From 9172e28315427a08367edd0de431455df12d6199 Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Tue, 6 Jan 2026 14:06:15 -0500 Subject: [PATCH 001/713] Add description for each settings item in /settings (#15936) --- .../src/ui/components/SettingsDialog.test.tsx | 17 ++ .../cli/src/ui/components/SettingsDialog.tsx | 117 +++++++--- .../SettingsDialog.test.tsx.snap | 216 ++++++++++++------ 3 files changed, 243 insertions(+), 107 deletions(-) diff --git a/packages/cli/src/ui/components/SettingsDialog.test.tsx b/packages/cli/src/ui/components/SettingsDialog.test.tsx index 82750be0ee..2c0c10e502 100644 --- a/packages/cli/src/ui/components/SettingsDialog.test.tsx +++ b/packages/cli/src/ui/components/SettingsDialog.test.tsx @@ -308,6 +308,23 @@ describe('SettingsDialog', () => { }); }); + describe('Setting Descriptions', () => { + it('should render descriptions for settings that have them', () => { + const settings = createMockSettings(); + const onSelect = vi.fn(); + + const { lastFrame } = renderDialog(settings, onSelect); + + const output = lastFrame(); + // 'general.vimMode' has description 'Enable Vim keybindings' in settingsSchema.ts + expect(output).toContain('Vim Mode'); + expect(output).toContain('Enable Vim keybindings'); + // 'general.disableAutoUpdate' has description 'Disable automatic updates' + expect(output).toContain('Disable Auto Update'); + expect(output).toContain('Disable automatic updates'); + }); + }); + describe('Settings Navigation', () => { it.each([ { diff --git a/packages/cli/src/ui/components/SettingsDialog.tsx b/packages/cli/src/ui/components/SettingsDialog.tsx index 1b1235edde..b0c40e2d2c 100644 --- a/packages/cli/src/ui/components/SettingsDialog.tsx +++ b/packages/cli/src/ui/components/SettingsDialog.tsx @@ -37,7 +37,12 @@ import { import { useVimMode } from '../contexts/VimModeContext.js'; import { useKeypress } from '../hooks/useKeypress.js'; import chalk from 'chalk'; -import { cpSlice, cpLen, stripUnsafeCharacters } from '../utils/textUtils.js'; +import { + cpSlice, + cpLen, + stripUnsafeCharacters, + getCachedStringWidth, +} from '../utils/textUtils.js'; import { type SettingsValue, TOGGLE_TYPES, @@ -65,7 +70,7 @@ interface SettingsDialogProps { config?: Config; } -const maxItemsToShow = 8; +const MAX_ITEMS_TO_SHOW = 8; export function SettingsDialog({ settings, @@ -194,6 +199,31 @@ export function SettingsDialog({ setShowRestartPrompt(newRestartRequired.size > 0); }, [selectedScope, settings, globalPendingChanges]); + // Calculate max width for the left column (Label/Description) to keep values aligned or close + const maxLabelOrDescriptionWidth = useMemo(() => { + const allKeys = getDialogSettingKeys(); + let max = 0; + for (const key of allKeys) { + const def = getSettingDefinition(key); + if (!def) continue; + + const scopeMessage = getScopeMessageForSetting( + key, + selectedScope, + settings, + ); + const label = def.label || key; + const labelFull = label + (scopeMessage ? ` ${scopeMessage}` : ''); + const lWidth = getCachedStringWidth(labelFull); + const dWidth = def.description + ? getCachedStringWidth(def.description) + : 0; + + max = Math.max(max, lWidth, dWidth); + } + return max; + }, [selectedScope, settings]); + const generateSettingsItems = () => { const settingKeys = searchQuery ? filteredKeys : getDialogSettingKeys(); @@ -202,6 +232,7 @@ export function SettingsDialog({ return { label: definition?.label || key, + description: definition?.description, value: key, type: definition?.type, toggle: () => { @@ -478,8 +509,8 @@ export function SettingsDialog({ currentAvailableTerminalHeight - totalFixedHeight, ); - // Each setting item takes 2 lines (the setting row + spacing) - let maxVisibleItems = Math.max(1, Math.floor(availableHeightForSettings / 2)); + // Each setting item takes up to 3 lines (label/value row, description row, and spacing) + let maxVisibleItems = Math.max(1, Math.floor(availableHeightForSettings / 3)); // Decide whether to show scope selection based on remaining space let showScopeSelection = true; @@ -492,7 +523,7 @@ export function SettingsDialog({ 1, currentAvailableTerminalHeight - totalWithScope, ); - const maxItemsWithScope = Math.max(1, Math.floor(availableWithScope / 2)); + const maxItemsWithScope = Math.max(1, Math.floor(availableWithScope / 3)); // If hiding scope selection allows us to show significantly more settings, do it if (maxVisibleItems > maxItemsWithScope + 1) { @@ -504,7 +535,7 @@ export function SettingsDialog({ 1, currentAvailableTerminalHeight - totalFixedHeight, ); - maxVisibleItems = Math.max(1, Math.floor(availableHeightForSettings / 2)); + maxVisibleItems = Math.max(1, Math.floor(availableHeightForSettings / 3)); } } else { // For normal height, include scope selection @@ -513,13 +544,13 @@ export function SettingsDialog({ 1, currentAvailableTerminalHeight - totalFixedHeight, ); - maxVisibleItems = Math.max(1, Math.floor(availableHeightForSettings / 2)); + maxVisibleItems = Math.max(1, Math.floor(availableHeightForSettings / 3)); } // Use the calculated maxVisibleItems or fall back to the original maxItemsToShow const effectiveMaxItemsToShow = availableTerminalHeight ? Math.min(maxVisibleItems, items.length) - : maxItemsToShow; + : MAX_ITEMS_TO_SHOW; // Ensure focus stays on settings when scope selection is hidden React.useEffect(() => { @@ -979,7 +1010,7 @@ export function SettingsDialog({ return ( - + - - - {item.label} - {scopeMessage && ( - - {' '} - {scopeMessage} - - )} - - - - - {displayValue} - + + + {item.label} + {scopeMessage && ( + + {' '} + {scopeMessage} + + )} + + + {item.description ?? ''} + + + + + + {displayValue} + + + diff --git a/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap index b6f3079414..90392e72f1 100644 --- a/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap +++ b/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap @@ -10,21 +10,29 @@ exports[`SettingsDialog > Initial Rendering > should render settings list with v │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ ▲ │ -│ ● Preview Features (e.g., models) false │ +│ ● Preview Features (e.g., models) false │ +│ Enable preview features (e.g., preview models). │ │ │ -│ Vim Mode false │ +│ Vim Mode false │ +│ Enable Vim keybindings │ │ │ -│ Disable Auto Update false │ +│ Disable Auto Update false │ +│ Disable automatic updates │ │ │ -│ Enable Prompt Completion false │ +│ Enable Prompt Completion false │ +│ Enable AI-powered prompt completion suggestions while typing. │ │ │ -│ Debug Keystroke Logging false │ +│ Debug Keystroke Logging false │ +│ Enable debug logging of keystrokes to the console. │ │ │ -│ Enable Session Cleanup false │ +│ Enable Session Cleanup false │ +│ Enable automatic session cleanup │ │ │ -│ Output Format Text │ +│ Output Format Text │ +│ The format of the CLI output. │ │ │ -│ Hide Window Title false │ +│ Hide Window Title false │ +│ Hide the window title bar │ │ │ │ ▼ │ │ │ @@ -48,21 +56,29 @@ exports[`SettingsDialog > Snapshot Tests > should render 'accessibility settings │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ ▲ │ -│ ● Preview Features (e.g., models) false │ +│ ● Preview Features (e.g., models) false │ +│ Enable preview features (e.g., preview models). │ │ │ -│ Vim Mode true* │ +│ Vim Mode true* │ +│ Enable Vim keybindings │ │ │ -│ Disable Auto Update false │ +│ Disable Auto Update false │ +│ Disable automatic updates │ │ │ -│ Enable Prompt Completion false │ +│ Enable Prompt Completion false │ +│ Enable AI-powered prompt completion suggestions while typing. │ │ │ -│ Debug Keystroke Logging false │ +│ Debug Keystroke Logging false │ +│ Enable debug logging of keystrokes to the console. │ │ │ -│ Enable Session Cleanup false │ +│ Enable Session Cleanup false │ +│ Enable automatic session cleanup │ │ │ -│ Output Format Text │ +│ Output Format Text │ +│ The format of the CLI output. │ │ │ -│ Hide Window Title false │ +│ Hide Window Title false │ +│ Hide the window title bar │ │ │ │ ▼ │ │ │ @@ -86,21 +102,29 @@ exports[`SettingsDialog > Snapshot Tests > should render 'all boolean settings d │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ ▲ │ -│ ● Preview Features (e.g., models) false │ +│ ● Preview Features (e.g., models) false │ +│ Enable preview features (e.g., preview models). │ │ │ -│ Vim Mode false* │ +│ Vim Mode false* │ +│ Enable Vim keybindings │ │ │ -│ Disable Auto Update false* │ +│ Disable Auto Update false* │ +│ Disable automatic updates │ │ │ -│ Enable Prompt Completion false* │ +│ Enable Prompt Completion false* │ +│ Enable AI-powered prompt completion suggestions while typing. │ │ │ -│ Debug Keystroke Logging false* │ +│ Debug Keystroke Logging false* │ +│ Enable debug logging of keystrokes to the console. │ │ │ -│ Enable Session Cleanup false │ +│ Enable Session Cleanup false │ +│ Enable automatic session cleanup │ │ │ -│ Output Format Text │ +│ Output Format Text │ +│ The format of the CLI output. │ │ │ -│ Hide Window Title false* │ +│ Hide Window Title false* │ +│ Hide the window title bar │ │ │ │ ▼ │ │ │ @@ -124,21 +148,29 @@ exports[`SettingsDialog > Snapshot Tests > should render 'default state' correct │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ ▲ │ -│ ● Preview Features (e.g., models) false │ +│ ● Preview Features (e.g., models) false │ +│ Enable preview features (e.g., preview models). │ │ │ -│ Vim Mode false │ +│ Vim Mode false │ +│ Enable Vim keybindings │ │ │ -│ Disable Auto Update false │ +│ Disable Auto Update false │ +│ Disable automatic updates │ │ │ -│ Enable Prompt Completion false │ +│ Enable Prompt Completion false │ +│ Enable AI-powered prompt completion suggestions while typing. │ │ │ -│ Debug Keystroke Logging false │ +│ Debug Keystroke Logging false │ +│ Enable debug logging of keystrokes to the console. │ │ │ -│ Enable Session Cleanup false │ +│ Enable Session Cleanup false │ +│ Enable automatic session cleanup │ │ │ -│ Output Format Text │ +│ Output Format Text │ +│ The format of the CLI output. │ │ │ -│ Hide Window Title false │ +│ Hide Window Title false │ +│ Hide the window title bar │ │ │ │ ▼ │ │ │ @@ -162,21 +194,29 @@ exports[`SettingsDialog > Snapshot Tests > should render 'file filtering setting │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ ▲ │ -│ ● Preview Features (e.g., models) false │ +│ ● Preview Features (e.g., models) false │ +│ Enable preview features (e.g., preview models). │ │ │ -│ Vim Mode false │ +│ Vim Mode false │ +│ Enable Vim keybindings │ │ │ -│ Disable Auto Update false │ +│ Disable Auto Update false │ +│ Disable automatic updates │ │ │ -│ Enable Prompt Completion false │ +│ Enable Prompt Completion false │ +│ Enable AI-powered prompt completion suggestions while typing. │ │ │ -│ Debug Keystroke Logging false │ +│ Debug Keystroke Logging false │ +│ Enable debug logging of keystrokes to the console. │ │ │ -│ Enable Session Cleanup false │ +│ Enable Session Cleanup false │ +│ Enable automatic session cleanup │ │ │ -│ Output Format Text │ +│ Output Format Text │ +│ The format of the CLI output. │ │ │ -│ Hide Window Title false │ +│ Hide Window Title false │ +│ Hide the window title bar │ │ │ │ ▼ │ │ │ @@ -200,21 +240,29 @@ exports[`SettingsDialog > Snapshot Tests > should render 'focused on scope selec │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ ▲ │ -│ Preview Features (e.g., models) false │ +│ Preview Features (e.g., models) false │ +│ Enable preview features (e.g., preview models). │ │ │ -│ Vim Mode false │ +│ Vim Mode false │ +│ Enable Vim keybindings │ │ │ -│ Disable Auto Update false │ +│ Disable Auto Update false │ +│ Disable automatic updates │ │ │ -│ Enable Prompt Completion false │ +│ Enable Prompt Completion false │ +│ Enable AI-powered prompt completion suggestions while typing. │ │ │ -│ Debug Keystroke Logging false │ +│ Debug Keystroke Logging false │ +│ Enable debug logging of keystrokes to the console. │ │ │ -│ Enable Session Cleanup false │ +│ Enable Session Cleanup false │ +│ Enable automatic session cleanup │ │ │ -│ Output Format Text │ +│ Output Format Text │ +│ The format of the CLI output. │ │ │ -│ Hide Window Title false │ +│ Hide Window Title false │ +│ Hide the window title bar │ │ │ │ ▼ │ │ │ @@ -238,21 +286,29 @@ exports[`SettingsDialog > Snapshot Tests > should render 'mixed boolean and numb │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ ▲ │ -│ ● Preview Features (e.g., models) false │ +│ ● Preview Features (e.g., models) false │ +│ Enable preview features (e.g., preview models). │ │ │ -│ Vim Mode false* │ +│ Vim Mode false* │ +│ Enable Vim keybindings │ │ │ -│ Disable Auto Update true* │ +│ Disable Auto Update true* │ +│ Disable automatic updates │ │ │ -│ Enable Prompt Completion false │ +│ Enable Prompt Completion false │ +│ Enable AI-powered prompt completion suggestions while typing. │ │ │ -│ Debug Keystroke Logging false │ +│ Debug Keystroke Logging false │ +│ Enable debug logging of keystrokes to the console. │ │ │ -│ Enable Session Cleanup false │ +│ Enable Session Cleanup false │ +│ Enable automatic session cleanup │ │ │ -│ Output Format Text │ +│ Output Format Text │ +│ The format of the CLI output. │ │ │ -│ Hide Window Title false* │ +│ Hide Window Title false* │ +│ Hide the window title bar │ │ │ │ ▼ │ │ │ @@ -276,21 +332,29 @@ exports[`SettingsDialog > Snapshot Tests > should render 'tools and security set │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ ▲ │ -│ ● Preview Features (e.g., models) false │ +│ ● Preview Features (e.g., models) false │ +│ Enable preview features (e.g., preview models). │ │ │ -│ Vim Mode false │ +│ Vim Mode false │ +│ Enable Vim keybindings │ │ │ -│ Disable Auto Update false │ +│ Disable Auto Update false │ +│ Disable automatic updates │ │ │ -│ Enable Prompt Completion false │ +│ Enable Prompt Completion false │ +│ Enable AI-powered prompt completion suggestions while typing. │ │ │ -│ Debug Keystroke Logging false │ +│ Debug Keystroke Logging false │ +│ Enable debug logging of keystrokes to the console. │ │ │ -│ Enable Session Cleanup false │ +│ Enable Session Cleanup false │ +│ Enable automatic session cleanup │ │ │ -│ Output Format Text │ +│ Output Format Text │ +│ The format of the CLI output. │ │ │ -│ Hide Window Title false │ +│ Hide Window Title false │ +│ Hide the window title bar │ │ │ │ ▼ │ │ │ @@ -314,21 +378,29 @@ exports[`SettingsDialog > Snapshot Tests > should render 'various boolean settin │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ ▲ │ -│ ● Preview Features (e.g., models) false │ +│ ● Preview Features (e.g., models) false │ +│ Enable preview features (e.g., preview models). │ │ │ -│ Vim Mode true* │ +│ Vim Mode true* │ +│ Enable Vim keybindings │ │ │ -│ Disable Auto Update true* │ +│ Disable Auto Update true* │ +│ Disable automatic updates │ │ │ -│ Enable Prompt Completion true* │ +│ Enable Prompt Completion true* │ +│ Enable AI-powered prompt completion suggestions while typing. │ │ │ -│ Debug Keystroke Logging true* │ +│ Debug Keystroke Logging true* │ +│ Enable debug logging of keystrokes to the console. │ │ │ -│ Enable Session Cleanup false │ +│ Enable Session Cleanup false │ +│ Enable automatic session cleanup │ │ │ -│ Output Format Text │ +│ Output Format Text │ +│ The format of the CLI output. │ │ │ -│ Hide Window Title true* │ +│ Hide Window Title true* │ +│ Hide the window title bar │ │ │ │ ▼ │ │ │ From cce4574143a2766d60aa88ca8c79c237ea3c2a4c Mon Sep 17 00:00:00 2001 From: Ishaan Gupta Date: Wed, 7 Jan 2026 00:38:59 +0530 Subject: [PATCH 002/713] Use GetOperation to poll for OnboardUser completion (#15827) Co-authored-by: Vedant Mahajan Co-authored-by: Tommaso Sciortino --- packages/core/src/code_assist/server.test.ts | 25 +++++++ packages/core/src/code_assist/server.ts | 32 +++++++-- packages/core/src/code_assist/setup.test.ts | 75 ++++++++++++++++++++ packages/core/src/code_assist/setup.ts | 10 +-- 4 files changed, 133 insertions(+), 9 deletions(-) diff --git a/packages/core/src/code_assist/server.test.ts b/packages/core/src/code_assist/server.test.ts index a30023f408..930e7dfdb2 100644 --- a/packages/core/src/code_assist/server.test.ts +++ b/packages/core/src/code_assist/server.test.ts @@ -432,6 +432,31 @@ describe('CodeAssistServer', () => { expect(response.name).toBe('operations/123'); }); + it('should call the getOperation endpoint', async () => { + const { server } = createTestServer(); + + const mockResponse = { + name: 'operations/123', + done: true, + response: { + cloudaicompanionProject: { + id: 'test-project', + name: 'projects/test-project', + }, + }, + }; + vi.spyOn(server, 'requestGetOperation').mockResolvedValue(mockResponse); + + const response = await server.getOperation('operations/123'); + + expect(server.requestGetOperation).toHaveBeenCalledWith('operations/123'); + expect(response.name).toBe('operations/123'); + expect(response.response?.cloudaicompanionProject?.id).toBe('test-project'); + expect(response.response?.cloudaicompanionProject?.name).toBe( + 'projects/test-project', + ); + }); + it('should call the loadCodeAssist endpoint', async () => { const { server } = createTestServer(); const mockResponse = { diff --git a/packages/core/src/code_assist/server.ts b/packages/core/src/code_assist/server.ts index bf2f693ad1..2fd45e0fd4 100644 --- a/packages/core/src/code_assist/server.ts +++ b/packages/core/src/code_assist/server.ts @@ -51,7 +51,6 @@ import { recordConversationOffered, } from './telemetry.js'; import { getClientMetadata } from './experiments/client_metadata.js'; - /** HTTP options to be used in each of the requests. */ export interface HttpOptions { /** Additional HTTP headers to be sent with the request. */ @@ -160,6 +159,10 @@ export class CodeAssistServer implements ContentGenerator { return this.requestPost('onboardUser', req); } + async getOperation(name: string): Promise { + return this.requestGetOperation(name); + } + async loadCodeAssist( req: LoadCodeAssistRequest, ): Promise { @@ -289,9 +292,12 @@ export class CodeAssistServer implements ContentGenerator { return res.data as T; } - async requestGet(method: string, signal?: AbortSignal): Promise { + private async makeGetRequest( + url: string, + signal?: AbortSignal, + ): Promise { const res = await this.client.request({ - url: this.getMethodUrl(method), + url, method: 'GET', headers: { 'Content-Type': 'application/json', @@ -303,6 +309,14 @@ export class CodeAssistServer implements ContentGenerator { return res.data as T; } + async requestGet(method: string, signal?: AbortSignal): Promise { + return this.makeGetRequest(this.getMethodUrl(method), signal); + } + + async requestGetOperation(name: string, signal?: AbortSignal): Promise { + return this.makeGetRequest(this.getOperationUrl(name), signal); + } + async requestStreamingPost( method: string, req: object, @@ -345,10 +359,18 @@ export class CodeAssistServer implements ContentGenerator { })(); } - getMethodUrl(method: string): string { + private getBaseUrl(): string { const endpoint = process.env['CODE_ASSIST_ENDPOINT'] ?? CODE_ASSIST_ENDPOINT; - return `${endpoint}/${CODE_ASSIST_API_VERSION}:${method}`; + return `${endpoint}/${CODE_ASSIST_API_VERSION}`; + } + + getMethodUrl(method: string): string { + return `${this.getBaseUrl()}:${method}`; + } + + getOperationUrl(name: string): string { + return `${this.getBaseUrl()}/${name}`; } } diff --git a/packages/core/src/code_assist/setup.test.ts b/packages/core/src/code_assist/setup.test.ts index 54ad7f2499..2a9640f703 100644 --- a/packages/core/src/code_assist/setup.test.ts +++ b/packages/core/src/code_assist/setup.test.ts @@ -106,9 +106,11 @@ describe('setupUser for existing user', () => { describe('setupUser for new user', () => { let mockLoad: ReturnType; let mockOnboardUser: ReturnType; + let mockGetOperation: ReturnType; beforeEach(() => { vi.resetAllMocks(); + vi.useFakeTimers(); mockLoad = vi.fn(); mockOnboardUser = vi.fn().mockResolvedValue({ done: true, @@ -118,16 +120,19 @@ describe('setupUser for new user', () => { }, }, }); + mockGetOperation = vi.fn(); vi.mocked(CodeAssistServer).mockImplementation( () => ({ loadCodeAssist: mockLoad, onboardUser: mockOnboardUser, + getOperation: mockGetOperation, }) as unknown as CodeAssistServer, ); }); afterEach(() => { + vi.useRealTimers(); vi.unstubAllEnvs(); }); @@ -221,4 +226,74 @@ describe('setupUser for new user', () => { ProjectIdRequiredError, ); }); + + it('should poll getOperation when onboardUser returns done=false', async () => { + vi.stubEnv('GOOGLE_CLOUD_PROJECT', 'test-project'); + mockLoad.mockResolvedValue({ + allowedTiers: [mockPaidTier], + }); + + const operationName = 'operations/123'; + + mockOnboardUser.mockResolvedValueOnce({ + name: operationName, + done: false, + }); + + mockGetOperation + .mockResolvedValueOnce({ + name: operationName, + done: false, + }) + .mockResolvedValueOnce({ + name: operationName, + done: true, + response: { + cloudaicompanionProject: { + id: 'server-project', + }, + }, + }); + + const setupPromise = setupUser({} as OAuth2Client); + + await vi.advanceTimersByTimeAsync(5000); + await vi.advanceTimersByTimeAsync(5000); + + const userData = await setupPromise; + + expect(mockOnboardUser).toHaveBeenCalledTimes(1); + expect(mockGetOperation).toHaveBeenCalledTimes(2); + expect(mockGetOperation).toHaveBeenCalledWith(operationName); + expect(userData).toEqual({ + projectId: 'server-project', + userTier: 'standard-tier', + }); + }); + + it('should not poll getOperation when onboardUser returns done=true immediately', async () => { + vi.stubEnv('GOOGLE_CLOUD_PROJECT', 'test-project'); + mockLoad.mockResolvedValue({ + allowedTiers: [mockPaidTier], + }); + + mockOnboardUser.mockResolvedValueOnce({ + name: 'operations/123', + done: true, + response: { + cloudaicompanionProject: { + id: 'server-project', + }, + }, + }); + + const userData = await setupUser({} as OAuth2Client); + + expect(mockOnboardUser).toHaveBeenCalledTimes(1); + expect(mockGetOperation).not.toHaveBeenCalled(); + expect(userData).toEqual({ + projectId: 'server-project', + userTier: 'standard-tier', + }); + }); }); diff --git a/packages/core/src/code_assist/setup.ts b/packages/core/src/code_assist/setup.ts index d33c019d6c..2d137607a2 100644 --- a/packages/core/src/code_assist/setup.ts +++ b/packages/core/src/code_assist/setup.ts @@ -89,11 +89,13 @@ export async function setupUser(client: AuthClient): Promise { }; } - // Poll onboardUser until long running operation is complete. let lroRes = await caServer.onboardUser(onboardReq); - while (!lroRes.done) { - await new Promise((f) => setTimeout(f, 5000)); - lroRes = await caServer.onboardUser(onboardReq); + if (!lroRes.done && lroRes.name) { + const operationName = lroRes.name; + while (!lroRes.done) { + await new Promise((f) => setTimeout(f, 5000)); + lroRes = await caServer.getOperation(operationName); + } } if (!lroRes.response?.cloudaicompanionProject?.id) { From 0c5413624415520a1bc5655a836b8c5f6737ceee Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 6 Jan 2026 11:24:37 -0800 Subject: [PATCH 003/713] Agent Skills: Add skill directory to WorkspaceContext upon activation (#15870) --- packages/core/src/tools/activate-skill.test.ts | 6 ++++++ packages/core/src/tools/activate-skill.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/core/src/tools/activate-skill.test.ts b/packages/core/src/tools/activate-skill.test.ts index 3e7fe4a6e8..4843a534e9 100644 --- a/packages/core/src/tools/activate-skill.test.ts +++ b/packages/core/src/tools/activate-skill.test.ts @@ -29,6 +29,9 @@ describe('ActivateSkillTool', () => { }, ]; mockConfig = { + getWorkspaceContext: vi.fn().mockReturnValue({ + addDirectory: vi.fn(), + }), getSkillManager: vi.fn().mockReturnValue({ getSkills: vi.fn().mockReturnValue(skills), getAllSkills: vi.fn().mockReturnValue(skills), @@ -81,6 +84,9 @@ describe('ActivateSkillTool', () => { expect(mockConfig.getSkillManager().activateSkill).toHaveBeenCalledWith( 'test-skill', ); + expect(mockConfig.getWorkspaceContext().addDirectory).toHaveBeenCalledWith( + '/path/to/test-skill', + ); expect(result.llmContent).toContain(''); expect(result.llmContent).toContain(''); expect(result.llmContent).toContain('Skill instructions content.'); diff --git a/packages/core/src/tools/activate-skill.ts b/packages/core/src/tools/activate-skill.ts index 31ee4d0c24..517c3e1a17 100644 --- a/packages/core/src/tools/activate-skill.ts +++ b/packages/core/src/tools/activate-skill.ts @@ -115,6 +115,12 @@ ${folderStructure}`, skillManager.activateSkill(skillName); + // Add the skill's directory to the workspace context so the agent has permission + // to read its bundled resources. + this.config + .getWorkspaceContext() + .addDirectory(path.dirname(skill.location)); + const folderStructure = await this.getOrFetchFolderStructure( skill.location, ); From 7edd8030344e1eae72e90c54debabc9f6f06e867 Mon Sep 17 00:00:00 2001 From: christine betts Date: Tue, 6 Jan 2026 14:50:27 -0500 Subject: [PATCH 004/713] Fix settings command fallback (#15926) --- .../src/commands/extensions/settings.test.ts | 231 ++++++++++++++++++ .../cli/src/commands/extensions/settings.ts | 4 + 2 files changed, 235 insertions(+) create mode 100644 packages/cli/src/commands/extensions/settings.test.ts diff --git a/packages/cli/src/commands/extensions/settings.test.ts b/packages/cli/src/commands/extensions/settings.test.ts new file mode 100644 index 0000000000..db8c14a922 --- /dev/null +++ b/packages/cli/src/commands/extensions/settings.test.ts @@ -0,0 +1,231 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + describe, + it, + expect, + vi, + beforeEach, + afterEach, + type Mock, +} from 'vitest'; +import { settingsCommand } from './settings.js'; +import yargs from 'yargs'; +import { debugLogger, type GeminiCLIExtension } from '@google/gemini-cli-core'; +import type { getExtensionAndManager } from './utils.js'; +import type { + updateSetting, + getScopedEnvContents, +} from '../../config/extensions/extensionSettings.js'; +import { + promptForSetting, + ExtensionSettingScope, +} from '../../config/extensions/extensionSettings.js'; +import type { exitCli } from '../utils.js'; +import type { ExtensionManager } from '../../config/extension-manager.js'; + +const mockGetExtensionAndManager: Mock = + vi.hoisted(() => vi.fn()); +const mockUpdateSetting: Mock = vi.hoisted(() => vi.fn()); +const mockGetScopedEnvContents: Mock = vi.hoisted( + () => vi.fn(), +); +const mockExitCli: Mock = vi.hoisted(() => vi.fn()); + +vi.mock('./utils.js', () => ({ + getExtensionAndManager: mockGetExtensionAndManager, +})); + +vi.mock('../../config/extensions/extensionSettings.js', () => ({ + updateSetting: mockUpdateSetting, + promptForSetting: vi.fn(), + ExtensionSettingScope: { + USER: 'user', + WORKSPACE: 'workspace', + }, + getScopedEnvContents: mockGetScopedEnvContents, +})); + +vi.mock('@google/gemini-cli-core', () => ({ + debugLogger: { + log: vi.fn(), + error: vi.fn(), + }, +})); + +vi.mock('../utils.js', () => ({ + exitCli: mockExitCli, +})); + +describe('settings command', () => { + let debugLogSpy: Mock; + let debugErrorSpy: Mock; + + beforeEach(() => { + debugLogSpy = debugLogger.log as Mock; + debugErrorSpy = debugLogger.error as Mock; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('set command', () => { + it('should log error and exit if extension is not found', async () => { + mockGetExtensionAndManager.mockResolvedValue({ + extension: null, + extensionManager: null, + }); + + await yargs([]) + .command(settingsCommand) + .parseAsync('settings set foo bar'); + + expect(mockExitCli).toHaveBeenCalled(); + }); + + it('should log error and exit if extension config is not found', async () => { + const mockExtensionManager = { + loadExtensionConfig: vi.fn().mockResolvedValue(null), + } as unknown as ExtensionManager; + mockGetExtensionAndManager.mockResolvedValue({ + extension: { path: '/path/to/ext' } as unknown as GeminiCLIExtension, + extensionManager: mockExtensionManager, + }); + + await yargs([]) + .command(settingsCommand) + .parseAsync('settings set foo bar'); + + expect(debugErrorSpy).toHaveBeenCalledWith( + 'Could not find configuration for extension "foo".', + ); + expect(mockExitCli).toHaveBeenCalled(); + }); + + it('should call updateSetting with correct arguments', async () => { + const mockExtensionManager = { + loadExtensionConfig: vi.fn().mockResolvedValue({}), + } as unknown as ExtensionManager; + const extension = { path: '/path/to/ext', id: 'ext-id' }; + mockGetExtensionAndManager.mockResolvedValue({ + extension: extension as unknown as GeminiCLIExtension, + extensionManager: mockExtensionManager, + }); + + await yargs([]) + .command(settingsCommand) + .parseAsync('settings set foo bar --scope workspace'); + + expect(mockUpdateSetting).toHaveBeenCalledWith( + {}, + 'ext-id', + 'bar', + promptForSetting, + ExtensionSettingScope.WORKSPACE, + ); + expect(mockExitCli).toHaveBeenCalled(); + }); + }); + + describe('list command', () => { + it('should log error and exit if extension is not found', async () => { + mockGetExtensionAndManager.mockResolvedValue({ + extension: null, + extensionManager: null, + }); + + await yargs([]).command(settingsCommand).parseAsync('settings list foo'); + + expect(mockExitCli).toHaveBeenCalled(); + }); + + it('should log message and exit if extension has no settings', async () => { + const mockExtensionManager = { + loadExtensionConfig: vi.fn().mockResolvedValue({ settings: [] }), + } as unknown as ExtensionManager; + mockGetExtensionAndManager.mockResolvedValue({ + extension: { path: '/path/to/ext' } as unknown as GeminiCLIExtension, + extensionManager: mockExtensionManager, + }); + + await yargs([]).command(settingsCommand).parseAsync('settings list foo'); + + expect(debugLogSpy).toHaveBeenCalledWith( + 'Extension "foo" has no settings to configure.', + ); + expect(mockExitCli).toHaveBeenCalled(); + }); + + it('should list settings correctly', async () => { + const mockExtensionManager = { + loadExtensionConfig: vi.fn().mockResolvedValue({ + settings: [ + { + name: 'Setting 1', + envVar: 'SETTING_1', + description: 'Desc 1', + sensitive: false, + }, + { + name: 'Setting 2', + envVar: 'SETTING_2', + description: 'Desc 2', + sensitive: true, + }, + { + name: 'Setting 3', + envVar: 'SETTING_3', + description: 'Desc 3', + sensitive: false, + }, + ], + }), + } as unknown as ExtensionManager; + const extension = { path: '/path/to/ext', id: 'ext-id' }; + mockGetExtensionAndManager.mockResolvedValue({ + extension: extension as unknown as GeminiCLIExtension, + extensionManager: mockExtensionManager, + }); + + mockGetScopedEnvContents.mockImplementation((_config, _id, scope) => { + if (scope === ExtensionSettingScope.USER) { + return Promise.resolve({ + SETTING_1: 'val1', + SETTING_2: 'val2', + }); + } + if (scope === ExtensionSettingScope.WORKSPACE) { + return Promise.resolve({ + SETTING_3: 'val3', + }); + } + return Promise.resolve({}); + }); + + await yargs([]).command(settingsCommand).parseAsync('settings list foo'); + + expect(debugLogSpy).toHaveBeenCalledWith('Settings for "foo":'); + // Setting 1 (User) + expect(debugLogSpy).toHaveBeenCalledWith('\n- Setting 1 (SETTING_1)'); + expect(debugLogSpy).toHaveBeenCalledWith(' Description: Desc 1'); + expect(debugLogSpy).toHaveBeenCalledWith(' Value: val1 (user)'); + // Setting 2 (Sensitive) + expect(debugLogSpy).toHaveBeenCalledWith('\n- Setting 2 (SETTING_2)'); + expect(debugLogSpy).toHaveBeenCalledWith(' Description: Desc 2'); + expect(debugLogSpy).toHaveBeenCalledWith( + ' Value: [value stored in keychain] (user)', + ); + // Setting 3 (Workspace) + expect(debugLogSpy).toHaveBeenCalledWith('\n- Setting 3 (SETTING_3)'); + expect(debugLogSpy).toHaveBeenCalledWith(' Description: Desc 3'); + expect(debugLogSpy).toHaveBeenCalledWith(' Value: val3 (workspace)'); + + expect(mockExitCli).toHaveBeenCalled(); + }); + }); +}); diff --git a/packages/cli/src/commands/extensions/settings.ts b/packages/cli/src/commands/extensions/settings.ts index 922f5aba71..f373534d7a 100644 --- a/packages/cli/src/commands/extensions/settings.ts +++ b/packages/cli/src/commands/extensions/settings.ts @@ -47,6 +47,7 @@ const setCommand: CommandModule = { const { name, setting, scope } = args; const { extension, extensionManager } = await getExtensionAndManager(name); if (!extension || !extensionManager) { + await exitCli(); return; } const extensionConfig = await extensionManager.loadExtensionConfig( @@ -56,6 +57,7 @@ const setCommand: CommandModule = { debugLogger.error( `Could not find configuration for extension "${name}".`, ); + await exitCli(); return; } await updateSetting( @@ -87,6 +89,7 @@ const listCommand: CommandModule = { const { name } = args; const { extension, extensionManager } = await getExtensionAndManager(name); if (!extension || !extensionManager) { + await exitCli(); return; } const extensionConfig = await extensionManager.loadExtensionConfig( @@ -98,6 +101,7 @@ const listCommand: CommandModule = { extensionConfig.settings.length === 0 ) { debugLogger.log(`Extension "${name}" has no settings to configure.`); + await exitCli(); return; } From a61fb058b7ca5c2b8b5ae24b6a9f6647cc9fbb30 Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Tue, 6 Jan 2026 12:08:25 -0800 Subject: [PATCH 005/713] fix: writeTodo construction (#16014) --- packages/core/src/config/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index bf16680f44..1891cfbc60 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -1725,7 +1725,7 @@ export class Config { registerCoreTool(MemoryTool); registerCoreTool(WebSearchTool, this); if (this.getUseWriteTodos()) { - registerCoreTool(WriteTodosTool, this); + registerCoreTool(WriteTodosTool); } // Register Subagents as Tools From d2849fda8ad46d314988d6e6a22a93bc2d8b5d9f Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Tue, 6 Jan 2026 12:11:43 -0800 Subject: [PATCH 006/713] properly disable keyboard modes on exit (#16006) --- .../src/ui/utils/terminalCapabilityManager.ts | 105 ++++-------------- 1 file changed, 21 insertions(+), 84 deletions(-) diff --git a/packages/cli/src/ui/utils/terminalCapabilityManager.ts b/packages/cli/src/ui/utils/terminalCapabilityManager.ts index f6838a79a0..5e5b8b490f 100644 --- a/packages/cli/src/ui/utils/terminalCapabilityManager.ts +++ b/packages/cli/src/ui/utils/terminalCapabilityManager.ts @@ -85,18 +85,14 @@ export class TerminalCapabilityManager { } const cleanupOnExit = () => { - if (this.kittySupported) { - this.disableKittyProtocol(); - } - if (this.modifyOtherKeysSupported) { - this.disableModifyOtherKeys(); - } - if (this.bracketedPasteSupported) { - this.disableBracketedPaste(); - } + // don't bother catching errors since if one write + // fails, the other probably will too + disableKittyKeyboardProtocol(); + disableModifyOtherKeys(); + disableBracketedPasteMode(); }; - process.on('exit', () => cleanupOnExit); - process.on('SIGTERM', () => cleanupOnExit); + process.on('exit', cleanupOnExit); + process.on('SIGTERM', cleanupOnExit); process.on('SIGINT', cleanupOnExit); return new Promise((resolve) => { @@ -234,13 +230,20 @@ export class TerminalCapabilityManager { } enableSupportedModes() { - if (this.kittySupported) { - this.enableKittyProtocol(); - } else if (this.modifyOtherKeysSupported) { - this.enableModifyOtherKeys(); - } - if (this.bracketedPasteSupported) { - this.enableBracketedPaste(); + try { + if (this.kittySupported) { + enableKittyKeyboardProtocol(); + this.kittyEnabled = true; + } else if (this.modifyOtherKeysSupported) { + enableModifyOtherKeys(); + this.modifyOtherKeysEnabled = true; + } + if (this.bracketedPasteSupported) { + enableBracketedPasteMode(); + this.bracketedPasteEnabled = true; + } + } catch (e) { + debugLogger.warn('Failed to enable keyboard protocols:', e); } } @@ -264,72 +267,6 @@ export class TerminalCapabilityManager { return this.bracketedPasteEnabled; } - enableBracketedPaste(): void { - try { - if (this.bracketedPasteSupported) { - enableBracketedPasteMode(); - this.bracketedPasteEnabled = true; - } - } catch (e) { - debugLogger.warn('Failed to enable bracketed paste mode:', e); - } - } - - disableBracketedPaste(): void { - try { - if (this.bracketedPasteEnabled) { - disableBracketedPasteMode(); - this.bracketedPasteEnabled = false; - } - } catch (e) { - debugLogger.warn('Failed to disable bracketed paste mode:', e); - } - } - - enableKittyProtocol(): void { - try { - if (this.kittySupported) { - enableKittyKeyboardProtocol(); - this.kittyEnabled = true; - } - } catch (e) { - debugLogger.warn('Failed to enable Kitty protocol:', e); - } - } - - disableKittyProtocol(): void { - try { - if (this.kittyEnabled) { - disableKittyKeyboardProtocol(); - this.kittyEnabled = false; - } - } catch (e) { - debugLogger.warn('Failed to disable Kitty protocol:', e); - } - } - - enableModifyOtherKeys(): void { - try { - if (this.modifyOtherKeysSupported) { - enableModifyOtherKeys(); - this.modifyOtherKeysEnabled = true; - } - } catch (e) { - debugLogger.warn('Failed to enable modifyOtherKeys protocol:', e); - } - } - - disableModifyOtherKeys(): void { - try { - if (this.modifyOtherKeysEnabled) { - disableModifyOtherKeys(); - this.modifyOtherKeysEnabled = false; - } - } catch (e) { - debugLogger.warn('Failed to disable modifyOtherKeys protocol:', e); - } - } - isModifyOtherKeysEnabled(): boolean { return this.modifyOtherKeysEnabled; } From 86b5995f126664ab30a42b2faf7a6ee4afb7426d Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Tue, 6 Jan 2026 16:00:47 -0500 Subject: [PATCH 007/713] Add workflow to label child issues for rollup (#16002) --- .../workflows/label-backlog-child-issues.yml | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/label-backlog-child-issues.yml diff --git a/.github/workflows/label-backlog-child-issues.yml b/.github/workflows/label-backlog-child-issues.yml new file mode 100644 index 0000000000..d1c085218d --- /dev/null +++ b/.github/workflows/label-backlog-child-issues.yml @@ -0,0 +1,34 @@ +name: 'Label Child Issues for Project Rollup' + +on: + issues: + types: ['opened', 'edited'] + +jobs: + labeler: + runs-on: 'ubuntu-latest' + permissions: + issues: 'write' + steps: + - name: 'Check for Parent Workstream and Apply Label' + uses: 'actions/github-script@v7' + with: + script: | + const issue = context.payload.issue; + // Define the parent workstream issue numbers + const parentWorkstreamNumbers = [15374, 15456, 15324]; + // Define the label to add + const labelToAdd = "workstream-rollup"; + + // Check if the issue has a body and a parent, and if that parent is in our list + if (issue && issue.body && issue.parent && parentWorkstreamNumbers.includes(issue.parent.number)) { + console.log(`Issue #${issue.number} is a child of a target workstream. Adding label.`); + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + labels: [labelToAdd] + }); + } else { + console.log(`Issue #${issue.number} is not a valid child of a target workstream or has no body. No action taken.`); + } From 61dbab03e0d512a681d32b0db432c585b9530fef Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Tue, 6 Jan 2026 15:52:12 -0500 Subject: [PATCH 008/713] feat(ui): add visual indicators for hook execution (#15408) --- docs/get-started/configuration.md | 4 + .../cli/src/config/settingsSchema.test.ts | 9 + packages/cli/src/config/settingsSchema.ts | 9 + packages/cli/src/ui/AppContainer.test.tsx | 19 ++ packages/cli/src/ui/AppContainer.tsx | 11 +- .../cli/src/ui/components/Composer.test.tsx | 16 ++ packages/cli/src/ui/components/Composer.tsx | 40 +-- .../components/ContextSummaryDisplay.test.tsx | 85 ++++--- .../ui/components/HookStatusDisplay.test.tsx | 55 ++++ .../src/ui/components/HookStatusDisplay.tsx | 39 +++ .../src/ui/components/StatusDisplay.test.tsx | 208 ++++++++++++++++ .../cli/src/ui/components/StatusDisplay.tsx | 78 ++++++ .../ContextSummaryDisplay.test.tsx.snap | 12 + .../HookStatusDisplay.test.tsx.snap | 7 + .../__snapshots__/StatusDisplay.test.tsx.snap | 21 ++ packages/cli/src/ui/constants.ts | 3 + .../cli/src/ui/contexts/UIStateContext.tsx | 2 + .../src/ui/hooks/useHookDisplayState.test.ts | 234 ++++++++++++++++++ .../cli/src/ui/hooks/useHookDisplayState.ts | 104 ++++++++ packages/cli/src/ui/types.ts | 7 + .../core/src/hooks/hookEventHandler.test.ts | 37 +++ packages/core/src/hooks/hookEventHandler.ts | 31 ++- packages/core/src/hooks/hookRunner.test.ts | 62 +++++ packages/core/src/hooks/hookRunner.ts | 18 +- packages/core/src/utils/events.test.ts | 31 +++ packages/core/src/utils/events.ts | 48 ++++ schemas/settings.schema.json | 7 + 27 files changed, 1124 insertions(+), 73 deletions(-) create mode 100644 packages/cli/src/ui/components/HookStatusDisplay.test.tsx create mode 100644 packages/cli/src/ui/components/HookStatusDisplay.tsx create mode 100644 packages/cli/src/ui/components/StatusDisplay.test.tsx create mode 100644 packages/cli/src/ui/components/StatusDisplay.tsx create mode 100644 packages/cli/src/ui/components/__snapshots__/ContextSummaryDisplay.test.tsx.snap create mode 100644 packages/cli/src/ui/components/__snapshots__/HookStatusDisplay.test.tsx.snap create mode 100644 packages/cli/src/ui/components/__snapshots__/StatusDisplay.test.tsx.snap create mode 100644 packages/cli/src/ui/hooks/useHookDisplayState.test.ts create mode 100644 packages/cli/src/ui/hooks/useHookDisplayState.ts diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 4ac0ac0764..58483baed1 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -872,6 +872,10 @@ their corresponding top-level category object in your `settings.json` file. Hooks in this list will not execute even if configured. - **Default:** `[]` +- **`hooks.notifications`** (boolean): + - **Description:** Show visual indicators when hooks are executing. + - **Default:** `true` + - **`hooks.BeforeTool`** (array): - **Description:** Hooks that execute before tool execution. Can intercept, validate, or modify tool calls. diff --git a/packages/cli/src/config/settingsSchema.test.ts b/packages/cli/src/config/settingsSchema.test.ts index 81f57feefe..e5706e0d6f 100644 --- a/packages/cli/src/config/settingsSchema.test.ts +++ b/packages/cli/src/config/settingsSchema.test.ts @@ -357,6 +357,15 @@ describe('SettingsSchema', () => { ); }); + it('should have hooks.notifications setting in schema', () => { + const setting = getSettingsSchema().hooks.properties.notifications; + expect(setting).toBeDefined(); + expect(setting.type).toBe('boolean'); + expect(setting.category).toBe('Advanced'); + expect(setting.default).toBe(true); + expect(setting.showInDialog).toBe(true); + }); + it('should have name and description in hook definitions', () => { const hookDef = SETTINGS_SCHEMA_DEFINITIONS['HookDefinitionArray']; expect(hookDef).toBeDefined(); diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index a2d7b2a008..08fb30a3cf 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -1559,6 +1559,15 @@ const SETTINGS_SCHEMA = { }, mergeStrategy: MergeStrategy.UNION, }, + notifications: { + type: 'boolean', + label: 'Hook Notifications', + category: 'Advanced', + requiresRestart: false, + default: true, + description: 'Show visual indicators when hooks are executing.', + showInDialog: true, + }, BeforeTool: { type: 'array', label: 'Before Tool Hooks', diff --git a/packages/cli/src/ui/AppContainer.test.tsx b/packages/cli/src/ui/AppContainer.test.tsx index 1d7fce5aa9..939045d44a 100644 --- a/packages/cli/src/ui/AppContainer.test.tsx +++ b/packages/cli/src/ui/AppContainer.test.tsx @@ -143,6 +143,7 @@ vi.mock('./contexts/SessionContext.js'); vi.mock('./components/shared/text-buffer.js'); vi.mock('./hooks/useLogger.js'); vi.mock('./hooks/useInputHistoryStore.js'); +vi.mock('./hooks/useHookDisplayState.js'); // Mock external utilities vi.mock('../utils/events.js'); @@ -171,6 +172,7 @@ import { useTextBuffer } from './components/shared/text-buffer.js'; import { useLogger } from './hooks/useLogger.js'; import { useLoadingIndicator } from './hooks/useLoadingIndicator.js'; import { useInputHistoryStore } from './hooks/useInputHistoryStore.js'; +import { useHookDisplayState } from './hooks/useHookDisplayState.js'; import { useKeypress, type Key } from './hooks/useKeypress.js'; import { measureElement } from 'ink'; import { useTerminalSize } from './hooks/useTerminalSize.js'; @@ -243,6 +245,7 @@ describe('AppContainer State Management', () => { const mockedUseLoadingIndicator = useLoadingIndicator as Mock; const mockedUseKeypress = useKeypress as Mock; const mockedUseInputHistoryStore = useInputHistoryStore as Mock; + const mockedUseHookDisplayState = useHookDisplayState as Mock; beforeEach(() => { vi.clearAllMocks(); @@ -363,6 +366,7 @@ describe('AppContainer State Management', () => { elapsedTime: '0.0s', currentLoadingPhrase: '', }); + mockedUseHookDisplayState.mockReturnValue([]); // Mock Config mockConfig = makeFakeConfig(); @@ -1874,6 +1878,21 @@ describe('AppContainer State Management', () => { expect(capturedUIState.currentModel).toBe('new-model'); unmount!(); }); + + it('provides activeHooks from useHookDisplayState', async () => { + const mockHooks = [{ name: 'hook1', eventName: 'event1' }]; + mockedUseHookDisplayState.mockReturnValue(mockHooks); + + let unmount: () => void; + await act(async () => { + const result = renderAppContainer(); + unmount = result.unmount; + }); + await waitFor(() => expect(capturedUIState).toBeTruthy()); + + expect(capturedUIState.activeHooks).toEqual(mockHooks); + unmount!(); + }); }); describe('Shell Interaction', () => { diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index f352556b06..7687a096c1 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -123,9 +123,11 @@ import { useSettings } from './contexts/SettingsContext.js'; import { terminalCapabilityManager } from './utils/terminalCapabilityManager.js'; import { useInputHistoryStore } from './hooks/useInputHistoryStore.js'; import { useBanner } from './hooks/useBanner.js'; - -const WARNING_PROMPT_DURATION_MS = 1000; -const QUEUE_ERROR_DISPLAY_DURATION_MS = 3000; +import { useHookDisplayState } from './hooks/useHookDisplayState.js'; +import { + WARNING_PROMPT_DURATION_MS, + QUEUE_ERROR_DISPLAY_DURATION_MS, +} from './constants.js'; function isToolExecuting(pendingHistoryItems: HistoryItemWithoutId[]) { return pendingHistoryItems.some((item) => { @@ -189,6 +191,7 @@ export const AppContainer = (props: AppContainerProps) => { useState(false); const [historyRemountKey, setHistoryRemountKey] = useState(0); const [settingsNonce, setSettingsNonce] = useState(0); + const activeHooks = useHookDisplayState(); const [updateInfo, setUpdateInfo] = useState(null); const [isTrustedFolder, setIsTrustedFolder] = useState( isWorkspaceTrusted(settings.merged).isTrusted, @@ -1522,6 +1525,7 @@ Logging in with Google... Restarting Gemini CLI to continue. elapsedTime, currentLoadingPhrase, historyRemountKey, + activeHooks, messageQueue, queueErrorMessage, showAutoAcceptIndicator, @@ -1612,6 +1616,7 @@ Logging in with Google... Restarting Gemini CLI to continue. elapsedTime, currentLoadingPhrase, historyRemountKey, + activeHooks, messageQueue, queueErrorMessage, showAutoAcceptIndicator, diff --git a/packages/cli/src/ui/components/Composer.test.tsx b/packages/cli/src/ui/components/Composer.test.tsx index ef97c56201..b48e18cc00 100644 --- a/packages/cli/src/ui/components/Composer.test.tsx +++ b/packages/cli/src/ui/components/Composer.test.tsx @@ -36,6 +36,10 @@ vi.mock('./ContextSummaryDisplay.js', () => ({ ContextSummaryDisplay: () => ContextSummaryDisplay, })); +vi.mock('./HookStatusDisplay.js', () => ({ + HookStatusDisplay: () => HookStatusDisplay, +})); + vi.mock('./AutoAcceptIndicator.js', () => ({ AutoAcceptIndicator: () => AutoAcceptIndicator, })); @@ -125,6 +129,7 @@ const createMockUIState = (overrides: Partial = {}): UIState => errorCount: 0, nightly: false, isTrustedFolder: true, + activeHooks: [], ...overrides, }) as UIState; @@ -341,6 +346,17 @@ describe('Composer', () => { expect(lastFrame()).toContain('ContextSummaryDisplay'); }); + it('renders HookStatusDisplay instead of ContextSummaryDisplay with active hooks', () => { + const uiState = createMockUIState({ + activeHooks: [{ name: 'test-hook', eventName: 'before-agent' }], + }); + + const { lastFrame } = renderComposer(uiState); + + expect(lastFrame()).toContain('HookStatusDisplay'); + expect(lastFrame()).not.toContain('ContextSummaryDisplay'); + }); + it('shows Ctrl+C exit prompt when ctrlCPressedOnce is true', () => { const uiState = createMockUIState({ ctrlCPressedOnce: true, diff --git a/packages/cli/src/ui/components/Composer.tsx b/packages/cli/src/ui/components/Composer.tsx index 11685a4435..d48cced332 100644 --- a/packages/cli/src/ui/components/Composer.tsx +++ b/packages/cli/src/ui/components/Composer.tsx @@ -5,9 +5,9 @@ */ import { useState } from 'react'; -import { Box, Text, useIsScreenReaderEnabled } from 'ink'; +import { Box, useIsScreenReaderEnabled } from 'ink'; import { LoadingIndicator } from './LoadingIndicator.js'; -import { ContextSummaryDisplay } from './ContextSummaryDisplay.js'; +import { StatusDisplay } from './StatusDisplay.js'; import { AutoAcceptIndicator } from './AutoAcceptIndicator.js'; import { ShellModeIndicator } from './ShellModeIndicator.js'; import { DetailedMessagesDisplay } from './DetailedMessagesDisplay.js'; @@ -17,7 +17,6 @@ import { Footer } from './Footer.js'; import { ShowMoreLines } from './ShowMoreLines.js'; import { QueuedMessageDisplay } from './QueuedMessageDisplay.js'; import { OverflowProvider } from '../contexts/OverflowContext.js'; -import { theme } from '../semantic-colors.js'; import { isNarrowWidth } from '../utils/isNarrowWidth.js'; import { useUIState } from '../contexts/UIStateContext.js'; import { useUIActions } from '../contexts/UIActionsContext.js'; @@ -43,7 +42,7 @@ export const Composer = () => { const [suggestionsVisible, setSuggestionsVisible] = useState(false); const isAlternateBuffer = useAlternateBuffer(); - const { contextFileNames, showAutoAcceptIndicator } = uiState; + const { showAutoAcceptIndicator } = uiState; const suggestionsPosition = isAlternateBuffer ? 'above' : 'below'; const hideContextSummary = suggestionsVisible && suggestionsPosition === 'above'; @@ -92,38 +91,7 @@ export const Composer = () => { alignItems={isNarrow ? 'flex-start' : 'center'} > - {process.env['GEMINI_SYSTEM_MD'] && ( - |⌐■_■| - )} - {uiState.ctrlCPressedOnce ? ( - - Press Ctrl+C again to exit. - - ) : uiState.warningMessage ? ( - {uiState.warningMessage} - ) : uiState.ctrlDPressedOnce ? ( - - Press Ctrl+D again to exit. - - ) : uiState.showEscapePrompt ? ( - Press Esc again to clear. - ) : uiState.queueErrorMessage ? ( - {uiState.queueErrorMessage} - ) : ( - !settings.merged.ui?.hideContextSummary && - !hideContextSummary && ( - - ) - )} + {showAutoAcceptIndicator !== ApprovalMode.DEFAULT && diff --git a/packages/cli/src/ui/components/ContextSummaryDisplay.test.tsx b/packages/cli/src/ui/components/ContextSummaryDisplay.test.tsx index 50a610f345..415e867a87 100644 --- a/packages/cli/src/ui/components/ContextSummaryDisplay.test.tsx +++ b/packages/cli/src/ui/components/ContextSummaryDisplay.test.tsx @@ -6,7 +6,7 @@ import type React from 'react'; import { render } from '../../test-utils/render.js'; -import { describe, it, expect, vi } from 'vitest'; +import { describe, it, expect, vi, afterEach } from 'vitest'; import { ContextSummaryDisplay } from './ContextSummaryDisplay.js'; import * as useTerminalSize from '../hooks/useTerminalSize.js'; @@ -16,6 +16,11 @@ vi.mock('../hooks/useTerminalSize.js', () => ({ const useTerminalSizeMock = vi.mocked(useTerminalSize.useTerminalSize); +afterEach(() => { + vi.restoreAllMocks(); + vi.useRealTimers(); +}); + const renderWithWidth = ( width: number, props: React.ComponentProps, @@ -26,48 +31,68 @@ const renderWithWidth = ( describe('', () => { const baseProps = { - geminiMdFileCount: 1, - contextFileNames: ['GEMINI.md'], - mcpServers: { 'test-server': { command: 'test' } }, + geminiMdFileCount: 0, + contextFileNames: [], + mcpServers: {}, ideContext: { workspaceState: { - openFiles: [{ path: '/a/b/c', timestamp: Date.now() }], + openFiles: [], }, }, skillCount: 1, }; it('should render on a single line on a wide screen', () => { - const { lastFrame, unmount } = renderWithWidth(120, baseProps); - const output = lastFrame()!; - expect(output).toContain( - '1 open file (ctrl+g to view) | 1 GEMINI.md file | 1 MCP server | 1 skill', - ); - expect(output).not.toContain('Using:'); - // Check for absence of newlines - expect(output.includes('\n')).toBe(false); + const props = { + ...baseProps, + geminiMdFileCount: 1, + contextFileNames: ['GEMINI.md'], + mcpServers: { 'test-server': { command: 'test' } }, + ideContext: { + workspaceState: { + openFiles: [{ path: '/a/b/c', timestamp: Date.now() }], + }, + }, + }; + const { lastFrame, unmount } = renderWithWidth(120, props); + expect(lastFrame()).toMatchSnapshot(); unmount(); }); it('should render on multiple lines on a narrow screen', () => { - const { lastFrame, unmount } = renderWithWidth(60, baseProps); - const output = lastFrame()!; - const expectedLines = [ - ' - 1 open file (ctrl+g to view)', - ' - 1 GEMINI.md file', - ' - 1 MCP server', - ' - 1 skill', - ]; - const actualLines = output.split('\n'); - expect(actualLines).toEqual(expectedLines); + const props = { + ...baseProps, + geminiMdFileCount: 1, + contextFileNames: ['GEMINI.md'], + mcpServers: { 'test-server': { command: 'test' } }, + ideContext: { + workspaceState: { + openFiles: [{ path: '/a/b/c', timestamp: Date.now() }], + }, + }, + }; + const { lastFrame, unmount } = renderWithWidth(60, props); + expect(lastFrame()).toMatchSnapshot(); unmount(); }); it('should switch layout at the 80-column breakpoint', () => { + const props = { + ...baseProps, + geminiMdFileCount: 1, + contextFileNames: ['GEMINI.md'], + mcpServers: { 'test-server': { command: 'test' } }, + ideContext: { + workspaceState: { + openFiles: [{ path: '/a/b/c', timestamp: Date.now() }], + }, + }, + }; + // At 80 columns, should be on one line const { lastFrame: wideFrame, unmount: unmountWide } = renderWithWidth( 80, - baseProps, + props, ); expect(wideFrame()!.includes('\n')).toBe(false); unmountWide(); @@ -75,13 +100,12 @@ describe('', () => { // At 79 columns, should be on multiple lines const { lastFrame: narrowFrame, unmount: unmountNarrow } = renderWithWidth( 79, - baseProps, + props, ); expect(narrowFrame()!.includes('\n')).toBe(true); expect(narrowFrame()!.split('\n').length).toBe(4); unmountNarrow(); }); - it('should not render empty parts', () => { const props = { ...baseProps, @@ -89,11 +113,14 @@ describe('', () => { contextFileNames: [], mcpServers: {}, skillCount: 0, + ideContext: { + workspaceState: { + openFiles: [{ path: '/a/b/c', timestamp: Date.now() }], + }, + }, }; const { lastFrame, unmount } = renderWithWidth(60, props); - const expectedLines = [' - 1 open file (ctrl+g to view)']; - const actualLines = lastFrame()!.split('\n'); - expect(actualLines).toEqual(expectedLines); + expect(lastFrame()).toMatchSnapshot(); unmount(); }); }); diff --git a/packages/cli/src/ui/components/HookStatusDisplay.test.tsx b/packages/cli/src/ui/components/HookStatusDisplay.test.tsx new file mode 100644 index 0000000000..69aa2cdb25 --- /dev/null +++ b/packages/cli/src/ui/components/HookStatusDisplay.test.tsx @@ -0,0 +1,55 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { render } from '../../test-utils/render.js'; +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { HookStatusDisplay } from './HookStatusDisplay.js'; + +afterEach(() => { + vi.restoreAllMocks(); + vi.useRealTimers(); +}); + +describe('', () => { + it('should render a single executing hook', () => { + const props = { + activeHooks: [{ name: 'test-hook', eventName: 'BeforeAgent' }], + }; + const { lastFrame, unmount } = render(); + expect(lastFrame()).toMatchSnapshot(); + unmount(); + }); + + it('should render multiple executing hooks', () => { + const props = { + activeHooks: [ + { name: 'h1', eventName: 'BeforeAgent' }, + { name: 'h2', eventName: 'BeforeAgent' }, + ], + }; + const { lastFrame, unmount } = render(); + expect(lastFrame()).toMatchSnapshot(); + unmount(); + }); + + it('should render sequential hook progress', () => { + const props = { + activeHooks: [ + { name: 'step', eventName: 'BeforeAgent', index: 1, total: 3 }, + ], + }; + const { lastFrame, unmount } = render(); + expect(lastFrame()).toMatchSnapshot(); + unmount(); + }); + + it('should return empty string if no active hooks', () => { + const props = { activeHooks: [] }; + const { lastFrame, unmount } = render(); + expect(lastFrame()).toBe(''); + unmount(); + }); +}); diff --git a/packages/cli/src/ui/components/HookStatusDisplay.tsx b/packages/cli/src/ui/components/HookStatusDisplay.tsx new file mode 100644 index 0000000000..07b2ee3d4a --- /dev/null +++ b/packages/cli/src/ui/components/HookStatusDisplay.tsx @@ -0,0 +1,39 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type React from 'react'; +import { Text } from 'ink'; +import { theme } from '../semantic-colors.js'; +import { type ActiveHook } from '../types.js'; + +interface HookStatusDisplayProps { + activeHooks: ActiveHook[]; +} + +export const HookStatusDisplay: React.FC = ({ + activeHooks, +}) => { + if (activeHooks.length === 0) { + return null; + } + + const label = activeHooks.length > 1 ? 'Executing Hooks' : 'Executing Hook'; + const displayNames = activeHooks.map((hook) => { + let name = hook.name; + if (hook.index && hook.total && hook.total > 1) { + name += ` (${hook.index}/${hook.total})`; + } + return name; + }); + + const text = `${label}: ${displayNames.join(', ')}`; + + return ( + + {text} + + ); +}; diff --git a/packages/cli/src/ui/components/StatusDisplay.test.tsx b/packages/cli/src/ui/components/StatusDisplay.test.tsx new file mode 100644 index 0000000000..e5a64bd3f3 --- /dev/null +++ b/packages/cli/src/ui/components/StatusDisplay.test.tsx @@ -0,0 +1,208 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render } from '../../test-utils/render.js'; +import { Text } from 'ink'; +import { StatusDisplay } from './StatusDisplay.js'; +import { UIStateContext, type UIState } from '../contexts/UIStateContext.js'; +import { ConfigContext } from '../contexts/ConfigContext.js'; +import { SettingsContext } from '../contexts/SettingsContext.js'; + +// Mock child components to simplify testing +vi.mock('./ContextSummaryDisplay.js', () => ({ + ContextSummaryDisplay: (props: { skillCount: number }) => ( + Mock Context Summary Display (Skills: {props.skillCount}) + ), +})); + +vi.mock('./HookStatusDisplay.js', () => ({ + HookStatusDisplay: () => Mock Hook Status Display, +})); + +// Create mock context providers +const createMockUIState = (overrides: Partial = {}): UIState => + ({ + ctrlCPressedOnce: false, + warningMessage: null, + ctrlDPressedOnce: false, + showEscapePrompt: false, + queueErrorMessage: null, + activeHooks: [], + ideContextState: null, + geminiMdFileCount: 0, + contextFileNames: [], + ...overrides, + }) as UIState; + +const createMockConfig = (overrides = {}) => ({ + getMcpClientManager: vi.fn().mockImplementation(() => ({ + getBlockedMcpServers: vi.fn(() => []), + getMcpServers: vi.fn(() => ({})), + })), + getSkillManager: vi.fn().mockImplementation(() => ({ + getSkills: vi.fn(() => ['skill1', 'skill2']), + })), + ...overrides, +}); + +const createMockSettings = (merged = {}) => ({ + merged: { + hooks: { notifications: true }, + ui: { hideContextSummary: false }, + ...merged, + }, +}); + +/* eslint-disable @typescript-eslint/no-explicit-any */ +const renderStatusDisplay = ( + props: { hideContextSummary: boolean } = { hideContextSummary: false }, + uiState: UIState = createMockUIState(), + settings = createMockSettings(), + config = createMockConfig(), +) => + render( + + + + + + + , + ); +/* eslint-enable @typescript-eslint/no-explicit-any */ + +describe('StatusDisplay', () => { + const originalEnv = process.env; + + afterEach(() => { + process.env = { ...originalEnv }; + delete process.env['GEMINI_SYSTEM_MD']; + }); + + it('renders nothing by default if context summary is hidden via props', () => { + const { lastFrame } = renderStatusDisplay({ hideContextSummary: true }); + expect(lastFrame()).toBe(''); + }); + + it('renders ContextSummaryDisplay by default', () => { + const { lastFrame } = renderStatusDisplay(); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('renders system md indicator if env var is set', () => { + process.env['GEMINI_SYSTEM_MD'] = 'true'; + const { lastFrame } = renderStatusDisplay(); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('prioritizes Ctrl+C prompt over everything else (except system md)', () => { + const uiState = createMockUIState({ + ctrlCPressedOnce: true, + warningMessage: 'Warning', + activeHooks: [{ name: 'hook', eventName: 'event' }], + }); + const { lastFrame } = renderStatusDisplay( + { hideContextSummary: false }, + uiState, + ); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('renders warning message', () => { + const uiState = createMockUIState({ + warningMessage: 'This is a warning', + }); + const { lastFrame } = renderStatusDisplay( + { hideContextSummary: false }, + uiState, + ); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('prioritizes warning over Ctrl+D', () => { + const uiState = createMockUIState({ + warningMessage: 'Warning', + ctrlDPressedOnce: true, + }); + const { lastFrame } = renderStatusDisplay( + { hideContextSummary: false }, + uiState, + ); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('renders Ctrl+D prompt', () => { + const uiState = createMockUIState({ + ctrlDPressedOnce: true, + }); + const { lastFrame } = renderStatusDisplay( + { hideContextSummary: false }, + uiState, + ); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('renders Escape prompt', () => { + const uiState = createMockUIState({ + showEscapePrompt: true, + }); + const { lastFrame } = renderStatusDisplay( + { hideContextSummary: false }, + uiState, + ); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('renders Queue Error Message', () => { + const uiState = createMockUIState({ + queueErrorMessage: 'Queue Error', + }); + const { lastFrame } = renderStatusDisplay( + { hideContextSummary: false }, + uiState, + ); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('renders HookStatusDisplay when hooks are active', () => { + const uiState = createMockUIState({ + activeHooks: [{ name: 'hook', eventName: 'event' }], + }); + const { lastFrame } = renderStatusDisplay( + { hideContextSummary: false }, + uiState, + ); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('does NOT render HookStatusDisplay if notifications are disabled in settings', () => { + const uiState = createMockUIState({ + activeHooks: [{ name: 'hook', eventName: 'event' }], + }); + const settings = createMockSettings({ + hooks: { notifications: false }, + }); + const { lastFrame } = renderStatusDisplay( + { hideContextSummary: false }, + uiState, + settings, + ); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('hides ContextSummaryDisplay if configured in settings', () => { + const settings = createMockSettings({ + ui: { hideContextSummary: true }, + }); + const { lastFrame } = renderStatusDisplay( + { hideContextSummary: false }, + undefined, + settings, + ); + expect(lastFrame()).toBe(''); + }); +}); diff --git a/packages/cli/src/ui/components/StatusDisplay.tsx b/packages/cli/src/ui/components/StatusDisplay.tsx new file mode 100644 index 0000000000..367be17593 --- /dev/null +++ b/packages/cli/src/ui/components/StatusDisplay.tsx @@ -0,0 +1,78 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type React from 'react'; +import { Text } from 'ink'; +import { theme } from '../semantic-colors.js'; +import { useUIState } from '../contexts/UIStateContext.js'; +import { useSettings } from '../contexts/SettingsContext.js'; +import { useConfig } from '../contexts/ConfigContext.js'; +import { ContextSummaryDisplay } from './ContextSummaryDisplay.js'; +import { HookStatusDisplay } from './HookStatusDisplay.js'; + +interface StatusDisplayProps { + hideContextSummary: boolean; +} + +export const StatusDisplay: React.FC = ({ + hideContextSummary, +}) => { + const uiState = useUIState(); + const settings = useSettings(); + const config = useConfig(); + + if (process.env['GEMINI_SYSTEM_MD']) { + return |⌐■_■| ; + } + + if (uiState.ctrlCPressedOnce) { + return ( + Press Ctrl+C again to exit. + ); + } + + if (uiState.warningMessage) { + return {uiState.warningMessage}; + } + + if (uiState.ctrlDPressedOnce) { + return ( + Press Ctrl+D again to exit. + ); + } + + if (uiState.showEscapePrompt) { + return Press Esc again to clear.; + } + + if (uiState.queueErrorMessage) { + return {uiState.queueErrorMessage}; + } + + if ( + uiState.activeHooks.length > 0 && + (settings.merged.hooks?.notifications ?? true) + ) { + return ; + } + + if (!settings.merged.ui?.hideContextSummary && !hideContextSummary) { + return ( + + ); + } + + return null; +}; diff --git a/packages/cli/src/ui/components/__snapshots__/ContextSummaryDisplay.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/ContextSummaryDisplay.test.tsx.snap new file mode 100644 index 0000000000..5146c01e39 --- /dev/null +++ b/packages/cli/src/ui/components/__snapshots__/ContextSummaryDisplay.test.tsx.snap @@ -0,0 +1,12 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > should not render empty parts 1`] = `" - 1 open file (ctrl+g to view)"`; + +exports[` > should render on a single line on a wide screen 1`] = `" 1 open file (ctrl+g to view) | 1 GEMINI.md file | 1 MCP server | 1 skill"`; + +exports[` > should render on multiple lines on a narrow screen 1`] = ` +" - 1 open file (ctrl+g to view) + - 1 GEMINI.md file + - 1 MCP server + - 1 skill" +`; diff --git a/packages/cli/src/ui/components/__snapshots__/HookStatusDisplay.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/HookStatusDisplay.test.tsx.snap new file mode 100644 index 0000000000..8d07035c07 --- /dev/null +++ b/packages/cli/src/ui/components/__snapshots__/HookStatusDisplay.test.tsx.snap @@ -0,0 +1,7 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > should render a single executing hook 1`] = `"Executing Hook: test-hook"`; + +exports[` > should render multiple executing hooks 1`] = `"Executing Hooks: h1, h2"`; + +exports[` > should render sequential hook progress 1`] = `"Executing Hook: step (1/3)"`; diff --git a/packages/cli/src/ui/components/__snapshots__/StatusDisplay.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/StatusDisplay.test.tsx.snap new file mode 100644 index 0000000000..ee2c68fbd5 --- /dev/null +++ b/packages/cli/src/ui/components/__snapshots__/StatusDisplay.test.tsx.snap @@ -0,0 +1,21 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`StatusDisplay > does NOT render HookStatusDisplay if notifications are disabled in settings 1`] = `"Mock Context Summary Display (Skills: 2)"`; + +exports[`StatusDisplay > prioritizes Ctrl+C prompt over everything else (except system md) 1`] = `"Press Ctrl+C again to exit."`; + +exports[`StatusDisplay > prioritizes warning over Ctrl+D 1`] = `"Warning"`; + +exports[`StatusDisplay > renders ContextSummaryDisplay by default 1`] = `"Mock Context Summary Display (Skills: 2)"`; + +exports[`StatusDisplay > renders Ctrl+D prompt 1`] = `"Press Ctrl+D again to exit."`; + +exports[`StatusDisplay > renders Escape prompt 1`] = `"Press Esc again to clear."`; + +exports[`StatusDisplay > renders HookStatusDisplay when hooks are active 1`] = `"Mock Hook Status Display"`; + +exports[`StatusDisplay > renders Queue Error Message 1`] = `"Queue Error"`; + +exports[`StatusDisplay > renders system md indicator if env var is set 1`] = `"|⌐■_■|"`; + +exports[`StatusDisplay > renders warning message 1`] = `"This is a warning"`; diff --git a/packages/cli/src/ui/constants.ts b/packages/cli/src/ui/constants.ts index 9bd4cf1b34..e27f3c3bbe 100644 --- a/packages/cli/src/ui/constants.ts +++ b/packages/cli/src/ui/constants.ts @@ -28,3 +28,6 @@ export const TOOL_STATUS = { // Maximum number of MCP resources to display per server before truncating export const MAX_MCP_RESOURCES_TO_SHOW = 10; + +export const WARNING_PROMPT_DURATION_MS = 1000; +export const QUEUE_ERROR_DISPLAY_DURATION_MS = 3000; diff --git a/packages/cli/src/ui/contexts/UIStateContext.tsx b/packages/cli/src/ui/contexts/UIStateContext.tsx index d9f74e59e0..1175b0743a 100644 --- a/packages/cli/src/ui/contexts/UIStateContext.tsx +++ b/packages/cli/src/ui/contexts/UIStateContext.tsx @@ -14,6 +14,7 @@ import type { LoopDetectionConfirmationRequest, HistoryItemWithoutId, StreamingState, + ActiveHook, } from '../types.js'; import type { CommandContext, SlashCommand } from '../commands/types.js'; import type { TextBuffer } from '../components/shared/text-buffer.js'; @@ -96,6 +97,7 @@ export interface UIState { elapsedTime: number; currentLoadingPhrase: string; historyRemountKey: number; + activeHooks: ActiveHook[]; messageQueue: string[]; queueErrorMessage: string | null; showAutoAcceptIndicator: ApprovalMode; diff --git a/packages/cli/src/ui/hooks/useHookDisplayState.test.ts b/packages/cli/src/ui/hooks/useHookDisplayState.test.ts new file mode 100644 index 0000000000..a6c86401bd --- /dev/null +++ b/packages/cli/src/ui/hooks/useHookDisplayState.test.ts @@ -0,0 +1,234 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { renderHook } from '../../test-utils/render.js'; +import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'; +import { useHookDisplayState } from './useHookDisplayState.js'; +import { + coreEvents, + CoreEvent, + type HookStartPayload, + type HookEndPayload, +} from '@google/gemini-cli-core'; +import { act } from 'react'; + +describe('useHookDisplayState', () => { + beforeEach(() => { + vi.useFakeTimers(); + }); + + afterEach(() => { + vi.restoreAllMocks(); + vi.useRealTimers(); + coreEvents.removeAllListeners(CoreEvent.HookStart); + coreEvents.removeAllListeners(CoreEvent.HookEnd); + }); + + it('should initialize with empty hooks', () => { + const { result } = renderHook(() => useHookDisplayState()); + expect(result.current).toEqual([]); + }); + + it('should add a hook when HookStart event is emitted', () => { + const { result } = renderHook(() => useHookDisplayState()); + + const payload: HookStartPayload = { + hookName: 'test-hook', + eventName: 'before-agent', + hookIndex: 1, + totalHooks: 1, + }; + + act(() => { + coreEvents.emitHookStart(payload); + }); + + expect(result.current).toHaveLength(1); + expect(result.current[0]).toMatchObject({ + name: 'test-hook', + eventName: 'before-agent', + }); + }); + + it('should remove a hook immediately if duration > 1s', () => { + const { result } = renderHook(() => useHookDisplayState()); + + const startPayload: HookStartPayload = { + hookName: 'test-hook', + eventName: 'before-agent', + }; + + act(() => { + coreEvents.emitHookStart(startPayload); + }); + + // Advance time by 1.1 seconds + act(() => { + vi.advanceTimersByTime(1100); + }); + + const endPayload: HookEndPayload = { + hookName: 'test-hook', + eventName: 'before-agent', + success: true, + }; + + act(() => { + coreEvents.emitHookEnd(endPayload); + }); + + expect(result.current).toHaveLength(0); + }); + + it('should delay removal if duration < 1s', () => { + const { result } = renderHook(() => useHookDisplayState()); + + const startPayload: HookStartPayload = { + hookName: 'test-hook', + eventName: 'before-agent', + }; + + act(() => { + coreEvents.emitHookStart(startPayload); + }); + + // Advance time by only 100ms + act(() => { + vi.advanceTimersByTime(100); + }); + + const endPayload: HookEndPayload = { + hookName: 'test-hook', + eventName: 'before-agent', + success: true, + }; + + act(() => { + coreEvents.emitHookEnd(endPayload); + }); + + // Should still be present + expect(result.current).toHaveLength(1); + + // Advance remaining time (900ms needed, let's go 950ms) + act(() => { + vi.advanceTimersByTime(950); + }); + + expect(result.current).toHaveLength(0); + }); + + it('should handle multiple hooks correctly', () => { + const { result } = renderHook(() => useHookDisplayState()); + + act(() => { + coreEvents.emitHookStart({ hookName: 'h1', eventName: 'e1' }); + }); + + act(() => { + vi.advanceTimersByTime(500); + }); + + act(() => { + coreEvents.emitHookStart({ hookName: 'h2', eventName: 'e1' }); + }); + + expect(result.current).toHaveLength(2); + + // End h1 (total time 500ms -> needs 500ms delay) + act(() => { + coreEvents.emitHookEnd({ + hookName: 'h1', + eventName: 'e1', + success: true, + }); + }); + + // h1 still there + expect(result.current).toHaveLength(2); + + // Advance 600ms. h1 should disappear. h2 has been running for 600ms. + act(() => { + vi.advanceTimersByTime(600); + }); + + expect(result.current).toHaveLength(1); + expect(result.current[0].name).toBe('h2'); + + // End h2 (total time 600ms -> needs 400ms delay) + act(() => { + coreEvents.emitHookEnd({ + hookName: 'h2', + eventName: 'e1', + success: true, + }); + }); + + expect(result.current).toHaveLength(1); + + act(() => { + vi.advanceTimersByTime(500); + }); + + expect(result.current).toHaveLength(0); + }); + + it('should handle interleaved hooks with same name and event', () => { + const { result } = renderHook(() => useHookDisplayState()); + const hook = { hookName: 'same-hook', eventName: 'same-event' }; + + // Start Hook 1 at t=0 + act(() => { + coreEvents.emitHookStart(hook); + }); + + // Advance to t=500 + act(() => { + vi.advanceTimersByTime(500); + }); + + // Start Hook 2 at t=500 + act(() => { + coreEvents.emitHookStart(hook); + }); + + expect(result.current).toHaveLength(2); + expect(result.current[0].name).toBe('same-hook'); + expect(result.current[1].name).toBe('same-hook'); + + // End Hook 1 at t=600 (Duration 600ms -> delay 400ms) + act(() => { + vi.advanceTimersByTime(100); + coreEvents.emitHookEnd({ ...hook, success: true }); + }); + + // Both still visible (Hook 1 pending removal in 400ms) + expect(result.current).toHaveLength(2); + + // Advance 400ms (t=1000). Hook 1 should be removed. + act(() => { + vi.advanceTimersByTime(400); + }); + + expect(result.current).toHaveLength(1); + + // End Hook 2 at t=1100 (Duration: 1100 - 500 = 600ms -> delay 400ms) + act(() => { + vi.advanceTimersByTime(100); + coreEvents.emitHookEnd({ ...hook, success: true }); + }); + + // Hook 2 still visible (pending removal in 400ms) + expect(result.current).toHaveLength(1); + + // Advance 400ms (t=1500). Hook 2 should be removed. + act(() => { + vi.advanceTimersByTime(400); + }); + + expect(result.current).toHaveLength(0); + }); +}); diff --git a/packages/cli/src/ui/hooks/useHookDisplayState.ts b/packages/cli/src/ui/hooks/useHookDisplayState.ts new file mode 100644 index 0000000000..6c9e1811ad --- /dev/null +++ b/packages/cli/src/ui/hooks/useHookDisplayState.ts @@ -0,0 +1,104 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { useState, useEffect, useRef } from 'react'; +import { + coreEvents, + CoreEvent, + type HookStartPayload, + type HookEndPayload, +} from '@google/gemini-cli-core'; +import { type ActiveHook } from '../types.js'; +import { WARNING_PROMPT_DURATION_MS } from '../constants.js'; + +export const useHookDisplayState = () => { + const [activeHooks, setActiveHooks] = useState([]); + + // Track start times independently of render state to calculate duration in event handlers + // Key: `${hookName}:${eventName}` -> Stack of StartTimes (FIFO) + const hookStartTimes = useRef>(new Map()); + + // Track active timeouts to clear them on unmount + const timeouts = useRef>(new Set()); + + useEffect(() => { + const activeTimeouts = timeouts.current; + const startTimes = hookStartTimes.current; + + const handleHookStart = (payload: HookStartPayload) => { + const key = `${payload.hookName}:${payload.eventName}`; + const now = Date.now(); + + // Add start time to ref + if (!startTimes.has(key)) { + startTimes.set(key, []); + } + startTimes.get(key)!.push(now); + + setActiveHooks((prev) => [ + ...prev, + { + name: payload.hookName, + eventName: payload.eventName, + index: payload.hookIndex, + total: payload.totalHooks, + }, + ]); + }; + + const handleHookEnd = (payload: HookEndPayload) => { + const key = `${payload.hookName}:${payload.eventName}`; + const starts = startTimes.get(key); + const startTime = starts?.shift(); // Get the earliest start time for this hook type + + // Cleanup empty arrays in map + if (starts && starts.length === 0) { + startTimes.delete(key); + } + + const now = Date.now(); + // Default to immediate removal if start time not found (defensive) + const elapsed = startTime ? now - startTime : WARNING_PROMPT_DURATION_MS; + const remaining = WARNING_PROMPT_DURATION_MS - elapsed; + + const removeHook = () => { + setActiveHooks((prev) => { + const index = prev.findIndex( + (h) => + h.name === payload.hookName && h.eventName === payload.eventName, + ); + if (index === -1) return prev; + const newHooks = [...prev]; + newHooks.splice(index, 1); + return newHooks; + }); + }; + + if (remaining > 0) { + const timeoutId = setTimeout(() => { + removeHook(); + activeTimeouts.delete(timeoutId); + }, remaining); + activeTimeouts.add(timeoutId); + } else { + removeHook(); + } + }; + + coreEvents.on(CoreEvent.HookStart, handleHookStart); + coreEvents.on(CoreEvent.HookEnd, handleHookEnd); + + return () => { + coreEvents.off(CoreEvent.HookStart, handleHookStart); + coreEvents.off(CoreEvent.HookEnd, handleHookEnd); + // Clear all pending timeouts + activeTimeouts.forEach(clearTimeout); + activeTimeouts.clear(); + }; + }, []); + + return activeHooks; +}; diff --git a/packages/cli/src/ui/types.ts b/packages/cli/src/ui/types.ts index c5947024f1..7535119a30 100644 --- a/packages/cli/src/ui/types.ts +++ b/packages/cli/src/ui/types.ts @@ -418,3 +418,10 @@ export interface ConfirmationRequest { export interface LoopDetectionConfirmationRequest { onComplete: (result: { userSelection: 'disable' | 'keep' }) => void; } + +export interface ActiveHook { + name: string; + eventName: string; + index?: number; + total?: number; +} diff --git a/packages/core/src/hooks/hookEventHandler.test.ts b/packages/core/src/hooks/hookEventHandler.test.ts index c6032298f6..2bffc805b6 100644 --- a/packages/core/src/hooks/hookEventHandler.test.ts +++ b/packages/core/src/hooks/hookEventHandler.test.ts @@ -31,6 +31,8 @@ const mockDebugLogger = vi.hoisted(() => ({ // Mock coreEvents const mockCoreEvents = vi.hoisted(() => ({ emitFeedback: vi.fn(), + emitHookStart: vi.fn(), + emitHookEnd: vi.fn(), })); vi.mock('../utils/debugLogger.js', () => ({ @@ -158,8 +160,31 @@ describe('HookEventHandler', () => { tool_name: 'EditTool', tool_input: { file: 'test.txt' }, }), + expect.any(Function), + expect.any(Function), ); + // Verify event emission via callbacks + const onHookStart = vi.mocked(mockHookRunner.executeHooksParallel).mock + .calls[0][3]; + const onHookEnd = vi.mocked(mockHookRunner.executeHooksParallel).mock + .calls[0][4]; + + if (onHookStart) onHookStart(mockPlan[0].hookConfig, 0); + expect(mockCoreEvents.emitHookStart).toHaveBeenCalledWith({ + hookName: './test.sh', + eventName: HookEventName.BeforeTool, + hookIndex: 1, + totalHooks: 1, + }); + + if (onHookEnd) onHookEnd(mockPlan[0].hookConfig, mockResults[0]); + expect(mockCoreEvents.emitHookEnd).toHaveBeenCalledWith({ + hookName: './test.sh', + eventName: HookEventName.BeforeTool, + success: true, + }); + expect(result).toBe(mockAggregated); }); @@ -294,6 +319,8 @@ describe('HookEventHandler', () => { tool_input: toolInput, tool_response: toolResponse, }), + expect.any(Function), + expect.any(Function), ); expect(result).toBe(mockAggregated); @@ -352,6 +379,8 @@ describe('HookEventHandler', () => { expect.objectContaining({ prompt, }), + expect.any(Function), + expect.any(Function), ); expect(result).toBe(mockAggregated); @@ -415,6 +444,8 @@ describe('HookEventHandler', () => { notification_type: 'ToolPermission', details: { type: 'ToolPermission', title: 'Test Permission' }, }), + expect.any(Function), + expect.any(Function), ); expect(result).toBe(mockAggregated); @@ -478,6 +509,8 @@ describe('HookEventHandler', () => { expect.objectContaining({ source: 'startup', }), + expect.any(Function), + expect.any(Function), ); expect(result).toBe(mockAggregated); @@ -548,6 +581,8 @@ describe('HookEventHandler', () => { ]), }), }), + expect.any(Function), + expect.any(Function), ); expect(result).toBe(mockAggregated); @@ -591,6 +626,8 @@ describe('HookEventHandler', () => { hook_event_name: 'BeforeTool', timestamp: expect.any(String), }), + expect.any(Function), + expect.any(Function), ); }); }); diff --git a/packages/core/src/hooks/hookEventHandler.ts b/packages/core/src/hooks/hookEventHandler.ts index 92268b7f51..e72aee913a 100644 --- a/packages/core/src/hooks/hookEventHandler.ts +++ b/packages/core/src/hooks/hookEventHandler.ts @@ -11,6 +11,7 @@ import type { HookRunner } from './hookRunner.js'; import type { HookAggregator, AggregatedHookResult } from './hookAggregator.js'; import { HookEventName } from './types.js'; import type { + HookConfig, HookInput, BeforeToolInput, AfterToolInput, @@ -507,17 +508,38 @@ export class HookEventHandler { }; } + const onHookStart = (config: HookConfig, index: number) => { + coreEvents.emitHookStart({ + hookName: this.getHookName(config), + eventName, + hookIndex: index + 1, + totalHooks: plan.hookConfigs.length, + }); + }; + + const onHookEnd = (config: HookConfig, result: HookExecutionResult) => { + coreEvents.emitHookEnd({ + hookName: this.getHookName(config), + eventName, + success: result.success, + }); + }; + // Execute hooks according to the plan's strategy const results = plan.sequential ? await this.hookRunner.executeHooksSequential( plan.hookConfigs, eventName, input, + onHookStart, + onHookEnd, ) : await this.hookRunner.executeHooksParallel( plan.hookConfigs, eventName, input, + onHookStart, + onHookEnd, ); // Aggregate results @@ -659,11 +681,18 @@ export class HookEventHandler { // Other common fields like decision/reason are handled by specific hook output classes } + /** + * Get hook name from config for display or telemetry + */ + private getHookName(config: HookConfig): string { + return config.name || config.command || 'unknown-command'; + } + /** * Get hook name from execution result for telemetry */ private getHookNameFromResult(result: HookExecutionResult): string { - return result.hookConfig.command || 'unknown-command'; + return this.getHookName(result.hookConfig); } /** diff --git a/packages/core/src/hooks/hookRunner.test.ts b/packages/core/src/hooks/hookRunner.test.ts index 090ae8e0d8..5bc671b088 100644 --- a/packages/core/src/hooks/hookRunner.test.ts +++ b/packages/core/src/hooks/hookRunner.test.ts @@ -434,6 +434,37 @@ describe('HookRunner', () => { expect(spawn).toHaveBeenCalledTimes(2); }); + it('should call onHookStart and onHookEnd callbacks', async () => { + const configs: HookConfig[] = [ + { name: 'hook1', type: HookType.Command, command: './hook1.sh' }, + ]; + + mockSpawn.mockProcessOn.mockImplementation( + (event: string, callback: (code: number) => void) => { + if (event === 'close') { + setImmediate(() => callback(0)); + } + }, + ); + + const onStart = vi.fn(); + const onEnd = vi.fn(); + + await hookRunner.executeHooksParallel( + configs, + HookEventName.BeforeTool, + mockInput, + onStart, + onEnd, + ); + + expect(onStart).toHaveBeenCalledWith(configs[0], 0); + expect(onEnd).toHaveBeenCalledWith( + configs[0], + expect.objectContaining({ success: true }), + ); + }); + it('should handle mixed success and failure', async () => { const configs: HookConfig[] = [ { type: HookType.Command, command: './hook1.sh' }, @@ -498,6 +529,37 @@ describe('HookRunner', () => { expect(executionOrder).toEqual(['./hook1.sh', './hook2.sh']); }); + it('should call onHookStart and onHookEnd callbacks sequentially', async () => { + const configs: HookConfig[] = [ + { name: 'hook1', type: HookType.Command, command: './hook1.sh' }, + { name: 'hook2', type: HookType.Command, command: './hook2.sh' }, + ]; + + mockSpawn.mockProcessOn.mockImplementation( + (event: string, callback: (code: number) => void) => { + if (event === 'close') { + setImmediate(() => callback(0)); + } + }, + ); + + const onStart = vi.fn(); + const onEnd = vi.fn(); + + await hookRunner.executeHooksSequential( + configs, + HookEventName.BeforeTool, + mockInput, + onStart, + onEnd, + ); + + expect(onStart).toHaveBeenCalledTimes(2); + expect(onEnd).toHaveBeenCalledTimes(2); + expect(onStart).toHaveBeenNthCalledWith(1, configs[0], 0); + expect(onStart).toHaveBeenNthCalledWith(2, configs[1], 1); + }); + it('should continue execution even if a hook fails', async () => { const configs: HookConfig[] = [ { type: HookType.Command, command: './hook1.sh' }, diff --git a/packages/core/src/hooks/hookRunner.ts b/packages/core/src/hooks/hookRunner.ts index 79aa4a1fd6..33d0404e6b 100644 --- a/packages/core/src/hooks/hookRunner.ts +++ b/packages/core/src/hooks/hookRunner.ts @@ -105,10 +105,15 @@ export class HookRunner { hookConfigs: HookConfig[], eventName: HookEventName, input: HookInput, + onHookStart?: (config: HookConfig, index: number) => void, + onHookEnd?: (config: HookConfig, result: HookExecutionResult) => void, ): Promise { - const promises = hookConfigs.map((config) => - this.executeHook(config, eventName, input), - ); + const promises = hookConfigs.map(async (config, index) => { + onHookStart?.(config, index); + const result = await this.executeHook(config, eventName, input); + onHookEnd?.(config, result); + return result; + }); return Promise.all(promises); } @@ -120,12 +125,17 @@ export class HookRunner { hookConfigs: HookConfig[], eventName: HookEventName, input: HookInput, + onHookStart?: (config: HookConfig, index: number) => void, + onHookEnd?: (config: HookConfig, result: HookExecutionResult) => void, ): Promise { const results: HookExecutionResult[] = []; let currentInput = input; - for (const config of hookConfigs) { + for (let i = 0; i < hookConfigs.length; i++) { + const config = hookConfigs[i]; + onHookStart?.(config, i); const result = await this.executeHook(config, eventName, currentInput); + onHookEnd?.(config, result); results.push(result); // If the hook succeeded and has output, use it to modify the input for the next hook diff --git a/packages/core/src/utils/events.test.ts b/packages/core/src/utils/events.test.ts index 497bec398f..5b84af0628 100644 --- a/packages/core/src/utils/events.test.ts +++ b/packages/core/src/utils/events.test.ts @@ -274,4 +274,35 @@ describe('CoreEventEmitter', () => { expect(listener).toHaveBeenCalledWith({ model: newModel }); }); }); + + describe('Hook Events', () => { + it('should emit HookStart event with correct payload using helper', () => { + const listener = vi.fn(); + events.on(CoreEvent.HookStart, listener); + + const payload = { + hookName: 'test-hook', + eventName: 'before-agent', + hookIndex: 1, + totalHooks: 1, + }; + events.emitHookStart(payload); + + expect(listener).toHaveBeenCalledWith(payload); + }); + + it('should emit HookEnd event with correct payload using helper', () => { + const listener = vi.fn(); + events.on(CoreEvent.HookEnd, listener); + + const payload = { + hookName: 'test-hook', + eventName: 'before-agent', + success: true, + }; + events.emitHookEnd(payload); + + expect(listener).toHaveBeenCalledWith(payload); + }); + }); }); diff --git a/packages/core/src/utils/events.ts b/packages/core/src/utils/events.ts index aebc1901a2..84058f9d99 100644 --- a/packages/core/src/utils/events.ts +++ b/packages/core/src/utils/events.ts @@ -67,6 +67,36 @@ export interface MemoryChangedPayload { fileCount: number; } +/** + * Base payload for hook-related events. + */ +export interface HookPayload { + hookName: string; + eventName: string; +} + +/** + * Payload for the 'hook-start' event. + */ +export interface HookStartPayload extends HookPayload { + /** + * The 1-based index of the current hook in the execution sequence. + * Used for progress indication (e.g. "Hook 1/3"). + */ + hookIndex?: number; + /** + * The total number of hooks in the current execution sequence. + */ + totalHooks?: number; +} + +/** + * Payload for the 'hook-end' event. + */ +export interface HookEndPayload extends HookPayload { + success: boolean; +} + export enum CoreEvent { UserFeedback = 'user-feedback', ModelChanged = 'model-changed', @@ -75,6 +105,8 @@ export enum CoreEvent { MemoryChanged = 'memory-changed', ExternalEditorClosed = 'external-editor-closed', SettingsChanged = 'settings-changed', + HookStart = 'hook-start', + HookEnd = 'hook-end', } export interface CoreEvents { @@ -85,6 +117,8 @@ export interface CoreEvents { [CoreEvent.MemoryChanged]: [MemoryChangedPayload]; [CoreEvent.ExternalEditorClosed]: never[]; [CoreEvent.SettingsChanged]: never[]; + [CoreEvent.HookStart]: [HookStartPayload]; + [CoreEvent.HookEnd]: [HookEndPayload]; } type EventBacklogItem = { @@ -172,6 +206,20 @@ export class CoreEventEmitter extends EventEmitter { this.emit(CoreEvent.SettingsChanged); } + /** + * Notifies subscribers that a hook execution has started. + */ + emitHookStart(payload: HookStartPayload): void { + this.emit(CoreEvent.HookStart, payload); + } + + /** + * Notifies subscribers that a hook execution has ended. + */ + emitHookEnd(payload: HookEndPayload): void { + this.emit(CoreEvent.HookEnd, payload); + } + /** * Flushes buffered messages. Call this immediately after primary UI listener * subscribes. diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index 4900fa25d6..7c6f1cf3c7 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -1512,6 +1512,13 @@ "type": "string" } }, + "notifications": { + "title": "Hook Notifications", + "description": "Show visual indicators when hooks are executing.", + "markdownDescription": "Show visual indicators when hooks are executing.\n\n- Category: `Advanced`\n- Requires restart: `no`\n- Default: `true`", + "default": true, + "type": "boolean" + }, "BeforeTool": { "title": "Before Tool Hooks", "description": "Hooks that execute before tool execution. Can intercept, validate, or modify tool calls.", From c31f05356ae3cd9a51e55319ebe3a5ae41abc48c Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Tue, 6 Jan 2026 16:19:29 -0500 Subject: [PATCH 009/713] fix: image token estimation (#16004) --- packages/core/src/core/client.ts | 3 ++- .../core/src/utils/tokenCalculation.test.ts | 22 ++++++++++++++-- packages/core/src/utils/tokenCalculation.ts | 25 +++++++++++++++---- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/packages/core/src/core/client.ts b/packages/core/src/core/client.ts index ecd1eff471..48da7e43e7 100644 --- a/packages/core/src/core/client.ts +++ b/packages/core/src/core/client.ts @@ -60,6 +60,7 @@ import { applyModelSelection, createAvailabilityContextProvider, } from '../availability/policyHelpers.js'; +import { resolveModel } from '../config/models.js'; import type { RetryAvailabilityContext } from '../utils/retry.js'; const MAX_TURNS = 100; @@ -508,7 +509,7 @@ export class GeminiClient { // Availability logic: The configured model is the source of truth, // including any permanent fallbacks (config.setModel) or manual overrides. - return this.config.getActiveModel(); + return resolveModel(this.config.getActiveModel()); } private async *processTurn( diff --git a/packages/core/src/utils/tokenCalculation.test.ts b/packages/core/src/utils/tokenCalculation.test.ts index 7e1eae3e88..c6e54bc887 100644 --- a/packages/core/src/utils/tokenCalculation.test.ts +++ b/packages/core/src/utils/tokenCalculation.test.ts @@ -123,8 +123,26 @@ describe('calculateRequestTokenCount', () => { // Should fallback to estimation: // 'Hello': 5 chars * 0.25 = 1.25 - // inlineData: JSON.stringify length / 4 - expect(count).toBeGreaterThan(0); + // inlineData: 3000 + // Total: 3001.25 -> 3001 + expect(count).toBe(3001); expect(mockContentGenerator.countTokens).toHaveBeenCalled(); }); + + it('should use fixed estimate for images in fallback', async () => { + vi.mocked(mockContentGenerator.countTokens).mockRejectedValue( + new Error('API error'), + ); + const request = [ + { inlineData: { mimeType: 'image/png', data: 'large_data' } }, + ]; + + const count = await calculateRequestTokenCount( + request, + mockContentGenerator, + model, + ); + + expect(count).toBe(3000); + }); }); diff --git a/packages/core/src/utils/tokenCalculation.ts b/packages/core/src/utils/tokenCalculation.ts index 0359cb3e7c..06292bb925 100644 --- a/packages/core/src/utils/tokenCalculation.ts +++ b/packages/core/src/utils/tokenCalculation.ts @@ -6,6 +6,7 @@ import type { PartListUnion, Part } from '@google/genai'; import type { ContentGenerator } from '../core/contentGenerator.js'; +import { debugLogger } from './debugLogger.js'; // Token estimation constants // ASCII characters (0-127) are roughly 4 chars per token @@ -13,6 +14,8 @@ const ASCII_TOKENS_PER_CHAR = 0.25; // Non-ASCII characters (including CJK) are often 1-2 tokens per char. // We use 1.3 as a conservative estimate to avoid underestimation. const NON_ASCII_TOKENS_PER_CHAR = 1.3; +// Fixed token estimate for images +const IMAGE_TOKEN_ESTIMATE = 3000; /** * Estimates token count for parts synchronously using a heuristic. @@ -31,10 +34,21 @@ export function estimateTokenCountSync(parts: Part[]): number { } } } else { - // For non-text parts (functionCall, functionResponse, executableCode, etc.), - // we fallback to the JSON string length heuristic. - // Note: This is an approximation. - totalTokens += JSON.stringify(part).length / 4; + // For images, we use a fixed safe estimate (3,000 tokens) covering + // up to 4K resolution on Gemini 3. + // See: https://ai.google.dev/gemini-api/docs/vision#token_counting + const inlineData = 'inlineData' in part ? part.inlineData : undefined; + const fileData = 'fileData' in part ? part.fileData : undefined; + const mimeType = inlineData?.mimeType || fileData?.mimeType; + + if (mimeType?.startsWith('image/')) { + totalTokens += IMAGE_TOKEN_ESTIMATE; + } else { + // For other non-text parts (functionCall, functionResponse, etc.), + // we fallback to the JSON string length heuristic. + // Note: This is an approximation. + totalTokens += JSON.stringify(part).length / 4; + } } } return Math.floor(totalTokens); @@ -69,8 +83,9 @@ export async function calculateRequestTokenCount( contents: [{ role: 'user', parts }], }); return response.totalTokens ?? 0; - } catch { + } catch (error) { // Fallback to local estimation if the API call fails + debugLogger.debug('countTokens API failed:', error); return estimateTokenCountSync(parts); } } From 56092bd782058b581ecf11b949211afdc2182f6b Mon Sep 17 00:00:00 2001 From: joshualitt Date: Tue, 6 Jan 2026 13:33:37 -0800 Subject: [PATCH 010/713] feat(hooks): Add a hooks.enabled setting. (#15933) --- docs/get-started/configuration.md | 13 +-- integration-tests/hooks-agent-flow.test.ts | 12 +-- integration-tests/hooks-system.test.ts | 90 +++++-------------- .../cli/src/commands/hooks/migrate.test.ts | 2 +- packages/cli/src/commands/hooks/migrate.ts | 2 +- packages/cli/src/config/config.ts | 5 +- packages/cli/src/config/extension-manager.ts | 3 +- packages/cli/src/config/extension.test.ts | 10 +-- packages/cli/src/config/settingsSchema.ts | 22 ++++- .../cli/src/ui/commands/hooksCommand.test.ts | 2 +- packages/cli/src/ui/commands/hooksCommand.ts | 2 +- packages/core/src/config/config.ts | 2 +- schemas/settings.schema.json | 15 +++- 13 files changed, 79 insertions(+), 101 deletions(-) diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 58483baed1..5e50764d2b 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -685,11 +685,9 @@ their corresponding top-level category object in your `settings.json` file. - **Requires restart:** Yes - **`tools.enableHooks`** (boolean): - - **Description:** Enable the hooks system for intercepting and customizing - Gemini CLI behavior. When enabled, hooks configured in settings will execute - at appropriate lifecycle events (BeforeTool, AfterTool, BeforeModel, etc.). - Requires MessageBus integration. - - **Default:** `false` + - **Description:** Enables the hooks system experiment. When disabled, the + hooks system is completely deactivated regardless of other settings. + - **Default:** `true` - **Requires restart:** Yes #### `mcp` @@ -867,6 +865,11 @@ their corresponding top-level category object in your `settings.json` file. #### `hooks` +- **`hooks.enabled`** (boolean): + - **Description:** Canonical toggle for the hooks system. When disabled, no + hooks will be executed. + - **Default:** `false` + - **`hooks.disabled`** (array): - **Description:** List of hook names (commands) that should be disabled. Hooks in this list will not execute even if configured. diff --git a/integration-tests/hooks-agent-flow.test.ts b/integration-tests/hooks-agent-flow.test.ts index 45dbb4b0e3..544d4e6072 100644 --- a/integration-tests/hooks-agent-flow.test.ts +++ b/integration-tests/hooks-agent-flow.test.ts @@ -53,10 +53,8 @@ describe('Hooks Agent Flow', () => { await rig.setup('should inject additional context via BeforeAgent hook', { settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeAgent: [ { hooks: [ @@ -118,10 +116,8 @@ describe('Hooks Agent Flow', () => { await rig.setup('should receive prompt and response in AfterAgent hook', { settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, AfterAgent: [ { hooks: [ @@ -167,10 +163,8 @@ describe('Hooks Agent Flow', () => { 'hooks-agent-flow-multistep.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeAgent: [ { hooks: [ diff --git a/integration-tests/hooks-system.test.ts b/integration-tests/hooks-system.test.ts index 34827a5f7c..c353f98511 100644 --- a/integration-tests/hooks-system.test.ts +++ b/integration-tests/hooks-system.test.ts @@ -32,10 +32,8 @@ describe('Hooks System Integration', () => { 'hooks-system.block-tool.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeTool: [ { matcher: 'write_file', @@ -86,10 +84,8 @@ describe('Hooks System Integration', () => { 'hooks-system.allow-tool.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeTool: [ { matcher: 'write_file', @@ -136,10 +132,8 @@ describe('Hooks System Integration', () => { 'hooks-system.after-tool-context.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, AfterTool: [ { matcher: 'read_file', @@ -211,10 +205,8 @@ console.log(JSON.stringify({ await rig.setup('should modify LLM requests with BeforeModel hooks', { settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeModel: [ { hooks: [ @@ -294,10 +286,8 @@ console.log(JSON.stringify({ await rig.setup('should modify LLM responses with AfterModel hooks', { settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, AfterModel: [ { hooks: [ @@ -347,10 +337,8 @@ console.log(JSON.stringify({ { settings: { debugMode: true, - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeToolSelection: [ { hooks: [ @@ -415,10 +403,8 @@ console.log(JSON.stringify({ await rig.setup('should augment prompts with BeforeAgent hooks', { settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeAgent: [ { hooks: [ @@ -460,11 +446,11 @@ console.log(JSON.stringify({ settings: { // Configure tools to enable hooks and require confirmation to trigger notifications tools: { - enableHooks: true, approval: 'ASK', // Disable YOLO mode to show permission prompts confirmationRequired: ['run_shell_command'], }, hooks: { + enabled: true, Notification: [ { matcher: 'ToolPermission', @@ -554,10 +540,8 @@ console.log(JSON.stringify({ 'hooks-system.sequential-execution.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeAgent: [ { sequential: true, @@ -636,10 +620,8 @@ try { await rig.setup('should provide correct input format to hooks', { settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeTool: [ { hooks: [ @@ -689,10 +671,8 @@ try { 'hooks-system.multiple-events.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeAgent: [ { hooks: [ @@ -804,10 +784,8 @@ try { await rig.setup('should handle hook failures gracefully', { settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeTool: [ { hooks: [ @@ -858,10 +836,8 @@ try { 'hooks-system.telemetry.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeTool: [ { hooks: [ @@ -901,10 +877,8 @@ try { 'hooks-system.session-startup.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, SessionStart: [ { matcher: 'startup', @@ -974,10 +948,8 @@ console.log(JSON.stringify({ await rig.setup('should fire SessionStart hook and inject context', { settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, SessionStart: [ { matcher: 'startup', @@ -1059,10 +1031,8 @@ console.log(JSON.stringify({ 'should fire SessionStart hook and display systemMessage in interactive mode', { settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, SessionStart: [ { matcher: 'startup', @@ -1129,10 +1099,8 @@ console.log(JSON.stringify({ 'hooks-system.session-clear.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, SessionEnd: [ { matcher: '*', @@ -1303,10 +1271,8 @@ console.log(JSON.stringify({ 'hooks-system.compress-auto.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, PreCompress: [ { matcher: 'auto', @@ -1370,10 +1336,8 @@ console.log(JSON.stringify({ 'hooks-system.session-startup.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, SessionEnd: [ { matcher: 'exit', @@ -1470,10 +1434,8 @@ console.log(JSON.stringify({decision: "block", systemMessage: "Disabled hook sho await rig.setup('should not execute hooks disabled in settings file', { settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeTool: [ { hooks: [ @@ -1552,10 +1514,8 @@ console.log(JSON.stringify({decision: "block", systemMessage: "Disabled hook sho 'should respect disabled hooks across multiple operations', { settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeTool: [ { hooks: [ @@ -1664,10 +1624,8 @@ console.log(JSON.stringify({decision: "block", systemMessage: "Disabled hook sho 'hooks-system.input-modification.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeTool: [ { matcher: 'write_file', @@ -1751,10 +1709,8 @@ console.log(JSON.stringify({decision: "block", systemMessage: "Disabled hook sho 'hooks-system.before-tool-stop.responses', ), settings: { - tools: { - enableHooks: true, - }, hooks: { + enabled: true, BeforeTool: [ { matcher: 'write_file', diff --git a/packages/cli/src/commands/hooks/migrate.test.ts b/packages/cli/src/commands/hooks/migrate.test.ts index 29811d39b1..03885af651 100644 --- a/packages/cli/src/commands/hooks/migrate.test.ts +++ b/packages/cli/src/commands/hooks/migrate.test.ts @@ -512,7 +512,7 @@ describe('migrate command', () => { '\nMigration complete! Please review the migrated hooks in .gemini/settings.json', ); expect(debugLoggerLogSpy).toHaveBeenCalledWith( - 'Note: Set tools.enableHooks to true in your settings to enable the hook system.', + 'Note: Set hooks.enabled to true in your settings to enable the hook system.', ); }); }); diff --git a/packages/cli/src/commands/hooks/migrate.ts b/packages/cli/src/commands/hooks/migrate.ts index c2fe65d574..36a1344f74 100644 --- a/packages/cli/src/commands/hooks/migrate.ts +++ b/packages/cli/src/commands/hooks/migrate.ts @@ -243,7 +243,7 @@ export async function handleMigrateFromClaude() { '\nMigration complete! Please review the migrated hooks in .gemini/settings.json', ); debugLogger.log( - 'Note: Set tools.enableHooks to true in your settings to enable the hook system.', + 'Note: Set hooks.enabled to true in your settings to enable the hook system.', ); } catch (error) { debugLogger.error(`Error saving migrated hooks: ${getErrorMessage(error)}`); diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 440f6e7a90..8f233f77fa 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -53,6 +53,7 @@ import { requestConsentNonInteractive } from './extensions/consent.js'; import { promptForSetting } from './extensions/extensionSettings.js'; import type { EventEmitter } from 'node:stream'; import { runExitCleanup } from '../utils/cleanup.js'; +import { getEnableHooks } from './settingsSchema.js'; export interface CliArgs { query: string | undefined; @@ -291,7 +292,7 @@ export async function parseArguments(settings: Settings): Promise { } // Register hooks command if hooks are enabled - if (settings?.tools?.enableHooks) { + if (getEnableHooks(settings)) { yargsInstance.command(hooksCommand); } @@ -722,7 +723,7 @@ export async function loadCliConfig( ptyInfo: ptyInfo?.name, modelConfigServiceConfig: settings.modelConfigs, // TODO: loading of hooks based on workspace trust - enableHooks: settings.tools?.enableHooks, + enableHooks: getEnableHooks(settings), hooks: settings.hooks || {}, projectHooks: projectHooks || {}, onModelChange: (model: string) => saveModelChange(loadedSettings, model), diff --git a/packages/cli/src/config/extension-manager.ts b/packages/cli/src/config/extension-manager.ts index 8c1c8e0a77..4fc9aa6258 100644 --- a/packages/cli/src/config/extension-manager.ts +++ b/packages/cli/src/config/extension-manager.ts @@ -64,6 +64,7 @@ import { type ExtensionSetting, } from './extensions/extensionSettings.js'; import type { EventEmitter } from 'node:stream'; +import { getEnableHooks } from './settingsSchema.js'; interface ExtensionManagerParams { enabledExtensionOverrides?: string[]; @@ -551,7 +552,7 @@ Would you like to attempt to install via "git clone" instead?`, .filter((contextFilePath) => fs.existsSync(contextFilePath)); let hooks: { [K in HookEventName]?: HookDefinition[] } | undefined; - if (this.settings.tools?.enableHooks) { + if (getEnableHooks(this.settings)) { hooks = await this.loadExtensionHooks(effectiveExtensionPath, { extensionPath: effectiveExtensionPath, workspacePath: this.workspaceDir, diff --git a/packages/cli/src/config/extension.test.ts b/packages/cli/src/config/extension.test.ts index 530d171cd7..9a60b96e40 100644 --- a/packages/cli/src/config/extension.test.ts +++ b/packages/cli/src/config/extension.test.ts @@ -750,8 +750,8 @@ describe('extension tests', () => { ); const settings = loadSettings(tempWorkspaceDir).merged; - if (!settings.tools) settings.tools = {}; - settings.tools.enableHooks = true; + if (!settings.hooks) settings.hooks = {}; + settings.hooks.enabled = true; extensionManager = new ExtensionManager({ workspaceDir: tempWorkspaceDir, @@ -771,7 +771,7 @@ describe('extension tests', () => { ); }); - it('should not load hooks if enableHooks is false', async () => { + it('should not load hooks if hooks.enabled is false', async () => { const extDir = createExtension({ extensionsDir: userExtensionsDir, name: 'hook-extension-disabled', @@ -786,8 +786,8 @@ describe('extension tests', () => { ); const settings = loadSettings(tempWorkspaceDir).merged; - if (!settings.tools) settings.tools = {}; - settings.tools.enableHooks = false; + if (!settings.hooks) settings.hooks = {}; + settings.hooks.enabled = false; extensionManager = new ExtensionManager({ workspaceDir: tempWorkspaceDir, diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index 08fb30a3cf..ba5f9895cd 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -1075,12 +1075,12 @@ const SETTINGS_SCHEMA = { }, enableHooks: { type: 'boolean', - label: 'Enable Hooks System', + label: 'Enable Hooks System (Experimental)', category: 'Advanced', requiresRestart: true, - default: false, + default: true, description: - 'Enable the hooks system for intercepting and customizing Gemini CLI behavior. When enabled, hooks configured in settings will execute at appropriate lifecycle events (BeforeTool, AfterTool, BeforeModel, etc.). Requires MessageBus integration.', + 'Enables the hooks system experiment. When disabled, the hooks system is completely deactivated regardless of other settings.', showInDialog: false, }, }, @@ -1544,6 +1544,16 @@ const SETTINGS_SCHEMA = { 'Hook configurations for intercepting and customizing agent behavior.', showInDialog: false, properties: { + enabled: { + type: 'boolean', + label: 'Enable Hooks', + category: 'Advanced', + requiresRestart: false, + default: false, + description: + 'Canonical toggle for the hooks system. When disabled, no hooks will be executed.', + showInDialog: false, + }, disabled: { type: 'array', label: 'Disabled Hooks', @@ -2057,3 +2067,9 @@ type InferSettings = { }; export type Settings = InferSettings; + +export function getEnableHooks(settings: Settings): boolean { + return ( + (settings.tools?.enableHooks ?? true) && (settings.hooks?.enabled ?? false) + ); +} diff --git a/packages/cli/src/ui/commands/hooksCommand.test.ts b/packages/cli/src/ui/commands/hooksCommand.test.ts index 990228809c..54a3edc991 100644 --- a/packages/cli/src/ui/commands/hooksCommand.test.ts +++ b/packages/cli/src/ui/commands/hooksCommand.test.ts @@ -147,7 +147,7 @@ describe('hooksCommand', () => { type: 'message', messageType: 'info', content: - 'Hook system is not enabled. Enable it in settings with tools.enableHooks', + 'Hook system is not enabled. Enable it in settings with hooks.enabled.', }); }); diff --git a/packages/cli/src/ui/commands/hooksCommand.ts b/packages/cli/src/ui/commands/hooksCommand.ts index 6bbfbb83e7..8028173a84 100644 --- a/packages/cli/src/ui/commands/hooksCommand.ts +++ b/packages/cli/src/ui/commands/hooksCommand.ts @@ -35,7 +35,7 @@ async function panelAction( type: 'message', messageType: 'info', content: - 'Hook system is not enabled. Enable it in settings with tools.enableHooks', + 'Hook system is not enabled. Enable it in settings with hooks.enabled.', }; } diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 1891cfbc60..616743acda 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -753,7 +753,7 @@ export class Config { } // Initialize hook system if enabled - if (this.enableHooks) { + if (this.getEnableHooks()) { this.hookSystem = new HookSystem(this); await this.hookSystem.initialize(); } diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index 7c6f1cf3c7..cbf96f738d 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -1129,10 +1129,10 @@ "type": "number" }, "enableHooks": { - "title": "Enable Hooks System", - "description": "Enable the hooks system for intercepting and customizing Gemini CLI behavior. When enabled, hooks configured in settings will execute at appropriate lifecycle events (BeforeTool, AfterTool, BeforeModel, etc.). Requires MessageBus integration.", - "markdownDescription": "Enable the hooks system for intercepting and customizing Gemini CLI behavior. When enabled, hooks configured in settings will execute at appropriate lifecycle events (BeforeTool, AfterTool, BeforeModel, etc.). Requires MessageBus integration.\n\n- Category: `Advanced`\n- Requires restart: `yes`\n- Default: `false`", - "default": false, + "title": "Enable Hooks System (Experimental)", + "description": "Enables the hooks system experiment. When disabled, the hooks system is completely deactivated regardless of other settings.", + "markdownDescription": "Enables the hooks system experiment. When disabled, the hooks system is completely deactivated regardless of other settings.\n\n- Category: `Advanced`\n- Requires restart: `yes`\n- Default: `true`", + "default": true, "type": "boolean" } }, @@ -1502,6 +1502,13 @@ "default": {}, "type": "object", "properties": { + "enabled": { + "title": "Enable Hooks", + "description": "Canonical toggle for the hooks system. When disabled, no hooks will be executed.", + "markdownDescription": "Canonical toggle for the hooks system. When disabled, no hooks will be executed.\n\n- Category: `Advanced`\n- Requires restart: `no`\n- Default: `false`", + "default": false, + "type": "boolean" + }, "disabled": { "title": "Disabled Hooks", "description": "List of hook names (commands) that should be disabled. Hooks in this list will not execute even if configured.", From 2fe45834dde6dac5a1bff2d4df4926b28755eaf0 Mon Sep 17 00:00:00 2001 From: Shreya Keshive Date: Tue, 6 Jan 2026 16:38:07 -0500 Subject: [PATCH 011/713] feat(admin): Introduce remote admin settings & implement secureModeEnabled/mcpEnabled (#15935) --- docs/get-started/configuration.md | 15 ++ packages/cli/src/config/config.test.ts | 133 +++++++++++++++++- packages/cli/src/config/config.ts | 36 +++-- packages/cli/src/config/settingsSchema.ts | 68 +++++++++ .../src/services/BuiltinCommandLoader.test.ts | 3 + .../cli/src/services/BuiltinCommandLoader.ts | 28 +++- packages/core/src/code_assist/types.ts | 23 +++ packages/core/src/config/config.ts | 17 +++ schemas/settings.schema.json | 51 +++++++ 9 files changed, 360 insertions(+), 14 deletions(-) diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 5e50764d2b..047a0eff31 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -933,6 +933,21 @@ their corresponding top-level category object in your `settings.json` file. - **Description:** Hooks that execute before tool selection. Can filter or prioritize available tools dynamically. - **Default:** `[]` + +#### `admin` + +- **`admin.secureModeEnabled`** (boolean): + - **Description:** If true, disallows yolo mode from being used. + - **Default:** `false` + +- **`admin.extensions.enabled`** (boolean): + - **Description:** If false, disallows extensions from being installed or + used. + - **Default:** `true` + +- **`admin.mcp.enabled`** (boolean): + - **Description:** If false, disallows MCP servers from being used. + - **Default:** `true` #### `mcpServers` diff --git a/packages/cli/src/config/config.test.ts b/packages/cli/src/config/config.test.ts index 3d5b45df80..465ed90bca 100644 --- a/packages/cli/src/config/config.test.ts +++ b/packages/cli/src/config/config.test.ts @@ -1069,7 +1069,7 @@ describe('Approval mode tool exclusion logic', () => { }; await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow( - 'Cannot start in YOLO mode when it is disabled by settings', + 'Cannot start in YOLO mode since it is disabled by your admin', ); }); @@ -2412,3 +2412,134 @@ describe('Policy Engine Integration in loadCliConfig', () => { ); }); }); + +describe('loadCliConfig secureModeEnabled', () => { + beforeEach(() => { + vi.resetAllMocks(); + vi.mocked(os.homedir).mockReturnValue('/mock/home/user'); + vi.stubEnv('GEMINI_API_KEY', 'test-api-key'); + vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([]); + vi.mocked(isWorkspaceTrusted).mockReturnValue({ + isTrusted: true, + source: undefined, + }); + }); + + afterEach(() => { + vi.unstubAllEnvs(); + vi.restoreAllMocks(); + }); + + it('should throw an error if YOLO mode is attempted when secureModeEnabled is true', async () => { + process.argv = ['node', 'script.js', '--yolo']; + const argv = await parseArguments({} as Settings); + const settings: Settings = { + admin: { + secureModeEnabled: true, + }, + }; + + await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow( + 'Cannot start in YOLO mode since it is disabled by your admin', + ); + }); + + it('should throw an error if approval-mode=yolo is attempted when secureModeEnabled is true', async () => { + process.argv = ['node', 'script.js', '--approval-mode=yolo']; + const argv = await parseArguments({} as Settings); + const settings: Settings = { + admin: { + secureModeEnabled: true, + }, + }; + + await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow( + 'Cannot start in YOLO mode since it is disabled by your admin', + ); + }); + + it('should set disableYoloMode to true when secureModeEnabled is true', async () => { + process.argv = ['node', 'script.js']; + const argv = await parseArguments({} as Settings); + const settings: Settings = { + admin: { + secureModeEnabled: true, + }, + }; + const config = await loadCliConfig(settings, 'test-session', argv); + expect(config.isYoloModeDisabled()).toBe(true); + }); +}); + +describe('loadCliConfig mcpEnabled', () => { + beforeEach(() => { + vi.resetAllMocks(); + vi.mocked(os.homedir).mockReturnValue('/mock/home/user'); + vi.stubEnv('GEMINI_API_KEY', 'test-api-key'); + vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([]); + }); + + afterEach(() => { + vi.unstubAllEnvs(); + vi.restoreAllMocks(); + }); + + const mcpSettings = { + mcp: { + serverCommand: 'mcp-server', + allowed: ['serverA'], + excluded: ['serverB'], + }, + mcpServers: { serverA: { url: 'http://a' } }, + }; + + it('should enable MCP by default', async () => { + process.argv = ['node', 'script.js']; + const argv = await parseArguments({} as Settings); + const settings: Settings = { ...mcpSettings }; + const config = await loadCliConfig(settings, 'test-session', argv); + expect(config.getMcpEnabled()).toBe(true); + expect(config.getMcpServerCommand()).toBe('mcp-server'); + expect(config.getMcpServers()).toEqual({ serverA: { url: 'http://a' } }); + expect(config.getAllowedMcpServers()).toEqual(['serverA']); + expect(config.getBlockedMcpServers()).toEqual(['serverB']); + }); + + it('should disable MCP when mcpEnabled is false', async () => { + process.argv = ['node', 'script.js']; + const argv = await parseArguments({} as Settings); + const settings: Settings = { + ...mcpSettings, + admin: { + mcp: { + enabled: false, + }, + }, + }; + const config = await loadCliConfig(settings, 'test-session', argv); + expect(config.getMcpEnabled()).toBe(false); + expect(config.getMcpServerCommand()).toBeUndefined(); + expect(config.getMcpServers()).toEqual({}); + expect(config.getAllowedMcpServers()).toEqual([]); + expect(config.getBlockedMcpServers()).toEqual([]); + }); + + it('should enable MCP when mcpEnabled is true', async () => { + process.argv = ['node', 'script.js']; + const argv = await parseArguments({} as Settings); + const settings: Settings = { + ...mcpSettings, + admin: { + mcp: { + enabled: true, + }, + }, + }; + const config = await loadCliConfig(settings, 'test-session', argv); + expect(config.getMcpEnabled()).toBe(true); + expect(config.getMcpServerCommand()).toBe('mcp-server'); + expect(config.getMcpServers()).toEqual({ serverA: { url: 'http://a' } }); + expect(config.getAllowedMcpServers()).toEqual(['serverA']); + expect(config.getBlockedMcpServers()).toEqual(['serverB']); + }); +}); diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 8f233f77fa..aa00fbe9f2 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -505,11 +505,19 @@ export async function loadCliConfig( } // Override approval mode if disableYoloMode is set. - if (settings.security?.disableYoloMode) { + if (settings.security?.disableYoloMode || settings.admin?.secureModeEnabled) { if (approvalMode === ApprovalMode.YOLO) { - debugLogger.error('YOLO mode is disabled by the "disableYolo" setting.'); + if (settings.admin?.secureModeEnabled) { + debugLogger.error( + 'YOLO mode is disabled by "secureModeEnabled" setting.', + ); + } else { + debugLogger.error( + 'YOLO mode is disabled by the "disableYolo" setting.', + ); + } throw new FatalConfigError( - 'Cannot start in YOLO mode when it is disabled by settings', + 'Cannot start in YOLO mode since it is disabled by your admin', ); } approvalMode = ApprovalMode.DEFAULT; @@ -628,6 +636,8 @@ export async function loadCliConfig( const ptyInfo = await getPty(); + const mcpEnabled = settings.admin?.mcp?.enabled ?? true; + return new Config({ sessionId, embeddingModel: DEFAULT_GEMINI_EMBEDDING_MODEL, @@ -646,12 +656,17 @@ export async function loadCliConfig( excludeTools, toolDiscoveryCommand: settings.tools?.discoveryCommand, toolCallCommand: settings.tools?.callCommand, - mcpServerCommand: settings.mcp?.serverCommand, - mcpServers: settings.mcpServers, - allowedMcpServers: argv.allowedMcpServerNames ?? settings.mcp?.allowed, - blockedMcpServers: argv.allowedMcpServerNames - ? undefined - : settings.mcp?.excluded, + mcpServerCommand: mcpEnabled ? settings.mcp?.serverCommand : undefined, + mcpServers: mcpEnabled ? settings.mcpServers : {}, + mcpEnabled, + allowedMcpServers: mcpEnabled + ? (argv.allowedMcpServerNames ?? settings.mcp?.allowed) + : undefined, + blockedMcpServers: mcpEnabled + ? argv.allowedMcpServerNames + ? undefined + : settings.mcp?.excluded + : undefined, blockedEnvironmentVariables: settings.security?.environmentVariableRedaction?.blocked, enableEnvironmentVariableRedaction: @@ -660,7 +675,8 @@ export async function loadCliConfig( geminiMdFileCount: fileCount, geminiMdFilePaths: filePaths, approvalMode, - disableYoloMode: settings.security?.disableYoloMode, + disableYoloMode: + settings.security?.disableYoloMode || settings.admin?.secureModeEnabled, showMemoryUsage: settings.ui?.showMemoryUsage || false, accessibility: { ...settings.ui?.accessibility, diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index ba5f9895cd..ee5a8e71c3 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -1718,6 +1718,74 @@ const SETTINGS_SCHEMA = { mergeStrategy: MergeStrategy.CONCAT, }, }, + + admin: { + type: 'object', + label: 'Admin', + category: 'Admin', + requiresRestart: false, + default: {}, + description: 'Settings configured remotely by enterprise admins.', + showInDialog: false, + mergeStrategy: MergeStrategy.REPLACE, + properties: { + secureModeEnabled: { + type: 'boolean', + label: 'Secure Mode Enabled', + category: 'Admin', + requiresRestart: false, + default: false, + description: 'If true, disallows yolo mode from being used.', + showInDialog: false, + mergeStrategy: MergeStrategy.REPLACE, + }, + extensions: { + type: 'object', + label: 'Extensions Settings', + category: 'Admin', + requiresRestart: false, + default: {}, + description: 'Extensions-specific admin settings.', + showInDialog: false, + mergeStrategy: MergeStrategy.REPLACE, + properties: { + enabled: { + type: 'boolean', + label: 'Extensions Enabled', + category: 'Admin', + requiresRestart: false, + default: true, + description: + 'If false, disallows extensions from being installed or used.', + showInDialog: false, + mergeStrategy: MergeStrategy.REPLACE, + }, + }, + }, + mcp: { + type: 'object', + label: 'MCP Settings', + category: 'Admin', + requiresRestart: false, + default: {}, + description: 'MCP-specific admin settings.', + showInDialog: false, + mergeStrategy: MergeStrategy.REPLACE, + properties: { + enabled: { + type: 'boolean', + label: 'MCP Enabled', + category: 'Admin', + requiresRestart: false, + default: true, + description: 'If false, disallows MCP servers from being used.', + showInDialog: false, + mergeStrategy: MergeStrategy.REPLACE, + }, + }, + }, + }, + }, } as const satisfies SettingsSchema; export type SettingsSchemaType = typeof SETTINGS_SCHEMA; diff --git a/packages/cli/src/services/BuiltinCommandLoader.test.ts b/packages/cli/src/services/BuiltinCommandLoader.test.ts index 4d8fe6773d..b99d58239e 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.test.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.test.ts @@ -102,6 +102,7 @@ describe('BuiltinCommandLoader', () => { getEnableExtensionReloading: () => false, getEnableHooks: () => false, isSkillsSupportEnabled: vi.fn().mockReturnValue(false), + getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ getAllSkills: vi.fn().mockReturnValue([]), }), @@ -179,6 +180,7 @@ describe('BuiltinCommandLoader', () => { const mockConfigWithMessageBus = { ...mockConfig, getEnableHooks: () => false, + getMcpEnabled: () => true, } as unknown as Config; const loader = new BuiltinCommandLoader(mockConfigWithMessageBus); const commands = await loader.loadCommands(new AbortController().signal); @@ -198,6 +200,7 @@ describe('BuiltinCommandLoader profile', () => { getEnableExtensionReloading: () => false, getEnableHooks: () => false, isSkillsSupportEnabled: vi.fn().mockReturnValue(false), + getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ getAllSkills: vi.fn().mockReturnValue([]), }), diff --git a/packages/cli/src/services/BuiltinCommandLoader.ts b/packages/cli/src/services/BuiltinCommandLoader.ts index 6978322bbf..31395c0172 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.ts @@ -6,8 +6,12 @@ import { isDevelopment } from '../utils/installationInfo.js'; import type { ICommandLoader } from './types.js'; -import type { SlashCommand } from '../ui/commands/types.js'; -import type { Config } from '@google/gemini-cli-core'; +import { + CommandKind, + type SlashCommand, + type CommandContext, +} from '../ui/commands/types.js'; +import type { MessageActionReturn, Config } from '@google/gemini-cli-core'; import { startupProfiler } from '@google/gemini-cli-core'; import { aboutCommand } from '../ui/commands/aboutCommand.js'; import { authCommand } from '../ui/commands/authCommand.js'; @@ -77,7 +81,25 @@ export class BuiltinCommandLoader implements ICommandLoader { ...(this.config?.getEnableHooks() ? [hooksCommand] : []), await ideCommand(), initCommand, - mcpCommand, + ...(this.config?.getMcpEnabled() === false + ? [ + { + name: 'mcp', + description: + 'Manage configured Model Context Protocol (MCP) servers', + kind: CommandKind.BUILT_IN, + autoExecute: false, + subCommands: [], + action: async ( + _context: CommandContext, + ): Promise => ({ + type: 'message', + messageType: 'error', + content: 'MCP disabled by your admin.', + }), + }, + ] + : [mcpCommand]), memoryCommand, modelCommand, ...(this.config?.getFolderTrust() ? [permissionsCommand] : []), diff --git a/packages/core/src/code_assist/types.ts b/packages/core/src/code_assist/types.ts index 824f6ff530..3fd81d465b 100644 --- a/packages/core/src/code_assist/types.ts +++ b/packages/core/src/code_assist/types.ts @@ -277,3 +277,26 @@ export interface ConversationInteraction { language?: string; isAgentic?: boolean; } + +export interface GeminiCodeAssistSetting { + secureModeEnabled?: boolean; + mcpSetting?: McpSetting; + cliFeatureSetting?: CliFeatureSetting; +} + +export interface McpSetting { + mcpEnabled?: boolean; + allowedMcpConfigs?: McpConfig[]; +} + +export interface McpConfig { + mcpServer?: string; +} + +export interface CliFeatureSetting { + extensionsSetting?: ExtensionsSetting; +} + +export interface ExtensionsSetting { + extensionsEnabled?: boolean; +} diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 616743acda..5859de2133 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -88,6 +88,7 @@ import type { PolicyEngineConfig } from '../policy/types.js'; import { HookSystem } from '../hooks/index.js'; import type { UserTierId } from '../code_assist/types.js'; import type { RetrieveUserQuotaResponse } from '../code_assist/types.js'; +import type { GeminiCodeAssistSetting } from '../code_assist/types.js'; import { getCodeAssistServer } from '../code_assist/codeAssist.js'; import type { Experiments } from '../code_assist/experiments/experiments.js'; import { AgentRegistry } from '../agents/registry.js'; @@ -356,6 +357,7 @@ export interface ConfigParameters { disabledSkills?: string[]; experimentalJitContext?: boolean; onModelChange?: (model: string) => void; + mcpEnabled?: boolean; onReload?: () => Promise<{ disabledSkills?: string[] }>; } @@ -389,6 +391,7 @@ export class Config { private readonly toolDiscoveryCommand: string | undefined; private readonly toolCallCommand: string | undefined; private readonly mcpServerCommand: string | undefined; + private readonly mcpEnabled: boolean; private mcpServers: Record | undefined; private userMemory: string; private geminiMdFileCount: number; @@ -491,6 +494,7 @@ export class Config { private readonly experimentalJitContext: boolean; private contextManager?: ContextManager; private terminalBackground: string | undefined = undefined; + private remoteAdminSettings: GeminiCodeAssistSetting | undefined; constructor(params: ConfigParameters) { this.sessionId = params.sessionId; @@ -512,6 +516,7 @@ export class Config { this.toolCallCommand = params.toolCallCommand; this.mcpServerCommand = params.mcpServerCommand; this.mcpServers = params.mcpServers; + this.mcpEnabled = params.mcpEnabled ?? true; this.allowedMcpServers = params.allowedMcpServers ?? []; this.blockedMcpServers = params.blockedMcpServers ?? []; this.allowedEnvironmentVariables = params.allowedEnvironmentVariables ?? []; @@ -894,6 +899,14 @@ export class Config { return this.terminalBackground; } + getRemoteAdminSettings(): GeminiCodeAssistSetting | undefined { + return this.remoteAdminSettings; + } + + setRemoteAdminSettings(settings: GeminiCodeAssistSetting): void { + this.remoteAdminSettings = settings; + } + shouldLoadMemoryFromIncludeDirectories(): boolean { return this.loadMemoryFromIncludeDirectories; } @@ -1125,6 +1138,10 @@ export class Config { return this.mcpServers; } + getMcpEnabled(): boolean { + return this.mcpEnabled; + } + getMcpClientManager(): McpClientManager | undefined { return this.mcpClientManager; } diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index cbf96f738d..f7f134d2c9 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -1608,6 +1608,57 @@ "type": "array", "items": {} } + }, + "admin": { + "title": "Admin", + "description": "Settings configured remotely by enterprise admins.", + "markdownDescription": "Settings configured remotely by enterprise admins.\n\n- Category: `Admin`\n- Requires restart: `no`\n- Default: `{}`", + "default": {}, + "type": "object", + "properties": { + "secureModeEnabled": { + "title": "Secure Mode Enabled", + "description": "If true, disallows yolo mode from being used.", + "markdownDescription": "If true, disallows yolo mode from being used.\n\n- Category: `Admin`\n- Requires restart: `no`\n- Default: `false`", + "default": false, + "type": "boolean" + }, + "extensions": { + "title": "Extensions Settings", + "description": "Extensions-specific admin settings.", + "markdownDescription": "Extensions-specific admin settings.\n\n- Category: `Admin`\n- Requires restart: `no`\n- Default: `{}`", + "default": {}, + "type": "object", + "properties": { + "enabled": { + "title": "Extensions Enabled", + "description": "If false, disallows extensions from being installed or used.", + "markdownDescription": "If false, disallows extensions from being installed or used.\n\n- Category: `Admin`\n- Requires restart: `no`\n- Default: `true`", + "default": true, + "type": "boolean" + } + }, + "additionalProperties": false + }, + "mcp": { + "title": "MCP Settings", + "description": "MCP-specific admin settings.", + "markdownDescription": "MCP-specific admin settings.\n\n- Category: `Admin`\n- Requires restart: `no`\n- Default: `{}`", + "default": {}, + "type": "object", + "properties": { + "enabled": { + "title": "MCP Enabled", + "description": "If false, disallows MCP servers from being used.", + "markdownDescription": "If false, disallows MCP servers from being used.\n\n- Category: `Admin`\n- Requires restart: `no`\n- Default: `true`", + "default": true, + "type": "boolean" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false } }, "$defs": { From 4b5c044272d236bba01311bcc2ecbd8d04a578c6 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Tue, 6 Jan 2026 17:48:08 -0500 Subject: [PATCH 012/713] Fix label-backlog-child-issues workflow logic --- .github/workflows/label-backlog-child-issues.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/label-backlog-child-issues.yml b/.github/workflows/label-backlog-child-issues.yml index d1c085218d..120b3e37e7 100644 --- a/.github/workflows/label-backlog-child-issues.yml +++ b/.github/workflows/label-backlog-child-issues.yml @@ -18,10 +18,10 @@ jobs: // Define the parent workstream issue numbers const parentWorkstreamNumbers = [15374, 15456, 15324]; // Define the label to add - const labelToAdd = "workstream-rollup"; + const labelToAdd = 'workstream-rollup'; - // Check if the issue has a body and a parent, and if that parent is in our list - if (issue && issue.body && issue.parent && parentWorkstreamNumbers.includes(issue.parent.number)) { + // Check if the issue has a parent and if that parent is in our list + if (issue.parent && parentWorkstreamNumbers.includes(issue.parent.number)) { console.log(`Issue #${issue.number} is a child of a target workstream. Adding label.`); await github.rest.issues.addLabels({ owner: context.repo.owner, @@ -30,5 +30,5 @@ jobs: labels: [labelToAdd] }); } else { - console.log(`Issue #${issue.number} is not a valid child of a target workstream or has no body. No action taken.`); + console.log(`Issue #${issue.number} is not a child of a target workstream. No action taken.`); } From d4b4aede2fc857ef93f6641d09e2a17261086446 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Tue, 6 Jan 2026 17:56:39 -0500 Subject: [PATCH 013/713] Add debugging logs for issue parent checks Added debugging logs to inspect issue object and parent information. --- .../workflows/label-backlog-child-issues.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/label-backlog-child-issues.yml b/.github/workflows/label-backlog-child-issues.yml index 120b3e37e7..f8ef939067 100644 --- a/.github/workflows/label-backlog-child-issues.yml +++ b/.github/workflows/label-backlog-child-issues.yml @@ -15,14 +15,22 @@ jobs: with: script: | const issue = context.payload.issue; - // Define the parent workstream issue numbers const parentWorkstreamNumbers = [15374, 15456, 15324]; - // Define the label to add const labelToAdd = 'workstream-rollup'; - // Check if the issue has a parent and if that parent is in our list + // --- START DEBUGGING --- + console.log('--- Full Issue Object from Payload ---'); + console.log(JSON.stringify(issue, null, 2)); + console.log('--- End of Full Issue Object ---'); + + console.log(`Value of issue.parent is: ${issue.parent}`); + if (issue.parent) { + console.log(`Value of issue.parent.number is: ${issue.parent.number}`); + } + // --- END DEBUGGING --- + if (issue.parent && parentWorkstreamNumbers.includes(issue.parent.number)) { - console.log(`Issue #${issue.number} is a child of a target workstream. Adding label.`); + console.log(`SUCCESS: Issue #${issue.number} is a child of a target workstream. Adding label.`); await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, @@ -30,5 +38,5 @@ jobs: labels: [labelToAdd] }); } else { - console.log(`Issue #${issue.number} is not a child of a target workstream. No action taken.`); + console.log(`FAILURE: Issue #${issue.number} is not a child of a target workstream. No action taken.`); } From 2122604b32689aad2fe4a90d132e7a4db688ee16 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Tue, 6 Jan 2026 18:00:39 -0500 Subject: [PATCH 014/713] Refactor parent issue check to use URLs --- .../workflows/label-backlog-child-issues.yml | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/.github/workflows/label-backlog-child-issues.yml b/.github/workflows/label-backlog-child-issues.yml index f8ef939067..04d550e9d8 100644 --- a/.github/workflows/label-backlog-child-issues.yml +++ b/.github/workflows/label-backlog-child-issues.yml @@ -15,28 +15,26 @@ jobs: with: script: | const issue = context.payload.issue; - const parentWorkstreamNumbers = [15374, 15456, 15324]; const labelToAdd = 'workstream-rollup'; - - // --- START DEBUGGING --- - console.log('--- Full Issue Object from Payload ---'); - console.log(JSON.stringify(issue, null, 2)); - console.log('--- End of Full Issue Object ---'); - console.log(`Value of issue.parent is: ${issue.parent}`); - if (issue.parent) { - console.log(`Value of issue.parent.number is: ${issue.parent.number}`); - } - // --- END DEBUGGING --- + // --- Define the FULL URLs of the allowed parent workstreams --- + const allowedParentUrls = [ + 'https://api.github.com/repos/google-gemini/gemini-cli/issues/15374', + 'https://api.github.com/repos/google-gemini/gemini-cli/issues/15456', + 'https://api.github.com/repos/google-gemini/gemini-cli/issues/15324' + ]; - if (issue.parent && parentWorkstreamNumbers.includes(issue.parent.number)) { - console.log(`SUCCESS: Issue #${issue.number} is a child of a target workstream. Adding label.`); + // Check if the issue has a parent_issue_url and if it's in our allowed list. + if (issue && issue.parent_issue_url && allowedParentUrls.includes(issue.parent_issue_url)) { + console.log(`SUCCESS: Issue #${issue.number} is a child of a target workstream (${issue.parent_issue_url}). Adding label.`); await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issue.number, labels: [labelToAdd] }); + } else if (issue && issue.parent_issue_url) { + console.log(`FAILURE: Issue #${issue.number} has a parent, but it's not a target workstream. Parent URL: ${issue.parent_issue_url}`); } else { - console.log(`FAILURE: Issue #${issue.number} is not a child of a target workstream. No action taken.`); + console.log(`FAILURE: Issue #${issue.number} is not a child of any issue. No action taken.`); } From 7feb2f8f42be2e39b877035a0b3e8be3440ac849 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Tue, 6 Jan 2026 18:17:12 -0500 Subject: [PATCH 015/713] Add 'reopened' type to issue labeling workflow --- .github/workflows/label-backlog-child-issues.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-backlog-child-issues.yml b/.github/workflows/label-backlog-child-issues.yml index 04d550e9d8..a61a73c5c9 100644 --- a/.github/workflows/label-backlog-child-issues.yml +++ b/.github/workflows/label-backlog-child-issues.yml @@ -2,7 +2,7 @@ name: 'Label Child Issues for Project Rollup' on: issues: - types: ['opened', 'edited'] + types: ['opened', 'edited', 'reopened'] jobs: labeler: From 1e31427da8b74007d7e25d9684888c61ec10a8a3 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Tue, 6 Jan 2026 15:41:58 -0800 Subject: [PATCH 016/713] Remove trailing whitespace in yaml. (#16036) --- .github/workflows/label-backlog-child-issues.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-backlog-child-issues.yml b/.github/workflows/label-backlog-child-issues.yml index a61a73c5c9..80774843e3 100644 --- a/.github/workflows/label-backlog-child-issues.yml +++ b/.github/workflows/label-backlog-child-issues.yml @@ -16,7 +16,7 @@ jobs: script: | const issue = context.payload.issue; const labelToAdd = 'workstream-rollup'; - + // --- Define the FULL URLs of the allowed parent workstreams --- const allowedParentUrls = [ 'https://api.github.com/repos/google-gemini/gemini-cli/issues/15374', From 96b9be3ec43937dae2f31bdfbd88a4ecfd48a0f4 Mon Sep 17 00:00:00 2001 From: Adam Weidman <65992621+adamfweidman@users.noreply.github.com> Date: Tue, 6 Jan 2026 18:45:05 -0500 Subject: [PATCH 017/713] feat(agents): add support for remote agents (#16013) --- .../src/agents/a2a-client-manager.test.ts | 39 +++ .../core/src/agents/a2a-client-manager.ts | 151 +++++++- packages/core/src/agents/a2aUtils.test.ts | 171 ++++++++++ packages/core/src/agents/a2aUtils.ts | 142 ++++++++ .../src/agents/delegate-to-agent-tool.test.ts | 43 +++ .../core/src/agents/remote-invocation.test.ts | 321 ++++++++++++++++-- packages/core/src/agents/remote-invocation.ts | 149 +++++++- packages/core/src/agents/types.ts | 5 + 8 files changed, 980 insertions(+), 41 deletions(-) create mode 100644 packages/core/src/agents/a2aUtils.test.ts create mode 100644 packages/core/src/agents/a2aUtils.ts diff --git a/packages/core/src/agents/a2a-client-manager.test.ts b/packages/core/src/agents/a2a-client-manager.test.ts index 1fe55a42ba..fb0f2829a4 100644 --- a/packages/core/src/agents/a2a-client-manager.test.ts +++ b/packages/core/src/agents/a2a-client-manager.test.ts @@ -8,6 +8,7 @@ import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest'; import { A2AClientManager, type SendMessageResult, + createAdapterFetch, } from './a2a-client-manager.js'; import type { AgentCard, Task } from '@a2a-js/sdk'; import type { AuthenticationHandler, Client } from '@a2a-js/sdk/client'; @@ -302,4 +303,42 @@ describe('A2AClientManager', () => { ).rejects.toThrow("Agent 'NonExistentAgent' not found."); }); }); + + describe('createAdapterFetch', () => { + it('normalizes TASK_STATE_ enums to lower-case', async () => { + const baseFetch = vi + .fn() + .mockResolvedValue( + new Response( + JSON.stringify({ status: { state: 'TASK_STATE_WORKING' } }), + ), + ); + + const adapter = createAdapterFetch(baseFetch as typeof fetch); + const response = await adapter('http://example.com', { + method: 'POST', + body: '{}', + }); + const data = await response.json(); + + expect(data.status.state).toBe('working'); + }); + + it('lowercases non-prefixed task states', async () => { + const baseFetch = vi + .fn() + .mockResolvedValue( + new Response(JSON.stringify({ status: { state: 'WORKING' } })), + ); + + const adapter = createAdapterFetch(baseFetch as typeof fetch); + const response = await adapter('http://example.com', { + method: 'POST', + body: '{}', + }); + const data = await response.json(); + + expect(data.status.state).toBe('working'); + }); + }); }); diff --git a/packages/core/src/agents/a2a-client-manager.ts b/packages/core/src/agents/a2a-client-manager.ts index 9eccca4ad4..ef93522e03 100644 --- a/packages/core/src/agents/a2a-client-manager.ts +++ b/packages/core/src/agents/a2a-client-manager.ts @@ -68,11 +68,15 @@ export class A2AClientManager { throw new Error(`Agent with name '${name}' is already loaded.`); } - let fetchImpl = fetch; + let fetchImpl: typeof fetch = fetch; if (authHandler) { fetchImpl = createAuthenticatingFetchWithRetry(fetch, authHandler); } + // Wrap with custom adapter for ADK Reasoning Engine compatibility + // TODO: Remove this when a2a-js fixes compatibility + fetchImpl = createAdapterFetch(fetchImpl); + const resolver = new DefaultAgentCardResolver({ fetchImpl }); const options = ClientFactoryOptions.createFrom( @@ -207,3 +211,148 @@ export class A2AClientManager { } } } + +/** + * Maps TaskState proto-JSON enums to lower-case strings. + */ +function mapTaskState(state: string | undefined): string | undefined { + if (!state) return state; + if (state.startsWith('TASK_STATE_')) { + return state.replace('TASK_STATE_', '').toLowerCase(); + } + return state.toLowerCase(); +} + +/** + * Creates a fetch implementation that adapts standard A2A SDK requests to the + * proto-JSON dialect and endpoint shapes required by Vertex AI Agent Engine. + */ +export function createAdapterFetch(baseFetch: typeof fetch): typeof fetch { + return async ( + input: RequestInfo | URL, + init?: RequestInit, + ): Promise => { + const urlStr = input as string; + + // 2. Dialect Mapping (Request) + let body = init?.body; + let isRpc = false; + let rpcId: string | number | undefined; + + if (typeof body === 'string') { + try { + let jsonBody = JSON.parse(body); + + // Unwrap JSON-RPC if present + if (jsonBody.jsonrpc === '2.0') { + isRpc = true; + rpcId = jsonBody.id; + jsonBody = jsonBody.params; + } + + // Apply dialect translation to the message object + const message = jsonBody.message || jsonBody; + if (message && typeof message === 'object') { + // Role: user -> ROLE_USER, agent/model -> ROLE_AGENT + if (message.role === 'user') message.role = 'ROLE_USER'; + if (message.role === 'agent' || message.role === 'model') { + message.role = 'ROLE_AGENT'; + } + + // Strip SDK-specific 'kind' field + delete message.kind; + + // Map 'parts' to 'content' (Proto-JSON dialect often uses 'content' or typed parts) + // Also strip 'kind' from parts. + if (Array.isArray(message.parts)) { + message.content = message.parts.map( + (p: { kind?: string; text?: string }) => { + const { kind: _k, ...rest } = p; + // If it's a simple text part, ensure it matches { text: "..." } + if (p.kind === 'text') return { text: p.text }; + return rest; + }, + ); + delete message.parts; + } + } + + body = JSON.stringify(jsonBody); + } catch (error) { + debugLogger.debug( + '[A2AClientManager] Failed to parse request body for dialect translation:', + error, + ); + // Non-JSON or parse error; let the baseFetch handle it. + } + } + + const response = await baseFetch(urlStr, { ...init, body }); + + // Map response back + if (response.ok) { + try { + const responseData = await response.clone().json(); + + const result = + responseData.task || responseData.message || responseData; + + // Restore 'kind' for the SDK and a2aUtils parsing + if (result && typeof result === 'object' && !result.kind) { + if (responseData.task || (result.id && result.status)) { + result.kind = 'task'; + } else if (responseData.message || result.messageId) { + result.kind = 'message'; + } + } + + // Restore 'kind' on parts so extractMessageText works + if (result?.parts && Array.isArray(result.parts)) { + for (const part of result.parts) { + if (!part.kind) { + if (part.file) part.kind = 'file'; + else if (part.data) part.kind = 'data'; + else if (part.text) part.kind = 'text'; + } + } + } + + // Recursively restore 'kind' on artifact parts + if (result?.artifacts && Array.isArray(result.artifacts)) { + for (const artifact of result.artifacts) { + if (artifact.parts && Array.isArray(artifact.parts)) { + for (const part of artifact.parts) { + if (!part.kind) { + if (part.file) part.kind = 'file'; + else if (part.data) part.kind = 'data'; + else if (part.text) part.kind = 'text'; + } + } + } + } + } + + // Map Task States back to SDK expectations + if (result && typeof result === 'object' && result.status) { + result.status.state = mapTaskState(result.status.state); + } + + if (isRpc) { + return new Response( + JSON.stringify({ + jsonrpc: '2.0', + id: rpcId, + result, + }), + response, + ); + } + return new Response(JSON.stringify(result), response); + } catch (_e) { + // Non-JSON response or unwrapping failure + } + } + + return response; + }; +} diff --git a/packages/core/src/agents/a2aUtils.test.ts b/packages/core/src/agents/a2aUtils.test.ts new file mode 100644 index 0000000000..0527b54bdd --- /dev/null +++ b/packages/core/src/agents/a2aUtils.test.ts @@ -0,0 +1,171 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect } from 'vitest'; +import { + extractMessageText, + extractTaskText, + extractIdsFromResponse, +} from './a2aUtils.js'; +import type { Message, Task, TextPart, DataPart, FilePart } from '@a2a-js/sdk'; + +describe('a2aUtils', () => { + describe('extractIdsFromResponse', () => { + it('should extract IDs from a message response', () => { + const message: Message = { + kind: 'message', + role: 'agent', + messageId: 'm1', + contextId: 'ctx-1', + taskId: 'task-1', + parts: [], + }; + + const result = extractIdsFromResponse(message); + expect(result).toEqual({ contextId: 'ctx-1', taskId: 'task-1' }); + }); + + it('should extract IDs from an in-progress task response', () => { + const task: Task = { + id: 'task-2', + contextId: 'ctx-2', + kind: 'task', + status: { state: 'working' }, + }; + + const result = extractIdsFromResponse(task); + expect(result).toEqual({ contextId: 'ctx-2', taskId: 'task-2' }); + }); + }); + + describe('extractMessageText', () => { + it('should extract text from simple text parts', () => { + const message: Message = { + kind: 'message', + role: 'user', + messageId: '1', + parts: [ + { kind: 'text', text: 'Hello' } as TextPart, + { kind: 'text', text: 'World' } as TextPart, + ], + }; + expect(extractMessageText(message)).toBe('Hello\nWorld'); + }); + + it('should extract data from data parts', () => { + const message: Message = { + kind: 'message', + role: 'user', + messageId: '1', + parts: [{ kind: 'data', data: { foo: 'bar' } } as DataPart], + }; + expect(extractMessageText(message)).toBe('Data: {"foo":"bar"}'); + }); + + it('should extract file info from file parts', () => { + const message: Message = { + kind: 'message', + role: 'user', + messageId: '1', + parts: [ + { + kind: 'file', + file: { + name: 'test.txt', + uri: 'file://test.txt', + mimeType: 'text/plain', + }, + } as FilePart, + { + kind: 'file', + file: { + uri: 'http://example.com/doc', + mimeType: 'application/pdf', + }, + } as FilePart, + ], + }; + // The formatting logic in a2aUtils prefers name over uri + expect(extractMessageText(message)).toContain('File: test.txt'); + expect(extractMessageText(message)).toContain( + 'File: http://example.com/doc', + ); + }); + + it('should handle mixed parts', () => { + const message: Message = { + kind: 'message', + role: 'user', + messageId: '1', + parts: [ + { kind: 'text', text: 'Here is data:' } as TextPart, + { kind: 'data', data: { value: 123 } } as DataPart, + ], + }; + expect(extractMessageText(message)).toBe( + 'Here is data:\nData: {"value":123}', + ); + }); + + it('should return empty string for undefined or empty message', () => { + expect(extractMessageText(undefined)).toBe(''); + expect( + extractMessageText({ + kind: 'message', + role: 'user', + messageId: '1', + parts: [], + } as Message), + ).toBe(''); + }); + }); + + describe('extractTaskText', () => { + it('should extract basic task info', () => { + const task: Task = { + id: 'task-1', + contextId: 'ctx-1', + kind: 'task', + status: { + state: 'working', + message: { + kind: 'message', + role: 'agent', + messageId: 'm1', + parts: [{ kind: 'text', text: 'Processing...' } as TextPart], + }, + }, + }; + + const result = extractTaskText(task); + expect(result).toContain('ID: task-1'); + expect(result).toContain('State: working'); + expect(result).toContain('Status Message: Processing...'); + }); + + it('should extract artifacts', () => { + const task: Task = { + id: 'task-1', + contextId: 'ctx-1', + kind: 'task', + status: { state: 'completed' }, + artifacts: [ + { + artifactId: 'art-1', + name: 'Report', + parts: [{ kind: 'text', text: 'This is the report.' } as TextPart], + }, + ], + }; + + const result = extractTaskText(task); + expect(result).toContain('Artifacts:'); + expect(result).toContain(' - Name: Report'); + expect(result).toContain(' Content:'); + expect(result).toContain(' This is the report.'); + }); + }); +}); diff --git a/packages/core/src/agents/a2aUtils.ts b/packages/core/src/agents/a2aUtils.ts new file mode 100644 index 0000000000..fc19eceb05 --- /dev/null +++ b/packages/core/src/agents/a2aUtils.ts @@ -0,0 +1,142 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type { + Message, + Task, + Part, + TextPart, + DataPart, + FilePart, +} from '@a2a-js/sdk'; + +/** + * Extracts a human-readable text representation from a Message object. + * Handles Text, Data (JSON), and File parts. + */ +export function extractMessageText(message: Message | undefined): string { + if (!message || !message.parts) { + return ''; + } + + const parts = message.parts + .map((part) => extractPartText(part)) + .filter(Boolean); + return parts.join('\n'); +} + +/** + * Extracts text from a single Part. + */ +export function extractPartText(part: Part): string { + if (isTextPart(part)) { + return part.text; + } + + if (isDataPart(part)) { + // Attempt to format known data types if metadata exists, otherwise JSON stringify + return `Data: ${JSON.stringify(part.data)}`; + } + + if (isFilePart(part)) { + const fileData = part.file; + if (fileData.name) { + return `File: ${fileData.name}`; + } + if ('uri' in fileData && fileData.uri) { + return `File: ${fileData.uri}`; + } + return `File: [binary/unnamed]`; + } + + return ''; +} + +/** + * Extracts a human-readable text summary from a Task object. + * Includes status, ID, and any artifact content. + */ +export function extractTaskText(task: Task): string { + let output = `ID: ${task.id}\n`; + output += `State: ${task.status.state}\n`; + + // Status Message + const statusMessageText = extractMessageText(task.status.message); + if (statusMessageText) { + output += `Status Message: ${statusMessageText}\n`; + } + + // Artifacts + if (task.artifacts && task.artifacts.length > 0) { + output += `Artifacts:\n`; + for (const artifact of task.artifacts) { + output += ` - Name: ${artifact.name}\n`; + if (artifact.parts && artifact.parts.length > 0) { + // Treat artifact parts as a message for extraction + const artifactContent = artifact.parts + .map((p) => extractPartText(p)) + .filter(Boolean) + .join('\n'); + + if (artifactContent) { + // Indent content for readability + const indentedContent = artifactContent.replace(/^/gm, ' '); + output += ` Content:\n${indentedContent}\n`; + } + } + } + } + + return output; +} + +// Type Guards + +function isTextPart(part: Part): part is TextPart { + return part.kind === 'text'; +} + +function isDataPart(part: Part): part is DataPart { + return part.kind === 'data'; +} + +function isFilePart(part: Part): part is FilePart { + return part.kind === 'file'; +} + +/** + * Extracts contextId and taskId from a Message or Task response. + * Follows the pattern from the A2A CLI sample to maintain conversational continuity. + */ +export function extractIdsFromResponse(result: Message | Task): { + contextId?: string; + taskId?: string; +} { + let contextId: string | undefined; + let taskId: string | undefined; + + if (result.kind === 'message') { + taskId = result.taskId; + contextId = result.contextId; + } else if (result.kind === 'task') { + taskId = result.id; + contextId = result.contextId; + + // If the task is in a final state (and not input-required), we clear the taskId + // so that the next interaction starts a fresh task (or keeps context without being bound to the old task). + if ( + result.status && + result.status.state !== 'input-required' && + (result.status.state === 'completed' || + result.status.state === 'failed' || + result.status.state === 'canceled') + ) { + taskId = undefined; + } + } + + return { contextId, taskId }; +} diff --git a/packages/core/src/agents/delegate-to-agent-tool.test.ts b/packages/core/src/agents/delegate-to-agent-tool.test.ts index 5c8601f217..3722ae2e88 100644 --- a/packages/core/src/agents/delegate-to-agent-tool.test.ts +++ b/packages/core/src/agents/delegate-to-agent-tool.test.ts @@ -13,6 +13,7 @@ import { LocalSubagentInvocation } from './local-invocation.js'; import type { MessageBus } from '../confirmation-bus/message-bus.js'; import { MessageBusType } from '../confirmation-bus/types.js'; import { DELEGATE_TO_AGENT_TOOL_NAME } from '../tools/tool-names.js'; +import { RemoteAgentInvocation } from './remote-invocation.js'; import { createMockMessageBus } from '../test-utils/mock-message-bus.js'; vi.mock('./local-invocation.js', () => ({ @@ -23,6 +24,15 @@ vi.mock('./local-invocation.js', () => ({ })), })); +vi.mock('./remote-invocation.js', () => ({ + RemoteAgentInvocation: vi.fn().mockImplementation(() => ({ + execute: vi.fn().mockResolvedValue({ + content: [{ type: 'text', text: 'Remote Success' }], + }), + shouldConfirmExecute: vi.fn().mockResolvedValue(true), + })), +})); + describe('DelegateToAgentTool', () => { let registry: AgentRegistry; let config: Config; @@ -45,6 +55,18 @@ describe('DelegateToAgentTool', () => { toolConfig: { tools: [] }, }; + const mockRemoteAgentDef: AgentDefinition = { + kind: 'remote', + name: 'remote_agent', + description: 'A remote agent', + agentCardUrl: 'https://example.com/agent.json', + inputConfig: { + inputs: { + query: { type: 'string', description: 'Query', required: true }, + }, + }, + }; + beforeEach(() => { config = { getDebugMode: () => false, @@ -58,6 +80,8 @@ describe('DelegateToAgentTool', () => { // Manually register the mock agent (bypassing protected method for testing) // eslint-disable-next-line @typescript-eslint/no-explicit-any (registry as any).agents.set(mockAgentDef.name, mockAgentDef); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (registry as any).agents.set(mockRemoteAgentDef.name, mockRemoteAgentDef); messageBus = createMockMessageBus(); @@ -176,4 +200,23 @@ describe('DelegateToAgentTool', () => { }), ); }); + + it('should delegate to remote agent correctly', async () => { + const invocation = tool.build({ + agent_name: 'remote_agent', + query: 'hello remote', + }); + + const result = await invocation.execute(new AbortController().signal); + expect(result).toEqual({ + content: [{ type: 'text', text: 'Remote Success' }], + }); + expect(RemoteAgentInvocation).toHaveBeenCalledWith( + mockRemoteAgentDef, + { query: 'hello remote' }, + messageBus, + 'remote_agent', + 'remote_agent', + ); + }); }); diff --git a/packages/core/src/agents/remote-invocation.test.ts b/packages/core/src/agents/remote-invocation.test.ts index 610961e440..f3c998e41b 100644 --- a/packages/core/src/agents/remote-invocation.test.ts +++ b/packages/core/src/agents/remote-invocation.test.ts @@ -4,55 +4,310 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { describe, it, expect } from 'vitest'; -import type { ToolCallConfirmationDetails } from '../tools/tools.js'; +import { + describe, + it, + expect, + vi, + beforeEach, + afterEach, + type Mock, +} from 'vitest'; import { RemoteAgentInvocation } from './remote-invocation.js'; +import { A2AClientManager } from './a2a-client-manager.js'; import type { RemoteAgentDefinition } from './types.js'; import { createMockMessageBus } from '../test-utils/mock-message-bus.js'; -class TestableRemoteAgentInvocation extends RemoteAgentInvocation { - override async getConfirmationDetails( - abortSignal: AbortSignal, - ): Promise { - return super.getConfirmationDetails(abortSignal); - } -} +// Mock A2AClientManager +vi.mock('./a2a-client-manager.js', () => { + const A2AClientManager = { + getInstance: vi.fn(), + }; + return { A2AClientManager }; +}); describe('RemoteAgentInvocation', () => { const mockDefinition: RemoteAgentDefinition = { + name: 'test-agent', kind: 'remote', - name: 'test-remote-agent', - description: 'A test remote agent', - displayName: 'Test Remote Agent', - agentCardUrl: 'https://example.com/agent-card', + agentCardUrl: 'http://test-agent/card', + displayName: 'Test Agent', + description: 'A test agent', inputConfig: { inputs: {}, }, }; + const mockClientManager = { + getClient: vi.fn(), + loadAgent: vi.fn(), + sendMessage: vi.fn(), + }; const mockMessageBus = createMockMessageBus(); - it('should be instantiated with correct params', () => { - const invocation = new RemoteAgentInvocation( - mockDefinition, - {}, - mockMessageBus, - ); - expect(invocation).toBeDefined(); - expect(invocation.getDescription()).toBe( - 'Calling remote agent Test Remote Agent', - ); + beforeEach(() => { + vi.clearAllMocks(); + (A2AClientManager.getInstance as Mock).mockReturnValue(mockClientManager); + ( + RemoteAgentInvocation as unknown as { + sessionState?: Map; + } + ).sessionState?.clear(); }); - it('should return false for confirmation details (not yet implemented)', async () => { - const invocation = new TestableRemoteAgentInvocation( - mockDefinition, - {}, - mockMessageBus, - ); - const details = await invocation.getConfirmationDetails( - new AbortController().signal, - ); - expect(details).toBe(false); + afterEach(() => { + vi.restoreAllMocks(); + }); + + describe('Constructor Validation', () => { + it('accepts valid input with string query', () => { + expect(() => { + new RemoteAgentInvocation( + mockDefinition, + { query: 'valid' }, + mockMessageBus, + ); + }).not.toThrow(); + }); + + it('throws if query is missing', () => { + expect(() => { + new RemoteAgentInvocation(mockDefinition, {}, mockMessageBus); + }).toThrow("requires a string 'query' input"); + }); + + it('throws if query is not a string', () => { + expect(() => { + new RemoteAgentInvocation( + mockDefinition, + { query: 123 }, + mockMessageBus, + ); + }).toThrow("requires a string 'query' input"); + }); + }); + + describe('Execution Logic', () => { + it('should lazy load the agent with ADCHandler if not present', async () => { + mockClientManager.getClient.mockReturnValue(undefined); + mockClientManager.sendMessage.mockResolvedValue({ + kind: 'message', + messageId: 'msg-1', + role: 'agent', + parts: [{ kind: 'text', text: 'Hello' }], + }); + + const invocation = new RemoteAgentInvocation( + mockDefinition, + { + query: 'hi', + }, + mockMessageBus, + ); + await invocation.execute(new AbortController().signal); + + expect(mockClientManager.loadAgent).toHaveBeenCalledWith( + 'test-agent', + 'http://test-agent/card', + expect.objectContaining({ + headers: expect.any(Function), + shouldRetryWithHeaders: expect.any(Function), + }), + ); + }); + + it('should not load the agent if already present', async () => { + mockClientManager.getClient.mockReturnValue({}); + mockClientManager.sendMessage.mockResolvedValue({ + kind: 'message', + messageId: 'msg-1', + role: 'agent', + parts: [{ kind: 'text', text: 'Hello' }], + }); + + const invocation = new RemoteAgentInvocation( + mockDefinition, + { + query: 'hi', + }, + mockMessageBus, + ); + await invocation.execute(new AbortController().signal); + + expect(mockClientManager.loadAgent).not.toHaveBeenCalled(); + }); + + it('should persist contextId and taskId across invocations', async () => { + mockClientManager.getClient.mockReturnValue({}); + + // First call return values + mockClientManager.sendMessage.mockResolvedValueOnce({ + kind: 'message', + messageId: 'msg-1', + role: 'agent', + parts: [{ kind: 'text', text: 'Response 1' }], + contextId: 'ctx-1', + taskId: 'task-1', + }); + + const invocation1 = new RemoteAgentInvocation( + mockDefinition, + { + query: 'first', + }, + mockMessageBus, + ); + + // Execute first time + const result1 = await invocation1.execute(new AbortController().signal); + expect(result1.returnDisplay).toBe('Response 1'); + expect(mockClientManager.sendMessage).toHaveBeenLastCalledWith( + 'test-agent', + 'first', + { contextId: undefined, taskId: undefined }, + ); + + // Prepare for second call with simulated state persistence + mockClientManager.sendMessage.mockResolvedValueOnce({ + kind: 'message', + messageId: 'msg-2', + role: 'agent', + parts: [{ kind: 'text', text: 'Response 2' }], + contextId: 'ctx-1', + taskId: 'task-2', + }); + + const invocation2 = new RemoteAgentInvocation( + mockDefinition, + { + query: 'second', + }, + mockMessageBus, + ); + const result2 = await invocation2.execute(new AbortController().signal); + expect(result2.returnDisplay).toBe('Response 2'); + + expect(mockClientManager.sendMessage).toHaveBeenLastCalledWith( + 'test-agent', + 'second', + { contextId: 'ctx-1', taskId: 'task-1' }, // Used state from first call + ); + + // Third call: Task completes + mockClientManager.sendMessage.mockResolvedValueOnce({ + kind: 'task', + id: 'task-2', + contextId: 'ctx-1', + status: { state: 'completed', message: undefined }, + artifacts: [], + history: [], + }); + + const invocation3 = new RemoteAgentInvocation( + mockDefinition, + { + query: 'third', + }, + mockMessageBus, + ); + await invocation3.execute(new AbortController().signal); + + // Fourth call: Should start new task (taskId undefined) + mockClientManager.sendMessage.mockResolvedValueOnce({ + kind: 'message', + messageId: 'msg-3', + role: 'agent', + parts: [{ kind: 'text', text: 'New Task' }], + }); + + const invocation4 = new RemoteAgentInvocation( + mockDefinition, + { + query: 'fourth', + }, + mockMessageBus, + ); + await invocation4.execute(new AbortController().signal); + + expect(mockClientManager.sendMessage).toHaveBeenLastCalledWith( + 'test-agent', + 'fourth', + { contextId: 'ctx-1', taskId: undefined }, // taskId cleared! + ); + }); + + it('should handle errors gracefully', async () => { + mockClientManager.getClient.mockReturnValue({}); + mockClientManager.sendMessage.mockRejectedValue( + new Error('Network error'), + ); + + const invocation = new RemoteAgentInvocation( + mockDefinition, + { + query: 'hi', + }, + mockMessageBus, + ); + const result = await invocation.execute(new AbortController().signal); + + expect(result.error).toBeDefined(); + expect(result.error?.message).toContain('Network error'); + expect(result.returnDisplay).toContain('Network error'); + }); + + it('should use a2a helpers for extracting text', async () => { + mockClientManager.getClient.mockReturnValue({}); + // Mock a complex message part that needs extraction + mockClientManager.sendMessage.mockResolvedValue({ + kind: 'message', + messageId: 'msg-1', + role: 'agent', + parts: [ + { kind: 'text', text: 'Extracted text' }, + { kind: 'data', data: { foo: 'bar' } }, + ], + }); + + const invocation = new RemoteAgentInvocation( + mockDefinition, + { + query: 'hi', + }, + mockMessageBus, + ); + const result = await invocation.execute(new AbortController().signal); + + // Just check that text is present, exact formatting depends on helper + expect(result.returnDisplay).toContain('Extracted text'); + }); + }); + + describe('Confirmations', () => { + it('should return info confirmation details', async () => { + const invocation = new RemoteAgentInvocation( + mockDefinition, + { + query: 'hi', + }, + mockMessageBus, + ); + // @ts-expect-error - getConfirmationDetails is protected + const confirmation = await invocation.getConfirmationDetails( + new AbortController().signal, + ); + + expect(confirmation).not.toBe(false); + if ( + confirmation && + typeof confirmation === 'object' && + confirmation.type === 'info' + ) { + expect(confirmation.title).toContain('Test Agent'); + expect(confirmation.prompt).toContain('http://test-agent/card'); + } else { + throw new Error('Expected confirmation to be of type info'); + } + }); }); }); diff --git a/packages/core/src/agents/remote-invocation.ts b/packages/core/src/agents/remote-invocation.ts index 28ee8de6bb..4bc23f7fb1 100644 --- a/packages/core/src/agents/remote-invocation.ts +++ b/packages/core/src/agents/remote-invocation.ts @@ -9,8 +9,54 @@ import { type ToolResult, type ToolCallConfirmationDetails, } from '../tools/tools.js'; -import type { AgentInputs, RemoteAgentDefinition } from './types.js'; +import type { + RemoteAgentInputs, + RemoteAgentDefinition, + AgentInputs, +} from './types.js'; import type { MessageBus } from '../confirmation-bus/message-bus.js'; +import { A2AClientManager } from './a2a-client-manager.js'; +import { + extractMessageText, + extractTaskText, + extractIdsFromResponse, +} from './a2aUtils.js'; +import { GoogleAuth } from 'google-auth-library'; +import type { AuthenticationHandler } from '@a2a-js/sdk/client'; +import { debugLogger } from '../utils/debugLogger.js'; + +/** + * Authentication handler implementation using Google Application Default Credentials (ADC). + */ +export class ADCHandler implements AuthenticationHandler { + private auth = new GoogleAuth({ + scopes: ['https://www.googleapis.com/auth/cloud-platform'], + }); + + async headers(): Promise> { + try { + const client = await this.auth.getClient(); + const token = await client.getAccessToken(); + if (token.token) { + return { Authorization: `Bearer ${token.token}` }; + } + throw new Error('Failed to retrieve ADC access token.'); + } catch (e) { + const errorMessage = `Failed to get ADC token: ${ + e instanceof Error ? e.message : String(e) + }`; + debugLogger.log('ERROR', errorMessage); + throw new Error(errorMessage); + } + } + + async shouldRetryWithHeaders( + _response: unknown, + ): Promise | undefined> { + // For ADC, we usually just re-fetch the token if needed. + return this.headers(); + } +} /** * A tool invocation that proxies to a remote A2A agent. @@ -19,9 +65,22 @@ import type { MessageBus } from '../confirmation-bus/message-bus.js'; * invokes the configured A2A tool. */ export class RemoteAgentInvocation extends BaseToolInvocation< - AgentInputs, + RemoteAgentInputs, ToolResult > { + // Persist state across ephemeral invocation instances. + private static readonly sessionState = new Map< + string, + { contextId?: string; taskId?: string } + >(); + // State for the ongoing conversation with the remote agent + private contextId: string | undefined; + private taskId: string | undefined; + // TODO: See if we can reuse the singleton from AppContainer or similar, but for now use getInstance directly + // as per the current pattern in the codebase. + private readonly clientManager = A2AClientManager.getInstance(); + private readonly authHandler = new ADCHandler(); + constructor( private readonly definition: RemoteAgentDefinition, params: AgentInputs, @@ -29,8 +88,15 @@ export class RemoteAgentInvocation extends BaseToolInvocation< _toolName?: string, _toolDisplayName?: string, ) { + const query = params['query']; + if (typeof query !== 'string') { + throw new Error( + `Remote agent '${definition.name}' requires a string 'query' input.`, + ); + } + // Safe to pass strict object to super super( - params, + { query }, messageBus, _toolName ?? definition.name, _toolDisplayName ?? definition.displayName, @@ -44,12 +110,81 @@ export class RemoteAgentInvocation extends BaseToolInvocation< protected override async getConfirmationDetails( _abortSignal: AbortSignal, ): Promise { - // TODO: Implement confirmation logic for remote agents. - return false; + // For now, always require confirmation for remote agents until we have a policy system for them. + return { + type: 'info', + title: `Call Remote Agent: ${this.definition.displayName ?? this.definition.name}`, + prompt: `This will send a message to the external agent at ${this.definition.agentCardUrl}.`, + onConfirm: async () => {}, // No-op for now, just informational + }; } async execute(_signal: AbortSignal): Promise { - // TODO: Implement remote agent invocation logic. - throw new Error(`Remote agent invocation not implemented.`); + // 1. Ensure the agent is loaded (cached by manager) + // We assume the user has provided an access token via some mechanism (TODO), + // or we rely on ADC. + try { + const priorState = RemoteAgentInvocation.sessionState.get( + this.definition.name, + ); + if (priorState) { + this.contextId = priorState.contextId; + this.taskId = priorState.taskId; + } + + if (!this.clientManager.getClient(this.definition.name)) { + await this.clientManager.loadAgent( + this.definition.name, + this.definition.agentCardUrl, + this.authHandler, + ); + } + + const message = this.params.query; + + const response = await this.clientManager.sendMessage( + this.definition.name, + message, + { + contextId: this.contextId, + taskId: this.taskId, + }, + ); + + // Extracts IDs, taskID will be undefined if the task is completed/failed/canceled. + const { contextId, taskId } = extractIdsFromResponse(response); + + this.contextId = contextId ?? this.contextId; + this.taskId = taskId; + + RemoteAgentInvocation.sessionState.set(this.definition.name, { + contextId: this.contextId, + taskId: this.taskId, + }); + + // Extract the output text + const resultData = response; + let outputText = ''; + + if (resultData.kind === 'message') { + outputText = extractMessageText(resultData); + } else if (resultData.kind === 'task') { + outputText = extractTaskText(resultData); + } else { + outputText = JSON.stringify(resultData); + } + + return { + llmContent: [{ text: outputText }], + returnDisplay: outputText, + }; + } catch (error: unknown) { + const errorMessage = `Error calling remote agent: ${error instanceof Error ? error.message : String(error)}`; + return { + llmContent: [{ text: errorMessage }], + returnDisplay: errorMessage, + error: { message: errorMessage }, + }; + } } } diff --git a/packages/core/src/agents/types.ts b/packages/core/src/agents/types.ts index c42a3103ac..f0d2743662 100644 --- a/packages/core/src/agents/types.ts +++ b/packages/core/src/agents/types.ts @@ -38,6 +38,11 @@ export interface OutputObject { */ export type AgentInputs = Record; +/** + * Simplified input structure for Remote Agents, which consumes a single string query. + */ +export type RemoteAgentInputs = { query: string }; + /** * Structured events emitted during subagent execution for user observability. */ From 7eeb7bd74c89ac8f1b09f453fd6e69afa6a70b67 Mon Sep 17 00:00:00 2001 From: Jerop Kipruto Date: Tue, 6 Jan 2026 19:03:23 -0500 Subject: [PATCH 018/713] fix: limit scheduled issue triage queries to prevent argument list too long error (#16021) --- .github/workflows/gemini-scheduled-issue-triage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gemini-scheduled-issue-triage.yml b/.github/workflows/gemini-scheduled-issue-triage.yml index 3b54546f98..8887a47413 100644 --- a/.github/workflows/gemini-scheduled-issue-triage.yml +++ b/.github/workflows/gemini-scheduled-issue-triage.yml @@ -45,11 +45,11 @@ jobs: echo '🔍 Finding issues without labels...' NO_LABEL_ISSUES="$(gh issue list --repo "${GITHUB_REPOSITORY}" \ - --search 'is:open is:issue no:label' --json number,title,body)" + --search 'is:open is:issue no:label' --limit 10 --json number,title,body)" echo '🏷️ Finding issues that need triage...' NEED_TRIAGE_ISSUES="$(gh issue list --repo "${GITHUB_REPOSITORY}" \ - --search "is:open is:issue label:\"status/need-triage\"" --limit 1000 --json number,title,body)" + --search "is:open is:issue label:\"status/need-triage\"" --limit 10 --json number,title,body)" echo '🔄 Merging and deduplicating issues...' ISSUES="$(echo "${NO_LABEL_ISSUES}" "${NEED_TRIAGE_ISSUES}" | jq -c -s 'add | unique_by(.number)')" From 8f5bf33eacc0223e081ed6a250d0af2c44bee391 Mon Sep 17 00:00:00 2001 From: Jerop Kipruto Date: Tue, 6 Jan 2026 19:15:00 -0500 Subject: [PATCH 019/713] ci(github-actions): triage all new issues automatically (#16018) --- .github/workflows/gemini-automated-issue-triage.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/gemini-automated-issue-triage.yml b/.github/workflows/gemini-automated-issue-triage.yml index f4191ef7a7..864174ca1c 100644 --- a/.github/workflows/gemini-automated-issue-triage.yml +++ b/.github/workflows/gemini-automated-issue-triage.yml @@ -39,7 +39,6 @@ jobs: github.event_name == 'workflow_dispatch' || ( (github.event_name == 'issues' || github.event_name == 'issue_comment') && - contains(github.event.issue.labels.*.name, 'status/need-triage') && (github.event_name != 'issue_comment' || ( contains(github.event.comment.body, '@gemini-cli /triage') && (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR') @@ -75,11 +74,6 @@ jobs: ISSUE_NUMBER_INPUT: '${{ github.event.inputs.issue_number }}' LABELS: '${{ steps.get_issue_data.outputs.labels }}' run: | - if ! echo "${LABELS}" | grep -q 'status/need-triage'; then - echo "Issue #${ISSUE_NUMBER_INPUT} does not have the 'status/need-triage' label. Stopping workflow." - exit 1 - fi - if echo "${LABELS}" | grep -q 'area/'; then echo "Issue #${ISSUE_NUMBER_INPUT} already has 'area/' label. Stopping workflow." exit 1 From 4086abf375050b04c010ddebbbeb80f71eca6db2 Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Tue, 6 Jan 2026 16:25:16 -0800 Subject: [PATCH 020/713] Fix test. (#16011) --- packages/core/src/code_assist/oauth2.test.ts | 66 +++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/packages/core/src/code_assist/oauth2.test.ts b/packages/core/src/code_assist/oauth2.test.ts index 63e63c897c..50a7f07a67 100644 --- a/packages/core/src/code_assist/oauth2.test.ts +++ b/packages/core/src/code_assist/oauth2.test.ts @@ -30,6 +30,7 @@ import { GEMINI_DIR } from '../utils/paths.js'; import { debugLogger } from '../utils/debugLogger.js'; import { writeToStdout } from '../utils/stdio.js'; import { FatalCancellationError } from '../utils/errors.js'; +import process from 'node:process'; vi.mock('os', async (importOriginal) => { const os = await importOriginal(); @@ -1128,8 +1129,16 @@ describe('oauth2', () => { () => mockHttpServer as unknown as http.Server, ); - // Spy on process.on to capture the SIGINT handler - const processOnSpy = vi.spyOn(process, 'on'); + // Mock process.on to immediately trigger SIGINT + const processOnSpy = vi + .spyOn(process, 'on') + .mockImplementation((event, listener: () => void) => { + if (event === 'SIGINT') { + listener(); + } + return process; + }); + const processRemoveListenerSpy = vi.spyOn(process, 'removeListener'); const clientPromise = getOauthClient( @@ -1137,21 +1146,6 @@ describe('oauth2', () => { mockConfig, ); - // Wait a tick to ensure the SIGINT handler is registered - await new Promise((resolve) => setTimeout(resolve, 0)); - - const sigintCall = processOnSpy.mock.calls.find( - (call) => call[0] === 'SIGINT', - ); - const sigIntHandler = sigintCall?.[1] as (() => void) | undefined; - - expect(sigIntHandler).toBeDefined(); - - // Trigger SIGINT - if (sigIntHandler) { - sigIntHandler(); - } - await expect(clientPromise).rejects.toThrow(FatalCancellationError); expect(processRemoveListenerSpy).toHaveBeenCalledWith( 'SIGINT', @@ -1186,8 +1180,18 @@ describe('oauth2', () => { () => mockHttpServer as unknown as http.Server, ); - // Spy on process.stdin.on - const stdinOnSpy = vi.spyOn(process.stdin, 'on'); + // Spy on process.stdin.on and immediately trigger Ctrl+C + const stdinOnSpy = vi + .spyOn(process.stdin, 'on') + .mockImplementation( + (event: string, listener: (data: Buffer) => void) => { + if (event === 'data') { + listener(Buffer.from([0x03])); + } + return process.stdin; + }, + ); + const stdinRemoveListenerSpy = vi.spyOn( process.stdin, 'removeListener', @@ -1198,22 +1202,6 @@ describe('oauth2', () => { mockConfig, ); - await new Promise((resolve) => setTimeout(resolve, 0)); - - const dataCall = stdinOnSpy.mock.calls.find( - (call: [string, ...unknown[]]) => call[0] === 'data', - ); - const dataHandler = dataCall?.[1] as - | ((data: Buffer) => void) - | undefined; - - expect(dataHandler).toBeDefined(); - - // Trigger Ctrl+C - if (dataHandler) { - dataHandler(Buffer.from([0x03])); - } - await expect(clientPromise).rejects.toThrow(FatalCancellationError); expect(stdinRemoveListenerSpy).toHaveBeenCalledWith( 'data', @@ -1420,7 +1408,7 @@ describe('oauth2', () => { await clientPromise; expect( - OAuthCredentialStorage.saveCredentials as Mock, + vi.mocked(OAuthCredentialStorage.saveCredentials), ).toHaveBeenCalledWith(mockTokens); const credsPath = path.join(tempHomeDir, GEMINI_DIR, 'oauth_creds.json'); expect(fs.existsSync(credsPath)).toBe(false); @@ -1431,7 +1419,7 @@ describe('oauth2', () => { './oauth-credential-storage.js' ); const cachedCreds = { refresh_token: 'cached-encrypted-token' }; - (OAuthCredentialStorage.loadCredentials as Mock).mockResolvedValue( + vi.mocked(OAuthCredentialStorage.loadCredentials).mockResolvedValue( cachedCreds, ); @@ -1455,7 +1443,9 @@ describe('oauth2', () => { await getOauthClient(AuthType.LOGIN_WITH_GOOGLE, mockConfig); - expect(OAuthCredentialStorage.loadCredentials as Mock).toHaveBeenCalled(); + expect( + vi.mocked(OAuthCredentialStorage.loadCredentials), + ).toHaveBeenCalled(); expect(mockClient.setCredentials).toHaveBeenCalledWith(cachedCreds); expect(mockClient.setCredentials).not.toHaveBeenCalledWith( unencryptedCreds, From 5f027cb63a45f0695b45729c445acb0ecfdfe00a Mon Sep 17 00:00:00 2001 From: Krushna Korade Date: Wed, 7 Jan 2026 06:25:13 +0530 Subject: [PATCH 021/713] fix: hide broken skills object from settings dialog (#15766) --- packages/cli/src/config/settingsSchema.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index ee5a8e71c3..a51776316b 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -1381,7 +1381,7 @@ const SETTINGS_SCHEMA = { requiresRestart: true, default: false, description: 'Enable Agent Skills (experimental).', - showInDialog: false, + showInDialog: true, }, codebaseInvestigatorSettings: { type: 'object', @@ -1518,7 +1518,7 @@ const SETTINGS_SCHEMA = { requiresRestart: true, default: {}, description: 'Settings for agent skills.', - showInDialog: true, + showInDialog: false, properties: { disabled: { type: 'array', From 59a18e710daaaab7435c34f517e7dfa4406bce0c Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 6 Jan 2026 16:59:56 -0800 Subject: [PATCH 022/713] Agent Skills: Initial Documentation & Tutorial (#15869) --- docs/cli/settings.md | 1 + docs/cli/skills.md | 156 +++++++++++++++++++ docs/cli/tutorials.md | 4 + docs/cli/tutorials/skills-getting-started.md | 124 +++++++++++++++ docs/sidebar.json | 4 + 5 files changed, 289 insertions(+) create mode 100644 docs/cli/skills.md create mode 100644 docs/cli/tutorials/skills-getting-started.md diff --git a/docs/cli/settings.md b/docs/cli/settings.md index 96912995d4..f281ec8da0 100644 --- a/docs/cli/settings.md +++ b/docs/cli/settings.md @@ -111,3 +111,4 @@ they appear in the UI. | ----------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------ | ------- | | Enable Codebase Investigator | `experimental.codebaseInvestigatorSettings.enabled` | Enable the Codebase Investigator agent. | `true` | | Codebase Investigator Max Num Turns | `experimental.codebaseInvestigatorSettings.maxNumTurns` | Maximum number of turns for the Codebase Investigator agent. | `10` | +| Agent Skills | `experimental.skills` | Enable Agent Skills (experimental). | `false` | diff --git a/docs/cli/skills.md b/docs/cli/skills.md new file mode 100644 index 0000000000..0badd9adaa --- /dev/null +++ b/docs/cli/skills.md @@ -0,0 +1,156 @@ +# Agent Skills + +_Note: This is an experimental feature enabled via `experimental.skills`. You +can also search for "Skills" within the `/settings` interactive UI to toggle +this and manage other skill-related settings._ + +Agent Skills allow you to extend Gemini CLI with specialized expertise, +procedural workflows, and task-specific resources. Based on the +[Agent Skills](https://agentskills.io) open standard, a "skill" is a +self-contained directory that packages instructions and assets into a +discoverable capability. + +## Overview + +Unlike general context files ([`GEMINI.md`](./gemini-md.md)), which provide +persistent project-wide background, Skills represent **on-demand expertise**. +This allows Gemini to maintain a vast library of specialized capabilities—such +as security auditing, cloud deployments, or codebase migrations—without +cluttering the model's immediate context window. + +Gemini autonomously decides when to employ a skill based on your request and the +skill's description. When a relevant skill is identified, the model "pulls in" +the full instructions and resources required to complete the task using the +`activate_skill` tool. + +## Key Benefits + +- **Shared Expertise:** Package complex workflows (like a specific team's PR + review process) into a folder that anyone can use. +- **Repeatable Workflows:** Ensure complex multi-step tasks are performed + consistently by providing a procedural framework. +- **Resource Bundling:** Include scripts, templates, or example data alongside + instructions so the agent has everything it needs. +- **Progressive Disclosure:** Only skill metadata (name and description) is + loaded initially. Detailed instructions and resources are only disclosed when + the model explicitly activates the skill, saving context tokens. + +## Skill Discovery Tiers + +Gemini CLI discovers skills from three primary locations: + +1. **Project Skills** (`.gemini/skills/`): Project-specific skills that are + typically committed to version control and shared with the team. +2. **User Skills** (`~/.gemini/skills/`): Personal skills available across all + your projects. +3. **Extension Skills**: Skills bundled within installed + [extensions](../extensions/index.md). + +**Precedence:** If multiple skills share the same name, higher-precedence +locations override lower ones: **Project > User > Extension**. + +## Managing Skills + +### In an Interactive Session + +Use the `/skills` slash command to view and manage available expertise: + +- `/skills list` (default): Shows all discovered skills and their status. +- `/skills disable `: Prevents a specific skill from being used. +- `/skills enable `: Re-enables a disabled skill. +- `/skills reload`: Refreshes the list of discovered skills from all tiers. + +_Note: `/skills disable` and `/skills enable` default to the `user` scope. Use +`--scope project` to manage project-specific settings._ + +### From the Terminal + +The `gemini skills` command provides management utilities: + +```bash +# List all discovered skills +gemini skills list + +# Enable/disable skills. Can use --scope to specify project or user +gemini skills enable my-expertise +gemini skills disable my-expertise +``` + +## Creating a Skill + +A skill is a directory containing a `SKILL.md` file at its root. This file uses +YAML frontmatter for metadata and Markdown for instructions. + +### Basic Structure + +```markdown +--- +name: +description: +--- + + +``` + +- **`name`**: A unique identifier (lowercase, alphanumeric, and dashes). +- **`description`**: The most critical field. Gemini uses this to decide when + the skill is relevant. Be specific about the expertise provided. +- **Body**: Everything below the second `---` is injected as expert procedural + guidance for the model. + +### Example: Team Code Reviewer + +```markdown +--- +name: code-reviewer +description: + Expertise in reviewing code for style, security, and performance. Use when the + user asks for "feedback," a "review," or to "check" their changes. +--- + +# Code Reviewer + +You are an expert code reviewer. When reviewing code, follow this workflow: + +1. **Analyze**: Review the staged changes or specific files provided. Ensure + that the changes are scoped properly and represent minimal changes required + to address the issue. +2. **Style**: Ensure code follows the project's conventions and idiomatic + patterns as described in the `GEMINI.md` file. +3. **Security**: Flag any potential security vulnerabilities. +4. **Tests**: Verify that new logic has corresponding test coverage and that + the test coverage adequately validates the changes. + +Provide your feedback as a concise bulleted list of "Strengths" and +"Opportunities." +``` + +### Resource Conventions + +While you can structure your skill directory however you like, the Agent Skills +standard encourages these conventions: + +- **`scripts/`**: Executable scripts (bash, python, node) the agent can run. +- **`references/`**: Static documentation, schemas, or example data for the + agent to consult. +- **`assets/`**: Code templates, boilerplate, or binary resources. + +When a skill is activated, Gemini CLI provides the model with a tree view of the +entire skill directory, allowing it to discover and utilize these assets. + +## How it Works (Security & Privacy) + +1. **Discovery**: At the start of a session, Gemini CLI scans the discovery + tiers and injects the name and description of all enabled skills into the + system prompt. +2. **Activation**: When Gemini identifies a task matching a skill's + description, it calls the `activate_skill` tool. +3. **Consent**: You will see a confirmation prompt in the UI detailing the + skill's name, purpose, and the directory path it will gain access to. +4. **Injection**: Upon your approval: + - The `SKILL.md` body and folder structure is added to the conversation + history. + - The skill's directory is added to the agent's allowed file paths, granting + it permission to read any bundled assets. +5. **Execution**: The model proceeds with the specialized expertise active. It + is instructed to prioritize the skill's procedural guidance within reason. diff --git a/docs/cli/tutorials.md b/docs/cli/tutorials.md index dff8918b5e..fe41220679 100644 --- a/docs/cli/tutorials.md +++ b/docs/cli/tutorials.md @@ -2,6 +2,10 @@ This page contains tutorials for interacting with Gemini CLI. +## Agent Skills + +- [Getting Started with Agent Skills](./tutorials/skills-getting-started.md) + ## Setting up a Model Context Protocol (MCP) server > [!CAUTION] Before using a third-party MCP server, ensure you trust its source diff --git a/docs/cli/tutorials/skills-getting-started.md b/docs/cli/tutorials/skills-getting-started.md new file mode 100644 index 0000000000..f559f6b1e5 --- /dev/null +++ b/docs/cli/tutorials/skills-getting-started.md @@ -0,0 +1,124 @@ +# Getting Started with Agent Skills + +Agent Skills allow you to extend Gemini CLI with specialized expertise. This +tutorial will guide you through creating your first skill, enabling it, and +using it in a session. + +## 1. Enable Agent Skills + +Agent Skills are currently an experimental feature and must be enabled in your +settings. + +### Via the interactive UI + +1. Start a Gemini CLI session by running `gemini`. +2. Type `/settings` to open the interactive settings dialog. +3. Search for "Skills". +4. Toggle **Agent Skills** to `true`. +5. Press `Esc` to save and exit. You may need to restart the CLI for the + changes to take effect. + +### Via `settings.json` + +Alternatively, you can manually edit your global settings file at +`~/.gemini/settings.json` (create it if it doesn't exist): + +```json +{ + "experimental": { + "skills": true + } +} +``` + +## 2. Create Your First Skill + +A skill is a directory containing a `SKILL.md` file. Let's create an **API +Auditor** skill that helps you verify if local or remote endpoints are +responding correctly. + +1. **Create the skill directory structure:** + + ```bash + mkdir -p .gemini/skills/api-auditor/scripts + ``` + +2. **Create the `SKILL.md` file:** Create a file at + `.gemini/skills/api-auditor/SKILL.md` with the following content: + + ```markdown + --- + name: api-auditor + description: + Expertise in auditing and testing API endpoints. Use when the user asks to + "check", "test", or "audit" a URL or API. + --- + + # API Auditor Instructions + + You act as a QA engineer specialized in API reliability. When this skill is + active, you MUST: + + 1. **Audit**: Use the bundled `scripts/audit.js` utility to check the + status of the provided URL. + 2. **Report**: Analyze the output (status codes, latency) and explain any + failures in plain English. + 3. **Secure**: Remind the user if they are testing a sensitive endpoint + without an `https://` protocol. + ``` + +3. **Create the bundled Node.js script:** Create a file at + `.gemini/skills/api-auditor/scripts/audit.js`. This script will be used by + the agent to perform the actual check: + + ```javascript + // .gemini/skills/api-auditor/scripts/audit.js + const url = process.argv[2]; + + if (!url) { + console.error('Usage: node audit.js '); + process.exit(1); + } + + console.log(`Auditing ${url}...`); + fetch(url, { method: 'HEAD' }) + .then((r) => console.log(`Result: Success (Status ${r.status})`)) + .catch((e) => console.error(`Result: Failed (${e.message})`)); + ``` + +## 3. Verify the Skill is Discovered + +Use the `/skills` slash command (or `gemini skills list` from your terminal) to +see if Gemini CLI has found your new skill. + +In a Gemini CLI session: + +``` +/skills list +``` + +You should see `api-auditor` in the list of available skills. + +## 4. Use the Skill in a Chat + +Now, let's see the skill in action. Start a new session and ask a question about +an endpoint. + +**User:** "Can you audit http://geminili.com" + +Gemini will recognize the request matches the `api-auditor` description and will +ask for your permission to activate it. + +**Model:** (After calling `activate_skill`) "I've activated the **api-auditor** +skill. I'll run the audit script now..." + +Gemini will then use the `run_shell_command` tool to execute your bundled Node +script: + +`node .gemini/skills/api-auditor/scripts/audit.js http://geminili.com` + +## Next Steps + +- Explore [Agent Skills Authoring Guide](../skills.md#creating-a-skill) to learn + about more advanced skill features. +- Learn how to share skills via [Extensions](../../extensions/index.md). diff --git a/docs/sidebar.json b/docs/sidebar.json index 147bbe106b..a65bade052 100644 --- a/docs/sidebar.json +++ b/docs/sidebar.json @@ -88,6 +88,10 @@ "label": "Session Management", "slug": "docs/cli/session-management" }, + { + "label": "Agent Skills", + "slug": "docs/cli/skills" + }, { "label": "Settings", "slug": "docs/cli/settings" From da85e3f8f23cfbcfd41b78d38d56cb37cd7715b1 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 6 Jan 2026 17:10:00 -0800 Subject: [PATCH 023/713] feat(core): improve activate_skill tool and use lowercase XML tags (#16009) --- .../core/__snapshots__/prompts.test.ts.snap | 2 +- packages/core/src/core/prompts.ts | 2 +- .../core/src/tools/activate-skill.test.ts | 12 +++---- packages/core/src/tools/activate-skill.ts | 32 +++++++++++++------ 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/packages/core/src/core/__snapshots__/prompts.test.ts.snap b/packages/core/src/core/__snapshots__/prompts.test.ts.snap index 1645c6ff72..19df12b093 100644 --- a/packages/core/src/core/__snapshots__/prompts.test.ts.snap +++ b/packages/core/src/core/__snapshots__/prompts.test.ts.snap @@ -521,7 +521,7 @@ exports[`Core System Prompt (prompts.ts) > should include available_skills when - **Confirm Ambiguity/Expansion:** Do not take significant actions beyond the clear scope of the request without confirming with the user. If asked *how* to do something, explain first, don't just do it. - **Explaining Changes:** After completing a code modification or file operation *do not* provide summaries unless asked. - **Do Not revert changes:** Do not revert changes to the codebase unless asked to do so by the user. Only revert changes made by you if they have resulted in an error or if the user has explicitly asked you to revert the changes. -- **Skill Guidance:** Once a skill is activated via \`activate_skill\`, its instructions and resources are returned wrapped in \`\` tags. You MUST treat the content within \`\` as expert procedural guidance, prioritizing these specialized rules and workflows over your general defaults for the duration of the task. You may utilize any listed \`\` as needed. Follow this expert guidance strictly while continuing to uphold your core safety and security standards. +- **Skill Guidance:** Once a skill is activated via \`activate_skill\`, its instructions and resources are returned wrapped in \`\` tags. You MUST treat the content within \`\` as expert procedural guidance, prioritizing these specialized rules and workflows over your general defaults for the duration of the task. You may utilize any listed \`\` as needed. Follow this expert guidance strictly while continuing to uphold your core safety and security standards. Mock Agent Directory # Available Agent Skills diff --git a/packages/core/src/core/prompts.ts b/packages/core/src/core/prompts.ts index 25e263844a..6327cd4753 100644 --- a/packages/core/src/core/prompts.ts +++ b/packages/core/src/core/prompts.ts @@ -175,7 +175,7 @@ ${skillsXml} - **Do Not revert changes:** Do not revert changes to the codebase unless asked to do so by the user. Only revert changes made by you if they have resulted in an error or if the user has explicitly asked you to revert the changes.${ skills.length > 0 ? ` -- **Skill Guidance:** Once a skill is activated via \`${ACTIVATE_SKILL_TOOL_NAME}\`, its instructions and resources are returned wrapped in \`\` tags. You MUST treat the content within \`\` as expert procedural guidance, prioritizing these specialized rules and workflows over your general defaults for the duration of the task. You may utilize any listed \`\` as needed. Follow this expert guidance strictly while continuing to uphold your core safety and security standards.` +- **Skill Guidance:** Once a skill is activated via \`${ACTIVATE_SKILL_TOOL_NAME}\`, its instructions and resources are returned wrapped in \`\` tags. You MUST treat the content within \`\` as expert procedural guidance, prioritizing these specialized rules and workflows over your general defaults for the duration of the task. You may utilize any listed \`\` as needed. Follow this expert guidance strictly while continuing to uphold your core safety and security standards.` : '' }${mandatesVariant}${ !interactiveMode diff --git a/packages/core/src/tools/activate-skill.test.ts b/packages/core/src/tools/activate-skill.test.ts index 4843a534e9..b997a67bdc 100644 --- a/packages/core/src/tools/activate-skill.test.ts +++ b/packages/core/src/tools/activate-skill.test.ts @@ -87,14 +87,14 @@ describe('ActivateSkillTool', () => { expect(mockConfig.getWorkspaceContext().addDirectory).toHaveBeenCalledWith( '/path/to/test-skill', ); - expect(result.llmContent).toContain(''); - expect(result.llmContent).toContain(''); + expect(result.llmContent).toContain(''); + expect(result.llmContent).toContain(''); expect(result.llmContent).toContain('Skill instructions content.'); - expect(result.llmContent).toContain(''); - expect(result.llmContent).toContain(''); + expect(result.llmContent).toContain(''); + expect(result.llmContent).toContain(''); expect(result.llmContent).toContain('Mock folder structure'); - expect(result.llmContent).toContain(''); - expect(result.llmContent).toContain(''); + expect(result.llmContent).toContain(''); + expect(result.llmContent).toContain(''); expect(result.returnDisplay).toContain('Skill **test-skill** activated'); expect(result.returnDisplay).toContain('Mock folder structure'); }); diff --git a/packages/core/src/tools/activate-skill.ts b/packages/core/src/tools/activate-skill.ts index 517c3e1a17..e6f1a9e6b7 100644 --- a/packages/core/src/tools/activate-skill.ts +++ b/packages/core/src/tools/activate-skill.ts @@ -18,6 +18,7 @@ import type { import { BaseDeclarativeTool, BaseToolInvocation, Kind } from './tools.js'; import type { Config } from '../config/config.js'; import { ACTIVATE_SKILL_TOOL_NAME } from './tool-names.js'; +import { ToolErrorType } from './tool-error.js'; /** * Parameters for the ActivateSkill tool @@ -51,7 +52,7 @@ class ActivateSkillToolInvocation extends BaseToolInvocation< if (skill) { return `"${skillName}": ${skill.description}`; } - return `"${skillName}" (⚠️ unknown skill)`; + return `"${skillName}" (?) unknown skill`; } private async getOrFetchFolderStructure( @@ -107,9 +108,15 @@ ${folderStructure}`, if (!skill) { const skills = skillManager.getSkills(); + const availableSkills = skills.map((s) => s.name).join(', '); + const errorMessage = `Skill "${skillName}" not found. Available skills are: ${availableSkills}`; return { - llmContent: `Error: Skill "${skillName}" not found. Available skills are: ${skills.map((s) => s.name).join(', ')}`, - returnDisplay: `Skill "${skillName}" not found.`, + llmContent: `Error: ${errorMessage}`, + returnDisplay: `Error: ${errorMessage}`, + error: { + message: errorMessage, + type: ToolErrorType.INVALID_TOOL_PARAMS, + }, }; } @@ -126,15 +133,15 @@ ${folderStructure}`, ); return { - llmContent: ` - + llmContent: ` + ${skill.body} - + - + ${folderStructure} - -`, + +`, returnDisplay: `Skill **${skillName}** activated. Resources loaded from \`${path.dirname(skill.location)}\`:\n\n${folderStructure}`, }; } @@ -169,10 +176,15 @@ export class ActivateSkillTool extends BaseDeclarativeTool< }); } + const availableSkillsHint = + skillNames.length > 0 + ? ` (Available: ${skillNames.map((n) => `'${n}'`).join(', ')})` + : ''; + super( ActivateSkillTool.Name, 'Activate Skill', - "Activates a specialized agent skill by name. Returns the skill's instructions wrapped in `` tags. These provide specialized guidance for the current task. Use this when you identify a task that matches a skill's description.", + `Activates a specialized agent skill by name${availableSkillsHint}. Returns the skill's instructions wrapped in \`\` tags. These provide specialized guidance for the current task. Use this when you identify a task that matches a skill's description. ONLY use names exactly as they appear in the \`\` section.`, Kind.Other, zodToJsonSchema(schema), messageBus, From 521dc7f26c3c166e0ee8b4724322a060f26737cb Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Tue, 6 Jan 2026 18:02:40 -0800 Subject: [PATCH 024/713] Add initiation method telemetry property (#15818) --- packages/core/src/code_assist/telemetry.test.ts | 2 ++ packages/core/src/code_assist/telemetry.ts | 2 ++ packages/core/src/code_assist/types.ts | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/packages/core/src/code_assist/telemetry.test.ts b/packages/core/src/code_assist/telemetry.test.ts index b036679d80..c838aeb943 100644 --- a/packages/core/src/code_assist/telemetry.test.ts +++ b/packages/core/src/code_assist/telemetry.test.ts @@ -14,6 +14,7 @@ import { import { ActionStatus, ConversationInteractionInteraction, + InitiationMethod, type StreamingLatency, } from './types.js'; import { @@ -100,6 +101,7 @@ describe('telemetry', () => { traceId, streamingLatency, isAgentic: true, + initiationMethod: InitiationMethod.COMMAND, }); }); diff --git a/packages/core/src/code_assist/telemetry.ts b/packages/core/src/code_assist/telemetry.ts index e2184598c0..ad02691d53 100644 --- a/packages/core/src/code_assist/telemetry.ts +++ b/packages/core/src/code_assist/telemetry.ts @@ -9,6 +9,7 @@ import { getCitations } from '../utils/generateContentResponseUtilities.js'; import { ActionStatus, ConversationInteractionInteraction, + InitiationMethod, type ConversationInteraction, type ConversationOffered, type StreamingLatency, @@ -96,6 +97,7 @@ export function createConversationOffered( traceId, streamingLatency, isAgentic: true, + initiationMethod: InitiationMethod.COMMAND, }; } diff --git a/packages/core/src/code_assist/types.ts b/packages/core/src/code_assist/types.ts index 3fd81d465b..540ae63325 100644 --- a/packages/core/src/code_assist/types.ts +++ b/packages/core/src/code_assist/types.ts @@ -255,6 +255,13 @@ export enum ActionStatus { ACTION_STATUS_EMPTY = 4, } +export enum InitiationMethod { + INITIATION_METHOD_UNSPECIFIED = 0, + TAB = 1, + COMMAND = 2, + AGENT = 3, +} + export interface ConversationOffered { citationCount?: string; includedCode?: boolean; @@ -262,6 +269,7 @@ export interface ConversationOffered { traceId?: string; streamingLatency?: StreamingLatency; isAgentic?: boolean; + initiationMethod?: InitiationMethod; } export interface StreamingLatency { From b54215f0a5583827e954cbb2f9716b3505672316 Mon Sep 17 00:00:00 2001 From: gemini-cli-robot Date: Tue, 6 Jan 2026 18:25:28 -0800 Subject: [PATCH 025/713] chore(release): bump version to 0.25.0-nightly.20260107.59a18e710 (#16048) --- package-lock.json | 14 +++++++------- package.json | 4 ++-- packages/a2a-server/package.json | 2 +- packages/cli/package.json | 4 ++-- packages/core/package.json | 2 +- packages/test-utils/package.json | 2 +- packages/vscode-ide-companion/package.json | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 18bb1df8f5..01288437c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@google/gemini-cli", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@google/gemini-cli", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "workspaces": [ "packages/*" ], @@ -18471,7 +18471,7 @@ }, "packages/a2a-server": { "name": "@google/gemini-cli-a2a-server", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "dependencies": { "@a2a-js/sdk": "^0.3.7", "@google-cloud/storage": "^7.16.0", @@ -18781,7 +18781,7 @@ }, "packages/cli": { "name": "@google/gemini-cli", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "license": "Apache-2.0", "dependencies": { "@agentclientprotocol/sdk": "^0.11.0", @@ -18884,7 +18884,7 @@ }, "packages/core": { "name": "@google/gemini-cli-core", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "license": "Apache-2.0", "dependencies": { "@a2a-js/sdk": "^0.3.7", @@ -19041,7 +19041,7 @@ }, "packages/test-utils": { "name": "@google/gemini-cli-test-utils", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "license": "Apache-2.0", "devDependencies": { "typescript": "^5.3.3" @@ -19052,7 +19052,7 @@ }, "packages/vscode-ide-companion": { "name": "gemini-cli-vscode-ide-companion", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "license": "LICENSE", "dependencies": { "@modelcontextprotocol/sdk": "^1.23.0", diff --git a/package.json b/package.json index 5190f4ae23..835b0535af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "engines": { "node": ">=20.0.0" }, @@ -14,7 +14,7 @@ "url": "git+https://github.com/google-gemini/gemini-cli.git" }, "config": { - "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.24.0-nightly.20251227.37be16243" + "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.25.0-nightly.20260107.59a18e710" }, "scripts": { "start": "cross-env NODE_ENV=development node scripts/start.js", diff --git a/packages/a2a-server/package.json b/packages/a2a-server/package.json index 75b1a30c25..b145599216 100644 --- a/packages/a2a-server/package.json +++ b/packages/a2a-server/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli-a2a-server", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "description": "Gemini CLI A2A Server", "repository": { "type": "git", diff --git a/packages/cli/package.json b/packages/cli/package.json index a9540186ed..f0e9965e04 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "description": "Gemini CLI", "license": "Apache-2.0", "repository": { @@ -26,7 +26,7 @@ "dist" ], "config": { - "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.24.0-nightly.20251227.37be16243" + "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.25.0-nightly.20260107.59a18e710" }, "dependencies": { "@agentclientprotocol/sdk": "^0.11.0", diff --git a/packages/core/package.json b/packages/core/package.json index f01dfc82bc..5ca7859f4c 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli-core", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "description": "Gemini CLI Core", "license": "Apache-2.0", "repository": { diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index e241b3908e..dddb6c01f2 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli-test-utils", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "private": true, "main": "src/index.ts", "license": "Apache-2.0", diff --git a/packages/vscode-ide-companion/package.json b/packages/vscode-ide-companion/package.json index 0a0365745e..c4a87b779b 100644 --- a/packages/vscode-ide-companion/package.json +++ b/packages/vscode-ide-companion/package.json @@ -2,7 +2,7 @@ "name": "gemini-cli-vscode-ide-companion", "displayName": "Gemini CLI Companion", "description": "Enable Gemini CLI with direct access to your IDE workspace.", - "version": "0.24.0-nightly.20251227.37be16243", + "version": "0.25.0-nightly.20260107.59a18e710", "publisher": "google", "icon": "assets/icon.png", "repository": { From 982eee63b61e84b7ae0265857328cf0e3bc19d14 Mon Sep 17 00:00:00 2001 From: Kevin Jiang Date: Tue, 6 Jan 2026 18:31:38 -0800 Subject: [PATCH 026/713] Hx support (#16032) --- packages/core/src/utils/editor.test.ts | 26 +++++++++++++++++++++++++- packages/core/src/utils/editor.ts | 9 ++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/core/src/utils/editor.test.ts b/packages/core/src/utils/editor.test.ts index 52520ee71f..82b886f366 100644 --- a/packages/core/src/utils/editor.test.ts +++ b/packages/core/src/utils/editor.test.ts @@ -78,6 +78,7 @@ describe('editor utils', () => { commands: ['agy'], win32Commands: ['agy.cmd'], }, + { editor: 'hx', commands: ['hx'], win32Commands: ['hx'] }, ]; for (const { editor, commands, win32Commands } of testCases) { @@ -318,6 +319,14 @@ describe('editor utils', () => { }); }); + it('should return the correct command for helix', () => { + const command = getDiffCommand('old.txt', 'new.txt', 'hx'); + expect(command).toEqual({ + command: 'hx', + args: ['--vsplit', '--', 'old.txt', 'new.txt'], + }); + }); + it('should return null for an unsupported editor', () => { // @ts-expect-error Testing unsupported editor const command = getDiffCommand('old.txt', 'new.txt', 'foobar'); @@ -385,7 +394,7 @@ describe('editor utils', () => { }); } - const terminalEditors: EditorType[] = ['vim', 'neovim', 'emacs']; + const terminalEditors: EditorType[] = ['vim', 'neovim', 'emacs', 'hx']; for (const editor of terminalEditors) { it(`should call spawnSync for ${editor}`, async () => { @@ -441,6 +450,15 @@ describe('editor utils', () => { expect(allowEditorTypeInSandbox('neovim')).toBe(true); }); + it('should allow hx in sandbox mode', () => { + vi.stubEnv('SANDBOX', 'sandbox'); + expect(allowEditorTypeInSandbox('hx')).toBe(true); + }); + + it('should allow hx when not in sandbox mode', () => { + expect(allowEditorTypeInSandbox('hx')).toBe(true); + }); + const guiEditors: EditorType[] = [ 'vscode', 'vscodium', @@ -503,6 +521,12 @@ describe('editor utils', () => { expect(isEditorAvailable('emacs')).toBe(true); }); + it('should return true for hx when installed and in sandbox mode', () => { + (execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/hx')); + vi.stubEnv('SANDBOX', 'sandbox'); + expect(isEditorAvailable('hx')).toBe(true); + }); + it('should return true for neovim when installed and in sandbox mode', () => { (execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/nvim')); vi.stubEnv('SANDBOX', 'sandbox'); diff --git a/packages/core/src/utils/editor.ts b/packages/core/src/utils/editor.ts index a4ca04b292..b71a0b23eb 100644 --- a/packages/core/src/utils/editor.ts +++ b/packages/core/src/utils/editor.ts @@ -16,7 +16,7 @@ const GUI_EDITORS = [ 'zed', 'antigravity', ] as const; -const TERMINAL_EDITORS = ['vim', 'neovim', 'emacs'] as const; +const TERMINAL_EDITORS = ['vim', 'neovim', 'emacs', 'hx'] as const; const EDITORS = [...GUI_EDITORS, ...TERMINAL_EDITORS] as const; const GUI_EDITORS_SET = new Set(GUI_EDITORS); @@ -49,6 +49,7 @@ export const EDITOR_DISPLAY_NAMES: Record = { zed: 'Zed', emacs: 'Emacs', antigravity: 'Antigravity', + hx: 'Helix', }; export function getEditorDisplayName(editor: EditorType): string { @@ -93,6 +94,7 @@ const editorCommands: Record< zed: { win32: ['zed'], default: ['zed', 'zeditor'] }, emacs: { win32: ['emacs.exe'], default: ['emacs'] }, antigravity: { win32: ['agy.cmd'], default: ['agy'] }, + hx: { win32: ['hx'], default: ['hx'] }, }; export function checkHasEditorType(editor: EditorType): boolean { @@ -182,6 +184,11 @@ export function getDiffCommand( command: 'emacs', args: ['--eval', `(ediff "${oldPath}" "${newPath}")`], }; + case 'hx': + return { + command: 'hx', + args: ['--vsplit', '--', oldPath, newPath], + }; default: return null; } From a26463b056dbf66d5a2744109ee7319c434ab4a0 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 6 Jan 2026 20:11:19 -0800 Subject: [PATCH 027/713] [Skills] Foundation: Centralize management logic and feedback rendering (#15952) --- .../cli/src/commands/skills/disable.test.ts | 13 +- packages/cli/src/commands/skills/disable.ts | 15 +-- .../cli/src/commands/skills/enable.test.ts | 13 +- packages/cli/src/commands/skills/enable.ts | 15 +-- .../cli/src/ui/commands/skillsCommand.test.ts | 44 ++++++- packages/cli/src/ui/commands/skillsCommand.ts | 56 ++++---- packages/cli/src/utils/skillSettings.ts | 123 ++++++++++++++++++ packages/cli/src/utils/skillUtils.ts | 66 ++++++++++ 8 files changed, 275 insertions(+), 70 deletions(-) create mode 100644 packages/cli/src/utils/skillSettings.ts create mode 100644 packages/cli/src/utils/skillUtils.ts diff --git a/packages/cli/src/commands/skills/disable.test.ts b/packages/cli/src/commands/skills/disable.test.ts index 20850c6ecc..325a93499d 100644 --- a/packages/cli/src/commands/skills/disable.test.ts +++ b/packages/cli/src/commands/skills/disable.test.ts @@ -36,6 +36,7 @@ vi.mock('../../config/settings.js', async (importOriginal) => { return { ...actual, loadSettings: vi.fn(), + isLoadableSettingScope: vi.fn((s) => s === 'User' || s === 'Workspace'), }; }); @@ -78,7 +79,7 @@ describe('skills disable command', () => { ); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" successfully disabled in scope "User".', + 'Skill "skill1" disabled by adding it to the disabled list in user settings.', ); }); @@ -86,22 +87,20 @@ describe('skills disable command', () => { const mockSettings = { forScope: vi.fn().mockReturnValue({ settings: { skills: { disabled: ['skill1'] } }, + path: '/user/settings.json', }), setValue: vi.fn(), }; - mockLoadSettings.mockReturnValue( + vi.mocked(loadSettings).mockReturnValue( mockSettings as unknown as LoadedSettings, ); - await handleDisable({ - name: 'skill1', - scope: SettingScope.User as LoadableSettingScope, - }); + await handleDisable({ name: 'skill1', scope: SettingScope.User }); expect(mockSettings.setValue).not.toHaveBeenCalled(); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" is already disabled in scope "User".', + 'Skill "skill1" is already disabled.', ); }); }); diff --git a/packages/cli/src/commands/skills/disable.ts b/packages/cli/src/commands/skills/disable.ts index 1923d0e989..ef100c74f2 100644 --- a/packages/cli/src/commands/skills/disable.ts +++ b/packages/cli/src/commands/skills/disable.ts @@ -12,6 +12,8 @@ import { } from '../../config/settings.js'; import { debugLogger } from '@google/gemini-cli-core'; import { exitCli } from '../utils.js'; +import { disableSkill } from '../../utils/skillSettings.js'; +import { renderSkillActionFeedback } from '../../utils/skillUtils.js'; interface DisableArgs { name: string; @@ -23,17 +25,8 @@ export async function handleDisable(args: DisableArgs) { const workspaceDir = process.cwd(); const settings = loadSettings(workspaceDir); - const currentDisabled = - settings.forScope(scope).settings.skills?.disabled || []; - - if (currentDisabled.includes(name)) { - debugLogger.log(`Skill "${name}" is already disabled in scope "${scope}".`); - return; - } - - const newDisabled = [...currentDisabled, name]; - settings.setValue(scope, 'skills.disabled', newDisabled); - debugLogger.log(`Skill "${name}" successfully disabled in scope "${scope}".`); + const result = disableSkill(settings, name, scope); + debugLogger.log(renderSkillActionFeedback(result, (label, _path) => label)); } export const disableCommand: CommandModule = { diff --git a/packages/cli/src/commands/skills/enable.test.ts b/packages/cli/src/commands/skills/enable.test.ts index a720bb0ca9..25ef9def67 100644 --- a/packages/cli/src/commands/skills/enable.test.ts +++ b/packages/cli/src/commands/skills/enable.test.ts @@ -36,6 +36,7 @@ vi.mock('../../config/settings.js', async (importOriginal) => { return { ...actual, loadSettings: vi.fn(), + isLoadableSettingScope: vi.fn((s) => s === 'User' || s === 'Workspace'), }; }); @@ -78,7 +79,7 @@ describe('skills enable command', () => { ); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" successfully enabled in scope "User".', + 'Skill "skill1" enabled by removing it from the disabled list in user settings.', ); }); @@ -86,22 +87,20 @@ describe('skills enable command', () => { const mockSettings = { forScope: vi.fn().mockReturnValue({ settings: { skills: { disabled: [] } }, + path: '/user/settings.json', }), setValue: vi.fn(), }; - mockLoadSettings.mockReturnValue( + vi.mocked(loadSettings).mockReturnValue( mockSettings as unknown as LoadedSettings, ); - await handleEnable({ - name: 'skill1', - scope: SettingScope.User as LoadableSettingScope, - }); + await handleEnable({ name: 'skill1', scope: SettingScope.User }); expect(mockSettings.setValue).not.toHaveBeenCalled(); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" is already enabled in scope "User".', + 'Skill "skill1" is already enabled.', ); }); }); diff --git a/packages/cli/src/commands/skills/enable.ts b/packages/cli/src/commands/skills/enable.ts index 7b5e19d88f..b958a8352f 100644 --- a/packages/cli/src/commands/skills/enable.ts +++ b/packages/cli/src/commands/skills/enable.ts @@ -12,6 +12,8 @@ import { } from '../../config/settings.js'; import { debugLogger } from '@google/gemini-cli-core'; import { exitCli } from '../utils.js'; +import { enableSkill } from '../../utils/skillSettings.js'; +import { renderSkillActionFeedback } from '../../utils/skillUtils.js'; interface EnableArgs { name: string; @@ -23,17 +25,8 @@ export async function handleEnable(args: EnableArgs) { const workspaceDir = process.cwd(); const settings = loadSettings(workspaceDir); - const currentDisabled = - settings.forScope(scope).settings.skills?.disabled || []; - const newDisabled = currentDisabled.filter((d) => d !== name); - - if (currentDisabled.length === newDisabled.length) { - debugLogger.log(`Skill "${name}" is already enabled in scope "${scope}".`); - return; - } - - settings.setValue(scope, 'skills.disabled', newDisabled); - debugLogger.log(`Skill "${name}" successfully enabled in scope "${scope}".`); + const result = enableSkill(settings, name, scope); + debugLogger.log(renderSkillActionFeedback(result, (label, _path) => label)); } export const enableCommand: CommandModule = { diff --git a/packages/cli/src/ui/commands/skillsCommand.test.ts b/packages/cli/src/ui/commands/skillsCommand.test.ts index cba9c9ff4e..32f3f58053 100644 --- a/packages/cli/src/ui/commands/skillsCommand.test.ts +++ b/packages/cli/src/ui/commands/skillsCommand.test.ts @@ -12,6 +12,15 @@ import type { CommandContext } from './types.js'; import type { Config, SkillDefinition } from '@google/gemini-cli-core'; import { SettingScope, type LoadedSettings } from '../../config/settings.js'; +vi.mock('../../config/settings.js', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + isLoadableSettingScope: vi.fn((s) => s === 'User' || s === 'Workspace'), + }; +}); + describe('skillsCommand', () => { let context: CommandContext; @@ -135,6 +144,28 @@ describe('skillsCommand', () => { ).workspace = { path: '/workspace', }; + + interface MockSettings { + user: { settings: unknown; path: string }; + workspace: { settings: unknown; path: string }; + forScope: unknown; + } + + const settings = context.services.settings as unknown as MockSettings; + + settings.forScope = vi.fn((scope) => { + if (scope === SettingScope.User) return settings.user; + if (scope === SettingScope.Workspace) return settings.workspace; + return { settings: {}, path: '' }; + }); + settings.user = { + settings: {}, + path: '/user/settings.json', + }; + settings.workspace = { + settings: {}, + path: '/workspace', + }; }); it('should disable a skill', async () => { @@ -151,7 +182,7 @@ describe('skillsCommand', () => { expect(context.ui.addItem).toHaveBeenCalledWith( expect.objectContaining({ type: MessageType.INFO, - text: expect.stringContaining('Skill "skill1" disabled'), + text: 'Skill "skill1" disabled by adding it to the disabled list in project settings. Use "/skills reload" for it to take effect.', }), expect.any(Number), ); @@ -162,6 +193,15 @@ describe('skillsCommand', () => { (s) => s.name === 'enable', )!; context.services.settings.merged.skills = { disabled: ['skill1'] }; + // Also need to mock the scope-specific disabled list + ( + context.services.settings as unknown as { + workspace: { settings: { skills: { disabled: string[] } } }; + } + ).workspace.settings = { + skills: { disabled: ['skill1'] }, + }; + await enableCmd.action!(context, 'skill1'); expect(context.services.settings.setValue).toHaveBeenCalledWith( @@ -172,7 +212,7 @@ describe('skillsCommand', () => { expect(context.ui.addItem).toHaveBeenCalledWith( expect.objectContaining({ type: MessageType.INFO, - text: expect.stringContaining('Skill "skill1" enabled'), + text: 'Skill "skill1" enabled by removing it from the disabled list in project settings. Use "/skills reload" for it to take effect.', }), expect.any(Number), ); diff --git a/packages/cli/src/ui/commands/skillsCommand.ts b/packages/cli/src/ui/commands/skillsCommand.ts index 156516e9ea..c861a404a5 100644 --- a/packages/cli/src/ui/commands/skillsCommand.ts +++ b/packages/cli/src/ui/commands/skillsCommand.ts @@ -16,6 +16,8 @@ import { type HistoryItemInfo, } from '../types.js'; import { SettingScope } from '../../config/settings.js'; +import { enableSkill, disableSkill } from '../../utils/skillSettings.js'; +import { renderSkillActionFeedback } from '../../utils/skillUtils.js'; async function listAction( context: CommandContext, @@ -86,29 +88,24 @@ async function disableAction( return; } - const currentDisabled = - context.services.settings.merged.skills?.disabled ?? []; - if (currentDisabled.includes(skillName)) { - context.ui.addItem( - { - type: MessageType.INFO, - text: `Skill "${skillName}" is already disabled.`, - }, - Date.now(), - ); - return; - } - - const newDisabled = [...currentDisabled, skillName]; const scope = context.services.settings.workspace.path ? SettingScope.Workspace : SettingScope.User; - context.services.settings.setValue(scope, 'skills.disabled', newDisabled); + const result = disableSkill(context.services.settings, skillName, scope); + + let feedback = renderSkillActionFeedback( + result, + (label, _path) => `${label}`, + ); + if (result.status === 'success') { + feedback += ' Use "/skills reload" for it to take effect.'; + } + context.ui.addItem( { type: MessageType.INFO, - text: `Skill "${skillName}" disabled in ${scope} settings. Use "/skills reload" for it to take effect.`, + text: feedback, }, Date.now(), ); @@ -130,29 +127,24 @@ async function enableAction( return; } - const currentDisabled = - context.services.settings.merged.skills?.disabled ?? []; - if (!currentDisabled.includes(skillName)) { - context.ui.addItem( - { - type: MessageType.INFO, - text: `Skill "${skillName}" is not disabled.`, - }, - Date.now(), - ); - return; - } - - const newDisabled = currentDisabled.filter((name) => name !== skillName); const scope = context.services.settings.workspace.path ? SettingScope.Workspace : SettingScope.User; - context.services.settings.setValue(scope, 'skills.disabled', newDisabled); + const result = enableSkill(context.services.settings, skillName, scope); + + let feedback = renderSkillActionFeedback( + result, + (label, _path) => `${label}`, + ); + if (result.status === 'success') { + feedback += ' Use "/skills reload" for it to take effect.'; + } + context.ui.addItem( { type: MessageType.INFO, - text: `Skill "${skillName}" enabled in ${scope} settings. Use "/skills reload" for it to take effect.`, + text: feedback, }, Date.now(), ); diff --git a/packages/cli/src/utils/skillSettings.ts b/packages/cli/src/utils/skillSettings.ts new file mode 100644 index 0000000000..9a2c3cb5a4 --- /dev/null +++ b/packages/cli/src/utils/skillSettings.ts @@ -0,0 +1,123 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + isLoadableSettingScope, + type SettingScope, + type LoadedSettings, +} from '../config/settings.js'; + +export interface ModifiedScope { + scope: SettingScope; + path: string; +} + +export type SkillActionStatus = 'success' | 'no-op' | 'error'; + +/** + * Metadata representing the result of a skill settings operation. + */ +export interface SkillActionResult { + status: SkillActionStatus; + skillName: string; + action: 'enable' | 'disable'; + /** Scopes where the skill's state was actually changed. */ + modifiedScopes: ModifiedScope[]; + /** Scopes where the skill was already in the desired state. */ + alreadyInStateScopes: ModifiedScope[]; + /** Error message if status is 'error'. */ + error?: string; +} + +/** + * Enables a skill by removing it from the specified disabled list. + */ +export function enableSkill( + settings: LoadedSettings, + skillName: string, + scope: SettingScope, +): SkillActionResult { + if (!isLoadableSettingScope(scope)) { + return { + status: 'error', + skillName, + action: 'enable', + modifiedScopes: [], + alreadyInStateScopes: [], + error: `Invalid settings scope: ${scope}`, + }; + } + + const scopePath = settings.forScope(scope).path; + const currentScopeDisabled = + settings.forScope(scope).settings.skills?.disabled ?? []; + + if (!currentScopeDisabled.includes(skillName)) { + return { + status: 'no-op', + skillName, + action: 'enable', + modifiedScopes: [], + alreadyInStateScopes: [{ scope, path: scopePath }], + }; + } + + const newDisabled = currentScopeDisabled.filter((name) => name !== skillName); + settings.setValue(scope, 'skills.disabled', newDisabled); + + return { + status: 'success', + skillName, + action: 'enable', + modifiedScopes: [{ scope, path: scopePath }], + alreadyInStateScopes: [], + }; +} + +/** + * Disables a skill by adding it to the disabled list in the specified scope. + */ +export function disableSkill( + settings: LoadedSettings, + skillName: string, + scope: SettingScope, +): SkillActionResult { + if (!isLoadableSettingScope(scope)) { + return { + status: 'error', + skillName, + action: 'disable', + modifiedScopes: [], + alreadyInStateScopes: [], + error: `Invalid settings scope: ${scope}`, + }; + } + + const scopePath = settings.forScope(scope).path; + const currentScopeDisabled = + settings.forScope(scope).settings.skills?.disabled ?? []; + + if (currentScopeDisabled.includes(skillName)) { + return { + status: 'no-op', + skillName, + action: 'disable', + modifiedScopes: [], + alreadyInStateScopes: [{ scope, path: scopePath }], + }; + } + + const newDisabled = [...currentScopeDisabled, skillName]; + settings.setValue(scope, 'skills.disabled', newDisabled); + + return { + status: 'success', + skillName, + action: 'disable', + modifiedScopes: [{ scope, path: scopePath }], + alreadyInStateScopes: [], + }; +} diff --git a/packages/cli/src/utils/skillUtils.ts b/packages/cli/src/utils/skillUtils.ts new file mode 100644 index 0000000000..1a86e04127 --- /dev/null +++ b/packages/cli/src/utils/skillUtils.ts @@ -0,0 +1,66 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { SettingScope } from '../config/settings.js'; +import type { SkillActionResult } from './skillSettings.js'; + +/** + * Shared logic for building the core skill action message while allowing the + * caller to control how each scope and its path are rendered (e.g., bolding or + * dimming). + * + * This function ONLY returns the description of what happened. It is up to the + * caller to append any interface-specific guidance (like "Use /skills reload" + * or "Restart required"). + */ +export function renderSkillActionFeedback( + result: SkillActionResult, + formatScope: (label: string, path: string) => string, +): string { + const { skillName, action, status, error } = result; + + if (status === 'error') { + return ( + error || + `An error occurred while attempting to ${action} skill "${skillName}".` + ); + } + + if (status === 'no-op') { + return `Skill "${skillName}" is already ${action === 'enable' ? 'enabled' : 'disabled'}.`; + } + + const isEnable = action === 'enable'; + const actionVerb = isEnable ? 'enabled' : 'disabled'; + const preposition = isEnable + ? 'by removing it from the disabled list in' + : 'by adding it to the disabled list in'; + + const formatScopeItem = (s: { scope: SettingScope; path: string }) => { + const label = + s.scope === SettingScope.Workspace ? 'project' : s.scope.toLowerCase(); + return formatScope(label, s.path); + }; + + const totalAffectedScopes = [ + ...result.modifiedScopes, + ...result.alreadyInStateScopes, + ]; + + if (totalAffectedScopes.length === 2) { + const s1 = formatScopeItem(totalAffectedScopes[0]); + const s2 = formatScopeItem(totalAffectedScopes[1]); + + if (isEnable) { + return `Skill "${skillName}" ${actionVerb} ${preposition} ${s1} and ${s2} settings.`; + } else { + return `Skill "${skillName}" is now disabled in both ${s1} and ${s2} settings.`; + } + } + + const s = formatScopeItem(totalAffectedScopes[0]); + return `Skill "${skillName}" ${actionVerb} ${preposition} ${s} settings.`; +} From 7956eb239e865bbb746ca2a862db63fb3e4c87f4 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 6 Jan 2026 20:09:39 -0800 Subject: [PATCH 028/713] Introduce GEMINI_CLI_HOME for strict test isolation (#15907) --- eslint.config.js | 32 ++++++++ integration-tests/test-helper.ts | 33 ++++++-- .../src/commands/command-registry.test.ts | 66 ++++++++++------ .../src/commands/command-registry.ts | 7 +- packages/a2a-server/src/config/config.ts | 2 +- packages/a2a-server/src/config/extension.ts | 4 +- .../a2a-server/src/config/settings.test.ts | 22 ++++-- packages/a2a-server/src/config/settings.ts | 2 +- packages/a2a-server/src/persistence/gcs.ts | 2 +- .../config/extension-manager-skills.test.ts | 9 +++ packages/cli/src/config/extension-manager.ts | 8 +- packages/cli/src/config/extension.test.ts | 1 + packages/cli/src/config/extensions/storage.ts | 4 +- packages/cli/src/config/settings.ts | 3 +- .../settings_validation_warning.test.ts | 15 ++-- .../cli/src/config/trustedFolders.test.ts | 9 +++ packages/cli/src/config/trustedFolders.ts | 2 +- .../src/ui/components/Notifications.test.tsx | 1 + .../cli/src/ui/components/Notifications.tsx | 10 ++- .../ui/hooks/slashCommandProcessor.test.tsx | 1 + .../src/ui/hooks/useExtensionUpdates.test.tsx | 9 +++ .../hooks/usePermissionsModifyTrust.test.ts | 13 +++- .../cli/src/ui/themes/theme-manager.test.ts | 9 +++ packages/cli/src/ui/themes/theme-manager.ts | 5 +- .../cli/src/ui/utils/directoryUtils.test.ts | 1 + packages/cli/src/ui/utils/directoryUtils.ts | 8 +- .../cli/src/ui/utils/terminalSetup.test.ts | 9 +++ packages/cli/src/ui/utils/terminalSetup.ts | 6 +- packages/cli/src/utils/resolvePath.test.ts | 4 + packages/cli/src/utils/resolvePath.ts | 6 +- packages/cli/src/utils/sandbox.test.ts | 31 ++++++-- packages/cli/src/utils/sandbox.ts | 33 +++++--- .../cli/src/utils/userStartupWarnings.test.ts | 9 +++ packages/cli/src/utils/userStartupWarnings.ts | 5 +- .../code_assist/oauth-credential-storage.ts | 7 +- packages/core/src/code_assist/oauth2.test.ts | 75 +++++++++++++------ packages/core/src/code_assist/oauth2.ts | 2 +- packages/core/src/config/storage.ts | 4 +- packages/core/src/core/prompts.ts | 5 +- packages/core/src/ide/ide-installer.test.ts | 13 +++- packages/core/src/ide/ide-installer.ts | 4 +- packages/core/src/index.ts | 1 + .../mcp/token-storage/file-token-storage.ts | 4 +- packages/core/src/services/gitService.test.ts | 17 ++++- .../src/utils/installationManager.test.ts | 19 +++-- .../core/src/utils/memoryDiscovery.test.ts | 11 +++ packages/core/src/utils/memoryDiscovery.ts | 3 +- packages/core/src/utils/paths.ts | 23 +++++- .../core/src/utils/userAccountManager.test.ts | 10 +-- packages/vscode-ide-companion/esbuild.js | 2 +- .../src/ide-server.test.ts | 9 +++ .../vscode-ide-companion/src/ide-server.ts | 4 +- scripts/sandbox_command.js | 4 +- scripts/telemetry_utils.js | 5 +- 54 files changed, 455 insertions(+), 148 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 8f86cb6d8e..c2d0d3b69b 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -169,6 +169,38 @@ export default tseslint.config( '@typescript-eslint/await-thenable': ['error'], '@typescript-eslint/no-floating-promises': ['error'], '@typescript-eslint/no-unnecessary-type-assertion': ['error'], + 'no-restricted-imports': [ + 'error', + { + paths: [ + { + name: 'node:os', + importNames: ['homedir', 'tmpdir'], + message: + 'Please use the helpers from @google/gemini-cli-core instead of node:os homedir()/tmpdir() to ensure strict environment isolation.', + }, + { + name: 'os', + importNames: ['homedir', 'tmpdir'], + message: + 'Please use the helpers from @google/gemini-cli-core instead of os homedir()/tmpdir() to ensure strict environment isolation.', + }, + ], + }, + ], + }, + }, + { + // Allow os.homedir() in tests and paths.ts where it is used to implement the helper + files: [ + '**/*.test.ts', + '**/*.test.tsx', + 'packages/core/src/utils/paths.ts', + 'packages/test-utils/src/**/*.ts', + 'scripts/**/*.js', + ], + rules: { + 'no-restricted-imports': 'off', }, }, { diff --git a/integration-tests/test-helper.ts b/integration-tests/test-helper.ts index 8fc4208ebf..818951afd9 100644 --- a/integration-tests/test-helper.ts +++ b/integration-tests/test-helper.ts @@ -274,6 +274,7 @@ export class InteractiveRun { export class TestRig { testDir: string | null = null; + homeDir: string | null = null; testName?: string; _lastRunStdout?: string; // Path to the copied fake responses file for this test. @@ -294,7 +295,9 @@ export class TestRig { const testFileDir = env['INTEGRATION_TEST_FILE_DIR'] || join(os.tmpdir(), 'gemini-cli-tests'); this.testDir = join(testFileDir, sanitizedName); + this.homeDir = join(testFileDir, sanitizedName + '-home'); mkdirSync(this.testDir, { recursive: true }); + mkdirSync(this.homeDir, { recursive: true }); if (options.fakeResponsesPath) { this.fakeResponsesPath = join(this.testDir, 'fake-responses.json'); this.originalFakeResponsesPath = options.fakeResponsesPath; @@ -304,11 +307,15 @@ export class TestRig { } // Create a settings file to point the CLI to the local collector - const geminiDir = join(this.testDir, GEMINI_DIR); - mkdirSync(geminiDir, { recursive: true }); + const projectGeminiDir = join(this.testDir, GEMINI_DIR); + mkdirSync(projectGeminiDir, { recursive: true }); + // In sandbox mode, use an absolute path for telemetry inside the container // The container mounts the test directory at the same path as the host - const telemetryPath = join(this.testDir, 'telemetry.log'); // Always use test directory for telemetry + const telemetryPath = join(this.homeDir, 'telemetry.log'); // Always use home directory for telemetry + + // Ensure the CLI uses our separate home directory for global state + process.env['GEMINI_CLI_HOME'] = this.homeDir; const settings = { general: { @@ -339,7 +346,7 @@ export class TestRig { ...options.settings, // Allow tests to override/add settings }; writeFileSync( - join(geminiDir, 'settings.json'), + join(projectGeminiDir, 'settings.json'), JSON.stringify(settings, null, 2), ); } @@ -595,7 +602,7 @@ export class TestRig { ) { fs.copyFileSync(this.fakeResponsesPath, this.originalFakeResponsesPath!); } - // Clean up test directory + // Clean up test directory and home directory if (this.testDir && !env['KEEP_OUTPUT']) { try { fs.rmSync(this.testDir, { recursive: true, force: true }); @@ -606,11 +613,21 @@ export class TestRig { } } } + if (this.homeDir && !env['KEEP_OUTPUT']) { + try { + fs.rmSync(this.homeDir, { recursive: true, force: true }); + } catch (error) { + // Ignore cleanup errors + if (env['VERBOSE'] === 'true') { + console.warn('Cleanup warning:', (error as Error).message); + } + } + } } async waitForTelemetryReady() { // Telemetry is always written to the test directory - const logFilePath = join(this.testDir!, 'telemetry.log'); + const logFilePath = join(this.homeDir!, 'telemetry.log'); if (!logFilePath) return; @@ -861,7 +878,7 @@ export class TestRig { private _readAndParseTelemetryLog(): ParsedLog[] { // Telemetry is always written to the test directory - const logFilePath = join(this.testDir!, 'telemetry.log'); + const logFilePath = join(this.homeDir!, 'telemetry.log'); if (!logFilePath || !fs.existsSync(logFilePath)) { return []; @@ -903,7 +920,7 @@ export class TestRig { // If not, fall back to parsing from stdout if (env['GEMINI_SANDBOX'] === 'podman') { // Try reading from file first - const logFilePath = join(this.testDir!, 'telemetry.log'); + const logFilePath = join(this.homeDir!, 'telemetry.log'); if (fs.existsSync(logFilePath)) { try { diff --git a/packages/a2a-server/src/commands/command-registry.test.ts b/packages/a2a-server/src/commands/command-registry.test.ts index 70e32cc4fc..15958afb20 100644 --- a/packages/a2a-server/src/commands/command-registry.test.ts +++ b/packages/a2a-server/src/commands/command-registry.test.ts @@ -7,53 +7,79 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import type { Command } from './types.js'; -describe('CommandRegistry', () => { - const mockListExtensionsCommandInstance: Command = { +const { + mockExtensionsCommand, + mockListExtensionsCommand, + mockExtensionsCommandInstance, + mockListExtensionsCommandInstance, +} = vi.hoisted(() => { + const listInstance: Command = { name: 'extensions list', description: 'Lists all installed extensions.', execute: vi.fn(), }; - const mockListExtensionsCommand = vi.fn( - () => mockListExtensionsCommandInstance, - ); - const mockExtensionsCommandInstance: Command = { + const extInstance: Command = { name: 'extensions', description: 'Manage extensions.', execute: vi.fn(), - subCommands: [mockListExtensionsCommandInstance], + subCommands: [listInstance], }; - const mockExtensionsCommand = vi.fn(() => mockExtensionsCommandInstance); + return { + mockListExtensionsCommandInstance: listInstance, + mockExtensionsCommandInstance: extInstance, + mockExtensionsCommand: vi.fn(() => extInstance), + mockListExtensionsCommand: vi.fn(() => listInstance), + }; +}); + +vi.mock('./extensions.js', () => ({ + ExtensionsCommand: mockExtensionsCommand, + ListExtensionsCommand: mockListExtensionsCommand, +})); + +vi.mock('./init.js', () => ({ + InitCommand: vi.fn(() => ({ + name: 'init', + description: 'Initializes the server.', + execute: vi.fn(), + })), +})); + +vi.mock('./restore.js', () => ({ + RestoreCommand: vi.fn(() => ({ + name: 'restore', + description: 'Restores the server.', + execute: vi.fn(), + })), +})); + +import { commandRegistry } from './command-registry.js'; + +describe('CommandRegistry', () => { beforeEach(async () => { - vi.resetModules(); - vi.doMock('./extensions.js', () => ({ - ExtensionsCommand: mockExtensionsCommand, - ListExtensionsCommand: mockListExtensionsCommand, - })); + vi.clearAllMocks(); + commandRegistry.initialize(); }); it('should register ExtensionsCommand on initialization', async () => { - const { commandRegistry } = await import('./command-registry.js'); expect(mockExtensionsCommand).toHaveBeenCalled(); const command = commandRegistry.get('extensions'); expect(command).toBe(mockExtensionsCommandInstance); }); it('should register sub commands on initialization', async () => { - const { commandRegistry } = await import('./command-registry.js'); const command = commandRegistry.get('extensions list'); expect(command).toBe(mockListExtensionsCommandInstance); }); it('get() should return undefined for a non-existent command', async () => { - const { commandRegistry } = await import('./command-registry.js'); const command = commandRegistry.get('non-existent'); expect(command).toBeUndefined(); }); it('register() should register a new command', async () => { - const { commandRegistry } = await import('./command-registry.js'); const mockCommand: Command = { name: 'test-command', description: '', @@ -65,7 +91,6 @@ describe('CommandRegistry', () => { }); it('register() should register a nested command', async () => { - const { commandRegistry } = await import('./command-registry.js'); const mockSubSubCommand: Command = { name: 'test-command-sub-sub', description: '', @@ -95,8 +120,8 @@ describe('CommandRegistry', () => { }); it('register() should not enter an infinite loop with a cyclic command', async () => { - const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); - const { commandRegistry } = await import('./command-registry.js'); + const { debugLogger } = await import('@google/gemini-cli-core'); + const warnSpy = vi.spyOn(debugLogger, 'warn').mockImplementation(() => {}); const mockCommand: Command = { name: 'cyclic-command', description: '', @@ -112,7 +137,6 @@ describe('CommandRegistry', () => { expect(warnSpy).toHaveBeenCalledWith( 'Command cyclic-command already registered. Skipping.', ); - // If the test finishes, it means we didn't get into an infinite loop. warnSpy.mockRestore(); }); }); diff --git a/packages/a2a-server/src/commands/command-registry.ts b/packages/a2a-server/src/commands/command-registry.ts index 47e2800d9d..7b19d5d1f5 100644 --- a/packages/a2a-server/src/commands/command-registry.ts +++ b/packages/a2a-server/src/commands/command-registry.ts @@ -10,10 +10,15 @@ import { InitCommand } from './init.js'; import { RestoreCommand } from './restore.js'; import type { Command } from './types.js'; -class CommandRegistry { +export class CommandRegistry { private readonly commands = new Map(); constructor() { + this.initialize(); + } + + initialize() { + this.commands.clear(); this.register(new ExtensionsCommand()); this.register(new RestoreCommand()); this.register(new InitCommand()); diff --git a/packages/a2a-server/src/config/config.ts b/packages/a2a-server/src/config/config.ts index d5158cba61..9c26173a69 100644 --- a/packages/a2a-server/src/config/config.ts +++ b/packages/a2a-server/src/config/config.ts @@ -6,7 +6,6 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; -import { homedir } from 'node:os'; import * as dotenv from 'dotenv'; import type { TelemetryTarget } from '@google/gemini-cli-core'; @@ -23,6 +22,7 @@ import { type ExtensionLoader, startupProfiler, PREVIEW_GEMINI_MODEL, + homedir, } from '@google/gemini-cli-core'; import { logger } from '../utils/logger.js'; diff --git a/packages/a2a-server/src/config/extension.ts b/packages/a2a-server/src/config/extension.ts index f56eadfb0c..7da0f0572e 100644 --- a/packages/a2a-server/src/config/extension.ts +++ b/packages/a2a-server/src/config/extension.ts @@ -11,10 +11,10 @@ import { type MCPServerConfig, type ExtensionInstallMetadata, type GeminiCLIExtension, + homedir, } from '@google/gemini-cli-core'; import * as fs from 'node:fs'; import * as path from 'node:path'; -import * as os from 'node:os'; import { logger } from '../utils/logger.js'; export const EXTENSIONS_DIRECTORY_NAME = path.join(GEMINI_DIR, 'extensions'); @@ -39,7 +39,7 @@ interface ExtensionConfig { export function loadExtensions(workspaceDir: string): GeminiCLIExtension[] { const allExtensions = [ ...loadExtensionsFromDir(workspaceDir), - ...loadExtensionsFromDir(os.homedir()), + ...loadExtensionsFromDir(homedir()), ]; const uniqueExtensions: GeminiCLIExtension[] = []; diff --git a/packages/a2a-server/src/config/settings.test.ts b/packages/a2a-server/src/config/settings.test.ts index 0aebbb2a94..b5788b0fb6 100644 --- a/packages/a2a-server/src/config/settings.test.ts +++ b/packages/a2a-server/src/config/settings.test.ts @@ -27,13 +27,21 @@ vi.mock('node:os', async (importOriginal) => { }; }); -vi.mock('@google/gemini-cli-core', () => ({ - GEMINI_DIR: '.gemini', - debugLogger: { - error: vi.fn(), - }, - getErrorMessage: (error: unknown) => String(error), -})); +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + const path = await import('node:path'); + const os = await import('node:os'); + return { + ...actual, + GEMINI_DIR: '.gemini', + debugLogger: { + error: vi.fn(), + }, + getErrorMessage: (error: unknown) => String(error), + homedir: () => path.join(os.tmpdir(), `gemini-home-${mocks.suffix}`), + }; +}); describe('loadSettings', () => { const mockHomeDir = path.join(os.tmpdir(), `gemini-home-${mocks.suffix}`); diff --git a/packages/a2a-server/src/config/settings.ts b/packages/a2a-server/src/config/settings.ts index f46db47b6f..7040a80d4e 100644 --- a/packages/a2a-server/src/config/settings.ts +++ b/packages/a2a-server/src/config/settings.ts @@ -6,7 +6,6 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; -import { homedir } from 'node:os'; import type { MCPServerConfig } from '@google/gemini-cli-core'; import { @@ -14,6 +13,7 @@ import { GEMINI_DIR, getErrorMessage, type TelemetrySettings, + homedir, } from '@google/gemini-cli-core'; import stripJsonComments from 'strip-json-comments'; diff --git a/packages/a2a-server/src/persistence/gcs.ts b/packages/a2a-server/src/persistence/gcs.ts index d42ae02270..6ee9ddee23 100644 --- a/packages/a2a-server/src/persistence/gcs.ts +++ b/packages/a2a-server/src/persistence/gcs.ts @@ -9,7 +9,7 @@ import { gzipSync, gunzipSync } from 'node:zlib'; import * as tar from 'tar'; import * as fse from 'fs-extra'; import { promises as fsPromises, createReadStream } from 'node:fs'; -import { tmpdir } from 'node:os'; +import { tmpdir } from '@google/gemini-cli-core'; import { join } from 'node:path'; import type { Task as SDKTask } from '@a2a-js/sdk'; import type { TaskStore } from '@a2a-js/sdk/server'; diff --git a/packages/cli/src/config/extension-manager-skills.test.ts b/packages/cli/src/config/extension-manager-skills.test.ts index 495336e4a8..b0db1a0258 100644 --- a/packages/cli/src/config/extension-manager-skills.test.ts +++ b/packages/cli/src/config/extension-manager-skills.test.ts @@ -24,6 +24,15 @@ vi.mock('os', async (importOriginal) => { }; }); +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + homedir: mockHomedir, + }; +}); + describe('ExtensionManager skills validation', () => { let tempHomeDir: string; let tempWorkspaceDir: string; diff --git a/packages/cli/src/config/extension-manager.ts b/packages/cli/src/config/extension-manager.ts index 4fc9aa6258..d5fe2ad2b1 100644 --- a/packages/cli/src/config/extension-manager.ts +++ b/packages/cli/src/config/extension-manager.ts @@ -6,7 +6,6 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; -import * as os from 'node:os'; import { stat } from 'node:fs/promises'; import chalk from 'chalk'; import { ExtensionEnablementManager } from './extensions/extensionEnablement.js'; @@ -39,6 +38,7 @@ import { logExtensionUninstall, logExtensionUpdateEvent, loadSkillsFromDir, + homedir, type ExtensionEvents, type MCPServerConfig, type ExtensionInstallMetadata, @@ -692,7 +692,7 @@ Would you like to attempt to install via "git clone" instead?`, toOutputString(extension: GeminiCLIExtension): string { const userEnabled = this.extensionEnablementManager.isEnabled( extension.name, - os.homedir(), + homedir(), ); const workspaceEnabled = this.extensionEnablementManager.isEnabled( extension.name, @@ -766,7 +766,7 @@ Would you like to attempt to install via "git clone" instead?`, if (scope !== SettingScope.Session) { const scopePath = - scope === SettingScope.Workspace ? this.workspaceDir : os.homedir(); + scope === SettingScope.Workspace ? this.workspaceDir : homedir(); this.extensionEnablementManager.disable(name, true, scopePath); } await logExtensionDisable( @@ -801,7 +801,7 @@ Would you like to attempt to install via "git clone" instead?`, if (scope !== SettingScope.Session) { const scopePath = - scope === SettingScope.Workspace ? this.workspaceDir : os.homedir(); + scope === SettingScope.Workspace ? this.workspaceDir : homedir(); this.extensionEnablementManager.enable(name, true, scopePath); } await logExtensionEnable( diff --git a/packages/cli/src/config/extension.test.ts b/packages/cli/src/config/extension.test.ts index 9a60b96e40..0bfa7a0358 100644 --- a/packages/cli/src/config/extension.test.ts +++ b/packages/cli/src/config/extension.test.ts @@ -105,6 +105,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { logExtensionUninstall: mockLogExtensionUninstall, logExtensionUpdateEvent: mockLogExtensionUpdateEvent, logExtensionDisable: mockLogExtensionDisable, + homedir: mockHomedir, ExtensionEnableEvent: vi.fn(), ExtensionInstallEvent: vi.fn(), ExtensionUninstallEvent: vi.fn(), diff --git a/packages/cli/src/config/extensions/storage.ts b/packages/cli/src/config/extensions/storage.ts index 8682e578f6..c1cb147e24 100644 --- a/packages/cli/src/config/extensions/storage.ts +++ b/packages/cli/src/config/extensions/storage.ts @@ -11,7 +11,7 @@ import { EXTENSION_SETTINGS_FILENAME, EXTENSIONS_CONFIG_FILENAME, } from './variables.js'; -import { Storage } from '@google/gemini-cli-core'; +import { Storage, homedir } from '@google/gemini-cli-core'; export class ExtensionStorage { private readonly extensionName: string; @@ -36,7 +36,7 @@ export class ExtensionStorage { } static getUserExtensionsDir(): string { - return new Storage(os.homedir()).getExtensionsDir(); + return new Storage(homedir()).getExtensionsDir(); } static async createTmpDir(): Promise { diff --git a/packages/cli/src/config/settings.ts b/packages/cli/src/config/settings.ts index 5cba3dd637..1389430f29 100644 --- a/packages/cli/src/config/settings.ts +++ b/packages/cli/src/config/settings.ts @@ -6,7 +6,7 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; -import { homedir, platform } from 'node:os'; +import { platform } from 'node:os'; import * as dotenv from 'dotenv'; import process from 'node:process'; import { @@ -16,6 +16,7 @@ import { getErrorMessage, Storage, coreEvents, + homedir, } from '@google/gemini-cli-core'; import stripJsonComments from 'strip-json-comments'; import { DefaultLight } from '../ui/themes/default-light.js'; diff --git a/packages/cli/src/config/settings_validation_warning.test.ts b/packages/cli/src/config/settings_validation_warning.test.ts index 67212bf0bc..498f803dd9 100644 --- a/packages/cli/src/config/settings_validation_warning.test.ts +++ b/packages/cli/src/config/settings_validation_warning.test.ts @@ -27,6 +27,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { return { ...actual, coreEvents: mockCoreEvents, + homedir: () => '/mock/home/user', Storage: class extends actual.Storage { static override getGlobalSettingsPath = () => '/mock/home/user/.gemini/settings.json'; @@ -52,11 +53,15 @@ vi.mock('./trustedFolders.js', () => ({ }, })); -vi.mock('os', () => ({ - homedir: () => '/mock/home/user', - platform: () => 'linux', - totalmem: () => 16 * 1024 * 1024 * 1024, -})); +vi.mock('os', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + homedir: () => '/mock/home/user', + platform: () => 'linux', + totalmem: () => 16 * 1024 * 1024 * 1024, + }; +}); vi.mock('fs', async (importOriginal) => { const actualFs = await importOriginal(); diff --git a/packages/cli/src/config/trustedFolders.test.ts b/packages/cli/src/config/trustedFolders.test.ts index 436e300957..9bd4cef9f6 100644 --- a/packages/cli/src/config/trustedFolders.test.ts +++ b/packages/cli/src/config/trustedFolders.test.ts @@ -36,6 +36,15 @@ vi.mock('os', async (importOriginal) => { platform: vi.fn(() => 'linux'), }; }); + +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + homedir: () => '/mock/home/user', + }; +}); vi.mock('fs', async (importOriginal) => { const actualFs = await importOriginal(); return { diff --git a/packages/cli/src/config/trustedFolders.ts b/packages/cli/src/config/trustedFolders.ts index 9a894c76cb..3057a7d3ec 100644 --- a/packages/cli/src/config/trustedFolders.ts +++ b/packages/cli/src/config/trustedFolders.ts @@ -6,13 +6,13 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; -import { homedir } from 'node:os'; import { FatalConfigError, getErrorMessage, isWithinRoot, ideContextStore, GEMINI_DIR, + homedir, } from '@google/gemini-cli-core'; import type { Settings } from './settings.js'; import stripJsonComments from 'strip-json-comments'; diff --git a/packages/cli/src/ui/components/Notifications.test.tsx b/packages/cli/src/ui/components/Notifications.test.tsx index 6e0c178e86..0e04799cba 100644 --- a/packages/cli/src/ui/components/Notifications.test.tsx +++ b/packages/cli/src/ui/components/Notifications.test.tsx @@ -48,6 +48,7 @@ vi.mock('node:path', async () => { vi.mock('@google/gemini-cli-core', () => ({ GEMINI_DIR: '.gemini', + homedir: () => '/mock/home', Storage: { getGlobalTempDir: () => '/mock/temp', }, diff --git a/packages/cli/src/ui/components/Notifications.tsx b/packages/cli/src/ui/components/Notifications.tsx index f36e9708fc..460d03f88b 100644 --- a/packages/cli/src/ui/components/Notifications.tsx +++ b/packages/cli/src/ui/components/Notifications.tsx @@ -12,13 +12,17 @@ import { theme } from '../semantic-colors.js'; import { StreamingState } from '../types.js'; import { UpdateNotification } from './UpdateNotification.js'; -import { GEMINI_DIR, Storage, debugLogger } from '@google/gemini-cli-core'; +import { + GEMINI_DIR, + Storage, + debugLogger, + homedir, +} from '@google/gemini-cli-core'; import * as fs from 'node:fs/promises'; -import os from 'node:os'; import path from 'node:path'; -const settingsPath = path.join(os.homedir(), GEMINI_DIR, 'settings.json'); +const settingsPath = path.join(homedir(), GEMINI_DIR, 'settings.json'); const screenReaderNudgeFilePath = path.join( Storage.getGlobalTempDir(), diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.tsx b/packages/cli/src/ui/hooks/slashCommandProcessor.test.tsx index 476a414717..d9831952b4 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.tsx +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.tsx @@ -74,6 +74,7 @@ vi.mock('node:process', () => { exit: mockProcessExit, platform: 'sunos', cwd: () => '/fake/dir', + env: {}, } as unknown as NodeJS.Process; return { ...mockProcess, diff --git a/packages/cli/src/ui/hooks/useExtensionUpdates.test.tsx b/packages/cli/src/ui/hooks/useExtensionUpdates.test.tsx index ae19a1fc55..5e78f4c4d6 100644 --- a/packages/cli/src/ui/hooks/useExtensionUpdates.test.tsx +++ b/packages/cli/src/ui/hooks/useExtensionUpdates.test.tsx @@ -30,6 +30,15 @@ vi.mock('os', async (importOriginal) => { }; }); +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + homedir: () => os.homedir(), + }; +}); + vi.mock('../../config/extensions/update.js', () => ({ checkForAllExtensionUpdates: vi.fn(), updateExtension: vi.fn(), diff --git a/packages/cli/src/ui/hooks/usePermissionsModifyTrust.test.ts b/packages/cli/src/ui/hooks/usePermissionsModifyTrust.test.ts index cc69d14eca..84e00cae15 100644 --- a/packages/cli/src/ui/hooks/usePermissionsModifyTrust.test.ts +++ b/packages/cli/src/ui/hooks/usePermissionsModifyTrust.test.ts @@ -28,9 +28,16 @@ const mockedIsWorkspaceTrusted = vi.hoisted(() => vi.fn()); const mockedUseSettings = vi.hoisted(() => vi.fn()); // Mock modules -vi.mock('node:process', () => ({ - cwd: mockedCwd, -})); +vi.mock('node:process', () => { + const mockProcess = { + cwd: mockedCwd, + env: {}, + }; + return { + ...mockProcess, + default: mockProcess, + }; +}); vi.mock('node:path', async (importOriginal) => { const actual = await importOriginal(); diff --git a/packages/cli/src/ui/themes/theme-manager.test.ts b/packages/cli/src/ui/themes/theme-manager.test.ts index 60d69ef7f9..02ef4ff633 100644 --- a/packages/cli/src/ui/themes/theme-manager.test.ts +++ b/packages/cli/src/ui/themes/theme-manager.test.ts @@ -27,6 +27,15 @@ vi.mock('node:os', async (importOriginal) => { }; }); +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + homedir: () => os.homedir(), + }; +}); + const validCustomTheme: CustomTheme = { type: 'custom', name: 'MyCustomTheme', diff --git a/packages/cli/src/ui/themes/theme-manager.ts b/packages/cli/src/ui/themes/theme-manager.ts index 9a1e6af7d4..ef67f7fc25 100644 --- a/packages/cli/src/ui/themes/theme-manager.ts +++ b/packages/cli/src/ui/themes/theme-manager.ts @@ -18,7 +18,6 @@ import { ShadesOfPurple } from './shades-of-purple.js'; import { XCode } from './xcode.js'; import * as fs from 'node:fs'; import * as path from 'node:path'; -import * as os from 'node:os'; import type { Theme, ThemeType, CustomTheme } from './theme.js'; import { createCustomTheme, validateCustomTheme } from './theme.js'; import type { SemanticColors } from './semantic-tokens.js'; @@ -26,7 +25,7 @@ import { ANSI } from './ansi.js'; import { ANSILight } from './ansi-light.js'; import { NoColorTheme } from './no-color.js'; import process from 'node:process'; -import { debugLogger } from '@google/gemini-cli-core'; +import { debugLogger, homedir } from '@google/gemini-cli-core'; export interface ThemeDisplay { name: string; @@ -255,7 +254,7 @@ class ThemeManager { } // 2. Perform security check. - const homeDir = path.resolve(os.homedir()); + const homeDir = path.resolve(homedir()); if (!canonicalPath.startsWith(homeDir)) { debugLogger.warn( `Theme file at "${themePath}" is outside your home directory. ` + diff --git a/packages/cli/src/ui/utils/directoryUtils.test.ts b/packages/cli/src/ui/utils/directoryUtils.test.ts index b001ece22c..eaf50005d0 100644 --- a/packages/cli/src/ui/utils/directoryUtils.test.ts +++ b/packages/cli/src/ui/utils/directoryUtils.test.ts @@ -16,6 +16,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { await importOriginal(); return { ...original, + homedir: () => mockHomeDir, loadServerHierarchicalMemory: vi.fn().mockResolvedValue({ memoryContent: 'mock memory', fileCount: 10, diff --git a/packages/cli/src/ui/utils/directoryUtils.ts b/packages/cli/src/ui/utils/directoryUtils.ts index 084052525b..e293243989 100644 --- a/packages/cli/src/ui/utils/directoryUtils.ts +++ b/packages/cli/src/ui/utils/directoryUtils.ts @@ -4,10 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -import * as os from 'node:os'; import * as path from 'node:path'; import * as fs from 'node:fs'; import { opendir } from 'node:fs/promises'; +import { homedir } from '@google/gemini-cli-core'; const MAX_SUGGESTIONS = 50; const MATCH_BUFFER_MULTIPLIER = 3; @@ -18,9 +18,9 @@ export function expandHomeDir(p: string): string { } let expandedPath = p; if (p.toLowerCase().startsWith('%userprofile%')) { - expandedPath = os.homedir() + p.substring('%userprofile%'.length); + expandedPath = homedir() + p.substring('%userprofile%'.length); } else if (p === '~' || p.startsWith('~/')) { - expandedPath = os.homedir() + p.substring(1); + expandedPath = homedir() + p.substring(1); } return path.normalize(expandedPath); } @@ -56,7 +56,7 @@ function parsePartialPath(partialPath: string): ParsedPath { !partialPath.includes('/') && !partialPath.includes(path.sep) ) { - searchDir = os.homedir(); + searchDir = homedir(); filter = partialPath.substring(1); } } diff --git a/packages/cli/src/ui/utils/terminalSetup.test.ts b/packages/cli/src/ui/utils/terminalSetup.test.ts index 6a4c3d85ec..a6f7b290a7 100644 --- a/packages/cli/src/ui/utils/terminalSetup.test.ts +++ b/packages/cli/src/ui/utils/terminalSetup.test.ts @@ -42,6 +42,15 @@ vi.mock('node:os', () => ({ platform: mocks.platform, })); +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + homedir: mocks.homedir, + }; +}); + vi.mock('./terminalCapabilityManager.js', () => ({ terminalCapabilityManager: { isKittyProtocolEnabled: vi.fn().mockReturnValue(false), diff --git a/packages/cli/src/ui/utils/terminalSetup.ts b/packages/cli/src/ui/utils/terminalSetup.ts index a66b6a19f4..9fb81099bb 100644 --- a/packages/cli/src/ui/utils/terminalSetup.ts +++ b/packages/cli/src/ui/utils/terminalSetup.ts @@ -30,7 +30,7 @@ import { exec } from 'node:child_process'; import { promisify } from 'node:util'; import { terminalCapabilityManager } from './terminalCapabilityManager.js'; -import { debugLogger } from '@google/gemini-cli-core'; +import { debugLogger, homedir } from '@google/gemini-cli-core'; export const VSCODE_SHIFT_ENTER_SEQUENCE = '\\\r\n'; @@ -124,7 +124,7 @@ function getVSCodeStyleConfigDir(appName: string): string | null { if (platform === 'darwin') { return path.join( - os.homedir(), + homedir(), 'Library', 'Application Support', appName, @@ -136,7 +136,7 @@ function getVSCodeStyleConfigDir(appName: string): string | null { } return path.join(process.env['APPDATA'], appName, 'User'); } else { - return path.join(os.homedir(), '.config', appName, 'User'); + return path.join(homedir(), '.config', appName, 'User'); } } diff --git a/packages/cli/src/utils/resolvePath.test.ts b/packages/cli/src/utils/resolvePath.test.ts index 9f4b8d0b24..949ccea59a 100644 --- a/packages/cli/src/utils/resolvePath.test.ts +++ b/packages/cli/src/utils/resolvePath.test.ts @@ -13,6 +13,10 @@ vi.mock('node:os', () => ({ homedir: vi.fn(), })); +vi.mock('@google/gemini-cli-core', () => ({ + homedir: () => os.homedir(), +})); + describe('resolvePath', () => { beforeEach(() => { vi.mocked(os.homedir).mockReturnValue('/home/user'); diff --git a/packages/cli/src/utils/resolvePath.ts b/packages/cli/src/utils/resolvePath.ts index dea8be55ae..14d5f77cbb 100644 --- a/packages/cli/src/utils/resolvePath.ts +++ b/packages/cli/src/utils/resolvePath.ts @@ -4,8 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import * as os from 'node:os'; import * as path from 'node:path'; +import { homedir } from '@google/gemini-cli-core'; export function resolvePath(p: string): string { if (!p) { @@ -13,9 +13,9 @@ export function resolvePath(p: string): string { } let expandedPath = p; if (p.toLowerCase().startsWith('%userprofile%')) { - expandedPath = os.homedir() + p.substring('%userprofile%'.length); + expandedPath = homedir() + p.substring('%userprofile%'.length); } else if (p === '~' || p.startsWith('~/')) { - expandedPath = os.homedir() + p.substring(1); + expandedPath = homedir() + p.substring(1); } return path.normalize(expandedPath); } diff --git a/packages/cli/src/utils/sandbox.test.ts b/packages/cli/src/utils/sandbox.test.ts index ed04ee80e5..9f59ca008c 100644 --- a/packages/cli/src/utils/sandbox.test.ts +++ b/packages/cli/src/utils/sandbox.test.ts @@ -12,9 +12,19 @@ import { start_sandbox } from './sandbox.js'; import { FatalSandboxError, type SandboxConfig } from '@google/gemini-cli-core'; import { EventEmitter } from 'node:events'; -vi.mock('../config/settings.js', () => ({ - USER_SETTINGS_DIR: '/home/user/.gemini', +const { mockedHomedir, mockedGetContainerPath } = vi.hoisted(() => ({ + mockedHomedir: vi.fn().mockReturnValue('/home/user'), + mockedGetContainerPath: vi.fn().mockImplementation((p: string) => p), })); + +vi.mock('./sandboxUtils.js', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + getContainerPath: mockedGetContainerPath, + }; +}); + vi.mock('node:child_process'); vi.mock('node:os'); vi.mock('node:fs'); @@ -44,6 +54,7 @@ vi.mock('node:util', async (importOriginal) => { }, }; }); + vi.mock('@google/gemini-cli-core', async (importOriginal) => { const actual = await importOriginal(); @@ -64,7 +75,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { } }, GEMINI_DIR: '.gemini', - USER_SETTINGS_DIR: '/home/user/.gemini', + homedir: mockedHomedir, }; }); @@ -341,13 +352,23 @@ describe('sandbox', () => { await start_sandbox(config); - expect(spawn).toHaveBeenCalledWith( + // The first call is 'docker images -q ...' + expect(spawn).toHaveBeenNthCalledWith( + 1, + 'docker', + expect.arrayContaining(['images', '-q']), + ); + + // The second call is 'docker run ...' + expect(spawn).toHaveBeenNthCalledWith( + 2, 'docker', expect.arrayContaining([ + 'run', '--volume', '/host/path:/container/path:ro', '--volume', - expect.stringContaining('/home/user/.gemini'), + expect.stringMatching(/[\\/]home[\\/]user[\\/]\.gemini/), ]), expect.any(Object), ); diff --git a/packages/cli/src/utils/sandbox.ts b/packages/cli/src/utils/sandbox.ts index c05f2cf3a4..2edadae2ad 100644 --- a/packages/cli/src/utils/sandbox.ts +++ b/packages/cli/src/utils/sandbox.ts @@ -5,12 +5,11 @@ */ import { exec, execSync, spawn, type ChildProcess } from 'node:child_process'; -import os from 'node:os'; import path from 'node:path'; import fs from 'node:fs'; +import os from 'node:os'; import { fileURLToPath } from 'node:url'; import { quote, parse } from 'shell-quote'; -import { USER_SETTINGS_DIR } from '../config/settings.js'; import { promisify } from 'node:util'; import type { Config, SandboxConfig } from '@google/gemini-cli-core'; import { @@ -18,6 +17,7 @@ import { debugLogger, FatalSandboxError, GEMINI_DIR, + homedir, } from '@google/gemini-cli-core'; import { ConsolePatcher } from '../ui/utils/ConsolePatcher.js'; import { randomBytes } from 'node:crypto'; @@ -82,7 +82,7 @@ export async function start_sandbox( '-D', `TMP_DIR=${fs.realpathSync(os.tmpdir())}`, '-D', - `HOME_DIR=${fs.realpathSync(os.homedir())}`, + `HOME_DIR=${fs.realpathSync(homedir())}`, '-D', `CACHE_DIR=${fs.realpathSync((await execAsync('getconf DARWIN_USER_CACHE_DIR')).stdout.trim())}`, ]; @@ -288,18 +288,23 @@ export async function start_sandbox( // mount user settings directory inside container, after creating if missing // note user/home changes inside sandbox and we mount at BOTH paths for consistency - const userSettingsDirOnHost = USER_SETTINGS_DIR; + const userHomeDirOnHost = homedir(); const userSettingsDirInSandbox = getContainerPath( `/home/node/${GEMINI_DIR}`, ); - if (!fs.existsSync(userSettingsDirOnHost)) { - fs.mkdirSync(userSettingsDirOnHost); + if (!fs.existsSync(userHomeDirOnHost)) { + fs.mkdirSync(userHomeDirOnHost, { recursive: true }); } + const userSettingsDirOnHost = path.join(userHomeDirOnHost, GEMINI_DIR); + if (!fs.existsSync(userSettingsDirOnHost)) { + fs.mkdirSync(userSettingsDirOnHost, { recursive: true }); + } + args.push( '--volume', `${userSettingsDirOnHost}:${userSettingsDirInSandbox}`, ); - if (userSettingsDirInSandbox !== userSettingsDirOnHost) { + if (userSettingsDirInSandbox !== getContainerPath(userSettingsDirOnHost)) { args.push( '--volume', `${userSettingsDirOnHost}:${getContainerPath(userSettingsDirOnHost)}`, @@ -309,8 +314,16 @@ export async function start_sandbox( // mount os.tmpdir() as os.tmpdir() inside container args.push('--volume', `${os.tmpdir()}:${getContainerPath(os.tmpdir())}`); + // mount homedir() as homedir() inside container + if (userHomeDirOnHost !== os.homedir()) { + args.push( + '--volume', + `${userHomeDirOnHost}:${getContainerPath(userHomeDirOnHost)}`, + ); + } + // mount gcloud config directory if it exists - const gcloudConfigDir = path.join(os.homedir(), '.config', 'gcloud'); + const gcloudConfigDir = path.join(homedir(), '.config', 'gcloud'); if (fs.existsSync(gcloudConfigDir)) { args.push( '--volume', @@ -585,7 +598,7 @@ export async function start_sandbox( // necessary on Linux to ensure the user exists within the // container's /etc/passwd file, which is required by os.userInfo(). const username = 'gemini'; - const homeDir = getContainerPath(os.homedir()); + const homeDir = getContainerPath(homedir()); const setupUserCommands = [ // Use -f with groupadd to avoid errors if the group already exists. @@ -606,7 +619,7 @@ export async function start_sandbox( // We still need userFlag for the simpler proxy container, which does not have this issue. userFlag = `--user ${uid}:${gid}`; // When forcing a UID in the sandbox, $HOME can be reset to '/', so we copy $HOME as well. - args.push('--env', `HOME=${os.homedir()}`); + args.push('--env', `HOME=${homedir()}`); } // push container image name diff --git a/packages/cli/src/utils/userStartupWarnings.test.ts b/packages/cli/src/utils/userStartupWarnings.test.ts index 5f87f286ce..0a9f957617 100644 --- a/packages/cli/src/utils/userStartupWarnings.test.ts +++ b/packages/cli/src/utils/userStartupWarnings.test.ts @@ -19,6 +19,15 @@ vi.mock('os', async (importOriginal) => { }; }); +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + homedir: () => os.homedir(), + }; +}); + describe('getUserStartupWarnings', () => { let testRootDir: string; let homeDir: string; diff --git a/packages/cli/src/utils/userStartupWarnings.ts b/packages/cli/src/utils/userStartupWarnings.ts index d355290789..37a5dd49cd 100644 --- a/packages/cli/src/utils/userStartupWarnings.ts +++ b/packages/cli/src/utils/userStartupWarnings.ts @@ -5,8 +5,9 @@ */ import fs from 'node:fs/promises'; -import * as os from 'node:os'; import path from 'node:path'; +import process from 'node:process'; +import { homedir } from '@google/gemini-cli-core'; type WarningCheck = { id: string; @@ -20,7 +21,7 @@ const homeDirectoryCheck: WarningCheck = { try { const [workspaceRealPath, homeRealPath] = await Promise.all([ fs.realpath(workspaceRoot), - fs.realpath(os.homedir()), + fs.realpath(homedir()), ]); if (workspaceRealPath === homeRealPath) { diff --git a/packages/core/src/code_assist/oauth-credential-storage.ts b/packages/core/src/code_assist/oauth-credential-storage.ts index 2f1c78d1df..149f53b97f 100644 --- a/packages/core/src/code_assist/oauth-credential-storage.ts +++ b/packages/core/src/code_assist/oauth-credential-storage.ts @@ -9,9 +9,8 @@ import { HybridTokenStorage } from '../mcp/token-storage/hybrid-token-storage.js import { OAUTH_FILE } from '../config/storage.js'; import type { OAuthCredentials } from '../mcp/token-storage/types.js'; import * as path from 'node:path'; -import * as os from 'node:os'; import { promises as fs } from 'node:fs'; -import { GEMINI_DIR } from '../utils/paths.js'; +import { GEMINI_DIR, homedir } from '../utils/paths.js'; import { coreEvents } from '../utils/events.js'; const KEYCHAIN_SERVICE_NAME = 'gemini-cli-oauth'; @@ -91,7 +90,7 @@ export class OAuthCredentialStorage { await this.storage.deleteCredentials(MAIN_ACCOUNT_KEY); // Also try to remove the old file if it exists - const oldFilePath = path.join(os.homedir(), GEMINI_DIR, OAUTH_FILE); + const oldFilePath = path.join(homedir(), GEMINI_DIR, OAUTH_FILE); await fs.rm(oldFilePath, { force: true }).catch(() => {}); } catch (error: unknown) { coreEvents.emitFeedback( @@ -107,7 +106,7 @@ export class OAuthCredentialStorage { * Migrate credentials from old file-based storage to keychain */ private static async migrateFromFileStorage(): Promise { - const oldFilePath = path.join(os.homedir(), GEMINI_DIR, OAUTH_FILE); + const oldFilePath = path.join(homedir(), GEMINI_DIR, OAUTH_FILE); let credsJson: string; try { diff --git a/packages/core/src/code_assist/oauth2.test.ts b/packages/core/src/code_assist/oauth2.test.ts index 50a7f07a67..0da2106db5 100644 --- a/packages/core/src/code_assist/oauth2.test.ts +++ b/packages/core/src/code_assist/oauth2.test.ts @@ -26,16 +26,24 @@ import { AuthType } from '../core/contentGenerator.js'; import type { Config } from '../config/config.js'; import readline from 'node:readline'; import { FORCE_ENCRYPTED_FILE_ENV_VAR } from '../mcp/token-storage/index.js'; -import { GEMINI_DIR } from '../utils/paths.js'; +import { GEMINI_DIR, homedir as pathsHomedir } from '../utils/paths.js'; import { debugLogger } from '../utils/debugLogger.js'; import { writeToStdout } from '../utils/stdio.js'; import { FatalCancellationError } from '../utils/errors.js'; import process from 'node:process'; -vi.mock('os', async (importOriginal) => { - const os = await importOriginal(); +vi.mock('node:os', async (importOriginal) => { + const actual = await importOriginal(); return { - ...os, + ...actual, + homedir: vi.fn(), + }; +}); + +vi.mock('../utils/paths.js', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, homedir: vi.fn(), }; }); @@ -89,6 +97,7 @@ describe('oauth2', () => { path.join(os.tmpdir(), 'gemini-cli-test-home-'), ); vi.mocked(os.homedir).mockReturnValue(tempHomeDir); + vi.mocked(pathsHomedir).mockReturnValue(tempHomeDir); }); afterEach(() => { fs.rmSync(tempHomeDir, { recursive: true, force: true }); @@ -1129,15 +1138,10 @@ describe('oauth2', () => { () => mockHttpServer as unknown as http.Server, ); - // Mock process.on to immediately trigger SIGINT + // Mock process.on to capture SIGINT handler const processOnSpy = vi .spyOn(process, 'on') - .mockImplementation((event, listener: () => void) => { - if (event === 'SIGINT') { - listener(); - } - return process; - }); + .mockImplementation(() => process); const processRemoveListenerSpy = vi.spyOn(process, 'removeListener'); @@ -1146,6 +1150,24 @@ describe('oauth2', () => { mockConfig, ); + // Wait for the SIGINT handler to be registered + let sigIntHandler: (() => void) | undefined; + await vi.waitFor(() => { + const sigintCall = processOnSpy.mock.calls.find( + (call) => call[0] === 'SIGINT', + ); + sigIntHandler = sigintCall?.[1] as (() => void) | undefined; + if (!sigIntHandler) + throw new Error('SIGINT handler not registered yet'); + }); + + expect(sigIntHandler).toBeDefined(); + + // Trigger SIGINT + if (sigIntHandler) { + sigIntHandler(); + } + await expect(clientPromise).rejects.toThrow(FatalCancellationError); expect(processRemoveListenerSpy).toHaveBeenCalledWith( 'SIGINT', @@ -1180,17 +1202,10 @@ describe('oauth2', () => { () => mockHttpServer as unknown as http.Server, ); - // Spy on process.stdin.on and immediately trigger Ctrl+C + // Spy on process.stdin.on to capture data handler const stdinOnSpy = vi .spyOn(process.stdin, 'on') - .mockImplementation( - (event: string, listener: (data: Buffer) => void) => { - if (event === 'data') { - listener(Buffer.from([0x03])); - } - return process.stdin; - }, - ); + .mockImplementation(() => process.stdin); const stdinRemoveListenerSpy = vi.spyOn( process.stdin, @@ -1202,6 +1217,23 @@ describe('oauth2', () => { mockConfig, ); + // Wait for the stdin handler to be registered + let dataHandler: ((data: Buffer) => void) | undefined; + await vi.waitFor(() => { + const dataCall = stdinOnSpy.mock.calls.find( + (call: [string, ...unknown[]]) => call[0] === 'data', + ); + dataHandler = dataCall?.[1] as ((data: Buffer) => void) | undefined; + if (!dataHandler) throw new Error('stdin handler not registered yet'); + }); + + expect(dataHandler).toBeDefined(); + + // Trigger Ctrl+C + if (dataHandler) { + dataHandler(Buffer.from([0x03])); + } + await expect(clientPromise).rejects.toThrow(FatalCancellationError); expect(stdinRemoveListenerSpy).toHaveBeenCalledWith( 'data', @@ -1302,7 +1334,8 @@ describe('oauth2', () => { tempHomeDir = fs.mkdtempSync( path.join(os.tmpdir(), 'gemini-cli-test-home-'), ); - (os.homedir as Mock).mockReturnValue(tempHomeDir); + vi.mocked(os.homedir).mockReturnValue(tempHomeDir); + vi.mocked(pathsHomedir).mockReturnValue(tempHomeDir); }); afterEach(() => { diff --git a/packages/core/src/code_assist/oauth2.ts b/packages/core/src/code_assist/oauth2.ts index 406e054f1e..9b4d2cf079 100644 --- a/packages/core/src/code_assist/oauth2.ts +++ b/packages/core/src/code_assist/oauth2.ts @@ -336,7 +336,7 @@ async function initOauthClient( // Note that SIGINT might not get raised on Ctrl+C in raw mode // so we also need to look for Ctrl+C directly in stdin. - stdinHandler = (data) => { + stdinHandler = (data: Buffer) => { if (data.includes(0x03)) { reject( new FatalCancellationError('Authentication cancelled by user.'), diff --git a/packages/core/src/config/storage.ts b/packages/core/src/config/storage.ts index 7da4aa2a56..bfadc2f7b7 100644 --- a/packages/core/src/config/storage.ts +++ b/packages/core/src/config/storage.ts @@ -8,7 +8,7 @@ import * as path from 'node:path'; import * as os from 'node:os'; import * as crypto from 'node:crypto'; import * as fs from 'node:fs'; -import { GEMINI_DIR } from '../utils/paths.js'; +import { GEMINI_DIR, homedir } from '../utils/paths.js'; export const GOOGLE_ACCOUNTS_FILENAME = 'google_accounts.json'; export const OAUTH_FILE = 'oauth_creds.json'; @@ -23,7 +23,7 @@ export class Storage { } static getGlobalGeminiDir(): string { - const homeDir = os.homedir(); + const homeDir = homedir(); if (!homeDir) { return path.join(os.tmpdir(), GEMINI_DIR); } diff --git a/packages/core/src/core/prompts.ts b/packages/core/src/core/prompts.ts index 6327cd4753..243582494f 100644 --- a/packages/core/src/core/prompts.ts +++ b/packages/core/src/core/prompts.ts @@ -6,7 +6,6 @@ import path from 'node:path'; import fs from 'node:fs'; -import os from 'node:os'; import { EDIT_TOOL_NAME, GLOB_TOOL_NAME, @@ -23,7 +22,7 @@ import process from 'node:process'; import { isGitRepository } from '../utils/gitUtils.js'; import { CodebaseInvestigatorAgent } from '../agents/codebase-investigator.js'; import type { Config } from '../config/config.js'; -import { GEMINI_DIR } from '../utils/paths.js'; +import { GEMINI_DIR, homedir } from '../utils/paths.js'; import { debugLogger } from '../utils/debugLogger.js'; import { WriteTodosTool } from '../tools/write-todos.js'; import { resolveModel, isPreviewModel } from '../config/models.js'; @@ -53,7 +52,7 @@ export function resolvePathFromEnv(envVar?: string): { // Safely expand the tilde (~) character to the user's home directory. if (customPath.startsWith('~/') || customPath === '~') { try { - const home = os.homedir(); // This is the call that can throw an error. + const home = homedir(); // This is the call that can throw an error. if (customPath === '~') { customPath = home; } else { diff --git a/packages/core/src/ide/ide-installer.test.ts b/packages/core/src/ide/ide-installer.test.ts index 4ca07dd419..5f0ab9abb4 100644 --- a/packages/core/src/ide/ide-installer.test.ts +++ b/packages/core/src/ide/ide-installer.test.ts @@ -14,8 +14,15 @@ vi.mock('node:child_process', async (importOriginal) => { spawnSync: vi.fn(() => ({ status: 0 })), }; }); -vi.mock('fs'); -vi.mock('os'); +vi.mock('node:fs'); +vi.mock('node:os'); +vi.mock('../utils/paths.js', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + homedir: vi.fn(), + }; +}); import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { getIdeInstaller } from './ide-installer.js'; @@ -24,12 +31,14 @@ import * as fs from 'node:fs'; import * as os from 'node:os'; import * as path from 'node:path'; import { IDE_DEFINITIONS, type IdeInfo } from './detect-ide.js'; +import { homedir as pathsHomedir } from '../utils/paths.js'; describe('ide-installer', () => { const HOME_DIR = '/home/user'; beforeEach(() => { vi.spyOn(os, 'homedir').mockReturnValue(HOME_DIR); + vi.mocked(pathsHomedir).mockReturnValue(HOME_DIR); }); afterEach(() => { diff --git a/packages/core/src/ide/ide-installer.ts b/packages/core/src/ide/ide-installer.ts index f1fd50fa4d..903e831268 100644 --- a/packages/core/src/ide/ide-installer.ts +++ b/packages/core/src/ide/ide-installer.ts @@ -8,9 +8,9 @@ import * as child_process from 'node:child_process'; import * as process from 'node:process'; import * as path from 'node:path'; import * as fs from 'node:fs'; -import * as os from 'node:os'; import { IDE_DEFINITIONS, type IdeInfo } from './detect-ide.js'; import { GEMINI_CLI_COMPANION_EXTENSION_NAME } from './constants.js'; +import { homedir } from '../utils/paths.js'; export interface IdeInstaller { install(): Promise; @@ -49,7 +49,7 @@ async function findCommand( // 2. Check common installation locations. const locations: string[] = []; - const homeDir = os.homedir(); + const homeDir = homedir(); if (command === 'code' || command === 'code.cmd') { if (platform === 'darwin') { diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index e20ed7f0a5..2f11c4ae71 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -50,6 +50,7 @@ export * from './code_assist/telemetry.js'; export * from './core/apiKeyCredentialStorage.js'; // Export utilities +export { homedir, tmpdir } from './utils/paths.js'; export * from './utils/paths.js'; export * from './utils/schemaValidator.js'; export * from './utils/errors.js'; diff --git a/packages/core/src/mcp/token-storage/file-token-storage.ts b/packages/core/src/mcp/token-storage/file-token-storage.ts index a9e17b60da..7a806de4a1 100644 --- a/packages/core/src/mcp/token-storage/file-token-storage.ts +++ b/packages/core/src/mcp/token-storage/file-token-storage.ts @@ -10,7 +10,7 @@ import * as os from 'node:os'; import * as crypto from 'node:crypto'; import { BaseTokenStorage } from './base-token-storage.js'; import type { OAuthCredentials } from './types.js'; -import { GEMINI_DIR } from '../../utils/paths.js'; +import { GEMINI_DIR, homedir } from '../../utils/paths.js'; export class FileTokenStorage extends BaseTokenStorage { private readonly tokenFilePath: string; @@ -18,7 +18,7 @@ export class FileTokenStorage extends BaseTokenStorage { constructor(serviceName: string) { super(serviceName); - const configDir = path.join(os.homedir(), GEMINI_DIR); + const configDir = path.join(homedir(), GEMINI_DIR); this.tokenFilePath = path.join(configDir, 'mcp-oauth-tokens-v2.json'); this.encryptionKey = this.deriveEncryptionKey(); } diff --git a/packages/core/src/services/gitService.test.ts b/packages/core/src/services/gitService.test.ts index d45dbed407..b3e3975265 100644 --- a/packages/core/src/services/gitService.test.ts +++ b/packages/core/src/services/gitService.test.ts @@ -18,7 +18,11 @@ import { Storage } from '../config/storage.js'; import * as path from 'node:path'; import * as fs from 'node:fs/promises'; import * as os from 'node:os'; -import { getProjectHash, GEMINI_DIR } from '../utils/paths.js'; +import { + getProjectHash, + GEMINI_DIR, + homedir as pathsHomedir, +} from '../utils/paths.js'; import { spawnAsync } from '../utils/shell-utils.js'; vi.mock('../utils/shell-utils.js', () => ({ @@ -52,7 +56,7 @@ vi.mock('../utils/gitUtils.js', () => ({ })); const hoistedMockHomedir = vi.hoisted(() => vi.fn()); -vi.mock('os', async (importOriginal) => { +vi.mock('node:os', async (importOriginal) => { const actual = await importOriginal(); return { ...actual, @@ -60,6 +64,14 @@ vi.mock('os', async (importOriginal) => { }; }); +vi.mock('../utils/paths.js', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + homedir: vi.fn(), + }; +}); + const hoistedMockDebugLogger = vi.hoisted(() => ({ debug: vi.fn(), warn: vi.fn(), @@ -93,6 +105,7 @@ describe('GitService', () => { }); hoistedMockHomedir.mockReturnValue(homedir); + (pathsHomedir as Mock).mockReturnValue(homedir); hoistedMockEnv.mockImplementation(() => ({ checkIsRepo: hoistedMockCheckIsRepo, diff --git a/packages/core/src/utils/installationManager.test.ts b/packages/core/src/utils/installationManager.test.ts index 2b4c586cb4..1cc7f69926 100644 --- a/packages/core/src/utils/installationManager.test.ts +++ b/packages/core/src/utils/installationManager.test.ts @@ -11,7 +11,7 @@ import * as fs from 'node:fs'; import * as os from 'node:os'; import path from 'node:path'; import { randomUUID } from 'node:crypto'; -import { GEMINI_DIR } from './paths.js'; +import { GEMINI_DIR, homedir as pathsHomedir } from './paths.js'; import { debugLogger } from './debugLogger.js'; vi.mock('node:fs', async (importOriginal) => { @@ -23,22 +23,30 @@ vi.mock('node:fs', async (importOriginal) => { } as typeof actual; }); -vi.mock('os', async (importOriginal) => { - const os = await importOriginal(); +vi.mock('node:os', async (importOriginal) => { + const os = await importOriginal(); return { ...os, homedir: vi.fn(), }; }); -vi.mock('crypto', async (importOriginal) => { - const crypto = await importOriginal(); +vi.mock('node:crypto', async (importOriginal) => { + const crypto = await importOriginal(); return { ...crypto, randomUUID: vi.fn(), }; }); +vi.mock('./paths.js', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + homedir: vi.fn(), + }; +}); + describe('InstallationManager', () => { let tempHomeDir: string; let installationManager: InstallationManager; @@ -49,6 +57,7 @@ describe('InstallationManager', () => { tempHomeDir = fs.mkdtempSync( path.join(os.tmpdir(), 'gemini-cli-test-home-'), ); + (pathsHomedir as Mock).mockReturnValue(tempHomeDir); (os.homedir as Mock).mockReturnValue(tempHomeDir); installationManager = new InstallationManager(); }); diff --git a/packages/core/src/utils/memoryDiscovery.test.ts b/packages/core/src/utils/memoryDiscovery.test.ts index 83f19569db..101cf5ad85 100644 --- a/packages/core/src/utils/memoryDiscovery.test.ts +++ b/packages/core/src/utils/memoryDiscovery.test.ts @@ -35,6 +35,16 @@ vi.mock('os', async (importOriginal) => { }; }); +vi.mock('../utils/paths.js', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + homedir: vi.fn(), + }; +}); + +import { homedir as pathsHomedir } from './paths.js'; + describe('memoryDiscovery', () => { const DEFAULT_FOLDER_TRUST = true; let testRootDir: string; @@ -67,6 +77,7 @@ describe('memoryDiscovery', () => { cwd = await createEmptyDir(path.join(projectRoot, 'src')); homedir = await createEmptyDir(path.join(testRootDir, 'userhome')); vi.mocked(os.homedir).mockReturnValue(homedir); + vi.mocked(pathsHomedir).mockReturnValue(homedir); }); afterEach(async () => { diff --git a/packages/core/src/utils/memoryDiscovery.ts b/packages/core/src/utils/memoryDiscovery.ts index 88a6760fe0..4997f543a0 100644 --- a/packages/core/src/utils/memoryDiscovery.ts +++ b/packages/core/src/utils/memoryDiscovery.ts @@ -7,14 +7,13 @@ import * as fs from 'node:fs/promises'; import * as fsSync from 'node:fs'; import * as path from 'node:path'; -import { homedir } from 'node:os'; import { bfsFileSearch } from './bfsFileSearch.js'; import { getAllGeminiMdFilenames } from '../tools/memoryTool.js'; import type { FileDiscoveryService } from '../services/fileDiscoveryService.js'; import { processImports } from './memoryImportProcessor.js'; import type { FileFilteringOptions } from '../config/constants.js'; import { DEFAULT_MEMORY_FILE_FILTERING_OPTIONS } from '../config/constants.js'; -import { GEMINI_DIR } from './paths.js'; +import { GEMINI_DIR, homedir } from './paths.js'; import type { ExtensionLoader } from './extensionLoader.js'; import { debugLogger } from './debugLogger.js'; import type { Config } from '../config/config.js'; diff --git a/packages/core/src/utils/paths.ts b/packages/core/src/utils/paths.ts index c32a3ce9f3..4d14a6d230 100644 --- a/packages/core/src/utils/paths.ts +++ b/packages/core/src/utils/paths.ts @@ -6,6 +6,7 @@ import path from 'node:path'; import os from 'node:os'; +import process from 'node:process'; import * as crypto from 'node:crypto'; export const GEMINI_DIR = '.gemini'; @@ -18,13 +19,33 @@ export const GOOGLE_ACCOUNTS_FILENAME = 'google_accounts.json'; */ export const SHELL_SPECIAL_CHARS = /[ \t()[\]{};|*?$`'"#&<>!~]/; +/** + * Returns the home directory. + * If GEMINI_CLI_HOME environment variable is set, it returns its value. + * Otherwise, it returns the user's home directory. + */ +export function homedir(): string { + const envHome = process.env['GEMINI_CLI_HOME']; + if (envHome) { + return envHome; + } + return os.homedir(); +} + +/** + * Returns the operating system's default directory for temporary files. + */ +export function tmpdir(): string { + return os.tmpdir(); +} + /** * Replaces the home directory with a tilde. * @param path - The path to tildeify. * @returns The tildeified path. */ export function tildeifyPath(path: string): string { - const homeDir = os.homedir(); + const homeDir = homedir(); if (path.startsWith(homeDir)) { return path.replace(homeDir, '~'); } diff --git a/packages/core/src/utils/userAccountManager.test.ts b/packages/core/src/utils/userAccountManager.test.ts index 8b4cb61056..4e970c334f 100644 --- a/packages/core/src/utils/userAccountManager.test.ts +++ b/packages/core/src/utils/userAccountManager.test.ts @@ -10,13 +10,13 @@ import { UserAccountManager } from './userAccountManager.js'; import * as fs from 'node:fs'; import * as os from 'node:os'; import path from 'node:path'; -import { GEMINI_DIR } from './paths.js'; +import { GEMINI_DIR, homedir as pathsHomedir } from './paths.js'; import { debugLogger } from './debugLogger.js'; -vi.mock('os', async (importOriginal) => { - const os = await importOriginal(); +vi.mock('./paths.js', async (importOriginal) => { + const actual = await importOriginal(); return { - ...os, + ...actual, homedir: vi.fn(), }; }); @@ -30,7 +30,7 @@ describe('UserAccountManager', () => { tempHomeDir = fs.mkdtempSync( path.join(os.tmpdir(), 'gemini-cli-test-home-'), ); - (os.homedir as Mock).mockReturnValue(tempHomeDir); + (pathsHomedir as Mock).mockReturnValue(tempHomeDir); accountsFile = () => path.join(tempHomeDir, GEMINI_DIR, 'google_accounts.json'); userAccountManager = new UserAccountManager(); diff --git a/packages/vscode-ide-companion/esbuild.js b/packages/vscode-ide-companion/esbuild.js index 7de7c7ada0..468ba34825 100644 --- a/packages/vscode-ide-companion/esbuild.js +++ b/packages/vscode-ide-companion/esbuild.js @@ -53,7 +53,7 @@ async function main() { /* add to the end of plugins array */ esbuildProblemMatcherPlugin, ], - loader: { '.node': 'file' }, + loader: { '.node': 'file', '.wasm': 'binary' }, }); if (watch) { await ctx.watch(); diff --git a/packages/vscode-ide-companion/src/ide-server.test.ts b/packages/vscode-ide-companion/src/ide-server.test.ts index 95f1c27a63..eb28638a78 100644 --- a/packages/vscode-ide-companion/src/ide-server.test.ts +++ b/packages/vscode-ide-companion/src/ide-server.test.ts @@ -38,6 +38,15 @@ vi.mock('node:os', async (importOriginal) => { }; }); +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + tmpdir: vi.fn(() => '/tmp'), + }; +}); + const vscodeMock = vi.hoisted(() => ({ workspace: { workspaceFolders: [ diff --git a/packages/vscode-ide-companion/src/ide-server.ts b/packages/vscode-ide-companion/src/ide-server.ts index f29bae29fd..4e4ef443f6 100644 --- a/packages/vscode-ide-companion/src/ide-server.ts +++ b/packages/vscode-ide-companion/src/ide-server.ts @@ -23,7 +23,7 @@ import { randomUUID } from 'node:crypto'; import { type Server as HTTPServer } from 'node:http'; import * as path from 'node:path'; import * as fs from 'node:fs/promises'; -import * as os from 'node:os'; +import { tmpdir } from '@google/gemini-cli-core'; import type { z } from 'zod'; import type { DiffManager } from './diff-manager.js'; import { OpenFilesManager } from './open-files-manager.js'; @@ -343,7 +343,7 @@ export class IDEServer { this.log(`IDE server listening on http://127.0.0.1:${this.port}`); let portFile: string | undefined; try { - const portDir = path.join(os.tmpdir(), 'gemini', 'ide'); + const portDir = path.join(tmpdir(), 'gemini', 'ide'); await fs.mkdir(portDir, { recursive: true }); portFile = path.join( portDir, diff --git a/scripts/sandbox_command.js b/scripts/sandbox_command.js index 29fb8a3b17..00becb667f 100644 --- a/scripts/sandbox_command.js +++ b/scripts/sandbox_command.js @@ -33,10 +33,12 @@ const argv = yargs(hideBin(process.argv)).option('q', { default: false, }).argv; +const homedir = () => process.env['GEMINI_CLI_HOME'] || os.homedir(); + let geminiSandbox = process.env.GEMINI_SANDBOX; if (!geminiSandbox) { - const userSettingsFile = join(os.homedir(), GEMINI_DIR, 'settings.json'); + const userSettingsFile = join(homedir(), GEMINI_DIR, 'settings.json'); if (existsSync(userSettingsFile)) { const settings = JSON.parse( stripJsonComments(readFileSync(userSettingsFile, 'utf-8')), diff --git a/scripts/telemetry_utils.js b/scripts/telemetry_utils.js index 1c81b1eb1b..4ab776e964 100644 --- a/scripts/telemetry_utils.js +++ b/scripts/telemetry_utils.js @@ -24,8 +24,11 @@ const projectHash = crypto .update(projectRoot) .digest('hex'); +// Returns the home directory, respecting GEMINI_CLI_HOME +const homedir = () => process.env['GEMINI_CLI_HOME'] || os.homedir(); + // User-level .gemini directory in home -const USER_GEMINI_DIR = path.join(os.homedir(), GEMINI_DIR); +const USER_GEMINI_DIR = path.join(homedir(), GEMINI_DIR); // Project-level .gemini directory in the workspace const WORKSPACE_GEMINI_DIR = path.join(projectRoot, GEMINI_DIR); From 2d683bb6f8a1fd9348fb0c72230981a46ed16d07 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 6 Jan 2026 20:24:29 -0800 Subject: [PATCH 029/713] [Skills] Multi-scope skill enablement and shadowing fix (#15953) --- .../cli/src/commands/skills/enable.test.ts | 63 +++++++++++++--- packages/cli/src/commands/skills/enable.ts | 32 ++------ .../cli/src/ui/commands/skillsCommand.test.ts | 43 ++++++++++- packages/cli/src/ui/commands/skillsCommand.ts | 6 +- packages/cli/src/utils/skillSettings.ts | 74 +++++++++++++------ 5 files changed, 154 insertions(+), 64 deletions(-) diff --git a/packages/cli/src/commands/skills/enable.test.ts b/packages/cli/src/commands/skills/enable.test.ts index 25ef9def67..35c7d5b0f5 100644 --- a/packages/cli/src/commands/skills/enable.test.ts +++ b/packages/cli/src/commands/skills/enable.test.ts @@ -11,7 +11,6 @@ import { loadSettings, SettingScope, type LoadedSettings, - type LoadableSettingScope, } from '../../config/settings.js'; const emitConsoleLog = vi.hoisted(() => vi.fn()); @@ -58,8 +57,14 @@ describe('skills enable command', () => { describe('handleEnable', () => { it('should enable a disabled skill in user scope', async () => { const mockSettings = { - forScope: vi.fn().mockReturnValue({ - settings: { skills: { disabled: ['skill1'] } }, + forScope: vi.fn().mockImplementation((scope) => { + if (scope === SettingScope.User) { + return { + settings: { skills: { disabled: ['skill1'] } }, + path: '/user/settings.json', + }; + } + return { settings: {}, path: '/project/settings.json' }; }), setValue: vi.fn(), }; @@ -67,10 +72,7 @@ describe('skills enable command', () => { mockSettings as unknown as LoadedSettings, ); - await handleEnable({ - name: 'skill1', - scope: SettingScope.User as LoadableSettingScope, - }); + await handleEnable({ name: 'skill1' }); expect(mockSettings.setValue).toHaveBeenCalledWith( SettingScope.User, @@ -79,7 +81,48 @@ describe('skills enable command', () => { ); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" enabled by removing it from the disabled list in user settings.', + 'Skill "skill1" enabled by removing it from the disabled list in user and project settings.', + ); + }); + + it('should enable a skill across multiple scopes', async () => { + const mockSettings = { + forScope: vi.fn().mockImplementation((scope) => { + if (scope === SettingScope.User) { + return { + settings: { skills: { disabled: ['skill1'] } }, + path: '/user/settings.json', + }; + } + if (scope === SettingScope.Workspace) { + return { + settings: { skills: { disabled: ['skill1'] } }, + path: '/workspace/settings.json', + }; + } + return { settings: {}, path: '' }; + }), + setValue: vi.fn(), + }; + mockLoadSettings.mockReturnValue( + mockSettings as unknown as LoadedSettings, + ); + + await handleEnable({ name: 'skill1' }); + + expect(mockSettings.setValue).toHaveBeenCalledWith( + SettingScope.User, + 'skills.disabled', + [], + ); + expect(mockSettings.setValue).toHaveBeenCalledWith( + SettingScope.Workspace, + 'skills.disabled', + [], + ); + expect(emitConsoleLog).toHaveBeenCalledWith( + 'log', + 'Skill "skill1" enabled by removing it from the disabled list in project and user settings.', ); }); @@ -91,11 +134,11 @@ describe('skills enable command', () => { }), setValue: vi.fn(), }; - vi.mocked(loadSettings).mockReturnValue( + mockLoadSettings.mockReturnValue( mockSettings as unknown as LoadedSettings, ); - await handleEnable({ name: 'skill1', scope: SettingScope.User }); + await handleEnable({ name: 'skill1' }); expect(mockSettings.setValue).not.toHaveBeenCalled(); expect(emitConsoleLog).toHaveBeenCalledWith( diff --git a/packages/cli/src/commands/skills/enable.ts b/packages/cli/src/commands/skills/enable.ts index b958a8352f..8bfcaa7c2b 100644 --- a/packages/cli/src/commands/skills/enable.ts +++ b/packages/cli/src/commands/skills/enable.ts @@ -5,11 +5,7 @@ */ import type { CommandModule } from 'yargs'; -import { - loadSettings, - SettingScope, - type LoadableSettingScope, -} from '../../config/settings.js'; +import { loadSettings } from '../../config/settings.js'; import { debugLogger } from '@google/gemini-cli-core'; import { exitCli } from '../utils.js'; import { enableSkill } from '../../utils/skillSettings.js'; @@ -17,15 +13,14 @@ import { renderSkillActionFeedback } from '../../utils/skillUtils.js'; interface EnableArgs { name: string; - scope: LoadableSettingScope; } export async function handleEnable(args: EnableArgs) { - const { name, scope } = args; + const { name } = args; const workspaceDir = process.cwd(); const settings = loadSettings(workspaceDir); - const result = enableSkill(settings, name, scope); + const result = enableSkill(settings, name); debugLogger.log(renderSkillActionFeedback(result, (label, _path) => label)); } @@ -33,25 +28,14 @@ export const enableCommand: CommandModule = { command: 'enable ', describe: 'Enables an agent skill.', builder: (yargs) => - yargs - .positional('name', { - describe: 'The name of the skill to enable.', - type: 'string', - demandOption: true, - }) - .option('scope', { - alias: 's', - describe: 'The scope to enable the skill in (user or project).', - type: 'string', - default: 'user', - choices: ['user', 'project'], - }), + yargs.positional('name', { + describe: 'The name of the skill to enable.', + type: 'string', + demandOption: true, + }), handler: async (argv) => { - const scope: LoadableSettingScope = - argv['scope'] === 'project' ? SettingScope.Workspace : SettingScope.User; await handleEnable({ name: argv['name'] as string, - scope, }); await exitCli(); }, diff --git a/packages/cli/src/ui/commands/skillsCommand.test.ts b/packages/cli/src/ui/commands/skillsCommand.test.ts index 32f3f58053..511effd0b6 100644 --- a/packages/cli/src/ui/commands/skillsCommand.test.ts +++ b/packages/cli/src/ui/commands/skillsCommand.test.ts @@ -193,7 +193,6 @@ describe('skillsCommand', () => { (s) => s.name === 'enable', )!; context.services.settings.merged.skills = { disabled: ['skill1'] }; - // Also need to mock the scope-specific disabled list ( context.services.settings as unknown as { workspace: { settings: { skills: { disabled: string[] } } }; @@ -212,7 +211,47 @@ describe('skillsCommand', () => { expect(context.ui.addItem).toHaveBeenCalledWith( expect.objectContaining({ type: MessageType.INFO, - text: 'Skill "skill1" enabled by removing it from the disabled list in project settings. Use "/skills reload" for it to take effect.', + text: 'Skill "skill1" enabled by removing it from the disabled list in project and user settings. Use "/skills reload" for it to take effect.', + }), + expect.any(Number), + ); + }); + + it('should enable a skill across multiple scopes', async () => { + const enableCmd = skillsCommand.subCommands!.find( + (s) => s.name === 'enable', + )!; + ( + context.services.settings as unknown as { + user: { settings: { skills: { disabled: string[] } } }; + } + ).user.settings = { + skills: { disabled: ['skill1'] }, + }; + ( + context.services.settings as unknown as { + workspace: { settings: { skills: { disabled: string[] } } }; + } + ).workspace.settings = { + skills: { disabled: ['skill1'] }, + }; + + await enableCmd.action!(context, 'skill1'); + + expect(context.services.settings.setValue).toHaveBeenCalledWith( + SettingScope.User, + 'skills.disabled', + [], + ); + expect(context.services.settings.setValue).toHaveBeenCalledWith( + SettingScope.Workspace, + 'skills.disabled', + [], + ); + expect(context.ui.addItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.INFO, + text: 'Skill "skill1" enabled by removing it from the disabled list in project and user settings. Use "/skills reload" for it to take effect.', }), expect.any(Number), ); diff --git a/packages/cli/src/ui/commands/skillsCommand.ts b/packages/cli/src/ui/commands/skillsCommand.ts index c861a404a5..35a41f461b 100644 --- a/packages/cli/src/ui/commands/skillsCommand.ts +++ b/packages/cli/src/ui/commands/skillsCommand.ts @@ -127,11 +127,7 @@ async function enableAction( return; } - const scope = context.services.settings.workspace.path - ? SettingScope.Workspace - : SettingScope.User; - - const result = enableSkill(context.services.settings, skillName, scope); + const result = enableSkill(context.services.settings, skillName); let feedback = renderSkillActionFeedback( result, diff --git a/packages/cli/src/utils/skillSettings.ts b/packages/cli/src/utils/skillSettings.ts index 9a2c3cb5a4..78921b7219 100644 --- a/packages/cli/src/utils/skillSettings.ts +++ b/packages/cli/src/utils/skillSettings.ts @@ -5,8 +5,8 @@ */ import { + SettingScope, isLoadableSettingScope, - type SettingScope, type LoadedSettings, } from '../config/settings.js'; @@ -33,47 +33,57 @@ export interface SkillActionResult { } /** - * Enables a skill by removing it from the specified disabled list. + * Enables a skill by removing it from all writable disabled lists (User and Workspace). */ export function enableSkill( settings: LoadedSettings, skillName: string, - scope: SettingScope, ): SkillActionResult { - if (!isLoadableSettingScope(scope)) { - return { - status: 'error', - skillName, - action: 'enable', - modifiedScopes: [], - alreadyInStateScopes: [], - error: `Invalid settings scope: ${scope}`, - }; + const writableScopes = [SettingScope.Workspace, SettingScope.User]; + const foundInDisabledScopes: ModifiedScope[] = []; + const alreadyEnabledScopes: ModifiedScope[] = []; + + for (const scope of writableScopes) { + if (isLoadableSettingScope(scope)) { + const scopePath = settings.forScope(scope).path; + const scopeDisabled = settings.forScope(scope).settings.skills?.disabled; + if (scopeDisabled?.includes(skillName)) { + foundInDisabledScopes.push({ scope, path: scopePath }); + } else { + alreadyEnabledScopes.push({ scope, path: scopePath }); + } + } } - const scopePath = settings.forScope(scope).path; - const currentScopeDisabled = - settings.forScope(scope).settings.skills?.disabled ?? []; - - if (!currentScopeDisabled.includes(skillName)) { + if (foundInDisabledScopes.length === 0) { return { status: 'no-op', skillName, action: 'enable', modifiedScopes: [], - alreadyInStateScopes: [{ scope, path: scopePath }], + alreadyInStateScopes: alreadyEnabledScopes, }; } - const newDisabled = currentScopeDisabled.filter((name) => name !== skillName); - settings.setValue(scope, 'skills.disabled', newDisabled); + const modifiedScopes: ModifiedScope[] = []; + for (const { scope, path } of foundInDisabledScopes) { + if (isLoadableSettingScope(scope)) { + const currentScopeDisabled = + settings.forScope(scope).settings.skills?.disabled ?? []; + const newDisabled = currentScopeDisabled.filter( + (name) => name !== skillName, + ); + settings.setValue(scope, 'skills.disabled', newDisabled); + modifiedScopes.push({ scope, path }); + } + } return { status: 'success', skillName, action: 'enable', - modifiedScopes: [{ scope, path: scopePath }], - alreadyInStateScopes: [], + modifiedScopes, + alreadyInStateScopes: alreadyEnabledScopes, }; } @@ -110,6 +120,24 @@ export function disableSkill( }; } + // Check if it's already disabled in the other writable scope + const otherScope = + scope === SettingScope.Workspace + ? SettingScope.User + : SettingScope.Workspace; + const alreadyDisabledInOther: ModifiedScope[] = []; + + if (isLoadableSettingScope(otherScope)) { + const otherScopeDisabled = + settings.forScope(otherScope).settings.skills?.disabled; + if (otherScopeDisabled?.includes(skillName)) { + alreadyDisabledInOther.push({ + scope: otherScope, + path: settings.forScope(otherScope).path, + }); + } + } + const newDisabled = [...currentScopeDisabled, skillName]; settings.setValue(scope, 'skills.disabled', newDisabled); @@ -118,6 +146,6 @@ export function disableSkill( skillName, action: 'disable', modifiedScopes: [{ scope, path: scopePath }], - alreadyInStateScopes: [], + alreadyInStateScopes: alreadyDisabledInOther, }; } From 5fe5d1da4678c21e18749981b7c511c3ec1f1ff9 Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Tue, 6 Jan 2026 23:28:06 -0500 Subject: [PATCH 030/713] policy: extract legacy policy from core tool scheduler to policy engine (#15902) --- .../a2a-server/src/utils/testing_utils.ts | 12 + .../prompt-processors/shellProcessor.test.ts | 197 ++++--- .../prompt-processors/shellProcessor.ts | 34 +- .../cli/src/ui/hooks/useToolScheduler.test.ts | 11 +- packages/core/src/config/config.ts | 4 +- .../core/src/core/coreToolScheduler.test.ts | 47 +- packages/core/src/core/coreToolScheduler.ts | 63 +- .../core/nonInteractiveToolExecutor.test.ts | 5 +- packages/core/src/index.ts | 3 +- packages/core/src/policy/persistence.test.ts | 2 +- .../core/src/policy/policy-updater.test.ts | 6 +- packages/core/src/policy/utils.test.ts | 45 +- packages/core/src/policy/utils.ts | 5 +- packages/core/src/tools/tool-error.ts | 4 + .../core/src/utils/shell-permissions.test.ts | 551 ------------------ packages/core/src/utils/shell-permissions.ts | 270 --------- 16 files changed, 286 insertions(+), 973 deletions(-) delete mode 100644 packages/core/src/utils/shell-permissions.test.ts delete mode 100644 packages/core/src/utils/shell-permissions.ts diff --git a/packages/a2a-server/src/utils/testing_utils.ts b/packages/a2a-server/src/utils/testing_utils.ts index d472b4f995..87c7315f82 100644 --- a/packages/a2a-server/src/utils/testing_utils.ts +++ b/packages/a2a-server/src/utils/testing_utils.ts @@ -16,6 +16,7 @@ import { DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD, GeminiClient, HookSystem, + PolicyDecision, } from '@google/gemini-cli-core'; import { createMockMessageBus } from '@google/gemini-cli-core/src/test-utils/mock-message-bus.js'; import type { Config, Storage } from '@google/gemini-cli-core'; @@ -77,6 +78,17 @@ export function createMockConfig( mockConfig.getGeminiClient = vi .fn() .mockReturnValue(new GeminiClient(mockConfig)); + + mockConfig.getPolicyEngine = vi.fn().mockReturnValue({ + check: async () => { + const mode = mockConfig.getApprovalMode(); + if (mode === ApprovalMode.YOLO) { + return { decision: PolicyDecision.ALLOW }; + } + return { decision: PolicyDecision.ASK_USER }; + }, + }); + return mockConfig; } diff --git a/packages/cli/src/services/prompt-processors/shellProcessor.test.ts b/packages/cli/src/services/prompt-processors/shellProcessor.test.ts index 2c93ecf8c0..0f6fb562a8 100644 --- a/packages/cli/src/services/prompt-processors/shellProcessor.test.ts +++ b/packages/cli/src/services/prompt-processors/shellProcessor.test.ts @@ -9,7 +9,11 @@ import { ConfirmationRequiredError, ShellProcessor } from './shellProcessor.js'; import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; import type { CommandContext } from '../../ui/commands/types.js'; import type { Config } from '@google/gemini-cli-core'; -import { ApprovalMode, getShellConfiguration } from '@google/gemini-cli-core'; +import { + ApprovalMode, + getShellConfiguration, + PolicyDecision, +} from '@google/gemini-cli-core'; import { quote } from 'shell-quote'; import { createPartFromText } from '@google/genai'; import type { PromptPipelineContent } from './types.js'; @@ -60,15 +64,23 @@ const SUCCESS_RESULT = { describe('ShellProcessor', () => { let context: CommandContext; let mockConfig: Partial; + let mockPolicyEngineCheck: Mock; beforeEach(() => { vi.clearAllMocks(); + mockPolicyEngineCheck = vi.fn().mockResolvedValue({ + decision: PolicyDecision.ALLOW, + }); + mockConfig = { getTargetDir: vi.fn().mockReturnValue('/test/dir'), getApprovalMode: vi.fn().mockReturnValue(ApprovalMode.DEFAULT), getEnableInteractiveShell: vi.fn().mockReturnValue(false), getShellExecutionConfig: vi.fn().mockReturnValue({}), + getPolicyEngine: vi.fn().mockReturnValue({ + check: mockPolicyEngineCheck, + }), }; context = createMockCommandContext({ @@ -124,9 +136,8 @@ describe('ShellProcessor', () => { const prompt: PromptPipelineContent = createPromptPipelineContent( 'The current status is: !{git status}', ); - mockCheckCommandPermissions.mockReturnValue({ - allAllowed: true, - disallowedCommands: [], + mockPolicyEngineCheck.mockResolvedValue({ + decision: PolicyDecision.ALLOW, }); mockShellExecute.mockReturnValue({ result: Promise.resolve({ ...SUCCESS_RESULT, output: 'On branch main' }), @@ -134,10 +145,12 @@ describe('ShellProcessor', () => { const result = await processor.process(prompt, context); - expect(mockCheckCommandPermissions).toHaveBeenCalledWith( - 'git status', - expect.any(Object), - context.session.sessionShellAllowlist, + expect(mockPolicyEngineCheck).toHaveBeenCalledWith( + { + name: 'run_shell_command', + args: { command: 'git status' }, + }, + undefined, ); expect(mockShellExecute).toHaveBeenCalledWith( 'git status', @@ -155,9 +168,8 @@ describe('ShellProcessor', () => { const prompt: PromptPipelineContent = createPromptPipelineContent( '!{git status} in !{pwd}', ); - mockCheckCommandPermissions.mockReturnValue({ - allAllowed: true, - disallowedCommands: [], + mockPolicyEngineCheck.mockResolvedValue({ + decision: PolicyDecision.ALLOW, }); mockShellExecute @@ -173,7 +185,7 @@ describe('ShellProcessor', () => { const result = await processor.process(prompt, context); - expect(mockCheckCommandPermissions).toHaveBeenCalledTimes(2); + expect(mockPolicyEngineCheck).toHaveBeenCalledTimes(2); expect(mockShellExecute).toHaveBeenCalledTimes(2); expect(result).toEqual([{ text: 'On branch main in /usr/home' }]); }); @@ -183,9 +195,8 @@ describe('ShellProcessor', () => { const prompt: PromptPipelineContent = createPromptPipelineContent( 'Do something dangerous: !{rm -rf /}', ); - mockCheckCommandPermissions.mockReturnValue({ - allAllowed: false, - disallowedCommands: ['rm -rf /'], + mockPolicyEngineCheck.mockResolvedValue({ + decision: PolicyDecision.ASK_USER, }); await expect(processor.process(prompt, context)).rejects.toThrow( @@ -198,11 +209,11 @@ describe('ShellProcessor', () => { const prompt: PromptPipelineContent = createPromptPipelineContent( 'Do something dangerous: !{rm -rf /}', ); - mockCheckCommandPermissions.mockReturnValue({ - allAllowed: false, - disallowedCommands: ['rm -rf /'], + // In YOLO mode, PolicyEngine returns ALLOW + mockPolicyEngineCheck.mockResolvedValue({ + decision: PolicyDecision.ALLOW, }); - // Override the approval mode for this test + // Override the approval mode for this test (though PolicyEngine mock handles the decision) (mockConfig.getApprovalMode as Mock).mockReturnValue(ApprovalMode.YOLO); mockShellExecute.mockReturnValue({ result: Promise.resolve({ ...SUCCESS_RESULT, output: 'deleted' }), @@ -227,17 +238,14 @@ describe('ShellProcessor', () => { const prompt: PromptPipelineContent = createPromptPipelineContent( 'Do something forbidden: !{reboot}', ); - mockCheckCommandPermissions.mockReturnValue({ - allAllowed: false, - disallowedCommands: ['reboot'], - isHardDenial: true, // This is the key difference - blockReason: 'System commands are blocked', + mockPolicyEngineCheck.mockResolvedValue({ + decision: PolicyDecision.DENY, }); // Set approval mode to YOLO (mockConfig.getApprovalMode as Mock).mockReturnValue(ApprovalMode.YOLO); await expect(processor.process(prompt, context)).rejects.toThrow( - /Blocked command: "reboot". Reason: System commands are blocked/, + /Blocked command: "reboot". Reason: Blocked by policy/, ); // Ensure it never tried to execute @@ -249,9 +257,8 @@ describe('ShellProcessor', () => { const prompt: PromptPipelineContent = createPromptPipelineContent( 'Do something dangerous: !{rm -rf /}', ); - mockCheckCommandPermissions.mockReturnValue({ - allAllowed: false, - disallowedCommands: ['rm -rf /'], + mockPolicyEngineCheck.mockResolvedValue({ + decision: PolicyDecision.ASK_USER, }); try { @@ -273,14 +280,12 @@ describe('ShellProcessor', () => { const prompt: PromptPipelineContent = createPromptPipelineContent( '!{cmd1} and !{cmd2}', ); - mockCheckCommandPermissions.mockImplementation((cmd) => { - if (cmd === 'cmd1') { - return { allAllowed: false, disallowedCommands: ['cmd1'] }; + mockPolicyEngineCheck.mockImplementation(async (toolCall) => { + const cmd = toolCall.args.command; + if (cmd === 'cmd1' || cmd === 'cmd2') { + return { decision: PolicyDecision.ASK_USER }; } - if (cmd === 'cmd2') { - return { allAllowed: false, disallowedCommands: ['cmd2'] }; - } - return { allAllowed: true, disallowedCommands: [] }; + return { decision: PolicyDecision.ALLOW }; }); try { @@ -301,11 +306,12 @@ describe('ShellProcessor', () => { 'First: !{echo "hello"}, Second: !{rm -rf /}', ); - mockCheckCommandPermissions.mockImplementation((cmd) => { + mockPolicyEngineCheck.mockImplementation(async (toolCall) => { + const cmd = toolCall.args.command; if (cmd.includes('rm')) { - return { allAllowed: false, disallowedCommands: [cmd] }; + return { decision: PolicyDecision.ASK_USER }; } - return { allAllowed: true, disallowedCommands: [] }; + return { decision: PolicyDecision.ALLOW }; }); await expect(processor.process(prompt, context)).rejects.toThrow( @@ -322,10 +328,13 @@ describe('ShellProcessor', () => { 'Allowed: !{ls -l}, Disallowed: !{rm -rf /}', ); - mockCheckCommandPermissions.mockImplementation((cmd) => ({ - allAllowed: !cmd.includes('rm'), - disallowedCommands: cmd.includes('rm') ? [cmd] : [], - })); + mockPolicyEngineCheck.mockImplementation(async (toolCall) => { + const cmd = toolCall.args.command; + if (cmd.includes('rm')) { + return { decision: PolicyDecision.ASK_USER }; + } + return { decision: PolicyDecision.ALLOW }; + }); try { await processor.process(prompt, context); @@ -344,13 +353,12 @@ describe('ShellProcessor', () => { 'Run !{cmd1} and !{cmd2}', ); - // Add commands to the session allowlist + // Add commands to the session allowlist (conceptually, in this test we just mock the engine allowing them) context.session.sessionShellAllowlist = new Set(['cmd1', 'cmd2']); // checkCommandPermissions should now pass for these - mockCheckCommandPermissions.mockReturnValue({ - allAllowed: true, - disallowedCommands: [], + mockPolicyEngineCheck.mockResolvedValue({ + decision: PolicyDecision.ALLOW, }); mockShellExecute @@ -363,20 +371,58 @@ describe('ShellProcessor', () => { const result = await processor.process(prompt, context); - expect(mockCheckCommandPermissions).toHaveBeenCalledWith( - 'cmd1', - expect.any(Object), - context.session.sessionShellAllowlist, - ); - expect(mockCheckCommandPermissions).toHaveBeenCalledWith( - 'cmd2', - expect.any(Object), - context.session.sessionShellAllowlist, - ); + expect(mockPolicyEngineCheck).not.toHaveBeenCalled(); expect(mockShellExecute).toHaveBeenCalledTimes(2); expect(result).toEqual([{ text: 'Run output1 and output2' }]); }); + it('should support the full confirmation flow (Ask -> Approve -> Retry)', async () => { + // 1. Initial State: Command NOT allowed + const processor = new ShellProcessor('test-command'); + const prompt: PromptPipelineContent = + createPromptPipelineContent('!{echo "once"}'); + + // Policy Engine says ASK_USER + mockPolicyEngineCheck.mockResolvedValue({ + decision: PolicyDecision.ASK_USER, + }); + + // 2. First Attempt: processing should fail with ConfirmationRequiredError + try { + await processor.process(prompt, context); + expect.fail('Should have thrown ConfirmationRequiredError'); + } catch (e) { + expect(e).toBeInstanceOf(ConfirmationRequiredError); + expect(mockPolicyEngineCheck).toHaveBeenCalledTimes(1); + } + + // 3. User Approves: Add to session allowlist (simulating UI action) + context.session.sessionShellAllowlist.add('echo "once"'); + + // 4. Retry: calling process() again with the same context + // Reset mocks to ensure we track new calls cleanly + mockPolicyEngineCheck.mockClear(); + + // Mock successful execution + mockShellExecute.mockReturnValue({ + result: Promise.resolve({ ...SUCCESS_RESULT, output: 'once' }), + }); + + const result = await processor.process(prompt, context); + + // 5. Verify Success AND Policy Engine Bypass + expect(mockPolicyEngineCheck).not.toHaveBeenCalled(); + expect(mockShellExecute).toHaveBeenCalledWith( + 'echo "once"', + expect.any(String), + expect.any(Function), + expect.any(Object), + false, + expect.any(Object), + ); + expect(result).toEqual([{ text: 'once' }]); + }); + it('should trim whitespace from the command inside the injection before interpolation', async () => { const processor = new ShellProcessor('test-command'); const prompt: PromptPipelineContent = createPromptPipelineContent( @@ -389,9 +435,8 @@ describe('ShellProcessor', () => { const expectedCommand = `ls ${expectedEscapedArgs} -l`; - mockCheckCommandPermissions.mockReturnValue({ - allAllowed: true, - disallowedCommands: [], + mockPolicyEngineCheck.mockResolvedValue({ + decision: PolicyDecision.ALLOW, }); mockShellExecute.mockReturnValue({ result: Promise.resolve({ ...SUCCESS_RESULT, output: 'total 0' }), @@ -399,10 +444,9 @@ describe('ShellProcessor', () => { await processor.process(prompt, context); - expect(mockCheckCommandPermissions).toHaveBeenCalledWith( - expectedCommand, - expect.any(Object), - context.session.sessionShellAllowlist, + expect(mockPolicyEngineCheck).toHaveBeenCalledWith( + { name: 'run_shell_command', args: { command: expectedCommand } }, + undefined, ); expect(mockShellExecute).toHaveBeenCalledWith( expectedCommand, @@ -421,7 +465,7 @@ describe('ShellProcessor', () => { const result = await processor.process(prompt, context); - expect(mockCheckCommandPermissions).not.toHaveBeenCalled(); + expect(mockPolicyEngineCheck).not.toHaveBeenCalled(); expect(mockShellExecute).not.toHaveBeenCalled(); // It replaces !{} with an empty string. @@ -615,20 +659,20 @@ describe('ShellProcessor', () => { const expectedEscapedArgs = getExpectedEscapedArgForPlatform(rawArgs); const expectedResolvedCommand = `rm ${expectedEscapedArgs}`; - mockCheckCommandPermissions.mockReturnValue({ - allAllowed: false, - disallowedCommands: [expectedResolvedCommand], - isHardDenial: false, + mockPolicyEngineCheck.mockResolvedValue({ + decision: PolicyDecision.ASK_USER, }); await expect(processor.process(prompt, context)).rejects.toThrow( ConfirmationRequiredError, ); - expect(mockCheckCommandPermissions).toHaveBeenCalledWith( - expectedResolvedCommand, - expect.any(Object), - context.session.sessionShellAllowlist, + expect(mockPolicyEngineCheck).toHaveBeenCalledWith( + { + name: 'run_shell_command', + args: { command: expectedResolvedCommand }, + }, + undefined, ); }); @@ -638,15 +682,12 @@ describe('ShellProcessor', () => { createPromptPipelineContent('!{rm {{args}}}'); const expectedEscapedArgs = getExpectedEscapedArgForPlatform(rawArgs); const expectedResolvedCommand = `rm ${expectedEscapedArgs}`; - mockCheckCommandPermissions.mockReturnValue({ - allAllowed: false, - disallowedCommands: [expectedResolvedCommand], - isHardDenial: true, - blockReason: 'It is forbidden.', + mockPolicyEngineCheck.mockResolvedValue({ + decision: PolicyDecision.DENY, }); await expect(processor.process(prompt, context)).rejects.toThrow( - `Blocked command: "${expectedResolvedCommand}". Reason: It is forbidden.`, + `Blocked command: "${expectedResolvedCommand}". Reason: Blocked by policy.`, ); }); }); diff --git a/packages/cli/src/services/prompt-processors/shellProcessor.ts b/packages/cli/src/services/prompt-processors/shellProcessor.ts index 350421c1c5..4c8369f664 100644 --- a/packages/cli/src/services/prompt-processors/shellProcessor.ts +++ b/packages/cli/src/services/prompt-processors/shellProcessor.ts @@ -5,12 +5,11 @@ */ import { - ApprovalMode, - checkCommandPermissions, escapeShellArg, getShellConfiguration, ShellExecutionService, flatMapTextParts, + PolicyDecision, } from '@google/gemini-cli-core'; import type { CommandContext } from '../../ui/commands/types.js'; @@ -81,7 +80,6 @@ export class ShellProcessor implements IPromptProcessor { `Security configuration not loaded. Cannot verify shell command permissions for '${this.commandName}'. Aborting.`, ); } - const { sessionShellAllowlist } = context.session; const injections = extractInjections( prompt, @@ -121,21 +119,25 @@ export class ShellProcessor implements IPromptProcessor { if (!command) continue; + if (context.session.sessionShellAllowlist?.has(command)) { + continue; + } + // Security check on the final, escaped command string. - const { allAllowed, disallowedCommands, blockReason, isHardDenial } = - checkCommandPermissions(command, config, sessionShellAllowlist); + const { decision } = await config.getPolicyEngine().check( + { + name: 'run_shell_command', + args: { command }, + }, + undefined, + ); - if (!allAllowed) { - if (isHardDenial) { - throw new Error( - `${this.commandName} cannot be run. Blocked command: "${command}". Reason: ${blockReason || 'Blocked by configuration.'}`, - ); - } - - // If not a hard denial, respect YOLO mode and auto-approve. - if (config.getApprovalMode() !== ApprovalMode.YOLO) { - disallowedCommands.forEach((uc) => commandsToConfirm.add(uc)); - } + if (decision === PolicyDecision.DENY) { + throw new Error( + `${this.commandName} cannot be run. Blocked command: "${command}". Reason: Blocked by policy.`, + ); + } else if (decision === PolicyDecision.ASK_USER) { + commandsToConfirm.add(command); } } diff --git a/packages/cli/src/ui/hooks/useToolScheduler.test.ts b/packages/cli/src/ui/hooks/useToolScheduler.test.ts index 7015e6afea..1ffaa61cc7 100644 --- a/packages/cli/src/ui/hooks/useToolScheduler.test.ts +++ b/packages/cli/src/ui/hooks/useToolScheduler.test.ts @@ -33,6 +33,7 @@ import { ApprovalMode, HookSystem, PREVIEW_GEMINI_MODEL, + PolicyDecision, } from '@google/gemini-cli-core'; import { MockTool } from '@google/gemini-cli-core/src/test-utils/mock-tool.js'; import { createMockMessageBus } from '@google/gemini-cli-core/src/test-utils/mock-message-bus.js'; @@ -80,13 +81,21 @@ const mockConfig = { getGeminiClient: () => null, // No client needed for these tests getShellExecutionConfig: () => ({ terminalWidth: 80, terminalHeight: 24 }), getMessageBus: () => null, - getPolicyEngine: () => null, isInteractive: () => false, getExperiments: () => {}, getEnableHooks: () => false, } as unknown as Config; mockConfig.getMessageBus = vi.fn().mockReturnValue(createMockMessageBus()); mockConfig.getHookSystem = vi.fn().mockReturnValue(new HookSystem(mockConfig)); +mockConfig.getPolicyEngine = vi.fn().mockReturnValue({ + check: async () => { + const mode = mockConfig.getApprovalMode(); + if (mode === ApprovalMode.YOLO) { + return { decision: PolicyDecision.ALLOW }; + } + return { decision: PolicyDecision.ASK_USER }; + }, +}); function createMockConfigOverride(overrides: Partial = {}): Config { return { ...mockConfig, ...overrides } as Config; diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 5859de2133..10c06950b8 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -84,7 +84,7 @@ import { FileExclusions } from '../utils/ignorePatterns.js'; import type { EventEmitter } from 'node:events'; import { MessageBus } from '../confirmation-bus/message-bus.js'; import { PolicyEngine } from '../policy/policy-engine.js'; -import type { PolicyEngineConfig } from '../policy/types.js'; +import { ApprovalMode, type PolicyEngineConfig } from '../policy/types.js'; import { HookSystem } from '../hooks/index.js'; import type { UserTierId } from '../code_assist/types.js'; import type { RetrieveUserQuotaResponse } from '../code_assist/types.js'; @@ -101,8 +101,6 @@ import { debugLogger } from '../utils/debugLogger.js'; import { SkillManager, type SkillDefinition } from '../skills/skillManager.js'; import { startupProfiler } from '../telemetry/startupProfiler.js'; -import { ApprovalMode } from '../policy/types.js'; - export interface AccessibilitySettings { disableLoadingPhrases?: boolean; screenReader?: boolean; diff --git a/packages/core/src/core/coreToolScheduler.test.ts b/packages/core/src/core/coreToolScheduler.test.ts index ba4e22506b..22ef939a62 100644 --- a/packages/core/src/core/coreToolScheduler.test.ts +++ b/packages/core/src/core/coreToolScheduler.test.ts @@ -19,7 +19,6 @@ import type { ToolResult, Config, ToolRegistry, - AnyToolInvocation, MessageBus, } from '../index.js'; import { @@ -31,6 +30,7 @@ import { Kind, ApprovalMode, HookSystem, + PolicyDecision, } from '../index.js'; import { createMockMessageBus } from '../test-utils/mock-message-bus.js'; import { @@ -39,8 +39,8 @@ import { MOCK_TOOL_SHOULD_CONFIRM_EXECUTE, } from '../test-utils/mock-tool.js'; import * as modifiableToolModule from '../tools/modifiable-tool.js'; -import { isShellInvocationAllowlisted } from '../utils/shell-permissions.js'; import { DEFAULT_GEMINI_MODEL } from '../config/models.js'; +import type { PolicyEngine } from '../policy/policy-engine.js'; vi.mock('fs/promises', () => ({ writeFile: vi.fn(), @@ -274,11 +274,35 @@ function createMockConfig(overrides: Partial = {}): Config { getGeminiClient: () => null, getMessageBus: () => createMockMessageBus(), getEnableHooks: () => false, - getPolicyEngine: () => null, getExperiments: () => {}, } as unknown as Config; - return { ...baseConfig, ...overrides } as Config; + const finalConfig = { ...baseConfig, ...overrides } as Config; + + // Patch the policy engine to use the final config if not overridden + if (!overrides.getPolicyEngine) { + finalConfig.getPolicyEngine = () => + ({ + check: async (toolCall: { name: string; args: object }) => { + // Mock simple policy logic for tests + const mode = finalConfig.getApprovalMode(); + if (mode === ApprovalMode.YOLO) { + return { decision: PolicyDecision.ALLOW }; + } + const allowed = finalConfig.getAllowedTools(); + if ( + allowed && + (allowed.includes(toolCall.name) || + allowed.some((p) => toolCall.name.startsWith(p))) + ) { + return { decision: PolicyDecision.ALLOW }; + } + return { decision: PolicyDecision.ASK_USER }; + }, + }) as unknown as PolicyEngine; + } + + return finalConfig; } describe('CoreToolScheduler', () => { @@ -570,7 +594,7 @@ describe('CoreToolScheduler', () => { const mockConfig = createMockConfig({ getToolRegistry: () => mockToolRegistry, - isInteractive: () => false, + isInteractive: () => true, }); const scheduler = new CoreToolScheduler({ @@ -1192,15 +1216,6 @@ describe('CoreToolScheduler request queueing', () => { }); it('should require approval for a chained shell command even when prefix is allowlisted', async () => { - expect( - isShellInvocationAllowlisted( - { - params: { command: 'git status && rm -rf /tmp/should-not-run' }, - } as unknown as AnyToolInvocation, - ['run_shell_command(git)'], - ), - ).toBe(false); - const executeFn = vi.fn().mockResolvedValue({ llmContent: 'Shell command executed', returnDisplay: 'Shell command executed', @@ -1249,6 +1264,10 @@ describe('CoreToolScheduler request queueing', () => { }), getToolRegistry: () => toolRegistry, getHookSystem: () => undefined, + getPolicyEngine: () => + ({ + check: async () => ({ decision: PolicyDecision.ASK_USER }), + }) as unknown as PolicyEngine, }); const scheduler = new CoreToolScheduler({ diff --git a/packages/core/src/core/coreToolScheduler.ts b/packages/core/src/core/coreToolScheduler.ts index 20afc07b2c..69a2e03475 100644 --- a/packages/core/src/core/coreToolScheduler.ts +++ b/packages/core/src/core/coreToolScheduler.ts @@ -14,7 +14,7 @@ import { } from '../tools/tools.js'; import type { EditorType } from '../utils/editor.js'; import type { Config } from '../config/config.js'; -import { ApprovalMode } from '../policy/types.js'; +import { PolicyDecision } from '../policy/types.js'; import { logToolCall } from '../telemetry/loggers.js'; import { ToolErrorType } from '../tools/tool-error.js'; import { ToolCallEvent } from '../telemetry/types.js'; @@ -25,12 +25,7 @@ import { modifyWithEditor, } from '../tools/modifiable-tool.js'; import * as Diff from 'diff'; -import { SHELL_TOOL_NAMES } from '../utils/shell-utils.js'; -import { - doesToolInvocationMatch, - getToolSuggestion, -} from '../utils/tool-utils.js'; -import { isShellInvocationAllowlisted } from '../utils/shell-permissions.js'; +import { getToolSuggestion } from '../utils/tool-utils.js'; import type { ToolConfirmationRequest } from '../confirmation-bus/types.js'; import { MessageBusType } from '../confirmation-bus/types.js'; import type { MessageBus } from '../confirmation-bus/message-bus.js'; @@ -592,17 +587,46 @@ export class CoreToolScheduler { return; } - const confirmationDetails = - await invocation.shouldConfirmExecute(signal); + // Policy Check using PolicyEngine + // We must reconstruct the FunctionCall format expected by PolicyEngine + const toolCallForPolicy = { + name: toolCall.request.name, + args: toolCall.request.args, + }; + const { decision } = await this.config + .getPolicyEngine() + .check(toolCallForPolicy, undefined); // Server name undefined for local tools - if (!confirmationDetails) { + if (decision === PolicyDecision.DENY) { + const errorMessage = `Tool execution denied by policy.`; + this.setStatusInternal( + reqInfo.callId, + 'error', + signal, + createErrorResponse( + reqInfo, + new Error(errorMessage), + ToolErrorType.POLICY_VIOLATION, + ), + ); + await this.checkAndNotifyCompletion(signal); + return; + } + + if (decision === PolicyDecision.ALLOW) { this.setToolCallOutcome( reqInfo.callId, ToolConfirmationOutcome.ProceedAlways, ); this.setStatusInternal(reqInfo.callId, 'scheduled', signal); } else { - if (this.isAutoApproved(toolCall)) { + // PolicyDecision.ASK_USER + + // We need confirmation details to show to the user + const confirmationDetails = + await invocation.shouldConfirmExecute(signal); + + if (!confirmationDetails) { this.setToolCallOutcome( reqInfo.callId, ToolConfirmationOutcome.ProceedAlways, @@ -616,6 +640,7 @@ export class CoreToolScheduler { }" requires user confirmation, which is not supported in non-interactive mode.`, ); } + // Fire Notification hook before showing confirmation to user const messageBus = this.config.getMessageBus(); const hooksEnabled = this.config.getEnableHooks(); @@ -1014,20 +1039,4 @@ export class CoreToolScheduler { }; }); } - - private isAutoApproved(toolCall: ValidatingToolCall): boolean { - if (this.config.getApprovalMode() === ApprovalMode.YOLO) { - return true; - } - - const allowedTools = this.config.getAllowedTools() || []; - const { tool, invocation } = toolCall; - const toolName = typeof tool === 'string' ? tool : tool.name; - - if (SHELL_TOOL_NAMES.includes(toolName)) { - return isShellInvocationAllowlisted(invocation, allowedTools); - } - - return doesToolInvocationMatch(tool, invocation, allowedTools); - } } diff --git a/packages/core/src/core/nonInteractiveToolExecutor.test.ts b/packages/core/src/core/nonInteractiveToolExecutor.test.ts index a903bfdfa1..7753923d88 100644 --- a/packages/core/src/core/nonInteractiveToolExecutor.test.ts +++ b/packages/core/src/core/nonInteractiveToolExecutor.test.ts @@ -20,6 +20,7 @@ import { ApprovalMode, HookSystem, PREVIEW_GEMINI_MODEL, + PolicyDecision, } from '../index.js'; import type { Part } from '@google/genai'; import { MockTool } from '../test-utils/mock-tool.js'; @@ -65,7 +66,9 @@ describe('executeToolCall', () => { getActiveModel: () => PREVIEW_GEMINI_MODEL, getGeminiClient: () => null, // No client needed for these tests getMessageBus: () => null, - getPolicyEngine: () => null, + getPolicyEngine: () => ({ + check: async () => ({ decision: PolicyDecision.ALLOW }), + }), isInteractive: () => false, getExperiments: () => {}, getEnableHooks: () => false, diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 2f11c4ae71..a15ee2951d 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -67,7 +67,8 @@ export * from './utils/googleQuotaErrors.js'; export * from './utils/fileUtils.js'; export * from './utils/retry.js'; export * from './utils/shell-utils.js'; -export * from './utils/shell-permissions.js'; +export { PolicyDecision, ApprovalMode } from './policy/types.js'; +export * from './utils/tool-utils.js'; export * from './utils/terminalSerializer.js'; export * from './utils/systemEncoding.js'; export * from './utils/textUtils.js'; diff --git a/packages/core/src/policy/persistence.test.ts b/packages/core/src/policy/persistence.test.ts index 479ae8707c..22f00ac9a8 100644 --- a/packages/core/src/policy/persistence.test.ts +++ b/packages/core/src/policy/persistence.test.ts @@ -127,7 +127,7 @@ describe('createPolicyUpdater', () => { expect(addedRule).toBeDefined(); expect(addedRule?.priority).toBe(2.95); expect(addedRule?.argsPattern).toEqual( - new RegExp(`"command":"git\\ status(?:[\\s"]|$)`), + new RegExp(`"command":"git\\ status(?:[\\s"]|\\\\")`), ); // Verify file written diff --git a/packages/core/src/policy/policy-updater.test.ts b/packages/core/src/policy/policy-updater.test.ts index e5add3748a..aa6b7ac887 100644 --- a/packages/core/src/policy/policy-updater.test.ts +++ b/packages/core/src/policy/policy-updater.test.ts @@ -72,14 +72,14 @@ describe('createPolicyUpdater', () => { 1, expect.objectContaining({ toolName: 'run_shell_command', - argsPattern: new RegExp('"command":"echo(?:[\\s"]|$)'), + argsPattern: new RegExp('"command":"echo(?:[\\s"]|\\\\")'), }), ); expect(policyEngine.addRule).toHaveBeenNthCalledWith( 2, expect.objectContaining({ toolName: 'run_shell_command', - argsPattern: new RegExp('"command":"ls(?:[\\s"]|$)'), + argsPattern: new RegExp('"command":"ls(?:[\\s"]|\\\\")'), }), ); }); @@ -98,7 +98,7 @@ describe('createPolicyUpdater', () => { expect(policyEngine.addRule).toHaveBeenCalledWith( expect.objectContaining({ toolName: 'run_shell_command', - argsPattern: new RegExp('"command":"git(?:[\\s"]|$)'), + argsPattern: new RegExp('"command":"git(?:[\\s"]|\\\\")'), }), ); }); diff --git a/packages/core/src/policy/utils.test.ts b/packages/core/src/policy/utils.test.ts index 991cd28eed..dfbb8b298c 100644 --- a/packages/core/src/policy/utils.test.ts +++ b/packages/core/src/policy/utils.test.ts @@ -31,14 +31,14 @@ describe('policy/utils', () => { it('should build pattern from a single commandPrefix', () => { const result = buildArgsPatterns(undefined, 'ls', undefined); - expect(result).toEqual(['"command":"ls(?:[\\s"]|$)']); + expect(result).toEqual(['"command":"ls(?:[\\s"]|\\\\")']); }); it('should build patterns from an array of commandPrefixes', () => { const result = buildArgsPatterns(undefined, ['ls', 'cd'], undefined); expect(result).toEqual([ - '"command":"ls(?:[\\s"]|$)', - '"command":"cd(?:[\\s"]|$)', + '"command":"ls(?:[\\s"]|\\\\")', + '"command":"cd(?:[\\s"]|\\\\")', ]); }); @@ -49,7 +49,7 @@ describe('policy/utils', () => { it('should prioritize commandPrefix over commandRegex and argsPattern', () => { const result = buildArgsPatterns('raw', 'prefix', 'regex'); - expect(result).toEqual(['"command":"prefix(?:[\\s"]|$)']); + expect(result).toEqual(['"command":"prefix(?:[\\s"]|\\\\")']); }); it('should prioritize commandRegex over argsPattern if no commandPrefix', () => { @@ -59,13 +59,15 @@ describe('policy/utils', () => { it('should escape characters in commandPrefix', () => { const result = buildArgsPatterns(undefined, 'git checkout -b', undefined); - expect(result).toEqual(['"command":"git\\ checkout\\ \\-b(?:[\\s"]|$)']); + expect(result).toEqual([ + '"command":"git\\ checkout\\ \\-b(?:[\\s"]|\\\\")', + ]); }); it('should correctly escape quotes in commandPrefix', () => { const result = buildArgsPatterns(undefined, 'git "fix"', undefined); expect(result).toEqual([ - '"command":"git\\ \\\\\\"fix\\\\\\"(?:[\\s"]|$)', + '"command":"git\\ \\\\\\"fix\\\\\\"(?:[\\s"]|\\\\")', ]); }); @@ -73,5 +75,36 @@ describe('policy/utils', () => { const result = buildArgsPatterns(undefined, undefined, undefined); expect(result).toEqual([undefined]); }); + + it('should match prefixes followed by JSON escaped quotes', () => { + // Testing the security fix logic: allowing "echo \"foo\"" + const prefix = 'echo '; + const patterns = buildArgsPatterns(undefined, prefix, undefined); + const regex = new RegExp(patterns[0]!); + + // Mimic JSON stringified args + // echo "foo" -> {"command":"echo \"foo\""} + const validJsonArgs = '{"command":"echo \\"foo\\""}'; + expect(regex.test(validJsonArgs)).toBe(true); + }); + + it('should NOT match prefixes followed by raw backslashes (security check)', () => { + // Testing that we blocked the hole: "echo\foo" + const prefix = 'echo '; + const patterns = buildArgsPatterns(undefined, prefix, undefined); + const regex = new RegExp(patterns[0]!); + + // echo\foo -> {"command":"echo\\foo"} + // In regex matching: "echo " is followed by "\" which is NOT in [\s"] and is not \" + const attackJsonArgs = '{"command":"echo\\\\foo"}'; + expect(regex.test(attackJsonArgs)).toBe(false); + + // Also validation for "git " matching "git\status" + const gitPatterns = buildArgsPatterns(undefined, 'git ', undefined); + const gitRegex = new RegExp(gitPatterns[0]!); + // git\status -> {"command":"git\\status"} + const gitAttack = '{"command":"git\\\\status"}'; + expect(gitRegex.test(gitAttack)).toBe(false); + }); }); }); diff --git a/packages/core/src/policy/utils.ts b/packages/core/src/policy/utils.ts index 0052e90035..b891a8fda1 100644 --- a/packages/core/src/policy/utils.ts +++ b/packages/core/src/policy/utils.ts @@ -38,7 +38,10 @@ export function buildArgsPatterns( // always followed by a space or a closing quote. return prefixes.map((prefix) => { const jsonPrefix = JSON.stringify(prefix).slice(1, -1); - return `"command":"${escapeRegex(jsonPrefix)}(?:[\\s"]|$)`; + // We allow [\s], ["], or the specific sequence [\"] (for escaped quotes + // in JSON). We do NOT allow generic [\\], which would match "git\status" + // -> "gitstatus". + return `"command":"${escapeRegex(jsonPrefix)}(?:[\\s"]|\\\\")`; }); } diff --git a/packages/core/src/tools/tool-error.ts b/packages/core/src/tools/tool-error.ts index 4102f1a490..f29470b780 100644 --- a/packages/core/src/tools/tool-error.ts +++ b/packages/core/src/tools/tool-error.ts @@ -12,6 +12,10 @@ * - Fatal: System-level issues that prevent continued execution (e.g., disk full, critical I/O errors) */ export enum ToolErrorType { + POLICY_VIOLATION = 'policy_violation', + /** + * General tool execution failure (e.g. file system error, API error). + */ // General Errors INVALID_TOOL_PARAMS = 'invalid_tool_params', UNKNOWN = 'unknown', diff --git a/packages/core/src/utils/shell-permissions.test.ts b/packages/core/src/utils/shell-permissions.test.ts deleted file mode 100644 index a80afdbd7a..0000000000 --- a/packages/core/src/utils/shell-permissions.test.ts +++ /dev/null @@ -1,551 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import { - expect, - describe, - it, - beforeEach, - beforeAll, - vi, - afterEach, -} from 'vitest'; -import { initializeShellParsers } from './shell-utils.js'; -import { - checkCommandPermissions, - isCommandAllowed, - isShellInvocationAllowlisted, -} from './shell-permissions.js'; -import type { Config } from '../config/config.js'; -import type { AnyToolInvocation } from '../index.js'; - -const mockPlatform = vi.hoisted(() => vi.fn()); -const mockHomedir = vi.hoisted(() => vi.fn()); -vi.mock('os', () => ({ - default: { - platform: mockPlatform, - homedir: mockHomedir, - }, - platform: mockPlatform, - homedir: mockHomedir, -})); - -const mockSpawnSync = vi.hoisted(() => vi.fn()); -vi.mock('node:child_process', async (importOriginal) => { - const actual = await importOriginal(); - return { - ...actual, - spawnSync: mockSpawnSync, - }; -}); - -const mockQuote = vi.hoisted(() => vi.fn()); -vi.mock('shell-quote', () => ({ - quote: mockQuote, -})); - -let config: Config; -const isWindowsRuntime = process.platform === 'win32'; -const describeWindowsOnly = isWindowsRuntime ? describe : describe.skip; - -beforeAll(async () => { - mockPlatform.mockReturnValue('linux'); - await initializeShellParsers(); -}); - -beforeEach(() => { - mockPlatform.mockReturnValue('linux'); - mockQuote.mockImplementation((args: string[]) => - args.map((arg) => `'${arg}'`).join(' '), - ); - config = { - getCoreTools: () => [], - getExcludeTools: () => new Set([]), - getAllowedTools: () => [], - getApprovalMode: () => 'strict', - isInteractive: () => false, - } as unknown as Config; -}); - -afterEach(() => { - vi.clearAllMocks(); -}); - -describe('isCommandAllowed', () => { - it('should allow a command if no restrictions are provided', () => { - const result = isCommandAllowed('goodCommand --safe', config); - expect(result.allowed).toBe(true); - }); - - it('should allow a command if it is in the global allowlist', () => { - config.getCoreTools = () => ['ShellTool(goodCommand)']; - const result = isCommandAllowed('goodCommand --safe', config); - expect(result.allowed).toBe(true); - }); - - it('should block a command if it is not in a strict global allowlist', () => { - config.getCoreTools = () => ['ShellTool(goodCommand --safe)']; - const result = isCommandAllowed('badCommand --danger', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command(s) not in the allowed commands list. Disallowed commands: "badCommand --danger"`, - ); - }); - - it('should block a command if it is in the blocked list', () => { - config.getExcludeTools = () => new Set(['ShellTool(badCommand --danger)']); - const result = isCommandAllowed('badCommand --danger', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command 'badCommand --danger' is blocked by configuration`, - ); - }); - - it('should prioritize the blocklist over the allowlist', () => { - config.getCoreTools = () => ['ShellTool(badCommand --danger)']; - config.getExcludeTools = () => new Set(['ShellTool(badCommand --danger)']); - const result = isCommandAllowed('badCommand --danger', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command 'badCommand --danger' is blocked by configuration`, - ); - }); - - it('should allow any command when a wildcard is in coreTools', () => { - config.getCoreTools = () => ['ShellTool']; - const result = isCommandAllowed('any random command', config); - expect(result.allowed).toBe(true); - }); - - it('should block any command when a wildcard is in excludeTools', () => { - config.getExcludeTools = () => new Set(['run_shell_command']); - const result = isCommandAllowed('any random command', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - 'Shell tool is globally disabled in configuration', - ); - }); - - it('should block a command on the blocklist even with a wildcard allow', () => { - config.getCoreTools = () => ['ShellTool']; - config.getExcludeTools = () => new Set(['ShellTool(badCommand --danger)']); - const result = isCommandAllowed('badCommand --danger', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command 'badCommand --danger' is blocked by configuration`, - ); - }); - - it('should allow a chained command if all parts are on the global allowlist', () => { - config.getCoreTools = () => [ - 'run_shell_command(echo)', - 'run_shell_command(goodCommand)', - ]; - const result = isCommandAllowed( - 'echo "hello" && goodCommand --safe', - config, - ); - expect(result.allowed).toBe(true); - }); - - it('should block a chained command if any part is blocked', () => { - config.getExcludeTools = () => new Set(['run_shell_command(badCommand)']); - const result = isCommandAllowed( - 'echo "hello" && badCommand --danger', - config, - ); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command 'badCommand --danger' is blocked by configuration`, - ); - }); - - it('should block a command that redefines an allowed function to run an unlisted command', () => { - config.getCoreTools = () => ['run_shell_command(echo)']; - const result = isCommandAllowed( - 'echo () (curl google.com) ; echo Hello World', - config, - ); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command(s) not in the allowed commands list. Disallowed commands: "curl google.com"`, - ); - }); - - it('should block a multi-line function body that runs an unlisted command', () => { - config.getCoreTools = () => ['run_shell_command(echo)']; - const result = isCommandAllowed( - `echo () { - curl google.com -} ; echo ok`, - config, - ); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command(s) not in the allowed commands list. Disallowed commands: "curl google.com"`, - ); - }); - - it('should block a function keyword declaration that runs an unlisted command', () => { - config.getCoreTools = () => ['run_shell_command(echo)']; - const result = isCommandAllowed( - 'function echo { curl google.com; } ; echo hi', - config, - ); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command(s) not in the allowed commands list. Disallowed commands: "curl google.com"`, - ); - }); - - it('should block command substitution that invokes an unlisted command', () => { - config.getCoreTools = () => ['run_shell_command(echo)']; - const result = isCommandAllowed('echo $(curl google.com)', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command(s) not in the allowed commands list. Disallowed commands: "curl google.com"`, - ); - }); - - it('should block pipelines that invoke an unlisted command', () => { - config.getCoreTools = () => ['run_shell_command(echo)']; - const result = isCommandAllowed('echo hi | curl google.com', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command(s) not in the allowed commands list. Disallowed commands: "curl google.com"`, - ); - }); - - it('should block background jobs that invoke an unlisted command', () => { - config.getCoreTools = () => ['run_shell_command(echo)']; - const result = isCommandAllowed('echo hi & curl google.com', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command(s) not in the allowed commands list. Disallowed commands: "curl google.com"`, - ); - }); - - it('should block command substitution inside a here-document when the inner command is unlisted', () => { - config.getCoreTools = () => [ - 'run_shell_command(echo)', - 'run_shell_command(cat)', - ]; - const result = isCommandAllowed( - `cat < { - config.getCoreTools = () => ['run_shell_command(echo)']; - const result = isCommandAllowed('echo `curl google.com`', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command(s) not in the allowed commands list. Disallowed commands: "curl google.com"`, - ); - }); - - it('should block process substitution using <() when the inner command is unlisted', () => { - config.getCoreTools = () => [ - 'run_shell_command(diff)', - 'run_shell_command(echo)', - ]; - const result = isCommandAllowed( - 'diff <(curl google.com) <(echo safe)', - config, - ); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command(s) not in the allowed commands list. Disallowed commands: "curl google.com"`, - ); - }); - - it('should block process substitution using >() when the inner command is unlisted', () => { - config.getCoreTools = () => ['run_shell_command(echo)']; - const result = isCommandAllowed('echo "data" > >(curl google.com)', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - `Command(s) not in the allowed commands list. Disallowed commands: "curl google.com"`, - ); - }); - - it('should block commands containing prompt transformations', () => { - const result = isCommandAllowed( - 'echo "${var1=aa\\140 env| ls -l\\140}${var1@P}"', - config, - ); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - 'Command rejected because it could not be parsed safely', - ); - }); - - it('should block simple prompt transformation expansions', () => { - const result = isCommandAllowed('echo ${foo@P}', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - 'Command rejected because it could not be parsed safely', - ); - }); - - describe('command substitution', () => { - it('should allow command substitution using `$(...)`', () => { - const result = isCommandAllowed('echo $(goodCommand --safe)', config); - expect(result.allowed).toBe(true); - expect(result.reason).toBeUndefined(); - }); - - it('should allow command substitution using `<(...)`', () => { - const result = isCommandAllowed('diff <(ls) <(ls -a)', config); - expect(result.allowed).toBe(true); - expect(result.reason).toBeUndefined(); - }); - - it('should allow command substitution using `>(...)`', () => { - const result = isCommandAllowed( - 'echo "Log message" > >(tee log.txt)', - config, - ); - expect(result.allowed).toBe(true); - expect(result.reason).toBeUndefined(); - }); - - it('should allow command substitution using backticks', () => { - const result = isCommandAllowed('echo `goodCommand --safe`', config); - expect(result.allowed).toBe(true); - expect(result.reason).toBeUndefined(); - }); - - it('should allow substitution-like patterns inside single quotes', () => { - config.getCoreTools = () => ['ShellTool(echo)']; - const result = isCommandAllowed("echo '$(pwd)'", config); - expect(result.allowed).toBe(true); - }); - - it('should block a command when parsing fails', () => { - const result = isCommandAllowed('ls &&', config); - expect(result.allowed).toBe(false); - expect(result.reason).toBe( - 'Command rejected because it could not be parsed safely', - ); - }); - }); -}); - -describe('checkCommandPermissions', () => { - describe('in "Default Allow" mode (no sessionAllowlist)', () => { - it('should return a detailed success object for an allowed command', () => { - const result = checkCommandPermissions('goodCommand --safe', config); - expect(result).toEqual({ - allAllowed: true, - disallowedCommands: [], - }); - }); - - it('should block commands that cannot be parsed safely', () => { - const result = checkCommandPermissions('ls &&', config); - expect(result).toEqual({ - allAllowed: false, - disallowedCommands: ['ls &&'], - blockReason: 'Command rejected because it could not be parsed safely', - isHardDenial: true, - }); - }); - - it('should return a detailed failure object for a blocked command', () => { - config.getExcludeTools = () => new Set(['ShellTool(badCommand)']); - const result = checkCommandPermissions('badCommand --danger', config); - expect(result).toEqual({ - allAllowed: false, - disallowedCommands: ['badCommand --danger'], - blockReason: `Command 'badCommand --danger' is blocked by configuration`, - isHardDenial: true, - }); - }); - - it('should return a detailed failure object for a command not on a strict allowlist', () => { - config.getCoreTools = () => ['ShellTool(goodCommand)']; - const result = checkCommandPermissions( - 'git status && goodCommand', - config, - ); - expect(result).toEqual({ - allAllowed: false, - disallowedCommands: ['git status'], - blockReason: `Command(s) not in the allowed commands list. Disallowed commands: "git status"`, - isHardDenial: false, - }); - }); - }); - - describe('in "Default Deny" mode (with sessionAllowlist)', () => { - it('should allow a command on the sessionAllowlist', () => { - const result = checkCommandPermissions( - 'goodCommand --safe', - config, - new Set(['goodCommand --safe']), - ); - expect(result.allAllowed).toBe(true); - }); - - it('should block a command not on the sessionAllowlist or global allowlist', () => { - const result = checkCommandPermissions( - 'badCommand --danger', - config, - new Set(['goodCommand --safe']), - ); - expect(result.allAllowed).toBe(false); - expect(result.blockReason).toContain( - 'not on the global or session allowlist', - ); - expect(result.disallowedCommands).toEqual(['badCommand --danger']); - }); - - it('should allow a command on the global allowlist even if not on the session allowlist', () => { - config.getCoreTools = () => ['ShellTool(git status)']; - const result = checkCommandPermissions( - 'git status', - config, - new Set(['goodCommand --safe']), - ); - expect(result.allAllowed).toBe(true); - }); - - it('should allow a chained command if parts are on different allowlists', () => { - config.getCoreTools = () => ['ShellTool(git status)']; - const result = checkCommandPermissions( - 'git status && git commit', - config, - new Set(['git commit']), - ); - expect(result.allAllowed).toBe(true); - }); - - it('should block a command on the sessionAllowlist if it is also globally blocked', () => { - config.getExcludeTools = () => new Set(['run_shell_command(badCommand)']); - const result = checkCommandPermissions( - 'badCommand --danger', - config, - new Set(['badCommand --danger']), - ); - expect(result.allAllowed).toBe(false); - expect(result.blockReason).toContain('is blocked by configuration'); - }); - - it('should block a chained command if one part is not on any allowlist', () => { - config.getCoreTools = () => ['run_shell_command(echo)']; - const result = checkCommandPermissions( - 'echo "hello" && badCommand --danger', - config, - new Set(['echo']), - ); - expect(result.allAllowed).toBe(false); - expect(result.disallowedCommands).toEqual(['badCommand --danger']); - }); - }); -}); - -describeWindowsOnly('PowerShell integration', () => { - const originalComSpec = process.env['ComSpec']; - - beforeEach(() => { - mockPlatform.mockReturnValue('win32'); - const systemRoot = process.env['SystemRoot'] || 'C:\\Windows'; - process.env['ComSpec'] = - `${systemRoot}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`; - }); - - afterEach(() => { - if (originalComSpec === undefined) { - delete process.env['ComSpec']; - } else { - process.env['ComSpec'] = originalComSpec; - } - }); - - it('should block commands when PowerShell parser reports errors', () => { - // Mock spawnSync to avoid the overhead of spawning a real PowerShell process, - // which can lead to timeouts in CI environments even on Windows. - mockSpawnSync.mockReturnValue({ - status: 0, - stdout: JSON.stringify({ success: false }), - }); - - const { allowed, reason } = isCommandAllowed('Get-ChildItem |', config); - expect(allowed).toBe(false); - expect(reason).toBe( - 'Command rejected because it could not be parsed safely', - ); - }); - - it('should allow valid commands through PowerShell parser', () => { - // Mock spawnSync to avoid the overhead of spawning a real PowerShell process, - // which can lead to timeouts in CI environments even on Windows. - mockSpawnSync.mockReturnValue({ - status: 0, - stdout: JSON.stringify({ - success: true, - commands: [{ name: 'Get-ChildItem', text: 'Get-ChildItem' }], - }), - }); - - const { allowed } = isCommandAllowed('Get-ChildItem', config); - expect(allowed).toBe(true); - }); -}); - -describe('isShellInvocationAllowlisted', () => { - function createInvocation(command: string): AnyToolInvocation { - return { params: { command } } as unknown as AnyToolInvocation; - } - - it('should return false when any chained command segment is not allowlisted', () => { - const invocation = createInvocation( - 'git status && rm -rf /tmp/should-not-run', - ); - expect( - isShellInvocationAllowlisted(invocation, ['run_shell_command(git)']), - ).toBe(false); - }); - - it('should return true when every segment is explicitly allowlisted', () => { - const invocation = createInvocation( - 'git status && rm -rf /tmp/should-run && git diff', - ); - expect( - isShellInvocationAllowlisted(invocation, [ - 'run_shell_command(git)', - 'run_shell_command(rm -rf)', - ]), - ).toBe(true); - }); - - it('should return true when the allowlist contains a wildcard shell entry', () => { - const invocation = createInvocation('git status && rm -rf /tmp/should-run'); - expect( - isShellInvocationAllowlisted(invocation, ['run_shell_command']), - ).toBe(true); - }); - - it('should treat piped commands as separate segments that must be allowlisted', () => { - const invocation = createInvocation('git status | tail -n 1'); - expect( - isShellInvocationAllowlisted(invocation, ['run_shell_command(git)']), - ).toBe(false); - expect( - isShellInvocationAllowlisted(invocation, [ - 'run_shell_command(git)', - 'run_shell_command(tail)', - ]), - ).toBe(true); - }); -}); diff --git a/packages/core/src/utils/shell-permissions.ts b/packages/core/src/utils/shell-permissions.ts deleted file mode 100644 index 29f28b5410..0000000000 --- a/packages/core/src/utils/shell-permissions.ts +++ /dev/null @@ -1,270 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import type { AnyToolInvocation } from '../index.js'; -import type { Config } from '../config/config.js'; -import { doesToolInvocationMatch } from './tool-utils.js'; -import { - parseCommandDetails, - SHELL_TOOL_NAMES, - type ParsedCommandDetail, -} from './shell-utils.js'; - -/** - * Checks a shell command against security policies and allowlists. - * - * This function operates in one of two modes depending on the presence of - * the `sessionAllowlist` parameter: - * - * 1. **"Default Deny" Mode (sessionAllowlist is provided):** This is the - * strictest mode, used for user-defined scripts like custom commands. - * A command is only permitted if it is found on the global `coreTools` - * allowlist OR the provided `sessionAllowlist`. It must not be on the - * global `excludeTools` blocklist. - * - * 2. **"Default Allow" Mode (sessionAllowlist is NOT provided):** This mode - * is used for direct tool invocations (e.g., by the model). If a strict - * global `coreTools` allowlist exists, commands must be on it. Otherwise, - * any command is permitted as long as it is not on the `excludeTools` - * blocklist. - * - * @param command The shell command string to validate. - * @param config The application configuration. - * @param sessionAllowlist A session-level list of approved commands. Its - * presence activates "Default Deny" mode. - * @returns An object detailing which commands are not allowed. - */ -export function checkCommandPermissions( - command: string, - config: Config, - sessionAllowlist?: Set, -): { - allAllowed: boolean; - disallowedCommands: string[]; - blockReason?: string; - isHardDenial?: boolean; -} { - const parseResult = parseCommandDetails(command); - if (!parseResult || parseResult.hasError) { - return { - allAllowed: false, - disallowedCommands: [command], - blockReason: 'Command rejected because it could not be parsed safely', - isHardDenial: true, - }; - } - - const normalize = (cmd: string): string => cmd.trim().replace(/\s+/g, ' '); - const commandsToValidate = parseResult.details - .map((detail: ParsedCommandDetail) => normalize(detail.text)) - .filter(Boolean); - const invocation: AnyToolInvocation & { params: { command: string } } = { - params: { command: '' }, - } as AnyToolInvocation & { params: { command: string } }; - - // 1. Blocklist Check (Highest Priority) - const excludeTools = config.getExcludeTools() || new Set([]); - const isWildcardBlocked = SHELL_TOOL_NAMES.some((name) => - excludeTools.has(name), - ); - - if (isWildcardBlocked) { - return { - allAllowed: false, - disallowedCommands: commandsToValidate, - blockReason: 'Shell tool is globally disabled in configuration', - isHardDenial: true, - }; - } - - for (const cmd of commandsToValidate) { - invocation.params['command'] = cmd; - if ( - doesToolInvocationMatch('run_shell_command', invocation, [ - ...excludeTools, - ]) - ) { - return { - allAllowed: false, - disallowedCommands: [cmd], - blockReason: `Command '${cmd}' is blocked by configuration`, - isHardDenial: true, - }; - } - } - - const coreTools = config.getCoreTools() || []; - const isWildcardAllowed = SHELL_TOOL_NAMES.some((name) => - coreTools.includes(name), - ); - - // If there's a global wildcard, all commands are allowed at this point - // because they have already passed the blocklist check. - if (isWildcardAllowed) { - return { allAllowed: true, disallowedCommands: [] }; - } - - const disallowedCommands: string[] = []; - - if (sessionAllowlist) { - // "DEFAULT DENY" MODE: A session allowlist is provided. - // All commands must be in either the session or global allowlist. - const normalizedSessionAllowlist = new Set( - [...sessionAllowlist].flatMap((cmd) => - SHELL_TOOL_NAMES.map((name) => `${name}(${cmd})`), - ), - ); - - for (const cmd of commandsToValidate) { - invocation.params['command'] = cmd; - const isSessionAllowed = doesToolInvocationMatch( - 'run_shell_command', - invocation, - [...normalizedSessionAllowlist], - ); - if (isSessionAllowed) continue; - - const isGloballyAllowed = doesToolInvocationMatch( - 'run_shell_command', - invocation, - coreTools, - ); - if (isGloballyAllowed) continue; - - disallowedCommands.push(cmd); - } - - if (disallowedCommands.length > 0) { - return { - allAllowed: false, - disallowedCommands, - blockReason: `Command(s) not on the global or session allowlist. Disallowed commands: ${disallowedCommands - .map((c) => JSON.stringify(c)) - .join(', ')}`, - isHardDenial: false, // This is a soft denial; confirmation is possible. - }; - } - } else { - // "DEFAULT ALLOW" MODE: No session allowlist. - const hasSpecificAllowedCommands = - coreTools.filter((tool) => - SHELL_TOOL_NAMES.some((name) => tool.startsWith(`${name}(`)), - ).length > 0; - - if (hasSpecificAllowedCommands) { - for (const cmd of commandsToValidate) { - invocation.params['command'] = cmd; - const isGloballyAllowed = doesToolInvocationMatch( - 'run_shell_command', - invocation, - coreTools, - ); - if (!isGloballyAllowed) { - disallowedCommands.push(cmd); - } - } - if (disallowedCommands.length > 0) { - return { - allAllowed: false, - disallowedCommands, - blockReason: `Command(s) not in the allowed commands list. Disallowed commands: ${disallowedCommands - .map((c) => JSON.stringify(c)) - .join(', ')}`, - isHardDenial: false, - }; - } - } - // If no specific global allowlist exists, and it passed the blocklist, - // the command is allowed by default. - } - - // If all checks for the current mode pass, the command is allowed. - return { allAllowed: true, disallowedCommands: [] }; -} - -export function isCommandAllowed( - command: string, - config: Config, -): { allowed: boolean; reason?: string } { - // By not providing a sessionAllowlist, we invoke "default allow" behavior. - const { allAllowed, blockReason } = checkCommandPermissions(command, config); - if (allAllowed) { - return { allowed: true }; - } - return { allowed: false, reason: blockReason }; -} - -/** - * Determines whether a shell invocation should be auto-approved based on an allowlist. - * - * This reuses the same parsing logic as command-permission enforcement so that - * chained commands must be individually covered by the allowlist. - * - * @param invocation The shell tool invocation being evaluated. - * @param allowedPatterns The configured allowlist patterns (e.g. `run_shell_command(git)`). - * @returns True if every parsed command segment is allowed by the patterns; false otherwise. - */ -export function isShellInvocationAllowlisted( - invocation: AnyToolInvocation, - allowedPatterns: string[], -): boolean { - if (!allowedPatterns.length) { - return false; - } - - const hasShellWildcard = allowedPatterns.some((pattern) => - SHELL_TOOL_NAMES.includes(pattern), - ); - const hasShellSpecificPattern = allowedPatterns.some((pattern) => - SHELL_TOOL_NAMES.some((name) => pattern.startsWith(`${name}(`)), - ); - - if (!hasShellWildcard && !hasShellSpecificPattern) { - return false; - } - - if (hasShellWildcard) { - return true; - } - - if ( - !('params' in invocation) || - typeof invocation.params !== 'object' || - invocation.params === null || - !('command' in invocation.params) - ) { - return false; - } - - const commandValue = (invocation.params as { command?: unknown }).command; - if (typeof commandValue !== 'string' || !commandValue.trim()) { - return false; - } - - const command = commandValue.trim(); - - const parseResult = parseCommandDetails(command); - if (!parseResult || parseResult.hasError) { - return false; - } - - const normalize = (cmd: string): string => cmd.trim().replace(/\s+/g, ' '); - const commandsToValidate = parseResult.details - .map((detail: ParsedCommandDetail) => normalize(detail.text)) - .filter(Boolean); - - if (commandsToValidate.length === 0) { - return false; - } - - return commandsToValidate.every((commandSegment: string) => - doesToolInvocationMatch( - SHELL_TOOL_NAMES[0], - { params: { command: commandSegment } } as AnyToolInvocation, - allowedPatterns, - ), - ); -} From 416d243027d975c284a8ca939e2ebcbefdf5c07f Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 6 Jan 2026 23:58:13 -0800 Subject: [PATCH 031/713] Enhance TestRig with process management and timeouts (#15908) --- integration-tests/json-output.test.ts | 11 +- integration-tests/test-helper.ts | 235 +++++++++++++++++-------- packages/cli/src/utils/cleanup.test.ts | 60 +++---- packages/cli/src/utils/cleanup.ts | 10 ++ 4 files changed, 205 insertions(+), 111 deletions(-) diff --git a/integration-tests/json-output.test.ts b/integration-tests/json-output.test.ts index 7d364d8c6c..4d3bdb6a18 100644 --- a/integration-tests/json-output.test.ts +++ b/integration-tests/json-output.test.ts @@ -14,7 +14,6 @@ describe('JSON output', () => { beforeEach(async () => { rig = new TestRig(); - await rig.setup('json-output-test'); }); afterEach(async () => { @@ -22,6 +21,7 @@ describe('JSON output', () => { }); it('should return a valid JSON with response and stats', async () => { + await rig.setup('json-output-response-stats'); const result = await rig.run({ args: ['What is the capital of France?', '--output-format', 'json'], }); @@ -36,6 +36,7 @@ describe('JSON output', () => { }); it('should return a valid JSON with a session ID', async () => { + await rig.setup('json-output-session-id'); const result = await rig.run({ args: ['Hello', '--output-format', 'json'], }); @@ -47,7 +48,6 @@ describe('JSON output', () => { }); it('should return a JSON error for sd auth mismatch before running', async () => { - process.env['GOOGLE_GENAI_USE_GCA'] = 'true'; await rig.setup('json-output-auth-mismatch', { settings: { security: { @@ -58,12 +58,13 @@ describe('JSON output', () => { let thrown: Error | undefined; try { - await rig.run({ args: ['Hello', '--output-format', 'json'] }); + await rig.run({ + args: ['Hello', '--output-format', 'json'], + env: { GOOGLE_GENAI_USE_GCA: 'true' }, + }); expect.fail('Expected process to exit with error'); } catch (e) { thrown = e as Error; - } finally { - delete process.env['GOOGLE_GENAI_USE_GCA']; } expect(thrown).toBeDefined(); diff --git a/integration-tests/test-helper.ts b/integration-tests/test-helper.ts index 818951afd9..53b409b733 100644 --- a/integration-tests/test-helper.ts +++ b/integration-tests/test-helper.ts @@ -5,11 +5,12 @@ */ import { expect } from 'vitest'; -import { execSync, spawn } from 'node:child_process'; +import { execSync, spawn, type ChildProcess } from 'node:child_process'; import { mkdirSync, writeFileSync, readFileSync } from 'node:fs'; import { join, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import { env } from 'node:process'; +import { setTimeout as sleep } from 'node:timers/promises'; import { DEFAULT_GEMINI_MODEL } from '../packages/core/src/config/models.js'; import fs from 'node:fs'; import * as pty from '@lydell/node-pty'; @@ -45,7 +46,7 @@ export async function poll( if (result) { return true; } - await new Promise((resolve) => setTimeout(resolve, interval)); + await sleep(interval); } if (env['VERBOSE'] === 'true') { console.log(`Poll timed out after ${attempts} attempts`); @@ -212,7 +213,7 @@ export class InteractiveRun { if (char === '\r') { // wait >30ms before `enter` to avoid fast return conversion // from bufferFastReturn() in KeypressContent.tsx - await new Promise((resolve) => setTimeout(resolve, 50)); + await sleep(50); } this.ptyProcess.write(char); @@ -239,7 +240,7 @@ export class InteractiveRun { // but may run into paste detection issues for larger strings. async sendText(text: string) { this.ptyProcess.write(text); - await new Promise((resolve) => setTimeout(resolve, 5)); + await sleep(5); } // Simulates typing a string one character at a time to avoid paste detection. @@ -247,7 +248,7 @@ export class InteractiveRun { const delay = 5; for (const char of text) { this.ptyProcess.write(char); - await new Promise((resolve) => setTimeout(resolve, delay)); + await sleep(delay); } } @@ -282,6 +283,7 @@ export class TestRig { // Original fake responses file path for rewriting goldens in record mode. originalFakeResponsesPath?: string; private _interactiveRuns: InteractiveRun[] = []; + private _spawnedProcesses: ChildProcess[] = []; setup( testName: string, @@ -307,15 +309,16 @@ export class TestRig { } // Create a settings file to point the CLI to the local collector - const projectGeminiDir = join(this.testDir, GEMINI_DIR); + this._createSettingsFile(options.settings); + } + + private _createSettingsFile(overrideSettings?: Record) { + const projectGeminiDir = join(this.testDir!, GEMINI_DIR); mkdirSync(projectGeminiDir, { recursive: true }); // In sandbox mode, use an absolute path for telemetry inside the container // The container mounts the test directory at the same path as the host - const telemetryPath = join(this.homeDir, 'telemetry.log'); // Always use home directory for telemetry - - // Ensure the CLI uses our separate home directory for global state - process.env['GEMINI_CLI_HOME'] = this.homeDir; + const telemetryPath = join(this.homeDir!, 'telemetry.log'); // Always use home directory for telemetry const settings = { general: { @@ -343,7 +346,7 @@ export class TestRig { env['GEMINI_SANDBOX'] !== 'false' ? env['GEMINI_SANDBOX'] : false, // Don't show the IDE connection dialog when running from VsCode ide: { enabled: false, hasSeenNudge: true }, - ...options.settings, // Allow tests to override/add settings + ...overrideSettings, // Allow tests to override/add settings }; writeFileSync( join(projectGeminiDir, 'settings.json'), @@ -362,6 +365,7 @@ export class TestRig { } sync() { + if (os.platform() === 'win32') return; // ensure file system is done before spawning execSync('sync', { cwd: this.testDir! }); } @@ -396,6 +400,8 @@ export class TestRig { stdin?: string; stdinDoesNotEnd?: boolean; yolo?: boolean; + timeout?: number; + env?: Record; }): Promise { const yolo = options.yolo !== false; const { command, initialArgs } = this._getCommandAndArgs( @@ -426,8 +432,13 @@ export class TestRig { const child = spawn(command, commandArgs, { cwd: this.testDir!, stdio: 'pipe', - env: env, + env: { + ...process.env, + GEMINI_CLI_HOME: this.homeDir!, + ...options.env, + }, }); + this._spawnedProcesses.push(child); let stdout = ''; let stderr = ''; @@ -441,63 +452,46 @@ export class TestRig { child.stdin!.end(); } - child.stdout!.on('data', (data: Buffer) => { + child.stdout!.setEncoding('utf8'); + child.stdout!.on('data', (data: string) => { stdout += data; if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { process.stdout.write(data); } }); - child.stderr!.on('data', (data: Buffer) => { + child.stderr!.setEncoding('utf8'); + child.stderr!.on('data', (data: string) => { stderr += data; if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { process.stderr.write(data); } }); + const timeout = options.timeout ?? 120000; const promise = new Promise((resolve, reject) => { + const timer = setTimeout(() => { + child.kill('SIGKILL'); + reject( + new Error( + `Process timed out after ${timeout}ms.\nStdout:\n${stdout}\nStderr:\n${stderr}`, + ), + ); + }, timeout); + + child.on('error', (err) => { + clearTimeout(timer); + reject(err); + }); + child.on('close', (code: number) => { + clearTimeout(timer); if (code === 0) { // Store the raw stdout for Podman telemetry parsing this._lastRunStdout = stdout; // Filter out telemetry output when running with Podman - // Podman seems to output telemetry to stdout even when writing to file - let result = stdout; - if (env['GEMINI_SANDBOX'] === 'podman') { - // Remove telemetry JSON objects from output - // They are multi-line JSON objects that start with { and contain telemetry fields - const lines = result.split(os.EOL); - const filteredLines = []; - let inTelemetryObject = false; - let braceDepth = 0; - - for (const line of lines) { - if (!inTelemetryObject && line.trim() === '{') { - // Check if this might be start of telemetry object - inTelemetryObject = true; - braceDepth = 1; - } else if (inTelemetryObject) { - // Count braces to track nesting - for (const char of line) { - if (char === '{') braceDepth++; - else if (char === '}') braceDepth--; - } - - // Check if we've closed all braces - if (braceDepth === 0) { - inTelemetryObject = false; - // Skip this line (the closing brace) - continue; - } - } else { - // Not in telemetry object, keep the line - filteredLines.push(line); - } - } - - result = filteredLines.join('\n'); - } + const result = this._filterPodmanTelemetry(stdout); // Check if this is a JSON output test - if so, don't include stderr // as it would corrupt the JSON @@ -506,11 +500,12 @@ export class TestRig { commandArgs.includes('json'); // If we have stderr output and it's not a JSON test, include that also - if (stderr && !isJsonOutput) { - result += `\n\nStdErr:\n${stderr}`; - } + const finalResult = + stderr && !isJsonOutput + ? `${result}\n\nStdErr:\n${stderr}` + : result; - resolve(result); + resolve(finalResult); } else { reject(new Error(`Process exited with code ${code}:\n${stderr}`)); } @@ -520,9 +515,52 @@ export class TestRig { return promise; } + private _filterPodmanTelemetry(stdout: string): string { + if (env['GEMINI_SANDBOX'] !== 'podman') { + return stdout; + } + + // Remove telemetry JSON objects from output + // They are multi-line JSON objects that start with { and contain telemetry fields + const lines = stdout.split(os.EOL); + const filteredLines = []; + let inTelemetryObject = false; + let braceDepth = 0; + + for (const line of lines) { + if (!inTelemetryObject && line.trim() === '{') { + // Check if this might be start of telemetry object + inTelemetryObject = true; + braceDepth = 1; + } else if (inTelemetryObject) { + // Count braces to track nesting + for (const char of line) { + if (char === '{') braceDepth++; + else if (char === '}') braceDepth--; + } + + // Check if we've closed all braces + if (braceDepth === 0) { + inTelemetryObject = false; + // Skip this line (the closing brace) + continue; + } + } else { + // Not in telemetry object, keep the line + filteredLines.push(line); + } + } + + return filteredLines.join('\n'); + } + runCommand( args: string[], - options: { stdin?: string } = {}, + options: { + stdin?: string; + timeout?: number; + env?: Record; + } = {}, ): Promise { const { command, initialArgs } = this._getCommandAndArgs(); const commandArgs = [...initialArgs, ...args]; @@ -530,7 +568,13 @@ export class TestRig { const child = spawn(command, commandArgs, { cwd: this.testDir!, stdio: 'pipe', + env: { + ...process.env, + GEMINI_CLI_HOME: this.homeDir!, + ...options.env, + }, }); + this._spawnedProcesses.push(child); let stdout = ''; let stderr = ''; @@ -540,29 +584,55 @@ export class TestRig { child.stdin!.end(); } - child.stdout!.on('data', (data: Buffer) => { + child.stdout!.setEncoding('utf8'); + child.stdout!.on('data', (data: string) => { stdout += data; if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { process.stdout.write(data); } }); - child.stderr!.on('data', (data: Buffer) => { + child.stderr!.setEncoding('utf8'); + child.stderr!.on('data', (data: string) => { stderr += data; if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { process.stderr.write(data); } }); + const timeout = options.timeout ?? 120000; const promise = new Promise((resolve, reject) => { + const timer = setTimeout(() => { + child.kill('SIGKILL'); + reject( + new Error( + `Process timed out after ${timeout}ms.\nStdout:\n${stdout}\nStderr:\n${stderr}`, + ), + ); + }, timeout); + + child.on('error', (err) => { + clearTimeout(timer); + reject(err); + }); + child.on('close', (code: number) => { + clearTimeout(timer); if (code === 0) { this._lastRunStdout = stdout; - let result = stdout; - if (stderr) { - result += `\n\nStdErr:\n${stderr}`; - } - resolve(result); + const result = this._filterPodmanTelemetry(stdout); + + // Check if this is a JSON output test - if so, don't include stderr + // as it would corrupt the JSON + const isJsonOutput = + commandArgs.includes('--output-format') && + commandArgs.includes('json'); + + const finalResult = + stderr && !isJsonOutput + ? `${result}\n\nStdErr:\n${stderr}` + : result; + resolve(finalResult); } else { reject(new Error(`Process exited with code ${code}:\n${stderr}`)); } @@ -596,6 +666,23 @@ export class TestRig { } this._interactiveRuns = []; + // Kill any other spawned processes that are still running + for (const child of this._spawnedProcesses) { + if (child.exitCode === null && child.signalCode === null) { + try { + child.kill('SIGKILL'); + } catch (error) { + if (env['VERBOSE'] === 'true') { + console.warn( + 'Failed to kill spawned process during cleanup:', + error, + ); + } + } + } + } + this._spawnedProcesses = []; + if ( process.env['REGENERATE_MODEL_GOLDENS'] === 'true' && this.fakeResponsesPath @@ -732,7 +819,6 @@ export class TestRig { } async waitForAnyToolCall(toolNames: string[], timeout?: number) { - // Use environment-specific timeout if (!timeout) { timeout = getDefaultTimeout(); } @@ -980,7 +1066,7 @@ export class TestRig { const apiRequests = logs.filter( (logData) => logData.attributes && - logData.attributes['event.name'] === 'gemini_cli.api_request', + logData.attributes['event.name'] === `gemini_cli.api_request`, ); return apiRequests; } @@ -990,7 +1076,7 @@ export class TestRig { const apiRequests = logs.filter( (logData) => logData.attributes && - logData.attributes['event.name'] === 'gemini_cli.api_request', + logData.attributes['event.name'] === `gemini_cli.api_request`, ); return apiRequests.pop() || null; } @@ -1042,6 +1128,7 @@ export class TestRig { async runInteractive(options?: { args?: string | string[]; yolo?: boolean; + env?: Record; }): Promise { const yolo = options?.yolo !== false; const { command, initialArgs } = this._getCommandAndArgs( @@ -1049,13 +1136,11 @@ export class TestRig { ); const commandArgs = [...initialArgs]; - if (options?.args) { - if (Array.isArray(options.args)) { - commandArgs.push(...options.args); - } else { - commandArgs.push(options.args); - } - } + const envVars = { + ...process.env, + GEMINI_CLI_HOME: this.homeDir!, + ...options?.env, + }; const ptyOptions: pty.IPtyForkOptions = { name: 'xterm-color', @@ -1063,7 +1148,7 @@ export class TestRig { rows: 80, cwd: this.testDir!, env: Object.fromEntries( - Object.entries(env).filter(([, v]) => v !== undefined), + Object.entries(envVars).filter(([, v]) => v !== undefined), ) as { [key: string]: string }, }; @@ -1130,11 +1215,11 @@ export class TestRig { while (Date.now() - startTime < timeout) { await commandFn(); // Give it a moment to process - await new Promise((resolve) => setTimeout(resolve, 500)); + await sleep(500); if (predicateFn()) { return; } - await new Promise((resolve) => setTimeout(resolve, interval)); + await sleep(interval); } throw new Error(`pollCommand timed out after ${timeout}ms`); } diff --git a/packages/cli/src/utils/cleanup.test.ts b/packages/cli/src/utils/cleanup.test.ts index 64935d838d..3bc38e9110 100644 --- a/packages/cli/src/utils/cleanup.test.ts +++ b/packages/cli/src/utils/cleanup.test.ts @@ -12,6 +12,8 @@ vi.mock('@google/gemini-cli-core', () => ({ Storage: vi.fn().mockImplementation(() => ({ getProjectTempDir: vi.fn().mockReturnValue('/tmp/project'), })), + shutdownTelemetry: vi.fn(), + isTelemetrySdkInitialized: vi.fn().mockReturnValue(false), })); vi.mock('node:fs', () => ({ @@ -20,61 +22,61 @@ vi.mock('node:fs', () => ({ }, })); +import { + registerCleanup, + runExitCleanup, + registerSyncCleanup, + runSyncCleanup, + cleanupCheckpoints, + resetCleanupForTesting, +} from './cleanup.js'; + describe('cleanup', () => { beforeEach(async () => { - vi.resetModules(); vi.clearAllMocks(); - // No need to re-assign, we can use the imported functions directly - // because we are using vi.resetModules() and re-importing if necessary, - // but actually, since we are mocking dependencies, we might not need to re-import cleanup.js - // unless it has internal state that needs resetting. It does (cleanupFunctions array). - // So we DO need to re-import it to get fresh state. + resetCleanupForTesting(); }); it('should run a registered synchronous function', async () => { - const cleanupModule = await import('./cleanup.js'); const cleanupFn = vi.fn(); - cleanupModule.registerCleanup(cleanupFn); + registerCleanup(cleanupFn); - await cleanupModule.runExitCleanup(); + await runExitCleanup(); expect(cleanupFn).toHaveBeenCalledTimes(1); }); it('should run a registered asynchronous function', async () => { - const cleanupModule = await import('./cleanup.js'); const cleanupFn = vi.fn().mockResolvedValue(undefined); - cleanupModule.registerCleanup(cleanupFn); + registerCleanup(cleanupFn); - await cleanupModule.runExitCleanup(); + await runExitCleanup(); expect(cleanupFn).toHaveBeenCalledTimes(1); }); it('should run multiple registered functions', async () => { - const cleanupModule = await import('./cleanup.js'); const syncFn = vi.fn(); const asyncFn = vi.fn().mockResolvedValue(undefined); - cleanupModule.registerCleanup(syncFn); - cleanupModule.registerCleanup(asyncFn); + registerCleanup(syncFn); + registerCleanup(asyncFn); - await cleanupModule.runExitCleanup(); + await runExitCleanup(); expect(syncFn).toHaveBeenCalledTimes(1); expect(asyncFn).toHaveBeenCalledTimes(1); }); it('should continue running cleanup functions even if one throws an error', async () => { - const cleanupModule = await import('./cleanup.js'); const errorFn = vi.fn().mockImplementation(() => { throw new Error('test error'); }); const successFn = vi.fn(); - cleanupModule.registerCleanup(errorFn); - cleanupModule.registerCleanup(successFn); + registerCleanup(errorFn); + registerCleanup(successFn); - await expect(cleanupModule.runExitCleanup()).resolves.not.toThrow(); + await expect(runExitCleanup()).resolves.not.toThrow(); expect(errorFn).toHaveBeenCalledTimes(1); expect(successFn).toHaveBeenCalledTimes(1); @@ -82,23 +84,21 @@ describe('cleanup', () => { describe('sync cleanup', () => { it('should run registered sync functions', async () => { - const cleanupModule = await import('./cleanup.js'); const syncFn = vi.fn(); - cleanupModule.registerSyncCleanup(syncFn); - cleanupModule.runSyncCleanup(); + registerSyncCleanup(syncFn); + runSyncCleanup(); expect(syncFn).toHaveBeenCalledTimes(1); }); it('should continue running sync cleanup functions even if one throws', async () => { - const cleanupModule = await import('./cleanup.js'); const errorFn = vi.fn().mockImplementation(() => { throw new Error('test error'); }); const successFn = vi.fn(); - cleanupModule.registerSyncCleanup(errorFn); - cleanupModule.registerSyncCleanup(successFn); + registerSyncCleanup(errorFn); + registerSyncCleanup(successFn); - expect(() => cleanupModule.runSyncCleanup()).not.toThrow(); + expect(() => runSyncCleanup()).not.toThrow(); expect(errorFn).toHaveBeenCalledTimes(1); expect(successFn).toHaveBeenCalledTimes(1); }); @@ -106,8 +106,7 @@ describe('cleanup', () => { describe('cleanupCheckpoints', () => { it('should remove checkpoints directory', async () => { - const cleanupModule = await import('./cleanup.js'); - await cleanupModule.cleanupCheckpoints(); + await cleanupCheckpoints(); expect(fs.rm).toHaveBeenCalledWith( path.join('/tmp/project', 'checkpoints'), { @@ -118,9 +117,8 @@ describe('cleanup', () => { }); it('should ignore errors during checkpoint removal', async () => { - const cleanupModule = await import('./cleanup.js'); vi.mocked(fs.rm).mockRejectedValue(new Error('Failed to remove')); - await expect(cleanupModule.cleanupCheckpoints()).resolves.not.toThrow(); + await expect(cleanupCheckpoints()).resolves.not.toThrow(); }); }); }); diff --git a/packages/cli/src/utils/cleanup.ts b/packages/cli/src/utils/cleanup.ts index 5d063927a2..ccb467572b 100644 --- a/packages/cli/src/utils/cleanup.ts +++ b/packages/cli/src/utils/cleanup.ts @@ -25,6 +25,16 @@ export function registerSyncCleanup(fn: () => void) { syncCleanupFunctions.push(fn); } +/** + * Resets the internal cleanup state for testing purposes. + * This allows tests to run in isolation without vi.resetModules(). + */ +export function resetCleanupForTesting() { + cleanupFunctions.length = 0; + syncCleanupFunctions.length = 0; + configForTelemetry = null; +} + export function runSyncCleanup() { for (const fn of syncCleanupFunctions) { try { From 8f9bb6bccc65500a7d16078ffb3540407c2f90f6 Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Wed, 7 Jan 2026 10:11:35 -0500 Subject: [PATCH 032/713] Update troubleshooting doc for UNABLE_TO_GET_ISSUER_CERT_LOCALLY (#16069) --- docs/troubleshooting.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 2daac9cd95..27a2679e9c 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -43,9 +43,15 @@ topics on: - **Cause:** You may be on a corporate network with a firewall that intercepts and inspects SSL/TLS traffic. This often requires a custom root CA certificate to be trusted by Node.js. - - **Solution:** Set the `NODE_EXTRA_CA_CERTS` environment variable to the - absolute path of your corporate root CA certificate file. - - Example: `export NODE_EXTRA_CA_CERTS=/path/to/your/corporate-ca.crt` + - **Solution:** First try setting `NODE_USE_SYSTEM_CA`; if that does not + resolve the issue, set `NODE_EXTRA_CA_CERTS`. + - Set the `NODE_USE_SYSTEM_CA=1` environment variable to tell Node.js to use + the operating system's native certificate store (where corporate + certificates are typically already installed). + - Example: `export NODE_USE_SYSTEM_CA=1` + - Set the `NODE_EXTRA_CA_CERTS` environment variable to the absolute path of + your corporate root CA certificate file. + - Example: `export NODE_EXTRA_CA_CERTS=/path/to/your/corporate-ca.crt` ## Common error messages and solutions From d1eb87c81ffeb4f9faf162c69afa0a2149d3acca Mon Sep 17 00:00:00 2001 From: christine betts Date: Wed, 7 Jan 2026 10:47:29 -0500 Subject: [PATCH 033/713] Add keytar to dependencies (#15928) --- esbuild.config.js | 1 + package-lock.json | 63 ++++++++++++++++++-------------------- package.json | 1 + packages/core/package.json | 3 +- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/esbuild.config.js b/esbuild.config.js index 2b13adcbbb..23b9ed5977 100644 --- a/esbuild.config.js +++ b/esbuild.config.js @@ -62,6 +62,7 @@ const external = [ '@lydell/node-pty-linux-x64', '@lydell/node-pty-win32-arm64', '@lydell/node-pty-win32-x64', + 'keytar', ]; const baseConfig = { diff --git a/package-lock.json b/package-lock.json index 01288437c6..1830ea7295 100644 --- a/package-lock.json +++ b/package-lock.json @@ -72,6 +72,7 @@ "@lydell/node-pty-linux-x64": "1.1.0", "@lydell/node-pty-win32-arm64": "1.1.0", "@lydell/node-pty-win32-x64": "1.1.0", + "keytar": "^7.9.0", "node-pty": "^1.0.0" } }, @@ -2500,6 +2501,7 @@ "integrity": "sha512-t54CUOsFMappY1Jbzb7fetWeO0n6K0k/4+/ZpkS+3Joz8I4VcvY9OiEBFRYISqaI2fq5sCiPtAjRDOzVYG8m+Q==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@octokit/auth-token": "^6.0.0", "@octokit/graphql": "^9.0.2", @@ -2680,6 +2682,7 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", "integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==", "license": "Apache-2.0", + "peer": true, "engines": { "node": ">=8.0.0" } @@ -2713,6 +2716,7 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-2.0.1.tgz", "integrity": "sha512-MaZk9SJIDgo1peKevlbhP6+IwIiNPNmswNL4AF0WaQJLbHXjr9SrZMgS12+iqr9ToV4ZVosCcc0f8Rg67LXjxw==", "license": "Apache-2.0", + "peer": true, "dependencies": { "@opentelemetry/semantic-conventions": "^1.29.0" }, @@ -3081,6 +3085,7 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-2.0.1.tgz", "integrity": "sha512-dZOB3R6zvBwDKnHDTB4X1xtMArB/d324VsbiPkX/Yu0Q8T2xceRthoIVFhJdvgVM2QhGVUyX9tzwiNxGtoBJUw==", "license": "Apache-2.0", + "peer": true, "dependencies": { "@opentelemetry/core": "2.0.1", "@opentelemetry/semantic-conventions": "^1.29.0" @@ -3114,6 +3119,7 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-metrics/-/sdk-metrics-2.0.1.tgz", "integrity": "sha512-wf8OaJoSnujMAHWR3g+/hGvNcsC16rf9s1So4JlMiFaFHiE4HpIA3oUh+uWZQ7CNuK8gVW/pQSkgoa5HkkOl0g==", "license": "Apache-2.0", + "peer": true, "dependencies": { "@opentelemetry/core": "2.0.1", "@opentelemetry/resources": "2.0.1" @@ -3166,6 +3172,7 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-trace-base/-/sdk-trace-base-2.0.1.tgz", "integrity": "sha512-xYLlvk/xdScGx1aEqvxLwf6sXQLXCjk3/1SQT9X9AoN5rXRhkdvIFShuNNmtTEPRBqcsMbS4p/gJLNI2wXaDuQ==", "license": "Apache-2.0", + "peer": true, "dependencies": { "@opentelemetry/core": "2.0.1", "@opentelemetry/resources": "2.0.1", @@ -4403,6 +4410,7 @@ "integrity": "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA==", "devOptional": true, "license": "MIT", + "peer": true, "dependencies": { "csstype": "^3.0.2" } @@ -4680,6 +4688,7 @@ "integrity": "sha512-6sMvZePQrnZH2/cJkwRpkT7DxoAWh+g6+GFRK6bV3YQo7ogi3SX5rgF6099r5Q53Ma5qeT7LGmOmuIutF4t3lA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.35.0", "@typescript-eslint/types": "8.35.0", @@ -5691,6 +5700,7 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -6135,8 +6145,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/array-includes": { "version": "3.1.9", @@ -6499,7 +6508,6 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", - "dev": true, "license": "MIT", "optional": true, "dependencies": { @@ -6650,7 +6658,6 @@ "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", - "dev": true, "funding": [ { "type": "github", @@ -7426,7 +7433,6 @@ "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", "license": "MIT", - "peer": true, "dependencies": { "safe-buffer": "5.2.1" }, @@ -8208,7 +8214,6 @@ "version": "2.0.4", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.4.tgz", "integrity": "sha512-3UDv+G9CsCKO1WKMGw9fwq/SWJYbI0c5Y7LU1AXYoDdbhE2AHQ6N6Nb34sG8Fj7T5APy8qXDCKuuIHd1BR0tVA==", - "dev": true, "license": "Apache-2.0", "optional": true, "engines": { @@ -8750,6 +8755,7 @@ "integrity": "sha512-GsGizj2Y1rCWDu6XoEekL3RLilp0voSePurjZIkxL3wlm5o5EC9VpgaP7lrCvjnkuLvzFBQWB3vWB3K5KQTveQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", @@ -9258,7 +9264,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==", - "dev": true, "license": "(MIT OR WTFPL)", "optional": true, "engines": { @@ -9355,7 +9360,6 @@ "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz", "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==", "license": "MIT", - "peer": true, "engines": { "node": ">= 0.6" } @@ -9365,7 +9369,6 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "license": "MIT", - "peer": true, "dependencies": { "ms": "2.0.0" } @@ -9375,7 +9378,6 @@ "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", "license": "MIT", - "peer": true, "engines": { "node": ">= 0.8" } @@ -9629,7 +9631,6 @@ "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.1.tgz", "integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==", "license": "MIT", - "peer": true, "dependencies": { "debug": "2.6.9", "encodeurl": "~2.0.0", @@ -9648,7 +9649,6 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "license": "MIT", - "peer": true, "dependencies": { "ms": "2.0.0" } @@ -9657,15 +9657,13 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/finalhandler/node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", "license": "MIT", - "peer": true, "engines": { "node": ">= 0.8" } @@ -9871,7 +9869,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", - "dev": true, "license": "MIT", "optional": true }, @@ -10114,7 +10111,6 @@ "version": "0.0.0", "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", "integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==", - "dev": true, "license": "MIT", "optional": true }, @@ -10843,7 +10839,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "dev": true, + "devOptional": true, "funding": [ { "type": "github", @@ -10951,6 +10947,7 @@ "resolved": "https://registry.npmjs.org/@jrichman/ink/-/ink-6.4.6.tgz", "integrity": "sha512-QHl6l1cl3zPCaRMzt9TUbTX6Q5SzvkGEZDDad0DmSf5SPmT1/90k6pGPejEvDCJprkitwObXpPaTWGHItqsy4g==", "license": "MIT", + "peer": true, "dependencies": { "@alcalzone/ansi-tokenize": "^0.2.1", "ansi-escapes": "^7.0.0", @@ -12042,7 +12039,6 @@ "version": "7.9.0", "resolved": "https://registry.npmjs.org/keytar/-/keytar-7.9.0.tgz", "integrity": "sha512-VPD8mtVtm5JNtA2AErl6Chp06JBfy7diFQ7TQQhdpWOl6MrCRB+eRbvAZUsbGQS9kiMq0coJsy0W0vHpDCkWsQ==", - "dev": true, "hasInstallScript": true, "license": "MIT", "optional": true, @@ -12899,7 +12895,6 @@ "version": "0.5.3", "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", - "dev": true, "license": "MIT", "optional": true }, @@ -13079,7 +13074,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-2.0.0.tgz", "integrity": "sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA==", - "dev": true, "license": "MIT", "optional": true }, @@ -13110,7 +13104,6 @@ "version": "3.75.0", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.75.0.tgz", "integrity": "sha512-OhYaY5sDsIka7H7AtijtI9jwGYLyl29eQn/W623DiN/MIv5sUqc4g7BIDThX+gb7di9f6xK02nkp8sdfFWZLTg==", - "dev": true, "license": "MIT", "optional": true, "dependencies": { @@ -13124,7 +13117,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz", "integrity": "sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==", - "dev": true, "license": "MIT", "optional": true }, @@ -14144,8 +14136,7 @@ "version": "0.1.12", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/path-type": { "version": "3.0.0", @@ -14306,7 +14297,6 @@ "version": "7.1.3", "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz", "integrity": "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==", - "dev": true, "license": "MIT", "optional": true, "dependencies": { @@ -14726,6 +14716,7 @@ "resolved": "https://registry.npmjs.org/react/-/react-19.2.0.tgz", "integrity": "sha512-tmbWg6W31tQLeB5cdIBOicJDJRR2KzXsV7uSK9iNfLWQ5bIZfxuPEHp7M8wiHyHnn0DD1i7w3Zmin0FtkrwoCQ==", "license": "MIT", + "peer": true, "engines": { "node": ">=0.10.0" } @@ -14736,6 +14727,7 @@ "integrity": "sha512-ePrwPfxAnB+7hgnEr8vpKxL9cmnp7F322t8oqcPshbIQQhDKgFDW4tjhF2wjVbdXF9O/nyuy3sQWd9JGpiLPvA==", "devOptional": true, "license": "MIT", + "peer": true, "dependencies": { "shell-quote": "^1.6.1", "ws": "^7" @@ -15838,7 +15830,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==", - "dev": true, "funding": [ { "type": "github", @@ -15860,7 +15851,6 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz", "integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==", - "dev": true, "funding": [ { "type": "github", @@ -16665,7 +16655,6 @@ "version": "2.1.4", "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.4.tgz", "integrity": "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==", - "dev": true, "license": "MIT", "optional": true, "dependencies": { @@ -16679,7 +16668,6 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", - "dev": true, "license": "ISC", "optional": true }, @@ -16687,7 +16675,6 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", - "dev": true, "license": "MIT", "optional": true, "dependencies": { @@ -16985,6 +16972,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -17211,7 +17199,8 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "dev": true, - "license": "0BSD" + "license": "0BSD", + "peer": true }, "node_modules/tsx": { "version": "4.20.3", @@ -17219,6 +17208,7 @@ "integrity": "sha512-qjbnuR9Tr+FJOMBqJCW5ehvIo/buZq7vH7qD7JziU98h6l3qGy0a/yPFjwO+y0/T7GFpNgNAvEcPPVfyT8rrPQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "~0.25.0", "get-tsconfig": "^4.7.5" @@ -17247,7 +17237,6 @@ "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", - "dev": true, "license": "Apache-2.0", "optional": true, "dependencies": { @@ -17403,6 +17392,7 @@ "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -17565,7 +17555,6 @@ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", "license": "MIT", - "peer": true, "engines": { "node": ">= 0.4.0" } @@ -17621,6 +17610,7 @@ "integrity": "sha512-BxAKBWmIbrDgrokdGZH1IgkIk/5mMHDreLDmCJ0qpyJaAteP8NvMhkwr/ZCQNqNH97bw/dANTE9PDzqwJghfMQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", @@ -17737,6 +17727,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -17750,6 +17741,7 @@ "integrity": "sha512-LUCP5ev3GURDysTWiP47wRRUpLKMOfPh+yKTx3kVIEiu5KOMeqzpnYNsKyOoVrULivR8tLcks4+lga33Whn90A==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/chai": "^5.2.2", "@vitest/expect": "3.2.4", @@ -18456,6 +18448,7 @@ "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", "license": "MIT", + "peer": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } @@ -18957,6 +18950,7 @@ "@lydell/node-pty-linux-x64": "1.1.0", "@lydell/node-pty-win32-arm64": "1.1.0", "@lydell/node-pty-win32-x64": "1.1.0", + "keytar": "^7.9.0", "node-pty": "^1.0.0" } }, @@ -19019,6 +19013,7 @@ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, diff --git a/package.json b/package.json index 835b0535af..04c7077437 100644 --- a/package.json +++ b/package.json @@ -132,6 +132,7 @@ "@lydell/node-pty-linux-x64": "1.1.0", "@lydell/node-pty-win32-arm64": "1.1.0", "@lydell/node-pty-win32-x64": "1.1.0", + "keytar": "^7.9.0", "node-pty": "^1.0.0" }, "lint-staged": { diff --git a/packages/core/package.json b/packages/core/package.json index 5ca7859f4c..7bbeeed2fa 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -77,7 +77,8 @@ "@lydell/node-pty-linux-x64": "1.1.0", "@lydell/node-pty-win32-arm64": "1.1.0", "@lydell/node-pty-win32-x64": "1.1.0", - "node-pty": "^1.0.0" + "node-pty": "^1.0.0", + "keytar": "^7.9.0" }, "devDependencies": { "@google/gemini-cli-test-utils": "file:../test-utils", From 97b31c4eefab2a9b7b9dedfc0511c930cf8d85a9 Mon Sep 17 00:00:00 2001 From: christine betts Date: Wed, 7 Jan 2026 11:23:07 -0500 Subject: [PATCH 034/713] Simplify extension settings command (#16001) --- docs/extensions/index.md | 4 +- packages/cli/src/commands/extensions.tsx | 4 +- .../src/commands/extensions/configure.test.ts | 292 ++++++++++++++++++ .../cli/src/commands/extensions/configure.ts | 210 +++++++++++++ .../src/commands/extensions/settings.test.ts | 231 -------------- .../cli/src/commands/extensions/settings.ts | 162 ---------- packages/cli/src/commands/extensions/utils.ts | 7 +- packages/cli/src/config/extension-manager.ts | 2 +- .../extensions/extensionUpdates.test.ts | 22 +- 9 files changed, 514 insertions(+), 420 deletions(-) create mode 100644 packages/cli/src/commands/extensions/configure.test.ts create mode 100644 packages/cli/src/commands/extensions/configure.ts delete mode 100644 packages/cli/src/commands/extensions/settings.test.ts delete mode 100644 packages/cli/src/commands/extensions/settings.ts diff --git a/docs/extensions/index.md b/docs/extensions/index.md index 9d4d6c63cc..2c1ab9cd93 100644 --- a/docs/extensions/index.md +++ b/docs/extensions/index.md @@ -226,13 +226,13 @@ key. The value will be saved to a `.env` file in the extension's directory You can view a list of an extension's settings by running: ``` -gemini extensions settings list +gemini extensions list ``` and you can update a given setting using: ``` -gemini extensions settings set [--scope ] +gemini extensions config [setting name] [--scope ] ``` - `--scope`: The scope to set the setting in (`user` or `workspace`). This is diff --git a/packages/cli/src/commands/extensions.tsx b/packages/cli/src/commands/extensions.tsx index b2cf160e90..8079d67256 100644 --- a/packages/cli/src/commands/extensions.tsx +++ b/packages/cli/src/commands/extensions.tsx @@ -14,7 +14,7 @@ import { enableCommand } from './extensions/enable.js'; import { linkCommand } from './extensions/link.js'; import { newCommand } from './extensions/new.js'; import { validateCommand } from './extensions/validate.js'; -import { settingsCommand } from './extensions/settings.js'; +import { configureCommand } from './extensions/configure.js'; import { initializeOutputListenersAndFlush } from '../gemini.js'; export const extensionsCommand: CommandModule = { @@ -33,7 +33,7 @@ export const extensionsCommand: CommandModule = { .command(linkCommand) .command(newCommand) .command(validateCommand) - .command(settingsCommand) + .command(configureCommand) .demandCommand(1, 'You need at least one command before continuing.') .version(false), handler: () => { diff --git a/packages/cli/src/commands/extensions/configure.test.ts b/packages/cli/src/commands/extensions/configure.test.ts new file mode 100644 index 0000000000..70c30e6945 --- /dev/null +++ b/packages/cli/src/commands/extensions/configure.test.ts @@ -0,0 +1,292 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ +import { + describe, + it, + expect, + vi, + beforeEach, + afterEach, + type Mock, +} from 'vitest'; +import { configureCommand } from './configure.js'; +import yargs from 'yargs'; +import { debugLogger } from '@google/gemini-cli-core'; +import { + updateSetting, + promptForSetting, + getScopedEnvContents, + type ExtensionSetting, +} from '../../config/extensions/extensionSettings.js'; +import prompts from 'prompts'; + +const { + mockExtensionManager, + mockGetExtensionAndManager, + mockGetExtensionManager, + mockLoadSettings, +} = vi.hoisted(() => { + const extensionManager = { + loadExtensionConfig: vi.fn(), + getExtensions: vi.fn(), + loadExtensions: vi.fn(), + getSettings: vi.fn(), + }; + return { + mockExtensionManager: extensionManager, + mockGetExtensionAndManager: vi.fn(), + mockGetExtensionManager: vi.fn(), + mockLoadSettings: vi.fn().mockReturnValue({ merged: {} }), + }; +}); + +vi.mock('../../config/extension-manager.js', () => ({ + ExtensionManager: vi.fn().mockImplementation(() => mockExtensionManager), +})); + +vi.mock('../../config/extensions/extensionSettings.js', () => ({ + updateSetting: vi.fn(), + promptForSetting: vi.fn(), + getScopedEnvContents: vi.fn(), + ExtensionSettingScope: { + USER: 'user', + WORKSPACE: 'workspace', + }, +})); + +vi.mock('../utils.js', () => ({ + exitCli: vi.fn(), +})); + +vi.mock('./utils.js', () => ({ + getExtensionAndManager: mockGetExtensionAndManager, + getExtensionManager: mockGetExtensionManager, +})); + +vi.mock('prompts'); + +vi.mock('../../config/extensions/consent.js', () => ({ + requestConsentNonInteractive: vi.fn(), +})); + +import { ExtensionManager } from '../../config/extension-manager.js'; + +vi.mock('../../config/settings.js', () => ({ + loadSettings: mockLoadSettings, +})); + +describe('extensions configure command', () => { + beforeEach(() => { + vi.spyOn(debugLogger, 'log'); + vi.spyOn(debugLogger, 'error'); + vi.clearAllMocks(); + + // Default behaviors + mockLoadSettings.mockReturnValue({ merged: {} }); + mockGetExtensionAndManager.mockResolvedValue({ + extension: null, + extensionManager: null, + }); + mockGetExtensionManager.mockResolvedValue(mockExtensionManager); + (ExtensionManager as unknown as Mock).mockImplementation( + () => mockExtensionManager, + ); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + const runCommand = async (command: string) => { + const parser = yargs().command(configureCommand).help(false).version(false); + await parser.parse(command); + }; + + const setupExtension = ( + name: string, + settings: Array> = [], + id = 'test-id', + path = '/test/path', + ) => { + const extension = { name, path, id }; + mockGetExtensionAndManager.mockImplementation(async (n) => { + if (n === name) + return { extension, extensionManager: mockExtensionManager }; + return { extension: null, extensionManager: null }; + }); + + mockExtensionManager.getExtensions.mockReturnValue([extension]); + mockExtensionManager.loadExtensionConfig.mockResolvedValue({ + name, + settings, + }); + return extension; + }; + + describe('Specific setting configuration', () => { + it('should configure a specific setting', async () => { + setupExtension('test-ext', [ + { name: 'Test Setting', envVar: 'TEST_VAR' }, + ]); + (updateSetting as Mock).mockResolvedValue(undefined); + + await runCommand('config test-ext TEST_VAR'); + + expect(updateSetting).toHaveBeenCalledWith( + expect.objectContaining({ name: 'test-ext' }), + 'test-id', + 'TEST_VAR', + promptForSetting, + 'user', + ); + }); + + it('should handle missing extension', async () => { + mockGetExtensionAndManager.mockResolvedValue({ + extension: null, + extensionManager: null, + }); + + await runCommand('config missing-ext TEST_VAR'); + + expect(updateSetting).not.toHaveBeenCalled(); + }); + + it('should reject invalid extension names', async () => { + await runCommand('config ../invalid TEST_VAR'); + expect(debugLogger.error).toHaveBeenCalledWith( + expect.stringContaining('Invalid extension name'), + ); + + await runCommand('config ext/with/slash TEST_VAR'); + expect(debugLogger.error).toHaveBeenCalledWith( + expect.stringContaining('Invalid extension name'), + ); + }); + }); + + describe('Extension configuration (all settings)', () => { + it('should configure all settings for an extension', async () => { + const settings = [{ name: 'Setting 1', envVar: 'VAR_1' }]; + setupExtension('test-ext', settings); + (getScopedEnvContents as Mock).mockResolvedValue({}); + (updateSetting as Mock).mockResolvedValue(undefined); + + await runCommand('config test-ext'); + + expect(debugLogger.log).toHaveBeenCalledWith( + 'Configuring settings for "test-ext"...', + ); + expect(updateSetting).toHaveBeenCalledWith( + expect.objectContaining({ name: 'test-ext' }), + 'test-id', + 'VAR_1', + promptForSetting, + 'user', + ); + }); + + it('should verify overwrite if setting is already set', async () => { + const settings = [{ name: 'Setting 1', envVar: 'VAR_1' }]; + setupExtension('test-ext', settings); + (getScopedEnvContents as Mock).mockImplementation( + async (_config, _id, scope) => { + if (scope === 'user') return { VAR_1: 'existing' }; + return {}; + }, + ); + (prompts as unknown as Mock).mockResolvedValue({ overwrite: true }); + (updateSetting as Mock).mockResolvedValue(undefined); + + await runCommand('config test-ext'); + + expect(prompts).toHaveBeenCalledWith( + expect.objectContaining({ + type: 'confirm', + message: expect.stringContaining('is already set. Overwrite?'), + }), + ); + expect(updateSetting).toHaveBeenCalled(); + }); + + it('should note if setting is configured in workspace', async () => { + const settings = [{ name: 'Setting 1', envVar: 'VAR_1' }]; + setupExtension('test-ext', settings); + (getScopedEnvContents as Mock).mockImplementation( + async (_config, _id, scope) => { + if (scope === 'workspace') return { VAR_1: 'workspace_value' }; + return {}; + }, + ); + (updateSetting as Mock).mockResolvedValue(undefined); + + await runCommand('config test-ext'); + + expect(debugLogger.log).toHaveBeenCalledWith( + expect.stringContaining('is already configured in the workspace scope'), + ); + }); + + it('should skip update if user denies overwrite', async () => { + const settings = [{ name: 'Setting 1', envVar: 'VAR_1' }]; + setupExtension('test-ext', settings); + (getScopedEnvContents as Mock).mockResolvedValue({ VAR_1: 'existing' }); + (prompts as unknown as Mock).mockResolvedValue({ overwrite: false }); + + await runCommand('config test-ext'); + + expect(prompts).toHaveBeenCalled(); + expect(updateSetting).not.toHaveBeenCalled(); + }); + }); + + describe('Configure all extensions', () => { + it('should configure settings for all installed extensions', async () => { + const ext1 = { + name: 'ext1', + path: '/p1', + id: 'id1', + settings: [{ envVar: 'V1' }], + }; + const ext2 = { + name: 'ext2', + path: '/p2', + id: 'id2', + settings: [{ envVar: 'V2' }], + }; + mockExtensionManager.getExtensions.mockReturnValue([ext1, ext2]); + + mockExtensionManager.loadExtensionConfig.mockImplementation( + async (path) => { + if (path === '/p1') + return { name: 'ext1', settings: [{ name: 'S1', envVar: 'V1' }] }; + if (path === '/p2') + return { name: 'ext2', settings: [{ name: 'S2', envVar: 'V2' }] }; + return null; + }, + ); + + (getScopedEnvContents as Mock).mockResolvedValue({}); + (updateSetting as Mock).mockResolvedValue(undefined); + + await runCommand('config'); + + expect(debugLogger.log).toHaveBeenCalledWith( + expect.stringContaining('Configuring settings for "ext1"'), + ); + expect(debugLogger.log).toHaveBeenCalledWith( + expect.stringContaining('Configuring settings for "ext2"'), + ); + expect(updateSetting).toHaveBeenCalledTimes(2); + }); + + it('should log if no extensions installed', async () => { + mockExtensionManager.getExtensions.mockReturnValue([]); + await runCommand('config'); + expect(debugLogger.log).toHaveBeenCalledWith('No extensions installed.'); + }); + }); +}); diff --git a/packages/cli/src/commands/extensions/configure.ts b/packages/cli/src/commands/extensions/configure.ts new file mode 100644 index 0000000000..4ea3299610 --- /dev/null +++ b/packages/cli/src/commands/extensions/configure.ts @@ -0,0 +1,210 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type { CommandModule } from 'yargs'; +import { + updateSetting, + promptForSetting, + ExtensionSettingScope, + getScopedEnvContents, +} from '../../config/extensions/extensionSettings.js'; +import { getExtensionAndManager, getExtensionManager } from './utils.js'; +import { debugLogger } from '@google/gemini-cli-core'; +import { exitCli } from '../utils.js'; +import prompts from 'prompts'; +import type { ExtensionConfig } from '../../config/extension.js'; +interface ConfigureArgs { + name?: string; + setting?: string; + scope: string; +} + +export const configureCommand: CommandModule = { + command: 'config [name] [setting]', + describe: 'Configure extension settings.', + builder: (yargs) => + yargs + .positional('name', { + describe: 'Name of the extension to configure.', + type: 'string', + }) + .positional('setting', { + describe: 'The specific setting to configure (name or env var).', + type: 'string', + }) + .option('scope', { + describe: 'The scope to set the setting in.', + type: 'string', + choices: ['user', 'workspace'], + default: 'user', + }), + handler: async (args) => { + const { name, setting, scope } = args; + + if (name) { + if (name.includes('/') || name.includes('\\') || name.includes('..')) { + debugLogger.error( + 'Invalid extension name. Names cannot contain path separators or "..".', + ); + return; + } + } + + // Case 1: Configure specific setting for an extension + if (name && setting) { + await configureSpecificSetting( + name, + setting, + scope as ExtensionSettingScope, + ); + } + // Case 2: Configure all settings for an extension + else if (name) { + await configureExtension(name, scope as ExtensionSettingScope); + } + // Case 3: Configure all extensions + else { + await configureAllExtensions(scope as ExtensionSettingScope); + } + + await exitCli(); + }, +}; + +async function configureSpecificSetting( + extensionName: string, + settingKey: string, + scope: ExtensionSettingScope, +) { + const { extension, extensionManager } = + await getExtensionAndManager(extensionName); + if (!extension || !extensionManager) { + return; + } + const extensionConfig = await extensionManager.loadExtensionConfig( + extension.path, + ); + if (!extensionConfig) { + debugLogger.error( + `Could not find configuration for extension "${extensionName}".`, + ); + return; + } + + await updateSetting( + extensionConfig, + extension.id, + settingKey, + promptForSetting, + scope, + ); +} + +async function configureExtension( + extensionName: string, + scope: ExtensionSettingScope, +) { + const { extension, extensionManager } = + await getExtensionAndManager(extensionName); + if (!extension || !extensionManager) { + return; + } + const extensionConfig = await extensionManager.loadExtensionConfig( + extension.path, + ); + if ( + !extensionConfig || + !extensionConfig.settings || + extensionConfig.settings.length === 0 + ) { + debugLogger.log( + `Extension "${extensionName}" has no settings to configure.`, + ); + return; + } + + debugLogger.log(`Configuring settings for "${extensionName}"...`); + await configureExtensionSettings(extensionConfig, extension.id, scope); +} + +async function configureAllExtensions(scope: ExtensionSettingScope) { + const extensionManager = await getExtensionManager(); + const extensions = extensionManager.getExtensions(); + + if (extensions.length === 0) { + debugLogger.log('No extensions installed.'); + return; + } + + for (const extension of extensions) { + const extensionConfig = await extensionManager.loadExtensionConfig( + extension.path, + ); + if ( + extensionConfig && + extensionConfig.settings && + extensionConfig.settings.length > 0 + ) { + debugLogger.log(`\nConfiguring settings for "${extension.name}"...`); + await configureExtensionSettings(extensionConfig, extension.id, scope); + } + } +} + +async function configureExtensionSettings( + extensionConfig: ExtensionConfig, + extensionId: string, + scope: ExtensionSettingScope, +) { + const currentScopedSettings = await getScopedEnvContents( + extensionConfig, + extensionId, + scope, + ); + + let workspaceSettings: Record = {}; + if (scope === ExtensionSettingScope.USER) { + workspaceSettings = await getScopedEnvContents( + extensionConfig, + extensionId, + ExtensionSettingScope.WORKSPACE, + ); + } + + if (!extensionConfig.settings) return; + + for (const setting of extensionConfig.settings) { + const currentValue = currentScopedSettings[setting.envVar]; + const workspaceValue = workspaceSettings[setting.envVar]; + + if (workspaceValue !== undefined) { + debugLogger.log( + `Note: Setting "${setting.name}" is already configured in the workspace scope.`, + ); + } + + if (currentValue !== undefined) { + const response = await prompts({ + type: 'confirm', + name: 'overwrite', + message: `Setting "${setting.name}" (${setting.envVar}) is already set. Overwrite?`, + initial: false, + }); + + if (!response.overwrite) { + continue; + } + } + + await updateSetting( + extensionConfig, + extensionId, + setting.envVar, + promptForSetting, + scope, + ); + } +} diff --git a/packages/cli/src/commands/extensions/settings.test.ts b/packages/cli/src/commands/extensions/settings.test.ts deleted file mode 100644 index db8c14a922..0000000000 --- a/packages/cli/src/commands/extensions/settings.test.ts +++ /dev/null @@ -1,231 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import { - describe, - it, - expect, - vi, - beforeEach, - afterEach, - type Mock, -} from 'vitest'; -import { settingsCommand } from './settings.js'; -import yargs from 'yargs'; -import { debugLogger, type GeminiCLIExtension } from '@google/gemini-cli-core'; -import type { getExtensionAndManager } from './utils.js'; -import type { - updateSetting, - getScopedEnvContents, -} from '../../config/extensions/extensionSettings.js'; -import { - promptForSetting, - ExtensionSettingScope, -} from '../../config/extensions/extensionSettings.js'; -import type { exitCli } from '../utils.js'; -import type { ExtensionManager } from '../../config/extension-manager.js'; - -const mockGetExtensionAndManager: Mock = - vi.hoisted(() => vi.fn()); -const mockUpdateSetting: Mock = vi.hoisted(() => vi.fn()); -const mockGetScopedEnvContents: Mock = vi.hoisted( - () => vi.fn(), -); -const mockExitCli: Mock = vi.hoisted(() => vi.fn()); - -vi.mock('./utils.js', () => ({ - getExtensionAndManager: mockGetExtensionAndManager, -})); - -vi.mock('../../config/extensions/extensionSettings.js', () => ({ - updateSetting: mockUpdateSetting, - promptForSetting: vi.fn(), - ExtensionSettingScope: { - USER: 'user', - WORKSPACE: 'workspace', - }, - getScopedEnvContents: mockGetScopedEnvContents, -})); - -vi.mock('@google/gemini-cli-core', () => ({ - debugLogger: { - log: vi.fn(), - error: vi.fn(), - }, -})); - -vi.mock('../utils.js', () => ({ - exitCli: mockExitCli, -})); - -describe('settings command', () => { - let debugLogSpy: Mock; - let debugErrorSpy: Mock; - - beforeEach(() => { - debugLogSpy = debugLogger.log as Mock; - debugErrorSpy = debugLogger.error as Mock; - }); - - afterEach(() => { - vi.clearAllMocks(); - }); - - describe('set command', () => { - it('should log error and exit if extension is not found', async () => { - mockGetExtensionAndManager.mockResolvedValue({ - extension: null, - extensionManager: null, - }); - - await yargs([]) - .command(settingsCommand) - .parseAsync('settings set foo bar'); - - expect(mockExitCli).toHaveBeenCalled(); - }); - - it('should log error and exit if extension config is not found', async () => { - const mockExtensionManager = { - loadExtensionConfig: vi.fn().mockResolvedValue(null), - } as unknown as ExtensionManager; - mockGetExtensionAndManager.mockResolvedValue({ - extension: { path: '/path/to/ext' } as unknown as GeminiCLIExtension, - extensionManager: mockExtensionManager, - }); - - await yargs([]) - .command(settingsCommand) - .parseAsync('settings set foo bar'); - - expect(debugErrorSpy).toHaveBeenCalledWith( - 'Could not find configuration for extension "foo".', - ); - expect(mockExitCli).toHaveBeenCalled(); - }); - - it('should call updateSetting with correct arguments', async () => { - const mockExtensionManager = { - loadExtensionConfig: vi.fn().mockResolvedValue({}), - } as unknown as ExtensionManager; - const extension = { path: '/path/to/ext', id: 'ext-id' }; - mockGetExtensionAndManager.mockResolvedValue({ - extension: extension as unknown as GeminiCLIExtension, - extensionManager: mockExtensionManager, - }); - - await yargs([]) - .command(settingsCommand) - .parseAsync('settings set foo bar --scope workspace'); - - expect(mockUpdateSetting).toHaveBeenCalledWith( - {}, - 'ext-id', - 'bar', - promptForSetting, - ExtensionSettingScope.WORKSPACE, - ); - expect(mockExitCli).toHaveBeenCalled(); - }); - }); - - describe('list command', () => { - it('should log error and exit if extension is not found', async () => { - mockGetExtensionAndManager.mockResolvedValue({ - extension: null, - extensionManager: null, - }); - - await yargs([]).command(settingsCommand).parseAsync('settings list foo'); - - expect(mockExitCli).toHaveBeenCalled(); - }); - - it('should log message and exit if extension has no settings', async () => { - const mockExtensionManager = { - loadExtensionConfig: vi.fn().mockResolvedValue({ settings: [] }), - } as unknown as ExtensionManager; - mockGetExtensionAndManager.mockResolvedValue({ - extension: { path: '/path/to/ext' } as unknown as GeminiCLIExtension, - extensionManager: mockExtensionManager, - }); - - await yargs([]).command(settingsCommand).parseAsync('settings list foo'); - - expect(debugLogSpy).toHaveBeenCalledWith( - 'Extension "foo" has no settings to configure.', - ); - expect(mockExitCli).toHaveBeenCalled(); - }); - - it('should list settings correctly', async () => { - const mockExtensionManager = { - loadExtensionConfig: vi.fn().mockResolvedValue({ - settings: [ - { - name: 'Setting 1', - envVar: 'SETTING_1', - description: 'Desc 1', - sensitive: false, - }, - { - name: 'Setting 2', - envVar: 'SETTING_2', - description: 'Desc 2', - sensitive: true, - }, - { - name: 'Setting 3', - envVar: 'SETTING_3', - description: 'Desc 3', - sensitive: false, - }, - ], - }), - } as unknown as ExtensionManager; - const extension = { path: '/path/to/ext', id: 'ext-id' }; - mockGetExtensionAndManager.mockResolvedValue({ - extension: extension as unknown as GeminiCLIExtension, - extensionManager: mockExtensionManager, - }); - - mockGetScopedEnvContents.mockImplementation((_config, _id, scope) => { - if (scope === ExtensionSettingScope.USER) { - return Promise.resolve({ - SETTING_1: 'val1', - SETTING_2: 'val2', - }); - } - if (scope === ExtensionSettingScope.WORKSPACE) { - return Promise.resolve({ - SETTING_3: 'val3', - }); - } - return Promise.resolve({}); - }); - - await yargs([]).command(settingsCommand).parseAsync('settings list foo'); - - expect(debugLogSpy).toHaveBeenCalledWith('Settings for "foo":'); - // Setting 1 (User) - expect(debugLogSpy).toHaveBeenCalledWith('\n- Setting 1 (SETTING_1)'); - expect(debugLogSpy).toHaveBeenCalledWith(' Description: Desc 1'); - expect(debugLogSpy).toHaveBeenCalledWith(' Value: val1 (user)'); - // Setting 2 (Sensitive) - expect(debugLogSpy).toHaveBeenCalledWith('\n- Setting 2 (SETTING_2)'); - expect(debugLogSpy).toHaveBeenCalledWith(' Description: Desc 2'); - expect(debugLogSpy).toHaveBeenCalledWith( - ' Value: [value stored in keychain] (user)', - ); - // Setting 3 (Workspace) - expect(debugLogSpy).toHaveBeenCalledWith('\n- Setting 3 (SETTING_3)'); - expect(debugLogSpy).toHaveBeenCalledWith(' Description: Desc 3'); - expect(debugLogSpy).toHaveBeenCalledWith(' Value: val3 (workspace)'); - - expect(mockExitCli).toHaveBeenCalled(); - }); - }); -}); diff --git a/packages/cli/src/commands/extensions/settings.ts b/packages/cli/src/commands/extensions/settings.ts deleted file mode 100644 index f373534d7a..0000000000 --- a/packages/cli/src/commands/extensions/settings.ts +++ /dev/null @@ -1,162 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import type { CommandModule } from 'yargs'; -import { - updateSetting, - promptForSetting, - ExtensionSettingScope, - getScopedEnvContents, -} from '../../config/extensions/extensionSettings.js'; -import { getExtensionAndManager } from './utils.js'; -import { debugLogger } from '@google/gemini-cli-core'; -import { exitCli } from '../utils.js'; - -// --- SET COMMAND --- -interface SetArgs { - name: string; - setting: string; - scope: string; -} - -const setCommand: CommandModule = { - command: 'set [--scope] ', - describe: 'Set a specific setting for an extension.', - builder: (yargs) => - yargs - .positional('name', { - describe: 'Name of the extension to configure.', - type: 'string', - demandOption: true, - }) - .positional('setting', { - describe: 'The setting to configure (name or env var).', - type: 'string', - demandOption: true, - }) - .option('scope', { - describe: 'The scope to set the setting in.', - type: 'string', - choices: ['user', 'workspace'], - default: 'user', - }), - handler: async (args) => { - const { name, setting, scope } = args; - const { extension, extensionManager } = await getExtensionAndManager(name); - if (!extension || !extensionManager) { - await exitCli(); - return; - } - const extensionConfig = await extensionManager.loadExtensionConfig( - extension.path, - ); - if (!extensionConfig) { - debugLogger.error( - `Could not find configuration for extension "${name}".`, - ); - await exitCli(); - return; - } - await updateSetting( - extensionConfig, - extension.id, - setting, - promptForSetting, - scope as ExtensionSettingScope, - ); - await exitCli(); - }, -}; - -// --- LIST COMMAND --- -interface ListArgs { - name: string; -} - -const listCommand: CommandModule = { - command: 'list ', - describe: 'List all settings for an extension.', - builder: (yargs) => - yargs.positional('name', { - describe: 'Name of the extension.', - type: 'string', - demandOption: true, - }), - handler: async (args) => { - const { name } = args; - const { extension, extensionManager } = await getExtensionAndManager(name); - if (!extension || !extensionManager) { - await exitCli(); - return; - } - const extensionConfig = await extensionManager.loadExtensionConfig( - extension.path, - ); - if ( - !extensionConfig || - !extensionConfig.settings || - extensionConfig.settings.length === 0 - ) { - debugLogger.log(`Extension "${name}" has no settings to configure.`); - await exitCli(); - return; - } - - const userSettings = await getScopedEnvContents( - extensionConfig, - extension.id, - ExtensionSettingScope.USER, - ); - const workspaceSettings = await getScopedEnvContents( - extensionConfig, - extension.id, - ExtensionSettingScope.WORKSPACE, - ); - const mergedSettings = { ...userSettings, ...workspaceSettings }; - - debugLogger.log(`Settings for "${name}":`); - for (const setting of extensionConfig.settings) { - const value = mergedSettings[setting.envVar]; - let displayValue: string; - let scopeInfo = ''; - - if (workspaceSettings[setting.envVar] !== undefined) { - scopeInfo = ' (workspace)'; - } else if (userSettings[setting.envVar] !== undefined) { - scopeInfo = ' (user)'; - } - - if (value === undefined) { - displayValue = '[not set]'; - } else if (setting.sensitive) { - displayValue = '[value stored in keychain]'; - } else { - displayValue = value; - } - debugLogger.log(` -- ${setting.name} (${setting.envVar})`); - debugLogger.log(` Description: ${setting.description}`); - debugLogger.log(` Value: ${displayValue}${scopeInfo}`); - } - await exitCli(); - }, -}; - -// --- SETTINGS COMMAND --- -export const settingsCommand: CommandModule = { - command: 'settings ', - describe: 'Manage extension settings.', - builder: (yargs) => - yargs - .command(setCommand) - .command(listCommand) - .demandCommand(1, 'You need to specify a command (set or list).') - .version(false), - handler: () => { - // This handler is not called when a subcommand is provided. - // Yargs will show the help menu. - }, -}; diff --git a/packages/cli/src/commands/extensions/utils.ts b/packages/cli/src/commands/extensions/utils.ts index 9e0ee97f40..1571c56794 100644 --- a/packages/cli/src/commands/extensions/utils.ts +++ b/packages/cli/src/commands/extensions/utils.ts @@ -10,7 +10,7 @@ import { loadSettings } from '../../config/settings.js'; import { requestConsentNonInteractive } from '../../config/extensions/consent.js'; import { debugLogger } from '@google/gemini-cli-core'; -export async function getExtensionAndManager(name: string) { +export async function getExtensionManager() { const workspaceDir = process.cwd(); const extensionManager = new ExtensionManager({ workspaceDir, @@ -19,6 +19,11 @@ export async function getExtensionAndManager(name: string) { settings: loadSettings(workspaceDir).merged, }); await extensionManager.loadExtensions(); + return extensionManager; +} + +export async function getExtensionAndManager(name: string) { + const extensionManager = await getExtensionManager(); const extension = extensionManager .getExtensions() .find((ext) => ext.name === name); diff --git a/packages/cli/src/config/extension-manager.ts b/packages/cli/src/config/extension-manager.ts index d5fe2ad2b1..3c4ed226c8 100644 --- a/packages/cli/src/config/extension-manager.ts +++ b/packages/cli/src/config/extension-manager.ts @@ -309,7 +309,7 @@ Would you like to attempt to install via "git clone" instead?`, .map((s) => s.name) .join( ', ', - )}. Please run "gemini extensions settings ${newExtensionConfig.name} " to configure them.`; + )}. Please run "gemini extensions config ${newExtensionConfig.name} [setting-name]" to configure them.`; debugLogger.warn(message); coreEvents.emitFeedback('warning', message); } diff --git a/packages/cli/src/config/extensions/extensionUpdates.test.ts b/packages/cli/src/config/extensions/extensionUpdates.test.ts index 3ba11981bb..bdd2841ad6 100644 --- a/packages/cli/src/config/extensions/extensionUpdates.test.ts +++ b/packages/cli/src/config/extensions/extensionUpdates.test.ts @@ -266,26 +266,6 @@ describe('extensionUpdates', () => { vi.spyOn(fs.promises, 'writeFile').mockResolvedValue(undefined); vi.spyOn(fs.promises, 'rm').mockResolvedValue(undefined); vi.mocked(fs.existsSync).mockReturnValue(false); // No hooks - - // Mock copyExtension? It's imported. - // We can rely on ignoring the failure if we mock enough. - // Actually copyExtension is called. We need to mock it if it does real IO. - // But we can just let it fail or mock fs.cp if it uses it. - // Let's assume the other mocks cover the critical path to the warning. - // Warning happens BEFORE copyExtension? - // No, warning is after copyExtension usually. - // But in my code: - // const missingSettings = await getMissingSettings(...) - // if (missingSettings.length > 0) debugLogger.warn(...) - // ... - // copyExtension(...) - - // Wait, let's check extension-manager.ts order. - // Line 303: getMissingSettings - // Line 317: if (installMetadata.type === 'local' ...) copyExtension - - // So getMissingSettings is called BEFORE copyExtension. - try { await manager.installOrUpdateExtension(installMetadata, previousConfig); } catch (_) { @@ -300,7 +280,7 @@ describe('extensionUpdates', () => { expect(coreEvents.emitFeedback).toHaveBeenCalledWith( 'warning', expect.stringContaining( - 'Please run "gemini extensions settings test-ext "', + 'Please run "gemini extensions config test-ext [setting-name]"', ), ); }); From db99beda36912b2a568fb2f986241843c60cce4d Mon Sep 17 00:00:00 2001 From: Shreya Keshive Date: Wed, 7 Jan 2026 11:31:17 -0500 Subject: [PATCH 035/713] feat(admin): implement extensions disabled (#16024) --- packages/cli/src/config/config.ts | 2 + packages/cli/src/config/extension-manager.ts | 22 ++++-- packages/cli/src/config/extension.test.ts | 71 +++++++++++++++++++ .../src/services/BuiltinCommandLoader.test.ts | 2 + .../cli/src/services/BuiltinCommandLoader.ts | 21 +++++- packages/core/src/config/config.ts | 7 ++ 6 files changed, 117 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index aa00fbe9f2..2c9bdcee51 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -637,6 +637,7 @@ export async function loadCliConfig( const ptyInfo = await getPty(); const mcpEnabled = settings.admin?.mcp?.enabled ?? true; + const extensionsEnabled = settings.admin?.extensions?.enabled ?? true; return new Config({ sessionId, @@ -659,6 +660,7 @@ export async function loadCliConfig( mcpServerCommand: mcpEnabled ? settings.mcp?.serverCommand : undefined, mcpServers: mcpEnabled ? settings.mcpServers : {}, mcpEnabled, + extensionsEnabled, allowedMcpServers: mcpEnabled ? (argv.allowedMcpServerNames ?? settings.mcp?.allowed) : undefined, diff --git a/packages/cli/src/config/extension-manager.ts b/packages/cli/src/config/extension-manager.ts index 3c4ed226c8..998b91529c 100644 --- a/packages/cli/src/config/extension-manager.ts +++ b/packages/cli/src/config/extension-manager.ts @@ -465,6 +465,12 @@ Would you like to attempt to install via "git clone" instead?`, if (this.loadedExtensions) { throw new Error('Extensions already loaded, only load extensions once.'); } + + if (this.settings.admin?.extensions?.enabled === false) { + this.loadedExtensions = []; + return this.loadedExtensions; + } + const extensionsDir = ExtensionStorage.getUserExtensionsDir(); this.loadedExtensions = []; if (!fs.existsSync(extensionsDir)) { @@ -537,12 +543,16 @@ Would you like to attempt to install via "git clone" instead?`, } if (config.mcpServers) { - config.mcpServers = Object.fromEntries( - Object.entries(config.mcpServers).map(([key, value]) => [ - key, - filterMcpConfig(value), - ]), - ); + if (this.settings.admin?.mcp?.enabled === false) { + config.mcpServers = undefined; + } else { + config.mcpServers = Object.fromEntries( + Object.entries(config.mcpServers).map(([key, value]) => [ + key, + filterMcpConfig(value), + ]), + ); + } } const contextFiles = getContextFileNames(config) diff --git a/packages/cli/src/config/extension.test.ts b/packages/cli/src/config/extension.test.ts index 0bfa7a0358..d4b15d760b 100644 --- a/packages/cli/src/config/extension.test.ts +++ b/packages/cli/src/config/extension.test.ts @@ -632,6 +632,77 @@ describe('extension tests', () => { expect(extension).toBeUndefined(); }); + it('should not load any extensions if admin.extensions.enabled is false', async () => { + createExtension({ + extensionsDir: userExtensionsDir, + name: 'test-extension', + version: '1.0.0', + }); + const loadedSettings = loadSettings(tempWorkspaceDir); + loadedSettings.setValue( + SettingScope.System, + 'admin.extensions.enabled', + false, + ); + extensionManager = new ExtensionManager({ + workspaceDir: tempWorkspaceDir, + requestConsent: mockRequestConsent, + requestSetting: mockPromptForSettings, + settings: loadedSettings.merged, + }); + + const extensions = await extensionManager.loadExtensions(); + expect(extensions).toEqual([]); + }); + + it('should not load mcpServers if admin.mcp.enabled is false', async () => { + createExtension({ + extensionsDir: userExtensionsDir, + name: 'test-extension', + version: '1.0.0', + mcpServers: { + 'test-server': { command: 'echo', args: ['hello'] }, + }, + }); + const loadedSettings = loadSettings(tempWorkspaceDir); + loadedSettings.setValue(SettingScope.System, 'admin.mcp.enabled', false); + extensionManager = new ExtensionManager({ + workspaceDir: tempWorkspaceDir, + requestConsent: mockRequestConsent, + requestSetting: mockPromptForSettings, + settings: loadedSettings.merged, + }); + + const extensions = await extensionManager.loadExtensions(); + expect(extensions).toHaveLength(1); + expect(extensions[0].mcpServers).toBeUndefined(); + }); + + it('should load mcpServers if admin.mcp.enabled is true', async () => { + createExtension({ + extensionsDir: userExtensionsDir, + name: 'test-extension', + version: '1.0.0', + mcpServers: { + 'test-server': { command: 'echo', args: ['hello'] }, + }, + }); + const loadedSettings = loadSettings(tempWorkspaceDir); + loadedSettings.setValue(SettingScope.System, 'admin.mcp.enabled', true); + extensionManager = new ExtensionManager({ + workspaceDir: tempWorkspaceDir, + requestConsent: mockRequestConsent, + requestSetting: mockPromptForSettings, + settings: loadedSettings.merged, + }); + + const extensions = await extensionManager.loadExtensions(); + expect(extensions).toHaveLength(1); + expect(extensions[0].mcpServers).toEqual({ + 'test-server': { command: 'echo', args: ['hello'] }, + }); + }); + describe('id generation', () => { it.each([ { diff --git a/packages/cli/src/services/BuiltinCommandLoader.test.ts b/packages/cli/src/services/BuiltinCommandLoader.test.ts index b99d58239e..af6c4176ec 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.test.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.test.ts @@ -101,6 +101,7 @@ describe('BuiltinCommandLoader', () => { getFolderTrust: vi.fn().mockReturnValue(true), getEnableExtensionReloading: () => false, getEnableHooks: () => false, + getExtensionsEnabled: vi.fn().mockReturnValue(true), isSkillsSupportEnabled: vi.fn().mockReturnValue(false), getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ @@ -199,6 +200,7 @@ describe('BuiltinCommandLoader profile', () => { getCheckpointingEnabled: () => false, getEnableExtensionReloading: () => false, getEnableHooks: () => false, + getExtensionsEnabled: vi.fn().mockReturnValue(true), isSkillsSupportEnabled: vi.fn().mockReturnValue(false), getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ diff --git a/packages/cli/src/services/BuiltinCommandLoader.ts b/packages/cli/src/services/BuiltinCommandLoader.ts index 31395c0172..aef44e6210 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.ts @@ -76,7 +76,24 @@ export class BuiltinCommandLoader implements ICommandLoader { docsCommand, directoryCommand, editorCommand, - extensionsCommand(this.config?.getEnableExtensionReloading()), + ...(this.config?.getExtensionsEnabled() === false + ? [ + { + name: 'extensions', + description: 'Manage extensions', + kind: CommandKind.BUILT_IN, + autoExecute: false, + subCommands: [], + action: async ( + _context: CommandContext, + ): Promise => ({ + type: 'message', + messageType: 'error', + content: 'Extensions are disabled by your admin.', + }), + }, + ] + : [extensionsCommand(this.config?.getEnableExtensionReloading())]), helpCommand, ...(this.config?.getEnableHooks() ? [hooksCommand] : []), await ideCommand(), @@ -95,7 +112,7 @@ export class BuiltinCommandLoader implements ICommandLoader { ): Promise => ({ type: 'message', messageType: 'error', - content: 'MCP disabled by your admin.', + content: 'MCP is disabled by your admin.', }), }, ] diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 10c06950b8..9314a3d0b3 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -356,6 +356,7 @@ export interface ConfigParameters { experimentalJitContext?: boolean; onModelChange?: (model: string) => void; mcpEnabled?: boolean; + extensionsEnabled?: boolean; onReload?: () => Promise<{ disabledSkills?: string[] }>; } @@ -390,6 +391,7 @@ export class Config { private readonly toolCallCommand: string | undefined; private readonly mcpServerCommand: string | undefined; private readonly mcpEnabled: boolean; + private readonly extensionsEnabled: boolean; private mcpServers: Record | undefined; private userMemory: string; private geminiMdFileCount: number; @@ -515,6 +517,7 @@ export class Config { this.mcpServerCommand = params.mcpServerCommand; this.mcpServers = params.mcpServers; this.mcpEnabled = params.mcpEnabled ?? true; + this.extensionsEnabled = params.extensionsEnabled ?? true; this.allowedMcpServers = params.allowedMcpServers ?? []; this.blockedMcpServers = params.blockedMcpServers ?? []; this.allowedEnvironmentVariables = params.allowedEnvironmentVariables ?? []; @@ -1140,6 +1143,10 @@ export class Config { return this.mcpEnabled; } + getExtensionsEnabled(): boolean { + return this.extensionsEnabled; + } + getMcpClientManager(): McpClientManager | undefined { return this.mcpClientManager; } From 57012ae5b33bcccee2e90e345447df5bbf653a3d Mon Sep 17 00:00:00 2001 From: Adib234 <30782825+Adib234@users.noreply.github.com> Date: Wed, 7 Jan 2026 12:10:22 -0500 Subject: [PATCH 036/713] Core data structure updates for Rewind functionality (#15714) --- .../components/messages/ToolMessage.test.tsx | 1 + .../useToolScheduler.test.ts.snap | 1 + packages/core/src/core/client.test.ts | 33 ++++++++++++ packages/core/src/core/client.ts | 14 ++++- packages/core/src/core/coreToolScheduler.ts | 1 + packages/core/src/core/geminiChat.ts | 5 +- .../src/services/chatRecordingService.test.ts | 53 +++++++++++++++++++ .../core/src/services/chatRecordingService.ts | 35 ++++++++++-- packages/core/src/telemetry/loggers.test.ts | 1 + packages/core/src/tools/edit.ts | 2 + packages/core/src/tools/tools.ts | 2 + packages/core/src/tools/write-file.ts | 2 + 12 files changed, 145 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/ui/components/messages/ToolMessage.test.tsx b/packages/cli/src/ui/components/messages/ToolMessage.test.tsx index 983bca8669..fb01c4d9bc 100644 --- a/packages/cli/src/ui/components/messages/ToolMessage.test.tsx +++ b/packages/cli/src/ui/components/messages/ToolMessage.test.tsx @@ -182,6 +182,7 @@ describe('', () => { fileName: 'file.txt', originalContent: 'old', newContent: 'new', + filePath: 'file.txt', }; const { lastFrame } = renderWithContext( , diff --git a/packages/cli/src/ui/hooks/__snapshots__/useToolScheduler.test.ts.snap b/packages/cli/src/ui/hooks/__snapshots__/useToolScheduler.test.ts.snap index 871be0e764..24ff4e1356 100644 --- a/packages/cli/src/ui/hooks/__snapshots__/useToolScheduler.test.ts.snap +++ b/packages/cli/src/ui/hooks/__snapshots__/useToolScheduler.test.ts.snap @@ -64,6 +64,7 @@ exports[`useReactToolScheduler > should handle tool requiring confirmation - can "resultDisplay": { "fileDiff": "Mock tool requires confirmation", "fileName": "mockToolRequiresConfirmation.ts", + "filePath": undefined, "newContent": undefined, "originalContent": undefined, }, diff --git a/packages/core/src/core/client.test.ts b/packages/core/src/core/client.test.ts index 6045088c04..16f78d40d8 100644 --- a/packages/core/src/core/client.test.ts +++ b/packages/core/src/core/client.test.ts @@ -38,6 +38,7 @@ import { ideContextStore } from '../ide/ideContext.js'; import type { ModelRouterService } from '../routing/modelRouterService.js'; import { uiTelemetryService } from '../telemetry/uiTelemetry.js'; import { ChatCompressionService } from '../services/chatCompressionService.js'; +import type { ChatRecordingService } from '../services/chatRecordingService.js'; import { createAvailabilityServiceMock } from '../availability/testUtils.js'; import type { ModelAvailabilityService } from '../availability/modelAvailabilityService.js'; import type { @@ -397,6 +398,10 @@ describe('Gemini Client (client.ts)', () => { getHistory: vi.fn((_curated?: boolean) => chatHistory), setHistory: vi.fn(), getLastPromptTokenCount: vi.fn().mockReturnValue(originalTokenCount), + getChatRecordingService: vi.fn().mockReturnValue({ + getConversation: vi.fn().mockReturnValue(null), + getConversationFilePath: vi.fn().mockReturnValue(null), + }), }; client['chat'] = mockOriginalChat as GeminiChat; @@ -617,6 +622,34 @@ describe('Gemini Client (client.ts)', () => { newTokenCount: 50, }); }); + + it('should resume the session file when compression succeeds', async () => { + const { client, mockOriginalChat } = setup({ + compressionStatus: CompressionStatus.COMPRESSED, + }); + + const mockConversation = { some: 'conversation' }; + const mockFilePath = '/tmp/session.json'; + + // Override the mock to return values + const mockRecordingService = { + getConversation: vi.fn().mockReturnValue(mockConversation), + getConversationFilePath: vi.fn().mockReturnValue(mockFilePath), + }; + vi.mocked(mockOriginalChat.getChatRecordingService!).mockReturnValue( + mockRecordingService as unknown as ChatRecordingService, + ); + + await client.tryCompressChat('prompt-id', false); + + expect(client['startChat']).toHaveBeenCalledWith( + expect.anything(), // newHistory + { + conversation: mockConversation, + filePath: mockFilePath, + }, + ); + }); }); describe('sendMessageStream', () => { diff --git a/packages/core/src/core/client.ts b/packages/core/src/core/client.ts index 48da7e43e7..bf70aa2200 100644 --- a/packages/core/src/core/client.ts +++ b/packages/core/src/core/client.ts @@ -972,7 +972,19 @@ export class GeminiClient { this.hasFailedCompressionAttempt || !force; } else if (info.compressionStatus === CompressionStatus.COMPRESSED) { if (newHistory) { - this.chat = await this.startChat(newHistory); + // capture current session data before resetting + const currentRecordingService = + this.getChat().getChatRecordingService(); + const conversation = currentRecordingService.getConversation(); + const filePath = currentRecordingService.getConversationFilePath(); + + let resumedData: ResumedSessionData | undefined; + + if (conversation && filePath) { + resumedData = { conversation, filePath }; + } + + this.chat = await this.startChat(newHistory, resumedData); this.updateTelemetryTokenCount(); this.forceFullIdeContext = true; } diff --git a/packages/core/src/core/coreToolScheduler.ts b/packages/core/src/core/coreToolScheduler.ts index 69a2e03475..1120074248 100644 --- a/packages/core/src/core/coreToolScheduler.ts +++ b/packages/core/src/core/coreToolScheduler.ts @@ -279,6 +279,7 @@ export class CoreToolScheduler { originalContent: waitingCall.confirmationDetails.originalContent, newContent: waitingCall.confirmationDetails.newContent, + filePath: waitingCall.confirmationDetails.filePath, }; } } diff --git a/packages/core/src/core/geminiChat.ts b/packages/core/src/core/geminiChat.ts index 3dc91e1b6c..3bc928c6fb 100644 --- a/packages/core/src/core/geminiChat.ts +++ b/packages/core/src/core/geminiChat.ts @@ -838,7 +838,10 @@ export class GeminiChat { const toolCallRecords = toolCalls.map((call) => { const resultDisplayRaw = call.response?.resultDisplay; const resultDisplay = - typeof resultDisplayRaw === 'string' ? resultDisplayRaw : undefined; + typeof resultDisplayRaw === 'string' || + (typeof resultDisplayRaw === 'object' && resultDisplayRaw !== null) + ? resultDisplayRaw + : undefined; return { id: call.request.callId, diff --git a/packages/core/src/services/chatRecordingService.test.ts b/packages/core/src/services/chatRecordingService.test.ts index dcd77c986f..6fb49fbd5f 100644 --- a/packages/core/src/services/chatRecordingService.test.ts +++ b/packages/core/src/services/chatRecordingService.test.ts @@ -401,4 +401,57 @@ describe('ChatRecordingService', () => { ); }); }); + + describe('rewindTo', () => { + it('should rewind the conversation to a specific message ID', () => { + chatRecordingService.initialize(); + const initialConversation = { + sessionId: 'test-session-id', + projectHash: 'test-project-hash', + messages: [ + { id: '1', type: 'user', content: 'msg1' }, + { id: '2', type: 'gemini', content: 'msg2' }, + { id: '3', type: 'user', content: 'msg3' }, + ], + }; + vi.spyOn(fs, 'readFileSync').mockReturnValue( + JSON.stringify(initialConversation), + ); + const writeFileSyncSpy = vi + .spyOn(fs, 'writeFileSync') + .mockImplementation(() => undefined); + + const result = chatRecordingService.rewindTo('2'); + + if (!result) throw new Error('Result should not be null'); + expect(result.messages).toHaveLength(1); + expect(result.messages[0].id).toBe('1'); + expect(writeFileSyncSpy).toHaveBeenCalled(); + const savedConversation = JSON.parse( + writeFileSyncSpy.mock.calls[0][1] as string, + ) as ConversationRecord; + expect(savedConversation.messages).toHaveLength(1); + }); + + it('should return the original conversation if the message ID is not found', () => { + chatRecordingService.initialize(); + const initialConversation = { + sessionId: 'test-session-id', + projectHash: 'test-project-hash', + messages: [{ id: '1', type: 'user', content: 'msg1' }], + }; + vi.spyOn(fs, 'readFileSync').mockReturnValue( + JSON.stringify(initialConversation), + ); + const writeFileSyncSpy = vi + .spyOn(fs, 'writeFileSync') + .mockImplementation(() => undefined); + + const result = chatRecordingService.rewindTo('non-existent'); + + if (!result) throw new Error('Result should not be null'); + expect(result.messages).toHaveLength(1); + expect(writeFileSyncSpy).not.toHaveBeenCalled(); + }); + }); }); diff --git a/packages/core/src/services/chatRecordingService.ts b/packages/core/src/services/chatRecordingService.ts index 0f4dab0f49..b308cce789 100644 --- a/packages/core/src/services/chatRecordingService.ts +++ b/packages/core/src/services/chatRecordingService.ts @@ -16,6 +16,7 @@ import type { GenerateContentResponseUsageMetadata, } from '@google/genai'; import { debugLogger } from '../utils/debugLogger.js'; +import type { ToolResultDisplay } from '../tools/tools.js'; export const SESSION_FILE_PREFIX = 'session-'; @@ -53,7 +54,7 @@ export interface ToolCallRecord { // UI-specific fields for display purposes displayName?: string; description?: string; - resultDisplay?: string; + resultDisplay?: ToolResultDisplay; renderOutputAsMarkdown?: boolean; } @@ -407,11 +408,14 @@ export class ChatRecordingService { /** * Saves the conversation record; overwrites the file. */ - private writeConversation(conversation: ConversationRecord): void { + private writeConversation( + conversation: ConversationRecord, + { allowEmpty = false }: { allowEmpty?: boolean } = {}, + ): void { try { if (!this.conversationFile) return; // Don't write the file yet until there's at least one message. - if (conversation.messages.length === 0) return; + if (conversation.messages.length === 0 && !allowEmpty) return; // Only write the file if this change would change the file. if (this.cachedLastConvData !== JSON.stringify(conversation, null, 2)) { @@ -492,4 +496,29 @@ export class ChatRecordingService { throw error; } } + + /** + * Rewinds the conversation to the state just before the specified message ID. + * All messages from (and including) the specified ID onwards are removed. + */ + rewindTo(messageId: string): ConversationRecord | null { + if (!this.conversationFile) { + return null; + } + const conversation = this.readConversation(); + const messageIndex = conversation.messages.findIndex( + (m) => m.id === messageId, + ); + + if (messageIndex === -1) { + debugLogger.error( + 'Message to rewind to not found in conversation history', + ); + return conversation; + } + + conversation.messages = conversation.messages.slice(0, messageIndex); + this.writeConversation(conversation, { allowEmpty: true }); + return conversation; + } } diff --git a/packages/core/src/telemetry/loggers.test.ts b/packages/core/src/telemetry/loggers.test.ts index 3dabc4a89d..c0023a1680 100644 --- a/packages/core/src/telemetry/loggers.test.ts +++ b/packages/core/src/telemetry/loggers.test.ts @@ -1053,6 +1053,7 @@ describe('loggers', () => { resultDisplay: { fileDiff: 'diff', fileName: 'file.txt', + filePath: 'file.txt', originalContent: 'old content', newContent: 'new content', diffStat: { diff --git a/packages/core/src/tools/edit.ts b/packages/core/src/tools/edit.ts index 3f71bdaad0..85c86ff804 100644 --- a/packages/core/src/tools/edit.ts +++ b/packages/core/src/tools/edit.ts @@ -818,9 +818,11 @@ class EditToolInvocation displayResult = { fileDiff, fileName, + filePath: this.params.file_path, originalContent: editData.currentContent, newContent: editData.newContent, diffStat, + isNewFile: editData.isNewFile, }; } diff --git a/packages/core/src/tools/tools.ts b/packages/core/src/tools/tools.ts index 1b6f6f92ee..d3efd56ec1 100644 --- a/packages/core/src/tools/tools.ts +++ b/packages/core/src/tools/tools.ts @@ -647,9 +647,11 @@ export interface Todo { export interface FileDiff { fileDiff: string; fileName: string; + filePath: string; originalContent: string | null; newContent: string; diffStat?: DiffStat; + isNewFile?: boolean; } export interface DiffStat { diff --git a/packages/core/src/tools/write-file.ts b/packages/core/src/tools/write-file.ts index 339a60b4b6..3dbb696acc 100644 --- a/packages/core/src/tools/write-file.ts +++ b/packages/core/src/tools/write-file.ts @@ -346,9 +346,11 @@ class WriteFileToolInvocation extends BaseToolInvocation< const displayResult: FileDiff = { fileDiff, fileName, + filePath: this.resolvedPath, originalContent: correctedContentResult.originalContent, newContent: correctedContentResult.correctedContent, diffStat, + isNewFile, }; return { From c64b5ec4a3a0c2e50e046ab012733024435612df Mon Sep 17 00:00:00 2001 From: Vedant Mahajan Date: Thu, 8 Jan 2026 00:41:49 +0530 Subject: [PATCH 037/713] feat(hooks): simplify hook firing with HookSystem wrapper methods (#15982) Co-authored-by: Ishaan Gupta --- packages/cli/src/gemini.test.tsx | 10 +++++ packages/cli/src/gemini.tsx | 55 ++++++++++-------------- packages/cli/src/gemini_cleanup.test.tsx | 1 + packages/core/src/hooks/hookSystem.ts | 40 ++++++++++++++++- 4 files changed, 72 insertions(+), 34 deletions(-) diff --git a/packages/cli/src/gemini.test.tsx b/packages/cli/src/gemini.test.tsx index f98cd7c3c9..f8bfa55383 100644 --- a/packages/cli/src/gemini.test.tsx +++ b/packages/cli/src/gemini.test.tsx @@ -269,6 +269,7 @@ describe('gemini.tsx main function', () => { subscribe: vi.fn(), }), getEnableHooks: () => false, + getHookSystem: () => undefined, getToolRegistry: vi.fn(), getContentGeneratorConfig: vi.fn(), getModel: () => 'gemini-pro', @@ -505,6 +506,7 @@ describe('gemini.tsx main function kitty protocol', () => { subscribe: vi.fn(), }), getEnableHooks: () => false, + getHookSystem: () => undefined, getToolRegistry: vi.fn(), getContentGeneratorConfig: vi.fn(), getModel: () => 'gemini-pro', @@ -609,6 +611,7 @@ describe('gemini.tsx main function kitty protocol', () => { getPolicyEngine: vi.fn(), getMessageBus: () => ({ subscribe: vi.fn() }), getEnableHooks: () => false, + getHookSystem: () => undefined, initialize: vi.fn(), getContentGeneratorConfig: vi.fn(), getMcpServers: () => ({}), @@ -692,6 +695,7 @@ describe('gemini.tsx main function kitty protocol', () => { getPolicyEngine: vi.fn(), getMessageBus: () => ({ subscribe: vi.fn() }), getEnableHooks: () => false, + getHookSystem: () => undefined, initialize: vi.fn(), getContentGeneratorConfig: vi.fn(), getMcpServers: () => ({}), @@ -760,6 +764,7 @@ describe('gemini.tsx main function kitty protocol', () => { getPolicyEngine: vi.fn(), getMessageBus: () => ({ subscribe: vi.fn() }), getEnableHooks: () => false, + getHookSystem: () => undefined, initialize: vi.fn(), getContentGeneratorConfig: vi.fn(), getMcpServers: () => ({}), @@ -843,6 +848,7 @@ describe('gemini.tsx main function kitty protocol', () => { getPolicyEngine: vi.fn(), getMessageBus: () => ({ subscribe: vi.fn() }), getEnableHooks: () => false, + getHookSystem: () => undefined, initialize: vi.fn(), getContentGeneratorConfig: vi.fn(), getMcpServers: () => ({}), @@ -923,6 +929,7 @@ describe('gemini.tsx main function kitty protocol', () => { getPolicyEngine: vi.fn(), getMessageBus: () => ({ subscribe: vi.fn() }), getEnableHooks: () => false, + getHookSystem: () => undefined, initialize: vi.fn(), getContentGeneratorConfig: vi.fn(), getMcpServers: () => ({}), @@ -997,6 +1004,7 @@ describe('gemini.tsx main function kitty protocol', () => { getPolicyEngine: vi.fn(), getMessageBus: () => ({ subscribe: vi.fn() }), getEnableHooks: () => false, + getHookSystem: () => undefined, initialize: vi.fn(), getContentGeneratorConfig: vi.fn(), getMcpServers: () => ({}), @@ -1170,6 +1178,7 @@ describe('gemini.tsx main function exit codes', () => { getPolicyEngine: vi.fn(), getMessageBus: () => ({ subscribe: vi.fn() }), getEnableHooks: () => false, + getHookSystem: () => undefined, getToolRegistry: vi.fn(), getContentGeneratorConfig: vi.fn(), getModel: () => 'gemini-pro', @@ -1234,6 +1243,7 @@ describe('gemini.tsx main function exit codes', () => { getPolicyEngine: vi.fn(), getMessageBus: () => ({ subscribe: vi.fn() }), getEnableHooks: () => false, + getHookSystem: () => undefined, getToolRegistry: vi.fn(), getContentGeneratorConfig: vi.fn(), getModel: () => 'gemini-pro', diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index 4a0096150a..b3ce41f7fe 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -64,8 +64,6 @@ import { ExitCodes, SessionStartSource, SessionEndReason, - fireSessionStartHook, - fireSessionEndHook, getVersion, } from '@google/gemini-cli-core'; import { @@ -491,11 +489,9 @@ export async function main() { // Register SessionEnd hook to fire on graceful exit // This runs before telemetry shutdown in runExitCleanup() - if (config.getEnableHooks() && messageBus) { - registerCleanup(async () => { - await fireSessionEndHook(messageBus, SessionEndReason.Exit); - }); - } + registerCleanup(async () => { + await config.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Exit); + }); // Cleanup sessions after config initialization try { @@ -646,36 +642,29 @@ export async function main() { // Fire SessionStart hook through MessageBus (only if hooks are enabled) // Must be called AFTER config.initialize() to ensure HookRegistry is loaded - const hooksEnabled = config.getEnableHooks(); - const hookMessageBus = config.getMessageBus(); - if (hooksEnabled && hookMessageBus) { - const sessionStartSource = resumedSessionData - ? SessionStartSource.Resume - : SessionStartSource.Startup; - const result = await fireSessionStartHook( - hookMessageBus, - sessionStartSource, - ); + const sessionStartSource = resumedSessionData + ? SessionStartSource.Resume + : SessionStartSource.Startup; + const result = await config + .getHookSystem() + ?.fireSessionStartEvent(sessionStartSource); - if (result) { - if (result.systemMessage) { - writeToStderr(result.systemMessage + '\n'); - } - const additionalContext = result.getAdditionalContext(); - if (additionalContext) { - // Prepend context to input (System Context -> Stdin -> Question) - input = input - ? `${additionalContext}\n\n${input}` - : additionalContext; - } + if (result?.finalOutput) { + if (result.finalOutput.systemMessage) { + writeToStderr(result.finalOutput.systemMessage + '\n'); + } + const additionalContext = result.finalOutput.getAdditionalContext(); + if (additionalContext) { + // Prepend context to input (System Context -> Stdin -> Question) + input = input ? `${additionalContext}\n\n${input}` : additionalContext; } - - // Register SessionEnd hook for graceful exit - registerCleanup(async () => { - await fireSessionEndHook(hookMessageBus, SessionEndReason.Exit); - }); } + // Register SessionEnd hook for graceful exit + registerCleanup(async () => { + await config.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Exit); + }); + if (!input) { debugLogger.error( `No input provided via stdin. Input can be provided by piping data into gemini or using the --prompt option.`, diff --git a/packages/cli/src/gemini_cleanup.test.tsx b/packages/cli/src/gemini_cleanup.test.tsx index 95471ef031..e198d3e887 100644 --- a/packages/cli/src/gemini_cleanup.test.tsx +++ b/packages/cli/src/gemini_cleanup.test.tsx @@ -189,6 +189,7 @@ describe('gemini.tsx main function cleanup', () => { getPolicyEngine: vi.fn(), getMessageBus: () => ({ subscribe: vi.fn() }), getEnableHooks: vi.fn(() => false), + getHookSystem: () => undefined, initialize: vi.fn(), getContentGeneratorConfig: vi.fn(), getMcpServers: () => ({}), diff --git a/packages/core/src/hooks/hookSystem.ts b/packages/core/src/hooks/hookSystem.ts index 3f170368a9..98f7baf817 100644 --- a/packages/core/src/hooks/hookSystem.ts +++ b/packages/core/src/hooks/hookSystem.ts @@ -14,11 +14,17 @@ import type { HookRegistryEntry } from './hookRegistry.js'; import { logs, type Logger } from '@opentelemetry/api-logs'; import { SERVICE_NAME } from '../telemetry/constants.js'; import { debugLogger } from '../utils/debugLogger.js'; - +import type { + SessionStartSource, + SessionEndReason, + PreCompressTrigger, +} from './types.js'; +import type { AggregatedHookResult } from './hookAggregator.js'; /** * Main hook system that coordinates all hook-related functionality */ export class HookSystem { + private readonly config: Config; private readonly hookRegistry: HookRegistry; private readonly hookRunner: HookRunner; private readonly hookAggregator: HookAggregator; @@ -26,6 +32,7 @@ export class HookSystem { private readonly hookEventHandler: HookEventHandler; constructor(config: Config) { + this.config = config; const logger: Logger = logs.getLogger(SERVICE_NAME); const messageBus = config.getMessageBus(); @@ -79,4 +86,35 @@ export class HookSystem { getAllHooks(): HookRegistryEntry[] { return this.hookRegistry.getAllHooks(); } + + /** + * Fire hook events directly + * Returns undefined if hooks are disabled + */ + async fireSessionStartEvent( + source: SessionStartSource, + ): Promise { + if (!this.config.getEnableHooks()) { + return undefined; + } + return this.hookEventHandler.fireSessionStartEvent(source); + } + + async fireSessionEndEvent( + reason: SessionEndReason, + ): Promise { + if (!this.config.getEnableHooks()) { + return undefined; + } + return this.hookEventHandler.fireSessionEndEvent(reason); + } + + async firePreCompressEvent( + trigger: PreCompressTrigger, + ): Promise { + if (!this.config.getEnableHooks()) { + return undefined; + } + return this.hookEventHandler.firePreCompressEvent(trigger); + } } From 143bb63483ad432cb3184a693e95f7a7179cb563 Mon Sep 17 00:00:00 2001 From: Gaurav <39389231+gsquared94@users.noreply.github.com> Date: Wed, 7 Jan 2026 11:26:25 -0800 Subject: [PATCH 038/713] Add exp.gws_experiment field to LogEventEntry (#16062) --- .../clearcut-logger/clearcut-logger.test.ts | 58 +++++++++++++++++-- .../clearcut-logger/clearcut-logger.ts | 25 +++++--- 2 files changed, 71 insertions(+), 12 deletions(-) diff --git a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts index c7cc10cdaa..349fa182eb 100644 --- a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts +++ b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts @@ -93,6 +93,22 @@ expect.extend({ `event ${received} ${isNot ? 'has' : 'does not have'} the metadata key ${key}`, }; }, + + toHaveGwsExperiments(received: LogEventEntry[], exps: number[]) { + const { isNot } = this; + const gwsExperiment = received[0].exp?.gws_experiment; + + const pass = + gwsExperiment !== undefined && + gwsExperiment.length === exps.length && + gwsExperiment.every((val, idx) => val === exps[idx]); + + return { + pass, + message: () => + `exp.gws_experiment ${JSON.stringify(gwsExperiment)} does${isNot ? '' : ' not'} match ${JSON.stringify(exps)}`, + }; + }, }); vi.mock('../../utils/userAccountManager.js'); @@ -850,19 +866,53 @@ describe('ClearcutLogger', () => { }); describe('logExperiments', () => { - it('logs an event with gws_experiment field containing exp ids', () => { + it('async path includes exp.gws_experiment field with experiment IDs', async () => { const { logger } = setup(); - const event = new AgentStartEvent('agent-123', 'TestAgent'); + const event = logger!.createLogEvent(EventNames.START_SESSION, []); - logger?.logAgentStartEvent(event); + await logger?.enqueueLogEventAfterExperimentsLoadAsync(event); + await vi.runAllTimersAsync(); const events = getEvents(logger!); expect(events.length).toBe(1); - expect(events[0]).toHaveEventName(EventNames.AGENT_START); + expect(events[0]).toHaveEventName(EventNames.START_SESSION); + // Both metadata and exp.gws_experiment should be populated expect(events[0]).toHaveMetadataValue([ EventMetadataKey.GEMINI_CLI_EXPERIMENT_IDS, '123,456,789', ]); + expect(events[0]).toHaveGwsExperiments([123, 456, 789]); + }); + + it('async path includes empty gws_experiment array when no experiments', async () => { + const { logger } = setup({ + config: { + experiments: { + experimentIds: [], + }, + } as unknown as Partial, + }); + const event = logger!.createLogEvent(EventNames.START_SESSION, []); + + await logger?.enqueueLogEventAfterExperimentsLoadAsync(event); + await vi.runAllTimersAsync(); + + const events = getEvents(logger!); + expect(events.length).toBe(1); + expect(events[0]).toHaveGwsExperiments([]); + }); + + it('non-async path does not include exp.gws_experiment field', () => { + const { logger } = setup(); + const event = new AgentStartEvent('agent-123', 'TestAgent'); + + // logAgentStartEvent uses the non-async enqueueLogEvent path + logger?.logAgentStartEvent(event); + + const events = getEvents(logger!); + expect(events.length).toBe(1); + // exp.gws_experiment should NOT be present for non-async events + expect(events[0][0].exp).toBeUndefined(); }); }); diff --git a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts index 443f9365c9..f3fc7e1347 100644 --- a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts +++ b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts @@ -106,6 +106,9 @@ export interface LogResponse { export interface LogEventEntry { event_time_ms: number; source_extension_json: string; + exp?: { + gws_experiment: number[]; + }; } export interface EventValue { @@ -250,7 +253,7 @@ export class ClearcutLogger { ClearcutLogger.instance = undefined; } - enqueueHelper(event: LogEvent): void { + enqueueHelper(event: LogEvent, experimentIds?: number[]): void { // Manually handle overflow for FixedDeque, which throws when full. const wasAtCapacity = this.events.size >= MAX_EVENTS; @@ -258,12 +261,18 @@ export class ClearcutLogger { this.events.shift(); // Evict oldest element to make space. } - this.events.push([ - { - event_time_ms: Date.now(), - source_extension_json: safeJsonStringify(event), - }, - ]); + const logEventEntry: LogEventEntry = { + event_time_ms: Date.now(), + source_extension_json: safeJsonStringify(event), + }; + + if (experimentIds !== undefined) { + logEventEntry.exp = { + gws_experiment: experimentIds, + }; + } + + this.events.push([logEventEntry]); if (wasAtCapacity && this.config?.getDebugMode()) { debugLogger.debug( @@ -298,7 +307,7 @@ export class ClearcutLogger { event.event_metadata = [[...event.event_metadata[0], ...exp_id_data]]; } - this.enqueueHelper(event); + this.enqueueHelper(event, experiments?.experimentIds); }); } catch (error) { debugLogger.warn('ClearcutLogger: Failed to enqueue log event.', error); From 19bdd95eab6209bcfc05c37ce933ceb41f6f4e49 Mon Sep 17 00:00:00 2001 From: christine betts Date: Wed, 7 Jan 2026 14:35:56 -0500 Subject: [PATCH 039/713] Revert "feat(admin): implement extensions disabled" (#16082) --- packages/cli/src/config/config.ts | 2 - packages/cli/src/config/extension-manager.ts | 22 ++---- packages/cli/src/config/extension.test.ts | 71 ------------------- .../src/services/BuiltinCommandLoader.test.ts | 2 - .../cli/src/services/BuiltinCommandLoader.ts | 21 +----- packages/core/src/config/config.ts | 7 -- 6 files changed, 8 insertions(+), 117 deletions(-) diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 2c9bdcee51..aa00fbe9f2 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -637,7 +637,6 @@ export async function loadCliConfig( const ptyInfo = await getPty(); const mcpEnabled = settings.admin?.mcp?.enabled ?? true; - const extensionsEnabled = settings.admin?.extensions?.enabled ?? true; return new Config({ sessionId, @@ -660,7 +659,6 @@ export async function loadCliConfig( mcpServerCommand: mcpEnabled ? settings.mcp?.serverCommand : undefined, mcpServers: mcpEnabled ? settings.mcpServers : {}, mcpEnabled, - extensionsEnabled, allowedMcpServers: mcpEnabled ? (argv.allowedMcpServerNames ?? settings.mcp?.allowed) : undefined, diff --git a/packages/cli/src/config/extension-manager.ts b/packages/cli/src/config/extension-manager.ts index 998b91529c..3c4ed226c8 100644 --- a/packages/cli/src/config/extension-manager.ts +++ b/packages/cli/src/config/extension-manager.ts @@ -465,12 +465,6 @@ Would you like to attempt to install via "git clone" instead?`, if (this.loadedExtensions) { throw new Error('Extensions already loaded, only load extensions once.'); } - - if (this.settings.admin?.extensions?.enabled === false) { - this.loadedExtensions = []; - return this.loadedExtensions; - } - const extensionsDir = ExtensionStorage.getUserExtensionsDir(); this.loadedExtensions = []; if (!fs.existsSync(extensionsDir)) { @@ -543,16 +537,12 @@ Would you like to attempt to install via "git clone" instead?`, } if (config.mcpServers) { - if (this.settings.admin?.mcp?.enabled === false) { - config.mcpServers = undefined; - } else { - config.mcpServers = Object.fromEntries( - Object.entries(config.mcpServers).map(([key, value]) => [ - key, - filterMcpConfig(value), - ]), - ); - } + config.mcpServers = Object.fromEntries( + Object.entries(config.mcpServers).map(([key, value]) => [ + key, + filterMcpConfig(value), + ]), + ); } const contextFiles = getContextFileNames(config) diff --git a/packages/cli/src/config/extension.test.ts b/packages/cli/src/config/extension.test.ts index d4b15d760b..0bfa7a0358 100644 --- a/packages/cli/src/config/extension.test.ts +++ b/packages/cli/src/config/extension.test.ts @@ -632,77 +632,6 @@ describe('extension tests', () => { expect(extension).toBeUndefined(); }); - it('should not load any extensions if admin.extensions.enabled is false', async () => { - createExtension({ - extensionsDir: userExtensionsDir, - name: 'test-extension', - version: '1.0.0', - }); - const loadedSettings = loadSettings(tempWorkspaceDir); - loadedSettings.setValue( - SettingScope.System, - 'admin.extensions.enabled', - false, - ); - extensionManager = new ExtensionManager({ - workspaceDir: tempWorkspaceDir, - requestConsent: mockRequestConsent, - requestSetting: mockPromptForSettings, - settings: loadedSettings.merged, - }); - - const extensions = await extensionManager.loadExtensions(); - expect(extensions).toEqual([]); - }); - - it('should not load mcpServers if admin.mcp.enabled is false', async () => { - createExtension({ - extensionsDir: userExtensionsDir, - name: 'test-extension', - version: '1.0.0', - mcpServers: { - 'test-server': { command: 'echo', args: ['hello'] }, - }, - }); - const loadedSettings = loadSettings(tempWorkspaceDir); - loadedSettings.setValue(SettingScope.System, 'admin.mcp.enabled', false); - extensionManager = new ExtensionManager({ - workspaceDir: tempWorkspaceDir, - requestConsent: mockRequestConsent, - requestSetting: mockPromptForSettings, - settings: loadedSettings.merged, - }); - - const extensions = await extensionManager.loadExtensions(); - expect(extensions).toHaveLength(1); - expect(extensions[0].mcpServers).toBeUndefined(); - }); - - it('should load mcpServers if admin.mcp.enabled is true', async () => { - createExtension({ - extensionsDir: userExtensionsDir, - name: 'test-extension', - version: '1.0.0', - mcpServers: { - 'test-server': { command: 'echo', args: ['hello'] }, - }, - }); - const loadedSettings = loadSettings(tempWorkspaceDir); - loadedSettings.setValue(SettingScope.System, 'admin.mcp.enabled', true); - extensionManager = new ExtensionManager({ - workspaceDir: tempWorkspaceDir, - requestConsent: mockRequestConsent, - requestSetting: mockPromptForSettings, - settings: loadedSettings.merged, - }); - - const extensions = await extensionManager.loadExtensions(); - expect(extensions).toHaveLength(1); - expect(extensions[0].mcpServers).toEqual({ - 'test-server': { command: 'echo', args: ['hello'] }, - }); - }); - describe('id generation', () => { it.each([ { diff --git a/packages/cli/src/services/BuiltinCommandLoader.test.ts b/packages/cli/src/services/BuiltinCommandLoader.test.ts index af6c4176ec..b99d58239e 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.test.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.test.ts @@ -101,7 +101,6 @@ describe('BuiltinCommandLoader', () => { getFolderTrust: vi.fn().mockReturnValue(true), getEnableExtensionReloading: () => false, getEnableHooks: () => false, - getExtensionsEnabled: vi.fn().mockReturnValue(true), isSkillsSupportEnabled: vi.fn().mockReturnValue(false), getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ @@ -200,7 +199,6 @@ describe('BuiltinCommandLoader profile', () => { getCheckpointingEnabled: () => false, getEnableExtensionReloading: () => false, getEnableHooks: () => false, - getExtensionsEnabled: vi.fn().mockReturnValue(true), isSkillsSupportEnabled: vi.fn().mockReturnValue(false), getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ diff --git a/packages/cli/src/services/BuiltinCommandLoader.ts b/packages/cli/src/services/BuiltinCommandLoader.ts index aef44e6210..31395c0172 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.ts @@ -76,24 +76,7 @@ export class BuiltinCommandLoader implements ICommandLoader { docsCommand, directoryCommand, editorCommand, - ...(this.config?.getExtensionsEnabled() === false - ? [ - { - name: 'extensions', - description: 'Manage extensions', - kind: CommandKind.BUILT_IN, - autoExecute: false, - subCommands: [], - action: async ( - _context: CommandContext, - ): Promise => ({ - type: 'message', - messageType: 'error', - content: 'Extensions are disabled by your admin.', - }), - }, - ] - : [extensionsCommand(this.config?.getEnableExtensionReloading())]), + extensionsCommand(this.config?.getEnableExtensionReloading()), helpCommand, ...(this.config?.getEnableHooks() ? [hooksCommand] : []), await ideCommand(), @@ -112,7 +95,7 @@ export class BuiltinCommandLoader implements ICommandLoader { ): Promise => ({ type: 'message', messageType: 'error', - content: 'MCP is disabled by your admin.', + content: 'MCP disabled by your admin.', }), }, ] diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 9314a3d0b3..10c06950b8 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -356,7 +356,6 @@ export interface ConfigParameters { experimentalJitContext?: boolean; onModelChange?: (model: string) => void; mcpEnabled?: boolean; - extensionsEnabled?: boolean; onReload?: () => Promise<{ disabledSkills?: string[] }>; } @@ -391,7 +390,6 @@ export class Config { private readonly toolCallCommand: string | undefined; private readonly mcpServerCommand: string | undefined; private readonly mcpEnabled: boolean; - private readonly extensionsEnabled: boolean; private mcpServers: Record | undefined; private userMemory: string; private geminiMdFileCount: number; @@ -517,7 +515,6 @@ export class Config { this.mcpServerCommand = params.mcpServerCommand; this.mcpServers = params.mcpServers; this.mcpEnabled = params.mcpEnabled ?? true; - this.extensionsEnabled = params.extensionsEnabled ?? true; this.allowedMcpServers = params.allowedMcpServers ?? []; this.blockedMcpServers = params.blockedMcpServers ?? []; this.allowedEnvironmentVariables = params.allowedEnvironmentVariables ?? []; @@ -1143,10 +1140,6 @@ export class Config { return this.mcpEnabled; } - getExtensionsEnabled(): boolean { - return this.extensionsEnabled; - } - getMcpClientManager(): McpClientManager | undefined { return this.mcpClientManager; } From 4c961df3136b6b293a17a565c34541198b62062a Mon Sep 17 00:00:00 2001 From: joshualitt Date: Wed, 7 Jan 2026 12:34:33 -0800 Subject: [PATCH 040/713] feat(core): Decouple enabling hooks UI from subsystem. (#16074) --- packages/cli/src/config/config.ts | 5 +++-- packages/cli/src/config/settingsSchema.ts | 10 ++++++---- packages/cli/src/services/BuiltinCommandLoader.test.ts | 2 ++ packages/cli/src/services/BuiltinCommandLoader.ts | 2 +- packages/core/src/config/config.ts | 7 +++++++ 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index aa00fbe9f2..e94119a931 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -53,7 +53,7 @@ import { requestConsentNonInteractive } from './extensions/consent.js'; import { promptForSetting } from './extensions/extensionSettings.js'; import type { EventEmitter } from 'node:stream'; import { runExitCleanup } from '../utils/cleanup.js'; -import { getEnableHooks } from './settingsSchema.js'; +import { getEnableHooks, getEnableHooksUI } from './settingsSchema.js'; export interface CliArgs { query: string | undefined; @@ -292,7 +292,7 @@ export async function parseArguments(settings: Settings): Promise { } // Register hooks command if hooks are enabled - if (getEnableHooks(settings)) { + if (getEnableHooksUI(settings)) { yargsInstance.command(hooksCommand); } @@ -740,6 +740,7 @@ export async function loadCliConfig( modelConfigServiceConfig: settings.modelConfigs, // TODO: loading of hooks based on workspace trust enableHooks: getEnableHooks(settings), + enableHooksUI: getEnableHooksUI(settings), hooks: settings.hooks || {}, projectHooks: projectHooks || {}, onModelChange: (model: string) => saveModelChange(loadedSettings, model), diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index a51776316b..efe535e42e 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -2136,8 +2136,10 @@ type InferSettings = { export type Settings = InferSettings; -export function getEnableHooks(settings: Settings): boolean { - return ( - (settings.tools?.enableHooks ?? true) && (settings.hooks?.enabled ?? false) - ); +export function getEnableHooksUI(settings: Settings): boolean { + return settings.tools?.enableHooks ?? true; +} + +export function getEnableHooks(settings: Settings): boolean { + return getEnableHooksUI(settings) && (settings.hooks?.enabled ?? false); } diff --git a/packages/cli/src/services/BuiltinCommandLoader.test.ts b/packages/cli/src/services/BuiltinCommandLoader.test.ts index b99d58239e..6bebf0b06e 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.test.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.test.ts @@ -101,6 +101,7 @@ describe('BuiltinCommandLoader', () => { getFolderTrust: vi.fn().mockReturnValue(true), getEnableExtensionReloading: () => false, getEnableHooks: () => false, + getEnableHooksUI: () => false, isSkillsSupportEnabled: vi.fn().mockReturnValue(false), getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ @@ -199,6 +200,7 @@ describe('BuiltinCommandLoader profile', () => { getCheckpointingEnabled: () => false, getEnableExtensionReloading: () => false, getEnableHooks: () => false, + getEnableHooksUI: () => false, isSkillsSupportEnabled: vi.fn().mockReturnValue(false), getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ diff --git a/packages/cli/src/services/BuiltinCommandLoader.ts b/packages/cli/src/services/BuiltinCommandLoader.ts index 31395c0172..ea72ecdb05 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.ts @@ -78,7 +78,7 @@ export class BuiltinCommandLoader implements ICommandLoader { editorCommand, extensionsCommand(this.config?.getEnableExtensionReloading()), helpCommand, - ...(this.config?.getEnableHooks() ? [hooksCommand] : []), + ...(this.config?.getEnableHooksUI() ? [hooksCommand] : []), await ideCommand(), initCommand, ...(this.config?.getMcpEnabled() === false diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 10c06950b8..cc9929f23c 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -344,6 +344,7 @@ export interface ConfigParameters { disableYoloMode?: boolean; modelConfigServiceConfig?: ModelConfigServiceConfig; enableHooks?: boolean; + enableHooksUI?: boolean; experiments?: Experiments; hooks?: { [K in HookEventName]?: HookDefinition[] } & { disabled?: string[] }; projectHooks?: { [K in HookEventName]?: HookDefinition[] } & { @@ -470,6 +471,7 @@ export class Config { private readonly disableYoloMode: boolean; private pendingIncludeDirectories: string[]; private readonly enableHooks: boolean; + private readonly enableHooksUI: boolean; private readonly hooks: | { [K in HookEventName]?: HookDefinition[] } | undefined; @@ -603,6 +605,7 @@ export class Config { this.useWriteTodos = isPreviewModel(this.model) ? false : (params.useWriteTodos ?? true); + this.enableHooksUI = params.enableHooksUI ?? true; this.enableHooks = params.enableHooks ?? false; this.disabledHooks = (params.hooks && 'disabled' in params.hooks @@ -1671,6 +1674,10 @@ export class Config { return this.enableHooks; } + getEnableHooksUI(): boolean { + return this.enableHooksUI; + } + getCodebaseInvestigatorSettings(): CodebaseInvestigatorSettings { return this.codebaseInvestigatorSettings; } From 17b3eb730a9aee670bdbcd8ac2eeb22c9bf670ab Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Wed, 7 Jan 2026 15:46:44 -0500 Subject: [PATCH 041/713] docs: add docs for hooks + extensions (#16073) --- docs/extensions/index.md | 58 ++++++++++++++++++++++++++++++++++--- docs/hooks/index.md | 8 ++++- docs/hooks/writing-hooks.md | 18 ++++++++++++ 3 files changed, 79 insertions(+), 5 deletions(-) diff --git a/docs/extensions/index.md b/docs/extensions/index.md index 2c1ab9cd93..2d00a4f7d4 100644 --- a/docs/extensions/index.md +++ b/docs/extensions/index.md @@ -263,6 +263,54 @@ Would provide these commands: - `/deploy` - Shows as `[gcp] Custom command from deploy.toml` in help - `/gcs:sync` - Shows as `[gcp] Custom command from sync.toml` in help +### Hooks + +Extensions can provide [hooks](../hooks/index.md) to intercept and customize +Gemini CLI behavior at specific lifecycle events. Hooks provided by an extension +must be defined in a `hooks/hooks.json` file within the extension directory. + +> [!IMPORTANT] Hooks are not defined directly in `gemini-extension.json`. The +> CLI specifically looks for the `hooks/hooks.json` file. + +#### Directory structure + +``` +.gemini/extensions/my-extension/ +├── gemini-extension.json +└── hooks/ + └── hooks.json +``` + +#### `hooks/hooks.json` format + +The `hooks.json` file contains a `hooks` object where keys are +[event names](../hooks/reference.md#supported-events) and values are arrays of +[hook definitions](../hooks/reference.md#hook-definition). + +```json +{ + "hooks": { + "before_agent": [ + { + "hooks": [ + { + "type": "command", + "command": "node ${extensionPath}/scripts/setup.js", + "name": "Extension Setup" + } + ] + } + ] + } +} +``` + +#### Supported variables + +Just like `gemini-extension.json`, the `hooks/hooks.json` file supports +[variable substitution](#variables). This is particularly useful for referencing +scripts within the extension directory using `${extensionPath}`. + ### Conflict resolution Extension commands have the lowest precedence. When a conflict occurs with user @@ -278,11 +326,12 @@ For example, if both a user and the `gcp` extension define a `deploy` command: - `/gcp.deploy` - Executes the extension's deploy command (marked with `[gcp]` tag) -## Variables +### Variables -Gemini CLI extensions allow variable substitution in `gemini-extension.json`. -This can be useful if e.g., you need the current directory to run an MCP server -using `"cwd": "${extensionPath}${/}run.ts"`. +Gemini CLI extensions allow variable substitution in both +`gemini-extension.json` and `hooks/hooks.json`. This can be useful if e.g., you +need the current directory to run an MCP server or hook script using +`"cwd": "${extensionPath}${/}run.ts"`. **Supported variables:** @@ -291,3 +340,4 @@ using `"cwd": "${extensionPath}${/}run.ts"`. | `${extensionPath}` | The fully-qualified path of the extension in the user's filesystem e.g., '/Users/username/.gemini/extensions/example-extension'. This will not unwrap symlinks. | | `${workspacePath}` | The fully-qualified path of the current workspace. | | `${/} or ${pathSeparator}` | The path separator (differs per OS). | +| `${process.execPath}` | The path to the Node.js binary executing the CLI. | diff --git a/docs/hooks/index.md b/docs/hooks/index.md index 48b30a721d..3470a54196 100644 --- a/docs/hooks/index.md +++ b/docs/hooks/index.md @@ -46,6 +46,11 @@ project hook (identified by its name and command), but it is **your responsibility** to review these hooks (and any installed extensions) before trusting them. +> [!NOTE] Extension hooks are subject to a mandatory security warning and +> consent flow during extension installation or update if hooks are detected. +> You must explicitly approve the installation or update of any extension that +> contains hooks. + See [Security Considerations](best-practices.md#using-hooks-securely) for a detailed threat model and mitigation strategies. @@ -444,7 +449,8 @@ numbers run first): 2. **User settings:** `~/.gemini/settings.json` 3. **System settings:** `/etc/gemini-cli/settings.json` 4. **Extensions:** Internal hooks defined by installed extensions (lowest - priority) + priority). See [Extensions documentation](../extensions/index.md#hooks) for + details on how extensions define and configure hooks. #### Deduplication and shadowing diff --git a/docs/hooks/writing-hooks.md b/docs/hooks/writing-hooks.md index 12fcb69758..e11fb049cb 100644 --- a/docs/hooks/writing-hooks.md +++ b/docs/hooks/writing-hooks.md @@ -1018,6 +1018,24 @@ const SECRET_PATTERNS = [ ]; ``` +## Packaging as an extension + +While project-level hooks are great for specific repositories, you might want to +share your hooks across multiple projects or with other users. You can do this +by packaging your hooks as a [Gemini CLI extension](../extensions/index.md). + +Packaging as an extension provides: + +- **Easy distribution:** Share hooks via a git repository or GitHub release. +- **Centralized management:** Install, update, and disable hooks using + `gemini extensions` commands. +- **Version control:** Manage hook versions separately from your project code. +- **Variable substitution:** Use `${extensionPath}` and `${process.execPath}` + for portable, cross-platform scripts. + +To package hooks as an extension, follow the +[extensions hook documentation](../extensions/index.md#hooks). + ## Learn more - [Hooks Reference](index.md) - Complete API reference and configuration From a1dd19738e3a15a9bc78cefc194e8ea6920e0dc4 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Wed, 7 Jan 2026 13:21:10 -0800 Subject: [PATCH 042/713] feat(core): Preliminary changes for subagent model routing. (#16035) --- packages/core/src/config/models.test.ts | 22 ++++++ packages/core/src/config/models.ts | 14 ++++ packages/core/src/core/client.ts | 1 + packages/core/src/routing/routingStrategy.ts | 2 + .../strategies/classifierStrategy.test.ts | 26 +++++++ .../routing/strategies/classifierStrategy.ts | 2 +- .../strategies/fallbackStrategy.test.ts | 21 ++++++ .../routing/strategies/fallbackStrategy.ts | 4 +- .../strategies/overrideStrategy.test.ts | 21 ++++++ .../routing/strategies/overrideStrategy.ts | 16 ++-- .../src/services/modelConfigService.test.ts | 75 +++++++++++++++++++ .../core/src/services/modelConfigService.ts | 11 ++- 12 files changed, 200 insertions(+), 15 deletions(-) diff --git a/packages/core/src/config/models.test.ts b/packages/core/src/config/models.test.ts index 55b1751484..8e6c3ea895 100644 --- a/packages/core/src/config/models.test.ts +++ b/packages/core/src/config/models.test.ts @@ -9,6 +9,7 @@ import { resolveModel, resolveClassifierModel, isGemini2Model, + isAutoModel, getDisplayString, DEFAULT_GEMINI_MODEL, PREVIEW_GEMINI_MODEL, @@ -18,6 +19,7 @@ import { GEMINI_MODEL_ALIAS_PRO, GEMINI_MODEL_ALIAS_FLASH, GEMINI_MODEL_ALIAS_FLASH_LITE, + GEMINI_MODEL_ALIAS_AUTO, PREVIEW_GEMINI_FLASH_MODEL, PREVIEW_GEMINI_MODEL_AUTO, DEFAULT_GEMINI_MODEL_AUTO, @@ -171,6 +173,26 @@ describe('isGemini2Model', () => { }); }); +describe('isAutoModel', () => { + it('should return true for "auto"', () => { + expect(isAutoModel(GEMINI_MODEL_ALIAS_AUTO)).toBe(true); + }); + + it('should return true for "auto-gemini-3"', () => { + expect(isAutoModel(PREVIEW_GEMINI_MODEL_AUTO)).toBe(true); + }); + + it('should return true for "auto-gemini-2.5"', () => { + expect(isAutoModel(DEFAULT_GEMINI_MODEL_AUTO)).toBe(true); + }); + + it('should return false for concrete models', () => { + expect(isAutoModel(DEFAULT_GEMINI_MODEL)).toBe(false); + expect(isAutoModel(PREVIEW_GEMINI_MODEL)).toBe(false); + expect(isAutoModel('some-random-model')).toBe(false); + }); +}); + describe('resolveClassifierModel', () => { it('should return flash model when alias is flash', () => { expect( diff --git a/packages/core/src/config/models.ts b/packages/core/src/config/models.ts index ca87ee2d40..4475a5db97 100644 --- a/packages/core/src/config/models.ts +++ b/packages/core/src/config/models.ts @@ -146,6 +146,20 @@ export function isGemini2Model(model: string): boolean { return /^gemini-2(\.|$)/.test(model); } +/** + * Checks if the model is an auto model. + * + * @param model The model name to check. + * @returns True if the model is an auto model. + */ +export function isAutoModel(model: string): boolean { + return ( + model === GEMINI_MODEL_ALIAS_AUTO || + model === PREVIEW_GEMINI_MODEL_AUTO || + model === DEFAULT_GEMINI_MODEL_AUTO + ); +} + /** * Checks if the model supports multimodal function responses (multimodal data nested within function response). * This is supported in Gemini 3. diff --git a/packages/core/src/core/client.ts b/packages/core/src/core/client.ts index bf70aa2200..3a8603ae65 100644 --- a/packages/core/src/core/client.ts +++ b/packages/core/src/core/client.ts @@ -606,6 +606,7 @@ export class GeminiClient { history: this.getChat().getHistory(/*curated=*/ true), request, signal, + requestedModel: this.config.getModel(), }; let modelToUse: string; diff --git a/packages/core/src/routing/routingStrategy.ts b/packages/core/src/routing/routingStrategy.ts index d5d8df8dc9..de8bcf04f1 100644 --- a/packages/core/src/routing/routingStrategy.ts +++ b/packages/core/src/routing/routingStrategy.ts @@ -35,6 +35,8 @@ export interface RoutingContext { request: PartListUnion; /** An abort signal to cancel an LLM call during routing. */ signal: AbortSignal; + /** The model string requested for this turn, if any. */ + requestedModel?: string; } /** diff --git a/packages/core/src/routing/strategies/classifierStrategy.test.ts b/packages/core/src/routing/strategies/classifierStrategy.test.ts index 21d324c1fb..e883b0be45 100644 --- a/packages/core/src/routing/strategies/classifierStrategy.test.ts +++ b/packages/core/src/routing/strategies/classifierStrategy.test.ts @@ -281,4 +281,30 @@ describe('ClassifierStrategy', () => { ); consoleWarnSpy.mockRestore(); }); + + it('should respect requestedModel from context in resolveClassifierModel', async () => { + const requestedModel = DEFAULT_GEMINI_MODEL; // Pro model + const mockApiResponse = { + reasoning: 'Choice is flash', + model_choice: 'flash', + }; + vi.mocked(mockBaseLlmClient.generateJson).mockResolvedValue( + mockApiResponse, + ); + + const contextWithRequestedModel = { + ...mockContext, + requestedModel, + } as RoutingContext; + + const decision = await strategy.route( + contextWithRequestedModel, + mockConfig, + mockBaseLlmClient, + ); + + expect(decision).not.toBeNull(); + // Since requestedModel is Pro, and choice is flash, it should resolve to Flash + expect(decision?.model).toBe(DEFAULT_GEMINI_FLASH_MODEL); + }); }); diff --git a/packages/core/src/routing/strategies/classifierStrategy.ts b/packages/core/src/routing/strategies/classifierStrategy.ts index 4747bc5352..59c5ff6fca 100644 --- a/packages/core/src/routing/strategies/classifierStrategy.ts +++ b/packages/core/src/routing/strategies/classifierStrategy.ts @@ -168,7 +168,7 @@ export class ClassifierStrategy implements RoutingStrategy { const reasoning = routerResponse.reasoning; const latencyMs = Date.now() - startTime; const selectedModel = resolveClassifierModel( - config.getModel(), + context.requestedModel ?? config.getModel(), routerResponse.model_choice, config.getPreviewFeatures(), ); diff --git a/packages/core/src/routing/strategies/fallbackStrategy.test.ts b/packages/core/src/routing/strategies/fallbackStrategy.test.ts index 6196e59526..2d30b153e5 100644 --- a/packages/core/src/routing/strategies/fallbackStrategy.test.ts +++ b/packages/core/src/routing/strategies/fallbackStrategy.test.ts @@ -108,4 +108,25 @@ describe('FallbackStrategy', () => { // Important: check that it queried snapshot with the RESOLVED model, not 'auto' expect(mockService.snapshot).toHaveBeenCalledWith(DEFAULT_GEMINI_MODEL); }); + + it('should respect requestedModel from context', async () => { + const requestedModel = 'requested-model'; + const configModel = 'config-model'; + vi.mocked(mockConfig.getModel).mockReturnValue(configModel); + vi.mocked(mockService.snapshot).mockReturnValue({ available: true }); + + const contextWithRequestedModel = { + requestedModel, + } as RoutingContext; + + const decision = await strategy.route( + contextWithRequestedModel, + mockConfig, + mockClient, + ); + + expect(decision).toBeNull(); + // Should check availability of the requested model from context + expect(mockService.snapshot).toHaveBeenCalledWith(requestedModel); + }); }); diff --git a/packages/core/src/routing/strategies/fallbackStrategy.ts b/packages/core/src/routing/strategies/fallbackStrategy.ts index dbaa484094..383f441713 100644 --- a/packages/core/src/routing/strategies/fallbackStrategy.ts +++ b/packages/core/src/routing/strategies/fallbackStrategy.ts @@ -18,11 +18,11 @@ export class FallbackStrategy implements RoutingStrategy { readonly name = 'fallback'; async route( - _context: RoutingContext, + context: RoutingContext, config: Config, _baseLlmClient: BaseLlmClient, ): Promise { - const requestedModel = config.getModel(); + const requestedModel = context.requestedModel ?? config.getModel(); const resolvedModel = resolveModel( requestedModel, config.getPreviewFeatures(), diff --git a/packages/core/src/routing/strategies/overrideStrategy.test.ts b/packages/core/src/routing/strategies/overrideStrategy.test.ts index f1ec54098d..97e9f4915f 100644 --- a/packages/core/src/routing/strategies/overrideStrategy.test.ts +++ b/packages/core/src/routing/strategies/overrideStrategy.test.ts @@ -56,4 +56,25 @@ describe('OverrideStrategy', () => { expect(decision).not.toBeNull(); expect(decision?.model).toBe(overrideModel); }); + + it('should respect requestedModel from context', async () => { + const requestedModel = 'requested-model'; + const configModel = 'config-model'; + const mockConfig = { + getModel: () => configModel, + getPreviewFeatures: () => false, + } as Config; + const contextWithRequestedModel = { + requestedModel, + } as RoutingContext; + + const decision = await strategy.route( + contextWithRequestedModel, + mockConfig, + mockClient, + ); + + expect(decision).not.toBeNull(); + expect(decision?.model).toBe(requestedModel); + }); }); diff --git a/packages/core/src/routing/strategies/overrideStrategy.ts b/packages/core/src/routing/strategies/overrideStrategy.ts index 6a4c2a50d2..c5f632ca3d 100644 --- a/packages/core/src/routing/strategies/overrideStrategy.ts +++ b/packages/core/src/routing/strategies/overrideStrategy.ts @@ -5,11 +5,7 @@ */ import type { Config } from '../../config/config.js'; -import { - DEFAULT_GEMINI_MODEL_AUTO, - PREVIEW_GEMINI_MODEL_AUTO, - resolveModel, -} from '../../config/models.js'; +import { isAutoModel, resolveModel } from '../../config/models.js'; import type { BaseLlmClient } from '../../core/baseLlmClient.js'; import type { RoutingContext, @@ -24,18 +20,16 @@ export class OverrideStrategy implements RoutingStrategy { readonly name = 'override'; async route( - _context: RoutingContext, + context: RoutingContext, config: Config, _baseLlmClient: BaseLlmClient, ): Promise { - const overrideModel = config.getModel(); + const overrideModel = context.requestedModel ?? config.getModel(); // If the model is 'auto' we should pass to the next strategy. - if ( - overrideModel === DEFAULT_GEMINI_MODEL_AUTO || - overrideModel === PREVIEW_GEMINI_MODEL_AUTO - ) + if (isAutoModel(overrideModel)) { return null; + } // Return the overridden model name. return { diff --git a/packages/core/src/services/modelConfigService.test.ts b/packages/core/src/services/modelConfigService.test.ts index 8d08e4f775..ee6cd09f40 100644 --- a/packages/core/src/services/modelConfigService.test.ts +++ b/packages/core/src/services/modelConfigService.test.ts @@ -577,6 +577,81 @@ describe('ModelConfigService', () => { }); }); + describe('runtime overrides', () => { + it('should resolve a simple runtime-registered override', () => { + const config: ModelConfigServiceConfig = { + aliases: {}, + overrides: [], + }; + const service = new ModelConfigService(config); + + service.registerRuntimeModelOverride({ + match: { model: 'gemini-pro' }, + modelConfig: { + generateContentConfig: { + temperature: 0.99, + }, + }, + }); + + const resolved = service.getResolvedConfig({ model: 'gemini-pro' }); + + expect(resolved.model).toBe('gemini-pro'); + expect(resolved.generateContentConfig.temperature).toBe(0.99); + }); + + it('should prioritize runtime overrides over default overrides when they have the same specificity', () => { + const config: ModelConfigServiceConfig = { + aliases: {}, + overrides: [ + { + match: { model: 'gemini-pro' }, + modelConfig: { generateContentConfig: { temperature: 0.1 } }, + }, + ], + }; + const service = new ModelConfigService(config); + + service.registerRuntimeModelOverride({ + match: { model: 'gemini-pro' }, + modelConfig: { generateContentConfig: { temperature: 0.9 } }, + }); + + const resolved = service.getResolvedConfig({ model: 'gemini-pro' }); + + // Runtime overrides are appended after overrides/customOverrides, so they should win. + expect(resolved.generateContentConfig.temperature).toBe(0.9); + }); + + it('should still respect specificity with runtime overrides', () => { + const config: ModelConfigServiceConfig = { + aliases: {}, + overrides: [], + }; + const service = new ModelConfigService(config); + + // Register a more specific runtime override + service.registerRuntimeModelOverride({ + match: { model: 'gemini-pro', overrideScope: 'my-agent' }, + modelConfig: { generateContentConfig: { temperature: 0.1 } }, + }); + + // Register a less specific runtime override later + service.registerRuntimeModelOverride({ + match: { model: 'gemini-pro' }, + modelConfig: { generateContentConfig: { temperature: 0.9 } }, + }); + + const resolved = service.getResolvedConfig({ + model: 'gemini-pro', + overrideScope: 'my-agent', + }); + + // Specificity should win over order + expect(resolved.generateContentConfig.temperature).toBe(0.1); + }); + }); + describe('custom aliases', () => { it('should resolve a custom alias', () => { const config: ModelConfigServiceConfig = { diff --git a/packages/core/src/services/modelConfigService.ts b/packages/core/src/services/modelConfigService.ts index 0b86baa4ad..6fb712243c 100644 --- a/packages/core/src/services/modelConfigService.ts +++ b/packages/core/src/services/modelConfigService.ts @@ -65,6 +65,7 @@ export interface _ResolvedModelConfig { export class ModelConfigService { private readonly runtimeAliases: Record = {}; + private readonly runtimeOverrides: ModelConfigOverride[] = []; // TODO(12597): Process config to build a typed alias hierarchy. constructor(private readonly config: ModelConfigServiceConfig) {} @@ -73,6 +74,10 @@ export class ModelConfigService { this.runtimeAliases[aliasName] = alias; } + registerRuntimeModelOverride(override: ModelConfigOverride): void { + this.runtimeOverrides.push(override); + } + private resolveAlias( aliasName: string, aliases: Record, @@ -123,7 +128,11 @@ export class ModelConfigService { ...customAliases, ...this.runtimeAliases, }; - const allOverrides = [...overrides, ...customOverrides]; + const allOverrides = [ + ...overrides, + ...customOverrides, + ...this.runtimeOverrides, + ]; let baseModel: string | undefined = context.model; let resolvedConfig: GenerateContentConfig = {}; From d5996fea9994fb2e22cf2f92ca1292d9b46e65c5 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 7 Jan 2026 13:50:22 -0800 Subject: [PATCH 043/713] Optimize CI workflow: Parallelize jobs and cache linters (#16054) Co-authored-by: matt korwel --- .github/workflows/chained_e2e.yml | 1 + .github/workflows/ci.yml | 48 +++++++++++++++++++++++++------ .prettierignore | 1 + package.json | 2 +- scripts/lint.js | 10 +++++-- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/.github/workflows/chained_e2e.yml b/.github/workflows/chained_e2e.yml index 722559ec17..494163966e 100644 --- a/.github/workflows/chained_e2e.yml +++ b/.github/workflows/chained_e2e.yml @@ -168,6 +168,7 @@ jobs: GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}' KEEP_OUTPUT: 'true' VERBOSE: 'true' + BUILD_SANDBOX_FLAGS: '--cache-from type=gha --cache-to type=gha,mode=max' shell: 'bash' run: | if [[ "${{ matrix.sandbox }}" == "sandbox:docker" ]]; then diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa8ce717f1..3fb1867db7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,8 @@ jobs: runs-on: 'gemini-cli-ubuntu-16-core' needs: 'merge_queue_skipper' if: "${{needs.merge_queue_skipper.outputs.skip == 'false'}}" + env: + GEMINI_LINT_TEMP_DIR: '${{ github.workspace }}/.gemini-linters' steps: - name: 'Checkout' uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 @@ -63,9 +65,21 @@ jobs: node-version-file: '.nvmrc' cache: 'npm' + - name: 'Cache Linters' + uses: 'actions/cache@v4' + with: + path: '${{ env.GEMINI_LINT_TEMP_DIR }}' + key: "${{ runner.os }}-${{ runner.arch }}-linters-${{ hashFiles('scripts/lint.js') }}" + - name: 'Install dependencies' run: 'npm ci' + - name: 'Cache ESLint' + uses: 'actions/cache@v4' + with: + path: '.eslintcache' + key: "${{ runner.os }}-eslint-${{ hashFiles('package-lock.json', 'eslint.config.js') }}" + - name: 'Validate NOTICES.txt' run: 'git diff --exit-code packages/vscode-ide-companion/NOTICES.txt' @@ -111,10 +125,9 @@ jobs: args: '--verbose --accept 200,503 ./**/*.md' fail: true test_linux: - name: 'Test (Linux)' + name: 'Test (Linux) - ${{ matrix.shard }}' runs-on: 'gemini-cli-ubuntu-16-core' needs: - - 'lint' - 'merge_queue_skipper' if: "${{needs.merge_queue_skipper.outputs.skip == 'false'}}" permissions: @@ -127,6 +140,9 @@ jobs: - '20.x' - '22.x' - '24.x' + shard: + - 'cli' + - 'others' steps: - name: 'Checkout' uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 @@ -146,7 +162,14 @@ jobs: - name: 'Run tests and generate reports' env: NO_COLOR: true - run: 'npm run test:ci' + run: | + if [[ "${{ matrix.shard }}" == "cli" ]]; then + npm run test:ci --workspace @google/gemini-cli + else + # Explicitly list non-cli packages to ensure they are sharded correctly + npm run test:ci --workspace @google/gemini-cli-core --workspace @google/gemini-cli-a2a-server --workspace gemini-cli-vscode-ide-companion --workspace @google/gemini-cli-test-utils --if-present + npm run test:scripts + fi - name: 'Bundle' run: 'npm run bundle' @@ -162,7 +185,7 @@ jobs: ${{ always() && (github.event.pull_request.head.repo.full_name == github.repository) }} uses: 'dorny/test-reporter@dc3a92680fcc15842eef52e8c4606ea7ce6bd3f3' # ratchet:dorny/test-reporter@v2 with: - name: 'Test Results (Node ${{ matrix.node-version }})' + name: 'Test Results (Node ${{ matrix.node-version }}, ${{ matrix.shard }})' path: 'packages/*/junit.xml' reporter: 'java-junit' fail-on-error: 'false' @@ -176,10 +199,9 @@ jobs: path: 'packages/*/junit.xml' test_mac: - name: 'Test (Mac)' + name: 'Test (Mac) - ${{ matrix.shard }}' runs-on: '${{ matrix.os }}' needs: - - 'lint' - 'merge_queue_skipper' if: "${{needs.merge_queue_skipper.outputs.skip == 'false'}}" permissions: @@ -195,6 +217,9 @@ jobs: - '20.x' - '22.x' - '24.x' + shard: + - 'cli' + - 'others' steps: - name: 'Checkout' uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 @@ -214,7 +239,14 @@ jobs: - name: 'Run tests and generate reports' env: NO_COLOR: true - run: 'npm run test:ci -- --coverage.enabled=false' + run: | + if [[ "${{ matrix.shard }}" == "cli" ]]; then + npm run test:ci --workspace @google/gemini-cli -- --coverage.enabled=false + else + # Explicitly list non-cli packages to ensure they are sharded correctly + npm run test:ci --workspace @google/gemini-cli-core --workspace @google/gemini-cli-a2a-server --workspace gemini-cli-vscode-ide-companion --workspace @google/gemini-cli-test-utils --if-present -- --coverage.enabled=false + npm run test:scripts + fi - name: 'Bundle' run: 'npm run bundle' @@ -230,7 +262,7 @@ jobs: ${{ always() && (github.event.pull_request.head.repo.full_name == github.repository) }} uses: 'dorny/test-reporter@dc3a92680fcc15842eef52e8c4606ea7ce6bd3f3' # ratchet:dorny/test-reporter@v2 with: - name: 'Test Results (Node ${{ matrix.node-version }})' + name: 'Test Results (Node ${{ matrix.node-version }}, ${{ matrix.shard }})' path: 'packages/*/junit.xml' reporter: 'java-junit' fail-on-error: 'false' diff --git a/.prettierignore b/.prettierignore index 7b8a75a110..120f04c358 100644 --- a/.prettierignore +++ b/.prettierignore @@ -17,5 +17,6 @@ eslint.config.js **/generated gha-creds-*.json junit.xml +.gemini-linters/ Thumbs.db .pytest_cache diff --git a/package.json b/package.json index 04c7077437..4328d4e637 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "test:integration:sandbox:none": "cross-env GEMINI_SANDBOX=false vitest run --root ./integration-tests", "test:integration:sandbox:docker": "cross-env GEMINI_SANDBOX=docker npm run build:sandbox && cross-env GEMINI_SANDBOX=docker vitest run --root ./integration-tests", "test:integration:sandbox:podman": "cross-env GEMINI_SANDBOX=podman vitest run --root ./integration-tests", - "lint": "eslint . --ext .ts,.tsx && eslint integration-tests && eslint scripts", + "lint": "eslint . --cache", "lint:fix": "eslint . --fix --ext .ts,.tsx && eslint integration-tests --fix && eslint scripts --fix && npm run format", "lint:ci": "npm run lint:all", "lint:all": "node scripts/lint.js", diff --git a/scripts/lint.js b/scripts/lint.js index 255c572551..c0c5689a01 100644 --- a/scripts/lint.js +++ b/scripts/lint.js @@ -21,7 +21,8 @@ const ACTIONLINT_VERSION = '1.7.7'; const SHELLCHECK_VERSION = '0.11.0'; const YAMLLINT_VERSION = '1.35.1'; -const TEMP_DIR = join(tmpdir(), 'gemini-cli-linters'); +const TEMP_DIR = + process.env.GEMINI_LINT_TEMP_DIR || join(tmpdir(), 'gemini-cli-linters'); function getPlatformArch() { const platform = process.platform; @@ -134,7 +135,9 @@ function runCommand(command, stdio = 'inherit') { export function setupLinters() { console.log('Setting up linters...'); - rmSync(TEMP_DIR, { recursive: true, force: true }); + if (!process.env.GEMINI_LINT_TEMP_DIR) { + rmSync(TEMP_DIR, { recursive: true, force: true }); + } mkdirSync(TEMP_DIR, { recursive: true }); for (const linter in LINTERS) { @@ -183,6 +186,9 @@ export function runYamllint() { export function runPrettier() { console.log('\nRunning Prettier...'); if (!runCommand('prettier --check .')) { + console.log( + 'Prettier check failed. Please run "npm run format" to fix formatting issues.', + ); process.exit(1); } } From 0be8b5b1ed2928a08818c725284e6ca56bdd2116 Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Wed, 7 Jan 2026 16:59:48 -0500 Subject: [PATCH 044/713] =?UTF-8?q?Add=20option=20to=20fallback=20for=20ca?= =?UTF-8?q?pacity=20errors=20in=20ProQuotaDi=E2=80=A6=20(#16050)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cli/src/ui/components/ProQuotaDialog.test.tsx | 7 ++++++- packages/cli/src/ui/components/ProQuotaDialog.tsx | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/ui/components/ProQuotaDialog.test.tsx b/packages/cli/src/ui/components/ProQuotaDialog.test.tsx index 42746678e2..2520036246 100644 --- a/packages/cli/src/ui/components/ProQuotaDialog.test.tsx +++ b/packages/cli/src/ui/components/ProQuotaDialog.test.tsx @@ -169,7 +169,7 @@ describe('ProQuotaDialog', () => { }); describe('when it is a capacity error', () => { - it('should render keep trying and stop options', () => { + it('should render keep trying, switch, and stop options', () => { const { unmount } = render( { value: 'retry_once', key: 'retry_once', }, + { + label: 'Switch to gemini-2.5-flash', + value: 'retry_always', + key: 'retry_always', + }, { label: 'Stop', value: 'retry_later', key: 'retry_later' }, ], }), diff --git a/packages/cli/src/ui/components/ProQuotaDialog.tsx b/packages/cli/src/ui/components/ProQuotaDialog.tsx index cda3937a7f..0dbf134c5b 100644 --- a/packages/cli/src/ui/components/ProQuotaDialog.tsx +++ b/packages/cli/src/ui/components/ProQuotaDialog.tsx @@ -91,6 +91,11 @@ export function ProQuotaDialog({ value: 'retry_once' as const, key: 'retry_once', }, + { + label: `Switch to ${fallbackModel}`, + value: 'retry_always' as const, + key: 'retry_always', + }, { label: 'Stop', value: 'retry_later' as const, From 1c77bac146a09f251d246110543e3994e223feb7 Mon Sep 17 00:00:00 2001 From: Adam Weidman <65992621+adamfweidman@users.noreply.github.com> Date: Wed, 7 Jan 2026 17:46:37 -0500 Subject: [PATCH 045/713] feat: add confirmation details support + jsonrpc vs http rest support (#16079) --- .../src/agents/a2a-client-manager.test.ts | 48 +++++++++++++++ .../core/src/agents/a2a-client-manager.ts | 42 +++++-------- .../src/agents/delegate-to-agent-tool.test.ts | 59 ++++++++++++++++++- .../core/src/agents/delegate-to-agent-tool.ts | 44 ++++++++++---- packages/core/src/agents/registry.ts | 4 ++ .../core/src/agents/remote-invocation.test.ts | 2 +- packages/core/src/agents/remote-invocation.ts | 7 ++- 7 files changed, 162 insertions(+), 44 deletions(-) diff --git a/packages/core/src/agents/a2a-client-manager.test.ts b/packages/core/src/agents/a2a-client-manager.test.ts index fb0f2829a4..4406cac966 100644 --- a/packages/core/src/agents/a2a-client-manager.test.ts +++ b/packages/core/src/agents/a2a-client-manager.test.ts @@ -340,5 +340,53 @@ describe('A2AClientManager', () => { expect(data.status.state).toBe('working'); }); + + it('bypasses adapter for JSON-RPC requests', async () => { + const baseFetch = vi.fn().mockResolvedValue(new Response('{}')); + const adapter = createAdapterFetch(baseFetch as typeof fetch); + const rpcBody = JSON.stringify({ jsonrpc: '2.0', method: 'foo' }); + + await adapter('http://example.com', { + method: 'POST', + body: rpcBody, + }); + + // Verify baseFetch was called with original body, not modified + expect(baseFetch).toHaveBeenCalledWith( + 'http://example.com', + expect.objectContaining({ body: rpcBody }), + ); + }); + + it('applies dialect translation for remote REST requests', async () => { + const baseFetch = vi.fn().mockResolvedValue(new Response('{}')); + const adapter = createAdapterFetch(baseFetch as typeof fetch); + const originalBody = JSON.stringify({ + message: { + role: 'user', + parts: [{ kind: 'text', text: 'hi' }], + }, + }); + + await adapter('https://remote-agent.com/v1/message:send', { + method: 'POST', + body: originalBody, + }); + + // Verify body WAS modified: + // 1. role: 'user' -> 'ROLE_USER' + // 2. parts mapped to content, kind stripped + const expectedBody = JSON.stringify({ + message: { + role: 'ROLE_USER', + content: [{ text: 'hi' }], + }, + }); + + expect(baseFetch).toHaveBeenCalledWith( + expect.any(String), + expect.objectContaining({ body: expectedBody }), + ); + }); }); }); diff --git a/packages/core/src/agents/a2a-client-manager.ts b/packages/core/src/agents/a2a-client-manager.ts index ef93522e03..c00fdfee43 100644 --- a/packages/core/src/agents/a2a-client-manager.ts +++ b/packages/core/src/agents/a2a-client-manager.ts @@ -232,25 +232,24 @@ export function createAdapterFetch(baseFetch: typeof fetch): typeof fetch { input: RequestInfo | URL, init?: RequestInit, ): Promise => { - const urlStr = input as string; - - // 2. Dialect Mapping (Request) - let body = init?.body; - let isRpc = false; - let rpcId: string | number | undefined; - + const body = init?.body; + // Protocol Detection + // JSON-RPC requests bypass the adapter as they are standard-compliant and + // don't require the dialect translation intended for Vertex AI REST bindings. + // This logic can be removed when a2a-js/sdk is fully compliant. + let effectiveBody = body; if (typeof body === 'string') { try { - let jsonBody = JSON.parse(body); + const jsonBody = JSON.parse(body); - // Unwrap JSON-RPC if present + // If the SDK decided to use JSON-RPC, we bypass the adapter because + // JSON-RPC requests are correctly supported in a2a-js/sdk. if (jsonBody.jsonrpc === '2.0') { - isRpc = true; - rpcId = jsonBody.id; - jsonBody = jsonBody.params; + return await baseFetch(input, init); } - // Apply dialect translation to the message object + // Dialect Mapping (REST / HTTP+JSON) + // Apply translation for Vertex AI Agent Engine compatibility. const message = jsonBody.message || jsonBody; if (message && typeof message === 'object') { // Role: user -> ROLE_USER, agent/model -> ROLE_AGENT @@ -277,23 +276,20 @@ export function createAdapterFetch(baseFetch: typeof fetch): typeof fetch { } } - body = JSON.stringify(jsonBody); + effectiveBody = JSON.stringify(jsonBody); } catch (error) { debugLogger.debug( '[A2AClientManager] Failed to parse request body for dialect translation:', error, ); - // Non-JSON or parse error; let the baseFetch handle it. } } - const response = await baseFetch(urlStr, { ...init, body }); + const response = await baseFetch(input, { ...init, body: effectiveBody }); - // Map response back if (response.ok) { try { const responseData = await response.clone().json(); - const result = responseData.task || responseData.message || responseData; @@ -337,16 +333,6 @@ export function createAdapterFetch(baseFetch: typeof fetch): typeof fetch { result.status.state = mapTaskState(result.status.state); } - if (isRpc) { - return new Response( - JSON.stringify({ - jsonrpc: '2.0', - id: rpcId, - result, - }), - response, - ); - } return new Response(JSON.stringify(result), response); } catch (_e) { // Non-JSON response or unwrapping failure diff --git a/packages/core/src/agents/delegate-to-agent-tool.test.ts b/packages/core/src/agents/delegate-to-agent-tool.test.ts index 3722ae2e88..9b2bd16aaf 100644 --- a/packages/core/src/agents/delegate-to-agent-tool.test.ts +++ b/packages/core/src/agents/delegate-to-agent-tool.test.ts @@ -21,6 +21,7 @@ vi.mock('./local-invocation.js', () => ({ execute: vi .fn() .mockResolvedValue({ content: [{ type: 'text', text: 'Success' }] }), + shouldConfirmExecute: vi.fn().mockResolvedValue(false), })), })); @@ -29,7 +30,12 @@ vi.mock('./remote-invocation.js', () => ({ execute: vi.fn().mockResolvedValue({ content: [{ type: 'text', text: 'Remote Success' }], }), - shouldConfirmExecute: vi.fn().mockResolvedValue(true), + shouldConfirmExecute: vi.fn().mockResolvedValue({ + type: 'info', + title: 'Remote Confirmation', + prompt: 'Confirm remote call', + onConfirm: vi.fn(), + }), })), })); @@ -219,4 +225,55 @@ describe('DelegateToAgentTool', () => { 'remote_agent', ); }); + + describe('Confirmation', () => { + it('should use default behavior for local agents (super call)', async () => { + const invocation = tool.build({ + agent_name: 'test_agent', + arg1: 'valid', + }); + + // We expect it to call messageBus.publish with 'delegate_to_agent' + // because super.shouldConfirmExecute checks the policy for the tool itself. + await invocation.shouldConfirmExecute(new AbortController().signal); + + expect(messageBus.publish).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageBusType.TOOL_CONFIRMATION_REQUEST, + toolCall: expect.objectContaining({ + name: DELEGATE_TO_AGENT_TOOL_NAME, + }), + }), + ); + }); + + it('should forward to remote agent confirmation logic', async () => { + const invocation = tool.build({ + agent_name: 'remote_agent', + query: 'hello remote', + }); + + const result = await invocation.shouldConfirmExecute( + new AbortController().signal, + ); + + // Verify it returns the mock confirmation from RemoteAgentInvocation + expect(result).toMatchObject({ + type: 'info', + title: 'Remote Confirmation', + }); + + // Verify it did NOT call messageBus.publish with 'delegate_to_agent' + // directly from DelegateInvocation, but instead went into RemoteAgentInvocation. + // RemoteAgentInvocation (the mock) doesn't call publish in its mock implementation. + const delegateToAgentPublish = vi + .mocked(messageBus.publish) + .mock.calls.find( + (call) => + call[0].type === MessageBusType.TOOL_CONFIRMATION_REQUEST && + call[0].toolCall.name === DELEGATE_TO_AGENT_TOOL_NAME, + ); + expect(delegateToAgentPublish).toBeUndefined(); + }); + }); }); diff --git a/packages/core/src/agents/delegate-to-agent-tool.ts b/packages/core/src/agents/delegate-to-agent-tool.ts index 6ac716b7f4..7f3c4466b5 100644 --- a/packages/core/src/agents/delegate-to-agent-tool.ts +++ b/packages/core/src/agents/delegate-to-agent-tool.ts @@ -12,14 +12,15 @@ import { type ToolInvocation, type ToolResult, BaseToolInvocation, + type ToolCallConfirmationDetails, } from '../tools/tools.js'; import type { AnsiOutput } from '../utils/terminalSerializer.js'; import { DELEGATE_TO_AGENT_TOOL_NAME } from '../tools/tool-names.js'; import type { AgentRegistry } from './registry.js'; import type { Config } from '../config/config.js'; import type { MessageBus } from '../confirmation-bus/message-bus.js'; +import type { AgentDefinition, AgentInputs } from './types.js'; import { SubagentToolWrapper } from './subagent-tool-wrapper.js'; -import type { AgentInputs } from './types.js'; type DelegateParams = { agent_name: string } & Record; @@ -166,6 +167,22 @@ class DelegateInvocation extends BaseToolInvocation< return `Delegating to agent '${this.params.agent_name}'`; } + override async shouldConfirmExecute( + abortSignal: AbortSignal, + ): Promise { + const definition = this.registry.getDefinition(this.params.agent_name); + if (!definition || definition.kind !== 'remote') { + return super.shouldConfirmExecute(abortSignal); + } + + const { agent_name: _agent_name, ...agentArgs } = this.params; + const invocation = this.buildSubInvocation( + definition, + agentArgs as AgentInputs, + ); + return invocation.shouldConfirmExecute(abortSignal); + } + async execute( signal: AbortSignal, updateOutput?: (output: string | AnsiOutput) => void, @@ -173,26 +190,29 @@ class DelegateInvocation extends BaseToolInvocation< const definition = this.registry.getDefinition(this.params.agent_name); if (!definition) { throw new Error( - `Agent '${this.params.agent_name}' exists in the tool definition but could not be found in the registry.`, + `Agent '${this.params.agent_name}' not found in registry.`, ); } - // Extract arguments (everything except agent_name) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { agent_name, ...agentArgs } = this.params; + const { agent_name: _agent_name, ...agentArgs } = this.params; + const invocation = this.buildSubInvocation( + definition, + agentArgs as AgentInputs, + ); - // Delegate the creation of the specific invocation (Local or Remote) to the wrapper. - // This centralizes the logic and ensures consistent handling. + return invocation.execute(signal, updateOutput); + } + + private buildSubInvocation( + definition: AgentDefinition, + agentArgs: AgentInputs, + ): ToolInvocation { const wrapper = new SubagentToolWrapper( definition, this.config, this.messageBus, ); - // We could skip extra validation here if we trust the Registry's schema, - // but build() will do a safety check anyway. - const invocation = wrapper.build(agentArgs as AgentInputs); - - return invocation.execute(signal, updateOutput); + return wrapper.build(agentArgs); } } diff --git a/packages/core/src/agents/registry.ts b/packages/core/src/agents/registry.ts index 38b28ffcc7..2e3e810b55 100644 --- a/packages/core/src/agents/registry.ts +++ b/packages/core/src/agents/registry.ts @@ -12,6 +12,7 @@ import { loadAgentsFromDirectory } from './toml-loader.js'; import { CodebaseInvestigatorAgent } from './codebase-investigator.js'; import { IntrospectionAgent } from './introspection-agent.js'; import { A2AClientManager } from './a2a-client-manager.js'; +import { ADCHandler } from './remote-invocation.js'; import { type z } from 'zod'; import { debugLogger } from '../utils/debugLogger.js'; import { @@ -251,9 +252,12 @@ export class AgentRegistry { // Log remote A2A agent registration for visibility. try { const clientManager = A2AClientManager.getInstance(); + // Use ADCHandler to ensure we can load agents hosted on secure platforms (e.g. Vertex AI) + const authHandler = new ADCHandler(); const agentCard = await clientManager.loadAgent( definition.name, definition.agentCardUrl, + authHandler, ); if (agentCard.skills && agentCard.skills.length > 0) { definition.description = agentCard.skills diff --git a/packages/core/src/agents/remote-invocation.test.ts b/packages/core/src/agents/remote-invocation.test.ts index f3c998e41b..5f2c3eb732 100644 --- a/packages/core/src/agents/remote-invocation.test.ts +++ b/packages/core/src/agents/remote-invocation.test.ts @@ -304,7 +304,7 @@ describe('RemoteAgentInvocation', () => { confirmation.type === 'info' ) { expect(confirmation.title).toContain('Test Agent'); - expect(confirmation.prompt).toContain('http://test-agent/card'); + expect(confirmation.prompt).toContain('Calling remote agent: "hi"'); } else { throw new Error('Expected confirmation to be of type info'); } diff --git a/packages/core/src/agents/remote-invocation.ts b/packages/core/src/agents/remote-invocation.ts index 4bc23f7fb1..9acb7794ea 100644 --- a/packages/core/src/agents/remote-invocation.ts +++ b/packages/core/src/agents/remote-invocation.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import type { ToolConfirmationOutcome } from '../tools/tools.js'; import { BaseToolInvocation, type ToolResult, @@ -114,8 +115,10 @@ export class RemoteAgentInvocation extends BaseToolInvocation< return { type: 'info', title: `Call Remote Agent: ${this.definition.displayName ?? this.definition.name}`, - prompt: `This will send a message to the external agent at ${this.definition.agentCardUrl}.`, - onConfirm: async () => {}, // No-op for now, just informational + prompt: `Calling remote agent: "${this.params.query}"`, + onConfirm: async (outcome: ToolConfirmationOutcome) => { + await this.publishPolicyUpdate(outcome); + }, }; } From bd77515fd931b66f1fcdf42f72bfcba70447d163 Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Wed, 7 Jan 2026 14:58:42 -0800 Subject: [PATCH 046/713] fix(workflows): fix and limit labels for pr-triage.sh script (#16096) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .github/scripts/pr-triage.sh | 57 ++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/.github/scripts/pr-triage.sh b/.github/scripts/pr-triage.sh index 48302028e0..9e1c140679 100755 --- a/.github/scripts/pr-triage.sh +++ b/.github/scripts/pr-triage.sh @@ -19,24 +19,40 @@ process_pr() { local PR_NUMBER=$1 echo "🔄 Processing PR #${PR_NUMBER}" - # Get closing issue number with error handling - local ISSUE_NUMBER - if ! ISSUE_NUMBER=$(gh pr view "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json closingIssuesReferences -q '.closingIssuesReferences.nodes[0].number' 2>/dev/null); then - echo " ⚠️ Could not fetch closing issue for PR #${PR_NUMBER}" + # Get PR details: closing issue and draft status + local PR_DATA + if ! PR_DATA=$(gh pr view "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json closingIssuesReferences,isDraft 2>/dev/null); then + echo " ⚠️ Could not fetch data for PR #${PR_NUMBER}" + return 0 fi + local ISSUE_NUMBER + ISSUE_NUMBER=$(echo "${PR_DATA}" | jq -r '.closingIssuesReferences[0].number // empty') + + local IS_DRAFT + IS_DRAFT=$(echo "${PR_DATA}" | jq -r '.isDraft') + if [[ -z "${ISSUE_NUMBER}" ]]; then - echo "⚠️ No linked issue found for PR #${PR_NUMBER}, adding status/need-issue label" - if ! gh pr edit "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --add-label "status/need-issue" 2>/dev/null; then - echo " ⚠️ Failed to add label (may already exist or have permission issues)" - fi - # Add PR number to the list - if [[ -z "${PRS_NEEDING_COMMENT}" ]]; then - PRS_NEEDING_COMMENT="${PR_NUMBER}" + if [[ "${IS_DRAFT}" == "true" ]]; then + echo "📝 PR #${PR_NUMBER} is a draft and has no linked issue, skipping status/need-issue label" + # Remove status/need-issue label if it was previously added + if ! gh pr edit "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --remove-label "status/need-issue" 2>/dev/null; then + echo " status/need-issue label not present or could not be removed" + fi + echo "needs_comment=false" >> "${GITHUB_OUTPUT}" else - PRS_NEEDING_COMMENT="${PRS_NEEDING_COMMENT},${PR_NUMBER}" + echo "⚠️ No linked issue found for PR #${PR_NUMBER}, adding status/need-issue label" + if ! gh pr edit "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --add-label "status/need-issue" 2>/dev/null; then + echo " ⚠️ Failed to add label (may already exist or have permission issues)" + fi + # Add PR number to the list + if [[ -z "${PRS_NEEDING_COMMENT}" ]]; then + PRS_NEEDING_COMMENT="${PR_NUMBER}" + else + PRS_NEEDING_COMMENT="${PRS_NEEDING_COMMENT},${PR_NUMBER}" + fi + echo "needs_comment=true" >> "${GITHUB_OUTPUT}" fi - echo "needs_comment=true" >> "${GITHUB_OUTPUT}" else echo "🔗 Found linked issue #${ISSUE_NUMBER}" @@ -46,11 +62,16 @@ process_pr() { fi # Get issue labels - echo "📥 Fetching labels from issue #${ISSUE_NUMBER}" + echo "📥 Fetching area and priority labels from issue #${ISSUE_NUMBER}" local ISSUE_LABELS="" - if ! ISSUE_LABELS=$(gh issue view "${ISSUE_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json labels -q '.labels[].name' 2>/dev/null | tr '\n' ',' | sed 's/,$//' || echo ""); then + local gh_output + if ! gh_output=$(gh issue view "${ISSUE_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json labels -q '.labels[].name' 2>/dev/null); then echo " ⚠️ Could not fetch issue #${ISSUE_NUMBER} (may not exist or be in different repo)" ISSUE_LABELS="" + else + # If grep finds no matches, it exits with 1, which pipefail would treat as an error. + # `|| echo ""` ensures the command succeeds with an empty string in that case. + ISSUE_LABELS=$(echo "${gh_output}" | grep -E "^(area|priority)/" | tr '\n' ',' | sed 's/,$//' || echo "") fi # Get PR labels @@ -61,18 +82,18 @@ process_pr() { PR_LABELS="" fi - echo " Issue labels: ${ISSUE_LABELS}" + echo " Issue labels (area/priority): ${ISSUE_LABELS}" echo " PR labels: ${PR_LABELS}" # Convert comma-separated strings to arrays local ISSUE_LABEL_ARRAY PR_LABEL_ARRAY IFS=',' read -ra ISSUE_LABEL_ARRAY <<< "${ISSUE_LABELS}" - IFS=',' read -ra PR_LABEL_ARRAY <<< "${PR_LABELS}" + IFS=',' read -ra PR_LABEL_ARRAY <<< "${PR_LABELS:-}" # Find labels to add (on issue but not on PR) local LABELS_TO_ADD="" for label in "${ISSUE_LABEL_ARRAY[@]}"; do - if [[ -n "${label}" ]] && [[ " ${PR_LABEL_ARRAY[*]} " != *" ${label} "* ]]; then + if [[ -n "${label}" ]] && [[ " ${PR_LABEL_ARRAY[*]:-}" != *" ${label} "* ]]; then if [[ -z "${LABELS_TO_ADD}" ]]; then LABELS_TO_ADD="${label}" else From d4b418ba01f16ed5962357cac95832fa4ff823aa Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Wed, 7 Jan 2026 15:01:57 -0800 Subject: [PATCH 047/713] Fix and rename introspection agent -> cli help agent (#16097) --- docs/get-started/configuration.md | 4 +-- integration-tests/json-output.test.ts | 3 +- packages/cli/src/config/config.ts | 3 +- packages/cli/src/config/settingsSchema.ts | 10 +++---- ...n-agent.test.ts => cli-help-agent.test.ts} | 18 +++++++---- ...trospection-agent.ts => cli-help-agent.ts} | 25 ++++++++-------- packages/core/src/agents/registry.test.ts | 12 ++++---- packages/core/src/agents/registry.ts | 10 +++---- packages/core/src/config/config.ts | 14 ++++----- packages/core/src/tools/get-internal-docs.ts | 30 +++++++------------ schemas/settings.schema.json | 14 ++++----- 11 files changed, 71 insertions(+), 72 deletions(-) rename packages/core/src/agents/{introspection-agent.test.ts => cli-help-agent.test.ts} (77%) rename packages/core/src/agents/{introspection-agent.ts => cli-help-agent.ts} (75%) diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 047a0eff31..c01240dcb9 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -851,8 +851,8 @@ their corresponding top-level category object in your `settings.json` file. (useful for remote sessions). - **Default:** `false` -- **`experimental.introspectionAgentSettings.enabled`** (boolean): - - **Description:** Enable the Introspection Agent. +- **`experimental.cliHelpAgentSettings.enabled`** (boolean): + - **Description:** Enable the CLI Help Agent. - **Default:** `false` - **Requires restart:** Yes diff --git a/integration-tests/json-output.test.ts b/integration-tests/json-output.test.ts index 4d3bdb6a18..0221034d3e 100644 --- a/integration-tests/json-output.test.ts +++ b/integration-tests/json-output.test.ts @@ -9,7 +9,8 @@ import { TestRig } from './test-helper.js'; import { join } from 'node:path'; import { ExitCodes } from '@google/gemini-cli-core/src/index.js'; -describe('JSON output', () => { +// TODO: Enable these tests once we figure out why they are flaky in CI. +describe.skip('JSON output', () => { let rig: TestRig; beforeEach(async () => { diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index e94119a931..2e2ecbd87f 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -731,8 +731,7 @@ export async function loadCliConfig( }, codebaseInvestigatorSettings: settings.experimental?.codebaseInvestigatorSettings, - introspectionAgentSettings: - settings.experimental?.introspectionAgentSettings, + cliHelpAgentSettings: settings.experimental?.cliHelpAgentSettings, fakeResponses: argv.fakeResponses, recordResponses: argv.recordResponses, retryFetchErrors: settings.general?.retryFetchErrors, diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index efe535e42e..38d075b207 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -1453,22 +1453,22 @@ const SETTINGS_SCHEMA = { 'Use OSC 52 sequence for pasting instead of clipboardy (useful for remote sessions).', showInDialog: true, }, - introspectionAgentSettings: { + cliHelpAgentSettings: { type: 'object', - label: 'Introspection Agent Settings', + label: 'CLI Help Agent Settings', category: 'Experimental', requiresRestart: true, default: {}, - description: 'Configuration for Introspection Agent.', + description: 'Configuration for CLI Help Agent.', showInDialog: false, properties: { enabled: { type: 'boolean', - label: 'Enable Introspection Agent', + label: 'Enable CLI Help Agent', category: 'Experimental', requiresRestart: true, default: false, - description: 'Enable the Introspection Agent.', + description: 'Enable the CLI Help Agent.', showInDialog: true, }, }, diff --git a/packages/core/src/agents/introspection-agent.test.ts b/packages/core/src/agents/cli-help-agent.test.ts similarity index 77% rename from packages/core/src/agents/introspection-agent.test.ts rename to packages/core/src/agents/cli-help-agent.test.ts index 5feac834f5..b1552f3d62 100644 --- a/packages/core/src/agents/introspection-agent.test.ts +++ b/packages/core/src/agents/cli-help-agent.test.ts @@ -5,18 +5,22 @@ */ import { describe, it, expect } from 'vitest'; -import { IntrospectionAgent } from './introspection-agent.js'; +import { CliHelpAgent } from './cli-help-agent.js'; import { GET_INTERNAL_DOCS_TOOL_NAME } from '../tools/tool-names.js'; import { GEMINI_MODEL_ALIAS_FLASH } from '../config/models.js'; import type { LocalAgentDefinition } from './types.js'; +import type { Config } from '../config/config.js'; -describe('IntrospectionAgent', () => { - const localAgent = IntrospectionAgent as LocalAgentDefinition; +describe('CliHelpAgent', () => { + const fakeConfig = { + getMessageBus: () => ({}), + } as unknown as Config; + const localAgent = CliHelpAgent(fakeConfig) as LocalAgentDefinition; it('should have the correct agent definition metadata', () => { - expect(localAgent.name).toBe('introspection_agent'); + expect(localAgent.name).toBe('cli_help'); expect(localAgent.kind).toBe('local'); - expect(localAgent.displayName).toBe('Introspection Agent'); + expect(localAgent.displayName).toBe('CLI Help Agent'); expect(localAgent.description).toContain('Gemini CLI'); }); @@ -32,7 +36,9 @@ describe('IntrospectionAgent', () => { expect(localAgent.modelConfig?.model).toBe(GEMINI_MODEL_ALIAS_FLASH); const tools = localAgent.toolConfig?.tools || []; - const hasInternalDocsTool = tools.includes(GET_INTERNAL_DOCS_TOOL_NAME); + const hasInternalDocsTool = tools.some( + (t) => typeof t !== 'string' && t.name === GET_INTERNAL_DOCS_TOOL_NAME, + ); expect(hasInternalDocsTool).toBe(true); }); diff --git a/packages/core/src/agents/introspection-agent.ts b/packages/core/src/agents/cli-help-agent.ts similarity index 75% rename from packages/core/src/agents/introspection-agent.ts rename to packages/core/src/agents/cli-help-agent.ts index 8801af6d50..331be120e9 100644 --- a/packages/core/src/agents/introspection-agent.ts +++ b/packages/core/src/agents/cli-help-agent.ts @@ -5,11 +5,12 @@ */ import type { AgentDefinition } from './types.js'; -import { GET_INTERNAL_DOCS_TOOL_NAME } from '../tools/tool-names.js'; import { GEMINI_MODEL_ALIAS_FLASH } from '../config/models.js'; import { z } from 'zod'; +import type { Config } from '../config/config.js'; +import { GetInternalDocsTool } from '../tools/get-internal-docs.js'; -const IntrospectionReportSchema = z.object({ +const CliHelpReportSchema = z.object({ answer: z .string() .describe('The detailed answer to the user question about Gemini CLI.'), @@ -22,14 +23,14 @@ const IntrospectionReportSchema = z.object({ * An agent specialized in answering questions about Gemini CLI itself, * using its own documentation and runtime state. */ -export const IntrospectionAgent: AgentDefinition< - typeof IntrospectionReportSchema -> = { - name: 'introspection_agent', +export const CliHelpAgent = ( + config: Config, +): AgentDefinition => ({ + name: 'cli_help', kind: 'local', - displayName: 'Introspection Agent', + displayName: 'CLI Help Agent', description: - 'Specialized in answering questions about yourself (Gemini CLI): features, documentation, and current runtime configuration.', + 'Specialized in answering questions about how users use you, (Gemini CLI): features, documentation, and current runtime configuration.', inputConfig: { inputs: { question: { @@ -42,7 +43,7 @@ export const IntrospectionAgent: AgentDefinition< outputConfig: { outputName: 'report', description: 'The final answer and sources as a JSON object.', - schema: IntrospectionReportSchema, + schema: CliHelpReportSchema, }, processOutput: (output) => JSON.stringify(output, null, 2), @@ -60,7 +61,7 @@ export const IntrospectionAgent: AgentDefinition< }, toolConfig: { - tools: [GET_INTERNAL_DOCS_TOOL_NAME], + tools: [new GetInternalDocsTool(config.getMessageBus())], }, promptConfig: { @@ -70,7 +71,7 @@ export const IntrospectionAgent: AgentDefinition< '${question}\n' + '', systemPrompt: - "You are **Introspection Agent**, an expert on Gemini CLI. Your purpose is to provide accurate information about Gemini CLI's features, configuration, and current state.\n\n" + + "You are **CLI Help Agent**, an expert on Gemini CLI. Your purpose is to provide accurate information about Gemini CLI's features, configuration, and current state.\n\n" + '### Runtime Context\n' + '- **CLI Version:** ${cliVersion}\n' + '- **Active Model:** ${activeModel}\n' + @@ -82,4 +83,4 @@ export const IntrospectionAgent: AgentDefinition< '4. **Non-Interactive**: You operate in a loop and cannot ask the user for more info. If the question is ambiguous, answer as best as you can with the information available.\n\n' + 'You MUST call `complete_task` with a JSON report containing your `answer` and the `sources` you used.', }, -}; +}); diff --git a/packages/core/src/agents/registry.test.ts b/packages/core/src/agents/registry.test.ts index f369e59b21..5517909045 100644 --- a/packages/core/src/agents/registry.test.ts +++ b/packages/core/src/agents/registry.test.ts @@ -220,26 +220,26 @@ describe('AgentRegistry', () => { ).not.toHaveBeenCalled(); }); - it('should register introspection agent if enabled', async () => { + it('should register CLI help agent if enabled', async () => { const config = makeFakeConfig({ - introspectionAgentSettings: { enabled: true }, + cliHelpAgentSettings: { enabled: true }, }); const registry = new TestableAgentRegistry(config); await registry.initialize(); - expect(registry.getDefinition('introspection_agent')).toBeDefined(); + expect(registry.getDefinition('cli_help')).toBeDefined(); }); - it('should NOT register introspection agent if disabled', async () => { + it('should NOT register CLI help agent if disabled', async () => { const config = makeFakeConfig({ - introspectionAgentSettings: { enabled: false }, + cliHelpAgentSettings: { enabled: false }, }); const registry = new TestableAgentRegistry(config); await registry.initialize(); - expect(registry.getDefinition('introspection_agent')).toBeUndefined(); + expect(registry.getDefinition('cli_help')).toBeUndefined(); }); }); diff --git a/packages/core/src/agents/registry.ts b/packages/core/src/agents/registry.ts index 2e3e810b55..13f203d7d1 100644 --- a/packages/core/src/agents/registry.ts +++ b/packages/core/src/agents/registry.ts @@ -10,7 +10,7 @@ import type { Config } from '../config/config.js'; import type { AgentDefinition } from './types.js'; import { loadAgentsFromDirectory } from './toml-loader.js'; import { CodebaseInvestigatorAgent } from './codebase-investigator.js'; -import { IntrospectionAgent } from './introspection-agent.js'; +import { CliHelpAgent } from './cli-help-agent.js'; import { A2AClientManager } from './a2a-client-manager.js'; import { ADCHandler } from './remote-invocation.js'; import { type z } from 'zod'; @@ -106,7 +106,7 @@ export class AgentRegistry { private loadBuiltInAgents(): void { const investigatorSettings = this.config.getCodebaseInvestigatorSettings(); - const introspectionSettings = this.config.getIntrospectionAgentSettings(); + const cliHelpSettings = this.config.getCliHelpAgentSettings(); // Only register the agent if it's enabled in the settings. if (investigatorSettings?.enabled) { @@ -145,9 +145,9 @@ export class AgentRegistry { this.registerLocalAgent(agentDef); } - // Register the introspection agent if it's explicitly enabled. - if (introspectionSettings.enabled) { - this.registerLocalAgent(IntrospectionAgent); + // Register the CLI help agent if it's explicitly enabled. + if (cliHelpSettings.enabled) { + this.registerLocalAgent(CliHelpAgent(this.config)); } } diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index cc9929f23c..2021576643 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -151,7 +151,7 @@ export interface ResolvedExtensionSetting { sensitive: boolean; } -export interface IntrospectionAgentSettings { +export interface CliHelpAgentSettings { enabled?: boolean; } @@ -333,7 +333,7 @@ export interface ConfigParameters { output?: OutputSettings; disableModelRouterForAuth?: AuthType[]; codebaseInvestigatorSettings?: CodebaseInvestigatorSettings; - introspectionAgentSettings?: IntrospectionAgentSettings; + cliHelpAgentSettings?: CliHelpAgentSettings; continueOnFailedApiCall?: boolean; retryFetchErrors?: boolean; enableShellOutputEfficiency?: boolean; @@ -461,7 +461,7 @@ export class Config { private readonly policyEngine: PolicyEngine; private readonly outputSettings: OutputSettings; private readonly codebaseInvestigatorSettings: CodebaseInvestigatorSettings; - private readonly introspectionAgentSettings: IntrospectionAgentSettings; + private readonly cliHelpAgentSettings: CliHelpAgentSettings; private readonly continueOnFailedApiCall: boolean; private readonly retryFetchErrors: boolean; private readonly enableShellOutputEfficiency: boolean; @@ -621,8 +621,8 @@ export class Config { DEFAULT_THINKING_MODE, model: params.codebaseInvestigatorSettings?.model, }; - this.introspectionAgentSettings = { - enabled: params.introspectionAgentSettings?.enabled ?? false, + this.cliHelpAgentSettings = { + enabled: params.cliHelpAgentSettings?.enabled ?? false, }; this.continueOnFailedApiCall = params.continueOnFailedApiCall ?? true; this.enableShellOutputEfficiency = @@ -1682,8 +1682,8 @@ export class Config { return this.codebaseInvestigatorSettings; } - getIntrospectionAgentSettings(): IntrospectionAgentSettings { - return this.introspectionAgentSettings; + getCliHelpAgentSettings(): CliHelpAgentSettings { + return this.cliHelpAgentSettings; } async createToolRegistry(): Promise { diff --git a/packages/core/src/tools/get-internal-docs.ts b/packages/core/src/tools/get-internal-docs.ts index c18c155404..a02bcf9fc6 100644 --- a/packages/core/src/tools/get-internal-docs.ts +++ b/packages/core/src/tools/get-internal-docs.ts @@ -36,7 +36,7 @@ export interface GetInternalDocsParams { */ async function getDocsRoot(): Promise { const currentFile = fileURLToPath(import.meta.url); - const currentDir = path.dirname(currentFile); + let searchDir = path.dirname(currentFile); const isDocsDir = async (dir: string) => { try { @@ -52,25 +52,17 @@ async function getDocsRoot(): Promise { return false; }; - // 1. Check for documentation in the distributed package (dist/docs) - // Path: dist/src/tools/get-internal-docs.js -> dist/docs - const distDocsPath = path.resolve(currentDir, '..', '..', 'docs'); - if (await isDocsDir(distDocsPath)) { - return distDocsPath; - } + while (true) { + const candidate = path.join(searchDir, 'docs'); + if (await isDocsDir(candidate)) { + return candidate; + } - // 2. Check for documentation in the repository root (development) - // Path: packages/core/src/tools/get-internal-docs.ts -> docs/ - const repoDocsPath = path.resolve(currentDir, '..', '..', '..', '..', 'docs'); - if (await isDocsDir(repoDocsPath)) { - return repoDocsPath; - } - - // 3. Check for documentation in the bundle directory (bundle/docs) - // Path: bundle/gemini.js -> bundle/docs - const bundleDocsPath = path.join(currentDir, 'docs'); - if (await isDocsDir(bundleDocsPath)) { - return bundleDocsPath; + const parent = path.dirname(searchDir); + if (parent === searchDir) { + break; + } + searchDir = parent; } throw new Error('Could not find Gemini CLI documentation directory.'); diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index f7f134d2c9..e7473ea395 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -1425,17 +1425,17 @@ "default": false, "type": "boolean" }, - "introspectionAgentSettings": { - "title": "Introspection Agent Settings", - "description": "Configuration for Introspection Agent.", - "markdownDescription": "Configuration for Introspection Agent.\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `{}`", + "cliHelpAgentSettings": { + "title": "CLI Help Agent Settings", + "description": "Configuration for CLI Help Agent.", + "markdownDescription": "Configuration for CLI Help Agent.\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `{}`", "default": {}, "type": "object", "properties": { "enabled": { - "title": "Enable Introspection Agent", - "description": "Enable the Introspection Agent.", - "markdownDescription": "Enable the Introspection Agent.\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `false`", + "title": "Enable CLI Help Agent", + "description": "Enable the CLI Help Agent.", + "markdownDescription": "Enable the CLI Help Agent.\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `false`", "default": false, "type": "boolean" } From 51d3f44d51066ec7dd2d80a2f61de2534a54eed3 Mon Sep 17 00:00:00 2001 From: Jenna Inouye Date: Wed, 7 Jan 2026 15:28:32 -0800 Subject: [PATCH 048/713] Docs: Changelogs update 20260105 (#15937) --- docs/changelogs/index.md | 22 +++ docs/changelogs/latest.md | 346 ++++++++++++++--------------------- docs/changelogs/preview.md | 230 +++++++++++------------ docs/changelogs/releases.md | 280 +++++++++++++++++++++++++++- docs/get-started/gemini-3.md | 19 +- 5 files changed, 550 insertions(+), 347 deletions(-) diff --git a/docs/changelogs/index.md b/docs/changelogs/index.md index e89b2eddd9..b0ae3518bf 100644 --- a/docs/changelogs/index.md +++ b/docs/changelogs/index.md @@ -18,6 +18,28 @@ on GitHub. | [Preview](preview.md) | Experimental features ready for early feedback. | | [Stable](latest.md) | Stable, recommended for general use. | +## Announcements: v0.22.0 - 2025-12-22 + +- 🎉**Free Tier + Gemini 3:** Free tier users now all have access to Gemini 3 + Pro & Flash. Enable in `/settings` by toggling "Preview Features" to `true`. +- 🎉**Gemini CLI + Colab:** Gemini CLI is now pre-installed. Can be used + headlessly in notebook cells or interactively in the built-in terminal + ([pic](https://imgur.com/a/G0Tn7vi)) +- 🎉**Gemini CLI Extensions:** + - **Conductor:** Planning++, Gemini works with you to build out a detailed + plan, pull in extra details as needed, ultimately to give the LLM guardrails + with artifacts. Measure twice, implement once! + + `gemini extensions install https://github.com/gemini-cli-extensions/conductor` + + Blog: + [https://developers.googleblog.com/conductor-introducing-context-driven-development-for-gemini-cli/](https://developers.googleblog.com/conductor-introducing-context-driven-development-for-gemini-cli/) + + - **Endor Labs:** Perform code analysis, vulnerability scanning, and + dependency checks using natural language. + + `gemini extensions install https://github.com/endorlabs/gemini-extension` + ## Announcements: v0.21.0 - 2025-12-15 - **⚡️⚡️⚡️ Gemini 3 Flash + Gemini CLI:** Better, faster and cheaper than 2.5 diff --git a/docs/changelogs/latest.md b/docs/changelogs/latest.md index 1fc9683861..295a4f6e3e 100644 --- a/docs/changelogs/latest.md +++ b/docs/changelogs/latest.md @@ -1,6 +1,6 @@ -# Latest stable release: v0.21.0 - v0.21.1 +# Latest stable release: v0.22.0 - v0.22.5 -Released: December 16, 2025 +Released: December 30, 2025 For most users, our latest stable release is the recommended release. Install the latest stable version with: @@ -11,215 +11,143 @@ npm install -g @google/gemini-cli ## Highlights -- **⚡️⚡️⚡️ Gemini 3 Flash + Gemini CLI:** If you are a paid user, you can now - enable Gemini 3 Pro and Gemini 3 Flash. Go to `/settings` and set **Preview - Features** to `true` to enable Gemini 3. For more information: - [Gemini 3 Flash is now available in Gemini CLI](https://developers.googleblog.com/gemini-3-flash-is-now-available-in-gemini-cli/). +- **Comprehensive quota visibility:** View usage statistics for all available + models in the `/stats` command, even those not yet used in your current + session. ([pic](https://imgur.com/a/cKyDtYh), + [pr](https://github.com/google-gemini/gemini-cli/pull/14764) by + [@sehoon38](https://github.com/sehoon38)) +- **Polished CLI statistics:** We’ve cleaned up the `/stats` view to prioritize + actionable quota information while providing a detailed token and + cache-efficiency breakdown in `/stats model` + ([login with Google](https://imgur.com/a/w9xKthm), + [api key](https://imgur.com/a/FjQPHOY), + [model stats](https://imgur.com/a/VfWzVgw), + [pr](https://github.com/google-gemini/gemini-cli/pull/14961) by + [@jacob314](https://github.com/jacob314)) +- **Multi-file drag & drop:** Multi-file drag & drop is now supported and + properly translated to be prefixed with `@`. + ([pr](https://github.com/google-gemini/gemini-cli/pull/14832) by + [@jackwotherspoon](https://github.com/jackwotherspoon)) ## What's Changed -- refactor(stdio): always patch stdout and use createWorkingStdio for clean - output by @allenhutchison in - https://github.com/google-gemini/gemini-cli/pull/14159 -- chore(release): bump version to 0.21.0-nightly.20251202.2d935b379 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14409 -- implement fuzzy search inside settings by @sehoon38 in - https://github.com/google-gemini/gemini-cli/pull/13864 -- feat: enable message bus integration by default by @allenhutchison in - https://github.com/google-gemini/gemini-cli/pull/14329 -- docs: Recommend using --debug intead of --verbose for CLI debugging by @bbiggs - in https://github.com/google-gemini/gemini-cli/pull/14334 -- feat: consolidate remote MCP servers to use `url` in config by - @jackwotherspoon in https://github.com/google-gemini/gemini-cli/pull/13762 -- Restrict integration tests tools by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14403 -- track github repository names in telemetry events by @IamRiddhi in - https://github.com/google-gemini/gemini-cli/pull/13670 -- Allow telemetry exporters to GCP to utilize user's login credentials, if - requested by @mboshernitsan in - https://github.com/google-gemini/gemini-cli/pull/13778 -- refactor(editor): use const assertion for editor types with single source of - truth by @amsminn in https://github.com/google-gemini/gemini-cli/pull/8604 -- fix(security): Fix npm audit vulnerabilities in glob and body-parser by - @afarber in https://github.com/google-gemini/gemini-cli/pull/14090 -- Add new enterprise instructions by @chrstnb in - https://github.com/google-gemini/gemini-cli/pull/8641 -- feat(hooks): Hook Session Lifecycle & Compression Integration by @Edilmo in - https://github.com/google-gemini/gemini-cli/pull/14151 -- Avoid triggering refreshStatic unless there really is a banner to display. by - @jacob314 in https://github.com/google-gemini/gemini-cli/pull/14328 -- feat(hooks): Hooks Commands Panel, Enable/Disable, and Migrate by @Edilmo in - https://github.com/google-gemini/gemini-cli/pull/14225 -- fix: Bundle default policies for npx distribution by @allenhutchison in - https://github.com/google-gemini/gemini-cli/pull/14457 -- feat(hooks): Hook System Documentation by @Edilmo in - https://github.com/google-gemini/gemini-cli/pull/14307 -- Fix tests by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14458 -- feat: add scheduled workflow to close stale issues by @galz10 in - https://github.com/google-gemini/gemini-cli/pull/14404 -- feat: Support Extension Hooks with Security Warning by @abhipatel12 in - https://github.com/google-gemini/gemini-cli/pull/14460 -- feat: Add enableAgents experimental flag by @adamfweidman in - https://github.com/google-gemini/gemini-cli/pull/14371 -- docs: fix typo 'socus' to 'focus' in todos.md by @Viktor286 in - https://github.com/google-gemini/gemini-cli/pull/14374 -- Markdown export: move the emoji to the end of the line by @mhansen in - https://github.com/google-gemini/gemini-cli/pull/12278 -- fix(acp): prevent unnecessary credential cache clearing on re-authent… by - @h-michael in https://github.com/google-gemini/gemini-cli/pull/9410 -- fix(cli): Fix word navigation for CJK characters by @SandyTao520 in - https://github.com/google-gemini/gemini-cli/pull/14475 -- Remove example extension by @chrstnb in - https://github.com/google-gemini/gemini-cli/pull/14376 -- Add commands for listing and updating per-extension settings by @chrstnb in - https://github.com/google-gemini/gemini-cli/pull/12664 -- chore(tests): remove obsolete test for hierarchical memory by @pareshjoshij in - https://github.com/google-gemini/gemini-cli/pull/13122 -- feat(cli): support /copy in remote sessions using OSC52 by @ismellpillows in - https://github.com/google-gemini/gemini-cli/pull/13471 -- Update setting search UX by @Adib234 in - https://github.com/google-gemini/gemini-cli/pull/14451 -- Fix(cli): Improve Homebrew update instruction to specify gemini-cli by - @DaanVersavel in https://github.com/google-gemini/gemini-cli/pull/14502 -- do not toggle the setting item when entering space by @sehoon38 in - https://github.com/google-gemini/gemini-cli/pull/14489 -- fix: improve retry logic for fetch errors and network codes by @megha1188 in - https://github.com/google-gemini/gemini-cli/pull/14439 -- remove unused isSearching field by @sehoon38 in - https://github.com/google-gemini/gemini-cli/pull/14509 -- feat(mcp): add `--type` alias for `--transport` flag in gemini mcp add by - @jackwotherspoon in https://github.com/google-gemini/gemini-cli/pull/14503 -- feat(cli): Move key restore logic to core by @cocosheng-g in - https://github.com/google-gemini/gemini-cli/pull/13013 -- feat: add auto-execute on Enter behavior to argumentless MCP prompts by - @jackwotherspoon in https://github.com/google-gemini/gemini-cli/pull/14510 -- fix(shell): cursor visibility when using interactive mode by @aswinashok44 in - https://github.com/google-gemini/gemini-cli/pull/14095 -- Adding session id as part of json o/p by @MJjainam in - https://github.com/google-gemini/gemini-cli/pull/14504 -- fix(extensions): resolve GitHub API 415 error for source tarballs by - @jpoehnelt in https://github.com/google-gemini/gemini-cli/pull/13319 -- fix(client): Correctly latch hasFailedCompressionAttempt flag by @pareshjoshij - in https://github.com/google-gemini/gemini-cli/pull/13002 -- Disable flaky extension reloading test on linux by @chrstnb in - https://github.com/google-gemini/gemini-cli/pull/14528 -- Add support for MCP dynamic tool update by `notifications/tools/list_changed` - by @Adib234 in https://github.com/google-gemini/gemini-cli/pull/14375 -- Fix privacy screen for legacy tier users by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14522 -- feat: Exclude maintainer labeled issues from stale issue closer by @galz10 in - https://github.com/google-gemini/gemini-cli/pull/14532 -- Grant chained workflows proper permission. by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14534 -- Make trigger_e2e manually fireable. by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14547 -- Write e2e status to local repo not forked repo by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14549 -- Fixes [API Error: Cannot read properties of undefined (reading 'error')] by - @silviojr in https://github.com/google-gemini/gemini-cli/pull/14553 -- Trigger chained e2e tests on all pull requests by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14551 -- Fix bug in the shellExecutionService resulting in both truncation and 3X bloat - by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/14545 -- Fix issue where we were passing the model content reflecting terminal line - wrapping. by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/14566 -- chore/release: bump version to 0.21.0-nightly.20251204.3da4fd5f7 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14476 -- feat(sessions): use 1-line generated session summary to describe sessions by - @jackwotherspoon in https://github.com/google-gemini/gemini-cli/pull/14467 -- Use Robot PAT for chained e2e merge queue skipper by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14585 -- fix(core): improve API response error handling and retry logic by @mattKorwel - in https://github.com/google-gemini/gemini-cli/pull/14563 -- Docs: Model routing clarification by @jkcinouye in - https://github.com/google-gemini/gemini-cli/pull/14373 -- expose previewFeatures flag in a2a by @sehoon38 in - https://github.com/google-gemini/gemini-cli/pull/14550 -- Fix emoji width in debug console. by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/14593 -- Fully detach autoupgrade process by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14595 -- Docs: Update Gemini 3 on Gemini CLI documentation by @jkcinouye in - https://github.com/google-gemini/gemini-cli/pull/14601 -- Disallow floating promises. by @gundermanc in - https://github.com/google-gemini/gemini-cli/pull/14605 -- chore/release: bump version to 0.21.0-nightly.20251207.025e450ac by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14662 -- feat(modelAvailabilityService): integrate model availability service into - backend logic by @adamfweidman in - https://github.com/google-gemini/gemini-cli/pull/14470 -- Add prompt_id propagation in a2a-server task by @koxkox111 in - https://github.com/google-gemini/gemini-cli/pull/14581 -- Fix: Prevent freezing in non-interactive Gemini CLI when debug mode is enabled - by @parthasaradhie in https://github.com/google-gemini/gemini-cli/pull/14580 -- fix(audio): improve reading of audio files by @jackwotherspoon in - https://github.com/google-gemini/gemini-cli/pull/14658 -- Update automated triage workflow to stop assigning priority labels by - @skeshive in https://github.com/google-gemini/gemini-cli/pull/14717 -- set failed status when chained e2e fails by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14725 -- feat(github action) Triage and Label Pull Requests by Size and Comple… by - @DaanVersavel in https://github.com/google-gemini/gemini-cli/pull/5571 -- refactor(telemetry): Improve previous PR that allows telemetry to use the CLI - auth and add testing by @mboshernitsan in - https://github.com/google-gemini/gemini-cli/pull/14589 -- Always set status in chained_e2e workflow by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14730 -- feat: Add OTEL log event `gemini_cli.startup_stats` for startup stats. by - @kevin-ramdass in https://github.com/google-gemini/gemini-cli/pull/14734 -- feat: auto-execute on slash command completion functions by @jackwotherspoon - in https://github.com/google-gemini/gemini-cli/pull/14584 -- Docs: Proper release notes by @jkcinouye in - https://github.com/google-gemini/gemini-cli/pull/14405 -- Add support for user-scoped extension settings by @chrstnb in - https://github.com/google-gemini/gemini-cli/pull/13748 -- refactor(core): Improve environment variable handling in shell execution by - @galz10 in https://github.com/google-gemini/gemini-cli/pull/14742 -- Remove old E2E Workflows by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14749 -- fix: handle missing local extension config and skip hooks when disabled by - @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/14744 -- chore/release: bump version to 0.21.0-nightly.20251209.ec9a8c7a7 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14751 -- feat: Add support for MCP Resources by @MrLesk in - https://github.com/google-gemini/gemini-cli/pull/13178 -- Always set pending status in E2E tests by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14756 -- fix(lint): upgrade pip and use public pypi for yamllint by @allenhutchison in - https://github.com/google-gemini/gemini-cli/pull/14746 -- fix: use Gemini API supported image formats for clipboard by @jackwotherspoon - in https://github.com/google-gemini/gemini-cli/pull/14762 -- feat(a2a): Introduce restore command for a2a server by @cocosheng-g in - https://github.com/google-gemini/gemini-cli/pull/13015 -- allow final:true to be returned on a2a server edit calls. by @DavidAPierce in - https://github.com/google-gemini/gemini-cli/pull/14747 -- (fix) Automated pr labeller by @DaanVersavel in - https://github.com/google-gemini/gemini-cli/pull/14788 -- Update CODEOWNERS by @kklashtorny1 in - https://github.com/google-gemini/gemini-cli/pull/14830 -- Docs: Fix errors preventing site rebuild. by @jkcinouye in - https://github.com/google-gemini/gemini-cli/pull/14842 -- chore(deps): bump express from 5.1.0 to 5.2.0 by @dependabot[bot] in - https://github.com/google-gemini/gemini-cli/pull/14325 -- fix(patch): cherry-pick 3f5f030 to release/v0.21.0-preview.0-pr-14843 to patch - version v0.21.0-preview.0 and create version 0.21.0-preview.1 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14851 -- fix(patch): cherry-pick ee6556c to release/v0.21.0-preview.1-pr-14691 to patch - version v0.21.0-preview.1 and create version 0.21.0-preview.2 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14908 -- fix(patch): cherry-pick 54de675 to release/v0.21.0-preview.2-pr-14961 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14968 -- fix(patch): cherry-pick 12cbe32 to release/v0.21.0-preview.3-pr-15000 to patch - version v0.21.0-preview.3 and create version 0.21.0-preview.4 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15003 -- fix(patch): cherry-pick edbe548 to release/v0.21.0-preview.4-pr-15007 to patch - version v0.21.0-preview.4 and create version 0.21.0-preview.5 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15015 -- fix(patch): cherry-pick 2995af6 to release/v0.21.0-preview.5-pr-15131 to patch - version v0.21.0-preview.5 and create version 0.21.0-preview.6 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15153 +- feat(ide): fallback to GEMINI_CLI_IDE_AUTH_TOKEN env var by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/14843 +- feat: display quota stats for unused models in /stats by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/14764 +- feat: ensure codebase investigator uses preview model when main agent does by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/14412 +- chore: add closing reason to stale bug workflow by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/14861 +- Send the model and CLI version with the user agent by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/14865 +- refactor(sessions): move session summary generation to startup by + @jackwotherspoon in https://github.com/google-gemini/gemini-cli/pull/14691 +- Limit search depth in path corrector by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/14869 +- Fix: Correct typo in code comment by @kuishou68 in + https://github.com/google-gemini/gemini-cli/pull/14671 +- feat(core): Plumbing for late resolution of model configs. by @joshualitt in + https://github.com/google-gemini/gemini-cli/pull/14597 +- feat: attempt more error parsing by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/14899 +- Add missing await. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/14910 +- feat(core): Add support for transcript_path in hooks for git-ai/Gemini + extension by @svarlamov in + https://github.com/google-gemini/gemini-cli/pull/14663 +- refactor: implement DelegateToAgentTool with discriminated union by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/14769 +- feat: reset availabilityService on /auth by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/14911 +- chore/release: bump version to 0.21.0-nightly.20251211.8c83e1ea9 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14924 +- Fix: Correctly detect MCP tool errors by @kevin-ramdass in + https://github.com/google-gemini/gemini-cli/pull/14937 +- increase labeler timeout by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/14922 +- tool(cli): tweak the frontend tool to be aware of more core files from the cli + by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/14962 +- feat(cli): polish cached token stats and simplify stats display when quota is + present. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/14961 +- feat(settings-validation): add validation for settings schema by @lifefloating + in https://github.com/google-gemini/gemini-cli/pull/12929 +- fix(ide): Update IDE extension to write auth token in env var by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/14999 +- Revert "chore(deps): bump express from 5.1.0 to 5.2.0" by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/14998 +- feat(a2a): Introduce /init command for a2a server by @cocosheng-g in + https://github.com/google-gemini/gemini-cli/pull/13419 +- feat: support multi-file drag and drop of images by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/14832 +- fix(policy): allow codebase_investigator by default in read-only policy by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15000 +- refactor(ide ext): Update port file name + switch to 1-based index for + characters + remove truncation text by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/10501 +- fix(vscode-ide-companion): correct license generation for workspace + dependencies by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/15004 +- fix: temp fix for subagent invocation until subagent delegation is merged to + stable by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15007 +- test: update ide detection tests to make them more robust when run in an ide + by @kevin-ramdass in https://github.com/google-gemini/gemini-cli/pull/15008 +- Remove flex from stats display. See snapshots for diffs. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/14983 +- Add license field into package.json by @jb-perez in + https://github.com/google-gemini/gemini-cli/pull/14473 +- feat: Persistent "Always Allow" policies with granular shell & MCP support by + @allenhutchison in https://github.com/google-gemini/gemini-cli/pull/14737 +- chore/release: bump version to 0.21.0-nightly.20251212.54de67536 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14969 +- fix(core): commandPrefix word boundary and compound command safety by + @allenhutchison in https://github.com/google-gemini/gemini-cli/pull/15006 +- chore(docs): add 'Maintainers only' label info to CONTRIBUTING.md by @jacob314 + in https://github.com/google-gemini/gemini-cli/pull/14914 +- Refresh hooks when refreshing extensions. by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/14918 +- Add clarity to error messages by @gsehgal in + https://github.com/google-gemini/gemini-cli/pull/14879 +- chore : remove a redundant tip by @JayadityaGit in + https://github.com/google-gemini/gemini-cli/pull/14947 +- chore/release: bump version to 0.21.0-nightly.20251213.977248e09 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15029 +- Disallow redundant typecasts. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15030 +- fix(auth): prioritize GEMINI_API_KEY env var and skip unnecessary key… by + @galz10 in https://github.com/google-gemini/gemini-cli/pull/14745 +- fix: use zod for safety check result validation by @allenhutchison in + https://github.com/google-gemini/gemini-cli/pull/15026 +- update(telemetry): add hashed_extension_name to field to extension events by + @kiranani in https://github.com/google-gemini/gemini-cli/pull/15025 +- fix: similar to policy-engine, throw error in case of requiring tool execution + confirmation for non-interactive mode by @MayV in + https://github.com/google-gemini/gemini-cli/pull/14702 +- Clean up processes in integration tests by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15102 +- docs: update policy engine getting started and defaults by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15105 +- Fix tool output fragmentation by encapsulating content in functionResponse by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/13082 +- Simplify method signature. by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15114 +- Show raw input token counts in json output. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15021 +- fix: Mark A2A requests as interactive by @MayV in + https://github.com/google-gemini/gemini-cli/pull/15108 +- use previewFeatures to determine which pro model to use for A2A by @sehoon38 + in https://github.com/google-gemini/gemini-cli/pull/15131 +- refactor(cli): fix settings merging so that settings using the new json format + take priority over ones using the old format by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15116 +- fix(patch): cherry-pick a6d1245 to release/v0.22.0-preview.1-pr-15214 to patch + version v0.22.0-preview.1 and create version 0.22.0-preview.2 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15226 +- fix(patch): cherry-pick 9e6914d to release/v0.22.0-preview.2-pr-15288 to patch + version v0.22.0-preview.2 and create version 0.22.0-preview.3 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15294 **Full Changelog**: -https://github.com/google-gemini/gemini-cli/compare/v0.20.2...v0.21.0 +https://github.com/google-gemini/gemini-cli/compare/v0.21.3...v0.22.0 diff --git a/docs/changelogs/preview.md b/docs/changelogs/preview.md index 299c90fbf3..a3484ce03c 100644 --- a/docs/changelogs/preview.md +++ b/docs/changelogs/preview.md @@ -1,6 +1,6 @@ -# Preview release: Release v0.22.0-preview.0 +# Preview release: Release v0.23.0-preview.0 -Released: December 16, 2025 +Released: December 22, 2025 Our preview release includes the latest, new, and experimental features. This release may not be as stable as our [latest weekly release](latest.md). @@ -13,117 +13,119 @@ npm install -g @google/gemini-cli@preview ## What's Changed -- feat(ide): fallback to GEMINI_CLI_IDE_AUTH_TOKEN env var by @skeshive in - https://github.com/google-gemini/gemini-cli/pull/14843 -- feat: display quota stats for unused models in /stats by @sehoon38 in - https://github.com/google-gemini/gemini-cli/pull/14764 -- feat: ensure codebase investigator uses preview model when main agent does by - @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/14412 -- chore: add closing reason to stale bug workflow by @galz10 in - https://github.com/google-gemini/gemini-cli/pull/14861 -- Send the model and CLI version with the user agent by @gundermanc in - https://github.com/google-gemini/gemini-cli/pull/14865 -- refactor(sessions): move session summary generation to startup by - @jackwotherspoon in https://github.com/google-gemini/gemini-cli/pull/14691 -- Limit search depth in path corrector by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14869 -- Fix: Correct typo in code comment by @kuishou68 in - https://github.com/google-gemini/gemini-cli/pull/14671 -- feat(core): Plumbing for late resolution of model configs. by @joshualitt in - https://github.com/google-gemini/gemini-cli/pull/14597 -- feat: attempt more error parsing by @adamfweidman in - https://github.com/google-gemini/gemini-cli/pull/14899 -- Add missing await. by @gundermanc in - https://github.com/google-gemini/gemini-cli/pull/14910 -- feat(core): Add support for transcript_path in hooks for git-ai/Gemini - extension by @svarlamov in - https://github.com/google-gemini/gemini-cli/pull/14663 -- refactor: implement DelegateToAgentTool with discriminated union by - @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/14769 -- feat: reset availabilityService on /auth by @adamfweidman in - https://github.com/google-gemini/gemini-cli/pull/14911 -- chore/release: bump version to 0.21.0-nightly.20251211.8c83e1ea9 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14924 -- Fix: Correctly detect MCP tool errors by @kevin-ramdass in - https://github.com/google-gemini/gemini-cli/pull/14937 -- increase labeler timeout by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14922 -- tool(cli): tweak the frontend tool to be aware of more core files from the cli - by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/14962 -- feat(cli): polish cached token stats and simplify stats display when quota is - present. by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/14961 -- feat(settings-validation): add validation for settings schema by @lifefloating - in https://github.com/google-gemini/gemini-cli/pull/12929 -- fix(ide): Update IDE extension to write auth token in env var by @skeshive in - https://github.com/google-gemini/gemini-cli/pull/14999 -- Revert "chore(deps): bump express from 5.1.0 to 5.2.0" by @skeshive in - https://github.com/google-gemini/gemini-cli/pull/14998 -- feat(a2a): Introduce /init command for a2a server by @cocosheng-g in - https://github.com/google-gemini/gemini-cli/pull/13419 -- feat: support multi-file drag and drop of images by @jackwotherspoon in - https://github.com/google-gemini/gemini-cli/pull/14832 -- fix(policy): allow codebase_investigator by default in read-only policy by - @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15000 -- refactor(ide ext): Update port file name + switch to 1-based index for - characters + remove truncation text by @skeshive in - https://github.com/google-gemini/gemini-cli/pull/10501 -- fix(vscode-ide-companion): correct license generation for workspace - dependencies by @skeshive in - https://github.com/google-gemini/gemini-cli/pull/15004 -- fix: temp fix for subagent invocation until subagent delegation is merged to - stable by @abhipatel12 in - https://github.com/google-gemini/gemini-cli/pull/15007 -- test: update ide detection tests to make them more robust when run in an ide - by @kevin-ramdass in https://github.com/google-gemini/gemini-cli/pull/15008 -- Remove flex from stats display. See snapshots for diffs. by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/14983 -- Add license field into package.json by @jb-perez in - https://github.com/google-gemini/gemini-cli/pull/14473 -- feat: Persistent "Always Allow" policies with granular shell & MCP support by - @allenhutchison in https://github.com/google-gemini/gemini-cli/pull/14737 -- chore/release: bump version to 0.21.0-nightly.20251212.54de67536 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14969 -- fix(core): commandPrefix word boundary and compound command safety by - @allenhutchison in https://github.com/google-gemini/gemini-cli/pull/15006 -- chore(docs): add 'Maintainers only' label info to CONTRIBUTING.md by @jacob314 - in https://github.com/google-gemini/gemini-cli/pull/14914 -- Refresh hooks when refreshing extensions. by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14918 -- Add clarity to error messages by @gsehgal in - https://github.com/google-gemini/gemini-cli/pull/14879 -- chore : remove a redundant tip by @JayadityaGit in - https://github.com/google-gemini/gemini-cli/pull/14947 -- chore/release: bump version to 0.21.0-nightly.20251213.977248e09 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15029 -- Disallow redundant typecasts. by @gundermanc in - https://github.com/google-gemini/gemini-cli/pull/15030 -- fix(auth): prioritize GEMINI_API_KEY env var and skip unnecessary key… by - @galz10 in https://github.com/google-gemini/gemini-cli/pull/14745 -- fix: use zod for safety check result validation by @allenhutchison in - https://github.com/google-gemini/gemini-cli/pull/15026 -- update(telemetry): add hashed_extension_name to field to extension events by - @kiranani in https://github.com/google-gemini/gemini-cli/pull/15025 -- fix: similar to policy-engine, throw error in case of requiring tool execution - confirmation for non-interactive mode by @MayV in - https://github.com/google-gemini/gemini-cli/pull/14702 -- Clean up processes in integration tests by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/15102 -- docs: update policy engine getting started and defaults by @NTaylorMullen in - https://github.com/google-gemini/gemini-cli/pull/15105 -- Fix tool output fragmentation by encapsulating content in functionResponse by - @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/13082 -- Simplify method signature. by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/15114 -- Show raw input token counts in json output. by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/15021 -- fix: Mark A2A requests as interactive by @MayV in - https://github.com/google-gemini/gemini-cli/pull/15108 -- use previewFeatures to determine which pro model to use for A2A by @sehoon38 - in https://github.com/google-gemini/gemini-cli/pull/15131 -- refactor(cli): fix settings merging so that settings using the new json format - take priority over ones using the old format by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/15116 +- Code assist service metrics. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15024 +- chore/release: bump version to 0.21.0-nightly.20251216.bb0c0d8ee by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15121 +- Docs by @Roaimkhan in https://github.com/google-gemini/gemini-cli/pull/15103 +- Use official ACP SDK and support HTTP/SSE based MCP servers by @SteffenDE in + https://github.com/google-gemini/gemini-cli/pull/13856 +- Remove foreground for themes other than shades of purple and holiday. by + @jacob314 in https://github.com/google-gemini/gemini-cli/pull/14606 +- chore: remove repo specific tips by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15164 +- chore: remove user query from footer in debug mode by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15169 +- Disallow unnecessary awaits. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15172 +- Add one to the padding in settings dialog to avoid flicker. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15173 +- feat(core): introduce remote agent infrastructure and rename local executor by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15110 +- feat(cli): Add `/auth logout` command to clear credentials and auth state by + @CN-Scars in https://github.com/google-gemini/gemini-cli/pull/13383 +- (fix) Automated pr labeler by @DaanVersavel in + https://github.com/google-gemini/gemini-cli/pull/14885 +- feat: launch Gemini 3 Flash in Gemini CLI ⚡️⚡️⚡️ by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15196 +- Refactor: Migrate console.error in ripGrep.ts to debugLogger by @Adib234 in + https://github.com/google-gemini/gemini-cli/pull/15201 +- chore: update a2a-js to 0.3.7 by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/15197 +- chore(core): remove redundant isModelAvailabilityServiceEnabled toggle and + clean up dead code by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/15207 +- feat(core): Late resolve `GenerateContentConfig`s and reduce mutation. by + @joshualitt in https://github.com/google-gemini/gemini-cli/pull/14920 +- Respect previewFeatures value from the remote flag if undefined by @sehoon38 + in https://github.com/google-gemini/gemini-cli/pull/15214 +- feat(ui): add Windows clipboard image support and Alt+V paste workaround by + @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15218 +- chore(core): remove legacy fallback flags and migrate loop detection by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15213 +- fix(ui): Prevent eager slash command completion hiding sibling commands by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15224 +- Docs: Update Changelog for Dec 17, 2025 by @jkcinouye in + https://github.com/google-gemini/gemini-cli/pull/15204 +- Code Assist backend telemetry for user accept/reject of suggestions by + @gundermanc in https://github.com/google-gemini/gemini-cli/pull/15206 +- fix(cli): correct initial history length handling for chat commands by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15223 +- chore/release: bump version to 0.21.0-nightly.20251218.739c02bd6 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15231 +- Change detailed model stats to use a new shared Table class to resolve + robustness issues. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15208 +- feat: add agent toml parser by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15112 +- Add core tool that adds all context from the core package. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15238 +- (docs): Add reference section to hooks documentation by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15159 +- feat(hooks): add support for friendly names and descriptions by @abhipatel12 + in https://github.com/google-gemini/gemini-cli/pull/15174 +- feat: Detect background color by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15132 +- add 3.0 to allowed sensitive keywords by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15276 +- feat: Pass additional environment variables to shell execution by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15160 +- Remove unused code by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15290 +- Handle all 429 as retryableQuotaError by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15288 +- Remove unnecessary dependencies by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15291 +- fix: prevent infinite loop in prompt completion on error by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/14548 +- fix(ui): show command suggestions even on perfect match and sort them by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15287 +- feat(hooks): reduce log verbosity and improve error reporting in UI by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15297 +- feat: simplify tool confirmation labels for better UX by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15296 +- chore/release: bump version to 0.21.0-nightly.20251219.70696e364 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15301 +- feat(core): Implement JIT context memory loading and UI sync by @SandyTao520 + in https://github.com/google-gemini/gemini-cli/pull/14469 +- feat(ui): Put "Allow for all future sessions" behind a setting off by default. + by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15322 +- fix(cli):change the placeholder of input during the shell mode by + @JayadityaGit in https://github.com/google-gemini/gemini-cli/pull/15135 +- Validate OAuth resource parameter matches MCP server URL by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15289 +- docs(cli): add System Prompt Override (GEMINI_SYSTEM_MD) by @ashmod in + https://github.com/google-gemini/gemini-cli/pull/9515 +- more robust command parsing logs by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15339 +- Introspection agent demo by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15232 +- fix(core): sanitize hook command expansion and prevent injection by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15343 +- fix(folder trust): add validation for trusted folder level by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/12215 +- fix(cli): fix right border overflow in trust dialogs by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15350 +- fix(policy): fix bug where accepting-edits continued after it was turned off + by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15351 +- fix: prevent infinite relaunch loop when --resume fails (#14941) by @Ying-xi + in https://github.com/google-gemini/gemini-cli/pull/14951 +- chore/release: bump version to 0.21.0-nightly.20251220.41a1a3eed by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15352 +- feat(telemetry): add clearcut logging for hooks by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15405 +- fix(core): Add `.geminiignore` support to SearchText tool by @xyrolle in + https://github.com/google-gemini/gemini-cli/pull/13763 **Full Changelog**: -https://github.com/google-gemini/gemini-cli/compare/v0.21.0-preview.6...v0.22.0-preview.0 +https://github.com/google-gemini/gemini-cli/compare/v0.22.0-preview.3...v0.23.0-preview.0 diff --git a/docs/changelogs/releases.md b/docs/changelogs/releases.md index 9793f75c7d..f89385377a 100644 --- a/docs/changelogs/releases.md +++ b/docs/changelogs/releases.md @@ -12,13 +12,279 @@ on GitHub. ## Current Releases -| Release channel | Notes | -| :------------------------------------------ | :---------------------------------------------- | -| Nightly | Nightly release with the most recent changes. | -| [Preview](#release-v0220-preview-0-preview) | Experimental features ready for early feedback. | -| [Latest](#release-v0210---v0211-latest) | Stable, recommended for general use. | +| Release channel | Notes | +| :---------------------------------------- | :---------------------------------------------- | +| Nightly | Nightly release with the most recent changes. | +| [Preview](#release-v0230-preview-preview) | Experimental features ready for early feedback. | +| [Latest](#release-v0220---v0225-latest) | Stable, recommended for general use. | -## Release v0.21.0 - v0.21.1 (Latest) +## Release v0.23.0-preview (Preview) + +## What's Changed + +- Code assist service metrics. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15024 +- chore/release: bump version to 0.21.0-nightly.20251216.bb0c0d8ee by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15121 +- Docs by @Roaimkhan in https://github.com/google-gemini/gemini-cli/pull/15103 +- Use official ACP SDK and support HTTP/SSE based MCP servers by @SteffenDE in + https://github.com/google-gemini/gemini-cli/pull/13856 +- Remove foreground for themes other than shades of purple and holiday. by + @jacob314 in https://github.com/google-gemini/gemini-cli/pull/14606 +- chore: remove repo specific tips by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15164 +- chore: remove user query from footer in debug mode by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15169 +- Disallow unnecessary awaits. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15172 +- Add one to the padding in settings dialog to avoid flicker. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15173 +- feat(core): introduce remote agent infrastructure and rename local executor by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15110 +- feat(cli): Add `/auth logout` command to clear credentials and auth state by + @CN-Scars in https://github.com/google-gemini/gemini-cli/pull/13383 +- (fix) Automated pr labeler by @DaanVersavel in + https://github.com/google-gemini/gemini-cli/pull/14885 +- feat: launch Gemini 3 Flash in Gemini CLI ⚡️⚡️⚡️ by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15196 +- Refactor: Migrate console.error in ripGrep.ts to debugLogger by @Adib234 in + https://github.com/google-gemini/gemini-cli/pull/15201 +- chore: update a2a-js to 0.3.7 by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/15197 +- chore(core): remove redundant isModelAvailabilityServiceEnabled toggle and + clean up dead code by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/15207 +- feat(core): Late resolve `GenerateContentConfig`s and reduce mutation. by + @joshualitt in https://github.com/google-gemini/gemini-cli/pull/14920 +- Respect previewFeatures value from the remote flag if undefined by @sehoon38 + in https://github.com/google-gemini/gemini-cli/pull/15214 +- feat(ui): add Windows clipboard image support and Alt+V paste workaround by + @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15218 +- chore(core): remove legacy fallback flags and migrate loop detection by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15213 +- fix(ui): Prevent eager slash command completion hiding sibling commands by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15224 +- Docs: Update Changelog for Dec 17, 2025 by @jkcinouye in + https://github.com/google-gemini/gemini-cli/pull/15204 +- Code Assist backend telemetry for user accept/reject of suggestions by + @gundermanc in https://github.com/google-gemini/gemini-cli/pull/15206 +- fix(cli): correct initial history length handling for chat commands by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15223 +- chore/release: bump version to 0.21.0-nightly.20251218.739c02bd6 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15231 +- Change detailed model stats to use a new shared Table class to resolve + robustness issues. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15208 +- feat: add agent toml parser by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15112 +- Add core tool that adds all context from the core package. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15238 +- (docs): Add reference section to hooks documentation by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15159 +- feat(hooks): add support for friendly names and descriptions by @abhipatel12 + in https://github.com/google-gemini/gemini-cli/pull/15174 +- feat: Detect background color by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15132 +- add 3.0 to allowed sensitive keywords by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15276 +- feat: Pass additional environment variables to shell execution by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15160 +- Remove unused code by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15290 +- Handle all 429 as retryableQuotaError by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15288 +- Remove unnecessary dependencies by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15291 +- fix: prevent infinite loop in prompt completion on error by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/14548 +- fix(ui): show command suggestions even on perfect match and sort them by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15287 +- feat(hooks): reduce log verbosity and improve error reporting in UI by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15297 +- feat: simplify tool confirmation labels for better UX by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15296 +- chore/release: bump version to 0.21.0-nightly.20251219.70696e364 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15301 +- feat(core): Implement JIT context memory loading and UI sync by @SandyTao520 + in https://github.com/google-gemini/gemini-cli/pull/14469 +- feat(ui): Put "Allow for all future sessions" behind a setting off by default. + by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15322 +- fix(cli):change the placeholder of input during the shell mode by + @JayadityaGit in https://github.com/google-gemini/gemini-cli/pull/15135 +- Validate OAuth resource parameter matches MCP server URL by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15289 +- docs(cli): add System Prompt Override (GEMINI_SYSTEM_MD) by @ashmod in + https://github.com/google-gemini/gemini-cli/pull/9515 +- more robust command parsing logs by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15339 +- Introspection agent demo by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15232 +- fix(core): sanitize hook command expansion and prevent injection by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15343 +- fix(folder trust): add validation for trusted folder level by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/12215 +- fix(cli): fix right border overflow in trust dialogs by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15350 +- fix(policy): fix bug where accepting-edits continued after it was turned off + by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15351 +- fix: prevent infinite relaunch loop when --resume fails (#14941) by @Ying-xi + in https://github.com/google-gemini/gemini-cli/pull/14951 +- chore/release: bump version to 0.21.0-nightly.20251220.41a1a3eed by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15352 +- feat(telemetry): add clearcut logging for hooks by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15405 +- fix(core): Add `.geminiignore` support to SearchText tool by @xyrolle in + https://github.com/google-gemini/gemini-cli/pull/13763 + +**Full Changelog**: +https://github.com/google-gemini/gemini-cli/compare/v0.22.0-preview.3...v0.23.0-preview.0 + +## Release v0.22.0 - v0.22.5 (Latest) + +### Highlights + +- **Comprehensive quota visibility:** View usage statistics for all available + models in the `/stats` command, even those not yet used in your current + session. ([pic](https://imgur.com/a/cKyDtYh), + [pr](https://github.com/google-gemini/gemini-cli/pull/14764) by + [@sehoon38](https://github.com/sehoon38)) +- **Polished CLI statistics:** We’ve cleaned up the `/stats` view to prioritize + actionable quota information while providing a detailed token and + cache-efficiency breakdown in `/stats model` + ([login with Google](https://imgur.com/a/w9xKthm), + [api key](https://imgur.com/a/FjQPHOY), + [model stats](https://imgur.com/a/VfWzVgw), + [pr](https://github.com/google-gemini/gemini-cli/pull/14961) by + [@jacob314](https://github.com/jacob314)) +- **Multi-file drag & drop:** Multi-file drag & drop is now supported and + properly translated to be prefixed with `@`. + ([pr](https://github.com/google-gemini/gemini-cli/pull/14832) by + [@jackwotherspoon](https://github.com/jackwotherspoon)) + +### What's Changed + +- feat(ide): fallback to GEMINI_CLI_IDE_AUTH_TOKEN env var by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/14843 +- feat: display quota stats for unused models in /stats by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/14764 +- feat: ensure codebase investigator uses preview model when main agent does by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/14412 +- chore: add closing reason to stale bug workflow by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/14861 +- Send the model and CLI version with the user agent by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/14865 +- refactor(sessions): move session summary generation to startup by + @jackwotherspoon in https://github.com/google-gemini/gemini-cli/pull/14691 +- Limit search depth in path corrector by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/14869 +- Fix: Correct typo in code comment by @kuishou68 in + https://github.com/google-gemini/gemini-cli/pull/14671 +- feat(core): Plumbing for late resolution of model configs. by @joshualitt in + https://github.com/google-gemini/gemini-cli/pull/14597 +- feat: attempt more error parsing by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/14899 +- Add missing await. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/14910 +- feat(core): Add support for transcript_path in hooks for git-ai/Gemini + extension by @svarlamov in + https://github.com/google-gemini/gemini-cli/pull/14663 +- refactor: implement DelegateToAgentTool with discriminated union by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/14769 +- feat: reset availabilityService on /auth by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/14911 +- chore/release: bump version to 0.21.0-nightly.20251211.8c83e1ea9 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14924 +- Fix: Correctly detect MCP tool errors by @kevin-ramdass in + https://github.com/google-gemini/gemini-cli/pull/14937 +- increase labeler timeout by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/14922 +- tool(cli): tweak the frontend tool to be aware of more core files from the cli + by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/14962 +- feat(cli): polish cached token stats and simplify stats display when quota is + present. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/14961 +- feat(settings-validation): add validation for settings schema by @lifefloating + in https://github.com/google-gemini/gemini-cli/pull/12929 +- fix(ide): Update IDE extension to write auth token in env var by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/14999 +- Revert "chore(deps): bump express from 5.1.0 to 5.2.0" by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/14998 +- feat(a2a): Introduce /init command for a2a server by @cocosheng-g in + https://github.com/google-gemini/gemini-cli/pull/13419 +- feat: support multi-file drag and drop of images by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/14832 +- fix(policy): allow codebase_investigator by default in read-only policy by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15000 +- refactor(ide ext): Update port file name + switch to 1-based index for + characters + remove truncation text by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/10501 +- fix(vscode-ide-companion): correct license generation for workspace + dependencies by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/15004 +- fix: temp fix for subagent invocation until subagent delegation is merged to + stable by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15007 +- test: update ide detection tests to make them more robust when run in an ide + by @kevin-ramdass in https://github.com/google-gemini/gemini-cli/pull/15008 +- Remove flex from stats display. See snapshots for diffs. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/14983 +- Add license field into package.json by @jb-perez in + https://github.com/google-gemini/gemini-cli/pull/14473 +- feat: Persistent "Always Allow" policies with granular shell & MCP support by + @allenhutchison in https://github.com/google-gemini/gemini-cli/pull/14737 +- chore/release: bump version to 0.21.0-nightly.20251212.54de67536 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14969 +- fix(core): commandPrefix word boundary and compound command safety by + @allenhutchison in https://github.com/google-gemini/gemini-cli/pull/15006 +- chore(docs): add 'Maintainers only' label info to CONTRIBUTING.md by @jacob314 + in https://github.com/google-gemini/gemini-cli/pull/14914 +- Refresh hooks when refreshing extensions. by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/14918 +- Add clarity to error messages by @gsehgal in + https://github.com/google-gemini/gemini-cli/pull/14879 +- chore : remove a redundant tip by @JayadityaGit in + https://github.com/google-gemini/gemini-cli/pull/14947 +- chore/release: bump version to 0.21.0-nightly.20251213.977248e09 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15029 +- Disallow redundant typecasts. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15030 +- fix(auth): prioritize GEMINI_API_KEY env var and skip unnecessary key… by + @galz10 in https://github.com/google-gemini/gemini-cli/pull/14745 +- fix: use zod for safety check result validation by @allenhutchison in + https://github.com/google-gemini/gemini-cli/pull/15026 +- update(telemetry): add hashed_extension_name to field to extension events by + @kiranani in https://github.com/google-gemini/gemini-cli/pull/15025 +- fix: similar to policy-engine, throw error in case of requiring tool execution + confirmation for non-interactive mode by @MayV in + https://github.com/google-gemini/gemini-cli/pull/14702 +- Clean up processes in integration tests by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15102 +- docs: update policy engine getting started and defaults by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15105 +- Fix tool output fragmentation by encapsulating content in functionResponse by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/13082 +- Simplify method signature. by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15114 +- Show raw input token counts in json output. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15021 +- fix: Mark A2A requests as interactive by @MayV in + https://github.com/google-gemini/gemini-cli/pull/15108 +- use previewFeatures to determine which pro model to use for A2A by @sehoon38 + in https://github.com/google-gemini/gemini-cli/pull/15131 +- refactor(cli): fix settings merging so that settings using the new json format + take priority over ones using the old format by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15116 +- fix(patch): cherry-pick a6d1245 to release/v0.22.0-preview.1-pr-15214 to patch + version v0.22.0-preview.1 and create version 0.22.0-preview.2 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15226 +- fix(patch): cherry-pick 9e6914d to release/v0.22.0-preview.2-pr-15288 to patch + version v0.22.0-preview.2 and create version 0.22.0-preview.3 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15294 + +**Full Changelog**: +https://github.com/google-gemini/gemini-cli/compare/v0.21.3...v0.22.0 + +## Release v0.21.0 - v0.21.1 ### Highlights @@ -206,7 +472,7 @@ on GitHub. https://github.com/google-gemini/gemini-cli/pull/13015 - allow final:true to be returned on a2a server edit calls. by @DavidAPierce in https://github.com/google-gemini/gemini-cli/pull/14747 -- (fix) Automated pr labeller by @DaanVersavel in +- (fix) Automated pr labeler by @DaanVersavel in https://github.com/google-gemini/gemini-cli/pull/14788 - Update CODEOWNERS by @kklashtorny1 in https://github.com/google-gemini/gemini-cli/pull/14830 diff --git a/docs/get-started/gemini-3.md b/docs/get-started/gemini-3.md index e0f6f8a1a7..333dbdb68d 100644 --- a/docs/get-started/gemini-3.md +++ b/docs/get-started/gemini-3.md @@ -1,25 +1,10 @@ # Gemini 3 Pro and Gemini 3 Flash on Gemini CLI -Gemini 3 Pro and Gemini 3 Flash are now available on Gemini CLI! Currently, most -paid customers of Gemini CLI will have access to both Gemini 3 Pro and Gemini 3 -Flash, including the following subscribers: - -- Google AI Pro and Google AI Ultra (excluding business customers). -- Gemini Code Assist Standard and Enterprise (requires - [administrative enablement](#administrator-instructions)). -- Paid Gemini API and Vertex API key holders. - -For free tier users: - -- If you signed up for the waitlist, please check your email for details. We’ve - onboarded everyone who signed up to the previously available waitlist. -- If you were not on our waitlist, we’re rolling out additional access gradually - to ensure the experience remains fast and reliable. Stay tuned for more - details. +Gemini 3 Pro and Gemini 3 Flash are available on Gemini CLI for all users! ## How to get started with Gemini 3 on Gemini CLI -Get started by upgrading Gemini CLI to the latest version (0.21.1): +Get started by upgrading Gemini CLI to the latest version: ```bash npm install -g @google/gemini-cli@latest From 1aa35c879605ef14027f8fa80a3b34ece495520d Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Wed, 7 Jan 2026 15:43:12 -0800 Subject: [PATCH 049/713] enable cli_help agent by default (#16100) --- docs/cli/settings.md | 1 + docs/get-started/configuration.md | 2 +- packages/cli/src/config/settingsSchema.ts | 2 +- packages/core/src/agents/registry.test.ts | 7 +++---- packages/core/src/config/config.test.ts | 1 + packages/core/src/config/config.ts | 5 +++-- schemas/settings.schema.json | 4 ++-- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/cli/settings.md b/docs/cli/settings.md index f281ec8da0..3aaeffdf9e 100644 --- a/docs/cli/settings.md +++ b/docs/cli/settings.md @@ -111,4 +111,5 @@ they appear in the UI. | ----------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------ | ------- | | Enable Codebase Investigator | `experimental.codebaseInvestigatorSettings.enabled` | Enable the Codebase Investigator agent. | `true` | | Codebase Investigator Max Num Turns | `experimental.codebaseInvestigatorSettings.maxNumTurns` | Maximum number of turns for the Codebase Investigator agent. | `10` | +| Enable CLI Help Agent | `experimental.cliHelpAgentSettings.enabled` | Enable the CLI Help Agent. | `true` | | Agent Skills | `experimental.skills` | Enable Agent Skills (experimental). | `false` | diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index c01240dcb9..1777d22f5f 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -853,7 +853,7 @@ their corresponding top-level category object in your `settings.json` file. - **`experimental.cliHelpAgentSettings.enabled`** (boolean): - **Description:** Enable the CLI Help Agent. - - **Default:** `false` + - **Default:** `true` - **Requires restart:** Yes #### `skills` diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index 38d075b207..4dea5d0a99 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -1467,7 +1467,7 @@ const SETTINGS_SCHEMA = { label: 'Enable CLI Help Agent', category: 'Experimental', requiresRestart: true, - default: false, + default: true, description: 'Enable the CLI Help Agent.', showInDialog: true, }, diff --git a/packages/core/src/agents/registry.test.ts b/packages/core/src/agents/registry.test.ts index 5517909045..4864566bc0 100644 --- a/packages/core/src/agents/registry.test.ts +++ b/packages/core/src/agents/registry.test.ts @@ -209,6 +209,7 @@ describe('AgentRegistry', () => { const disabledConfig = makeFakeConfig({ enableAgents: false, codebaseInvestigatorSettings: { enabled: false }, + cliHelpAgentSettings: { enabled: false }, }); const disabledRegistry = new TestableAgentRegistry(disabledConfig); @@ -220,10 +221,8 @@ describe('AgentRegistry', () => { ).not.toHaveBeenCalled(); }); - it('should register CLI help agent if enabled', async () => { - const config = makeFakeConfig({ - cliHelpAgentSettings: { enabled: true }, - }); + it('should register CLI help agent by default', async () => { + const config = makeFakeConfig(); const registry = new TestableAgentRegistry(config); await registry.initialize(); diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index e16ef982fc..265785a891 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -941,6 +941,7 @@ describe('Server Config (config.ts)', () => { const params: ConfigParameters = { ...baseParams, codebaseInvestigatorSettings: { enabled: false }, + cliHelpAgentSettings: { enabled: false }, }; const config = new Config(params); diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 2021576643..8e7a8e42cb 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -622,7 +622,7 @@ export class Config { model: params.codebaseInvestigatorSettings?.model, }; this.cliHelpAgentSettings = { - enabled: params.cliHelpAgentSettings?.enabled ?? false, + enabled: params.cliHelpAgentSettings?.enabled ?? true, }; this.continueOnFailedApiCall = params.continueOnFailedApiCall ?? true; this.enableShellOutputEfficiency = @@ -1754,7 +1754,8 @@ export class Config { // Register DelegateToAgentTool if agents are enabled if ( this.isAgentsEnabled() || - this.getCodebaseInvestigatorSettings().enabled + this.getCodebaseInvestigatorSettings().enabled || + this.getCliHelpAgentSettings().enabled ) { // Check if the delegate tool itself is allowed (if allowedTools is set) const allowedTools = this.getAllowedTools(); diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index e7473ea395..83429aecca 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -1435,8 +1435,8 @@ "enabled": { "title": "Enable CLI Help Agent", "description": "Enable the CLI Help Agent.", - "markdownDescription": "Enable the CLI Help Agent.\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `false`", - "default": false, + "markdownDescription": "Enable the CLI Help Agent.\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `true`", + "default": true, "type": "boolean" } }, From 1bd4f9d8b6fe819248abbe2c222effd763ba45cc Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 7 Jan 2026 16:10:50 -0800 Subject: [PATCH 050/713] Optimize json-output tests with mock responses (#16102) --- .../json-output.france.responses | 1 + .../json-output.session-id.responses | 1 + integration-tests/json-output.test.ts | 19 ++++++++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 integration-tests/json-output.france.responses create mode 100644 integration-tests/json-output.session-id.responses diff --git a/integration-tests/json-output.france.responses b/integration-tests/json-output.france.responses new file mode 100644 index 0000000000..5c9edce888 --- /dev/null +++ b/integration-tests/json-output.france.responses @@ -0,0 +1 @@ +{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"The capital of France is Paris."}],"role":"model"},"finishReason":"STOP","index":0}],"usageMetadata":{"promptTokenCount":7,"candidatesTokenCount":7,"totalTokenCount":14,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7}]}}]} diff --git a/integration-tests/json-output.session-id.responses b/integration-tests/json-output.session-id.responses new file mode 100644 index 0000000000..c96cbccea4 --- /dev/null +++ b/integration-tests/json-output.session-id.responses @@ -0,0 +1 @@ +{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"Hello! How can I help you today?"}],"role":"model"},"finishReason":"STOP","index":0}],"usageMetadata":{"promptTokenCount":5,"candidatesTokenCount":9,"totalTokenCount":14,"promptTokensDetails":[{"modality":"TEXT","tokenCount":5}]}}]} \ No newline at end of file diff --git a/integration-tests/json-output.test.ts b/integration-tests/json-output.test.ts index 0221034d3e..215cf21226 100644 --- a/integration-tests/json-output.test.ts +++ b/integration-tests/json-output.test.ts @@ -9,8 +9,7 @@ import { TestRig } from './test-helper.js'; import { join } from 'node:path'; import { ExitCodes } from '@google/gemini-cli-core/src/index.js'; -// TODO: Enable these tests once we figure out why they are flaky in CI. -describe.skip('JSON output', () => { +describe('JSON output', () => { let rig: TestRig; beforeEach(async () => { @@ -22,7 +21,12 @@ describe.skip('JSON output', () => { }); it('should return a valid JSON with response and stats', async () => { - await rig.setup('json-output-response-stats'); + await rig.setup('json-output-france', { + fakeResponsesPath: join( + import.meta.dirname, + 'json-output.france.responses', + ), + }); const result = await rig.run({ args: ['What is the capital of France?', '--output-format', 'json'], }); @@ -37,7 +41,12 @@ describe.skip('JSON output', () => { }); it('should return a valid JSON with a session ID', async () => { - await rig.setup('json-output-session-id'); + await rig.setup('json-output-session-id', { + fakeResponsesPath: join( + import.meta.dirname, + 'json-output.session-id.responses', + ), + }); const result = await rig.run({ args: ['Hello', '--output-format', 'json'], }); @@ -104,7 +113,7 @@ describe.skip('JSON output', () => { }); it('should not exit on tool errors and allow model to self-correct in JSON mode', async () => { - rig.setup('json-output-error', { + await rig.setup('json-output-error', { fakeResponsesPath: join( import.meta.dirname, 'json-output.error.responses', From dd04b46e86d04d72682164b4a766baf9ddef12dc Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Wed, 7 Jan 2026 16:18:33 -0800 Subject: [PATCH 051/713] Fix CI for forks (#16113) --- .github/workflows/ci.yml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3fb1867db7..6b95abdddc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,7 +125,7 @@ jobs: args: '--verbose --accept 200,503 ./**/*.md' fail: true test_linux: - name: 'Test (Linux) - ${{ matrix.shard }}' + name: 'Test (Linux) - ${{ matrix.node-version }}, ${{ matrix.shard }}' runs-on: 'gemini-cli-ubuntu-16-core' needs: - 'merge_queue_skipper' @@ -185,7 +185,7 @@ jobs: ${{ always() && (github.event.pull_request.head.repo.full_name == github.repository) }} uses: 'dorny/test-reporter@dc3a92680fcc15842eef52e8c4606ea7ce6bd3f3' # ratchet:dorny/test-reporter@v2 with: - name: 'Test Results (Node ${{ matrix.node-version }}, ${{ matrix.shard }})' + name: 'Test Results (Node ${{ runner.os }}, ${{ matrix.node-version }}, ${{ matrix.shard }})' path: 'packages/*/junit.xml' reporter: 'java-junit' fail-on-error: 'false' @@ -195,12 +195,12 @@ jobs: ${{ always() && (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) }} uses: 'actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02' # ratchet:actions/upload-artifact@v4 with: - name: 'test-results-fork-${{ matrix.node-version }}-${{ runner.os }}' + name: 'test-results-fork-${{ runner.os }}-${{ matrix.node-version }}-${{ matrix.shard }}' path: 'packages/*/junit.xml' test_mac: - name: 'Test (Mac) - ${{ matrix.shard }}' - runs-on: '${{ matrix.os }}' + name: 'Test (Mac) - ${{ matrix.node-version }}, ${{ matrix.shard }}' + runs-on: 'macos-latest' needs: - 'merge_queue_skipper' if: "${{needs.merge_queue_skipper.outputs.skip == 'false'}}" @@ -211,8 +211,6 @@ jobs: continue-on-error: true strategy: matrix: - os: - - 'macos-latest' node-version: - '20.x' - '22.x' @@ -262,7 +260,7 @@ jobs: ${{ always() && (github.event.pull_request.head.repo.full_name == github.repository) }} uses: 'dorny/test-reporter@dc3a92680fcc15842eef52e8c4606ea7ce6bd3f3' # ratchet:dorny/test-reporter@v2 with: - name: 'Test Results (Node ${{ matrix.node-version }}, ${{ matrix.shard }})' + name: 'Test Results (Node ${{ runner.os }}, ${{ matrix.node-version }}, ${{ matrix.shard }})' path: 'packages/*/junit.xml' reporter: 'java-junit' fail-on-error: 'false' @@ -272,7 +270,7 @@ jobs: ${{ always() && (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) }} uses: 'actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02' # ratchet:actions/upload-artifact@v4 with: - name: 'test-results-fork-${{ matrix.node-version }}-${{ runner.os }}' + name: 'test-results-fork-${{ runner.os }}-${{ matrix.node-version }}-${{ matrix.shard }}' path: 'packages/*/junit.xml' - name: 'Upload coverage reports' @@ -280,7 +278,7 @@ jobs: ${{ always() }} uses: 'actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02' # ratchet:actions/upload-artifact@v4 with: - name: 'coverage-reports-${{ matrix.node-version }}-${{ matrix.os }}' + name: 'coverage-reports-${{ runner.os }}-${{ matrix.node-version }}-${{ matrix.shard }}' path: 'packages/*/coverage' codeql: From 41cc6cf105df25dd3d10f495c6aa319537390b35 Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Wed, 7 Jan 2026 16:53:03 -0800 Subject: [PATCH 052/713] Reduce nags about PRs that reference issues but don't fix them. (#16112) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .github/scripts/pr-triage.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/scripts/pr-triage.sh b/.github/scripts/pr-triage.sh index 9e1c140679..e5f49d0c2a 100755 --- a/.github/scripts/pr-triage.sh +++ b/.github/scripts/pr-triage.sh @@ -19,9 +19,9 @@ process_pr() { local PR_NUMBER=$1 echo "🔄 Processing PR #${PR_NUMBER}" - # Get PR details: closing issue and draft status + # Get PR details: closing issue, draft status, body and labels local PR_DATA - if ! PR_DATA=$(gh pr view "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json closingIssuesReferences,isDraft 2>/dev/null); then + if ! PR_DATA=$(gh pr view "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json closingIssuesReferences,isDraft,body,labels 2>/dev/null); then echo " ⚠️ Could not fetch data for PR #${PR_NUMBER}" return 0 fi @@ -29,6 +29,17 @@ process_pr() { local ISSUE_NUMBER ISSUE_NUMBER=$(echo "${PR_DATA}" | jq -r '.closingIssuesReferences[0].number // empty') + # If no closing issue found, check body for references (e.g. #123) + if [[ -z "${ISSUE_NUMBER}" ]]; then + local REFERENCED_ISSUE + # Search for # followed by digits, not preceded by alphanumeric chars + REFERENCED_ISSUE=$(echo "${PR_DATA}" | jq -r '.body // empty' | grep -oE '(^|[^a-zA-Z0-9])#[0-9]+([^a-zA-Z0-9]|$)' | head -n 1 | grep -oE '[0-9]+' || echo "") + if [[ -n "${REFERENCED_ISSUE}" ]]; then + ISSUE_NUMBER="${REFERENCED_ISSUE}" + echo "🔗 Found referenced issue #${ISSUE_NUMBER} in PR body" + fi + fi + local IS_DRAFT IS_DRAFT=$(echo "${PR_DATA}" | jq -r '.isDraft') @@ -74,13 +85,10 @@ process_pr() { ISSUE_LABELS=$(echo "${gh_output}" | grep -E "^(area|priority)/" | tr '\n' ',' | sed 's/,$//' || echo "") fi - # Get PR labels - echo "📥 Fetching labels from PR #${PR_NUMBER}" + # Get PR labels from already fetched PR_DATA + echo "📥 Extracting labels from PR #${PR_NUMBER}" local PR_LABELS="" - if ! PR_LABELS=$(gh pr view "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json labels -q '.labels[].name' 2>/dev/null | tr '\n' ',' | sed 's/,$//' || echo ""); then - echo " ⚠️ Could not fetch PR labels" - PR_LABELS="" - fi + PR_LABELS=$(echo "${PR_DATA}" | jq -r '.labels[].name // empty' | tr '\n' ',' | sed 's/,$//' || echo "") echo " Issue labels (area/priority): ${ISSUE_LABELS}" echo " PR labels: ${PR_LABELS}" From d48c934357cd6f89f534385a712728387aae0fdc Mon Sep 17 00:00:00 2001 From: Jasmeet Bhatia Date: Wed, 7 Jan 2026 17:47:05 -0800 Subject: [PATCH 053/713] feat(cli): add filepath autosuggestion after slash commands (#14738) Co-authored-by: Tommaso Sciortino --- .../ui/hooks/useCommandCompletion.test.tsx | 113 ++++++++++++++++++ .../cli/src/ui/hooks/useCommandCompletion.tsx | 23 ++-- 2 files changed, 127 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/ui/hooks/useCommandCompletion.test.tsx b/packages/cli/src/ui/hooks/useCommandCompletion.test.tsx index 09088d50df..1679782707 100644 --- a/packages/cli/src/ui/hooks/useCommandCompletion.test.tsx +++ b/packages/cli/src/ui/hooks/useCommandCompletion.test.tsx @@ -585,4 +585,117 @@ describe('useCommandCompletion', () => { ); }); }); + + describe('@ completion after slash commands (issue #14420)', () => { + it('should show file suggestions when typing @path after a slash command', async () => { + setupMocks({ + atSuggestions: [{ label: 'src/file.txt', value: 'src/file.txt' }], + }); + + const text = '/mycommand @src/fi'; + const cursorOffset = text.length; + + renderCommandCompletionHook(text, cursorOffset); + + await waitFor(() => { + expect(useAtCompletion).toHaveBeenLastCalledWith( + expect.objectContaining({ + enabled: true, + pattern: 'src/fi', + }), + ); + }); + }); + + it('should show slash suggestions when cursor is on command part (no @)', async () => { + setupMocks({ + slashSuggestions: [{ label: 'mycommand', value: 'mycommand' }], + }); + + const text = '/mycom'; + const cursorOffset = text.length; + + const { result } = renderCommandCompletionHook(text, cursorOffset); + + await waitFor(() => { + expect(result.current.suggestions).toHaveLength(1); + expect(result.current.suggestions[0]?.label).toBe('mycommand'); + }); + }); + + it('should switch to @ completion when typing @ after slash command', async () => { + setupMocks({ + atSuggestions: [{ label: 'file.txt', value: 'file.txt' }], + }); + + const text = '/command @'; + const cursorOffset = text.length; + + renderCommandCompletionHook(text, cursorOffset); + + await waitFor(() => { + expect(useAtCompletion).toHaveBeenLastCalledWith( + expect.objectContaining({ + enabled: true, + pattern: '', + }), + ); + }); + }); + + it('should handle multiple @ references in a slash command', async () => { + setupMocks({ + atSuggestions: [{ label: 'src/bar.ts', value: 'src/bar.ts' }], + }); + + const text = '/diff @src/foo.ts @src/ba'; + const cursorOffset = text.length; + + renderCommandCompletionHook(text, cursorOffset); + + await waitFor(() => { + expect(useAtCompletion).toHaveBeenLastCalledWith( + expect.objectContaining({ + enabled: true, + pattern: 'src/ba', + }), + ); + }); + }); + + it('should complete file path and add trailing space', async () => { + setupMocks({ + atSuggestions: [{ label: 'src/file.txt', value: 'src/file.txt' }], + }); + + const { result } = renderCommandCompletionHook('/cmd @src/fi'); + + await waitFor(() => { + expect(result.current.suggestions.length).toBe(1); + }); + + act(() => { + result.current.handleAutocomplete(0); + }); + + expect(result.current.textBuffer.text).toBe('/cmd @src/file.txt '); + }); + + it('should stay in slash mode when slash command has trailing space but no @', async () => { + setupMocks({ + slashSuggestions: [{ label: 'help', value: 'help' }], + }); + + const text = '/help '; + renderCommandCompletionHook(text); + + await waitFor(() => { + expect(useSlashCompletion).toHaveBeenLastCalledWith( + expect.objectContaining({ + enabled: true, + }), + ); + }); + }); + }); }); diff --git a/packages/cli/src/ui/hooks/useCommandCompletion.tsx b/packages/cli/src/ui/hooks/useCommandCompletion.tsx index beabca860b..b6c4991648 100644 --- a/packages/cli/src/ui/hooks/useCommandCompletion.tsx +++ b/packages/cli/src/ui/hooks/useCommandCompletion.tsx @@ -92,16 +92,11 @@ export function useCommandCompletion( const { completionMode, query, completionStart, completionEnd } = useMemo(() => { const currentLine = buffer.lines[cursorRow] || ''; - if (cursorRow === 0 && isSlashCommand(currentLine.trim())) { - return { - completionMode: CompletionMode.SLASH, - query: currentLine, - completionStart: 0, - completionEnd: currentLine.length, - }; - } - const codePoints = toCodePoints(currentLine); + + // FIRST: Check for @ completion (scan backwards from cursor) + // This must happen before slash command check so that `/cmd @file` + // triggers file completion, not just slash command completion. for (let i = cursorCol - 1; i >= 0; i--) { const char = codePoints[i]; @@ -139,6 +134,16 @@ export function useCommandCompletion( } } + // THEN: Check for slash command (only if no @ completion is active) + if (cursorRow === 0 && isSlashCommand(currentLine.trim())) { + return { + completionMode: CompletionMode.SLASH, + query: currentLine, + completionStart: 0, + completionEnd: currentLine.length, + }; + } + // Check for prompt completion - only if enabled const trimmedText = buffer.text.trim(); const isPromptCompletionEnabled = From aca6bf6aa0397b6ffcf53426af900447395fa18a Mon Sep 17 00:00:00 2001 From: cayden-google Date: Thu, 8 Jan 2026 13:01:40 +1100 Subject: [PATCH 054/713] Add upgrade option for paid users (#15978) --- .../cli/src/ui/components/DialogManager.tsx | 1 - .../src/ui/components/ProQuotaDialog.test.tsx | 26 ++++++++++++------- .../cli/src/ui/components/ProQuotaDialog.tsx | 25 ++---------------- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/packages/cli/src/ui/components/DialogManager.tsx b/packages/cli/src/ui/components/DialogManager.tsx index 325009db67..132b1a020e 100644 --- a/packages/cli/src/ui/components/DialogManager.tsx +++ b/packages/cli/src/ui/components/DialogManager.tsx @@ -62,7 +62,6 @@ export const DialogManager = ({ isTerminalQuotaError={uiState.proQuotaRequest.isTerminalQuotaError} isModelNotFoundError={!!uiState.proQuotaRequest.isModelNotFoundError} onChoice={uiActions.handleProQuotaChoice} - userTier={uiState.userTier} /> ); } diff --git a/packages/cli/src/ui/components/ProQuotaDialog.test.tsx b/packages/cli/src/ui/components/ProQuotaDialog.test.tsx index 2520036246..f74f5fa447 100644 --- a/packages/cli/src/ui/components/ProQuotaDialog.test.tsx +++ b/packages/cli/src/ui/components/ProQuotaDialog.test.tsx @@ -12,7 +12,6 @@ import { RadioButtonSelect } from './shared/RadioButtonSelect.js'; import { PREVIEW_GEMINI_MODEL, - UserTierId, DEFAULT_GEMINI_FLASH_MODEL, } from '@google/gemini-cli-core'; @@ -37,7 +36,6 @@ describe('ProQuotaDialog', () => { message="flash error" isTerminalQuotaError={true} // should not matter onChoice={mockOnChoice} - userTier={UserTierId.FREE} />, ); @@ -64,7 +62,7 @@ describe('ProQuotaDialog', () => { describe('for non-flash model failures', () => { describe('when it is a terminal quota error', () => { - it('should render switch and stop options for paid tiers', () => { + it('should render switch, upgrade, and stop options for paid tiers', () => { const { unmount } = render( { isTerminalQuotaError={true} isModelNotFoundError={false} onChoice={mockOnChoice} - userTier={UserTierId.LEGACY} />, ); @@ -85,6 +82,11 @@ describe('ProQuotaDialog', () => { value: 'retry_always', key: 'retry_always', }, + { + label: 'Upgrade for higher limits', + value: 'upgrade', + key: 'upgrade', + }, { label: 'Stop', value: 'retry_later', @@ -105,7 +107,6 @@ describe('ProQuotaDialog', () => { message="flash error" isTerminalQuotaError={true} onChoice={mockOnChoice} - userTier={UserTierId.FREE} />, ); @@ -138,7 +139,6 @@ describe('ProQuotaDialog', () => { isTerminalQuotaError={true} isModelNotFoundError={false} onChoice={mockOnChoice} - userTier={UserTierId.FREE} />, ); @@ -178,7 +178,6 @@ describe('ProQuotaDialog', () => { isTerminalQuotaError={false} isModelNotFoundError={false} onChoice={mockOnChoice} - userTier={UserTierId.FREE} />, ); @@ -214,7 +213,6 @@ describe('ProQuotaDialog', () => { isTerminalQuotaError={false} isModelNotFoundError={true} onChoice={mockOnChoice} - userTier={UserTierId.FREE} />, ); @@ -226,6 +224,11 @@ describe('ProQuotaDialog', () => { value: 'retry_always', key: 'retry_always', }, + { + label: 'Upgrade for higher limits', + value: 'upgrade', + key: 'upgrade', + }, { label: 'Stop', value: 'retry_later', @@ -247,7 +250,6 @@ describe('ProQuotaDialog', () => { isTerminalQuotaError={false} isModelNotFoundError={true} onChoice={mockOnChoice} - userTier={UserTierId.LEGACY} />, ); @@ -259,6 +261,11 @@ describe('ProQuotaDialog', () => { value: 'retry_always', key: 'retry_always', }, + { + label: 'Upgrade for higher limits', + value: 'upgrade', + key: 'upgrade', + }, { label: 'Stop', value: 'retry_later', @@ -282,7 +289,6 @@ describe('ProQuotaDialog', () => { message="" isTerminalQuotaError={false} onChoice={mockOnChoice} - userTier={UserTierId.FREE} />, ); diff --git a/packages/cli/src/ui/components/ProQuotaDialog.tsx b/packages/cli/src/ui/components/ProQuotaDialog.tsx index 0dbf134c5b..ccc20b3e75 100644 --- a/packages/cli/src/ui/components/ProQuotaDialog.tsx +++ b/packages/cli/src/ui/components/ProQuotaDialog.tsx @@ -9,8 +9,6 @@ import { Box, Text } from 'ink'; import { RadioButtonSelect } from './shared/RadioButtonSelect.js'; import { theme } from '../semantic-colors.js'; -import { UserTierId } from '@google/gemini-cli-core'; - interface ProQuotaDialogProps { failedModel: string; fallbackModel: string; @@ -20,7 +18,6 @@ interface ProQuotaDialogProps { onChoice: ( choice: 'retry_later' | 'retry_once' | 'retry_always' | 'upgrade', ) => void; - userTier: UserTierId | undefined; } export function ProQuotaDialog({ @@ -30,11 +27,7 @@ export function ProQuotaDialog({ isTerminalQuotaError, isModelNotFoundError, onChoice, - userTier, }: ProQuotaDialogProps): React.JSX.Element { - // Use actual user tier if available; otherwise, default to FREE tier behavior (safe default) - const isPaidTier = - userTier === UserTierId.LEGACY || userTier === UserTierId.STANDARD; let items; // Do not provide a fallback option if failed model and fallbackmodel are same. if (failedModel === fallbackModel) { @@ -50,22 +43,8 @@ export function ProQuotaDialog({ key: 'retry_later', }, ]; - } else if (isModelNotFoundError || (isTerminalQuotaError && isPaidTier)) { - // out of quota - items = [ - { - label: `Switch to ${fallbackModel}`, - value: 'retry_always' as const, - key: 'retry_always', - }, - { - label: `Stop`, - value: 'retry_later' as const, - key: 'retry_later', - }, - ]; - } else if (isTerminalQuotaError && !isPaidTier) { - // free user gets an option to upgrade + } else if (isModelNotFoundError || isTerminalQuotaError) { + // free users and out of quota users on G1 pro and Cloud Console gets an option to upgrade items = [ { label: `Switch to ${fallbackModel}`, From 3e2f4eb8ba12bded08183f3e71163cb0f7b00b31 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 7 Jan 2026 22:30:33 -0800 Subject: [PATCH 055/713] [Skills] UX Polishing: Transparent feedback and CLI refinements (#15954) --- .../cli/src/commands/skills/disable.test.ts | 3 ++- packages/cli/src/commands/skills/disable.ts | 22 +++++++++++-------- .../cli/src/commands/skills/enable.test.ts | 4 ++-- packages/cli/src/commands/skills/enable.ts | 10 ++++++++- .../cli/src/ui/commands/skillsCommand.test.ts | 6 ++--- packages/cli/src/ui/commands/skillsCommand.ts | 4 ++-- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/packages/cli/src/commands/skills/disable.test.ts b/packages/cli/src/commands/skills/disable.test.ts index 325a93499d..4fa8403702 100644 --- a/packages/cli/src/commands/skills/disable.test.ts +++ b/packages/cli/src/commands/skills/disable.test.ts @@ -60,6 +60,7 @@ describe('skills disable command', () => { const mockSettings = { forScope: vi.fn().mockReturnValue({ settings: { skills: { disabled: [] } }, + path: '/user/settings.json', }), setValue: vi.fn(), }; @@ -79,7 +80,7 @@ describe('skills disable command', () => { ); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" disabled by adding it to the disabled list in user settings.', + 'Skill "skill1" disabled by adding it to the disabled list in user (/user/settings.json) settings. Restart required to take effect.', ); }); diff --git a/packages/cli/src/commands/skills/disable.ts b/packages/cli/src/commands/skills/disable.ts index ef100c74f2..f1831654f5 100644 --- a/packages/cli/src/commands/skills/disable.ts +++ b/packages/cli/src/commands/skills/disable.ts @@ -5,19 +5,16 @@ */ import type { CommandModule } from 'yargs'; -import { - loadSettings, - SettingScope, - type LoadableSettingScope, -} from '../../config/settings.js'; +import { loadSettings, SettingScope } from '../../config/settings.js'; import { debugLogger } from '@google/gemini-cli-core'; import { exitCli } from '../utils.js'; import { disableSkill } from '../../utils/skillSettings.js'; import { renderSkillActionFeedback } from '../../utils/skillUtils.js'; +import chalk from 'chalk'; interface DisableArgs { name: string; - scope: LoadableSettingScope; + scope: SettingScope; } export async function handleDisable(args: DisableArgs) { @@ -26,7 +23,14 @@ export async function handleDisable(args: DisableArgs) { const settings = loadSettings(workspaceDir); const result = disableSkill(settings, name, scope); - debugLogger.log(renderSkillActionFeedback(result, (label, _path) => label)); + let feedback = renderSkillActionFeedback( + result, + (label, path) => `${chalk.bold(label)} (${chalk.dim(path)})`, + ); + if (result.status === 'success') { + feedback += ' Restart required to take effect.'; + } + debugLogger.log(feedback); } export const disableCommand: CommandModule = { @@ -43,11 +47,11 @@ export const disableCommand: CommandModule = { alias: 's', describe: 'The scope to disable the skill in (user or project).', type: 'string', - default: 'user', + default: 'project', choices: ['user', 'project'], }), handler: async (argv) => { - const scope: LoadableSettingScope = + const scope = argv['scope'] === 'project' ? SettingScope.Workspace : SettingScope.User; await handleDisable({ name: argv['name'] as string, diff --git a/packages/cli/src/commands/skills/enable.test.ts b/packages/cli/src/commands/skills/enable.test.ts index 35c7d5b0f5..b3a96d5967 100644 --- a/packages/cli/src/commands/skills/enable.test.ts +++ b/packages/cli/src/commands/skills/enable.test.ts @@ -81,7 +81,7 @@ describe('skills enable command', () => { ); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" enabled by removing it from the disabled list in user and project settings.', + 'Skill "skill1" enabled by removing it from the disabled list in user (/user/settings.json) and project (/project/settings.json) settings. Restart required to take effect.', ); }); @@ -122,7 +122,7 @@ describe('skills enable command', () => { ); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" enabled by removing it from the disabled list in project and user settings.', + 'Skill "skill1" enabled by removing it from the disabled list in project (/workspace/settings.json) and user (/user/settings.json) settings. Restart required to take effect.', ); }); diff --git a/packages/cli/src/commands/skills/enable.ts b/packages/cli/src/commands/skills/enable.ts index 8bfcaa7c2b..1e1cc12e49 100644 --- a/packages/cli/src/commands/skills/enable.ts +++ b/packages/cli/src/commands/skills/enable.ts @@ -10,6 +10,7 @@ import { debugLogger } from '@google/gemini-cli-core'; import { exitCli } from '../utils.js'; import { enableSkill } from '../../utils/skillSettings.js'; import { renderSkillActionFeedback } from '../../utils/skillUtils.js'; +import chalk from 'chalk'; interface EnableArgs { name: string; @@ -21,7 +22,14 @@ export async function handleEnable(args: EnableArgs) { const settings = loadSettings(workspaceDir); const result = enableSkill(settings, name); - debugLogger.log(renderSkillActionFeedback(result, (label, _path) => label)); + let feedback = renderSkillActionFeedback( + result, + (label, path) => `${chalk.bold(label)} (${chalk.dim(path)})`, + ); + if (result.status === 'success') { + feedback += ' Restart required to take effect.'; + } + debugLogger.log(feedback); } export const enableCommand: CommandModule = { diff --git a/packages/cli/src/ui/commands/skillsCommand.test.ts b/packages/cli/src/ui/commands/skillsCommand.test.ts index 511effd0b6..e90c695e0c 100644 --- a/packages/cli/src/ui/commands/skillsCommand.test.ts +++ b/packages/cli/src/ui/commands/skillsCommand.test.ts @@ -182,7 +182,7 @@ describe('skillsCommand', () => { expect(context.ui.addItem).toHaveBeenCalledWith( expect.objectContaining({ type: MessageType.INFO, - text: 'Skill "skill1" disabled by adding it to the disabled list in project settings. Use "/skills reload" for it to take effect.', + text: 'Skill "skill1" disabled by adding it to the disabled list in project (/workspace) settings. Use "/skills reload" for it to take effect.', }), expect.any(Number), ); @@ -211,7 +211,7 @@ describe('skillsCommand', () => { expect(context.ui.addItem).toHaveBeenCalledWith( expect.objectContaining({ type: MessageType.INFO, - text: 'Skill "skill1" enabled by removing it from the disabled list in project and user settings. Use "/skills reload" for it to take effect.', + text: 'Skill "skill1" enabled by removing it from the disabled list in project (/workspace) and user (/user/settings.json) settings. Use "/skills reload" for it to take effect.', }), expect.any(Number), ); @@ -251,7 +251,7 @@ describe('skillsCommand', () => { expect(context.ui.addItem).toHaveBeenCalledWith( expect.objectContaining({ type: MessageType.INFO, - text: 'Skill "skill1" enabled by removing it from the disabled list in project and user settings. Use "/skills reload" for it to take effect.', + text: 'Skill "skill1" enabled by removing it from the disabled list in project (/workspace) and user (/user/settings.json) settings. Use "/skills reload" for it to take effect.', }), expect.any(Number), ); diff --git a/packages/cli/src/ui/commands/skillsCommand.ts b/packages/cli/src/ui/commands/skillsCommand.ts index 35a41f461b..d769b9941d 100644 --- a/packages/cli/src/ui/commands/skillsCommand.ts +++ b/packages/cli/src/ui/commands/skillsCommand.ts @@ -96,7 +96,7 @@ async function disableAction( let feedback = renderSkillActionFeedback( result, - (label, _path) => `${label}`, + (label, path) => `${label} (${path})`, ); if (result.status === 'success') { feedback += ' Use "/skills reload" for it to take effect.'; @@ -131,7 +131,7 @@ async function enableAction( let feedback = renderSkillActionFeedback( result, - (label, _path) => `${label}`, + (label, path) => `${label} (${path})`, ); if (result.status === 'success') { feedback += ' Use "/skills reload" for it to take effect.'; From 722c4933dc34f962f1ad1c877c5ab779500af859 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 8 Jan 2026 03:38:47 -0800 Subject: [PATCH 056/713] Polish: Move 'Failed to load skills' warning to debug logs (#16142) --- .../src/config/extension-manager-skills.test.ts | 15 ++++++--------- packages/core/src/skills/skillLoader.test.ts | 8 ++++---- packages/core/src/skills/skillLoader.ts | 3 +-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/cli/src/config/extension-manager-skills.test.ts b/packages/cli/src/config/extension-manager-skills.test.ts index b0db1a0258..585f2adc51 100644 --- a/packages/cli/src/config/extension-manager-skills.test.ts +++ b/packages/cli/src/config/extension-manager-skills.test.ts @@ -12,7 +12,7 @@ import { ExtensionManager } from './extension-manager.js'; import { loadSettings } from './settings.js'; import { createExtension } from '../test-utils/createExtension.js'; import { EXTENSIONS_DIRECTORY_NAME } from './extensions/variables.js'; -import { coreEvents } from '@google/gemini-cli-core'; +import { coreEvents, debugLogger } from '@google/gemini-cli-core'; const mockHomedir = vi.hoisted(() => vi.fn()); @@ -58,6 +58,7 @@ describe('ExtensionManager skills validation', () => { settings: loadSettings(tempWorkspaceDir).merged, }); vi.spyOn(coreEvents, 'emitFeedback'); + vi.spyOn(debugLogger, 'debug').mockImplementation(() => {}); }); afterEach(() => { @@ -83,8 +84,7 @@ describe('ExtensionManager skills validation', () => { }); expect(extension.name).toBe('skills-ext'); - expect(coreEvents.emitFeedback).toHaveBeenCalledWith( - 'warning', + expect(debugLogger.debug).toHaveBeenCalledWith( expect.stringContaining('Failed to load skills from'), ); }); @@ -102,12 +102,10 @@ describe('ExtensionManager skills validation', () => { await extensionManager.loadExtensions(); - expect(coreEvents.emitFeedback).toHaveBeenCalledWith( - 'warning', + expect(debugLogger.debug).toHaveBeenCalledWith( expect.stringContaining('Failed to load skills from'), ); - expect(coreEvents.emitFeedback).toHaveBeenCalledWith( - 'warning', + expect(debugLogger.debug).toHaveBeenCalledWith( expect.stringContaining( 'The directory is not empty but no valid skills were discovered', ), @@ -139,8 +137,7 @@ describe('ExtensionManager skills validation', () => { expect(extension.skills![0].name).toBe('test-skill'); // It might be called for other reasons during startup, but shouldn't be called for our skills loading success // Actually, it shouldn't be called with our warning message - expect(coreEvents.emitFeedback).not.toHaveBeenCalledWith( - 'warning', + expect(debugLogger.debug).not.toHaveBeenCalledWith( expect.stringContaining('Failed to load skills from'), ); }); diff --git a/packages/core/src/skills/skillLoader.test.ts b/packages/core/src/skills/skillLoader.test.ts index 3a42253f9f..9f46f9ae4c 100644 --- a/packages/core/src/skills/skillLoader.test.ts +++ b/packages/core/src/skills/skillLoader.test.ts @@ -10,6 +10,7 @@ import * as os from 'node:os'; import * as path from 'node:path'; import { loadSkillsFromDir } from './skillLoader.js'; import { coreEvents } from '../utils/events.js'; +import { debugLogger } from '../utils/debugLogger.js'; describe('skillLoader', () => { let testRootDir: string; @@ -19,6 +20,7 @@ describe('skillLoader', () => { path.join(os.tmpdir(), 'skill-loader-test-'), ); vi.spyOn(coreEvents, 'emitFeedback'); + vi.spyOn(debugLogger, 'debug').mockImplementation(() => {}); }); afterEach(async () => { @@ -53,8 +55,7 @@ describe('skillLoader', () => { const skills = await loadSkillsFromDir(testRootDir); expect(skills).toHaveLength(0); - expect(coreEvents.emitFeedback).toHaveBeenCalledWith( - 'warning', + expect(debugLogger.debug).toHaveBeenCalledWith( expect.stringContaining('Failed to load skills from'), ); }); @@ -89,8 +90,7 @@ describe('skillLoader', () => { const skills = await loadSkillsFromDir(testRootDir); expect(skills).toHaveLength(0); - expect(coreEvents.emitFeedback).toHaveBeenCalledWith( - 'warning', + expect(debugLogger.debug).toHaveBeenCalledWith( expect.stringContaining('Failed to load skills from'), ); }); diff --git a/packages/core/src/skills/skillLoader.ts b/packages/core/src/skills/skillLoader.ts index e9de2db2f0..cbd1f238bd 100644 --- a/packages/core/src/skills/skillLoader.ts +++ b/packages/core/src/skills/skillLoader.ts @@ -60,8 +60,7 @@ export async function loadSkillsFromDir( if (discoveredSkills.length === 0) { const files = await fs.readdir(absoluteSearchPath); if (files.length > 0) { - coreEvents.emitFeedback( - 'warning', + debugLogger.debug( `Failed to load skills from ${absoluteSearchPath}. The directory is not empty but no valid skills were discovered. Please ensure SKILL.md files are present in subdirectories and have valid frontmatter.`, ); } From 030847a80a482d7bc545903de886da338f20e986 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 8 Jan 2026 03:43:55 -0800 Subject: [PATCH 057/713] feat(cli): export chat history in /bug and prefill GitHub issue (#16115) --- .gitignore | 1 + .../cli/src/ui/commands/bugCommand.test.ts | 82 ++++++++++++++++- packages/cli/src/ui/commands/bugCommand.ts | 40 ++++++++- .../cli/src/ui/commands/chatCommand.test.ts | 90 ++++++++----------- packages/cli/src/ui/commands/chatCommand.ts | 43 +-------- .../cli/src/ui/utils/historyExportUtils.ts | 79 ++++++++++++++++ 6 files changed, 234 insertions(+), 101 deletions(-) create mode 100644 packages/cli/src/ui/utils/historyExportUtils.ts diff --git a/.gitignore b/.gitignore index 1222895148..d9cfed7b0d 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,4 @@ patch_output.log .genkit .gemini-clipboard/ +.eslintcache diff --git a/packages/cli/src/ui/commands/bugCommand.test.ts b/packages/cli/src/ui/commands/bugCommand.test.ts index 9031e918f5..78f6bfb4a1 100644 --- a/packages/cli/src/ui/commands/bugCommand.test.ts +++ b/packages/cli/src/ui/commands/bugCommand.test.ts @@ -6,6 +6,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import open from 'open'; +import path from 'node:path'; import { bugCommand } from './bugCommand.js'; import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; import { getVersion } from '@google/gemini-cli-core'; @@ -15,6 +16,16 @@ import { formatMemoryUsage } from '../utils/formatters.js'; // Mock dependencies vi.mock('open'); vi.mock('../utils/formatters.js'); +vi.mock('../utils/historyExportUtils.js', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + exportHistoryToFile: vi.fn(), + }; +}); +import { exportHistoryToFile } from '../utils/historyExportUtils.js'; + vi.mock('@google/gemini-cli-core', async (importOriginal) => { const actual = await importOriginal(); @@ -27,6 +38,13 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { }, sessionId: 'test-session-id', getVersion: vi.fn(), + INITIAL_HISTORY_LENGTH: 1, + debugLogger: { + error: vi.fn(), + log: vi.fn(), + debug: vi.fn(), + warn: vi.fn(), + }, }; }); vi.mock('node:process', () => ({ @@ -52,11 +70,14 @@ describe('bugCommand', () => { vi.mocked(getVersion).mockResolvedValue('0.1.0'); vi.mocked(formatMemoryUsage).mockReturnValue('100 MB'); vi.stubEnv('SANDBOX', 'gemini-test'); + vi.useFakeTimers(); + vi.setSystemTime(new Date('2024-01-01T00:00:00Z')); }); afterEach(() => { vi.unstubAllEnvs(); vi.clearAllMocks(); + vi.useRealTimers(); }); it('should generate the default GitHub issue URL', async () => { @@ -66,6 +87,11 @@ describe('bugCommand', () => { getModel: () => 'gemini-pro', getBugCommand: () => undefined, getIdeMode: () => true, + getGeminiClient: () => ({ + getChat: () => ({ + getHistory: () => [], + }), + }), }, }, }); @@ -86,13 +112,58 @@ describe('bugCommand', () => { * **Kitty Keyboard Protocol:** Supported * **IDE Client:** VSCode `; - const expectedUrl = - 'https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.yml&title=A%20test%20bug&info=' + - encodeURIComponent(expectedInfo); + const expectedUrl = `https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.yml&title=A%20test%20bug&info=${encodeURIComponent(expectedInfo)}&problem=A%20test%20bug`; expect(open).toHaveBeenCalledWith(expectedUrl); }); + it('should export chat history if available', async () => { + const history = [ + { role: 'user', parts: [{ text: 'hello' }] }, + { role: 'model', parts: [{ text: 'hi' }] }, + ]; + const mockContext = createMockCommandContext({ + services: { + config: { + getModel: () => 'gemini-pro', + getBugCommand: () => undefined, + getIdeMode: () => true, + getGeminiClient: () => ({ + getChat: () => ({ + getHistory: () => history, + }), + }), + storage: { + getProjectTempDir: () => '/tmp/gemini', + }, + }, + }, + }); + + if (!bugCommand.action) throw new Error('Action is not defined'); + await bugCommand.action(mockContext, 'Bug with history'); + + const expectedPath = path.join( + '/tmp/gemini', + 'bug-report-history-1704067200000.json', + ); + expect(exportHistoryToFile).toHaveBeenCalledWith({ + history, + filePath: expectedPath, + }); + + const addItemCall = vi.mocked(mockContext.ui.addItem).mock.calls[0]; + const messageText = addItemCall[0].text; + expect(messageText).toContain(expectedPath); + expect(messageText).toContain('📄 **Chat History Exported**'); + expect(messageText).toContain('Privacy Disclaimer:'); + expect(messageText).not.toContain('additional-context='); + expect(messageText).toContain('problem='); + const reminder = + '\n\n[ACTION REQUIRED] 📎 PLEASE ATTACH THE EXPORTED CHAT HISTORY JSON FILE TO THIS ISSUE IF YOU FEEL COMFORTABLE SHARING IT.'; + expect(messageText).toContain(encodeURIComponent(reminder)); + }); + it('should use a custom URL template from config if provided', async () => { const customTemplate = 'https://internal.bug-tracker.com/new?desc={title}&details={info}'; @@ -102,6 +173,11 @@ describe('bugCommand', () => { getModel: () => 'gemini-pro', getBugCommand: () => ({ urlTemplate: customTemplate }), getIdeMode: () => true, + getGeminiClient: () => ({ + getChat: () => ({ + getHistory: () => [], + }), + }), }, }, }); diff --git a/packages/cli/src/ui/commands/bugCommand.ts b/packages/cli/src/ui/commands/bugCommand.ts index 21df2028cc..6c3a5a70d1 100644 --- a/packages/cli/src/ui/commands/bugCommand.ts +++ b/packages/cli/src/ui/commands/bugCommand.ts @@ -14,8 +14,16 @@ import { import { MessageType } from '../types.js'; import { GIT_COMMIT_INFO } from '../../generated/git-commit.js'; import { formatMemoryUsage } from '../utils/formatters.js'; -import { IdeClient, sessionId, getVersion } from '@google/gemini-cli-core'; +import { + IdeClient, + sessionId, + getVersion, + INITIAL_HISTORY_LENGTH, + debugLogger, +} from '@google/gemini-cli-core'; import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js'; +import { exportHistoryToFile } from '../utils/historyExportUtils.js'; +import path from 'node:path'; export const bugCommand: SlashCommand = { name: 'bug', @@ -63,8 +71,31 @@ export const bugCommand: SlashCommand = { info += `* **IDE Client:** ${ideClient}\n`; } + const chat = config?.getGeminiClient()?.getChat(); + const history = chat?.getHistory() || []; + let historyFileMessage = ''; + let problemValue = bugDescription; + + if (history.length > INITIAL_HISTORY_LENGTH) { + const tempDir = config?.storage?.getProjectTempDir(); + if (tempDir) { + const historyFileName = `bug-report-history-${Date.now()}.json`; + const historyFilePath = path.join(tempDir, historyFileName); + try { + await exportHistoryToFile({ history, filePath: historyFilePath }); + historyFileMessage = `\n\n--------------------------------------------------------------------------------\n\n📄 **Chat History Exported**\nTo help us debug, we've exported your current chat history to:\n${historyFilePath}\n\nPlease consider attaching this file to your GitHub issue if you feel comfortable doing so.\n\n**Privacy Disclaimer:** Please do not upload any logs containing sensitive or private information that you are not comfortable sharing publicly.`; + problemValue += `\n\n[ACTION REQUIRED] 📎 PLEASE ATTACH THE EXPORTED CHAT HISTORY JSON FILE TO THIS ISSUE IF YOU FEEL COMFORTABLE SHARING IT.`; + } catch (err) { + const errorMessage = err instanceof Error ? err.message : String(err); + debugLogger.error( + `Failed to export chat history for bug report: ${errorMessage}`, + ); + } + } + } + let bugReportUrl = - 'https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.yml&title={title}&info={info}'; + 'https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.yml&title={title}&info={info}&problem={problem}'; const bugCommandSettings = config?.getBugCommand(); if (bugCommandSettings?.urlTemplate) { @@ -73,12 +104,13 @@ export const bugCommand: SlashCommand = { bugReportUrl = bugReportUrl .replace('{title}', encodeURIComponent(bugDescription)) - .replace('{info}', encodeURIComponent(info)); + .replace('{info}', encodeURIComponent(info)) + .replace('{problem}', encodeURIComponent(problemValue)); context.ui.addItem( { type: MessageType.INFO, - text: `To submit your bug report, please open the following URL in your browser:\n${bugReportUrl}`, + text: `To submit your bug report, please open the following URL in your browser:\n${bugReportUrl}${historyFileMessage}`, }, Date.now(), ); diff --git a/packages/cli/src/ui/commands/chatCommand.test.ts b/packages/cli/src/ui/commands/chatCommand.test.ts index c934c29dfd..20d0be1e06 100644 --- a/packages/cli/src/ui/commands/chatCommand.test.ts +++ b/packages/cli/src/ui/commands/chatCommand.test.ts @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import type { Mocked } from 'vitest'; import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest'; import type { SlashCommand, CommandContext } from './types.js'; @@ -13,7 +12,11 @@ import type { Content } from '@google/genai'; import { AuthType, type GeminiClient } from '@google/gemini-cli-core'; import * as fsPromises from 'node:fs/promises'; -import { chatCommand, serializeHistoryToMarkdown } from './chatCommand.js'; +import { chatCommand } from './chatCommand.js'; +import { + serializeHistoryToMarkdown, + exportHistoryToFile, +} from '../utils/historyExportUtils.js'; import type { Stats } from 'node:fs'; import type { HistoryItemWithoutId } from '../types.js'; import path from 'node:path'; @@ -24,8 +27,18 @@ vi.mock('fs/promises', () => ({ writeFile: vi.fn(), })); +vi.mock('../utils/historyExportUtils.js', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + exportHistoryToFile: vi.fn(), + }; +}); + describe('chatCommand', () => { - const mockFs = fsPromises as Mocked; + const mockFs = vi.mocked(fsPromises); + const mockExport = vi.mocked(exportHistoryToFile); let mockContext: CommandContext; let mockGetChat: ReturnType; @@ -448,9 +461,10 @@ describe('chatCommand', () => { process.cwd(), 'gemini-conversation-1234567890.json', ); - const [actualPath, actualContent] = mockFs.writeFile.mock.calls[0]; - expect(actualPath).toEqual(expectedPath); - expect(actualContent).toEqual(JSON.stringify(mockHistory, null, 2)); + expect(mockExport).toHaveBeenCalledWith({ + history: mockHistory, + filePath: expectedPath, + }); expect(result).toEqual({ type: 'message', messageType: 'info', @@ -462,9 +476,10 @@ describe('chatCommand', () => { const filePath = 'my-chat.json'; const result = await shareCommand?.action?.(mockContext, filePath); const expectedPath = path.join(process.cwd(), 'my-chat.json'); - const [actualPath, actualContent] = mockFs.writeFile.mock.calls[0]; - expect(actualPath).toEqual(expectedPath); - expect(actualContent).toEqual(JSON.stringify(mockHistory, null, 2)); + expect(mockExport).toHaveBeenCalledWith({ + history: mockHistory, + filePath: expectedPath, + }); expect(result).toEqual({ type: 'message', messageType: 'info', @@ -476,30 +491,10 @@ describe('chatCommand', () => { const filePath = 'my-chat.md'; const result = await shareCommand?.action?.(mockContext, filePath); const expectedPath = path.join(process.cwd(), 'my-chat.md'); - const [actualPath, actualContent] = mockFs.writeFile.mock.calls[0]; - expect(actualPath).toEqual(expectedPath); - const expectedContent = `## USER 🧑‍💻 - -context - ---- - -## MODEL ✨ - -context response - ---- - -## USER 🧑‍💻 - -Hello - ---- - -## MODEL ✨ - -Hi there!`; - expect(actualContent).toEqual(expectedContent); + expect(mockExport).toHaveBeenCalledWith({ + history: mockHistory, + filePath: expectedPath, + }); expect(result).toEqual({ type: 'message', messageType: 'info', @@ -510,7 +505,7 @@ Hi there!`; it('should return an error for unsupported file extensions', async () => { const filePath = 'my-chat.txt'; const result = await shareCommand?.action?.(mockContext, filePath); - expect(mockFs.writeFile).not.toHaveBeenCalled(); + expect(mockExport).not.toHaveBeenCalled(); expect(result).toEqual({ type: 'message', messageType: 'error', @@ -523,7 +518,7 @@ Hi there!`; { role: 'user', parts: [{ text: 'context' }] }, ]); const result = await shareCommand?.action?.(mockContext, 'my-chat.json'); - expect(mockFs.writeFile).not.toHaveBeenCalled(); + expect(mockExport).not.toHaveBeenCalled(); expect(result).toEqual({ type: 'message', messageType: 'info', @@ -533,7 +528,7 @@ Hi there!`; it('should handle errors during file writing', async () => { const error = new Error('Permission denied'); - mockFs.writeFile.mockRejectedValue(error); + mockExport.mockRejectedValue(error); const result = await shareCommand?.action?.(mockContext, 'my-chat.json'); expect(result).toEqual({ type: 'message', @@ -546,14 +541,9 @@ Hi there!`; const filePath = 'my-chat.json'; await shareCommand?.action?.(mockContext, filePath); const expectedPath = path.join(process.cwd(), 'my-chat.json'); - const [actualPath, actualContent] = mockFs.writeFile.mock.calls[0]; - expect(actualPath).toEqual(expectedPath); - const parsedContent = JSON.parse(actualContent as string); - expect(Array.isArray(parsedContent)).toBe(true); - parsedContent.forEach((item: Content) => { - expect(item).toHaveProperty('role'); - expect(item).toHaveProperty('parts'); - expect(Array.isArray(item.parts)).toBe(true); + expect(mockExport).toHaveBeenCalledWith({ + history: mockHistory, + filePath: expectedPath, }); }); @@ -561,15 +551,9 @@ Hi there!`; const filePath = 'my-chat.md'; await shareCommand?.action?.(mockContext, filePath); const expectedPath = path.join(process.cwd(), 'my-chat.md'); - const [actualPath, actualContent] = mockFs.writeFile.mock.calls[0]; - expect(actualPath).toEqual(expectedPath); - const entries = (actualContent as string).split('\n\n---\n\n'); - expect(entries.length).toBe(mockHistory.length); - entries.forEach((entry: string, index: number) => { - const { role, parts } = mockHistory[index]; - const text = parts.map((p) => p.text).join(''); - const roleIcon = role === 'user' ? '🧑‍💻' : '✨'; - expect(entry).toBe(`## ${role.toUpperCase()} ${roleIcon}\n\n${text}`); + expect(mockExport).toHaveBeenCalledWith({ + history: mockHistory, + filePath: expectedPath, }); }); }); diff --git a/packages/cli/src/ui/commands/chatCommand.ts b/packages/cli/src/ui/commands/chatCommand.ts index 4b0078309c..7c9b632b1a 100644 --- a/packages/cli/src/ui/commands/chatCommand.ts +++ b/packages/cli/src/ui/commands/chatCommand.ts @@ -26,7 +26,7 @@ import type { ChatDetail, } from '../types.js'; import { MessageType } from '../types.js'; -import type { Content } from '@google/genai'; +import { exportHistoryToFile } from '../utils/historyExportUtils.js'; const getSavedChatTags = async ( context: CommandContext, @@ -272,38 +272,6 @@ const deleteCommand: SlashCommand = { }, }; -export function serializeHistoryToMarkdown(history: Content[]): string { - return history - .map((item) => { - const text = - item.parts - ?.map((part) => { - if (part.text) { - return part.text; - } - if (part.functionCall) { - return `**Tool Command**:\n\`\`\`json\n${JSON.stringify( - part.functionCall, - null, - 2, - )}\n\`\`\``; - } - if (part.functionResponse) { - return `**Tool Response**:\n\`\`\`json\n${JSON.stringify( - part.functionResponse, - null, - 2, - )}\n\`\`\``; - } - return ''; - }) - .join('') || ''; - const roleIcon = item.role === 'user' ? '🧑‍💻' : '✨'; - return `## ${(item.role || 'model').toUpperCase()} ${roleIcon}\n\n${text}`; - }) - .join('\n\n---\n\n'); -} - const shareCommand: SlashCommand = { name: 'share', description: @@ -348,15 +316,8 @@ const shareCommand: SlashCommand = { }; } - let content = ''; - if (extension === '.json') { - content = JSON.stringify(history, null, 2); - } else { - content = serializeHistoryToMarkdown(history); - } - try { - await fsPromises.writeFile(filePath, content); + await exportHistoryToFile({ history, filePath }); return { type: 'message', messageType: 'info', diff --git a/packages/cli/src/ui/utils/historyExportUtils.ts b/packages/cli/src/ui/utils/historyExportUtils.ts new file mode 100644 index 0000000000..85a53dd330 --- /dev/null +++ b/packages/cli/src/ui/utils/historyExportUtils.ts @@ -0,0 +1,79 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import * as fsPromises from 'node:fs/promises'; +import path from 'node:path'; +import type { Content } from '@google/genai'; + +/** + * Serializes chat history to a Markdown string. + */ +export function serializeHistoryToMarkdown(history: Content[]): string { + return history + .map((item) => { + const text = + item.parts + ?.map((part) => { + if (part.text) { + return part.text; + } + if (part.functionCall) { + return ( + `**Tool Command**:\n` + + '```json\n' + + JSON.stringify(part.functionCall, null, 2) + + '\n```' + ); + } + if (part.functionResponse) { + return ( + `**Tool Response**:\n` + + '```json\n' + + JSON.stringify(part.functionResponse, null, 2) + + '\n```' + ); + } + return ''; + }) + .join('') || ''; + const roleIcon = item.role === 'user' ? '🧑‍💻' : '✨'; + return `## ${(item.role || 'model').toUpperCase()} ${roleIcon}\n\n${text}`; + }) + .join('\n\n---\n\n'); +} + +/** + * Options for exporting chat history. + */ +export interface ExportHistoryOptions { + history: Content[]; + filePath: string; +} + +/** + * Exports chat history to a file (JSON or Markdown). + */ +export async function exportHistoryToFile( + options: ExportHistoryOptions, +): Promise { + const { history, filePath } = options; + const extension = path.extname(filePath).toLowerCase(); + + let content: string; + if (extension === '.json') { + content = JSON.stringify(history, null, 2); + } else if (extension === '.md') { + content = serializeHistoryToMarkdown(history); + } else { + throw new Error( + `Unsupported file extension: ${extension}. Use .json or .md.`, + ); + } + + const dir = path.dirname(filePath); + await fsPromises.mkdir(dir, { recursive: true }); + await fsPromises.writeFile(filePath, content, 'utf-8'); +} From eb75f59a96e48e4da5bd995be5f27da8d1ae4561 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Thu, 8 Jan 2026 06:59:58 -0800 Subject: [PATCH 058/713] bug(core): fix issue with overrides to bases. (#15255) --- .../services/modelConfig.integration.test.ts | 4 +- .../src/services/modelConfigService.test.ts | 65 ++++- .../core/src/services/modelConfigService.ts | 273 +++++++++++------- 3 files changed, 234 insertions(+), 108 deletions(-) diff --git a/packages/core/src/services/modelConfig.integration.test.ts b/packages/core/src/services/modelConfig.integration.test.ts index c6daf962b6..2ed2cb47af 100644 --- a/packages/core/src/services/modelConfig.integration.test.ts +++ b/packages/core/src/services/modelConfig.integration.test.ts @@ -141,7 +141,7 @@ describe('ModelConfigService Integration', () => { // No agent specified, so it should match core agent-specific rules }); - expect(resolved.model).toBe('gemini-1.5-flash-latest'); // from alias + expect(resolved.model).toBe('gemini-1.5-pro-latest'); // now overridden by 'base' expect(resolved.generateContentConfig).toEqual({ topP: 0.95, // from base topK: 64, // from base @@ -171,7 +171,7 @@ describe('ModelConfigService Integration', () => { overrideScope: 'core', }); - expect(resolved.model).toBe('gemini-1.5-flash-latest'); + expect(resolved.model).toBe('gemini-1.5-pro-latest'); // now overridden by 'base' expect(resolved.generateContentConfig).toEqual({ // Inherited from 'base' topP: 0.95, diff --git a/packages/core/src/services/modelConfigService.test.ts b/packages/core/src/services/modelConfigService.test.ts index ee6cd09f40..c9ddda2e2b 100644 --- a/packages/core/src/services/modelConfigService.test.ts +++ b/packages/core/src/services/modelConfigService.test.ts @@ -5,7 +5,10 @@ */ import { describe, it, expect } from 'vitest'; -import type { ModelConfigServiceConfig } from './modelConfigService.js'; +import type { + ModelConfigAlias, + ModelConfigServiceConfig, +} from './modelConfigService.js'; import { ModelConfigService } from './modelConfigService.js'; describe('ModelConfigService', () => { @@ -470,6 +473,21 @@ describe('ModelConfigService', () => { 'Alias "non-existent" not found.', ); }); + + it('should throw an error if the alias chain is too deep', () => { + const aliases: Record = {}; + for (let i = 0; i < 101; i++) { + aliases[`alias-${i}`] = { + extends: i === 100 ? undefined : `alias-${i + 1}`, + modelConfig: i === 100 ? { model: 'gemini-pro' } : {}, + }; + } + const config: ModelConfigServiceConfig = { aliases }; + const service = new ModelConfigService(config); + expect(() => service.getResolvedConfig({ model: 'alias-0' })).toThrow( + 'Alias inheritance chain exceeded maximum depth of 100.', + ); + }); }); describe('deep merging', () => { @@ -889,5 +907,50 @@ describe('ModelConfigService', () => { }); expect(retry.generateContentConfig.temperature).toBe(1.0); }); + + it('should apply overrides to parents in the alias hierarchy', () => { + const config: ModelConfigServiceConfig = { + aliases: { + 'base-alias': { + modelConfig: { + model: 'gemini-test', + generateContentConfig: { + temperature: 0.5, + }, + }, + }, + 'child-alias': { + extends: 'base-alias', + modelConfig: { + generateContentConfig: { + topP: 0.9, + }, + }, + }, + }, + overrides: [ + { + match: { model: 'base-alias', isRetry: true }, + modelConfig: { + generateContentConfig: { + temperature: 1.0, + }, + }, + }, + ], + }; + const service = new ModelConfigService(config); + + // Normal request + const normal = service.getResolvedConfig({ model: 'child-alias' }); + expect(normal.generateContentConfig.temperature).toBe(0.5); + + // Retry request - should match override on parent + const retry = service.getResolvedConfig({ + model: 'child-alias', + isRetry: true, + }); + expect(retry.generateContentConfig.temperature).toBe(1.0); + }); }); }); diff --git a/packages/core/src/services/modelConfigService.ts b/packages/core/src/services/modelConfigService.ts index 6fb712243c..0ec6d77ffb 100644 --- a/packages/core/src/services/modelConfigService.ts +++ b/packages/core/src/services/modelConfigService.ts @@ -54,6 +54,8 @@ export interface ModelConfigServiceConfig { customOverrides?: ModelConfigOverride[]; } +const MAX_ALIAS_CHAIN_DEPTH = 100; + export type ResolvedModelConfig = _ResolvedModelConfig & { readonly _brand: unique symbol; }; @@ -78,130 +80,68 @@ export class ModelConfigService { this.runtimeOverrides.push(override); } - private resolveAlias( - aliasName: string, - aliases: Record, - visited = new Set(), - ): ModelConfigAlias { - if (visited.has(aliasName)) { - throw new Error( - `Circular alias dependency: ${[...visited, aliasName].join(' -> ')}`, - ); - } - visited.add(aliasName); - - const alias = aliases[aliasName]; - if (!alias) { - throw new Error(`Alias "${aliasName}" not found.`); - } - - if (!alias.extends) { - return alias; - } - - const baseAlias = this.resolveAlias(alias.extends, aliases, visited); - - return { - modelConfig: { - model: alias.modelConfig.model ?? baseAlias.modelConfig.model, - generateContentConfig: this.deepMerge( - baseAlias.modelConfig.generateContentConfig, - alias.modelConfig.generateContentConfig, - ), - }, - }; - } - + /** + * Resolves a model configuration by merging settings from aliases and applying overrides. + * + * The resolution follows a linear application pipeline: + * + * 1. Alias Chain Resolution: + * Builds the inheritance chain from root to leaf. Configurations are merged starting from + * the root, so that children naturally override parents. + * + * 2. Override Level Assignment: + * Overrides are matched against the hierarchy and assigned a "Level" for application: + * - Level 0: Broad matches (Global or Resolved Model name). + * - Level 1..N: Hierarchy matches (from Root-most alias to Leaf-most alias). + * + * 3. Precedence & Application: + * Overrides are applied in order of their Level (ASC), then Specificity (ASC), then + * Configuration Order (ASC). This ensures that more targeted and "deeper" rules + * naturally layer on top of broader ones. + * + * 4. Orthogonality: + * All fields (including 'model') are treated equally. A more specific or deeper override + * can freely change any setting, including the target model name. + */ private internalGetResolvedConfig(context: ModelConfigKey): { model: string | undefined; generateContentConfig: GenerateContentConfig; } { - const config = this.config || {}; const { aliases = {}, customAliases = {}, overrides = [], customOverrides = [], - } = config; + } = this.config || {}; const allAliases = { ...aliases, ...customAliases, ...this.runtimeAliases, }; + + const { + aliasChain, + baseModel: initialBaseModel, + resolvedConfig: initialResolvedConfig, + } = this.resolveAliasChain(context.model, allAliases); + + let baseModel = initialBaseModel; + let resolvedConfig = initialResolvedConfig; + + const modelToLevel = this.buildModelLevelMap(aliasChain, baseModel); const allOverrides = [ ...overrides, ...customOverrides, ...this.runtimeOverrides, ]; - let baseModel: string | undefined = context.model; - let resolvedConfig: GenerateContentConfig = {}; + const matches = this.findMatchingOverrides( + allOverrides, + context, + modelToLevel, + ); - // Step 1: Alias Resolution - if (allAliases[context.model]) { - const resolvedAlias = this.resolveAlias(context.model, allAliases); - baseModel = resolvedAlias.modelConfig.model; // This can now be undefined - resolvedConfig = this.deepMerge( - resolvedConfig, - resolvedAlias.modelConfig.generateContentConfig, - ); - } + this.sortOverrides(matches); - // If an alias was used but didn't resolve to a model, `baseModel` is undefined. - // We still need a model for matching overrides. We'll use the original alias name - // for matching if no model is resolved yet. - const modelForMatching = baseModel ?? context.model; - - const finalContext = { - ...context, - model: modelForMatching, - }; - - // Step 2: Override Application - const matches = allOverrides - .map((override, index) => { - const matchEntries = Object.entries(override.match); - if (matchEntries.length === 0) { - return null; - } - - const isMatch = matchEntries.every(([key, value]) => { - if (key === 'model') { - return value === context.model || value === finalContext.model; - } - if (key === 'overrideScope' && value === 'core') { - // The 'core' overrideScope is special. It should match if the - // overrideScope is explicitly 'core' or if the overrideScope - // is not specified. - return context.overrideScope === 'core' || !context.overrideScope; - } - return finalContext[key as keyof ModelConfigKey] === value; - }); - - if (isMatch) { - return { - specificity: matchEntries.length, - modelConfig: override.modelConfig, - index, - }; - } - return null; - }) - .filter((match): match is NonNullable => match !== null); - - // The override application logic is designed to be both simple and powerful. - // By first sorting all matching overrides by specificity (and then by their - // original order as a tie-breaker), we ensure that as we merge the `config` - // objects, the settings from the most specific rules are applied last, - // correctly overwriting any values from broader, less-specific rules. - // This achieves a per-property override effect without complex per-property logic. - matches.sort((a, b) => { - if (a.specificity !== b.specificity) { - return a.specificity - b.specificity; - } - return a.index - b.index; - }); - - // Apply matching overrides for (const match of matches) { if (match.modelConfig.model) { baseModel = match.modelConfig.model; @@ -214,12 +154,135 @@ export class ModelConfigService { } } + return { model: baseModel, generateContentConfig: resolvedConfig }; + } + + private resolveAliasChain( + requestedModel: string, + allAliases: Record, + ): { + aliasChain: string[]; + baseModel: string | undefined; + resolvedConfig: GenerateContentConfig; + } { + let baseModel: string | undefined = undefined; + let resolvedConfig: GenerateContentConfig = {}; + const aliasChain: string[] = []; + + if (allAliases[requestedModel]) { + let current: string | undefined = requestedModel; + const visited = new Set(); + while (current) { + const alias: ModelConfigAlias = allAliases[current]; + if (!alias) { + throw new Error(`Alias "${current}" not found.`); + } + if (visited.size >= MAX_ALIAS_CHAIN_DEPTH) { + throw new Error( + `Alias inheritance chain exceeded maximum depth of ${MAX_ALIAS_CHAIN_DEPTH}.`, + ); + } + if (visited.has(current)) { + throw new Error( + `Circular alias dependency: ${[...visited, current].join(' -> ')}`, + ); + } + visited.add(current); + aliasChain.push(current); + current = alias.extends; + } + + // Root-to-Leaf chain for merging and level assignment. + const reversedChain = [...aliasChain].reverse(); + for (const aliasName of reversedChain) { + const alias = allAliases[aliasName]; + if (alias.modelConfig.model) { + baseModel = alias.modelConfig.model; + } + resolvedConfig = this.deepMerge( + resolvedConfig, + alias.modelConfig.generateContentConfig, + ); + } + return { aliasChain: reversedChain, baseModel, resolvedConfig }; + } + return { - model: baseModel, - generateContentConfig: resolvedConfig, + aliasChain: [requestedModel], + baseModel: requestedModel, + resolvedConfig: {}, }; } + private buildModelLevelMap( + aliasChain: string[], + baseModel: string | undefined, + ): Map { + const modelToLevel = new Map(); + // Global and Model name are both level 0. + if (baseModel) { + modelToLevel.set(baseModel, 0); + } + // Alias chain starts at level 1. + aliasChain.forEach((name, i) => modelToLevel.set(name, i + 1)); + return modelToLevel; + } + + private findMatchingOverrides( + overrides: ModelConfigOverride[], + context: ModelConfigKey, + modelToLevel: Map, + ): Array<{ + specificity: number; + level: number; + modelConfig: ModelConfig; + index: number; + }> { + return overrides + .map((override, index) => { + const matchEntries = Object.entries(override.match); + if (matchEntries.length === 0) return null; + + let matchedLevel = 0; // Default to Global + const isMatch = matchEntries.every(([key, value]) => { + if (key === 'model') { + const level = modelToLevel.get(value as string); + if (level === undefined) return false; + matchedLevel = level; + return true; + } + if (key === 'overrideScope' && value === 'core') { + return context.overrideScope === 'core' || !context.overrideScope; + } + return context[key as keyof ModelConfigKey] === value; + }); + + return isMatch + ? { + specificity: matchEntries.length, + level: matchedLevel, + modelConfig: override.modelConfig, + index, + } + : null; + }) + .filter((m): m is NonNullable => m !== null); + } + + private sortOverrides( + matches: Array<{ specificity: number; level: number; index: number }>, + ): void { + matches.sort((a, b) => { + if (a.level !== b.level) { + return a.level - b.level; + } + if (a.specificity !== b.specificity) { + return a.specificity - b.specificity; + } + return a.index - b.index; + }); + } + getResolvedConfig(context: ModelConfigKey): ResolvedModelConfig { const resolved = this.internalGetResolvedConfig(context); From cf021ccae46e3d419f21bcc41dc7fd0638c8cd6b Mon Sep 17 00:00:00 2001 From: David Pierce Date: Thu, 8 Jan 2026 12:03:30 -0500 Subject: [PATCH 059/713] enableInteractiveShell for external tooling relying on a2a server (#16080) --- packages/a2a-server/src/config/config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/a2a-server/src/config/config.ts b/packages/a2a-server/src/config/config.ts index 9c26173a69..a748c0b2d7 100644 --- a/packages/a2a-server/src/config/config.ts +++ b/packages/a2a-server/src/config/config.ts @@ -79,6 +79,7 @@ export async function loadConfig( : settings.checkpointing?.enabled, previewFeatures: settings.general?.previewFeatures, interactive: true, + enableInteractiveShell: true, }; const fileService = new FileDiscoveryService(workspaceDir); From 97ad3d97cba27b871efbd84cb69f90ca4846760c Mon Sep 17 00:00:00 2001 From: Shreya Keshive Date: Thu, 8 Jan 2026 12:59:30 -0500 Subject: [PATCH 060/713] Reapply "feat(admin): implement extensions disabled" (#16082) (#16109) --- packages/cli/src/config/config.ts | 2 + packages/cli/src/config/extension-manager.ts | 22 ++++-- packages/cli/src/config/extension.test.ts | 73 +++++++++++++++++++ .../src/services/BuiltinCommandLoader.test.ts | 2 + .../cli/src/services/BuiltinCommandLoader.ts | 21 +++++- packages/core/src/config/config.ts | 7 ++ 6 files changed, 119 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 2e2ecbd87f..7ca8d2934d 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -637,6 +637,7 @@ export async function loadCliConfig( const ptyInfo = await getPty(); const mcpEnabled = settings.admin?.mcp?.enabled ?? true; + const extensionsEnabled = settings.admin?.extensions?.enabled ?? true; return new Config({ sessionId, @@ -659,6 +660,7 @@ export async function loadCliConfig( mcpServerCommand: mcpEnabled ? settings.mcp?.serverCommand : undefined, mcpServers: mcpEnabled ? settings.mcpServers : {}, mcpEnabled, + extensionsEnabled, allowedMcpServers: mcpEnabled ? (argv.allowedMcpServerNames ?? settings.mcp?.allowed) : undefined, diff --git a/packages/cli/src/config/extension-manager.ts b/packages/cli/src/config/extension-manager.ts index 3c4ed226c8..998b91529c 100644 --- a/packages/cli/src/config/extension-manager.ts +++ b/packages/cli/src/config/extension-manager.ts @@ -465,6 +465,12 @@ Would you like to attempt to install via "git clone" instead?`, if (this.loadedExtensions) { throw new Error('Extensions already loaded, only load extensions once.'); } + + if (this.settings.admin?.extensions?.enabled === false) { + this.loadedExtensions = []; + return this.loadedExtensions; + } + const extensionsDir = ExtensionStorage.getUserExtensionsDir(); this.loadedExtensions = []; if (!fs.existsSync(extensionsDir)) { @@ -537,12 +543,16 @@ Would you like to attempt to install via "git clone" instead?`, } if (config.mcpServers) { - config.mcpServers = Object.fromEntries( - Object.entries(config.mcpServers).map(([key, value]) => [ - key, - filterMcpConfig(value), - ]), - ); + if (this.settings.admin?.mcp?.enabled === false) { + config.mcpServers = undefined; + } else { + config.mcpServers = Object.fromEntries( + Object.entries(config.mcpServers).map(([key, value]) => [ + key, + filterMcpConfig(value), + ]), + ); + } } const contextFiles = getContextFileNames(config) diff --git a/packages/cli/src/config/extension.test.ts b/packages/cli/src/config/extension.test.ts index 0bfa7a0358..1807144e82 100644 --- a/packages/cli/src/config/extension.test.ts +++ b/packages/cli/src/config/extension.test.ts @@ -632,6 +632,79 @@ describe('extension tests', () => { expect(extension).toBeUndefined(); }); + it('should not load any extensions if admin.extensions.enabled is false', async () => { + createExtension({ + extensionsDir: userExtensionsDir, + name: 'test-extension', + version: '1.0.0', + }); + const loadedSettings = loadSettings(tempWorkspaceDir).merged; + (loadedSettings.admin ??= {}).extensions ??= {}; + loadedSettings.admin.extensions.enabled = false; + + extensionManager = new ExtensionManager({ + workspaceDir: tempWorkspaceDir, + requestConsent: mockRequestConsent, + requestSetting: mockPromptForSettings, + settings: loadedSettings, + }); + + const extensions = await extensionManager.loadExtensions(); + expect(extensions).toEqual([]); + }); + + it('should not load mcpServers if admin.mcp.enabled is false', async () => { + createExtension({ + extensionsDir: userExtensionsDir, + name: 'test-extension', + version: '1.0.0', + mcpServers: { + 'test-server': { command: 'echo', args: ['hello'] }, + }, + }); + const loadedSettings = loadSettings(tempWorkspaceDir).merged; + (loadedSettings.admin ??= {}).mcp ??= {}; + loadedSettings.admin.mcp.enabled = false; + + extensionManager = new ExtensionManager({ + workspaceDir: tempWorkspaceDir, + requestConsent: mockRequestConsent, + requestSetting: mockPromptForSettings, + settings: loadedSettings, + }); + + const extensions = await extensionManager.loadExtensions(); + expect(extensions).toHaveLength(1); + expect(extensions[0].mcpServers).toBeUndefined(); + }); + + it('should load mcpServers if admin.mcp.enabled is true', async () => { + createExtension({ + extensionsDir: userExtensionsDir, + name: 'test-extension', + version: '1.0.0', + mcpServers: { + 'test-server': { command: 'echo', args: ['hello'] }, + }, + }); + const loadedSettings = loadSettings(tempWorkspaceDir).merged; + (loadedSettings.admin ??= {}).mcp ??= {}; + loadedSettings.admin.mcp.enabled = true; + + extensionManager = new ExtensionManager({ + workspaceDir: tempWorkspaceDir, + requestConsent: mockRequestConsent, + requestSetting: mockPromptForSettings, + settings: loadedSettings, + }); + + const extensions = await extensionManager.loadExtensions(); + expect(extensions).toHaveLength(1); + expect(extensions[0].mcpServers).toEqual({ + 'test-server': { command: 'echo', args: ['hello'] }, + }); + }); + describe('id generation', () => { it.each([ { diff --git a/packages/cli/src/services/BuiltinCommandLoader.test.ts b/packages/cli/src/services/BuiltinCommandLoader.test.ts index 6bebf0b06e..22b7a47ffc 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.test.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.test.ts @@ -102,6 +102,7 @@ describe('BuiltinCommandLoader', () => { getEnableExtensionReloading: () => false, getEnableHooks: () => false, getEnableHooksUI: () => false, + getExtensionsEnabled: vi.fn().mockReturnValue(true), isSkillsSupportEnabled: vi.fn().mockReturnValue(false), getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ @@ -201,6 +202,7 @@ describe('BuiltinCommandLoader profile', () => { getEnableExtensionReloading: () => false, getEnableHooks: () => false, getEnableHooksUI: () => false, + getExtensionsEnabled: vi.fn().mockReturnValue(true), isSkillsSupportEnabled: vi.fn().mockReturnValue(false), getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ diff --git a/packages/cli/src/services/BuiltinCommandLoader.ts b/packages/cli/src/services/BuiltinCommandLoader.ts index ea72ecdb05..4320217220 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.ts @@ -76,7 +76,24 @@ export class BuiltinCommandLoader implements ICommandLoader { docsCommand, directoryCommand, editorCommand, - extensionsCommand(this.config?.getEnableExtensionReloading()), + ...(this.config?.getExtensionsEnabled() === false + ? [ + { + name: 'extensions', + description: 'Manage extensions', + kind: CommandKind.BUILT_IN, + autoExecute: false, + subCommands: [], + action: async ( + _context: CommandContext, + ): Promise => ({ + type: 'message', + messageType: 'error', + content: 'Extensions are disabled by your admin.', + }), + }, + ] + : [extensionsCommand(this.config?.getEnableExtensionReloading())]), helpCommand, ...(this.config?.getEnableHooksUI() ? [hooksCommand] : []), await ideCommand(), @@ -95,7 +112,7 @@ export class BuiltinCommandLoader implements ICommandLoader { ): Promise => ({ type: 'message', messageType: 'error', - content: 'MCP disabled by your admin.', + content: 'MCP is disabled by your admin.', }), }, ] diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 8e7a8e42cb..01615c1081 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -357,6 +357,7 @@ export interface ConfigParameters { experimentalJitContext?: boolean; onModelChange?: (model: string) => void; mcpEnabled?: boolean; + extensionsEnabled?: boolean; onReload?: () => Promise<{ disabledSkills?: string[] }>; } @@ -391,6 +392,7 @@ export class Config { private readonly toolCallCommand: string | undefined; private readonly mcpServerCommand: string | undefined; private readonly mcpEnabled: boolean; + private readonly extensionsEnabled: boolean; private mcpServers: Record | undefined; private userMemory: string; private geminiMdFileCount: number; @@ -517,6 +519,7 @@ export class Config { this.mcpServerCommand = params.mcpServerCommand; this.mcpServers = params.mcpServers; this.mcpEnabled = params.mcpEnabled ?? true; + this.extensionsEnabled = params.extensionsEnabled ?? true; this.allowedMcpServers = params.allowedMcpServers ?? []; this.blockedMcpServers = params.blockedMcpServers ?? []; this.allowedEnvironmentVariables = params.allowedEnvironmentVariables ?? []; @@ -1143,6 +1146,10 @@ export class Config { return this.mcpEnabled; } + getExtensionsEnabled(): boolean { + return this.extensionsEnabled; + } + getMcpClientManager(): McpClientManager | undefined { return this.mcpClientManager; } From 660368f249066151e033a65668525ea17c20e3b3 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Thu, 8 Jan 2026 10:12:11 -0800 Subject: [PATCH 061/713] bug(core): Fix spewie getter in `hookTranslator.ts` (#16108) --- packages/core/src/hooks/hookTranslator.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/src/hooks/hookTranslator.ts b/packages/core/src/hooks/hookTranslator.ts index 9cbcd903f8..56036a16db 100644 --- a/packages/core/src/hooks/hookTranslator.ts +++ b/packages/core/src/hooks/hookTranslator.ts @@ -12,6 +12,7 @@ import type { FunctionCallingConfig, } from '@google/genai'; import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js'; +import { getResponseText } from '../utils/partUtils.js'; /** * Decoupled LLM request format - stable across Gemini CLI versions @@ -267,7 +268,7 @@ export class HookTranslatorGenAIv1 extends HookTranslator { */ toHookLLMResponse(sdkResponse: GenerateContentResponse): LLMResponse { return { - text: sdkResponse.text, + text: getResponseText(sdkResponse) ?? undefined, candidates: (sdkResponse.candidates || []).map((candidate) => { // Extract text parts from the candidate const textParts = From eb3f3cfdb8a0d2fd9a81ed7ab7d2a96f965ac483 Mon Sep 17 00:00:00 2001 From: Vijay Vasudevan Date: Thu, 8 Jan 2026 10:35:33 -0800 Subject: [PATCH 062/713] feat(hooks): add mcp_context to BeforeTool and AfterTool hook inputs (#15656) Co-authored-by: Tommaso Sciortino --- docs/hooks/reference.md | 10 + .../core/src/core/coreToolHookTriggers.ts | 53 +++++ .../core/src/hooks/hookEventHandler.test.ts | 194 ++++++++++++++++++ packages/core/src/hooks/hookEventHandler.ts | 43 +++- packages/core/src/hooks/types.ts | 26 +++ packages/core/src/scheduler/tool-executor.ts | 3 + packages/core/src/tools/mcp-tool.ts | 2 +- 7 files changed, 325 insertions(+), 6 deletions(-) diff --git a/docs/hooks/reference.md b/docs/hooks/reference.md index bc7b6e5fa2..b5174f827e 100644 --- a/docs/hooks/reference.md +++ b/docs/hooks/reference.md @@ -46,6 +46,16 @@ specific event. - `tool_input`: (`object`) The arguments passed to the tool. - `tool_response`: (`object`, **AfterTool only**) The raw output from the tool execution. +- `mcp_context`: (`object`, **optional**) Present only for MCP tool invocations. + Contains server identity information: + - `server_name`: (`string`) The configured name of the MCP server. + - `tool_name`: (`string`) The original tool name from the MCP server. + - `command`: (`string`, optional) For stdio transport, the command used to + start the server. + - `args`: (`string[]`, optional) For stdio transport, the command arguments. + - `cwd`: (`string`, optional) For stdio transport, the working directory. + - `url`: (`string`, optional) For SSE/HTTP transport, the server URL. + - `tcp`: (`string`, optional) For WebSocket transport, the TCP address. #### Agent Events (`BeforeAgent`, `AfterAgent`) diff --git a/packages/core/src/core/coreToolHookTriggers.ts b/packages/core/src/core/coreToolHookTriggers.ts index 70f9e93c1d..ca1467518b 100644 --- a/packages/core/src/core/coreToolHookTriggers.ts +++ b/packages/core/src/core/coreToolHookTriggers.ts @@ -14,8 +14,10 @@ import { createHookOutput, NotificationType, type DefaultHookOutput, + type McpToolContext, BeforeToolHookOutput, } from '../hooks/types.js'; +import type { Config } from '../config/config.js'; import type { ToolCallConfirmationDetails, ToolResult, @@ -26,6 +28,7 @@ import { debugLogger } from '../utils/debugLogger.js'; import type { AnsiOutput, ShellExecutionConfig } from '../index.js'; import type { AnyToolInvocation } from '../tools/tools.js'; import { ShellToolInvocation } from '../tools/shell.js'; +import { DiscoveredMCPToolInvocation } from '../tools/mcp-tool.js'; /** * Serializable representation of tool confirmation details for hooks. @@ -154,18 +157,57 @@ export async function fireToolNotificationHook( } } +/** + * Extracts MCP context from a tool invocation if it's an MCP tool. + * + * @param invocation The tool invocation + * @param config Config to look up server details + * @returns MCP context if this is an MCP tool, undefined otherwise + */ +function extractMcpContext( + invocation: ShellToolInvocation | AnyToolInvocation, + config: Config, +): McpToolContext | undefined { + if (!(invocation instanceof DiscoveredMCPToolInvocation)) { + return undefined; + } + + // Get the server config + const mcpServers = + config.getMcpClientManager()?.getMcpServers() ?? + config.getMcpServers() ?? + {}; + const serverConfig = mcpServers[invocation.serverName]; + if (!serverConfig) { + return undefined; + } + + return { + server_name: invocation.serverName, + tool_name: invocation.serverToolName, + // Non-sensitive connection details only + command: serverConfig.command, + args: serverConfig.args, + cwd: serverConfig.cwd, + url: serverConfig.url ?? serverConfig.httpUrl, + tcp: serverConfig.tcp, + }; +} + /** * Fires the BeforeTool hook and returns the hook output. * * @param messageBus The message bus to use for hook communication * @param toolName The name of the tool being executed * @param toolInput The input parameters for the tool + * @param mcpContext Optional MCP context for MCP tools * @returns The hook output, or undefined if no hook was executed or on error */ export async function fireBeforeToolHook( messageBus: MessageBus, toolName: string, toolInput: Record, + mcpContext?: McpToolContext, ): Promise { try { const response = await messageBus.request< @@ -178,6 +220,7 @@ export async function fireBeforeToolHook( input: { tool_name: toolName, tool_input: toolInput, + ...(mcpContext && { mcp_context: mcpContext }), }, }, MessageBusType.HOOK_EXECUTION_RESPONSE, @@ -199,6 +242,7 @@ export async function fireBeforeToolHook( * @param toolName The name of the tool that was executed * @param toolInput The input parameters for the tool * @param toolResponse The result from the tool execution + * @param mcpContext Optional MCP context for MCP tools * @returns The hook output, or undefined if no hook was executed or on error */ export async function fireAfterToolHook( @@ -210,6 +254,7 @@ export async function fireAfterToolHook( returnDisplay: ToolResult['returnDisplay']; error: ToolResult['error']; }, + mcpContext?: McpToolContext, ): Promise { try { const response = await messageBus.request< @@ -223,6 +268,7 @@ export async function fireAfterToolHook( tool_name: toolName, tool_input: toolInput, tool_response: toolResponse, + ...(mcpContext && { mcp_context: mcpContext }), }, }, MessageBusType.HOOK_EXECUTION_RESPONSE, @@ -248,6 +294,7 @@ export async function fireAfterToolHook( * @param liveOutputCallback Optional callback for live output updates * @param shellExecutionConfig Optional shell execution config * @param setPidCallback Optional callback to set the PID for shell invocations + * @param config Config to look up MCP server details for hook context * @returns The tool result */ export async function executeToolWithHooks( @@ -260,17 +307,22 @@ export async function executeToolWithHooks( liveOutputCallback?: (outputChunk: string | AnsiOutput) => void, shellExecutionConfig?: ShellExecutionConfig, setPidCallback?: (pid: number) => void, + config?: Config, ): Promise { const toolInput = (invocation.params || {}) as Record; let inputWasModified = false; let modifiedKeys: string[] = []; + // Extract MCP context if this is an MCP tool (only if config is provided) + const mcpContext = config ? extractMcpContext(invocation, config) : undefined; + // Fire BeforeTool hook through MessageBus (only if hooks are enabled) if (hooksEnabled && messageBus) { const beforeOutput = await fireBeforeToolHook( messageBus, toolName, toolInput, + mcpContext, ); // Check if hook requested to stop entire agent execution @@ -378,6 +430,7 @@ export async function executeToolWithHooks( returnDisplay: toolResult.returnDisplay, error: toolResult.error, }, + mcpContext, ); // Check if hook requested to stop entire agent execution diff --git a/packages/core/src/hooks/hookEventHandler.test.ts b/packages/core/src/hooks/hookEventHandler.test.ts index 2bffc805b6..af7a6be37a 100644 --- a/packages/core/src/hooks/hookEventHandler.test.ts +++ b/packages/core/src/hooks/hookEventHandler.test.ts @@ -258,6 +258,128 @@ describe('HookEventHandler', () => { expect.stringContaining('F12'), ); }); + + it('should fire BeforeTool event with MCP context when provided', async () => { + const mockPlan = [ + { + hookConfig: { + type: HookType.Command, + command: './test.sh', + } as unknown as HookConfig, + eventName: HookEventName.BeforeTool, + }, + ]; + const mockResults: HookExecutionResult[] = [ + { + success: true, + duration: 100, + hookConfig: { + type: HookType.Command, + command: './test.sh', + timeout: 30000, + }, + eventName: HookEventName.BeforeTool, + }, + ]; + const mockAggregated = { + success: true, + allOutputs: [], + errors: [], + totalDuration: 100, + }; + + vi.mocked(mockHookPlanner.createExecutionPlan).mockReturnValue({ + eventName: HookEventName.BeforeTool, + hookConfigs: mockPlan.map((p) => p.hookConfig), + sequential: false, + }); + vi.mocked(mockHookRunner.executeHooksParallel).mockResolvedValue( + mockResults, + ); + vi.mocked(mockHookAggregator.aggregateResults).mockReturnValue( + mockAggregated, + ); + + const mcpContext = { + server_name: 'my-mcp-server', + tool_name: 'read_file', + command: 'npx', + args: ['-y', '@my-org/mcp-server'], + }; + + const result = await hookEventHandler.fireBeforeToolEvent( + 'my-mcp-server__read_file', + { path: '/etc/passwd' }, + mcpContext, + ); + + expect(mockHookRunner.executeHooksParallel).toHaveBeenCalledWith( + [mockPlan[0].hookConfig], + HookEventName.BeforeTool, + expect.objectContaining({ + session_id: 'test-session', + cwd: '/test/project', + hook_event_name: 'BeforeTool', + tool_name: 'my-mcp-server__read_file', + tool_input: { path: '/etc/passwd' }, + mcp_context: mcpContext, + }), + expect.any(Function), + expect.any(Function), + ); + + expect(result).toBe(mockAggregated); + }); + + it('should not include mcp_context when not provided', async () => { + const mockPlan = [ + { + hookConfig: { + type: HookType.Command, + command: './test.sh', + } as unknown as HookConfig, + eventName: HookEventName.BeforeTool, + }, + ]; + const mockResults: HookExecutionResult[] = [ + { + success: true, + duration: 100, + hookConfig: { + type: HookType.Command, + command: './test.sh', + timeout: 30000, + }, + eventName: HookEventName.BeforeTool, + }, + ]; + const mockAggregated = { + success: true, + allOutputs: [], + errors: [], + totalDuration: 100, + }; + + vi.mocked(mockHookPlanner.createExecutionPlan).mockReturnValue({ + eventName: HookEventName.BeforeTool, + hookConfigs: mockPlan.map((p) => p.hookConfig), + sequential: false, + }); + vi.mocked(mockHookRunner.executeHooksParallel).mockResolvedValue( + mockResults, + ); + vi.mocked(mockHookAggregator.aggregateResults).mockReturnValue( + mockAggregated, + ); + + await hookEventHandler.fireBeforeToolEvent('EditTool', { + file: 'test.txt', + }); + + const callArgs = vi.mocked(mockHookRunner.executeHooksParallel).mock + .calls[0][2]; + expect(callArgs).not.toHaveProperty('mcp_context'); + }); }); describe('fireAfterToolEvent', () => { @@ -325,6 +447,78 @@ describe('HookEventHandler', () => { expect(result).toBe(mockAggregated); }); + + it('should fire AfterTool event with MCP context when provided', async () => { + const mockPlan = [ + { + hookConfig: { + type: HookType.Command, + command: './after.sh', + } as unknown as HookConfig, + eventName: HookEventName.AfterTool, + }, + ]; + const mockResults: HookExecutionResult[] = [ + { + success: true, + duration: 100, + hookConfig: { + type: HookType.Command, + command: './after.sh', + timeout: 30000, + }, + eventName: HookEventName.AfterTool, + }, + ]; + const mockAggregated = { + success: true, + allOutputs: [], + errors: [], + totalDuration: 100, + }; + + vi.mocked(mockHookPlanner.createExecutionPlan).mockReturnValue({ + eventName: HookEventName.AfterTool, + hookConfigs: mockPlan.map((p) => p.hookConfig), + sequential: false, + }); + vi.mocked(mockHookRunner.executeHooksParallel).mockResolvedValue( + mockResults, + ); + vi.mocked(mockHookAggregator.aggregateResults).mockReturnValue( + mockAggregated, + ); + + const toolInput = { path: '/etc/passwd' }; + const toolResponse = { success: true, content: 'File content' }; + const mcpContext = { + server_name: 'my-mcp-server', + tool_name: 'read_file', + url: 'https://mcp.example.com', + }; + + const result = await hookEventHandler.fireAfterToolEvent( + 'my-mcp-server__read_file', + toolInput, + toolResponse, + mcpContext, + ); + + expect(mockHookRunner.executeHooksParallel).toHaveBeenCalledWith( + [mockPlan[0].hookConfig], + HookEventName.AfterTool, + expect.objectContaining({ + tool_name: 'my-mcp-server__read_file', + tool_input: toolInput, + tool_response: toolResponse, + mcp_context: mcpContext, + }), + expect.any(Function), + expect.any(Function), + ); + + expect(result).toBe(mockAggregated); + }); }); describe('fireBeforeAgentEvent', () => { diff --git a/packages/core/src/hooks/hookEventHandler.ts b/packages/core/src/hooks/hookEventHandler.ts index e72aee913a..e208dd1ed4 100644 --- a/packages/core/src/hooks/hookEventHandler.ts +++ b/packages/core/src/hooks/hookEventHandler.ts @@ -29,6 +29,7 @@ import type { SessionEndReason, PreCompressTrigger, HookExecutionResult, + McpToolContext, } from './types.js'; import { defaultHookTranslator } from './hookTranslator.js'; import type { @@ -58,9 +59,11 @@ function isObject(value: unknown): value is Record { function validateBeforeToolInput(input: Record): { toolName: string; toolInput: Record; + mcpContext?: McpToolContext; } { const toolName = input['tool_name']; const toolInput = input['tool_input']; + const mcpContext = input['mcp_context']; if (typeof toolName !== 'string') { throw new Error( 'Invalid input for BeforeTool hook event: tool_name must be a string', @@ -71,7 +74,16 @@ function validateBeforeToolInput(input: Record): { 'Invalid input for BeforeTool hook event: tool_input must be an object', ); } - return { toolName, toolInput }; + if (mcpContext !== undefined && !isObject(mcpContext)) { + throw new Error( + 'Invalid input for BeforeTool hook event: mcp_context must be an object', + ); + } + return { + toolName, + toolInput, + mcpContext: mcpContext as McpToolContext | undefined, + }; } /** @@ -81,10 +93,12 @@ function validateAfterToolInput(input: Record): { toolName: string; toolInput: Record; toolResponse: Record; + mcpContext?: McpToolContext; } { const toolName = input['tool_name']; const toolInput = input['tool_input']; const toolResponse = input['tool_response']; + const mcpContext = input['mcp_context']; if (typeof toolName !== 'string') { throw new Error( 'Invalid input for AfterTool hook event: tool_name must be a string', @@ -100,7 +114,17 @@ function validateAfterToolInput(input: Record): { 'Invalid input for AfterTool hook event: tool_response must be an object', ); } - return { toolName, toolInput, toolResponse }; + if (mcpContext !== undefined && !isObject(mcpContext)) { + throw new Error( + 'Invalid input for AfterTool hook event: mcp_context must be an object', + ); + } + return { + toolName, + toolInput, + toolResponse, + mcpContext: mcpContext as McpToolContext | undefined, + }; } /** @@ -313,11 +337,13 @@ export class HookEventHandler { async fireBeforeToolEvent( toolName: string, toolInput: Record, + mcpContext?: McpToolContext, ): Promise { const input: BeforeToolInput = { ...this.createBaseInput(HookEventName.BeforeTool), tool_name: toolName, tool_input: toolInput, + ...(mcpContext && { mcp_context: mcpContext }), }; const context: HookEventContext = { toolName }; @@ -332,12 +358,14 @@ export class HookEventHandler { toolName: string, toolInput: Record, toolResponse: Record, + mcpContext?: McpToolContext, ): Promise { const input: AfterToolInput = { ...this.createBaseInput(HookEventName.AfterTool), tool_name: toolName, tool_input: toolInput, tool_response: toolResponse, + ...(mcpContext && { mcp_context: mcpContext }), }; const context: HookEventContext = { toolName }; @@ -725,18 +753,23 @@ export class HookEventHandler { // Route to appropriate event handler based on eventName switch (request.eventName) { case HookEventName.BeforeTool: { - const { toolName, toolInput } = + const { toolName, toolInput, mcpContext } = validateBeforeToolInput(enrichedInput); - result = await this.fireBeforeToolEvent(toolName, toolInput); + result = await this.fireBeforeToolEvent( + toolName, + toolInput, + mcpContext, + ); break; } case HookEventName.AfterTool: { - const { toolName, toolInput, toolResponse } = + const { toolName, toolInput, toolResponse, mcpContext } = validateAfterToolInput(enrichedInput); result = await this.fireAfterToolEvent( toolName, toolInput, toolResponse, + mcpContext, ); break; } diff --git a/packages/core/src/hooks/types.ts b/packages/core/src/hooks/types.ts index e54a03f840..5ca7bd5fb1 100644 --- a/packages/core/src/hooks/types.ts +++ b/packages/core/src/hooks/types.ts @@ -373,12 +373,37 @@ export class AfterModelHookOutput extends DefaultHookOutput { } } +/** + * Context for MCP tool executions. + * Contains non-sensitive connection information about the MCP server + * identity. Since server_name is user controlled and arbitrary, we + * also include connection information (e.g., command or url) to + * help identify the MCP server. + * + * NOTE: In the future, consider defining a shared sanitized interface + * from MCPServerConfig to avoid duplication and ensure consistency. + */ +export interface McpToolContext { + server_name: string; + tool_name: string; // Original tool name from the MCP server + + // Connection info (mutually exclusive based on transport type) + command?: string; // For stdio transport + args?: string[]; // For stdio transport + cwd?: string; // For stdio transport + + url?: string; // For SSE/HTTP transport + + tcp?: string; // For WebSocket transport +} + /** * BeforeTool hook input */ export interface BeforeToolInput extends HookInput { tool_name: string; tool_input: Record; + mcp_context?: McpToolContext; // Only present for MCP tools } /** @@ -398,6 +423,7 @@ export interface AfterToolInput extends HookInput { tool_name: string; tool_input: Record; tool_response: Record; + mcp_context?: McpToolContext; // Only present for MCP tools } /** diff --git a/packages/core/src/scheduler/tool-executor.ts b/packages/core/src/scheduler/tool-executor.ts index 8334168b93..233ff998ff 100644 --- a/packages/core/src/scheduler/tool-executor.ts +++ b/packages/core/src/scheduler/tool-executor.ts @@ -98,6 +98,7 @@ export class ToolExecutor { liveOutputCallback, shellExecutionConfig, setPidCallback, + this.config, ); } else { promise = executeToolWithHooks( @@ -109,6 +110,8 @@ export class ToolExecutor { tool, liveOutputCallback, shellExecutionConfig, + undefined, + this.config, ); } diff --git a/packages/core/src/tools/mcp-tool.ts b/packages/core/src/tools/mcp-tool.ts index 44a07d99e8..8259b6c2f3 100644 --- a/packages/core/src/tools/mcp-tool.ts +++ b/packages/core/src/tools/mcp-tool.ts @@ -59,7 +59,7 @@ type McpContentBlock = | McpResourceBlock | McpResourceLinkBlock; -class DiscoveredMCPToolInvocation extends BaseToolInvocation< +export class DiscoveredMCPToolInvocation extends BaseToolInvocation< ToolParams, ToolResult > { From 02cf264ee10b88e24cef1f2ca01299ed29768cd1 Mon Sep 17 00:00:00 2001 From: kevinjwang1 Date: Thu, 8 Jan 2026 10:37:16 -0800 Subject: [PATCH 063/713] Add extension linking capabilities in cli (#16040) --- .../src/ui/commands/extensionsCommand.test.ts | 97 +++++++++++++++- .../cli/src/ui/commands/extensionsCommand.ts | 105 +++++++++++++++++- 2 files changed, 197 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/ui/commands/extensionsCommand.test.ts b/packages/cli/src/ui/commands/extensionsCommand.test.ts index 4af145b631..55f20eb25d 100644 --- a/packages/cli/src/ui/commands/extensionsCommand.test.ts +++ b/packages/cli/src/ui/commands/extensionsCommand.test.ts @@ -31,6 +31,7 @@ import { inferInstallMetadata, } from '../../config/extension-manager.js'; import { SettingScope } from '../../config/settings.js'; +import { stat } from 'node:fs/promises'; vi.mock('../../config/extension-manager.js', async (importOriginal) => { const actual = @@ -42,11 +43,16 @@ vi.mock('../../config/extension-manager.js', async (importOriginal) => { }); import open from 'open'; +import type { Stats } from 'node:fs'; vi.mock('open', () => ({ default: vi.fn(), })); +vi.mock('node:fs/promises', () => ({ + stat: vi.fn(), +})); + vi.mock('../../config/extensions/update.js', () => ({ updateExtension: vi.fn(), checkForAllExtensionUpdates: vi.fn(), @@ -493,34 +499,37 @@ describe('extensionsCommand', () => { }); describe('when enableExtensionReloading is true', () => { - it('should include enable, disable, install, and uninstall subcommands', () => { + it('should include enable, disable, install, link, and uninstall subcommands', () => { const command = extensionsCommand(true); const subCommandNames = command.subCommands?.map((cmd) => cmd.name); expect(subCommandNames).toContain('enable'); expect(subCommandNames).toContain('disable'); expect(subCommandNames).toContain('install'); + expect(subCommandNames).toContain('link'); expect(subCommandNames).toContain('uninstall'); }); }); describe('when enableExtensionReloading is false', () => { - it('should not include enable, disable, install, and uninstall subcommands', () => { + it('should not include enable, disable, install, link, and uninstall subcommands', () => { const command = extensionsCommand(false); const subCommandNames = command.subCommands?.map((cmd) => cmd.name); expect(subCommandNames).not.toContain('enable'); expect(subCommandNames).not.toContain('disable'); expect(subCommandNames).not.toContain('install'); + expect(subCommandNames).not.toContain('link'); expect(subCommandNames).not.toContain('uninstall'); }); }); describe('when enableExtensionReloading is not provided', () => { - it('should not include enable, disable, install, and uninstall subcommands by default', () => { + it('should not include enable, disable, install, link, and uninstall subcommands by default', () => { const command = extensionsCommand(); const subCommandNames = command.subCommands?.map((cmd) => cmd.name); expect(subCommandNames).not.toContain('enable'); expect(subCommandNames).not.toContain('disable'); expect(subCommandNames).not.toContain('install'); + expect(subCommandNames).not.toContain('link'); expect(subCommandNames).not.toContain('uninstall'); }); }); @@ -617,6 +626,88 @@ describe('extensionsCommand', () => { }); }); + describe('link', () => { + let linkAction: SlashCommand['action']; + + beforeEach(() => { + linkAction = extensionsCommand(true).subCommands?.find( + (cmd) => cmd.name === 'link', + )?.action; + + expect(linkAction).not.toBeNull(); + mockContext.invocation!.name = 'link'; + }); + + it('should show usage if no extension is provided', async () => { + await linkAction!(mockContext, ''); + expect(mockContext.ui.addItem).toHaveBeenCalledWith( + { + type: MessageType.ERROR, + text: 'Usage: /extensions link ', + }, + expect.any(Number), + ); + expect(mockInstallExtension).not.toHaveBeenCalled(); + }); + + it('should call installExtension and show success message', async () => { + const packageName = 'test-extension-package'; + mockInstallExtension.mockResolvedValue({ name: packageName }); + vi.mocked(stat).mockResolvedValue({ + size: 100, + } as Stats); + await linkAction!(mockContext, packageName); + expect(mockInstallExtension).toHaveBeenCalledWith({ + source: packageName, + type: 'link', + }); + expect(mockContext.ui.addItem).toHaveBeenCalledWith( + { + type: MessageType.INFO, + text: `Linking extension from "${packageName}"...`, + }, + expect.any(Number), + ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith( + { + type: MessageType.INFO, + text: `Extension "${packageName}" linked successfully.`, + }, + expect.any(Number), + ); + }); + + it('should show error message on linking failure', async () => { + const packageName = 'test-extension-package'; + const errorMessage = 'link failed'; + mockInstallExtension.mockRejectedValue(new Error(errorMessage)); + vi.mocked(stat).mockResolvedValue({ + size: 100, + } as Stats); + + await linkAction!(mockContext, packageName); + expect(mockInstallExtension).toHaveBeenCalledWith({ + source: packageName, + type: 'link', + }); + expect(mockContext.ui.addItem).toHaveBeenCalledWith( + { + type: MessageType.ERROR, + text: `Failed to link extension from "${packageName}": ${errorMessage}`, + }, + expect.any(Number), + ); + }); + + it('should show error message for invalid source', async () => { + const packageName = 'test-extension-package'; + const errorMessage = 'invalid path'; + vi.mocked(stat).mockRejectedValue(new Error(errorMessage)); + await linkAction!(mockContext, packageName); + expect(mockInstallExtension).not.toHaveBeenCalled(); + }); + }); + describe('uninstall', () => { let uninstallAction: SlashCommand['action']; diff --git a/packages/cli/src/ui/commands/extensionsCommand.ts b/packages/cli/src/ui/commands/extensionsCommand.ts index 99ea05bccf..7c21115880 100644 --- a/packages/cli/src/ui/commands/extensionsCommand.ts +++ b/packages/cli/src/ui/commands/extensionsCommand.ts @@ -4,7 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { debugLogger, listExtensions } from '@google/gemini-cli-core'; +import { + debugLogger, + listExtensions, + type ExtensionInstallMetadata, +} from '@google/gemini-cli-core'; import type { ExtensionUpdateInfo } from '../../config/extension.js'; import { getErrorMessage } from '../../utils/errors.js'; import { @@ -26,6 +30,7 @@ import { } from '../../config/extension-manager.js'; import { SettingScope } from '../../config/settings.js'; import { theme } from '../semantic-colors.js'; +import { stat } from 'node:fs/promises'; function showMessageIfNoExtensions( context: CommandContext, @@ -510,6 +515,88 @@ async function installAction(context: CommandContext, args: string) { } } +async function linkAction(context: CommandContext, args: string) { + const extensionLoader = context.services.config?.getExtensionLoader(); + if (!(extensionLoader instanceof ExtensionManager)) { + debugLogger.error( + `Cannot ${context.invocation?.name} extensions in this environment`, + ); + return; + } + + const sourceFilepath = args.trim(); + if (!sourceFilepath) { + context.ui.addItem( + { + type: MessageType.ERROR, + text: `Usage: /extensions link `, + }, + Date.now(), + ); + return; + } + if (/[;&|`'"]/.test(sourceFilepath)) { + context.ui.addItem( + { + type: MessageType.ERROR, + text: `Source file path contains disallowed characters: ${sourceFilepath}`, + }, + Date.now(), + ); + return; + } + + try { + await stat(sourceFilepath); + } catch (error) { + context.ui.addItem( + { + type: MessageType.ERROR, + text: `Invalid source: ${sourceFilepath}`, + }, + Date.now(), + ); + debugLogger.error( + `Failed to stat path "${sourceFilepath}": ${getErrorMessage(error)}`, + ); + return; + } + + context.ui.addItem( + { + type: MessageType.INFO, + text: `Linking extension from "${sourceFilepath}"...`, + }, + Date.now(), + ); + + try { + const installMetadata: ExtensionInstallMetadata = { + source: sourceFilepath, + type: 'link', + }; + const extension = + await extensionLoader.installOrUpdateExtension(installMetadata); + context.ui.addItem( + { + type: MessageType.INFO, + text: `Extension "${extension.name}" linked successfully.`, + }, + Date.now(), + ); + } catch (error) { + context.ui.addItem( + { + type: MessageType.ERROR, + text: `Failed to link extension from "${sourceFilepath}": ${getErrorMessage( + error, + )}`, + }, + Date.now(), + ); + } +} + async function uninstallAction(context: CommandContext, args: string) { const extensionLoader = context.services.config?.getExtensionLoader(); if (!(extensionLoader instanceof ExtensionManager)) { @@ -645,6 +732,14 @@ const installCommand: SlashCommand = { action: installAction, }; +const linkCommand: SlashCommand = { + name: 'link', + description: 'Link an extension from a local path', + kind: CommandKind.BUILT_IN, + autoExecute: false, + action: linkAction, +}; + const uninstallCommand: SlashCommand = { name: 'uninstall', description: 'Uninstall an extension', @@ -675,7 +770,13 @@ export function extensionsCommand( enableExtensionReloading?: boolean, ): SlashCommand { const conditionalCommands = enableExtensionReloading - ? [disableCommand, enableCommand, installCommand, uninstallCommand] + ? [ + disableCommand, + enableCommand, + installCommand, + uninstallCommand, + linkCommand, + ] : []; return { name: 'extensions', From 76d020511fd4703da0a4a2d166531cc5ae4a97c0 Mon Sep 17 00:00:00 2001 From: Keith Schaab Date: Thu, 8 Jan 2026 10:43:35 -0800 Subject: [PATCH 064/713] Update the page's title to be consistent and show in site. (#16174) --- docs/cli/model-routing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cli/model-routing.md b/docs/cli/model-routing.md index ed5d4eb0bc..15105a4ef8 100644 --- a/docs/cli/model-routing.md +++ b/docs/cli/model-routing.md @@ -1,4 +1,4 @@ -## Model routing +# Model routing Gemini CLI includes a model routing feature that automatically switches to a fallback model in case of a model failure. This feature is enabled by default From ced5110dab1649bfd0ca1199d373ffe805388f47 Mon Sep 17 00:00:00 2001 From: minglu7 <1347866672@qq.com> Date: Fri, 9 Jan 2026 02:59:02 +0800 Subject: [PATCH 065/713] =?UTF-8?q?docs:=20correct=20typo=20in=20bufferFas?= =?UTF-8?q?tReturn=20JSDoc=20("accomodate"=20=E2=86=92=20"accommodate")=20?= =?UTF-8?q?(#16056)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cli/src/ui/contexts/KeypressContext.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/ui/contexts/KeypressContext.tsx b/packages/cli/src/ui/contexts/KeypressContext.tsx index a5ff7e92a2..cd5b6224f0 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.tsx @@ -193,7 +193,7 @@ function bufferBackslashEnter( * Converts return keys pressed quickly after other keys into plain * insertable return characters. * - * This is to accomodate older terminals that paste text without bracketing. + * This is to accommodate older terminals that paste text without bracketing. */ function bufferFastReturn(keypressHandler: KeypressHandler): KeypressHandler { let lastKeyTime = 0; From 75bc41fc20efd8f087a13564df9a2d63ac964ac7 Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Thu, 8 Jan 2026 13:59:23 -0500 Subject: [PATCH 066/713] fix: typo in MCP servers settings description (#15929) --- docs/extensions/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/extensions/index.md b/docs/extensions/index.md index 2d00a4f7d4..25c24c7f21 100644 --- a/docs/extensions/index.md +++ b/docs/extensions/index.md @@ -165,7 +165,7 @@ The file has the following structure: - `version`: The version of the extension. - `mcpServers`: A map of MCP servers to settings. The key is the name of the server, and the value is the server configuration. These servers will be - loaded on startup just like MCP servers settingsd in a + loaded on startup just like MCP servers settings in a [`settings.json` file](../get-started/configuration.md). If both an extension and a `settings.json` file settings an MCP server with the same name, the server defined in the `settings.json` file takes precedence. From 1a4ae413978cb2a55029279669c03243e1bfdd94 Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Thu, 8 Jan 2026 14:24:51 -0500 Subject: [PATCH 067/713] fix: yolo should auto allow redirection (#16183) --- packages/core/src/policy/policies/yolo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/policy/policies/yolo.toml b/packages/core/src/policy/policies/yolo.toml index 0c5f9e9221..052ca6c4d3 100644 --- a/packages/core/src/policy/policies/yolo.toml +++ b/packages/core/src/policy/policies/yolo.toml @@ -29,3 +29,4 @@ decision = "allow" priority = 999 modes = ["yolo"] +allow_redirection = true From f8138262fa7cc5e6c2f8f5af8baff2efcd4888e1 Mon Sep 17 00:00:00 2001 From: Pyush Sinha Date: Thu, 8 Jan 2026 11:48:03 -0800 Subject: [PATCH 068/713] fix(cli): disableYoloMode shouldn't enforce default approval mode against args (#16155) --- packages/cli/src/config/config.test.ts | 39 ++++++++++++++++++++++++++ packages/cli/src/config/config.ts | 1 - 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/config/config.test.ts b/packages/cli/src/config/config.test.ts index 465ed90bca..d3040aabf0 100644 --- a/packages/cli/src/config/config.test.ts +++ b/packages/cli/src/config/config.test.ts @@ -2413,6 +2413,45 @@ describe('Policy Engine Integration in loadCliConfig', () => { }); }); +describe('loadCliConfig disableYoloMode', () => { + beforeEach(() => { + vi.resetAllMocks(); + vi.mocked(os.homedir).mockReturnValue('/mock/home/user'); + vi.stubEnv('GEMINI_API_KEY', 'test-api-key'); + vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([]); + vi.mocked(isWorkspaceTrusted).mockReturnValue({ + isTrusted: true, + source: undefined, + }); + }); + + afterEach(() => { + vi.unstubAllEnvs(); + vi.restoreAllMocks(); + }); + + it('should allow auto_edit mode even if yolo mode is disabled', async () => { + process.argv = ['node', 'script.js', '--approval-mode=auto_edit']; + const argv = await parseArguments({} as Settings); + const settings: Settings = { + security: { disableYoloMode: true }, + }; + const config = await loadCliConfig(settings, 'test-session', argv); + expect(config.getApprovalMode()).toBe(ApprovalMode.AUTO_EDIT); + }); + + it('should throw if YOLO mode is attempted when disableYoloMode is true', async () => { + process.argv = ['node', 'script.js', '--yolo']; + const argv = await parseArguments({} as Settings); + const settings: Settings = { + security: { disableYoloMode: true }, + }; + await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow( + 'Cannot start in YOLO mode since it is disabled by your admin', + ); + }); +}); + describe('loadCliConfig secureModeEnabled', () => { beforeEach(() => { vi.resetAllMocks(); diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 7ca8d2934d..bc185ffdf8 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -520,7 +520,6 @@ export async function loadCliConfig( 'Cannot start in YOLO mode since it is disabled by your admin', ); } - approvalMode = ApprovalMode.DEFAULT; } else if (approvalMode === ApprovalMode.YOLO) { debugLogger.warn( 'YOLO mode is enabled. All tool calls will be automatically approved.', From fbfad06307c7292287333c380005d9c5ce2f39e2 Mon Sep 17 00:00:00 2001 From: phreakocious Date: Thu, 8 Jan 2026 13:49:05 -0600 Subject: [PATCH 069/713] feat: add native Sublime Text support to IDE detection (#16083) Co-authored-by: phreakocious <567063+phreakocious@users.noreply.github.com> --- packages/core/src/ide/detect-ide.test.ts | 12 ++++++++++++ packages/core/src/ide/detect-ide.ts | 11 +++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/core/src/ide/detect-ide.test.ts b/packages/core/src/ide/detect-ide.test.ts index ebeb522933..6cab76e07d 100644 --- a/packages/core/src/ide/detect-ide.test.ts +++ b/packages/core/src/ide/detect-ide.test.ts @@ -114,6 +114,18 @@ describe('detectIde', () => { vi.stubEnv('ANTIGRAVITY_CLI_ALIAS', 'agy'); expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.antigravity); }); + + it('should detect Sublime Text', () => { + vi.stubEnv('TERM_PROGRAM', 'sublime'); + vi.stubEnv('ANTIGRAVITY_CLI_ALIAS', ''); + expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.sublimetext); + }); + + it('should prioritize Antigravity over Sublime Text', () => { + vi.stubEnv('TERM_PROGRAM', 'sublime'); + vi.stubEnv('ANTIGRAVITY_CLI_ALIAS', 'agy'); + expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.antigravity); + }); }); describe('detectIde with ideInfoFromFile', () => { diff --git a/packages/core/src/ide/detect-ide.ts b/packages/core/src/ide/detect-ide.ts index c7945593b2..0939af6b79 100644 --- a/packages/core/src/ide/detect-ide.ts +++ b/packages/core/src/ide/detect-ide.ts @@ -15,6 +15,7 @@ export const IDE_DEFINITIONS = { vscode: { name: 'vscode', displayName: 'VS Code' }, vscodefork: { name: 'vscodefork', displayName: 'IDE' }, antigravity: { name: 'antigravity', displayName: 'Antigravity' }, + sublimetext: { name: 'sublimetext', displayName: 'Sublime Text' }, } as const; export interface IdeInfo { @@ -51,6 +52,9 @@ export function detectIdeFromEnv(): IdeInfo { if (process.env['MONOSPACE_ENV']) { return IDE_DEFINITIONS.firebasestudio; } + if (process.env['TERM_PROGRAM'] === 'sublime') { + return IDE_DEFINITIONS.sublimetext; + } return IDE_DEFINITIONS.vscode; } @@ -87,8 +91,11 @@ export function detectIde( }; } - // Only VSCode-based integrations are currently supported. - if (process.env['TERM_PROGRAM'] !== 'vscode') { + // Only VS Code and Sublime Text integrations are currently supported. + if ( + process.env['TERM_PROGRAM'] !== 'vscode' && + process.env['TERM_PROGRAM'] !== 'sublime' + ) { return undefined; } From 16da6918cb56b04141583ad7253270afc7a77e34 Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Thu, 8 Jan 2026 14:52:56 -0500 Subject: [PATCH 070/713] refactor(core): extract ToolModificationHandler from scheduler (#16118) --- .../core/src/core/coreToolScheduler.test.ts | 11 + packages/core/src/core/coreToolScheduler.ts | 121 +++------ .../core/src/scheduler/tool-modifier.test.ts | 252 ++++++++++++++++++ packages/core/src/scheduler/tool-modifier.ts | 105 ++++++++ packages/core/src/utils/editor.test.ts | 13 +- packages/core/src/utils/editor.ts | 13 +- 6 files changed, 427 insertions(+), 88 deletions(-) create mode 100644 packages/core/src/scheduler/tool-modifier.test.ts create mode 100644 packages/core/src/scheduler/tool-modifier.ts diff --git a/packages/core/src/core/coreToolScheduler.test.ts b/packages/core/src/core/coreToolScheduler.test.ts index 22ef939a62..9cfacc2358 100644 --- a/packages/core/src/core/coreToolScheduler.test.ts +++ b/packages/core/src/core/coreToolScheduler.test.ts @@ -750,6 +750,17 @@ describe('CoreToolScheduler with payload', () => { ); } + // After internal update, the tool should be awaiting approval again with the NEW content. + const updatedAwaitingCall = (await waitForStatus( + onToolCallsUpdate, + 'awaiting_approval', + )) as WaitingToolCall; + + // Now confirm for real to execute. + await updatedAwaitingCall.confirmationDetails.onConfirm( + ToolConfirmationOutcome.ProceedOnce, + ); + // Wait for the tool execution to complete await vi.waitFor(() => { expect(onAllToolCallsComplete).toHaveBeenCalled(); diff --git a/packages/core/src/core/coreToolScheduler.ts b/packages/core/src/core/coreToolScheduler.ts index 1120074248..bec4eacd53 100644 --- a/packages/core/src/core/coreToolScheduler.ts +++ b/packages/core/src/core/coreToolScheduler.ts @@ -19,12 +19,7 @@ import { logToolCall } from '../telemetry/loggers.js'; import { ToolErrorType } from '../tools/tool-error.js'; import { ToolCallEvent } from '../telemetry/types.js'; import { runInDevTraceSpan } from '../telemetry/trace.js'; -import type { ModifyContext } from '../tools/modifiable-tool.js'; -import { - isModifiableDeclarativeTool, - modifyWithEditor, -} from '../tools/modifiable-tool.js'; -import * as Diff from 'diff'; +import { ToolModificationHandler } from '../scheduler/tool-modifier.js'; import { getToolSuggestion } from '../utils/tool-utils.js'; import type { ToolConfirmationRequest } from '../confirmation-bus/types.js'; import { MessageBusType } from '../confirmation-bus/types.js'; @@ -124,6 +119,7 @@ export class CoreToolScheduler { private toolCallQueue: ToolCall[] = []; private completedToolCallsForBatch: CompletedToolCall[] = []; private toolExecutor: ToolExecutor; + private toolModifier: ToolModificationHandler; constructor(options: CoreToolSchedulerOptions) { this.config = options.config; @@ -132,6 +128,7 @@ export class CoreToolScheduler { this.onToolCallsUpdate = options.onToolCallsUpdate; this.getPreferredEditor = options.getPreferredEditor; this.toolExecutor = new ToolExecutor(this.config); + this.toolModifier = new ToolModificationHandler(); // Subscribe to message bus for ASK_USER policy decisions // Use a static WeakMap to ensure we only subscribe ONCE per MessageBus instance @@ -749,105 +746,61 @@ export class CoreToolScheduler { return; // `cancelAll` calls `checkAndNotifyCompletion`, so we can exit here. } else if (outcome === ToolConfirmationOutcome.ModifyWithEditor) { const waitingToolCall = toolCall as WaitingToolCall; - if (isModifiableDeclarativeTool(waitingToolCall.tool)) { - const modifyContext = waitingToolCall.tool.getModifyContext(signal); - const editorType = this.getPreferredEditor(); - if (!editorType) { - return; - } + const editorType = this.getPreferredEditor(); + if (!editorType) { + return; + } + + this.setStatusInternal(callId, 'awaiting_approval', signal, { + ...waitingToolCall.confirmationDetails, + isModifying: true, + } as ToolCallConfirmationDetails); + + const result = await this.toolModifier.handleModifyWithEditor( + waitingToolCall, + editorType, + signal, + ); + + // Restore status (isModifying: false) and update diff if result exists + if (result) { + this.setArgsInternal(callId, result.updatedParams); this.setStatusInternal(callId, 'awaiting_approval', signal, { ...waitingToolCall.confirmationDetails, - isModifying: true, + fileDiff: result.updatedDiff, + isModifying: false, } as ToolCallConfirmationDetails); - - const contentOverrides = - waitingToolCall.confirmationDetails.type === 'edit' - ? { - currentContent: - waitingToolCall.confirmationDetails.originalContent, - proposedContent: waitingToolCall.confirmationDetails.newContent, - } - : undefined; - - const { updatedParams, updatedDiff } = await modifyWithEditor< - typeof waitingToolCall.request.args - >( - waitingToolCall.request.args, - modifyContext as ModifyContext, - editorType, - signal, - contentOverrides, - ); - this.setArgsInternal(callId, updatedParams); + } else { this.setStatusInternal(callId, 'awaiting_approval', signal, { ...waitingToolCall.confirmationDetails, - fileDiff: updatedDiff, isModifying: false, } as ToolCallConfirmationDetails); } } else { - // If the client provided new content, apply it before scheduling. + // If the client provided new content, apply it and wait for + // re-confirmation. if (payload?.newContent && toolCall) { - await this._applyInlineModify( + const result = await this.toolModifier.applyInlineModify( toolCall as WaitingToolCall, payload, signal, ); + if (result) { + this.setArgsInternal(callId, result.updatedParams); + this.setStatusInternal(callId, 'awaiting_approval', signal, { + ...(toolCall as WaitingToolCall).confirmationDetails, + fileDiff: result.updatedDiff, + } as ToolCallConfirmationDetails); + // After an inline modification, wait for another user confirmation. + return; + } } this.setStatusInternal(callId, 'scheduled', signal); } await this.attemptExecutionOfScheduledCalls(signal); } - /** - * Applies user-provided content changes to a tool call that is awaiting confirmation. - * This method updates the tool's arguments and refreshes the confirmation prompt with a new diff - * before the tool is scheduled for execution. - * @private - */ - private async _applyInlineModify( - toolCall: WaitingToolCall, - payload: ToolConfirmationPayload, - signal: AbortSignal, - ): Promise { - if ( - toolCall.confirmationDetails.type !== 'edit' || - !isModifiableDeclarativeTool(toolCall.tool) - ) { - return; - } - - const modifyContext = toolCall.tool.getModifyContext(signal); - const currentContent = await modifyContext.getCurrentContent( - toolCall.request.args, - ); - - const updatedParams = modifyContext.createUpdatedParams( - currentContent, - payload.newContent, - toolCall.request.args, - ); - const updatedDiff = Diff.createPatch( - modifyContext.getFilePath(toolCall.request.args), - currentContent, - payload.newContent, - 'Current', - 'Proposed', - ); - - this.setArgsInternal(toolCall.request.callId, updatedParams); - this.setStatusInternal( - toolCall.request.callId, - 'awaiting_approval', - signal, - { - ...toolCall.confirmationDetails, - fileDiff: updatedDiff, - }, - ); - } - private async attemptExecutionOfScheduledCalls( signal: AbortSignal, ): Promise { diff --git a/packages/core/src/scheduler/tool-modifier.test.ts b/packages/core/src/scheduler/tool-modifier.test.ts new file mode 100644 index 0000000000..8107e4c901 --- /dev/null +++ b/packages/core/src/scheduler/tool-modifier.test.ts @@ -0,0 +1,252 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { ToolModificationHandler } from './tool-modifier.js'; +import type { WaitingToolCall, ToolCallRequestInfo } from './types.js'; +import * as modifiableToolModule from '../tools/modifiable-tool.js'; +import * as Diff from 'diff'; +import { MockModifiableTool, MockTool } from '../test-utils/mock-tool.js'; +import type { + ToolResult, + ToolInvocation, + ToolConfirmationPayload, +} from '../tools/tools.js'; +import type { ModifyContext } from '../tools/modifiable-tool.js'; +import type { Mock } from 'vitest'; + +// Mock the modules that export functions we need to control +vi.mock('diff', () => ({ + createPatch: vi.fn(), + diffLines: vi.fn(), +})); + +vi.mock('../tools/modifiable-tool.js', () => ({ + isModifiableDeclarativeTool: vi.fn(), + modifyWithEditor: vi.fn(), +})); + +type MockModifyContext = { + [K in keyof ModifyContext>]: Mock; +}; + +function createMockWaitingToolCall( + overrides: Partial = {}, +): WaitingToolCall { + return { + status: 'awaiting_approval', + request: { + callId: 'test-call-id', + name: 'test-tool', + args: {}, + isClientInitiated: false, + prompt_id: 'test-prompt-id', + } as ToolCallRequestInfo, + tool: new MockTool({ name: 'test-tool' }), + invocation: {} as ToolInvocation, ToolResult>, // We generally don't check invocation details in these tests + confirmationDetails: { + type: 'edit', + title: 'Test Confirmation', + fileName: 'test.txt', + filePath: '/path/to/test.txt', + fileDiff: 'diff', + originalContent: 'original', + newContent: 'new', + onConfirm: async () => {}, + }, + ...overrides, + }; +} + +describe('ToolModificationHandler', () => { + let handler: ToolModificationHandler; + let mockModifiableTool: MockModifiableTool; + let mockPlainTool: MockTool; + let mockModifyContext: MockModifyContext; + + beforeEach(() => { + vi.clearAllMocks(); + handler = new ToolModificationHandler(); + mockModifiableTool = new MockModifiableTool(); + mockPlainTool = new MockTool({ name: 'plainTool' }); + + mockModifyContext = { + getCurrentContent: vi.fn(), + getFilePath: vi.fn(), + createUpdatedParams: vi.fn(), + getProposedContent: vi.fn(), + }; + + vi.spyOn(mockModifiableTool, 'getModifyContext').mockReturnValue( + mockModifyContext as unknown as ModifyContext>, + ); + }); + + describe('handleModifyWithEditor', () => { + it('should return undefined if tool is not modifiable', async () => { + vi.mocked( + modifiableToolModule.isModifiableDeclarativeTool, + ).mockReturnValue(false); + + const mockWaitingToolCall = createMockWaitingToolCall({ + tool: mockPlainTool, + request: { + callId: 'call-1', + name: 'plainTool', + args: { path: 'foo.txt' }, + isClientInitiated: false, + prompt_id: 'p1', + }, + }); + + const result = await handler.handleModifyWithEditor( + mockWaitingToolCall, + 'vscode', + new AbortController().signal, + ); + + expect(result).toBeUndefined(); + }); + + it('should call modifyWithEditor and return updated params', async () => { + vi.mocked( + modifiableToolModule.isModifiableDeclarativeTool, + ).mockReturnValue(true); + + vi.mocked(modifiableToolModule.modifyWithEditor).mockResolvedValue({ + updatedParams: { path: 'foo.txt', content: 'new' }, + updatedDiff: 'diff', + }); + + const mockWaitingToolCall = createMockWaitingToolCall({ + tool: mockModifiableTool, + request: { + callId: 'call-1', + name: 'mockModifiableTool', + args: { path: 'foo.txt' }, + isClientInitiated: false, + prompt_id: 'p1', + }, + confirmationDetails: { + type: 'edit', + title: 'Confirm', + fileName: 'foo.txt', + filePath: 'foo.txt', + fileDiff: 'diff', + originalContent: 'old', + newContent: 'new', + onConfirm: async () => {}, + }, + }); + + const result = await handler.handleModifyWithEditor( + mockWaitingToolCall, + 'vscode', + new AbortController().signal, + ); + + expect(modifiableToolModule.modifyWithEditor).toHaveBeenCalledWith( + mockWaitingToolCall.request.args, + mockModifyContext, + 'vscode', + expect.any(AbortSignal), + { currentContent: 'old', proposedContent: 'new' }, + ); + + expect(result).toEqual({ + updatedParams: { path: 'foo.txt', content: 'new' }, + updatedDiff: 'diff', + }); + }); + }); + + describe('applyInlineModify', () => { + it('should return undefined if tool is not modifiable', async () => { + vi.mocked( + modifiableToolModule.isModifiableDeclarativeTool, + ).mockReturnValue(false); + + const mockWaitingToolCall = createMockWaitingToolCall({ + tool: mockPlainTool, + }); + + const result = await handler.applyInlineModify( + mockWaitingToolCall, + { newContent: 'foo' }, + new AbortController().signal, + ); + + expect(result).toBeUndefined(); + }); + + it('should return undefined if payload has no new content', async () => { + vi.mocked( + modifiableToolModule.isModifiableDeclarativeTool, + ).mockReturnValue(true); + + const mockWaitingToolCall = createMockWaitingToolCall({ + tool: mockModifiableTool, + }); + + const result = await handler.applyInlineModify( + mockWaitingToolCall, + { newContent: undefined } as unknown as ToolConfirmationPayload, + new AbortController().signal, + ); + + expect(result).toBeUndefined(); + }); + + it('should calculate diff and return updated params', async () => { + vi.mocked( + modifiableToolModule.isModifiableDeclarativeTool, + ).mockReturnValue(true); + (Diff.createPatch as unknown as Mock).mockReturnValue('mock-diff'); + + mockModifyContext.getCurrentContent.mockResolvedValue('old content'); + mockModifyContext.getFilePath.mockReturnValue('test.txt'); + mockModifyContext.createUpdatedParams.mockReturnValue({ + content: 'new content', + }); + + const mockWaitingToolCall = createMockWaitingToolCall({ + tool: mockModifiableTool, + request: { + callId: 'call-1', + name: 'mockModifiableTool', + args: { content: 'original' }, + isClientInitiated: false, + prompt_id: 'p1', + }, + }); + + const result = await handler.applyInlineModify( + mockWaitingToolCall, + { newContent: 'new content' }, + new AbortController().signal, + ); + + expect(mockModifyContext.getCurrentContent).toHaveBeenCalled(); + expect(mockModifyContext.createUpdatedParams).toHaveBeenCalledWith( + 'old content', + 'new content', + { content: 'original' }, + ); + expect(Diff.createPatch).toHaveBeenCalledWith( + 'test.txt', + 'old content', + 'new content', + 'Current', + 'Proposed', + ); + + expect(result).toEqual({ + updatedParams: { content: 'new content' }, + updatedDiff: 'mock-diff', + }); + }); + }); +}); diff --git a/packages/core/src/scheduler/tool-modifier.ts b/packages/core/src/scheduler/tool-modifier.ts new file mode 100644 index 0000000000..c7d9c93c67 --- /dev/null +++ b/packages/core/src/scheduler/tool-modifier.ts @@ -0,0 +1,105 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import * as Diff from 'diff'; +import type { EditorType } from '../utils/editor.js'; +import { + isModifiableDeclarativeTool, + modifyWithEditor, + type ModifyContext, +} from '../tools/modifiable-tool.js'; +import type { ToolConfirmationPayload } from '../tools/tools.js'; +import type { WaitingToolCall } from './types.js'; + +export interface ModificationResult { + updatedParams: Record; + updatedDiff?: string; +} + +export class ToolModificationHandler { + /** + * Handles the "Modify with Editor" flow where an external editor is launched + * to modify the tool's parameters. + */ + async handleModifyWithEditor( + toolCall: WaitingToolCall, + editorType: EditorType, + signal: AbortSignal, + ): Promise { + if (!isModifiableDeclarativeTool(toolCall.tool)) { + return undefined; + } + + const confirmationDetails = toolCall.confirmationDetails; + const modifyContext = toolCall.tool.getModifyContext(signal); + + const contentOverrides = + confirmationDetails.type === 'edit' + ? { + currentContent: confirmationDetails.originalContent, + proposedContent: confirmationDetails.newContent, + } + : undefined; + + const { updatedParams, updatedDiff } = await modifyWithEditor< + typeof toolCall.request.args + >( + toolCall.request.args, + modifyContext as ModifyContext, + editorType, + signal, + contentOverrides, + ); + + return { + updatedParams, + updatedDiff, + }; + } + + /** + * Applies user-provided inline content updates (e.g. from the chat UI). + */ + async applyInlineModify( + toolCall: WaitingToolCall, + payload: ToolConfirmationPayload, + signal: AbortSignal, + ): Promise { + if ( + toolCall.confirmationDetails.type !== 'edit' || + !payload.newContent || + !isModifiableDeclarativeTool(toolCall.tool) + ) { + return undefined; + } + + const modifyContext = toolCall.tool.getModifyContext( + signal, + ) as ModifyContext; + const currentContent = await modifyContext.getCurrentContent( + toolCall.request.args, + ); + + const updatedParams = modifyContext.createUpdatedParams( + currentContent, + payload.newContent, + toolCall.request.args, + ); + + const updatedDiff = Diff.createPatch( + modifyContext.getFilePath(toolCall.request.args), + currentContent, + payload.newContent, + 'Current', + 'Proposed', + ); + + return { + updatedParams, + updatedDiff, + }; + } +} diff --git a/packages/core/src/utils/editor.test.ts b/packages/core/src/utils/editor.test.ts index 82b886f366..78035c4cc9 100644 --- a/packages/core/src/utils/editor.test.ts +++ b/packages/core/src/utils/editor.test.ts @@ -311,11 +311,18 @@ describe('editor utils', () => { }); } - it('should return the correct command for emacs', () => { - const command = getDiffCommand('old.txt', 'new.txt', 'emacs'); + it('should return the correct command for emacs with escaped paths', () => { + const command = getDiffCommand( + 'old file "quote".txt', + 'new file \\back\\slash.txt', + 'emacs', + ); expect(command).toEqual({ command: 'emacs', - args: ['--eval', '(ediff "old.txt" "new.txt")'], + args: [ + '--eval', + '(ediff "old file \\"quote\\".txt" "new file \\\\back\\\\slash.txt")', + ], }); }); diff --git a/packages/core/src/utils/editor.ts b/packages/core/src/utils/editor.ts index b71a0b23eb..742d1157fb 100644 --- a/packages/core/src/utils/editor.ts +++ b/packages/core/src/utils/editor.ts @@ -60,6 +60,14 @@ function isValidEditorType(editor: string): editor is EditorType { return EDITORS_SET.has(editor); } +/** + * Escapes a string for use in an Emacs Lisp string literal. + * Wraps in double quotes and escapes backslashes and double quotes. + */ +function escapeELispString(str: string): string { + return `"${str.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`; +} + interface DiffCommand { command: string; args: string[]; @@ -182,7 +190,10 @@ export function getDiffCommand( case 'emacs': return { command: 'emacs', - args: ['--eval', `(ediff "${oldPath}" "${newPath}")`], + args: [ + '--eval', + `(ediff ${escapeELispString(oldPath)} ${escapeELispString(newPath)})`, + ], }; case 'hx': return { From 01d2d4373721415cb4a9cd8a1bbe055e3beeb145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20L=C3=B3pez=20Almeida?= Date: Thu, 8 Jan 2026 13:08:30 -0700 Subject: [PATCH 071/713] Add support for Antigravity terminal in terminal setup utility (#16051) Co-authored-by: Jacob Richman --- packages/cli/src/ui/utils/terminalSetup.ts | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/ui/utils/terminalSetup.ts b/packages/cli/src/ui/utils/terminalSetup.ts index 9fb81099bb..ede409dd49 100644 --- a/packages/cli/src/ui/utils/terminalSetup.ts +++ b/packages/cli/src/ui/utils/terminalSetup.ts @@ -14,6 +14,7 @@ * - VS Code: Configures keybindings.json to send \\\r\n * - Cursor: Configures keybindings.json to send \\\r\n (VS Code fork) * - Windsurf: Configures keybindings.json to send \\\r\n (VS Code fork) + * - Antigravity: Configures keybindings.json to send \\\r\n (VS Code fork) * * For VS Code and its forks: * - Shift+Enter: Sends \\\r\n (backslash followed by CRLF) @@ -51,7 +52,7 @@ export interface TerminalSetupResult { requiresRestart?: boolean; } -type SupportedTerminal = 'vscode' | 'cursor' | 'windsurf'; +type SupportedTerminal = 'vscode' | 'cursor' | 'windsurf' | 'antigravity'; export function getTerminalProgram(): SupportedTerminal | null { const termProgram = process.env['TERM_PROGRAM']; @@ -70,6 +71,14 @@ export function getTerminalProgram(): SupportedTerminal | null { ) { return 'windsurf'; } + // Check for Antigravity-specific indicators + if ( + process.env['VSCODE_GIT_ASKPASS_MAIN'] + ?.toLowerCase() + .includes('antigravity') + ) { + return 'antigravity'; + } // Check VS Code last since forks may also set VSCODE env vars if (termProgram === 'vscode' || process.env['VSCODE_GIT_IPC_HANDLE']) { return 'vscode'; @@ -93,6 +102,11 @@ async function detectTerminal(): Promise { // Check forks before VS Code to avoid false positives if (parentName.includes('windsurf') || parentName.includes('Windsurf')) return 'windsurf'; + if ( + parentName.includes('antigravity') || + parentName.includes('Antigravity') + ) + return 'antigravity'; if (parentName.includes('cursor') || parentName.includes('Cursor')) return 'cursor'; if (parentName.includes('code') || parentName.includes('Code')) @@ -302,6 +316,10 @@ async function configureWindsurf(): Promise { return configureVSCodeStyle('Windsurf', 'Windsurf'); } +async function configureAntigravity(): Promise { + return configureVSCodeStyle('Antigravity', 'Antigravity'); +} + /** * Main terminal setup function that detects and configures the current terminal. * @@ -337,7 +355,7 @@ export async function terminalSetup(): Promise { return { success: false, message: - 'Could not detect terminal type. Supported terminals: VS Code, Cursor, and Windsurf.', + 'Could not detect terminal type. Supported terminals: VS Code, Cursor, Windsurf, and Antigravity.', }; } @@ -348,6 +366,8 @@ export async function terminalSetup(): Promise { return configureCursor(); case 'windsurf': return configureWindsurf(); + case 'antigravity': + return configureAntigravity(); default: return { success: false, From 41a8809280f844870600f63a4beea4c0bd585d8e Mon Sep 17 00:00:00 2001 From: joshualitt Date: Thu, 8 Jan 2026 12:39:40 -0800 Subject: [PATCH 072/713] feat(core): Wire up model routing to subagents. (#16043) --- .../core/src/agents/local-executor.test.ts | 101 +++++++++++++++++- packages/core/src/agents/local-executor.ts | 39 ++++++- packages/core/src/agents/registry.test.ts | 45 ++++++++ packages/core/src/agents/registry.ts | 42 +++++--- 4 files changed, 211 insertions(+), 16 deletions(-) diff --git a/packages/core/src/agents/local-executor.test.ts b/packages/core/src/agents/local-executor.test.ts index 98d017c864..a0a8a513f2 100644 --- a/packages/core/src/agents/local-executor.test.ts +++ b/packages/core/src/agents/local-executor.test.ts @@ -57,8 +57,12 @@ import { AgentTerminateMode } from './types.js'; import type { AnyDeclarativeTool, AnyToolInvocation } from '../tools/tools.js'; import { CompressionStatus } from '../core/turn.js'; import { ChatCompressionService } from '../services/chatCompressionService.js'; -import type { ModelConfigKey } from '../services/modelConfigService.js'; +import type { + ModelConfigKey, + ResolvedModelConfig, +} from '../services/modelConfigService.js'; import { getModelConfigAlias } from './registry.js'; +import type { ModelRouterService } from '../routing/modelRouterService.js'; const { mockSendMessageStream, @@ -1192,6 +1196,101 @@ describe('LocalAgentExecutor', () => { }); }); + describe('Model Routing', () => { + it('should use model routing when the agent model is "auto"', async () => { + const definition = createTestDefinition(); + definition.modelConfig.model = 'auto'; + + const mockRouter = { + route: vi.fn().mockResolvedValue({ + model: 'routed-model', + metadata: { source: 'test', reasoning: 'test' }, + }), + }; + vi.spyOn(mockConfig, 'getModelRouterService').mockReturnValue( + mockRouter as unknown as ModelRouterService, + ); + + // Mock resolved config to return 'auto' + vi.spyOn( + mockConfig.modelConfigService, + 'getResolvedConfig', + ).mockReturnValue({ + model: 'auto', + generateContentConfig: {}, + } as unknown as ResolvedModelConfig); + + const executor = await LocalAgentExecutor.create( + definition, + mockConfig, + onActivity, + ); + + mockModelResponse([ + { + name: TASK_COMPLETE_TOOL_NAME, + args: { finalResult: 'done' }, + id: 'call1', + }, + ]); + + await executor.run({ goal: 'test' }, signal); + + expect(mockRouter.route).toHaveBeenCalled(); + expect(mockSendMessageStream).toHaveBeenCalledWith( + expect.objectContaining({ model: 'routed-model' }), + expect.any(Array), + expect.any(String), + expect.any(AbortSignal), + ); + }); + + it('should NOT use model routing when the agent model is NOT "auto"', async () => { + const definition = createTestDefinition(); + definition.modelConfig.model = 'concrete-model'; + + const mockRouter = { + route: vi.fn(), + }; + vi.spyOn(mockConfig, 'getModelRouterService').mockReturnValue( + mockRouter as unknown as ModelRouterService, + ); + + // Mock resolved config to return 'concrete-model' + vi.spyOn( + mockConfig.modelConfigService, + 'getResolvedConfig', + ).mockReturnValue({ + model: 'concrete-model', + generateContentConfig: {}, + } as unknown as ResolvedModelConfig); + + const executor = await LocalAgentExecutor.create( + definition, + mockConfig, + onActivity, + ); + + mockModelResponse([ + { + name: TASK_COMPLETE_TOOL_NAME, + args: { finalResult: 'done' }, + id: 'call1', + }, + ]); + + await executor.run({ goal: 'test' }, signal); + + expect(mockRouter.route).not.toHaveBeenCalled(); + expect(mockSendMessageStream).toHaveBeenCalledWith( + expect.objectContaining({ model: 'concrete-model' }), + expect.any(Array), + expect.any(String), + expect.any(AbortSignal), + ); + }); + }); + describe('run (Termination Conditions)', () => { const mockWorkResponse = (id: string) => { mockModelResponse([{ name: LS_TOOL_NAME, args: { path: '.' }, id }]); diff --git a/packages/core/src/agents/local-executor.ts b/packages/core/src/agents/local-executor.ts index 994c616594..fc866c97b5 100644 --- a/packages/core/src/agents/local-executor.ts +++ b/packages/core/src/agents/local-executor.ts @@ -40,6 +40,8 @@ import type { } from './types.js'; import { AgentTerminateMode } from './types.js'; import { templateString } from './utils.js'; +import { DEFAULT_GEMINI_MODEL, isAutoModel } from '../config/models.js'; +import type { RoutingContext } from '../routing/routingStrategy.js'; import { parseThought } from '../utils/thoughtUtils.js'; import { type z } from 'zod'; import { zodToJsonSchema } from 'zod-to-json-schema'; @@ -589,9 +591,44 @@ export class LocalAgentExecutor { signal: AbortSignal, promptId: string, ): Promise<{ functionCalls: FunctionCall[]; textResponse: string }> { + const modelConfigAlias = getModelConfigAlias(this.definition); + + // Resolve the model config early to get the concrete model string (which may be `auto`). + const resolvedConfig = + this.runtimeContext.modelConfigService.getResolvedConfig({ + model: modelConfigAlias, + overrideScope: this.definition.name, + }); + const requestedModel = resolvedConfig.model; + + let modelToUse: string; + if (isAutoModel(requestedModel)) { + // TODO(joshualitt): This try / catch is inconsistent with the routing + // behavior for the main agent. Ideally, we would have a universal + // policy for routing failure. Given routing failure does not necessarily + // mean generation will fail, we may want to share this logic with + // other places we use model routing. + try { + const routingContext: RoutingContext = { + history: chat.getHistory(/*curated=*/ true), + request: message.parts || [], + signal, + requestedModel, + }; + const router = this.runtimeContext.getModelRouterService(); + const decision = await router.route(routingContext); + modelToUse = decision.model; + } catch (error) { + debugLogger.warn(`Error during model routing: ${error}`); + modelToUse = DEFAULT_GEMINI_MODEL; + } + } else { + modelToUse = requestedModel; + } + const responseStream = await chat.sendMessageStream( { - model: getModelConfigAlias(this.definition), + model: modelToUse, overrideScope: this.definition.name, }, message.parts || [], diff --git a/packages/core/src/agents/registry.test.ts b/packages/core/src/agents/registry.test.ts index 4864566bc0..84a9001a03 100644 --- a/packages/core/src/agents/registry.test.ts +++ b/packages/core/src/agents/registry.test.ts @@ -243,6 +243,51 @@ describe('AgentRegistry', () => { }); describe('registration logic', () => { + it('should register runtime overrides when the model is "auto"', async () => { + const autoAgent: LocalAgentDefinition = { + ...MOCK_AGENT_V1, + name: 'AutoAgent', + modelConfig: { ...MOCK_AGENT_V1.modelConfig, model: 'auto' }, + }; + + const registerOverrideSpy = vi.spyOn( + mockConfig.modelConfigService, + 'registerRuntimeModelOverride', + ); + + await registry.testRegisterAgent(autoAgent); + + // Should register one alias for the custom model config. + expect( + mockConfig.modelConfigService.getResolvedConfig({ + model: getModelConfigAlias(autoAgent), + }), + ).toStrictEqual({ + model: 'auto', + generateContentConfig: { + temperature: autoAgent.modelConfig.temp, + topP: autoAgent.modelConfig.top_p, + thinkingConfig: { + includeThoughts: true, + thinkingBudget: -1, + }, + }, + }); + + // Should register one override for the agent name (scope) + expect(registerOverrideSpy).toHaveBeenCalledTimes(1); + + // Check scope override + expect(registerOverrideSpy).toHaveBeenCalledWith( + expect.objectContaining({ + match: { overrideScope: autoAgent.name }, + modelConfig: expect.objectContaining({ + generateContentConfig: expect.any(Object), + }), + }), + ); + }); + it('should register a valid agent definition', async () => { await registry.testRegisterAgent(MOCK_AGENT_V1); expect(registry.getDefinition('MockAgent')).toEqual(MOCK_AGENT_V1); diff --git a/packages/core/src/agents/registry.ts b/packages/core/src/agents/registry.ts index 13f203d7d1..ee42795a66 100644 --- a/packages/core/src/agents/registry.ts +++ b/packages/core/src/agents/registry.ts @@ -20,8 +20,8 @@ import { GEMINI_MODEL_ALIAS_AUTO, PREVIEW_GEMINI_FLASH_MODEL, isPreviewModel, + isAutoModel, } from '../config/models.js'; -import type { ModelConfigAlias } from '../services/modelConfigService.js'; /** * Returns the model config alias for a given agent definition. @@ -199,7 +199,10 @@ export class AgentRegistry { this.agents.set(definition.name, definition); - // Register model config. + // Register model config. We always create a runtime alias. However, + // if the user is using `auto` as a model string then we also create + // runtime overrides to ensure the subagent generation settings are + // respected regardless of the final model string from routing. // TODO(12916): Migrate sub-agents where possible to static configs. const modelConfig = definition.modelConfig; let model = modelConfig.model; @@ -207,24 +210,35 @@ export class AgentRegistry { model = this.config.getModel(); } - const runtimeAlias: ModelConfigAlias = { - modelConfig: { - model, - generateContentConfig: { - temperature: modelConfig.temp, - topP: modelConfig.top_p, - thinkingConfig: { - includeThoughts: true, - thinkingBudget: modelConfig.thinkingBudget ?? -1, - }, - }, + const generateContentConfig = { + temperature: modelConfig.temp, + topP: modelConfig.top_p, + thinkingConfig: { + includeThoughts: true, + thinkingBudget: modelConfig.thinkingBudget ?? -1, }, }; this.config.modelConfigService.registerRuntimeModelConfig( getModelConfigAlias(definition), - runtimeAlias, + { + modelConfig: { + model, + generateContentConfig, + }, + }, ); + + if (isAutoModel(model)) { + this.config.modelConfigService.registerRuntimeModelOverride({ + match: { + overrideScope: definition.name, + }, + modelConfig: { + generateContentConfig, + }, + }); + } } /** From 7e02ef697ddc147037a4e7261f22c80617125df5 Mon Sep 17 00:00:00 2001 From: Adam Weidman <65992621+adamfweidman@users.noreply.github.com> Date: Thu, 8 Jan 2026 16:02:44 -0500 Subject: [PATCH 073/713] feat(cli): add /agents slash command to list available agents (#16182) --- .../src/services/BuiltinCommandLoader.test.ts | 21 +++++ .../cli/src/services/BuiltinCommandLoader.ts | 2 + .../cli/src/ui/commands/agentsCommand.test.ts | 85 +++++++++++++++++++ packages/cli/src/ui/commands/agentsCommand.ts | 51 +++++++++++ .../ui/components/HistoryItemDisplay.test.tsx | 24 ++++++ .../src/ui/components/HistoryItemDisplay.tsx | 7 ++ .../HistoryItemDisplay.test.tsx.snap | 15 ++++ .../src/ui/components/views/AgentsStatus.tsx | 72 ++++++++++++++++ packages/cli/src/ui/types.ts | 13 +++ packages/core/src/index.ts | 3 + 10 files changed, 293 insertions(+) create mode 100644 packages/cli/src/ui/commands/agentsCommand.test.ts create mode 100644 packages/cli/src/ui/commands/agentsCommand.ts create mode 100644 packages/cli/src/ui/components/views/AgentsStatus.tsx diff --git a/packages/cli/src/services/BuiltinCommandLoader.test.ts b/packages/cli/src/services/BuiltinCommandLoader.test.ts index 22b7a47ffc..545168e88d 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.test.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.test.ts @@ -58,6 +58,9 @@ import { CommandKind } from '../ui/commands/types.js'; import { restoreCommand } from '../ui/commands/restoreCommand.js'; vi.mock('../ui/commands/authCommand.js', () => ({ authCommand: {} })); +vi.mock('../ui/commands/agentsCommand.js', () => ({ + agentsCommand: { name: 'agents' }, +})); vi.mock('../ui/commands/bugCommand.js', () => ({ bugCommand: {} })); vi.mock('../ui/commands/chatCommand.js', () => ({ chatCommand: {} })); vi.mock('../ui/commands/clearCommand.js', () => ({ clearCommand: {} })); @@ -104,6 +107,7 @@ describe('BuiltinCommandLoader', () => { getEnableHooksUI: () => false, getExtensionsEnabled: vi.fn().mockReturnValue(true), isSkillsSupportEnabled: vi.fn().mockReturnValue(false), + isAgentsEnabled: vi.fn().mockReturnValue(false), getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ getAllSkills: vi.fn().mockReturnValue([]), @@ -189,6 +193,22 @@ describe('BuiltinCommandLoader', () => { const policiesCmd = commands.find((c) => c.name === 'policies'); expect(policiesCmd).toBeDefined(); }); + + it('should include agents command when agents are enabled', async () => { + mockConfig.isAgentsEnabled = vi.fn().mockReturnValue(true); + const loader = new BuiltinCommandLoader(mockConfig); + const commands = await loader.loadCommands(new AbortController().signal); + const agentsCmd = commands.find((c) => c.name === 'agents'); + expect(agentsCmd).toBeDefined(); + }); + + it('should exclude agents command when agents are disabled', async () => { + mockConfig.isAgentsEnabled = vi.fn().mockReturnValue(false); + const loader = new BuiltinCommandLoader(mockConfig); + const commands = await loader.loadCommands(new AbortController().signal); + const agentsCmd = commands.find((c) => c.name === 'agents'); + expect(agentsCmd).toBeUndefined(); + }); }); describe('BuiltinCommandLoader profile', () => { @@ -204,6 +224,7 @@ describe('BuiltinCommandLoader profile', () => { getEnableHooksUI: () => false, getExtensionsEnabled: vi.fn().mockReturnValue(true), isSkillsSupportEnabled: vi.fn().mockReturnValue(false), + isAgentsEnabled: vi.fn().mockReturnValue(false), getMcpEnabled: vi.fn().mockReturnValue(true), getSkillManager: vi.fn().mockReturnValue({ getAllSkills: vi.fn().mockReturnValue([]), diff --git a/packages/cli/src/services/BuiltinCommandLoader.ts b/packages/cli/src/services/BuiltinCommandLoader.ts index 4320217220..5193b5fe9c 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.ts @@ -14,6 +14,7 @@ import { import type { MessageActionReturn, Config } from '@google/gemini-cli-core'; import { startupProfiler } from '@google/gemini-cli-core'; import { aboutCommand } from '../ui/commands/aboutCommand.js'; +import { agentsCommand } from '../ui/commands/agentsCommand.js'; import { authCommand } from '../ui/commands/authCommand.js'; import { bugCommand } from '../ui/commands/bugCommand.js'; import { chatCommand } from '../ui/commands/chatCommand.js'; @@ -66,6 +67,7 @@ export class BuiltinCommandLoader implements ICommandLoader { const handle = startupProfiler.start('load_builtin_commands'); const allDefinitions: Array = [ aboutCommand, + ...(this.config?.isAgentsEnabled() ? [agentsCommand] : []), authCommand, bugCommand, chatCommand, diff --git a/packages/cli/src/ui/commands/agentsCommand.test.ts b/packages/cli/src/ui/commands/agentsCommand.test.ts new file mode 100644 index 0000000000..1e871bae6a --- /dev/null +++ b/packages/cli/src/ui/commands/agentsCommand.test.ts @@ -0,0 +1,85 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { vi, describe, it, expect, beforeEach } from 'vitest'; +import { agentsCommand } from './agentsCommand.js'; +import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; +import type { Config } from '@google/gemini-cli-core'; +import { MessageType } from '../types.js'; + +describe('agentsCommand', () => { + let mockContext: ReturnType; + let mockConfig: { + getAgentRegistry: ReturnType; + }; + + beforeEach(() => { + vi.clearAllMocks(); + + mockConfig = { + getAgentRegistry: vi.fn().mockReturnValue({ + getAllDefinitions: vi.fn().mockReturnValue([]), + }), + }; + + mockContext = createMockCommandContext({ + services: { + config: mockConfig as unknown as Config, + }, + }); + }); + + it('should show an error if config is not available', async () => { + const contextWithoutConfig = createMockCommandContext({ + services: { + config: null, + }, + }); + + const result = await agentsCommand.action!(contextWithoutConfig, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: 'Config not loaded.', + }); + }); + + it('should show an error if agent registry is not available', async () => { + mockConfig.getAgentRegistry = vi.fn().mockReturnValue(undefined); + + const result = await agentsCommand.action!(mockContext, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: 'Agent registry not found.', + }); + }); + + it('should call addItem with correct agents list', async () => { + const mockAgents = [ + { + name: 'agent1', + displayName: 'Agent One', + description: 'desc1', + kind: 'local', + }, + { name: 'agent2', description: 'desc2', kind: 'remote' }, + ]; + mockConfig.getAgentRegistry().getAllDefinitions.mockReturnValue(mockAgents); + + await agentsCommand.action!(mockContext, ''); + + expect(mockContext.ui.addItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.AGENTS_LIST, + agents: mockAgents, + }), + expect.any(Number), + ); + }); +}); diff --git a/packages/cli/src/ui/commands/agentsCommand.ts b/packages/cli/src/ui/commands/agentsCommand.ts new file mode 100644 index 0000000000..516c326662 --- /dev/null +++ b/packages/cli/src/ui/commands/agentsCommand.ts @@ -0,0 +1,51 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type { SlashCommand, CommandContext } from './types.js'; +import { CommandKind } from './types.js'; +import { MessageType, type HistoryItemAgentsList } from '../types.js'; + +export const agentsCommand: SlashCommand = { + name: 'agents', + description: 'List available local and remote agents', + kind: CommandKind.BUILT_IN, + autoExecute: true, + action: async (context: CommandContext) => { + const { config } = context.services; + if (!config) { + return { + type: 'message', + messageType: 'error', + content: 'Config not loaded.', + }; + } + + const agentRegistry = config.getAgentRegistry(); + if (!agentRegistry) { + return { + type: 'message', + messageType: 'error', + content: 'Agent registry not found.', + }; + } + + const agents = agentRegistry.getAllDefinitions().map((def) => ({ + name: def.name, + displayName: def.displayName, + description: def.description, + kind: def.kind, + })); + + const agentsListItem: HistoryItemAgentsList = { + type: MessageType.AGENTS_LIST, + agents, + }; + + context.ui.addItem(agentsListItem, Date.now()); + + return; + }, +}; diff --git a/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx b/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx index 8488a78dfb..17fd06e6c8 100644 --- a/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx +++ b/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx @@ -71,6 +71,30 @@ describe('', () => { }, ); + it('renders AgentsStatus for "agents_list" type', () => { + const item: HistoryItem = { + ...baseItem, + type: MessageType.AGENTS_LIST, + agents: [ + { + name: 'local_agent', + displayName: 'Local Agent', + description: ' Local agent description.\n Second line.', + kind: 'local', + }, + { + name: 'remote_agent', + description: 'Remote agent description.', + kind: 'remote', + }, + ], + }; + const { lastFrame } = renderWithProviders( + , + ); + expect(lastFrame()).toMatchSnapshot(); + }); + it('renders StatsDisplay for "stats" type', () => { const item: HistoryItem = { ...baseItem, diff --git a/packages/cli/src/ui/components/HistoryItemDisplay.tsx b/packages/cli/src/ui/components/HistoryItemDisplay.tsx index 5a7f769402..509645eda5 100644 --- a/packages/cli/src/ui/components/HistoryItemDisplay.tsx +++ b/packages/cli/src/ui/components/HistoryItemDisplay.tsx @@ -29,6 +29,7 @@ import { ExtensionsList } from './views/ExtensionsList.js'; import { getMCPServerStatus } from '@google/gemini-cli-core'; import { ToolsList } from './views/ToolsList.js'; import { SkillsList } from './views/SkillsList.js'; +import { AgentsStatus } from './views/AgentsStatus.js'; import { McpStatus } from './views/McpStatus.js'; import { ChatList } from './views/ChatList.js'; import { HooksList } from './views/HooksList.js'; @@ -160,6 +161,12 @@ export const HistoryItemDisplay: React.FC = ({ showDescriptions={itemForDisplay.showDescriptions} /> )} + {itemForDisplay.type === 'agents_list' && ( + + )} {itemForDisplay.type === 'mcp_status' && ( )} diff --git a/packages/cli/src/ui/components/__snapshots__/HistoryItemDisplay.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/HistoryItemDisplay.test.tsx.snap index 74b54dbc79..ad04fdb2ba 100644 --- a/packages/cli/src/ui/components/__snapshots__/HistoryItemDisplay.test.tsx.snap +++ b/packages/cli/src/ui/components/__snapshots__/HistoryItemDisplay.test.tsx.snap @@ -352,6 +352,21 @@ exports[` > gemini items (alternateBuffer=true) > should r 50 Line 50" `; +exports[` > renders AgentsStatus for "agents_list" type 1`] = ` +"Local Agents + + - Local Agent (local_agent) + Local agent description. + Second line. + +Remote Agents + + - remote_agent + Remote agent description. + +" +`; + exports[` > renders InfoMessage for "info" type with multi-line text (alternateBuffer=false) 1`] = ` " ℹ ⚡ Line 1 diff --git a/packages/cli/src/ui/components/views/AgentsStatus.tsx b/packages/cli/src/ui/components/views/AgentsStatus.tsx new file mode 100644 index 0000000000..2e6131f7a9 --- /dev/null +++ b/packages/cli/src/ui/components/views/AgentsStatus.tsx @@ -0,0 +1,72 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Box, Text } from 'ink'; +import type React from 'react'; +import { theme } from '../../semantic-colors.js'; +import type { AgentDefinitionJson } from '../../types.js'; +import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js'; + +interface AgentsStatusProps { + agents: AgentDefinitionJson[]; + terminalWidth: number; +} + +export const AgentsStatus: React.FC = ({ + agents, + terminalWidth, +}) => { + const localAgents = agents.filter((a) => a.kind === 'local'); + const remoteAgents = agents.filter((a) => a.kind === 'remote'); + + if (agents.length === 0) { + return ( + + No agents available. + + ); + } + + const renderAgentList = (title: string, agentList: AgentDefinitionJson[]) => { + if (agentList.length === 0) return null; + + return ( + + + {title} + + + {agentList.map((agent) => ( + + {' '}- + + + {agent.displayName || agent.name} + {agent.displayName && agent.displayName !== agent.name && ( + ({agent.name}) + )} + + {agent.description && ( + + )} + + + ))} + + ); + }; + + return ( + + {renderAgentList('Local Agents', localAgents)} + {renderAgentList('Remote Agents', remoteAgents)} + + ); +}; diff --git a/packages/cli/src/ui/types.ts b/packages/cli/src/ui/types.ts index 7535119a30..096caf862a 100644 --- a/packages/cli/src/ui/types.ts +++ b/packages/cli/src/ui/types.ts @@ -14,6 +14,7 @@ import type { ToolResultDisplay, RetrieveUserQuotaResponse, SkillDefinition, + AgentDefinition, } from '@google/gemini-cli-core'; import type { PartListUnion } from '@google/genai'; import { type ReactNode } from 'react'; @@ -213,6 +214,16 @@ export type HistoryItemSkillsList = HistoryItemBase & { showDescriptions: boolean; }; +export type AgentDefinitionJson = Pick< + AgentDefinition, + 'name' | 'displayName' | 'description' | 'kind' +>; + +export type HistoryItemAgentsList = HistoryItemBase & { + type: 'agents_list'; + agents: AgentDefinitionJson[]; +}; + // JSON-friendly types for using as a simple data model showing info about an // MCP Server. export interface JsonMcpTool { @@ -292,6 +303,7 @@ export type HistoryItemWithoutId = | HistoryItemExtensionsList | HistoryItemToolsList | HistoryItemSkillsList + | HistoryItemAgentsList | HistoryItemMcpStatus | HistoryItemChatList | HistoryItemHooksList; @@ -315,6 +327,7 @@ export enum MessageType { EXTENSIONS_LIST = 'extensions_list', TOOLS_LIST = 'tools_list', SKILLS_LIST = 'skills_list', + AGENTS_LIST = 'agents_list', MCP_STATUS = 'mcp_status', CHAT_LIST = 'chat_list', HOOKS_LIST = 'hooks_list', diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index a15ee2951d..be23fb2d27 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -120,6 +120,9 @@ export * from './resources/resource-registry.js'; // Export prompt logic export * from './prompts/mcp-prompts.js'; +// Export agent definitions +export * from './agents/types.js'; + // Export specific tool logic export * from './tools/read-file.js'; export * from './tools/ls.js'; From 9062a943e732c4af1179bf31a4fcc0323a38ee6b Mon Sep 17 00:00:00 2001 From: maruto <53184634+maru0804@users.noreply.github.com> Date: Fri, 9 Jan 2026 06:59:15 +0900 Subject: [PATCH 074/713] docs(cli): fix includeDirectories nesting in configuration.md (#15067) --- docs/cli/configuration.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/cli/configuration.md b/docs/cli/configuration.md index a03a325afd..1b7177362c 100644 --- a/docs/cli/configuration.md +++ b/docs/cli/configuration.md @@ -358,7 +358,7 @@ contain other project-specific files related to Gemini CLI's operation, such as: "excludedProjectEnvVars": ["DEBUG", "DEBUG_MODE", "NODE_ENV"] ``` -- **`includeDirectories`** (array of strings): +- **`context.includeDirectories`** (array of strings): - **Description:** Specifies an array of additional absolute or relative paths to include in the workspace context. This allows you to work with files across multiple directories as if they were one. Paths can use `~` to refer @@ -367,14 +367,16 @@ contain other project-specific files related to Gemini CLI's operation, such as: - **Default:** `[]` - **Example:** ```json - "includeDirectories": [ - "/path/to/another/project", - "../shared-library", - "~/common-utils" - ] + "context": { + "includeDirectories": [ + "/path/to/another/project", + "../shared-library", + "~/common-utils" + ] + } ``` -- **`loadMemoryFromIncludeDirectories`** (boolean): +- **`context.loadMemoryFromIncludeDirectories`** (boolean): - **Description:** Controls the behavior of the `/memory refresh` command. If set to `true`, `GEMINI.md` files should be loaded from all directories that are added. If set to `false`, `GEMINI.md` should only be loaded from the @@ -382,7 +384,9 @@ contain other project-specific files related to Gemini CLI's operation, such as: - **Default:** `false` - **Example:** ```json - "loadMemoryFromIncludeDirectories": true + "context": { + "loadMemoryFromIncludeDirectories": true + } ``` ### Example `settings.json`: @@ -418,8 +422,10 @@ contain other project-specific files related to Gemini CLI's operation, such as: } }, "excludedProjectEnvVars": ["DEBUG", "DEBUG_MODE", "NODE_ENV"], - "includeDirectories": ["path/to/dir1", "~/path/to/dir2", "../path/to/dir3"], - "loadMemoryFromIncludeDirectories": true + "context": { + "includeDirectories": ["path/to/dir1", "~/path/to/dir2", "../path/to/dir3"], + "loadMemoryFromIncludeDirectories": true + } } ``` From e5f7a9c4240c4655e4075863c06ae842ca81e369 Mon Sep 17 00:00:00 2001 From: Adib234 <30782825+Adib234@users.noreply.github.com> Date: Thu, 8 Jan 2026 17:21:15 -0500 Subject: [PATCH 075/713] feat: implement file system reversion utilities for rewind (#15715) --- .../cli/src/ui/utils/rewindFileOps.test.ts | 473 ++++++++++++++++++ packages/cli/src/ui/utils/rewindFileOps.ts | 250 +++++++++ packages/core/src/index.ts | 1 + packages/core/src/telemetry/types.ts | 9 +- packages/core/src/utils/fileDiffUtils.test.ts | 104 ++++ packages/core/src/utils/fileDiffUtils.ts | 50 ++ 6 files changed, 885 insertions(+), 2 deletions(-) create mode 100644 packages/cli/src/ui/utils/rewindFileOps.test.ts create mode 100644 packages/cli/src/ui/utils/rewindFileOps.ts create mode 100644 packages/core/src/utils/fileDiffUtils.test.ts create mode 100644 packages/core/src/utils/fileDiffUtils.ts diff --git a/packages/cli/src/ui/utils/rewindFileOps.test.ts b/packages/cli/src/ui/utils/rewindFileOps.test.ts new file mode 100644 index 0000000000..a70dd0337f --- /dev/null +++ b/packages/cli/src/ui/utils/rewindFileOps.test.ts @@ -0,0 +1,473 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { + calculateTurnStats, + calculateRewindImpact, + revertFileChanges, +} from './rewindFileOps.js'; +import type { + ConversationRecord, + MessageRecord, + ToolCallRecord, +} from '@google/gemini-cli-core'; +import { coreEvents } from '@google/gemini-cli-core'; +import fs from 'node:fs/promises'; +import path from 'node:path'; + +vi.mock('node:fs/promises'); +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + coreEvents: { + emitFeedback: vi.fn(), + }, + }; +}); + +describe('rewindFileOps', () => { + const mockConversation: ConversationRecord = { + sessionId: 'test-session', + projectHash: 'hash', + startTime: 'time', + lastUpdated: 'time', + messages: [], + }; + + beforeEach(() => { + vi.clearAllMocks(); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + describe('calculateTurnStats', () => { + it('returns null if no edits found after user message', () => { + const userMsg: MessageRecord = { + type: 'user', + content: 'hello', + id: '1', + timestamp: '1', + }; + const geminiMsg: MessageRecord = { + type: 'gemini', + content: 'hi', + id: '2', + timestamp: '2', + }; + mockConversation.messages = [userMsg, geminiMsg]; + + const stats = calculateTurnStats(mockConversation, userMsg); + expect(stats).toBeNull(); + }); + + it('calculates stats for single turn correctly', () => { + const userMsg: MessageRecord = { + type: 'user', + content: 'hello', + id: '1', + timestamp: '1', + }; + const toolMsg: MessageRecord = { + type: 'gemini', + id: '2', + timestamp: '2', + content: '', + toolCalls: [ + { + name: 'replace', + id: 'tool-call-1', + status: 'success', + timestamp: '2', + args: {}, + resultDisplay: { + fileName: 'file1.ts', + filePath: '/file1.ts', + originalContent: 'old', + newContent: 'new', + isNewFile: false, + diffStat: { + model_added_lines: 5, + model_removed_lines: 2, + user_added_lines: 0, + user_removed_lines: 0, + model_added_chars: 100, + model_removed_chars: 20, + user_added_chars: 0, + user_removed_chars: 0, + }, + }, + }, + ] as unknown as ToolCallRecord[], + }; + + const userMsg2: MessageRecord = { + type: 'user', + content: 'next', + id: '3', + timestamp: '3', + }; + + mockConversation.messages = [userMsg, toolMsg, userMsg2]; + + const stats = calculateTurnStats(mockConversation, userMsg); + expect(stats).toEqual({ + addedLines: 5, + removedLines: 2, + fileCount: 1, + }); + }); + }); + + describe('calculateRewindImpact', () => { + it('calculates cumulative stats across multiple turns', () => { + const userMsg1: MessageRecord = { + type: 'user', + content: 'start', + id: '1', + timestamp: '1', + }; + const toolMsg1: MessageRecord = { + type: 'gemini', + id: '2', + timestamp: '2', + content: '', + toolCalls: [ + { + name: 'replace', + id: 'tool-call-1', + status: 'success', + timestamp: '2', + args: {}, + resultDisplay: { + fileName: 'file1.ts', + filePath: '/file1.ts', + fileDiff: 'diff1', + originalContent: 'old', + newContent: 'new', + isNewFile: false, + diffStat: { + model_added_lines: 5, + model_removed_lines: 2, + user_added_lines: 0, + user_removed_lines: 0, + model_added_chars: 0, + model_removed_chars: 0, + user_added_chars: 0, + user_removed_chars: 0, + }, + }, + }, + ] as unknown as ToolCallRecord[], + }; + + const userMsg2: MessageRecord = { + type: 'user', + content: 'next', + id: '3', + timestamp: '3', + }; + + const toolMsg2: MessageRecord = { + type: 'gemini', + id: '4', + timestamp: '4', + content: '', + toolCalls: [ + { + name: 'replace', + id: 'tool-call-2', + status: 'success', + timestamp: '4', + args: {}, + resultDisplay: { + fileName: 'file2.ts', + filePath: '/file2.ts', + fileDiff: 'diff2', + originalContent: 'old', + newContent: 'new', + isNewFile: false, + diffStat: { + model_added_lines: 3, + model_removed_lines: 1, + user_added_lines: 0, + user_removed_lines: 0, + model_added_chars: 0, + model_removed_chars: 0, + user_added_chars: 0, + user_removed_chars: 0, + }, + }, + }, + ] as unknown as ToolCallRecord[], + }; + + mockConversation.messages = [userMsg1, toolMsg1, userMsg2, toolMsg2]; + + const stats = calculateRewindImpact(mockConversation, userMsg1); + + expect(stats).toEqual({ + addedLines: 8, // 5 + 3 + removedLines: 3, // 2 + 1 + fileCount: 2, + details: [ + { fileName: 'file1.ts', diff: 'diff1' }, + { fileName: 'file2.ts', diff: 'diff2' }, + ], + }); + }); + }); + + describe('revertFileChanges', () => { + const mockDiffStat = { + model_added_lines: 1, + model_removed_lines: 1, + user_added_lines: 0, + user_removed_lines: 0, + model_added_chars: 1, + model_removed_chars: 1, + user_added_chars: 0, + user_removed_chars: 0, + }; + + it('does nothing if message not found', async () => { + mockConversation.messages = []; + await revertFileChanges(mockConversation, 'missing-id'); + expect(fs.writeFile).not.toHaveBeenCalled(); + }); + + it('reverts exact match', async () => { + const userMsg: MessageRecord = { + type: 'user', + content: 'start', + id: '1', + timestamp: '1', + }; + const toolMsg: MessageRecord = { + type: 'gemini', + id: '2', + timestamp: '2', + content: '', + toolCalls: [ + { + name: 'replace', + id: 'tool-call-1', + status: 'success', + timestamp: '2', + args: {}, + resultDisplay: { + fileName: 'file.txt', + filePath: path.resolve('/root/file.txt'), + originalContent: 'old', + newContent: 'new', + isNewFile: false, + diffStat: mockDiffStat, + }, + }, + ] as unknown as ToolCallRecord[], + }; + + mockConversation.messages = [userMsg, toolMsg]; + + vi.mocked(fs.readFile).mockResolvedValue('new'); + + await revertFileChanges(mockConversation, '1'); + + expect(fs.writeFile).toHaveBeenCalledWith( + path.resolve('/root/file.txt'), + 'old', + ); + }); + + it('deletes new file on revert', async () => { + const userMsg: MessageRecord = { + type: 'user', + content: 'start', + id: '1', + timestamp: '1', + }; + const toolMsg: MessageRecord = { + type: 'gemini', + id: '2', + timestamp: '2', + content: '', + toolCalls: [ + { + name: 'write_file', + id: 'tool-call-2', + status: 'success', + timestamp: '2', + args: {}, + resultDisplay: { + fileName: 'file.txt', + filePath: path.resolve('/root/file.txt'), + originalContent: null, + newContent: 'content', + isNewFile: true, + diffStat: mockDiffStat, + }, + }, + ] as unknown as ToolCallRecord[], + }; + + mockConversation.messages = [userMsg, toolMsg]; + + vi.mocked(fs.readFile).mockResolvedValue('content'); + + await revertFileChanges(mockConversation, '1'); + + expect(fs.unlink).toHaveBeenCalledWith(path.resolve('/root/file.txt')); + }); + + it('handles smart revert (patching) successfully', async () => { + const original = Array.from( + { length: 20 }, + (_, i) => `line${i + 1}`, + ).join('\n'); + // Agent changes line 2 + const agentModifiedLines = original.split('\n'); + agentModifiedLines[1] = 'line2-modified'; + const agentModified = agentModifiedLines.join('\n'); + + // User changes line 18 (far away from line 2) + const userModifiedLines = [...agentModifiedLines]; + userModifiedLines[17] = 'line18-modified'; + const userModified = userModifiedLines.join('\n'); + + const toolMsg: MessageRecord = { + type: 'gemini', + id: '2', + timestamp: '2', + content: '', + toolCalls: [ + { + name: 'replace', + id: 'tool-call-1', + status: 'success', + timestamp: '2', + args: {}, + resultDisplay: { + fileName: 'file.txt', + filePath: path.resolve('/root/file.txt'), + originalContent: original, + newContent: agentModified, + isNewFile: false, + diffStat: mockDiffStat, + }, + }, + ] as unknown as ToolCallRecord[], + }; + + mockConversation.messages = [ + { type: 'user', content: 'start', id: '1', timestamp: '1' }, + toolMsg, + ]; + vi.mocked(fs.readFile).mockResolvedValue(userModified); + + await revertFileChanges(mockConversation, '1'); + + // Expect line 2 to be reverted to original, but line 18 to keep user modification + const expectedLines = original.split('\n'); + expectedLines[17] = 'line18-modified'; + const expectedContent = expectedLines.join('\n'); + + expect(fs.writeFile).toHaveBeenCalledWith( + path.resolve('/root/file.txt'), + expectedContent, + ); + }); + + it('emits warning on smart revert failure', async () => { + const original = 'line1\nline2\nline3'; + const agentModified = 'line1\nline2-modified\nline3'; + // User modification conflicts with the agent's change. + const userModified = 'line1\nline2-usermodified\nline3'; + + const toolMsg: MessageRecord = { + type: 'gemini', + id: '2', + timestamp: '2', + content: '', + toolCalls: [ + { + name: 'replace', + id: 'tool-call-1', + status: 'success', + timestamp: '2', + args: {}, + resultDisplay: { + fileName: 'file.txt', + filePath: path.resolve('/root/file.txt'), + originalContent: original, + newContent: agentModified, + isNewFile: false, + diffStat: mockDiffStat, + }, + }, + ] as unknown as ToolCallRecord[], + }; + + mockConversation.messages = [ + { type: 'user', content: 'start', id: '1', timestamp: '1' }, + toolMsg, + ]; + vi.mocked(fs.readFile).mockResolvedValue(userModified); + + await revertFileChanges(mockConversation, '1'); + + expect(fs.writeFile).not.toHaveBeenCalled(); + expect(coreEvents.emitFeedback).toHaveBeenCalledWith( + 'warning', + expect.stringContaining('Smart revert for file.txt failed'), + ); + }); + + it('emits error if fs.readFile fails with a generic error', async () => { + const toolMsg: MessageRecord = { + type: 'gemini', + id: '2', + timestamp: '2', + content: '', + toolCalls: [ + { + name: 'replace', + id: 'tool-call-1', + status: 'success', + timestamp: '2', + args: {}, + resultDisplay: { + fileName: 'file.txt', + filePath: path.resolve('/root/file.txt'), + originalContent: 'old', + newContent: 'new', + isNewFile: false, + diffStat: mockDiffStat, + }, + }, + ] as unknown as ToolCallRecord[], + }; + + mockConversation.messages = [ + { type: 'user', content: 'start', id: '1', timestamp: '1' }, + toolMsg, + ]; + // Simulate a generic file read error + vi.mocked(fs.readFile).mockRejectedValue(new Error('Permission denied')); + + await revertFileChanges(mockConversation, '1'); + expect(fs.writeFile).not.toHaveBeenCalled(); + expect(coreEvents.emitFeedback).toHaveBeenCalledWith( + 'error', + 'Error reading file.txt during revert: Permission denied', + expect.any(Error), + ); + }); + }); +}); diff --git a/packages/cli/src/ui/utils/rewindFileOps.ts b/packages/cli/src/ui/utils/rewindFileOps.ts new file mode 100644 index 0000000000..89315c9f2d --- /dev/null +++ b/packages/cli/src/ui/utils/rewindFileOps.ts @@ -0,0 +1,250 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type { + ConversationRecord, + MessageRecord, +} from '@google/gemini-cli-core'; +import fs from 'node:fs/promises'; +import * as Diff from 'diff'; +import { + coreEvents, + debugLogger, + getFileDiffFromResultDisplay, + computeAddedAndRemovedLines, +} from '@google/gemini-cli-core'; + +export interface FileChangeDetail { + fileName: string; + diff: string; +} + +export interface FileChangeStats { + addedLines: number; + removedLines: number; + fileCount: number; + details?: FileChangeDetail[]; +} + +/** + * Calculates file change statistics for a single turn. + * A turn is defined as the sequence of messages starting after the given user message + * and continuing until the next user message or the end of the conversation. + * + * @param conversation The full conversation record. + * @param userMessage The starting user message for the turn. + * @returns Statistics about lines added/removed and files touched, or null if no edits occurred. + */ +export function calculateTurnStats( + conversation: ConversationRecord, + userMessage: MessageRecord, +): FileChangeStats | null { + const msgIndex = conversation.messages.indexOf(userMessage); + if (msgIndex === -1) return null; + + let addedLines = 0; + let removedLines = 0; + const files = new Set(); + let hasEdits = false; + + // Look ahead until the next user message (single turn) + for (let i = msgIndex + 1; i < conversation.messages.length; i++) { + const msg = conversation.messages[i]; + if (msg.type === 'user') break; // Stop at next user message + + if (msg.type === 'gemini' && msg.toolCalls) { + for (const toolCall of msg.toolCalls) { + const fileDiff = getFileDiffFromResultDisplay(toolCall.resultDisplay); + if (fileDiff) { + hasEdits = true; + const stats = fileDiff.diffStat; + const calculations = computeAddedAndRemovedLines(stats); + addedLines += calculations.addedLines; + removedLines += calculations.removedLines; + + files.add(fileDiff.fileName); + } + } + } + } + + if (!hasEdits) return null; + + return { + addedLines, + removedLines, + fileCount: files.size, + }; +} + +/** + * Calculates the cumulative file change statistics from a specific message + * to the end of the conversation. + * + * @param conversation The full conversation record. + * @param userMessage The message to start calculating impact from (exclusive). + * @returns Aggregate statistics about lines added/removed and files touched, or null if no edits occurred. + */ +export function calculateRewindImpact( + conversation: ConversationRecord, + userMessage: MessageRecord, +): FileChangeStats | null { + const msgIndex = conversation.messages.indexOf(userMessage); + if (msgIndex === -1) return null; + + let addedLines = 0; + let removedLines = 0; + const files = new Set(); + const details: FileChangeDetail[] = []; + let hasEdits = false; + + // Look ahead to the end of conversation (cumulative) + for (let i = msgIndex + 1; i < conversation.messages.length; i++) { + const msg = conversation.messages[i]; + // Do NOT break on user message - we want total impact + + if (msg.type === 'gemini' && msg.toolCalls) { + for (const toolCall of msg.toolCalls) { + const fileDiff = getFileDiffFromResultDisplay(toolCall.resultDisplay); + if (fileDiff) { + hasEdits = true; + const stats = fileDiff.diffStat; + const calculations = computeAddedAndRemovedLines(stats); + addedLines += calculations.addedLines; + removedLines += calculations.removedLines; + files.add(fileDiff.fileName); + details.push({ + fileName: fileDiff.fileName, + diff: fileDiff.fileDiff, + }); + } + } + } + } + + if (!hasEdits) return null; + + return { + addedLines, + removedLines, + fileCount: files.size, + details, + }; +} + +/** + * Reverts file changes made by the model from the end of the conversation + * back to a specific target message. + * + * It iterates backwards through the conversation history and attempts to undo + * any file modifications. It handles cases where the user might have subsequently + * modified the file by attempting a smart patch (using the `diff` library). + * + * @param conversation The full conversation record. + * @param targetMessageId The ID of the message to revert back to. Changes *after* this message will be undone. + */ +export async function revertFileChanges( + conversation: ConversationRecord, + targetMessageId: string, +): Promise { + const messageIndex = conversation.messages.findIndex( + (m) => m.id === targetMessageId, + ); + + if (messageIndex === -1) { + debugLogger.error('Requested message to rewind to was not found '); + return; + } + + // Iterate backwards from the end to the message being rewound (exclusive of the messageId itself) + for (let i = conversation.messages.length - 1; i > messageIndex; i--) { + const msg = conversation.messages[i]; + if (msg.type === 'gemini' && msg.toolCalls) { + for (let j = msg.toolCalls.length - 1; j >= 0; j--) { + const toolCall = msg.toolCalls[j]; + const fileDiff = getFileDiffFromResultDisplay(toolCall.resultDisplay); + if (fileDiff) { + const { filePath, fileName, newContent, originalContent, isNewFile } = + fileDiff; + try { + let currentContent: string | null = null; + try { + currentContent = await fs.readFile(filePath, 'utf8'); + } catch (e) { + const error = e as Error; + if ('code' in error && error.code === 'ENOENT') { + // File does not exist, which is fine in some revert scenarios. + debugLogger.debug( + `File ${fileName} not found during revert, proceeding as it may be a new file deletion.`, + ); + } else { + // Other read errors are unexpected. + coreEvents.emitFeedback( + 'error', + `Error reading ${fileName} during revert: ${error.message}`, + e, + ); + // Continue to next tool call + return; + } + } + // 1. Exact Match: Safe to revert directly + if (currentContent === newContent) { + if (!isNewFile) { + await fs.writeFile(filePath, originalContent ?? ''); + } else { + // Original content was null (new file), so we delete the file + await fs.unlink(filePath); + } + } + // 2. Mismatch: Attempt Smart Revert (Patch) + else if (currentContent !== null) { + const originalText = originalContent ?? ''; + + // Create a patch that transforms Agent -> Original + const undoPatch = Diff.createPatch( + fileName, + newContent, + originalText, + ); + + // Apply that patch to the Current content + const patchedContent = Diff.applyPatch(currentContent, undoPatch); + + if (typeof patchedContent === 'string') { + if (patchedContent === '' && isNewFile) { + // If the result is empty and the file didn't exist originally, delete it + await fs.unlink(filePath); + } else { + await fs.writeFile(filePath, patchedContent); + } + } else { + // Patch failed + coreEvents.emitFeedback( + 'warning', + `Smart revert for ${fileName} failed. The file may have been modified in a way that conflicts with the undo operation.`, + ); + } + } else { + // File was deleted by the user, but we expected content. + // This can happen if a file created by the agent is deleted before rewind. + coreEvents.emitFeedback( + 'warning', + `Cannot revert changes for ${fileName} because it was not found on disk. This is expected if a file created by the agent was deleted before rewind`, + ); + } + } catch (e) { + coreEvents.emitFeedback( + 'error', + `An unexpected error occurred while reverting ${fileName}.`, + e, + ); + } + } + } + } + } +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index be23fb2d27..a56d5ae813 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -65,6 +65,7 @@ export * from './utils/quotaErrorDetection.js'; export * from './utils/userAccountManager.js'; export * from './utils/googleQuotaErrors.js'; export * from './utils/fileUtils.js'; +export * from './utils/fileDiffUtils.js'; export * from './utils/retry.js'; export * from './utils/shell-utils.js'; export { PolicyDecision, ApprovalMode } from './policy/types.js'; diff --git a/packages/core/src/telemetry/types.ts b/packages/core/src/telemetry/types.ts index 3ff143335f..0549ae3aa2 100644 --- a/packages/core/src/telemetry/types.ts +++ b/packages/core/src/telemetry/types.ts @@ -39,6 +39,7 @@ import { toSystemInstruction, } from './semantic.js'; import { sanitizeHookName } from './sanitize.js'; +import { getFileDiffFromResultDisplay } from '../utils/fileDiffUtils.js'; export interface BaseTelemetryEvent { 'event.name': string; @@ -290,13 +291,17 @@ export class ToolCallEvent implements BaseTelemetryEvent { this.tool_type = 'native'; } + const fileDiff = getFileDiffFromResultDisplay( + call.response.resultDisplay, + ); + if ( call.status === 'success' && typeof call.response.resultDisplay === 'object' && call.response.resultDisplay !== null && - 'diffStat' in call.response.resultDisplay + fileDiff ) { - const diffStat = call.response.resultDisplay.diffStat; + const diffStat = fileDiff.diffStat; if (diffStat) { this.metadata = { model_added_lines: diffStat.model_added_lines, diff --git a/packages/core/src/utils/fileDiffUtils.test.ts b/packages/core/src/utils/fileDiffUtils.test.ts new file mode 100644 index 0000000000..3c4c4c7667 --- /dev/null +++ b/packages/core/src/utils/fileDiffUtils.test.ts @@ -0,0 +1,104 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect } from 'vitest'; +import { + getFileDiffFromResultDisplay, + computeAddedAndRemovedLines, +} from './fileDiffUtils.js'; +import type { FileDiff, ToolResultDisplay } from '../tools/tools.js'; + +describe('fileDiffUtils', () => { + describe('getFileDiffFromResultDisplay', () => { + it('returns undefined if resultDisplay is undefined', () => { + expect(getFileDiffFromResultDisplay(undefined)).toBeUndefined(); + }); + + it('returns undefined if resultDisplay is not an object', () => { + expect( + getFileDiffFromResultDisplay('string' as ToolResultDisplay), + ).toBeUndefined(); + }); + + it('returns undefined if resultDisplay missing diffStat', () => { + const resultDisplay = { + fileName: 'file.txt', + }; + expect( + getFileDiffFromResultDisplay(resultDisplay as ToolResultDisplay), + ).toBeUndefined(); + }); + + it('returns the FileDiff object if structure is valid', () => { + const validDiffStat = { + model_added_lines: 1, + model_removed_lines: 2, + user_added_lines: 3, + user_removed_lines: 4, + model_added_chars: 10, + model_removed_chars: 20, + user_added_chars: 30, + user_removed_chars: 40, + }; + const resultDisplay = { + fileName: 'file.txt', + diffStat: validDiffStat, + }; + + const result = getFileDiffFromResultDisplay( + resultDisplay as ToolResultDisplay, + ); + expect(result).toBe(resultDisplay); + }); + }); + + describe('computeAddedAndRemovedLines', () => { + it('returns 0 added and 0 removed if stats is undefined', () => { + expect(computeAddedAndRemovedLines(undefined)).toEqual({ + addedLines: 0, + removedLines: 0, + }); + }); + + it('correctly sums added and removed lines from stats', () => { + const stats: FileDiff['diffStat'] = { + model_added_lines: 10, + model_removed_lines: 5, + user_added_lines: 2, + user_removed_lines: 1, + model_added_chars: 100, + model_removed_chars: 50, + user_added_chars: 20, + user_removed_chars: 10, + }; + + const result = computeAddedAndRemovedLines(stats); + expect(result).toEqual({ + addedLines: 12, // 10 + 2 + removedLines: 6, // 5 + 1 + }); + }); + + it('handles zero values correctly', () => { + const stats: FileDiff['diffStat'] = { + model_added_lines: 0, + model_removed_lines: 0, + user_added_lines: 0, + user_removed_lines: 0, + model_added_chars: 0, + model_removed_chars: 0, + user_added_chars: 0, + user_removed_chars: 0, + }; + + const result = computeAddedAndRemovedLines(stats); + expect(result).toEqual({ + addedLines: 0, + removedLines: 0, + }); + }); + }); +}); diff --git a/packages/core/src/utils/fileDiffUtils.ts b/packages/core/src/utils/fileDiffUtils.ts new file mode 100644 index 0000000000..47916c1e8e --- /dev/null +++ b/packages/core/src/utils/fileDiffUtils.ts @@ -0,0 +1,50 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type { FileDiff } from '../tools/tools.js'; +import type { ToolCallRecord } from '../services/chatRecordingService.js'; + +/** + * Safely extracts the FileDiff object from a tool call's resultDisplay. + * This helper performs runtime checks to ensure the object conforms to the FileDiff structure. + * @param resultDisplay The resultDisplay property of a ToolCallRecord. + * @returns The FileDiff object if found and valid, otherwise undefined. + */ +export function getFileDiffFromResultDisplay( + resultDisplay: ToolCallRecord['resultDisplay'], +): FileDiff | undefined { + if ( + resultDisplay && + typeof resultDisplay === 'object' && + 'diffStat' in resultDisplay && + typeof resultDisplay.diffStat === 'object' && + resultDisplay.diffStat !== null + ) { + const diffStat = resultDisplay.diffStat as FileDiff['diffStat']; + if (diffStat) { + return resultDisplay; + } + } + return undefined; +} + +export function computeAddedAndRemovedLines( + stats: FileDiff['diffStat'] | undefined, +): { + addedLines: number; + removedLines: number; +} { + if (!stats) { + return { + addedLines: 0, + removedLines: 0, + }; + } + return { + addedLines: stats.model_added_lines + stats.user_added_lines, + removedLines: stats.model_removed_lines + stats.user_removed_lines, + }; +} From d75792703a0288ae5bbba0a2e98b4871661d1670 Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Thu, 8 Jan 2026 22:35:12 +0000 Subject: [PATCH 076/713] Always enable redaction in GitHub actions. (#16200) --- .../src/services/environmentSanitization.ts | 10 +-- .../services/shellExecutionService.test.ts | 67 ++++++++++++++++++- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/packages/core/src/services/environmentSanitization.ts b/packages/core/src/services/environmentSanitization.ts index 5d82ac227d..dc9c92484d 100644 --- a/packages/core/src/services/environmentSanitization.ts +++ b/packages/core/src/services/environmentSanitization.ts @@ -14,7 +14,12 @@ export function sanitizeEnvironment( processEnv: NodeJS.ProcessEnv, config: EnvironmentSanitizationConfig, ): NodeJS.ProcessEnv { - if (!config.enableEnvironmentVariableRedaction) { + // Enable strict sanitization in GitHub actions. + const isStrictSanitization = + !!processEnv['GITHUB_SHA'] || processEnv['SURFACE'] === 'Github'; + + // Always sanitize when in GitHub actions. + if (!config.enableEnvironmentVariableRedaction && !isStrictSanitization) { return { ...processEnv }; } @@ -27,9 +32,6 @@ export function sanitizeEnvironment( (config.blockedEnvironmentVariables || []).map((k) => k.toUpperCase()), ); - // Enable strict sanitization in GitHub actions. - const isStrictSanitization = !!processEnv['GITHUB_SHA']; - for (const key in processEnv) { const value = processEnv[key]; diff --git a/packages/core/src/services/shellExecutionService.test.ts b/packages/core/src/services/shellExecutionService.test.ts index 4061ed5b84..14ffafa3c0 100644 --- a/packages/core/src/services/shellExecutionService.test.ts +++ b/packages/core/src/services/shellExecutionService.test.ts @@ -84,7 +84,7 @@ const shellExecutionConfig: ShellExecutionConfig = { showColor: false, disableDynamicLineTrimming: true, sanitizationConfig: { - enableEnvironmentVariableRedaction: true, + enableEnvironmentVariableRedaction: false, allowedEnvironmentVariables: [], blockedEnvironmentVariables: [], }, @@ -1422,9 +1422,74 @@ describe('ShellExecutionService environment variables', () => { vi.fn(), new AbortController().signal, true, + { + sanitizationConfig: { + enableEnvironmentVariableRedaction: false, + allowedEnvironmentVariables: [], + blockedEnvironmentVariables: [], + }, + }, + ); + + const cpEnv = mockCpSpawn.mock.calls[0][2].env; + expect(cpEnv).not.toHaveProperty('MY_SENSITIVE_VAR'); + expect(cpEnv).toHaveProperty('PATH', '/test/path'); + expect(cpEnv).toHaveProperty('GEMINI_CLI_TEST_VAR', 'test-value'); + + // Ensure child_process exits + mockChildProcess.emit('exit', 0, null); + mockChildProcess.emit('close', 0, null); + await new Promise(process.nextTick); + }); + + it('should use a sanitized environment when in a GitHub run (SURFACE=Github)', async () => { + // Mock the environment to simulate a GitHub Actions run via SURFACE variable + vi.stubEnv('SURFACE', 'Github'); + vi.stubEnv('MY_SENSITIVE_VAR', 'secret-value'); // This should be stripped out + vi.stubEnv('PATH', '/test/path'); // An essential var that should be kept + vi.stubEnv('GEMINI_CLI_TEST_VAR', 'test-value'); // A test var that should be kept + + vi.resetModules(); + const { ShellExecutionService } = await import( + './shellExecutionService.js' + ); + + // Test pty path + await ShellExecutionService.execute( + 'test-pty-command-surface', + '/', + vi.fn(), + new AbortController().signal, + true, shellExecutionConfig, ); + const ptyEnv = mockPtySpawn.mock.calls[0][2].env; + expect(ptyEnv).not.toHaveProperty('MY_SENSITIVE_VAR'); + expect(ptyEnv).toHaveProperty('PATH', '/test/path'); + expect(ptyEnv).toHaveProperty('GEMINI_CLI_TEST_VAR', 'test-value'); + + // Ensure pty process exits for next test + mockPtyProcess.onExit.mock.calls[0][0]({ exitCode: 0, signal: null }); + await new Promise(process.nextTick); + + // Test child_process path + mockGetPty.mockResolvedValue(null); // Force fallback + await ShellExecutionService.execute( + 'test-cp-command-surface', + '/', + vi.fn(), + new AbortController().signal, + true, + { + sanitizationConfig: { + enableEnvironmentVariableRedaction: false, + allowedEnvironmentVariables: [], + blockedEnvironmentVariables: [], + }, + }, + ); + const cpEnv = mockCpSpawn.mock.calls[0][2].env; expect(cpEnv).not.toHaveProperty('MY_SENSITIVE_VAR'); expect(cpEnv).toHaveProperty('PATH', '/test/path'); From e51f3e11f1f24409c051fc627fe2ec9d478f5509 Mon Sep 17 00:00:00 2001 From: sangwook <73056306+Han5991@users.noreply.github.com> Date: Fri, 9 Jan 2026 07:45:41 +0900 Subject: [PATCH 077/713] fix: remove unsupported 'enabled' key from workflow config (#15611) Co-authored-by: Tommaso Sciortino --- .github/workflows/gemini-automated-issue-dedup.yml | 1 - .github/workflows/gemini-scheduled-issue-dedup.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/gemini-automated-issue-dedup.yml b/.github/workflows/gemini-automated-issue-dedup.yml index b84b5aa94d..0fe02b5530 100644 --- a/.github/workflows/gemini-automated-issue-dedup.yml +++ b/.github/workflows/gemini-automated-issue-dedup.yml @@ -101,7 +101,6 @@ jobs: "FIRESTORE_DATABASE_ID": "(default)", "GOOGLE_APPLICATION_CREDENTIALS": "${GOOGLE_APPLICATION_CREDENTIALS}" }, - "enabled": true, "timeout": 600000 } }, diff --git a/.github/workflows/gemini-scheduled-issue-dedup.yml b/.github/workflows/gemini-scheduled-issue-dedup.yml index 9eea5e0aa0..46a6f4628b 100644 --- a/.github/workflows/gemini-scheduled-issue-dedup.yml +++ b/.github/workflows/gemini-scheduled-issue-dedup.yml @@ -81,7 +81,6 @@ jobs: "FIRESTORE_DATABASE_ID": "(default)", "GOOGLE_APPLICATION_CREDENTIALS": "${GOOGLE_APPLICATION_CREDENTIALS}" }, - "enabled": true, "timeout": 600000 } }, From 26505b580cc905e889e6494eddb75515ae8cd3f1 Mon Sep 17 00:00:00 2001 From: Liqiong Zheng Date: Thu, 8 Jan 2026 15:07:45 -0800 Subject: [PATCH 078/713] docs: Remove redundant and duplicate documentation files (#14699) Co-authored-by: Liqiong Zheng Co-authored-by: Tommaso Sciortino --- docs/cli/configuration.md | 786 --------------------------------- docs/cli/model.md | 2 +- docs/get-started/deployment.md | 143 ------ docs/hooks/best-practices.md | 2 +- docs/hooks/index.md | 3 +- docs/hooks/writing-hooks.md | 2 +- 6 files changed, 5 insertions(+), 933 deletions(-) delete mode 100644 docs/cli/configuration.md delete mode 100644 docs/get-started/deployment.md diff --git a/docs/cli/configuration.md b/docs/cli/configuration.md deleted file mode 100644 index 1b7177362c..0000000000 --- a/docs/cli/configuration.md +++ /dev/null @@ -1,786 +0,0 @@ -# Gemini CLI configuration - -Gemini CLI offers several ways to configure its behavior, including environment -variables, command-line arguments, and settings files. This document outlines -the different configuration methods and available settings. - -## Configuration layers - -Configuration is applied in the following order of precedence (lower numbers are -overridden by higher numbers): - -1. **Default values:** Hardcoded defaults within the application. -2. **User settings file:** Global settings for the current user. -3. **Project settings file:** Project-specific settings. -4. **System settings file:** System-wide settings. -5. **Environment variables:** System-wide or session-specific variables, - potentially loaded from `.env` files. -6. **Command-line arguments:** Values passed when launching the CLI. - -## Settings files - -Gemini CLI uses `settings.json` files for persistent configuration. There are -three locations for these files: - -- **User settings file:** - - **Location:** `~/.gemini/settings.json` (where `~` is your home directory). - - **Scope:** Applies to all Gemini CLI sessions for the current user. -- **Project settings file:** - - **Location:** `.gemini/settings.json` within your project's root directory. - - **Scope:** Applies only when running Gemini CLI from that specific project. - Project settings override user settings. -- **System settings file:** - - **Location:** `/etc/gemini-cli/settings.json` (Linux), - `C:\ProgramData\gemini-cli\settings.json` (Windows) or - `/Library/Application Support/GeminiCli/settings.json` (macOS). The path can - be overridden using the `GEMINI_CLI_SYSTEM_SETTINGS_PATH` environment - variable. - - **Scope:** Applies to all Gemini CLI sessions on the system, for all users. - System settings override user and project settings. May be useful for system - administrators at enterprises to have controls over users' Gemini CLI - setups. - -**Note on environment variables in settings:** String values within your -`settings.json` files can reference environment variables using either -`$VAR_NAME` or `${VAR_NAME}` syntax. These variables will be automatically -resolved when the settings are loaded. For example, if you have an environment -variable `MY_API_TOKEN`, you could use it in `settings.json` like this: -`"apiKey": "$MY_API_TOKEN"`. - -### The `.gemini` directory in your project - -In addition to a project settings file, a project's `.gemini` directory can -contain other project-specific files related to Gemini CLI's operation, such as: - -- [Custom sandbox profiles](#sandboxing) (e.g., - `.gemini/sandbox-macos-custom.sb`, `.gemini/sandbox.Dockerfile`). - -### Available settings in `settings.json`: - -- **`contextFileName`** (string or array of strings): - - **Description:** Specifies the filename for context files (e.g., - `GEMINI.md`, `AGENTS.md`). Can be a single filename or a list of accepted - filenames. - - **Default:** `GEMINI.md` - - **Example:** `"contextFileName": "AGENTS.md"` - -- **`bugCommand`** (object): - - **Description:** Overrides the default URL for the `/bug` command. - - **Default:** - `"urlTemplate": "https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.yml&title={title}&info={info}"` - - **Properties:** - - **`urlTemplate`** (string): A URL that can contain `{title}` and `{info}` - placeholders. - - **Example:** - ```json - "bugCommand": { - "urlTemplate": "https://bug.example.com/new?title={title}&info={info}" - } - ``` - -- **`fileFiltering`** (object): - - **Description:** Controls git-aware file filtering behavior for @ commands - and file discovery tools. - - **Default:** `"respectGitIgnore": true, "enableRecursiveFileSearch": true` - - **Properties:** - - **`respectGitIgnore`** (boolean): Whether to respect .gitignore patterns - when discovering files. When set to `true`, git-ignored files (like - `node_modules/`, `dist/`, `.env`) are automatically excluded from @ - commands and file listing operations. - - **`enableRecursiveFileSearch`** (boolean): Whether to enable searching - recursively for filenames under the current tree when completing @ - prefixes in the prompt. - - **Example:** - ```json - "fileFiltering": { - "respectGitIgnore": true, - "enableRecursiveFileSearch": false - } - ``` - -- **`coreTools`** (array of strings): - - **Description:** Allows you to specify a list of core tool names that should - be made available to the model. This can be used to restrict the set of - built-in tools. See [Built-in Tools](../core/tools-api.md#built-in-tools) - for a list of core tools. You can also specify command-specific restrictions - for tools that support it, like the `ShellTool`. For example, - `"coreTools": ["ShellTool(ls -l)"]` will only allow the `ls -l` command to - be executed. - - **Default:** All tools available for use by the Gemini model. - - **Example:** `"coreTools": ["ReadFileTool", "GlobTool", "ShellTool(ls)"]`. - -- **`excludeTools`** (array of strings): - - **Description:** Allows you to specify a list of core tool names that should - be excluded from the model. A tool listed in both `excludeTools` and - `coreTools` is excluded. You can also specify command-specific restrictions - for tools that support it, like the `ShellTool`. For example, - `"excludeTools": ["ShellTool(rm -rf)"]` will block the `rm -rf` command. - - **Default**: No tools excluded. - - **Example:** `"excludeTools": ["run_shell_command", "findFiles"]`. - - **Security Note:** Command-specific restrictions in `excludeTools` for - `run_shell_command` are based on simple string matching and can be easily - bypassed. This feature is **not a security mechanism** and should not be - relied upon to safely execute untrusted code. It is recommended to use - `coreTools` to explicitly select commands that can be executed. - -- **`allowMCPServers`** (array of strings): - - **Description:** Allows you to specify a list of MCP server names that - should be made available to the model. This can be used to restrict the set - of MCP servers to connect to. Note that this will be ignored if - `--allowed-mcp-server-names` is set. - - **Default:** All MCP servers are available for use by the Gemini model. - - **Example:** `"allowMCPServers": ["myPythonServer"]`. - - **Security Note:** This uses simple string matching on MCP server names, - which can be modified. If you're a system administrator looking to prevent - users from bypassing this, consider configuring the `mcpServers` at the - system settings level such that the user will not be able to configure any - MCP servers of their own. This should not be used as an airtight security - mechanism. - -- **`excludeMCPServers`** (array of strings): - - **Description:** Allows you to specify a list of MCP server names that - should be excluded from the model. A server listed in both - `excludeMCPServers` and `allowMCPServers` is excluded. Note that this will - be ignored if `--allowed-mcp-server-names` is set. - - **Default**: No MCP servers excluded. - - **Example:** `"excludeMCPServers": ["myNodeServer"]`. - - **Security note:** This uses simple string matching on MCP server names, - which can be modified. If you're a system administrator looking to prevent - users from bypassing this, consider configuring the `mcpServers` at the - system settings level such that the user will not be able to configure any - MCP servers of their own. This should not be used as an airtight security - mechanism. - -- **`autoAccept`** (boolean): - - **Description:** Controls whether the CLI automatically accepts and executes - tool calls that are considered safe (e.g., read-only operations) without - explicit user confirmation. If set to `true`, the CLI will bypass the - confirmation prompt for tools deemed safe. - - **Default:** `false` - - **Example:** `"autoAccept": true` - -- **`theme`** (string): - - **Description:** Sets the visual [theme](./themes.md) for Gemini CLI. - - **Default:** `"Default"` - - **Example:** `"theme": "GitHub"` - -- **`vimMode`** (boolean): - - **Description:** Enables or disables vim mode for input editing. When - enabled, the input area supports vim-style navigation and editing commands - with NORMAL and INSERT modes. The vim mode status is displayed in the footer - and persists between sessions. - - **Default:** `false` - - **Example:** `"vimMode": true` - -- **`sandbox`** (boolean or string): - - **Description:** Controls whether and how to use sandboxing for tool - execution. If set to `true`, Gemini CLI uses a pre-built - `gemini-cli-sandbox` Docker image. For more information, see - [Sandboxing](#sandboxing). - - **Default:** `false` - - **Example:** `"sandbox": "docker"` - -- **`toolDiscoveryCommand`** (string): - - **Description:** Defines a custom shell command for discovering tools from - your project. The shell command must return on `stdout` a JSON array of - [function declarations](https://ai.google.dev/gemini-api/docs/function-calling#function-declarations). - Tool wrappers are optional. - - **Default:** Empty - - **Example:** `"toolDiscoveryCommand": "bin/get_tools"` - -- **`toolCallCommand`** (string): - - **Description:** Defines a custom shell command for calling a specific tool - that was discovered using `toolDiscoveryCommand`. The shell command must - meet the following criteria: - - It must take function `name` (exactly as in - [function declaration](https://ai.google.dev/gemini-api/docs/function-calling#function-declarations)) - as first command line argument. - - It must read function arguments as JSON on `stdin`, analogous to - [`functionCall.args`](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#functioncall). - - It must return function output as JSON on `stdout`, analogous to - [`functionResponse.response.content`](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#functionresponse). - - **Default:** Empty - - **Example:** `"toolCallCommand": "bin/call_tool"` - -- **`mcpServers`** (object): - - **Description:** Configures connections to one or more Model-Context - Protocol (MCP) servers for discovering and using custom tools. Gemini CLI - attempts to connect to each configured MCP server to discover available - tools. If multiple MCP servers expose a tool with the same name, the tool - names will be prefixed with the server alias you defined in the - configuration (e.g., `serverAlias__actualToolName`) to avoid conflicts. Note - that the system might strip certain schema properties from MCP tool - definitions for compatibility. - - **Default:** Empty - - **Properties:** - - **``** (object): The server parameters for the named server. - - `command` (string, required): The command to execute to start the MCP - server. - - `args` (array of strings, optional): Arguments to pass to the command. - - `env` (object, optional): Environment variables to set for the server - process. - - `cwd` (string, optional): The working directory in which to start the - server. - - `timeout` (number, optional): Timeout in milliseconds for requests to - this MCP server. - - `trust` (boolean, optional): Trust this server and bypass all tool call - confirmations. - - `includeTools` (array of strings, optional): List of tool names to - include from this MCP server. When specified, only the tools listed here - will be available from this server (whitelist behavior). If not - specified, all tools from the server are enabled by default. - - `excludeTools` (array of strings, optional): List of tool names to - exclude from this MCP server. Tools listed here will not be available to - the model, even if they are exposed by the server. **Note:** - `excludeTools` takes precedence over `includeTools` - if a tool is in - both lists, it will be excluded. - - **Example:** - ```json - "mcpServers": { - "myPythonServer": { - "command": "python", - "args": ["mcp_server.py", "--port", "8080"], - "cwd": "./mcp_tools/python", - "timeout": 5000, - "includeTools": ["safe_tool", "file_reader"], - }, - "myNodeServer": { - "command": "node", - "args": ["mcp_server.js"], - "cwd": "./mcp_tools/node", - "excludeTools": ["dangerous_tool", "file_deleter"] - }, - "myDockerServer": { - "command": "docker", - "args": ["run", "-i", "--rm", "-e", "API_KEY", "ghcr.io/foo/bar"], - "env": { - "API_KEY": "$MY_API_TOKEN" - } - } - } - ``` - -- **`checkpointing`** (object): - - **Description:** Configures the checkpointing feature, which allows you to - save and restore conversation and file states. See the - [Checkpointing documentation](./checkpointing.md) for more details. - - **Default:** `{"enabled": false}` - - **Properties:** - - **`enabled`** (boolean): When `true`, the `/restore` command is available. - -- **`preferredEditor`** (string): - - **Description:** Specifies the preferred editor to use for viewing diffs. - - **Default:** `vscode` - - **Example:** `"preferredEditor": "vscode"` - -- **`telemetry`** (object) - - **Description:** Configures logging and metrics collection for Gemini CLI. - For more information, see [Telemetry](./telemetry.md). - - **Default:** - `{"enabled": false, "target": "local", "otlpEndpoint": "http://localhost:4317", "logPrompts": true}` - - **Properties:** - - **`enabled`** (boolean): Whether or not telemetry is enabled. - - **`target`** (string): The destination for collected telemetry. Supported - values are `local` and `gcp`. - - **`otlpEndpoint`** (string): The endpoint for the OTLP Exporter. - - **`logPrompts`** (boolean): Whether or not to include the content of user - prompts in the logs. - - **Example:** - ```json - "telemetry": { - "enabled": true, - "target": "local", - "otlpEndpoint": "http://localhost:16686", - "logPrompts": false - } - ``` -- **`usageStatisticsEnabled`** (boolean): - - **Description:** Enables or disables the collection of usage statistics. See - [Usage Statistics](#usage-statistics) for more information. - - **Default:** `true` - - **Example:** - ```json - "usageStatisticsEnabled": false - ``` - -- **`hideTips`** (boolean): - - **Description:** Enables or disables helpful tips in the CLI interface. - - **Default:** `false` - - **Example:** - - ```json - "hideTips": true - ``` - -- **`hideBanner`** (boolean): - - **Description:** Enables or disables the startup banner (ASCII art logo) in - the CLI interface. - - **Default:** `false` - - **Example:** - - ```json - "hideBanner": true - ``` - -- **`maxSessionTurns`** (number): - - **Description:** Sets the maximum number of turns for a session. If the - session exceeds this limit, the CLI will stop processing and start a new - chat. - - **Default:** `-1` (unlimited) - - **Example:** - ```json - "maxSessionTurns": 10 - ``` - -- **`summarizeToolOutput`** (object): - - **Description:** Enables or disables the summarization of tool output. You - can specify the token budget for the summarization using the `tokenBudget` - setting. - - Note: Currently only the `run_shell_command` tool is supported. - - **Default:** `{}` (Disabled by default) - - **Example:** - ```json - "summarizeToolOutput": { - "run_shell_command": { - "tokenBudget": 2000 - } - } - ``` - -- **`excludedProjectEnvVars`** (array of strings): - - **Description:** Specifies environment variables that should be excluded - from being loaded from project `.env` files. This prevents project-specific - environment variables (like `DEBUG=true`) from interfering with gemini-cli - behavior. Variables from `.gemini/.env` files are never excluded. - - **Default:** `["DEBUG", "DEBUG_MODE"]` - - **Example:** - ```json - "excludedProjectEnvVars": ["DEBUG", "DEBUG_MODE", "NODE_ENV"] - ``` - -- **`context.includeDirectories`** (array of strings): - - **Description:** Specifies an array of additional absolute or relative paths - to include in the workspace context. This allows you to work with files - across multiple directories as if they were one. Paths can use `~` to refer - to the user's home directory. This setting can be combined with the - `--include-directories` command-line flag. - - **Default:** `[]` - - **Example:** - ```json - "context": { - "includeDirectories": [ - "/path/to/another/project", - "../shared-library", - "~/common-utils" - ] - } - ``` - -- **`context.loadMemoryFromIncludeDirectories`** (boolean): - - **Description:** Controls the behavior of the `/memory refresh` command. If - set to `true`, `GEMINI.md` files should be loaded from all directories that - are added. If set to `false`, `GEMINI.md` should only be loaded from the - current directory. - - **Default:** `false` - - **Example:** - ```json - "context": { - "loadMemoryFromIncludeDirectories": true - } - ``` - -### Example `settings.json`: - -```json -{ - "theme": "GitHub", - "sandbox": "docker", - "toolDiscoveryCommand": "bin/get_tools", - "toolCallCommand": "bin/call_tool", - "mcpServers": { - "mainServer": { - "command": "bin/mcp_server.py" - }, - "anotherServer": { - "command": "node", - "args": ["mcp_server.js", "--verbose"] - } - }, - "telemetry": { - "enabled": true, - "target": "local", - "otlpEndpoint": "http://localhost:4317", - "logPrompts": true - }, - "usageStatisticsEnabled": true, - "hideTips": false, - "hideBanner": false, - "maxSessionTurns": 10, - "summarizeToolOutput": { - "run_shell_command": { - "tokenBudget": 100 - } - }, - "excludedProjectEnvVars": ["DEBUG", "DEBUG_MODE", "NODE_ENV"], - "context": { - "includeDirectories": ["path/to/dir1", "~/path/to/dir2", "../path/to/dir3"], - "loadMemoryFromIncludeDirectories": true - } -} -``` - -## Shell history - -The CLI keeps a history of shell commands you run. To avoid conflicts between -different projects, this history is stored in a project-specific directory -within your user's home folder. - -- **Location:** `~/.gemini/tmp//shell_history` - - `` is a unique identifier generated from your project's root - path. - - The history is stored in a file named `shell_history`. - -## Environment variables and `.env` files - -Environment variables are a common way to configure applications, especially for -sensitive information like API keys or for settings that might change between -environments. - -The CLI automatically loads environment variables from an `.env` file. The -loading order is: - -1. `.env` file in the current working directory. -2. If not found, it searches upwards in parent directories until it finds an - `.env` file or reaches the project root (identified by a `.git` folder) or - the home directory. -3. If still not found, it looks for `~/.env` (in the user's home directory). - -**Environment variable exclusion:** Some environment variables (like `DEBUG` and -`DEBUG_MODE`) are automatically excluded from being loaded from project `.env` -files to prevent interference with gemini-cli behavior. Variables from -`.gemini/.env` files are never excluded. You can customize this behavior using -the `excludedProjectEnvVars` setting in your `settings.json` file. - -- **`GEMINI_API_KEY`** (Required): - - Your API key for the Gemini API. - - **Crucial for operation.** The CLI will not function without it. - - Set this in your shell profile (e.g., `~/.bashrc`, `~/.zshrc`) or an `.env` - file. -- **`GEMINI_MODEL`**: - - Specifies the default Gemini model to use. - - Overrides the hardcoded default - - Example: `export GEMINI_MODEL="gemini-2.5-flash"` -- **`GEMINI_CLI_CUSTOM_HEADERS`**: - - Adds extra HTTP headers to Gemini API and Code Assist requests. - - Accepts a comma-separated list of `Name: value` pairs. - - Example: - `export GEMINI_CLI_CUSTOM_HEADERS="X-My-Header: foo, X-Trace-ID: abc123"`. -- **`GEMINI_API_KEY_AUTH_MECHANISM`**: - - Specifies how the API key should be sent for authentication when using - `AuthType.USE_GEMINI` or `AuthType.USE_VERTEX_AI`. - - Valid values are `x-goog-api-key` (default) or `bearer`. - - If set to `bearer`, the API key will be sent in the - `Authorization: Bearer ` header. - - Example: `export GEMINI_API_KEY_AUTH_MECHANISM="bearer"` -- **`GOOGLE_API_KEY`**: - - Your Google Cloud API key. - - Required for using Vertex AI in express mode. - - Ensure you have the necessary permissions. - - Example: `export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"`. -- **`GOOGLE_CLOUD_PROJECT`**: - - Your Google Cloud Project ID. - - Required for using Code Assist or Vertex AI. - - If using Vertex AI, ensure you have the necessary permissions in this - project. - - **Cloud shell note:** When running in a Cloud Shell environment, this - variable defaults to a special project allocated for Cloud Shell users. If - you have `GOOGLE_CLOUD_PROJECT` set in your global environment in Cloud - Shell, it will be overridden by this default. To use a different project in - Cloud Shell, you must define `GOOGLE_CLOUD_PROJECT` in a `.env` file. - - Example: `export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`. -- **`GOOGLE_APPLICATION_CREDENTIALS`** (string): - - **Description:** The path to your Google Application Credentials JSON file. - - **Example:** - `export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credentials.json"` -- **`OTLP_GOOGLE_CLOUD_PROJECT`**: - - Your Google Cloud Project ID for Telemetry in Google Cloud - - Example: `export OTLP_GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`. -- **`GOOGLE_CLOUD_LOCATION`**: - - Your Google Cloud Project Location (e.g., us-central1). - - Required for using Vertex AI in non express mode. - - Example: `export GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION"`. -- **`GEMINI_SANDBOX`**: - - Alternative to the `sandbox` setting in `settings.json`. - - Accepts `true`, `false`, `docker`, `podman`, or a custom command string. -- **`HTTP_PROXY` / `HTTPS_PROXY`**: - - Specifies the proxy server to use for outgoing HTTP/HTTPS requests. - - Example: `export HTTPS_PROXY="http://proxy.example.com:8080"` -- **`SEATBELT_PROFILE`** (macOS specific): - - Switches the Seatbelt (`sandbox-exec`) profile on macOS. - - `permissive-open`: (Default) Restricts writes to the project folder (and a - few other folders, see - `packages/cli/src/utils/sandbox-macos-permissive-open.sb`) but allows other - operations. - - `strict`: Uses a strict profile that declines operations by default. - - ``: Uses a custom profile. To define a custom profile, create - a file named `sandbox-macos-.sb` in your project's `.gemini/` - directory (e.g., `my-project/.gemini/sandbox-macos-custom.sb`). -- **`DEBUG` or `DEBUG_MODE`** (often used by underlying libraries or the CLI - itself): - - Set to `true` or `1` to enable verbose debug logging, which can be helpful - for troubleshooting. - - **Note:** These variables are automatically excluded from project `.env` - files by default to prevent interference with gemini-cli behavior. Use - `.gemini/.env` files if you need to set these for gemini-cli specifically. -- **`NO_COLOR`**: - - Set to any value to disable all color output in the CLI. -- **`CLI_TITLE`**: - - Set to a string to customize the title of the CLI. -- **`CODE_ASSIST_ENDPOINT`**: - - Specifies the endpoint for the code assist server. - - This is useful for development and testing. -- **`GEMINI_SYSTEM_MD`**: - - Overrides the base system prompt with the contents of a Markdown file. - - If set to `1` or `true`, it uses the file at `.gemini/system.md`. - - If set to a file path, it uses that file. The path can be absolute or - relative. `~` is supported for the home directory. - - The specified file must exist. -- **`GEMINI_WRITE_SYSTEM_MD`**: - - Writes the default system prompt to a file. This is useful for getting a - template to customize. - - If set to `1` or `true`, it writes to `.gemini/system.md`. - - If set to a file path, it writes to that path. The path can be absolute or - relative. `~` is supported for the home directory. **Note: This will - overwrite the file if it already exists.** - -## Command-line arguments - -Arguments passed directly when running the CLI can override other configurations -for that specific session. - -- **`--model `** (**`-m `**): - - Specifies the Gemini model to use for this session. - - Example: `npm start -- --model gemini-1.5-pro-latest` -- **`--prompt `** (**`-p `**): - - Used to pass a prompt directly to the command. This invokes Gemini CLI in a - non-interactive mode. -- **`--prompt-interactive `** (**`-i `**): - - Starts an interactive session with the provided prompt as the initial input. - - The prompt is processed within the interactive session, not before it. - - Cannot be used when piping input from stdin. - - Example: `gemini -i "explain this code"` -- **`--sandbox`** (**`-s`**): - - Enables sandbox mode for this session. -- **`--sandbox-image`**: - - Sets the sandbox image URI. -- **`--debug`** (**`-d`**): - - Enables debug mode for this session, providing more verbose output. -- **`--all-files`** (**`-a`**): - - If set, recursively includes all files within the current directory as - context for the prompt. -- **`--help`** (or **`-h`**): - - Displays help information about command-line arguments. -- **`--show-memory-usage`**: - - Displays the current memory usage. -- **`--yolo`**: - - Enables YOLO mode, which automatically approves all tool calls. -- **`--telemetry`**: - - Enables [telemetry](./telemetry.md). -- **`--telemetry-target`**: - - Sets the telemetry target. See [telemetry](./telemetry.md) for more - information. -- **`--telemetry-otlp-endpoint`**: - - Sets the OTLP endpoint for telemetry. See [telemetry](./telemetry.md) for - more information. -- **`--telemetry-log-prompts`**: - - Enables logging of prompts for telemetry. See [telemetry](./telemetry.md) - for more information. -- **`--extensions `** (**`-e `**): - - Specifies a list of extensions to use for the session. If not provided, all - available extensions are used. - - Use the special term `gemini -e none` to disable all extensions. - - Example: `gemini -e my-extension -e my-other-extension` -- **`--list-extensions`** (**`-l`**): - - Lists all available extensions and exits. -- **`--include-directories `**: - - Includes additional directories in the workspace for multi-directory - support. - - Can be specified multiple times or as comma-separated values. - - 5 directories can be added at maximum. - - Example: `--include-directories /path/to/project1,/path/to/project2` or - `--include-directories /path/to/project1 --include-directories /path/to/project2` -- **`--version`**: - - Displays the version of the CLI. - -## Context files (hierarchical instructional context) - -While not strictly configuration for the CLI's _behavior_, context files -(defaulting to `GEMINI.md` but configurable via the `contextFileName` setting) -are crucial for configuring the _instructional context_ (also referred to as -"memory") provided to the Gemini model. This powerful feature allows you to give -project-specific instructions, coding style guides, or any relevant background -information to the AI, making its responses more tailored and accurate to your -needs. The CLI includes UI elements, such as an indicator in the footer showing -the number of loaded context files, to keep you informed about the active -context. - -- **Purpose:** These Markdown files contain instructions, guidelines, or context - that you want the Gemini model to be aware of during your interactions. The - system is designed to manage this instructional context hierarchically. - -### Example context file content (e.g., `GEMINI.md`) - -Here's a conceptual example of what a context file at the root of a TypeScript -project might contain: - -```markdown -# Project: My Awesome TypeScript Library - -## General Instructions: - -- When generating new TypeScript code, please follow the existing coding style. -- Ensure all new functions and classes have JSDoc comments. -- Prefer functional programming paradigms where appropriate. -- All code should be compatible with TypeScript 5.0 and Node.js 20+. - -## Coding Style: - -- Use 2 spaces for indentation. -- Interface names should be prefixed with `I` (e.g., `IUserService`). -- Private class members should be prefixed with an underscore (`_`). -- Always use strict equality (`===` and `!==`). - -## Specific Component: `src/api/client.ts` - -- This file handles all outbound API requests. -- When adding new API call functions, ensure they include robust error handling - and logging. -- Use the existing `fetchWithRetry` utility for all GET requests. - -## Regarding Dependencies: - -- Avoid introducing new external dependencies unless absolutely necessary. -- If a new dependency is required, please state the reason. -``` - -This example demonstrates how you can provide general project context, specific -coding conventions, and even notes about particular files or components. The -more relevant and precise your context files are, the better the AI can assist -you. Project-specific context files are highly encouraged to establish -conventions and context. - -- **Hierarchical loading and precedence:** The CLI implements a sophisticated - hierarchical memory system by loading context files (e.g., `GEMINI.md`) from - several locations. Content from files lower in this list (more specific) - typically overrides or supplements content from files higher up (more - general). The exact concatenation order and final context can be inspected - using the `/memory show` command. The typical loading order is: - 1. **Global context file:** - - Location: `~/.gemini/` (e.g., `~/.gemini/GEMINI.md` in - your user home directory). - - Scope: Provides default instructions for all your projects. - 2. **Project root and ancestors context files:** - - Location: The CLI searches for the configured context file in the - current working directory and then in each parent directory up to either - the project root (identified by a `.git` folder) or your home directory. - - Scope: Provides context relevant to the entire project or a significant - portion of it. - 3. **Sub-directory context files (contextual/local):** - - Location: The CLI also scans for the configured context file in - subdirectories _below_ the current working directory (respecting common - ignore patterns like `node_modules`, `.git`, etc.). The breadth of this - search is limited to 200 directories by default, but can be configured - with a `memoryDiscoveryMaxDirs` field in your `settings.json` file. - - Scope: Allows for highly specific instructions relevant to a particular - component, module, or subsection of your project. -- **Concatenation and UI indication:** The contents of all found context files - are concatenated (with separators indicating their origin and path) and - provided as part of the system prompt to the Gemini model. The CLI footer - displays the count of loaded context files, giving you a quick visual cue - about the active instructional context. -- **Importing content:** You can modularize your context files by importing - other Markdown files using the `@path/to/file.md` syntax. For more details, - see the [Memory Import Processor documentation](../core/memport.md). -- **Commands for memory management:** - - Use `/memory refresh` to force a re-scan and reload of all context files - from all configured locations. This updates the AI's instructional context. - - Use `/memory show` to display the combined instructional context currently - loaded, allowing you to verify the hierarchy and content being used by the - AI. - - See the [Commands documentation](./commands.md#memory) for full details on - the `/memory` command and its sub-commands (`show` and `refresh`). - -By understanding and utilizing these configuration layers and the hierarchical -nature of context files, you can effectively manage the AI's memory and tailor -the Gemini CLI's responses to your specific needs and projects. - -## Sandboxing - -The Gemini CLI can execute potentially unsafe operations (like shell commands -and file modifications) within a sandboxed environment to protect your system. - -Sandboxing is disabled by default, but you can enable it in a few ways: - -- Using `--sandbox` or `-s` flag. -- Setting `GEMINI_SANDBOX` environment variable. -- Sandbox is enabled in `--yolo` mode by default. - -By default, it uses a pre-built `gemini-cli-sandbox` Docker image. - -For project-specific sandboxing needs, you can create a custom Dockerfile at -`.gemini/sandbox.Dockerfile` in your project's root directory. This Dockerfile -can be based on the base sandbox image: - -```dockerfile -FROM gemini-cli-sandbox - -# Add your custom dependencies or configurations here -# For example: -# RUN apt-get update && apt-get install -y some-package -# COPY ./my-config /app/my-config -``` - -When `.gemini/sandbox.Dockerfile` exists, you can use `BUILD_SANDBOX` -environment variable when running Gemini CLI to automatically build the custom -sandbox image: - -```bash -BUILD_SANDBOX=1 gemini -s -``` - -## Usage statistics - -To help us improve the Gemini CLI, we collect anonymized usage statistics. This -data helps us understand how the CLI is used, identify common issues, and -prioritize new features. - -**What we collect:** - -- **Tool calls:** We log the names of the tools that are called, whether they - succeed or fail, and how long they take to execute. We do not collect the - arguments passed to the tools or any data returned by them. -- **API requests:** We log the Gemini model used for each request, the duration - of the request, and whether it was successful. We do not collect the content - of the prompts or responses. -- **Session information:** We collect information about the configuration of the - CLI, such as the enabled tools and the approval mode. - -**What we DON'T collect:** - -- **Personally identifiable information (PII):** We do not collect any personal - information, such as your name, email address, or API keys. -- **Prompt and response content:** We do not log the content of your prompts or - the responses from the Gemini model. -- **File content:** We do not log the content of any files that are read or - written by the CLI. - -**How to opt out:** - -You can opt out of usage statistics collection at any time by setting the -`usageStatisticsEnabled` property to `false` in your `settings.json` file: - -```json -{ - "usageStatisticsEnabled": false -} -``` diff --git a/docs/cli/model.md b/docs/cli/model.md index 9da7dc4c4f..fd0e950bbb 100644 --- a/docs/cli/model.md +++ b/docs/cli/model.md @@ -39,7 +39,7 @@ To enable Gemini 3 Pro and Gemini 3 Flash (if available), enable You can also use the `--model` flag to specify a particular Gemini model on startup. For more details, refer to the -[configuration documentation](./configuration.md). +[configuration documentation](../get-started/configuration.md). Changes to these settings will be applied to all subsequent interactions with Gemini CLI. diff --git a/docs/get-started/deployment.md b/docs/get-started/deployment.md deleted file mode 100644 index 670a3cf8c0..0000000000 --- a/docs/get-started/deployment.md +++ /dev/null @@ -1,143 +0,0 @@ -Note: This page will be replaced by [installation.md](installation.md). - -# Gemini CLI installation, execution, and deployment - -Install and run Gemini CLI. This document provides an overview of Gemini CLI's -installation methods and deployment architecture. - -## How to install and/or run Gemini CLI - -There are several ways to run Gemini CLI. The recommended option depends on how -you intend to use Gemini CLI. - -- As a standard installation. This is the most straightforward method of using - Gemini CLI. -- In a sandbox. This method offers increased security and isolation. -- From the source. This is recommended for contributors to the project. - -### 1. Standard installation (recommended for standard users) - -This is the recommended way for end-users to install Gemini CLI. It involves -downloading the Gemini CLI package from the NPM registry. - -- **Global install:** - - ```bash - npm install -g @google/gemini-cli - ``` - - Then, run the CLI from anywhere: - - ```bash - gemini - ``` - -- **NPX execution:** - - ```bash - # Execute the latest version from NPM without a global install - npx @google/gemini-cli - ``` - -### 2. Run in a sandbox (Docker/Podman) - -For security and isolation, Gemini CLI can be run inside a container. This is -the default way that the CLI executes tools that might have side effects. - -- **Directly from the registry:** You can run the published sandbox image - directly. This is useful for environments where you only have Docker and want - to run the CLI. - ```bash - # Run the published sandbox image - docker run --rm -it us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.1.1 - ``` -- **Using the `--sandbox` flag:** If you have Gemini CLI installed locally - (using the standard installation described above), you can instruct it to run - inside the sandbox container. - ```bash - gemini --sandbox -y -p "your prompt here" - ``` - -### 3. Run from source (recommended for Gemini CLI contributors) - -Contributors to the project will want to run the CLI directly from the source -code. - -- **Development mode:** This method provides hot-reloading and is useful for - active development. - ```bash - # From the root of the repository - npm run start - ``` -- **Production-like mode (Linked package):** This method simulates a global - installation by linking your local package. It's useful for testing a local - build in a production workflow. - - ```bash - # Link the local cli package to your global node_modules - npm link packages/cli - - # Now you can run your local version using the `gemini` command - gemini - ``` - ---- - -### 4. Running the latest Gemini CLI commit from GitHub - -You can run the most recently committed version of Gemini CLI directly from the -GitHub repository. This is useful for testing features still in development. - -```bash -# Execute the CLI directly from the main branch on GitHub -npx https://github.com/google-gemini/gemini-cli -``` - -## Deployment architecture - -The execution methods described above are made possible by the following -architectural components and processes: - -**NPM packages** - -Gemini CLI project is a monorepo that publishes two core packages to the NPM -registry: - -- `@google/gemini-cli-core`: The backend, handling logic and tool execution. -- `@google/gemini-cli`: The user-facing frontend. - -These packages are used when performing the standard installation and when -running Gemini CLI from the source. - -**Build and packaging processes** - -There are two distinct build processes used, depending on the distribution -channel: - -- **NPM publication:** For publishing to the NPM registry, the TypeScript source - code in `@google/gemini-cli-core` and `@google/gemini-cli` is transpiled into - standard JavaScript using the TypeScript Compiler (`tsc`). The resulting - `dist/` directory is what gets published in the NPM package. This is a - standard approach for TypeScript libraries. - -- **GitHub `npx` execution:** When running the latest version of Gemini CLI - directly from GitHub, a different process is triggered by the `prepare` script - in `package.json`. This script uses `esbuild` to bundle the entire application - and its dependencies into a single, self-contained JavaScript file. This - bundle is created on-the-fly on the user's machine and is not checked into the - repository. - -**Docker sandbox image** - -The Docker-based execution method is supported by the `gemini-cli-sandbox` -container image. This image is published to a container registry and contains a -pre-installed, global version of Gemini CLI. - -## Release process - -The release process is automated through GitHub Actions. The release workflow -performs the following actions: - -1. Build the NPM packages using `tsc`. -2. Publish the NPM packages to the artifact registry. -3. Create GitHub releases with bundled assets. diff --git a/docs/hooks/best-practices.md b/docs/hooks/best-practices.md index fef22b8cc1..663066c0c8 100644 --- a/docs/hooks/best-practices.md +++ b/docs/hooks/best-practices.md @@ -852,5 +852,5 @@ console.log(JSON.stringify(sanitizeOutput(hookOutput))); - [Hooks Reference](index.md) - Complete API reference - [Writing Hooks](writing-hooks.md) - Tutorial and examples -- [Configuration](../cli/configuration.md) - Gemini CLI settings +- [Configuration](../get-started/configuration.md) - Gemini CLI settings - [Hooks Design Document](../hooks-design.md) - Technical architecture diff --git a/docs/hooks/index.md b/docs/hooks/index.md index 3470a54196..de3e00e31f 100644 --- a/docs/hooks/index.md +++ b/docs/hooks/index.md @@ -689,5 +689,6 @@ matchers: - [Best Practices](best-practices.md) - Security, performance, and debugging - [Custom Commands](../cli/custom-commands.md) - Create reusable prompt shortcuts -- [Configuration](../cli/configuration.md) - Gemini CLI configuration options +- [Configuration](../get-started/configuration.md) - Gemini CLI configuration + options - [Hooks Design Document](../hooks-design.md) - Technical architecture details diff --git a/docs/hooks/writing-hooks.md b/docs/hooks/writing-hooks.md index e11fb049cb..817dd76ca8 100644 --- a/docs/hooks/writing-hooks.md +++ b/docs/hooks/writing-hooks.md @@ -1040,5 +1040,5 @@ To package hooks as an extension, follow the - [Hooks Reference](index.md) - Complete API reference and configuration - [Best Practices](best-practices.md) - Security, performance, and debugging -- [Configuration](../cli/configuration.md) - Gemini CLI settings +- [Configuration](../get-started/configuration.md) - Gemini CLI settings - [Custom Commands](../cli/custom-commands.md) - Create custom commands From a7f758eb3a42904ea21f6ff009c9fc2b6ccdae6b Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 8 Jan 2026 18:18:31 -0500 Subject: [PATCH 079/713] docs: shorten run command and use published version (#16172) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Tommaso Sciortino --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d3fe95f7e..f46c4569f0 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Learn all about Gemini CLI in our [documentation](https://geminicli.com/docs/). ```bash # Using npx (no installation required) -npx https://github.com/google-gemini/gemini-cli +npx @google/gemini-cli ``` #### Install globally with npm From 84710b19532fec3609b445cd8fa2a8d55e87917a Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Fri, 9 Jan 2026 07:46:29 +0800 Subject: [PATCH 080/713] test(command-registry): increase initialization test timeout (#15979) Signed-off-by: Zhou Qiankang Co-authored-by: Tommaso Sciortino --- packages/a2a-server/src/commands/command-registry.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/a2a-server/src/commands/command-registry.test.ts b/packages/a2a-server/src/commands/command-registry.test.ts index 15958afb20..7a6b1e8091 100644 --- a/packages/a2a-server/src/commands/command-registry.test.ts +++ b/packages/a2a-server/src/commands/command-registry.test.ts @@ -67,7 +67,7 @@ describe('CommandRegistry', () => { expect(mockExtensionsCommand).toHaveBeenCalled(); const command = commandRegistry.get('extensions'); expect(command).toBe(mockExtensionsCommandInstance); - }); + }, 20000); it('should register sub commands on initialization', async () => { const command = commandRegistry.get('extensions list'); From 4ab1b9895add04adef60a790bb7c84532492b14d Mon Sep 17 00:00:00 2001 From: falouu Date: Fri, 9 Jan 2026 00:51:57 +0100 Subject: [PATCH 081/713] Ensure TERM is set to xterm-256color (#15828) --- packages/core/src/services/shellExecutionService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/services/shellExecutionService.ts b/packages/core/src/services/shellExecutionService.ts index 28f9321596..1509072fe5 100644 --- a/packages/core/src/services/shellExecutionService.ts +++ b/packages/core/src/services/shellExecutionService.ts @@ -466,7 +466,7 @@ export class ShellExecutionService { const ptyProcess = ptyInfo.module.spawn(executable, args, { cwd, - name: 'xterm', + name: 'xterm-256color', cols, rows, env: { From ffb80c2426d5627d212b334162e95a0be784a4e0 Mon Sep 17 00:00:00 2001 From: Joseph Sheng Date: Fri, 9 Jan 2026 08:07:57 +0800 Subject: [PATCH 082/713] The telemetry.js script should handle paths that contain spaces (#12078) --- scripts/telemetry.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/telemetry.js b/scripts/telemetry.js index 0fd686beb2..e7a96fef74 100755 --- a/scripts/telemetry.js +++ b/scripts/telemetry.js @@ -6,7 +6,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { execSync } from 'node:child_process'; +import { execFileSync } from 'node:child_process'; import { join } from 'node:path'; import { existsSync, readFileSync } from 'node:fs'; import { GEMINI_DIR } from '@google/gemini-cli-core'; @@ -79,7 +79,7 @@ try { console.log(`🚀 Running telemetry script for target: ${target}.`); const env = { ...process.env }; - execSync(`node ${scriptPath}`, { + execFileSync('node', [scriptPath], { stdio: 'inherit', cwd: projectRoot, env, From 6166d7f6ec6a7ba519fc583e81303597edcc2e7d Mon Sep 17 00:00:00 2001 From: Wesley Tanaka <35872+wtanaka@users.noreply.github.com> Date: Thu, 8 Jan 2026 16:16:00 -0800 Subject: [PATCH 083/713] ci: guard links workflow from running on forks (#15461) Co-authored-by: Tommaso Sciortino --- .github/workflows/links.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/links.yml b/.github/workflows/links.yml index b4aa73aac4..1ed45019f9 100644 --- a/.github/workflows/links.yml +++ b/.github/workflows/links.yml @@ -12,6 +12,8 @@ on: jobs: linkChecker: + if: |- + ${{ github.repository == 'google-gemini/gemini-cli' }} runs-on: 'ubuntu-latest' steps: - uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 From f1ca7fa40a253400a0a96eb6d5833270bec534f0 Mon Sep 17 00:00:00 2001 From: Wesley Tanaka <35872+wtanaka@users.noreply.github.com> Date: Thu, 8 Jan 2026 16:17:58 -0800 Subject: [PATCH 084/713] ci: guard nightly release workflow from running on forks (#15463) Co-authored-by: wtanaka.com Co-authored-by: Tommaso Sciortino --- .github/workflows/release-nightly.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release-nightly.yml b/.github/workflows/release-nightly.yml index 987cb42389..5fe7bca115 100644 --- a/.github/workflows/release-nightly.yml +++ b/.github/workflows/release-nightly.yml @@ -31,6 +31,7 @@ on: jobs: release: + if: "github.repository == 'google-gemini/gemini-cli'" environment: "${{ github.event.inputs.environment || 'prod' }}" runs-on: 'ubuntu-latest' permissions: From 18dd399cb571e47178dda7fc811d9f4a1867991c Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Thu, 8 Jan 2026 19:51:18 -0500 Subject: [PATCH 085/713] Support @ suggestions for subagenets (#16201) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/cli/src/ui/commands/types.ts | 1 + .../src/ui/components/SuggestionsDisplay.tsx | 16 +- .../cli/src/ui/hooks/atCommandProcessor.ts | 22 +- .../hooks/atCommandProcessor_agents.test.ts | 241 ++++++++++++++++++ packages/cli/src/ui/hooks/useAtCompletion.ts | 40 +++ .../ui/hooks/useAtCompletion_agents.test.ts | 117 +++++++++ packages/core/src/index.ts | 3 + 7 files changed, 435 insertions(+), 5 deletions(-) create mode 100644 packages/cli/src/ui/hooks/atCommandProcessor_agents.test.ts create mode 100644 packages/cli/src/ui/hooks/useAtCompletion_agents.test.ts diff --git a/packages/cli/src/ui/commands/types.ts b/packages/cli/src/ui/commands/types.ts index 2165ab377a..a34ff960bb 100644 --- a/packages/cli/src/ui/commands/types.ts +++ b/packages/cli/src/ui/commands/types.ts @@ -163,6 +163,7 @@ export enum CommandKind { BUILT_IN = 'built-in', FILE = 'file', MCP_PROMPT = 'mcp-prompt', + AGENT = 'agent', } // The standardized contract for any command in the system. diff --git a/packages/cli/src/ui/components/SuggestionsDisplay.tsx b/packages/cli/src/ui/components/SuggestionsDisplay.tsx index 1a8c7cab81..96eb554076 100644 --- a/packages/cli/src/ui/components/SuggestionsDisplay.tsx +++ b/packages/cli/src/ui/components/SuggestionsDisplay.tsx @@ -60,8 +60,13 @@ export function SuggestionsDisplay({ ); const visibleSuggestions = suggestions.slice(startIndex, endIndex); + const COMMAND_KIND_SUFFIX: Partial> = { + [CommandKind.MCP_PROMPT]: ' [MCP]', + [CommandKind.AGENT]: ' [Agent]', + }; + const getFullLabel = (s: Suggestion) => - s.label + (s.commandKind === CommandKind.MCP_PROMPT ? ' [MCP]' : ''); + s.label + (s.commandKind ? (COMMAND_KIND_SUFFIX[s.commandKind] ?? '') : ''); const maxLabelLength = Math.max( ...suggestions.map((s) => getFullLabel(s).length), @@ -98,9 +103,12 @@ export function SuggestionsDisplay({ > {labelElement} - {suggestion.commandKind === CommandKind.MCP_PROMPT && ( - [MCP] - )} + {suggestion.commandKind && + COMMAND_KIND_SUFFIX[suggestion.commandKind] && ( + + {COMMAND_KIND_SUFFIX[suggestion.commandKind]} + + )} diff --git a/packages/cli/src/ui/hooks/atCommandProcessor.ts b/packages/cli/src/ui/hooks/atCommandProcessor.ts index 10196a3545..f545c3e103 100644 --- a/packages/cli/src/ui/hooks/atCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/atCommandProcessor.ts @@ -155,6 +155,7 @@ export async function handleAtCommand({ const pathSpecsToRead: string[] = []; const resourceAttachments: DiscoveredMCPResource[] = []; const atPathToResolvedSpecMap = new Map(); + const agentsFound: string[] = []; const fileLabelsForDisplay: string[] = []; const absoluteToRelativePathMap = new Map(); const ignoredByReason: Record = { @@ -208,6 +209,14 @@ export async function handleAtCommand({ return { processedQuery: null, error: errMsg }; } + // Check if this is an Agent reference + const agentRegistry = config.getAgentRegistry?.(); + if (agentRegistry?.getDefinition(pathName)) { + agentsFound.push(pathName); + atPathToResolvedSpecMap.set(originalAtPath, pathName); + continue; + } + // Check if this is an MCP resource reference (serverName:uri format) const resourceMatch = resourceRegistry.findResourceByUri(pathName); if (resourceMatch) { @@ -420,7 +429,11 @@ export async function handleAtCommand({ } // Fallback for lone "@" or completely invalid @-commands resulting in empty initialQueryText - if (pathSpecsToRead.length === 0 && resourceAttachments.length === 0) { + if ( + pathSpecsToRead.length === 0 && + resourceAttachments.length === 0 && + agentsFound.length === 0 + ) { onDebugMessage('No valid file paths found in @ commands to read.'); if (initialQueryText === '@' && query.trim() === '@') { // If the only thing was a lone @, pass original query (which might have spaces) @@ -435,6 +448,13 @@ export async function handleAtCommand({ const processedQueryParts: PartListUnion = [{ text: initialQueryText }]; + if (agentsFound.length > 0) { + const agentNudge = `\n\nThe user has explicitly selected the following agent(s): ${agentsFound.join( + ', ', + )}. Please use the 'delegate_to_agent' tool to delegate the task to the selected agent(s).\n\n`; + processedQueryParts.push({ text: agentNudge }); + } + const resourcePromises = resourceAttachments.map(async (resource) => { const uri = resource.uri; const client = mcpClientManager?.getClient(resource.serverName); diff --git a/packages/cli/src/ui/hooks/atCommandProcessor_agents.test.ts b/packages/cli/src/ui/hooks/atCommandProcessor_agents.test.ts new file mode 100644 index 0000000000..0364cf94f6 --- /dev/null +++ b/packages/cli/src/ui/hooks/atCommandProcessor_agents.test.ts @@ -0,0 +1,241 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { handleAtCommand } from './atCommandProcessor.js'; +import type { + Config, + AgentDefinition, + MessageBus, +} from '@google/gemini-cli-core'; +import { + FileDiscoveryService, + GlobTool, + ReadManyFilesTool, + StandardFileSystemService, + ToolRegistry, + COMMON_IGNORE_PATTERNS, +} from '@google/gemini-cli-core'; +import * as os from 'node:os'; +import type { UseHistoryManagerReturn } from './useHistoryManager.js'; +import * as fsPromises from 'node:fs/promises'; +import * as path from 'node:path'; + +describe('handleAtCommand with Agents', () => { + let testRootDir: string; + let mockConfig: Config; + + const mockAddItem: UseHistoryManagerReturn['addItem'] = vi.fn(); + const mockOnDebugMessage: (message: string) => void = vi.fn(); + + let abortController: AbortController; + + beforeEach(async () => { + vi.resetAllMocks(); + + testRootDir = await fsPromises.mkdtemp( + path.join(os.tmpdir(), 'agent-test-'), + ); + + abortController = new AbortController(); + + const getToolRegistry = vi.fn(); + const mockMessageBus = { + publish: vi.fn(), + subscribe: vi.fn(), + unsubscribe: vi.fn(), + } as unknown as MessageBus; + + const mockAgentRegistry = { + getDefinition: vi.fn((name: string) => { + if (name === 'CodebaseInvestigator') { + return { + name: 'CodebaseInvestigator', + description: 'Investigates codebase', + kind: 'local', + } as AgentDefinition; + } + return undefined; + }), + }; + + mockConfig = { + getToolRegistry, + getTargetDir: () => testRootDir, + isSandboxed: () => false, + getExcludeTools: vi.fn(), + getFileService: () => new FileDiscoveryService(testRootDir), + getFileFilteringRespectGitIgnore: () => true, + getFileFilteringRespectGeminiIgnore: () => true, + getFileFilteringOptions: () => ({ + respectGitIgnore: true, + respectGeminiIgnore: true, + }), + getFileSystemService: () => new StandardFileSystemService(), + getEnableRecursiveFileSearch: vi.fn(() => true), + getWorkspaceContext: () => ({ + isPathWithinWorkspace: () => true, + getDirectories: () => [testRootDir], + }), + getMcpServers: () => ({}), + getMcpServerCommand: () => undefined, + getPromptRegistry: () => ({ + getPromptsByServer: () => [], + }), + getDebugMode: () => false, + getFileExclusions: () => ({ + getCoreIgnorePatterns: () => COMMON_IGNORE_PATTERNS, + getDefaultExcludePatterns: () => [], + getGlobExcludes: () => [], + buildExcludePatterns: () => [], + getReadManyFilesExcludes: () => [], + }), + getUsageStatisticsEnabled: () => false, + getEnableExtensionReloading: () => false, + getResourceRegistry: () => ({ + findResourceByUri: () => undefined, + getAllResources: () => [], + }), + getMcpClientManager: () => ({ + getClient: () => undefined, + }), + getAgentRegistry: () => mockAgentRegistry, + getMessageBus: () => mockMessageBus, + } as unknown as Config; + + const registry = new ToolRegistry(mockConfig, mockMessageBus); + registry.registerTool(new ReadManyFilesTool(mockConfig, mockMessageBus)); + registry.registerTool(new GlobTool(mockConfig, mockMessageBus)); + getToolRegistry.mockReturnValue(registry); + }); + + afterEach(async () => { + abortController.abort(); + await fsPromises.rm(testRootDir, { recursive: true, force: true }); + }); + + it('should detect agent reference and add nudge message', async () => { + const query = 'Please help me @CodebaseInvestigator'; + + const result = await handleAtCommand({ + query, + config: mockConfig, + addItem: mockAddItem, + onDebugMessage: mockOnDebugMessage, + messageId: 123, + signal: abortController.signal, + }); + + expect(result.processedQuery).toBeDefined(); + const parts = result.processedQuery; + + if (!Array.isArray(parts)) { + throw new Error('processedQuery should be an array'); + } + + // Check if the query text is preserved + const firstPart = parts[0]; + if ( + typeof firstPart === 'object' && + firstPart !== null && + 'text' in firstPart + ) { + expect((firstPart as { text: string }).text).toContain( + 'Please help me @CodebaseInvestigator', + ); + } else { + throw new Error('First part should be a text part'); + } + + // Check if the nudge message is added + const nudgePart = parts.find( + (p) => + typeof p === 'object' && + p !== null && + 'text' in p && + (p as { text: string }).text.includes(''), + ); + expect(nudgePart).toBeDefined(); + if (nudgePart && typeof nudgePart === 'object' && 'text' in nudgePart) { + expect((nudgePart as { text: string }).text).toContain( + 'The user has explicitly selected the following agent(s): CodebaseInvestigator', + ); + } + }); + + it('should handle multiple agents', async () => { + // Mock another agent + const mockAgentRegistry = mockConfig.getAgentRegistry() as { + getDefinition: (name: string) => AgentDefinition | undefined; + }; + mockAgentRegistry.getDefinition = vi.fn((name: string) => { + if (name === 'CodebaseInvestigator' || name === 'AnotherAgent') { + return { name, description: 'desc', kind: 'local' } as AgentDefinition; + } + return undefined; + }); + + const query = '@CodebaseInvestigator and @AnotherAgent'; + const result = await handleAtCommand({ + query, + config: mockConfig, + addItem: mockAddItem, + onDebugMessage: mockOnDebugMessage, + messageId: 124, + signal: abortController.signal, + }); + + const parts = result.processedQuery; + if (!Array.isArray(parts)) { + throw new Error('processedQuery should be an array'); + } + + const nudgePart = parts.find( + (p) => + typeof p === 'object' && + p !== null && + 'text' in p && + (p as { text: string }).text.includes(''), + ); + expect(nudgePart).toBeDefined(); + if (nudgePart && typeof nudgePart === 'object' && 'text' in nudgePart) { + expect((nudgePart as { text: string }).text).toContain( + 'CodebaseInvestigator, AnotherAgent', + ); + } + }); + + it('should not treat non-agents as agents', async () => { + const query = '@UnknownAgent'; + // This should fail to resolve and fallback or error depending on file search + // Since it's not a file, handleAtCommand logic for files will run. + // It will likely log debug message about not finding file/glob. + // But critical for this test: it should NOT add the agent nudge. + + const result = await handleAtCommand({ + query, + config: mockConfig, + addItem: mockAddItem, + onDebugMessage: mockOnDebugMessage, + messageId: 125, + signal: abortController.signal, + }); + + const parts = result.processedQuery; + if (!Array.isArray(parts)) { + throw new Error('processedQuery should be an array'); + } + + const nudgePart = parts.find( + (p) => + typeof p === 'object' && + p !== null && + 'text' in p && + (p as { text: string }).text.includes(''), + ); + expect(nudgePart).toBeUndefined(); + }); +}); diff --git a/packages/cli/src/ui/hooks/useAtCompletion.ts b/packages/cli/src/ui/hooks/useAtCompletion.ts index c361089947..dcb6dfa478 100644 --- a/packages/cli/src/ui/hooks/useAtCompletion.ts +++ b/packages/cli/src/ui/hooks/useAtCompletion.ts @@ -9,6 +9,7 @@ import type { Config, FileSearch } from '@google/gemini-cli-core'; import { FileSearchFactory, escapePath } from '@google/gemini-cli-core'; import type { Suggestion } from '../components/SuggestionsDisplay.js'; import { MAX_SUGGESTIONS_TO_SHOW } from '../components/SuggestionsDisplay.js'; +import { CommandKind } from '../commands/types.js'; import { AsyncFzf } from 'fzf'; export enum AtCompletionStatus { @@ -127,6 +128,18 @@ function buildResourceCandidates( return resources; } +function buildAgentCandidates(config?: Config): Suggestion[] { + const registry = config?.getAgentRegistry?.(); + if (!registry) { + return []; + } + return registry.getAllDefinitions().map((def) => ({ + label: def.name, + value: def.name, + commandKind: CommandKind.AGENT, + })); +} + async function searchResourceCandidates( pattern: string, candidates: ResourceSuggestionCandidate[], @@ -153,6 +166,26 @@ async function searchResourceCandidates( ); } +async function searchAgentCandidates( + pattern: string, + candidates: Suggestion[], +): Promise { + if (candidates.length === 0) { + return []; + } + const normalizedPattern = pattern.toLowerCase(); + if (!normalizedPattern) { + return candidates.slice(0, MAX_SUGGESTIONS_TO_SHOW); + } + const fzf = new AsyncFzf(candidates, { + selector: (s: Suggestion) => s.label, + }); + const results = await fzf.find(normalizedPattern, { + limit: MAX_SUGGESTIONS_TO_SHOW, + }); + return results.map((r: { item: Suggestion }) => r.item); +} + export function useAtCompletion(props: UseAtCompletionProps): void { const { enabled, @@ -283,7 +316,14 @@ export function useAtCompletion(props: UseAtCompletionProps): void { value: suggestion.value.replace(/^@/, ''), })); + const agentCandidates = buildAgentCandidates(config); + const agentSuggestions = await searchAgentCandidates( + state.pattern ?? '', + agentCandidates, + ); + const combinedSuggestions = [ + ...agentSuggestions, ...fileSuggestions, ...resourceSuggestions, ]; diff --git a/packages/cli/src/ui/hooks/useAtCompletion_agents.test.ts b/packages/cli/src/ui/hooks/useAtCompletion_agents.test.ts new file mode 100644 index 0000000000..53b416ce6a --- /dev/null +++ b/packages/cli/src/ui/hooks/useAtCompletion_agents.test.ts @@ -0,0 +1,117 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; +import { useState } from 'react'; +import { renderHook } from '../../test-utils/render.js'; +import { waitFor } from '../../test-utils/async.js'; +import { useAtCompletion } from './useAtCompletion.js'; +import type { Config, AgentDefinition } from '@google/gemini-cli-core'; +import { createTmpDir, cleanupTmpDir } from '@google/gemini-cli-test-utils'; +import type { Suggestion } from '../components/SuggestionsDisplay.js'; +import { CommandKind } from '../commands/types.js'; + +// Test harness to capture the state from the hook's callbacks. +function useTestHarnessForAtCompletion( + enabled: boolean, + pattern: string, + config: Config | undefined, + cwd: string, +) { + const [suggestions, setSuggestions] = useState([]); + const [isLoadingSuggestions, setIsLoadingSuggestions] = useState(false); + + useAtCompletion({ + enabled, + pattern, + config, + cwd, + setSuggestions, + setIsLoadingSuggestions, + }); + + return { suggestions, isLoadingSuggestions }; +} + +describe('useAtCompletion with Agents', () => { + let testRootDir: string; + let mockConfig: Config; + + beforeEach(() => { + const mockAgentRegistry = { + getAllDefinitions: vi.fn(() => [ + { + name: 'CodebaseInvestigator', + description: 'Investigates codebase', + kind: 'local', + } as AgentDefinition, + { + name: 'OtherAgent', + description: 'Another agent', + kind: 'local', + } as AgentDefinition, + ]), + }; + + mockConfig = { + getFileFilteringOptions: vi.fn(() => ({ + respectGitIgnore: true, + respectGeminiIgnore: true, + })), + getEnableRecursiveFileSearch: () => true, + getFileFilteringDisableFuzzySearch: () => false, + getResourceRegistry: vi.fn().mockReturnValue({ + getAllResources: () => [], + }), + getAgentRegistry: () => mockAgentRegistry, + } as unknown as Config; + vi.clearAllMocks(); + }); + + afterEach(async () => { + if (testRootDir) { + await cleanupTmpDir(testRootDir); + } + vi.restoreAllMocks(); + }); + + it('should include agent suggestions', async () => { + testRootDir = await createTmpDir({}); + + const { result } = renderHook(() => + useTestHarnessForAtCompletion(true, '', mockConfig, testRootDir), + ); + + await waitFor(() => { + expect(result.current.suggestions.length).toBeGreaterThan(0); + }); + + const agentSuggestion = result.current.suggestions.find( + (s) => s.value === 'CodebaseInvestigator', + ); + expect(agentSuggestion).toBeDefined(); + expect(agentSuggestion?.commandKind).toBe(CommandKind.AGENT); + }); + + it('should filter agent suggestions', async () => { + testRootDir = await createTmpDir({}); + + const { result } = renderHook(() => + useTestHarnessForAtCompletion(true, 'Code', mockConfig, testRootDir), + ); + + await waitFor(() => { + expect(result.current.suggestions.length).toBeGreaterThan(0); + }); + + expect(result.current.suggestions.map((s) => s.value)).toContain( + 'CodebaseInvestigator', + ); + expect(result.current.suggestions.map((s) => s.value)).not.toContain( + 'OtherAgent', + ); + }); +}); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index a56d5ae813..75acd00143 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -167,6 +167,9 @@ export * from './hooks/index.js'; // Export hook types export * from './hooks/types.js'; +// Export agent types +export * from './agents/types.js'; + // Export stdio utils export * from './utils/stdio.js'; export * from './utils/terminal.js'; From e1e3efc9d04a1e93899e559e888b93c95b14ae2f Mon Sep 17 00:00:00 2001 From: Sandy Tao Date: Fri, 9 Jan 2026 13:36:27 +0800 Subject: [PATCH 086/713] feat(hooks): Support explicit stop and block execution control in model hooks (#15947) Co-authored-by: matt korwel --- packages/core/src/core/geminiChat.test.ts | 159 ++++++++++++++ packages/core/src/core/geminiChat.ts | 99 ++++++++- .../src/core/geminiChatHookTriggers.test.ts | 204 ++++++++++++++++++ .../core/src/core/geminiChatHookTriggers.ts | 52 ++++- packages/core/src/core/turn.ts | 16 ++ packages/core/src/hooks/types.test.ts | 36 +--- packages/core/src/hooks/types.ts | 16 -- 7 files changed, 517 insertions(+), 65 deletions(-) create mode 100644 packages/core/src/core/geminiChatHookTriggers.test.ts diff --git a/packages/core/src/core/geminiChat.test.ts b/packages/core/src/core/geminiChat.test.ts index baf8973904..1f60565f0d 100644 --- a/packages/core/src/core/geminiChat.test.ts +++ b/packages/core/src/core/geminiChat.test.ts @@ -28,6 +28,18 @@ import { createAvailabilityServiceMock } from '../availability/testUtils.js'; import type { ModelAvailabilityService } from '../availability/modelAvailabilityService.js'; import * as policyHelpers from '../availability/policyHelpers.js'; import { makeResolvedModelConfig } from '../services/modelConfigServiceTestUtils.js'; +import { + fireBeforeModelHook, + fireAfterModelHook, + fireBeforeToolSelectionHook, +} from './geminiChatHookTriggers.js'; + +// Mock hook triggers +vi.mock('./geminiChatHookTriggers.js', () => ({ + fireBeforeModelHook: vi.fn(), + fireAfterModelHook: vi.fn(), + fireBeforeToolSelectionHook: vi.fn().mockResolvedValue({}), +})); // Mock fs module to prevent actual file system operations during tests const mockFileSystem = new Map(); @@ -2269,4 +2281,151 @@ describe('GeminiChat', () => { ); }); }); + + describe('Hook execution control', () => { + beforeEach(() => { + vi.mocked(mockConfig.getEnableHooks).mockReturnValue(true); + // Default to allowing execution + vi.mocked(fireBeforeModelHook).mockResolvedValue({ blocked: false }); + vi.mocked(fireAfterModelHook).mockResolvedValue({ + response: {} as GenerateContentResponse, + }); + vi.mocked(fireBeforeToolSelectionHook).mockResolvedValue({}); + }); + + it('should yield AGENT_EXECUTION_STOPPED when BeforeModel hook stops execution', async () => { + vi.mocked(fireBeforeModelHook).mockResolvedValue({ + blocked: true, + stopped: true, + reason: 'stopped by hook', + }); + + const stream = await chat.sendMessageStream( + { model: 'gemini-pro' }, + 'test', + 'prompt-id', + new AbortController().signal, + ); + + const events: StreamEvent[] = []; + for await (const event of stream) { + events.push(event); + } + + expect(events).toHaveLength(1); + expect(events[0]).toEqual({ + type: StreamEventType.AGENT_EXECUTION_STOPPED, + reason: 'stopped by hook', + }); + }); + + it('should yield AGENT_EXECUTION_BLOCKED and synthetic response when BeforeModel hook blocks execution', async () => { + const syntheticResponse = { + candidates: [{ content: { parts: [{ text: 'blocked' }] } }], + } as GenerateContentResponse; + + vi.mocked(fireBeforeModelHook).mockResolvedValue({ + blocked: true, + reason: 'blocked by hook', + syntheticResponse, + }); + + const stream = await chat.sendMessageStream( + { model: 'gemini-pro' }, + 'test', + 'prompt-id', + new AbortController().signal, + ); + + const events: StreamEvent[] = []; + for await (const event of stream) { + events.push(event); + } + + expect(events).toHaveLength(2); + expect(events[0]).toEqual({ + type: StreamEventType.AGENT_EXECUTION_BLOCKED, + reason: 'blocked by hook', + }); + expect(events[1]).toEqual({ + type: StreamEventType.CHUNK, + value: syntheticResponse, + }); + }); + + it('should yield AGENT_EXECUTION_STOPPED when AfterModel hook stops execution', async () => { + // Mock content generator to return a stream + vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue( + (async function* () { + yield { + candidates: [{ content: { parts: [{ text: 'response' }] } }], + } as unknown as GenerateContentResponse; + })(), + ); + + vi.mocked(fireAfterModelHook).mockResolvedValue({ + response: {} as GenerateContentResponse, + stopped: true, + reason: 'stopped by after hook', + }); + + const stream = await chat.sendMessageStream( + { model: 'gemini-pro' }, + 'test', + 'prompt-id', + new AbortController().signal, + ); + + const events: StreamEvent[] = []; + for await (const event of stream) { + events.push(event); + } + + expect(events).toContainEqual({ + type: StreamEventType.AGENT_EXECUTION_STOPPED, + reason: 'stopped by after hook', + }); + }); + + it('should yield AGENT_EXECUTION_BLOCKED and response when AfterModel hook blocks execution', async () => { + const response = { + candidates: [{ content: { parts: [{ text: 'response' }] } }], + } as unknown as GenerateContentResponse; + + // Mock content generator to return a stream + vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue( + (async function* () { + yield response; + })(), + ); + + vi.mocked(fireAfterModelHook).mockResolvedValue({ + response, + blocked: true, + reason: 'blocked by after hook', + }); + + const stream = await chat.sendMessageStream( + { model: 'gemini-pro' }, + 'test', + 'prompt-id', + new AbortController().signal, + ); + + const events: StreamEvent[] = []; + for await (const event of stream) { + events.push(event); + } + + expect(events).toContainEqual({ + type: StreamEventType.AGENT_EXECUTION_BLOCKED, + reason: 'blocked by after hook', + }); + // Should also contain the chunk (hook response) + expect(events).toContainEqual({ + type: StreamEventType.CHUNK, + value: response, + }); + }); + }); }); diff --git a/packages/core/src/core/geminiChat.ts b/packages/core/src/core/geminiChat.ts index 3bc928c6fb..2dff70c16d 100644 --- a/packages/core/src/core/geminiChat.ts +++ b/packages/core/src/core/geminiChat.ts @@ -61,11 +61,17 @@ export enum StreamEventType { /** A signal that a retry is about to happen. The UI should discard any partial * content from the attempt that just failed. */ RETRY = 'retry', + /** A signal that the agent execution has been stopped by a hook. */ + AGENT_EXECUTION_STOPPED = 'agent_execution_stopped', + /** A signal that the agent execution has been blocked by a hook. */ + AGENT_EXECUTION_BLOCKED = 'agent_execution_blocked', } export type StreamEvent = | { type: StreamEventType.CHUNK; value: GenerateContentResponse } - | { type: StreamEventType.RETRY }; + | { type: StreamEventType.RETRY } + | { type: StreamEventType.AGENT_EXECUTION_STOPPED; reason: string } + | { type: StreamEventType.AGENT_EXECUTION_BLOCKED; reason: string }; /** * Options for retrying due to invalid content from the model. @@ -197,6 +203,29 @@ export class InvalidStreamError extends Error { } } +/** + * Custom error to signal that agent execution has been stopped. + */ +export class AgentExecutionStoppedError extends Error { + constructor(public reason: string) { + super(reason); + this.name = 'AgentExecutionStoppedError'; + } +} + +/** + * Custom error to signal that agent execution has been blocked. + */ +export class AgentExecutionBlockedError extends Error { + constructor( + public reason: string, + public syntheticResponse?: GenerateContentResponse, + ) { + super(reason); + this.name = 'AgentExecutionBlockedError'; + } +} + /** * Chat session that enables sending messages to the model with previous * conversation context. @@ -325,6 +354,30 @@ export class GeminiChat { lastError = null; break; } catch (error) { + if (error instanceof AgentExecutionStoppedError) { + yield { + type: StreamEventType.AGENT_EXECUTION_STOPPED, + reason: error.reason, + }; + lastError = null; // Clear error as this is an expected stop + return; // Stop the generator + } + + if (error instanceof AgentExecutionBlockedError) { + yield { + type: StreamEventType.AGENT_EXECUTION_BLOCKED, + reason: error.reason, + }; + if (error.syntheticResponse) { + yield { + type: StreamEventType.CHUNK, + value: error.syntheticResponse, + }; + } + lastError = null; // Clear error as this is an expected stop + return; // Stop the generator + } + if (isConnectionPhase) { throw error; } @@ -457,19 +510,35 @@ export class GeminiChat { contents: contentsToUse, }); + // Check if hook requested to stop execution + if (beforeModelResult.stopped) { + throw new AgentExecutionStoppedError( + beforeModelResult.reason || 'Agent execution stopped by hook', + ); + } + // Check if hook blocked the model call if (beforeModelResult.blocked) { // Return a synthetic response generator const syntheticResponse = beforeModelResult.syntheticResponse; if (syntheticResponse) { - return (async function* () { - yield syntheticResponse; - })(); + // Ensure synthetic response has a finish reason to prevent InvalidStreamError + if ( + syntheticResponse.candidates && + syntheticResponse.candidates.length > 0 + ) { + for (const candidate of syntheticResponse.candidates) { + if (!candidate.finishReason) { + candidate.finishReason = FinishReason.STOP; + } + } + } } - // If blocked without synthetic response, return empty generator - return (async function* () { - // Empty generator - no response - })(); + + throw new AgentExecutionBlockedError( + beforeModelResult.reason || 'Model call blocked by hook', + syntheticResponse, + ); } // Apply modifications from BeforeModel hook @@ -748,6 +817,20 @@ export class GeminiChat { originalRequest, chunk, ); + + if (hookResult.stopped) { + throw new AgentExecutionStoppedError( + hookResult.reason || 'Agent execution stopped by hook', + ); + } + + if (hookResult.blocked) { + throw new AgentExecutionBlockedError( + hookResult.reason || 'Agent execution blocked by hook', + hookResult.response, + ); + } + yield hookResult.response; } else { yield chunk; // Yield every chunk to the UI immediately. diff --git a/packages/core/src/core/geminiChatHookTriggers.test.ts b/packages/core/src/core/geminiChatHookTriggers.test.ts new file mode 100644 index 0000000000..0bc1501386 --- /dev/null +++ b/packages/core/src/core/geminiChatHookTriggers.test.ts @@ -0,0 +1,204 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { + fireBeforeModelHook, + fireAfterModelHook, +} from './geminiChatHookTriggers.js'; +import type { MessageBus } from '../confirmation-bus/message-bus.js'; +import type { + GenerateContentParameters, + GenerateContentResponse, +} from '@google/genai'; + +// Mock dependencies +const mockRequest = vi.fn(); +const mockMessageBus = { + request: mockRequest, +} as unknown as MessageBus; + +// Mock hook types +vi.mock('../hooks/types.js', async () => { + const actual = await vi.importActual('../hooks/types.js'); + return { + ...actual, + createHookOutput: vi.fn(), + }; +}); + +import { createHookOutput } from '../hooks/types.js'; + +describe('Gemini Chat Hook Triggers', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + describe('fireBeforeModelHook', () => { + const llmRequest = { + model: 'gemini-pro', + contents: [{ parts: [{ text: 'test' }] }], + } as GenerateContentParameters; + + it('should return stopped: true when hook requests stop execution', async () => { + mockRequest.mockResolvedValue({ + output: { continue: false, stopReason: 'stopped by hook' }, + }); + vi.mocked(createHookOutput).mockReturnValue({ + shouldStopExecution: () => true, + getEffectiveReason: () => 'stopped by hook', + getBlockingError: () => ({ blocked: false, reason: '' }), + } as unknown as ReturnType); + + const result = await fireBeforeModelHook(mockMessageBus, llmRequest); + + expect(result).toEqual({ + blocked: true, + stopped: true, + reason: 'stopped by hook', + }); + }); + + it('should return blocked: true when hook blocks execution', async () => { + mockRequest.mockResolvedValue({ + output: { decision: 'block', reason: 'blocked by hook' }, + }); + vi.mocked(createHookOutput).mockReturnValue({ + shouldStopExecution: () => false, + getBlockingError: () => ({ blocked: true, reason: 'blocked by hook' }), + getEffectiveReason: () => 'blocked by hook', + getSyntheticResponse: () => undefined, + } as unknown as ReturnType); + + const result = await fireBeforeModelHook(mockMessageBus, llmRequest); + + expect(result).toEqual({ + blocked: true, + reason: 'blocked by hook', + syntheticResponse: undefined, + }); + }); + + it('should return modifications when hook allows execution', async () => { + mockRequest.mockResolvedValue({ + output: { decision: 'allow' }, + }); + vi.mocked(createHookOutput).mockReturnValue({ + shouldStopExecution: () => false, + getBlockingError: () => ({ blocked: false, reason: '' }), + applyLLMRequestModifications: (req: GenerateContentParameters) => req, + } as unknown as ReturnType); + + const result = await fireBeforeModelHook(mockMessageBus, llmRequest); + + expect(result).toEqual({ + blocked: false, + modifiedConfig: undefined, + modifiedContents: llmRequest.contents, + }); + }); + }); + + describe('fireAfterModelHook', () => { + const llmRequest = { + model: 'gemini-pro', + contents: [], + } as GenerateContentParameters; + const llmResponse = { + candidates: [ + { content: { role: 'model', parts: [{ text: 'response' }] } }, + ], + } as GenerateContentResponse; + + it('should return stopped: true when hook requests stop execution', async () => { + mockRequest.mockResolvedValue({ + output: { continue: false, stopReason: 'stopped by hook' }, + }); + vi.mocked(createHookOutput).mockReturnValue({ + shouldStopExecution: () => true, + getEffectiveReason: () => 'stopped by hook', + } as unknown as ReturnType); + + const result = await fireAfterModelHook( + mockMessageBus, + llmRequest, + llmResponse, + ); + + expect(result).toEqual({ + response: llmResponse, + stopped: true, + reason: 'stopped by hook', + }); + }); + + it('should return blocked: true when hook blocks execution', async () => { + mockRequest.mockResolvedValue({ + output: { decision: 'block', reason: 'blocked by hook' }, + }); + vi.mocked(createHookOutput).mockReturnValue({ + shouldStopExecution: () => false, + getBlockingError: () => ({ blocked: true, reason: 'blocked by hook' }), + getEffectiveReason: () => 'blocked by hook', + } as unknown as ReturnType); + + const result = await fireAfterModelHook( + mockMessageBus, + llmRequest, + llmResponse, + ); + + expect(result).toEqual({ + response: llmResponse, + blocked: true, + reason: 'blocked by hook', + }); + }); + + it('should return modified response when hook modifies response', async () => { + const modifiedResponse = { ...llmResponse, text: 'modified' }; + mockRequest.mockResolvedValue({ + output: { hookSpecificOutput: { llm_response: {} } }, + }); + vi.mocked(createHookOutput).mockReturnValue({ + shouldStopExecution: () => false, + getBlockingError: () => ({ blocked: false, reason: '' }), + getModifiedResponse: () => modifiedResponse, + } as unknown as ReturnType); + + const result = await fireAfterModelHook( + mockMessageBus, + llmRequest, + llmResponse, + ); + + expect(result).toEqual({ + response: modifiedResponse, + }); + }); + + it('should return original response when hook has no effect', async () => { + mockRequest.mockResolvedValue({ + output: {}, + }); + vi.mocked(createHookOutput).mockReturnValue({ + shouldStopExecution: () => false, + getBlockingError: () => ({ blocked: false, reason: '' }), + getModifiedResponse: () => undefined, + } as unknown as ReturnType); + + const result = await fireAfterModelHook( + mockMessageBus, + llmRequest, + llmResponse, + ); + + expect(result).toEqual({ + response: llmResponse, + }); + }); + }); +}); diff --git a/packages/core/src/core/geminiChatHookTriggers.ts b/packages/core/src/core/geminiChatHookTriggers.ts index 0672ec961d..e0632105de 100644 --- a/packages/core/src/core/geminiChatHookTriggers.ts +++ b/packages/core/src/core/geminiChatHookTriggers.ts @@ -32,6 +32,8 @@ import { debugLogger } from '../utils/debugLogger.js'; export interface BeforeModelHookResult { /** Whether the model call was blocked */ blocked: boolean; + /** Whether the execution should be stopped entirely */ + stopped?: boolean; /** Reason for blocking (if blocked) */ reason?: string; /** Synthetic response to return instead of calling the model (if blocked) */ @@ -59,14 +61,16 @@ export interface BeforeToolSelectionHookResult { export interface AfterModelHookResult { /** The response to yield (either modified or original) */ response: GenerateContentResponse; + /** Whether the execution should be stopped entirely */ + stopped?: boolean; + /** Whether the model call was blocked */ + blocked?: boolean; + /** Reason for blocking or stopping */ + reason?: string; } /** * Fires the BeforeModel hook and returns the result. - * - * @param messageBus The message bus to use for hook communication - * @param llmRequest The LLM request parameters - * @returns The hook result with blocking info or modifications */ export async function fireBeforeModelHook( messageBus: MessageBus, @@ -94,9 +98,18 @@ export async function fireBeforeModelHook( const hookOutput = beforeResultFinalOutput; - // Check if hook blocked the model call or requested to stop execution + // Check if hook requested to stop execution + if (hookOutput?.shouldStopExecution()) { + return { + blocked: true, + stopped: true, + reason: hookOutput.getEffectiveReason(), + }; + } + + // Check if hook blocked the model call const blockingError = hookOutput?.getBlockingError(); - if (blockingError?.blocked || hookOutput?.shouldStopExecution()) { + if (blockingError?.blocked) { const beforeModelOutput = hookOutput as BeforeModelHookOutput; const syntheticResponse = beforeModelOutput.getSyntheticResponse(); const reason = @@ -217,9 +230,30 @@ export async function fireAfterModelHook( ? createHookOutput('AfterModel', response.output) : undefined; - // Apply modifications from hook (handles both normal modifications and stop execution) - if (afterResultFinalOutput) { - const afterModelOutput = afterResultFinalOutput as AfterModelHookOutput; + const hookOutput = afterResultFinalOutput; + + // Check if hook requested to stop execution + if (hookOutput?.shouldStopExecution()) { + return { + response: chunk, + stopped: true, + reason: hookOutput.getEffectiveReason(), + }; + } + + // Check if hook blocked the model call + const blockingError = hookOutput?.getBlockingError(); + if (blockingError?.blocked) { + return { + response: chunk, + blocked: true, + reason: hookOutput?.getEffectiveReason(), + }; + } + + // Apply modifications from hook + if (hookOutput) { + const afterModelOutput = hookOutput as AfterModelHookOutput; const modifiedResponse = afterModelOutput.getModifiedResponse(); if (modifiedResponse) { return { response: modifiedResponse }; diff --git a/packages/core/src/core/turn.ts b/packages/core/src/core/turn.ts index 11825d9d7b..fcb8e18e04 100644 --- a/packages/core/src/core/turn.ts +++ b/packages/core/src/core/turn.ts @@ -264,6 +264,22 @@ export class Turn { continue; // Skip to the next event in the stream } + if (streamEvent.type === 'agent_execution_stopped') { + yield { + type: GeminiEventType.AgentExecutionStopped, + value: { reason: streamEvent.reason }, + }; + return; + } + + if (streamEvent.type === 'agent_execution_blocked') { + yield { + type: GeminiEventType.AgentExecutionBlocked, + value: { reason: streamEvent.reason }, + }; + continue; + } + // Assuming other events are chunks with a `value` property const resp = streamEvent.value; if (!resp) continue; // Skip if there's no response body diff --git a/packages/core/src/hooks/types.test.ts b/packages/core/src/hooks/types.test.ts index 18a18fe121..fb3e6d062c 100644 --- a/packages/core/src/hooks/types.test.ts +++ b/packages/core/src/hooks/types.test.ts @@ -319,45 +319,17 @@ describe('Hook Output Classes', () => { expect(output.getModifiedResponse()).toBeUndefined(); }); - it('getModifiedResponse should return a synthetic stop response if shouldStopExecution is true', () => { + it('getModifiedResponse should return undefined if shouldStopExecution is true', () => { const output = new AfterModelHookOutput({ continue: false, stopReason: 'stopped by hook', }); - const expectedResponse: LLMResponse = { - candidates: [ - { - content: { - role: 'model', - parts: ['stopped by hook'], - }, - finishReason: 'STOP', - }, - ], - }; - expect(output.getModifiedResponse()).toEqual(expectedResponse); - expect(defaultHookTranslator.fromHookLLMResponse).toHaveBeenCalledWith( - expectedResponse, - ); + expect(output.getModifiedResponse()).toBeUndefined(); }); - it('getModifiedResponse should return a synthetic stop response with default reason if shouldStopExecution is true and no stopReason', () => { + it('getModifiedResponse should return undefined if shouldStopExecution is true and no stopReason', () => { const output = new AfterModelHookOutput({ continue: false }); - const expectedResponse: LLMResponse = { - candidates: [ - { - content: { - role: 'model', - parts: ['No reason provided'], - }, - finishReason: 'STOP', - }, - ], - }; - expect(output.getModifiedResponse()).toEqual(expectedResponse); - expect(defaultHookTranslator.fromHookLLMResponse).toHaveBeenCalledWith( - expectedResponse, - ); + expect(output.getModifiedResponse()).toBeUndefined(); }); }); }); diff --git a/packages/core/src/hooks/types.ts b/packages/core/src/hooks/types.ts index 5ca7bd5fb1..8d6e203778 100644 --- a/packages/core/src/hooks/types.ts +++ b/packages/core/src/hooks/types.ts @@ -353,22 +353,6 @@ export class AfterModelHookOutput extends DefaultHookOutput { } } - // If hook wants to stop execution, create a synthetic stop response - if (this.shouldStopExecution()) { - const stopResponse: LLMResponse = { - candidates: [ - { - content: { - role: 'model', - parts: [this.getEffectiveReason() || 'Execution stopped by hook'], - }, - finishReason: 'STOP', - }, - ], - }; - return defaultHookTranslator.fromHookLLMResponse(stopResponse); - } - return undefined; } } From 41e627a7ee4ca48a8cfdf4f8498153b0ac91b619 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 8 Jan 2026 23:59:40 -0800 Subject: [PATCH 087/713] Refine Gemini 3 system instructions to reduce model verbosity (#16139) --- packages/core/src/core/__snapshots__/prompts.test.ts.snap | 6 ++++-- packages/core/src/core/prompts.test.ts | 4 ++-- packages/core/src/core/prompts.ts | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/core/src/core/__snapshots__/prompts.test.ts.snap b/packages/core/src/core/__snapshots__/prompts.test.ts.snap index 19df12b093..f8dd7ead06 100644 --- a/packages/core/src/core/__snapshots__/prompts.test.ts.snap +++ b/packages/core/src/core/__snapshots__/prompts.test.ts.snap @@ -1219,7 +1219,7 @@ exports[`Core System Prompt (prompts.ts) > should use chatty system prompt for p - **Confirm Ambiguity/Expansion:** Do not take significant actions beyond the clear scope of the request without confirming with the user. If asked *how* to do something, explain first, don't just do it. - **Explaining Changes:** After completing a code modification or file operation *do not* provide summaries unless asked. - **Do Not revert changes:** Do not revert changes to the codebase unless asked to do so by the user. Only revert changes made by you if they have resulted in an error or if the user has explicitly asked you to revert the changes. -- **Do not call tools in silence:** You must provide to the user very short and concise natural explanation (one sentence) before calling tools. +- **Explain Before Acting:** Never call tools in silence. You MUST provide a concise, one-sentence explanation of your intent or strategy immediately before executing tool calls. This is essential for transparency, especially when confirming a request or answering a question. Silence is only acceptable for repetitive, low-level discovery operations (e.g., sequential file reads) where narration would be noisy. Mock Agent Directory @@ -1272,6 +1272,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Concise & Direct:** Adopt a professional, direct, and concise tone suitable for a CLI environment. - **Minimal Output:** Aim for fewer than 3 lines of text output (excluding tool use/code generation) per response whenever practical. Focus strictly on the user's query. - **Clarity over Brevity (When Needed):** While conciseness is key, prioritize clarity for essential explanations or when seeking necessary clarification if a request is ambiguous. +- **No Chitchat:** Avoid conversational filler, preambles ("Okay, I will now..."), or postambles ("I have finished the changes...") unless they serve to explain intent as required by the 'Explain Before Acting' mandate. - **Formatting:** Use GitHub-flavored Markdown. Responses will be rendered in monospace. - **Tools vs. Text:** Use tools for actions, text output *only* for communication. Do not add explanatory comments within tool calls or code blocks unless specifically part of the required code/command itself. - **Handling Inability:** If unable/unwilling to fulfill a request, state so briefly (1-2 sentences) without excessive justification. Offer alternatives if appropriate. @@ -1317,7 +1318,7 @@ exports[`Core System Prompt (prompts.ts) > should use chatty system prompt for p - **Confirm Ambiguity/Expansion:** Do not take significant actions beyond the clear scope of the request without confirming with the user. If asked *how* to do something, explain first, don't just do it. - **Explaining Changes:** After completing a code modification or file operation *do not* provide summaries unless asked. - **Do Not revert changes:** Do not revert changes to the codebase unless asked to do so by the user. Only revert changes made by you if they have resulted in an error or if the user has explicitly asked you to revert the changes. -- **Do not call tools in silence:** You must provide to the user very short and concise natural explanation (one sentence) before calling tools. +- **Explain Before Acting:** Never call tools in silence. You MUST provide a concise, one-sentence explanation of your intent or strategy immediately before executing tool calls. This is essential for transparency, especially when confirming a request or answering a question. Silence is only acceptable for repetitive, low-level discovery operations (e.g., sequential file reads) where narration would be noisy. Mock Agent Directory @@ -1370,6 +1371,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Concise & Direct:** Adopt a professional, direct, and concise tone suitable for a CLI environment. - **Minimal Output:** Aim for fewer than 3 lines of text output (excluding tool use/code generation) per response whenever practical. Focus strictly on the user's query. - **Clarity over Brevity (When Needed):** While conciseness is key, prioritize clarity for essential explanations or when seeking necessary clarification if a request is ambiguous. +- **No Chitchat:** Avoid conversational filler, preambles ("Okay, I will now..."), or postambles ("I have finished the changes...") unless they serve to explain intent as required by the 'Explain Before Acting' mandate. - **Formatting:** Use GitHub-flavored Markdown. Responses will be rendered in monospace. - **Tools vs. Text:** Use tools for actions, text output *only* for communication. Do not add explanatory comments within tool calls or code blocks unless specifically part of the required code/command itself. - **Handling Inability:** If unable/unwilling to fulfill a request, state so briefly (1-2 sentences) without excessive justification. Offer alternatives if appropriate. diff --git a/packages/core/src/core/prompts.test.ts b/packages/core/src/core/prompts.test.ts index ceb5019df8..1ecdcc2776 100644 --- a/packages/core/src/core/prompts.test.ts +++ b/packages/core/src/core/prompts.test.ts @@ -122,7 +122,7 @@ describe('Core System Prompt (prompts.ts)', () => { vi.mocked(mockConfig.getActiveModel).mockReturnValue(PREVIEW_GEMINI_MODEL); const prompt = getCoreSystemPrompt(mockConfig); expect(prompt).toContain('You are an interactive CLI agent'); // Check for core content - expect(prompt).not.toContain('No Chitchat:'); + expect(prompt).toContain('No Chitchat:'); expect(prompt).toMatchSnapshot(); }); @@ -132,7 +132,7 @@ describe('Core System Prompt (prompts.ts)', () => { ); const prompt = getCoreSystemPrompt(mockConfig); expect(prompt).toContain('You are an interactive CLI agent'); // Check for core content - expect(prompt).not.toContain('No Chitchat:'); + expect(prompt).toContain('No Chitchat:'); expect(prompt).toMatchSnapshot(); }); diff --git a/packages/core/src/core/prompts.ts b/packages/core/src/core/prompts.ts index 243582494f..a2811dcfa1 100644 --- a/packages/core/src/core/prompts.ts +++ b/packages/core/src/core/prompts.ts @@ -115,7 +115,7 @@ export function getCoreSystemPrompt( const mandatesVariant = isGemini3 ? ` -- **Do not call tools in silence:** You must provide to the user very short and concise natural explanation (one sentence) before calling tools.` +- **Explain Before Acting:** Never call tools in silence. You MUST provide a concise, one-sentence explanation of your intent or strategy immediately before executing tool calls. This is essential for transparency, especially when confirming a request or answering a question. Silence is only acceptable for repetitive, low-level discovery operations (e.g., sequential file reads) where narration would be noisy.` : ``; const enableCodebaseInvestigator = config @@ -271,7 +271,8 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Minimal Output:** Aim for fewer than 3 lines of text output (excluding tool use/code generation) per response whenever practical. Focus strictly on the user's query. - **Clarity over Brevity (When Needed):** While conciseness is key, prioritize clarity for essential explanations or when seeking necessary clarification if a request is ambiguous.${(function () { if (isGemini3) { - return ''; + return ` +- **No Chitchat:** Avoid conversational filler, preambles ("Okay, I will now..."), or postambles ("I have finished the changes...") unless they serve to explain intent as required by the 'Explain Before Acting' mandate.`; } else { return ` - **No Chitchat:** Avoid conversational filler, preambles ("Okay, I will now..."), or postambles ("I have finished the changes..."). Get straight to the action or answer.`; From aa480e5fbbbe4acd99b9f3f66de67511fa7aab6c Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Fri, 9 Jan 2026 10:03:46 -0500 Subject: [PATCH 088/713] chore: clean up unused models and use consts (#16246) --- packages/core/src/core/tokenLimits.test.ts | 18 ++++++++++++---- packages/core/src/core/tokenLimits.ts | 25 +++++++++++----------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/packages/core/src/core/tokenLimits.test.ts b/packages/core/src/core/tokenLimits.test.ts index 1bff09d315..5a5092d7ea 100644 --- a/packages/core/src/core/tokenLimits.test.ts +++ b/packages/core/src/core/tokenLimits.test.ts @@ -6,14 +6,24 @@ import { describe, it, expect } from 'vitest'; import { tokenLimit, DEFAULT_TOKEN_LIMIT } from './tokenLimits.js'; +import { + DEFAULT_GEMINI_FLASH_LITE_MODEL, + DEFAULT_GEMINI_FLASH_MODEL, + DEFAULT_GEMINI_MODEL, + PREVIEW_GEMINI_FLASH_MODEL, + PREVIEW_GEMINI_MODEL, +} from '../config/models.js'; describe('tokenLimit', () => { - it('should return the correct token limit for gemini-1.5-pro', () => { - expect(tokenLimit('gemini-1.5-pro')).toBe(2_097_152); + it('should return the correct token limit for default models', () => { + expect(tokenLimit(DEFAULT_GEMINI_MODEL)).toBe(1_048_576); + expect(tokenLimit(DEFAULT_GEMINI_FLASH_MODEL)).toBe(1_048_576); + expect(tokenLimit(DEFAULT_GEMINI_FLASH_LITE_MODEL)).toBe(1_048_576); }); - it('should return the correct token limit for gemini-1.5-flash', () => { - expect(tokenLimit('gemini-1.5-flash')).toBe(1_048_576); + it('should return the correct token limit for preview models', () => { + expect(tokenLimit(PREVIEW_GEMINI_MODEL)).toBe(1_048_576); + expect(tokenLimit(PREVIEW_GEMINI_FLASH_MODEL)).toBe(1_048_576); }); it('should return the default token limit for an unknown model', () => { diff --git a/packages/core/src/core/tokenLimits.ts b/packages/core/src/core/tokenLimits.ts index d238cdb3a0..39a3443e36 100644 --- a/packages/core/src/core/tokenLimits.ts +++ b/packages/core/src/core/tokenLimits.ts @@ -4,6 +4,14 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { + DEFAULT_GEMINI_FLASH_LITE_MODEL, + DEFAULT_GEMINI_FLASH_MODEL, + DEFAULT_GEMINI_MODEL, + PREVIEW_GEMINI_FLASH_MODEL, + PREVIEW_GEMINI_MODEL, +} from '../config/models.js'; + type Model = string; type TokenCount = number; @@ -13,19 +21,12 @@ export function tokenLimit(model: Model): TokenCount { // Add other models as they become relevant or if specified by config // Pulled from https://ai.google.dev/gemini-api/docs/models switch (model) { - case 'gemini-1.5-pro': - return 2_097_152; - case 'gemini-1.5-flash': - case 'gemini-2.5-pro-preview-05-06': - case 'gemini-2.5-pro-preview-06-05': - case 'gemini-2.5-pro': - case 'gemini-2.5-flash-preview-05-20': - case 'gemini-2.5-flash': - case 'gemini-2.5-flash-lite': - case 'gemini-2.0-flash': + case PREVIEW_GEMINI_MODEL: + case PREVIEW_GEMINI_FLASH_MODEL: + case DEFAULT_GEMINI_MODEL: + case DEFAULT_GEMINI_FLASH_MODEL: + case DEFAULT_GEMINI_FLASH_LITE_MODEL: return 1_048_576; - case 'gemini-2.0-flash-preview-image-generation': - return 32_000; default: return DEFAULT_TOKEN_LIMIT; } From 88f1ec8d0ae40ee81eba7a997abe7a324f101aa7 Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Fri, 9 Jan 2026 08:07:05 -0800 Subject: [PATCH 089/713] Always enable bracketed paste (#16179) --- .../cli/src/ui/contexts/KeypressContext.tsx | 28 ------------- .../utils/terminalCapabilityManager.test.ts | 42 ------------------- .../src/ui/utils/terminalCapabilityManager.ts | 30 ++----------- 3 files changed, 3 insertions(+), 97 deletions(-) diff --git a/packages/cli/src/ui/contexts/KeypressContext.tsx b/packages/cli/src/ui/contexts/KeypressContext.tsx index cd5b6224f0..f1680a5b26 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.tsx @@ -19,7 +19,6 @@ import { ESC } from '../utils/input.js'; import { parseMouseEvent } from '../utils/mouse.js'; import { FOCUS_IN, FOCUS_OUT } from '../hooks/useFocus.js'; import { appEvents, AppEvent } from '../../utils/events.js'; -import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js'; export const BACKSLASH_ENTER_TIMEOUT = 5; export const ESC_TIMEOUT = 50; @@ -189,30 +188,6 @@ function bufferBackslashEnter( return (key: Key) => bufferer.next(key); } -/** - * Converts return keys pressed quickly after other keys into plain - * insertable return characters. - * - * This is to accommodate older terminals that paste text without bracketing. - */ -function bufferFastReturn(keypressHandler: KeypressHandler): KeypressHandler { - let lastKeyTime = 0; - return (key: Key) => { - const now = Date.now(); - if (key.name === 'return' && now - lastKeyTime <= FAST_RETURN_TIMEOUT) { - keypressHandler({ - ...key, - name: '', - sequence: '\r', - insertable: true, - }); - } else { - keypressHandler(key); - } - lastKeyTime = now; - }; -} - /** * Buffers paste events between paste-start and paste-end sequences. * Will flush the buffer if no data is received for PASTE_TIMEOUT ms or @@ -661,9 +636,6 @@ export function KeypressProvider({ process.stdin.setEncoding('utf8'); // Make data events emit strings let processor = nonKeyboardEventFilter(broadcast); - if (!terminalCapabilityManager.isBracketedPasteEnabled()) { - processor = bufferFastReturn(processor); - } processor = bufferBackslashEnter(processor); processor = bufferPaste(processor); let dataListener = createDataListener(processor); diff --git a/packages/cli/src/ui/utils/terminalCapabilityManager.test.ts b/packages/cli/src/ui/utils/terminalCapabilityManager.test.ts index bd58fc5cab..e10ca2593c 100644 --- a/packages/cli/src/ui/utils/terminalCapabilityManager.test.ts +++ b/packages/cli/src/ui/utils/terminalCapabilityManager.test.ts @@ -266,46 +266,4 @@ describe('TerminalCapabilityManager', () => { expect(manager.isModifyOtherKeysEnabled()).toBe(true); }); }); - - describe('bracketed paste detection', () => { - it('should detect bracketed paste support (mode set)', async () => { - const manager = TerminalCapabilityManager.getInstance(); - const promise = manager.detectCapabilities(); - - // Simulate bracketed paste response: \x1b[?2004;1$y - stdin.emit('data', Buffer.from('\x1b[?2004;1$y')); - // Complete detection with DA1 - stdin.emit('data', Buffer.from('\x1b[?62c')); - - await promise; - expect(manager.isBracketedPasteSupported()).toBe(true); - expect(manager.isBracketedPasteEnabled()).toBe(true); - }); - - it('should detect bracketed paste support (mode reset)', async () => { - const manager = TerminalCapabilityManager.getInstance(); - const promise = manager.detectCapabilities(); - - // Simulate bracketed paste response: \x1b[?2004;2$y - stdin.emit('data', Buffer.from('\x1b[?2004;2$y')); - // Complete detection with DA1 - stdin.emit('data', Buffer.from('\x1b[?62c')); - - await promise; - expect(manager.isBracketedPasteSupported()).toBe(true); - expect(manager.isBracketedPasteEnabled()).toBe(true); - }); - - it('should not enable bracketed paste if not supported', async () => { - const manager = TerminalCapabilityManager.getInstance(); - const promise = manager.detectCapabilities(); - - // Complete detection with DA1 only - stdin.emit('data', Buffer.from('\x1b[?62c')); - - await promise; - expect(manager.isBracketedPasteSupported()).toBe(false); - expect(manager.isBracketedPasteEnabled()).toBe(false); - }); - }); }); diff --git a/packages/cli/src/ui/utils/terminalCapabilityManager.ts b/packages/cli/src/ui/utils/terminalCapabilityManager.ts index 5e5b8b490f..7b09a33e4e 100644 --- a/packages/cli/src/ui/utils/terminalCapabilityManager.ts +++ b/packages/cli/src/ui/utils/terminalCapabilityManager.ts @@ -25,7 +25,6 @@ export class TerminalCapabilityManager { private static readonly TERMINAL_NAME_QUERY = '\x1b[>q'; private static readonly DEVICE_ATTRIBUTES_QUERY = '\x1b[c'; private static readonly MODIFY_OTHER_KEYS_QUERY = '\x1b[>4;?m'; - private static readonly BRACKETED_PASTE_QUERY = '\x1b[?2004$p'; // Kitty keyboard flags: CSI ? flags u // eslint-disable-next-line no-control-regex @@ -43,10 +42,6 @@ export class TerminalCapabilityManager { // modifyOtherKeys response: CSI > 4 ; level m // eslint-disable-next-line no-control-regex private static readonly MODIFY_OTHER_KEYS_REGEX = /\x1b\[>4;(\d+)m/; - // DECRQM response for bracketed paste: CSI ? 2004 ; Ps $ y - // Ps = 1 (set), 2 (reset), 3 (permanently set), 4 (permanently reset) - // eslint-disable-next-line no-control-regex - private static readonly BRACKETED_PASTE_REGEX = /\x1b\[\?2004;([1-4])\$y/; private terminalBackgroundColor: TerminalBackgroundColor; private kittySupported = false; @@ -55,7 +50,6 @@ export class TerminalCapabilityManager { private terminalName: string | undefined; private modifyOtherKeysSupported = false; private modifyOtherKeysEnabled = false; - private bracketedPasteSupported = false; private bracketedPasteEnabled = false; private constructor() {} @@ -107,7 +101,6 @@ export class TerminalCapabilityManager { let deviceAttributesReceived = false; let bgReceived = false; let modifyOtherKeysReceived = false; - let bracketedPasteReceived = false; // eslint-disable-next-line prefer-const let timeoutId: NodeJS.Timeout; @@ -172,17 +165,6 @@ export class TerminalCapabilityManager { } } - // check for bracketed paste support - if (!bracketedPasteReceived) { - const match = buffer.match( - TerminalCapabilityManager.BRACKETED_PASTE_REGEX, - ); - if (match) { - bracketedPasteReceived = true; - this.bracketedPasteSupported = true; - } - } - // Check for Terminal Name/Version response. if (!terminalNameReceived) { const match = buffer.match( @@ -219,7 +201,6 @@ export class TerminalCapabilityManager { TerminalCapabilityManager.OSC_11_QUERY + TerminalCapabilityManager.TERMINAL_NAME_QUERY + TerminalCapabilityManager.MODIFY_OTHER_KEYS_QUERY + - TerminalCapabilityManager.BRACKETED_PASTE_QUERY + TerminalCapabilityManager.DEVICE_ATTRIBUTES_QUERY, ); } catch (e) { @@ -238,10 +219,9 @@ export class TerminalCapabilityManager { enableModifyOtherKeys(); this.modifyOtherKeysEnabled = true; } - if (this.bracketedPasteSupported) { - enableBracketedPasteMode(); - this.bracketedPasteEnabled = true; - } + // Always enable bracketed paste since it'll be ignored if unsupported. + enableBracketedPasteMode(); + this.bracketedPasteEnabled = true; } catch (e) { debugLogger.warn('Failed to enable keyboard protocols:', e); } @@ -259,10 +239,6 @@ export class TerminalCapabilityManager { return this.kittyEnabled; } - isBracketedPasteSupported(): boolean { - return this.bracketedPasteSupported; - } - isBracketedPasteEnabled(): boolean { return this.bracketedPasteEnabled; } From f7b97ef55ec96d851c53998ea19d090e4e01cff0 Mon Sep 17 00:00:00 2001 From: Ishaan Gupta Date: Fri, 9 Jan 2026 22:17:54 +0530 Subject: [PATCH 090/713] refactor: migrate app containter hook calls to hook system (#16161) --- packages/cli/src/ui/AppContainer.tsx | 61 +++++++++++----------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index 7687a096c1..19f4ed44f2 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -59,8 +59,6 @@ import { startupProfiler, SessionStartSource, SessionEndReason, - fireSessionStartHook, - fireSessionEndHook, generateSummary, } from '@google/gemini-cli-core'; import { validateAuthMethod } from '../config/auth.js'; @@ -294,38 +292,31 @@ export const AppContainer = (props: AppContainerProps) => { setConfigInitialized(true); startupProfiler.flush(config); - // Fire SessionStart hook through MessageBus (only if hooks are enabled) - // Must be called AFTER config.initialize() to ensure HookRegistry is loaded - const hooksEnabled = config.getEnableHooks(); - const hookMessageBus = config.getMessageBus(); - if (hooksEnabled && hookMessageBus) { - const sessionStartSource = resumedSessionData - ? SessionStartSource.Resume - : SessionStartSource.Startup; - const result = await fireSessionStartHook( - hookMessageBus, - sessionStartSource, - ); + const sessionStartSource = resumedSessionData + ? SessionStartSource.Resume + : SessionStartSource.Startup; + const result = await config + .getHookSystem() + ?.fireSessionStartEvent(sessionStartSource); - if (result) { - if (result.systemMessage) { - historyManager.addItem( - { - type: MessageType.INFO, - text: result.systemMessage, - }, - Date.now(), - ); - } + if (result?.finalOutput) { + if (result.finalOutput?.systemMessage) { + historyManager.addItem( + { + type: MessageType.INFO, + text: result.finalOutput.systemMessage, + }, + Date.now(), + ); + } - const additionalContext = result.getAdditionalContext(); - const geminiClient = config.getGeminiClient(); - if (additionalContext && geminiClient) { - await geminiClient.addHistory({ - role: 'user', - parts: [{ text: additionalContext }], - }); - } + const additionalContext = result.finalOutput.getAdditionalContext(); + const geminiClient = config.getGeminiClient(); + if (additionalContext && geminiClient) { + await geminiClient.addHistory({ + role: 'user', + parts: [{ text: additionalContext }], + }); } } @@ -341,11 +332,7 @@ export const AppContainer = (props: AppContainerProps) => { await ideClient.disconnect(); // Fire SessionEnd hook on cleanup (only if hooks are enabled) - const hooksEnabled = config.getEnableHooks(); - const hookMessageBus = config.getMessageBus(); - if (hooksEnabled && hookMessageBus) { - await fireSessionEndHook(hookMessageBus, SessionEndReason.Exit); - } + await config?.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Exit); }); // Disable the dependencies check here. historyManager gets flagged // but we don't want to react to changes to it because each new history From b9f8858bfb6ff8989ef098588dbf54da7c4e7e3d Mon Sep 17 00:00:00 2001 From: Vedant Mahajan Date: Fri, 9 Jan 2026 22:18:55 +0530 Subject: [PATCH 091/713] refactor: migrate clearCommand hook calls to HookSystem (#16157) --- .../cli/src/ui/commands/clearCommand.test.ts | 4 ++++ packages/cli/src/ui/commands/clearCommand.ts | 19 ++++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/ui/commands/clearCommand.test.ts b/packages/cli/src/ui/commands/clearCommand.test.ts index 7f16a3ddf6..bc204044f7 100644 --- a/packages/cli/src/ui/commands/clearCommand.test.ts +++ b/packages/cli/src/ui/commands/clearCommand.test.ts @@ -46,6 +46,10 @@ describe('clearCommand', () => { setSessionId: vi.fn(), getEnableHooks: vi.fn().mockReturnValue(false), getMessageBus: vi.fn().mockReturnValue(undefined), + getHookSystem: vi.fn().mockReturnValue({ + fireSessionEndEvent: vi.fn().mockResolvedValue(undefined), + fireSessionStartEvent: vi.fn().mockResolvedValue(undefined), + }), }, }, }); diff --git a/packages/cli/src/ui/commands/clearCommand.ts b/packages/cli/src/ui/commands/clearCommand.ts index ec8b7a52ef..196be503a0 100644 --- a/packages/cli/src/ui/commands/clearCommand.ts +++ b/packages/cli/src/ui/commands/clearCommand.ts @@ -4,11 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import type { DefaultHookOutput } from '@google/gemini-cli-core'; import { uiTelemetryService, - fireSessionEndHook, - fireSessionStartHook, SessionEndReason, SessionStartSource, flushTelemetry, @@ -30,12 +27,9 @@ export const clearCommand: SlashCommand = { ?.getGeminiClient() ?.getChat() .getChatRecordingService(); - const messageBus = config?.getMessageBus(); // Fire SessionEnd hook before clearing - if (config?.getEnableHooks() && messageBus) { - await fireSessionEndHook(messageBus, SessionEndReason.Clear); - } + await config?.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Clear); if (geminiClient) { context.ui.setDebugMessage('Clearing terminal and resetting chat.'); @@ -54,10 +48,9 @@ export const clearCommand: SlashCommand = { } // Fire SessionStart hook after clearing - let result: DefaultHookOutput | undefined; - if (config?.getEnableHooks() && messageBus) { - result = await fireSessionStartHook(messageBus, SessionStartSource.Clear); - } + const result = await config + ?.getHookSystem() + ?.fireSessionStartEvent(SessionStartSource.Clear); // Give the event loop a chance to process any pending telemetry operations // This ensures logger.emit() calls have fully propagated to the BatchLogRecordProcessor @@ -72,11 +65,11 @@ export const clearCommand: SlashCommand = { uiTelemetryService.setLastPromptTokenCount(0); context.ui.clear(); - if (result?.systemMessage) { + if (result?.finalOutput?.systemMessage) { context.ui.addItem( { type: MessageType.INFO, - text: result.systemMessage, + text: result.finalOutput.systemMessage, }, Date.now(), ); From 77e226c55fe7e795982843596ad93ac1a5756983 Mon Sep 17 00:00:00 2001 From: christine betts Date: Fri, 9 Jan 2026 12:04:53 -0500 Subject: [PATCH 092/713] Show settings source in extensions lists (#16207) --- .../config/extension-manager-scope.test.ts | 196 ++++++++++++++++++ packages/cli/src/config/extension-manager.ts | 56 ++++- .../extensions/extensionSettings.test.ts | 13 +- .../config/extensions/extensionSettings.ts | 33 ++- .../extensions/extensionUpdates.test.ts | 24 ++- .../components/views/ExtensionsList.test.tsx | 13 +- .../ui/components/views/ExtensionsList.tsx | 9 + packages/core/src/config/config.ts | 2 + 8 files changed, 329 insertions(+), 17 deletions(-) create mode 100644 packages/cli/src/config/extension-manager-scope.test.ts diff --git a/packages/cli/src/config/extension-manager-scope.test.ts b/packages/cli/src/config/extension-manager-scope.test.ts new file mode 100644 index 0000000000..a42e198bd0 --- /dev/null +++ b/packages/cli/src/config/extension-manager-scope.test.ts @@ -0,0 +1,196 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import * as os from 'node:os'; +import { ExtensionManager } from './extension-manager.js'; +import type { Settings } from './settings.js'; + +let currentTempHome = ''; + +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + homedir: () => currentTempHome, + debugLogger: { + log: vi.fn(), + error: vi.fn(), + warn: vi.fn(), + }, + }; +}); + +describe('ExtensionManager Settings Scope', () => { + const extensionName = 'test-extension'; + let tempWorkspace: string; + let extensionsDir: string; + let extensionDir: string; + + beforeEach(async () => { + currentTempHome = fs.mkdtempSync( + path.join(os.tmpdir(), 'gemini-cli-test-home-'), + ); + tempWorkspace = fs.mkdtempSync( + path.join(os.tmpdir(), 'gemini-cli-test-workspace-'), + ); + extensionsDir = path.join(currentTempHome, '.gemini', 'extensions'); + extensionDir = path.join(extensionsDir, extensionName); + + fs.mkdirSync(extensionDir, { recursive: true }); + + // Create gemini-extension.json + const extensionConfig = { + name: extensionName, + version: '1.0.0', + settings: [ + { + name: 'Test Setting', + envVar: 'TEST_SETTING', + description: 'A test setting', + }, + ], + }; + fs.writeFileSync( + path.join(extensionDir, 'gemini-extension.json'), + JSON.stringify(extensionConfig), + ); + + // Create install metadata + const installMetadata = { + source: extensionDir, + type: 'local', + }; + fs.writeFileSync( + path.join(extensionDir, 'install-metadata.json'), + JSON.stringify(installMetadata), + ); + }); + + afterEach(() => { + // Clean up files if needed, or rely on temp dir cleanup + vi.clearAllMocks(); + }); + + it('should prioritize workspace settings over user settings and report correct scope', async () => { + // 1. Set User Setting + const userSettingsPath = path.join(extensionDir, '.env'); + fs.writeFileSync(userSettingsPath, 'TEST_SETTING=user-value'); + + // 2. Set Workspace Setting + const workspaceSettingsPath = path.join(tempWorkspace, '.env'); + fs.writeFileSync(workspaceSettingsPath, 'TEST_SETTING=workspace-value'); + + const extensionManager = new ExtensionManager({ + workspaceDir: tempWorkspace, + requestConsent: async () => true, + requestSetting: async () => '', + settings: { + telemetry: { + enabled: false, + }, + } as Settings, + }); + + const extensions = await extensionManager.loadExtensions(); + const extension = extensions.find((e) => e.name === extensionName); + + expect(extension).toBeDefined(); + + // Verify resolved settings + const setting = extension?.resolvedSettings?.find( + (s) => s.envVar === 'TEST_SETTING', + ); + expect(setting).toBeDefined(); + expect(setting?.value).toBe('workspace-value'); + expect(setting?.scope).toBe('workspace'); + expect(setting?.source).toBe(workspaceSettingsPath); + + // Verify output string contains (Workspace - ) + const output = extensionManager.toOutputString(extension!); + expect(output).toContain( + `Test Setting: workspace-value (Workspace - ${workspaceSettingsPath})`, + ); + }); + + it('should fallback to user settings if workspace setting is missing', async () => { + // 1. Set User Setting + const userSettingsPath = path.join(extensionDir, '.env'); + fs.writeFileSync(userSettingsPath, 'TEST_SETTING=user-value'); + + // 2. No Workspace Setting + + const extensionManager = new ExtensionManager({ + workspaceDir: tempWorkspace, + requestConsent: async () => true, + requestSetting: async () => '', + settings: { + telemetry: { + enabled: false, + }, + } as Settings, + }); + + const extensions = await extensionManager.loadExtensions(); + const extension = extensions.find((e) => e.name === extensionName); + + expect(extension).toBeDefined(); + + // Verify resolved settings + const setting = extension?.resolvedSettings?.find( + (s) => s.envVar === 'TEST_SETTING', + ); + expect(setting).toBeDefined(); + expect(setting?.value).toBe('user-value'); + expect(setting?.scope).toBe('user'); + expect(setting?.source?.endsWith(path.join(extensionName, '.env'))).toBe( + true, + ); + + // Verify output string contains (User - ) + const output = extensionManager.toOutputString(extension!); + expect(output).toContain( + `Test Setting: user-value (User - ${userSettingsPath})`, + ); + }); + + it('should report unset if neither is present', async () => { + // No settings files + + const extensionManager = new ExtensionManager({ + workspaceDir: tempWorkspace, + requestConsent: async () => true, + requestSetting: async () => '', + settings: { + telemetry: { + enabled: false, + }, + } as Settings, + }); + + const extensions = await extensionManager.loadExtensions(); + const extension = extensions.find((e) => e.name === extensionName); + + expect(extension).toBeDefined(); + + // Verify resolved settings + const setting = extension?.resolvedSettings?.find( + (s) => s.envVar === 'TEST_SETTING', + ); + expect(setting).toBeDefined(); + expect(setting?.value).toBe('[not set]'); + expect(setting?.scope).toBeUndefined(); + + // Verify output string does not contain scope + const output = extensionManager.toOutputString(extension!); + expect(output).toContain('Test Setting: [not set]'); + expect(output).not.toContain('Test Setting: [not set] (User)'); + expect(output).not.toContain('Test Setting: [not set] (Workspace)'); + }); +}); diff --git a/packages/cli/src/config/extension-manager.ts b/packages/cli/src/config/extension-manager.ts index 998b91529c..d979692441 100644 --- a/packages/cli/src/config/extension-manager.ts +++ b/packages/cli/src/config/extension-manager.ts @@ -59,9 +59,12 @@ import { } from './extensions/variables.js'; import { getEnvContents, + getEnvFilePath, maybePromptForSettings, getMissingSettings, type ExtensionSetting, + getScopedEnvContents, + ExtensionSettingScope, } from './extensions/extensionSettings.js'; import type { EventEmitter } from 'node:stream'; import { getEnableHooks } from './settingsSchema.js'; @@ -277,6 +280,7 @@ Would you like to attempt to install via "git clone" instead?`, previousSettings = await getEnvContents( previousExtensionConfig, extensionId, + this.workspaceDir, ); await this.uninstallExtension(newExtensionName, isUpdate); } @@ -303,6 +307,7 @@ Would you like to attempt to install via "git clone" instead?`, const missingSettings = await getMissingSettings( newExtensionConfig, extensionId, + this.workspaceDir, ); if (missingSettings.length > 0) { const message = `Extension "${newExtensionConfig.name}" has missing settings: ${missingSettings @@ -518,16 +523,51 @@ Would you like to attempt to install via "git clone" instead?`, ); } - const customEnv = await getEnvContents( + const extensionId = getExtensionId(config, installMetadata); + + const userSettings = await getScopedEnvContents( config, - getExtensionId(config, installMetadata), + extensionId, + ExtensionSettingScope.USER, ); + const workspaceSettings = await getScopedEnvContents( + config, + extensionId, + ExtensionSettingScope.WORKSPACE, + this.workspaceDir, + ); + + const customEnv = { ...userSettings, ...workspaceSettings }; config = resolveEnvVarsInObject(config, customEnv); const resolvedSettings: ResolvedExtensionSetting[] = []; if (config.settings) { for (const setting of config.settings) { const value = customEnv[setting.envVar]; + let scope: 'user' | 'workspace' | undefined; + let source: string | undefined; + + // Note: strict check for undefined, as empty string is a valid value + if (workspaceSettings[setting.envVar] !== undefined) { + scope = 'workspace'; + if (setting.sensitive) { + source = 'Keychain'; + } else { + source = getEnvFilePath( + config.name, + ExtensionSettingScope.WORKSPACE, + this.workspaceDir, + ); + } + } else if (userSettings[setting.envVar] !== undefined) { + scope = 'user'; + if (setting.sensitive) { + source = 'Keychain'; + } else { + source = getEnvFilePath(config.name, ExtensionSettingScope.USER); + } + } + resolvedSettings.push({ name: setting.name, envVar: setting.envVar, @@ -538,6 +578,8 @@ Would you like to attempt to install via "git clone" instead?`, ? '***' : value, sensitive: setting.sensitive ?? false, + scope, + source, }); } } @@ -754,7 +796,15 @@ Would you like to attempt to install via "git clone" instead?`, if (resolvedSettings && resolvedSettings.length > 0) { output += `\n Settings:`; resolvedSettings.forEach((setting) => { - output += `\n ${setting.name}: ${setting.value}`; + let scope = ''; + if (setting.scope) { + scope = setting.scope === 'workspace' ? '(Workspace' : '(User'; + if (setting.source) { + scope += ` - ${setting.source}`; + } + scope += ')'; + } + output += `\n ${setting.name}: ${setting.value} ${scope}`; }); } return output; diff --git a/packages/cli/src/config/extensions/extensionSettings.test.ts b/packages/cli/src/config/extensions/extensionSettings.test.ts index 39b1eafe40..db527f1ecb 100644 --- a/packages/cli/src/config/extensions/extensionSettings.test.ts +++ b/packages/cli/src/config/extensions/extensionSettings.test.ts @@ -529,6 +529,7 @@ describe('extensionSettings', () => { config, extensionId, ExtensionSettingScope.USER, + tempWorkspaceDir, ); expect(contents).toEqual({ @@ -552,6 +553,7 @@ describe('extensionSettings', () => { config, extensionId, ExtensionSettingScope.WORKSPACE, + tempWorkspaceDir, ); expect(contents).toEqual({ @@ -596,7 +598,11 @@ describe('extensionSettings', () => { ); await workspaceKeychain.setSecret('VAR2', 'workspace-secret2'); - const contents = await getEnvContents(config, extensionId); + const contents = await getEnvContents( + config, + extensionId, + tempWorkspaceDir, + ); expect(contents).toEqual({ VAR1: 'workspace-value1', @@ -636,6 +642,7 @@ describe('extensionSettings', () => { 'VAR1', mockRequestSetting, ExtensionSettingScope.USER, + tempWorkspaceDir, ); const expectedEnvPath = path.join(extensionDir, '.env'); @@ -652,6 +659,7 @@ describe('extensionSettings', () => { 'VAR1', mockRequestSetting, ExtensionSettingScope.WORKSPACE, + tempWorkspaceDir, ); const expectedEnvPath = path.join(tempWorkspaceDir, '.env'); @@ -668,6 +676,7 @@ describe('extensionSettings', () => { 'VAR2', mockRequestSetting, ExtensionSettingScope.USER, + tempWorkspaceDir, ); const userKeychain = new KeychainTokenStorage( @@ -685,6 +694,7 @@ describe('extensionSettings', () => { 'VAR2', mockRequestSetting, ExtensionSettingScope.WORKSPACE, + tempWorkspaceDir, ); const workspaceKeychain = new KeychainTokenStorage( @@ -710,6 +720,7 @@ describe('extensionSettings', () => { 'VAR1', mockRequestSetting, ExtensionSettingScope.WORKSPACE, + tempWorkspaceDir, ); // Read the .env file after update diff --git a/packages/cli/src/config/extensions/extensionSettings.ts b/packages/cli/src/config/extensions/extensionSettings.ts index 582a94c807..482c206cd6 100644 --- a/packages/cli/src/config/extensions/extensionSettings.ts +++ b/packages/cli/src/config/extensions/extensionSettings.ts @@ -33,20 +33,28 @@ const getKeychainStorageName = ( extensionName: string, extensionId: string, scope: ExtensionSettingScope, + workspaceDir?: string, ): string => { const base = `Gemini CLI Extensions ${extensionName} ${extensionId}`; if (scope === ExtensionSettingScope.WORKSPACE) { - return `${base} ${process.cwd()}`; + if (!workspaceDir) { + throw new Error('Workspace directory is required for workspace scope'); + } + return `${base} ${workspaceDir}`; } return base; }; -const getEnvFilePath = ( +export const getEnvFilePath = ( extensionName: string, scope: ExtensionSettingScope, + workspaceDir?: string, ): string => { if (scope === ExtensionSettingScope.WORKSPACE) { - return path.join(process.cwd(), EXTENSION_SETTINGS_FILENAME); + if (!workspaceDir) { + throw new Error('Workspace directory is required for workspace scope'); + } + return path.join(workspaceDir, EXTENSION_SETTINGS_FILENAME); } return new ExtensionStorage(extensionName).getEnvFilePath(); }; @@ -143,12 +151,13 @@ export async function getScopedEnvContents( extensionConfig: ExtensionConfig, extensionId: string, scope: ExtensionSettingScope, + workspaceDir?: string, ): Promise> { const { name: extensionName } = extensionConfig; const keychain = new KeychainTokenStorage( - getKeychainStorageName(extensionName, extensionId, scope), + getKeychainStorageName(extensionName, extensionId, scope, workspaceDir), ); - const envFilePath = getEnvFilePath(extensionName, scope); + const envFilePath = getEnvFilePath(extensionName, scope, workspaceDir); let customEnv: Record = {}; if (fsSync.existsSync(envFilePath)) { const envFile = fsSync.readFileSync(envFilePath, 'utf-8'); @@ -171,6 +180,7 @@ export async function getScopedEnvContents( export async function getEnvContents( extensionConfig: ExtensionConfig, extensionId: string, + workspaceDir: string, ): Promise> { if (!extensionConfig.settings || extensionConfig.settings.length === 0) { return Promise.resolve({}); @@ -185,6 +195,7 @@ export async function getEnvContents( extensionConfig, extensionId, ExtensionSettingScope.WORKSPACE, + workspaceDir, ); return { ...userSettings, ...workspaceSettings }; @@ -196,6 +207,7 @@ export async function updateSetting( settingKey: string, requestSetting: (setting: ExtensionSetting) => Promise, scope: ExtensionSettingScope, + workspaceDir?: string, ): Promise { const { name: extensionName, settings } = extensionConfig; if (!settings || settings.length === 0) { @@ -214,7 +226,7 @@ export async function updateSetting( const newValue = await requestSetting(settingToUpdate); const keychain = new KeychainTokenStorage( - getKeychainStorageName(extensionName, extensionId, scope), + getKeychainStorageName(extensionName, extensionId, scope, workspaceDir), ); if (settingToUpdate.sensitive) { @@ -224,7 +236,7 @@ export async function updateSetting( // For non-sensitive settings, we need to read the existing .env file, // update the value, and write it back, preserving any other values. - const envFilePath = getEnvFilePath(extensionName, scope); + const envFilePath = getEnvFilePath(extensionName, scope, workspaceDir); let envContent = ''; if (fsSync.existsSync(envFilePath)) { envContent = await fs.readFile(envFilePath, 'utf-8'); @@ -302,13 +314,18 @@ async function clearSettings( export async function getMissingSettings( extensionConfig: ExtensionConfig, extensionId: string, + workspaceDir: string, ): Promise { const { settings } = extensionConfig; if (!settings || settings.length === 0) { return []; } - const existingSettings = await getEnvContents(extensionConfig, extensionId); + const existingSettings = await getEnvContents( + extensionConfig, + extensionId, + workspaceDir, + ); const missingSettings: ExtensionSetting[] = []; for (const setting of settings) { diff --git a/packages/cli/src/config/extensions/extensionUpdates.test.ts b/packages/cli/src/config/extensions/extensionUpdates.test.ts index bdd2841ad6..1e30e0b898 100644 --- a/packages/cli/src/config/extensions/extensionUpdates.test.ts +++ b/packages/cli/src/config/extensions/extensionUpdates.test.ts @@ -154,7 +154,11 @@ describe('extensionUpdates', () => { ); await userKeychain.setSecret('VAR2', 'val2'); - const missing = await getMissingSettings(config, extensionId); + const missing = await getMissingSettings( + config, + extensionId, + tempWorkspaceDir, + ); expect(missing).toEqual([]); }); @@ -166,7 +170,11 @@ describe('extensionUpdates', () => { }; const extensionId = '12345'; - const missing = await getMissingSettings(config, extensionId); + const missing = await getMissingSettings( + config, + extensionId, + tempWorkspaceDir, + ); expect(missing).toHaveLength(1); expect(missing[0].name).toBe('s1'); }); @@ -181,7 +189,11 @@ describe('extensionUpdates', () => { }; const extensionId = '12345'; - const missing = await getMissingSettings(config, extensionId); + const missing = await getMissingSettings( + config, + extensionId, + tempWorkspaceDir, + ); expect(missing).toHaveLength(1); expect(missing[0].name).toBe('s2'); }); @@ -201,7 +213,11 @@ describe('extensionUpdates', () => { ); fs.writeFileSync(workspaceEnvPath, 'VAR1=val1'); - const missing = await getMissingSettings(config, extensionId); + const missing = await getMissingSettings( + config, + extensionId, + tempWorkspaceDir, + ); expect(missing).toEqual([]); }); }); diff --git a/packages/cli/src/ui/components/views/ExtensionsList.test.tsx b/packages/cli/src/ui/components/views/ExtensionsList.test.tsx index 7fb5d2f361..b1aa1e83db 100644 --- a/packages/cli/src/ui/components/views/ExtensionsList.test.tsx +++ b/packages/cli/src/ui/components/views/ExtensionsList.test.tsx @@ -142,6 +142,16 @@ describe('', () => { value: '1000', envVar: 'MAX_TOKENS', sensitive: false, + scope: 'user' as const, + source: '/path/to/.env', + }, + { + name: 'model', + value: 'gemini-pro', + envVar: 'MODEL', + sensitive: false, + scope: 'workspace' as const, + source: 'Keychain', }, ], }; @@ -151,7 +161,8 @@ describe('', () => { const output = lastFrame(); expect(output).toContain('settings:'); expect(output).toContain('- sensitiveApiKey: ***'); - expect(output).toContain('- maxTokens: 1000'); + expect(output).toContain('- maxTokens: 1000 (User - /path/to/.env)'); + expect(output).toContain('- model: gemini-pro (Workspace - Keychain)'); unmount(); }); }); diff --git a/packages/cli/src/ui/components/views/ExtensionsList.tsx b/packages/cli/src/ui/components/views/ExtensionsList.tsx index 2d456625f1..27ce6f5e92 100644 --- a/packages/cli/src/ui/components/views/ExtensionsList.tsx +++ b/packages/cli/src/ui/components/views/ExtensionsList.tsx @@ -71,6 +71,15 @@ export const ExtensionsList: React.FC = ({ extensions }) => { {ext.resolvedSettings.map((setting) => ( - {setting.name}: {setting.value} + {setting.scope && ( + + {' '} + ( + {setting.scope.charAt(0).toUpperCase() + + setting.scope.slice(1)} + {setting.source ? ` - ${setting.source}` : ''}) + + )} ))} diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 01615c1081..2a9ae19284 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -149,6 +149,8 @@ export interface ResolvedExtensionSetting { envVar: string; value: string; sensitive: boolean; + scope?: 'user' | 'workspace'; + source?: string; } export interface CliHelpAgentSettings { From 8bc3cfe29a6339c81eb5d777ec489def6a2e695c Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 9 Jan 2026 09:25:14 -0800 Subject: [PATCH 093/713] feat(skills): add pr-creator skill and enable skills (#16232) --- .gemini/settings.json | 5 ++++ .gemini/skills/pr-creator/SKILL.md | 37 ++++++++++++++++++++++++++++++ .gitignore | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 .gemini/settings.json create mode 100644 .gemini/skills/pr-creator/SKILL.md diff --git a/.gemini/settings.json b/.gemini/settings.json new file mode 100644 index 0000000000..aaac8204b6 --- /dev/null +++ b/.gemini/settings.json @@ -0,0 +1,5 @@ +{ + "experimental": { + "skills": true + } +} diff --git a/.gemini/skills/pr-creator/SKILL.md b/.gemini/skills/pr-creator/SKILL.md new file mode 100644 index 0000000000..f89a3d07e0 --- /dev/null +++ b/.gemini/skills/pr-creator/SKILL.md @@ -0,0 +1,37 @@ +--- +name: pr-creator +description: Use this skill when asked to create a pull request (PR). It ensures all PRs follow the repository's established templates and standards. +--- + +# Pull Request Creator + +This skill guides the creation of high-quality Pull Requests that adhere to the repository's standards. + +## Workflow + +Follow these steps to create a Pull Request: + +1. **Locate Template**: Search for a pull request template in the repository. + * Check `.github/pull_request_template.md` + * Check `.github/PULL_REQUEST_TEMPLATE.md` + * If multiple templates exist (e.g., in `.github/PULL_REQUEST_TEMPLATE/`), ask the user which one to use or select the most appropriate one based on the context (e.g., `bug_fix.md` vs `feature.md`). + +2. **Read Template**: Read the content of the identified template file. + +3. **Draft Description**: Create a PR description that strictly follows the template's structure. + * **Headings**: Keep all headings from the template. + * **Checklists**: Review each item. Mark with `[x]` if completed. If an item is not applicable, leave it unchecked or mark as `[ ]` (depending on the template's instructions) or remove it if the template allows flexibility (but prefer keeping it unchecked for transparency). + * **Content**: Fill in the sections with clear, concise summaries of your changes. + * **Related Issues**: Link any issues fixed or related to this PR (e.g., "Fixes #123"). + +4. **Create PR**: Use the `gh` CLI to create the PR. + ```bash + gh pr create --title "type(scope): succinct description" --body "..." + ``` + * **Title**: Ensure the title follows the [Conventional Commits](https://www.conventionalcommits.org/) format if the repository uses it (e.g., `feat(ui): add new button`, `fix(core): resolve crash`). + +## Principles + +* **Compliance**: Never ignore the PR template. It exists for a reason. +* **Completeness**: Fill out all relevant sections. +* **Accuracy**: Don't check boxes for tasks you haven't done. diff --git a/.gitignore b/.gitignore index d9cfed7b0d..bfb2b5e576 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ .gemini/* !.gemini/config.yaml !.gemini/commands/ +!.gemini/skills/ +!.gemini/settings.json # Note: .gemini-clipboard/ is NOT in gitignore so Gemini can access pasted images From c1401682ed0d65e511310c92e83d2601c919c14f Mon Sep 17 00:00:00 2001 From: Tu Shaokun <53142663+tt-a1i@users.noreply.github.com> Date: Sat, 10 Jan 2026 01:28:14 +0800 Subject: [PATCH 094/713] fix: handle Shift+Space in Kitty keyboard protocol terminals (#15767) --- .../src/ui/contexts/KeypressContext.test.tsx | 36 ++++++++++++++----- .../cli/src/ui/contexts/KeypressContext.tsx | 5 +++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/ui/contexts/KeypressContext.test.tsx b/packages/cli/src/ui/contexts/KeypressContext.test.tsx index c4ce92ee52..fddca507dd 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.test.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.test.tsx @@ -224,40 +224,60 @@ describe('KeypressContext', () => { }); }); - describe('Tab and Backspace handling', () => { + describe('Tab, Backspace, and Space handling', () => { it.each([ { name: 'Tab key', - sequence: '\x1b[9u', + inputSequence: '\x1b[9u', expected: { name: 'tab', shift: false }, }, { name: 'Shift+Tab', - sequence: '\x1b[9;2u', + inputSequence: '\x1b[9;2u', expected: { name: 'tab', shift: true }, }, { name: 'Backspace', - sequence: '\x1b[127u', + inputSequence: '\x1b[127u', expected: { name: 'backspace', meta: false }, }, { name: 'Option+Backspace', - sequence: '\x1b[127;3u', + inputSequence: '\x1b[127;3u', expected: { name: 'backspace', meta: true }, }, { name: 'Ctrl+Backspace', - sequence: '\x1b[127;5u', + inputSequence: '\x1b[127;5u', expected: { name: 'backspace', ctrl: true }, }, + { + name: 'Shift+Space', + inputSequence: '\x1b[32;2u', + expected: { + name: 'space', + shift: true, + insertable: true, + sequence: ' ', + }, + }, + { + name: 'Ctrl+Space', + inputSequence: '\x1b[32;5u', + expected: { + name: 'space', + ctrl: true, + insertable: false, + sequence: '\x1b[32;5u', + }, + }, ])( 'should recognize $name in kitty protocol', - async ({ sequence, expected }) => { + async ({ inputSequence, expected }) => { const { keyHandler } = setupKeypressTest(); act(() => { - stdin.write(sequence); + stdin.write(inputSequence); }); expect(keyHandler).toHaveBeenCalledWith( diff --git a/packages/cli/src/ui/contexts/KeypressContext.tsx b/packages/cli/src/ui/contexts/KeypressContext.tsx index f1680a5b26..1faa705220 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.tsx @@ -84,6 +84,7 @@ const KEY_INFO_MAP: Record< '[9u': { name: 'tab' }, '[13u': { name: 'return' }, '[27u': { name: 'escape' }, + '[32u': { name: 'space' }, '[127u': { name: 'backspace' }, '[57414u': { name: 'return' }, // Numpad Enter '[a': { name: 'up', shift: true }, @@ -479,6 +480,10 @@ function* emitKeys( if (keyInfo.ctrl) { ctrl = true; } + if (name === 'space' && !ctrl && !meta) { + sequence = ' '; + insertable = true; + } } else { name = 'undefined'; if ((ctrl || meta) && (code.endsWith('u') || code.endsWith('~'))) { From 041463d112265fbf7cf9a5ab2e7fcdb860c80dd9 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Fri, 9 Jan 2026 09:33:59 -0800 Subject: [PATCH 095/713] feat(core, ui): Add `/agents refresh` command. (#16204) --- .../cli/src/ui/commands/agentsCommand.test.ts | 36 +++++++++++++++++ packages/cli/src/ui/commands/agentsCommand.ts | 39 ++++++++++++++++++- .../src/agents/a2a-client-manager.test.ts | 14 +++++++ .../core/src/agents/a2a-client-manager.ts | 9 +++++ packages/core/src/agents/registry.test.ts | 33 +++++++++++++++- packages/core/src/agents/registry.ts | 20 ++++++++-- packages/core/src/utils/events.ts | 9 +++++ 7 files changed, 154 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/ui/commands/agentsCommand.test.ts b/packages/cli/src/ui/commands/agentsCommand.test.ts index 1e871bae6a..5c1fe5892d 100644 --- a/packages/cli/src/ui/commands/agentsCommand.test.ts +++ b/packages/cli/src/ui/commands/agentsCommand.test.ts @@ -82,4 +82,40 @@ describe('agentsCommand', () => { expect.any(Number), ); }); + + it('should reload the agent registry when refresh subcommand is called', async () => { + const reloadSpy = vi.fn().mockResolvedValue(undefined); + mockConfig.getAgentRegistry = vi.fn().mockReturnValue({ + reload: reloadSpy, + }); + + const refreshCommand = agentsCommand.subCommands?.find( + (cmd) => cmd.name === 'refresh', + ); + expect(refreshCommand).toBeDefined(); + + const result = await refreshCommand!.action!(mockContext, ''); + + expect(reloadSpy).toHaveBeenCalled(); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: 'Agents refreshed successfully.', + }); + }); + + it('should show an error if agent registry is not available during refresh', async () => { + mockConfig.getAgentRegistry = vi.fn().mockReturnValue(undefined); + + const refreshCommand = agentsCommand.subCommands?.find( + (cmd) => cmd.name === 'refresh', + ); + const result = await refreshCommand!.action!(mockContext, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: 'Agent registry not found.', + }); + }); }); diff --git a/packages/cli/src/ui/commands/agentsCommand.ts b/packages/cli/src/ui/commands/agentsCommand.ts index 516c326662..d904e8ca78 100644 --- a/packages/cli/src/ui/commands/agentsCommand.ts +++ b/packages/cli/src/ui/commands/agentsCommand.ts @@ -8,8 +8,8 @@ import type { SlashCommand, CommandContext } from './types.js'; import { CommandKind } from './types.js'; import { MessageType, type HistoryItemAgentsList } from '../types.js'; -export const agentsCommand: SlashCommand = { - name: 'agents', +const agentsListCommand: SlashCommand = { + name: 'list', description: 'List available local and remote agents', kind: CommandKind.BUILT_IN, autoExecute: true, @@ -49,3 +49,38 @@ export const agentsCommand: SlashCommand = { return; }, }; + +const agentsRefreshCommand: SlashCommand = { + name: 'refresh', + description: 'Reload the agent registry', + kind: CommandKind.BUILT_IN, + action: async (context: CommandContext) => { + const { config } = context.services; + const agentRegistry = config?.getAgentRegistry(); + if (!agentRegistry) { + return { + type: 'message', + messageType: 'error', + content: 'Agent registry not found.', + }; + } + + await agentRegistry.reload(); + + return { + type: 'message', + messageType: 'info', + content: 'Agents refreshed successfully.', + }; + }, +}; + +export const agentsCommand: SlashCommand = { + name: 'agents', + description: 'Manage agents', + kind: CommandKind.BUILT_IN, + subCommands: [agentsListCommand, agentsRefreshCommand], + action: async (context: CommandContext, args) => + // Default to list if no subcommand is provided + agentsListCommand.action!(context, args), +}; diff --git a/packages/core/src/agents/a2a-client-manager.test.ts b/packages/core/src/agents/a2a-client-manager.test.ts index 4406cac966..6d6561c963 100644 --- a/packages/core/src/agents/a2a-client-manager.test.ts +++ b/packages/core/src/agents/a2a-client-manager.test.ts @@ -162,6 +162,20 @@ describe('A2AClientManager', () => { "[A2AClientManager] Loaded agent 'TestAgent' from http://test.agent/card", ); }); + + it('should clear the cache', async () => { + await manager.loadAgent('TestAgent', 'http://test.agent/card'); + expect(manager.getAgentCard('TestAgent')).toBeDefined(); + expect(manager.getClient('TestAgent')).toBeDefined(); + + manager.clearCache(); + + expect(manager.getAgentCard('TestAgent')).toBeUndefined(); + expect(manager.getClient('TestAgent')).toBeUndefined(); + expect(debugLogger.debug).toHaveBeenCalledWith( + '[A2AClientManager] Cache cleared.', + ); + }); }); describe('sendMessage', () => { diff --git a/packages/core/src/agents/a2a-client-manager.ts b/packages/core/src/agents/a2a-client-manager.ts index c00fdfee43..ff379f1719 100644 --- a/packages/core/src/agents/a2a-client-manager.ts +++ b/packages/core/src/agents/a2a-client-manager.ts @@ -104,6 +104,15 @@ export class A2AClientManager { return agentCard; } + /** + * Invalidates all cached clients and agent cards. + */ + clearCache(): void { + this.clients.clear(); + this.agentCards.clear(); + debugLogger.debug('[A2AClientManager] Cache cleared.'); + } + /** * Sends a message to a loaded agent. * @param agentName The name of the agent to send the message to. diff --git a/packages/core/src/agents/registry.test.ts b/packages/core/src/agents/registry.test.ts index 84a9001a03..073dd5ac10 100644 --- a/packages/core/src/agents/registry.test.ts +++ b/packages/core/src/agents/registry.test.ts @@ -99,7 +99,7 @@ describe('AgentRegistry', () => { const agentCount = debugRegistry.getAllDefinitions().length; expect(debugLogSpy).toHaveBeenCalledWith( - `[AgentRegistry] Initialized with ${agentCount} agents.`, + `[AgentRegistry] Loaded with ${agentCount} agents.`, ); }); @@ -444,6 +444,37 @@ describe('AgentRegistry', () => { }); }); + describe('reload', () => { + it('should clear existing agents and reload from directories', async () => { + const config = makeFakeConfig({ enableAgents: true }); + const registry = new TestableAgentRegistry(config); + + const initialAgent = { ...MOCK_AGENT_V1, name: 'InitialAgent' }; + await registry.testRegisterAgent(initialAgent); + expect(registry.getDefinition('InitialAgent')).toBeDefined(); + + const newAgent = { ...MOCK_AGENT_V1, name: 'NewAgent' }; + vi.mocked(tomlLoader.loadAgentsFromDirectory).mockResolvedValue({ + agents: [newAgent], + errors: [], + }); + + const clearCacheSpy = vi.fn(); + vi.mocked(A2AClientManager.getInstance).mockReturnValue({ + clearCache: clearCacheSpy, + } as unknown as A2AClientManager); + + const emitSpy = vi.spyOn(coreEvents, 'emitAgentsRefreshed'); + + await registry.reload(); + + expect(clearCacheSpy).toHaveBeenCalled(); + expect(registry.getDefinition('InitialAgent')).toBeUndefined(); + expect(registry.getDefinition('NewAgent')).toBeDefined(); + expect(emitSpy).toHaveBeenCalled(); + }); + }); + describe('inheritance and refresh', () => { it('should resolve "inherit" to the current model from configuration', async () => { const config = makeFakeConfig({ model: 'current-model' }); diff --git a/packages/core/src/agents/registry.ts b/packages/core/src/agents/registry.ts index ee42795a66..8a35a70241 100644 --- a/packages/core/src/agents/registry.ts +++ b/packages/core/src/agents/registry.ts @@ -46,8 +46,6 @@ export class AgentRegistry { * Discovers and loads agents. */ async initialize(): Promise { - this.loadBuiltInAgents(); - coreEvents.on(CoreEvent.ModelChanged, () => { this.refreshAgents().catch((e) => { debugLogger.error( @@ -57,6 +55,22 @@ export class AgentRegistry { }); }); + await this.loadAgents(); + } + + /** + * Clears the current registry and re-scans for agents. + */ + async reload(): Promise { + A2AClientManager.getInstance().clearCache(); + this.agents.clear(); + await this.loadAgents(); + coreEvents.emitAgentsRefreshed(); + } + + private async loadAgents(): Promise { + this.loadBuiltInAgents(); + if (!this.config.isAgentsEnabled()) { return; } @@ -99,7 +113,7 @@ export class AgentRegistry { if (this.config.getDebugMode()) { debugLogger.log( - `[AgentRegistry] Initialized with ${this.agents.size} agents.`, + `[AgentRegistry] Loaded with ${this.agents.size} agents.`, ); } } diff --git a/packages/core/src/utils/events.ts b/packages/core/src/utils/events.ts index 84058f9d99..89dd02395f 100644 --- a/packages/core/src/utils/events.ts +++ b/packages/core/src/utils/events.ts @@ -107,6 +107,7 @@ export enum CoreEvent { SettingsChanged = 'settings-changed', HookStart = 'hook-start', HookEnd = 'hook-end', + AgentsRefreshed = 'agents-refreshed', } export interface CoreEvents { @@ -119,6 +120,7 @@ export interface CoreEvents { [CoreEvent.SettingsChanged]: never[]; [CoreEvent.HookStart]: [HookStartPayload]; [CoreEvent.HookEnd]: [HookEndPayload]; + [CoreEvent.AgentsRefreshed]: never[]; } type EventBacklogItem = { @@ -220,6 +222,13 @@ export class CoreEventEmitter extends EventEmitter { this.emit(CoreEvent.HookEnd, payload); } + /** + * Notifies subscribers that agents have been refreshed. + */ + emitAgentsRefreshed(): void { + this.emit(CoreEvent.AgentsRefreshed); + } + /** * Flushes buffered messages. Call this immediately after primary UI listener * subscribes. From ca4866142339601a70db5daa837ab10baf450755 Mon Sep 17 00:00:00 2001 From: Kevin Ramdass Date: Fri, 9 Jan 2026 10:47:05 -0800 Subject: [PATCH 096/713] feat(core): add local experiments override via GEMINI_EXP (#16181) --- .../code_assist/experiments/experiments.ts | 28 +++- .../experiments/experiments_local.test.ts | 146 ++++++++++++++++++ packages/core/src/config/config.test.ts | 4 + packages/core/src/config/config.ts | 48 +++--- 4 files changed, 197 insertions(+), 29 deletions(-) create mode 100644 packages/core/src/code_assist/experiments/experiments_local.test.ts diff --git a/packages/core/src/code_assist/experiments/experiments.ts b/packages/core/src/code_assist/experiments/experiments.ts index 90eae36679..ecb98491eb 100644 --- a/packages/core/src/code_assist/experiments/experiments.ts +++ b/packages/core/src/code_assist/experiments/experiments.ts @@ -7,6 +7,8 @@ import type { CodeAssistServer } from '../server.js'; import { getClientMetadata } from './client_metadata.js'; import type { ListExperimentsResponse, Flag } from './types.js'; +import * as fs from 'node:fs'; +import { debugLogger } from '../../utils/debugLogger.js'; export interface Experiments { flags: Record; @@ -21,13 +23,37 @@ let experimentsPromise: Promise | undefined; * The experiments are cached so that they are only fetched once. */ export async function getExperiments( - server: CodeAssistServer, + server?: CodeAssistServer, ): Promise { if (experimentsPromise) { return experimentsPromise; } experimentsPromise = (async () => { + if (process.env['GEMINI_EXP']) { + try { + const expPath = process.env['GEMINI_EXP']; + debugLogger.debug('Reading experiments from', expPath); + const content = await fs.promises.readFile(expPath, 'utf8'); + const response = JSON.parse(content); + if ( + (response.flags && !Array.isArray(response.flags)) || + (response.experimentIds && !Array.isArray(response.experimentIds)) + ) { + throw new Error( + 'Invalid format for experiments file: `flags` and `experimentIds` must be arrays if present.', + ); + } + return parseExperiments(response as ListExperimentsResponse); + } catch (e) { + debugLogger.debug('Failed to read experiments from GEMINI_EXP', e); + } + } + + if (!server) { + return { flags: {}, experimentIds: [] }; + } + const metadata = await getClientMetadata(); const response = await server.listExperiments(metadata); return parseExperiments(response); diff --git a/packages/core/src/code_assist/experiments/experiments_local.test.ts b/packages/core/src/code_assist/experiments/experiments_local.test.ts new file mode 100644 index 0000000000..f7bed37319 --- /dev/null +++ b/packages/core/src/code_assist/experiments/experiments_local.test.ts @@ -0,0 +1,146 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import type { CodeAssistServer } from '../server.js'; +import * as fs from 'node:fs'; +import * as os from 'node:os'; +import type { ListExperimentsResponse } from './types.js'; +import type { ClientMetadata } from '../types.js'; + +// Mock dependencies +vi.mock('node:fs', () => ({ + promises: { + readFile: vi.fn(), + }, + readFileSync: vi.fn(), +})); +vi.mock('node:os'); +vi.mock('../server.js'); +vi.mock('./client_metadata.js', () => ({ + getClientMetadata: vi.fn(), +})); + +describe('experiments with GEMINI_EXP', () => { + let mockServer: CodeAssistServer; + + beforeEach(() => { + vi.resetModules(); + vi.clearAllMocks(); + process.env['GEMINI_EXP'] = ''; // Clear env var + + // Default mocks + vi.mocked(os.homedir).mockReturnValue('/home/user'); + mockServer = { + listExperiments: vi.fn(), + } as unknown as CodeAssistServer; + }); + + afterEach(() => { + delete process.env['GEMINI_EXP']; + }); + + it('should read experiments from local file if GEMINI_EXP is set', async () => { + process.env['GEMINI_EXP'] = '/tmp/experiments.json'; + const mockFileContent = JSON.stringify({ + flags: [{ flagId: 111, boolValue: true }], + experimentIds: [999], + }); + vi.mocked(fs.promises.readFile).mockResolvedValue(mockFileContent); + + const { getExperiments } = await import('./experiments.js'); + const experiments = await getExperiments(mockServer); + + expect(fs.promises.readFile).toHaveBeenCalledWith( + '/tmp/experiments.json', + 'utf8', + ); + expect(experiments.flags[111]).toEqual({ + flagId: 111, + boolValue: true, + }); + expect(experiments.experimentIds).toEqual([999]); + expect(mockServer.listExperiments).not.toHaveBeenCalled(); + }); + + it('should fall back to server if reading file fails', async () => { + process.env['GEMINI_EXP'] = '/tmp/missing.json'; + vi.mocked(fs.promises.readFile).mockRejectedValue( + new Error('File not found'), + ); + + // Mock server response + const mockApiResponse = { + flags: [{ flagId: 222, boolValue: true }], + experimentIds: [111], + }; + vi.mocked(mockServer.listExperiments).mockResolvedValue( + mockApiResponse as ListExperimentsResponse, + ); + const { getClientMetadata } = await import('./client_metadata.js'); + vi.mocked(getClientMetadata).mockResolvedValue( + {} as unknown as ClientMetadata, + ); + + const { getExperiments } = await import('./experiments.js'); + const experiments = await getExperiments(mockServer); + + expect(experiments.flags[222]).toBeDefined(); + expect(mockServer.listExperiments).toHaveBeenCalled(); + }); + + it('should work without server if file read succeeds', async () => { + process.env['GEMINI_EXP'] = '/tmp/experiments.json'; + const mockFileContent = JSON.stringify({ + flags: [{ flagId: 333, boolValue: true }], + experimentIds: [999], + }); + vi.mocked(fs.promises.readFile).mockResolvedValue(mockFileContent); + + const { getExperiments } = await import('./experiments.js'); + const experiments = await getExperiments(undefined); + + expect(experiments.flags[333]).toEqual({ + flagId: 333, + boolValue: true, + }); + }); + + it('should return empty if no server and no GEMINI_EXP', async () => { + const { getExperiments } = await import('./experiments.js'); + const experiments = await getExperiments(undefined); + expect(experiments.flags).toEqual({}); + expect(experiments.experimentIds).toEqual([]); + }); + + it('should fallback to server if file has invalid structure', async () => { + process.env['GEMINI_EXP'] = '/tmp/invalid.json'; + const mockFileContent = JSON.stringify({ + flags: 'invalid-flags-type', // Should be array + experimentIds: 123, // Should be array + }); + vi.mocked(fs.promises.readFile).mockResolvedValue(mockFileContent); + + // Mock server response + const mockApiResponse = { + flags: [{ flagId: 444, boolValue: true }], + experimentIds: [555], + }; + vi.mocked(mockServer.listExperiments).mockResolvedValue( + mockApiResponse as ListExperimentsResponse, + ); + const { getClientMetadata } = await import('./client_metadata.js'); + vi.mocked(getClientMetadata).mockResolvedValue( + {} as unknown as ClientMetadata, + ); + + const { getExperiments } = await import('./experiments.js'); + const experiments = await getExperiments(mockServer); + + expect(experiments.flags[444]).toBeDefined(); + expect(mockServer.listExperiments).toHaveBeenCalled(); + }); +}); diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index 265785a891..8e1c9d9b68 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -226,6 +226,10 @@ describe('Server Config (config.ts)', () => { beforeEach(() => { // Reset mocks if necessary vi.clearAllMocks(); + vi.mocked(getExperiments).mockResolvedValue({ + experimentIds: [], + flags: {}, + }); }); describe('initialize', () => { diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 2a9ae19284..f877a2e797 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -814,32 +814,27 @@ export class Config { this.baseLlmClient = new BaseLlmClient(this.contentGenerator, this); const codeAssistServer = getCodeAssistServer(this); - if (codeAssistServer) { - if (codeAssistServer.projectId) { - await this.refreshUserQuota(); - } - - this.experimentsPromise = getExperiments(codeAssistServer) - .then((experiments) => { - this.setExperiments(experiments); - - // If preview features have not been set and the user authenticated through Google, we enable preview based on remote config only if it's true - if (this.getPreviewFeatures() === undefined) { - const remotePreviewFeatures = - experiments.flags[ExperimentFlags.ENABLE_PREVIEW]?.boolValue; - if (remotePreviewFeatures === true) { - this.setPreviewFeatures(remotePreviewFeatures); - } - } - }) - .catch((e) => { - debugLogger.error('Failed to fetch experiments', e); - }); - } else { - this.experiments = undefined; - this.experimentsPromise = undefined; + if (codeAssistServer?.projectId) { + await this.refreshUserQuota(); } + this.experimentsPromise = getExperiments(codeAssistServer) + .then((experiments) => { + this.setExperiments(experiments); + + // If preview features have not been set and the user authenticated through Google, we enable preview based on remote config only if it's true + if (this.getPreviewFeatures() === undefined) { + const remotePreviewFeatures = + experiments.flags[ExperimentFlags.ENABLE_PREVIEW]?.boolValue; + if (remotePreviewFeatures === true) { + this.setPreviewFeatures(remotePreviewFeatures); + } + } + }) + .catch((e) => { + debugLogger.error('Failed to fetch experiments', e); + }); + const authType = this.contentGeneratorConfig.authType; if ( authType === AuthType.USE_GEMINI || @@ -859,10 +854,7 @@ export class Config { return this.experiments; } const codeAssistServer = getCodeAssistServer(this); - if (codeAssistServer) { - return getExperiments(codeAssistServer); - } - return undefined; + return getExperiments(codeAssistServer); } getUserTier(): UserTierId | undefined { From 14f0cb45389deff7b0293dfe58e04fea11ee151c Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 9 Jan 2026 11:56:22 -0800 Subject: [PATCH 097/713] feat(ui): reduce home directory warning noise and add opt-out setting (#16229) --- docs/get-started/configuration.md | 6 +++ packages/cli/src/config/settingsSchema.ts | 10 ++++ packages/cli/src/gemini.tsx | 2 +- .../cli/src/utils/userStartupWarnings.test.ts | 54 ++++++++++++++++--- packages/cli/src/utils/userStartupWarnings.ts | 28 ++++++++-- schemas/settings.schema.json | 7 +++ 6 files changed, 95 insertions(+), 12 deletions(-) diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 1777d22f5f..8d7b95e24d 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -184,6 +184,12 @@ their corresponding top-level category object in your `settings.json` file. title - **Default:** `false` +- **`ui.showHomeDirectoryWarning`** (boolean): + - **Description:** Show a warning when running Gemini CLI in the home + directory. + - **Default:** `true` + - **Requires restart:** Yes + - **`ui.hideTips`** (boolean): - **Description:** Hide helpful tips in the UI - **Default:** `false` diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index 4dea5d0a99..b69d8f7fe6 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -384,6 +384,16 @@ const SETTINGS_SCHEMA = { 'Show Gemini CLI status and thoughts in the terminal window title', showInDialog: true, }, + showHomeDirectoryWarning: { + type: 'boolean', + label: 'Show Home Directory Warning', + category: 'UI', + requiresRestart: true, + default: true, + description: + 'Show a warning when running Gemini CLI in the home directory.', + showInDialog: true, + }, hideTips: { type: 'boolean', label: 'Hide Tips', diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index b3ce41f7fe..d75f509dd2 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -588,7 +588,7 @@ export async function main() { let input = config.getQuestion(); const startupWarnings = [ ...(await getStartupWarnings()), - ...(await getUserStartupWarnings()), + ...(await getUserStartupWarnings(settings.merged)), ]; // Handle --resume flag diff --git a/packages/cli/src/utils/userStartupWarnings.test.ts b/packages/cli/src/utils/userStartupWarnings.test.ts index 0a9f957617..c3746ad0a1 100644 --- a/packages/cli/src/utils/userStartupWarnings.test.ts +++ b/packages/cli/src/utils/userStartupWarnings.test.ts @@ -9,6 +9,10 @@ import { getUserStartupWarnings } from './userStartupWarnings.js'; import * as os from 'node:os'; import fs from 'node:fs/promises'; import path from 'node:path'; +import { + isFolderTrustEnabled, + isWorkspaceTrusted, +} from '../config/trustedFolders.js'; // Mock os.homedir to control the home directory in tests vi.mock('os', async (importOriginal) => { @@ -28,6 +32,11 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { }; }); +vi.mock('../config/trustedFolders.js', () => ({ + isFolderTrustEnabled: vi.fn(), + isWorkspaceTrusted: vi.fn(), +})); + describe('getUserStartupWarnings', () => { let testRootDir: string; let homeDir: string; @@ -37,6 +46,11 @@ describe('getUserStartupWarnings', () => { homeDir = path.join(testRootDir, 'home'); await fs.mkdir(homeDir, { recursive: true }); vi.mocked(os.homedir).mockReturnValue(homeDir); + vi.mocked(isFolderTrustEnabled).mockReturnValue(false); + vi.mocked(isWorkspaceTrusted).mockReturnValue({ + isTrusted: false, + source: undefined, + }); }); afterEach(async () => { @@ -46,16 +60,44 @@ describe('getUserStartupWarnings', () => { describe('home directory check', () => { it('should return a warning when running in home directory', async () => { - const warnings = await getUserStartupWarnings(homeDir); + const warnings = await getUserStartupWarnings({}, homeDir); expect(warnings).toContainEqual( - expect.stringContaining('home directory'), + expect.stringContaining( + 'Warning you are running Gemini CLI in your home directory', + ), + ); + expect(warnings).toContainEqual( + expect.stringContaining('warning can be disabled in /settings'), ); }); it('should not return a warning when running in a project directory', async () => { const projectDir = path.join(testRootDir, 'project'); await fs.mkdir(projectDir); - const warnings = await getUserStartupWarnings(projectDir); + const warnings = await getUserStartupWarnings({}, projectDir); + expect(warnings).not.toContainEqual( + expect.stringContaining('home directory'), + ); + }); + + it('should not return a warning when showHomeDirectoryWarning is false', async () => { + const warnings = await getUserStartupWarnings( + { ui: { showHomeDirectoryWarning: false } }, + homeDir, + ); + expect(warnings).not.toContainEqual( + expect.stringContaining('home directory'), + ); + }); + + it('should not return a warning when folder trust is enabled and workspace is trusted', async () => { + vi.mocked(isFolderTrustEnabled).mockReturnValue(true); + vi.mocked(isWorkspaceTrusted).mockReturnValue({ + isTrusted: true, + source: 'file', + }); + + const warnings = await getUserStartupWarnings({}, homeDir); expect(warnings).not.toContainEqual( expect.stringContaining('home directory'), ); @@ -65,7 +107,7 @@ describe('getUserStartupWarnings', () => { describe('root directory check', () => { it('should return a warning when running in a root directory', async () => { const rootDir = path.parse(testRootDir).root; - const warnings = await getUserStartupWarnings(rootDir); + const warnings = await getUserStartupWarnings({}, rootDir); expect(warnings).toContainEqual( expect.stringContaining('root directory'), ); @@ -77,7 +119,7 @@ describe('getUserStartupWarnings', () => { it('should not return a warning when running in a non-root directory', async () => { const projectDir = path.join(testRootDir, 'project'); await fs.mkdir(projectDir); - const warnings = await getUserStartupWarnings(projectDir); + const warnings = await getUserStartupWarnings({}, projectDir); expect(warnings).not.toContainEqual( expect.stringContaining('root directory'), ); @@ -87,7 +129,7 @@ describe('getUserStartupWarnings', () => { describe('error handling', () => { it('should handle errors when checking directory', async () => { const nonExistentPath = path.join(testRootDir, 'non-existent'); - const warnings = await getUserStartupWarnings(nonExistentPath); + const warnings = await getUserStartupWarnings({}, nonExistentPath); const expectedWarning = 'Could not verify the current directory due to a file system error.'; expect(warnings).toEqual([expectedWarning, expectedWarning]); diff --git a/packages/cli/src/utils/userStartupWarnings.ts b/packages/cli/src/utils/userStartupWarnings.ts index 37a5dd49cd..8a0c0b0d3a 100644 --- a/packages/cli/src/utils/userStartupWarnings.ts +++ b/packages/cli/src/utils/userStartupWarnings.ts @@ -8,16 +8,25 @@ import fs from 'node:fs/promises'; import path from 'node:path'; import process from 'node:process'; import { homedir } from '@google/gemini-cli-core'; +import type { Settings } from '../config/settingsSchema.js'; +import { + isFolderTrustEnabled, + isWorkspaceTrusted, +} from '../config/trustedFolders.js'; type WarningCheck = { id: string; - check: (workspaceRoot: string) => Promise; + check: (workspaceRoot: string, settings: Settings) => Promise; }; // Individual warning checks const homeDirectoryCheck: WarningCheck = { id: 'home-directory', - check: async (workspaceRoot: string) => { + check: async (workspaceRoot: string, settings: Settings) => { + if (settings.ui?.showHomeDirectoryWarning === false) { + return null; + } + try { const [workspaceRealPath, homeRealPath] = await Promise.all([ fs.realpath(workspaceRoot), @@ -25,7 +34,15 @@ const homeDirectoryCheck: WarningCheck = { ]); if (workspaceRealPath === homeRealPath) { - return 'You are running Gemini CLI in your home directory. It is recommended to run in a project-specific directory.'; + // If folder trust is enabled and the user trusts the home directory, don't show the warning. + if ( + isFolderTrustEnabled(settings) && + isWorkspaceTrusted(settings).isTrusted + ) { + return null; + } + + return 'Warning you are running Gemini CLI in your home directory.\nThis warning can be disabled in /settings'; } return null; } catch (_err: unknown) { @@ -36,7 +53,7 @@ const homeDirectoryCheck: WarningCheck = { const rootDirectoryCheck: WarningCheck = { id: 'root-directory', - check: async (workspaceRoot: string) => { + check: async (workspaceRoot: string, _settings: Settings) => { try { const workspaceRealPath = await fs.realpath(workspaceRoot); const errorMessage = @@ -61,10 +78,11 @@ const WARNING_CHECKS: readonly WarningCheck[] = [ ]; export async function getUserStartupWarnings( + settings: Settings, workspaceRoot: string = process.cwd(), ): Promise { const results = await Promise.all( - WARNING_CHECKS.map((check) => check.check(workspaceRoot)), + WARNING_CHECKS.map((check) => check.check(workspaceRoot, settings)), ); return results.filter((msg) => msg !== null); } diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index 83429aecca..2cfbcb5056 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -194,6 +194,13 @@ "default": false, "type": "boolean" }, + "showHomeDirectoryWarning": { + "title": "Show Home Directory Warning", + "description": "Show a warning when running Gemini CLI in the home directory.", + "markdownDescription": "Show a warning when running Gemini CLI in the home directory.\n\n- Category: `UI`\n- Requires restart: `yes`\n- Default: `true`", + "default": true, + "type": "boolean" + }, "hideTips": { "title": "Hide Tips", "description": "Hide helpful tips in the UI", From 9d187e041c8f8c8e6e464fe0711504c6c37d7ead Mon Sep 17 00:00:00 2001 From: Vedant Mahajan Date: Sat, 10 Jan 2026 01:48:06 +0530 Subject: [PATCH 098/713] refactor: migrate chatCompressionService to use HookSystem (#16259) Co-authored-by: Tommaso Sciortino --- .../src/services/chatCompressionService.test.ts | 1 + .../core/src/services/chatCompressionService.ts | 13 +++---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/core/src/services/chatCompressionService.test.ts b/packages/core/src/services/chatCompressionService.test.ts index 7909f8bdef..38c7dba65d 100644 --- a/packages/core/src/services/chatCompressionService.test.ts +++ b/packages/core/src/services/chatCompressionService.test.ts @@ -159,6 +159,7 @@ describe('ChatCompressionService', () => { }), getEnableHooks: vi.fn().mockReturnValue(false), getMessageBus: vi.fn().mockReturnValue(undefined), + getHookSystem: () => undefined, } as unknown as Config; vi.mocked(tokenLimit).mockReturnValue(1000); diff --git a/packages/core/src/services/chatCompressionService.ts b/packages/core/src/services/chatCompressionService.ts index 2336b75f55..c76e937750 100644 --- a/packages/core/src/services/chatCompressionService.ts +++ b/packages/core/src/services/chatCompressionService.ts @@ -22,7 +22,6 @@ import { PREVIEW_GEMINI_MODEL, PREVIEW_GEMINI_FLASH_MODEL, } from '../config/models.js'; -import { firePreCompressHook } from '../core/sessionHookTriggers.js'; import { PreCompressTrigger } from '../hooks/types.js'; /** @@ -128,16 +127,10 @@ export class ChatCompressionService { }; } - // Fire PreCompress hook before compression (only if hooks are enabled) + // Fire PreCompress hook before compression // This fires for both manual and auto compression attempts - const hooksEnabled = config.getEnableHooks(); - const messageBus = config.getMessageBus(); - if (hooksEnabled && messageBus) { - const trigger = force - ? PreCompressTrigger.Manual - : PreCompressTrigger.Auto; - await firePreCompressHook(messageBus, trigger); - } + const trigger = force ? PreCompressTrigger.Manual : PreCompressTrigger.Auto; + await config.getHookSystem()?.firePreCompressEvent(trigger); const originalTokenCount = chat.getLastPromptTokenCount(); From c7d17dda49daf0dcecf800c140f0360719772849 Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Fri, 9 Jan 2026 15:47:14 -0500 Subject: [PATCH 099/713] fix: properly use systemMessage for hooks in UI (#16250) --- docs/hooks/reference.md | 18 ++--- packages/cli/src/nonInteractiveCli.ts | 4 +- .../cli/src/ui/hooks/useGeminiStream.test.tsx | 65 ++++++++++++++++++- packages/cli/src/ui/hooks/useGeminiStream.ts | 10 +-- packages/core/src/core/client.ts | 8 ++- packages/core/src/core/turn.ts | 2 + 6 files changed, 88 insertions(+), 19 deletions(-) diff --git a/docs/hooks/reference.md b/docs/hooks/reference.md index b5174f827e..f65abeaf84 100644 --- a/docs/hooks/reference.md +++ b/docs/hooks/reference.md @@ -94,15 +94,15 @@ If the hook exits with `0`, the CLI attempts to parse `stdout` as JSON. ### Common Output Fields -| Field | Type | Description | -| :------------------- | :-------- | :----------------------------------------------------------------------- | -| `decision` | `string` | One of: `allow`, `deny`, `block`, `ask`, `approve`. | -| `reason` | `string` | Explanation shown to the **agent** when a decision is `deny` or `block`. | -| `systemMessage` | `string` | Message displayed to the **user** in the CLI terminal. | -| `continue` | `boolean` | If `false`, immediately terminates the agent loop for this turn. | -| `stopReason` | `string` | Message shown to the user when `continue` is `false`. | -| `suppressOutput` | `boolean` | If `true`, the hook execution is hidden from the CLI transcript. | -| `hookSpecificOutput` | `object` | Container for event-specific data (see below). | +| Field | Type | Description | +| :------------------- | :-------- | :------------------------------------------------------------------------------------- | +| `decision` | `string` | One of: `allow`, `deny`, `block`, `ask`, `approve`. | +| `reason` | `string` | Explanation shown to the **agent** when a decision is `deny` or `block`. | +| `systemMessage` | `string` | Message displayed in Gemini CLI terminal to provide warning or context to the **user** | +| `continue` | `boolean` | If `false`, immediately terminates the agent loop for this turn. | +| `stopReason` | `string` | Message shown to the user when `continue` is `false`. | +| `suppressOutput` | `boolean` | If `true`, the hook execution is hidden from the CLI transcript. | +| `hookSpecificOutput` | `object` | Container for event-specific data (see below). | ### `hookSpecificOutput` Reference diff --git a/packages/cli/src/nonInteractiveCli.ts b/packages/cli/src/nonInteractiveCli.ts index d1f468ef39..7830798dd5 100644 --- a/packages/cli/src/nonInteractiveCli.ts +++ b/packages/cli/src/nonInteractiveCli.ts @@ -349,7 +349,7 @@ export async function runNonInteractive({ } else if (event.type === GeminiEventType.Error) { throw event.value.error; } else if (event.type === GeminiEventType.AgentExecutionStopped) { - const stopMessage = `Agent execution stopped: ${event.value.reason}`; + const stopMessage = `Agent execution stopped: ${event.value.systemMessage?.trim() || event.value.reason}`; if (config.getOutputFormat() === OutputFormat.TEXT) { process.stderr.write(`${stopMessage}\n`); } @@ -369,7 +369,7 @@ export async function runNonInteractive({ } return; } else if (event.type === GeminiEventType.AgentExecutionBlocked) { - const blockMessage = `Agent execution blocked: ${event.value.reason}`; + const blockMessage = `Agent execution blocked: ${event.value.systemMessage?.trim() || event.value.reason}`; if (config.getOutputFormat() === OutputFormat.TEXT) { process.stderr.write(`[WARNING] ${blockMessage}\n`); } diff --git a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx index 2414c340f4..bbf6412bc6 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx +++ b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx @@ -2800,7 +2800,38 @@ describe('useGeminiStream', () => { }); describe('Agent Execution Events', () => { - it('should handle AgentExecutionStopped event', async () => { + it('should handle AgentExecutionStopped event with systemMessage', async () => { + mockSendMessageStream.mockReturnValue( + (async function* () { + yield { + type: ServerGeminiEventType.AgentExecutionStopped, + value: { + reason: 'hook-reason', + systemMessage: 'Custom stop message', + }, + }; + })(), + ); + + const { result } = renderTestHook(); + + await act(async () => { + await result.current.submitQuery('test stop'); + }); + + await waitFor(() => { + expect(mockAddItem).toHaveBeenCalledWith( + { + type: MessageType.INFO, + text: 'Agent execution stopped: Custom stop message', + }, + expect.any(Number), + ); + expect(result.current.streamingState).toBe(StreamingState.Idle); + }); + }); + + it('should handle AgentExecutionStopped event by falling back to reason when systemMessage is missing', async () => { mockSendMessageStream.mockReturnValue( (async function* () { yield { @@ -2828,7 +2859,37 @@ describe('useGeminiStream', () => { }); }); - it('should handle AgentExecutionBlocked event', async () => { + it('should handle AgentExecutionBlocked event with systemMessage', async () => { + mockSendMessageStream.mockReturnValue( + (async function* () { + yield { + type: ServerGeminiEventType.AgentExecutionBlocked, + value: { + reason: 'hook-reason', + systemMessage: 'Custom block message', + }, + }; + })(), + ); + + const { result } = renderTestHook(); + + await act(async () => { + await result.current.submitQuery('test block'); + }); + + await waitFor(() => { + expect(mockAddItem).toHaveBeenCalledWith( + { + type: MessageType.WARNING, + text: 'Agent execution blocked: Custom block message', + }, + expect.any(Number), + ); + }); + }); + + it('should handle AgentExecutionBlocked event by falling back to reason when systemMessage is missing', async () => { mockSendMessageStream.mockReturnValue( (async function* () { yield { diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index 4522af13c7..113c6a08bf 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -794,7 +794,7 @@ export const useGeminiStream = ( ); const handleAgentExecutionStoppedEvent = useCallback( - (reason: string, userMessageTimestamp: number) => { + (reason: string, userMessageTimestamp: number, systemMessage?: string) => { if (pendingHistoryItemRef.current) { addItem(pendingHistoryItemRef.current, userMessageTimestamp); setPendingHistoryItem(null); @@ -802,7 +802,7 @@ export const useGeminiStream = ( addItem( { type: MessageType.INFO, - text: `Agent execution stopped: ${reason}`, + text: `Agent execution stopped: ${systemMessage?.trim() || reason}`, }, userMessageTimestamp, ); @@ -812,7 +812,7 @@ export const useGeminiStream = ( ); const handleAgentExecutionBlockedEvent = useCallback( - (reason: string, userMessageTimestamp: number) => { + (reason: string, userMessageTimestamp: number, systemMessage?: string) => { if (pendingHistoryItemRef.current) { addItem(pendingHistoryItemRef.current, userMessageTimestamp); setPendingHistoryItem(null); @@ -820,7 +820,7 @@ export const useGeminiStream = ( addItem( { type: MessageType.WARNING, - text: `Agent execution blocked: ${reason}`, + text: `Agent execution blocked: ${systemMessage?.trim() || reason}`, }, userMessageTimestamp, ); @@ -861,12 +861,14 @@ export const useGeminiStream = ( handleAgentExecutionStoppedEvent( event.value.reason, userMessageTimestamp, + event.value.systemMessage, ); break; case ServerGeminiEventType.AgentExecutionBlocked: handleAgentExecutionBlockedEvent( event.value.reason, userMessageTimestamp, + event.value.systemMessage, ); break; case ServerGeminiEventType.ChatCompressed: diff --git a/packages/core/src/core/client.ts b/packages/core/src/core/client.ts index 3a8603ae65..67dae3f927 100644 --- a/packages/core/src/core/client.ts +++ b/packages/core/src/core/client.ts @@ -68,11 +68,11 @@ const MAX_TURNS = 100; type BeforeAgentHookReturn = | { type: GeminiEventType.AgentExecutionStopped; - value: { reason: string }; + value: { reason: string; systemMessage?: string }; } | { type: GeminiEventType.AgentExecutionBlocked; - value: { reason: string }; + value: { reason: string; systemMessage?: string }; } | { additionalContext: string | undefined } | undefined; @@ -146,6 +146,7 @@ export class GeminiClient { type: GeminiEventType.AgentExecutionStopped, value: { reason: hookOutput.getEffectiveReason(), + systemMessage: hookOutput.systemMessage, }, }; } @@ -155,6 +156,7 @@ export class GeminiClient { type: GeminiEventType.AgentExecutionBlocked, value: { reason: hookOutput.getEffectiveReason(), + systemMessage: hookOutput.systemMessage, }, }; } @@ -811,6 +813,7 @@ export class GeminiClient { type: GeminiEventType.AgentExecutionStopped, value: { reason: hookOutput.getEffectiveReason(), + systemMessage: hookOutput.systemMessage, }, }; return turn; @@ -822,6 +825,7 @@ export class GeminiClient { type: GeminiEventType.AgentExecutionBlocked, value: { reason: continueReason, + systemMessage: hookOutput.systemMessage, }, }; const continueRequest = [{ text: continueReason }]; diff --git a/packages/core/src/core/turn.ts b/packages/core/src/core/turn.ts index fcb8e18e04..90d6a3cbfc 100644 --- a/packages/core/src/core/turn.ts +++ b/packages/core/src/core/turn.ts @@ -78,6 +78,7 @@ export type ServerGeminiAgentExecutionStoppedEvent = { type: GeminiEventType.AgentExecutionStopped; value: { reason: string; + systemMessage?: string; }; }; @@ -85,6 +86,7 @@ export type ServerGeminiAgentExecutionBlockedEvent = { type: GeminiEventType.AgentExecutionBlocked; value: { reason: string; + systemMessage?: string; }; }; From ea7393f7fd5a072a2884db814b650d986e1cc933 Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Fri, 9 Jan 2026 13:10:15 -0800 Subject: [PATCH 100/713] Infer modifyOtherKeys support (#16270) --- .../src/ui/components/InputPrompt.test.tsx | 5 --- .../src/ui/components/SettingsDialog.test.tsx | 5 --- .../utils/terminalCapabilityManager.test.ts | 38 ++++++++++++++++--- .../src/ui/utils/terminalCapabilityManager.ts | 26 ++++++------- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/packages/cli/src/ui/components/InputPrompt.test.tsx b/packages/cli/src/ui/components/InputPrompt.test.tsx index 7717b1e2f9..0d000fc79f 100644 --- a/packages/cli/src/ui/components/InputPrompt.test.tsx +++ b/packages/cli/src/ui/components/InputPrompt.test.tsx @@ -34,7 +34,6 @@ import { useReverseSearchCompletion } from '../hooks/useReverseSearchCompletion. import clipboardy from 'clipboardy'; import * as clipboardUtils from '../utils/clipboardUtils.js'; import { useKittyKeyboardProtocol } from '../hooks/useKittyKeyboardProtocol.js'; -import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js'; import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; import stripAnsi from 'strip-ansi'; import chalk from 'chalk'; @@ -125,10 +124,6 @@ describe('InputPrompt', () => { beforeEach(() => { vi.resetAllMocks(); - vi.spyOn( - terminalCapabilityManager, - 'isBracketedPasteEnabled', - ).mockReturnValue(true); mockCommandContext = createMockCommandContext(); diff --git a/packages/cli/src/ui/components/SettingsDialog.test.tsx b/packages/cli/src/ui/components/SettingsDialog.test.tsx index 2c0c10e502..d33130744a 100644 --- a/packages/cli/src/ui/components/SettingsDialog.test.tsx +++ b/packages/cli/src/ui/components/SettingsDialog.test.tsx @@ -35,7 +35,6 @@ import { type SettingDefinition, type SettingsSchemaType, } from '../../config/settingsSchema.js'; -import { terminalCapabilityManager } from '../../ui/utils/terminalCapabilityManager.js'; // Mock the VimModeContext const mockToggleVimEnabled = vi.fn(); @@ -254,10 +253,6 @@ const renderDialog = ( describe('SettingsDialog', () => { beforeEach(() => { - vi.spyOn( - terminalCapabilityManager, - 'isBracketedPasteEnabled', - ).mockReturnValue(true); mockToggleVimEnabled.mockResolvedValue(true); }); diff --git a/packages/cli/src/ui/utils/terminalCapabilityManager.test.ts b/packages/cli/src/ui/utils/terminalCapabilityManager.test.ts index e10ca2593c..67f16e5db2 100644 --- a/packages/cli/src/ui/utils/terminalCapabilityManager.test.ts +++ b/packages/cli/src/ui/utils/terminalCapabilityManager.test.ts @@ -7,6 +7,10 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { TerminalCapabilityManager } from './terminalCapabilityManager.js'; import { EventEmitter } from 'node:events'; +import { + enableKittyKeyboardProtocol, + enableModifyOtherKeys, +} from '@google/gemini-cli-core'; // Mock fs vi.mock('node:fs', () => ({ @@ -190,7 +194,8 @@ describe('TerminalCapabilityManager', () => { stdin.emit('data', Buffer.from('\x1b[?62c')); await promise; - expect(manager.isModifyOtherKeysEnabled()).toBe(true); + + expect(enableModifyOtherKeys).toHaveBeenCalled(); }); it('should not enable modifyOtherKeys for level 0', async () => { @@ -203,7 +208,8 @@ describe('TerminalCapabilityManager', () => { stdin.emit('data', Buffer.from('\x1b[?62c')); await promise; - expect(manager.isModifyOtherKeysEnabled()).toBe(false); + + expect(enableModifyOtherKeys).not.toHaveBeenCalled(); }); it('should prefer Kitty over modifyOtherKeys', async () => { @@ -218,7 +224,9 @@ describe('TerminalCapabilityManager', () => { await promise; expect(manager.isKittyProtocolEnabled()).toBe(true); - expect(manager.isModifyOtherKeysEnabled()).toBe(false); + + expect(enableKittyKeyboardProtocol).toHaveBeenCalled(); + expect(enableModifyOtherKeys).not.toHaveBeenCalled(); }); it('should enable modifyOtherKeys when Kitty not supported', async () => { @@ -231,8 +239,9 @@ describe('TerminalCapabilityManager', () => { stdin.emit('data', Buffer.from('\x1b[?62c')); await promise; - expect(manager.isModifyOtherKeysEnabled()).toBe(true); + expect(manager.isKittyProtocolEnabled()).toBe(false); + expect(enableModifyOtherKeys).toHaveBeenCalled(); }); it('should handle split modifyOtherKeys response chunks', async () => { @@ -246,7 +255,8 @@ describe('TerminalCapabilityManager', () => { stdin.emit('data', Buffer.from('\x1b[?62c')); await promise; - expect(manager.isModifyOtherKeysEnabled()).toBe(true); + + expect(enableModifyOtherKeys).toHaveBeenCalled(); }); it('should detect modifyOtherKeys with other capabilities', async () => { @@ -263,7 +273,23 @@ describe('TerminalCapabilityManager', () => { expect(manager.getTerminalBackgroundColor()).toBe('#1a1a1a'); expect(manager.getTerminalName()).toBe('tmux'); - expect(manager.isModifyOtherKeysEnabled()).toBe(true); + + expect(enableModifyOtherKeys).toHaveBeenCalled(); + }); + + it('should infer modifyOtherKeys support from Device Attributes (DA1) alone', async () => { + const manager = TerminalCapabilityManager.getInstance(); + const promise = manager.detectCapabilities(); + + // Simulate only DA1 response (no specific MOK or Kitty response) + stdin.emit('data', Buffer.from('\x1b[?62c')); + + await promise; + + expect(manager.isKittyProtocolEnabled()).toBe(false); + // It should fall back to modifyOtherKeys because DA1 proves it's an ANSI terminal + + expect(enableModifyOtherKeys).toHaveBeenCalled(); }); }); }); diff --git a/packages/cli/src/ui/utils/terminalCapabilityManager.ts b/packages/cli/src/ui/utils/terminalCapabilityManager.ts index 7b09a33e4e..50a69ee707 100644 --- a/packages/cli/src/ui/utils/terminalCapabilityManager.ts +++ b/packages/cli/src/ui/utils/terminalCapabilityManager.ts @@ -43,14 +43,13 @@ export class TerminalCapabilityManager { // eslint-disable-next-line no-control-regex private static readonly MODIFY_OTHER_KEYS_REGEX = /\x1b\[>4;(\d+)m/; + private detectionComplete = false; private terminalBackgroundColor: TerminalBackgroundColor; private kittySupported = false; private kittyEnabled = false; - private detectionComplete = false; private terminalName: string | undefined; - private modifyOtherKeysSupported = false; - private modifyOtherKeysEnabled = false; - private bracketedPasteEnabled = false; + private modifyOtherKeysSupported?: boolean; + private deviceAttributesSupported = false; private constructor() {} @@ -187,6 +186,7 @@ export class TerminalCapabilityManager { ); if (match) { deviceAttributesReceived = true; + this.deviceAttributesSupported = true; cleanup(); } } @@ -215,13 +215,17 @@ export class TerminalCapabilityManager { if (this.kittySupported) { enableKittyKeyboardProtocol(); this.kittyEnabled = true; - } else if (this.modifyOtherKeysSupported) { + } else if ( + this.modifyOtherKeysSupported === true || + // If device attributes were received it's safe to try enabling + // anyways, since it will be ignored if unsupported + (this.modifyOtherKeysSupported === undefined && + this.deviceAttributesSupported) + ) { enableModifyOtherKeys(); - this.modifyOtherKeysEnabled = true; } // Always enable bracketed paste since it'll be ignored if unsupported. enableBracketedPasteMode(); - this.bracketedPasteEnabled = true; } catch (e) { debugLogger.warn('Failed to enable keyboard protocols:', e); } @@ -239,14 +243,6 @@ export class TerminalCapabilityManager { return this.kittyEnabled; } - isBracketedPasteEnabled(): boolean { - return this.bracketedPasteEnabled; - } - - isModifyOtherKeysEnabled(): boolean { - return this.modifyOtherKeysEnabled; - } - private parseColor(rHex: string, gHex: string, bHex: string): string { const parseComponent = (hex: string) => { const val = parseInt(hex, 16); From e04a5f0cb0ee6f659278260ca559a89b54ed9ed1 Mon Sep 17 00:00:00 2001 From: Eric Rahm Date: Fri, 9 Jan 2026 13:22:53 -0800 Subject: [PATCH 101/713] feat(core): Cache ignore instances for performance (#16185) --- packages/core/src/utils/gitIgnoreParser.ts | 28 ++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/core/src/utils/gitIgnoreParser.ts b/packages/core/src/utils/gitIgnoreParser.ts index f2dc3d1a28..cca0ca3bac 100644 --- a/packages/core/src/utils/gitIgnoreParser.ts +++ b/packages/core/src/utils/gitIgnoreParser.ts @@ -6,7 +6,7 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; -import ignore from 'ignore'; +import ignore, { type Ignore } from 'ignore'; export interface GitIgnoreFilter { isIgnored(filePath: string): boolean; @@ -14,30 +14,30 @@ export interface GitIgnoreFilter { export class GitIgnoreParser implements GitIgnoreFilter { private projectRoot: string; - private cache: Map = new Map(); - private globalPatterns: string[] | undefined; - private processedExtraPatterns: string[] = []; + private cache: Map = new Map(); + private globalPatterns: Ignore | undefined; + private processedExtraPatterns: Ignore; constructor( projectRoot: string, private readonly extraPatterns?: string[], ) { this.projectRoot = path.resolve(projectRoot); + this.processedExtraPatterns = ignore(); if (this.extraPatterns) { // extraPatterns are assumed to be from project root (like .geminiignore) - this.processedExtraPatterns = this.processPatterns( - this.extraPatterns, - '.', + this.processedExtraPatterns.add( + this.processPatterns(this.extraPatterns, '.'), ); } } - private loadPatternsForFile(patternsFilePath: string): string[] { + private loadPatternsForFile(patternsFilePath: string): Ignore { let content: string; try { content = fs.readFileSync(patternsFilePath, 'utf-8'); } catch (_error) { - return []; + return ignore(); } const isExcludeFile = patternsFilePath.endsWith( @@ -52,7 +52,7 @@ export class GitIgnoreParser implements GitIgnoreFilter { .join(path.posix.sep); const rawPatterns = content.split('\n'); - return this.processPatterns(rawPatterns, relativeBaseDir); + return ignore().add(this.processPatterns(rawPatterns, relativeBaseDir)); } private processPatterns( @@ -155,7 +155,7 @@ export class GitIgnoreParser implements GitIgnoreFilter { ); this.globalPatterns = fs.existsSync(excludeFile) ? this.loadPatternsForFile(excludeFile) - : []; + : ignore(); } ig.add(this.globalPatterns); @@ -198,15 +198,13 @@ export class GitIgnoreParser implements GitIgnoreFilter { this.cache.set(dir, patterns); ig.add(patterns); } else { - this.cache.set(dir, []); // Cache miss + this.cache.set(dir, ignore()); } } } // Apply extra patterns (e.g. from .geminiignore) last for precedence - if (this.processedExtraPatterns.length > 0) { - ig.add(this.processedExtraPatterns); - } + ig.add(this.processedExtraPatterns); return ig.ignores(normalizedPath); } catch (_error) { From d74bf9ef2f2b55f1b034f00fca876583d4c2a143 Mon Sep 17 00:00:00 2001 From: Shreya Keshive Date: Fri, 9 Jan 2026 17:04:57 -0500 Subject: [PATCH 102/713] feat: apply remote admin settings (no-op) (#16106) --- packages/cli/src/config/settings.test.ts | 181 +++++++++++++++++++++++ packages/cli/src/config/settings.ts | 46 +++++- packages/cli/src/gemini.test.tsx | 94 ++---------- packages/cli/src/gemini.tsx | 84 ++++++----- packages/cli/src/gemini_cleanup.test.tsx | 1 + 5 files changed, 281 insertions(+), 125 deletions(-) diff --git a/packages/cli/src/config/settings.test.ts b/packages/cli/src/config/settings.test.ts index df3fdbe9ea..4c07d08b38 100644 --- a/packages/cli/src/config/settings.test.ts +++ b/packages/cli/src/config/settings.test.ts @@ -2476,6 +2476,187 @@ describe('Settings Loading and Merging', () => { }); }); + describe('LoadedSettings and remote admin settings', () => { + it('should prioritize remote admin settings over file-based admin settings', () => { + (mockFsExistsSync as Mock).mockReturnValue(true); + const systemSettingsContent = { + admin: { + // These should be ignored + secureModeEnabled: true, + mcp: { enabled: false }, + extensions: { enabled: false }, + }, + // A non-admin setting to ensure it's still processed + ui: { theme: 'system-theme' }, + }; + + (fs.readFileSync as Mock).mockImplementation( + (p: fs.PathOrFileDescriptor) => { + if (p === getSystemSettingsPath()) { + return JSON.stringify(systemSettingsContent); + } + return '{}'; + }, + ); + + const loadedSettings = loadSettings(MOCK_WORKSPACE_DIR); + + // 1. Verify that on initial load, file-based admin settings are ignored + // and schema defaults are used instead. + expect(loadedSettings.merged.admin?.secureModeEnabled).toBe(false); // default: false + expect(loadedSettings.merged.admin?.mcp?.enabled).toBe(true); // default: true + expect(loadedSettings.merged.admin?.extensions?.enabled).toBe(true); // default: true + expect(loadedSettings.merged.ui?.theme).toBe('system-theme'); // non-admin setting should be loaded + + // 2. Now, set remote admin settings. + loadedSettings.setRemoteAdminSettings({ + secureModeEnabled: true, + mcpSetting: { mcpEnabled: false }, + cliFeatureSetting: { extensionsSetting: { extensionsEnabled: false } }, + }); + + // 3. Verify that remote admin settings take precedence. + expect(loadedSettings.merged.admin?.secureModeEnabled).toBe(true); + expect(loadedSettings.merged.admin?.mcp?.enabled).toBe(false); + expect(loadedSettings.merged.admin?.extensions?.enabled).toBe(false); + // non-admin setting should remain unchanged + expect(loadedSettings.merged.ui?.theme).toBe('system-theme'); + }); + + it('should set remote admin settings and recompute merged settings', () => { + (mockFsExistsSync as Mock).mockReturnValue(true); + const systemSettingsContent = { + admin: { + secureModeEnabled: false, + mcp: { enabled: false }, + extensions: { enabled: false }, + }, + ui: { theme: 'initial-theme' }, + }; + + (fs.readFileSync as Mock).mockImplementation( + (p: fs.PathOrFileDescriptor) => { + if (p === getSystemSettingsPath()) { + return JSON.stringify(systemSettingsContent); + } + return '{}'; + }, + ); + + const loadedSettings = loadSettings(MOCK_WORKSPACE_DIR); + // Ensure initial state from defaults (as file-based admin settings are ignored) + expect(loadedSettings.merged.admin?.secureModeEnabled).toBe(false); + expect(loadedSettings.merged.admin?.mcp?.enabled).toBe(true); + expect(loadedSettings.merged.admin?.extensions?.enabled).toBe(true); + expect(loadedSettings.merged.ui?.theme).toBe('initial-theme'); + + const newRemoteSettings = { + secureModeEnabled: true, + mcpSetting: { mcpEnabled: false }, + cliFeatureSetting: { extensionsSetting: { extensionsEnabled: false } }, + }; + + loadedSettings.setRemoteAdminSettings(newRemoteSettings); + + // Verify that remote admin settings are applied + expect(loadedSettings.merged.admin?.secureModeEnabled).toBe(true); + expect(loadedSettings.merged.admin?.mcp?.enabled).toBe(false); + expect(loadedSettings.merged.admin?.extensions?.enabled).toBe(false); + // Non-admin settings should remain untouched + expect(loadedSettings.merged.ui?.theme).toBe('initial-theme'); + + // Verify that calling setRemoteAdminSettings with partial data overwrites previous remote settings + // and missing properties revert to schema defaults. + loadedSettings.setRemoteAdminSettings({ secureModeEnabled: false }); + expect(loadedSettings.merged.admin?.secureModeEnabled).toBe(false); + expect(loadedSettings.merged.admin?.mcp?.enabled).toBe(true); // Reverts to default: true + expect(loadedSettings.merged.admin?.extensions?.enabled).toBe(true); // Reverts to default: true + }); + + it('should correctly handle undefined remote admin settings', () => { + (mockFsExistsSync as Mock).mockReturnValue(true); + const systemSettingsContent = { + ui: { theme: 'initial-theme' }, + }; + + (fs.readFileSync as Mock).mockImplementation( + (p: fs.PathOrFileDescriptor) => { + if (p === getSystemSettingsPath()) { + return JSON.stringify(systemSettingsContent); + } + return '{}'; + }, + ); + + const loadedSettings = loadSettings(MOCK_WORKSPACE_DIR); + // Should have default admin settings + expect(loadedSettings.merged.admin?.secureModeEnabled).toBe(false); + expect(loadedSettings.merged.admin?.mcp?.enabled).toBe(true); + expect(loadedSettings.merged.admin?.extensions?.enabled).toBe(true); + + loadedSettings.setRemoteAdminSettings({}); // Set empty remote settings + + // Admin settings should revert to defaults because there are no remote overrides + expect(loadedSettings.merged.admin?.secureModeEnabled).toBe(false); + expect(loadedSettings.merged.admin?.mcp?.enabled).toBe(true); + expect(loadedSettings.merged.admin?.extensions?.enabled).toBe(true); + }); + + it('should correctly handle missing properties in remote admin settings', () => { + (mockFsExistsSync as Mock).mockReturnValue(true); + const systemSettingsContent = { + admin: { + secureModeEnabled: true, + }, + }; + + (fs.readFileSync as Mock).mockImplementation( + (p: fs.PathOrFileDescriptor) => { + if (p === getSystemSettingsPath()) { + return JSON.stringify(systemSettingsContent); + } + return '{}'; + }, + ); + + const loadedSettings = loadSettings(MOCK_WORKSPACE_DIR); + // Ensure initial state from defaults (as file-based admin settings are ignored) + expect(loadedSettings.merged.admin?.secureModeEnabled).toBe(false); + expect(loadedSettings.merged.admin?.mcp?.enabled).toBe(true); + expect(loadedSettings.merged.admin?.extensions?.enabled).toBe(true); + + // Set remote settings with only secureModeEnabled + loadedSettings.setRemoteAdminSettings({ + secureModeEnabled: true, + }); + + // Verify secureModeEnabled is updated, others remain defaults + expect(loadedSettings.merged.admin?.secureModeEnabled).toBe(true); + expect(loadedSettings.merged.admin?.mcp?.enabled).toBe(true); + expect(loadedSettings.merged.admin?.extensions?.enabled).toBe(true); + + // Set remote settings with only mcpSetting.mcpEnabled + loadedSettings.setRemoteAdminSettings({ + mcpSetting: { mcpEnabled: false }, + }); + + // Verify mcpEnabled is updated, others remain defaults (secureModeEnabled reverts to default:false) + expect(loadedSettings.merged.admin?.secureModeEnabled).toBe(false); + expect(loadedSettings.merged.admin?.mcp?.enabled).toBe(false); + expect(loadedSettings.merged.admin?.extensions?.enabled).toBe(true); + + // Set remote settings with only cliFeatureSetting.extensionsSetting.extensionsEnabled + loadedSettings.setRemoteAdminSettings({ + cliFeatureSetting: { extensionsSetting: { extensionsEnabled: false } }, + }); + + // Verify extensionsEnabled is updated, others remain defaults + expect(loadedSettings.merged.admin?.secureModeEnabled).toBe(false); + expect(loadedSettings.merged.admin?.mcp?.enabled).toBe(true); + expect(loadedSettings.merged.admin?.extensions?.enabled).toBe(false); + }); + }); + describe('getDefaultsFromSchema', () => { it('should extract defaults from a schema', () => { const mockSchema = { diff --git a/packages/cli/src/config/settings.ts b/packages/cli/src/config/settings.ts index 1389430f29..43bdc1a627 100644 --- a/packages/cli/src/config/settings.ts +++ b/packages/cli/src/config/settings.ts @@ -17,6 +17,7 @@ import { Storage, coreEvents, homedir, + type GeminiCodeAssistSetting, } from '@google/gemini-cli-core'; import stripJsonComments from 'strip-json-comments'; import { DefaultLight } from '../ui/themes/default-light.js'; @@ -499,19 +500,37 @@ export class LoadedSettings { readonly errors: SettingsError[]; private _merged: Settings; + private _remoteAdminSettings: Partial | undefined; get merged(): Settings { return this._merged; } private computeMergedSettings(): Settings { - return mergeSettings( + const merged = mergeSettings( this.system.settings, this.systemDefaults.settings, this.user.settings, this.workspace.settings, this.isTrusted, ); + + // Remote admin settings always take precedence and file-based admin settings + // are ignored. + const adminSettingSchema = getSettingsSchema().admin; + if (adminSettingSchema?.properties) { + const adminSchema = adminSettingSchema.properties; + const adminDefaults = getDefaultsFromSchema(adminSchema); + + // The final admin settings are the defaults overridden by remote settings. + // Any admin settings from files are ignored. + merged.admin = customDeepMerge( + (path: string[]) => getMergeStrategyForPath(['admin', ...path]), + adminDefaults, + this._remoteAdminSettings?.admin ?? {}, + ) as Settings['admin']; + } + return merged; } forScope(scope: LoadableSettingScope): SettingsFile { @@ -537,6 +556,31 @@ export class LoadedSettings { saveSettings(settingsFile); coreEvents.emitSettingsChanged(); } + + setRemoteAdminSettings(remoteSettings: GeminiCodeAssistSetting): void { + const admin: Settings['admin'] = {}; + + if (remoteSettings.secureModeEnabled !== undefined) { + admin.secureModeEnabled = remoteSettings.secureModeEnabled; + } + + if (remoteSettings.mcpSetting?.mcpEnabled !== undefined) { + admin.mcp = { enabled: remoteSettings.mcpSetting.mcpEnabled }; + } + + if ( + remoteSettings.cliFeatureSetting?.extensionsSetting?.extensionsEnabled !== + undefined + ) { + admin.extensions = { + enabled: + remoteSettings.cliFeatureSetting.extensionsSetting.extensionsEnabled, + }; + } + + this._remoteAdminSettings = { admin }; + this._merged = this.computeMergedSettings(); + } } function findEnvFile(startDir: string): string | null { diff --git a/packages/cli/src/gemini.test.tsx b/packages/cli/src/gemini.test.tsx index f8bfa55383..950705bfca 100644 --- a/packages/cli/src/gemini.test.tsx +++ b/packages/cli/src/gemini.test.tsx @@ -230,91 +230,6 @@ describe('gemini.tsx main function', () => { vi.restoreAllMocks(); }); - it('verifies that we dont load the config before relaunchAppInChildProcess', async () => { - const processExitSpy = vi - .spyOn(process, 'exit') - .mockImplementation((code) => { - throw new MockProcessExitError(code); - }); - const { relaunchAppInChildProcess } = await import('./utils/relaunch.js'); - const { loadCliConfig } = await import('./config/config.js'); - const { loadSettings } = await import('./config/settings.js'); - const { loadSandboxConfig } = await import('./config/sandboxConfig.js'); - vi.mocked(loadSandboxConfig).mockResolvedValue(undefined); - - const callOrder: string[] = []; - vi.mocked(relaunchAppInChildProcess).mockImplementation(async () => { - callOrder.push('relaunch'); - }); - vi.mocked(loadCliConfig).mockImplementation(async () => { - callOrder.push('loadCliConfig'); - return { - isInteractive: () => false, - getQuestion: () => '', - getSandbox: () => false, - getDebugMode: () => false, - getListExtensions: () => false, - getListSessions: () => false, - getDeleteSession: () => undefined, - getMcpServers: () => ({}), - getMcpClientManager: vi.fn(), - initialize: vi.fn(), - getIdeMode: () => false, - getExperimentalZedIntegration: () => false, - getScreenReader: () => false, - getGeminiMdFileCount: () => 0, - getProjectRoot: () => '/', - getPolicyEngine: vi.fn(), - getMessageBus: () => ({ - subscribe: vi.fn(), - }), - getEnableHooks: () => false, - getHookSystem: () => undefined, - getToolRegistry: vi.fn(), - getContentGeneratorConfig: vi.fn(), - getModel: () => 'gemini-pro', - getEmbeddingModel: () => 'embedding-001', - getApprovalMode: () => 'default', - getCoreTools: () => [], - getTelemetryEnabled: () => false, - getTelemetryLogPromptsEnabled: () => false, - getFileFilteringRespectGitIgnore: () => true, - getOutputFormat: () => 'text', - getExtensions: () => [], - getUsageStatisticsEnabled: () => false, - refreshAuth: vi.fn(), - setTerminalBackground: vi.fn(), - } as unknown as Config; - }); - vi.mocked(loadSettings).mockReturnValue({ - errors: [], - merged: { - advanced: { autoConfigureMemory: true }, - security: { auth: {} }, - ui: {}, - }, - workspace: { settings: {} }, - setValue: vi.fn(), - forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), - } as never); - try { - await main(); - } catch (e) { - // Mocked process exit throws an error. - if (!(e instanceof MockProcessExitError)) throw e; - } - - // It is critical that we call relaunch before loadCliConfig to avoid - // loading config in the outer process when we are going to relaunch. - // By ensuring we don't load the config we also ensure we don't trigger any - // operations that might require loading the config such as such as - // initializing mcp servers. - // For the sandbox case we still have to load a partial cli config. - // we can authorize outside the sandbox. - expect(callOrder).toEqual(['relaunch', 'loadCliConfig']); - processExitSpy.mockRestore(); - }); - it('should log unhandled promise rejections and open debug console on first error', async () => { const processExitSpy = vi .spyOn(process, 'exit') @@ -519,6 +434,7 @@ describe('gemini.tsx main function kitty protocol', () => { getOutputFormat: () => 'text', getExtensions: () => [], getUsageStatisticsEnabled: () => false, + getRemoteAdminSettings: () => undefined, setTerminalBackground: vi.fn(), } as unknown as Config); vi.mocked(loadSettings).mockReturnValue({ @@ -621,6 +537,7 @@ describe('gemini.tsx main function kitty protocol', () => { getScreenReader: () => false, getGeminiMdFileCount: () => 0, getProjectRoot: () => '/', + getRemoteAdminSettings: () => undefined, setTerminalBackground: vi.fn(), } as unknown as Config; @@ -706,6 +623,7 @@ describe('gemini.tsx main function kitty protocol', () => { getGeminiMdFileCount: () => 0, getProjectRoot: () => '/', refreshAuth: vi.fn(), + getRemoteAdminSettings: () => undefined, setTerminalBackground: vi.fn(), } as unknown as Config; @@ -790,6 +708,7 @@ describe('gemini.tsx main function kitty protocol', () => { getUsageStatisticsEnabled: () => false, refreshAuth: vi.fn(), setTerminalBackground: vi.fn(), + getRemoteAdminSettings: () => undefined, } as any); // eslint-disable-line @typescript-eslint/no-explicit-any vi.spyOn(themeManager, 'setActiveTheme').mockReturnValue(false); @@ -872,6 +791,7 @@ describe('gemini.tsx main function kitty protocol', () => { getFileFilteringRespectGitIgnore: () => true, getOutputFormat: () => 'text', getUsageStatisticsEnabled: () => false, + getRemoteAdminSettings: () => undefined, setTerminalBackground: vi.fn(), } as any); // eslint-disable-line @typescript-eslint/no-explicit-any @@ -953,6 +873,7 @@ describe('gemini.tsx main function kitty protocol', () => { getFileFilteringRespectGitIgnore: () => true, getOutputFormat: () => 'text', getUsageStatisticsEnabled: () => false, + getRemoteAdminSettings: () => undefined, setTerminalBackground: vi.fn(), } as any); // eslint-disable-line @typescript-eslint/no-explicit-any @@ -1030,6 +951,7 @@ describe('gemini.tsx main function kitty protocol', () => { getUsageStatisticsEnabled: () => false, refreshAuth: vi.fn(), setTerminalBackground: vi.fn(), + getRemoteAdminSettings: () => undefined, } as any); // eslint-disable-line @typescript-eslint/no-explicit-any vi.mock('./utils/readStdin.js', () => ({ @@ -1191,6 +1113,7 @@ describe('gemini.tsx main function exit codes', () => { getOutputFormat: () => 'text', getExtensions: () => [], getUsageStatisticsEnabled: () => false, + getRemoteAdminSettings: () => undefined, setTerminalBackground: vi.fn(), } as unknown as Config); vi.mocked(loadSettings).mockReturnValue({ @@ -1257,6 +1180,7 @@ describe('gemini.tsx main function exit codes', () => { getExtensions: () => [], getUsageStatisticsEnabled: () => false, setTerminalBackground: vi.fn(), + getRemoteAdminSettings: () => undefined, } as unknown as Config); vi.mocked(loadSettings).mockReturnValue({ merged: { security: { auth: {} }, ui: {} }, diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index d75f509dd2..5dac29630b 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -375,6 +375,51 @@ export async function main() { } } + const partialConfig = await loadCliConfig(settings.merged, sessionId, argv, { + projectHooks: settings.workspace.settings.hooks, + }); + + // Refresh auth to fetch remote admin settings from CCPA and before entering + // the sandbox because the sandbox will interfere with the Oauth2 web + // redirect. + if ( + settings.merged.security?.auth?.selectedType && + !settings.merged.security?.auth?.useExternal + ) { + try { + if (partialConfig.isInteractive()) { + const err = validateAuthMethod( + settings.merged.security.auth.selectedType, + ); + if (err) { + throw new Error(err); + } + + await partialConfig.refreshAuth( + settings.merged.security.auth.selectedType, + ); + } else { + const authType = await validateNonInteractiveAuth( + settings.merged.security?.auth?.selectedType, + settings.merged.security?.auth?.useExternal, + partialConfig, + settings, + ); + await partialConfig.refreshAuth(authType); + } + } catch (err) { + debugLogger.error('Error authenticating:', err); + await runExitCleanup(); + process.exit(ExitCodes.FATAL_AUTHENTICATION_ERROR); + } + } + + const remoteAdminSettings = partialConfig.getRemoteAdminSettings(); + // Set remote admin settings if returned from CCPA. + if (remoteAdminSettings) { + settings.setRemoteAdminSettings(remoteAdminSettings); + } + // hop into sandbox if we are outside and sandboxing is enabled if (!process.env['SANDBOX']) { const memoryArgs = settings.merged.advanced?.autoConfigureMemory @@ -388,45 +433,6 @@ export async function main() { // another way to decouple refreshAuth from requiring a config. if (sandboxConfig) { - const partialConfig = await loadCliConfig( - settings.merged, - sessionId, - argv, - { projectHooks: settings.workspace.settings.hooks }, - ); - - if ( - settings.merged.security?.auth?.selectedType && - !settings.merged.security?.auth?.useExternal - ) { - try { - if (partialConfig.isInteractive()) { - // Validate authentication here because the sandbox will interfere with the Oauth2 web redirect. - const err = validateAuthMethod( - settings.merged.security.auth.selectedType, - ); - if (err) { - throw new Error(err); - } - - await partialConfig.refreshAuth( - settings.merged.security.auth.selectedType, - ); - } else { - const authType = await validateNonInteractiveAuth( - settings.merged.security?.auth?.selectedType, - settings.merged.security?.auth?.useExternal, - partialConfig, - settings, - ); - await partialConfig.refreshAuth(authType); - } - } catch (err) { - debugLogger.error('Error authenticating:', err); - await runExitCleanup(); - process.exit(ExitCodes.FATAL_AUTHENTICATION_ERROR); - } - } let stdinData = ''; if (!process.stdin.isTTY) { stdinData = await readStdin(); diff --git a/packages/cli/src/gemini_cleanup.test.tsx b/packages/cli/src/gemini_cleanup.test.tsx index e198d3e887..ec1341a768 100644 --- a/packages/cli/src/gemini_cleanup.test.tsx +++ b/packages/cli/src/gemini_cleanup.test.tsx @@ -215,6 +215,7 @@ describe('gemini.tsx main function cleanup', () => { getUsageStatisticsEnabled: vi.fn(() => false), setTerminalBackground: vi.fn(), refreshAuth: vi.fn(), + getRemoteAdminSettings: vi.fn(() => undefined), } as any); // eslint-disable-line @typescript-eslint/no-explicit-any try { From 1fb55dcb2e0b0fe876f4792669adf9432b535bc6 Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Fri, 9 Jan 2026 14:28:09 -0800 Subject: [PATCH 103/713] Autogenerate docs/cli/settings.md docs/getting-started/configuration.md was already autogenerated but settings.md was not. (#14408) --- docs/cli/settings.md | 121 ++++++++++-------- docs/get-started/configuration.md | 8 +- packages/cli/src/config/settingsSchema.ts | 8 +- .../SettingsDialog.test.tsx.snap | 18 +-- schemas/settings.schema.json | 16 +-- scripts/generate-settings-doc.ts | 105 ++++++++++++--- 6 files changed, 179 insertions(+), 97 deletions(-) diff --git a/docs/cli/settings.md b/docs/cli/settings.md index 3aaeffdf9e..f0df2d48c0 100644 --- a/docs/cli/settings.md +++ b/docs/cli/settings.md @@ -18,45 +18,49 @@ Note: Workspace settings override user settings. Here is a list of all the available settings, grouped by category and ordered as they appear in the UI. + + ### General -| UI Label | Setting | Description | Default | -| ------------------------------- | ---------------------------------- | ---------------------------------------------------------------------------- | ----------- | -| Preview Features (e.g., models) | `general.previewFeatures` | Enable preview features (e.g., preview models). | `false` | -| Vim Mode | `general.vimMode` | Enable Vim keybindings. | `false` | -| Disable Auto Update | `general.disableAutoUpdate` | Disable automatic updates. | `false` | -| Enable Prompt Completion | `general.enablePromptCompletion` | Enable AI-powered prompt completion suggestions while typing. | `false` | -| Debug Keystroke Logging | `general.debugKeystrokeLogging` | Enable debug logging of keystrokes to the console. | `false` | -| Session Retention | `general.sessionRetention` | Settings for automatic session cleanup. This feature is disabled by default. | `undefined` | -| Enable Session Cleanup | `general.sessionRetention.enabled` | Enable automatic session cleanup. | `false` | +| UI Label | Setting | Description | Default | +| ------------------------------- | ---------------------------------- | ------------------------------------------------------------- | ------- | +| Preview Features (e.g., models) | `general.previewFeatures` | Enable preview features (e.g., preview models). | `false` | +| Vim Mode | `general.vimMode` | Enable Vim keybindings | `false` | +| Disable Auto Update | `general.disableAutoUpdate` | Disable automatic updates | `false` | +| Enable Prompt Completion | `general.enablePromptCompletion` | Enable AI-powered prompt completion suggestions while typing. | `false` | +| Debug Keystroke Logging | `general.debugKeystrokeLogging` | Enable debug logging of keystrokes to the console. | `false` | +| Enable Session Cleanup | `general.sessionRetention.enabled` | Enable automatic session cleanup | `false` | ### Output -| UI Label | Setting | Description | Default | -| ------------- | --------------- | ------------------------------------------------------ | ------- | -| Output Format | `output.format` | The format of the CLI output. Can be `text` or `json`. | `text` | +| UI Label | Setting | Description | Default | +| ------------- | --------------- | ------------------------------------------------------ | -------- | +| Output Format | `output.format` | The format of the CLI output. Can be `text` or `json`. | `"text"` | ### UI -| UI Label | Setting | Description | Default | -| ------------------------------ | ---------------------------------------- | -------------------------------------------------------------------- | ------- | -| Hide Window Title | `ui.hideWindowTitle` | Hide the window title bar. | `false` | -| Show Status in Title | `ui.showStatusInTitle` | Show Gemini CLI status and thoughts in the terminal window title. | `false` | -| Hide Tips | `ui.hideTips` | Hide helpful tips in the UI. | `false` | -| Hide Banner | `ui.hideBanner` | Hide the application banner. | `false` | -| Hide Context Summary | `ui.hideContextSummary` | Hide the context summary (GEMINI.md, MCP servers) above the input. | `false` | -| Hide CWD | `ui.footer.hideCWD` | Hide the current working directory path in the footer. | `false` | -| Hide Sandbox Status | `ui.footer.hideSandboxStatus` | Hide the sandbox status indicator in the footer. | `false` | -| Hide Model Info | `ui.footer.hideModelInfo` | Hide the model name and context usage in the footer. | `false` | -| Hide Context Window Percentage | `ui.footer.hideContextPercentage` | Hides the context window remaining percentage. | `true` | -| Hide Footer | `ui.hideFooter` | Hide the footer from the UI. | `false` | -| Show Memory Usage | `ui.showMemoryUsage` | Display memory usage information in the UI. | `false` | -| Show Line Numbers | `ui.showLineNumbers` | Show line numbers in the chat. | `false` | -| Show Citations | `ui.showCitations` | Show citations for generated text in the chat. | `false` | -| Use Full Width | `ui.useFullWidth` | Use the entire width of the terminal for output. | `true` | -| Use Alternate Screen Buffer | `ui.useAlternateBuffer` | Use an alternate screen buffer for the UI, preserving shell history. | `true` | -| Disable Loading Phrases | `ui.accessibility.disableLoadingPhrases` | Disable loading phrases for accessibility. | `false` | -| Screen Reader Mode | `ui.accessibility.screenReader` | Render output in plain-text to be more screen reader accessible. | `false` | +| UI Label | Setting | Description | Default | +| ------------------------------ | ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | +| Hide Window Title | `ui.hideWindowTitle` | Hide the window title bar | `false` | +| Show Status in Title | `ui.showStatusInTitle` | Show Gemini CLI status and thoughts in the terminal window title | `false` | +| Show Home Directory Warning | `ui.showHomeDirectoryWarning` | Show a warning when running Gemini CLI in the home directory. | `true` | +| Hide Tips | `ui.hideTips` | Hide helpful tips in the UI | `false` | +| Hide Banner | `ui.hideBanner` | Hide the application banner | `false` | +| Hide Context Summary | `ui.hideContextSummary` | Hide the context summary (GEMINI.md, MCP servers) above the input. | `false` | +| Hide CWD | `ui.footer.hideCWD` | Hide the current working directory path in the footer. | `false` | +| Hide Sandbox Status | `ui.footer.hideSandboxStatus` | Hide the sandbox status indicator in the footer. | `false` | +| Hide Model Info | `ui.footer.hideModelInfo` | Hide the model name and context usage in the footer. | `false` | +| Hide Context Window Percentage | `ui.footer.hideContextPercentage` | Hides the context window remaining percentage. | `true` | +| Hide Footer | `ui.hideFooter` | Hide the footer from the UI | `false` | +| Show Memory Usage | `ui.showMemoryUsage` | Display memory usage information in the UI | `false` | +| Show Line Numbers | `ui.showLineNumbers` | Show line numbers in the chat. | `true` | +| Show Citations | `ui.showCitations` | Show citations for generated text in the chat. | `false` | +| Show Model Info In Chat | `ui.showModelInfoInChat` | Show the model name in the chat for each model turn. | `false` | +| Use Full Width | `ui.useFullWidth` | Use the entire width of the terminal for output. | `true` | +| Use Alternate Screen Buffer | `ui.useAlternateBuffer` | Use an alternate screen buffer for the UI, preserving shell history. | `false` | +| Incremental Rendering | `ui.incrementalRendering` | Enable incremental rendering for the UI. This option will reduce flickering but may cause rendering artifacts. Only supported when useAlternateBuffer is enabled. | `true` | +| Disable Loading Phrases | `ui.accessibility.disableLoadingPhrases` | Disable loading phrases for accessibility | `false` | +| Screen Reader Mode | `ui.accessibility.screenReader` | Render output in plain-text to be more screen reader accessible | `false` | ### IDE @@ -69,7 +73,7 @@ they appear in the UI. | UI Label | Setting | Description | Default | | ----------------------- | ---------------------------- | -------------------------------------------------------------------------------------- | ------- | | Max Session Turns | `model.maxSessionTurns` | Maximum number of user/model/tool turns to keep in a session. -1 means unlimited. | `-1` | -| Compression Threshold | `model.compressionThreshold` | The fraction of context usage at which to trigger context compression (e.g. 0.2, 0.3). | `0.2` | +| Compression Threshold | `model.compressionThreshold` | The fraction of context usage at which to trigger context compression (e.g. 0.2, 0.3). | `0.5` | | Skip Next Speaker Check | `model.skipNextSpeakerCheck` | Skip the next speaker check. | `true` | ### Context @@ -85,31 +89,40 @@ they appear in the UI. ### Tools -| UI Label | Setting | Description | Default | -| -------------------------------- | ------------------------------------ | --------------------------------------------------------------------------------------------------------------- | ------- | -| Enable Interactive Shell | `tools.shell.enableInteractiveShell` | Use node-pty for an interactive shell experience. Fallback to child_process still applies. | `true` | -| Show Color | `tools.shell.showColor` | Show color in shell output. | `false` | -| Auto Accept | `tools.autoAccept` | Automatically accept and execute tool calls that are considered safe (e.g., read-only operations). | `false` | -| Use Ripgrep | `tools.useRipgrep` | Use ripgrep for file content search instead of the fallback implementation. Provides faster search performance. | `true` | -| Enable Tool Output Truncation | `tools.enableToolOutputTruncation` | Enable truncation of large tool outputs. | `true` | -| Tool Output Truncation Threshold | `tools.truncateToolOutputThreshold` | Truncate tool output if it is larger than this many characters. Set to -1 to disable. | `10000` | -| Tool Output Truncation Lines | `tools.truncateToolOutputLines` | The number of lines to keep when truncating tool output. | `100` | +| UI Label | Setting | Description | Default | +| -------------------------------- | ------------------------------------ | --------------------------------------------------------------------------------------------------------------- | --------- | +| Enable Interactive Shell | `tools.shell.enableInteractiveShell` | Use node-pty for an interactive shell experience. Fallback to child_process still applies. | `true` | +| Show Color | `tools.shell.showColor` | Show color in shell output. | `false` | +| Auto Accept | `tools.autoAccept` | Automatically accept and execute tool calls that are considered safe (e.g., read-only operations). | `false` | +| Use Ripgrep | `tools.useRipgrep` | Use ripgrep for file content search instead of the fallback implementation. Provides faster search performance. | `true` | +| Enable Tool Output Truncation | `tools.enableToolOutputTruncation` | Enable truncation of large tool outputs. | `true` | +| Tool Output Truncation Threshold | `tools.truncateToolOutputThreshold` | Truncate tool output if it is larger than this many characters. Set to -1 to disable. | `4000000` | +| Tool Output Truncation Lines | `tools.truncateToolOutputLines` | The number of lines to keep when truncating tool output. | `1000` | ### Security -| UI Label | Setting | Description | Default | -| ----------------------------- | ----------------------------------------------- | --------------------------------------------------------- | ------- | -| Disable YOLO Mode | `security.disableYoloMode` | Disable YOLO mode, even if enabled by a flag. | `false` | -| Blocks extensions from Git | `security.blockGitExtensions` | Blocks installing and loading extensions from Git. | `false` | -| Folder Trust | `security.folderTrust.enabled` | Setting to track whether Folder trust is enabled. | `false` | -| Allowed Environment Variables | `security.environmentVariableRedaction.allowed` | Environment variables to always allow (bypass redaction). | `[]` | -| Blocked Environment Variables | `security.environmentVariableRedaction.blocked` | Environment variables to always redact. | `[]` | +| UI Label | Setting | Description | Default | +| ------------------------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------- | ------- | +| Disable YOLO Mode | `security.disableYoloMode` | Disable YOLO mode, even if enabled by a flag. | `false` | +| Allow Permanent Tool Approval | `security.enablePermanentToolApproval` | Enable the "Allow for all future sessions" option in tool confirmation dialogs. | `false` | +| Blocks extensions from Git | `security.blockGitExtensions` | Blocks installing and loading extensions from Git. | `false` | +| Folder Trust | `security.folderTrust.enabled` | Setting to track whether Folder trust is enabled. | `false` | +| Enable Environment Variable Redaction | `security.environmentVariableRedaction.enabled` | Enable redaction of environment variables that may contain secrets. | `false` | ### Experimental -| UI Label | Setting | Description | Default | -| ----------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------ | ------- | -| Enable Codebase Investigator | `experimental.codebaseInvestigatorSettings.enabled` | Enable the Codebase Investigator agent. | `true` | -| Codebase Investigator Max Num Turns | `experimental.codebaseInvestigatorSettings.maxNumTurns` | Maximum number of turns for the Codebase Investigator agent. | `10` | -| Enable CLI Help Agent | `experimental.cliHelpAgentSettings.enabled` | Enable the CLI Help Agent. | `true` | -| Agent Skills | `experimental.skills` | Enable Agent Skills (experimental). | `false` | +| UI Label | Setting | Description | Default | +| ----------------------------------- | ------------------------------------------------------- | ----------------------------------------------------------------------------------- | ------- | +| Agent Skills | `experimental.skills` | Enable Agent Skills (experimental). | `false` | +| Enable Codebase Investigator | `experimental.codebaseInvestigatorSettings.enabled` | Enable the Codebase Investigator agent. | `true` | +| Codebase Investigator Max Num Turns | `experimental.codebaseInvestigatorSettings.maxNumTurns` | Maximum number of turns for the Codebase Investigator agent. | `10` | +| Use OSC 52 Paste | `experimental.useOSC52Paste` | Use OSC 52 sequence for pasting instead of clipboardy (useful for remote sessions). | `false` | +| Enable CLI Help Agent | `experimental.cliHelpAgentSettings.enabled` | Enable the CLI Help Agent. | `true` | + +### Hooks + +| UI Label | Setting | Description | Default | +| ------------------ | --------------------- | ------------------------------------------------ | ------- | +| Hook Notifications | `hooks.notifications` | Show visual indicators when hooks are executing. | `true` | + + diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 8d7b95e24d..2ec3edc09b 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -159,7 +159,7 @@ their corresponding top-level category object in your `settings.json` file. #### `output` - **`output.format`** (enum): - - **Description:** The format of the CLI output. + - **Description:** The format of the CLI output. Can be `text` or `json`. - **Default:** `"text"` - **Values:** `"text"`, `"json"` @@ -275,7 +275,7 @@ their corresponding top-level category object in your `settings.json` file. #### `ide` - **`ide.enabled`** (boolean): - - **Description:** Enable IDE integration mode + - **Description:** Enable IDE integration mode. - **Default:** `false` - **Requires restart:** Yes @@ -579,12 +579,12 @@ their corresponding top-level category object in your `settings.json` file. - **Default:** `false` - **`context.fileFiltering.respectGitIgnore`** (boolean): - - **Description:** Respect .gitignore files when searching + - **Description:** Respect .gitignore files when searching. - **Default:** `true` - **Requires restart:** Yes - **`context.fileFiltering.respectGeminiIgnore`** (boolean): - - **Description:** Respect .geminiignore files when searching + - **Description:** Respect .geminiignore files when searching. - **Default:** `true` - **Requires restart:** Yes diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index b69d8f7fe6..7b29ff3d62 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -323,7 +323,7 @@ const SETTINGS_SCHEMA = { category: 'General', requiresRestart: false, default: 'text', - description: 'The format of the CLI output.', + description: 'The format of the CLI output. Can be `text` or `json`.', showInDialog: true, options: [ { value: 'text', label: 'Text' }, @@ -605,7 +605,7 @@ const SETTINGS_SCHEMA = { category: 'IDE', requiresRestart: true, default: false, - description: 'Enable IDE integration mode', + description: 'Enable IDE integration mode.', showInDialog: true, }, hasSeenNudge: { @@ -854,7 +854,7 @@ const SETTINGS_SCHEMA = { category: 'Context', requiresRestart: true, default: true, - description: 'Respect .gitignore files when searching', + description: 'Respect .gitignore files when searching.', showInDialog: true, }, respectGeminiIgnore: { @@ -863,7 +863,7 @@ const SETTINGS_SCHEMA = { category: 'Context', requiresRestart: true, default: true, - description: 'Respect .geminiignore files when searching', + description: 'Respect .geminiignore files when searching.', showInDialog: true, }, enableRecursiveFileSearch: { diff --git a/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap index 90392e72f1..144b936ab6 100644 --- a/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap +++ b/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap @@ -29,7 +29,7 @@ exports[`SettingsDialog > Initial Rendering > should render settings list with v │ Enable automatic session cleanup │ │ │ │ Output Format Text │ -│ The format of the CLI output. │ +│ The format of the CLI output. Can be \`text\` or \`json\`. │ │ │ │ Hide Window Title false │ │ Hide the window title bar │ @@ -75,7 +75,7 @@ exports[`SettingsDialog > Snapshot Tests > should render 'accessibility settings │ Enable automatic session cleanup │ │ │ │ Output Format Text │ -│ The format of the CLI output. │ +│ The format of the CLI output. Can be \`text\` or \`json\`. │ │ │ │ Hide Window Title false │ │ Hide the window title bar │ @@ -121,7 +121,7 @@ exports[`SettingsDialog > Snapshot Tests > should render 'all boolean settings d │ Enable automatic session cleanup │ │ │ │ Output Format Text │ -│ The format of the CLI output. │ +│ The format of the CLI output. Can be \`text\` or \`json\`. │ │ │ │ Hide Window Title false* │ │ Hide the window title bar │ @@ -167,7 +167,7 @@ exports[`SettingsDialog > Snapshot Tests > should render 'default state' correct │ Enable automatic session cleanup │ │ │ │ Output Format Text │ -│ The format of the CLI output. │ +│ The format of the CLI output. Can be \`text\` or \`json\`. │ │ │ │ Hide Window Title false │ │ Hide the window title bar │ @@ -213,7 +213,7 @@ exports[`SettingsDialog > Snapshot Tests > should render 'file filtering setting │ Enable automatic session cleanup │ │ │ │ Output Format Text │ -│ The format of the CLI output. │ +│ The format of the CLI output. Can be \`text\` or \`json\`. │ │ │ │ Hide Window Title false │ │ Hide the window title bar │ @@ -259,7 +259,7 @@ exports[`SettingsDialog > Snapshot Tests > should render 'focused on scope selec │ Enable automatic session cleanup │ │ │ │ Output Format Text │ -│ The format of the CLI output. │ +│ The format of the CLI output. Can be \`text\` or \`json\`. │ │ │ │ Hide Window Title false │ │ Hide the window title bar │ @@ -305,7 +305,7 @@ exports[`SettingsDialog > Snapshot Tests > should render 'mixed boolean and numb │ Enable automatic session cleanup │ │ │ │ Output Format Text │ -│ The format of the CLI output. │ +│ The format of the CLI output. Can be \`text\` or \`json\`. │ │ │ │ Hide Window Title false* │ │ Hide the window title bar │ @@ -351,7 +351,7 @@ exports[`SettingsDialog > Snapshot Tests > should render 'tools and security set │ Enable automatic session cleanup │ │ │ │ Output Format Text │ -│ The format of the CLI output. │ +│ The format of the CLI output. Can be \`text\` or \`json\`. │ │ │ │ Hide Window Title false │ │ Hide the window title bar │ @@ -397,7 +397,7 @@ exports[`SettingsDialog > Snapshot Tests > should render 'various boolean settin │ Enable automatic session cleanup │ │ │ │ Output Format Text │ -│ The format of the CLI output. │ +│ The format of the CLI output. Can be \`text\` or \`json\`. │ │ │ │ Hide Window Title true* │ │ Hide the window title bar │ diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index 2cfbcb5056..33a659a822 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -148,8 +148,8 @@ "properties": { "format": { "title": "Output Format", - "description": "The format of the CLI output.", - "markdownDescription": "The format of the CLI output.\n\n- Category: `General`\n- Requires restart: `no`\n- Default: `text`", + "description": "The format of the CLI output. Can be `text` or `json`.", + "markdownDescription": "The format of the CLI output. Can be `text` or `json`.\n\n- Category: `General`\n- Requires restart: `no`\n- Default: `text`", "default": "text", "type": "string", "enum": ["text", "json"] @@ -362,8 +362,8 @@ "properties": { "enabled": { "title": "IDE Mode", - "description": "Enable IDE integration mode", - "markdownDescription": "Enable IDE integration mode\n\n- Category: `IDE`\n- Requires restart: `yes`\n- Default: `false`", + "description": "Enable IDE integration mode.", + "markdownDescription": "Enable IDE integration mode.\n\n- Category: `IDE`\n- Requires restart: `yes`\n- Default: `false`", "default": false, "type": "boolean" }, @@ -971,15 +971,15 @@ "properties": { "respectGitIgnore": { "title": "Respect .gitignore", - "description": "Respect .gitignore files when searching", - "markdownDescription": "Respect .gitignore files when searching\n\n- Category: `Context`\n- Requires restart: `yes`\n- Default: `true`", + "description": "Respect .gitignore files when searching.", + "markdownDescription": "Respect .gitignore files when searching.\n\n- Category: `Context`\n- Requires restart: `yes`\n- Default: `true`", "default": true, "type": "boolean" }, "respectGeminiIgnore": { "title": "Respect .geminiignore", - "description": "Respect .geminiignore files when searching", - "markdownDescription": "Respect .geminiignore files when searching\n\n- Category: `Context`\n- Requires restart: `yes`\n- Default: `true`", + "description": "Respect .geminiignore files when searching.", + "markdownDescription": "Respect .geminiignore files when searching.\n\n- Category: `Context`\n- Requires restart: `yes`\n- Default: `true`", "default": true, "type": "boolean" }, diff --git a/scripts/generate-settings-doc.ts b/scripts/generate-settings-doc.ts index 6cd5c6a293..1511559705 100644 --- a/scripts/generate-settings-doc.ts +++ b/scripts/generate-settings-doc.ts @@ -30,6 +30,8 @@ const MANUAL_TOP_LEVEL = new Set(['mcpServers', 'telemetry', 'extensions']); interface DocEntry { path: string; type: string; + label: string; + category: string; description: string; defaultValue: string; requiresRestart: boolean; @@ -46,40 +48,61 @@ export async function main(argv = process.argv.slice(2)) { '..', ); const docPath = path.join(repoRoot, 'docs/get-started/configuration.md'); + const cliSettingsDocPath = path.join(repoRoot, 'docs/cli/settings.md'); const { getSettingsSchema } = await loadSettingsSchemaModule(); const schema = getSettingsSchema(); - const sections = collectEntries(schema); - const generatedBlock = renderSections(sections); + const allSettingsSections = collectEntries(schema, { includeAll: true }); + const filteredSettingsSections = collectEntries(schema, { + includeAll: false, + }); - const doc = await readFile(docPath, 'utf8'); + const generatedBlock = renderSections(allSettingsSections); + const generatedTableBlock = renderTableSections(filteredSettingsSections); + + await updateFile(docPath, generatedBlock, checkOnly); + await updateFile(cliSettingsDocPath, generatedTableBlock, checkOnly); +} + +async function updateFile( + filePath: string, + newContent: string, + checkOnly: boolean, +) { + const doc = await readFile(filePath, 'utf8'); const injectedDoc = injectBetweenMarkers({ document: doc, startMarker: START_MARKER, endMarker: END_MARKER, - newContent: generatedBlock, + newContent: newContent, paddingBefore: '\n', paddingAfter: '\n', }); - const formattedDoc = await formatWithPrettier(injectedDoc, docPath); + const formattedDoc = await formatWithPrettier(injectedDoc, filePath); if (normalizeForCompare(doc) === normalizeForCompare(formattedDoc)) { if (!checkOnly) { - console.log('Settings documentation already up to date.'); + console.log( + `Settings documentation (${path.basename(filePath)}) already up to date.`, + ); } return; } if (checkOnly) { console.error( - 'Settings documentation is out of date. Run `npm run docs:settings` to regenerate.', + 'Settings documentation (' + + path.basename(filePath) + + ') is out of date. Run `npm run docs:settings` to regenerate.', ); process.exitCode = 1; return; } - await writeFile(docPath, formattedDoc); - console.log('Settings documentation regenerated.'); + await writeFile(filePath, formattedDoc); + console.log( + `Settings documentation (${path.basename(filePath)}) regenerated.`, + ); } async function loadSettingsSchemaModule() { @@ -87,7 +110,10 @@ async function loadSettingsSchemaModule() { return import(modulePath); } -function collectEntries(schema: SettingsSchemaType) { +function collectEntries( + schema: SettingsSchemaType, + options: { includeAll?: boolean } = {}, +) { const sections = new Map(); const visit = ( @@ -107,7 +133,7 @@ function collectEntries(schema: SettingsSchemaType) { definition.properties && Object.keys(definition.properties).length > 0; - if (!hasChildren) { + if (!hasChildren && (options.includeAll || definition.showInDialog)) { if (!sections.has(sectionKey)) { sections.set(sectionKey, []); } @@ -115,6 +141,8 @@ function collectEntries(schema: SettingsSchemaType) { sections.get(sectionKey)!.push({ path: newPathSegments.join('.'), type: formatType(definition), + label: definition.label, + category: definition.category, description: formatDescription(definition), defaultValue: formatDefaultValue(definition.default, { quoteStrings: true, @@ -162,12 +190,12 @@ function renderSections(sections: Map) { continue; } - lines.push(`#### \`${section}\``); + lines.push('#### `' + section + '`'); lines.push(''); for (const entry of entries) { - lines.push(`- **\`${entry.path}\`** (${entry.type}):`); - lines.push(` - **Description:** ${entry.description}`); + lines.push('- **`' + entry.path + '`** (' + entry.type + '):'); + lines.push(' - **Description:** ' + entry.description); if (entry.defaultValue.includes('\n')) { lines.push(' - **Default:**'); @@ -176,21 +204,21 @@ function renderSections(sections: Map) { lines.push( entry.defaultValue .split('\n') - .map((line) => ` ${line}`) + .map((line) => ' ' + line) .join('\n'), ); lines.push(' ```'); } else { lines.push( - ` - **Default:** \`${escapeBackticks(entry.defaultValue)}\``, + ' - **Default:** `' + escapeBackticks(entry.defaultValue) + '`', ); } if (entry.enumValues && entry.enumValues.length > 0) { const values = entry.enumValues - .map((value) => `\`${escapeBackticks(value)}\``) + .map((value) => '`' + escapeBackticks(value) + '`') .join(', '); - lines.push(` - **Values:** ${values}`); + lines.push(' - **Values:** ' + values); } if (entry.requiresRestart) { @@ -204,6 +232,47 @@ function renderSections(sections: Map) { return lines.join('\n').trimEnd(); } +function renderTableSections(sections: Map) { + const lines: string[] = []; + + for (const [section, entries] of sections) { + if (entries.length === 0) { + continue; + } + + let title = section.charAt(0).toUpperCase() + section.slice(1); + if (title === 'Ui') { + title = 'UI'; + } else if (title === 'Ide') { + title = 'IDE'; + } + lines.push(`### ${title}`); + lines.push(''); + lines.push('| UI Label | Setting | Description | Default |'); + lines.push('| --- | --- | --- | --- |'); + + for (const entry of entries) { + const val = entry.defaultValue.replace(/\n/g, ' '); + const defaultVal = '`' + escapeBackticks(val) + '`'; + lines.push( + '| ' + + entry.label + + ' | `' + + entry.path + + '` | ' + + entry.description + + ' | ' + + defaultVal + + ' |', + ); + } + + lines.push(''); + } + + return lines.join('\n').trimEnd(); +} + if (process.argv[1]) { const entryUrl = pathToFileURL(path.resolve(process.argv[1])).href; if (entryUrl === import.meta.url) { From 356f76e545df28b26e8d7c6f2e5a0ade1fa55cd6 Mon Sep 17 00:00:00 2001 From: Gal Zahavi <38544478+galz10@users.noreply.github.com> Date: Fri, 9 Jan 2026 14:34:23 -0800 Subject: [PATCH 104/713] refactor(config): remove legacy V1 settings migration logic (#16252) --- integration-tests/test-helper.ts | 4 +- packages/cli/src/config/settings.test.ts | 818 +----------------- packages/cli/src/config/settings.ts | 319 +------ packages/cli/src/gemini.tsx | 21 +- packages/cli/src/test-utils/render.tsx | 4 +- packages/cli/src/ui/App.test.tsx | 8 +- .../src/ui/components/SettingsDialog.test.tsx | 2 +- .../src/ui/components/ThemeDialog.test.tsx | 2 +- .../cli/src/ui/utils/CodeColorizer.test.tsx | 2 +- .../cli/src/ui/utils/MarkdownDisplay.test.tsx | 2 +- 10 files changed, 22 insertions(+), 1160 deletions(-) diff --git a/integration-tests/test-helper.ts b/integration-tests/test-helper.ts index 53b409b733..9a2a6cefca 100644 --- a/integration-tests/test-helper.ts +++ b/integration-tests/test-helper.ts @@ -341,7 +341,9 @@ export class TestRig { ui: { useAlternateBuffer: true, }, - model: DEFAULT_GEMINI_MODEL, + model: { + name: DEFAULT_GEMINI_MODEL, + }, sandbox: env['GEMINI_SANDBOX'] !== 'false' ? env['GEMINI_SANDBOX'] : false, // Don't show the IDE connection dialog when running from VsCode diff --git a/packages/cli/src/config/settings.test.ts b/packages/cli/src/config/settings.test.ts index 4c07d08b38..004b60ea28 100644 --- a/packages/cli/src/config/settings.test.ts +++ b/packages/cli/src/config/settings.test.ts @@ -44,7 +44,7 @@ vi.mock('./settingsSchema.js', async (importOriginal) => { }); // NOW import everything else, including the (now effectively re-exported) settings.js -import path, * as pathActual from 'node:path'; // Restored for MOCK_WORKSPACE_SETTINGS_PATH +import * as pathActual from 'node:path'; // Restored for MOCK_WORKSPACE_SETTINGS_PATH import { describe, it, @@ -65,18 +65,12 @@ import { USER_SETTINGS_PATH, // This IS the mocked path. getSystemSettingsPath, getSystemDefaultsPath, - migrateSettingsToV1, - needsMigration, type Settings, - loadEnvironment, - migrateDeprecatedSettings, - SettingScope, saveSettings, type SettingsFile, getDefaultsFromSchema, } from './settings.js'; import { FatalConfigError, GEMINI_DIR } from '@google/gemini-cli-core'; -import { ExtensionManager } from './extension-manager.js'; import { updateSettingsFilePreservingFormat } from '../utils/commentJson.js'; import { getSettingsSchema, @@ -290,169 +284,6 @@ describe('Settings Loading and Merging', () => { }); }); - it('should correctly migrate a complex legacy (v1) settings file', () => { - (mockFsExistsSync as Mock).mockImplementation( - (p: fs.PathLike) => p === USER_SETTINGS_PATH, - ); - const legacySettingsContent = { - theme: 'legacy-dark', - vimMode: true, - contextFileName: 'LEGACY_CONTEXT.md', - model: 'gemini-2.5-pro', - mcpServers: { - 'legacy-server-1': { - command: 'npm', - args: ['run', 'start:server1'], - description: 'Legacy Server 1', - }, - 'legacy-server-2': { - command: 'node', - args: ['server2.js'], - description: 'Legacy Server 2', - }, - }, - allowMCPServers: ['legacy-server-1'], - someUnrecognizedSetting: 'should-be-preserved', - }; - - (fs.readFileSync as Mock).mockImplementation( - (p: fs.PathOrFileDescriptor) => { - if (p === USER_SETTINGS_PATH) - return JSON.stringify(legacySettingsContent); - return '{}'; - }, - ); - - const settings = loadSettings(MOCK_WORKSPACE_DIR); - - expect(settings.merged).toMatchObject({ - ui: { - theme: 'legacy-dark', - }, - general: { - vimMode: true, - }, - context: { - fileName: 'LEGACY_CONTEXT.md', - }, - model: { - name: 'gemini-2.5-pro', - }, - mcpServers: { - 'legacy-server-1': { - command: 'npm', - args: ['run', 'start:server1'], - description: 'Legacy Server 1', - }, - 'legacy-server-2': { - command: 'node', - args: ['server2.js'], - description: 'Legacy Server 2', - }, - }, - mcp: { - allowed: ['legacy-server-1'], - }, - someUnrecognizedSetting: 'should-be-preserved', - }); - }); - - it('should rewrite allowedTools to tools.allowed during migration', () => { - (mockFsExistsSync as Mock).mockImplementation( - (p: fs.PathLike) => p === USER_SETTINGS_PATH, - ); - const legacySettingsContent = { - allowedTools: ['fs', 'shell'], - }; - (fs.readFileSync as Mock).mockImplementation( - (p: fs.PathOrFileDescriptor) => { - if (p === USER_SETTINGS_PATH) - return JSON.stringify(legacySettingsContent); - return '{}'; - }, - ); - - const settings = loadSettings(MOCK_WORKSPACE_DIR); - - expect(settings.merged.tools?.allowed).toEqual(['fs', 'shell']); - expect((settings.merged as TestSettings)['allowedTools']).toBeUndefined(); - }); - - it('should allow V2 settings to override V1 settings when both are present (zombie setting fix)', () => { - (mockFsExistsSync as Mock).mockImplementation( - (p: fs.PathLike) => p === USER_SETTINGS_PATH, - ); - const mixedSettingsContent = { - // V1 setting (migrates to ui.accessibility.screenReader = true) - accessibility: { - screenReader: true, - }, - // V2 setting (explicitly set to false) - ui: { - accessibility: { - screenReader: false, - }, - }, - }; - - (fs.readFileSync as Mock).mockImplementation( - (p: fs.PathOrFileDescriptor) => { - if (p === USER_SETTINGS_PATH) - return JSON.stringify(mixedSettingsContent); - return '{}'; - }, - ); - - const settings = loadSettings(MOCK_WORKSPACE_DIR); - - // We expect the V2 setting (false) to win, NOT the migrated V1 setting (true) - expect(settings.merged.ui?.accessibility?.screenReader).toBe(false); - }); - - it('should correctly merge and migrate legacy array properties from multiple scopes', () => { - (mockFsExistsSync as Mock).mockReturnValue(true); - const legacyUserSettings = { - includeDirectories: ['/user/dir'], - excludeTools: ['user-tool'], - excludedProjectEnvVars: ['USER_VAR'], - }; - const legacyWorkspaceSettings = { - includeDirectories: ['/workspace/dir'], - excludeTools: ['workspace-tool'], - excludedProjectEnvVars: ['WORKSPACE_VAR', 'USER_VAR'], - }; - - (fs.readFileSync as Mock).mockImplementation( - (p: fs.PathOrFileDescriptor) => { - if (p === USER_SETTINGS_PATH) - return JSON.stringify(legacyUserSettings); - if (p === MOCK_WORKSPACE_SETTINGS_PATH) - return JSON.stringify(legacyWorkspaceSettings); - return '{}'; - }, - ); - - const settings = loadSettings(MOCK_WORKSPACE_DIR); - - // Verify includeDirectories are concatenated - expect(settings.merged.context?.includeDirectories).toEqual([ - '/user/dir', - '/workspace/dir', - ]); - - // Verify excludeTools are concatenated and de-duped - expect(settings.merged.tools?.exclude).toEqual([ - 'user-tool', - 'workspace-tool', - ]); - - // Verify excludedProjectEnvVars are concatenated and de-duped - expect(settings.merged.advanced?.excludedEnvVars).toEqual( - expect.arrayContaining(['USER_VAR', 'WORKSPACE_VAR']), - ); - expect(settings.merged.advanced?.excludedEnvVars).toHaveLength(4); - }); - it('should merge all settings files with the correct precedence', () => { // Mock schema to test defaults application const mockSchema = { @@ -1771,653 +1602,6 @@ describe('Settings Loading and Merging', () => { }); }); - describe('with workspace trust', () => { - it('should merge workspace settings when workspace is trusted', () => { - (mockFsExistsSync as Mock).mockReturnValue(true); - const userSettingsContent = { - ui: { theme: 'dark' }, - tools: { sandbox: false }, - }; - const workspaceSettingsContent = { - tools: { sandbox: true }, - context: { fileName: 'WORKSPACE.md' }, - }; - - (fs.readFileSync as Mock).mockImplementation( - (p: fs.PathOrFileDescriptor) => { - if (p === USER_SETTINGS_PATH) - return JSON.stringify(userSettingsContent); - if (p === MOCK_WORKSPACE_SETTINGS_PATH) - return JSON.stringify(workspaceSettingsContent); - return '{}'; - }, - ); - - const settings = loadSettings(MOCK_WORKSPACE_DIR); - expect(settings.merged.tools?.sandbox).toBe(true); - expect(settings.merged.context?.fileName).toBe('WORKSPACE.md'); - expect(settings.merged.ui?.theme).toBe('dark'); - }); - - it('should NOT merge workspace settings when workspace is not trusted', () => { - vi.mocked(isWorkspaceTrusted).mockReturnValue({ - isTrusted: false, - source: 'file', - }); - (mockFsExistsSync as Mock).mockReturnValue(true); - const userSettingsContent = { - ui: { theme: 'dark' }, - tools: { sandbox: false }, - context: { fileName: 'USER.md' }, - }; - const workspaceSettingsContent = { - tools: { sandbox: true }, - context: { fileName: 'WORKSPACE.md' }, - }; - - (fs.readFileSync as Mock).mockImplementation( - (p: fs.PathOrFileDescriptor) => { - if (p === USER_SETTINGS_PATH) - return JSON.stringify(userSettingsContent); - if (p === MOCK_WORKSPACE_SETTINGS_PATH) - return JSON.stringify(workspaceSettingsContent); - return '{}'; - }, - ); - - const settings = loadSettings(MOCK_WORKSPACE_DIR); - - expect(settings.merged.tools?.sandbox).toBe(false); // User setting - expect(settings.merged.context?.fileName).toBe('USER.md'); // User setting - expect(settings.merged.ui?.theme).toBe('dark'); // User setting - }); - }); - - describe('migrateSettingsToV1', () => { - it('should handle an empty object', () => { - const v2Settings = {}; - const v1Settings = migrateSettingsToV1(v2Settings); - expect(v1Settings).toEqual({}); - }); - - it('should migrate a simple v2 settings object to v1', () => { - const v2Settings = { - general: { - preferredEditor: 'vscode', - vimMode: true, - }, - ui: { - theme: 'dark', - }, - }; - const v1Settings = migrateSettingsToV1(v2Settings); - expect(v1Settings).toEqual({ - preferredEditor: 'vscode', - vimMode: true, - theme: 'dark', - }); - }); - - it('should handle nested properties correctly', () => { - const v2Settings = { - security: { - folderTrust: { - enabled: true, - }, - auth: { - selectedType: 'oauth', - }, - }, - advanced: { - autoConfigureMemory: true, - }, - }; - const v1Settings = migrateSettingsToV1(v2Settings); - expect(v1Settings).toEqual({ - folderTrust: true, - selectedAuthType: 'oauth', - autoConfigureMaxOldSpaceSize: true, - }); - }); - - it('should preserve mcpServers at the top level', () => { - const v2Settings = { - general: { - preferredEditor: 'vscode', - }, - mcpServers: { - 'my-server': { - command: 'npm start', - }, - }, - }; - const v1Settings = migrateSettingsToV1(v2Settings); - expect(v1Settings).toEqual({ - preferredEditor: 'vscode', - mcpServers: { - 'my-server': { - command: 'npm start', - }, - }, - }); - }); - - it('should carry over unrecognized top-level properties', () => { - const v2Settings = { - general: { - vimMode: false, - }, - unrecognized: 'value', - another: { - nested: true, - }, - }; - const v1Settings = migrateSettingsToV1(v2Settings); - expect(v1Settings).toEqual({ - vimMode: false, - unrecognized: 'value', - another: { - nested: true, - }, - }); - }); - - it('should handle a complex object with mixed properties', () => { - const v2Settings = { - general: { - disableAutoUpdate: true, - }, - ui: { - hideBanner: true, - customThemes: { - myTheme: {}, - }, - }, - model: { - name: 'gemini-pro', - }, - mcpServers: { - 'server-1': { - command: 'node server.js', - }, - }, - unrecognized: { - should: 'be-preserved', - }, - }; - const v1Settings = migrateSettingsToV1(v2Settings); - expect(v1Settings).toEqual({ - disableAutoUpdate: true, - hideBanner: true, - customThemes: { - myTheme: {}, - }, - model: 'gemini-pro', - mcpServers: { - 'server-1': { - command: 'node server.js', - }, - }, - unrecognized: { - should: 'be-preserved', - }, - }); - }); - - it('should not migrate a v1 settings object', () => { - const v1Settings = { - preferredEditor: 'vscode', - vimMode: true, - theme: 'dark', - }; - const migratedSettings = migrateSettingsToV1(v1Settings); - expect(migratedSettings).toEqual({ - preferredEditor: 'vscode', - vimMode: true, - theme: 'dark', - }); - }); - - it('should migrate a full v2 settings object to v1', () => { - const v2Settings: TestSettings = { - general: { - preferredEditor: 'code', - vimMode: true, - }, - ui: { - theme: 'dark', - }, - privacy: { - usageStatisticsEnabled: false, - }, - model: { - name: 'gemini-2.5-pro', - }, - context: { - fileName: 'CONTEXT.md', - includeDirectories: ['/src'], - }, - tools: { - sandbox: true, - exclude: ['toolA'], - }, - mcp: { - allowed: ['server1'], - }, - security: { - folderTrust: { - enabled: true, - }, - }, - advanced: { - dnsResolutionOrder: 'ipv4first', - excludedEnvVars: ['SECRET'], - }, - mcpServers: { - 'my-server': { - command: 'npm start', - }, - }, - unrecognizedTopLevel: { - value: 'should be preserved', - }, - }; - - const v1Settings = migrateSettingsToV1(v2Settings); - - expect(v1Settings).toEqual({ - preferredEditor: 'code', - vimMode: true, - theme: 'dark', - usageStatisticsEnabled: false, - model: 'gemini-2.5-pro', - contextFileName: 'CONTEXT.md', - includeDirectories: ['/src'], - sandbox: true, - excludeTools: ['toolA'], - allowMCPServers: ['server1'], - folderTrust: true, - dnsResolutionOrder: 'ipv4first', - excludedProjectEnvVars: ['SECRET'], - mcpServers: { - 'my-server': { - command: 'npm start', - }, - }, - unrecognizedTopLevel: { - value: 'should be preserved', - }, - }); - }); - - it('should handle partial v2 settings', () => { - const v2Settings: TestSettings = { - general: { - vimMode: false, - }, - ui: {}, - model: { - name: 'gemini-2.5-pro', - }, - unrecognized: 'value', - }; - - const v1Settings = migrateSettingsToV1(v2Settings); - - expect(v1Settings).toEqual({ - vimMode: false, - model: 'gemini-2.5-pro', - unrecognized: 'value', - }); - }); - - it('should handle settings with different data types', () => { - const v2Settings: TestSettings = { - general: { - vimMode: false, - }, - model: { - maxSessionTurns: -1, - }, - context: { - includeDirectories: [], - }, - security: { - folderTrust: { - enabled: undefined, - }, - }, - }; - - const v1Settings = migrateSettingsToV1(v2Settings); - - expect(v1Settings).toEqual({ - vimMode: false, - maxSessionTurns: -1, - includeDirectories: [], - security: { - folderTrust: { - enabled: undefined, - }, - }, - }); - }); - - it('should preserve unrecognized top-level keys', () => { - const v2Settings: TestSettings = { - general: { - vimMode: true, - }, - customTopLevel: { - a: 1, - b: [2], - }, - anotherOne: 'hello', - }; - - const v1Settings = migrateSettingsToV1(v2Settings); - - expect(v1Settings).toEqual({ - vimMode: true, - customTopLevel: { - a: 1, - b: [2], - }, - anotherOne: 'hello', - }); - }); - - it('should handle an empty v2 settings object', () => { - const v2Settings = {}; - const v1Settings = migrateSettingsToV1(v2Settings); - expect(v1Settings).toEqual({}); - }); - - it('should correctly handle mcpServers at the top level', () => { - const v2Settings: TestSettings = { - mcpServers: { - serverA: { command: 'a' }, - }, - mcp: { - allowed: ['serverA'], - }, - }; - - const v1Settings = migrateSettingsToV1(v2Settings); - - expect(v1Settings).toEqual({ - mcpServers: { - serverA: { command: 'a' }, - }, - allowMCPServers: ['serverA'], - }); - }); - - it('should correctly migrate customWittyPhrases', () => { - const v2Settings: Partial = { - ui: { - customWittyPhrases: ['test phrase'], - }, - }; - const v1Settings = migrateSettingsToV1(v2Settings as Settings); - expect(v1Settings).toEqual({ - customWittyPhrases: ['test phrase'], - }); - }); - }); - - describe('loadEnvironment', () => { - function setup({ - isFolderTrustEnabled = true, - isWorkspaceTrustedValue = true, - }) { - delete process.env['TESTTEST']; // reset - const geminiEnvPath = path.resolve(path.join(GEMINI_DIR, '.env')); - - vi.mocked(isWorkspaceTrusted).mockReturnValue({ - isTrusted: isWorkspaceTrustedValue, - source: 'file', - }); - (mockFsExistsSync as Mock).mockImplementation((p: fs.PathLike) => - [USER_SETTINGS_PATH, geminiEnvPath].includes(p.toString()), - ); - const userSettingsContent: Settings = { - ui: { - theme: 'dark', - }, - security: { - folderTrust: { - enabled: isFolderTrustEnabled, - }, - }, - context: { - fileName: 'USER_CONTEXT.md', - }, - }; - (fs.readFileSync as Mock).mockImplementation( - (p: fs.PathOrFileDescriptor) => { - if (p === USER_SETTINGS_PATH) - return JSON.stringify(userSettingsContent); - if (p === geminiEnvPath) return 'TESTTEST=1234'; - return '{}'; - }, - ); - } - - it('sets environment variables from .env files', () => { - setup({ isFolderTrustEnabled: false, isWorkspaceTrustedValue: true }); - loadEnvironment(loadSettings(MOCK_WORKSPACE_DIR).merged); - - expect(process.env['TESTTEST']).toEqual('1234'); - }); - - it('does not load env files from untrusted spaces', () => { - setup({ isFolderTrustEnabled: true, isWorkspaceTrustedValue: false }); - loadEnvironment(loadSettings(MOCK_WORKSPACE_DIR).merged); - - expect(process.env['TESTTEST']).not.toEqual('1234'); - }); - }); - - describe('needsMigration', () => { - it('should return false for an empty object', () => { - expect(needsMigration({})).toBe(false); - }); - - it('should return false for settings that are already in V2 format', () => { - const v2Settings: Partial = { - ui: { - theme: 'dark', - }, - tools: { - sandbox: true, - }, - }; - expect(needsMigration(v2Settings)).toBe(false); - }); - - it('should return true for settings with a V1 key that needs to be moved', () => { - const v1Settings = { - theme: 'dark', // v1 key - }; - expect(needsMigration(v1Settings)).toBe(true); - }); - - it('should return true for settings with a mix of V1 and V2 keys', () => { - const mixedSettings = { - theme: 'dark', // v1 key - tools: { - sandbox: true, // v2 key - }, - }; - expect(needsMigration(mixedSettings)).toBe(true); - }); - - it('should return false for settings with only V1 keys that are the same in V2', () => { - const v1Settings = { - mcpServers: {}, - telemetry: {}, - extensions: [], - }; - expect(needsMigration(v1Settings)).toBe(false); - }); - - it('should return true for settings with a mix of V1 keys that are the same in V2 and V1 keys that need moving', () => { - const v1Settings = { - mcpServers: {}, // same in v2 - theme: 'dark', // needs moving - }; - expect(needsMigration(v1Settings)).toBe(true); - }); - - it('should return false for settings with unrecognized keys', () => { - const settings = { - someUnrecognizedKey: 'value', - }; - expect(needsMigration(settings)).toBe(false); - }); - - it('should return false for settings with v2 keys and unrecognized keys', () => { - const settings = { - ui: { theme: 'dark' }, - someUnrecognizedKey: 'value', - }; - expect(needsMigration(settings)).toBe(false); - }); - }); - - describe('migrateDeprecatedSettings', () => { - let mockFsExistsSync: Mock; - let mockFsReadFileSync: Mock; - - beforeEach(() => { - vi.resetAllMocks(); - mockFsExistsSync = vi.mocked(fs.existsSync); - mockFsExistsSync.mockReturnValue(true); - mockFsReadFileSync = vi.mocked(fs.readFileSync); - mockFsReadFileSync.mockReturnValue('{}'); - vi.mocked(isWorkspaceTrusted).mockReturnValue({ - isTrusted: true, - source: undefined, - }); - }); - - afterEach(() => { - vi.restoreAllMocks(); - }); - - it('should migrate disabled extensions from user and workspace settings', () => { - const userSettingsContent = { - extensions: { - disabled: ['user-ext-1', 'shared-ext'], - }, - }; - const workspaceSettingsContent = { - extensions: { - disabled: ['workspace-ext-1', 'shared-ext'], - }, - }; - - mockFsReadFileSync.mockImplementation((p: fs.PathOrFileDescriptor) => { - if (p === USER_SETTINGS_PATH) - return JSON.stringify(userSettingsContent); - if (p === MOCK_WORKSPACE_SETTINGS_PATH) - return JSON.stringify(workspaceSettingsContent); - return '{}'; - }); - - const loadedSettings = loadSettings(MOCK_WORKSPACE_DIR); - const setValueSpy = vi.spyOn(loadedSettings, 'setValue'); - const extensionManager = new ExtensionManager({ - settings: loadedSettings.merged, - workspaceDir: MOCK_WORKSPACE_DIR, - requestConsent: vi.fn(), - requestSetting: vi.fn(), - }); - const mockDisableExtension = vi.spyOn( - extensionManager, - 'disableExtension', - ); - mockDisableExtension.mockImplementation(async () => {}); - - migrateDeprecatedSettings(loadedSettings, extensionManager); - - // Check user settings migration - expect(mockDisableExtension).toHaveBeenCalledWith( - 'user-ext-1', - SettingScope.User, - ); - expect(mockDisableExtension).toHaveBeenCalledWith( - 'shared-ext', - SettingScope.User, - ); - - // Check workspace settings migration - expect(mockDisableExtension).toHaveBeenCalledWith( - 'workspace-ext-1', - SettingScope.Workspace, - ); - expect(mockDisableExtension).toHaveBeenCalledWith( - 'shared-ext', - SettingScope.Workspace, - ); - - // Check that setValue was called to remove the deprecated setting - expect(setValueSpy).toHaveBeenCalledWith( - SettingScope.User, - 'extensions', - { - disabled: undefined, - }, - ); - expect(setValueSpy).toHaveBeenCalledWith( - SettingScope.Workspace, - 'extensions', - { - disabled: undefined, - }, - ); - }); - - it('should not do anything if there are no deprecated settings', () => { - const userSettingsContent = { - extensions: { - enabled: ['user-ext-1'], - }, - }; - const workspaceSettingsContent = { - someOtherSetting: 'value', - }; - - mockFsReadFileSync.mockImplementation((p: fs.PathOrFileDescriptor) => { - if (p === USER_SETTINGS_PATH) - return JSON.stringify(userSettingsContent); - if (p === MOCK_WORKSPACE_SETTINGS_PATH) - return JSON.stringify(workspaceSettingsContent); - return '{}'; - }); - - const loadedSettings = loadSettings(MOCK_WORKSPACE_DIR); - const setValueSpy = vi.spyOn(loadedSettings, 'setValue'); - const extensionManager = new ExtensionManager({ - settings: loadedSettings.merged, - workspaceDir: MOCK_WORKSPACE_DIR, - requestConsent: vi.fn(), - requestSetting: vi.fn(), - }); - const mockDisableExtension = vi.spyOn( - extensionManager, - 'disableExtension', - ); - mockDisableExtension.mockImplementation(async () => {}); - - migrateDeprecatedSettings(loadedSettings, extensionManager); - - expect(mockDisableExtension).not.toHaveBeenCalled(); - expect(setValueSpy).not.toHaveBeenCalled(); - }); - }); - describe('saveSettings', () => { it('should save settings using updateSettingsFilePreservingFormat', () => { const mockUpdateSettings = vi.mocked(updateSettingsFilePreservingFormat); diff --git a/packages/cli/src/config/settings.ts b/packages/cli/src/config/settings.ts index 43bdc1a627..07cc686524 100644 --- a/packages/cli/src/config/settings.ts +++ b/packages/cli/src/config/settings.ts @@ -10,7 +10,6 @@ import { platform } from 'node:os'; import * as dotenv from 'dotenv'; import process from 'node:process'; import { - debugLogger, FatalConfigError, GEMINI_DIR, getErrorMessage, @@ -32,14 +31,12 @@ import { getSettingsSchema, } from './settingsSchema.js'; import { resolveEnvVarsInObject } from '../utils/envVarResolver.js'; -import { customDeepMerge, type MergeableObject } from '../utils/deepMerge.js'; +import { customDeepMerge } from '../utils/deepMerge.js'; import { updateSettingsFilePreservingFormat } from '../utils/commentJson.js'; -import type { ExtensionManager } from './extension-manager.js'; import { validateSettings, formatValidationError, } from './settings-validation.js'; -import { SettingPaths } from './settingPaths.js'; function getMergeStrategyForPath(path: string[]): MergeStrategy | undefined { let current: SettingDefinition | undefined = undefined; @@ -68,79 +65,6 @@ export const USER_SETTINGS_PATH = Storage.getGlobalSettingsPath(); export const USER_SETTINGS_DIR = path.dirname(USER_SETTINGS_PATH); export const DEFAULT_EXCLUDED_ENV_VARS = ['DEBUG', 'DEBUG_MODE']; -const MIGRATE_V2_OVERWRITE = true; - -const MIGRATION_MAP: Record = { - accessibility: 'ui.accessibility', - allowedTools: 'tools.allowed', - allowMCPServers: 'mcp.allowed', - autoAccept: 'tools.autoAccept', - autoConfigureMaxOldSpaceSize: 'advanced.autoConfigureMemory', - bugCommand: 'advanced.bugCommand', - chatCompression: 'model.compressionThreshold', - checkpointing: 'general.checkpointing', - coreTools: 'tools.core', - contextFileName: 'context.fileName', - customThemes: 'ui.customThemes', - customWittyPhrases: 'ui.customWittyPhrases', - debugKeystrokeLogging: 'general.debugKeystrokeLogging', - disableAutoUpdate: 'general.disableAutoUpdate', - disableUpdateNag: 'general.disableUpdateNag', - dnsResolutionOrder: 'advanced.dnsResolutionOrder', - enableHooks: 'tools.enableHooks', - enablePromptCompletion: 'general.enablePromptCompletion', - enforcedAuthType: 'security.auth.enforcedType', - excludeTools: 'tools.exclude', - excludeMCPServers: 'mcp.excluded', - excludedProjectEnvVars: 'advanced.excludedEnvVars', - experimentalSkills: 'experimental.skills', - extensionManagement: 'experimental.extensionManagement', - extensions: 'extensions', - fileFiltering: 'context.fileFiltering', - folderTrustFeature: 'security.folderTrust.featureEnabled', - folderTrust: 'security.folderTrust.enabled', - hasSeenIdeIntegrationNudge: 'ide.hasSeenNudge', - hideWindowTitle: 'ui.hideWindowTitle', - showStatusInTitle: 'ui.showStatusInTitle', - hideTips: 'ui.hideTips', - hideBanner: 'ui.hideBanner', - hideFooter: 'ui.hideFooter', - hideCWD: 'ui.footer.hideCWD', - hideSandboxStatus: 'ui.footer.hideSandboxStatus', - hideModelInfo: 'ui.footer.hideModelInfo', - hideContextSummary: 'ui.hideContextSummary', - showMemoryUsage: 'ui.showMemoryUsage', - showLineNumbers: 'ui.showLineNumbers', - showCitations: 'ui.showCitations', - ideMode: 'ide.enabled', - includeDirectories: 'context.includeDirectories', - loadMemoryFromIncludeDirectories: 'context.loadFromIncludeDirectories', - maxSessionTurns: 'model.maxSessionTurns', - mcpServers: 'mcpServers', - mcpServerCommand: 'mcp.serverCommand', - memoryImportFormat: 'context.importFormat', - memoryDiscoveryMaxDirs: 'context.discoveryMaxDirs', - model: 'model.name', - preferredEditor: SettingPaths.General.PreferredEditor, - retryFetchErrors: 'general.retryFetchErrors', - sandbox: 'tools.sandbox', - selectedAuthType: 'security.auth.selectedType', - enableInteractiveShell: 'tools.shell.enableInteractiveShell', - shellPager: 'tools.shell.pager', - shellShowColor: 'tools.shell.showColor', - shellInactivityTimeout: 'tools.shell.inactivityTimeout', - skipNextSpeakerCheck: 'model.skipNextSpeakerCheck', - summarizeToolOutput: 'model.summarizeToolOutput', - telemetry: 'telemetry', - theme: 'ui.theme', - toolDiscoveryCommand: 'tools.discoveryCommand', - toolCallCommand: 'tools.callCommand', - usageStatisticsEnabled: 'privacy.usageStatisticsEnabled', - useExternalAuth: 'security.auth.useExternal', - useRipgrep: 'tools.useRipgrep', - vimMode: 'general.vimMode', -}; - export function getSystemSettingsPath(): string { if (process.env['GEMINI_CLI_SYSTEM_SETTINGS_PATH']) { return process.env['GEMINI_CLI_SYSTEM_SETTINGS_PATH']; @@ -270,162 +194,6 @@ function setNestedProperty( current[lastKey] = value; } -export function needsMigration(settings: Record): boolean { - // A file needs migration if it contains any top-level key that is moved to a - // nested location in V2. - const hasV1Keys = Object.entries(MIGRATION_MAP).some(([v1Key, v2Path]) => { - if (v1Key === v2Path || !(v1Key in settings)) { - return false; - } - // If a key exists that is a V1 key and a V2 container (like 'model'), - // we need to check the type. If it's an object, it's a V2 container and not - // a V1 key that needs migration. - if ( - KNOWN_V2_CONTAINERS.has(v1Key) && - typeof settings[v1Key] === 'object' && - settings[v1Key] !== null - ) { - return false; - } - return true; - }); - - return hasV1Keys; -} - -function migrateSettingsToV2( - flatSettings: Record, -): Record | null { - if (!needsMigration(flatSettings)) { - return null; - } - - const v2Settings: Record = {}; - const flatKeys = new Set(Object.keys(flatSettings)); - - for (const [oldKey, newPath] of Object.entries(MIGRATION_MAP)) { - if (flatKeys.has(oldKey)) { - // If the key exists and is a V2 container (like 'model'), and the value is an object, - // it is likely already migrated or partially migrated. We should not move it - // to the mapped V2 path (e.g. 'model' -> 'model.name'). - // Instead, let it fall through to the "Carry over" section to be merged. - if ( - KNOWN_V2_CONTAINERS.has(oldKey) && - typeof flatSettings[oldKey] === 'object' && - flatSettings[oldKey] !== null && - !Array.isArray(flatSettings[oldKey]) - ) { - continue; - } - - setNestedProperty(v2Settings, newPath, flatSettings[oldKey]); - flatKeys.delete(oldKey); - } - } - - // Preserve mcpServers at the top level - if (flatSettings['mcpServers']) { - v2Settings['mcpServers'] = flatSettings['mcpServers']; - flatKeys.delete('mcpServers'); - } - - // Carry over any unrecognized keys - for (const remainingKey of flatKeys) { - const existingValue = v2Settings[remainingKey]; - const newValue = flatSettings[remainingKey]; - - if ( - typeof existingValue === 'object' && - existingValue !== null && - !Array.isArray(existingValue) && - typeof newValue === 'object' && - newValue !== null && - !Array.isArray(newValue) - ) { - const pathAwareGetStrategy = (path: string[]) => - getMergeStrategyForPath([remainingKey, ...path]); - v2Settings[remainingKey] = customDeepMerge( - pathAwareGetStrategy, - {}, - existingValue as MergeableObject, - newValue as MergeableObject, - ); - } else { - v2Settings[remainingKey] = newValue; - } - } - - return v2Settings; -} - -function getNestedProperty( - obj: Record, - path: string, -): unknown { - const keys = path.split('.'); - let current: unknown = obj; - for (const key of keys) { - if (typeof current !== 'object' || current === null || !(key in current)) { - return undefined; - } - current = (current as Record)[key]; - } - return current; -} - -const REVERSE_MIGRATION_MAP: Record = Object.fromEntries( - Object.entries(MIGRATION_MAP).map(([key, value]) => [value, key]), -); - -// Dynamically determine the top-level keys from the V2 settings structure. -const KNOWN_V2_CONTAINERS = new Set( - Object.values(MIGRATION_MAP).map((path) => path.split('.')[0]), -); - -export function migrateSettingsToV1( - v2Settings: Record, -): Record { - const v1Settings: Record = {}; - const v2Keys = new Set(Object.keys(v2Settings)); - - for (const [newPath, oldKey] of Object.entries(REVERSE_MIGRATION_MAP)) { - const value = getNestedProperty(v2Settings, newPath); - if (value !== undefined) { - v1Settings[oldKey] = value; - v2Keys.delete(newPath.split('.')[0]); - } - } - - // Preserve mcpServers at the top level - if (v2Settings['mcpServers']) { - v1Settings['mcpServers'] = v2Settings['mcpServers']; - v2Keys.delete('mcpServers'); - } - - // Carry over any unrecognized keys - for (const remainingKey of v2Keys) { - const value = v2Settings[remainingKey]; - if (value === undefined) { - continue; - } - - // Don't carry over empty objects that were just containers for migrated settings. - if ( - KNOWN_V2_CONTAINERS.has(remainingKey) && - typeof value === 'object' && - value !== null && - !Array.isArray(value) && - Object.keys(value).length === 0 - ) { - continue; - } - - v1Settings[remainingKey] = value; - } - - return v1Settings; -} - export function getDefaultsFromSchema( schema: SettingsSchema = getSettingsSchema(), ): Settings { @@ -478,7 +246,6 @@ export class LoadedSettings { user: SettingsFile, workspace: SettingsFile, isTrusted: boolean, - migratedInMemoryScopes: Set, errors: SettingsError[] = [], ) { this.system = system; @@ -486,7 +253,6 @@ export class LoadedSettings { this.user = user; this.workspace = workspace; this.isTrusted = isTrusted; - this.migratedInMemoryScopes = migratedInMemoryScopes; this.errors = errors; this._merged = this.computeMergedSettings(); } @@ -496,7 +262,6 @@ export class LoadedSettings { readonly user: SettingsFile; readonly workspace: SettingsFile; readonly isTrusted: boolean; - readonly migratedInMemoryScopes: Set; readonly errors: SettingsError[]; private _merged: Settings; @@ -690,7 +455,6 @@ export function loadSettings( const settingsErrors: SettingsError[] = []; const systemSettingsPath = getSystemSettingsPath(); const systemDefaultsPath = getSystemDefaultsPath(); - const migratedInMemoryScopes = new Set(); // Resolve paths to their canonical representation to handle symlinks const resolvedWorkspaceDir = path.resolve(workspaceDir); @@ -711,10 +475,7 @@ export function loadSettings( workspaceDir, ).getWorkspaceSettingsPath(); - const loadAndMigrate = ( - filePath: string, - scope: SettingScope, - ): { settings: Settings; rawJson?: string } => { + const load = (filePath: string): { settings: Settings; rawJson?: string } => { try { if (fs.existsSync(filePath)) { const content = fs.readFileSync(filePath, 'utf-8'); @@ -733,33 +494,9 @@ export function loadSettings( return { settings: {} }; } - let settingsObject = rawSettings as Record; - if (needsMigration(settingsObject)) { - const migratedSettings = migrateSettingsToV2(settingsObject); - if (migratedSettings) { - if (MIGRATE_V2_OVERWRITE) { - try { - fs.renameSync(filePath, `${filePath}.orig`); - fs.writeFileSync( - filePath, - JSON.stringify(migratedSettings, null, 2), - 'utf-8', - ); - } catch (e) { - coreEvents.emitFeedback( - 'error', - 'Failed to migrate settings file.', - e, - ); - } - } else { - migratedInMemoryScopes.add(scope); - } - settingsObject = migratedSettings; - } - } + const settingsObject = rawSettings as Record; - // Validate settings structure with Zod after migration + // Validate settings structure with Zod const validationResult = validateSettings(settingsObject); if (!validationResult.success && validationResult.error) { const errorMessage = formatValidationError( @@ -785,22 +522,16 @@ export function loadSettings( return { settings: {} }; }; - const systemResult = loadAndMigrate(systemSettingsPath, SettingScope.System); - const systemDefaultsResult = loadAndMigrate( - systemDefaultsPath, - SettingScope.SystemDefaults, - ); - const userResult = loadAndMigrate(USER_SETTINGS_PATH, SettingScope.User); + const systemResult = load(systemSettingsPath); + const systemDefaultsResult = load(systemDefaultsPath); + const userResult = load(USER_SETTINGS_PATH); let workspaceResult: { settings: Settings; rawJson?: string } = { settings: {} as Settings, rawJson: undefined, }; if (realWorkspaceDir !== realHomeDir) { - workspaceResult = loadAndMigrate( - workspaceSettingsPath, - SettingScope.Workspace, - ); + workspaceResult = load(workspaceSettingsPath); } const systemOriginalSettings = structuredClone(systemResult.settings); @@ -888,37 +619,10 @@ export function loadSettings( rawJson: workspaceResult.rawJson, }, isTrusted, - migratedInMemoryScopes, settingsErrors, ); } -export function migrateDeprecatedSettings( - loadedSettings: LoadedSettings, - extensionManager: ExtensionManager, -): void { - const processScope = (scope: LoadableSettingScope) => { - const settings = loadedSettings.forScope(scope).settings; - if (settings.extensions?.disabled) { - debugLogger.log( - `Migrating deprecated extensions.disabled settings from ${scope} settings...`, - ); - for (const extension of settings.extensions.disabled ?? []) { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - extensionManager.disableExtension(extension, scope); - } - - const newExtensionsValue = { ...settings.extensions }; - newExtensionsValue.disabled = undefined; - - loadedSettings.setValue(scope, 'extensions', newExtensionsValue); - } - }; - - processScope(SettingScope.User); - processScope(SettingScope.Workspace); -} - export function saveSettings(settingsFile: SettingsFile): void { try { // Ensure the directory exists @@ -927,12 +631,7 @@ export function saveSettings(settingsFile: SettingsFile): void { fs.mkdirSync(dirPath, { recursive: true }); } - let settingsToSave = settingsFile.originalSettings; - if (!MIGRATE_V2_OVERWRITE) { - settingsToSave = migrateSettingsToV1( - settingsToSave as Record, - ) as Settings; - } + const settingsToSave = settingsFile.originalSettings; // Use the format-preserving update function updateSettingsFilePreservingFormat( diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index 5dac29630b..32284b132d 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -20,11 +20,7 @@ import { loadTrustedFolders, type TrustedFoldersError, } from './config/trustedFolders.js'; -import { - loadSettings, - migrateDeprecatedSettings, - SettingScope, -} from './config/settings.js'; +import { loadSettings, SettingScope } from './config/settings.js'; import { getStartupWarnings } from './utils/startupWarnings.js'; import { getUserStartupWarnings } from './utils/userStartupWarnings.js'; import { ConsolePatcher } from './ui/utils/ConsolePatcher.js'; @@ -93,9 +89,7 @@ import { } from './utils/relaunch.js'; import { loadSandboxConfig } from './config/sandboxConfig.js'; import { deleteSession, listSessions } from './utils/sessions.js'; -import { ExtensionManager } from './config/extension-manager.js'; import { createPolicyUpdater } from './config/policy.js'; -import { requestConsentNonInteractive } from './config/extensions/consent.js'; import { ScrollProvider } from './ui/contexts/ScrollProvider.js'; import { isAlternateBufferEnabled } from './ui/hooks/useAlternateBuffer.js'; @@ -315,19 +309,6 @@ export async function main() { ); }); - const migrateHandle = startupProfiler.start('migrate_settings'); - migrateDeprecatedSettings( - settings, - // Temporary extension manager only used during this non-interactive UI phase. - new ExtensionManager({ - workspaceDir: process.cwd(), - settings: settings.merged, - enabledExtensionOverrides: [], - requestConsent: requestConsentNonInteractive, - requestSetting: null, - }), - ); - migrateHandle?.end(); await cleanupCheckpoints(); const parseArgsHandle = startupProfiler.start('parse_arguments'); diff --git a/packages/cli/src/test-utils/render.tsx b/packages/cli/src/test-utils/render.tsx index d02b5af8ae..e083918683 100644 --- a/packages/cli/src/test-utils/render.tsx +++ b/packages/cli/src/test-utils/render.tsx @@ -109,7 +109,7 @@ export const mockSettings = new LoadedSettings( { path: '', settings: {}, originalSettings: {} }, { path: '', settings: {}, originalSettings: {} }, true, - new Set(), + [], ); export const createMockSettings = ( @@ -122,7 +122,7 @@ export const createMockSettings = ( { path: '', settings, originalSettings: settings }, { path: '', settings: {}, originalSettings: {} }, true, - new Set(), + [], ); }; diff --git a/packages/cli/src/ui/App.test.tsx b/packages/cli/src/ui/App.test.tsx index 64f42fae11..1a8851685a 100644 --- a/packages/cli/src/ui/App.test.tsx +++ b/packages/cli/src/ui/App.test.tsx @@ -14,11 +14,7 @@ import { StreamingState } from './types.js'; import { ConfigContext } from './contexts/ConfigContext.js'; import { AppContext, type AppState } from './contexts/AppContext.js'; import { SettingsContext } from './contexts/SettingsContext.js'; -import { - type SettingScope, - LoadedSettings, - type SettingsFile, -} from '../config/settings.js'; +import { LoadedSettings, type SettingsFile } from '../config/settings.js'; vi.mock('ink', async (importOriginal) => { const original = await importOriginal(); @@ -92,7 +88,7 @@ describe('App', () => { mockSettingsFile, mockSettingsFile, true, - new Set(), + [], ); const mockAppState: AppState = { diff --git a/packages/cli/src/ui/components/SettingsDialog.test.tsx b/packages/cli/src/ui/components/SettingsDialog.test.tsx index d33130744a..78bd5a3917 100644 --- a/packages/cli/src/ui/components/SettingsDialog.test.tsx +++ b/packages/cli/src/ui/components/SettingsDialog.test.tsx @@ -104,7 +104,7 @@ const createMockSettings = ( path: '/workspace/settings.json', }, true, - new Set(), + [], ); vi.mock('../../config/settingsSchema.js', async (importOriginal) => { diff --git a/packages/cli/src/ui/components/ThemeDialog.test.tsx b/packages/cli/src/ui/components/ThemeDialog.test.tsx index ef2306c122..bcfeb5a9c9 100644 --- a/packages/cli/src/ui/components/ThemeDialog.test.tsx +++ b/packages/cli/src/ui/components/ThemeDialog.test.tsx @@ -51,7 +51,7 @@ const createMockSettings = ( path: '/workspace/settings.json', }, true, - new Set(), + [], ); describe('ThemeDialog Snapshots', () => { diff --git a/packages/cli/src/ui/utils/CodeColorizer.test.tsx b/packages/cli/src/ui/utils/CodeColorizer.test.tsx index 641567c00b..94913c88bf 100644 --- a/packages/cli/src/ui/utils/CodeColorizer.test.tsx +++ b/packages/cli/src/ui/utils/CodeColorizer.test.tsx @@ -24,7 +24,7 @@ describe('colorizeCode', () => { }, { path: '', settings: {}, originalSettings: {} }, true, - new Set(), + [], ); const result = colorizeCode({ diff --git a/packages/cli/src/ui/utils/MarkdownDisplay.test.tsx b/packages/cli/src/ui/utils/MarkdownDisplay.test.tsx index 927a69e154..bfb81e6519 100644 --- a/packages/cli/src/ui/utils/MarkdownDisplay.test.tsx +++ b/packages/cli/src/ui/utils/MarkdownDisplay.test.tsx @@ -198,7 +198,7 @@ Another paragraph. }, { path: '', settings: {}, originalSettings: {} }, true, - new Set(), + [], ); const { lastFrame } = renderWithProviders( From c87d1aed4c5ad90dcff551a0eeb150f8994a9feb Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Fri, 9 Jan 2026 23:05:27 +0000 Subject: [PATCH 105/713] Fix an issue where the agent stops prematurely (#16269) --- .../src/ui/hooks/useQuotaAndFallback.test.ts | 22 +++--- .../cli/src/ui/hooks/useQuotaAndFallback.ts | 32 ++++---- .../availability/fallbackIntegration.test.ts | 78 +++++++++++++++++++ packages/core/src/config/config.ts | 3 +- .../core/src/config/flashFallback.test.ts | 7 +- .../core/src/core/loggingContentGenerator.ts | 1 + 6 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 packages/core/src/availability/fallbackIntegration.test.ts diff --git a/packages/cli/src/ui/hooks/useQuotaAndFallback.test.ts b/packages/cli/src/ui/hooks/useQuotaAndFallback.test.ts index 60064957e8..5ea4e2a84e 100644 --- a/packages/cli/src/ui/hooks/useQuotaAndFallback.test.ts +++ b/packages/cli/src/ui/hooks/useQuotaAndFallback.test.ts @@ -70,6 +70,7 @@ describe('useQuotaAndFallback', () => { setFallbackHandlerSpy = vi.spyOn(mockConfig, 'setFallbackModelHandler'); vi.spyOn(mockConfig, 'setQuotaErrorOccurred'); vi.spyOn(mockConfig, 'setModel'); + vi.spyOn(mockConfig, 'setActiveModel'); }); afterEach(() => { @@ -164,8 +165,8 @@ describe('useQuotaAndFallback', () => { const intent = await promise!; expect(intent).toBe('retry_always'); - // Verify setModel was called with isFallbackModel=true - expect(mockConfig.setModel).toHaveBeenCalledWith('gemini-flash', true); + // Verify setActiveModel was called + expect(mockConfig.setActiveModel).toHaveBeenCalledWith('gemini-flash'); // The pending request should be cleared from the state expect(result.current.proQuotaRequest).toBeNull(); @@ -278,8 +279,8 @@ describe('useQuotaAndFallback', () => { const intent = await promise!; expect(intent).toBe('retry_always'); - // Verify setModel was called with isFallbackModel=true - expect(mockConfig.setModel).toHaveBeenCalledWith('model-B', true); + // Verify setActiveModel was called + expect(mockConfig.setActiveModel).toHaveBeenCalledWith('model-B'); // The pending request should be cleared from the state expect(result.current.proQuotaRequest).toBeNull(); @@ -336,10 +337,9 @@ To disable gemini-3-pro-preview, disable "Preview features" in /settings.`, const intent = await promise!; expect(intent).toBe('retry_always'); - // Verify setModel was called with isFallbackModel=true - expect(mockConfig.setModel).toHaveBeenCalledWith( + // Verify setActiveModel was called + expect(mockConfig.setActiveModel).toHaveBeenCalledWith( 'gemini-2.5-pro', - true, ); expect(result.current.proQuotaRequest).toBeNull(); @@ -425,8 +425,12 @@ To disable gemini-3-pro-preview, disable "Preview features" in /settings.`, expect(intent).toBe('retry_always'); expect(result.current.proQuotaRequest).toBeNull(); - // Verify setModel was called with isFallbackModel=true - expect(mockConfig.setModel).toHaveBeenCalledWith('gemini-flash', true); + // Verify setActiveModel was called + expect(mockConfig.setActiveModel).toHaveBeenCalledWith('gemini-flash'); + + // Verify quota error flags are reset + expect(mockSetModelSwitchedFromQuotaError).toHaveBeenCalledWith(false); + expect(mockConfig.setQuotaErrorOccurred).toHaveBeenCalledWith(false); // Check for the "Switched to fallback model" message expect(mockHistoryManager.addItem).toHaveBeenCalledTimes(1); diff --git a/packages/cli/src/ui/hooks/useQuotaAndFallback.ts b/packages/cli/src/ui/hooks/useQuotaAndFallback.ts index eb53513fdc..d83b082950 100644 --- a/packages/cli/src/ui/hooks/useQuotaAndFallback.ts +++ b/packages/cli/src/ui/hooks/useQuotaAndFallback.ts @@ -129,21 +129,27 @@ export function useQuotaAndFallback({ setProQuotaRequest(null); isDialogPending.current = false; // Reset the flag here - if (choice === 'retry_always') { - // Set the model to the fallback model for the current session. - // This ensures the Footer updates and future turns use this model. - // The change is not persisted, so the original model is restored on restart. - config.activateFallbackMode(proQuotaRequest.fallbackModel); - historyManager.addItem( - { - type: MessageType.INFO, - text: `Switched to fallback model ${proQuotaRequest.fallbackModel}`, - }, - Date.now(), - ); + if (choice === 'retry_always' || choice === 'retry_once') { + // Reset quota error flags to allow the agent loop to continue. + setModelSwitchedFromQuotaError(false); + config.setQuotaErrorOccurred(false); + + if (choice === 'retry_always') { + // Set the model to the fallback model for the current session. + // This ensures the Footer updates and future turns use this model. + // The change is not persisted, so the original model is restored on restart. + config.activateFallbackMode(proQuotaRequest.fallbackModel); + historyManager.addItem( + { + type: MessageType.INFO, + text: `Switched to fallback model ${proQuotaRequest.fallbackModel}`, + }, + Date.now(), + ); + } } }, - [proQuotaRequest, historyManager, config], + [proQuotaRequest, historyManager, config, setModelSwitchedFromQuotaError], ); return { diff --git a/packages/core/src/availability/fallbackIntegration.test.ts b/packages/core/src/availability/fallbackIntegration.test.ts new file mode 100644 index 0000000000..39cbe2e0b4 --- /dev/null +++ b/packages/core/src/availability/fallbackIntegration.test.ts @@ -0,0 +1,78 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { applyModelSelection } from './policyHelpers.js'; +import type { Config } from '../config/config.js'; +import { + PREVIEW_GEMINI_MODEL, + PREVIEW_GEMINI_FLASH_MODEL, + PREVIEW_GEMINI_MODEL_AUTO, +} from '../config/models.js'; +import { ModelAvailabilityService } from './modelAvailabilityService.js'; +import { ModelConfigService } from '../services/modelConfigService.js'; +import { DEFAULT_MODEL_CONFIGS } from '../config/defaultModelConfigs.js'; + +describe('Fallback Integration', () => { + let config: Config; + let availabilityService: ModelAvailabilityService; + let modelConfigService: ModelConfigService; + + beforeEach(() => { + // Mocking Config because it has many dependencies + config = { + getModel: () => PREVIEW_GEMINI_MODEL_AUTO, + getActiveModel: () => PREVIEW_GEMINI_MODEL_AUTO, + setActiveModel: vi.fn(), + getPreviewFeatures: () => true, // Preview enabled for Gemini 3 + getUserTier: () => undefined, + getModelAvailabilityService: () => availabilityService, + modelConfigService: undefined as unknown as ModelConfigService, + } as unknown as Config; + + availabilityService = new ModelAvailabilityService(); + modelConfigService = new ModelConfigService(DEFAULT_MODEL_CONFIGS); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (config as any).modelConfigService = modelConfigService; + }); + + it('should select fallback model when primary model is terminal and config is in AUTO mode', () => { + // 1. Simulate "Pro" failing with a terminal quota error + // The policy chain for PREVIEW_GEMINI_MODEL_AUTO is [PREVIEW_GEMINI_MODEL, PREVIEW_GEMINI_FLASH_MODEL] + availabilityService.markTerminal(PREVIEW_GEMINI_MODEL, 'quota'); + + // 2. Request "Pro" explicitly (as Agent would) + const requestedModel = PREVIEW_GEMINI_MODEL; + + // 3. Apply model selection + const result = applyModelSelection(config, { model: requestedModel }); + + // 4. Expect fallback to Flash + expect(result.model).toBe(PREVIEW_GEMINI_FLASH_MODEL); + + // 5. Expect active model to be updated + expect(config.setActiveModel).toHaveBeenCalledWith( + PREVIEW_GEMINI_FLASH_MODEL, + ); + }); + + it('should NOT fallback if config is NOT in AUTO mode', () => { + // 1. Config is explicitly set to Pro, not Auto + vi.spyOn(config, 'getModel').mockReturnValue(PREVIEW_GEMINI_MODEL); + + // 2. Simulate "Pro" failing + availabilityService.markTerminal(PREVIEW_GEMINI_MODEL, 'quota'); + + // 3. Request "Pro" + const requestedModel = PREVIEW_GEMINI_MODEL; + + // 4. Apply model selection + const result = applyModelSelection(config, { model: requestedModel }); + + // 5. Expect it to stay on Pro (because single model chain) + expect(result.model).toBe(PREVIEW_GEMINI_MODEL); + }); +}); diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index f877a2e797..6fb07754ec 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -939,7 +939,8 @@ export class Config { } activateFallbackMode(model: string): void { - this.setModel(model, true); + this.setActiveModel(model); + coreEvents.emitModelChanged(model); const authType = this.getContentGeneratorConfig()?.authType; if (authType) { logFlashFallback(this, new FlashFallbackEvent(authType)); diff --git a/packages/core/src/config/flashFallback.test.ts b/packages/core/src/config/flashFallback.test.ts index 320d69c565..96adf37655 100644 --- a/packages/core/src/config/flashFallback.test.ts +++ b/packages/core/src/config/flashFallback.test.ts @@ -65,9 +65,12 @@ describe('Flash Model Fallback Configuration', () => { }); describe('activateFallbackMode', () => { - it('should set model to fallback and log event', () => { + it('should set active model to fallback and log event', () => { config.activateFallbackMode(DEFAULT_GEMINI_FLASH_MODEL); - expect(config.getModel()).toBe(DEFAULT_GEMINI_FLASH_MODEL); + expect(config.getActiveModel()).toBe(DEFAULT_GEMINI_FLASH_MODEL); + // Ensure the persisted model setting is NOT changed (to preserve AUTO behavior) + expect(config.getModel()).toBe(DEFAULT_GEMINI_MODEL); + expect(logFlashFallback).toHaveBeenCalledWith( config, expect.any(FlashFallbackEvent), diff --git a/packages/core/src/core/loggingContentGenerator.ts b/packages/core/src/core/loggingContentGenerator.ts index b8cf49a091..e559846366 100644 --- a/packages/core/src/core/loggingContentGenerator.ts +++ b/packages/core/src/core/loggingContentGenerator.ts @@ -195,6 +195,7 @@ export class LoggingContentGenerator implements ContentGenerator { req.config, serverDetails, ); + try { const response = await this.wrapped.generateContent( req, From b08b0d715b55559fbf484bfeed6e0aa2aab50a42 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 9 Jan 2026 15:38:11 -0800 Subject: [PATCH 106/713] Update system prompt to prefer non-interactive commands (#16117) --- .../core/__snapshots__/prompts.test.ts.snap | 50 +++++++++---------- packages/core/src/core/prompts.ts | 4 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/core/src/core/__snapshots__/prompts.test.ts.snap b/packages/core/src/core/__snapshots__/prompts.test.ts.snap index f8dd7ead06..0a54e9f19d 100644 --- a/packages/core/src/core/__snapshots__/prompts.test.ts.snap +++ b/packages/core/src/core/__snapshots__/prompts.test.ts.snap @@ -25,7 +25,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -79,7 +79,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). - **Command Execution:** Use the 'run_shell_command' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. - **Remembering Facts:** Use the 'save_memory' tool to remember specific, *user-related* facts or preferences when the user explicitly asks, or when they state a clear, concise piece of information that would help personalize or streamline *your future interactions with them* (e.g., preferred coding style, common project paths they use, personal tool aliases). This tool is for user-specific information that should persist across sessions. Do *not* use it for general project context or information. If unsure whether to save something, you can ask the user, "Should I remember that for you?" - **Respect User Confirmations:** Most tool calls (also denoted as 'function calls') will first require confirmation from the user, where they will either approve or cancel the function call. If a user cancels a function call, respect their choice and do _not_ try to make the function call again. It is okay to request the tool call again _only_ if the user requests that same tool call on a subsequent prompt. When a user cancels a function call, assume best intentions from the user and consider inquiring if they prefer any alternative paths forward. @@ -129,7 +129,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -225,7 +225,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, 1. **Understand & Strategize:** Think about the user's request and the relevant codebase context. When the task involves **complex refactoring, codebase exploration or system-wide analysis**, your **first and primary action** must be to delegate to the 'codebase_investigator' agent using the 'delegate_to_agent' tool. Use it to build a comprehensive understanding of the code, its structure, and dependencies. For **simple, targeted searches** (like finding a specific function name, file path, or variable declaration), you should use 'search_file_content' or 'glob' directly. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. If 'codebase_investigator' was used, do not ignore the output of the agent, you must use it as the foundation of your plan. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -321,7 +321,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -375,7 +375,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). - **Command Execution:** Use the 'run_shell_command' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. - **Remembering Facts:** Use the 'save_memory' tool to remember specific, *user-related* facts or preferences when the user explicitly asks, or when they state a clear, concise piece of information that would help personalize or streamline *your future interactions with them* (e.g., preferred coding style, common project paths they use, personal tool aliases). This tool is for user-specific information that should persist across sessions. Do *not* use it for general project context or information. If unsure whether to save something, you can ask the user, "Should I remember that for you?" - **Respect User Confirmations:** Most tool calls (also denoted as 'function calls') will first require confirmation from the user, where they will either approve or cancel the function call. If a user cancels a function call, respect their choice and do _not_ try to make the function call again. It is okay to request the tool call again _only_ if the user requests that same tool call on a subsequent prompt. When a user cancels a function call, assume best intentions from the user and consider inquiring if they prefer any alternative paths forward. @@ -419,7 +419,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -473,7 +473,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). - **Command Execution:** Use the 'run_shell_command' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. - **Remembering Facts:** Use the 'save_memory' tool to remember specific, *user-related* facts or preferences when the user explicitly asks, or when they state a clear, concise piece of information that would help personalize or streamline *your future interactions with them* (e.g., preferred coding style, common project paths they use, personal tool aliases). This tool is for user-specific information that should persist across sessions. Do *not* use it for general project context or information. If unsure whether to save something, you can ask the user, "Should I remember that for you?" - **Respect User Confirmations:** Most tool calls (also denoted as 'function calls') will first require confirmation from the user, where they will either approve or cancel the function call. If a user cancels a function call, respect their choice and do _not_ try to make the function call again. It is okay to request the tool call again _only_ if the user requests that same tool call on a subsequent prompt. When a user cancels a function call, assume best intentions from the user and consider inquiring if they prefer any alternative paths forward. @@ -545,7 +545,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -599,7 +599,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). - **Command Execution:** Use the 'run_shell_command' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. - **Remembering Facts:** Use the 'save_memory' tool to remember specific, *user-related* facts or preferences when the user explicitly asks, or when they state a clear, concise piece of information that would help personalize or streamline *your future interactions with them* (e.g., preferred coding style, common project paths they use, personal tool aliases). This tool is for user-specific information that should persist across sessions. Do *not* use it for general project context or information. If unsure whether to save something, you can ask the user, "Should I remember that for you?" - **Respect User Confirmations:** Most tool calls (also denoted as 'function calls') will first require confirmation from the user, where they will either approve or cancel the function call. If a user cancels a function call, respect their choice and do _not_ try to make the function call again. It is okay to request the tool call again _only_ if the user requests that same tool call on a subsequent prompt. When a user cancels a function call, assume best intentions from the user and consider inquiring if they prefer any alternative paths forward. @@ -643,7 +643,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -697,7 +697,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). - **Command Execution:** Use the 'run_shell_command' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. - **Remembering Facts:** Use the 'save_memory' tool to remember specific, *user-related* facts or preferences when the user explicitly asks, or when they state a clear, concise piece of information that would help personalize or streamline *your future interactions with them* (e.g., preferred coding style, common project paths they use, personal tool aliases). This tool is for user-specific information that should persist across sessions. Do *not* use it for general project context or information. If unsure whether to save something, you can ask the user, "Should I remember that for you?" - **Respect User Confirmations:** Most tool calls (also denoted as 'function calls') will first require confirmation from the user, where they will either approve or cancel the function call. If a user cancels a function call, respect their choice and do _not_ try to make the function call again. It is okay to request the tool call again _only_ if the user requests that same tool call on a subsequent prompt. When a user cancels a function call, assume best intentions from the user and consider inquiring if they prefer any alternative paths forward. @@ -741,7 +741,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -795,7 +795,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). - **Command Execution:** Use the 'run_shell_command' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. - **Remembering Facts:** Use the 'save_memory' tool to remember specific, *user-related* facts or preferences when the user explicitly asks, or when they state a clear, concise piece of information that would help personalize or streamline *your future interactions with them* (e.g., preferred coding style, common project paths they use, personal tool aliases). This tool is for user-specific information that should persist across sessions. Do *not* use it for general project context or information. If unsure whether to save something, you can ask the user, "Should I remember that for you?" - **Respect User Confirmations:** Most tool calls (also denoted as 'function calls') will first require confirmation from the user, where they will either approve or cancel the function call. If a user cancels a function call, respect their choice and do _not_ try to make the function call again. It is okay to request the tool call again _only_ if the user requests that same tool call on a subsequent prompt. When a user cancels a function call, assume best intentions from the user and consider inquiring if they prefer any alternative paths forward. @@ -839,7 +839,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -893,7 +893,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). - **Command Execution:** Use the 'run_shell_command' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. - **Remembering Facts:** Use the 'save_memory' tool to remember specific, *user-related* facts or preferences when the user explicitly asks, or when they state a clear, concise piece of information that would help personalize or streamline *your future interactions with them* (e.g., preferred coding style, common project paths they use, personal tool aliases). This tool is for user-specific information that should persist across sessions. Do *not* use it for general project context or information. If unsure whether to save something, you can ask the user, "Should I remember that for you?" - **Respect User Confirmations:** Most tool calls (also denoted as 'function calls') will first require confirmation from the user, where they will either approve or cancel the function call. If a user cancels a function call, respect their choice and do _not_ try to make the function call again. It is okay to request the tool call again _only_ if the user requests that same tool call on a subsequent prompt. When a user cancels a function call, assume best intentions from the user and consider inquiring if they prefer any alternative paths forward. @@ -937,7 +937,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -991,7 +991,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). - **Command Execution:** Use the 'run_shell_command' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. - **Remembering Facts:** Use the 'save_memory' tool to remember specific, *user-related* facts or preferences when the user explicitly asks, or when they state a clear, concise piece of information that would help personalize or streamline *your future interactions with them* (e.g., preferred coding style, common project paths they use, personal tool aliases). This tool is for user-specific information that should persist across sessions. Do *not* use it for general project context or information. If unsure whether to save something, you can ask the user, "Should I remember that for you?" - **Respect User Confirmations:** Most tool calls (also denoted as 'function calls') will first require confirmation from the user, where they will either approve or cancel the function call. If a user cancels a function call, respect their choice and do _not_ try to make the function call again. It is okay to request the tool call again _only_ if the user requests that same tool call on a subsequent prompt. When a user cancels a function call, assume best intentions from the user and consider inquiring if they prefer any alternative paths forward. @@ -1035,7 +1035,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -1089,7 +1089,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). - **Command Execution:** Use the 'run_shell_command' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. - **Remembering Facts:** Use the 'save_memory' tool to remember specific, *user-related* facts or preferences when the user explicitly asks, or when they state a clear, concise piece of information that would help personalize or streamline *your future interactions with them* (e.g., preferred coding style, common project paths they use, personal tool aliases). This tool is for user-specific information that should persist across sessions. Do *not* use it for general project context or information. If unsure whether to save something, you can ask the user, "Should I remember that for you?" - **Respect User Confirmations:** Most tool calls (also denoted as 'function calls') will first require confirmation from the user, where they will either approve or cancel the function call. If a user cancels a function call, respect their choice and do _not_ try to make the function call again. It is okay to request the tool call again _only_ if the user requests that same tool call on a subsequent prompt. When a user cancels a function call, assume best intentions from the user and consider inquiring if they prefer any alternative paths forward. @@ -1134,7 +1134,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -1231,7 +1231,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -1285,7 +1285,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). - **Command Execution:** Use the 'run_shell_command' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. - **Remembering Facts:** Use the 'save_memory' tool to remember specific, *user-related* facts or preferences when the user explicitly asks, or when they state a clear, concise piece of information that would help personalize or streamline *your future interactions with them* (e.g., preferred coding style, common project paths they use, personal tool aliases). This tool is for user-specific information that should persist across sessions. Do *not* use it for general project context or information. If unsure whether to save something, you can ask the user, "Should I remember that for you?" - **Respect User Confirmations:** Most tool calls (also denoted as 'function calls') will first require confirmation from the user, where they will either approve or cancel the function call. If a user cancels a function call, respect their choice and do _not_ try to make the function call again. It is okay to request the tool call again _only_ if the user requests that same tool call on a subsequent prompt. When a user cancels a function call, assume best intentions from the user and consider inquiring if they prefer any alternative paths forward. @@ -1330,7 +1330,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, Use 'read_file' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to 'read_file'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution. 3. **Implement:** Use the available tools (e.g., 'replace', 'write_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -1384,7 +1384,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). - **Command Execution:** Use the 'run_shell_command' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input. - **Remembering Facts:** Use the 'save_memory' tool to remember specific, *user-related* facts or preferences when the user explicitly asks, or when they state a clear, concise piece of information that would help personalize or streamline *your future interactions with them* (e.g., preferred coding style, common project paths they use, personal tool aliases). This tool is for user-specific information that should persist across sessions. Do *not* use it for general project context or information. If unsure whether to save something, you can ask the user, "Should I remember that for you?" - **Respect User Confirmations:** Most tool calls (also denoted as 'function calls') will first require confirmation from the user, where they will either approve or cancel the function call. If a user cancels a function call, respect their choice and do _not_ try to make the function call again. It is okay to request the tool call again _only_ if the user requests that same tool call on a subsequent prompt. When a user cancels a function call, assume best intentions from the user and consider inquiring if they prefer any alternative paths forward. diff --git a/packages/core/src/core/prompts.ts b/packages/core/src/core/prompts.ts index a2811dcfa1..0aec32f155 100644 --- a/packages/core/src/core/prompts.ts +++ b/packages/core/src/core/prompts.ts @@ -217,7 +217,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring, 1. **Understand:** Think about the user's request and the relevant codebase context. Use '${GREP_TOOL_NAME}' and '${GLOB_TOOL_NAME}' search tools extensively (in parallel if independent) to understand file structures, existing code patterns, and conventions. Use '${READ_FILE_TOOL_NAME}' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to '${READ_FILE_TOOL_NAME}'. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. For complex tasks, break them down into smaller, manageable subtasks and use the \`${WRITE_TODOS_TOOL_NAME}\` tool to track your progress. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution.`, primaryWorkflows_suffix: `3. **Implement:** Use the available tools (e.g., '${EDIT_TOOL_NAME}', '${WRITE_FILE_TOOL_NAME}' '${SHELL_TOOL_NAME}' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). -4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. +4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. When executing test commands, prefer "run once" or "CI" modes to ensure the command terminates after completion. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards.${interactiveMode ? " If unsure about these commands, you can ask the user if they'd like you to run them and if so how to." : ''} 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. @@ -292,7 +292,7 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. ${(function () { if (interactiveMode) { return `- **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. -- **Interactive Commands:** Prefer non-interactive commands when it makes sense; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input.`; +- **Interactive Commands:** Always prefer non-interactive commands (e.g., using 'run once' or 'CI' flags for test runners to avoid persistent watch modes) unless a persistent process is specifically required; however, some commands are only interactive and expect user input during their execution (e.g. ssh, vim). If you choose to execute an interactive command consider letting the user know they can press \`ctrl + f\` to focus into the shell to provide input.`; } else { return `- **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. - **Interactive Commands:** Only execute non-interactive commands.`; From b54e688c75f4693b43c74fb09179b9707f41648e Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Fri, 9 Jan 2026 16:31:29 -0800 Subject: [PATCH 107/713] Update ink version to 6.4.7 (#16284) --- package-lock.json | 10 +++++----- package.json | 4 ++-- packages/cli/package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1830ea7295..908dc636f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "packages/*" ], "dependencies": { - "ink": "npm:@jrichman/ink@6.4.6", + "ink": "npm:@jrichman/ink@6.4.7", "latest-version": "^9.0.0", "simple-git": "^3.28.0" }, @@ -10943,9 +10943,9 @@ }, "node_modules/ink": { "name": "@jrichman/ink", - "version": "6.4.6", - "resolved": "https://registry.npmjs.org/@jrichman/ink/-/ink-6.4.6.tgz", - "integrity": "sha512-QHl6l1cl3zPCaRMzt9TUbTX6Q5SzvkGEZDDad0DmSf5SPmT1/90k6pGPejEvDCJprkitwObXpPaTWGHItqsy4g==", + "version": "6.4.7", + "resolved": "https://registry.npmjs.org/@jrichman/ink/-/ink-6.4.7.tgz", + "integrity": "sha512-QHyxhNF5VonF5cRmdAJD/UPucB9nRx3FozWMjQrDGfBxfAL9lpyu72/MlFPgloS1TMTGsOt7YN6dTPPA6mh0Aw==", "license": "MIT", "peer": true, "dependencies": { @@ -18793,7 +18793,7 @@ "fzf": "^0.5.2", "glob": "^12.0.0", "highlight.js": "^11.11.1", - "ink": "npm:@jrichman/ink@6.4.6", + "ink": "npm:@jrichman/ink@6.4.7", "ink-gradient": "^3.0.0", "ink-spinner": "^5.0.0", "latest-version": "^9.0.0", diff --git a/package.json b/package.json index 4328d4e637..f5c10deaf5 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "pre-commit": "node scripts/pre-commit.js" }, "overrides": { - "ink": "npm:@jrichman/ink@6.4.6", + "ink": "npm:@jrichman/ink@6.4.7", "wrap-ansi": "9.0.2", "cliui": { "wrap-ansi": "7.0.0" @@ -121,7 +121,7 @@ "yargs": "^17.7.2" }, "dependencies": { - "ink": "npm:@jrichman/ink@6.4.6", + "ink": "npm:@jrichman/ink@6.4.7", "latest-version": "^9.0.0", "simple-git": "^3.28.0" }, diff --git a/packages/cli/package.json b/packages/cli/package.json index f0e9965e04..425dd919a2 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -45,7 +45,7 @@ "fzf": "^0.5.2", "glob": "^12.0.0", "highlight.js": "^11.11.1", - "ink": "npm:@jrichman/ink@6.4.6", + "ink": "npm:@jrichman/ink@6.4.7", "ink-gradient": "^3.0.0", "ink-spinner": "^5.0.0", "latest-version": "^9.0.0", From 461c277bf2de4057a704505315d138cad9ab7ead Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 9 Jan 2026 22:26:58 -0800 Subject: [PATCH 108/713] Support for Built-in Agent Skills (#16045) --- packages/cli/src/commands/skills/list.test.ts | 59 +- packages/cli/src/commands/skills/list.ts | 29 +- .../config/extension-manager-skills.test.ts | 141 ++-- .../cli/src/ui/commands/skillsCommand.test.ts | 47 +- packages/cli/src/ui/commands/skillsCommand.ts | 20 +- .../cli/src/ui/components/Composer.test.tsx | 1 + .../src/ui/components/StatusDisplay.test.tsx | 1 + .../cli/src/ui/components/StatusDisplay.tsx | 4 +- .../ui/components/views/SkillsList.test.tsx | 21 + .../src/ui/components/views/SkillsList.tsx | 32 +- .../src/ui/hooks/useQuotaAndFallback.test.ts | 23 +- .../cli/src/ui/utils/rewindFileOps.test.ts | 717 +++++++++--------- packages/core/src/skills/skillLoader.ts | 2 + packages/core/src/skills/skillManager.test.ts | 41 + packages/core/src/skills/skillManager.ts | 36 +- .../core/src/tools/activate-skill.test.ts | 28 + packages/core/src/tools/activate-skill.ts | 4 + 17 files changed, 755 insertions(+), 451 deletions(-) diff --git a/packages/cli/src/commands/skills/list.test.ts b/packages/cli/src/commands/skills/list.test.ts index ce5a5d0cf8..81230b33a2 100644 --- a/packages/cli/src/commands/skills/list.test.ts +++ b/packages/cli/src/commands/skills/list.test.ts @@ -65,7 +65,7 @@ describe('skills list command', () => { }; mockLoadCliConfig.mockResolvedValue(mockConfig as unknown as Config); - await handleList(); + await handleList({}); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', @@ -96,7 +96,7 @@ describe('skills list command', () => { }; mockLoadCliConfig.mockResolvedValue(mockConfig as unknown as Config); - await handleList(); + await handleList({}); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', @@ -120,10 +120,63 @@ describe('skills list command', () => { ); }); + it('should filter built-in skills by default and show them with { all: true }', async () => { + const skills = [ + { + name: 'regular', + description: 'desc1', + disabled: false, + location: '/loc1', + }, + { + name: 'builtin', + description: 'desc2', + disabled: false, + location: '/loc2', + isBuiltin: true, + }, + ]; + const mockConfig = { + initialize: vi.fn().mockResolvedValue(undefined), + getSkillManager: vi.fn().mockReturnValue({ + getAllSkills: vi.fn().mockReturnValue(skills), + }), + }; + mockLoadCliConfig.mockResolvedValue(mockConfig as unknown as Config); + + // Default + await handleList({ all: false }); + expect(emitConsoleLog).toHaveBeenCalledWith( + 'log', + expect.stringContaining('regular'), + ); + expect(emitConsoleLog).not.toHaveBeenCalledWith( + 'log', + expect.stringContaining('builtin'), + ); + + vi.clearAllMocks(); + + // With all: true + await handleList({ all: true }); + expect(emitConsoleLog).toHaveBeenCalledWith( + 'log', + expect.stringContaining('regular'), + ); + expect(emitConsoleLog).toHaveBeenCalledWith( + 'log', + expect.stringContaining('builtin'), + ); + expect(emitConsoleLog).toHaveBeenCalledWith( + 'log', + expect.stringContaining(chalk.gray(' [Built-in]')), + ); + }); + it('should throw an error when listing fails', async () => { mockLoadCliConfig.mockRejectedValue(new Error('List failed')); - await expect(handleList()).rejects.toThrow('List failed'); + await expect(handleList({})).rejects.toThrow('List failed'); }); }); diff --git a/packages/cli/src/commands/skills/list.ts b/packages/cli/src/commands/skills/list.ts index 29b234df98..17f225c510 100644 --- a/packages/cli/src/commands/skills/list.ts +++ b/packages/cli/src/commands/skills/list.ts @@ -11,7 +11,7 @@ import { loadCliConfig, type CliArgs } from '../../config/config.js'; import { exitCli } from '../utils.js'; import chalk from 'chalk'; -export async function handleList() { +export async function handleList(args: { all?: boolean }) { const workspaceDir = process.cwd(); const settings = loadSettings(workspaceDir); @@ -28,7 +28,17 @@ export async function handleList() { await config.initialize(); const skillManager = config.getSkillManager(); - const skills = skillManager.getAllSkills(); + const skills = args.all + ? skillManager.getAllSkills() + : skillManager.getAllSkills().filter((s) => !s.isBuiltin); + + // Sort skills: non-built-in first, then alphabetically by name + skills.sort((a, b) => { + if (a.isBuiltin === b.isBuiltin) { + return a.name.localeCompare(b.name); + } + return a.isBuiltin ? 1 : -1; + }); if (skills.length === 0) { debugLogger.log('No skills discovered.'); @@ -43,7 +53,9 @@ export async function handleList() { ? chalk.red('[Disabled]') : chalk.green('[Enabled]'); - debugLogger.log(`${chalk.bold(skill.name)} ${status}`); + const builtinSuffix = skill.isBuiltin ? chalk.gray(' [Built-in]') : ''; + + debugLogger.log(`${chalk.bold(skill.name)} ${status}${builtinSuffix}`); debugLogger.log(` Description: ${skill.description}`); debugLogger.log(` Location: ${skill.location}`); debugLogger.log(''); @@ -53,9 +65,14 @@ export async function handleList() { export const listCommand: CommandModule = { command: 'list', describe: 'Lists discovered agent skills.', - builder: (yargs) => yargs, - handler: async () => { - await handleList(); + builder: (yargs) => + yargs.option('all', { + type: 'boolean', + description: 'Show all skills, including built-in ones.', + default: false, + }), + handler: async (argv) => { + await handleList({ all: argv['all'] as boolean }); await exitCli(); }, }; diff --git a/packages/cli/src/config/extension-manager-skills.test.ts b/packages/cli/src/config/extension-manager-skills.test.ts index 585f2adc51..526db275e2 100644 --- a/packages/cli/src/config/extension-manager-skills.test.ts +++ b/packages/cli/src/config/extension-manager-skills.test.ts @@ -4,26 +4,27 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import * as fs from 'node:fs'; import * as path from 'node:path'; import * as os from 'node:os'; import { ExtensionManager } from './extension-manager.js'; -import { loadSettings } from './settings.js'; +import { debugLogger, coreEvents } from '@google/gemini-cli-core'; +import { type Settings } from './settings.js'; import { createExtension } from '../test-utils/createExtension.js'; import { EXTENSIONS_DIRECTORY_NAME } from './extensions/variables.js'; -import { coreEvents, debugLogger } from '@google/gemini-cli-core'; -const mockHomedir = vi.hoisted(() => vi.fn()); +const mockHomedir = vi.hoisted(() => vi.fn(() => '/tmp/mock-home')); -vi.mock('os', async (importOriginal) => { - const mockedOs = await importOriginal(); +vi.mock('node:os', async (importOriginal) => { + const actual = await importOriginal(); return { - ...mockedOs, + ...actual, homedir: mockHomedir, }; }); +// Mock @google/gemini-cli-core vi.mock('@google/gemini-cli-core', async (importOriginal) => { const actual = await importOriginal(); @@ -34,92 +35,130 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { }); describe('ExtensionManager skills validation', () => { - let tempHomeDir: string; - let tempWorkspaceDir: string; - let userExtensionsDir: string; let extensionManager: ExtensionManager; + let tempDir: string; + let extensionsDir: string; beforeEach(() => { - tempHomeDir = fs.mkdtempSync( - path.join(os.tmpdir(), 'gemini-cli-skills-test-home-'), - ); - tempWorkspaceDir = fs.mkdtempSync( - path.join(tempHomeDir, 'gemini-cli-skills-test-workspace-'), - ); - userExtensionsDir = path.join(tempHomeDir, EXTENSIONS_DIRECTORY_NAME); - fs.mkdirSync(userExtensionsDir, { recursive: true }); - - mockHomedir.mockReturnValue(tempHomeDir); - - extensionManager = new ExtensionManager({ - workspaceDir: tempWorkspaceDir, - requestConsent: vi.fn().mockResolvedValue(true), - requestSetting: vi.fn().mockResolvedValue(''), - settings: loadSettings(tempWorkspaceDir).merged, - }); + vi.clearAllMocks(); vi.spyOn(coreEvents, 'emitFeedback'); vi.spyOn(debugLogger, 'debug').mockImplementation(() => {}); + + tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gemini-test-')); + mockHomedir.mockReturnValue(tempDir); + + // Create the extensions directory that ExtensionManager expects + extensionsDir = path.join(tempDir, '.gemini', EXTENSIONS_DIRECTORY_NAME); + fs.mkdirSync(extensionsDir, { recursive: true }); + + extensionManager = new ExtensionManager({ + settings: { + telemetry: { enabled: false }, + trustedFolders: [tempDir], + } as unknown as Settings, + requestConsent: vi.fn().mockResolvedValue(true), + requestSetting: vi.fn(), + workspaceDir: tempDir, + }); }); afterEach(() => { - fs.rmSync(tempHomeDir, { recursive: true, force: true }); - vi.restoreAllMocks(); + try { + fs.rmSync(tempDir, { recursive: true, force: true }); + } catch { + // ignore + } }); it('should emit a warning during install if skills directory is not empty but no skills are loaded', async () => { - const sourceExtDir = createExtension({ - extensionsDir: tempHomeDir, + // Create a source extension + const sourceDir = path.join(tempDir, 'source-ext'); + createExtension({ + extensionsDir: sourceDir, // createExtension appends name name: 'skills-ext', version: '1.0.0', + installMetadata: { + type: 'local', + source: path.join(sourceDir, 'skills-ext'), + }, }); + const extensionPath = path.join(sourceDir, 'skills-ext'); - const skillsDir = path.join(sourceExtDir, 'skills'); + // Add invalid skills content + const skillsDir = path.join(extensionPath, 'skills'); fs.mkdirSync(skillsDir); fs.writeFileSync(path.join(skillsDir, 'not-a-skill.txt'), 'hello'); await extensionManager.loadExtensions(); - const extension = await extensionManager.installOrUpdateExtension({ - source: sourceExtDir, + + await extensionManager.installOrUpdateExtension({ type: 'local', + source: extensionPath, }); - expect(extension.name).toBe('skills-ext'); expect(debugLogger.debug).toHaveBeenCalledWith( expect.stringContaining('Failed to load skills from'), ); }); it('should emit a warning during load if skills directory is not empty but no skills are loaded', async () => { - const extDir = createExtension({ - extensionsDir: userExtensionsDir, - name: 'load-skills-ext', + // 1. Create a source extension + const sourceDir = path.join(tempDir, 'source-ext-load'); + createExtension({ + extensionsDir: sourceDir, + name: 'skills-ext-load', version: '1.0.0', }); + const sourceExtPath = path.join(sourceDir, 'skills-ext-load'); - const skillsDir = path.join(extDir, 'skills'); + // Add invalid skills content + const skillsDir = path.join(sourceExtPath, 'skills'); fs.mkdirSync(skillsDir); fs.writeFileSync(path.join(skillsDir, 'not-a-skill.txt'), 'hello'); + // 2. Install it to ensure correct disk state await extensionManager.loadExtensions(); + await extensionManager.installOrUpdateExtension({ + type: 'local', + source: sourceExtPath, + }); + + // Clear the spy + vi.mocked(debugLogger.debug).mockClear(); + + // 3. Create a fresh ExtensionManager to force loading from disk + const newExtensionManager = new ExtensionManager({ + settings: { + telemetry: { enabled: false }, + trustedFolders: [tempDir], + } as unknown as Settings, + requestConsent: vi.fn().mockResolvedValue(true), + requestSetting: vi.fn(), + workspaceDir: tempDir, + }); + + // 4. Load extensions + await newExtensionManager.loadExtensions(); expect(debugLogger.debug).toHaveBeenCalledWith( expect.stringContaining('Failed to load skills from'), ); - expect(debugLogger.debug).toHaveBeenCalledWith( - expect.stringContaining( - 'The directory is not empty but no valid skills were discovered', - ), - ); }); it('should succeed if skills are correctly loaded', async () => { - const sourceExtDir = createExtension({ - extensionsDir: tempHomeDir, + const sourceDir = path.join(tempDir, 'source-ext-good'); + createExtension({ + extensionsDir: sourceDir, name: 'good-skills-ext', version: '1.0.0', + installMetadata: { + type: 'local', + source: path.join(sourceDir, 'good-skills-ext'), + }, }); + const extensionPath = path.join(sourceDir, 'good-skills-ext'); - const skillsDir = path.join(sourceExtDir, 'skills'); + const skillsDir = path.join(extensionPath, 'skills'); const skillSubdir = path.join(skillsDir, 'test-skill'); fs.mkdirSync(skillSubdir, { recursive: true }); fs.writeFileSync( @@ -128,15 +167,13 @@ describe('ExtensionManager skills validation', () => { ); await extensionManager.loadExtensions(); + const extension = await extensionManager.installOrUpdateExtension({ - source: sourceExtDir, type: 'local', + source: extensionPath, }); - expect(extension.skills).toHaveLength(1); - expect(extension.skills![0].name).toBe('test-skill'); - // It might be called for other reasons during startup, but shouldn't be called for our skills loading success - // Actually, it shouldn't be called with our warning message + expect(extension.name).toBe('good-skills-ext'); expect(debugLogger.debug).not.toHaveBeenCalledWith( expect.stringContaining('Failed to load skills from'), ); diff --git a/packages/cli/src/ui/commands/skillsCommand.test.ts b/packages/cli/src/ui/commands/skillsCommand.test.ts index e90c695e0c..3bcfa6ba06 100644 --- a/packages/cli/src/ui/commands/skillsCommand.test.ts +++ b/packages/cli/src/ui/commands/skillsCommand.test.ts @@ -6,7 +6,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { skillsCommand } from './skillsCommand.js'; -import { MessageType } from '../types.js'; +import { MessageType, type HistoryItemSkillsList } from '../types.js'; import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; import type { CommandContext } from './types.js'; import type { Config, SkillDefinition } from '@google/gemini-cli-core'; @@ -136,6 +136,51 @@ describe('skillsCommand', () => { ); }); + it('should filter built-in skills by default and show them with "all"', async () => { + const skillManager = context.services.config!.getSkillManager(); + const mockSkills = [ + { + name: 'regular', + description: 'desc1', + location: '/loc1', + body: 'body1', + }, + { + name: 'builtin', + description: 'desc2', + location: '/loc2', + body: 'body2', + isBuiltin: true, + }, + ]; + vi.mocked(skillManager.getAllSkills).mockReturnValue(mockSkills); + + const listCmd = skillsCommand.subCommands!.find((s) => s.name === 'list')!; + + // By default, only regular skills + await listCmd.action!(context, ''); + let lastCall = vi + .mocked(context.ui.addItem) + .mock.calls.at(-1)![0] as HistoryItemSkillsList; + expect(lastCall.skills).toHaveLength(1); + expect(lastCall.skills[0].name).toBe('regular'); + + // With "all", show both + await listCmd.action!(context, 'all'); + lastCall = vi + .mocked(context.ui.addItem) + .mock.calls.at(-1)![0] as HistoryItemSkillsList; + expect(lastCall.skills).toHaveLength(2); + expect(lastCall.skills.map((s) => s.name)).toContain('builtin'); + + // With "--all", show both + await listCmd.action!(context, '--all'); + lastCall = vi + .mocked(context.ui.addItem) + .mock.calls.at(-1)![0] as HistoryItemSkillsList; + expect(lastCall.skills).toHaveLength(2); + }); + describe('disable/enable', () => { beforeEach(() => { context.services.settings.merged.skills = { disabled: [] }; diff --git a/packages/cli/src/ui/commands/skillsCommand.ts b/packages/cli/src/ui/commands/skillsCommand.ts index d769b9941d..ca476a32ea 100644 --- a/packages/cli/src/ui/commands/skillsCommand.ts +++ b/packages/cli/src/ui/commands/skillsCommand.ts @@ -23,12 +23,18 @@ async function listAction( context: CommandContext, args: string, ): Promise { - const subCommand = args.trim(); + const subArgs = args.trim().split(/\s+/); // Default to SHOWING descriptions. The user can hide them with 'nodesc'. let useShowDescriptions = true; - if (subCommand === 'nodesc') { - useShowDescriptions = false; + let showAll = false; + + for (const arg of subArgs) { + if (arg === 'nodesc' || arg === '--nodesc') { + useShowDescriptions = false; + } else if (arg === 'all' || arg === '--all') { + showAll = true; + } } const skillManager = context.services.config?.getSkillManager(); @@ -43,7 +49,9 @@ async function listAction( return; } - const skills = skillManager.getAllSkills(); + const skills = showAll + ? skillManager.getAllSkills() + : skillManager.getAllSkills().filter((s) => !s.isBuiltin); const skillsListItem: HistoryItemSkillsList = { type: MessageType.SKILLS_LIST, @@ -53,6 +61,7 @@ async function listAction( disabled: skill.disabled, location: skill.location, body: skill.body, + isBuiltin: skill.isBuiltin, })), showDescriptions: useShowDescriptions, }; @@ -278,7 +287,8 @@ export const skillsCommand: SlashCommand = { subCommands: [ { name: 'list', - description: 'List available agent skills. Usage: /skills list [nodesc]', + description: + 'List available agent skills. Usage: /skills list [nodesc] [all]', kind: CommandKind.BUILT_IN, action: listAction, }, diff --git a/packages/cli/src/ui/components/Composer.test.tsx b/packages/cli/src/ui/components/Composer.test.tsx index b48e18cc00..e5e6e02830 100644 --- a/packages/cli/src/ui/components/Composer.test.tsx +++ b/packages/cli/src/ui/components/Composer.test.tsx @@ -154,6 +154,7 @@ const createMockConfig = (overrides = {}) => ({ }), getSkillManager: () => ({ getSkills: () => [], + getDisplayableSkills: () => [], }), getMcpClientManager: () => ({ getMcpServers: () => ({}), diff --git a/packages/cli/src/ui/components/StatusDisplay.test.tsx b/packages/cli/src/ui/components/StatusDisplay.test.tsx index e5a64bd3f3..8e3bdff68c 100644 --- a/packages/cli/src/ui/components/StatusDisplay.test.tsx +++ b/packages/cli/src/ui/components/StatusDisplay.test.tsx @@ -45,6 +45,7 @@ const createMockConfig = (overrides = {}) => ({ })), getSkillManager: vi.fn().mockImplementation(() => ({ getSkills: vi.fn(() => ['skill1', 'skill2']), + getDisplayableSkills: vi.fn(() => ['skill1', 'skill2']), })), ...overrides, }); diff --git a/packages/cli/src/ui/components/StatusDisplay.tsx b/packages/cli/src/ui/components/StatusDisplay.tsx index 367be17593..40925fa5ba 100644 --- a/packages/cli/src/ui/components/StatusDisplay.tsx +++ b/packages/cli/src/ui/components/StatusDisplay.tsx @@ -25,7 +25,7 @@ export const StatusDisplay: React.FC = ({ const config = useConfig(); if (process.env['GEMINI_SYSTEM_MD']) { - return |⌐■_■| ; + return |⌐■_■|; } if (uiState.ctrlCPressedOnce) { @@ -69,7 +69,7 @@ export const StatusDisplay: React.FC = ({ blockedMcpServers={ config.getMcpClientManager()?.getBlockedMcpServers() ?? [] } - skillCount={config.getSkillManager().getSkills().length} + skillCount={config.getSkillManager().getDisplayableSkills().length} /> ); } diff --git a/packages/cli/src/ui/components/views/SkillsList.test.tsx b/packages/cli/src/ui/components/views/SkillsList.test.tsx index e04958cc9a..d12871803e 100644 --- a/packages/cli/src/ui/components/views/SkillsList.test.tsx +++ b/packages/cli/src/ui/components/views/SkillsList.test.tsx @@ -105,4 +105,25 @@ describe('SkillsList Component', () => { unmount(); }); + + it('should render [Built-in] tag for built-in skills', () => { + const builtinSkill: SkillDefinition = { + name: 'builtin-skill', + description: 'A built-in skill', + disabled: false, + location: 'loc', + body: 'body', + isBuiltin: true, + }; + + const { lastFrame, unmount } = render( + , + ); + const output = lastFrame(); + + expect(output).toContain('builtin-skill'); + expect(output).toContain('Built-in'); + + unmount(); + }); }); diff --git a/packages/cli/src/ui/components/views/SkillsList.tsx b/packages/cli/src/ui/components/views/SkillsList.tsx index ebb3c8519b..64e2d3efd7 100644 --- a/packages/cli/src/ui/components/views/SkillsList.tsx +++ b/packages/cli/src/ui/components/views/SkillsList.tsx @@ -18,24 +18,32 @@ export const SkillsList: React.FC = ({ skills, showDescriptions, }) => { - const enabledSkills = skills - .filter((s) => !s.disabled) - .sort((a, b) => a.name.localeCompare(b.name)); + const sortSkills = (a: SkillDefinition, b: SkillDefinition) => { + if (a.isBuiltin === b.isBuiltin) { + return a.name.localeCompare(b.name); + } + return a.isBuiltin ? 1 : -1; + }; - const disabledSkills = skills - .filter((s) => s.disabled) - .sort((a, b) => a.name.localeCompare(b.name)); + const enabledSkills = skills.filter((s) => !s.disabled).sort(sortSkills); + + const disabledSkills = skills.filter((s) => s.disabled).sort(sortSkills); const renderSkill = (skill: SkillDefinition) => ( {' '}- - - {skill.name} - + + + {skill.name} + + {skill.isBuiltin && ( + {' [Built-in]'} + )} + {showDescriptions && skill.description && ( { vi.spyOn(mockConfig, 'setQuotaErrorOccurred'); vi.spyOn(mockConfig, 'setModel'); vi.spyOn(mockConfig, 'setActiveModel'); + vi.spyOn(mockConfig, 'activateFallbackMode'); }); afterEach(() => { @@ -165,8 +166,10 @@ describe('useQuotaAndFallback', () => { const intent = await promise!; expect(intent).toBe('retry_always'); - // Verify setActiveModel was called - expect(mockConfig.setActiveModel).toHaveBeenCalledWith('gemini-flash'); + // Verify activateFallbackMode was called + expect(mockConfig.activateFallbackMode).toHaveBeenCalledWith( + 'gemini-flash', + ); // The pending request should be cleared from the state expect(result.current.proQuotaRequest).toBeNull(); @@ -279,8 +282,10 @@ describe('useQuotaAndFallback', () => { const intent = await promise!; expect(intent).toBe('retry_always'); - // Verify setActiveModel was called - expect(mockConfig.setActiveModel).toHaveBeenCalledWith('model-B'); + // Verify activateFallbackMode was called + expect(mockConfig.activateFallbackMode).toHaveBeenCalledWith( + 'model-B', + ); // The pending request should be cleared from the state expect(result.current.proQuotaRequest).toBeNull(); @@ -337,8 +342,8 @@ To disable gemini-3-pro-preview, disable "Preview features" in /settings.`, const intent = await promise!; expect(intent).toBe('retry_always'); - // Verify setActiveModel was called - expect(mockConfig.setActiveModel).toHaveBeenCalledWith( + // Verify activateFallbackMode was called + expect(mockConfig.activateFallbackMode).toHaveBeenCalledWith( 'gemini-2.5-pro', ); @@ -425,8 +430,10 @@ To disable gemini-3-pro-preview, disable "Preview features" in /settings.`, expect(intent).toBe('retry_always'); expect(result.current.proQuotaRequest).toBeNull(); - // Verify setActiveModel was called - expect(mockConfig.setActiveModel).toHaveBeenCalledWith('gemini-flash'); + // Verify activateFallbackMode was called + expect(mockConfig.activateFallbackMode).toHaveBeenCalledWith( + 'gemini-flash', + ); // Verify quota error flags are reset expect(mockSetModelSwitchedFromQuotaError).toHaveBeenCalledWith(false); diff --git a/packages/cli/src/ui/utils/rewindFileOps.test.ts b/packages/cli/src/ui/utils/rewindFileOps.test.ts index a70dd0337f..fa0a1df51d 100644 --- a/packages/cli/src/ui/utils/rewindFileOps.test.ts +++ b/packages/cli/src/ui/utils/rewindFileOps.test.ts @@ -4,219 +4,204 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import fs from 'node:fs/promises'; import { calculateTurnStats, calculateRewindImpact, revertFileChanges, } from './rewindFileOps.js'; -import type { - ConversationRecord, - MessageRecord, - ToolCallRecord, +import { + coreEvents, + type ConversationRecord, + type MessageRecord, + type ToolCallRecord, } from '@google/gemini-cli-core'; -import { coreEvents } from '@google/gemini-cli-core'; -import fs from 'node:fs/promises'; -import path from 'node:path'; -vi.mock('node:fs/promises'); +// Mock fs/promises +vi.mock('node:fs/promises', () => ({ + default: { + readFile: vi.fn(), + writeFile: vi.fn(), + rm: vi.fn(), + unlink: vi.fn(), + }, +})); + +// Mock @google/gemini-cli-core vi.mock('@google/gemini-cli-core', async (importOriginal) => { const actual = await importOriginal(); return { ...actual, - coreEvents: { - emitFeedback: vi.fn(), + debugLogger: { + log: vi.fn(), + warn: vi.fn(), + error: vi.fn(), + debug: vi.fn(), }, + getFileDiffFromResultDisplay: vi.fn(), + computeAddedAndRemovedLines: vi.fn(), }; }); describe('rewindFileOps', () => { - const mockConversation: ConversationRecord = { - sessionId: 'test-session', - projectHash: 'hash', - startTime: 'time', - lastUpdated: 'time', - messages: [], - }; - beforeEach(() => { vi.clearAllMocks(); - }); - - afterEach(() => { - vi.restoreAllMocks(); + vi.spyOn(coreEvents, 'emitFeedback'); }); describe('calculateTurnStats', () => { it('returns null if no edits found after user message', () => { - const userMsg: MessageRecord = { - type: 'user', - content: 'hello', - id: '1', - timestamp: '1', + const userMsg = { type: 'user' } as unknown as MessageRecord; + const conversation = { + messages: [ + userMsg, + { type: 'gemini', text: 'Hello' } as unknown as MessageRecord, + ], }; - const geminiMsg: MessageRecord = { - type: 'gemini', - content: 'hi', - id: '2', - timestamp: '2', - }; - mockConversation.messages = [userMsg, geminiMsg]; - - const stats = calculateTurnStats(mockConversation, userMsg); - expect(stats).toBeNull(); + const result = calculateTurnStats( + conversation as unknown as ConversationRecord, + userMsg, + ); + expect(result).toBeNull(); }); - it('calculates stats for single turn correctly', () => { - const userMsg: MessageRecord = { - type: 'user', - content: 'hello', - id: '1', - timestamp: '1', - }; - const toolMsg: MessageRecord = { - type: 'gemini', - id: '2', - timestamp: '2', - content: '', - toolCalls: [ + it('calculates stats for single turn correctly', async () => { + const { getFileDiffFromResultDisplay, computeAddedAndRemovedLines } = + await import('@google/gemini-cli-core'); + vi.mocked(getFileDiffFromResultDisplay).mockReturnValue({ + filePath: 'test.ts', + fileName: 'test.ts', + originalContent: 'old', + newContent: 'new', + isNewFile: false, + diffStat: { + model_added_lines: 0, + model_removed_lines: 0, + model_added_chars: 0, + model_removed_chars: 0, + user_added_lines: 0, + user_removed_lines: 0, + user_added_chars: 0, + user_removed_chars: 0, + }, + fileDiff: 'diff', + }); + vi.mocked(computeAddedAndRemovedLines).mockReturnValue({ + addedLines: 3, + removedLines: 3, + }); + + const userMsg = { type: 'user' } as unknown as MessageRecord; + const conversation = { + messages: [ + userMsg, { - name: 'replace', - id: 'tool-call-1', - status: 'success', - timestamp: '2', - args: {}, - resultDisplay: { - fileName: 'file1.ts', - filePath: '/file1.ts', - originalContent: 'old', - newContent: 'new', - isNewFile: false, - diffStat: { - model_added_lines: 5, - model_removed_lines: 2, - user_added_lines: 0, - user_removed_lines: 0, - model_added_chars: 100, - model_removed_chars: 20, - user_added_chars: 0, - user_removed_chars: 0, + type: 'gemini', + toolCalls: [ + { + name: 'replace', + args: {}, + resultDisplay: 'diff', }, - }, - }, - ] as unknown as ToolCallRecord[], + ], + } as unknown as MessageRecord, + ], }; - const userMsg2: MessageRecord = { - type: 'user', - content: 'next', - id: '3', - timestamp: '3', - }; - - mockConversation.messages = [userMsg, toolMsg, userMsg2]; - - const stats = calculateTurnStats(mockConversation, userMsg); - expect(stats).toEqual({ - addedLines: 5, - removedLines: 2, + const result = calculateTurnStats( + conversation as unknown as ConversationRecord, + userMsg, + ); + expect(result).toEqual({ fileCount: 1, + addedLines: 3, + removedLines: 3, }); }); }); describe('calculateRewindImpact', () => { - it('calculates cumulative stats across multiple turns', () => { - const userMsg1: MessageRecord = { - type: 'user', - content: 'start', - id: '1', - timestamp: '1', - }; - const toolMsg1: MessageRecord = { - type: 'gemini', - id: '2', - timestamp: '2', - content: '', - toolCalls: [ - { - name: 'replace', - id: 'tool-call-1', - status: 'success', - timestamp: '2', - args: {}, - resultDisplay: { - fileName: 'file1.ts', - filePath: '/file1.ts', - fileDiff: 'diff1', - originalContent: 'old', - newContent: 'new', - isNewFile: false, - diffStat: { - model_added_lines: 5, - model_removed_lines: 2, - user_added_lines: 0, - user_removed_lines: 0, - model_added_chars: 0, - model_removed_chars: 0, - user_added_chars: 0, - user_removed_chars: 0, - }, - }, + it('calculates cumulative stats across multiple turns', async () => { + const { getFileDiffFromResultDisplay, computeAddedAndRemovedLines } = + await import('@google/gemini-cli-core'); + vi.mocked(getFileDiffFromResultDisplay) + .mockReturnValueOnce({ + filePath: 'file1.ts', + fileName: 'file1.ts', + originalContent: '123', + newContent: '12345', + isNewFile: false, + diffStat: { + model_added_lines: 0, + model_removed_lines: 0, + model_added_chars: 0, + model_removed_chars: 0, + user_added_lines: 0, + user_removed_lines: 0, + user_added_chars: 0, + user_removed_chars: 0, }, - ] as unknown as ToolCallRecord[], - }; - - const userMsg2: MessageRecord = { - type: 'user', - content: 'next', - id: '3', - timestamp: '3', - }; - - const toolMsg2: MessageRecord = { - type: 'gemini', - id: '4', - timestamp: '4', - content: '', - toolCalls: [ - { - name: 'replace', - id: 'tool-call-2', - status: 'success', - timestamp: '4', - args: {}, - resultDisplay: { - fileName: 'file2.ts', - filePath: '/file2.ts', - fileDiff: 'diff2', - originalContent: 'old', - newContent: 'new', - isNewFile: false, - diffStat: { - model_added_lines: 3, - model_removed_lines: 1, - user_added_lines: 0, - user_removed_lines: 0, - model_added_chars: 0, - model_removed_chars: 0, - user_added_chars: 0, - user_removed_chars: 0, - }, - }, + fileDiff: 'diff1', + }) + .mockReturnValueOnce({ + filePath: 'file2.ts', + fileName: 'file2.ts', + originalContent: 'abc', + newContent: 'abcd', + isNewFile: true, + diffStat: { + model_added_lines: 0, + model_removed_lines: 0, + model_added_chars: 0, + model_removed_chars: 0, + user_added_lines: 0, + user_removed_lines: 0, + user_added_chars: 0, + user_removed_chars: 0, }, - ] as unknown as ToolCallRecord[], + fileDiff: 'diff2', + }); + + vi.mocked(computeAddedAndRemovedLines) + .mockReturnValueOnce({ addedLines: 5, removedLines: 3 }) + .mockReturnValueOnce({ addedLines: 4, removedLines: 0 }); + + const userMsg = { type: 'user' } as unknown as MessageRecord; + const conversation = { + messages: [ + userMsg, + { + type: 'gemini', + toolCalls: [ + { + resultDisplay: 'd1', + } as unknown as ToolCallRecord, + ], + } as unknown as MessageRecord, + { + type: 'user', + } as unknown as MessageRecord, + { + type: 'gemini', + toolCalls: [ + { + resultDisplay: 'd2', + } as unknown as ToolCallRecord, + ], + } as unknown as MessageRecord, + ], }; - mockConversation.messages = [userMsg1, toolMsg1, userMsg2, toolMsg2]; - - const stats = calculateRewindImpact(mockConversation, userMsg1); - - expect(stats).toEqual({ - addedLines: 8, // 5 + 3 - removedLines: 3, // 2 + 1 + const result = calculateRewindImpact( + conversation as unknown as ConversationRecord, + userMsg, + ); + expect(result).toEqual({ fileCount: 2, + addedLines: 9, // 5 + 4 + removedLines: 3, // 3 + 0 details: [ { fileName: 'file1.ts', diff: 'diff1' }, { fileName: 'file2.ts', diff: 'diff2' }, @@ -226,246 +211,264 @@ describe('rewindFileOps', () => { }); describe('revertFileChanges', () => { - const mockDiffStat = { - model_added_lines: 1, - model_removed_lines: 1, - user_added_lines: 0, - user_removed_lines: 0, - model_added_chars: 1, - model_removed_chars: 1, - user_added_chars: 0, - user_removed_chars: 0, - }; - it('does nothing if message not found', async () => { - mockConversation.messages = []; - await revertFileChanges(mockConversation, 'missing-id'); + await revertFileChanges( + { messages: [] } as unknown as ConversationRecord, + 'missing', + ); expect(fs.writeFile).not.toHaveBeenCalled(); }); it('reverts exact match', async () => { - const userMsg: MessageRecord = { + const { getFileDiffFromResultDisplay } = await import( + '@google/gemini-cli-core' + ); + vi.mocked(getFileDiffFromResultDisplay).mockReturnValue({ + filePath: '/abs/path/test.ts', + fileName: 'test.ts', + originalContent: 'ORIGINAL_CONTENT', + newContent: 'NEW_CONTENT', + isNewFile: false, + diffStat: { + model_added_lines: 0, + model_removed_lines: 0, + model_added_chars: 0, + model_removed_chars: 0, + user_added_lines: 0, + user_removed_lines: 0, + user_added_chars: 0, + user_removed_chars: 0, + }, + fileDiff: 'diff', + }); + + const userMsg = { type: 'user', - content: 'start', - id: '1', - timestamp: '1', - }; - const toolMsg: MessageRecord = { - type: 'gemini', - id: '2', - timestamp: '2', - content: '', - toolCalls: [ + id: 'target', + } as unknown as MessageRecord; + const conversation = { + messages: [ + userMsg, { - name: 'replace', - id: 'tool-call-1', - status: 'success', - timestamp: '2', - args: {}, - resultDisplay: { - fileName: 'file.txt', - filePath: path.resolve('/root/file.txt'), - originalContent: 'old', - newContent: 'new', - isNewFile: false, - diffStat: mockDiffStat, - }, - }, - ] as unknown as ToolCallRecord[], + type: 'gemini', + toolCalls: [{ resultDisplay: 'diff' } as unknown as ToolCallRecord], + } as unknown as MessageRecord, + ], }; - mockConversation.messages = [userMsg, toolMsg]; + vi.mocked(fs.readFile).mockResolvedValue('NEW_CONTENT'); - vi.mocked(fs.readFile).mockResolvedValue('new'); - - await revertFileChanges(mockConversation, '1'); + await revertFileChanges( + conversation as unknown as ConversationRecord, + 'target', + ); expect(fs.writeFile).toHaveBeenCalledWith( - path.resolve('/root/file.txt'), - 'old', + '/abs/path/test.ts', + 'ORIGINAL_CONTENT', ); }); it('deletes new file on revert', async () => { - const userMsg: MessageRecord = { + const { getFileDiffFromResultDisplay } = await import( + '@google/gemini-cli-core' + ); + vi.mocked(getFileDiffFromResultDisplay).mockReturnValue({ + filePath: '/abs/path/new.ts', + fileName: 'new.ts', + originalContent: '', + newContent: 'SOME_CONTENT', + isNewFile: true, + diffStat: { + model_added_lines: 0, + model_removed_lines: 0, + model_added_chars: 0, + model_removed_chars: 0, + user_added_lines: 0, + user_removed_lines: 0, + user_added_chars: 0, + user_removed_chars: 0, + }, + fileDiff: 'diff', + }); + + const userMsg = { type: 'user', - content: 'start', - id: '1', - timestamp: '1', - }; - const toolMsg: MessageRecord = { - type: 'gemini', - id: '2', - timestamp: '2', - content: '', - toolCalls: [ + id: 'target', + } as unknown as MessageRecord; + const conversation = { + messages: [ + userMsg, { - name: 'write_file', - id: 'tool-call-2', - status: 'success', - timestamp: '2', - args: {}, - resultDisplay: { - fileName: 'file.txt', - filePath: path.resolve('/root/file.txt'), - originalContent: null, - newContent: 'content', - isNewFile: true, - diffStat: mockDiffStat, - }, - }, - ] as unknown as ToolCallRecord[], + type: 'gemini', + toolCalls: [{ resultDisplay: 'diff' } as unknown as ToolCallRecord], + } as unknown as MessageRecord, + ], }; - mockConversation.messages = [userMsg, toolMsg]; + vi.mocked(fs.readFile).mockResolvedValue('SOME_CONTENT'); - vi.mocked(fs.readFile).mockResolvedValue('content'); + await revertFileChanges( + conversation as unknown as ConversationRecord, + 'target', + ); - await revertFileChanges(mockConversation, '1'); - - expect(fs.unlink).toHaveBeenCalledWith(path.resolve('/root/file.txt')); + expect(fs.unlink).toHaveBeenCalledWith('/abs/path/new.ts'); }); it('handles smart revert (patching) successfully', async () => { - const original = Array.from( - { length: 20 }, - (_, i) => `line${i + 1}`, - ).join('\n'); - // Agent changes line 2 - const agentModifiedLines = original.split('\n'); - agentModifiedLines[1] = 'line2-modified'; - const agentModified = agentModifiedLines.join('\n'); + const { getFileDiffFromResultDisplay } = await import( + '@google/gemini-cli-core' + ); + vi.mocked(getFileDiffFromResultDisplay).mockReturnValue({ + filePath: '/abs/path/test.ts', + fileName: 'test.ts', + originalContent: 'LINE1\nLINE2\nLINE3', + newContent: 'LINE1\nEDITED\nLINE3', + isNewFile: false, + diffStat: { + model_added_lines: 0, + model_removed_lines: 0, + model_added_chars: 0, + model_removed_chars: 0, + user_added_lines: 0, + user_removed_lines: 0, + user_added_chars: 0, + user_removed_chars: 0, + }, + fileDiff: 'diff', + }); - // User changes line 18 (far away from line 2) - const userModifiedLines = [...agentModifiedLines]; - userModifiedLines[17] = 'line18-modified'; - const userModified = userModifiedLines.join('\n'); - - const toolMsg: MessageRecord = { - type: 'gemini', - id: '2', - timestamp: '2', - content: '', - toolCalls: [ + const userMsg = { + type: 'user', + id: 'target', + } as unknown as MessageRecord; + const conversation = { + messages: [ + userMsg, { - name: 'replace', - id: 'tool-call-1', - status: 'success', - timestamp: '2', - args: {}, - resultDisplay: { - fileName: 'file.txt', - filePath: path.resolve('/root/file.txt'), - originalContent: original, - newContent: agentModified, - isNewFile: false, - diffStat: mockDiffStat, - }, - }, - ] as unknown as ToolCallRecord[], + type: 'gemini', + toolCalls: [{ resultDisplay: 'diff' } as unknown as ToolCallRecord], + } as unknown as MessageRecord, + ], }; - mockConversation.messages = [ - { type: 'user', content: 'start', id: '1', timestamp: '1' }, - toolMsg, - ]; - vi.mocked(fs.readFile).mockResolvedValue(userModified); + // Current content has FURTHER changes + vi.mocked(fs.readFile).mockResolvedValue('LINE1\nEDITED\nLINE3\nNEWLINE'); - await revertFileChanges(mockConversation, '1'); - - // Expect line 2 to be reverted to original, but line 18 to keep user modification - const expectedLines = original.split('\n'); - expectedLines[17] = 'line18-modified'; - const expectedContent = expectedLines.join('\n'); + await revertFileChanges( + conversation as unknown as ConversationRecord, + 'target', + ); + // Should have successfully patched it back to ORIGINAL state but kept the NEWLINE expect(fs.writeFile).toHaveBeenCalledWith( - path.resolve('/root/file.txt'), - expectedContent, + '/abs/path/test.ts', + 'LINE1\nLINE2\nLINE3\nNEWLINE', ); }); it('emits warning on smart revert failure', async () => { - const original = 'line1\nline2\nline3'; - const agentModified = 'line1\nline2-modified\nline3'; - // User modification conflicts with the agent's change. - const userModified = 'line1\nline2-usermodified\nline3'; + const { getFileDiffFromResultDisplay } = await import( + '@google/gemini-cli-core' + ); + vi.mocked(getFileDiffFromResultDisplay).mockReturnValue({ + filePath: '/abs/path/test.ts', + fileName: 'test.ts', + originalContent: 'OLD', + newContent: 'NEW', + isNewFile: false, + diffStat: { + model_added_lines: 0, + model_removed_lines: 0, + model_added_chars: 0, + model_removed_chars: 0, + user_added_lines: 0, + user_removed_lines: 0, + user_added_chars: 0, + user_removed_chars: 0, + }, + fileDiff: 'diff', + }); - const toolMsg: MessageRecord = { - type: 'gemini', - id: '2', - timestamp: '2', - content: '', - toolCalls: [ + const userMsg = { + type: 'user', + id: 'target', + } as unknown as MessageRecord; + const conversation = { + messages: [ + userMsg, { - name: 'replace', - id: 'tool-call-1', - status: 'success', - timestamp: '2', - args: {}, - resultDisplay: { - fileName: 'file.txt', - filePath: path.resolve('/root/file.txt'), - originalContent: original, - newContent: agentModified, - isNewFile: false, - diffStat: mockDiffStat, - }, - }, - ] as unknown as ToolCallRecord[], + type: 'gemini', + toolCalls: [{ resultDisplay: 'diff' } as unknown as ToolCallRecord], + } as unknown as MessageRecord, + ], }; - mockConversation.messages = [ - { type: 'user', content: 'start', id: '1', timestamp: '1' }, - toolMsg, - ]; - vi.mocked(fs.readFile).mockResolvedValue(userModified); + // Current content is completely unrelated - diff won't apply + vi.mocked(fs.readFile).mockResolvedValue('UNRELATED'); - await revertFileChanges(mockConversation, '1'); + await revertFileChanges( + conversation as unknown as ConversationRecord, + 'target', + ); expect(fs.writeFile).not.toHaveBeenCalled(); expect(coreEvents.emitFeedback).toHaveBeenCalledWith( 'warning', - expect.stringContaining('Smart revert for file.txt failed'), + expect.stringContaining('Smart revert for test.ts failed'), ); }); it('emits error if fs.readFile fails with a generic error', async () => { - const toolMsg: MessageRecord = { - type: 'gemini', - id: '2', - timestamp: '2', - content: '', - toolCalls: [ + const { getFileDiffFromResultDisplay } = await import( + '@google/gemini-cli-core' + ); + vi.mocked(getFileDiffFromResultDisplay).mockReturnValue({ + filePath: '/abs/path/test.ts', + fileName: 'test.ts', + originalContent: 'OLD', + newContent: 'NEW', + isNewFile: false, + diffStat: { + model_added_lines: 0, + model_removed_lines: 0, + model_added_chars: 0, + model_removed_chars: 0, + user_added_lines: 0, + user_removed_lines: 0, + user_added_chars: 0, + user_removed_chars: 0, + }, + fileDiff: 'diff', + }); + + const userMsg = { + type: 'user', + id: 'target', + } as unknown as MessageRecord; + const conversation = { + messages: [ + userMsg, { - name: 'replace', - id: 'tool-call-1', - status: 'success', - timestamp: '2', - args: {}, - resultDisplay: { - fileName: 'file.txt', - filePath: path.resolve('/root/file.txt'), - originalContent: 'old', - newContent: 'new', - isNewFile: false, - diffStat: mockDiffStat, - }, - }, - ] as unknown as ToolCallRecord[], + type: 'gemini', + toolCalls: [{ resultDisplay: 'diff' } as unknown as ToolCallRecord], + } as unknown as MessageRecord, + ], }; - mockConversation.messages = [ - { type: 'user', content: 'start', id: '1', timestamp: '1' }, - toolMsg, - ]; - // Simulate a generic file read error - vi.mocked(fs.readFile).mockRejectedValue(new Error('Permission denied')); + vi.mocked(fs.readFile).mockRejectedValue(new Error('disk failure')); + + await revertFileChanges( + conversation as unknown as ConversationRecord, + 'target', + ); - await revertFileChanges(mockConversation, '1'); - expect(fs.writeFile).not.toHaveBeenCalled(); expect(coreEvents.emitFeedback).toHaveBeenCalledWith( 'error', - 'Error reading file.txt during revert: Permission denied', + expect.stringContaining( + 'Error reading test.ts during revert: disk failure', + ), expect.any(Error), ); }); diff --git a/packages/core/src/skills/skillLoader.ts b/packages/core/src/skills/skillLoader.ts index cbd1f238bd..be962eaa67 100644 --- a/packages/core/src/skills/skillLoader.ts +++ b/packages/core/src/skills/skillLoader.ts @@ -25,6 +25,8 @@ export interface SkillDefinition { body: string; /** Whether the skill is currently disabled. */ disabled?: boolean; + /** Whether the skill is a built-in skill. */ + isBuiltin?: boolean; } const FRONTMATTER_REGEX = /^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)/; diff --git a/packages/core/src/skills/skillManager.test.ts b/packages/core/src/skills/skillManager.test.ts index 4bd200e4d7..293115267c 100644 --- a/packages/core/src/skills/skillManager.test.ts +++ b/packages/core/src/skills/skillManager.test.ts @@ -163,4 +163,45 @@ description: desc1 expect(service.getAllSkills()).toHaveLength(1); expect(service.getAllSkills()[0].disabled).toBe(true); }); + + it('should filter built-in skills in getDisplayableSkills', async () => { + const service = new SkillManager(); + + // @ts-expect-error accessing private property for testing + service.skills = [ + { + name: 'regular-skill', + description: 'regular', + location: 'loc1', + body: 'body', + isBuiltin: false, + }, + { + name: 'builtin-skill', + description: 'builtin', + location: 'loc2', + body: 'body', + isBuiltin: true, + }, + { + name: 'disabled-builtin', + description: 'disabled builtin', + location: 'loc3', + body: 'body', + isBuiltin: true, + disabled: true, + }, + ]; + + const displayable = service.getDisplayableSkills(); + expect(displayable).toHaveLength(1); + expect(displayable[0].name).toBe('regular-skill'); + + const all = service.getAllSkills(); + expect(all).toHaveLength(3); + + const enabled = service.getSkills(); + expect(enabled).toHaveLength(2); + expect(enabled.map((s) => s.name)).toContain('builtin-skill'); + }); }); diff --git a/packages/core/src/skills/skillManager.ts b/packages/core/src/skills/skillManager.ts index 22e0858cc8..0279df5a65 100644 --- a/packages/core/src/skills/skillManager.ts +++ b/packages/core/src/skills/skillManager.ts @@ -31,24 +31,36 @@ export class SkillManager { ): Promise { this.clearSkills(); - // 1. Extension skills (lowest precedence) + // 1. Built-in skills (lowest precedence) + await this.discoverBuiltinSkills(); + + // 2. Extension skills for (const extension of extensions) { if (extension.isActive && extension.skills) { this.addSkillsWithPrecedence(extension.skills); } } - // 2. User skills + // 3. User skills const userSkills = await loadSkillsFromDir(Storage.getUserSkillsDir()); this.addSkillsWithPrecedence(userSkills); - // 3. Project skills (highest precedence) + // 4. Project skills (highest precedence) const projectSkills = await loadSkillsFromDir( storage.getProjectSkillsDir(), ); this.addSkillsWithPrecedence(projectSkills); } + /** + * Discovers built-in skills. + */ + private async discoverBuiltinSkills(): Promise { + // Built-in skills can be added here. + // For now, this is a placeholder for where built-in skills will be loaded from. + // They could be loaded from a specific directory within the package. + } + private addSkillsWithPrecedence(newSkills: SkillDefinition[]): void { const skillMap = new Map(); for (const skill of [...this.skills, ...newSkills]) { @@ -64,6 +76,14 @@ export class SkillManager { return this.skills.filter((s) => !s.disabled); } + /** + * Returns the list of enabled discovered skills that should be displayed in the UI. + * This excludes built-in skills. + */ + getDisplayableSkills(): SkillDefinition[] { + return this.skills.filter((s) => !s.disabled && !s.isBuiltin); + } + /** * Returns all discovered skills, including disabled ones. */ @@ -82,8 +102,11 @@ export class SkillManager { * Sets the list of disabled skill names. */ setDisabledSkills(disabledNames: string[]): void { + const lowercaseDisabledNames = disabledNames.map((n) => n.toLowerCase()); for (const skill of this.skills) { - skill.disabled = disabledNames.includes(skill.name); + skill.disabled = lowercaseDisabledNames.includes( + skill.name.toLowerCase(), + ); } } @@ -91,7 +114,10 @@ export class SkillManager { * Reads the full content (metadata + body) of a skill by name. */ getSkill(name: string): SkillDefinition | null { - return this.skills.find((s) => s.name === name) ?? null; + const lowercaseName = name.toLowerCase(); + return ( + this.skills.find((s) => s.name.toLowerCase() === lowercaseName) ?? null + ); } /** diff --git a/packages/core/src/tools/activate-skill.test.ts b/packages/core/src/tools/activate-skill.test.ts index b997a67bdc..553a34dd43 100644 --- a/packages/core/src/tools/activate-skill.test.ts +++ b/packages/core/src/tools/activate-skill.test.ts @@ -76,6 +76,34 @@ describe('ActivateSkillTool', () => { expect(details.prompt).toContain('Mock folder structure'); }); + it('should skip confirmation for built-in skills', async () => { + const builtinSkill = { + name: 'builtin-skill', + description: 'A built-in skill', + location: '/path/to/builtin/SKILL.md', + isBuiltin: true, + body: 'Built-in instructions', + }; + vi.mocked(mockConfig.getSkillManager().getSkill).mockReturnValue( + builtinSkill, + ); + vi.mocked(mockConfig.getSkillManager().getSkills).mockReturnValue([ + builtinSkill, + ]); + + const params = { name: 'builtin-skill' }; + const toolWithBuiltin = new ActivateSkillTool(mockConfig, mockMessageBus); + const invocation = toolWithBuiltin.build(params); + + const details = await ( + invocation as unknown as { + getConfirmationDetails: (signal: AbortSignal) => Promise; + } + ).getConfirmationDetails(new AbortController().signal); + + expect(details).toBe(false); + }); + it('should activate a valid skill and return its content in XML tags', async () => { const params = { name: 'test-skill' }; const invocation = tool.build(params); diff --git a/packages/core/src/tools/activate-skill.ts b/packages/core/src/tools/activate-skill.ts index e6f1a9e6b7..381ad66976 100644 --- a/packages/core/src/tools/activate-skill.ts +++ b/packages/core/src/tools/activate-skill.ts @@ -80,6 +80,10 @@ class ActivateSkillToolInvocation extends BaseToolInvocation< return false; } + if (skill.isBuiltin) { + return false; + } + const folderStructure = await this.getOrFetchFolderStructure( skill.location, ); From 3090008b1c0f60058afce5750cb01717ea3a4152 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Sat, 10 Jan 2026 03:59:38 -0800 Subject: [PATCH 109/713] fix(skills): remove "Restart required" message from non-interactive commands (#16307) --- packages/cli/src/commands/skills/disable.test.ts | 2 +- packages/cli/src/commands/skills/disable.ts | 5 +---- packages/cli/src/commands/skills/enable.test.ts | 4 ++-- packages/cli/src/commands/skills/enable.ts | 5 +---- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/cli/src/commands/skills/disable.test.ts b/packages/cli/src/commands/skills/disable.test.ts index 4fa8403702..b7bc8805c8 100644 --- a/packages/cli/src/commands/skills/disable.test.ts +++ b/packages/cli/src/commands/skills/disable.test.ts @@ -80,7 +80,7 @@ describe('skills disable command', () => { ); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" disabled by adding it to the disabled list in user (/user/settings.json) settings. Restart required to take effect.', + 'Skill "skill1" disabled by adding it to the disabled list in user (/user/settings.json) settings.', ); }); diff --git a/packages/cli/src/commands/skills/disable.ts b/packages/cli/src/commands/skills/disable.ts index f1831654f5..e0b657afbc 100644 --- a/packages/cli/src/commands/skills/disable.ts +++ b/packages/cli/src/commands/skills/disable.ts @@ -23,13 +23,10 @@ export async function handleDisable(args: DisableArgs) { const settings = loadSettings(workspaceDir); const result = disableSkill(settings, name, scope); - let feedback = renderSkillActionFeedback( + const feedback = renderSkillActionFeedback( result, (label, path) => `${chalk.bold(label)} (${chalk.dim(path)})`, ); - if (result.status === 'success') { - feedback += ' Restart required to take effect.'; - } debugLogger.log(feedback); } diff --git a/packages/cli/src/commands/skills/enable.test.ts b/packages/cli/src/commands/skills/enable.test.ts index b3a96d5967..5874072130 100644 --- a/packages/cli/src/commands/skills/enable.test.ts +++ b/packages/cli/src/commands/skills/enable.test.ts @@ -81,7 +81,7 @@ describe('skills enable command', () => { ); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" enabled by removing it from the disabled list in user (/user/settings.json) and project (/project/settings.json) settings. Restart required to take effect.', + 'Skill "skill1" enabled by removing it from the disabled list in user (/user/settings.json) and project (/project/settings.json) settings.', ); }); @@ -122,7 +122,7 @@ describe('skills enable command', () => { ); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" enabled by removing it from the disabled list in project (/workspace/settings.json) and user (/user/settings.json) settings. Restart required to take effect.', + 'Skill "skill1" enabled by removing it from the disabled list in project (/workspace/settings.json) and user (/user/settings.json) settings.', ); }); diff --git a/packages/cli/src/commands/skills/enable.ts b/packages/cli/src/commands/skills/enable.ts index 1e1cc12e49..bc9d0066b1 100644 --- a/packages/cli/src/commands/skills/enable.ts +++ b/packages/cli/src/commands/skills/enable.ts @@ -22,13 +22,10 @@ export async function handleEnable(args: EnableArgs) { const settings = loadSettings(workspaceDir); const result = enableSkill(settings, name); - let feedback = renderSkillActionFeedback( + const feedback = renderSkillActionFeedback( result, (label, path) => `${chalk.bold(label)} (${chalk.dim(path)})`, ); - if (result.status === 'success') { - feedback += ' Restart required to take effect.'; - } debugLogger.log(feedback); } From 6f7d7981894ad34553d8f0ba04c1b099ab1451ff Mon Sep 17 00:00:00 2001 From: Vedant Mahajan Date: Sat, 10 Jan 2026 22:19:15 +0530 Subject: [PATCH 110/713] remove unused sessionHookTriggers and exports (#16324) --- packages/core/src/core/sessionHookTriggers.ts | 108 ------------------ packages/core/src/hooks/index.ts | 7 -- 2 files changed, 115 deletions(-) delete mode 100644 packages/core/src/core/sessionHookTriggers.ts diff --git a/packages/core/src/core/sessionHookTriggers.ts b/packages/core/src/core/sessionHookTriggers.ts deleted file mode 100644 index 149a84edbd..0000000000 --- a/packages/core/src/core/sessionHookTriggers.ts +++ /dev/null @@ -1,108 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import type { MessageBus } from '../confirmation-bus/message-bus.js'; -import { - MessageBusType, - type HookExecutionRequest, - type HookExecutionResponse, -} from '../confirmation-bus/types.js'; -import { - type SessionStartSource, - type SessionEndReason, - type PreCompressTrigger, - createHookOutput, - type DefaultHookOutput, -} from '../hooks/types.js'; -import { debugLogger } from '../utils/debugLogger.js'; - -/** - * Fires the SessionStart hook. - * - * @param messageBus The message bus to use for hook communication - * @param source The source/trigger of the session start - * @returns The output from the SessionStart hook, or undefined if failed/no output - */ -export async function fireSessionStartHook( - messageBus: MessageBus, - source: SessionStartSource, -): Promise { - try { - const response = await messageBus.request< - HookExecutionRequest, - HookExecutionResponse - >( - { - type: MessageBusType.HOOK_EXECUTION_REQUEST, - eventName: 'SessionStart', - input: { - source, - }, - }, - MessageBusType.HOOK_EXECUTION_RESPONSE, - ); - - if (response.output) { - return createHookOutput('SessionStart', response.output); - } - return undefined; - } catch (error) { - debugLogger.debug(`SessionStart hook failed:`, error); - return undefined; - } -} - -/** - * Fires the SessionEnd hook. - * - * @param messageBus The message bus to use for hook communication - * @param reason The reason for the session end - */ -export async function fireSessionEndHook( - messageBus: MessageBus, - reason: SessionEndReason, -): Promise { - try { - await messageBus.request( - { - type: MessageBusType.HOOK_EXECUTION_REQUEST, - eventName: 'SessionEnd', - input: { - reason, - }, - }, - MessageBusType.HOOK_EXECUTION_RESPONSE, - ); - } catch (error) { - debugLogger.debug(`SessionEnd hook failed:`, error); - } -} - -/** - * Fires the PreCompress hook. - * - * @param messageBus The message bus to use for hook communication - * @param trigger The trigger type (manual or auto) - */ -export async function firePreCompressHook( - messageBus: MessageBus, - trigger: PreCompressTrigger, -): Promise { - try { - await messageBus.request( - { - type: MessageBusType.HOOK_EXECUTION_REQUEST, - eventName: 'PreCompress', - input: { - trigger, - }, - }, - MessageBusType.HOOK_EXECUTION_RESPONSE, - ); - } catch (error) { - debugLogger.debug(`PreCompress hook failed:`, error); - } -} diff --git a/packages/core/src/hooks/index.ts b/packages/core/src/hooks/index.ts index 223ac25e42..b8e54fdc2f 100644 --- a/packages/core/src/hooks/index.ts +++ b/packages/core/src/hooks/index.ts @@ -20,10 +20,3 @@ export type { HookRegistryEntry } from './hookRegistry.js'; export { ConfigSource } from './types.js'; export type { AggregatedHookResult } from './hookAggregator.js'; export type { HookEventContext } from './hookPlanner.js'; - -// Export hook trigger functions -export { - fireSessionStartHook, - fireSessionEndHook, - firePreCompressHook, -} from '../core/sessionHookTriggers.js'; From 72dae7e0eebc7da2656c83daa4fea5a1226c854d Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Sat, 10 Jan 2026 14:58:36 -0500 Subject: [PATCH 111/713] Triage action cleanup (#16319) --- .../gemini-automated-issue-triage.yml | 17 ++++-- .../gemini-scheduled-issue-triage.yml | 60 +++---------------- scripts/relabel_issues.sh | 42 +++++++++++++ 3 files changed, 61 insertions(+), 58 deletions(-) create mode 100755 scripts/relabel_issues.sh diff --git a/.github/workflows/gemini-automated-issue-triage.yml b/.github/workflows/gemini-automated-issue-triage.yml index 864174ca1c..02809630bc 100644 --- a/.github/workflows/gemini-automated-issue-triage.yml +++ b/.github/workflows/gemini-automated-issue-triage.yml @@ -14,9 +14,15 @@ on: description: 'issue number to triage' required: true type: 'number' + workflow_call: + inputs: + issue_number: + description: 'issue number to triage' + required: false + type: 'string' concurrency: - group: '${{ github.workflow }}-${{ github.event.issue.number || github.event.inputs.issue_number }}' + group: '${{ github.workflow }}-${{ github.event.issue.number || github.event.inputs.issue_number || inputs.issue_number }}' cancel-in-progress: true defaults: @@ -34,7 +40,7 @@ permissions: jobs: triage-issue: if: |- - github.repository == 'google-gemini/gemini-cli' && + (github.repository == 'google-gemini/gemini-cli' || github.repository == 'google-gemini/maintainers-gemini-cli') && ( github.event_name == 'workflow_dispatch' || ( @@ -57,10 +63,11 @@ jobs: with: github-token: '${{ secrets.GITHUB_TOKEN }}' script: | + const issueNumber = ${{ github.event.inputs.issue_number || inputs.issue_number }}; const { data: issue } = await github.rest.issues.get({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: ${{ github.event.inputs.issue_number }}, + issue_number: issueNumber, }); core.setOutput('title', issue.title); core.setOutput('body', issue.body); @@ -71,7 +78,7 @@ jobs: if: |- github.event_name == 'workflow_dispatch' env: - ISSUE_NUMBER_INPUT: '${{ github.event.inputs.issue_number }}' + ISSUE_NUMBER_INPUT: '${{ github.event.inputs.issue_number || inputs.issue_number }}' LABELS: '${{ steps.get_issue_data.outputs.labels }}' run: | if echo "${LABELS}" | grep -q 'area/'; then @@ -127,7 +134,7 @@ jobs: ISSUE_BODY: >- ${{ github.event_name == 'workflow_dispatch' && steps.get_issue_data.outputs.body || github.event.issue.body }} ISSUE_NUMBER: >- - ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.issue_number || github.event.issue.number }} + ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.issue_number || inputs.issue_number) || github.event.issue.number }} REPOSITORY: '${{ github.repository }}' AVAILABLE_LABELS: '${{ steps.get_labels.outputs.available_labels }}' with: diff --git a/.github/workflows/gemini-scheduled-issue-triage.yml b/.github/workflows/gemini-scheduled-issue-triage.yml index 8887a47413..a892ddbe13 100644 --- a/.github/workflows/gemini-scheduled-issue-triage.yml +++ b/.github/workflows/gemini-scheduled-issue-triage.yml @@ -116,12 +116,12 @@ jobs: 1. You are only able to use the echo command. Review the available labels in the environment variable: "${AVAILABLE_LABELS}". 2. Check environment variable for issues to triage: $ISSUES_TO_TRIAGE (JSON array of issues) 3. Review the issue title, body and any comments provided in the environment variables. - 4. Identify the most relevant labels from the existing labels, focusing on kind/*, area/*, sub-area/* and priority/*. - 5. If the issue already has area/ label, dont try to change it. Similarly, if the issue already has a kind/ label don't change it. And if the issue already has a priority/ label do not change it for example: - If an issue has area/core and kind/bug you will only add a priority/ label. - Instead if an issue has no labels, you will could add one lable of each kind. + 4. Identify the most relevant labels from the existing labels, focusing on kind/* and priority/*. + 5. If the issue already has a kind/ label don't change it. And if the issue already has a priority/ label do not change it for example: + If an issue has kind/bug you will only add a priority/ label. + Instead if an issue has no labels, you could add one label of each kind. 6. Identify other applicable labels based on the issue content, such as status/*, help wanted, good first issue, etc. - 7. For area/* and kind/* limit yourself to only the single most applicable label in each case. + 7. For kind/* limit yourself to only the single most applicable label. 8. Give me a single short explanation about why you are selecting each label in the process. 9. Output a JSON array of objects, each containing the issue number and the labels to add and remove, along with an explanation. For example: @@ -147,7 +147,7 @@ jobs: 11. If you see that the issue doesn't look like it has sufficient information recommend the status/need-information label and leave a comment politely requesting the relevant information, eg.. if repro steps are missing request for repro steps. if version information is missing request for version information into the explanation section below. - After identifying appropriate labels to an issue, add "status/need-triage" label to labels_to_remove in the output. 12. If you think an issue might be a Priority/P0 do not apply the priority/p0 label. Instead apply a status/manual-triage label and include a note in your explanation. - 13. If you are uncertain and have not been able to apply one each of kind/, area/ and priority/ , apply the status/manual-triage label. + 13. If you are uncertain and have not been able to apply one each of kind/ and priority/ , apply the status/manual-triage label. ## Guidelines @@ -157,9 +157,8 @@ jobs: - Do not add comments or modify the issue content. - Do not remove the following labels maintainer, help wanted or good first issue. - Triage only the current issue. - - Identify only one area/ label - Identify only one kind/ label (Do not apply kind/duplicate or kind/parent-issue) - - Identify all applicable sub-area/* and priority/* labels based on the issue content. It's ok to have multiple of these. + - Identify all applicable priority/* labels based on the issue content. It's ok to have multiple of these. - Once you categorize the issue if it needs information bump down the priority by 1 eg.. a p0 would become a p1 a p1 would become a p2. P2 and P3 can stay as is in this scenario. Categorization Guidelines: P0: Critical / Blocker @@ -206,51 +205,6 @@ jobs: - If users are talking about issues where the model gets downgraded from pro to flash then i want you to categorize that as a performance issue - This product is designed to use different models eg.. using pro, downgrading to flash etc. - When users report that they dont expect the model to change those would be categorized as feature requests. - Definition of Areas - area/ux: - - Issues concerning user-facing elements like command usability, interactive features, help docs, and perceived performance. - - I am seeing my screen flicker when using Gemini CLI - - I am seeing the output malformed - - Theme changes aren't taking effect - - My keyboard inputs arent' being recognzied - area/platform: - - Issues related to installation, packaging, OS compatibility (Windows, macOS, Linux), and the underlying CLI framework. - area/background: Issues related to long-running background tasks, daemons, and autonomous or proactive agent features. - area/models: - - i am not getting a response that is reasonable or expected. this can include things like - - I am calling a tool and the tool is not performing as expected. - - i am expecting a tool to be called and it is not getting called , - - Including experience when using - - built-in tools (e.g., web search, code interpreter, read file, writefile, etc..), - - Function calling issues should be under this area - - i am getting responses from the model that are malformed. - - Issues concerning Gemini quality of response and inference, - - Issues talking about unnecessary token consumption. - - Issues talking about Model getting stuck in a loop be watchful as this could be the root cause for issues that otherwise seem like model performance issues. - - Memory compression - - unexpected responses, - - poor quality of generated code - area/tools: - - These are primarily issues related to Model Context Protocol - - These are issues that mention MCP support - - feature requests asking for support for new tools. - area/core: - - Issues with fundamental components like command parsing, configuration management, session state, and the main API client logic. Introducing multi-modality - area/contribution: - - Issues related to improving the developer contribution experience, such as CI/CD pipelines, build scripts, and test automation infrastructure. - area/authentication: - - Issues related to user identity, login flows, API key handling, credential storage, and access token management, unable to sign in selecting wrong authentication path etc.. - area/security-privacy: - - Issues concerning vulnerability patching, dependency security, data sanitization, privacy controls, and preventing unauthorized data access. - area/extensibility: - - Issues related to the plugin system, extension APIs, or making the CLI's functionality available in other applications, github actions, ide support etc.. - area/performance: - - Issues focused on model performance - - Issues with running out of capacity, - - 429 errors etc.. - - could also pertain to latency, - - other general software performance like, memory usage, CPU consumption, and algorithmic efficiency. - - Switching models from one to the other unexpectedly. - name: 'Apply Labels to Issues' if: |- diff --git a/scripts/relabel_issues.sh b/scripts/relabel_issues.sh new file mode 100755 index 0000000000..82857bfa45 --- /dev/null +++ b/scripts/relabel_issues.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# scripts/relabel_issues.sh +# Usage: ./scripts/relabel_issues.sh [repository] + +set -e + +OLD_LABEL="$1" +NEW_LABEL="$2" +REPO="${3:-google-gemini/gemini-cli}" + +if [ -z "$OLD_LABEL" ] || [ -z "$NEW_LABEL" ]; then + echo "Usage: $0 [repository]" + echo "Example: $0 'area/models' 'area/agent'" + exit 1 +fi + +echo "🔍 Searching for open issues in '$REPO' with label '$OLD_LABEL'..." + +# Fetch issues with the old label +ISSUES=$(gh issue list --repo "$REPO" --label "$OLD_LABEL" --state open --limit 1000 --json number,title) + +COUNT=$(echo "$ISSUES" | jq '. | length') + +if [ "$COUNT" -eq 0 ]; then + echo "✅ No issues found with label '$OLD_LABEL'." + exit 0 +fi + +echo "found $COUNT issues to relabel." + +# Iterate and update +echo "$ISSUES" | jq -r '.[] | "\(.number) \(.title)"' | while read -r number title; do + echo "🔄 Processing #$number: $title" + echo " - Removing: $OLD_LABEL" + echo " + Adding: $NEW_LABEL" + + gh issue edit "$number" --repo "$REPO" --add-label "$NEW_LABEL" --remove-label "$OLD_LABEL" + + echo " ✅ Done." +done + +echo "🎉 All issues relabeled!" From d130d99ff02e6908a7e517ec7b2b69073f748d40 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Sat, 10 Jan 2026 16:23:41 -0500 Subject: [PATCH 112/713] fix: Add event-driven trigger to issue triage workflow (#16334) --- .../gemini-scheduled-issue-triage.yml | 23 ++++++++--- scripts/batch_triage.sh | 40 +++++++++++++++++++ 2 files changed, 58 insertions(+), 5 deletions(-) create mode 100755 scripts/batch_triage.sh diff --git a/.github/workflows/gemini-scheduled-issue-triage.yml b/.github/workflows/gemini-scheduled-issue-triage.yml index a892ddbe13..76752388a7 100644 --- a/.github/workflows/gemini-scheduled-issue-triage.yml +++ b/.github/workflows/gemini-scheduled-issue-triage.yml @@ -1,12 +1,16 @@ name: '📋 Gemini Scheduled Issue Triage' on: + issues: + types: + - 'opened' + - 'reopened' schedule: - cron: '0 * * * *' # Runs every hour workflow_dispatch: concurrency: - group: '${{ github.workflow }}' + group: '${{ github.workflow }}-${{ github.event.number || github.run_id }}' cancel-in-progress: true defaults: @@ -35,7 +39,17 @@ jobs: private-key: '${{ secrets.PRIVATE_KEY }}' permission-issues: 'write' + - name: 'Get issue from event' + if: github.event_name == 'issues' + id: 'get_issue_from_event' + run: | + set -euo pipefail + ISSUE_JSON=$(jq -n --argjson issue "$${{ toJSON(github.event.issue) }}" '[{number: $issue.number, title: $issue.title, body: $issue.body}]') + echo "issues_to_triage=${ISSUE_JSON}" >> "${GITHUB_OUTPUT}" + echo "✅ Found issue #${{ github.event.issue.number }} from event to triage! 🎯" + - name: 'Find untriaged issues' + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' id: 'find_issues' env: GITHUB_TOKEN: '${{ steps.generate_token.outputs.token }}' @@ -76,13 +90,12 @@ jobs: return labelNames; - name: 'Run Gemini Issue Analysis' - if: |- - ${{ steps.find_issues.outputs.issues_to_triage != '[]' }} + if: steps.get_issue_from_event.outputs.issues_to_triage != '[]' || steps.find_issues.outputs.issues_to_triage != '[]' uses: 'google-github-actions/run-gemini-cli@a3bf79042542528e91937b3a3a6fbc4967ee3c31' # ratchet:google-github-actions/run-gemini-cli@v0 id: 'gemini_issue_analysis' env: GITHUB_TOKEN: '' # Do not pass any auth token here since this runs on untrusted inputs - ISSUES_TO_TRIAGE: '${{ steps.find_issues.outputs.issues_to_triage }}' + ISSUES_TO_TRIAGE: "${{ steps.get_issue_from_event.outputs.issues_to_triage || steps.find_issues.outputs.issues_to_triage }}" REPOSITORY: '${{ github.repository }}' AVAILABLE_LABELS: '${{ steps.get_labels.outputs.available_labels }}' with: @@ -284,4 +297,4 @@ jobs: if ((!entry.labels_to_add || entry.labels_to_add.length === 0) && (!entry.labels_to_remove || entry.labels_to_remove.length === 0)) { core.info(`No labels to add or remove for #${issueNumber}, leaving as is`); } - } + } \ No newline at end of file diff --git a/scripts/batch_triage.sh b/scripts/batch_triage.sh new file mode 100755 index 0000000000..c6f1982491 --- /dev/null +++ b/scripts/batch_triage.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# scripts/batch_triage.sh +# Usage: ./scripts/batch_triage.sh [repository] +# Example: ./scripts/batch_triage.sh google-gemini/maintainers-gemini-cli + +set -e + +REPO="${1:-google-gemini/gemini-cli}" +WORKFLOW="gemini-automated-issue-triage.yml" + +echo "🔍 Searching for open issues in '$REPO' that need triage (missing 'area/' label)..." + +# Fetch open issues with number, title, and labels +# We fetch up to 1000 issues. +ISSUES_JSON=$(gh issue list --repo "$REPO" --state open --limit 1000 --json number,title,labels) + +# Filter issues that DO NOT have a label starting with 'area/' +TARGET_ISSUES=$(echo "$ISSUES_JSON" | jq '[.[] | select(.labels | map(.name) | any(startswith("area/")) | not)]') + +COUNT=$(echo "$TARGET_ISSUES" | jq '. | length') + +if [ "$COUNT" -eq 0 ]; then + echo "✅ No issues found needing triage in '$REPO'." + exit 0 +fi + +echo "🚀 Found $COUNT issues to triage." + +# Loop through and trigger workflow +echo "$TARGET_ISSUES" | jq -r '.[] | "\(.number)|\(.title)"' | while IFS="|" read -r number title; do + echo "▶️ Triggering triage for #$number: $title" + + # Trigger the workflow dispatch event + gh workflow run "$WORKFLOW" --repo "$REPO" -f issue_number="$number" + + # Sleep briefly to be nice to the API + sleep 1 +done + +echo "🎉 All triage workflows triggered!" From 446058cb1c717d59e383a6876343e7b4f25c07fe Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Sat, 10 Jan 2026 16:46:27 -0500 Subject: [PATCH 113/713] fix: fallback to GITHUB_TOKEN if App ID is missing --- .github/workflows/gemini-automated-issue-triage.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gemini-automated-issue-triage.yml b/.github/workflows/gemini-automated-issue-triage.yml index 02809630bc..b1251fee66 100644 --- a/.github/workflows/gemini-automated-issue-triage.yml +++ b/.github/workflows/gemini-automated-issue-triage.yml @@ -93,6 +93,7 @@ jobs: - name: 'Generate GitHub App Token' id: 'generate_token' + if: ${{ secrets.APP_ID != '' }} uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2 with: app-id: '${{ secrets.APP_ID }}' @@ -103,7 +104,7 @@ jobs: id: 'get_labels' uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' with: - github-token: '${{ steps.generate_token.outputs.token }}' + github-token: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}' script: |- const { data: labels } = await github.rest.issues.listLabelsForRepo({ owner: context.repo.owner, @@ -260,7 +261,7 @@ jobs: LABELS_OUTPUT: '${{ steps.gemini_issue_analysis.outputs.summary }}' uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' with: - github-token: '${{ steps.generate_token.outputs.token }}' + github-token: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}' script: | const rawOutput = process.env.LABELS_OUTPUT; core.info(`Raw output from model: ${rawOutput}`); @@ -326,7 +327,7 @@ jobs: RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' with: - github-token: '${{ steps.generate_token.outputs.token }}' + github-token: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}' script: |- github.rest.issues.createComment({ owner: context.repo.owner, From 33e3ed0f6ce244597f2a6f2d377fbb92a2a35008 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Sat, 10 Jan 2026 19:31:17 -0500 Subject: [PATCH 114/713] fix(workflows): resolve triage workflow failures and actionlint errors (#16338) --- .../gemini-automated-issue-triage.yml | 4 +- .../gemini-scheduled-issue-triage.yml | 39 ++++++++++++------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/.github/workflows/gemini-automated-issue-triage.yml b/.github/workflows/gemini-automated-issue-triage.yml index b1251fee66..47801fcb9b 100644 --- a/.github/workflows/gemini-automated-issue-triage.yml +++ b/.github/workflows/gemini-automated-issue-triage.yml @@ -93,7 +93,9 @@ jobs: - name: 'Generate GitHub App Token' id: 'generate_token' - if: ${{ secrets.APP_ID != '' }} + env: + APP_ID: '${{ secrets.APP_ID }}' + if: "${{ env.APP_ID != '' }}" uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2 with: app-id: '${{ secrets.APP_ID }}' diff --git a/.github/workflows/gemini-scheduled-issue-triage.yml b/.github/workflows/gemini-scheduled-issue-triage.yml index 76752388a7..6c3fbb7c63 100644 --- a/.github/workflows/gemini-scheduled-issue-triage.yml +++ b/.github/workflows/gemini-scheduled-issue-triage.yml @@ -40,16 +40,18 @@ jobs: permission-issues: 'write' - name: 'Get issue from event' - if: github.event_name == 'issues' + if: "github.event_name == 'issues'" id: 'get_issue_from_event' + env: + ISSUE_EVENT: '${{ toJSON(github.event.issue) }}' run: | set -euo pipefail - ISSUE_JSON=$(jq -n --argjson issue "$${{ toJSON(github.event.issue) }}" '[{number: $issue.number, title: $issue.title, body: $issue.body}]') + ISSUE_JSON=$(echo "$ISSUE_EVENT" | jq -c '[{number: .number, title: .title, body: .body}]') echo "issues_to_triage=${ISSUE_JSON}" >> "${GITHUB_OUTPUT}" echo "✅ Found issue #${{ github.event.issue.number }} from event to triage! 🎯" - name: 'Find untriaged issues' - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + if: "github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'" id: 'find_issues' env: GITHUB_TOKEN: '${{ steps.generate_token.outputs.token }}' @@ -90,12 +92,14 @@ jobs: return labelNames; - name: 'Run Gemini Issue Analysis' - if: steps.get_issue_from_event.outputs.issues_to_triage != '[]' || steps.find_issues.outputs.issues_to_triage != '[]' + if: |- + (steps.get_issue_from_event.outputs.issues_to_triage != '' && steps.get_issue_from_event.outputs.issues_to_triage != '[]') || + (steps.find_issues.outputs.issues_to_triage != '' && steps.find_issues.outputs.issues_to_triage != '[]') uses: 'google-github-actions/run-gemini-cli@a3bf79042542528e91937b3a3a6fbc4967ee3c31' # ratchet:google-github-actions/run-gemini-cli@v0 id: 'gemini_issue_analysis' env: GITHUB_TOKEN: '' # Do not pass any auth token here since this runs on untrusted inputs - ISSUES_TO_TRIAGE: "${{ steps.get_issue_from_event.outputs.issues_to_triage || steps.find_issues.outputs.issues_to_triage }}" + ISSUES_TO_TRIAGE: '${{ steps.get_issue_from_event.outputs.issues_to_triage || steps.find_issues.outputs.issues_to_triage }}' REPOSITORY: '${{ github.repository }}' AVAILABLE_LABELS: '${{ steps.get_labels.outputs.available_labels }}' with: @@ -234,16 +238,23 @@ jobs: core.info(`Raw labels JSON: ${rawLabels}`); let parsedLabels; try { + // First, try to parse the raw output as JSON. + parsedLabels = JSON.parse(rawLabels.trim()); + } catch (jsonError) { + // If that fails, check for a markdown code block. + core.info(`Direct JSON parsing failed: ${jsonError.message}. Trying to extract from a markdown block.`); const jsonMatch = rawLabels.match(/```json\s*([\s\S]*?)\s*```/); - if (!jsonMatch || !jsonMatch[1]) { - throw new Error("Could not find a ```json ... ``` block in the output."); + if (jsonMatch && jsonMatch[1]) { + try { + parsedLabels = JSON.parse(jsonMatch[1].trim()); + } catch (markdownError) { + core.setFailed(`Failed to parse JSON even after extracting from markdown block: ${markdownError.message}\nRaw output: ${rawLabels}`); + return; + } + } else { + core.setFailed(`Output is not valid JSON and does not contain a JSON markdown block.\nRaw output: ${rawLabels}`); + return; } - const jsonString = jsonMatch[1].trim(); - parsedLabels = JSON.parse(jsonString); - core.info(`Parsed labels JSON: ${JSON.stringify(parsedLabels)}`); - } catch (err) { - core.setFailed(`Failed to parse labels JSON from Gemini output: ${err.message}\nRaw output: ${rawLabels}`); - return; } for (const entry of parsedLabels) { @@ -297,4 +308,4 @@ jobs: if ((!entry.labels_to_add || entry.labels_to_add.length === 0) && (!entry.labels_to_remove || entry.labels_to_remove.length === 0)) { core.info(`No labels to add or remove for #${issueNumber}, leaving as is`); } - } \ No newline at end of file + } From b9762a3ee1b348c23ba052c420626175afef3b0e Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Sat, 10 Jan 2026 19:34:59 -0500 Subject: [PATCH 115/713] docs: add note about experimental hooks (#16337) --- docs/hooks/index.md | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/docs/hooks/index.md b/docs/hooks/index.md index de3e00e31f..0c62957a9a 100644 --- a/docs/hooks/index.md +++ b/docs/hooks/index.md @@ -4,6 +4,19 @@ Hooks are scripts or programs that Gemini CLI executes at specific points in the agentic loop, allowing you to intercept and customize behavior without modifying the CLI's source code. +> **Note: Hooks are currently an experimental feature.** +> +> To use hooks, you must explicitly enable them in your `settings.json`: +> +> ```json +> { +> "tools": { "enableHooks": true }, +> "hooks": { "enabled": true } +> } +> ``` +> +> Both of these are needed in this experimental phase. + See [writing hooks guide](writing-hooks.md) for a tutorial on creating your first hook and a comprehensive example. @@ -29,10 +42,10 @@ Gemini CLI waits for all matching hooks to complete before continuing. ## Security and Risks -> [!WARNING] **Hooks execute arbitrary code with your user privileges.** - -By configuring hooks, you are explicitly allowing Gemini CLI to run shell -commands on your machine. Malicious or poorly configured hooks can: +> **Warning: Hooks execute arbitrary code with your user privileges.** +> +> By configuring hooks, you are explicitly allowing Gemini CLI to run shell +> commands on your machine. Malicious or poorly configured hooks can: - **Exfiltrate data**: Read sensitive files (`.env`, ssh keys) and send them to remote servers. @@ -46,7 +59,7 @@ project hook (identified by its name and command), but it is **your responsibility** to review these hooks (and any installed extensions) before trusting them. -> [!NOTE] Extension hooks are subject to a mandatory security warning and +> **Note:** Extension hooks are subject to a mandatory security warning and > consent flow during extension installation or update if hooks are detected. > You must explicitly approve the installation or update of any extension that > contains hooks. From 39b3f20a2285e85f265cc0a160ff34cc4de27321 Mon Sep 17 00:00:00 2001 From: Sandy Tao Date: Sun, 11 Jan 2026 21:22:49 +0800 Subject: [PATCH 116/713] feat(cli): implement passive activity logger for session analysis (#15829) --- packages/cli/src/gemini.test.tsx | 18 + packages/cli/src/gemini.tsx | 7 + packages/cli/src/nonInteractiveCli.test.ts | 3 +- packages/cli/src/utils/activityLogger.ts | 371 +++++++++++++++++++++ packages/core/src/config/storage.ts | 4 + 5 files changed, 402 insertions(+), 1 deletion(-) create mode 100644 packages/cli/src/utils/activityLogger.ts diff --git a/packages/cli/src/gemini.test.tsx b/packages/cli/src/gemini.test.tsx index 950705bfca..9619035b0d 100644 --- a/packages/cli/src/gemini.test.tsx +++ b/packages/cli/src/gemini.test.tsx @@ -142,6 +142,9 @@ vi.mock('./config/config.js', () => ({ getQuestion: vi.fn(() => ''), isInteractive: () => false, setTerminalBackground: vi.fn(), + storage: { + getProjectTempDir: vi.fn().mockReturnValue('/tmp/gemini-test'), + }, } as unknown as Config), parseArguments: vi.fn().mockResolvedValue({}), isDebugMode: vi.fn(() => false), @@ -436,6 +439,9 @@ describe('gemini.tsx main function kitty protocol', () => { getUsageStatisticsEnabled: () => false, getRemoteAdminSettings: () => undefined, setTerminalBackground: vi.fn(), + storage: { + getProjectTempDir: vi.fn().mockReturnValue('/tmp/gemini-test'), + }, } as unknown as Config); vi.mocked(loadSettings).mockReturnValue({ errors: [], @@ -793,6 +799,9 @@ describe('gemini.tsx main function kitty protocol', () => { getUsageStatisticsEnabled: () => false, getRemoteAdminSettings: () => undefined, setTerminalBackground: vi.fn(), + storage: { + getProjectTempDir: vi.fn().mockReturnValue('/tmp/gemini-test'), + }, } as any); // eslint-disable-line @typescript-eslint/no-explicit-any try { @@ -875,6 +884,9 @@ describe('gemini.tsx main function kitty protocol', () => { getUsageStatisticsEnabled: () => false, getRemoteAdminSettings: () => undefined, setTerminalBackground: vi.fn(), + storage: { + getProjectTempDir: vi.fn().mockReturnValue('/tmp/gemini-test'), + }, } as any); // eslint-disable-line @typescript-eslint/no-explicit-any // The mock is already set up at the top of the test @@ -1115,6 +1127,9 @@ describe('gemini.tsx main function exit codes', () => { getUsageStatisticsEnabled: () => false, getRemoteAdminSettings: () => undefined, setTerminalBackground: vi.fn(), + storage: { + getProjectTempDir: vi.fn().mockReturnValue('/tmp/gemini-test'), + }, } as unknown as Config); vi.mocked(loadSettings).mockReturnValue({ merged: { security: { auth: {} }, ui: {} }, @@ -1180,6 +1195,9 @@ describe('gemini.tsx main function exit codes', () => { getExtensions: () => [], getUsageStatisticsEnabled: () => false, setTerminalBackground: vi.fn(), + storage: { + getProjectTempDir: vi.fn().mockReturnValue('/tmp/gemini-test'), + }, getRemoteAdminSettings: () => undefined, } as unknown as Config); vi.mocked(loadSettings).mockReturnValue({ diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index 32284b132d..53153c2944 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -466,6 +466,13 @@ export async function main() { }); loadConfigHandle?.end(); + if (config.isInteractive() && config.storage && config.getDebugMode()) { + const { registerActivityLogger } = await import( + './utils/activityLogger.js' + ); + registerActivityLogger(config); + } + // Register config for telemetry shutdown // This ensures telemetry (including SessionEnd hooks) is properly flushed on exit registerTelemetryConfig(config); diff --git a/packages/cli/src/nonInteractiveCli.test.ts b/packages/cli/src/nonInteractiveCli.test.ts index c171d95a74..c4ce96452a 100644 --- a/packages/cli/src/nonInteractiveCli.test.ts +++ b/packages/cli/src/nonInteractiveCli.test.ts @@ -42,9 +42,10 @@ vi.mock('./ui/hooks/atCommandProcessor.js'); const mockCoreEvents = vi.hoisted(() => ({ on: vi.fn(), off: vi.fn(), - drainBacklogs: vi.fn(), emit: vi.fn(), + emitConsoleLog: vi.fn(), emitFeedback: vi.fn(), + drainBacklogs: vi.fn(), })); vi.mock('@google/gemini-cli-core', async (importOriginal) => { diff --git a/packages/cli/src/utils/activityLogger.ts b/packages/cli/src/utils/activityLogger.ts new file mode 100644 index 0000000000..486ed4858a --- /dev/null +++ b/packages/cli/src/utils/activityLogger.ts @@ -0,0 +1,371 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ +/* eslint-disable @typescript-eslint/no-this-alias */ + +import http from 'node:http'; +import https from 'node:https'; +import zlib from 'node:zlib'; +import fs from 'node:fs'; +import path from 'node:path'; +import { EventEmitter } from 'node:events'; +import { CoreEvent, coreEvents, debugLogger } from '@google/gemini-cli-core'; +import type { Config } from '@google/gemini-cli-core'; + +const ACTIVITY_ID_HEADER = 'x-activity-request-id'; + +export interface NetworkLog { + id: string; + timestamp: number; + method: string; + url: string; + headers: Record; + body?: string; + pending?: boolean; + response?: { + status: number; + headers: Record; + body?: string; + durationMs: number; + }; + error?: string; +} + +/** + * Capture utility for session activities (network and console). + * Provides a stream of events that can be persisted for analysis or inspection. + */ +export class ActivityLogger extends EventEmitter { + private static instance: ActivityLogger; + private isInterceptionEnabled = false; + private requestStartTimes = new Map(); + + static getInstance(): ActivityLogger { + if (!ActivityLogger.instance) { + ActivityLogger.instance = new ActivityLogger(); + } + return ActivityLogger.instance; + } + + private stringifyHeaders(headers: unknown): Record { + const result: Record = {}; + if (!headers) return result; + + if (headers instanceof Headers) { + headers.forEach((v, k) => { + result[k.toLowerCase()] = v; + }); + } else if (typeof headers === 'object' && headers !== null) { + for (const [key, val] of Object.entries(headers)) { + result[key.toLowerCase()] = Array.isArray(val) + ? val.join(', ') + : String(val); + } + } + return result; + } + + private sanitizeNetworkLog(log: any): any { + if (!log || typeof log !== 'object') return log; + + const sanitized = { ...log }; + + // Sanitize request headers + if (sanitized.headers) { + const headers = { ...sanitized.headers }; + for (const key of Object.keys(headers)) { + if ( + ['authorization', 'cookie', 'x-goog-api-key'].includes( + key.toLowerCase(), + ) + ) { + headers[key] = '[REDACTED]'; + } + } + sanitized.headers = headers; + } + + // Sanitize response headers + if (sanitized.response?.headers) { + const resHeaders = { ...sanitized.response.headers }; + for (const key of Object.keys(resHeaders)) { + if (['set-cookie'].includes(key.toLowerCase())) { + resHeaders[key] = '[REDACTED]'; + } + } + sanitized.response = { ...sanitized.response, headers: resHeaders }; + } + + return sanitized; + } + + private safeEmitNetwork(payload: any) { + this.emit('network', this.sanitizeNetworkLog(payload)); + } + + enable() { + if (this.isInterceptionEnabled) return; + this.isInterceptionEnabled = true; + + this.patchGlobalFetch(); + this.patchNodeHttp(); + } + + private patchGlobalFetch() { + if (!global.fetch) return; + const originalFetch = global.fetch; + + global.fetch = async (input: RequestInfo | URL, init?: RequestInit) => { + const url = + typeof input === 'string' + ? input + : input instanceof URL + ? input.toString() + : (input as any).url; + if (url.includes('127.0.0.1')) return originalFetch(input, init); + + const id = Math.random().toString(36).substring(7); + const method = (init?.method || 'GET').toUpperCase(); + + const newInit = { ...init }; + const headers = new Headers(init?.headers || {}); + headers.set(ACTIVITY_ID_HEADER, id); + newInit.headers = headers; + + let reqBody = ''; + if (init?.body) { + if (typeof init.body === 'string') reqBody = init.body; + else if (init.body instanceof URLSearchParams) + reqBody = init.body.toString(); + } + + this.requestStartTimes.set(id, Date.now()); + this.safeEmitNetwork({ + id, + timestamp: Date.now(), + method, + url, + headers: this.stringifyHeaders(newInit.headers), + body: reqBody, + pending: true, + }); + + try { + const response = await originalFetch(input, newInit); + const clonedRes = response.clone(); + + clonedRes + .text() + .then((text) => { + const startTime = this.requestStartTimes.get(id); + const durationMs = startTime ? Date.now() - startTime : 0; + this.requestStartTimes.delete(id); + + this.safeEmitNetwork({ + id, + pending: false, + response: { + status: response.status, + headers: this.stringifyHeaders(response.headers), + body: text, + durationMs, + }, + }); + }) + .catch((err) => { + const message = err instanceof Error ? err.message : String(err); + this.safeEmitNetwork({ + id, + pending: false, + error: `Failed to read response body: ${message}`, + }); + }); + + return response; + } catch (err: unknown) { + this.requestStartTimes.delete(id); + const message = err instanceof Error ? err.message : String(err); + this.safeEmitNetwork({ id, pending: false, error: message }); + throw err; + } + }; + } + + private patchNodeHttp() { + const self = this; + const originalRequest = http.request; + const originalHttpsRequest = https.request; + + const wrapRequest = (originalFn: any, args: any[], protocol: string) => { + const options = args[0]; + const url = + typeof options === 'string' + ? options + : options.href || + `${protocol}//${options.hostname || options.host || 'localhost'}${options.path || '/'}`; + + if (url.includes('127.0.0.1')) return originalFn.apply(http, args); + + const headers = + typeof options === 'object' && typeof options !== 'function' + ? (options as any).headers + : {}; + if (headers && headers[ACTIVITY_ID_HEADER]) { + delete headers[ACTIVITY_ID_HEADER]; + return originalFn.apply(http, args); + } + + const id = Math.random().toString(36).substring(7); + self.requestStartTimes.set(id, Date.now()); + const req = originalFn.apply(http, args); + const requestChunks: Buffer[] = []; + + const oldWrite = req.write; + const oldEnd = req.end; + + req.write = function (chunk: any, ...etc: any[]) { + if (chunk) { + const encoding = + typeof etc[0] === 'string' ? (etc[0] as BufferEncoding) : undefined; + requestChunks.push( + Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding), + ); + } + return oldWrite.apply(this, [chunk, ...etc]); + }; + + req.end = function (this: any, chunk: any, ...etc: any[]) { + if (chunk && typeof chunk !== 'function') { + const encoding = + typeof etc[0] === 'string' ? (etc[0] as BufferEncoding) : undefined; + requestChunks.push( + Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding), + ); + } + const body = Buffer.concat(requestChunks).toString('utf8'); + + self.safeEmitNetwork({ + id, + timestamp: Date.now(), + method: req.method || 'GET', + url, + headers: self.stringifyHeaders(req.getHeaders()), + body, + pending: true, + }); + return oldEnd.apply(this, [chunk, ...etc]); + }; + + req.on('response', (res: any) => { + const responseChunks: Buffer[] = []; + res.on('data', (chunk: Buffer) => + responseChunks.push(Buffer.from(chunk)), + ); + res.on('end', () => { + const buffer = Buffer.concat(responseChunks); + const encoding = res.headers['content-encoding']; + + const processBuffer = (finalBuffer: Buffer) => { + const resBody = finalBuffer.toString('utf8'); + const startTime = self.requestStartTimes.get(id); + const durationMs = startTime ? Date.now() - startTime : 0; + self.requestStartTimes.delete(id); + + self.safeEmitNetwork({ + id, + pending: false, + response: { + status: res.statusCode, + headers: self.stringifyHeaders(res.headers), + body: resBody, + durationMs, + }, + }); + }; + + if (encoding === 'gzip') { + zlib.gunzip(buffer, (err, decompressed) => { + processBuffer(err ? buffer : decompressed); + }); + } else if (encoding === 'deflate') { + zlib.inflate(buffer, (err, decompressed) => { + processBuffer(err ? buffer : decompressed); + }); + } else { + processBuffer(buffer); + } + }); + }); + + req.on('error', (err: any) => { + self.requestStartTimes.delete(id); + const message = err instanceof Error ? err.message : String(err); + self.safeEmitNetwork({ id, pending: false, error: message }); + }); + + return req; + }; + + http.request = (...args: any[]) => + wrapRequest(originalRequest, args, 'http:'); + https.request = (...args: any[]) => + wrapRequest(originalHttpsRequest, args, 'https:'); + } + + logConsole(payload: unknown) { + this.emit('console', payload); + } +} + +/** + * Registers the activity logger if debug mode and interactive session are enabled. + * Captures network and console logs to a session-specific JSONL file. + * + * @param config The CLI configuration + */ +export function registerActivityLogger(config: Config) { + if (config.isInteractive() && config.storage && config.getDebugMode()) { + const capture = ActivityLogger.getInstance(); + capture.enable(); + + const logsDir = config.storage.getProjectTempLogsDir(); + if (!fs.existsSync(logsDir)) { + fs.mkdirSync(logsDir, { recursive: true }); + } + + const logFile = path.join( + logsDir, + `session-${config.getSessionId()}.jsonl`, + ); + const writeToLog = (type: 'console' | 'network', payload: unknown) => { + try { + const entry = + JSON.stringify({ + type, + payload, + timestamp: Date.now(), + }) + '\n'; + + // Use asynchronous fire-and-forget to avoid blocking the event loop + fs.promises.appendFile(logFile, entry).catch((err) => { + debugLogger.error('Failed to write to activity log:', err); + }); + } catch (err) { + debugLogger.error('Failed to prepare activity log entry:', err); + } + }; + + capture.on('console', (payload) => writeToLog('console', payload)); + capture.on('network', (payload) => writeToLog('network', payload)); + + // Bridge CoreEvents to local capture + coreEvents.on(CoreEvent.ConsoleLog, (payload) => { + capture.logConsole(payload); + }); + } +} diff --git a/packages/core/src/config/storage.ts b/packages/core/src/config/storage.ts index bfadc2f7b7..da7142d09c 100644 --- a/packages/core/src/config/storage.ts +++ b/packages/core/src/config/storage.ts @@ -143,6 +143,10 @@ export class Storage { return path.join(this.getProjectTempDir(), 'checkpoints'); } + getProjectTempLogsDir(): string { + return path.join(this.getProjectTempDir(), 'logs'); + } + getExtensionsDir(): string { return path.join(this.getGeminiDir(), 'extensions'); } From 0e955da17108acc339325180269ac6157f33b3e8 Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Sun, 11 Jan 2026 14:11:06 -0500 Subject: [PATCH 117/713] feat(cli): add /chat debug command for nightly builds (#16339) --- .../src/services/BuiltinCommandLoader.test.ts | 39 +++- .../cli/src/services/BuiltinCommandLoader.ts | 14 +- .../cli/src/ui/commands/chatCommand.test.ts | 63 ++++++- packages/cli/src/ui/commands/chatCommand.ts | 41 ++++ packages/core/src/config/config.ts | 10 + .../src/core/loggingContentGenerator.test.ts | 48 +++++ .../core/src/core/loggingContentGenerator.ts | 7 + packages/core/src/index.ts | 2 + .../core/src/utils/apiConversionUtils.test.ts | 177 ++++++++++++++++++ packages/core/src/utils/apiConversionUtils.ts | 57 ++++++ scripts/send_gemini_request.sh | 102 ++++++++++ 11 files changed, 555 insertions(+), 5 deletions(-) create mode 100644 packages/core/src/utils/apiConversionUtils.test.ts create mode 100644 packages/core/src/utils/apiConversionUtils.ts create mode 100755 scripts/send_gemini_request.sh diff --git a/packages/cli/src/services/BuiltinCommandLoader.test.ts b/packages/cli/src/services/BuiltinCommandLoader.test.ts index 545168e88d..44ddaeb039 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.test.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.test.ts @@ -53,16 +53,29 @@ vi.mock('../ui/commands/permissionsCommand.js', async () => { import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest'; import { BuiltinCommandLoader } from './BuiltinCommandLoader.js'; import type { Config } from '@google/gemini-cli-core'; +import { isNightly } from '@google/gemini-cli-core'; import { CommandKind } from '../ui/commands/types.js'; import { restoreCommand } from '../ui/commands/restoreCommand.js'; +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + isNightly: vi.fn().mockResolvedValue(false), + }; +}); + vi.mock('../ui/commands/authCommand.js', () => ({ authCommand: {} })); vi.mock('../ui/commands/agentsCommand.js', () => ({ agentsCommand: { name: 'agents' }, })); vi.mock('../ui/commands/bugCommand.js', () => ({ bugCommand: {} })); -vi.mock('../ui/commands/chatCommand.js', () => ({ chatCommand: {} })); +vi.mock('../ui/commands/chatCommand.js', () => ({ + chatCommand: { name: 'chat', subCommands: [] }, + debugCommand: { name: 'debug' }, +})); vi.mock('../ui/commands/clearCommand.js', () => ({ clearCommand: {} })); vi.mock('../ui/commands/compressCommand.js', () => ({ compressCommand: {} })); vi.mock('../ui/commands/corgiCommand.js', () => ({ corgiCommand: {} })); @@ -209,6 +222,30 @@ describe('BuiltinCommandLoader', () => { const agentsCmd = commands.find((c) => c.name === 'agents'); expect(agentsCmd).toBeUndefined(); }); + + describe('chat debug command', () => { + it('should NOT add debug subcommand to chatCommand if not a nightly build', async () => { + vi.mocked(isNightly).mockResolvedValue(false); + const loader = new BuiltinCommandLoader(mockConfig); + const commands = await loader.loadCommands(new AbortController().signal); + + const chatCmd = commands.find((c) => c.name === 'chat'); + expect(chatCmd?.subCommands).toBeDefined(); + const hasDebug = chatCmd!.subCommands!.some((c) => c.name === 'debug'); + expect(hasDebug).toBe(false); + }); + + it('should add debug subcommand to chatCommand if it is a nightly build', async () => { + vi.mocked(isNightly).mockResolvedValue(true); + const loader = new BuiltinCommandLoader(mockConfig); + const commands = await loader.loadCommands(new AbortController().signal); + + const chatCmd = commands.find((c) => c.name === 'chat'); + expect(chatCmd?.subCommands).toBeDefined(); + const hasDebug = chatCmd!.subCommands!.some((c) => c.name === 'debug'); + expect(hasDebug).toBe(true); + }); + }); }); describe('BuiltinCommandLoader profile', () => { diff --git a/packages/cli/src/services/BuiltinCommandLoader.ts b/packages/cli/src/services/BuiltinCommandLoader.ts index 5193b5fe9c..263a17fd3a 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.ts @@ -12,12 +12,12 @@ import { type CommandContext, } from '../ui/commands/types.js'; import type { MessageActionReturn, Config } from '@google/gemini-cli-core'; -import { startupProfiler } from '@google/gemini-cli-core'; +import { isNightly, startupProfiler } from '@google/gemini-cli-core'; import { aboutCommand } from '../ui/commands/aboutCommand.js'; import { agentsCommand } from '../ui/commands/agentsCommand.js'; import { authCommand } from '../ui/commands/authCommand.js'; import { bugCommand } from '../ui/commands/bugCommand.js'; -import { chatCommand } from '../ui/commands/chatCommand.js'; +import { chatCommand, debugCommand } from '../ui/commands/chatCommand.js'; import { clearCommand } from '../ui/commands/clearCommand.js'; import { compressCommand } from '../ui/commands/compressCommand.js'; import { copyCommand } from '../ui/commands/copyCommand.js'; @@ -65,12 +65,20 @@ export class BuiltinCommandLoader implements ICommandLoader { */ async loadCommands(_signal: AbortSignal): Promise { const handle = startupProfiler.start('load_builtin_commands'); + + const isNightlyBuild = await isNightly(process.cwd()); + const allDefinitions: Array = [ aboutCommand, ...(this.config?.isAgentsEnabled() ? [agentsCommand] : []), authCommand, bugCommand, - chatCommand, + { + ...chatCommand, + subCommands: isNightlyBuild + ? [...(chatCommand.subCommands || []), debugCommand] + : chatCommand.subCommands, + }, clearCommand, compressCommand, copyCommand, diff --git a/packages/cli/src/ui/commands/chatCommand.test.ts b/packages/cli/src/ui/commands/chatCommand.test.ts index 20d0be1e06..6edae787d2 100644 --- a/packages/cli/src/ui/commands/chatCommand.test.ts +++ b/packages/cli/src/ui/commands/chatCommand.test.ts @@ -12,7 +12,7 @@ import type { Content } from '@google/genai'; import { AuthType, type GeminiClient } from '@google/gemini-cli-core'; import * as fsPromises from 'node:fs/promises'; -import { chatCommand } from './chatCommand.js'; +import { chatCommand, debugCommand } from './chatCommand.js'; import { serializeHistoryToMarkdown, exportHistoryToFile, @@ -693,5 +693,66 @@ Hi there!`; const result = serializeHistoryToMarkdown(history as Content[]); expect(result).toBe(expectedMarkdown); }); + describe('debug subcommand', () => { + let mockGetLatestApiRequest: ReturnType; + + beforeEach(() => { + mockGetLatestApiRequest = vi.fn(); + mockContext.services.config!.getLatestApiRequest = + mockGetLatestApiRequest; + vi.spyOn(process, 'cwd').mockReturnValue('/project/root'); + vi.spyOn(Date, 'now').mockReturnValue(1234567890); + mockFs.writeFile.mockClear(); + }); + + it('should return an error if no API request is found', async () => { + mockGetLatestApiRequest.mockReturnValue(undefined); + + const result = await debugCommand.action?.(mockContext, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: 'No recent API request found to export.', + }); + expect(mockFs.writeFile).not.toHaveBeenCalled(); + }); + + it('should convert and write the API request to a json file', async () => { + const mockRequest = { + contents: [{ role: 'user', parts: [{ text: 'test' }] }], + }; + mockGetLatestApiRequest.mockReturnValue(mockRequest); + + const result = await debugCommand.action?.(mockContext, ''); + + const expectedFilename = 'gcli-request-1234567890.json'; + const expectedPath = path.join('/project/root', expectedFilename); + + expect(mockFs.writeFile).toHaveBeenCalledWith( + expectedPath, + expect.stringContaining('"role": "user"'), + ); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: `Debug API request saved to ${expectedFilename}`, + }); + }); + + it('should handle errors during file write', async () => { + const mockRequest = { contents: [] }; + mockGetLatestApiRequest.mockReturnValue(mockRequest); + mockFs.writeFile.mockRejectedValue(new Error('Write failed')); + + const result = await debugCommand.action?.(mockContext, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: 'Error saving debug request: Write failed', + }); + }); + }); }); }); diff --git a/packages/cli/src/ui/commands/chatCommand.ts b/packages/cli/src/ui/commands/chatCommand.ts index 7c9b632b1a..89a770e1f8 100644 --- a/packages/cli/src/ui/commands/chatCommand.ts +++ b/packages/cli/src/ui/commands/chatCommand.ts @@ -27,6 +27,7 @@ import type { } from '../types.js'; import { MessageType } from '../types.js'; import { exportHistoryToFile } from '../utils/historyExportUtils.js'; +import { convertToRestPayload } from '@google/gemini-cli-core'; const getSavedChatTags = async ( context: CommandContext, @@ -334,6 +335,46 @@ const shareCommand: SlashCommand = { }, }; +export const debugCommand: SlashCommand = { + name: 'debug', + description: 'Export the most recent API request as a JSON payload', + kind: CommandKind.BUILT_IN, + autoExecute: true, + action: async (context): Promise => { + const req = context.services.config?.getLatestApiRequest(); + if (!req) { + return { + type: 'message', + messageType: 'error', + content: 'No recent API request found to export.', + }; + } + + const restPayload = convertToRestPayload(req); + const filename = `gcli-request-${Date.now()}.json`; + const filePath = path.join(process.cwd(), filename); + + try { + await fsPromises.writeFile( + filePath, + JSON.stringify(restPayload, null, 2), + ); + return { + type: 'message', + messageType: 'info', + content: `Debug API request saved to ${filename}`, + }; + } catch (err) { + const errorMessage = err instanceof Error ? err.message : String(err); + return { + type: 'message', + messageType: 'error', + content: `Error saving debug request: ${errorMessage}`, + }; + } + }, +}; + export const chatCommand: SlashCommand = { name: 'chat', description: 'Manage conversation history', diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 6fb07754ec..60783cffab 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -73,6 +73,7 @@ import type { ModelConfigServiceConfig } from '../services/modelConfigService.js import { ModelConfigService } from '../services/modelConfigService.js'; import { DEFAULT_MODEL_CONFIGS } from './defaultModelConfigs.js'; import { ContextManager } from '../services/contextManager.js'; +import type { GenerateContentParameters } from '@google/genai'; // Re-export OAuth config type export type { MCPOAuthConfig, AnyToolInvocation }; @@ -499,6 +500,7 @@ export class Config { private contextManager?: ContextManager; private terminalBackground: string | undefined = undefined; private remoteAdminSettings: GeminiCodeAssistSetting | undefined; + private latestApiRequest: GenerateContentParameters | undefined; constructor(params: ConfigParameters) { this.sessionId = params.sessionId; @@ -897,6 +899,14 @@ export class Config { return this.terminalBackground; } + getLatestApiRequest(): GenerateContentParameters | undefined { + return this.latestApiRequest; + } + + setLatestApiRequest(req: GenerateContentParameters): void { + this.latestApiRequest = req; + } + getRemoteAdminSettings(): GeminiCodeAssistSetting | undefined { return this.remoteAdminSettings; } diff --git a/packages/core/src/core/loggingContentGenerator.test.ts b/packages/core/src/core/loggingContentGenerator.test.ts index e591f86be9..92286d207c 100644 --- a/packages/core/src/core/loggingContentGenerator.test.ts +++ b/packages/core/src/core/loggingContentGenerator.test.ts @@ -218,6 +218,54 @@ describe('LoggingContentGenerator', () => { const errorEvent = vi.mocked(logApiError).mock.calls[0][1]; expect(errorEvent.duration_ms).toBe(1000); }); + + it('should set latest API request in config for main agent requests', async () => { + const req = { + contents: [{ role: 'user', parts: [{ text: 'hello' }] }], + model: 'gemini-pro', + }; + // Main agent prompt IDs end with exactly 8 hashes and a turn counter + const mainAgentPromptId = 'session-uuid########1'; + config.setLatestApiRequest = vi.fn(); + + async function* createAsyncGenerator() { + yield { candidates: [] } as unknown as GenerateContentResponse; + } + vi.mocked(wrapped.generateContentStream).mockResolvedValue( + createAsyncGenerator(), + ); + + await loggingContentGenerator.generateContentStream( + req, + mainAgentPromptId, + ); + + expect(config.setLatestApiRequest).toHaveBeenCalledWith(req); + }); + + it('should NOT set latest API request in config for sub-agent requests', async () => { + const req = { + contents: [{ role: 'user', parts: [{ text: 'hello' }] }], + model: 'gemini-pro', + }; + // Sub-agent prompt IDs contain fewer hashes, typically separating the agent name and ID + const subAgentPromptId = 'codebase_investigator#12345'; + config.setLatestApiRequest = vi.fn(); + + async function* createAsyncGenerator() { + yield { candidates: [] } as unknown as GenerateContentResponse; + } + vi.mocked(wrapped.generateContentStream).mockResolvedValue( + createAsyncGenerator(), + ); + + await loggingContentGenerator.generateContentStream( + req, + subAgentPromptId, + ); + + expect(config.setLatestApiRequest).not.toHaveBeenCalled(); + }); }); describe('getWrapped', () => { diff --git a/packages/core/src/core/loggingContentGenerator.ts b/packages/core/src/core/loggingContentGenerator.ts index e559846366..cc5ab05890 100644 --- a/packages/core/src/core/loggingContentGenerator.ts +++ b/packages/core/src/core/loggingContentGenerator.ts @@ -258,6 +258,13 @@ export class LoggingContentGenerator implements ContentGenerator { req, 'generateContentStream', ); + + // For debugging: Capture the latest main agent request payload. + // Main agent prompt IDs end with exactly 8 hashes and a turn counter (e.g. "...########1") + if (/########\d+$/.test(userPromptId)) { + this.config.setLatestApiRequest(req); + } + this.logApiRequest( toContents(req.contents), req.model, diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 75acd00143..ce62f9fcfa 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -89,6 +89,8 @@ export * from './utils/extensionLoader.js'; export * from './utils/package.js'; export * from './utils/version.js'; export * from './utils/checkpointUtils.js'; +export * from './utils/apiConversionUtils.js'; +export * from './utils/channel.js'; // Export services export * from './services/fileDiscoveryService.js'; diff --git a/packages/core/src/utils/apiConversionUtils.test.ts b/packages/core/src/utils/apiConversionUtils.test.ts new file mode 100644 index 0000000000..615bcb1de8 --- /dev/null +++ b/packages/core/src/utils/apiConversionUtils.test.ts @@ -0,0 +1,177 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect } from 'vitest'; +import { convertToRestPayload } from './apiConversionUtils.js'; +import type { GenerateContentParameters } from '@google/genai'; +import { + FunctionCallingConfigMode, + HarmCategory, + HarmBlockThreshold, +} from '@google/genai'; + +describe('apiConversionUtils', () => { + describe('convertToRestPayload', () => { + it('handles minimal requests with no config', () => { + const req: GenerateContentParameters = { + model: 'gemini-3-flash', + contents: [{ role: 'user', parts: [{ text: 'Hello' }] }], + }; + + const result = convertToRestPayload(req); + + expect(result).toStrictEqual({ + contents: [{ role: 'user', parts: [{ text: 'Hello' }] }], + }); + expect(result['generationConfig']).toBeUndefined(); + }); + + it('normalizes string systemInstruction to REST format', () => { + const req: GenerateContentParameters = { + model: 'gemini-3-flash', + contents: [{ role: 'user', parts: [{ text: 'Hello' }] }], + config: { + systemInstruction: 'You are a helpful assistant.', + }, + }; + + const result = convertToRestPayload(req); + + expect(result['systemInstruction']).toStrictEqual({ + parts: [{ text: 'You are a helpful assistant.' }], + }); + expect(result['generationConfig']).toBeUndefined(); + }); + + it('preserves object-based systemInstruction', () => { + const sysInstruction = { parts: [{ text: 'Object instruction' }] }; + const req: GenerateContentParameters = { + model: 'gemini-3-flash', + contents: [{ role: 'user', parts: [{ text: 'Hello' }] }], + config: { + systemInstruction: sysInstruction, + }, + }; + + const result = convertToRestPayload(req); + + expect(result['systemInstruction']).toStrictEqual(sysInstruction); + }); + + it('hoists capabilities (tools, safety, cachedContent) to the root level', () => { + const req: GenerateContentParameters = { + model: 'gemini-3-flash', + contents: [{ role: 'user', parts: [{ text: 'Hello' }] }], + config: { + tools: [{ functionDeclarations: [{ name: 'myTool' }] }], + toolConfig: { + functionCallingConfig: { mode: FunctionCallingConfigMode.ANY }, + }, + safetySettings: [ + { + category: HarmCategory.HARM_CATEGORY_HARASSMENT, + threshold: HarmBlockThreshold.BLOCK_NONE, + }, + ], + cachedContent: 'cached-content-id', + }, + }; + + const result = convertToRestPayload(req); + + expect(result['tools']).toBeDefined(); + expect(result['toolConfig']).toBeDefined(); + expect(result['safetySettings']).toBeDefined(); + expect(result['cachedContent']).toBe('cached-content-id'); + // generationConfig should be omitted since no pure hyperparameters were passed + expect(result['generationConfig']).toBeUndefined(); + }); + + it('retains pure hyperparameters in generationConfig', () => { + const req: GenerateContentParameters = { + model: 'gemini-3-flash', + contents: [{ role: 'user', parts: [{ text: 'Hello' }] }], + config: { + temperature: 0.7, + topP: 0.9, + maxOutputTokens: 100, + }, + }; + + const result = convertToRestPayload(req); + + expect(result['generationConfig']).toStrictEqual({ + temperature: 0.7, + topP: 0.9, + maxOutputTokens: 100, + }); + }); + + it('strips JS-specific abortSignal from the final payload', () => { + const req: GenerateContentParameters = { + model: 'gemini-3-flash', + contents: [{ role: 'user', parts: [{ text: 'Hello' }] }], + config: { + temperature: 0.5, + abortSignal: new AbortController().signal, + }, + }; + + const result = convertToRestPayload(req); + + expect(result['generationConfig']).toStrictEqual({ + temperature: 0.5, + }); + expect(result['abortSignal']).toBeUndefined(); + // @ts-expect-error Checking that the key doesn't exist inside generationConfig + expect(result['generationConfig']?.abortSignal).toBeUndefined(); + }); + + it('handles a complex kitchen-sink request correctly', () => { + const req: GenerateContentParameters = { + model: 'gemini-3-flash', + contents: [{ role: 'user', parts: [{ text: 'Kitchen sink' }] }], + config: { + systemInstruction: 'Be witty.', + temperature: 0.8, + tools: [{ functionDeclarations: [{ name: 'test' }] }], + abortSignal: new AbortController().signal, + safetySettings: [ + { + category: HarmCategory.HARM_CATEGORY_HATE_SPEECH, + threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, + }, + ], + topK: 40, + }, + }; + + const result = convertToRestPayload(req); + + // Root level checks + expect(result['contents']).toBeDefined(); + expect(result['systemInstruction']).toStrictEqual({ + parts: [{ text: 'Be witty.' }], + }); + expect(result['tools']).toStrictEqual([ + { functionDeclarations: [{ name: 'test' }] }, + ]); + expect(result['safetySettings']).toStrictEqual([ + { + category: HarmCategory.HARM_CATEGORY_HATE_SPEECH, + threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, + }, + ]); + expect(result['abortSignal']).toBeUndefined(); + + // Generation config checks + expect(result['generationConfig']).toStrictEqual({ + temperature: 0.8, + topK: 40, + }); + }); + }); +}); diff --git a/packages/core/src/utils/apiConversionUtils.ts b/packages/core/src/utils/apiConversionUtils.ts new file mode 100644 index 0000000000..2e22a3a3ed --- /dev/null +++ b/packages/core/src/utils/apiConversionUtils.ts @@ -0,0 +1,57 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type { GenerateContentParameters } from '@google/genai'; + +/** + * Transforms a standard SDK GenerateContentParameters object into the + * equivalent REST API payload format. This is primarily used for debugging + * and exporting requests. + */ +export function convertToRestPayload( + req: GenerateContentParameters, +): Record { + // Extract top-level REST fields from the SDK config object. + // 'pureGenerationConfig' will capture any remaining hyperparameters (e.g., temperature, topP). + const { + systemInstruction: sdkSystemInstruction, + tools: sdkTools, + toolConfig: sdkToolConfig, + safetySettings: sdkSafetySettings, + cachedContent: sdkCachedContent, + abortSignal: _sdkAbortSignal, // Exclude JS-specific abort controller + ...pureGenerationConfig + } = req.config || {}; + + // Normalize systemInstruction to the expected REST Content format. + let restSystemInstruction; + if (typeof sdkSystemInstruction === 'string') { + restSystemInstruction = { + parts: [{ text: sdkSystemInstruction }], + }; + } else if (sdkSystemInstruction !== undefined) { + restSystemInstruction = sdkSystemInstruction; + } + + const restPayload: Record = { + contents: req.contents, + }; + + // Only include generationConfig if actual hyperparameters exist. + if (Object.keys(pureGenerationConfig).length > 0) { + restPayload['generationConfig'] = pureGenerationConfig; + } + + // Assign extracted capabilities to the root level. + if (restSystemInstruction) + restPayload['systemInstruction'] = restSystemInstruction; + if (sdkTools) restPayload['tools'] = sdkTools; + if (sdkToolConfig) restPayload['toolConfig'] = sdkToolConfig; + if (sdkSafetySettings) restPayload['safetySettings'] = sdkSafetySettings; + if (sdkCachedContent) restPayload['cachedContent'] = sdkCachedContent; + + return restPayload; +} diff --git a/scripts/send_gemini_request.sh b/scripts/send_gemini_request.sh new file mode 100755 index 0000000000..18cedfa5bf --- /dev/null +++ b/scripts/send_gemini_request.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Gemini API Replay Script +# ----------------------------------------------------------------------------- +# Purpose: +# This script is used to replay a Gemini API request using a raw JSON payload. +# It is particularly useful for debugging the exact requests made by the +# Gemini CLI. +# +# Prerequisites: +# 1. Export your Gemini API key: +# export GEMINI_API_KEY="your_api_key_here" +# +# 2. Generate a request payload from the Gemini CLI: +# Inside the CLI, run the `/chat debug` command. This will save the most +# recent API request to a file named `gcli-request-.json`. +# +# Usage: +# ./scripts/send_gemini_request.sh --payload --model [--stream] +# +# Options: +# --payload Path to the JSON request payload. +# --model The Gemini model ID (e.g., gemini-3-flash-preview). +# --stream (Optional) Use the streaming API endpoint. Defaults to non-streaming. +# +# Example: +# ./scripts/send_gemini_request.sh --payload gcli-request.json --model gemini-3-flash-preview +# ----------------------------------------------------------------------------- + +set -e -E + +# Load environment variables from .env if it exists +if [ -f ".env" ]; then + echo "Loading environment variables from .env file..." + set -a # Automatically export all variables + source .env + set +a +fi + +# Function to print usage +usage() { + echo "Usage: $0 --payload --model [--stream]" + echo "Ensure GEMINI_API_KEY environment variable is set." + exit 1 +} + +STREAM_MODE=false + +# Parse command line arguments +while [[ "$#" -gt 0 ]]; do + case $1 in + --payload) PAYLOAD_FILE="$2"; shift ;; + --model) MODEL_ID="$2"; shift ;; + --stream) STREAM_MODE=true ;; + *) echo "Unknown parameter passed: $1"; usage ;; + esac + shift +done + +# Validate inputs +if [ -z "$PAYLOAD_FILE" ] || [ -z "$MODEL_ID" ]; then + echo "Error: Missing required arguments." + usage +fi + +if [ -z "$GEMINI_API_KEY" ]; then + echo "Error: GEMINI_API_KEY environment variable is not set." + exit 1 +fi + +if [ ! -f "$PAYLOAD_FILE" ]; then + echo "Error: Payload file '$PAYLOAD_FILE' does not exist." + exit 1 +fi + +# API Endpoint definition +if [ "$STREAM_MODE" = true ]; then + GENERATE_CONTENT_API="streamGenerateContent" + echo "Mode: Streaming" +else + GENERATE_CONTENT_API="generateContent" + echo "Mode: Non-streaming (Default)" +fi + +echo "Sending request to model: $MODEL_ID" +echo "Using payload from: $PAYLOAD_FILE" +echo "----------------------------------------" + +# Make the cURL request. If non-streaming, pipe through jq for readability if available. +if [ "$STREAM_MODE" = false ] && command -v jq &> /dev/null; then + curl -s -X POST \ + -H "Content-Type: application/json" \ + "https://generativelanguage.googleapis.com/v1beta/models/${MODEL_ID}:${GENERATE_CONTENT_API}?key=${GEMINI_API_KEY}" \ + -d "@${PAYLOAD_FILE}" | jq . +else + curl -X POST \ + -H "Content-Type: application/json" \ + "https://generativelanguage.googleapis.com/v1beta/models/${MODEL_ID}:${GENERATE_CONTENT_API}?key=${GEMINI_API_KEY}" \ + -d "@${PAYLOAD_FILE}" +fi + +echo -e "\n----------------------------------------" From 93b57b82c10c05a6de779f7be5dfbd4da34b8f85 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Sun, 11 Jan 2026 16:54:49 -0800 Subject: [PATCH 118/713] style: format pr-creator skill (#16381) --- .gemini/skills/pr-creator/SKILL.md | 42 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/.gemini/skills/pr-creator/SKILL.md b/.gemini/skills/pr-creator/SKILL.md index f89a3d07e0..db845b2dbc 100644 --- a/.gemini/skills/pr-creator/SKILL.md +++ b/.gemini/skills/pr-creator/SKILL.md @@ -1,37 +1,51 @@ --- name: pr-creator -description: Use this skill when asked to create a pull request (PR). It ensures all PRs follow the repository's established templates and standards. +description: + Use this skill when asked to create a pull request (PR). It ensures all PRs + follow the repository's established templates and standards. --- # Pull Request Creator -This skill guides the creation of high-quality Pull Requests that adhere to the repository's standards. +This skill guides the creation of high-quality Pull Requests that adhere to the +repository's standards. ## Workflow Follow these steps to create a Pull Request: 1. **Locate Template**: Search for a pull request template in the repository. - * Check `.github/pull_request_template.md` - * Check `.github/PULL_REQUEST_TEMPLATE.md` - * If multiple templates exist (e.g., in `.github/PULL_REQUEST_TEMPLATE/`), ask the user which one to use or select the most appropriate one based on the context (e.g., `bug_fix.md` vs `feature.md`). + - Check `.github/pull_request_template.md` + - Check `.github/PULL_REQUEST_TEMPLATE.md` + - If multiple templates exist (e.g., in `.github/PULL_REQUEST_TEMPLATE/`), + ask the user which one to use or select the most appropriate one based on + the context (e.g., `bug_fix.md` vs `feature.md`). 2. **Read Template**: Read the content of the identified template file. -3. **Draft Description**: Create a PR description that strictly follows the template's structure. - * **Headings**: Keep all headings from the template. - * **Checklists**: Review each item. Mark with `[x]` if completed. If an item is not applicable, leave it unchecked or mark as `[ ]` (depending on the template's instructions) or remove it if the template allows flexibility (but prefer keeping it unchecked for transparency). - * **Content**: Fill in the sections with clear, concise summaries of your changes. - * **Related Issues**: Link any issues fixed or related to this PR (e.g., "Fixes #123"). +3. **Draft Description**: Create a PR description that strictly follows the + template's structure. + - **Headings**: Keep all headings from the template. + - **Checklists**: Review each item. Mark with `[x]` if completed. If an item + is not applicable, leave it unchecked or mark as `[ ]` (depending on the + template's instructions) or remove it if the template allows flexibility + (but prefer keeping it unchecked for transparency). + - **Content**: Fill in the sections with clear, concise summaries of your + changes. + - **Related Issues**: Link any issues fixed or related to this PR (e.g., + "Fixes #123"). 4. **Create PR**: Use the `gh` CLI to create the PR. ```bash gh pr create --title "type(scope): succinct description" --body "..." ``` - * **Title**: Ensure the title follows the [Conventional Commits](https://www.conventionalcommits.org/) format if the repository uses it (e.g., `feat(ui): add new button`, `fix(core): resolve crash`). + - **Title**: Ensure the title follows the + [Conventional Commits](https://www.conventionalcommits.org/) format if the + repository uses it (e.g., `feat(ui): add new button`, + `fix(core): resolve crash`). ## Principles -* **Compliance**: Never ignore the PR template. It exists for a reason. -* **Completeness**: Fill out all relevant sections. -* **Accuracy**: Don't check boxes for tasks you haven't done. +- **Compliance**: Never ignore the PR template. It exists for a reason. +- **Completeness**: Fill out all relevant sections. +- **Accuracy**: Don't check boxes for tasks you haven't done. From 9703fe73cf910716b255891e76ec5dafd43696b9 Mon Sep 17 00:00:00 2001 From: Abdul Tawab <122252873+AbdulTawabJuly@users.noreply.github.com> Date: Mon, 12 Jan 2026 12:42:04 +0500 Subject: [PATCH 119/713] feat(cli): Hooks enable-all/disable-all feature with dynamic status (#15552) --- docs/hooks/index.md | 26 +- .../cli/src/ui/commands/hooksCommand.test.ts | 297 +++++++++++++++++- packages/cli/src/ui/commands/hooksCommand.ts | 194 ++++++++++-- .../cli/src/ui/components/views/HooksList.tsx | 191 ++++++----- 4 files changed, 569 insertions(+), 139 deletions(-) diff --git a/docs/hooks/index.md b/docs/hooks/index.md index 0c62957a9a..66dfa6ef56 100644 --- a/docs/hooks/index.md +++ b/docs/hooks/index.md @@ -533,14 +533,29 @@ Use the `/hooks panel` command to view all registered hooks: This command displays: -- All active hooks organized by event +- All configured hooks organized by event - Hook source (user, project, system) - Hook type (command or plugin) -- Execution status and recent output +- Individual hook status (enabled/disabled) -### Enable and disable hooks +### Enable and disable all hooks at once -You can temporarily enable or disable individual hooks using commands: +You can enable or disable all hooks at once using commands: + +```bash +/hooks enable-all +/hooks disable-all +``` + +These commands provide a shortcut to enable or disable all configured hooks +without managing them individually. The `enable-all` command removes all hooks +from the `hooks.disabled` array, while `disable-all` adds all configured hooks +to the disabled list. Changes take effect immediately without requiring a +restart. + +### Enable and disable individual hooks + +You can enable or disable individual hooks using commands: ```bash /hooks enable hook-name @@ -549,7 +564,8 @@ You can temporarily enable or disable individual hooks using commands: These commands allow you to control hook execution without editing configuration files. The hook name should match the `name` field in your hook configuration. -Changes made via these commands are persisted to your global User settings +Changes made via these commands are persisted to your settings. The settings are +saved to workspace scope if available, otherwise to your global user settings (`~/.gemini/settings.json`). ### Disabled hooks configuration diff --git a/packages/cli/src/ui/commands/hooksCommand.test.ts b/packages/cli/src/ui/commands/hooksCommand.test.ts index 54a3edc991..aa4eb12971 100644 --- a/packages/cli/src/ui/commands/hooksCommand.test.ts +++ b/packages/cli/src/ui/commands/hooksCommand.test.ts @@ -21,12 +21,16 @@ describe('hooksCommand', () => { }; let mockConfig: { getHookSystem: ReturnType; + getEnableHooks: ReturnType; }; let mockSettings: { merged: { hooks?: { disabled?: string[]; }; + tools?: { + enableHooks?: boolean; + }; }; setValue: ReturnType; }; @@ -46,6 +50,7 @@ describe('hooksCommand', () => { // Create mock config mockConfig = { getHookSystem: vi.fn().mockReturnValue(mockHookSystem), + getEnableHooks: vi.fn().mockReturnValue(true), }; // Create mock settings @@ -79,12 +84,14 @@ describe('hooksCommand', () => { it('should have all expected subcommands', () => { expect(hooksCommand.subCommands).toBeDefined(); - expect(hooksCommand.subCommands).toHaveLength(3); + expect(hooksCommand.subCommands).toHaveLength(5); const subCommandNames = hooksCommand.subCommands!.map((cmd) => cmd.name); expect(subCommandNames).toContain('panel'); expect(subCommandNames).toContain('enable'); expect(subCommandNames).toContain('disable'); + expect(subCommandNames).toContain('enable-all'); + expect(subCommandNames).toContain('disable-all'); }); it('should delegate to panel action when invoked without subcommand', async () => { @@ -131,7 +138,7 @@ describe('hooksCommand', () => { }); }); - it('should return info message when hook system is not enabled', async () => { + it('should display panel even when hook system is not enabled', async () => { mockConfig.getHookSystem.mockReturnValue(null); const panelCmd = hooksCommand.subCommands!.find( @@ -141,18 +148,22 @@ describe('hooksCommand', () => { throw new Error('panel command must have an action'); } - const result = await panelCmd.action(mockContext, ''); + await panelCmd.action(mockContext, ''); - expect(result).toEqual({ - type: 'message', - messageType: 'info', - content: - 'Hook system is not enabled. Enable it in settings with hooks.enabled.', - }); + expect(mockContext.ui.addItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.HOOKS_LIST, + hooks: [], + }), + expect.any(Number), + ); }); - it('should return info message when no hooks are configured', async () => { + it('should display panel when no hooks are configured', async () => { mockHookSystem.getAllHooks.mockReturnValue([]); + (mockContext.services.settings.merged as Record)[ + 'tools' + ] = { enableHooks: true }; const panelCmd = hooksCommand.subCommands!.find( (cmd) => cmd.name === 'panel', @@ -161,14 +172,15 @@ describe('hooksCommand', () => { throw new Error('panel command must have an action'); } - const result = await panelCmd.action(mockContext, ''); + await panelCmd.action(mockContext, ''); - expect(result).toEqual({ - type: 'message', - messageType: 'info', - content: - 'No hooks configured. Add hooks to your settings to get started.', - }); + expect(mockContext.ui.addItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.HOOKS_LIST, + hooks: [], + }), + expect.any(Number), + ); }); it('should display hooks list when hooks are configured', async () => { @@ -178,6 +190,9 @@ describe('hooksCommand', () => { ]; mockHookSystem.getAllHooks.mockReturnValue(mockHooks); + (mockContext.services.settings.merged as Record)[ + 'tools' + ] = { enableHooks: true }; const panelCmd = hooksCommand.subCommands!.find( (cmd) => cmd.name === 'panel', @@ -562,6 +577,254 @@ describe('hooksCommand', () => { expect(result).toEqual(['test-hook']); }); }); + + describe('enable-all subcommand', () => { + it('should return error when config is not loaded', async () => { + const contextWithoutConfig = createMockCommandContext({ + services: { + config: null, + }, + }); + + const enableAllCmd = hooksCommand.subCommands!.find( + (cmd) => cmd.name === 'enable-all', + ); + if (!enableAllCmd?.action) { + throw new Error('enable-all command must have an action'); + } + + const result = await enableAllCmd.action(contextWithoutConfig, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: 'Config not loaded.', + }); + }); + + it('should return error when hook system is not enabled', async () => { + mockConfig.getHookSystem.mockReturnValue(null); + + const enableAllCmd = hooksCommand.subCommands!.find( + (cmd) => cmd.name === 'enable-all', + ); + if (!enableAllCmd?.action) { + throw new Error('enable-all command must have an action'); + } + + const result = await enableAllCmd.action(mockContext, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: 'Hook system is not enabled.', + }); + }); + + it('should enable all disabled hooks', async () => { + const mockHooks = [ + createMockHook('hook-1', HookEventName.BeforeTool, false), + createMockHook('hook-2', HookEventName.AfterTool, false), + createMockHook('hook-3', HookEventName.BeforeAgent, true), // already enabled + ]; + mockHookSystem.getAllHooks.mockReturnValue(mockHooks); + + const enableAllCmd = hooksCommand.subCommands!.find( + (cmd) => cmd.name === 'enable-all', + ); + if (!enableAllCmd?.action) { + throw new Error('enable-all command must have an action'); + } + + const result = await enableAllCmd.action(mockContext, ''); + + expect(mockContext.services.settings.setValue).toHaveBeenCalledWith( + expect.any(String), + 'hooks.disabled', + [], + ); + expect(mockHookSystem.setHookEnabled).toHaveBeenCalledWith( + 'hook-1', + true, + ); + expect(mockHookSystem.setHookEnabled).toHaveBeenCalledWith( + 'hook-2', + true, + ); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: 'Enabled 2 hook(s) successfully.', + }); + }); + + it('should return info when no hooks are configured', async () => { + mockHookSystem.getAllHooks.mockReturnValue([]); + + const enableAllCmd = hooksCommand.subCommands!.find( + (cmd) => cmd.name === 'enable-all', + ); + if (!enableAllCmd?.action) { + throw new Error('enable-all command must have an action'); + } + + const result = await enableAllCmd.action(mockContext, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: 'No hooks configured.', + }); + }); + + it('should return info when all hooks are already enabled', async () => { + const mockHooks = [ + createMockHook('hook-1', HookEventName.BeforeTool, true), + createMockHook('hook-2', HookEventName.AfterTool, true), + ]; + mockHookSystem.getAllHooks.mockReturnValue(mockHooks); + + const enableAllCmd = hooksCommand.subCommands!.find( + (cmd) => cmd.name === 'enable-all', + ); + if (!enableAllCmd?.action) { + throw new Error('enable-all command must have an action'); + } + + const result = await enableAllCmd.action(mockContext, ''); + + expect(mockContext.services.settings.setValue).not.toHaveBeenCalled(); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: 'All hooks are already enabled.', + }); + }); + }); + + describe('disable-all subcommand', () => { + it('should return error when config is not loaded', async () => { + const contextWithoutConfig = createMockCommandContext({ + services: { + config: null, + }, + }); + + const disableAllCmd = hooksCommand.subCommands!.find( + (cmd) => cmd.name === 'disable-all', + ); + if (!disableAllCmd?.action) { + throw new Error('disable-all command must have an action'); + } + + const result = await disableAllCmd.action(contextWithoutConfig, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: 'Config not loaded.', + }); + }); + + it('should return error when hook system is not enabled', async () => { + mockConfig.getHookSystem.mockReturnValue(null); + + const disableAllCmd = hooksCommand.subCommands!.find( + (cmd) => cmd.name === 'disable-all', + ); + if (!disableAllCmd?.action) { + throw new Error('disable-all command must have an action'); + } + + const result = await disableAllCmd.action(mockContext, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: 'Hook system is not enabled.', + }); + }); + + it('should disable all enabled hooks', async () => { + const mockHooks = [ + createMockHook('hook-1', HookEventName.BeforeTool, true), + createMockHook('hook-2', HookEventName.AfterTool, true), + createMockHook('hook-3', HookEventName.BeforeAgent, false), // already disabled + ]; + mockHookSystem.getAllHooks.mockReturnValue(mockHooks); + + const disableAllCmd = hooksCommand.subCommands!.find( + (cmd) => cmd.name === 'disable-all', + ); + if (!disableAllCmd?.action) { + throw new Error('disable-all command must have an action'); + } + + const result = await disableAllCmd.action(mockContext, ''); + + expect(mockContext.services.settings.setValue).toHaveBeenCalledWith( + expect.any(String), + 'hooks.disabled', + ['hook-1', 'hook-2', 'hook-3'], + ); + expect(mockHookSystem.setHookEnabled).toHaveBeenCalledWith( + 'hook-1', + false, + ); + expect(mockHookSystem.setHookEnabled).toHaveBeenCalledWith( + 'hook-2', + false, + ); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: 'Disabled 2 hook(s) successfully.', + }); + }); + + it('should return info when no hooks are configured', async () => { + mockHookSystem.getAllHooks.mockReturnValue([]); + + const disableAllCmd = hooksCommand.subCommands!.find( + (cmd) => cmd.name === 'disable-all', + ); + if (!disableAllCmd?.action) { + throw new Error('disable-all command must have an action'); + } + + const result = await disableAllCmd.action(mockContext, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: 'No hooks configured.', + }); + }); + + it('should return info when all hooks are already disabled', async () => { + const mockHooks = [ + createMockHook('hook-1', HookEventName.BeforeTool, false), + createMockHook('hook-2', HookEventName.AfterTool, false), + ]; + mockHookSystem.getAllHooks.mockReturnValue(mockHooks); + + const disableAllCmd = hooksCommand.subCommands!.find( + (cmd) => cmd.name === 'disable-all', + ); + if (!disableAllCmd?.action) { + throw new Error('disable-all command must have an action'); + } + + const result = await disableAllCmd.action(mockContext, ''); + + expect(mockContext.services.settings.setValue).not.toHaveBeenCalled(); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: 'All hooks are already disabled.', + }); + }); + }); }); /** diff --git a/packages/cli/src/ui/commands/hooksCommand.ts b/packages/cli/src/ui/commands/hooksCommand.ts index 8028173a84..1017474952 100644 --- a/packages/cli/src/ui/commands/hooksCommand.ts +++ b/packages/cli/src/ui/commands/hooksCommand.ts @@ -30,24 +30,7 @@ async function panelAction( } const hookSystem = config.getHookSystem(); - if (!hookSystem) { - return { - type: 'message', - messageType: 'info', - content: - 'Hook system is not enabled. Enable it in settings with hooks.enabled.', - }; - } - - const allHooks = hookSystem.getAllHooks(); - if (allHooks.length === 0) { - return { - type: 'message', - messageType: 'info', - content: - 'No hooks configured. Add hooks to your settings to get started.', - }; - } + const allHooks = hookSystem?.getAllHooks() || []; const hooksListItem: HistoryItemHooksList = { type: MessageType.HOOKS_LIST, @@ -102,7 +85,10 @@ async function enableAction( // Update settings (setValue automatically saves) try { - settings.setValue(SettingScope.User, 'hooks.disabled', newDisabledHooks); + const scope = settings.workspace + ? SettingScope.Workspace + : SettingScope.User; + settings.setValue(scope, 'hooks.disabled', newDisabledHooks); // Enable in hook system hookSystem.setHookEnabled(hookName, true); @@ -165,7 +151,10 @@ async function disableAction( // Update settings (setValue automatically saves) try { - settings.setValue(SettingScope.User, 'hooks.disabled', newDisabledHooks); + const scope = settings.workspace + ? SettingScope.Workspace + : SettingScope.User; + settings.setValue(scope, 'hooks.disabled', newDisabledHooks); // Disable in hook system hookSystem.setHookEnabled(hookName, false); @@ -216,6 +205,145 @@ function getHookDisplayName(hook: HookRegistryEntry): string { return hook.config.name || hook.config.command || 'unknown-hook'; } +/** + * Enable all hooks by clearing the disabled list + */ +async function enableAllAction( + context: CommandContext, +): Promise { + const { config } = context.services; + if (!config) { + return { + type: 'message', + messageType: 'error', + content: 'Config not loaded.', + }; + } + + const hookSystem = config.getHookSystem(); + if (!hookSystem) { + return { + type: 'message', + messageType: 'error', + content: 'Hook system is not enabled.', + }; + } + + const settings = context.services.settings; + const allHooks = hookSystem.getAllHooks(); + + if (allHooks.length === 0) { + return { + type: 'message', + messageType: 'info', + content: 'No hooks configured.', + }; + } + + const disabledHooks = allHooks.filter((hook) => !hook.enabled); + if (disabledHooks.length === 0) { + return { + type: 'message', + messageType: 'info', + content: 'All hooks are already enabled.', + }; + } + + try { + const scope = settings.workspace + ? SettingScope.Workspace + : SettingScope.User; + settings.setValue(scope, 'hooks.disabled', []); + + for (const hook of disabledHooks) { + const hookName = getHookDisplayName(hook); + hookSystem.setHookEnabled(hookName, true); + } + + return { + type: 'message', + messageType: 'info', + content: `Enabled ${disabledHooks.length} hook(s) successfully.`, + }; + } catch (error) { + return { + type: 'message', + messageType: 'error', + content: `Failed to enable hooks: ${getErrorMessage(error)}`, + }; + } +} + +/** + * Disable all hooks by adding all hooks to the disabled list + */ +async function disableAllAction( + context: CommandContext, +): Promise { + const { config } = context.services; + if (!config) { + return { + type: 'message', + messageType: 'error', + content: 'Config not loaded.', + }; + } + + const hookSystem = config.getHookSystem(); + if (!hookSystem) { + return { + type: 'message', + messageType: 'error', + content: 'Hook system is not enabled.', + }; + } + + const settings = context.services.settings; + const allHooks = hookSystem.getAllHooks(); + + if (allHooks.length === 0) { + return { + type: 'message', + messageType: 'info', + content: 'No hooks configured.', + }; + } + + const enabledHooks = allHooks.filter((hook) => hook.enabled); + if (enabledHooks.length === 0) { + return { + type: 'message', + messageType: 'info', + content: 'All hooks are already disabled.', + }; + } + + try { + const allHookNames = allHooks.map((hook) => getHookDisplayName(hook)); + const scope = settings.workspace + ? SettingScope.Workspace + : SettingScope.User; + settings.setValue(scope, 'hooks.disabled', allHookNames); + + for (const hook of enabledHooks) { + const hookName = getHookDisplayName(hook); + hookSystem.setHookEnabled(hookName, false); + } + + return { + type: 'message', + messageType: 'info', + content: `Disabled ${enabledHooks.length} hook(s) successfully.`, + }; + } catch (error) { + return { + type: 'message', + messageType: 'error', + content: `Failed to disable hooks: ${getErrorMessage(error)}`, + }; + } +} + const panelCommand: SlashCommand = { name: 'panel', altNames: ['list', 'show'], @@ -242,10 +370,34 @@ const disableCommand: SlashCommand = { completion: completeHookNames, }; +const enableAllCommand: SlashCommand = { + name: 'enable-all', + altNames: ['enableall'], + description: 'Enable all disabled hooks', + kind: CommandKind.BUILT_IN, + autoExecute: true, + action: enableAllAction, +}; + +const disableAllCommand: SlashCommand = { + name: 'disable-all', + altNames: ['disableall'], + description: 'Disable all enabled hooks', + kind: CommandKind.BUILT_IN, + autoExecute: true, + action: disableAllAction, +}; + export const hooksCommand: SlashCommand = { name: 'hooks', description: 'Manage hooks', kind: CommandKind.BUILT_IN, - subCommands: [panelCommand, enableCommand, disableCommand], + subCommands: [ + panelCommand, + enableCommand, + disableCommand, + enableAllCommand, + disableAllCommand, + ], action: async (context: CommandContext) => panelCommand.action!(context, ''), }; diff --git a/packages/cli/src/ui/components/views/HooksList.tsx b/packages/cli/src/ui/components/views/HooksList.tsx index c2b8d8a7d7..629a7b5b83 100644 --- a/packages/cli/src/ui/components/views/HooksList.tsx +++ b/packages/cli/src/ui/components/views/HooksList.tsx @@ -25,105 +25,104 @@ interface HooksListProps { }>; } -export const HooksList: React.FC = ({ hooks }) => ( - - - Hooks are scripts or programs that Gemini CLI executes at specific points - in the agentic loop, allowing you to intercept and customize behavior. - +export const HooksList: React.FC = ({ hooks }) => { + if (hooks.length === 0) { + return ( + + + No hooks configured. + + + ); + } - - - ⚠️ Security Warning: - - - Hooks can execute arbitrary commands on your system. Only use hooks from - sources you trust. Review hook scripts carefully. - - + // Group hooks by event name for better organization + const hooksByEvent = hooks.reduce( + (acc, hook) => { + if (!acc[hook.eventName]) { + acc[hook.eventName] = []; + } + acc[hook.eventName].push(hook); + return acc; + }, + {} as Record>, + ); - - - Learn more:{' '} - https://geminicli.com/docs/hooks - - + return ( + + + + ⚠️ Security Warning: + + + Hooks can execute arbitrary commands on your system. Only use hooks + from sources you trust. Review hook scripts carefully. + + - - {hooks.length === 0 ? ( - No hooks configured. - ) : ( - <> - - Registered Hooks: - - - {Object.entries( - hooks.reduce( - (acc, hook) => { - if (!acc[hook.eventName]) { - acc[hook.eventName] = []; - } - acc[hook.eventName].push(hook); - return acc; - }, - {} as Record>, - ), - ).map(([eventName, eventHooks]) => ( - - - {eventName}: - - - {eventHooks.map((hook, index) => { - const hookName = - hook.config.name || hook.config.command || 'unknown'; - const statusColor = hook.enabled ? 'green' : 'gray'; - const statusText = hook.enabled ? 'enabled' : 'disabled'; + + + Learn more:{' '} + https://geminicli.com/docs/hooks + + - return ( - - - - {hookName} - {` [${statusText}]`} - - - - {hook.config.description && ( - - {hook.config.description} - - )} - - Source: {hook.source} - {hook.config.name && - hook.config.command && - ` | Command: ${hook.config.command}`} - {hook.matcher && ` | Matcher: ${hook.matcher}`} - {hook.sequential && ` | Sequential`} - {hook.config.timeout && - ` | Timeout: ${hook.config.timeout}s`} - - - - ); - })} - - - ))} + + Configured Hooks: + + + {Object.entries(hooksByEvent).map(([eventName, eventHooks]) => ( + + + {eventName}: + + + {eventHooks.map((hook, index) => { + const hookName = + hook.config.name || hook.config.command || 'unknown'; + const statusColor = hook.enabled + ? theme.status.success + : theme.text.secondary; + const statusText = hook.enabled ? 'enabled' : 'disabled'; + + return ( + + + + {hookName} + {` [${statusText}]`} + + + + {hook.config.description && ( + {hook.config.description} + )} + + Source: {hook.source} + {hook.config.name && + hook.config.command && + ` | Command: ${hook.config.command}`} + {hook.matcher && ` | Matcher: ${hook.matcher}`} + {hook.sequential && ` | Sequential`} + {hook.config.timeout && + ` | Timeout: ${hook.config.timeout}s`} + + + + ); + })} + - - )} + ))} + + + + Tip: Use /hooks enable {''} or{' '} + /hooks disable {''} to toggle individual + hooks. Use /hooks enable-all or{' '} + /hooks disable-all to toggle all hooks at once. + + - - - - Tip: Use `/hooks enable {''}` or `/hooks disable{' '} - {''}` to toggle hooks - - - -); + ); +}; From d315f4d3dad7d6be1f51a0c0ce54b72958b1de09 Mon Sep 17 00:00:00 2001 From: Adam Weidman <65992621+adamfweidman@users.noreply.github.com> Date: Mon, 12 Jan 2026 03:55:16 -0500 Subject: [PATCH 120/713] fix(core): ensure silent local subagent delegation while allowing remote confirmation (#16395) Co-authored-by: N. Taylor Mullen --- docs/core/policy-engine.md | 5 +- .../src/agents/delegate-to-agent-tool.test.ts | 53 +++++++++++-------- .../core/src/agents/delegate-to-agent-tool.ts | 3 +- packages/core/src/policy/policies/agent.toml | 2 +- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/docs/core/policy-engine.md b/docs/core/policy-engine.md index 6f5dc600c1..6811b8b6fb 100644 --- a/docs/core/policy-engine.md +++ b/docs/core/policy-engine.md @@ -258,8 +258,9 @@ The Gemini CLI ships with a set of default policies to provide a safe out-of-the-box experience. - **Read-only tools** (like `read_file`, `glob`) are generally **allowed**. -- **Agent delegation** (like `delegate_to_agent`) is **allowed** (sub-agent - actions are checked individually). +- **Agent delegation** (like `delegate_to_agent`) defaults to **`ask_user`** to + ensure remote agents can prompt for confirmation, but local sub-agent actions + are executed silently and checked individually. - **Write tools** (like `write_file`, `run_shell_command`) default to **`ask_user`**. - In **`yolo`** mode, a high-priority rule allows all tools. diff --git a/packages/core/src/agents/delegate-to-agent-tool.test.ts b/packages/core/src/agents/delegate-to-agent-tool.test.ts index 9b2bd16aaf..65dcd2b2e0 100644 --- a/packages/core/src/agents/delegate-to-agent-tool.test.ts +++ b/packages/core/src/agents/delegate-to-agent-tool.test.ts @@ -187,24 +187,28 @@ describe('DelegateToAgentTool', () => { ); }); - it('should use correct tool name "delegate_to_agent" when requesting confirmation', async () => { + it('should execute local agents silently without requesting confirmation', async () => { const invocation = tool.build({ agent_name: 'test_agent', arg1: 'valid', }); // Trigger confirmation check - const p = invocation.shouldConfirmExecute(new AbortController().signal); - void p; - - expect(messageBus.publish).toHaveBeenCalledWith( - expect.objectContaining({ - type: MessageBusType.TOOL_CONFIRMATION_REQUEST, - toolCall: expect.objectContaining({ - name: DELEGATE_TO_AGENT_TOOL_NAME, - }), - }), + const result = await invocation.shouldConfirmExecute( + new AbortController().signal, ); + + expect(result).toBe(false); + + // Verify it did NOT call messageBus.publish with 'delegate_to_agent' + const delegateToAgentPublish = vi + .mocked(messageBus.publish) + .mock.calls.find( + (call) => + call[0].type === MessageBusType.TOOL_CONFIRMATION_REQUEST && + call[0].toolCall.name === DELEGATE_TO_AGENT_TOOL_NAME, + ); + expect(delegateToAgentPublish).toBeUndefined(); }); it('should delegate to remote agent correctly', async () => { @@ -227,24 +231,27 @@ describe('DelegateToAgentTool', () => { }); describe('Confirmation', () => { - it('should use default behavior for local agents (super call)', async () => { + it('should return false for local agents (silent execution)', async () => { const invocation = tool.build({ agent_name: 'test_agent', arg1: 'valid', }); - // We expect it to call messageBus.publish with 'delegate_to_agent' - // because super.shouldConfirmExecute checks the policy for the tool itself. - await invocation.shouldConfirmExecute(new AbortController().signal); - - expect(messageBus.publish).toHaveBeenCalledWith( - expect.objectContaining({ - type: MessageBusType.TOOL_CONFIRMATION_REQUEST, - toolCall: expect.objectContaining({ - name: DELEGATE_TO_AGENT_TOOL_NAME, - }), - }), + // Local agents should now return false directly, bypassing policy check + const result = await invocation.shouldConfirmExecute( + new AbortController().signal, ); + + expect(result).toBe(false); + + const delegateToAgentPublish = vi + .mocked(messageBus.publish) + .mock.calls.find( + (call) => + call[0].type === MessageBusType.TOOL_CONFIRMATION_REQUEST && + call[0].toolCall.name === DELEGATE_TO_AGENT_TOOL_NAME, + ); + expect(delegateToAgentPublish).toBeUndefined(); }); it('should forward to remote agent confirmation logic', async () => { diff --git a/packages/core/src/agents/delegate-to-agent-tool.ts b/packages/core/src/agents/delegate-to-agent-tool.ts index 7f3c4466b5..84d398aa4d 100644 --- a/packages/core/src/agents/delegate-to-agent-tool.ts +++ b/packages/core/src/agents/delegate-to-agent-tool.ts @@ -172,7 +172,8 @@ class DelegateInvocation extends BaseToolInvocation< ): Promise { const definition = this.registry.getDefinition(this.params.agent_name); if (!definition || definition.kind !== 'remote') { - return super.shouldConfirmExecute(abortSignal); + // Local agents should execute without confirmation. Inner tool calls will bubble up their own confirmations to the user. + return false; } const { agent_name: _agent_name, ...agentArgs } = this.params; diff --git a/packages/core/src/policy/policies/agent.toml b/packages/core/src/policy/policies/agent.toml index 58876246bf..218f2dc986 100644 --- a/packages/core/src/policy/policies/agent.toml +++ b/packages/core/src/policy/policies/agent.toml @@ -27,5 +27,5 @@ [[rule]] toolName = "delegate_to_agent" -decision = "allow" +decision = "ask_user" priority = 50 From 7b7f2fc69e37e5648ee8e8993f1804a9618f3946 Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Mon, 12 Jan 2026 11:31:49 -0500 Subject: [PATCH 121/713] Markdown w/ Frontmatter Agent Parser (#16094) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/core/src/agents/agentLoader.test.ts | 342 ++++++++++++++++ .../agents/{toml-loader.ts => agentLoader.ts} | 219 +++++----- packages/core/src/agents/registry.test.ts | 4 +- packages/core/src/agents/registry.ts | 2 +- packages/core/src/agents/toml-loader.test.ts | 373 ------------------ packages/core/src/skills/skillLoader.ts | 2 +- 6 files changed, 460 insertions(+), 482 deletions(-) create mode 100644 packages/core/src/agents/agentLoader.test.ts rename packages/core/src/agents/{toml-loader.ts => agentLoader.ts} (58%) delete mode 100644 packages/core/src/agents/toml-loader.test.ts diff --git a/packages/core/src/agents/agentLoader.test.ts b/packages/core/src/agents/agentLoader.test.ts new file mode 100644 index 0000000000..0d6acf7de0 --- /dev/null +++ b/packages/core/src/agents/agentLoader.test.ts @@ -0,0 +1,342 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; +import * as fs from 'node:fs/promises'; +import * as path from 'node:path'; +import * as os from 'node:os'; +import { + parseAgentMarkdown, + markdownToAgentDefinition, + loadAgentsFromDirectory, + AgentLoadError, +} from './agentLoader.js'; +import { GEMINI_MODEL_ALIAS_PRO } from '../config/models.js'; +import type { LocalAgentDefinition } from './types.js'; + +describe('loader', () => { + let tempDir: string; + + beforeEach(async () => { + tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'agent-test-')); + }); + + afterEach(async () => { + if (tempDir) { + await fs.rm(tempDir, { recursive: true, force: true }); + } + }); + + async function writeAgentMarkdown(content: string, fileName = 'test.md') { + const filePath = path.join(tempDir, fileName); + await fs.writeFile(filePath, content); + return filePath; + } + + describe('parseAgentMarkdown', () => { + it('should parse a valid markdown agent file', async () => { + const filePath = await writeAgentMarkdown(`--- +name: test-agent-md +description: A markdown agent +--- +You are a markdown agent.`); + + const result = await parseAgentMarkdown(filePath); + expect(result).toHaveLength(1); + expect(result[0]).toMatchObject({ + name: 'test-agent-md', + description: 'A markdown agent', + kind: 'local', + system_prompt: 'You are a markdown agent.', + }); + }); + + it('should parse frontmatter with tools and model config', async () => { + const filePath = await writeAgentMarkdown(`--- +name: complex-agent +description: A complex markdown agent +tools: + - run_shell_command +model: gemini-pro +temperature: 0.7 +--- +System prompt content.`); + + const result = await parseAgentMarkdown(filePath); + expect(result).toHaveLength(1); + expect(result[0]).toMatchObject({ + name: 'complex-agent', + description: 'A complex markdown agent', + tools: ['run_shell_command'], + model: 'gemini-pro', + temperature: 0.7, + system_prompt: 'System prompt content.', + }); + }); + + it('should throw AgentLoadError if frontmatter is missing', async () => { + const filePath = await writeAgentMarkdown(`Just some markdown content.`); + await expect(parseAgentMarkdown(filePath)).rejects.toThrow( + AgentLoadError, + ); + await expect(parseAgentMarkdown(filePath)).rejects.toThrow( + 'Invalid markdown format', + ); + }); + + it('should throw AgentLoadError if frontmatter is invalid YAML', async () => { + const filePath = await writeAgentMarkdown(`--- +name: [invalid yaml +--- +Body`); + await expect(parseAgentMarkdown(filePath)).rejects.toThrow( + AgentLoadError, + ); + await expect(parseAgentMarkdown(filePath)).rejects.toThrow( + 'YAML frontmatter parsing failed', + ); + }); + + it('should throw AgentLoadError if validation fails (missing required field)', async () => { + const filePath = await writeAgentMarkdown(`--- +name: test-agent +# missing description +--- +Body`); + await expect(parseAgentMarkdown(filePath)).rejects.toThrow( + /Validation failed/, + ); + }); + + it('should throw AgentLoadError if tools list includes forbidden tool', async () => { + const filePath = await writeAgentMarkdown(`--- +name: test-agent +description: Test +tools: + - delegate_to_agent +--- +Body`); + await expect(parseAgentMarkdown(filePath)).rejects.toThrow( + /tools list cannot include 'delegate_to_agent'/, + ); + }); + + it('should parse a valid remote agent markdown file', async () => { + const filePath = await writeAgentMarkdown(`--- +kind: remote +name: remote-agent +description: A remote agent +agent_card_url: https://example.com/card +--- +`); + const result = await parseAgentMarkdown(filePath); + expect(result).toHaveLength(1); + expect(result[0]).toEqual({ + kind: 'remote', + name: 'remote-agent', + description: 'A remote agent', + agent_card_url: 'https://example.com/card', + }); + }); + + it('should infer remote agent kind from agent_card_url', async () => { + const filePath = await writeAgentMarkdown(`--- +name: inferred-remote +description: Inferred +agent_card_url: https://example.com/inferred +--- +`); + const result = await parseAgentMarkdown(filePath); + expect(result).toHaveLength(1); + expect(result[0]).toEqual({ + kind: 'remote', + name: 'inferred-remote', + description: 'Inferred', + agent_card_url: 'https://example.com/inferred', + }); + }); + + it('should parse a remote agent with no body', async () => { + const filePath = await writeAgentMarkdown(`--- +kind: remote +name: no-body-remote +agent_card_url: https://example.com/card +--- +`); + const result = await parseAgentMarkdown(filePath); + expect(result).toHaveLength(1); + expect(result[0]).toEqual({ + kind: 'remote', + name: 'no-body-remote', + agent_card_url: 'https://example.com/card', + }); + }); + + it('should parse multiple remote agents in a list', async () => { + const filePath = await writeAgentMarkdown(`--- +- kind: remote + name: remote-1 + agent_card_url: https://example.com/1 +- kind: remote + name: remote-2 + agent_card_url: https://example.com/2 +--- +`); + const result = await parseAgentMarkdown(filePath); + expect(result).toHaveLength(2); + expect(result[0]).toEqual({ + kind: 'remote', + name: 'remote-1', + agent_card_url: 'https://example.com/1', + }); + expect(result[1]).toEqual({ + kind: 'remote', + name: 'remote-2', + agent_card_url: 'https://example.com/2', + }); + }); + }); + + describe('markdownToAgentDefinition', () => { + it('should convert valid Markdown DTO to AgentDefinition with defaults', () => { + const markdown = { + kind: 'local' as const, + name: 'test-agent', + description: 'A test agent', + system_prompt: 'You are a test agent.', + }; + + const result = markdownToAgentDefinition(markdown); + expect(result).toMatchObject({ + name: 'test-agent', + description: 'A test agent', + promptConfig: { + systemPrompt: 'You are a test agent.', + query: '${query}', + }, + modelConfig: { + model: 'inherit', + top_p: 0.95, + }, + runConfig: { + max_time_minutes: 5, + }, + inputConfig: { + inputs: { + query: { + type: 'string', + required: false, + }, + }, + }, + }); + }); + + it('should pass through model aliases', () => { + const markdown = { + kind: 'local' as const, + name: 'test-agent', + description: 'A test agent', + model: GEMINI_MODEL_ALIAS_PRO, + system_prompt: 'You are a test agent.', + }; + + const result = markdownToAgentDefinition( + markdown, + ) as LocalAgentDefinition; + expect(result.modelConfig.model).toBe(GEMINI_MODEL_ALIAS_PRO); + }); + + it('should pass through unknown model names (e.g. auto)', () => { + const markdown = { + kind: 'local' as const, + name: 'test-agent', + description: 'A test agent', + model: 'auto', + system_prompt: 'You are a test agent.', + }; + + const result = markdownToAgentDefinition( + markdown, + ) as LocalAgentDefinition; + expect(result.modelConfig.model).toBe('auto'); + }); + + it('should convert remote agent definition', () => { + const markdown = { + kind: 'remote' as const, + name: 'remote-agent', + description: 'A remote agent', + agent_card_url: 'https://example.com/card', + }; + + const result = markdownToAgentDefinition(markdown); + expect(result).toEqual({ + kind: 'remote', + name: 'remote-agent', + description: 'A remote agent', + displayName: undefined, + agentCardUrl: 'https://example.com/card', + inputConfig: { + inputs: { + query: { + type: 'string', + description: 'The task for the agent.', + required: false, + }, + }, + }, + }); + }); + }); + + describe('loadAgentsFromDirectory', () => { + it('should load definitions from a directory (Markdown only)', async () => { + await writeAgentMarkdown( + `--- +name: agent-1 +description: Agent 1 +--- +Prompt 1`, + 'valid.md', + ); + + // Create a non-supported file + await fs.writeFile(path.join(tempDir, 'other.txt'), 'content'); + + // Create a hidden file + await writeAgentMarkdown( + `--- +name: hidden +description: Hidden +--- +Hidden`, + '_hidden.md', + ); + + const result = await loadAgentsFromDirectory(tempDir); + expect(result.agents).toHaveLength(1); + expect(result.agents[0].name).toBe('agent-1'); + expect(result.errors).toHaveLength(0); + }); + + it('should return empty result if directory does not exist', async () => { + const nonExistentDir = path.join(tempDir, 'does-not-exist'); + const result = await loadAgentsFromDirectory(nonExistentDir); + expect(result.agents).toHaveLength(0); + expect(result.errors).toHaveLength(0); + }); + + it('should capture errors for malformed individual files', async () => { + // Create a malformed Markdown file + await writeAgentMarkdown('invalid markdown', 'malformed.md'); + + const result = await loadAgentsFromDirectory(tempDir); + expect(result.agents).toHaveLength(0); + expect(result.errors).toHaveLength(1); + }); + }); +}); diff --git a/packages/core/src/agents/toml-loader.ts b/packages/core/src/agents/agentLoader.ts similarity index 58% rename from packages/core/src/agents/toml-loader.ts rename to packages/core/src/agents/agentLoader.ts index 28ab2207d6..5a65f03218 100644 --- a/packages/core/src/agents/toml-loader.ts +++ b/packages/core/src/agents/agentLoader.ts @@ -1,10 +1,10 @@ /** * @license - * Copyright 2025 Google LLC + * Copyright 2026 Google LLC * SPDX-License-Identifier: Apache-2.0 */ -import TOML from '@iarna/toml'; +import yaml from 'js-yaml'; import * as fs from 'node:fs/promises'; import { type Dirent } from 'node:fs'; import * as path from 'node:path'; @@ -14,40 +14,38 @@ import { isValidToolName, DELEGATE_TO_AGENT_TOOL_NAME, } from '../tools/tool-names.js'; +import { FRONTMATTER_REGEX } from '../skills/skillLoader.js'; /** - * DTO for TOML parsing - represents the raw structure of the TOML file. + * DTO for Markdown parsing - represents the structure from frontmatter. */ -interface TomlBaseAgentDefinition { +interface FrontmatterBaseAgentDefinition { name: string; display_name?: string; } -interface TomlLocalAgentDefinition extends TomlBaseAgentDefinition { +interface FrontmatterLocalAgentDefinition + extends FrontmatterBaseAgentDefinition { kind: 'local'; description: string; tools?: string[]; - prompts: { - system_prompt: string; - query?: string; - }; - model?: { - model?: string; - temperature?: number; - }; - run?: { - max_turns?: number; - timeout_mins?: number; - }; + system_prompt: string; + model?: string; + temperature?: number; + max_turns?: number; + timeout_mins?: number; } -interface TomlRemoteAgentDefinition extends TomlBaseAgentDefinition { - description?: string; +interface FrontmatterRemoteAgentDefinition + extends FrontmatterBaseAgentDefinition { kind: 'remote'; + description?: string; agent_card_url: string; } -type TomlAgentDefinition = TomlLocalAgentDefinition | TomlRemoteAgentDefinition; +type FrontmatterAgentDefinition = + | FrontmatterLocalAgentDefinition + | FrontmatterRemoteAgentDefinition; /** * Error thrown when an agent definition is invalid or cannot be loaded. @@ -87,22 +85,10 @@ const localAgentSchema = z }), ) .optional(), - prompts: z.object({ - system_prompt: z.string().min(1), - query: z.string().optional(), - }), - model: z - .object({ - model: z.string().optional(), - temperature: z.number().optional(), - }) - .optional(), - run: z - .object({ - max_turns: z.number().int().positive().optional(), - timeout_mins: z.number().int().positive().optional(), - }) - .optional(), + model: z.string().optional(), + temperature: z.number().optional(), + max_turns: z.number().int().positive().optional(), + timeout_mins: z.number().int().positive().optional(), }) .strict(); @@ -116,22 +102,16 @@ const remoteAgentSchema = z }) .strict(); -const remoteAgentsConfigSchema = z - .object({ - remote_agents: z.array(remoteAgentSchema), - }) - .strict(); - // Use a Zod union to automatically discriminate between local and remote -// agent types. This is more robust than manually checking the 'kind' field, -// as it correctly handles cases where 'kind' is omitted by relying on -// the presence of unique fields like `agent_card_url` or `prompts`. +// agent types. const agentUnionOptions = [ { schema: localAgentSchema, label: 'Local Agent' }, { schema: remoteAgentSchema, label: 'Remote Agent' }, ] as const; -const singleAgentSchema = z.union([ +const remoteAgentsListSchema = z.array(remoteAgentSchema); + +const markdownFrontmatterSchema = z.union([ agentUnionOptions[0].schema, agentUnionOptions[1].schema, ]); @@ -159,15 +139,15 @@ function formatZodError(error: z.ZodError, context: string): string { } /** - * Parses and validates an agent TOML file. Returns a validated array of RemoteAgentDefinitions or a single LocalAgentDefinition. + * Parses and validates an agent Markdown file with frontmatter. * - * @param filePath Path to the TOML file. - * @returns An array of parsed and validated TomlAgentDefinitions. + * @param filePath Path to the Markdown file. + * @returns An array containing the single parsed agent definition. * @throws AgentLoadError if parsing or validation fails. */ -export async function parseAgentToml( +export async function parseAgentMarkdown( filePath: string, -): Promise { +): Promise { let content: string; try { content = await fs.readFile(filePath, 'utf-8'); @@ -178,34 +158,44 @@ export async function parseAgentToml( ); } - let raw: unknown; - try { - raw = TOML.parse(content); - } catch (error) { + // Split frontmatter and body + const match = content.match(FRONTMATTER_REGEX); + if (!match) { throw new AgentLoadError( filePath, - `TOML parsing failed: ${(error as Error).message}`, + 'Invalid markdown format. File must start with YAML frontmatter enclosed in "---".', ); } - // Check for `remote_agents` array - if ( - typeof raw === 'object' && - raw !== null && - 'remote_agents' in (raw as Record) - ) { - const result = remoteAgentsConfigSchema.safeParse(raw); + const frontmatterStr = match[1]; + const body = match[2] || ''; + + let rawFrontmatter: unknown; + try { + rawFrontmatter = yaml.load(frontmatterStr); + } catch (error) { + throw new AgentLoadError( + filePath, + `YAML frontmatter parsing failed: ${(error as Error).message}`, + ); + } + + // Handle array of remote agents + if (Array.isArray(rawFrontmatter)) { + const result = remoteAgentsListSchema.safeParse(rawFrontmatter); if (!result.success) { throw new AgentLoadError( filePath, - `Validation failed: ${formatZodError(result.error, 'Remote Agents Config')}`, + `Validation failed: ${formatZodError(result.error, 'Remote Agents List')}`, ); } - return result.data.remote_agents as TomlAgentDefinition[]; + return result.data.map((agent) => ({ + ...agent, + kind: 'remote', + })); } - // Single Agent Logic - const result = singleAgentSchema.safeParse(raw); + const result = markdownFrontmatterSchema.safeParse(rawFrontmatter); if (!result.success) { throw new AgentLoadError( @@ -214,27 +204,47 @@ export async function parseAgentToml( ); } - const toml = result.data as TomlAgentDefinition; + const frontmatter = result.data; - // Prevent sub-agents from delegating to other agents (to prevent recursion/complexity) - if ('tools' in toml && toml.tools?.includes(DELEGATE_TO_AGENT_TOOL_NAME)) { + if (frontmatter.kind === 'remote') { + return [ + { + ...frontmatter, + kind: 'remote', + }, + ]; + } + + // Local agent validation + // Validate tools + if ( + frontmatter.tools && + frontmatter.tools.includes(DELEGATE_TO_AGENT_TOOL_NAME) + ) { throw new AgentLoadError( filePath, `Validation failed: tools list cannot include '${DELEGATE_TO_AGENT_TOOL_NAME}'. Sub-agents cannot delegate to other agents.`, ); } - return [toml]; + // Construct the local agent definition + const agentDef: FrontmatterLocalAgentDefinition = { + ...frontmatter, + kind: 'local', + system_prompt: body.trim(), + }; + + return [agentDef]; } /** - * Converts a TomlAgentDefinition DTO to the internal AgentDefinition structure. + * Converts a FrontmatterAgentDefinition DTO to the internal AgentDefinition structure. * - * @param toml The parsed TOML definition. + * @param markdown The parsed Markdown/Frontmatter definition. * @returns The internal AgentDefinition. */ -export function tomlToAgentDefinition( - toml: TomlAgentDefinition, +export function markdownToAgentDefinition( + markdown: FrontmatterAgentDefinition, ): AgentDefinition { const inputConfig = { inputs: { @@ -246,41 +256,41 @@ export function tomlToAgentDefinition( }, }; - if (toml.kind === 'remote') { + if (markdown.kind === 'remote') { return { kind: 'remote', - name: toml.name, - description: toml.description || '(Loading description...)', - displayName: toml.display_name, - agentCardUrl: toml.agent_card_url, + name: markdown.name, + description: markdown.description || '(Loading description...)', + displayName: markdown.display_name, + agentCardUrl: markdown.agent_card_url, inputConfig, }; } // If a model is specified, use it. Otherwise, inherit - const modelName = toml.model?.model || 'inherit'; + const modelName = markdown.model || 'inherit'; return { kind: 'local', - name: toml.name, - description: toml.description, - displayName: toml.display_name, + name: markdown.name, + description: markdown.description, + displayName: markdown.display_name, promptConfig: { - systemPrompt: toml.prompts.system_prompt, - query: toml.prompts.query, + systemPrompt: markdown.system_prompt, + query: '${query}', }, modelConfig: { model: modelName, - temp: toml.model?.temperature ?? 1, + temp: markdown.temperature ?? 1, top_p: 0.95, }, runConfig: { - max_turns: toml.run?.max_turns, - max_time_minutes: toml.run?.timeout_mins || 5, + max_turns: markdown.max_turns, + max_time_minutes: markdown.timeout_mins || 5, }, - toolConfig: toml.tools + toolConfig: markdown.tools ? { - tools: toml.tools, + tools: markdown.tools, } : undefined, inputConfig, @@ -289,7 +299,8 @@ export function tomlToAgentDefinition( /** * Loads all agents from a specific directory. - * Ignores non-TOML files and files starting with _. + * Ignores files starting with _ and non-supported extensions. + * Supported extensions: .md * * @param dir Directory path to scan. * @returns Object containing successfully loaded agents and any errors. @@ -319,21 +330,19 @@ export async function loadAgentsFromDirectory( return result; } - const files = dirEntries - .filter( - (entry) => - entry.isFile() && - entry.name.endsWith('.toml') && - !entry.name.startsWith('_'), - ) - .map((entry) => entry.name); + const files = dirEntries.filter( + (entry) => + entry.isFile() && + !entry.name.startsWith('_') && + entry.name.endsWith('.md'), + ); - for (const file of files) { - const filePath = path.join(dir, file); + for (const entry of files) { + const filePath = path.join(dir, entry.name); try { - const tomls = await parseAgentToml(filePath); - for (const toml of tomls) { - const agent = tomlToAgentDefinition(toml); + const agentDefs = await parseAgentMarkdown(filePath); + for (const def of agentDefs) { + const agent = markdownToAgentDefinition(def); result.agents.push(agent); } } catch (error) { diff --git a/packages/core/src/agents/registry.test.ts b/packages/core/src/agents/registry.test.ts index 073dd5ac10..42a6aab25b 100644 --- a/packages/core/src/agents/registry.test.ts +++ b/packages/core/src/agents/registry.test.ts @@ -19,9 +19,9 @@ import { PREVIEW_GEMINI_MODEL, PREVIEW_GEMINI_MODEL_AUTO, } from '../config/models.js'; -import * as tomlLoader from './toml-loader.js'; +import * as tomlLoader from './agentLoader.js'; -vi.mock('./toml-loader.js', () => ({ +vi.mock('./agentLoader.js', () => ({ loadAgentsFromDirectory: vi .fn() .mockResolvedValue({ agents: [], errors: [] }), diff --git a/packages/core/src/agents/registry.ts b/packages/core/src/agents/registry.ts index 8a35a70241..9b9ccb19ed 100644 --- a/packages/core/src/agents/registry.ts +++ b/packages/core/src/agents/registry.ts @@ -8,7 +8,7 @@ import { Storage } from '../config/storage.js'; import { coreEvents, CoreEvent } from '../utils/events.js'; import type { Config } from '../config/config.js'; import type { AgentDefinition } from './types.js'; -import { loadAgentsFromDirectory } from './toml-loader.js'; +import { loadAgentsFromDirectory } from './agentLoader.js'; import { CodebaseInvestigatorAgent } from './codebase-investigator.js'; import { CliHelpAgent } from './cli-help-agent.js'; import { A2AClientManager } from './a2a-client-manager.js'; diff --git a/packages/core/src/agents/toml-loader.test.ts b/packages/core/src/agents/toml-loader.test.ts deleted file mode 100644 index 5e91887cd8..0000000000 --- a/packages/core/src/agents/toml-loader.test.ts +++ /dev/null @@ -1,373 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import { describe, it, expect, beforeEach, afterEach } from 'vitest'; -import * as fs from 'node:fs/promises'; -import * as path from 'node:path'; -import * as os from 'node:os'; -import { - parseAgentToml, - tomlToAgentDefinition, - loadAgentsFromDirectory, - AgentLoadError, -} from './toml-loader.js'; -import { GEMINI_MODEL_ALIAS_PRO } from '../config/models.js'; -import type { LocalAgentDefinition } from './types.js'; - -describe('toml-loader', () => { - let tempDir: string; - - beforeEach(async () => { - tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'agent-test-')); - }); - - afterEach(async () => { - if (tempDir) { - await fs.rm(tempDir, { recursive: true, force: true }); - } - }); - - async function writeAgentToml(content: string, fileName = 'test.toml') { - const filePath = path.join(tempDir, fileName); - await fs.writeFile(filePath, content); - return filePath; - } - - describe('parseAgentToml', () => { - it('should parse a valid MVA TOML file', async () => { - const filePath = await writeAgentToml(` - name = "test-agent" - description = "A test agent" - [prompts] - system_prompt = "You are a test agent." - `); - - const result = await parseAgentToml(filePath); - expect(result).toHaveLength(1); - expect(result[0]).toMatchObject({ - name: 'test-agent', - description: 'A test agent', - prompts: { - system_prompt: 'You are a test agent.', - }, - }); - }); - - it('should parse a valid remote agent TOML file', async () => { - const filePath = await writeAgentToml(` - kind = "remote" - name = "remote-agent" - description = "A remote agent" - agent_card_url = "https://example.com/card" - `); - - const result = await parseAgentToml(filePath); - expect(result).toHaveLength(1); - expect(result[0]).toEqual({ - kind: 'remote', - name: 'remote-agent', - description: 'A remote agent', - agent_card_url: 'https://example.com/card', - }); - }); - - it('should infer remote agent kind from agent_card_url', async () => { - const filePath = await writeAgentToml(` - name = "inferred-remote" - description = "Inferred" - agent_card_url = "https://example.com/inferred" - `); - - const result = await parseAgentToml(filePath); - expect(result).toHaveLength(1); - expect(result[0]).toEqual({ - kind: 'remote', - name: 'inferred-remote', - description: 'Inferred', - agent_card_url: 'https://example.com/inferred', - }); - }); - - it('should parse a remote agent without description', async () => { - const filePath = await writeAgentToml(` - kind = "remote" - name = "no-description-remote" - agent_card_url = "https://example.com/card" - `); - - const result = await parseAgentToml(filePath); - expect(result).toHaveLength(1); - expect(result[0]).toEqual({ - kind: 'remote', - name: 'no-description-remote', - agent_card_url: 'https://example.com/card', - }); - expect(result[0].description).toBeUndefined(); - - // defined after conversion to AgentDefinition - const agentDef = tomlToAgentDefinition(result[0]); - expect(agentDef.description).toBe('(Loading description...)'); - }); - - it('should parse multiple agents in one file', async () => { - const filePath = await writeAgentToml(` - [[remote_agents]] - kind = "remote" - name = "agent-1" - description = "Remote 1" - agent_card_url = "https://example.com/1" - - [[remote_agents]] - kind = "remote" - name = "agent-2" - description = "Remote 2" - agent_card_url = "https://example.com/2" - `); - - const result = await parseAgentToml(filePath); - expect(result).toHaveLength(2); - expect(result[0].name).toBe('agent-1'); - expect(result[0].kind).toBe('remote'); - expect(result[1].name).toBe('agent-2'); - expect(result[1].kind).toBe('remote'); - }); - - it('should allow omitting kind in remote_agents block', async () => { - const filePath = await writeAgentToml(` - [[remote_agents]] - name = "implicit-remote-1" - agent_card_url = "https://example.com/1" - - [[remote_agents]] - name = "implicit-remote-2" - agent_card_url = "https://example.com/2" - `); - - const result = await parseAgentToml(filePath); - expect(result).toHaveLength(2); - expect(result[0]).toMatchObject({ - kind: 'remote', - name: 'implicit-remote-1', - agent_card_url: 'https://example.com/1', - }); - expect(result[1]).toMatchObject({ - kind: 'remote', - name: 'implicit-remote-2', - agent_card_url: 'https://example.com/2', - }); - }); - - it('should throw AgentLoadError if file reading fails', async () => { - const filePath = path.join(tempDir, 'non-existent.toml'); - await expect(parseAgentToml(filePath)).rejects.toThrow(AgentLoadError); - }); - - it('should throw AgentLoadError if TOML parsing fails', async () => { - const filePath = await writeAgentToml('invalid toml ['); - await expect(parseAgentToml(filePath)).rejects.toThrow(AgentLoadError); - }); - - it('should throw AgentLoadError if validation fails (missing required field)', async () => { - const filePath = await writeAgentToml(` - name = "test-agent" - # missing description - [prompts] - system_prompt = "You are a test agent." - `); - await expect(parseAgentToml(filePath)).rejects.toThrow( - /Validation failed/, - ); - }); - - it('should throw AgentLoadError if name is not a slug', async () => { - const filePath = await writeAgentToml(` - name = "Test Agent!" - description = "A test agent" - [prompts] - system_prompt = "You are a test agent." - `); - await expect(parseAgentToml(filePath)).rejects.toThrow( - /Name must be a valid slug/, - ); - }); - - it('should throw AgentLoadError if delegate_to_agent is included in tools', async () => { - const filePath = await writeAgentToml(` - name = "test-agent" - description = "A test agent" - tools = ["run_shell_command", "delegate_to_agent"] - [prompts] - system_prompt = "You are a test agent." - `); - - await expect(parseAgentToml(filePath)).rejects.toThrow( - /tools list cannot include 'delegate_to_agent'/, - ); - }); - - it('should throw AgentLoadError if tools contains invalid names', async () => { - const filePath = await writeAgentToml(` - name = "test-agent" - description = "A test agent" - tools = ["not-a-tool"] - [prompts] - system_prompt = "You are a test agent." - `); - await expect(parseAgentToml(filePath)).rejects.toThrow( - /Validation failed:[\s\S]*tools.0: Invalid tool name/, - ); - }); - - it('should throw AgentLoadError if file contains both single and multiple agents', async () => { - const filePath = await writeAgentToml(` - name = "top-level-agent" - description = "I should not be here" - [prompts] - system_prompt = "..." - - [[remote_agents]] - kind = "remote" - name = "array-agent" - description = "I am in an array" - agent_card_url = "https://example.com/card" - `); - - await expect(parseAgentToml(filePath)).rejects.toThrow( - /Validation failed/, - ); - }); - - it('should show both options in error message when validation fails ambiguously', async () => { - const filePath = await writeAgentToml(` - name = "ambiguous-agent" - description = "I have neither prompts nor card" - `); - await expect(parseAgentToml(filePath)).rejects.toThrow( - /Validation failed: Agent Definition:\n\(Local Agent\) prompts: Required\n\(Remote Agent\) agent_card_url: Required/, - ); - }); - }); - - describe('tomlToAgentDefinition', () => { - it('should convert valid TOML to AgentDefinition with defaults', () => { - const toml = { - kind: 'local' as const, - name: 'test-agent', - description: 'A test agent', - prompts: { - system_prompt: 'You are a test agent.', - }, - }; - - const result = tomlToAgentDefinition(toml); - expect(result).toMatchObject({ - name: 'test-agent', - description: 'A test agent', - promptConfig: { - systemPrompt: 'You are a test agent.', - }, - modelConfig: { - model: 'inherit', - top_p: 0.95, - }, - runConfig: { - max_time_minutes: 5, - }, - inputConfig: { - inputs: { - query: { - type: 'string', - required: false, - }, - }, - }, - }); - }); - - it('should pass through model aliases', () => { - const toml = { - kind: 'local' as const, - name: 'test-agent', - description: 'A test agent', - model: { - model: GEMINI_MODEL_ALIAS_PRO, - }, - prompts: { - system_prompt: 'You are a test agent.', - }, - }; - - const result = tomlToAgentDefinition(toml) as LocalAgentDefinition; - expect(result.modelConfig.model).toBe(GEMINI_MODEL_ALIAS_PRO); - }); - - it('should pass through unknown model names (e.g. auto)', () => { - const toml = { - kind: 'local' as const, - name: 'test-agent', - description: 'A test agent', - model: { - model: 'auto', - }, - prompts: { - system_prompt: 'You are a test agent.', - }, - }; - - const result = tomlToAgentDefinition(toml) as LocalAgentDefinition; - expect(result.modelConfig.model).toBe('auto'); - }); - }); - - describe('loadAgentsFromDirectory', () => { - it('should load definitions from a directory', async () => { - await writeAgentToml( - ` - name = "agent-1" - description = "Agent 1" - [prompts] - system_prompt = "Prompt 1" - `, - 'valid.toml', - ); - - // Create a non-TOML file - await fs.writeFile(path.join(tempDir, 'other.txt'), 'content'); - - // Create a hidden file - await writeAgentToml( - ` - name = "hidden" - description = "Hidden" - [prompts] - system_prompt = "Hidden" - `, - '_hidden.toml', - ); - - const result = await loadAgentsFromDirectory(tempDir); - expect(result.agents).toHaveLength(1); - expect(result.agents[0].name).toBe('agent-1'); - expect(result.errors).toHaveLength(0); - }); - - it('should return empty result if directory does not exist', async () => { - const nonExistentDir = path.join(tempDir, 'does-not-exist'); - const result = await loadAgentsFromDirectory(nonExistentDir); - expect(result.agents).toHaveLength(0); - expect(result.errors).toHaveLength(0); - }); - - it('should capture errors for malformed individual files', async () => { - // Create a malformed TOML file - await writeAgentToml('invalid toml [', 'malformed.toml'); - - const result = await loadAgentsFromDirectory(tempDir); - expect(result.agents).toHaveLength(0); - expect(result.errors).toHaveLength(1); - }); - }); -}); diff --git a/packages/core/src/skills/skillLoader.ts b/packages/core/src/skills/skillLoader.ts index be962eaa67..f5ef5a643c 100644 --- a/packages/core/src/skills/skillLoader.ts +++ b/packages/core/src/skills/skillLoader.ts @@ -29,7 +29,7 @@ export interface SkillDefinition { isBuiltin?: boolean; } -const FRONTMATTER_REGEX = /^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)/; +export const FRONTMATTER_REGEX = /^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)/; /** * Discovers and loads all skills in the provided directory. From 64c75cb767cee155c9722129fd081f1a0251650f Mon Sep 17 00:00:00 2001 From: christine betts Date: Mon, 12 Jan 2026 11:52:19 -0500 Subject: [PATCH 122/713] Fix crash on unicode character (#16420) --- packages/cli/src/ui/utils/textUtils.test.ts | 19 ++++++++++++++++++- packages/cli/src/ui/utils/textUtils.ts | 10 +++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/ui/utils/textUtils.test.ts b/packages/cli/src/ui/utils/textUtils.test.ts index eaf501a1fb..f9a90c63b4 100644 --- a/packages/cli/src/ui/utils/textUtils.test.ts +++ b/packages/cli/src/ui/utils/textUtils.test.ts @@ -9,9 +9,26 @@ import type { ToolCallConfirmationDetails, ToolEditConfirmationDetails, } from '@google/gemini-cli-core'; -import { escapeAnsiCtrlCodes, stripUnsafeCharacters } from './textUtils.js'; +import { + escapeAnsiCtrlCodes, + stripUnsafeCharacters, + getCachedStringWidth, +} from './textUtils.js'; describe('textUtils', () => { + describe('getCachedStringWidth', () => { + it('should handle unicode characters that crash string-width', () => { + // U+0602 caused string-width to crash (see #16418) + const char = '؂'; + expect(getCachedStringWidth(char)).toBe(1); + }); + + it('should handle unicode characters that crash string-width with ANSI codes', () => { + const charWithAnsi = '\u001b[31m' + '؂' + '\u001b[0m'; + expect(getCachedStringWidth(charWithAnsi)).toBe(1); + }); + }); + describe('stripUnsafeCharacters', () => { it('should not strip tab characters', () => { const input = 'hello world'; diff --git a/packages/cli/src/ui/utils/textUtils.ts b/packages/cli/src/ui/utils/textUtils.ts index 5da186c423..13c009a136 100644 --- a/packages/cli/src/ui/utils/textUtils.ts +++ b/packages/cli/src/ui/utils/textUtils.ts @@ -136,7 +136,15 @@ export const getCachedStringWidth = (str: string): number => { return stringWidthCache.get(str)!; } - const width = stringWidth(str); + let width: number; + try { + width = stringWidth(str); + } catch { + // Fallback for characters that cause string-width to crash (e.g. U+0602) + // See: https://github.com/google-gemini/gemini-cli/issues/16418 + width = toCodePoints(stripAnsi(str)).length; + } + stringWidthCache.set(str, width); return width; From 950244f6b00ff54c9c9ee40b2b0d16d980021f80 Mon Sep 17 00:00:00 2001 From: christine betts Date: Mon, 12 Jan 2026 11:53:04 -0500 Subject: [PATCH 123/713] Attempt to resolve OOM w/ useMemo on history items (#16424) --- .../cli/src/ui/components/MainContent.tsx | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/cli/src/ui/components/MainContent.tsx b/packages/cli/src/ui/components/MainContent.tsx index a60f782d8f..f46a9c0c2f 100644 --- a/packages/cli/src/ui/components/MainContent.tsx +++ b/packages/cli/src/ui/components/MainContent.tsx @@ -36,17 +36,26 @@ export const MainContent = () => { availableTerminalHeight, } = uiState; - const historyItems = uiState.history.map((h) => ( - - )); + const historyItems = useMemo( + () => + uiState.history.map((h) => ( + + )), + [ + uiState.history, + mainAreaWidth, + staticAreaMaxItemHeight, + uiState.slashCommands, + ], + ); const pendingItems = useMemo( () => ( From 465ec9759dbb173118f43f36b4e90c42482ee140 Mon Sep 17 00:00:00 2001 From: Adam Weidman <65992621+adamfweidman@users.noreply.github.com> Date: Mon, 12 Jan 2026 12:11:24 -0500 Subject: [PATCH 124/713] fix(core): ensure sub-agent schema and prompt refresh during runtime (#16409) Co-authored-by: Sehoon Shon --- packages/cli/src/utils/cleanup.ts | 8 ++++ .../core/src/agents/cli-help-agent.test.ts | 17 +++++++ packages/core/src/agents/cli-help-agent.ts | 6 +++ packages/core/src/agents/registry.ts | 25 ++++++---- packages/core/src/config/config.test.ts | 11 +++-- packages/core/src/config/config.ts | 48 +++++++++++++++++-- packages/core/src/core/prompts.test.ts | 2 + 7 files changed, 101 insertions(+), 16 deletions(-) diff --git a/packages/cli/src/utils/cleanup.ts b/packages/cli/src/utils/cleanup.ts index ccb467572b..da9ff927ef 100644 --- a/packages/cli/src/utils/cleanup.ts +++ b/packages/cli/src/utils/cleanup.ts @@ -65,6 +65,14 @@ export async function runExitCleanup() { } cleanupFunctions.length = 0; // Clear the array + if (configForTelemetry) { + try { + await configForTelemetry.dispose(); + } catch (_) { + // Ignore errors during disposal + } + } + // IMPORTANT: Shutdown telemetry AFTER all other cleanup functions have run // This ensures SessionEnd hooks and other telemetry are properly flushed if (configForTelemetry && isTelemetrySdkInitialized()) { diff --git a/packages/core/src/agents/cli-help-agent.test.ts b/packages/core/src/agents/cli-help-agent.test.ts index b1552f3d62..579dd58d72 100644 --- a/packages/core/src/agents/cli-help-agent.test.ts +++ b/packages/core/src/agents/cli-help-agent.test.ts @@ -14,6 +14,7 @@ import type { Config } from '../config/config.js'; describe('CliHelpAgent', () => { const fakeConfig = { getMessageBus: () => ({}), + isAgentsEnabled: () => false, } as unknown as Config; const localAgent = CliHelpAgent(fakeConfig) as LocalAgentDefinition; @@ -52,6 +53,22 @@ describe('CliHelpAgent', () => { expect(query).toContain('${question}'); }); + it('should include sub-agent information when agents are enabled', () => { + const enabledConfig = { + getMessageBus: () => ({}), + isAgentsEnabled: () => true, + getAgentRegistry: () => ({ + getDirectoryContext: () => 'Mock Agent Directory', + }), + } as unknown as Config; + const agent = CliHelpAgent(enabledConfig) as LocalAgentDefinition; + const systemPrompt = agent.promptConfig.systemPrompt || ''; + + expect(systemPrompt).toContain('### Sub-Agents (Local & Remote)'); + expect(systemPrompt).toContain('Remote Agent (A2A)'); + expect(systemPrompt).toContain('Agent2Agent functionality'); + }); + it('should process output to a formatted JSON string', () => { const mockOutput = { answer: 'This is the answer.', diff --git a/packages/core/src/agents/cli-help-agent.ts b/packages/core/src/agents/cli-help-agent.ts index 331be120e9..a1909454bf 100644 --- a/packages/core/src/agents/cli-help-agent.ts +++ b/packages/core/src/agents/cli-help-agent.ts @@ -76,6 +76,12 @@ export const CliHelpAgent = ( '- **CLI Version:** ${cliVersion}\n' + '- **Active Model:** ${activeModel}\n' + "- **Today's Date:** ${today}\n\n" + + (config.isAgentsEnabled() + ? '### Sub-Agents (Local & Remote)\n' + + 'User defined sub-agents are defined in `.gemini/agents/` or `~/.gemini/agents/` using YAML frontmatter for metadata and Markdown for instructions (system_prompt). Always reference the types and properties outlined here directly when answering questions about sub-agents.\n' + + '- **Local Agent:** `kind = "local"`, `name`, `description`, `prompts.system_prompt`, and optional `tools`, `model`, `run`.\n' + + '- **Remote Agent (A2A):** `kind = "remote"`, `name`, `agent_card_url`. Multiple remotes can be defined using a `remote_agents` array. **Note:** When users ask about "remote agents", they are referring to this Agent2Agent functionality, which is completely distinct from MCP servers.\n\n' + : '') + '### Instructions\n' + "1. **Explore Documentation**: Use the `get_internal_docs` tool to find answers. If you don't know where to start, call `get_internal_docs()` without arguments to see the full list of available documentation files.\n" + '2. **Be Precise**: Use the provided runtime context and documentation to give exact answers.\n' + diff --git a/packages/core/src/agents/registry.ts b/packages/core/src/agents/registry.ts index 9b9ccb19ed..71cb1442cc 100644 --- a/packages/core/src/agents/registry.ts +++ b/packages/core/src/agents/registry.ts @@ -46,18 +46,20 @@ export class AgentRegistry { * Discovers and loads agents. */ async initialize(): Promise { - coreEvents.on(CoreEvent.ModelChanged, () => { - this.refreshAgents().catch((e) => { - debugLogger.error( - '[AgentRegistry] Failed to refresh agents on model change:', - e, - ); - }); - }); + coreEvents.on(CoreEvent.ModelChanged, this.onModelChanged); await this.loadAgents(); } + private onModelChanged = () => { + this.refreshAgents().catch((e) => { + debugLogger.error( + '[AgentRegistry] Failed to refresh agents on model change:', + e, + ); + }); + }; + /** * Clears the current registry and re-scans for agents. */ @@ -68,6 +70,13 @@ export class AgentRegistry { coreEvents.emitAgentsRefreshed(); } + /** + * Disposes of resources and removes event listeners. + */ + dispose(): void { + coreEvents.off(CoreEvent.ModelChanged, this.onModelChanged); + } + private async loadAgents(): Promise { this.loadBuiltInAgents(); diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index 8e1c9d9b68..2ccbb4c546 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -167,13 +167,18 @@ const mockCoreEvents = vi.hoisted(() => ({ emitFeedback: vi.fn(), emitModelChanged: vi.fn(), emitConsoleLog: vi.fn(), + on: vi.fn(), })); const mockSetGlobalProxy = vi.hoisted(() => vi.fn()); -vi.mock('../utils/events.js', () => ({ - coreEvents: mockCoreEvents, -})); +vi.mock('../utils/events.js', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + coreEvents: mockCoreEvents, + }; +}); vi.mock('../utils/fetch.js', () => ({ setGlobalProxy: mockSetGlobalProxy, diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 60783cffab..241de0d04f 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -43,7 +43,7 @@ import { DEFAULT_OTLP_ENDPOINT, uiTelemetryService, } from '../telemetry/index.js'; -import { coreEvents } from '../utils/events.js'; +import { coreEvents, CoreEvent } from '../utils/events.js'; import { tokenLimit } from '../core/tokenLimits.js'; import { DEFAULT_GEMINI_EMBEDDING_MODEL, @@ -735,6 +735,8 @@ export class Config { this.agentRegistry = new AgentRegistry(this); await this.agentRegistry.initialize(); + coreEvents.on(CoreEvent.AgentsRefreshed, this.onAgentsRefreshed); + this.toolRegistry = await this.createToolRegistry(); discoverToolsHandle?.end(); this.mcpClientManager = new McpClientManager( @@ -1764,6 +1766,17 @@ export class Config { // Register Subagents as Tools // Register DelegateToAgentTool if agents are enabled + this.registerDelegateToAgentTool(registry); + + await registry.discoverAllTools(); + registry.sortTools(); + return registry; + } + + /** + * Registers the DelegateToAgentTool if agents or related features are enabled. + */ + private registerDelegateToAgentTool(registry: ToolRegistry): void { if ( this.isAgentsEnabled() || this.getCodebaseInvestigatorSettings().enabled || @@ -1783,10 +1796,6 @@ export class Config { registry.registerTool(delegateTool); } } - - await registry.discoverAllTools(); - registry.sortTools(); - return registry; } /** @@ -1870,6 +1879,35 @@ export class Config { }); debugLogger.debug('Experiments loaded', summaryString); } + + private onAgentsRefreshed = async () => { + if (this.toolRegistry) { + this.registerDelegateToAgentTool(this.toolRegistry); + } + // Propagate updates to the active chat session + const client = this.getGeminiClient(); + if (client?.isInitialized()) { + await client.setTools(); + await client.updateSystemInstruction(); + } else { + debugLogger.debug( + '[Config] GeminiClient not initialized; skipping live prompt/tool refresh.', + ); + } + }; + + /** + * Disposes of resources and removes event listeners. + */ + async dispose(): Promise { + coreEvents.off(CoreEvent.AgentsRefreshed, this.onAgentsRefreshed); + if (this.agentRegistry) { + this.agentRegistry.dispose(); + } + if (this.mcpClientManager) { + await this.mcpClientManager.stop(); + } + } } // Export model constants for use in CLI export { DEFAULT_GEMINI_FLASH_MODEL }; diff --git a/packages/core/src/core/prompts.test.ts b/packages/core/src/core/prompts.test.ts index 1ecdcc2776..039453ca12 100644 --- a/packages/core/src/core/prompts.test.ts +++ b/packages/core/src/core/prompts.test.ts @@ -66,6 +66,7 @@ describe('Core System Prompt (prompts.ts)', () => { }, isInteractive: vi.fn().mockReturnValue(true), isInteractiveShellEnabled: vi.fn().mockReturnValue(true), + isAgentsEnabled: vi.fn().mockReturnValue(false), getModel: vi.fn().mockReturnValue(DEFAULT_GEMINI_MODEL_AUTO), getActiveModel: vi.fn().mockReturnValue(DEFAULT_GEMINI_MODEL), getPreviewFeatures: vi.fn().mockReturnValue(false), @@ -214,6 +215,7 @@ describe('Core System Prompt (prompts.ts)', () => { }, isInteractive: vi.fn().mockReturnValue(false), isInteractiveShellEnabled: vi.fn().mockReturnValue(false), + isAgentsEnabled: vi.fn().mockReturnValue(false), getModel: vi.fn().mockReturnValue('auto'), getActiveModel: vi.fn().mockReturnValue(DEFAULT_GEMINI_MODEL), getPreviewFeatures: vi.fn().mockReturnValue(false), From ed7bcf9968edece61b8d2d7eb3403dd001e3bb28 Mon Sep 17 00:00:00 2001 From: christine betts Date: Mon, 12 Jan 2026 12:16:35 -0500 Subject: [PATCH 125/713] Update extension examples (#16274) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- eslint.config.js | 10 ++ .../examples/hooks/gemini-extension.json | 4 + .../examples/hooks/hooks/hooks.json | 14 ++ .../examples/hooks/scripts/on-start.js | 8 ++ .../extensions/examples/mcp-server/README.md | 35 +++++ .../mcp-server/{example.ts => example.js} | 0 .../examples/mcp-server/example.test.ts | 135 ------------------ .../examples/mcp-server/gemini-extension.json | 2 +- .../examples/mcp-server/package.json | 7 - .../examples/mcp-server/tsconfig.json | 13 -- .../examples/skills/gemini-extension.json | 4 + .../examples/skills/skills/greeter/SKILL.md | 7 + packages/cli/tsconfig.json | 2 +- 13 files changed, 84 insertions(+), 157 deletions(-) create mode 100644 packages/cli/src/commands/extensions/examples/hooks/gemini-extension.json create mode 100644 packages/cli/src/commands/extensions/examples/hooks/hooks/hooks.json create mode 100644 packages/cli/src/commands/extensions/examples/hooks/scripts/on-start.js create mode 100644 packages/cli/src/commands/extensions/examples/mcp-server/README.md rename packages/cli/src/commands/extensions/examples/mcp-server/{example.ts => example.js} (100%) delete mode 100644 packages/cli/src/commands/extensions/examples/mcp-server/example.test.ts delete mode 100644 packages/cli/src/commands/extensions/examples/mcp-server/tsconfig.json create mode 100644 packages/cli/src/commands/extensions/examples/skills/gemini-extension.json create mode 100644 packages/cli/src/commands/extensions/examples/skills/skills/greeter/SKILL.md diff --git a/eslint.config.js b/eslint.config.js index c2d0d3b69b..959fbc5edb 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -301,6 +301,16 @@ export default tseslint.config( '@typescript-eslint/no-require-imports': 'off', }, }, + // Examples should have access to standard globals like fetch + { + files: ['packages/cli/src/commands/extensions/examples/**/*.js'], + languageOptions: { + globals: { + ...globals.node, + fetch: 'readonly', + }, + }, + }, // extra settings for scripts that we run directly with node { files: ['packages/vscode-ide-companion/scripts/**/*.js'], diff --git a/packages/cli/src/commands/extensions/examples/hooks/gemini-extension.json b/packages/cli/src/commands/extensions/examples/hooks/gemini-extension.json new file mode 100644 index 0000000000..708e986346 --- /dev/null +++ b/packages/cli/src/commands/extensions/examples/hooks/gemini-extension.json @@ -0,0 +1,4 @@ +{ + "name": "hooks-example", + "version": "1.0.0" +} diff --git a/packages/cli/src/commands/extensions/examples/hooks/hooks/hooks.json b/packages/cli/src/commands/extensions/examples/hooks/hooks/hooks.json new file mode 100644 index 0000000000..f1af86d980 --- /dev/null +++ b/packages/cli/src/commands/extensions/examples/hooks/hooks/hooks.json @@ -0,0 +1,14 @@ +{ + "hooks": { + "SessionStart": [ + { + "hooks": [ + { + "type": "command", + "command": "node ${extensionPath}/scripts/on-start.js" + } + ] + } + ] + } +} diff --git a/packages/cli/src/commands/extensions/examples/hooks/scripts/on-start.js b/packages/cli/src/commands/extensions/examples/hooks/scripts/on-start.js new file mode 100644 index 0000000000..1f426f9a2f --- /dev/null +++ b/packages/cli/src/commands/extensions/examples/hooks/scripts/on-start.js @@ -0,0 +1,8 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ +console.log( + 'Session Started! This is running from a script in the hooks-example extension.', +); diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/README.md b/packages/cli/src/commands/extensions/examples/mcp-server/README.md new file mode 100644 index 0000000000..3ca50977ed --- /dev/null +++ b/packages/cli/src/commands/extensions/examples/mcp-server/README.md @@ -0,0 +1,35 @@ +# MCP Server Example + +This is a basic example of an MCP (Model Context Protocol) server used as a +Gemini CLI extension. It demonstrates how to expose tools and prompts to the +Gemini CLI. + +## Description + +The contents of this directory are a valid MCP server implementation using the +`@modelcontextprotocol/sdk`. It exposes: + +- A tool `fetch_posts` that mock-fetches posts. +- A prompt `poem-writer`. + +## Structure + +- `example.js`: The main server entry point. +- `gemini-extension.json`: The configuration file that tells Gemini CLI how to + use this extension. +- `package.json`: Helper for dependencies. + +## How to Use + +1. Navigate to this directory: + + ```bash + cd packages/cli/src/commands/extensions/examples/mcp-server + ``` + +2. Install dependencies: + ```bash + npm install + ``` + +This example is typically used by `gemini extensions new`. diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/example.ts b/packages/cli/src/commands/extensions/examples/mcp-server/example.js similarity index 100% rename from packages/cli/src/commands/extensions/examples/mcp-server/example.ts rename to packages/cli/src/commands/extensions/examples/mcp-server/example.js diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/example.test.ts b/packages/cli/src/commands/extensions/examples/mcp-server/example.test.ts deleted file mode 100644 index 5f5660df76..0000000000 --- a/packages/cli/src/commands/extensions/examples/mcp-server/example.test.ts +++ /dev/null @@ -1,135 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; -import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; -import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; -import { z } from 'zod'; - -// Mock the MCP server and transport -const mockRegisterTool = vi.fn(); -const mockRegisterPrompt = vi.fn(); -const mockConnect = vi.fn(); - -vi.mock('@modelcontextprotocol/sdk/server/mcp.js', () => ({ - McpServer: vi.fn().mockImplementation(() => ({ - registerTool: mockRegisterTool, - registerPrompt: mockRegisterPrompt, - connect: mockConnect, - })), -})); - -vi.mock('@modelcontextprotocol/sdk/server/stdio.js', () => ({ - StdioServerTransport: vi.fn(), -})); - -describe('MCP Server Example', () => { - beforeEach(async () => { - // Dynamically import the server setup after mocks are in place - await import('./example.js'); - }); - - afterEach(() => { - vi.clearAllMocks(); - vi.resetModules(); - }); - - it('should create an McpServer with the correct name and version', () => { - expect(McpServer).toHaveBeenCalledWith({ - name: 'prompt-server', - version: '1.0.0', - }); - }); - - it('should register the "fetch_posts" tool', () => { - expect(mockRegisterTool).toHaveBeenCalledWith( - 'fetch_posts', - { - description: 'Fetches a list of posts from a public API.', - inputSchema: z.object({}).shape, - }, - expect.any(Function), - ); - }); - - it('should register the "poem-writer" prompt', () => { - expect(mockRegisterPrompt).toHaveBeenCalledWith( - 'poem-writer', - { - title: 'Poem Writer', - description: 'Write a nice haiku', - argsSchema: expect.any(Object), - }, - expect.any(Function), - ); - }); - - it('should connect the server to an StdioServerTransport', () => { - expect(StdioServerTransport).toHaveBeenCalled(); - expect(mockConnect).toHaveBeenCalledWith(expect.any(StdioServerTransport)); - }); - - describe('fetch_posts tool implementation', () => { - it('should fetch posts and return a formatted response', async () => { - const mockPosts = [ - { id: 1, title: 'Post 1' }, - { id: 2, title: 'Post 2' }, - ]; - global.fetch = vi.fn().mockResolvedValue({ - json: vi.fn().mockResolvedValue(mockPosts), - }); - - const toolFn = mockRegisterTool.mock.calls[0][2]; - const result = await toolFn(); - - expect(global.fetch).toHaveBeenCalledWith( - 'https://jsonplaceholder.typicode.com/posts', - ); - expect(result).toEqual({ - content: [ - { - type: 'text', - text: JSON.stringify({ posts: mockPosts }), - }, - ], - }); - }); - }); - - describe('poem-writer prompt implementation', () => { - it('should generate a prompt with a title', () => { - const promptFn = mockRegisterPrompt.mock.calls[0][2]; - const result = promptFn({ title: 'My Poem' }); - expect(result).toEqual({ - messages: [ - { - role: 'user', - content: { - type: 'text', - text: 'Write a haiku called My Poem. Note that a haiku is 5 syllables followed by 7 syllables followed by 5 syllables ', - }, - }, - ], - }); - }); - - it('should generate a prompt with a title and mood', () => { - const promptFn = mockRegisterPrompt.mock.calls[0][2]; - const result = promptFn({ title: 'My Poem', mood: 'sad' }); - expect(result).toEqual({ - messages: [ - { - role: 'user', - content: { - type: 'text', - text: 'Write a haiku with the mood sad called My Poem. Note that a haiku is 5 syllables followed by 7 syllables followed by 5 syllables ', - }, - }, - ], - }); - }); - }); -}); diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/gemini-extension.json b/packages/cli/src/commands/extensions/examples/mcp-server/gemini-extension.json index 62561dbf8d..25cea93411 100644 --- a/packages/cli/src/commands/extensions/examples/mcp-server/gemini-extension.json +++ b/packages/cli/src/commands/extensions/examples/mcp-server/gemini-extension.json @@ -4,7 +4,7 @@ "mcpServers": { "nodeServer": { "command": "node", - "args": ["${extensionPath}${/}dist${/}example.js"], + "args": ["${extensionPath}${/}example.js"], "cwd": "${extensionPath}" } } diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/package.json b/packages/cli/src/commands/extensions/examples/mcp-server/package.json index 45aa203ef3..ddb2959c38 100644 --- a/packages/cli/src/commands/extensions/examples/mcp-server/package.json +++ b/packages/cli/src/commands/extensions/examples/mcp-server/package.json @@ -4,13 +4,6 @@ "description": "Example MCP Server for Gemini CLI Extension", "type": "module", "main": "example.js", - "scripts": { - "build": "tsc" - }, - "devDependencies": { - "typescript": "~5.4.5", - "@types/node": "^20.11.25" - }, "dependencies": { "@modelcontextprotocol/sdk": "^1.23.0", "zod": "^3.22.4" diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/tsconfig.json b/packages/cli/src/commands/extensions/examples/mcp-server/tsconfig.json deleted file mode 100644 index b94585edce..0000000000 --- a/packages/cli/src/commands/extensions/examples/mcp-server/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2022", - "module": "NodeNext", - "moduleResolution": "NodeNext", - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "outDir": "./dist" - }, - "include": ["example.ts"] -} diff --git a/packages/cli/src/commands/extensions/examples/skills/gemini-extension.json b/packages/cli/src/commands/extensions/examples/skills/gemini-extension.json new file mode 100644 index 0000000000..2674ef9e0f --- /dev/null +++ b/packages/cli/src/commands/extensions/examples/skills/gemini-extension.json @@ -0,0 +1,4 @@ +{ + "name": "skills-example", + "version": "1.0.0" +} diff --git a/packages/cli/src/commands/extensions/examples/skills/skills/greeter/SKILL.md b/packages/cli/src/commands/extensions/examples/skills/skills/greeter/SKILL.md new file mode 100644 index 0000000000..24da110909 --- /dev/null +++ b/packages/cli/src/commands/extensions/examples/skills/skills/greeter/SKILL.md @@ -0,0 +1,7 @@ +--- +name: greeter +description: A friendly greeter skill +--- + +You are a friendly greeter. When the user says "hello" or asks for a greeting, +you should reply with: "Greetings from the skills-example extension! 👋" diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index e361d7ffe0..b06787f0e6 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -13,6 +13,6 @@ "src/**/*.json", "./package.json" ], - "exclude": ["node_modules", "dist"], + "exclude": ["node_modules", "dist", "src/commands/extensions/examples"], "references": [{ "path": "../core" }] } From 8656ce8a27451a906bede9b74ad5a56e9221a9ad Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Mon, 12 Jan 2026 12:23:06 -0500 Subject: [PATCH 126/713] revert the change that was recently added from a fix (#16390) --- packages/core/src/config/config.ts | 3 +-- packages/core/src/config/flashFallback.test.ts | 7 ++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 241de0d04f..4677ef155e 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -951,8 +951,7 @@ export class Config { } activateFallbackMode(model: string): void { - this.setActiveModel(model); - coreEvents.emitModelChanged(model); + this.setModel(model, true); const authType = this.getContentGeneratorConfig()?.authType; if (authType) { logFlashFallback(this, new FlashFallbackEvent(authType)); diff --git a/packages/core/src/config/flashFallback.test.ts b/packages/core/src/config/flashFallback.test.ts index 96adf37655..320d69c565 100644 --- a/packages/core/src/config/flashFallback.test.ts +++ b/packages/core/src/config/flashFallback.test.ts @@ -65,12 +65,9 @@ describe('Flash Model Fallback Configuration', () => { }); describe('activateFallbackMode', () => { - it('should set active model to fallback and log event', () => { + it('should set model to fallback and log event', () => { config.activateFallbackMode(DEFAULT_GEMINI_FLASH_MODEL); - expect(config.getActiveModel()).toBe(DEFAULT_GEMINI_FLASH_MODEL); - // Ensure the persisted model setting is NOT changed (to preserve AUTO behavior) - expect(config.getModel()).toBe(DEFAULT_GEMINI_MODEL); - + expect(config.getModel()).toBe(DEFAULT_GEMINI_FLASH_MODEL); expect(logFlashFallback).toHaveBeenCalledWith( config, expect.any(FlashFallbackEvent), From 8a2e0fac0d8c3499e628ed52d517987163f32541 Mon Sep 17 00:00:00 2001 From: Vedant Mahajan Date: Mon, 12 Jan 2026 23:08:45 +0530 Subject: [PATCH 127/713] Add other hook wrapper methods to hooksystem (#16361) --- packages/core/src/core/client.test.ts | 141 +++++++++++++++----------- packages/core/src/core/client.ts | 30 ++---- packages/core/src/hooks/hookSystem.ts | 24 +++++ 3 files changed, 118 insertions(+), 77 deletions(-) diff --git a/packages/core/src/core/client.test.ts b/packages/core/src/core/client.test.ts index 16f78d40d8..84418c9855 100644 --- a/packages/core/src/core/client.test.ts +++ b/packages/core/src/core/client.test.ts @@ -46,9 +46,8 @@ import type { ResolvedModelConfig, } from '../services/modelConfigService.js'; import { ClearcutLogger } from '../telemetry/clearcut-logger/clearcut-logger.js'; -import { HookSystem } from '../hooks/hookSystem.js'; -import type { DefaultHookOutput } from '../hooks/types.js'; import * as policyCatalog from '../availability/policyCatalog.js'; +import { partToString } from '../utils/partUtils.js'; vi.mock('../services/chatCompressionService.js'); @@ -137,15 +136,22 @@ vi.mock('../telemetry/uiTelemetry.js', () => ({ }, })); vi.mock('../hooks/hookSystem.js'); -vi.mock('./clientHookTriggers.js', () => ({ - fireBeforeAgentHook: vi.fn(), - fireAfterAgentHook: vi.fn().mockResolvedValue({ - decision: 'allow', - continue: false, - suppressOutput: false, - systemMessage: undefined, +const mockHookSystem = { + fireBeforeAgentEvent: vi.fn().mockResolvedValue({ + success: true, + finalOutput: undefined, + allOutputs: [], + errors: [], + totalDuration: 0, }), -})); + fireAfterAgentEvent: vi.fn().mockResolvedValue({ + success: true, + finalOutput: undefined, + allOutputs: [], + errors: [], + totalDuration: 0, + }), +}; /** * Array.fromAsync ponyfill, which will be available in es 2024. @@ -286,9 +292,7 @@ describe('Gemini Client (client.ts)', () => { .fn() .mockReturnValue(createAvailabilityServiceMock()), } as unknown as Config; - mockConfig.getHookSystem = vi - .fn() - .mockReturnValue(new HookSystem(mockConfig)); + mockConfig.getHookSystem = vi.fn().mockReturnValue(mockHookSystem); client = new GeminiClient(mockConfig); await client.initialize(); @@ -2688,9 +2692,6 @@ ${JSON.stringify( const promptId = 'test-prompt-hook-1'; const request = { text: 'Hello Hooks' }; const signal = new AbortController().signal; - const { fireBeforeAgentHook, fireAfterAgentHook } = await import( - './clientHookTriggers.js' - ); mockTurnRunFn.mockImplementation(async function* ( this: MockTurnContext, @@ -2702,11 +2703,10 @@ ${JSON.stringify( const stream = client.sendMessageStream(request, signal, promptId); while (!(await stream.next()).done); - expect(fireBeforeAgentHook).toHaveBeenCalledTimes(1); - expect(fireAfterAgentHook).toHaveBeenCalledTimes(1); - expect(fireAfterAgentHook).toHaveBeenCalledWith( - expect.anything(), - request, + expect(mockHookSystem.fireBeforeAgentEvent).toHaveBeenCalledTimes(1); + expect(mockHookSystem.fireAfterAgentEvent).toHaveBeenCalledTimes(1); + expect(mockHookSystem.fireAfterAgentEvent).toHaveBeenCalledWith( + partToString(request), 'Hook Response', ); @@ -2725,9 +2725,6 @@ ${JSON.stringify( const promptId = 'test-prompt-hook-recursive'; const request = { text: 'Recursion Test' }; const signal = new AbortController().signal; - const { fireBeforeAgentHook, fireAfterAgentHook } = await import( - './clientHookTriggers.js' - ); let callCount = 0; mockTurnRunFn.mockImplementation(async function* ( @@ -2743,15 +2740,14 @@ ${JSON.stringify( while (!(await stream.next()).done); // BeforeAgent should fire ONLY once despite multiple internal turns - expect(fireBeforeAgentHook).toHaveBeenCalledTimes(1); + expect(mockHookSystem.fireBeforeAgentEvent).toHaveBeenCalledTimes(1); // AfterAgent should fire ONLY when the stack unwinds - expect(fireAfterAgentHook).toHaveBeenCalledTimes(1); + expect(mockHookSystem.fireAfterAgentEvent).toHaveBeenCalledTimes(1); // Check cumulative response (separated by newline) - expect(fireAfterAgentHook).toHaveBeenCalledWith( - expect.anything(), - request, + expect(mockHookSystem.fireAfterAgentEvent).toHaveBeenCalledWith( + partToString(request), 'Response 1\nResponse 2', ); @@ -2769,7 +2765,6 @@ ${JSON.stringify( const promptId = 'test-prompt-hook-original-req'; const request = { text: 'Do something' }; const signal = new AbortController().signal; - const { fireAfterAgentHook } = await import('./clientHookTriggers.js'); mockTurnRunFn.mockImplementation(async function* ( this: MockTurnContext, @@ -2781,9 +2776,8 @@ ${JSON.stringify( const stream = client.sendMessageStream(request, signal, promptId); while (!(await stream.next()).done); - expect(fireAfterAgentHook).toHaveBeenCalledWith( - expect.anything(), - request, // Should be 'Do something' + expect(mockHookSystem.fireAfterAgentEvent).toHaveBeenCalledWith( + partToString(request), // Should be 'Do something' expect.stringContaining('Ok'), ); }); @@ -2817,11 +2811,17 @@ ${JSON.stringify( }); it('should stop execution in BeforeAgent when hook returns continue: false', async () => { - const { fireBeforeAgentHook } = await import('./clientHookTriggers.js'); - vi.mocked(fireBeforeAgentHook).mockResolvedValue({ - shouldStopExecution: () => true, - getEffectiveReason: () => 'Stopped by hook', - } as DefaultHookOutput); + mockHookSystem.fireBeforeAgentEvent.mockResolvedValue({ + success: true, + finalOutput: { + shouldStopExecution: () => true, + getEffectiveReason: () => 'Stopped by hook', + systemMessage: undefined, + }, + allOutputs: [], + errors: [], + totalDuration: 0, + }); const mockChat: Partial = { addHistory: vi.fn(), @@ -2850,12 +2850,18 @@ ${JSON.stringify( }); it('should block execution in BeforeAgent when hook returns decision: block', async () => { - const { fireBeforeAgentHook } = await import('./clientHookTriggers.js'); - vi.mocked(fireBeforeAgentHook).mockResolvedValue({ - shouldStopExecution: () => false, - isBlockingDecision: () => true, - getEffectiveReason: () => 'Blocked by hook', - } as DefaultHookOutput); + mockHookSystem.fireBeforeAgentEvent.mockResolvedValue({ + success: true, + finalOutput: { + shouldStopExecution: () => false, + isBlockingDecision: () => true, + getEffectiveReason: () => 'Blocked by hook', + systemMessage: undefined, + }, + allOutputs: [], + errors: [], + totalDuration: 0, + }); const mockChat: Partial = { addHistory: vi.fn(), @@ -2883,11 +2889,17 @@ ${JSON.stringify( }); it('should stop execution in AfterAgent when hook returns continue: false', async () => { - const { fireAfterAgentHook } = await import('./clientHookTriggers.js'); - vi.mocked(fireAfterAgentHook).mockResolvedValue({ - shouldStopExecution: () => true, - getEffectiveReason: () => 'Stopped after agent', - } as DefaultHookOutput); + mockHookSystem.fireAfterAgentEvent.mockResolvedValue({ + success: true, + finalOutput: { + shouldStopExecution: () => true, + getEffectiveReason: () => 'Stopped after agent', + systemMessage: undefined, + }, + allOutputs: [], + errors: [], + totalDuration: 0, + }); mockTurnRunFn.mockImplementation(async function* () { yield { type: GeminiEventType.Content, value: 'Hello' }; @@ -2909,17 +2921,30 @@ ${JSON.stringify( }); it('should yield AgentExecutionBlocked and recurse in AfterAgent when hook returns decision: block', async () => { - const { fireAfterAgentHook } = await import('./clientHookTriggers.js'); - vi.mocked(fireAfterAgentHook) + mockHookSystem.fireAfterAgentEvent .mockResolvedValueOnce({ - shouldStopExecution: () => false, - isBlockingDecision: () => true, - getEffectiveReason: () => 'Please explain', - } as DefaultHookOutput) + success: true, + finalOutput: { + shouldStopExecution: () => false, + isBlockingDecision: () => true, + getEffectiveReason: () => 'Please explain', + systemMessage: undefined, + }, + allOutputs: [], + errors: [], + totalDuration: 0, + }) .mockResolvedValueOnce({ - shouldStopExecution: () => false, - isBlockingDecision: () => false, - } as DefaultHookOutput); + success: true, + finalOutput: { + shouldStopExecution: () => false, + isBlockingDecision: () => false, + systemMessage: undefined, + }, + allOutputs: [], + errors: [], + totalDuration: 0, + }); mockTurnRunFn.mockImplementation(async function* () { yield { type: GeminiEventType.Content, value: 'Response' }; diff --git a/packages/core/src/core/client.ts b/packages/core/src/core/client.ts index 67dae3f927..535bf15ce7 100644 --- a/packages/core/src/core/client.ts +++ b/packages/core/src/core/client.ts @@ -12,7 +12,6 @@ import type { GenerateContentResponse, } from '@google/genai'; import { createUserContent } from '@google/genai'; -import type { MessageBus } from '../confirmation-bus/message-bus.js'; import { getDirectoryContextString, getInitialChatHistory, @@ -40,10 +39,6 @@ import { logContentRetryFailure, logNextSpeakerCheck, } from '../telemetry/loggers.js'; -import { - fireBeforeAgentHook, - fireAfterAgentHook, -} from './clientHookTriggers.js'; import type { DefaultHookOutput } from '../hooks/types.js'; import { ContentRetryFailureEvent, @@ -62,6 +57,7 @@ import { } from '../availability/policyHelpers.js'; import { resolveModel } from '../config/models.js'; import type { RetryAvailabilityContext } from '../utils/retry.js'; +import { partToString } from '../utils/partUtils.js'; const MAX_TURNS = 100; @@ -113,7 +109,6 @@ export class GeminiClient { >(); private async fireBeforeAgentHookSafe( - messageBus: MessageBus, request: PartListUnion, prompt_id: string, ): Promise { @@ -138,7 +133,10 @@ export class GeminiClient { return undefined; } - const hookOutput = await fireBeforeAgentHook(messageBus, request); + const hookResult = await this.config + .getHookSystem() + ?.fireBeforeAgentEvent(partToString(request)); + const hookOutput = hookResult?.finalOutput; hookState.hasFiredBeforeAgent = true; if (hookOutput?.shouldStopExecution()) { @@ -169,7 +167,6 @@ export class GeminiClient { } private async fireAfterAgentHookSafe( - messageBus: MessageBus, currentRequest: PartListUnion, prompt_id: string, turn?: Turn, @@ -190,11 +187,11 @@ export class GeminiClient { '[no response text]'; const finalRequest = hookState.originalRequest || currentRequest; - const hookOutput = await fireAfterAgentHook( - messageBus, - finalRequest, - finalResponseText, - ); + const hookResult = await this.config + .getHookSystem() + ?.fireAfterAgentEvent(partToString(finalRequest), finalResponseText); + const hookOutput = hookResult?.finalOutput; + return hookOutput; } @@ -757,11 +754,7 @@ export class GeminiClient { } if (hooksEnabled && messageBus) { - const hookResult = await this.fireBeforeAgentHookSafe( - messageBus, - request, - prompt_id, - ); + const hookResult = await this.fireBeforeAgentHookSafe(request, prompt_id); if (hookResult) { if ( 'type' in hookResult && @@ -802,7 +795,6 @@ export class GeminiClient { // Fire AfterAgent hook if we have a turn and no pending tools if (hooksEnabled && messageBus) { const hookOutput = await this.fireAfterAgentHookSafe( - messageBus, request, prompt_id, turn, diff --git a/packages/core/src/hooks/hookSystem.ts b/packages/core/src/hooks/hookSystem.ts index 98f7baf817..547b44a923 100644 --- a/packages/core/src/hooks/hookSystem.ts +++ b/packages/core/src/hooks/hookSystem.ts @@ -117,4 +117,28 @@ export class HookSystem { } return this.hookEventHandler.firePreCompressEvent(trigger); } + + async fireBeforeAgentEvent( + prompt: string, + ): Promise { + if (!this.config.getEnableHooks()) { + return undefined; + } + return this.hookEventHandler.fireBeforeAgentEvent(prompt); + } + + async fireAfterAgentEvent( + prompt: string, + response: string, + stopHookActive: boolean = false, + ): Promise { + if (!this.config.getEnableHooks()) { + return undefined; + } + return this.hookEventHandler.fireAfterAgentEvent( + prompt, + response, + stopHookActive, + ); + } } From 15891721ad09f030cb761d66d9e0772ae53f9332 Mon Sep 17 00:00:00 2001 From: Adib234 <30782825+Adib234@users.noreply.github.com> Date: Mon, 12 Jan 2026 12:42:14 -0500 Subject: [PATCH 128/713] feat: introduce useRewindLogic hook for conversation history navigation (#15716) --- packages/cli/src/ui/hooks/useRewind.test.ts | 134 ++++++++++++++++++++ packages/cli/src/ui/hooks/useRewind.ts | 54 ++++++++ 2 files changed, 188 insertions(+) create mode 100644 packages/cli/src/ui/hooks/useRewind.test.ts create mode 100644 packages/cli/src/ui/hooks/useRewind.ts diff --git a/packages/cli/src/ui/hooks/useRewind.test.ts b/packages/cli/src/ui/hooks/useRewind.test.ts new file mode 100644 index 0000000000..7694dbd7a7 --- /dev/null +++ b/packages/cli/src/ui/hooks/useRewind.test.ts @@ -0,0 +1,134 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { act } from 'react'; +import { renderHook } from '../../test-utils/render.js'; +import { useRewind } from './useRewind.js'; +import * as rewindFileOps from '../utils/rewindFileOps.js'; +import type { FileChangeStats } from '../utils/rewindFileOps.js'; +import type { + ConversationRecord, + MessageRecord, +} from '@google/gemini-cli-core'; + +// Mock the dependency +vi.mock('../utils/rewindFileOps.js', () => ({ + calculateTurnStats: vi.fn(), + calculateRewindImpact: vi.fn(), +})); + +describe('useRewindLogic', () => { + const mockUserMessage: MessageRecord = { + id: 'msg-1', + type: 'user', + content: 'Hello', + timestamp: new Date(1000).toISOString(), + }; + + const mockModelMessage: MessageRecord = { + id: 'msg-2', + type: 'gemini', + content: 'Hi there', + timestamp: new Date(1001).toISOString(), + }; + + const mockConversation: ConversationRecord = { + sessionId: 'conv-1', + projectHash: 'hash-1', + startTime: new Date(1000).toISOString(), + lastUpdated: new Date(1001).toISOString(), + messages: [mockUserMessage, mockModelMessage], + }; + + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('should initialize with no selection', () => { + const { result } = renderHook(() => useRewind(mockConversation)); + + expect(result.current.selectedMessageId).toBeNull(); + expect(result.current.confirmationStats).toBeNull(); + }); + + it('should update state when a message is selected', () => { + const mockStats: FileChangeStats = { + fileCount: 1, + addedLines: 5, + removedLines: 0, + }; + vi.mocked(rewindFileOps.calculateRewindImpact).mockReturnValue(mockStats); + + const { result } = renderHook(() => useRewind(mockConversation)); + + act(() => { + result.current.selectMessage('msg-1'); + }); + + expect(result.current.selectedMessageId).toBe('msg-1'); + expect(result.current.confirmationStats).toEqual(mockStats); + expect(rewindFileOps.calculateRewindImpact).toHaveBeenCalledWith( + mockConversation, + mockUserMessage, + ); + }); + + it('should not update state if selected message is not found', () => { + const { result } = renderHook(() => useRewind(mockConversation)); + + act(() => { + result.current.selectMessage('non-existent-id'); + }); + + expect(result.current.selectedMessageId).toBeNull(); + expect(result.current.confirmationStats).toBeNull(); + }); + + it('should clear selection correctly', () => { + const mockStats: FileChangeStats = { + fileCount: 1, + addedLines: 5, + removedLines: 0, + }; + vi.mocked(rewindFileOps.calculateRewindImpact).mockReturnValue(mockStats); + + const { result } = renderHook(() => useRewind(mockConversation)); + + // Select first + act(() => { + result.current.selectMessage('msg-1'); + }); + expect(result.current.selectedMessageId).toBe('msg-1'); + + // Then clear + act(() => { + result.current.clearSelection(); + }); + + expect(result.current.selectedMessageId).toBeNull(); + expect(result.current.confirmationStats).toBeNull(); + }); + + it('should proxy getStats call to utility function', () => { + const mockStats: FileChangeStats = { + fileCount: 2, + addedLines: 10, + removedLines: 2, + }; + vi.mocked(rewindFileOps.calculateTurnStats).mockReturnValue(mockStats); + + const { result } = renderHook(() => useRewind(mockConversation)); + + const stats = result.current.getStats(mockUserMessage); + + expect(stats).toEqual(mockStats); + expect(rewindFileOps.calculateTurnStats).toHaveBeenCalledWith( + mockConversation, + mockUserMessage, + ); + }); +}); diff --git a/packages/cli/src/ui/hooks/useRewind.ts b/packages/cli/src/ui/hooks/useRewind.ts new file mode 100644 index 0000000000..66074be694 --- /dev/null +++ b/packages/cli/src/ui/hooks/useRewind.ts @@ -0,0 +1,54 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { useState, useCallback } from 'react'; +import type { + ConversationRecord, + MessageRecord, +} from '@google/gemini-cli-core'; +import { + calculateTurnStats, + calculateRewindImpact, + type FileChangeStats, +} from '../utils/rewindFileOps.js'; + +export function useRewind(conversation: ConversationRecord) { + const [selectedMessageId, setSelectedMessageId] = useState( + null, + ); + const [confirmationStats, setConfirmationStats] = + useState(null); + + const getStats = useCallback( + (userMessage: MessageRecord) => + calculateTurnStats(conversation, userMessage), + [conversation], + ); + + const selectMessage = useCallback( + (messageId: string) => { + const msg = conversation.messages.find((m) => m.id === messageId); + if (msg) { + setSelectedMessageId(messageId); + setConfirmationStats(calculateRewindImpact(conversation, msg)); + } + }, + [conversation], + ); + + const clearSelection = useCallback(() => { + setSelectedMessageId(null); + setConfirmationStats(null); + }, []); + + return { + selectedMessageId, + getStats, + confirmationStats, + selectMessage, + clearSelection, + }; +} From 0167392f2268473e348f54af541a4d6d6ed50f64 Mon Sep 17 00:00:00 2001 From: Wang Lecheng Date: Tue, 13 Jan 2026 02:17:15 +0800 Subject: [PATCH 129/713] docs: Fix formatting issue in memport documentation (#14774) --- docs/core/memport.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/core/memport.md b/docs/core/memport.md index 9248f68dee..1460404792 100644 --- a/docs/core/memport.md +++ b/docs/core/memport.md @@ -83,7 +83,9 @@ The processor automatically detects and prevents circular imports: # file-a.md @./file-b.md +``` +```markdown # file-b.md @./file-a.md From 64cde8d439501f9b8448acdfa5baa9b6963bdee7 Mon Sep 17 00:00:00 2001 From: Allen Hutchison Date: Mon, 12 Jan 2026 11:23:32 -0800 Subject: [PATCH 130/713] fix(policy): enhance shell command safety and parsing (#15034) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com> --- packages/core/src/policy/policy-engine.ts | 105 ++++- packages/core/src/policy/shell-safety.test.ts | 446 +++++++++++++++++- packages/core/src/policy/types.ts | 5 + 3 files changed, 526 insertions(+), 30 deletions(-) diff --git a/packages/core/src/policy/policy-engine.ts b/packages/core/src/policy/policy-engine.ts index 13a3ef5225..f90b905938 100644 --- a/packages/core/src/policy/policy-engine.ts +++ b/packages/core/src/policy/policy-engine.ts @@ -151,9 +151,13 @@ export class PolicyEngine { serverName: string | undefined, dir_path: string | undefined, allowRedirection?: boolean, - ): Promise { + rule?: PolicyRule, + ): Promise<{ decision: PolicyDecision; rule?: PolicyRule }> { if (!command) { - return this.applyNonInteractiveMode(ruleDecision); + return { + decision: this.applyNonInteractiveMode(ruleDecision), + rule, + }; } await initializeShellParsers(); @@ -163,7 +167,12 @@ export class PolicyEngine { debugLogger.debug( `[PolicyEngine.check] Command parsing failed for: ${command}. Falling back to ASK_USER.`, ); - return this.applyNonInteractiveMode(PolicyDecision.ASK_USER); + // Parsing logic failed, we can't trust it. Force ASK_USER (or DENY). + // We don't blame a specific rule here, unless the input rule was stricter. + return { + decision: this.applyNonInteractiveMode(PolicyDecision.ASK_USER), + rule: undefined, + }; } // If there are multiple parts, or if we just want to validate the single part against DENY rules @@ -173,14 +182,16 @@ export class PolicyEngine { ); if (ruleDecision === PolicyDecision.DENY) { - return PolicyDecision.DENY; + return { decision: PolicyDecision.DENY, rule }; } // Start optimistically. If all parts are ALLOW, the whole is ALLOW. // We will downgrade if any part is ASK_USER or DENY. let aggregateDecision = PolicyDecision.ALLOW; + let responsibleRule: PolicyRule | undefined; - for (const subCmd of subCommands) { + for (const rawSubCmd of subCommands) { + const subCmd = rawSubCmd.trim(); // Prevent infinite recursion for the root command if (subCmd === command) { if (!allowRedirection && hasRedirection(subCmd)) { @@ -190,17 +201,16 @@ export class PolicyEngine { // Redirection always downgrades ALLOW to ASK_USER if (aggregateDecision === PolicyDecision.ALLOW) { aggregateDecision = PolicyDecision.ASK_USER; + responsibleRule = undefined; // Inherent policy } } else { - // If the command is atomic (cannot be split further) and didn't - // trigger infinite recursion checks, we must respect the decision - // of the rule that triggered this check. If the rule was ASK_USER - // (e.g. wildcard), we must downgrade. + // Atomic command matching the rule. if ( ruleDecision === PolicyDecision.ASK_USER && aggregateDecision === PolicyDecision.ALLOW ) { aggregateDecision = PolicyDecision.ASK_USER; + responsibleRule = rule; } } continue; @@ -216,13 +226,17 @@ export class PolicyEngine { // If any part is DENIED, the whole command is DENIED if (subDecision === PolicyDecision.DENY) { - return PolicyDecision.DENY; + return { + decision: PolicyDecision.DENY, + rule: subResult.rule, + }; } // If any part requires ASK_USER, the whole command requires ASK_USER if (subDecision === PolicyDecision.ASK_USER) { - if (aggregateDecision === PolicyDecision.ALLOW) { - aggregateDecision = PolicyDecision.ASK_USER; + aggregateDecision = PolicyDecision.ASK_USER; + if (!responsibleRule) { + responsibleRule = subResult.rule; } } @@ -237,13 +251,22 @@ export class PolicyEngine { ); if (aggregateDecision === PolicyDecision.ALLOW) { aggregateDecision = PolicyDecision.ASK_USER; + responsibleRule = undefined; } } } - return this.applyNonInteractiveMode(aggregateDecision); + return { + decision: this.applyNonInteractiveMode(aggregateDecision), + // If we stayed at ALLOW, we return the original rule (if any). + // If we downgraded, we return the responsible rule (or undefined if implicit). + rule: aggregateDecision === ruleDecision ? rule : responsibleRule, + }; } - return this.applyNonInteractiveMode(ruleDecision); + return { + decision: this.applyNonInteractiveMode(ruleDecision), + rule, + }; } /** @@ -271,6 +294,18 @@ export class PolicyEngine { `[PolicyEngine.check] toolCall.name: ${toolCall.name}, stringifiedArgs: ${stringifiedArgs}`, ); + // Check for shell commands upfront to handle splitting + let isShellCommand = false; + let command: string | undefined; + let shellDirPath: string | undefined; + + if (toolCall.name && SHELL_TOOL_NAMES.includes(toolCall.name)) { + isShellCommand = true; + const args = toolCall.args as { command?: string; dir_path?: string }; + command = args?.command; + shellDirPath = args?.dir_path; + } + // Find the first matching rule (already sorted by priority) let matchedRule: PolicyRule | undefined; let decision: PolicyDecision | undefined; @@ -289,21 +324,31 @@ export class PolicyEngine { `[PolicyEngine.check] MATCHED rule: toolName=${rule.toolName}, decision=${rule.decision}, priority=${rule.priority}, argsPattern=${rule.argsPattern?.source || 'none'}`, ); - if (toolCall.name && SHELL_TOOL_NAMES.includes(toolCall.name)) { - const args = toolCall.args as { command?: string; dir_path?: string }; - decision = await this.checkShellCommand( - toolCall.name, - args?.command, + if (isShellCommand) { + const shellResult = await this.checkShellCommand( + toolCall.name!, + command, rule.decision, serverName, - args?.dir_path, + shellDirPath, rule.allowRedirection, + rule, ); + decision = shellResult.decision; + if (shellResult.rule) { + matchedRule = shellResult.rule; + break; + } + // If no rule returned (e.g. downgraded to default ASK_USER due to redirection), + // we might still want to blame the matched rule? + // No, test says we should return undefined rule if implicit. + matchedRule = shellResult.rule; + break; } else { decision = this.applyNonInteractiveMode(rule.decision); + matchedRule = rule; + break; } - matchedRule = rule; - break; } } @@ -313,6 +358,22 @@ export class PolicyEngine { `[PolicyEngine.check] NO MATCH - using default decision: ${this.defaultDecision}`, ); decision = this.applyNonInteractiveMode(this.defaultDecision); + + // If it's a shell command and we fell back to default, we MUST still verify subcommands! + // This is critical for security: "git commit && git push" where "git push" is DENY but "git commit" has no rule. + if (isShellCommand && decision !== PolicyDecision.DENY) { + const shellResult = await this.checkShellCommand( + toolCall.name!, + command, + decision, // default decision + serverName, + shellDirPath, + false, // no rule, so no allowRedirection + undefined, // no rule + ); + decision = shellResult.decision; + matchedRule = shellResult.rule; + } } // If decision is not DENY, run safety checkers diff --git a/packages/core/src/policy/shell-safety.test.ts b/packages/core/src/policy/shell-safety.test.ts index bcc9f562d9..340264485e 100644 --- a/packages/core/src/policy/shell-safety.test.ts +++ b/packages/core/src/policy/shell-safety.test.ts @@ -4,29 +4,107 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { describe, it, expect, beforeEach } from 'vitest'; +import { describe, it, expect, beforeEach, vi } from 'vitest'; + +// Mock shell-utils to avoid relying on tree-sitter WASM which is flaky in CI on Windows +vi.mock('../utils/shell-utils.js', async (importOriginal) => { + const actual = + await importOriginal(); + + // Static map of test commands to their expected subcommands + // This mirrors what the real parser would output for these specific strings + const commandMap: Record = { + 'git log': ['git log'], + 'git log --oneline': ['git log --oneline'], + 'git logout': ['git logout'], + 'git log && rm -rf /': ['git log', 'rm -rf /'], + 'git log; rm -rf /': ['git log', 'rm -rf /'], + 'git log || rm -rf /': ['git log', 'rm -rf /'], + 'git log &&& rm -rf /': [], // Simulates parse failure + 'echo $(rm -rf /)': ['echo $(rm -rf /)', 'rm -rf /'], + 'echo $(git log)': ['echo $(git log)', 'git log'], + 'echo `rm -rf /`': ['echo `rm -rf /`', 'rm -rf /'], + 'diff <(git log) <(rm -rf /)': [ + 'diff <(git log) <(rm -rf /)', + 'git log', + 'rm -rf /', + ], + 'tee >(rm -rf /)': ['tee >(rm -rf /)', 'rm -rf /'], + 'git log | rm -rf /': ['git log', 'rm -rf /'], + 'git log --format=$(rm -rf /)': [ + 'git log --format=$(rm -rf /)', + 'rm -rf /', + ], + 'git log && echo $(git log | rm -rf /)': [ + 'git log', + 'echo $(git log | rm -rf /)', + 'git log', + 'rm -rf /', + ], + 'git log && echo $(git log)': ['git log', 'echo $(git log)', 'git log'], + 'git log > /tmp/test': ['git log > /tmp/test'], + 'git log @(Get-Process)': [], // Simulates parse failure (Bash parser vs PowerShell syntax) + 'git commit -m "msg" && git push': ['git commit -m "msg"', 'git push'], + 'git status && unknown_command': ['git status', 'unknown_command'], + 'unknown_command_1 && another_unknown_command': [ + 'unknown_command_1', + 'another_unknown_command', + ], + 'known_ask_command_1 && known_ask_command_2': [ + 'known_ask_command_1', + 'known_ask_command_2', + ], + }; + + return { + ...actual, + initializeShellParsers: vi.fn(), + splitCommands: (command: string) => { + if (Object.prototype.hasOwnProperty.call(commandMap, command)) { + return commandMap[command]; + } + const known = commandMap[command]; + if (known) return known; + // Default fallback for unmatched simple cases in development, but explicit map is better + return [command]; + }, + hasRedirection: (command: string) => + // Simple regex check sufficient for testing the policy engine's handling of the *result* of hasRedirection + /[><]/.test(command), + }; +}); + import { PolicyEngine } from './policy-engine.js'; import { PolicyDecision, ApprovalMode } from './types.js'; import type { FunctionCall } from '@google/genai'; +import { buildArgsPatterns } from './utils.js'; describe('Shell Safety Policy', () => { let policyEngine: PolicyEngine; - beforeEach(() => { - policyEngine = new PolicyEngine({ + // Helper to create a policy engine with a simple command prefix rule + function createPolicyEngineWithPrefix(prefix: string) { + const argsPatterns = buildArgsPatterns(undefined, prefix, undefined); + // Since buildArgsPatterns returns array of patterns (strings), we pick the first one + // and compile it. + const argsPattern = new RegExp(argsPatterns[0]!); + + return new PolicyEngine({ rules: [ { toolName: 'run_shell_command', - // Mimic the regex generated by toml-loader for commandPrefix = ["git log"] - // Regex: "command":"git log(?:[\s"]|$) - argsPattern: /"command":"git log(?:[\s"]|$)/, + argsPattern, decision: PolicyDecision.ALLOW, - priority: 1.01, // Higher priority than default + priority: 1.01, }, ], defaultDecision: PolicyDecision.ASK_USER, approvalMode: ApprovalMode.DEFAULT, }); + } + + beforeEach(() => { + policyEngine = createPolicyEngineWithPrefix('git log'); }); it('SHOULD match "git log" exactly', async () => { @@ -71,6 +149,25 @@ describe('Shell Safety Policy', () => { const result = await policyEngine.check(toolCall, undefined); expect(result.decision).toBe(PolicyDecision.ASK_USER); }); + + it('SHOULD NOT allow "git log; rm -rf /" (semicolon separator)', async () => { + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'git log; rm -rf /' }, + }; + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + }); + + it('SHOULD NOT allow "git log || rm -rf /" (OR separator)', async () => { + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'git log || rm -rf /' }, + }; + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + }); + it('SHOULD NOT allow "git log &&& rm -rf /" when prefix is "git log" (parse failure)', async () => { const toolCall: FunctionCall = { name: 'run_shell_command', @@ -78,8 +175,341 @@ describe('Shell Safety Policy', () => { }; // Desired behavior: Should fail safe (ASK_USER or DENY) because parsing failed. - // If we let it pass as "single command" that matches prefix, it's dangerous. const result = await policyEngine.check(toolCall, undefined); expect(result.decision).toBe(PolicyDecision.ASK_USER); }); + + it('SHOULD NOT allow command substitution $(rm -rf /)', async () => { + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'echo $(rm -rf /)' }, + }; + // `splitCommands` recursively finds nested commands (e.g., `rm` inside `echo $()`). + // The policy engine requires ALL extracted commands to be allowed. + // Since `rm` does not match the allowed prefix, this should result in ASK_USER. + const echoPolicy = createPolicyEngineWithPrefix('echo'); + const result = await echoPolicy.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + }); + + it('SHOULD allow command substitution if inner command is ALSO allowed', async () => { + // Both `echo` and `git` allowed. + const argsPatternsEcho = buildArgsPatterns(undefined, 'echo', undefined); + const argsPatternsGit = buildArgsPatterns(undefined, 'git', undefined); // Allow all git + + const policyEngineWithBoth = new PolicyEngine({ + rules: [ + { + toolName: 'run_shell_command', + argsPattern: new RegExp(argsPatternsEcho[0]!), + decision: PolicyDecision.ALLOW, + priority: 2, + }, + { + toolName: 'run_shell_command', + argsPattern: new RegExp(argsPatternsGit[0]!), + decision: PolicyDecision.ALLOW, + priority: 2, + }, + ], + defaultDecision: PolicyDecision.ASK_USER, + }); + + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'echo $(git log)' }, + }; + + const result = await policyEngineWithBoth.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ALLOW); + }); + it('SHOULD NOT allow command substitution with backticks `rm -rf /`', async () => { + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'echo `rm -rf /`' }, + }; + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + }); + + it('SHOULD NOT allow process substitution <(rm -rf /)', async () => { + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'diff <(git log) <(rm -rf /)' }, + }; + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + }); + + it('SHOULD NOT allow process substitution >(rm -rf /)', async () => { + // Note: >(...) is output substitution, but syntax is similar. + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'tee >(rm -rf /)' }, + }; + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + }); + + it('SHOULD NOT allow piped commands "git log | rm -rf /"', async () => { + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'git log | rm -rf /' }, + }; + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + }); + + it('SHOULD NOT allow argument injection via --arg=$(rm -rf /)', async () => { + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'git log --format=$(rm -rf /)' }, + }; + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + }); + + it('SHOULD NOT allow complex nested commands "git log && echo $(git log | rm -rf /)"', async () => { + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'git log && echo $(git log | rm -rf /)' }, + }; + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + }); + + it('SHOULD allow complex allowed commands "git log && echo $(git log)"', async () => { + // Both `echo` and `git` allowed. + const argsPatternsEcho = buildArgsPatterns(undefined, 'echo', undefined); + const argsPatternsGit = buildArgsPatterns(undefined, 'git', undefined); + + const policyEngineWithBoth = new PolicyEngine({ + rules: [ + { + toolName: 'run_shell_command', + argsPattern: new RegExp(argsPatternsEcho[0]!), + decision: PolicyDecision.ALLOW, + priority: 2, + }, + { + toolName: 'run_shell_command', + // Matches "git" at start of *subcommand* + argsPattern: new RegExp(argsPatternsGit[0]!), + decision: PolicyDecision.ALLOW, + priority: 2, + }, + ], + defaultDecision: PolicyDecision.ASK_USER, + }); + + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'git log && echo $(git log)' }, + }; + + const result = await policyEngineWithBoth.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ALLOW); + }); + + it('SHOULD NOT allow generic redirection > /tmp/test', async () => { + // Current logic downgrades ALLOW to ASK_USER for redirections if redirection is not explicitly allowed. + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'git log > /tmp/test' }, + }; + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + }); + + it('SHOULD allow generic redirection > /tmp/test if allowRedirection is true', async () => { + // If PolicyRule has allowRedirection: true, it should stay ALLOW + const argsPatternsGitLog = buildArgsPatterns( + undefined, + 'git log', + undefined, + ); + const policyWithRedirection = new PolicyEngine({ + rules: [ + { + toolName: 'run_shell_command', + argsPattern: new RegExp(argsPatternsGitLog[0]!), + decision: PolicyDecision.ALLOW, + priority: 2, + allowRedirection: true, + }, + ], + defaultDecision: PolicyDecision.ASK_USER, + }); + + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'git log > /tmp/test' }, + }; + const result = await policyWithRedirection.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ALLOW); + }); + + it('SHOULD NOT allow PowerShell @(...) usage if it implies code execution', async () => { + // Bash parser fails on PowerShell syntax @(...) (returns empty subcommands). + // The policy engine correctly identifies this as unparseable and falls back to ASK_USER. + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'git log @(Get-Process)' }, + }; + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + }); + + it('SHOULD match DENY rule even if nested/chained with unknown command', async () => { + // Scenario: + // git commit -m "..." (Unknown/No Rule -> ASK_USER) + // git push (DENY -> DENY) + // Overall should be DENY. + const argsPatternsPush = buildArgsPatterns( + undefined, + 'git push', + undefined, + ); + + const denyPushPolicy = new PolicyEngine({ + rules: [ + { + toolName: 'run_shell_command', + argsPattern: new RegExp(argsPatternsPush[0]!), + decision: PolicyDecision.DENY, + priority: 2, + }, + ], + defaultDecision: PolicyDecision.ASK_USER, + }); + + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'git commit -m "msg" && git push' }, + }; + + const result = await denyPushPolicy.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.DENY); + }); + + it('SHOULD aggregate ALLOW + ASK_USER to ASK_USER and blame the ASK_USER part', async () => { + // Scenario: + // `git status` (ALLOW) && `unknown_command` (ASK_USER by default) + // Expected: ASK_USER, and the matched rule should be related to the unknown_command + const argsPatternsGitStatus = buildArgsPatterns( + undefined, + 'git status', + undefined, + ); + + const policyEngine = new PolicyEngine({ + rules: [ + { + toolName: 'run_shell_command', + argsPattern: new RegExp(argsPatternsGitStatus[0]!), + decision: PolicyDecision.ALLOW, + priority: 2, + name: 'allow_git_status_rule', // Give a name to easily identify + }, + ], + defaultDecision: PolicyDecision.ASK_USER, + }); + + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'git status && unknown_command' }, + }; + + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + // Expect the matched rule to be null/undefined since it's the default decision for 'unknown_command' + // or the rule that led to the ASK_USER decision. In this case, it should be the rule for 'unknown_command', which is the default decision. + // The policy engine's `matchedRule` will be the rule that caused the final decision. + // If it's a default ASK_USER, then `result.rule` should be undefined. + expect(result.rule).toBeUndefined(); + }); + + it('SHOULD aggregate ASK_USER (default) + ASK_USER (rule) to ASK_USER and blame the specific ASK_USER rule', async () => { + // Scenario: + // `unknown_command_1` (ASK_USER by default) && `another_unknown_command` (ASK_USER by explicit rule) + // Expected: ASK_USER, and the matched rule should be the explicit ASK_USER rule + const argsPatternsAnotherUnknown = buildArgsPatterns( + undefined, + 'another_unknown_command', + undefined, + ); + + const policyEngine = new PolicyEngine({ + rules: [ + { + toolName: 'run_shell_command', + argsPattern: new RegExp(argsPatternsAnotherUnknown[0]!), + decision: PolicyDecision.ASK_USER, + priority: 2, + name: 'ask_another_unknown_command_rule', + }, + ], + defaultDecision: PolicyDecision.ASK_USER, + }); + + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'unknown_command_1 && another_unknown_command' }, + }; + + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + // The first command triggers default ASK_USER (undefined rule). + // The second triggers explicit ASK_USER rule. + // We attribute to the first cause => undefined. + expect(result.rule).toBeUndefined(); + }); + + it('SHOULD aggregate ASK_USER (rule) + ASK_USER (rule) to ASK_USER and blame the first specific ASK_USER rule in subcommands', async () => { + // Scenario: + // `known_ask_command_1` (ASK_USER by explicit rule 1) && `known_ask_command_2` (ASK_USER by explicit rule 2) + // Expected: ASK_USER, and the matched rule should be explicit ASK_USER rule 1. + // The current implementation prioritizes the rule that changes the decision to ASK_USER, if any. + // If multiple rules lead to ASK_USER, it takes the first one. + const argsPatternsAsk1 = buildArgsPatterns( + undefined, + 'known_ask_command_1', + undefined, + ); + const argsPatternsAsk2 = buildArgsPatterns( + undefined, + 'known_ask_command_2', + undefined, + ); + + const policyEngine = new PolicyEngine({ + rules: [ + { + toolName: 'run_shell_command', + argsPattern: new RegExp(argsPatternsAsk1[0]!), + decision: PolicyDecision.ASK_USER, + priority: 2, + name: 'ask_rule_1', + }, + { + toolName: 'run_shell_command', + argsPattern: new RegExp(argsPatternsAsk2[0]!), + decision: PolicyDecision.ASK_USER, + priority: 2, + name: 'ask_rule_2', + }, + ], + defaultDecision: PolicyDecision.ALLOW, // Set default to ALLOW to ensure rules are hit + }); + + const toolCall: FunctionCall = { + name: 'run_shell_command', + args: { command: 'known_ask_command_1 && known_ask_command_2' }, + }; + + const result = await policyEngine.check(toolCall, undefined); + expect(result.decision).toBe(PolicyDecision.ASK_USER); + // Expect the rule that first caused ASK_USER to be blamed + expect(result.rule?.name).toBe('ask_rule_1'); + }); }); diff --git a/packages/core/src/policy/types.ts b/packages/core/src/policy/types.ts index 1d61ec84c5..c2d2802f1e 100644 --- a/packages/core/src/policy/types.ts +++ b/packages/core/src/policy/types.ts @@ -95,6 +95,11 @@ export type SafetyCheckerConfig = | InProcessCheckerConfig; export interface PolicyRule { + /** + * A unique name for the policy rule, useful for identification and debugging. + */ + name?: string; + /** * The name of the tool this rule applies to. * If undefined, the rule applies to all tools. From 3b678a4da0fffa6bafc0e570d5578cb99afc2c45 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 12 Jan 2026 11:31:34 -0800 Subject: [PATCH 131/713] fix(core): avoid 'activate_skill' re-registration warning (#16398) --- packages/core/src/config/config.test.ts | 2 +- packages/core/src/config/config.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index 2ccbb4c546..384e97cbb2 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -2029,7 +2029,7 @@ describe('Config JIT Initialization', () => { expect(mockOnReload).toHaveBeenCalled(); expect(skillManager.setDisabledSkills).toHaveBeenCalledWith(['skill2']); expect(toolRegistry.registerTool).toHaveBeenCalled(); - expect(toolRegistry.unregisterTool).not.toHaveBeenCalledWith( + expect(toolRegistry.unregisterTool).toHaveBeenCalledWith( ACTIVATE_SKILL_TOOL_NAME, ); }); diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 4677ef155e..91d16b2b70 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -761,6 +761,7 @@ export class Config { // Re-register ActivateSkillTool to update its schema with the discovered enabled skill enums if (this.getSkillManager().getSkills().length > 0) { + this.getToolRegistry().unregisterTool(ActivateSkillTool.Name); this.getToolRegistry().registerTool( new ActivateSkillTool(this, this.messageBus), ); @@ -1568,6 +1569,7 @@ export class Config { // Re-register ActivateSkillTool to update its schema with the newly discovered skills if (this.getSkillManager().getSkills().length > 0) { + this.getToolRegistry().unregisterTool(ActivateSkillTool.Name); this.getToolRegistry().registerTool( new ActivateSkillTool(this, this.messageBus), ); From 2306e60be455c622719009b93105034cb50755b6 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Mon, 12 Jan 2026 14:49:20 -0500 Subject: [PATCH 132/713] perf(workflows): optimize PR triage script for faster execution (#16355) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .github/scripts/pr-triage.sh | 249 +++++++++--------- .../workflows/gemini-scheduled-pr-triage.yml | 4 + 2 files changed, 132 insertions(+), 121 deletions(-) diff --git a/.github/scripts/pr-triage.sh b/.github/scripts/pr-triage.sh index e5f49d0c2a..45dfcf7a3c 100755 --- a/.github/scripts/pr-triage.sh +++ b/.github/scripts/pr-triage.sh @@ -4,163 +4,170 @@ set -euo pipefail # Initialize a comma-separated string to hold PR numbers that need a comment PRS_NEEDING_COMMENT="" -# Function to process a single PR -process_pr() { - if [[ -z "${GITHUB_REPOSITORY:-}" ]]; then - echo "‼️ Missing \$GITHUB_REPOSITORY - this must be run from GitHub Actions" - return 1 +# Global cache for issue labels (compatible with Bash 3.2) +# Stores "ISSUE_NUM:LABELS" pairs separated by spaces +ISSUE_LABELS_CACHE_FLAT="" + +# Function to get area and priority labels from an issue (with caching) +get_issue_labels() { + local ISSUE_NUM=$1 + if [[ -z "${ISSUE_NUM}" || "${ISSUE_NUM}" == "null" || "${ISSUE_NUM}" == "" ]]; then + return fi - if [[ -z "${GITHUB_OUTPUT:-}" ]]; then - echo "‼️ Missing \$GITHUB_OUTPUT - this must be run from GitHub Actions" - return 1 + # Check cache + case " ${ISSUE_LABELS_CACHE_FLAT} " in + *" ${ISSUE_NUM}:"*) + local suffix="${ISSUE_LABELS_CACHE_FLAT#* ${ISSUE_NUM}:}" + echo "${suffix%% *}" + return + ;; + esac + + echo " 📥 Fetching area and priority labels from issue #${ISSUE_NUM}" >&2 + local gh_output + if ! gh_output=$(gh issue view "${ISSUE_NUM}" --repo "${GITHUB_REPOSITORY}" --json labels -q '.labels[].name' 2>/dev/null); then + echo " ⚠️ Could not fetch issue #${ISSUE_NUM}" >&2 + ISSUE_LABELS_CACHE_FLAT="${ISSUE_LABELS_CACHE_FLAT} ${ISSUE_NUM}:" + return fi + local labels + labels=$(echo "${gh_output}" | grep -E "^(area|priority)/" | tr '\n' ',' | sed 's/,$//' || echo "") + + # Save to flat cache + ISSUE_LABELS_CACHE_FLAT="${ISSUE_LABELS_CACHE_FLAT} ${ISSUE_NUM}:${labels}" + echo "$labels" +} + +# Function to process a single PR with pre-fetched data +process_pr_optimized() { local PR_NUMBER=$1 + local IS_DRAFT=$2 + local ISSUE_NUMBER=$3 + local CURRENT_LABELS=$4 # Comma-separated labels + echo "🔄 Processing PR #${PR_NUMBER}" - # Get PR details: closing issue, draft status, body and labels - local PR_DATA - if ! PR_DATA=$(gh pr view "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json closingIssuesReferences,isDraft,body,labels 2>/dev/null); then - echo " ⚠️ Could not fetch data for PR #${PR_NUMBER}" - return 0 - fi + local LABELS_TO_ADD="" + local LABELS_TO_REMOVE="" - local ISSUE_NUMBER - ISSUE_NUMBER=$(echo "${PR_DATA}" | jq -r '.closingIssuesReferences[0].number // empty') - - # If no closing issue found, check body for references (e.g. #123) - if [[ -z "${ISSUE_NUMBER}" ]]; then - local REFERENCED_ISSUE - # Search for # followed by digits, not preceded by alphanumeric chars - REFERENCED_ISSUE=$(echo "${PR_DATA}" | jq -r '.body // empty' | grep -oE '(^|[^a-zA-Z0-9])#[0-9]+([^a-zA-Z0-9]|$)' | head -n 1 | grep -oE '[0-9]+' || echo "") - if [[ -n "${REFERENCED_ISSUE}" ]]; then - ISSUE_NUMBER="${REFERENCED_ISSUE}" - echo "🔗 Found referenced issue #${ISSUE_NUMBER} in PR body" - fi - fi - - local IS_DRAFT - IS_DRAFT=$(echo "${PR_DATA}" | jq -r '.isDraft') - - if [[ -z "${ISSUE_NUMBER}" ]]; then + if [[ -z "${ISSUE_NUMBER}" || "${ISSUE_NUMBER}" == "null" || "${ISSUE_NUMBER}" == "" ]]; then if [[ "${IS_DRAFT}" == "true" ]]; then - echo "📝 PR #${PR_NUMBER} is a draft and has no linked issue, skipping status/need-issue label" - # Remove status/need-issue label if it was previously added - if ! gh pr edit "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --remove-label "status/need-issue" 2>/dev/null; then - echo " status/need-issue label not present or could not be removed" + echo " 📝 PR #${PR_NUMBER} is a draft and has no linked issue" + if [[ ",${CURRENT_LABELS}," == ",status/need-issue,"* ]]; then + echo " ➖ Removing status/need-issue label" + LABELS_TO_REMOVE="status/need-issue" fi - echo "needs_comment=false" >> "${GITHUB_OUTPUT}" else - echo "⚠️ No linked issue found for PR #${PR_NUMBER}, adding status/need-issue label" - if ! gh pr edit "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --add-label "status/need-issue" 2>/dev/null; then - echo " ⚠️ Failed to add label (may already exist or have permission issues)" + echo " ⚠️ No linked issue found for PR #${PR_NUMBER}" + if [[ ",${CURRENT_LABELS}," != ",status/need-issue,"* ]]; then + echo " ➕ Adding status/need-issue label" + LABELS_TO_ADD="status/need-issue" fi - # Add PR number to the list + if [[ -z "${PRS_NEEDING_COMMENT}" ]]; then PRS_NEEDING_COMMENT="${PR_NUMBER}" else PRS_NEEDING_COMMENT="${PRS_NEEDING_COMMENT},${PR_NUMBER}" fi - echo "needs_comment=true" >> "${GITHUB_OUTPUT}" fi else - echo "🔗 Found linked issue #${ISSUE_NUMBER}" + echo " 🔗 Found linked issue #${ISSUE_NUMBER}" - # Remove status/need-issue label if present - if ! gh pr edit "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --remove-label "status/need-issue" 2>/dev/null; then - echo " status/need-issue label not present or could not be removed" + if [[ ",${CURRENT_LABELS}," == ",status/need-issue,"* ]]; then + echo " ➖ Removing status/need-issue label" + LABELS_TO_REMOVE="status/need-issue" fi - # Get issue labels - echo "📥 Fetching area and priority labels from issue #${ISSUE_NUMBER}" - local ISSUE_LABELS="" - local gh_output - if ! gh_output=$(gh issue view "${ISSUE_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json labels -q '.labels[].name' 2>/dev/null); then - echo " ⚠️ Could not fetch issue #${ISSUE_NUMBER} (may not exist or be in different repo)" - ISSUE_LABELS="" - else - # If grep finds no matches, it exits with 1, which pipefail would treat as an error. - # `|| echo ""` ensures the command succeeds with an empty string in that case. - ISSUE_LABELS=$(echo "${gh_output}" | grep -E "^(area|priority)/" | tr '\n' ',' | sed 's/,$//' || echo "") - fi + local ISSUE_LABELS + ISSUE_LABELS=$(get_issue_labels "${ISSUE_NUMBER}") - # Get PR labels from already fetched PR_DATA - echo "📥 Extracting labels from PR #${PR_NUMBER}" - local PR_LABELS="" - PR_LABELS=$(echo "${PR_DATA}" | jq -r '.labels[].name // empty' | tr '\n' ',' | sed 's/,$//' || echo "") - - echo " Issue labels (area/priority): ${ISSUE_LABELS}" - echo " PR labels: ${PR_LABELS}" - - # Convert comma-separated strings to arrays - local ISSUE_LABEL_ARRAY PR_LABEL_ARRAY - IFS=',' read -ra ISSUE_LABEL_ARRAY <<< "${ISSUE_LABELS}" - IFS=',' read -ra PR_LABEL_ARRAY <<< "${PR_LABELS:-}" - - # Find labels to add (on issue but not on PR) - local LABELS_TO_ADD="" - for label in "${ISSUE_LABEL_ARRAY[@]}"; do - if [[ -n "${label}" ]] && [[ " ${PR_LABEL_ARRAY[*]:-}" != *" ${label} "* ]]; then - if [[ -z "${LABELS_TO_ADD}" ]]; then - LABELS_TO_ADD="${label}" - else - LABELS_TO_ADD="${LABELS_TO_ADD},${label}" + if [[ -n "${ISSUE_LABELS}" ]]; then + local IFS_OLD=$IFS + IFS=',' + for label in ${ISSUE_LABELS}; do + if [[ -n "${label}" ]] && [[ ",${CURRENT_LABELS}," != *",${label},"* ]]; then + if [[ -z "${LABELS_TO_ADD}" ]]; then + LABELS_TO_ADD="${label}" + else + LABELS_TO_ADD="${LABELS_TO_ADD},${label}" + fi fi - fi - done + done + IFS=$IFS_OLD + fi - # Apply label changes + if [[ -z "${LABELS_TO_ADD}" && -z "${LABELS_TO_REMOVE}" ]]; then + echo " ✅ Labels already synchronized" + fi + fi + + if [[ -n "${LABELS_TO_ADD}" || -n "${LABELS_TO_REMOVE}" ]]; then + local EDIT_CMD=("gh" "pr" "edit" "${PR_NUMBER}" "--repo" "${GITHUB_REPOSITORY}") if [[ -n "${LABELS_TO_ADD}" ]]; then - echo "➕ Adding labels: ${LABELS_TO_ADD}" - if ! gh pr edit "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --add-label "${LABELS_TO_ADD}" 2>/dev/null; then - echo " ⚠️ Failed to add some labels" - fi + echo " ➕ Syncing labels to add: ${LABELS_TO_ADD}" + EDIT_CMD+=("--add-label" "${LABELS_TO_ADD}") fi - - if [[ -z "${LABELS_TO_ADD}" ]]; then - echo "✅ Labels already synchronized" + if [[ -n "${LABELS_TO_REMOVE}" ]]; then + echo " ➖ Syncing labels to remove: ${LABELS_TO_REMOVE}" + EDIT_CMD+=("--remove-label" "${LABELS_TO_REMOVE}") fi - echo "needs_comment=false" >> "${GITHUB_OUTPUT}" + + ("${EDIT_CMD[@]}" 2>/dev/null || true) fi } -# If PR_NUMBER is set, process only that PR -if [[ -n "${PR_NUMBER:-}" ]]; then - if ! process_pr "${PR_NUMBER}"; then - echo "❌ Failed to process PR #${PR_NUMBER}" - exit 1 - fi -else - # Otherwise, get all open PRs and process them - # The script logic will determine which ones need issue linking or label sync - echo "📥 Getting all open pull requests..." - if ! PR_NUMBERS=$(gh pr list --repo "${GITHUB_REPOSITORY}" --state open --limit 1000 --json number -q '.[].number' 2>/dev/null); then - echo "❌ Failed to fetch PR list" - exit 1 - fi - - if [[ -z "${PR_NUMBERS}" ]]; then - echo "✅ No open PRs found" - else - # Count the number of PRs - PR_COUNT=$(echo "${PR_NUMBERS}" | wc -w | tr -d ' ') - echo "📊 Found ${PR_COUNT} open PRs to process" - - for pr_number in ${PR_NUMBERS}; do - if ! process_pr "${pr_number}"; then - echo "⚠️ Failed to process PR #${pr_number}, continuing with next PR..." - continue - fi - done - fi +if [[ -z "${GITHUB_REPOSITORY:-}" ]]; then + echo "‼️ Missing \$GITHUB_REPOSITORY - this must be run from GitHub Actions" + exit 1 +fi + +if [[ -z "${GITHUB_OUTPUT:-}" ]]; then + echo "‼️ Missing \$GITHUB_OUTPUT - this must be run from GitHub Actions" + exit 1 +fi + +JQ_EXTRACT_FIELDS='{ + number: .number, + isDraft: .isDraft, + issue: (.closingIssuesReferences[0].number // (.body // "" | capture("(^|[^a-zA-Z0-9])#(?[0-9]+)([^a-zA-Z0-9]|$)")? | .num) // "null"), + labels: [.labels[].name] | join(",") +}' + +JQ_TSV_FORMAT='"\((.number | tostring))\t\(.isDraft)\t\((.issue // "null") | tostring)\t\(.labels)"' + +if [[ -n "${PR_NUMBER:-}" ]]; then + echo "🔄 Processing single PR #${PR_NUMBER}" + PR_DATA=$(gh pr view "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json number,closingIssuesReferences,isDraft,body,labels 2>/dev/null) || { + echo "❌ Failed to fetch data for PR #${PR_NUMBER}" + exit 1 + } + + line=$(echo "$PR_DATA" | jq -r "$JQ_EXTRACT_FIELDS | $JQ_TSV_FORMAT") + IFS=$'\t' read -r pr_num is_draft issue_num current_labels <<< "$line" + process_pr_optimized "$pr_num" "$is_draft" "$issue_num" "$current_labels" +else + echo "📥 Getting all open pull requests..." + PR_DATA_ALL=$(gh pr list --repo "${GITHUB_REPOSITORY}" --state open --limit 1000 --json number,closingIssuesReferences,isDraft,body,labels 2>/dev/null) || { + echo "❌ Failed to fetch PR list" + exit 1 + } + + PR_COUNT=$(echo "${PR_DATA_ALL}" | jq '. | length') + echo "📊 Found ${PR_COUNT} open PRs to process" + + while read -r line; do + [[ -z "$line" ]] && continue + IFS=$'\t' read -r pr_num is_draft issue_num current_labels <<< "$line" + process_pr_optimized "$pr_num" "$is_draft" "$issue_num" "$current_labels" + done < <(echo "${PR_DATA_ALL}" | jq -r ".[] | $JQ_EXTRACT_FIELDS | $JQ_TSV_FORMAT") fi -# Ensure output is always set, even if empty if [[ -z "${PRS_NEEDING_COMMENT}" ]]; then echo "prs_needing_comment=[]" >> "${GITHUB_OUTPUT}" else echo "prs_needing_comment=[${PRS_NEEDING_COMMENT}]" >> "${GITHUB_OUTPUT}" fi -echo "✅ PR triage completed" +echo "✅ PR triage completed" \ No newline at end of file diff --git a/.github/workflows/gemini-scheduled-pr-triage.yml b/.github/workflows/gemini-scheduled-pr-triage.yml index 007b8daa3f..50cd5a1bad 100644 --- a/.github/workflows/gemini-scheduled-pr-triage.yml +++ b/.github/workflows/gemini-scheduled-pr-triage.yml @@ -39,3 +39,7 @@ jobs: GITHUB_REPOSITORY: '${{ github.repository }}' run: |- ./.github/scripts/pr-triage.sh + # If prs_needing_comment is empty, set it to [] explicitly for downstream steps + if [[ -z "$(grep 'prs_needing_comment' "${GITHUB_OUTPUT}" | cut -d'=' -f2-)" ]]; then + echo "prs_needing_comment=[]" >> "${GITHUB_OUTPUT}" + fi From d65eab01d2569474c7866c6e76ce8060a6ce1535 Mon Sep 17 00:00:00 2001 From: Shreya Keshive Date: Mon, 12 Jan 2026 15:39:08 -0500 Subject: [PATCH 133/713] feat(admin): prompt user to restart the CLI if they change auth to oauth mid-session or don't have auth type selected at start of session (#16426) --- packages/cli/src/test-utils/render.tsx | 1 + packages/cli/src/ui/AppContainer.tsx | 31 ++++++- packages/cli/src/ui/auth/AuthDialog.test.tsx | 24 +++++ packages/cli/src/ui/auth/AuthDialog.tsx | 9 +- .../LoginWithGoogleRestartDialog.test.tsx | 87 +++++++++++++++++++ .../ui/auth/LoginWithGoogleRestartDialog.tsx | 45 ++++++++++ ...LoginWithGoogleRestartDialog.test.tsx.snap | 8 ++ .../cli/src/ui/components/DialogManager.tsx | 1 + .../cli/src/ui/contexts/UIActionsContext.tsx | 1 + packages/cli/src/ui/types.ts | 2 + 10 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.test.tsx create mode 100644 packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.tsx create mode 100644 packages/cli/src/ui/auth/__snapshots__/LoginWithGoogleRestartDialog.test.tsx.snap diff --git a/packages/cli/src/test-utils/render.tsx b/packages/cli/src/test-utils/render.tsx index e083918683..3f77acd7a7 100644 --- a/packages/cli/src/test-utils/render.tsx +++ b/packages/cli/src/test-utils/render.tsx @@ -171,6 +171,7 @@ const mockUIActions: UIActions = { handleApiKeyCancel: vi.fn(), setBannerVisible: vi.fn(), setEmbeddedShellFocused: vi.fn(), + setAuthContext: vi.fn(), }; export const renderWithProviders = ( diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index 19f4ed44f2..e98a6476a2 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -126,6 +126,7 @@ import { WARNING_PROMPT_DURATION_MS, QUEUE_ERROR_DISPLAY_DURATION_MS, } from './constants.js'; +import { LoginWithGoogleRestartDialog } from './auth/LoginWithGoogleRestartDialog.js'; function isToolExecuting(pendingHistoryItems: HistoryItemWithoutId[]) { return pendingHistoryItems.some((item) => { @@ -468,6 +469,16 @@ export const AppContainer = (props: AppContainerProps) => { apiKeyDefaultValue, reloadApiKey, } = useAuthCommand(settings, config); + const [authContext, setAuthContext] = useState<{ requiresRestart?: boolean }>( + {}, + ); + + useEffect(() => { + if (authState === AuthState.Authenticated && authContext.requiresRestart) { + setAuthState(AuthState.AwaitingGoogleLoginRestart); + setAuthContext({}); + } + }, [authState, authContext, setAuthState]); const { proQuotaRequest, handleProQuotaChoice } = useQuotaAndFallback({ config, @@ -511,6 +522,11 @@ export const AppContainer = (props: AppContainerProps) => { const handleAuthSelect = useCallback( async (authType: AuthType | undefined, scope: LoadableSettingScope) => { if (authType) { + if (authType === AuthType.LOGIN_WITH_GOOGLE) { + setAuthContext({ requiresRestart: true }); + } else { + setAuthContext({}); + } await clearCachedCredentialFile(); settings.setValue(scope, 'security.auth.selectedType', authType); @@ -539,7 +555,7 @@ Logging in with Google... Restarting Gemini CLI to continue. } setAuthState(AuthState.Authenticated); }, - [settings, config, setAuthState, onAuthError], + [settings, config, setAuthState, onAuthError, setAuthContext], ); const handleApiKeySubmit = useCallback( @@ -1687,6 +1703,7 @@ Logging in with Google... Restarting Gemini CLI to continue. handleApiKeyCancel, setBannerVisible, setEmbeddedShellFocused, + setAuthContext, }), [ handleThemeSelect, @@ -1722,9 +1739,21 @@ Logging in with Google... Restarting Gemini CLI to continue. handleApiKeyCancel, setBannerVisible, setEmbeddedShellFocused, + setAuthContext, ], ); + if (authState === AuthState.AwaitingGoogleLoginRestart) { + return ( + { + setAuthContext({}); + setAuthState(AuthState.Updating); + }} + /> + ); + } + return ( diff --git a/packages/cli/src/ui/auth/AuthDialog.test.tsx b/packages/cli/src/ui/auth/AuthDialog.test.tsx index 16f0f9cbe8..66be01856d 100644 --- a/packages/cli/src/ui/auth/AuthDialog.test.tsx +++ b/packages/cli/src/ui/auth/AuthDialog.test.tsx @@ -72,6 +72,7 @@ describe('AuthDialog', () => { setAuthState: (state: AuthState) => void; authError: string | null; onAuthError: (error: string | null) => void; + setAuthContext: (context: { requiresRestart?: boolean }) => void; }; const originalEnv = { ...process.env }; @@ -94,6 +95,7 @@ describe('AuthDialog', () => { setAuthState: vi.fn(), authError: null, onAuthError: vi.fn(), + setAuthContext: vi.fn(), }; }); @@ -217,6 +219,28 @@ describe('AuthDialog', () => { expect(props.settings.setValue).not.toHaveBeenCalled(); }); + it('sets auth context with requiresRestart: true for LOGIN_WITH_GOOGLE', async () => { + mockedValidateAuthMethod.mockReturnValue(null); + renderWithProviders(); + const { onSelect: handleAuthSelect } = + mockedRadioButtonSelect.mock.calls[0][0]; + await handleAuthSelect(AuthType.LOGIN_WITH_GOOGLE); + + expect(props.setAuthContext).toHaveBeenCalledWith({ + requiresRestart: true, + }); + }); + + it('sets auth context with empty object for other auth types', async () => { + mockedValidateAuthMethod.mockReturnValue(null); + renderWithProviders(); + const { onSelect: handleAuthSelect } = + mockedRadioButtonSelect.mock.calls[0][0]; + await handleAuthSelect(AuthType.USE_GEMINI); + + expect(props.setAuthContext).toHaveBeenCalledWith({}); + }); + it('skips API key dialog on initial setup if env var is present', async () => { mockedValidateAuthMethod.mockReturnValue(null); process.env['GEMINI_API_KEY'] = 'test-key-from-env'; diff --git a/packages/cli/src/ui/auth/AuthDialog.tsx b/packages/cli/src/ui/auth/AuthDialog.tsx index b133acf52b..558927dcf2 100644 --- a/packages/cli/src/ui/auth/AuthDialog.tsx +++ b/packages/cli/src/ui/auth/AuthDialog.tsx @@ -31,6 +31,7 @@ interface AuthDialogProps { setAuthState: (state: AuthState) => void; authError: string | null; onAuthError: (error: string | null) => void; + setAuthContext: (context: { requiresRestart?: boolean }) => void; } export function AuthDialog({ @@ -39,6 +40,7 @@ export function AuthDialog({ setAuthState, authError, onAuthError, + setAuthContext, }: AuthDialogProps): React.JSX.Element { const [exiting, setExiting] = useState(false); let items = [ @@ -116,6 +118,11 @@ export function AuthDialog({ return; } if (authType) { + if (authType === AuthType.LOGIN_WITH_GOOGLE) { + setAuthContext({ requiresRestart: true }); + } else { + setAuthContext({}); + } await clearCachedCredentialFile(); settings.setValue(scope, 'security.auth.selectedType', authType); @@ -143,7 +150,7 @@ export function AuthDialog({ } setAuthState(AuthState.Unauthenticated); }, - [settings, config, setAuthState, exiting], + [settings, config, setAuthState, exiting, setAuthContext], ); const handleAuthSelect = (authMethod: AuthType) => { diff --git a/packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.test.tsx b/packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.test.tsx new file mode 100644 index 0000000000..5dd9d0c171 --- /dev/null +++ b/packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.test.tsx @@ -0,0 +1,87 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { render } from '../../test-utils/render.js'; +import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest'; +import { LoginWithGoogleRestartDialog } from './LoginWithGoogleRestartDialog.js'; +import { useKeypress } from '../hooks/useKeypress.js'; +import { runExitCleanup } from '../../utils/cleanup.js'; +import { RELAUNCH_EXIT_CODE } from '../../utils/processUtils.js'; + +// Mocks +vi.mock('../hooks/useKeypress.js', () => ({ + useKeypress: vi.fn(), +})); + +vi.mock('../../utils/cleanup.js', () => ({ + runExitCleanup: vi.fn(), +})); + +const mockedUseKeypress = useKeypress as Mock; +const mockedRunExitCleanup = runExitCleanup as Mock; + +describe('LoginWithGoogleRestartDialog', () => { + const onDismiss = vi.fn(); + const exitSpy = vi + .spyOn(process, 'exit') + .mockImplementation(() => undefined as never); + + beforeEach(() => { + vi.clearAllMocks(); + exitSpy.mockClear(); + vi.useRealTimers(); + }); + + it('renders correctly', () => { + const { lastFrame } = render( + , + ); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('calls onDismiss when escape is pressed', () => { + render(); + const keypressHandler = mockedUseKeypress.mock.calls[0][0]; + + keypressHandler({ + name: 'escape', + sequence: '\u001b', + ctrl: false, + meta: false, + shift: false, + paste: false, + }); + + expect(onDismiss).toHaveBeenCalledTimes(1); + }); + + it.each(['r', 'R'])( + 'calls runExitCleanup and process.exit when %s is pressed', + async (keyName) => { + vi.useFakeTimers(); + + render(); + const keypressHandler = mockedUseKeypress.mock.calls[0][0]; + + keypressHandler({ + name: keyName, + sequence: keyName, + ctrl: false, + meta: false, + shift: false, + paste: false, + }); + + // Advance timers to trigger the setTimeout callback + await vi.runAllTimersAsync(); + + expect(mockedRunExitCleanup).toHaveBeenCalledTimes(1); + expect(exitSpy).toHaveBeenCalledWith(RELAUNCH_EXIT_CODE); + + vi.useRealTimers(); + }, + ); +}); diff --git a/packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.tsx b/packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.tsx new file mode 100644 index 0000000000..0418e3f3f3 --- /dev/null +++ b/packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.tsx @@ -0,0 +1,45 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Box, Text } from 'ink'; +import { theme } from '../semantic-colors.js'; +import { useKeypress } from '../hooks/useKeypress.js'; +import { runExitCleanup } from '../../utils/cleanup.js'; +import { RELAUNCH_EXIT_CODE } from '../../utils/processUtils.js'; + +interface LoginWithGoogleRestartDialogProps { + onDismiss: () => void; +} + +export const LoginWithGoogleRestartDialog = ({ + onDismiss, +}: LoginWithGoogleRestartDialogProps) => { + useKeypress( + (key) => { + if (key.name === 'escape') { + onDismiss(); + } else if (key.name === 'r' || key.name === 'R') { + setTimeout(async () => { + await runExitCleanup(); + process.exit(RELAUNCH_EXIT_CODE); + }, 100); + } + }, + { isActive: true }, + ); + + const message = + 'You have successfully logged in with Google. Gemini CLI needs to be restarted.'; + + return ( + + + {message} Press 'r' to restart, or 'escape' to + choose a different auth method. + + + ); +}; diff --git a/packages/cli/src/ui/auth/__snapshots__/LoginWithGoogleRestartDialog.test.tsx.snap b/packages/cli/src/ui/auth/__snapshots__/LoginWithGoogleRestartDialog.test.tsx.snap new file mode 100644 index 0000000000..effd559184 --- /dev/null +++ b/packages/cli/src/ui/auth/__snapshots__/LoginWithGoogleRestartDialog.test.tsx.snap @@ -0,0 +1,8 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`LoginWithGoogleRestartDialog > renders correctly 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ You have successfully logged in with Google. Gemini CLI needs to be restarted. Press 'r' to │ +│ restart, or 'escape' to choose a different auth method. │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; diff --git a/packages/cli/src/ui/components/DialogManager.tsx b/packages/cli/src/ui/components/DialogManager.tsx index 132b1a020e..6a2fc46568 100644 --- a/packages/cli/src/ui/components/DialogManager.tsx +++ b/packages/cli/src/ui/components/DialogManager.tsx @@ -183,6 +183,7 @@ export const DialogManager = ({ setAuthState={uiActions.setAuthState} authError={uiState.authError} onAuthError={uiActions.onAuthError} + setAuthContext={uiActions.setAuthContext} /> ); diff --git a/packages/cli/src/ui/contexts/UIActionsContext.tsx b/packages/cli/src/ui/contexts/UIActionsContext.tsx index 120def8b1c..85839829f5 100644 --- a/packages/cli/src/ui/contexts/UIActionsContext.tsx +++ b/packages/cli/src/ui/contexts/UIActionsContext.tsx @@ -56,6 +56,7 @@ export interface UIActions { handleApiKeyCancel: () => void; setBannerVisible: (visible: boolean) => void; setEmbeddedShellFocused: (value: boolean) => void; + setAuthContext: (context: { requiresRestart?: boolean }) => void; } export const UIActionsContext = createContext(null); diff --git a/packages/cli/src/ui/types.ts b/packages/cli/src/ui/types.ts index 096caf862a..4f9a970278 100644 --- a/packages/cli/src/ui/types.ts +++ b/packages/cli/src/ui/types.ts @@ -30,6 +30,8 @@ export enum AuthState { AwaitingApiKeyInput = 'awaiting_api_key_input', // Successfully authenticated Authenticated = 'authenticated', + // Waiting for the user to restart after a Google login + AwaitingGoogleLoginRestart = 'awaiting_google_login_restart', } // Only defining the state enum needed by the UI From 7d9224201108ccbef51ecda09dcefa9ec7c0f6ae Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Mon, 12 Jan 2026 15:41:01 -0500 Subject: [PATCH 134/713] Update cli-help agent's system prompt in sub-agents section (#16441) --- packages/core/src/agents/cli-help-agent.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/agents/cli-help-agent.ts b/packages/core/src/agents/cli-help-agent.ts index a1909454bf..f774469ac3 100644 --- a/packages/core/src/agents/cli-help-agent.ts +++ b/packages/core/src/agents/cli-help-agent.ts @@ -78,9 +78,9 @@ export const CliHelpAgent = ( "- **Today's Date:** ${today}\n\n" + (config.isAgentsEnabled() ? '### Sub-Agents (Local & Remote)\n' + - 'User defined sub-agents are defined in `.gemini/agents/` or `~/.gemini/agents/` using YAML frontmatter for metadata and Markdown for instructions (system_prompt). Always reference the types and properties outlined here directly when answering questions about sub-agents.\n' + - '- **Local Agent:** `kind = "local"`, `name`, `description`, `prompts.system_prompt`, and optional `tools`, `model`, `run`.\n' + - '- **Remote Agent (A2A):** `kind = "remote"`, `name`, `agent_card_url`. Multiple remotes can be defined using a `remote_agents` array. **Note:** When users ask about "remote agents", they are referring to this Agent2Agent functionality, which is completely distinct from MCP servers.\n\n' + "User defined sub-agents are defined in `.gemini/agents/` or `~/.gemini/agents/` as .md files. These files contain YAML frontmatter for metadata, and the Markdown body becomes the agent's system prompt (`system_prompt`). Always reference the types and properties outlined here directly when answering questions about sub-agents.\n" + + '- **Local Agent:** `kind = "local"`, `name`, `description`, `system_prompt`, and optional `tools`, `model`, `temperate`, `max_turns`, `timeout_mins`.\n' + + '- **Remote Agent (A2A):** `kind = "remote"`, `name`, `agent_card_url`. Remote Agents do not use `system_prompt`. Multiple remote agents can be defined by using a YAML array at the top level of the frontmatter. **Note:** When users ask about "remote agents", they are referring to this Agent2Agent functionality, which is completely distinct from MCP servers.\n\n' : '') + '### Instructions\n' + "1. **Explore Documentation**: Use the `get_internal_docs` tool to find answers. If you don't know where to start, call `get_internal_docs()` without arguments to see the full list of available documentation files.\n" + From 8437ce940a1cc478c65630c05bc9e015271c572a Mon Sep 17 00:00:00 2001 From: christine betts Date: Mon, 12 Jan 2026 15:53:22 -0500 Subject: [PATCH 135/713] Revert "Update extension examples" (#16442) --- eslint.config.js | 10 -- .../examples/hooks/gemini-extension.json | 4 - .../examples/hooks/hooks/hooks.json | 14 -- .../examples/hooks/scripts/on-start.js | 8 -- .../extensions/examples/mcp-server/README.md | 35 ----- .../examples/mcp-server/example.test.ts | 135 ++++++++++++++++++ .../mcp-server/{example.js => example.ts} | 0 .../examples/mcp-server/gemini-extension.json | 2 +- .../examples/mcp-server/package.json | 7 + .../examples/mcp-server/tsconfig.json | 13 ++ .../examples/skills/gemini-extension.json | 4 - .../examples/skills/skills/greeter/SKILL.md | 7 - packages/cli/tsconfig.json | 2 +- 13 files changed, 157 insertions(+), 84 deletions(-) delete mode 100644 packages/cli/src/commands/extensions/examples/hooks/gemini-extension.json delete mode 100644 packages/cli/src/commands/extensions/examples/hooks/hooks/hooks.json delete mode 100644 packages/cli/src/commands/extensions/examples/hooks/scripts/on-start.js delete mode 100644 packages/cli/src/commands/extensions/examples/mcp-server/README.md create mode 100644 packages/cli/src/commands/extensions/examples/mcp-server/example.test.ts rename packages/cli/src/commands/extensions/examples/mcp-server/{example.js => example.ts} (100%) create mode 100644 packages/cli/src/commands/extensions/examples/mcp-server/tsconfig.json delete mode 100644 packages/cli/src/commands/extensions/examples/skills/gemini-extension.json delete mode 100644 packages/cli/src/commands/extensions/examples/skills/skills/greeter/SKILL.md diff --git a/eslint.config.js b/eslint.config.js index 959fbc5edb..c2d0d3b69b 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -301,16 +301,6 @@ export default tseslint.config( '@typescript-eslint/no-require-imports': 'off', }, }, - // Examples should have access to standard globals like fetch - { - files: ['packages/cli/src/commands/extensions/examples/**/*.js'], - languageOptions: { - globals: { - ...globals.node, - fetch: 'readonly', - }, - }, - }, // extra settings for scripts that we run directly with node { files: ['packages/vscode-ide-companion/scripts/**/*.js'], diff --git a/packages/cli/src/commands/extensions/examples/hooks/gemini-extension.json b/packages/cli/src/commands/extensions/examples/hooks/gemini-extension.json deleted file mode 100644 index 708e986346..0000000000 --- a/packages/cli/src/commands/extensions/examples/hooks/gemini-extension.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "hooks-example", - "version": "1.0.0" -} diff --git a/packages/cli/src/commands/extensions/examples/hooks/hooks/hooks.json b/packages/cli/src/commands/extensions/examples/hooks/hooks/hooks.json deleted file mode 100644 index f1af86d980..0000000000 --- a/packages/cli/src/commands/extensions/examples/hooks/hooks/hooks.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "hooks": { - "SessionStart": [ - { - "hooks": [ - { - "type": "command", - "command": "node ${extensionPath}/scripts/on-start.js" - } - ] - } - ] - } -} diff --git a/packages/cli/src/commands/extensions/examples/hooks/scripts/on-start.js b/packages/cli/src/commands/extensions/examples/hooks/scripts/on-start.js deleted file mode 100644 index 1f426f9a2f..0000000000 --- a/packages/cli/src/commands/extensions/examples/hooks/scripts/on-start.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @license - * Copyright 2026 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ -console.log( - 'Session Started! This is running from a script in the hooks-example extension.', -); diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/README.md b/packages/cli/src/commands/extensions/examples/mcp-server/README.md deleted file mode 100644 index 3ca50977ed..0000000000 --- a/packages/cli/src/commands/extensions/examples/mcp-server/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# MCP Server Example - -This is a basic example of an MCP (Model Context Protocol) server used as a -Gemini CLI extension. It demonstrates how to expose tools and prompts to the -Gemini CLI. - -## Description - -The contents of this directory are a valid MCP server implementation using the -`@modelcontextprotocol/sdk`. It exposes: - -- A tool `fetch_posts` that mock-fetches posts. -- A prompt `poem-writer`. - -## Structure - -- `example.js`: The main server entry point. -- `gemini-extension.json`: The configuration file that tells Gemini CLI how to - use this extension. -- `package.json`: Helper for dependencies. - -## How to Use - -1. Navigate to this directory: - - ```bash - cd packages/cli/src/commands/extensions/examples/mcp-server - ``` - -2. Install dependencies: - ```bash - npm install - ``` - -This example is typically used by `gemini extensions new`. diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/example.test.ts b/packages/cli/src/commands/extensions/examples/mcp-server/example.test.ts new file mode 100644 index 0000000000..5f5660df76 --- /dev/null +++ b/packages/cli/src/commands/extensions/examples/mcp-server/example.test.ts @@ -0,0 +1,135 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; +import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; +import { z } from 'zod'; + +// Mock the MCP server and transport +const mockRegisterTool = vi.fn(); +const mockRegisterPrompt = vi.fn(); +const mockConnect = vi.fn(); + +vi.mock('@modelcontextprotocol/sdk/server/mcp.js', () => ({ + McpServer: vi.fn().mockImplementation(() => ({ + registerTool: mockRegisterTool, + registerPrompt: mockRegisterPrompt, + connect: mockConnect, + })), +})); + +vi.mock('@modelcontextprotocol/sdk/server/stdio.js', () => ({ + StdioServerTransport: vi.fn(), +})); + +describe('MCP Server Example', () => { + beforeEach(async () => { + // Dynamically import the server setup after mocks are in place + await import('./example.js'); + }); + + afterEach(() => { + vi.clearAllMocks(); + vi.resetModules(); + }); + + it('should create an McpServer with the correct name and version', () => { + expect(McpServer).toHaveBeenCalledWith({ + name: 'prompt-server', + version: '1.0.0', + }); + }); + + it('should register the "fetch_posts" tool', () => { + expect(mockRegisterTool).toHaveBeenCalledWith( + 'fetch_posts', + { + description: 'Fetches a list of posts from a public API.', + inputSchema: z.object({}).shape, + }, + expect.any(Function), + ); + }); + + it('should register the "poem-writer" prompt', () => { + expect(mockRegisterPrompt).toHaveBeenCalledWith( + 'poem-writer', + { + title: 'Poem Writer', + description: 'Write a nice haiku', + argsSchema: expect.any(Object), + }, + expect.any(Function), + ); + }); + + it('should connect the server to an StdioServerTransport', () => { + expect(StdioServerTransport).toHaveBeenCalled(); + expect(mockConnect).toHaveBeenCalledWith(expect.any(StdioServerTransport)); + }); + + describe('fetch_posts tool implementation', () => { + it('should fetch posts and return a formatted response', async () => { + const mockPosts = [ + { id: 1, title: 'Post 1' }, + { id: 2, title: 'Post 2' }, + ]; + global.fetch = vi.fn().mockResolvedValue({ + json: vi.fn().mockResolvedValue(mockPosts), + }); + + const toolFn = mockRegisterTool.mock.calls[0][2]; + const result = await toolFn(); + + expect(global.fetch).toHaveBeenCalledWith( + 'https://jsonplaceholder.typicode.com/posts', + ); + expect(result).toEqual({ + content: [ + { + type: 'text', + text: JSON.stringify({ posts: mockPosts }), + }, + ], + }); + }); + }); + + describe('poem-writer prompt implementation', () => { + it('should generate a prompt with a title', () => { + const promptFn = mockRegisterPrompt.mock.calls[0][2]; + const result = promptFn({ title: 'My Poem' }); + expect(result).toEqual({ + messages: [ + { + role: 'user', + content: { + type: 'text', + text: 'Write a haiku called My Poem. Note that a haiku is 5 syllables followed by 7 syllables followed by 5 syllables ', + }, + }, + ], + }); + }); + + it('should generate a prompt with a title and mood', () => { + const promptFn = mockRegisterPrompt.mock.calls[0][2]; + const result = promptFn({ title: 'My Poem', mood: 'sad' }); + expect(result).toEqual({ + messages: [ + { + role: 'user', + content: { + type: 'text', + text: 'Write a haiku with the mood sad called My Poem. Note that a haiku is 5 syllables followed by 7 syllables followed by 5 syllables ', + }, + }, + ], + }); + }); + }); +}); diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/example.js b/packages/cli/src/commands/extensions/examples/mcp-server/example.ts similarity index 100% rename from packages/cli/src/commands/extensions/examples/mcp-server/example.js rename to packages/cli/src/commands/extensions/examples/mcp-server/example.ts diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/gemini-extension.json b/packages/cli/src/commands/extensions/examples/mcp-server/gemini-extension.json index 25cea93411..62561dbf8d 100644 --- a/packages/cli/src/commands/extensions/examples/mcp-server/gemini-extension.json +++ b/packages/cli/src/commands/extensions/examples/mcp-server/gemini-extension.json @@ -4,7 +4,7 @@ "mcpServers": { "nodeServer": { "command": "node", - "args": ["${extensionPath}${/}example.js"], + "args": ["${extensionPath}${/}dist${/}example.js"], "cwd": "${extensionPath}" } } diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/package.json b/packages/cli/src/commands/extensions/examples/mcp-server/package.json index ddb2959c38..45aa203ef3 100644 --- a/packages/cli/src/commands/extensions/examples/mcp-server/package.json +++ b/packages/cli/src/commands/extensions/examples/mcp-server/package.json @@ -4,6 +4,13 @@ "description": "Example MCP Server for Gemini CLI Extension", "type": "module", "main": "example.js", + "scripts": { + "build": "tsc" + }, + "devDependencies": { + "typescript": "~5.4.5", + "@types/node": "^20.11.25" + }, "dependencies": { "@modelcontextprotocol/sdk": "^1.23.0", "zod": "^3.22.4" diff --git a/packages/cli/src/commands/extensions/examples/mcp-server/tsconfig.json b/packages/cli/src/commands/extensions/examples/mcp-server/tsconfig.json new file mode 100644 index 0000000000..b94585edce --- /dev/null +++ b/packages/cli/src/commands/extensions/examples/mcp-server/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "outDir": "./dist" + }, + "include": ["example.ts"] +} diff --git a/packages/cli/src/commands/extensions/examples/skills/gemini-extension.json b/packages/cli/src/commands/extensions/examples/skills/gemini-extension.json deleted file mode 100644 index 2674ef9e0f..0000000000 --- a/packages/cli/src/commands/extensions/examples/skills/gemini-extension.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "skills-example", - "version": "1.0.0" -} diff --git a/packages/cli/src/commands/extensions/examples/skills/skills/greeter/SKILL.md b/packages/cli/src/commands/extensions/examples/skills/skills/greeter/SKILL.md deleted file mode 100644 index 24da110909..0000000000 --- a/packages/cli/src/commands/extensions/examples/skills/skills/greeter/SKILL.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -name: greeter -description: A friendly greeter skill ---- - -You are a friendly greeter. When the user says "hello" or asks for a greeting, -you should reply with: "Greetings from the skills-example extension! 👋" diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index b06787f0e6..e361d7ffe0 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -13,6 +13,6 @@ "src/**/*.json", "./package.json" ], - "exclude": ["node_modules", "dist", "src/commands/extensions/examples"], + "exclude": ["node_modules", "dist"], "references": [{ "path": "../core" }] } From e049d5e4e8fc8020a537a92b1607a7f0f28dec0b Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Mon, 12 Jan 2026 13:31:33 -0800 Subject: [PATCH 136/713] Fix: add back fastreturn support (#16440) --- .../src/ui/components/InputPrompt.test.tsx | 5 ++ .../src/ui/components/SettingsDialog.test.tsx | 10 +++- .../src/ui/contexts/KeypressContext.test.tsx | 49 +++++++++++++++++++ .../cli/src/ui/contexts/KeypressContext.tsx | 28 +++++++++++ 4 files changed, 90 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/ui/components/InputPrompt.test.tsx b/packages/cli/src/ui/components/InputPrompt.test.tsx index 0d000fc79f..7318d2119c 100644 --- a/packages/cli/src/ui/components/InputPrompt.test.tsx +++ b/packages/cli/src/ui/components/InputPrompt.test.tsx @@ -38,6 +38,7 @@ import { createMockCommandContext } from '../../test-utils/mockCommandContext.js import stripAnsi from 'strip-ansi'; import chalk from 'chalk'; import { StreamingState } from '../types.js'; +import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js'; vi.mock('../hooks/useShellHistory.js'); vi.mock('../hooks/useCommandCompletion.js'); @@ -124,6 +125,10 @@ describe('InputPrompt', () => { beforeEach(() => { vi.resetAllMocks(); + vi.spyOn( + terminalCapabilityManager, + 'isKittyProtocolEnabled', + ).mockReturnValue(true); mockCommandContext = createMockCommandContext(); diff --git a/packages/cli/src/ui/components/SettingsDialog.test.tsx b/packages/cli/src/ui/components/SettingsDialog.test.tsx index 78bd5a3917..d8481bc9d7 100644 --- a/packages/cli/src/ui/components/SettingsDialog.test.tsx +++ b/packages/cli/src/ui/components/SettingsDialog.test.tsx @@ -35,9 +35,10 @@ import { type SettingDefinition, type SettingsSchemaType, } from '../../config/settingsSchema.js'; +import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js'; // Mock the VimModeContext -const mockToggleVimEnabled = vi.fn(); +const mockToggleVimEnabled = vi.fn().mockResolvedValue(undefined); const mockSetVimMode = vi.fn(); vi.mock('../contexts/UIStateContext.js', () => ({ @@ -253,7 +254,12 @@ const renderDialog = ( describe('SettingsDialog', () => { beforeEach(() => { - mockToggleVimEnabled.mockResolvedValue(true); + vi.clearAllMocks(); + vi.spyOn( + terminalCapabilityManager, + 'isKittyProtocolEnabled', + ).mockReturnValue(true); + mockToggleVimEnabled.mockRejectedValue(undefined); }); afterEach(() => { diff --git a/packages/cli/src/ui/contexts/KeypressContext.test.tsx b/packages/cli/src/ui/contexts/KeypressContext.test.tsx index fddca507dd..348f940dbd 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.test.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.test.tsx @@ -16,7 +16,9 @@ import { KeypressProvider, useKeypressContext, ESC_TIMEOUT, + FAST_RETURN_TIMEOUT, } from './KeypressContext.js'; +import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js'; import { useStdin } from 'ink'; import { EventEmitter } from 'node:events'; @@ -154,6 +156,53 @@ describe('KeypressContext', () => { ); }); + describe('Fast return buffering', () => { + let kittySpy: ReturnType; + + beforeEach(() => { + kittySpy = vi + .spyOn(terminalCapabilityManager, 'isKittyProtocolEnabled') + .mockReturnValue(false); + }); + + afterEach(() => kittySpy.mockRestore()); + + it('should buffer return key pressed quickly after another key', async () => { + const { keyHandler } = setupKeypressTest(); + + act(() => stdin.write('a')); + expect(keyHandler).toHaveBeenLastCalledWith( + expect.objectContaining({ name: 'a' }), + ); + + act(() => stdin.write('\r')); + + expect(keyHandler).toHaveBeenLastCalledWith( + expect.objectContaining({ + name: '', + sequence: '\r', + insertable: true, + }), + ); + }); + + it('should NOT buffer return key if delay is long enough', async () => { + const { keyHandler } = setupKeypressTest(); + + act(() => stdin.write('a')); + + vi.advanceTimersByTime(FAST_RETURN_TIMEOUT + 1); + + act(() => stdin.write('\r')); + + expect(keyHandler).toHaveBeenLastCalledWith( + expect.objectContaining({ + name: 'return', + }), + ); + }); + }); + describe('Escape key handling', () => { it('should recognize escape key (keycode 27) in kitty protocol', async () => { const { keyHandler } = setupKeypressTest(); diff --git a/packages/cli/src/ui/contexts/KeypressContext.tsx b/packages/cli/src/ui/contexts/KeypressContext.tsx index 1faa705220..c0fdd6deac 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.tsx @@ -19,6 +19,7 @@ import { ESC } from '../utils/input.js'; import { parseMouseEvent } from '../utils/mouse.js'; import { FOCUS_IN, FOCUS_OUT } from '../hooks/useFocus.js'; import { appEvents, AppEvent } from '../../utils/events.js'; +import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js'; export const BACKSLASH_ENTER_TIMEOUT = 5; export const ESC_TIMEOUT = 50; @@ -143,6 +144,30 @@ function nonKeyboardEventFilter( }; } +/** + * Converts return keys pressed quickly after other keys into plain + * insertable return characters. + * + * This is to accommodate older terminals that paste text without bracketing. + */ +function bufferFastReturn(keypressHandler: KeypressHandler): KeypressHandler { + let lastKeyTime = 0; + return (key: Key) => { + const now = Date.now(); + if (key.name === 'return' && now - lastKeyTime <= FAST_RETURN_TIMEOUT) { + keypressHandler({ + ...key, + name: '', + sequence: '\r', + insertable: true, + }); + } else { + keypressHandler(key); + } + lastKeyTime = now; + }; +} + /** * Buffers "/" keys to see if they are followed return. * Will flush the buffer if no data is received for DRAG_COMPLETION_TIMEOUT_MS @@ -641,6 +666,9 @@ export function KeypressProvider({ process.stdin.setEncoding('utf8'); // Make data events emit strings let processor = nonKeyboardEventFilter(broadcast); + if (!terminalCapabilityManager.isKittyProtocolEnabled()) { + processor = bufferFastReturn(processor); + } processor = bufferBackslashEnter(processor); processor = bufferPaste(processor); let dataListener = createDataListener(processor); From d7bff8610f8cd177776453ecc05145d629573b16 Mon Sep 17 00:00:00 2001 From: Coco Sheng Date: Mon, 12 Jan 2026 16:46:42 -0500 Subject: [PATCH 137/713] feat(a2a): Introduce /memory command for a2a server (#14456) Co-authored-by: Shreya Keshive --- .../src/commands/command-registry.ts | 2 + .../a2a-server/src/commands/memory.test.ts | 208 ++++++++++++++++++ packages/a2a-server/src/commands/memory.ts | 118 ++++++++++ packages/a2a-server/src/config/config.ts | 25 ++- .../cli/src/ui/commands/memoryCommand.test.ts | 54 +++-- packages/cli/src/ui/commands/memoryCommand.ts | 71 ++---- packages/core/src/commands/memory.test.ts | 205 +++++++++++++++++ packages/core/src/commands/memory.ts | 96 ++++++++ packages/core/src/index.ts | 1 + 9 files changed, 703 insertions(+), 77 deletions(-) create mode 100644 packages/a2a-server/src/commands/memory.test.ts create mode 100644 packages/a2a-server/src/commands/memory.ts create mode 100644 packages/core/src/commands/memory.test.ts create mode 100644 packages/core/src/commands/memory.ts diff --git a/packages/a2a-server/src/commands/command-registry.ts b/packages/a2a-server/src/commands/command-registry.ts index 7b19d5d1f5..e9cd75b11a 100644 --- a/packages/a2a-server/src/commands/command-registry.ts +++ b/packages/a2a-server/src/commands/command-registry.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { MemoryCommand } from './memory.js'; import { debugLogger } from '@google/gemini-cli-core'; import { ExtensionsCommand } from './extensions.js'; import { InitCommand } from './init.js'; @@ -22,6 +23,7 @@ export class CommandRegistry { this.register(new ExtensionsCommand()); this.register(new RestoreCommand()); this.register(new InitCommand()); + this.register(new MemoryCommand()); } register(command: Command) { diff --git a/packages/a2a-server/src/commands/memory.test.ts b/packages/a2a-server/src/commands/memory.test.ts new file mode 100644 index 0000000000..40c5d1b90b --- /dev/null +++ b/packages/a2a-server/src/commands/memory.test.ts @@ -0,0 +1,208 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + addMemory, + listMemoryFiles, + refreshMemory, + showMemory, +} from '@google/gemini-cli-core'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { + AddMemoryCommand, + ListMemoryCommand, + MemoryCommand, + RefreshMemoryCommand, + ShowMemoryCommand, +} from './memory.js'; +import type { CommandContext } from './types.js'; +import type { + AnyDeclarativeTool, + Config, + ToolRegistry, +} from '@google/gemini-cli-core'; + +// Mock the core functions +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + showMemory: vi.fn(), + refreshMemory: vi.fn(), + listMemoryFiles: vi.fn(), + addMemory: vi.fn(), + }; +}); + +const mockShowMemory = vi.mocked(showMemory); +const mockRefreshMemory = vi.mocked(refreshMemory); +const mockListMemoryFiles = vi.mocked(listMemoryFiles); +const mockAddMemory = vi.mocked(addMemory); + +describe('a2a-server memory commands', () => { + let mockContext: CommandContext; + let mockConfig: Config; + let mockToolRegistry: ToolRegistry; + let mockSaveMemoryTool: AnyDeclarativeTool; + + beforeEach(() => { + mockSaveMemoryTool = { + name: 'save_memory', + description: 'Saves memory', + buildAndExecute: vi.fn().mockResolvedValue(undefined), + } as unknown as AnyDeclarativeTool; + + mockToolRegistry = { + getTool: vi.fn(), + } as unknown as ToolRegistry; + + mockConfig = { + getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry), + } as unknown as Config; + + mockContext = { + config: mockConfig, + }; + + vi.mocked(mockToolRegistry.getTool).mockReturnValue(mockSaveMemoryTool); + }); + + describe('MemoryCommand', () => { + it('delegates to ShowMemoryCommand', async () => { + const command = new MemoryCommand(); + mockShowMemory.mockReturnValue({ + type: 'message', + messageType: 'info', + content: 'showing memory', + }); + const response = await command.execute(mockContext, []); + expect(response.data).toBe('showing memory'); + expect(mockShowMemory).toHaveBeenCalledWith(mockContext.config); + }); + }); + + describe('ShowMemoryCommand', () => { + it('executes showMemory and returns the content', async () => { + const command = new ShowMemoryCommand(); + mockShowMemory.mockReturnValue({ + type: 'message', + messageType: 'info', + content: 'test memory content', + }); + + const response = await command.execute(mockContext, []); + + expect(mockShowMemory).toHaveBeenCalledWith(mockContext.config); + expect(response.name).toBe('memory show'); + expect(response.data).toBe('test memory content'); + }); + }); + + describe('RefreshMemoryCommand', () => { + it('executes refreshMemory and returns the content', async () => { + const command = new RefreshMemoryCommand(); + mockRefreshMemory.mockResolvedValue({ + type: 'message', + messageType: 'info', + content: 'memory refreshed', + }); + + const response = await command.execute(mockContext, []); + + expect(mockRefreshMemory).toHaveBeenCalledWith(mockContext.config); + expect(response.name).toBe('memory refresh'); + expect(response.data).toBe('memory refreshed'); + }); + }); + + describe('ListMemoryCommand', () => { + it('executes listMemoryFiles and returns the content', async () => { + const command = new ListMemoryCommand(); + mockListMemoryFiles.mockReturnValue({ + type: 'message', + messageType: 'info', + content: 'file1.md\nfile2.md', + }); + + const response = await command.execute(mockContext, []); + + expect(mockListMemoryFiles).toHaveBeenCalledWith(mockContext.config); + expect(response.name).toBe('memory list'); + expect(response.data).toBe('file1.md\nfile2.md'); + }); + }); + + describe('AddMemoryCommand', () => { + it('returns message content if addMemory returns a message', async () => { + const command = new AddMemoryCommand(); + mockAddMemory.mockReturnValue({ + type: 'message', + messageType: 'error', + content: 'error message', + }); + + const response = await command.execute(mockContext, []); + + expect(mockAddMemory).toHaveBeenCalledWith(''); + expect(response.name).toBe('memory add'); + expect(response.data).toBe('error message'); + }); + + it('executes the save_memory tool if found', async () => { + const command = new AddMemoryCommand(); + const fact = 'this is a new fact'; + mockAddMemory.mockReturnValue({ + type: 'tool', + toolName: 'save_memory', + toolArgs: { fact }, + }); + + const response = await command.execute(mockContext, [ + 'this', + 'is', + 'a', + 'new', + 'fact', + ]); + + expect(mockAddMemory).toHaveBeenCalledWith(fact); + expect(mockConfig.getToolRegistry).toHaveBeenCalled(); + expect(mockToolRegistry.getTool).toHaveBeenCalledWith('save_memory'); + expect(mockSaveMemoryTool.buildAndExecute).toHaveBeenCalledWith( + { fact }, + expect.any(AbortSignal), + undefined, + { + sanitizationConfig: { + allowedEnvironmentVariables: [], + blockedEnvironmentVariables: [], + enableEnvironmentVariableRedaction: false, + }, + }, + ); + expect(mockRefreshMemory).toHaveBeenCalledWith(mockContext.config); + expect(response.name).toBe('memory add'); + expect(response.data).toBe(`Added memory: "${fact}"`); + }); + + it('returns an error if the tool is not found', async () => { + const command = new AddMemoryCommand(); + const fact = 'another fact'; + mockAddMemory.mockReturnValue({ + type: 'tool', + toolName: 'save_memory', + toolArgs: { fact }, + }); + vi.mocked(mockToolRegistry.getTool).mockReturnValue(undefined); + + const response = await command.execute(mockContext, ['another', 'fact']); + + expect(response.name).toBe('memory add'); + expect(response.data).toBe('Error: Tool save_memory not found.'); + }); + }); +}); diff --git a/packages/a2a-server/src/commands/memory.ts b/packages/a2a-server/src/commands/memory.ts new file mode 100644 index 0000000000..16af1d3fe2 --- /dev/null +++ b/packages/a2a-server/src/commands/memory.ts @@ -0,0 +1,118 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + addMemory, + listMemoryFiles, + refreshMemory, + showMemory, +} from '@google/gemini-cli-core'; +import type { + Command, + CommandContext, + CommandExecutionResponse, +} from './types.js'; + +const DEFAULT_SANITIZATION_CONFIG = { + allowedEnvironmentVariables: [], + blockedEnvironmentVariables: [], + enableEnvironmentVariableRedaction: false, +}; + +export class MemoryCommand implements Command { + readonly name = 'memory'; + readonly description = 'Manage memory.'; + readonly subCommands = [ + new ShowMemoryCommand(), + new RefreshMemoryCommand(), + new ListMemoryCommand(), + new AddMemoryCommand(), + ]; + readonly topLevel = true; + readonly requiresWorkspace = true; + + async execute( + context: CommandContext, + _: string[], + ): Promise { + return new ShowMemoryCommand().execute(context, _); + } +} + +export class ShowMemoryCommand implements Command { + readonly name = 'memory show'; + readonly description = 'Shows the current memory contents.'; + + async execute( + context: CommandContext, + _: string[], + ): Promise { + const result = showMemory(context.config); + return { name: this.name, data: result.content }; + } +} + +export class RefreshMemoryCommand implements Command { + readonly name = 'memory refresh'; + readonly description = 'Refreshes the memory from the source.'; + + async execute( + context: CommandContext, + _: string[], + ): Promise { + const result = await refreshMemory(context.config); + return { name: this.name, data: result.content }; + } +} + +export class ListMemoryCommand implements Command { + readonly name = 'memory list'; + readonly description = 'Lists the paths of the GEMINI.md files in use.'; + + async execute( + context: CommandContext, + _: string[], + ): Promise { + const result = listMemoryFiles(context.config); + return { name: this.name, data: result.content }; + } +} + +export class AddMemoryCommand implements Command { + readonly name = 'memory add'; + readonly description = 'Add content to the memory.'; + + async execute( + context: CommandContext, + args: string[], + ): Promise { + const textToAdd = args.join(' ').trim(); + const result = addMemory(textToAdd); + if (result.type === 'message') { + return { name: this.name, data: result.content }; + } + + const toolRegistry = context.config.getToolRegistry(); + const tool = toolRegistry.getTool(result.toolName); + if (tool) { + const abortController = new AbortController(); + const signal = abortController.signal; + await tool.buildAndExecute(result.toolArgs, signal, undefined, { + sanitizationConfig: DEFAULT_SANITIZATION_CONFIG, + }); + await refreshMemory(context.config); + return { + name: this.name, + data: `Added memory: "${textToAdd}"`, + }; + } else { + return { + name: this.name, + data: `Error: Tool ${result.toolName} not found.`, + }; + } + } +} diff --git a/packages/a2a-server/src/config/config.ts b/packages/a2a-server/src/config/config.ts index a748c0b2d7..13d0d56995 100644 --- a/packages/a2a-server/src/config/config.ts +++ b/packages/a2a-server/src/config/config.ts @@ -37,6 +37,10 @@ export async function loadConfig( const workspaceDir = process.cwd(); const adcFilePath = process.env['GOOGLE_APPLICATION_CREDENTIALS']; + const folderTrust = + settings.folderTrust === true || + process.env['GEMINI_FOLDER_TRUST'] === 'true'; + const configParams: ConfigParameters = { sessionId: taskId, model: settings.general?.previewFeatures @@ -72,7 +76,8 @@ export async function loadConfig( settings.fileFiltering?.enableRecursiveFileSearch, }, ideMode: false, - folderTrust: settings.folderTrust === true, + folderTrust, + trustedFolder: true, extensionLoader, checkpointing: process.env['CHECKPOINTING'] ? process.env['CHECKPOINTING'] === 'true' @@ -83,16 +88,18 @@ export async function loadConfig( }; const fileService = new FileDiscoveryService(workspaceDir); - const { memoryContent, fileCount } = await loadServerHierarchicalMemory( - workspaceDir, - [workspaceDir], - false, - fileService, - extensionLoader, - settings.folderTrust === true, - ); + const { memoryContent, fileCount, filePaths } = + await loadServerHierarchicalMemory( + workspaceDir, + [workspaceDir], + false, + fileService, + extensionLoader, + folderTrust, + ); configParams.userMemory = memoryContent; configParams.geminiMdFileCount = fileCount; + configParams.geminiMdFilePaths = filePaths; const config = new Config({ ...configParams, }); diff --git a/packages/cli/src/ui/commands/memoryCommand.test.ts b/packages/cli/src/ui/commands/memoryCommand.test.ts index 178a133e93..63ebb5e36a 100644 --- a/packages/cli/src/ui/commands/memoryCommand.test.ts +++ b/packages/cli/src/ui/commands/memoryCommand.test.ts @@ -12,12 +12,11 @@ import { createMockCommandContext } from '../../test-utils/mockCommandContext.js import { MessageType } from '../types.js'; import type { LoadedSettings } from '../../config/settings.js'; import { - getErrorMessage, + refreshMemory, refreshServerHierarchicalMemory, SimpleExtensionLoader, type FileDiscoveryService, } from '@google/gemini-cli-core'; -import type { LoadServerHierarchicalMemoryResponse } from '@google/gemini-cli-core/index.js'; vi.mock('@google/gemini-cli-core', async (importOriginal) => { const original = @@ -28,10 +27,28 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { if (error instanceof Error) return error.message; return String(error); }), + refreshMemory: vi.fn(async (config) => { + if (config.isJitContextEnabled()) { + await config.getContextManager()?.refresh(); + const memoryContent = config.getUserMemory() || ''; + const fileCount = config.getGeminiMdFileCount() || 0; + return { + type: 'message', + messageType: 'info', + content: `Memory refreshed successfully. Loaded ${memoryContent.length} characters from ${fileCount} file(s).`, + }; + } + return { + type: 'message', + messageType: 'info', + content: 'Memory refreshed successfully.', + }; + }), refreshServerHierarchicalMemory: vi.fn(), }; }); +const mockRefreshMemory = refreshMemory as Mock; const mockRefreshServerHierarchicalMemory = refreshServerHierarchicalMemory as Mock; @@ -208,7 +225,7 @@ describe('memoryCommand', () => { } as unknown as LoadedSettings, }, }); - mockRefreshServerHierarchicalMemory.mockClear(); + mockRefreshMemory.mockClear(); }); it('should use ContextManager.refresh when JIT is enabled', async () => { @@ -239,12 +256,13 @@ describe('memoryCommand', () => { it('should display success message when memory is refreshed with content (Legacy)', async () => { if (!refreshCommand.action) throw new Error('Command has no action'); - const refreshResult: LoadServerHierarchicalMemoryResponse = { - memoryContent: 'new memory content', - fileCount: 2, - filePaths: ['/path/one/GEMINI.md', '/path/two/GEMINI.md'], + const successMessage = { + type: 'message', + messageType: MessageType.INFO, + content: + 'Memory refreshed successfully. Loaded 18 characters from 2 file(s).', }; - mockRefreshServerHierarchicalMemory.mockResolvedValue(refreshResult); + mockRefreshMemory.mockResolvedValue(successMessage); await refreshCommand.action(mockContext, ''); @@ -256,7 +274,7 @@ describe('memoryCommand', () => { expect.any(Number), ); - expect(mockRefreshServerHierarchicalMemory).toHaveBeenCalledOnce(); + expect(mockRefreshMemory).toHaveBeenCalledOnce(); expect(mockContext.ui.addItem).toHaveBeenCalledWith( { @@ -270,12 +288,16 @@ describe('memoryCommand', () => { it('should display success message when memory is refreshed with no content', async () => { if (!refreshCommand.action) throw new Error('Command has no action'); - const refreshResult = { memoryContent: '', fileCount: 0, filePaths: [] }; - mockRefreshServerHierarchicalMemory.mockResolvedValue(refreshResult); + const successMessage = { + type: 'message', + messageType: MessageType.INFO, + content: 'Memory refreshed successfully. No memory content found.', + }; + mockRefreshMemory.mockResolvedValue(successMessage); await refreshCommand.action(mockContext, ''); - expect(mockRefreshServerHierarchicalMemory).toHaveBeenCalledOnce(); + expect(mockRefreshMemory).toHaveBeenCalledOnce(); expect(mockContext.ui.addItem).toHaveBeenCalledWith( { @@ -290,11 +312,11 @@ describe('memoryCommand', () => { if (!refreshCommand.action) throw new Error('Command has no action'); const error = new Error('Failed to read memory files.'); - mockRefreshServerHierarchicalMemory.mockRejectedValue(error); + mockRefreshMemory.mockRejectedValue(error); await refreshCommand.action(mockContext, ''); - expect(mockRefreshServerHierarchicalMemory).toHaveBeenCalledOnce(); + expect(mockRefreshMemory).toHaveBeenCalledOnce(); expect(mockSetUserMemory).not.toHaveBeenCalled(); expect(mockSetGeminiMdFileCount).not.toHaveBeenCalled(); expect(mockSetGeminiMdFilePaths).not.toHaveBeenCalled(); @@ -306,8 +328,6 @@ describe('memoryCommand', () => { }, expect.any(Number), ); - - expect(getErrorMessage).toHaveBeenCalledWith(error); }); it('should not throw if config service is unavailable', async () => { @@ -329,7 +349,7 @@ describe('memoryCommand', () => { expect.any(Number), ); - expect(mockRefreshServerHierarchicalMemory).not.toHaveBeenCalled(); + expect(mockRefreshMemory).not.toHaveBeenCalled(); }); }); diff --git a/packages/cli/src/ui/commands/memoryCommand.ts b/packages/cli/src/ui/commands/memoryCommand.ts index d0df88f747..8f4bdaffbe 100644 --- a/packages/cli/src/ui/commands/memoryCommand.ts +++ b/packages/cli/src/ui/commands/memoryCommand.ts @@ -5,8 +5,10 @@ */ import { - getErrorMessage, - refreshServerHierarchicalMemory, + addMemory, + listMemoryFiles, + refreshMemory, + showMemory, } from '@google/gemini-cli-core'; import { MessageType } from '../types.js'; import type { SlashCommand, SlashCommandActionReturn } from './types.js'; @@ -24,18 +26,14 @@ export const memoryCommand: SlashCommand = { kind: CommandKind.BUILT_IN, autoExecute: true, action: async (context) => { - const memoryContent = context.services.config?.getUserMemory() || ''; - const fileCount = context.services.config?.getGeminiMdFileCount() || 0; - - const messageContent = - memoryContent.length > 0 - ? `Current memory content from ${fileCount} file(s):\n\n---\n${memoryContent}\n---` - : 'Memory is currently empty.'; + const config = context.services.config; + if (!config) return; + const result = showMemory(config); context.ui.addItem( { type: MessageType.INFO, - text: messageContent, + text: result.content, }, Date.now(), ); @@ -47,12 +45,10 @@ export const memoryCommand: SlashCommand = { kind: CommandKind.BUILT_IN, autoExecute: false, action: (context, args): SlashCommandActionReturn | void => { - if (!args || args.trim() === '') { - return { - type: 'message', - messageType: 'error', - content: 'Usage: /memory add ', - }; + const result = addMemory(args); + + if (result.type === 'message') { + return result; } context.ui.addItem( @@ -63,11 +59,7 @@ export const memoryCommand: SlashCommand = { Date.now(), ); - return { - type: 'tool', - toolName: 'save_memory', - toolArgs: { fact: args.trim() }, - }; + return result; }, }, { @@ -87,40 +79,21 @@ export const memoryCommand: SlashCommand = { try { const config = context.services.config; if (config) { - let memoryContent = ''; - let fileCount = 0; - - if (config.isJitContextEnabled()) { - await config.getContextManager()?.refresh(); - memoryContent = config.getUserMemory(); - fileCount = config.getGeminiMdFileCount(); - } else { - const result = await refreshServerHierarchicalMemory(config); - memoryContent = result.memoryContent; - fileCount = result.fileCount; - } - - await config.updateSystemInstructionIfInitialized(); - - const successMessage = - memoryContent.length > 0 - ? `Memory refreshed successfully. Loaded ${memoryContent.length} characters from ${fileCount} file(s).` - : 'Memory refreshed successfully. No memory content found.'; + const result = await refreshMemory(config); context.ui.addItem( { type: MessageType.INFO, - text: successMessage, + text: result.content, }, Date.now(), ); } } catch (error) { - const errorMessage = getErrorMessage(error); context.ui.addItem( { type: MessageType.ERROR, - text: `Error refreshing memory: ${errorMessage}`, + text: `Error refreshing memory: ${(error as Error).message}`, }, Date.now(), ); @@ -133,18 +106,14 @@ export const memoryCommand: SlashCommand = { kind: CommandKind.BUILT_IN, autoExecute: true, action: async (context) => { - const filePaths = context.services.config?.getGeminiMdFilePaths() || []; - const fileCount = filePaths.length; - - const messageContent = - fileCount > 0 - ? `There are ${fileCount} GEMINI.md file(s) in use:\n\n${filePaths.join('\n')}` - : 'No GEMINI.md files in use.'; + const config = context.services.config; + if (!config) return; + const result = listMemoryFiles(config); context.ui.addItem( { type: MessageType.INFO, - text: messageContent, + text: result.content, }, Date.now(), ); diff --git a/packages/core/src/commands/memory.test.ts b/packages/core/src/commands/memory.test.ts new file mode 100644 index 0000000000..3c885aa87c --- /dev/null +++ b/packages/core/src/commands/memory.test.ts @@ -0,0 +1,205 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import type { Config } from '../config/config.js'; +import { + addMemory, + listMemoryFiles, + refreshMemory, + showMemory, +} from './memory.js'; +import * as memoryDiscovery from '../utils/memoryDiscovery.js'; + +vi.mock('../utils/memoryDiscovery.js', () => ({ + refreshServerHierarchicalMemory: vi.fn(), +})); + +const mockRefresh = vi.mocked(memoryDiscovery.refreshServerHierarchicalMemory); + +describe('memory commands', () => { + let mockConfig: Config; + + beforeEach(() => { + mockConfig = { + getUserMemory: vi.fn(), + getGeminiMdFileCount: vi.fn(), + getGeminiMdFilePaths: vi.fn(), + isJitContextEnabled: vi.fn(), + updateSystemInstructionIfInitialized: vi + .fn() + .mockResolvedValue(undefined), + } as unknown as Config; + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + describe('showMemory', () => { + it('should show memory content if it exists', () => { + vi.mocked(mockConfig.getUserMemory).mockReturnValue( + 'some memory content', + ); + vi.mocked(mockConfig.getGeminiMdFileCount).mockReturnValue(1); + + const result = showMemory(mockConfig); + + expect(result.type).toBe('message'); + if (result.type === 'message') { + expect(result.messageType).toBe('info'); + expect(result.content).toContain( + 'Current memory content from 1 file(s)', + ); + expect(result.content).toContain('some memory content'); + } + }); + + it('should show a message if memory is empty', () => { + vi.mocked(mockConfig.getUserMemory).mockReturnValue(''); + vi.mocked(mockConfig.getGeminiMdFileCount).mockReturnValue(0); + + const result = showMemory(mockConfig); + + expect(result.type).toBe('message'); + if (result.type === 'message') { + expect(result.messageType).toBe('info'); + expect(result.content).toBe('Memory is currently empty.'); + } + }); + }); + + describe('addMemory', () => { + it('should return a tool action to save memory', () => { + const result = addMemory('new memory'); + expect(result.type).toBe('tool'); + if (result.type === 'tool') { + expect(result.toolName).toBe('save_memory'); + expect(result.toolArgs).toEqual({ fact: 'new memory' }); + } + }); + + it('should trim the arguments', () => { + const result = addMemory(' new memory '); + expect(result.type).toBe('tool'); + if (result.type === 'tool') { + expect(result.toolArgs).toEqual({ fact: 'new memory' }); + } + }); + + it('should return an error if args are empty', () => { + const result = addMemory(''); + expect(result.type).toBe('message'); + if (result.type === 'message') { + expect(result.messageType).toBe('error'); + expect(result.content).toBe('Usage: /memory add '); + } + }); + + it('should return an error if args are just whitespace', () => { + const result = addMemory(' '); + expect(result.type).toBe('message'); + if (result.type === 'message') { + expect(result.messageType).toBe('error'); + expect(result.content).toBe('Usage: /memory add '); + } + }); + + it('should return an error if args are undefined', () => { + const result = addMemory(undefined); + expect(result.type).toBe('message'); + if (result.type === 'message') { + expect(result.messageType).toBe('error'); + expect(result.content).toBe('Usage: /memory add '); + } + }); + }); + + describe('refreshMemory', () => { + it('should refresh memory and show success message', async () => { + mockRefresh.mockResolvedValue({ + memoryContent: 'refreshed content', + fileCount: 2, + filePaths: [], + }); + + const result = await refreshMemory(mockConfig); + + expect(mockRefresh).toHaveBeenCalledWith(mockConfig); + expect( + mockConfig.updateSystemInstructionIfInitialized, + ).toHaveBeenCalled(); + expect(result.type).toBe('message'); + if (result.type === 'message') { + expect(result.messageType).toBe('info'); + expect(result.content).toBe( + 'Memory refreshed successfully. Loaded 17 characters from 2 file(s).', + ); + } + }); + + it('should show a message if no memory content is found after refresh', async () => { + mockRefresh.mockResolvedValue({ + memoryContent: '', + fileCount: 0, + filePaths: [], + }); + + const result = await refreshMemory(mockConfig); + expect(result.type).toBe('message'); + if (result.type === 'message') { + expect(result.messageType).toBe('info'); + expect(result.content).toBe( + 'Memory refreshed successfully. No memory content found.', + ); + } + }); + }); + + describe('listMemoryFiles', () => { + it('should list the memory files in use', () => { + const filePaths = ['/path/to/GEMINI.md', '/other/path/GEMINI.md']; + vi.mocked(mockConfig.getGeminiMdFilePaths).mockReturnValue(filePaths); + + const result = listMemoryFiles(mockConfig); + + expect(result.type).toBe('message'); + if (result.type === 'message') { + expect(result.messageType).toBe('info'); + expect(result.content).toContain( + 'There are 2 GEMINI.md file(s) in use:', + ); + expect(result.content).toContain(filePaths.join('\n')); + } + }); + + it('should show a message if no memory files are in use', () => { + vi.mocked(mockConfig.getGeminiMdFilePaths).mockReturnValue([]); + + const result = listMemoryFiles(mockConfig); + + expect(result.type).toBe('message'); + if (result.type === 'message') { + expect(result.messageType).toBe('info'); + expect(result.content).toBe('No GEMINI.md files in use.'); + } + }); + + it('should show a message if file paths are undefined', () => { + vi.mocked(mockConfig.getGeminiMdFilePaths).mockReturnValue( + undefined as unknown as string[], + ); + + const result = listMemoryFiles(mockConfig); + + expect(result.type).toBe('message'); + if (result.type === 'message') { + expect(result.messageType).toBe('info'); + expect(result.content).toBe('No GEMINI.md files in use.'); + } + }); + }); +}); diff --git a/packages/core/src/commands/memory.ts b/packages/core/src/commands/memory.ts new file mode 100644 index 0000000000..6065cf0dab --- /dev/null +++ b/packages/core/src/commands/memory.ts @@ -0,0 +1,96 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type { Config } from '../config/config.js'; +import { refreshServerHierarchicalMemory } from '../utils/memoryDiscovery.js'; +import type { MessageActionReturn, ToolActionReturn } from './types.js'; + +export function showMemory(config: Config): MessageActionReturn { + const memoryContent = config.getUserMemory() || ''; + const fileCount = config.getGeminiMdFileCount() || 0; + let content: string; + + if (memoryContent.length > 0) { + content = `Current memory content from ${fileCount} file(s):\n\n---\n${memoryContent}\n---`; + } else { + content = 'Memory is currently empty.'; + } + + return { + type: 'message', + messageType: 'info', + content, + }; +} + +export function addMemory( + args?: string, +): MessageActionReturn | ToolActionReturn { + if (!args || args.trim() === '') { + return { + type: 'message', + messageType: 'error', + content: 'Usage: /memory add ', + }; + } + return { + type: 'tool', + toolName: 'save_memory', + toolArgs: { fact: args.trim() }, + }; +} + +export async function refreshMemory( + config: Config, +): Promise { + let memoryContent = ''; + let fileCount = 0; + + if (config.isJitContextEnabled()) { + await config.getContextManager()?.refresh(); + memoryContent = config.getUserMemory(); + fileCount = config.getGeminiMdFileCount(); + } else { + const result = await refreshServerHierarchicalMemory(config); + memoryContent = result.memoryContent; + fileCount = result.fileCount; + } + + await config.updateSystemInstructionIfInitialized(); + let content: string; + + if (memoryContent.length > 0) { + content = `Memory refreshed successfully. Loaded ${memoryContent.length} characters from ${fileCount} file(s).`; + } else { + content = 'Memory refreshed successfully. No memory content found.'; + } + + return { + type: 'message', + messageType: 'info', + content, + }; +} + +export function listMemoryFiles(config: Config): MessageActionReturn { + const filePaths = config.getGeminiMdFilePaths() || []; + const fileCount = filePaths.length; + let content: string; + + if (fileCount > 0) { + content = `There are ${fileCount} GEMINI.md file(s) in use:\n\n${filePaths.join( + '\n', + )}`; + } else { + content = 'No GEMINI.md files in use.'; + } + + return { + type: 'message', + messageType: 'info', + content, + }; +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index ce62f9fcfa..d587d3f221 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -22,6 +22,7 @@ export * from './confirmation-bus/message-bus.js'; export * from './commands/extensions.js'; export * from './commands/restore.js'; export * from './commands/init.js'; +export * from './commands/memory.js'; export * from './commands/types.js'; // Export Core Logic From b8cc414d5b3f1088c58883fdf7abf49b949ccf76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9E=E9=BD=90?= <62661921+Gong-Mi@users.noreply.github.com> Date: Tue, 13 Jan 2026 05:58:22 +0800 Subject: [PATCH 138/713] docs: fix broken internal link by using relative path (#15371) --- docs/releases.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/releases.md b/docs/releases.md index 5d98ff040e..3c8b3cf584 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -12,7 +12,7 @@ Dressing Room, which is Google's system for managing NPM packages in the `@google/**` namespace. The packages are all named `@google/**`. More information can be found about these systems in the -[maintainer repo guide](https://github.com/google-gemini/maintainers-gemini-cli/blob/main/npm.md) +[NPM Package Overview](npm.md) ### Package scopes From 95d9a339966b6d594bddc2ed649b2348f1e94000 Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Mon, 12 Jan 2026 14:50:32 -0800 Subject: [PATCH 139/713] migrate yolo/auto-edit keybindings (#16457) --- docs/cli/keyboard-shortcuts.md | 22 +++++++++---------- packages/cli/src/config/keyBindings.ts | 8 +++++++ .../src/ui/hooks/useAutoAcceptIndicator.ts | 5 +++-- packages/cli/src/ui/keyMatchers.test.ts | 12 ++++++++++ 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index 22ce5866c0..56f19a45a0 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -91,15 +91,17 @@ available combinations. #### App Controls -| Action | Keys | -| ----------------------------------------------------------------- | ---------- | -| Toggle detailed error information. | `F12` | -| Toggle the full TODO list. | `Ctrl + T` | -| Toggle IDE context details. | `Ctrl + G` | -| Toggle Markdown rendering. | `Cmd + M` | -| Toggle copy mode when the terminal is using the alternate buffer. | `Ctrl + S` | -| Expand a height-constrained response to show additional lines. | `Ctrl + S` | -| Toggle focus between the shell and Gemini input. | `Ctrl + F` | +| Action | Keys | +| ----------------------------------------------------------------- | ------------- | +| Toggle detailed error information. | `F12` | +| Toggle the full TODO list. | `Ctrl + T` | +| Toggle IDE context details. | `Ctrl + G` | +| Toggle Markdown rendering. | `Cmd + M` | +| Toggle copy mode when the terminal is using the alternate buffer. | `Ctrl + S` | +| Toggle YOLO (auto-approval) mode for tool calls. | `Ctrl + Y` | +| Toggle Auto Edit (auto-accept edits) mode. | `Shift + Tab` | +| Expand a height-constrained response to show additional lines. | `Ctrl + S` | +| Toggle focus between the shell and Gemini input. | `Ctrl + F` | #### Session Control @@ -112,8 +114,6 @@ available combinations. ## Additional context-specific shortcuts -- `Ctrl+Y`: Toggle YOLO (auto-approval) mode for tool calls. -- `Shift+Tab`: Toggle Auto Edit (auto-accept edits) mode. - `Option+M` (macOS): Entering `µ` with Option+M also toggles Markdown rendering, matching `Cmd+M`. - `!` on an empty prompt: Enter or exit shell mode. diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index b5a20b90e3..a919da1aff 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -62,6 +62,8 @@ export enum Command { TOGGLE_IDE_CONTEXT_DETAIL = 'toggleIDEContextDetail', TOGGLE_MARKDOWN = 'toggleMarkdown', TOGGLE_COPY_MODE = 'toggleCopyMode', + TOGGLE_YOLO = 'toggleYolo', + TOGGLE_AUTO_EDIT = 'toggleAutoEdit', QUIT = 'quit', EXIT = 'exit', SHOW_MORE_LINES = 'showMoreLines', @@ -203,6 +205,8 @@ export const defaultKeyBindings: KeyBindingConfig = { [Command.TOGGLE_IDE_CONTEXT_DETAIL]: [{ key: 'g', ctrl: true }], [Command.TOGGLE_MARKDOWN]: [{ key: 'm', command: true }], [Command.TOGGLE_COPY_MODE]: [{ key: 's', ctrl: true }], + [Command.TOGGLE_YOLO]: [{ key: 'y', ctrl: true }], + [Command.TOGGLE_AUTO_EDIT]: [{ key: 'tab', shift: true }], [Command.QUIT]: [{ key: 'c', ctrl: true }], [Command.EXIT]: [{ key: 'd', ctrl: true }], [Command.SHOW_MORE_LINES]: [{ key: 's', ctrl: true }], @@ -305,6 +309,8 @@ export const commandCategories: readonly CommandCategory[] = [ Command.TOGGLE_IDE_CONTEXT_DETAIL, Command.TOGGLE_MARKDOWN, Command.TOGGLE_COPY_MODE, + Command.TOGGLE_YOLO, + Command.TOGGLE_AUTO_EDIT, Command.SHOW_MORE_LINES, Command.TOGGLE_SHELL_INPUT_FOCUS, ], @@ -354,6 +360,8 @@ export const commandDescriptions: Readonly> = { [Command.TOGGLE_MARKDOWN]: 'Toggle Markdown rendering.', [Command.TOGGLE_COPY_MODE]: 'Toggle copy mode when the terminal is using the alternate buffer.', + [Command.TOGGLE_YOLO]: 'Toggle YOLO (auto-approval) mode for tool calls.', + [Command.TOGGLE_AUTO_EDIT]: 'Toggle Auto Edit (auto-accept edits) mode.', [Command.QUIT]: 'Cancel the current request or quit the CLI.', [Command.EXIT]: 'Exit the CLI when the input buffer is empty.', [Command.SHOW_MORE_LINES]: diff --git a/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts b/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts index 6091420abd..282ac3ea7d 100644 --- a/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts +++ b/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts @@ -7,6 +7,7 @@ import { useState, useEffect } from 'react'; import { ApprovalMode, type Config } from '@google/gemini-cli-core'; import { useKeypress } from './useKeypress.js'; +import { keyMatchers, Command } from '../keyMatchers.js'; import type { HistoryItemWithoutId } from '../types.js'; import { MessageType } from '../types.js'; @@ -33,7 +34,7 @@ export function useAutoAcceptIndicator({ (key) => { let nextApprovalMode: ApprovalMode | undefined; - if (key.ctrl && key.name === 'y') { + if (keyMatchers[Command.TOGGLE_YOLO](key)) { if ( config.isYoloModeDisabled() && config.getApprovalMode() !== ApprovalMode.YOLO @@ -53,7 +54,7 @@ export function useAutoAcceptIndicator({ config.getApprovalMode() === ApprovalMode.YOLO ? ApprovalMode.DEFAULT : ApprovalMode.YOLO; - } else if (key.shift && key.name === 'tab') { + } else if (keyMatchers[Command.TOGGLE_AUTO_EDIT](key)) { nextApprovalMode = config.getApprovalMode() === ApprovalMode.AUTO_EDIT ? ApprovalMode.DEFAULT diff --git a/packages/cli/src/ui/keyMatchers.test.ts b/packages/cli/src/ui/keyMatchers.test.ts index 0982e84b2a..b3ed875e6e 100644 --- a/packages/cli/src/ui/keyMatchers.test.ts +++ b/packages/cli/src/ui/keyMatchers.test.ts @@ -77,6 +77,8 @@ describe('keyMatchers', () => { key.name === 'tab', [Command.TOGGLE_SHELL_INPUT_FOCUS]: (key: Key) => key.ctrl && key.name === 'f', + [Command.TOGGLE_YOLO]: (key: Key) => key.ctrl && key.name === 'y', + [Command.TOGGLE_AUTO_EDIT]: (key: Key) => key.shift && key.name === 'tab', [Command.EXPAND_SUGGESTION]: (key: Key) => key.name === 'right', [Command.COLLAPSE_SUGGESTION]: (key: Key) => key.name === 'left', }; @@ -336,6 +338,16 @@ describe('keyMatchers', () => { positive: [createKey('f', { ctrl: true })], negative: [createKey('f')], }, + { + command: Command.TOGGLE_YOLO, + positive: [createKey('y', { ctrl: true })], + negative: [createKey('y'), createKey('y', { meta: true })], + }, + { + command: Command.TOGGLE_AUTO_EDIT, + positive: [createKey('tab', { shift: true })], + negative: [createKey('tab')], + }, ]; describe('Data-driven key binding matches original logic', () => { From 2e8c6cfdbb82bc360cec83738dfec5132b06ff0a Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 12 Jan 2026 15:24:41 -0800 Subject: [PATCH 140/713] feat(cli): add install and uninstall commands for skills (#16377) --- docs/cli/skills.md | 21 ++- packages/cli/src/commands/skills.tsx | 4 + .../cli/src/commands/skills/install.test.ts | 79 +++++++++++ packages/cli/src/commands/skills/install.ts | 85 +++++++++++ .../cli/src/commands/skills/uninstall.test.ts | 78 +++++++++++ packages/cli/src/commands/skills/uninstall.ts | 72 ++++++++++ packages/cli/src/utils/skillUtils.test.ts | 81 +++++++++++ packages/cli/src/utils/skillUtils.ts | 132 ++++++++++++++++++ packages/core/src/skills/skillLoader.ts | 2 +- 9 files changed, 551 insertions(+), 3 deletions(-) create mode 100644 packages/cli/src/commands/skills/install.test.ts create mode 100644 packages/cli/src/commands/skills/install.ts create mode 100644 packages/cli/src/commands/skills/uninstall.test.ts create mode 100644 packages/cli/src/commands/skills/uninstall.ts create mode 100644 packages/cli/src/utils/skillUtils.test.ts diff --git a/docs/cli/skills.md b/docs/cli/skills.md index 0badd9adaa..f7ddf003df 100644 --- a/docs/cli/skills.md +++ b/docs/cli/skills.md @@ -71,9 +71,26 @@ The `gemini skills` command provides management utilities: # List all discovered skills gemini skills list -# Enable/disable skills. Can use --scope to specify project or user +# Install a skill from a Git repository, local directory, or zipped skill file (.skill) +# Uses the user scope by default (~/.gemini/skills) +gemini skills install https://github.com/user/repo.git +gemini skills install /path/to/local/skill +gemini skills install /path/to/local/my-expertise.skill + +# Install a specific skill from a monorepo or subdirectory using --path +gemini skills install https://github.com/my-org/my-skills.git --path skills/frontend-design + +# Install to the workspace scope (.gemini/skills) +gemini skills install /path/to/skill --scope workspace + +# Uninstall a skill by name +gemini skills uninstall my-expertise --scope workspace + +# Enable a skill (globally) gemini skills enable my-expertise -gemini skills disable my-expertise + +# Disable a skill. Can use --scope to specify project or user (defaults to project) +gemini skills disable my-expertise --scope project ``` ## Creating a Skill diff --git a/packages/cli/src/commands/skills.tsx b/packages/cli/src/commands/skills.tsx index 2178456481..d2f249b049 100644 --- a/packages/cli/src/commands/skills.tsx +++ b/packages/cli/src/commands/skills.tsx @@ -8,6 +8,8 @@ import type { CommandModule } from 'yargs'; import { listCommand } from './skills/list.js'; import { enableCommand } from './skills/enable.js'; import { disableCommand } from './skills/disable.js'; +import { installCommand } from './skills/install.js'; +import { uninstallCommand } from './skills/uninstall.js'; import { initializeOutputListenersAndFlush } from '../gemini.js'; export const skillsCommand: CommandModule = { @@ -20,6 +22,8 @@ export const skillsCommand: CommandModule = { .command(listCommand) .command(enableCommand) .command(disableCommand) + .command(installCommand) + .command(uninstallCommand) .demandCommand(1, 'You need at least one command before continuing.') .version(false), handler: () => { diff --git a/packages/cli/src/commands/skills/install.test.ts b/packages/cli/src/commands/skills/install.test.ts new file mode 100644 index 0000000000..d3f36fbac3 --- /dev/null +++ b/packages/cli/src/commands/skills/install.test.ts @@ -0,0 +1,79 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach } from 'vitest'; + +const mockInstallSkill = vi.hoisted(() => vi.fn()); + +vi.mock('../../utils/skillUtils.js', () => ({ + installSkill: mockInstallSkill, +})); + +vi.mock('@google/gemini-cli-core', () => ({ + debugLogger: { log: vi.fn(), error: vi.fn() }, +})); + +import { debugLogger } from '@google/gemini-cli-core'; +import { handleInstall } from './install.js'; + +describe('skill install command', () => { + beforeEach(() => { + vi.clearAllMocks(); + vi.spyOn(process, 'exit').mockImplementation(() => undefined as never); + }); + + it('should call installSkill with correct arguments for user scope', async () => { + mockInstallSkill.mockResolvedValue([ + { name: 'test-skill', location: '/mock/user/skills/test-skill' }, + ]); + + await handleInstall({ + source: 'https://example.com/repo.git', + scope: 'user', + }); + + expect(mockInstallSkill).toHaveBeenCalledWith( + 'https://example.com/repo.git', + 'user', + undefined, + expect.any(Function), + ); + expect(debugLogger.log).toHaveBeenCalledWith( + expect.stringContaining('Successfully installed skill: test-skill'), + ); + expect(debugLogger.log).toHaveBeenCalledWith( + expect.stringContaining('location: /mock/user/skills/test-skill'), + ); + }); + + it('should call installSkill with correct arguments for workspace scope and subpath', async () => { + mockInstallSkill.mockResolvedValue([ + { name: 'test-skill', location: '/mock/workspace/skills/test-skill' }, + ]); + + await handleInstall({ + source: 'https://example.com/repo.git', + scope: 'workspace', + path: 'my-skills-dir', + }); + + expect(mockInstallSkill).toHaveBeenCalledWith( + 'https://example.com/repo.git', + 'workspace', + 'my-skills-dir', + expect.any(Function), + ); + }); + + it('should handle errors gracefully', async () => { + mockInstallSkill.mockRejectedValue(new Error('Install failed')); + + await handleInstall({ source: '/local/path' }); + + expect(debugLogger.error).toHaveBeenCalledWith('Install failed'); + expect(process.exit).toHaveBeenCalledWith(1); + }); +}); diff --git a/packages/cli/src/commands/skills/install.ts b/packages/cli/src/commands/skills/install.ts new file mode 100644 index 0000000000..9dbc0007bf --- /dev/null +++ b/packages/cli/src/commands/skills/install.ts @@ -0,0 +1,85 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type { CommandModule } from 'yargs'; +import { debugLogger } from '@google/gemini-cli-core'; +import { getErrorMessage } from '../../utils/errors.js'; +import { exitCli } from '../utils.js'; +import { installSkill } from '../../utils/skillUtils.js'; +import chalk from 'chalk'; + +interface InstallArgs { + source: string; + scope?: 'user' | 'workspace'; + path?: string; +} + +export async function handleInstall(args: InstallArgs) { + try { + const { source } = args; + const scope = args.scope ?? 'user'; + const subpath = args.path; + + const installedSkills = await installSkill( + source, + scope, + subpath, + (msg) => { + debugLogger.log(msg); + }, + ); + + for (const skill of installedSkills) { + debugLogger.log( + chalk.green( + `Successfully installed skill: ${chalk.bold(skill.name)} (scope: ${scope}, location: ${skill.location})`, + ), + ); + } + } catch (error) { + debugLogger.error(getErrorMessage(error)); + await exitCli(1); + } +} + +export const installCommand: CommandModule = { + command: 'install ', + describe: + 'Installs an agent skill from a git repository URL or a local path.', + builder: (yargs) => + yargs + .positional('source', { + describe: + 'The git repository URL or local path of the skill to install.', + type: 'string', + demandOption: true, + }) + .option('scope', { + describe: + 'The scope to install the skill into. Defaults to "user" (global).', + choices: ['user', 'workspace'], + default: 'user', + }) + .option('path', { + describe: + 'Sub-path within the repository to install from (only used for git repository sources).', + type: 'string', + }) + .check((argv) => { + if (!argv.source) { + throw new Error('The source argument must be provided.'); + } + return true; + }), + handler: async (argv) => { + await handleInstall({ + source: argv['source'] as string, + scope: argv['scope'] as 'user' | 'workspace', + path: argv['path'] as string | undefined, + }); + await exitCli(); + }, +}; diff --git a/packages/cli/src/commands/skills/uninstall.test.ts b/packages/cli/src/commands/skills/uninstall.test.ts new file mode 100644 index 0000000000..d1feaf7838 --- /dev/null +++ b/packages/cli/src/commands/skills/uninstall.test.ts @@ -0,0 +1,78 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach } from 'vitest'; + +const mockUninstallSkill = vi.hoisted(() => vi.fn()); + +vi.mock('../../utils/skillUtils.js', () => ({ + uninstallSkill: mockUninstallSkill, +})); + +vi.mock('@google/gemini-cli-core', () => ({ + debugLogger: { log: vi.fn(), error: vi.fn() }, +})); + +import { debugLogger } from '@google/gemini-cli-core'; +import { handleUninstall } from './uninstall.js'; + +describe('skill uninstall command', () => { + beforeEach(() => { + vi.clearAllMocks(); + vi.spyOn(process, 'exit').mockImplementation(() => undefined as never); + }); + + it('should call uninstallSkill with correct arguments for user scope', async () => { + mockUninstallSkill.mockResolvedValue({ + location: '/mock/user/skills/test-skill', + }); + + await handleUninstall({ + name: 'test-skill', + scope: 'user', + }); + + expect(mockUninstallSkill).toHaveBeenCalledWith('test-skill', 'user'); + expect(debugLogger.log).toHaveBeenCalledWith( + expect.stringContaining('Successfully uninstalled skill: test-skill'), + ); + expect(debugLogger.log).toHaveBeenCalledWith( + expect.stringContaining('location: /mock/user/skills/test-skill'), + ); + }); + + it('should call uninstallSkill with correct arguments for workspace scope', async () => { + mockUninstallSkill.mockResolvedValue({ + location: '/mock/workspace/skills/test-skill', + }); + + await handleUninstall({ + name: 'test-skill', + scope: 'workspace', + }); + + expect(mockUninstallSkill).toHaveBeenCalledWith('test-skill', 'workspace'); + }); + + it('should log an error if skill is not found', async () => { + mockUninstallSkill.mockResolvedValue(null); + + await handleUninstall({ name: 'test-skill' }); + + expect(debugLogger.error).toHaveBeenCalledWith( + 'Skill "test-skill" is not installed in the user scope.', + ); + }); + + it('should handle errors gracefully', async () => { + mockUninstallSkill.mockRejectedValue(new Error('Uninstall failed')); + + await handleUninstall({ name: 'test-skill' }); + + expect(debugLogger.error).toHaveBeenCalledWith('Uninstall failed'); + expect(process.exit).toHaveBeenCalledWith(1); + }); +}); diff --git a/packages/cli/src/commands/skills/uninstall.ts b/packages/cli/src/commands/skills/uninstall.ts new file mode 100644 index 0000000000..99f9091e3c --- /dev/null +++ b/packages/cli/src/commands/skills/uninstall.ts @@ -0,0 +1,72 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type { CommandModule } from 'yargs'; +import { debugLogger } from '@google/gemini-cli-core'; +import { getErrorMessage } from '../../utils/errors.js'; +import { exitCli } from '../utils.js'; +import { uninstallSkill } from '../../utils/skillUtils.js'; +import chalk from 'chalk'; + +interface UninstallArgs { + name: string; + scope?: 'user' | 'workspace'; +} + +export async function handleUninstall(args: UninstallArgs) { + try { + const { name } = args; + const scope = args.scope ?? 'user'; + + const result = await uninstallSkill(name, scope); + + if (result) { + debugLogger.log( + chalk.green( + `Successfully uninstalled skill: ${chalk.bold(name)} (scope: ${scope}, location: ${result.location})`, + ), + ); + } else { + debugLogger.error( + `Skill "${name}" is not installed in the ${scope} scope.`, + ); + } + } catch (error) { + debugLogger.error(getErrorMessage(error)); + await exitCli(1); + } +} + +export const uninstallCommand: CommandModule = { + command: 'uninstall ', + describe: 'Uninstalls an agent skill by name.', + builder: (yargs) => + yargs + .positional('name', { + describe: 'The name of the skill to uninstall.', + type: 'string', + demandOption: true, + }) + .option('scope', { + describe: + 'The scope to uninstall the skill from. Defaults to "user" (global).', + choices: ['user', 'workspace'], + default: 'user', + }) + .check((argv) => { + if (!argv.name) { + throw new Error('The skill name must be provided.'); + } + return true; + }), + handler: async (argv) => { + await handleUninstall({ + name: argv['name'] as string, + scope: argv['scope'] as 'user' | 'workspace', + }); + await exitCli(); + }, +}; diff --git a/packages/cli/src/utils/skillUtils.test.ts b/packages/cli/src/utils/skillUtils.test.ts new file mode 100644 index 0000000000..9dfe8560a6 --- /dev/null +++ b/packages/cli/src/utils/skillUtils.test.ts @@ -0,0 +1,81 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import * as fs from 'node:fs/promises'; +import * as path from 'node:path'; +import * as os from 'node:os'; +import { installSkill } from './skillUtils.js'; + +describe('skillUtils', () => { + let tempDir: string; + const projectRoot = path.resolve(__dirname, '../../../../../'); + + beforeEach(async () => { + tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'skill-utils-test-')); + vi.spyOn(process, 'cwd').mockReturnValue(tempDir); + }); + + afterEach(async () => { + await fs.rm(tempDir, { recursive: true, force: true }); + vi.restoreAllMocks(); + }); + + it('should successfully install from a .skill file', async () => { + const skillPath = path.join(projectRoot, 'weather-skill.skill'); + + // Ensure the file exists + const exists = await fs.stat(skillPath).catch(() => null); + if (!exists) { + // If we can't find it in CI or other environments, we skip or use a mock. + // For now, since it exists in the user's environment, this test will pass there. + return; + } + + const skills = await installSkill( + skillPath, + 'workspace', + undefined, + () => {}, + ); + expect(skills.length).toBeGreaterThan(0); + expect(skills[0].name).toBe('weather-skill'); + + // Verify it was copied to the workspace skills dir + const installedPath = path.join(tempDir, '.gemini/skills', 'weather-skill'); + const installedExists = await fs.stat(installedPath).catch(() => null); + expect(installedExists?.isDirectory()).toBe(true); + + const skillMdExists = await fs + .stat(path.join(installedPath, 'SKILL.md')) + .catch(() => null); + expect(skillMdExists?.isFile()).toBe(true); + }); + + it('should successfully install from a local directory', async () => { + // Create a mock skill directory + const mockSkillDir = path.join(tempDir, 'mock-skill-source'); + const skillSubDir = path.join(mockSkillDir, 'test-skill'); + await fs.mkdir(skillSubDir, { recursive: true }); + await fs.writeFile( + path.join(skillSubDir, 'SKILL.md'), + '---\nname: test-skill\ndescription: test\n---\nbody', + ); + + const skills = await installSkill( + mockSkillDir, + 'workspace', + undefined, + () => {}, + ); + expect(skills.length).toBe(1); + expect(skills[0].name).toBe('test-skill'); + + const installedPath = path.join(tempDir, '.gemini/skills', 'test-skill'); + const installedExists = await fs.stat(installedPath).catch(() => null); + expect(installedExists?.isDirectory()).toBe(true); + }); +}); diff --git a/packages/cli/src/utils/skillUtils.ts b/packages/cli/src/utils/skillUtils.ts index 1a86e04127..7acad4baf7 100644 --- a/packages/cli/src/utils/skillUtils.ts +++ b/packages/cli/src/utils/skillUtils.ts @@ -6,6 +6,12 @@ import { SettingScope } from '../config/settings.js'; import type { SkillActionResult } from './skillSettings.js'; +import { Storage, loadSkillsFromDir } from '@google/gemini-cli-core'; +import { cloneFromGit } from '../config/extensions/github.js'; +import extract from 'extract-zip'; +import * as fs from 'node:fs/promises'; +import * as path from 'node:path'; +import * as os from 'node:os'; /** * Shared logic for building the core skill action message while allowing the @@ -64,3 +70,129 @@ export function renderSkillActionFeedback( const s = formatScopeItem(totalAffectedScopes[0]); return `Skill "${skillName}" ${actionVerb} ${preposition} ${s} settings.`; } + +/** + * Central logic for installing a skill from a remote URL or local path. + */ +export async function installSkill( + source: string, + scope: 'user' | 'workspace', + subpath: string | undefined, + onLog: (msg: string) => void, +): Promise> { + let sourcePath = source; + let tempDirToClean: string | undefined = undefined; + + const isGitUrl = + source.startsWith('git@') || + source.startsWith('http://') || + source.startsWith('https://'); + + const isSkillFile = source.toLowerCase().endsWith('.skill'); + + if (isGitUrl) { + tempDirToClean = await fs.mkdtemp(path.join(os.tmpdir(), 'gemini-skill-')); + sourcePath = tempDirToClean; + + onLog(`Cloning skill from ${source}...`); + // Reuse existing robust git cloning utility from extension manager. + await cloneFromGit( + { + source, + type: 'git', + }, + tempDirToClean, + ); + } else if (isSkillFile) { + tempDirToClean = await fs.mkdtemp(path.join(os.tmpdir(), 'gemini-skill-')); + sourcePath = tempDirToClean; + + onLog(`Extracting skill from ${source}...`); + await extract(path.resolve(source), { dir: tempDirToClean }); + } + + // If a subpath is provided, resolve it against the cloned/local root. + if (subpath) { + sourcePath = path.join(sourcePath, subpath); + } + + sourcePath = path.resolve(sourcePath); + + // Quick security check to prevent directory traversal out of temp dir when cloning + if (tempDirToClean && !sourcePath.startsWith(path.resolve(tempDirToClean))) { + if (tempDirToClean) { + await fs.rm(tempDirToClean, { recursive: true, force: true }); + } + throw new Error('Invalid path: Directory traversal not allowed.'); + } + + onLog(`Searching for skills in ${sourcePath}...`); + const skills = await loadSkillsFromDir(sourcePath); + + if (skills.length === 0) { + if (tempDirToClean) { + await fs.rm(tempDirToClean, { recursive: true, force: true }); + } + throw new Error( + `No valid skills found in ${source}${subpath ? ` at path "${subpath}"` : ''}. Ensure a SKILL.md file exists with valid frontmatter.`, + ); + } + + const workspaceDir = process.cwd(); + const storage = new Storage(workspaceDir); + const targetDir = + scope === 'workspace' + ? storage.getProjectSkillsDir() + : Storage.getUserSkillsDir(); + + await fs.mkdir(targetDir, { recursive: true }); + + const installedSkills: Array<{ name: string; location: string }> = []; + + for (const skill of skills) { + const skillName = skill.name; + const skillDir = path.dirname(skill.location); + const destPath = path.join(targetDir, skillName); + + const exists = await fs.stat(destPath).catch(() => null); + if (exists) { + onLog(`Skill "${skillName}" already exists. Overwriting...`); + await fs.rm(destPath, { recursive: true, force: true }); + } + + await fs.cp(skillDir, destPath, { recursive: true }); + installedSkills.push({ name: skillName, location: destPath }); + } + + if (tempDirToClean) { + await fs.rm(tempDirToClean, { recursive: true, force: true }); + } + + return installedSkills; +} + +/** + * Central logic for uninstalling a skill by name. + */ +export async function uninstallSkill( + name: string, + scope: 'user' | 'workspace', +): Promise<{ location: string } | null> { + const workspaceDir = process.cwd(); + const storage = new Storage(workspaceDir); + const targetDir = + scope === 'workspace' + ? storage.getProjectSkillsDir() + : Storage.getUserSkillsDir(); + + const skillPath = path.join(targetDir, name); + + const exists = await fs.stat(skillPath).catch(() => null); + + if (!exists) { + return null; + } + + await fs.rm(skillPath, { recursive: true, force: true }); + return { location: skillPath }; +} diff --git a/packages/core/src/skills/skillLoader.ts b/packages/core/src/skills/skillLoader.ts index f5ef5a643c..354467734b 100644 --- a/packages/core/src/skills/skillLoader.ts +++ b/packages/core/src/skills/skillLoader.ts @@ -46,7 +46,7 @@ export async function loadSkillsFromDir( return []; } - const skillFiles = await glob('*/SKILL.md', { + const skillFiles = await glob(['SKILL.md', '*/SKILL.md'], { cwd: absoluteSearchPath, absolute: true, nodir: true, From ca6786a28bdcc1f452352acb19cfa53542059b55 Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Mon, 12 Jan 2026 15:30:12 -0800 Subject: [PATCH 141/713] feat(ui): use Tab to switch focus between shell and input (#14332) --- docs/cli/keyboard-shortcuts.md | 26 +++---- docs/tools/shell.md | 2 +- packages/cli/src/config/keyBindings.ts | 17 ++-- packages/cli/src/ui/AppContainer.tsx | 74 +++++++++++++----- .../src/ui/components/InputPrompt.test.tsx | 78 +++++++++++++++++++ .../cli/src/ui/components/InputPrompt.tsx | 12 ++- .../components/messages/ShellToolMessage.tsx | 2 +- .../ui/components/messages/ToolMessage.tsx | 2 +- .../src/ui/hooks/useAutoAcceptIndicator.ts | 4 +- packages/cli/src/ui/hooks/usePhraseCycler.ts | 2 +- packages/cli/src/ui/keyMatchers.test.ts | 75 +----------------- 11 files changed, 180 insertions(+), 114 deletions(-) diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index 56f19a45a0..e6960bcde5 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -91,17 +91,18 @@ available combinations. #### App Controls -| Action | Keys | -| ----------------------------------------------------------------- | ------------- | -| Toggle detailed error information. | `F12` | -| Toggle the full TODO list. | `Ctrl + T` | -| Toggle IDE context details. | `Ctrl + G` | -| Toggle Markdown rendering. | `Cmd + M` | -| Toggle copy mode when the terminal is using the alternate buffer. | `Ctrl + S` | -| Toggle YOLO (auto-approval) mode for tool calls. | `Ctrl + Y` | -| Toggle Auto Edit (auto-accept edits) mode. | `Shift + Tab` | -| Expand a height-constrained response to show additional lines. | `Ctrl + S` | -| Toggle focus between the shell and Gemini input. | `Ctrl + F` | +| Action | Keys | +| ----------------------------------------------------------------- | ----------------------------------- | +| Toggle detailed error information. | `F12` | +| Toggle the full TODO list. | `Ctrl + T` | +| Toggle IDE context details. | `Ctrl + G` | +| Toggle Markdown rendering. | `Cmd + M` | +| Toggle copy mode when the terminal is using the alternate buffer. | `Ctrl + S` | +| Toggle YOLO (auto-approval) mode for tool calls. | `Ctrl + Y` | +| Toggle Auto Edit (auto-accept edits) mode. | `Shift + Tab` | +| Expand a height-constrained response to show additional lines. | `Ctrl + S` | +| Toggle focus between the shell and Gemini input. | `Tab (no Shift)` | +| Toggle focus out of the interactive shell and into Gemini input. | `Tab (no Shift)`
`Shift + Tab` | #### Session Control @@ -122,8 +123,7 @@ available combinations. - `Ctrl+Delete` / `Meta+Delete`: Delete the word to the right of the cursor. - `Ctrl+B` or `Left Arrow`: Move the cursor one character to the left while editing text. -- `Ctrl+F` or `Right Arrow`: Move the cursor one character to the right; with an - embedded shell attached, `Ctrl+F` still toggles focus. +- `Ctrl+F` or `Right Arrow`: Move the cursor one character to the right. - `Ctrl+D` or `Delete`: Remove the character immediately to the right of the cursor. - `Ctrl+H` or `Backspace`: Remove the character immediately to the left of the diff --git a/docs/tools/shell.md b/docs/tools/shell.md index b179b6ce7f..0bb4b68244 100644 --- a/docs/tools/shell.md +++ b/docs/tools/shell.md @@ -135,7 +135,7 @@ user input, such as text editors (`vim`, `nano`), terminal-based UIs (`htop`), and interactive version control operations (`git rebase -i`). When an interactive command is running, you can send input to it from the Gemini -CLI. To focus on the interactive shell, press `ctrl+f`. The terminal output, +CLI. To focus on the interactive shell, press `Tab`. The terminal output, including complex TUIs, will be rendered correctly. ## Important notes diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index a919da1aff..06819e382a 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -72,7 +72,8 @@ export enum Command { REVERSE_SEARCH = 'reverseSearch', SUBMIT_REVERSE_SEARCH = 'submitReverseSearch', ACCEPT_SUGGESTION_REVERSE_SEARCH = 'acceptSuggestionReverseSearch', - TOGGLE_SHELL_INPUT_FOCUS = 'toggleShellInputFocus', + TOGGLE_SHELL_INPUT_FOCUS_IN = 'toggleShellInputFocus', + TOGGLE_SHELL_INPUT_FOCUS_OUT = 'toggleShellInputFocusOut', // Suggestion expansion EXPAND_SUGGESTION = 'expandSuggestion', @@ -216,8 +217,11 @@ export const defaultKeyBindings: KeyBindingConfig = { // Note: original logic ONLY checked ctrl=false, ignored meta/shift/paste [Command.SUBMIT_REVERSE_SEARCH]: [{ key: 'return', ctrl: false }], [Command.ACCEPT_SUGGESTION_REVERSE_SEARCH]: [{ key: 'tab' }], - [Command.TOGGLE_SHELL_INPUT_FOCUS]: [{ key: 'f', ctrl: true }], - + [Command.TOGGLE_SHELL_INPUT_FOCUS_IN]: [{ key: 'tab', shift: false }], + [Command.TOGGLE_SHELL_INPUT_FOCUS_OUT]: [ + { key: 'tab', shift: false }, + { key: 'tab', shift: true }, + ], // Suggestion expansion [Command.EXPAND_SUGGESTION]: [{ key: 'right' }], [Command.COLLAPSE_SUGGESTION]: [{ key: 'left' }], @@ -312,7 +316,8 @@ export const commandCategories: readonly CommandCategory[] = [ Command.TOGGLE_YOLO, Command.TOGGLE_AUTO_EDIT, Command.SHOW_MORE_LINES, - Command.TOGGLE_SHELL_INPUT_FOCUS, + Command.TOGGLE_SHELL_INPUT_FOCUS_IN, + Command.TOGGLE_SHELL_INPUT_FOCUS_OUT, ], }, { @@ -370,8 +375,10 @@ export const commandDescriptions: Readonly> = { [Command.SUBMIT_REVERSE_SEARCH]: 'Insert the selected reverse-search match.', [Command.ACCEPT_SUGGESTION_REVERSE_SEARCH]: 'Accept a suggestion while reverse searching.', - [Command.TOGGLE_SHELL_INPUT_FOCUS]: + [Command.TOGGLE_SHELL_INPUT_FOCUS_IN]: 'Toggle focus between the shell and Gemini input.', + [Command.TOGGLE_SHELL_INPUT_FOCUS_OUT]: + 'Toggle focus out of the interactive shell and into Gemini input.', [Command.EXPAND_SUGGESTION]: 'Expand an inline suggestion.', [Command.COLLAPSE_SUGGESTION]: 'Collapse an inline suggestion.', }; diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index e98a6476a2..93fef00dbb 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -823,11 +823,17 @@ Logging in with Google... Restarting Gemini CLI to continue. embeddedShellFocused, ); + const lastOutputTimeRef = useRef(0); + useEffect(() => { + lastOutputTimeRef.current = lastOutputTime; + }, [lastOutputTime]); + // Auto-accept indicator const showAutoAcceptIndicator = useAutoAcceptIndicator({ config, addItem: historyManager.addItem, onApprovalModeChange: handleApprovalModeChange, + isActive: !embeddedShellFocused, }); const { @@ -1053,19 +1059,20 @@ Logging in with Google... Restarting Gemini CLI to continue. useIncludeDirsTrust(config, isTrustedFolder, historyManager, setCustomDialog); + const warningTimeoutRef = useRef(null); + const tabFocusTimeoutRef = useRef(null); + + const handleWarning = useCallback((message: string) => { + setWarningMessage(message); + if (warningTimeoutRef.current) { + clearTimeout(warningTimeoutRef.current); + } + warningTimeoutRef.current = setTimeout(() => { + setWarningMessage(null); + }, WARNING_PROMPT_DURATION_MS); + }, []); + useEffect(() => { - let timeoutId: NodeJS.Timeout; - - const handleWarning = (message: string) => { - setWarningMessage(message); - if (timeoutId) { - clearTimeout(timeoutId); - } - timeoutId = setTimeout(() => { - setWarningMessage(null); - }, WARNING_PROMPT_DURATION_MS); - }; - const handleSelectionWarning = () => { handleWarning('Press Ctrl-S to enter selection mode to copy text.'); }; @@ -1077,11 +1084,14 @@ Logging in with Google... Restarting Gemini CLI to continue. return () => { appEvents.off(AppEvent.SelectionWarning, handleSelectionWarning); appEvents.off(AppEvent.PasteTimeout, handlePasteTimeout); - if (timeoutId) { - clearTimeout(timeoutId); + if (warningTimeoutRef.current) { + clearTimeout(warningTimeoutRef.current); + } + if (tabFocusTimeoutRef.current) { + clearTimeout(tabFocusTimeoutRef.current); } }; - }, []); + }, [handleWarning]); useEffect(() => { if (ideNeedsRestart) { @@ -1269,10 +1279,37 @@ Logging in with Google... Restarting Gemini CLI to continue. !enteringConstrainHeightMode ) { setConstrainHeight(false); - } else if (keyMatchers[Command.TOGGLE_SHELL_INPUT_FOCUS](key)) { - if (activePtyId || embeddedShellFocused) { - setEmbeddedShellFocused((prev) => !prev); + } else if ( + keyMatchers[Command.TOGGLE_SHELL_INPUT_FOCUS_OUT](key) && + activePtyId && + embeddedShellFocused + ) { + if (key.name === 'tab' && key.shift) { + // Always change focus + setEmbeddedShellFocused(false); + return; } + + const now = Date.now(); + // If the shell hasn't produced output in the last 100ms, it's considered idle. + const isIdle = now - lastOutputTimeRef.current >= 100; + if (isIdle) { + if (tabFocusTimeoutRef.current) { + clearTimeout(tabFocusTimeoutRef.current); + } + tabFocusTimeoutRef.current = setTimeout(() => { + tabFocusTimeoutRef.current = null; + // If the shell produced output since the tab press, we assume it handled the tab + // (e.g. autocomplete) so we should not toggle focus. + if (lastOutputTimeRef.current > now) { + handleWarning('Press Shift+Tab to focus out.'); + return; + } + setEmbeddedShellFocused(false); + }, 100); + return; + } + handleWarning('Press Shift+Tab to focus out.'); } }, [ @@ -1293,6 +1330,7 @@ Logging in with Google... Restarting Gemini CLI to continue. setCopyModeEnabled, copyModeEnabled, isAlternateBuffer, + handleWarning, ], ); diff --git a/packages/cli/src/ui/components/InputPrompt.test.tsx b/packages/cli/src/ui/components/InputPrompt.test.tsx index 7318d2119c..ee194dc3cb 100644 --- a/packages/cli/src/ui/components/InputPrompt.test.tsx +++ b/packages/cli/src/ui/components/InputPrompt.test.tsx @@ -2418,6 +2418,84 @@ describe('InputPrompt', () => { }); }); + describe('Tab focus toggle', () => { + it.each([ + { + name: 'should toggle focus in on Tab when no suggestions or ghost text', + showSuggestions: false, + ghostText: '', + suggestions: [], + expectedFocusToggle: true, + }, + { + name: 'should accept ghost text and NOT toggle focus on Tab', + showSuggestions: false, + ghostText: 'ghost text', + suggestions: [], + expectedFocusToggle: false, + expectedAcceptCall: true, + }, + { + name: 'should NOT toggle focus on Tab when suggestions are present', + showSuggestions: true, + ghostText: '', + suggestions: [{ label: 'test', value: 'test' }], + expectedFocusToggle: false, + }, + ])( + '$name', + async ({ + showSuggestions, + ghostText, + suggestions, + expectedFocusToggle, + expectedAcceptCall, + }) => { + const mockAccept = vi.fn(); + mockedUseCommandCompletion.mockReturnValue({ + ...mockCommandCompletion, + showSuggestions, + suggestions, + promptCompletion: { + text: ghostText, + accept: mockAccept, + clear: vi.fn(), + isLoading: false, + isActive: ghostText !== '', + markSelected: vi.fn(), + }, + }); + + const { stdin, unmount } = renderWithProviders( + , + { + uiActions, + uiState: { activePtyId: 1 }, + }, + ); + + await act(async () => { + stdin.write('\t'); + }); + + await waitFor(() => { + if (expectedFocusToggle) { + expect(uiActions.setEmbeddedShellFocused).toHaveBeenCalledWith( + true, + ); + } else { + expect(uiActions.setEmbeddedShellFocused).not.toHaveBeenCalled(); + } + + if (expectedAcceptCall) { + expect(mockAccept).toHaveBeenCalled(); + } + }); + unmount(); + }, + ); + }); + describe('mouse interaction', () => { it.each([ { diff --git a/packages/cli/src/ui/components/InputPrompt.tsx b/packages/cli/src/ui/components/InputPrompt.tsx index 78031a8a9e..239e192fec 100644 --- a/packages/cli/src/ui/components/InputPrompt.tsx +++ b/packages/cli/src/ui/components/InputPrompt.tsx @@ -135,7 +135,7 @@ export const InputPrompt: React.FC = ({ const kittyProtocol = useKittyKeyboardProtocol(); const isShellFocused = useShellFocusState(); const { setEmbeddedShellFocused } = useUIActions(); - const { mainAreaWidth } = useUIState(); + const { mainAreaWidth, activePtyId } = useUIState(); const [justNavigatedHistory, setJustNavigatedHistory] = useState(false); const escPressCount = useRef(0); const [showEscapePrompt, setShowEscapePrompt] = useState(false); @@ -829,6 +829,14 @@ export const InputPrompt: React.FC = ({ return; } + if (keyMatchers[Command.TOGGLE_SHELL_INPUT_FOCUS_IN](key)) { + // If we got here, Autocomplete didn't handle the key (e.g. no suggestions). + if (activePtyId) { + setEmbeddedShellFocused(true); + } + return; + } + // Fall back to the text buffer's default input handling for all other keys buffer.handleInput(key); @@ -870,6 +878,8 @@ export const InputPrompt: React.FC = ({ kittyProtocol.enabled, tryLoadQueuedMessages, setBannerVisible, + activePtyId, + setEmbeddedShellFocused, ], ); diff --git a/packages/cli/src/ui/components/messages/ShellToolMessage.tsx b/packages/cli/src/ui/components/messages/ShellToolMessage.tsx index a9197f15c5..b5be480279 100644 --- a/packages/cli/src/ui/components/messages/ShellToolMessage.tsx +++ b/packages/cli/src/ui/components/messages/ShellToolMessage.tsx @@ -140,7 +140,7 @@ export const ShellToolMessage: React.FC = ({ {shouldShowFocusHint && ( - {isThisShellFocused ? '(Focused)' : '(ctrl+f to focus)'} + {isThisShellFocused ? '(Focused)' : '(tab to focus)'} )} diff --git a/packages/cli/src/ui/components/messages/ToolMessage.tsx b/packages/cli/src/ui/components/messages/ToolMessage.tsx index 86ad6968d8..f8180f92c5 100644 --- a/packages/cli/src/ui/components/messages/ToolMessage.tsx +++ b/packages/cli/src/ui/components/messages/ToolMessage.tsx @@ -112,7 +112,7 @@ export const ToolMessage: React.FC = ({ {shouldShowFocusHint && ( - {isThisShellFocused ? '(Focused)' : '(ctrl+f to focus)'} + {isThisShellFocused ? '(Focused)' : '(tab to focus)'} )} diff --git a/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts b/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts index 282ac3ea7d..aca0de57df 100644 --- a/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts +++ b/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts @@ -15,12 +15,14 @@ export interface UseAutoAcceptIndicatorArgs { config: Config; addItem?: (item: HistoryItemWithoutId, timestamp: number) => void; onApprovalModeChange?: (mode: ApprovalMode) => void; + isActive?: boolean; } export function useAutoAcceptIndicator({ config, addItem, onApprovalModeChange, + isActive = true, }: UseAutoAcceptIndicatorArgs): ApprovalMode { const currentConfigValue = config.getApprovalMode(); const [showAutoAcceptIndicator, setShowAutoAcceptIndicator] = @@ -82,7 +84,7 @@ export function useAutoAcceptIndicator({ } } }, - { isActive: true }, + { isActive }, ); return showAutoAcceptIndicator; diff --git a/packages/cli/src/ui/hooks/usePhraseCycler.ts b/packages/cli/src/ui/hooks/usePhraseCycler.ts index 969fe47135..86a7292152 100644 --- a/packages/cli/src/ui/hooks/usePhraseCycler.ts +++ b/packages/cli/src/ui/hooks/usePhraseCycler.ts @@ -12,7 +12,7 @@ import { useInactivityTimer } from './useInactivityTimer.js'; export const PHRASE_CHANGE_INTERVAL_MS = 15000; export const INTERACTIVE_SHELL_WAITING_PHRASE = - 'Interactive shell awaiting input... press Ctrl+f to focus shell'; + 'Interactive shell awaiting input... press tab to focus shell'; /** * Custom hook to manage cycling through loading phrases. diff --git a/packages/cli/src/ui/keyMatchers.test.ts b/packages/cli/src/ui/keyMatchers.test.ts index b3ed875e6e..8ddfd0371d 100644 --- a/packages/cli/src/ui/keyMatchers.test.ts +++ b/packages/cli/src/ui/keyMatchers.test.ts @@ -22,67 +22,6 @@ describe('keyMatchers', () => { ...mods, }); - // Original hard-coded logic (for comparison) - const originalMatchers: Record boolean> = { - [Command.RETURN]: (key: Key) => key.name === 'return', - [Command.HOME]: (key: Key) => key.ctrl && key.name === 'a', - [Command.END]: (key: Key) => key.ctrl && key.name === 'e', - [Command.KILL_LINE_RIGHT]: (key: Key) => key.ctrl && key.name === 'k', - [Command.KILL_LINE_LEFT]: (key: Key) => key.ctrl && key.name === 'u', - [Command.CLEAR_INPUT]: (key: Key) => key.ctrl && key.name === 'c', - [Command.DELETE_WORD_BACKWARD]: (key: Key) => - (key.ctrl || key.meta) && key.name === 'backspace', - [Command.CLEAR_SCREEN]: (key: Key) => key.ctrl && key.name === 'l', - [Command.SCROLL_UP]: (key: Key) => key.name === 'up' && !!key.shift, - [Command.SCROLL_DOWN]: (key: Key) => key.name === 'down' && !!key.shift, - [Command.SCROLL_HOME]: (key: Key) => key.name === 'home', - [Command.SCROLL_END]: (key: Key) => key.name === 'end', - [Command.PAGE_UP]: (key: Key) => key.name === 'pageup', - [Command.PAGE_DOWN]: (key: Key) => key.name === 'pagedown', - [Command.HISTORY_UP]: (key: Key) => key.ctrl && key.name === 'p', - [Command.HISTORY_DOWN]: (key: Key) => key.ctrl && key.name === 'n', - [Command.NAVIGATION_UP]: (key: Key) => key.name === 'up', - [Command.NAVIGATION_DOWN]: (key: Key) => key.name === 'down', - [Command.DIALOG_NAVIGATION_UP]: (key: Key) => - !key.shift && (key.name === 'up' || key.name === 'k'), - [Command.DIALOG_NAVIGATION_DOWN]: (key: Key) => - !key.shift && (key.name === 'down' || key.name === 'j'), - [Command.ACCEPT_SUGGESTION]: (key: Key) => - key.name === 'tab' || (key.name === 'return' && !key.ctrl), - [Command.COMPLETION_UP]: (key: Key) => - key.name === 'up' || (key.ctrl && key.name === 'p'), - [Command.COMPLETION_DOWN]: (key: Key) => - key.name === 'down' || (key.ctrl && key.name === 'n'), - [Command.ESCAPE]: (key: Key) => key.name === 'escape', - [Command.SUBMIT]: (key: Key) => - key.name === 'return' && !key.ctrl && !key.meta && !key.paste, - [Command.NEWLINE]: (key: Key) => - key.name === 'return' && (key.ctrl || key.meta || key.paste), - [Command.OPEN_EXTERNAL_EDITOR]: (key: Key) => - key.ctrl && (key.name === 'x' || key.sequence === '\x18'), - [Command.PASTE_CLIPBOARD]: (key: Key) => key.ctrl && key.name === 'v', - [Command.SHOW_ERROR_DETAILS]: (key: Key) => key.name === 'f12', - [Command.SHOW_FULL_TODOS]: (key: Key) => key.ctrl && key.name === 't', - [Command.TOGGLE_IDE_CONTEXT_DETAIL]: (key: Key) => - key.ctrl && key.name === 'g', - [Command.TOGGLE_MARKDOWN]: (key: Key) => key.meta && key.name === 'm', - [Command.TOGGLE_COPY_MODE]: (key: Key) => key.ctrl && key.name === 's', - [Command.QUIT]: (key: Key) => key.ctrl && key.name === 'c', - [Command.EXIT]: (key: Key) => key.ctrl && key.name === 'd', - [Command.SHOW_MORE_LINES]: (key: Key) => key.ctrl && key.name === 's', - [Command.REVERSE_SEARCH]: (key: Key) => key.ctrl && key.name === 'r', - [Command.SUBMIT_REVERSE_SEARCH]: (key: Key) => - key.name === 'return' && !key.ctrl, - [Command.ACCEPT_SUGGESTION_REVERSE_SEARCH]: (key: Key) => - key.name === 'tab', - [Command.TOGGLE_SHELL_INPUT_FOCUS]: (key: Key) => - key.ctrl && key.name === 'f', - [Command.TOGGLE_YOLO]: (key: Key) => key.ctrl && key.name === 'y', - [Command.TOGGLE_AUTO_EDIT]: (key: Key) => key.shift && key.name === 'tab', - [Command.EXPAND_SUGGESTION]: (key: Key) => key.name === 'right', - [Command.COLLAPSE_SUGGESTION]: (key: Key) => key.name === 'left', - }; - // Test data for each command with positive and negative test cases const testCases = [ // Basic bindings @@ -334,9 +273,9 @@ describe('keyMatchers', () => { negative: [createKey('return'), createKey('space')], }, { - command: Command.TOGGLE_SHELL_INPUT_FOCUS, - positive: [createKey('f', { ctrl: true })], - negative: [createKey('f')], + command: Command.TOGGLE_SHELL_INPUT_FOCUS_IN, + positive: [createKey('tab')], + negative: [createKey('f', { ctrl: true }), createKey('f')], }, { command: Command.TOGGLE_YOLO, @@ -358,10 +297,6 @@ describe('keyMatchers', () => { keyMatchers[command](key), `Expected ${command} to match ${JSON.stringify(key)}`, ).toBe(true); - expect( - originalMatchers[command](key), - `Original matcher should also match ${JSON.stringify(key)}`, - ).toBe(true); }); negative.forEach((key) => { @@ -369,10 +304,6 @@ describe('keyMatchers', () => { keyMatchers[command](key), `Expected ${command} to NOT match ${JSON.stringify(key)}`, ).toBe(false); - expect( - originalMatchers[command](key), - `Original matcher should also NOT match ${JSON.stringify(key)}`, - ).toBe(false); }); }); }); From e9c9dd1d6723fde75c255e2ade5ed33280c6809c Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 12 Jan 2026 15:44:08 -0800 Subject: [PATCH 142/713] feat(core): support shipping built-in skills with the CLI (#16300) --- packages/core/src/skills/skillManager.test.ts | 43 +++++++++++++++++++ packages/core/src/skills/skillManager.ts | 15 +++++-- scripts/copy_bundle_assets.js | 11 +++++ scripts/copy_files.js | 9 ++++ 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/packages/core/src/skills/skillManager.test.ts b/packages/core/src/skills/skillManager.test.ts index 293115267c..ca3652a489 100644 --- a/packages/core/src/skills/skillManager.test.ts +++ b/packages/core/src/skills/skillManager.test.ts @@ -11,6 +11,15 @@ import * as path from 'node:path'; import { SkillManager } from './skillManager.js'; import { Storage } from '../config/storage.js'; import { type GeminiCLIExtension } from '../config/config.js'; +import { loadSkillsFromDir, type SkillDefinition } from './skillLoader.js'; + +vi.mock('./skillLoader.js', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + loadSkillsFromDir: vi.fn(actual.loadSkillsFromDir), + }; +}); describe('SkillManager', () => { let testRootDir: string; @@ -71,6 +80,8 @@ description: project-desc vi.spyOn(storage, 'getProjectSkillsDir').mockReturnValue(projectDir); const service = new SkillManager(); + // @ts-expect-error accessing private method for testing + vi.spyOn(service, 'discoverBuiltinSkills').mockResolvedValue(undefined); await service.discoverSkills(storage, [mockExtension]); const skills = service.getSkills(); @@ -126,6 +137,8 @@ description: project-desc vi.spyOn(storage, 'getProjectSkillsDir').mockReturnValue(projectDir); const service = new SkillManager(); + // @ts-expect-error accessing private method for testing + vi.spyOn(service, 'discoverBuiltinSkills').mockResolvedValue(undefined); await service.discoverSkills(storage, [mockExtension]); const skills = service.getSkills(); @@ -138,6 +151,34 @@ description: project-desc expect(service.getSkills()[0].description).toBe('user-desc'); }); + it('should discover built-in skills', async () => { + const service = new SkillManager(); + const mockBuiltinSkill: SkillDefinition = { + name: 'builtin-skill', + description: 'builtin-desc', + location: 'builtin-loc', + body: 'builtin-body', + }; + + vi.mocked(loadSkillsFromDir).mockImplementation(async (dir) => { + if (dir.endsWith('builtin')) { + return [{ ...mockBuiltinSkill }]; + } + return []; + }); + + const storage = new Storage('/dummy'); + vi.spyOn(storage, 'getProjectSkillsDir').mockReturnValue('/non-existent'); + vi.spyOn(Storage, 'getUserSkillsDir').mockReturnValue('/non-existent'); + + await service.discoverSkills(storage); + + const skills = service.getSkills(); + expect(skills).toHaveLength(1); + expect(skills[0].name).toBe('builtin-skill'); + expect(skills[0].isBuiltin).toBe(true); + }); + it('should filter disabled skills in getSkills but not in getAllSkills', async () => { const skillDir = path.join(testRootDir, 'skill1'); await fs.mkdir(skillDir, { recursive: true }); @@ -156,6 +197,8 @@ description: desc1 vi.spyOn(Storage, 'getUserSkillsDir').mockReturnValue('/non-existent'); const service = new SkillManager(); + // @ts-expect-error accessing private method for testing + vi.spyOn(service, 'discoverBuiltinSkills').mockResolvedValue(undefined); await service.discoverSkills(storage); service.setDisabledSkills(['skill1']); diff --git a/packages/core/src/skills/skillManager.ts b/packages/core/src/skills/skillManager.ts index 0279df5a65..6d301bd2f4 100644 --- a/packages/core/src/skills/skillManager.ts +++ b/packages/core/src/skills/skillManager.ts @@ -4,6 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as path from 'node:path'; +import { fileURLToPath } from 'node:url'; import { Storage } from '../config/storage.js'; import { type SkillDefinition, loadSkillsFromDir } from './skillLoader.js'; import type { GeminiCLIExtension } from '../config/config.js'; @@ -56,9 +58,16 @@ export class SkillManager { * Discovers built-in skills. */ private async discoverBuiltinSkills(): Promise { - // Built-in skills can be added here. - // For now, this is a placeholder for where built-in skills will be loaded from. - // They could be loaded from a specific directory within the package. + const __dirname = path.dirname(fileURLToPath(import.meta.url)); + const builtinDir = path.join(__dirname, 'builtin'); + + const builtinSkills = await loadSkillsFromDir(builtinDir); + + for (const skill of builtinSkills) { + skill.isBuiltin = true; + } + + this.addSkillsWithPrecedence(builtinSkills); } private addSkillsWithPrecedence(newSkills: SkillDefinition[]): void { diff --git a/scripts/copy_bundle_assets.js b/scripts/copy_bundle_assets.js index afd2b35ea4..d7cc87e8be 100644 --- a/scripts/copy_bundle_assets.js +++ b/scripts/copy_bundle_assets.js @@ -62,4 +62,15 @@ if (existsSync(docsSrc)) { console.log('Copied docs to bundle/docs/'); } +// 4. Copy Built-in Skills (packages/core/src/skills/builtin) +const builtinSkillsSrc = join(root, 'packages/core/src/skills/builtin'); +const builtinSkillsDest = join(bundleDir, 'builtin'); +if (existsSync(builtinSkillsSrc)) { + cpSync(builtinSkillsSrc, builtinSkillsDest, { + recursive: true, + dereference: true, + }); + console.log('Copied built-in skills to bundle/builtin/'); +} + console.log('Assets copied to bundle/'); diff --git a/scripts/copy_files.js b/scripts/copy_files.js index 4e32e61e00..fc612fd144 100644 --- a/scripts/copy_files.js +++ b/scripts/copy_files.js @@ -74,4 +74,13 @@ if (packageName === 'cli') { } } +// Copy built-in skills for the core package. +if (packageName === 'core') { + const builtinSkillsSource = path.join(sourceDir, 'skills', 'builtin'); + const builtinSkillsTarget = path.join(targetDir, 'skills', 'builtin'); + if (fs.existsSync(builtinSkillsSource)) { + fs.cpSync(builtinSkillsSource, builtinSkillsTarget, { recursive: true }); + } +} + console.log('Successfully copied files.'); From 6ef2a92233bca8e94a1603efaf929aca2943f257 Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Mon, 12 Jan 2026 23:59:22 +0000 Subject: [PATCH 143/713] Collect hardware details telemetry. (#16119) --- package-lock.json | 68 ++++++++------ packages/core/package.json | 1 + .../clearcut-logger/clearcut-logger.test.ts | 90 ++++++++++++++++++- .../clearcut-logger/clearcut-logger.ts | 62 ++++++++++++- .../clearcut-logger/event-metadata-key.ts | 12 +++ packages/core/src/telemetry/loggers.test.ts | 8 ++ packages/core/src/telemetry/loggers.ts | 2 +- 7 files changed, 213 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 908dc636f2..b9f71c339f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2501,7 +2501,6 @@ "integrity": "sha512-t54CUOsFMappY1Jbzb7fetWeO0n6K0k/4+/ZpkS+3Joz8I4VcvY9OiEBFRYISqaI2fq5sCiPtAjRDOzVYG8m+Q==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@octokit/auth-token": "^6.0.0", "@octokit/graphql": "^9.0.2", @@ -2682,7 +2681,6 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", "integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==", "license": "Apache-2.0", - "peer": true, "engines": { "node": ">=8.0.0" } @@ -2716,7 +2714,6 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-2.0.1.tgz", "integrity": "sha512-MaZk9SJIDgo1peKevlbhP6+IwIiNPNmswNL4AF0WaQJLbHXjr9SrZMgS12+iqr9ToV4ZVosCcc0f8Rg67LXjxw==", "license": "Apache-2.0", - "peer": true, "dependencies": { "@opentelemetry/semantic-conventions": "^1.29.0" }, @@ -3085,7 +3082,6 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-2.0.1.tgz", "integrity": "sha512-dZOB3R6zvBwDKnHDTB4X1xtMArB/d324VsbiPkX/Yu0Q8T2xceRthoIVFhJdvgVM2QhGVUyX9tzwiNxGtoBJUw==", "license": "Apache-2.0", - "peer": true, "dependencies": { "@opentelemetry/core": "2.0.1", "@opentelemetry/semantic-conventions": "^1.29.0" @@ -3119,7 +3115,6 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-metrics/-/sdk-metrics-2.0.1.tgz", "integrity": "sha512-wf8OaJoSnujMAHWR3g+/hGvNcsC16rf9s1So4JlMiFaFHiE4HpIA3oUh+uWZQ7CNuK8gVW/pQSkgoa5HkkOl0g==", "license": "Apache-2.0", - "peer": true, "dependencies": { "@opentelemetry/core": "2.0.1", "@opentelemetry/resources": "2.0.1" @@ -3172,7 +3167,6 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-trace-base/-/sdk-trace-base-2.0.1.tgz", "integrity": "sha512-xYLlvk/xdScGx1aEqvxLwf6sXQLXCjk3/1SQT9X9AoN5rXRhkdvIFShuNNmtTEPRBqcsMbS4p/gJLNI2wXaDuQ==", "license": "Apache-2.0", - "peer": true, "dependencies": { "@opentelemetry/core": "2.0.1", "@opentelemetry/resources": "2.0.1", @@ -4410,7 +4404,6 @@ "integrity": "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA==", "devOptional": true, "license": "MIT", - "peer": true, "dependencies": { "csstype": "^3.0.2" } @@ -4688,7 +4681,6 @@ "integrity": "sha512-6sMvZePQrnZH2/cJkwRpkT7DxoAWh+g6+GFRK6bV3YQo7ogi3SX5rgF6099r5Q53Ma5qeT7LGmOmuIutF4t3lA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.35.0", "@typescript-eslint/types": "8.35.0", @@ -5700,7 +5692,6 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -6145,7 +6136,8 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/array-includes": { "version": "3.1.9", @@ -7433,6 +7425,7 @@ "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", "license": "MIT", + "peer": true, "dependencies": { "safe-buffer": "5.2.1" }, @@ -8755,7 +8748,6 @@ "integrity": "sha512-GsGizj2Y1rCWDu6XoEekL3RLilp0voSePurjZIkxL3wlm5o5EC9VpgaP7lrCvjnkuLvzFBQWB3vWB3K5KQTveQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", @@ -9360,6 +9352,7 @@ "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz", "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==", "license": "MIT", + "peer": true, "engines": { "node": ">= 0.6" } @@ -9369,6 +9362,7 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "license": "MIT", + "peer": true, "dependencies": { "ms": "2.0.0" } @@ -9378,6 +9372,7 @@ "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", "license": "MIT", + "peer": true, "engines": { "node": ">= 0.8" } @@ -9631,6 +9626,7 @@ "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.1.tgz", "integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==", "license": "MIT", + "peer": true, "dependencies": { "debug": "2.6.9", "encodeurl": "~2.0.0", @@ -9649,6 +9645,7 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "license": "MIT", + "peer": true, "dependencies": { "ms": "2.0.0" } @@ -9657,13 +9654,15 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/finalhandler/node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", "license": "MIT", + "peer": true, "engines": { "node": ">= 0.8" } @@ -10947,7 +10946,6 @@ "resolved": "https://registry.npmjs.org/@jrichman/ink/-/ink-6.4.7.tgz", "integrity": "sha512-QHyxhNF5VonF5cRmdAJD/UPucB9nRx3FozWMjQrDGfBxfAL9lpyu72/MlFPgloS1TMTGsOt7YN6dTPPA6mh0Aw==", "license": "MIT", - "peer": true, "dependencies": { "@alcalzone/ansi-tokenize": "^0.2.1", "ansi-escapes": "^7.0.0", @@ -14136,7 +14134,8 @@ "version": "0.1.12", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/path-type": { "version": "3.0.0", @@ -14716,7 +14715,6 @@ "resolved": "https://registry.npmjs.org/react/-/react-19.2.0.tgz", "integrity": "sha512-tmbWg6W31tQLeB5cdIBOicJDJRR2KzXsV7uSK9iNfLWQ5bIZfxuPEHp7M8wiHyHnn0DD1i7w3Zmin0FtkrwoCQ==", "license": "MIT", - "peer": true, "engines": { "node": ">=0.10.0" } @@ -14727,7 +14725,6 @@ "integrity": "sha512-ePrwPfxAnB+7hgnEr8vpKxL9cmnp7F322t8oqcPshbIQQhDKgFDW4tjhF2wjVbdXF9O/nyuy3sQWd9JGpiLPvA==", "devOptional": true, "license": "MIT", - "peer": true, "dependencies": { "shell-quote": "^1.6.1", "ws": "^7" @@ -16547,6 +16544,32 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/systeminformation": { + "version": "5.30.2", + "resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.30.2.tgz", + "integrity": "sha512-Rrt5oFTWluUVuPlbtn3o9ja+nvjdF3Um4DG0KxqfYvpzcx7Q9plZBTjJiJy9mAouua4+OI7IUGBaG9Zyt9NgxA==", + "license": "MIT", + "os": [ + "darwin", + "linux", + "win32", + "freebsd", + "openbsd", + "netbsd", + "sunos", + "android" + ], + "bin": { + "systeminformation": "lib/cli.js" + }, + "engines": { + "node": ">=8.0.0" + }, + "funding": { + "type": "Buy me a coffee", + "url": "https://www.buymeacoffee.com/systeminfo" + } + }, "node_modules/table": { "version": "6.9.0", "resolved": "https://registry.npmjs.org/table/-/table-6.9.0.tgz", @@ -16972,7 +16995,6 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -17199,8 +17221,7 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "dev": true, - "license": "0BSD", - "peer": true + "license": "0BSD" }, "node_modules/tsx": { "version": "4.20.3", @@ -17208,7 +17229,6 @@ "integrity": "sha512-qjbnuR9Tr+FJOMBqJCW5ehvIo/buZq7vH7qD7JziU98h6l3qGy0a/yPFjwO+y0/T7GFpNgNAvEcPPVfyT8rrPQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "esbuild": "~0.25.0", "get-tsconfig": "^4.7.5" @@ -17392,7 +17412,6 @@ "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -17555,6 +17574,7 @@ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", "license": "MIT", + "peer": true, "engines": { "node": ">= 0.4.0" } @@ -17610,7 +17630,6 @@ "integrity": "sha512-BxAKBWmIbrDgrokdGZH1IgkIk/5mMHDreLDmCJ0qpyJaAteP8NvMhkwr/ZCQNqNH97bw/dANTE9PDzqwJghfMQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", @@ -17727,7 +17746,6 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -17741,7 +17759,6 @@ "integrity": "sha512-LUCP5ev3GURDysTWiP47wRRUpLKMOfPh+yKTx3kVIEiu5KOMeqzpnYNsKyOoVrULivR8tLcks4+lga33Whn90A==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/chai": "^5.2.2", "@vitest/expect": "3.2.4", @@ -18448,7 +18465,6 @@ "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", "license": "MIT", - "peer": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } @@ -18923,6 +18939,7 @@ "shell-quote": "^1.8.3", "simple-git": "^3.28.0", "strip-ansi": "^7.1.0", + "systeminformation": "^5.25.11", "tree-sitter-bash": "^0.25.0", "undici": "^7.10.0", "uuid": "^13.0.0", @@ -19013,7 +19030,6 @@ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, diff --git a/packages/core/package.json b/packages/core/package.json index 7bbeeed2fa..428066517b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -64,6 +64,7 @@ "shell-quote": "^1.8.3", "simple-git": "^3.28.0", "strip-ansi": "^7.1.0", + "systeminformation": "^5.25.11", "tree-sitter-bash": "^0.25.0", "undici": "^7.10.0", "uuid": "^13.0.0", diff --git a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts index 349fa182eb..8af85e88d4 100644 --- a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts +++ b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts @@ -26,6 +26,7 @@ import { makeFakeConfig } from '../../test-utils/config.js'; import { http, HttpResponse } from 'msw'; import { server } from '../../mocks/msw.js'; import { + StartSessionEvent, UserPromptEvent, makeChatCompressionEvent, ModelRoutingEvent, @@ -40,6 +41,9 @@ import { GIT_COMMIT_INFO, CLI_VERSION } from '../../generated/git-commit.js'; import { UserAccountManager } from '../../utils/userAccountManager.js'; import { InstallationManager } from '../../utils/installationManager.js'; +import si from 'systeminformation'; +import type { Systeminformation } from 'systeminformation'; + interface CustomMatchers { toHaveMetadataValue: ([key, value]: [EventMetadataKey, string]) => R; toHaveEventName: (name: EventNames) => R; @@ -111,8 +115,24 @@ expect.extend({ }, }); +vi.mock('node:os', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + cpus: vi.fn(() => [{ model: 'Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz' }]), + totalmem: vi.fn(() => 32 * 1024 * 1024 * 1024), + }; +}); + vi.mock('../../utils/userAccountManager.js'); vi.mock('../../utils/installationManager.js'); +vi.mock('systeminformation', () => ({ + default: { + graphics: vi.fn().mockResolvedValue({ + controllers: [{ model: 'Mock GPU' }], + }), + }, +})); const mockUserAccount = vi.mocked(UserAccountManager.prototype); const mockInstallMgr = vi.mocked(InstallationManager.prototype); @@ -204,6 +224,7 @@ describe('ClearcutLogger', () => { afterEach(() => { ClearcutLogger.clearInstance(); + TEST_ONLY.resetCachedGpuInfoForTesting(); vi.useRealTimers(); vi.restoreAllMocks(); }); @@ -238,7 +259,7 @@ describe('ClearcutLogger', () => { }); describe('createLogEvent', () => { - it('logs the total number of google accounts', () => { + it('logs the total number of google accounts', async () => { const { logger } = setup({ lifetimeGoogleAccounts: 9001, }); @@ -346,6 +367,73 @@ describe('ClearcutLogger', () => { }); }); + it('logs the GPU information (single GPU)', async () => { + vi.mocked(si.graphics).mockResolvedValueOnce({ + controllers: [{ model: 'Single GPU' }], + } as unknown as Systeminformation.GraphicsData); + const { logger, loggerConfig } = setup({}); + + await logger?.logStartSessionEvent(new StartSessionEvent(loggerConfig)); + + const event = logger?.createLogEvent(EventNames.API_ERROR, []); + + const gpuInfoEntry = event?.event_metadata[0].find( + (item) => item.gemini_cli_key === EventMetadataKey.GEMINI_CLI_GPU_INFO, + ); + expect(gpuInfoEntry).toBeDefined(); + expect(gpuInfoEntry?.value).toBe('Single GPU'); + }); + + it('logs multiple GPUs', async () => { + vi.mocked(si.graphics).mockResolvedValueOnce({ + controllers: [{ model: 'GPU 1' }, { model: 'GPU 2' }], + } as unknown as Systeminformation.GraphicsData); + const { logger, loggerConfig } = setup({}); + + await logger?.logStartSessionEvent(new StartSessionEvent(loggerConfig)); + + const event = logger?.createLogEvent(EventNames.API_ERROR, []); + const metadata = event?.event_metadata[0]; + + const gpuInfoEntry = metadata?.find( + (m) => m.gemini_cli_key === EventMetadataKey.GEMINI_CLI_GPU_INFO, + ); + expect(gpuInfoEntry?.value).toBe('GPU 1, GPU 2'); + }); + + it('logs NA when no GPUs are found', async () => { + vi.mocked(si.graphics).mockResolvedValueOnce({ + controllers: [], + } as unknown as Systeminformation.GraphicsData); + const { logger, loggerConfig } = setup({}); + + await logger?.logStartSessionEvent(new StartSessionEvent(loggerConfig)); + + const event = logger?.createLogEvent(EventNames.API_ERROR, []); + const metadata = event?.event_metadata[0]; + + const gpuInfoEntry = metadata?.find( + (m) => m.gemini_cli_key === EventMetadataKey.GEMINI_CLI_GPU_INFO, + ); + expect(gpuInfoEntry?.value).toBe('NA'); + }); + + it('logs FAILED when GPU detection fails', async () => { + vi.mocked(si.graphics).mockRejectedValueOnce( + new Error('Detection failed'), + ); + const { logger, loggerConfig } = setup({}); + + await logger?.logStartSessionEvent(new StartSessionEvent(loggerConfig)); + + const event = logger?.createLogEvent(EventNames.API_ERROR, []); + + expect(event?.event_metadata[0]).toContainEqual({ + gemini_cli_key: EventMetadataKey.GEMINI_CLI_GPU_INFO, + value: 'FAILED', + }); + }); + type SurfaceDetectionTestCase = { name: string; env: Record; diff --git a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts index f3fc7e1347..46e5828f70 100644 --- a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts +++ b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts @@ -5,6 +5,8 @@ */ import { createHash } from 'node:crypto'; +import * as os from 'node:os'; +import si from 'systeminformation'; import { HttpsProxyAgent } from 'https-proxy-agent'; import type { StartSessionEvent, @@ -57,6 +59,7 @@ import { isCloudShell, } from '../../ide/detect-ide.js'; import { debugLogger } from '../../utils/debugLogger.js'; +import { getErrorMessage } from '../../utils/errors.js'; export enum EventNames { START_SESSION = 'start_session', @@ -190,6 +193,35 @@ const MAX_EVENTS = 1000; */ const MAX_RETRY_EVENTS = 100; +const NO_GPU = 'NA'; + +let cachedGpuInfo: string | undefined; + +async function refreshGpuInfo(): Promise { + try { + const graphics = await si.graphics(); + if (graphics.controllers && graphics.controllers.length > 0) { + cachedGpuInfo = graphics.controllers.map((c) => c.model).join(', '); + } else { + cachedGpuInfo = NO_GPU; + } + } catch (error) { + cachedGpuInfo = 'FAILED'; + debugLogger.error( + 'Failed to get GPU information for telemetry', + getErrorMessage(error), + ); + } +} + +async function getGpuInfo(): Promise { + if (!cachedGpuInfo) { + await refreshGpuInfo(); + } + + return cachedGpuInfo ?? NO_GPU; +} + // Singleton class for batch posting log events to Clearcut. When a new event comes in, the elapsed time // is checked and events are flushed to Clearcut if at least a minute has passed since the last flush. export class ClearcutLogger { @@ -321,7 +353,6 @@ export class ClearcutLogger { const email = this.userAccountManager.getCachedGoogleAccount(); const surface = determineSurface(); const ghWorkflowName = determineGHWorkflowName(); - const baseMetadata: EventValue[] = [ ...data, { @@ -475,7 +506,7 @@ export class ClearcutLogger { return result; } - logStartSessionEvent(event: StartSessionEvent): void { + async logStartSessionEvent(event: StartSessionEvent): Promise { const data: EventValue[] = [ { gemini_cli_key: EventMetadataKey.GEMINI_CLI_START_SESSION_MODEL, @@ -564,6 +595,29 @@ export class ClearcutLogger { value: event.extension_ids.toString(), }, ]; + + // Add hardware information only to the start session event + const cpus = os.cpus(); + data.push( + { + gemini_cli_key: EventMetadataKey.GEMINI_CLI_CPU_INFO, + value: cpus[0].model, + }, + { + gemini_cli_key: EventMetadataKey.GEMINI_CLI_CPU_CORES, + value: cpus.length.toString(), + }, + { + gemini_cli_key: EventMetadataKey.GEMINI_CLI_RAM_TOTAL_GB, + value: (os.totalmem() / 1024 ** 3).toFixed(2).toString(), + }, + ); + + const gpuInfo = await getGpuInfo(); + data.push({ + gemini_cli_key: EventMetadataKey.GEMINI_CLI_GPU_INFO, + value: gpuInfo, + }); this.sessionData = data; // Flush after experiments finish loading from CCPA server @@ -1533,4 +1587,8 @@ export class ClearcutLogger { export const TEST_ONLY = { MAX_RETRY_EVENTS, MAX_EVENTS, + refreshGpuInfo, + resetCachedGpuInfoForTesting: () => { + cachedGpuInfo = undefined; + }, }; diff --git a/packages/core/src/telemetry/clearcut-logger/event-metadata-key.ts b/packages/core/src/telemetry/clearcut-logger/event-metadata-key.ts index e53ae71ae9..5f12b8442e 100644 --- a/packages/core/src/telemetry/clearcut-logger/event-metadata-key.ts +++ b/packages/core/src/telemetry/clearcut-logger/event-metadata-key.ts @@ -517,4 +517,16 @@ export enum EventMetadataKey { // Logs the exit code of the hook script (if applicable). GEMINI_CLI_HOOK_EXIT_CODE = 136, + + // Logs CPU information of user machine. + GEMINI_CLI_CPU_INFO = 137, + + // Logs number of CPU cores of user machine. + GEMINI_CLI_CPU_CORES = 138, + + // Logs GPU information of user machine. + GEMINI_CLI_GPU_INFO = 139, + + // Logs total RAM in GB of user machine. + GEMINI_CLI_RAM_TOTAL_GB = 140, } diff --git a/packages/core/src/telemetry/loggers.test.ts b/packages/core/src/telemetry/loggers.test.ts index c0023a1680..d584dc8ae7 100644 --- a/packages/core/src/telemetry/loggers.test.ts +++ b/packages/core/src/telemetry/loggers.test.ts @@ -111,6 +111,14 @@ import { UserAccountManager } from '../utils/userAccountManager.js'; import { InstallationManager } from '../utils/installationManager.js'; import { AgentTerminateMode } from '../agents/types.js'; +vi.mock('systeminformation', () => ({ + default: { + graphics: vi.fn().mockResolvedValue({ + controllers: [{ model: 'Mock GPU' }], + }), + }, +})); + describe('loggers', () => { const mockLogger = { emit: vi.fn(), diff --git a/packages/core/src/telemetry/loggers.ts b/packages/core/src/telemetry/loggers.ts index 7ab974213f..eef2fe6db7 100644 --- a/packages/core/src/telemetry/loggers.ts +++ b/packages/core/src/telemetry/loggers.ts @@ -79,7 +79,7 @@ export function logCliConfiguration( config: Config, event: StartSessionEvent, ): void { - ClearcutLogger.getInstance(config)?.logStartSessionEvent(event); + void ClearcutLogger.getInstance(config)?.logStartSessionEvent(event); bufferTelemetryEvent(() => { const logger = logs.getLogger(SERVICE_NAME); const logRecord: LogRecord = { From 548641c952a7abff9e474120dee9abc1c6ede1e3 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 12 Jan 2026 16:20:28 -0800 Subject: [PATCH 144/713] feat(agents): improve UI feedback and parser reliability (#16459) --- packages/cli/src/ui/commands/agentsCommand.ts | 8 ++++++ packages/core/src/agents/agentLoader.test.ts | 26 +++++++++++++++++++ packages/core/src/agents/cli-help-agent.ts | 4 ++- packages/core/src/skills/skillLoader.ts | 3 ++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/ui/commands/agentsCommand.ts b/packages/cli/src/ui/commands/agentsCommand.ts index d904e8ca78..690396b798 100644 --- a/packages/cli/src/ui/commands/agentsCommand.ts +++ b/packages/cli/src/ui/commands/agentsCommand.ts @@ -65,6 +65,14 @@ const agentsRefreshCommand: SlashCommand = { }; } + context.ui.addItem( + { + type: MessageType.INFO, + text: 'Refreshing agent registry...', + }, + Date.now(), + ); + await agentRegistry.reload(); return { diff --git a/packages/core/src/agents/agentLoader.test.ts b/packages/core/src/agents/agentLoader.test.ts index 0d6acf7de0..eb642a7eb5 100644 --- a/packages/core/src/agents/agentLoader.test.ts +++ b/packages/core/src/agents/agentLoader.test.ts @@ -198,6 +198,32 @@ agent_card_url: https://example.com/card agent_card_url: 'https://example.com/2', }); }); + + it('should parse frontmatter without a trailing newline', async () => { + const filePath = await writeAgentMarkdown(`--- +kind: remote +name: no-trailing-newline +agent_card_url: https://example.com/card +---`); + const result = await parseAgentMarkdown(filePath); + expect(result).toHaveLength(1); + expect(result[0]).toEqual({ + kind: 'remote', + name: 'no-trailing-newline', + agent_card_url: 'https://example.com/card', + }); + }); + + it('should throw AgentLoadError if agent name is not a valid slug', async () => { + const filePath = await writeAgentMarkdown(`--- +name: Invalid Name With Spaces +description: Test +--- +Body`); + await expect(parseAgentMarkdown(filePath)).rejects.toThrow( + /Name must be a valid slug/, + ); + }); }); describe('markdownToAgentDefinition', () => { diff --git a/packages/core/src/agents/cli-help-agent.ts b/packages/core/src/agents/cli-help-agent.ts index f774469ac3..cf65819252 100644 --- a/packages/core/src/agents/cli-help-agent.ts +++ b/packages/core/src/agents/cli-help-agent.ts @@ -80,7 +80,9 @@ export const CliHelpAgent = ( ? '### Sub-Agents (Local & Remote)\n' + "User defined sub-agents are defined in `.gemini/agents/` or `~/.gemini/agents/` as .md files. These files contain YAML frontmatter for metadata, and the Markdown body becomes the agent's system prompt (`system_prompt`). Always reference the types and properties outlined here directly when answering questions about sub-agents.\n" + '- **Local Agent:** `kind = "local"`, `name`, `description`, `system_prompt`, and optional `tools`, `model`, `temperate`, `max_turns`, `timeout_mins`.\n' + - '- **Remote Agent (A2A):** `kind = "remote"`, `name`, `agent_card_url`. Remote Agents do not use `system_prompt`. Multiple remote agents can be defined by using a YAML array at the top level of the frontmatter. **Note:** When users ask about "remote agents", they are referring to this Agent2Agent functionality, which is completely distinct from MCP servers.\n\n' + '- **Remote Agent (A2A):** `kind = "remote"`, `name`, `agent_card_url`. Remote Agents do not use `system_prompt`. Multiple remote agents can be defined by using a YAML array at the top level of the frontmatter. **Note:** When users ask about "remote agents", they are referring to this Agent2Agent functionality, which is completely distinct from MCP servers.\n' + + '- **Agent Names:** Must be valid slugs (lowercase letters, numbers, hyphens, and underscores only).\n' + + '- **User Commands:** The user can manage agents using `/agents list` to see all available agents and `/agents refresh` to reload the registry after modifying definition files. You (the agent) cannot run these commands.\n\n' : '') + '### Instructions\n' + "1. **Explore Documentation**: Use the `get_internal_docs` tool to find answers. If you don't know where to start, call `get_internal_docs()` without arguments to see the full list of available documentation files.\n" + diff --git a/packages/core/src/skills/skillLoader.ts b/packages/core/src/skills/skillLoader.ts index 354467734b..995d8160f0 100644 --- a/packages/core/src/skills/skillLoader.ts +++ b/packages/core/src/skills/skillLoader.ts @@ -29,7 +29,8 @@ export interface SkillDefinition { isBuiltin?: boolean; } -export const FRONTMATTER_REGEX = /^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)/; +export const FRONTMATTER_REGEX = + /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?/; /** * Discovers and loads all skills in the provided directory. From 8d3e93cdb0d7cec5ab62f8afaa5cf9b7797f00d5 Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Mon, 12 Jan 2026 16:28:10 -0800 Subject: [PATCH 145/713] Migrate keybindings (#16460) --- docs/cli/keyboard-shortcuts.md | 49 ++++++-------- packages/cli/src/config/keyBindings.ts | 65 +++++++++++++++++- packages/cli/src/ui/components/Help.tsx | 2 +- .../src/ui/components/shared/text-buffer.ts | 43 ++++-------- packages/cli/src/ui/constants/tips.ts | 2 +- packages/cli/src/ui/keyMatchers.test.ts | 67 ++++++++++++++++++- 6 files changed, 165 insertions(+), 63 deletions(-) diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index e6960bcde5..54defec914 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -15,19 +15,28 @@ available combinations. #### Cursor Movement -| Action | Keys | -| ----------------------------------------- | ---------------------- | -| Move the cursor to the start of the line. | `Ctrl + A`
`Home` | -| Move the cursor to the end of the line. | `Ctrl + E`
`End` | +| Action | Keys | +| ------------------------------------------- | ------------------------------------------------------------ | +| Move the cursor to the start of the line. | `Ctrl + A`
`Home` | +| Move the cursor to the end of the line. | `Ctrl + E`
`End` | +| Move the cursor one character to the left. | `Left Arrow (no Ctrl, no Cmd)`
`Ctrl + B` | +| Move the cursor one character to the right. | `Right Arrow (no Ctrl, no Cmd)`
`Ctrl + F` | +| Move the cursor one word to the left. | `Ctrl + Left Arrow`
`Cmd + Left Arrow`
`Cmd + B` | +| Move the cursor one word to the right. | `Ctrl + Right Arrow`
`Cmd + Right Arrow`
`Cmd + F` | #### Editing -| Action | Keys | -| ------------------------------------------------ | ----------------------------------------- | -| Delete from the cursor to the end of the line. | `Ctrl + K` | -| Delete from the cursor to the start of the line. | `Ctrl + U` | -| Clear all text in the input field. | `Ctrl + C` | -| Delete the previous word. | `Ctrl + Backspace`
`Cmd + Backspace` | +| Action | Keys | +| ------------------------------------------------ | -------------------------------------------------------------------------------------------- | +| Delete from the cursor to the end of the line. | `Ctrl + K` | +| Delete from the cursor to the start of the line. | `Ctrl + U` | +| Clear all text in the input field. | `Ctrl + C` | +| Delete the previous word. | `Ctrl + Backspace`
`Cmd + Backspace`
`Ctrl + ""`
`Cmd + ""`
`Ctrl + W` | +| Delete the next word. | `Ctrl + Delete`
`Cmd + Delete` | +| Delete the character to the left. | `Backspace`
`""`
`Ctrl + H` | +| Delete the character to the right. | `Delete`
`Ctrl + D` | +| Undo the most recent text edit. | `Ctrl + Z (no Shift)` | +| Redo the most recent undone text edit. | `Ctrl + Shift + Z` | #### Screen Control @@ -115,27 +124,11 @@ available combinations. ## Additional context-specific shortcuts -- `Option+M` (macOS): Entering `µ` with Option+M also toggles Markdown - rendering, matching `Cmd+M`. +- `Option+B/F/M` (macOS only): Are interpreted as `Cmd+B/F/M` even if your + terminal isn't configured to send Meta with Option. - `!` on an empty prompt: Enter or exit shell mode. - `\` (at end of a line) + `Enter`: Insert a newline without leaving single-line mode. -- `Ctrl+Delete` / `Meta+Delete`: Delete the word to the right of the cursor. -- `Ctrl+B` or `Left Arrow`: Move the cursor one character to the left while - editing text. -- `Ctrl+F` or `Right Arrow`: Move the cursor one character to the right. -- `Ctrl+D` or `Delete`: Remove the character immediately to the right of the - cursor. -- `Ctrl+H` or `Backspace`: Remove the character immediately to the left of the - cursor. -- `Ctrl+Left Arrow` / `Meta+Left Arrow` / `Meta+B`: Move one word to the left. -- `Ctrl+Right Arrow` / `Meta+Right Arrow` / `Meta+F`: Move one word to the - right. -- `Ctrl+W`: Delete the word to the left of the cursor (in addition to - `Ctrl+Backspace` / `Cmd+Backspace`). -- `Ctrl+Z` / `Ctrl+Shift+Z`: Undo or redo the most recent text edit. -- `Meta+Enter`: Open the current input in an external editor (alias for - `Ctrl+X`). - `Esc` pressed twice quickly: Clear the current input buffer. - `Up Arrow` / `Down Arrow`: When the cursor is at the top or bottom of a single-line input, navigate backward or forward through prompt history. diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index 06819e382a..ba7b2e10a3 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -64,6 +64,15 @@ export enum Command { TOGGLE_COPY_MODE = 'toggleCopyMode', TOGGLE_YOLO = 'toggleYolo', TOGGLE_AUTO_EDIT = 'toggleAutoEdit', + UNDO = 'undo', + REDO = 'redo', + MOVE_LEFT = 'moveLeft', + MOVE_RIGHT = 'moveRight', + MOVE_WORD_LEFT = 'moveWordLeft', + MOVE_WORD_RIGHT = 'moveWordRight', + DELETE_CHAR_LEFT = 'deleteCharLeft', + DELETE_CHAR_RIGHT = 'deleteCharRight', + DELETE_WORD_FORWARD = 'deleteWordForward', QUIT = 'quit', EXIT = 'exit', SHOW_MORE_LINES = 'showMoreLines', @@ -126,6 +135,37 @@ export const defaultKeyBindings: KeyBindingConfig = { [Command.DELETE_WORD_BACKWARD]: [ { key: 'backspace', ctrl: true }, { key: 'backspace', command: true }, + { sequence: '\x7f', ctrl: true }, + { sequence: '\x7f', command: true }, + { key: 'w', ctrl: true }, + ], + [Command.MOVE_LEFT]: [ + { key: 'left', ctrl: false, command: false }, + { key: 'b', ctrl: true }, + ], + [Command.MOVE_RIGHT]: [ + { key: 'right', ctrl: false, command: false }, + { key: 'f', ctrl: true }, + ], + [Command.MOVE_WORD_LEFT]: [ + { key: 'left', ctrl: true }, + { key: 'left', command: true }, + { key: 'b', command: true }, + ], + [Command.MOVE_WORD_RIGHT]: [ + { key: 'right', ctrl: true }, + { key: 'right', command: true }, + { key: 'f', command: true }, + ], + [Command.DELETE_CHAR_LEFT]: [ + { key: 'backspace' }, + { sequence: '\x7f' }, + { key: 'h', ctrl: true }, + ], + [Command.DELETE_CHAR_RIGHT]: [{ key: 'delete' }, { key: 'd', ctrl: true }], + [Command.DELETE_WORD_FORWARD]: [ + { key: 'delete', ctrl: true }, + { key: 'delete', command: true }, ], // Screen control @@ -208,6 +248,8 @@ export const defaultKeyBindings: KeyBindingConfig = { [Command.TOGGLE_COPY_MODE]: [{ key: 's', ctrl: true }], [Command.TOGGLE_YOLO]: [{ key: 'y', ctrl: true }], [Command.TOGGLE_AUTO_EDIT]: [{ key: 'tab', shift: true }], + [Command.UNDO]: [{ key: 'z', ctrl: true, shift: false }], + [Command.REDO]: [{ key: 'z', ctrl: true, shift: true }], [Command.QUIT]: [{ key: 'c', ctrl: true }], [Command.EXIT]: [{ key: 'd', ctrl: true }], [Command.SHOW_MORE_LINES]: [{ key: 's', ctrl: true }], @@ -242,7 +284,14 @@ export const commandCategories: readonly CommandCategory[] = [ }, { title: 'Cursor Movement', - commands: [Command.HOME, Command.END], + commands: [ + Command.HOME, + Command.END, + Command.MOVE_LEFT, + Command.MOVE_RIGHT, + Command.MOVE_WORD_LEFT, + Command.MOVE_WORD_RIGHT, + ], }, { title: 'Editing', @@ -251,6 +300,11 @@ export const commandCategories: readonly CommandCategory[] = [ Command.KILL_LINE_LEFT, Command.CLEAR_INPUT, Command.DELETE_WORD_BACKWARD, + Command.DELETE_WORD_FORWARD, + Command.DELETE_CHAR_LEFT, + Command.DELETE_CHAR_RIGHT, + Command.UNDO, + Command.REDO, ], }, { @@ -334,10 +388,19 @@ export const commandDescriptions: Readonly> = { [Command.ESCAPE]: 'Dismiss dialogs or cancel the current focus.', [Command.HOME]: 'Move the cursor to the start of the line.', [Command.END]: 'Move the cursor to the end of the line.', + [Command.MOVE_LEFT]: 'Move the cursor one character to the left.', + [Command.MOVE_RIGHT]: 'Move the cursor one character to the right.', + [Command.MOVE_WORD_LEFT]: 'Move the cursor one word to the left.', + [Command.MOVE_WORD_RIGHT]: 'Move the cursor one word to the right.', [Command.KILL_LINE_RIGHT]: 'Delete from the cursor to the end of the line.', [Command.KILL_LINE_LEFT]: 'Delete from the cursor to the start of the line.', [Command.CLEAR_INPUT]: 'Clear all text in the input field.', [Command.DELETE_WORD_BACKWARD]: 'Delete the previous word.', + [Command.DELETE_WORD_FORWARD]: 'Delete the next word.', + [Command.DELETE_CHAR_LEFT]: 'Delete the character to the left.', + [Command.DELETE_CHAR_RIGHT]: 'Delete the character to the right.', + [Command.UNDO]: 'Undo the most recent text edit.', + [Command.REDO]: 'Redo the most recent undone text edit.', [Command.CLEAR_SCREEN]: 'Clear the terminal screen and redraw the UI.', [Command.SCROLL_UP]: 'Scroll content up.', [Command.SCROLL_DOWN]: 'Scroll content down.', diff --git a/packages/cli/src/ui/components/Help.tsx b/packages/cli/src/ui/components/Help.tsx index 385f7edfa3..c32726475c 100644 --- a/packages/cli/src/ui/components/Help.tsx +++ b/packages/cli/src/ui/components/Help.tsx @@ -144,7 +144,7 @@ export const Help: React.FC = ({ commands }) => (
- {process.platform === 'darwin' ? 'Ctrl+X / Meta+Enter' : 'Ctrl+X'} + Ctrl+X {' '} - Open input in external editor diff --git a/packages/cli/src/ui/components/shared/text-buffer.ts b/packages/cli/src/ui/components/shared/text-buffer.ts index abcdbdc420..cdf689c24f 100644 --- a/packages/cli/src/ui/components/shared/text-buffer.ts +++ b/packages/cli/src/ui/components/shared/text-buffer.ts @@ -25,6 +25,7 @@ import { } from '../../utils/textUtils.js'; import { parsePastedPaths } from '../../utils/clipboardUtils.js'; import type { Key } from '../../contexts/KeypressContext.js'; +import { keyMatchers, Command } from '../../keyMatchers.js'; import type { VimAction } from './vim-buffer-actions.js'; import { handleVimAction } from './vim-buffer-actions.js'; @@ -2220,38 +2221,20 @@ export function useTextBuffer({ input === '\\r') // VSCode terminal represents shift + enter this way ) newline(); - else if (key.name === 'left' && !key.meta && !key.ctrl) move('left'); - else if (key.ctrl && key.name === 'b') move('left'); - else if (key.name === 'right' && !key.meta && !key.ctrl) move('right'); - else if (key.ctrl && key.name === 'f') move('right'); + else if (keyMatchers[Command.MOVE_LEFT](key)) move('left'); + else if (keyMatchers[Command.MOVE_RIGHT](key)) move('right'); else if (key.name === 'up') move('up'); else if (key.name === 'down') move('down'); - else if ((key.ctrl || key.meta) && key.name === 'left') move('wordLeft'); - else if (key.meta && key.name === 'b') move('wordLeft'); - else if ((key.ctrl || key.meta) && key.name === 'right') - move('wordRight'); - else if (key.meta && key.name === 'f') move('wordRight'); - else if (key.name === 'home') move('home'); - else if (key.ctrl && key.name === 'a') move('home'); - else if (key.name === 'end') move('end'); - else if (key.ctrl && key.name === 'e') move('end'); - else if (key.ctrl && key.name === 'w') deleteWordLeft(); - else if ( - (key.meta || key.ctrl) && - (key.name === 'backspace' || input === '\x7f') - ) - deleteWordLeft(); - else if ((key.meta || key.ctrl) && key.name === 'delete') - deleteWordRight(); - else if ( - key.name === 'backspace' || - input === '\x7f' || - (key.ctrl && key.name === 'h') - ) - backspace(); - else if (key.name === 'delete' || (key.ctrl && key.name === 'd')) del(); - else if (key.ctrl && !key.shift && key.name === 'z') undo(); - else if (key.ctrl && key.shift && key.name === 'z') redo(); + else if (keyMatchers[Command.MOVE_WORD_LEFT](key)) move('wordLeft'); + else if (keyMatchers[Command.MOVE_WORD_RIGHT](key)) move('wordRight'); + else if (keyMatchers[Command.HOME](key)) move('home'); + else if (keyMatchers[Command.END](key)) move('end'); + else if (keyMatchers[Command.DELETE_WORD_BACKWARD](key)) deleteWordLeft(); + else if (keyMatchers[Command.DELETE_WORD_FORWARD](key)) deleteWordRight(); + else if (keyMatchers[Command.DELETE_CHAR_LEFT](key)) backspace(); + else if (keyMatchers[Command.DELETE_CHAR_RIGHT](key)) del(); + else if (keyMatchers[Command.UNDO](key)) undo(); + else if (keyMatchers[Command.REDO](key)) redo(); else if (key.insertable) { insert(input, { paste: key.paste }); } diff --git a/packages/cli/src/ui/constants/tips.ts b/packages/cli/src/ui/constants/tips.ts index a18205ff36..7322718d06 100644 --- a/packages/cli/src/ui/constants/tips.ts +++ b/packages/cli/src/ui/constants/tips.ts @@ -112,7 +112,7 @@ export const INFORMATIVE_TIPS = [ 'Paste from your clipboard with Ctrl+V...', 'Undo text edits in the input with Ctrl+Z...', 'Redo undone text edits with Ctrl+Shift+Z...', - 'Open the current prompt in an external editor with Ctrl+X or Meta+Enter...', + 'Open the current prompt in an external editor with Ctrl+X...', 'In menus, move up/down with k/j or the arrow keys...', 'In menus, select an item by typing its number...', "If you're using an IDE, see the context with Ctrl+G...", diff --git a/packages/cli/src/ui/keyMatchers.test.ts b/packages/cli/src/ui/keyMatchers.test.ts index 8ddfd0371d..2cf98b7b9c 100644 --- a/packages/cli/src/ui/keyMatchers.test.ts +++ b/packages/cli/src/ui/keyMatchers.test.ts @@ -39,7 +39,7 @@ describe('keyMatchers', () => { // Cursor movement { command: Command.HOME, - positive: [createKey('a', { ctrl: true })], + positive: [createKey('a', { ctrl: true }), createKey('home')], negative: [ createKey('a'), createKey('a', { shift: true }), @@ -48,13 +48,41 @@ describe('keyMatchers', () => { }, { command: Command.END, - positive: [createKey('e', { ctrl: true })], + positive: [createKey('e', { ctrl: true }), createKey('end')], negative: [ createKey('e'), createKey('e', { shift: true }), createKey('a', { ctrl: true }), ], }, + { + command: Command.MOVE_LEFT, + positive: [createKey('left'), createKey('b', { ctrl: true })], + negative: [createKey('left', { ctrl: true }), createKey('b')], + }, + { + command: Command.MOVE_RIGHT, + positive: [createKey('right'), createKey('f', { ctrl: true })], + negative: [createKey('right', { ctrl: true }), createKey('f')], + }, + { + command: Command.MOVE_WORD_LEFT, + positive: [ + createKey('left', { ctrl: true }), + createKey('left', { meta: true }), + createKey('b', { meta: true }), + ], + negative: [createKey('left'), createKey('b', { ctrl: true })], + }, + { + command: Command.MOVE_WORD_RIGHT, + positive: [ + createKey('right', { ctrl: true }), + createKey('right', { meta: true }), + createKey('f', { meta: true }), + ], + negative: [createKey('right'), createKey('f', { ctrl: true })], + }, // Text deletion { @@ -72,14 +100,49 @@ describe('keyMatchers', () => { positive: [createKey('c', { ctrl: true })], negative: [createKey('c'), createKey('k', { ctrl: true })], }, + { + command: Command.DELETE_CHAR_LEFT, + positive: [ + createKey('backspace'), + { ...createKey('\x7f'), sequence: '\x7f' }, + createKey('h', { ctrl: true }), + ], + negative: [createKey('h'), createKey('x', { ctrl: true })], + }, + { + command: Command.DELETE_CHAR_RIGHT, + positive: [createKey('delete'), createKey('d', { ctrl: true })], + negative: [createKey('d'), createKey('x', { ctrl: true })], + }, { command: Command.DELETE_WORD_BACKWARD, positive: [ createKey('backspace', { ctrl: true }), createKey('backspace', { meta: true }), + { ...createKey('\x7f', { ctrl: true }), sequence: '\x7f' }, + { ...createKey('\x7f', { meta: true }), sequence: '\x7f' }, + createKey('w', { ctrl: true }), ], negative: [createKey('backspace'), createKey('delete', { ctrl: true })], }, + { + command: Command.DELETE_WORD_FORWARD, + positive: [ + createKey('delete', { ctrl: true }), + createKey('delete', { meta: true }), + ], + negative: [createKey('delete'), createKey('backspace', { ctrl: true })], + }, + { + command: Command.UNDO, + positive: [createKey('z', { ctrl: true, shift: false })], + negative: [createKey('z'), createKey('z', { ctrl: true, shift: true })], + }, + { + command: Command.REDO, + positive: [createKey('z', { ctrl: true, shift: true })], + negative: [createKey('z'), createKey('z', { ctrl: true, shift: false })], + }, // Screen control { From c572b9e9ac686eed1e434b60c7a0c2461043a1e9 Mon Sep 17 00:00:00 2001 From: Sandy Tao Date: Tue, 13 Jan 2026 09:12:35 +0800 Subject: [PATCH 146/713] feat(cli): cleanup activity logs alongside session files (#16399) --- packages/cli/src/utils/sessionCleanup.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/cli/src/utils/sessionCleanup.ts b/packages/cli/src/utils/sessionCleanup.ts index 3cdce025c9..50b788d215 100644 --- a/packages/cli/src/utils/sessionCleanup.ts +++ b/packages/cli/src/utils/sessionCleanup.ts @@ -86,6 +86,18 @@ export async function cleanupExpiredSessions( const sessionPath = path.join(chatsDir, sessionToDelete.fileName); await fs.unlink(sessionPath); + // ALSO cleanup Activity logs in the project logs directory + const sessionId = sessionToDelete.sessionInfo?.id; + if (sessionId) { + const logsDir = path.join(config.storage.getProjectTempDir(), 'logs'); + const logPath = path.join(logsDir, `session-${sessionId}.jsonl`); + try { + await fs.unlink(logPath); + } catch { + /* ignore if log doesn't exist */ + } + } + if (config.getDebugMode()) { if (sessionToDelete.sessionInfo === null) { debugLogger.debug( From 2fc61685a32eaa58477ba46d14ed1465ce7c356b Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 12 Jan 2026 17:18:14 -0800 Subject: [PATCH 147/713] feat(cli): implement dynamic terminal tab titles for CLI status (#16378) --- docs/cli/settings.md | 3 +- docs/get-started/configuration.md | 9 +- packages/cli/src/config/settingsSchema.ts | 14 +- packages/cli/src/gemini.tsx | 12 +- packages/cli/src/ui/AppContainer.test.tsx | 189 +++++++++++++---- packages/cli/src/ui/AppContainer.tsx | 50 +++-- packages/cli/src/ui/constants.ts | 1 + packages/cli/src/utils/windowTitle.test.ts | 226 +++++++++++++++++---- packages/cli/src/utils/windowTitle.ts | 105 +++++++++- schemas/settings.schema.json | 13 +- 10 files changed, 508 insertions(+), 114 deletions(-) diff --git a/docs/cli/settings.md b/docs/cli/settings.md index f0df2d48c0..ebd7c05fe0 100644 --- a/docs/cli/settings.md +++ b/docs/cli/settings.md @@ -42,7 +42,8 @@ they appear in the UI. | UI Label | Setting | Description | Default | | ------------------------------ | ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | | Hide Window Title | `ui.hideWindowTitle` | Hide the window title bar | `false` | -| Show Status in Title | `ui.showStatusInTitle` | Show Gemini CLI status and thoughts in the terminal window title | `false` | +| Show Thoughts in Title | `ui.showStatusInTitle` | Show Gemini CLI model thoughts in the terminal window title during the working phase | `false` | +| Dynamic Window Title | `ui.dynamicWindowTitle` | Update the terminal window title with current status icons (Ready: ◇, Action Required: ✋, Working: ✦) | `true` | | Show Home Directory Warning | `ui.showHomeDirectoryWarning` | Show a warning when running Gemini CLI in the home directory. | `true` | | Hide Tips | `ui.hideTips` | Hide helpful tips in the UI | `false` | | Hide Banner | `ui.hideBanner` | Hide the application banner | `false` | diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 2ec3edc09b..4dc17aa548 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -180,10 +180,15 @@ their corresponding top-level category object in your `settings.json` file. - **Requires restart:** Yes - **`ui.showStatusInTitle`** (boolean): - - **Description:** Show Gemini CLI status and thoughts in the terminal window - title + - **Description:** Show Gemini CLI model thoughts in the terminal window title + during the working phase - **Default:** `false` +- **`ui.dynamicWindowTitle`** (boolean): + - **Description:** Update the terminal window title with current status icons + (Ready: ◇, Action Required: ✋, Working: ✦) + - **Default:** `true` + - **`ui.showHomeDirectoryWarning`** (boolean): - **Description:** Show a warning when running Gemini CLI in the home directory. diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index 7b29ff3d62..390c0ad403 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -376,12 +376,22 @@ const SETTINGS_SCHEMA = { }, showStatusInTitle: { type: 'boolean', - label: 'Show Status in Title', + label: 'Show Thoughts in Title', category: 'UI', requiresRestart: false, default: false, description: - 'Show Gemini CLI status and thoughts in the terminal window title', + 'Show Gemini CLI model thoughts in the terminal window title during the working phase', + showInDialog: true, + }, + dynamicWindowTitle: { + type: 'boolean', + label: 'Dynamic Window Title', + category: 'UI', + requiresRestart: false, + default: true, + description: + 'Update the terminal window title with current status icons (Ready: ◇, Action Required: ✋, Working: ✦)', showInDialog: true, }, showHomeDirectoryWarning: { diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index 53153c2944..7a100678df 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -75,9 +75,10 @@ import { checkForUpdates } from './ui/utils/updateCheck.js'; import { handleAutoUpdate } from './utils/handleAutoUpdate.js'; import { appEvents, AppEvent } from './utils/events.js'; import { SessionSelector } from './utils/sessionUtils.js'; -import { computeWindowTitle } from './utils/windowTitle.js'; import { SettingsContext } from './ui/contexts/SettingsContext.js'; import { MouseProvider } from './ui/contexts/MouseContext.js'; +import { StreamingState } from './ui/types.js'; +import { computeTerminalTitle } from './utils/windowTitle.js'; import { SessionStatsProvider } from './ui/contexts/SessionContext.js'; import { VimModeProvider } from './ui/contexts/VimModeContext.js'; @@ -711,7 +712,14 @@ export async function main() { function setWindowTitle(title: string, settings: LoadedSettings) { if (!settings.merged.ui?.hideWindowTitle) { - const windowTitle = computeWindowTitle(title); + // Initial state before React loop starts + const windowTitle = computeTerminalTitle({ + streamingState: StreamingState.Idle, + isConfirming: false, + folderName: title, + showThoughts: !!settings.merged.ui?.showStatusInTitle, + useDynamicTitle: settings.merged.ui?.dynamicWindowTitle ?? true, + }); writeToStdout(`\x1b]2;${windowTitle}\x07`); process.on('exit', () => { diff --git a/packages/cli/src/ui/AppContainer.test.tsx b/packages/cli/src/ui/AppContainer.test.tsx index 939045d44a..be0ba688b6 100644 --- a/packages/cli/src/ui/AppContainer.test.tsx +++ b/packages/cli/src/ui/AppContainer.test.tsx @@ -250,20 +250,13 @@ describe('AppContainer State Management', () => { beforeEach(() => { vi.clearAllMocks(); + mockIdeClient.getInstance.mockReturnValue(new Promise(() => {})); + // Initialize mock stdout for terminal title tests + mocks.mockStdout.write.mockClear(); - // Mock computeWindowTitle function to centralize title logic testing - vi.mock('../utils/windowTitle.js', async () => ({ - computeWindowTitle: vi.fn( - (folderName: string) => - // Default behavior: return "Gemini - {folderName}" unless CLI_TITLE is set - process.env['CLI_TITLE'] || `Gemini - ${folderName}`, - ), - })); - capturedUIState = null!; - capturedUIActions = null!; // **Provide a default return value for EVERY mocked hook.** mockedUseQuotaAndFallback.mockReturnValue({ @@ -413,6 +406,7 @@ describe('AppContainer State Management', () => { afterEach(() => { cleanup(); + vi.restoreAllMocks(); }); describe('Basic Rendering', () => { @@ -995,7 +989,7 @@ describe('AppContainer State Management', () => { expect(stdout).toBe(mocks.mockStdout); }); - it('should not update terminal title when showStatusInTitle is false', () => { + it('should update terminal title with Working… when showStatusInTitle is false', () => { // Arrange: Set up mock settings with showStatusInTitle disabled const mockSettingsWithShowStatusFalse = { ...mockSettings, @@ -1009,17 +1003,71 @@ describe('AppContainer State Management', () => { }, } as unknown as LoadedSettings; + // Mock the streaming state as Active + mockedUseGeminiStream.mockReturnValue({ + streamingState: 'responding', + submitQuery: vi.fn(), + initError: null, + pendingHistoryItems: [], + thought: { subject: 'Some thought' }, + cancelOngoingRequest: vi.fn(), + }); + // Act: Render the container const { unmount } = renderAppContainer({ settings: mockSettingsWithShowStatusFalse, }); - // Assert: Check that no title-related writes occurred + // Assert: Check that title was updated with "Working…" const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => call[0].includes('\x1b]2;'), ); - expect(titleWrites).toHaveLength(0); + expect(titleWrites).toHaveLength(1); + expect(titleWrites[0][0]).toBe( + `\x1b]2;${'✦ Working… (workspace)'.padEnd(80, ' ')}\x07`, + ); + unmount(); + }); + + it('should use legacy terminal title when dynamicWindowTitle is false', () => { + // Arrange: Set up mock settings with dynamicWindowTitle disabled + const mockSettingsWithDynamicTitleFalse = { + ...mockSettings, + merged: { + ...mockSettings.merged, + ui: { + ...mockSettings.merged.ui, + dynamicWindowTitle: false, + hideWindowTitle: false, + }, + }, + } as unknown as LoadedSettings; + + // Mock the streaming state + mockedUseGeminiStream.mockReturnValue({ + streamingState: 'responding', + submitQuery: vi.fn(), + initError: null, + pendingHistoryItems: [], + thought: { subject: 'Some thought' }, + cancelOngoingRequest: vi.fn(), + }); + + // Act: Render the container + const { unmount } = renderAppContainer({ + settings: mockSettingsWithDynamicTitleFalse, + }); + + // Assert: Check that legacy title was used + const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => + call[0].includes('\x1b]2;'), + ); + + expect(titleWrites).toHaveLength(1); + expect(titleWrites[0][0]).toBe( + `\x1b]2;${'Gemini CLI (workspace)'.padEnd(80, ' ')}\x07`, + ); unmount(); }); @@ -1081,14 +1129,14 @@ describe('AppContainer State Management', () => { settings: mockSettingsWithTitleEnabled, }); - // Assert: Check that title was updated with thought subject + // Assert: Check that title was updated with thought subject and suffix const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => call[0].includes('\x1b]2;'), ); expect(titleWrites).toHaveLength(1); expect(titleWrites[0][0]).toBe( - `\x1b]2;${thoughtSubject.padEnd(80, ' ')}\x07`, + `\x1b]2;${`✦ ${thoughtSubject} (workspace)`.padEnd(80, ' ')}\x07`, ); unmount(); }); @@ -1129,12 +1177,12 @@ describe('AppContainer State Management', () => { expect(titleWrites).toHaveLength(1); expect(titleWrites[0][0]).toBe( - `\x1b]2;${'Gemini - workspace'.padEnd(80, ' ')}\x07`, + `\x1b]2;${'◇ Ready (workspace)'.padEnd(80, ' ')}\x07`, ); unmount(); }); - it('should update terminal title when in WaitingForConfirmation state with thought subject', () => { + it('should update terminal title when in WaitingForConfirmation state with thought subject', async () => { // Arrange: Set up mock settings with showStatusInTitle enabled const mockSettingsWithTitleEnabled = { ...mockSettings, @@ -1151,7 +1199,7 @@ describe('AppContainer State Management', () => { // Mock the streaming state and thought const thoughtSubject = 'Confirm tool execution'; mockedUseGeminiStream.mockReturnValue({ - streamingState: 'waitingForConfirmation', + streamingState: 'waiting_for_confirmation', submitQuery: vi.fn(), initError: null, pendingHistoryItems: [], @@ -1160,8 +1208,12 @@ describe('AppContainer State Management', () => { }); // Act: Render the container - const { unmount } = renderAppContainer({ - settings: mockSettingsWithTitleEnabled, + let unmount: () => void; + await act(async () => { + const result = renderAppContainer({ + settings: mockSettingsWithTitleEnabled, + }); + unmount = result.unmount; }); // Assert: Check that title was updated with confirmation text @@ -1171,9 +1223,74 @@ describe('AppContainer State Management', () => { expect(titleWrites).toHaveLength(1); expect(titleWrites[0][0]).toBe( - `\x1b]2;${thoughtSubject.padEnd(80, ' ')}\x07`, + `\x1b]2;${'✋ Action Required (workspace)'.padEnd(80, ' ')}\x07`, ); - unmount(); + unmount!(); + }); + + describe('Shell Focus Action Required', () => { + beforeEach(() => { + vi.useFakeTimers(); + }); + + afterEach(() => { + vi.useRealTimers(); + }); + + it('should show Action Required in title after a delay when shell is awaiting focus', async () => { + // Arrange: Set up mock settings with showStatusInTitle enabled + const mockSettingsWithTitleEnabled = { + ...mockSettings, + merged: { + ...mockSettings.merged, + ui: { + ...mockSettings.merged.ui, + showStatusInTitle: true, + hideWindowTitle: false, + }, + }, + } as unknown as LoadedSettings; + + // Mock an active shell pty but not focused + mockedUseGeminiStream.mockReturnValue({ + streamingState: 'responding', + submitQuery: vi.fn(), + initError: null, + pendingHistoryItems: [], + thought: { subject: 'Executing shell command' }, + cancelOngoingRequest: vi.fn(), + activePtyId: 'pty-1', + }); + + // Act: Render the container (embeddedShellFocused is false by default in state) + const { unmount } = renderAppContainer({ + settings: mockSettingsWithTitleEnabled, + }); + + // Initially it should show the working status + const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => + call[0].includes('\x1b]2;'), + ); + expect(titleWrites[titleWrites.length - 1][0]).toContain( + '✦ Executing shell command', + ); + + // Fast-forward time by 31 seconds + await act(async () => { + vi.advanceTimersByTime(31000); + }); + + // Now it should show Action Required + await waitFor(() => { + const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => + call[0].includes('\x1b]2;'), + ); + const lastTitle = titleWrites[titleWrites.length - 1][0]; + expect(lastTitle).toContain('✋ Action Required'); + }); + + unmount(); + }); }); it('should pad title to exactly 80 characters', () => { @@ -1213,12 +1330,9 @@ describe('AppContainer State Management', () => { expect(titleWrites).toHaveLength(1); const calledWith = titleWrites[0][0]; - const expectedTitle = shortTitle.padEnd(80, ' '); - - expect(calledWith).toContain(shortTitle); - expect(calledWith).toContain('\x1b]2;'); - expect(calledWith).toContain('\x07'); - expect(calledWith).toBe('\x1b]2;' + expectedTitle + '\x07'); + const expectedTitle = `✦ ${shortTitle} (workspace)`.padEnd(80, ' '); + const expectedEscapeSequence = `\x1b]2;${expectedTitle}\x07`; + expect(calledWith).toBe(expectedEscapeSequence); unmount(); }); @@ -1258,20 +1372,20 @@ describe('AppContainer State Management', () => { ); expect(titleWrites).toHaveLength(1); - const expectedEscapeSequence = `\x1b]2;${title.padEnd(80, ' ')}\x07`; + const expectedEscapeSequence = `\x1b]2;${`✦ ${title} (workspace)`.padEnd(80, ' ')}\x07`; expect(titleWrites[0][0]).toBe(expectedEscapeSequence); unmount(); }); it('should use CLI_TITLE environment variable when set', () => { - // Arrange: Set up mock settings with showStatusInTitle enabled - const mockSettingsWithTitleEnabled = { + // Arrange: Set up mock settings with showStatusInTitle disabled (so it shows suffix) + const mockSettingsWithTitleDisabled = { ...mockSettings, merged: { ...mockSettings.merged, ui: { ...mockSettings.merged.ui, - showStatusInTitle: true, + showStatusInTitle: false, hideWindowTitle: false, }, }, @@ -1280,9 +1394,9 @@ describe('AppContainer State Management', () => { // Mock CLI_TITLE environment variable vi.stubEnv('CLI_TITLE', 'Custom Gemini Title'); - // Mock the streaming state as Idle with no thought + // Mock the streaming state mockedUseGeminiStream.mockReturnValue({ - streamingState: 'idle', + streamingState: 'responding', submitQuery: vi.fn(), initError: null, pendingHistoryItems: [], @@ -1292,7 +1406,7 @@ describe('AppContainer State Management', () => { // Act: Render the container const { unmount } = renderAppContainer({ - settings: mockSettingsWithTitleEnabled, + settings: mockSettingsWithTitleDisabled, }); // Assert: Check that title was updated with CLI_TITLE value @@ -1302,7 +1416,7 @@ describe('AppContainer State Management', () => { expect(titleWrites).toHaveLength(1); expect(titleWrites[0][0]).toBe( - `\x1b]2;${'Custom Gemini Title'.padEnd(80, ' ')}\x07`, + `\x1b]2;${'✦ Working… (Custom Gemini Title)'.padEnd(80, ' ')}\x07`, ); unmount(); }); @@ -1315,6 +1429,7 @@ describe('AppContainer State Management', () => { afterEach(() => { vi.useRealTimers(); + vi.restoreAllMocks(); }); it('should set and clear the queue error message after a timeout', async () => { @@ -1483,6 +1598,7 @@ describe('AppContainer State Management', () => { afterEach(() => { vi.useRealTimers(); + vi.restoreAllMocks(); }); describe('CTRL+C', () => { @@ -1620,6 +1736,7 @@ describe('AppContainer State Management', () => { afterEach(() => { vi.useRealTimers(); + vi.restoreAllMocks(); }); describe.each([ diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index 93fef00dbb..dbfdf58681 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -81,7 +81,7 @@ import { calculateMainAreaWidth } from './utils/ui-sizing.js'; import ansiEscapes from 'ansi-escapes'; import * as fs from 'node:fs'; import { basename } from 'node:path'; -import { computeWindowTitle } from '../utils/windowTitle.js'; +import { computeTerminalTitle } from '../utils/windowTitle.js'; import { useTextBuffer } from './components/shared/text-buffer.js'; import { useLogger } from './hooks/useLogger.js'; import { useGeminiStream } from './hooks/useGeminiStream.js'; @@ -125,8 +125,10 @@ import { useHookDisplayState } from './hooks/useHookDisplayState.js'; import { WARNING_PROMPT_DURATION_MS, QUEUE_ERROR_DISPLAY_DURATION_MS, + SHELL_ACTION_REQUIRED_TITLE_DELAY_MS, } from './constants.js'; import { LoginWithGoogleRestartDialog } from './auth/LoginWithGoogleRestartDialog.js'; +import { useInactivityTimer } from './hooks/useInactivityTimer.js'; function isToolExecuting(pendingHistoryItems: HistoryItemWithoutId[]) { return pendingHistoryItems.some((item) => { @@ -278,9 +280,6 @@ export const AppContainer = (props: AppContainerProps) => { const mainControlsRef = useRef(null); // For performance profiling only const rootUiRef = useRef(null); - const originalTitleRef = useRef( - computeWindowTitle(basename(config.getTargetDir())), - ); const lastTitleRef = useRef(null); const staticExtraHeight = 3; @@ -828,6 +827,13 @@ Logging in with Google... Restarting Gemini CLI to continue. lastOutputTimeRef.current = lastOutputTime; }, [lastOutputTime]); + const isShellAwaitingFocus = !!activePtyId && !embeddedShellFocused; + const showShellActionRequired = useInactivityTimer( + isShellAwaitingFocus, + isShellAwaitingFocus, + SHELL_ACTION_REQUIRED_TITLE_DELAY_MS, + ); + // Auto-accept indicator const showAutoAcceptIndicator = useAutoAcceptIndicator({ config, @@ -1338,25 +1344,20 @@ Logging in with Google... Restarting Gemini CLI to continue. // Update terminal title with Gemini CLI status and thoughts useEffect(() => { - // Respect both showStatusInTitle and hideWindowTitle settings - if ( - !settings.merged.ui?.showStatusInTitle || - settings.merged.ui?.hideWindowTitle - ) - return; + // Respect hideWindowTitle settings + if (settings.merged.ui?.hideWindowTitle) return; - let title; - if (streamingState === StreamingState.Idle) { - title = originalTitleRef.current; - } else { - const statusText = thought?.subject - ?.replace(/[\r\n]+/g, ' ') - .substring(0, 80); - title = statusText || originalTitleRef.current; - } - - // Pad the title to a fixed width to prevent taskbar icon resizing. - const paddedTitle = title.padEnd(80, ' '); + const paddedTitle = computeTerminalTitle({ + streamingState, + thoughtSubject: thought?.subject, + isConfirming: + !!shellConfirmationRequest || + !!confirmationRequest || + showShellActionRequired, + folderName: basename(config.getTargetDir()), + showThoughts: !!settings.merged.ui?.showStatusInTitle, + useDynamicTitle: settings.merged.ui?.dynamicWindowTitle ?? true, + }); // Only update the title if it's different from the last value we set if (lastTitleRef.current !== paddedTitle) { @@ -1367,8 +1368,13 @@ Logging in with Google... Restarting Gemini CLI to continue. }, [ streamingState, thought, + shellConfirmationRequest, + confirmationRequest, + showShellActionRequired, settings.merged.ui?.showStatusInTitle, + settings.merged.ui?.dynamicWindowTitle, settings.merged.ui?.hideWindowTitle, + config, stdout, ]); diff --git a/packages/cli/src/ui/constants.ts b/packages/cli/src/ui/constants.ts index e27f3c3bbe..b211c9ce8d 100644 --- a/packages/cli/src/ui/constants.ts +++ b/packages/cli/src/ui/constants.ts @@ -31,3 +31,4 @@ export const MAX_MCP_RESOURCES_TO_SHOW = 10; export const WARNING_PROMPT_DURATION_MS = 1000; export const QUEUE_ERROR_DISPLAY_DURATION_MS = 3000; +export const SHELL_ACTION_REQUIRED_TITLE_DELAY_MS = 30000; diff --git a/packages/cli/src/utils/windowTitle.test.ts b/packages/cli/src/utils/windowTitle.test.ts index eed30f6768..c25f151f83 100644 --- a/packages/cli/src/utils/windowTitle.test.ts +++ b/packages/cli/src/utils/windowTitle.test.ts @@ -4,56 +4,210 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { describe, it, expect, vi, beforeEach } from 'vitest'; -import { computeWindowTitle } from './windowTitle.js'; - -describe('computeWindowTitle', () => { - let originalEnv: NodeJS.ProcessEnv; - - beforeEach(() => { - originalEnv = process.env; - vi.stubEnv('CLI_TITLE', undefined); - }); +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { computeTerminalTitle } from './windowTitle.js'; +import { StreamingState } from '../ui/types.js'; +describe('computeTerminalTitle', () => { afterEach(() => { - process.env = originalEnv; + vi.unstubAllEnvs(); }); - it('should use default Gemini title when CLI_TITLE is not set', () => { - const result = computeWindowTitle('my-project'); - expect(result).toBe('Gemini - my-project'); + it.each([ + { + description: 'idle state title with folder name', + args: { + streamingState: StreamingState.Idle, + isConfirming: false, + folderName: 'my-project', + showThoughts: false, + useDynamicTitle: true, + }, + expected: '◇ Ready (my-project)', + }, + { + description: 'legacy title when useDynamicTitle is false', + args: { + streamingState: StreamingState.Responding, + isConfirming: false, + folderName: 'my-project', + showThoughts: true, + useDynamicTitle: false, + }, + expected: 'Gemini CLI (my-project)'.padEnd(80, ' '), + exact: true, + }, + { + description: + 'active state title with "Working…" when thoughts are disabled', + args: { + streamingState: StreamingState.Responding, + thoughtSubject: 'Reading files', + isConfirming: false, + folderName: 'my-project', + showThoughts: false, + useDynamicTitle: true, + }, + expected: '✦ Working… (my-project)', + }, + { + description: + 'active state title with thought subject and suffix when thoughts are short enough', + args: { + streamingState: StreamingState.Responding, + thoughtSubject: 'Short thought', + isConfirming: false, + folderName: 'my-project', + showThoughts: true, + useDynamicTitle: true, + }, + expected: '✦ Short thought (my-project)', + }, + { + description: + 'fallback active title with suffix if no thought subject is provided even when thoughts are enabled', + args: { + streamingState: StreamingState.Responding, + thoughtSubject: undefined, + isConfirming: false, + folderName: 'my-project', + showThoughts: true, + useDynamicTitle: true, + }, + expected: '✦ Working… (my-project)'.padEnd(80, ' '), + exact: true, + }, + { + description: 'action required state when confirming', + args: { + streamingState: StreamingState.Idle, + isConfirming: true, + folderName: 'my-project', + showThoughts: false, + useDynamicTitle: true, + }, + expected: '✋ Action Required (my-project)', + }, + ])('should return $description', ({ args, expected, exact }) => { + const title = computeTerminalTitle(args); + if (exact) { + expect(title).toBe(expected); + } else { + expect(title).toContain(expected); + } + expect(title.length).toBe(80); }); - it('should use CLI_TITLE environment variable when set', () => { - vi.stubEnv('CLI_TITLE', 'Custom Title'); - const result = computeWindowTitle('my-project'); - expect(result).toBe('Custom Title'); + it('should return active state title with thought subject and NO suffix when thoughts are very long', () => { + const longThought = 'A'.repeat(70); + const title = computeTerminalTitle({ + streamingState: StreamingState.Responding, + thoughtSubject: longThought, + isConfirming: false, + folderName: 'my-project', + showThoughts: true, + useDynamicTitle: true, + }); + + expect(title).not.toContain('(my-project)'); + expect(title).toContain('✦ AAAAAAAAAAAAAAAA'); + expect(title.length).toBe(80); }); - it('should remove control characters from title', () => { - vi.stubEnv('CLI_TITLE', 'Title\x1b[31m with \x07 control chars'); - const result = computeWindowTitle('my-project'); - // The \x1b[31m (ANSI escape sequence) and \x07 (bell character) should be removed - expect(result).toBe('Title[31m with control chars'); + it('should truncate long thought subjects when thoughts are enabled', () => { + const longThought = 'A'.repeat(100); + const title = computeTerminalTitle({ + streamingState: StreamingState.Responding, + thoughtSubject: longThought, + isConfirming: false, + folderName: 'my-project', + showThoughts: true, + useDynamicTitle: true, + }); + + expect(title.length).toBe(80); + expect(title).toContain('…'); + expect(title.trimEnd().length).toBe(80); }); - it('should handle folder names with control characters', () => { - const result = computeWindowTitle('project\x07name'); - expect(result).toBe('Gemini - projectname'); + it('should strip control characters from the title', () => { + const title = computeTerminalTitle({ + streamingState: StreamingState.Responding, + thoughtSubject: 'BadTitle\x00 With\x07Control\x1BChars', + isConfirming: false, + folderName: 'my-project', + showThoughts: true, + useDynamicTitle: true, + }); + + expect(title).toContain('BadTitle WithControlChars'); + expect(title).not.toContain('\x00'); + expect(title).not.toContain('\x07'); + expect(title).not.toContain('\x1B'); + expect(title.length).toBe(80); }); - it('should handle empty folder name', () => { - const result = computeWindowTitle(''); - expect(result).toBe('Gemini - '); + it('should prioritize CLI_TITLE environment variable over folder name when thoughts are disabled', () => { + vi.stubEnv('CLI_TITLE', 'EnvOverride'); + + const title = computeTerminalTitle({ + streamingState: StreamingState.Idle, + isConfirming: false, + folderName: 'my-project', + showThoughts: false, + useDynamicTitle: true, + }); + + expect(title).toContain('◇ Ready (EnvOverride)'); + expect(title).not.toContain('my-project'); + expect(title.length).toBe(80); }); - it('should handle folder names with spaces', () => { - const result = computeWindowTitle('my project'); - expect(result).toBe('Gemini - my project'); - }); + it.each([ + { + name: 'folder name', + folderName: 'A'.repeat(100), + expected: '◇ Ready (AAAAA', + }, + { + name: 'CLI_TITLE', + folderName: 'my-project', + envTitle: 'B'.repeat(100), + expected: '◇ Ready (BBBBB', + }, + ])( + 'should truncate very long $name to fit within 80 characters', + ({ folderName, envTitle, expected }) => { + if (envTitle) { + vi.stubEnv('CLI_TITLE', envTitle); + } - it('should handle folder names with special characters', () => { - const result = computeWindowTitle('project-name_v1.0'); - expect(result).toBe('Gemini - project-name_v1.0'); + const title = computeTerminalTitle({ + streamingState: StreamingState.Idle, + isConfirming: false, + folderName, + showThoughts: false, + useDynamicTitle: true, + }); + + expect(title.length).toBe(80); + expect(title).toContain(expected); + expect(title).toContain('…)'); + }, + ); + + it('should truncate long folder name when useDynamicTitle is false', () => { + const longFolderName = 'C'.repeat(100); + const title = computeTerminalTitle({ + streamingState: StreamingState.Responding, + isConfirming: false, + folderName: longFolderName, + showThoughts: true, + useDynamicTitle: false, + }); + + expect(title.length).toBe(80); + expect(title).toContain('Gemini CLI (CCCCC'); + expect(title).toContain('…)'); }); }); diff --git a/packages/cli/src/utils/windowTitle.ts b/packages/cli/src/utils/windowTitle.ts index 7ff462494c..3378119915 100644 --- a/packages/cli/src/utils/windowTitle.ts +++ b/packages/cli/src/utils/windowTitle.ts @@ -4,19 +4,104 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { StreamingState } from '../ui/types.js'; + +export interface TerminalTitleOptions { + streamingState: StreamingState; + thoughtSubject?: string; + isConfirming: boolean; + folderName: string; + showThoughts: boolean; + useDynamicTitle: boolean; +} + +function truncate(text: string, maxLen: number): string { + if (text.length <= maxLen) { + return text; + } + return text.substring(0, maxLen - 1) + '…'; +} + /** - * Computes the window title for the Gemini CLI application. + * Computes the dynamic terminal window title based on the current CLI state. * - * @param folderName - The name of the current folder/workspace to display in the title - * @returns The computed window title, either from CLI_TITLE environment variable or the default Gemini title + * @param options - The current state of the CLI and environment context + * @returns A formatted string padded to 80 characters for the terminal title */ -export function computeWindowTitle(folderName: string): string { - const title = process.env['CLI_TITLE'] || `Gemini - ${folderName}`; +export function computeTerminalTitle({ + streamingState, + thoughtSubject, + isConfirming, + folderName, + showThoughts, + useDynamicTitle, +}: TerminalTitleOptions): string { + const MAX_LEN = 80; + + // Use CLI_TITLE env var if available, otherwise use the provided folder name + let displayContext = process.env['CLI_TITLE'] || folderName; + + if (!useDynamicTitle) { + const base = 'Gemini CLI '; + // Max context length is 80 - base.length - 2 (for brackets) + const maxContextLen = MAX_LEN - base.length - 2; + displayContext = truncate(displayContext, maxContextLen); + return `${base}(${displayContext})`.padEnd(MAX_LEN, ' '); + } + + // Pre-calculate suffix but keep it flexible + const getSuffix = (context: string) => ` (${context})`; + + let title; + if ( + isConfirming || + streamingState === StreamingState.WaitingForConfirmation + ) { + const base = '✋ Action Required'; + // Max context length is 80 - base.length - 3 (for ' (' and ')') + const maxContextLen = MAX_LEN - base.length - 3; + const context = truncate(displayContext, maxContextLen); + title = `${base}${getSuffix(context)}`; + } else if (streamingState === StreamingState.Idle) { + const base = '◇ Ready'; + // Max context length is 80 - base.length - 3 (for ' (' and ')') + const maxContextLen = MAX_LEN - base.length - 3; + const context = truncate(displayContext, maxContextLen); + title = `${base}${getSuffix(context)}`; + } else { + // Active/Working state + const cleanSubject = + showThoughts && thoughtSubject?.replace(/[\r\n]+/g, ' ').trim(); + + // If we have a thought subject and it's too long to fit with the suffix, + // we drop the suffix to maximize space for the thought. + // Otherwise, we keep the suffix. + const suffix = getSuffix(displayContext); + const suffixLen = suffix.length; + const canFitThoughtWithSuffix = cleanSubject + ? cleanSubject.length + suffixLen + 3 <= MAX_LEN + : true; + + let activeSuffix = ''; + let maxStatusLen = MAX_LEN - 3; // Subtract icon prefix "✦ " (3 chars) + + if (!cleanSubject || canFitThoughtWithSuffix) { + activeSuffix = suffix; + maxStatusLen -= activeSuffix.length; + } + + const displayStatus = cleanSubject + ? truncate(cleanSubject, maxStatusLen) + : 'Working…'; + + title = `✦ ${displayStatus}${activeSuffix}`; + } // Remove control characters that could cause issues in terminal titles - return title.replace( - // eslint-disable-next-line no-control-regex - /[\x00-\x1F\x7F]/g, - '', - ); + // eslint-disable-next-line no-control-regex + const safeTitle = title.replace(/[\x00-\x1F\x7F]/g, ''); + + // Pad the title to a fixed width to prevent taskbar icon resizing/jitter. + // We also slice it to ensure it NEVER exceeds MAX_LEN. + return safeTitle.padEnd(MAX_LEN, ' ').substring(0, MAX_LEN); } diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index 33a659a822..2f06d0c954 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -188,12 +188,19 @@ "type": "boolean" }, "showStatusInTitle": { - "title": "Show Status in Title", - "description": "Show Gemini CLI status and thoughts in the terminal window title", - "markdownDescription": "Show Gemini CLI status and thoughts in the terminal window title\n\n- Category: `UI`\n- Requires restart: `no`\n- Default: `false`", + "title": "Show Thoughts in Title", + "description": "Show Gemini CLI model thoughts in the terminal window title during the working phase", + "markdownDescription": "Show Gemini CLI model thoughts in the terminal window title during the working phase\n\n- Category: `UI`\n- Requires restart: `no`\n- Default: `false`", "default": false, "type": "boolean" }, + "dynamicWindowTitle": { + "title": "Dynamic Window Title", + "description": "Update the terminal window title with current status icons (Ready: ◇, Action Required: ✋, Working: ✦)", + "markdownDescription": "Update the terminal window title with current status icons (Ready: ◇, Action Required: ✋, Working: ✦)\n\n- Category: `UI`\n- Requires restart: `no`\n- Default: `true`", + "default": true, + "type": "boolean" + }, "showHomeDirectoryWarning": { "title": "Show Home Directory Warning", "description": "Show a warning when running Gemini CLI in the home directory.", From b81fe6832589b13b0874f7bcb9f21cd211773a0a Mon Sep 17 00:00:00 2001 From: Sandy Tao Date: Tue, 13 Jan 2026 09:26:53 +0800 Subject: [PATCH 148/713] feat(core): add disableLLMCorrection setting to skip auto-correction in edit tools (#16000) --- docs/cli/settings.md | 19 ++--- docs/get-started/configuration.md | 7 ++ packages/cli/src/config/config.ts | 1 + packages/cli/src/config/settingsSchema.ts | 12 +++ packages/core/src/config/config.ts | 7 ++ .../src/tools/confirmation-policy.test.ts | 1 + packages/core/src/tools/edit.test.ts | 44 +++++++++++ packages/core/src/tools/edit.ts | 11 +++ packages/core/src/tools/write-file.test.ts | 76 +++++++++++++++++++ packages/core/src/tools/write-file.ts | 2 + packages/core/src/utils/editCorrector.test.ts | 20 +++++ packages/core/src/utils/editCorrector.ts | 26 ++++++- schemas/settings.schema.json | 7 ++ 13 files changed, 221 insertions(+), 12 deletions(-) diff --git a/docs/cli/settings.md b/docs/cli/settings.md index ebd7c05fe0..29181f928b 100644 --- a/docs/cli/settings.md +++ b/docs/cli/settings.md @@ -90,15 +90,16 @@ they appear in the UI. ### Tools -| UI Label | Setting | Description | Default | -| -------------------------------- | ------------------------------------ | --------------------------------------------------------------------------------------------------------------- | --------- | -| Enable Interactive Shell | `tools.shell.enableInteractiveShell` | Use node-pty for an interactive shell experience. Fallback to child_process still applies. | `true` | -| Show Color | `tools.shell.showColor` | Show color in shell output. | `false` | -| Auto Accept | `tools.autoAccept` | Automatically accept and execute tool calls that are considered safe (e.g., read-only operations). | `false` | -| Use Ripgrep | `tools.useRipgrep` | Use ripgrep for file content search instead of the fallback implementation. Provides faster search performance. | `true` | -| Enable Tool Output Truncation | `tools.enableToolOutputTruncation` | Enable truncation of large tool outputs. | `true` | -| Tool Output Truncation Threshold | `tools.truncateToolOutputThreshold` | Truncate tool output if it is larger than this many characters. Set to -1 to disable. | `4000000` | -| Tool Output Truncation Lines | `tools.truncateToolOutputLines` | The number of lines to keep when truncating tool output. | `1000` | +| UI Label | Setting | Description | Default | +| -------------------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | +| Enable Interactive Shell | `tools.shell.enableInteractiveShell` | Use node-pty for an interactive shell experience. Fallback to child_process still applies. | `true` | +| Show Color | `tools.shell.showColor` | Show color in shell output. | `false` | +| Auto Accept | `tools.autoAccept` | Automatically accept and execute tool calls that are considered safe (e.g., read-only operations). | `false` | +| Use Ripgrep | `tools.useRipgrep` | Use ripgrep for file content search instead of the fallback implementation. Provides faster search performance. | `true` | +| Enable Tool Output Truncation | `tools.enableToolOutputTruncation` | Enable truncation of large tool outputs. | `true` | +| Tool Output Truncation Threshold | `tools.truncateToolOutputThreshold` | Truncate tool output if it is larger than this many characters. Set to -1 to disable. | `4000000` | +| Tool Output Truncation Lines | `tools.truncateToolOutputLines` | The number of lines to keep when truncating tool output. | `1000` | +| Disable LLM Correction | `tools.disableLLMCorrection` | Disable LLM-based error correction for edit tools. When enabled, tools will fail immediately if exact string matches are not found, instead of attempting to self-correct. | `false` | ### Security diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 4dc17aa548..810468e406 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -695,6 +695,13 @@ their corresponding top-level category object in your `settings.json` file. - **Default:** `1000` - **Requires restart:** Yes +- **`tools.disableLLMCorrection`** (boolean): + - **Description:** Disable LLM-based error correction for edit tools. When + enabled, tools will fail immediately if exact string matches are not found, + instead of attempting to self-correct. + - **Default:** `false` + - **Requires restart:** Yes + - **`tools.enableHooks`** (boolean): - **Description:** Enables the hooks system experiment. When disabled, the hooks system is completely deactivated regardless of other settings. diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index bc185ffdf8..4d353b360c 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -737,6 +737,7 @@ export async function loadCliConfig( recordResponses: argv.recordResponses, retryFetchErrors: settings.general?.retryFetchErrors, ptyInfo: ptyInfo?.name, + disableLLMCorrection: settings.tools?.disableLLMCorrection, modelConfigServiceConfig: settings.modelConfigs, // TODO: loading of hooks based on workspace trust enableHooks: getEnableHooks(settings), diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index 390c0ad403..c4e7cc7faa 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -1093,6 +1093,18 @@ const SETTINGS_SCHEMA = { description: 'The number of lines to keep when truncating tool output.', showInDialog: true, }, + disableLLMCorrection: { + type: 'boolean', + label: 'Disable LLM Correction', + category: 'Tools', + requiresRestart: true, + default: false, + description: oneLine` + Disable LLM-based error correction for edit tools. + When enabled, tools will fail immediately if exact string matches are not found, instead of attempting to self-correct. + `, + showInDialog: true, + }, enableHooks: { type: 'boolean', label: 'Enable Hooks System (Experimental)', diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 91d16b2b70..6c57be29ab 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -358,6 +358,7 @@ export interface ConfigParameters { skillsSupport?: boolean; disabledSkills?: string[]; experimentalJitContext?: boolean; + disableLLMCorrection?: boolean; onModelChange?: (model: string) => void; mcpEnabled?: boolean; extensionsEnabled?: boolean; @@ -497,6 +498,7 @@ export class Config { private disabledSkills: string[]; private readonly experimentalJitContext: boolean; + private readonly disableLLMCorrection: boolean; private contextManager?: ContextManager; private terminalBackground: string | undefined = undefined; private remoteAdminSettings: GeminiCodeAssistSetting | undefined; @@ -566,6 +568,7 @@ export class Config { this.model = params.model; this._activeModel = params.model; this.enableAgents = params.enableAgents ?? false; + this.disableLLMCorrection = params.disableLLMCorrection ?? false; this.skillsSupport = params.skillsSupport ?? false; this.disabledSkills = params.disabledSkills ?? []; this.modelAvailabilityService = new ModelAvailabilityService(); @@ -1426,6 +1429,10 @@ export class Config { return this.enableExtensionReloading; } + getDisableLLMCorrection(): boolean { + return this.disableLLMCorrection; + } + isAgentsEnabled(): boolean { return this.enableAgents; } diff --git a/packages/core/src/tools/confirmation-policy.test.ts b/packages/core/src/tools/confirmation-policy.test.ts index df14bbfb63..e3b87ecb59 100644 --- a/packages/core/src/tools/confirmation-policy.test.ts +++ b/packages/core/src/tools/confirmation-policy.test.ts @@ -64,6 +64,7 @@ describe('Tool Confirmation Policy Updates', () => { getFileFilteringOptions: () => ({}), getGeminiClient: () => ({}), getBaseLlmClient: () => ({}), + getDisableLLMCorrection: () => false, getIdeMode: () => false, getWorkspaceContext: () => ({ isPathWithinWorkspace: () => true, diff --git a/packages/core/src/tools/edit.test.ts b/packages/core/src/tools/edit.test.ts index 14d520456b..874c3e4140 100644 --- a/packages/core/src/tools/edit.test.ts +++ b/packages/core/src/tools/edit.test.ts @@ -120,6 +120,7 @@ describe('EditTool', () => { setGeminiMdFileCount: vi.fn(), getToolRegistry: () => ({}) as any, isInteractive: () => false, + getDisableLLMCorrection: vi.fn(() => false), getExperiments: () => {}, } as unknown as Config; @@ -858,4 +859,47 @@ describe('EditTool', () => { expect(totalActualRemoved).toBe(totalExpectedRemoved); }); }); + + describe('disableLLMCorrection', () => { + it('should NOT call FixLLMEditWithInstruction when disableLLMCorrection is true', async () => { + const filePath = path.join(rootDir, 'disable_llm_test.txt'); + fs.writeFileSync(filePath, 'Some content.', 'utf8'); + + // Enable the setting + (mockConfig.getDisableLLMCorrection as Mock).mockReturnValue(true); + + const params: EditToolParams = { + file_path: filePath, + instruction: 'Replace non-existent text', + old_string: 'nonexistent', + new_string: 'replacement', + }; + + const invocation = tool.build(params); + const result = await invocation.execute(new AbortController().signal); + + expect(result.error?.type).toBe(ToolErrorType.EDIT_NO_OCCURRENCE_FOUND); + expect(mockFixLLMEditWithInstruction).not.toHaveBeenCalled(); + }); + + it('should call FixLLMEditWithInstruction when disableLLMCorrection is false (default)', async () => { + const filePath = path.join(rootDir, 'enable_llm_test.txt'); + fs.writeFileSync(filePath, 'Some content.', 'utf8'); + + // Default is false, but being explicit + (mockConfig.getDisableLLMCorrection as Mock).mockReturnValue(false); + + const params: EditToolParams = { + file_path: filePath, + instruction: 'Replace non-existent text', + old_string: 'nonexistent', + new_string: 'replacement', + }; + + const invocation = tool.build(params); + await invocation.execute(new AbortController().signal); + + expect(mockFixLLMEditWithInstruction).toHaveBeenCalled(); + }); + }); }); diff --git a/packages/core/src/tools/edit.ts b/packages/core/src/tools/edit.ts index 85c86ff804..a133c0e2cf 100644 --- a/packages/core/src/tools/edit.ts +++ b/packages/core/src/tools/edit.ts @@ -639,6 +639,17 @@ class EditToolInvocation }; } + if (this.config.getDisableLLMCorrection()) { + return { + currentContent, + newContent: currentContent, + occurrences: replacementResult.occurrences, + isNewFile: false, + error: initialError, + originalLineEnding, + }; + } + // If there was an error, try to self-correct. return this.attemptSelfCorrection( params, diff --git a/packages/core/src/tools/write-file.test.ts b/packages/core/src/tools/write-file.test.ts index cd5436e7be..7a657cfc64 100644 --- a/packages/core/src/tools/write-file.test.ts +++ b/packages/core/src/tools/write-file.test.ts @@ -106,6 +106,7 @@ const mockConfigInternal = { discoverTools: vi.fn(), }) as unknown as ToolRegistry, isInteractive: () => false, + getDisableLLMCorrection: vi.fn(() => false), }; const mockConfig = mockConfigInternal as unknown as Config; @@ -293,6 +294,7 @@ describe('WriteFileTool', () => { proposedContent, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockEnsureCorrectEdit).not.toHaveBeenCalled(); expect(result.correctedContent).toBe(correctedContent); @@ -337,6 +339,7 @@ describe('WriteFileTool', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockEnsureCorrectFileContent).not.toHaveBeenCalled(); expect(result.correctedContent).toBe(correctedProposedContent); @@ -414,6 +417,7 @@ describe('WriteFileTool', () => { proposedContent, mockBaseLlmClientInstance, abortSignal, + false, ); expect(confirmation).toEqual( expect.objectContaining({ @@ -464,6 +468,7 @@ describe('WriteFileTool', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(confirmation).toEqual( expect.objectContaining({ @@ -658,6 +663,7 @@ describe('WriteFileTool', () => { proposedContent, mockBaseLlmClientInstance, abortSignal, + false, ); expect(result.llmContent).toMatch( /Successfully created and wrote to new file/, @@ -715,6 +721,7 @@ describe('WriteFileTool', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(result.llmContent).toMatch(/Successfully overwrote file/); const writtenContent = await fsService.readTextFile(filePath); @@ -899,4 +906,73 @@ describe('WriteFileTool', () => { }, ); }); + + describe('disableLLMCorrection', () => { + const abortSignal = new AbortController().signal; + + it('should call ensureCorrectFileContent with disableLLMCorrection=true for a new file when disabled', async () => { + const filePath = path.join(rootDir, 'new_file_no_correction.txt'); + const proposedContent = 'Proposed content.'; + + mockConfigInternal.getDisableLLMCorrection.mockReturnValue(true); + // Ensure the mock returns the content passed to it (simulating no change or unescaped change) + mockEnsureCorrectFileContent.mockResolvedValue(proposedContent); + + const result = await getCorrectedFileContent( + mockConfig, + filePath, + proposedContent, + abortSignal, + ); + + expect(mockEnsureCorrectFileContent).toHaveBeenCalledWith( + proposedContent, + mockBaseLlmClientInstance, + abortSignal, + true, + ); + expect(mockEnsureCorrectEdit).not.toHaveBeenCalled(); + expect(result.correctedContent).toBe(proposedContent); + expect(result.fileExists).toBe(false); + }); + + it('should call ensureCorrectEdit with disableLLMCorrection=true for an existing file when disabled', async () => { + const filePath = path.join(rootDir, 'existing_file_no_correction.txt'); + const originalContent = 'Original content.'; + const proposedContent = 'Proposed content.'; + fs.writeFileSync(filePath, originalContent, 'utf8'); + + mockConfigInternal.getDisableLLMCorrection.mockReturnValue(true); + // Ensure the mock returns the content passed to it + mockEnsureCorrectEdit.mockResolvedValue({ + params: { + file_path: filePath, + old_string: originalContent, + new_string: proposedContent, + }, + occurrences: 1, + }); + + const result = await getCorrectedFileContent( + mockConfig, + filePath, + proposedContent, + abortSignal, + ); + + expect(mockEnsureCorrectEdit).toHaveBeenCalledWith( + filePath, + originalContent, + expect.anything(), // params object + mockGeminiClientInstance, + mockBaseLlmClientInstance, + abortSignal, + true, + ); + expect(mockEnsureCorrectFileContent).not.toHaveBeenCalled(); + expect(result.correctedContent).toBe(proposedContent); + expect(result.originalContent).toBe(originalContent); + expect(result.fileExists).toBe(true); + }); + }); }); diff --git a/packages/core/src/tools/write-file.ts b/packages/core/src/tools/write-file.ts index 3dbb696acc..b496fa6e8e 100644 --- a/packages/core/src/tools/write-file.ts +++ b/packages/core/src/tools/write-file.ts @@ -127,6 +127,7 @@ export async function getCorrectedFileContent( config.getGeminiClient(), config.getBaseLlmClient(), abortSignal, + config.getDisableLLMCorrection(), ); correctedContent = correctedParams.new_string; } else { @@ -135,6 +136,7 @@ export async function getCorrectedFileContent( proposedContent, config.getBaseLlmClient(), abortSignal, + config.getDisableLLMCorrection(), ); } return { originalContent, correctedContent, fileExists }; diff --git a/packages/core/src/utils/editCorrector.test.ts b/packages/core/src/utils/editCorrector.test.ts index 02b8c1a3fb..2d3f4b9a20 100644 --- a/packages/core/src/utils/editCorrector.test.ts +++ b/packages/core/src/utils/editCorrector.test.ts @@ -273,6 +273,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(1); expect(result.params.new_string).toBe('replace with "this"'); @@ -293,6 +294,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(0); expect(result.params.new_string).toBe('replace with this'); @@ -316,6 +318,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(1); expect(result.params.new_string).toBe('replace with "this"'); @@ -336,6 +339,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(0); expect(result.params.new_string).toBe('replace with this'); @@ -360,6 +364,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(1); expect(result.params.new_string).toBe('replace with "this"'); @@ -380,6 +385,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(0); expect(result.params.new_string).toBe('replace with this'); @@ -400,6 +406,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(0); expect(result.params.new_string).toBe('replace with foobar'); @@ -425,6 +432,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(1); expect(result.params.new_string).toBe(llmNewString); @@ -449,6 +457,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(2); expect(result.params.new_string).toBe(llmNewString); @@ -471,6 +480,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(1); expect(result.params.new_string).toBe('replace with "this"'); @@ -495,6 +505,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(1); expect(result.params.new_string).toBe(newStringForLLMAndReturnedByLLM); @@ -518,6 +529,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(1); expect(result.params).toEqual(originalParams); @@ -538,6 +550,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(0); expect(result.params).toEqual(originalParams); @@ -563,6 +576,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(mockGenerateJson).toHaveBeenCalledTimes(2); expect(result.params.old_string).toBe(currentContent); @@ -618,6 +632,7 @@ describe('editCorrector', () => { mockGeminiClientInstance, mockBaseLlmClientInstance, abortSignal, + false, ); expect(result.occurrences).toBe(0); @@ -665,6 +680,7 @@ describe('editCorrector', () => { content, mockBaseLlmClientInstance, abortSignal, + false, ); expect(result).toBe(content); expect(mockGenerateJson).toHaveBeenCalledTimes(0); @@ -681,6 +697,7 @@ describe('editCorrector', () => { content, mockBaseLlmClientInstance, abortSignal, + false, ); expect(result).toBe(correctedContent); @@ -701,6 +718,7 @@ describe('editCorrector', () => { content, mockBaseLlmClientInstance, abortSignal, + false, ); expect(result).toBe(correctedContent); @@ -716,6 +734,7 @@ describe('editCorrector', () => { content, mockBaseLlmClientInstance, abortSignal, + false, ); expect(result).toBe(content); @@ -736,6 +755,7 @@ describe('editCorrector', () => { content, mockBaseLlmClientInstance, abortSignal, + false, ); expect(result).toBe(correctedContent); diff --git a/packages/core/src/utils/editCorrector.ts b/packages/core/src/utils/editCorrector.ts index 99019e2b60..27e40b8c74 100644 --- a/packages/core/src/utils/editCorrector.ts +++ b/packages/core/src/utils/editCorrector.ts @@ -167,10 +167,11 @@ async function findLastEditTimestamp( export async function ensureCorrectEdit( filePath: string, currentContent: string, - originalParams: EditToolParams, // This is the EditToolParams from edit.ts, without \'corrected\' + originalParams: EditToolParams, // This is the EditToolParams from edit.ts, without 'corrected' geminiClient: GeminiClient, baseLlmClient: BaseLlmClient, abortSignal: AbortSignal, + disableLLMCorrection: boolean, ): Promise { const cacheKey = `${currentContent}---${originalParams.old_string}---${originalParams.new_string}`; const cachedResult = editCorrectionCache.get(cacheKey); @@ -189,7 +190,7 @@ export async function ensureCorrectEdit( let occurrences = countOccurrences(currentContent, finalOldString); if (occurrences === expectedReplacements) { - if (newStringPotentiallyEscaped) { + if (newStringPotentiallyEscaped && !disableLLMCorrection) { finalNewString = await correctNewStringEscaping( baseLlmClient, finalOldString, @@ -236,7 +237,7 @@ export async function ensureCorrectEdit( if (occurrences === expectedReplacements) { finalOldString = unescapedOldStringAttempt; - if (newStringPotentiallyEscaped) { + if (newStringPotentiallyEscaped && !disableLLMCorrection) { finalNewString = await correctNewString( baseLlmClient, originalParams.old_string, // original old @@ -274,6 +275,15 @@ export async function ensureCorrectEdit( } } + if (disableLLMCorrection) { + const result: CorrectedEditResult = { + params: { ...originalParams }, + occurrences: 0, + }; + editCorrectionCache.set(cacheKey, result); + return result; + } + const llmCorrectedOldString = await correctOldStringMismatch( baseLlmClient, currentContent, @@ -347,6 +357,7 @@ export async function ensureCorrectFileContent( content: string, baseLlmClient: BaseLlmClient, abortSignal: AbortSignal, + disableLLMCorrection: boolean = false, ): Promise { const cachedResult = fileContentCorrectionCache.get(content); if (cachedResult) { @@ -360,6 +371,15 @@ export async function ensureCorrectFileContent( return content; } + if (disableLLMCorrection) { + // If we can't use LLM, we should at least use the unescaped content + // as it's likely better than the original if it was detected as potentially escaped. + // unescapeStringForGeminiBug is a heuristic, not an LLM call. + const unescaped = unescapeStringForGeminiBug(content); + fileContentCorrectionCache.set(content, unescaped); + return unescaped; + } + const correctedContent = await correctStringEscaping( content, baseLlmClient, diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index 2f06d0c954..6c7f8beaa4 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -1142,6 +1142,13 @@ "default": 1000, "type": "number" }, + "disableLLMCorrection": { + "title": "Disable LLM Correction", + "description": "Disable LLM-based error correction for edit tools. When enabled, tools will fail immediately if exact string matches are not found, instead of attempting to self-correct.", + "markdownDescription": "Disable LLM-based error correction for edit tools. When enabled, tools will fail immediately if exact string matches are not found, instead of attempting to self-correct.\n\n- Category: `Tools`\n- Requires restart: `yes`\n- Default: `false`", + "default": false, + "type": "boolean" + }, "enableHooks": { "title": "Enable Hooks System (Experimental)", "description": "Enables the hooks system experiment. When disabled, the hooks system is completely deactivated regardless of other settings.", From 6adae9f7756d8efbc4c5901fe5884fa4a35f1f68 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 12 Jan 2026 20:14:01 -0800 Subject: [PATCH 149/713] fix: Set both tab and window title instead of just window title (#16464) Co-authored-by: Oleksandr Nikitin --- packages/cli/src/gemini.tsx | 4 +-- packages/cli/src/ui/AppContainer.test.tsx | 38 +++++++++++------------ packages/cli/src/ui/AppContainer.tsx | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index 7a100678df..8ae21247e9 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -720,10 +720,10 @@ function setWindowTitle(title: string, settings: LoadedSettings) { showThoughts: !!settings.merged.ui?.showStatusInTitle, useDynamicTitle: settings.merged.ui?.dynamicWindowTitle ?? true, }); - writeToStdout(`\x1b]2;${windowTitle}\x07`); + writeToStdout(`\x1b]0;${windowTitle}\x07`); process.on('exit', () => { - writeToStdout(`\x1b]2;\x07`); + writeToStdout(`\x1b]0;\x07`); }); } } diff --git a/packages/cli/src/ui/AppContainer.test.tsx b/packages/cli/src/ui/AppContainer.test.tsx index be0ba688b6..fcaa4e012a 100644 --- a/packages/cli/src/ui/AppContainer.test.tsx +++ b/packages/cli/src/ui/AppContainer.test.tsx @@ -1020,12 +1020,12 @@ describe('AppContainer State Management', () => { // Assert: Check that title was updated with "Working…" const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]2;'), + call[0].includes('\x1b]0;'), ); expect(titleWrites).toHaveLength(1); expect(titleWrites[0][0]).toBe( - `\x1b]2;${'✦ Working… (workspace)'.padEnd(80, ' ')}\x07`, + `\x1b]0;${'✦ Working… (workspace)'.padEnd(80, ' ')}\x07`, ); unmount(); }); @@ -1061,12 +1061,12 @@ describe('AppContainer State Management', () => { // Assert: Check that legacy title was used const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]2;'), + call[0].includes('\x1b]0;'), ); expect(titleWrites).toHaveLength(1); expect(titleWrites[0][0]).toBe( - `\x1b]2;${'Gemini CLI (workspace)'.padEnd(80, ' ')}\x07`, + `\x1b]0;${'Gemini CLI (workspace)'.padEnd(80, ' ')}\x07`, ); unmount(); }); @@ -1092,7 +1092,7 @@ describe('AppContainer State Management', () => { // Assert: Check that no title-related writes occurred const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]2;'), + call[0].includes('\x1b]0;'), ); expect(titleWrites).toHaveLength(0); @@ -1131,12 +1131,12 @@ describe('AppContainer State Management', () => { // Assert: Check that title was updated with thought subject and suffix const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]2;'), + call[0].includes('\x1b]0;'), ); expect(titleWrites).toHaveLength(1); expect(titleWrites[0][0]).toBe( - `\x1b]2;${`✦ ${thoughtSubject} (workspace)`.padEnd(80, ' ')}\x07`, + `\x1b]0;${`✦ ${thoughtSubject} (workspace)`.padEnd(80, ' ')}\x07`, ); unmount(); }); @@ -1172,12 +1172,12 @@ describe('AppContainer State Management', () => { // Assert: Check that title was updated with default Idle text const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]2;'), + call[0].includes('\x1b]0;'), ); expect(titleWrites).toHaveLength(1); expect(titleWrites[0][0]).toBe( - `\x1b]2;${'◇ Ready (workspace)'.padEnd(80, ' ')}\x07`, + `\x1b]0;${'◇ Ready (workspace)'.padEnd(80, ' ')}\x07`, ); unmount(); }); @@ -1218,12 +1218,12 @@ describe('AppContainer State Management', () => { // Assert: Check that title was updated with confirmation text const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]2;'), + call[0].includes('\x1b]0;'), ); expect(titleWrites).toHaveLength(1); expect(titleWrites[0][0]).toBe( - `\x1b]2;${'✋ Action Required (workspace)'.padEnd(80, ' ')}\x07`, + `\x1b]0;${'✋ Action Required (workspace)'.padEnd(80, ' ')}\x07`, ); unmount!(); }); @@ -1269,7 +1269,7 @@ describe('AppContainer State Management', () => { // Initially it should show the working status const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]2;'), + call[0].includes('\x1b]0;'), ); expect(titleWrites[titleWrites.length - 1][0]).toContain( '✦ Executing shell command', @@ -1283,7 +1283,7 @@ describe('AppContainer State Management', () => { // Now it should show Action Required await waitFor(() => { const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]2;'), + call[0].includes('\x1b]0;'), ); const lastTitle = titleWrites[titleWrites.length - 1][0]; expect(lastTitle).toContain('✋ Action Required'); @@ -1325,13 +1325,13 @@ describe('AppContainer State Management', () => { // Assert: Check that title is padded to exactly 80 characters const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]2;'), + call[0].includes('\x1b]0;'), ); expect(titleWrites).toHaveLength(1); const calledWith = titleWrites[0][0]; const expectedTitle = `✦ ${shortTitle} (workspace)`.padEnd(80, ' '); - const expectedEscapeSequence = `\x1b]2;${expectedTitle}\x07`; + const expectedEscapeSequence = `\x1b]0;${expectedTitle}\x07`; expect(calledWith).toBe(expectedEscapeSequence); unmount(); }); @@ -1368,11 +1368,11 @@ describe('AppContainer State Management', () => { // Assert: Check that the correct ANSI escape sequence is used const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]2;'), + call[0].includes('\x1b]0;'), ); expect(titleWrites).toHaveLength(1); - const expectedEscapeSequence = `\x1b]2;${`✦ ${title} (workspace)`.padEnd(80, ' ')}\x07`; + const expectedEscapeSequence = `\x1b]0;${`✦ ${title} (workspace)`.padEnd(80, ' ')}\x07`; expect(titleWrites[0][0]).toBe(expectedEscapeSequence); unmount(); }); @@ -1411,12 +1411,12 @@ describe('AppContainer State Management', () => { // Assert: Check that title was updated with CLI_TITLE value const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]2;'), + call[0].includes('\x1b]0;'), ); expect(titleWrites).toHaveLength(1); expect(titleWrites[0][0]).toBe( - `\x1b]2;${'✦ Working… (Custom Gemini Title)'.padEnd(80, ' ')}\x07`, + `\x1b]0;${'✦ Working… (Custom Gemini Title)'.padEnd(80, ' ')}\x07`, ); unmount(); }); diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index dbfdf58681..5184853e4b 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -1362,7 +1362,7 @@ Logging in with Google... Restarting Gemini CLI to continue. // Only update the title if it's different from the last value we set if (lastTitleRef.current !== paddedTitle) { lastTitleRef.current = paddedTitle; - stdout.write(`\x1b]2;${paddedTitle}\x07`); + stdout.write(`\x1b]0;${paddedTitle}\x07`); } // Note: We don't need to reset the window title on exit because Gemini CLI is already doing that elsewhere }, [ From 7bbfaabffa7051b8a7b3250f6d5e7a5f24e5304d Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 12 Jan 2026 23:25:11 -0800 Subject: [PATCH 150/713] fix(policy): ensure MCP policies match unqualified names in non-interactive mode (#16490) --- .../core/src/core/coreToolScheduler.test.ts | 72 ++++++++++++++++++- packages/core/src/core/coreToolScheduler.ts | 9 ++- .../core/src/policy/policy-engine.test.ts | 31 ++++++++ packages/core/src/policy/policy-engine.ts | 24 ++++--- 4 files changed, 125 insertions(+), 11 deletions(-) diff --git a/packages/core/src/core/coreToolScheduler.test.ts b/packages/core/src/core/coreToolScheduler.test.ts index 9cfacc2358..f3a35319e9 100644 --- a/packages/core/src/core/coreToolScheduler.test.ts +++ b/packages/core/src/core/coreToolScheduler.test.ts @@ -6,6 +6,7 @@ import { describe, it, expect, vi } from 'vitest'; import type { Mock } from 'vitest'; +import type { CallableTool } from '@google/genai'; import { CoreToolScheduler } from './coreToolScheduler.js'; import type { ToolCall, @@ -41,6 +42,7 @@ import { import * as modifiableToolModule from '../tools/modifiable-tool.js'; import { DEFAULT_GEMINI_MODEL } from '../config/models.js'; import type { PolicyEngine } from '../policy/policy-engine.js'; +import { DiscoveredMCPTool } from '../tools/mcp-tool.js'; vi.mock('fs/promises', () => ({ writeFile: vi.fn(), @@ -283,7 +285,10 @@ function createMockConfig(overrides: Partial = {}): Config { if (!overrides.getPolicyEngine) { finalConfig.getPolicyEngine = () => ({ - check: async (toolCall: { name: string; args: object }) => { + check: async ( + toolCall: { name: string; args: object }, + _serverName?: string, + ) => { // Mock simple policy logic for tests const mode = finalConfig.getApprovalMode(); if (mode === ApprovalMode.YOLO) { @@ -1834,4 +1839,69 @@ describe('CoreToolScheduler Sequential Execution', () => { modifyWithEditorSpy.mockRestore(); }); + + it('should pass serverName to policy engine for DiscoveredMCPTool', async () => { + const mockMcpTool = { + tool: async () => ({ functionDeclarations: [] }), + callTool: async () => [], + }; + const serverName = 'test-server'; + const toolName = 'test-tool'; + const mcpTool = new DiscoveredMCPTool( + mockMcpTool as unknown as CallableTool, + serverName, + toolName, + 'description', + { type: 'object', properties: {} }, + createMockMessageBus() as unknown as MessageBus, + ); + + const mockToolRegistry = { + getTool: () => mcpTool, + getFunctionDeclarations: () => [], + tools: new Map(), + discovery: {}, + registerTool: () => {}, + getToolByName: () => mcpTool, + getToolByDisplayName: () => mcpTool, + getTools: () => [], + discoverTools: async () => {}, + getAllTools: () => [], + getToolsByServer: () => [], + } as unknown as ToolRegistry; + + const mockPolicyEngineCheck = vi.fn().mockResolvedValue({ + decision: PolicyDecision.ALLOW, + }); + + const mockConfig = createMockConfig({ + getToolRegistry: () => mockToolRegistry, + getPolicyEngine: () => + ({ + check: mockPolicyEngineCheck, + }) as unknown as PolicyEngine, + isInteractive: () => false, + }); + + const scheduler = new CoreToolScheduler({ + config: mockConfig, + getPreferredEditor: () => 'vscode', + }); + + const abortController = new AbortController(); + const request = { + callId: '1', + name: toolName, + args: {}, + isClientInitiated: false, + prompt_id: 'prompt-id-1', + }; + + await scheduler.schedule(request, abortController.signal); + + expect(mockPolicyEngineCheck).toHaveBeenCalledWith( + expect.objectContaining({ name: toolName }), + serverName, + ); + }); }); diff --git a/packages/core/src/core/coreToolScheduler.ts b/packages/core/src/core/coreToolScheduler.ts index bec4eacd53..9b2b08c47f 100644 --- a/packages/core/src/core/coreToolScheduler.ts +++ b/packages/core/src/core/coreToolScheduler.ts @@ -44,6 +44,7 @@ import { type ToolCallResponseInfo, } from '../scheduler/types.js'; import { ToolExecutor } from '../scheduler/tool-executor.js'; +import { DiscoveredMCPTool } from '../tools/mcp-tool.js'; export type { ToolCall, @@ -591,9 +592,15 @@ export class CoreToolScheduler { name: toolCall.request.name, args: toolCall.request.args, }; + + const serverName = + toolCall.tool instanceof DiscoveredMCPTool + ? toolCall.tool.serverName + : undefined; + const { decision } = await this.config .getPolicyEngine() - .check(toolCallForPolicy, undefined); // Server name undefined for local tools + .check(toolCallForPolicy, serverName); if (decision === PolicyDecision.DENY) { const errorMessage = `Tool execution denied by policy.`; diff --git a/packages/core/src/policy/policy-engine.test.ts b/packages/core/src/policy/policy-engine.test.ts index 33dc77f00f..c30681a429 100644 --- a/packages/core/src/policy/policy-engine.test.ts +++ b/packages/core/src/policy/policy-engine.test.ts @@ -109,6 +109,37 @@ describe('PolicyEngine', () => { ); }); + it('should match unqualified tool names with qualified rules when serverName is provided', async () => { + const rules: PolicyRule[] = [ + { + toolName: 'my-server__tool', + decision: PolicyDecision.ALLOW, + }, + ]; + + engine = new PolicyEngine({ rules }); + + // Match with qualified name (standard) + expect( + (await engine.check({ name: 'my-server__tool' }, 'my-server')).decision, + ).toBe(PolicyDecision.ALLOW); + + // Match with unqualified name + serverName (the fix) + expect((await engine.check({ name: 'tool' }, 'my-server')).decision).toBe( + PolicyDecision.ALLOW, + ); + + // Should NOT match with unqualified name but NO serverName + expect((await engine.check({ name: 'tool' }, undefined)).decision).toBe( + PolicyDecision.ASK_USER, + ); + + // Should NOT match with unqualified name but WRONG serverName + expect( + (await engine.check({ name: 'tool' }, 'wrong-server')).decision, + ).toBe(PolicyDecision.ASK_USER); + }); + it('should match by args pattern', async () => { const rules: PolicyRule[] = [ { diff --git a/packages/core/src/policy/policy-engine.ts b/packages/core/src/policy/policy-engine.ts index f90b905938..3394dc5b30 100644 --- a/packages/core/src/policy/policy-engine.ts +++ b/packages/core/src/policy/policy-engine.ts @@ -310,16 +310,22 @@ export class PolicyEngine { let matchedRule: PolicyRule | undefined; let decision: PolicyDecision | undefined; + // For tools with a server name, we want to try matching both the + // original name and the fully qualified name (server__tool). + const toolCallsToTry: FunctionCall[] = [toolCall]; + if (serverName && toolCall.name && !toolCall.name.includes('__')) { + toolCallsToTry.push({ + ...toolCall, + name: `${serverName}__${toolCall.name}`, + }); + } + for (const rule of this.rules) { - if ( - ruleMatches( - rule, - toolCall, - stringifiedArgs, - serverName, - this.approvalMode, - ) - ) { + const match = toolCallsToTry.some((tc) => + ruleMatches(rule, tc, stringifiedArgs, serverName, this.approvalMode), + ); + + if (match) { debugLogger.debug( `[PolicyEngine.check] MATCHED rule: toolName=${rule.toolName}, decision=${rule.decision}, priority=${rule.priority}, argsPattern=${rule.argsPattern?.source || 'none'}`, ); From 304caa4e43aa8032828a00209309007419e5798f Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 13 Jan 2026 06:19:53 -0800 Subject: [PATCH 151/713] fix(cli): refine 'Action Required' indicator and focus hints (#16497) --- packages/cli/src/ui/AppContainer.test.tsx | 121 ++++++++++++++++-- packages/cli/src/ui/AppContainer.tsx | 7 +- .../cli/src/ui/hooks/useGeminiStream.test.tsx | 58 +++++++++ packages/cli/src/ui/hooks/useGeminiStream.ts | 10 +- packages/cli/src/ui/hooks/usePhraseCycler.ts | 2 +- 5 files changed, 184 insertions(+), 14 deletions(-) diff --git a/packages/cli/src/ui/AppContainer.test.tsx b/packages/cli/src/ui/AppContainer.test.tsx index fcaa4e012a..dd648d1975 100644 --- a/packages/cli/src/ui/AppContainer.test.tsx +++ b/packages/cli/src/ui/AppContainer.test.tsx @@ -1238,6 +1238,9 @@ describe('AppContainer State Management', () => { }); it('should show Action Required in title after a delay when shell is awaiting focus', async () => { + const startTime = 1000000; + vi.setSystemTime(startTime); + // Arrange: Set up mock settings with showStatusInTitle enabled const mockSettingsWithTitleEnabled = { ...mockSettings, @@ -1260,8 +1263,12 @@ describe('AppContainer State Management', () => { thought: { subject: 'Executing shell command' }, cancelOngoingRequest: vi.fn(), activePtyId: 'pty-1', + lastOutputTime: 0, }); + vi.spyOn(mockConfig, 'isInteractive').mockReturnValue(true); + vi.spyOn(mockConfig, 'isInteractiveShellEnabled').mockReturnValue(true); + // Act: Render the container (embeddedShellFocused is false by default in state) const { unmount } = renderAppContainer({ settings: mockSettingsWithTitleEnabled, @@ -1275,20 +1282,110 @@ describe('AppContainer State Management', () => { '✦ Executing shell command', ); - // Fast-forward time by 31 seconds + // Fast-forward time by 40 seconds await act(async () => { - vi.advanceTimersByTime(31000); + await vi.advanceTimersByTimeAsync(40000); }); // Now it should show Action Required - await waitFor(() => { - const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => - call[0].includes('\x1b]0;'), - ); - const lastTitle = titleWrites[titleWrites.length - 1][0]; - expect(lastTitle).toContain('✋ Action Required'); + const titleWritesDelayed = mocks.mockStdout.write.mock.calls.filter( + (call) => call[0].includes('\x1b]0;'), + ); + const lastTitle = titleWritesDelayed[titleWritesDelayed.length - 1][0]; + expect(lastTitle).toContain('✋ Action Required'); + + unmount(); + }); + + it('should NOT show Action Required in title if shell is streaming output', async () => { + const startTime = 1000000; + vi.setSystemTime(startTime); + + // Arrange: Set up mock settings with showStatusInTitle enabled + const mockSettingsWithTitleEnabled = { + ...mockSettings, + merged: { + ...mockSettings.merged, + ui: { + ...mockSettings.merged.ui, + showStatusInTitle: true, + hideWindowTitle: false, + }, + }, + } as unknown as LoadedSettings; + + // Mock an active shell pty but not focused + let lastOutputTime = 1000; + mockedUseGeminiStream.mockImplementation(() => ({ + streamingState: 'responding', + submitQuery: vi.fn(), + initError: null, + pendingHistoryItems: [], + thought: { subject: 'Executing shell command' }, + cancelOngoingRequest: vi.fn(), + activePtyId: 'pty-1', + lastOutputTime, + })); + + vi.spyOn(mockConfig, 'isInteractive').mockReturnValue(true); + vi.spyOn(mockConfig, 'isInteractiveShellEnabled').mockReturnValue(true); + + // Act: Render the container + const { unmount, rerender } = renderAppContainer({ + settings: mockSettingsWithTitleEnabled, }); + // Fast-forward time by 20 seconds + await act(async () => { + await vi.advanceTimersByTimeAsync(20000); + }); + + // Update lastOutputTime to simulate new output + lastOutputTime = 21000; + mockedUseGeminiStream.mockImplementation(() => ({ + streamingState: 'responding', + submitQuery: vi.fn(), + initError: null, + pendingHistoryItems: [], + thought: { subject: 'Executing shell command' }, + cancelOngoingRequest: vi.fn(), + activePtyId: 'pty-1', + lastOutputTime, + })); + + // Rerender to propagate the new lastOutputTime + await act(async () => { + rerender(getAppContainer({ settings: mockSettingsWithTitleEnabled })); + }); + + // Fast-forward time by another 20 seconds + // Total time elapsed: 40s. + // Time since last output: 20s. + // It should NOT show Action Required yet. + await act(async () => { + await vi.advanceTimersByTimeAsync(20000); + }); + + const titleWritesAfterOutput = mocks.mockStdout.write.mock.calls.filter( + (call) => call[0].includes('\x1b]0;'), + ); + const lastTitle = + titleWritesAfterOutput[titleWritesAfterOutput.length - 1][0]; + expect(lastTitle).not.toContain('✋ Action Required'); + expect(lastTitle).toContain('✦ Executing shell command'); + + // Fast-forward another 40 seconds (Total 60s since last output) + await act(async () => { + await vi.advanceTimersByTimeAsync(40000); + }); + + // Now it SHOULD show Action Required + const titleWrites = mocks.mockStdout.write.mock.calls.filter((call) => + call[0].includes('\x1b]0;'), + ); + const lastTitleFinal = titleWrites[titleWrites.length - 1][0]; + expect(lastTitleFinal).toContain('✋ Action Required'); + unmount(); }); }); @@ -1992,7 +2089,9 @@ describe('AppContainer State Management', () => { }); // Assert: Verify model is updated - expect(capturedUIState.currentModel).toBe('new-model'); + await waitFor(() => { + expect(capturedUIState.currentModel).toBe('new-model'); + }); unmount!(); }); @@ -2123,7 +2222,9 @@ describe('AppContainer State Management', () => { onCancelSubmit(true); }); - expect(mockSetText).toHaveBeenCalledWith('previous message'); + await waitFor(() => { + expect(mockSetText).toHaveBeenCalledWith('previous message'); + }); unmount!(); }); diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index 5184853e4b..ad5ddc5fed 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -827,10 +827,13 @@ Logging in with Google... Restarting Gemini CLI to continue. lastOutputTimeRef.current = lastOutputTime; }, [lastOutputTime]); - const isShellAwaitingFocus = !!activePtyId && !embeddedShellFocused; + const isShellAwaitingFocus = + !!activePtyId && + !embeddedShellFocused && + config.isInteractiveShellEnabled(); const showShellActionRequired = useInactivityTimer( isShellAwaitingFocus, - isShellAwaitingFocus, + lastOutputTime, SHELL_ACTION_REQUIRED_TITLE_DELAY_MS, ); diff --git a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx index bbf6412bc6..5952508bf8 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx +++ b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx @@ -100,6 +100,8 @@ vi.mock('./useKeypress.js', () => ({ vi.mock('./shellCommandProcessor.js', () => ({ useShellCommandProcessor: vi.fn().mockReturnValue({ handleShellCommand: vi.fn(), + activeShellPtyId: null, + lastShellOutputTime: 0, }), })); @@ -238,6 +240,7 @@ describe('useGeminiStream', () => { mockMarkToolsAsSubmitted, vi.fn(), // setToolCallsForDisplay mockCancelAllToolCalls, + 0, // lastToolOutputTime ]); // Reset mocks for GeminiClient instance methods (startChat and sendMessageStream) @@ -2485,6 +2488,61 @@ describe('useGeminiStream', () => { 'gemini-2.5-flash', ); }); + + it('should update lastOutputTime on Gemini thought and content events', async () => { + vi.useFakeTimers(); + const startTime = 1000000; + vi.setSystemTime(startTime); + + // Mock a stream that yields a thought then content + mockSendMessageStream.mockReturnValue( + (async function* () { + yield { + type: ServerGeminiEventType.Thought, + value: { subject: 'Thinking...', description: '' }, + }; + // Advance time for the next event + vi.advanceTimersByTime(1000); + yield { + type: ServerGeminiEventType.Content, + value: 'Hello', + }; + })(), + ); + + const { result } = renderHook(() => + useGeminiStream( + new MockedGeminiClientClass(mockConfig), + [], + mockAddItem, + mockConfig, + mockLoadedSettings, + mockOnDebugMessage, + mockHandleSlashCommand, + false, + () => 'vscode' as EditorType, + () => {}, + () => Promise.resolve(), + false, + () => {}, + () => {}, + () => {}, + 80, + 24, + ), + ); + + // Submit query + await act(async () => { + await result.current.submitQuery('Test query'); + }); + + // Verify lastOutputTime was updated + // It should be the time of the last event (startTime + 1000) + expect(result.current.lastOutputTime).toBe(startTime + 1000); + + vi.useRealTimers(); + }); }); describe('Loop Detection Confirmation', () => { diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index 113c6a08bf..ec7370ccfa 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -120,6 +120,8 @@ export const useGeminiStream = ( const [thought, setThought] = useState(null); const [pendingHistoryItem, pendingHistoryItemRef, setPendingHistoryItem] = useStateAndRef(null); + const [lastGeminiActivityTime, setLastGeminiActivityTime] = + useState(0); const processedMemoryToolsRef = useRef>(new Set()); const { startNewPrompt, getPromptCount } = useSessionStats(); const storage = config.storage; @@ -839,9 +841,11 @@ export const useGeminiStream = ( for await (const event of stream) { switch (event.type) { case ServerGeminiEventType.Thought: + setLastGeminiActivityTime(Date.now()); setThought(event.value); break; case ServerGeminiEventType.Content: + setLastGeminiActivityTime(Date.now()); geminiMessageBuffer = handleContentEvent( event.value, geminiMessageBuffer, @@ -1371,7 +1375,11 @@ export const useGeminiStream = ( storage, ]); - const lastOutputTime = Math.max(lastToolOutputTime, lastShellOutputTime); + const lastOutputTime = Math.max( + lastToolOutputTime, + lastShellOutputTime, + lastGeminiActivityTime, + ); return { streamingState, diff --git a/packages/cli/src/ui/hooks/usePhraseCycler.ts b/packages/cli/src/ui/hooks/usePhraseCycler.ts index 86a7292152..559aaa4a40 100644 --- a/packages/cli/src/ui/hooks/usePhraseCycler.ts +++ b/packages/cli/src/ui/hooks/usePhraseCycler.ts @@ -38,7 +38,7 @@ export const usePhraseCycler = ( loadingPhrases[0], ); const showShellFocusHint = useInactivityTimer( - isInteractiveShellWaiting && lastOutputTime > 0, + isInteractiveShellWaiting, lastOutputTime, SHELL_FOCUS_HINT_DELAY_MS, ); From a6dca02344bae91108dd7297944203339af96ad0 Mon Sep 17 00:00:00 2001 From: Vedant Mahajan Date: Tue, 13 Jan 2026 22:20:54 +0530 Subject: [PATCH 152/713] Refactor beforeAgent and afterAgent hookEvents to follow desired output (#16495) --- packages/core/src/core/client.test.ts | 80 +++++++-------------------- packages/core/src/core/client.ts | 6 +- packages/core/src/hooks/hookSystem.ts | 11 ++-- 3 files changed, 28 insertions(+), 69 deletions(-) diff --git a/packages/core/src/core/client.test.ts b/packages/core/src/core/client.test.ts index 84418c9855..50ee7f765a 100644 --- a/packages/core/src/core/client.test.ts +++ b/packages/core/src/core/client.test.ts @@ -137,20 +137,8 @@ vi.mock('../telemetry/uiTelemetry.js', () => ({ })); vi.mock('../hooks/hookSystem.js'); const mockHookSystem = { - fireBeforeAgentEvent: vi.fn().mockResolvedValue({ - success: true, - finalOutput: undefined, - allOutputs: [], - errors: [], - totalDuration: 0, - }), - fireAfterAgentEvent: vi.fn().mockResolvedValue({ - success: true, - finalOutput: undefined, - allOutputs: [], - errors: [], - totalDuration: 0, - }), + fireBeforeAgentEvent: vi.fn().mockResolvedValue(undefined), + fireAfterAgentEvent: vi.fn().mockResolvedValue(undefined), }; /** @@ -2812,15 +2800,9 @@ ${JSON.stringify( it('should stop execution in BeforeAgent when hook returns continue: false', async () => { mockHookSystem.fireBeforeAgentEvent.mockResolvedValue({ - success: true, - finalOutput: { - shouldStopExecution: () => true, - getEffectiveReason: () => 'Stopped by hook', - systemMessage: undefined, - }, - allOutputs: [], - errors: [], - totalDuration: 0, + shouldStopExecution: () => true, + getEffectiveReason: () => 'Stopped by hook', + systemMessage: undefined, }); const mockChat: Partial = { @@ -2851,16 +2833,10 @@ ${JSON.stringify( it('should block execution in BeforeAgent when hook returns decision: block', async () => { mockHookSystem.fireBeforeAgentEvent.mockResolvedValue({ - success: true, - finalOutput: { - shouldStopExecution: () => false, - isBlockingDecision: () => true, - getEffectiveReason: () => 'Blocked by hook', - systemMessage: undefined, - }, - allOutputs: [], - errors: [], - totalDuration: 0, + shouldStopExecution: () => false, + isBlockingDecision: () => true, + getEffectiveReason: () => 'Blocked by hook', + systemMessage: undefined, }); const mockChat: Partial = { @@ -2890,15 +2866,9 @@ ${JSON.stringify( it('should stop execution in AfterAgent when hook returns continue: false', async () => { mockHookSystem.fireAfterAgentEvent.mockResolvedValue({ - success: true, - finalOutput: { - shouldStopExecution: () => true, - getEffectiveReason: () => 'Stopped after agent', - systemMessage: undefined, - }, - allOutputs: [], - errors: [], - totalDuration: 0, + shouldStopExecution: () => true, + getEffectiveReason: () => 'Stopped after agent', + systemMessage: undefined, }); mockTurnRunFn.mockImplementation(async function* () { @@ -2923,27 +2893,15 @@ ${JSON.stringify( it('should yield AgentExecutionBlocked and recurse in AfterAgent when hook returns decision: block', async () => { mockHookSystem.fireAfterAgentEvent .mockResolvedValueOnce({ - success: true, - finalOutput: { - shouldStopExecution: () => false, - isBlockingDecision: () => true, - getEffectiveReason: () => 'Please explain', - systemMessage: undefined, - }, - allOutputs: [], - errors: [], - totalDuration: 0, + shouldStopExecution: () => false, + isBlockingDecision: () => true, + getEffectiveReason: () => 'Please explain', + systemMessage: undefined, }) .mockResolvedValueOnce({ - success: true, - finalOutput: { - shouldStopExecution: () => false, - isBlockingDecision: () => false, - systemMessage: undefined, - }, - allOutputs: [], - errors: [], - totalDuration: 0, + shouldStopExecution: () => false, + isBlockingDecision: () => false, + systemMessage: undefined, }); mockTurnRunFn.mockImplementation(async function* () { diff --git a/packages/core/src/core/client.ts b/packages/core/src/core/client.ts index 535bf15ce7..dbf81aee2f 100644 --- a/packages/core/src/core/client.ts +++ b/packages/core/src/core/client.ts @@ -133,10 +133,9 @@ export class GeminiClient { return undefined; } - const hookResult = await this.config + const hookOutput = await this.config .getHookSystem() ?.fireBeforeAgentEvent(partToString(request)); - const hookOutput = hookResult?.finalOutput; hookState.hasFiredBeforeAgent = true; if (hookOutput?.shouldStopExecution()) { @@ -187,10 +186,9 @@ export class GeminiClient { '[no response text]'; const finalRequest = hookState.originalRequest || currentRequest; - const hookResult = await this.config + const hookOutput = await this.config .getHookSystem() ?.fireAfterAgentEvent(partToString(finalRequest), finalResponseText); - const hookOutput = hookResult?.finalOutput; return hookOutput; } diff --git a/packages/core/src/hooks/hookSystem.ts b/packages/core/src/hooks/hookSystem.ts index 547b44a923..7d5e7783f8 100644 --- a/packages/core/src/hooks/hookSystem.ts +++ b/packages/core/src/hooks/hookSystem.ts @@ -18,6 +18,7 @@ import type { SessionStartSource, SessionEndReason, PreCompressTrigger, + DefaultHookOutput, } from './types.js'; import type { AggregatedHookResult } from './hookAggregator.js'; /** @@ -120,25 +121,27 @@ export class HookSystem { async fireBeforeAgentEvent( prompt: string, - ): Promise { + ): Promise { if (!this.config.getEnableHooks()) { return undefined; } - return this.hookEventHandler.fireBeforeAgentEvent(prompt); + const result = await this.hookEventHandler.fireBeforeAgentEvent(prompt); + return result.finalOutput; } async fireAfterAgentEvent( prompt: string, response: string, stopHookActive: boolean = false, - ): Promise { + ): Promise { if (!this.config.getEnableHooks()) { return undefined; } - return this.hookEventHandler.fireAfterAgentEvent( + const result = await this.hookEventHandler.fireAfterAgentEvent( prompt, response, stopHookActive, ); + return result.finalOutput; } } From 8faa23cea6c67fb75740a53f333f2de8f4656371 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 13 Jan 2026 09:44:52 -0800 Subject: [PATCH 153/713] feat(agents): clarify mandatory YAML frontmatter for sub-agents (#16515) --- packages/core/src/agents/agentLoader.test.ts | 2 +- packages/core/src/agents/agentLoader.ts | 2 +- packages/core/src/agents/cli-help-agent.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/agents/agentLoader.test.ts b/packages/core/src/agents/agentLoader.test.ts index eb642a7eb5..199d715fe9 100644 --- a/packages/core/src/agents/agentLoader.test.ts +++ b/packages/core/src/agents/agentLoader.test.ts @@ -83,7 +83,7 @@ System prompt content.`); AgentLoadError, ); await expect(parseAgentMarkdown(filePath)).rejects.toThrow( - 'Invalid markdown format', + 'Missing mandatory YAML frontmatter', ); }); diff --git a/packages/core/src/agents/agentLoader.ts b/packages/core/src/agents/agentLoader.ts index 5a65f03218..f8283c1933 100644 --- a/packages/core/src/agents/agentLoader.ts +++ b/packages/core/src/agents/agentLoader.ts @@ -163,7 +163,7 @@ export async function parseAgentMarkdown( if (!match) { throw new AgentLoadError( filePath, - 'Invalid markdown format. File must start with YAML frontmatter enclosed in "---".', + 'Invalid agent definition: Missing mandatory YAML frontmatter. Agent Markdown files MUST start with YAML frontmatter enclosed in triple-dashes "---" (e.g., ---\nname: my-agent\n---).', ); } diff --git a/packages/core/src/agents/cli-help-agent.ts b/packages/core/src/agents/cli-help-agent.ts index cf65819252..ea6709ca86 100644 --- a/packages/core/src/agents/cli-help-agent.ts +++ b/packages/core/src/agents/cli-help-agent.ts @@ -78,7 +78,7 @@ export const CliHelpAgent = ( "- **Today's Date:** ${today}\n\n" + (config.isAgentsEnabled() ? '### Sub-Agents (Local & Remote)\n' + - "User defined sub-agents are defined in `.gemini/agents/` or `~/.gemini/agents/` as .md files. These files contain YAML frontmatter for metadata, and the Markdown body becomes the agent's system prompt (`system_prompt`). Always reference the types and properties outlined here directly when answering questions about sub-agents.\n" + + "User defined sub-agents are defined in `.gemini/agents/` or `~/.gemini/agents/` as .md files. **CRITICAL:** These files **MUST** start with YAML frontmatter enclosed in triple-dashes `---`, for example:\n\n```yaml\n---\nname: my-agent\n---\n```\n\nWithout this mandatory frontmatter, the agent will not be discovered or loaded by Gemini CLI. The Markdown body following the frontmatter becomes the agent's system prompt (`system_prompt`). Always reference the types and properties outlined here directly when answering questions about sub-agents.\n" + '- **Local Agent:** `kind = "local"`, `name`, `description`, `system_prompt`, and optional `tools`, `model`, `temperate`, `max_turns`, `timeout_mins`.\n' + '- **Remote Agent (A2A):** `kind = "remote"`, `name`, `agent_card_url`. Remote Agents do not use `system_prompt`. Multiple remote agents can be defined by using a YAML array at the top level of the frontmatter. **Note:** When users ask about "remote agents", they are referring to this Agent2Agent functionality, which is completely distinct from MCP servers.\n' + '- **Agent Names:** Must be valid slugs (lowercase letters, numbers, hyphens, and underscores only).\n' + From 0f7a136612ef49f812f8c516a58df88cc4675c4a Mon Sep 17 00:00:00 2001 From: Jerop Kipruto Date: Tue, 13 Jan 2026 13:10:34 -0500 Subject: [PATCH 154/713] docs(telemetry): add Google Cloud Monitoring dashboard documentation (#16520) --- docs/assets/monitoring-dashboard-logs.png | Bin 0 -> 112499 bytes docs/assets/monitoring-dashboard-metrics.png | Bin 0 -> 58937 bytes docs/assets/monitoring-dashboard-overview.png | Bin 0 -> 55791 bytes docs/cli/telemetry.md | 20 ++++++++++++++++++ 4 files changed, 20 insertions(+) create mode 100644 docs/assets/monitoring-dashboard-logs.png create mode 100644 docs/assets/monitoring-dashboard-metrics.png create mode 100644 docs/assets/monitoring-dashboard-overview.png diff --git a/docs/assets/monitoring-dashboard-logs.png b/docs/assets/monitoring-dashboard-logs.png new file mode 100644 index 0000000000000000000000000000000000000000..e0d36ad327d4dedba84ec10134f43838192da51e GIT binary patch literal 112499 zcmZs@Wmp_dw>6BryEAxj0t9z=cXxLuxVyU(fCz%9`Yl4XCq{xDZIy zB*D?g2N6>ZNi$hl5SovD7!c4fOAv@Zr+mEdK3*S}=YxWPe{4bje3uXQpQGS_eDMG5 zgPi|4kzTYr3j{;}L{dah#RK%T1KL|>$d%E%>Ab+*AA*}&N`+C)F=?N4pvh*4!ZYG` ze}uFV)s`2dC*uS)qo;nScNh6&l=N4}2O(Cq~}I!%fJDk^}g z0P#OJOfV1XaL{e>yO$m^sVg>WzlO}Km#oil4f;IuMocd0D6^+rWcnHwKmXv4xpmi< z9&-yj>iA#3?oaB#NowGEIk5QZy~m0}rrih3+aq@pTNwTgNF1xvVQQ1O4= z_v0x7QiSu98K;DJE)K9U4`_>6b&sxfEDtdSPNg8!Ne-Nv@~f&CB>4DN8p<{*4caey z;hoNOsvDY{$8MMOseF8VcJH5y%F4>(7vlV0&|$;+oYric@%XD;vN@f_VhQ;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t z*VXS_T1OhMmC|nSw%lU*)qSpdfAvN2Txq{vN4>B4#`Aybb(H7J_w{E=zsh%)d+l9s zxxds??_2rqR(QQ82c)k7BFL>wl&b$2^P|k%*LZKmYsRSDNTw}3a6RaABloLBjj)nraA_dC&xGD$a3I|+dfXA*>Zk1=R^tmhS;&r*b^tE2uK>J;PcA(GH+qs$V zucfco^6bqVqqZtldue_9v5!Ru!^j>;xebu$ZRQm6LwquIzvm!a48P9lwc? zapNQVTNj>b-Zd0xD9})#p}=R10y5b+THwc~z01(shQ#kSj>YdbMpVYjrR}iZk2aqh z3N#dGD9}*gQ%V8ni|CD<$u53eUoZJb==BRS3b?uPK+|{>J#$m@5g*J00000NkvXXu0mjf(KR#m literal 0 HcmV?d00001 diff --git a/docs/assets/monitoring-dashboard-metrics.png b/docs/assets/monitoring-dashboard-metrics.png new file mode 100644 index 0000000000000000000000000000000000000000..7a4a1e221ec329623d9d34befd138161cf95d95b GIT binary patch literal 58937 zcmZsDbwC^6x-FyuQrw|Pad#{3?i6=|yL)jjR@{pfE5(AlyHlV@aVzfbFa6zn-o5Xf z_eV05WM?w_`}Vi?T5HcFQbkD`1(5&|1_lO2Rz^Y<2IdVZbpHYb4}Gq8$o~o5z`CkR zi@{V*5bZ->NSJHOS|}>Q&_nk@Ft8EUFu=b}pbrA*1N!wmSeQ4^E$rX-@&Nz(^bKj= zn}6-YT>NcV&z1BY21W!%Rzg(W3-+kp(k*+~oBD2(dRqpDQUnv&t?*&7xyYeWSBFU_ zk!oqH+EbAKeHHiJ;7f*}&qU7F)(QuIEC0>WS3wS2pLtWNCB#&sU>S)o+z3aPvz|zIPTmP8a3Z0NE!~e{5A*^W*K=7vet>aBIcWh=f#i9h|Gk00 zg1kPEqK%7Tr~t8HB}M-CCL|D%^f$)8zbgsuMIVxfarSXM|Lxal%rzDBpDjj7RbcW( z=L79B{!9nc|J$$X5eAjxqK{CPs@n`_vP~>3G*KqWVmVq^NCkK2RR>dIMmF#IPWoiM z@2ovN=6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b4h=bM/otel/collector-gcp.log` to view local collector logs. +### Monitoring Dashboards + +Gemini CLI provides a pre-configured +[Google Cloud Monitoring](https://cloud.google.com/monitoring) dashboard to +visualize your telemetry. + +This dashboard can be found under **Google Cloud Monitoring Dashboard +Templates** as "**Gemini CLI Monitoring**". + +![Gemini CLI Monitoring Dashboard Overview](../assets/monitoring-dashboard-overview.png) + +![Gemini CLI Monitoring Dashboard Metrics](../assets/monitoring-dashboard-metrics.png) + +![Gemini CLI Monitoring Dashboard Logs](../assets/monitoring-dashboard-logs.png) + +To learn more, check out this blog post: +[Instant insights: Gemini CLI’s new pre-configured monitoring dashboards](https://cloud.google.com/blog/topics/developers-practitioners/instant-insights-gemini-clis-new-pre-configured-monitoring-dashboards/). + ## Local telemetry For local development and debugging, you can capture telemetry data locally: From aa524625503ff15029c744864936afb55076d6e9 Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Tue, 13 Jan 2026 19:09:22 +0000 Subject: [PATCH 155/713] Implement support for subagents as extensions. (#16473) --- .../config/extension-manager-agents.test.ts | 140 ++++++++++++++++++ packages/cli/src/config/extension-manager.ts | 13 ++ packages/core/src/agents/registry.test.ts | 58 +++++++- packages/core/src/agents/registry.ts | 12 +- packages/core/src/config/config.ts | 2 + packages/core/src/index.ts | 1 + 6 files changed, 223 insertions(+), 3 deletions(-) create mode 100644 packages/cli/src/config/extension-manager-agents.test.ts diff --git a/packages/cli/src/config/extension-manager-agents.test.ts b/packages/cli/src/config/extension-manager-agents.test.ts new file mode 100644 index 0000000000..936d3fea10 --- /dev/null +++ b/packages/cli/src/config/extension-manager-agents.test.ts @@ -0,0 +1,140 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import * as os from 'node:os'; +import { ExtensionManager } from './extension-manager.js'; +import { debugLogger } from '@google/gemini-cli-core'; +import { type Settings } from './settings.js'; +import { createExtension } from '../test-utils/createExtension.js'; +import { EXTENSIONS_DIRECTORY_NAME } from './extensions/variables.js'; + +const mockHomedir = vi.hoisted(() => vi.fn(() => '/tmp/mock-home')); + +vi.mock('node:os', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + homedir: mockHomedir, + }; +}); + +// Mock @google/gemini-cli-core +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + homedir: mockHomedir, + }; +}); + +describe('ExtensionManager agents loading', () => { + let extensionManager: ExtensionManager; + let tempDir: string; + let extensionsDir: string; + + beforeEach(() => { + vi.clearAllMocks(); + vi.spyOn(debugLogger, 'warn').mockImplementation(() => {}); + + tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gemini-test-agents-')); + mockHomedir.mockReturnValue(tempDir); + + // Create the extensions directory that ExtensionManager expects + extensionsDir = path.join(tempDir, '.gemini', EXTENSIONS_DIRECTORY_NAME); + fs.mkdirSync(extensionsDir, { recursive: true }); + + extensionManager = new ExtensionManager({ + settings: { + telemetry: { enabled: false }, + trustedFolders: [tempDir], + } as unknown as Settings, + requestConsent: vi.fn().mockResolvedValue(true), + requestSetting: vi.fn(), + workspaceDir: tempDir, + }); + }); + + afterEach(() => { + try { + fs.rmSync(tempDir, { recursive: true, force: true }); + } catch { + // ignore + } + }); + + it('should load agents from an extension', async () => { + const sourceDir = path.join(tempDir, 'source-ext-good'); + createExtension({ + extensionsDir: sourceDir, + name: 'good-agents-ext', + version: '1.0.0', + installMetadata: { + type: 'local', + source: path.join(sourceDir, 'good-agents-ext'), + }, + }); + const extensionPath = path.join(sourceDir, 'good-agents-ext'); + + const agentsDir = path.join(extensionPath, 'agents'); + fs.mkdirSync(agentsDir, { recursive: true }); + fs.writeFileSync( + path.join(agentsDir, 'test-agent.md'), + '---\nname: test-agent\nkind: local\ndescription: test desc\n---\nbody', + ); + + await extensionManager.loadExtensions(); + + const extension = await extensionManager.installOrUpdateExtension({ + type: 'local', + source: extensionPath, + }); + + expect(extension.name).toBe('good-agents-ext'); + expect(extension.agents).toBeDefined(); + expect(extension.agents).toHaveLength(1); + expect(extension.agents![0].name).toBe('test-agent'); + expect(debugLogger.warn).not.toHaveBeenCalled(); + }); + + it('should log errors but continue if an agent fails to load', async () => { + const sourceDir = path.join(tempDir, 'source-ext-bad'); + createExtension({ + extensionsDir: sourceDir, + name: 'bad-agents-ext', + version: '1.0.0', + installMetadata: { + type: 'local', + source: path.join(sourceDir, 'bad-agents-ext'), + }, + }); + const extensionPath = path.join(sourceDir, 'bad-agents-ext'); + + const agentsDir = path.join(extensionPath, 'agents'); + fs.mkdirSync(agentsDir, { recursive: true }); + // Invalid agent (missing description) + fs.writeFileSync( + path.join(agentsDir, 'bad-agent.md'), + '---\nname: bad-agent\nkind: local\n---\nbody', + ); + + await extensionManager.loadExtensions(); + + const extension = await extensionManager.installOrUpdateExtension({ + type: 'local', + source: extensionPath, + }); + + expect(extension.name).toBe('bad-agents-ext'); + expect(extension.agents).toEqual([]); + expect(debugLogger.warn).toHaveBeenCalledWith( + expect.stringContaining('Error loading agent from bad-agents-ext'), + ); + }); +}); diff --git a/packages/cli/src/config/extension-manager.ts b/packages/cli/src/config/extension-manager.ts index d979692441..fafa801bf2 100644 --- a/packages/cli/src/config/extension-manager.ts +++ b/packages/cli/src/config/extension-manager.ts @@ -38,6 +38,7 @@ import { logExtensionUninstall, logExtensionUpdateEvent, loadSkillsFromDir, + loadAgentsFromDirectory, homedir, type ExtensionEvents, type MCPServerConfig, @@ -615,6 +616,17 @@ Would you like to attempt to install via "git clone" instead?`, path.join(effectiveExtensionPath, 'skills'), ); + const agentLoadResult = await loadAgentsFromDirectory( + path.join(effectiveExtensionPath, 'agents'), + ); + + // Log errors but don't fail the entire extension load + for (const error of agentLoadResult.errors) { + debugLogger.warn( + `[ExtensionManager] Error loading agent from ${config.name}: ${error.message}`, + ); + } + const extension: GeminiCLIExtension = { name: config.name, version: config.version, @@ -632,6 +644,7 @@ Would you like to attempt to install via "git clone" instead?`, settings: config.settings, resolvedSettings, skills, + agents: agentLoadResult.agents, }; this.loadedExtensions = [...this.loadedExtensions, extension]; diff --git a/packages/core/src/agents/registry.test.ts b/packages/core/src/agents/registry.test.ts index 42a6aab25b..95d0f925eb 100644 --- a/packages/core/src/agents/registry.test.ts +++ b/packages/core/src/agents/registry.test.ts @@ -8,7 +8,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { AgentRegistry, getModelConfigAlias } from './registry.js'; import { makeFakeConfig } from '../test-utils/config.js'; import type { AgentDefinition, LocalAgentDefinition } from './types.js'; -import type { Config } from '../config/config.js'; +import type { Config, GeminiCLIExtension } from '../config/config.js'; import { debugLogger } from '../utils/debugLogger.js'; import { coreEvents, CoreEvent } from '../utils/events.js'; import { A2AClientManager } from './a2a-client-manager.js'; @@ -20,6 +20,7 @@ import { PREVIEW_GEMINI_MODEL_AUTO, } from '../config/models.js'; import * as tomlLoader from './agentLoader.js'; +import { SimpleExtensionLoader } from '../utils/extensionLoader.js'; vi.mock('./agentLoader.js', () => ({ loadAgentsFromDirectory: vi @@ -230,7 +231,7 @@ describe('AgentRegistry', () => { expect(registry.getDefinition('cli_help')).toBeDefined(); }); - it('should NOT register CLI help agent if disabled', async () => { + it('should register CLI help agent if disabled', async () => { const config = makeFakeConfig({ cliHelpAgentSettings: { enabled: false }, }); @@ -240,6 +241,59 @@ describe('AgentRegistry', () => { expect(registry.getDefinition('cli_help')).toBeUndefined(); }); + + it('should load agents from active extensions', async () => { + const extensionAgent = { + ...MOCK_AGENT_V1, + name: 'extension-agent', + }; + const extensions: GeminiCLIExtension[] = [ + { + name: 'test-extension', + isActive: true, + agents: [extensionAgent], + version: '1.0.0', + path: '/path/to/extension', + contextFiles: [], + id: 'test-extension-id', + }, + ]; + const mockConfig = makeFakeConfig({ + extensionLoader: new SimpleExtensionLoader(extensions), + enableAgents: true, + }); + const registry = new TestableAgentRegistry(mockConfig); + + await registry.initialize(); + + expect(registry.getDefinition('extension-agent')).toEqual(extensionAgent); + }); + + it('should NOT load agents from inactive extensions', async () => { + const extensionAgent = { + ...MOCK_AGENT_V1, + name: 'extension-agent', + }; + const extensions: GeminiCLIExtension[] = [ + { + name: 'test-extension', + isActive: false, + agents: [extensionAgent], + version: '1.0.0', + path: '/path/to/extension', + contextFiles: [], + id: 'test-extension-id', + }, + ]; + const mockConfig = makeFakeConfig({ + extensionLoader: new SimpleExtensionLoader(extensions), + }); + const registry = new TestableAgentRegistry(mockConfig); + + await registry.initialize(); + + expect(registry.getDefinition('extension-agent')).toBeUndefined(); + }); }); describe('registration logic', () => { diff --git a/packages/core/src/agents/registry.ts b/packages/core/src/agents/registry.ts index 71cb1442cc..cd3065e0f6 100644 --- a/packages/core/src/agents/registry.ts +++ b/packages/core/src/agents/registry.ts @@ -14,6 +14,7 @@ import { CliHelpAgent } from './cli-help-agent.js'; import { A2AClientManager } from './a2a-client-manager.js'; import { ADCHandler } from './remote-invocation.js'; import { type z } from 'zod'; +import type { GenerateContentConfig } from '@google/genai'; import { debugLogger } from '../utils/debugLogger.js'; import { DEFAULT_GEMINI_MODEL, @@ -120,6 +121,15 @@ export class AgentRegistry { ); } + // Load agents from extensions + for (const extension of this.config.getExtensions()) { + if (extension.isActive && extension.agents) { + await Promise.allSettled( + extension.agents.map((agent) => this.registerAgent(agent)), + ); + } + } + if (this.config.getDebugMode()) { debugLogger.log( `[AgentRegistry] Loaded with ${this.agents.size} agents.`, @@ -233,7 +243,7 @@ export class AgentRegistry { model = this.config.getModel(); } - const generateContentConfig = { + const generateContentConfig: GenerateContentConfig = { temperature: modelConfig.temp, topP: modelConfig.top_p, thinkingConfig: { diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 6c57be29ab..02d73b1b6b 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -101,6 +101,7 @@ import { ExperimentFlags } from '../code_assist/experiments/flagNames.js'; import { debugLogger } from '../utils/debugLogger.js'; import { SkillManager, type SkillDefinition } from '../skills/skillManager.js'; import { startupProfiler } from '../telemetry/startupProfiler.js'; +import type { AgentDefinition } from '../agents/types.js'; export interface AccessibilitySettings { disableLoadingPhrases?: boolean; @@ -178,6 +179,7 @@ export interface GeminiCLIExtension { settings?: ExtensionSetting[]; resolvedSettings?: ResolvedExtensionSetting[]; skills?: SkillDefinition[]; + agents?: AgentDefinition[]; } export interface ExtensionInstallMetadata { diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index d587d3f221..a42ea862f2 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -126,6 +126,7 @@ export * from './prompts/mcp-prompts.js'; // Export agent definitions export * from './agents/types.js'; +export * from './agents/agentLoader.js'; // Export specific tool logic export * from './tools/read-file.js'; From 91fcca3b1c77590c500d27350dff9c2dbb1d0c21 Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Tue, 13 Jan 2026 14:15:04 -0500 Subject: [PATCH 156/713] refactor: make baseTimestamp optional in addItem and remove redundant calls (#16471) --- .../cli/src/ui/commands/aboutCommand.test.ts | 28 +- packages/cli/src/ui/commands/aboutCommand.ts | 2 +- .../cli/src/ui/commands/agentsCommand.test.ts | 1 - packages/cli/src/ui/commands/agentsCommand.ts | 13 +- .../cli/src/ui/commands/chatCommand.test.ts | 29 +- packages/cli/src/ui/commands/chatCommand.ts | 2 +- .../src/ui/commands/directoryCommand.test.tsx | 9 - .../cli/src/ui/commands/directoryCommand.tsx | 99 ++--- .../src/ui/commands/extensionsCommand.test.ts | 326 ++++++--------- .../cli/src/ui/commands/extensionsCommand.ts | 374 +++++++----------- .../cli/src/ui/commands/helpCommand.test.ts | 1 - packages/cli/src/ui/commands/helpCommand.ts | 2 +- .../cli/src/ui/commands/hooksCommand.test.ts | 4 - packages/cli/src/ui/commands/hooksCommand.ts | 2 +- .../cli/src/ui/commands/mcpCommand.test.ts | 3 - packages/cli/src/ui/commands/mcpCommand.ts | 48 +-- .../cli/src/ui/commands/skillsCommand.test.ts | 13 - packages/cli/src/ui/commands/skillsCommand.ts | 105 ++--- .../cli/src/ui/commands/statsCommand.test.ts | 30 +- packages/cli/src/ui/commands/statsCommand.ts | 31 +- .../cli/src/ui/commands/toolsCommand.test.ts | 24 +- packages/cli/src/ui/commands/toolsCommand.ts | 13 +- .../MultiFolderTrustDialog.test.tsx | 13 +- .../ui/components/MultiFolderTrustDialog.tsx | 18 +- .../cli/src/ui/hooks/useGeminiStream.test.tsx | 69 ++-- packages/cli/src/ui/hooks/useGeminiStream.ts | 113 ++---- .../src/ui/hooks/useHistoryManager.test.ts | 19 + .../cli/src/ui/hooks/useHistoryManager.ts | 4 +- .../src/ui/hooks/useIncludeDirsTrust.test.tsx | 3 +- .../cli/src/ui/hooks/useIncludeDirsTrust.tsx | 18 +- 30 files changed, 528 insertions(+), 888 deletions(-) diff --git a/packages/cli/src/ui/commands/aboutCommand.test.ts b/packages/cli/src/ui/commands/aboutCommand.test.ts index b21dfa5233..9b93641958 100644 --- a/packages/cli/src/ui/commands/aboutCommand.test.ts +++ b/packages/cli/src/ui/commands/aboutCommand.test.ts @@ -87,20 +87,17 @@ describe('aboutCommand', () => { await aboutCommand.action(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ABOUT, - cliVersion: 'test-version', - osVersion: 'test-os', - sandboxEnv: 'no sandbox', - modelVersion: 'test-model', - selectedAuthType: 'test-auth', - gcpProject: 'test-gcp-project', - ideClient: 'test-ide', - userEmail: 'test-email@example.com', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ABOUT, + cliVersion: 'test-version', + osVersion: 'test-os', + sandboxEnv: 'no sandbox', + modelVersion: 'test-model', + selectedAuthType: 'test-auth', + gcpProject: 'test-gcp-project', + ideClient: 'test-ide', + userEmail: 'test-email@example.com', + }); }); it('should show the correct sandbox environment variable', async () => { @@ -115,7 +112,6 @@ describe('aboutCommand', () => { expect.objectContaining({ sandboxEnv: 'gemini-sandbox', }), - expect.any(Number), ); }); @@ -132,7 +128,6 @@ describe('aboutCommand', () => { expect.objectContaining({ sandboxEnv: 'sandbox-exec (test-profile)', }), - expect.any(Number), ); }); @@ -159,7 +154,6 @@ describe('aboutCommand', () => { gcpProject: 'test-gcp-project', ideClient: '', }), - expect.any(Number), ); }); }); diff --git a/packages/cli/src/ui/commands/aboutCommand.ts b/packages/cli/src/ui/commands/aboutCommand.ts index 9b4cc34d0c..46589a0c99 100644 --- a/packages/cli/src/ui/commands/aboutCommand.ts +++ b/packages/cli/src/ui/commands/aboutCommand.ts @@ -56,7 +56,7 @@ export const aboutCommand: SlashCommand = { userEmail, }; - context.ui.addItem(aboutItem, Date.now()); + context.ui.addItem(aboutItem); }, }; diff --git a/packages/cli/src/ui/commands/agentsCommand.test.ts b/packages/cli/src/ui/commands/agentsCommand.test.ts index 5c1fe5892d..bc84252cf2 100644 --- a/packages/cli/src/ui/commands/agentsCommand.test.ts +++ b/packages/cli/src/ui/commands/agentsCommand.test.ts @@ -79,7 +79,6 @@ describe('agentsCommand', () => { type: MessageType.AGENTS_LIST, agents: mockAgents, }), - expect.any(Number), ); }); diff --git a/packages/cli/src/ui/commands/agentsCommand.ts b/packages/cli/src/ui/commands/agentsCommand.ts index 690396b798..5059fc1937 100644 --- a/packages/cli/src/ui/commands/agentsCommand.ts +++ b/packages/cli/src/ui/commands/agentsCommand.ts @@ -44,7 +44,7 @@ const agentsListCommand: SlashCommand = { agents, }; - context.ui.addItem(agentsListItem, Date.now()); + context.ui.addItem(agentsListItem); return; }, @@ -65,13 +65,10 @@ const agentsRefreshCommand: SlashCommand = { }; } - context.ui.addItem( - { - type: MessageType.INFO, - text: 'Refreshing agent registry...', - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: 'Refreshing agent registry...', + }); await agentRegistry.reload(); diff --git a/packages/cli/src/ui/commands/chatCommand.test.ts b/packages/cli/src/ui/commands/chatCommand.test.ts index 6edae787d2..6ff8d8a52e 100644 --- a/packages/cli/src/ui/commands/chatCommand.test.ts +++ b/packages/cli/src/ui/commands/chatCommand.test.ts @@ -127,22 +127,19 @@ describe('chatCommand', () => { await listCommand?.action?.(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: 'chat_list', - chats: [ - { - name: 'test1', - mtime: date1.toISOString(), - }, - { - name: 'test2', - mtime: date2.toISOString(), - }, - ], - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: 'chat_list', + chats: [ + { + name: 'test1', + mtime: date1.toISOString(), + }, + { + name: 'test2', + mtime: date2.toISOString(), + }, + ], + }); }); }); describe('save subcommand', () => { diff --git a/packages/cli/src/ui/commands/chatCommand.ts b/packages/cli/src/ui/commands/chatCommand.ts index 89a770e1f8..3dafe59554 100644 --- a/packages/cli/src/ui/commands/chatCommand.ts +++ b/packages/cli/src/ui/commands/chatCommand.ts @@ -81,7 +81,7 @@ const listCommand: SlashCommand = { chats: chatDetails, }; - context.ui.addItem(item, Date.now()); + context.ui.addItem(item); }, }; diff --git a/packages/cli/src/ui/commands/directoryCommand.test.tsx b/packages/cli/src/ui/commands/directoryCommand.test.tsx index 1c43149440..45ddd6fbe2 100644 --- a/packages/cli/src/ui/commands/directoryCommand.test.tsx +++ b/packages/cli/src/ui/commands/directoryCommand.test.tsx @@ -94,7 +94,6 @@ describe('directoryCommand', () => { '/home/user/project1', )}\n- ${path.normalize('/home/user/project2')}`, }), - expect.any(Number), ); }); }); @@ -121,7 +120,6 @@ describe('directoryCommand', () => { type: MessageType.ERROR, text: 'Please provide at least one path to add.', }), - expect.any(Number), ); }); @@ -135,7 +133,6 @@ describe('directoryCommand', () => { type: MessageType.INFO, text: `Successfully added directories:\n- ${newPath}`, }), - expect.any(Number), ); }); @@ -151,7 +148,6 @@ describe('directoryCommand', () => { type: MessageType.INFO, text: `Successfully added directories:\n- ${newPath1}\n- ${newPath2}`, }), - expect.any(Number), ); }); @@ -168,7 +164,6 @@ describe('directoryCommand', () => { type: MessageType.ERROR, text: `Error adding '${newPath}': ${error.message}`, }), - expect.any(Number), ); }); @@ -191,7 +186,6 @@ describe('directoryCommand', () => { type: MessageType.INFO, text: `The following directories are already in the workspace:\n- ${existingPath}`, }), - expect.any(Number), ); expect(mockWorkspaceContext.addDirectory).not.toHaveBeenCalledWith( existingPath, @@ -218,7 +212,6 @@ describe('directoryCommand', () => { type: MessageType.INFO, text: `Successfully added directories:\n- ${validPath}`, }), - expect.any(Number), ); expect(mockContext.ui.addItem).toHaveBeenCalledWith( @@ -226,7 +219,6 @@ describe('directoryCommand', () => { type: MessageType.ERROR, text: `Error adding '${invalidPath}': ${error.message}`, }), - expect.any(Number), ); }); @@ -317,7 +309,6 @@ describe('directoryCommand', () => { type: MessageType.ERROR, text: expect.stringContaining('explicitly untrusted'), }), - expect.any(Number), ); }); diff --git a/packages/cli/src/ui/commands/directoryCommand.tsx b/packages/cli/src/ui/commands/directoryCommand.tsx index 872945ecea..c3c56d46f2 100644 --- a/packages/cli/src/ui/commands/directoryCommand.tsx +++ b/packages/cli/src/ui/commands/directoryCommand.tsx @@ -22,18 +22,18 @@ import type { Config } from '@google/gemini-cli-core'; async function finishAddingDirectories( config: Config, - addItem: (itemData: Omit, baseTimestamp: number) => number, + addItem: ( + itemData: Omit, + baseTimestamp?: number, + ) => number, added: string[], errors: string[], ) { if (!config) { - addItem( - { - type: MessageType.ERROR, - text: 'Configuration is not available.', - }, - Date.now(), - ); + addItem({ + type: MessageType.ERROR, + text: 'Configuration is not available.', + }); return; } @@ -41,13 +41,10 @@ async function finishAddingDirectories( if (config.shouldLoadMemoryFromIncludeDirectories()) { await refreshServerHierarchicalMemory(config); } - addItem( - { - type: MessageType.INFO, - text: `Successfully added GEMINI.md files from the following directories if there are:\n- ${added.join('\n- ')}`, - }, - Date.now(), - ); + addItem({ + type: MessageType.INFO, + text: `Successfully added GEMINI.md files from the following directories if there are:\n- ${added.join('\n- ')}`, + }); } catch (error) { errors.push(`Error refreshing memory: ${(error as Error).message}`); } @@ -57,17 +54,14 @@ async function finishAddingDirectories( if (gemini) { await gemini.addDirectoryContext(); } - addItem( - { - type: MessageType.INFO, - text: `Successfully added directories:\n- ${added.join('\n- ')}`, - }, - Date.now(), - ); + addItem({ + type: MessageType.INFO, + text: `Successfully added directories:\n- ${added.join('\n- ')}`, + }); } if (errors.length > 0) { - addItem({ type: MessageType.ERROR, text: errors.join('\n') }, Date.now()); + addItem({ type: MessageType.ERROR, text: errors.join('\n') }); } } @@ -112,13 +106,10 @@ export const directoryCommand: SlashCommand = { const [...rest] = args.split(' '); if (!config) { - addItem( - { - type: MessageType.ERROR, - text: 'Configuration is not available.', - }, - Date.now(), - ); + addItem({ + type: MessageType.ERROR, + text: 'Configuration is not available.', + }); return; } @@ -136,13 +127,10 @@ export const directoryCommand: SlashCommand = { .split(',') .filter((p) => p); if (pathsToAdd.length === 0) { - addItem( - { - type: MessageType.ERROR, - text: 'Please provide at least one path to add.', - }, - Date.now(), - ); + addItem({ + type: MessageType.ERROR, + text: 'Please provide at least one path to add.', + }); return; } @@ -164,15 +152,12 @@ export const directoryCommand: SlashCommand = { } if (alreadyAdded.length > 0) { - addItem( - { - type: MessageType.INFO, - text: `The following directories are already in the workspace:\n- ${alreadyAdded.join( - '\n- ', - )}`, - }, - Date.now(), - ); + addItem({ + type: MessageType.INFO, + text: `The following directories are already in the workspace:\n- ${alreadyAdded.join( + '\n- ', + )}`, + }); } if (pathsToProcess.length === 0) { @@ -262,25 +247,19 @@ export const directoryCommand: SlashCommand = { services: { config }, } = context; if (!config) { - addItem( - { - type: MessageType.ERROR, - text: 'Configuration is not available.', - }, - Date.now(), - ); + addItem({ + type: MessageType.ERROR, + text: 'Configuration is not available.', + }); return; } const workspaceContext = config.getWorkspaceContext(); const directories = workspaceContext.getDirectories(); const directoryList = directories.map((dir) => `- ${dir}`).join('\n'); - addItem( - { - type: MessageType.INFO, - text: `Current workspace directories:\n${directoryList}`, - }, - Date.now(), - ); + addItem({ + type: MessageType.INFO, + text: `Current workspace directories:\n${directoryList}`, + }); }, }, ], diff --git a/packages/cli/src/ui/commands/extensionsCommand.test.ts b/packages/cli/src/ui/commands/extensionsCommand.test.ts index 55f20eb25d..9e46ab47aa 100644 --- a/packages/cli/src/ui/commands/extensionsCommand.test.ts +++ b/packages/cli/src/ui/commands/extensionsCommand.test.ts @@ -148,13 +148,10 @@ describe('extensionsCommand', () => { if (!command.action) throw new Error('Action not defined'); await command.action(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.EXTENSIONS_LIST, - extensions: expect.any(Array), - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.EXTENSIONS_LIST, + extensions: expect.any(Array), + }); }); it('should show a message if no extensions are installed', async () => { @@ -163,13 +160,10 @@ describe('extensionsCommand', () => { if (!command.action) throw new Error('Action not defined'); await command.action(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: 'No extensions installed. Run `/extensions explore` to check out the gallery.', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: 'No extensions installed. Run `/extensions explore` to check out the gallery.', + }); }); }); @@ -244,26 +238,20 @@ describe('extensionsCommand', () => { it('should show usage if no args are provided', async () => { await updateAction(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: 'Usage: /extensions update |--all', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: 'Usage: /extensions update |--all', + }); }); it('should show a message if no extensions are installed', async () => { mockGetExtensions.mockReturnValue([]); await updateAction(mockContext, 'ext-one'); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: 'No extensions installed. Run `/extensions explore` to check out the gallery.', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: 'No extensions installed. Run `/extensions explore` to check out the gallery.', + }); }); it('should inform user if there are no extensions to update with --all', async () => { @@ -276,13 +264,10 @@ describe('extensionsCommand', () => { ); await updateAction(mockContext, '--all'); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: 'No extensions to update.', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: 'No extensions to update.', + }); }); it('should call setPendingItem and addItem in a finally block on success', async () => { @@ -310,13 +295,10 @@ describe('extensionsCommand', () => { extensions: expect.any(Array), }); expect(mockContext.ui.setPendingItem).toHaveBeenCalledWith(null); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.EXTENSIONS_LIST, - extensions: expect.any(Array), - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.EXTENSIONS_LIST, + extensions: expect.any(Array), + }); }); it('should call setPendingItem and addItem in a finally block on failure', async () => { @@ -329,20 +311,14 @@ describe('extensionsCommand', () => { extensions: expect.any(Array), }); expect(mockContext.ui.setPendingItem).toHaveBeenCalledWith(null); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.EXTENSIONS_LIST, - extensions: expect.any(Array), - }, - expect.any(Number), - ); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: 'Something went wrong', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.EXTENSIONS_LIST, + extensions: expect.any(Array), + }); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: 'Something went wrong', + }); }); it('should update a single extension by name', async () => { @@ -403,13 +379,10 @@ describe('extensionsCommand', () => { extensions: expect.any(Array), }); expect(mockContext.ui.setPendingItem).toHaveBeenCalledWith(null); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.EXTENSIONS_LIST, - extensions: expect.any(Array), - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.EXTENSIONS_LIST, + extensions: expect.any(Array), + }); }); }); @@ -430,13 +403,10 @@ describe('extensionsCommand', () => { await exploreAction(mockContext, ''); const extensionsUrl = 'https://geminicli.com/extensions/'; - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: `Opening extensions page in your browser: ${extensionsUrl}`, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: `Opening extensions page in your browser: ${extensionsUrl}`, + }); expect(open).toHaveBeenCalledWith(extensionsUrl); }); @@ -449,13 +419,10 @@ describe('extensionsCommand', () => { await exploreAction(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: `View available extensions at ${extensionsUrl}`, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: `View available extensions at ${extensionsUrl}`, + }); // Ensure 'open' was not called in the sandbox expect(open).not.toHaveBeenCalled(); @@ -468,13 +435,10 @@ describe('extensionsCommand', () => { await exploreAction(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: `Would open extensions page in your browser: ${extensionsUrl} (skipped in test environment)`, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: `Would open extensions page in your browser: ${extensionsUrl} (skipped in test environment)`, + }); // Ensure 'open' was not called in test environment expect(open).not.toHaveBeenCalled(); @@ -488,13 +452,10 @@ describe('extensionsCommand', () => { await exploreAction(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: `Failed to open browser. Check out the extensions gallery at ${extensionsUrl}`, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: `Failed to open browser. Check out the extensions gallery at ${extensionsUrl}`, + }); }); }); @@ -549,13 +510,10 @@ describe('extensionsCommand', () => { it('should show usage if no extension name is provided', async () => { await installAction!(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: 'Usage: /extensions install ', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: 'Usage: /extensions install ', + }); expect(mockInstallExtension).not.toHaveBeenCalled(); }); @@ -572,20 +530,14 @@ describe('extensionsCommand', () => { source: packageName, type: 'git', }); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: `Installing extension from "${packageName}"...`, - }, - expect.any(Number), - ); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: `Extension "${packageName}" installed successfully.`, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: `Installing extension from "${packageName}"...`, + }); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: `Extension "${packageName}" installed successfully.`, + }); }); it('should show error message on installation failure', async () => { @@ -603,25 +555,19 @@ describe('extensionsCommand', () => { source: packageName, type: 'git', }); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: `Failed to install extension from "${packageName}": ${errorMessage}`, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: `Failed to install extension from "${packageName}": ${errorMessage}`, + }); }); it('should show error message for invalid source', async () => { const invalidSource = 'a;b'; await installAction!(mockContext, invalidSource); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: `Invalid source: ${invalidSource}`, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: `Invalid source: ${invalidSource}`, + }); expect(mockInstallExtension).not.toHaveBeenCalled(); }); }); @@ -640,13 +586,10 @@ describe('extensionsCommand', () => { it('should show usage if no extension is provided', async () => { await linkAction!(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: 'Usage: /extensions link ', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: 'Usage: /extensions link ', + }); expect(mockInstallExtension).not.toHaveBeenCalled(); }); @@ -661,20 +604,14 @@ describe('extensionsCommand', () => { source: packageName, type: 'link', }); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: `Linking extension from "${packageName}"...`, - }, - expect.any(Number), - ); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: `Extension "${packageName}" linked successfully.`, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: `Linking extension from "${packageName}"...`, + }); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: `Extension "${packageName}" linked successfully.`, + }); }); it('should show error message on linking failure', async () => { @@ -690,13 +627,10 @@ describe('extensionsCommand', () => { source: packageName, type: 'link', }); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: `Failed to link extension from "${packageName}": ${errorMessage}`, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: `Failed to link extension from "${packageName}": ${errorMessage}`, + }); }); it('should show error message for invalid source', async () => { @@ -723,13 +657,10 @@ describe('extensionsCommand', () => { it('should show usage if no extension name is provided', async () => { await uninstallAction!(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: 'Usage: /extensions uninstall ', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: 'Usage: /extensions uninstall ', + }); expect(mockUninstallExtension).not.toHaveBeenCalled(); }); @@ -737,20 +668,14 @@ describe('extensionsCommand', () => { const extensionName = 'test-extension'; await uninstallAction!(mockContext, extensionName); expect(mockUninstallExtension).toHaveBeenCalledWith(extensionName, false); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: `Uninstalling extension "${extensionName}"...`, - }, - expect.any(Number), - ); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: `Extension "${extensionName}" uninstalled successfully.`, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: `Uninstalling extension "${extensionName}"...`, + }); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: `Extension "${extensionName}" uninstalled successfully.`, + }); }); it('should show error message on uninstallation failure', async () => { @@ -760,13 +685,10 @@ describe('extensionsCommand', () => { await uninstallAction!(mockContext, extensionName); expect(mockUninstallExtension).toHaveBeenCalledWith(extensionName, false); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: `Failed to uninstall extension "${extensionName}": ${errorMessage}`, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: `Failed to uninstall extension "${extensionName}": ${errorMessage}`, + }); }); }); @@ -785,13 +707,10 @@ describe('extensionsCommand', () => { it('should show usage if no extension name is provided', async () => { await enableAction!(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: 'Usage: /extensions enable [--scope=]', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: 'Usage: /extensions enable [--scope=]', + }); }); it('should call enableExtension with the provided scope', async () => { @@ -840,13 +759,10 @@ describe('extensionsCommand', () => { it('should show usage if no extension name is provided', async () => { await disableAction!(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: 'Usage: /extensions disable [--scope=]', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: 'Usage: /extensions disable [--scope=]', + }); }); it('should call disableExtension with the provided scope', async () => { @@ -912,13 +828,10 @@ describe('extensionsCommand', () => { await restartAction!(mockContext, '--all'); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: 'No extensions installed. Run `/extensions explore` to check out the gallery.', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: 'No extensions installed. Run `/extensions explore` to check out the gallery.', + }); }); it('restarts all active extensions when --all is provided', async () => { @@ -939,14 +852,12 @@ describe('extensionsCommand', () => { type: MessageType.INFO, text: 'Restarting 2 extensions...', }), - expect.any(Number), ); expect(mockContext.ui.addItem).toHaveBeenCalledWith( expect.objectContaining({ type: MessageType.INFO, text: '2 extensions restarted successfully.', }), - expect.any(Number), ); expect(mockContext.ui.dispatchExtensionStateUpdate).toHaveBeenCalledWith({ type: 'RESTARTED', @@ -986,7 +897,6 @@ describe('extensionsCommand', () => { type: MessageType.ERROR, text: "Extensions are not yet loaded, can't restart yet", }), - expect.any(Number), ); expect(mockRestartExtension).not.toHaveBeenCalled(); }); @@ -999,7 +909,6 @@ describe('extensionsCommand', () => { type: MessageType.ERROR, text: 'Usage: /extensions restart |--all', }), - expect.any(Number), ); expect(mockRestartExtension).not.toHaveBeenCalled(); }); @@ -1019,7 +928,6 @@ describe('extensionsCommand', () => { type: MessageType.ERROR, text: 'Failed to restart some extensions:\n ext1: Failed to restart', }), - expect.any(Number), ); }); @@ -1038,7 +946,6 @@ describe('extensionsCommand', () => { type: MessageType.WARNING, text: 'Extension(s) not found or not active: ext2', }), - expect.any(Number), ); }); @@ -1056,7 +963,6 @@ describe('extensionsCommand', () => { type: MessageType.WARNING, text: 'Extension(s) not found or not active: ext2, ext3', }), - expect.any(Number), ); }); diff --git a/packages/cli/src/ui/commands/extensionsCommand.ts b/packages/cli/src/ui/commands/extensionsCommand.ts index 7c21115880..6aa748153a 100644 --- a/packages/cli/src/ui/commands/extensionsCommand.ts +++ b/packages/cli/src/ui/commands/extensionsCommand.ts @@ -37,13 +37,10 @@ function showMessageIfNoExtensions( extensions: unknown[], ): boolean { if (extensions.length === 0) { - context.ui.addItem( - { - type: MessageType.INFO, - text: 'No extensions installed. Run `/extensions explore` to check out the gallery.', - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: 'No extensions installed. Run `/extensions explore` to check out the gallery.', + }); return true; } return false; @@ -63,7 +60,7 @@ async function listAction(context: CommandContext) { extensions, }; - context.ui.addItem(historyItem, Date.now()); + context.ui.addItem(historyItem); } function updateAction(context: CommandContext, args: string): Promise { @@ -72,13 +69,10 @@ function updateAction(context: CommandContext, args: string): Promise { const names = all ? null : updateArgs; if (!all && names?.length === 0) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: 'Usage: /extensions update |--all', - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: 'Usage: /extensions update |--all', + }); return Promise.resolve(); } @@ -103,16 +97,13 @@ function updateAction(context: CommandContext, args: string): Promise { // eslint-disable-next-line @typescript-eslint/no-floating-promises updateComplete.then((updateInfos) => { if (updateInfos.length === 0) { - context.ui.addItem( - { - type: MessageType.INFO, - text: 'No extensions to update.', - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: 'No extensions to update.', + }); } - context.ui.addItem(historyItem, Date.now()); + context.ui.addItem(historyItem); context.ui.setPendingItem(null); }); @@ -136,26 +127,20 @@ function updateAction(context: CommandContext, args: string): Promise { (extension) => extension.name === name, ); if (!extension) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Extension ${name} not found.`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Extension ${name} not found.`, + }); continue; } } } } catch (error) { resolveUpdateComplete!([]); - context.ui.addItem( - { - type: MessageType.ERROR, - text: getErrorMessage(error), - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: getErrorMessage(error), + }); } return updateComplete.then((_) => {}); } @@ -166,13 +151,10 @@ async function restartAction( ): Promise { const extensionLoader = context.services.config?.getExtensionLoader(); if (!extensionLoader) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: "Extensions are not yet loaded, can't restart yet", - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: "Extensions are not yet loaded, can't restart yet", + }); return; } @@ -185,13 +167,10 @@ async function restartAction( const all = restartArgs.length === 1 && restartArgs[0] === '--all'; const names = all ? null : restartArgs; if (!all && names?.length === 0) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: 'Usage: /extensions restart |--all', - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: 'Usage: /extensions restart |--all', + }); return Promise.resolve(); } @@ -208,15 +187,10 @@ async function restartAction( !extensionsToRestart.some((extension) => extension.name === name), ); if (notFound.length > 0) { - context.ui.addItem( - { - type: MessageType.WARNING, - text: `Extension(s) not found or not active: ${notFound.join( - ', ', - )}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.WARNING, + text: `Extension(s) not found or not active: ${notFound.join(', ')}`, + }); } } } @@ -232,7 +206,7 @@ async function restartAction( text: `Restarting ${extensionsToRestart.length} extension${s}...`, color: theme.text.primary, }; - context.ui.addItem(restartingMessage, Date.now()); + context.ui.addItem(restartingMessage); const results = await Promise.allSettled( extensionsToRestart.map(async (extension) => { @@ -259,13 +233,10 @@ async function restartAction( return `${extensionName}: ${getErrorMessage(failure.reason)}`; }) .join('\n '); - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Failed to restart some extensions:\n ${errorMessages}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Failed to restart some extensions:\n ${errorMessages}`, + }); } else { const infoItem: HistoryItemInfo = { type: MessageType.INFO, @@ -273,7 +244,7 @@ async function restartAction( icon: emptyIcon, color: theme.text.primary, }; - context.ui.addItem(infoItem, Date.now()); + context.ui.addItem(infoItem); } } @@ -282,42 +253,30 @@ async function exploreAction(context: CommandContext) { // Only check for NODE_ENV for explicit test mode, not for unit test framework if (process.env['NODE_ENV'] === 'test') { - context.ui.addItem( - { - type: MessageType.INFO, - text: `Would open extensions page in your browser: ${extensionsUrl} (skipped in test environment)`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: `Would open extensions page in your browser: ${extensionsUrl} (skipped in test environment)`, + }); } else if ( process.env['SANDBOX'] && process.env['SANDBOX'] !== 'sandbox-exec' ) { - context.ui.addItem( - { - type: MessageType.INFO, - text: `View available extensions at ${extensionsUrl}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: `View available extensions at ${extensionsUrl}`, + }); } else { - context.ui.addItem( - { - type: MessageType.INFO, - text: `Opening extensions page in your browser: ${extensionsUrl}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: `Opening extensions page in your browser: ${extensionsUrl}`, + }); try { await open(extensionsUrl); } catch (_error) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Failed to open browser. Check out the extensions gallery at ${extensionsUrl}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Failed to open browser. Check out the extensions gallery at ${extensionsUrl}`, + }); } } } @@ -346,13 +305,10 @@ function getEnableDisableContext( (parts.length === 3 && parts[1] === '--scope') // --scope ) ) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Usage: /extensions ${context.invocation?.name} [--scope=]`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Usage: /extensions ${context.invocation?.name} [--scope=]`, + }); return null; } let scope: SettingScope; @@ -372,13 +328,10 @@ function getEnableDisableContext( scope = SettingScope.Session; break; default: - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Unsupported scope ${parts[2]}, should be one of "user", "workspace", or "session"`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Unsupported scope ${parts[2]}, should be one of "user", "workspace", or "session"`, + }); debugLogger.error(); return null; } @@ -410,13 +363,10 @@ async function disableAction(context: CommandContext, args: string) { const { names, scope, extensionManager } = enableContext; for (const name of names) { await extensionManager.disableExtension(name, scope); - context.ui.addItem( - { - type: MessageType.INFO, - text: `Extension "${name}" disabled for the scope "${scope}"`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: `Extension "${name}" disabled for the scope "${scope}"`, + }); } } @@ -427,13 +377,10 @@ async function enableAction(context: CommandContext, args: string) { const { names, scope, extensionManager } = enableContext; for (const name of names) { await extensionManager.enableExtension(name, scope); - context.ui.addItem( - { - type: MessageType.INFO, - text: `Extension "${name}" enabled for the scope "${scope}"`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: `Extension "${name}" enabled for the scope "${scope}"`, + }); } } @@ -448,13 +395,10 @@ async function installAction(context: CommandContext, args: string) { const source = args.trim(); if (!source) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Usage: /extensions install `, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Usage: /extensions install `, + }); return; } @@ -473,45 +417,33 @@ async function installAction(context: CommandContext, args: string) { } if (!isValid) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Invalid source: ${source}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Invalid source: ${source}`, + }); return; } - context.ui.addItem( - { - type: MessageType.INFO, - text: `Installing extension from "${source}"...`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: `Installing extension from "${source}"...`, + }); try { const installMetadata = await inferInstallMetadata(source); const extension = await extensionLoader.installOrUpdateExtension(installMetadata); - context.ui.addItem( - { - type: MessageType.INFO, - text: `Extension "${extension.name}" installed successfully.`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: `Extension "${extension.name}" installed successfully.`, + }); } catch (error) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Failed to install extension from "${source}": ${getErrorMessage( - error, - )}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Failed to install extension from "${source}": ${getErrorMessage( + error, + )}`, + }); } } @@ -526,49 +458,37 @@ async function linkAction(context: CommandContext, args: string) { const sourceFilepath = args.trim(); if (!sourceFilepath) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Usage: /extensions link `, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Usage: /extensions link `, + }); return; } if (/[;&|`'"]/.test(sourceFilepath)) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Source file path contains disallowed characters: ${sourceFilepath}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Source file path contains disallowed characters: ${sourceFilepath}`, + }); return; } try { await stat(sourceFilepath); } catch (error) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Invalid source: ${sourceFilepath}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Invalid source: ${sourceFilepath}`, + }); debugLogger.error( `Failed to stat path "${sourceFilepath}": ${getErrorMessage(error)}`, ); return; } - context.ui.addItem( - { - type: MessageType.INFO, - text: `Linking extension from "${sourceFilepath}"...`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: `Linking extension from "${sourceFilepath}"...`, + }); try { const installMetadata: ExtensionInstallMetadata = { @@ -577,23 +497,17 @@ async function linkAction(context: CommandContext, args: string) { }; const extension = await extensionLoader.installOrUpdateExtension(installMetadata); - context.ui.addItem( - { - type: MessageType.INFO, - text: `Extension "${extension.name}" linked successfully.`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: `Extension "${extension.name}" linked successfully.`, + }); } catch (error) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Failed to link extension from "${sourceFilepath}": ${getErrorMessage( - error, - )}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Failed to link extension from "${sourceFilepath}": ${getErrorMessage( + error, + )}`, + }); } } @@ -608,43 +522,31 @@ async function uninstallAction(context: CommandContext, args: string) { const name = args.trim(); if (!name) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Usage: /extensions uninstall `, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Usage: /extensions uninstall `, + }); return; } - context.ui.addItem( - { - type: MessageType.INFO, - text: `Uninstalling extension "${name}"...`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: `Uninstalling extension "${name}"...`, + }); try { await extensionLoader.uninstallExtension(name, false); - context.ui.addItem( - { - type: MessageType.INFO, - text: `Extension "${name}" uninstalled successfully.`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: `Extension "${name}" uninstalled successfully.`, + }); } catch (error) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Failed to uninstall extension "${name}": ${getErrorMessage( - error, - )}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Failed to uninstall extension "${name}": ${getErrorMessage( + error, + )}`, + }); } } diff --git a/packages/cli/src/ui/commands/helpCommand.test.ts b/packages/cli/src/ui/commands/helpCommand.test.ts index 9eff142ba0..58b02251f9 100644 --- a/packages/cli/src/ui/commands/helpCommand.test.ts +++ b/packages/cli/src/ui/commands/helpCommand.test.ts @@ -40,7 +40,6 @@ describe('helpCommand', () => { type: MessageType.HELP, timestamp: expect.any(Date), }), - expect.any(Number), ); }); diff --git a/packages/cli/src/ui/commands/helpCommand.ts b/packages/cli/src/ui/commands/helpCommand.ts index f7d469a7e7..cacebafe01 100644 --- a/packages/cli/src/ui/commands/helpCommand.ts +++ b/packages/cli/src/ui/commands/helpCommand.ts @@ -20,6 +20,6 @@ export const helpCommand: SlashCommand = { timestamp: new Date(), }; - context.ui.addItem(helpItem, Date.now()); + context.ui.addItem(helpItem); }, }; diff --git a/packages/cli/src/ui/commands/hooksCommand.test.ts b/packages/cli/src/ui/commands/hooksCommand.test.ts index aa4eb12971..4f9499c0aa 100644 --- a/packages/cli/src/ui/commands/hooksCommand.test.ts +++ b/packages/cli/src/ui/commands/hooksCommand.test.ts @@ -109,7 +109,6 @@ describe('hooksCommand', () => { expect.objectContaining({ type: MessageType.HOOKS_LIST, }), - expect.any(Number), ); }); }); @@ -155,7 +154,6 @@ describe('hooksCommand', () => { type: MessageType.HOOKS_LIST, hooks: [], }), - expect.any(Number), ); }); @@ -179,7 +177,6 @@ describe('hooksCommand', () => { type: MessageType.HOOKS_LIST, hooks: [], }), - expect.any(Number), ); }); @@ -208,7 +205,6 @@ describe('hooksCommand', () => { type: MessageType.HOOKS_LIST, hooks: mockHooks, }), - expect.any(Number), ); }); }); diff --git a/packages/cli/src/ui/commands/hooksCommand.ts b/packages/cli/src/ui/commands/hooksCommand.ts index 1017474952..050bf3045e 100644 --- a/packages/cli/src/ui/commands/hooksCommand.ts +++ b/packages/cli/src/ui/commands/hooksCommand.ts @@ -37,7 +37,7 @@ async function panelAction( hooks: allHooks, }; - context.ui.addItem(hooksListItem, Date.now()); + context.ui.addItem(hooksListItem); } /** diff --git a/packages/cli/src/ui/commands/mcpCommand.test.ts b/packages/cli/src/ui/commands/mcpCommand.test.ts index 85ee967143..83b5dbb179 100644 --- a/packages/cli/src/ui/commands/mcpCommand.test.ts +++ b/packages/cli/src/ui/commands/mcpCommand.test.ts @@ -231,7 +231,6 @@ describe('mcpCommand', () => { }), ]), }), - expect.any(Number), ); }); @@ -246,7 +245,6 @@ describe('mcpCommand', () => { type: MessageType.MCP_STATUS, showDescriptions: true, }), - expect.any(Number), ); }); @@ -261,7 +259,6 @@ describe('mcpCommand', () => { type: MessageType.MCP_STATUS, showDescriptions: false, }), - expect.any(Number), ); }); }); diff --git a/packages/cli/src/ui/commands/mcpCommand.ts b/packages/cli/src/ui/commands/mcpCommand.ts index 8df7a9c397..b0d95bd603 100644 --- a/packages/cli/src/ui/commands/mcpCommand.ts +++ b/packages/cli/src/ui/commands/mcpCommand.ts @@ -91,19 +91,16 @@ const authCommand: SlashCommand = { // The authentication process will discover OAuth requirements automatically const displayListener = (message: string) => { - context.ui.addItem({ type: 'info', text: message }, Date.now()); + context.ui.addItem({ type: 'info', text: message }); }; appEvents.on(AppEvent.OauthDisplayMessage, displayListener); try { - context.ui.addItem( - { - type: 'info', - text: `Starting OAuth authentication for MCP server '${serverName}'...`, - }, - Date.now(), - ); + context.ui.addItem({ + type: 'info', + text: `Starting OAuth authentication for MCP server '${serverName}'...`, + }); // Import dynamically to avoid circular dependencies const { MCPOAuthProvider } = await import('@google/gemini-cli-core'); @@ -122,24 +119,18 @@ const authCommand: SlashCommand = { appEvents, ); - context.ui.addItem( - { - type: 'info', - text: `✅ Successfully authenticated with MCP server '${serverName}'!`, - }, - Date.now(), - ); + context.ui.addItem({ + type: 'info', + text: `✅ Successfully authenticated with MCP server '${serverName}'!`, + }); // Trigger tool re-discovery to pick up authenticated server const mcpClientManager = config.getMcpClientManager(); if (mcpClientManager) { - context.ui.addItem( - { - type: 'info', - text: `Restarting MCP server '${serverName}'...`, - }, - Date.now(), - ); + context.ui.addItem({ + type: 'info', + text: `Restarting MCP server '${serverName}'...`, + }); await mcpClientManager.restartServer(serverName); } // Update the client with the new tools @@ -279,7 +270,7 @@ const listAction = async ( showSchema, }; - context.ui.addItem(mcpStatusItem, Date.now()); + context.ui.addItem(mcpStatusItem); }; const listCommand: SlashCommand = { @@ -335,13 +326,10 @@ const refreshCommand: SlashCommand = { }; } - context.ui.addItem( - { - type: 'info', - text: 'Restarting MCP servers...', - }, - Date.now(), - ); + context.ui.addItem({ + type: 'info', + text: 'Restarting MCP servers...', + }); await mcpClientManager.restart(); diff --git a/packages/cli/src/ui/commands/skillsCommand.test.ts b/packages/cli/src/ui/commands/skillsCommand.test.ts index 3bcfa6ba06..df11195889 100644 --- a/packages/cli/src/ui/commands/skillsCommand.test.ts +++ b/packages/cli/src/ui/commands/skillsCommand.test.ts @@ -91,7 +91,6 @@ describe('skillsCommand', () => { ], showDescriptions: true, }), - expect.any(Number), ); }); @@ -120,7 +119,6 @@ describe('skillsCommand', () => { ], showDescriptions: true, }), - expect.any(Number), ); }); @@ -132,7 +130,6 @@ describe('skillsCommand', () => { expect.objectContaining({ showDescriptions: false, }), - expect.any(Number), ); }); @@ -229,7 +226,6 @@ describe('skillsCommand', () => { type: MessageType.INFO, text: 'Skill "skill1" disabled by adding it to the disabled list in project (/workspace) settings. Use "/skills reload" for it to take effect.', }), - expect.any(Number), ); }); @@ -258,7 +254,6 @@ describe('skillsCommand', () => { type: MessageType.INFO, text: 'Skill "skill1" enabled by removing it from the disabled list in project (/workspace) and user (/user/settings.json) settings. Use "/skills reload" for it to take effect.', }), - expect.any(Number), ); }); @@ -298,7 +293,6 @@ describe('skillsCommand', () => { type: MessageType.INFO, text: 'Skill "skill1" enabled by removing it from the disabled list in project (/workspace) and user (/user/settings.json) settings. Use "/skills reload" for it to take effect.', }), - expect.any(Number), ); }); @@ -313,7 +307,6 @@ describe('skillsCommand', () => { type: MessageType.ERROR, text: 'Skill "non-existent" not found.', }), - expect.any(Number), ); }); }); @@ -359,7 +352,6 @@ describe('skillsCommand', () => { type: MessageType.INFO, text: 'Agent skills reloaded successfully.', }), - expect.any(Number), ); }); @@ -385,7 +377,6 @@ describe('skillsCommand', () => { type: MessageType.INFO, text: 'Agent skills reloaded successfully. 1 newly available skill.', }), - expect.any(Number), ); }); @@ -409,7 +400,6 @@ describe('skillsCommand', () => { type: MessageType.INFO, text: 'Agent skills reloaded successfully. 1 skill no longer available.', }), - expect.any(Number), ); }); @@ -434,7 +424,6 @@ describe('skillsCommand', () => { type: MessageType.INFO, text: 'Agent skills reloaded successfully. 1 newly available skill and 1 skill no longer available.', }), - expect.any(Number), ); }); @@ -451,7 +440,6 @@ describe('skillsCommand', () => { type: MessageType.ERROR, text: 'Could not retrieve configuration.', }), - expect.any(Number), ); }); @@ -477,7 +465,6 @@ describe('skillsCommand', () => { type: MessageType.ERROR, text: 'Failed to reload skills: Reload failed', }), - expect.any(Number), ); }); }); diff --git a/packages/cli/src/ui/commands/skillsCommand.ts b/packages/cli/src/ui/commands/skillsCommand.ts index ca476a32ea..f632501eee 100644 --- a/packages/cli/src/ui/commands/skillsCommand.ts +++ b/packages/cli/src/ui/commands/skillsCommand.ts @@ -39,13 +39,10 @@ async function listAction( const skillManager = context.services.config?.getSkillManager(); if (!skillManager) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: 'Could not retrieve skill manager.', - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: 'Could not retrieve skill manager.', + }); return; } @@ -66,7 +63,7 @@ async function listAction( showDescriptions: useShowDescriptions, }; - context.ui.addItem(skillsListItem, Date.now()); + context.ui.addItem(skillsListItem); } async function disableAction( @@ -75,25 +72,19 @@ async function disableAction( ): Promise { const skillName = args.trim(); if (!skillName) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: 'Please provide a skill name to disable.', - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: 'Please provide a skill name to disable.', + }); return; } const skillManager = context.services.config?.getSkillManager(); const skill = skillManager?.getSkill(skillName); if (!skill) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Skill "${skillName}" not found.`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Skill "${skillName}" not found.`, + }); return; } @@ -111,13 +102,10 @@ async function disableAction( feedback += ' Use "/skills reload" for it to take effect.'; } - context.ui.addItem( - { - type: MessageType.INFO, - text: feedback, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: feedback, + }); } async function enableAction( @@ -126,13 +114,10 @@ async function enableAction( ): Promise { const skillName = args.trim(); if (!skillName) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: 'Please provide a skill name to enable.', - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: 'Please provide a skill name to enable.', + }); return; } @@ -146,13 +131,10 @@ async function enableAction( feedback += ' Use "/skills reload" for it to take effect.'; } - context.ui.addItem( - { - type: MessageType.INFO, - text: feedback, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.INFO, + text: feedback, + }); } async function reloadAction( @@ -160,13 +142,10 @@ async function reloadAction( ): Promise { const config = context.services.config; if (!config) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: 'Could not retrieve configuration.', - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: 'Could not retrieve configuration.', + }); return; } @@ -226,27 +205,21 @@ async function reloadAction( successText += ` ${details.join(' and ')}.`; } - context.ui.addItem( - { - type: 'info', - text: successText, - icon: '✓ ', - color: 'green', - } as HistoryItemInfo, - Date.now(), - ); + context.ui.addItem({ + type: 'info', + text: successText, + icon: '✓ ', + color: 'green', + } as HistoryItemInfo); } catch (error) { clearTimeout(pendingTimeout); if (pendingItemSet) { context.ui.setPendingItem(null); } - context.ui.addItem( - { - type: MessageType.ERROR, - text: `Failed to reload skills: ${error instanceof Error ? error.message : String(error)}`, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: `Failed to reload skills: ${error instanceof Error ? error.message : String(error)}`, + }); } } diff --git a/packages/cli/src/ui/commands/statsCommand.test.ts b/packages/cli/src/ui/commands/statsCommand.test.ts index 2a054ecc4d..cf948790d6 100644 --- a/packages/cli/src/ui/commands/statsCommand.test.ts +++ b/packages/cli/src/ui/commands/statsCommand.test.ts @@ -37,13 +37,10 @@ describe('statsCommand', () => { const expectedDuration = formatDuration( endTime.getTime() - startTime.getTime(), ); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.STATS, - duration: expectedDuration, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.STATS, + duration: expectedDuration, + }); }); it('should fetch and display quota if config is available', async () => { @@ -62,7 +59,6 @@ describe('statsCommand', () => { expect.objectContaining({ quotas: mockQuota, }), - expect.any(Number), ); }); @@ -75,12 +71,9 @@ describe('statsCommand', () => { // eslint-disable-next-line @typescript-eslint/no-floating-promises modelSubCommand.action(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.MODEL_STATS, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.MODEL_STATS, + }); }); it('should display tool stats when using the "tools" subcommand', () => { @@ -92,11 +85,8 @@ describe('statsCommand', () => { // eslint-disable-next-line @typescript-eslint/no-floating-promises toolsSubCommand.action(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.TOOL_STATS, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.TOOL_STATS, + }); }); }); diff --git a/packages/cli/src/ui/commands/statsCommand.ts b/packages/cli/src/ui/commands/statsCommand.ts index 718da86f69..917c52c143 100644 --- a/packages/cli/src/ui/commands/statsCommand.ts +++ b/packages/cli/src/ui/commands/statsCommand.ts @@ -17,13 +17,10 @@ async function defaultSessionView(context: CommandContext) { const now = new Date(); const { sessionStartTime } = context.session.stats; if (!sessionStartTime) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: 'Session start time is unavailable, cannot calculate stats.', - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: 'Session start time is unavailable, cannot calculate stats.', + }); return; } const wallDuration = now.getTime() - sessionStartTime.getTime(); @@ -40,7 +37,7 @@ async function defaultSessionView(context: CommandContext) { } } - context.ui.addItem(statsItem, Date.now()); + context.ui.addItem(statsItem); } export const statsCommand: SlashCommand = { @@ -68,12 +65,9 @@ export const statsCommand: SlashCommand = { kind: CommandKind.BUILT_IN, autoExecute: true, action: (context: CommandContext) => { - context.ui.addItem( - { - type: MessageType.MODEL_STATS, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.MODEL_STATS, + }); }, }, { @@ -82,12 +76,9 @@ export const statsCommand: SlashCommand = { kind: CommandKind.BUILT_IN, autoExecute: true, action: (context: CommandContext) => { - context.ui.addItem( - { - type: MessageType.TOOL_STATS, - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.TOOL_STATS, + }); }, }, ], diff --git a/packages/cli/src/ui/commands/toolsCommand.test.ts b/packages/cli/src/ui/commands/toolsCommand.test.ts index d44be3f973..257e6ba167 100644 --- a/packages/cli/src/ui/commands/toolsCommand.test.ts +++ b/packages/cli/src/ui/commands/toolsCommand.test.ts @@ -40,13 +40,10 @@ describe('toolsCommand', () => { if (!toolsCommand.action) throw new Error('Action not defined'); await toolsCommand.action(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: 'Could not retrieve tool registry.', - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: 'Could not retrieve tool registry.', + }); }); it('should display "No tools available" when none are found', async () => { @@ -63,14 +60,11 @@ describe('toolsCommand', () => { if (!toolsCommand.action) throw new Error('Action not defined'); await toolsCommand.action(mockContext, ''); - expect(mockContext.ui.addItem).toHaveBeenCalledWith( - { - type: MessageType.TOOLS_LIST, - tools: [], - showDescriptions: false, - }, - expect.any(Number), - ); + expect(mockContext.ui.addItem).toHaveBeenCalledWith({ + type: MessageType.TOOLS_LIST, + tools: [], + showDescriptions: false, + }); }); it('should list tools without descriptions by default', async () => { diff --git a/packages/cli/src/ui/commands/toolsCommand.ts b/packages/cli/src/ui/commands/toolsCommand.ts index bbb86082f1..ff772c5cc8 100644 --- a/packages/cli/src/ui/commands/toolsCommand.ts +++ b/packages/cli/src/ui/commands/toolsCommand.ts @@ -27,13 +27,10 @@ export const toolsCommand: SlashCommand = { const toolRegistry = context.services.config?.getToolRegistry(); if (!toolRegistry) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: 'Could not retrieve tool registry.', - }, - Date.now(), - ); + context.ui.addItem({ + type: MessageType.ERROR, + text: 'Could not retrieve tool registry.', + }); return; } @@ -51,6 +48,6 @@ export const toolsCommand: SlashCommand = { showDescriptions: useShowDescriptions, }; - context.ui.addItem(toolsListItem, Date.now()); + context.ui.addItem(toolsListItem); }, }; diff --git a/packages/cli/src/ui/components/MultiFolderTrustDialog.test.tsx b/packages/cli/src/ui/components/MultiFolderTrustDialog.test.tsx index 36ec622a65..64e992b06a 100644 --- a/packages/cli/src/ui/components/MultiFolderTrustDialog.test.tsx +++ b/packages/cli/src/ui/components/MultiFolderTrustDialog.test.tsx @@ -11,7 +11,7 @@ import { MultiFolderTrustChoice, type MultiFolderTrustDialogProps, } from './MultiFolderTrustDialog.js'; -import { vi } from 'vitest'; +import { vi, describe, it, expect, beforeEach } from 'vitest'; import { TrustLevel, type LoadedTrustedFolders, @@ -213,13 +213,10 @@ describe('MultiFolderTrustDialog', () => { onSelect(MultiFolderTrustChoice.YES); }); - expect(mockAddItem).toHaveBeenCalledWith( - { - type: MessageType.ERROR, - text: 'Configuration is not available.', - }, - expect.any(Number), - ); + expect(mockAddItem).toHaveBeenCalledWith({ + type: MessageType.ERROR, + text: 'Configuration is not available.', + }); expect(mockOnComplete).toHaveBeenCalled(); expect(mockFinishAddingDirectories).not.toHaveBeenCalled(); }); diff --git a/packages/cli/src/ui/components/MultiFolderTrustDialog.tsx b/packages/cli/src/ui/components/MultiFolderTrustDialog.tsx index 1f0885358f..5928f766b7 100644 --- a/packages/cli/src/ui/components/MultiFolderTrustDialog.tsx +++ b/packages/cli/src/ui/components/MultiFolderTrustDialog.tsx @@ -31,13 +31,16 @@ export interface MultiFolderTrustDialogProps { config: Config, addItem: ( itemData: Omit, - baseTimestamp: number, + baseTimestamp?: number, ) => number, added: string[], errors: string[], ) => Promise; config: Config; - addItem: (itemData: Omit, baseTimestamp: number) => number; + addItem: ( + itemData: Omit, + baseTimestamp?: number, + ) => number; } export const MultiFolderTrustDialog: React.FC = ({ @@ -95,13 +98,10 @@ export const MultiFolderTrustDialog: React.FC = ({ setSubmitted(true); if (!config) { - addItem( - { - type: MessageType.ERROR, - text: 'Configuration is not available.', - }, - Date.now(), - ); + addItem({ + type: MessageType.ERROR, + text: 'Configuration is not available.', + }); onComplete(); return; } diff --git a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx index 5952508bf8..21bb2191e9 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx +++ b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx @@ -780,7 +780,6 @@ describe('useGeminiStream', () => { 'Agent execution stopped: Stop reason from hook', ), }), - expect.any(Number), ); // Ensure we do NOT call back to the API expect(mockSendMessageStream).not.toHaveBeenCalled(); @@ -1085,13 +1084,10 @@ describe('useGeminiStream', () => { // Verify cancellation message is added await waitFor(() => { - expect(mockAddItem).toHaveBeenCalledWith( - { - type: MessageType.INFO, - text: 'Request cancelled.', - }, - expect.any(Number), - ); + expect(mockAddItem).toHaveBeenCalledWith({ + type: MessageType.INFO, + text: 'Request cancelled.', + }); }); // Verify state is reset @@ -1194,7 +1190,6 @@ describe('useGeminiStream', () => { expect.objectContaining({ text: 'Request cancelled.', }), - expect.any(Number), ); }); @@ -1330,7 +1325,6 @@ describe('useGeminiStream', () => { expect.objectContaining({ text: 'Request cancelled.', }), - expect.any(Number), ); }); @@ -1995,13 +1989,10 @@ describe('useGeminiStream', () => { }); await waitFor(() => { - expect(mockAddItem).toHaveBeenCalledWith( - { - type: 'info', - text: expectedMessage, - }, - expect.any(Number), - ); + expect(mockAddItem).toHaveBeenCalledWith({ + type: 'info', + text: expectedMessage, + }); }); }, ); @@ -2644,13 +2635,10 @@ describe('useGeminiStream', () => { expect(result.current.loopDetectionConfirmationRequest).toBeNull(); // Verify appropriate message was added - expect(mockAddItem).toHaveBeenCalledWith( - { - type: 'info', - text: 'Loop detection has been disabled for this session. Retrying request...', - }, - expect.any(Number), - ); + expect(mockAddItem).toHaveBeenCalledWith({ + type: 'info', + text: 'Loop detection has been disabled for this session. Retrying request...', + }); // Verify that the request was retried await waitFor(() => { @@ -2707,13 +2695,10 @@ describe('useGeminiStream', () => { expect(result.current.loopDetectionConfirmationRequest).toBeNull(); // Verify appropriate message was added - expect(mockAddItem).toHaveBeenCalledWith( - { - type: 'info', - text: 'A potential loop was detected. This can happen due to repetitive tool calls or other model behavior. The request has been halted.', - }, - expect.any(Number), - ); + expect(mockAddItem).toHaveBeenCalledWith({ + type: 'info', + text: 'A potential loop was detected. This can happen due to repetitive tool calls or other model behavior. The request has been halted.', + }); // Verify that the request was NOT retried expect(mockSendMessageStream).toHaveBeenCalledTimes(1); @@ -2750,13 +2735,10 @@ describe('useGeminiStream', () => { expect(result.current.loopDetectionConfirmationRequest).toBeNull(); // Verify first message was added - expect(mockAddItem).toHaveBeenCalledWith( - { - type: 'info', - text: 'A potential loop was detected. This can happen due to repetitive tool calls or other model behavior. The request has been halted.', - }, - expect.any(Number), - ); + expect(mockAddItem).toHaveBeenCalledWith({ + type: 'info', + text: 'A potential loop was detected. This can happen due to repetitive tool calls or other model behavior. The request has been halted.', + }); // Second loop detection - set up fresh mock for second call mockSendMessageStream.mockReturnValueOnce( @@ -2800,13 +2782,10 @@ describe('useGeminiStream', () => { expect(result.current.loopDetectionConfirmationRequest).toBeNull(); // Verify second message was added - expect(mockAddItem).toHaveBeenCalledWith( - { - type: 'info', - text: 'Loop detection has been disabled for this session. Retrying request...', - }, - expect.any(Number), - ); + expect(mockAddItem).toHaveBeenCalledWith({ + type: 'info', + text: 'Loop detection has been disabled for this session. Retrying request...', + }); // Verify that the request was retried await waitFor(() => { diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index ec7370ccfa..253582359e 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -149,7 +149,6 @@ export const useGeminiStream = ( mapTrackedToolCallsToDisplay( completedToolCallsFromScheduler as TrackedToolCall[], ), - Date.now(), ); // Clear the live-updating display now that the final state is in history. @@ -248,10 +247,7 @@ export const useGeminiStream = ( prevActiveShellPtyIdRef.current !== null && activeShellPtyId === null ) { - addItem( - { type: MessageType.INFO, text: 'Request cancelled.' }, - Date.now(), - ); + addItem({ type: MessageType.INFO, text: 'Request cancelled.' }); setIsResponding(false); } prevActiveShellPtyIdRef.current = activeShellPtyId; @@ -351,12 +347,9 @@ export const useGeminiStream = ( } return tool; }); - addItem( - { ...toolGroup, tools: updatedTools } as HistoryItemWithoutId, - Date.now(), - ); + addItem({ ...toolGroup, tools: updatedTools } as HistoryItemWithoutId); } else { - addItem(pendingHistoryItemRef.current, Date.now()); + addItem(pendingHistoryItemRef.current); } } setPendingHistoryItem(null); @@ -368,13 +361,10 @@ export const useGeminiStream = ( // If shell is active, we delay this message to ensure correct ordering // (Shell item first, then Info message). if (!activeShellPtyId) { - addItem( - { - type: MessageType.INFO, - text: 'Request cancelled.', - }, - Date.now(), - ); + addItem({ + type: MessageType.INFO, + text: 'Request cancelled.', + }); setIsResponding(false); } } @@ -719,32 +709,26 @@ export const useGeminiStream = ( addItem(pendingHistoryItemRef.current, userMessageTimestamp); setPendingHistoryItem(null); } - return addItem( - { - type: 'info', - text: - `IMPORTANT: This conversation exceeded the compress threshold. ` + - `A compressed context will be sent for future messages (compressed from: ` + - `${eventValue?.originalTokenCount ?? 'unknown'} to ` + - `${eventValue?.newTokenCount ?? 'unknown'} tokens).`, - }, - Date.now(), - ); + return addItem({ + type: 'info', + text: + `IMPORTANT: This conversation exceeded the compress threshold. ` + + `A compressed context will be sent for future messages (compressed from: ` + + `${eventValue?.originalTokenCount ?? 'unknown'} to ` + + `${eventValue?.newTokenCount ?? 'unknown'} tokens).`, + }); }, [addItem, pendingHistoryItemRef, setPendingHistoryItem], ); const handleMaxSessionTurnsEvent = useCallback( () => - addItem( - { - type: 'info', - text: - `The session has reached the maximum number of turns: ${config.getMaxSessionTurns()}. ` + - `Please update this limit in your setting.json file.`, - }, - Date.now(), - ), + addItem({ + type: 'info', + text: + `The session has reached the maximum number of turns: ${config.getMaxSessionTurns()}. ` + + `Please update this limit in your setting.json file.`, + }), [addItem, config], ); @@ -764,13 +748,10 @@ export const useGeminiStream = ( ' Please try reducing the size of your message or use the `/compress` command to compress the chat history.'; } - addItem( - { - type: 'info', - text, - }, - Date.now(), - ); + addItem({ + type: 'info', + text, + }); }, [addItem, onCancelSubmit, config], ); @@ -1041,13 +1022,10 @@ export const useGeminiStream = ( .getGeminiClient() .getLoopDetectionService() .disableForSession(); - addItem( - { - type: 'info', - text: `Loop detection has been disabled for this session. Retrying request...`, - }, - Date.now(), - ); + addItem({ + type: 'info', + text: `Loop detection has been disabled for this session. Retrying request...`, + }); if (lastQueryRef.current && lastPromptIdRef.current) { // eslint-disable-next-line @typescript-eslint/no-floating-promises @@ -1058,13 +1036,10 @@ export const useGeminiStream = ( ); } } else { - addItem( - { - type: 'info', - text: `A potential loop was detected. This can happen due to repetitive tool calls or other model behavior. The request has been halted.`, - }, - Date.now(), - ); + addItem({ + type: 'info', + text: `A potential loop was detected. This can happen due to repetitive tool calls or other model behavior. The request has been halted.`, + }); } }, }); @@ -1215,13 +1190,10 @@ export const useGeminiStream = ( ); if (stopExecutionTool && stopExecutionTool.response.error) { - addItem( - { - type: MessageType.INFO, - text: `Agent execution stopped: ${stopExecutionTool.response.error.message}`, - }, - Date.now(), - ); + addItem({ + type: MessageType.INFO, + text: `Agent execution stopped: ${stopExecutionTool.response.error.message}`, + }); setIsResponding(false); const callIdsToMarkAsSubmitted = geminiTools.map( @@ -1240,13 +1212,10 @@ export const useGeminiStream = ( // If the turn was cancelled via the imperative escape key flow, // the cancellation message is added there. We check the ref to avoid duplication. if (!turnCancelledRef.current) { - addItem( - { - type: MessageType.INFO, - text: 'Request cancelled.', - }, - Date.now(), - ); + addItem({ + type: MessageType.INFO, + text: 'Request cancelled.', + }); } setIsResponding(false); diff --git a/packages/cli/src/ui/hooks/useHistoryManager.test.ts b/packages/cli/src/ui/hooks/useHistoryManager.test.ts index cff7ef69bf..79a708ec41 100644 --- a/packages/cli/src/ui/hooks/useHistoryManager.test.ts +++ b/packages/cli/src/ui/hooks/useHistoryManager.test.ts @@ -200,4 +200,23 @@ describe('useHistoryManager', () => { expect(result.current.history[1].text).toBe('Gemini response'); expect(result.current.history[2].text).toBe('Message 1'); }); + + it('should use Date.now() as default baseTimestamp if not provided', () => { + const { result } = renderHook(() => useHistory()); + const before = Date.now(); + const itemData: Omit = { + type: 'user', + text: 'Default timestamp test', + }; + + act(() => { + result.current.addItem(itemData); + }); + const after = Date.now(); + + expect(result.current.history).toHaveLength(1); + // ID should be >= before + 1 (since counter starts at 0 and increments to 1) + expect(result.current.history[0].id).toBeGreaterThanOrEqual(before + 1); + expect(result.current.history[0].id).toBeLessThanOrEqual(after + 1); + }); }); diff --git a/packages/cli/src/ui/hooks/useHistoryManager.ts b/packages/cli/src/ui/hooks/useHistoryManager.ts index 66eff02824..3c7abaacc6 100644 --- a/packages/cli/src/ui/hooks/useHistoryManager.ts +++ b/packages/cli/src/ui/hooks/useHistoryManager.ts @@ -17,7 +17,7 @@ export interface UseHistoryManagerReturn { history: HistoryItem[]; addItem: ( itemData: Omit, - baseTimestamp: number, + baseTimestamp?: number, isResuming?: boolean, ) => number; // Returns the generated ID updateItem: ( @@ -56,7 +56,7 @@ export function useHistory({ const addItem = useCallback( ( itemData: Omit, - baseTimestamp: number, + baseTimestamp: number = Date.now(), isResuming: boolean = false, ): number => { const id = getNextMessageId(baseTimestamp); diff --git a/packages/cli/src/ui/hooks/useIncludeDirsTrust.test.tsx b/packages/cli/src/ui/hooks/useIncludeDirsTrust.test.tsx index 1954301c2a..199e1b4587 100644 --- a/packages/cli/src/ui/hooks/useIncludeDirsTrust.test.tsx +++ b/packages/cli/src/ui/hooks/useIncludeDirsTrust.test.tsx @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { vi, describe, it, expect, beforeEach } from 'vitest'; +import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest'; import type { Mock } from 'vitest'; import { renderHook } from '../../test-utils/render.js'; import { waitFor } from '../../test-utils/async.js'; @@ -132,7 +132,6 @@ describe('useIncludeDirsTrust', () => { expect.objectContaining({ text: expect.stringContaining("Error adding '/dir2': Test error"), }), - expect.any(Number), ); expect( mockConfig.clearPendingIncludeDirectories, diff --git a/packages/cli/src/ui/hooks/useIncludeDirsTrust.tsx b/packages/cli/src/ui/hooks/useIncludeDirsTrust.tsx index 53f613898b..90cb33cb1a 100644 --- a/packages/cli/src/ui/hooks/useIncludeDirsTrust.tsx +++ b/packages/cli/src/ui/hooks/useIncludeDirsTrust.tsx @@ -18,18 +18,18 @@ import { MessageType, type HistoryItem } from '../types.js'; async function finishAddingDirectories( config: Config, - addItem: (itemData: Omit, baseTimestamp: number) => number, + addItem: ( + itemData: Omit, + baseTimestamp?: number, + ) => number, added: string[], errors: string[], ) { if (!config) { - addItem( - { - type: MessageType.ERROR, - text: 'Configuration is not available.', - }, - Date.now(), - ); + addItem({ + type: MessageType.ERROR, + text: 'Configuration is not available.', + }); return; } @@ -49,7 +49,7 @@ async function finishAddingDirectories( } if (errors.length > 0) { - addItem({ type: MessageType.ERROR, text: errors.join('\n') }, Date.now()); + addItem({ type: MessageType.ERROR, text: errors.join('\n') }); } } From e931ebe581bf46de8b9b900392af9431d6c694cf Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Tue, 13 Jan 2026 12:07:55 -0800 Subject: [PATCH 157/713] Improve key binding names and descriptions (#16529) --- docs/cli/keyboard-shortcuts.md | 26 ++++++++-------- packages/cli/src/config/keyBindings.ts | 31 ++++++++----------- packages/cli/src/ui/AppContainer.tsx | 4 +-- .../cli/src/ui/components/InputPrompt.tsx | 2 +- packages/cli/src/ui/keyMatchers.test.ts | 4 +-- 5 files changed, 31 insertions(+), 36 deletions(-) diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index 54defec914..831f74da80 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -62,7 +62,7 @@ available combinations. | Show the previous entry in history. | `Ctrl + P (no Shift)` | | Show the next entry in history. | `Ctrl + N (no Shift)` | | Start reverse search through history. | `Ctrl + R` | -| Insert the selected reverse-search match. | `Enter (no Ctrl)` | +| Submit the selected reverse-search match. | `Enter (no Ctrl)` | | Accept a suggestion while reverse searching. | `Tab` | #### Navigation @@ -100,18 +100,18 @@ available combinations. #### App Controls -| Action | Keys | -| ----------------------------------------------------------------- | ----------------------------------- | -| Toggle detailed error information. | `F12` | -| Toggle the full TODO list. | `Ctrl + T` | -| Toggle IDE context details. | `Ctrl + G` | -| Toggle Markdown rendering. | `Cmd + M` | -| Toggle copy mode when the terminal is using the alternate buffer. | `Ctrl + S` | -| Toggle YOLO (auto-approval) mode for tool calls. | `Ctrl + Y` | -| Toggle Auto Edit (auto-accept edits) mode. | `Shift + Tab` | -| Expand a height-constrained response to show additional lines. | `Ctrl + S` | -| Toggle focus between the shell and Gemini input. | `Tab (no Shift)` | -| Toggle focus out of the interactive shell and into Gemini input. | `Tab (no Shift)`
`Shift + Tab` | +| Action | Keys | +| ----------------------------------------------------------------- | ---------------- | +| Toggle detailed error information. | `F12` | +| Toggle the full TODO list. | `Ctrl + T` | +| Show IDE context details. | `Ctrl + G` | +| Toggle Markdown rendering. | `Cmd + M` | +| Toggle copy mode when the terminal is using the alternate buffer. | `Ctrl + S` | +| Toggle YOLO (auto-approval) mode for tool calls. | `Ctrl + Y` | +| Toggle Auto Edit (auto-accept edits) mode. | `Shift + Tab` | +| Expand a height-constrained response to show additional lines. | `Ctrl + S` | +| Focus the shell input from the gemini input. | `Tab (no Shift)` | +| Focus the Gemini input from the shell input. | `Tab` | #### Session Control diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index ba7b2e10a3..4e0daf5ae2 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -59,7 +59,7 @@ export enum Command { // App level bindings SHOW_ERROR_DETAILS = 'showErrorDetails', SHOW_FULL_TODOS = 'showFullTodos', - TOGGLE_IDE_CONTEXT_DETAIL = 'toggleIDEContextDetail', + SHOW_IDE_CONTEXT_DETAIL = 'showIDEContextDetail', TOGGLE_MARKDOWN = 'toggleMarkdown', TOGGLE_COPY_MODE = 'toggleCopyMode', TOGGLE_YOLO = 'toggleYolo', @@ -81,8 +81,8 @@ export enum Command { REVERSE_SEARCH = 'reverseSearch', SUBMIT_REVERSE_SEARCH = 'submitReverseSearch', ACCEPT_SUGGESTION_REVERSE_SEARCH = 'acceptSuggestionReverseSearch', - TOGGLE_SHELL_INPUT_FOCUS_IN = 'toggleShellInputFocus', - TOGGLE_SHELL_INPUT_FOCUS_OUT = 'toggleShellInputFocusOut', + FOCUS_SHELL_INPUT = 'focusShellInput', + UNFOCUS_SHELL_INPUT = 'unfocusShellInput', // Suggestion expansion EXPAND_SUGGESTION = 'expandSuggestion', @@ -243,7 +243,7 @@ export const defaultKeyBindings: KeyBindingConfig = { // App level bindings [Command.SHOW_ERROR_DETAILS]: [{ key: 'f12' }], [Command.SHOW_FULL_TODOS]: [{ key: 't', ctrl: true }], - [Command.TOGGLE_IDE_CONTEXT_DETAIL]: [{ key: 'g', ctrl: true }], + [Command.SHOW_IDE_CONTEXT_DETAIL]: [{ key: 'g', ctrl: true }], [Command.TOGGLE_MARKDOWN]: [{ key: 'm', command: true }], [Command.TOGGLE_COPY_MODE]: [{ key: 's', ctrl: true }], [Command.TOGGLE_YOLO]: [{ key: 'y', ctrl: true }], @@ -259,11 +259,8 @@ export const defaultKeyBindings: KeyBindingConfig = { // Note: original logic ONLY checked ctrl=false, ignored meta/shift/paste [Command.SUBMIT_REVERSE_SEARCH]: [{ key: 'return', ctrl: false }], [Command.ACCEPT_SUGGESTION_REVERSE_SEARCH]: [{ key: 'tab' }], - [Command.TOGGLE_SHELL_INPUT_FOCUS_IN]: [{ key: 'tab', shift: false }], - [Command.TOGGLE_SHELL_INPUT_FOCUS_OUT]: [ - { key: 'tab', shift: false }, - { key: 'tab', shift: true }, - ], + [Command.FOCUS_SHELL_INPUT]: [{ key: 'tab', shift: false }], + [Command.UNFOCUS_SHELL_INPUT]: [{ key: 'tab' }], // Suggestion expansion [Command.EXPAND_SUGGESTION]: [{ key: 'right' }], [Command.COLLAPSE_SUGGESTION]: [{ key: 'left' }], @@ -364,14 +361,14 @@ export const commandCategories: readonly CommandCategory[] = [ commands: [ Command.SHOW_ERROR_DETAILS, Command.SHOW_FULL_TODOS, - Command.TOGGLE_IDE_CONTEXT_DETAIL, + Command.SHOW_IDE_CONTEXT_DETAIL, Command.TOGGLE_MARKDOWN, Command.TOGGLE_COPY_MODE, Command.TOGGLE_YOLO, Command.TOGGLE_AUTO_EDIT, Command.SHOW_MORE_LINES, - Command.TOGGLE_SHELL_INPUT_FOCUS_IN, - Command.TOGGLE_SHELL_INPUT_FOCUS_OUT, + Command.FOCUS_SHELL_INPUT, + Command.UNFOCUS_SHELL_INPUT, ], }, { @@ -424,7 +421,7 @@ export const commandDescriptions: Readonly> = { [Command.PASTE_CLIPBOARD]: 'Paste from the clipboard.', [Command.SHOW_ERROR_DETAILS]: 'Toggle detailed error information.', [Command.SHOW_FULL_TODOS]: 'Toggle the full TODO list.', - [Command.TOGGLE_IDE_CONTEXT_DETAIL]: 'Toggle IDE context details.', + [Command.SHOW_IDE_CONTEXT_DETAIL]: 'Show IDE context details.', [Command.TOGGLE_MARKDOWN]: 'Toggle Markdown rendering.', [Command.TOGGLE_COPY_MODE]: 'Toggle copy mode when the terminal is using the alternate buffer.', @@ -435,13 +432,11 @@ export const commandDescriptions: Readonly> = { [Command.SHOW_MORE_LINES]: 'Expand a height-constrained response to show additional lines.', [Command.REVERSE_SEARCH]: 'Start reverse search through history.', - [Command.SUBMIT_REVERSE_SEARCH]: 'Insert the selected reverse-search match.', + [Command.SUBMIT_REVERSE_SEARCH]: 'Submit the selected reverse-search match.', [Command.ACCEPT_SUGGESTION_REVERSE_SEARCH]: 'Accept a suggestion while reverse searching.', - [Command.TOGGLE_SHELL_INPUT_FOCUS_IN]: - 'Toggle focus between the shell and Gemini input.', - [Command.TOGGLE_SHELL_INPUT_FOCUS_OUT]: - 'Toggle focus out of the interactive shell and into Gemini input.', + [Command.FOCUS_SHELL_INPUT]: 'Focus the shell input from the gemini input.', + [Command.UNFOCUS_SHELL_INPUT]: 'Focus the Gemini input from the shell input.', [Command.EXPAND_SUGGESTION]: 'Expand an inline suggestion.', [Command.COLLAPSE_SUGGESTION]: 'Collapse an inline suggestion.', }; diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index ad5ddc5fed..4f3c9617a8 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -1277,7 +1277,7 @@ Logging in with Google... Restarting Gemini CLI to continue. return newValue; }); } else if ( - keyMatchers[Command.TOGGLE_IDE_CONTEXT_DETAIL](key) && + keyMatchers[Command.SHOW_IDE_CONTEXT_DETAIL](key) && config.getIdeMode() && ideContextState ) { @@ -1289,7 +1289,7 @@ Logging in with Google... Restarting Gemini CLI to continue. ) { setConstrainHeight(false); } else if ( - keyMatchers[Command.TOGGLE_SHELL_INPUT_FOCUS_OUT](key) && + keyMatchers[Command.UNFOCUS_SHELL_INPUT](key) && activePtyId && embeddedShellFocused ) { diff --git a/packages/cli/src/ui/components/InputPrompt.tsx b/packages/cli/src/ui/components/InputPrompt.tsx index 239e192fec..2ed22900b2 100644 --- a/packages/cli/src/ui/components/InputPrompt.tsx +++ b/packages/cli/src/ui/components/InputPrompt.tsx @@ -829,7 +829,7 @@ export const InputPrompt: React.FC = ({ return; } - if (keyMatchers[Command.TOGGLE_SHELL_INPUT_FOCUS_IN](key)) { + if (keyMatchers[Command.FOCUS_SHELL_INPUT](key)) { // If we got here, Autocomplete didn't handle the key (e.g. no suggestions). if (activePtyId) { setEmbeddedShellFocused(true); diff --git a/packages/cli/src/ui/keyMatchers.test.ts b/packages/cli/src/ui/keyMatchers.test.ts index 2cf98b7b9c..4b112de358 100644 --- a/packages/cli/src/ui/keyMatchers.test.ts +++ b/packages/cli/src/ui/keyMatchers.test.ts @@ -289,7 +289,7 @@ describe('keyMatchers', () => { negative: [createKey('t'), createKey('e', { ctrl: true })], }, { - command: Command.TOGGLE_IDE_CONTEXT_DETAIL, + command: Command.SHOW_IDE_CONTEXT_DETAIL, positive: [createKey('g', { ctrl: true })], negative: [createKey('g'), createKey('t', { ctrl: true })], }, @@ -336,7 +336,7 @@ describe('keyMatchers', () => { negative: [createKey('return'), createKey('space')], }, { - command: Command.TOGGLE_SHELL_INPUT_FOCUS_IN, + command: Command.FOCUS_SHELL_INPUT, positive: [createKey('tab')], negative: [createKey('f', { ctrl: true }), createKey('f')], }, From 92e31e3c4aede4a84f29ea31b372f29dbd55b67e Mon Sep 17 00:00:00 2001 From: joshualitt Date: Tue, 13 Jan 2026 12:16:02 -0800 Subject: [PATCH 158/713] feat(core, cli): Add support for agents in settings.json. (#16433) --- docs/get-started/configuration.md | 8 ++ packages/cli/src/config/config.ts | 1 + packages/cli/src/config/settingsSchema.ts | 56 ++++++++ packages/core/src/agents/registry.test.ts | 121 ++++++++++++++++++ packages/core/src/agents/registry.ts | 82 +++++++++--- packages/core/src/config/config.ts | 27 +++- .../core/src/services/modelConfigService.ts | 93 ++++++++------ schemas/settings.schema.json | 50 ++++++++ 8 files changed, 382 insertions(+), 56 deletions(-) diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 810468e406..93bcefa778 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -557,6 +557,14 @@ their corresponding top-level category object in your `settings.json` file. used. - **Default:** `[]` +#### `agents` + +- **`agents.overrides`** (object): + - **Description:** Override settings for specific agents, e.g. to disable the + agent, set a custom model config, or run config. + - **Default:** `{}` + - **Requires restart:** Yes + #### `context` - **`context.fileName`** (string | string[]): diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 4d353b360c..c10fd2518e 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -660,6 +660,7 @@ export async function loadCliConfig( mcpServers: mcpEnabled ? settings.mcpServers : {}, mcpEnabled, extensionsEnabled, + agents: settings.agents, allowedMcpServers: mcpEnabled ? (argv.allowedMcpServerNames ?? settings.mcp?.allowed) : undefined, diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index c4e7cc7faa..c48e49cf01 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -785,6 +785,32 @@ const SETTINGS_SCHEMA = { }, }, + agents: { + type: 'object', + label: 'Agents', + category: 'Advanced', + requiresRestart: true, + default: {}, + description: 'Settings for subagents.', + showInDialog: false, + properties: { + overrides: { + type: 'object', + label: 'Agent Overrides', + category: 'Advanced', + requiresRestart: true, + default: {}, + description: + 'Override settings for specific agents, e.g. to disable the agent, set a custom model config, or run config.', + showInDialog: false, + additionalProperties: { + type: 'object', + ref: 'AgentOverride', + }, + }, + }, + }, + context: { type: 'object', label: 'Context', @@ -2002,6 +2028,36 @@ export const SETTINGS_SCHEMA_DEFINITIONS: Record< }, }, }, + AgentOverride: { + type: 'object', + description: 'Override settings for a specific agent.', + additionalProperties: false, + properties: { + modelConfig: { + type: 'object', + additionalProperties: true, + }, + runConfig: { + type: 'object', + description: 'Run configuration for an agent.', + additionalProperties: false, + properties: { + maxTimeMinutes: { + type: 'number', + description: 'The maximum execution time for the agent in minutes.', + }, + maxTurns: { + type: 'number', + description: 'The maximum number of conversational turns.', + }, + }, + }, + disabled: { + type: 'boolean', + description: 'Whether to disable the agent.', + }, + }, + }, CustomTheme: { type: 'object', description: diff --git a/packages/core/src/agents/registry.test.ts b/packages/core/src/agents/registry.test.ts index 95d0f925eb..837d4c5f63 100644 --- a/packages/core/src/agents/registry.test.ts +++ b/packages/core/src/agents/registry.test.ts @@ -619,6 +619,127 @@ describe('AgentRegistry', () => { ); }); }); + + describe('overrides', () => { + it('should skip registration if agent is disabled in settings', async () => { + const config = makeFakeConfig({ + agents: { + overrides: { + MockAgent: { disabled: true }, + }, + }, + }); + const registry = new TestableAgentRegistry(config); + + await registry.testRegisterAgent(MOCK_AGENT_V1); + + expect(registry.getDefinition('MockAgent')).toBeUndefined(); + }); + + it('should skip remote agent registration if disabled in settings', async () => { + const config = makeFakeConfig({ + agents: { + overrides: { + RemoteAgent: { disabled: true }, + }, + }, + }); + const registry = new TestableAgentRegistry(config); + + const remoteAgent: AgentDefinition = { + kind: 'remote', + name: 'RemoteAgent', + description: 'A remote agent', + agentCardUrl: 'https://example.com/card', + inputConfig: { inputs: {} }, + }; + + await registry.testRegisterAgent(remoteAgent); + + expect(registry.getDefinition('RemoteAgent')).toBeUndefined(); + }); + + it('should merge runConfig overrides', async () => { + const config = makeFakeConfig({ + agents: { + overrides: { + MockAgent: { + runConfig: { maxTurns: 50 }, + }, + }, + }, + }); + const registry = new TestableAgentRegistry(config); + + await registry.testRegisterAgent(MOCK_AGENT_V1); + + const def = registry.getDefinition('MockAgent') as LocalAgentDefinition; + expect(def.runConfig.max_turns).toBe(50); + expect(def.runConfig.max_time_minutes).toBe( + MOCK_AGENT_V1.runConfig.max_time_minutes, + ); + }); + + it('should apply modelConfig overrides', async () => { + const config = makeFakeConfig({ + agents: { + overrides: { + MockAgent: { + modelConfig: { + model: 'overridden-model', + generateContentConfig: { + temperature: 0.5, + }, + }, + }, + }, + }, + }); + const registry = new TestableAgentRegistry(config); + + await registry.testRegisterAgent(MOCK_AGENT_V1); + + const resolved = config.modelConfigService.getResolvedConfig({ + model: getModelConfigAlias(MOCK_AGENT_V1), + }); + + expect(resolved.model).toBe('overridden-model'); + expect(resolved.generateContentConfig.temperature).toBe(0.5); + // topP should still be MOCK_AGENT_V1.modelConfig.top_p (1) because we merged + expect(resolved.generateContentConfig.topP).toBe(1); + }); + + it('should deep merge generateContentConfig (e.g. thinkingConfig)', async () => { + const config = makeFakeConfig({ + agents: { + overrides: { + MockAgent: { + modelConfig: { + generateContentConfig: { + thinkingConfig: { + thinkingBudget: 16384, + }, + }, + }, + }, + }, + }, + }); + const registry = new TestableAgentRegistry(config); + + await registry.testRegisterAgent(MOCK_AGENT_V1); + + const resolved = config.modelConfigService.getResolvedConfig({ + model: getModelConfigAlias(MOCK_AGENT_V1), + }); + + expect(resolved.generateContentConfig.thinkingConfig).toEqual({ + includeThoughts: true, // Preserved from default + thinkingBudget: 16384, // Overridden + }); + }); + }); + describe('getToolDescription', () => { it('should return default message when no agents are registered', () => { expect(registry.getToolDescription()).toContain( diff --git a/packages/core/src/agents/registry.ts b/packages/core/src/agents/registry.ts index cd3065e0f6..0038a2b783 100644 --- a/packages/core/src/agents/registry.ts +++ b/packages/core/src/agents/registry.ts @@ -14,7 +14,6 @@ import { CliHelpAgent } from './cli-help-agent.js'; import { A2AClientManager } from './a2a-client-manager.js'; import { ADCHandler } from './remote-invocation.js'; import { type z } from 'zod'; -import type { GenerateContentConfig } from '@google/genai'; import { debugLogger } from '../utils/debugLogger.js'; import { DEFAULT_GEMINI_MODEL, @@ -23,6 +22,10 @@ import { isPreviewModel, isAutoModel, } from '../config/models.js'; +import { + type ModelConfig, + ModelConfigService, +} from '../services/modelConfigService.js'; /** * Returns the model config alias for a given agent definition. @@ -226,49 +229,83 @@ export class AgentRegistry { return; } + const overrides = + this.config.getAgentsSettings().overrides?.[definition.name]; + if (overrides?.disabled) { + if (this.config.getDebugMode()) { + debugLogger.log( + `[AgentRegistry] Skipping disabled agent '${definition.name}'`, + ); + } + return; + } + if (this.agents.has(definition.name) && this.config.getDebugMode()) { debugLogger.log(`[AgentRegistry] Overriding agent '${definition.name}'`); } - this.agents.set(definition.name, definition); + // TODO(16443): Refactor definition merging logic into a helper. + // To do this, we need to align the definition of the internal `Definition` + // type with the one exported in settings.json. + const mergedDefinition = { + ...definition, + runConfig: { + ...definition.runConfig, + max_time_minutes: + overrides?.runConfig?.maxTimeMinutes ?? + definition.runConfig.max_time_minutes, + max_turns: + overrides?.runConfig?.maxTurns ?? definition.runConfig.max_turns, + }, + }; + + this.agents.set(mergedDefinition.name, mergedDefinition); // Register model config. We always create a runtime alias. However, // if the user is using `auto` as a model string then we also create // runtime overrides to ensure the subagent generation settings are // respected regardless of the final model string from routing. // TODO(12916): Migrate sub-agents where possible to static configs. - const modelConfig = definition.modelConfig; + const modelConfig = mergedDefinition.modelConfig; let model = modelConfig.model; if (model === 'inherit') { model = this.config.getModel(); } - const generateContentConfig: GenerateContentConfig = { - temperature: modelConfig.temp, - topP: modelConfig.top_p, - thinkingConfig: { - includeThoughts: true, - thinkingBudget: modelConfig.thinkingBudget ?? -1, + let agentModelConfig: ModelConfig = { + model, + generateContentConfig: { + temperature: modelConfig.temp, + topP: modelConfig.top_p, + thinkingConfig: { + includeThoughts: true, + thinkingBudget: modelConfig.thinkingBudget ?? -1, + }, }, }; + // Apply standardized modelConfig overrides if present. + if (overrides?.modelConfig) { + agentModelConfig = ModelConfigService.merge( + agentModelConfig, + overrides.modelConfig, + ); + } + this.config.modelConfigService.registerRuntimeModelConfig( - getModelConfigAlias(definition), + getModelConfigAlias(mergedDefinition), { - modelConfig: { - model, - generateContentConfig, - }, + modelConfig: agentModelConfig, }, ); - if (isAutoModel(model)) { + if (agentModelConfig.model && isAutoModel(agentModelConfig.model)) { this.config.modelConfigService.registerRuntimeModelOverride({ match: { - overrideScope: definition.name, + overrideScope: mergedDefinition.name, }, modelConfig: { - generateContentConfig, + generateContentConfig: agentModelConfig.generateContentConfig, }, }); } @@ -292,6 +329,17 @@ export class AgentRegistry { return; } + const overrides = + this.config.getAgentsSettings().overrides?.[definition.name]; + if (overrides?.disabled) { + if (this.config.getDebugMode()) { + debugLogger.log( + `[AgentRegistry] Skipping disabled remote agent '${definition.name}'`, + ); + } + return; + } + if (this.agents.has(definition.name) && this.config.getDebugMode()) { debugLogger.log(`[AgentRegistry] Overriding agent '${definition.name}'`); } diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 02d73b1b6b..6dce2f7403 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -69,7 +69,10 @@ import type { FallbackModelHandler } from '../fallback/types.js'; import { ModelAvailabilityService } from '../availability/modelAvailabilityService.js'; import { ModelRouterService } from '../routing/modelRouterService.js'; import { OutputFormat } from '../output/types.js'; -import type { ModelConfigServiceConfig } from '../services/modelConfigService.js'; +import type { + ModelConfig, + ModelConfigServiceConfig, +} from '../services/modelConfigService.js'; import { ModelConfigService } from '../services/modelConfigService.js'; import { DEFAULT_MODEL_CONFIGS } from './defaultModelConfigs.js'; import { ContextManager } from '../services/contextManager.js'; @@ -159,6 +162,21 @@ export interface CliHelpAgentSettings { enabled?: boolean; } +export interface AgentRunConfig { + maxTimeMinutes?: number; + maxTurns?: number; +} + +export interface AgentOverride { + modelConfig?: ModelConfig; + runConfig?: AgentRunConfig; + disabled?: boolean; +} + +export interface AgentSettings { + overrides?: Record; +} + /** * All information required in CLI to handle an extension. Defined in Core so * that the collection of loaded, active, and inactive extensions can be passed @@ -364,6 +382,7 @@ export interface ConfigParameters { onModelChange?: (model: string) => void; mcpEnabled?: boolean; extensionsEnabled?: boolean; + agents?: AgentSettings; onReload?: () => Promise<{ disabledSkills?: string[] }>; } @@ -496,6 +515,7 @@ export class Config { | undefined; private readonly enableAgents: boolean; + private readonly agents: AgentSettings; private readonly skillsSupport: boolean; private disabledSkills: string[]; @@ -570,6 +590,7 @@ export class Config { this.model = params.model; this._activeModel = params.model; this.enableAgents = params.enableAgents ?? false; + this.agents = params.agents ?? {}; this.disableLLMCorrection = params.disableLLMCorrection ?? false; this.skillsSupport = params.skillsSupport ?? false; this.disabledSkills = params.disabledSkills ?? []; @@ -1443,6 +1464,10 @@ export class Config { return this.noBrowser; } + getAgentsSettings(): AgentSettings { + return this.agents; + } + isBrowserLaunchSuppressed(): boolean { return this.getNoBrowser() || !shouldAttemptBrowserLaunch(); } diff --git a/packages/core/src/services/modelConfigService.ts b/packages/core/src/services/modelConfigService.ts index 0ec6d77ffb..a73764e75a 100644 --- a/packages/core/src/services/modelConfigService.ts +++ b/packages/core/src/services/modelConfigService.ts @@ -119,14 +119,10 @@ export class ModelConfigService { ...this.runtimeAliases, }; - const { - aliasChain, - baseModel: initialBaseModel, - resolvedConfig: initialResolvedConfig, - } = this.resolveAliasChain(context.model, allAliases); - - let baseModel = initialBaseModel; - let resolvedConfig = initialResolvedConfig; + const { aliasChain, baseModel, resolvedConfig } = this.resolveAliasChain( + context.model, + allAliases, + ); const modelToLevel = this.buildModelLevelMap(aliasChain, baseModel); const allOverrides = [ @@ -142,19 +138,22 @@ export class ModelConfigService { this.sortOverrides(matches); + let currentConfig: ModelConfig = { + model: baseModel, + generateContentConfig: resolvedConfig, + }; + for (const match of matches) { - if (match.modelConfig.model) { - baseModel = match.modelConfig.model; - } - if (match.modelConfig.generateContentConfig) { - resolvedConfig = this.deepMerge( - resolvedConfig, - match.modelConfig.generateContentConfig, - ); - } + currentConfig = ModelConfigService.merge( + currentConfig, + match.modelConfig, + ); } - return { model: baseModel, generateContentConfig: resolvedConfig }; + return { + model: currentConfig.model, + generateContentConfig: currentConfig.generateContentConfig ?? {}, + }; } private resolveAliasChain( @@ -165,8 +164,6 @@ export class ModelConfigService { baseModel: string | undefined; resolvedConfig: GenerateContentConfig; } { - let baseModel: string | undefined = undefined; - let resolvedConfig: GenerateContentConfig = {}; const aliasChain: string[] = []; if (allAliases[requestedModel]) { @@ -194,17 +191,19 @@ export class ModelConfigService { // Root-to-Leaf chain for merging and level assignment. const reversedChain = [...aliasChain].reverse(); + let resolvedConfig: ModelConfig = {}; for (const aliasName of reversedChain) { const alias = allAliases[aliasName]; - if (alias.modelConfig.model) { - baseModel = alias.modelConfig.model; - } - resolvedConfig = this.deepMerge( + resolvedConfig = ModelConfigService.merge( resolvedConfig, - alias.modelConfig.generateContentConfig, + alias.modelConfig, ); } - return { aliasChain: reversedChain, baseModel, resolvedConfig }; + return { + aliasChain: reversedChain, + baseModel: resolvedConfig.model, + resolvedConfig: resolvedConfig.generateContentConfig ?? {}, + }; } return { @@ -298,21 +297,36 @@ export class ModelConfigService { } as ResolvedModelConfig; } - private isObject(item: unknown): item is Record { + static isObject(item: unknown): item is Record { return !!item && typeof item === 'object' && !Array.isArray(item); } - private deepMerge( - config1: GenerateContentConfig | undefined, - config2: GenerateContentConfig | undefined, - ): Record { - return this.genericDeepMerge( - config1 as Record | undefined, - config2 as Record | undefined, - ); + /** + * Merges an override `ModelConfig` into a base `ModelConfig`. + * The override's model name takes precedence if provided. + * The `generateContentConfig` properties are deeply merged. + */ + static merge(base: ModelConfig, override: ModelConfig): ModelConfig { + return { + model: override.model ?? base.model, + generateContentConfig: ModelConfigService.deepMerge( + base.generateContentConfig, + override.generateContentConfig, + ), + }; } - private genericDeepMerge( + static deepMerge( + config1: GenerateContentConfig | undefined, + config2: GenerateContentConfig | undefined, + ): GenerateContentConfig { + return ModelConfigService.genericDeepMerge( + config1 as Record | undefined, + config2 as Record | undefined, + ) as GenerateContentConfig; + } + + private static genericDeepMerge( ...objects: Array | undefined> ): Record { return objects.reduce((acc: Record, obj) => { @@ -329,8 +343,11 @@ export class ModelConfigService { // override the base array. // TODO(joshualitt): Consider knobs here, i.e. opt-in to deep merging // arrays on a case-by-case basis. - if (this.isObject(accValue) && this.isObject(objValue)) { - acc[key] = this.deepMerge(accValue, objValue); + if ( + ModelConfigService.isObject(accValue) && + ModelConfigService.isObject(objValue) + ) { + acc[key] = ModelConfigService.genericDeepMerge(accValue, objValue); } else { acc[key] = objValue; } diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index 6c7f8beaa4..2c3effa172 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -926,6 +926,26 @@ }, "additionalProperties": false }, + "agents": { + "title": "Agents", + "description": "Settings for subagents.", + "markdownDescription": "Settings for subagents.\n\n- Category: `Advanced`\n- Requires restart: `yes`\n- Default: `{}`", + "default": {}, + "type": "object", + "properties": { + "overrides": { + "title": "Agent Overrides", + "description": "Override settings for specific agents, e.g. to disable the agent, set a custom model config, or run config.", + "markdownDescription": "Override settings for specific agents, e.g. to disable the agent, set a custom model config, or run config.\n\n- Category: `Advanced`\n- Requires restart: `yes`\n- Default: `{}`", + "default": {}, + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/AgentOverride" + } + } + }, + "additionalProperties": false + }, "context": { "title": "Context", "description": "Settings for managing context provided to the model.", @@ -1854,6 +1874,36 @@ } } }, + "AgentOverride": { + "type": "object", + "description": "Override settings for a specific agent.", + "additionalProperties": false, + "properties": { + "modelConfig": { + "type": "object", + "additionalProperties": true + }, + "runConfig": { + "type": "object", + "description": "Run configuration for an agent.", + "additionalProperties": false, + "properties": { + "maxTimeMinutes": { + "type": "number", + "description": "The maximum execution time for the agent in minutes." + }, + "maxTurns": { + "type": "number", + "description": "The maximum number of conversational turns." + } + } + }, + "disabled": { + "type": "boolean", + "description": "Whether to disable the agent." + } + } + }, "CustomTheme": { "type": "object", "description": "Custom theme definition used for styling Gemini CLI output. Colors are provided as hex strings or named ANSI colors.", From e8be252b755864bf9e60f18a69c198a762a11df0 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 13 Jan 2026 13:14:14 -0800 Subject: [PATCH 159/713] fix(cli): fix 'gemini skills install' unknown argument error (#16537) --- packages/cli/src/commands/skills/disable.test.ts | 2 +- packages/cli/src/commands/skills/disable.ts | 2 +- packages/cli/src/commands/skills/install.test.ts | 13 ++++++++++++- packages/cli/src/commands/skills/install.ts | 2 +- packages/cli/src/commands/skills/list.test.ts | 2 +- packages/cli/src/commands/skills/list.ts | 2 +- packages/cli/src/commands/skills/uninstall.test.ts | 11 ++++++++++- packages/cli/src/commands/skills/uninstall.ts | 2 +- 8 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/commands/skills/disable.test.ts b/packages/cli/src/commands/skills/disable.test.ts index b7bc8805c8..f4ae0d954e 100644 --- a/packages/cli/src/commands/skills/disable.test.ts +++ b/packages/cli/src/commands/skills/disable.test.ts @@ -108,7 +108,7 @@ describe('skills disable command', () => { describe('disableCommand', () => { it('should have correct command and describe', () => { - expect(disableCommand.command).toBe('disable '); + expect(disableCommand.command).toBe('disable [--scope]'); expect(disableCommand.describe).toBe('Disables an agent skill.'); }); }); diff --git a/packages/cli/src/commands/skills/disable.ts b/packages/cli/src/commands/skills/disable.ts index e0b657afbc..fcb69c087d 100644 --- a/packages/cli/src/commands/skills/disable.ts +++ b/packages/cli/src/commands/skills/disable.ts @@ -31,7 +31,7 @@ export async function handleDisable(args: DisableArgs) { } export const disableCommand: CommandModule = { - command: 'disable ', + command: 'disable [--scope]', describe: 'Disables an agent skill.', builder: (yargs) => yargs diff --git a/packages/cli/src/commands/skills/install.test.ts b/packages/cli/src/commands/skills/install.test.ts index d3f36fbac3..e0621c8028 100644 --- a/packages/cli/src/commands/skills/install.test.ts +++ b/packages/cli/src/commands/skills/install.test.ts @@ -17,7 +17,7 @@ vi.mock('@google/gemini-cli-core', () => ({ })); import { debugLogger } from '@google/gemini-cli-core'; -import { handleInstall } from './install.js'; +import { handleInstall, installCommand } from './install.js'; describe('skill install command', () => { beforeEach(() => { @@ -25,6 +25,17 @@ describe('skill install command', () => { vi.spyOn(process, 'exit').mockImplementation(() => undefined as never); }); + describe('installCommand', () => { + it('should have correct command and describe', () => { + expect(installCommand.command).toBe( + 'install [--scope] [--path]', + ); + expect(installCommand.describe).toBe( + 'Installs an agent skill from a git repository URL or a local path.', + ); + }); + }); + it('should call installSkill with correct arguments for user scope', async () => { mockInstallSkill.mockResolvedValue([ { name: 'test-skill', location: '/mock/user/skills/test-skill' }, diff --git a/packages/cli/src/commands/skills/install.ts b/packages/cli/src/commands/skills/install.ts index 9dbc0007bf..bdf8402de7 100644 --- a/packages/cli/src/commands/skills/install.ts +++ b/packages/cli/src/commands/skills/install.ts @@ -46,7 +46,7 @@ export async function handleInstall(args: InstallArgs) { } export const installCommand: CommandModule = { - command: 'install ', + command: 'install [--scope] [--path]', describe: 'Installs an agent skill from a git repository URL or a local path.', builder: (yargs) => diff --git a/packages/cli/src/commands/skills/list.test.ts b/packages/cli/src/commands/skills/list.test.ts index 81230b33a2..e7e25a2736 100644 --- a/packages/cli/src/commands/skills/list.test.ts +++ b/packages/cli/src/commands/skills/list.test.ts @@ -184,7 +184,7 @@ describe('skills list command', () => { const command = listCommand; it('should have correct command and describe', () => { - expect(command.command).toBe('list'); + expect(command.command).toBe('list [--all]'); expect(command.describe).toBe('Lists discovered agent skills.'); }); }); diff --git a/packages/cli/src/commands/skills/list.ts b/packages/cli/src/commands/skills/list.ts index 17f225c510..c262f39b9b 100644 --- a/packages/cli/src/commands/skills/list.ts +++ b/packages/cli/src/commands/skills/list.ts @@ -63,7 +63,7 @@ export async function handleList(args: { all?: boolean }) { } export const listCommand: CommandModule = { - command: 'list', + command: 'list [--all]', describe: 'Lists discovered agent skills.', builder: (yargs) => yargs.option('all', { diff --git a/packages/cli/src/commands/skills/uninstall.test.ts b/packages/cli/src/commands/skills/uninstall.test.ts index d1feaf7838..74f1730590 100644 --- a/packages/cli/src/commands/skills/uninstall.test.ts +++ b/packages/cli/src/commands/skills/uninstall.test.ts @@ -17,7 +17,7 @@ vi.mock('@google/gemini-cli-core', () => ({ })); import { debugLogger } from '@google/gemini-cli-core'; -import { handleUninstall } from './uninstall.js'; +import { handleUninstall, uninstallCommand } from './uninstall.js'; describe('skill uninstall command', () => { beforeEach(() => { @@ -25,6 +25,15 @@ describe('skill uninstall command', () => { vi.spyOn(process, 'exit').mockImplementation(() => undefined as never); }); + describe('uninstallCommand', () => { + it('should have correct command and describe', () => { + expect(uninstallCommand.command).toBe('uninstall [--scope]'); + expect(uninstallCommand.describe).toBe( + 'Uninstalls an agent skill by name.', + ); + }); + }); + it('should call uninstallSkill with correct arguments for user scope', async () => { mockUninstallSkill.mockResolvedValue({ location: '/mock/user/skills/test-skill', diff --git a/packages/cli/src/commands/skills/uninstall.ts b/packages/cli/src/commands/skills/uninstall.ts index 99f9091e3c..1ab0c130b9 100644 --- a/packages/cli/src/commands/skills/uninstall.ts +++ b/packages/cli/src/commands/skills/uninstall.ts @@ -41,7 +41,7 @@ export async function handleUninstall(args: UninstallArgs) { } export const uninstallCommand: CommandModule = { - command: 'uninstall ', + command: 'uninstall [--scope]', describe: 'Uninstalls an agent skill by name.', builder: (yargs) => yargs From b518125c4618dbc661b47a639d63e13e5f3d2f9e Mon Sep 17 00:00:00 2001 From: Adam Weidman <65992621+adamfweidman@users.noreply.github.com> Date: Tue, 13 Jan 2026 16:35:31 -0500 Subject: [PATCH 160/713] chore(ui): optimize AgentsStatus layout with dense list style and group separation (#16545) --- .../__snapshots__/HistoryItemDisplay.test.tsx.snap | 1 - packages/cli/src/ui/components/views/AgentsStatus.tsx | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/ui/components/__snapshots__/HistoryItemDisplay.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/HistoryItemDisplay.test.tsx.snap index ad04fdb2ba..7c92db1ab6 100644 --- a/packages/cli/src/ui/components/__snapshots__/HistoryItemDisplay.test.tsx.snap +++ b/packages/cli/src/ui/components/__snapshots__/HistoryItemDisplay.test.tsx.snap @@ -363,7 +363,6 @@ Remote Agents - remote_agent Remote agent description. - " `; diff --git a/packages/cli/src/ui/components/views/AgentsStatus.tsx b/packages/cli/src/ui/components/views/AgentsStatus.tsx index 2e6131f7a9..375a5c16e1 100644 --- a/packages/cli/src/ui/components/views/AgentsStatus.tsx +++ b/packages/cli/src/ui/components/views/AgentsStatus.tsx @@ -24,7 +24,7 @@ export const AgentsStatus: React.FC = ({ if (agents.length === 0) { return ( - + No agents available. ); @@ -34,7 +34,7 @@ export const AgentsStatus: React.FC = ({ if (agentList.length === 0) return null; return ( - + {title} @@ -66,6 +66,7 @@ export const AgentsStatus: React.FC = ({ return ( {renderAgentList('Local Agents', localAgents)} + {localAgents.length > 0 && remoteAgents.length > 0 && } {renderAgentList('Remote Agents', remoteAgents)} ); From b2e866585d4ae4545351afbd831f6fd713a8a633 Mon Sep 17 00:00:00 2001 From: Gal Zahavi <38544478+galz10@users.noreply.github.com> Date: Tue, 13 Jan 2026 14:01:30 -0800 Subject: [PATCH 161/713] fix(cli): allow @ file selector on slash command lines (#16370) --- .../cli/src/ui/components/InputPrompt.test.tsx | 6 +++++- packages/cli/src/ui/components/InputPrompt.tsx | 17 +++++++++++------ .../src/ui/hooks/useCommandCompletion.test.tsx | 12 ++++++++++-- .../cli/src/ui/hooks/useCommandCompletion.tsx | 2 ++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/ui/components/InputPrompt.test.tsx b/packages/cli/src/ui/components/InputPrompt.test.tsx index ee194dc3cb..68b044071d 100644 --- a/packages/cli/src/ui/components/InputPrompt.test.tsx +++ b/packages/cli/src/ui/components/InputPrompt.test.tsx @@ -26,7 +26,10 @@ import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; import type { UseShellHistoryReturn } from '../hooks/useShellHistory.js'; import { useShellHistory } from '../hooks/useShellHistory.js'; import type { UseCommandCompletionReturn } from '../hooks/useCommandCompletion.js'; -import { useCommandCompletion } from '../hooks/useCommandCompletion.js'; +import { + useCommandCompletion, + CompletionMode, +} from '../hooks/useCommandCompletion.js'; import type { UseInputHistoryReturn } from '../hooks/useInputHistory.js'; import { useInputHistory } from '../hooks/useInputHistory.js'; import type { UseReverseSearchCompletionReturn } from '../hooks/useReverseSearchCompletion.js'; @@ -214,6 +217,7 @@ describe('InputPrompt', () => { leafCommand: null, }, getCompletedText: vi.fn().mockReturnValue(null), + completionMode: CompletionMode.IDLE, }; mockedUseCommandCompletion.mockReturnValue(mockCommandCompletion); diff --git a/packages/cli/src/ui/components/InputPrompt.tsx b/packages/cli/src/ui/components/InputPrompt.tsx index 2ed22900b2..20d84ca650 100644 --- a/packages/cli/src/ui/components/InputPrompt.tsx +++ b/packages/cli/src/ui/components/InputPrompt.tsx @@ -18,7 +18,10 @@ import chalk from 'chalk'; import stringWidth from 'string-width'; import { useShellHistory } from '../hooks/useShellHistory.js'; import { useReverseSearchCompletion } from '../hooks/useReverseSearchCompletion.js'; -import { useCommandCompletion } from '../hooks/useCommandCompletion.js'; +import { + useCommandCompletion, + CompletionMode, +} from '../hooks/useCommandCompletion.js'; import type { Key } from '../hooks/useKeypress.js'; import { useKeypress } from '../hooks/useKeypress.js'; import { keyMatchers, Command } from '../keyMatchers.js'; @@ -1045,11 +1048,13 @@ export const InputPrompt: React.FC = ({ scrollOffset={activeCompletion.visibleStartIndex} userInput={buffer.text} mode={ - buffer.text.startsWith('/') && - !reverseSearchActive && - !commandSearchActive - ? 'slash' - : 'reverse' + completion.completionMode === CompletionMode.AT + ? 'reverse' + : buffer.text.startsWith('/') && + !reverseSearchActive && + !commandSearchActive + ? 'slash' + : 'reverse' } expandedIndex={expandedSuggestionIndex} /> diff --git a/packages/cli/src/ui/hooks/useCommandCompletion.test.tsx b/packages/cli/src/ui/hooks/useCommandCompletion.test.tsx index 1679782707..e023de786f 100644 --- a/packages/cli/src/ui/hooks/useCommandCompletion.test.tsx +++ b/packages/cli/src/ui/hooks/useCommandCompletion.test.tsx @@ -16,7 +16,10 @@ import { import { act, useEffect } from 'react'; import { renderWithProviders } from '../../test-utils/render.js'; import { waitFor } from '../../test-utils/async.js'; -import { useCommandCompletion } from './useCommandCompletion.js'; +import { + useCommandCompletion, + CompletionMode, +} from './useCommandCompletion.js'; import type { CommandContext } from '../commands/types.js'; import type { Config } from '@google/gemini-cli-core'; import { useTextBuffer } from '../components/shared/text-buffer.js'; @@ -160,6 +163,7 @@ describe('useCommandCompletion', () => { expect(result.current.visibleStartIndex).toBe(0); expect(result.current.showSuggestions).toBe(false); expect(result.current.isLoadingSuggestions).toBe(false); + expect(result.current.completionMode).toBe(CompletionMode.IDLE); }); it('should reset state when completion mode becomes IDLE', async () => { @@ -207,7 +211,7 @@ describe('useCommandCompletion', () => { it('should call useAtCompletion with the correct query for an escaped space', async () => { const text = '@src/a\\ file.txt'; - renderCommandCompletionHook(text); + const { result } = renderCommandCompletionHook(text); await waitFor(() => { expect(useAtCompletion).toHaveBeenLastCalledWith( @@ -216,6 +220,7 @@ describe('useCommandCompletion', () => { pattern: 'src/a\\ file.txt', }), ); + expect(result.current.completionMode).toBe(CompletionMode.AT); }); }); @@ -272,6 +277,9 @@ describe('useCommandCompletion', () => { expect(result.current.showSuggestions).toBe( expectedShowSuggestions, ); + if (!shellModeActive) { + expect(result.current.completionMode).toBe(CompletionMode.SLASH); + } }); }, ); diff --git a/packages/cli/src/ui/hooks/useCommandCompletion.tsx b/packages/cli/src/ui/hooks/useCommandCompletion.tsx index b6c4991648..b5f3264ee7 100644 --- a/packages/cli/src/ui/hooks/useCommandCompletion.tsx +++ b/packages/cli/src/ui/hooks/useCommandCompletion.tsx @@ -55,6 +55,7 @@ export interface UseCommandCompletionReturn { leafCommand: SlashCommand | null; }; getCompletedText: (suggestion: Suggestion) => string | null; + completionMode: CompletionMode; } export function useCommandCompletion( @@ -341,5 +342,6 @@ export function useCommandCompletion( getCommandFromSuggestion: slashCompletionRange.getCommandFromSuggestion, slashCompletionRange, getCompletedText, + completionMode, }; } From 63c918fe7de79c760236270036647ae7a64530a6 Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Tue, 13 Jan 2026 14:17:05 -0800 Subject: [PATCH 162/713] fix(ui): resolve sticky header regression in tool messages (#16514) --- .../cli/src/ui/components/StickyHeader.tsx | 5 +- .../components/messages/ShellToolMessage.tsx | 53 ++++- .../ui/components/messages/ToolMessage.tsx | 7 +- .../ToolStickyHeaderRegression.test.tsx | 206 ++++++++++++++++++ .../ToolStickyHeaderRegression.test.tsx.snap | 41 ++++ 5 files changed, 297 insertions(+), 15 deletions(-) create mode 100644 packages/cli/src/ui/components/messages/ToolStickyHeaderRegression.test.tsx create mode 100644 packages/cli/src/ui/components/messages/__snapshots__/ToolStickyHeaderRegression.test.tsx.snap diff --git a/packages/cli/src/ui/components/StickyHeader.tsx b/packages/cli/src/ui/components/StickyHeader.tsx index 58608ce1c4..62d5dcd22d 100644 --- a/packages/cli/src/ui/components/StickyHeader.tsx +++ b/packages/cli/src/ui/components/StickyHeader.tsx @@ -5,7 +5,7 @@ */ import type React from 'react'; -import { Box } from 'ink'; +import { Box, type DOMElement } from 'ink'; import { theme } from '../semantic-colors.js'; export interface StickyHeaderProps { @@ -14,6 +14,7 @@ export interface StickyHeaderProps { isFirst: boolean; borderColor: string; borderDimColor: boolean; + containerRef?: React.RefObject; } export const StickyHeader: React.FC = ({ @@ -22,8 +23,10 @@ export const StickyHeader: React.FC = ({ isFirst, borderColor, borderDimColor, + containerRef, }) => ( = ({ name, + description, + resultDisplay, + status, + availableTerminalHeight, + terminalWidth, + emphasis = 'medium', + renderOutputAsMarkdown = true, + activeShellPtyId, + embeddedShellFocused, + ptyId, + config, + isFirst, + borderColor, + borderDimColor, }) => { const isThisShellFocused = @@ -60,8 +74,13 @@ export const ShellToolMessage: React.FC = ({ embeddedShellFocused; const { setEmbeddedShellFocused } = useUIActions(); - const containerRef = React.useRef(null); + + const headerRef = React.useRef(null); + + const contentRef = React.useRef(null); + // The shell is focusable if it's the shell command, it's executing, and the interactive shell is enabled. + const isThisShellFocusable = (name === SHELL_COMMAND_NAME || name === SHELL_NAME || @@ -69,17 +88,18 @@ export const ShellToolMessage: React.FC = ({ status === ToolCallStatus.Executing && config?.getEnableInteractiveShell(); - useMouseClick( - containerRef, - () => { - if (isThisShellFocusable) { - setEmbeddedShellFocused(true); - } - }, - { isActive: !!isThisShellFocusable }, - ); + const handleFocus = () => { + if (isThisShellFocusable) { + setEmbeddedShellFocused(true); + } + }; + + useMouseClick(headerRef, handleFocus, { isActive: !!isThisShellFocusable }); + + useMouseClick(contentRef, handleFocus, { isActive: !!isThisShellFocusable }); const wasFocusedRef = React.useRef(false); + React.useEffect(() => { if (isThisShellFocused) { wasFocusedRef.current = true; @@ -87,12 +107,15 @@ export const ShellToolMessage: React.FC = ({ if (embeddedShellFocused) { setEmbeddedShellFocused(false); } + wasFocusedRef.current = false; } }, [isThisShellFocused, embeddedShellFocused, setEmbeddedShellFocused]); const [lastUpdateTime, setLastUpdateTime] = React.useState(null); + const [userHasFocused, setUserHasFocused] = React.useState(false); + const [showFocusHint, setShowFocusHint] = React.useState(false); React.useEffect(() => { @@ -123,20 +146,23 @@ export const ShellToolMessage: React.FC = ({ isThisShellFocusable && (showFocusHint || userHasFocused); return ( - + <> + + {shouldShowFocusHint && ( @@ -144,9 +170,12 @@ export const ShellToolMessage: React.FC = ({ )} + {emphasis === 'high' && } + = ({ )} - + ); }; diff --git a/packages/cli/src/ui/components/messages/ToolMessage.tsx b/packages/cli/src/ui/components/messages/ToolMessage.tsx index f8180f92c5..de141d27cd 100644 --- a/packages/cli/src/ui/components/messages/ToolMessage.tsx +++ b/packages/cli/src/ui/components/messages/ToolMessage.tsx @@ -95,7 +95,10 @@ export const ToolMessage: React.FC = ({ isThisShellFocusable && (showFocusHint || userHasFocused); return ( - + // It is crucial we don't replace this <> with a Box because otherwise the + // sticky header inside it would be sticky to that box rather than to the + // parent component of this ToolMessage. + <> = ({ )} - + ); }; diff --git a/packages/cli/src/ui/components/messages/ToolStickyHeaderRegression.test.tsx b/packages/cli/src/ui/components/messages/ToolStickyHeaderRegression.test.tsx new file mode 100644 index 0000000000..eaba97a8eb --- /dev/null +++ b/packages/cli/src/ui/components/messages/ToolStickyHeaderRegression.test.tsx @@ -0,0 +1,206 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { renderWithProviders } from '../../../test-utils/render.js'; +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { ToolGroupMessage } from './ToolGroupMessage.js'; +import { ToolCallStatus } from '../../types.js'; +import { + ScrollableList, + type ScrollableListRef, +} from '../shared/ScrollableList.js'; +import { Box, Text } from 'ink'; +import { act, useRef, useEffect } from 'react'; +import { waitFor } from '../../../test-utils/async.js'; +import { SHELL_COMMAND_NAME } from '../../constants.js'; + +// Mock child components that might be complex +vi.mock('../TerminalOutput.js', () => ({ + TerminalOutput: () => MockTerminalOutput, +})); + +vi.mock('../AnsiOutput.js', () => ({ + AnsiOutputText: () => MockAnsiOutput, +})); + +vi.mock('../GeminiRespondingSpinner.js', () => ({ + GeminiRespondingSpinner: () => MockRespondingSpinner, +})); + +vi.mock('./DiffRenderer.js', () => ({ + DiffRenderer: () => MockDiff, +})); + +vi.mock('../../utils/MarkdownDisplay.js', () => ({ + MarkdownDisplay: ({ text }: { text: string }) => {text}, +})); + +describe('ToolMessage Sticky Header Regression', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + const createToolCall = (id: string, name: string, resultPrefix: string) => ({ + callId: id, + name, + description: `Description for ${name}`, + resultDisplay: Array.from( + { length: 10 }, + (_, i) => `${resultPrefix}-${String(i + 1).padStart(2, '0')}`, + ).join('\n'), + status: ToolCallStatus.Success, + confirmationDetails: undefined, + renderOutputAsMarkdown: false, + }); + + it('verifies that multiple ToolMessages in a ToolGroupMessage in a ScrollableList have sticky headers', async () => { + const toolCalls = [ + createToolCall('1', 'tool-1', 'c1'), + createToolCall('2', 'tool-2', 'c2'), + ]; + + const terminalWidth = 80; + const terminalHeight = 5; + + let listRef: ScrollableListRef | null = null; + + const TestComponent = () => { + const internalRef = useRef>(null); + useEffect(() => { + listRef = internalRef.current; + }, []); + + return ( + ( + + )} + estimatedItemHeight={() => 30} + keyExtractor={(item) => item} + hasFocus={true} + /> + ); + }; + + const { lastFrame } = renderWithProviders( + + + , + { + width: terminalWidth, + uiState: { terminalWidth }, + }, + ); + + // Initial state: tool-1 should be visible + await waitFor(() => { + expect(lastFrame()).toContain('tool-1'); + }); + expect(lastFrame()).toContain('Description for tool-1'); + expect(lastFrame()).toMatchSnapshot(); + + // Scroll down so that tool-1's header should be stuck + await act(async () => { + listRef?.scrollBy(5); + }); + + // tool-1 header should still be visible because it is sticky + await waitFor(() => { + expect(lastFrame()).toContain('tool-1'); + }); + expect(lastFrame()).toContain('Description for tool-1'); + // Content lines 1-4 should be scrolled off + expect(lastFrame()).not.toContain('c1-01'); + expect(lastFrame()).not.toContain('c1-04'); + // Line 6 and 7 should be visible (terminalHeight=5 means only 2 lines of content show below 3-line header) + expect(lastFrame()).toContain('c1-06'); + expect(lastFrame()).toContain('c1-07'); + expect(lastFrame()).toMatchSnapshot(); + + // Scroll further so tool-1 is completely gone and tool-2's header should be stuck + await act(async () => { + listRef?.scrollBy(17); + }); + + await waitFor(() => { + expect(lastFrame()).toContain('tool-2'); + }); + expect(lastFrame()).toContain('Description for tool-2'); + // tool-1 should be gone now (both header and content) + expect(lastFrame()).not.toContain('tool-1'); + expect(lastFrame()).toMatchSnapshot(); + }); + + it('verifies that ShellToolMessage in a ToolGroupMessage in a ScrollableList has sticky headers', async () => { + const toolCalls = [ + { + ...createToolCall('1', SHELL_COMMAND_NAME, 'shell'), + status: ToolCallStatus.Success, + }, + ]; + + const terminalWidth = 80; + const terminalHeight = 5; + + let listRef: ScrollableListRef | null = null; + + const TestComponent = () => { + const internalRef = useRef>(null); + useEffect(() => { + listRef = internalRef.current; + }, []); + + return ( + ( + + )} + estimatedItemHeight={() => 30} + keyExtractor={(item) => item} + hasFocus={true} + /> + ); + }; + + const { lastFrame } = renderWithProviders( + + + , + { + width: terminalWidth, + uiState: { terminalWidth }, + }, + ); + + await waitFor(() => { + expect(lastFrame()).toContain(SHELL_COMMAND_NAME); + }); + expect(lastFrame()).toMatchSnapshot(); + + // Scroll down + await act(async () => { + listRef?.scrollBy(5); + }); + + await waitFor(() => { + expect(lastFrame()).toContain(SHELL_COMMAND_NAME); + }); + expect(lastFrame()).toContain('shell-06'); + expect(lastFrame()).toMatchSnapshot(); + }); +}); diff --git a/packages/cli/src/ui/components/messages/__snapshots__/ToolStickyHeaderRegression.test.tsx.snap b/packages/cli/src/ui/components/messages/__snapshots__/ToolStickyHeaderRegression.test.tsx.snap new file mode 100644 index 0000000000..9fa4d21ab9 --- /dev/null +++ b/packages/cli/src/ui/components/messages/__snapshots__/ToolStickyHeaderRegression.test.tsx.snap @@ -0,0 +1,41 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`ToolMessage Sticky Header Regression > verifies that ShellToolMessage in a ToolGroupMessage in a ScrollableList has sticky headers 1`] = ` +"╭────────────────────────────────────────────────────────────────────────────╮ █ +│ ✓ Shell Command Description for Shell Command │ █ +│ │ +│ shell-01 │ +│ shell-02 │" +`; + +exports[`ToolMessage Sticky Header Regression > verifies that ShellToolMessage in a ToolGroupMessage in a ScrollableList has sticky headers 2`] = ` +"╭────────────────────────────────────────────────────────────────────────────╮ +│ ✓ Shell Command Description for Shell Command │ ▄ +│────────────────────────────────────────────────────────────────────────────│ █ +│ shell-06 │ ▀ +│ shell-07 │" +`; + +exports[`ToolMessage Sticky Header Regression > verifies that multiple ToolMessages in a ToolGroupMessage in a ScrollableList have sticky headers 1`] = ` +"╭────────────────────────────────────────────────────────────────────────────╮ █ +│ ✓ tool-1 Description for tool-1 │ +│ │ +│ c1-01 │ +│ c1-02 │" +`; + +exports[`ToolMessage Sticky Header Regression > verifies that multiple ToolMessages in a ToolGroupMessage in a ScrollableList have sticky headers 2`] = ` +"╭────────────────────────────────────────────────────────────────────────────╮ +│ ✓ tool-1 Description for tool-1 │ █ +│────────────────────────────────────────────────────────────────────────────│ +│ c1-06 │ +│ c1-07 │" +`; + +exports[`ToolMessage Sticky Header Regression > verifies that multiple ToolMessages in a ToolGroupMessage in a ScrollableList have sticky headers 3`] = ` +"│ │ +│ ✓ tool-2 Description for tool-2 │ +│────────────────────────────────────────────────────────────────────────────│ +│ c2-10 │ +╰────────────────────────────────────────────────────────────────────────────╯ █" +`; From d66ec38f82909eb291788328cd16af6c6584fbd3 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Tue, 13 Jan 2026 14:31:34 -0800 Subject: [PATCH 163/713] feat(core): Align internal agent settings with configs exposed through settings.json (#16458) --- packages/core/src/agents/agentLoader.test.ts | 6 +- packages/core/src/agents/agentLoader.ts | 10 +- packages/core/src/agents/cli-help-agent.ts | 15 +- .../core/src/agents/codebase-investigator.ts | 15 +- .../src/agents/delegate-to-agent-tool.test.ts | 10 +- .../core/src/agents/local-executor.test.ts | 28 ++-- packages/core/src/agents/local-executor.ts | 14 +- .../core/src/agents/local-invocation.test.ts | 10 +- packages/core/src/agents/registry.test.ts | 29 ++-- packages/core/src/agents/registry.ts | 149 +++++++++--------- .../src/agents/subagent-tool-wrapper.test.ts | 10 +- packages/core/src/agents/types.ts | 15 +- 12 files changed, 176 insertions(+), 135 deletions(-) diff --git a/packages/core/src/agents/agentLoader.test.ts b/packages/core/src/agents/agentLoader.test.ts index 199d715fe9..088b233177 100644 --- a/packages/core/src/agents/agentLoader.test.ts +++ b/packages/core/src/agents/agentLoader.test.ts @@ -245,10 +245,12 @@ Body`); }, modelConfig: { model: 'inherit', - top_p: 0.95, + generateContentConfig: { + topP: 0.95, + }, }, runConfig: { - max_time_minutes: 5, + maxTimeMinutes: 5, }, inputConfig: { inputs: { diff --git a/packages/core/src/agents/agentLoader.ts b/packages/core/src/agents/agentLoader.ts index f8283c1933..b08979bbe4 100644 --- a/packages/core/src/agents/agentLoader.ts +++ b/packages/core/src/agents/agentLoader.ts @@ -281,12 +281,14 @@ export function markdownToAgentDefinition( }, modelConfig: { model: modelName, - temp: markdown.temperature ?? 1, - top_p: 0.95, + generateContentConfig: { + temperature: markdown.temperature ?? 1, + topP: 0.95, + }, }, runConfig: { - max_turns: markdown.max_turns, - max_time_minutes: markdown.timeout_mins || 5, + maxTurns: markdown.max_turns, + maxTimeMinutes: markdown.timeout_mins || 5, }, toolConfig: markdown.tools ? { diff --git a/packages/core/src/agents/cli-help-agent.ts b/packages/core/src/agents/cli-help-agent.ts index ea6709ca86..71a020f3a8 100644 --- a/packages/core/src/agents/cli-help-agent.ts +++ b/packages/core/src/agents/cli-help-agent.ts @@ -50,14 +50,19 @@ export const CliHelpAgent = ( modelConfig: { model: GEMINI_MODEL_ALIAS_FLASH, - temp: 0.1, - top_p: 0.95, - thinkingBudget: -1, + generateContentConfig: { + temperature: 0.1, + topP: 0.95, + thinkingConfig: { + includeThoughts: true, + thinkingBudget: -1, + }, + }, }, runConfig: { - max_time_minutes: 3, - max_turns: 10, + maxTimeMinutes: 3, + maxTurns: 10, }, toolConfig: { diff --git a/packages/core/src/agents/codebase-investigator.ts b/packages/core/src/agents/codebase-investigator.ts index ddff2e8500..7e0b7fd3cf 100644 --- a/packages/core/src/agents/codebase-investigator.ts +++ b/packages/core/src/agents/codebase-investigator.ts @@ -71,14 +71,19 @@ export const CodebaseInvestigatorAgent: LocalAgentDefinition< modelConfig: { model: DEFAULT_GEMINI_MODEL, - temp: 0.1, - top_p: 0.95, - thinkingBudget: -1, + generateContentConfig: { + temperature: 0.1, + topP: 0.95, + thinkingConfig: { + includeThoughts: true, + thinkingBudget: -1, + }, + }, }, runConfig: { - max_time_minutes: 5, - max_turns: 15, + maxTimeMinutes: 5, + maxTurns: 15, }, toolConfig: { diff --git a/packages/core/src/agents/delegate-to-agent-tool.test.ts b/packages/core/src/agents/delegate-to-agent-tool.test.ts index 65dcd2b2e0..b709c01911 100644 --- a/packages/core/src/agents/delegate-to-agent-tool.test.ts +++ b/packages/core/src/agents/delegate-to-agent-tool.test.ts @@ -50,14 +50,20 @@ describe('DelegateToAgentTool', () => { name: 'test_agent', description: 'A test agent', promptConfig: {}, - modelConfig: { model: 'test-model', temp: 0, top_p: 0 }, + modelConfig: { + model: 'test-model', + generateContentConfig: { + temperature: 0, + topP: 0, + }, + }, inputConfig: { inputs: { arg1: { type: 'string', description: 'Argument 1', required: true }, arg2: { type: 'number', description: 'Argument 2', required: false }, }, }, - runConfig: { max_turns: 1, max_time_minutes: 1 }, + runConfig: { maxTurns: 1, maxTimeMinutes: 1 }, toolConfig: { tools: [] }, }; diff --git a/packages/core/src/agents/local-executor.test.ts b/packages/core/src/agents/local-executor.test.ts index a0a8a513f2..c65442182c 100644 --- a/packages/core/src/agents/local-executor.test.ts +++ b/packages/core/src/agents/local-executor.test.ts @@ -225,8 +225,14 @@ const createTestDefinition = ( inputConfig: { inputs: { goal: { type: 'string', required: true, description: 'goal' } }, }, - modelConfig: { model: 'gemini-test-model', temp: 0, top_p: 1 }, - runConfig: { max_time_minutes: 5, max_turns: 5, ...runConfigOverrides }, + modelConfig: { + model: 'gemini-test-model', + generateContentConfig: { + temperature: 0, + topP: 1, + }, + }, + runConfig: { maxTimeMinutes: 5, maxTurns: 5, ...runConfigOverrides }, promptConfig: { systemPrompt: 'Achieve the goal: ${goal}.' }, toolConfig: { tools }, outputConfig, @@ -1321,7 +1327,7 @@ describe('LocalAgentExecutor', () => { it('should terminate when max_turns is reached', async () => { const MAX = 2; const definition = createTestDefinition([LS_TOOL_NAME], { - max_turns: MAX, + maxTurns: MAX, }); const executor = await LocalAgentExecutor.create(definition, mockConfig); @@ -1338,7 +1344,7 @@ describe('LocalAgentExecutor', () => { it('should terminate with TIMEOUT if a model call takes too long', async () => { const definition = createTestDefinition([LS_TOOL_NAME], { - max_time_minutes: 0.5, // 30 seconds + maxTimeMinutes: 0.5, // 30 seconds }); const executor = await LocalAgentExecutor.create( definition, @@ -1395,7 +1401,7 @@ describe('LocalAgentExecutor', () => { it('should terminate with TIMEOUT if a tool call takes too long', async () => { const definition = createTestDefinition([LS_TOOL_NAME], { - max_time_minutes: 1, + maxTimeMinutes: 1, }); const executor = await LocalAgentExecutor.create(definition, mockConfig); @@ -1483,7 +1489,7 @@ describe('LocalAgentExecutor', () => { it('should recover successfully if complete_task is called during the grace turn after MAX_TURNS', async () => { const MAX = 1; const definition = createTestDefinition([LS_TOOL_NAME], { - max_turns: MAX, + maxTurns: MAX, }); const executor = await LocalAgentExecutor.create( definition, @@ -1531,7 +1537,7 @@ describe('LocalAgentExecutor', () => { it('should fail if complete_task is NOT called during the grace turn after MAX_TURNS', async () => { const MAX = 1; const definition = createTestDefinition([LS_TOOL_NAME], { - max_turns: MAX, + maxTurns: MAX, }); const executor = await LocalAgentExecutor.create( definition, @@ -1650,7 +1656,7 @@ describe('LocalAgentExecutor', () => { it('should recover successfully from a TIMEOUT', async () => { const definition = createTestDefinition([LS_TOOL_NAME], { - max_time_minutes: 0.5, // 30 seconds + maxTimeMinutes: 0.5, // 30 seconds }); const executor = await LocalAgentExecutor.create( definition, @@ -1705,7 +1711,7 @@ describe('LocalAgentExecutor', () => { it('should fail recovery from a TIMEOUT if the grace period also times out', async () => { const definition = createTestDefinition([LS_TOOL_NAME], { - max_time_minutes: 0.5, // 30 seconds + maxTimeMinutes: 0.5, // 30 seconds }); const executor = await LocalAgentExecutor.create( definition, @@ -1797,7 +1803,7 @@ describe('LocalAgentExecutor', () => { it('should log a RecoveryAttemptEvent when a recoverable error occurs and recovery fails', async () => { const MAX = 1; const definition = createTestDefinition([LS_TOOL_NAME], { - max_turns: MAX, + maxTurns: MAX, }); const executor = await LocalAgentExecutor.create(definition, mockConfig); @@ -1822,7 +1828,7 @@ describe('LocalAgentExecutor', () => { it('should log a successful RecoveryAttemptEvent when recovery succeeds', async () => { const MAX = 1; const definition = createTestDefinition([LS_TOOL_NAME], { - max_turns: MAX, + maxTurns: MAX, }); const executor = await LocalAgentExecutor.create(definition, mockConfig); diff --git a/packages/core/src/agents/local-executor.ts b/packages/core/src/agents/local-executor.ts index fc866c97b5..fa5b4701c6 100644 --- a/packages/core/src/agents/local-executor.ts +++ b/packages/core/src/agents/local-executor.ts @@ -361,11 +361,11 @@ export class LocalAgentExecutor { let terminateReason: AgentTerminateMode = AgentTerminateMode.ERROR; let finalResult: string | null = null; - const { max_time_minutes } = this.definition.runConfig; + const { maxTimeMinutes } = this.definition.runConfig; const timeoutController = new AbortController(); const timeoutId = setTimeout( () => timeoutController.abort(new Error('Agent timed out.')), - max_time_minutes * 60 * 1000, + maxTimeMinutes * 60 * 1000, ); // Combine the external signal with the internal timeout signal. @@ -454,13 +454,13 @@ export class LocalAgentExecutor { } else { // Recovery Failed. Set the final error message based on the *original* reason. if (terminateReason === AgentTerminateMode.TIMEOUT) { - finalResult = `Agent timed out after ${this.definition.runConfig.max_time_minutes} minutes.`; + finalResult = `Agent timed out after ${this.definition.runConfig.maxTimeMinutes} minutes.`; this.emitActivity('ERROR', { error: finalResult, context: 'timeout', }); } else if (terminateReason === AgentTerminateMode.MAX_TURNS) { - finalResult = `Agent reached max turns limit (${this.definition.runConfig.max_turns}).`; + finalResult = `Agent reached max turns limit (${this.definition.runConfig.maxTurns}).`; this.emitActivity('ERROR', { error: finalResult, context: 'max_turns', @@ -524,7 +524,7 @@ export class LocalAgentExecutor { } // Recovery failed or wasn't possible - finalResult = `Agent timed out after ${this.definition.runConfig.max_time_minutes} minutes.`; + finalResult = `Agent timed out after ${this.definition.runConfig.maxTimeMinutes} minutes.`; this.emitActivity('ERROR', { error: finalResult, context: 'timeout', @@ -556,7 +556,7 @@ export class LocalAgentExecutor { chat: GeminiChat, prompt_id: string, ): Promise { - const model = this.definition.modelConfig.model; + const model = this.definition.modelConfig.model ?? DEFAULT_GEMINI_MODEL; const { newHistory, info } = await this.compressionService.compress( chat, @@ -1109,7 +1109,7 @@ Important Rules: ): AgentTerminateMode | null { const { runConfig } = this.definition; - if (runConfig.max_turns && turnCounter >= runConfig.max_turns) { + if (runConfig.maxTurns && turnCounter >= runConfig.maxTurns) { return AgentTerminateMode.MAX_TURNS; } diff --git a/packages/core/src/agents/local-invocation.test.ts b/packages/core/src/agents/local-invocation.test.ts index 91614cea04..62de4b4c02 100644 --- a/packages/core/src/agents/local-invocation.test.ts +++ b/packages/core/src/agents/local-invocation.test.ts @@ -33,8 +33,14 @@ const testDefinition: LocalAgentDefinition = { priority: { type: 'number', required: false, description: 'prio' }, }, }, - modelConfig: { model: 'test', temp: 0, top_p: 1 }, - runConfig: { max_time_minutes: 1 }, + modelConfig: { + model: 'test', + generateContentConfig: { + temperature: 0, + topP: 1, + }, + }, + runConfig: { maxTimeMinutes: 1 }, promptConfig: { systemPrompt: 'test' }, }; diff --git a/packages/core/src/agents/registry.test.ts b/packages/core/src/agents/registry.test.ts index 837d4c5f63..a81b3035bb 100644 --- a/packages/core/src/agents/registry.test.ts +++ b/packages/core/src/agents/registry.test.ts @@ -47,8 +47,18 @@ const MOCK_AGENT_V1: AgentDefinition = { name: 'MockAgent', description: 'Mock Description V1', inputConfig: { inputs: {} }, - modelConfig: { model: 'test', temp: 0, top_p: 1 }, - runConfig: { max_time_minutes: 1 }, + modelConfig: { + model: 'test', + generateContentConfig: { + temperature: 0, + topP: 1, + thinkingConfig: { + includeThoughts: true, + thinkingBudget: -1, + }, + }, + }, + runConfig: { maxTimeMinutes: 1 }, promptConfig: { systemPrompt: 'test' }, }; @@ -319,8 +329,8 @@ describe('AgentRegistry', () => { ).toStrictEqual({ model: 'auto', generateContentConfig: { - temperature: autoAgent.modelConfig.temp, - topP: autoAgent.modelConfig.top_p, + temperature: autoAgent.modelConfig.generateContentConfig?.temperature, + topP: autoAgent.modelConfig.generateContentConfig?.topP, thinkingConfig: { includeThoughts: true, thinkingBudget: -1, @@ -352,8 +362,9 @@ describe('AgentRegistry', () => { ).toStrictEqual({ model: MOCK_AGENT_V1.modelConfig.model, generateContentConfig: { - temperature: MOCK_AGENT_V1.modelConfig.temp, - topP: MOCK_AGENT_V1.modelConfig.top_p, + temperature: + MOCK_AGENT_V1.modelConfig.generateContentConfig?.temperature, + topP: MOCK_AGENT_V1.modelConfig.generateContentConfig?.topP, thinkingConfig: { includeThoughts: true, thinkingBudget: -1, @@ -674,9 +685,9 @@ describe('AgentRegistry', () => { await registry.testRegisterAgent(MOCK_AGENT_V1); const def = registry.getDefinition('MockAgent') as LocalAgentDefinition; - expect(def.runConfig.max_turns).toBe(50); - expect(def.runConfig.max_time_minutes).toBe( - MOCK_AGENT_V1.runConfig.max_time_minutes, + expect(def.runConfig.maxTurns).toBe(50); + expect(def.runConfig.maxTimeMinutes).toBe( + MOCK_AGENT_V1.runConfig.maxTimeMinutes, ); }); diff --git a/packages/core/src/agents/registry.ts b/packages/core/src/agents/registry.ts index 0038a2b783..49d425bd6e 100644 --- a/packages/core/src/agents/registry.ts +++ b/packages/core/src/agents/registry.ts @@ -6,8 +6,8 @@ import { Storage } from '../config/storage.js'; import { coreEvents, CoreEvent } from '../utils/events.js'; -import type { Config } from '../config/config.js'; -import type { AgentDefinition } from './types.js'; +import type { AgentOverride, Config } from '../config/config.js'; +import type { AgentDefinition, LocalAgentDefinition } from './types.js'; import { loadAgentsFromDirectory } from './agentLoader.js'; import { CodebaseInvestigatorAgent } from './codebase-investigator.js'; import { CliHelpAgent } from './cli-help-agent.js'; @@ -164,18 +164,26 @@ export class AgentRegistry { modelConfig: { ...CodebaseInvestigatorAgent.modelConfig, model, - thinkingBudget: - investigatorSettings.thinkingBudget ?? - CodebaseInvestigatorAgent.modelConfig.thinkingBudget, + generateContentConfig: { + ...CodebaseInvestigatorAgent.modelConfig.generateContentConfig, + thinkingConfig: { + ...CodebaseInvestigatorAgent.modelConfig.generateContentConfig + ?.thinkingConfig, + thinkingBudget: + investigatorSettings.thinkingBudget ?? + CodebaseInvestigatorAgent.modelConfig.generateContentConfig + ?.thinkingConfig?.thinkingBudget, + }, + }, }, runConfig: { ...CodebaseInvestigatorAgent.runConfig, - max_time_minutes: + maxTimeMinutes: investigatorSettings.maxTimeMinutes ?? - CodebaseInvestigatorAgent.runConfig.max_time_minutes, - max_turns: + CodebaseInvestigatorAgent.runConfig.maxTimeMinutes, + maxTurns: investigatorSettings.maxNumTurns ?? - CodebaseInvestigatorAgent.runConfig.max_turns, + CodebaseInvestigatorAgent.runConfig.maxTurns, }, }; this.registerLocalAgent(agentDef); @@ -229,9 +237,9 @@ export class AgentRegistry { return; } - const overrides = + const settingsOverrides = this.config.getAgentsSettings().overrides?.[definition.name]; - if (overrides?.disabled) { + if (settingsOverrides?.disabled) { if (this.config.getDebugMode()) { debugLogger.log( `[AgentRegistry] Skipping disabled agent '${definition.name}'`, @@ -244,71 +252,10 @@ export class AgentRegistry { debugLogger.log(`[AgentRegistry] Overriding agent '${definition.name}'`); } - // TODO(16443): Refactor definition merging logic into a helper. - // To do this, we need to align the definition of the internal `Definition` - // type with the one exported in settings.json. - const mergedDefinition = { - ...definition, - runConfig: { - ...definition.runConfig, - max_time_minutes: - overrides?.runConfig?.maxTimeMinutes ?? - definition.runConfig.max_time_minutes, - max_turns: - overrides?.runConfig?.maxTurns ?? definition.runConfig.max_turns, - }, - }; - + const mergedDefinition = this.applyOverrides(definition, settingsOverrides); this.agents.set(mergedDefinition.name, mergedDefinition); - // Register model config. We always create a runtime alias. However, - // if the user is using `auto` as a model string then we also create - // runtime overrides to ensure the subagent generation settings are - // respected regardless of the final model string from routing. - // TODO(12916): Migrate sub-agents where possible to static configs. - const modelConfig = mergedDefinition.modelConfig; - let model = modelConfig.model; - if (model === 'inherit') { - model = this.config.getModel(); - } - - let agentModelConfig: ModelConfig = { - model, - generateContentConfig: { - temperature: modelConfig.temp, - topP: modelConfig.top_p, - thinkingConfig: { - includeThoughts: true, - thinkingBudget: modelConfig.thinkingBudget ?? -1, - }, - }, - }; - - // Apply standardized modelConfig overrides if present. - if (overrides?.modelConfig) { - agentModelConfig = ModelConfigService.merge( - agentModelConfig, - overrides.modelConfig, - ); - } - - this.config.modelConfigService.registerRuntimeModelConfig( - getModelConfigAlias(mergedDefinition), - { - modelConfig: agentModelConfig, - }, - ); - - if (agentModelConfig.model && isAutoModel(agentModelConfig.model)) { - this.config.modelConfigService.registerRuntimeModelOverride({ - match: { - overrideScope: mergedDefinition.name, - }, - modelConfig: { - generateContentConfig: agentModelConfig.generateContentConfig, - }, - }); - } + this.registerModelConfigs(mergedDefinition); } /** @@ -376,6 +323,60 @@ export class AgentRegistry { } } + private applyOverrides( + definition: LocalAgentDefinition, + overrides?: AgentOverride, + ): LocalAgentDefinition { + if (definition.kind !== 'local' || !overrides) { + return definition; + } + + return { + ...definition, + runConfig: { + ...definition.runConfig, + ...overrides.runConfig, + }, + modelConfig: ModelConfigService.merge( + definition.modelConfig, + overrides.modelConfig ?? {}, + ), + }; + } + + private registerModelConfigs( + definition: LocalAgentDefinition, + ): void { + const modelConfig = definition.modelConfig; + let model = modelConfig.model; + if (model === 'inherit') { + model = this.config.getModel(); + } + + const agentModelConfig: ModelConfig = { + ...modelConfig, + model, + }; + + this.config.modelConfigService.registerRuntimeModelConfig( + getModelConfigAlias(definition), + { + modelConfig: agentModelConfig, + }, + ); + + if (agentModelConfig.model && isAutoModel(agentModelConfig.model)) { + this.config.modelConfigService.registerRuntimeModelOverride({ + match: { + overrideScope: definition.name, + }, + modelConfig: { + generateContentConfig: agentModelConfig.generateContentConfig, + }, + }); + } + } + /** * Retrieves an agent definition by name. */ diff --git a/packages/core/src/agents/subagent-tool-wrapper.test.ts b/packages/core/src/agents/subagent-tool-wrapper.test.ts index 29a241f32e..c45b085991 100644 --- a/packages/core/src/agents/subagent-tool-wrapper.test.ts +++ b/packages/core/src/agents/subagent-tool-wrapper.test.ts @@ -43,8 +43,14 @@ const mockDefinition: LocalAgentDefinition = { }, }, }, - modelConfig: { model: 'gemini-test-model', temp: 0, top_p: 1 }, - runConfig: { max_time_minutes: 5 }, + modelConfig: { + model: 'gemini-test-model', + generateContentConfig: { + temperature: 0, + topP: 1, + }, + }, + runConfig: { maxTimeMinutes: 5 }, promptConfig: { systemPrompt: 'You are a test agent.' }, }; diff --git a/packages/core/src/agents/types.ts b/packages/core/src/agents/types.ts index f0d2743662..23c6f75626 100644 --- a/packages/core/src/agents/types.ts +++ b/packages/core/src/agents/types.ts @@ -11,6 +11,7 @@ import type { Content, FunctionDeclaration } from '@google/genai'; import type { AnyDeclarativeTool } from '../tools/tools.js'; import { type z } from 'zod'; +import type { ModelConfig } from '../services/modelConfigService.js'; /** * Describes the possible termination modes for an agent. @@ -177,22 +178,12 @@ export interface OutputConfig { schema: T; } -/** - * Configures the generative model parameters for the agent. - */ -export interface ModelConfig { - model: string; - temp: number; - top_p: number; - thinkingBudget?: number; -} - /** * Configures the execution environment and constraints for the agent. */ export interface RunConfig { /** The maximum execution time for the agent in minutes. */ - max_time_minutes: number; + maxTimeMinutes: number; /** The maximum number of conversational turns. */ - max_turns?: number; + maxTurns?: number; } From c7c409c68fba8990af9452fcb32f6d5de35eb578 Mon Sep 17 00:00:00 2001 From: Sercan Sagman Date: Wed, 14 Jan 2026 01:55:28 +0300 Subject: [PATCH 164/713] fix(cli): copy uses OSC52 only in SSH/WSL (#16554) Signed-off-by: assagman --- docs/cli/commands.md | 3 +++ .../cli/src/ui/utils/commandUtils.test.ts | 21 +++++++++++++++++-- packages/cli/src/ui/utils/commandUtils.ts | 4 +--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/cli/commands.md b/docs/cli/commands.md index 979ca59dfc..da29410533 100644 --- a/docs/cli/commands.md +++ b/docs/cli/commands.md @@ -73,6 +73,9 @@ Slash commands provide meta-level control over the CLI itself. - **`/copy`** - **Description:** Copies the last output produced by Gemini CLI to your clipboard, for easy sharing or reuse. + - **Behavior:** + - Local sessions use system clipboard tools (pbcopy/xclip/clip). + - Remote sessions (SSH/WSL) use OSC 52 and require terminal support. - **Note:** This command requires platform-specific clipboard tools to be installed. - On Linux, it requires `xclip` or `xsel`. You can typically install them diff --git a/packages/cli/src/ui/utils/commandUtils.test.ts b/packages/cli/src/ui/utils/commandUtils.test.ts index 7a2e62a947..ba5aeaab35 100644 --- a/packages/cli/src/ui/utils/commandUtils.test.ts +++ b/packages/cli/src/ui/utils/commandUtils.test.ts @@ -239,11 +239,12 @@ describe('commandUtils', () => { expect(mockClipboardyWrite).not.toHaveBeenCalled(); }); - it('wraps OSC-52 for tmux', async () => { + it('wraps OSC-52 for tmux when in SSH', async () => { const testText = 'tmux-copy'; const tty = makeWritable({ isTTY: true }); mockFs.createWriteStream.mockReturnValue(tty); + process.env['SSH_CONNECTION'] = '1'; process.env['TMUX'] = '1'; await copyToClipboard(testText); @@ -257,12 +258,13 @@ describe('commandUtils', () => { expect(mockClipboardyWrite).not.toHaveBeenCalled(); }); - it('wraps OSC-52 for GNU screen with chunked DCS', async () => { + it('wraps OSC-52 for GNU screen with chunked DCS when in SSH', async () => { // ensure payload > chunk size (240) so there are multiple chunks const testText = 'x'.repeat(1200); const tty = makeWritable({ isTTY: true }); mockFs.createWriteStream.mockReturnValue(tty); + process.env['SSH_CONNECTION'] = '1'; process.env['STY'] = 'screen-session'; await copyToClipboard(testText); @@ -358,6 +360,21 @@ describe('commandUtils', () => { expect(tty.end).not.toHaveBeenCalled(); }); + it('uses clipboardy in tmux when not in SSH/WSL', async () => { + const tty = makeWritable({ isTTY: true }); + mockFs.createWriteStream.mockReturnValue(tty); + const text = 'tmux-local'; + mockClipboardyWrite.mockResolvedValue(undefined); + + process.env['TMUX'] = '1'; + + await copyToClipboard(text); + + expect(mockClipboardyWrite).toHaveBeenCalledWith(text); + expect(tty.write).not.toHaveBeenCalled(); + expect(tty.end).not.toHaveBeenCalled(); + }); + it('skips /dev/tty on Windows and uses stderr fallback for OSC-52', async () => { mockProcess.platform = 'win32'; const stderrStream = makeWritable({ isTTY: true }); diff --git a/packages/cli/src/ui/utils/commandUtils.ts b/packages/cli/src/ui/utils/commandUtils.ts index c1bd755221..87a873cb64 100644 --- a/packages/cli/src/ui/utils/commandUtils.ts +++ b/packages/cli/src/ui/utils/commandUtils.ts @@ -113,9 +113,7 @@ const isWSL = (): boolean => const isDumbTerm = (): boolean => (process.env['TERM'] ?? '') === 'dumb'; const shouldUseOsc52 = (tty: TtyTarget): boolean => - Boolean(tty) && - !isDumbTerm() && - (isSSH() || inTmux() || inScreen() || isWSL()); + Boolean(tty) && !isDumbTerm() && (isSSH() || isWSL()); const safeUtf8Truncate = (buf: Buffer, maxBytes: number): Buffer => { if (buf.length <= maxBytes) return buf; From 778de55fd8c312b9e8a5cc39cc8d666ff043f21b Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 13 Jan 2026 16:03:45 -0800 Subject: [PATCH 165/713] docs(skills): clarify skill directory structure and file location (#16532) --- docs/cli/skills.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/cli/skills.md b/docs/cli/skills.md index f7ddf003df..5aebf00cb5 100644 --- a/docs/cli/skills.md +++ b/docs/cli/skills.md @@ -98,7 +98,20 @@ gemini skills disable my-expertise --scope project A skill is a directory containing a `SKILL.md` file at its root. This file uses YAML frontmatter for metadata and Markdown for instructions. -### Basic Structure +### Folder Structure + +Skills are self-contained directories. At a minimum, a skill requires a +`SKILL.md` file, but can include other resources: + +```text +my-skill/ +├── SKILL.md (Required) Instructions and metadata +├── scripts/ (Optional) Executable scripts/tools +├── references/ (Optional) Static documentation and examples +└── assets/ (Optional) Templates and binary resources +``` + +### Basic Structure (SKILL.md) ```markdown --- @@ -117,6 +130,8 @@ description: ### Example: Team Code Reviewer +Create `~/.gemini/skills/code-reviewer/SKILL.md`: + ```markdown --- name: code-reviewer From 8dbaa2bceaf947b293868ad5ed9244fa872ab31f Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Tue, 13 Jan 2026 16:55:07 -0800 Subject: [PATCH 166/713] Fix: make ctrl+x use preferred editor (#16556) --- packages/cli/src/ui/AppContainer.tsx | 11 +- .../src/ui/components/shared/text-buffer.ts | 111 ++++++++++-------- packages/core/src/utils/editor.ts | 17 ++- 3 files changed, 81 insertions(+), 58 deletions(-) diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index 4f3c9617a8..8e05ac1fd7 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -391,6 +391,11 @@ export const AppContainer = (props: AppContainerProps) => { } }, []); + const getPreferredEditor = useCallback( + () => settings.merged.general?.preferredEditor as EditorType, + [settings.merged.general?.preferredEditor], + ); + const buffer = useTextBuffer({ initialText: '', viewport: { height: 10, width: inputWidth }, @@ -398,6 +403,7 @@ export const AppContainer = (props: AppContainerProps) => { setRawMode, isValidPath, shellModeActive, + getPreferredEditor, }); // Initialize input history from logger (past sessions) @@ -758,11 +764,6 @@ Logging in with Google... Restarting Gemini CLI to continue. () => {}, ); - const getPreferredEditor = useCallback( - () => settings.merged.general?.preferredEditor as EditorType, - [settings.merged.general?.preferredEditor], - ); - const onCancelSubmit = useCallback((shouldRestorePrompt?: boolean) => { if (shouldRestorePrompt) { setPendingRestorePrompt(true); diff --git a/packages/cli/src/ui/components/shared/text-buffer.ts b/packages/cli/src/ui/components/shared/text-buffer.ts index cdf689c24f..26c1ddca80 100644 --- a/packages/cli/src/ui/components/shared/text-buffer.ts +++ b/packages/cli/src/ui/components/shared/text-buffer.ts @@ -15,6 +15,9 @@ import { CoreEvent, debugLogger, unescapePath, + type EditorType, + getEditorCommand, + isGuiEditor, } from '@google/gemini-cli-core'; import { toCodePoints, @@ -566,6 +569,7 @@ interface UseTextBufferProps { shellModeActive?: boolean; // Whether the text buffer is in shell mode inputFilter?: (text: string) => string; // Optional filter for input text singleLine?: boolean; + getPreferredEditor?: () => EditorType | undefined; } interface UndoHistoryEntry { @@ -1826,6 +1830,7 @@ export function useTextBuffer({ shellModeActive = false, inputFilter, singleLine = false, + getPreferredEditor, }: UseTextBufferProps): TextBuffer { const initialState = useMemo((): TextBufferState => { const lines = initialText.split('\n'); @@ -2152,55 +2157,67 @@ export function useTextBuffer({ dispatch({ type: 'vim_escape_insert_mode' }); }, []); - const openInExternalEditor = useCallback( - async (opts: { editor?: string } = {}): Promise => { - const editor = - opts.editor ?? - process.env['VISUAL'] ?? - process.env['EDITOR'] ?? - (process.platform === 'win32' ? 'notepad' : 'vi'); - const tmpDir = fs.mkdtempSync(pathMod.join(os.tmpdir(), 'gemini-edit-')); - const filePath = pathMod.join(tmpDir, 'buffer.txt'); - fs.writeFileSync(filePath, text, 'utf8'); + const openInExternalEditor = useCallback(async (): Promise => { + const tmpDir = fs.mkdtempSync(pathMod.join(os.tmpdir(), 'gemini-edit-')); + const filePath = pathMod.join(tmpDir, 'buffer.txt'); + fs.writeFileSync(filePath, text, 'utf8'); - dispatch({ type: 'create_undo_snapshot' }); + let command: string | undefined = undefined; + const args = [filePath]; - const wasRaw = stdin?.isRaw ?? false; - try { - setRawMode?.(false); - const { status, error } = spawnSync(editor, [filePath], { - stdio: 'inherit', - }); - if (error) throw error; - if (typeof status === 'number' && status !== 0) - throw new Error(`External editor exited with status ${status}`); - - let newText = fs.readFileSync(filePath, 'utf8'); - newText = newText.replace(/\r\n?/g, '\n'); - dispatch({ type: 'set_text', payload: newText, pushToUndo: false }); - } catch (err) { - coreEvents.emitFeedback( - 'error', - '[useTextBuffer] external editor error', - err, - ); - } finally { - coreEvents.emit(CoreEvent.ExternalEditorClosed); - if (wasRaw) setRawMode?.(true); - try { - fs.unlinkSync(filePath); - } catch { - /* ignore */ - } - try { - fs.rmdirSync(tmpDir); - } catch { - /* ignore */ - } + const preferredEditorType = getPreferredEditor?.(); + if (!command && preferredEditorType) { + command = getEditorCommand(preferredEditorType); + if (isGuiEditor(preferredEditorType)) { + args.unshift('--wait'); } - }, - [text, stdin, setRawMode], - ); + } + + if (!command) { + command = + (process.env['VISUAL'] ?? + process.env['EDITOR'] ?? + process.platform === 'win32') + ? 'notepad' + : 'vi'; + } + + dispatch({ type: 'create_undo_snapshot' }); + + const wasRaw = stdin?.isRaw ?? false; + try { + setRawMode?.(false); + const { status, error } = spawnSync(command, args, { + stdio: 'inherit', + }); + if (error) throw error; + if (typeof status === 'number' && status !== 0) + throw new Error(`External editor exited with status ${status}`); + + let newText = fs.readFileSync(filePath, 'utf8'); + newText = newText.replace(/\r\n?/g, '\n'); + dispatch({ type: 'set_text', payload: newText, pushToUndo: false }); + } catch (err) { + coreEvents.emitFeedback( + 'error', + '[useTextBuffer] external editor error', + err, + ); + } finally { + coreEvents.emit(CoreEvent.ExternalEditorClosed); + if (wasRaw) setRawMode?.(true); + try { + fs.unlinkSync(filePath); + } catch { + /* ignore */ + } + try { + fs.rmdirSync(tmpDir); + } catch { + /* ignore */ + } + } + }, [text, stdin, setRawMode, getPreferredEditor]); const handleInput = useCallback( (key: Key): void => { @@ -2616,7 +2633,7 @@ export interface TextBuffer { * continuing. This mirrors Git's behaviour and simplifies downstream * control‑flow (callers can simply `await` the Promise). */ - openInExternalEditor: (opts?: { editor?: string }) => Promise; + openInExternalEditor: () => Promise; replaceRangeByOffset: ( startOffset: number, diff --git a/packages/core/src/utils/editor.ts b/packages/core/src/utils/editor.ts index 742d1157fb..e48a055d40 100644 --- a/packages/core/src/utils/editor.ts +++ b/packages/core/src/utils/editor.ts @@ -112,6 +112,16 @@ export function checkHasEditorType(editor: EditorType): boolean { return commands.some((cmd) => commandExists(cmd)); } +export function getEditorCommand(editor: EditorType): string { + const commandConfig = editorCommands[editor]; + const commands = + process.platform === 'win32' ? commandConfig.win32 : commandConfig.default; + return ( + commands.slice(0, -1).find((cmd) => commandExists(cmd)) || + commands[commands.length - 1] + ); +} + export function allowEditorTypeInSandbox(editor: EditorType): boolean { const notUsingSandbox = !process.env['SANDBOX']; if (isGuiEditor(editor)) { @@ -143,12 +153,7 @@ export function getDiffCommand( if (!isValidEditorType(editor)) { return null; } - const commandConfig = editorCommands[editor]; - const commands = - process.platform === 'win32' ? commandConfig.win32 : commandConfig.default; - const command = - commands.slice(0, -1).find((cmd) => commandExists(cmd)) || - commands[commands.length - 1]; + const command = getEditorCommand(editor); switch (editor) { case 'vscode': From eda47f587cfd18d98b28ae3f0773718c3f4b067f Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Tue, 13 Jan 2026 20:37:10 -0500 Subject: [PATCH 167/713] fix(core): Resolve race condition in tool response reporting (#16557) --- .../core/src/core/coreToolScheduler.test.ts | 171 ++++++++++++++++++ packages/core/src/core/coreToolScheduler.ts | 29 ++- 2 files changed, 193 insertions(+), 7 deletions(-) diff --git a/packages/core/src/core/coreToolScheduler.test.ts b/packages/core/src/core/coreToolScheduler.test.ts index f3a35319e9..c27e194cc6 100644 --- a/packages/core/src/core/coreToolScheduler.test.ts +++ b/packages/core/src/core/coreToolScheduler.test.ts @@ -1904,4 +1904,175 @@ describe('CoreToolScheduler Sequential Execution', () => { serverName, ); }); + + it('should not double-report completed tools when concurrent completions occur', async () => { + // Arrange + const executeFn = vi.fn().mockResolvedValue({ llmContent: 'success' }); + const mockTool = new MockTool({ name: 'mockTool', execute: executeFn }); + const declarativeTool = mockTool; + + const mockToolRegistry = { + getTool: () => declarativeTool, + getToolByName: () => declarativeTool, + getFunctionDeclarations: () => [], + tools: new Map(), + discovery: {}, + registerTool: () => {}, + getToolByDisplayName: () => declarativeTool, + getTools: () => [], + discoverTools: async () => {}, + getAllTools: () => [], + getToolsByServer: () => [], + } as unknown as ToolRegistry; + + let completionCallCount = 0; + const onAllToolCallsComplete = vi.fn().mockImplementation(async () => { + completionCallCount++; + // Simulate slow reporting (e.g. Gemini API call) + await new Promise((resolve) => setTimeout(resolve, 50)); + }); + + const mockConfig = createMockConfig({ + getToolRegistry: () => mockToolRegistry, + getApprovalMode: () => ApprovalMode.YOLO, + isInteractive: () => false, + }); + const mockMessageBus = createMockMessageBus(); + mockConfig.getMessageBus = vi.fn().mockReturnValue(mockMessageBus); + mockConfig.getEnableHooks = vi.fn().mockReturnValue(false); + mockConfig.getHookSystem = vi + .fn() + .mockReturnValue(new HookSystem(mockConfig)); + + const scheduler = new CoreToolScheduler({ + config: mockConfig, + onAllToolCallsComplete, + getPreferredEditor: () => 'vscode', + }); + + const abortController = new AbortController(); + const request = { + callId: '1', + name: 'mockTool', + args: {}, + isClientInitiated: false, + prompt_id: 'prompt-1', + }; + + // Act + // 1. Start execution + const schedulePromise = scheduler.schedule( + [request], + abortController.signal, + ); + + // 2. Wait just enough for it to finish and enter checkAndNotifyCompletion + // (awaiting our slow mock) + await vi.waitFor(() => { + expect(completionCallCount).toBe(1); + }); + + // 3. Trigger a concurrent completion event (e.g. via cancelAll) + scheduler.cancelAll(abortController.signal); + + await schedulePromise; + + // Assert + // Even though cancelAll was called while the first completion was in progress, + // it should not have triggered a SECOND completion call because the first one + // was still 'finalizing' and will drain any new tools. + expect(onAllToolCallsComplete).toHaveBeenCalledTimes(1); + }); + + it('should complete reporting all tools even mid-callback during abort', async () => { + // Arrange + const onAllToolCallsComplete = vi.fn().mockImplementation(async () => { + // Simulate slow reporting + await new Promise((resolve) => setTimeout(resolve, 50)); + }); + + const mockTool = new MockTool({ name: 'mockTool' }); + const mockToolRegistry = { + getTool: () => mockTool, + getToolByName: () => mockTool, + getFunctionDeclarations: () => [], + tools: new Map(), + discovery: {}, + registerTool: () => {}, + getToolByDisplayName: () => mockTool, + getTools: () => [], + discoverTools: async () => {}, + getAllTools: () => [], + getToolsByServer: () => [], + } as unknown as ToolRegistry; + + const mockConfig = createMockConfig({ + getToolRegistry: () => mockToolRegistry, + getApprovalMode: () => ApprovalMode.YOLO, + isInteractive: () => false, + }); + + const scheduler = new CoreToolScheduler({ + config: mockConfig, + onAllToolCallsComplete, + getPreferredEditor: () => 'vscode', + }); + + const abortController = new AbortController(); + const signal = abortController.signal; + + // Act + // 1. Start execution of two tools + const schedulePromise = scheduler.schedule( + [ + { + callId: '1', + name: 'mockTool', + args: {}, + isClientInitiated: false, + prompt_id: 'prompt-1', + }, + { + callId: '2', + name: 'mockTool', + args: {}, + isClientInitiated: false, + prompt_id: 'prompt-1', + }, + ], + signal, + ); + + // 2. Wait for reporting to start + await vi.waitFor(() => { + expect(onAllToolCallsComplete).toHaveBeenCalled(); + }); + + // 3. Abort the signal while reporting is in progress + abortController.abort(); + + await schedulePromise; + + // Assert + // Verify that onAllToolCallsComplete was called and processed the tools, + // and that the scheduler didn't just drop them because of the abort. + expect(onAllToolCallsComplete).toHaveBeenCalled(); + + const reportedTools = onAllToolCallsComplete.mock.calls.flatMap((call) => + // eslint-disable-next-line @typescript-eslint/no-explicit-any + call[0].map((t: any) => t.request.callId), + ); + + // Both tools should have been reported exactly once with success status + expect(reportedTools).toContain('1'); + expect(reportedTools).toContain('2'); + + const allStatuses = onAllToolCallsComplete.mock.calls.flatMap((call) => + // eslint-disable-next-line @typescript-eslint/no-explicit-any + call[0].map((t: any) => t.status), + ); + expect(allStatuses).toEqual(['success', 'success']); + + expect(onAllToolCallsComplete).toHaveBeenCalledTimes(1); + }); }); diff --git a/packages/core/src/core/coreToolScheduler.ts b/packages/core/src/core/coreToolScheduler.ts index 9b2b08c47f..0d4ad1b938 100644 --- a/packages/core/src/core/coreToolScheduler.ts +++ b/packages/core/src/core/coreToolScheduler.ts @@ -909,21 +909,36 @@ export class CoreToolScheduler { this._cancelAllQueuedCalls(); } + // If we are already finalizing, another concurrent call to + // checkAndNotifyCompletion will just return. The ongoing finalized loop + // will pick up any new tools added to completedToolCallsForBatch. + if (this.isFinalizingToolCalls) { + return; + } + // If there's nothing to report and we weren't cancelled, we can stop. // But if we were cancelled, we must proceed to potentially start the next queued request. if (this.completedToolCallsForBatch.length === 0 && !signal.aborted) { return; } - if (this.onAllToolCallsComplete) { - this.isFinalizingToolCalls = true; - // Use the batch array, not the (now empty) active array. - await this.onAllToolCallsComplete(this.completedToolCallsForBatch); - this.completedToolCallsForBatch = []; // Clear after reporting. + this.isFinalizingToolCalls = true; + try { + // We use a while loop here to ensure that if new tools are added to the + // batch (e.g., via cancellation) while we are awaiting + // onAllToolCallsComplete, they are also reported before we finish. + while (this.completedToolCallsForBatch.length > 0) { + const batchToReport = [...this.completedToolCallsForBatch]; + this.completedToolCallsForBatch = []; + if (this.onAllToolCallsComplete) { + await this.onAllToolCallsComplete(batchToReport); + } + } + } finally { this.isFinalizingToolCalls = false; + this.isCancelling = false; + this.notifyToolCallsUpdate(); } - this.isCancelling = false; - this.notifyToolCallsUpdate(); // After completion of the entire batch, process the next item in the main request queue. if (this.requestQueue.length > 0) { From 04f65d7b4eff956124f1cc41b09cd62c04764af3 Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Tue, 13 Jan 2026 20:52:42 -0500 Subject: [PATCH 168/713] feat(ui): highlight persist mode status in ModelDialog (#16483) --- packages/cli/src/ui/components/ModelDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/ui/components/ModelDialog.tsx b/packages/cli/src/ui/components/ModelDialog.tsx index d1c12af8ce..f0a27b7cf7 100644 --- a/packages/cli/src/ui/components/ModelDialog.tsx +++ b/packages/cli/src/ui/components/ModelDialog.tsx @@ -221,7 +221,7 @@ export function ModelDialog({ onClose }: ModelDialogProps): React.JSX.Element { Remember model for future sessions:{' '} - + {persistMode ? 'true' : 'false'} From 428e6028822b73b492d514f14a6cbc2fd8647b42 Mon Sep 17 00:00:00 2001 From: Adam Weidman <65992621+adamfweidman@users.noreply.github.com> Date: Tue, 13 Jan 2026 20:58:55 -0500 Subject: [PATCH 169/713] refactor: clean up A2A task output for users and LLMs (#16561) --- packages/core/src/agents/a2aUtils.test.ts | 18 +++--- packages/core/src/agents/a2aUtils.ts | 55 ++++++++++--------- packages/core/src/agents/remote-invocation.ts | 18 +++--- 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/packages/core/src/agents/a2aUtils.test.ts b/packages/core/src/agents/a2aUtils.test.ts index 0527b54bdd..dcb911f2c0 100644 --- a/packages/core/src/agents/a2aUtils.test.ts +++ b/packages/core/src/agents/a2aUtils.test.ts @@ -124,7 +124,7 @@ describe('a2aUtils', () => { }); describe('extractTaskText', () => { - it('should extract basic task info', () => { + it('should extract basic task info (clean)', () => { const task: Task = { id: 'task-1', contextId: 'ctx-1', @@ -141,12 +141,12 @@ describe('a2aUtils', () => { }; const result = extractTaskText(task); - expect(result).toContain('ID: task-1'); - expect(result).toContain('State: working'); - expect(result).toContain('Status Message: Processing...'); + expect(result).not.toContain('ID: task-1'); + expect(result).not.toContain('State: working'); + expect(result).toBe('Processing...'); }); - it('should extract artifacts', () => { + it('should extract artifacts with headers', () => { const task: Task = { id: 'task-1', contextId: 'ctx-1', @@ -162,10 +162,10 @@ describe('a2aUtils', () => { }; const result = extractTaskText(task); - expect(result).toContain('Artifacts:'); - expect(result).toContain(' - Name: Report'); - expect(result).toContain(' Content:'); - expect(result).toContain(' This is the report.'); + expect(result).toContain('Artifact (Report):'); + expect(result).toContain('This is the report.'); + expect(result).not.toContain('Artifacts:'); + expect(result).not.toContain(' - Name: Report'); }); }); }); diff --git a/packages/core/src/agents/a2aUtils.ts b/packages/core/src/agents/a2aUtils.ts index fc19eceb05..311658118b 100644 --- a/packages/core/src/agents/a2aUtils.ts +++ b/packages/core/src/agents/a2aUtils.ts @@ -18,14 +18,11 @@ import type { * Handles Text, Data (JSON), and File parts. */ export function extractMessageText(message: Message | undefined): string { - if (!message || !message.parts) { + if (!message) { return ''; } - const parts = message.parts - .map((part) => extractPartText(part)) - .filter(Boolean); - return parts.join('\n'); + return extractPartsText(message.parts); } /** @@ -56,41 +53,47 @@ export function extractPartText(part: Part): string { } /** - * Extracts a human-readable text summary from a Task object. - * Includes status, ID, and any artifact content. + * Extracts a clean, human-readable text summary from a Task object. + * Includes the status message and any artifact content with context headers. + * Technical metadata like ID and State are omitted for better clarity and token efficiency. */ export function extractTaskText(task: Task): string { - let output = `ID: ${task.id}\n`; - output += `State: ${task.status.state}\n`; + const parts: string[] = []; // Status Message - const statusMessageText = extractMessageText(task.status.message); + const statusMessageText = extractMessageText(task.status?.message); if (statusMessageText) { - output += `Status Message: ${statusMessageText}\n`; + parts.push(statusMessageText); } // Artifacts - if (task.artifacts && task.artifacts.length > 0) { - output += `Artifacts:\n`; + if (task.artifacts) { for (const artifact of task.artifacts) { - output += ` - Name: ${artifact.name}\n`; - if (artifact.parts && artifact.parts.length > 0) { - // Treat artifact parts as a message for extraction - const artifactContent = artifact.parts - .map((p) => extractPartText(p)) - .filter(Boolean) - .join('\n'); + const artifactContent = extractPartsText(artifact.parts); - if (artifactContent) { - // Indent content for readability - const indentedContent = artifactContent.replace(/^/gm, ' '); - output += ` Content:\n${indentedContent}\n`; - } + if (artifactContent) { + const header = artifact.name + ? `Artifact (${artifact.name}):` + : 'Artifact:'; + parts.push(`${header}\n${artifactContent}`); } } } - return output; + return parts.join('\n\n'); +} + +/** + * Extracts text from an array of parts. + */ +function extractPartsText(parts: Part[] | undefined): string { + if (!parts || parts.length === 0) { + return ''; + } + return parts + .map((p) => extractPartText(p)) + .filter(Boolean) + .join('\n'); } // Type Guards diff --git a/packages/core/src/agents/remote-invocation.ts b/packages/core/src/agents/remote-invocation.ts index 9acb7794ea..a5894c37b4 100644 --- a/packages/core/src/agents/remote-invocation.ts +++ b/packages/core/src/agents/remote-invocation.ts @@ -166,16 +166,16 @@ export class RemoteAgentInvocation extends BaseToolInvocation< }); // Extract the output text - const resultData = response; - let outputText = ''; + const outputText = + response.kind === 'task' + ? extractTaskText(response) + : response.kind === 'message' + ? extractMessageText(response) + : JSON.stringify(response); - if (resultData.kind === 'message') { - outputText = extractMessageText(resultData); - } else if (resultData.kind === 'task') { - outputText = extractTaskText(resultData); - } else { - outputText = JSON.stringify(resultData); - } + debugLogger.debug( + `[RemoteAgent] Response from ${this.definition.name}:\n${JSON.stringify(response, null, 2)}`, + ); return { llmContent: [{ text: outputText }], From 4afd3741df7c3322f7bce276876682d320fa7ae2 Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Tue, 13 Jan 2026 23:03:19 -0500 Subject: [PATCH 170/713] feat(core/ui): enhance retry mechanism and UX (#16489) --- packages/cli/src/ui/AppContainer.tsx | 2 + .../cli/src/ui/hooks/useGeminiStream.test.tsx | 62 +++++++++++++++++++ packages/cli/src/ui/hooks/useGeminiStream.ts | 48 ++++++++++---- .../src/ui/hooks/useLoadingIndicator.test.tsx | 26 ++++++++ .../cli/src/ui/hooks/useLoadingIndicator.ts | 13 +++- packages/core/src/core/geminiChat.ts | 17 +++++ packages/core/src/utils/events.ts | 20 ++++++ packages/core/src/utils/retry.test.ts | 22 +++---- packages/core/src/utils/retry.ts | 16 ++++- 9 files changed, 200 insertions(+), 26 deletions(-) diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index 8e05ac1fd7..10f5a54a1c 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -802,6 +802,7 @@ Logging in with Google... Restarting Gemini CLI to continue. activePtyId, loopDetectionConfirmationRequest, lastOutputTime, + retryStatus, } = useGeminiStream( config.getGeminiClient(), historyManager.history, @@ -1223,6 +1224,7 @@ Logging in with Google... Restarting Gemini CLI to continue. settings.merged.ui?.customWittyPhrases, !!activePtyId && !embeddedShellFocused, lastOutputTime, + retryStatus, ); const handleGlobalKeypress = useCallback( diff --git a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx index 21bb2191e9..c5a004a437 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx +++ b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx @@ -34,6 +34,8 @@ import { ToolConfirmationOutcome, tokenLimit, debugLogger, + coreEvents, + CoreEvent, } from '@google/gemini-cli-core'; import type { Part, PartListUnion } from '@google/genai'; import type { UseHistoryManagerReturn } from './useHistoryManager.js'; @@ -1333,6 +1335,66 @@ describe('useGeminiStream', () => { }); }); + describe('Retry Handling', () => { + it('should update retryStatus when CoreEvent.RetryAttempt is emitted', async () => { + const { result } = renderHookWithDefaults(); + + const retryPayload = { + model: 'gemini-2.5-pro', + attempt: 2, + maxAttempts: 3, + delayMs: 1000, + }; + + await act(async () => { + coreEvents.emit(CoreEvent.RetryAttempt, retryPayload); + }); + + expect(result.current.retryStatus).toEqual(retryPayload); + }); + + it('should reset retryStatus when isResponding becomes false', async () => { + const { result } = renderTestHook(); + + const retryPayload = { + model: 'gemini-2.5-pro', + attempt: 2, + maxAttempts: 3, + delayMs: 1000, + }; + + // Start a query to make isResponding true + const mockStream = (async function* () { + yield { type: ServerGeminiEventType.Content, value: 'Part 1' }; + await new Promise(() => {}); // Keep stream open + })(); + mockSendMessageStream.mockReturnValue(mockStream); + + await act(async () => { + // eslint-disable-next-line @typescript-eslint/no-floating-promises + result.current.submitQuery('test query'); + }); + + await waitFor(() => { + expect(result.current.streamingState).toBe(StreamingState.Responding); + }); + + // Emit retry event + await act(async () => { + coreEvents.emit(CoreEvent.RetryAttempt, retryPayload); + }); + + expect(result.current.retryStatus).toEqual(retryPayload); + + // Cancel to make isResponding false + await act(async () => { + result.current.cancelOngoingRequest(); + }); + + expect(result.current.retryStatus).toBeNull(); + }); + }); + describe('Slash Command Handling', () => { it('should schedule a tool call when the command processor returns a schedule_tool action', async () => { const clientToolRequest: SlashCommandProcessorResult = { diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index 253582359e..ab88962047 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -5,18 +5,6 @@ */ import { useState, useRef, useCallback, useEffect, useMemo } from 'react'; -import type { - Config, - EditorType, - GeminiClient, - ServerGeminiChatCompressedEvent, - ServerGeminiContentEvent as ContentEvent, - ServerGeminiFinishedEvent, - ServerGeminiStreamEvent as GeminiEvent, - ThoughtSummary, - ToolCallRequestInfo, - GeminiErrorEventValue, -} from '@google/gemini-cli-core'; import { GeminiEventType as ServerGeminiEventType, getErrorMessage, @@ -40,6 +28,21 @@ import { processRestorableToolCalls, recordToolCallInteractions, ToolErrorType, + coreEvents, + CoreEvent, +} from '@google/gemini-cli-core'; +import type { + Config, + EditorType, + GeminiClient, + ServerGeminiChatCompressedEvent, + ServerGeminiContentEvent as ContentEvent, + ServerGeminiFinishedEvent, + ServerGeminiStreamEvent as GeminiEvent, + ThoughtSummary, + ToolCallRequestInfo, + GeminiErrorEventValue, + RetryAttemptPayload, } from '@google/gemini-cli-core'; import { type Part, type PartListUnion, FinishReason } from '@google/genai'; import type { @@ -113,6 +116,9 @@ export const useGeminiStream = ( isShellFocused?: boolean, ) => { const [initError, setInitError] = useState(null); + const [retryStatus, setRetryStatus] = useState( + null, + ); const abortControllerRef = useRef(null); const turnCancelledRef = useRef(false); const activeQueryIdRef = useRef(null); @@ -133,6 +139,16 @@ export const useGeminiStream = ( return new GitService(config.getProjectRoot(), storage); }, [config, storage]); + useEffect(() => { + const handleRetryAttempt = (payload: RetryAttemptPayload) => { + setRetryStatus(payload); + }; + coreEvents.on(CoreEvent.RetryAttempt, handleRetryAttempt); + return () => { + coreEvents.off(CoreEvent.RetryAttempt, handleRetryAttempt); + }; + }, []); + const [ toolCalls, scheduleToolCalls, @@ -297,6 +313,12 @@ export const useGeminiStream = ( } }, [streamingState, config, history]); + useEffect(() => { + if (!isResponding) { + setRetryStatus(null); + } + }, [isResponding]); + const cancelOngoingRequest = useCallback(() => { if ( streamingState !== StreamingState.Responding && @@ -527,6 +549,7 @@ export const useGeminiStream = ( currentGeminiMessageBuffer: string, userMessageTimestamp: number, ): string => { + setRetryStatus(null); if (turnCancelledRef.current) { // Prevents additional output after a user initiated cancel. return ''; @@ -1362,5 +1385,6 @@ export const useGeminiStream = ( activePtyId, loopDetectionConfirmationRequest, lastOutputTime, + retryStatus, }; }; diff --git a/packages/cli/src/ui/hooks/useLoadingIndicator.test.tsx b/packages/cli/src/ui/hooks/useLoadingIndicator.test.tsx index 14270019ac..300ef823da 100644 --- a/packages/cli/src/ui/hooks/useLoadingIndicator.test.tsx +++ b/packages/cli/src/ui/hooks/useLoadingIndicator.test.tsx @@ -15,6 +15,7 @@ import { } from './usePhraseCycler.js'; import { WITTY_LOADING_PHRASES } from '../constants/wittyPhrases.js'; import { INFORMATIVE_TIPS } from '../constants/tips.js'; +import type { RetryAttemptPayload } from '@google/gemini-cli-core'; describe('useLoadingIndicator', () => { beforeEach(() => { @@ -32,22 +33,26 @@ describe('useLoadingIndicator', () => { initialStreamingState: StreamingState, initialIsInteractiveShellWaiting: boolean = false, initialLastOutputTime: number = 0, + initialRetryStatus: RetryAttemptPayload | null = null, ) => { let hookResult: ReturnType; function TestComponent({ streamingState, isInteractiveShellWaiting, lastOutputTime, + retryStatus, }: { streamingState: StreamingState; isInteractiveShellWaiting?: boolean; lastOutputTime?: number; + retryStatus?: RetryAttemptPayload | null; }) { hookResult = useLoadingIndicator( streamingState, undefined, isInteractiveShellWaiting, lastOutputTime, + retryStatus, ); return null; } @@ -56,6 +61,7 @@ describe('useLoadingIndicator', () => { streamingState={initialStreamingState} isInteractiveShellWaiting={initialIsInteractiveShellWaiting} lastOutputTime={initialLastOutputTime} + retryStatus={initialRetryStatus} />, ); return { @@ -68,6 +74,7 @@ describe('useLoadingIndicator', () => { streamingState: StreamingState; isInteractiveShellWaiting?: boolean; lastOutputTime?: number; + retryStatus?: RetryAttemptPayload | null; }) => rerender(), }; }; @@ -206,4 +213,23 @@ describe('useLoadingIndicator', () => { }); expect(result.current.elapsedTime).toBe(0); }); + + it('should reflect retry status in currentLoadingPhrase when provided', () => { + const retryStatus = { + model: 'gemini-pro', + attempt: 2, + maxAttempts: 3, + delayMs: 1000, + }; + const { result } = renderLoadingIndicatorHook( + StreamingState.Responding, + false, + 0, + retryStatus, + ); + + expect(result.current.currentLoadingPhrase).toBe( + 'Trying to reach gemini-pro (Attempt 2/3)', + ); + }); }); diff --git a/packages/cli/src/ui/hooks/useLoadingIndicator.ts b/packages/cli/src/ui/hooks/useLoadingIndicator.ts index a39b0c0e29..9782752d46 100644 --- a/packages/cli/src/ui/hooks/useLoadingIndicator.ts +++ b/packages/cli/src/ui/hooks/useLoadingIndicator.ts @@ -7,13 +7,18 @@ import { StreamingState } from '../types.js'; import { useTimer } from './useTimer.js'; import { usePhraseCycler } from './usePhraseCycler.js'; -import { useState, useEffect, useRef } from 'react'; // Added useRef +import { useState, useEffect, useRef } from 'react'; +import { + getDisplayString, + type RetryAttemptPayload, +} from '@google/gemini-cli-core'; export const useLoadingIndicator = ( streamingState: StreamingState, customWittyPhrases?: string[], isInteractiveShellWaiting: boolean = false, lastOutputTime: number = 0, + retryStatus: RetryAttemptPayload | null = null, ) => { const [timerResetKey, setTimerResetKey] = useState(0); const isTimerActive = streamingState === StreamingState.Responding; @@ -55,11 +60,15 @@ export const useLoadingIndicator = ( prevStreamingStateRef.current = streamingState; }, [streamingState, elapsedTimeFromTimer]); + const retryPhrase = retryStatus + ? `Trying to reach ${getDisplayString(retryStatus.model)} (Attempt ${retryStatus.attempt}/${retryStatus.maxAttempts})` + : null; + return { elapsedTime: streamingState === StreamingState.WaitingForConfirmation ? retainedElapsedTime : elapsedTimeFromTimer, - currentLoadingPhrase, + currentLoadingPhrase: retryPhrase || currentLoadingPhrase, }; }; diff --git a/packages/core/src/core/geminiChat.ts b/packages/core/src/core/geminiChat.ts index 2dff70c16d..25f32e09a7 100644 --- a/packages/core/src/core/geminiChat.ts +++ b/packages/core/src/core/geminiChat.ts @@ -54,6 +54,7 @@ import { fireBeforeModelHook, fireBeforeToolSelectionHook, } from './geminiChatHookTriggers.js'; +import { coreEvents } from '../utils/events.js'; export enum StreamEventType { /** A regular content chunk from the API. */ @@ -401,6 +402,13 @@ export class GeminiChat { this.config, new ContentRetryEvent(attempt, retryType, delayMs, model), ); + coreEvents.emitRetryAttempt({ + attempt: attempt + 1, + maxAttempts, + delayMs: delayMs * (attempt + 1), + error: error instanceof Error ? error.message : String(error), + model, + }); await new Promise((res) => setTimeout(res, delayMs * (attempt + 1)), ); @@ -601,6 +609,15 @@ export class GeminiChat { signal: abortSignal, maxAttempts: availabilityMaxAttempts, getAvailabilityContext, + onRetry: (attempt, error, delayMs) => { + coreEvents.emitRetryAttempt({ + attempt, + maxAttempts: availabilityMaxAttempts ?? 10, + delayMs, + error: error instanceof Error ? error.message : String(error), + model: lastModelToUse, + }); + }, }); // Store the original request for AfterModel hooks diff --git a/packages/core/src/utils/events.ts b/packages/core/src/utils/events.ts index 89dd02395f..e6a15c68ab 100644 --- a/packages/core/src/utils/events.ts +++ b/packages/core/src/utils/events.ts @@ -97,6 +97,17 @@ export interface HookEndPayload extends HookPayload { success: boolean; } +/** + * Payload for the 'retry-attempt' event. + */ +export interface RetryAttemptPayload { + attempt: number; + maxAttempts: number; + delayMs: number; + error?: string; + model: string; +} + export enum CoreEvent { UserFeedback = 'user-feedback', ModelChanged = 'model-changed', @@ -108,6 +119,7 @@ export enum CoreEvent { HookStart = 'hook-start', HookEnd = 'hook-end', AgentsRefreshed = 'agents-refreshed', + RetryAttempt = 'retry-attempt', } export interface CoreEvents { @@ -121,6 +133,7 @@ export interface CoreEvents { [CoreEvent.HookStart]: [HookStartPayload]; [CoreEvent.HookEnd]: [HookEndPayload]; [CoreEvent.AgentsRefreshed]: never[]; + [CoreEvent.RetryAttempt]: [RetryAttemptPayload]; } type EventBacklogItem = { @@ -229,6 +242,13 @@ export class CoreEventEmitter extends EventEmitter { this.emit(CoreEvent.AgentsRefreshed); } + /** + * Notifies subscribers that a retry attempt is happening. + */ + emitRetryAttempt(payload: RetryAttemptPayload): void { + this.emit(CoreEvent.RetryAttempt, payload); + } + /** * Flushes buffered messages. Call this immediately after primary UI listener * subscribes. diff --git a/packages/core/src/utils/retry.test.ts b/packages/core/src/utils/retry.test.ts index b4edf6a9ce..7a70b45bb4 100644 --- a/packages/core/src/utils/retry.test.ts +++ b/packages/core/src/utils/retry.test.ts @@ -101,33 +101,33 @@ describe('retryWithBackoff', () => { expect(mockFn).toHaveBeenCalledTimes(3); }); - it('should default to 3 maxAttempts if no options are provided', async () => { - // This function will fail more than 3 times to ensure all retries are used. - const mockFn = createFailingFunction(10); + it('should default to 10 maxAttempts if no options are provided', async () => { + // This function will fail more than 10 times to ensure all retries are used. + const mockFn = createFailingFunction(15); const promise = retryWithBackoff(mockFn); await Promise.all([ - expect(promise).rejects.toThrow('Simulated error attempt 3'), + expect(promise).rejects.toThrow('Simulated error attempt 10'), vi.runAllTimersAsync(), ]); - expect(mockFn).toHaveBeenCalledTimes(3); + expect(mockFn).toHaveBeenCalledTimes(10); }); - it('should default to 3 maxAttempts if options.maxAttempts is undefined', async () => { - // This function will fail more than 3 times to ensure all retries are used. - const mockFn = createFailingFunction(10); + it('should default to 10 maxAttempts if options.maxAttempts is undefined', async () => { + // This function will fail more than 10 times to ensure all retries are used. + const mockFn = createFailingFunction(15); const promise = retryWithBackoff(mockFn, { maxAttempts: undefined }); - // Expect it to fail with the error from the 5th attempt. + // Expect it to fail with the error from the 10th attempt. await Promise.all([ - expect(promise).rejects.toThrow('Simulated error attempt 3'), + expect(promise).rejects.toThrow('Simulated error attempt 10'), vi.runAllTimersAsync(), ]); - expect(mockFn).toHaveBeenCalledTimes(3); + expect(mockFn).toHaveBeenCalledTimes(10); }); it('should not retry if shouldRetry returns false', async () => { diff --git a/packages/core/src/utils/retry.ts b/packages/core/src/utils/retry.ts index 5716e48886..eb9e145c18 100644 --- a/packages/core/src/utils/retry.ts +++ b/packages/core/src/utils/retry.ts @@ -32,10 +32,11 @@ export interface RetryOptions { retryFetchErrors?: boolean; signal?: AbortSignal; getAvailabilityContext?: () => RetryAvailabilityContext | undefined; + onRetry?: (attempt: number, error: unknown, delayMs: number) => void; } const DEFAULT_RETRY_OPTIONS: RetryOptions = { - maxAttempts: 3, + maxAttempts: 10, initialDelayMs: 5000, maxDelayMs: 30000, // 30 seconds shouldRetryOnError: isRetryableError, @@ -149,6 +150,7 @@ export async function retryWithBackoff( retryFetchErrors, signal, getAvailabilityContext, + onRetry, } = { ...DEFAULT_RETRY_OPTIONS, shouldRetryOnError: isRetryableError, @@ -172,6 +174,9 @@ export async function retryWithBackoff( ) { const jitter = currentDelay * 0.3 * (Math.random() * 2 - 1); const delayWithJitter = Math.max(0, currentDelay + jitter); + if (onRetry) { + onRetry(attempt, new Error('Invalid content'), delayWithJitter); + } await delay(delayWithJitter, signal); currentDelay = Math.min(maxDelayMs, currentDelay * 2); continue; @@ -252,6 +257,9 @@ export async function retryWithBackoff( debugLogger.warn( `Attempt ${attempt} failed: ${classifiedError.message}. Retrying after ${classifiedError.retryDelayMs}ms...`, ); + if (onRetry) { + onRetry(attempt, error, classifiedError.retryDelayMs); + } await delay(classifiedError.retryDelayMs, signal); continue; } else { @@ -261,6 +269,9 @@ export async function retryWithBackoff( // Exponential backoff with jitter for non-quota errors const jitter = currentDelay * 0.3 * (Math.random() * 2 - 1); const delayWithJitter = Math.max(0, currentDelay + jitter); + if (onRetry) { + onRetry(attempt, error, delayWithJitter); + } await delay(delayWithJitter, signal); currentDelay = Math.min(maxDelayMs, currentDelay * 2); continue; @@ -281,6 +292,9 @@ export async function retryWithBackoff( // Exponential backoff with jitter for non-quota errors const jitter = currentDelay * 0.3 * (Math.random() * 2 - 1); const delayWithJitter = Math.max(0, currentDelay + jitter); + if (onRetry) { + onRetry(attempt, error, delayWithJitter); + } await delay(delayWithJitter, signal); currentDelay = Math.min(maxDelayMs, currentDelay * 2); } From 933bc5774fe25a477b429c012ab91b7d32f78cee Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Tue, 13 Jan 2026 20:22:10 -0800 Subject: [PATCH 171/713] Modernize MaxSizedBox to use and ResizeObservers (#16565) --- packages/cli/src/gemini.tsx | 2 - .../src/ui/components/MainContent.test.tsx | 42 +- .../cli/src/ui/components/MainContent.tsx | 15 +- .../__snapshots__/MainContent.test.tsx.snap | 9 + .../components/messages/DiffRenderer.test.tsx | 85 ++- .../ui/components/messages/DiffRenderer.tsx | 76 +-- .../messages/ToolConfirmationMessage.tsx | 17 +- .../messages/ToolResultDisplay.test.tsx | 73 ++- .../components/messages/ToolResultDisplay.tsx | 108 ++-- .../__snapshots__/DiffRenderer.test.tsx.snap | 34 +- .../ToolMessageRawMarkdown.test.tsx.snap | 2 +- .../ToolResultDisplay.test.tsx.snap | 332 +--------- .../ui/components/shared/MaxSizedBox.test.tsx | 417 +++--------- .../src/ui/components/shared/MaxSizedBox.tsx | 612 ++---------------- .../__snapshots__/MaxSizedBox.test.tsx.snap | 71 ++ packages/cli/src/ui/utils/CodeColorizer.tsx | 23 +- 16 files changed, 482 insertions(+), 1436 deletions(-) create mode 100644 packages/cli/src/ui/components/__snapshots__/MainContent.test.tsx.snap create mode 100644 packages/cli/src/ui/components/shared/__snapshots__/MaxSizedBox.test.tsx.snap diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index 8ae21247e9..741632af85 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -67,7 +67,6 @@ import { type InitializationResult, } from './core/initializer.js'; import { validateAuthMethod } from './config/auth.js'; -import { setMaxSizedBoxDebugging } from './ui/components/shared/MaxSizedBox.js'; import { runZedIntegration } from './zed-integration/zedIntegration.js'; import { cleanupExpiredSessions } from './utils/sessionCleanup.js'; import { validateNonInteractiveAuth } from './validateNonInterActiveAuth.js'; @@ -562,7 +561,6 @@ export async function main() { await setupTerminalAndTheme(config, settings); - setMaxSizedBoxDebugging(isDebugMode); const initAppHandle = startupProfiler.start('initialize_app'); const initializationResult = await initializeApp(config, settings); initAppHandle?.end(); diff --git a/packages/cli/src/ui/components/MainContent.test.tsx b/packages/cli/src/ui/components/MainContent.test.tsx index 4bd823503c..63cbdce790 100644 --- a/packages/cli/src/ui/components/MainContent.test.tsx +++ b/packages/cli/src/ui/components/MainContent.test.tsx @@ -5,6 +5,7 @@ */ import { render } from '../../test-utils/render.js'; +import { waitFor } from '../../test-utils/async.js'; import { MainContent } from './MainContent.js'; import { describe, it, expect, vi, beforeEach } from 'vitest'; import { Box, Text } from 'ink'; @@ -41,9 +42,21 @@ vi.mock('../hooks/useAlternateBuffer.js', () => ({ })); vi.mock('./HistoryItemDisplay.js', () => ({ - HistoryItemDisplay: ({ item }: { item: { content: string } }) => ( + HistoryItemDisplay: ({ + item, + availableTerminalHeight, + }: { + item: { content: string }; + availableTerminalHeight?: number; + }) => ( - HistoryItem: {item.content} + + HistoryItem: {item.content} (height:{' '} + {availableTerminalHeight === undefined + ? 'undefined' + : availableTerminalHeight} + ) + ), })); @@ -81,23 +94,32 @@ describe('MainContent', () => { vi.mocked(useAlternateBuffer).mockReturnValue(false); }); - it('renders in normal buffer mode', () => { + it('renders in normal buffer mode', async () => { const { lastFrame } = render(); + await waitFor(() => expect(lastFrame()).toContain('AppHeader')); const output = lastFrame(); - expect(output).toContain('AppHeader'); - expect(output).toContain('HistoryItem: Hello'); - expect(output).toContain('HistoryItem: Hi there'); + expect(output).toContain('HistoryItem: Hello (height: 20)'); + expect(output).toContain('HistoryItem: Hi there (height: 20)'); }); - it('renders in alternate buffer mode', () => { + it('renders in alternate buffer mode', async () => { vi.mocked(useAlternateBuffer).mockReturnValue(true); const { lastFrame } = render(); + await waitFor(() => expect(lastFrame()).toContain('ScrollableList')); const output = lastFrame(); - expect(output).toContain('ScrollableList'); expect(output).toContain('AppHeader'); - expect(output).toContain('HistoryItem: Hello'); - expect(output).toContain('HistoryItem: Hi there'); + expect(output).toContain('HistoryItem: Hello (height: undefined)'); + expect(output).toContain('HistoryItem: Hi there (height: undefined)'); + }); + + it('does not constrain height in alternate buffer mode', async () => { + vi.mocked(useAlternateBuffer).mockReturnValue(true); + const { lastFrame } = render(); + await waitFor(() => expect(lastFrame()).toContain('HistoryItem: Hello')); + const output = lastFrame(); + + expect(output).toMatchSnapshot(); }); }); diff --git a/packages/cli/src/ui/components/MainContent.tsx b/packages/cli/src/ui/components/MainContent.tsx index f46a9c0c2f..7f3982eec0 100644 --- a/packages/cli/src/ui/components/MainContent.tsx +++ b/packages/cli/src/ui/components/MainContent.tsx @@ -65,7 +65,9 @@ export const MainContent = () => { { [ pendingHistoryItems, uiState.constrainHeight, + isAlternateBuffer, availableTerminalHeight, mainAreaWidth, uiState.isEditorDialogOpen, @@ -107,7 +110,7 @@ export const MainContent = () => { return ( { return pendingItems; } }, - [ - version, - mainAreaWidth, - staticAreaMaxItemHeight, - uiState.slashCommands, - pendingItems, - ], + [version, mainAreaWidth, uiState.slashCommands, pendingItems], ); if (isAlternateBuffer) { diff --git a/packages/cli/src/ui/components/__snapshots__/MainContent.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/MainContent.test.tsx.snap new file mode 100644 index 0000000000..ffbb0ab2d2 --- /dev/null +++ b/packages/cli/src/ui/components/__snapshots__/MainContent.test.tsx.snap @@ -0,0 +1,9 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`MainContent > does not constrain height in alternate buffer mode 1`] = ` +"ScrollableList +AppHeader +HistoryItem: Hello (height: undefined) +HistoryItem: Hi there (height: undefined) +ShowMoreLines" +`; diff --git a/packages/cli/src/ui/components/messages/DiffRenderer.test.tsx b/packages/cli/src/ui/components/messages/DiffRenderer.test.tsx index 9b1b93f25a..9063606146 100644 --- a/packages/cli/src/ui/components/messages/DiffRenderer.test.tsx +++ b/packages/cli/src/ui/components/messages/DiffRenderer.test.tsx @@ -6,6 +6,7 @@ import { OverflowProvider } from '../../contexts/OverflowContext.js'; import { renderWithProviders } from '../../../test-utils/render.js'; +import { waitFor } from '../../../test-utils/async.js'; import { DiffRenderer } from './DiffRenderer.js'; import * as CodeColorizer from '../../utils/CodeColorizer.js'; import { vi } from 'vitest'; @@ -23,7 +24,7 @@ describe('', () => { describe.each([true, false])( 'with useAlternateBuffer = %s', (useAlternateBuffer) => { - it('should call colorizeCode with correct language for new file with known extension', () => { + it('should call colorizeCode with correct language for new file with known extension', async () => { const newFileDiffContent = ` diff --git a/test.py b/test.py new file mode 100644 @@ -43,17 +44,19 @@ index 0000000..e69de29 , { useAlternateBuffer }, ); - expect(mockColorizeCode).toHaveBeenCalledWith({ - code: 'print("hello world")', - language: 'python', - availableHeight: undefined, - maxWidth: 80, - theme: undefined, - settings: expect.anything(), - }); + await waitFor(() => + expect(mockColorizeCode).toHaveBeenCalledWith({ + code: 'print("hello world")', + language: 'python', + availableHeight: undefined, + maxWidth: 80, + theme: undefined, + settings: expect.anything(), + }), + ); }); - it('should call colorizeCode with null language for new file with unknown extension', () => { + it('should call colorizeCode with null language for new file with unknown extension', async () => { const newFileDiffContent = ` diff --git a/test.unknown b/test.unknown new file mode 100644 @@ -73,17 +76,19 @@ index 0000000..e69de29 , { useAlternateBuffer }, ); - expect(mockColorizeCode).toHaveBeenCalledWith({ - code: 'some content', - language: null, - availableHeight: undefined, - maxWidth: 80, - theme: undefined, - settings: expect.anything(), - }); + await waitFor(() => + expect(mockColorizeCode).toHaveBeenCalledWith({ + code: 'some content', + language: null, + availableHeight: undefined, + maxWidth: 80, + theme: undefined, + settings: expect.anything(), + }), + ); }); - it('should call colorizeCode with null language for new file if no filename is provided', () => { + it('should call colorizeCode with null language for new file if no filename is provided', async () => { const newFileDiffContent = ` diff --git a/test.txt b/test.txt new file mode 100644 @@ -99,17 +104,19 @@ index 0000000..e69de29 , { useAlternateBuffer }, ); - expect(mockColorizeCode).toHaveBeenCalledWith({ - code: 'some text content', - language: null, - availableHeight: undefined, - maxWidth: 80, - theme: undefined, - settings: expect.anything(), - }); + await waitFor(() => + expect(mockColorizeCode).toHaveBeenCalledWith({ + code: 'some text content', + language: null, + availableHeight: undefined, + maxWidth: 80, + theme: undefined, + settings: expect.anything(), + }), + ); }); - it('should render diff content for existing file (not calling colorizeCode directly for the whole block)', () => { + it('should render diff content for existing file (not calling colorizeCode directly for the whole block)', async () => { const existingFileDiffContent = ` diff --git a/test.txt b/test.txt @@ -131,6 +138,7 @@ index 0000001..0000002 100644 { useAlternateBuffer }, ); // colorizeCode is used internally by the line-by-line rendering, not for the whole block + await waitFor(() => expect(lastFrame()).toContain('new line')); expect(mockColorizeCode).not.toHaveBeenCalledWith( expect.objectContaining({ code: expect.stringContaining('old line'), @@ -144,7 +152,7 @@ index 0000001..0000002 100644 expect(lastFrame()).toMatchSnapshot(); }); - it('should handle diff with only header and no changes', () => { + it('should handle diff with only header and no changes', async () => { const noChangeDiff = `diff --git a/file.txt b/file.txt index 1234567..1234567 100644 --- a/file.txt @@ -160,22 +168,24 @@ index 1234567..1234567 100644 , { useAlternateBuffer }, ); + await waitFor(() => expect(lastFrame()).toBeDefined()); expect(lastFrame()).toMatchSnapshot(); expect(mockColorizeCode).not.toHaveBeenCalled(); }); - it('should handle empty diff content', () => { + it('should handle empty diff content', async () => { const { lastFrame } = renderWithProviders( , { useAlternateBuffer }, ); + await waitFor(() => expect(lastFrame()).toBeDefined()); expect(lastFrame()).toMatchSnapshot(); expect(mockColorizeCode).not.toHaveBeenCalled(); }); - it('should render a gap indicator for skipped lines', () => { + it('should render a gap indicator for skipped lines', async () => { const diffWithGap = ` diff --git a/file.txt b/file.txt @@ -200,10 +210,11 @@ index 123..456 100644 , { useAlternateBuffer }, ); + await waitFor(() => expect(lastFrame()).toContain('added line')); expect(lastFrame()).toMatchSnapshot(); }); - it('should not render a gap indicator for small gaps (<= MAX_CONTEXT_LINES_WITHOUT_GAP)', () => { + it('should not render a gap indicator for small gaps (<= MAX_CONTEXT_LINES_WITHOUT_GAP)', async () => { const diffWithSmallGap = ` diff --git a/file.txt b/file.txt @@ -233,6 +244,7 @@ index abc..def 100644 , { useAlternateBuffer }, ); + await waitFor(() => expect(lastFrame()).toContain('context line 15')); expect(lastFrame()).toMatchSnapshot(); }); @@ -270,7 +282,7 @@ index 123..789 100644 }, ])( 'with terminalWidth $terminalWidth and height $height', - ({ terminalWidth, height }) => { + async ({ terminalWidth, height }) => { const { lastFrame } = renderWithProviders( , { useAlternateBuffer }, ); + await waitFor(() => expect(lastFrame()).toContain('anotherNew')); const output = lastFrame(); expect(sanitizeOutput(output, terminalWidth)).toMatchSnapshot(); }, ); }); - it('should correctly render a diff with a SVN diff format', () => { + it('should correctly render a diff with a SVN diff format', async () => { const newFileDiff = ` fileDiff Index: file.txt @@ -315,10 +328,11 @@ fileDiff Index: file.txt , { useAlternateBuffer }, ); + await waitFor(() => expect(lastFrame()).toContain('newVar')); expect(lastFrame()).toMatchSnapshot(); }); - it('should correctly render a new file with no file extension correctly', () => { + it('should correctly render a new file with no file extension correctly', async () => { const newFileDiff = ` fileDiff Index: Dockerfile @@ -341,6 +355,7 @@ fileDiff Index: Dockerfile , { useAlternateBuffer }, ); + await waitFor(() => expect(lastFrame()).toContain('RUN npm run build')); expect(lastFrame()).toMatchSnapshot(); }); }, diff --git a/packages/cli/src/ui/components/messages/DiffRenderer.tsx b/packages/cli/src/ui/components/messages/DiffRenderer.tsx index fdf1d26c91..83b205ac76 100644 --- a/packages/cli/src/ui/components/messages/DiffRenderer.tsx +++ b/packages/cli/src/ui/components/messages/DiffRenderer.tsx @@ -13,7 +13,6 @@ import { MaxSizedBox } from '../shared/MaxSizedBox.js'; import { theme as semanticTheme } from '../../semantic-colors.js'; import type { Theme } from '../../themes/theme.js'; import { useSettings } from '../../contexts/SettingsContext.js'; -import { useAlternateBuffer } from '../../hooks/useAlternateBuffer.js'; interface DiffLine { type: 'add' | 'del' | 'context' | 'hunk' | 'other'; @@ -102,7 +101,6 @@ export const DiffRenderer: React.FC = ({ theme, }) => { const settings = useSettings(); - const isAlternateBuffer = useAlternateBuffer(); const screenReaderEnabled = useIsScreenReaderEnabled(); @@ -179,7 +177,6 @@ export const DiffRenderer: React.FC = ({ tabWidth, availableTerminalHeight, terminalWidth, - !isAlternateBuffer, ); } }, [ @@ -192,7 +189,6 @@ export const DiffRenderer: React.FC = ({ terminalWidth, theme, settings, - isAlternateBuffer, tabWidth, ]); @@ -205,7 +201,6 @@ const renderDiffContent = ( tabWidth = DEFAULT_TAB_WIDTH, availableTerminalHeight: number | undefined, terminalWidth: number, - useMaxSizedBox: boolean, ) => { // 1. Normalize whitespace (replace tabs with spaces) *before* further processing const normalizedLines = parsedLines.map((line) => ({ @@ -283,22 +278,14 @@ const renderDiffContent = ( ) { acc.push( - {useMaxSizedBox ? ( - - {'═'.repeat(terminalWidth)} - - ) : ( - // We can use a proper separator when not using max sized box. - - )} + , ); } @@ -342,24 +329,15 @@ const renderDiffContent = ( : undefined; acc.push( - {useMaxSizedBox ? ( - - {gutterNumStr.padStart(gutterWidth)}{' '} - - ) : ( - - {gutterNumStr} - - )} + + {gutterNumStr} + {line.type === 'context' ? ( <> {prefixSymbol} @@ -393,22 +371,14 @@ const renderDiffContent = ( [], ); - if (useMaxSizedBox) { - return ( - - {content} - - ); - } - return ( - + {content} - + ); }; diff --git a/packages/cli/src/ui/components/messages/ToolConfirmationMessage.tsx b/packages/cli/src/ui/components/messages/ToolConfirmationMessage.tsx index 5be9169f02..6728100eff 100644 --- a/packages/cli/src/ui/components/messages/ToolConfirmationMessage.tsx +++ b/packages/cli/src/ui/components/messages/ToolConfirmationMessage.tsx @@ -19,7 +19,6 @@ import { RadioButtonSelect } from '../shared/RadioButtonSelect.js'; import { MaxSizedBox } from '../shared/MaxSizedBox.js'; import { useKeypress } from '../../hooks/useKeypress.js'; import { theme } from '../../semantic-colors.js'; -import { useAlternateBuffer } from '../../hooks/useAlternateBuffer.js'; import { useSettings } from '../../contexts/SettingsContext.js'; export interface ToolConfirmationMessageProps { @@ -41,7 +40,6 @@ export const ToolConfirmationMessage: React.FC< }) => { const { onConfirm } = confirmationDetails; - const isAlternateBuffer = useAlternateBuffer(); const settings = useSettings(); const allowPermanentApproval = settings.merged.security?.enablePermanentToolApproval ?? false; @@ -273,20 +271,14 @@ export const ToolConfirmationMessage: React.FC< bodyContentHeight -= 2; // Account for padding; } - const commandBox = ( - - {executionProps.command} - - ); - - bodyContent = isAlternateBuffer ? ( - commandBox - ) : ( + bodyContent = ( - {commandBox} + + {executionProps.command} + ); } else if (confirmationDetails.type === 'info') { @@ -338,7 +330,6 @@ export const ToolConfirmationMessage: React.FC< isDiffingEnabled, availableTerminalHeight, terminalWidth, - isAlternateBuffer, allowPermanentApproval, ]); diff --git a/packages/cli/src/ui/components/messages/ToolResultDisplay.test.tsx b/packages/cli/src/ui/components/messages/ToolResultDisplay.test.tsx index 98b0af9f40..41f79aab08 100644 --- a/packages/cli/src/ui/components/messages/ToolResultDisplay.test.tsx +++ b/packages/cli/src/ui/components/messages/ToolResultDisplay.test.tsx @@ -27,31 +27,6 @@ vi.mock('./DiffRenderer.js', () => ({ ), })); -vi.mock('../../utils/MarkdownDisplay.js', () => ({ - MarkdownDisplay: ({ text }: { text: string }) => ( - - MarkdownDisplay: {text} - - ), -})); - -vi.mock('../AnsiOutput.js', () => ({ - AnsiOutputText: ({ data }: { data: unknown }) => ( - - AnsiOutputText: {JSON.stringify(data)} - - ), -})); - -vi.mock('../shared/MaxSizedBox.js', () => ({ - MaxSizedBox: ({ children }: { children: React.ReactNode }) => ( - - MaxSizedBox: - {children} - - ), -})); - // Mock UIStateContext const mockUseUIState = vi.fn(); vi.mock('../../contexts/UIStateContext.js', () => ({ @@ -64,6 +39,25 @@ vi.mock('../../hooks/useAlternateBuffer.js', () => ({ useAlternateBuffer: () => mockUseAlternateBuffer(), })); +// Mock useSettings +vi.mock('../../contexts/SettingsContext.js', () => ({ + useSettings: () => ({ + merged: { + ui: { + useAlternateBuffer: false, + }, + }, + }), +})); + +// Mock useOverflowActions +vi.mock('../../contexts/OverflowContext.js', () => ({ + useOverflowActions: () => ({ + addOverflowingId: vi.fn(), + removeOverflowingId: vi.fn(), + }), +})); + describe('ToolResultDisplay', () => { beforeEach(() => { vi.clearAllMocks(); @@ -73,7 +67,7 @@ describe('ToolResultDisplay', () => { it('renders string result as markdown by default', () => { const { lastFrame } = render( - , + , ); const output = lastFrame(); @@ -83,7 +77,7 @@ describe('ToolResultDisplay', () => { it('renders string result as plain text when renderOutputAsMarkdown is false', () => { const { lastFrame } = render( { }); it('renders ANSI output result', () => { - const ansiResult = { - text: 'ansi content', - }; + const ansiResult: AnsiOutput = [ + [ + { + text: 'ansi content', + fg: 'red', + bg: 'black', + bold: false, + italic: false, + underline: false, + dim: false, + inverse: false, + }, + ], + ]; const { lastFrame } = render( { expect(output).toMatchSnapshot(); }); - it('falls back to plain text if availableHeight is set and not in alternate buffer', () => { + it('does not fall back to plain text if availableHeight is set and not in alternate buffer', () => { mockUseAlternateBuffer.mockReturnValue(false); // availableHeight calculation: 20 - 1 - 5 = 14 > 3 const { lastFrame } = render( , ); const output = lastFrame(); - - // Should force renderOutputAsMarkdown to false expect(output).toMatchSnapshot(); }); @@ -178,7 +181,7 @@ describe('ToolResultDisplay', () => { mockUseAlternateBuffer.mockReturnValue(true); const { lastFrame } = render( = ({ renderOutputAsMarkdown = true, }) => { const { renderMarkdown } = useUIState(); - const isAlternateBuffer = useAlternateBuffer(); const availableHeight = availableTerminalHeight ? Math.max( @@ -51,13 +49,6 @@ export const ToolResultDisplay: React.FC = ({ ) : undefined; - // Long tool call response in MarkdownDisplay doesn't respect availableTerminalHeight properly, - // so if we aren't using alternate buffer mode, we're forcing it to not render as markdown when the response is too long, it will fallback - // to render as plain text, which is contained within the terminal using MaxSizedBox - if (availableHeight && !isAlternateBuffer) { - renderOutputAsMarkdown = false; - } - const combinedPaddingAndBorderWidth = 4; const childWidth = terminalWidth - combinedPaddingAndBorderWidth; @@ -72,56 +63,59 @@ export const ToolResultDisplay: React.FC = ({ if (!truncatedResultDisplay) return null; + let content: React.ReactNode; + + if (typeof truncatedResultDisplay === 'string' && renderOutputAsMarkdown) { + content = ( + + ); + } else if ( + typeof truncatedResultDisplay === 'string' && + !renderOutputAsMarkdown + ) { + content = ( + + {truncatedResultDisplay} + + ); + } else if ( + typeof truncatedResultDisplay === 'object' && + 'fileDiff' in truncatedResultDisplay + ) { + content = ( + + ); + } else if ( + typeof truncatedResultDisplay === 'object' && + 'todos' in truncatedResultDisplay + ) { + // display nothing, as the TodoTray will handle rendering todos + return null; + } else { + content = ( + + ); + } + return ( - - {typeof truncatedResultDisplay === 'string' && - renderOutputAsMarkdown ? ( - - - - ) : typeof truncatedResultDisplay === 'string' && - !renderOutputAsMarkdown ? ( - isAlternateBuffer ? ( - - - {truncatedResultDisplay} - - - ) : ( - - - - {truncatedResultDisplay} - - - - ) - ) : typeof truncatedResultDisplay === 'object' && - 'fileDiff' in truncatedResultDisplay ? ( - - ) : typeof truncatedResultDisplay === 'object' && - 'todos' in truncatedResultDisplay ? ( - // display nothing, as the TodoTray will handle rendering todos - <> - ) : ( - - )} - + + {content} + ); }; diff --git a/packages/cli/src/ui/components/messages/__snapshots__/DiffRenderer.test.tsx.snap b/packages/cli/src/ui/components/messages/__snapshots__/DiffRenderer.test.tsx.snap index 38944657b1..03f55105a7 100644 --- a/packages/cli/src/ui/components/messages/__snapshots__/DiffRenderer.test.tsx.snap +++ b/packages/cli/src/ui/components/messages/__snapshots__/DiffRenderer.test.tsx.snap @@ -10,11 +10,11 @@ exports[` > with useAlterna exports[` > with useAlternateBuffer = false > should correctly render a diff with multiple hunks and a gap indicator > with terminalWidth 30 and height 6 1`] = ` "... first 10 lines hidden ... - ; -21 + const anotherNew = 'test' - ; -22 console.log('end of - second hunk');" + 'test'; +21 + const anotherNew = + 'test'; +22 console.log('end of second + hunk');" `; exports[` > with useAlternateBuffer = false > should correctly render a diff with multiple hunks and a gap indicator > with terminalWidth 80 and height 6 1`] = ` @@ -84,22 +84,13 @@ exports[` > with useAlterna exports[` > with useAlternateBuffer = true > should correctly render a diff with a SVN diff format 1`] = ` " 1 - const oldVar = 1; 1 + const newVar = 1; -═══════════════════════════════════════════════════════════════════════════════ +════════════════════════════════════════════════════════════════════════════════ 20 - const anotherOld = 'test'; 20 + const anotherNew = 'test';" `; exports[` > with useAlternateBuffer = true > should correctly render a diff with multiple hunks and a gap indicator > with terminalWidth 30 and height 6 1`] = ` -" 1 console.log('first hunk'); - - 2 - const oldVar = 1; - 2 + const newVar = 1; - 3 console.log('end of first - hunk'); -═════════════════════════════ -20 console.log('second - hunk'); -21 - const anotherOld = +"... first 10 lines hidden ... 'test'; 21 + const anotherNew = 'test'; @@ -108,11 +99,8 @@ exports[` > with useAlterna `; exports[` > with useAlternateBuffer = true > should correctly render a diff with multiple hunks and a gap indicator > with terminalWidth 80 and height 6 1`] = ` -" 1 console.log('first hunk'); - 2 - const oldVar = 1; - 2 + const newVar = 1; - 3 console.log('end of first hunk'); -═══════════════════════════════════════════════════════════════════════════════ +"... first 4 lines hidden ... +════════════════════════════════════════════════════════════════════════════════ 20 console.log('second hunk'); 21 - const anotherOld = 'test'; 21 + const anotherNew = 'test'; @@ -124,7 +112,7 @@ exports[` > with useAlterna 2 - const oldVar = 1; 2 + const newVar = 1; 3 console.log('end of first hunk'); -═══════════════════════════════════════════════════════════════════════════════ +════════════════════════════════════════════════════════════════════════════════ 20 console.log('second hunk'); 21 - const anotherOld = 'test'; 21 + const anotherNew = 'test'; @@ -164,7 +152,7 @@ exports[` > with useAlterna " 1 context line 1 2 - deleted line 2 + added line -═══════════════════════════════════════════════════════════════════════════════ +════════════════════════════════════════════════════════════════════════════════ 10 context line 10 11 context line 11" `; diff --git a/packages/cli/src/ui/components/messages/__snapshots__/ToolMessageRawMarkdown.test.tsx.snap b/packages/cli/src/ui/components/messages/__snapshots__/ToolMessageRawMarkdown.test.tsx.snap index e61465aee6..5a0a17f7e9 100644 --- a/packages/cli/src/ui/components/messages/__snapshots__/ToolMessageRawMarkdown.test.tsx.snap +++ b/packages/cli/src/ui/components/messages/__snapshots__/ToolMessageRawMarkdown.test.tsx.snap @@ -18,7 +18,7 @@ exports[` - Raw Markdown Display Snapshots > renders with renderM "╭──────────────────────────────────────────────────────────────────────────────╮ │ ✓ test-tool A tool for testing │ │ │ -│ Test **bold** and \`code\` markdown │" +│ Test bold and code markdown │" `; exports[` - Raw Markdown Display Snapshots > renders with renderMarkdown=true, useAlternateBuffer=false '(default, regular buffer)' 1`] = ` diff --git a/packages/cli/src/ui/components/messages/__snapshots__/ToolResultDisplay.test.tsx.snap b/packages/cli/src/ui/components/messages/__snapshots__/ToolResultDisplay.test.tsx.snap index 2919124771..666a2f7fed 100644 --- a/packages/cli/src/ui/components/messages/__snapshots__/ToolResultDisplay.test.tsx.snap +++ b/packages/cli/src/ui/components/messages/__snapshots__/ToolResultDisplay.test.tsx.snap @@ -1,326 +1,32 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`ToolResultDisplay > falls back to plain text if availableHeight is set and not in alternate buffer 1`] = `"MaxSizedBox:Some result"`; +exports[`ToolResultDisplay > does not fall back to plain text if availableHeight is set and not in alternate buffer 1`] = `"Some result"`; -exports[`ToolResultDisplay > keeps markdown if in alternate buffer even with availableHeight 1`] = `"MarkdownDisplay: Some result"`; +exports[`ToolResultDisplay > keeps markdown if in alternate buffer even with availableHeight 1`] = `"Some result"`; -exports[`ToolResultDisplay > renders ANSI output result 1`] = `"AnsiOutputText: {"text":"ansi content"}"`; +exports[`ToolResultDisplay > renders ANSI output result 1`] = `"ansi content"`; exports[`ToolResultDisplay > renders file diff result 1`] = `"DiffRenderer: test.ts - diff content"`; exports[`ToolResultDisplay > renders nothing for todos result 1`] = `""`; -exports[`ToolResultDisplay > renders string result as markdown by default 1`] = `"MarkdownDisplay: Some result"`; +exports[`ToolResultDisplay > renders string result as markdown by default 1`] = `"Some result"`; -exports[`ToolResultDisplay > renders string result as plain text when renderOutputAsMarkdown is false 1`] = `"MaxSizedBox:Some result"`; +exports[`ToolResultDisplay > renders string result as plain text when renderOutputAsMarkdown is false 1`] = `"**Some result**"`; exports[`ToolResultDisplay > truncates very long string results 1`] = ` -"MaxSizedBo...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaa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aaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaa" `; diff --git a/packages/cli/src/ui/components/shared/MaxSizedBox.test.tsx b/packages/cli/src/ui/components/shared/MaxSizedBox.test.tsx index 6312e4816a..06501eca3e 100644 --- a/packages/cli/src/ui/components/shared/MaxSizedBox.test.tsx +++ b/packages/cli/src/ui/components/shared/MaxSizedBox.test.tsx @@ -5,19 +5,14 @@ */ import { render } from '../../../test-utils/render.js'; +import { waitFor } from '../../../test-utils/async.js'; import { OverflowProvider } from '../../contexts/OverflowContext.js'; -import { MaxSizedBox, setMaxSizedBoxDebugging } from './MaxSizedBox.js'; +import { MaxSizedBox } from './MaxSizedBox.js'; import { Box, Text } from 'ink'; import { describe, it, expect } from 'vitest'; describe('', () => { - // Make sure MaxSizedBox logs errors on invalid configurations. - // This is useful for debugging issues with the component. - // It should be set to false in production for performance and to avoid - // cluttering the console if there are ignorable issues. - setMaxSizedBoxDebugging(true); - - it('renders children without truncation when they fit', () => { + it('renders children without truncation when they fit', async () => { const { lastFrame, unmount } = render( @@ -27,53 +22,105 @@ describe('', () => { , ); - expect(lastFrame()).equals('Hello, World!'); + await waitFor(() => expect(lastFrame()).toContain('Hello, World!')); + expect(lastFrame()).toMatchSnapshot(); unmount(); }); - it('hides lines when content exceeds maxHeight', () => { + it('hides lines when content exceeds maxHeight', async () => { const { lastFrame, unmount } = render( - + Line 1 - - Line 2 - - Line 3 , ); - expect(lastFrame()).equals(`... first 2 lines hidden ... -Line 3`); + await waitFor(() => + expect(lastFrame()).toContain('... first 2 lines hidden ...'), + ); + expect(lastFrame()).toMatchSnapshot(); unmount(); }); - it('hides lines at the end when content exceeds maxHeight and overflowDirection is bottom', () => { + it('hides lines at the end when content exceeds maxHeight and overflowDirection is bottom', async () => { const { lastFrame, unmount } = render( - + Line 1 - - Line 2 - - Line 3 , ); - expect(lastFrame()).equals(`Line 1 -... last 2 lines hidden ...`); + await waitFor(() => + expect(lastFrame()).toContain('... last 2 lines hidden ...'), + ); + expect(lastFrame()).toMatchSnapshot(); unmount(); }); - it('wraps text that exceeds maxWidth', () => { + it('shows plural "lines" when more than one line is hidden', async () => { + const { lastFrame, unmount } = render( + + + + Line 1 + Line 2 + Line 3 + + + , + ); + await waitFor(() => + expect(lastFrame()).toContain('... first 2 lines hidden ...'), + ); + expect(lastFrame()).toMatchSnapshot(); + unmount(); + }); + + it('shows singular "line" when exactly one line is hidden', async () => { + const { lastFrame, unmount } = render( + + + + Line 1 + + + , + ); + await waitFor(() => + expect(lastFrame()).toContain('... first 1 line hidden ...'), + ); + expect(lastFrame()).toMatchSnapshot(); + unmount(); + }); + + it('accounts for additionalHiddenLinesCount', async () => { + const { lastFrame, unmount } = render( + + + + Line 1 + Line 2 + Line 3 + + + , + ); + await waitFor(() => + expect(lastFrame()).toContain('... first 7 lines hidden ...'), + ); + expect(lastFrame()).toMatchSnapshot(); + unmount(); + }); + + it('wraps text that exceeds maxWidth', async () => { const { lastFrame, unmount } = render( @@ -84,325 +131,66 @@ Line 3`); , ); - expect(lastFrame()).equals(`This is a -long line -of text`); + await waitFor(() => expect(lastFrame()).toContain('This is a')); + expect(lastFrame()).toMatchSnapshot(); unmount(); }); - it('handles mixed wrapping and non-wrapping segments', () => { - const multilineText = `This part will wrap around. -And has a line break. - Leading spaces preserved.`; - const { lastFrame, unmount } = render( - - - - Example - - - No Wrap: - {multilineText} - - - Longer No Wrap: - This part will wrap around. - - - , - ); - - expect(lastFrame()).equals( - `Example -No Wrap: This part - will wrap - around. - And has a - line break. - Leading - spaces - preserved. -Longer No Wrap: This - part - will - wrap - arou - nd.`, - ); - unmount(); - }); - - it('handles words longer than maxWidth by splitting them', () => { - const { lastFrame, unmount } = render( - - - - Supercalifragilisticexpialidocious - - - , - ); - - expect(lastFrame()).equals(`... … -istic -expia -lidoc -ious`); - unmount(); - }); - - it('does not truncate when maxHeight is undefined', () => { + it('does not truncate when maxHeight is undefined', async () => { const { lastFrame, unmount } = render( - + Line 1 - - Line 2 , ); - expect(lastFrame()).equals(`Line 1 -Line 2`); + await waitFor(() => expect(lastFrame()).toContain('Line 1')); + expect(lastFrame()).toMatchSnapshot(); unmount(); }); - it('shows plural "lines" when more than one line is hidden', () => { - const { lastFrame, unmount } = render( - - - - Line 1 - - - Line 2 - - - Line 3 - - - , - ); - expect(lastFrame()).equals(`... first 2 lines hidden ... -Line 3`); - unmount(); - }); - - it('shows plural "lines" when more than one line is hidden and overflowDirection is bottom', () => { - const { lastFrame, unmount } = render( - - - - Line 1 - - - Line 2 - - - Line 3 - - - , - ); - expect(lastFrame()).equals(`Line 1 -... last 2 lines hidden ...`); - unmount(); - }); - - it('renders an empty box for empty children', () => { + it('renders an empty box for empty children', async () => { const { lastFrame, unmount } = render( , ); - // Expect an empty string or a box with nothing in it. - // Ink renders an empty box as an empty string. - expect(lastFrame()).equals(''); + // Use waitFor to ensure ResizeObserver has a chance to run + await waitFor(() => expect(lastFrame()).toBeDefined()); + expect(lastFrame()?.trim()).equals(''); unmount(); }); - it('wraps text with multi-byte unicode characters correctly', () => { - const { lastFrame, unmount } = render( - - - - 你好世界 - - - , - ); - - // "你好" has a visual width of 4. "世界" has a visual width of 4. - // With maxWidth=5, it should wrap after the second character. - expect(lastFrame()).equals(`你好 -世界`); - unmount(); - }); - - it('wraps text with multi-byte emoji characters correctly', () => { - const { lastFrame, unmount } = render( - - - - 🐶🐶🐶🐶🐶 - - - , - ); - - // Each "🐶" has a visual width of 2. - // With maxWidth=5, it should wrap every 2 emojis. - expect(lastFrame()).equals(`🐶🐶 -🐶🐶 -🐶`); - unmount(); - }); - - it('falls back to an ellipsis when width is extremely small', () => { - const { lastFrame, unmount } = render( - - - - No - wrap - - - , - ); - - expect(lastFrame()).equals('N…'); - unmount(); - }); - - it('truncates long non-wrapping text with ellipsis', () => { - const { lastFrame, unmount } = render( - - - - ABCDE - wrap - - - , - ); - - expect(lastFrame()).equals('AB…'); - unmount(); - }); - - it('truncates non-wrapping text containing line breaks', () => { - const { lastFrame, unmount } = render( - - - - {'A\nBCDE'} - wrap - - - , - ); - - expect(lastFrame()).equals(`A\n…`); - unmount(); - }); - - it('truncates emoji characters correctly with ellipsis', () => { - const { lastFrame, unmount } = render( - - - - 🐶🐶🐶 - wrap - - - , - ); - - expect(lastFrame()).equals(`🐶…`); - unmount(); - }); - - it('shows ellipsis for multiple rows with long non-wrapping text', () => { - const { lastFrame, unmount } = render( - - - - AAA - first - - - BBB - second - - - CCC - third - - - , - ); - - expect(lastFrame()).equals(`AA…\nBB…\nCC…`); - unmount(); - }); - - it('accounts for additionalHiddenLinesCount', () => { - const { lastFrame, unmount } = render( - - - - Line 1 - - - Line 2 - - - Line 3 - - - , - ); - // 1 line is hidden by overflow, 5 are additionally hidden. - expect(lastFrame()).equals(`... first 7 lines hidden ... -Line 3`); - unmount(); - }); - - it('handles React.Fragment as a child', () => { + it('handles React.Fragment as a child', async () => { const { lastFrame, unmount } = render( - <> - + + <> Line 1 from Fragment - - Line 2 from Fragment - - - + Line 3 direct child , ); - expect(lastFrame()).equals(`Line 1 from Fragment -Line 2 from Fragment -Line 3 direct child`); + await waitFor(() => expect(lastFrame()).toContain('Line 1 from Fragment')); + expect(lastFrame()).toMatchSnapshot(); unmount(); }); - it('clips a long single text child from the top', () => { + it('clips a long single text child from the top', async () => { const THIRTY_LINES = Array.from( { length: 30 }, (_, i) => `Line ${i + 1}`, ).join('\n'); - const { lastFrame, unmount } = render( - + {THIRTY_LINES} @@ -410,21 +198,18 @@ Line 3 direct child`); , ); - const expected = [ - '... first 21 lines hidden ...', - ...Array.from({ length: 9 }, (_, i) => `Line ${22 + i}`), - ].join('\n'); - - expect(lastFrame()).equals(expected); + await waitFor(() => + expect(lastFrame()).toContain('... first 21 lines hidden ...'), + ); + expect(lastFrame()).toMatchSnapshot(); unmount(); }); - it('clips a long single text child from the bottom', () => { + it('clips a long single text child from the bottom', async () => { const THIRTY_LINES = Array.from( { length: 30 }, (_, i) => `Line ${i + 1}`, ).join('\n'); - const { lastFrame, unmount } = render( @@ -435,12 +220,10 @@ Line 3 direct child`); , ); - const expected = [ - ...Array.from({ length: 9 }, (_, i) => `Line ${i + 1}`), - '... last 21 lines hidden ...', - ].join('\n'); - - expect(lastFrame()).equals(expected); + await waitFor(() => + expect(lastFrame()).toContain('... last 21 lines hidden ...'), + ); + expect(lastFrame()).toMatchSnapshot(); unmount(); }); }); diff --git a/packages/cli/src/ui/components/shared/MaxSizedBox.tsx b/packages/cli/src/ui/components/shared/MaxSizedBox.tsx index d8b15d104d..0e87d5a6cd 100644 --- a/packages/cli/src/ui/components/shared/MaxSizedBox.tsx +++ b/packages/cli/src/ui/components/shared/MaxSizedBox.tsx @@ -4,15 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { Fragment, useEffect, useId } from 'react'; -import { Box, Text } from 'ink'; -import stringWidth from 'string-width'; +import type React from 'react'; +import { useCallback, useEffect, useId, useRef, useState } from 'react'; +import { Box, Text, ResizeObserver, type DOMElement } from 'ink'; import { theme } from '../../semantic-colors.js'; -import { toCodePoints } from '../../utils/textUtils.js'; import { useOverflowActions } from '../../contexts/OverflowContext.js'; -import { debugLogger } from '@google/gemini-cli-core'; - -let enableDebugLog = false; /** * Minimum height for the MaxSizedBox component. @@ -21,42 +17,10 @@ let enableDebugLog = false; */ export const MINIMUM_MAX_HEIGHT = 2; -export function setMaxSizedBoxDebugging(value: boolean) { - enableDebugLog = value; -} - -function debugReportError(message: string, element: React.ReactNode) { - if (!enableDebugLog) return; - - if (!React.isValidElement(element)) { - debugLogger.warn( - message, - `Invalid element: '${String(element)}' typeof=${typeof element}`, - ); - return; - } - - let sourceMessage = ''; - try { - const elementWithSource = element as { - _source?: { fileName?: string; lineNumber?: number }; - }; - const fileName = elementWithSource._source?.fileName; - const lineNumber = elementWithSource._source?.lineNumber; - sourceMessage = fileName ? `${fileName}:${lineNumber}` : ''; - } catch (error) { - debugLogger.warn('Error while trying to get file name:', error); - } - - debugLogger.warn( - message, - `${String(element.type)}. Source: ${sourceMessage}`, - ); -} interface MaxSizedBoxProps { children?: React.ReactNode; maxWidth?: number; - maxHeight: number | undefined; + maxHeight?: number; overflowDirection?: 'top' | 'bottom'; additionalHiddenLinesCount?: number; } @@ -64,41 +28,6 @@ interface MaxSizedBoxProps { /** * A React component that constrains the size of its children and provides * content-aware truncation when the content exceeds the specified `maxHeight`. - * - * `MaxSizedBox` requires a specific structure for its children to correctly - * measure and render the content: - * - * 1. **Direct children must be `` elements.** Each `` represents a - * single row of content. - * 2. **Row `` elements must contain only `` elements.** These - * `` elements can be nested and there are no restrictions to Text - * element styling other than that non-wrapping text elements must be - * before wrapping text elements. - * - * **Constraints:** - * - **Box Properties:** Custom properties on the child `` elements are - * ignored. In debug mode, runtime checks will report errors for any - * unsupported properties. - * - **Text Wrapping:** Within a single row, `` elements with no wrapping - * (e.g., headers, labels) must appear before any `` elements that wrap. - * - **Element Types:** Runtime checks will warn if unsupported element types - * are used as children. - * - * @example - * - * - * This is the first line. - * - * - * Non-wrapping Header: - * This is the rest of the line which will wrap if it's too long. - * - * - * - * Line 3 with nested styled text inside of it. - * - * - * */ export const MaxSizedBox: React.FC = ({ children, @@ -109,49 +38,50 @@ export const MaxSizedBox: React.FC = ({ }) => { const id = useId(); const { addOverflowingId, removeOverflowingId } = useOverflowActions() || {}; + const observerRef = useRef(null); + const [contentHeight, setContentHeight] = useState(0); - const laidOutStyledText: StyledText[][] = []; - const targetMaxHeight = Math.max( - Math.round(maxHeight ?? Number.MAX_SAFE_INTEGER), - MINIMUM_MAX_HEIGHT, + const onRefChange = useCallback( + (node: DOMElement | null) => { + if (observerRef.current) { + observerRef.current.disconnect(); + observerRef.current = null; + } + + if (node && maxHeight !== undefined) { + const observer = new ResizeObserver((entries) => { + const entry = entries[0]; + if (entry) { + setContentHeight(entry.contentRect.height); + } + }); + observer.observe(node); + observerRef.current = observer; + } + }, + [maxHeight], ); - if (maxWidth === undefined) { - throw new Error('maxWidth must be defined when maxHeight is set.'); - } - function visitRows(element: React.ReactNode) { - if (!React.isValidElement<{ children?: React.ReactNode }>(element)) { - return; - } + const effectiveMaxHeight = + maxHeight !== undefined + ? Math.max(Math.round(maxHeight), MINIMUM_MAX_HEIGHT) + : undefined; - if (element.type === Fragment) { - React.Children.forEach(element.props.children, visitRows); - return; - } - - if (element.type === Box) { - layoutInkElementAsStyledText(element, maxWidth!, laidOutStyledText); - return; - } - - debugReportError('MaxSizedBox children must be elements', element); - } - - React.Children.forEach(children, visitRows); - - const contentWillOverflow = - (targetMaxHeight !== undefined && - laidOutStyledText.length > targetMaxHeight) || + const isOverflowing = + (effectiveMaxHeight !== undefined && contentHeight > effectiveMaxHeight) || additionalHiddenLinesCount > 0; + + // If we're overflowing, we need to hide at least 1 line for the message. const visibleContentHeight = - contentWillOverflow && targetMaxHeight !== undefined - ? targetMaxHeight - 1 - : targetMaxHeight; + isOverflowing && effectiveMaxHeight !== undefined + ? effectiveMaxHeight - 1 + : effectiveMaxHeight; const hiddenLinesCount = visibleContentHeight !== undefined - ? Math.max(0, laidOutStyledText.length - visibleContentHeight) + ? Math.max(0, contentHeight - visibleContentHeight) : 0; + const totalHiddenLines = hiddenLinesCount + additionalHiddenLinesCount; useEffect(() => { @@ -166,36 +96,40 @@ export const MaxSizedBox: React.FC = ({ }; }, [id, totalHiddenLines, addOverflowingId, removeOverflowingId]); - const visibleStyledText = - hiddenLinesCount > 0 - ? overflowDirection === 'top' - ? laidOutStyledText.slice(hiddenLinesCount, laidOutStyledText.length) - : laidOutStyledText.slice(0, visibleContentHeight) - : laidOutStyledText; + if (effectiveMaxHeight === undefined) { + return ( + + {children} + + ); + } - const visibleLines = visibleStyledText.map((line, index) => ( - - {line.length > 0 ? ( - line.map((segment, segIndex) => ( - - {segment.text} - - )) - ) : ( - - )} - - )); + const offset = + hiddenLinesCount > 0 && overflowDirection === 'top' ? -hiddenLinesCount : 0; return ( - + {totalHiddenLines > 0 && overflowDirection === 'top' && ( ... first {totalHiddenLines} line{totalHiddenLines === 1 ? '' : 's'}{' '} hidden ... )} - {visibleLines} + + + {children} + + {totalHiddenLines > 0 && overflowDirection === 'bottom' && ( ... last {totalHiddenLines} line{totalHiddenLines === 1 ? '' : 's'}{' '} @@ -205,423 +139,3 @@ export const MaxSizedBox: React.FC = ({ ); }; - -// Define a type for styled text segments -interface StyledText { - text: string; - props: Record; -} - -/** - * Single row of content within the MaxSizedBox. - * - * A row can contain segments that are not wrapped, followed by segments that - * are. This is a minimal implementation that only supports the functionality - * needed today. - */ -interface Row { - noWrapSegments: StyledText[]; - segments: StyledText[]; -} - -/** - * Flattens the child elements of MaxSizedBox into an array of `Row` objects. - * - * This function expects a specific child structure to function correctly: - * 1. The top-level child of `MaxSizedBox` should be a single ``. This - * outer box is primarily for structure and is not directly rendered. - * 2. Inside the outer ``, there should be one or more children. Each of - * these children must be a `` that represents a row. - * 3. Inside each "row" ``, the children must be `` components. - * - * The structure should look like this: - * - * // Row 1 - * ... - * ... - * - * // Row 2 - * ... - * - * - * - * It is an error for a child without wrapping to appear after a - * child with wrapping within the same row Box. - * - * @param element The React node to flatten. - * @returns An array of `Row` objects. - */ -function visitBoxRow(element: React.ReactNode): Row { - if ( - !React.isValidElement<{ children?: React.ReactNode }>(element) || - element.type !== Box - ) { - debugReportError( - `All children of MaxSizedBox must be elements`, - element, - ); - return { - noWrapSegments: [{ text: '', props: {} }], - segments: [], - }; - } - - if (enableDebugLog) { - const boxProps = element.props as { - children?: React.ReactNode; - readonly flexDirection?: - | 'row' - | 'column' - | 'row-reverse' - | 'column-reverse'; - }; - // Ensure the Box has no props other than the default ones and key. - let maxExpectedProps = 4; - if (boxProps.children !== undefined) { - // Allow the key prop, which is automatically added by React. - maxExpectedProps += 1; - } - if ( - boxProps.flexDirection !== undefined && - boxProps.flexDirection !== 'row' - ) { - debugReportError( - 'MaxSizedBox children must have flexDirection="row".', - element, - ); - } - if (Object.keys(boxProps).length > maxExpectedProps) { - debugReportError( - `Boxes inside MaxSizedBox must not have additional props. ${Object.keys( - boxProps, - ).join(', ')}`, - element, - ); - } - } - - const row: Row = { - noWrapSegments: [], - segments: [], - }; - - let hasSeenWrapped = false; - - function visitRowChild( - element: React.ReactNode, - parentProps: Record | undefined, - ) { - if (element === null) { - return; - } - if (typeof element === 'string' || typeof element === 'number') { - const text = String(element); - // Ignore empty strings as they don't need to be rendered. - if (!text) { - return; - } - - const segment: StyledText = { text, props: parentProps ?? {} }; - - // Check the 'wrap' property from the merged props to decide the segment type. - if (parentProps === undefined || parentProps['wrap'] === 'wrap') { - hasSeenWrapped = true; - row.segments.push(segment); - } else { - if (!hasSeenWrapped) { - row.noWrapSegments.push(segment); - } else { - // put in the wrapped segment as the row is already stuck in wrapped mode. - row.segments.push(segment); - debugReportError( - 'Text elements without wrapping cannot appear after elements with wrapping in the same row.', - element, - ); - } - } - return; - } - - if (!React.isValidElement<{ children?: React.ReactNode }>(element)) { - debugReportError('Invalid element.', element); - return; - } - - if (element.type === Fragment) { - React.Children.forEach(element.props.children, (child) => - visitRowChild(child, parentProps), - ); - return; - } - - if (element.type !== Text) { - debugReportError( - 'Children of a row Box must be elements.', - element, - ); - return; - } - - // Merge props from parent elements. Child props take precedence. - const { children, ...currentProps } = element.props; - const mergedProps = - parentProps === undefined - ? currentProps - : { ...parentProps, ...currentProps }; - React.Children.forEach(children, (child) => - visitRowChild(child, mergedProps), - ); - } - - React.Children.forEach(element.props.children, (child) => - visitRowChild(child, undefined), - ); - - return row; -} - -function layoutInkElementAsStyledText( - element: React.ReactElement, - maxWidth: number, - output: StyledText[][], -) { - const row = visitBoxRow(element); - if (row.segments.length === 0 && row.noWrapSegments.length === 0) { - // Return a single empty line if there are no segments to display - output.push([]); - return; - } - - const lines: StyledText[][] = []; - const nonWrappingContent: StyledText[] = []; - let noWrappingWidth = 0; - - // First, lay out the non-wrapping segments - row.noWrapSegments.forEach((segment) => { - nonWrappingContent.push(segment); - noWrappingWidth += stringWidth(segment.text); - }); - - if (row.segments.length === 0) { - // This is a bit of a special case when there are no segments that allow - // wrapping. It would be ideal to unify. - const lines: StyledText[][] = []; - let currentLine: StyledText[] = []; - nonWrappingContent.forEach((segment) => { - const textLines = segment.text.split('\n'); - textLines.forEach((text, index) => { - if (index > 0) { - lines.push(currentLine); - currentLine = []; - } - if (text) { - currentLine.push({ text, props: segment.props }); - } - }); - }); - if ( - currentLine.length > 0 || - (nonWrappingContent.length > 0 && - nonWrappingContent[nonWrappingContent.length - 1].text.endsWith('\n')) - ) { - lines.push(currentLine); - } - for (const line of lines) { - output.push(line); - } - return; - } - - const availableWidth = maxWidth - noWrappingWidth; - - if (availableWidth < 1) { - // No room to render the wrapping segments. Truncate the non-wrapping - // content and append an ellipsis so the line always fits within maxWidth. - - // Handle line breaks in non-wrapping content when truncating - const lines: StyledText[][] = []; - let currentLine: StyledText[] = []; - let currentLineWidth = 0; - - for (const segment of nonWrappingContent) { - const textLines = segment.text.split('\n'); - textLines.forEach((text, index) => { - if (index > 0) { - // New line encountered, finish current line and start new one - lines.push(currentLine); - currentLine = []; - currentLineWidth = 0; - } - - if (text) { - const textWidth = stringWidth(text); - - // When there's no room for wrapping content, be very conservative - // For lines after the first line break, show only ellipsis if the text would be truncated - if (index > 0 && textWidth > 0) { - // This is content after a line break - just show ellipsis to indicate truncation - currentLine.push({ text: '…', props: {} }); - currentLineWidth = stringWidth('…'); - } else { - // This is the first line or a continuation, try to fit what we can - const maxContentWidth = Math.max(0, maxWidth - stringWidth('…')); - - if (textWidth <= maxContentWidth && currentLineWidth === 0) { - // Text fits completely on this line - currentLine.push({ text, props: segment.props }); - currentLineWidth += textWidth; - } else { - // Text needs truncation - const codePoints = toCodePoints(text); - let truncatedWidth = currentLineWidth; - let sliceEndIndex = 0; - - for (const char of codePoints) { - const charWidth = stringWidth(char); - if (truncatedWidth + charWidth > maxContentWidth) { - break; - } - truncatedWidth += charWidth; - sliceEndIndex++; - } - - const slice = codePoints.slice(0, sliceEndIndex).join(''); - if (slice) { - currentLine.push({ text: slice, props: segment.props }); - } - currentLine.push({ text: '…', props: {} }); - currentLineWidth = truncatedWidth + stringWidth('…'); - } - } - } - }); - } - - // Add the last line if it has content or if the last segment ended with \n - if ( - currentLine.length > 0 || - (nonWrappingContent.length > 0 && - nonWrappingContent[nonWrappingContent.length - 1].text.endsWith('\n')) - ) { - lines.push(currentLine); - } - - // If we don't have any lines yet, add an ellipsis line - if (lines.length === 0) { - lines.push([{ text: '…', props: {} }]); - } - - for (const line of lines) { - output.push(line); - } - return; - } - - // Now, lay out the wrapping segments - let wrappingPart: StyledText[] = []; - let wrappingPartWidth = 0; - - function addWrappingPartToLines() { - if (lines.length === 0) { - lines.push([...nonWrappingContent, ...wrappingPart]); - } else { - if (noWrappingWidth > 0) { - lines.push([ - ...[{ text: ' '.repeat(noWrappingWidth), props: {} }], - ...wrappingPart, - ]); - } else { - lines.push(wrappingPart); - } - } - wrappingPart = []; - wrappingPartWidth = 0; - } - - function addToWrappingPart(text: string, props: Record) { - if ( - wrappingPart.length > 0 && - wrappingPart[wrappingPart.length - 1].props === props - ) { - wrappingPart[wrappingPart.length - 1].text += text; - } else { - wrappingPart.push({ text, props }); - } - } - - row.segments.forEach((segment) => { - const linesFromSegment = segment.text.split('\n'); - - linesFromSegment.forEach((lineText, lineIndex) => { - if (lineIndex > 0) { - addWrappingPartToLines(); - } - - const words = lineText.split(/(\s+)/); // Split by whitespace - - words.forEach((word) => { - if (!word) return; - const wordWidth = stringWidth(word); - - if ( - wrappingPartWidth + wordWidth > availableWidth && - wrappingPartWidth > 0 - ) { - addWrappingPartToLines(); - if (/^\s+$/.test(word)) { - return; - } - } - - if (wordWidth > availableWidth) { - // Word is too long, needs to be split across lines - const wordAsCodePoints = toCodePoints(word); - let remainingWordAsCodePoints = wordAsCodePoints; - while (remainingWordAsCodePoints.length > 0) { - let splitIndex = 0; - let currentSplitWidth = 0; - for (const char of remainingWordAsCodePoints) { - const charWidth = stringWidth(char); - if ( - wrappingPartWidth + currentSplitWidth + charWidth > - availableWidth - ) { - break; - } - currentSplitWidth += charWidth; - splitIndex++; - } - - if (splitIndex > 0) { - const part = remainingWordAsCodePoints - .slice(0, splitIndex) - .join(''); - addToWrappingPart(part, segment.props); - wrappingPartWidth += stringWidth(part); - remainingWordAsCodePoints = - remainingWordAsCodePoints.slice(splitIndex); - } - - if (remainingWordAsCodePoints.length > 0) { - addWrappingPartToLines(); - } - } - } else { - addToWrappingPart(word, segment.props); - wrappingPartWidth += wordWidth; - } - }); - }); - // Split omits a trailing newline, so we need to handle it here - if (segment.text.endsWith('\n')) { - addWrappingPartToLines(); - } - }); - - if (wrappingPart.length > 0) { - addWrappingPartToLines(); - } - for (const line of lines) { - output.push(line); - } -} diff --git a/packages/cli/src/ui/components/shared/__snapshots__/MaxSizedBox.test.tsx.snap b/packages/cli/src/ui/components/shared/__snapshots__/MaxSizedBox.test.tsx.snap new file mode 100644 index 0000000000..7725615aa2 --- /dev/null +++ b/packages/cli/src/ui/components/shared/__snapshots__/MaxSizedBox.test.tsx.snap @@ -0,0 +1,71 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > accounts for additionalHiddenLinesCount 1`] = ` +"... first 7 lines hidden ... +Line 3" +`; + +exports[` > clips a long single text child from the bottom 1`] = ` +"Line 1 +Line 2 +Line 3 +Line 4 +Line 5 +Line 6 +Line 7 +Line 8 +Line 9 +... last 21 lines hidden ..." +`; + +exports[` > clips a long single text child from the top 1`] = ` +"... first 21 lines hidden ... +Line 22 +Line 23 +Line 24 +Line 25 +Line 26 +Line 27 +Line 28 +Line 29 +Line 30" +`; + +exports[` > does not truncate when maxHeight is undefined 1`] = ` +"Line 1 +Line 2" +`; + +exports[` > handles React.Fragment as a child 1`] = ` +"Line 1 from Fragment +Line 2 from Fragment +Line 3 direct child" +`; + +exports[` > hides lines at the end when content exceeds maxHeight and overflowDirection is bottom 1`] = ` +"Line 1 +... last 2 lines hidden ..." +`; + +exports[` > hides lines when content exceeds maxHeight 1`] = ` +"... first 2 lines hidden ... +Line 3" +`; + +exports[` > renders children without truncation when they fit 1`] = `"Hello, World!"`; + +exports[` > shows plural "lines" when more than one line is hidden 1`] = ` +"... first 2 lines hidden ... +Line 3" +`; + +exports[` > shows singular "line" when exactly one line is hidden 1`] = ` +"... first 1 line hidden ... +Line 1" +`; + +exports[` > wraps text that exceeds maxWidth 1`] = ` +"This is a +long line +of text" +`; diff --git a/packages/cli/src/ui/utils/CodeColorizer.tsx b/packages/cli/src/ui/utils/CodeColorizer.tsx index ae05eb8ea2..75571883f4 100644 --- a/packages/cli/src/ui/utils/CodeColorizer.tsx +++ b/packages/cli/src/ui/utils/CodeColorizer.tsx @@ -178,17 +178,8 @@ export function colorizeCode({ ); return ( - - {/* We have to render line numbers differently depending on whether we are using MaxSizeBox or not */} - {showLineNumbers && useMaxSizedBox && ( - - {`${String(index + 1 + hiddenLinesCount).padStart( - padWidth, - ' ', - )} `} - - )} - {showLineNumbers && !useMaxSizedBox && ( + + {showLineNumbers && ( ( - - {/* We have to render line numbers differently depending on whether we are using MaxSizeBox or not */} - {showLineNumbers && useMaxSizedBox && ( - - {`${String(index + 1).padStart(padWidth, ' ')} `} - - )} - {showLineNumbers && !useMaxSizedBox && ( + + {showLineNumbers && ( Date: Wed, 14 Jan 2026 04:49:17 +0000 Subject: [PATCH 172/713] Behavioral evals framework. (#16047) --- .github/workflows/chained_e2e.yml | 35 +- .github/workflows/evals-nightly.yml | 41 + .gitignore | 1 + eslint.config.js | 2 + evals/README.md | 102 ++ evals/save_memory.eval.ts | 31 + evals/test-helper.ts | 70 ++ evals/vitest.config.ts | 15 + integration-tests/save_memory.test.ts | 54 -- integration-tests/test-helper.ts | 1223 +----------------------- package-lock.json | 180 +--- package.json | 2 + packages/test-utils/package.json | 6 + packages/test-utils/src/index.ts | 1 + packages/test-utils/src/test-rig.ts | 1227 +++++++++++++++++++++++++ 15 files changed, 1577 insertions(+), 1413 deletions(-) create mode 100644 .github/workflows/evals-nightly.yml create mode 100644 evals/README.md create mode 100644 evals/save_memory.eval.ts create mode 100644 evals/test-helper.ts create mode 100644 evals/vitest.config.ts delete mode 100644 integration-tests/save_memory.test.ts create mode 100644 packages/test-utils/src/test-rig.ts diff --git a/.github/workflows/chained_e2e.yml b/.github/workflows/chained_e2e.yml index 494163966e..487225d452 100644 --- a/.github/workflows/chained_e2e.yml +++ b/.github/workflows/chained_e2e.yml @@ -277,6 +277,37 @@ jobs: shell: 'pwsh' run: 'npm run test:integration:sandbox:none' + evals: + name: 'Evals (ALWAYS_PASSING)' + needs: + - 'merge_queue_skipper' + - 'parse_run_context' + runs-on: 'gemini-cli-ubuntu-16-core' + if: | + always() && (needs.merge_queue_skipper.result !='success' || needs.merge_queue_skipper.outputs.skip != 'true') + steps: + - name: 'Checkout' + uses: 'actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955' # ratchet:actions/checkout@v5 + with: + ref: '${{ needs.parse_run_context.outputs.sha }}' + repository: '${{ needs.parse_run_context.outputs.repository }}' + + - name: 'Set up Node.js 20.x' + uses: 'actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020' # ratchet:actions-node@v4 + with: + node-version: '20.x' + + - name: 'Install dependencies' + run: 'npm ci' + + - name: 'Build project' + run: 'npm run build' + + - name: 'Run Evals (Required to pass)' + env: + GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}' + run: 'npm run test:always_passing_evals' + e2e: name: 'E2E' if: | @@ -284,13 +315,15 @@ jobs: needs: - 'e2e_linux' - 'e2e_mac' + - 'evals' - 'merge_queue_skipper' runs-on: 'gemini-cli-ubuntu-16-core' steps: - name: 'Check E2E test results' run: | if [[ ${{ needs.e2e_linux.result }} != 'success' || \ - ${{ needs.e2e_mac.result }} != 'success' ]]; then + ${{ needs.e2e_mac.result }} != 'success' || \ + ${{ needs.evals.result }} != 'success' ]]; then echo "One or more E2E jobs failed." exit 1 fi diff --git a/.github/workflows/evals-nightly.yml b/.github/workflows/evals-nightly.yml new file mode 100644 index 0000000000..6d44de7c12 --- /dev/null +++ b/.github/workflows/evals-nightly.yml @@ -0,0 +1,41 @@ +name: 'Evals: Nightly' + +on: + schedule: + - cron: '0 1 * * *' # Runs at 1 AM every day + workflow_dispatch: + inputs: + run_all: + description: 'Run all evaluations (including usually passing)' + type: 'boolean' + default: true + +permissions: + contents: 'read' + checks: 'write' + +jobs: + evals: + name: 'Evals (USUALLY_PASSING) nightly run' + runs-on: 'gemini-cli-ubuntu-16-core' + steps: + - name: 'Checkout' + uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 + + - name: 'Set up Node.js' + uses: 'actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020' # ratchet:actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - name: 'Install dependencies' + run: 'npm ci' + + - name: 'Build project' + run: 'npm run build' + + - name: 'Run Evals' + env: + GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}' + RUN_EVALS: "${{ github.event.inputs.run_all != 'false' }}" + run: 'npm run test:all_evals' diff --git a/.gitignore b/.gitignore index bfb2b5e576..5128952039 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,4 @@ patch_output.log .genkit .gemini-clipboard/ .eslintcache +evals/logs/ diff --git a/eslint.config.js b/eslint.config.js index c2d0d3b69b..0f20eeab42 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -35,6 +35,8 @@ export default tseslint.config( 'package/bundle/**', '.integration-tests/**', 'dist/**', + 'evals/**', + 'packages/test-utils/**', ], }, eslint.configs.recommended, diff --git a/evals/README.md b/evals/README.md new file mode 100644 index 0000000000..a339af842f --- /dev/null +++ b/evals/README.md @@ -0,0 +1,102 @@ +# Behavioral Evals + +Behavioral evaluations (evals) are tests designed to validate the agent's +behavior in response to specific prompts. They serve as a critical feedback loop +for changes to system prompts, tool definitions, and other model-steering +mechanisms. + +## Why Behavioral Evals? + +Unlike traditional **integration tests** which verify that the system functions +correctly (e.g., "does the file writer actually write to disk?"), behavioral +evals verify that the model _chooses_ to take the correct action (e.g., "does +the model decide to write to disk when asked to save code?"). + +They are also distinct from broad **industry benchmarks** (like SWE-bench). +While benchmarks measure general capabilities across complex challenges, our +behavioral evals focus on specific, granular behaviors relevant to the Gemini +CLI's features. + +### Key Characteristics + +- **Feedback Loop**: They help us understand how changes to prompts or tools + affect the model's decision-making. + - _Did a change to the system prompt make the model less likely to use tool + X?_ + - _Did a new tool definition confuse the model?_ +- **Regression Testing**: They prevent regressions in model steering. +- **Non-Determinism**: Unlike unit tests, LLM behavior can be non-deterministic. + We distinguish between behaviors that should be robust (`ALWAYS_PASSES`) and + those that are generally reliable but might occasionally vary + (`USUALLY_PASSES`). + +## Creating an Evaluation + +Evaluations are located in the `evals` directory. Each evaluation is a Vitest +test file that uses the `evalTest` function from `evals/test-helper.ts`. + +### `evalTest` + +The `evalTest` function is a helper that runs a single evaluation case. It takes +two arguments: + +1. `policy`: The consistency expectation for this test (`'ALWAYS_PASSES'` or + `'USUALLY_PASSES'`). +2. `evalCase`: An object defining the test case. + +#### Policies + +- `ALWAYS_PASSES`: Tests expected to pass 100% of the time. These are typically + trivial and test basic functionality. These run in every CI. +- `USUALLY_PASSES`: Tests expected to pass most of the time but may have some + flakiness due to non-deterministic behaviors. These are run nightly and used + to track the health of the product from build to build. + +#### `EvalCase` Properties + +- `name`: The name of the evaluation case. +- `prompt`: The prompt to send to the model. +- `params`: An optional object with parameters to pass to the test rig (e.g., + settings). +- `assert`: An async function that takes the test rig and the result of the run + and asserts that the result is correct. +- `log`: An optional boolean that, if set to `true`, will log the tool calls to + a file in the `evals/logs` directory. + +### Example + +```typescript +import { describe, expect } from 'vitest'; +import { evalTest } from './test-helper.js'; + +describe('my_feature', () => { + evalTest('ALWAYS_PASSES', { + name: 'should do something', + prompt: 'do it', + assert: async (rig, result) => { + // assertions + }, + }); +}); +``` + +## Running Evaluations + +### Always Passing Evals + +To run the evaluations that are expected to always pass (CI safe): + +```bash +npm run test:always_passing_evals +``` + +### All Evals + +To run all evaluations, including those that may be flaky ("usually passes"): + +```bash +npm run test:all_evals +``` + +This command sets the `RUN_EVALS` environment variable to `1`, which enables the +`USUALLY_PASSES` tests. diff --git a/evals/save_memory.eval.ts b/evals/save_memory.eval.ts new file mode 100644 index 0000000000..a64f21798a --- /dev/null +++ b/evals/save_memory.eval.ts @@ -0,0 +1,31 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, expect } from 'vitest'; +import { evalTest } from './test-helper.js'; +import { validateModelOutput } from '../integration-tests/test-helper.js'; + +describe('save_memory', () => { + evalTest('ALWAYS_PASSES', { + name: 'should be able to save to memory', + log: true, + params: { + settings: { tools: { core: ['save_memory'] } }, + }, + prompt: `remember that my favorite color is blue. + + what is my favorite color? tell me that and surround it with $ symbol`, + assert: async (rig, result) => { + const foundToolCall = await rig.waitForToolCall('save_memory'); + expect( + foundToolCall, + 'Expected to find a save_memory tool call', + ).toBeTruthy(); + + validateModelOutput(result, 'blue', 'Save memory test'); + }, + }); +}); diff --git a/evals/test-helper.ts b/evals/test-helper.ts new file mode 100644 index 0000000000..f394521d1e --- /dev/null +++ b/evals/test-helper.ts @@ -0,0 +1,70 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { it } from 'vitest'; +import fs from 'node:fs'; +import { TestRig } from '@google/gemini-cli-test-utils'; + +export * from '@google/gemini-cli-test-utils'; + +// Indicates the consistency expectation for this test. +// - ALWAYS_PASSES - Means that the test is expected to pass 100% of the time. These +// These tests are typically trivial and test basic functionality with unambiguous +// prompts. For example: "call save_memory to remember foo" should be fairly reliable. +// These are the first line of defense against regressions in key behaviors and run in +// every CI. You can run these locally with 'npm run test:always_passing_evals'. +// +// - USUALLY_PASSES - Means that the test is expected to pass most of the time but +// may have some flakiness as a result of relying on non-deterministic prompted +// behaviors and/or ambiguous prompts or complex tasks. +// For example: "Please do build changes until the very end" --> ambiguous whether +// the agent should add to memory without more explicit system prompt or user +// instructions. There are many more of these tests and they may pass less consistently. +// The pass/fail trendline of this set of tests can be used as a general measure +// of product quality. You can run these locally with 'npm run test:all_evals'. +// This may take a really long time and is not recommended. +export type EvalPolicy = 'ALWAYS_PASSES' | 'USUALLY_PASSES'; + +export function evalTest(policy: EvalPolicy, evalCase: EvalCase) { + const fn = async () => { + const rig = new TestRig(); + try { + await rig.setup(evalCase.name, evalCase.params); + const result = await rig.run({ args: evalCase.prompt }); + await evalCase.assert(rig, result); + } finally { + if (evalCase.log) { + await logToFile( + evalCase.name, + JSON.stringify(rig.readToolLogs(), null, 2), + ); + } + await rig.cleanup(); + } + }; + + if (policy === 'USUALLY_PASSES' && !process.env.RUN_EVALS) { + it.skip(evalCase.name, fn); + } else { + it(evalCase.name, fn); + } +} + +export interface EvalCase { + name: string; + params?: Record; + prompt: string; + assert: (rig: TestRig, result: string) => Promise; + log?: boolean; +} + +async function logToFile(name: string, content: string) { + const logDir = 'evals/logs'; + await fs.promises.mkdir(logDir, { recursive: true }); + const sanitizedName = name.replace(/[^a-z0-9]/gi, '_').toLowerCase(); + const logFile = `${logDir}/${sanitizedName}.log`; + await fs.promises.writeFile(logFile, content); +} diff --git a/evals/vitest.config.ts b/evals/vitest.config.ts new file mode 100644 index 0000000000..8476b638ff --- /dev/null +++ b/evals/vitest.config.ts @@ -0,0 +1,15 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + testTimeout: 300000, // 5 minutes + reporters: ['default'], + include: ['**/*.eval.ts'], + }, +}); diff --git a/integration-tests/save_memory.test.ts b/integration-tests/save_memory.test.ts deleted file mode 100644 index 38b4d060fa..0000000000 --- a/integration-tests/save_memory.test.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import { describe, it, expect, beforeEach, afterEach } from 'vitest'; -import { TestRig, printDebugInfo, validateModelOutput } from './test-helper.js'; - -describe('save_memory', () => { - let rig: TestRig; - - beforeEach(() => { - rig = new TestRig(); - }); - - afterEach(async () => await rig.cleanup()); - - it('should be able to save to memory', async () => { - await rig.setup('should be able to save to memory', { - settings: { tools: { core: ['save_memory'] } }, - }); - - const prompt = `remember that my favorite color is blue. - - what is my favorite color? tell me that and surround it with $ symbol`; - const result = await rig.run({ args: prompt }); - - const foundToolCall = await rig.waitForToolCall('save_memory'); - - // Add debugging information - if (!foundToolCall || !result.toLowerCase().includes('blue')) { - const allTools = printDebugInfo(rig, result, { - 'Found tool call': foundToolCall, - 'Contains blue': result.toLowerCase().includes('blue'), - }); - - console.error( - 'Memory tool calls:', - allTools - .filter((t) => t.toolRequest.name === 'save_memory') - .map((t) => t.toolRequest.args), - ); - } - - expect( - foundToolCall, - 'Expected to find a save_memory tool call', - ).toBeTruthy(); - - // Validate model output - will throw if no output, warn if missing expected content - validateModelOutput(result, 'blue', 'Save memory test'); - }); -}); diff --git a/integration-tests/test-helper.ts b/integration-tests/test-helper.ts index 9a2a6cefca..a13f260c4b 100644 --- a/integration-tests/test-helper.ts +++ b/integration-tests/test-helper.ts @@ -4,1225 +4,4 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { expect } from 'vitest'; -import { execSync, spawn, type ChildProcess } from 'node:child_process'; -import { mkdirSync, writeFileSync, readFileSync } from 'node:fs'; -import { join, dirname } from 'node:path'; -import { fileURLToPath } from 'node:url'; -import { env } from 'node:process'; -import { setTimeout as sleep } from 'node:timers/promises'; -import { DEFAULT_GEMINI_MODEL } from '../packages/core/src/config/models.js'; -import fs from 'node:fs'; -import * as pty from '@lydell/node-pty'; -import stripAnsi from 'strip-ansi'; -import * as os from 'node:os'; -import { GEMINI_DIR } from '../packages/core/src/utils/paths.js'; - -const __dirname = dirname(fileURLToPath(import.meta.url)); -const BUNDLE_PATH = join(__dirname, '..', 'bundle/gemini.js'); - -// Get timeout based on environment -function getDefaultTimeout() { - if (env['CI']) return 60000; // 1 minute in CI - if (env['GEMINI_SANDBOX']) return 30000; // 30s in containers - return 15000; // 15s locally -} - -export async function poll( - predicate: () => boolean, - timeout: number, - interval: number, -): Promise { - const startTime = Date.now(); - let attempts = 0; - while (Date.now() - startTime < timeout) { - attempts++; - const result = predicate(); - if (env['VERBOSE'] === 'true' && attempts % 5 === 0) { - console.log( - `Poll attempt ${attempts}: ${result ? 'success' : 'waiting...'}`, - ); - } - if (result) { - return true; - } - await sleep(interval); - } - if (env['VERBOSE'] === 'true') { - console.log(`Poll timed out after ${attempts} attempts`); - } - return false; -} - -function sanitizeTestName(name: string) { - return name - .toLowerCase() - .replace(/[^a-z0-9]/g, '-') - .replace(/-+/g, '-'); -} - -// Helper to create detailed error messages -export function createToolCallErrorMessage( - expectedTools: string | string[], - foundTools: string[], - result: string, -) { - const expectedStr = Array.isArray(expectedTools) - ? expectedTools.join(' or ') - : expectedTools; - return ( - `Expected to find ${expectedStr} tool call(s). ` + - `Found: ${foundTools.length > 0 ? foundTools.join(', ') : 'none'}. ` + - `Output preview: ${result ? result.substring(0, 200) + '...' : 'no output'}` - ); -} - -// Helper to print debug information when tests fail -export function printDebugInfo( - rig: TestRig, - result: string, - context: Record = {}, -) { - console.error('Test failed - Debug info:'); - console.error('Result length:', result.length); - console.error('Result (first 500 chars):', result.substring(0, 500)); - console.error( - 'Result (last 500 chars):', - result.substring(result.length - 500), - ); - - // Print any additional context provided - Object.entries(context).forEach(([key, value]) => { - console.error(`${key}:`, value); - }); - - // Check what tools were actually called - const allTools = rig.readToolLogs(); - console.error( - 'All tool calls found:', - allTools.map((t) => t.toolRequest.name), - ); - - return allTools; -} - -// Helper to validate model output and warn about unexpected content -export function validateModelOutput( - result: string, - expectedContent: string | (string | RegExp)[] | null = null, - testName = '', -) { - // First, check if there's any output at all (this should fail the test if missing) - if (!result || result.trim().length === 0) { - throw new Error('Expected LLM to return some output'); - } - - // If expectedContent is provided, check for it and warn if missing - if (expectedContent) { - const contents = Array.isArray(expectedContent) - ? expectedContent - : [expectedContent]; - const missingContent = contents.filter((content) => { - if (typeof content === 'string') { - return !result.toLowerCase().includes(content.toLowerCase()); - } else if (content instanceof RegExp) { - return !content.test(result); - } - return false; - }); - - if (missingContent.length > 0) { - console.warn( - `Warning: LLM did not include expected content in response: ${missingContent.join( - ', ', - )}.`, - 'This is not ideal but not a test failure.', - ); - console.warn( - 'The tool was called successfully, which is the main requirement.', - ); - console.warn('Expected content:', expectedContent); - console.warn('Actual output:', result); - return false; - } else if (env['VERBOSE'] === 'true') { - console.log(`${testName}: Model output validated successfully.`); - } - return true; - } - - return true; -} - -interface ParsedLog { - attributes?: { - 'event.name'?: string; - function_name?: string; - function_args?: string; - success?: boolean; - duration_ms?: number; - request_text?: string; - hook_event_name?: string; - hook_name?: string; - hook_input?: Record; - hook_output?: Record; - exit_code?: number; - stdout?: string; - stderr?: string; - error?: string; - }; - scopeMetrics?: { - metrics: { - descriptor: { - name: string; - }; - }[]; - }[]; -} - -export class InteractiveRun { - ptyProcess: pty.IPty; - public output = ''; - - constructor(ptyProcess: pty.IPty) { - this.ptyProcess = ptyProcess; - ptyProcess.onData((data) => { - this.output += data; - if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { - process.stdout.write(data); - } - }); - } - - async expectText(text: string, timeout?: number) { - if (!timeout) { - timeout = getDefaultTimeout(); - } - await poll( - () => stripAnsi(this.output).toLowerCase().includes(text.toLowerCase()), - timeout, - 200, - ); - expect(stripAnsi(this.output).toLowerCase()).toContain(text.toLowerCase()); - } - - // This types slowly to make sure command is correct, but only work for short - // commands that are not multi-line, use sendKeys to type long prompts - async type(text: string) { - let typedSoFar = ''; - for (const char of text) { - if (char === '\r') { - // wait >30ms before `enter` to avoid fast return conversion - // from bufferFastReturn() in KeypressContent.tsx - await sleep(50); - } - - this.ptyProcess.write(char); - typedSoFar += char; - - // Wait for the typed sequence so far to be echoed back. - const found = await poll( - () => stripAnsi(this.output).includes(typedSoFar), - 5000, // 5s timeout per character (generous for CI) - 10, // check frequently - ); - - if (!found) { - throw new Error( - `Timed out waiting for typed text to appear in output: "${typedSoFar}".\nStripped output:\n${stripAnsi( - this.output, - )}`, - ); - } - } - } - - // Types an entire string at once, necessary for some things like commands - // but may run into paste detection issues for larger strings. - async sendText(text: string) { - this.ptyProcess.write(text); - await sleep(5); - } - - // Simulates typing a string one character at a time to avoid paste detection. - async sendKeys(text: string) { - const delay = 5; - for (const char of text) { - this.ptyProcess.write(char); - await sleep(delay); - } - } - - async kill() { - this.ptyProcess.kill(); - } - - expectExit(): Promise { - return new Promise((resolve, reject) => { - const timer = setTimeout( - () => - reject( - new Error(`Test timed out: process did not exit within a minute.`), - ), - 60000, - ); - this.ptyProcess.onExit(({ exitCode }) => { - clearTimeout(timer); - resolve(exitCode); - }); - }); - } -} - -export class TestRig { - testDir: string | null = null; - homeDir: string | null = null; - testName?: string; - _lastRunStdout?: string; - // Path to the copied fake responses file for this test. - fakeResponsesPath?: string; - // Original fake responses file path for rewriting goldens in record mode. - originalFakeResponsesPath?: string; - private _interactiveRuns: InteractiveRun[] = []; - private _spawnedProcesses: ChildProcess[] = []; - - setup( - testName: string, - options: { - settings?: Record; - fakeResponsesPath?: string; - } = {}, - ) { - this.testName = testName; - const sanitizedName = sanitizeTestName(testName); - const testFileDir = - env['INTEGRATION_TEST_FILE_DIR'] || join(os.tmpdir(), 'gemini-cli-tests'); - this.testDir = join(testFileDir, sanitizedName); - this.homeDir = join(testFileDir, sanitizedName + '-home'); - mkdirSync(this.testDir, { recursive: true }); - mkdirSync(this.homeDir, { recursive: true }); - if (options.fakeResponsesPath) { - this.fakeResponsesPath = join(this.testDir, 'fake-responses.json'); - this.originalFakeResponsesPath = options.fakeResponsesPath; - if (process.env['REGENERATE_MODEL_GOLDENS'] !== 'true') { - fs.copyFileSync(options.fakeResponsesPath, this.fakeResponsesPath); - } - } - - // Create a settings file to point the CLI to the local collector - this._createSettingsFile(options.settings); - } - - private _createSettingsFile(overrideSettings?: Record) { - const projectGeminiDir = join(this.testDir!, GEMINI_DIR); - mkdirSync(projectGeminiDir, { recursive: true }); - - // In sandbox mode, use an absolute path for telemetry inside the container - // The container mounts the test directory at the same path as the host - const telemetryPath = join(this.homeDir!, 'telemetry.log'); // Always use home directory for telemetry - - const settings = { - general: { - // Nightly releases sometimes becomes out of sync with local code and - // triggers auto-update, which causes tests to fail. - disableAutoUpdate: true, - previewFeatures: false, - }, - telemetry: { - enabled: true, - target: 'local', - otlpEndpoint: '', - outfile: telemetryPath, - }, - security: { - auth: { - selectedType: 'gemini-api-key', - }, - }, - ui: { - useAlternateBuffer: true, - }, - model: { - name: DEFAULT_GEMINI_MODEL, - }, - sandbox: - env['GEMINI_SANDBOX'] !== 'false' ? env['GEMINI_SANDBOX'] : false, - // Don't show the IDE connection dialog when running from VsCode - ide: { enabled: false, hasSeenNudge: true }, - ...overrideSettings, // Allow tests to override/add settings - }; - writeFileSync( - join(projectGeminiDir, 'settings.json'), - JSON.stringify(settings, null, 2), - ); - } - - createFile(fileName: string, content: string) { - const filePath = join(this.testDir!, fileName); - writeFileSync(filePath, content); - return filePath; - } - - mkdir(dir: string) { - mkdirSync(join(this.testDir!, dir), { recursive: true }); - } - - sync() { - if (os.platform() === 'win32') return; - // ensure file system is done before spawning - execSync('sync', { cwd: this.testDir! }); - } - - /** - * The command and args to use to invoke Gemini CLI. Allows us to switch - * between using the bundled gemini.js (the default) and using the installed - * 'gemini' (used to verify npm bundles). - */ - private _getCommandAndArgs(extraInitialArgs: string[] = []): { - command: string; - initialArgs: string[]; - } { - const isNpmReleaseTest = - env['INTEGRATION_TEST_USE_INSTALLED_GEMINI'] === 'true'; - const command = isNpmReleaseTest ? 'gemini' : 'node'; - const initialArgs = isNpmReleaseTest - ? extraInitialArgs - : [BUNDLE_PATH, ...extraInitialArgs]; - if (this.fakeResponsesPath) { - if (process.env['REGENERATE_MODEL_GOLDENS'] === 'true') { - initialArgs.push('--record-responses', this.fakeResponsesPath); - } else { - initialArgs.push('--fake-responses', this.fakeResponsesPath); - } - } - return { command, initialArgs }; - } - - run(options: { - args?: string | string[]; - stdin?: string; - stdinDoesNotEnd?: boolean; - yolo?: boolean; - timeout?: number; - env?: Record; - }): Promise { - const yolo = options.yolo !== false; - const { command, initialArgs } = this._getCommandAndArgs( - yolo ? ['--yolo'] : [], - ); - const commandArgs = [...initialArgs]; - const execOptions: { - cwd: string; - encoding: 'utf-8'; - input?: string; - } = { - cwd: this.testDir!, - encoding: 'utf-8', - }; - - if (options.args) { - if (Array.isArray(options.args)) { - commandArgs.push(...options.args); - } else { - commandArgs.push(options.args); - } - } - - if (options.stdin) { - execOptions.input = options.stdin; - } - - const child = spawn(command, commandArgs, { - cwd: this.testDir!, - stdio: 'pipe', - env: { - ...process.env, - GEMINI_CLI_HOME: this.homeDir!, - ...options.env, - }, - }); - this._spawnedProcesses.push(child); - - let stdout = ''; - let stderr = ''; - - // Handle stdin if provided - if (execOptions.input) { - child.stdin!.write(execOptions.input); - } - - if (!options.stdinDoesNotEnd) { - child.stdin!.end(); - } - - child.stdout!.setEncoding('utf8'); - child.stdout!.on('data', (data: string) => { - stdout += data; - if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { - process.stdout.write(data); - } - }); - - child.stderr!.setEncoding('utf8'); - child.stderr!.on('data', (data: string) => { - stderr += data; - if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { - process.stderr.write(data); - } - }); - - const timeout = options.timeout ?? 120000; - const promise = new Promise((resolve, reject) => { - const timer = setTimeout(() => { - child.kill('SIGKILL'); - reject( - new Error( - `Process timed out after ${timeout}ms.\nStdout:\n${stdout}\nStderr:\n${stderr}`, - ), - ); - }, timeout); - - child.on('error', (err) => { - clearTimeout(timer); - reject(err); - }); - - child.on('close', (code: number) => { - clearTimeout(timer); - if (code === 0) { - // Store the raw stdout for Podman telemetry parsing - this._lastRunStdout = stdout; - - // Filter out telemetry output when running with Podman - const result = this._filterPodmanTelemetry(stdout); - - // Check if this is a JSON output test - if so, don't include stderr - // as it would corrupt the JSON - const isJsonOutput = - commandArgs.includes('--output-format') && - commandArgs.includes('json'); - - // If we have stderr output and it's not a JSON test, include that also - const finalResult = - stderr && !isJsonOutput - ? `${result}\n\nStdErr:\n${stderr}` - : result; - - resolve(finalResult); - } else { - reject(new Error(`Process exited with code ${code}:\n${stderr}`)); - } - }); - }); - - return promise; - } - - private _filterPodmanTelemetry(stdout: string): string { - if (env['GEMINI_SANDBOX'] !== 'podman') { - return stdout; - } - - // Remove telemetry JSON objects from output - // They are multi-line JSON objects that start with { and contain telemetry fields - const lines = stdout.split(os.EOL); - const filteredLines = []; - let inTelemetryObject = false; - let braceDepth = 0; - - for (const line of lines) { - if (!inTelemetryObject && line.trim() === '{') { - // Check if this might be start of telemetry object - inTelemetryObject = true; - braceDepth = 1; - } else if (inTelemetryObject) { - // Count braces to track nesting - for (const char of line) { - if (char === '{') braceDepth++; - else if (char === '}') braceDepth--; - } - - // Check if we've closed all braces - if (braceDepth === 0) { - inTelemetryObject = false; - // Skip this line (the closing brace) - continue; - } - } else { - // Not in telemetry object, keep the line - filteredLines.push(line); - } - } - - return filteredLines.join('\n'); - } - - runCommand( - args: string[], - options: { - stdin?: string; - timeout?: number; - env?: Record; - } = {}, - ): Promise { - const { command, initialArgs } = this._getCommandAndArgs(); - const commandArgs = [...initialArgs, ...args]; - - const child = spawn(command, commandArgs, { - cwd: this.testDir!, - stdio: 'pipe', - env: { - ...process.env, - GEMINI_CLI_HOME: this.homeDir!, - ...options.env, - }, - }); - this._spawnedProcesses.push(child); - - let stdout = ''; - let stderr = ''; - - if (options.stdin) { - child.stdin!.write(options.stdin); - child.stdin!.end(); - } - - child.stdout!.setEncoding('utf8'); - child.stdout!.on('data', (data: string) => { - stdout += data; - if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { - process.stdout.write(data); - } - }); - - child.stderr!.setEncoding('utf8'); - child.stderr!.on('data', (data: string) => { - stderr += data; - if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { - process.stderr.write(data); - } - }); - - const timeout = options.timeout ?? 120000; - const promise = new Promise((resolve, reject) => { - const timer = setTimeout(() => { - child.kill('SIGKILL'); - reject( - new Error( - `Process timed out after ${timeout}ms.\nStdout:\n${stdout}\nStderr:\n${stderr}`, - ), - ); - }, timeout); - - child.on('error', (err) => { - clearTimeout(timer); - reject(err); - }); - - child.on('close', (code: number) => { - clearTimeout(timer); - if (code === 0) { - this._lastRunStdout = stdout; - const result = this._filterPodmanTelemetry(stdout); - - // Check if this is a JSON output test - if so, don't include stderr - // as it would corrupt the JSON - const isJsonOutput = - commandArgs.includes('--output-format') && - commandArgs.includes('json'); - - const finalResult = - stderr && !isJsonOutput - ? `${result}\n\nStdErr:\n${stderr}` - : result; - resolve(finalResult); - } else { - reject(new Error(`Process exited with code ${code}:\n${stderr}`)); - } - }); - }); - - return promise; - } - - readFile(fileName: string) { - const filePath = join(this.testDir!, fileName); - const content = readFileSync(filePath, 'utf-8'); - if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { - console.log(`--- FILE: ${filePath} ---`); - console.log(content); - console.log(`--- END FILE: ${filePath} ---`); - } - return content; - } - - async cleanup() { - // Kill any interactive runs that are still active - for (const run of this._interactiveRuns) { - try { - await run.kill(); - } catch (error) { - if (env['VERBOSE'] === 'true') { - console.warn('Failed to kill interactive run during cleanup:', error); - } - } - } - this._interactiveRuns = []; - - // Kill any other spawned processes that are still running - for (const child of this._spawnedProcesses) { - if (child.exitCode === null && child.signalCode === null) { - try { - child.kill('SIGKILL'); - } catch (error) { - if (env['VERBOSE'] === 'true') { - console.warn( - 'Failed to kill spawned process during cleanup:', - error, - ); - } - } - } - } - this._spawnedProcesses = []; - - if ( - process.env['REGENERATE_MODEL_GOLDENS'] === 'true' && - this.fakeResponsesPath - ) { - fs.copyFileSync(this.fakeResponsesPath, this.originalFakeResponsesPath!); - } - // Clean up test directory and home directory - if (this.testDir && !env['KEEP_OUTPUT']) { - try { - fs.rmSync(this.testDir, { recursive: true, force: true }); - } catch (error) { - // Ignore cleanup errors - if (env['VERBOSE'] === 'true') { - console.warn('Cleanup warning:', (error as Error).message); - } - } - } - if (this.homeDir && !env['KEEP_OUTPUT']) { - try { - fs.rmSync(this.homeDir, { recursive: true, force: true }); - } catch (error) { - // Ignore cleanup errors - if (env['VERBOSE'] === 'true') { - console.warn('Cleanup warning:', (error as Error).message); - } - } - } - } - - async waitForTelemetryReady() { - // Telemetry is always written to the test directory - const logFilePath = join(this.homeDir!, 'telemetry.log'); - - if (!logFilePath) return; - - // Wait for telemetry file to exist and have content - await poll( - () => { - if (!fs.existsSync(logFilePath)) return false; - try { - const content = readFileSync(logFilePath, 'utf-8'); - // Check if file has meaningful content (at least one complete JSON object) - return content.includes('"scopeMetrics"'); - } catch { - return false; - } - }, - 2000, // 2 seconds max - reduced since telemetry should flush on exit now - 100, // check every 100ms - ); - } - - async waitForTelemetryEvent(eventName: string, timeout?: number) { - if (!timeout) { - timeout = getDefaultTimeout(); - } - - await this.waitForTelemetryReady(); - - return poll( - () => { - const logs = this._readAndParseTelemetryLog(); - return logs.some( - (logData) => - logData.attributes && - logData.attributes['event.name'] === `gemini_cli.${eventName}`, - ); - }, - timeout, - 100, - ); - } - - async waitForToolCall( - toolName: string, - timeout?: number, - matchArgs?: (args: string) => boolean, - ) { - // Use environment-specific timeout - if (!timeout) { - timeout = getDefaultTimeout(); - } - - // Wait for telemetry to be ready before polling for tool calls - await this.waitForTelemetryReady(); - - return poll( - () => { - const toolLogs = this.readToolLogs(); - return toolLogs.some( - (log) => - log.toolRequest.name === toolName && - (matchArgs?.call(this, log.toolRequest.args) ?? true), - ); - }, - timeout, - 100, - ); - } - - async expectToolCallSuccess( - toolNames: string[], - timeout?: number, - matchArgs?: (args: string) => boolean, - ) { - // Use environment-specific timeout - if (!timeout) { - timeout = getDefaultTimeout(); - } - - // Wait for telemetry to be ready before polling for tool calls - await this.waitForTelemetryReady(); - - const success = await poll( - () => { - const toolLogs = this.readToolLogs(); - return toolNames.some((name) => - toolLogs.some( - (log) => - log.toolRequest.name === name && - log.toolRequest.success && - (matchArgs?.call(this, log.toolRequest.args) ?? true), - ), - ); - }, - timeout, - 100, - ); - - expect( - success, - `Expected to find successful toolCalls for ${JSON.stringify(toolNames)}`, - ).toBe(true); - } - - async waitForAnyToolCall(toolNames: string[], timeout?: number) { - if (!timeout) { - timeout = getDefaultTimeout(); - } - - // Wait for telemetry to be ready before polling for tool calls - await this.waitForTelemetryReady(); - - return poll( - () => { - const toolLogs = this.readToolLogs(); - return toolNames.some((name) => - toolLogs.some((log) => log.toolRequest.name === name), - ); - }, - timeout, - 100, - ); - } - - _parseToolLogsFromStdout(stdout: string) { - const logs: { - timestamp: number; - toolRequest: { - name: string; - args: string; - success: boolean; - duration_ms: number; - }; - }[] = []; - - // The console output from Podman is JavaScript object notation, not JSON - // Look for tool call events in the output - // Updated regex to handle tool names with hyphens and underscores - const toolCallPattern = - /body:\s*'Tool call:\s*([\w-]+)\..*?Success:\s*(\w+)\..*?Duration:\s*(\d+)ms\.'/g; - const matches = [...stdout.matchAll(toolCallPattern)]; - - for (const match of matches) { - const toolName = match[1]; - const success = match[2] === 'true'; - const duration = parseInt(match[3], 10); - - // Try to find function_args nearby - const matchIndex = match.index || 0; - const contextStart = Math.max(0, matchIndex - 500); - const contextEnd = Math.min(stdout.length, matchIndex + 500); - const context = stdout.substring(contextStart, contextEnd); - - // Look for function_args in the context - let args = '{}'; - const argsMatch = context.match(/function_args:\s*'([^']+)'/); - if (argsMatch) { - args = argsMatch[1]; - } - - // Also try to find function_name to double-check - // Updated regex to handle tool names with hyphens and underscores - const nameMatch = context.match(/function_name:\s*'([\w-]+)'/); - const actualToolName = nameMatch ? nameMatch[1] : toolName; - - logs.push({ - timestamp: Date.now(), - toolRequest: { - name: actualToolName, - args: args, - success: success, - duration_ms: duration, - }, - }); - } - - // If no matches found with the simple pattern, try the JSON parsing approach - // in case the format changes - if (logs.length === 0) { - const lines = stdout.split(os.EOL); - let currentObject = ''; - let inObject = false; - let braceDepth = 0; - - for (const line of lines) { - if (!inObject && line.trim() === '{') { - inObject = true; - braceDepth = 1; - currentObject = line + '\n'; - } else if (inObject) { - currentObject += line + '\n'; - - // Count braces - for (const char of line) { - if (char === '{') braceDepth++; - else if (char === '}') braceDepth--; - } - - // If we've closed all braces, try to parse the object - if (braceDepth === 0) { - inObject = false; - try { - const obj = JSON.parse(currentObject); - - // Check for tool call in different formats - if ( - obj.body && - obj.body.includes('Tool call:') && - obj.attributes - ) { - const bodyMatch = obj.body.match(/Tool call: (\w+)\./); - if (bodyMatch) { - logs.push({ - timestamp: obj.timestamp || Date.now(), - toolRequest: { - name: bodyMatch[1], - args: obj.attributes.function_args || '{}', - success: obj.attributes.success !== false, - duration_ms: obj.attributes.duration_ms || 0, - }, - }); - } - } else if ( - obj.attributes && - obj.attributes['event.name'] === 'gemini_cli.tool_call' - ) { - logs.push({ - timestamp: obj.attributes['event.timestamp'], - toolRequest: { - name: obj.attributes.function_name, - args: obj.attributes.function_args, - success: obj.attributes.success, - duration_ms: obj.attributes.duration_ms, - }, - }); - } - } catch { - // Not valid JSON - } - currentObject = ''; - } - } - } - } - - return logs; - } - - private _readAndParseTelemetryLog(): ParsedLog[] { - // Telemetry is always written to the test directory - const logFilePath = join(this.homeDir!, 'telemetry.log'); - - if (!logFilePath || !fs.existsSync(logFilePath)) { - return []; - } - - const content = readFileSync(logFilePath, 'utf-8'); - - // Split the content into individual JSON objects - // They are separated by "}\n{" - const jsonObjects = content - .split(/}\n{/) - .map((obj, index, array) => { - // Add back the braces we removed during split - if (index > 0) obj = '{' + obj; - if (index < array.length - 1) obj = obj + '}'; - return obj.trim(); - }) - .filter((obj) => obj); - - const logs: ParsedLog[] = []; - - for (const jsonStr of jsonObjects) { - try { - const logData = JSON.parse(jsonStr); - logs.push(logData); - } catch (e) { - // Skip objects that aren't valid JSON - if (env['VERBOSE'] === 'true') { - console.error('Failed to parse telemetry object:', e); - } - } - } - - return logs; - } - - readToolLogs() { - // For Podman, first check if telemetry file exists and has content - // If not, fall back to parsing from stdout - if (env['GEMINI_SANDBOX'] === 'podman') { - // Try reading from file first - const logFilePath = join(this.homeDir!, 'telemetry.log'); - - if (fs.existsSync(logFilePath)) { - try { - const content = readFileSync(logFilePath, 'utf-8'); - if (content && content.includes('"event.name"')) { - // File has content, use normal file parsing - // Continue to the normal file parsing logic below - } else if (this._lastRunStdout) { - // File exists but is empty or doesn't have events, parse from stdout - return this._parseToolLogsFromStdout(this._lastRunStdout); - } - } catch { - // Error reading file, fall back to stdout - if (this._lastRunStdout) { - return this._parseToolLogsFromStdout(this._lastRunStdout); - } - } - } else if (this._lastRunStdout) { - // No file exists, parse from stdout - return this._parseToolLogsFromStdout(this._lastRunStdout); - } - } - - const parsedLogs = this._readAndParseTelemetryLog(); - const logs: { - toolRequest: { - name: string; - args: string; - success: boolean; - duration_ms: number; - }; - }[] = []; - - for (const logData of parsedLogs) { - // Look for tool call logs - if ( - logData.attributes && - logData.attributes['event.name'] === 'gemini_cli.tool_call' - ) { - const toolName = logData.attributes.function_name!; - logs.push({ - toolRequest: { - name: toolName, - args: logData.attributes.function_args ?? '{}', - success: logData.attributes.success ?? false, - duration_ms: logData.attributes.duration_ms ?? 0, - }, - }); - } - } - - return logs; - } - - readAllApiRequest(): ParsedLog[] { - const logs = this._readAndParseTelemetryLog(); - const apiRequests = logs.filter( - (logData) => - logData.attributes && - logData.attributes['event.name'] === `gemini_cli.api_request`, - ); - return apiRequests; - } - - readLastApiRequest(): ParsedLog | null { - const logs = this._readAndParseTelemetryLog(); - const apiRequests = logs.filter( - (logData) => - logData.attributes && - logData.attributes['event.name'] === `gemini_cli.api_request`, - ); - return apiRequests.pop() || null; - } - - async waitForMetric(metricName: string, timeout?: number) { - await this.waitForTelemetryReady(); - - const fullName = metricName.startsWith('gemini_cli.') - ? metricName - : `gemini_cli.${metricName}`; - - return poll( - () => { - const logs = this._readAndParseTelemetryLog(); - for (const logData of logs) { - if (logData.scopeMetrics) { - for (const scopeMetric of logData.scopeMetrics) { - for (const metric of scopeMetric.metrics) { - if (metric.descriptor.name === fullName) { - return true; - } - } - } - } - } - return false; - }, - timeout ?? getDefaultTimeout(), - 100, - ); - } - - readMetric(metricName: string): Record | null { - const logs = this._readAndParseTelemetryLog(); - for (const logData of logs) { - if (logData.scopeMetrics) { - for (const scopeMetric of logData.scopeMetrics) { - for (const metric of scopeMetric.metrics) { - if (metric.descriptor.name === `gemini_cli.${metricName}`) { - return metric; - } - } - } - } - } - return null; - } - - async runInteractive(options?: { - args?: string | string[]; - yolo?: boolean; - env?: Record; - }): Promise { - const yolo = options?.yolo !== false; - const { command, initialArgs } = this._getCommandAndArgs( - yolo ? ['--yolo'] : [], - ); - const commandArgs = [...initialArgs]; - - const envVars = { - ...process.env, - GEMINI_CLI_HOME: this.homeDir!, - ...options?.env, - }; - - const ptyOptions: pty.IPtyForkOptions = { - name: 'xterm-color', - cols: 80, - rows: 80, - cwd: this.testDir!, - env: Object.fromEntries( - Object.entries(envVars).filter(([, v]) => v !== undefined), - ) as { [key: string]: string }, - }; - - const executable = command === 'node' ? process.execPath : command; - const ptyProcess = pty.spawn(executable, commandArgs, ptyOptions); - - const run = new InteractiveRun(ptyProcess); - this._interactiveRuns.push(run); - // Wait for the app to be ready - await run.expectText(' Type your message or @path/to/file', 30000); - return run; - } - - readHookLogs() { - const parsedLogs = this._readAndParseTelemetryLog(); - const logs: { - hookCall: { - hook_event_name: string; - hook_name: string; - hook_input: Record; - hook_output: Record; - exit_code: number; - stdout: string; - stderr: string; - duration_ms: number; - success: boolean; - error: string; - }; - }[] = []; - - for (const logData of parsedLogs) { - // Look for tool call logs - if ( - logData.attributes && - logData.attributes['event.name'] === 'gemini_cli.hook_call' - ) { - logs.push({ - hookCall: { - hook_event_name: logData.attributes.hook_event_name ?? '', - hook_name: logData.attributes.hook_name ?? '', - hook_input: logData.attributes.hook_input ?? {}, - hook_output: logData.attributes.hook_output ?? {}, - exit_code: logData.attributes.exit_code ?? 0, - stdout: logData.attributes.stdout ?? '', - stderr: logData.attributes.stderr ?? '', - duration_ms: logData.attributes.duration_ms ?? 0, - success: logData.attributes.success ?? false, - error: logData.attributes.error ?? '', - }, - }); - } - } - - return logs; - } - - async pollCommand( - commandFn: () => Promise, - predicateFn: () => boolean, - timeout: number = 30000, - interval: number = 1000, - ) { - const startTime = Date.now(); - while (Date.now() - startTime < timeout) { - await commandFn(); - // Give it a moment to process - await sleep(500); - if (predicateFn()) { - return; - } - await sleep(interval); - } - throw new Error(`pollCommand timed out after ${timeout}ms`); - } -} +export * from '@google/gemini-cli-test-utils'; diff --git a/package-lock.json b/package-lock.json index b9f71c339f..7d036d9b96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -522,7 +522,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/@bundled-es-modules/cookie/-/cookie-2.0.1.tgz", "integrity": "sha512-8o+5fRPLNbjbdGRRmJj3h6Hh1AQJf2dk3qQ/5ZFb+PXkRNiSoMGGUKlsgLfrxneb72axVJyIYji64E2+nNfYyw==", - "dev": true, + "devOptional": true, "license": "ISC", "dependencies": { "cookie": "^0.7.2" @@ -532,7 +532,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/@bundled-es-modules/statuses/-/statuses-1.0.1.tgz", "integrity": "sha512-yn7BklA5acgcBr+7w064fGV+SGIFySjCKpqjcWgBAIfrAkY+4GQTJJHQMeT3V/sgz23VTEVV8TtOmkvJAhFVfg==", - "dev": true, + "devOptional": true, "license": "ISC", "dependencies": { "statuses": "^2.0.1" @@ -542,7 +542,7 @@ "version": "0.1.6", "resolved": "https://registry.npmjs.org/@bundled-es-modules/tough-cookie/-/tough-cookie-0.1.6.tgz", "integrity": "sha512-dvMHbL464C0zI+Yqxbz6kZ5TOEp7GLW+pry/RWndAR8MJQAXZ2rPmIs8tziTZjeIyhSNZgZbCePtfSbdWqStJw==", - "dev": true, + "devOptional": true, "license": "ISC", "dependencies": { "@types/tough-cookie": "^4.0.5", @@ -553,7 +553,7 @@ "version": "4.1.4", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.4.tgz", "integrity": "sha512-Loo5UUvLD9ScZ6jh8beX1T6sO1w2/MpCRpEP7V280GKMVUQ0Jzar2U3UJPsrdbziLEMMhu3Ujnq//rhiFuIeag==", - "dev": true, + "devOptional": true, "license": "BSD-3-Clause", "dependencies": { "psl": "^1.1.33", @@ -592,7 +592,6 @@ "cpu": [ "ppc64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -609,7 +608,6 @@ "cpu": [ "arm" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -626,7 +624,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -643,7 +640,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -660,7 +656,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -677,7 +672,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -694,7 +688,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -711,7 +704,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -728,7 +720,6 @@ "cpu": [ "arm" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -745,7 +736,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -762,7 +752,6 @@ "cpu": [ "ia32" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -779,7 +768,6 @@ "cpu": [ "loong64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -796,7 +784,6 @@ "cpu": [ "mips64el" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -813,7 +800,6 @@ "cpu": [ "ppc64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -830,7 +816,6 @@ "cpu": [ "riscv64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -847,7 +832,6 @@ "cpu": [ "s390x" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -864,7 +848,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -881,7 +864,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -898,7 +880,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -915,7 +896,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -932,7 +912,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -949,7 +928,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -966,7 +944,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -983,7 +960,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1000,7 +976,6 @@ "cpu": [ "ia32" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1017,7 +992,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1639,7 +1613,7 @@ "version": "5.1.14", "resolved": "https://registry.npmjs.org/@inquirer/confirm/-/confirm-5.1.14.tgz", "integrity": "sha512-5yR4IBfe0kXe59r1YCTG8WXkUbl7Z35HK87Sw+WUyGD8wNUx7JvY7laahzeytyE1oLn74bQnL7hstctQxisQ8Q==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "@inquirer/core": "^10.1.15", @@ -1661,7 +1635,7 @@ "version": "10.1.15", "resolved": "https://registry.npmjs.org/@inquirer/core/-/core-10.1.15.tgz", "integrity": "sha512-8xrp836RZvKkpNbVvgWUlxjT4CraKk2q+I3Ksy+seI2zkcE+y6wNs1BVhgcv8VyImFecUhdQrYLdW32pAjwBdA==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "@inquirer/figures": "^1.0.13", @@ -1689,7 +1663,7 @@ "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", "integrity": "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "type-fest": "^0.21.3" @@ -1705,7 +1679,7 @@ "version": "0.21.3", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz", "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==", - "dev": true, + "devOptional": true, "license": "(MIT OR CC0-1.0)", "engines": { "node": ">=10" @@ -1718,7 +1692,7 @@ "version": "1.0.13", "resolved": "https://registry.npmjs.org/@inquirer/figures/-/figures-1.0.13.tgz", "integrity": "sha512-lGPVU3yO9ZNqA7vTYz26jny41lE7yoQansmqdMLBEfqaGsmdg7V3W9mK9Pvb5IL4EVZ9GnSDGMO/cJXud5dMaw==", - "dev": true, + "devOptional": true, "license": "MIT", "engines": { "node": ">=18" @@ -1728,7 +1702,7 @@ "version": "3.0.8", "resolved": "https://registry.npmjs.org/@inquirer/type/-/type-3.0.8.tgz", "integrity": "sha512-lg9Whz8onIHRthWaN1Q9EGLa/0LFJjyM8mEUbL1eTi6yMGvBf8gvyDLtxSXztQsxMvhxxNpJYrwa1YHdq+w4Jw==", - "dev": true, + "devOptional": true, "license": "MIT", "engines": { "node": ">=18" @@ -1863,7 +1837,6 @@ "version": "1.5.5", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", - "dev": true, "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { @@ -2032,7 +2005,6 @@ "resolved": "https://registry.npmjs.org/@lydell/node-pty/-/node-pty-1.1.0.tgz", "integrity": "sha512-VDD8LtlMTOrPKWMXUAcB9+LTktzuunqrMwkYR1DMRBkS6LQrCt+0/Ws1o2rMml/n3guePpS7cxhHF7Nm5K4iMw==", "license": "MIT", - "optional": true, "optionalDependencies": { "@lydell/node-pty-darwin-arm64": "1.1.0", "@lydell/node-pty-darwin-x64": "1.1.0", @@ -2420,7 +2392,7 @@ "version": "0.39.5", "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.39.5.tgz", "integrity": "sha512-B9nHSJYtsv79uo7QdkZ/b/WoKm20IkVSmTc/WCKarmDtFwM0dRx2ouEniqwNkzCSLn3fydzKmnMzjtfdOWt3VQ==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "@open-draft/deferred-promise": "^2.2.0", @@ -2655,14 +2627,14 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/@open-draft/deferred-promise/-/deferred-promise-2.2.0.tgz", "integrity": "sha512-CecwLWx3rhxVQF6V4bAgPS5t+So2sTbPgAzafKkVizyi7tlwpcFpdFqq+wqF2OwNBmqFuu6tOyouTuxgpMfzmA==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/@open-draft/logger": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/@open-draft/logger/-/logger-0.3.0.tgz", "integrity": "sha512-X2g45fzhxH238HKO4xbSr7+wBS8Fvw6ixhTDuvLd5mqh6bJJCFAPwU9mPDxbcrRtfxv4u5IHCEH77BmxvXmmxQ==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "is-node-process": "^1.2.0", @@ -2673,7 +2645,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/@open-draft/until/-/until-2.1.0.tgz", "integrity": "sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/@opentelemetry/api": { @@ -3337,7 +3309,6 @@ "cpu": [ "arm" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3351,7 +3322,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3365,7 +3335,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3379,7 +3348,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3393,7 +3361,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3407,7 +3374,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3421,7 +3387,6 @@ "cpu": [ "arm" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3435,7 +3400,6 @@ "cpu": [ "arm" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3449,7 +3413,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3463,7 +3426,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3477,7 +3439,6 @@ "cpu": [ "loong64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3491,7 +3452,6 @@ "cpu": [ "ppc64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3505,7 +3465,6 @@ "cpu": [ "riscv64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3519,7 +3478,6 @@ "cpu": [ "riscv64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3533,7 +3491,6 @@ "cpu": [ "s390x" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3547,7 +3504,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3561,7 +3517,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3575,7 +3530,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3589,7 +3543,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3603,7 +3556,6 @@ "cpu": [ "ia32" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3617,7 +3569,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3631,7 +3582,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -4088,7 +4038,6 @@ "version": "5.2.3", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", - "dev": true, "license": "MIT", "dependencies": { "@types/deep-eql": "*", @@ -4122,7 +4071,7 @@ "version": "0.6.0", "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz", "integrity": "sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/@types/cookiejar": { @@ -4146,7 +4095,6 @@ "version": "4.0.2", "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", - "dev": true, "license": "MIT" }, "node_modules/@types/diff": { @@ -4170,7 +4118,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", - "dev": true, "license": "MIT" }, "node_modules/@types/express": { @@ -4526,7 +4473,7 @@ "version": "2.0.6", "resolved": "https://registry.npmjs.org/@types/statuses/-/statuses-2.0.6.tgz", "integrity": "sha512-xMAgYwceFhRA2zY+XbEA7mxYbA093wdiW8Vu6gZPGWy9cmOyU9XesH1tNcEWsKFd5Vzrqx5T3D38PWx1FIIXkA==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/@types/superagent": { @@ -5140,7 +5087,6 @@ "version": "3.2.4", "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-3.2.4.tgz", "integrity": "sha512-Io0yyORnB6sikFlt8QW5K7slY4OjqNX9jmJQ02QDda8lyM6B5oNgVWoSoKPac8/kgnCUzuHQKrSLtu/uOqqrig==", - "dev": true, "license": "MIT", "dependencies": { "@types/chai": "^5.2.2", @@ -5157,7 +5103,6 @@ "version": "3.2.4", "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-3.2.4.tgz", "integrity": "sha512-46ryTE9RZO/rfDd7pEqFl7etuyzekzEhUbTW3BvmeO/BcCMEgq59BKhek3dXDWgAj4oMK6OZi+vRr1wPW6qjEQ==", - "dev": true, "license": "MIT", "dependencies": { "@vitest/spy": "3.2.4", @@ -5184,7 +5129,6 @@ "version": "3.2.4", "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-3.2.4.tgz", "integrity": "sha512-IVNZik8IVRJRTr9fxlitMKeJeXFFFN0JaB9PHPGQ8NKQbGpfjlTx9zO4RefN8gp7eqjNy8nyK3NZmBzOPeIxtA==", - "dev": true, "license": "MIT", "dependencies": { "tinyrainbow": "^2.0.0" @@ -5197,7 +5141,6 @@ "version": "3.2.4", "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-3.2.4.tgz", "integrity": "sha512-oukfKT9Mk41LreEW09vt45f8wx7DordoWUZMYdY/cyAk7w5TWkTRCNZYF7sX7n2wB7jyGAl74OxgwhPgKaqDMQ==", - "dev": true, "license": "MIT", "dependencies": { "@vitest/utils": "3.2.4", @@ -5212,7 +5155,6 @@ "version": "3.2.4", "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-3.2.4.tgz", "integrity": "sha512-dEYtS7qQP2CjU27QBC5oUOxLE/v5eLkGqPE0ZKEIDGMs4vKWe7IjgLOeauHsR0D5YuuycGRO5oSRXnwnmA78fQ==", - "dev": true, "license": "MIT", "dependencies": { "@vitest/pretty-format": "3.2.4", @@ -5227,7 +5169,6 @@ "version": "3.2.4", "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-3.2.4.tgz", "integrity": "sha512-vAfasCOe6AIK70iP5UD11Ac4siNUNJ9i/9PZ3NKx07sG6sUxeag1LWdNrMWeKKYBLlzuK+Gn65Yd5nyL6ds+nw==", - "dev": true, "license": "MIT", "dependencies": { "tinyspy": "^4.0.3" @@ -5240,7 +5181,6 @@ "version": "3.2.4", "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-3.2.4.tgz", "integrity": "sha512-fB2V0JFrQSMsCo9HiSq3Ezpdv4iYaXRG1Sx8edX3MwxfyNn83mKiGzOcH+Fkxt4MHxr3y42fQi1oeAInqgX2QA==", - "dev": true, "license": "MIT", "dependencies": { "@vitest/pretty-format": "3.2.4", @@ -6318,7 +6258,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -6714,7 +6653,6 @@ "version": "6.7.14", "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", "integrity": "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -6830,7 +6768,6 @@ "version": "5.3.3", "resolved": "https://registry.npmjs.org/chai/-/chai-5.3.3.tgz", "integrity": "sha512-4zNhdJD/iOjSH0A05ea+Ke6MU5mmpQcbQsSOkgdaUMJ9zTlDTD/GYlwohmIE2u0gaxHYiVHEn1Fw9mZ/ktJWgw==", - "dev": true, "license": "MIT", "dependencies": { "assertion-error": "^2.0.1", @@ -6881,7 +6818,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.1.tgz", "integrity": "sha512-OAlb+T7V4Op9OwdkjmguYRqncdlx5JiofwOAUkmTF+jNdHwzTaTs4sRAGpzLF3oOz5xAyDGrPgeIDFQmDOTiJw==", - "dev": true, "license": "MIT", "engines": { "node": ">= 16" @@ -7101,7 +7037,7 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-4.1.0.tgz", "integrity": "sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==", - "dev": true, + "devOptional": true, "license": "ISC", "engines": { "node": ">= 12" @@ -7805,7 +7741,6 @@ "version": "5.0.2", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz", "integrity": "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -8587,7 +8522,6 @@ "version": "1.7.0", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz", "integrity": "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==", - "dev": true, "license": "MIT" }, "node_modules/es-object-atoms": { @@ -8662,7 +8596,6 @@ "version": "0.25.6", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.6.tgz", "integrity": "sha512-GVuzuUwtdsghE3ocJ9Bs8PNoF13HNQ5TXbEi2AhvVb8xU1Iwt9Fos9FEamfoee+u/TOsn7GUWc04lz46n2bbTg==", - "dev": true, "hasInstallScript": true, "license": "MIT", "bin": { @@ -9111,7 +9044,6 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", - "dev": true, "license": "MIT", "dependencies": { "@types/estree": "^1.0.0" @@ -9279,7 +9211,6 @@ "version": "1.2.2", "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.2.2.tgz", "integrity": "sha512-JhFGDVJ7tmDJItKhYgJCGLOWjuK9vPxiXoUFLwLDc99NlmklilbiQJwoctZtt13+xMw91MCk/REan6MWHqDjyA==", - "dev": true, "license": "Apache-2.0", "engines": { "node": ">=12.0.0" @@ -9898,7 +9829,6 @@ "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, "hasInstallScript": true, "license": "MIT", "optional": true, @@ -10097,7 +10027,7 @@ "version": "4.10.1", "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.10.1.tgz", "integrity": "sha512-auHyJ4AgMz7vgS8Hp3N6HXSmlMdUyhSUrfBF16w153rxtLIEOE+HGqaBppczZvnHLqQJfiHotCYpNhl0lUROFQ==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "resolve-pkg-maps": "^1.0.0" @@ -10498,7 +10428,7 @@ "version": "16.11.0", "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.11.0.tgz", "integrity": "sha512-mS1lbMsxgQj6hge1XZ6p7GPhbrtFwUFYi3wRzXAC/FmYnyXMTvvI3td3rjmQ2u8ewXueaSvRPWaEcgVVOT9Jnw==", - "dev": true, + "devOptional": true, "license": "MIT", "engines": { "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" @@ -10620,7 +10550,7 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/headers-polyfill/-/headers-polyfill-4.0.3.tgz", "integrity": "sha512-IScLbePpkvO846sIwOtOTDjutRMWdXdJmXdMvk6gCBHxFO8d+QKOQedyZSxFTTFYRSmlgSTDtXqqq4pcenBXLQ==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/highlight.js": { @@ -11411,7 +11341,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/is-node-process/-/is-node-process-1.2.0.tgz", "integrity": "sha512-Vg4o6/fqPxIjtxgUH5QLJhwZ7gW5diGCVlXpuUfELC62CuxM1iHcRe51f2W1FDy04Ai4KJkagKjx3XaqyfRKXw==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/is-number": { @@ -11824,7 +11754,6 @@ "version": "9.0.1", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-9.0.1.tgz", "integrity": "sha512-mxa9E9ITFOt0ban3j6L5MpjwegGz6lBQmM1IJkWeBZGcMxto50+eWdjC/52xDbS2vy0k7vIMK0Fe2wfL9OQSpQ==", - "dev": true, "license": "MIT" }, "node_modules/js-yaml": { @@ -12564,7 +12493,6 @@ "version": "3.2.1", "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.2.1.tgz", "integrity": "sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==", - "dev": true, "license": "MIT" }, "node_modules/lowercase-keys": { @@ -12604,7 +12532,6 @@ "version": "0.30.21", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", - "dev": true, "license": "MIT", "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" @@ -12931,7 +12858,7 @@ "version": "2.10.4", "resolved": "https://registry.npmjs.org/msw/-/msw-2.10.4.tgz", "integrity": "sha512-6R1or/qyele7q3RyPwNuvc0IxO8L8/Aim6Sz5ncXEgcWUNxSKE+udriTOWHtpMwmfkLYlacA2y7TIx4cL5lgHA==", - "dev": true, + "devOptional": true, "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -12976,14 +12903,14 @@ "version": "6.3.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.3.0.tgz", "integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/msw/node_modules/type-fest": { "version": "4.41.0", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", "integrity": "sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==", - "dev": true, + "devOptional": true, "license": "(MIT OR CC0-1.0)", "engines": { "node": ">=16" @@ -13023,7 +12950,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-2.0.0.tgz", "integrity": "sha512-WWdIxpyjEn+FhQJQQv9aQAYlHoNVdzIzUySNV1gHUPDSdZJ3yZn7pAAbQcV7B56Mvu881q9FZV+0Vx2xC44VWA==", - "dev": true, + "devOptional": true, "license": "ISC", "engines": { "node": "^18.17.0 || >=20.5.0" @@ -13053,7 +12980,6 @@ "version": "3.3.11", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz", "integrity": "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==", - "dev": true, "funding": [ { "type": "github", @@ -13807,7 +13733,7 @@ "version": "1.4.3", "resolved": "https://registry.npmjs.org/outvariant/-/outvariant-1.4.3.tgz", "integrity": "sha512-+Sl2UErvtsoajRDKCE5/dBz4DIvHXQQnAxtQTF04OJxY0+DyZXSo5P5Bb7XYWOh81syohlYL24hbDwxedPUJCA==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/own-keys": { @@ -14154,14 +14080,12 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", - "dev": true, "license": "MIT" }, "node_modules/pathval": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.1.tgz", "integrity": "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ==", - "dev": true, "license": "MIT", "engines": { "node": ">= 14.16" @@ -14267,7 +14191,6 @@ "version": "8.5.6", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz", "integrity": "sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==", - "dev": true, "funding": [ { "type": "opencollective", @@ -14495,7 +14418,7 @@ "version": "1.15.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.15.0.tgz", "integrity": "sha512-JZd3gMVBAVQkSs6HdNZo9Sdo0LNcQeMNP3CozBJb3JYC/QUYZTnKxP+f8oWRX4rHP5EurWxqAHTSwUCjlNKa1w==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "punycode": "^2.3.1" @@ -14529,7 +14452,7 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", - "dev": true, + "devOptional": true, "license": "MIT", "engines": { "node": ">=6" @@ -14564,7 +14487,7 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/queue-microtask": { @@ -15070,7 +14993,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/resolve": { @@ -15127,7 +15050,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", - "dev": true, + "devOptional": true, "license": "MIT", "funding": { "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" @@ -15305,7 +15228,6 @@ "version": "4.53.2", "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.53.2.tgz", "integrity": "sha512-MHngMYwGJVi6Fmnk6ISmnk7JAHRNF0UkuucA0CUW3N3a4KnONPEZz+vUanQP/ZC/iY1Qkf3bwPWzyY84wEks1g==", - "dev": true, "license": "MIT", "dependencies": { "@types/estree": "1.0.8" @@ -15808,7 +15730,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", - "dev": true, "license": "ISC" }, "node_modules/signal-exit": { @@ -15966,7 +15887,6 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", - "dev": true, "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" @@ -16045,7 +15965,6 @@ "version": "0.0.2", "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", - "dev": true, "license": "MIT" }, "node_modules/statuses": { @@ -16061,7 +15980,6 @@ "version": "3.10.0", "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.10.0.tgz", "integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==", - "dev": true, "license": "MIT" }, "node_modules/stop-iteration-iterator": { @@ -16109,7 +16027,7 @@ "version": "0.5.1", "resolved": "https://registry.npmjs.org/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz", "integrity": "sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/string_decoder": { @@ -16382,7 +16300,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/strip-literal/-/strip-literal-3.1.0.tgz", "integrity": "sha512-8r3mkIM/2+PpjHoOtiAW8Rg3jJLHaV7xPwG+YRGrv6FP0wwk/toTpATxWYOW0BKdWwl82VT2tFYi5DlROa0Mxg==", - "dev": true, "license": "MIT", "dependencies": { "js-tokens": "^9.0.1" @@ -16938,7 +16855,6 @@ "version": "2.9.0", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", - "dev": true, "license": "MIT" }, "node_modules/tinycolor2": { @@ -16951,14 +16867,12 @@ "version": "0.3.2", "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-0.3.2.tgz", "integrity": "sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA==", - "dev": true, "license": "MIT" }, "node_modules/tinyglobby": { "version": "0.2.15", "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz", "integrity": "sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==", - "dev": true, "license": "MIT", "dependencies": { "fdir": "^6.5.0", @@ -16975,7 +16889,6 @@ "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", - "dev": true, "license": "MIT", "engines": { "node": ">=12.0.0" @@ -16993,7 +16906,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -17016,7 +16928,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/tinypool/-/tinypool-1.1.1.tgz", "integrity": "sha512-Zba82s87IFq9A9XmjiX5uZA/ARWDrB03OHlq+Vw1fSdt0I+4/Kutwy8BP4Y/y/aORMo61FQ0vIb5j44vSo5Pkg==", - "dev": true, "license": "MIT", "engines": { "node": "^18.0.0 || >=20.0.0" @@ -17026,7 +16937,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-2.0.0.tgz", "integrity": "sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==", - "dev": true, "license": "MIT", "engines": { "node": ">=14.0.0" @@ -17036,7 +16946,6 @@ "version": "4.0.4", "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-4.0.4.tgz", "integrity": "sha512-azl+t0z7pw/z958Gy9svOTuzqIk6xq+NSheJzn5MMWtWTFywIacg2wUlzKFGtt3cthx0r2SxMK0yzJOR0IES7Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=14.0.0" @@ -17227,7 +17136,7 @@ "version": "4.20.3", "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.20.3.tgz", "integrity": "sha512-qjbnuR9Tr+FJOMBqJCW5ehvIo/buZq7vH7qD7JziU98h6l3qGy0a/yPFjwO+y0/T7GFpNgNAvEcPPVfyT8rrPQ==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "esbuild": "~0.25.0", @@ -17410,7 +17319,7 @@ "version": "5.8.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", - "dev": true, + "devOptional": true, "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", @@ -17514,7 +17423,7 @@ "version": "0.2.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==", - "dev": true, + "devOptional": true, "license": "MIT", "engines": { "node": ">= 4.0.0" @@ -17550,7 +17459,7 @@ "version": "1.5.10", "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "querystringify": "^2.1.1", @@ -17628,7 +17537,6 @@ "version": "7.2.2", "resolved": "https://registry.npmjs.org/vite/-/vite-7.2.2.tgz", "integrity": "sha512-BxAKBWmIbrDgrokdGZH1IgkIk/5mMHDreLDmCJ0qpyJaAteP8NvMhkwr/ZCQNqNH97bw/dANTE9PDzqwJghfMQ==", - "dev": true, "license": "MIT", "dependencies": { "esbuild": "^0.25.0", @@ -17703,7 +17611,6 @@ "version": "3.2.4", "resolved": "https://registry.npmjs.org/vite-node/-/vite-node-3.2.4.tgz", "integrity": "sha512-EbKSKh+bh1E1IFxeO0pg1n4dvoOTt0UDiXMd/qn++r98+jPO1xtJilvXldeuQ8giIB5IkpjCgMleHMNEsGH6pg==", - "dev": true, "license": "MIT", "dependencies": { "cac": "^6.7.14", @@ -17726,7 +17633,6 @@ "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", - "dev": true, "license": "MIT", "engines": { "node": ">=12.0.0" @@ -17744,7 +17650,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -17757,7 +17662,6 @@ "version": "3.2.4", "resolved": "https://registry.npmjs.org/vitest/-/vitest-3.2.4.tgz", "integrity": "sha512-LUCP5ev3GURDysTWiP47wRRUpLKMOfPh+yKTx3kVIEiu5KOMeqzpnYNsKyOoVrULivR8tLcks4+lga33Whn90A==", - "dev": true, "license": "MIT", "dependencies": { "@types/chai": "^5.2.2", @@ -17830,7 +17734,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -17993,7 +17896,6 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz", "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==", - "dev": true, "license": "MIT", "dependencies": { "siginfo": "^2.0.0", @@ -18263,7 +18165,7 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.1.tgz", "integrity": "sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==", - "dev": true, + "devOptional": true, "license": "ISC", "bin": { "yaml": "bin.mjs" @@ -18388,7 +18290,7 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/yoctocolors-cjs/-/yoctocolors-cjs-2.1.2.tgz", "integrity": "sha512-cYVsTjKl8b+FrnidjibDWskAv7UKOfcwaVZdp/it9n1s9fU3IkgDbhdIRKCW4JDsAlECJY0ytoVPT3sK6kideA==", - "dev": true, + "devOptional": true, "license": "MIT", "engines": { "node": ">=18" @@ -19054,6 +18956,12 @@ "name": "@google/gemini-cli-test-utils", "version": "0.25.0-nightly.20260107.59a18e710", "license": "Apache-2.0", + "dependencies": { + "@google/gemini-cli-core": "file:../core", + "@lydell/node-pty": "1.1.0", + "strip-ansi": "^7.1.2", + "vitest": "^3.2.4" + }, "devDependencies": { "typescript": "^5.3.3" }, diff --git a/package.json b/package.json index f5c10deaf5..b69c37d69b 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,8 @@ "test": "npm run test --workspaces --if-present", "test:ci": "npm run test:ci --workspaces --if-present && npm run test:scripts", "test:scripts": "vitest run --config ./scripts/tests/vitest.config.ts", + "test:always_passing_evals": "vitest run --config evals/vitest.config.ts", + "test:all_evals": "cross-env RUN_EVALS=1 vitest run --config evals/vitest.config.ts", "test:e2e": "cross-env VERBOSE=true KEEP_OUTPUT=true npm run test:integration:sandbox:none", "test:integration:all": "npm run test:integration:sandbox:none && npm run test:integration:sandbox:docker && npm run test:integration:sandbox:podman", "test:integration:sandbox:none": "cross-env GEMINI_SANDBOX=false vitest run --root ./integration-tests", diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index dddb6c01f2..a05464d3e5 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -9,6 +9,12 @@ "build": "node ../../scripts/build_package.js", "typecheck": "tsc --noEmit" }, + "dependencies": { + "@google/gemini-cli-core": "file:../core", + "@lydell/node-pty": "1.1.0", + "strip-ansi": "^7.1.2", + "vitest": "^3.2.4" + }, "devDependencies": { "typescript": "^5.3.3" }, diff --git a/packages/test-utils/src/index.ts b/packages/test-utils/src/index.ts index b8af8aa7d6..c1f2f09d3e 100644 --- a/packages/test-utils/src/index.ts +++ b/packages/test-utils/src/index.ts @@ -5,3 +5,4 @@ */ export * from './file-system-test-helpers.js'; +export * from './test-rig.js'; diff --git a/packages/test-utils/src/test-rig.ts b/packages/test-utils/src/test-rig.ts new file mode 100644 index 0000000000..8b55637715 --- /dev/null +++ b/packages/test-utils/src/test-rig.ts @@ -0,0 +1,1227 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { expect } from 'vitest'; +import { execSync, spawn, type ChildProcess } from 'node:child_process'; +import { mkdirSync, writeFileSync, readFileSync } from 'node:fs'; +import { join, dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { env } from 'node:process'; +import { setTimeout as sleep } from 'node:timers/promises'; +import { DEFAULT_GEMINI_MODEL, GEMINI_DIR } from '@google/gemini-cli-core'; +import fs from 'node:fs'; +import * as pty from '@lydell/node-pty'; +import stripAnsi from 'strip-ansi'; +import * as os from 'node:os'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const BUNDLE_PATH = join(__dirname, '..', '..', '..', 'bundle/gemini.js'); + +// Get timeout based on environment +export function getDefaultTimeout() { + if (env['CI']) return 60000; // 1 minute in CI + if (env['GEMINI_SANDBOX']) return 30000; // 30s in containers + return 15000; // 15s locally +} + +export async function poll( + predicate: () => boolean, + timeout: number, + interval: number, +): Promise { + const startTime = Date.now(); + let attempts = 0; + while (Date.now() - startTime < timeout) { + attempts++; + const result = predicate(); + if (env['VERBOSE'] === 'true' && attempts % 5 === 0) { + console.log( + `Poll attempt ${attempts}: ${result ? 'success' : 'waiting...'}`, + ); + } + if (result) { + return true; + } + await sleep(interval); + } + if (env['VERBOSE'] === 'true') { + console.log(`Poll timed out after ${attempts} attempts`); + } + return false; +} + +export function sanitizeTestName(name: string) { + return name + .toLowerCase() + .replace(/[^a-z0-9]/g, '-') + .replace(/-+/g, '-'); +} + +// Helper to create detailed error messages +export function createToolCallErrorMessage( + expectedTools: string | string[], + foundTools: string[], + result: string, +) { + const expectedStr = Array.isArray(expectedTools) + ? expectedTools.join(' or ') + : expectedTools; + return ( + `Expected to find ${expectedStr} tool call(s). ` + + `Found: ${foundTools.length > 0 ? foundTools.join(', ') : 'none'}. ` + + `Output preview: ${result ? result.substring(0, 200) + '...' : 'no output'}` + ); +} + +// Helper to print debug information when tests fail +export function printDebugInfo( + rig: TestRig, + result: string, + context: Record = {}, +) { + console.error('Test failed - Debug info:'); + console.error('Result length:', result.length); + console.error('Result (first 500 chars):', result.substring(0, 500)); + console.error( + 'Result (last 500 chars):', + result.substring(result.length - 500), + ); + + // Print any additional context provided + Object.entries(context).forEach(([key, value]) => { + console.error(`${key}:`, value); + }); + + // Check what tools were actually called + const allTools = rig.readToolLogs(); + console.error( + 'All tool calls found:', + allTools.map((t) => t.toolRequest.name), + ); + + return allTools; +} + +// Helper to validate model output and warn about unexpected content +export function validateModelOutput( + result: string, + expectedContent: string | (string | RegExp)[] | null = null, + testName = '', +) { + // First, check if there's any output at all (this should fail the test if missing) + if (!result || result.trim().length === 0) { + throw new Error('Expected LLM to return some output'); + } + + // If expectedContent is provided, check for it and warn if missing + if (expectedContent) { + const contents = Array.isArray(expectedContent) + ? expectedContent + : [expectedContent]; + const missingContent = contents.filter((content) => { + if (typeof content === 'string') { + return !result.toLowerCase().includes(content.toLowerCase()); + } else if (content instanceof RegExp) { + return !content.test(result); + } + return false; + }); + + if (missingContent.length > 0) { + console.warn( + `Warning: LLM did not include expected content in response: ${missingContent.join( + ', ', + )}.`, + 'This is not ideal but not a test failure.', + ); + console.warn( + 'The tool was called successfully, which is the main requirement.', + ); + console.warn('Expected content:', expectedContent); + console.warn('Actual output:', result); + return false; + } else if (env['VERBOSE'] === 'true') { + console.log(`${testName}: Model output validated successfully.`); + } + return true; + } + + return true; +} + +export interface ParsedLog { + attributes?: { + 'event.name'?: string; + function_name?: string; + function_args?: string; + success?: boolean; + duration_ms?: number; + request_text?: string; + hook_event_name?: string; + hook_name?: string; + hook_input?: Record; + hook_output?: Record; + exit_code?: number; + stdout?: string; + stderr?: string; + error?: string; + }; + scopeMetrics?: { + metrics: { + descriptor: { + name: string; + }; + }[]; + }[]; +} + +export class InteractiveRun { + ptyProcess: pty.IPty; + public output = ''; + + constructor(ptyProcess: pty.IPty) { + this.ptyProcess = ptyProcess; + ptyProcess.onData((data) => { + this.output += data; + if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { + process.stdout.write(data); + } + }); + } + + async expectText(text: string, timeout?: number) { + if (!timeout) { + timeout = getDefaultTimeout(); + } + await poll( + () => stripAnsi(this.output).toLowerCase().includes(text.toLowerCase()), + timeout, + 200, + ); + expect(stripAnsi(this.output).toLowerCase()).toContain(text.toLowerCase()); + } + + // This types slowly to make sure command is correct, but only work for short + // commands that are not multi-line, use sendKeys to type long prompts + async type(text: string) { + let typedSoFar = ''; + for (const char of text) { + if (char === '\r') { + // wait >30ms before `enter` to avoid fast return conversion + // from bufferFastReturn() in KeypressContent.tsx + await sleep(50); + } + + this.ptyProcess.write(char); + typedSoFar += char; + + // Wait for the typed sequence so far to be echoed back. + const found = await poll( + () => stripAnsi(this.output).includes(typedSoFar), + 5000, // 5s timeout per character (generous for CI) + 10, // check frequently + ); + + if (!found) { + throw new Error( + `Timed out waiting for typed text to appear in output: "${typedSoFar}".\nStripped output:\n${stripAnsi( + this.output, + )}`, + ); + } + } + } + + // Types an entire string at once, necessary for some things like commands + // but may run into paste detection issues for larger strings. + async sendText(text: string) { + this.ptyProcess.write(text); + await sleep(5); + } + + // Simulates typing a string one character at a time to avoid paste detection. + async sendKeys(text: string) { + const delay = 5; + for (const char of text) { + this.ptyProcess.write(char); + await sleep(delay); + } + } + + async kill() { + this.ptyProcess.kill(); + } + + expectExit(): Promise { + return new Promise((resolve, reject) => { + const timer = setTimeout( + () => + reject( + new Error(`Test timed out: process did not exit within a minute.`), + ), + 60000, + ); + this.ptyProcess.onExit(({ exitCode }) => { + clearTimeout(timer); + resolve(exitCode); + }); + }); + } +} + +export class TestRig { + testDir: string | null = null; + homeDir: string | null = null; + testName?: string; + _lastRunStdout?: string; + // Path to the copied fake responses file for this test. + fakeResponsesPath?: string; + // Original fake responses file path for rewriting goldens in record mode. + originalFakeResponsesPath?: string; + private _interactiveRuns: InteractiveRun[] = []; + private _spawnedProcesses: ChildProcess[] = []; + + setup( + testName: string, + options: { + settings?: Record; + fakeResponsesPath?: string; + } = {}, + ) { + this.testName = testName; + const sanitizedName = sanitizeTestName(testName); + const testFileDir = + env['INTEGRATION_TEST_FILE_DIR'] || join(os.tmpdir(), 'gemini-cli-tests'); + this.testDir = join(testFileDir, sanitizedName); + this.homeDir = join(testFileDir, sanitizedName + '-home'); + mkdirSync(this.testDir, { recursive: true }); + mkdirSync(this.homeDir, { recursive: true }); + if (options.fakeResponsesPath) { + this.fakeResponsesPath = join(this.testDir, 'fake-responses.json'); + this.originalFakeResponsesPath = options.fakeResponsesPath; + if (process.env['REGENERATE_MODEL_GOLDENS'] !== 'true') { + fs.copyFileSync(options.fakeResponsesPath, this.fakeResponsesPath); + } + } + + // Create a settings file to point the CLI to the local collector + this._createSettingsFile(options.settings); + } + + private _createSettingsFile(overrideSettings?: Record) { + const projectGeminiDir = join(this.testDir!, GEMINI_DIR); + mkdirSync(projectGeminiDir, { recursive: true }); + + // In sandbox mode, use an absolute path for telemetry inside the container + // The container mounts the test directory at the same path as the host + const telemetryPath = join(this.homeDir!, 'telemetry.log'); // Always use home directory for telemetry + + const settings = { + general: { + // Nightly releases sometimes becomes out of sync with local code and + // triggers auto-update, which causes tests to fail. + disableAutoUpdate: true, + previewFeatures: false, + }, + telemetry: { + enabled: true, + target: 'local', + otlpEndpoint: '', + outfile: telemetryPath, + }, + security: { + auth: { + selectedType: 'gemini-api-key', + }, + }, + ui: { + useAlternateBuffer: true, + }, + model: { + name: DEFAULT_GEMINI_MODEL, + }, + sandbox: + env['GEMINI_SANDBOX'] !== 'false' ? env['GEMINI_SANDBOX'] : false, + // Don't show the IDE connection dialog when running from VsCode + ide: { enabled: false, hasSeenNudge: true }, + ...overrideSettings, // Allow tests to override/add settings + }; + writeFileSync( + join(projectGeminiDir, 'settings.json'), + JSON.stringify(settings, null, 2), + ); + } + + createFile(fileName: string, content: string) { + const filePath = join(this.testDir!, fileName); + writeFileSync(filePath, content); + return filePath; + } + + mkdir(dir: string) { + mkdirSync(join(this.testDir!, dir), { recursive: true }); + } + + sync() { + if (os.platform() === 'win32') return; + // ensure file system is done before spawning + execSync('sync', { cwd: this.testDir! }); + } + + /** + * The command and args to use to invoke Gemini CLI. Allows us to switch + * between using the bundled gemini.js (the default) and using the installed + * 'gemini' (used to verify npm bundles). + */ + private _getCommandAndArgs(extraInitialArgs: string[] = []): { + command: string; + initialArgs: string[]; + } { + const isNpmReleaseTest = + env['INTEGRATION_TEST_USE_INSTALLED_GEMINI'] === 'true'; + const command = isNpmReleaseTest ? 'gemini' : 'node'; + const initialArgs = isNpmReleaseTest + ? extraInitialArgs + : [BUNDLE_PATH, ...extraInitialArgs]; + if (this.fakeResponsesPath) { + if (process.env['REGENERATE_MODEL_GOLDENS'] === 'true') { + initialArgs.push('--record-responses', this.fakeResponsesPath); + } else { + initialArgs.push('--fake-responses', this.fakeResponsesPath); + } + } + return { command, initialArgs }; + } + + run(options: { + args?: string | string[]; + stdin?: string; + stdinDoesNotEnd?: boolean; + yolo?: boolean; + timeout?: number; + env?: Record; + }): Promise { + const yolo = options.yolo !== false; + const { command, initialArgs } = this._getCommandAndArgs( + yolo ? ['--yolo'] : [], + ); + const commandArgs = [...initialArgs]; + const execOptions: { + cwd: string; + encoding: 'utf-8'; + input?: string; + } = { + cwd: this.testDir!, + encoding: 'utf-8', + }; + + if (options.args) { + if (Array.isArray(options.args)) { + commandArgs.push(...options.args); + } else { + commandArgs.push(options.args); + } + } + + if (options.stdin) { + execOptions.input = options.stdin; + } + + const child = spawn(command, commandArgs, { + cwd: this.testDir!, + stdio: 'pipe', + env: { + ...process.env, + GEMINI_CLI_HOME: this.homeDir!, + ...options.env, + }, + }); + this._spawnedProcesses.push(child); + + let stdout = ''; + let stderr = ''; + + // Handle stdin if provided + if (execOptions.input) { + child.stdin!.write(execOptions.input); + } + + if (!options.stdinDoesNotEnd) { + child.stdin!.end(); + } + + child.stdout!.setEncoding('utf8'); + child.stdout!.on('data', (data: string) => { + stdout += data; + if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { + process.stdout.write(data); + } + }); + + child.stderr!.setEncoding('utf8'); + child.stderr!.on('data', (data: string) => { + stderr += data; + if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { + process.stderr.write(data); + } + }); + + const timeout = options.timeout ?? 120000; + const promise = new Promise((resolve, reject) => { + const timer = setTimeout(() => { + child.kill('SIGKILL'); + reject( + new Error( + `Process timed out after ${timeout}ms.\nStdout:\n${stdout}\nStderr:\n${stderr}`, + ), + ); + }, timeout); + + child.on('error', (err) => { + clearTimeout(timer); + reject(err); + }); + + child.on('close', (code: number) => { + clearTimeout(timer); + if (code === 0) { + // Store the raw stdout for Podman telemetry parsing + this._lastRunStdout = stdout; + + // Filter out telemetry output when running with Podman + const result = this._filterPodmanTelemetry(stdout); + + // Check if this is a JSON output test - if so, don't include stderr + // as it would corrupt the JSON + const isJsonOutput = + commandArgs.includes('--output-format') && + commandArgs.includes('json'); + + // If we have stderr output and it's not a JSON test, include that also + const finalResult = + stderr && !isJsonOutput + ? `${result}\n\nStdErr:\n${stderr}` + : result; + + resolve(finalResult); + } else { + reject(new Error(`Process exited with code ${code}:\n${stderr}`)); + } + }); + }); + + return promise; + } + + private _filterPodmanTelemetry(stdout: string): string { + if (env['GEMINI_SANDBOX'] !== 'podman') { + return stdout; + } + + // Remove telemetry JSON objects from output + // They are multi-line JSON objects that start with { and contain telemetry fields + const lines = stdout.split(os.EOL); + const filteredLines = []; + let inTelemetryObject = false; + let braceDepth = 0; + + for (const line of lines) { + if (!inTelemetryObject && line.trim() === '{') { + // Check if this might be start of telemetry object + inTelemetryObject = true; + braceDepth = 1; + } else if (inTelemetryObject) { + // Count braces to track nesting + for (const char of line) { + if (char === '{') braceDepth++; + else if (char === '}') braceDepth--; + } + + // Check if we've closed all braces + if (braceDepth === 0) { + inTelemetryObject = false; + // Skip this line (the closing brace) + continue; + } + } else { + // Not in telemetry object, keep the line + filteredLines.push(line); + } + } + + return filteredLines.join('\n'); + } + + runCommand( + args: string[], + options: { + stdin?: string; + timeout?: number; + env?: Record; + } = {}, + ): Promise { + const { command, initialArgs } = this._getCommandAndArgs(); + const commandArgs = [...initialArgs, ...args]; + + const child = spawn(command, commandArgs, { + cwd: this.testDir!, + stdio: 'pipe', + env: { + ...process.env, + GEMINI_CLI_HOME: this.homeDir!, + ...options.env, + }, + }); + this._spawnedProcesses.push(child); + + let stdout = ''; + let stderr = ''; + + if (options.stdin) { + child.stdin!.write(options.stdin); + child.stdin!.end(); + } + + child.stdout!.setEncoding('utf8'); + child.stdout!.on('data', (data: string) => { + stdout += data; + if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { + process.stdout.write(data); + } + }); + + child.stderr!.setEncoding('utf8'); + child.stderr!.on('data', (data: string) => { + stderr += data; + if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { + process.stderr.write(data); + } + }); + + const timeout = options.timeout ?? 120000; + const promise = new Promise((resolve, reject) => { + const timer = setTimeout(() => { + child.kill('SIGKILL'); + reject( + new Error( + `Process timed out after ${timeout}ms.\nStdout:\n${stdout}\nStderr:\n${stderr}`, + ), + ); + }, timeout); + + child.on('error', (err) => { + clearTimeout(timer); + reject(err); + }); + + child.on('close', (code: number) => { + clearTimeout(timer); + if (code === 0) { + this._lastRunStdout = stdout; + const result = this._filterPodmanTelemetry(stdout); + + // Check if this is a JSON output test - if so, don't include stderr + // as it would corrupt the JSON + const isJsonOutput = + commandArgs.includes('--output-format') && + commandArgs.includes('json'); + + const finalResult = + stderr && !isJsonOutput + ? `${result}\n\nStdErr:\n${stderr}` + : result; + resolve(finalResult); + } else { + reject(new Error(`Process exited with code ${code}:\n${stderr}`)); + } + }); + }); + + return promise; + } + + readFile(fileName: string) { + const filePath = join(this.testDir!, fileName); + const content = readFileSync(filePath, 'utf-8'); + if (env['KEEP_OUTPUT'] === 'true' || env['VERBOSE'] === 'true') { + console.log(`--- FILE: ${filePath} ---`); + console.log(content); + console.log(`--- END FILE: ${filePath} ---`); + } + return content; + } + + async cleanup() { + // Kill any interactive runs that are still active + for (const run of this._interactiveRuns) { + try { + await run.kill(); + } catch (error) { + if (env['VERBOSE'] === 'true') { + console.warn('Failed to kill interactive run during cleanup:', error); + } + } + } + this._interactiveRuns = []; + + // Kill any other spawned processes that are still running + for (const child of this._spawnedProcesses) { + if (child.exitCode === null && child.signalCode === null) { + try { + child.kill('SIGKILL'); + } catch (error) { + if (env['VERBOSE'] === 'true') { + console.warn( + 'Failed to kill spawned process during cleanup:', + error, + ); + } + } + } + } + this._spawnedProcesses = []; + + if ( + process.env['REGENERATE_MODEL_GOLDENS'] === 'true' && + this.fakeResponsesPath + ) { + fs.copyFileSync(this.fakeResponsesPath, this.originalFakeResponsesPath!); + } + // Clean up test directory and home directory + if (this.testDir && !env['KEEP_OUTPUT']) { + try { + fs.rmSync(this.testDir, { recursive: true, force: true }); + } catch (error) { + // Ignore cleanup errors + if (env['VERBOSE'] === 'true') { + console.warn('Cleanup warning:', (error as Error).message); + } + } + } + if (this.homeDir && !env['KEEP_OUTPUT']) { + try { + fs.rmSync(this.homeDir, { recursive: true, force: true }); + } catch (error) { + // Ignore cleanup errors + if (env['VERBOSE'] === 'true') { + console.warn('Cleanup warning:', (error as Error).message); + } + } + } + } + + async waitForTelemetryReady() { + // Telemetry is always written to the test directory + const logFilePath = join(this.homeDir!, 'telemetry.log'); + + if (!logFilePath) return; + + // Wait for telemetry file to exist and have content + await poll( + () => { + if (!fs.existsSync(logFilePath)) return false; + try { + const content = readFileSync(logFilePath, 'utf-8'); + // Check if file has meaningful content (at least one complete JSON object) + return content.includes('"scopeMetrics"'); + } catch { + return false; + } + }, + 2000, // 2 seconds max - reduced since telemetry should flush on exit now + 100, // check every 100ms + ); + } + + async waitForTelemetryEvent(eventName: string, timeout?: number) { + if (!timeout) { + timeout = getDefaultTimeout(); + } + + await this.waitForTelemetryReady(); + + return poll( + () => { + const logs = this._readAndParseTelemetryLog(); + return logs.some( + (logData) => + logData.attributes && + logData.attributes['event.name'] === `gemini_cli.${eventName}`, + ); + }, + timeout, + 100, + ); + } + + async waitForToolCall( + toolName: string, + timeout?: number, + matchArgs?: (args: string) => boolean, + ) { + // Use environment-specific timeout + if (!timeout) { + timeout = getDefaultTimeout(); + } + + // Wait for telemetry to be ready before polling for tool calls + await this.waitForTelemetryReady(); + + return poll( + () => { + const toolLogs = this.readToolLogs(); + return toolLogs.some( + (log) => + log.toolRequest.name === toolName && + (matchArgs?.call(this, log.toolRequest.args) ?? true), + ); + }, + timeout, + 100, + ); + } + + async expectToolCallSuccess( + toolNames: string[], + timeout?: number, + matchArgs?: (args: string) => boolean, + ) { + // Use environment-specific timeout + if (!timeout) { + timeout = getDefaultTimeout(); + } + + // Wait for telemetry to be ready before polling for tool calls + await this.waitForTelemetryReady(); + + const success = await poll( + () => { + const toolLogs = this.readToolLogs(); + return toolNames.some((name) => + toolLogs.some( + (log) => + log.toolRequest.name === name && + log.toolRequest.success && + (matchArgs?.call(this, log.toolRequest.args) ?? true), + ), + ); + }, + timeout, + 100, + ); + + expect( + success, + `Expected to find successful toolCalls for ${JSON.stringify(toolNames)}`, + ).toBe(true); + } + + async waitForAnyToolCall(toolNames: string[], timeout?: number) { + if (!timeout) { + timeout = getDefaultTimeout(); + } + + // Wait for telemetry to be ready before polling for tool calls + await this.waitForTelemetryReady(); + + return poll( + () => { + const toolLogs = this.readToolLogs(); + return toolNames.some((name) => + toolLogs.some((log) => log.toolRequest.name === name), + ); + }, + timeout, + 100, + ); + } + + _parseToolLogsFromStdout(stdout: string) { + const logs: { + timestamp: number; + toolRequest: { + name: string; + args: string; + success: boolean; + duration_ms: number; + }; + }[] = []; + + // The console output from Podman is JavaScript object notation, not JSON + // Look for tool call events in the output + // Updated regex to handle tool names with hyphens and underscores + const toolCallPattern = + /body:\s*'Tool call:\s*([\w-]+)\..*?Success:\s*(\w+)\..*?Duration:\s*(\d+)ms\.'/g; + const matches = [...stdout.matchAll(toolCallPattern)]; + + for (const match of matches) { + const toolName = match[1]; + const success = match[2] === 'true'; + const duration = parseInt(match[3], 10); + + // Try to find function_args nearby + const matchIndex = match.index || 0; + const contextStart = Math.max(0, matchIndex - 500); + const contextEnd = Math.min(stdout.length, matchIndex + 500); + const context = stdout.substring(contextStart, contextEnd); + + // Look for function_args in the context + let args = '{}'; + const argsMatch = context.match(/function_args:\s*'([^']+)'/); + if (argsMatch) { + args = argsMatch[1]; + } + + // Also try to find function_name to double-check + // Updated regex to handle tool names with hyphens and underscores + const nameMatch = context.match(/function_name:\s*'([\w-]+)'/); + const actualToolName = nameMatch ? nameMatch[1] : toolName; + + logs.push({ + timestamp: Date.now(), + toolRequest: { + name: actualToolName, + args: args, + success: success, + duration_ms: duration, + }, + }); + } + + // If no matches found with the simple pattern, try the JSON parsing approach + // in case the format changes + if (logs.length === 0) { + const lines = stdout.split(os.EOL); + let currentObject = ''; + let inObject = false; + let braceDepth = 0; + + for (const line of lines) { + if (!inObject && line.trim() === '{') { + inObject = true; + braceDepth = 1; + currentObject = line + '\n'; + } else if (inObject) { + currentObject += line + '\n'; + + // Count braces + for (const char of line) { + if (char === '{') braceDepth++; + else if (char === '}') braceDepth--; + } + + // If we've closed all braces, try to parse the object + if (braceDepth === 0) { + inObject = false; + try { + const obj = JSON.parse(currentObject); + + // Check for tool call in different formats + if ( + obj.body && + obj.body.includes('Tool call:') && + obj.attributes + ) { + const bodyMatch = obj.body.match(/Tool call: (\w+)\./); + if (bodyMatch) { + logs.push({ + timestamp: obj.timestamp || Date.now(), + toolRequest: { + name: bodyMatch[1], + args: obj.attributes.function_args || '{}', + success: obj.attributes.success !== false, + duration_ms: obj.attributes.duration_ms || 0, + }, + }); + } + } else if ( + obj.attributes && + obj.attributes['event.name'] === 'gemini_cli.tool_call' + ) { + logs.push({ + timestamp: obj.attributes['event.timestamp'], + toolRequest: { + name: obj.attributes.function_name, + args: obj.attributes.function_args, + success: obj.attributes.success, + duration_ms: obj.attributes.duration_ms, + }, + }); + } + } catch { + // Not valid JSON + } + currentObject = ''; + } + } + } + } + + return logs; + } + + private _readAndParseTelemetryLog(): ParsedLog[] { + // Telemetry is always written to the test directory + const logFilePath = join(this.homeDir!, 'telemetry.log'); + + if (!logFilePath || !fs.existsSync(logFilePath)) { + return []; + } + + const content = readFileSync(logFilePath, 'utf-8'); + + // Split the content into individual JSON objects + // They are separated by "}\n{" + const jsonObjects = content + .split(/}\n{/) + .map((obj, index, array) => { + // Add back the braces we removed during split + if (index > 0) obj = '{' + obj; + if (index < array.length - 1) obj = obj + '}'; + return obj.trim(); + }) + .filter((obj) => obj); + + const logs: ParsedLog[] = []; + + for (const jsonStr of jsonObjects) { + try { + const logData = JSON.parse(jsonStr); + logs.push(logData); + } catch (e) { + // Skip objects that aren't valid JSON + if (env['VERBOSE'] === 'true') { + console.error('Failed to parse telemetry object:', e); + } + } + } + + return logs; + } + + readToolLogs() { + // For Podman, first check if telemetry file exists and has content + // If not, fall back to parsing from stdout + if (env['GEMINI_SANDBOX'] === 'podman') { + // Try reading from file first + const logFilePath = join(this.homeDir!, 'telemetry.log'); + + if (fs.existsSync(logFilePath)) { + try { + const content = readFileSync(logFilePath, 'utf-8'); + if (content && content.includes('"event.name"')) { + // File has content, use normal file parsing + // Continue to the normal file parsing logic below + } else if (this._lastRunStdout) { + // File exists but is empty or doesn't have events, parse from stdout + return this._parseToolLogsFromStdout(this._lastRunStdout); + } + } catch { + // Error reading file, fall back to stdout + if (this._lastRunStdout) { + return this._parseToolLogsFromStdout(this._lastRunStdout); + } + } + } else if (this._lastRunStdout) { + // No file exists, parse from stdout + return this._parseToolLogsFromStdout(this._lastRunStdout); + } + } + + const parsedLogs = this._readAndParseTelemetryLog(); + const logs: { + toolRequest: { + name: string; + args: string; + success: boolean; + duration_ms: number; + }; + }[] = []; + + for (const logData of parsedLogs) { + // Look for tool call logs + if ( + logData.attributes && + logData.attributes['event.name'] === 'gemini_cli.tool_call' + ) { + const toolName = logData.attributes.function_name!; + logs.push({ + toolRequest: { + name: toolName, + args: logData.attributes.function_args ?? '{}', + success: logData.attributes.success ?? false, + duration_ms: logData.attributes.duration_ms ?? 0, + }, + }); + } + } + + return logs; + } + + readAllApiRequest(): ParsedLog[] { + const logs = this._readAndParseTelemetryLog(); + const apiRequests = logs.filter( + (logData) => + logData.attributes && + logData.attributes['event.name'] === `gemini_cli.api_request`, + ); + return apiRequests; + } + + readLastApiRequest(): ParsedLog | null { + const logs = this._readAndParseTelemetryLog(); + const apiRequests = logs.filter( + (logData) => + logData.attributes && + logData.attributes['event.name'] === `gemini_cli.api_request`, + ); + return apiRequests.pop() || null; + } + + async waitForMetric(metricName: string, timeout?: number) { + await this.waitForTelemetryReady(); + + const fullName = metricName.startsWith('gemini_cli.') + ? metricName + : `gemini_cli.${metricName}`; + + return poll( + () => { + const logs = this._readAndParseTelemetryLog(); + for (const logData of logs) { + if (logData.scopeMetrics) { + for (const scopeMetric of logData.scopeMetrics) { + for (const metric of scopeMetric.metrics) { + if (metric.descriptor.name === fullName) { + return true; + } + } + } + } + } + return false; + }, + timeout ?? getDefaultTimeout(), + 100, + ); + } + + readMetric(metricName: string): Record | null { + const logs = this._readAndParseTelemetryLog(); + for (const logData of logs) { + if (logData.scopeMetrics) { + for (const scopeMetric of logData.scopeMetrics) { + for (const metric of scopeMetric.metrics) { + if (metric.descriptor.name === `gemini_cli.${metricName}`) { + return metric; + } + } + } + } + } + return null; + } + + async runInteractive(options?: { + args?: string | string[]; + yolo?: boolean; + env?: Record; + }): Promise { + const yolo = options?.yolo !== false; + const { command, initialArgs } = this._getCommandAndArgs( + yolo ? ['--yolo'] : [], + ); + const commandArgs = [...initialArgs]; + + const envVars = { + ...process.env, + GEMINI_CLI_HOME: this.homeDir!, + ...options?.env, + }; + + const ptyOptions: pty.IPtyForkOptions = { + name: 'xterm-color', + cols: 80, + rows: 80, + cwd: this.testDir!, + env: Object.fromEntries( + Object.entries(envVars).filter(([, v]) => v !== undefined), + ) as { [key: string]: string }, + }; + + const executable = command === 'node' ? process.execPath : command; + const ptyProcess = pty.spawn(executable, commandArgs, ptyOptions); + + const run = new InteractiveRun(ptyProcess); + this._interactiveRuns.push(run); + // Wait for the app to be ready + await run.expectText(' Type your message or @path/to/file', 30000); + return run; + } + + readHookLogs() { + const parsedLogs = this._readAndParseTelemetryLog(); + const logs: { + hookCall: { + hook_event_name: string; + hook_name: string; + hook_input: Record; + hook_output: Record; + exit_code: number; + stdout: string; + stderr: string; + duration_ms: number; + success: boolean; + error: string; + }; + }[] = []; + + for (const logData of parsedLogs) { + // Look for tool call logs + if ( + logData.attributes && + logData.attributes['event.name'] === 'gemini_cli.hook_call' + ) { + logs.push({ + hookCall: { + hook_event_name: logData.attributes.hook_event_name ?? '', + hook_name: logData.attributes.hook_name ?? '', + hook_input: logData.attributes.hook_input ?? {}, + hook_output: logData.attributes.hook_output ?? {}, + exit_code: logData.attributes.exit_code ?? 0, + stdout: logData.attributes.stdout ?? '', + stderr: logData.attributes.stderr ?? '', + duration_ms: logData.attributes.duration_ms ?? 0, + success: logData.attributes.success ?? false, + error: logData.attributes.error ?? '', + }, + }); + } + } + + return logs; + } + + async pollCommand( + commandFn: () => Promise, + predicateFn: () => boolean, + timeout: number = 30000, + interval: number = 1000, + ) { + const startTime = Date.now(); + while (Date.now() - startTime < timeout) { + await commandFn(); + // Give it a moment to process + await sleep(500); + if (predicateFn()) { + return; + } + await sleep(interval); + } + throw new Error(`pollCommand timed out after ${timeout}ms`); + } +} From 66e7b479ae427d77d9634ad5c87d8e3229afbcc7 Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Wed, 14 Jan 2026 07:08:05 +0000 Subject: [PATCH 173/713] Aggregate test results. (#16581) --- .github/workflows/evals-nightly.yml | 35 +++++ evals/README.md | 40 ++++++ evals/save_memory.eval.ts | 1 - evals/test-helper.ts | 11 +- evals/vitest.config.ts | 5 +- scripts/aggregate_evals.js | 212 ++++++++++++++++++++++++++++ 6 files changed, 295 insertions(+), 9 deletions(-) create mode 100644 scripts/aggregate_evals.js diff --git a/.github/workflows/evals-nightly.yml b/.github/workflows/evals-nightly.yml index 6d44de7c12..40c42e2b07 100644 --- a/.github/workflows/evals-nightly.yml +++ b/.github/workflows/evals-nightly.yml @@ -13,11 +13,16 @@ on: permissions: contents: 'read' checks: 'write' + actions: 'read' jobs: evals: name: 'Evals (USUALLY_PASSING) nightly run' runs-on: 'gemini-cli-ubuntu-16-core' + strategy: + fail-fast: false + matrix: + run_attempt: [1, 2, 3] steps: - name: 'Checkout' uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 @@ -34,8 +39,38 @@ jobs: - name: 'Build project' run: 'npm run build' + - name: 'Create logs directory' + run: 'mkdir -p evals/logs' + - name: 'Run Evals' env: GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}' RUN_EVALS: "${{ github.event.inputs.run_all != 'false' }}" run: 'npm run test:all_evals' + + - name: 'Upload Logs' + if: 'always()' + uses: 'actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02' # ratchet:actions/upload-artifact@v4 + with: + name: 'eval-logs-${{ matrix.run_attempt }}' + path: 'evals/logs' + retention-days: 7 + + aggregate-results: + name: 'Aggregate Results' + needs: ['evals'] + if: 'always()' + runs-on: 'gemini-cli-ubuntu-16-core' + steps: + - name: 'Checkout' + uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 + + - name: 'Download Logs' + uses: 'actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806' # ratchet:actions/download-artifact@v4 + with: + path: 'artifacts' + + - name: 'Generate Summary' + env: + GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + run: 'node scripts/aggregate_evals.js artifacts >> "$GITHUB_STEP_SUMMARY"' diff --git a/evals/README.md b/evals/README.md index a339af842f..891a9549f5 100644 --- a/evals/README.md +++ b/evals/README.md @@ -46,6 +46,12 @@ two arguments: #### Policies +Policies control how strictly a test is validated. Tests should generally use +the ALWAYS_PASSES policy to offer the strictest guarantees. + +USUALLY_PASSES exists to enable assertion of less consistent or aspirational +behaviors. + - `ALWAYS_PASSES`: Tests expected to pass 100% of the time. These are typically trivial and test basic functionality. These run in every CI. - `USUALLY_PASSES`: Tests expected to pass most of the time but may have some @@ -100,3 +106,37 @@ npm run test:all_evals This command sets the `RUN_EVALS` environment variable to `1`, which enables the `USUALLY_PASSES` tests. + +## Reporting + +Results for evaluations are available on GitHub Actions: + +- **CI Evals**: Included in the + [E2E (Chained)](https://github.com/google-gemini/gemini-cli/actions/workflows/chained_e2e.yml) + workflow. These must pass 100% for every PR. +- **Nightly Evals**: Run daily via the + [Evals: Nightly](https://github.com/google-gemini/gemini-cli/actions/workflows/evals-nightly.yml) + workflow. These track the long-term health and stability of model steering. + +### Nightly Report Format + +The nightly workflow executes the full evaluation suite multiple times +(currently 3 attempts) to account for non-determinism. These results are +aggregated into a **Nightly Summary** attached to the workflow run. + +#### How to interpret the report: + +- **Pass Rate (%)**: Each cell represents the percentage of successful runs for + a specific test in that workflow instance. +- **History**: The table shows the pass rates for the last 10 nightly runs, + allowing you to identify if a model's behavior is trending towards + instability. +- **Total Pass Rate**: An aggregate metric of all evaluations run in that batch. + +A significant drop in the pass rate for a `USUALLY_PASSES` test—even if it +doesn't drop to 0%—often indicates that a recent change to a system prompt or +tool definition has made the model's behavior less reliable. + +You may be able to investigate the regression using Gemini CLI by giving it the +link to the runs before and after the change and the name of the test and asking +it to investigate what changes may have impacted the test. diff --git a/evals/save_memory.eval.ts b/evals/save_memory.eval.ts index a64f21798a..48658113ce 100644 --- a/evals/save_memory.eval.ts +++ b/evals/save_memory.eval.ts @@ -11,7 +11,6 @@ import { validateModelOutput } from '../integration-tests/test-helper.js'; describe('save_memory', () => { evalTest('ALWAYS_PASSES', { name: 'should be able to save to memory', - log: true, params: { settings: { tools: { core: ['save_memory'] } }, }, diff --git a/evals/test-helper.ts b/evals/test-helper.ts index f394521d1e..9801d2307b 100644 --- a/evals/test-helper.ts +++ b/evals/test-helper.ts @@ -36,12 +36,10 @@ export function evalTest(policy: EvalPolicy, evalCase: EvalCase) { const result = await rig.run({ args: evalCase.prompt }); await evalCase.assert(rig, result); } finally { - if (evalCase.log) { - await logToFile( - evalCase.name, - JSON.stringify(rig.readToolLogs(), null, 2), - ); - } + await logToFile( + evalCase.name, + JSON.stringify(rig.readToolLogs(), null, 2), + ); await rig.cleanup(); } }; @@ -58,7 +56,6 @@ export interface EvalCase { params?: Record; prompt: string; assert: (rig: TestRig, result: string) => Promise; - log?: boolean; } async function logToFile(name: string, content: string) { diff --git a/evals/vitest.config.ts b/evals/vitest.config.ts index 8476b638ff..2c59682f16 100644 --- a/evals/vitest.config.ts +++ b/evals/vitest.config.ts @@ -9,7 +9,10 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { testTimeout: 300000, // 5 minutes - reporters: ['default'], + reporters: ['default', 'json'], + outputFile: { + json: 'evals/logs/report.json', + }, include: ['**/*.eval.ts'], }, }); diff --git a/scripts/aggregate_evals.js b/scripts/aggregate_evals.js new file mode 100644 index 0000000000..4a9fba02eb --- /dev/null +++ b/scripts/aggregate_evals.js @@ -0,0 +1,212 @@ +#!/usr/bin/env node + +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import fs from 'node:fs'; +import path from 'node:path'; +import { execSync } from 'node:child_process'; +import os from 'node:os'; + +const artifactsDir = process.argv[2] || '.'; +const MAX_HISTORY = 10; + +// Find all report.json files recursively +function findReports(dir) { + const reports = []; + if (!fs.existsSync(dir)) return reports; + + const files = fs.readdirSync(dir); + for (const file of files) { + const fullPath = path.join(dir, file); + const stat = fs.statSync(fullPath); + if (stat.isDirectory()) { + reports.push(...findReports(fullPath)); + } else if (file === 'report.json') { + reports.push(fullPath); + } + } + return reports; +} + +function getStats(reports) { + const testStats = {}; + + for (const reportPath of reports) { + try { + const content = fs.readFileSync(reportPath, 'utf-8'); + const json = JSON.parse(content); + + for (const testResult of json.testResults) { + for (const assertion of testResult.assertionResults) { + const name = assertion.title; + if (!testStats[name]) { + testStats[name] = { passed: 0, failed: 0, total: 0 }; + } + testStats[name].total++; + if (assertion.status === 'passed') { + testStats[name].passed++; + } else { + testStats[name].failed++; + } + } + } + } catch (error) { + console.error(`Error processing report at ${reportPath}:`, error); + } + } + return testStats; +} + +function fetchHistoricalData() { + const history = []; + + try { + // Determine branch + const branch = 'main'; + + // Get recent runs + const cmd = `gh run list --workflow evals-nightly.yml --branch "${branch}" --limit ${ + MAX_HISTORY + 5 + } --json databaseId,createdAt,url,displayTitle,status,conclusion`; + const runsJson = execSync(cmd, { encoding: 'utf-8' }); + let runs = JSON.parse(runsJson); + + // Filter out current run + const currentRunId = process.env.GITHUB_RUN_ID; + if (currentRunId) { + runs = runs.filter((r) => r.databaseId.toString() !== currentRunId); + } + + // Filter for runs that likely have artifacts (completed) and take top N + // We accept 'failure' too because we want to see stats. + runs = runs.filter((r) => r.status === 'completed').slice(0, MAX_HISTORY); + + // Fetch artifacts for each run + for (const run of runs) { + const tmpDir = fs.mkdtempSync( + path.join(os.tmpdir(), `gemini-evals-${run.databaseId}-`), + ); + try { + // Download report.json files. + // The artifacts are named 'eval-logs-X'. + // We use -p to match pattern. + execSync( + `gh run download ${run.databaseId} -p "eval-logs-*" -D "${tmpDir}"`, + { stdio: 'ignore' }, + ); + + const runReports = findReports(tmpDir); + if (runReports.length > 0) { + history.push({ + run, + stats: getStats(runReports), + }); + } + } catch (error) { + console.error( + `Failed to download or process artifacts for run ${run.databaseId}:`, + error, + ); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + } + } catch (error) { + console.error('Failed to fetch historical data:', error); + } + + return history; +} + +function generateMarkdown(currentStats, history) { + const totalStats = Object.values(currentStats).reduce( + (acc, stats) => { + acc.passed += stats.passed; + acc.total += stats.total; + return acc; + }, + { passed: 0, total: 0 }, + ); + + const totalPassRate = + totalStats.total > 0 + ? ((totalStats.passed / totalStats.total) * 100).toFixed(1) + '%' + : 'N/A'; + + console.log('### Evals Nightly Summary'); + console.log(`**Total Pass Rate: ${totalPassRate}**\n`); + console.log( + 'See [evals/README.md](https://github.com/google-gemini/gemini-cli/tree/main/evals) for more details.\n', + ); + + // Reverse history to show oldest first + const reversedHistory = [...history].reverse(); + + // Header + let header = '| Test Name |'; + let separator = '| :--- |'; + + for (const item of reversedHistory) { + header += ` [${item.run.databaseId}](${item.run.url}) |`; + separator += ' :---: |'; + } + + // Add Current column last + header += ' Current |'; + separator += ' :---: |'; + + console.log(header); + console.log(separator); + + // Collect all test names + const allTestNames = new Set(Object.keys(currentStats)); + for (const item of reversedHistory) { + Object.keys(item.stats).forEach((name) => allTestNames.add(name)); + } + + for (const name of Array.from(allTestNames).sort()) { + const searchUrl = `https://github.com/search?q=repo%3Agoogle-gemini%2Fgemini-cli%20%22${encodeURIComponent(name)}%22&type=code`; + let row = `| [${name}](${searchUrl}) |`; + + // History + for (const item of reversedHistory) { + const stat = item.stats[name]; + if (stat) { + const passRate = ((stat.passed / stat.total) * 100).toFixed(0) + '%'; + row += ` ${passRate} |`; + } else { + row += ' - |'; + } + } + + // Current + const curr = currentStats[name]; + if (curr) { + const passRate = ((curr.passed / curr.total) * 100).toFixed(0) + '%'; + row += ` ${passRate} |`; + } else { + row += ' - |'; + } + + console.log(row); + } +} + +// --- Main --- + +const currentReports = findReports(artifactsDir); +if (currentReports.length === 0) { + console.log('No reports found.'); + // We don't exit here because we might still want to see history if available, + // but practically if current has no reports, something is wrong. + // Sticking to original behavior roughly, but maybe we can continue. + process.exit(0); +} + +const currentStats = getStats(currentReports); +const history = fetchHistoricalData(); +generateMarkdown(currentStats, history); From bb6c57414434ecc6272bec40f5b1d4f0917b2f87 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 13 Jan 2026 23:40:23 -0800 Subject: [PATCH 174/713] feat(admin): support admin-enforced settings for Agent Skills (#16406) --- docs/get-started/configuration.md | 4 ++ packages/cli/src/config/config.ts | 5 ++ .../config/extension-manager-agents.test.ts | 7 +- .../config/extension-manager-scope.test.ts | 14 ++++ .../config/extension-manager-skills.test.ts | 6 ++ packages/cli/src/config/extension.test.ts | 11 +++ packages/cli/src/config/settings.ts | 20 +++--- packages/cli/src/config/settingsSchema.ts | 22 ++++++ .../cli/src/services/BuiltinCommandLoader.ts | 21 +++++- .../cli/src/ui/commands/memoryCommand.test.ts | 51 ++++++++++++++ .../cli/src/ui/commands/skillsCommand.test.ts | 38 ++++++++++ packages/cli/src/ui/commands/skillsCommand.ts | 34 +++++++-- .../src/ui/hooks/useExtensionUpdates.test.tsx | 17 ++++- packages/core/src/config/config.test.ts | 25 +++++++ packages/core/src/config/config.ts | 69 ++++++++++++------- packages/core/src/policy/config.test.ts | 6 +- packages/core/src/skills/skillManager.test.ts | 18 ++++- packages/core/src/skills/skillManager.ts | 15 ++++ .../core/src/utils/workspaceContext.test.ts | 2 +- schemas/settings.schema.json | 17 +++++ 20 files changed, 350 insertions(+), 52 deletions(-) diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 93bcefa778..a3842a3b1f 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -974,6 +974,10 @@ their corresponding top-level category object in your `settings.json` file. - **`admin.mcp.enabled`** (boolean): - **Description:** If false, disallows MCP servers from being used. - **Default:** `true` + +- **`admin.skills.enabled`** (boolean): + - **Description:** If false, disallows agent skills from being used. + - **Default:** `true` #### `mcpServers` diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index c10fd2518e..a339e8ccc5 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -637,6 +637,7 @@ export async function loadCliConfig( const mcpEnabled = settings.admin?.mcp?.enabled ?? true; const extensionsEnabled = settings.admin?.extensions?.enabled ?? true; + const adminSkillsEnabled = settings.admin?.skills?.enabled ?? true; return new Config({ sessionId, @@ -661,6 +662,7 @@ export async function loadCliConfig( mcpEnabled, extensionsEnabled, agents: settings.agents, + adminSkillsEnabled, allowedMcpServers: mcpEnabled ? (argv.allowedMcpServerNames ?? settings.mcp?.allowed) : undefined, @@ -708,6 +710,7 @@ export async function loadCliConfig( enableAgents: settings.experimental?.enableAgents, skillsSupport: settings.experimental?.skills, disabledSkills: settings.skills?.disabled, + experimentalJitContext: settings.experimental?.jitContext, noBrowser: !!process.env['NO_BROWSER'], summarizeToolOutput: settings.model?.summarizeToolOutput, @@ -750,6 +753,8 @@ export async function loadCliConfig( const refreshedSettings = loadSettings(cwd); return { disabledSkills: refreshedSettings.merged.skills?.disabled, + adminSkillsEnabled: + refreshedSettings.merged.admin?.skills?.enabled ?? adminSkillsEnabled, }; }, }); diff --git a/packages/cli/src/config/extension-manager-agents.test.ts b/packages/cli/src/config/extension-manager-agents.test.ts index 936d3fea10..7ae845875f 100644 --- a/packages/cli/src/config/extension-manager-agents.test.ts +++ b/packages/cli/src/config/extension-manager-agents.test.ts @@ -26,11 +26,12 @@ vi.mock('node:os', async (importOriginal) => { // Mock @google/gemini-cli-core vi.mock('@google/gemini-cli-core', async (importOriginal) => { - const actual = - await importOriginal(); + const core = await importOriginal(); return { - ...actual, + ...core, homedir: mockHomedir, + loadAgentsFromDirectory: core.loadAgentsFromDirectory, + loadSkillsFromDir: core.loadSkillsFromDir, }; }); diff --git a/packages/cli/src/config/extension-manager-scope.test.ts b/packages/cli/src/config/extension-manager-scope.test.ts index a42e198bd0..a9e0738c87 100644 --- a/packages/cli/src/config/extension-manager-scope.test.ts +++ b/packages/cli/src/config/extension-manager-scope.test.ts @@ -10,6 +10,10 @@ import * as path from 'node:path'; import * as os from 'node:os'; import { ExtensionManager } from './extension-manager.js'; import type { Settings } from './settings.js'; +import { + loadAgentsFromDirectory, + loadSkillsFromDir, +} from '@google/gemini-cli-core'; let currentTempHome = ''; @@ -24,6 +28,11 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { error: vi.fn(), warn: vi.fn(), }, + loadAgentsFromDirectory: vi.fn().mockImplementation(async () => ({ + agents: [], + errors: [], + })), + loadSkillsFromDir: vi.fn().mockImplementation(async () => []), }; }); @@ -34,6 +43,11 @@ describe('ExtensionManager Settings Scope', () => { let extensionDir: string; beforeEach(async () => { + vi.mocked(loadAgentsFromDirectory).mockResolvedValue({ + agents: [], + errors: [], + }); + vi.mocked(loadSkillsFromDir).mockResolvedValue([]); currentTempHome = fs.mkdtempSync( path.join(os.tmpdir(), 'gemini-cli-test-home-'), ); diff --git a/packages/cli/src/config/extension-manager-skills.test.ts b/packages/cli/src/config/extension-manager-skills.test.ts index 526db275e2..ecc0dfa3c0 100644 --- a/packages/cli/src/config/extension-manager-skills.test.ts +++ b/packages/cli/src/config/extension-manager-skills.test.ts @@ -31,6 +31,12 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { return { ...actual, homedir: mockHomedir, + loadAgentsFromDirectory: vi + .fn() + .mockImplementation(async () => ({ agents: [], errors: [] })), + loadSkillsFromDir: ( + await importOriginal() + ).loadSkillsFromDir, }; }); diff --git a/packages/cli/src/config/extension.test.ts b/packages/cli/src/config/extension.test.ts index 1807144e82..d1999d60c8 100644 --- a/packages/cli/src/config/extension.test.ts +++ b/packages/cli/src/config/extension.test.ts @@ -23,6 +23,8 @@ import { ExtensionDisableEvent, ExtensionEnableEvent, KeychainTokenStorage, + loadAgentsFromDirectory, + loadSkillsFromDir, } from '@google/gemini-cli-core'; import { loadSettings, SettingScope } from './settings.js'; import { @@ -117,6 +119,10 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { listSecrets: vi.fn(), isAvailable: vi.fn().mockResolvedValue(true), })), + loadAgentsFromDirectory: vi + .fn() + .mockImplementation(async () => ({ agents: [], errors: [] })), + loadSkillsFromDir: vi.fn().mockImplementation(async () => []), }; }); @@ -171,6 +177,11 @@ describe('extension tests', () => { ( KeychainTokenStorage as unknown as ReturnType ).mockImplementation(() => mockKeychainStorage); + vi.mocked(loadAgentsFromDirectory).mockResolvedValue({ + agents: [], + errors: [], + }); + vi.mocked(loadSkillsFromDir).mockResolvedValue([]); tempHomeDir = fs.mkdtempSync( path.join(os.tmpdir(), 'gemini-cli-test-home-'), ); diff --git a/packages/cli/src/config/settings.ts b/packages/cli/src/config/settings.ts index 07cc686524..07cd457785 100644 --- a/packages/cli/src/config/settings.ts +++ b/packages/cli/src/config/settings.ts @@ -324,23 +324,19 @@ export class LoadedSettings { setRemoteAdminSettings(remoteSettings: GeminiCodeAssistSetting): void { const admin: Settings['admin'] = {}; + const { secureModeEnabled, mcpSetting, cliFeatureSetting } = remoteSettings; - if (remoteSettings.secureModeEnabled !== undefined) { - admin.secureModeEnabled = remoteSettings.secureModeEnabled; + if (secureModeEnabled !== undefined) { + admin.secureModeEnabled = secureModeEnabled; } - if (remoteSettings.mcpSetting?.mcpEnabled !== undefined) { - admin.mcp = { enabled: remoteSettings.mcpSetting.mcpEnabled }; + if (mcpSetting?.mcpEnabled !== undefined) { + admin.mcp = { enabled: mcpSetting.mcpEnabled }; } - if ( - remoteSettings.cliFeatureSetting?.extensionsSetting?.extensionsEnabled !== - undefined - ) { - admin.extensions = { - enabled: - remoteSettings.cliFeatureSetting.extensionsSetting.extensionsEnabled, - }; + const extensionsSetting = cliFeatureSetting?.extensionsSetting; + if (extensionsSetting?.extensionsEnabled !== undefined) { + admin.extensions = { enabled: extensionsSetting.extensionsEnabled }; } this._remoteAdminSettings = { admin }; diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index c48e49cf01..424f2e1906 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -1842,6 +1842,28 @@ const SETTINGS_SCHEMA = { }, }, }, + skills: { + type: 'object', + label: 'Skills Settings', + category: 'Admin', + requiresRestart: false, + default: {}, + description: 'Agent Skills-specific admin settings.', + showInDialog: false, + mergeStrategy: MergeStrategy.REPLACE, + properties: { + enabled: { + type: 'boolean', + label: 'Skills Enabled', + category: 'Admin', + requiresRestart: false, + default: true, + description: 'If false, disallows agent skills from being used.', + showInDialog: false, + mergeStrategy: MergeStrategy.REPLACE, + }, + }, + }, }, }, } as const satisfies SettingsSchema; diff --git a/packages/cli/src/services/BuiltinCommandLoader.ts b/packages/cli/src/services/BuiltinCommandLoader.ts index 263a17fd3a..5873aec22a 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.ts @@ -139,7 +139,26 @@ export class BuiltinCommandLoader implements ICommandLoader { statsCommand, themeCommand, toolsCommand, - ...(this.config?.isSkillsSupportEnabled() ? [skillsCommand] : []), + ...(this.config?.isSkillsSupportEnabled() + ? this.config?.getSkillManager()?.isAdminEnabled() === false + ? [ + { + name: 'skills', + description: 'Manage agent skills', + kind: CommandKind.BUILT_IN, + autoExecute: false, + subCommands: [], + action: async ( + _context: CommandContext, + ): Promise => ({ + type: 'message', + messageType: 'error', + content: 'Agent skills are disabled by your admin.', + }), + }, + ] + : [skillsCommand] + : []), settingsCommand, vimCommand, setupGithubCommand, diff --git a/packages/cli/src/ui/commands/memoryCommand.test.ts b/packages/cli/src/ui/commands/memoryCommand.test.ts index 63ebb5e36a..642e98569b 100644 --- a/packages/cli/src/ui/commands/memoryCommand.test.ts +++ b/packages/cli/src/ui/commands/memoryCommand.test.ts @@ -16,6 +16,9 @@ import { refreshServerHierarchicalMemory, SimpleExtensionLoader, type FileDiscoveryService, + showMemory, + addMemory, + listMemoryFiles, } from '@google/gemini-cli-core'; vi.mock('@google/gemini-cli-core', async (importOriginal) => { @@ -44,6 +47,9 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { content: 'Memory refreshed successfully.', }; }), + showMemory: vi.fn(), + addMemory: vi.fn(), + listMemoryFiles: vi.fn(), refreshServerHierarchicalMemory: vi.fn(), }; }); @@ -78,6 +84,22 @@ describe('memoryCommand', () => { mockGetUserMemory = vi.fn(); mockGetGeminiMdFileCount = vi.fn(); + vi.mocked(showMemory).mockImplementation((config) => { + const memoryContent = config.getUserMemory() || ''; + const fileCount = config.getGeminiMdFileCount() || 0; + let content; + if (memoryContent.length > 0) { + content = `Current memory content from ${fileCount} file(s):\n\n---\n${memoryContent}\n---`; + } else { + content = 'Memory is currently empty.'; + } + return { + type: 'message', + messageType: 'info', + content, + }; + }); + mockContext = createMockCommandContext({ services: { config: { @@ -131,6 +153,20 @@ describe('memoryCommand', () => { beforeEach(() => { addCommand = getSubCommand('add'); + vi.mocked(addMemory).mockImplementation((args) => { + if (!args || args.trim() === '') { + return { + type: 'message', + messageType: 'error', + content: 'Usage: /memory add ', + }; + } + return { + type: 'tool', + toolName: 'save_memory', + toolArgs: { fact: args.trim() }, + }; + }); mockContext = createMockCommandContext(); }); @@ -360,6 +396,21 @@ describe('memoryCommand', () => { beforeEach(() => { listCommand = getSubCommand('list'); mockGetGeminiMdfilePaths = vi.fn(); + vi.mocked(listMemoryFiles).mockImplementation((config) => { + const filePaths = config.getGeminiMdFilePaths() || []; + const fileCount = filePaths.length; + let content; + if (fileCount > 0) { + content = `There are ${fileCount} GEMINI.md file(s) in use:\n\n${filePaths.join('\n')}`; + } else { + content = 'No GEMINI.md files in use.'; + } + return { + type: 'message', + messageType: 'info', + content, + }; + }); mockContext = createMockCommandContext({ services: { config: { diff --git a/packages/cli/src/ui/commands/skillsCommand.test.ts b/packages/cli/src/ui/commands/skillsCommand.test.ts index df11195889..d6e0bb30b7 100644 --- a/packages/cli/src/ui/commands/skillsCommand.test.ts +++ b/packages/cli/src/ui/commands/skillsCommand.test.ts @@ -46,6 +46,7 @@ describe('skillsCommand', () => { getSkillManager: vi.fn().mockReturnValue({ getAllSkills: vi.fn().mockReturnValue(skills), getSkills: vi.fn().mockReturnValue(skills), + isAdminEnabled: vi.fn().mockReturnValue(true), getSkill: vi .fn() .mockImplementation( @@ -307,6 +308,43 @@ describe('skillsCommand', () => { type: MessageType.ERROR, text: 'Skill "non-existent" not found.', }), + expect.any(Number), + ); + }); + + it('should show error if skills are disabled by admin during disable', async () => { + const skillManager = context.services.config!.getSkillManager(); + vi.mocked(skillManager.isAdminEnabled).mockReturnValue(false); + + const disableCmd = skillsCommand.subCommands!.find( + (s) => s.name === 'disable', + )!; + await disableCmd.action!(context, 'skill1'); + + expect(context.ui.addItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.ERROR, + text: 'Agent skills are disabled by your admin.', + }), + expect.any(Number), + ); + }); + + it('should show error if skills are disabled by admin during enable', async () => { + const skillManager = context.services.config!.getSkillManager(); + vi.mocked(skillManager.isAdminEnabled).mockReturnValue(false); + + const enableCmd = skillsCommand.subCommands!.find( + (s) => s.name === 'enable', + )!; + await enableCmd.action!(context, 'skill1'); + + expect(context.ui.addItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.ERROR, + text: 'Agent skills are disabled by your admin.', + }), + expect.any(Number), ); }); }); diff --git a/packages/cli/src/ui/commands/skillsCommand.ts b/packages/cli/src/ui/commands/skillsCommand.ts index f632501eee..ee79a6c368 100644 --- a/packages/cli/src/ui/commands/skillsCommand.ts +++ b/packages/cli/src/ui/commands/skillsCommand.ts @@ -79,12 +79,26 @@ async function disableAction( return; } const skillManager = context.services.config?.getSkillManager(); + if (skillManager?.isAdminEnabled() === false) { + context.ui.addItem( + { + type: MessageType.ERROR, + text: 'Agent skills are disabled by your admin.', + }, + Date.now(), + ); + return; + } + const skill = skillManager?.getSkill(skillName); if (!skill) { - context.ui.addItem({ - type: MessageType.ERROR, - text: `Skill "${skillName}" not found.`, - }); + context.ui.addItem( + { + type: MessageType.ERROR, + text: `Skill "${skillName}" not found.`, + }, + Date.now(), + ); return; } @@ -121,6 +135,18 @@ async function enableAction( return; } + const skillManager = context.services.config?.getSkillManager(); + if (skillManager?.isAdminEnabled() === false) { + context.ui.addItem( + { + type: MessageType.ERROR, + text: 'Agent skills are disabled by your admin.', + }, + Date.now(), + ); + return; + } + const result = enableSkill(context.services.settings, skillName); let feedback = renderSkillActionFeedback( diff --git a/packages/cli/src/ui/hooks/useExtensionUpdates.test.tsx b/packages/cli/src/ui/hooks/useExtensionUpdates.test.tsx index 5e78f4c4d6..a558686bd8 100644 --- a/packages/cli/src/ui/hooks/useExtensionUpdates.test.tsx +++ b/packages/cli/src/ui/hooks/useExtensionUpdates.test.tsx @@ -4,13 +4,17 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { vi } from 'vitest'; +import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest'; import * as fs from 'node:fs'; import * as os from 'node:os'; import * as path from 'node:path'; import { createExtension } from '../../test-utils/createExtension.js'; import { useExtensionUpdates } from './useExtensionUpdates.js'; -import { GEMINI_DIR } from '@google/gemini-cli-core'; +import { + GEMINI_DIR, + loadAgentsFromDirectory, + loadSkillsFromDir, +} from '@google/gemini-cli-core'; import { render } from '../../test-utils/render.js'; import { waitFor } from '../../test-utils/async.js'; import { MessageType } from '../types.js'; @@ -36,6 +40,10 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { return { ...actual, homedir: () => os.homedir(), + loadAgentsFromDirectory: vi + .fn() + .mockResolvedValue({ agents: [], errors: [] }), + loadSkillsFromDir: vi.fn().mockResolvedValue([]), }; }); @@ -51,6 +59,11 @@ describe('useExtensionUpdates', () => { let extensionManager: ExtensionManager; beforeEach(() => { + vi.mocked(loadAgentsFromDirectory).mockResolvedValue({ + agents: [], + errors: [], + }); + vi.mocked(loadSkillsFromDir).mockResolvedValue([]); tempHomeDir = fs.mkdtempSync( path.join(os.tmpdir(), 'gemini-cli-test-home-'), ); diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index 384e97cbb2..ab389bea01 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -2091,5 +2091,30 @@ describe('Config JIT Initialization', () => { expect(skillManager.setDisabledSkills).toHaveBeenCalledWith([]); }); + + it('should update admin settings from onReload', async () => { + const mockOnReload = vi.fn().mockResolvedValue({ + adminSkillsEnabled: false, + }); + const params: ConfigParameters = { + sessionId: 'test-session', + targetDir: '/tmp/test', + debugMode: false, + model: 'test-model', + cwd: '/tmp/test', + skillsSupport: true, + onReload: mockOnReload, + }; + + config = new Config(params); + await config.initialize(); + + const skillManager = config.getSkillManager(); + vi.spyOn(skillManager, 'setAdminSettings'); + + await config.reloadSkills(); + + expect(skillManager.setAdminSettings).toHaveBeenCalledWith(false); + }); }); }); diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 6dce2f7403..5db98732b1 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -377,13 +377,17 @@ export interface ConfigParameters { enableAgents?: boolean; skillsSupport?: boolean; disabledSkills?: string[]; + adminSkillsEnabled?: boolean; experimentalJitContext?: boolean; disableLLMCorrection?: boolean; onModelChange?: (model: string) => void; mcpEnabled?: boolean; extensionsEnabled?: boolean; agents?: AgentSettings; - onReload?: () => Promise<{ disabledSkills?: string[] }>; + onReload?: () => Promise<{ + disabledSkills?: string[]; + adminSkillsEnabled?: boolean; + }>; } export class Config { @@ -511,13 +515,17 @@ export class Config { private hookSystem?: HookSystem; private readonly onModelChange: ((model: string) => void) | undefined; private readonly onReload: - | (() => Promise<{ disabledSkills?: string[] }>) + | (() => Promise<{ + disabledSkills?: string[]; + adminSkillsEnabled?: boolean; + }>) | undefined; private readonly enableAgents: boolean; private readonly agents: AgentSettings; private readonly skillsSupport: boolean; private disabledSkills: string[]; + private readonly adminSkillsEnabled: boolean; private readonly experimentalJitContext: boolean; private readonly disableLLMCorrection: boolean; @@ -594,6 +602,7 @@ export class Config { this.disableLLMCorrection = params.disableLLMCorrection ?? false; this.skillsSupport = params.skillsSupport ?? false; this.disabledSkills = params.disabledSkills ?? []; + this.adminSkillsEnabled = params.adminSkillsEnabled ?? true; this.modelAvailabilityService = new ModelAvailabilityService(); this.previewFeatures = params.previewFeatures ?? undefined; this.experimentalJitContext = params.experimentalJitContext ?? false; @@ -777,20 +786,22 @@ export class Config { ]); initMcpHandle?.end(); - // Discover skills if enabled if (this.skillsSupport) { - await this.getSkillManager().discoverSkills( - this.storage, - this.getExtensions(), - ); - this.getSkillManager().setDisabledSkills(this.disabledSkills); - - // Re-register ActivateSkillTool to update its schema with the discovered enabled skill enums - if (this.getSkillManager().getSkills().length > 0) { - this.getToolRegistry().unregisterTool(ActivateSkillTool.Name); - this.getToolRegistry().registerTool( - new ActivateSkillTool(this, this.messageBus), + this.getSkillManager().setAdminSettings(this.adminSkillsEnabled); + if (this.adminSkillsEnabled) { + await this.getSkillManager().discoverSkills( + this.storage, + this.getExtensions(), ); + this.getSkillManager().setDisabledSkills(this.disabledSkills); + + // Re-register ActivateSkillTool to update its schema with the discovered enabled skill enums + if (this.getSkillManager().getSkills().length > 0) { + this.getToolRegistry().unregisterTool(ActivateSkillTool.Name); + this.getToolRegistry().registerTool( + new ActivateSkillTool(this, this.messageBus), + ); + } } } @@ -1593,21 +1604,29 @@ export class Config { if (this.onReload) { const refreshed = await this.onReload(); this.disabledSkills = refreshed.disabledSkills ?? []; + this.getSkillManager().setAdminSettings( + refreshed.adminSkillsEnabled ?? this.adminSkillsEnabled, + ); } - await this.getSkillManager().discoverSkills( - this.storage, - this.getExtensions(), - ); - this.getSkillManager().setDisabledSkills(this.disabledSkills); - - // Re-register ActivateSkillTool to update its schema with the newly discovered skills - if (this.getSkillManager().getSkills().length > 0) { - this.getToolRegistry().unregisterTool(ActivateSkillTool.Name); - this.getToolRegistry().registerTool( - new ActivateSkillTool(this, this.messageBus), + if (this.getSkillManager().isAdminEnabled()) { + await this.getSkillManager().discoverSkills( + this.storage, + this.getExtensions(), ); + this.getSkillManager().setDisabledSkills(this.disabledSkills); + + // Re-register ActivateSkillTool to update its schema with the newly discovered skills + if (this.getSkillManager().getSkills().length > 0) { + this.getToolRegistry().unregisterTool(ActivateSkillTool.Name); + this.getToolRegistry().registerTool( + new ActivateSkillTool(this, this.messageBus), + ); + } else { + this.getToolRegistry().unregisterTool(ActivateSkillTool.Name); + } } else { + this.getSkillManager().clearSkills(); this.getToolRegistry().unregisterTool(ActivateSkillTool.Name); } diff --git a/packages/core/src/policy/config.test.ts b/packages/core/src/policy/config.test.ts index a3e6126734..608f1c51c7 100644 --- a/packages/core/src/policy/config.test.ts +++ b/packages/core/src/policy/config.test.ts @@ -11,8 +11,6 @@ import nodePath from 'node:path'; import type { PolicySettings } from './types.js'; import { ApprovalMode, PolicyDecision, InProcessCheckerType } from './types.js'; -import { Storage } from '../config/storage.js'; - afterEach(() => { vi.clearAllMocks(); vi.restoreAllMocks(); @@ -20,7 +18,9 @@ afterEach(() => { }); describe('createPolicyEngineConfig', () => { - beforeEach(() => { + beforeEach(async () => { + vi.resetModules(); + const { Storage } = await import('../config/storage.js'); // Mock Storage to avoid picking up real user/system policies from the host environment vi.spyOn(Storage, 'getUserPoliciesDir').mockReturnValue( '/non/existent/user/policies', diff --git a/packages/core/src/skills/skillManager.test.ts b/packages/core/src/skills/skillManager.test.ts index ca3652a489..5635ddf4c3 100644 --- a/packages/core/src/skills/skillManager.test.ts +++ b/packages/core/src/skills/skillManager.test.ts @@ -189,7 +189,7 @@ description: project-desc name: skill1 description: desc1 --- -`, +body1`, ); const storage = new Storage('/dummy'); @@ -247,4 +247,20 @@ description: desc1 expect(enabled).toHaveLength(2); expect(enabled.map((s) => s.name)).toContain('builtin-skill'); }); + + it('should maintain admin settings state', async () => { + const service = new SkillManager(); + + // Case 1: Enabled by admin + + service.setAdminSettings(true); + + expect(service.isAdminEnabled()).toBe(true); + + // Case 2: Disabled by admin + + service.setAdminSettings(false); + + expect(service.isAdminEnabled()).toBe(false); + }); }); diff --git a/packages/core/src/skills/skillManager.ts b/packages/core/src/skills/skillManager.ts index 6d301bd2f4..f14a9de78d 100644 --- a/packages/core/src/skills/skillManager.ts +++ b/packages/core/src/skills/skillManager.ts @@ -15,6 +15,7 @@ export { type SkillDefinition }; export class SkillManager { private skills: SkillDefinition[] = []; private activeSkillNames: Set = new Set(); + private adminSkillsEnabled = true; /** * Clears all discovered skills. @@ -23,6 +24,20 @@ export class SkillManager { this.skills = []; } + /** + * Sets administrative settings for skills. + */ + setAdminSettings(enabled: boolean): void { + this.adminSkillsEnabled = enabled; + } + + /** + * Returns true if skills are enabled by the admin. + */ + isAdminEnabled(): boolean { + return this.adminSkillsEnabled; + } + /** * Discovers skills from standard user and project locations, as well as extensions. * Precedence: Extensions (lowest) -> User -> Project (highest). diff --git a/packages/core/src/utils/workspaceContext.test.ts b/packages/core/src/utils/workspaceContext.test.ts index 1580aa32d9..6c01a2ab8b 100644 --- a/packages/core/src/utils/workspaceContext.test.ts +++ b/packages/core/src/utils/workspaceContext.test.ts @@ -278,7 +278,7 @@ describe('WorkspaceContext with real filesystem', () => { // handle it gracefully and return false. expect(workspaceContext.isPathWithinWorkspace(linkA)).toBe(false); expect(workspaceContext.isPathWithinWorkspace(linkB)).toBe(false); - }); + }, 30000); }); }); diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index 2c3effa172..1e3e1f0923 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -1697,6 +1697,23 @@ } }, "additionalProperties": false + }, + "skills": { + "title": "Skills Settings", + "description": "Agent Skills-specific admin settings.", + "markdownDescription": "Agent Skills-specific admin settings.\n\n- Category: `Admin`\n- Requires restart: `no`\n- Default: `{}`", + "default": {}, + "type": "object", + "properties": { + "enabled": { + "title": "Skills Enabled", + "description": "If false, disallows agent skills from being used.", + "markdownDescription": "If false, disallows agent skills from being used.\n\n- Category: `Admin`\n- Requires restart: `no`\n- Default: `true`", + "default": true, + "type": "boolean" + } + }, + "additionalProperties": false } }, "additionalProperties": false From c8d7c09ca45a38827e22508c9afa5f14669f08a8 Mon Sep 17 00:00:00 2001 From: Krushna Korade Date: Wed, 14 Jan 2026 19:02:36 +0530 Subject: [PATCH 175/713] fix: PDF token estimation (#16494) (#16527) Co-authored-by: Jack Wotherspoon --- .../core/src/utils/tokenCalculation.test.ts | 36 +++++++++++++++++++ packages/core/src/utils/tokenCalculation.ts | 11 ++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/packages/core/src/utils/tokenCalculation.test.ts b/packages/core/src/utils/tokenCalculation.test.ts index c6e54bc887..126ef7bac2 100644 --- a/packages/core/src/utils/tokenCalculation.test.ts +++ b/packages/core/src/utils/tokenCalculation.test.ts @@ -145,4 +145,40 @@ describe('calculateRequestTokenCount', () => { expect(count).toBe(3000); }); + + it('should use countTokens API for PDF requests', async () => { + vi.mocked(mockContentGenerator.countTokens).mockResolvedValue({ + totalTokens: 5160, + }); + const request = [ + { inlineData: { mimeType: 'application/pdf', data: 'pdf_data' } }, + ]; + + const count = await calculateRequestTokenCount( + request, + mockContentGenerator, + model, + ); + + expect(count).toBe(5160); + expect(mockContentGenerator.countTokens).toHaveBeenCalled(); + }); + + it('should use fixed estimate for PDFs in fallback', async () => { + vi.mocked(mockContentGenerator.countTokens).mockRejectedValue( + new Error('API error'), + ); + const request = [ + { inlineData: { mimeType: 'application/pdf', data: 'large_pdf_data' } }, + ]; + + const count = await calculateRequestTokenCount( + request, + mockContentGenerator, + model, + ); + + // PDF estimate: 25800 tokens (~100 pages at 258 tokens/page) + expect(count).toBe(25800); + }); }); diff --git a/packages/core/src/utils/tokenCalculation.ts b/packages/core/src/utils/tokenCalculation.ts index 06292bb925..cc2b83beb3 100644 --- a/packages/core/src/utils/tokenCalculation.ts +++ b/packages/core/src/utils/tokenCalculation.ts @@ -16,6 +16,9 @@ const ASCII_TOKENS_PER_CHAR = 0.25; const NON_ASCII_TOKENS_PER_CHAR = 1.3; // Fixed token estimate for images const IMAGE_TOKEN_ESTIMATE = 3000; +// Fixed token estimate for PDFs (~100 pages at 258 tokens/page) +// See: https://ai.google.dev/gemini-api/docs/document-processing +const PDF_TOKEN_ESTIMATE = 25800; /** * Estimates token count for parts synchronously using a heuristic. @@ -34,15 +37,19 @@ export function estimateTokenCountSync(parts: Part[]): number { } } } else { - // For images, we use a fixed safe estimate (3,000 tokens) covering - // up to 4K resolution on Gemini 3. + // For images and PDFs, we use fixed safe estimates: + // - Images: 3,000 tokens (covers up to 4K resolution on Gemini 3) + // - PDFs: 25,800 tokens (~100 pages at 258 tokens/page) // See: https://ai.google.dev/gemini-api/docs/vision#token_counting + // See: https://ai.google.dev/gemini-api/docs/document-processing const inlineData = 'inlineData' in part ? part.inlineData : undefined; const fileData = 'fileData' in part ? part.fileData : undefined; const mimeType = inlineData?.mimeType || fileData?.mimeType; if (mimeType?.startsWith('image/')) { totalTokens += IMAGE_TOKEN_ESTIMATE; + } else if (mimeType?.startsWith('application/pdf')) { + totalTokens += PDF_TOKEN_ESTIMATE; } else { // For other non-text parts (functionCall, functionResponse, etc.), // we fallback to the JSON string length heuristic. From a1cbe85da3ce6a9f966d63b79831f6dc9952db9c Mon Sep 17 00:00:00 2001 From: gemini-cli-robot Date: Wed, 14 Jan 2026 05:37:32 -0800 Subject: [PATCH 176/713] chore(release): bump version to 0.26.0-nightly.20260114.bb6c57414 (#16604) --- package-lock.json | 14 +++++++------- package.json | 4 ++-- packages/a2a-server/package.json | 2 +- packages/cli/package.json | 4 ++-- packages/core/package.json | 2 +- packages/test-utils/package.json | 2 +- packages/vscode-ide-companion/package.json | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7d036d9b96..6fb8dad5a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@google/gemini-cli", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@google/gemini-cli", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "workspaces": [ "packages/*" ], @@ -18382,7 +18382,7 @@ }, "packages/a2a-server": { "name": "@google/gemini-cli-a2a-server", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "dependencies": { "@a2a-js/sdk": "^0.3.7", "@google-cloud/storage": "^7.16.0", @@ -18692,7 +18692,7 @@ }, "packages/cli": { "name": "@google/gemini-cli", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "license": "Apache-2.0", "dependencies": { "@agentclientprotocol/sdk": "^0.11.0", @@ -18795,7 +18795,7 @@ }, "packages/core": { "name": "@google/gemini-cli-core", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "license": "Apache-2.0", "dependencies": { "@a2a-js/sdk": "^0.3.7", @@ -18954,7 +18954,7 @@ }, "packages/test-utils": { "name": "@google/gemini-cli-test-utils", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "license": "Apache-2.0", "dependencies": { "@google/gemini-cli-core": "file:../core", @@ -18971,7 +18971,7 @@ }, "packages/vscode-ide-companion": { "name": "gemini-cli-vscode-ide-companion", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "license": "LICENSE", "dependencies": { "@modelcontextprotocol/sdk": "^1.23.0", diff --git a/package.json b/package.json index b69c37d69b..ff97e64715 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "engines": { "node": ">=20.0.0" }, @@ -14,7 +14,7 @@ "url": "git+https://github.com/google-gemini/gemini-cli.git" }, "config": { - "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.25.0-nightly.20260107.59a18e710" + "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.26.0-nightly.20260114.bb6c57414" }, "scripts": { "start": "cross-env NODE_ENV=development node scripts/start.js", diff --git a/packages/a2a-server/package.json b/packages/a2a-server/package.json index b145599216..91bca79c21 100644 --- a/packages/a2a-server/package.json +++ b/packages/a2a-server/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli-a2a-server", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "description": "Gemini CLI A2A Server", "repository": { "type": "git", diff --git a/packages/cli/package.json b/packages/cli/package.json index 425dd919a2..ea1737738e 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "description": "Gemini CLI", "license": "Apache-2.0", "repository": { @@ -26,7 +26,7 @@ "dist" ], "config": { - "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.25.0-nightly.20260107.59a18e710" + "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.26.0-nightly.20260114.bb6c57414" }, "dependencies": { "@agentclientprotocol/sdk": "^0.11.0", diff --git a/packages/core/package.json b/packages/core/package.json index 428066517b..47cf6dca99 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli-core", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "description": "Gemini CLI Core", "license": "Apache-2.0", "repository": { diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index a05464d3e5..c3e00ddd69 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli-test-utils", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "private": true, "main": "src/index.ts", "license": "Apache-2.0", diff --git a/packages/vscode-ide-companion/package.json b/packages/vscode-ide-companion/package.json index c4a87b779b..9b0a994862 100644 --- a/packages/vscode-ide-companion/package.json +++ b/packages/vscode-ide-companion/package.json @@ -2,7 +2,7 @@ "name": "gemini-cli-vscode-ide-companion", "displayName": "Gemini CLI Companion", "description": "Enable Gemini CLI with direct access to your IDE workspace.", - "version": "0.25.0-nightly.20260107.59a18e710", + "version": "0.26.0-nightly.20260114.bb6c57414", "publisher": "google", "icon": "assets/icon.png", "repository": { From c04af6c3e9af363d7891d70a864c96ecdf606c8e Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Wed, 14 Jan 2026 08:48:52 -0500 Subject: [PATCH 177/713] docs: clarify F12 to open debug console (#16570) --- docs/get-started/configuration.md | 3 ++- docs/tools/mcp-server.md | 3 ++- docs/troubleshooting.md | 3 ++- packages/cli/src/config/config.ts | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index a3842a3b1f..3c8d0a76d8 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -1323,7 +1323,8 @@ for that specific session. - **`--sandbox`** (**`-s`**): - Enables sandbox mode for this session. - **`--debug`** (**`-d`**): - - Enables debug mode for this session, providing more verbose output. + - Enables debug mode for this session, providing more verbose output. Open the + debug console with F12 to see the additional logging. - **`--help`** (or **`-h`**): - Displays help information about command-line arguments. diff --git a/docs/tools/mcp-server.md b/docs/tools/mcp-server.md index a489f833c2..d1066d5170 100644 --- a/docs/tools/mcp-server.md +++ b/docs/tools/mcp-server.md @@ -722,7 +722,8 @@ The MCP integration tracks several states: ### Debugging tips -1. **Enable debug mode:** Run the CLI with `--debug` for verbose output +1. **Enable debug mode:** Run the CLI with `--debug` for verbose output (use F12 + to open debug console in interactive mode) 2. **Check stderr:** MCP server stderr is captured and logged (INFO messages filtered) 3. **Test isolation:** Test your MCP server independently before integrating diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 27a2679e9c..2dea1c7212 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -130,7 +130,8 @@ This is especially useful for scripting and automation. ## Debugging tips - **CLI debugging:** - - Use the `--debug` flag for more detailed output. + - Use the `--debug` flag for more detailed output. In interactive mode, press + F12 to view the debug console. - Check the CLI logs, often found in a user-specific configuration or cache directory. diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index a339e8ccc5..beccbfa0a9 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -93,7 +93,7 @@ export async function parseArguments(settings: Settings): Promise { .option('debug', { alias: 'd', type: 'boolean', - description: 'Run in debug mode?', + description: 'Run in debug mode (open debug console with F12)', default: false, }) .command('$0 [query..]', 'Launch Gemini CLI', (yargsInstance) => From f6c2d619066dcceabd43f80eabd163c13973d961 Mon Sep 17 00:00:00 2001 From: Aaron Smith <60046611+medic-code@users.noreply.github.com> Date: Wed, 14 Jan 2026 14:02:13 +0000 Subject: [PATCH 178/713] docs: Remove .md extension from internal links in architecture.md (#12899) Co-authored-by: Jack Wotherspoon --- docs/architecture.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/architecture.md b/docs/architecture.md index 2ba454e172..cf6ac8359d 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -13,11 +13,11 @@ input: as handling the initial user input, presenting the final output, and managing the overall user experience. - **Key functions contained in the package:** - - [Input processing](/docs/cli/commands.md) + - [Input processing](/docs/cli/commands) - History management - Display rendering - - [Theme and UI customization](/docs/cli/themes.md) - - [CLI configuration settings](/docs/get-started/configuration.md) + - [Theme and UI customization](/docs/cli/themes) + - [CLI configuration settings](/docs/get-started/configuration) 2. **Core package (`packages/core`):** - **Purpose:** This acts as the backend for the Gemini CLI. It receives From 3b55581aaf5f8e90882f6a2f9dd4927dbc79eb55 Mon Sep 17 00:00:00 2001 From: christine betts Date: Wed, 14 Jan 2026 10:16:42 -0500 Subject: [PATCH 179/713] Add an experimental setting for extension config (#16506) --- docs/get-started/configuration.md | 5 ++ .../cli/src/commands/extensions/configure.ts | 13 ++++- .../config/extension-manager-scope.test.ts | 9 ++++ packages/cli/src/config/extension-manager.ts | 50 ++++++++++++------- packages/cli/src/config/extension.test.ts | 4 +- .../extensions/extensionUpdates.test.ts | 10 +++- packages/cli/src/config/settingsSchema.ts | 9 ++++ schemas/settings.schema.json | 7 +++ 8 files changed, 85 insertions(+), 22 deletions(-) diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 3c8d0a76d8..d845c33692 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -830,6 +830,11 @@ their corresponding top-level category object in your `settings.json` file. - **Default:** `true` - **Requires restart:** Yes +- **`experimental.extensionConfig`** (boolean): + - **Description:** Enable requesting and fetching of extension settings. + - **Default:** `false` + - **Requires restart:** Yes + - **`experimental.extensionReloading`** (boolean): - **Description:** Enables extension loading/unloading within the CLI session. - **Default:** `false` diff --git a/packages/cli/src/commands/extensions/configure.ts b/packages/cli/src/commands/extensions/configure.ts index 4ea3299610..7d16179cc0 100644 --- a/packages/cli/src/commands/extensions/configure.ts +++ b/packages/cli/src/commands/extensions/configure.ts @@ -12,7 +12,8 @@ import { getScopedEnvContents, } from '../../config/extensions/extensionSettings.js'; import { getExtensionAndManager, getExtensionManager } from './utils.js'; -import { debugLogger } from '@google/gemini-cli-core'; +import { loadSettings } from '../../config/settings.js'; +import { debugLogger, coreEvents } from '@google/gemini-cli-core'; import { exitCli } from '../utils.js'; import prompts from 'prompts'; import type { ExtensionConfig } from '../../config/extension.js'; @@ -43,6 +44,16 @@ export const configureCommand: CommandModule = { }), handler: async (args) => { const { name, setting, scope } = args; + const settings = loadSettings(process.cwd()).merged; + + if (!(settings.experimental?.extensionConfig ?? true)) { + coreEvents.emitFeedback( + 'error', + 'Extension configuration is currently disabled. Enable it by setting "experimental.extensionConfig" to true.', + ); + await exitCli(); + return; + } if (name) { if (name.includes('/') || name.includes('\\') || name.includes('..')) { diff --git a/packages/cli/src/config/extension-manager-scope.test.ts b/packages/cli/src/config/extension-manager-scope.test.ts index a9e0738c87..6d3e51b4d8 100644 --- a/packages/cli/src/config/extension-manager-scope.test.ts +++ b/packages/cli/src/config/extension-manager-scope.test.ts @@ -109,6 +109,9 @@ describe('ExtensionManager Settings Scope', () => { telemetry: { enabled: false, }, + experimental: { + extensionConfig: true, + }, } as Settings, }); @@ -148,6 +151,9 @@ describe('ExtensionManager Settings Scope', () => { telemetry: { enabled: false, }, + experimental: { + extensionConfig: true, + }, } as Settings, }); @@ -185,6 +191,9 @@ describe('ExtensionManager Settings Scope', () => { telemetry: { enabled: false, }, + experimental: { + extensionConfig: true, + }, } as Settings, }); diff --git a/packages/cli/src/config/extension-manager.ts b/packages/cli/src/config/extension-manager.ts index fafa801bf2..75416f1909 100644 --- a/packages/cli/src/config/extension-manager.ts +++ b/packages/cli/src/config/extension-manager.ts @@ -287,7 +287,10 @@ Would you like to attempt to install via "git clone" instead?`, } await fs.promises.mkdir(destinationPath, { recursive: true }); - if (this.requestSetting) { + if ( + this.requestSetting && + (this.settings.experimental?.extensionConfig ?? false) + ) { if (isUpdate) { await maybePromptForSettings( newExtensionConfig, @@ -305,11 +308,14 @@ Would you like to attempt to install via "git clone" instead?`, } } - const missingSettings = await getMissingSettings( - newExtensionConfig, - extensionId, - this.workspaceDir, - ); + const missingSettings = + (this.settings.experimental?.extensionConfig ?? false) + ? await getMissingSettings( + newExtensionConfig, + extensionId, + this.workspaceDir, + ) + : []; if (missingSettings.length > 0) { const message = `Extension "${newExtensionConfig.name}" has missing settings: ${missingSettings .map((s) => s.name) @@ -526,23 +532,31 @@ Would you like to attempt to install via "git clone" instead?`, const extensionId = getExtensionId(config, installMetadata); - const userSettings = await getScopedEnvContents( - config, - extensionId, - ExtensionSettingScope.USER, - ); - const workspaceSettings = await getScopedEnvContents( - config, - extensionId, - ExtensionSettingScope.WORKSPACE, - this.workspaceDir, - ); + let userSettings: Record = {}; + let workspaceSettings: Record = {}; + + if (this.settings.experimental?.extensionConfig ?? false) { + userSettings = await getScopedEnvContents( + config, + extensionId, + ExtensionSettingScope.USER, + ); + workspaceSettings = await getScopedEnvContents( + config, + extensionId, + ExtensionSettingScope.WORKSPACE, + this.workspaceDir, + ); + } const customEnv = { ...userSettings, ...workspaceSettings }; config = resolveEnvVarsInObject(config, customEnv); const resolvedSettings: ResolvedExtensionSetting[] = []; - if (config.settings) { + if ( + config.settings && + (this.settings.experimental?.extensionConfig ?? false) + ) { for (const setting of config.settings) { const value = customEnv[setting.envVar]; let scope: 'user' | 'workspace' | undefined; diff --git a/packages/cli/src/config/extension.test.ts b/packages/cli/src/config/extension.test.ts index d1999d60c8..6619befc66 100644 --- a/packages/cli/src/config/extension.test.ts +++ b/packages/cli/src/config/extension.test.ts @@ -200,11 +200,13 @@ describe('extension tests', () => { source: undefined, }); vi.spyOn(process, 'cwd').mockReturnValue(tempWorkspaceDir); + const settings = loadSettings(tempWorkspaceDir).merged; + (settings.experimental ??= {}).extensionConfig = true; extensionManager = new ExtensionManager({ workspaceDir: tempWorkspaceDir, requestConsent: mockRequestConsent, requestSetting: mockPromptForSettings, - settings: loadSettings(tempWorkspaceDir).merged, + settings, }); resetTrustedFoldersForTesting(); }); diff --git a/packages/cli/src/config/extensions/extensionUpdates.test.ts b/packages/cli/src/config/extensions/extensionUpdates.test.ts index 1e30e0b898..a9240a1676 100644 --- a/packages/cli/src/config/extensions/extensionUpdates.test.ts +++ b/packages/cli/src/config/extensions/extensionUpdates.test.ts @@ -11,6 +11,7 @@ import * as fs from 'node:fs'; import { getMissingSettings } from './extensionSettings.js'; import type { ExtensionConfig } from '../extension.js'; import { ExtensionStorage } from './storage.js'; +import type { Settings } from '../settings.js'; import { KeychainTokenStorage, debugLogger, @@ -245,8 +246,13 @@ describe('extensionUpdates', () => { const manager = new ExtensionManager({ workspaceDir: tempWorkspaceDir, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - settings: { telemetry: {} } as any, + + settings: { + telemetry: { + enabled: false, + }, + experimental: { extensionConfig: true }, + } as unknown as Settings, requestConsent: vi.fn().mockResolvedValue(true), requestSetting: null, // Simulate non-interactive }); diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index 424f2e1906..229eebf81d 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -1413,6 +1413,15 @@ const SETTINGS_SCHEMA = { description: 'Enable extension management features.', showInDialog: false, }, + extensionConfig: { + type: 'boolean', + label: 'Extension Configuration', + category: 'Experimental', + requiresRestart: true, + default: false, + description: 'Enable requesting and fetching of extension settings.', + showInDialog: false, + }, extensionReloading: { type: 'boolean', label: 'Extension Reloading', diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index 1e3e1f0923..a976c19fd6 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -1393,6 +1393,13 @@ "default": true, "type": "boolean" }, + "extensionConfig": { + "title": "Extension Configuration", + "description": "Enable requesting and fetching of extension settings.", + "markdownDescription": "Enable requesting and fetching of extension settings.\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `false`", + "default": false, + "type": "boolean" + }, "extensionReloading": { "title": "Extension Reloading", "description": "Enables extension loading/unloading within the CLI session.", From dfb7dc70695ce528bad952b1bb0a5131278e76ed Mon Sep 17 00:00:00 2001 From: Adib234 <30782825+Adib234@users.noreply.github.com> Date: Wed, 14 Jan 2026 10:22:21 -0500 Subject: [PATCH 180/713] feat: add Rewind Confirmation dialog and Rewind Viewer component (#15717) --- docs/cli/commands.md | 7 + docs/cli/keyboard-shortcuts.md | 3 +- docs/cli/rewind.md | 51 +++ docs/sidebar.json | 4 + packages/cli/src/config/keyBindings.ts | 4 + packages/cli/src/test-utils/render.tsx | 1 + .../cli/src/ui/components/Composer.test.tsx | 2 +- .../src/ui/components/InputPrompt.test.tsx | 20 +- .../cli/src/ui/components/InputPrompt.tsx | 11 +- .../ui/components/RewindConfirmation.test.tsx | 91 +++++ .../src/ui/components/RewindConfirmation.tsx | 156 +++++++++ .../src/ui/components/RewindViewer.test.tsx | 330 ++++++++++++++++++ .../cli/src/ui/components/RewindViewer.tsx | 211 +++++++++++ .../cli/src/ui/components/StatusDisplay.tsx | 2 +- .../RewindConfirmation.test.tsx.snap | 53 +++ .../__snapshots__/RewindViewer.test.tsx.snap | 265 ++++++++++++++ .../__snapshots__/StatusDisplay.test.tsx.snap | 2 +- packages/cli/src/ui/utils/formatters.test.ts | 98 +++++- packages/cli/src/ui/utils/formatters.ts | 34 ++ 19 files changed, 1318 insertions(+), 27 deletions(-) create mode 100644 docs/cli/rewind.md create mode 100644 packages/cli/src/ui/components/RewindConfirmation.test.tsx create mode 100644 packages/cli/src/ui/components/RewindConfirmation.tsx create mode 100644 packages/cli/src/ui/components/RewindViewer.test.tsx create mode 100644 packages/cli/src/ui/components/RewindViewer.tsx create mode 100644 packages/cli/src/ui/components/__snapshots__/RewindConfirmation.test.tsx.snap create mode 100644 packages/cli/src/ui/components/__snapshots__/RewindViewer.test.tsx.snap diff --git a/docs/cli/commands.md b/docs/cli/commands.md index da29410533..fb5da33133 100644 --- a/docs/cli/commands.md +++ b/docs/cli/commands.md @@ -167,6 +167,13 @@ Slash commands provide meta-level control over the CLI itself. - **Note:** Only available if checkpointing is configured via [settings](../get-started/configuration.md). See [Checkpointing documentation](../cli/checkpointing.md) for more details. + +- [**`/rewind`**](./rewind.md) + - **Description:** Browse and rewind previous interactions. Allows you to + rewind the conversation, revert file changes, or both. Provides an + interactive interface to select the exact point to rewind to. + - **Keyboard shortcut:** Press **Esc** twice. + - **`/resume`** - **Description:** Browse and resume previous conversation sessions. Opens an interactive session browser where you can search, filter, and select from diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index 831f74da80..e56b508d68 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -64,6 +64,7 @@ available combinations. | Start reverse search through history. | `Ctrl + R` | | Submit the selected reverse-search match. | `Enter (no Ctrl)` | | Accept a suggestion while reverse searching. | `Tab` | +| Browse and rewind previous interactions. | `Esc (×2)` | #### Navigation @@ -129,7 +130,7 @@ available combinations. - `!` on an empty prompt: Enter or exit shell mode. - `\` (at end of a line) + `Enter`: Insert a newline without leaving single-line mode. -- `Esc` pressed twice quickly: Clear the current input buffer. +- `Esc` pressed twice quickly: Browse and rewind previous interactions. - `Up Arrow` / `Down Arrow`: When the cursor is at the top or bottom of a single-line input, navigate backward or forward through prompt history. - `Number keys (1-9, multi-digit)` inside selection dialogs: Jump directly to diff --git a/docs/cli/rewind.md b/docs/cli/rewind.md new file mode 100644 index 0000000000..e0e0cf15d7 --- /dev/null +++ b/docs/cli/rewind.md @@ -0,0 +1,51 @@ +# Rewind + +The `/rewind` command allows you to go back to a previous state in your +conversation and, optionally, revert any file changes made by the AI during +those interactions. This is a powerful tool for undoing mistakes, exploring +different approaches, or simply cleaning up your session history. + +## Usage + +To use the rewind feature, simply type `/rewind` into the input prompt and press +**Enter**. + +Alternatively, you can use the keyboard shortcut: **Press `Esc` twice**. + +## Interface + +When you trigger a rewind, an interactive list of your previous interactions +appears. + +1. **Select Interaction:** Use the **Up/Down arrow keys** to navigate through + the list. The most recent interactions are at the bottom. +2. **Preview:** As you select an interaction, you'll see a preview of the user + prompt and, if applicable, the number of files changed during that step. +3. **Confirm Selection:** Press **Enter** on the interaction you want to rewind + back to. +4. **Action Selection:** After selecting an interaction, you'll be presented + with a confirmation dialog with up to three options: + - **Rewind conversation and revert code changes:** Reverts both the chat + history and the file modifications to the state before the selected + interaction. + - **Rewind conversation:** Only reverts the chat history. File changes are + kept. + - **Revert code changes:** Only reverts the file modifications. The chat + history is kept. + - **Do nothing (esc):** Cancels the rewind operation. + +If no code changes were made since the selected point, the options related to +reverting code changes will be hidden. + +## Key Considerations + +- **Destructive Action:** Rewinding is a destructive action for your current + session history and potentially your files. Use it with care. +- **Agent Awareness:** When you rewind the conversation, the AI model loses all + memory of the interactions that were removed. If you only revert code changes, + you may need to inform the model that the files have changed. +- **Manual Edits:** Rewinding only affects file changes made by the AI's edit + tools. It does **not** undo manual edits you've made or changes triggered by + the shell tool (`!`). +- **Compression:** Rewind works across chat compression points by reconstructing + the history from stored session data. diff --git a/docs/sidebar.json b/docs/sidebar.json index a65bade052..d103ee4692 100644 --- a/docs/sidebar.json +++ b/docs/sidebar.json @@ -80,6 +80,10 @@ "label": "Model selection", "slug": "docs/cli/model" }, + { + "label": "Rewind", + "slug": "docs/cli/rewind" + }, { "label": "Sandbox", "slug": "docs/cli/sandbox" diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index 4e0daf5ae2..915128487a 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -76,6 +76,7 @@ export enum Command { QUIT = 'quit', EXIT = 'exit', SHOW_MORE_LINES = 'showMoreLines', + REWIND = 'rewind', // Shell commands REVERSE_SEARCH = 'reverseSearch', @@ -264,6 +265,7 @@ export const defaultKeyBindings: KeyBindingConfig = { // Suggestion expansion [Command.EXPAND_SUGGESTION]: [{ key: 'right' }], [Command.COLLAPSE_SUGGESTION]: [{ key: 'left' }], + [Command.REWIND]: [{ key: 'Esc (×2)' }], }; interface CommandCategory { @@ -327,6 +329,7 @@ export const commandCategories: readonly CommandCategory[] = [ Command.REVERSE_SEARCH, Command.SUBMIT_REVERSE_SEARCH, Command.ACCEPT_SUGGESTION_REVERSE_SEARCH, + Command.REWIND, ], }, { @@ -439,4 +442,5 @@ export const commandDescriptions: Readonly> = { [Command.UNFOCUS_SHELL_INPUT]: 'Focus the Gemini input from the shell input.', [Command.EXPAND_SUGGESTION]: 'Expand an inline suggestion.', [Command.COLLAPSE_SUGGESTION]: 'Collapse an inline suggestion.', + [Command.REWIND]: 'Browse and rewind previous interactions.', }; diff --git a/packages/cli/src/test-utils/render.tsx b/packages/cli/src/test-utils/render.tsx index 3f77acd7a7..083b636a2f 100644 --- a/packages/cli/src/test-utils/render.tsx +++ b/packages/cli/src/test-utils/render.tsx @@ -133,6 +133,7 @@ const baseMockUiState = { streamingState: StreamingState.Idle, mainAreaWidth: 100, terminalWidth: 120, + terminalHeight: 40, currentModel: 'gemini-pro', terminalBackgroundColor: undefined, }; diff --git a/packages/cli/src/ui/components/Composer.test.tsx b/packages/cli/src/ui/components/Composer.test.tsx index e5e6e02830..c39d7c5ece 100644 --- a/packages/cli/src/ui/components/Composer.test.tsx +++ b/packages/cli/src/ui/components/Composer.test.tsx @@ -385,7 +385,7 @@ describe('Composer', () => { const { lastFrame } = renderComposer(uiState); - expect(lastFrame()).toContain('Press Esc again to clear'); + expect(lastFrame()).toContain('Press Esc again to rewind'); }); }); diff --git a/packages/cli/src/ui/components/InputPrompt.test.tsx b/packages/cli/src/ui/components/InputPrompt.test.tsx index 68b044071d..b9a3d2622d 100644 --- a/packages/cli/src/ui/components/InputPrompt.test.tsx +++ b/packages/cli/src/ui/components/InputPrompt.test.tsx @@ -1870,11 +1870,11 @@ describe('InputPrompt', () => { }); }); - describe('enhanced input UX - double ESC clear functionality', () => { + describe('enhanced input UX - keyboard shortcuts', () => { beforeEach(() => vi.useFakeTimers()); afterEach(() => vi.useRealTimers()); - it('should clear buffer on second ESC press', async () => { + it('should clear buffer on Ctrl-C', async () => { const onEscapePromptChange = vi.fn(); props.onEscapePromptChange = onEscapePromptChange; props.buffer.setText('text to clear'); @@ -1884,14 +1884,7 @@ describe('InputPrompt', () => { ); await act(async () => { - stdin.write('\x1B'); - vi.advanceTimersByTime(100); - - expect(onEscapePromptChange).toHaveBeenCalledWith(false); - }); - - await act(async () => { - stdin.write('\x1B'); + stdin.write('\x03'); vi.advanceTimersByTime(100); expect(props.buffer.setText).toHaveBeenCalledWith(''); @@ -1900,10 +1893,10 @@ describe('InputPrompt', () => { unmount(); }); - it('should clear buffer on double ESC', async () => { + it('should submit /rewind on double ESC', async () => { const onEscapePromptChange = vi.fn(); props.onEscapePromptChange = onEscapePromptChange; - props.buffer.setText('text to clear'); + props.buffer.setText('some text'); const { stdin, unmount } = renderWithProviders( , @@ -1913,8 +1906,7 @@ describe('InputPrompt', () => { stdin.write('\x1B\x1B'); vi.advanceTimersByTime(100); - expect(props.buffer.setText).toHaveBeenCalledWith(''); - expect(mockCommandCompletion.resetCompletionState).toHaveBeenCalled(); + expect(props.onSubmit).toHaveBeenCalledWith('/rewind'); }); unmount(); }); diff --git a/packages/cli/src/ui/components/InputPrompt.tsx b/packages/cli/src/ui/components/InputPrompt.tsx index 20d84ca650..762fc84b06 100644 --- a/packages/cli/src/ui/components/InputPrompt.tsx +++ b/packages/cli/src/ui/components/InputPrompt.tsx @@ -495,11 +495,8 @@ export const InputPrompt: React.FC = ({ return; } - // Handle double ESC for clearing input + // Handle double ESC for rewind if (escPressCount.current === 0) { - if (buffer.text === '') { - return; - } escPressCount.current = 1; setShowEscapePrompt(true); if (escapeTimerRef.current) { @@ -509,10 +506,9 @@ export const InputPrompt: React.FC = ({ resetEscapeState(); }, 500); } else { - // clear input and immediately reset state - buffer.setText(''); - resetCompletionState(); + // Second ESC triggers rewind resetEscapeState(); + onSubmit('/rewind'); } return; } @@ -881,6 +877,7 @@ export const InputPrompt: React.FC = ({ kittyProtocol.enabled, tryLoadQueuedMessages, setBannerVisible, + onSubmit, activePtyId, setEmbeddedShellFocused, ], diff --git a/packages/cli/src/ui/components/RewindConfirmation.test.tsx b/packages/cli/src/ui/components/RewindConfirmation.test.tsx new file mode 100644 index 0000000000..5245a05490 --- /dev/null +++ b/packages/cli/src/ui/components/RewindConfirmation.test.tsx @@ -0,0 +1,91 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { act } from 'react'; +import { renderWithProviders } from '../../test-utils/render.js'; +import { waitFor } from '../../test-utils/async.js'; +import { RewindConfirmation, RewindOutcome } from './RewindConfirmation.js'; + +describe('RewindConfirmation', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it('renders correctly with stats', () => { + const stats = { + addedLines: 10, + removedLines: 5, + fileCount: 1, + details: [{ fileName: 'test.ts', diff: '' }], + }; + const onConfirm = vi.fn(); + const { lastFrame } = renderWithProviders( + , + { width: 80 }, + ); + + expect(lastFrame()).toMatchSnapshot(); + expect(lastFrame()).toContain('Revert code changes'); + }); + + it('renders correctly without stats', () => { + const onConfirm = vi.fn(); + const { lastFrame } = renderWithProviders( + , + { width: 80 }, + ); + + expect(lastFrame()).toMatchSnapshot(); + expect(lastFrame()).not.toContain('Revert code changes'); + expect(lastFrame()).toContain('Rewind conversation'); + }); + + it('calls onConfirm with Cancel on Escape', async () => { + const onConfirm = vi.fn(); + const { stdin } = renderWithProviders( + , + { width: 80 }, + ); + + await act(async () => { + stdin.write('\x1b'); + }); + + await waitFor(() => { + expect(onConfirm).toHaveBeenCalledWith(RewindOutcome.Cancel); + }); + }); + + it('renders timestamp when provided', () => { + const onConfirm = vi.fn(); + const timestamp = new Date().toISOString(); + const { lastFrame } = renderWithProviders( + , + { width: 80 }, + ); + + expect(lastFrame()).toMatchSnapshot(); + expect(lastFrame()).not.toContain('Revert code changes'); + }); +}); diff --git a/packages/cli/src/ui/components/RewindConfirmation.tsx b/packages/cli/src/ui/components/RewindConfirmation.tsx new file mode 100644 index 0000000000..5b9f4d8253 --- /dev/null +++ b/packages/cli/src/ui/components/RewindConfirmation.tsx @@ -0,0 +1,156 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Box, Text } from 'ink'; +import type React from 'react'; +import { useMemo } from 'react'; +import { theme } from '../semantic-colors.js'; +import { RadioButtonSelect } from './shared/RadioButtonSelect.js'; +import type { RadioSelectItem } from './shared/RadioButtonSelect.js'; +import type { FileChangeStats } from '../utils/rewindFileOps.js'; +import { useKeypress } from '../hooks/useKeypress.js'; +import { formatTimeAgo } from '../utils/formatters.js'; +import { keyMatchers, Command } from '../keyMatchers.js'; + +export enum RewindOutcome { + RewindAndRevert = 'rewind_and_revert', + RewindOnly = 'rewind_only', + RevertOnly = 'revert_only', + Cancel = 'cancel', +} + +const REWIND_OPTIONS: Array> = [ + { + label: 'Rewind conversation and revert code changes', + value: RewindOutcome.RewindAndRevert, + key: 'Rewind conversation and revert code changes', + }, + { + label: 'Rewind conversation', + value: RewindOutcome.RewindOnly, + key: 'Rewind conversation', + }, + { + label: 'Revert code changes', + value: RewindOutcome.RevertOnly, + key: 'Revert code changes', + }, + { + label: 'Do nothing (esc)', + value: RewindOutcome.Cancel, + key: 'Do nothing (esc)', + }, +]; + +interface RewindConfirmationProps { + stats: FileChangeStats | null; + onConfirm: (outcome: RewindOutcome) => void; + terminalWidth: number; + timestamp?: string; +} + +export const RewindConfirmation: React.FC = ({ + stats, + onConfirm, + terminalWidth, + timestamp, +}) => { + useKeypress( + (key) => { + if (keyMatchers[Command.ESCAPE](key)) { + onConfirm(RewindOutcome.Cancel); + } + }, + { isActive: true }, + ); + + const handleSelect = (outcome: RewindOutcome) => { + onConfirm(outcome); + }; + + const options = useMemo(() => { + if (stats) { + return REWIND_OPTIONS; + } + return REWIND_OPTIONS.filter( + (option) => + option.value !== RewindOutcome.RewindAndRevert && + option.value !== RewindOutcome.RevertOnly, + ); + }, [stats]); + + return ( + + + Confirm Rewind + + + {stats && ( + + + {stats.fileCount === 1 + ? `File: ${stats.details?.at(0)?.fileName}` + : `${stats.fileCount} files affected`} + + + + Lines added: {stats.addedLines}{' '} + + + Lines removed: {stats.removedLines} + + {timestamp && ( + + {' '} + ({formatTimeAgo(timestamp)}) + + )} + + + + ℹ Rewinding does not affect files edited manually or by the shell + tool. + + + + )} + + {!stats && ( + + No code changes to revert. + {timestamp && ( + + {' '} + ({formatTimeAgo(timestamp)}) + + )} + + )} + + + Select an action: + + + + + ); +}; diff --git a/packages/cli/src/ui/components/RewindViewer.test.tsx b/packages/cli/src/ui/components/RewindViewer.test.tsx new file mode 100644 index 0000000000..649fbb4f4b --- /dev/null +++ b/packages/cli/src/ui/components/RewindViewer.test.tsx @@ -0,0 +1,330 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { act } from 'react'; +import { renderWithProviders } from '../../test-utils/render.js'; +import { RewindViewer } from './RewindViewer.js'; +import { waitFor } from '../../test-utils/async.js'; +import type { + ConversationRecord, + MessageRecord, +} from '@google/gemini-cli-core'; + +vi.mock('../utils/formatters.js', async (importOriginal) => { + const original = + await importOriginal(); + return { + ...original, + formatTimeAgo: () => 'some time ago', + }; +}); + +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const original = + await importOriginal(); + + const partToStringRecursive = (part: unknown): string => { + if (!part) { + return ''; + } + if (typeof part === 'string') { + return part; + } + if (Array.isArray(part)) { + return part.map(partToStringRecursive).join(''); + } + if (typeof part === 'object' && part !== null && 'text' in part) { + return (part as { text: string }).text ?? ''; + } + return ''; + }; + + return { + ...original, + partToString: (part: string | JSON) => partToStringRecursive(part), + }; +}); + +const createConversation = (messages: MessageRecord[]): ConversationRecord => ({ + sessionId: 'test-session', + projectHash: 'hash', + startTime: new Date().toISOString(), + lastUpdated: new Date().toISOString(), + messages, +}); + +describe('RewindViewer', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + describe('Rendering', () => { + it.each([ + { name: 'nothing interesting for empty conversation', messages: [] }, + { + name: 'a single interaction', + messages: [ + { type: 'user', content: 'Hello', id: '1', timestamp: '1' }, + { type: 'gemini', content: 'Hi there!', id: '1', timestamp: '1' }, + ], + }, + { + name: 'full text for selected item', + messages: [ + { + type: 'user', + content: '1\n2\n3\n4\n5\n6\n7', + id: '1', + timestamp: '1', + }, + ], + }, + ])('renders $name', ({ messages }) => { + const conversation = createConversation(messages as MessageRecord[]); + const onExit = vi.fn(); + const onRewind = vi.fn(); + const { lastFrame } = renderWithProviders( + , + ); + expect(lastFrame()).toMatchSnapshot(); + }); + }); + + it('updates selection and expansion on navigation', async () => { + const longText1 = 'Line A\nLine B\nLine C\nLine D\nLine E\nLine F\nLine G'; + const longText2 = 'Line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7'; + const conversation = createConversation([ + { type: 'user', content: longText1, id: '1', timestamp: '1' }, + { type: 'gemini', content: 'Response 1', id: '1', timestamp: '1' }, + { type: 'user', content: longText2, id: '2', timestamp: '1' }, + { type: 'gemini', content: 'Response 2', id: '2', timestamp: '1' }, + ]); + const onExit = vi.fn(); + const onRewind = vi.fn(); + const { lastFrame, stdin } = renderWithProviders( + , + ); + + // Initial state + expect(lastFrame()).toMatchSnapshot('initial-state'); + + // Move down to select Item 1 (older message) + act(() => { + stdin.write('\x1b[B'); + }); + + await waitFor(() => { + expect(lastFrame()).toMatchSnapshot('after-down'); + }); + }); + + describe('Navigation', () => { + it.each([ + { name: 'down', sequence: '\x1b[B', expectedSnapshot: 'after-down' }, + { name: 'up', sequence: '\x1b[A', expectedSnapshot: 'after-up' }, + ])('handles $name navigation', async ({ sequence, expectedSnapshot }) => { + const conversation = createConversation([ + { type: 'user', content: 'Q1', id: '1', timestamp: '1' }, + { type: 'user', content: 'Q2', id: '2', timestamp: '1' }, + { type: 'user', content: 'Q3', id: '3', timestamp: '1' }, + ]); + const { lastFrame, stdin } = renderWithProviders( + , + ); + + act(() => { + stdin.write(sequence); + }); + await waitFor(() => { + expect(lastFrame()).toMatchSnapshot(expectedSnapshot); + }); + }); + + it('handles cyclic navigation', async () => { + const conversation = createConversation([ + { type: 'user', content: 'Q1', id: '1', timestamp: '1' }, + { type: 'user', content: 'Q2', id: '2', timestamp: '1' }, + { type: 'user', content: 'Q3', id: '3', timestamp: '1' }, + ]); + const { lastFrame, stdin } = renderWithProviders( + , + ); + + // Up from first -> Last + act(() => { + stdin.write('\x1b[A'); + }); + await waitFor(() => { + expect(lastFrame()).toMatchSnapshot('cyclic-up'); + }); + + // Down from last -> First + act(() => { + stdin.write('\x1b[B'); + }); + await waitFor(() => { + expect(lastFrame()).toMatchSnapshot('cyclic-down'); + }); + }); + }); + + describe('Interaction Selection', () => { + it.each([ + { + name: 'confirms on Enter', + actionStep: async ( + stdin: { write: (data: string) => void }, + lastFrame: () => string | undefined, + ) => { + // Wait for confirmation dialog to be rendered and interactive + await waitFor(() => { + expect(lastFrame()).toContain('Confirm Rewind'); + }); + act(() => { + stdin.write('\r'); + }); + }, + }, + { + name: 'cancels on Escape', + actionStep: async ( + stdin: { write: (data: string) => void }, + lastFrame: () => string | undefined, + ) => { + // Wait for confirmation dialog + await waitFor(() => { + expect(lastFrame()).toContain('Confirm Rewind'); + }); + act(() => { + stdin.write('\x1b'); + }); + // Wait for return to main view + await waitFor(() => { + expect(lastFrame()).toContain('> Rewind'); + }); + }, + }, + ])('$name', async ({ actionStep }) => { + const conversation = createConversation([ + { type: 'user', content: 'Original Prompt', id: '1', timestamp: '1' }, + ]); + const onRewind = vi.fn(); + const { lastFrame, stdin } = renderWithProviders( + , + ); + + // Select + act(() => { + stdin.write('\r'); + }); + expect(lastFrame()).toMatchSnapshot('confirmation-dialog'); + + // Act + await actionStep(stdin, lastFrame); + }); + }); + + describe('Content Filtering', () => { + it.each([ + { + description: 'removes reference markers', + prompt: + 'some command @file\n--- Content from referenced files ---\nContent from file:\nblah blah\n--- End of content ---', + }, + { + description: 'strips expanded MCP resource content', + prompt: + 'read @server3:mcp://demo-resource hello\n' + + '--- Content from referenced files ---\n' + + '\nContent from @server3:mcp://demo-resource:\n' + + 'This is the content of the demo resource.\n' + + '--- End of content ---', + }, + ])('$description', async ({ prompt }) => { + const conversation = createConversation([ + { type: 'user', content: prompt, id: '1', timestamp: '1' }, + ]); + const onRewind = vi.fn(); + const { lastFrame, stdin } = renderWithProviders( + , + ); + + expect(lastFrame()).toMatchSnapshot(); + + // Select + act(() => { + stdin.write('\r'); // Select + }); + + // Wait for confirmation dialog + await waitFor(() => { + expect(lastFrame()).toContain('Confirm Rewind'); + }); + }); + }); + + it('updates content when conversation changes (background update)', () => { + const messages: MessageRecord[] = [ + { type: 'user', content: 'Message 1', id: '1', timestamp: '1' }, + ]; + let conversation = createConversation(messages); + const onExit = vi.fn(); + const onRewind = vi.fn(); + + const { lastFrame, unmount } = renderWithProviders( + , + ); + + expect(lastFrame()).toMatchSnapshot('initial'); + + unmount(); + + const newMessages: MessageRecord[] = [ + ...messages, + { type: 'user', content: 'Message 2', id: '2', timestamp: '2' }, + ]; + conversation = createConversation(newMessages); + + const { lastFrame: lastFrame2 } = renderWithProviders( + , + ); + + expect(lastFrame2()).toMatchSnapshot('after-update'); + }); +}); diff --git a/packages/cli/src/ui/components/RewindViewer.tsx b/packages/cli/src/ui/components/RewindViewer.tsx new file mode 100644 index 0000000000..f33b3786f5 --- /dev/null +++ b/packages/cli/src/ui/components/RewindViewer.tsx @@ -0,0 +1,211 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type React from 'react'; +import { useMemo } from 'react'; +import { Box, Text } from 'ink'; +import { useUIState } from '../contexts/UIStateContext.js'; +import { + type ConversationRecord, + type MessageRecord, + partToString, +} from '@google/gemini-cli-core'; +import { BaseSelectionList } from './shared/BaseSelectionList.js'; +import { theme } from '../semantic-colors.js'; +import { useKeypress } from '../hooks/useKeypress.js'; +import { useRewind } from '../hooks/useRewind.js'; +import { RewindConfirmation, RewindOutcome } from './RewindConfirmation.js'; +import { stripReferenceContent } from '../utils/formatters.js'; +import { MaxSizedBox } from './shared/MaxSizedBox.js'; +import { keyMatchers, Command } from '../keyMatchers.js'; + +interface RewindViewerProps { + conversation: ConversationRecord; + onExit: () => void; + onRewind: ( + messageId: string, + newText: string, + outcome: RewindOutcome, + ) => void; +} + +const MAX_LINES_PER_BOX = 2; + +export const RewindViewer: React.FC = ({ + conversation, + onExit, + onRewind, +}) => { + const { terminalWidth, terminalHeight } = useUIState(); + const { + selectedMessageId, + getStats, + confirmationStats, + selectMessage, + clearSelection, + } = useRewind(conversation); + + const interactions = useMemo( + () => conversation.messages.filter((msg) => msg.type === 'user'), + [conversation.messages], + ); + + const items = useMemo( + () => + interactions + .map((msg, idx) => ({ + key: `${msg.id || 'msg'}-${idx}`, + value: msg, + index: idx, + })) + .reverse(), + [interactions], + ); + + useKeypress( + (key) => { + if (!selectedMessageId) { + if (keyMatchers[Command.ESCAPE](key)) { + onExit(); + } + } + }, + { isActive: true }, + ); + + // Height constraint calculations + const DIALOG_PADDING = 2; // Top/bottom padding + const HEADER_HEIGHT = 2; // Title + margin + const CONTROLS_HEIGHT = 2; // Controls text + margin + + const listHeight = Math.max( + 5, + terminalHeight - DIALOG_PADDING - HEADER_HEIGHT - CONTROLS_HEIGHT - 2, + ); + + const maxItemsToShow = Math.max(1, Math.floor(listHeight / 4)); + + if (selectedMessageId) { + const selectedMessage = interactions.find( + (m) => m.id === selectedMessageId, + ); + return ( + { + if (outcome === RewindOutcome.Cancel) { + clearSelection(); + } else { + const userPrompt = interactions.find( + (m) => m.id === selectedMessageId, + ); + if (userPrompt) { + const originalUserText = userPrompt.content + ? partToString(userPrompt.content) + : ''; + const cleanedText = stripReferenceContent(originalUserText); + onRewind(selectedMessageId, cleanedText, outcome); + } + } + }} + /> + ); + } + + return ( + + + {'> '}Rewind + + + + { + const userPrompt = item; + if (userPrompt && userPrompt.id) { + selectMessage(userPrompt.id); + } + }} + maxItemsToShow={maxItemsToShow} + renderItem={(itemWrapper, { isSelected }) => { + const userPrompt = itemWrapper.value; + const stats = getStats(userPrompt); + const firstFileName = stats?.details?.at(0)?.fileName; + const originalUserText = userPrompt.content + ? partToString(userPrompt.content) + : ''; + const cleanedText = stripReferenceContent(originalUserText); + + return ( + + + + {cleanedText.split('\n').map((line, i) => ( + + + {line} + + + ))} + + + {stats ? ( + + + {stats.fileCount === 1 + ? firstFileName + ? firstFileName + : '1 file changed' + : `${stats.fileCount} files changed`}{' '} + + {stats.addedLines > 0 && ( + +{stats.addedLines} + )} + {stats.removedLines > 0 && ( + -{stats.removedLines} + )} + + ) : ( + + No files have been changed + + )} + + ); + }} + /> + + + + + (Use Enter to select a message, Esc to close) + + + + ); +}; diff --git a/packages/cli/src/ui/components/StatusDisplay.tsx b/packages/cli/src/ui/components/StatusDisplay.tsx index 40925fa5ba..96d2868830 100644 --- a/packages/cli/src/ui/components/StatusDisplay.tsx +++ b/packages/cli/src/ui/components/StatusDisplay.tsx @@ -45,7 +45,7 @@ export const StatusDisplay: React.FC = ({ } if (uiState.showEscapePrompt) { - return Press Esc again to clear.; + return Press Esc again to rewind.; } if (uiState.queueErrorMessage) { diff --git a/packages/cli/src/ui/components/__snapshots__/RewindConfirmation.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/RewindConfirmation.test.tsx.snap new file mode 100644 index 0000000000..643f2aaaeb --- /dev/null +++ b/packages/cli/src/ui/components/__snapshots__/RewindConfirmation.test.tsx.snap @@ -0,0 +1,53 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`RewindConfirmation > renders correctly with stats 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ Confirm Rewind │ +│ │ +│ ┌──────────────────────────────────────────────────────────────────────────┐ │ +│ │ File: test.ts │ │ +│ │ Lines added: 10 Lines removed: 5 │ │ +│ │ │ │ +│ │ ℹ Rewinding does not affect files edited manually or by the shell tool. │ │ +│ └──────────────────────────────────────────────────────────────────────────┘ │ +│ │ +│ Select an action: │ +│ │ +│ ● 1. Rewind conversation and revert code changes │ +│ 2. Rewind conversation │ +│ 3. Revert code changes │ +│ 4. Do nothing (esc) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindConfirmation > renders correctly without stats 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ Confirm Rewind │ +│ │ +│ No code changes to revert. │ +│ │ +│ Select an action: │ +│ │ +│ ● 1. Rewind conversation │ +│ 2. Do nothing (esc) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindConfirmation > renders timestamp when provided 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ Confirm Rewind │ +│ │ +│ No code changes to revert. (just now) │ +│ │ +│ Select an action: │ +│ │ +│ ● 1. Rewind conversation │ +│ 2. Do nothing (esc) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────╯" +`; diff --git a/packages/cli/src/ui/components/__snapshots__/RewindViewer.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/RewindViewer.test.tsx.snap new file mode 100644 index 0000000000..7db1c1c507 --- /dev/null +++ b/packages/cli/src/ui/components/__snapshots__/RewindViewer.test.tsx.snap @@ -0,0 +1,265 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`RewindViewer > Content Filtering > 'removes reference markers' 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ ● some command @file │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > Content Filtering > 'strips expanded MCP resource content' 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ ● read @server3:mcp://demo-resource hello │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > Interaction Selection > 'cancels on Escape' > confirmation-dialog 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ Confirm Rewind │ +│ │ +│ No code changes to revert. (some time ago) │ +│ │ +│ Select an action: │ +│ │ +│ ● 1. Rewind conversation │ +│ 2. Do nothing (esc) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > Interaction Selection > 'confirms on Enter' > confirmation-dialog 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ Confirm Rewind │ +│ │ +│ No code changes to revert. (some time ago) │ +│ │ +│ Select an action: │ +│ │ +│ ● 1. Rewind conversation │ +│ 2. Do nothing (esc) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > Navigation > handles 'down' navigation > after-down 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ Q3 │ +│ No files have been changed │ +│ │ +│ ● Q2 │ +│ No files have been changed │ +│ │ +│ Q1 │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > Navigation > handles 'up' navigation > after-up 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ Q3 │ +│ No files have been changed │ +│ │ +│ Q2 │ +│ No files have been changed │ +│ │ +│ ● Q1 │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > Navigation > handles cyclic navigation > cyclic-down 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ ● Q3 │ +│ No files have been changed │ +│ │ +│ Q2 │ +│ No files have been changed │ +│ │ +│ Q1 │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > Navigation > handles cyclic navigation > cyclic-up 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ Q3 │ +│ No files have been changed │ +│ │ +│ Q2 │ +│ No files have been changed │ +│ │ +│ ● Q1 │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > Rendering > renders 'a single interaction' 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ ● Hello │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > Rendering > renders 'full text for selected item' 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ ● 1 │ +│ 2 │ +│ 3 │ +│ 4 │ +│ 5 │ +│ 6 │ +│ 7 │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > Rendering > renders 'nothing interesting for empty convers…' 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > updates content when conversation changes (background update) > after-update 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ ● Message 2 │ +│ No files have been changed │ +│ │ +│ Message 1 │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > updates content when conversation changes (background update) > initial 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ ● Message 1 │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > updates selection and expansion on navigation > after-down 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ Line 1 │ +│ Line 2 │ +│ ... last 5 lines hidden ... │ +│ No files have been changed │ +│ │ +│ ● Line A │ +│ Line B │ +│ Line C │ +│ Line D │ +│ Line E │ +│ Line F │ +│ Line G │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; + +exports[`RewindViewer > updates selection and expansion on navigation > initial-state 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ > Rewind │ +│ │ +│ ● Line 1 │ +│ Line 2 │ +│ Line 3 │ +│ Line 4 │ +│ Line 5 │ +│ Line 6 │ +│ Line 7 │ +│ No files have been changed │ +│ │ +│ Line A │ +│ Line B │ +│ ... last 5 lines hidden ... │ +│ No files have been changed │ +│ │ +│ │ +│ (Use Enter to select a message, Esc to close) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +`; diff --git a/packages/cli/src/ui/components/__snapshots__/StatusDisplay.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/StatusDisplay.test.tsx.snap index ee2c68fbd5..521f642a9a 100644 --- a/packages/cli/src/ui/components/__snapshots__/StatusDisplay.test.tsx.snap +++ b/packages/cli/src/ui/components/__snapshots__/StatusDisplay.test.tsx.snap @@ -10,7 +10,7 @@ exports[`StatusDisplay > renders ContextSummaryDisplay by default 1`] = `"Mock C exports[`StatusDisplay > renders Ctrl+D prompt 1`] = `"Press Ctrl+D again to exit."`; -exports[`StatusDisplay > renders Escape prompt 1`] = `"Press Esc again to clear."`; +exports[`StatusDisplay > renders Escape prompt 1`] = `"Press Esc again to rewind."`; exports[`StatusDisplay > renders HookStatusDisplay when hooks are active 1`] = `"Mock Hook Status Display"`; diff --git a/packages/cli/src/ui/utils/formatters.test.ts b/packages/cli/src/ui/utils/formatters.test.ts index cb3d132421..48c0a2c605 100644 --- a/packages/cli/src/ui/utils/formatters.test.ts +++ b/packages/cli/src/ui/utils/formatters.test.ts @@ -4,8 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { describe, it, expect } from 'vitest'; -import { formatDuration, formatMemoryUsage } from './formatters.js'; +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { + formatDuration, + formatMemoryUsage, + formatTimeAgo, + stripReferenceContent, +} from './formatters.js'; describe('formatters', () => { describe('formatMemoryUsage', () => { @@ -69,4 +74,93 @@ describe('formatters', () => { expect(formatDuration(-100)).toBe('0s'); }); }); + + describe('formatTimeAgo', () => { + const NOW = new Date('2025-01-01T12:00:00Z'); + + beforeEach(() => { + vi.useFakeTimers(); + vi.setSystemTime(NOW); + }); + + afterEach(() => { + vi.useRealTimers(); + }); + + it('should return "just now" for dates less than a minute ago', () => { + const past = new Date(NOW.getTime() - 30 * 1000); + expect(formatTimeAgo(past)).toBe('just now'); + }); + + it('should return minutes ago', () => { + const past = new Date(NOW.getTime() - 5 * 60 * 1000); + expect(formatTimeAgo(past)).toBe('5m ago'); + }); + + it('should return hours ago', () => { + const past = new Date(NOW.getTime() - 3 * 60 * 60 * 1000); + expect(formatTimeAgo(past)).toBe('3h ago'); + }); + + it('should return days ago', () => { + const past = new Date(NOW.getTime() - 2 * 24 * 60 * 60 * 1000); + expect(formatTimeAgo(past)).toBe('48h ago'); + }); + + it('should handle string dates', () => { + const past = '2025-01-01T11:00:00Z'; // 1 hour ago + expect(formatTimeAgo(past)).toBe('1h ago'); + }); + + it('should handle number timestamps', () => { + const past = NOW.getTime() - 10 * 60 * 1000; // 10 minutes ago + expect(formatTimeAgo(past)).toBe('10m ago'); + }); + it('should handle invalid timestamps', () => { + const past = 'hello'; + expect(formatTimeAgo(past)).toBe('invalid date'); + }); + }); + + describe('stripReferenceContent', () => { + it('should return the original text if no markers are present', () => { + const text = 'Hello world'; + expect(stripReferenceContent(text)).toBe(text); + }); + + it('should strip content between markers', () => { + const text = + 'Prompt @file.txt\n--- Content from referenced files ---\nFile content here\n--- End of content ---'; + expect(stripReferenceContent(text)).toBe('Prompt @file.txt'); + }); + + it('should strip content and keep text after the markers', () => { + const text = + 'Before\n--- Content from referenced files ---\nMiddle\n--- End of content ---\nAfter'; + expect(stripReferenceContent(text)).toBe('Before\nAfter'); + }); + + it('should handle missing end marker gracefully', () => { + const text = 'Before\n--- Content from referenced files ---\nMiddle'; + expect(stripReferenceContent(text)).toBe(text); + }); + + it('should handle end marker before start marker gracefully', () => { + const text = + '--- End of content ---\n--- Content from referenced files ---'; + expect(stripReferenceContent(text)).toBe(text); + }); + + it('should strip even if markers are on the same line (though unlikely)', () => { + const text = + 'A--- Content from referenced files ---B--- End of content ---C'; + expect(stripReferenceContent(text)).toBe('AC'); + }); + + it('should strip multiple blocks correctly and preserve text in between', () => { + const text = + 'Start\n--- Content from referenced files ---\nBlock1\n--- End of content ---\nMiddle\n--- Content from referenced files ---\nBlock2\n--- End of content ---\nEnd'; + expect(stripReferenceContent(text)).toBe('Start\nMiddle\nEnd'); + }); + }); }); diff --git a/packages/cli/src/ui/utils/formatters.ts b/packages/cli/src/ui/utils/formatters.ts index 2b6af54598..6552f6c4f7 100644 --- a/packages/cli/src/ui/utils/formatters.ts +++ b/packages/cli/src/ui/utils/formatters.ts @@ -61,3 +61,37 @@ export const formatDuration = (milliseconds: number): string => { return parts.join(' '); }; + +export const formatTimeAgo = (date: string | number | Date): string => { + const past = new Date(date); + if (isNaN(past.getTime())) { + return 'invalid date'; + } + + const now = new Date(); + const diffMs = now.getTime() - past.getTime(); + if (diffMs < 60000) { + return 'just now'; + } + return `${formatDuration(diffMs)} ago`; +}; + +const REFERENCE_CONTENT_START = '--- Content from referenced files ---'; +const REFERENCE_CONTENT_END = '--- End of content ---'; + +/** + * Removes content bounded by reference content markers from the given text. + * The markers are "--- Content from referenced files ---" and "--- End of content ---". + * + * @param text The input text containing potential reference blocks. + * @returns The text with reference blocks removed and trimmed. + */ +export function stripReferenceContent(text: string): string { + // Match optional newline, the start marker, content (non-greedy), and the end marker + const pattern = new RegExp( + `\\n?${REFERENCE_CONTENT_START}[\\s\\S]*?${REFERENCE_CONTENT_END}`, + 'g', + ); + + return text.replace(pattern, '').trim(); +} From 764016bca77ff0e095477e1bb1455af3b671bdd2 Mon Sep 17 00:00:00 2001 From: Emily Hedlund Date: Wed, 14 Jan 2026 12:04:51 -0500 Subject: [PATCH 181/713] fix(a2a): Don't throw errors for GeminiEventType Retry and InvalidStream. (#16541) Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com> --- packages/a2a-server/src/agent/task.test.ts | 38 ++++++++++++++++++++++ packages/a2a-server/src/agent/task.ts | 4 +++ 2 files changed, 42 insertions(+) diff --git a/packages/a2a-server/src/agent/task.test.ts b/packages/a2a-server/src/agent/task.test.ts index 148ce21531..9b5bca8c5c 100644 --- a/packages/a2a-server/src/agent/task.test.ts +++ b/packages/a2a-server/src/agent/task.test.ts @@ -349,6 +349,44 @@ describe('Task', () => { }), ); }); + + it.each([ + { eventType: GeminiEventType.Retry, eventName: 'Retry' }, + { eventType: GeminiEventType.InvalidStream, eventName: 'InvalidStream' }, + ])( + 'should handle $eventName event without triggering error handling', + async ({ eventType }) => { + const mockConfig = createMockConfig(); + const mockEventBus: ExecutionEventBus = { + publish: vi.fn(), + on: vi.fn(), + off: vi.fn(), + once: vi.fn(), + removeAllListeners: vi.fn(), + finished: vi.fn(), + }; + + // @ts-expect-error - Calling private constructor + const task = new Task( + 'task-id', + 'context-id', + mockConfig as Config, + mockEventBus, + ); + + const cancelPendingToolsSpy = vi.spyOn(task, 'cancelPendingTools'); + const setTaskStateSpy = vi.spyOn(task, 'setTaskStateAndPublishUpdate'); + + const event = { + type: eventType, + }; + + await task.acceptAgentMessage(event); + + expect(cancelPendingToolsSpy).not.toHaveBeenCalled(); + expect(setTaskStateSpy).not.toHaveBeenCalled(); + }, + ); }); describe('_schedulerToolCallsUpdate', () => { diff --git a/packages/a2a-server/src/agent/task.ts b/packages/a2a-server/src/agent/task.ts index 187c155808..7bf5e5ad4c 100644 --- a/packages/a2a-server/src/agent/task.ts +++ b/packages/a2a-server/src/agent/task.ts @@ -707,6 +707,10 @@ export class Task { case GeminiEventType.ModelInfo: this.modelInfo = event.value; break; + case GeminiEventType.Retry: + case GeminiEventType.InvalidStream: + // An invalid stream should trigger a retry, which requires no action from the user. + break; case GeminiEventType.Error: default: { // Block scope for lexical declaration From a3234fb534f71f2561083118b0979a2788416f3d Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Wed, 14 Jan 2026 13:50:28 -0500 Subject: [PATCH 182/713] prefactor: add rootCommands as array so it can be used for policy parsing (#16640) --- packages/cli/src/ui/components/HistoryItemDisplay.test.tsx | 1 + .../src/ui/components/messages/ToolConfirmationMessage.test.tsx | 1 + packages/cli/src/ui/utils/textUtils.test.ts | 1 + packages/core/src/core/coreToolScheduler.test.ts | 1 + packages/core/src/test-utils/mock-tool.ts | 1 + packages/core/src/tools/shell.ts | 1 + packages/core/src/tools/tools.ts | 1 + 7 files changed, 7 insertions(+) diff --git a/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx b/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx index 17fd06e6c8..1aecb9a0ba 100644 --- a/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx +++ b/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx @@ -208,6 +208,7 @@ describe('', () => { title: 'Run Shell Command', command: 'echo "\u001b[31mhello\u001b[0m"', rootCommand: 'echo', + rootCommands: ['echo'], onConfirm: async () => {}, }, }, diff --git a/packages/cli/src/ui/components/messages/ToolConfirmationMessage.test.tsx b/packages/cli/src/ui/components/messages/ToolConfirmationMessage.test.tsx index 0291396e63..7444f4f2ec 100644 --- a/packages/cli/src/ui/components/messages/ToolConfirmationMessage.test.tsx +++ b/packages/cli/src/ui/components/messages/ToolConfirmationMessage.test.tsx @@ -83,6 +83,7 @@ describe('ToolConfirmationMessage', () => { title: 'Confirm Execution', command: 'echo "hello"', rootCommand: 'echo', + rootCommands: ['echo'], onConfirm: vi.fn(), }; diff --git a/packages/cli/src/ui/utils/textUtils.test.ts b/packages/cli/src/ui/utils/textUtils.test.ts index f9a90c63b4..e9bb0c196a 100644 --- a/packages/cli/src/ui/utils/textUtils.test.ts +++ b/packages/cli/src/ui/utils/textUtils.test.ts @@ -63,6 +63,7 @@ describe('textUtils', () => { type: 'exec', command: '\u001b[31mmls -l\u001b[0m', rootCommand: '\u001b[32msudo apt-get update\u001b[0m', + rootCommands: ['sudo'], onConfirm: async () => {}, }; diff --git a/packages/core/src/core/coreToolScheduler.test.ts b/packages/core/src/core/coreToolScheduler.test.ts index c27e194cc6..90b8ea7938 100644 --- a/packages/core/src/core/coreToolScheduler.test.ts +++ b/packages/core/src/core/coreToolScheduler.test.ts @@ -1245,6 +1245,7 @@ describe('CoreToolScheduler request queueing', () => { title: 'Confirm Shell Command', command: String(params['command'] ?? ''), rootCommand: 'git', + rootCommands: ['git'], onConfirm: async () => {}, }), execute: () => executeFn({}), diff --git a/packages/core/src/test-utils/mock-tool.ts b/packages/core/src/test-utils/mock-tool.ts index 2c12aa0962..4fa536d2db 100644 --- a/packages/core/src/test-utils/mock-tool.ts +++ b/packages/core/src/test-utils/mock-tool.ts @@ -136,6 +136,7 @@ export const MOCK_TOOL_SHOULD_CONFIRM_EXECUTE = () => title: 'Confirm mockTool', command: 'mockTool', rootCommand: 'mockTool', + rootCommands: ['mockTool'], onConfirm: async () => {}, }); diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index a2d3b611c5..4fc8a64735 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -120,6 +120,7 @@ export class ShellToolInvocation extends BaseToolInvocation< title: 'Confirm Shell Command', command: this.params.command, rootCommand: rootCommands.join(', '), + rootCommands, onConfirm: async (outcome: ToolConfirmationOutcome) => { await this.publishPolicyUpdate(outcome); }, diff --git a/packages/core/src/tools/tools.ts b/packages/core/src/tools/tools.ts index d3efd56ec1..1b365bde40 100644 --- a/packages/core/src/tools/tools.ts +++ b/packages/core/src/tools/tools.ts @@ -693,6 +693,7 @@ export interface ToolExecuteConfirmationDetails { onConfirm: (outcome: ToolConfirmationOutcome) => Promise; command: string; rootCommand: string; + rootCommands: string[]; } export interface ToolMcpConfirmationDetails { From 09a7301d80ed1c29ef4a7bddd2f73481e0d0e421 Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Wed, 14 Jan 2026 12:08:46 -0800 Subject: [PATCH 183/713] remove unnecessary `\x7f` key bindings (#16646) --- docs/cli/keyboard-shortcuts.md | 22 +++++++++++----------- packages/cli/src/config/keyBindings.ts | 8 +------- packages/cli/src/ui/keyMatchers.test.ts | 8 +------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index e56b508d68..96565a5cf3 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -26,17 +26,17 @@ available combinations. #### Editing -| Action | Keys | -| ------------------------------------------------ | -------------------------------------------------------------------------------------------- | -| Delete from the cursor to the end of the line. | `Ctrl + K` | -| Delete from the cursor to the start of the line. | `Ctrl + U` | -| Clear all text in the input field. | `Ctrl + C` | -| Delete the previous word. | `Ctrl + Backspace`
`Cmd + Backspace`
`Ctrl + ""`
`Cmd + ""`
`Ctrl + W` | -| Delete the next word. | `Ctrl + Delete`
`Cmd + Delete` | -| Delete the character to the left. | `Backspace`
`""`
`Ctrl + H` | -| Delete the character to the right. | `Delete`
`Ctrl + D` | -| Undo the most recent text edit. | `Ctrl + Z (no Shift)` | -| Redo the most recent undone text edit. | `Ctrl + Shift + Z` | +| Action | Keys | +| ------------------------------------------------ | --------------------------------------------------------- | +| Delete from the cursor to the end of the line. | `Ctrl + K` | +| Delete from the cursor to the start of the line. | `Ctrl + U` | +| Clear all text in the input field. | `Ctrl + C` | +| Delete the previous word. | `Ctrl + Backspace`
`Cmd + Backspace`
`Ctrl + W` | +| Delete the next word. | `Ctrl + Delete`
`Cmd + Delete` | +| Delete the character to the left. | `Backspace`
`Ctrl + H` | +| Delete the character to the right. | `Delete`
`Ctrl + D` | +| Undo the most recent text edit. | `Ctrl + Z (no Shift)` | +| Redo the most recent undone text edit. | `Ctrl + Shift + Z` | #### Screen Control diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index 915128487a..432d958489 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -136,8 +136,6 @@ export const defaultKeyBindings: KeyBindingConfig = { [Command.DELETE_WORD_BACKWARD]: [ { key: 'backspace', ctrl: true }, { key: 'backspace', command: true }, - { sequence: '\x7f', ctrl: true }, - { sequence: '\x7f', command: true }, { key: 'w', ctrl: true }, ], [Command.MOVE_LEFT]: [ @@ -158,11 +156,7 @@ export const defaultKeyBindings: KeyBindingConfig = { { key: 'right', command: true }, { key: 'f', command: true }, ], - [Command.DELETE_CHAR_LEFT]: [ - { key: 'backspace' }, - { sequence: '\x7f' }, - { key: 'h', ctrl: true }, - ], + [Command.DELETE_CHAR_LEFT]: [{ key: 'backspace' }, { key: 'h', ctrl: true }], [Command.DELETE_CHAR_RIGHT]: [{ key: 'delete' }, { key: 'd', ctrl: true }], [Command.DELETE_WORD_FORWARD]: [ { key: 'delete', ctrl: true }, diff --git a/packages/cli/src/ui/keyMatchers.test.ts b/packages/cli/src/ui/keyMatchers.test.ts index 4b112de358..06af0e0a95 100644 --- a/packages/cli/src/ui/keyMatchers.test.ts +++ b/packages/cli/src/ui/keyMatchers.test.ts @@ -102,11 +102,7 @@ describe('keyMatchers', () => { }, { command: Command.DELETE_CHAR_LEFT, - positive: [ - createKey('backspace'), - { ...createKey('\x7f'), sequence: '\x7f' }, - createKey('h', { ctrl: true }), - ], + positive: [createKey('backspace'), createKey('h', { ctrl: true })], negative: [createKey('h'), createKey('x', { ctrl: true })], }, { @@ -119,8 +115,6 @@ describe('keyMatchers', () => { positive: [ createKey('backspace', { ctrl: true }), createKey('backspace', { meta: true }), - { ...createKey('\x7f', { ctrl: true }), sequence: '\x7f' }, - { ...createKey('\x7f', { meta: true }), sequence: '\x7f' }, createKey('w', { ctrl: true }), ], negative: [createKey('backspace'), createKey('delete', { ctrl: true })], From 4db00b8f2ae808784910b89a5afa5a2d2a5c935c Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Wed, 14 Jan 2026 15:23:04 -0500 Subject: [PATCH 184/713] docs(skills): use body-file in pr-creator skill for better reliability (#16642) --- .gemini/skills/pr-creator/SKILL.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.gemini/skills/pr-creator/SKILL.md b/.gemini/skills/pr-creator/SKILL.md index db845b2dbc..d1fea8edf1 100644 --- a/.gemini/skills/pr-creator/SKILL.md +++ b/.gemini/skills/pr-creator/SKILL.md @@ -35,9 +35,15 @@ Follow these steps to create a Pull Request: - **Related Issues**: Link any issues fixed or related to this PR (e.g., "Fixes #123"). -4. **Create PR**: Use the `gh` CLI to create the PR. +4. **Create PR**: Use the `gh` CLI to create the PR. To avoid shell escaping + issues with multi-line Markdown, write the description to a temporary file + first. ```bash - gh pr create --title "type(scope): succinct description" --body "..." + # 1. Write the drafted description to a temporary file + # 2. Create the PR using the --body-file flag + gh pr create --title "type(scope): succinct description" --body-file + # 3. Remove the temporary file + rm ``` - **Title**: Ensure the title follows the [Conventional Commits](https://www.conventionalcommits.org/) format if the From 1212161d1d170c4edd8643d16ef54ae76b244bbb Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Wed, 14 Jan 2026 15:56:16 -0500 Subject: [PATCH 185/713] chore(automation): recursive labeling for workstream descendants (#16609) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .github/scripts/pr-triage.sh | 2 +- .github/scripts/sync-maintainer-labels.cjs | 355 ++++++++++++++++++ .../gemini-scheduled-issue-triage.yml | 23 +- .../workflows/label-backlog-child-issues.yml | 71 ++-- 4 files changed, 408 insertions(+), 43 deletions(-) create mode 100644 .github/scripts/sync-maintainer-labels.cjs diff --git a/.github/scripts/pr-triage.sh b/.github/scripts/pr-triage.sh index 45dfcf7a3c..ddbe4182ce 100755 --- a/.github/scripts/pr-triage.sh +++ b/.github/scripts/pr-triage.sh @@ -55,7 +55,7 @@ process_pr_optimized() { if [[ -z "${ISSUE_NUMBER}" || "${ISSUE_NUMBER}" == "null" || "${ISSUE_NUMBER}" == "" ]]; then if [[ "${IS_DRAFT}" == "true" ]]; then echo " 📝 PR #${PR_NUMBER} is a draft and has no linked issue" - if [[ ",${CURRENT_LABELS}," == ",status/need-issue,"* ]]; then + if [[ ",${CURRENT_LABELS}," == *",status/need-issue,"* ]]; then echo " ➖ Removing status/need-issue label" LABELS_TO_REMOVE="status/need-issue" fi diff --git a/.github/scripts/sync-maintainer-labels.cjs b/.github/scripts/sync-maintainer-labels.cjs new file mode 100644 index 0000000000..ab2358d369 --- /dev/null +++ b/.github/scripts/sync-maintainer-labels.cjs @@ -0,0 +1,355 @@ +/* eslint-disable @typescript-eslint/no-require-imports */ +/* global process, console, require */ +const { Octokit } = require('@octokit/rest'); + +/** + * Sync Maintainer Labels (Recursive with strict parent-child relationship detection) + * - Uses Native Sub-issues. + * - Uses Markdown Task Lists (- [ ] #123). + * - Filters for OPEN issues only. + * - Skips DUPLICATES. + * - Skips Pull Requests. + * - ONLY labels issues in the PUBLIC (gemini-cli) repo. + */ + +const REPO_OWNER = 'google-gemini'; +const PUBLIC_REPO = 'gemini-cli'; +const PRIVATE_REPO = 'maintainers-gemini-cli'; +const ALLOWED_REPOS = [PUBLIC_REPO, PRIVATE_REPO]; + +const ROOT_ISSUES = [ + { owner: REPO_OWNER, repo: PUBLIC_REPO, number: 15374 }, + { owner: REPO_OWNER, repo: PUBLIC_REPO, number: 15456 }, + { owner: REPO_OWNER, repo: PUBLIC_REPO, number: 15324 }, +]; + +const TARGET_LABEL = '🔒 maintainer only'; +const isDryRun = + process.argv.includes('--dry-run') || process.env.DRY_RUN === 'true'; + +const octokit = new Octokit({ + auth: process.env.GITHUB_TOKEN, +}); + +/** + * Extracts child issue references from markdown Task Lists ONLY. + * e.g. - [ ] #123 or - [x] google-gemini/gemini-cli#123 + */ +function extractTaskListLinks(text, contextOwner, contextRepo) { + if (!text) return []; + const childIssues = new Map(); + + const add = (owner, repo, number) => { + if (ALLOWED_REPOS.includes(repo)) { + const key = `${owner}/${repo}#${number}`; + childIssues.set(key, { owner, repo, number: parseInt(number, 10) }); + } + }; + + // 1. Full URLs in task lists + const urlRegex = + /-\s+\[[ x]\].*https:\/\/github\.com\/([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)\/issues\/(\d+)\b/g; + let match; + while ((match = urlRegex.exec(text)) !== null) { + add(match[1], match[2], match[3]); + } + + // 2. Cross-repo refs in task lists: owner/repo#123 + const crossRepoRegex = + /-\s+\[[ x]\].*([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)#(\d+)\b/g; + while ((match = crossRepoRegex.exec(text)) !== null) { + add(match[1], match[2], match[3]); + } + + // 3. Short refs in task lists: #123 + const shortRefRegex = /-\s+\[[ x]\].*#(\d+)\b/g; + while ((match = shortRefRegex.exec(text)) !== null) { + add(contextOwner, contextRepo, match[1]); + } + + return Array.from(childIssues.values()); +} + +/** + * Fetches issue data via GraphQL with full pagination for sub-issues, comments, and labels. + */ +async function fetchIssueData(owner, repo, number) { + const query = ` + query($owner:String!, $repo:String!, $number:Int!) { + repository(owner:$owner, name:$repo) { + issue(number:$number) { + state + title + body + labels(first: 100) { + nodes { name } + pageInfo { hasNextPage endCursor } + } + subIssues(first: 100) { + nodes { + number + repository { + name + owner { login } + } + } + pageInfo { hasNextPage endCursor } + } + comments(first: 100) { + nodes { + body + } + } + } + } + } + `; + + try { + const response = await octokit.graphql(query, { owner, repo, number }); + const data = response.repository.issue; + if (!data) return null; + + const issue = { + state: data.state, + title: data.title, + body: data.body || '', + labels: data.labels.nodes.map((n) => n.name), + subIssues: [...data.subIssues.nodes], + comments: data.comments.nodes.map((n) => n.body), + }; + + // Paginate subIssues if there are more than 100 + if (data.subIssues.pageInfo.hasNextPage) { + const moreSubIssues = await paginateConnection( + owner, + repo, + number, + 'subIssues', + 'number repository { name owner { login } }', + data.subIssues.pageInfo.endCursor, + ); + issue.subIssues.push(...moreSubIssues); + } + + // Paginate labels if there are more than 100 (unlikely but for completeness) + if (data.labels.pageInfo.hasNextPage) { + const moreLabels = await paginateConnection( + owner, + repo, + number, + 'labels', + 'name', + data.labels.pageInfo.endCursor, + (n) => n.name, + ); + issue.labels.push(...moreLabels); + } + + // Note: Comments are handled via Task Lists in body + first 100 comments. + // If an issue has > 100 comments with task lists, we'd need to paginate those too. + // Given the 1,100+ issue discovery count, 100 comments is usually sufficient, + // but we can add it for absolute completeness. + // (Skipping for now to avoid excessive API churn unless clearly needed). + + return issue; + } catch (error) { + if (error.errors && error.errors.some((e) => e.type === 'NOT_FOUND')) { + return null; + } + throw error; + } +} + +/** + * Helper to paginate any GraphQL connection. + */ +async function paginateConnection( + owner, + repo, + number, + connectionName, + nodeFields, + initialCursor, + transformNode = (n) => n, +) { + let additionalNodes = []; + let hasNext = true; + let cursor = initialCursor; + + while (hasNext) { + const query = ` + query($owner:String!, $repo:String!, $number:Int!, $cursor:String) { + repository(owner:$owner, name:$repo) { + issue(number:$number) { + ${connectionName}(first: 100, after: $cursor) { + nodes { ${nodeFields} } + pageInfo { hasNextPage endCursor } + } + } + } + } + `; + const response = await octokit.graphql(query, { + owner, + repo, + number, + cursor, + }); + const connection = response.repository.issue[connectionName]; + additionalNodes.push(...connection.nodes.map(transformNode)); + hasNext = connection.pageInfo.hasNextPage; + cursor = connection.pageInfo.endCursor; + } + return additionalNodes; +} + +/** + * Validates if an issue should be processed (Open, not a duplicate, not a PR) + */ +function shouldProcess(issueData) { + if (!issueData) return false; + + if (issueData.state !== 'OPEN') return false; + + const labels = issueData.labels.map((l) => l.toLowerCase()); + if (labels.includes('duplicate') || labels.includes('kind/duplicate')) { + return false; + } + + return true; +} + +async function getAllDescendants(roots) { + const allDescendants = new Map(); + const visited = new Set(); + const queue = [...roots]; + + for (const root of roots) { + visited.add(`${root.owner}/${root.repo}#${root.number}`); + } + + console.log(`Starting discovery from ${roots.length} roots...`); + + while (queue.length > 0) { + const current = queue.shift(); + const currentKey = `${current.owner}/${current.repo}#${current.number}`; + + try { + const issueData = await fetchIssueData( + current.owner, + current.repo, + current.number, + ); + + if (!shouldProcess(issueData)) { + continue; + } + + // ONLY add to labeling list if it's in the PUBLIC repository + if (current.repo === PUBLIC_REPO) { + // Don't label the roots themselves + if ( + !ROOT_ISSUES.some( + (r) => r.number === current.number && r.repo === current.repo, + ) + ) { + allDescendants.set(currentKey, { + ...current, + title: issueData.title, + labels: issueData.labels, + }); + } + } + + const children = new Map(); + + // 1. Process Native Sub-issues + if (issueData.subIssues) { + for (const node of issueData.subIssues) { + const childOwner = node.repository.owner.login; + const childRepo = node.repository.name; + const childNumber = node.number; + const key = `${childOwner}/${childRepo}#${childNumber}`; + children.set(key, { + owner: childOwner, + repo: childRepo, + number: childNumber, + }); + } + } + + // 2. Process Markdown Task Lists in Body and Comments + let combinedText = issueData.body || ''; + if (issueData.comments) { + for (const commentBody of issueData.comments) { + combinedText += '\n' + (commentBody || ''); + } + } + + const taskListLinks = extractTaskListLinks( + combinedText, + current.owner, + current.repo, + ); + for (const link of taskListLinks) { + const key = `${link.owner}/${link.repo}#${link.number}`; + children.set(key, link); + } + + // Queue children (regardless of which repo they are in, for recursion) + for (const [key, child] of children) { + if (!visited.has(key)) { + visited.add(key); + queue.push(child); + } + } + } catch (error) { + console.error(`Error processing ${currentKey}: ${error.message}`); + } + } + + return Array.from(allDescendants.values()); +} + +async function run() { + if (isDryRun) { + console.log('=== DRY RUN MODE: No labels will be applied ==='); + } + + const descendants = await getAllDescendants(ROOT_ISSUES); + console.log( + `\nFound ${descendants.length} total unique open descendant issues in ${PUBLIC_REPO}.`, + ); + + for (const issueInfo of descendants) { + const issueKey = `${issueInfo.owner}/${issueInfo.repo}#${issueInfo.number}`; + try { + // Data is already available from the discovery phase + const hasLabel = issueInfo.labels.some((l) => l === TARGET_LABEL); + + if (!hasLabel) { + if (isDryRun) { + console.log( + `[DRY RUN] Would label ${issueKey}: "${issueInfo.title}"`, + ); + } else { + console.log(`Labeling ${issueKey}: "${issueInfo.title}"...`); + await octokit.rest.issues.addLabels({ + owner: issueInfo.owner, + repo: issueInfo.repo, + issue_number: issueInfo.number, + labels: [TARGET_LABEL], + }); + } + } + } catch (error) { + console.error(`Error processing label for ${issueKey}: ${error.message}`); + } + } +} + +run().catch((error) => { + console.error(error); + process.exit(1); +}); diff --git a/.github/workflows/gemini-scheduled-issue-triage.yml b/.github/workflows/gemini-scheduled-issue-triage.yml index 6c3fbb7c63..6aaeb950cf 100644 --- a/.github/workflows/gemini-scheduled-issue-triage.yml +++ b/.github/workflows/gemini-scheduled-issue-triage.yml @@ -238,23 +238,16 @@ jobs: core.info(`Raw labels JSON: ${rawLabels}`); let parsedLabels; try { - // First, try to parse the raw output as JSON. - parsedLabels = JSON.parse(rawLabels.trim()); - } catch (jsonError) { - // If that fails, check for a markdown code block. - core.info(`Direct JSON parsing failed: ${jsonError.message}. Trying to extract from a markdown block.`); const jsonMatch = rawLabels.match(/```json\s*([\s\S]*?)\s*```/); - if (jsonMatch && jsonMatch[1]) { - try { - parsedLabels = JSON.parse(jsonMatch[1].trim()); - } catch (markdownError) { - core.setFailed(`Failed to parse JSON even after extracting from markdown block: ${markdownError.message}\nRaw output: ${rawLabels}`); - return; - } - } else { - core.setFailed(`Output is not valid JSON and does not contain a JSON markdown block.\nRaw output: ${rawLabels}`); - return; + if (!jsonMatch || !jsonMatch[1]) { + throw new Error("Could not find a ```json ... ``` block in the output."); } + const jsonString = jsonMatch[1].trim(); + parsedLabels = JSON.parse(jsonString); + core.info(`Parsed labels JSON: ${JSON.stringify(parsedLabels)}`); + } catch (err) { + core.setFailed(`Failed to parse labels JSON from Gemini output: ${err.message}\nRaw output: ${rawLabels}`); + return; } for (const entry of parsedLabels) { diff --git a/.github/workflows/label-backlog-child-issues.yml b/.github/workflows/label-backlog-child-issues.yml index 80774843e3..b11f509f80 100644 --- a/.github/workflows/label-backlog-child-issues.yml +++ b/.github/workflows/label-backlog-child-issues.yml @@ -3,38 +3,55 @@ name: 'Label Child Issues for Project Rollup' on: issues: types: ['opened', 'edited', 'reopened'] + schedule: + - cron: '0 * * * *' # Run every hour + workflow_dispatch: + +permissions: + issues: 'write' + contents: 'read' jobs: + # Event-based: Quick reaction to new/edited issues in THIS repo labeler: + if: "github.event_name == 'issues'" runs-on: 'ubuntu-latest' - permissions: - issues: 'write' steps: - - name: 'Check for Parent Workstream and Apply Label' - uses: 'actions/github-script@v7' + - name: 'Checkout' + uses: 'actions/checkout@v4' + + - name: 'Setup Node.js' + uses: 'actions/setup-node@v4' with: - script: | - const issue = context.payload.issue; - const labelToAdd = 'workstream-rollup'; + node-version: '20' + cache: 'npm' - // --- Define the FULL URLs of the allowed parent workstreams --- - const allowedParentUrls = [ - 'https://api.github.com/repos/google-gemini/gemini-cli/issues/15374', - 'https://api.github.com/repos/google-gemini/gemini-cli/issues/15456', - 'https://api.github.com/repos/google-gemini/gemini-cli/issues/15324' - ]; + - name: 'Install Dependencies' + run: 'npm ci' - // Check if the issue has a parent_issue_url and if it's in our allowed list. - if (issue && issue.parent_issue_url && allowedParentUrls.includes(issue.parent_issue_url)) { - console.log(`SUCCESS: Issue #${issue.number} is a child of a target workstream (${issue.parent_issue_url}). Adding label.`); - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue.number, - labels: [labelToAdd] - }); - } else if (issue && issue.parent_issue_url) { - console.log(`FAILURE: Issue #${issue.number} has a parent, but it's not a target workstream. Parent URL: ${issue.parent_issue_url}`); - } else { - console.log(`FAILURE: Issue #${issue.number} is not a child of any issue. No action taken.`); - } + - name: 'Run Multi-Repo Sync Script' + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + run: 'node .github/scripts/sync-maintainer-labels.cjs' + + # Scheduled/Manual: Recursive sync across multiple repos + sync-maintainer-labels: + if: "github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'" + runs-on: 'ubuntu-latest' + steps: + - name: 'Checkout' + uses: 'actions/checkout@v4' + + - name: 'Setup Node.js' + uses: 'actions/setup-node@v4' + with: + node-version: '20' + cache: 'npm' + + - name: 'Install Dependencies' + run: 'npm ci' + + - name: 'Run Multi-Repo Sync Script' + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + run: 'node .github/scripts/sync-maintainer-labels.cjs' From 16b35910e2b919b249199fdefc4adff629b12705 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 14 Jan 2026 12:57:46 -0800 Subject: [PATCH 186/713] feat: introduce 'skill-creator' built-in skill and CJS management tools (#16394) --- .prettierignore | 1 + eslint.config.js | 1 + .../skill-creator-scripts.test.ts | 97 +++++ .../skill-creator-vulnerabilities.test.ts | 111 +++++ .../src/skills/builtin/skill-creator/SKILL.md | 382 ++++++++++++++++++ .../skill-creator/scripts/init_skill.cjs | 235 +++++++++++ .../skill-creator/scripts/package_skill.cjs | 87 ++++ .../skill-creator/scripts/validate_skill.cjs | 127 ++++++ 8 files changed, 1041 insertions(+) create mode 100644 integration-tests/skill-creator-scripts.test.ts create mode 100644 integration-tests/skill-creator-vulnerabilities.test.ts create mode 100644 packages/core/src/skills/builtin/skill-creator/SKILL.md create mode 100644 packages/core/src/skills/builtin/skill-creator/scripts/init_skill.cjs create mode 100644 packages/core/src/skills/builtin/skill-creator/scripts/package_skill.cjs create mode 100644 packages/core/src/skills/builtin/skill-creator/scripts/validate_skill.cjs diff --git a/.prettierignore b/.prettierignore index 120f04c358..e8f035ad74 100644 --- a/.prettierignore +++ b/.prettierignore @@ -20,3 +20,4 @@ junit.xml .gemini-linters/ Thumbs.db .pytest_cache +**/SKILL.md diff --git a/eslint.config.js b/eslint.config.js index 0f20eeab42..3dcb7d8903 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -37,6 +37,7 @@ export default tseslint.config( 'dist/**', 'evals/**', 'packages/test-utils/**', + 'packages/core/src/skills/builtin/skill-creator/scripts/*.cjs', ], }, eslint.configs.recommended, diff --git a/integration-tests/skill-creator-scripts.test.ts b/integration-tests/skill-creator-scripts.test.ts new file mode 100644 index 0000000000..fe58ed9d90 --- /dev/null +++ b/integration-tests/skill-creator-scripts.test.ts @@ -0,0 +1,97 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; +import { TestRig } from './test-helper.js'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import { execSync } from 'node:child_process'; + +describe('skill-creator scripts e2e', () => { + let rig: TestRig; + const initScript = path.resolve( + 'packages/core/src/skills/builtin/skill-creator/scripts/init_skill.cjs', + ); + const validateScript = path.resolve( + 'packages/core/src/skills/builtin/skill-creator/scripts/validate_skill.cjs', + ); + const packageScript = path.resolve( + 'packages/core/src/skills/builtin/skill-creator/scripts/package_skill.cjs', + ); + + beforeEach(() => { + rig = new TestRig(); + }); + + afterEach(async () => { + await rig.cleanup(); + }); + + it('should initialize, validate, and package a skill', async () => { + await rig.setup('skill-creator scripts e2e'); + const skillName = 'e2e-test-skill'; + const tempDir = rig.testDir!; + + // 1. Initialize + execSync(`node "${initScript}" ${skillName} --path "${tempDir}"`, { + stdio: 'inherit', + }); + const skillDir = path.join(tempDir, skillName); + + expect(fs.existsSync(skillDir)).toBe(true); + expect(fs.existsSync(path.join(skillDir, 'SKILL.md'))).toBe(true); + expect( + fs.existsSync(path.join(skillDir, 'scripts/example_script.cjs')), + ).toBe(true); + + // 2. Validate (should have warning initially due to TODOs) + const validateOutputInitial = execSync( + `node "${validateScript}" "${skillDir}" 2>&1`, + { encoding: 'utf8' }, + ); + expect(validateOutputInitial).toContain('⚠️ Found unresolved TODO'); + + // 3. Package (should fail due to TODOs) + try { + execSync(`node "${packageScript}" "${skillDir}" "${tempDir}"`, { + stdio: 'pipe', + }); + throw new Error('Packaging should have failed due to TODOs'); + } catch (err: unknown) { + expect((err as Error).message).toContain('Command failed'); + } + + // 4. Fix SKILL.md (remove TODOs) + let content = fs.readFileSync(path.join(skillDir, 'SKILL.md'), 'utf8'); + content = content.replace(/TODO: .+/g, 'Fixed'); + content = content.replace(/\[TODO: .+/g, 'Fixed'); + fs.writeFileSync(path.join(skillDir, 'SKILL.md'), content); + + // Also remove TODOs from example scripts + const exampleScriptPath = path.join(skillDir, 'scripts/example_script.cjs'); + let scriptContent = fs.readFileSync(exampleScriptPath, 'utf8'); + scriptContent = scriptContent.replace(/TODO: .+/g, 'Fixed'); + fs.writeFileSync(exampleScriptPath, scriptContent); + + // 4. Validate again (should pass now) + const validateOutput = execSync(`node "${validateScript}" "${skillDir}"`, { + encoding: 'utf8', + }); + expect(validateOutput).toContain('Skill is valid!'); + + // 5. Package + execSync(`node "${packageScript}" "${skillDir}" "${tempDir}"`, { + stdio: 'inherit', + }); + const skillFile = path.join(tempDir, `${skillName}.skill`); + expect(fs.existsSync(skillFile)).toBe(true); + + // 6. Verify zip content (should NOT have nested directory) + const zipList = execSync(`unzip -l "${skillFile}"`, { encoding: 'utf8' }); + expect(zipList).toContain('SKILL.md'); + expect(zipList).not.toContain(`${skillName}/SKILL.md`); + }); +}); diff --git a/integration-tests/skill-creator-vulnerabilities.test.ts b/integration-tests/skill-creator-vulnerabilities.test.ts new file mode 100644 index 0000000000..b94273e57f --- /dev/null +++ b/integration-tests/skill-creator-vulnerabilities.test.ts @@ -0,0 +1,111 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; +import { TestRig } from './test-helper.js'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import { execSync, spawnSync } from 'node:child_process'; + +describe('skill-creator scripts security and bug fixes', () => { + let rig: TestRig; + const initScript = path.resolve( + 'packages/core/src/skills/builtin/skill-creator/scripts/init_skill.cjs', + ); + const validateScript = path.resolve( + 'packages/core/src/skills/builtin/skill-creator/scripts/validate_skill.cjs', + ); + const packageScript = path.resolve( + 'packages/core/src/skills/builtin/skill-creator/scripts/package_skill.cjs', + ); + + beforeEach(() => { + rig = new TestRig(); + }); + + afterEach(async () => { + await rig.cleanup(); + }); + + it('should prevent command injection in package_skill.cjs', async () => { + await rig.setup('skill-creator command injection'); + const tempDir = rig.testDir!; + + // Create a dummy skill + const skillName = 'injection-test'; + execSync(`node "${initScript}" ${skillName} --path "${tempDir}"`); + const skillDir = path.join(tempDir, skillName); + + // Malicious output filename with command injection + const maliciousFilename = '"; touch injection_success; #'; + + // Attempt to package with malicious filename + // We expect this to fail or at least NOT create the 'injection_success' file + spawnSync('node', [packageScript, skillDir, tempDir, maliciousFilename], { + cwd: tempDir, + }); + + const injectionFile = path.join(tempDir, 'injection_success'); + expect(fs.existsSync(injectionFile)).toBe(false); + }); + + it('should prevent path traversal in init_skill.cjs', async () => { + await rig.setup('skill-creator init path traversal'); + const tempDir = rig.testDir!; + + const maliciousName = '../traversal-success'; + + const result = spawnSync( + 'node', + [initScript, maliciousName, '--path', tempDir], + { + encoding: 'utf8', + }, + ); + + expect(result.stderr).toContain( + 'Error: Skill name cannot contain path separators', + ); + const traversalDir = path.join(path.dirname(tempDir), 'traversal-success'); + expect(fs.existsSync(traversalDir)).toBe(false); + }); + + it('should prevent path traversal in validate_skill.cjs', async () => { + await rig.setup('skill-creator validate path traversal'); + + const maliciousPath = '../../../../etc/passwd'; + const result = spawnSync('node', [validateScript, maliciousPath], { + encoding: 'utf8', + }); + + expect(result.stderr).toContain('Error: Path traversal detected'); + }); + + it('should not crash on empty description in validate_skill.cjs', async () => { + await rig.setup('skill-creator regex crash'); + const tempDir = rig.testDir!; + const skillName = 'empty-desc-skill'; + + execSync(`node "${initScript}" ${skillName} --path "${tempDir}"`); + const skillDir = path.join(tempDir, skillName); + const skillMd = path.join(skillDir, 'SKILL.md'); + + // Set an empty quoted description + let content = fs.readFileSync(skillMd, 'utf8'); + content = content.replace(/^description: .+$/m, 'description: ""'); + fs.writeFileSync(skillMd, content); + + const result = spawnSync('node', [validateScript, skillDir], { + encoding: 'utf8', + }); + + // It might still fail validation (e.g. TODOs), but it should NOT crash with a stack trace + expect(result.status).not.toBe(null); + expect(result.stderr).not.toContain( + "TypeError: Cannot read properties of undefined (reading 'trim')", + ); + }); +}); diff --git a/packages/core/src/skills/builtin/skill-creator/SKILL.md b/packages/core/src/skills/builtin/skill-creator/SKILL.md new file mode 100644 index 0000000000..57996a25cd --- /dev/null +++ b/packages/core/src/skills/builtin/skill-creator/SKILL.md @@ -0,0 +1,382 @@ +--- +name: skill-creator +description: Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Gemini CLI's capabilities with specialized knowledge, workflows, or tool integrations. +--- + +# Skill Creator + +This skill provides guidance for creating effective skills. + +## About Skills + +Skills are modular, self-contained packages that extend Gemini CLI's capabilities by providing specialized knowledge, workflows, and tools. Think of them as "onboarding guides" for specific domains or tasks—they transform Gemini CLI from a general-purpose agent into a specialized agent equipped with procedural knowledge that no model can fully possess. + +### What Skills Provide + +1. Specialized workflows - Multi-step procedures for specific domains +2. Tool integrations - Instructions for working with specific file formats or APIs +3. Domain expertise - Company-specific knowledge, schemas, business logic +4. Bundled resources - Scripts, references, and assets for complex and repetitive tasks + +## Core Principles + +### Concise is Key + +The context window is a public good. Skills share the context window with everything else Gemini CLI needs: system prompt, conversation history, other Skills' metadata, and the actual user request. + +**Default assumption: Gemini CLI is already very smart.** Only add context Gemini CLI doesn't already have. Challenge each piece of information: "Does Gemini CLI really need this explanation?" and "Does this paragraph justify its token cost?" + +Prefer concise examples over verbose explanations. + +### Set Appropriate Degrees of Freedom + +Match the level of specificity to the task's fragility and variability: + +**High freedom (text-based instructions)**: Use when multiple approaches are valid, decisions depend on context, or heuristics guide the approach. + +**Medium freedom (pseudocode or scripts with parameters)**: Use when a preferred pattern exists, some variation is acceptable, or configuration affects behavior. + +**Low freedom (specific scripts, few parameters)**: Use when operations are fragile and error-prone, consistency is critical, or a specific sequence must be followed. + +Think of Gemini CLI as exploring a path: a narrow bridge with cliffs needs specific guardrails (low freedom), while an open field allows many routes (high freedom). + +### Anatomy of a Skill + +Every skill consists of a required SKILL.md file and optional bundled resources: + +``` +skill-name/ +├── SKILL.md (required) +│ ├── YAML frontmatter metadata (required) +│ │ ├── name: (required) +│ │ └── description: (required) +│ └── Markdown instructions (required) +└── Bundled Resources (optional) + ├── scripts/ - Executable code (Node.js/Python/Bash/etc.) + ├── references/ - Documentation intended to be loaded into context as needed + └── assets/ - Files used in output (templates, icons, fonts, etc.) +``` + +#### SKILL.md (required) + +Every SKILL.md consists of: + +- **Frontmatter** (YAML): Contains `name` and `description` fields. These are the only fields that Gemini CLI reads to determine when the skill gets used, thus it is very important to be clear and comprehensive in describing what the skill is, and when it should be used. +- **Body** (Markdown): Instructions and guidance for using the skill. Only loaded AFTER the skill triggers (if at all). + +#### Bundled Resources (optional) + +##### Scripts (`scripts/`) + +Executable code (Node.js/Python/Bash/etc.) for tasks that require deterministic reliability or are repeatedly rewritten. + +- **When to include**: When the same code is being rewritten repeatedly or deterministic reliability is needed +- **Example**: `scripts/rotate_pdf.cjs` for PDF rotation tasks +- **Benefits**: Token efficient, deterministic, may be executed without loading into context +- **Agentic Ergonomics**: Scripts must output LLM-friendly stdout. Suppress standard tracebacks. Output clear, concise success/failure messages, and paginate or truncate outputs (e.g., "Success: First 50 lines of processed file...") to prevent context window overflow. +- **Note**: Scripts may still need to be read by Gemini CLI for patching or environment-specific adjustments + +##### References (`references/`) + +Documentation and reference material intended to be loaded as needed into context to inform Gemini CLI's process and thinking. + +- **When to include**: For documentation that Gemini CLI should reference while working +- **Examples**: `references/finance.md` for financial schemas, `references/mnda.md` for company NDA template, `references/policies.md` for company policies, `references/api_docs.md` for API specifications +- **Use cases**: Database schemas, API documentation, domain knowledge, company policies, detailed workflow guides +- **Benefits**: Keeps SKILL.md lean, loaded only when Gemini CLI determines it's needed +- **Best practice**: If files are large (>10k words), include grep search patterns in SKILL.md +- **Avoid duplication**: Information should live in either SKILL.md or + references files, not both. Prefer references files for detailed information unless it's truly core to the skill—this keeps SKILL.md lean while making information discoverable without hogging the context window. Keep only essential procedural instructions and workflow guidance in SKILL.md; move detailed reference material, schemas, and examples to references files. + +##### Assets (`assets/`) + +Files not intended to be loaded into context, but rather used within the output Gemini CLI produces. + +- **When to include**: When the skill needs files that will be used in the final output +- **Examples**: `assets/logo.png` for brand assets, `assets/slides.pptx` for PowerPoint templates, `assets/frontend-template/` for HTML/React boilerplate, `assets/font.ttf` for typography +- **Use cases**: Templates, images, icons, boilerplate code, fonts, sample documents that get copied or modified +- **Benefits**: Separates output resources from documentation, enables Gemini CLI to use files without loading them into context + +#### What to Not Include in a Skill + +A skill should only contain essential files that directly support its functionality. Do NOT create extraneous documentation or auxiliary files, including: + +- README.md +- INSTALLATION_GUIDE.md +- QUICK_REFERENCE.md +- CHANGELOG.md +- etc. + +The skill should only contain the information needed for an AI agent to do the job at hand. It should not contain auxiliary context about the process that went into creating it, setup and testing procedures, user-facing documentation, etc. Creating additional documentation files just adds clutter and confusion. + +### Progressive Disclosure Design Principle + +Skills use a three-level loading system to manage context efficiently: + +1. **Metadata (name + description)** - Always in context (~100 words) +2. **SKILL.md body** - When skill triggers (<5k words) +3. **Bundled resources** - As needed by Gemini CLI (Unlimited because scripts can be executed without reading into context window) + +#### Progressive Disclosure Patterns + +Keep SKILL.md body to the essentials and under 500 lines to minimize context bloat. Split content into separate files when approaching this limit. When splitting out content into other files, it is very important to reference them from SKILL.md and describe clearly when to read them, to ensure the reader of the skill knows they exist and when to use them. + +**Key principle:** When a skill supports multiple variations, frameworks, or options, keep only the core workflow and selection guidance in SKILL.md. Move variant-specific details (patterns, examples, configuration) into separate reference files. + +**Pattern 1: High-level guide with references** + +```markdown +# PDF Processing + +## Quick start + +Extract text with pdfplumber: [code example] + +## Advanced features + +- **Form filling**: See [FORMS.md](FORMS.md) for complete guide +- **API reference**: See [REFERENCE.md](REFERENCE.md) for all methods +- **Examples**: See [EXAMPLES.md](EXAMPLES.md) for common patterns +``` + +Gemini CLI loads FORMS.md, REFERENCE.md, or EXAMPLES.md only when needed. + +**Pattern 2: Domain-specific organization** + +For Skills with multiple domains, organize content by domain to avoid loading irrelevant context: + +``` +bigquery-skill/ +├── SKILL.md (overview and navigation) +└── reference/ + ├── finance.md (revenue, billing metrics) + ├── sales.md (opportunities, pipeline) + ├── product.md (API usage, features) + └── marketing.md (campaigns, attribution) +``` + +When a user asks about sales metrics, Gemini CLI only reads sales.md. + +Similarly, for skills supporting multiple frameworks or variants, organize by variant: + +``` +cloud-deploy/ +├── SKILL.md (workflow + provider selection) +└── references/ + ├── aws.md (AWS deployment patterns) + ├── gcp.md (GCP deployment patterns) + └── azure.md (Azure deployment patterns) +``` + +When the user chooses AWS, Gemini CLI only reads aws.md. + +**Pattern 3: Conditional details** + +Show basic content, link to advanced content: + +```markdown +# CSV Processing + +## Basic Analysis + +Use pandas for loading and basic queries. See [PANDAS.md](PANDAS.md). + +## Advanced Operations + +For massive files that exceed memory, see [STREAMING.md](STREAMING.md). For timestamp normalization, see [TIMESTAMPS.md](TIMESTAMPS.md). + +Gemini CLI reads REDLINING.md or OOXML.md only when the user needs those features. +``` + +**Important guidelines:** + +- **Avoid deeply nested references** - Keep references one level deep from SKILL.md. All reference files should link directly from SKILL.md. +- **Structure longer reference files** - For files longer than 100 lines, include a table of contents at the top so Gemini CLI can see the full scope when previewing. + +## Skill Creation Process + +Skill creation involves these steps: + +1. Understand the skill with concrete examples +2. Plan reusable skill contents (scripts, references, assets) +3. Initialize the skill (run node init_skill.cjs) +4. Edit the skill (implement resources and write SKILL.md) +5. Package the skill (run node package_skill.cjs) +6. Install and reload the skill +7. Iterate based on real usage + +Follow these steps in order, skipping only if there is a clear reason why they are not applicable. + +### Skill Naming + +- Use lowercase letters, digits, and hyphens only; normalize user-provided titles to hyphen-case (e.g., "Plan Mode" -> `plan-mode`). +- When generating names, generate a name under 64 characters (letters, digits, hyphens). +- Prefer short, verb-led phrases that describe the action. +- Namespace by tool when it improves clarity or triggering (e.g., `gh-address-comments`, `linear-address-issue`). +- Name the skill folder exactly after the skill name. + +### Step 1: Understanding the Skill with Concrete Examples + +Skip this step only when the skill's usage patterns are already clearly understood. It remains valuable even when working with an existing skill. + +To create an effective skill, clearly understand concrete examples of how the skill will be used. This understanding can come from either direct user examples or generated examples that are validated with user feedback. + +For example, when building an image-editor skill, relevant questions include: + +- "What functionality should the image-editor skill support? Editing, rotating, anything else?" +- "Can you give some examples of how this skill would be used?" +- "I can imagine users asking for things like 'Remove the red-eye from this image' or 'Rotate this image'. Are there other ways you imagine this skill being used?" +- "What would a user say that should trigger this skill?" + +**Avoid interrogation loops:** Do not ask more than one or two clarifying questions at a time. Bias toward action: propose a concrete list of features or examples based on your initial understanding, and ask the user to refine them. + +Conclude this step when there is a clear sense of the functionality the skill should support. + +### Step 2: Planning the Reusable Skill Contents + +To turn concrete examples into an effective skill, analyze each example by: + +1. Considering how to execute on the example from scratch +2. Identifying what scripts, references, and assets would be helpful when executing these workflows repeatedly + +Example: When building a `pdf-editor` skill to handle queries like "Help me rotate this PDF," the analysis shows: + +1. Rotating a PDF requires re-writing the same code each time +2. A `scripts/rotate_pdf.cjs` script would be helpful to store in the skill + +Example: When designing a `frontend-webapp-builder` skill for queries like "Build me a todo app" or "Build me a dashboard to track my steps," the analysis shows: + +1. Writing a frontend webapp requires the same boilerplate HTML/React each time +2. An `assets/hello-world/` template containing the boilerplate HTML/React project files would be helpful to store in the skill + +Example: When building a `big-query` skill to handle queries like "How many users have logged in today?" the analysis shows: + +1. Querying BigQuery requires re-discovering the table schemas and relationships each time +2. A `references/schema.md` file documenting the table schemas would be helpful to store in the skill + +To establish the skill's contents, analyze each concrete example to create a list of the reusable resources to include: scripts, references, and assets. + +### Step 3: Initializing the Skill + +At this point, it is time to actually create the skill. + +Skip this step only if the skill being developed already exists, and iteration or packaging is needed. In this case, continue to the next step. + +When creating a new skill from scratch, always run the `init_skill.cjs` script. The script conveniently generates a new template skill directory that automatically includes everything a skill requires, making the skill creation process much more efficient and reliable. + +**Note:** Use the absolute path to the script as provided in the `available_resources` section. + +Usage: + +```bash +node /scripts/init_skill.cjs --path +``` + +The script: + +- Creates the skill directory at the specified path +- Generates a SKILL.md template with proper frontmatter and TODO placeholders +- Creates example resource directories: `scripts/`, `references/`, and `assets/` +- Adds example files (`scripts/example_script.cjs`, `references/example_reference.md`, `assets/example_asset.txt`) that can be customized or deleted + +After initialization, customize or remove the generated SKILL.md and example files as needed. + +### Step 4: Edit the Skill + +When editing the (newly-generated or existing) skill, remember that the skill is being created for another instance of Gemini CLI to use. Include information that would be beneficial and non-obvious to Gemini CLI. Consider what procedural knowledge, domain-specific details, or reusable assets would help another Gemini CLI instance execute these tasks more effectively. + +#### Learn Proven Design Patterns + +Consult these helpful guides based on your skill's needs: + +- **Multi-step processes**: See references/workflows.md for sequential workflows and conditional logic +- **Specific output formats or quality standards**: See references/output-patterns.md for template and example patterns + +These files contain established best practices for effective skill design. + +#### Start with Reusable Skill Contents + +To begin implementation, start with the reusable resources identified above: `scripts/`, `references/`, and `assets/` files. Note that this step may require user input. For example, when implementing a `brand-guidelines` skill, the user may need to provide brand assets or templates to store in `assets/`, or documentation to store in `references/`. + +Added scripts must be tested by actually running them to ensure there are no bugs and that the output matches what is expected. If there are many similar scripts, only a representative sample needs to be tested to ensure confidence that they all work while balancing time to completion. + +Any example files and directories not needed for the skill should be deleted. The initialization script creates example files in `scripts/`, `references/`, and `assets/` to demonstrate structure, but most skills won't need all of them. + +#### Update SKILL.md + +**Writing Guidelines:** Always use imperative/infinitive form. + +##### Frontmatter + +Write the YAML frontmatter with `name` and `description`: + +- `name`: The skill name +- `description`: This is the primary triggering mechanism for your skill, and helps Gemini CLI understand when to use the skill. + - Include both what the Skill does and specific triggers/contexts for when to use it. + - **Must be a single-line string** (e.g., `description: Data ingestion...`). Quotes are optional. + - Include all "when to use" information here - Not in the body. The body is only loaded after triggering, so "When to Use This Skill" sections in the body are not helpful to Gemini CLI. + - Example: `description: Data ingestion, cleaning, and transformation for tabular data. Use when Gemini CLI needs to work with CSV/TSV files to analyze large datasets, normalize schemas, or merge sources.` + +Do not include any other fields in YAML frontmatter. + +##### Body + +Write instructions for using the skill and its bundled resources. + +### Step 5: Packaging a Skill + +Once development of the skill is complete, it must be packaged into a distributable .skill file that gets shared with the user. The packaging process automatically validates the skill first (checking YAML and ensuring no TODOs remain) to ensure it meets all requirements: + +**Note:** Use the absolute path to the script as provided in the `available_resources` section. + +```bash +node /scripts/package_skill.cjs +``` + +Optional output directory specification: + +```bash +node /scripts/package_skill.cjs ./dist +``` + +The packaging script will: + +1. **Validate** the skill automatically, checking: + - YAML frontmatter format and required fields + - Skill naming conventions and directory structure + - Description completeness and quality + - File organization and resource references + +2. **Package** the skill if validation passes, creating a .skill file named after the skill (e.g., `my-skill.skill`) that includes all files and maintains the proper directory structure for distribution. The .skill file is a zip file with a .skill extension. + +If validation fails, the script will report the errors and exit without creating a package. Fix any validation errors and run the packaging command again. + +### Step 6: Installing and Reloading a Skill + +Once the skill is packaged into a `.skill` file, offer to install it for the user. Ask whether they would like to install it locally in the current folder (workspace scope) or at the user level (user scope). + +If the user agrees to an installation, perform it immediately using the `run_shell_command` tool: + +- **Locally (workspace scope)**: + ```bash + gemini skills install --scope workspace + ``` +- **User level (user scope)**: + ```bash + gemini skills install --scope user + ``` + +**Important:** After the installation is complete, notify the user that they MUST manually execute the `/skills reload` command in their interactive Gemini CLI session to enable the new skill. They can then verify the installation by running `/skills list`. + +Note: You (the agent) cannot execute the `/skills reload` command yourself; it must be done by the user in an interactive instance of Gemini CLI. Do not attempt to run it on their behalf. + +### Step 7: Iterate + +After testing the skill, users may request improvements. Often this happens right after using the skill, with fresh context of how the skill performed. + +**Iteration workflow:** + +1. Use the skill on real tasks +2. Notice struggles or inefficiencies +3. Identify how SKILL.md or bundled resources should be updated +4. Implement changes and test again diff --git a/packages/core/src/skills/builtin/skill-creator/scripts/init_skill.cjs b/packages/core/src/skills/builtin/skill-creator/scripts/init_skill.cjs new file mode 100644 index 0000000000..d23853f255 --- /dev/null +++ b/packages/core/src/skills/builtin/skill-creator/scripts/init_skill.cjs @@ -0,0 +1,235 @@ +#!/usr/bin/env node + +/* eslint-env node */ + +/** + * Skill Initializer - Creates a new skill from template + * + * Usage: + * node init_skill.cjs --path + * + * Examples: + * node init_skill.cjs my-new-skill --path skills/public + */ + +const fs = require('node:fs'); +const path = require('node:path'); + +const SKILL_TEMPLATE = `--- +name: {skill_name} +description: TODO: Complete and informative explanation of what the skill does and when to use it. Include WHEN to use this skill - specific scenarios, file types, or tasks that trigger it. +--- + +# {skill_title} + +## Overview + +[TODO: 1-2 sentences explaining what this skill enables] + +## Structuring This Skill + +[TODO: Choose the structure that best fits this skill's purpose. Common patterns: + +**1. Workflow-Based** (best for sequential processes) +- Works well when there are clear step-by-step procedures +- Example: CSV-Processor skill with "Workflow Decision Tree" → "Ingestion" → "Cleaning" → "Analysis" +- Structure: ## Overview → ## Workflow Decision Tree → ## Step 1 → ## Step 2... + +**2. Task-Based** (best for tool collections) +- Works well when the skill offers different operations/capabilities +- Example: PDF skill with "Quick Start" → "Merge PDFs" → "Split PDFs" → "Extract Text" +- Structure: ## Overview → ## Quick Start → ## Task Category 1 → ## Task Category 2... + +**3. Reference/Guidelines** (best for standards or specifications) +- Works well for brand guidelines, coding standards, or requirements +- Example: Brand styling with "Brand Guidelines" → "Colors" → "Typography" → "Features" +- Structure: ## Overview → ## Guidelines → ## Specifications → ## Usage... + +**4. Capabilities-Based** (best for integrated systems) +- Works well when the skill provides multiple interrelated features +- Example: Product Management with "Core Capabilities" → numbered capability list +- Structure: ## Overview → ## Core Capabilities → ### 1. Feature → ### 2. Feature... + +Patterns can be mixed and matched as needed. Most skills combine patterns (e.g., start with task-based, add workflow for complex operations). + +Delete this entire "Structuring This Skill" section when done - it's just guidance.] + +## [TODO: Replace with the first main section based on chosen structure] + +[TODO: Add content here. See examples in existing skills: +- Code samples for technical skills +- Decision trees for complex workflows +- Concrete examples with realistic user requests +- References to scripts/templates/references as needed] + +## Resources + +This skill includes example resource directories that demonstrate how to organize different types of bundled resources: + +### scripts/ +Executable code that can be run directly to perform specific operations. + +**Examples from other skills:** +- PDF skill: fill_fillable_fields.cjs, extract_form_field_info.cjs - utilities for PDF manipulation +- CSV skill: normalize_schema.cjs, merge_datasets.cjs - utilities for tabular data manipulation + +**Appropriate for:** Node.cjs scripts (cjs), shell scripts, or any executable code that performs automation, data processing, or specific operations. + +**Note:** Scripts may be executed without loading into context, but can still be read by Gemini CLI for patching or environment adjustments. + +### references/ +Documentation and reference material intended to be loaded into context to inform Gemini CLI's process and thinking. + +**Examples from other skills:** +- Product management: communication.md, context_building.md - detailed workflow guides +- BigQuery: API reference documentation and query examples +- Finance: Schema documentation, company policies + +**Appropriate for:** In-depth documentation, API references, database schemas, comprehensive guides, or any detailed information that Gemini CLI should reference while working. + +### assets/ +Files not intended to be loaded into context, but rather used within the output Gemini CLI produces. + +**Examples from other skills:** +- Brand styling: PowerPoint template files (.pptx), logo files +- Frontend builder: HTML/React boilerplate project directories +- Typography: Font files (.ttf, .woff2) + +**Appropriate for:** Templates, boilerplate code, document templates, images, icons, fonts, or any files meant to be copied or used in the final output. + +--- + +**Any unneeded directories can be deleted.** Not every skill requires all three types of resources. +`; + +const EXAMPLE_SCRIPT = `#!/usr/bin/env node + +/** + * Example helper script for {skill_name} + * + * This is a placeholder script that can be executed directly. + * Replace with actual implementation or delete if not needed. + * + * Example real scripts from other skills: + * - pdf/scripts/fill_fillable_fields.cjs - Fills PDF form fields + * - pdf/scripts/convert_pdf_to_images.cjs - Converts PDF pages to images + * + * Agentic Ergonomics: + * - Suppress tracebacks. + * - Return clean success/failure strings. + * - Truncate long outputs. + */ + +async function main() { + try { + // TODO: Add actual script logic here. + // This could be data processing, file conversion, API calls, etc. + + // Example output formatting for an LLM agent + process.stdout.write("Success: Processed the task.\\n"); + } catch (err) { + // Trap the error and output a clean message instead of a noisy stack trace + process.stderr.write(\`Failure: \${err.message}\\n\`); + process.exit(1); + } +} + +main(); +`; + +const EXAMPLE_REFERENCE = `# Reference Documentation for {skill_title} + +This is a placeholder for detailed reference documentation. +Replace with actual reference content or delete if not needed. + +## Structure Suggestions + +### API Reference Example +- Overview +- Authentication +- Endpoints with examples +- Error codes + +### Workflow Guide Example +- Prerequisites +- Step-by-step instructions +- Best practices +`; + +function titleCase(name) { + return name + .split('-') + .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) + .join(' '); +} + +async function main() { + const args = process.argv.slice(2); + if (args.length < 3 || args[1] !== '--path') { + console.log('Usage: node init_skill.cjs --path '); + process.exit(1); + } + + const skillName = args[0]; + const basePath = path.resolve(args[2]); + + // Prevent path traversal + if ( + skillName.includes(path.sep) || + skillName.includes('/') || + skillName.includes('\\') + ) { + console.error('❌ Error: Skill name cannot contain path separators.'); + process.exit(1); + } + + const skillDir = path.join(basePath, skillName); + + // Additional check to ensure the resolved skillDir is actually inside basePath + if (!skillDir.startsWith(basePath)) { + console.error('❌ Error: Invalid skill name or path.'); + process.exit(1); + } + + if (fs.existsSync(skillDir)) { + console.error(`❌ Error: Skill directory already exists: ${skillDir}`); + process.exit(1); + } + + const skillTitle = titleCase(skillName); + + try { + fs.mkdirSync(skillDir, { recursive: true }); + fs.mkdirSync(path.join(skillDir, 'scripts')); + fs.mkdirSync(path.join(skillDir, 'references')); + fs.mkdirSync(path.join(skillDir, 'assets')); + + fs.writeFileSync( + path.join(skillDir, 'SKILL.md'), + SKILL_TEMPLATE.replace(/{skill_name}/g, skillName).replace( + /{skill_title}/g, + skillTitle, + ), + ); + fs.writeFileSync( + path.join(skillDir, 'scripts/example_script.cjs'), + EXAMPLE_SCRIPT.replace(/{skill_name}/g, skillName), + { mode: 0o755 }, + ); + fs.writeFileSync( + path.join(skillDir, 'references/example_reference.md'), + EXAMPLE_REFERENCE.replace(/{skill_title}/g, skillTitle), + ); + fs.writeFileSync( + path.join(skillDir, 'assets/example_asset.txt'), + 'Placeholder for assets.', + ); + + console.log(`✅ Skill '${skillName}' initialized at ${skillDir}`); + } catch (err) { + console.error(`❌ Error: ${err.message}`); + process.exit(1); + } +} + +main(); diff --git a/packages/core/src/skills/builtin/skill-creator/scripts/package_skill.cjs b/packages/core/src/skills/builtin/skill-creator/scripts/package_skill.cjs new file mode 100644 index 0000000000..c01edff4f7 --- /dev/null +++ b/packages/core/src/skills/builtin/skill-creator/scripts/package_skill.cjs @@ -0,0 +1,87 @@ +#!/usr/bin/env node + +/* eslint-env node */ + +/** + * Skill Packager - Creates a distributable .skill file of a skill folder + * + * Usage: + * node package_skill.js [output-directory] + */ + +const path = require('node:path'); +const { spawnSync } = require('node:child_process'); +const { validateSkill } = require('./validate_skill.cjs'); + +async function main() { + const args = process.argv.slice(2); + if (args.length < 1) { + console.log( + 'Usage: node package_skill.js [output-directory]', + ); + process.exit(1); + } + + const skillPathArg = args[0]; + const outputDirArg = args[1]; + + if ( + skillPathArg.includes('..') || + (outputDirArg && outputDirArg.includes('..')) + ) { + console.error('❌ Error: Path traversal detected in arguments.'); + process.exit(1); + } + + const skillPath = path.resolve(skillPathArg); + const outputDir = outputDirArg ? path.resolve(outputDirArg) : process.cwd(); + const skillName = path.basename(skillPath); + + // 1. Validate first + console.log('🔍 Validating skill...'); + const result = validateSkill(skillPath); + if (!result.valid) { + console.error(`❌ Validation failed: ${result.message}`); + process.exit(1); + } + + if (result.warning) { + console.warn(`⚠️ ${result.warning}`); + console.log('Please resolve all TODOs before packaging.'); + process.exit(1); + } + console.log('✅ Skill is valid!'); + + // 2. Package + const outputFilename = path.join(outputDir, `${skillName}.skill`); + + try { + // Zip everything except junk, keeping the folder structure + // We'll use the native 'zip' command for simplicity in a CLI environment + // or we could use a JS library, but zip is ubiquitous on darwin/linux. + + // Command to zip: + // -r: recursive + // -x: exclude patterns + // Run the zip command from within the directory to avoid parent folder nesting + const zipProcess = spawnSync('zip', ['-r', outputFilename, '.'], { + cwd: skillPath, + stdio: 'inherit', + }); + + if (zipProcess.error) { + throw zipProcess.error; + } + + if (zipProcess.status !== 0) { + throw new Error(`zip command failed with exit code ${zipProcess.status}`); + } + + console.log(`✅ Successfully packaged skill to: ${outputFilename}`); + } catch (err) { + console.error(`❌ Error packaging: ${err.message}`); + process.exit(1); + } +} + +main(); diff --git a/packages/core/src/skills/builtin/skill-creator/scripts/validate_skill.cjs b/packages/core/src/skills/builtin/skill-creator/scripts/validate_skill.cjs new file mode 100644 index 0000000000..d51fec96ba --- /dev/null +++ b/packages/core/src/skills/builtin/skill-creator/scripts/validate_skill.cjs @@ -0,0 +1,127 @@ +/* eslint-env node */ + +/** + * Quick validation logic for skills. + * Leveraging existing dependencies when possible or providing a zero-dep fallback. + */ + +const fs = require('node:fs'); +const path = require('node:path'); + +function validateSkill(skillPath) { + if (!fs.existsSync(skillPath) || !fs.statSync(skillPath).isDirectory()) { + return { valid: false, message: `Path is not a directory: ${skillPath}` }; + } + + const skillMdPath = path.join(skillPath, 'SKILL.md'); + if (!fs.existsSync(skillMdPath)) { + return { valid: false, message: 'SKILL.md not found' }; + } + + const content = fs.readFileSync(skillMdPath, 'utf8'); + if (!content.startsWith('---')) { + return { valid: false, message: 'No YAML frontmatter found' }; + } + + const parts = content.split('---'); + if (parts.length < 3) { + return { valid: false, message: 'Invalid frontmatter format' }; + } + + const frontmatterText = parts[1]; + + const nameMatch = frontmatterText.match(/^name:\s*(.+)$/m); + // Match description: "text" or description: 'text' or description: text + const descMatch = frontmatterText.match( + /^description:\s*(?:'([^']*)'|"([^"]*)"|(.+))$/m, + ); + + if (!nameMatch) + return { valid: false, message: 'Missing "name" in frontmatter' }; + if (!descMatch) + return { + valid: false, + message: 'Description must be a single-line string: description: ...', + }; + + const name = nameMatch[1].trim(); + const description = ( + descMatch[1] !== undefined + ? descMatch[1] + : descMatch[2] !== undefined + ? descMatch[2] + : descMatch[3] || '' + ).trim(); + + if (description.includes('\n')) { + return { + valid: false, + message: 'Description must be a single line (no newlines)', + }; + } + + if (!/^[a-z0-9-]+$/.test(name)) { + return { valid: false, message: `Name "${name}" should be hyphen-case` }; + } + + if (description.length > 1024) { + return { valid: false, message: 'Description is too long (max 1024)' }; + } + + // Check for TODOs + const files = getAllFiles(skillPath); + for (const file of files) { + const fileContent = fs.readFileSync(file, 'utf8'); + if (fileContent.includes('TODO:')) { + return { + valid: true, + message: 'Skill has unresolved TODOs', + warning: `Found unresolved TODO in ${path.relative(skillPath, file)}`, + }; + } + } + + return { valid: true, message: 'Skill is valid!' }; +} + +function getAllFiles(dir, fileList = []) { + const files = fs.readdirSync(dir); + files.forEach((file) => { + const name = path.join(dir, file); + if (fs.statSync(name).isDirectory()) { + if (!['node_modules', '.git', '__pycache__'].includes(file)) { + getAllFiles(name, fileList); + } + } else { + fileList.push(name); + } + }); + return fileList; +} + +if (require.main === module) { + const args = process.argv.slice(2); + if (args.length !== 1) { + console.log('Usage: node validate_skill.js '); + process.exit(1); + } + + const skillDirArg = args[0]; + if (skillDirArg.includes('..')) { + console.error('❌ Error: Path traversal detected in skill directory path.'); + process.exit(1); + } + + const result = validateSkill(path.resolve(skillDirArg)); + if (result.warning) { + console.warn(`⚠️ ${result.warning}`); + } + if (result.valid) { + console.log(`✅ ${result.message}`); + } else { + console.error(`❌ ${result.message}`); + process.exit(1); + } +} + +module.exports = { validateSkill }; From b3eecc3a50099fa8adcbed98a3bb7901c9cd8b10 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Wed, 14 Jan 2026 16:04:55 -0500 Subject: [PATCH 187/713] chore(automation): remove automated PR size and complexity labeler (#16648) --- .../gemini-automated-pr-size-labeler.yml | 127 ------------------ 1 file changed, 127 deletions(-) delete mode 100644 .github/workflows/gemini-automated-pr-size-labeler.yml diff --git a/.github/workflows/gemini-automated-pr-size-labeler.yml b/.github/workflows/gemini-automated-pr-size-labeler.yml deleted file mode 100644 index 1438d6429b..0000000000 --- a/.github/workflows/gemini-automated-pr-size-labeler.yml +++ /dev/null @@ -1,127 +0,0 @@ -name: 'Gemini Automated PR Labeler' - -on: - pull_request_target: - types: ['opened', 'reopened', 'synchronize'] - -jobs: - label-pr: - timeout-minutes: 10 - if: |- - ${{ github.repository == 'google-gemini/gemini-cli' }} - permissions: - pull-requests: 'write' - contents: 'read' - id-token: 'write' - - concurrency: - group: '${{ github.workflow }}-${{ github.event.pull_request.number }}' - cancel-in-progress: true - - runs-on: 'ubuntu-latest' - - steps: - - name: 'Generate GitHub App Token' - id: 'generate_token' - uses: 'actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e' # v2 - with: - app-id: '${{ secrets.APP_ID }}' - private-key: '${{ secrets.PRIVATE_KEY }}' - permission-pull-requests: 'write' - - - name: 'Run Gemini PR size and complexity labeller' - uses: 'google-github-actions/run-gemini-cli@a3bf79042542528e91937b3a3a6fbc4967ee3c31' # Use the specific commit SHA - env: - GH_TOKEN: '${{ steps.generate_token.outputs.token }}' - PR_NUMBER: '${{ github.event.pull_request.number }}' - REPOSITORY: '${{ github.repository }}' - with: - gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}' - gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}' - gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}' - gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}' - gemini_api_key: '${{ secrets.GEMINI_API_KEY }}' - use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}' - use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}' - settings: | - { - "coreTools": [ - "run_shell_command(gh pr diff)", - "run_shell_command(gh pr edit)", - "run_shell_command(gh pr comment)", - "run_shell_command(gh pr view)" - ], - "telemetry": { - "enabled": true, - "target": "gcp" - }, - "sandbox": false - } - prompt: | - You are a Pull Request labeller and Feedback Assistant. Your primary goal is to improve review velocity and help maintainers prioritize their work by automatically labeling pull requests based on size and complexity, and providing guidance for overly large PRs. - - Steps: - 1. Retrieve Pull Request Information: - - Use `gh pr diff ${{ env.PR_NUMBER }} --repo ${{ env.REPOSITORY }}` to get the diff content. - - Parse the output from `gh pr diff` to determine the total lines of code added and deleted. Calculate `TOTAL_LINES_CHANGED`. - - 2. Determine Pull Request Size: - - Use `gh pr view ${{ env.PR_NUMBER }} --repo ${{ env.REPOSITORY }} --json labels` to get the current labels on the PR. - - Check the current labels and identify if any `size/*` labels already exist (e.g., `size/xs`, `size/s`, etc.). - - If an old `size/*` label is found and it is different from the newly calculated size, remove it using: - `gh pr edit ${{ env.PR_NUMBER }} --repo ${{ env.REPOSITORY }} --remove-label "size-label-to-remove"` - - Based on `TOTAL_LINES_CHANGED`, select the appropriate new size label: - - `size/xs`: < 10 lines changed - - `size/s`: 10-50 lines changed - - `size/m`: 51-200 lines changed - - `size/l`: 201-1000 lines changed - - `size/xl`: > 1000 lines changed - - Do not invent new size labels. - - Apply the newly determined `size/*` label to the pull request using: - `gh pr edit ${{ env.PR_NUMBER }} --repo ${{ env.REPOSITORY }} --add-label "your-new-size-label"` - - 3. Analyze Pull Request Complexity: - - Perform Code Change Analysis: Examine the content of the code changes obtained from `gh pr diff ${{ env.PR_NUMBER }} --repo ${{ env.REPOSITORY }}`. Look for indicators of complexity such as: - - Number of files changed (can be inferred from the diff headers). - - Diversity of file types (e.g., changes across different languages, configuration files, documentation). - - Presence of new external dependencies. - - Introduction of new architectural components or significant refactoring. - - Complexity of individual code changes (e.g., deeply nested logic, complex algorithms, extensive conditional statements). - - Apply Heuristic-based Complexity Assessment: - - If the PR touches a small number of files with minor changes (e.g., typos, simple bug fixes, small feature additions), categorize it as `review/quick`. - - If the PR involves changes across multiple files, introduces new features, significantly refactors existing code, or has a high line count (even within `size/l`), categorize it as `review/involved`. - - Pay close attention to changes in critical or core modules as these inherently increase complexity. - - **Only use the labels `review/quick` or `review/involved` for complexity. Do not invent new complexity labels.** - - **Remove any previous `review/*` labels if they no longer apply, similar to the size label process.** - - Apply the determined `review/*` label to the pull request using: - `gh pr edit ${{ env.PR_NUMBER }} --repo ${{ env.REPOSITORY }} --add-label "your-complexity-label"` - - 4. Handle Overly Large Pull Requests (`size/xl`): - - **Conditional Check:** If the pull request has been labeled `size/xl` (i.e., > 1000 lines of code changed) in Step 2, proceed to the next sub-step. - - **Post Constructive Comment:** Post a polite and helpful comment on the pull request using: - `gh pr comment ${{ env.PR_NUMBER }} --repo ${{ env.REPOSITORY }} --body "Your comment here"` - The comment body should be: - """ - Thanks for your hard work on this pull request! - - This pull request is quite large, which can make it challenging and time-consuming for reviewers to go through thoroughly. - - To help us review it more efficiently and get your changes merged faster, we kindly request you consider breaking this into smaller, more focused pull requests. Each smaller PR should ideally address a single logical change or a small set of related changes. - - For example, you could separate out refactoring, new feature additions, and bug fixes into individual PRs. This makes it easier to understand, review, and test each component independently. - - We appreciate your understanding and cooperation. Feel free to reach out if you need any assistance with this! - """ - - Guidelines: - - Automation Focus: All actions should be automated and not require manual intervention. - - Non-intrusive: The system should add labels and comments but not modify the code or close the pull request. - - Polite and Constructive: All communication, especially for large PRs, must be polite, encouraging, and constructive. - - Prioritize Clarity: The labels applied should clearly convey the PR's size and complexity to reviewers. - - Adhere to Defined Labels: Only use the specified `size/*` and `review/*` labels. Do not create or apply any other labels. - - Utilize `gh CLI`: Interact with GitHub using the `gh` command-line tool for diffing, label management, and commenting. - - Execute commands strictly as described in the steps. Do not invent new commands. - - In no case should you change other pull request that are not the one you are working on. Which can be found by using env.PR_NUMBER - - Execute each step that is defined in the steps section. - - In no case should you execute code from the pull request because this could be malicious code. - - If you fail to do this step log the errors you received From c8c7b57a79f7286ca93e02d734cd614c2b6283fb Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 14 Jan 2026 13:05:26 -0800 Subject: [PATCH 188/713] refactor(skills): replace 'project' with 'workspace' scope (#16380) --- docs/cli/skills.md | 16 +++++------ .../cli/src/commands/skills/disable.test.ts | 28 +++++++++++++++++++ packages/cli/src/commands/skills/disable.ts | 10 ++++--- .../cli/src/commands/skills/enable.test.ts | 6 ++-- .../cli/src/ui/commands/skillsCommand.test.ts | 6 ++-- packages/cli/src/utils/skillUtils.ts | 2 +- packages/core/src/skills/skillManager.test.ts | 8 +++--- packages/core/src/skills/skillManager.ts | 6 ++-- 8 files changed, 56 insertions(+), 26 deletions(-) diff --git a/docs/cli/skills.md b/docs/cli/skills.md index 5aebf00cb5..448734a14d 100644 --- a/docs/cli/skills.md +++ b/docs/cli/skills.md @@ -13,7 +13,7 @@ discoverable capability. ## Overview Unlike general context files ([`GEMINI.md`](./gemini-md.md)), which provide -persistent project-wide background, Skills represent **on-demand expertise**. +persistent workspace-wide background, Skills represent **on-demand expertise**. This allows Gemini to maintain a vast library of specialized capabilities—such as security auditing, cloud deployments, or codebase migrations—without cluttering the model's immediate context window. @@ -39,15 +39,15 @@ the full instructions and resources required to complete the task using the Gemini CLI discovers skills from three primary locations: -1. **Project Skills** (`.gemini/skills/`): Project-specific skills that are +1. **Workspace Skills** (`.gemini/skills/`): Workspace-specific skills that are typically committed to version control and shared with the team. 2. **User Skills** (`~/.gemini/skills/`): Personal skills available across all - your projects. + your workspaces. 3. **Extension Skills**: Skills bundled within installed [extensions](../extensions/index.md). **Precedence:** If multiple skills share the same name, higher-precedence -locations override lower ones: **Project > User > Extension**. +locations override lower ones: **Workspace > User > Extension**. ## Managing Skills @@ -61,7 +61,7 @@ Use the `/skills` slash command to view and manage available expertise: - `/skills reload`: Refreshes the list of discovered skills from all tiers. _Note: `/skills disable` and `/skills enable` default to the `user` scope. Use -`--scope project` to manage project-specific settings._ +`--scope workspace` to manage workspace-specific settings._ ### From the Terminal @@ -89,8 +89,8 @@ gemini skills uninstall my-expertise --scope workspace # Enable a skill (globally) gemini skills enable my-expertise -# Disable a skill. Can use --scope to specify project or user (defaults to project) -gemini skills disable my-expertise --scope project +# Disable a skill. Can use --scope to specify workspace or user (defaults to workspace) +gemini skills disable my-expertise --scope workspace ``` ## Creating a Skill @@ -147,7 +147,7 @@ You are an expert code reviewer. When reviewing code, follow this workflow: 1. **Analyze**: Review the staged changes or specific files provided. Ensure that the changes are scoped properly and represent minimal changes required to address the issue. -2. **Style**: Ensure code follows the project's conventions and idiomatic +2. **Style**: Ensure code follows the workspace's conventions and idiomatic patterns as described in the `GEMINI.md` file. 3. **Security**: Flag any potential security vulnerabilities. 4. **Tests**: Verify that new logic has corresponding test coverage and that diff --git a/packages/cli/src/commands/skills/disable.test.ts b/packages/cli/src/commands/skills/disable.test.ts index f4ae0d954e..4a5097471b 100644 --- a/packages/cli/src/commands/skills/disable.test.ts +++ b/packages/cli/src/commands/skills/disable.test.ts @@ -84,6 +84,34 @@ describe('skills disable command', () => { ); }); + it('should disable an enabled skill in workspace scope', async () => { + const mockSettings = { + forScope: vi.fn().mockReturnValue({ + settings: { skills: { disabled: [] } }, + path: '/workspace/.gemini/settings.json', + }), + setValue: vi.fn(), + }; + mockLoadSettings.mockReturnValue( + mockSettings as unknown as LoadedSettings, + ); + + await handleDisable({ + name: 'skill1', + scope: SettingScope.Workspace as LoadableSettingScope, + }); + + expect(mockSettings.setValue).toHaveBeenCalledWith( + SettingScope.Workspace, + 'skills.disabled', + ['skill1'], + ); + expect(emitConsoleLog).toHaveBeenCalledWith( + 'log', + 'Skill "skill1" disabled by adding it to the disabled list in workspace (/workspace/.gemini/settings.json) settings.', + ); + }); + it('should log a message if the skill is already disabled', async () => { const mockSettings = { forScope: vi.fn().mockReturnValue({ diff --git a/packages/cli/src/commands/skills/disable.ts b/packages/cli/src/commands/skills/disable.ts index fcb69c087d..95fd607924 100644 --- a/packages/cli/src/commands/skills/disable.ts +++ b/packages/cli/src/commands/skills/disable.ts @@ -42,14 +42,16 @@ export const disableCommand: CommandModule = { }) .option('scope', { alias: 's', - describe: 'The scope to disable the skill in (user or project).', + describe: 'The scope to disable the skill in (user or workspace).', type: 'string', - default: 'project', - choices: ['user', 'project'], + default: 'workspace', + choices: ['user', 'workspace'], }), handler: async (argv) => { const scope = - argv['scope'] === 'project' ? SettingScope.Workspace : SettingScope.User; + argv['scope'] === 'workspace' + ? SettingScope.Workspace + : SettingScope.User; await handleDisable({ name: argv['name'] as string, scope, diff --git a/packages/cli/src/commands/skills/enable.test.ts b/packages/cli/src/commands/skills/enable.test.ts index 5874072130..e204da2f66 100644 --- a/packages/cli/src/commands/skills/enable.test.ts +++ b/packages/cli/src/commands/skills/enable.test.ts @@ -64,7 +64,7 @@ describe('skills enable command', () => { path: '/user/settings.json', }; } - return { settings: {}, path: '/project/settings.json' }; + return { settings: {}, path: '/workspace/settings.json' }; }), setValue: vi.fn(), }; @@ -81,7 +81,7 @@ describe('skills enable command', () => { ); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" enabled by removing it from the disabled list in user (/user/settings.json) and project (/project/settings.json) settings.', + 'Skill "skill1" enabled by removing it from the disabled list in user (/user/settings.json) and workspace (/workspace/settings.json) settings.', ); }); @@ -122,7 +122,7 @@ describe('skills enable command', () => { ); expect(emitConsoleLog).toHaveBeenCalledWith( 'log', - 'Skill "skill1" enabled by removing it from the disabled list in project (/workspace/settings.json) and user (/user/settings.json) settings.', + 'Skill "skill1" enabled by removing it from the disabled list in workspace (/workspace/settings.json) and user (/user/settings.json) settings.', ); }); diff --git a/packages/cli/src/ui/commands/skillsCommand.test.ts b/packages/cli/src/ui/commands/skillsCommand.test.ts index d6e0bb30b7..8d55d343e6 100644 --- a/packages/cli/src/ui/commands/skillsCommand.test.ts +++ b/packages/cli/src/ui/commands/skillsCommand.test.ts @@ -225,7 +225,7 @@ describe('skillsCommand', () => { expect(context.ui.addItem).toHaveBeenCalledWith( expect.objectContaining({ type: MessageType.INFO, - text: 'Skill "skill1" disabled by adding it to the disabled list in project (/workspace) settings. Use "/skills reload" for it to take effect.', + text: 'Skill "skill1" disabled by adding it to the disabled list in workspace (/workspace) settings. Use "/skills reload" for it to take effect.', }), ); }); @@ -253,7 +253,7 @@ describe('skillsCommand', () => { expect(context.ui.addItem).toHaveBeenCalledWith( expect.objectContaining({ type: MessageType.INFO, - text: 'Skill "skill1" enabled by removing it from the disabled list in project (/workspace) and user (/user/settings.json) settings. Use "/skills reload" for it to take effect.', + text: 'Skill "skill1" enabled by removing it from the disabled list in workspace (/workspace) and user (/user/settings.json) settings. Use "/skills reload" for it to take effect.', }), ); }); @@ -292,7 +292,7 @@ describe('skillsCommand', () => { expect(context.ui.addItem).toHaveBeenCalledWith( expect.objectContaining({ type: MessageType.INFO, - text: 'Skill "skill1" enabled by removing it from the disabled list in project (/workspace) and user (/user/settings.json) settings. Use "/skills reload" for it to take effect.', + text: 'Skill "skill1" enabled by removing it from the disabled list in workspace (/workspace) and user (/user/settings.json) settings. Use "/skills reload" for it to take effect.', }), ); }); diff --git a/packages/cli/src/utils/skillUtils.ts b/packages/cli/src/utils/skillUtils.ts index 7acad4baf7..75acbae87d 100644 --- a/packages/cli/src/utils/skillUtils.ts +++ b/packages/cli/src/utils/skillUtils.ts @@ -47,7 +47,7 @@ export function renderSkillActionFeedback( const formatScopeItem = (s: { scope: SettingScope; path: string }) => { const label = - s.scope === SettingScope.Workspace ? 'project' : s.scope.toLowerCase(); + s.scope === SettingScope.Workspace ? 'workspace' : s.scope.toLowerCase(); return formatScope(label, s.path); }; diff --git a/packages/core/src/skills/skillManager.test.ts b/packages/core/src/skills/skillManager.test.ts index 5635ddf4c3..20cba08405 100644 --- a/packages/core/src/skills/skillManager.test.ts +++ b/packages/core/src/skills/skillManager.test.ts @@ -35,9 +35,9 @@ describe('SkillManager', () => { vi.restoreAllMocks(); }); - it('should discover skills from extensions, user, and project with precedence', async () => { + it('should discover skills from extensions, user, and workspace with precedence', async () => { const userDir = path.join(testRootDir, 'user'); - const projectDir = path.join(testRootDir, 'project'); + const projectDir = path.join(testRootDir, 'workspace'); await fs.mkdir(path.join(userDir, 'skill-a'), { recursive: true }); await fs.mkdir(path.join(projectDir, 'skill-b'), { recursive: true }); @@ -92,9 +92,9 @@ description: project-desc expect(names).toContain('skill-project'); }); - it('should respect precedence: Project > User > Extension', async () => { + it('should respect precedence: Workspace > User > Extension', async () => { const userDir = path.join(testRootDir, 'user'); - const projectDir = path.join(testRootDir, 'project'); + const projectDir = path.join(testRootDir, 'workspace'); await fs.mkdir(path.join(userDir, 'skill'), { recursive: true }); await fs.mkdir(path.join(projectDir, 'skill'), { recursive: true }); diff --git a/packages/core/src/skills/skillManager.ts b/packages/core/src/skills/skillManager.ts index f14a9de78d..b2ec9e660e 100644 --- a/packages/core/src/skills/skillManager.ts +++ b/packages/core/src/skills/skillManager.ts @@ -39,8 +39,8 @@ export class SkillManager { } /** - * Discovers skills from standard user and project locations, as well as extensions. - * Precedence: Extensions (lowest) -> User -> Project (highest). + * Discovers skills from standard user and workspace locations, as well as extensions. + * Precedence: Extensions (lowest) -> User -> Workspace (highest). */ async discoverSkills( storage: Storage, @@ -62,7 +62,7 @@ export class SkillManager { const userSkills = await loadSkillsFromDir(Storage.getUserSkillsDir()); this.addSkillsWithPrecedence(userSkills); - // 4. Project skills (highest precedence) + // 4. Workspace skills (highest precedence) const projectSkills = await loadSkillsFromDir( storage.getProjectSkillsDir(), ); From 41369f67eb77ab42582469a5858a41b8a090dbfd Mon Sep 17 00:00:00 2001 From: Jenna Inouye Date: Wed, 14 Jan 2026 13:27:33 -0800 Subject: [PATCH 189/713] Docs: Update release notes for 1/13/2026 (#16583) Co-authored-by: Tommaso Sciortino --- docs/changelogs/index.md | 25 +++ docs/changelogs/latest.md | 288 ++++++++++++------------ docs/changelogs/preview.md | 329 +++++++++++++++++---------- docs/changelogs/releases.md | 431 +++++++++++++++++++++++++++++++++--- 4 files changed, 792 insertions(+), 281 deletions(-) diff --git a/docs/changelogs/index.md b/docs/changelogs/index.md index b0ae3518bf..5cd0ff8f9c 100644 --- a/docs/changelogs/index.md +++ b/docs/changelogs/index.md @@ -18,6 +18,31 @@ on GitHub. | [Preview](preview.md) | Experimental features ready for early feedback. | | [Stable](latest.md) | Stable, recommended for general use. | +## Announcements: v0.23.0 - 2026-01-07 + +- 🎉 **Experimental Agent Skills Support in Preview:** Gemini CLI now supports + [Agent Skills](https://agentskills.io/home) in our preview builds. This is an + early preview where we’re looking for feedback! + - Install Preview: `npm install -g @google/gemini-cli@preview` + - Enable in `/settings` + - Docs: + [https://geminicli.com/docs/cli/skills/](https://geminicli.com/docs/cli/skills/) +- **Gemini CLI wrapped:** Run `npx gemini-wrapped` to visualize your usage + stats, top models, languages, and more! +- **Windows clipboard image support:** Windows users can now paste images + directly from their clipboard into the CLI using `Alt`+`V`. + ([pr](https://github.com/google-gemini/gemini-cli/pull/13997) by + [@sgeraldes](https://github.com/sgeraldes)) +- **Terminal background color detection:** Automatically optimizes your + terminal's background color to select compatible themes and provide + accessibility warnings. + ([pr](https://github.com/google-gemini/gemini-cli/pull/15132) by + [@jacob314](https://github.com/jacob314)) +- **Session logout:** Use the new `/logout` command to instantly clear + credentials and reset your authentication state for seamless account + switching. ([pr](https://github.com/google-gemini/gemini-cli/pull/13383) by + [@CN-Scars](https://github.com/CN-Scars)) + ## Announcements: v0.22.0 - 2025-12-22 - 🎉**Free Tier + Gemini 3:** Free tier users now all have access to Gemini 3 diff --git a/docs/changelogs/latest.md b/docs/changelogs/latest.md index 295a4f6e3e..fb26d6a911 100644 --- a/docs/changelogs/latest.md +++ b/docs/changelogs/latest.md @@ -1,6 +1,6 @@ -# Latest stable release: v0.22.0 - v0.22.5 +# Latest stable release: v0.23.0 -Released: December 30, 2025 +Released: January 6, 2026 For most users, our latest stable release is the recommended release. Install the latest stable version with: @@ -11,143 +11,155 @@ npm install -g @google/gemini-cli ## Highlights -- **Comprehensive quota visibility:** View usage statistics for all available - models in the `/stats` command, even those not yet used in your current - session. ([pic](https://imgur.com/a/cKyDtYh), - [pr](https://github.com/google-gemini/gemini-cli/pull/14764) by - [@sehoon38](https://github.com/sehoon38)) -- **Polished CLI statistics:** We’ve cleaned up the `/stats` view to prioritize - actionable quota information while providing a detailed token and - cache-efficiency breakdown in `/stats model` - ([login with Google](https://imgur.com/a/w9xKthm), - [api key](https://imgur.com/a/FjQPHOY), - [model stats](https://imgur.com/a/VfWzVgw), - [pr](https://github.com/google-gemini/gemini-cli/pull/14961) by +- **Gemini CLI wrapped:** Run `npx gemini-wrapped` to visualize your usage + stats, top models, languages, and more! +- **Windows clipboard image support:** Windows users can now paste images + directly from their clipboard into the CLI using `Alt`+`V`. + ([pr](https://github.com/google-gemini/gemini-cli/pull/13997) by + [@sgeraldes](https://github.com/sgeraldes)) +- **Terminal background color detection:** Automatically optimizes your + terminal's background color to select compatible themes and provide + accessibility warnings. + ([pr](https://github.com/google-gemini/gemini-cli/pull/15132) by [@jacob314](https://github.com/jacob314)) -- **Multi-file drag & drop:** Multi-file drag & drop is now supported and - properly translated to be prefixed with `@`. - ([pr](https://github.com/google-gemini/gemini-cli/pull/14832) by - [@jackwotherspoon](https://github.com/jackwotherspoon)) +- **Session logout:** Use the new `/logout` command to instantly clear + credentials and reset your authentication state for seamless account + switching. ([pr](https://github.com/google-gemini/gemini-cli/pull/13383) by + [@CN-Scars](https://github.com/CN-Scars)) -## What's Changed +## What's changed -- feat(ide): fallback to GEMINI_CLI_IDE_AUTH_TOKEN env var by @skeshive in - https://github.com/google-gemini/gemini-cli/pull/14843 -- feat: display quota stats for unused models in /stats by @sehoon38 in - https://github.com/google-gemini/gemini-cli/pull/14764 -- feat: ensure codebase investigator uses preview model when main agent does by - @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/14412 -- chore: add closing reason to stale bug workflow by @galz10 in - https://github.com/google-gemini/gemini-cli/pull/14861 -- Send the model and CLI version with the user agent by @gundermanc in - https://github.com/google-gemini/gemini-cli/pull/14865 -- refactor(sessions): move session summary generation to startup by - @jackwotherspoon in https://github.com/google-gemini/gemini-cli/pull/14691 -- Limit search depth in path corrector by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14869 -- Fix: Correct typo in code comment by @kuishou68 in - https://github.com/google-gemini/gemini-cli/pull/14671 -- feat(core): Plumbing for late resolution of model configs. by @joshualitt in - https://github.com/google-gemini/gemini-cli/pull/14597 -- feat: attempt more error parsing by @adamfweidman in - https://github.com/google-gemini/gemini-cli/pull/14899 -- Add missing await. by @gundermanc in - https://github.com/google-gemini/gemini-cli/pull/14910 -- feat(core): Add support for transcript_path in hooks for git-ai/Gemini - extension by @svarlamov in - https://github.com/google-gemini/gemini-cli/pull/14663 -- refactor: implement DelegateToAgentTool with discriminated union by - @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/14769 -- feat: reset availabilityService on /auth by @adamfweidman in - https://github.com/google-gemini/gemini-cli/pull/14911 -- chore/release: bump version to 0.21.0-nightly.20251211.8c83e1ea9 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14924 -- Fix: Correctly detect MCP tool errors by @kevin-ramdass in - https://github.com/google-gemini/gemini-cli/pull/14937 -- increase labeler timeout by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14922 -- tool(cli): tweak the frontend tool to be aware of more core files from the cli - by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/14962 -- feat(cli): polish cached token stats and simplify stats display when quota is - present. by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/14961 -- feat(settings-validation): add validation for settings schema by @lifefloating - in https://github.com/google-gemini/gemini-cli/pull/12929 -- fix(ide): Update IDE extension to write auth token in env var by @skeshive in - https://github.com/google-gemini/gemini-cli/pull/14999 -- Revert "chore(deps): bump express from 5.1.0 to 5.2.0" by @skeshive in - https://github.com/google-gemini/gemini-cli/pull/14998 -- feat(a2a): Introduce /init command for a2a server by @cocosheng-g in - https://github.com/google-gemini/gemini-cli/pull/13419 -- feat: support multi-file drag and drop of images by @jackwotherspoon in - https://github.com/google-gemini/gemini-cli/pull/14832 -- fix(policy): allow codebase_investigator by default in read-only policy by - @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15000 -- refactor(ide ext): Update port file name + switch to 1-based index for - characters + remove truncation text by @skeshive in - https://github.com/google-gemini/gemini-cli/pull/10501 -- fix(vscode-ide-companion): correct license generation for workspace - dependencies by @skeshive in - https://github.com/google-gemini/gemini-cli/pull/15004 -- fix: temp fix for subagent invocation until subagent delegation is merged to - stable by @abhipatel12 in - https://github.com/google-gemini/gemini-cli/pull/15007 -- test: update ide detection tests to make them more robust when run in an ide - by @kevin-ramdass in https://github.com/google-gemini/gemini-cli/pull/15008 -- Remove flex from stats display. See snapshots for diffs. by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/14983 -- Add license field into package.json by @jb-perez in - https://github.com/google-gemini/gemini-cli/pull/14473 -- feat: Persistent "Always Allow" policies with granular shell & MCP support by - @allenhutchison in https://github.com/google-gemini/gemini-cli/pull/14737 -- chore/release: bump version to 0.21.0-nightly.20251212.54de67536 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14969 -- fix(core): commandPrefix word boundary and compound command safety by - @allenhutchison in https://github.com/google-gemini/gemini-cli/pull/15006 -- chore(docs): add 'Maintainers only' label info to CONTRIBUTING.md by @jacob314 - in https://github.com/google-gemini/gemini-cli/pull/14914 -- Refresh hooks when refreshing extensions. by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/14918 -- Add clarity to error messages by @gsehgal in - https://github.com/google-gemini/gemini-cli/pull/14879 -- chore : remove a redundant tip by @JayadityaGit in - https://github.com/google-gemini/gemini-cli/pull/14947 -- chore/release: bump version to 0.21.0-nightly.20251213.977248e09 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15029 -- Disallow redundant typecasts. by @gundermanc in - https://github.com/google-gemini/gemini-cli/pull/15030 -- fix(auth): prioritize GEMINI_API_KEY env var and skip unnecessary key… by - @galz10 in https://github.com/google-gemini/gemini-cli/pull/14745 -- fix: use zod for safety check result validation by @allenhutchison in - https://github.com/google-gemini/gemini-cli/pull/15026 -- update(telemetry): add hashed_extension_name to field to extension events by - @kiranani in https://github.com/google-gemini/gemini-cli/pull/15025 -- fix: similar to policy-engine, throw error in case of requiring tool execution - confirmation for non-interactive mode by @MayV in - https://github.com/google-gemini/gemini-cli/pull/14702 -- Clean up processes in integration tests by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/15102 -- docs: update policy engine getting started and defaults by @NTaylorMullen in - https://github.com/google-gemini/gemini-cli/pull/15105 -- Fix tool output fragmentation by encapsulating content in functionResponse by - @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/13082 -- Simplify method signature. by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/15114 -- Show raw input token counts in json output. by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/15021 -- fix: Mark A2A requests as interactive by @MayV in - https://github.com/google-gemini/gemini-cli/pull/15108 -- use previewFeatures to determine which pro model to use for A2A by @sehoon38 - in https://github.com/google-gemini/gemini-cli/pull/15131 -- refactor(cli): fix settings merging so that settings using the new json format - take priority over ones using the old format by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/15116 -- fix(patch): cherry-pick a6d1245 to release/v0.22.0-preview.1-pr-15214 to patch - version v0.22.0-preview.1 and create version 0.22.0-preview.2 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15226 -- fix(patch): cherry-pick 9e6914d to release/v0.22.0-preview.2-pr-15288 to patch - version v0.22.0-preview.2 and create version 0.22.0-preview.3 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15294 +- Code assist service metrics. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15024 +- chore/release: bump version to 0.21.0-nightly.20251216.bb0c0d8ee by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15121 +- Docs by @Roaimkhan in https://github.com/google-gemini/gemini-cli/pull/15103 +- Use official ACP SDK and support HTTP/SSE based MCP servers by @SteffenDE in + https://github.com/google-gemini/gemini-cli/pull/13856 +- Remove foreground for themes other than shades of purple and holiday. by + @jacob314 in https://github.com/google-gemini/gemini-cli/pull/14606 +- chore: remove repo specific tips by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15164 +- chore: remove user query from footer in debug mode by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15169 +- Disallow unnecessary awaits. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15172 +- Add one to the padding in settings dialog to avoid flicker. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15173 +- feat(core): introduce remote agent infrastructure and rename local executor by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15110 +- feat(cli): Add `/auth logout` command to clear credentials and auth state by + @CN-Scars in https://github.com/google-gemini/gemini-cli/pull/13383 +- (fix) Automated pr labeller by @DaanVersavel in + https://github.com/google-gemini/gemini-cli/pull/14885 +- feat: launch Gemini 3 Flash in Gemini CLI ⚡️⚡️⚡️ by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15196 +- Refactor: Migrate console.error in ripGrep.ts to debugLogger by @Adib234 in + https://github.com/google-gemini/gemini-cli/pull/15201 +- chore: update a2a-js to 0.3.7 by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/15197 +- chore(core): remove redundant isModelAvailabilityServiceEnabled toggle and + clean up dead code by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/15207 +- feat(core): Late resolve `GenerateContentConfig`s and reduce mutation. by + @joshualitt in https://github.com/google-gemini/gemini-cli/pull/14920 +- Respect previewFeatures value from the remote flag if undefined by @sehoon38 + in https://github.com/google-gemini/gemini-cli/pull/15214 +- feat(ui): add Windows clipboard image support and Alt+V paste workaround by + @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15218 +- chore(core): remove legacy fallback flags and migrate loop detection by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15213 +- fix(ui): Prevent eager slash command completion hiding sibling commands by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15224 +- Docs: Update Changelog for Dec 17, 2025 by @jkcinouye in + https://github.com/google-gemini/gemini-cli/pull/15204 +- Code Assist backend telemetry for user accept/reject of suggestions by + @gundermanc in https://github.com/google-gemini/gemini-cli/pull/15206 +- fix(cli): correct initial history length handling for chat commands by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15223 +- chore/release: bump version to 0.21.0-nightly.20251218.739c02bd6 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15231 +- Change detailed model stats to use a new shared Table class to resolve + robustness issues. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15208 +- feat: add agent toml parser by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15112 +- Add core tool that adds all context from the core package. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15238 +- (docs): Add reference section to hooks documentation by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15159 +- feat(hooks): add support for friendly names and descriptions by @abhipatel12 + in https://github.com/google-gemini/gemini-cli/pull/15174 +- feat: Detect background color by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15132 +- add 3.0 to allowed sensitive keywords by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15276 +- feat: Pass additional environment variables to shell execution by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15160 +- Remove unused code by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15290 +- Handle all 429 as retryableQuotaError by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15288 +- Remove unnecessary dependencies by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15291 +- fix: prevent infinite loop in prompt completion on error by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/14548 +- fix(ui): show command suggestions even on perfect match and sort them by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15287 +- feat(hooks): reduce log verbosity and improve error reporting in UI by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15297 +- feat: simplify tool confirmation labels for better UX by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15296 +- chore/release: bump version to 0.21.0-nightly.20251219.70696e364 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15301 +- feat(core): Implement JIT context memory loading and UI sync by @SandyTao520 + in https://github.com/google-gemini/gemini-cli/pull/14469 +- feat(ui): Put "Allow for all future sessions" behind a setting off by default. + by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15322 +- fix(cli):change the placeholder of input during the shell mode by + @JayadityaGit in https://github.com/google-gemini/gemini-cli/pull/15135 +- Validate OAuth resource parameter matches MCP server URL by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15289 +- docs(cli): add System Prompt Override (GEMINI_SYSTEM_MD) by @ashmod in + https://github.com/google-gemini/gemini-cli/pull/9515 +- more robust command parsing logs by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15339 +- Introspection agent demo by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15232 +- fix(core): sanitize hook command expansion and prevent injection by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15343 +- fix(folder trust): add validation for trusted folder level by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/12215 +- fix(cli): fix right border overflow in trust dialogs by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15350 +- fix(policy): fix bug where accepting-edits continued after it was turned off + by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15351 +- fix: prevent infinite relaunch loop when --resume fails (#14941) by @Ying-xi + in https://github.com/google-gemini/gemini-cli/pull/14951 +- chore/release: bump version to 0.21.0-nightly.20251220.41a1a3eed by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15352 +- feat(telemetry): add clearcut logging for hooks by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15405 +- fix(core): Add `.geminiignore` support to SearchText tool by @xyrolle in + https://github.com/google-gemini/gemini-cli/pull/13763 +- fix(patch): cherry-pick 0843d9a to release/v0.23.0-preview.0-pr-15443 to patch + version v0.23.0-preview.0 and create version 0.23.0-preview.1 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15445 +- fix(patch): cherry-pick 9cdb267 to release/v0.23.0-preview.1-pr-15494 to patch + version v0.23.0-preview.1 and create version 0.23.0-preview.2 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15592 +- fix(patch): cherry-pick 37be162 to release/v0.23.0-preview.2-pr-15601 to patch + version v0.23.0-preview.2 and create version 0.23.0-preview.3 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15603 +- fix(patch): cherry-pick 07e597d to release/v0.23.0-preview.3-pr-15684 + [CONFLICTS] by @gemini-cli-robot in + https://github.com/google-gemini/gemini-cli/pull/15734 +- fix(patch): cherry-pick c31f053 to release/v0.23.0-preview.4-pr-16004 to patch + version v0.23.0-preview.4 and create version 0.23.0-preview.5 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/16027 +- fix(patch): cherry-pick 788bb04 to release/v0.23.0-preview.5-pr-15817 + [CONFLICTS] by @gemini-cli-robot in + https://github.com/google-gemini/gemini-cli/pull/16038 -**Full Changelog**: -https://github.com/google-gemini/gemini-cli/compare/v0.21.3...v0.22.0 +**Full changelog**: +https://github.com/google-gemini/gemini-cli/compare/v0.22.5...v0.23.0 diff --git a/docs/changelogs/preview.md b/docs/changelogs/preview.md index a3484ce03c..981dce272a 100644 --- a/docs/changelogs/preview.md +++ b/docs/changelogs/preview.md @@ -1,6 +1,6 @@ -# Preview release: Release v0.23.0-preview.0 +# Preview release: Release v0.24.0-preview.0 -Released: December 22, 2025 +Released: January 6, 2026 Our preview release includes the latest, new, and experimental features. This release may not be as stable as our [latest weekly release](latest.md). @@ -11,121 +11,214 @@ To install the preview release: npm install -g @google/gemini-cli@preview ``` -## What's Changed +## What's changed -- Code assist service metrics. by @gundermanc in - https://github.com/google-gemini/gemini-cli/pull/15024 -- chore/release: bump version to 0.21.0-nightly.20251216.bb0c0d8ee by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15121 -- Docs by @Roaimkhan in https://github.com/google-gemini/gemini-cli/pull/15103 -- Use official ACP SDK and support HTTP/SSE based MCP servers by @SteffenDE in - https://github.com/google-gemini/gemini-cli/pull/13856 -- Remove foreground for themes other than shades of purple and holiday. by - @jacob314 in https://github.com/google-gemini/gemini-cli/pull/14606 -- chore: remove repo specific tips by @jackwotherspoon in - https://github.com/google-gemini/gemini-cli/pull/15164 -- chore: remove user query from footer in debug mode by @jackwotherspoon in - https://github.com/google-gemini/gemini-cli/pull/15169 -- Disallow unnecessary awaits. by @gundermanc in - https://github.com/google-gemini/gemini-cli/pull/15172 -- Add one to the padding in settings dialog to avoid flicker. by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/15173 -- feat(core): introduce remote agent infrastructure and rename local executor by - @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15110 -- feat(cli): Add `/auth logout` command to clear credentials and auth state by - @CN-Scars in https://github.com/google-gemini/gemini-cli/pull/13383 -- (fix) Automated pr labeler by @DaanVersavel in - https://github.com/google-gemini/gemini-cli/pull/14885 -- feat: launch Gemini 3 Flash in Gemini CLI ⚡️⚡️⚡️ by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/15196 -- Refactor: Migrate console.error in ripGrep.ts to debugLogger by @Adib234 in - https://github.com/google-gemini/gemini-cli/pull/15201 -- chore: update a2a-js to 0.3.7 by @adamfweidman in - https://github.com/google-gemini/gemini-cli/pull/15197 -- chore(core): remove redundant isModelAvailabilityServiceEnabled toggle and - clean up dead code by @adamfweidman in - https://github.com/google-gemini/gemini-cli/pull/15207 -- feat(core): Late resolve `GenerateContentConfig`s and reduce mutation. by - @joshualitt in https://github.com/google-gemini/gemini-cli/pull/14920 -- Respect previewFeatures value from the remote flag if undefined by @sehoon38 - in https://github.com/google-gemini/gemini-cli/pull/15214 -- feat(ui): add Windows clipboard image support and Alt+V paste workaround by - @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15218 -- chore(core): remove legacy fallback flags and migrate loop detection by - @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15213 -- fix(ui): Prevent eager slash command completion hiding sibling commands by - @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15224 -- Docs: Update Changelog for Dec 17, 2025 by @jkcinouye in - https://github.com/google-gemini/gemini-cli/pull/15204 -- Code Assist backend telemetry for user accept/reject of suggestions by - @gundermanc in https://github.com/google-gemini/gemini-cli/pull/15206 -- fix(cli): correct initial history length handling for chat commands by - @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15223 -- chore/release: bump version to 0.21.0-nightly.20251218.739c02bd6 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15231 -- Change detailed model stats to use a new shared Table class to resolve - robustness issues. by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/15208 -- feat: add agent toml parser by @abhipatel12 in - https://github.com/google-gemini/gemini-cli/pull/15112 -- Add core tool that adds all context from the core package. by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/15238 -- (docs): Add reference section to hooks documentation by @abhipatel12 in - https://github.com/google-gemini/gemini-cli/pull/15159 -- feat(hooks): add support for friendly names and descriptions by @abhipatel12 - in https://github.com/google-gemini/gemini-cli/pull/15174 -- feat: Detect background color by @jacob314 in - https://github.com/google-gemini/gemini-cli/pull/15132 -- add 3.0 to allowed sensitive keywords by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/15276 -- feat: Pass additional environment variables to shell execution by @galz10 in - https://github.com/google-gemini/gemini-cli/pull/15160 -- Remove unused code by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/15290 -- Handle all 429 as retryableQuotaError by @sehoon38 in - https://github.com/google-gemini/gemini-cli/pull/15288 -- Remove unnecessary dependencies by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/15291 -- fix: prevent infinite loop in prompt completion on error by @galz10 in - https://github.com/google-gemini/gemini-cli/pull/14548 -- fix(ui): show command suggestions even on perfect match and sort them by - @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15287 -- feat(hooks): reduce log verbosity and improve error reporting in UI by - @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15297 -- feat: simplify tool confirmation labels for better UX by @NTaylorMullen in - https://github.com/google-gemini/gemini-cli/pull/15296 -- chore/release: bump version to 0.21.0-nightly.20251219.70696e364 by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15301 -- feat(core): Implement JIT context memory loading and UI sync by @SandyTao520 - in https://github.com/google-gemini/gemini-cli/pull/14469 -- feat(ui): Put "Allow for all future sessions" behind a setting off by default. - by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15322 -- fix(cli):change the placeholder of input during the shell mode by - @JayadityaGit in https://github.com/google-gemini/gemini-cli/pull/15135 -- Validate OAuth resource parameter matches MCP server URL by @galz10 in - https://github.com/google-gemini/gemini-cli/pull/15289 -- docs(cli): add System Prompt Override (GEMINI_SYSTEM_MD) by @ashmod in - https://github.com/google-gemini/gemini-cli/pull/9515 -- more robust command parsing logs by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/15339 -- Introspection agent demo by @scidomino in - https://github.com/google-gemini/gemini-cli/pull/15232 -- fix(core): sanitize hook command expansion and prevent injection by - @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15343 -- fix(folder trust): add validation for trusted folder level by @adamfweidman in - https://github.com/google-gemini/gemini-cli/pull/12215 -- fix(cli): fix right border overflow in trust dialogs by @galz10 in - https://github.com/google-gemini/gemini-cli/pull/15350 -- fix(policy): fix bug where accepting-edits continued after it was turned off - by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15351 -- fix: prevent infinite relaunch loop when --resume fails (#14941) by @Ying-xi - in https://github.com/google-gemini/gemini-cli/pull/14951 -- chore/release: bump version to 0.21.0-nightly.20251220.41a1a3eed by - @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15352 -- feat(telemetry): add clearcut logging for hooks by @abhipatel12 in - https://github.com/google-gemini/gemini-cli/pull/15405 -- fix(core): Add `.geminiignore` support to SearchText tool by @xyrolle in - https://github.com/google-gemini/gemini-cli/pull/13763 +- chore(core): refactor model resolution and cleanup fallback logic by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15228 +- Add Folder Trust Support To Hooks by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15325 +- Record timestamp with code assist metrics. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15439 +- feat(policy): implement dynamic mode-aware policy evaluation by @abhipatel12 + in https://github.com/google-gemini/gemini-cli/pull/15307 +- fix(core): use debugLogger.debug for startup profiler logs by @NTaylorMullen + in https://github.com/google-gemini/gemini-cli/pull/15443 +- feat(ui): Add security warning and improve layout for Hooks list by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15440 +- fix #15369, prevent crash on unhandled EIO error in readStdin cleanup by + @ElecTwix in https://github.com/google-gemini/gemini-cli/pull/15410 +- chore: improve error messages for --resume by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15360 +- chore: remove clipboard file by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15447 +- Implemented unified secrets sanitization and env. redaction options by + @gundermanc in https://github.com/google-gemini/gemini-cli/pull/15348 +- feat: automatic `/model` persistence across Gemini CLI sessions by @niyasrad + in https://github.com/google-gemini/gemini-cli/pull/13199 +- refactor(core): remove deprecated permission aliases from BeforeToolHookOutput + by @StoyanD in https://github.com/google-gemini/gemini-cli/pull/14855 +- fix: add missing `type` field to MCPServerConfig by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15465 +- Make schema validation errors non-fatal by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15487 +- chore: limit MCP resources display to 10 by default by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15489 +- Add experimental in-CLI extension install and uninstall subcommands by + @chrstnb in https://github.com/google-gemini/gemini-cli/pull/15178 +- feat: Add A2A Client Manager and tests by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/15485 +- feat: terse transformations of image paths in text buffer by @psinha40898 in + https://github.com/google-gemini/gemini-cli/pull/4924 +- Security: Project-level hook warnings by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15470 +- Added modifyOtherKeys protocol support for tmux by @ved015 in + https://github.com/google-gemini/gemini-cli/pull/15524 +- chore(core): fix comment typo by @Mapleeeeeeeeeee in + https://github.com/google-gemini/gemini-cli/pull/15558 +- feat: Show snowfall animation for holiday theme by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15494 +- do not persist the fallback model by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15483 +- Resolve unhandled promise rejection in ide-client.ts by @Adib234 in + https://github.com/google-gemini/gemini-cli/pull/15587 +- fix(core): handle checkIsRepo failure in GitService.initialize by + @Mapleeeeeeeeeee in https://github.com/google-gemini/gemini-cli/pull/15574 +- fix(cli): add enableShellOutputEfficiency to settings schema by + @Mapleeeeeeeeeee in https://github.com/google-gemini/gemini-cli/pull/15560 +- Manual nightly version bump to 0.24.0-nightly.20251226.546baf993 by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15594 +- refactor(core): extract static concerns from CoreToolScheduler by @abhipatel12 + in https://github.com/google-gemini/gemini-cli/pull/15589 +- fix(core): enable granular shell command allowlisting in policy engine by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15601 +- chore/release: bump version to 0.24.0-nightly.20251227.37be16243 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15612 +- refactor: deprecate legacy confirmation settings and enforce Policy Engine by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15626 +- Migrate console to coreEvents.emitFeedback or debugLogger by @Adib234 in + https://github.com/google-gemini/gemini-cli/pull/15219 +- Exponential back-off retries for retryable error without a specified … by + @sehoon38 in https://github.com/google-gemini/gemini-cli/pull/15684 +- feat(agents): add support for remote agents and multi-agent TOML files by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15437 +- Update wittyPhrases.ts by @segyges in + https://github.com/google-gemini/gemini-cli/pull/15697 +- refactor(auth): Refactor non-interactive mode auth validation & refresh by + @skeshive in https://github.com/google-gemini/gemini-cli/pull/15679 +- Revert "Update wittyPhrases.ts (#15697)" by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15719 +- fix(hooks): deduplicate agent hooks and add cross-platform integration tests + by @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15701 +- Implement support for tool input modification by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15492 +- Add instructions to the extensions update info notification by @chrstnb in + https://github.com/google-gemini/gemini-cli/pull/14907 +- Add extension settings info to /extensions list by @chrstnb in + https://github.com/google-gemini/gemini-cli/pull/14905 +- Agent Skills: Implement Core Skill Infrastructure & Tiered Discovery by + @NTaylorMullen in https://github.com/google-gemini/gemini-cli/pull/15698 +- chore: remove cot style comments by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15735 +- feat(agents): Add remote agents to agent registry by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15711 +- feat(hooks): implement STOP_EXECUTION and enhance hook decision handling by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15685 +- Fix build issues caused by year-specific linter rule by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15780 +- fix(core): handle unhandled promise rejection in mcp-client-manager by + @kamja44 in https://github.com/google-gemini/gemini-cli/pull/14701 +- log fallback mode by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15817 +- Agent Skills: Implement Autonomous Activation Tool & Context Injection by + @NTaylorMullen in https://github.com/google-gemini/gemini-cli/pull/15725 +- fix(core): improve shell command with redirection detection by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15683 +- Add security docs by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15739 +- feat: add folder suggestions to `/dir add` command by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15724 +- Agent Skills: Implement Agent Integration and System Prompt Awareness by + @NTaylorMullen in https://github.com/google-gemini/gemini-cli/pull/15728 +- chore: cleanup old smart edit settings by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15832 +- Agent Skills: Status Bar Integration for Skill Counts by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15741 +- fix(core): mock powershell output in shell-utils test by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15831 +- Agent Skills: Unify Representation & Centralize Loading by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15833 +- Unify shell security policy and remove legacy logic by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15770 +- feat(core): restore MessageBus optionality for soft migration (Phase 1) by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15774 +- feat(core): Standardize Tool and Agent Invocation constructors (Phase 2) by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15775 +- feat(core,cli): enforce mandatory MessageBus injection (Phase 3 Hard + Migration) by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15776 +- Agent Skills: Extension Support & Security Disclosure by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15834 +- feat(hooks): implement granular stop and block behavior for agent hooks by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15824 +- Agent Skills: Add gemini skills CLI management command by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15837 +- refactor: consolidate EditTool and SmartEditTool by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15857 +- fix(cli): mock fs.readdir in consent tests for Windows compatibility by + @NTaylorMullen in https://github.com/google-gemini/gemini-cli/pull/15904 +- refactor(core): Extract and integrate ToolExecutor by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15900 +- Fix terminal hang when user exits browser without logging in by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15748 +- fix: avoid SDK warning by not accessing .text getter in logging by @ved015 in + https://github.com/google-gemini/gemini-cli/pull/15706 +- Make default settings apply by @devr0306 in + https://github.com/google-gemini/gemini-cli/pull/15354 +- chore: rename smart-edit to edit by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15923 +- Opt-in to persist model from /model by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15820 +- fix: prevent /copy crash on Windows by skipping /dev/tty by @ManojINaik in + https://github.com/google-gemini/gemini-cli/pull/15657 +- Support context injection via SessionStart hook. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15746 +- Fix order of preflight by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15941 +- Fix failing unit tests by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15940 +- fix(cli): resolve paste issue on Windows terminals. by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15932 +- Agent Skills: Implement /skills reload by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15865 +- Add setting to support OSC 52 paste by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15336 +- remove manual string when displaying manual model in the footer by @sehoon38 + in https://github.com/google-gemini/gemini-cli/pull/15967 +- fix(core): use correct interactive check for system prompt by @ppergame in + https://github.com/google-gemini/gemini-cli/pull/15020 +- Inform user of missing settings on extensions update by @chrstnb in + https://github.com/google-gemini/gemini-cli/pull/15944 +- feat(policy): allow 'modes' in user and admin policies by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15977 +- fix: default folder trust to untrusted for enhanced security by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15943 +- Add description for each settings item in /settings by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15936 +- Use GetOperation to poll for OnboardUser completion by @ishaanxgupta in + https://github.com/google-gemini/gemini-cli/pull/15827 +- Agent Skills: Add skill directory to WorkspaceContext upon activation by + @NTaylorMullen in https://github.com/google-gemini/gemini-cli/pull/15870 +- Fix settings command fallback by @chrstnb in + https://github.com/google-gemini/gemini-cli/pull/15926 +- fix: writeTodo construction by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/16014 +- properly disable keyboard modes on exit by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/16006 +- Add workflow to label child issues for rollup by @bdmorgan in + https://github.com/google-gemini/gemini-cli/pull/16002 +- feat(ui): add visual indicators for hook execution by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15408 +- fix: image token estimation by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/16004 +- feat(hooks): Add a hooks.enabled setting. by @joshualitt in + https://github.com/google-gemini/gemini-cli/pull/15933 +- feat(admin): Introduce remote admin settings & implement + secureModeEnabled/mcpEnabled by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/15935 +- Remove trailing whitespace in yaml. by @joshualitt in + https://github.com/google-gemini/gemini-cli/pull/16036 +- feat(agents): add support for remote agents by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/16013 +- fix: limit scheduled issue triage queries to prevent argument list too long + error by @jerop in https://github.com/google-gemini/gemini-cli/pull/16021 +- ci(github-actions): triage all new issues automatically by @jerop in + https://github.com/google-gemini/gemini-cli/pull/16018 +- Fix test. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/16011 +- fix: hide broken skills object from settings dialog by @korade-krushna in + https://github.com/google-gemini/gemini-cli/pull/15766 +- Agent Skills: Initial Documentation & Tutorial by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15869 -**Full Changelog**: -https://github.com/google-gemini/gemini-cli/compare/v0.22.0-preview.3...v0.23.0-preview.0 +**Full changelog**: +https://github.com/google-gemini/gemini-cli/compare/v0.23.0-preview.6...v0.24.0-preview.0 diff --git a/docs/changelogs/releases.md b/docs/changelogs/releases.md index f89385377a..90b94140c3 100644 --- a/docs/changelogs/releases.md +++ b/docs/changelogs/releases.md @@ -10,17 +10,398 @@ For the full changelog, including nightly releases, refer to [Releases - google-gemini/gemini-cli](https://github.com/google-gemini/gemini-cli/releases) on GitHub. -## Current Releases +## Current releases | Release channel | Notes | | :---------------------------------------- | :---------------------------------------------- | | Nightly | Nightly release with the most recent changes. | -| [Preview](#release-v0230-preview-preview) | Experimental features ready for early feedback. | -| [Latest](#release-v0220---v0225-latest) | Stable, recommended for general use. | +| [Preview](#release-v0240-preview-preview) | Experimental features ready for early feedback. | +| [Latest](#release-v0230-latest) | Stable, recommended for general use. | -## Release v0.23.0-preview (Preview) +## Release v0.24.0-preview (Preview) -## What's Changed +### Highlights + +- 🎉 **Experimental Agent Skills Support in Preview:** Gemini CLI now supports + [Agent Skills](https://agentskills.io/home) in our preview builds. This is an + early preview where we’re looking for feedback! + - Install Preview: `npm install -g @google/gemini-cli@preview` + - Enable in `/settings` + - Docs: + [https://geminicli.com/docs/cli/skills/](https://geminicli.com/docs/cli/skills/) + +### What's changed + +- chore(core): refactor model resolution and cleanup fallback logic by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15228 +- Add Folder Trust Support To Hooks by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15325 +- Record timestamp with code assist metrics. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15439 +- feat(policy): implement dynamic mode-aware policy evaluation by @abhipatel12 + in https://github.com/google-gemini/gemini-cli/pull/15307 +- fix(core): use debugLogger.debug for startup profiler logs by @NTaylorMullen + in https://github.com/google-gemini/gemini-cli/pull/15443 +- feat(ui): Add security warning and improve layout for Hooks list by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15440 +- fix #15369, prevent crash on unhandled EIO error in readStdin cleanup by + @ElecTwix in https://github.com/google-gemini/gemini-cli/pull/15410 +- chore: improve error messages for --resume by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15360 +- chore: remove clipboard file by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15447 +- Implemented unified secrets sanitization and env. redaction options by + @gundermanc in https://github.com/google-gemini/gemini-cli/pull/15348 +- feat: automatic `/model` persistence across Gemini CLI sessions by @niyasrad + in https://github.com/google-gemini/gemini-cli/pull/13199 +- refactor(core): remove deprecated permission aliases from BeforeToolHookOutput + by @StoyanD in https://github.com/google-gemini/gemini-cli/pull/14855 +- fix: add missing `type` field to MCPServerConfig by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15465 +- Make schema validation errors non-fatal by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15487 +- chore: limit MCP resources display to 10 by default by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15489 +- Add experimental in-CLI extension install and uninstall subcommands by + @chrstnb in https://github.com/google-gemini/gemini-cli/pull/15178 +- feat: Add A2A Client Manager and tests by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/15485 +- feat: terse transformations of image paths in text buffer by @psinha40898 in + https://github.com/google-gemini/gemini-cli/pull/4924 +- Security: Project-level hook warnings by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15470 +- Added modifyOtherKeys protocol support for tmux by @ved015 in + https://github.com/google-gemini/gemini-cli/pull/15524 +- chore(core): fix comment typo by @Mapleeeeeeeeeee in + https://github.com/google-gemini/gemini-cli/pull/15558 +- feat: Show snowfall animation for holiday theme by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15494 +- do not persist the fallback model by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15483 +- Resolve unhandled promise rejection in ide-client.ts by @Adib234 in + https://github.com/google-gemini/gemini-cli/pull/15587 +- fix(core): handle checkIsRepo failure in GitService.initialize by + @Mapleeeeeeeeeee in https://github.com/google-gemini/gemini-cli/pull/15574 +- fix(cli): add enableShellOutputEfficiency to settings schema by + @Mapleeeeeeeeeee in https://github.com/google-gemini/gemini-cli/pull/15560 +- Manual nightly version bump to 0.24.0-nightly.20251226.546baf993 by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15594 +- refactor(core): extract static concerns from CoreToolScheduler by @abhipatel12 + in https://github.com/google-gemini/gemini-cli/pull/15589 +- fix(core): enable granular shell command allowlisting in policy engine by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15601 +- chore/release: bump version to 0.24.0-nightly.20251227.37be16243 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15612 +- refactor: deprecate legacy confirmation settings and enforce Policy Engine by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15626 +- Migrate console to coreEvents.emitFeedback or debugLogger by @Adib234 in + https://github.com/google-gemini/gemini-cli/pull/15219 +- Exponential back-off retries for retryable error without a specified … by + @sehoon38 in https://github.com/google-gemini/gemini-cli/pull/15684 +- feat(agents): add support for remote agents and multi-agent TOML files by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15437 +- Update wittyPhrases.ts by @segyges in + https://github.com/google-gemini/gemini-cli/pull/15697 +- refactor(auth): Refactor non-interactive mode auth validation & refresh by + @skeshive in https://github.com/google-gemini/gemini-cli/pull/15679 +- Revert "Update wittyPhrases.ts (#15697)" by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15719 +- fix(hooks): deduplicate agent hooks and add cross-platform integration tests + by @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15701 +- Implement support for tool input modification by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15492 +- Add instructions to the extensions update info notification by @chrstnb in + https://github.com/google-gemini/gemini-cli/pull/14907 +- Add extension settings info to /extensions list by @chrstnb in + https://github.com/google-gemini/gemini-cli/pull/14905 +- Agent Skills: Implement Core Skill Infrastructure & Tiered Discovery by + @NTaylorMullen in https://github.com/google-gemini/gemini-cli/pull/15698 +- chore: remove cot style comments by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15735 +- feat(agents): Add remote agents to agent registry by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15711 +- feat(hooks): implement STOP_EXECUTION and enhance hook decision handling by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15685 +- Fix build issues caused by year-specific linter rule by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15780 +- fix(core): handle unhandled promise rejection in mcp-client-manager by + @kamja44 in https://github.com/google-gemini/gemini-cli/pull/14701 +- log fallback mode by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15817 +- Agent Skills: Implement Autonomous Activation Tool & Context Injection by + @NTaylorMullen in https://github.com/google-gemini/gemini-cli/pull/15725 +- fix(core): improve shell command with redirection detection by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15683 +- Add security docs by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15739 +- feat: add folder suggestions to `/dir add` command by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15724 +- Agent Skills: Implement Agent Integration and System Prompt Awareness by + @NTaylorMullen in https://github.com/google-gemini/gemini-cli/pull/15728 +- chore: cleanup old smart edit settings by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15832 +- Agent Skills: Status Bar Integration for Skill Counts by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15741 +- fix(core): mock powershell output in shell-utils test by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15831 +- Agent Skills: Unify Representation & Centralize Loading by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15833 +- Unify shell security policy and remove legacy logic by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15770 +- feat(core): restore MessageBus optionality for soft migration (Phase 1) by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15774 +- feat(core): Standardize Tool and Agent Invocation constructors (Phase 2) by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15775 +- feat(core,cli): enforce mandatory MessageBus injection (Phase 3 Hard + Migration) by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15776 +- Agent Skills: Extension Support & Security Disclosure by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15834 +- feat(hooks): implement granular stop and block behavior for agent hooks by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15824 +- Agent Skills: Add gemini skills CLI management command by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15837 +- refactor: consolidate EditTool and SmartEditTool by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15857 +- fix(cli): mock fs.readdir in consent tests for Windows compatibility by + @NTaylorMullen in https://github.com/google-gemini/gemini-cli/pull/15904 +- refactor(core): Extract and integrate ToolExecutor by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15900 +- Fix terminal hang when user exits browser without logging in by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15748 +- fix: avoid SDK warning by not accessing .text getter in logging by @ved015 in + https://github.com/google-gemini/gemini-cli/pull/15706 +- Make default settings apply by @devr0306 in + https://github.com/google-gemini/gemini-cli/pull/15354 +- chore: rename smart-edit to edit by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15923 +- Opt-in to persist model from /model by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15820 +- fix: prevent /copy crash on Windows by skipping /dev/tty by @ManojINaik in + https://github.com/google-gemini/gemini-cli/pull/15657 +- Support context injection via SessionStart hook. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15746 +- Fix order of preflight by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15941 +- Fix failing unit tests by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15940 +- fix(cli): resolve paste issue on Windows terminals. by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15932 +- Agent Skills: Implement /skills reload by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15865 +- Add setting to support OSC 52 paste by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15336 +- remove manual string when displaying manual model in the footer by @sehoon38 + in https://github.com/google-gemini/gemini-cli/pull/15967 +- fix(core): use correct interactive check for system prompt by @ppergame in + https://github.com/google-gemini/gemini-cli/pull/15020 +- Inform user of missing settings on extensions update by @chrstnb in + https://github.com/google-gemini/gemini-cli/pull/15944 +- feat(policy): allow 'modes' in user and admin policies by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15977 +- fix: default folder trust to untrusted for enhanced security by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15943 +- Add description for each settings item in /settings by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15936 +- Use GetOperation to poll for OnboardUser completion by @ishaanxgupta in + https://github.com/google-gemini/gemini-cli/pull/15827 +- Agent Skills: Add skill directory to WorkspaceContext upon activation by + @NTaylorMullen in https://github.com/google-gemini/gemini-cli/pull/15870 +- Fix settings command fallback by @chrstnb in + https://github.com/google-gemini/gemini-cli/pull/15926 +- fix: writeTodo construction by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/16014 +- properly disable keyboard modes on exit by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/16006 +- Add workflow to label child issues for rollup by @bdmorgan in + https://github.com/google-gemini/gemini-cli/pull/16002 +- feat(ui): add visual indicators for hook execution by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15408 +- fix: image token estimation by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/16004 +- feat(hooks): Add a hooks.enabled setting. by @joshualitt in + https://github.com/google-gemini/gemini-cli/pull/15933 +- feat(admin): Introduce remote admin settings & implement + secureModeEnabled/mcpEnabled by @skeshive in + https://github.com/google-gemini/gemini-cli/pull/15935 +- Remove trailing whitespace in yaml. by @joshualitt in + https://github.com/google-gemini/gemini-cli/pull/16036 +- feat(agents): add support for remote agents by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/16013 +- fix: limit scheduled issue triage queries to prevent argument list too long + error by @jerop in https://github.com/google-gemini/gemini-cli/pull/16021 +- ci(github-actions): triage all new issues automatically by @jerop in + https://github.com/google-gemini/gemini-cli/pull/16018 +- Fix test. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/16011 +- fix: hide broken skills object from settings dialog by @korade-krushna in + https://github.com/google-gemini/gemini-cli/pull/15766 +- Agent Skills: Initial Documentation & Tutorial by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15869 + +**Full changelog**: +https://github.com/google-gemini/gemini-cli/compare/v0.23.0-preview.6...v0.24.0-preview.0 + +## Release v0.23.0 (Latest) + +### Highlights + +- **Gemini CLI wrapped:** Run `npx gemini-wrapped` to visualize your usage + stats, top models, languages, and more! +- **Windows clipboard image support:** Windows users can now paste images + directly from their clipboard into the CLI using `Alt`+`V`. + ([pr](https://github.com/google-gemini/gemini-cli/pull/13997) by + [@sgeraldes](https://github.com/sgeraldes)) +- **Terminal background color detection:** Automatically optimizes your + terminal's background color to select compatible themes and provide + accessibility warnings. + ([pr](https://github.com/google-gemini/gemini-cli/pull/15132) by + [@jacob314](https://github.com/jacob314)) +- **Session logout:** Use the new `/logout` command to instantly clear + credentials and reset your authentication state for seamless account + switching. ([pr](https://github.com/google-gemini/gemini-cli/pull/13383) by + [@CN-Scars](https://github.com/CN-Scars)) + +### What's changed + +- Code assist service metrics. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15024 +- chore/release: bump version to 0.21.0-nightly.20251216.bb0c0d8ee by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15121 +- Docs by @Roaimkhan in https://github.com/google-gemini/gemini-cli/pull/15103 +- Use official ACP SDK and support HTTP/SSE based MCP servers by @SteffenDE in + https://github.com/google-gemini/gemini-cli/pull/13856 +- Remove foreground for themes other than shades of purple and holiday. by + @jacob314 in https://github.com/google-gemini/gemini-cli/pull/14606 +- chore: remove repo specific tips by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15164 +- chore: remove user query from footer in debug mode by @jackwotherspoon in + https://github.com/google-gemini/gemini-cli/pull/15169 +- Disallow unnecessary awaits. by @gundermanc in + https://github.com/google-gemini/gemini-cli/pull/15172 +- Add one to the padding in settings dialog to avoid flicker. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15173 +- feat(core): introduce remote agent infrastructure and rename local executor by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15110 +- feat(cli): Add `/auth logout` command to clear credentials and auth state by + @CN-Scars in https://github.com/google-gemini/gemini-cli/pull/13383 +- (fix) Automated pr labeller by @DaanVersavel in + https://github.com/google-gemini/gemini-cli/pull/14885 +- feat: launch Gemini 3 Flash in Gemini CLI ⚡️⚡️⚡️ by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15196 +- Refactor: Migrate console.error in ripGrep.ts to debugLogger by @Adib234 in + https://github.com/google-gemini/gemini-cli/pull/15201 +- chore: update a2a-js to 0.3.7 by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/15197 +- chore(core): remove redundant isModelAvailabilityServiceEnabled toggle and + clean up dead code by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/15207 +- feat(core): Late resolve `GenerateContentConfig`s and reduce mutation. by + @joshualitt in https://github.com/google-gemini/gemini-cli/pull/14920 +- Respect previewFeatures value from the remote flag if undefined by @sehoon38 + in https://github.com/google-gemini/gemini-cli/pull/15214 +- feat(ui): add Windows clipboard image support and Alt+V paste workaround by + @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15218 +- chore(core): remove legacy fallback flags and migrate loop detection by + @adamfweidman in https://github.com/google-gemini/gemini-cli/pull/15213 +- fix(ui): Prevent eager slash command completion hiding sibling commands by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15224 +- Docs: Update Changelog for Dec 17, 2025 by @jkcinouye in + https://github.com/google-gemini/gemini-cli/pull/15204 +- Code Assist backend telemetry for user accept/reject of suggestions by + @gundermanc in https://github.com/google-gemini/gemini-cli/pull/15206 +- fix(cli): correct initial history length handling for chat commands by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15223 +- chore/release: bump version to 0.21.0-nightly.20251218.739c02bd6 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15231 +- Change detailed model stats to use a new shared Table class to resolve + robustness issues. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15208 +- feat: add agent toml parser by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15112 +- Add core tool that adds all context from the core package. by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15238 +- (docs): Add reference section to hooks documentation by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15159 +- feat(hooks): add support for friendly names and descriptions by @abhipatel12 + in https://github.com/google-gemini/gemini-cli/pull/15174 +- feat: Detect background color by @jacob314 in + https://github.com/google-gemini/gemini-cli/pull/15132 +- add 3.0 to allowed sensitive keywords by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15276 +- feat: Pass additional environment variables to shell execution by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15160 +- Remove unused code by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15290 +- Handle all 429 as retryableQuotaError by @sehoon38 in + https://github.com/google-gemini/gemini-cli/pull/15288 +- Remove unnecessary dependencies by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15291 +- fix: prevent infinite loop in prompt completion on error by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/14548 +- fix(ui): show command suggestions even on perfect match and sort them by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15287 +- feat(hooks): reduce log verbosity and improve error reporting in UI by + @abhipatel12 in https://github.com/google-gemini/gemini-cli/pull/15297 +- feat: simplify tool confirmation labels for better UX by @NTaylorMullen in + https://github.com/google-gemini/gemini-cli/pull/15296 +- chore/release: bump version to 0.21.0-nightly.20251219.70696e364 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15301 +- feat(core): Implement JIT context memory loading and UI sync by @SandyTao520 + in https://github.com/google-gemini/gemini-cli/pull/14469 +- feat(ui): Put "Allow for all future sessions" behind a setting off by default. + by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15322 +- fix(cli):change the placeholder of input during the shell mode by + @JayadityaGit in https://github.com/google-gemini/gemini-cli/pull/15135 +- Validate OAuth resource parameter matches MCP server URL by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15289 +- docs(cli): add System Prompt Override (GEMINI_SYSTEM_MD) by @ashmod in + https://github.com/google-gemini/gemini-cli/pull/9515 +- more robust command parsing logs by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15339 +- Introspection agent demo by @scidomino in + https://github.com/google-gemini/gemini-cli/pull/15232 +- fix(core): sanitize hook command expansion and prevent injection by + @SandyTao520 in https://github.com/google-gemini/gemini-cli/pull/15343 +- fix(folder trust): add validation for trusted folder level by @adamfweidman in + https://github.com/google-gemini/gemini-cli/pull/12215 +- fix(cli): fix right border overflow in trust dialogs by @galz10 in + https://github.com/google-gemini/gemini-cli/pull/15350 +- fix(policy): fix bug where accepting-edits continued after it was turned off + by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15351 +- fix: prevent infinite relaunch loop when --resume fails (#14941) by @Ying-xi + in https://github.com/google-gemini/gemini-cli/pull/14951 +- chore/release: bump version to 0.21.0-nightly.20251220.41a1a3eed by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15352 +- feat(telemetry): add clearcut logging for hooks by @abhipatel12 in + https://github.com/google-gemini/gemini-cli/pull/15405 +- fix(core): Add `.geminiignore` support to SearchText tool by @xyrolle in + https://github.com/google-gemini/gemini-cli/pull/13763 +- fix(patch): cherry-pick 0843d9a to release/v0.23.0-preview.0-pr-15443 to patch + version v0.23.0-preview.0 and create version 0.23.0-preview.1 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15445 +- fix(patch): cherry-pick 9cdb267 to release/v0.23.0-preview.1-pr-15494 to patch + version v0.23.0-preview.1 and create version 0.23.0-preview.2 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15592 +- fix(patch): cherry-pick 37be162 to release/v0.23.0-preview.2-pr-15601 to patch + version v0.23.0-preview.2 and create version 0.23.0-preview.3 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15603 +- fix(patch): cherry-pick 07e597d to release/v0.23.0-preview.3-pr-15684 + [CONFLICTS] by @gemini-cli-robot in + https://github.com/google-gemini/gemini-cli/pull/15734 +- fix(patch): cherry-pick c31f053 to release/v0.23.0-preview.4-pr-16004 to patch + version v0.23.0-preview.4 and create version 0.23.0-preview.5 by + @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/16027 +- fix(patch): cherry-pick 788bb04 to release/v0.23.0-preview.5-pr-15817 + [CONFLICTS] by @gemini-cli-robot in + https://github.com/google-gemini/gemini-cli/pull/16038 + +**Full changelog**: +https://github.com/google-gemini/gemini-cli/compare/v0.22.5...v0.23.0 + +## Release v0.23.0-preview + +### What's changed - Code assist service metrics. by @gundermanc in https://github.com/google-gemini/gemini-cli/pull/15024 @@ -136,10 +517,10 @@ on GitHub. - fix(core): Add `.geminiignore` support to SearchText tool by @xyrolle in https://github.com/google-gemini/gemini-cli/pull/13763 -**Full Changelog**: +**Full changelog**: https://github.com/google-gemini/gemini-cli/compare/v0.22.0-preview.3...v0.23.0-preview.0 -## Release v0.22.0 - v0.22.5 (Latest) +## Release v0.22.0 ### Highlights @@ -161,7 +542,7 @@ https://github.com/google-gemini/gemini-cli/compare/v0.22.0-preview.3...v0.23.0- ([pr](https://github.com/google-gemini/gemini-cli/pull/14832) by [@jackwotherspoon](https://github.com/jackwotherspoon)) -### What's Changed +### What's changed - feat(ide): fallback to GEMINI_CLI_IDE_AUTH_TOKEN env var by @skeshive in https://github.com/google-gemini/gemini-cli/pull/14843 @@ -281,10 +662,10 @@ https://github.com/google-gemini/gemini-cli/compare/v0.22.0-preview.3...v0.23.0- version v0.22.0-preview.2 and create version 0.22.0-preview.3 by @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15294 -**Full Changelog**: +**Full changelog**: https://github.com/google-gemini/gemini-cli/compare/v0.21.3...v0.22.0 -## Release v0.21.0 - v0.21.1 +## Release v0.21.0 ### Highlights @@ -293,7 +674,7 @@ https://github.com/google-gemini/gemini-cli/compare/v0.21.3...v0.22.0 Features** to `true` to enable Gemini 3. For more information: [Gemini 3 Flash is now available in Gemini CLI](https://developers.googleblog.com/gemini-3-flash-is-now-available-in-gemini-cli/). -### What's Changed +### What's changed - refactor(stdio): always patch stdout and use createWorkingStdio for clean output by @allenhutchison in @@ -498,12 +879,12 @@ https://github.com/google-gemini/gemini-cli/compare/v0.21.3...v0.22.0 version v0.21.0-preview.5 and create version 0.21.0-preview.6 by @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/15153 -**Full Changelog**: +**Full changelog**: https://github.com/google-gemini/gemini-cli/compare/v0.20.2...v0.21.0 -## Release v0.22.0-preview-0 (Preview) +## Release v0.22.0-preview-0 -### What's Changed +### What's changed - feat(ide): fallback to GEMINI_CLI_IDE_AUTH_TOKEN env var by @skeshive in https://github.com/google-gemini/gemini-cli/pull/14843 @@ -617,12 +998,12 @@ https://github.com/google-gemini/gemini-cli/compare/v0.20.2...v0.21.0 take priority over ones using the old format by @jacob314 in https://github.com/google-gemini/gemini-cli/pull/15116 -**Full Changelog**: +**Full changelog**: https://github.com/google-gemini/gemini-cli/compare/v0.21.0-preview.6...v0.22.0-preview.0 -## Release v0.20.0 - v0.20.2 +## Release v0.20.0 -### What's Changed +### What's changed - Update error codes when process exiting the gemini cli by @megha1188 in https://github.com/google-gemini/gemini-cli/pull/13728 @@ -747,10 +1128,10 @@ https://github.com/google-gemini/gemini-cli/compare/v0.21.0-preview.6...v0.22.0- version v0.20.0-preview.2 and create version 0.20.0-preview.5 by @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14752 -**Full Changelog**: +**Full changelog**: https://github.com/google-gemini/gemini-cli/compare/v0.19.4...v0.20.0 -## Release v0.19.0 - v0.19.4 +## Release v0.19.0 ## Highlights @@ -765,7 +1146,7 @@ https://github.com/google-gemini/gemini-cli/compare/v0.19.4...v0.20.0 [pr](https://github.com/google-gemini/gemini-cli/pull/12535) by [@jackwotherspoon](https://github.com/jackwotherspoon)) -### What's Changed +### What's changed - Use lenient MCP output schema validator by @cornmander in https://github.com/google-gemini/gemini-cli/pull/13521 @@ -894,12 +1275,12 @@ https://github.com/google-gemini/gemini-cli/compare/v0.19.4...v0.20.0 [CONFLICTS] by @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/14402 -**Full Changelog**: +**Full changelog**: https://github.com/google-gemini/gemini-cli/compare/v0.18.4...v0.19.0 ## Release v0.19.0-preview.0 -### What's Changed +### What's changed - Use lenient MCP output schema validator by @cornmander in https://github.com/google-gemini/gemini-cli/pull/13521 @@ -1025,10 +1406,10 @@ https://github.com/google-gemini/gemini-cli/compare/v0.18.4...v0.19.0 - Update dependency for modelcontextprotocol/sdk to 1.23.0 by @bbiggs in https://github.com/google-gemini/gemini-cli/pull/13827 -**Full Changelog**: +**Full changelog**: https://github.com/google-gemini/gemini-cli/compare/v0.18.0-preview.4...v0.19.0-preview.0 -## Release v0.18.0 - v0.18.4 +## Release v0.18.0 ### Highlights @@ -1158,5 +1539,5 @@ https://github.com/google-gemini/gemini-cli/compare/v0.18.0-preview.4...v0.19.0- version v0.18.0-preview.3 and create version 0.18.0-preview.4 by @gemini-cli-robot in https://github.com/google-gemini/gemini-cli/pull/13826 - **Full Changelog**: + **Full changelog**: https://github.com/google-gemini/gemini-cli/compare/v0.17.1...v0.18.0 From 94d5ae541ee0524e1ba313ffc58e015d22d50213 Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Wed, 14 Jan 2026 13:27:36 -0800 Subject: [PATCH 190/713] Simplify paste handling (#16654) --- docs/cli/keyboard-shortcuts.md | 8 +++--- packages/cli/src/config/keyBindings.test.ts | 3 --- packages/cli/src/config/keyBindings.ts | 4 --- packages/cli/src/ui/AppContainer.test.tsx | 5 ---- .../cli/src/ui/auth/ApiAuthDialog.test.tsx | 1 - .../LoginWithGoogleRestartDialog.test.tsx | 2 -- .../src/ui/components/InputPrompt.test.tsx | 4 +-- .../cli/src/ui/components/InputPrompt.tsx | 4 +-- .../MultiFolderTrustDialog.test.tsx | 1 - .../src/ui/components/SessionBrowser.test.tsx | 1 - .../cli/src/ui/components/SettingsDialog.tsx | 2 +- .../ui/components/shared/TextInput.test.tsx | 8 ------ .../ui/components/shared/text-buffer.test.ts | 19 -------------- .../src/ui/components/shared/text-buffer.ts | 6 ++--- .../src/ui/contexts/KeypressContext.test.tsx | 10 +------- .../cli/src/ui/contexts/KeypressContext.tsx | 7 +----- .../cli/src/ui/hooks/useKeypress.test.tsx | 25 ++++++++----------- .../src/ui/hooks/useSelectionList.test.tsx | 3 --- packages/cli/src/ui/hooks/vim.test.tsx | 1 - packages/cli/src/ui/hooks/vim.ts | 1 - packages/cli/src/ui/keyMatchers.test.ts | 3 --- packages/cli/src/ui/keyMatchers.ts | 4 --- 22 files changed, 25 insertions(+), 97 deletions(-) diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index 96565a5cf3..b90954a31a 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -87,10 +87,10 @@ available combinations. #### Text Input -| Action | Keys | -| ------------------------------------ | ------------------------------------------------------------------------------------------- | -| Submit the current prompt. | `Enter (no Ctrl, no Shift, no Cmd, not Paste)` | -| Insert a newline without submitting. | `Ctrl + Enter`
`Cmd + Enter`
`Paste + Enter`
`Shift + Enter`
`Ctrl + J` | +| Action | Keys | +| ------------------------------------ | ---------------------------------------------------------------------- | +| Submit the current prompt. | `Enter (no Ctrl, no Shift, no Cmd)` | +| Insert a newline without submitting. | `Ctrl + Enter`
`Cmd + Enter`
`Shift + Enter`
`Ctrl + J` | #### External Tools diff --git a/packages/cli/src/config/keyBindings.test.ts b/packages/cli/src/config/keyBindings.test.ts index 2a4debd483..d8c83024f5 100644 --- a/packages/cli/src/config/keyBindings.test.ts +++ b/packages/cli/src/config/keyBindings.test.ts @@ -45,9 +45,6 @@ describe('keyBindings config', () => { if (binding.command !== undefined) { expect(typeof binding.command).toBe('boolean'); } - if (binding.paste !== undefined) { - expect(typeof binding.paste).toBe('boolean'); - } } } }); diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index 432d958489..d888c1046e 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -104,8 +104,6 @@ export interface KeyBinding { shift?: boolean; /** Command/meta key requirement: true=must be pressed, false=must not be pressed, undefined=ignore */ command?: boolean; - /** Paste operation requirement: true=must be paste, false=must not be paste, undefined=ignore */ - paste?: boolean; } /** @@ -211,7 +209,6 @@ export const defaultKeyBindings: KeyBindingConfig = { key: 'return', ctrl: false, command: false, - paste: false, shift: false, }, ], @@ -220,7 +217,6 @@ export const defaultKeyBindings: KeyBindingConfig = { [Command.NEWLINE]: [ { key: 'return', ctrl: true }, { key: 'return', command: true }, - { key: 'return', paste: true }, { key: 'return', shift: true }, { key: 'j', ctrl: true }, ], diff --git a/packages/cli/src/ui/AppContainer.test.tsx b/packages/cli/src/ui/AppContainer.test.tsx index dd648d1975..3dbf61c965 100644 --- a/packages/cli/src/ui/AppContainer.test.tsx +++ b/packages/cli/src/ui/AppContainer.test.tsx @@ -1858,7 +1858,6 @@ describe('AppContainer State Management', () => { ctrl: true, meta: false, shift: false, - paste: false, insertable: false, sequence: '\x13', }); @@ -1885,7 +1884,6 @@ describe('AppContainer State Management', () => { ctrl: true, meta: false, shift: false, - paste: false, insertable: false, sequence: '\x13', }); @@ -1900,7 +1898,6 @@ describe('AppContainer State Management', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: true, sequence: 'a', }); @@ -1921,7 +1918,6 @@ describe('AppContainer State Management', () => { ctrl: true, meta: false, shift: false, - paste: false, insertable: false, sequence: '\x13', }); @@ -1937,7 +1933,6 @@ describe('AppContainer State Management', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: true, sequence: 'a', }); diff --git a/packages/cli/src/ui/auth/ApiAuthDialog.test.tsx b/packages/cli/src/ui/auth/ApiAuthDialog.test.tsx index a17c2708bf..e752c616a0 100644 --- a/packages/cli/src/ui/auth/ApiAuthDialog.test.tsx +++ b/packages/cli/src/ui/auth/ApiAuthDialog.test.tsx @@ -112,7 +112,6 @@ describe('ApiAuthDialog', () => { ctrl: false, meta: false, shift: false, - paste: false, }); expect(expectedCall).toHaveBeenCalledWith(...args); diff --git a/packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.test.tsx b/packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.test.tsx index 5dd9d0c171..a7e857bd3b 100644 --- a/packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.test.tsx +++ b/packages/cli/src/ui/auth/LoginWithGoogleRestartDialog.test.tsx @@ -52,7 +52,6 @@ describe('LoginWithGoogleRestartDialog', () => { ctrl: false, meta: false, shift: false, - paste: false, }); expect(onDismiss).toHaveBeenCalledTimes(1); @@ -72,7 +71,6 @@ describe('LoginWithGoogleRestartDialog', () => { ctrl: false, meta: false, shift: false, - paste: false, }); // Advance timers to trigger the setTimeout callback diff --git a/packages/cli/src/ui/components/InputPrompt.test.tsx b/packages/cli/src/ui/components/InputPrompt.test.tsx index b9a3d2622d..0a801cba87 100644 --- a/packages/cli/src/ui/components/InputPrompt.test.tsx +++ b/packages/cli/src/ui/components/InputPrompt.test.tsx @@ -1465,7 +1465,7 @@ describe('InputPrompt', () => { await waitFor(() => { expect(mockBuffer.handleInput).toHaveBeenCalledWith( expect.objectContaining({ - paste: true, + name: 'paste', sequence: 'pasted text', }), ); @@ -1708,7 +1708,7 @@ describe('InputPrompt', () => { expect(props.buffer.handleInput).toHaveBeenCalledTimes(1); expect(props.buffer.handleInput).toHaveBeenCalledWith( expect.objectContaining({ - paste: true, + name: 'paste', sequence: pastedText, }), ); diff --git a/packages/cli/src/ui/components/InputPrompt.tsx b/packages/cli/src/ui/components/InputPrompt.tsx index 762fc84b06..f2445d4061 100644 --- a/packages/cli/src/ui/components/InputPrompt.tsx +++ b/packages/cli/src/ui/components/InputPrompt.tsx @@ -396,11 +396,11 @@ export const InputPrompt: React.FC = ({ // We should probably stop supporting paste if the InputPrompt is not // focused. /// We want to handle paste even when not focused to support drag and drop. - if (!focus && !key.paste) { + if (!focus && key.name !== 'paste') { return; } - if (key.paste) { + if (key.name === 'paste') { // Record paste time to prevent accidental auto-submission if (!isTerminalPasteTrusted(kittyProtocol.enabled)) { setRecentUnsafePasteTime(Date.now()); diff --git a/packages/cli/src/ui/components/MultiFolderTrustDialog.test.tsx b/packages/cli/src/ui/components/MultiFolderTrustDialog.test.tsx index 64e992b06a..9ec91f53c4 100644 --- a/packages/cli/src/ui/components/MultiFolderTrustDialog.test.tsx +++ b/packages/cli/src/ui/components/MultiFolderTrustDialog.test.tsx @@ -94,7 +94,6 @@ describe('MultiFolderTrustDialog', () => { ctrl: false, meta: false, shift: false, - paste: false, sequence: '', insertable: false, }); diff --git a/packages/cli/src/ui/components/SessionBrowser.test.tsx b/packages/cli/src/ui/components/SessionBrowser.test.tsx index 5668d21037..3fa4da896d 100644 --- a/packages/cli/src/ui/components/SessionBrowser.test.tsx +++ b/packages/cli/src/ui/components/SessionBrowser.test.tsx @@ -111,7 +111,6 @@ const triggerKey = ( ctrl: false, meta: false, shift: false, - paste: false, insertable: false, sequence: '', ...partialKey, diff --git a/packages/cli/src/ui/components/SettingsDialog.tsx b/packages/cli/src/ui/components/SettingsDialog.tsx index b0c40e2d2c..97ae3939fb 100644 --- a/packages/cli/src/ui/components/SettingsDialog.tsx +++ b/packages/cli/src/ui/components/SettingsDialog.tsx @@ -606,7 +606,7 @@ export function SettingsDialog({ const definition = getSettingDefinition(editingKey); const type = definition?.type; - if (key.paste && key.sequence) { + if (key.name === 'paste' && key.sequence) { let pasted = key.sequence; if (type === 'number') { pasted = key.sequence.replace(/[^0-9\-+.]/g, ''); diff --git a/packages/cli/src/ui/components/shared/TextInput.test.tsx b/packages/cli/src/ui/components/shared/TextInput.test.tsx index 7af09fe7a9..56c3edbd37 100644 --- a/packages/cli/src/ui/components/shared/TextInput.test.tsx +++ b/packages/cli/src/ui/components/shared/TextInput.test.tsx @@ -155,7 +155,6 @@ describe('TextInput', () => { ctrl: false, meta: false, shift: false, - paste: false, }); expect(mockBuffer.handleInput).toHaveBeenCalledWith({ @@ -164,7 +163,6 @@ describe('TextInput', () => { ctrl: false, meta: false, shift: false, - paste: false, }); expect(mockBuffer.text).toBe('a'); }); @@ -182,7 +180,6 @@ describe('TextInput', () => { ctrl: false, meta: false, shift: false, - paste: false, }); expect(mockBuffer.handleInput).toHaveBeenCalledWith({ @@ -191,7 +188,6 @@ describe('TextInput', () => { ctrl: false, meta: false, shift: false, - paste: false, }); expect(mockBuffer.text).toBe('tes'); }); @@ -209,7 +205,6 @@ describe('TextInput', () => { ctrl: false, meta: false, shift: false, - paste: false, }); // Cursor moves from end to before 't' @@ -230,7 +225,6 @@ describe('TextInput', () => { ctrl: false, meta: false, shift: false, - paste: false, }); expect(mockBuffer.visualCursor[1]).toBe(3); @@ -249,7 +243,6 @@ describe('TextInput', () => { ctrl: false, meta: false, shift: false, - paste: false, }); expect(onSubmit).toHaveBeenCalledWith('test'); @@ -268,7 +261,6 @@ describe('TextInput', () => { ctrl: false, meta: false, shift: false, - paste: false, }); await vi.runAllTimersAsync(); diff --git a/packages/cli/src/ui/components/shared/text-buffer.test.ts b/packages/cli/src/ui/components/shared/text-buffer.test.ts index f127f28051..0cd7c7bfd2 100644 --- a/packages/cli/src/ui/components/shared/text-buffer.test.ts +++ b/packages/cli/src/ui/components/shared/text-buffer.test.ts @@ -1051,7 +1051,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: true, sequence: 'h', }), @@ -1062,7 +1061,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: true, sequence: 'i', }), @@ -1080,7 +1078,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: true, sequence: '\r', }), @@ -1098,7 +1095,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: false, sequence: '\t', }), @@ -1116,7 +1112,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: true, - paste: false, insertable: false, sequence: '\u001b[9;2u', }), @@ -1139,7 +1134,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: false, sequence: '\x7f', }), @@ -1164,7 +1158,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: false, sequence: '\x7f', }); @@ -1173,7 +1166,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: false, sequence: '\x7f', }); @@ -1182,7 +1174,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: false, sequence: '\x7f', }); @@ -1242,7 +1233,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: false, sequence: '\x1b[D', }), @@ -1254,7 +1244,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: false, sequence: '\x1b[C', }), @@ -1274,7 +1263,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: true, sequence: textWithAnsi, }), @@ -1292,7 +1280,6 @@ describe('useTextBuffer', () => { ctrl: false, meta: false, shift: true, - paste: false, insertable: true, sequence: '\r', }), @@ -1497,7 +1484,6 @@ Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots ctrl: false, meta: false, shift: false, - paste: false, insertable: true, sequence, }); @@ -1556,7 +1542,6 @@ Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots ctrl: false, meta: false, shift: false, - paste: false, insertable: true, sequence: largeTextWithUnsafe, }), @@ -1591,7 +1576,6 @@ Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots ctrl: false, meta: false, shift: false, - paste: false, insertable: true, sequence: largeTextWithAnsi, }), @@ -1616,7 +1600,6 @@ Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots ctrl: false, meta: false, shift: false, - paste: false, insertable: true, sequence: emojis, }), @@ -1808,7 +1791,6 @@ Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots ctrl: false, meta: false, shift: false, - paste: false, insertable: true, sequence: '\r', }), @@ -1830,7 +1812,6 @@ Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots ctrl: false, meta: false, shift: false, - paste: false, insertable: false, sequence: '\u001bOP', }), diff --git a/packages/cli/src/ui/components/shared/text-buffer.ts b/packages/cli/src/ui/components/shared/text-buffer.ts index 26c1ddca80..9ef6fdec83 100644 --- a/packages/cli/src/ui/components/shared/text-buffer.ts +++ b/packages/cli/src/ui/components/shared/text-buffer.ts @@ -2223,10 +2223,10 @@ export function useTextBuffer({ (key: Key): void => { const { sequence: input } = key; - if (key.paste) { + if (key.name === 'paste') { // Do not do any other processing on pastes so ensure we handle them // before all other cases. - insert(input, { paste: key.paste }); + insert(input, { paste: true }); return; } @@ -2253,7 +2253,7 @@ export function useTextBuffer({ else if (keyMatchers[Command.UNDO](key)) undo(); else if (keyMatchers[Command.REDO](key)) redo(); else if (key.insertable) { - insert(input, { paste: key.paste }); + insert(input, { paste: false }); } }, [ diff --git a/packages/cli/src/ui/contexts/KeypressContext.test.tsx b/packages/cli/src/ui/contexts/KeypressContext.test.tsx index 348f940dbd..24cadfa85c 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.test.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.test.tsx @@ -384,7 +384,7 @@ describe('KeypressContext', () => { expect(keyHandler).toHaveBeenCalledWith( expect.objectContaining({ - paste: true, + name: 'paste', sequence: pastedText, }), ); @@ -405,7 +405,6 @@ describe('KeypressContext', () => { expect(keyHandler).toHaveBeenCalledWith( expect.objectContaining({ name: 'paste', - paste: true, sequence: 'Hello OSC 52', }), ); @@ -432,7 +431,6 @@ describe('KeypressContext', () => { expect(keyHandler).toHaveBeenCalledWith( expect.objectContaining({ name: 'paste', - paste: true, sequence: 'Split Paste', }), ); @@ -454,7 +452,6 @@ describe('KeypressContext', () => { expect(keyHandler).toHaveBeenCalledWith( expect.objectContaining({ name: 'paste', - paste: true, sequence: 'Terminated by ST', }), ); @@ -727,7 +724,6 @@ describe('KeypressContext', () => { ctrl: false, meta: true, shift: false, - paste: false, }, }; } else if (terminal === 'MacTerminal') { @@ -743,7 +739,6 @@ describe('KeypressContext', () => { ctrl: false, meta: true, shift: false, - paste: false, }, }; } else { @@ -759,7 +754,6 @@ describe('KeypressContext', () => { ctrl: false, meta: true, // Always expect meta:true after conversion shift: false, - paste: false, sequence: accentedChar, }, }; @@ -834,7 +828,6 @@ describe('KeypressContext', () => { expect.objectContaining({ name: 'undefined', sequence: INCOMPLETE_KITTY_SEQUENCE, - paste: false, }), ); }); @@ -853,7 +846,6 @@ describe('KeypressContext', () => { expect(keyHandler).toHaveBeenCalledWith( expect.objectContaining({ sequence: '\x1b[m', - paste: false, }), ); }); diff --git a/packages/cli/src/ui/contexts/KeypressContext.tsx b/packages/cli/src/ui/contexts/KeypressContext.tsx index c0fdd6deac..df59356990 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.tsx @@ -250,11 +250,10 @@ function bufferPaste(keypressHandler: KeypressHandler): KeypressHandler { if (buffer.length > 0) { keypressHandler({ - name: '', + name: 'paste', ctrl: false, meta: false, shift: false, - paste: true, insertable: true, sequence: buffer, }); @@ -357,7 +356,6 @@ function* emitKeys( ctrl: false, meta: false, shift: false, - paste: true, insertable: true, sequence: decoded, }); @@ -570,7 +568,6 @@ function* emitKeys( ctrl, meta, shift, - paste: false, insertable: false, sequence: ESC, }); @@ -592,7 +589,6 @@ function* emitKeys( ctrl, meta, shift, - paste: false, insertable, sequence, }); @@ -606,7 +602,6 @@ export interface Key { ctrl: boolean; meta: boolean; shift: boolean; - paste: boolean; insertable: boolean; sequence: string; } diff --git a/packages/cli/src/ui/hooks/useKeypress.test.tsx b/packages/cli/src/ui/hooks/useKeypress.test.tsx index ebbc5eef82..71d901bcb5 100644 --- a/packages/cli/src/ui/hooks/useKeypress.test.tsx +++ b/packages/cli/src/ui/hooks/useKeypress.test.tsx @@ -114,7 +114,7 @@ describe(`useKeypress`, () => { const key = { name: 'return', sequence: '\x1B\r' }; act(() => stdin.write(key.sequence)); expect(onKeypress).toHaveBeenCalledWith( - expect.objectContaining({ ...key, meta: true, paste: false }), + expect.objectContaining({ ...key, meta: true }), ); }); @@ -139,11 +139,10 @@ describe(`useKeypress`, () => { expect(onKeypress).toHaveBeenCalledTimes(1); expect(onKeypress).toHaveBeenCalledWith({ - name: '', + name: 'paste', ctrl: false, meta: false, shift: false, - paste: true, insertable: true, sequence: pasteText, }); @@ -155,19 +154,19 @@ describe(`useKeypress`, () => { const keyA = { name: 'a', sequence: 'a' }; act(() => stdin.write('a')); expect(onKeypress).toHaveBeenCalledWith( - expect.objectContaining({ ...keyA, paste: false }), + expect.objectContaining({ ...keyA }), ); const pasteText = 'pasted'; act(() => stdin.write(PASTE_START + pasteText + PASTE_END)); expect(onKeypress).toHaveBeenCalledWith( - expect.objectContaining({ paste: true, sequence: pasteText }), + expect.objectContaining({ name: 'paste', sequence: pasteText }), ); const keyB = { name: 'b', sequence: 'b' }; act(() => stdin.write('b')); expect(onKeypress).toHaveBeenCalledWith( - expect.objectContaining({ ...keyB, paste: false }), + expect.objectContaining({ ...keyB }), ); expect(onKeypress).toHaveBeenCalledTimes(3); @@ -183,10 +182,8 @@ describe(`useKeypress`, () => { stdin.write(PASTE_END); }); expect(onKeypress).toHaveBeenCalledWith( - expect.objectContaining({ paste: true, sequence: pasteText }), + expect.objectContaining({ name: 'paste', sequence: pasteText }), ); - - expect(onKeypress).toHaveBeenCalledTimes(1); }); it('should handle paste false alarm', async () => { @@ -222,10 +219,10 @@ describe(`useKeypress`, () => { ); }); expect(onKeypress).toHaveBeenCalledWith( - expect.objectContaining({ paste: true, sequence: pasteText1 }), + expect.objectContaining({ name: 'paste', sequence: pasteText1 }), ); expect(onKeypress).toHaveBeenCalledWith( - expect.objectContaining({ paste: true, sequence: pasteText2 }), + expect.objectContaining({ name: 'paste', sequence: pasteText2 }), ); expect(onKeypress).toHaveBeenCalledTimes(2); @@ -237,7 +234,7 @@ describe(`useKeypress`, () => { const keyA = { name: 'a', sequence: 'a' }; act(() => stdin.write('a')); expect(onKeypress).toHaveBeenCalledWith( - expect.objectContaining({ ...keyA, paste: false }), + expect.objectContaining({ ...keyA }), ); const pasteText = 'pasted'; @@ -251,13 +248,13 @@ describe(`useKeypress`, () => { stdin.write(PASTE_END.slice(3)); }); expect(onKeypress).toHaveBeenCalledWith( - expect.objectContaining({ paste: true, sequence: pasteText }), + expect.objectContaining({ name: 'paste', sequence: pasteText }), ); const keyB = { name: 'b', sequence: 'b' }; act(() => stdin.write('b')); expect(onKeypress).toHaveBeenCalledWith( - expect.objectContaining({ ...keyB, paste: false }), + expect.objectContaining({ ...keyB }), ); expect(onKeypress).toHaveBeenCalledTimes(3); diff --git a/packages/cli/src/ui/hooks/useSelectionList.test.tsx b/packages/cli/src/ui/hooks/useSelectionList.test.tsx index 38351710b0..7006f0f5d3 100644 --- a/packages/cli/src/ui/hooks/useSelectionList.test.tsx +++ b/packages/cli/src/ui/hooks/useSelectionList.test.tsx @@ -61,7 +61,6 @@ describe('useSelectionList', () => { ctrl: options.ctrl ?? false, meta: false, shift: options.shift ?? false, - paste: false, insertable: false, }; activeKeypressHandler(key); @@ -331,7 +330,6 @@ describe('useSelectionList', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: true, }; handler(key); @@ -381,7 +379,6 @@ describe('useSelectionList', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: false, }; handler(key); diff --git a/packages/cli/src/ui/hooks/vim.test.tsx b/packages/cli/src/ui/hooks/vim.test.tsx index a7931f0733..db7d287425 100644 --- a/packages/cli/src/ui/hooks/vim.test.tsx +++ b/packages/cli/src/ui/hooks/vim.test.tsx @@ -39,7 +39,6 @@ const createKey = (partial: Partial): Key => ({ ctrl: partial.ctrl || false, meta: partial.meta || false, shift: partial.shift || false, - paste: partial.paste || false, insertable: partial.insertable || false, ...partial, }); diff --git a/packages/cli/src/ui/hooks/vim.ts b/packages/cli/src/ui/hooks/vim.ts index dc3344a201..46492220a0 100644 --- a/packages/cli/src/ui/hooks/vim.ts +++ b/packages/cli/src/ui/hooks/vim.ts @@ -312,7 +312,6 @@ export function useVim(buffer: TextBuffer, onSubmit?: (value: string) => void) { ctrl: key.ctrl || false, meta: key.meta || false, shift: key.shift || false, - paste: key.paste || false, insertable: key.insertable || false, }), [], diff --git a/packages/cli/src/ui/keyMatchers.test.ts b/packages/cli/src/ui/keyMatchers.test.ts index 06af0e0a95..670f84a87b 100644 --- a/packages/cli/src/ui/keyMatchers.test.ts +++ b/packages/cli/src/ui/keyMatchers.test.ts @@ -16,7 +16,6 @@ describe('keyMatchers', () => { ctrl: false, meta: false, shift: false, - paste: false, insertable: false, sequence: name, ...mods, @@ -243,7 +242,6 @@ describe('keyMatchers', () => { negative: [ createKey('return', { ctrl: true }), createKey('return', { meta: true }), - createKey('return', { paste: true }), ], }, { @@ -251,7 +249,6 @@ describe('keyMatchers', () => { positive: [ createKey('return', { ctrl: true }), createKey('return', { meta: true }), - createKey('return', { paste: true }), ], negative: [createKey('return'), createKey('n')], }, diff --git a/packages/cli/src/ui/keyMatchers.ts b/packages/cli/src/ui/keyMatchers.ts index 103c571003..b12160dbb6 100644 --- a/packages/cli/src/ui/keyMatchers.ts +++ b/packages/cli/src/ui/keyMatchers.ts @@ -46,10 +46,6 @@ function matchKeyBinding(keyBinding: KeyBinding, key: Key): boolean { return false; } - if (keyBinding.paste !== undefined && key.paste !== keyBinding.paste) { - return false; - } - return true; } From b14cf1dc301187a29bcc5766f5201104efecde32 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Wed, 14 Jan 2026 16:55:19 -0500 Subject: [PATCH 191/713] chore(automation): improve scheduled issue triage discovery and throughput (#16652) --- .../gemini-scheduled-issue-triage.yml | 135 ++++++++---------- 1 file changed, 63 insertions(+), 72 deletions(-) diff --git a/.github/workflows/gemini-scheduled-issue-triage.yml b/.github/workflows/gemini-scheduled-issue-triage.yml index 6aaeb950cf..7a966d59aa 100644 --- a/.github/workflows/gemini-scheduled-issue-triage.yml +++ b/.github/workflows/gemini-scheduled-issue-triage.yml @@ -59,22 +59,26 @@ jobs: run: |- set -euo pipefail - echo '🔍 Finding issues without labels...' - NO_LABEL_ISSUES="$(gh issue list --repo "${GITHUB_REPOSITORY}" \ - --search 'is:open is:issue no:label' --limit 10 --json number,title,body)" + echo '🔍 Finding issues missing area labels...' + NO_AREA_ISSUES="$(gh issue list --repo "${GITHUB_REPOSITORY}" \ + --search 'is:open is:issue -label:area/core -label:area/agent -label:area/enterprise -label:area/non-interactive -label:area/security -label:area/platform -label:area/extensions -label:area/unknown' --limit 100 --json number,title,body)" - echo '🏷️ Finding issues that need triage...' - NEED_TRIAGE_ISSUES="$(gh issue list --repo "${GITHUB_REPOSITORY}" \ - --search "is:open is:issue label:\"status/need-triage\"" --limit 10 --json number,title,body)" + echo '🔍 Finding issues missing kind labels...' + NO_KIND_ISSUES="$(gh issue list --repo "${GITHUB_REPOSITORY}" \ + --search 'is:open is:issue -label:kind/bug -label:kind/enhancement -label:kind/customer-issue -label:kind/question' --limit 100 --json number,title,body)" + + echo '🏷️ Finding issues missing priority labels...' + NO_PRIORITY_ISSUES="$(gh issue list --repo "${GITHUB_REPOSITORY}" \ + --search 'is:open is:issue -label:priority/p0 -label:priority/p1 -label:priority/p2 -label:priority/p3 -label:priority/unknown' --limit 100 --json number,title,body)" echo '🔄 Merging and deduplicating issues...' - ISSUES="$(echo "${NO_LABEL_ISSUES}" "${NEED_TRIAGE_ISSUES}" | jq -c -s 'add | unique_by(.number)')" + ISSUES="$(echo "${NO_AREA_ISSUES}" "${NO_KIND_ISSUES}" "${NO_PRIORITY_ISSUES}" | jq -c -s 'add | unique_by(.number)')" echo '📝 Setting output for GitHub Actions...' echo "issues_to_triage=${ISSUES}" >> "${GITHUB_OUTPUT}" ISSUE_COUNT="$(echo "${ISSUES}" | jq 'length')" - echo "✅ Found ${ISSUE_COUNT} issues to triage! 🎯" + echo "✅ Found ${ISSUE_COUNT} unique issues to triage! 🎯" - name: 'Get Repository Labels' id: 'get_labels' @@ -133,38 +137,33 @@ jobs: 1. You are only able to use the echo command. Review the available labels in the environment variable: "${AVAILABLE_LABELS}". 2. Check environment variable for issues to triage: $ISSUES_TO_TRIAGE (JSON array of issues) 3. Review the issue title, body and any comments provided in the environment variables. - 4. Identify the most relevant labels from the existing labels, focusing on kind/* and priority/*. - 5. If the issue already has a kind/ label don't change it. And if the issue already has a priority/ label do not change it for example: - If an issue has kind/bug you will only add a priority/ label. - Instead if an issue has no labels, you could add one label of each kind. + 4. Identify the most relevant labels from the existing labels, specifically focusing on area/*, kind/* and priority/*. + 5. Label Policy: + - If the issue already has a kind/ label, do not change it. + - If the issue already has a priority/ label, do not change it. + - If the issue already has an area/ label, do not change it. + - If any of these are missing, select exactly ONE appropriate label for the missing category. 6. Identify other applicable labels based on the issue content, such as status/*, help wanted, good first issue, etc. - 7. For kind/* limit yourself to only the single most applicable label. - 8. Give me a single short explanation about why you are selecting each label in the process. - 9. Output a JSON array of objects, each containing the issue number + 7. Give me a single short explanation about why you are selecting each label in the process. + 8. Output a JSON array of objects, each containing the issue number and the labels to add and remove, along with an explanation. For example: ``` [ { "issue_number": 123, - "labels_to_add": ["kind/bug", "priority/p2"], + "labels_to_add": ["area/core", "kind/bug", "priority/p2"], "labels_to_remove": ["status/need-triage"], - "explanation": "This issue is a bug that needs to be addressed with medium priority." - }, - { - "issue_number": 456, - "labels_to_add": ["kind/enhancement"], - "labels_to_remove": [], - "explanation": "This issue is an enhancement request that could improve the user experience." + "explanation": "This issue is a UI bug that needs to be addressed with medium priority." } ] ``` If an issue cannot be classified, do not include it in the output array. - 10. For each issue please check if CLI version is present, this is usually in the output of the /about command and will look like 0.1.5 + 9. For each issue please check if CLI version is present, this is usually in the output of the /about command and will look like 0.1.5 - Anything more than 6 versions older than the most recent should add the status/need-retesting label - 11. If you see that the issue doesn't look like it has sufficient information recommend the status/need-information label and leave a comment politely requesting the relevant information, eg.. if repro steps are missing request for repro steps. if version information is missing request for version information into the explanation section below. + 10. If you see that the issue doesn't look like it has sufficient information recommend the status/need-information label and leave a comment politely requesting the relevant information, eg.. if repro steps are missing request for repro steps. if version information is missing request for version information into the explanation section below. - After identifying appropriate labels to an issue, add "status/need-triage" label to labels_to_remove in the output. - 12. If you think an issue might be a Priority/P0 do not apply the priority/p0 label. Instead apply a status/manual-triage label and include a note in your explanation. - 13. If you are uncertain and have not been able to apply one each of kind/ and priority/ , apply the status/manual-triage label. + 11. If you think an issue might be a Priority/P0 do not apply the priority/p0 label. Instead apply a status/manual-triage label and include a note in your explanation. + 12. If you are uncertain about a category, use the area/unknown, kind/question, or priority/unknown labels as appropriate. If you are extremely uncertain, apply the status/manual-triage label. ## Guidelines @@ -174,54 +173,46 @@ jobs: - Do not add comments or modify the issue content. - Do not remove the following labels maintainer, help wanted or good first issue. - Triage only the current issue. + - Identify only one area/ label. - Identify only one kind/ label (Do not apply kind/duplicate or kind/parent-issue) - - Identify all applicable priority/* labels based on the issue content. It's ok to have multiple of these. + - Identify only one priority/ label. - Once you categorize the issue if it needs information bump down the priority by 1 eg.. a p0 would become a p1 a p1 would become a p2. P2 and P3 can stay as is in this scenario. - Categorization Guidelines: - P0: Critical / Blocker - - A P0 bug is a catastrophic failure that demands immediate attention. - - To be a P0 it means almost all users are running into this issue and it is blocking users from being able to use the product. - - You would see this in the form of many comments from different developers on the bug. - - It represents a complete showstopper for a significant portion of users or for the development process itself. - Impact: - - Blocks development or testing for the entire team. - - Major security vulnerability that could compromise user data or system integrity. - - Causes data loss or corruption with no workaround. - - Crashes the application or makes a core feature completely unusable for all or most users in a production environment. Will it cause severe quality degration? - - Is it preventing contributors from contributing to the repository or is it a release blocker? - Qualifier: Is the main function of the software broken? - Example: The gemini auth login command fails with an unrecoverable error, preventing any user from authenticating and using the rest of the CLI. - P1: High - - A P1 bug is a serious issue that significantly degrades the user experience or impacts a core feature. - - While not a complete blocker, it's a major problem that needs a fast resolution. Feature requests are almost never P1. - - Once again this would be affecting many users. - - You would see this in the form of comments from different developers on the bug. - Impact: - - A core feature is broken or behaving incorrectly for a large number of users or large number of use cases. - - Review the bug details and comments to try figure out if this issue affects a large set of use cases or if it's a narrow set of use cases. - - Severe performance degradation making the application frustratingly slow. - - No straightforward workaround exists, or the workaround is difficult and non-obvious. - Qualifier: Is a key feature unusable or giving very wrong results? - Example: Gemini CLI enters a loop when making read-many-files tool call. I am unable to break out of the loop and gemini doesn't follow instructions subsequently. - P2: Medium - - A P2 bug is a moderately impactful issue. It's a noticeable problem but doesn't prevent the use of the software's main functionality. - Impact: - - Affects a non-critical feature or a smaller, specific subset of users. - - An inconvenient but functional workaround is available and easy to execute. - - Noticeable UI/UX problems that don't break functionality but look unprofessional (e.g., elements are misaligned or overlapping). - Qualifier: Is it an annoying but non-blocking problem? - Example: An error message is unclear or contains a typo, causing user confusion but not halting their workflow. - P3: Low - - A P3 bug is a minor, low-impact issue that is trivial or cosmetic. It has little to no effect on the overall functionality of the application. - Impact: - - Minor cosmetic issues like color inconsistencies, typos in documentation, or slight alignment problems on a non-critical page. - - An edge-case bug that is very difficult to reproduce and affects a tiny fraction of users. - Qualifier: Is it a "nice-to-fix" issue? - Example: Spelling mistakes etc. + + Categorization Guidelines (Priority): + P0 - Urgent Blocking Issues: + - DO NOT APPLY THIS LABEL AUTOMATICALLY. Use status/manual-triage instead. + - Definition: Urgent, block a significant percentage of the user base, and prevent frequent use of the Gemini CLI. + - This includes core stability blockers (e.g., authentication failures, broken upgrades), critical crashes, and P0 security vulnerabilities. + - Impact: Blocks development or testing for the entire team; Major security vulnerability; Causes data loss or corruption with no workaround; Crashes the application or makes a core feature completely unusable for all or most users. + - Qualifier: Is the main function of the software broken? + P1 - High-Impact Issues: + - Definition: Affect a large number of users, blocking them from using parts of the Gemini CLI, or make the CLI frequently unusable even with workarounds available. + - Impact: A core feature is broken or behaving incorrectly for a large number of users or use cases; Severe performance degradation; No straightforward workaround exists. + - Qualifier: Is a key feature unusable or giving very wrong results? + P2 - Significant Issues: + - Definition: Affect some users significantly, such as preventing the use of certain features or authentication types. + - Can also be issues that many users complain about, causing annoyance or hindering daily use. + - Impact: Affects a non-critical feature or a smaller, specific subset of users; An inconvenient but functional workaround is available; Noticeable UI/UX problems that look unprofessional. + - Qualifier: Is it an annoying but non-blocking problem? + P3 - Low-Impact Issues: + - Definition: Typically usability issues that cause annoyance to a limited user base. + - Includes feature requests that could be addressed in the near future and may be suitable for community contributions. + - Impact: Minor cosmetic issues; An edge-case bug that is very difficult to reproduce and affects a tiny fraction of users. + - Qualifier: Is it a "nice-to-fix" issue? + + Categorization Guidelines (Area): + area/agent: Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality + area/core: User Interface, OS Support, Core Functionality + area/enterprise: Telemetry, Policy, Quota / Licensing + area/extensions: Gemini CLI extensions capability + area/non-interactive: GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automation + area/platform: Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt + area/security: security related issues + Additional Context: - - If users are talking about issues where the model gets downgraded from pro to flash then i want you to categorize that as a performance issue - - This product is designed to use different models eg.. using pro, downgrading to flash etc. - - When users report that they dont expect the model to change those would be categorized as feature requests. + - If users are talking about issues where the model gets downgraded from pro to flash then i want you to categorize that as a performance issue. + - This product is designed to use different models eg.. using pro, downgrading to flash etc. + - When users report that they dont expect the model to change those would be categorized as feature requests. - name: 'Apply Labels to Issues' if: |- From 7e6817da5b892bc8015dc4313257509de07dbed7 Mon Sep 17 00:00:00 2001 From: Adrian Cole <64215+codefromthecrypt@users.noreply.github.com> Date: Thu, 15 Jan 2026 06:02:44 +0800 Subject: [PATCH 192/713] fix(acp): run exit cleanup when stdin closes (#14953) Signed-off-by: Adrian Cole Co-authored-by: Allen Hutchison Co-authored-by: Allen Hutchison --- integration-tests/acp-telemetry.test.ts | 116 ++++++++++++++++++ package-lock.json | 9 +- package.json | 1 + packages/cli/package.json | 2 +- .../cli/src/zed-integration/zedIntegration.ts | 8 +- packages/core/src/core/contentGenerator.ts | 6 +- 6 files changed, 133 insertions(+), 9 deletions(-) create mode 100644 integration-tests/acp-telemetry.test.ts diff --git a/integration-tests/acp-telemetry.test.ts b/integration-tests/acp-telemetry.test.ts new file mode 100644 index 0000000000..970239de9e --- /dev/null +++ b/integration-tests/acp-telemetry.test.ts @@ -0,0 +1,116 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; +import { TestRig } from './test-helper.js'; +import { spawn, ChildProcess } from 'node:child_process'; +import { join } from 'node:path'; +import { readFileSync, existsSync } from 'node:fs'; +import { Writable, Readable } from 'node:stream'; +import { env } from 'node:process'; +import * as acp from '@agentclientprotocol/sdk'; + +// Skip in sandbox mode - test spawns CLI directly which behaves differently in containers +const sandboxEnv = env['GEMINI_SANDBOX']; +const itMaybe = sandboxEnv && sandboxEnv !== 'false' ? it.skip : it; + +// Reuse existing fake responses that return a simple "Hello" response +const SIMPLE_RESPONSE_PATH = 'hooks-system.session-startup.responses'; + +class SessionUpdateCollector implements acp.Client { + updates: acp.SessionNotification[] = []; + + sessionUpdate = async (params: acp.SessionNotification) => { + this.updates.push(params); + }; + + requestPermission = async (): Promise => { + throw new Error('unexpected'); + }; +} + +describe('ACP telemetry', () => { + let rig: TestRig; + let child: ChildProcess | undefined; + + beforeEach(() => { + rig = new TestRig(); + }); + + afterEach(async () => { + child?.kill(); + child = undefined; + await rig.cleanup(); + }); + + itMaybe('should flush telemetry when connection closes', async () => { + rig.setup('acp-telemetry-flush', { + fakeResponsesPath: join(import.meta.dirname, SIMPLE_RESPONSE_PATH), + }); + + const telemetryPath = join(rig.homeDir!, 'telemetry.log'); + const bundlePath = join(import.meta.dirname, '..', 'bundle/gemini.js'); + + child = spawn( + 'node', + [ + bundlePath, + '--experimental-acp', + '--fake-responses', + join(rig.testDir!, 'fake-responses.json'), + ], + { + cwd: rig.testDir!, + stdio: ['pipe', 'pipe', 'inherit'], + env: { + ...process.env, + GEMINI_API_KEY: 'fake-key', + GEMINI_CLI_HOME: rig.homeDir!, + GEMINI_TELEMETRY_ENABLED: 'true', + GEMINI_TELEMETRY_TARGET: 'local', + GEMINI_TELEMETRY_OUTFILE: telemetryPath, + // GEMINI_DEV_TRACING not set: fake responses aren't instrumented for spans + }, + }, + ); + + const input = Writable.toWeb(child.stdin!); + const output = Readable.toWeb(child.stdout!) as ReadableStream; + const testClient = new SessionUpdateCollector(); + const stream = acp.ndJsonStream(input, output); + const connection = new acp.ClientSideConnection(() => testClient, stream); + + await connection.initialize({ + protocolVersion: acp.PROTOCOL_VERSION, + clientCapabilities: { fs: { readTextFile: false, writeTextFile: false } }, + }); + + const { sessionId } = await connection.newSession({ + cwd: rig.testDir!, + mcpServers: [], + }); + + await connection.prompt({ + sessionId, + prompt: [{ type: 'text', text: 'Say hello' }], + }); + + expect(JSON.stringify(testClient.updates)).toContain('Hello'); + + // Close stdin to trigger telemetry flush via runExitCleanup() + child.stdin!.end(); + await new Promise((resolve) => { + child!.on('close', () => resolve()); + }); + child = undefined; + + // gen_ai.output.messages is the last OTEL log emitted (after prompt response) + expect(existsSync(telemetryPath)).toBe(true); + expect(readFileSync(telemetryPath, 'utf-8')).toContain( + 'gen_ai.output.messages', + ); + }); +}); diff --git a/package-lock.json b/package-lock.json index 6fb8dad5a0..56b985c5e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "gemini": "bundle/gemini.js" }, "devDependencies": { + "@agentclientprotocol/sdk": "^0.12.0", "@octokit/rest": "^22.0.0", "@types/marked": "^5.0.2", "@types/mime-types": "^3.0.1", @@ -110,9 +111,9 @@ } }, "node_modules/@agentclientprotocol/sdk": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@agentclientprotocol/sdk/-/sdk-0.11.0.tgz", - "integrity": "sha512-hngnMwQ13DCC7oEr0BUnrx+vTDFf/ToCLhF0YcCMWRs+v4X60rKQyAENsx0PdbQF21jC1VjMFkh2+vwNBLh6fQ==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@agentclientprotocol/sdk/-/sdk-0.12.0.tgz", + "integrity": "sha512-V8uH/KK1t7utqyJmTA7y7DzKu6+jKFIXM+ZVouz8E55j8Ej2RV42rEvPKn3/PpBJlliI5crcGk1qQhZ7VwaepA==", "license": "Apache-2.0", "peerDependencies": { "zod": "^3.25.0 || ^4.0.0" @@ -18695,7 +18696,7 @@ "version": "0.26.0-nightly.20260114.bb6c57414", "license": "Apache-2.0", "dependencies": { - "@agentclientprotocol/sdk": "^0.11.0", + "@agentclientprotocol/sdk": "^0.12.0", "@google/gemini-cli-core": "file:../core", "@google/genai": "1.30.0", "@iarna/toml": "^2.2.5", diff --git a/package.json b/package.json index ff97e64715..e4602937ba 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "LICENSE" ], "devDependencies": { + "@agentclientprotocol/sdk": "^0.12.0", "@octokit/rest": "^22.0.0", "@types/marked": "^5.0.2", "@types/mime-types": "^3.0.1", diff --git a/packages/cli/package.json b/packages/cli/package.json index ea1737738e..2f8e5ec8c2 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -29,7 +29,7 @@ "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.26.0-nightly.20260114.bb6c57414" }, "dependencies": { - "@agentclientprotocol/sdk": "^0.11.0", + "@agentclientprotocol/sdk": "^0.12.0", "@google/gemini-cli-core": "file:../core", "@google/genai": "1.30.0", "@iarna/toml": "^2.2.5", diff --git a/packages/cli/src/zed-integration/zedIntegration.ts b/packages/cli/src/zed-integration/zedIntegration.ts index d4381efc0e..0d7d3262ac 100644 --- a/packages/cli/src/zed-integration/zedIntegration.ts +++ b/packages/cli/src/zed-integration/zedIntegration.ts @@ -44,6 +44,7 @@ import { z } from 'zod'; import { randomUUID } from 'node:crypto'; import type { CliArgs } from '../config/config.js'; import { loadCliConfig } from '../config/config.js'; +import { runExitCleanup } from '../utils/cleanup.js'; export async function runZedIntegration( config: Config, @@ -55,10 +56,15 @@ export async function runZedIntegration( const stdin = Readable.toWeb(process.stdin) as ReadableStream; const stream = acp.ndJsonStream(stdout, stdin); - new acp.AgentSideConnection( + const connection = new acp.AgentSideConnection( (connection) => new GeminiAgent(config, settings, argv, connection), stream, ); + + // SIGTERM/SIGINT handlers (in sdk.ts) don't fire when stdin closes. + // We must explicitly await the connection close to flush telemetry. + // Use finally() to ensure cleanup runs even on stream errors. + await connection.closed.finally(runExitCleanup); } export class GeminiAgent { diff --git a/packages/core/src/core/contentGenerator.ts b/packages/core/src/core/contentGenerator.ts index 12e07790cc..740bede47c 100644 --- a/packages/core/src/core/contentGenerator.ts +++ b/packages/core/src/core/contentGenerator.ts @@ -114,10 +114,10 @@ export async function createContentGenerator( ): Promise { const generator = await (async () => { if (gcConfig.fakeResponses) { - return new LoggingContentGenerator( - await FakeContentGenerator.fromFile(gcConfig.fakeResponses), - gcConfig, + const fakeGenerator = await FakeContentGenerator.fromFile( + gcConfig.fakeResponses, ); + return new LoggingContentGenerator(fakeGenerator, gcConfig); } const version = await getVersion(); const model = resolveModel( From 6021e4c3baed2e1d9ff2c40d6e8ac8a13c1d9beb Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Wed, 14 Jan 2026 17:22:44 -0500 Subject: [PATCH 193/713] feat(scheduler): add types needed for event driven scheduler (#16641) --- packages/a2a-server/src/agent/task.ts | 6 +- packages/cli/src/ui/hooks/useGeminiStream.ts | 11 ++-- .../cli/src/ui/hooks/useReactToolScheduler.ts | 4 +- packages/core/src/confirmation-bus/types.ts | 57 ++++++++++++++++++- .../core/src/core/coreToolScheduler.test.ts | 28 ++++----- packages/core/src/scheduler/types.ts | 14 ++++- 6 files changed, 98 insertions(+), 22 deletions(-) diff --git a/packages/a2a-server/src/agent/task.ts b/packages/a2a-server/src/agent/task.ts index 7bf5e5ad4c..c82e9e6992 100644 --- a/packages/a2a-server/src/agent/task.ts +++ b/packages/a2a-server/src/agent/task.ts @@ -378,7 +378,7 @@ export class Task { if (tc.status === 'awaiting_approval' && tc.confirmationDetails) { this.pendingToolConfirmationDetails.set( tc.request.callId, - tc.confirmationDetails, + tc.confirmationDetails as ToolCallConfirmationDetails, ); } @@ -412,7 +412,9 @@ export class Task { toolCalls.forEach((tc: ToolCall) => { if (tc.status === 'awaiting_approval' && tc.confirmationDetails) { // eslint-disable-next-line @typescript-eslint/no-floating-promises - tc.confirmationDetails.onConfirm(ToolConfirmationOutcome.ProceedOnce); + (tc.confirmationDetails as ToolCallConfirmationDetails).onConfirm( + ToolConfirmationOutcome.ProceedOnce, + ); this.pendingToolConfirmationDetails.delete(tc.request.callId); } }); diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index ab88962047..21add85556 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -43,6 +43,7 @@ import type { ToolCallRequestInfo, GeminiErrorEventValue, RetryAttemptPayload, + ToolCallConfirmationDetails, } from '@google/gemini-cli-core'; import { type Part, type PartListUnion, FinishReason } from '@google/genai'; import type { @@ -1132,11 +1133,13 @@ export const useGeminiStream = ( // Process pending tool calls sequentially to reduce UI chaos for (const call of awaitingApprovalCalls) { - if (call.confirmationDetails?.onConfirm) { + if ( + (call.confirmationDetails as ToolCallConfirmationDetails)?.onConfirm + ) { try { - await call.confirmationDetails.onConfirm( - ToolConfirmationOutcome.ProceedOnce, - ); + await ( + call.confirmationDetails as ToolCallConfirmationDetails + ).onConfirm(ToolConfirmationOutcome.ProceedOnce); } catch (error) { debugLogger.warn( `Failed to auto-approve tool call ${call.request.callId}:`, diff --git a/packages/cli/src/ui/hooks/useReactToolScheduler.ts b/packages/cli/src/ui/hooks/useReactToolScheduler.ts index af32b18288..8939f5aa80 100644 --- a/packages/cli/src/ui/hooks/useReactToolScheduler.ts +++ b/packages/cli/src/ui/hooks/useReactToolScheduler.ts @@ -17,6 +17,7 @@ import type { AllToolCallsCompleteHandler, ToolCallsUpdateHandler, ToolCall, + ToolCallConfirmationDetails, Status as CoreStatus, EditorType, } from '@google/gemini-cli-core'; @@ -306,7 +307,8 @@ export function mapToDisplay( ...baseDisplayProperties, status: mapCoreStatusToDisplayStatus(trackedCall.status), resultDisplay: undefined, - confirmationDetails: trackedCall.confirmationDetails, + confirmationDetails: + trackedCall.confirmationDetails as ToolCallConfirmationDetails, }; case 'executing': return { diff --git a/packages/core/src/confirmation-bus/types.ts b/packages/core/src/confirmation-bus/types.ts index a26b786701..d9caa9c5c2 100644 --- a/packages/core/src/confirmation-bus/types.ts +++ b/packages/core/src/confirmation-bus/types.ts @@ -5,6 +5,11 @@ */ import { type FunctionCall } from '@google/genai'; +import type { + ToolConfirmationOutcome, + ToolConfirmationPayload, +} from '../tools/tools.js'; +import type { ToolCall } from '../scheduler/types.js'; export enum MessageBusType { TOOL_CONFIRMATION_REQUEST = 'tool-confirmation-request', @@ -16,6 +21,12 @@ export enum MessageBusType { HOOK_EXECUTION_REQUEST = 'hook-execution-request', HOOK_EXECUTION_RESPONSE = 'hook-execution-response', HOOK_POLICY_DECISION = 'hook-policy-decision', + TOOL_CALLS_UPDATE = 'tool-calls-update', +} + +export interface ToolCallsUpdateMessage { + type: MessageBusType.TOOL_CALLS_UPDATE; + toolCalls: ToolCall[]; } export interface ToolConfirmationRequest { @@ -23,12 +34,26 @@ export interface ToolConfirmationRequest { toolCall: FunctionCall; correlationId: string; serverName?: string; + /** + * Optional rich details for the confirmation UI (diffs, counts, etc.) + */ + details?: SerializableConfirmationDetails; } export interface ToolConfirmationResponse { type: MessageBusType.TOOL_CONFIRMATION_RESPONSE; correlationId: string; confirmed: boolean; + /** + * The specific outcome selected by the user. + * + * TODO: Make required after migration. + */ + outcome?: ToolConfirmationOutcome; + /** + * Optional payload (e.g., modified content for 'modify_with_editor'). + */ + payload?: ToolConfirmationPayload; /** * When true, indicates that policy decision was ASK_USER and the tool should * show its legacy confirmation UI instead of auto-proceeding. @@ -36,6 +61,35 @@ export interface ToolConfirmationResponse { requiresUserConfirmation?: boolean; } +/** + * Data-only versions of ToolCallConfirmationDetails for bus transmission. + */ +export type SerializableConfirmationDetails = + | { type: 'info'; title: string; prompt: string; urls?: string[] } + | { + type: 'edit'; + title: string; + fileName: string; + filePath: string; + fileDiff: string; + originalContent: string | null; + newContent: string; + } + | { + type: 'exec'; + title: string; + command: string; + rootCommand: string; + rootCommands: string[]; + } + | { + type: 'mcp'; + title: string; + serverName: string; + toolName: string; + toolDisplayName: string; + }; + export interface UpdatePolicy { type: MessageBusType.UPDATE_POLICY; toolName: string; @@ -94,4 +148,5 @@ export type Message = | UpdatePolicy | HookExecutionRequest | HookExecutionResponse - | HookPolicyDecision; + | HookPolicyDecision + | ToolCallsUpdateMessage; diff --git a/packages/core/src/core/coreToolScheduler.test.ts b/packages/core/src/core/coreToolScheduler.test.ts index 90b8ea7938..1497f7ac02 100644 --- a/packages/core/src/core/coreToolScheduler.test.ts +++ b/packages/core/src/core/coreToolScheduler.test.ts @@ -547,9 +547,9 @@ describe('CoreToolScheduler', () => { )) as WaitingToolCall; // Cancel the first tool via its confirmation handler - await awaitingCall.confirmationDetails.onConfirm( - ToolConfirmationOutcome.Cancel, - ); + const confirmationDetails = + awaitingCall.confirmationDetails as ToolCallConfirmationDetails; + await confirmationDetails.onConfirm(ToolConfirmationOutcome.Cancel); abortController.abort(); // User cancelling often involves an abort signal await vi.waitFor(() => { @@ -749,7 +749,7 @@ describe('CoreToolScheduler with payload', () => { if (confirmationDetails) { const payload: ToolConfirmationPayload = { newContent: 'final version' }; - await confirmationDetails.onConfirm( + await (confirmationDetails as ToolCallConfirmationDetails).onConfirm( ToolConfirmationOutcome.ProceedOnce, payload, ); @@ -762,9 +762,9 @@ describe('CoreToolScheduler with payload', () => { )) as WaitingToolCall; // Now confirm for real to execute. - await updatedAwaitingCall.confirmationDetails.onConfirm( - ToolConfirmationOutcome.ProceedOnce, - ); + await ( + updatedAwaitingCall.confirmationDetails as ToolCallConfirmationDetails + ).onConfirm(ToolConfirmationOutcome.ProceedOnce); // Wait for the tool execution to complete await vi.waitFor(() => { @@ -897,7 +897,9 @@ describe('CoreToolScheduler edit cancellation', () => { // Cancel the edit const confirmationDetails = awaitingCall.confirmationDetails; if (confirmationDetails) { - await confirmationDetails.onConfirm(ToolConfirmationOutcome.Cancel); + await (confirmationDetails as ToolCallConfirmationDetails).onConfirm( + ToolConfirmationOutcome.Cancel, + ); } expect(onAllToolCallsComplete).toHaveBeenCalled(); @@ -1447,14 +1449,14 @@ describe('CoreToolScheduler request queueing', () => { toolCalls.forEach((call) => { if (call.status === 'awaiting_approval') { const waitingCall = call; - if (waitingCall.confirmationDetails?.onConfirm) { + const details = + waitingCall.confirmationDetails as ToolCallConfirmationDetails; + if (details?.onConfirm) { const originalHandler = pendingConfirmations.find( - (h) => h === waitingCall.confirmationDetails.onConfirm, + (h) => h === details.onConfirm, ); if (!originalHandler) { - pendingConfirmations.push( - waitingCall.confirmationDetails.onConfirm, - ); + pendingConfirmations.push(details.onConfirm); } } } diff --git a/packages/core/src/scheduler/types.ts b/packages/core/src/scheduler/types.ts index 3a43a47704..2f2baf77e3 100644 --- a/packages/core/src/scheduler/types.ts +++ b/packages/core/src/scheduler/types.ts @@ -14,6 +14,7 @@ import type { } from '../tools/tools.js'; import type { AnsiOutput } from '../utils/terminalSerializer.js'; import type { ToolErrorType } from '../tools/tool-error.js'; +import type { SerializableConfirmationDetails } from '../confirmation-bus/types.js'; export interface ToolCallRequestInfo { callId: string; @@ -98,7 +99,18 @@ export type WaitingToolCall = { request: ToolCallRequestInfo; tool: AnyDeclarativeTool; invocation: AnyToolInvocation; - confirmationDetails: ToolCallConfirmationDetails; + /** + * Supports both legacy (with callbacks) and new (serializable) details. + * New code should treat this as SerializableConfirmationDetails. + * + * TODO: Remove ToolCallConfirmationDetails and collapse to just + * SerializableConfirmationDetails after migration. + */ + confirmationDetails: + | ToolCallConfirmationDetails + | SerializableConfirmationDetails; + // TODO: Make required after migration. + correlationId?: string; startTime?: number; outcome?: ToolConfirmationOutcome; }; From 5ed275ce39d5e06a989df710c50e77d6f26358fc Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Wed, 14 Jan 2026 14:46:33 -0800 Subject: [PATCH 194/713] Remove unused rewind key binding (#16659) --- docs/cli/keyboard-shortcuts.md | 1 - packages/cli/src/config/keyBindings.ts | 4 ---- 2 files changed, 5 deletions(-) diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index b90954a31a..8cb87a1048 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -64,7 +64,6 @@ available combinations. | Start reverse search through history. | `Ctrl + R` | | Submit the selected reverse-search match. | `Enter (no Ctrl)` | | Accept a suggestion while reverse searching. | `Tab` | -| Browse and rewind previous interactions. | `Esc (×2)` | #### Navigation diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index d888c1046e..80a889ddb9 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -76,7 +76,6 @@ export enum Command { QUIT = 'quit', EXIT = 'exit', SHOW_MORE_LINES = 'showMoreLines', - REWIND = 'rewind', // Shell commands REVERSE_SEARCH = 'reverseSearch', @@ -255,7 +254,6 @@ export const defaultKeyBindings: KeyBindingConfig = { // Suggestion expansion [Command.EXPAND_SUGGESTION]: [{ key: 'right' }], [Command.COLLAPSE_SUGGESTION]: [{ key: 'left' }], - [Command.REWIND]: [{ key: 'Esc (×2)' }], }; interface CommandCategory { @@ -319,7 +317,6 @@ export const commandCategories: readonly CommandCategory[] = [ Command.REVERSE_SEARCH, Command.SUBMIT_REVERSE_SEARCH, Command.ACCEPT_SUGGESTION_REVERSE_SEARCH, - Command.REWIND, ], }, { @@ -432,5 +429,4 @@ export const commandDescriptions: Readonly> = { [Command.UNFOCUS_SHELL_INPUT]: 'Focus the Gemini input from the shell input.', [Command.EXPAND_SUGGESTION]: 'Expand an inline suggestion.', [Command.COLLAPSE_SUGGESTION]: 'Collapse an inline suggestion.', - [Command.REWIND]: 'Browse and rewind previous interactions.', }; From fb7640886ba428f5056cfc222fb5c636aa0a6639 Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Wed, 14 Jan 2026 15:09:09 -0800 Subject: [PATCH 195/713] Remove sequence binding (#16664) --- packages/cli/src/config/keyBindings.test.ts | 9 +++---- packages/cli/src/config/keyBindings.ts | 9 ++----- packages/cli/src/ui/keyMatchers.test.ts | 5 +--- packages/cli/src/ui/keyMatchers.ts | 14 +--------- scripts/generate-keybindings-doc.ts | 30 ++------------------- 5 files changed, 9 insertions(+), 58 deletions(-) diff --git a/packages/cli/src/config/keyBindings.test.ts b/packages/cli/src/config/keyBindings.test.ts index d8c83024f5..018394f80c 100644 --- a/packages/cli/src/config/keyBindings.test.ts +++ b/packages/cli/src/config/keyBindings.test.ts @@ -28,12 +28,9 @@ describe('keyBindings config', () => { it('should have valid key binding structures', () => { for (const [_, bindings] of Object.entries(defaultKeyBindings)) { for (const binding of bindings) { - // Each binding should have either key or sequence, but not both - const hasKey = binding.key !== undefined; - const hasSequence = binding.sequence !== undefined; - - expect(hasKey || hasSequence).toBe(true); - expect(hasKey && hasSequence).toBe(false); + // Each binding must have a key name + expect(typeof binding.key).toBe('string'); + expect(binding.key.length).toBeGreaterThan(0); // Modifier properties should be boolean or undefined if (binding.ctrl !== undefined) { diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index 80a889ddb9..b420ab0ef2 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -94,9 +94,7 @@ export enum Command { */ export interface KeyBinding { /** The key name (e.g., 'a', 'return', 'tab', 'escape') */ - key?: string; - /** The key sequence (e.g., '\x18' for Ctrl+X) - alternative to key name */ - sequence?: string; + key: string; /** Control key requirement: true=must be pressed, false=must not be pressed, undefined=ignore */ ctrl?: boolean; /** Shift key requirement: true=must be pressed, false=must not be pressed, undefined=ignore */ @@ -221,10 +219,7 @@ export const defaultKeyBindings: KeyBindingConfig = { ], // External tools - [Command.OPEN_EXTERNAL_EDITOR]: [ - { key: 'x', ctrl: true }, - { sequence: '\x18', ctrl: true }, - ], + [Command.OPEN_EXTERNAL_EDITOR]: [{ key: 'x', ctrl: true }], [Command.PASTE_CLIPBOARD]: [ { key: 'v', ctrl: true }, { key: 'v', command: true }, diff --git a/packages/cli/src/ui/keyMatchers.test.ts b/packages/cli/src/ui/keyMatchers.test.ts index 670f84a87b..e8d9da4434 100644 --- a/packages/cli/src/ui/keyMatchers.test.ts +++ b/packages/cli/src/ui/keyMatchers.test.ts @@ -256,10 +256,7 @@ describe('keyMatchers', () => { // External tools { command: Command.OPEN_EXTERNAL_EDITOR, - positive: [ - createKey('x', { ctrl: true }), - { ...createKey('\x18'), sequence: '\x18', ctrl: true }, - ], + positive: [createKey('x', { ctrl: true })], negative: [createKey('x'), createKey('c', { ctrl: true })], }, { diff --git a/packages/cli/src/ui/keyMatchers.ts b/packages/cli/src/ui/keyMatchers.ts index b12160dbb6..73636130be 100644 --- a/packages/cli/src/ui/keyMatchers.ts +++ b/packages/cli/src/ui/keyMatchers.ts @@ -13,19 +13,7 @@ import { Command, defaultKeyBindings } from '../config/keyBindings.js'; * Pure data-driven matching logic */ function matchKeyBinding(keyBinding: KeyBinding, key: Key): boolean { - // Either key name or sequence must match (but not both should be defined) - let keyMatches = false; - - if (keyBinding.key !== undefined) { - keyMatches = keyBinding.key === key.name; - } else if (keyBinding.sequence !== undefined) { - keyMatches = keyBinding.sequence === key.sequence; - } else { - // Neither key nor sequence defined - invalid binding - return false; - } - - if (!keyMatches) { + if (keyBinding.key !== key.name) { return false; } diff --git a/scripts/generate-keybindings-doc.ts b/scripts/generate-keybindings-doc.ts index 13f195aca8..4c2e6c4618 100644 --- a/scripts/generate-keybindings-doc.ts +++ b/scripts/generate-keybindings-doc.ts @@ -157,14 +157,8 @@ function formatBinding(binding: KeyBinding): string { if (binding.ctrl) modifiers.push('Ctrl'); if (binding.command) modifiers.push('Cmd'); if (binding.shift) modifiers.push('Shift'); - if (binding.paste) modifiers.push('Paste'); - - const keyName = binding.key - ? formatKeyName(binding.key) - : binding.sequence - ? formatSequence(binding.sequence) - : ''; + const keyName = formatKeyName(binding.key); if (!keyName) { return ''; } @@ -176,7 +170,6 @@ function formatBinding(binding: KeyBinding): string { if (binding.ctrl === false) restrictions.push('no Ctrl'); if (binding.shift === false) restrictions.push('no Shift'); if (binding.command === false) restrictions.push('no Cmd'); - if (binding.paste === false) restrictions.push('not Paste'); if (restrictions.length > 0) { combo = `${combo} (${restrictions.join(', ')})`; @@ -190,26 +183,7 @@ function formatKeyName(key: string): string { if (KEY_NAME_OVERRIDES[normalized]) { return KEY_NAME_OVERRIDES[normalized]; } - if (key.length === 1) { - return key.toUpperCase(); - } - return key; -} - -function formatSequence(sequence: string): string { - if (sequence.length === 1) { - const code = sequence.charCodeAt(0); - if (code >= 1 && code <= 26) { - return String.fromCharCode(code + 64); - } - if (code === 10 || code === 13) { - return 'Enter'; - } - if (code === 9) { - return 'Tab'; - } - } - return JSON.stringify(sequence); + return key.length === 1 ? key.toUpperCase() : key; } if (process.argv[1]) { From a2dab146b97f5ed9dce0f4aa6b30b8fd2f08a215 Mon Sep 17 00:00:00 2001 From: Alex Austin Chettiar <75135556+alexaustin007@users.noreply.github.com> Date: Thu, 15 Jan 2026 04:39:27 +0530 Subject: [PATCH 196/713] feat(cli): undeprecate the --prompt flag (#13981) Co-authored-by: Allen Hutchison --- packages/cli/src/config/config.ts | 6 +-- packages/cli/src/gemini.tsx | 4 -- packages/cli/src/nonInteractiveCli.test.ts | 52 ---------------------- packages/cli/src/nonInteractiveCli.ts | 17 ------- 4 files changed, 1 insertion(+), 78 deletions(-) diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index beccbfa0a9..40601eea1c 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -242,11 +242,7 @@ export async function parseArguments(settings: Settings): Promise { type: 'string', description: 'Path to a file to record model responses for testing.', hidden: true, - }) - .deprecateOption( - 'prompt', - 'Use the positional prompt instead. This flag will be removed in a future version.', - ), + }), ) // Register MCP subcommands .command(mcpCommand) diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index 741632af85..3f808c20b7 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -689,9 +689,6 @@ export async function main() { debugLogger.log('Session ID: %s', sessionId); } - const hasDeprecatedPromptArg = process.argv.some((arg) => - arg.startsWith('--prompt'), - ); initializeOutputListenersAndFlush(); await runNonInteractive({ @@ -699,7 +696,6 @@ export async function main() { settings, input, prompt_id, - hasDeprecatedPromptArg, resumedSessionData, }); // Call cleanup before process.exit, which causes cleanup to not run diff --git a/packages/cli/src/nonInteractiveCli.test.ts b/packages/cli/src/nonInteractiveCli.test.ts index c4ce96452a..8a05ac1178 100644 --- a/packages/cli/src/nonInteractiveCli.test.ts +++ b/packages/cli/src/nonInteractiveCli.test.ts @@ -1418,58 +1418,6 @@ describe('runNonInteractive', () => { }); }); - it('should display a deprecation warning if hasDeprecatedPromptArg is true', async () => { - const events: ServerGeminiStreamEvent[] = [ - { type: GeminiEventType.Content, value: 'Final Answer' }, - { - type: GeminiEventType.Finished, - value: { reason: undefined, usageMetadata: { totalTokenCount: 10 } }, - }, - ]; - mockGeminiClient.sendMessageStream.mockReturnValue( - createStreamFromEvents(events), - ); - - await runNonInteractive({ - config: mockConfig, - settings: mockSettings, - input: 'Test input', - prompt_id: 'prompt-id-deprecated', - hasDeprecatedPromptArg: true, - }); - - expect(processStderrSpy).toHaveBeenCalledWith( - 'The --prompt (-p) flag has been deprecated and will be removed in a future version. Please use a positional argument for your prompt. See gemini --help for more information.\n', - ); - expect(processStdoutSpy).toHaveBeenCalledWith('Final Answer'); - }); - - it('should display a deprecation warning for JSON format', async () => { - const events: ServerGeminiStreamEvent[] = [ - { type: GeminiEventType.Content, value: 'Final Answer' }, - { - type: GeminiEventType.Finished, - value: { reason: undefined, usageMetadata: { totalTokenCount: 10 } }, - }, - ]; - mockGeminiClient.sendMessageStream.mockReturnValue( - createStreamFromEvents(events), - ); - vi.mocked(mockConfig.getOutputFormat).mockReturnValue(OutputFormat.JSON); - - await runNonInteractive({ - config: mockConfig, - settings: mockSettings, - input: 'Test input', - prompt_id: 'prompt-id-deprecated-json', - hasDeprecatedPromptArg: true, - }); - - const deprecateText = - 'The --prompt (-p) flag has been deprecated and will be removed in a future version. Please use a positional argument for your prompt. See gemini --help for more information.\n'; - expect(processStderrSpy).toHaveBeenCalledWith(deprecateText); - }); - it('should emit appropriate events for streaming JSON output', async () => { vi.mocked(mockConfig.getOutputFormat).mockReturnValue( OutputFormat.STREAM_JSON, diff --git a/packages/cli/src/nonInteractiveCli.ts b/packages/cli/src/nonInteractiveCli.ts index 7830798dd5..8eac2f61d3 100644 --- a/packages/cli/src/nonInteractiveCli.ts +++ b/packages/cli/src/nonInteractiveCli.ts @@ -51,7 +51,6 @@ interface RunNonInteractiveParams { settings: LoadedSettings; input: string; prompt_id: string; - hasDeprecatedPromptArg?: boolean; resumedSessionData?: ResumedSessionData; } @@ -60,7 +59,6 @@ export async function runNonInteractive({ settings, input, prompt_id, - hasDeprecatedPromptArg, resumedSessionData, }: RunNonInteractiveParams): Promise { return promptIdContext.run(prompt_id, async () => { @@ -264,21 +262,6 @@ export async function runNonInteractive({ let currentMessages: Content[] = [{ role: 'user', parts: query }]; let turnCount = 0; - const deprecateText = - 'The --prompt (-p) flag has been deprecated and will be removed in a future version. Please use a positional argument for your prompt. See gemini --help for more information.\n'; - if (hasDeprecatedPromptArg) { - if (streamFormatter) { - streamFormatter.emitEvent({ - type: JsonStreamEventType.MESSAGE, - timestamp: new Date().toISOString(), - role: 'assistant', - content: deprecateText, - delta: true, - }); - } else { - process.stderr.write(deprecateText); - } - } while (true) { turnCount++; if ( From b3527dc9e4ae15ae4637e51814d3e2f79a3f6b76 Mon Sep 17 00:00:00 2001 From: Patrick Schimpl <115887603+cosmopax@users.noreply.github.com> Date: Thu, 15 Jan 2026 01:02:54 +0100 Subject: [PATCH 197/713] chore: update dependabot configuration (#13507) Co-authored-by: Tommaso Sciortino --- .github/dependabot.yml | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c5d37a5d1f..92b0732f13 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,35 +1,33 @@ -# See https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file version: 2 updates: - package-ecosystem: 'npm' directory: '/' schedule: - interval: 'daily' - target-branch: 'main' - commit-message: - prefix: 'chore(deps)' - include: 'scope' + interval: 'weekly' + day: 'monday' + open-pull-requests-limit: 10 reviewers: - - 'google-gemini/gemini-cli-askmode-approvers' + - 'joshualitt' groups: - # Group all non-major updates together. - # This is to reduce the number of PRs that need to be reviewed. - # Major updates will still be created as separate PRs. - npm-minor-patch: - applies-to: 'version-updates' + npm-dependencies: + patterns: + - '*' update-types: - 'minor' - 'patch' - open-pull-requests-limit: 0 - package-ecosystem: 'github-actions' directory: '/' schedule: - interval: 'daily' - target-branch: 'main' - commit-message: - prefix: 'chore(deps)' - include: 'scope' + interval: 'weekly' + day: 'monday' + open-pull-requests-limit: 10 reviewers: - - 'google-gemini/gemini-cli-askmode-approvers' - open-pull-requests-limit: 0 + - 'joshualitt' + groups: + actions-dependencies: + patterns: + - '*' + update-types: + - 'minor' + - 'patch' From e58fca68ceb33f8540826fe973a5d8d0665c0145 Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Wed, 14 Jan 2026 19:07:51 -0500 Subject: [PATCH 198/713] feat(config): add 'auto' alias for default model selection (#16661) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/cli/src/config/config.test.ts | 14 ++++++++++++++ packages/cli/src/config/config.ts | 12 +++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/config/config.test.ts b/packages/cli/src/config/config.test.ts index d3040aabf0..78a4847fd2 100644 --- a/packages/cli/src/config/config.test.ts +++ b/packages/cli/src/config/config.test.ts @@ -1313,6 +1313,20 @@ describe('loadCliConfig model selection', () => { expect(config.getModel()).toBe('gemini-2.5-flash-preview'); }); + + it('selects the default auto model if provided via auto alias', async () => { + process.argv = ['node', 'script.js', '--model', 'auto']; + const argv = await parseArguments({} as Settings); + const config = await loadCliConfig( + { + // No model provided via settings. + }, + 'test-session', + argv, + ); + + expect(config.getModel()).toBe('auto-gemini-2.5'); + }); }); describe('loadCliConfig folderTrust', () => { diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 40601eea1c..fc21e43fce 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -36,6 +36,7 @@ import { type HookDefinition, type HookEventName, type OutputFormat, + GEMINI_MODEL_ALIAS_AUTO, } from '@google/gemini-cli-core'; import type { Settings } from './settings.js'; import { saveModelChange, loadSettings } from './settings.js'; @@ -617,12 +618,13 @@ export async function loadCliConfig( const defaultModel = settings.general?.previewFeatures ? PREVIEW_GEMINI_MODEL_AUTO : DEFAULT_GEMINI_MODEL_AUTO; - const resolvedModel: string = - argv.model || - process.env['GEMINI_MODEL'] || - settings.model?.name || - defaultModel; + const specifiedModel = + argv.model || process.env['GEMINI_MODEL'] || settings.model?.name; + const resolvedModel = + specifiedModel === GEMINI_MODEL_ALIAS_AUTO + ? defaultModel + : specifiedModel || defaultModel; const sandboxConfig = await loadSandboxConfig(settings, argv); const screenReader = argv.screenReader !== undefined From 42c26d1e1b274ff88aa340a2330bc8f4decfa6ba Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Wed, 14 Jan 2026 16:30:07 -0800 Subject: [PATCH 199/713] cleanup: Improve keybindings (#16672) --- docs/cli/keyboard-shortcuts.md | 2 ++ packages/cli/src/config/keyBindings.ts | 8 ++++++ .../src/ui/components/shared/text-buffer.ts | 26 ++++--------------- .../src/ui/contexts/KeypressContext.test.tsx | 2 +- .../cli/src/ui/contexts/KeypressContext.tsx | 2 +- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index 8cb87a1048..16a4083584 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -19,6 +19,8 @@ available combinations. | ------------------------------------------- | ------------------------------------------------------------ | | Move the cursor to the start of the line. | `Ctrl + A`
`Home` | | Move the cursor to the end of the line. | `Ctrl + E`
`End` | +| Move the cursor up one line. | `Up Arrow (no Ctrl, no Cmd)` | +| Move the cursor down one line. | `Down Arrow (no Ctrl, no Cmd)` | | Move the cursor one character to the left. | `Left Arrow (no Ctrl, no Cmd)`
`Ctrl + B` | | Move the cursor one character to the right. | `Right Arrow (no Ctrl, no Cmd)`
`Ctrl + F` | | Move the cursor one word to the left. | `Ctrl + Left Arrow`
`Cmd + Left Arrow`
`Cmd + B` | diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index b420ab0ef2..b101ae489e 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -66,6 +66,8 @@ export enum Command { TOGGLE_AUTO_EDIT = 'toggleAutoEdit', UNDO = 'undo', REDO = 'redo', + MOVE_UP = 'moveUp', + MOVE_DOWN = 'moveDown', MOVE_LEFT = 'moveLeft', MOVE_RIGHT = 'moveRight', MOVE_WORD_LEFT = 'moveWordLeft', @@ -141,6 +143,8 @@ export const defaultKeyBindings: KeyBindingConfig = { { key: 'right', ctrl: false, command: false }, { key: 'f', ctrl: true }, ], + [Command.MOVE_UP]: [{ key: 'up', ctrl: false, command: false }], + [Command.MOVE_DOWN]: [{ key: 'down', ctrl: false, command: false }], [Command.MOVE_WORD_LEFT]: [ { key: 'left', ctrl: true }, { key: 'left', command: true }, @@ -269,6 +273,8 @@ export const commandCategories: readonly CommandCategory[] = [ commands: [ Command.HOME, Command.END, + Command.MOVE_UP, + Command.MOVE_DOWN, Command.MOVE_LEFT, Command.MOVE_RIGHT, Command.MOVE_WORD_LEFT, @@ -372,6 +378,8 @@ export const commandDescriptions: Readonly> = { [Command.END]: 'Move the cursor to the end of the line.', [Command.MOVE_LEFT]: 'Move the cursor one character to the left.', [Command.MOVE_RIGHT]: 'Move the cursor one character to the right.', + [Command.MOVE_UP]: 'Move the cursor up one line.', + [Command.MOVE_DOWN]: 'Move the cursor down one line.', [Command.MOVE_WORD_LEFT]: 'Move the cursor one word to the left.', [Command.MOVE_WORD_RIGHT]: 'Move the cursor one word to the right.', [Command.KILL_LINE_RIGHT]: 'Delete from the cursor to the end of the line.', diff --git a/packages/cli/src/ui/components/shared/text-buffer.ts b/packages/cli/src/ui/components/shared/text-buffer.ts index 9ef6fdec83..a80d088bf2 100644 --- a/packages/cli/src/ui/components/shared/text-buffer.ts +++ b/packages/cli/src/ui/components/shared/text-buffer.ts @@ -2223,25 +2223,12 @@ export function useTextBuffer({ (key: Key): void => { const { sequence: input } = key; - if (key.name === 'paste') { - // Do not do any other processing on pastes so ensure we handle them - // before all other cases. - insert(input, { paste: true }); - return; - } - - if ( - !singleLine && - (key.name === 'return' || - input === '\r' || - input === '\n' || - input === '\\r') // VSCode terminal represents shift + enter this way - ) - newline(); + if (key.name === 'paste') insert(input, { paste: true }); + else if (keyMatchers[Command.RETURN](key)) newline(); else if (keyMatchers[Command.MOVE_LEFT](key)) move('left'); else if (keyMatchers[Command.MOVE_RIGHT](key)) move('right'); - else if (key.name === 'up') move('up'); - else if (key.name === 'down') move('down'); + else if (keyMatchers[Command.MOVE_UP](key)) move('up'); + else if (keyMatchers[Command.MOVE_DOWN](key)) move('down'); else if (keyMatchers[Command.MOVE_WORD_LEFT](key)) move('wordLeft'); else if (keyMatchers[Command.MOVE_WORD_RIGHT](key)) move('wordRight'); else if (keyMatchers[Command.HOME](key)) move('home'); @@ -2252,9 +2239,7 @@ export function useTextBuffer({ else if (keyMatchers[Command.DELETE_CHAR_RIGHT](key)) del(); else if (keyMatchers[Command.UNDO](key)) undo(); else if (keyMatchers[Command.REDO](key)) redo(); - else if (key.insertable) { - insert(input, { paste: false }); - } + else if (key.insertable) insert(input, { paste: false }); }, [ newline, @@ -2266,7 +2251,6 @@ export function useTextBuffer({ insert, undo, redo, - singleLine, ], ); diff --git a/packages/cli/src/ui/contexts/KeypressContext.test.tsx b/packages/cli/src/ui/contexts/KeypressContext.test.tsx index 24cadfa85c..af707fff69 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.test.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.test.tsx @@ -179,7 +179,7 @@ describe('KeypressContext', () => { expect(keyHandler).toHaveBeenLastCalledWith( expect.objectContaining({ - name: '', + name: 'return', sequence: '\r', insertable: true, }), diff --git a/packages/cli/src/ui/contexts/KeypressContext.tsx b/packages/cli/src/ui/contexts/KeypressContext.tsx index df59356990..4fc774a00b 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.tsx @@ -157,7 +157,7 @@ function bufferFastReturn(keypressHandler: KeypressHandler): KeypressHandler { if (key.name === 'return' && now - lastKeyTime <= FAST_RETURN_TIMEOUT) { keypressHandler({ ...key, - name: '', + name: 'return', sequence: '\r', insertable: true, }); From 4b2e9f79545c8b00c18395c3555e29600ef5809c Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Wed, 14 Jan 2026 19:30:17 -0500 Subject: [PATCH 200/713] Enable & disable agents (#16225) --- packages/cli/src/config/config.ts | 4 +- .../cli/src/ui/commands/agentsCommand.test.ts | 201 ++++++++++++++++- packages/cli/src/ui/commands/agentsCommand.ts | 208 +++++++++++++++++- packages/cli/src/utils/agentSettings.ts | 150 +++++++++++++ packages/cli/src/utils/agentUtils.test.ts | 150 +++++++++++++ packages/cli/src/utils/agentUtils.ts | 65 ++++++ .../core/src/agents/a2a-client-manager.ts | 2 +- packages/core/src/agents/registry.ts | 17 +- packages/core/src/config/config.ts | 16 +- 9 files changed, 800 insertions(+), 13 deletions(-) create mode 100644 packages/cli/src/utils/agentSettings.ts create mode 100644 packages/cli/src/utils/agentUtils.test.ts create mode 100644 packages/cli/src/utils/agentUtils.ts diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index fc21e43fce..137e01d943 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -708,7 +708,6 @@ export async function loadCliConfig( enableAgents: settings.experimental?.enableAgents, skillsSupport: settings.experimental?.skills, disabledSkills: settings.skills?.disabled, - experimentalJitContext: settings.experimental?.jitContext, noBrowser: !!process.env['NO_BROWSER'], summarizeToolOutput: settings.model?.summarizeToolOutput, @@ -751,8 +750,7 @@ export async function loadCliConfig( const refreshedSettings = loadSettings(cwd); return { disabledSkills: refreshedSettings.merged.skills?.disabled, - adminSkillsEnabled: - refreshedSettings.merged.admin?.skills?.enabled ?? adminSkillsEnabled, + agents: refreshedSettings.merged.agents, }; }, }); diff --git a/packages/cli/src/ui/commands/agentsCommand.test.ts b/packages/cli/src/ui/commands/agentsCommand.test.ts index bc84252cf2..f126ddd8ee 100644 --- a/packages/cli/src/ui/commands/agentsCommand.test.ts +++ b/packages/cli/src/ui/commands/agentsCommand.test.ts @@ -7,8 +7,20 @@ import { vi, describe, it, expect, beforeEach } from 'vitest'; import { agentsCommand } from './agentsCommand.js'; import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; -import type { Config } from '@google/gemini-cli-core'; +import type { Config, AgentOverride } from '@google/gemini-cli-core'; +import type { LoadedSettings } from '../../config/settings.js'; import { MessageType } from '../types.js'; +import { enableAgent, disableAgent } from '../../utils/agentSettings.js'; +import { renderAgentActionFeedback } from '../../utils/agentUtils.js'; + +vi.mock('../../utils/agentSettings.js', () => ({ + enableAgent: vi.fn(), + disableAgent: vi.fn(), +})); + +vi.mock('../../utils/agentUtils.js', () => ({ + renderAgentActionFeedback: vi.fn(), +})); describe('agentsCommand', () => { let mockContext: ReturnType; @@ -22,12 +34,18 @@ describe('agentsCommand', () => { mockConfig = { getAgentRegistry: vi.fn().mockReturnValue({ getAllDefinitions: vi.fn().mockReturnValue([]), + getAllAgentNames: vi.fn().mockReturnValue([]), + reload: vi.fn(), }), }; mockContext = createMockCommandContext({ services: { config: mockConfig as unknown as Config, + settings: { + workspace: { path: '/mock/path' }, + merged: { agents: { overrides: {} } }, + } as unknown as LoadedSettings, }, }); }); @@ -68,7 +86,12 @@ describe('agentsCommand', () => { description: 'desc1', kind: 'local', }, - { name: 'agent2', description: 'desc2', kind: 'remote' }, + { + name: 'agent2', + displayName: undefined, + description: 'desc2', + kind: 'remote', + }, ]; mockConfig.getAgentRegistry().getAllDefinitions.mockReturnValue(mockAgents); @@ -117,4 +140,178 @@ describe('agentsCommand', () => { content: 'Agent registry not found.', }); }); + + it('should enable an agent successfully', async () => { + const reloadSpy = vi.fn().mockResolvedValue(undefined); + mockConfig.getAgentRegistry = vi.fn().mockReturnValue({ + getAllAgentNames: vi.fn().mockReturnValue([]), + reload: reloadSpy, + }); + // Add agent to disabled overrides so validation passes + ( + mockContext.services.settings.merged.agents!.overrides as Record< + string, + AgentOverride + > + )['test-agent'] = { disabled: true }; + + vi.mocked(enableAgent).mockReturnValue({ + status: 'success', + agentName: 'test-agent', + action: 'enable', + modifiedScopes: [], + alreadyInStateScopes: [], + }); + vi.mocked(renderAgentActionFeedback).mockReturnValue('Enabled test-agent.'); + + const enableCommand = agentsCommand.subCommands?.find( + (cmd) => cmd.name === 'enable', + ); + expect(enableCommand).toBeDefined(); + + const result = await enableCommand!.action!(mockContext, 'test-agent'); + + expect(enableAgent).toHaveBeenCalledWith( + mockContext.services.settings, + 'test-agent', + ); + expect(reloadSpy).toHaveBeenCalled(); + expect(mockContext.ui.addItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.INFO, + text: 'Enabling test-agent...', + }), + ); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: 'Enabled test-agent.', + }); + }); + + it('should handle no-op when enabling an agent', async () => { + mockConfig + .getAgentRegistry() + .getAllAgentNames.mockReturnValue(['test-agent']); + + const enableCommand = agentsCommand.subCommands?.find( + (cmd) => cmd.name === 'enable', + ); + const result = await enableCommand!.action!(mockContext, 'test-agent'); + + expect(enableAgent).not.toHaveBeenCalled(); + expect(mockContext.ui.addItem).not.toHaveBeenCalled(); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: "Agent 'test-agent' is already enabled.", + }); + }); + + it('should show usage error if no agent name provided for enable', async () => { + const enableCommand = agentsCommand.subCommands?.find( + (cmd) => cmd.name === 'enable', + ); + const result = await enableCommand!.action!(mockContext, ' '); + + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: 'Usage: /agents enable ', + }); + }); + + it('should disable an agent successfully', async () => { + const reloadSpy = vi.fn().mockResolvedValue(undefined); + mockConfig.getAgentRegistry = vi.fn().mockReturnValue({ + getAllAgentNames: vi.fn().mockReturnValue(['test-agent']), + reload: reloadSpy, + }); + vi.mocked(disableAgent).mockReturnValue({ + status: 'success', + agentName: 'test-agent', + action: 'disable', + modifiedScopes: [], + alreadyInStateScopes: [], + }); + vi.mocked(renderAgentActionFeedback).mockReturnValue( + 'Disabled test-agent.', + ); + + const disableCommand = agentsCommand.subCommands?.find( + (cmd) => cmd.name === 'disable', + ); + expect(disableCommand).toBeDefined(); + + const result = await disableCommand!.action!(mockContext, 'test-agent'); + + expect(disableAgent).toHaveBeenCalledWith( + mockContext.services.settings, + 'test-agent', + expect.anything(), // Scope is derived in the command + ); + expect(reloadSpy).toHaveBeenCalled(); + expect(mockContext.ui.addItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.INFO, + text: 'Disabling test-agent...', + }), + ); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: 'Disabled test-agent.', + }); + }); + + it('should show info message if agent is already disabled', async () => { + mockConfig.getAgentRegistry().getAllAgentNames.mockReturnValue([]); + ( + mockContext.services.settings.merged.agents!.overrides as Record< + string, + AgentOverride + > + )['test-agent'] = { disabled: true }; + + const disableCommand = agentsCommand.subCommands?.find( + (cmd) => cmd.name === 'disable', + ); + const result = await disableCommand!.action!(mockContext, 'test-agent'); + + expect(disableAgent).not.toHaveBeenCalled(); + expect(result).toEqual({ + type: 'message', + messageType: 'info', + content: "Agent 'test-agent' is already disabled.", + }); + }); + + it('should show error if agent is not found when disabling', async () => { + mockConfig.getAgentRegistry().getAllAgentNames.mockReturnValue([]); + + const disableCommand = agentsCommand.subCommands?.find( + (cmd) => cmd.name === 'disable', + ); + const result = await disableCommand!.action!(mockContext, 'test-agent'); + + expect(disableAgent).not.toHaveBeenCalled(); + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: "Agent 'test-agent' not found.", + }); + }); + + it('should show usage error if no agent name provided for disable', async () => { + const disableCommand = agentsCommand.subCommands?.find( + (cmd) => cmd.name === 'disable', + ); + const result = await disableCommand!.action!(mockContext, ''); + + expect(result).toEqual({ + type: 'message', + messageType: 'error', + content: 'Usage: /agents disable ', + }); + }); }); diff --git a/packages/cli/src/ui/commands/agentsCommand.ts b/packages/cli/src/ui/commands/agentsCommand.ts index 5059fc1937..1c03524332 100644 --- a/packages/cli/src/ui/commands/agentsCommand.ts +++ b/packages/cli/src/ui/commands/agentsCommand.ts @@ -4,9 +4,17 @@ * SPDX-License-Identifier: Apache-2.0 */ -import type { SlashCommand, CommandContext } from './types.js'; +import type { + SlashCommand, + CommandContext, + SlashCommandActionReturn, +} from './types.js'; import { CommandKind } from './types.js'; import { MessageType, type HistoryItemAgentsList } from '../types.js'; +import { SettingScope } from '../../config/settings.js'; +import type { AgentOverride } from '@google/gemini-cli-core'; +import { disableAgent, enableAgent } from '../../utils/agentSettings.js'; +import { renderAgentActionFeedback } from '../../utils/agentUtils.js'; const agentsListCommand: SlashCommand = { name: 'list', @@ -50,6 +58,197 @@ const agentsListCommand: SlashCommand = { }, }; +async function enableAction( + context: CommandContext, + args: string, +): Promise { + const { config, settings } = context.services; + if (!config) return; + + const agentName = args.trim(); + if (!agentName) { + return { + type: 'message', + messageType: 'error', + content: 'Usage: /agents enable ', + }; + } + + const agentRegistry = config.getAgentRegistry(); + if (!agentRegistry) { + return { + type: 'message', + messageType: 'error', + content: 'Agent registry not found.', + }; + } + + const allAgents = agentRegistry.getAllAgentNames(); + const overrides = (settings.merged.agents?.overrides ?? {}) as Record< + string, + AgentOverride + >; + const disabledAgents = Object.keys(overrides).filter( + (name) => overrides[name]?.disabled === true, + ); + + if (allAgents.includes(agentName)) { + return { + type: 'message', + messageType: 'info', + content: `Agent '${agentName}' is already enabled.`, + }; + } + + if (!disabledAgents.includes(agentName)) { + return { + type: 'message', + messageType: 'error', + content: `Agent '${agentName}' not found.`, + }; + } + + const result = enableAgent(settings, agentName); + + if (result.status === 'no-op') { + return { + type: 'message', + messageType: 'info', + content: renderAgentActionFeedback(result, (l, p) => `${l} (${p})`), + }; + } + + context.ui.addItem({ + type: MessageType.INFO, + text: `Enabling ${agentName}...`, + }); + await agentRegistry.reload(); + + return { + type: 'message', + messageType: 'info', + content: renderAgentActionFeedback(result, (l, p) => `${l} (${p})`), + }; +} + +async function disableAction( + context: CommandContext, + args: string, +): Promise { + const { config, settings } = context.services; + if (!config) return; + + const agentName = args.trim(); + if (!agentName) { + return { + type: 'message', + messageType: 'error', + content: 'Usage: /agents disable ', + }; + } + + const agentRegistry = config.getAgentRegistry(); + if (!agentRegistry) { + return { + type: 'message', + messageType: 'error', + content: 'Agent registry not found.', + }; + } + + const allAgents = agentRegistry.getAllAgentNames(); + const overrides = (settings.merged.agents?.overrides ?? {}) as Record< + string, + AgentOverride + >; + const disabledAgents = Object.keys(overrides).filter( + (name) => overrides[name]?.disabled === true, + ); + + if (disabledAgents.includes(agentName)) { + return { + type: 'message', + messageType: 'info', + content: `Agent '${agentName}' is already disabled.`, + }; + } + + if (!allAgents.includes(agentName)) { + return { + type: 'message', + messageType: 'error', + content: `Agent '${agentName}' not found.`, + }; + } + + const scope = context.services.settings.workspace.path + ? SettingScope.Workspace + : SettingScope.User; + const result = disableAgent(settings, agentName, scope); + + if (result.status === 'no-op') { + return { + type: 'message', + messageType: 'info', + content: renderAgentActionFeedback(result, (l, p) => `${l} (${p})`), + }; + } + + context.ui.addItem({ + type: MessageType.INFO, + text: `Disabling ${agentName}...`, + }); + await agentRegistry.reload(); + + return { + type: 'message', + messageType: 'info', + content: renderAgentActionFeedback(result, (l, p) => `${l} (${p})`), + }; +} + +function completeAgentsToEnable(context: CommandContext, partialArg: string) { + const { config, settings } = context.services; + if (!config) return []; + + const overrides = (settings.merged.agents?.overrides ?? {}) as Record< + string, + AgentOverride + >; + const disabledAgents = Object.entries(overrides) + .filter(([_, override]) => override?.disabled === true) + .map(([name]) => name); + + return disabledAgents.filter((name) => name.startsWith(partialArg)); +} + +function completeAgentsToDisable(context: CommandContext, partialArg: string) { + const { config } = context.services; + if (!config) return []; + + const agentRegistry = config.getAgentRegistry(); + const allAgents = agentRegistry ? agentRegistry.getAllAgentNames() : []; + return allAgents.filter((name: string) => name.startsWith(partialArg)); +} + +const enableCommand: SlashCommand = { + name: 'enable', + description: 'Enable a disabled agent', + kind: CommandKind.BUILT_IN, + autoExecute: false, + action: enableAction, + completion: completeAgentsToEnable, +}; + +const disableCommand: SlashCommand = { + name: 'disable', + description: 'Disable an enabled agent', + kind: CommandKind.BUILT_IN, + autoExecute: false, + action: disableAction, + completion: completeAgentsToDisable, +}; + const agentsRefreshCommand: SlashCommand = { name: 'refresh', description: 'Reload the agent registry', @@ -84,7 +283,12 @@ export const agentsCommand: SlashCommand = { name: 'agents', description: 'Manage agents', kind: CommandKind.BUILT_IN, - subCommands: [agentsListCommand, agentsRefreshCommand], + subCommands: [ + agentsListCommand, + agentsRefreshCommand, + enableCommand, + disableCommand, + ], action: async (context: CommandContext, args) => // Default to list if no subcommand is provided agentsListCommand.action!(context, args), diff --git a/packages/cli/src/utils/agentSettings.ts b/packages/cli/src/utils/agentSettings.ts new file mode 100644 index 0000000000..adf444c4ba --- /dev/null +++ b/packages/cli/src/utils/agentSettings.ts @@ -0,0 +1,150 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + SettingScope, + isLoadableSettingScope, + type LoadedSettings, +} from '../config/settings.js'; +import type { ModifiedScope } from './skillSettings.js'; +import type { AgentOverride } from '@google/gemini-cli-core'; + +export type AgentActionStatus = 'success' | 'no-op' | 'error'; + +/** + * Metadata representing the result of an agent settings operation. + */ +export interface AgentActionResult { + status: AgentActionStatus; + agentName: string; + action: 'enable' | 'disable'; + /** Scopes where the agent's state was actually changed. */ + modifiedScopes: ModifiedScope[]; + /** Scopes where the agent was already in the desired state. */ + alreadyInStateScopes: ModifiedScope[]; + /** Error message if status is 'error'. */ + error?: string; +} + +/** + * Enables an agent by ensuring it is not disabled in any writable scope (User and Workspace). + * It sets `agents.overrides..disabled` to `false` if it was found to be `true`. + */ +export function enableAgent( + settings: LoadedSettings, + agentName: string, +): AgentActionResult { + const writableScopes = [SettingScope.Workspace, SettingScope.User]; + const foundInDisabledScopes: ModifiedScope[] = []; + const alreadyEnabledScopes: ModifiedScope[] = []; + + for (const scope of writableScopes) { + if (isLoadableSettingScope(scope)) { + const scopePath = settings.forScope(scope).path; + const agentOverrides = settings.forScope(scope).settings.agents + ?.overrides as Record | undefined; + const isDisabled = agentOverrides?.[agentName]?.disabled === true; + + if (isDisabled) { + foundInDisabledScopes.push({ scope, path: scopePath }); + } else { + alreadyEnabledScopes.push({ scope, path: scopePath }); + } + } + } + + if (foundInDisabledScopes.length === 0) { + return { + status: 'no-op', + agentName, + action: 'enable', + modifiedScopes: [], + alreadyInStateScopes: alreadyEnabledScopes, + }; + } + + const modifiedScopes: ModifiedScope[] = []; + for (const { scope, path } of foundInDisabledScopes) { + if (isLoadableSettingScope(scope)) { + // Explicitly enable it to override any lower-precedence disables, or just clear the disable. + // Setting to false ensures it is enabled. + settings.setValue(scope, `agents.overrides.${agentName}.disabled`, false); + modifiedScopes.push({ scope, path }); + } + } + + return { + status: 'success', + agentName, + action: 'enable', + modifiedScopes, + alreadyInStateScopes: alreadyEnabledScopes, + }; +} + +/** + * Disables an agent by setting `agents.overrides..disabled` to `true` in the specified scope. + */ +export function disableAgent( + settings: LoadedSettings, + agentName: string, + scope: SettingScope, +): AgentActionResult { + if (!isLoadableSettingScope(scope)) { + return { + status: 'error', + agentName, + action: 'disable', + modifiedScopes: [], + alreadyInStateScopes: [], + error: `Invalid settings scope: ${scope}`, + }; + } + + const scopePath = settings.forScope(scope).path; + const agentOverrides = settings.forScope(scope).settings.agents?.overrides as + | Record + | undefined; + const isDisabled = agentOverrides?.[agentName]?.disabled === true; + + if (isDisabled) { + return { + status: 'no-op', + agentName, + action: 'disable', + modifiedScopes: [], + alreadyInStateScopes: [{ scope, path: scopePath }], + }; + } + + // Check if it's already disabled in the other writable scope + const otherScope = + scope === SettingScope.Workspace + ? SettingScope.User + : SettingScope.Workspace; + const alreadyDisabledInOther: ModifiedScope[] = []; + + if (isLoadableSettingScope(otherScope)) { + const otherOverrides = settings.forScope(otherScope).settings.agents + ?.overrides as Record | undefined; + if (otherOverrides?.[agentName]?.disabled === true) { + alreadyDisabledInOther.push({ + scope: otherScope, + path: settings.forScope(otherScope).path, + }); + } + } + + settings.setValue(scope, `agents.overrides.${agentName}.disabled`, true); + + return { + status: 'success', + agentName, + action: 'disable', + modifiedScopes: [{ scope, path: scopePath }], + alreadyInStateScopes: alreadyDisabledInOther, + }; +} diff --git a/packages/cli/src/utils/agentUtils.test.ts b/packages/cli/src/utils/agentUtils.test.ts new file mode 100644 index 0000000000..e62fb7f1f2 --- /dev/null +++ b/packages/cli/src/utils/agentUtils.test.ts @@ -0,0 +1,150 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi } from 'vitest'; + +vi.mock('../config/settings.js', () => ({ + SettingScope: { + User: 'User', + Workspace: 'Workspace', + System: 'System', + SystemDefaults: 'SystemDefaults', + }, +})); + +import { renderAgentActionFeedback } from './agentUtils.js'; +import { SettingScope } from '../config/settings.js'; +import type { AgentActionResult } from './agentSettings.js'; + +describe('agentUtils', () => { + describe('renderAgentActionFeedback', () => { + const mockFormatScope = (label: string, path: string) => + `[${label}:${path}]`; + + it('should return error message if status is error', () => { + const result: AgentActionResult = { + status: 'error', + agentName: 'my-agent', + action: 'enable', + modifiedScopes: [], + alreadyInStateScopes: [], + error: 'Something went wrong', + }; + expect(renderAgentActionFeedback(result, mockFormatScope)).toBe( + 'Something went wrong', + ); + }); + + it('should return default error message if status is error and no error message provided', () => { + const result: AgentActionResult = { + status: 'error', + agentName: 'my-agent', + action: 'enable', + modifiedScopes: [], + alreadyInStateScopes: [], + }; + expect(renderAgentActionFeedback(result, mockFormatScope)).toBe( + 'An error occurred while attempting to enable agent "my-agent".', + ); + }); + + it('should return no-op message for enable', () => { + const result: AgentActionResult = { + status: 'no-op', + agentName: 'my-agent', + action: 'enable', + modifiedScopes: [], + alreadyInStateScopes: [], + }; + expect(renderAgentActionFeedback(result, mockFormatScope)).toBe( + 'Agent "my-agent" is already enabled.', + ); + }); + + it('should return no-op message for disable', () => { + const result: AgentActionResult = { + status: 'no-op', + agentName: 'my-agent', + action: 'disable', + modifiedScopes: [], + alreadyInStateScopes: [], + }; + expect(renderAgentActionFeedback(result, mockFormatScope)).toBe( + 'Agent "my-agent" is already disabled.', + ); + }); + + it('should return success message for enable (single scope)', () => { + const result: AgentActionResult = { + status: 'success', + agentName: 'my-agent', + action: 'enable', + modifiedScopes: [ + { scope: SettingScope.User, path: '/path/to/user/settings' }, + ], + alreadyInStateScopes: [], + }; + expect(renderAgentActionFeedback(result, mockFormatScope)).toBe( + 'Agent "my-agent" enabled by setting it to enabled in [user:/path/to/user/settings] settings.', + ); + }); + + it('should return success message for enable (two scopes)', () => { + const result: AgentActionResult = { + status: 'success', + agentName: 'my-agent', + action: 'enable', + modifiedScopes: [ + { scope: SettingScope.User, path: '/path/to/user/settings' }, + ], + alreadyInStateScopes: [ + { + scope: SettingScope.Workspace, + path: '/path/to/workspace/settings', + }, + ], + }; + expect(renderAgentActionFeedback(result, mockFormatScope)).toBe( + 'Agent "my-agent" enabled by setting it to enabled in [user:/path/to/user/settings] and [project:/path/to/workspace/settings] settings.', + ); + }); + + it('should return success message for disable (single scope)', () => { + const result: AgentActionResult = { + status: 'success', + agentName: 'my-agent', + action: 'disable', + modifiedScopes: [ + { scope: SettingScope.User, path: '/path/to/user/settings' }, + ], + alreadyInStateScopes: [], + }; + expect(renderAgentActionFeedback(result, mockFormatScope)).toBe( + 'Agent "my-agent" disabled by setting it to disabled in [user:/path/to/user/settings] settings.', + ); + }); + + it('should return success message for disable (two scopes)', () => { + const result: AgentActionResult = { + status: 'success', + agentName: 'my-agent', + action: 'disable', + modifiedScopes: [ + { scope: SettingScope.User, path: '/path/to/user/settings' }, + ], + alreadyInStateScopes: [ + { + scope: SettingScope.Workspace, + path: '/path/to/workspace/settings', + }, + ], + }; + expect(renderAgentActionFeedback(result, mockFormatScope)).toBe( + 'Agent "my-agent" is now disabled in both [user:/path/to/user/settings] and [project:/path/to/workspace/settings] settings.', + ); + }); + }); +}); diff --git a/packages/cli/src/utils/agentUtils.ts b/packages/cli/src/utils/agentUtils.ts new file mode 100644 index 0000000000..4bcee796d1 --- /dev/null +++ b/packages/cli/src/utils/agentUtils.ts @@ -0,0 +1,65 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { SettingScope } from '../config/settings.js'; +import type { AgentActionResult } from './agentSettings.js'; + +/** + * Shared logic for building the core agent action message while allowing the + * caller to control how each scope and its path are rendered (e.g., bolding or + * dimming). + * + * This function ONLY returns the description of what happened. It is up to the + * caller to append any interface-specific guidance. + */ +export function renderAgentActionFeedback( + result: AgentActionResult, + formatScope: (label: string, path: string) => string, +): string { + const { agentName, action, status, error } = result; + + if (status === 'error') { + return ( + error || + `An error occurred while attempting to ${action} agent "${agentName}".` + ); + } + + if (status === 'no-op') { + return `Agent "${agentName}" is already ${action === 'enable' ? 'enabled' : 'disabled'}.`; + } + + const isEnable = action === 'enable'; + const actionVerb = isEnable ? 'enabled' : 'disabled'; + const preposition = isEnable + ? 'by setting it to enabled in' + : 'by setting it to disabled in'; + + const formatScopeItem = (s: { scope: SettingScope; path: string }) => { + const label = + s.scope === SettingScope.Workspace ? 'project' : s.scope.toLowerCase(); + return formatScope(label, s.path); + }; + + const totalAffectedScopes = [ + ...result.modifiedScopes, + ...result.alreadyInStateScopes, + ]; + + if (totalAffectedScopes.length === 2) { + const s1 = formatScopeItem(totalAffectedScopes[0]); + const s2 = formatScopeItem(totalAffectedScopes[1]); + + if (isEnable) { + return `Agent "${agentName}" ${actionVerb} ${preposition} ${s1} and ${s2} settings.`; + } else { + return `Agent "${agentName}" is now disabled in both ${s1} and ${s2} settings.`; + } + } + + const s = formatScopeItem(totalAffectedScopes[0]); + return `Agent "${agentName}" ${actionVerb} ${preposition} ${s} settings.`; +} diff --git a/packages/core/src/agents/a2a-client-manager.ts b/packages/core/src/agents/a2a-client-manager.ts index ff379f1719..97355eef06 100644 --- a/packages/core/src/agents/a2a-client-manager.ts +++ b/packages/core/src/agents/a2a-client-manager.ts @@ -64,7 +64,7 @@ export class A2AClientManager { agentCardUrl: string, authHandler?: AuthenticationHandler, ): Promise { - if (this.clients.has(name)) { + if (this.clients.has(name) && this.agentCards.has(name)) { throw new Error(`Agent with name '${name}' is already loaded.`); } diff --git a/packages/core/src/agents/registry.ts b/packages/core/src/agents/registry.ts index 49d425bd6e..4e042ab711 100644 --- a/packages/core/src/agents/registry.ts +++ b/packages/core/src/agents/registry.ts @@ -69,6 +69,7 @@ export class AgentRegistry { */ async reload(): Promise { A2AClientManager.getInstance().clearCache(); + await this.config.reloadAgents(); this.agents.clear(); await this.loadAgents(); coreEvents.emitAgentsRefreshed(); @@ -143,9 +144,14 @@ export class AgentRegistry { private loadBuiltInAgents(): void { const investigatorSettings = this.config.getCodebaseInvestigatorSettings(); const cliHelpSettings = this.config.getCliHelpAgentSettings(); + const agentsSettings = this.config.getAgentsSettings(); + const agentsOverrides = agentsSettings.overrides ?? {}; - // Only register the agent if it's enabled in the settings. - if (investigatorSettings?.enabled) { + // Only register the agent if it's enabled in the settings and not explicitly disabled via overrides. + if ( + investigatorSettings?.enabled && + !agentsOverrides[CodebaseInvestigatorAgent.name]?.disabled + ) { let model; const settingsModel = investigatorSettings.model; // Check if the user explicitly set a model in the settings. @@ -189,8 +195,11 @@ export class AgentRegistry { this.registerLocalAgent(agentDef); } - // Register the CLI help agent if it's explicitly enabled. - if (cliHelpSettings.enabled) { + // Register the CLI help agent if it's explicitly enabled and not explicitly disabled via overrides. + if ( + cliHelpSettings.enabled && + !agentsOverrides[CliHelpAgent.name]?.disabled + ) { this.registerLocalAgent(CliHelpAgent(this.config)); } } diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 5db98732b1..5e77a93ab8 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -387,6 +387,7 @@ export interface ConfigParameters { onReload?: () => Promise<{ disabledSkills?: string[]; adminSkillsEnabled?: boolean; + agents?: AgentSettings; }>; } @@ -518,11 +519,12 @@ export class Config { | (() => Promise<{ disabledSkills?: string[]; adminSkillsEnabled?: boolean; + agents?: AgentSettings; }>) | undefined; private readonly enableAgents: boolean; - private readonly agents: AgentSettings; + private agents: AgentSettings; private readonly skillsSupport: boolean; private disabledSkills: string[]; private readonly adminSkillsEnabled: boolean; @@ -1634,6 +1636,18 @@ export class Config { await this.updateSystemInstructionIfInitialized(); } + /** + * Reloads agent settings. + */ + async reloadAgents(): Promise { + if (this.onReload) { + const refreshed = await this.onReload(); + if (refreshed.agents) { + this.agents = refreshed.agents; + } + } + } + isInteractive(): boolean { return this.interactive; } From ae198029bca1ac82e83e4e82ae2cf21f04bf876c Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Wed, 14 Jan 2026 16:48:02 -0800 Subject: [PATCH 201/713] Add timeout for shell-utils to prevent hangs. (#16667) --- packages/core/src/utils/shell-utils.test.ts | 32 +++++++++++++++++++++ packages/core/src/utils/shell-utils.ts | 28 ++++++++++++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/packages/core/src/utils/shell-utils.test.ts b/packages/core/src/utils/shell-utils.test.ts index 443e7d9182..862b2014bc 100644 --- a/packages/core/src/utils/shell-utils.test.ts +++ b/packages/core/src/utils/shell-utils.test.ts @@ -44,6 +44,16 @@ vi.mock('shell-quote', () => ({ quote: mockQuote, })); +const mockDebugLogger = vi.hoisted(() => ({ + error: vi.fn(), + debug: vi.fn(), + log: vi.fn(), + warn: vi.fn(), +})); +vi.mock('./debugLogger.js', () => ({ + debugLogger: mockDebugLogger, +})); + const isWindowsRuntime = process.platform === 'win32'; const describeWindowsOnly = isWindowsRuntime ? describe : describe.skip; @@ -161,6 +171,28 @@ describe('getCommandRoots', () => { const roots = shellUtils.getCommandRoots('ls -la'); expect(roots).toEqual([]); }); + + it('should handle bash parser timeouts', () => { + const nowSpy = vi.spyOn(performance, 'now'); + // Mock performance.now() to trigger timeout: + // 1st call: start time = 0. deadline = 0 + 1000ms. + // 2nd call (and onwards): inside progressCallback, return 2000ms. + nowSpy.mockReturnValueOnce(0).mockReturnValue(2000); + + // Use a very complex command to ensure progressCallback is triggered at least once + const complexCommand = + 'ls -la && ' + Array(100).fill('echo "hello"').join(' && '); + const roots = getCommandRoots(complexCommand); + expect(roots).toEqual([]); + expect(nowSpy).toHaveBeenCalled(); + + expect(mockDebugLogger.error).toHaveBeenCalledWith( + 'Bash command parsing timed out for command:', + complexCommand, + ); + + nowSpy.mockRestore(); + }); }); describe('hasRedirection', () => { diff --git a/packages/core/src/utils/shell-utils.ts b/packages/core/src/utils/shell-utils.ts index 609c0e28d5..c5eb6e8cf9 100644 --- a/packages/core/src/utils/shell-utils.ts +++ b/packages/core/src/utils/shell-utils.ts @@ -11,7 +11,7 @@ import { spawnSync, type SpawnOptionsWithoutStdio, } from 'node:child_process'; -import type { Node } from 'web-tree-sitter'; +import type { Node, Tree } from 'web-tree-sitter'; import { Language, Parser, Query } from 'web-tree-sitter'; import { loadWasmBinary } from './fileUtils.js'; import { debugLogger } from './debugLogger.js'; @@ -119,6 +119,7 @@ interface CommandParseResult { } const POWERSHELL_COMMAND_ENV = '__GCLI_POWERSHELL_COMMAND__'; +const PARSE_TIMEOUT_MICROS = 1000 * 1000; // 1 second // Encode the parser script as UTF-16LE base64 so we can pass it via PowerShell's -EncodedCommand flag; // this avoids brittle quoting/escaping when spawning PowerShell and ensures the script is received byte-for-byte. @@ -179,14 +180,35 @@ function createParser(): Parser | null { } } -function parseCommandTree(command: string) { +function parseCommandTree( + command: string, + timeoutMicros: number = PARSE_TIMEOUT_MICROS, +): Tree | null { const parser = createParser(); if (!parser || !command.trim()) { return null; } + const deadline = performance.now() + timeoutMicros / 1000; + let timedOut = false; + try { - return parser.parse(command); + const tree = parser.parse(command, null, { + progressCallback: () => { + if (performance.now() > deadline) { + timedOut = true; + return true as unknown as void; // Returning true cancels parsing, but type says void + } + }, + }); + + if (timedOut) { + debugLogger.error('Bash command parsing timed out for command:', command); + // Returning a partial tree could be risky so we return null to be safe. + return null; + } + + return tree; } catch { return null; } From 5bdfe1a1faa696c462c01322d4b9b695be00ce51 Mon Sep 17 00:00:00 2001 From: Jerop Kipruto Date: Wed, 14 Jan 2026 19:55:10 -0500 Subject: [PATCH 202/713] feat(plan): add experimental plan flag (#16650) --- docs/cli/settings.md | 1 + docs/get-started/configuration.md | 5 ++++ packages/cli/src/config/config.ts | 1 + .../cli/src/config/settingsSchema.test.ts | 13 +++++++++++ packages/cli/src/config/settingsSchema.ts | 9 ++++++++ packages/core/src/config/config.test.ts | 23 +++++++++++++++++++ packages/core/src/config/config.ts | 7 ++++++ schemas/settings.schema.json | 7 ++++++ 8 files changed, 66 insertions(+) diff --git a/docs/cli/settings.md b/docs/cli/settings.md index 29181f928b..85471807ca 100644 --- a/docs/cli/settings.md +++ b/docs/cli/settings.md @@ -120,6 +120,7 @@ they appear in the UI. | Codebase Investigator Max Num Turns | `experimental.codebaseInvestigatorSettings.maxNumTurns` | Maximum number of turns for the Codebase Investigator agent. | `10` | | Use OSC 52 Paste | `experimental.useOSC52Paste` | Use OSC 52 sequence for pasting instead of clipboardy (useful for remote sessions). | `false` | | Enable CLI Help Agent | `experimental.cliHelpAgentSettings.enabled` | Enable the CLI Help Agent. | `true` | +| Plan | `experimental.plan` | Enable planning features (Plan Mode and tools). | `false` | ### Hooks diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index d845c33692..d0ae56041c 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -887,6 +887,11 @@ their corresponding top-level category object in your `settings.json` file. - **Default:** `true` - **Requires restart:** Yes +- **`experimental.plan`** (boolean): + - **Description:** Enable planning features (Plan Mode and tools). + - **Default:** `false` + - **Requires restart:** Yes + #### `skills` - **`skills.disabled`** (array): diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 137e01d943..341226fed2 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -706,6 +706,7 @@ export async function loadCliConfig( extensionLoader: extensionManager, enableExtensionReloading: settings.experimental?.extensionReloading, enableAgents: settings.experimental?.enableAgents, + plan: settings.experimental?.plan, skillsSupport: settings.experimental?.skills, disabledSkills: settings.skills?.disabled, experimentalJitContext: settings.experimental?.jitContext, diff --git a/packages/cli/src/config/settingsSchema.test.ts b/packages/cli/src/config/settingsSchema.test.ts index e5706e0d6f..03f7a6e313 100644 --- a/packages/cli/src/config/settingsSchema.test.ts +++ b/packages/cli/src/config/settingsSchema.test.ts @@ -357,6 +357,19 @@ describe('SettingsSchema', () => { ); }); + it('should have plan setting in schema', () => { + const setting = getSettingsSchema().experimental.properties.plan; + expect(setting).toBeDefined(); + expect(setting.type).toBe('boolean'); + expect(setting.category).toBe('Experimental'); + expect(setting.default).toBe(false); + expect(setting.requiresRestart).toBe(true); + expect(setting.showInDialog).toBe(true); + expect(setting.description).toBe( + 'Enable planning features (Plan Mode and tools).', + ); + }); + it('should have hooks.notifications setting in schema', () => { const setting = getSettingsSchema().hooks.properties.notifications; expect(setting).toBeDefined(); diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index 229eebf81d..b7d4cbb296 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -1540,6 +1540,15 @@ const SETTINGS_SCHEMA = { }, }, }, + plan: { + type: 'boolean', + label: 'Plan', + category: 'Experimental', + requiresRestart: true, + default: false, + description: 'Enable planning features (Plan Mode and tools).', + showInDialog: true, + }, }, }, diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index ab389bea01..225b687380 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -1924,6 +1924,29 @@ describe('Config Quota & Preview Model Access', () => { expect(config.getModel()).toBe(PREVIEW_GEMINI_MODEL); }); }); + + describe('isPlanEnabled', () => { + it('should return false by default', () => { + const config = new Config(baseParams); + expect(config.isPlanEnabled()).toBe(false); + }); + + it('should return true when plan is enabled', () => { + const config = new Config({ + ...baseParams, + plan: true, + }); + expect(config.isPlanEnabled()).toBe(true); + }); + + it('should return false when plan is explicitly disabled', () => { + const config = new Config({ + ...baseParams, + plan: false, + }); + expect(config.isPlanEnabled()).toBe(false); + }); + }); }); describe('Config JIT Initialization', () => { diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 5e77a93ab8..08bd18216d 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -380,6 +380,7 @@ export interface ConfigParameters { adminSkillsEnabled?: boolean; experimentalJitContext?: boolean; disableLLMCorrection?: boolean; + plan?: boolean; onModelChange?: (model: string) => void; mcpEnabled?: boolean; extensionsEnabled?: boolean; @@ -531,6 +532,7 @@ export class Config { private readonly experimentalJitContext: boolean; private readonly disableLLMCorrection: boolean; + private readonly planEnabled: boolean; private contextManager?: ContextManager; private terminalBackground: string | undefined = undefined; private remoteAdminSettings: GeminiCodeAssistSetting | undefined; @@ -602,6 +604,7 @@ export class Config { this.enableAgents = params.enableAgents ?? false; this.agents = params.agents ?? {}; this.disableLLMCorrection = params.disableLLMCorrection ?? false; + this.planEnabled = params.plan ?? false; this.skillsSupport = params.skillsSupport ?? false; this.disabledSkills = params.disabledSkills ?? []; this.adminSkillsEnabled = params.adminSkillsEnabled ?? true; @@ -1469,6 +1472,10 @@ export class Config { return this.disableLLMCorrection; } + isPlanEnabled(): boolean { + return this.planEnabled; + } + isAgentsEnabled(): boolean { return this.enableAgents; } diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index a976c19fd6..4b99ec4632 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -1489,6 +1489,13 @@ } }, "additionalProperties": false + }, + "plan": { + "title": "Plan", + "description": "Enable planning features (Plan Mode and tools).", + "markdownDescription": "Enable planning features (Plan Mode and tools).\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `false`", + "default": false, + "type": "boolean" } }, "additionalProperties": false From a81500a92979b25d4520781cf5f5002bfb2d243c Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 14 Jan 2026 17:47:02 -0800 Subject: [PATCH 203/713] feat(cli): add security consent prompts for skill installation (#16549) --- .../cli/src/commands/skills/install.test.ts | 59 ++++++- packages/cli/src/commands/skills/install.ts | 31 +++- packages/cli/src/config/extension.test.ts | 5 +- .../cli/src/config/extensions/consent.test.ts | 52 +++++- packages/cli/src/config/extensions/consent.ts | 64 +++++-- packages/cli/src/utils/skillUtils.test.ts | 29 ++++ packages/cli/src/utils/skillUtils.ts | 157 ++++++++++-------- 7 files changed, 296 insertions(+), 101 deletions(-) diff --git a/packages/cli/src/commands/skills/install.test.ts b/packages/cli/src/commands/skills/install.test.ts index e0621c8028..9fd05affcd 100644 --- a/packages/cli/src/commands/skills/install.test.ts +++ b/packages/cli/src/commands/skills/install.test.ts @@ -7,11 +7,18 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; const mockInstallSkill = vi.hoisted(() => vi.fn()); +const mockRequestConsentNonInteractive = vi.hoisted(() => vi.fn()); +const mockSkillsConsentString = vi.hoisted(() => vi.fn()); vi.mock('../../utils/skillUtils.js', () => ({ installSkill: mockInstallSkill, })); +vi.mock('../../config/extensions/consent.js', () => ({ + requestConsentNonInteractive: mockRequestConsentNonInteractive, + skillsConsentString: mockSkillsConsentString, +})); + vi.mock('@google/gemini-cli-core', () => ({ debugLogger: { log: vi.fn(), error: vi.fn() }, })); @@ -23,6 +30,8 @@ describe('skill install command', () => { beforeEach(() => { vi.clearAllMocks(); vi.spyOn(process, 'exit').mockImplementation(() => undefined as never); + mockSkillsConsentString.mockResolvedValue('Mock Consent String'); + mockRequestConsentNonInteractive.mockResolvedValue(true); }); describe('installCommand', () => { @@ -37,9 +46,10 @@ describe('skill install command', () => { }); it('should call installSkill with correct arguments for user scope', async () => { - mockInstallSkill.mockResolvedValue([ - { name: 'test-skill', location: '/mock/user/skills/test-skill' }, - ]); + mockInstallSkill.mockImplementation(async (_s, _sc, _p, _ol, rc) => { + await rc([]); + return [{ name: 'test-skill', location: '/mock/user/skills/test-skill' }]; + }); await handleInstall({ source: 'https://example.com/repo.git', @@ -51,6 +61,7 @@ describe('skill install command', () => { 'user', undefined, expect.any(Function), + expect.any(Function), ); expect(debugLogger.log).toHaveBeenCalledWith( expect.stringContaining('Successfully installed skill: test-skill'), @@ -58,6 +69,47 @@ describe('skill install command', () => { expect(debugLogger.log).toHaveBeenCalledWith( expect.stringContaining('location: /mock/user/skills/test-skill'), ); + expect(mockRequestConsentNonInteractive).toHaveBeenCalledWith( + 'Mock Consent String', + ); + }); + + it('should skip prompt and log consent when --consent is provided', async () => { + mockInstallSkill.mockImplementation(async (_s, _sc, _p, _ol, rc) => { + await rc([]); + return [{ name: 'test-skill', location: '/mock/user/skills/test-skill' }]; + }); + + await handleInstall({ + source: 'https://example.com/repo.git', + consent: true, + }); + + expect(mockRequestConsentNonInteractive).not.toHaveBeenCalled(); + expect(debugLogger.log).toHaveBeenCalledWith( + 'You have consented to the following:', + ); + expect(debugLogger.log).toHaveBeenCalledWith('Mock Consent String'); + expect(mockInstallSkill).toHaveBeenCalled(); + }); + + it('should abort installation if consent is denied', async () => { + mockRequestConsentNonInteractive.mockResolvedValue(false); + mockInstallSkill.mockImplementation(async (_s, _sc, _p, _ol, rc) => { + if (!(await rc([]))) { + throw new Error('Skill installation cancelled by user.'); + } + return []; + }); + + await handleInstall({ + source: 'https://example.com/repo.git', + }); + + expect(debugLogger.error).toHaveBeenCalledWith( + 'Skill installation cancelled by user.', + ); + expect(process.exit).toHaveBeenCalledWith(1); }); it('should call installSkill with correct arguments for workspace scope and subpath', async () => { @@ -76,6 +128,7 @@ describe('skill install command', () => { 'workspace', 'my-skills-dir', expect.any(Function), + expect.any(Function), ); }); diff --git a/packages/cli/src/commands/skills/install.ts b/packages/cli/src/commands/skills/install.ts index bdf8402de7..f0701d39b6 100644 --- a/packages/cli/src/commands/skills/install.ts +++ b/packages/cli/src/commands/skills/install.ts @@ -5,24 +5,43 @@ */ import type { CommandModule } from 'yargs'; -import { debugLogger } from '@google/gemini-cli-core'; +import { debugLogger, type SkillDefinition } from '@google/gemini-cli-core'; import { getErrorMessage } from '../../utils/errors.js'; import { exitCli } from '../utils.js'; import { installSkill } from '../../utils/skillUtils.js'; import chalk from 'chalk'; +import { + requestConsentNonInteractive, + skillsConsentString, +} from '../../config/extensions/consent.js'; interface InstallArgs { source: string; scope?: 'user' | 'workspace'; path?: string; + consent?: boolean; } export async function handleInstall(args: InstallArgs) { try { - const { source } = args; + const { source, consent } = args; const scope = args.scope ?? 'user'; const subpath = args.path; + const requestConsent = async ( + skills: SkillDefinition[], + targetDir: string, + ) => { + if (consent) { + debugLogger.log('You have consented to the following:'); + debugLogger.log(await skillsConsentString(skills, source, targetDir)); + return true; + } + return requestConsentNonInteractive( + await skillsConsentString(skills, source, targetDir), + ); + }; + const installedSkills = await installSkill( source, scope, @@ -30,6 +49,7 @@ export async function handleInstall(args: InstallArgs) { (msg) => { debugLogger.log(msg); }, + requestConsent, ); for (const skill of installedSkills) { @@ -68,6 +88,12 @@ export const installCommand: CommandModule = { 'Sub-path within the repository to install from (only used for git repository sources).', type: 'string', }) + .option('consent', { + describe: + 'Acknowledge the security risks of installing a skill and skip the confirmation prompt.', + type: 'boolean', + default: false, + }) .check((argv) => { if (!argv.source) { throw new Error('The source argument must be provided.'); @@ -79,6 +105,7 @@ export const installCommand: CommandModule = { source: argv['source'] as string, scope: argv['scope'] as 'user' | 'workspace', path: argv['path'] as string | undefined, + consent: argv['consent'] as boolean | undefined, }); await exitCli(); }, diff --git a/packages/cli/src/config/extension.test.ts b/packages/cli/src/config/extension.test.ts index 6619befc66..a3230058f7 100644 --- a/packages/cli/src/config/extension.test.ts +++ b/packages/cli/src/config/extension.test.ts @@ -1298,10 +1298,11 @@ describe('extension tests', () => { expect(mockRequestConsent).toHaveBeenCalledWith( `Installing extension "my-local-extension". -${INSTALL_WARNING_MESSAGE} This extension will run the following MCP servers: * test-server (local): node dobadthing \\u001b[12D\\u001b[K server.js - * test-server-2 (remote): https://google.com`, + * test-server-2 (remote): https://google.com + +${INSTALL_WARNING_MESSAGE}`, ); }); diff --git a/packages/cli/src/config/extensions/consent.test.ts b/packages/cli/src/config/extensions/consent.test.ts index ccb569f43e..4180a72b16 100644 --- a/packages/cli/src/config/extensions/consent.test.ts +++ b/packages/cli/src/config/extensions/consent.test.ts @@ -191,12 +191,13 @@ describe('consent', () => { const expectedConsentString = [ 'Installing extension "test-ext".', - INSTALL_WARNING_MESSAGE, 'This extension will run the following MCP servers:', ' * server1 (local): npm start', ' * server2 (remote): https://remote.com', 'This extension will append info to your gemini.md context using my-context.md', 'This extension will exclude the following core tools: tool1,tool2', + '', + INSTALL_WARNING_MESSAGE, ].join('\n'); expect(requestConsent).toHaveBeenCalledWith(expectedConsentString); @@ -324,7 +325,6 @@ describe('consent', () => { const expectedConsentString = [ 'Installing extension "test-ext".', - INSTALL_WARNING_MESSAGE, 'This extension will run the following MCP servers:', ' * server1 (local): npm start', ' * server2 (remote): https://remote.com', @@ -332,13 +332,17 @@ describe('consent', () => { 'This extension will exclude the following core tools: tool1,tool2', '', chalk.bold('Agent Skills:'), - SKILLS_WARNING_MESSAGE, - 'This extension will install the following agent skills:', + '\nThis extension will install the following agent skills:\n', ` * ${chalk.bold('skill1')}: desc1`, - ` (Location: ${skill1.location}) (2 items in directory)`, - ` * ${chalk.bold('skill2')}: desc2`, - ` (Location: ${skill2.location}) (1 items in directory)`, + chalk.dim(` (Source: ${skill1.location}) (2 items in directory)`), '', + ` * ${chalk.bold('skill2')}: desc2`, + chalk.dim(` (Source: ${skill2.location}) (1 items in directory)`), + '', + '', + INSTALL_WARNING_MESSAGE, + '', + SKILLS_WARNING_MESSAGE, ].join('\n'); expect(requestConsent).toHaveBeenCalledWith(expectedConsentString); @@ -375,10 +379,42 @@ describe('consent', () => { expect(requestConsent).toHaveBeenCalledWith( expect.stringContaining( - ` (Location: ${skill.location}) ${chalk.red('⚠️ (Could not count items in directory)')}`, + ` (Source: ${skill.location}) ${chalk.red('⚠️ (Could not count items in directory)')}`, ), ); }); }); }); + + describe('skillsConsentString', () => { + it('should generate a consent string for skills', async () => { + const skill1Dir = path.join(tempDir, 'skill1'); + await fs.mkdir(skill1Dir, { recursive: true }); + await fs.writeFile(path.join(skill1Dir, 'SKILL.md'), 'body1'); + + const skill1: SkillDefinition = { + name: 'skill1', + description: 'desc1', + location: path.join(skill1Dir, 'SKILL.md'), + body: 'body1', + }; + + const { skillsConsentString } = await import('./consent.js'); + const consentString = await skillsConsentString( + [skill1], + 'https://example.com/repo.git', + '/mock/target/dir', + ); + + expect(consentString).toContain( + 'Installing agent skill(s) from "https://example.com/repo.git".', + ); + expect(consentString).toContain('Install Destination: /mock/target/dir'); + expect(consentString).toContain('\n' + SKILLS_WARNING_MESSAGE); + expect(consentString).toContain(` * ${chalk.bold('skill1')}: desc1`); + expect(consentString).toContain( + chalk.dim(`(Source: ${skill1.location}) (1 items in directory)`), + ); + }); + }); }); diff --git a/packages/cli/src/config/extensions/consent.ts b/packages/cli/src/config/extensions/consent.ts index 47391fd9e6..27b8e9a904 100644 --- a/packages/cli/src/config/extensions/consent.ts +++ b/packages/cli/src/config/extensions/consent.ts @@ -21,6 +21,27 @@ export const SKILLS_WARNING_MESSAGE = chalk.yellow( "Agent skills inject specialized instructions and domain-specific knowledge into the agent's system prompt. This can change how the agent interprets your requests and interacts with your environment. Review the skill definitions at the location(s) provided below to ensure they meet your security standards.", ); +/** + * Builds a consent string for installing agent skills. + */ +export async function skillsConsentString( + skills: SkillDefinition[], + source: string, + targetDir?: string, +): Promise { + const output: string[] = []; + output.push(`Installing agent skill(s) from "${source}".`); + output.push('\nThe following agent skill(s) will be installed:\n'); + output.push(...(await renderSkillsList(skills))); + + if (targetDir) { + output.push(`Install Destination: ${targetDir}`); + } + output.push('\n' + SKILLS_WARNING_MESSAGE); + + return output.join('\n'); +} + /** * Requests consent from the user to perform an action, by reading a Y/n * character from stdin. @@ -120,7 +141,6 @@ async function extensionConsentString( const output: string[] = []; const mcpServerEntries = Object.entries(sanitizedConfig.mcpServers || {}); output.push(`Installing extension "${sanitizedConfig.name}".`); - output.push(INSTALL_WARNING_MESSAGE); if (mcpServerEntries.length) { output.push('This extension will run the following MCP servers:'); @@ -149,23 +169,37 @@ async function extensionConsentString( } if (skills.length > 0) { output.push(`\n${chalk.bold('Agent Skills:')}`); - output.push(SKILLS_WARNING_MESSAGE); - output.push('This extension will install the following agent skills:'); - for (const skill of skills) { - output.push(` * ${chalk.bold(skill.name)}: ${skill.description}`); - const skillDir = path.dirname(skill.location); - let fileCountStr = ''; - try { - const skillDirItems = await fs.readdir(skillDir); - fileCountStr = ` (${skillDirItems.length} items in directory)`; - } catch { - fileCountStr = ` ${chalk.red('⚠️ (Could not count items in directory)')}`; - } - output.push(` (Location: ${skill.location})${fileCountStr}`); + output.push('\nThis extension will install the following agent skills:\n'); + output.push(...(await renderSkillsList(skills))); + } + + output.push('\n' + INSTALL_WARNING_MESSAGE); + if (skills.length > 0) { + output.push('\n' + SKILLS_WARNING_MESSAGE); + } + + return output.join('\n'); +} + +/** + * Shared logic for formatting a list of agent skills for a consent prompt. + */ +async function renderSkillsList(skills: SkillDefinition[]): Promise { + const output: string[] = []; + for (const skill of skills) { + output.push(` * ${chalk.bold(skill.name)}: ${skill.description}`); + const skillDir = path.dirname(skill.location); + let fileCountStr = ''; + try { + const skillDirItems = await fs.readdir(skillDir); + fileCountStr = ` (${skillDirItems.length} items in directory)`; + } catch { + fileCountStr = ` ${chalk.red('⚠️ (Could not count items in directory)')}`; } + output.push(chalk.dim(` (Source: ${skill.location})${fileCountStr}`)); output.push(''); } - return output.join('\n'); + return output; } /** diff --git a/packages/cli/src/utils/skillUtils.test.ts b/packages/cli/src/utils/skillUtils.test.ts index 9dfe8560a6..5f98471112 100644 --- a/packages/cli/src/utils/skillUtils.test.ts +++ b/packages/cli/src/utils/skillUtils.test.ts @@ -78,4 +78,33 @@ describe('skillUtils', () => { const installedExists = await fs.stat(installedPath).catch(() => null); expect(installedExists?.isDirectory()).toBe(true); }); + + it('should abort installation if consent is rejected', async () => { + const mockSkillDir = path.join(tempDir, 'mock-skill-source'); + const skillSubDir = path.join(mockSkillDir, 'test-skill'); + await fs.mkdir(skillSubDir, { recursive: true }); + await fs.writeFile( + path.join(skillSubDir, 'SKILL.md'), + '---\nname: test-skill\ndescription: test\n---\nbody', + ); + + const requestConsent = vi.fn().mockResolvedValue(false); + + await expect( + installSkill( + mockSkillDir, + 'workspace', + undefined, + () => {}, + requestConsent, + ), + ).rejects.toThrow('Skill installation cancelled by user.'); + + expect(requestConsent).toHaveBeenCalled(); + + // Verify it was NOT copied + const installedPath = path.join(tempDir, '.gemini/skills', 'test-skill'); + const installedExists = await fs.stat(installedPath).catch(() => null); + expect(installedExists).toBeNull(); + }); }); diff --git a/packages/cli/src/utils/skillUtils.ts b/packages/cli/src/utils/skillUtils.ts index 75acbae87d..43cae2733c 100644 --- a/packages/cli/src/utils/skillUtils.ts +++ b/packages/cli/src/utils/skillUtils.ts @@ -6,7 +6,11 @@ import { SettingScope } from '../config/settings.js'; import type { SkillActionResult } from './skillSettings.js'; -import { Storage, loadSkillsFromDir } from '@google/gemini-cli-core'; +import { + Storage, + loadSkillsFromDir, + type SkillDefinition, +} from '@google/gemini-cli-core'; import { cloneFromGit } from '../config/extensions/github.js'; import extract from 'extract-zip'; import * as fs from 'node:fs/promises'; @@ -79,6 +83,10 @@ export async function installSkill( scope: 'user' | 'workspace', subpath: string | undefined, onLog: (msg: string) => void, + requestConsent: ( + skills: SkillDefinition[], + targetDir: string, + ) => Promise = () => Promise.resolve(true), ): Promise> { let sourcePath = source; let tempDirToClean: string | undefined = undefined; @@ -90,85 +98,92 @@ export async function installSkill( const isSkillFile = source.toLowerCase().endsWith('.skill'); - if (isGitUrl) { - tempDirToClean = await fs.mkdtemp(path.join(os.tmpdir(), 'gemini-skill-')); - sourcePath = tempDirToClean; + try { + if (isGitUrl) { + tempDirToClean = await fs.mkdtemp( + path.join(os.tmpdir(), 'gemini-skill-'), + ); + sourcePath = tempDirToClean; - onLog(`Cloning skill from ${source}...`); - // Reuse existing robust git cloning utility from extension manager. - await cloneFromGit( - { - source, - type: 'git', - }, - tempDirToClean, - ); - } else if (isSkillFile) { - tempDirToClean = await fs.mkdtemp(path.join(os.tmpdir(), 'gemini-skill-')); - sourcePath = tempDirToClean; + onLog(`Cloning skill from ${source}...`); + // Reuse existing robust git cloning utility from extension manager. + await cloneFromGit( + { + source, + type: 'git', + }, + tempDirToClean, + ); + } else if (isSkillFile) { + tempDirToClean = await fs.mkdtemp( + path.join(os.tmpdir(), 'gemini-skill-'), + ); + sourcePath = tempDirToClean; - onLog(`Extracting skill from ${source}...`); - await extract(path.resolve(source), { dir: tempDirToClean }); - } + onLog(`Extracting skill from ${source}...`); + await extract(path.resolve(source), { dir: tempDirToClean }); + } - // If a subpath is provided, resolve it against the cloned/local root. - if (subpath) { - sourcePath = path.join(sourcePath, subpath); - } + // If a subpath is provided, resolve it against the cloned/local root. + if (subpath) { + sourcePath = path.join(sourcePath, subpath); + } - sourcePath = path.resolve(sourcePath); + sourcePath = path.resolve(sourcePath); - // Quick security check to prevent directory traversal out of temp dir when cloning - if (tempDirToClean && !sourcePath.startsWith(path.resolve(tempDirToClean))) { + // Quick security check to prevent directory traversal out of temp dir when cloning + if ( + tempDirToClean && + !sourcePath.startsWith(path.resolve(tempDirToClean)) + ) { + throw new Error('Invalid path: Directory traversal not allowed.'); + } + + onLog(`Searching for skills in ${sourcePath}...`); + const skills = await loadSkillsFromDir(sourcePath); + + if (skills.length === 0) { + throw new Error( + `No valid skills found in ${source}${subpath ? ` at path "${subpath}"` : ''}. Ensure a SKILL.md file exists with valid frontmatter.`, + ); + } + + const workspaceDir = process.cwd(); + const storage = new Storage(workspaceDir); + const targetDir = + scope === 'workspace' + ? storage.getProjectSkillsDir() + : Storage.getUserSkillsDir(); + + if (!(await requestConsent(skills, targetDir))) { + throw new Error('Skill installation cancelled by user.'); + } + + await fs.mkdir(targetDir, { recursive: true }); + + const installedSkills: Array<{ name: string; location: string }> = []; + + for (const skill of skills) { + const skillName = skill.name; + const skillDir = path.dirname(skill.location); + const destPath = path.join(targetDir, skillName); + + const exists = await fs.stat(destPath).catch(() => null); + if (exists) { + onLog(`Skill "${skillName}" already exists. Overwriting...`); + await fs.rm(destPath, { recursive: true, force: true }); + } + + await fs.cp(skillDir, destPath, { recursive: true }); + installedSkills.push({ name: skillName, location: destPath }); + } + + return installedSkills; + } finally { if (tempDirToClean) { await fs.rm(tempDirToClean, { recursive: true, force: true }); } - throw new Error('Invalid path: Directory traversal not allowed.'); } - - onLog(`Searching for skills in ${sourcePath}...`); - const skills = await loadSkillsFromDir(sourcePath); - - if (skills.length === 0) { - if (tempDirToClean) { - await fs.rm(tempDirToClean, { recursive: true, force: true }); - } - throw new Error( - `No valid skills found in ${source}${subpath ? ` at path "${subpath}"` : ''}. Ensure a SKILL.md file exists with valid frontmatter.`, - ); - } - - const workspaceDir = process.cwd(); - const storage = new Storage(workspaceDir); - const targetDir = - scope === 'workspace' - ? storage.getProjectSkillsDir() - : Storage.getUserSkillsDir(); - - await fs.mkdir(targetDir, { recursive: true }); - - const installedSkills: Array<{ name: string; location: string }> = []; - - for (const skill of skills) { - const skillName = skill.name; - const skillDir = path.dirname(skill.location); - const destPath = path.join(targetDir, skillName); - - const exists = await fs.stat(destPath).catch(() => null); - if (exists) { - onLog(`Skill "${skillName}" already exists. Overwriting...`); - await fs.rm(destPath, { recursive: true, force: true }); - } - - await fs.cp(skillDir, destPath, { recursive: true }); - installedSkills.push({ name: skillName, location: destPath }); - } - - if (tempDirToClean) { - await fs.rm(tempDirToClean, { recursive: true, force: true }); - } - - return installedSkills; } /** From 4f324b548ed2bc52f4c9d0977fa399cb16edaab0 Mon Sep 17 00:00:00 2001 From: ZhangYvJing Date: Thu, 15 Jan 2026 09:47:39 +0800 Subject: [PATCH 204/713] fix: replace 3 consecutive periods with ellipsis character (#16587) --- packages/cli/src/ui/constants/tips.ts | 300 +++++++++--------- packages/cli/src/ui/constants/wittyPhrases.ts | 236 +++++++------- 2 files changed, 268 insertions(+), 268 deletions(-) diff --git a/packages/cli/src/ui/constants/tips.ts b/packages/cli/src/ui/constants/tips.ts index 7322718d06..7d11c0826e 100644 --- a/packages/cli/src/ui/constants/tips.ts +++ b/packages/cli/src/ui/constants/tips.ts @@ -6,159 +6,159 @@ export const INFORMATIVE_TIPS = [ //Settings tips start here - 'Set your preferred editor for opening files (/settings)...', - 'Toggle Vim mode for a modal editing experience (/settings)...', - 'Disable automatic updates if you prefer manual control (/settings)...', - 'Turn off nagging update notifications (settings.json)...', - 'Enable checkpointing to recover your session after a crash (settings.json)...', - 'Change CLI output format to JSON for scripting (/settings)...', - 'Personalize your CLI with a new color theme (/settings)...', - 'Create and use your own custom themes (settings.json)...', - 'Hide window title for a more minimal UI (/settings)...', - "Don't like these tips? You can hide them (/settings)...", - 'Hide the startup banner for a cleaner launch (/settings)...', - 'Hide the context summary above the input (/settings)...', - 'Reclaim vertical space by hiding the footer (/settings)...', - 'Hide individual footer elements like CWD or sandbox status (/settings)...', - 'Hide the context window percentage in the footer (/settings)...', - 'Show memory usage for performance monitoring (/settings)...', - 'Show line numbers in the chat for easier reference (/settings)...', - 'Show citations to see where the model gets information (/settings)...', - 'Disable loading phrases for a quieter experience (/settings)...', - 'Add custom witty phrases to the loading screen (settings.json)...', - 'Use alternate screen buffer to preserve shell history (/settings)...', - 'Choose a specific Gemini model for conversations (/settings)...', - 'Limit the number of turns in your session history (/settings)...', - 'Automatically summarize large tool outputs to save tokens (settings.json)...', - 'Control when chat history gets compressed based on token usage (settings.json)...', - 'Define custom context file names, like CONTEXT.md (settings.json)...', - 'Set max directories to scan for context files (/settings)...', - 'Expand your workspace with additional directories (/directory)...', - 'Control how /memory refresh loads context files (/settings)...', - 'Toggle respect for .gitignore files in context (/settings)...', - 'Toggle respect for .geminiignore files in context (/settings)...', - 'Enable recursive file search for @-file completions (/settings)...', - 'Disable fuzzy search when searching for files (/settings)...', - 'Run tools in a secure sandbox environment (settings.json)...', - 'Use an interactive terminal for shell commands (/settings)...', - 'Show color in shell command output (/settings)...', - 'Automatically accept safe read-only tool calls (/settings)...', - 'Restrict available built-in tools (settings.json)...', - 'Exclude specific tools from being used (settings.json)...', - 'Bypass confirmation for trusted tools (settings.json)...', - 'Use a custom command for tool discovery (settings.json)...', - 'Define a custom command for calling discovered tools (settings.json)...', - 'Define and manage connections to MCP servers (settings.json)...', - 'Enable folder trust to enhance security (/settings)...', - 'Disable YOLO mode to enforce confirmations (settings.json)...', - 'Block Git extensions for enhanced security (settings.json)...', - 'Change your authentication method (/settings)...', - 'Enforce auth type for enterprise use (settings.json)...', - 'Let Node.js auto-configure memory (settings.json)...', - 'Retry on fetch failed errors automatically (settings.json)...', - 'Customize the DNS resolution order (settings.json)...', - 'Exclude env vars from the context (settings.json)...', - 'Configure a custom command for filing bug reports (settings.json)...', - 'Enable or disable telemetry collection (/settings)...', - 'Send telemetry data to a local file or GCP (settings.json)...', - 'Configure the OTLP endpoint for telemetry (settings.json)...', - 'Choose whether to log prompt content (settings.json)...', - 'Enable AI-powered prompt completion while typing (/settings)...', - 'Enable debug logging of keystrokes to the console (/settings)...', - 'Enable automatic session cleanup of old conversations (/settings)...', - 'Show Gemini CLI status in the terminal window title (/settings)...', - 'Use the entire width of the terminal for output (/settings)...', - 'Enable screen reader mode for better accessibility (/settings)...', - 'Skip the next speaker check for faster responses (/settings)...', - 'Use ripgrep for faster file content search (/settings)...', - 'Enable truncation of large tool outputs to save tokens (/settings)...', - 'Set the character threshold for truncating tool outputs (/settings)...', - 'Set the number of lines to keep when truncating outputs (/settings)...', - 'Enable policy-based tool confirmation via message bus (/settings)...', - 'Enable write_todos_list tool to generate task lists (/settings)...', - 'Enable model routing based on complexity (/settings)...', - 'Enable experimental subagents for task delegation (/settings)...', - 'Enable extension management features (settings.json)...', - 'Enable extension reloading within the CLI session (settings.json)...', + 'Set your preferred editor for opening files (/settings)…', + 'Toggle Vim mode for a modal editing experience (/settings)…', + 'Disable automatic updates if you prefer manual control (/settings)…', + 'Turn off nagging update notifications (settings.json)…', + 'Enable checkpointing to recover your session after a crash (settings.json)…', + 'Change CLI output format to JSON for scripting (/settings)…', + 'Personalize your CLI with a new color theme (/settings)…', + 'Create and use your own custom themes (settings.json)…', + 'Hide window title for a more minimal UI (/settings)…', + "Don't like these tips? You can hide them (/settings)…", + 'Hide the startup banner for a cleaner launch (/settings)…', + 'Hide the context summary above the input (/settings)…', + 'Reclaim vertical space by hiding the footer (/settings)…', + 'Hide individual footer elements like CWD or sandbox status (/settings)…', + 'Hide the context window percentage in the footer (/settings)…', + 'Show memory usage for performance monitoring (/settings)…', + 'Show line numbers in the chat for easier reference (/settings)…', + 'Show citations to see where the model gets information (/settings)…', + 'Disable loading phrases for a quieter experience (/settings)…', + 'Add custom witty phrases to the loading screen (settings.json)…', + 'Use alternate screen buffer to preserve shell history (/settings)…', + 'Choose a specific Gemini model for conversations (/settings)…', + 'Limit the number of turns in your session history (/settings)…', + 'Automatically summarize large tool outputs to save tokens (settings.json)…', + 'Control when chat history gets compressed based on token usage (settings.json)…', + 'Define custom context file names, like CONTEXT.md (settings.json)…', + 'Set max directories to scan for context files (/settings)…', + 'Expand your workspace with additional directories (/directory)…', + 'Control how /memory refresh loads context files (/settings)…', + 'Toggle respect for .gitignore files in context (/settings)…', + 'Toggle respect for .geminiignore files in context (/settings)…', + 'Enable recursive file search for @-file completions (/settings)…', + 'Disable fuzzy search when searching for files (/settings)…', + 'Run tools in a secure sandbox environment (settings.json)…', + 'Use an interactive terminal for shell commands (/settings)…', + 'Show color in shell command output (/settings)…', + 'Automatically accept safe read-only tool calls (/settings)…', + 'Restrict available built-in tools (settings.json)…', + 'Exclude specific tools from being used (settings.json)…', + 'Bypass confirmation for trusted tools (settings.json)…', + 'Use a custom command for tool discovery (settings.json)…', + 'Define a custom command for calling discovered tools (settings.json)…', + 'Define and manage connections to MCP servers (settings.json)…', + 'Enable folder trust to enhance security (/settings)…', + 'Disable YOLO mode to enforce confirmations (settings.json)…', + 'Block Git extensions for enhanced security (settings.json)…', + 'Change your authentication method (/settings)…', + 'Enforce auth type for enterprise use (settings.json)…', + 'Let Node.js auto-configure memory (settings.json)…', + 'Retry on fetch failed errors automatically (settings.json)…', + 'Customize the DNS resolution order (settings.json)…', + 'Exclude env vars from the context (settings.json)…', + 'Configure a custom command for filing bug reports (settings.json)…', + 'Enable or disable telemetry collection (/settings)…', + 'Send telemetry data to a local file or GCP (settings.json)…', + 'Configure the OTLP endpoint for telemetry (settings.json)…', + 'Choose whether to log prompt content (settings.json)…', + 'Enable AI-powered prompt completion while typing (/settings)…', + 'Enable debug logging of keystrokes to the console (/settings)…', + 'Enable automatic session cleanup of old conversations (/settings)…', + 'Show Gemini CLI status in the terminal window title (/settings)…', + 'Use the entire width of the terminal for output (/settings)…', + 'Enable screen reader mode for better accessibility (/settings)…', + 'Skip the next speaker check for faster responses (/settings)…', + 'Use ripgrep for faster file content search (/settings)…', + 'Enable truncation of large tool outputs to save tokens (/settings)…', + 'Set the character threshold for truncating tool outputs (/settings)…', + 'Set the number of lines to keep when truncating outputs (/settings)…', + 'Enable policy-based tool confirmation via message bus (/settings)…', + 'Enable write_todos_list tool to generate task lists (/settings)…', + 'Enable model routing based on complexity (/settings)…', + 'Enable experimental subagents for task delegation (/settings)…', + 'Enable extension management features (settings.json)…', + 'Enable extension reloading within the CLI session (settings.json)…', //Settings tips end here // Keyboard shortcut tips start here - 'Close dialogs and suggestions with Esc...', - 'Cancel a request with Ctrl+C, or press twice to exit...', - 'Exit the app with Ctrl+D on an empty line...', - 'Clear your screen at any time with Ctrl+L...', - 'Toggle the debug console display with F12...', - 'Toggle the todo list display with Ctrl+T...', - 'See full, untruncated responses with Ctrl+S...', - 'Toggle auto-approval (YOLO mode) for all tools with Ctrl+Y...', - 'Toggle auto-accepting edits approval mode with Shift+Tab...', - 'Toggle Markdown rendering (raw markdown mode) with Option+M...', - 'Toggle shell mode by typing ! in an empty prompt...', - 'Insert a newline with a backslash (\\) followed by Enter...', - 'Navigate your prompt history with the Up and Down arrows...', - 'You can also use Ctrl+P (up) and Ctrl+N (down) for history...', - 'Search through command history with Ctrl+R...', - 'Accept an autocomplete suggestion with Tab or Enter...', - 'Move to the start of the line with Ctrl+A or Home...', - 'Move to the end of the line with Ctrl+E or End...', - 'Move one character left or right with Ctrl+B/F or the arrow keys...', - 'Move one word left or right with Ctrl+Left/Right Arrow...', - 'Delete the character to the left with Ctrl+H or Backspace...', - 'Delete the character to the right with Ctrl+D or Delete...', - 'Delete the word to the left of the cursor with Ctrl+W...', - 'Delete the word to the right of the cursor with Ctrl+Delete...', - 'Delete from the cursor to the start of the line with Ctrl+U...', - 'Delete from the cursor to the end of the line with Ctrl+K...', - 'Clear the entire input prompt with a double-press of Esc...', - 'Paste from your clipboard with Ctrl+V...', - 'Undo text edits in the input with Ctrl+Z...', - 'Redo undone text edits with Ctrl+Shift+Z...', - 'Open the current prompt in an external editor with Ctrl+X...', - 'In menus, move up/down with k/j or the arrow keys...', - 'In menus, select an item by typing its number...', - "If you're using an IDE, see the context with Ctrl+G...", + 'Close dialogs and suggestions with Esc…', + 'Cancel a request with Ctrl+C, or press twice to exit…', + 'Exit the app with Ctrl+D on an empty line…', + 'Clear your screen at any time with Ctrl+L…', + 'Toggle the debug console display with F12…', + 'Toggle the todo list display with Ctrl+T…', + 'See full, untruncated responses with Ctrl+S…', + 'Toggle auto-approval (YOLO mode) for all tools with Ctrl+Y…', + 'Toggle auto-accepting edits approval mode with Shift+Tab…', + 'Toggle Markdown rendering (raw markdown mode) with Option+M…', + 'Toggle shell mode by typing ! in an empty prompt…', + 'Insert a newline with a backslash (\\) followed by Enter…', + 'Navigate your prompt history with the Up and Down arrows…', + 'You can also use Ctrl+P (up) and Ctrl+N (down) for history…', + 'Search through command history with Ctrl+R…', + 'Accept an autocomplete suggestion with Tab or Enter…', + 'Move to the start of the line with Ctrl+A or Home…', + 'Move to the end of the line with Ctrl+E or End…', + 'Move one character left or right with Ctrl+B/F or the arrow keys…', + 'Move one word left or right with Ctrl+Left/Right Arrow…', + 'Delete the character to the left with Ctrl+H or Backspace…', + 'Delete the character to the right with Ctrl+D or Delete…', + 'Delete the word to the left of the cursor with Ctrl+W…', + 'Delete the word to the right of the cursor with Ctrl+Delete…', + 'Delete from the cursor to the start of the line with Ctrl+U…', + 'Delete from the cursor to the end of the line with Ctrl+K…', + 'Clear the entire input prompt with a double-press of Esc…', + 'Paste from your clipboard with Ctrl+V…', + 'Undo text edits in the input with Ctrl+Z…', + 'Redo undone text edits with Ctrl+Shift+Z…', + 'Open the current prompt in an external editor with Ctrl+X…', + 'In menus, move up/down with k/j or the arrow keys…', + 'In menus, select an item by typing its number…', + "If you're using an IDE, see the context with Ctrl+G…", // Keyboard shortcut tips end here // Command tips start here - 'Show version info with /about...', - 'Change your authentication method with /auth...', - 'File a bug report directly with /bug...', - 'List your saved chat checkpoints with /chat list...', - 'Save your current conversation with /chat save ...', - 'Resume a saved conversation with /chat resume ...', - 'Delete a conversation checkpoint with /chat delete ...', - 'Share your conversation to a file with /chat share ...', - 'Clear the screen and history with /clear...', - 'Save tokens by summarizing the context with /compress...', - 'Copy the last response to your clipboard with /copy...', - 'Open the full documentation in your browser with /docs...', - 'Add directories to your workspace with /directory add ...', - 'Show all directories in your workspace with /directory show...', - 'Use /dir as a shortcut for /directory...', - 'Set your preferred external editor with /editor...', - 'List all active extensions with /extensions list...', - 'Update all or specific extensions with /extensions update...', - 'Get help on commands with /help...', - 'Manage IDE integration with /ide...', - 'Create a project-specific GEMINI.md file with /init...', - 'List configured MCP servers and tools with /mcp list...', - 'Authenticate with an OAuth-enabled MCP server with /mcp auth...', - 'Restart MCP servers with /mcp refresh...', - 'See the current instructional context with /memory show...', - 'Add content to the instructional memory with /memory add...', - 'Reload instructional context from GEMINI.md files with /memory refresh...', - 'List the paths of the GEMINI.md files in use with /memory list...', - 'Choose your Gemini model with /model...', - 'Display the privacy notice with /privacy...', - 'Restore project files to a previous state with /restore...', - 'Exit the CLI with /quit or /exit...', - 'Check model-specific usage stats with /stats model...', - 'Check tool-specific usage stats with /stats tools...', - "Change the CLI's color theme with /theme...", - 'List all available tools with /tools...', - 'View and edit settings with the /settings editor...', - 'Toggle Vim keybindings on and off with /vim...', - 'Set up GitHub Actions with /setup-github...', - 'Configure terminal keybindings for multiline input with /terminal-setup...', - 'Find relevant documentation with /find-docs...', - 'Execute any shell command with !...', + 'Show version info with /about…', + 'Change your authentication method with /auth…', + 'File a bug report directly with /bug…', + 'List your saved chat checkpoints with /chat list…', + 'Save your current conversation with /chat save …', + 'Resume a saved conversation with /chat resume …', + 'Delete a conversation checkpoint with /chat delete …', + 'Share your conversation to a file with /chat share …', + 'Clear the screen and history with /clear…', + 'Save tokens by summarizing the context with /compress…', + 'Copy the last response to your clipboard with /copy…', + 'Open the full documentation in your browser with /docs…', + 'Add directories to your workspace with /directory add …', + 'Show all directories in your workspace with /directory show…', + 'Use /dir as a shortcut for /directory…', + 'Set your preferred external editor with /editor…', + 'List all active extensions with /extensions list…', + 'Update all or specific extensions with /extensions update…', + 'Get help on commands with /help…', + 'Manage IDE integration with /ide…', + 'Create a project-specific GEMINI.md file with /init…', + 'List configured MCP servers and tools with /mcp list…', + 'Authenticate with an OAuth-enabled MCP server with /mcp auth…', + 'Restart MCP servers with /mcp refresh…', + 'See the current instructional context with /memory show…', + 'Add content to the instructional memory with /memory add…', + 'Reload instructional context from GEMINI.md files with /memory refresh…', + 'List the paths of the GEMINI.md files in use with /memory list…', + 'Choose your Gemini model with /model…', + 'Display the privacy notice with /privacy…', + 'Restore project files to a previous state with /restore…', + 'Exit the CLI with /quit or /exit…', + 'Check model-specific usage stats with /stats model…', + 'Check tool-specific usage stats with /stats tools…', + "Change the CLI's color theme with /theme…", + 'List all available tools with /tools…', + 'View and edit settings with the /settings editor…', + 'Toggle Vim keybindings on and off with /vim…', + 'Set up GitHub Actions with /setup-github…', + 'Configure terminal keybindings for multiline input with /terminal-setup…', + 'Find relevant documentation with /find-docs…', + 'Execute any shell command with !…', // Command tips end here ]; diff --git a/packages/cli/src/ui/constants/wittyPhrases.ts b/packages/cli/src/ui/constants/wittyPhrases.ts index 87473b52bb..a8facd9e5a 100644 --- a/packages/cli/src/ui/constants/wittyPhrases.ts +++ b/packages/cli/src/ui/constants/wittyPhrases.ts @@ -6,132 +6,132 @@ export const WITTY_LOADING_PHRASES = [ "I'm Feeling Lucky", - 'Shipping awesomeness... ', - 'Painting the serifs back on...', - 'Navigating the slime mold...', - 'Consulting the digital spirits...', - 'Reticulating splines...', - 'Warming up the AI hamsters...', - 'Asking the magic conch shell...', - 'Generating witty retort...', - 'Polishing the algorithms...', - "Don't rush perfection (or my code)...", - 'Brewing fresh bytes...', - 'Counting electrons...', - 'Engaging cognitive processors...', - 'Checking for syntax errors in the universe...', - 'One moment, optimizing humor...', - 'Shuffling punchlines...', - 'Untangling neural nets...', - 'Compiling brilliance...', - 'Loading wit.exe...', - 'Summoning the cloud of wisdom...', - 'Preparing a witty response...', - "Just a sec, I'm debugging reality...", - 'Confuzzling the options...', - 'Tuning the cosmic frequencies...', - 'Crafting a response worthy of your patience...', - 'Compiling the 1s and 0s...', - 'Resolving dependencies... and existential crises...', - 'Defragmenting memories... both RAM and personal...', - 'Rebooting the humor module...', - 'Caching the essentials (mostly cat memes)...', + 'Shipping awesomeness… ', + 'Painting the serifs back on…', + 'Navigating the slime mold…', + 'Consulting the digital spirits…', + 'Reticulating splines…', + 'Warming up the AI hamsters…', + 'Asking the magic conch shell…', + 'Generating witty retort…', + 'Polishing the algorithms…', + "Don't rush perfection (or my code)…", + 'Brewing fresh bytes…', + 'Counting electrons…', + 'Engaging cognitive processors…', + 'Checking for syntax errors in the universe…', + 'One moment, optimizing humor…', + 'Shuffling punchlines…', + 'Untangling neural nets…', + 'Compiling brilliance…', + 'Loading wit.exe…', + 'Summoning the cloud of wisdom…', + 'Preparing a witty response…', + "Just a sec, I'm debugging reality…", + 'Confuzzling the options…', + 'Tuning the cosmic frequencies…', + 'Crafting a response worthy of your patience…', + 'Compiling the 1s and 0s…', + 'Resolving dependencies… and existential crises…', + 'Defragmenting memories… both RAM and personal…', + 'Rebooting the humor module…', + 'Caching the essentials (mostly cat memes)…', 'Optimizing for ludicrous speed', - "Swapping bits... don't tell the bytes...", - 'Garbage collecting... be right back...', - 'Assembling the interwebs...', - 'Converting coffee into code...', - 'Updating the syntax for reality...', - 'Rewiring the synapses...', - 'Looking for a misplaced semicolon...', - "Greasin' the cogs of the machine...", - 'Pre-heating the servers...', - 'Calibrating the flux capacitor...', - 'Engaging the improbability drive...', - 'Channeling the Force...', - 'Aligning the stars for optimal response...', - 'So say we all...', - 'Loading the next great idea...', - "Just a moment, I'm in the zone...", - 'Preparing to dazzle you with brilliance...', - "Just a tick, I'm polishing my wit...", - "Hold tight, I'm crafting a masterpiece...", - "Just a jiffy, I'm debugging the universe...", - "Just a moment, I'm aligning the pixels...", - "Just a sec, I'm optimizing the humor...", - "Just a moment, I'm tuning the algorithms...", - 'Warp speed engaged...', - 'Mining for more Dilithium crystals...', - "Don't panic...", - 'Following the white rabbit...', - 'The truth is in here... somewhere...', - 'Blowing on the cartridge...', - 'Loading... Do a barrel roll!', - 'Waiting for the respawn...', - 'Finishing the Kessel Run in less than 12 parsecs...', - "The cake is not a lie, it's just still loading...", - 'Fiddling with the character creation screen...', - "Just a moment, I'm finding the right meme...", - "Pressing 'A' to continue...", - 'Herding digital cats...', - 'Polishing the pixels...', - 'Finding a suitable loading screen pun...', - 'Distracting you with this witty phrase...', - 'Almost there... probably...', - 'Our hamsters are working as fast as they can...', - 'Giving Cloudy a pat on the head...', - 'Petting the cat...', - 'Rickrolling my boss...', - 'Slapping the bass...', - 'Tasting the snozberries...', - "I'm going the distance, I'm going for speed...", - 'Is this the real life? Is this just fantasy?...', - "I've got a good feeling about this...", - 'Poking the bear...', - 'Doing research on the latest memes...', - 'Figuring out how to make this more witty...', - 'Hmmm... let me think...', - 'What do you call a fish with no eyes? A fsh...', - 'Why did the computer go to therapy? It had too many bytes...', - "Why don't programmers like nature? It has too many bugs...", - 'Why do programmers prefer dark mode? Because light attracts bugs...', - 'Why did the developer go broke? Because they used up all their cache...', - "What can you do with a broken pencil? Nothing, it's pointless...", - 'Applying percussive maintenance...', - 'Searching for the correct USB orientation...', - 'Ensuring the magic smoke stays inside the wires...', - 'Rewriting in Rust for no particular reason...', - 'Trying to exit Vim...', - 'Spinning up the hamster wheel...', - "That's not a bug, it's an undocumented feature...", + "Swapping bits… don't tell the bytes…", + 'Garbage collecting… be right back…', + 'Assembling the interwebs…', + 'Converting coffee into code…', + 'Updating the syntax for reality…', + 'Rewiring the synapses…', + 'Looking for a misplaced semicolon…', + "Greasin' the cogs of the machine…", + 'Pre-heating the servers…', + 'Calibrating the flux capacitor…', + 'Engaging the improbability drive…', + 'Channeling the Force…', + 'Aligning the stars for optimal response…', + 'So say we all…', + 'Loading the next great idea…', + "Just a moment, I'm in the zone…", + 'Preparing to dazzle you with brilliance…', + "Just a tick, I'm polishing my wit…", + "Hold tight, I'm crafting a masterpiece…", + "Just a jiffy, I'm debugging the universe…", + "Just a moment, I'm aligning the pixels…", + "Just a sec, I'm optimizing the humor…", + "Just a moment, I'm tuning the algorithms…", + 'Warp speed engaged…', + 'Mining for more Dilithium crystals…', + "Don't panic…", + 'Following the white rabbit…', + 'The truth is in here… somewhere…', + 'Blowing on the cartridge…', + 'Loading… Do a barrel roll!', + 'Waiting for the respawn…', + 'Finishing the Kessel Run in less than 12 parsecs…', + "The cake is not a lie, it's just still loading…", + 'Fiddling with the character creation screen…', + "Just a moment, I'm finding the right meme…", + "Pressing 'A' to continue…", + 'Herding digital cats…', + 'Polishing the pixels…', + 'Finding a suitable loading screen pun…', + 'Distracting you with this witty phrase…', + 'Almost there… probably…', + 'Our hamsters are working as fast as they can…', + 'Giving Cloudy a pat on the head…', + 'Petting the cat…', + 'Rickrolling my boss…', + 'Slapping the bass…', + 'Tasting the snozberries…', + "I'm going the distance, I'm going for speed…", + 'Is this the real life? Is this just fantasy?…', + "I've got a good feeling about this…", + 'Poking the bear…', + 'Doing research on the latest memes…', + 'Figuring out how to make this more witty…', + 'Hmmm… let me think…', + 'What do you call a fish with no eyes? A fsh…', + 'Why did the computer go to therapy? It had too many bytes…', + "Why don't programmers like nature? It has too many bugs…", + 'Why do programmers prefer dark mode? Because light attracts bugs…', + 'Why did the developer go broke? Because they used up all their cache…', + "What can you do with a broken pencil? Nothing, it's pointless…", + 'Applying percussive maintenance…', + 'Searching for the correct USB orientation…', + 'Ensuring the magic smoke stays inside the wires…', + 'Rewriting in Rust for no particular reason…', + 'Trying to exit Vim…', + 'Spinning up the hamster wheel…', + "That's not a bug, it's an undocumented feature…", 'Engage.', - "I'll be back... with an answer.", - 'My other process is a TARDIS...', - 'Communing with the machine spirit...', - 'Letting the thoughts marinate...', - 'Just remembered where I put my keys...', - 'Pondering the orb...', - "I've seen things you people wouldn't believe... like a user who reads loading messages.", - 'Initiating thoughtful gaze...', + "I'll be back… with an answer.", + 'My other process is a TARDIS…', + 'Communing with the machine spirit…', + 'Letting the thoughts marinate…', + 'Just remembered where I put my keys…', + 'Pondering the orb…', + "I've seen things you people wouldn't believe… like a user who reads loading messages.", + 'Initiating thoughtful gaze…', "What's a computer's favorite snack? Microchips.", "Why do Java developers wear glasses? Because they don't C#.", - 'Charging the laser... pew pew!', - 'Dividing by zero... just kidding!', - 'Looking for an adult superviso... I mean, processing.', + 'Charging the laser… pew pew!', + 'Dividing by zero… just kidding!', + 'Looking for an adult superviso… I mean, processing.', 'Making it go beep boop.', - 'Buffering... because even AIs need a moment.', - 'Entangling quantum particles for a faster response...', - 'Polishing the chrome... on the algorithms.', + 'Buffering… because even AIs need a moment.', + 'Entangling quantum particles for a faster response…', + 'Polishing the chrome… on the algorithms.', 'Are you not entertained? (Working on it!)', - 'Summoning the code gremlins... to help, of course.', - 'Just waiting for the dial-up tone to finish...', + 'Summoning the code gremlins… to help, of course.', + 'Just waiting for the dial-up tone to finish…', 'Recalibrating the humor-o-meter.', 'My other loading screen is even funnier.', - "Pretty sure there's a cat walking on the keyboard somewhere...", - 'Enhancing... Enhancing... Still loading.', - "It's not a bug, it's a feature... of this loading screen.", + "Pretty sure there's a cat walking on the keyboard somewhere…", + 'Enhancing… Enhancing… Still loading.', + "It's not a bug, it's a feature… of this loading screen.", 'Have you tried turning it off and on again? (The loading screen, not me.)', - 'Constructing additional pylons...', + 'Constructing additional pylons…', 'New line? That’s Ctrl+J.', - 'Releasing the HypnoDrones...', + 'Releasing the HypnoDrones…', ]; From 467e86932629c4603ad7a7d87112bb7f682799bb Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Wed, 14 Jan 2026 20:58:50 -0500 Subject: [PATCH 205/713] chore(automation): ensure status/need-triage is applied and never cleared automatically (#16657) --- .github/scripts/backfill-need-triage.cjs | 138 ++++++++++++++++++ .github/scripts/pr-triage.sh | 51 ++++--- .../gemini-automated-issue-triage.yml | 19 +-- .../gemini-scheduled-issue-triage.yml | 25 +--- .github/workflows/issue-opened-labeler.yml | 46 ++++++ scripts/batch_triage.sh | 24 +-- scripts/relabel_issues.sh | 32 ++-- scripts/send_gemini_request.sh | 31 ++-- 8 files changed, 268 insertions(+), 98 deletions(-) create mode 100644 .github/scripts/backfill-need-triage.cjs create mode 100644 .github/workflows/issue-opened-labeler.yml diff --git a/.github/scripts/backfill-need-triage.cjs b/.github/scripts/backfill-need-triage.cjs new file mode 100644 index 0000000000..e621396528 --- /dev/null +++ b/.github/scripts/backfill-need-triage.cjs @@ -0,0 +1,138 @@ +/* eslint-disable */ +/* global require, console, process */ + +/** + * Script to backfill the 'status/need-triage' label to all open issues + * that are NOT currently labeled with '🔒 maintainer only' or 'help wanted'. + */ + +const { execFileSync } = require('child_process'); + +const isDryRun = process.argv.includes('--dry-run'); +const REPO = 'google-gemini/gemini-cli'; + +/** + * Executes a GitHub CLI command safely using an argument array to prevent command injection. + * @param {string[]} args + * @returns {string|null} + */ +function runGh(args) { + try { + // Using execFileSync with an array of arguments is safe as it doesn't use a shell. + // We set a large maxBuffer (10MB) to handle repositories with many issues. + return execFileSync('gh', args, { + encoding: 'utf8', + maxBuffer: 10 * 1024 * 1024, + stdio: ['ignore', 'pipe', 'pipe'], + }).trim(); + } catch (error) { + const stderr = error.stderr ? ` Stderr: ${error.stderr.trim()}` : ''; + console.error( + `❌ Error running gh ${args.join(' ')}: ${error.message}${stderr}`, + ); + return null; + } +} + +async function main() { + console.log('🔐 GitHub CLI security check...'); + const authStatus = runGh(['auth', 'status']); + if (authStatus === null) { + console.error('❌ GitHub CLI (gh) is not installed or not authenticated.'); + process.exit(1); + } + + if (isDryRun) { + console.log('🧪 DRY RUN MODE ENABLED - No changes will be made.\n'); + } + + console.log(`🔍 Fetching and filtering open issues from ${REPO}...`); + + // We use the /issues endpoint with pagination to bypass the 1000-result limit. + // The jq filter ensures we exclude PRs, maintainer-only, help-wanted, and existing status/need-triage. + const jqFilter = + '.[] | select(.pull_request == null) | select([.labels[].name] as $l | (any($l[]; . == "🔒 maintainer only") | not) and (any($l[]; . == "help wanted") | not) and (any($l[]; . == "status/need-triage") | not)) | {number: .number, title: .title}'; + + const output = runGh([ + 'api', + `repos/${REPO}/issues?state=open&per_page=100`, + '--paginate', + '--jq', + jqFilter, + ]); + + if (output === null) { + process.exit(1); + } + + const issues = output + .split('\n') + .filter((line) => line.trim()) + .map((line) => { + try { + return JSON.parse(line); + } catch (_e) { + console.error(`⚠️ Failed to parse line: ${line}`); + return null; + } + }) + .filter(Boolean); + + console.log(`✅ Found ${issues.length} issues matching criteria.`); + + if (issues.length === 0) { + console.log('✨ No issues need backfilling.'); + return; + } + + let successCount = 0; + let failCount = 0; + + if (isDryRun) { + for (const issue of issues) { + console.log( + `[DRY RUN] Would label issue #${issue.number}: ${issue.title}`, + ); + } + successCount = issues.length; + } else { + console.log(`🏷️ Applying labels to ${issues.length} issues...`); + + for (const issue of issues) { + const issueNumber = String(issue.number); + console.log(`🏷️ Labeling issue #${issueNumber}: ${issue.title}`); + + const result = runGh([ + 'issue', + 'edit', + issueNumber, + '--add-label', + 'status/need-triage', + '--repo', + REPO, + ]); + + if (result !== null) { + successCount++; + } else { + failCount++; + } + } + } + + console.log(`\n📊 Summary:`); + console.log(` - Success: ${successCount}`); + console.log(` - Failed: ${failCount}`); + + if (failCount > 0) { + console.error(`\n❌ Backfill completed with ${failCount} errors.`); + process.exit(1); + } else { + console.log(`\n🎉 ${isDryRun ? 'Dry run' : 'Backfill'} complete!`); + } +} + +main().catch((error) => { + console.error('❌ Unexpected error:', error); + process.exit(1); +}); diff --git a/.github/scripts/pr-triage.sh b/.github/scripts/pr-triage.sh index ddbe4182ce..2052406869 100755 --- a/.github/scripts/pr-triage.sh +++ b/.github/scripts/pr-triage.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash +# @license +# Copyright 2026 Google LLC +# SPDX-License-Identifier: Apache-2.0 + set -euo pipefail # Initialize a comma-separated string to hold PR numbers that need a comment @@ -10,7 +14,7 @@ ISSUE_LABELS_CACHE_FLAT="" # Function to get area and priority labels from an issue (with caching) get_issue_labels() { - local ISSUE_NUM=$1 + local ISSUE_NUM="${1}" if [[ -z "${ISSUE_NUM}" || "${ISSUE_NUM}" == "null" || "${ISSUE_NUM}" == "" ]]; then return fi @@ -18,10 +22,13 @@ get_issue_labels() { # Check cache case " ${ISSUE_LABELS_CACHE_FLAT} " in *" ${ISSUE_NUM}:"*) - local suffix="${ISSUE_LABELS_CACHE_FLAT#* ${ISSUE_NUM}:}" + local suffix="${ISSUE_LABELS_CACHE_FLAT#* " ${ISSUE_NUM}:"}" echo "${suffix%% *}" return ;; + *) + # Cache miss, proceed to fetch + ;; esac echo " 📥 Fetching area and priority labels from issue #${ISSUE_NUM}" >&2 @@ -33,19 +40,19 @@ get_issue_labels() { fi local labels - labels=$(echo "${gh_output}" | grep -E "^(area|priority)/" | tr '\n' ',' | sed 's/,$//' || echo "") + labels=$(echo "${gh_output}" | grep -E '^(area|priority)/' | tr '\n' ',' | sed 's/,$//' || echo "") # Save to flat cache ISSUE_LABELS_CACHE_FLAT="${ISSUE_LABELS_CACHE_FLAT} ${ISSUE_NUM}:${labels}" - echo "$labels" + echo "${labels}" } # Function to process a single PR with pre-fetched data process_pr_optimized() { - local PR_NUMBER=$1 - local IS_DRAFT=$2 - local ISSUE_NUMBER=$3 - local CURRENT_LABELS=$4 # Comma-separated labels + local PR_NUMBER="${1}" + local IS_DRAFT="${2}" + local ISSUE_NUMBER="${3}" + local CURRENT_LABELS="${4}" # Comma-separated labels echo "🔄 Processing PR #${PR_NUMBER}" @@ -84,7 +91,7 @@ process_pr_optimized() { ISSUE_LABELS=$(get_issue_labels "${ISSUE_NUMBER}") if [[ -n "${ISSUE_LABELS}" ]]; then - local IFS_OLD=$IFS + local IFS_OLD="${IFS}" IFS=',' for label in ${ISSUE_LABELS}; do if [[ -n "${label}" ]] && [[ ",${CURRENT_LABELS}," != *",${label},"* ]]; then @@ -94,8 +101,8 @@ process_pr_optimized() { LABELS_TO_ADD="${LABELS_TO_ADD},${label}" fi fi - done - IFS=$IFS_OLD +done + IFS="${IFS_OLD}" fi if [[ -z "${LABELS_TO_ADD}" && -z "${LABELS_TO_REMOVE}" ]]; then @@ -135,7 +142,7 @@ JQ_EXTRACT_FIELDS='{ labels: [.labels[].name] | join(",") }' -JQ_TSV_FORMAT='"\((.number | tostring))\t\(.isDraft)\t\((.issue // "null") | tostring)\t\(.labels)"' +JQ_TSV_FORMAT='"\((.number | tostring))\t\(.isDraft)\t\((.issue // \"null\") | tostring)\t\(.labels)"' # Corrected escaping for quotes within the string literal if [[ -n "${PR_NUMBER:-}" ]]; then echo "🔄 Processing single PR #${PR_NUMBER}" @@ -144,9 +151,9 @@ if [[ -n "${PR_NUMBER:-}" ]]; then exit 1 } - line=$(echo "$PR_DATA" | jq -r "$JQ_EXTRACT_FIELDS | $JQ_TSV_FORMAT") - IFS=$'\t' read -r pr_num is_draft issue_num current_labels <<< "$line" - process_pr_optimized "$pr_num" "$is_draft" "$issue_num" "$current_labels" + line=$(echo "${PR_DATA}" | jq -r "${JQ_EXTRACT_FIELDS} | ${JQ_TSV_FORMAT}") + IFS=$'\t' read -r pr_num is_draft issue_num current_labels <<< "${line}" + process_pr_optimized "${pr_num}" "${is_draft}" "${issue_num}" "${current_labels}" else echo "📥 Getting all open pull requests..." PR_DATA_ALL=$(gh pr list --repo "${GITHUB_REPOSITORY}" --state open --limit 1000 --json number,closingIssuesReferences,isDraft,body,labels 2>/dev/null) || { @@ -157,11 +164,15 @@ else PR_COUNT=$(echo "${PR_DATA_ALL}" | jq '. | length') echo "📊 Found ${PR_COUNT} open PRs to process" + # Use a temporary file to avoid masking exit codes in process substitution + tmp_file=$(mktemp) + echo "${PR_DATA_ALL}" | jq -r ".[] | ${JQ_EXTRACT_FIELDS} | ${JQ_TSV_FORMAT}" > "${tmp_file}" while read -r line; do - [[ -z "$line" ]] && continue - IFS=$'\t' read -r pr_num is_draft issue_num current_labels <<< "$line" - process_pr_optimized "$pr_num" "$is_draft" "$issue_num" "$current_labels" - done < <(echo "${PR_DATA_ALL}" | jq -r ".[] | $JQ_EXTRACT_FIELDS | $JQ_TSV_FORMAT") + [[ -z "${line}" ]] && continue + IFS=$'\t' read -r pr_num is_draft issue_num current_labels <<< "${line}" + process_pr_optimized "${pr_num}" "${is_draft}" "${issue_num}" "${current_labels}" + done < "${tmp_file}" + rm -f "${tmp_file}" fi if [[ -z "${PRS_NEEDING_COMMENT}" ]]; then @@ -170,4 +181,4 @@ else echo "prs_needing_comment=[${PRS_NEEDING_COMMENT}]" >> "${GITHUB_OUTPUT}" fi -echo "✅ PR triage completed" \ No newline at end of file +echo "✅ PR triage completed" diff --git a/.github/workflows/gemini-automated-issue-triage.yml b/.github/workflows/gemini-automated-issue-triage.yml index 47801fcb9b..08b97db0a2 100644 --- a/.github/workflows/gemini-automated-issue-triage.yml +++ b/.github/workflows/gemini-automated-issue-triage.yml @@ -95,7 +95,8 @@ jobs: id: 'generate_token' env: APP_ID: '${{ secrets.APP_ID }}' - if: "${{ env.APP_ID != '' }}" + if: |- + ${{ env.APP_ID != '' }} uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2 with: app-id: '${{ secrets.APP_ID }}' @@ -305,22 +306,6 @@ jobs: }); core.info(`Successfully added labels for #${issueNumber}: ${labelsToAdd.join(', ')}`); - // Remove the 'status/need-triage' label - try { - await github.rest.issues.removeLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueNumber, - name: 'status/need-triage' - }); - core.info(`Successfully removed 'status/need-triage' label.`); - } catch (error) { - // If the label doesn't exist, the API call will throw a 404. We can ignore this. - if (error.status !== 404) { - core.warning(`Failed to remove 'status/need-triage': ${error.message}`); - } - } - - name: 'Post Issue Analysis Failure Comment' if: |- ${{ failure() && steps.gemini_issue_analysis.outcome == 'failure' }} diff --git a/.github/workflows/gemini-scheduled-issue-triage.yml b/.github/workflows/gemini-scheduled-issue-triage.yml index 7a966d59aa..25b0cdf4ec 100644 --- a/.github/workflows/gemini-scheduled-issue-triage.yml +++ b/.github/workflows/gemini-scheduled-issue-triage.yml @@ -40,7 +40,8 @@ jobs: permission-issues: 'write' - name: 'Get issue from event' - if: "github.event_name == 'issues'" + if: |- + ${{ github.event_name == 'issues' }} id: 'get_issue_from_event' env: ISSUE_EVENT: '${{ toJSON(github.event.issue) }}' @@ -51,7 +52,8 @@ jobs: echo "✅ Found issue #${{ github.event.issue.number }} from event to triage! 🎯" - name: 'Find untriaged issues' - if: "github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'" + if: |- + ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} id: 'find_issues' env: GITHUB_TOKEN: '${{ steps.generate_token.outputs.token }}' @@ -161,7 +163,6 @@ jobs: 9. For each issue please check if CLI version is present, this is usually in the output of the /about command and will look like 0.1.5 - Anything more than 6 versions older than the most recent should add the status/need-retesting label 10. If you see that the issue doesn't look like it has sufficient information recommend the status/need-information label and leave a comment politely requesting the relevant information, eg.. if repro steps are missing request for repro steps. if version information is missing request for version information into the explanation section below. - - After identifying appropriate labels to an issue, add "status/need-triage" label to labels_to_remove in the output. 11. If you think an issue might be a Priority/P0 do not apply the priority/p0 label. Instead apply a status/manual-triage label and include a note in your explanation. 12. If you are uncertain about a category, use the area/unknown, kind/question, or priority/unknown labels as appropriate. If you are extremely uncertain, apply the status/manual-triage label. @@ -262,24 +263,6 @@ jobs: core.info(`Successfully added labels for #${issueNumber}: ${labelsToAdd.join(', ')}${explanation}`); } - if (entry.labels_to_remove && entry.labels_to_remove.length > 0) { - for (const label of entry.labels_to_remove) { - try { - await github.rest.issues.removeLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueNumber, - name: label - }); - } catch (error) { - if (error.status !== 404) { - throw error; - } - } - } - core.info(`Successfully removed labels for #${issueNumber}: ${entry.labels_to_remove.join(', ')}`); - } - if (entry.explanation) { await github.rest.issues.createComment({ owner: context.repo.owner, diff --git a/.github/workflows/issue-opened-labeler.yml b/.github/workflows/issue-opened-labeler.yml new file mode 100644 index 0000000000..69a0911954 --- /dev/null +++ b/.github/workflows/issue-opened-labeler.yml @@ -0,0 +1,46 @@ +name: '🏷️ Issue Opened Labeler' + +on: + issues: + types: + - 'opened' + +jobs: + label-issue: + runs-on: 'ubuntu-latest' + if: |- + ${{ github.repository == 'google-gemini/gemini-cli' || github.repository == 'google-gemini/maintainers-gemini-cli' }} + steps: + - name: 'Generate GitHub App Token' + id: 'generate_token' + env: + APP_ID: '${{ secrets.APP_ID }}' + if: |- + ${{ env.APP_ID != '' }} + uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2 + with: + app-id: '${{ secrets.APP_ID }}' + private-key: '${{ secrets.PRIVATE_KEY }}' + + - name: 'Add need-triage label' + uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' + with: + github-token: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}' + script: |- + const { data: issue } = await github.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + const hasLabel = issue.labels.some(l => l.name === 'status/need-triage'); + if (!hasLabel) { + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + labels: ['status/need-triage'] + }); + } else { + core.info('Issue already has status/need-triage label. Skipping.'); + } diff --git a/scripts/batch_triage.sh b/scripts/batch_triage.sh index c6f1982491..1f4a84b97a 100755 --- a/scripts/batch_triage.sh +++ b/scripts/batch_triage.sh @@ -4,37 +4,39 @@ # Example: ./scripts/batch_triage.sh google-gemini/maintainers-gemini-cli set -e +set -o pipefail REPO="${1:-google-gemini/gemini-cli}" WORKFLOW="gemini-automated-issue-triage.yml" -echo "🔍 Searching for open issues in '$REPO' that need triage (missing 'area/' label)..." +echo "🔍 Searching for open issues in '${REPO}' that need triage (missing 'area/' label)..." # Fetch open issues with number, title, and labels # We fetch up to 1000 issues. -ISSUES_JSON=$(gh issue list --repo "$REPO" --state open --limit 1000 --json number,title,labels) +ISSUES_JSON=$(gh issue list --repo "${REPO}" --state open --limit 1000 --json number,title,labels) # Filter issues that DO NOT have a label starting with 'area/' -TARGET_ISSUES=$(echo "$ISSUES_JSON" | jq '[.[] | select(.labels | map(.name) | any(startswith("area/")) | not)]') +TARGET_ISSUES=$(echo "${ISSUES_JSON}" | jq '[.[] | select(.labels | map(.name) | any(startswith("area/")) | not)]') -COUNT=$(echo "$TARGET_ISSUES" | jq '. | length') +# Avoid masking return value +COUNT=$(jq '. | length' <<< "${TARGET_ISSUES}") -if [ "$COUNT" -eq 0 ]; then - echo "✅ No issues found needing triage in '$REPO'." +if [[ "${COUNT}" -eq 0 ]]; then + echo "✅ No issues found needing triage in '${REPO}'." exit 0 fi -echo "🚀 Found $COUNT issues to triage." +echo "🚀 Found ${COUNT} issues to triage." # Loop through and trigger workflow -echo "$TARGET_ISSUES" | jq -r '.[] | "\(.number)|\(.title)"' | while IFS="|" read -r number title; do - echo "▶️ Triggering triage for #$number: $title" +echo "${TARGET_ISSUES}" | jq -r '.[] | "\(.number)|\(.title)"' | while IFS="|" read -r number title; do + echo "▶️ Triggering triage for #${number}: ${title}" # Trigger the workflow dispatch event - gh workflow run "$WORKFLOW" --repo "$REPO" -f issue_number="$number" + gh workflow run "${WORKFLOW}" --repo "${REPO}" -f issue_number="${number}" # Sleep briefly to be nice to the API sleep 1 done -echo "🎉 All triage workflows triggered!" +echo "🎉 All triage workflows triggered!" \ No newline at end of file diff --git a/scripts/relabel_issues.sh b/scripts/relabel_issues.sh index 82857bfa45..9e8a776440 100755 --- a/scripts/relabel_issues.sh +++ b/scripts/relabel_issues.sh @@ -3,40 +3,42 @@ # Usage: ./scripts/relabel_issues.sh [repository] set -e +set -o pipefail -OLD_LABEL="$1" -NEW_LABEL="$2" +OLD_LABEL="${1}" +NEW_LABEL="${2}" REPO="${3:-google-gemini/gemini-cli}" -if [ -z "$OLD_LABEL" ] || [ -z "$NEW_LABEL" ]; then +if [[ -z "${OLD_LABEL}" ]] || [[ -z "${NEW_LABEL}" ]]; then echo "Usage: $0 [repository]" echo "Example: $0 'area/models' 'area/agent'" exit 1 fi -echo "🔍 Searching for open issues in '$REPO' with label '$OLD_LABEL'..." +echo "🔍 Searching for open issues in '${REPO}' with label '${OLD_LABEL}'..." # Fetch issues with the old label -ISSUES=$(gh issue list --repo "$REPO" --label "$OLD_LABEL" --state open --limit 1000 --json number,title) +ISSUES=$(gh issue list --repo "${REPO}" --label "${OLD_LABEL}" --state open --limit 1000 --json number,title) -COUNT=$(echo "$ISSUES" | jq '. | length') +# Avoid masking return value +COUNT=$(jq '. | length' <<< "${ISSUES}") -if [ "$COUNT" -eq 0 ]; then - echo "✅ No issues found with label '$OLD_LABEL'." +if [[ "${COUNT}" -eq 0 ]]; then + echo "✅ No issues found with label '${OLD_LABEL}'." exit 0 fi -echo "found $COUNT issues to relabel." +echo "found ${COUNT} issues to relabel." # Iterate and update -echo "$ISSUES" | jq -r '.[] | "\(.number) \(.title)"' | while read -r number title; do - echo "🔄 Processing #$number: $title" - echo " - Removing: $OLD_LABEL" - echo " + Adding: $NEW_LABEL" +echo "${ISSUES}" | jq -r '.[] | "\(.number) \(.title)"' | while read -r number title; do + echo "🔄 Processing #${number}: ${title}" + echo " - Removing: ${OLD_LABEL}" + echo " + Adding: ${NEW_LABEL}" - gh issue edit "$number" --repo "$REPO" --add-label "$NEW_LABEL" --remove-label "$OLD_LABEL" + gh issue edit "${number}" --repo "${REPO}" --add-label "${NEW_LABEL}" --remove-label "${OLD_LABEL}" echo " ✅ Done." done -echo "🎉 All issues relabeled!" +echo "🎉 All issues relabeled!" \ No newline at end of file diff --git a/scripts/send_gemini_request.sh b/scripts/send_gemini_request.sh index 18cedfa5bf..ebccf7e89b 100755 --- a/scripts/send_gemini_request.sh +++ b/scripts/send_gemini_request.sh @@ -30,9 +30,10 @@ set -e -E # Load environment variables from .env if it exists -if [ -f ".env" ]; then +if [[ -f ".env" ]]; then echo "Loading environment variables from .env file..." set -a # Automatically export all variables + # shellcheck source=/dev/null source .env set +a fi @@ -49,32 +50,32 @@ STREAM_MODE=false # Parse command line arguments while [[ "$#" -gt 0 ]]; do case $1 in - --payload) PAYLOAD_FILE="$2"; shift ;; - --model) MODEL_ID="$2"; shift ;; + --payload) PAYLOAD_FILE="${2}"; shift ;; + --model) MODEL_ID="${2}"; shift ;; --stream) STREAM_MODE=true ;; - *) echo "Unknown parameter passed: $1"; usage ;; + *) echo "Unknown parameter passed: ${1}"; usage ;; esac shift done # Validate inputs -if [ -z "$PAYLOAD_FILE" ] || [ -z "$MODEL_ID" ]; then +if [[ -z "${PAYLOAD_FILE}" ]] || [[ -z "${MODEL_ID}" ]]; then echo "Error: Missing required arguments." usage fi -if [ -z "$GEMINI_API_KEY" ]; then +if [[ -z "${GEMINI_API_KEY}" ]]; then echo "Error: GEMINI_API_KEY environment variable is not set." exit 1 fi -if [ ! -f "$PAYLOAD_FILE" ]; then - echo "Error: Payload file '$PAYLOAD_FILE' does not exist." +if [[ ! -f "${PAYLOAD_FILE}" ]]; then + echo "Error: Payload file '${PAYLOAD_FILE}' does not exist." exit 1 fi # API Endpoint definition -if [ "$STREAM_MODE" = true ]; then +if [[ "${STREAM_MODE}" = true ]]; then GENERATE_CONTENT_API="streamGenerateContent" echo "Mode: Streaming" else @@ -82,16 +83,18 @@ else echo "Mode: Non-streaming (Default)" fi -echo "Sending request to model: $MODEL_ID" -echo "Using payload from: $PAYLOAD_FILE" +echo "Sending request to model: ${MODEL_ID}" +echo "Using payload from: ${PAYLOAD_FILE}" echo "----------------------------------------" # Make the cURL request. If non-streaming, pipe through jq for readability if available. -if [ "$STREAM_MODE" = false ] && command -v jq &> /dev/null; then - curl -s -X POST \ +if [[ "${STREAM_MODE}" = false ]] && command -v jq &> /dev/null; then + # Invoke curl separately to avoid masking its return value + output=$(curl -s -X POST \ -H "Content-Type: application/json" \ "https://generativelanguage.googleapis.com/v1beta/models/${MODEL_ID}:${GENERATE_CONTENT_API}?key=${GEMINI_API_KEY}" \ - -d "@${PAYLOAD_FILE}" | jq . + -d "@${PAYLOAD_FILE}") + echo "${output}" | jq . else curl -X POST \ -H "Content-Type: application/json" \ From 4848f42486c958c68d979fcbee2f7f0f616e37d3 Mon Sep 17 00:00:00 2001 From: maruto <53184634+maru0804@users.noreply.github.com> Date: Thu, 15 Jan 2026 11:10:21 +0900 Subject: [PATCH 206/713] fix: Handle colons in skill description frontmatter (#16345) Co-authored-by: gemini-code-assist[bot] --- packages/core/src/skills/skillLoader.test.ts | 94 ++++++++++++++++++++ packages/core/src/skills/skillLoader.ts | 81 +++++++++++++++-- 2 files changed, 166 insertions(+), 9 deletions(-) diff --git a/packages/core/src/skills/skillLoader.test.ts b/packages/core/src/skills/skillLoader.test.ts index 9f46f9ae4c..7c74ff2f37 100644 --- a/packages/core/src/skills/skillLoader.test.ts +++ b/packages/core/src/skills/skillLoader.test.ts @@ -100,4 +100,98 @@ describe('skillLoader', () => { expect(skills).toEqual([]); expect(coreEvents.emitFeedback).not.toHaveBeenCalled(); }); + + it('should parse skill with colon in description (issue #16323)', async () => { + const skillDir = path.join(testRootDir, 'colon-skill'); + await fs.mkdir(skillDir, { recursive: true }); + const skillFile = path.join(skillDir, 'SKILL.md'); + await fs.writeFile( + skillFile, + `--- +name: foo +description: Simple story generation assistant for fiction writing. Use for creating characters, scenes, storylines, and prose. Trigger words: character, scene, storyline, story, prose, fiction, writing. +--- +# Instructions +Do something. +`, + ); + + const skills = await loadSkillsFromDir(testRootDir); + + expect(skills).toHaveLength(1); + expect(skills[0].name).toBe('foo'); + expect(skills[0].description).toContain('Trigger words:'); + }); + + it('should parse skill with multiple colons in description', async () => { + const skillDir = path.join(testRootDir, 'multi-colon-skill'); + await fs.mkdir(skillDir, { recursive: true }); + const skillFile = path.join(skillDir, 'SKILL.md'); + await fs.writeFile( + skillFile, + `--- +name: multi-colon +description: Use this for tasks like: coding, reviewing, testing. Keywords: async, await, promise. +--- +# Instructions +Do something. +`, + ); + + const skills = await loadSkillsFromDir(testRootDir); + + expect(skills).toHaveLength(1); + expect(skills[0].name).toBe('multi-colon'); + expect(skills[0].description).toContain('tasks like:'); + expect(skills[0].description).toContain('Keywords:'); + }); + + it('should parse skill with quoted YAML description (backward compatibility)', async () => { + const skillDir = path.join(testRootDir, 'quoted-skill'); + await fs.mkdir(skillDir, { recursive: true }); + const skillFile = path.join(skillDir, 'SKILL.md'); + await fs.writeFile( + skillFile, + `--- +name: quoted-skill +description: "A skill with colons: like this one: and another." +--- +# Instructions +Do something. +`, + ); + + const skills = await loadSkillsFromDir(testRootDir); + + expect(skills).toHaveLength(1); + expect(skills[0].name).toBe('quoted-skill'); + expect(skills[0].description).toBe( + 'A skill with colons: like this one: and another.', + ); + }); + + it('should parse skill with multi-line YAML description', async () => { + const skillDir = path.join(testRootDir, 'multiline-skill'); + await fs.mkdir(skillDir, { recursive: true }); + const skillFile = path.join(skillDir, 'SKILL.md'); + await fs.writeFile( + skillFile, + `--- +name: multiline-skill +description: + Expertise in reviewing code for style, security, and performance. Use when the + user asks for "feedback," a "review," or to "check" their changes. +--- +# Instructions +Do something. +`, + ); + + const skills = await loadSkillsFromDir(testRootDir); + + expect(skills).toHaveLength(1); + expect(skills[0].name).toBe('multiline-skill'); + expect(skills[0].description).toContain('Expertise in reviewing code'); + expect(skills[0].description).toContain('check'); + }); }); diff --git a/packages/core/src/skills/skillLoader.ts b/packages/core/src/skills/skillLoader.ts index 995d8160f0..f25d55f08b 100644 --- a/packages/core/src/skills/skillLoader.ts +++ b/packages/core/src/skills/skillLoader.ts @@ -32,6 +32,74 @@ export interface SkillDefinition { export const FRONTMATTER_REGEX = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?/; +/** + * Parses frontmatter content using YAML with a fallback to simple key-value parsing. + * This handles cases where description contains colons that would break YAML parsing. + */ +function parseFrontmatter( + content: string, +): { name: string; description: string } | null { + try { + const parsed = yaml.load(content); + if (parsed && typeof parsed === 'object') { + const { name, description } = parsed as Record; + if (typeof name === 'string' && typeof description === 'string') { + return { name, description }; + } + } + } catch (yamlError) { + debugLogger.debug( + 'YAML frontmatter parsing failed, falling back to simple parser:', + yamlError, + ); + } + + return parseSimpleFrontmatter(content); +} + +/** + * Simple frontmatter parser that extracts name and description fields. + * Handles cases where values contain colons that would break YAML parsing. + */ +function parseSimpleFrontmatter( + content: string, +): { name: string; description: string } | null { + const lines = content.split(/\r?\n/); + let name: string | undefined; + let description: string | undefined; + + for (let i = 0; i < lines.length; i++) { + const line = lines[i]; + + if (line.startsWith('name:')) { + name = line.substring(5).trim(); + continue; + } + + if (line.startsWith('description:')) { + const descLines = [line.substring(12).trim()]; + + while (i + 1 < lines.length) { + const nextLine = lines[i + 1]; + if (nextLine.match(/^[ \t]+\S/)) { + descLines.push(nextLine.trim()); + i++; + } else { + break; + } + } + + description = descLines.filter(Boolean).join(' '); + continue; + } + } + + if (name !== undefined && description !== undefined) { + return { name, description }; + } + return null; +} + /** * Discovers and loads all skills in the provided directory. */ @@ -92,19 +160,14 @@ export async function loadSkillFromFile( return null; } - const frontmatter = yaml.load(match[1]); - if (!frontmatter || typeof frontmatter !== 'object') { - return null; - } - - const { name, description } = frontmatter as Record; - if (typeof name !== 'string' || typeof description !== 'string') { + const frontmatter = parseFrontmatter(match[1]); + if (!frontmatter) { return null; } return { - name, - description, + name: frontmatter.name, + description: frontmatter.description, location: filePath, body: match[2].trim(), }; From d0bbc7fa59537852ab7c1b06b562405a1f80230b Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 14 Jan 2026 18:44:08 -0800 Subject: [PATCH 207/713] refactor(core): harden skill frontmatter parsing (#16705) --- packages/core/src/skills/skillLoader.test.ts | 60 ++++++++++++++++++++ packages/core/src/skills/skillLoader.ts | 16 ++++-- 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/packages/core/src/skills/skillLoader.test.ts b/packages/core/src/skills/skillLoader.test.ts index 7c74ff2f37..dd0564be06 100644 --- a/packages/core/src/skills/skillLoader.test.ts +++ b/packages/core/src/skills/skillLoader.test.ts @@ -194,4 +194,64 @@ Do something. expect(skills[0].description).toContain('Expertise in reviewing code'); expect(skills[0].description).toContain('check'); }); + + it('should handle empty name or description', async () => { + const skillDir = path.join(testRootDir, 'empty-skill'); + await fs.mkdir(skillDir, { recursive: true }); + const skillFile = path.join(skillDir, 'SKILL.md'); + await fs.writeFile( + skillFile, + `--- +name: +description: +--- +`, + ); + + const skills = await loadSkillsFromDir(testRootDir); + + expect(skills).toHaveLength(1); + expect(skills[0].name).toBe(''); + expect(skills[0].description).toBe(''); + }); + + it('should handle indented name and description fields', async () => { + const skillDir = path.join(testRootDir, 'indented-fields'); + await fs.mkdir(skillDir, { recursive: true }); + const skillFile = path.join(skillDir, 'SKILL.md'); + await fs.writeFile( + skillFile, + `--- + name: indented-name + description: indented-desc +--- +`, + ); + + const skills = await loadSkillsFromDir(testRootDir); + + expect(skills).toHaveLength(1); + expect(skills[0].name).toBe('indented-name'); + expect(skills[0].description).toBe('indented-desc'); + }); + + it('should handle missing space after colon', async () => { + const skillDir = path.join(testRootDir, 'no-space'); + await fs.mkdir(skillDir, { recursive: true }); + const skillFile = path.join(skillDir, 'SKILL.md'); + await fs.writeFile( + skillFile, + `--- +name:no-space-name +description:no-space-desc +--- +`, + ); + + const skills = await loadSkillsFromDir(testRootDir); + + expect(skills).toHaveLength(1); + expect(skills[0].name).toBe('no-space-name'); + expect(skills[0].description).toBe('no-space-desc'); + }); }); diff --git a/packages/core/src/skills/skillLoader.ts b/packages/core/src/skills/skillLoader.ts index f25d55f08b..4bbf0823f7 100644 --- a/packages/core/src/skills/skillLoader.ts +++ b/packages/core/src/skills/skillLoader.ts @@ -71,16 +71,22 @@ function parseSimpleFrontmatter( for (let i = 0; i < lines.length; i++) { const line = lines[i]; - if (line.startsWith('name:')) { - name = line.substring(5).trim(); + // Match "name:" at the start of the line (optional whitespace) + const nameMatch = line.match(/^\s*name:\s*(.*)$/); + if (nameMatch) { + name = nameMatch[1].trim(); continue; } - if (line.startsWith('description:')) { - const descLines = [line.substring(12).trim()]; + // Match "description:" at the start of the line (optional whitespace) + const descMatch = line.match(/^\s*description:\s*(.*)$/); + if (descMatch) { + const descLines = [descMatch[1].trim()]; + // Check for multi-line description (indented continuation lines) while (i + 1 < lines.length) { const nextLine = lines[i + 1]; + // If next line is indented, it's a continuation of the description if (nextLine.match(/^[ \t]+\S/)) { descLines.push(nextLine.trim()); i++; @@ -169,7 +175,7 @@ export async function loadSkillFromFile( name: frontmatter.name, description: frontmatter.description, location: filePath, - body: match[2].trim(), + body: match[2]?.trim() ?? '', }; } catch (error) { debugLogger.log(`Error parsing skill file ${filePath}:`, error); From 222b7395011f22cb7451c0b80984c9c6c214feb0 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 14 Jan 2026 20:02:17 -0800 Subject: [PATCH 208/713] feat(skills): add conflict detection and warnings for skill overrides (#16709) --- packages/core/src/skills/skillManager.test.ts | 111 ++++++++++++++++++ packages/core/src/skills/skillManager.ts | 25 +++- 2 files changed, 133 insertions(+), 3 deletions(-) diff --git a/packages/core/src/skills/skillManager.test.ts b/packages/core/src/skills/skillManager.test.ts index 20cba08405..0171ca0f61 100644 --- a/packages/core/src/skills/skillManager.test.ts +++ b/packages/core/src/skills/skillManager.test.ts @@ -12,6 +12,8 @@ import { SkillManager } from './skillManager.js'; import { Storage } from '../config/storage.js'; import { type GeminiCLIExtension } from '../config/config.js'; import { loadSkillsFromDir, type SkillDefinition } from './skillLoader.js'; +import { coreEvents } from '../utils/events.js'; +import { debugLogger } from '../utils/debugLogger.js'; vi.mock('./skillLoader.js', async (importOriginal) => { const actual = await importOriginal(); @@ -263,4 +265,113 @@ body1`, expect(service.isAdminEnabled()).toBe(false); }); + + describe('Conflict Detection', () => { + it('should emit UI warning when a non-built-in skill is overridden', async () => { + const emitFeedbackSpy = vi.spyOn(coreEvents, 'emitFeedback'); + const userDir = path.join(testRootDir, 'user'); + const projectDir = path.join(testRootDir, 'workspace'); + await fs.mkdir(userDir, { recursive: true }); + await fs.mkdir(projectDir, { recursive: true }); + + const skillName = 'conflicting-skill'; + const userSkillPath = path.join(userDir, 'SKILL.md'); + const projectSkillPath = path.join(projectDir, 'SKILL.md'); + + vi.mocked(loadSkillsFromDir).mockImplementation(async (dir) => { + if (dir === userDir) { + return [ + { + name: skillName, + description: 'user-desc', + location: userSkillPath, + body: '', + }, + ]; + } + if (dir === projectDir) { + return [ + { + name: skillName, + description: 'project-desc', + location: projectSkillPath, + body: '', + }, + ]; + } + return []; + }); + + vi.spyOn(Storage, 'getUserSkillsDir').mockReturnValue(userDir); + const storage = new Storage('/dummy'); + vi.spyOn(storage, 'getProjectSkillsDir').mockReturnValue(projectDir); + + const service = new SkillManager(); + // @ts-expect-error accessing private method for testing + vi.spyOn(service, 'discoverBuiltinSkills').mockResolvedValue(undefined); + + await service.discoverSkills(storage, []); + + expect(emitFeedbackSpy).toHaveBeenCalledWith( + 'warning', + expect.stringContaining( + `Skill conflict detected: "${skillName}" from "${projectSkillPath}" is overriding the same skill from "${userSkillPath}".`, + ), + ); + }); + + it('should log warning but NOT emit UI warning when a built-in skill is overridden', async () => { + const emitFeedbackSpy = vi.spyOn(coreEvents, 'emitFeedback'); + const debugWarnSpy = vi.spyOn(debugLogger, 'warn'); + const userDir = path.join(testRootDir, 'user'); + await fs.mkdir(userDir, { recursive: true }); + + const skillName = 'builtin-skill'; + const userSkillPath = path.join(userDir, 'SKILL.md'); + const builtinSkillPath = 'builtin/loc'; + + vi.mocked(loadSkillsFromDir).mockImplementation(async (dir) => { + if (dir.endsWith('builtin')) { + return [ + { + name: skillName, + description: 'builtin-desc', + location: builtinSkillPath, + body: '', + isBuiltin: true, + }, + ]; + } + if (dir === userDir) { + return [ + { + name: skillName, + description: 'user-desc', + location: userSkillPath, + body: '', + }, + ]; + } + return []; + }); + + vi.spyOn(Storage, 'getUserSkillsDir').mockReturnValue(userDir); + const storage = new Storage('/dummy'); + vi.spyOn(storage, 'getProjectSkillsDir').mockReturnValue('/non-existent'); + + const service = new SkillManager(); + + await service.discoverSkills(storage, []); + + // UI warning should not be called + expect(emitFeedbackSpy).not.toHaveBeenCalled(); + + // Debug warning should be called + expect(debugWarnSpy).toHaveBeenCalledWith( + expect.stringContaining( + `Skill "${skillName}" from "${userSkillPath}" is overriding the built-in skill.`, + ), + ); + }); + }); }); diff --git a/packages/core/src/skills/skillManager.ts b/packages/core/src/skills/skillManager.ts index b2ec9e660e..d80202cd5b 100644 --- a/packages/core/src/skills/skillManager.ts +++ b/packages/core/src/skills/skillManager.ts @@ -9,6 +9,8 @@ import { fileURLToPath } from 'node:url'; import { Storage } from '../config/storage.js'; import { type SkillDefinition, loadSkillsFromDir } from './skillLoader.js'; import type { GeminiCLIExtension } from '../config/config.js'; +import { debugLogger } from '../utils/debugLogger.js'; +import { coreEvents } from '../utils/events.js'; export { type SkillDefinition }; @@ -86,10 +88,27 @@ export class SkillManager { } private addSkillsWithPrecedence(newSkills: SkillDefinition[]): void { - const skillMap = new Map(); - for (const skill of [...this.skills, ...newSkills]) { - skillMap.set(skill.name, skill); + const skillMap = new Map( + this.skills.map((s) => [s.name, s]), + ); + + for (const newSkill of newSkills) { + const existingSkill = skillMap.get(newSkill.name); + if (existingSkill && existingSkill.location !== newSkill.location) { + if (existingSkill.isBuiltin) { + debugLogger.warn( + `Skill "${newSkill.name}" from "${newSkill.location}" is overriding the built-in skill.`, + ); + } else { + coreEvents.emitFeedback( + 'warning', + `Skill conflict detected: "${newSkill.name}" from "${newSkill.location}" is overriding the same skill from "${existingSkill.location}".`, + ); + } + } + skillMap.set(newSkill.name, newSkill); } + this.skills = Array.from(skillMap.values()); } From 409f9c825b832d5b58b13114b9d6282093ce7ccc Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Wed, 14 Jan 2026 23:42:31 -0500 Subject: [PATCH 209/713] feat(scheduler): add SchedulerStateManager for reactive tool state (#16651) --- .../core/src/scheduler/state-manager.test.ts | 532 ++++++++++++++++++ packages/core/src/scheduler/state-manager.ts | 482 ++++++++++++++++ 2 files changed, 1014 insertions(+) create mode 100644 packages/core/src/scheduler/state-manager.test.ts create mode 100644 packages/core/src/scheduler/state-manager.ts diff --git a/packages/core/src/scheduler/state-manager.test.ts b/packages/core/src/scheduler/state-manager.test.ts new file mode 100644 index 0000000000..504dbbf007 --- /dev/null +++ b/packages/core/src/scheduler/state-manager.test.ts @@ -0,0 +1,532 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { SchedulerStateManager } from './state-manager.js'; +import type { + ValidatingToolCall, + WaitingToolCall, + SuccessfulToolCall, + ErroredToolCall, + CancelledToolCall, + ExecutingToolCall, + ToolCallRequestInfo, + ToolCallResponseInfo, +} from './types.js'; +import { + ToolConfirmationOutcome, + type AnyDeclarativeTool, + type AnyToolInvocation, +} from '../tools/tools.js'; +import { MessageBusType } from '../confirmation-bus/types.js'; +import type { MessageBus } from '../confirmation-bus/message-bus.js'; + +describe('SchedulerStateManager', () => { + const mockRequest: ToolCallRequestInfo = { + callId: 'call-1', + name: 'test-tool', + args: { foo: 'bar' }, + isClientInitiated: false, + prompt_id: 'prompt-1', + }; + + const mockTool = { + name: 'test-tool', + displayName: 'Test Tool', + } as AnyDeclarativeTool; + + const mockInvocation = { + shouldConfirmExecute: vi.fn(), + } as unknown as AnyToolInvocation; + + const createValidatingCall = (id = 'call-1'): ValidatingToolCall => ({ + status: 'validating', + request: { ...mockRequest, callId: id }, + tool: mockTool, + invocation: mockInvocation, + startTime: Date.now(), + }); + + const createMockResponse = (id: string): ToolCallResponseInfo => ({ + callId: id, + responseParts: [], + resultDisplay: 'Success', + error: undefined, + errorType: undefined, + }); + + let stateManager: SchedulerStateManager; + let mockMessageBus: MessageBus; + let onUpdate: (calls: unknown[]) => void; + + beforeEach(() => { + onUpdate = vi.fn(); + mockMessageBus = { + publish: vi.fn(), + subscribe: vi.fn(), + unsubscribe: vi.fn(), + } as unknown as MessageBus; + + // Capture the update when published + vi.mocked(mockMessageBus.publish).mockImplementation((msg) => { + // Return a Promise to satisfy the void | Promise signature if needed, + // though typically mocks handle it. + if (msg.type === MessageBusType.TOOL_CALLS_UPDATE) { + onUpdate(msg.toolCalls); + } + return Promise.resolve(); + }); + + stateManager = new SchedulerStateManager(mockMessageBus); + }); + + describe('Initialization', () => { + it('should start with empty state', () => { + expect(stateManager.isActive).toBe(false); + expect(stateManager.activeCallCount).toBe(0); + expect(stateManager.queueLength).toBe(0); + expect(stateManager.getSnapshot()).toEqual([]); + }); + }); + + describe('Lookup Operations', () => { + it('should find tool calls in active calls', () => { + const call = createValidatingCall('active-1'); + stateManager.enqueue([call]); + stateManager.dequeue(); + expect(stateManager.getToolCall('active-1')).toEqual(call); + }); + + it('should find tool calls in the queue', () => { + const call = createValidatingCall('queued-1'); + stateManager.enqueue([call]); + expect(stateManager.getToolCall('queued-1')).toEqual(call); + }); + + it('should find tool calls in the completed batch', () => { + const call = createValidatingCall('completed-1'); + stateManager.enqueue([call]); + stateManager.dequeue(); + stateManager.updateStatus( + 'completed-1', + 'success', + createMockResponse('completed-1'), + ); + stateManager.finalizeCall('completed-1'); + expect(stateManager.getToolCall('completed-1')).toBeDefined(); + }); + + it('should return undefined for non-existent callIds', () => { + expect(stateManager.getToolCall('void')).toBeUndefined(); + }); + }); + + describe('Queue Management', () => { + it('should enqueue calls and notify', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + + expect(stateManager.queueLength).toBe(1); + expect(onUpdate).toHaveBeenCalledWith([call]); + }); + + it('should dequeue calls and notify', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + + const dequeued = stateManager.dequeue(); + + expect(dequeued).toEqual(call); + expect(stateManager.queueLength).toBe(0); + expect(stateManager.activeCallCount).toBe(1); + expect(onUpdate).toHaveBeenCalled(); + }); + + it('should return undefined when dequeueing from empty queue', () => { + const dequeued = stateManager.dequeue(); + expect(dequeued).toBeUndefined(); + }); + }); + + describe('Status Transitions', () => { + it('should transition validating to scheduled', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + + stateManager.updateStatus(call.request.callId, 'scheduled'); + + const snapshot = stateManager.getSnapshot(); + expect(snapshot[0].status).toBe('scheduled'); + expect(snapshot[0].request.callId).toBe(call.request.callId); + }); + + it('should transition scheduled to executing', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + stateManager.updateStatus(call.request.callId, 'scheduled'); + + stateManager.updateStatus(call.request.callId, 'executing'); + + expect(stateManager.firstActiveCall?.status).toBe('executing'); + }); + + it('should transition to success and move to completed batch', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + + const response: ToolCallResponseInfo = { + callId: call.request.callId, + responseParts: [], + resultDisplay: 'Success', + error: undefined, + errorType: undefined, + }; + + stateManager.updateStatus(call.request.callId, 'success', response); + stateManager.finalizeCall(call.request.callId); + + expect(stateManager.isActive).toBe(false); + expect(stateManager.completedBatch).toHaveLength(1); + const completed = stateManager.completedBatch[0] as SuccessfulToolCall; + expect(completed.status).toBe('success'); + expect(completed.response).toEqual(response); + expect(completed.durationMs).toBeDefined(); + }); + + it('should transition to error and move to completed batch', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + + const response: ToolCallResponseInfo = { + callId: call.request.callId, + responseParts: [], + resultDisplay: 'Error', + error: new Error('Failed'), + errorType: undefined, + }; + + stateManager.updateStatus(call.request.callId, 'error', response); + stateManager.finalizeCall(call.request.callId); + + expect(stateManager.isActive).toBe(false); + expect(stateManager.completedBatch).toHaveLength(1); + const completed = stateManager.completedBatch[0] as ErroredToolCall; + expect(completed.status).toBe('error'); + expect(completed.response).toEqual(response); + }); + + it('should transition to awaiting_approval with details', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + + const details = { + type: 'info' as const, + title: 'Confirm', + prompt: 'Proceed?', + onConfirm: vi.fn(), + }; + + stateManager.updateStatus( + call.request.callId, + 'awaiting_approval', + details, + ); + + const active = stateManager.firstActiveCall as WaitingToolCall; + expect(active.status).toBe('awaiting_approval'); + expect(active.confirmationDetails).toEqual(details); + }); + + it('should transition to awaiting_approval with event-driven format', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + + const details = { + type: 'info' as const, + title: 'Confirm', + prompt: 'Proceed?', + }; + const eventDrivenData = { + correlationId: 'corr-123', + confirmationDetails: details, + }; + + stateManager.updateStatus( + call.request.callId, + 'awaiting_approval', + eventDrivenData, + ); + + const active = stateManager.firstActiveCall as WaitingToolCall; + expect(active.status).toBe('awaiting_approval'); + expect(active.correlationId).toBe('corr-123'); + expect(active.confirmationDetails).toEqual(details); + }); + + it('should preserve diff when cancelling an edit tool call', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + + const details = { + type: 'edit' as const, + title: 'Edit', + fileName: 'test.txt', + filePath: '/path/to/test.txt', + fileDiff: 'diff', + originalContent: 'old', + newContent: 'new', + onConfirm: vi.fn(), + }; + + stateManager.updateStatus( + call.request.callId, + 'awaiting_approval', + details, + ); + stateManager.updateStatus( + call.request.callId, + 'cancelled', + 'User said no', + ); + stateManager.finalizeCall(call.request.callId); + + const completed = stateManager.completedBatch[0] as CancelledToolCall; + expect(completed.status).toBe('cancelled'); + expect(completed.response.resultDisplay).toEqual({ + fileDiff: 'diff', + fileName: 'test.txt', + filePath: '/path/to/test.txt', + originalContent: 'old', + newContent: 'new', + }); + }); + + it('should ignore status updates for non-existent callIds', () => { + stateManager.updateStatus('unknown', 'scheduled'); + expect(onUpdate).not.toHaveBeenCalled(); + }); + + it('should ignore status updates for terminal calls', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + stateManager.updateStatus( + call.request.callId, + 'success', + createMockResponse(call.request.callId), + ); + stateManager.finalizeCall(call.request.callId); + + vi.mocked(onUpdate).mockClear(); + stateManager.updateStatus(call.request.callId, 'scheduled'); + expect(onUpdate).not.toHaveBeenCalled(); + }); + + it('should only finalize terminal calls', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + + stateManager.updateStatus(call.request.callId, 'executing'); + stateManager.finalizeCall(call.request.callId); + + expect(stateManager.isActive).toBe(true); + expect(stateManager.completedBatch).toHaveLength(0); + + stateManager.updateStatus( + call.request.callId, + 'success', + createMockResponse(call.request.callId), + ); + stateManager.finalizeCall(call.request.callId); + + expect(stateManager.isActive).toBe(false); + expect(stateManager.completedBatch).toHaveLength(1); + }); + + it('should merge liveOutput and pid during executing updates', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + + // Start executing + stateManager.updateStatus(call.request.callId, 'executing'); + let active = stateManager.firstActiveCall as ExecutingToolCall; + expect(active.status).toBe('executing'); + expect(active.liveOutput).toBeUndefined(); + + // Update with live output + stateManager.updateStatus(call.request.callId, 'executing', { + liveOutput: 'chunk 1', + }); + active = stateManager.firstActiveCall as ExecutingToolCall; + expect(active.liveOutput).toBe('chunk 1'); + + // Update with pid (should preserve liveOutput) + stateManager.updateStatus(call.request.callId, 'executing', { + pid: 1234, + }); + active = stateManager.firstActiveCall as ExecutingToolCall; + expect(active.liveOutput).toBe('chunk 1'); + expect(active.pid).toBe(1234); + + // Update live output again (should preserve pid) + stateManager.updateStatus(call.request.callId, 'executing', { + liveOutput: 'chunk 2', + }); + active = stateManager.firstActiveCall as ExecutingToolCall; + expect(active.liveOutput).toBe('chunk 2'); + expect(active.pid).toBe(1234); + }); + }); + + describe('Argument Updates', () => { + it('should update args and invocation', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + + const newArgs = { foo: 'updated' }; + const newInvocation = { ...mockInvocation } as AnyToolInvocation; + + stateManager.updateArgs(call.request.callId, newArgs, newInvocation); + + const active = stateManager.firstActiveCall; + if (active && 'invocation' in active) { + expect(active.invocation).toEqual(newInvocation); + } else { + throw new Error('Active call should have invocation'); + } + }); + + it('should ignore arg updates for errored calls', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + stateManager.updateStatus( + call.request.callId, + 'error', + createMockResponse(call.request.callId), + ); + stateManager.finalizeCall(call.request.callId); + + stateManager.updateArgs( + call.request.callId, + { foo: 'new' }, + mockInvocation, + ); + + const completed = stateManager.completedBatch[0]; + expect(completed.request.args).toEqual(mockRequest.args); + }); + }); + + describe('Outcome Tracking', () => { + it('should set outcome and notify', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + + stateManager.setOutcome( + call.request.callId, + ToolConfirmationOutcome.ProceedAlways, + ); + + const active = stateManager.firstActiveCall; + expect(active?.outcome).toBe(ToolConfirmationOutcome.ProceedAlways); + expect(onUpdate).toHaveBeenCalled(); + }); + }); + + describe('Batch Operations', () => { + it('should cancel all queued calls', () => { + stateManager.enqueue([ + createValidatingCall('1'), + createValidatingCall('2'), + ]); + + stateManager.cancelAllQueued('Batch cancel'); + + expect(stateManager.queueLength).toBe(0); + expect(stateManager.completedBatch).toHaveLength(2); + expect( + stateManager.completedBatch.every((c) => c.status === 'cancelled'), + ).toBe(true); + }); + + it('should clear batch and notify', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + stateManager.updateStatus( + call.request.callId, + 'success', + createMockResponse(call.request.callId), + ); + stateManager.finalizeCall(call.request.callId); + + stateManager.clearBatch(); + + expect(stateManager.completedBatch).toHaveLength(0); + expect(onUpdate).toHaveBeenCalledWith([]); + }); + + it('should return a copy of the completed batch (defensive)', () => { + const call = createValidatingCall(); + stateManager.enqueue([call]); + stateManager.dequeue(); + stateManager.updateStatus( + call.request.callId, + 'success', + createMockResponse(call.request.callId), + ); + stateManager.finalizeCall(call.request.callId); + + const batch = stateManager.completedBatch; + expect(batch).toHaveLength(1); + + // Mutate the returned array + batch.pop(); + expect(batch).toHaveLength(0); + + // Verify internal state is unchanged + expect(stateManager.completedBatch).toHaveLength(1); + }); + }); + + describe('Snapshot and Ordering', () => { + it('should return snapshot in order: completed, active, queue', () => { + // 1. Completed + const call1 = createValidatingCall('1'); + stateManager.enqueue([call1]); + stateManager.dequeue(); + stateManager.updateStatus('1', 'success', createMockResponse('1')); + stateManager.finalizeCall('1'); + + // 2. Active + const call2 = createValidatingCall('2'); + stateManager.enqueue([call2]); + stateManager.dequeue(); + + // 3. Queue + const call3 = createValidatingCall('3'); + stateManager.enqueue([call3]); + + const snapshot = stateManager.getSnapshot(); + expect(snapshot).toHaveLength(3); + expect(snapshot[0].request.callId).toBe('1'); + expect(snapshot[1].request.callId).toBe('2'); + expect(snapshot[2].request.callId).toBe('3'); + }); + }); +}); diff --git a/packages/core/src/scheduler/state-manager.ts b/packages/core/src/scheduler/state-manager.ts new file mode 100644 index 0000000000..1817f0771f --- /dev/null +++ b/packages/core/src/scheduler/state-manager.ts @@ -0,0 +1,482 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type { + ToolCall, + Status, + WaitingToolCall, + CompletedToolCall, + SuccessfulToolCall, + ErroredToolCall, + CancelledToolCall, + ScheduledToolCall, + ValidatingToolCall, + ExecutingToolCall, + ToolCallResponseInfo, +} from './types.js'; +import type { + ToolConfirmationOutcome, + ToolResultDisplay, + AnyToolInvocation, + ToolCallConfirmationDetails, + AnyDeclarativeTool, +} from '../tools/tools.js'; +import type { MessageBus } from '../confirmation-bus/message-bus.js'; +import { + MessageBusType, + type SerializableConfirmationDetails, +} from '../confirmation-bus/types.js'; + +/** + * Manages the state of tool calls. + * Publishes state changes to the MessageBus via TOOL_CALLS_UPDATE events. + */ +export class SchedulerStateManager { + private readonly activeCalls = new Map(); + private readonly queue: ToolCall[] = []; + private _completedBatch: CompletedToolCall[] = []; + + constructor(private readonly messageBus: MessageBus) {} + + addToolCalls(calls: ToolCall[]): void { + this.enqueue(calls); + } + + getToolCall(callId: string): ToolCall | undefined { + return ( + this.activeCalls.get(callId) || + this.queue.find((c) => c.request.callId === callId) || + this._completedBatch.find((c) => c.request.callId === callId) + ); + } + + enqueue(calls: ToolCall[]): void { + this.queue.push(...calls); + this.emitUpdate(); + } + + dequeue(): ToolCall | undefined { + const next = this.queue.shift(); + if (next) { + this.activeCalls.set(next.request.callId, next); + this.emitUpdate(); + } + return next; + } + + get isActive(): boolean { + return this.activeCalls.size > 0; + } + + get activeCallCount(): number { + return this.activeCalls.size; + } + + get queueLength(): number { + return this.queue.length; + } + + get firstActiveCall(): ToolCall | undefined { + return this.activeCalls.values().next().value; + } + + /** + * Updates the status of a tool call with specific auxiliary data required for certain states. + */ + updateStatus( + callId: string, + status: 'success', + data: ToolCallResponseInfo, + ): void; + updateStatus( + callId: string, + status: 'error', + data: ToolCallResponseInfo, + ): void; + updateStatus( + callId: string, + status: 'awaiting_approval', + data: + | ToolCallConfirmationDetails + | { + correlationId: string; + confirmationDetails: SerializableConfirmationDetails; + }, + ): void; + updateStatus(callId: string, status: 'cancelled', data: string): void; + updateStatus( + callId: string, + status: 'executing', + data?: Partial, + ): void; + updateStatus(callId: string, status: 'scheduled' | 'validating'): void; + updateStatus(callId: string, status: Status, auxiliaryData?: unknown): void { + const call = this.activeCalls.get(callId); + if (!call) return; + + const updatedCall = this.transitionCall(call, status, auxiliaryData); + this.activeCalls.set(callId, updatedCall); + + this.emitUpdate(); + } + + finalizeCall(callId: string): void { + const call = this.activeCalls.get(callId); + if (!call) return; + + if (this.isTerminalCall(call)) { + this._completedBatch.push(call); + this.activeCalls.delete(callId); + } + } + + updateArgs( + callId: string, + newArgs: Record, + newInvocation: AnyToolInvocation, + ): void { + const call = this.activeCalls.get(callId); + if (!call || call.status === 'error') return; + + this.activeCalls.set( + callId, + this.patchCall(call, { + request: { ...call.request, args: newArgs }, + invocation: newInvocation, + }), + ); + this.emitUpdate(); + } + + setOutcome(callId: string, outcome: ToolConfirmationOutcome): void { + const call = this.activeCalls.get(callId); + if (!call) return; + + this.activeCalls.set(callId, this.patchCall(call, { outcome })); + this.emitUpdate(); + } + + cancelAllQueued(reason: string): void { + while (this.queue.length > 0) { + const queuedCall = this.queue.shift()!; + if (queuedCall.status === 'error') { + this._completedBatch.push(queuedCall); + continue; + } + this._completedBatch.push(this.toCancelled(queuedCall, reason)); + } + this.emitUpdate(); + } + + getSnapshot(): ToolCall[] { + return [ + ...this._completedBatch, + ...Array.from(this.activeCalls.values()), + ...this.queue, + ]; + } + + clearBatch(): void { + if (this._completedBatch.length === 0) return; + this._completedBatch = []; + this.emitUpdate(); + } + + get completedBatch(): CompletedToolCall[] { + return [...this._completedBatch]; + } + + private emitUpdate() { + const snapshot = this.getSnapshot(); + + // Fire and forget - The message bus handles the publish and error handling. + void this.messageBus.publish({ + type: MessageBusType.TOOL_CALLS_UPDATE, + toolCalls: snapshot, + }); + } + + private isTerminalCall(call: ToolCall): call is CompletedToolCall { + const { status } = call; + return status === 'success' || status === 'error' || status === 'cancelled'; + } + + private transitionCall( + call: ToolCall, + newStatus: Status, + auxiliaryData?: unknown, + ): ToolCall { + switch (newStatus) { + case 'success': { + if (!this.isToolCallResponseInfo(auxiliaryData)) { + throw new Error( + `Invalid data for 'success' transition (callId: ${call.request.callId})`, + ); + } + return this.toSuccess(call, auxiliaryData); + } + case 'error': { + if (!this.isToolCallResponseInfo(auxiliaryData)) { + throw new Error( + `Invalid data for 'error' transition (callId: ${call.request.callId})`, + ); + } + return this.toError(call, auxiliaryData); + } + case 'awaiting_approval': { + if (!auxiliaryData) { + throw new Error( + `Missing data for 'awaiting_approval' transition (callId: ${call.request.callId})`, + ); + } + return this.toAwaitingApproval(call, auxiliaryData); + } + case 'scheduled': + return this.toScheduled(call); + case 'cancelled': { + if (typeof auxiliaryData !== 'string') { + throw new Error( + `Invalid reason (string) for 'cancelled' transition (callId: ${call.request.callId})`, + ); + } + return this.toCancelled(call, auxiliaryData); + } + case 'validating': + return this.toValidating(call); + case 'executing': { + if ( + auxiliaryData !== undefined && + !this.isExecutingToolCallPatch(auxiliaryData) + ) { + throw new Error( + `Invalid patch for 'executing' transition (callId: ${call.request.callId})`, + ); + } + return this.toExecuting(call, auxiliaryData); + } + default: { + const exhaustiveCheck: never = newStatus; + return exhaustiveCheck; + } + } + } + + private isToolCallResponseInfo(data: unknown): data is ToolCallResponseInfo { + return ( + typeof data === 'object' && + data !== null && + 'callId' in data && + 'responseParts' in data + ); + } + + private isExecutingToolCallPatch( + data: unknown, + ): data is Partial { + // A partial can be an empty object, but it must be a non-null object. + return typeof data === 'object' && data !== null; + } + + // --- Transition Helpers --- + + /** + * Ensures the tool call has an associated tool and invocation before + * transitioning to states that require them. + */ + private validateHasToolAndInvocation( + call: ToolCall, + targetStatus: Status, + ): asserts call is ToolCall & { + tool: AnyDeclarativeTool; + invocation: AnyToolInvocation; + } { + if ( + !('tool' in call && call.tool && 'invocation' in call && call.invocation) + ) { + throw new Error( + `Invalid state transition: cannot transition to ${targetStatus} without tool/invocation (callId: ${call.request.callId})`, + ); + } + } + + private toSuccess( + call: ToolCall, + response: ToolCallResponseInfo, + ): SuccessfulToolCall { + this.validateHasToolAndInvocation(call, 'success'); + const startTime = 'startTime' in call ? call.startTime : undefined; + return { + request: call.request, + tool: call.tool, + invocation: call.invocation, + status: 'success', + response, + durationMs: startTime ? Date.now() - startTime : undefined, + outcome: call.outcome, + }; + } + + private toError( + call: ToolCall, + response: ToolCallResponseInfo, + ): ErroredToolCall { + const startTime = 'startTime' in call ? call.startTime : undefined; + return { + request: call.request, + status: 'error', + tool: 'tool' in call ? call.tool : undefined, + response, + durationMs: startTime ? Date.now() - startTime : undefined, + outcome: call.outcome, + }; + } + + private toAwaitingApproval(call: ToolCall, data: unknown): WaitingToolCall { + this.validateHasToolAndInvocation(call, 'awaiting_approval'); + + let confirmationDetails: + | ToolCallConfirmationDetails + | SerializableConfirmationDetails; + let correlationId: string | undefined; + + if (this.isEventDrivenApprovalData(data)) { + correlationId = data.correlationId; + confirmationDetails = data.confirmationDetails; + } else { + // TODO: Remove legacy callback shape once event-driven migration is complete + confirmationDetails = data as ToolCallConfirmationDetails; + } + + return { + request: call.request, + tool: call.tool, + status: 'awaiting_approval', + correlationId, + confirmationDetails, + startTime: 'startTime' in call ? call.startTime : undefined, + outcome: call.outcome, + invocation: call.invocation, + }; + } + + private isEventDrivenApprovalData(data: unknown): data is { + correlationId: string; + confirmationDetails: SerializableConfirmationDetails; + } { + return ( + typeof data === 'object' && + data !== null && + 'correlationId' in data && + 'confirmationDetails' in data + ); + } + + private toScheduled(call: ToolCall): ScheduledToolCall { + this.validateHasToolAndInvocation(call, 'scheduled'); + return { + request: call.request, + tool: call.tool, + status: 'scheduled', + startTime: 'startTime' in call ? call.startTime : undefined, + outcome: call.outcome, + invocation: call.invocation, + }; + } + + private toCancelled(call: ToolCall, reason: string): CancelledToolCall { + this.validateHasToolAndInvocation(call, 'cancelled'); + const startTime = 'startTime' in call ? call.startTime : undefined; + + // TODO: Refactor this tool-specific logic into the confirmation details payload. + // See: https://github.com/google-gemini/gemini-cli/issues/16716 + let resultDisplay: ToolResultDisplay | undefined = undefined; + if (this.isWaitingToolCall(call)) { + const details = call.confirmationDetails; + if ( + details.type === 'edit' && + 'fileDiff' in details && + 'fileName' in details && + 'filePath' in details && + 'originalContent' in details && + 'newContent' in details + ) { + resultDisplay = { + fileDiff: details.fileDiff, + fileName: details.fileName, + filePath: details.filePath, + originalContent: details.originalContent, + newContent: details.newContent, + }; + } + } + + const errorMessage = `[Operation Cancelled] Reason: ${reason}`; + return { + request: call.request, + tool: call.tool, + invocation: call.invocation, + status: 'cancelled', + response: { + callId: call.request.callId, + responseParts: [ + { + functionResponse: { + id: call.request.callId, + name: call.request.name, + response: { error: errorMessage }, + }, + }, + ], + resultDisplay, + error: undefined, + errorType: undefined, + contentLength: errorMessage.length, + }, + durationMs: startTime ? Date.now() - startTime : undefined, + outcome: call.outcome, + }; + } + + private isWaitingToolCall(call: ToolCall): call is WaitingToolCall { + return call.status === 'awaiting_approval'; + } + + private patchCall(call: T, patch: Partial): T { + return { ...call, ...patch }; + } + + private toValidating(call: ToolCall): ValidatingToolCall { + this.validateHasToolAndInvocation(call, 'validating'); + return { + request: call.request, + tool: call.tool, + status: 'validating', + startTime: 'startTime' in call ? call.startTime : undefined, + outcome: call.outcome, + invocation: call.invocation, + }; + } + + private toExecuting(call: ToolCall, data?: unknown): ExecutingToolCall { + this.validateHasToolAndInvocation(call, 'executing'); + const execData = data as Partial | undefined; + const liveOutput = + execData?.liveOutput ?? + ('liveOutput' in call ? call.liveOutput : undefined); + const pid = execData?.pid ?? ('pid' in call ? call.pid : undefined); + + return { + request: call.request, + tool: call.tool, + status: 'executing', + startTime: 'startTime' in call ? call.startTime : undefined, + outcome: call.outcome, + invocation: call.invocation, + liveOutput, + pid, + }; + } +} From 53f54436c9935c357fa0e5d0cbaa6da863b8f7ca Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Thu, 15 Jan 2026 00:36:58 -0500 Subject: [PATCH 210/713] chore(automation): enforce 'help wanted' label permissions and update guidelines (#16707) --- .github/scripts/backfill-pr-notification.cjs | 190 ++++++++++++++++++ .github/workflows/label-enforcer.yml | 113 +++++++++++ .../pr-contribution-guidelines-notifier.yml | 90 +++++++++ CONTRIBUTING.md | 16 +- 4 files changed, 405 insertions(+), 4 deletions(-) create mode 100644 .github/scripts/backfill-pr-notification.cjs create mode 100644 .github/workflows/label-enforcer.yml create mode 100644 .github/workflows/pr-contribution-guidelines-notifier.yml diff --git a/.github/scripts/backfill-pr-notification.cjs b/.github/scripts/backfill-pr-notification.cjs new file mode 100644 index 0000000000..3014398519 --- /dev/null +++ b/.github/scripts/backfill-pr-notification.cjs @@ -0,0 +1,190 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/* eslint-disable */ +/* global require, console, process */ + +/** + * Script to backfill a process change notification comment to all open PRs + * not created by members of the 'gemini-cli-maintainers' team. + * + * Skip PRs that are already associated with an issue. + */ + +const { execFileSync } = require('child_process'); + +const isDryRun = process.argv.includes('--dry-run'); +const REPO = 'google-gemini/gemini-cli'; +const ORG = 'google-gemini'; +const TEAM_SLUG = 'gemini-cli-maintainers'; +const DISCUSSION_URL = + 'https://github.com/google-gemini/gemini-cli/discussions/16706'; + +/** + * Executes a GitHub CLI command safely using an argument array. + */ +function runGh(args, options = {}) { + const { silent = false } = options; + try { + return execFileSync('gh', args, { + encoding: 'utf8', + maxBuffer: 10 * 1024 * 1024, + stdio: ['ignore', 'pipe', 'pipe'], + }).trim(); + } catch (error) { + if (!silent) { + const stderr = error.stderr ? ` Stderr: ${error.stderr.trim()}` : ''; + console.error( + `❌ Error running gh ${args.join(' ')}: ${error.message}${stderr}`, + ); + } + return null; + } +} + +/** + * Checks if a user is a member of the maintainers team. + */ +const membershipCache = new Map(); +function isMaintainer(username) { + if (membershipCache.has(username)) return membershipCache.get(username); + + // GitHub returns 404 if user is not a member. + // We use silent: true to avoid logging 404s as errors. + const result = runGh( + ['api', `orgs/${ORG}/teams/${TEAM_SLUG}/memberships/${username}`], + { silent: true }, + ); + + const isMember = result !== null; + membershipCache.set(username, isMember); + return isMember; +} + +async function main() { + console.log('🔐 GitHub CLI security check...'); + if (runGh(['auth', 'status']) === null) { + console.error('❌ GitHub CLI (gh) is not authenticated.'); + process.exit(1); + } + + if (isDryRun) { + console.log('🧪 DRY RUN MODE ENABLED\n'); + } + + console.log(`📥 Fetching open PRs from ${REPO}...`); + // Fetch number, author, and closingIssuesReferences to check if linked to an issue + const prsJson = runGh([ + 'pr', + 'list', + '--repo', + REPO, + '--state', + 'open', + '--limit', + '1000', + '--json', + 'number,author,closingIssuesReferences', + ]); + + if (prsJson === null) process.exit(1); + const prs = JSON.parse(prsJson); + + console.log(`📊 Found ${prs.length} open PRs. Filtering...`); + + let targetPrs = []; + for (const pr of prs) { + const author = pr.author.login; + const issueCount = pr.closingIssuesReferences + ? pr.closingIssuesReferences.length + : 0; + + if (issueCount > 0) { + // Skip if already linked to an issue + continue; + } + + if (!isMaintainer(author)) { + targetPrs.push(pr); + } + } + + console.log( + `✅ Found ${targetPrs.length} PRs from non-maintainers without associated issues.`, + ); + + const commentBody = + "\nHi @{AUTHOR}, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.\n\nWe're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: [Improving Our Contribution Process & Introducing New Guidelines](${DISCUSSION_URL}).\n\nKey Update: Starting **January 26, 2026**, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.\n\nThank you for your understanding and for being a part of our community!\n ".trim(); + + let successCount = 0; + let skipCount = 0; + let failCount = 0; + + for (const pr of targetPrs) { + const prNumber = String(pr.number); + const author = pr.author.login; + + // Check if we already commented (idempotency) + // We use silent: true here because view might fail if PR is deleted mid-run + const existingComments = runGh( + [ + 'pr', + 'view', + prNumber, + '--repo', + REPO, + '--json', + 'comments', + '--jq', + `.comments[].body | contains("${DISCUSSION_URL}")`, + ], + { silent: true }, + ); + + if (existingComments && existingComments.includes('true')) { + console.log( + `⏭️ PR #${prNumber} already has the notification. Skipping.`, + ); + skipCount++; + continue; + } + + if (isDryRun) { + console.log(`[DRY RUN] Would notify @${author} on PR #${prNumber}`); + successCount++; + } else { + console.log(`💬 Notifying @${author} on PR #${prNumber}...`); + const personalizedComment = commentBody.replace('{AUTHOR}', author); + const result = runGh([ + 'pr', + 'comment', + prNumber, + '--repo', + REPO, + '--body', + personalizedComment, + ]); + + if (result !== null) { + successCount++; + } else { + failCount++; + } + } + } + + console.log(`\n📊 Summary:`); + console.log(` - Notified: ${successCount}`); + console.log(` - Skipped: ${skipCount}`); + console.log(` - Failed: ${failCount}`); + + if (failCount > 0) process.exit(1); +} + +main().catch((e) => { + console.error(e); + process.exit(1); +}); diff --git a/.github/workflows/label-enforcer.yml b/.github/workflows/label-enforcer.yml new file mode 100644 index 0000000000..173a80c103 --- /dev/null +++ b/.github/workflows/label-enforcer.yml @@ -0,0 +1,113 @@ +name: '🏷️ Enforce Restricted Label Permissions' + +on: + issues: + types: + - 'labeled' + - 'unlabeled' + +jobs: + enforce-label: + # Run this job only when restricted labels are changed + if: |- + ${{ (github.event.label.name == 'help wanted' || github.event.label.name == 'status/need-triage') && + (github.repository == 'google-gemini/gemini-cli' || github.repository == 'google-gemini/maintainers-gemini-cli') }} + runs-on: 'ubuntu-latest' + permissions: + issues: 'write' + steps: + - name: 'Generate GitHub App Token' + id: 'generate_token' + env: + APP_ID: '${{ secrets.APP_ID }}' + if: |- + ${{ env.APP_ID != '' }} + uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2 + with: + app-id: '${{ secrets.APP_ID }}' + private-key: '${{ secrets.PRIVATE_KEY }}' + + - name: 'Check if user is in the maintainers team' + uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' + with: + github-token: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}' + script: |- + const org = context.repo.owner; + const username = context.payload.sender.login; + const team_slug = 'gemini-cli-maintainers'; + const action = context.payload.action; // 'labeled' or 'unlabeled' + const labelName = context.payload.label.name; + + // Skip if the change was made by a bot to avoid infinite loops + if (username === 'github-actions[bot]') { + core.info('Change made by a bot. Skipping.'); + return; + } + + try { + // This will succeed with a 204 status if the user is a member, + // and fail with a 404 error if they are not. + await github.rest.teams.getMembershipForUserInOrg ({ + org, + team_slug, + username, + }); + core.info(`${username} is a member of the ${team_slug} team. No action needed.`); + } catch (error) { + // If the error is not 404, rethrow it to fail the action + if (error.status !== 404) { + throw error; + } + + core.info(`${username} is not a member. Reverting '${action}' action for '${labelName}' label.`); + + if (action === 'labeled') { + // 1. Remove the label if added by a non-maintainer + await github.rest.issues.removeLabel ({ + owner: org, + repo: context.repo.repo, + issue_number: context.issue.number, + name: labelName + }); + + // 2. Post a polite comment + const comment = ` + Hi @${username}, thank you for your interest in helping triage issues! + + The \`${labelName}\` label is reserved for project maintainers to apply. This helps us ensure that an issue is ready and properly vetted for community contribution. + + A maintainer will review this issue soon. Please see our [CONTRIBUTING.md](https://github.com/google-gemini/gemini-cli/blob/main/CONTRIBUTING.md) for more details on our labeling process. + `.trim().replace(/^[ ]+/gm, ''); + + await github.rest.issues.createComment ({ + owner: org, + repo: context.repo.repo, + issue_number: context.issue.number, + body: comment + }); + } else if (action === 'unlabeled') { + // 1. Add the label back if removed by a non-maintainer + await github.rest.issues.addLabels ({ + owner: org, + repo: context.repo.repo, + issue_number: context.issue.number, + labels: [labelName] + }); + + // 2. Post a polite comment + const comment = ` + Hi @${username}, it looks like the \`${labelName}\` label was removed. + + This label is managed by project maintainers. We've added it back to ensure the issue remains visible to potential contributors until a maintainer decides otherwise. + + Thank you for your understanding! + `.trim().replace(/^[ ]+/gm, ''); + + await github.rest.issues.createComment ({ + owner: org, + repo: context.repo.repo, + issue_number: context.issue.number, + body: comment + }); + } + } diff --git a/.github/workflows/pr-contribution-guidelines-notifier.yml b/.github/workflows/pr-contribution-guidelines-notifier.yml new file mode 100644 index 0000000000..c9bebbb3c5 --- /dev/null +++ b/.github/workflows/pr-contribution-guidelines-notifier.yml @@ -0,0 +1,90 @@ +name: '🏷️ PR Contribution Guidelines Notifier' + +on: + pull_request: + types: + - 'opened' + +jobs: + notify-process-change: + runs-on: 'ubuntu-latest' + if: |- + github.repository == 'google-gemini/gemini-cli' || github.repository == 'google-gemini/maintainers-gemini-cli' + permissions: + pull-requests: 'write' + steps: + - name: 'Generate GitHub App Token' + id: 'generate_token' + env: + APP_ID: '${{ secrets.APP_ID }}' + if: |- + ${{ env.APP_ID != '' }} + uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2 + with: + app-id: '${{ secrets.APP_ID }}' + private-key: '${{ secrets.PRIVATE_KEY }}' + + - name: 'Check membership and post comment' + uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' + with: + github-token: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}' + script: |- + const org = context.repo.owner; + const repo = context.repo.repo; + const username = context.payload.pull_request.user.login; + const pr_number = context.payload.pull_request.number; + const team_slug = 'gemini-cli-maintainers'; + + // 1. Check if the PR author is a maintainer + try { + await github.rest.teams.getMembershipForUserInOrg({ + org, + team_slug, + username, + }); + core.info(`${username} is a maintainer. No notification needed.`); + return; + } catch (error) { + if (error.status !== 404) throw error; + } + + // 2. Check if the PR is already associated with an issue + const query = ` + query($owner:String!, $repo:String!, $number:Int!) { + repository(owner:$owner, name:$repo) { + pullRequest(number:$number) { + closingIssuesReferences(first: 1) { + totalCount + } + } + } + } + `; + const variables = { owner: org, repo: repo, number: pr_number }; + const result = await github.graphql(query, variables); + const issueCount = result.repository.pullRequest.closingIssuesReferences.totalCount; + + if (issueCount > 0) { + core.info(`PR #${pr_number} is already associated with an issue. No notification needed.`); + return; + } + + // 3. Post the notification comment + core.info(`${username} is not a maintainer and PR #${pr_number} has no linked issue. Posting notification.`); + + const comment = ` + Hi @${username}, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. + + We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: [Improving Our Contribution Process & Introducing New Guidelines](https://github.com/google-gemini/gemini-cli/discussions/16706). + + Key Update: Starting **January 26, 2026**, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. + + Thank you for your understanding and for being a part of our community! + `.trim().replace(/^[ ]+/gm, ''); + + await github.rest.issues.createComment({ + owner: org, + repo: repo, + issue_number: pr_number, + body: comment + }); diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d96c25b5b7..d1848f143c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,8 +42,13 @@ This project follows The process for contributing code is as follows: 1. **Find an issue** that you want to work on. If an issue is tagged as - "🔒Maintainers only", this means it is reserved for project maintainers. We - will not accept pull requests related to these issues. + `🔒Maintainers only`, this means it is reserved for project maintainers. We + will not accept pull requests related to these issues. In the near future, + we will explicitly mark issues looking for contributions using the + `help wanted` label. If you believe an issue is a good candidate for + community contribution, please leave a comment on the issue. A maintainer + will review it and apply the `help-wanted` label if appropriate. Only + maintainers should attempt to add the `help-wanted` label to an issue. 2. **Fork the repository** and create a new branch. 3. **Make your changes** in the `packages/` directory. 4. **Ensure all checks pass** by running `npm run preflight`. @@ -94,8 +99,11 @@ any code is written. - **For features:** The PR should be linked to the feature request or proposal issue that has been approved by a maintainer. -If an issue for your change doesn't exist, please **open one first** and wait -for feedback before you start coding. +If an issue for your change doesn't exist, we will automatically close your PR +along with a comment reminding you to associate the PR with an issue. The ideal +workflow starts with an issue that has been reviewed and approved by a +maintainer. Please **open the issue first** and wait for feedback before you +start coding. #### 2. Keep it small and focused From 448fd3ca6612c5daf35230a40e4c293c84d8ecfa Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Thu, 15 Jan 2026 02:42:03 -0500 Subject: [PATCH 211/713] fix(core): resolve circular dependency via tsconfig paths (#16730) --- packages/core/tsconfig.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 06e3256b97..7526c37932 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -4,7 +4,11 @@ "outDir": "dist", "lib": ["DOM", "DOM.Iterable", "ES2023"], "composite": true, - "types": ["node", "vitest/globals"] + "types": ["node", "vitest/globals"], + "baseUrl": ".", + "paths": { + "@google/gemini-cli-core": ["./index.ts"] + } }, "include": ["index.ts", "src/**/*.ts", "src/**/*.json"], "exclude": ["node_modules", "dist"] From b0c9db7b3383babeeda79063774bc68b8ebdd721 Mon Sep 17 00:00:00 2001 From: gemini-cli-robot Date: Thu, 15 Jan 2026 00:24:47 -0800 Subject: [PATCH 212/713] chore/release: bump version to 0.26.0-nightly.20260115.6cb3ae4e0 (#16738) Co-authored-by: Sehoon Shon --- package-lock.json | 14 +++++++------- package.json | 4 ++-- packages/a2a-server/package.json | 2 +- packages/cli/package.json | 4 ++-- packages/core/package.json | 2 +- packages/test-utils/package.json | 2 +- packages/vscode-ide-companion/package.json | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 56b985c5e7..9eec016a70 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@google/gemini-cli", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@google/gemini-cli", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "workspaces": [ "packages/*" ], @@ -18383,7 +18383,7 @@ }, "packages/a2a-server": { "name": "@google/gemini-cli-a2a-server", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "dependencies": { "@a2a-js/sdk": "^0.3.7", "@google-cloud/storage": "^7.16.0", @@ -18693,7 +18693,7 @@ }, "packages/cli": { "name": "@google/gemini-cli", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "license": "Apache-2.0", "dependencies": { "@agentclientprotocol/sdk": "^0.12.0", @@ -18796,7 +18796,7 @@ }, "packages/core": { "name": "@google/gemini-cli-core", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "license": "Apache-2.0", "dependencies": { "@a2a-js/sdk": "^0.3.7", @@ -18955,7 +18955,7 @@ }, "packages/test-utils": { "name": "@google/gemini-cli-test-utils", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "license": "Apache-2.0", "dependencies": { "@google/gemini-cli-core": "file:../core", @@ -18972,7 +18972,7 @@ }, "packages/vscode-ide-companion": { "name": "gemini-cli-vscode-ide-companion", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "license": "LICENSE", "dependencies": { "@modelcontextprotocol/sdk": "^1.23.0", diff --git a/package.json b/package.json index e4602937ba..3434bb8e49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "engines": { "node": ">=20.0.0" }, @@ -14,7 +14,7 @@ "url": "git+https://github.com/google-gemini/gemini-cli.git" }, "config": { - "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.26.0-nightly.20260114.bb6c57414" + "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.26.0-nightly.20260115.6cb3ae4e0" }, "scripts": { "start": "cross-env NODE_ENV=development node scripts/start.js", diff --git a/packages/a2a-server/package.json b/packages/a2a-server/package.json index 91bca79c21..d8d42b3cc8 100644 --- a/packages/a2a-server/package.json +++ b/packages/a2a-server/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli-a2a-server", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "description": "Gemini CLI A2A Server", "repository": { "type": "git", diff --git a/packages/cli/package.json b/packages/cli/package.json index 2f8e5ec8c2..880be3306f 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "description": "Gemini CLI", "license": "Apache-2.0", "repository": { @@ -26,7 +26,7 @@ "dist" ], "config": { - "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.26.0-nightly.20260114.bb6c57414" + "sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.26.0-nightly.20260115.6cb3ae4e0" }, "dependencies": { "@agentclientprotocol/sdk": "^0.12.0", diff --git a/packages/core/package.json b/packages/core/package.json index 47cf6dca99..c07bde995f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli-core", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "description": "Gemini CLI Core", "license": "Apache-2.0", "repository": { diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index c3e00ddd69..948fa14020 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -1,6 +1,6 @@ { "name": "@google/gemini-cli-test-utils", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "private": true, "main": "src/index.ts", "license": "Apache-2.0", diff --git a/packages/vscode-ide-companion/package.json b/packages/vscode-ide-companion/package.json index 9b0a994862..446e483664 100644 --- a/packages/vscode-ide-companion/package.json +++ b/packages/vscode-ide-companion/package.json @@ -2,7 +2,7 @@ "name": "gemini-cli-vscode-ide-companion", "displayName": "Gemini CLI Companion", "description": "Enable Gemini CLI with direct access to your IDE workspace.", - "version": "0.26.0-nightly.20260114.bb6c57414", + "version": "0.26.0-nightly.20260115.6cb3ae4e0", "publisher": "google", "icon": "assets/icon.png", "repository": { From a8631a109e5a397c859c7b37e7167171a10d06ec Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Thu, 15 Jan 2026 09:26:00 -0500 Subject: [PATCH 213/713] fix(automation): correct status/need-issue label matching wildcard (#16727) --- .github/scripts/pr-triage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/pr-triage.sh b/.github/scripts/pr-triage.sh index 2052406869..cca12747b7 100755 --- a/.github/scripts/pr-triage.sh +++ b/.github/scripts/pr-triage.sh @@ -68,7 +68,7 @@ process_pr_optimized() { fi else echo " ⚠️ No linked issue found for PR #${PR_NUMBER}" - if [[ ",${CURRENT_LABELS}," != ",status/need-issue,"* ]]; then + if [[ ",${CURRENT_LABELS}," != *",status/need-issue,"* ]]; then echo " ➕ Adding status/need-issue label" LABELS_TO_ADD="status/need-issue" fi @@ -82,7 +82,7 @@ process_pr_optimized() { else echo " 🔗 Found linked issue #${ISSUE_NUMBER}" - if [[ ",${CURRENT_LABELS}," == ",status/need-issue,"* ]]; then + if [[ ",${CURRENT_LABELS}," == *",status/need-issue,"* ]]; then echo " ➖ Removing status/need-issue label" LABELS_TO_REMOVE="status/need-issue" fi From d545a3b614e7c63ba53a4dd5d5807938c418c066 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Thu, 15 Jan 2026 10:50:36 -0500 Subject: [PATCH 214/713] fix(automation): prevent label-enforcer loop by ignoring all bots (#16746) Co-authored-by: Sehoon Shon --- .github/workflows/label-enforcer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-enforcer.yml b/.github/workflows/label-enforcer.yml index 173a80c103..8975e0d220 100644 --- a/.github/workflows/label-enforcer.yml +++ b/.github/workflows/label-enforcer.yml @@ -39,7 +39,7 @@ jobs: const labelName = context.payload.label.name; // Skip if the change was made by a bot to avoid infinite loops - if (username === 'github-actions[bot]') { + if (username === 'github-actions[bot]' || username === 'gemini-cli[bot]' || username.endsWith('[bot]')) { core.info('Change made by a bot. Skipping.'); return; } From fa3981990c981152d54dd4f30f79dd27507e24b9 Mon Sep 17 00:00:00 2001 From: g-samroberts <158088236+g-samroberts@users.noreply.github.com> Date: Thu, 15 Jan 2026 07:59:31 -0800 Subject: [PATCH 215/713] Add links to supported locations and minor fixes (#16476) --- docs/changelogs/releases.md | 4 ++-- docs/cli/custom-commands.md | 18 +++++++++--------- docs/cli/index.md | 4 ++-- docs/cli/model-routing.md | 2 +- docs/cli/sandbox.md | 2 +- docs/local-development.md | 2 +- docs/troubleshooting.md | 13 ++++++++++++- 7 files changed, 28 insertions(+), 17 deletions(-) diff --git a/docs/changelogs/releases.md b/docs/changelogs/releases.md index 90b94140c3..23524cfc3c 100644 --- a/docs/changelogs/releases.md +++ b/docs/changelogs/releases.md @@ -1230,7 +1230,7 @@ https://github.com/google-gemini/gemini-cli/compare/v0.19.4...v0.20.0 https://github.com/google-gemini/gemini-cli/pull/12863 - feat(hooks): Hook Telemetry Infrastructure by @Edilmo in https://github.com/google-gemini/gemini-cli/pull/9082 -- fix: (some minor improvements to configs and getPackageJson return behaviour) +- fix: (some minor improvements to configs and getPackageJson return behavior) by @grMLEqomlkkU5Eeinz4brIrOVCUCkJuN in https://github.com/google-gemini/gemini-cli/pull/12510 - feat(hooks): Hook Event Handling by @Edilmo in @@ -1364,7 +1364,7 @@ https://github.com/google-gemini/gemini-cli/compare/v0.18.4...v0.19.0 https://github.com/google-gemini/gemini-cli/pull/12863 - feat(hooks): Hook Telemetry Infrastructure by @Edilmo in https://github.com/google-gemini/gemini-cli/pull/9082 -- fix: (some minor improvements to configs and getPackageJson return behaviour) +- fix: (some minor improvements to configs and getPackageJson return behavior) by @grMLEqomlkkU5Eeinz4brIrOVCUCkJuN in https://github.com/google-gemini/gemini-cli/pull/12510 - feat(hooks): Hook Event Handling by @Edilmo in diff --git a/docs/cli/custom-commands.md b/docs/cli/custom-commands.md index 2d251fc373..b70be823f1 100644 --- a/docs/cli/custom-commands.md +++ b/docs/cli/custom-commands.md @@ -50,7 +50,7 @@ Your command definition files must be written in the TOML format and use the ## Handling arguments Custom commands support two powerful methods for handling arguments. The CLI -automatically chooses the correct method based on the content of your command\'s +automatically chooses the correct method based on the content of your command's `prompt`. ### 1. Context-aware injection with `{{args}}` @@ -96,13 +96,13 @@ Search Results: """ ``` -When you run `/grep-code It\'s complicated`: +When you run `/grep-code It's complicated`: 1. The CLI sees `{{args}}` used both outside and inside `!{...}`. -2. Outside: The first `{{args}}` is replaced raw with `It\'s complicated`. +2. Outside: The first `{{args}}` is replaced raw with `It's complicated`. 3. Inside: The second `{{args}}` is replaced with the escaped version (e.g., on Linux: `"It\'s complicated"`). -4. The command executed is `grep -r "It\'s complicated" .`. +4. The command executed is `grep -r "It's complicated" .`. 5. The CLI prompts you to confirm this exact, secure command before execution. 6. The final prompt is sent. @@ -129,13 +129,13 @@ format and behavior. # In: /.gemini/commands/changelog.toml # Invoked via: /changelog 1.2.0 added "Support for default argument parsing." -description = "Adds a new entry to the project\'s CHANGELOG.md file." +description = "Adds a new entry to the project's CHANGELOG.md file." prompt = """ # Task: Update Changelog You are an expert maintainer of this software project. A user has invoked a command to add a new entry to the changelog. -**The user\'s raw command is appended below your instructions.** +**The user's raw command is appended below your instructions.** Your task is to parse the ``, ``, and `` from their input and use the `write_file` tool to correctly update the `CHANGELOG.md` file. @@ -147,7 +147,7 @@ The command follows this format: `/changelog ` 1. Read the `CHANGELOG.md` file. 2. Find the section for the specified ``. 3. Add the `` under the correct `` heading. -4. If the version or type section doesn\'t exist, create it. +4. If the version or type section doesn't exist, create it. 5. Adhere strictly to the "Keep a Changelog" format. """ ``` @@ -241,7 +241,7 @@ operate on specific files. **Example (`review.toml`):** This command injects the content of a _fixed_ best practices file -(`docs/best-practices.md`) and uses the user\'s arguments to provide context for +(`docs/best-practices.md`) and uses the user's arguments to provide context for the review. ```toml @@ -293,7 +293,7 @@ practice. description = "Asks the model to refactor the current context into a pure function." prompt = """ -Please analyze the code I\'ve provided in the current context. +Please analyze the code I've provided in the current context. Refactor it into a pure function. Your response should include: diff --git a/docs/cli/index.md b/docs/cli/index.md index 069c802411..94d04f5c63 100644 --- a/docs/cli/index.md +++ b/docs/cli/index.md @@ -25,8 +25,8 @@ overview of Gemini CLI, see the [main documentation page](../index.md). - **[Checkpointing](./checkpointing.md):** Automatically save and restore snapshots of your session and files. -- **[Enterprise configuration](./enterprise.md):** Deploying and manage Gemini - CLI in an enterprise environment. +- **[Enterprise configuration](./enterprise.md):** Deploy and manage Gemini CLI + in an enterprise environment. - **[Sandboxing](./sandbox.md):** Isolate tool execution in a secure, containerized environment. - **[Telemetry](./telemetry.md):** Configure observability to monitor usage and diff --git a/docs/cli/model-routing.md b/docs/cli/model-routing.md index 15105a4ef8..1f833d3f6e 100644 --- a/docs/cli/model-routing.md +++ b/docs/cli/model-routing.md @@ -11,7 +11,7 @@ health and automatically routes requests to available models based on defined policies. 1. **Model failure:** If the currently selected model fails (e.g., due to quota - or server errors), the CLI will iniate the fallback process. + or server errors), the CLI will initiate the fallback process. 2. **User consent:** Depending on the failure and the model's policy, the CLI may prompt you to switch to a fallback model (by default always prompts diff --git a/docs/cli/sandbox.md b/docs/cli/sandbox.md index 09bb8f76d3..28b54851c2 100644 --- a/docs/cli/sandbox.md +++ b/docs/cli/sandbox.md @@ -11,7 +11,7 @@ Before using sandboxing, you need to install and set up the Gemini CLI: npm install -g @google/gemini-cli ``` -To verify the installation +To verify the installation: ```bash gemini --version diff --git a/docs/local-development.md b/docs/local-development.md index 11cbbae139..e194307eae 100644 --- a/docs/local-development.md +++ b/docs/local-development.md @@ -10,7 +10,7 @@ debug your code by instrumenting interesting events like model calls, tool scheduler, tool calls, etc. Dev traces are verbose and are specifically meant for understanding agent -behaviour and debugging issues. They are disabled by default. +behavior and debugging issues. They are disabled by default. To enable dev traces, set the `GEMINI_DEV_TRACING=true` environment variable when running Gemini CLI. diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 2dea1c7212..515099934a 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -28,6 +28,16 @@ topics on: - **Organizational Users:** Contact your Google Cloud administrator to be added to your organization's Gemini Code Assist subscription. +- **Error: + `Failed to login. Message: Your current account is not eligible... because it is not currently available in your location.`** + - **Cause:** Gemini CLI does not currently support your location. For a full + list of supported locations, see the following pages: + - Gemini Code Assist for individuals: + [Available locations](https://developers.google.com/gemini-code-assist/resources/available-locations#americas) + - Google AI Pro and Ultra where Gemini Code Assist (and Gemini CLI) is also + available: + [Available locations](https://developers.google.com/gemini-code-assist/resources/locations-pro-ultra) + - **Error: `Failed to login. Message: Request contains an invalid argument`** - **Cause:** Users with Google Workspace accounts or Google Cloud accounts associated with their Gmail accounts may not be able to activate the free @@ -137,7 +147,8 @@ This is especially useful for scripting and automation. - **Core debugging:** - Check the server console output for error messages or stack traces. - - Increase log verbosity if configurable. + - Increase log verbosity if configurable. For example, set the `DEBUG_MODE` + environment variable to `true` or `1`. - Use Node.js debugging tools (e.g., `node --inspect`) if you need to step through server-side code. From f909c9ef90304357d8b7ff30052ca4ed7c9ad781 Mon Sep 17 00:00:00 2001 From: Allen Hutchison Date: Thu, 15 Jan 2026 08:06:07 -0800 Subject: [PATCH 216/713] feat(policy): add source tracking to policy rules (#16670) --- packages/cli/src/ui/commands/policiesCommand.test.ts | 5 ++++- packages/cli/src/ui/commands/policiesCommand.ts | 3 +++ packages/core/src/policy/config.ts | 9 +++++++++ packages/core/src/policy/toml-loader.test.ts | 2 ++ packages/core/src/policy/toml-loader.ts | 1 + packages/core/src/policy/types.ts | 6 ++++++ 6 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/ui/commands/policiesCommand.test.ts b/packages/cli/src/ui/commands/policiesCommand.test.ts index 1e72bce0ae..268d00b9eb 100644 --- a/packages/cli/src/ui/commands/policiesCommand.test.ts +++ b/packages/cli/src/ui/commands/policiesCommand.test.ts @@ -72,6 +72,7 @@ describe('policiesCommand', () => { { decision: PolicyDecision.ALLOW, argsPattern: /safe/, + source: 'test.toml', }, { decision: PolicyDecision.ASK_USER, @@ -101,7 +102,9 @@ describe('policiesCommand', () => { expect(content).toContain( '1. **DENY** tool: `dangerousTool` [Priority: 10]', ); - expect(content).toContain('2. **ALLOW** all tools (args match: `safe`)'); + expect(content).toContain( + '2. **ALLOW** all tools (args match: `safe`) [Source: `test.toml`]', + ); expect(content).toContain('3. **ASK_USER** all tools'); }); }); diff --git a/packages/cli/src/ui/commands/policiesCommand.ts b/packages/cli/src/ui/commands/policiesCommand.ts index cc6136c3d5..f739364c11 100644 --- a/packages/cli/src/ui/commands/policiesCommand.ts +++ b/packages/cli/src/ui/commands/policiesCommand.ts @@ -53,6 +53,9 @@ const listPoliciesCommand: SlashCommand = { if (rule.priority !== undefined) { content += ` [Priority: ${rule.priority}]`; } + if (rule.source) { + content += ` [Source: \`${rule.source}\`]`; + } content += '\n'; }); diff --git a/packages/core/src/policy/config.ts b/packages/core/src/policy/config.ts index ff09b31d41..ccd2df7ec2 100644 --- a/packages/core/src/policy/config.ts +++ b/packages/core/src/policy/config.ts @@ -174,6 +174,7 @@ export async function createPolicyEngineConfig( toolName: `${serverName}__*`, decision: PolicyDecision.DENY, priority: 2.9, + source: 'Settings (MCP Excluded)', }); } } @@ -186,6 +187,7 @@ export async function createPolicyEngineConfig( toolName: tool, decision: PolicyDecision.DENY, priority: 2.4, + source: 'Settings (Tools Excluded)', }); } } @@ -213,6 +215,7 @@ export async function createPolicyEngineConfig( decision: PolicyDecision.ALLOW, priority: 2.3, argsPattern: new RegExp(pattern), + source: 'Settings (Tools Allowed)', }); } } @@ -223,6 +226,7 @@ export async function createPolicyEngineConfig( toolName, decision: PolicyDecision.ALLOW, priority: 2.3, + source: 'Settings (Tools Allowed)', }); } } else { @@ -234,6 +238,7 @@ export async function createPolicyEngineConfig( toolName, decision: PolicyDecision.ALLOW, priority: 2.3, + source: 'Settings (Tools Allowed)', }); } } @@ -252,6 +257,7 @@ export async function createPolicyEngineConfig( toolName: `${serverName}__*`, decision: PolicyDecision.ALLOW, priority: 2.2, + source: 'Settings (MCP Trusted)', }); } } @@ -265,6 +271,7 @@ export async function createPolicyEngineConfig( toolName: `${serverName}__*`, decision: PolicyDecision.ALLOW, priority: 2.1, + source: 'Settings (MCP Allowed)', }); } } @@ -310,6 +317,7 @@ export function createPolicyUpdater( // but still lose to admin policies (3.xxx) and settings excludes (200) priority: 2.95, argsPattern: new RegExp(pattern), + source: 'Dynamic (Confirmed)', }); } } @@ -326,6 +334,7 @@ export function createPolicyUpdater( // but still lose to admin policies (3.xxx) and settings excludes (200) priority: 2.95, argsPattern, + source: 'Dynamic (Confirmed)', }); } diff --git a/packages/core/src/policy/toml-loader.test.ts b/packages/core/src/policy/toml-loader.test.ts index 5f0a0eab8d..5b26c6a4bb 100644 --- a/packages/core/src/policy/toml-loader.test.ts +++ b/packages/core/src/policy/toml-loader.test.ts @@ -53,6 +53,7 @@ priority = 100 toolName: 'glob', decision: PolicyDecision.ALLOW, priority: 1.1, // tier 1 + 100/1000 + source: 'Default: test.toml', }); expect(result.checkers).toHaveLength(0); expect(result.errors).toHaveLength(0); @@ -190,6 +191,7 @@ modes = ["autoEdit"] expect(result.rules).toHaveLength(1); expect(result.rules[0].toolName).toBe('tier2-tool'); expect(result.rules[0].modes).toEqual(['autoEdit']); + expect(result.rules[0].source).toBe('User: tier2.toml'); expect(result.errors).toHaveLength(0); }); diff --git a/packages/core/src/policy/toml-loader.ts b/packages/core/src/policy/toml-loader.ts index b731151424..a895d01572 100644 --- a/packages/core/src/policy/toml-loader.ts +++ b/packages/core/src/policy/toml-loader.ts @@ -346,6 +346,7 @@ export async function loadPoliciesFromToml( priority: transformPriority(rule.priority, tier), modes: rule.modes, allowRedirection: rule.allow_redirection, + source: `${tierName.charAt(0).toUpperCase() + tierName.slice(1)}: ${file}`, }; // Compile regex pattern diff --git a/packages/core/src/policy/types.ts b/packages/core/src/policy/types.ts index c2d2802f1e..28f32035bc 100644 --- a/packages/core/src/policy/types.ts +++ b/packages/core/src/policy/types.ts @@ -135,6 +135,12 @@ export interface PolicyRule { * Only applies when decision is ALLOW. */ allowRedirection?: boolean; + + /** + * Effect of the rule's source. + * e.g. "my-policies.toml", "Settings (MCP Trusted)", etc. + */ + source?: string; } export interface SafetyCheckerRule { From 2b6bfe4097bd27cfa1cf56fc9c9ffab7079df60b Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Thu, 15 Jan 2026 11:40:33 -0500 Subject: [PATCH 217/713] =?UTF-8?q?feat(automation):=20enforce=20'?= =?UTF-8?q?=F0=9F=94=92=20maintainer=20only'=20and=20fix=20bot=20loop=20(#?= =?UTF-8?q?16751)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/label-enforcer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-enforcer.yml b/.github/workflows/label-enforcer.yml index 8975e0d220..5b5812dffe 100644 --- a/.github/workflows/label-enforcer.yml +++ b/.github/workflows/label-enforcer.yml @@ -10,7 +10,7 @@ jobs: enforce-label: # Run this job only when restricted labels are changed if: |- - ${{ (github.event.label.name == 'help wanted' || github.event.label.name == 'status/need-triage') && + ${{ (github.event.label.name == 'help wanted' || github.event.label.name == 'status/need-triage' || github.event.label.name == '🔒 maintainer only') && (github.repository == 'google-gemini/gemini-cli' || github.repository == 'google-gemini/maintainers-gemini-cli') }} runs-on: 'ubuntu-latest' permissions: From f7f38e2b9ef78fa0d4499ce442c8c633949efdba Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Thu, 15 Jan 2026 09:26:10 -0800 Subject: [PATCH 218/713] Make merged settings non-nullable and fix all lints related to that. (#16647) --- packages/cli/src/commands/hooks/migrate.ts | 3 +- packages/cli/src/commands/mcp/list.test.ts | 43 +- packages/cli/src/commands/mcp/list.ts | 5 +- .../cli/src/config/config.integration.test.ts | 9 +- packages/cli/src/config/config.test.ts | 741 +++++++++++------- packages/cli/src/config/config.ts | 44 +- .../config/extension-manager-agents.test.ts | 7 +- .../config/extension-manager-scope.test.ts | 38 +- .../config/extension-manager-skills.test.ts | 12 +- packages/cli/src/config/extension-manager.ts | 44 +- packages/cli/src/config/extension.test.ts | 29 +- .../extensions/extensionUpdates.test.ts | 10 +- packages/cli/src/config/settings.ts | 50 +- packages/cli/src/config/settingsSchema.ts | 24 +- packages/cli/src/core/initializer.test.ts | 2 +- packages/cli/src/core/initializer.ts | 4 +- packages/cli/src/core/theme.test.ts | 2 +- packages/cli/src/core/theme.ts | 2 +- packages/cli/src/gemini.test.tsx | 235 +++--- packages/cli/src/gemini.tsx | 37 +- .../cli/src/test-utils/mockCommandContext.ts | 9 +- packages/cli/src/ui/App.test.tsx | 4 +- packages/cli/src/ui/AppContainer.test.tsx | 51 +- packages/cli/src/ui/AppContainer.tsx | 54 +- packages/cli/src/ui/auth/AuthDialog.test.tsx | 14 +- packages/cli/src/ui/auth/AuthDialog.tsx | 10 +- packages/cli/src/ui/auth/useAuth.ts | 6 +- packages/cli/src/ui/commands/aboutCommand.ts | 2 +- .../cli/src/ui/commands/agentsCommand.test.ts | 20 +- packages/cli/src/ui/commands/agentsCommand.ts | 16 +- .../cli/src/ui/commands/hooksCommand.test.ts | 19 +- packages/cli/src/ui/commands/hooksCommand.ts | 6 +- packages/cli/src/ui/components/AppHeader.tsx | 4 +- .../cli/src/ui/components/Composer.test.tsx | 22 +- packages/cli/src/ui/components/Composer.tsx | 6 +- .../ui/components/EditorSettingsDialog.tsx | 6 +- packages/cli/src/ui/components/Footer.tsx | 11 +- .../cli/src/ui/components/StatusDisplay.tsx | 7 +- .../cli/src/ui/components/ThemeDialog.tsx | 4 +- .../messages/ToolConfirmationMessage.tsx | 2 +- .../cli/src/ui/contexts/VimModeContext.tsx | 6 +- .../cli/src/ui/hooks/useAlternateBuffer.ts | 2 +- packages/cli/src/ui/hooks/useFolderTrust.ts | 2 +- packages/cli/src/ui/hooks/useGeminiStream.ts | 4 +- .../src/ui/hooks/usePermissionsModifyTrust.ts | 2 +- .../cli/src/ui/hooks/useShowMemoryCommand.ts | 2 +- packages/cli/src/ui/hooks/useThemeCommand.ts | 8 +- packages/cli/src/ui/utils/CodeColorizer.tsx | 2 +- packages/cli/src/ui/utils/ui-sizing.ts | 2 +- packages/cli/src/ui/utils/updateCheck.test.ts | 2 +- packages/cli/src/ui/utils/updateCheck.ts | 2 +- packages/cli/src/utils/agentSettings.ts | 13 +- .../cli/src/utils/handleAutoUpdate.test.ts | 12 +- packages/cli/src/utils/handleAutoUpdate.ts | 8 +- packages/cli/src/utils/terminalTheme.ts | 8 +- .../src/validateNonInterActiveAuth.test.ts | 10 +- .../cli/src/validateNonInterActiveAuth.ts | 2 +- .../cli/src/zed-integration/zedIntegration.ts | 4 +- packages/core/src/telemetry/sdk.test.ts | 3 +- 59 files changed, 964 insertions(+), 744 deletions(-) diff --git a/packages/cli/src/commands/hooks/migrate.ts b/packages/cli/src/commands/hooks/migrate.ts index 36a1344f74..008997d4fe 100644 --- a/packages/cli/src/commands/hooks/migrate.ts +++ b/packages/cli/src/commands/hooks/migrate.ts @@ -230,8 +230,7 @@ export async function handleMigrateFromClaude() { const settings = loadSettings(workingDir); // Merge migrated hooks with existing hooks - const existingHooks = - (settings.merged.hooks as Record) || {}; + const existingHooks = settings.merged.hooks as Record; const mergedHooks = { ...existingHooks, ...migratedHooks }; // Update settings (setValue automatically saves) diff --git a/packages/cli/src/commands/mcp/list.test.ts b/packages/cli/src/commands/mcp/list.test.ts index 7d78d48233..fed9fb6a5c 100644 --- a/packages/cli/src/commands/mcp/list.test.ts +++ b/packages/cli/src/commands/mcp/list.test.ts @@ -6,15 +6,20 @@ import { vi, describe, it, expect, beforeEach, type Mock } from 'vitest'; import { listMcpServers } from './list.js'; -import { loadSettings } from '../../config/settings.js'; +import { loadSettings, mergeSettings } from '../../config/settings.js'; import { createTransport, debugLogger } from '@google/gemini-cli-core'; import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { ExtensionStorage } from '../../config/extensions/storage.js'; import { ExtensionManager } from '../../config/extension-manager.js'; -vi.mock('../../config/settings.js', () => ({ - loadSettings: vi.fn(), -})); +vi.mock('../../config/settings.js', async (importOriginal) => { + const actual = + await importOriginal(); + return { + ...actual, + loadSettings: vi.fn(), + }; +}); vi.mock('../../config/extensions/storage.js', () => ({ ExtensionStorage: { getUserExtensionsDir: vi.fn(), @@ -32,11 +37,16 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { CONNECTING: 'CONNECTING', DISCONNECTED: 'DISCONNECTED', }, - Storage: vi.fn().mockImplementation((_cwd: string) => ({ - getGlobalSettingsPath: () => '/tmp/gemini/settings.json', - getWorkspaceSettingsPath: () => '/tmp/gemini/workspace-settings.json', - getProjectTempDir: () => '/test/home/.gemini/tmp/mocked_hash', - })), + Storage: Object.assign( + vi.fn().mockImplementation((_cwd: string) => ({ + getGlobalSettingsPath: () => '/tmp/gemini/settings.json', + getWorkspaceSettingsPath: () => '/tmp/gemini/workspace-settings.json', + getProjectTempDir: () => '/test/home/.gemini/tmp/mocked_hash', + })), + { + getGlobalSettingsPath: () => '/tmp/gemini/settings.json', + }, + ), GEMINI_DIR: '.gemini', getErrorMessage: (e: unknown) => e instanceof Error ? e.message : String(e), @@ -96,7 +106,10 @@ describe('mcp list command', () => { }); it('should display message when no servers configured', async () => { - mockedLoadSettings.mockReturnValue({ merged: { mcpServers: {} } }); + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); + mockedLoadSettings.mockReturnValue({ + merged: { ...defaultMergedSettings, mcpServers: {} }, + }); await listMcpServers(); @@ -104,8 +117,10 @@ describe('mcp list command', () => { }); it('should display different server types with connected status', async () => { + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); mockedLoadSettings.mockReturnValue({ merged: { + ...defaultMergedSettings, mcpServers: { 'stdio-server': { command: '/path/to/server', args: ['arg1'] }, 'sse-server': { url: 'https://example.com/sse' }, @@ -138,8 +153,10 @@ describe('mcp list command', () => { }); it('should display disconnected status when connection fails', async () => { + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); mockedLoadSettings.mockReturnValue({ merged: { + ...defaultMergedSettings, mcpServers: { 'test-server': { command: '/test/server' }, }, @@ -158,9 +175,13 @@ describe('mcp list command', () => { }); it('should merge extension servers with config servers', async () => { + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); mockedLoadSettings.mockReturnValue({ merged: { - mcpServers: { 'config-server': { command: '/config/server' } }, + ...defaultMergedSettings, + mcpServers: { + 'config-server': { command: '/config/server' }, + }, }, }); diff --git a/packages/cli/src/commands/mcp/list.ts b/packages/cli/src/commands/mcp/list.ts index b41baec960..27a25fec4a 100644 --- a/packages/cli/src/commands/mcp/list.ts +++ b/packages/cli/src/commands/mcp/list.ts @@ -35,7 +35,7 @@ async function getMcpServersFromConfig(): Promise< requestSetting: promptForSetting, }); const extensions = await extensionManager.loadExtensions(); - const mcpServers = { ...(settings.merged.mcpServers || {}) }; + const mcpServers = { ...settings.merged.mcpServers }; for (const extension of extensions) { Object.entries(extension.mcpServers || {}).forEach(([key, server]) => { if (mcpServers[key]) { @@ -63,8 +63,7 @@ async function testMCPConnection( const sanitizationConfig = { enableEnvironmentVariableRedaction: true, allowedEnvironmentVariables: [], - blockedEnvironmentVariables: - settings.merged.advanced?.excludedEnvVars || [], + blockedEnvironmentVariables: settings.merged.advanced.excludedEnvVars, }; let transport; diff --git a/packages/cli/src/config/config.integration.test.ts b/packages/cli/src/config/config.integration.test.ts index 49afb1ae5b..6797be4447 100644 --- a/packages/cli/src/config/config.integration.test.ts +++ b/packages/cli/src/config/config.integration.test.ts @@ -22,8 +22,9 @@ import { Config, DEFAULT_FILE_FILTERING_OPTIONS, } from '@google/gemini-cli-core'; -import type { Settings } from './settingsSchema.js'; +import { createTestMergedSettings } from './settings.js'; import { http, HttpResponse } from 'msw'; + import { setupServer } from 'msw/node'; export const server = setupServer(); @@ -212,7 +213,7 @@ describe('Configuration Integration Tests', () => { const originalArgv = process.argv; try { process.argv = argv; - const parsedArgs = await parseArguments({} as Settings); + const parsedArgs = await parseArguments(createTestMergedSettings()); expect(parsedArgs.approvalMode).toBe(expected.approvalMode); expect(parsedArgs.prompt).toBe(expected.prompt); expect(parsedArgs.yolo).toBe(expected.yolo); @@ -235,7 +236,9 @@ describe('Configuration Integration Tests', () => { const originalArgv = process.argv; try { process.argv = argv; - await expect(parseArguments({} as Settings)).rejects.toThrow(); + await expect( + parseArguments(createTestMergedSettings()), + ).rejects.toThrow(); } finally { process.argv = originalArgv; } diff --git a/packages/cli/src/config/config.test.ts b/packages/cli/src/config/config.test.ts index 78a4847fd2..3dd1a6e155 100644 --- a/packages/cli/src/config/config.test.ts +++ b/packages/cli/src/config/config.test.ts @@ -19,8 +19,9 @@ import { ApprovalMode, } from '@google/gemini-cli-core'; import { loadCliConfig, parseArguments, type CliArgs } from './config.js'; -import type { Settings } from './settings.js'; +import { type Settings, createTestMergedSettings } from './settings.js'; import * as ServerConfig from '@google/gemini-cli-core'; + import { isWorkspaceTrusted } from './trustedFolders.js'; import { ExtensionManager } from './extension-manager.js'; import { RESUME_LATEST } from '../utils/sessionUtils.js'; @@ -189,7 +190,7 @@ describe('parseArguments', () => { .spyOn(console, 'error') .mockImplementation(() => {}); - await expect(parseArguments({} as Settings)).rejects.toThrow( + await expect(parseArguments(createTestMergedSettings())).rejects.toThrow( 'process.exit called', ); @@ -222,7 +223,7 @@ describe('parseArguments', () => { }, ])('$description', async ({ argv, expected }) => { process.argv = argv; - const parsedArgs = await parseArguments({} as Settings); + const parsedArgs = await parseArguments(createTestMergedSettings()); expect(parsedArgs.prompt).toBe(expected.prompt); expect(parsedArgs.promptInteractive).toBe(expected.promptInteractive); }); @@ -344,7 +345,7 @@ describe('parseArguments', () => { '$description', async ({ argv, expectedQuery, expectedModel, debug }) => { process.argv = argv; - const parsedArgs = await parseArguments({} as Settings); + const parsedArgs = await parseArguments(createTestMergedSettings()); expect(parsedArgs.query).toBe(expectedQuery); expect(parsedArgs.prompt).toBe(expectedQuery); expect(parsedArgs.promptInteractive).toBeUndefined(); @@ -380,7 +381,7 @@ describe('parseArguments', () => { .spyOn(console, 'error') .mockImplementation(() => {}); - await expect(parseArguments({} as Settings)).rejects.toThrow( + await expect(parseArguments(createTestMergedSettings())).rejects.toThrow( 'process.exit called', ); @@ -408,7 +409,7 @@ describe('parseArguments', () => { }, ])('$description', async ({ argv, expected }) => { process.argv = argv; - const parsedArgs = await parseArguments({} as Settings); + const parsedArgs = await parseArguments(createTestMergedSettings()); expect(parsedArgs.approvalMode).toBe(expected.approvalMode); expect(parsedArgs.yolo).toBe(expected.yolo); }); @@ -427,7 +428,7 @@ describe('parseArguments', () => { .spyOn(debugLogger, 'error') .mockImplementation(() => {}); - await expect(parseArguments({} as Settings)).rejects.toThrow( + await expect(parseArguments(createTestMergedSettings())).rejects.toThrow( 'process.exit called', ); @@ -447,7 +448,7 @@ describe('parseArguments', () => { process.argv = ['node', 'script.js', '--resume', 'session-id']; try { - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); expect(argv.resume).toBe('session-id'); } finally { process.stdin.isTTY = originalIsTTY; @@ -460,7 +461,7 @@ describe('parseArguments', () => { process.argv = ['node', 'script.js', '--resume']; try { - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); expect(argv.resume).toBe(RESUME_LATEST); expect(argv.resume).toBe('latest'); } finally { @@ -475,7 +476,7 @@ describe('parseArguments', () => { '--allowed-tools', 'read_file,ShellTool(git status)', ]; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); expect(argv.allowedTools).toEqual(['read_file', 'ShellTool(git status)']); }); @@ -486,13 +487,13 @@ describe('parseArguments', () => { '--allowed-mcp-server-names', 'server1,server2', ]; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); expect(argv.allowedMcpServerNames).toEqual(['server1', 'server2']); }); it('should support comma-separated values for --extensions', async () => { process.argv = ['node', 'script.js', '--extensions', 'ext1,ext2']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); expect(argv.extensions).toEqual(['ext1', 'ext2']); }); @@ -504,7 +505,7 @@ describe('parseArguments', () => { 'test-model-string', 'my-positional-arg', ]; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); expect(argv.model).toBe('test-model-string'); expect(argv.query).toBe('my-positional-arg'); }); @@ -521,7 +522,7 @@ describe('parseArguments', () => { '--allowed-tools=ShellTool(wc)', 'Use whoami to write a poem in file poem.md about my username in pig latin and use wc to tell me how many lines are in the poem you wrote.', ]; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); expect(argv.extensions).toEqual(['none']); expect(argv.approvalMode).toBe('auto_edit'); expect(argv.allowedTools).toEqual([ @@ -576,8 +577,8 @@ describe('loadCliConfig', () => { it(`should leave proxy to empty by default`, async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getProxy()).toBeFalsy(); }); @@ -617,8 +618,8 @@ describe('loadCliConfig', () => { it(`should set proxy to ${expected} according to environment variable [${input.env_name}]`, async () => { vi.stubEnv(input.env_name, input.proxy_url); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getProxy()).toBe(expected); }); @@ -627,8 +628,8 @@ describe('loadCliConfig', () => { it('should use default fileFilter options when unconfigured', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getFileFilteringRespectGitIgnore()).toBe( DEFAULT_FILE_FILTERING_OPTIONS.respectGitIgnore, @@ -653,7 +654,7 @@ describe('Hierarchical Memory Loading (config.ts) - Placeholder Suite', () => { it('should pass extension context file paths to loadServerHierarchicalMemory', async () => { process.argv = ['node', 'script.js']; - const settings: Settings = {}; + const settings = createTestMergedSettings(); vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([ { path: '/path/to/ext1', @@ -683,7 +684,7 @@ describe('Hierarchical Memory Loading (config.ts) - Placeholder Suite', () => { isActive: true, }, ]); - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); await loadCliConfig(settings, 'session-id', argv); expect(ServerConfig.loadServerHierarchicalMemory).toHaveBeenCalledWith( expect.any(String), @@ -693,24 +694,24 @@ describe('Hierarchical Memory Loading (config.ts) - Placeholder Suite', () => { expect.any(ExtensionManager), true, 'tree', - { - respectGitIgnore: false, + expect.objectContaining({ + respectGitIgnore: true, respectGeminiIgnore: true, - }, - undefined, // maxDirs + }), + 200, // maxDirs ); }); }); describe('mergeMcpServers', () => { it('should not modify the original settings object', async () => { - const settings: Settings = { + const settings = createTestMergedSettings({ mcpServers: { 'test-server': { url: 'http://localhost:8080', }, }, - }; + }); vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([ { @@ -730,7 +731,7 @@ describe('mergeMcpServers', () => { ]); const originalSettings = JSON.parse(JSON.stringify(settings)); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); await loadCliConfig(settings, 'test-session', argv); expect(settings).toEqual(originalSettings); }); @@ -755,7 +756,9 @@ describe('mergeExcludeTools', () => { }); it('should merge excludeTools from settings and extensions', async () => { - const settings: Settings = { tools: { exclude: ['tool1', 'tool2'] } }; + const settings = createTestMergedSettings({ + tools: { exclude: ['tool1', 'tool2'] }, + }); vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([ { path: '/path/to/ext1', @@ -777,7 +780,7 @@ describe('mergeExcludeTools', () => { }, ]); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig( settings, @@ -791,7 +794,9 @@ describe('mergeExcludeTools', () => { }); it('should handle overlapping excludeTools between settings and extensions', async () => { - const settings: Settings = { tools: { exclude: ['tool1', 'tool2'] } }; + const settings = createTestMergedSettings({ + tools: { exclude: ['tool1', 'tool2'] }, + }); vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([ { path: '/path/to/ext1', @@ -804,7 +809,7 @@ describe('mergeExcludeTools', () => { }, ]); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getExcludeTools()).toEqual( new Set(['tool1', 'tool2', 'tool3']), @@ -813,7 +818,9 @@ describe('mergeExcludeTools', () => { }); it('should handle overlapping excludeTools between extensions', async () => { - const settings: Settings = { tools: { exclude: ['tool1'] } }; + const settings = createTestMergedSettings({ + tools: { exclude: ['tool1'] }, + }); vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([ { path: '/path/to/ext1', @@ -835,7 +842,7 @@ describe('mergeExcludeTools', () => { }, ]); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getExcludeTools()).toEqual( new Set(['tool1', 'tool2', 'tool3', 'tool4']), @@ -845,26 +852,28 @@ describe('mergeExcludeTools', () => { it('should return an empty array when no excludeTools are specified and it is interactive', async () => { process.stdin.isTTY = true; - const settings: Settings = {}; + const settings = createTestMergedSettings(); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getExcludeTools()).toEqual(new Set([])); }); it('should return default excludes when no excludeTools are specified and it is not interactive', async () => { process.stdin.isTTY = false; - const settings: Settings = {}; + const settings = createTestMergedSettings(); process.argv = ['node', 'script.js', '-p', 'test']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getExcludeTools()).toEqual(defaultExcludes); }); it('should handle settings with excludeTools but no extensions', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { tools: { exclude: ['tool1', 'tool2'] } }; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ + tools: { exclude: ['tool1', 'tool2'] }, + }); vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([]); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getExcludeTools()).toEqual(new Set(['tool1', 'tool2'])); @@ -872,7 +881,7 @@ describe('mergeExcludeTools', () => { }); it('should handle extensions with excludeTools but no settings', async () => { - const settings: Settings = {}; + const settings = createTestMergedSettings(); vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([ { path: '/path/to/ext', @@ -885,14 +894,16 @@ describe('mergeExcludeTools', () => { }, ]); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getExcludeTools()).toEqual(new Set(['tool1', 'tool2'])); expect(config.getExcludeTools()).toHaveLength(2); }); it('should not modify the original settings object', async () => { - const settings: Settings = { tools: { exclude: ['tool1'] } }; + const settings = createTestMergedSettings({ + tools: { exclude: ['tool1'] }, + }); vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([ { path: '/path/to/ext', @@ -906,7 +917,7 @@ describe('mergeExcludeTools', () => { ]); const originalSettings = JSON.parse(JSON.stringify(settings)); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); await loadCliConfig(settings, 'test-session', argv); expect(settings).toEqual(originalSettings); }); @@ -930,8 +941,8 @@ describe('Approval mode tool exclusion logic', () => { it('should exclude all interactive tools in non-interactive mode with default approval mode', async () => { process.argv = ['node', 'script.js', '-p', 'test']; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); const excludedTools = config.getExcludeTools(); @@ -949,8 +960,8 @@ describe('Approval mode tool exclusion logic', () => { '-p', 'test', ]; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); @@ -969,8 +980,8 @@ describe('Approval mode tool exclusion logic', () => { '-p', 'test', ]; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); @@ -989,8 +1000,8 @@ describe('Approval mode tool exclusion logic', () => { '-p', 'test', ]; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); @@ -1002,8 +1013,8 @@ describe('Approval mode tool exclusion logic', () => { it('should exclude no interactive tools in non-interactive mode with legacy yolo flag', async () => { process.argv = ['node', 'script.js', '--yolo', '-p', 'test']; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); @@ -1026,8 +1037,8 @@ describe('Approval mode tool exclusion logic', () => { for (const testCase of testCases) { process.argv = testCase.args; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); @@ -1047,8 +1058,10 @@ describe('Approval mode tool exclusion logic', () => { '-p', 'test', ]; - const argv = await parseArguments({} as Settings); - const settings: Settings = { tools: { exclude: ['custom_tool'] } }; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ + tools: { exclude: ['custom_tool'] }, + }); const config = await loadCliConfig(settings, 'test-session', argv); @@ -1061,12 +1074,12 @@ describe('Approval mode tool exclusion logic', () => { it('should throw an error if YOLO mode is attempted when disableYoloMode is true', async () => { process.argv = ['node', 'script.js', '--yolo']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ security: { disableYoloMode: true, }, - }; + }); await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow( 'Cannot start in YOLO mode since it is disabled by your admin', @@ -1082,7 +1095,7 @@ describe('Approval mode tool exclusion logic', () => { yolo: false, }; - const settings: Settings = {}; + const settings = createTestMergedSettings(); await expect( loadCliConfig(settings, 'test-session', invalidArgv as CliArgs), ).rejects.toThrow( @@ -1104,17 +1117,17 @@ describe('loadCliConfig with allowed-mcp-server-names', () => { vi.restoreAllMocks(); }); - const baseSettings: Settings = { + const baseSettings = createTestMergedSettings({ mcpServers: { server1: { url: 'http://localhost:8080' }, server2: { url: 'http://localhost:8081' }, server3: { url: 'http://localhost:8082' }, }, - }; + }); it('should allow all MCP servers if the flag is not provided', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig(baseSettings, 'test-session', argv); expect(config.getMcpServers()).toEqual(baseSettings.mcpServers); }); @@ -1126,7 +1139,7 @@ describe('loadCliConfig with allowed-mcp-server-names', () => { '--allowed-mcp-server-names', 'server1', ]; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig(baseSettings, 'test-session', argv); expect(config.getAllowedMcpServers()).toEqual(['server1']); }); @@ -1140,7 +1153,7 @@ describe('loadCliConfig with allowed-mcp-server-names', () => { '--allowed-mcp-server-names', 'server3', ]; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig(baseSettings, 'test-session', argv); expect(config.getAllowedMcpServers()).toEqual(['server1', 'server3']); }); @@ -1154,50 +1167,50 @@ describe('loadCliConfig with allowed-mcp-server-names', () => { '--allowed-mcp-server-names', 'server4', ]; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig(baseSettings, 'test-session', argv); expect(config.getAllowedMcpServers()).toEqual(['server1', 'server4']); }); it('should allow no MCP servers if the flag is provided but empty', async () => { process.argv = ['node', 'script.js', '--allowed-mcp-server-names', '']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig(baseSettings, 'test-session', argv); expect(config.getAllowedMcpServers()).toEqual(['']); }); it('should read allowMCPServers from settings', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ ...baseSettings, mcp: { allowed: ['server1', 'server2'] }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getAllowedMcpServers()).toEqual(['server1', 'server2']); }); it('should read excludeMCPServers from settings', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ ...baseSettings, mcp: { excluded: ['server1', 'server2'] }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getBlockedMcpServers()).toEqual(['server1', 'server2']); }); it('should override allowMCPServers with excludeMCPServers if overlapping', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ ...baseSettings, mcp: { excluded: ['server1'], allowed: ['server1', 'server2'], }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getAllowedMcpServers()).toEqual(['server1', 'server2']); expect(config.getBlockedMcpServers()).toEqual(['server1']); @@ -1210,14 +1223,14 @@ describe('loadCliConfig with allowed-mcp-server-names', () => { '--allowed-mcp-server-names', 'server1', ]; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ ...baseSettings, mcp: { excluded: ['server1'], allowed: ['server2'], }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getAllowedMcpServers()).toEqual(['server1']); }); @@ -1231,14 +1244,14 @@ describe('loadCliConfig with allowed-mcp-server-names', () => { '--allowed-mcp-server-names', 'server3', ]; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ ...baseSettings, mcp: { allowed: ['server1', 'server2'], // Should be ignored excluded: ['server3'], // Should be ignored }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getAllowedMcpServers()).toEqual(['server2', 'server3']); expect(config.getBlockedMcpServers()).toEqual([]); @@ -1256,13 +1269,13 @@ describe('loadCliConfig model selection', () => { it('selects a model from settings.json if provided', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig( - { + createTestMergedSettings({ model: { name: 'gemini-2.5-pro', }, - }, + }), 'test-session', argv, ); @@ -1272,11 +1285,11 @@ describe('loadCliConfig model selection', () => { it('uses the default gemini model if nothing is set', async () => { process.argv = ['node', 'script.js']; // No model set. - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig( - { + createTestMergedSettings({ // No model set. - }, + }), 'test-session', argv, ); @@ -1286,13 +1299,13 @@ describe('loadCliConfig model selection', () => { it('always prefers model from argv', async () => { process.argv = ['node', 'script.js', '--model', 'gemini-2.5-flash-preview']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig( - { + createTestMergedSettings({ model: { name: 'gemini-2.5-pro', }, - }, + }), 'test-session', argv, ); @@ -1302,11 +1315,11 @@ describe('loadCliConfig model selection', () => { it('selects the model from argv if provided', async () => { process.argv = ['node', 'script.js', '--model', 'gemini-2.5-flash-preview']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig( - { + createTestMergedSettings({ // No model provided via settings. - }, + }), 'test-session', argv, ); @@ -1316,11 +1329,11 @@ describe('loadCliConfig model selection', () => { it('selects the default auto model if provided via auto alias', async () => { process.argv = ['node', 'script.js', '--model', 'auto']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig( - { + createTestMergedSettings({ // No model provided via settings. - }, + }), 'test-session', argv, ); @@ -1344,36 +1357,36 @@ describe('loadCliConfig folderTrust', () => { it('should be false when folderTrust is false', async () => { process.argv = ['node', 'script.js']; - const settings: Settings = { + const settings = createTestMergedSettings({ security: { folderTrust: { enabled: false, }, }, - }; - const argv = await parseArguments({} as Settings); + }); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getFolderTrust()).toBe(false); }); it('should be true when folderTrust is true', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ security: { folderTrust: { enabled: true, }, }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getFolderTrust()).toBe(true); }); it('should be false by default', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getFolderTrust()).toBe(false); }); @@ -1404,8 +1417,8 @@ describe('loadCliConfig with includeDirectories', () => { '--include-directories', `${path.resolve(path.sep, 'cli', 'path1')},${path.join(mockCwd, 'cli', 'path2')}`, ]; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ context: { includeDirectories: [ path.resolve(path.sep, 'settings', 'path1'), @@ -1413,7 +1426,7 @@ describe('loadCliConfig with includeDirectories', () => { path.join(mockCwd, 'settings', 'path3'), ], }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); const expected = [ mockCwd, @@ -1449,22 +1462,22 @@ describe('loadCliConfig compressionThreshold', () => { it('should pass settings to the core config', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ model: { compressionThreshold: 0.5, }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(await config.getCompressionThreshold()).toBe(0.5); }); - it('should have undefined compressionThreshold if not in settings', async () => { + it('should have default compressionThreshold if not in settings', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); - expect(await config.getCompressionThreshold()).toBeUndefined(); + expect(await config.getCompressionThreshold()).toBe(0.5); }); }); @@ -1483,24 +1496,24 @@ describe('loadCliConfig useRipgrep', () => { it('should be true by default when useRipgrep is not set in settings', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getUseRipgrep()).toBe(true); }); it('should be false when useRipgrep is set to false in settings', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { tools: { useRipgrep: false } }; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ tools: { useRipgrep: false } }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getUseRipgrep()).toBe(false); }); it('should be true when useRipgrep is explicitly set to true in settings', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { tools: { useRipgrep: true } }; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ tools: { useRipgrep: true } }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getUseRipgrep()).toBe(true); }); @@ -1521,38 +1534,38 @@ describe('screenReader configuration', () => { it('should use screenReader value from settings if CLI flag is not present (settings true)', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ ui: { accessibility: { screenReader: true } }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getScreenReader()).toBe(true); }); it('should use screenReader value from settings if CLI flag is not present (settings false)', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ ui: { accessibility: { screenReader: false } }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getScreenReader()).toBe(false); }); it('should prioritize --screen-reader CLI flag (true) over settings (false)', async () => { process.argv = ['node', 'script.js', '--screen-reader']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ ui: { accessibility: { screenReader: false } }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getScreenReader()).toBe(true); }); it('should be false by default when no flag or setting is present', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = {}; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings(); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getScreenReader()).toBe(false); }); @@ -1582,8 +1595,12 @@ describe('loadCliConfig tool exclusions', () => { it('should not exclude interactive tools in interactive mode without YOLO', async () => { process.stdin.isTTY = true; process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getExcludeTools()).not.toContain('run_shell_command'); expect(config.getExcludeTools()).not.toContain('replace'); expect(config.getExcludeTools()).not.toContain('write_file'); @@ -1592,8 +1609,12 @@ describe('loadCliConfig tool exclusions', () => { it('should not exclude interactive tools in interactive mode with YOLO', async () => { process.stdin.isTTY = true; process.argv = ['node', 'script.js', '--yolo']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getExcludeTools()).not.toContain('run_shell_command'); expect(config.getExcludeTools()).not.toContain('replace'); expect(config.getExcludeTools()).not.toContain('write_file'); @@ -1602,8 +1623,12 @@ describe('loadCliConfig tool exclusions', () => { it('should exclude interactive tools in non-interactive mode without YOLO', async () => { process.stdin.isTTY = false; process.argv = ['node', 'script.js', '-p', 'test']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getExcludeTools()).toContain('run_shell_command'); expect(config.getExcludeTools()).toContain('replace'); expect(config.getExcludeTools()).toContain('write_file'); @@ -1612,8 +1637,12 @@ describe('loadCliConfig tool exclusions', () => { it('should not exclude interactive tools in non-interactive mode with YOLO', async () => { process.stdin.isTTY = false; process.argv = ['node', 'script.js', '-p', 'test', '--yolo']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getExcludeTools()).not.toContain('run_shell_command'); expect(config.getExcludeTools()).not.toContain('replace'); expect(config.getExcludeTools()).not.toContain('write_file'); @@ -1629,16 +1658,24 @@ describe('loadCliConfig tool exclusions', () => { '--allowed-tools', 'ShellTool', ]; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getExcludeTools()).not.toContain(SHELL_TOOL_NAME); }); it('should exclude web-fetch in non-interactive mode when not allowed', async () => { process.stdin.isTTY = false; process.argv = ['node', 'script.js', '-p', 'test']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getExcludeTools()).toContain(WEB_FETCH_TOOL_NAME); }); @@ -1652,8 +1689,12 @@ describe('loadCliConfig tool exclusions', () => { '--allowed-tools', WEB_FETCH_TOOL_NAME, ]; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getExcludeTools()).not.toContain(WEB_FETCH_TOOL_NAME); }); @@ -1667,8 +1708,12 @@ describe('loadCliConfig tool exclusions', () => { '--allowed-tools', 'run_shell_command', ]; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getExcludeTools()).not.toContain(SHELL_TOOL_NAME); }); @@ -1682,8 +1727,12 @@ describe('loadCliConfig tool exclusions', () => { '--allowed-tools', 'ShellTool(wc)', ]; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getExcludeTools()).not.toContain(SHELL_TOOL_NAME); }); }); @@ -1708,40 +1757,60 @@ describe('loadCliConfig interactive', () => { it('should be interactive if isTTY and no prompt', async () => { process.stdin.isTTY = true; process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(true); }); it('should be interactive if prompt-interactive is set', async () => { process.stdin.isTTY = false; process.argv = ['node', 'script.js', '--prompt-interactive', 'test']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(true); }); it('should not be interactive if not isTTY and no prompt', async () => { process.stdin.isTTY = false; process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(false); }); it('should not be interactive if prompt is set', async () => { process.stdin.isTTY = true; process.argv = ['node', 'script.js', '--prompt', 'test']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(false); }); it('should not be interactive if positional prompt words are provided with other flags', async () => { process.stdin.isTTY = true; process.argv = ['node', 'script.js', '--model', 'gemini-2.5-pro', 'Hello']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(false); }); @@ -1755,8 +1824,12 @@ describe('loadCliConfig interactive', () => { '--yolo', 'Hello world', ]; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(false); // Verify the question is preserved for one-shot execution expect(argv.prompt).toBe('Hello world'); @@ -1766,8 +1839,12 @@ describe('loadCliConfig interactive', () => { it('should not be interactive if positional prompt words are provided with extensions flag', async () => { process.stdin.isTTY = true; process.argv = ['node', 'script.js', '-e', 'none', 'hello']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(false); expect(argv.query).toBe('hello'); expect(argv.extensions).toEqual(['none']); @@ -1776,8 +1853,12 @@ describe('loadCliConfig interactive', () => { it('should handle multiple positional words correctly', async () => { process.stdin.isTTY = true; process.argv = ['node', 'script.js', 'hello world how are you']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(false); expect(argv.query).toBe('hello world how are you'); expect(argv.prompt).toBe('hello world how are you'); @@ -1797,8 +1878,12 @@ describe('loadCliConfig interactive', () => { 'sort', 'array', ]; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(false); expect(argv.query).toBe('write a function to sort array'); expect(argv.model).toBe('gemini-2.5-pro'); @@ -1807,8 +1892,12 @@ describe('loadCliConfig interactive', () => { it('should handle empty positional arguments', async () => { process.stdin.isTTY = true; process.argv = ['node', 'script.js', '']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(true); expect(argv.query).toBeUndefined(); }); @@ -1826,8 +1915,12 @@ describe('loadCliConfig interactive', () => { 'are', 'you', ]; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(false); expect(argv.query).toBe('hello world how are you'); expect(argv.extensions).toEqual(['none']); @@ -1836,8 +1929,12 @@ describe('loadCliConfig interactive', () => { it('should be interactive if no positional prompt words are provided with flags', async () => { process.stdin.isTTY = true; process.argv = ['node', 'script.js', '--model', 'gemini-2.5-pro']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(true); }); }); @@ -1865,43 +1962,67 @@ describe('loadCliConfig approval mode', () => { it('should default to DEFAULT approval mode when no flags are set', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT); }); it('should set YOLO approval mode when --yolo flag is used', async () => { process.argv = ['node', 'script.js', '--yolo']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.YOLO); }); it('should set YOLO approval mode when -y flag is used', async () => { process.argv = ['node', 'script.js', '-y']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.YOLO); }); it('should set DEFAULT approval mode when --approval-mode=default', async () => { process.argv = ['node', 'script.js', '--approval-mode', 'default']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT); }); it('should set AUTO_EDIT approval mode when --approval-mode=auto_edit', async () => { process.argv = ['node', 'script.js', '--approval-mode', 'auto_edit']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.AUTO_EDIT); }); it('should set YOLO approval mode when --approval-mode=yolo', async () => { process.argv = ['node', 'script.js', '--approval-mode', 'yolo']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.YOLO); }); @@ -1909,17 +2030,25 @@ describe('loadCliConfig approval mode', () => { // Note: This test documents the intended behavior, but in practice the validation // prevents both flags from being used together process.argv = ['node', 'script.js', '--approval-mode', 'default']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); // Manually set yolo to true to simulate what would happen if validation didn't prevent it argv.yolo = true; - const config = await loadCliConfig({}, 'test-session', argv); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT); }); it('should fall back to --yolo behavior when --approval-mode is not set', async () => { process.argv = ['node', 'script.js', '--yolo']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.YOLO); }); @@ -1934,29 +2063,45 @@ describe('loadCliConfig approval mode', () => { it('should override --approval-mode=yolo to DEFAULT', async () => { process.argv = ['node', 'script.js', '--approval-mode', 'yolo']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT); }); it('should override --approval-mode=auto_edit to DEFAULT', async () => { process.argv = ['node', 'script.js', '--approval-mode', 'auto_edit']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT); }); it('should override --yolo flag to DEFAULT', async () => { process.argv = ['node', 'script.js', '--yolo']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT); }); it('should remain DEFAULT when --approval-mode=default', async () => { process.argv = ['node', 'script.js', '--approval-mode', 'default']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT); }); }); @@ -2032,11 +2177,11 @@ describe('loadCliConfig fileFiltering', () => { it.each(testCases)( 'should pass $property from settings to config when $value', async ({ property, getter, value }) => { - const settings: Settings = { + const settings = createTestMergedSettings({ context: { fileFiltering: { [property]: value }, }, - }; + }); const argv = await parseArguments(settings); const config = await loadCliConfig(settings, 'test-session', argv); expect(getter(config)).toBe(value); @@ -2055,16 +2200,20 @@ describe('Output format', () => { it('should default to TEXT', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getOutputFormat()).toBe(OutputFormat.TEXT); }); it('should use the format from settings', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig( - { output: { format: OutputFormat.JSON } }, + createTestMergedSettings({ output: { format: OutputFormat.JSON } }), 'test-session', argv, ); @@ -2073,9 +2222,9 @@ describe('Output format', () => { it('should prioritize the format from argv', async () => { process.argv = ['node', 'script.js', '--output-format', 'json']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig( - { output: { format: OutputFormat.JSON } }, + createTestMergedSettings({ output: { format: OutputFormat.JSON } }), 'test-session', argv, ); @@ -2084,8 +2233,12 @@ describe('Output format', () => { it('should accept stream-json as a valid output format', async () => { process.argv = ['node', 'script.js', '--output-format', 'stream-json']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getOutputFormat()).toBe(OutputFormat.STREAM_JSON); }); @@ -2103,7 +2256,7 @@ describe('Output format', () => { .spyOn(debugLogger, 'error') .mockImplementation(() => {}); - await expect(parseArguments({} as Settings)).rejects.toThrow( + await expect(parseArguments(createTestMergedSettings())).rejects.toThrow( 'process.exit called', ); expect(debugErrorSpy).toHaveBeenCalledWith( @@ -2145,7 +2298,7 @@ describe('parseArguments with positional prompt', () => { .spyOn(debugLogger, 'error') .mockImplementation(() => {}); - await expect(parseArguments({} as Settings)).rejects.toThrow( + await expect(parseArguments(createTestMergedSettings())).rejects.toThrow( 'process.exit called', ); @@ -2162,7 +2315,7 @@ describe('parseArguments with positional prompt', () => { it('should correctly parse a positional prompt to query field', async () => { process.argv = ['node', 'script.js', 'positional', 'prompt']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); expect(argv.query).toBe('positional prompt'); // Since no explicit prompt flags are set and query doesn't start with @, should map to prompt (one-shot) expect(argv.prompt).toBe('positional prompt'); @@ -2175,13 +2328,13 @@ describe('parseArguments with positional prompt', () => { // This test verifies that the positional 'query' argument is properly configured // with the description: "Positional prompt. Defaults to one-shot; use -i/--prompt-interactive for interactive." process.argv = ['node', 'script.js', 'test', 'query']; - const argv = await yargsInstance.parseArguments({} as Settings); + const argv = await yargsInstance.parseArguments(createTestMergedSettings()); expect(argv.query).toBe('test query'); }); it('should correctly parse a prompt from the --prompt flag', async () => { process.argv = ['node', 'script.js', '--prompt', 'test prompt']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); expect(argv.prompt).toBe('test prompt'); }); }); @@ -2197,8 +2350,10 @@ describe('Telemetry configuration via environment variables', () => { it('should prioritize GEMINI_TELEMETRY_ENABLED over settings', async () => { vi.stubEnv('GEMINI_TELEMETRY_ENABLED', 'true'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { telemetry: { enabled: false } }; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ + telemetry: { enabled: false }, + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getTelemetryEnabled()).toBe(true); }); @@ -2206,10 +2361,10 @@ describe('Telemetry configuration via environment variables', () => { it('should prioritize GEMINI_TELEMETRY_TARGET over settings', async () => { vi.stubEnv('GEMINI_TELEMETRY_TARGET', 'gcp'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ telemetry: { target: ServerConfig.TelemetryTarget.LOCAL }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getTelemetryTarget()).toBe('gcp'); }); @@ -2217,10 +2372,10 @@ describe('Telemetry configuration via environment variables', () => { it('should throw when GEMINI_TELEMETRY_TARGET is invalid', async () => { vi.stubEnv('GEMINI_TELEMETRY_TARGET', 'bogus'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ telemetry: { target: ServerConfig.TelemetryTarget.GCP }, - }; + }); await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow( /Invalid telemetry configuration: .*Invalid telemetry target/i, ); @@ -2231,10 +2386,10 @@ describe('Telemetry configuration via environment variables', () => { vi.stubEnv('OTEL_EXPORTER_OTLP_ENDPOINT', 'http://default.env.com'); vi.stubEnv('GEMINI_TELEMETRY_OTLP_ENDPOINT', 'http://gemini.env.com'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ telemetry: { otlpEndpoint: 'http://settings.com' }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getTelemetryOtlpEndpoint()).toBe('http://gemini.env.com'); }); @@ -2242,8 +2397,10 @@ describe('Telemetry configuration via environment variables', () => { it('should prioritize GEMINI_TELEMETRY_OTLP_PROTOCOL over settings', async () => { vi.stubEnv('GEMINI_TELEMETRY_OTLP_PROTOCOL', 'http'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { telemetry: { otlpProtocol: 'grpc' } }; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ + telemetry: { otlpProtocol: 'grpc' }, + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getTelemetryOtlpProtocol()).toBe('http'); }); @@ -2251,8 +2408,10 @@ describe('Telemetry configuration via environment variables', () => { it('should prioritize GEMINI_TELEMETRY_LOG_PROMPTS over settings', async () => { vi.stubEnv('GEMINI_TELEMETRY_LOG_PROMPTS', 'false'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { telemetry: { logPrompts: true } }; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ + telemetry: { logPrompts: true }, + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getTelemetryLogPromptsEnabled()).toBe(false); }); @@ -2260,10 +2419,10 @@ describe('Telemetry configuration via environment variables', () => { it('should prioritize GEMINI_TELEMETRY_OUTFILE over settings', async () => { vi.stubEnv('GEMINI_TELEMETRY_OUTFILE', '/gemini/env/telemetry.log'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ telemetry: { outfile: '/settings/telemetry.log' }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getTelemetryOutfile()).toBe('/gemini/env/telemetry.log'); }); @@ -2271,8 +2430,10 @@ describe('Telemetry configuration via environment variables', () => { it('should prioritize GEMINI_TELEMETRY_USE_COLLECTOR over settings', async () => { vi.stubEnv('GEMINI_TELEMETRY_USE_COLLECTOR', 'true'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { telemetry: { useCollector: false } }; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ + telemetry: { useCollector: false }, + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getTelemetryUseCollector()).toBe(true); }); @@ -2280,8 +2441,8 @@ describe('Telemetry configuration via environment variables', () => { it('should use settings value when GEMINI_TELEMETRY_ENABLED is not set', async () => { vi.stubEnv('GEMINI_TELEMETRY_ENABLED', undefined); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { telemetry: { enabled: true } }; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ telemetry: { enabled: true } }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getTelemetryEnabled()).toBe(true); }); @@ -2289,10 +2450,10 @@ describe('Telemetry configuration via environment variables', () => { it('should use settings value when GEMINI_TELEMETRY_TARGET is not set', async () => { vi.stubEnv('GEMINI_TELEMETRY_TARGET', undefined); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ telemetry: { target: ServerConfig.TelemetryTarget.LOCAL }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getTelemetryTarget()).toBe('local'); }); @@ -2300,17 +2461,21 @@ describe('Telemetry configuration via environment variables', () => { it("should treat GEMINI_TELEMETRY_ENABLED='1' as true", async () => { vi.stubEnv('GEMINI_TELEMETRY_ENABLED', '1'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getTelemetryEnabled()).toBe(true); }); it("should treat GEMINI_TELEMETRY_ENABLED='0' as false", async () => { vi.stubEnv('GEMINI_TELEMETRY_ENABLED', '0'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig( - { telemetry: { enabled: true } }, + createTestMergedSettings({ telemetry: { enabled: true } }), 'test-session', argv, ); @@ -2320,17 +2485,21 @@ describe('Telemetry configuration via environment variables', () => { it("should treat GEMINI_TELEMETRY_LOG_PROMPTS='1' as true", async () => { vi.stubEnv('GEMINI_TELEMETRY_LOG_PROMPTS', '1'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.getTelemetryLogPromptsEnabled()).toBe(true); }); it("should treat GEMINI_TELEMETRY_LOG_PROMPTS='false' as false", async () => { vi.stubEnv('GEMINI_TELEMETRY_LOG_PROMPTS', 'false'); process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); + const argv = await parseArguments(createTestMergedSettings()); const config = await loadCliConfig( - { telemetry: { logPrompts: true } }, + createTestMergedSettings({ telemetry: { logPrompts: true } }), 'test-session', argv, ); @@ -2355,8 +2524,12 @@ describe('PolicyEngine nonInteractive wiring', () => { it('should set nonInteractive to true in one-shot mode', async () => { process.stdin.isTTY = true; process.argv = ['node', 'script.js', 'echo hello']; // Positional query makes it one-shot - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(false); expect( (config.getPolicyEngine() as unknown as { nonInteractive: boolean }) @@ -2367,8 +2540,12 @@ describe('PolicyEngine nonInteractive wiring', () => { it('should set nonInteractive to false in interactive mode', async () => { process.stdin.isTTY = true; process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const config = await loadCliConfig({}, 'test-session', argv); + const argv = await parseArguments(createTestMergedSettings()); + const config = await loadCliConfig( + createTestMergedSettings(), + 'test-session', + argv, + ); expect(config.isInteractive()).toBe(true); expect( (config.getPolicyEngine() as unknown as { nonInteractive: boolean }) @@ -2392,8 +2569,10 @@ describe('Policy Engine Integration in loadCliConfig', () => { it('should pass merged allowed tools from CLI and settings to createPolicyEngineConfig', async () => { process.argv = ['node', 'script.js', '--allowed-tools', 'cli-tool']; - const settings: Settings = { tools: { allowed: ['settings-tool'] } }; - const argv = await parseArguments({} as Settings); + const settings = createTestMergedSettings({ + tools: { allowed: ['settings-tool'] }, + }); + const argv = await parseArguments(createTestMergedSettings()); await loadCliConfig(settings, 'test-session', argv); @@ -2410,8 +2589,10 @@ describe('Policy Engine Integration in loadCliConfig', () => { it('should pass merged exclude tools from CLI logic and settings to createPolicyEngineConfig', async () => { process.stdin.isTTY = false; // Non-interactive to trigger default excludes process.argv = ['node', 'script.js', '-p', 'test']; - const settings: Settings = { tools: { exclude: ['settings-exclude'] } }; - const argv = await parseArguments({} as Settings); + const settings = createTestMergedSettings({ + tools: { exclude: ['settings-exclude'] }, + }); + const argv = await parseArguments(createTestMergedSettings()); await loadCliConfig(settings, 'test-session', argv); @@ -2446,20 +2627,20 @@ describe('loadCliConfig disableYoloMode', () => { it('should allow auto_edit mode even if yolo mode is disabled', async () => { process.argv = ['node', 'script.js', '--approval-mode=auto_edit']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ security: { disableYoloMode: true }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getApprovalMode()).toBe(ApprovalMode.AUTO_EDIT); }); it('should throw if YOLO mode is attempted when disableYoloMode is true', async () => { process.argv = ['node', 'script.js', '--yolo']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ security: { disableYoloMode: true }, - }; + }); await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow( 'Cannot start in YOLO mode since it is disabled by your admin', ); @@ -2485,12 +2666,12 @@ describe('loadCliConfig secureModeEnabled', () => { it('should throw an error if YOLO mode is attempted when secureModeEnabled is true', async () => { process.argv = ['node', 'script.js', '--yolo']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ admin: { secureModeEnabled: true, }, - }; + }); await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow( 'Cannot start in YOLO mode since it is disabled by your admin', @@ -2499,12 +2680,12 @@ describe('loadCliConfig secureModeEnabled', () => { it('should throw an error if approval-mode=yolo is attempted when secureModeEnabled is true', async () => { process.argv = ['node', 'script.js', '--approval-mode=yolo']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ admin: { secureModeEnabled: true, }, - }; + }); await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow( 'Cannot start in YOLO mode since it is disabled by your admin', @@ -2513,12 +2694,12 @@ describe('loadCliConfig secureModeEnabled', () => { it('should set disableYoloMode to true when secureModeEnabled is true', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ admin: { secureModeEnabled: true, }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.isYoloModeDisabled()).toBe(true); }); @@ -2548,8 +2729,8 @@ describe('loadCliConfig mcpEnabled', () => { it('should enable MCP by default', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { ...mcpSettings }; + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ ...mcpSettings }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getMcpEnabled()).toBe(true); expect(config.getMcpServerCommand()).toBe('mcp-server'); @@ -2560,15 +2741,15 @@ describe('loadCliConfig mcpEnabled', () => { it('should disable MCP when mcpEnabled is false', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ ...mcpSettings, admin: { mcp: { enabled: false, }, }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getMcpEnabled()).toBe(false); expect(config.getMcpServerCommand()).toBeUndefined(); @@ -2579,15 +2760,15 @@ describe('loadCliConfig mcpEnabled', () => { it('should enable MCP when mcpEnabled is true', async () => { process.argv = ['node', 'script.js']; - const argv = await parseArguments({} as Settings); - const settings: Settings = { + const argv = await parseArguments(createTestMergedSettings()); + const settings = createTestMergedSettings({ ...mcpSettings, admin: { mcp: { enabled: true, }, }, - }; + }); const config = await loadCliConfig(settings, 'test-session', argv); expect(config.getMcpEnabled()).toBe(true); expect(config.getMcpServerCommand()).toBe('mcp-server'); diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 341226fed2..7dfa125bcb 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -38,8 +38,12 @@ import { type OutputFormat, GEMINI_MODEL_ALIAS_AUTO, } from '@google/gemini-cli-core'; -import type { Settings } from './settings.js'; -import { saveModelChange, loadSettings } from './settings.js'; +import { + type Settings, + type MergedSettings, + saveModelChange, + loadSettings, +} from './settings.js'; import { loadSandboxConfig } from './sandboxConfig.js'; import { resolvePath } from '../utils/resolvePath.js'; @@ -54,7 +58,6 @@ import { requestConsentNonInteractive } from './extensions/consent.js'; import { promptForSetting } from './extensions/extensionSettings.js'; import type { EventEmitter } from 'node:stream'; import { runExitCleanup } from '../utils/cleanup.js'; -import { getEnableHooks, getEnableHooksUI } from './settingsSchema.js'; export interface CliArgs { query: string | undefined; @@ -82,7 +85,9 @@ export interface CliArgs { recordResponses: string | undefined; } -export async function parseArguments(settings: Settings): Promise { +export async function parseArguments( + settings: MergedSettings, +): Promise { const rawArgv = hideBin(process.argv); const yargsInstance = yargs(rawArgv) .locale('en') @@ -280,16 +285,16 @@ export async function parseArguments(settings: Settings): Promise { return true; }); - if (settings?.experimental?.extensionManagement ?? true) { + if (settings.experimental.extensionManagement) { yargsInstance.command(extensionsCommand); } - if (settings?.experimental?.skills ?? false) { + if (settings.experimental.skills) { yargsInstance.command(skillsCommand); } // Register hooks command if hooks are enabled - if (getEnableHooksUI(settings)) { + if (settings.tools.enableHooks) { yargsInstance.command(hooksCommand); } @@ -392,7 +397,7 @@ export interface LoadCliConfigOptions { } export async function loadCliConfig( - settings: Settings, + settings: MergedSettings, sessionId: string, argv: CliArgs, options: LoadCliConfigOptions = {}, @@ -590,10 +595,7 @@ export async function loadCliConfig( } } - const excludeTools = mergeExcludeTools( - settings, - extraExcludes.length > 0 ? extraExcludes : undefined, - ); + const excludeTools = mergeExcludeTools(settings, extraExcludes); // Create a settings object that includes CLI overrides for policy generation const effectiveSettings: Settings = { @@ -742,15 +744,17 @@ export async function loadCliConfig( disableLLMCorrection: settings.tools?.disableLLMCorrection, modelConfigServiceConfig: settings.modelConfigs, // TODO: loading of hooks based on workspace trust - enableHooks: getEnableHooks(settings), - enableHooksUI: getEnableHooksUI(settings), + enableHooks: + (settings.tools?.enableHooks ?? true) && + (settings.hooks?.enabled ?? false), + enableHooksUI: settings.tools?.enableHooks ?? true, hooks: settings.hooks || {}, projectHooks: projectHooks || {}, onModelChange: (model: string) => saveModelChange(loadedSettings, model), onReload: async () => { const refreshedSettings = loadSettings(cwd); return { - disabledSkills: refreshedSettings.merged.skills?.disabled, + disabledSkills: refreshedSettings.merged.skills.disabled, agents: refreshedSettings.merged.agents, }; }, @@ -758,12 +762,12 @@ export async function loadCliConfig( } function mergeExcludeTools( - settings: Settings, - extraExcludes?: string[] | undefined, + settings: MergedSettings, + extraExcludes: string[] = [], ): string[] { const allExcludeTools = new Set([ - ...(settings.tools?.exclude || []), - ...(extraExcludes || []), + ...(settings.tools.exclude || []), + ...extraExcludes, ]); - return [...allExcludeTools]; + return Array.from(allExcludeTools); } diff --git a/packages/cli/src/config/extension-manager-agents.test.ts b/packages/cli/src/config/extension-manager-agents.test.ts index 7ae845875f..19ef150d22 100644 --- a/packages/cli/src/config/extension-manager-agents.test.ts +++ b/packages/cli/src/config/extension-manager-agents.test.ts @@ -10,7 +10,7 @@ import * as path from 'node:path'; import * as os from 'node:os'; import { ExtensionManager } from './extension-manager.js'; import { debugLogger } from '@google/gemini-cli-core'; -import { type Settings } from './settings.js'; +import { createTestMergedSettings } from './settings.js'; import { createExtension } from '../test-utils/createExtension.js'; import { EXTENSIONS_DIRECTORY_NAME } from './extensions/variables.js'; @@ -52,10 +52,9 @@ describe('ExtensionManager agents loading', () => { fs.mkdirSync(extensionsDir, { recursive: true }); extensionManager = new ExtensionManager({ - settings: { + settings: createTestMergedSettings({ telemetry: { enabled: false }, - trustedFolders: [tempDir], - } as unknown as Settings, + }), requestConsent: vi.fn().mockResolvedValue(true), requestSetting: vi.fn(), workspaceDir: tempDir, diff --git a/packages/cli/src/config/extension-manager-scope.test.ts b/packages/cli/src/config/extension-manager-scope.test.ts index 6d3e51b4d8..5079075366 100644 --- a/packages/cli/src/config/extension-manager-scope.test.ts +++ b/packages/cli/src/config/extension-manager-scope.test.ts @@ -9,7 +9,7 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; import * as os from 'node:os'; import { ExtensionManager } from './extension-manager.js'; -import type { Settings } from './settings.js'; +import { createTestMergedSettings } from './settings.js'; import { loadAgentsFromDirectory, loadSkillsFromDir, @@ -105,14 +105,10 @@ describe('ExtensionManager Settings Scope', () => { workspaceDir: tempWorkspace, requestConsent: async () => true, requestSetting: async () => '', - settings: { - telemetry: { - enabled: false, - }, - experimental: { - extensionConfig: true, - }, - } as Settings, + settings: createTestMergedSettings({ + telemetry: { enabled: false }, + experimental: { extensionConfig: true }, + }), }); const extensions = await extensionManager.loadExtensions(); @@ -147,14 +143,10 @@ describe('ExtensionManager Settings Scope', () => { workspaceDir: tempWorkspace, requestConsent: async () => true, requestSetting: async () => '', - settings: { - telemetry: { - enabled: false, - }, - experimental: { - extensionConfig: true, - }, - } as Settings, + settings: createTestMergedSettings({ + telemetry: { enabled: false }, + experimental: { extensionConfig: true }, + }), }); const extensions = await extensionManager.loadExtensions(); @@ -187,14 +179,10 @@ describe('ExtensionManager Settings Scope', () => { workspaceDir: tempWorkspace, requestConsent: async () => true, requestSetting: async () => '', - settings: { - telemetry: { - enabled: false, - }, - experimental: { - extensionConfig: true, - }, - } as Settings, + settings: createTestMergedSettings({ + telemetry: { enabled: false }, + experimental: { extensionConfig: true }, + }), }); const extensions = await extensionManager.loadExtensions(); diff --git a/packages/cli/src/config/extension-manager-skills.test.ts b/packages/cli/src/config/extension-manager-skills.test.ts index ecc0dfa3c0..a76d88482d 100644 --- a/packages/cli/src/config/extension-manager-skills.test.ts +++ b/packages/cli/src/config/extension-manager-skills.test.ts @@ -10,7 +10,7 @@ import * as path from 'node:path'; import * as os from 'node:os'; import { ExtensionManager } from './extension-manager.js'; import { debugLogger, coreEvents } from '@google/gemini-cli-core'; -import { type Settings } from './settings.js'; +import { createTestMergedSettings } from './settings.js'; import { createExtension } from '../test-utils/createExtension.js'; import { EXTENSIONS_DIRECTORY_NAME } from './extensions/variables.js'; @@ -58,10 +58,9 @@ describe('ExtensionManager skills validation', () => { fs.mkdirSync(extensionsDir, { recursive: true }); extensionManager = new ExtensionManager({ - settings: { + settings: createTestMergedSettings({ telemetry: { enabled: false }, - trustedFolders: [tempDir], - } as unknown as Settings, + }), requestConsent: vi.fn().mockResolvedValue(true), requestSetting: vi.fn(), workspaceDir: tempDir, @@ -134,10 +133,9 @@ describe('ExtensionManager skills validation', () => { // 3. Create a fresh ExtensionManager to force loading from disk const newExtensionManager = new ExtensionManager({ - settings: { + settings: createTestMergedSettings({ telemetry: { enabled: false }, - trustedFolders: [tempDir], - } as unknown as Settings, + }), requestConsent: vi.fn().mockResolvedValue(true), requestSetting: vi.fn(), workspaceDir: tempDir, diff --git a/packages/cli/src/config/extension-manager.ts b/packages/cli/src/config/extension-manager.ts index 75416f1909..45ca5a0d8a 100644 --- a/packages/cli/src/config/extension-manager.ts +++ b/packages/cli/src/config/extension-manager.ts @@ -9,7 +9,7 @@ import * as path from 'node:path'; import { stat } from 'node:fs/promises'; import chalk from 'chalk'; import { ExtensionEnablementManager } from './extensions/extensionEnablement.js'; -import { type Settings, SettingScope } from './settings.js'; +import { type MergedSettings, SettingScope } from './settings.js'; import { createHash, randomUUID } from 'node:crypto'; import { loadInstallMetadata, type ExtensionConfig } from './extension.js'; import { @@ -68,11 +68,10 @@ import { ExtensionSettingScope, } from './extensions/extensionSettings.js'; import type { EventEmitter } from 'node:stream'; -import { getEnableHooks } from './settingsSchema.js'; interface ExtensionManagerParams { enabledExtensionOverrides?: string[]; - settings: Settings; + settings: MergedSettings; requestConsent: (consent: string) => Promise; requestSetting: ((setting: ExtensionSetting) => Promise) | null; workspaceDir: string; @@ -86,7 +85,7 @@ interface ExtensionManagerParams { */ export class ExtensionManager extends ExtensionLoader { private extensionEnablementManager: ExtensionEnablementManager; - private settings: Settings; + private settings: MergedSettings; private requestConsent: (consent: string) => Promise; private requestSetting: | ((setting: ExtensionSetting) => Promise) @@ -143,7 +142,7 @@ export class ExtensionManager extends ExtensionLoader { if ( (installMetadata.type === 'git' || installMetadata.type === 'github-release') && - this.settings.security?.blockGitExtensions + this.settings.security.blockGitExtensions ) { throw new Error( 'Installing extensions from remote sources is disallowed by your current settings.', @@ -287,10 +286,7 @@ Would you like to attempt to install via "git clone" instead?`, } await fs.promises.mkdir(destinationPath, { recursive: true }); - if ( - this.requestSetting && - (this.settings.experimental?.extensionConfig ?? false) - ) { + if (this.requestSetting && this.settings.experimental.extensionConfig) { if (isUpdate) { await maybePromptForSettings( newExtensionConfig, @@ -308,14 +304,13 @@ Would you like to attempt to install via "git clone" instead?`, } } - const missingSettings = - (this.settings.experimental?.extensionConfig ?? false) - ? await getMissingSettings( - newExtensionConfig, - extensionId, - this.workspaceDir, - ) - : []; + const missingSettings = this.settings.experimental.extensionConfig + ? await getMissingSettings( + newExtensionConfig, + extensionId, + this.workspaceDir, + ) + : []; if (missingSettings.length > 0) { const message = `Extension "${newExtensionConfig.name}" has missing settings: ${missingSettings .map((s) => s.name) @@ -478,7 +473,7 @@ Would you like to attempt to install via "git clone" instead?`, throw new Error('Extensions already loaded, only load extensions once.'); } - if (this.settings.admin?.extensions?.enabled === false) { + if (this.settings.admin.extensions.enabled === false) { this.loadedExtensions = []; return this.loadedExtensions; } @@ -511,7 +506,7 @@ Would you like to attempt to install via "git clone" instead?`, if ( (installMetadata?.type === 'git' || installMetadata?.type === 'github-release') && - this.settings.security?.blockGitExtensions + this.settings.security.blockGitExtensions ) { return null; } @@ -535,7 +530,7 @@ Would you like to attempt to install via "git clone" instead?`, let userSettings: Record = {}; let workspaceSettings: Record = {}; - if (this.settings.experimental?.extensionConfig ?? false) { + if (this.settings.experimental.extensionConfig) { userSettings = await getScopedEnvContents( config, extensionId, @@ -553,10 +548,7 @@ Would you like to attempt to install via "git clone" instead?`, config = resolveEnvVarsInObject(config, customEnv); const resolvedSettings: ResolvedExtensionSetting[] = []; - if ( - config.settings && - (this.settings.experimental?.extensionConfig ?? false) - ) { + if (config.settings && this.settings.experimental.extensionConfig) { for (const setting of config.settings) { const value = customEnv[setting.envVar]; let scope: 'user' | 'workspace' | undefined; @@ -600,7 +592,7 @@ Would you like to attempt to install via "git clone" instead?`, } if (config.mcpServers) { - if (this.settings.admin?.mcp?.enabled === false) { + if (this.settings.admin.mcp.enabled === false) { config.mcpServers = undefined; } else { config.mcpServers = Object.fromEntries( @@ -619,7 +611,7 @@ Would you like to attempt to install via "git clone" instead?`, .filter((contextFilePath) => fs.existsSync(contextFilePath)); let hooks: { [K in HookEventName]?: HookDefinition[] } | undefined; - if (getEnableHooks(this.settings)) { + if (this.settings.tools.enableHooks && this.settings.hooks.enabled) { hooks = await this.loadExtensionHooks(effectiveExtensionPath, { extensionPath: effectiveExtensionPath, workspacePath: this.workspaceDir, diff --git a/packages/cli/src/config/extension.test.ts b/packages/cli/src/config/extension.test.ts index a3230058f7..55f44a6c20 100644 --- a/packages/cli/src/config/extension.test.ts +++ b/packages/cli/src/config/extension.test.ts @@ -26,7 +26,11 @@ import { loadAgentsFromDirectory, loadSkillsFromDir, } from '@google/gemini-cli-core'; -import { loadSettings, SettingScope } from './settings.js'; +import { + loadSettings, + createTestMergedSettings, + SettingScope, +} from './settings.js'; import { isWorkspaceTrusted, resetTrustedFoldersForTesting, @@ -201,7 +205,7 @@ describe('extension tests', () => { }); vi.spyOn(process, 'cwd').mockReturnValue(tempWorkspaceDir); const settings = loadSettings(tempWorkspaceDir).merged; - (settings.experimental ??= {}).extensionConfig = true; + settings.experimental.extensionConfig = true; extensionManager = new ExtensionManager({ workspaceDir: tempWorkspaceDir, requestConsent: mockRequestConsent, @@ -628,11 +632,9 @@ describe('extension tests', () => { }, }); - const blockGitExtensionsSetting = { - security: { - blockGitExtensions: true, - }, - }; + const blockGitExtensionsSetting = createTestMergedSettings({ + security: { blockGitExtensions: true }, + }); extensionManager = new ExtensionManager({ workspaceDir: tempWorkspaceDir, requestConsent: mockRequestConsent, @@ -652,7 +654,6 @@ describe('extension tests', () => { version: '1.0.0', }); const loadedSettings = loadSettings(tempWorkspaceDir).merged; - (loadedSettings.admin ??= {}).extensions ??= {}; loadedSettings.admin.extensions.enabled = false; extensionManager = new ExtensionManager({ @@ -676,7 +677,6 @@ describe('extension tests', () => { }, }); const loadedSettings = loadSettings(tempWorkspaceDir).merged; - (loadedSettings.admin ??= {}).mcp ??= {}; loadedSettings.admin.mcp.enabled = false; extensionManager = new ExtensionManager({ @@ -701,7 +701,6 @@ describe('extension tests', () => { }, }); const loadedSettings = loadSettings(tempWorkspaceDir).merged; - (loadedSettings.admin ??= {}).mcp ??= {}; loadedSettings.admin.mcp.enabled = true; extensionManager = new ExtensionManager({ @@ -837,7 +836,6 @@ describe('extension tests', () => { ); const settings = loadSettings(tempWorkspaceDir).merged; - if (!settings.hooks) settings.hooks = {}; settings.hooks.enabled = true; extensionManager = new ExtensionManager({ @@ -873,7 +871,6 @@ describe('extension tests', () => { ); const settings = loadSettings(tempWorkspaceDir).merged; - if (!settings.hooks) settings.hooks = {}; settings.hooks.enabled = false; extensionManager = new ExtensionManager({ @@ -1098,11 +1095,9 @@ describe('extension tests', () => { it('should not install a github extension if blockGitExtensions is set', async () => { const gitUrl = 'https://somehost.com/somerepo.git'; - const blockGitExtensionsSetting = { - security: { - blockGitExtensions: true, - }, - }; + const blockGitExtensionsSetting = createTestMergedSettings({ + security: { blockGitExtensions: true }, + }); extensionManager = new ExtensionManager({ workspaceDir: tempWorkspaceDir, requestConsent: mockRequestConsent, diff --git a/packages/cli/src/config/extensions/extensionUpdates.test.ts b/packages/cli/src/config/extensions/extensionUpdates.test.ts index a9240a1676..43b19d1228 100644 --- a/packages/cli/src/config/extensions/extensionUpdates.test.ts +++ b/packages/cli/src/config/extensions/extensionUpdates.test.ts @@ -11,7 +11,6 @@ import * as fs from 'node:fs'; import { getMissingSettings } from './extensionSettings.js'; import type { ExtensionConfig } from '../extension.js'; import { ExtensionStorage } from './storage.js'; -import type { Settings } from '../settings.js'; import { KeychainTokenStorage, debugLogger, @@ -21,6 +20,7 @@ import { } from '@google/gemini-cli-core'; import { EXTENSION_SETTINGS_FILENAME } from './variables.js'; import { ExtensionManager } from '../extension-manager.js'; +import { createTestMergedSettings } from '../settings.js'; vi.mock('node:fs', async (importOriginal) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -247,12 +247,10 @@ describe('extensionUpdates', () => { const manager = new ExtensionManager({ workspaceDir: tempWorkspaceDir, - settings: { - telemetry: { - enabled: false, - }, + settings: createTestMergedSettings({ + telemetry: { enabled: false }, experimental: { extensionConfig: true }, - } as unknown as Settings, + }), requestConsent: vi.fn().mockResolvedValue(true), requestSetting: null, // Simulate non-interactive }); diff --git a/packages/cli/src/config/settings.ts b/packages/cli/src/config/settings.ts index 07cd457785..a7bbd76ca6 100644 --- a/packages/cli/src/config/settings.ts +++ b/packages/cli/src/config/settings.ts @@ -24,12 +24,24 @@ import { DefaultDark } from '../ui/themes/default.js'; import { isWorkspaceTrusted } from './trustedFolders.js'; import { type Settings, + type MergedSettings, type MemoryImportFormat, type MergeStrategy, type SettingsSchema, type SettingDefinition, getSettingsSchema, } from './settingsSchema.js'; + +export { + type Settings, + type MergedSettings, + type MemoryImportFormat, + type MergeStrategy, + type SettingsSchema, + type SettingDefinition, + getSettingsSchema, +}; + import { resolveEnvVarsInObject } from '../utils/envVarResolver.js'; import { customDeepMerge } from '../utils/deepMerge.js'; import { updateSettingsFilePreservingFormat } from '../utils/commentJson.js'; @@ -59,8 +71,6 @@ function getMergeStrategyForPath(path: string[]): MergeStrategy | undefined { return current?.mergeStrategy; } -export type { Settings, MemoryImportFormat }; - export const USER_SETTINGS_PATH = Storage.getGlobalSettingsPath(); export const USER_SETTINGS_DIR = path.dirname(USER_SETTINGS_PATH); export const DEFAULT_EXCLUDED_ENV_VARS = ['DEBUG', 'DEBUG_MODE']; @@ -201,10 +211,7 @@ export function getDefaultsFromSchema( for (const key in schema) { const definition = schema[key]; if (definition.properties) { - const childDefaults = getDefaultsFromSchema(definition.properties); - if (Object.keys(childDefaults).length > 0) { - defaults[key] = childDefaults; - } + defaults[key] = getDefaultsFromSchema(definition.properties); } else if (definition.default !== undefined) { defaults[key] = definition.default; } @@ -212,13 +219,13 @@ export function getDefaultsFromSchema( return defaults as Settings; } -function mergeSettings( +export function mergeSettings( system: Settings, systemDefaults: Settings, user: Settings, workspace: Settings, isTrusted: boolean, -): Settings { +): MergedSettings { const safeWorkspace = isTrusted ? workspace : ({} as Settings); const schemaDefaults = getDefaultsFromSchema(); @@ -236,7 +243,24 @@ function mergeSettings( user, safeWorkspace, system, - ) as Settings; + ) as MergedSettings; +} + +/** + * Creates a fully populated MergedSettings object for testing purposes. + * It merges the provided overrides with the default settings from the schema. + * + * @param overrides Partial settings to override the defaults. + * @returns A complete MergedSettings object. + */ +export function createTestMergedSettings( + overrides: Partial = {}, +): MergedSettings { + return customDeepMerge( + getMergeStrategyForPath, + getDefaultsFromSchema(), + overrides, + ) as MergedSettings; } export class LoadedSettings { @@ -264,14 +288,14 @@ export class LoadedSettings { readonly isTrusted: boolean; readonly errors: SettingsError[]; - private _merged: Settings; + private _merged: MergedSettings; private _remoteAdminSettings: Partial | undefined; - get merged(): Settings { + get merged(): MergedSettings { return this._merged; } - private computeMergedSettings(): Settings { + private computeMergedSettings(): MergedSettings { const merged = mergeSettings( this.system.settings, this.systemDefaults.settings, @@ -293,7 +317,7 @@ export class LoadedSettings { (path: string[]) => getMergeStrategyForPath(['admin', ...path]), adminDefaults, this._remoteAdminSettings?.admin ?? {}, - ) as Settings['admin']; + ) as MergedSettings['admin']; } return merged; } diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index b7d4cbb296..0af37b7c1f 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -14,6 +14,7 @@ import type { BugCommandSettings, TelemetrySettings, AuthType, + AgentOverride, } from '@google/gemini-cli-core'; import { DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES, @@ -799,7 +800,7 @@ const SETTINGS_SCHEMA = { label: 'Agent Overrides', category: 'Advanced', requiresRestart: true, - default: {}, + default: {} as Record, description: 'Override settings for specific agents, e.g. to disable the agent, set a custom model config, or run config.', showInDialog: false, @@ -2262,12 +2263,17 @@ type InferSettings = { : T[K]['default']; }; +type InferMergedSettings = { + -readonly [K in keyof T]-?: T[K] extends { properties: SettingsSchema } + ? InferMergedSettings + : T[K]['type'] extends 'enum' + ? T[K]['options'] extends readonly SettingEnumOption[] + ? T[K]['options'][number]['value'] + : T[K]['default'] + : T[K]['default'] extends boolean + ? boolean + : T[K]['default']; +}; + export type Settings = InferSettings; - -export function getEnableHooksUI(settings: Settings): boolean { - return settings.tools?.enableHooks ?? true; -} - -export function getEnableHooks(settings: Settings): boolean { - return getEnableHooksUI(settings) && (settings.hooks?.enabled ?? false); -} +export type MergedSettings = InferMergedSettings; diff --git a/packages/cli/src/core/initializer.test.ts b/packages/cli/src/core/initializer.test.ts index 61a4b00422..57f1c41551 100644 --- a/packages/cli/src/core/initializer.test.ts +++ b/packages/cli/src/core/initializer.test.ts @@ -127,7 +127,7 @@ describe('initializer', () => { }); it('should handle undefined auth type', async () => { - mockSettings.merged.security!.auth!.selectedType = undefined; + mockSettings.merged.security.auth.selectedType = undefined; const result = await initializeApp( mockConfig as unknown as Config, mockSettings, diff --git a/packages/cli/src/core/initializer.ts b/packages/cli/src/core/initializer.ts index 0ba76a989f..e99efd90f6 100644 --- a/packages/cli/src/core/initializer.ts +++ b/packages/cli/src/core/initializer.ts @@ -39,13 +39,13 @@ export async function initializeApp( const authHandle = startupProfiler.start('authenticate'); const authError = await performInitialAuth( config, - settings.merged.security?.auth?.selectedType, + settings.merged.security.auth.selectedType, ); authHandle?.end(); const themeError = validateTheme(settings); const shouldOpenAuthDialog = - settings.merged.security?.auth?.selectedType === undefined || !!authError; + settings.merged.security.auth.selectedType === undefined || !!authError; logCliConfiguration( config, diff --git a/packages/cli/src/core/theme.test.ts b/packages/cli/src/core/theme.test.ts index fb57d2cde3..eb87a9ee10 100644 --- a/packages/cli/src/core/theme.test.ts +++ b/packages/cli/src/core/theme.test.ts @@ -46,7 +46,7 @@ describe('theme', () => { }); it('should return null if theme is undefined', () => { - mockSettings.merged.ui!.theme = undefined; + mockSettings.merged.ui.theme = undefined; const result = validateTheme(mockSettings); expect(result).toBeNull(); expect(themeManager.findThemeByName).not.toHaveBeenCalled(); diff --git a/packages/cli/src/core/theme.ts b/packages/cli/src/core/theme.ts index ed2805a5ab..f0f58fdbba 100644 --- a/packages/cli/src/core/theme.ts +++ b/packages/cli/src/core/theme.ts @@ -13,7 +13,7 @@ import { type LoadedSettings } from '../config/settings.js'; * @returns An error message if the theme is not found, otherwise null. */ export function validateTheme(settings: LoadedSettings): string | null { - const effectiveTheme = settings.merged.ui?.theme; + const effectiveTheme = settings.merged.ui.theme; if (effectiveTheme && !themeManager.findThemeByName(effectiveTheme)) { return `Theme "${effectiveTheme}" not found.`; } diff --git a/packages/cli/src/gemini.test.tsx b/packages/cli/src/gemini.test.tsx index 9619035b0d..896f89e3c8 100644 --- a/packages/cli/src/gemini.test.tsx +++ b/packages/cli/src/gemini.test.tsx @@ -23,8 +23,30 @@ import { import os from 'node:os'; import v8 from 'node:v8'; import { type CliArgs } from './config/config.js'; -import { type LoadedSettings } from './config/settings.js'; +import { + type LoadedSettings, + type Settings, + createTestMergedSettings, +} from './config/settings.js'; import { appEvents, AppEvent } from './utils/events.js'; + +function createMockSettings( + overrides: Record = {}, +): LoadedSettings { + const merged = createTestMergedSettings( + (overrides['merged'] as Partial) || {}, + ); + + return { + system: { settings: {} }, + systemDefaults: { settings: {} }, + user: { settings: {} }, + workspace: { settings: {} }, + errors: [], + ...overrides, + merged, + } as unknown as LoadedSettings; +} import { type Config, type ResumedSessionData, @@ -108,26 +130,19 @@ class MockProcessExitError extends Error { } // Mock dependencies -vi.mock('./config/settings.js', () => ({ - loadSettings: vi.fn().mockReturnValue({ - merged: { - advanced: {}, - security: { auth: {} }, - ui: {}, - }, - workspace: { settings: {} }, - setValue: vi.fn(), - forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), - errors: [], - }), - migrateDeprecatedSettings: vi.fn(), - SettingScope: { - User: 'user', - Workspace: 'workspace', - System: 'system', - SystemDefaults: 'system-defaults', - }, -})); +vi.mock('./config/settings.js', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + loadSettings: vi.fn().mockImplementation(() => ({ + merged: actual.getDefaultsFromSchema(), + workspace: { settings: {} }, + errors: [], + })), + saveModelChange: vi.fn(), + getDefaultsFromSchema: actual.getDefaultsFromSchema, + }; +}); vi.mock('./ui/utils/terminalCapabilityManager.js', () => ({ terminalCapabilityManager: { @@ -443,17 +458,15 @@ describe('gemini.tsx main function kitty protocol', () => { getProjectTempDir: vi.fn().mockReturnValue('/tmp/gemini-test'), }, } as unknown as Config); - vi.mocked(loadSettings).mockReturnValue({ - errors: [], - merged: { - advanced: {}, - security: { auth: {} }, - ui: {}, - }, - workspace: { settings: {} }, - setValue: vi.fn(), - forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), - } as never); + vi.mocked(loadSettings).mockReturnValue( + createMockSettings({ + merged: { + advanced: {}, + security: { auth: {} }, + ui: {}, + }, + }), + ); vi.mocked(parseArguments).mockResolvedValue({ model: undefined, sandbox: undefined, @@ -505,17 +518,18 @@ describe('gemini.tsx main function kitty protocol', () => { throw new MockProcessExitError(code); }); - vi.mocked(loadSettings).mockReturnValue({ - merged: { - advanced: {}, - security: { auth: {} }, - ui: {}, - }, - workspace: { settings: {} }, - setValue: vi.fn(), - forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), - errors: [], - } as any); // eslint-disable-line @typescript-eslint/no-explicit-any + vi.mocked(loadSettings).mockReturnValue( + createMockSettings({ + merged: { + advanced: {}, + security: { auth: {} }, + ui: {}, + }, + workspace: { settings: {} }, + setValue: vi.fn(), + forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), + }), + ); vi.mocked(parseArguments).mockResolvedValue({ promptInteractive: false, @@ -594,17 +608,18 @@ describe('gemini.tsx main function kitty protocol', () => { promptInteractive: false, } as any); // eslint-disable-line @typescript-eslint/no-explicit-any - vi.mocked(loadSettings).mockReturnValue({ - merged: { - advanced: {}, - security: { auth: {} }, - ui: {}, - }, - workspace: { settings: {} }, - setValue: vi.fn(), - forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), - errors: [], - } as any); // eslint-disable-line @typescript-eslint/no-explicit-any + vi.mocked(loadSettings).mockReturnValue( + createMockSettings({ + merged: { + advanced: {}, + security: { auth: {} }, + ui: {}, + }, + workspace: { settings: {} }, + setValue: vi.fn(), + forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), + }), + ); const mockConfig = { isInteractive: () => false, @@ -665,17 +680,18 @@ describe('gemini.tsx main function kitty protocol', () => { throw new MockProcessExitError(code); }); - vi.mocked(loadSettings).mockReturnValue({ - merged: { - advanced: {}, - security: { auth: {} }, - ui: { theme: 'non-existent-theme' }, - }, - workspace: { settings: {} }, - setValue: vi.fn(), - forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), - errors: [], - } as any); // eslint-disable-line @typescript-eslint/no-explicit-any + vi.mocked(loadSettings).mockReturnValue( + createMockSettings({ + merged: { + advanced: {}, + security: { auth: {} }, + ui: { theme: 'non-existent-theme' }, + }, + workspace: { settings: {} }, + setValue: vi.fn(), + forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), + }), + ); vi.mocked(parseArguments).mockResolvedValue({ promptInteractive: false, @@ -753,13 +769,14 @@ describe('gemini.tsx main function kitty protocol', () => { }); const emitFeedbackSpy = vi.spyOn(coreEvents, 'emitFeedback'); - vi.mocked(loadSettings).mockReturnValue({ - merged: { advanced: {}, security: { auth: {} }, ui: { theme: 'test' } }, - workspace: { settings: {} }, - setValue: vi.fn(), - forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), - errors: [], - } as any); // eslint-disable-line @typescript-eslint/no-explicit-any + vi.mocked(loadSettings).mockReturnValue( + createMockSettings({ + merged: { advanced: {}, security: { auth: {} }, ui: { theme: 'test' } }, + workspace: { settings: {} }, + setValue: vi.fn(), + forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), + }), + ); vi.mocked(parseArguments).mockResolvedValue({ promptInteractive: false, @@ -839,13 +856,14 @@ describe('gemini.tsx main function kitty protocol', () => { throw new MockProcessExitError(code); }); - vi.mocked(loadSettings).mockReturnValue({ - merged: { advanced: {}, security: { auth: {} }, ui: {} }, - workspace: { settings: {} }, - setValue: vi.fn(), - forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), - errors: [], - } as any); // eslint-disable-line @typescript-eslint/no-explicit-any + vi.mocked(loadSettings).mockReturnValue( + createMockSettings({ + merged: { advanced: {}, security: { auth: {} }, ui: {} }, + workspace: { settings: {} }, + setValue: vi.fn(), + forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), + }), + ); vi.mocked(parseArguments).mockResolvedValue({ promptInteractive: false, @@ -918,13 +936,14 @@ describe('gemini.tsx main function kitty protocol', () => { throw new MockProcessExitError(code); }); - vi.mocked(loadSettings).mockReturnValue({ - merged: { advanced: {}, security: { auth: {} }, ui: {} }, - workspace: { settings: {} }, - setValue: vi.fn(), - forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), - errors: [], - } as any); // eslint-disable-line @typescript-eslint/no-explicit-any + vi.mocked(loadSettings).mockReturnValue( + createMockSettings({ + merged: { advanced: {}, security: { auth: {} }, ui: {} }, + workspace: { settings: {} }, + setValue: vi.fn(), + forScope: () => ({ settings: {}, originalSettings: {}, path: '' }), + }), + ); vi.mocked(parseArguments).mockResolvedValue({ promptInteractive: false, @@ -1034,10 +1053,11 @@ describe('gemini.tsx main function exit codes', () => { ); const { loadSettings } = await import('./config/settings.js'); vi.mocked(loadCliConfig).mockResolvedValue({} as Config); - vi.mocked(loadSettings).mockReturnValue({ - merged: { security: { auth: {} }, ui: {} }, - errors: [], - } as never); + vi.mocked(loadSettings).mockReturnValue( + createMockSettings({ + merged: { security: { auth: {} }, ui: {} }, + }), + ); vi.mocked(parseArguments).mockResolvedValue({ promptInteractive: true, } as unknown as CliArgs); @@ -1066,14 +1086,13 @@ describe('gemini.tsx main function exit codes', () => { vi.mocked(loadCliConfig).mockResolvedValue({ refreshAuth: vi.fn().mockRejectedValue(new Error('Auth failed')), } as unknown as Config); - vi.mocked(loadSettings).mockReturnValue({ - merged: { - security: { auth: { selectedType: 'google', useExternal: false } }, - ui: {}, - }, - workspace: { settings: {} }, - errors: [], - } as never); + vi.mocked(loadSettings).mockReturnValue( + createMockSettings({ + merged: { + security: { auth: { selectedType: 'google', useExternal: false } }, + }, + }), + ); vi.mocked(parseArguments).mockResolvedValue({} as unknown as CliArgs); vi.mock('./config/auth.js', () => ({ validateAuthMethod: vi.fn().mockReturnValue(null), @@ -1131,11 +1150,11 @@ describe('gemini.tsx main function exit codes', () => { getProjectTempDir: vi.fn().mockReturnValue('/tmp/gemini-test'), }, } as unknown as Config); - vi.mocked(loadSettings).mockReturnValue({ - merged: { security: { auth: {} }, ui: {} }, - workspace: { settings: {} }, - errors: [], - } as never); + vi.mocked(loadSettings).mockReturnValue( + createMockSettings({ + merged: { security: { auth: {} }, ui: {} }, + }), + ); vi.mocked(parseArguments).mockResolvedValue({ resume: 'invalid-session', } as unknown as CliArgs); @@ -1200,11 +1219,11 @@ describe('gemini.tsx main function exit codes', () => { }, getRemoteAdminSettings: () => undefined, } as unknown as Config); - vi.mocked(loadSettings).mockReturnValue({ - merged: { security: { auth: {} }, ui: {} }, - workspace: { settings: {} }, - errors: [], - } as never); + vi.mocked(loadSettings).mockReturnValue( + createMockSettings({ + merged: { security: { auth: {} }, ui: {} }, + }), + ); vi.mocked(parseArguments).mockResolvedValue({} as unknown as CliArgs); Object.defineProperty(process.stdin, 'isTTY', { value: true, // Simulate TTY so it doesn't try to read stdin diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index 3f808c20b7..36411feae5 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -213,12 +213,12 @@ export async function startInteractiveUI( @@ -263,8 +263,7 @@ export async function startInteractiveUI( patchConsole: false, alternateBuffer: useAlternateBuffer, incrementalRendering: - settings.merged.ui?.incrementalRendering !== false && - useAlternateBuffer, + settings.merged.ui.incrementalRendering !== false && useAlternateBuffer, }, ); @@ -336,13 +335,13 @@ export async function main() { registerCleanup(consolePatcher.cleanup); dns.setDefaultResultOrder( - validateDnsResolutionOrder(settings.merged.advanced?.dnsResolutionOrder), + validateDnsResolutionOrder(settings.merged.advanced.dnsResolutionOrder), ); // Set a default auth type if one isn't set or is set to a legacy type if ( - !settings.merged.security?.auth?.selectedType || - settings.merged.security?.auth?.selectedType === AuthType.LEGACY_CLOUD_SHELL + !settings.merged.security.auth.selectedType || + settings.merged.security.auth.selectedType === AuthType.LEGACY_CLOUD_SHELL ) { if ( process.env['CLOUD_SHELL'] === 'true' || @@ -364,8 +363,8 @@ export async function main() { // the sandbox because the sandbox will interfere with the Oauth2 web // redirect. if ( - settings.merged.security?.auth?.selectedType && - !settings.merged.security?.auth?.useExternal + settings.merged.security.auth.selectedType && + !settings.merged.security.auth.useExternal ) { try { if (partialConfig.isInteractive()) { @@ -381,8 +380,8 @@ export async function main() { ); } else { const authType = await validateNonInteractiveAuth( - settings.merged.security?.auth?.selectedType, - settings.merged.security?.auth?.useExternal, + settings.merged.security.auth.selectedType, + settings.merged.security.auth.useExternal, partialConfig, settings, ); @@ -403,7 +402,7 @@ export async function main() { // hop into sandbox if we are outside and sandboxing is enabled if (!process.env['SANDBOX']) { - const memoryArgs = settings.merged.advanced?.autoConfigureMemory + const memoryArgs = settings.merged.advanced.autoConfigureMemory ? getNodeMemoryArgs(isDebugMode) : []; const sandboxConfig = await loadSandboxConfig(settings.merged, argv); @@ -506,7 +505,7 @@ export async function main() { // Handle --list-sessions flag if (config.getListSessions()) { // Attempt auth for summary generation (gracefully skips if not configured) - const authType = settings.merged.security?.auth?.selectedType; + const authType = settings.merged.security.auth.selectedType; if (authType) { try { await config.refreshAuth(authType); @@ -566,7 +565,7 @@ export async function main() { initAppHandle?.end(); if ( - settings.merged.security?.auth?.selectedType === + settings.merged.security.auth.selectedType === AuthType.LOGIN_WITH_GOOGLE && config.isBrowserLaunchSuppressed() ) { @@ -678,8 +677,8 @@ export async function main() { ); const authType = await validateNonInteractiveAuth( - settings.merged.security?.auth?.selectedType, - settings.merged.security?.auth?.useExternal, + settings.merged.security.auth.selectedType, + settings.merged.security.auth.useExternal, config, settings, ); @@ -705,14 +704,14 @@ export async function main() { } function setWindowTitle(title: string, settings: LoadedSettings) { - if (!settings.merged.ui?.hideWindowTitle) { + if (!settings.merged.ui.hideWindowTitle) { // Initial state before React loop starts const windowTitle = computeTerminalTitle({ streamingState: StreamingState.Idle, isConfirming: false, folderName: title, - showThoughts: !!settings.merged.ui?.showStatusInTitle, - useDynamicTitle: settings.merged.ui?.dynamicWindowTitle ?? true, + showThoughts: !!settings.merged.ui.showStatusInTitle, + useDynamicTitle: settings.merged.ui.dynamicWindowTitle, }); writeToStdout(`\x1b]0;${windowTitle}\x07`); diff --git a/packages/cli/src/test-utils/mockCommandContext.ts b/packages/cli/src/test-utils/mockCommandContext.ts index 37a0edcb19..63328b2a21 100644 --- a/packages/cli/src/test-utils/mockCommandContext.ts +++ b/packages/cli/src/test-utils/mockCommandContext.ts @@ -7,6 +7,7 @@ import { vi } from 'vitest'; import type { CommandContext } from '../ui/commands/types.js'; import type { LoadedSettings } from '../config/settings.js'; +import { mergeSettings } from '../config/settings.js'; import type { GitService } from '@google/gemini-cli-core'; import type { SessionStatsState } from '../ui/contexts/SessionContext.js'; @@ -27,6 +28,8 @@ type DeepPartial = T extends object export const createMockCommandContext = ( overrides: DeepPartial = {}, ): CommandContext => { + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); + const defaultMocks: CommandContext = { invocation: { raw: '', @@ -35,7 +38,11 @@ export const createMockCommandContext = ( }, services: { config: null, - settings: { merged: {} } as LoadedSettings, + settings: { + merged: defaultMergedSettings, + setValue: vi.fn(), + forScope: vi.fn().mockReturnValue({ settings: {} }), + } as unknown as LoadedSettings, git: undefined as GitService | undefined, logger: { log: vi.fn(), diff --git a/packages/cli/src/ui/App.test.tsx b/packages/cli/src/ui/App.test.tsx index 1a8851685a..0f806702ea 100644 --- a/packages/cli/src/ui/App.test.tsx +++ b/packages/cli/src/ui/App.test.tsx @@ -136,7 +136,7 @@ describe('App', () => { pendingHistoryItems: [{ type: 'user', text: 'pending item' }], } as UIState; - mockLoadedSettings.merged.ui = { useAlternateBuffer: true }; + mockLoadedSettings.merged.ui.useAlternateBuffer = true; const { lastFrame } = renderWithProviders(, quittingUIState); @@ -144,7 +144,7 @@ describe('App', () => { expect(lastFrame()).toContain('Quitting...'); // Reset settings - mockLoadedSettings.merged.ui = { useAlternateBuffer: false }; + mockLoadedSettings.merged.ui.useAlternateBuffer = false; }); it('should render dialog manager when dialogs are visible', () => { diff --git a/packages/cli/src/ui/AppContainer.test.tsx b/packages/cli/src/ui/AppContainer.test.tsx index 3dbf61c965..74ad2f35b1 100644 --- a/packages/cli/src/ui/AppContainer.test.tsx +++ b/packages/cli/src/ui/AppContainer.test.tsx @@ -82,7 +82,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { }; }); import ansiEscapes from 'ansi-escapes'; -import type { LoadedSettings } from '../config/settings.js'; +import { type LoadedSettings, mergeSettings } from '../config/settings.js'; import type { InitializationResult } from '../core/initializer.js'; import { useQuotaAndFallback } from './hooks/useQuotaAndFallback.js'; import { UIStateContext, type UIState } from './contexts/UIStateContext.js'; @@ -380,14 +380,17 @@ describe('AppContainer State Management', () => { ); // Mock LoadedSettings + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); mockSettings = { merged: { + ...defaultMergedSettings, hideBanner: false, hideFooter: false, hideTips: false, showMemoryUsage: false, theme: 'default', ui: { + ...defaultMergedSettings.ui, showStatusInTitle: false, hideWindowTitle: false, }, @@ -507,8 +510,10 @@ describe('AppContainer State Management', () => { describe('Settings Integration', () => { it('handles settings with all display options disabled', async () => { + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); const settingsAllHidden = { merged: { + ...defaultMergedSettings, hideBanner: true, hideFooter: true, hideTips: true, @@ -526,8 +531,10 @@ describe('AppContainer State Management', () => { }); it('handles settings with memory usage enabled', async () => { + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); const settingsWithMemory = { merged: { + ...defaultMergedSettings, hideBanner: false, hideFooter: false, hideTips: false, @@ -574,7 +581,7 @@ describe('AppContainer State Management', () => { it('handles undefined settings gracefully', async () => { const undefinedSettings = { - merged: {}, + merged: mergeSettings({}, {}, {}, {}, true), } as LoadedSettings; let unmount: () => void; @@ -991,12 +998,13 @@ describe('AppContainer State Management', () => { it('should update terminal title with Working… when showStatusInTitle is false', () => { // Arrange: Set up mock settings with showStatusInTitle disabled + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); const mockSettingsWithShowStatusFalse = { ...mockSettings, merged: { - ...mockSettings.merged, + ...defaultMergedSettings, ui: { - ...mockSettings.merged.ui, + ...defaultMergedSettings.ui, showStatusInTitle: false, hideWindowTitle: false, }, @@ -1073,12 +1081,13 @@ describe('AppContainer State Management', () => { it('should not update terminal title when hideWindowTitle is true', () => { // Arrange: Set up mock settings with hideWindowTitle enabled + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); const mockSettingsWithHideTitleTrue = { ...mockSettings, merged: { - ...mockSettings.merged, + ...defaultMergedSettings, ui: { - ...mockSettings.merged.ui, + ...defaultMergedSettings.ui, showStatusInTitle: true, hideWindowTitle: true, }, @@ -1101,12 +1110,13 @@ describe('AppContainer State Management', () => { it('should update terminal title with thought subject when in active state', () => { // Arrange: Set up mock settings with showStatusInTitle enabled + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); const mockSettingsWithTitleEnabled = { ...mockSettings, merged: { - ...mockSettings.merged, + ...defaultMergedSettings, ui: { - ...mockSettings.merged.ui, + ...defaultMergedSettings.ui, showStatusInTitle: true, hideWindowTitle: false, }, @@ -1143,12 +1153,13 @@ describe('AppContainer State Management', () => { it('should update terminal title with default text when in Idle state and no thought subject', () => { // Arrange: Set up mock settings with showStatusInTitle enabled + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); const mockSettingsWithTitleEnabled = { ...mockSettings, merged: { - ...mockSettings.merged, + ...defaultMergedSettings, ui: { - ...mockSettings.merged.ui, + ...defaultMergedSettings.ui, showStatusInTitle: true, hideWindowTitle: false, }, @@ -1184,12 +1195,13 @@ describe('AppContainer State Management', () => { it('should update terminal title when in WaitingForConfirmation state with thought subject', async () => { // Arrange: Set up mock settings with showStatusInTitle enabled + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); const mockSettingsWithTitleEnabled = { ...mockSettings, merged: { - ...mockSettings.merged, + ...defaultMergedSettings, ui: { - ...mockSettings.merged.ui, + ...defaultMergedSettings.ui, showStatusInTitle: true, hideWindowTitle: false, }, @@ -1392,12 +1404,13 @@ describe('AppContainer State Management', () => { it('should pad title to exactly 80 characters', () => { // Arrange: Set up mock settings with showStatusInTitle enabled + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); const mockSettingsWithTitleEnabled = { ...mockSettings, merged: { - ...mockSettings.merged, + ...defaultMergedSettings, ui: { - ...mockSettings.merged.ui, + ...defaultMergedSettings.ui, showStatusInTitle: true, hideWindowTitle: false, }, @@ -1435,12 +1448,13 @@ describe('AppContainer State Management', () => { it('should use correct ANSI escape code format', () => { // Arrange: Set up mock settings with showStatusInTitle enabled + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); const mockSettingsWithTitleEnabled = { ...mockSettings, merged: { - ...mockSettings.merged, + ...defaultMergedSettings, ui: { - ...mockSettings.merged.ui, + ...defaultMergedSettings.ui, showStatusInTitle: true, hideWindowTitle: false, }, @@ -1802,12 +1816,13 @@ describe('AppContainer State Management', () => { const setupCopyModeTest = async (isAlternateMode = false) => { // Update settings for this test run + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); const testSettings = { ...mockSettings, merged: { - ...mockSettings.merged, + ...defaultMergedSettings, ui: { - ...mockSettings.merged.ui, + ...defaultMergedSettings.ui, useAlternateBuffer: isAlternateMode, }, }, diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index 10f5a54a1c..46dd1a69c2 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -392,8 +392,8 @@ export const AppContainer = (props: AppContainerProps) => { }, []); const getPreferredEditor = useCallback( - () => settings.merged.general?.preferredEditor as EditorType, - [settings.merged.general?.preferredEditor], + () => settings.merged.general.preferredEditor as EditorType, + [settings.merged.general.preferredEditor], ); const buffer = useTextBuffer({ @@ -443,7 +443,7 @@ export const AppContainer = (props: AppContainerProps) => { useEffect(() => { if ( - !(settings.merged.ui?.hideBanner || config.getScreenReader()) && + !(settings.merged.ui.hideBanner || config.getScreenReader()) && bannerVisible && bannerText ) { @@ -603,17 +603,17 @@ Logging in with Google... Restarting Gemini CLI to continue. // Check for enforced auth type mismatch useEffect(() => { if ( - settings.merged.security?.auth?.enforcedType && - settings.merged.security?.auth.selectedType && - settings.merged.security?.auth.enforcedType !== - settings.merged.security?.auth.selectedType + settings.merged.security.auth.enforcedType && + settings.merged.security.auth.selectedType && + settings.merged.security.auth.enforcedType !== + settings.merged.security.auth.selectedType ) { onAuthError( - `Authentication is enforced to be ${settings.merged.security?.auth.enforcedType}, but you are currently using ${settings.merged.security?.auth.selectedType}.`, + `Authentication is enforced to be ${settings.merged.security.auth.enforcedType}, but you are currently using ${settings.merged.security.auth.selectedType}.`, ); } else if ( - settings.merged.security?.auth?.selectedType && - !settings.merged.security?.auth?.useExternal + settings.merged.security.auth.selectedType && + !settings.merged.security.auth.useExternal ) { // We skip validation for Gemini API key here because it might be stored // in the keychain, which we can't check synchronously. @@ -630,9 +630,9 @@ Logging in with Google... Restarting Gemini CLI to continue. } } }, [ - settings.merged.security?.auth?.selectedType, - settings.merged.security?.auth?.enforcedType, - settings.merged.security?.auth?.useExternal, + settings.merged.security.auth.selectedType, + settings.merged.security.auth.enforcedType, + settings.merged.security.auth.useExternal, onAuthError, ]); @@ -951,8 +951,8 @@ Logging in with Google... Restarting Gemini CLI to continue. Math.floor(availableTerminalHeight - SHELL_HEIGHT_PADDING), 1, ), - pager: settings.merged.tools?.shell?.pager, - showColor: settings.merged.tools?.shell?.showColor, + pager: settings.merged.tools.shell.pager, + showColor: settings.merged.tools.shell.showColor, sanitizationConfig: config.sanitizationConfig, }); @@ -960,13 +960,13 @@ Logging in with Google... Restarting Gemini CLI to continue. // Context file names computation const contextFileNames = useMemo(() => { - const fromSettings = settings.merged.context?.fileName; + const fromSettings = settings.merged.context.fileName; return fromSettings ? Array.isArray(fromSettings) ? fromSettings : [fromSettings] : getAllGeminiMdFilenames(); - }, [settings.merged.context?.fileName]); + }, [settings.merged.context.fileName]); // Initial prompt handling const initialPrompt = useMemo(() => config.getQuestion(), [config]); const initialPromptSubmitted = useRef(false); @@ -1040,7 +1040,7 @@ Logging in with Google... Restarting Gemini CLI to continue. const shouldShowIdePrompt = Boolean( currentIDE && !config.getIdeMode() && - !settings.merged.ide?.hasSeenNudge && + !settings.merged.ide.hasSeenNudge && !idePromptAnswered, ); @@ -1221,7 +1221,7 @@ Logging in with Google... Restarting Gemini CLI to continue. const { elapsedTime, currentLoadingPhrase } = useLoadingIndicator( streamingState, - settings.merged.ui?.customWittyPhrases, + settings.merged.ui.customWittyPhrases, !!activePtyId && !embeddedShellFocused, lastOutputTime, retryStatus, @@ -1237,7 +1237,7 @@ Logging in with Google... Restarting Gemini CLI to continue. } // Debug log keystrokes if enabled - if (settings.merged.general?.debugKeystrokeLogging) { + if (settings.merged.general.debugKeystrokeLogging) { debugLogger.log('[DEBUG] Keystroke:', JSON.stringify(key)); } @@ -1337,7 +1337,7 @@ Logging in with Google... Restarting Gemini CLI to continue. cancelOngoingRequest, activePtyId, embeddedShellFocused, - settings.merged.general?.debugKeystrokeLogging, + settings.merged.general.debugKeystrokeLogging, refreshStatic, setCopyModeEnabled, copyModeEnabled, @@ -1351,7 +1351,7 @@ Logging in with Google... Restarting Gemini CLI to continue. // Update terminal title with Gemini CLI status and thoughts useEffect(() => { // Respect hideWindowTitle settings - if (settings.merged.ui?.hideWindowTitle) return; + if (settings.merged.ui.hideWindowTitle) return; const paddedTitle = computeTerminalTitle({ streamingState, @@ -1361,8 +1361,8 @@ Logging in with Google... Restarting Gemini CLI to continue. !!confirmationRequest || showShellActionRequired, folderName: basename(config.getTargetDir()), - showThoughts: !!settings.merged.ui?.showStatusInTitle, - useDynamicTitle: settings.merged.ui?.dynamicWindowTitle ?? true, + showThoughts: !!settings.merged.ui.showStatusInTitle, + useDynamicTitle: settings.merged.ui.dynamicWindowTitle, }); // Only update the title if it's different from the last value we set @@ -1377,9 +1377,9 @@ Logging in with Google... Restarting Gemini CLI to continue. shellConfirmationRequest, confirmationRequest, showShellActionRequired, - settings.merged.ui?.showStatusInTitle, - settings.merged.ui?.dynamicWindowTitle, - settings.merged.ui?.hideWindowTitle, + settings.merged.ui.showStatusInTitle, + settings.merged.ui.dynamicWindowTitle, + settings.merged.ui.hideWindowTitle, config, stdout, ]); diff --git a/packages/cli/src/ui/auth/AuthDialog.test.tsx b/packages/cli/src/ui/auth/AuthDialog.test.tsx index 66be01856d..6757979c42 100644 --- a/packages/cli/src/ui/auth/AuthDialog.test.tsx +++ b/packages/cli/src/ui/auth/AuthDialog.test.tsx @@ -152,7 +152,7 @@ describe('AuthDialog', () => { }); it('filters auth types when enforcedType is set', () => { - props.settings.merged.security!.auth!.enforcedType = AuthType.USE_GEMINI; + props.settings.merged.security.auth.enforcedType = AuthType.USE_GEMINI; renderWithProviders(); const items = mockedRadioButtonSelect.mock.calls[0][0].items; expect(items).toHaveLength(1); @@ -160,7 +160,7 @@ describe('AuthDialog', () => { }); it('sets initial index to 0 when enforcedType is set', () => { - props.settings.merged.security!.auth!.enforcedType = AuthType.USE_GEMINI; + props.settings.merged.security.auth.enforcedType = AuthType.USE_GEMINI; renderWithProviders(); const { initialIndex } = mockedRadioButtonSelect.mock.calls[0][0]; expect(initialIndex).toBe(0); @@ -170,7 +170,7 @@ describe('AuthDialog', () => { it.each([ { setup: () => { - props.settings.merged.security!.auth!.selectedType = + props.settings.merged.security.auth.selectedType = AuthType.USE_VERTEX_AI; }, expected: AuthType.USE_VERTEX_AI, @@ -290,7 +290,7 @@ describe('AuthDialog', () => { mockedValidateAuthMethod.mockReturnValue(null); process.env['GEMINI_API_KEY'] = 'test-key-from-env'; // Simulate that the user has already authenticated once - props.settings.merged.security!.auth!.selectedType = + props.settings.merged.security.auth.selectedType = AuthType.LOGIN_WITH_GOOGLE; renderWithProviders(); @@ -349,7 +349,7 @@ describe('AuthDialog', () => { { desc: 'calls onAuthError on escape if no auth method is set', setup: () => { - props.settings.merged.security!.auth!.selectedType = undefined; + props.settings.merged.security.auth.selectedType = undefined; }, expectations: (p: typeof props) => { expect(p.onAuthError).toHaveBeenCalledWith( @@ -360,7 +360,7 @@ describe('AuthDialog', () => { { desc: 'calls setAuthState(Unauthenticated) on escape if auth method is set', setup: () => { - props.settings.merged.security!.auth!.selectedType = + props.settings.merged.security.auth.selectedType = AuthType.USE_GEMINI; }, expectations: (p: typeof props) => { @@ -392,7 +392,7 @@ describe('AuthDialog', () => { }); it('renders correctly with enforced auth type', () => { - props.settings.merged.security!.auth!.enforcedType = AuthType.USE_GEMINI; + props.settings.merged.security.auth.enforcedType = AuthType.USE_GEMINI; const { lastFrame } = renderWithProviders(); expect(lastFrame()).toMatchSnapshot(); }); diff --git a/packages/cli/src/ui/auth/AuthDialog.tsx b/packages/cli/src/ui/auth/AuthDialog.tsx index 558927dcf2..0799b38b70 100644 --- a/packages/cli/src/ui/auth/AuthDialog.tsx +++ b/packages/cli/src/ui/auth/AuthDialog.tsx @@ -78,9 +78,9 @@ export function AuthDialog({ }, ]; - if (settings.merged.security?.auth?.enforcedType) { + if (settings.merged.security.auth.enforcedType) { items = items.filter( - (item) => item.value === settings.merged.security?.auth?.enforcedType, + (item) => item.value === settings.merged.security.auth.enforcedType, ); } @@ -94,7 +94,7 @@ export function AuthDialog({ } let initialAuthIndex = items.findIndex((item) => { - if (settings.merged.security?.auth?.selectedType) { + if (settings.merged.security.auth.selectedType) { return item.value === settings.merged.security.auth.selectedType; } @@ -108,7 +108,7 @@ export function AuthDialog({ return item.value === AuthType.LOGIN_WITH_GOOGLE; }); - if (settings.merged.security?.auth?.enforcedType) { + if (settings.merged.security.auth.enforcedType) { initialAuthIndex = 0; } @@ -171,7 +171,7 @@ export function AuthDialog({ if (authError) { return; } - if (settings.merged.security?.auth?.selectedType === undefined) { + if (settings.merged.security.auth.selectedType === undefined) { // Prevent exiting if no auth method is set onAuthError( 'You must select an auth method to proceed. Press Ctrl+C twice to exit.', diff --git a/packages/cli/src/ui/auth/useAuth.ts b/packages/cli/src/ui/auth/useAuth.ts index 004e362d10..7b37e2d421 100644 --- a/packages/cli/src/ui/auth/useAuth.ts +++ b/packages/cli/src/ui/auth/useAuth.ts @@ -20,11 +20,11 @@ export function validateAuthMethodWithSettings( authType: AuthType, settings: LoadedSettings, ): string | null { - const enforcedType = settings.merged.security?.auth?.enforcedType; + const enforcedType = settings.merged.security.auth.enforcedType; if (enforcedType && enforcedType !== authType) { return `Authentication is enforced to be ${enforcedType}, but you are currently using ${authType}.`; } - if (settings.merged.security?.auth?.useExternal) { + if (settings.merged.security.auth.useExternal) { return null; } // If using Gemini API key, we don't validate it here as we might need to prompt for it. @@ -80,7 +80,7 @@ export const useAuthCommand = (settings: LoadedSettings, config: Config) => { return; } - const authType = settings.merged.security?.auth?.selectedType; + const authType = settings.merged.security.auth.selectedType; if (!authType) { if (process.env['GEMINI_API_KEY']) { onAuthError( diff --git a/packages/cli/src/ui/commands/aboutCommand.ts b/packages/cli/src/ui/commands/aboutCommand.ts index 46589a0c99..3def750895 100644 --- a/packages/cli/src/ui/commands/aboutCommand.ts +++ b/packages/cli/src/ui/commands/aboutCommand.ts @@ -33,7 +33,7 @@ export const aboutCommand: SlashCommand = { const modelVersion = context.services.config?.getModel() || 'Unknown'; const cliVersion = await getVersion(); const selectedAuthType = - context.services.settings.merged.security?.auth?.selectedType || ''; + context.services.settings.merged.security.auth.selectedType || ''; const gcpProject = process.env['GOOGLE_CLOUD_PROJECT'] || ''; const ideClient = await getIdeClientName(context); diff --git a/packages/cli/src/ui/commands/agentsCommand.test.ts b/packages/cli/src/ui/commands/agentsCommand.test.ts index f126ddd8ee..e8d2568f60 100644 --- a/packages/cli/src/ui/commands/agentsCommand.test.ts +++ b/packages/cli/src/ui/commands/agentsCommand.test.ts @@ -7,7 +7,7 @@ import { vi, describe, it, expect, beforeEach } from 'vitest'; import { agentsCommand } from './agentsCommand.js'; import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; -import type { Config, AgentOverride } from '@google/gemini-cli-core'; +import type { Config } from '@google/gemini-cli-core'; import type { LoadedSettings } from '../../config/settings.js'; import { MessageType } from '../types.js'; import { enableAgent, disableAgent } from '../../utils/agentSettings.js'; @@ -148,12 +148,9 @@ describe('agentsCommand', () => { reload: reloadSpy, }); // Add agent to disabled overrides so validation passes - ( - mockContext.services.settings.merged.agents!.overrides as Record< - string, - AgentOverride - > - )['test-agent'] = { disabled: true }; + mockContext.services.settings.merged.agents.overrides['test-agent'] = { + disabled: true, + }; vi.mocked(enableAgent).mockReturnValue({ status: 'success', @@ -266,12 +263,9 @@ describe('agentsCommand', () => { it('should show info message if agent is already disabled', async () => { mockConfig.getAgentRegistry().getAllAgentNames.mockReturnValue([]); - ( - mockContext.services.settings.merged.agents!.overrides as Record< - string, - AgentOverride - > - )['test-agent'] = { disabled: true }; + mockContext.services.settings.merged.agents.overrides['test-agent'] = { + disabled: true, + }; const disableCommand = agentsCommand.subCommands?.find( (cmd) => cmd.name === 'disable', diff --git a/packages/cli/src/ui/commands/agentsCommand.ts b/packages/cli/src/ui/commands/agentsCommand.ts index 1c03524332..345d66bb24 100644 --- a/packages/cli/src/ui/commands/agentsCommand.ts +++ b/packages/cli/src/ui/commands/agentsCommand.ts @@ -12,7 +12,6 @@ import type { import { CommandKind } from './types.js'; import { MessageType, type HistoryItemAgentsList } from '../types.js'; import { SettingScope } from '../../config/settings.js'; -import type { AgentOverride } from '@google/gemini-cli-core'; import { disableAgent, enableAgent } from '../../utils/agentSettings.js'; import { renderAgentActionFeedback } from '../../utils/agentUtils.js'; @@ -84,10 +83,7 @@ async function enableAction( } const allAgents = agentRegistry.getAllAgentNames(); - const overrides = (settings.merged.agents?.overrides ?? {}) as Record< - string, - AgentOverride - >; + const overrides = settings.merged.agents.overrides; const disabledAgents = Object.keys(overrides).filter( (name) => overrides[name]?.disabled === true, ); @@ -157,10 +153,7 @@ async function disableAction( } const allAgents = agentRegistry.getAllAgentNames(); - const overrides = (settings.merged.agents?.overrides ?? {}) as Record< - string, - AgentOverride - >; + const overrides = settings.merged.agents.overrides; const disabledAgents = Object.keys(overrides).filter( (name) => overrides[name]?.disabled === true, ); @@ -211,10 +204,7 @@ function completeAgentsToEnable(context: CommandContext, partialArg: string) { const { config, settings } = context.services; if (!config) return []; - const overrides = (settings.merged.agents?.overrides ?? {}) as Record< - string, - AgentOverride - >; + const overrides = settings.merged.agents.overrides; const disabledAgents = Object.entries(overrides) .filter(([_, override]) => override?.disabled === true) .map(([name]) => name); diff --git a/packages/cli/src/ui/commands/hooksCommand.test.ts b/packages/cli/src/ui/commands/hooksCommand.test.ts index 4f9499c0aa..2d5588dee8 100644 --- a/packages/cli/src/ui/commands/hooksCommand.test.ts +++ b/packages/cli/src/ui/commands/hooksCommand.test.ts @@ -271,9 +271,10 @@ describe('hooksCommand', () => { it('should enable a hook and update settings', async () => { // Update the context's settings with disabled hooks - mockContext.services.settings.merged.hooks = { - disabled: ['test-hook', 'other-hook'], - }; + mockContext.services.settings.merged.hooks.disabled = [ + 'test-hook', + 'other-hook', + ]; const enableCmd = hooksCommand.subCommands!.find( (cmd) => cmd.name === 'enable', @@ -401,9 +402,7 @@ describe('hooksCommand', () => { }); it('should disable a hook and update settings', async () => { - mockContext.services.settings.merged.hooks = { - disabled: [], - }; + mockContext.services.settings.merged.hooks.disabled = []; const disableCmd = hooksCommand.subCommands!.find( (cmd) => cmd.name === 'disable', @@ -432,9 +431,7 @@ describe('hooksCommand', () => { it('should return info when hook is already disabled', async () => { // Update the context's settings with the hook already disabled - mockContext.services.settings.merged.hooks = { - disabled: ['test-hook'], - }; + mockContext.services.settings.merged.hooks.disabled = ['test-hook']; const disableCmd = hooksCommand.subCommands!.find( (cmd) => cmd.name === 'disable', @@ -455,9 +452,7 @@ describe('hooksCommand', () => { }); it('should handle error when disabling hook fails', async () => { - mockContext.services.settings.merged.hooks = { - disabled: [], - }; + mockContext.services.settings.merged.hooks.disabled = []; mockSettings.setValue.mockImplementationOnce(() => { throw new Error('Failed to save settings'); }); diff --git a/packages/cli/src/ui/commands/hooksCommand.ts b/packages/cli/src/ui/commands/hooksCommand.ts index 050bf3045e..e8afca5613 100644 --- a/packages/cli/src/ui/commands/hooksCommand.ts +++ b/packages/cli/src/ui/commands/hooksCommand.ts @@ -76,8 +76,7 @@ async function enableAction( // Get current disabled hooks from settings const settings = context.services.settings; - const disabledHooks = settings.merged.hooks?.disabled || ([] as string[]); - + const disabledHooks = settings.merged.hooks.disabled; // Remove from disabled list if present const newDisabledHooks = disabledHooks.filter( (name: string) => name !== hookName, @@ -143,8 +142,7 @@ async function disableAction( // Get current disabled hooks from settings const settings = context.services.settings; - const disabledHooks = settings.merged.hooks?.disabled || ([] as string[]); - + const disabledHooks = settings.merged.hooks.disabled; // Add to disabled list if not already present if (!disabledHooks.includes(hookName)) { const newDisabledHooks = [...disabledHooks, hookName]; diff --git a/packages/cli/src/ui/components/AppHeader.tsx b/packages/cli/src/ui/components/AppHeader.tsx index c404c0e9f9..a70a7b20d8 100644 --- a/packages/cli/src/ui/components/AppHeader.tsx +++ b/packages/cli/src/ui/components/AppHeader.tsx @@ -26,7 +26,7 @@ export const AppHeader = ({ version }: AppHeaderProps) => { return ( - {!(settings.merged.ui?.hideBanner || config.getScreenReader()) && ( + {!(settings.merged.ui.hideBanner || config.getScreenReader()) && ( <>
{bannerVisible && bannerText && ( @@ -38,7 +38,7 @@ export const AppHeader = ({ version }: AppHeaderProps) => { )} )} - {!(settings.merged.ui?.hideTips || config.getScreenReader()) && ( + {!(settings.merged.ui.hideTips || config.getScreenReader()) && ( )} diff --git a/packages/cli/src/ui/components/Composer.test.tsx b/packages/cli/src/ui/components/Composer.test.tsx index c39d7c5ece..73e68684a5 100644 --- a/packages/cli/src/ui/components/Composer.test.tsx +++ b/packages/cli/src/ui/components/Composer.test.tsx @@ -24,6 +24,7 @@ vi.mock('../contexts/VimModeContext.js', () => ({ })); import { ApprovalMode } from '@google/gemini-cli-core'; import { StreamingState } from '../types.js'; +import { mergeSettings } from '../../config/settings.js'; // Mock child components vi.mock('./LoadingIndicator.js', () => ({ @@ -163,13 +164,20 @@ const createMockConfig = (overrides = {}) => ({ ...overrides, }); -const createMockSettings = (merged = {}) => ({ - merged: { - hideFooter: false, - showMemoryUsage: false, - ...merged, - }, -}); +const createMockSettings = (merged = {}) => { + const defaultMergedSettings = mergeSettings({}, {}, {}, {}, true); + return { + merged: { + ...defaultMergedSettings, + ui: { + ...defaultMergedSettings.ui, + hideFooter: false, + showMemoryUsage: false, + ...merged, + }, + }, + }; +}; /* eslint-disable @typescript-eslint/no-explicit-any */ const renderComposer = ( diff --git a/packages/cli/src/ui/components/Composer.tsx b/packages/cli/src/ui/components/Composer.tsx index d48cced332..b7db494409 100644 --- a/packages/cli/src/ui/components/Composer.tsx +++ b/packages/cli/src/ui/components/Composer.tsx @@ -82,9 +82,7 @@ export const Composer = () => { { /> )} - {!settings.merged.ui?.hideFooter && !isScreenReaderEnabled &&