Make a stateful extensions list component, with update statuses (#8301)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
Jacob MacDonald
2025-09-12 09:20:04 -07:00
committed by GitHub
parent 8810ef2f40
commit e89012efa8
15 changed files with 714 additions and 250 deletions
+35 -4
View File
@@ -9,6 +9,9 @@ import {
updateExtensionByName, updateExtensionByName,
updateAllUpdatableExtensions, updateAllUpdatableExtensions,
type ExtensionUpdateInfo, type ExtensionUpdateInfo,
loadExtensions,
annotateActiveExtensions,
checkForAllExtensionUpdates,
} from '../../config/extension.js'; } from '../../config/extension.js';
import { getErrorMessage } from '../../utils/errors.js'; import { getErrorMessage } from '../../utils/errors.js';
@@ -21,9 +24,25 @@ const updateOutput = (info: ExtensionUpdateInfo) =>
`Extension "${info.name}" successfully updated: ${info.originalVersion}${info.updatedVersion}.`; `Extension "${info.name}" successfully updated: ${info.originalVersion}${info.updatedVersion}.`;
export async function handleUpdate(args: UpdateArgs) { export async function handleUpdate(args: UpdateArgs) {
const workingDir = process.cwd();
const allExtensions = loadExtensions();
const extensions = annotateActiveExtensions(
allExtensions,
allExtensions.map((e) => e.config.name),
workingDir,
);
if (args.all) { if (args.all) {
try { try {
const updateInfos = await updateAllUpdatableExtensions(); let updateInfos = await updateAllUpdatableExtensions(
workingDir,
extensions,
await checkForAllExtensionUpdates(extensions, (_) => {}),
() => {},
);
updateInfos = updateInfos.filter(
(info) => info.originalVersion !== info.updatedVersion,
);
if (updateInfos.length === 0) { if (updateInfos.length === 0) {
console.log('No extensions to update.'); console.log('No extensions to update.');
return; return;
@@ -36,10 +55,22 @@ export async function handleUpdate(args: UpdateArgs) {
if (args.name) if (args.name)
try { try {
// TODO(chrstnb): we should list extensions if the requested extension is not installed. // TODO(chrstnb): we should list extensions if the requested extension is not installed.
const updatedExtensionInfo = await updateExtensionByName(args.name); const updatedExtensionInfo = await updateExtensionByName(
console.log( args.name,
`Extension "${args.name}" successfully updated: ${updatedExtensionInfo.originalVersion}${updatedExtensionInfo.updatedVersion}.`, workingDir,
extensions,
() => {},
); );
if (
updatedExtensionInfo.originalVersion !==
updatedExtensionInfo.updatedVersion
) {
console.log(
`Extension "${args.name}" successfully updated: ${updatedExtensionInfo.originalVersion}${updatedExtensionInfo.updatedVersion}.`,
);
} else {
console.log(`Extension "${args.name}" already up to date.`);
}
} catch (error) { } catch (error) {
console.error(getErrorMessage(error)); console.error(getErrorMessage(error));
} }
+243 -36
View File
@@ -12,10 +12,10 @@ import {
EXTENSIONS_CONFIG_FILENAME, EXTENSIONS_CONFIG_FILENAME,
INSTALL_METADATA_FILENAME, INSTALL_METADATA_FILENAME,
annotateActiveExtensions, annotateActiveExtensions,
checkForExtensionUpdates, checkForAllExtensionUpdates,
checkForExtensionUpdate,
disableExtension, disableExtension,
enableExtension, enableExtension,
ExtensionUpdateStatus,
installExtension, installExtension,
loadExtension, loadExtension,
loadExtensions, loadExtensions,
@@ -23,6 +23,7 @@ import {
uninstallExtension, uninstallExtension,
updateExtension, updateExtension,
type Extension, type Extension,
type ExtensionInstallMetadata,
} from './extension.js'; } from './extension.js';
import { import {
GEMINI_DIR, GEMINI_DIR,
@@ -34,6 +35,7 @@ import {
import { execSync } from 'node:child_process'; import { execSync } from 'node:child_process';
import { SettingScope, loadSettings } from './settings.js'; import { SettingScope, loadSettings } from './settings.js';
import { isWorkspaceTrusted } from './trustedFolders.js'; import { isWorkspaceTrusted } from './trustedFolders.js';
import { ExtensionUpdateState } from '../ui/state/extensions.js';
const mockGit = { const mockGit = {
clone: vi.fn(), clone: vi.fn(),
@@ -829,6 +831,7 @@ function createExtension({
addContextFile = false, addContextFile = false,
contextFileName = undefined as string | undefined, contextFileName = undefined as string | undefined,
mcpServers = {} as Record<string, MCPServerConfig>, mcpServers = {} as Record<string, MCPServerConfig>,
installMetadata = undefined as ExtensionInstallMetadata | undefined,
} = {}): string { } = {}): string {
const extDir = path.join(extensionsDir, name); const extDir = path.join(extensionsDir, name);
fs.mkdirSync(extDir, { recursive: true }); fs.mkdirSync(extDir, { recursive: true });
@@ -842,9 +845,14 @@ function createExtension({
} }
if (contextFileName) { if (contextFileName) {
const contextPath = path.join(extDir, contextFileName); fs.writeFileSync(path.join(extDir, contextFileName), 'context');
fs.mkdirSync(path.dirname(contextPath), { recursive: true }); }
fs.writeFileSync(contextPath, 'context');
if (installMetadata) {
fs.writeFileSync(
path.join(extDir, INSTALL_METADATA_FILENAME),
JSON.stringify(installMetadata),
);
} }
return extDir; return extDir;
} }
@@ -897,8 +905,12 @@ describe('updateExtension', () => {
); );
}); });
mockGit.getRemotes.mockResolvedValue([{ name: 'origin' }]); mockGit.getRemotes.mockResolvedValue([{ name: 'origin' }]);
const extension = annotateActiveExtensions(
const updateInfo = await updateExtension(loadExtension(targetExtDir)!); [loadExtension(targetExtDir)!],
[],
process.cwd(),
)[0];
const updateInfo = await updateExtension(extension, tempHomeDir, () => {});
expect(updateInfo).toEqual({ expect(updateInfo).toEqual({
name: 'gemini-extensions', name: 'gemini-extensions',
@@ -914,9 +926,80 @@ describe('updateExtension', () => {
); );
expect(updatedConfig.version).toBe('1.1.0'); expect(updatedConfig.version).toBe('1.1.0');
}); });
it('should call setExtensionUpdateState with UPDATING and then UPDATED_NEEDS_RESTART on success', async () => {
const extensionName = 'test-extension';
const extensionDir = createExtension({
extensionsDir: userExtensionsDir,
name: extensionName,
version: '1.0.0',
installMetadata: {
source: 'https://some.git/repo',
type: 'git',
},
});
mockGit.clone.mockImplementation(async (_, destination) => {
fs.mkdirSync(path.join(mockGit.path(), destination), { recursive: true });
fs.writeFileSync(
path.join(mockGit.path(), destination, EXTENSIONS_CONFIG_FILENAME),
JSON.stringify({ name: extensionName, version: '1.1.0' }),
);
});
mockGit.getRemotes.mockResolvedValue([{ name: 'origin' }]);
const setExtensionUpdateState = vi.fn();
const extension = annotateActiveExtensions(
[loadExtension(extensionDir)!],
[],
process.cwd(),
)[0];
await updateExtension(extension, tempHomeDir, setExtensionUpdateState);
expect(setExtensionUpdateState).toHaveBeenCalledWith(
ExtensionUpdateState.UPDATING,
);
expect(setExtensionUpdateState).toHaveBeenCalledWith(
ExtensionUpdateState.UPDATED_NEEDS_RESTART,
);
});
it('should call setExtensionUpdateState with ERROR on failure', async () => {
const extensionName = 'test-extension';
const extensionDir = createExtension({
extensionsDir: userExtensionsDir,
name: extensionName,
version: '1.0.0',
installMetadata: {
source: 'https://some.git/repo',
type: 'git',
},
});
mockGit.clone.mockRejectedValue(new Error('Git clone failed'));
mockGit.getRemotes.mockResolvedValue([{ name: 'origin' }]);
const setExtensionUpdateState = vi.fn();
const extension = annotateActiveExtensions(
[loadExtension(extensionDir)!],
[],
process.cwd(),
)[0];
await expect(
updateExtension(extension, tempHomeDir, setExtensionUpdateState),
).rejects.toThrow();
expect(setExtensionUpdateState).toHaveBeenCalledWith(
ExtensionUpdateState.UPDATING,
);
expect(setExtensionUpdateState).toHaveBeenCalledWith(
ExtensionUpdateState.ERROR,
);
});
}); });
describe('checkForExtensionUpdates', () => { describe('checkForAllExtensionUpdates', () => {
let tempHomeDir: string; let tempHomeDir: string;
let userExtensionsDir: string; let userExtensionsDir: string;
@@ -939,12 +1022,16 @@ describe('checkForExtensionUpdates', () => {
extensionsDir: userExtensionsDir, extensionsDir: userExtensionsDir,
name: 'test-extension', name: 'test-extension',
version: '1.0.0', version: '1.0.0',
installMetadata: {
source: 'https://some.git/repo',
type: 'git',
},
}); });
const extension = loadExtension(extensionDir)!; const extension = annotateActiveExtensions(
extension.installMetadata = { [loadExtension(extensionDir)!],
source: 'https://some.git/repo', [],
type: 'git', process.cwd(),
}; )[0];
mockGit.getRemotes.mockResolvedValue([ mockGit.getRemotes.mockResolvedValue([
{ name: 'origin', refs: { fetch: 'https://some.git/repo' } }, { name: 'origin', refs: { fetch: 'https://some.git/repo' } },
@@ -952,9 +1039,9 @@ describe('checkForExtensionUpdates', () => {
mockGit.listRemote.mockResolvedValue('remoteHash HEAD'); mockGit.listRemote.mockResolvedValue('remoteHash HEAD');
mockGit.revparse.mockResolvedValue('localHash'); mockGit.revparse.mockResolvedValue('localHash');
const results = await checkForExtensionUpdates([extension]); const results = await checkForAllExtensionUpdates([extension], () => {});
const result = results.get('test-extension'); const result = results.get('test-extension');
expect(result?.status).toBe(ExtensionUpdateStatus.UpdateAvailable); expect(result).toBe(ExtensionUpdateState.UPDATE_AVAILABLE);
}); });
it('should return UpToDate for a git extension with no updates', async () => { it('should return UpToDate for a git extension with no updates', async () => {
@@ -962,12 +1049,16 @@ describe('checkForExtensionUpdates', () => {
extensionsDir: userExtensionsDir, extensionsDir: userExtensionsDir,
name: 'test-extension', name: 'test-extension',
version: '1.0.0', version: '1.0.0',
installMetadata: {
source: 'https://some.git/repo',
type: 'git',
},
}); });
const extension = loadExtension(extensionDir)!; const extension = annotateActiveExtensions(
extension.installMetadata = { [loadExtension(extensionDir)!],
source: 'https://some.git/repo', [],
type: 'git', process.cwd(),
}; )[0];
mockGit.getRemotes.mockResolvedValue([ mockGit.getRemotes.mockResolvedValue([
{ name: 'origin', refs: { fetch: 'https://some.git/repo' } }, { name: 'origin', refs: { fetch: 'https://some.git/repo' } },
@@ -975,9 +1066,121 @@ describe('checkForExtensionUpdates', () => {
mockGit.listRemote.mockResolvedValue('sameHash HEAD'); mockGit.listRemote.mockResolvedValue('sameHash HEAD');
mockGit.revparse.mockResolvedValue('sameHash'); mockGit.revparse.mockResolvedValue('sameHash');
const results = await checkForExtensionUpdates([extension]); const results = await checkForAllExtensionUpdates([extension], () => {});
const result = results.get('test-extension'); const result = results.get('test-extension');
expect(result?.status).toBe(ExtensionUpdateStatus.UpToDate); expect(result).toBe(ExtensionUpdateState.UP_TO_DATE);
});
it('should return NotUpdatable for a non-git extension', async () => {
const extensionDir = createExtension({
extensionsDir: userExtensionsDir,
name: 'local-extension',
version: '1.0.0',
installMetadata: { source: '/local/path', type: 'local' },
});
const extension = annotateActiveExtensions(
[loadExtension(extensionDir)!],
[],
process.cwd(),
)[0];
const results = await checkForAllExtensionUpdates([extension], () => {});
const result = results.get('local-extension');
expect(result).toBe(ExtensionUpdateState.NOT_UPDATABLE);
});
it('should return Error when git check fails', async () => {
const extensionDir = createExtension({
extensionsDir: userExtensionsDir,
name: 'error-extension',
version: '1.0.0',
installMetadata: {
source: 'https://some.git/repo',
type: 'git',
},
});
const extension = annotateActiveExtensions(
[loadExtension(extensionDir)!],
[],
process.cwd(),
)[0];
mockGit.getRemotes.mockRejectedValue(new Error('Git error'));
const results = await checkForAllExtensionUpdates([extension], () => {});
const result = results.get('error-extension');
expect(result).toBe(ExtensionUpdateState.ERROR);
});
});
describe('checkForExtensionUpdate', () => {
let tempHomeDir: string;
let userExtensionsDir: string;
beforeEach(() => {
tempHomeDir = fs.mkdtempSync(
path.join(os.tmpdir(), 'gemini-cli-test-home-'),
);
vi.mocked(os.homedir).mockReturnValue(tempHomeDir);
userExtensionsDir = path.join(tempHomeDir, GEMINI_DIR, 'extensions');
fs.mkdirSync(userExtensionsDir, { recursive: true });
Object.values(mockGit).forEach((fn) => fn.mockReset());
});
afterEach(() => {
fs.rmSync(tempHomeDir, { recursive: true, force: true });
});
it('should return UpdateAvailable for a git extension with updates', async () => {
const extensionDir = createExtension({
extensionsDir: userExtensionsDir,
name: 'test-extension',
version: '1.0.0',
installMetadata: {
source: 'https://some.git/repo',
type: 'git',
},
});
const extension = annotateActiveExtensions(
[loadExtension(extensionDir)!],
[],
process.cwd(),
)[0];
mockGit.getRemotes.mockResolvedValue([
{ name: 'origin', refs: { fetch: 'https://some.git/repo' } },
]);
mockGit.listRemote.mockResolvedValue('remoteHash HEAD');
mockGit.revparse.mockResolvedValue('localHash');
const result = await checkForExtensionUpdate(extension);
expect(result).toBe(ExtensionUpdateState.UPDATE_AVAILABLE);
});
it('should return UpToDate for a git extension with no updates', async () => {
const extensionDir = createExtension({
extensionsDir: userExtensionsDir,
name: 'test-extension',
version: '1.0.0',
installMetadata: {
source: 'https://some.git/repo',
type: 'git',
},
});
const extension = annotateActiveExtensions(
[loadExtension(extensionDir)!],
[],
process.cwd(),
)[0];
mockGit.getRemotes.mockResolvedValue([
{ name: 'origin', refs: { fetch: 'https://some.git/repo' } },
]);
mockGit.listRemote.mockResolvedValue('sameHash HEAD');
mockGit.revparse.mockResolvedValue('sameHash');
const result = await checkForExtensionUpdate(extension);
expect(result).toBe(ExtensionUpdateState.UP_TO_DATE);
}); });
it('should return NotUpdatable for a non-git extension', async () => { it('should return NotUpdatable for a non-git extension', async () => {
@@ -986,12 +1189,14 @@ describe('checkForExtensionUpdates', () => {
name: 'local-extension', name: 'local-extension',
version: '1.0.0', version: '1.0.0',
}); });
const extension = loadExtension(extensionDir)!; const extension = annotateActiveExtensions(
extension.installMetadata = { source: '/local/path', type: 'local' }; [loadExtension(extensionDir)!],
[],
process.cwd(),
)[0];
const results = await checkForExtensionUpdates([extension]); const result = await checkForExtensionUpdate(extension);
const result = results.get('local-extension'); expect(result).toBe(ExtensionUpdateState.NOT_UPDATABLE);
expect(result?.status).toBe(ExtensionUpdateStatus.NotUpdatable);
}); });
it('should return Error when git check fails', async () => { it('should return Error when git check fails', async () => {
@@ -999,19 +1204,21 @@ describe('checkForExtensionUpdates', () => {
extensionsDir: userExtensionsDir, extensionsDir: userExtensionsDir,
name: 'error-extension', name: 'error-extension',
version: '1.0.0', version: '1.0.0',
installMetadata: {
source: 'https://some.git/repo',
type: 'git',
},
}); });
const extension = loadExtension(extensionDir)!; const extension = annotateActiveExtensions(
extension.installMetadata = { [loadExtension(extensionDir)!],
source: 'https://some.git/repo', [],
type: 'git', process.cwd(),
}; )[0];
mockGit.getRemotes.mockRejectedValue(new Error('Git error')); mockGit.getRemotes.mockRejectedValue(new Error('Git error'));
const results = await checkForExtensionUpdates([extension]); const result = await checkForExtensionUpdate(extension);
const result = results.get('error-extension'); expect(result).toBe(ExtensionUpdateState.ERROR);
expect(result?.status).toBe(ExtensionUpdateStatus.Error);
expect(result?.error).toContain('Failed to check for updates');
}); });
}); });
+118 -94
View File
@@ -25,6 +25,7 @@ import { recursivelyHydrateStrings } from './extensions/variables.js';
import { isWorkspaceTrusted } from './trustedFolders.js'; import { isWorkspaceTrusted } from './trustedFolders.js';
import { resolveEnvVarsInObject } from '../utils/envVarResolver.js'; import { resolveEnvVarsInObject } from '../utils/envVarResolver.js';
import { randomUUID } from 'node:crypto'; import { randomUUID } from 'node:crypto';
import { ExtensionUpdateState } from '../ui/state/extensions.js';
export const EXTENSIONS_DIRECTORY_NAME = path.join(GEMINI_DIR, 'extensions'); export const EXTENSIONS_DIRECTORY_NAME = path.join(GEMINI_DIR, 'extensions');
@@ -291,6 +292,9 @@ export function annotateActiveExtensions(
version: extension.config.version, version: extension.config.version,
isActive: !disabledExtensions.includes(extension.config.name), isActive: !disabledExtensions.includes(extension.config.name),
path: extension.path, path: extension.path,
source: extension.installMetadata?.source,
type: extension.installMetadata?.type,
ref: extension.installMetadata?.ref,
})); }));
} }
@@ -307,6 +311,9 @@ export function annotateActiveExtensions(
version: extension.config.version, version: extension.config.version,
isActive: false, isActive: false,
path: extension.path, path: extension.path,
source: extension.installMetadata?.source,
type: extension.installMetadata?.type,
ref: extension.installMetadata?.ref,
})); }));
} }
@@ -609,46 +616,63 @@ export function toOutputString(extension: Extension): string {
export async function updateExtensionByName( export async function updateExtensionByName(
extensionName: string, extensionName: string,
cwd: string = process.cwd(), cwd: string = process.cwd(),
extensions: GeminiCLIExtension[],
setExtensionUpdateState: (updateState: ExtensionUpdateState) => void,
): Promise<ExtensionUpdateInfo> { ): Promise<ExtensionUpdateInfo> {
const installedExtensions = loadUserExtensions(); const extension = extensions.find(
const extension = installedExtensions.find( (installed) => installed.name === extensionName,
(installed) => installed.config.name === extensionName,
); );
if (!extension) { if (!extension) {
throw new Error( throw new Error(
`Extension "${extensionName}" not found. Run gemini extensions list to see available extensions.`, `Extension "${extensionName}" not found. Run gemini extensions list to see available extensions.`,
); );
} }
return await updateExtension(extension, cwd); return await updateExtension(extension, cwd, setExtensionUpdateState);
} }
export async function updateExtension( export async function updateExtension(
extension: Extension, extension: GeminiCLIExtension,
cwd: string = process.cwd(), cwd: string = process.cwd(),
setExtensionUpdateState: (updateState: ExtensionUpdateState) => void,
): Promise<ExtensionUpdateInfo> { ): Promise<ExtensionUpdateInfo> {
if (!extension.installMetadata) { if (!extension.type) {
throw new Error(`Extension ${extension.config.name} cannot be updated.`); setExtensionUpdateState(ExtensionUpdateState.ERROR);
throw new Error(
`Extension ${extension.name} cannot be updated, type is unknown.`,
);
} }
if (extension.installMetadata.type === 'link') { if (extension.type === 'link') {
setExtensionUpdateState(ExtensionUpdateState.UP_TO_DATE);
throw new Error(`Extension is linked so does not need to be updated`); throw new Error(`Extension is linked so does not need to be updated`);
} }
const originalVersion = extension.config.version; setExtensionUpdateState(ExtensionUpdateState.UPDATING);
const originalVersion = extension.version;
const tempDir = await ExtensionStorage.createTmpDir(); const tempDir = await ExtensionStorage.createTmpDir();
try { try {
await copyExtension(extension.path, tempDir); await copyExtension(extension.path, tempDir);
await uninstallExtension(extension.config.name, cwd); await uninstallExtension(extension.name, cwd);
await installExtension(extension.installMetadata, cwd); await installExtension(
const updatedExtensionStorage = new ExtensionStorage(extension.config.name); {
source: extension.source!,
type: extension.type,
ref: extension.ref,
},
cwd,
);
const updatedExtensionStorage = new ExtensionStorage(extension.name);
const updatedExtension = loadExtension( const updatedExtension = loadExtension(
updatedExtensionStorage.getExtensionDir(), updatedExtensionStorage.getExtensionDir(),
); );
if (!updatedExtension) { if (!updatedExtension) {
setExtensionUpdateState(ExtensionUpdateState.ERROR);
throw new Error('Updated extension not found after installation.'); throw new Error('Updated extension not found after installation.');
} }
const updatedVersion = updatedExtension.config.version; const updatedVersion = updatedExtension.config.version;
setExtensionUpdateState(ExtensionUpdateState.UPDATED_NEEDS_RESTART);
return { return {
name: extension.config.name, name: extension.name,
originalVersion, originalVersion,
updatedVersion, updatedVersion,
}; };
@@ -656,6 +680,7 @@ export async function updateExtension(
console.error( console.error(
`Error updating extension, rolling back. ${getErrorMessage(e)}`, `Error updating extension, rolling back. ${getErrorMessage(e)}`,
); );
setExtensionUpdateState(ExtensionUpdateState.ERROR);
await copyExtension(tempDir, extension.path); await copyExtension(tempDir, extension.path);
throw e; throw e;
} finally { } finally {
@@ -714,98 +739,97 @@ function removeFromDisabledExtensions(
export async function updateAllUpdatableExtensions( export async function updateAllUpdatableExtensions(
cwd: string = process.cwd(), cwd: string = process.cwd(),
extensions: GeminiCLIExtension[],
extensionsState: Map<string, ExtensionUpdateState>,
setExtensionsUpdateState: (
updateState: Map<string, ExtensionUpdateState>,
) => void,
): Promise<ExtensionUpdateInfo[]> { ): Promise<ExtensionUpdateInfo[]> {
const extensions = loadExtensions(cwd).filter(
(extension) => !!extension.installMetadata,
);
return await Promise.all( return await Promise.all(
extensions.map((extension) => updateExtension(extension, cwd)), extensions
.filter(
(extension) =>
extensionsState.get(extension.name) ===
ExtensionUpdateState.UPDATE_AVAILABLE,
)
.map((extension) =>
updateExtension(extension, cwd, (updateState) => {
const newState = new Map(extensionsState);
newState.set(extension.name, updateState);
setExtensionsUpdateState(newState);
}),
),
); );
} }
export enum ExtensionUpdateStatus {
UpdateAvailable,
UpToDate,
Error,
NotUpdatable,
}
export interface ExtensionUpdateCheckResult { export interface ExtensionUpdateCheckResult {
status: ExtensionUpdateStatus; state: ExtensionUpdateState;
error?: string; error?: string;
} }
export async function checkForExtensionUpdates( export async function checkForAllExtensionUpdates(
extensions: Extension[], extensions: GeminiCLIExtension[],
): Promise<Map<string, ExtensionUpdateCheckResult>> { setExtensionsUpdateState: (
const results = new Map<string, ExtensionUpdateCheckResult>(); updateState: Map<string, ExtensionUpdateState>,
) => void,
): Promise<Map<string, ExtensionUpdateState>> {
const finalState = new Map<string, ExtensionUpdateState>();
for (const extension of extensions) { for (const extension of extensions) {
if (extension.installMetadata?.type !== 'git') { finalState.set(extension.name, await checkForExtensionUpdate(extension));
results.set(extension.config.name, { }
status: ExtensionUpdateStatus.NotUpdatable, setExtensionsUpdateState(finalState);
}); return finalState;
continue; }
}
try { export async function checkForExtensionUpdate(
const git = simpleGit(extension.path); extension: GeminiCLIExtension,
const remotes = await git.getRemotes(true); ): Promise<ExtensionUpdateState> {
if (remotes.length === 0) { if (extension.type !== 'git') {
results.set(extension.config.name, { return ExtensionUpdateState.NOT_UPDATABLE;
status: ExtensionUpdateStatus.Error,
error: 'No git remotes found.',
});
continue;
}
const remoteUrl = remotes[0].refs.fetch;
if (!remoteUrl) {
results.set(extension.config.name, {
status: ExtensionUpdateStatus.Error,
error: `No fetch URL found for git remote ${remotes[0].name}.`,
});
continue;
}
// Determine the ref to check on the remote.
const refToCheck = extension.installMetadata.ref || 'HEAD';
const lsRemoteOutput = await git.listRemote([remoteUrl, refToCheck]);
if (typeof lsRemoteOutput !== 'string' || lsRemoteOutput.trim() === '') {
results.set(extension.config.name, {
status: ExtensionUpdateStatus.Error,
error: `Git ref ${refToCheck} not found.`,
});
continue;
}
const remoteHash = lsRemoteOutput.split('\t')[0];
const localHash = await git.revparse(['HEAD']);
if (!remoteHash) {
results.set(extension.config.name, {
status: ExtensionUpdateStatus.Error,
error: `Unable to parse hash from git ls-remote output "${lsRemoteOutput}"`,
});
} else if (remoteHash === localHash) {
results.set(extension.config.name, {
status: ExtensionUpdateStatus.UpToDate,
});
} else {
results.set(extension.config.name, {
status: ExtensionUpdateStatus.UpdateAvailable,
});
}
} catch (error) {
results.set(extension.config.name, {
status: ExtensionUpdateStatus.Error,
error: `Failed to check for updates for extension "${
extension.config.name
}": ${getErrorMessage(error)}`,
});
}
} }
return results; try {
const git = simpleGit(extension.path);
const remotes = await git.getRemotes(true);
if (remotes.length === 0) {
console.error('No git remotes found.');
return ExtensionUpdateState.ERROR;
}
const remoteUrl = remotes[0].refs.fetch;
if (!remoteUrl) {
console.error(`No fetch URL found for git remote ${remotes[0].name}.`);
return ExtensionUpdateState.ERROR;
}
// Determine the ref to check on the remote.
const refToCheck = extension.ref || 'HEAD';
const lsRemoteOutput = await git.listRemote([remoteUrl, refToCheck]);
if (typeof lsRemoteOutput !== 'string' || lsRemoteOutput.trim() === '') {
console.error(`Git ref ${refToCheck} not found.`);
return ExtensionUpdateState.ERROR;
}
const remoteHash = lsRemoteOutput.split('\t')[0];
const localHash = await git.revparse(['HEAD']);
if (!remoteHash) {
console.error(
`Unable to parse hash from git ls-remote output "${lsRemoteOutput}"`,
);
return ExtensionUpdateState.ERROR;
} else if (remoteHash === localHash) {
return ExtensionUpdateState.UP_TO_DATE;
} else {
return ExtensionUpdateState.UPDATE_AVAILABLE;
}
} catch (error) {
console.error(
`Failed to check for updates for extension "${
extension.name
}": ${getErrorMessage(error)}`,
);
return ExtensionUpdateState.ERROR;
}
} }
+15
View File
@@ -76,6 +76,8 @@ import { useAutoAcceptIndicator } from './hooks/useAutoAcceptIndicator.js';
import { useWorkspaceMigration } from './hooks/useWorkspaceMigration.js'; import { useWorkspaceMigration } from './hooks/useWorkspaceMigration.js';
import { useSessionStats } from './contexts/SessionContext.js'; import { useSessionStats } from './contexts/SessionContext.js';
import { useGitBranchName } from './hooks/useGitBranchName.js'; import { useGitBranchName } from './hooks/useGitBranchName.js';
import type { ExtensionUpdateState } from './state/extensions.js';
import { checkForAllExtensionUpdates } from '../config/extension.js';
const CTRL_EXIT_PROMPT_DURATION_MS = 1000; const CTRL_EXIT_PROMPT_DURATION_MS = 1000;
@@ -136,6 +138,9 @@ export const AppContainer = (props: AppContainerProps) => {
const [isTrustedFolder, setIsTrustedFolder] = useState<boolean | undefined>( const [isTrustedFolder, setIsTrustedFolder] = useState<boolean | undefined>(
config.isTrustedFolder(), config.isTrustedFolder(),
); );
const [extensionsUpdateState, setExtensionsUpdateState] = useState(
new Map<string, ExtensionUpdateState>(),
);
// Helper to determine the effective model, considering the fallback state. // Helper to determine the effective model, considering the fallback state.
const getEffectiveModel = useCallback(() => { const getEffectiveModel = useCallback(() => {
@@ -419,6 +424,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
}, },
setDebugMessage, setDebugMessage,
toggleCorgiMode: () => setCorgiMode((prev) => !prev), toggleCorgiMode: () => setCorgiMode((prev) => !prev),
setExtensionsUpdateState,
}), }),
[ [
setAuthState, setAuthState,
@@ -429,6 +435,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
setDebugMessage, setDebugMessage,
setShowPrivacyNotice, setShowPrivacyNotice,
setCorgiMode, setCorgiMode,
setExtensionsUpdateState,
], ],
); );
@@ -450,6 +457,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
setIsProcessing, setIsProcessing,
setGeminiMdFileCount, setGeminiMdFileCount,
slashCommandActions, slashCommandActions,
extensionsUpdateState,
isConfigInitialized, isConfigInitialized,
); );
@@ -1040,6 +1048,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
updateInfo, updateInfo,
showIdeRestartPrompt, showIdeRestartPrompt,
isRestarting, isRestarting,
extensionsUpdateState,
activePtyId, activePtyId,
shellFocused, shellFocused,
}), }),
@@ -1115,6 +1124,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
showIdeRestartPrompt, showIdeRestartPrompt,
isRestarting, isRestarting,
currentModel, currentModel,
extensionsUpdateState,
activePtyId, activePtyId,
shellFocused, shellFocused,
], ],
@@ -1168,6 +1178,11 @@ Logging in with Google... Please restart Gemini CLI to continue.
], ],
); );
const extensions = config.getExtensions();
useEffect(() => {
checkForAllExtensionUpdates(extensions, setExtensionsUpdateState);
}, [extensions, setExtensionsUpdateState]);
return ( return (
<UIStateContext.Provider value={uiState}> <UIStateContext.Provider value={uiState}>
<UIActionsContext.Provider value={uiActions}> <UIActionsContext.Provider value={uiActions}>
@@ -44,51 +44,20 @@ describe('extensionsCommand', () => {
services: { services: {
config: { config: {
getExtensions: () => [], getExtensions: () => [],
getWorkingDir: () => '/test/dir',
}, },
}, },
}); });
}); });
describe('list', () => { describe('list', () => {
it('should display "No active extensions." when none are found', async () => { it('should add an EXTENSIONS_LIST item to the UI', async () => {
if (!extensionsCommand.action) throw new Error('Action not defined'); if (!extensionsCommand.action) throw new Error('Action not defined');
await extensionsCommand.action(mockContext, ''); await extensionsCommand.action(mockContext, '');
expect(mockContext.ui.addItem).toHaveBeenCalledWith( expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{ {
type: MessageType.INFO, type: MessageType.EXTENSIONS_LIST,
text: 'No active extensions.',
},
expect.any(Number),
);
});
it('should list active extensions when they are found', async () => {
const mockExtensions = [
{ name: 'ext-one', version: '1.0.0', isActive: true },
{ name: 'ext-two', version: '2.1.0', isActive: true },
{ name: 'ext-three', version: '3.0.0', isActive: false },
];
mockContext = createMockCommandContext({
services: {
config: {
getExtensions: () => mockExtensions,
},
},
});
if (!extensionsCommand.action) throw new Error('Action not defined');
await extensionsCommand.action(mockContext, '');
const expectedMessage =
'Active extensions:\n\n' +
` - \u001b[36mext-one (v1.0.0)\u001b[0m\n` +
` - \u001b[36mext-two (v2.1.0)\u001b[0m\n`;
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{
type: MessageType.INFO,
text: expectedMessage,
}, },
expect.any(Number), expect.any(Number),
); );
@@ -127,7 +96,7 @@ describe('extensionsCommand', () => {
); );
}); });
it('should update all extensions with --all', async () => { it('should call setPendingItem and addItem in a finally block on success', async () => {
mockUpdateAllUpdatableExtensions.mockResolvedValue([ mockUpdateAllUpdatableExtensions.mockResolvedValue([
{ {
name: 'ext-one', name: 'ext-one',
@@ -141,23 +110,33 @@ describe('extensionsCommand', () => {
}, },
]); ]);
await updateAction(mockContext, '--all'); await updateAction(mockContext, '--all');
expect(mockContext.ui.setPendingItem).toHaveBeenCalledWith({
type: MessageType.EXTENSIONS_LIST,
});
expect(mockContext.ui.setPendingItem).toHaveBeenCalledWith(null);
expect(mockContext.ui.addItem).toHaveBeenCalledWith( expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{ {
type: MessageType.INFO, type: MessageType.EXTENSIONS_LIST,
text:
'Extension "ext-one" successfully updated: 1.0.0 → 1.0.1.\n' +
'Extension "ext-two" successfully updated: 2.0.0 → 2.0.1.\n' +
'Restart gemini-cli to see the changes.',
}, },
expect.any(Number), expect.any(Number),
); );
}); });
it('should handle errors when updating all extensions', async () => { it('should call setPendingItem and addItem in a finally block on failure', async () => {
mockUpdateAllUpdatableExtensions.mockRejectedValue( mockUpdateAllUpdatableExtensions.mockRejectedValue(
new Error('Something went wrong'), new Error('Something went wrong'),
); );
await updateAction(mockContext, '--all'); await updateAction(mockContext, '--all');
expect(mockContext.ui.setPendingItem).toHaveBeenCalledWith({
type: MessageType.EXTENSIONS_LIST,
});
expect(mockContext.ui.setPendingItem).toHaveBeenCalledWith(null);
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{
type: MessageType.EXTENSIONS_LIST,
},
expect.any(Number),
);
expect(mockContext.ui.addItem).toHaveBeenCalledWith( expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{ {
type: MessageType.ERROR, type: MessageType.ERROR,
@@ -174,14 +153,11 @@ describe('extensionsCommand', () => {
updatedVersion: '1.0.1', updatedVersion: '1.0.1',
}); });
await updateAction(mockContext, 'ext-one'); await updateAction(mockContext, 'ext-one');
expect(mockContext.ui.addItem).toHaveBeenCalledWith( expect(mockUpdateExtensionByName).toHaveBeenCalledWith(
{ 'ext-one',
type: MessageType.INFO, '/test/dir',
text: [],
'Extension "ext-one" successfully updated: 1.0.0 → 1.0.1.\n' + expect.any(Function),
'Restart gemini-cli to see the changes.',
},
expect.any(Number),
); );
}); });
@@ -213,13 +189,13 @@ describe('extensionsCommand', () => {
}); });
await updateAction(mockContext, 'ext-one ext-two'); await updateAction(mockContext, 'ext-one ext-two');
expect(mockUpdateExtensionByName).toHaveBeenCalledTimes(2); expect(mockUpdateExtensionByName).toHaveBeenCalledTimes(2);
expect(mockContext.ui.setPendingItem).toHaveBeenCalledWith({
type: MessageType.EXTENSIONS_LIST,
});
expect(mockContext.ui.setPendingItem).toHaveBeenCalledWith(null);
expect(mockContext.ui.addItem).toHaveBeenCalledWith( expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{ {
type: MessageType.INFO, type: MessageType.EXTENSIONS_LIST,
text:
'Extension "ext-one" successfully updated: 1.0.0 → 1.0.1.\n' +
'Extension "ext-two" successfully updated: 2.0.0 → 2.0.1.\n' +
'Restart gemini-cli to see the changes.',
}, },
expect.any(Number), expect.any(Number),
); );
@@ -18,65 +18,59 @@ import {
} from './types.js'; } from './types.js';
async function listAction(context: CommandContext) { async function listAction(context: CommandContext) {
const activeExtensions = context.services.config
?.getExtensions()
.filter((ext) => ext.isActive);
if (!activeExtensions || activeExtensions.length === 0) {
context.ui.addItem(
{
type: MessageType.INFO,
text: 'No active extensions.',
},
Date.now(),
);
return;
}
const extensionLines = activeExtensions.map(
(ext) => ` - \u001b[36m${ext.name} (v${ext.version})\u001b[0m`,
);
const message = `Active extensions:\n\n${extensionLines.join('\n')}\n`;
context.ui.addItem( context.ui.addItem(
{ {
type: MessageType.INFO, type: MessageType.EXTENSIONS_LIST,
text: message,
}, },
Date.now(), Date.now(),
); );
} }
const updateOutput = (info: ExtensionUpdateInfo) =>
`Extension "${info.name}" successfully updated: ${info.originalVersion}${info.updatedVersion}.`;
async function updateAction(context: CommandContext, args: string) { async function updateAction(context: CommandContext, args: string) {
const updateArgs = args.split(' ').filter((value) => value.length > 0); const updateArgs = args.split(' ').filter((value) => value.length > 0);
const all = updateArgs.length === 1 && updateArgs[0] === '--all'; const all = updateArgs.length === 1 && updateArgs[0] === '--all';
const names = all ? undefined : updateArgs; const names = all ? undefined : updateArgs;
let updateInfos: ExtensionUpdateInfo[] = []; let updateInfos: ExtensionUpdateInfo[] = [];
if (!all && names?.length === 0) {
context.ui.addItem(
{
type: MessageType.ERROR,
text: 'Usage: /extensions update <extension-names>|--all',
},
Date.now(),
);
return;
}
try { try {
context.ui.setPendingItem({
type: MessageType.EXTENSIONS_LIST,
});
if (all) { if (all) {
updateInfos = await updateAllUpdatableExtensions(); updateInfos = await updateAllUpdatableExtensions(
context.services.config!.getWorkingDir(),
context.services.config!.getExtensions(),
context.ui.extensionsUpdateState,
context.ui.setExtensionsUpdateState,
);
} else if (names?.length) { } else if (names?.length) {
for (const name of names) { for (const name of names) {
updateInfos.push(await updateExtensionByName(name)); updateInfos.push(
await updateExtensionByName(
name,
context.services.config!.getWorkingDir(),
context.services.config!.getExtensions(),
(updateState) => {
const newState = new Map(context.ui.extensionsUpdateState);
newState.set(name, updateState);
context.ui.setExtensionsUpdateState(newState);
},
),
);
} }
} else {
context.ui.addItem(
{
type: MessageType.ERROR,
text: 'Usage: /extensions update <extension-names>|--all',
},
Date.now(),
);
return;
} }
// Filter to the actually updated ones.
updateInfos = updateInfos.filter(
(info) => info.originalVersion !== info.updatedVersion,
);
if (updateInfos.length === 0) { if (updateInfos.length === 0) {
context.ui.addItem( context.ui.addItem(
{ {
@@ -87,17 +81,6 @@ async function updateAction(context: CommandContext, args: string) {
); );
return; return;
} }
context.ui.addItem(
{
type: MessageType.INFO,
text: [
...updateInfos.map((info) => updateOutput(info)),
'Restart gemini-cli to see the changes.',
].join('\n'),
},
Date.now(),
);
} catch (error) { } catch (error) {
context.ui.addItem( context.ui.addItem(
{ {
@@ -106,6 +89,14 @@ async function updateAction(context: CommandContext, args: string) {
}, },
Date.now(), Date.now(),
); );
} finally {
context.ui.addItem(
{
type: MessageType.EXTENSIONS_LIST,
},
Date.now(),
);
context.ui.setPendingItem(null);
} }
} }
+6 -1
View File
@@ -4,13 +4,14 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import { type ReactNode } from 'react'; import type { ReactNode } from 'react';
import type { Content, PartListUnion } from '@google/genai'; import type { Content, PartListUnion } from '@google/genai';
import type { HistoryItemWithoutId, HistoryItem } from '../types.js'; import type { HistoryItemWithoutId, HistoryItem } from '../types.js';
import type { Config, GitService, Logger } from '@google/gemini-cli-core'; import type { Config, GitService, Logger } from '@google/gemini-cli-core';
import type { LoadedSettings } from '../../config/settings.js'; import type { LoadedSettings } from '../../config/settings.js';
import type { UseHistoryManagerReturn } from '../hooks/useHistoryManager.js'; import type { UseHistoryManagerReturn } from '../hooks/useHistoryManager.js';
import type { SessionStatsState } from '../contexts/SessionContext.js'; import type { SessionStatsState } from '../contexts/SessionContext.js';
import type { ExtensionUpdateState } from '../state/extensions.js';
// Grouped dependencies for clarity and easier mocking // Grouped dependencies for clarity and easier mocking
export interface CommandContext { export interface CommandContext {
@@ -61,6 +62,10 @@ export interface CommandContext {
toggleVimEnabled: () => Promise<boolean>; toggleVimEnabled: () => Promise<boolean>;
setGeminiMdFileCount: (count: number) => void; setGeminiMdFileCount: (count: number) => void;
reloadCommands: () => void; reloadCommands: () => void;
extensionsUpdateState: Map<string, ExtensionUpdateState>;
setExtensionsUpdateState: (
updateState: Map<string, ExtensionUpdateState>,
) => void;
}; };
// Session-specific data // Session-specific data
session: { session: {
@@ -22,6 +22,7 @@ import { ToolStatsDisplay } from './ToolStatsDisplay.js';
import { SessionSummaryDisplay } from './SessionSummaryDisplay.js'; import { SessionSummaryDisplay } from './SessionSummaryDisplay.js';
import { Help } from './Help.js'; import { Help } from './Help.js';
import type { SlashCommand } from '../commands/types.js'; import type { SlashCommand } from '../commands/types.js';
import { ExtensionsList } from './views/ExtensionsList.js';
interface HistoryItemDisplayProps { interface HistoryItemDisplayProps {
item: HistoryItem; item: HistoryItem;
@@ -96,5 +97,6 @@ export const HistoryItemDisplay: React.FC<HistoryItemDisplayProps> = ({
{item.type === 'compression' && ( {item.type === 'compression' && (
<CompressionMessage compression={item.compression} /> <CompressionMessage compression={item.compression} />
)} )}
{item.type === 'extensions_list' && <ExtensionsList />}
</Box> </Box>
); );
@@ -0,0 +1,110 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { render } from 'ink-testing-library';
import { vi } from 'vitest';
import { useUIState } from '../../contexts/UIStateContext.js';
import { ExtensionUpdateState } from '../../state/extensions.js';
import { ExtensionsList } from './ExtensionsList.js';
import { createMockCommandContext } from '../../../test-utils/mockCommandContext.js';
vi.mock('../../contexts/UIStateContext.js');
const mockUseUIState = vi.mocked(useUIState);
const mockExtensions = [
{ name: 'ext-one', version: '1.0.0', isActive: true },
{ name: 'ext-two', version: '2.1.0', isActive: true },
{ name: 'ext-disabled', version: '3.0.0', isActive: false },
];
describe('<ExtensionsList />', () => {
beforeEach(() => {
vi.resetAllMocks();
});
const mockUIState = (
extensions: unknown[],
extensionsUpdateState: Map<string, ExtensionUpdateState>,
disabledExtensions: string[] = [],
) => {
mockUseUIState.mockReturnValue({
commandContext: createMockCommandContext({
services: {
config: {
getExtensions: () => extensions,
},
settings: {
merged: {
extensions: {
disabled: disabledExtensions,
},
},
},
},
}),
extensionsUpdateState,
// Add other required properties from UIState if needed by the component
} as never);
};
it('should render "No extensions installed." if there are no extensions', () => {
mockUIState([], new Map());
const { lastFrame } = render(<ExtensionsList />);
expect(lastFrame()).toContain('No extensions installed.');
});
it('should render a list of extensions with their version and status', () => {
mockUIState(mockExtensions, new Map(), ['ext-disabled']);
const { lastFrame } = render(<ExtensionsList />);
const output = lastFrame();
expect(output).toContain('ext-one (v1.0.0) - active');
expect(output).toContain('ext-two (v2.1.0) - active');
expect(output).toContain('ext-disabled (v3.0.0) - disabled');
});
it('should display "unknown state" if an extension has no update state', () => {
mockUIState([mockExtensions[0]], new Map());
const { lastFrame } = render(<ExtensionsList />);
expect(lastFrame()).toContain('(unknown state)');
});
const stateTestCases = [
{
state: ExtensionUpdateState.CHECKING_FOR_UPDATES,
expectedText: '(checking for updates)',
},
{
state: ExtensionUpdateState.UPDATING,
expectedText: '(updating)',
},
{
state: ExtensionUpdateState.UPDATE_AVAILABLE,
expectedText: '(update available)',
},
{
state: ExtensionUpdateState.UPDATED_NEEDS_RESTART,
expectedText: '(updated, needs restart)',
},
{
state: ExtensionUpdateState.ERROR,
expectedText: '(error checking for updates)',
},
{
state: ExtensionUpdateState.UP_TO_DATE,
expectedText: '(up to date)',
},
];
for (const { state, expectedText } of stateTestCases) {
it(`should correctly display the state: ${state}`, () => {
const updateState = new Map([[mockExtensions[0].name, state]]);
mockUIState([mockExtensions[0]], updateState);
const { lastFrame } = render(<ExtensionsList />);
expect(lastFrame()).toContain(expectedText);
});
}
});
@@ -0,0 +1,67 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { Box, Text } from 'ink';
import { useUIState } from '../../contexts/UIStateContext.js';
import { ExtensionUpdateState } from '../../state/extensions.js';
export const ExtensionsList = () => {
const { commandContext, extensionsUpdateState } = useUIState();
const allExtensions = commandContext.services.config!.getExtensions();
const settings = commandContext.services.settings;
const disabledExtensions = settings.merged.extensions?.disabled ?? [];
if (allExtensions.length === 0) {
return <Text>No extensions installed.</Text>;
}
return (
<Box flexDirection="column" marginTop={1} marginBottom={1}>
<Text>Installed extensions:</Text>
<Box flexDirection="column" paddingLeft={2}>
{allExtensions.map((ext) => {
const state = extensionsUpdateState.get(ext.name);
const isActive = !disabledExtensions.includes(ext.name);
const activeString = isActive ? 'active' : 'disabled';
let stateColor = 'gray';
const stateText = state || 'unknown state';
switch (state) {
case ExtensionUpdateState.CHECKING_FOR_UPDATES:
case ExtensionUpdateState.UPDATING:
stateColor = 'cyan';
break;
case ExtensionUpdateState.UPDATE_AVAILABLE:
case ExtensionUpdateState.UPDATED_NEEDS_RESTART:
stateColor = 'yellow';
break;
case ExtensionUpdateState.ERROR:
stateColor = 'red';
break;
case ExtensionUpdateState.UP_TO_DATE:
case ExtensionUpdateState.NOT_UPDATABLE:
stateColor = 'green';
break;
default:
console.error(`Unhandled ExtensionUpdateState ${state}`);
break;
}
return (
<Box key={ext.name}>
<Text>
<Text color="cyan">{`${ext.name} (v${ext.version})`}</Text>
{` - ${activeString}`}
{<Text color={stateColor}>{` (${stateText})`}</Text>}
</Text>
</Box>
);
})}
</Box>
</Box>
);
};
@@ -27,6 +27,7 @@ import type {
import type { DOMElement } from 'ink'; import type { DOMElement } from 'ink';
import type { SessionStatsState } from '../contexts/SessionContext.js'; import type { SessionStatsState } from '../contexts/SessionContext.js';
import type { UpdateObject } from '../utils/updateCheck.js'; import type { UpdateObject } from '../utils/updateCheck.js';
import type { ExtensionUpdateState } from '../state/extensions.js';
export interface ProQuotaDialogRequest { export interface ProQuotaDialogRequest {
failedModel: string; failedModel: string;
@@ -108,6 +109,7 @@ export interface UIState {
updateInfo: UpdateObject | null; updateInfo: UpdateObject | null;
showIdeRestartPrompt: boolean; showIdeRestartPrompt: boolean;
isRestarting: boolean; isRestarting: boolean;
extensionsUpdateState: Map<string, ExtensionUpdateState>;
activePtyId: number | undefined; activePtyId: number | undefined;
shellFocused: boolean; shellFocused: boolean;
} }
@@ -33,6 +33,7 @@ import { CommandService } from '../../services/CommandService.js';
import { BuiltinCommandLoader } from '../../services/BuiltinCommandLoader.js'; import { BuiltinCommandLoader } from '../../services/BuiltinCommandLoader.js';
import { FileCommandLoader } from '../../services/FileCommandLoader.js'; import { FileCommandLoader } from '../../services/FileCommandLoader.js';
import { McpPromptLoader } from '../../services/McpPromptLoader.js'; import { McpPromptLoader } from '../../services/McpPromptLoader.js';
import type { ExtensionUpdateState } from '../state/extensions.js';
interface SlashCommandProcessorActions { interface SlashCommandProcessorActions {
openAuthDialog: () => void; openAuthDialog: () => void;
@@ -43,6 +44,9 @@ interface SlashCommandProcessorActions {
quit: (messages: HistoryItem[]) => void; quit: (messages: HistoryItem[]) => void;
setDebugMessage: (message: string) => void; setDebugMessage: (message: string) => void;
toggleCorgiMode: () => void; toggleCorgiMode: () => void;
setExtensionsUpdateState: (
updateState: Map<string, ExtensionUpdateState>,
) => void;
} }
/** /**
@@ -59,6 +63,7 @@ export const useSlashCommandProcessor = (
setIsProcessing: (isProcessing: boolean) => void, setIsProcessing: (isProcessing: boolean) => void,
setGeminiMdFileCount: (count: number) => void, setGeminiMdFileCount: (count: number) => void,
actions: SlashCommandProcessorActions, actions: SlashCommandProcessorActions,
extensionsUpdateState: Map<string, ExtensionUpdateState>,
isConfigInitialized: boolean, isConfigInitialized: boolean,
) => { ) => {
const session = useSessionStats(); const session = useSessionStats();
@@ -101,16 +106,17 @@ export const useSlashCommandProcessor = (
return l; return l;
}, [config]); }, [config]);
const [pendingCompressionItem, setPendingCompressionItem] = const [pendingItem, setPendingItem] = useState<HistoryItemWithoutId | null>(
useState<HistoryItemWithoutId | null>(null); null,
);
const pendingHistoryItems = useMemo(() => { const pendingHistoryItems = useMemo(() => {
const items: HistoryItemWithoutId[] = []; const items: HistoryItemWithoutId[] = [];
if (pendingCompressionItem != null) { if (pendingItem != null) {
items.push(pendingCompressionItem); items.push(pendingItem);
} }
return items; return items;
}, [pendingCompressionItem]); }, [pendingItem]);
const addMessage = useCallback( const addMessage = useCallback(
(message: Message) => { (message: Message) => {
@@ -182,12 +188,14 @@ export const useSlashCommandProcessor = (
}, },
loadHistory, loadHistory,
setDebugMessage: actions.setDebugMessage, setDebugMessage: actions.setDebugMessage,
pendingItem: pendingCompressionItem, pendingItem,
setPendingItem: setPendingCompressionItem, setPendingItem,
toggleCorgiMode: actions.toggleCorgiMode, toggleCorgiMode: actions.toggleCorgiMode,
toggleVimEnabled, toggleVimEnabled,
setGeminiMdFileCount, setGeminiMdFileCount,
reloadCommands, reloadCommands,
extensionsUpdateState,
setExtensionsUpdateState: actions.setExtensionsUpdateState,
}, },
session: { session: {
stats: session.stats, stats: session.stats,
@@ -205,12 +213,13 @@ export const useSlashCommandProcessor = (
refreshStatic, refreshStatic,
session.stats, session.stats,
actions, actions,
pendingCompressionItem, pendingItem,
setPendingCompressionItem, setPendingItem,
toggleVimEnabled, toggleVimEnabled,
sessionShellAllowlist, sessionShellAllowlist,
setGeminiMdFileCount, setGeminiMdFileCount,
reloadCommands, reloadCommands,
extensionsUpdateState,
], ],
); );
+15
View File
@@ -0,0 +1,15 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
export enum ExtensionUpdateState {
CHECKING_FOR_UPDATES = 'checking for updates',
UPDATED_NEEDS_RESTART = 'updated, needs restart',
UPDATING = 'updating',
UPDATE_AVAILABLE = 'update available',
UP_TO_DATE = 'up to date',
ERROR = 'error checking for updates',
NOT_UPDATABLE = 'not updatable',
}
+7 -1
View File
@@ -155,6 +155,10 @@ export type HistoryItemCompression = HistoryItemBase & {
compression: CompressionProps; compression: CompressionProps;
}; };
export type HistoryItemExtensionsList = HistoryItemBase & {
type: 'extensions_list';
};
// Using Omit<HistoryItem, 'id'> seems to have some issues with typescript's // Using Omit<HistoryItem, 'id'> seems to have some issues with typescript's
// type inference e.g. historyItem.type === 'tool_group' isn't auto-inferring that // type inference e.g. historyItem.type === 'tool_group' isn't auto-inferring that
// 'tools' in historyItem. // 'tools' in historyItem.
@@ -173,7 +177,8 @@ export type HistoryItemWithoutId =
| HistoryItemModelStats | HistoryItemModelStats
| HistoryItemToolStats | HistoryItemToolStats
| HistoryItemQuit | HistoryItemQuit
| HistoryItemCompression; | HistoryItemCompression
| HistoryItemExtensionsList;
export type HistoryItem = HistoryItemWithoutId & { id: number }; export type HistoryItem = HistoryItemWithoutId & { id: number };
@@ -190,6 +195,7 @@ export enum MessageType {
QUIT = 'quit', QUIT = 'quit',
GEMINI = 'gemini', GEMINI = 'gemini',
COMPRESSION = 'compression', COMPRESSION = 'compression',
EXTENSIONS_LIST = 'extensions_list',
} }
// Simplified message structure for internal feedback // Simplified message structure for internal feedback
+4
View File
@@ -115,7 +115,11 @@ export interface GeminiCLIExtension {
version: string; version: string;
isActive: boolean; isActive: boolean;
path: string; path: string;
source?: string;
type?: 'git' | 'local' | 'link';
ref?: string;
} }
export interface FileFilteringOptions { export interface FileFilteringOptions {
respectGitIgnore: boolean; respectGitIgnore: boolean;
respectGeminiIgnore: boolean; respectGeminiIgnore: boolean;