From 02adfe2bca6d2f9769dcc1426b52daee2447bd4f Mon Sep 17 00:00:00 2001 From: Jerop Kipruto Date: Wed, 11 Feb 2026 15:04:01 -0500 Subject: [PATCH 01/44] docs(plan): add `ask_user` tool documentation (#18830) --- docs/cli/plan-mode.md | 5 ++- docs/tools/ask-user.md | 95 ++++++++++++++++++++++++++++++++++++++++++ docs/tools/index.md | 2 + 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 docs/tools/ask-user.md diff --git a/docs/cli/plan-mode.md b/docs/cli/plan-mode.md index 6c85515755..751794996b 100644 --- a/docs/cli/plan-mode.md +++ b/docs/cli/plan-mode.md @@ -68,7 +68,7 @@ You can enter Plan Mode in three ways: ### The Planning Workflow -1. **Requirements:** The agent clarifies goals using `ask_user`. +1. **Requirements:** The agent clarifies goals using [`ask_user`]. 2. **Exploration:** The agent uses read-only tools (like [`read_file`]) to map the codebase and validate assumptions. 3. **Design:** The agent proposes alternative approaches with a recommended @@ -95,7 +95,7 @@ These are the only allowed tools: - **FileSystem (Read):** [`read_file`], [`list_directory`], [`glob`] - **Search:** [`grep_search`], [`google_web_search`] -- **Interaction:** `ask_user` +- **Interaction:** [`ask_user`] - **MCP Tools (Read):** Read-only [MCP tools] (e.g., `github_read_issue`, `postgres_read_schema`) are allowed. - **Planning (Write):** [`write_file`] and [`replace`] ONLY allowed for `.md` @@ -183,3 +183,4 @@ Guide]. [Policy Engine Guide]: /docs/core/policy-engine.md [`enter_plan_mode`]: /docs/tools/planning.md#1-enter_plan_mode-enterplanmode [`exit_plan_mode`]: /docs/tools/planning.md#2-exit_plan_mode-exitplanmode +[`ask_user`]: /docs/tools/ask-user.md diff --git a/docs/tools/ask-user.md b/docs/tools/ask-user.md new file mode 100644 index 0000000000..ad6c3b5a06 --- /dev/null +++ b/docs/tools/ask-user.md @@ -0,0 +1,95 @@ +# Ask User Tool + +The `ask_user` tool allows the agent to ask you one or more questions to gather +preferences, clarify requirements, or make decisions. It supports multiple +question types including multiple-choice, free-form text, and Yes/No +confirmation. + +## `ask_user` (Ask User) + +- **Tool name:** `ask_user` +- **Display name:** Ask User +- **File:** `ask-user.ts` +- **Parameters:** + - `questions` (array of objects, required): A list of 1 to 4 questions to ask. + Each question object has the following properties: + - `question` (string, required): The complete question text. + - `header` (string, required): A short label (max 16 chars) displayed as a + chip/tag (e.g., "Auth", "Database"). + - `type` (string, optional): The type of question. Defaults to `'choice'`. + - `'choice'`: Multiple-choice with options (supports multi-select). + - `'text'`: Free-form text input. + - `'yesno'`: Yes/No confirmation. + - `options` (array of objects, optional): Required for `'choice'` type. 2-4 + selectable options. + - `label` (string, required): Display text (1-5 words). + - `description` (string, required): Brief explanation. + - `multiSelect` (boolean, optional): For `'choice'` type, allows selecting + multiple options. + - `placeholder` (string, optional): Hint text for input fields. + +- **Behavior:** + - Presents an interactive dialog to the user with the specified questions. + - Pauses execution until the user provides answers or dismisses the dialog. + - Returns the user's answers to the model. + +- **Output (`llmContent`):** A JSON string containing the user's answers, + indexed by question position (e.g., + `{"answers":{"0": "Option A", "1": "Some text"}}`). + +- **Confirmation:** Yes. The tool inherently involves user interaction. + +## Usage Examples + +### Multiple Choice Question + +```json +{ + "questions": [ + { + "header": "Database", + "question": "Which database would you like to use?", + "type": "choice", + "options": [ + { + "label": "PostgreSQL", + "description": "Powerful, open source object-relational database system." + }, + { + "label": "SQLite", + "description": "C-library that implements a SQL database engine." + } + ] + } + ] +} +``` + +### Text Input Question + +```json +{ + "questions": [ + { + "header": "Project Name", + "question": "What is the name of your new project?", + "type": "text", + "placeholder": "e.g., my-awesome-app" + } + ] +} +``` + +### Yes/No Question + +```json +{ + "questions": [ + { + "header": "Deploy", + "question": "Do you want to deploy the application now?", + "type": "yesno" + } + ] +} +``` diff --git a/docs/tools/index.md b/docs/tools/index.md index ff594056ac..c7b2c1fc72 100644 --- a/docs/tools/index.md +++ b/docs/tools/index.md @@ -87,6 +87,8 @@ Gemini CLI's built-in tools can be broadly categorized as follows: - **[Todo Tool](./todos.md) (`write_todos`):** For managing subtasks of complex requests. - **[Planning Tools](./planning.md):** For entering and exiting Plan Mode. +- **[Ask User Tool](./ask-user.md) (`ask_user`):** For gathering user input and + making decisions. Additionally, these tools incorporate: From e9a94748107ac24a05f51b4c5b0c0a8952374285 Mon Sep 17 00:00:00 2001 From: Adib234 <30782825+Adib234@users.noreply.github.com> Date: Wed, 11 Feb 2026 15:06:28 -0500 Subject: [PATCH 02/44] Revert unintended credentials exposure (#18840) --- docs/tools/mcp-server.md | 13 +--- packages/cli/src/commands/mcp/add.ts | 7 -- .../services/environmentSanitization.test.ts | 3 - .../src/services/environmentSanitization.ts | 3 - packages/core/src/tools/mcp-client.test.ts | 73 +------------------ packages/core/src/tools/mcp-client.ts | 41 ++--------- 6 files changed, 8 insertions(+), 132 deletions(-) diff --git a/docs/tools/mcp-server.md b/docs/tools/mcp-server.md index eb246fd86f..dd3842759c 100644 --- a/docs/tools/mcp-server.md +++ b/docs/tools/mcp-server.md @@ -739,21 +739,10 @@ The MCP integration tracks several states: cautiously and only for servers you completely control - **Access tokens:** Be security-aware when configuring environment variables containing API keys or tokens -- **Environment variable redaction:** By default, the Gemini CLI redacts - sensitive environment variables (such as `GEMINI_API_KEY`, `GOOGLE_API_KEY`, - and variables matching patterns like `*TOKEN*`, `*SECRET*`, `*PASSWORD*`) when - spawning MCP servers using the `stdio` transport. This prevents unintended - exposure of your credentials to third-party servers. -- **Explicit environment variables:** If you need to pass a specific environment - variable to an MCP server, you should define it explicitly in the `env` - property of the server configuration in `settings.json`. - **Sandbox compatibility:** When using sandboxing, ensure MCP servers are - available within the sandbox environment. + available within the sandbox environment - **Private data:** Using broadly scoped personal access tokens can lead to information leakage between repositories. -- **Untrusted servers:** Be extremely cautious when adding MCP servers from - untrusted or third-party sources. Malicious servers could attempt to - exfiltrate data or perform unauthorized actions through the tools they expose. ### Performance and resource management diff --git a/packages/cli/src/commands/mcp/add.ts b/packages/cli/src/commands/mcp/add.ts index 7d744a1daa..98e6a70879 100644 --- a/packages/cli/src/commands/mcp/add.ts +++ b/packages/cli/src/commands/mcp/add.ts @@ -128,13 +128,6 @@ async function addMcpServer( settings.setValue(settingsScope, 'mcpServers', mcpServers); - if (transport === 'stdio') { - debugLogger.warn( - 'Security Warning: Running MCP servers with stdio transport can expose inherited environment variables. ' + - 'While the Gemini CLI redacts common API keys and secrets by default, you should only run servers from trusted sources.', - ); - } - if (isExistingServer) { debugLogger.log(`MCP server "${name}" updated in ${scope} settings.`); } else { diff --git a/packages/core/src/services/environmentSanitization.test.ts b/packages/core/src/services/environmentSanitization.test.ts index 97f7e575ca..cc26d7547d 100644 --- a/packages/core/src/services/environmentSanitization.test.ts +++ b/packages/core/src/services/environmentSanitization.test.ts @@ -46,9 +46,6 @@ describe('sanitizeEnvironment', () => { CLIENT_ID: 'sensitive-id', DB_URI: 'sensitive-uri', DATABASE_URL: 'sensitive-url', - GEMINI_API_KEY: 'sensitive-gemini-key', - GOOGLE_API_KEY: 'sensitive-google-key', - GOOGLE_APPLICATION_CREDENTIALS: '/path/to/creds.json', SAFE_VAR: 'is-safe', }; const sanitized = sanitizeEnvironment(env, EMPTY_OPTIONS); diff --git a/packages/core/src/services/environmentSanitization.ts b/packages/core/src/services/environmentSanitization.ts index b30b229079..dc9c92484d 100644 --- a/packages/core/src/services/environmentSanitization.ts +++ b/packages/core/src/services/environmentSanitization.ts @@ -103,9 +103,6 @@ export const NEVER_ALLOWED_ENVIRONMENT_VARIABLES: ReadonlySet = new Set( 'GOOGLE_CLOUD_PROJECT', 'GOOGLE_CLOUD_ACCOUNT', 'FIREBASE_PROJECT_ID', - 'GEMINI_API_KEY', - 'GOOGLE_API_KEY', - 'GOOGLE_APPLICATION_CREDENTIALS', ], ); diff --git a/packages/core/src/tools/mcp-client.test.ts b/packages/core/src/tools/mcp-client.test.ts index 77dec9d657..39165bde45 100644 --- a/packages/core/src/tools/mcp-client.test.ts +++ b/packages/core/src/tools/mcp-client.test.ts @@ -1623,7 +1623,7 @@ describe('mcp-client', () => { { command: 'test-command', args: ['--foo', 'bar'], - env: { GEMINI_CLI_FOO: 'bar' }, + env: { FOO: 'bar' }, cwd: 'test/cwd', }, false, @@ -1634,80 +1634,11 @@ describe('mcp-client', () => { command: 'test-command', args: ['--foo', 'bar'], cwd: 'test/cwd', - env: expect.objectContaining({ GEMINI_CLI_FOO: 'bar' }), + env: expect.objectContaining({ FOO: 'bar' }), stderr: 'pipe', }); }); - it('should redact sensitive environment variables for command transport', async () => { - const mockedTransport = vi - .spyOn(SdkClientStdioLib, 'StdioClientTransport') - .mockReturnValue({} as SdkClientStdioLib.StdioClientTransport); - - const originalEnv = process.env; - process.env = { - ...originalEnv, - GEMINI_API_KEY: 'sensitive-key', - GEMINI_CLI_SAFE_VAR: 'safe-value', - }; - // Ensure strict sanitization is not triggered for this test - delete process.env['GITHUB_SHA']; - delete process.env['SURFACE']; - - try { - await createTransport( - 'test-server', - { - command: 'test-command', - }, - false, - EMPTY_CONFIG, - ); - - const callArgs = mockedTransport.mock.calls[0][0]; - expect(callArgs.env).toBeDefined(); - expect(callArgs.env!['GEMINI_CLI_SAFE_VAR']).toBe('safe-value'); - expect(callArgs.env!['GEMINI_API_KEY']).toBeUndefined(); - } finally { - process.env = originalEnv; - } - }); - - it('should include extension settings in environment', async () => { - const mockedTransport = vi - .spyOn(SdkClientStdioLib, 'StdioClientTransport') - .mockReturnValue({} as SdkClientStdioLib.StdioClientTransport); - - await createTransport( - 'test-server', - { - command: 'test-command', - extension: { - name: 'test-ext', - resolvedSettings: [ - { - envVar: 'GEMINI_CLI_EXT_VAR', - value: 'ext-value', - sensitive: false, - name: 'ext-setting', - }, - ], - version: '', - isActive: false, - path: '', - contextFiles: [], - id: '', - }, - }, - false, - EMPTY_CONFIG, - ); - - const callArgs = mockedTransport.mock.calls[0][0]; - expect(callArgs.env).toBeDefined(); - expect(callArgs.env!['GEMINI_CLI_EXT_VAR']).toBe('ext-value'); - }); - it('should exclude extension settings with undefined values from environment', async () => { const mockedTransport = vi .spyOn(SdkClientStdioLib, 'StdioClientTransport') diff --git a/packages/core/src/tools/mcp-client.ts b/packages/core/src/tools/mcp-client.ts index c069f7a211..2588d54dba 100644 --- a/packages/core/src/tools/mcp-client.ts +++ b/packages/core/src/tools/mcp-client.ts @@ -34,11 +34,7 @@ import { } from '@modelcontextprotocol/sdk/types.js'; import { ApprovalMode, PolicyDecision } from '../policy/types.js'; import { parse } from 'shell-quote'; -import type { - Config, - GeminiCLIExtension, - MCPServerConfig, -} from '../config/config.js'; +import type { Config, MCPServerConfig } from '../config/config.js'; import { AuthProviderType } from '../config/config.js'; import { GoogleCredentialProvider } from '../mcp/google-auth-provider.js'; import { ServiceAccountImpersonationProvider } from '../mcp/sa-impersonation-provider.js'; @@ -1902,23 +1898,10 @@ export async function createTransport( command: mcpServerConfig.command, args: mcpServerConfig.args || [], // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion - env: sanitizeEnvironment( - { - ...process.env, - ...getExtensionEnvironment(mcpServerConfig.extension), - ...(mcpServerConfig.env || {}), - }, - { - ...sanitizationConfig, - allowedEnvironmentVariables: [ - ...(sanitizationConfig.allowedEnvironmentVariables ?? []), - ...(mcpServerConfig.extension?.resolvedSettings?.map( - (s) => s.envVar, - ) ?? []), - ], - enableEnvironmentVariableRedaction: true, - }, - ) as Record, + env: { + ...sanitizeEnvironment(process.env, sanitizationConfig), + ...(mcpServerConfig.env || {}), + } as Record, cwd: mcpServerConfig.cwd, stderr: 'pipe', }); @@ -1993,17 +1976,3 @@ export function isEnabled( ) ); } - -function getExtensionEnvironment( - extension?: GeminiCLIExtension, -): Record { - const env: Record = {}; - if (extension?.resolvedSettings) { - for (const setting of extension.resolvedSettings) { - if (setting.value) { - env[setting.envVar] = setting.value; - } - } - } - return env; -} From bfa791e13d11501b2c93ae1e1864be14f86b43ba Mon Sep 17 00:00:00 2001 From: Sandy Tao Date: Wed, 11 Feb 2026 12:20:14 -0800 Subject: [PATCH 03/44] feat(core): update internal utility models to Gemini 3 (#18773) --- docs/get-started/configuration.md | 22 +++++---- .../availability/fallbackIntegration.test.ts | 6 +-- .../src/availability/policyHelpers.test.ts | 13 +++++ .../core/src/availability/policyHelpers.ts | 32 +++++++++---- .../core/src/config/defaultModelConfigs.ts | 22 +++++---- .../resolved-aliases-retry.golden.json | 23 +++++---- .../test-data/resolved-aliases.golden.json | 23 +++++---- schemas/settings.schema.json | 48 ++++++++++++------- 8 files changed, 128 insertions(+), 61 deletions(-) diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 84818a59be..263dd815a8 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -447,6 +447,12 @@ their corresponding top-level category object in your `settings.json` file. "model": "gemini-2.5-flash" } }, + "gemini-3-flash-base": { + "extends": "base", + "modelConfig": { + "model": "gemini-3-flash-preview" + } + }, "classifier": { "extends": "base", "modelConfig": { @@ -502,7 +508,7 @@ their corresponding top-level category object in your `settings.json` file. } }, "web-search": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": { "generateContentConfig": { "tools": [ @@ -514,7 +520,7 @@ their corresponding top-level category object in your `settings.json` file. } }, "web-fetch": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": { "generateContentConfig": { "tools": [ @@ -526,25 +532,25 @@ their corresponding top-level category object in your `settings.json` file. } }, "web-fetch-fallback": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "loop-detection": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "loop-detection-double-check": { "extends": "base", "modelConfig": { - "model": "gemini-2.5-pro" + "model": "gemini-3-pro-preview" } }, "llm-edit-fixer": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "next-speaker-checker": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "chat-compression-3-pro": { @@ -574,7 +580,7 @@ their corresponding top-level category object in your `settings.json` file. }, "chat-compression-default": { "modelConfig": { - "model": "gemini-2.5-pro" + "model": "gemini-3-pro-preview" } } } diff --git a/packages/core/src/availability/fallbackIntegration.test.ts b/packages/core/src/availability/fallbackIntegration.test.ts index 55f9ac800f..f9de1f3b2b 100644 --- a/packages/core/src/availability/fallbackIntegration.test.ts +++ b/packages/core/src/availability/fallbackIntegration.test.ts @@ -58,7 +58,7 @@ describe('Fallback Integration', () => { ); }); - it('should NOT fallback if config is NOT in AUTO mode', () => { + it('should fallback for Gemini 3 models even if config is NOT in AUTO mode', () => { // 1. Config is explicitly set to Pro, not Auto vi.spyOn(config, 'getModel').mockReturnValue(PREVIEW_GEMINI_MODEL); @@ -71,7 +71,7 @@ describe('Fallback Integration', () => { // 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); + // 5. Expect it to fallback to Flash (because Gemini 3 uses PREVIEW_CHAIN) + expect(result.model).toBe(PREVIEW_GEMINI_FLASH_MODEL); }); }); diff --git a/packages/core/src/availability/policyHelpers.test.ts b/packages/core/src/availability/policyHelpers.test.ts index 4e923f638e..298f17eb74 100644 --- a/packages/core/src/availability/policyHelpers.test.ts +++ b/packages/core/src/availability/policyHelpers.test.ts @@ -115,6 +115,19 @@ describe('policyHelpers', () => { expect(chain[0]?.model).toBe('gemini-2.5-flash'); expect(chain[1]?.model).toBe('gemini-2.5-pro'); }); + + it('proactively returns Gemini 2.5 chain if Gemini 3 requested but user lacks access', () => { + const config = createMockConfig({ + getModel: () => 'auto-gemini-3', + getHasAccessToPreviewModel: () => false, + }); + const chain = resolvePolicyChain(config); + + // Should downgrade to [Pro 2.5, Flash 2.5] + expect(chain).toHaveLength(2); + expect(chain[0]?.model).toBe('gemini-2.5-pro'); + expect(chain[1]?.model).toBe('gemini-2.5-flash'); + }); }); describe('buildFallbackPolicyContext', () => { diff --git a/packages/core/src/availability/policyHelpers.ts b/packages/core/src/availability/policyHelpers.ts index 4d65b84d77..569157561f 100644 --- a/packages/core/src/availability/policyHelpers.ts +++ b/packages/core/src/availability/policyHelpers.ts @@ -24,6 +24,7 @@ import { DEFAULT_GEMINI_MODEL, PREVIEW_GEMINI_MODEL_AUTO, isAutoModel, + isGemini3Model, resolveModel, } from '../config/models.js'; import type { ModelSelectionResult } from './modelAvailabilityService.js'; @@ -46,17 +47,32 @@ export function resolvePolicyChain( const resolvedModel = resolveModel(modelFromConfig); const isAutoPreferred = preferredModel ? isAutoModel(preferredModel) : false; const isAutoConfigured = isAutoModel(configuredModel); + const hasAccessToPreview = config.getHasAccessToPreviewModel?.() ?? true; if (resolvedModel === DEFAULT_GEMINI_FLASH_LITE_MODEL) { chain = getFlashLitePolicyChain(); - } else if (isAutoPreferred || isAutoConfigured) { - const previewEnabled = - preferredModel === PREVIEW_GEMINI_MODEL_AUTO || - configuredModel === PREVIEW_GEMINI_MODEL_AUTO; - chain = getModelPolicyChain({ - previewEnabled, - userTier: config.getUserTier(), - }); + } else if ( + isGemini3Model(resolvedModel) || + isAutoPreferred || + isAutoConfigured + ) { + if (hasAccessToPreview) { + const previewEnabled = + isGemini3Model(resolvedModel) || + preferredModel === PREVIEW_GEMINI_MODEL_AUTO || + configuredModel === PREVIEW_GEMINI_MODEL_AUTO; + chain = getModelPolicyChain({ + previewEnabled, + userTier: config.getUserTier(), + }); + } else { + // User requested Gemini 3 but has no access. Proactively downgrade + // to the stable Gemini 2.5 chain. + return getModelPolicyChain({ + previewEnabled: false, + userTier: config.getUserTier(), + }); + } } else { chain = createSingleModelChain(modelFromConfig); } diff --git a/packages/core/src/config/defaultModelConfigs.ts b/packages/core/src/config/defaultModelConfigs.ts index 773223dc0c..c0424de9e3 100644 --- a/packages/core/src/config/defaultModelConfigs.ts +++ b/packages/core/src/config/defaultModelConfigs.ts @@ -96,6 +96,12 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = { model: 'gemini-2.5-flash', }, }, + 'gemini-3-flash-base': { + extends: 'base', + modelConfig: { + model: 'gemini-3-flash-preview', + }, + }, classifier: { extends: 'base', modelConfig: { @@ -151,7 +157,7 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = { }, }, 'web-search': { - extends: 'gemini-2.5-flash-base', + extends: 'gemini-3-flash-base', modelConfig: { generateContentConfig: { tools: [{ googleSearch: {} }], @@ -159,7 +165,7 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = { }, }, 'web-fetch': { - extends: 'gemini-2.5-flash-base', + extends: 'gemini-3-flash-base', modelConfig: { generateContentConfig: { tools: [{ urlContext: {} }], @@ -168,25 +174,25 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = { }, // TODO(joshualitt): During cleanup, make modelConfig optional. 'web-fetch-fallback': { - extends: 'gemini-2.5-flash-base', + extends: 'gemini-3-flash-base', modelConfig: {}, }, 'loop-detection': { - extends: 'gemini-2.5-flash-base', + extends: 'gemini-3-flash-base', modelConfig: {}, }, 'loop-detection-double-check': { extends: 'base', modelConfig: { - model: 'gemini-2.5-pro', + model: 'gemini-3-pro-preview', }, }, 'llm-edit-fixer': { - extends: 'gemini-2.5-flash-base', + extends: 'gemini-3-flash-base', modelConfig: {}, }, 'next-speaker-checker': { - extends: 'gemini-2.5-flash-base', + extends: 'gemini-3-flash-base', modelConfig: {}, }, 'chat-compression-3-pro': { @@ -216,7 +222,7 @@ export const DEFAULT_MODEL_CONFIGS: ModelConfigServiceConfig = { }, 'chat-compression-default': { modelConfig: { - model: 'gemini-2.5-pro', + model: 'gemini-3-pro-preview', }, }, }, diff --git a/packages/core/src/services/test-data/resolved-aliases-retry.golden.json b/packages/core/src/services/test-data/resolved-aliases-retry.golden.json index 3b38b909d8..9bfd252b88 100644 --- a/packages/core/src/services/test-data/resolved-aliases-retry.golden.json +++ b/packages/core/src/services/test-data/resolved-aliases-retry.golden.json @@ -104,6 +104,13 @@ "topP": 1 } }, + "gemini-3-flash-base": { + "model": "gemini-3-flash-preview", + "generateContentConfig": { + "temperature": 0, + "topP": 1 + } + }, "classifier": { "model": "gemini-2.5-flash-lite", "generateContentConfig": { @@ -153,7 +160,7 @@ } }, "web-search": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1, @@ -165,7 +172,7 @@ } }, "web-fetch": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1, @@ -177,35 +184,35 @@ } }, "web-fetch-fallback": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1 } }, "loop-detection": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1 } }, "loop-detection-double-check": { - "model": "gemini-2.5-pro", + "model": "gemini-3-pro-preview", "generateContentConfig": { "temperature": 0, "topP": 1 } }, "llm-edit-fixer": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1 } }, "next-speaker-checker": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1 @@ -232,7 +239,7 @@ "generateContentConfig": {} }, "chat-compression-default": { - "model": "gemini-2.5-pro", + "model": "gemini-3-pro-preview", "generateContentConfig": {} } } diff --git a/packages/core/src/services/test-data/resolved-aliases.golden.json b/packages/core/src/services/test-data/resolved-aliases.golden.json index 3b38b909d8..9bfd252b88 100644 --- a/packages/core/src/services/test-data/resolved-aliases.golden.json +++ b/packages/core/src/services/test-data/resolved-aliases.golden.json @@ -104,6 +104,13 @@ "topP": 1 } }, + "gemini-3-flash-base": { + "model": "gemini-3-flash-preview", + "generateContentConfig": { + "temperature": 0, + "topP": 1 + } + }, "classifier": { "model": "gemini-2.5-flash-lite", "generateContentConfig": { @@ -153,7 +160,7 @@ } }, "web-search": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1, @@ -165,7 +172,7 @@ } }, "web-fetch": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1, @@ -177,35 +184,35 @@ } }, "web-fetch-fallback": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1 } }, "loop-detection": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1 } }, "loop-detection-double-check": { - "model": "gemini-2.5-pro", + "model": "gemini-3-pro-preview", "generateContentConfig": { "temperature": 0, "topP": 1 } }, "llm-edit-fixer": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1 } }, "next-speaker-checker": { - "model": "gemini-2.5-flash", + "model": "gemini-3-flash-preview", "generateContentConfig": { "temperature": 0, "topP": 1 @@ -232,7 +239,7 @@ "generateContentConfig": {} }, "chat-compression-default": { - "model": "gemini-2.5-pro", + "model": "gemini-3-pro-preview", "generateContentConfig": {} } } diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index dd2702e712..06ad037929 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -514,7 +514,7 @@ "modelConfigs": { "title": "Model Configs", "description": "Model configurations.", - "markdownDescription": "Model configurations.\n\n- Category: `Model`\n- Requires restart: `no`\n- Default: `{\n \"aliases\": {\n \"base\": {\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"temperature\": 0,\n \"topP\": 1\n }\n }\n },\n \"chat-base\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"includeThoughts\": true\n },\n \"temperature\": 1,\n \"topP\": 0.95,\n \"topK\": 64\n }\n }\n },\n \"chat-base-2.5\": {\n \"extends\": \"chat-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingBudget\": 8192\n }\n }\n }\n },\n \"chat-base-3\": {\n \"extends\": \"chat-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingLevel\": \"HIGH\"\n }\n }\n }\n },\n \"gemini-3-pro-preview\": {\n \"extends\": \"chat-base-3\",\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n },\n \"gemini-3-flash-preview\": {\n \"extends\": \"chat-base-3\",\n \"modelConfig\": {\n \"model\": \"gemini-3-flash-preview\"\n }\n },\n \"gemini-2.5-pro\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n },\n \"gemini-2.5-flash\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"gemini-2.5-flash-lite\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\"\n }\n },\n \"gemini-2.5-flash-base\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"classifier\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 1024,\n \"thinkingConfig\": {\n \"thinkingBudget\": 512\n }\n }\n }\n },\n \"prompt-completion\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"temperature\": 0.3,\n \"maxOutputTokens\": 16000,\n \"thinkingConfig\": {\n \"thinkingBudget\": 0\n }\n }\n }\n },\n \"edit-corrector\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingBudget\": 0\n }\n }\n }\n },\n \"summarizer-default\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 2000\n }\n }\n },\n \"summarizer-shell\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 2000\n }\n }\n },\n \"web-search\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"tools\": [\n {\n \"googleSearch\": {}\n }\n ]\n }\n }\n },\n \"web-fetch\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"tools\": [\n {\n \"urlContext\": {}\n }\n ]\n }\n }\n },\n \"web-fetch-fallback\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {}\n },\n \"loop-detection\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {}\n },\n \"loop-detection-double-check\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n },\n \"llm-edit-fixer\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {}\n },\n \"next-speaker-checker\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {}\n },\n \"chat-compression-3-pro\": {\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n },\n \"chat-compression-3-flash\": {\n \"modelConfig\": {\n \"model\": \"gemini-3-flash-preview\"\n }\n },\n \"chat-compression-2.5-pro\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n },\n \"chat-compression-2.5-flash\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"chat-compression-2.5-flash-lite\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\"\n }\n },\n \"chat-compression-default\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n }\n },\n \"overrides\": [\n {\n \"match\": {\n \"model\": \"chat-base\",\n \"isRetry\": true\n },\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"temperature\": 1\n }\n }\n }\n ]\n}`", + "markdownDescription": "Model configurations.\n\n- Category: `Model`\n- Requires restart: `no`\n- Default: `{\n \"aliases\": {\n \"base\": {\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"temperature\": 0,\n \"topP\": 1\n }\n }\n },\n \"chat-base\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"includeThoughts\": true\n },\n \"temperature\": 1,\n \"topP\": 0.95,\n \"topK\": 64\n }\n }\n },\n \"chat-base-2.5\": {\n \"extends\": \"chat-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingBudget\": 8192\n }\n }\n }\n },\n \"chat-base-3\": {\n \"extends\": \"chat-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingLevel\": \"HIGH\"\n }\n }\n }\n },\n \"gemini-3-pro-preview\": {\n \"extends\": \"chat-base-3\",\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n },\n \"gemini-3-flash-preview\": {\n \"extends\": \"chat-base-3\",\n \"modelConfig\": {\n \"model\": \"gemini-3-flash-preview\"\n }\n },\n \"gemini-2.5-pro\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n },\n \"gemini-2.5-flash\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"gemini-2.5-flash-lite\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\"\n }\n },\n \"gemini-2.5-flash-base\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"gemini-3-flash-base\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-3-flash-preview\"\n }\n },\n \"classifier\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 1024,\n \"thinkingConfig\": {\n \"thinkingBudget\": 512\n }\n }\n }\n },\n \"prompt-completion\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"temperature\": 0.3,\n \"maxOutputTokens\": 16000,\n \"thinkingConfig\": {\n \"thinkingBudget\": 0\n }\n }\n }\n },\n \"edit-corrector\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingBudget\": 0\n }\n }\n }\n },\n \"summarizer-default\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 2000\n }\n }\n },\n \"summarizer-shell\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 2000\n }\n }\n },\n \"web-search\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"tools\": [\n {\n \"googleSearch\": {}\n }\n ]\n }\n }\n },\n \"web-fetch\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"tools\": [\n {\n \"urlContext\": {}\n }\n ]\n }\n }\n },\n \"web-fetch-fallback\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {}\n },\n \"loop-detection\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {}\n },\n \"loop-detection-double-check\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n },\n \"llm-edit-fixer\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {}\n },\n \"next-speaker-checker\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {}\n },\n \"chat-compression-3-pro\": {\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n },\n \"chat-compression-3-flash\": {\n \"modelConfig\": {\n \"model\": \"gemini-3-flash-preview\"\n }\n },\n \"chat-compression-2.5-pro\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n },\n \"chat-compression-2.5-flash\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"chat-compression-2.5-flash-lite\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\"\n }\n },\n \"chat-compression-default\": {\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n }\n },\n \"overrides\": [\n {\n \"match\": {\n \"model\": \"chat-base\",\n \"isRetry\": true\n },\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"temperature\": 1\n }\n }\n }\n ]\n}`", "default": { "aliases": { "base": { @@ -594,6 +594,12 @@ "model": "gemini-2.5-flash" } }, + "gemini-3-flash-base": { + "extends": "base", + "modelConfig": { + "model": "gemini-3-flash-preview" + } + }, "classifier": { "extends": "base", "modelConfig": { @@ -649,7 +655,7 @@ } }, "web-search": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": { "generateContentConfig": { "tools": [ @@ -661,7 +667,7 @@ } }, "web-fetch": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": { "generateContentConfig": { "tools": [ @@ -673,25 +679,25 @@ } }, "web-fetch-fallback": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "loop-detection": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "loop-detection-double-check": { "extends": "base", "modelConfig": { - "model": "gemini-2.5-pro" + "model": "gemini-3-pro-preview" } }, "llm-edit-fixer": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "next-speaker-checker": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "chat-compression-3-pro": { @@ -721,7 +727,7 @@ }, "chat-compression-default": { "modelConfig": { - "model": "gemini-2.5-pro" + "model": "gemini-3-pro-preview" } } }, @@ -744,7 +750,7 @@ "aliases": { "title": "Model Config Aliases", "description": "Named presets for model configs. Can be used in place of a model name and can inherit from other aliases using an `extends` property.", - "markdownDescription": "Named presets for model configs. Can be used in place of a model name and can inherit from other aliases using an `extends` property.\n\n- Category: `Model`\n- Requires restart: `no`\n- Default: `{\n \"base\": {\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"temperature\": 0,\n \"topP\": 1\n }\n }\n },\n \"chat-base\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"includeThoughts\": true\n },\n \"temperature\": 1,\n \"topP\": 0.95,\n \"topK\": 64\n }\n }\n },\n \"chat-base-2.5\": {\n \"extends\": \"chat-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingBudget\": 8192\n }\n }\n }\n },\n \"chat-base-3\": {\n \"extends\": \"chat-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingLevel\": \"HIGH\"\n }\n }\n }\n },\n \"gemini-3-pro-preview\": {\n \"extends\": \"chat-base-3\",\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n },\n \"gemini-3-flash-preview\": {\n \"extends\": \"chat-base-3\",\n \"modelConfig\": {\n \"model\": \"gemini-3-flash-preview\"\n }\n },\n \"gemini-2.5-pro\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n },\n \"gemini-2.5-flash\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"gemini-2.5-flash-lite\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\"\n }\n },\n \"gemini-2.5-flash-base\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"classifier\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 1024,\n \"thinkingConfig\": {\n \"thinkingBudget\": 512\n }\n }\n }\n },\n \"prompt-completion\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"temperature\": 0.3,\n \"maxOutputTokens\": 16000,\n \"thinkingConfig\": {\n \"thinkingBudget\": 0\n }\n }\n }\n },\n \"edit-corrector\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingBudget\": 0\n }\n }\n }\n },\n \"summarizer-default\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 2000\n }\n }\n },\n \"summarizer-shell\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 2000\n }\n }\n },\n \"web-search\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"tools\": [\n {\n \"googleSearch\": {}\n }\n ]\n }\n }\n },\n \"web-fetch\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"tools\": [\n {\n \"urlContext\": {}\n }\n ]\n }\n }\n },\n \"web-fetch-fallback\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {}\n },\n \"loop-detection\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {}\n },\n \"loop-detection-double-check\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n },\n \"llm-edit-fixer\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {}\n },\n \"next-speaker-checker\": {\n \"extends\": \"gemini-2.5-flash-base\",\n \"modelConfig\": {}\n },\n \"chat-compression-3-pro\": {\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n },\n \"chat-compression-3-flash\": {\n \"modelConfig\": {\n \"model\": \"gemini-3-flash-preview\"\n }\n },\n \"chat-compression-2.5-pro\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n },\n \"chat-compression-2.5-flash\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"chat-compression-2.5-flash-lite\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\"\n }\n },\n \"chat-compression-default\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n }\n}`", + "markdownDescription": "Named presets for model configs. Can be used in place of a model name and can inherit from other aliases using an `extends` property.\n\n- Category: `Model`\n- Requires restart: `no`\n- Default: `{\n \"base\": {\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"temperature\": 0,\n \"topP\": 1\n }\n }\n },\n \"chat-base\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"includeThoughts\": true\n },\n \"temperature\": 1,\n \"topP\": 0.95,\n \"topK\": 64\n }\n }\n },\n \"chat-base-2.5\": {\n \"extends\": \"chat-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingBudget\": 8192\n }\n }\n }\n },\n \"chat-base-3\": {\n \"extends\": \"chat-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingLevel\": \"HIGH\"\n }\n }\n }\n },\n \"gemini-3-pro-preview\": {\n \"extends\": \"chat-base-3\",\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n },\n \"gemini-3-flash-preview\": {\n \"extends\": \"chat-base-3\",\n \"modelConfig\": {\n \"model\": \"gemini-3-flash-preview\"\n }\n },\n \"gemini-2.5-pro\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n },\n \"gemini-2.5-flash\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"gemini-2.5-flash-lite\": {\n \"extends\": \"chat-base-2.5\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\"\n }\n },\n \"gemini-2.5-flash-base\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"gemini-3-flash-base\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-3-flash-preview\"\n }\n },\n \"classifier\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 1024,\n \"thinkingConfig\": {\n \"thinkingBudget\": 512\n }\n }\n }\n },\n \"prompt-completion\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"temperature\": 0.3,\n \"maxOutputTokens\": 16000,\n \"thinkingConfig\": {\n \"thinkingBudget\": 0\n }\n }\n }\n },\n \"edit-corrector\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"thinkingConfig\": {\n \"thinkingBudget\": 0\n }\n }\n }\n },\n \"summarizer-default\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 2000\n }\n }\n },\n \"summarizer-shell\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\",\n \"generateContentConfig\": {\n \"maxOutputTokens\": 2000\n }\n }\n },\n \"web-search\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"tools\": [\n {\n \"googleSearch\": {}\n }\n ]\n }\n }\n },\n \"web-fetch\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {\n \"generateContentConfig\": {\n \"tools\": [\n {\n \"urlContext\": {}\n }\n ]\n }\n }\n },\n \"web-fetch-fallback\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {}\n },\n \"loop-detection\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {}\n },\n \"loop-detection-double-check\": {\n \"extends\": \"base\",\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n },\n \"llm-edit-fixer\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {}\n },\n \"next-speaker-checker\": {\n \"extends\": \"gemini-3-flash-base\",\n \"modelConfig\": {}\n },\n \"chat-compression-3-pro\": {\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n },\n \"chat-compression-3-flash\": {\n \"modelConfig\": {\n \"model\": \"gemini-3-flash-preview\"\n }\n },\n \"chat-compression-2.5-pro\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-pro\"\n }\n },\n \"chat-compression-2.5-flash\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash\"\n }\n },\n \"chat-compression-2.5-flash-lite\": {\n \"modelConfig\": {\n \"model\": \"gemini-2.5-flash-lite\"\n }\n },\n \"chat-compression-default\": {\n \"modelConfig\": {\n \"model\": \"gemini-3-pro-preview\"\n }\n }\n}`", "default": { "base": { "modelConfig": { @@ -823,6 +829,12 @@ "model": "gemini-2.5-flash" } }, + "gemini-3-flash-base": { + "extends": "base", + "modelConfig": { + "model": "gemini-3-flash-preview" + } + }, "classifier": { "extends": "base", "modelConfig": { @@ -878,7 +890,7 @@ } }, "web-search": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": { "generateContentConfig": { "tools": [ @@ -890,7 +902,7 @@ } }, "web-fetch": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": { "generateContentConfig": { "tools": [ @@ -902,25 +914,25 @@ } }, "web-fetch-fallback": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "loop-detection": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "loop-detection-double-check": { "extends": "base", "modelConfig": { - "model": "gemini-2.5-pro" + "model": "gemini-3-pro-preview" } }, "llm-edit-fixer": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "next-speaker-checker": { - "extends": "gemini-2.5-flash-base", + "extends": "gemini-3-flash-base", "modelConfig": {} }, "chat-compression-3-pro": { @@ -950,7 +962,7 @@ }, "chat-compression-default": { "modelConfig": { - "model": "gemini-2.5-pro" + "model": "gemini-3-pro-preview" } } }, From 4138667bae4259169114d4911fafa8496cc42a36 Mon Sep 17 00:00:00 2001 From: Adam Weidman <65992621+adamfweidman@users.noreply.github.com> Date: Wed, 11 Feb 2026 16:23:28 -0500 Subject: [PATCH 04/44] feat(a2a): add value-resolver for auth credential resolution (#18653) --- packages/core/src/agents/agentLoader.test.ts | 167 ++++++++++++++++++ packages/core/src/agents/agentLoader.ts | 153 ++++++++++++++++ .../src/agents/auth-provider/base-provider.ts | 29 ++- .../auth-provider/value-resolver.test.ts | 136 ++++++++++++++ .../agents/auth-provider/value-resolver.ts | 102 +++++++++++ 5 files changed, 583 insertions(+), 4 deletions(-) create mode 100644 packages/core/src/agents/auth-provider/value-resolver.test.ts create mode 100644 packages/core/src/agents/auth-provider/value-resolver.ts diff --git a/packages/core/src/agents/agentLoader.test.ts b/packages/core/src/agents/agentLoader.test.ts index 3649558b64..a54626b637 100644 --- a/packages/core/src/agents/agentLoader.test.ts +++ b/packages/core/src/agents/agentLoader.test.ts @@ -363,4 +363,171 @@ Hidden`, expect(result.errors).toHaveLength(1); }); }); + + describe('remote agent auth configuration', () => { + it('should parse remote agent with apiKey auth', async () => { + const filePath = await writeAgentMarkdown(`--- +kind: remote +name: api-key-agent +agent_card_url: https://example.com/card +auth: + type: apiKey + key: $MY_API_KEY + in: header + name: X-Custom-Key +--- +`); + const result = await parseAgentMarkdown(filePath); + expect(result).toHaveLength(1); + expect(result[0]).toMatchObject({ + kind: 'remote', + name: 'api-key-agent', + auth: { + type: 'apiKey', + key: '$MY_API_KEY', + in: 'header', + name: 'X-Custom-Key', + }, + }); + }); + + it('should parse remote agent with http Bearer auth', async () => { + const filePath = await writeAgentMarkdown(`--- +kind: remote +name: bearer-agent +agent_card_url: https://example.com/card +auth: + type: http + scheme: Bearer + token: $BEARER_TOKEN +--- +`); + const result = await parseAgentMarkdown(filePath); + expect(result).toHaveLength(1); + expect(result[0]).toMatchObject({ + kind: 'remote', + name: 'bearer-agent', + auth: { + type: 'http', + scheme: 'Bearer', + token: '$BEARER_TOKEN', + }, + }); + }); + + it('should parse remote agent with http Basic auth', async () => { + const filePath = await writeAgentMarkdown(`--- +kind: remote +name: basic-agent +agent_card_url: https://example.com/card +auth: + type: http + scheme: Basic + username: $AUTH_USER + password: $AUTH_PASS +--- +`); + const result = await parseAgentMarkdown(filePath); + expect(result).toHaveLength(1); + expect(result[0]).toMatchObject({ + kind: 'remote', + name: 'basic-agent', + auth: { + type: 'http', + scheme: 'Basic', + username: '$AUTH_USER', + password: '$AUTH_PASS', + }, + }); + }); + + it('should throw error for Bearer auth without token', async () => { + const filePath = await writeAgentMarkdown(`--- +kind: remote +name: invalid-bearer +agent_card_url: https://example.com/card +auth: + type: http + scheme: Bearer +--- +`); + await expect(parseAgentMarkdown(filePath)).rejects.toThrow( + /Bearer scheme requires "token"/, + ); + }); + + it('should throw error for Basic auth without credentials', async () => { + const filePath = await writeAgentMarkdown(`--- +kind: remote +name: invalid-basic +agent_card_url: https://example.com/card +auth: + type: http + scheme: Basic + username: user +--- +`); + await expect(parseAgentMarkdown(filePath)).rejects.toThrow( + /Basic scheme requires "username" and "password"/, + ); + }); + + it('should throw error for apiKey auth without key', async () => { + const filePath = await writeAgentMarkdown(`--- +kind: remote +name: invalid-apikey +agent_card_url: https://example.com/card +auth: + type: apiKey +--- +`); + await expect(parseAgentMarkdown(filePath)).rejects.toThrow( + /auth\.key.*Required/, + ); + }); + + it('should convert auth config in markdownToAgentDefinition', () => { + const markdown = { + kind: 'remote' as const, + name: 'auth-agent', + agent_card_url: 'https://example.com/card', + auth: { + type: 'apiKey' as const, + key: '$API_KEY', + in: 'header' as const, + }, + }; + + const result = markdownToAgentDefinition(markdown); + expect(result).toMatchObject({ + kind: 'remote', + name: 'auth-agent', + auth: { + type: 'apiKey', + key: '$API_KEY', + location: 'header', + }, + }); + }); + + it('should parse auth with agent_card_requires_auth flag', async () => { + const filePath = await writeAgentMarkdown(`--- +kind: remote +name: protected-card-agent +agent_card_url: https://example.com/card +auth: + type: apiKey + key: $MY_API_KEY + agent_card_requires_auth: true +--- +`); + const result = await parseAgentMarkdown(filePath); + expect(result[0]).toMatchObject({ + auth: { + type: 'apiKey', + agent_card_requires_auth: true, + }, + }); + }); + }); }); diff --git a/packages/core/src/agents/agentLoader.ts b/packages/core/src/agents/agentLoader.ts index 8d5e44b93c..cb2a605779 100644 --- a/packages/core/src/agents/agentLoader.ts +++ b/packages/core/src/agents/agentLoader.ts @@ -15,6 +15,7 @@ import { DEFAULT_MAX_TURNS, DEFAULT_MAX_TIME_MINUTES, } from './types.js'; +import type { A2AAuthConfig } from './auth-provider/types.js'; import { isValidToolName } from '../tools/tool-names.js'; import { FRONTMATTER_REGEX } from '../skills/skillLoader.js'; import { getErrorMessage } from '../utils/errors.js'; @@ -39,11 +40,29 @@ interface FrontmatterLocalAgentDefinition timeout_mins?: number; } +/** + * Authentication configuration for remote agents in frontmatter format. + */ +interface FrontmatterAuthConfig { + type: 'apiKey' | 'http'; + agent_card_requires_auth?: boolean; + // API Key + key?: string; + in?: 'header' | 'query' | 'cookie'; + name?: string; + // HTTP + scheme?: 'Bearer' | 'Basic'; + token?: string; + username?: string; + password?: string; +} + interface FrontmatterRemoteAgentDefinition extends FrontmatterBaseAgentDefinition { kind: 'remote'; description?: string; agent_card_url: string; + auth?: FrontmatterAuthConfig; } type FrontmatterAgentDefinition = @@ -95,6 +114,66 @@ const localAgentSchema = z }) .strict(); +/** + * Base fields shared by all auth configs. + */ +const baseAuthFields = { + agent_card_requires_auth: z.boolean().optional(), +}; + +/** + * API Key auth schema. + * Supports sending key in header, query parameter, or cookie. + */ +const apiKeyAuthSchema = z.object({ + ...baseAuthFields, + type: z.literal('apiKey'), + key: z.string().min(1, 'API key is required'), + in: z.enum(['header', 'query', 'cookie']).optional(), + name: z.string().optional(), +}); + +/** + * HTTP auth schema (Bearer or Basic). + * Note: Validation for scheme-specific fields is applied in authConfigSchema + * since discriminatedUnion doesn't support refined schemas directly. + */ +const httpAuthSchemaBase = z.object({ + ...baseAuthFields, + type: z.literal('http'), + scheme: z.enum(['Bearer', 'Basic']), + token: z.string().optional(), + username: z.string().optional(), + password: z.string().optional(), +}); + +/** + * Combined auth schema - discriminated union of all auth types. + * Note: We use the base schema for discriminatedUnion, then apply refinements + * via superRefine since discriminatedUnion doesn't support refined schemas directly. + */ +const authConfigSchema = z + .discriminatedUnion('type', [apiKeyAuthSchema, httpAuthSchemaBase]) + .superRefine((data, ctx) => { + // Apply HTTP auth validation after union parsing + if (data.type === 'http') { + if (data.scheme === 'Bearer' && !data.token) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'Bearer scheme requires "token"', + path: ['token'], + }); + } + if (data.scheme === 'Basic' && (!data.username || !data.password)) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'Basic scheme requires "username" and "password"', + path: data.username ? ['password'] : ['username'], + }); + } + } + }); + const remoteAgentSchema = z .object({ kind: z.literal('remote').optional().default('remote'), @@ -102,6 +181,7 @@ const remoteAgentSchema = z description: z.string().optional(), display_name: z.string().optional(), agent_card_url: z.string().url(), + auth: authConfigSchema.optional(), }) .strict(); @@ -238,6 +318,76 @@ export async function parseAgentMarkdown( return [agentDef]; } +/** + * Converts frontmatter auth config to the internal A2AAuthConfig type. + * This handles the mapping from snake_case YAML to the internal type structure. + */ +function convertFrontmatterAuthToConfig( + frontmatter: FrontmatterAuthConfig, +): A2AAuthConfig { + const base = { + agent_card_requires_auth: frontmatter.agent_card_requires_auth, + }; + + switch (frontmatter.type) { + case 'apiKey': + if (!frontmatter.key) { + throw new Error('Internal error: API key missing after validation.'); + } + return { + ...base, + type: 'apiKey', + key: frontmatter.key, + location: frontmatter.in, + name: frontmatter.name, + }; + + case 'http': { + if (!frontmatter.scheme) { + throw new Error( + 'Internal error: HTTP scheme missing after validation.', + ); + } + switch (frontmatter.scheme) { + case 'Bearer': + if (!frontmatter.token) { + throw new Error( + 'Internal error: Bearer token missing after validation.', + ); + } + return { + ...base, + type: 'http', + scheme: 'Bearer', + token: frontmatter.token, + }; + case 'Basic': + if (!frontmatter.username || !frontmatter.password) { + throw new Error( + 'Internal error: Basic auth credentials missing after validation.', + ); + } + return { + ...base, + type: 'http', + scheme: 'Basic', + username: frontmatter.username, + password: frontmatter.password, + }; + default: { + const exhaustive: never = frontmatter.scheme; + throw new Error(`Unknown HTTP scheme: ${exhaustive}`); + } + } + } + + default: { + const exhaustive: never = frontmatter.type; + throw new Error(`Unknown auth type: ${exhaustive}`); + } + } +} + /** * Converts a FrontmatterAgentDefinition DTO to the internal AgentDefinition structure. * @@ -270,6 +420,9 @@ export function markdownToAgentDefinition( description: markdown.description || '(Loading description...)', displayName: markdown.display_name, agentCardUrl: markdown.agent_card_url, + auth: markdown.auth + ? convertFrontmatterAuthToConfig(markdown.auth) + : undefined, inputConfig, metadata, }; diff --git a/packages/core/src/agents/auth-provider/base-provider.ts b/packages/core/src/agents/auth-provider/base-provider.ts index 7b21853a09..7fb2e61acc 100644 --- a/packages/core/src/agents/auth-provider/base-provider.ts +++ b/packages/core/src/agents/auth-provider/base-provider.ts @@ -9,17 +9,33 @@ import type { A2AAuthProvider, A2AAuthProviderType } from './types.js'; /** * Abstract base class for A2A authentication providers. + * Provides default implementations for optional methods. */ export abstract class BaseA2AAuthProvider implements A2AAuthProvider { + /** + * The type of authentication provider. + */ abstract readonly type: A2AAuthProviderType; + + /** + * Get the HTTP headers to include in requests. + * Subclasses must implement this method. + */ abstract headers(): Promise; private static readonly MAX_AUTH_RETRIES = 2; private authRetryCount = 0; /** - * Default: retry on 401/403 with fresh headers. - * Subclasses with cached tokens must override to force-refresh to avoid infinite retries. + * Check if a request should be retried with new headers. + * + * The default implementation checks for 401/403 status codes and + * returns fresh headers for retry. Subclasses can override for + * custom retry logic. + * + * @param _req The original request init + * @param res The response from the server + * @returns New headers for retry, or undefined if no retry should be made */ async shouldRetryWithHeaders( _req: RequestInit, @@ -32,10 +48,15 @@ export abstract class BaseA2AAuthProvider implements A2AAuthProvider { this.authRetryCount++; return this.headers(); } - // Reset on success + // Reset count if not an auth error this.authRetryCount = 0; return undefined; } - async initialize(): Promise {} + /** + * Initialize the provider. Override in subclasses that need async setup. + */ + async initialize(): Promise { + // Default: no-op + } } diff --git a/packages/core/src/agents/auth-provider/value-resolver.test.ts b/packages/core/src/agents/auth-provider/value-resolver.test.ts new file mode 100644 index 0000000000..58aa84c077 --- /dev/null +++ b/packages/core/src/agents/auth-provider/value-resolver.test.ts @@ -0,0 +1,136 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, afterEach, vi } from 'vitest'; +import { + resolveAuthValue, + needsResolution, + maskSensitiveValue, +} from './value-resolver.js'; + +describe('value-resolver', () => { + describe('resolveAuthValue', () => { + describe('environment variables', () => { + afterEach(() => { + vi.unstubAllEnvs(); + }); + + it('should resolve environment variable with $ prefix', async () => { + vi.stubEnv('TEST_API_KEY', 'secret-key-123'); + const result = await resolveAuthValue('$TEST_API_KEY'); + expect(result).toBe('secret-key-123'); + }); + + it('should throw error for unset environment variable', async () => { + await expect(resolveAuthValue('$UNSET_VAR_12345')).rejects.toThrow( + "Environment variable 'UNSET_VAR_12345' is not set or is empty", + ); + }); + + it('should throw error for empty environment variable', async () => { + vi.stubEnv('EMPTY_VAR', ''); + await expect(resolveAuthValue('$EMPTY_VAR')).rejects.toThrow( + "Environment variable 'EMPTY_VAR' is not set or is empty", + ); + }); + }); + + describe('shell commands', () => { + it('should execute shell command with ! prefix', async () => { + const result = await resolveAuthValue('!echo hello'); + expect(result).toBe('hello'); + }); + + it('should trim whitespace from command output', async () => { + const result = await resolveAuthValue('!echo " hello "'); + expect(result).toBe('hello'); + }); + + it('should throw error for empty command', async () => { + await expect(resolveAuthValue('!')).rejects.toThrow( + 'Empty command in auth value', + ); + }); + + it('should throw error for command that returns empty output', async () => { + await expect(resolveAuthValue('!echo -n ""')).rejects.toThrow( + 'returned empty output', + ); + }); + + it('should throw error for failed command', async () => { + await expect( + resolveAuthValue('!nonexistent-command-12345'), + ).rejects.toThrow(/Command.*failed/); + }); + }); + + describe('literal values', () => { + it('should return literal value as-is', async () => { + const result = await resolveAuthValue('literal-api-key'); + expect(result).toBe('literal-api-key'); + }); + + it('should return empty string as-is', async () => { + const result = await resolveAuthValue(''); + expect(result).toBe(''); + }); + + it('should not treat values starting with other characters as special', async () => { + const result = await resolveAuthValue('api-key-123'); + expect(result).toBe('api-key-123'); + }); + }); + + describe('escaped literals', () => { + it('should return $ literal when value starts with $$', async () => { + const result = await resolveAuthValue('$$LITERAL'); + expect(result).toBe('$LITERAL'); + }); + + it('should return ! literal when value starts with !!', async () => { + const result = await resolveAuthValue('!!not-a-command'); + expect(result).toBe('!not-a-command'); + }); + }); + }); + + describe('needsResolution', () => { + it('should return true for environment variable reference', () => { + expect(needsResolution('$ENV_VAR')).toBe(true); + }); + + it('should return true for command reference', () => { + expect(needsResolution('!command')).toBe(true); + }); + + it('should return false for literal value', () => { + expect(needsResolution('literal')).toBe(false); + }); + + it('should return false for empty string', () => { + expect(needsResolution('')).toBe(false); + }); + }); + + describe('maskSensitiveValue', () => { + it('should mask value longer than 12 characters', () => { + expect(maskSensitiveValue('1234567890abcd')).toBe('12****cd'); + }); + + it('should return **** for short values', () => { + expect(maskSensitiveValue('short')).toBe('****'); + }); + + it('should return **** for exactly 12 characters', () => { + expect(maskSensitiveValue('123456789012')).toBe('****'); + }); + + it('should return **** for empty string', () => { + expect(maskSensitiveValue('')).toBe('****'); + }); + }); +}); diff --git a/packages/core/src/agents/auth-provider/value-resolver.ts b/packages/core/src/agents/auth-provider/value-resolver.ts new file mode 100644 index 0000000000..c349a57498 --- /dev/null +++ b/packages/core/src/agents/auth-provider/value-resolver.ts @@ -0,0 +1,102 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { debugLogger } from '../../utils/debugLogger.js'; +import { getShellConfiguration, spawnAsync } from '../../utils/shell-utils.js'; + +const COMMAND_TIMEOUT_MS = 60_000; + +/** + * Resolves a value that may be an environment variable reference, + * a shell command, or a literal value. + * + * Supported formats: + * - `$ENV_VAR`: Read from environment variable + * - `!command`: Execute shell command and use output (trimmed) + * - `$$` or `!!`: Escape prefix, returns rest as literal + * - Any other string: Use as literal value + * + * @param value The value to resolve + * @returns The resolved value + * @throws Error if environment variable is not set or command fails + */ +export async function resolveAuthValue(value: string): Promise { + // Support escaping with double prefix (e.g. $$ or !!). + // Strips one prefix char: $$FOO → $FOO, !!cmd → !cmd (literal, not resolved). + if (value.startsWith('$$') || value.startsWith('!!')) { + return value.slice(1); + } + + // Environment variable: $MY_VAR + if (value.startsWith('$')) { + const envVar = value.slice(1); + const resolved = process.env[envVar]; + if (resolved === undefined || resolved === '') { + throw new Error( + `Environment variable '${envVar}' is not set or is empty. ` + + `Please set it before using this agent.`, + ); + } + debugLogger.debug(`[AuthValueResolver] Resolved env var: ${envVar}`); + return resolved; + } + + // Shell command: !command arg1 arg2 + if (value.startsWith('!')) { + const command = value.slice(1).trim(); + if (!command) { + throw new Error('Empty command in auth value. Expected format: !command'); + } + + debugLogger.debug(`[AuthValueResolver] Executing command for auth value`); + + const shellConfig = getShellConfiguration(); + try { + const { stdout } = await spawnAsync( + shellConfig.executable, + [...shellConfig.argsPrefix, command], + { + signal: AbortSignal.timeout(COMMAND_TIMEOUT_MS), + windowsHide: true, + }, + ); + + const trimmed = stdout.trim(); + if (!trimmed) { + throw new Error(`Command '${command}' returned empty output`); + } + return trimmed; + } catch (error) { + if (error instanceof Error && error.name === 'AbortError') { + throw new Error( + `Command '${command}' timed out after ${COMMAND_TIMEOUT_MS / 1000} seconds`, + ); + } + throw error; + } + } + + // Literal value - return as-is + return value; +} + +/** + * Check if a value needs resolution (is an env var or command reference). + */ +export function needsResolution(value: string): boolean { + return value.startsWith('$') || value.startsWith('!'); +} + +/** + * Mask a sensitive value for logging purposes. + * Shows the first and last 2 characters with asterisks in between. + */ +export function maskSensitiveValue(value: string): string { + if (value.length <= 12) { + return '****'; + } + return `${value.slice(0, 2)}****${value.slice(-2)}`; +} From 00966062b82d552e703d2aec186e7b4ae0a16aac Mon Sep 17 00:00:00 2001 From: Dev Randalpura Date: Wed, 11 Feb 2026 13:47:02 -0800 Subject: [PATCH 05/44] Removed getPlainTextLength (#18848) --- .../ui/utils/InlineMarkdownRenderer.test.ts | 25 ------------------- .../src/ui/utils/InlineMarkdownRenderer.tsx | 17 ------------- 2 files changed, 42 deletions(-) delete mode 100644 packages/cli/src/ui/utils/InlineMarkdownRenderer.test.ts diff --git a/packages/cli/src/ui/utils/InlineMarkdownRenderer.test.ts b/packages/cli/src/ui/utils/InlineMarkdownRenderer.test.ts deleted file mode 100644 index 11fb6d56eb..0000000000 --- a/packages/cli/src/ui/utils/InlineMarkdownRenderer.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import { getPlainTextLength } from './InlineMarkdownRenderer.js'; -import { describe, it, expect } from 'vitest'; - -describe('getPlainTextLength', () => { - it.each([ - ['**Primary Go', 12], - ['*Primary Go', 11], - ['**Primary Go**', 10], - ['*Primary Go*', 10], - ['**', 2], - ['*', 1], - ['compile-time**', 14], - ])( - 'should measure markdown text length correctly for "%s"', - (input, expected) => { - expect(getPlainTextLength(input)).toBe(expected); - }, - ); -}); diff --git a/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx b/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx index 8d4c6a7da6..0418582919 100644 --- a/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx +++ b/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx @@ -7,7 +7,6 @@ import React from 'react'; import { Text } from 'ink'; import { theme } from '../semantic-colors.js'; -import stringWidth from 'string-width'; import { debugLogger } from '@google/gemini-cli-core'; // Constants for Markdown parsing @@ -171,19 +170,3 @@ const RenderInlineInternal: React.FC = ({ }; export const RenderInline = React.memo(RenderInlineInternal); - -/** - * Utility function to get the plain text length of a string with markdown formatting - * This is useful for calculating column widths in tables - */ -export const getPlainTextLength = (text: string): number => { - const cleanText = text - .replace(/\*\*(.*?)\*\*/g, '$1') - .replace(/\*(.+?)\*/g, '$1') - .replace(/_(.*?)_/g, '$1') - .replace(/~~(.*?)~~/g, '$1') - .replace(/`(.*?)`/g, '$1') - .replace(/(.*?)<\/u>/g, '$1') - .replace(/.*\[(.*?)\]\(.*\)/g, '$1'); - return stringWidth(cleanText); -}; From 6c1773170e952cc95dacd88e3d63996364527d34 Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Wed, 11 Feb 2026 21:55:27 +0000 Subject: [PATCH 06/44] More grep prompt tweaks (#18846) --- evals/frugalSearch.eval.ts | 36 ++++++++++------- .../core/__snapshots__/prompts.test.ts.snap | 39 ++++++++++++------- packages/core/src/prompts/snippets.ts | 3 +- 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/evals/frugalSearch.eval.ts b/evals/frugalSearch.eval.ts index e4f3e85956..11c51e8529 100644 --- a/evals/frugalSearch.eval.ts +++ b/evals/frugalSearch.eval.ts @@ -7,6 +7,11 @@ import { describe, expect } from 'vitest'; import { evalTest } from './test-helper.js'; +/** + * Evals to verify that the agent uses search tools efficiently (frugally) + * by utilizing limiting parameters like `total_max_matches` and `max_matches_per_file`. + * This ensures the agent doesn't flood the context window with unnecessary search results. + */ describe('Frugal Search', () => { const getGrepParams = (call: any): any => { let args = call.toolRequest.args; @@ -112,21 +117,26 @@ describe('Frugal Search', () => { expect(grepCalls.length).toBeGreaterThan(0); - const hasFrugalLimit = grepCalls.some((call) => { - const params = getGrepParams(call); - // Check for explicitly set small limit for "sample" or "example" requests - return ( - params.total_max_matches !== undefined && - params.total_max_matches <= 100 - ); - }); + const grepParams = grepCalls.map(getGrepParams); + const hasTotalMaxLimit = grepParams.some( + (p) => p.total_max_matches !== undefined && p.total_max_matches <= 100, + ); expect( - hasFrugalLimit, - `Expected agent to use a small total_max_matches for a sample usage request. Params used: ${JSON.stringify( - grepCalls.map(getGrepParams), - null, - 2, + hasTotalMaxLimit, + `Expected agent to use a small total_max_matches (<= 100) for a sample usage request. Actual values: ${JSON.stringify( + grepParams.map((p) => p.total_max_matches), + )}`, + ).toBe(true); + + const hasMaxMatchesPerFileLimit = grepParams.some( + (p) => + p.max_matches_per_file !== undefined && p.max_matches_per_file <= 5, + ); + expect( + hasMaxMatchesPerFileLimit, + `Expected agent to use a small max_matches_per_file (<= 5) for a sample usage request. Actual values: ${JSON.stringify( + grepParams.map((p) => p.max_matches_per_file), )}`, ).toBe(true); }, diff --git a/packages/core/src/core/__snapshots__/prompts.test.ts.snap b/packages/core/src/core/__snapshots__/prompts.test.ts.snap index c827d66ddc..e944565366 100644 --- a/packages/core/src/core/__snapshots__/prompts.test.ts.snap +++ b/packages/core/src/core/__snapshots__/prompts.test.ts.snap @@ -520,7 +520,8 @@ exports[`Core System Prompt (prompts.ts) > should append userMemory with separat - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -650,7 +651,8 @@ exports[`Core System Prompt (prompts.ts) > should handle CodebaseInvestigator wi - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -745,7 +747,8 @@ exports[`Core System Prompt (prompts.ts) > should handle CodebaseInvestigator wi - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -1309,7 +1312,8 @@ exports[`Core System Prompt (prompts.ts) > should include available_skills with - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -1435,7 +1439,8 @@ exports[`Core System Prompt (prompts.ts) > should include correct sandbox instru - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -1552,7 +1557,8 @@ exports[`Core System Prompt (prompts.ts) > should include correct sandbox instru - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -1669,7 +1675,8 @@ exports[`Core System Prompt (prompts.ts) > should include correct sandbox instru - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -1782,7 +1789,8 @@ exports[`Core System Prompt (prompts.ts) > should include planning phase suggest - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -1895,7 +1903,8 @@ exports[`Core System Prompt (prompts.ts) > should include sub-agents in XML for - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -2247,7 +2256,8 @@ exports[`Core System Prompt (prompts.ts) > should return the base prompt when us - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -2360,7 +2370,8 @@ exports[`Core System Prompt (prompts.ts) > should return the base prompt when us - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -2584,7 +2595,8 @@ exports[`Core System Prompt (prompts.ts) > should use chatty system prompt for p - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. @@ -2697,7 +2709,8 @@ exports[`Core System Prompt (prompts.ts) > should use chatty system prompt for p - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your grep_search searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in \`GEMINI.md\` files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. diff --git a/packages/core/src/prompts/snippets.ts b/packages/core/src/prompts/snippets.ts index f1b9f6dc12..3dcf346de6 100644 --- a/packages/core/src/prompts/snippets.ts +++ b/packages/core/src/prompts/snippets.ts @@ -165,7 +165,8 @@ export function renderCoreMandates(options?: CoreMandatesOptions): string { - **Source Control:** Do not stage or commit changes unless specifically requested by the user. ## Context Efficiency: -- Always minimize wasted context window by scoping and limiting all of your ${GREP_TOOL_NAME} searches. e.g.: pass total_max_matches, include, and max_matches_per_file. +- Always scope and limit your searches to avoid context window exhaustion and ensure high-signal results. Use include to target relevant files and strictly limit results using total_max_matches and max_matches_per_file, especially during the research phase. +- For broad discovery, use names_only=true or max_matches_per_file=1 to identify files without retrieving their context. ## Engineering Standards - **Contextual Precedence:** Instructions found in ${formattedFilenames} files are foundational mandates. They take absolute precedence over the general workflows and tool defaults described in this system prompt. From b8008695dbedc8d2e03de2d97c697a87e15c4fc9 Mon Sep 17 00:00:00 2001 From: Pyush Sinha Date: Wed, 11 Feb 2026 15:40:27 -0800 Subject: [PATCH 07/44] refactor(cli): Reactive useSettingsStore hook (#14915) --- packages/cli/src/config/settings.test.ts | 44 +++++ packages/cli/src/config/settings.ts | 48 +++++ .../src/ui/contexts/SettingsContext.test.tsx | 167 ++++++++++++++++++ .../cli/src/ui/contexts/SettingsContext.tsx | 70 +++++++- 4 files changed, 326 insertions(+), 3 deletions(-) create mode 100644 packages/cli/src/ui/contexts/SettingsContext.test.tsx diff --git a/packages/cli/src/config/settings.test.ts b/packages/cli/src/config/settings.test.ts index 721458952f..e88c9104dd 100644 --- a/packages/cli/src/config/settings.test.ts +++ b/packages/cli/src/config/settings.test.ts @@ -2546,6 +2546,50 @@ describe('Settings Loading and Merging', () => { }); }); + describe('Reactivity & Snapshots', () => { + let loadedSettings: LoadedSettings; + + beforeEach(() => { + const emptySettingsFile: SettingsFile = { + path: '/mock/path', + settings: {}, + originalSettings: {}, + }; + + loadedSettings = new LoadedSettings( + { ...emptySettingsFile, path: getSystemSettingsPath() }, + { ...emptySettingsFile, path: getSystemDefaultsPath() }, + { ...emptySettingsFile, path: USER_SETTINGS_PATH }, + { ...emptySettingsFile, path: MOCK_WORKSPACE_SETTINGS_PATH }, + true, // isTrusted + [], + ); + }); + + it('getSnapshot() should return stable reference if no changes occur', () => { + const snap1 = loadedSettings.getSnapshot(); + const snap2 = loadedSettings.getSnapshot(); + expect(snap1).toBe(snap2); + }); + + it('setValue() should create a new snapshot reference and emit event', () => { + const oldSnapshot = loadedSettings.getSnapshot(); + const oldUserRef = oldSnapshot.user.settings; + + loadedSettings.setValue(SettingScope.User, 'ui.theme', 'high-contrast'); + + const newSnapshot = loadedSettings.getSnapshot(); + + expect(newSnapshot).not.toBe(oldSnapshot); + expect(newSnapshot.user.settings).not.toBe(oldUserRef); + expect(newSnapshot.user.settings.ui?.theme).toBe('high-contrast'); + + expect(newSnapshot.system.settings).not.toBe(oldSnapshot.system.settings); + + expect(mockCoreEvents.emitSettingsChanged).toHaveBeenCalled(); + }); + }); + describe('Security and Sandbox', () => { let originalArgv: string[]; let originalEnv: NodeJS.ProcessEnv; diff --git a/packages/cli/src/config/settings.ts b/packages/cli/src/config/settings.ts index 8e9ff7380f..b2b526a010 100644 --- a/packages/cli/src/config/settings.ts +++ b/packages/cli/src/config/settings.ts @@ -10,6 +10,7 @@ import { platform } from 'node:os'; import * as dotenv from 'dotenv'; import process from 'node:process'; import { + CoreEvent, FatalConfigError, GEMINI_DIR, getErrorMessage, @@ -284,6 +285,20 @@ export function createTestMergedSettings( ) as MergedSettings; } +/** + * An immutable snapshot of settings state. + * Used with useSyncExternalStore for reactive updates. + */ +export interface LoadedSettingsSnapshot { + system: SettingsFile; + systemDefaults: SettingsFile; + user: SettingsFile; + workspace: SettingsFile; + isTrusted: boolean; + errors: SettingsError[]; + merged: MergedSettings; +} + export class LoadedSettings { constructor( system: SettingsFile, @@ -303,6 +318,7 @@ export class LoadedSettings { : this.createEmptyWorkspace(workspace); this.errors = errors; this._merged = this.computeMergedSettings(); + this._snapshot = this.computeSnapshot(); } readonly system: SettingsFile; @@ -314,6 +330,7 @@ export class LoadedSettings { private _workspaceFile: SettingsFile; private _merged: MergedSettings; + private _snapshot: LoadedSettingsSnapshot; private _remoteAdminSettings: Partial | undefined; get merged(): MergedSettings { @@ -368,6 +385,36 @@ export class LoadedSettings { return merged; } + private computeSnapshot(): LoadedSettingsSnapshot { + const cloneSettingsFile = (file: SettingsFile): SettingsFile => ({ + path: file.path, + rawJson: file.rawJson, + settings: structuredClone(file.settings), + originalSettings: structuredClone(file.originalSettings), + }); + return { + system: cloneSettingsFile(this.system), + systemDefaults: cloneSettingsFile(this.systemDefaults), + user: cloneSettingsFile(this.user), + workspace: cloneSettingsFile(this.workspace), + isTrusted: this.isTrusted, + errors: [...this.errors], + merged: structuredClone(this._merged), + }; + } + + // Passing this along with getSnapshot to useSyncExternalStore allows for idiomatic reactivity on settings changes + // React will pass a listener fn into this subscribe fn + // that listener fn will perform an object identity check on the snapshot and trigger a React re render if the snapshot has changed + subscribe(listener: () => void): () => void { + coreEvents.on(CoreEvent.SettingsChanged, listener); + return () => coreEvents.off(CoreEvent.SettingsChanged, listener); + } + + getSnapshot(): LoadedSettingsSnapshot { + return this._snapshot; + } + forScope(scope: LoadableSettingScope): SettingsFile { switch (scope) { case SettingScope.User: @@ -409,6 +456,7 @@ export class LoadedSettings { } this._merged = this.computeMergedSettings(); + this._snapshot = this.computeSnapshot(); coreEvents.emitSettingsChanged(); } diff --git a/packages/cli/src/ui/contexts/SettingsContext.test.tsx b/packages/cli/src/ui/contexts/SettingsContext.test.tsx new file mode 100644 index 0000000000..3124108f90 --- /dev/null +++ b/packages/cli/src/ui/contexts/SettingsContext.test.tsx @@ -0,0 +1,167 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import type React from 'react'; +import { Component, type ReactNode } from 'react'; +import { renderHook, render } from '../../test-utils/render.js'; +import { act } from 'react'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { SettingsContext, useSettingsStore } from './SettingsContext.js'; +import { + type LoadedSettings, + SettingScope, + type LoadedSettingsSnapshot, + type SettingsFile, + createTestMergedSettings, +} from '../../config/settings.js'; + +const createMockSettingsFile = (path: string): SettingsFile => ({ + path, + settings: {}, + originalSettings: {}, +}); + +const mockSnapshot: LoadedSettingsSnapshot = { + system: createMockSettingsFile('/system'), + systemDefaults: createMockSettingsFile('/defaults'), + user: createMockSettingsFile('/user'), + workspace: createMockSettingsFile('/workspace'), + isTrusted: true, + errors: [], + merged: createTestMergedSettings({ + ui: { theme: 'default-theme' }, + }), +}; + +class ErrorBoundary extends Component< + { children: ReactNode; onError: (error: Error) => void }, + { hasError: boolean } +> { + constructor(props: { children: ReactNode; onError: (error: Error) => void }) { + super(props); + this.state = { hasError: false }; + } + + static getDerivedStateFromError(_error: Error) { + return { hasError: true }; + } + + override componentDidCatch(error: Error) { + this.props.onError(error); + } + + override render() { + if (this.state.hasError) { + return null; + } + return this.props.children; + } +} + +const TestHarness = () => { + useSettingsStore(); + return null; +}; + +describe('SettingsContext', () => { + let mockLoadedSettings: LoadedSettings; + let listeners: Array<() => void> = []; + + beforeEach(() => { + listeners = []; + + mockLoadedSettings = { + subscribe: vi.fn((listener: () => void) => { + listeners.push(listener); + return () => { + listeners = listeners.filter((l) => l !== listener); + }; + }), + getSnapshot: vi.fn(() => mockSnapshot), + setValue: vi.fn(), + } as unknown as LoadedSettings; + }); + + const wrapper = ({ children }: { children: React.ReactNode }) => ( + + {children} + + ); + + it('should provide the correct initial state', () => { + const { result } = renderHook(() => useSettingsStore(), { wrapper }); + + expect(result.current.settings.merged).toEqual(mockSnapshot.merged); + expect(result.current.settings.isTrusted).toBe(true); + }); + + it('should allow accessing settings for a specific scope', () => { + const { result } = renderHook(() => useSettingsStore(), { wrapper }); + + const userSettings = result.current.settings.forScope(SettingScope.User); + expect(userSettings).toBe(mockSnapshot.user); + + const workspaceSettings = result.current.settings.forScope( + SettingScope.Workspace, + ); + expect(workspaceSettings).toBe(mockSnapshot.workspace); + }); + + it('should trigger re-renders when settings change (external event)', () => { + const { result } = renderHook(() => useSettingsStore(), { wrapper }); + + expect(result.current.settings.merged.ui?.theme).toBe('default-theme'); + + const newSnapshot = { + ...mockSnapshot, + merged: { ui: { theme: 'new-theme' } }, + }; + ( + mockLoadedSettings.getSnapshot as ReturnType + ).mockReturnValue(newSnapshot); + + // Trigger the listeners (simulate coreEvents emission) + act(() => { + listeners.forEach((l) => l()); + }); + + expect(result.current.settings.merged.ui?.theme).toBe('new-theme'); + }); + + it('should call store.setValue when setSetting is called', () => { + const { result } = renderHook(() => useSettingsStore(), { wrapper }); + + act(() => { + result.current.setSetting(SettingScope.User, 'ui.theme', 'dark'); + }); + + expect(mockLoadedSettings.setValue).toHaveBeenCalledWith( + SettingScope.User, + 'ui.theme', + 'dark', + ); + }); + + it('should throw error if used outside provider', () => { + const onError = vi.fn(); + // Suppress console.error (React logs error boundary info) + const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); + + render( + + + , + ); + + expect(onError).toHaveBeenCalledWith( + expect.objectContaining({ + message: 'useSettingsStore must be used within a SettingsProvider', + }), + ); + + consoleSpy.mockRestore(); + }); +}); diff --git a/packages/cli/src/ui/contexts/SettingsContext.tsx b/packages/cli/src/ui/contexts/SettingsContext.tsx index 144e1a2859..2c5ae37dfd 100644 --- a/packages/cli/src/ui/contexts/SettingsContext.tsx +++ b/packages/cli/src/ui/contexts/SettingsContext.tsx @@ -4,17 +4,81 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useContext } from 'react'; -import type { LoadedSettings } from '../../config/settings.js'; +import React, { useContext, useMemo, useSyncExternalStore } from 'react'; +import type { + LoadableSettingScope, + LoadedSettings, + LoadedSettingsSnapshot, + SettingsFile, +} from '../../config/settings.js'; +import { SettingScope } from '../../config/settings.js'; export const SettingsContext = React.createContext( undefined, ); -export const useSettings = () => { +export const useSettings = (): LoadedSettings => { const context = useContext(SettingsContext); if (context === undefined) { throw new Error('useSettings must be used within a SettingsProvider'); } return context; }; + +export interface SettingsState extends LoadedSettingsSnapshot { + forScope: (scope: LoadableSettingScope) => SettingsFile; +} + +export interface SettingsStoreValue { + settings: SettingsState; + setSetting: ( + scope: LoadableSettingScope, + key: string, + value: unknown, + ) => void; +} + +// Components that call this hook will re render when a settings change event is emitted +export const useSettingsStore = (): SettingsStoreValue => { + const store = useContext(SettingsContext); + if (store === undefined) { + throw new Error('useSettingsStore must be used within a SettingsProvider'); + } + + // React passes a listener fn into the subscribe function + // When the listener runs, it re renders the component if the snapshot changed + const snapshot = useSyncExternalStore( + (listener) => store.subscribe(listener), + () => store.getSnapshot(), + ); + + const settings: SettingsState = useMemo( + () => ({ + ...snapshot, + forScope: (scope: LoadableSettingScope) => { + switch (scope) { + case SettingScope.User: + return snapshot.user; + case SettingScope.Workspace: + return snapshot.workspace; + case SettingScope.System: + return snapshot.system; + case SettingScope.SystemDefaults: + return snapshot.systemDefaults; + default: + throw new Error(`Invalid scope: ${scope}`); + } + }, + }), + [snapshot], + ); + + return useMemo( + () => ({ + settings, + setSetting: (scope: LoadableSettingScope, key: string, value: unknown) => + store.setValue(scope, key, value), + }), + [settings, store], + ); +}; From 941691ce72367f278ff6807e5e98d60d977c1e52 Mon Sep 17 00:00:00 2001 From: Richie Foreman Date: Wed, 11 Feb 2026 16:07:51 -0800 Subject: [PATCH 08/44] fix(mcp): Ensure that stdio MCP server execution has the `GEMINI_CLI=1` env variable populated. (#18832) --- .../src/services/shellExecutionService.ts | 15 ++++++++++++- packages/core/src/tools/mcp-client.test.ts | 22 +++++++++++++++++++ packages/core/src/tools/mcp-client.ts | 7 +++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/packages/core/src/services/shellExecutionService.ts b/packages/core/src/services/shellExecutionService.ts index 23ac63f772..96cae8c269 100644 --- a/packages/core/src/services/shellExecutionService.ts +++ b/packages/core/src/services/shellExecutionService.ts @@ -32,6 +32,18 @@ const { Terminal } = pkg; const MAX_CHILD_PROCESS_BUFFER_SIZE = 16 * 1024 * 1024; // 16MB +/** + * An environment variable that is set for shell executions. This can be used + * by downstream executables and scripts to identify that they were executed + * from within Gemini CLI. + */ +export const GEMINI_CLI_IDENTIFICATION_ENV_VAR = 'GEMINI_CLI'; + +/** + * The value of {@link GEMINI_CLI_IDENTIFICATION_ENV_VAR} + */ +export const GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE = '1'; + // We want to allow shell outputs that are close to the context window in size. // 300,000 lines is roughly equivalent to a large context window, ensuring // we capture significant output from long-running commands. @@ -302,7 +314,8 @@ export class ShellExecutionService { detached: !isWindows, env: { ...sanitizeEnvironment(process.env, sanitizationConfig), - GEMINI_CLI: '1', + [GEMINI_CLI_IDENTIFICATION_ENV_VAR]: + GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE, TERM: 'xterm-256color', PAGER: 'cat', GIT_PAGER: 'cat', diff --git a/packages/core/src/tools/mcp-client.test.ts b/packages/core/src/tools/mcp-client.test.ts index 39165bde45..3f289f1732 100644 --- a/packages/core/src/tools/mcp-client.test.ts +++ b/packages/core/src/tools/mcp-client.test.ts @@ -1639,6 +1639,28 @@ describe('mcp-client', () => { }); }); + it('sets an env variable GEMINI_CLI=1 for stdio MCP servers', async () => { + const mockedTransport = vi + .spyOn(SdkClientStdioLib, 'StdioClientTransport') + .mockReturnValue({} as SdkClientStdioLib.StdioClientTransport); + + await createTransport( + 'test-server', + { + command: 'test-command', + args: ['--foo', 'bar'], + env: {}, + cwd: 'test/cwd', + }, + false, + EMPTY_CONFIG, + ); + + const callArgs = mockedTransport.mock.calls[0][0]; + expect(callArgs.env).toBeDefined(); + expect(callArgs.env!['GEMINI_CLI']).toBe('1'); + }); + it('should exclude extension settings with undefined values from environment', async () => { const mockedTransport = vi .spyOn(SdkClientStdioLib, 'StdioClientTransport') diff --git a/packages/core/src/tools/mcp-client.ts b/packages/core/src/tools/mcp-client.ts index 2588d54dba..7902d8953a 100644 --- a/packages/core/src/tools/mcp-client.ts +++ b/packages/core/src/tools/mcp-client.ts @@ -67,6 +67,10 @@ import { sanitizeEnvironment, type EnvironmentSanitizationConfig, } from '../services/environmentSanitization.js'; +import { + GEMINI_CLI_IDENTIFICATION_ENV_VAR, + GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE, +} from '../services/shellExecutionService.js'; export const MCP_DEFAULT_TIMEOUT_MSEC = 10 * 60 * 1000; // default to 10 minutes @@ -1897,10 +1901,11 @@ export async function createTransport( let transport: Transport = new StdioClientTransport({ command: mcpServerConfig.command, args: mcpServerConfig.args || [], - // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion env: { ...sanitizeEnvironment(process.env, sanitizationConfig), ...(mcpServerConfig.env || {}), + [GEMINI_CLI_IDENTIFICATION_ENV_VAR]: + GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE, } as Record, cwd: mcpServerConfig.cwd, stderr: 'pipe', From 08e8eeab841fbd16554d01a273f9a67a0825d233 Mon Sep 17 00:00:00 2001 From: Gal Zahavi <38544478+galz10@users.noreply.github.com> Date: Wed, 11 Feb 2026 16:20:54 -0800 Subject: [PATCH 09/44] fix(core): improve headless mode detection for flags and query args (#18855) --- packages/cli/src/config/config.ts | 9 ++-- .../cli/src/config/trustedFolders.test.ts | 8 +++ packages/cli/src/config/trustedFolders.ts | 21 ++++++-- packages/core/src/utils/headless.test.ts | 52 ++++++++++++++++--- packages/core/src/utils/headless.ts | 29 +++++++---- 5 files changed, 94 insertions(+), 25 deletions(-) diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 87eb1e8fa7..f164ce77d8 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -445,7 +445,11 @@ export async function loadCliConfig( process.env['VITEST'] === 'true' ? false : (settings.security?.folderTrust?.enabled ?? false); - const trustedFolder = isWorkspaceTrusted(settings, cwd)?.isTrusted ?? false; + const trustedFolder = + isWorkspaceTrusted(settings, cwd, undefined, { + prompt: argv.prompt, + query: argv.query, + })?.isTrusted ?? false; // Set the context filename in the server's memoryTool module BEFORE loading memory // TODO(b/343434939): This is a bit of a hack. The contextFileName should ideally be passed @@ -602,8 +606,7 @@ export async function loadCliConfig( const interactive = !!argv.promptInteractive || !!argv.experimentalAcp || - (!isHeadlessMode({ prompt: argv.prompt }) && - !argv.query && + (!isHeadlessMode({ prompt: argv.prompt, query: argv.query }) && !argv.isCommand); const allowedTools = argv.allowedTools || settings.tools?.allowed || []; diff --git a/packages/cli/src/config/trustedFolders.test.ts b/packages/cli/src/config/trustedFolders.test.ts index dff4610b90..892cd86e4b 100644 --- a/packages/cli/src/config/trustedFolders.test.ts +++ b/packages/cli/src/config/trustedFolders.test.ts @@ -449,6 +449,14 @@ describe('Trusted Folders', () => { false, ); }); + + it('should return true for isPathTrusted when isHeadlessMode is true', async () => { + const geminiCore = await import('@google/gemini-cli-core'); + vi.spyOn(geminiCore, 'isHeadlessMode').mockReturnValue(true); + + const folders = loadTrustedFolders(); + expect(folders.isPathTrusted('/any-untrusted-path')).toBe(true); + }); }); describe('Trusted Folders Caching', () => { diff --git a/packages/cli/src/config/trustedFolders.ts b/packages/cli/src/config/trustedFolders.ts index 1f85684900..761bc368d3 100644 --- a/packages/cli/src/config/trustedFolders.ts +++ b/packages/cli/src/config/trustedFolders.ts @@ -17,6 +17,7 @@ import { homedir, isHeadlessMode, coreEvents, + type HeadlessModeOptions, } from '@google/gemini-cli-core'; import type { Settings } from './settings.js'; import stripJsonComments from 'strip-json-comments'; @@ -128,7 +129,11 @@ export class LoadedTrustedFolders { isPathTrusted( location: string, config?: Record, + headlessOptions?: HeadlessModeOptions, ): boolean | undefined { + if (isHeadlessMode(headlessOptions)) { + return true; + } const configToUse = config ?? this.user.config; // Resolve location to its realpath for canonical comparison @@ -333,6 +338,7 @@ export function isFolderTrustEnabled(settings: Settings): boolean { function getWorkspaceTrustFromLocalConfig( workspaceDir: string, trustConfig?: Record, + headlessOptions?: HeadlessModeOptions, ): TrustResult { const folders = loadTrustedFolders(); const configToUse = trustConfig ?? folders.user.config; @@ -346,7 +352,11 @@ function getWorkspaceTrustFromLocalConfig( ); } - const isTrusted = folders.isPathTrusted(workspaceDir, configToUse); + const isTrusted = folders.isPathTrusted( + workspaceDir, + configToUse, + headlessOptions, + ); return { isTrusted, source: isTrusted !== undefined ? 'file' : undefined, @@ -357,8 +367,9 @@ export function isWorkspaceTrusted( settings: Settings, workspaceDir: string = process.cwd(), trustConfig?: Record, + headlessOptions?: HeadlessModeOptions, ): TrustResult { - if (isHeadlessMode()) { + if (isHeadlessMode(headlessOptions)) { return { isTrusted: true, source: undefined }; } @@ -372,5 +383,9 @@ export function isWorkspaceTrusted( } // Fall back to the local user configuration - return getWorkspaceTrustFromLocalConfig(workspaceDir, trustConfig); + return getWorkspaceTrustFromLocalConfig( + workspaceDir, + trustConfig, + headlessOptions, + ); } diff --git a/packages/core/src/utils/headless.test.ts b/packages/core/src/utils/headless.test.ts index 89f42ffcd6..4708c79969 100644 --- a/packages/core/src/utils/headless.test.ts +++ b/packages/core/src/utils/headless.test.ts @@ -99,16 +99,50 @@ describe('isHeadlessMode', () => { expect(isHeadlessMode({ prompt: true })).toBe(true); }); - it('should return false if query is provided but it is still a TTY', () => { - // Note: per current logic, query alone doesn't force headless if TTY - // This matches the existing behavior in packages/cli/src/config/config.ts - expect(isHeadlessMode({ query: 'test query' })).toBe(false); + it('should return true if query is provided', () => { + expect(isHeadlessMode({ query: 'test query' })).toBe(true); + }); + + it('should return true if -p or --prompt is in process.argv as a fallback', () => { + const originalArgv = process.argv; + process.argv = ['node', 'index.js', '-p', 'hello']; + try { + expect(isHeadlessMode()).toBe(true); + } finally { + process.argv = originalArgv; + } + + process.argv = ['node', 'index.js', '--prompt', 'hello']; + try { + expect(isHeadlessMode()).toBe(true); + } finally { + process.argv = originalArgv; + } + }); + + it('should return true if -y or --yolo is in process.argv as a fallback', () => { + const originalArgv = process.argv; + process.argv = ['node', 'index.js', '-y']; + try { + expect(isHeadlessMode()).toBe(true); + } finally { + process.argv = originalArgv; + } + + process.argv = ['node', 'index.js', '--yolo']; + try { + expect(isHeadlessMode()).toBe(true); + } finally { + process.argv = originalArgv; + } }); it('should handle undefined process.stdout gracefully', () => { const originalStdout = process.stdout; - // @ts-expect-error - testing edge case - delete process.stdout; + Object.defineProperty(process, 'stdout', { + value: undefined, + configurable: true, + }); try { expect(isHeadlessMode()).toBe(false); @@ -122,8 +156,10 @@ describe('isHeadlessMode', () => { it('should handle undefined process.stdin gracefully', () => { const originalStdin = process.stdin; - // @ts-expect-error - testing edge case - delete process.stdin; + Object.defineProperty(process, 'stdin', { + value: undefined, + configurable: true, + }); try { expect(isHeadlessMode()).toBe(false); diff --git a/packages/core/src/utils/headless.ts b/packages/core/src/utils/headless.ts index 27ea5f9cbf..5a46b90d6d 100644 --- a/packages/core/src/utils/headless.ts +++ b/packages/core/src/utils/headless.ts @@ -28,18 +28,25 @@ export interface HeadlessModeOptions { * @returns true if the environment is considered headless. */ export function isHeadlessMode(options?: HeadlessModeOptions): boolean { - if (process.env['GEMINI_CLI_INTEGRATION_TEST'] === 'true') { - return ( - !!options?.prompt || - (!!process.stdin && !process.stdin.isTTY) || - (!!process.stdout && !process.stdout.isTTY) - ); + if (process.env['GEMINI_CLI_INTEGRATION_TEST'] !== 'true') { + const isCI = + process.env['CI'] === 'true' || process.env['GITHUB_ACTIONS'] === 'true'; + if (isCI) { + return true; + } } - return ( - process.env['CI'] === 'true' || - process.env['GITHUB_ACTIONS'] === 'true' || - !!options?.prompt || + + const isNotTTY = (!!process.stdin && !process.stdin.isTTY) || - (!!process.stdout && !process.stdout.isTTY) + (!!process.stdout && !process.stdout.isTTY); + + if (isNotTTY || !!options?.prompt || !!options?.query) { + return true; + } + + // Fallback: check process.argv for flags that imply headless or auto-approve mode. + return process.argv.some( + (arg) => + arg === '-p' || arg === '--prompt' || arg === '-y' || arg === '--yolo', ); } From c370d2397b17f02dbdabff366bcec0bca073a937 Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Wed, 11 Feb 2026 19:46:58 -0500 Subject: [PATCH 10/44] refactor(cli): simplify UI and remove legacy inline tool confirmation logic (#18566) --- .../AlternateBufferQuittingDisplay.tsx | 6 +- .../src/ui/components/HistoryItemDisplay.tsx | 3 - .../cli/src/ui/components/MainContent.tsx | 7 +- .../ToolConfirmationMessageOverflow.test.tsx | 128 ------ .../messages/ToolGroupMessage.test.tsx | 381 +++--------------- .../components/messages/ToolGroupMessage.tsx | 72 +--- .../ToolGroupMessage.test.tsx.snap | 111 +---- 7 files changed, 83 insertions(+), 625 deletions(-) delete mode 100644 packages/cli/src/ui/components/messages/ToolConfirmationMessageOverflow.test.tsx diff --git a/packages/cli/src/ui/components/AlternateBufferQuittingDisplay.tsx b/packages/cli/src/ui/components/AlternateBufferQuittingDisplay.tsx index fec35d46c3..8e0ede2e09 100644 --- a/packages/cli/src/ui/components/AlternateBufferQuittingDisplay.tsx +++ b/packages/cli/src/ui/components/AlternateBufferQuittingDisplay.tsx @@ -12,18 +12,15 @@ import { QuittingDisplay } from './QuittingDisplay.js'; import { useAppContext } from '../contexts/AppContext.js'; import { MAX_GEMINI_MESSAGE_LINES } from '../constants.js'; import { useConfirmingTool } from '../hooks/useConfirmingTool.js'; -import { useConfig } from '../contexts/ConfigContext.js'; import { ToolStatusIndicator, ToolInfo } from './messages/ToolShared.js'; import { theme } from '../semantic-colors.js'; export const AlternateBufferQuittingDisplay = () => { const { version } = useAppContext(); const uiState = useUIState(); - const config = useConfig(); const confirmingTool = useConfirmingTool(); - const showPromptedTool = - config.isEventDrivenSchedulerEnabled() && confirmingTool !== null; + const showPromptedTool = confirmingTool !== null; // We render the entire chat history and header here to ensure that the // conversation history is visible to the user after the app quits and the @@ -56,7 +53,6 @@ export const AlternateBufferQuittingDisplay = () => { terminalWidth={uiState.mainAreaWidth} item={{ ...item, id: 0 }} isPending={true} - isFocused={false} activeShellPtyId={uiState.activePtyId} embeddedShellFocused={uiState.embeddedShellFocused} /> diff --git a/packages/cli/src/ui/components/HistoryItemDisplay.tsx b/packages/cli/src/ui/components/HistoryItemDisplay.tsx index 41340c1b08..f41ee20895 100644 --- a/packages/cli/src/ui/components/HistoryItemDisplay.tsx +++ b/packages/cli/src/ui/components/HistoryItemDisplay.tsx @@ -43,7 +43,6 @@ interface HistoryItemDisplayProps { availableTerminalHeight?: number; terminalWidth: number; isPending: boolean; - isFocused?: boolean; commands?: readonly SlashCommand[]; activeShellPtyId?: number | null; embeddedShellFocused?: boolean; @@ -56,7 +55,6 @@ export const HistoryItemDisplay: React.FC = ({ terminalWidth, isPending, commands, - isFocused = true, activeShellPtyId, embeddedShellFocused, availableTerminalHeightGemini, @@ -179,7 +177,6 @@ export const HistoryItemDisplay: React.FC = ({ groupId={itemForDisplay.id} availableTerminalHeight={availableTerminalHeight} terminalWidth={terminalWidth} - isFocused={isFocused} activeShellPtyId={activeShellPtyId} embeddedShellFocused={embeddedShellFocused} borderTop={itemForDisplay.borderTop} diff --git a/packages/cli/src/ui/components/MainContent.tsx b/packages/cli/src/ui/components/MainContent.tsx index 32c70e8cad..586553a1f2 100644 --- a/packages/cli/src/ui/components/MainContent.tsx +++ b/packages/cli/src/ui/components/MainContent.tsx @@ -19,7 +19,6 @@ import { useMemo, memo, useCallback, useEffect, useRef } from 'react'; import { MAX_GEMINI_MESSAGE_LINES } from '../constants.js'; import { useConfirmingTool } from '../hooks/useConfirmingTool.js'; import { ToolConfirmationQueue } from './ToolConfirmationQueue.js'; -import { useConfig } from '../contexts/ConfigContext.js'; const MemoizedHistoryItemDisplay = memo(HistoryItemDisplay); const MemoizedAppHeader = memo(AppHeader); @@ -31,12 +30,10 @@ const MemoizedAppHeader = memo(AppHeader); export const MainContent = () => { const { version } = useAppContext(); const uiState = useUIState(); - const config = useConfig(); const isAlternateBuffer = useAlternateBuffer(); const confirmingTool = useConfirmingTool(); - const showConfirmationQueue = - config.isEventDrivenSchedulerEnabled() && confirmingTool !== null; + const showConfirmationQueue = confirmingTool !== null; const scrollableListRef = useRef>(null); @@ -89,7 +86,6 @@ export const MainContent = () => { terminalWidth={mainAreaWidth} item={{ ...item, id: 0 }} isPending={true} - isFocused={!uiState.isEditorDialogOpen} activeShellPtyId={uiState.activePtyId} embeddedShellFocused={uiState.embeddedShellFocused} /> @@ -105,7 +101,6 @@ export const MainContent = () => { isAlternateBuffer, availableTerminalHeight, mainAreaWidth, - uiState.isEditorDialogOpen, uiState.activePtyId, uiState.embeddedShellFocused, showConfirmationQueue, diff --git a/packages/cli/src/ui/components/messages/ToolConfirmationMessageOverflow.test.tsx b/packages/cli/src/ui/components/messages/ToolConfirmationMessageOverflow.test.tsx deleted file mode 100644 index b59b6c5adf..0000000000 --- a/packages/cli/src/ui/components/messages/ToolConfirmationMessageOverflow.test.tsx +++ /dev/null @@ -1,128 +0,0 @@ -/** - * @license - * Copyright 2026 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import { describe, it, expect, vi } from 'vitest'; -import { ToolGroupMessage } from './ToolGroupMessage.js'; -import type { - ToolCallConfirmationDetails, - Config, -} from '@google/gemini-cli-core'; -import { renderWithProviders } from '../../../test-utils/render.js'; -import { useToolActions } from '../../contexts/ToolActionsContext.js'; -import { - StreamingState, - ToolCallStatus, - type IndividualToolCallDisplay, -} from '../../types.js'; -import { OverflowProvider } from '../../contexts/OverflowContext.js'; -import { waitFor } from '../../../test-utils/async.js'; - -vi.mock('../../contexts/ToolActionsContext.js', async (importOriginal) => { - const actual = - await importOriginal< - typeof import('../../contexts/ToolActionsContext.js') - >(); - return { - ...actual, - useToolActions: vi.fn(), - }; -}); - -describe('ToolConfirmationMessage Overflow', () => { - const mockConfirm = vi.fn(); - vi.mocked(useToolActions).mockReturnValue({ - confirm: mockConfirm, - cancel: vi.fn(), - isDiffingEnabled: false, - }); - - const mockConfig = { - isTrustedFolder: () => true, - getIdeMode: () => false, - getMessageBus: () => ({ - subscribe: vi.fn(), - unsubscribe: vi.fn(), - publish: vi.fn(), - }), - isEventDrivenSchedulerEnabled: () => false, - getTheme: () => ({ - status: { warning: 'yellow' }, - text: { primary: 'white', secondary: 'gray', link: 'blue' }, - border: { default: 'gray' }, - ui: { symbol: 'cyan' }, - }), - } as unknown as Config; - - it('should display "press ctrl-o" hint when content overflows in ToolGroupMessage', async () => { - // Large diff that will definitely overflow - const diffLines = ['--- a/test.txt', '+++ b/test.txt', '@@ -1,20 +1,20 @@']; - for (let i = 0; i < 50; i++) { - diffLines.push(`+ line ${i + 1}`); - } - const fileDiff = diffLines.join('\n'); - - const confirmationDetails: ToolCallConfirmationDetails = { - type: 'edit', - title: 'Confirm Edit', - fileName: 'test.txt', - filePath: '/test.txt', - fileDiff, - originalContent: '', - newContent: 'lots of lines', - onConfirm: vi.fn(), - }; - - const toolCalls: IndividualToolCallDisplay[] = [ - { - callId: 'test-call-id', - name: 'test-tool', - description: 'a test tool', - status: ToolCallStatus.Confirming, - confirmationDetails, - resultDisplay: undefined, - }, - ]; - - const { lastFrame } = renderWithProviders( - - - , - { - config: mockConfig, - uiState: { - streamingState: StreamingState.WaitingForConfirmation, - constrainHeight: true, - }, - }, - ); - - // ResizeObserver might take a tick - await waitFor(() => - expect(lastFrame()).toContain('Press ctrl-o to show more lines'), - ); - - const frame = lastFrame(); - expect(frame).toBeDefined(); - if (frame) { - expect(frame).toContain('Press ctrl-o to show more lines'); - // Ensure it's AFTER the bottom border - const linesOfOutput = frame.split('\n'); - const bottomBorderIndex = linesOfOutput.findLastIndex((l) => - l.includes('╰─'), - ); - const hintIndex = linesOfOutput.findIndex((l) => - l.includes('Press ctrl-o to show more lines'), - ); - expect(hintIndex).toBeGreaterThan(bottomBorderIndex); - expect(frame).toMatchSnapshot(); - } - }); -}); diff --git a/packages/cli/src/ui/components/messages/ToolGroupMessage.test.tsx b/packages/cli/src/ui/components/messages/ToolGroupMessage.test.tsx index 5368684ea2..d2d3cd277a 100644 --- a/packages/cli/src/ui/components/messages/ToolGroupMessage.test.tsx +++ b/packages/cli/src/ui/components/messages/ToolGroupMessage.test.tsx @@ -5,7 +5,6 @@ */ import { renderWithProviders } from '../../../test-utils/render.js'; -import { createMockSettings } from '../../../test-utils/settings.js'; import { describe, it, expect, vi, afterEach } from 'vitest'; import { ToolGroupMessage } from './ToolGroupMessage.js'; import type { IndividualToolCallDisplay } from '../../types.js'; @@ -35,7 +34,6 @@ describe('', () => { const baseProps = { groupId: 1, terminalWidth: 80, - isFocused: true, }; const baseMockConfig = makeFakeConfig({ @@ -45,7 +43,6 @@ describe('', () => { folderTrust: false, ideMode: false, enableInteractiveShell: true, - enableEventDrivenScheduler: true, }); describe('Golden Snapshots', () => { @@ -64,7 +61,31 @@ describe('', () => { unmount(); }); - it('renders multiple tool calls with different statuses', () => { + it('hides confirming tools (standard behavior)', () => { + const toolCalls = [ + createToolCall({ + callId: 'confirm-tool', + status: ToolCallStatus.Confirming, + confirmationDetails: { + type: 'info', + title: 'Confirm tool', + prompt: 'Do you want to proceed?', + onConfirm: vi.fn(), + }, + }), + ]; + + const { lastFrame, unmount } = renderWithProviders( + , + { config: baseMockConfig }, + ); + + // Should render nothing because all tools in the group are confirming + expect(lastFrame()).toBe(''); + unmount(); + }); + + it('renders multiple tool calls with different statuses (only visible ones)', () => { const toolCalls = [ createToolCall({ callId: 'tool-1', @@ -85,68 +106,7 @@ describe('', () => { status: ToolCallStatus.Error, }), ]; - const mockConfig = makeFakeConfig({ - model: 'gemini-pro', - targetDir: os.tmpdir(), - enableEventDrivenScheduler: false, - }); - const { lastFrame, unmount } = renderWithProviders( - , - { - config: mockConfig, - uiState: { - pendingHistoryItems: [{ type: 'tool_group', tools: toolCalls }], - }, - }, - ); - expect(lastFrame()).toMatchSnapshot(); - unmount(); - }); - - it('renders tool call awaiting confirmation', () => { - const toolCalls = [ - createToolCall({ - callId: 'tool-confirm', - name: 'confirmation-tool', - description: 'This tool needs confirmation', - status: ToolCallStatus.Confirming, - confirmationDetails: { - type: 'info', - title: 'Confirm Tool Execution', - prompt: 'Are you sure you want to proceed?', - onConfirm: vi.fn(), - }, - }), - ]; - const mockConfig = makeFakeConfig({ - model: 'gemini-pro', - targetDir: os.tmpdir(), - enableEventDrivenScheduler: false, - }); - - const { lastFrame, unmount } = renderWithProviders( - , - { - config: mockConfig, - uiState: { - pendingHistoryItems: [{ type: 'tool_group', tools: toolCalls }], - }, - }, - ); - expect(lastFrame()).toMatchSnapshot(); - unmount(); - }); - - it('renders shell command with yellow border', () => { - const toolCalls = [ - createToolCall({ - callId: 'shell-1', - name: 'run_shell_command', - description: 'Execute shell command', - status: ToolCallStatus.Success, - }), - ]; const { lastFrame, unmount } = renderWithProviders( , { @@ -156,7 +116,12 @@ describe('', () => { }, }, ); - expect(lastFrame()).toMatchSnapshot(); + // pending-tool should be hidden + const output = lastFrame(); + expect(output).toContain('successful-tool'); + expect(output).not.toContain('pending-tool'); + expect(output).toContain('error-tool'); + expect(output).toMatchSnapshot(); unmount(); }); @@ -181,22 +146,22 @@ describe('', () => { status: ToolCallStatus.Pending, }), ]; - const mockConfig = makeFakeConfig({ - model: 'gemini-pro', - targetDir: os.tmpdir(), - enableEventDrivenScheduler: false, - }); const { lastFrame, unmount } = renderWithProviders( , { - config: mockConfig, + config: baseMockConfig, uiState: { pendingHistoryItems: [{ type: 'tool_group', tools: toolCalls }], }, }, ); - expect(lastFrame()).toMatchSnapshot(); + // write_file (Pending) should be hidden + const output = lastFrame(); + expect(output).toContain('read_file'); + expect(output).toContain('run_shell_command'); + expect(output).not.toContain('write_file'); + expect(output).toMatchSnapshot(); unmount(); }); @@ -233,25 +198,6 @@ describe('', () => { unmount(); }); - it('renders when not focused', () => { - const toolCalls = [createToolCall()]; - const { lastFrame, unmount } = renderWithProviders( - , - { - config: baseMockConfig, - uiState: { - pendingHistoryItems: [{ type: 'tool_group', tools: toolCalls }], - }, - }, - ); - expect(lastFrame()).toMatchSnapshot(); - unmount(); - }); - it('renders with narrow terminal width', () => { const toolCalls = [ createToolCall({ @@ -384,28 +330,6 @@ describe('', () => { }); describe('Border Color Logic', () => { - it('uses yellow border when tools are pending', () => { - const toolCalls = [createToolCall({ status: ToolCallStatus.Pending })]; - const mockConfig = makeFakeConfig({ - model: 'gemini-pro', - targetDir: os.tmpdir(), - enableEventDrivenScheduler: false, - }); - - const { lastFrame, unmount } = renderWithProviders( - , - { - config: mockConfig, - uiState: { - pendingHistoryItems: [{ type: 'tool_group', tools: toolCalls }], - }, - }, - ); - // The snapshot will capture the visual appearance including border color - expect(lastFrame()).toMatchSnapshot(); - unmount(); - }); - it('uses yellow border for shell commands even when successful', () => { const toolCalls = [ createToolCall({ @@ -483,210 +407,6 @@ describe('', () => { }); }); - describe('Confirmation Handling', () => { - it('shows confirmation dialog for first confirming tool only', () => { - const toolCalls = [ - createToolCall({ - callId: 'tool-1', - name: 'first-confirm', - status: ToolCallStatus.Confirming, - confirmationDetails: { - type: 'info', - title: 'Confirm First Tool', - prompt: 'Confirm first tool', - onConfirm: vi.fn(), - }, - }), - createToolCall({ - callId: 'tool-2', - name: 'second-confirm', - status: ToolCallStatus.Confirming, - confirmationDetails: { - type: 'info', - title: 'Confirm Second Tool', - prompt: 'Confirm second tool', - onConfirm: vi.fn(), - }, - }), - ]; - const mockConfig = makeFakeConfig({ - model: 'gemini-pro', - targetDir: os.tmpdir(), - enableEventDrivenScheduler: false, - }); - - const { lastFrame, unmount } = renderWithProviders( - , - { - config: mockConfig, - uiState: { - pendingHistoryItems: [{ type: 'tool_group', tools: toolCalls }], - }, - }, - ); - // Should only show confirmation for the first tool - expect(lastFrame()).toMatchSnapshot(); - unmount(); - }); - - it('renders confirmation with permanent approval enabled', () => { - const toolCalls = [ - createToolCall({ - callId: 'tool-1', - name: 'confirm-tool', - status: ToolCallStatus.Confirming, - confirmationDetails: { - type: 'info', - title: 'Confirm Tool', - prompt: 'Do you want to proceed?', - onConfirm: vi.fn(), - }, - }), - ]; - const settings = createMockSettings({ - security: { enablePermanentToolApproval: true }, - }); - const mockConfig = makeFakeConfig({ - model: 'gemini-pro', - targetDir: os.tmpdir(), - enableEventDrivenScheduler: false, - }); - - const { lastFrame, unmount } = renderWithProviders( - , - { - settings, - config: mockConfig, - uiState: { - pendingHistoryItems: [{ type: 'tool_group', tools: toolCalls }], - }, - }, - ); - expect(lastFrame()).toContain('Allow for all future sessions'); - expect(lastFrame()).toMatchSnapshot(); - unmount(); - }); - - it('renders confirmation with permanent approval disabled', () => { - const toolCalls = [ - createToolCall({ - callId: 'confirm-tool', - name: 'confirm-tool', - status: ToolCallStatus.Confirming, - confirmationDetails: { - type: 'info', - title: 'Confirm tool', - prompt: 'Do you want to proceed?', - onConfirm: vi.fn(), - }, - }), - ]; - - const mockConfig = makeFakeConfig({ - model: 'gemini-pro', - targetDir: os.tmpdir(), - enableEventDrivenScheduler: false, - }); - - const { lastFrame, unmount } = renderWithProviders( - , - { config: mockConfig }, - ); - expect(lastFrame()).not.toContain('Allow for all future sessions'); - expect(lastFrame()).toMatchSnapshot(); - unmount(); - }); - }); - - describe('Event-Driven Scheduler', () => { - it('hides confirming tools when event-driven scheduler is enabled', () => { - const toolCalls = [ - createToolCall({ - callId: 'confirm-tool', - status: ToolCallStatus.Confirming, - confirmationDetails: { - type: 'info', - title: 'Confirm tool', - prompt: 'Do you want to proceed?', - onConfirm: vi.fn(), - }, - }), - ]; - - const mockConfig = baseMockConfig; - - const { lastFrame, unmount } = renderWithProviders( - , - { config: mockConfig }, - ); - - // Should render nothing because all tools in the group are confirming - expect(lastFrame()).toBe(''); - expect(lastFrame()).toMatchSnapshot(); - unmount(); - }); - - it('shows only successful tools when mixed with confirming tools', () => { - const toolCalls = [ - createToolCall({ - callId: 'success-tool', - name: 'success-tool', - status: ToolCallStatus.Success, - }), - createToolCall({ - callId: 'confirm-tool', - name: 'confirm-tool', - status: ToolCallStatus.Confirming, - confirmationDetails: { - type: 'info', - title: 'Confirm tool', - prompt: 'Do you want to proceed?', - onConfirm: vi.fn(), - }, - }), - ]; - - const mockConfig = baseMockConfig; - - const { lastFrame, unmount } = renderWithProviders( - , - { config: mockConfig }, - ); - - const output = lastFrame(); - expect(output).toContain('success-tool'); - expect(output).not.toContain('confirm-tool'); - expect(output).not.toContain('Do you want to proceed?'); - expect(output).toMatchSnapshot(); - unmount(); - }); - - it('renders nothing when only tool is in-progress AskUser with borderBottom=false', () => { - // AskUser tools in progress are rendered by AskUserDialog, not ToolGroupMessage. - // When AskUser is the only tool and borderBottom=false (no border to close), - // the component should render nothing. - const toolCalls = [ - createToolCall({ - callId: 'ask-user-tool', - name: 'Ask User', - status: ToolCallStatus.Executing, - }), - ]; - - const { lastFrame, unmount } = renderWithProviders( - , - { config: baseMockConfig }, - ); - // AskUser tools in progress are rendered by AskUserDialog, so we expect nothing. - expect(lastFrame()).toMatchSnapshot(); - unmount(); - }); - }); - describe('Ask User Filtering', () => { it.each([ ToolCallStatus.Pending, @@ -753,5 +473,30 @@ describe('', () => { expect(lastFrame()).toMatchSnapshot(); unmount(); }); + + it('renders nothing when only tool is in-progress AskUser with borderBottom=false', () => { + // AskUser tools in progress are rendered by AskUserDialog, not ToolGroupMessage. + // When AskUser is the only tool and borderBottom=false (no border to close), + // the component should render nothing. + const toolCalls = [ + createToolCall({ + callId: 'ask-user-tool', + name: ASK_USER_DISPLAY_NAME, + status: ToolCallStatus.Executing, + }), + ]; + + const { lastFrame, unmount } = renderWithProviders( + , + { config: baseMockConfig }, + ); + // AskUser tools in progress are rendered by AskUserDialog, so we expect nothing. + expect(lastFrame()).toBe(''); + unmount(); + }); }); }); diff --git a/packages/cli/src/ui/components/messages/ToolGroupMessage.tsx b/packages/cli/src/ui/components/messages/ToolGroupMessage.tsx index f9225b60e7..07ae280558 100644 --- a/packages/cli/src/ui/components/messages/ToolGroupMessage.tsx +++ b/packages/cli/src/ui/components/messages/ToolGroupMessage.tsx @@ -11,7 +11,6 @@ import type { IndividualToolCallDisplay } from '../../types.js'; import { ToolCallStatus } from '../../types.js'; import { ToolMessage } from './ToolMessage.js'; import { ShellToolMessage } from './ShellToolMessage.js'; -import { ToolConfirmationMessage } from './ToolConfirmationMessage.js'; import { theme } from '../../semantic-colors.js'; import { useConfig } from '../../contexts/ConfigContext.js'; import { isShellTool, isThisShellFocused } from './ToolShared.js'; @@ -24,7 +23,6 @@ interface ToolGroupMessageProps { toolCalls: IndividualToolCallDisplay[]; availableTerminalHeight?: number; terminalWidth: number; - isFocused?: boolean; activeShellPtyId?: number | null; embeddedShellFocused?: boolean; onShellInputSubmit?: (input: string) => void; @@ -43,13 +41,11 @@ const isAskUserInProgress = (t: IndividualToolCallDisplay): boolean => // Main component renders the border and maps the tools using ToolMessage const TOOL_MESSAGE_HORIZONTAL_MARGIN = 4; -const TOOL_CONFIRMATION_INTERNAL_PADDING = 4; export const ToolGroupMessage: React.FC = ({ toolCalls: allToolCalls, availableTerminalHeight, terminalWidth, - isFocused = true, activeShellPtyId, embeddedShellFocused, borderTop: borderTopOverride, @@ -64,24 +60,20 @@ export const ToolGroupMessage: React.FC = ({ const config = useConfig(); const { constrainHeight } = useUIState(); - const isEventDriven = config.isEventDrivenSchedulerEnabled(); - - // If Event-Driven Scheduler is enabled, we HIDE tools that are still in - // pre-execution states (Confirming, Pending) from the History log. - // They live in the Global Queue or wait for their turn. - const visibleToolCalls = useMemo(() => { - if (!isEventDriven) { - return toolCalls; - } - // Only show tools that are actually running or finished. - // We explicitly exclude Pending and Confirming to ensure they only - // appear in the Global Queue until they are approved and start executing. - return toolCalls.filter( - (t) => - t.status !== ToolCallStatus.Pending && - t.status !== ToolCallStatus.Confirming, - ); - }, [toolCalls, isEventDriven]); + // We HIDE tools that are still in pre-execution states (Confirming, Pending) + // from the History log. They live in the Global Queue or wait for their turn. + // Only show tools that are actually running or finished. + // We explicitly exclude Pending and Confirming to ensure they only + // appear in the Global Queue until they are approved and start executing. + const visibleToolCalls = useMemo( + () => + toolCalls.filter( + (t) => + t.status !== ToolCallStatus.Pending && + t.status !== ToolCallStatus.Confirming, + ), + [toolCalls], + ); const isEmbeddedShellFocused = visibleToolCalls.some((t) => isThisShellFocused( @@ -110,17 +102,8 @@ export const ToolGroupMessage: React.FC = ({ const staticHeight = /* border */ 2 + /* marginBottom */ 1; - // Inline confirmations are ONLY used when the Global Queue is disabled. - const toolAwaitingApproval = useMemo( - () => - isEventDriven - ? undefined - : toolCalls.find((tc) => tc.status === ToolCallStatus.Confirming), - [toolCalls, isEventDriven], - ); - - // If all tools are filtered out (e.g., in-progress AskUser tools, confirming tools - // in event-driven mode), only render if we need to close a border from previous + // If all tools are filtered out (e.g., in-progress AskUser tools, confirming tools), + // only render if we need to close a border from previous // tool groups. borderBottomOverride=true means we must render the closing border; // undefined or false means there's nothing to display. if (visibleToolCalls.length === 0 && borderBottomOverride !== true) { @@ -163,7 +146,6 @@ export const ToolGroupMessage: React.FC = ({ paddingRight={TOOL_MESSAGE_HORIZONTAL_MARGIN} > {visibleToolCalls.map((tool, index) => { - const isConfirming = toolAwaitingApproval?.callId === tool.callId; const isFirst = index === 0; const isShellToolCall = isShellTool(tool.name); @@ -171,11 +153,7 @@ export const ToolGroupMessage: React.FC = ({ ...tool, availableTerminalHeight: availableTerminalHeightPerToolMessage, terminalWidth: contentWidth, - emphasis: isConfirming - ? ('high' as const) - : toolAwaitingApproval - ? ('low' as const) - : ('medium' as const), + emphasis: 'medium' as const, isFirst: borderTopOverride !== undefined ? borderTopOverride && isFirst @@ -213,22 +191,6 @@ export const ToolGroupMessage: React.FC = ({ paddingLeft={1} paddingRight={1} > - {tool.status === ToolCallStatus.Confirming && - isConfirming && - tool.confirmationDetails && ( - - )} {tool.outputFile && ( diff --git a/packages/cli/src/ui/components/messages/__snapshots__/ToolGroupMessage.test.tsx.snap b/packages/cli/src/ui/components/messages/__snapshots__/ToolGroupMessage.test.tsx.snap index 369fa59174..3586b32c21 100644 --- a/packages/cli/src/ui/components/messages/__snapshots__/ToolGroupMessage.test.tsx.snap +++ b/packages/cli/src/ui/components/messages/__snapshots__/ToolGroupMessage.test.tsx.snap @@ -50,76 +50,6 @@ exports[` > Border Color Logic > uses yellow border for shel ╰──────────────────────────────────────────────────────────────────────────╯" `; -exports[` > Border Color Logic > uses yellow border when tools are pending 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────╮ -│ o test-tool A tool for testing │ -│ │ -│ Test result │ -╰──────────────────────────────────────────────────────────────────────────╯" -`; - -exports[` > Confirmation Handling > renders confirmation with permanent approval disabled 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────╮ -│ ? confirm-tool A tool for testing ← │ -│ │ -│ Test result │ -│ Do you want to proceed? │ -│ Do you want to proceed? │ -│ │ -│ ● 1. Allow once │ -│ 2. Allow for this session │ -│ 3. No, suggest changes (esc) │ -│ │ -╰──────────────────────────────────────────────────────────────────────────╯" -`; - -exports[` > Confirmation Handling > renders confirmation with permanent approval enabled 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────╮ -│ ? confirm-tool A tool for testing ← │ -│ │ -│ Test result │ -│ Do you want to proceed? │ -│ Do you want to proceed? │ -│ │ -│ ● 1. Allow once │ -│ 2. Allow for this session │ -│ 3. Allow for all future sessions │ -│ 4. No, suggest changes (esc) │ -│ │ -╰──────────────────────────────────────────────────────────────────────────╯" -`; - -exports[` > Confirmation Handling > shows confirmation dialog for first confirming tool only 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────╮ -│ ? first-confirm A tool for testing ← │ -│ │ -│ Test result │ -│ Confirm first tool │ -│ Do you want to proceed? │ -│ │ -│ ● 1. Allow once │ -│ 2. Allow for this session │ -│ 3. No, suggest changes (esc) │ -│ │ -│ │ -│ ? second-confirm A tool for testing │ -│ │ -│ Test result │ -╰──────────────────────────────────────────────────────────────────────────╯" -`; - -exports[` > Event-Driven Scheduler > hides confirming tools when event-driven scheduler is enabled 1`] = `""`; - -exports[` > Event-Driven Scheduler > renders nothing when only tool is in-progress AskUser with borderBottom=false 1`] = `""`; - -exports[` > Event-Driven Scheduler > shows only successful tools when mixed with confirming tools 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────╮ -│ ✓ success-tool A tool for testing │ -│ │ -│ Test result │ -╰──────────────────────────────────────────────────────────────────────────╯" -`; - exports[` > Golden Snapshots > renders empty tool calls array 1`] = `""`; exports[` > Golden Snapshots > renders header when scrolled 1`] = ` @@ -144,37 +74,21 @@ exports[` > Golden Snapshots > renders mixed tool calls incl │ ⊷ run_shell_command Run command │ │ │ │ Test result │ -│ │ -│ o write_file Write to file │ -│ │ -│ Test result │ ╰──────────────────────────────────────────────────────────────────────────╯" `; -exports[` > Golden Snapshots > renders multiple tool calls with different statuses 1`] = ` +exports[` > Golden Snapshots > renders multiple tool calls with different statuses (only visible ones) 1`] = ` "╭──────────────────────────────────────────────────────────────────────────╮ │ ✓ successful-tool This tool succeeded │ │ │ │ Test result │ │ │ -│ o pending-tool This tool is pending │ -│ │ -│ Test result │ -│ │ │ x error-tool This tool failed │ │ │ │ Test result │ ╰──────────────────────────────────────────────────────────────────────────╯" `; -exports[` > Golden Snapshots > renders shell command with yellow border 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────╮ -│ ✓ run_shell_command Execute shell command │ -│ │ -│ Test result │ -╰──────────────────────────────────────────────────────────────────────────╯" -`; - exports[` > Golden Snapshots > renders single successful tool call 1`] = ` "╭──────────────────────────────────────────────────────────────────────────╮ │ ✓ test-tool A tool for testing │ @@ -183,21 +97,6 @@ exports[` > Golden Snapshots > renders single successful too ╰──────────────────────────────────────────────────────────────────────────╯" `; -exports[` > Golden Snapshots > renders tool call awaiting confirmation 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────╮ -│ ? confirmation-tool This tool needs confirmation ← │ -│ │ -│ Test result │ -│ Are you sure you want to proceed? │ -│ Do you want to proceed? │ -│ │ -│ ● 1. Allow once │ -│ 2. Allow for this session │ -│ 3. No, suggest changes (esc) │ -│ │ -╰──────────────────────────────────────────────────────────────────────────╯" -`; - exports[` > Golden Snapshots > renders tool call with outputFile 1`] = ` "╭──────────────────────────────────────────────────────────────────────────╮ │ ✓ tool-with-file Tool that saved output to file │ @@ -216,14 +115,6 @@ exports[` > Golden Snapshots > renders two tool groups where ╰──────────────────────────────────────────────────────────────────────────╯ █" `; -exports[` > Golden Snapshots > renders when not focused 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────╮ -│ ✓ test-tool A tool for testing │ -│ │ -│ Test result │ -╰──────────────────────────────────────────────────────────────────────────╯" -`; - exports[` > Golden Snapshots > renders with limited terminal height 1`] = ` "╭──────────────────────────────────────────────────────────────────────────╮ │ ✓ tool-with-result Tool with output │ From 0e85e021dcfdbe7abb2594f38f516ba3bb7ef33e Mon Sep 17 00:00:00 2001 From: Abhijit Balaji Date: Wed, 11 Feb 2026 16:49:48 -0800 Subject: [PATCH 11/44] feat(cli): deprecate --allowed-tools and excludeTools in favor of policy engine (#18508) --- docs/cli/cli-reference.md | 46 +++--- docs/cli/enterprise.md | 11 +- docs/get-started/configuration-v1.md | 8 +- docs/tools/shell.md | 9 +- packages/cli/src/config/config.ts | 3 +- packages/cli/src/gemini.tsx | 20 +++ packages/core/src/config/config.ts | 13 +- .../core/src/policy/policy-engine.test.ts | 150 ++++++++++++++++++ packages/core/src/policy/policy-engine.ts | 106 ++++++++++++- 9 files changed, 327 insertions(+), 39 deletions(-) diff --git a/docs/cli/cli-reference.md b/docs/cli/cli-reference.md index d1094a15e2..8199445625 100644 --- a/docs/cli/cli-reference.md +++ b/docs/cli/cli-reference.md @@ -27,29 +27,29 @@ and parameters. ## CLI Options -| Option | Alias | Type | Default | Description | -| -------------------------------- | ----- | ------- | --------- | ---------------------------------------------------------------------------------------------------------- | -| `--debug` | `-d` | boolean | `false` | Run in debug mode with verbose logging | -| `--version` | `-v` | - | - | Show CLI version number and exit | -| `--help` | `-h` | - | - | Show help information | -| `--model` | `-m` | string | `auto` | Model to use. See [Model Selection](#model-selection) for available values. | -| `--prompt` | `-p` | string | - | Prompt text. Appended to stdin input if provided. **Deprecated:** Use positional arguments instead. | -| `--prompt-interactive` | `-i` | string | - | Execute prompt and continue in interactive mode | -| `--sandbox` | `-s` | boolean | `false` | Run in a sandboxed environment for safer execution | -| `--approval-mode` | - | string | `default` | Approval mode for tool execution. Choices: `default`, `auto_edit`, `yolo` | -| `--yolo` | `-y` | boolean | `false` | **Deprecated.** Auto-approve all actions. Use `--approval-mode=yolo` instead. | -| `--experimental-acp` | - | boolean | - | Start in ACP (Agent Code Pilot) mode. **Experimental feature.** | -| `--experimental-zed-integration` | - | boolean | - | Run in Zed editor integration mode. **Experimental feature.** | -| `--allowed-mcp-server-names` | - | array | - | Allowed MCP server names (comma-separated or multiple flags) | -| `--allowed-tools` | - | array | - | Tools that are allowed to run without confirmation (comma-separated or multiple flags) | -| `--extensions` | `-e` | array | - | List of extensions to use. If not provided, all extensions are enabled (comma-separated or multiple flags) | -| `--list-extensions` | `-l` | boolean | - | List all available extensions and exit | -| `--resume` | `-r` | string | - | Resume a previous session. Use `"latest"` for most recent or index number (e.g. `--resume 5`) | -| `--list-sessions` | - | boolean | - | List available sessions for the current project and exit | -| `--delete-session` | - | string | - | Delete a session by index number (use `--list-sessions` to see available sessions) | -| `--include-directories` | - | array | - | Additional directories to include in the workspace (comma-separated or multiple flags) | -| `--screen-reader` | - | boolean | - | Enable screen reader mode for accessibility | -| `--output-format` | `-o` | string | `text` | The format of the CLI output. Choices: `text`, `json`, `stream-json` | +| Option | Alias | Type | Default | Description | +| -------------------------------- | ----- | ------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `--debug` | `-d` | boolean | `false` | Run in debug mode with verbose logging | +| `--version` | `-v` | - | - | Show CLI version number and exit | +| `--help` | `-h` | - | - | Show help information | +| `--model` | `-m` | string | `auto` | Model to use. See [Model Selection](#model-selection) for available values. | +| `--prompt` | `-p` | string | - | Prompt text. Appended to stdin input if provided. **Deprecated:** Use positional arguments instead. | +| `--prompt-interactive` | `-i` | string | - | Execute prompt and continue in interactive mode | +| `--sandbox` | `-s` | boolean | `false` | Run in a sandboxed environment for safer execution | +| `--approval-mode` | - | string | `default` | Approval mode for tool execution. Choices: `default`, `auto_edit`, `yolo` | +| `--yolo` | `-y` | boolean | `false` | **Deprecated.** Auto-approve all actions. Use `--approval-mode=yolo` instead. | +| `--experimental-acp` | - | boolean | - | Start in ACP (Agent Code Pilot) mode. **Experimental feature.** | +| `--experimental-zed-integration` | - | boolean | - | Run in Zed editor integration mode. **Experimental feature.** | +| `--allowed-mcp-server-names` | - | array | - | Allowed MCP server names (comma-separated or multiple flags) | +| `--allowed-tools` | - | array | - | **Deprecated.** Use the [Policy Engine](../core/policy-engine.md) instead. Tools that are allowed to run without confirmation (comma-separated or multiple flags) | +| `--extensions` | `-e` | array | - | List of extensions to use. If not provided, all extensions are enabled (comma-separated or multiple flags) | +| `--list-extensions` | `-l` | boolean | - | List all available extensions and exit | +| `--resume` | `-r` | string | - | Resume a previous session. Use `"latest"` for most recent or index number (e.g. `--resume 5`) | +| `--list-sessions` | - | boolean | - | List available sessions for the current project and exit | +| `--delete-session` | - | string | - | Delete a session by index number (use `--list-sessions` to see available sessions) | +| `--include-directories` | - | array | - | Additional directories to include in the workspace (comma-separated or multiple flags) | +| `--screen-reader` | - | boolean | - | Enable screen reader mode for accessibility | +| `--output-format` | `-o` | string | `text` | The format of the CLI output. Choices: `text`, `json`, `stream-json` | ## Model selection diff --git a/docs/cli/enterprise.md b/docs/cli/enterprise.md index f22ec81c37..861fc68c71 100644 --- a/docs/cli/enterprise.md +++ b/docs/cli/enterprise.md @@ -223,9 +223,9 @@ gemini ## Restricting tool access You can significantly enhance security by controlling which tools the Gemini -model can use. This is achieved through the `tools.core` and `tools.exclude` -settings. For a list of available tools, see the -[Tools documentation](../tools/index.md). +model can use. This is achieved through the `tools.core` setting and the +[Policy Engine](../core/policy-engine.md). For a list of available tools, see +the [Tools documentation](../tools/index.md). ### Allowlisting with `coreTools` @@ -243,7 +243,10 @@ on the approved list. } ``` -### Blocklisting with `excludeTools` +### Blocklisting with `excludeTools` (Deprecated) + +> **Deprecated:** Use the [Policy Engine](../core/policy-engine.md) for more +> robust control. Alternatively, you can add specific tools that are considered dangerous in your environment to a blocklist. diff --git a/docs/get-started/configuration-v1.md b/docs/get-started/configuration-v1.md index 050dce32b6..cd1325b977 100644 --- a/docs/get-started/configuration-v1.md +++ b/docs/get-started/configuration-v1.md @@ -166,19 +166,21 @@ a few things you can try in order of recommendation: - **Default:** All tools available for use by the Gemini model. - **Example:** `"coreTools": ["ReadFileTool", "GlobTool", "ShellTool(ls)"]`. -- **`allowedTools`** (array of strings): +- **`allowedTools`** (array of strings) [DEPRECATED]: - **Default:** `undefined` - **Description:** A list of tool names that will bypass the confirmation dialog. This is useful for tools that you trust and use frequently. The - match semantics are the same as `coreTools`. + match semantics are the same as `coreTools`. **Deprecated**: Use the + [Policy Engine](../core/policy-engine.md) instead. - **Example:** `"allowedTools": ["ShellTool(git status)"]`. -- **`excludeTools`** (array of strings): +- **`excludeTools`** (array of strings) [DEPRECATED]: - **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. + **Deprecated**: Use the [Policy Engine](../core/policy-engine.md) instead. - **Default**: No tools excluded. - **Example:** `"excludeTools": ["run_shell_command", "findFiles"]`. - **Security Note:** Command-specific restrictions in `excludeTools` for diff --git a/docs/tools/shell.md b/docs/tools/shell.md index 0bb4b68244..48854e82f1 100644 --- a/docs/tools/shell.md +++ b/docs/tools/shell.md @@ -167,10 +167,11 @@ configuration file. `"tools": {"core": ["run_shell_command(git)"]}` will only allow `git` commands. Including the generic `run_shell_command` acts as a wildcard, allowing any command not explicitly blocked. -- `tools.exclude`: To block specific commands, add entries to the `exclude` list - under the `tools` category in the format `run_shell_command()`. For - example, `"tools": {"exclude": ["run_shell_command(rm)"]}` will block `rm` - commands. +- `tools.exclude` [DEPRECATED]: To block specific commands, use the + [Policy Engine](../core/policy-engine.md). Historically, this setting allowed + adding entries to the `exclude` list under the `tools` category in the format + `run_shell_command()`. For example, + `"tools": {"exclude": ["run_shell_command(rm)"]}` will block `rm` commands. The validation logic is designed to be secure and flexible: diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index f164ce77d8..ea7d6f72a5 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -177,7 +177,8 @@ export async function parseArguments( type: 'array', string: true, nargs: 1, - description: 'Tools that are allowed to run without confirmation', + description: + '[DEPRECATED: Use Policy Engine instead See https://geminicli.com/docs/core/policy-engine] Tools that are allowed to run without confirmation', coerce: (tools: string[]) => // Handle comma-separated values tools.flatMap((tool) => tool.split(',').map((t) => t.trim())), diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index a18f3ace37..e138cfe03a 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -361,6 +361,26 @@ export async function main() { const argv = await parseArguments(settings.merged); parseArgsHandle?.end(); + if ( + (argv.allowedTools && argv.allowedTools.length > 0) || + (settings.merged.tools?.allowed && settings.merged.tools.allowed.length > 0) + ) { + coreEvents.emitFeedback( + 'warning', + 'Warning: --allowed-tools cli argument and tools.allowed in settings.json are deprecated and will be removed in 1.0: Migrate to Policy Engine: https://geminicli.com/docs/core/policy-engine/', + ); + } + + if ( + settings.merged.tools?.exclude && + settings.merged.tools.exclude.length > 0 + ) { + coreEvents.emitFeedback( + 'warning', + 'Warning: tools.exclude in settings.json is deprecated and will be removed in 1.0. Migrate to Policy Engine: https://geminicli.com/docs/core/policy-engine/', + ); + } + if (argv.startupMessages) { argv.startupMessages.forEach((msg) => { coreEvents.emitFeedback('info', msg); diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 6d811799bc..db4085c1fa 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -383,7 +383,9 @@ export interface ConfigParameters { question?: string; coreTools?: string[]; + /** @deprecated Use Policy Engine instead */ allowedTools?: string[]; + /** @deprecated Use Policy Engine instead */ excludeTools?: string[]; toolDiscoveryCommand?: string; toolCallCommand?: string; @@ -516,7 +518,9 @@ export class Config { private readonly question: string | undefined; private readonly coreTools: string[] | undefined; + /** @deprecated Use Policy Engine instead */ private readonly allowedTools: string[] | undefined; + /** @deprecated Use Policy Engine instead */ private readonly excludeTools: string[] | undefined; private readonly toolDiscoveryCommand: string | undefined; private readonly toolCallCommand: string | undefined; @@ -1487,11 +1491,12 @@ export class Config { /** * All the excluded tools from static configuration, loaded extensions, or - * other sources. + * other sources (like the Policy Engine). * * May change over time. */ getExcludeTools(): Set | undefined { + // Right now this is present for backward compatibility with settings.json exclude const excludeToolsSet = new Set([...(this.excludeTools ?? [])]); for (const extension of this.getExtensionLoader().getExtensions()) { if (!extension.isActive) { @@ -1501,6 +1506,12 @@ export class Config { excludeToolsSet.add(tool); } } + + const policyExclusions = this.policyEngine.getExcludedTools(); + for (const tool of policyExclusions) { + excludeToolsSet.add(tool); + } + return excludeToolsSet; } diff --git a/packages/core/src/policy/policy-engine.test.ts b/packages/core/src/policy/policy-engine.test.ts index 59b0fd8106..26aecaa1eb 100644 --- a/packages/core/src/policy/policy-engine.test.ts +++ b/packages/core/src/policy/policy-engine.test.ts @@ -2031,6 +2031,156 @@ describe('PolicyEngine', () => { }); }); + describe('getExcludedTools', () => { + interface TestCase { + name: string; + rules: PolicyRule[]; + approvalMode?: ApprovalMode; + nonInteractive?: boolean; + expected: string[]; + } + + const testCases: TestCase[] = [ + { + name: 'should return empty set when no rules provided', + rules: [], + expected: [], + }, + { + name: 'should include tools with DENY decision', + rules: [ + { toolName: 'tool1', decision: PolicyDecision.DENY }, + { toolName: 'tool2', decision: PolicyDecision.ALLOW }, + ], + expected: ['tool1'], + }, + { + name: 'should respect priority and ignore lower priority rules (DENY wins)', + rules: [ + { toolName: 'tool1', decision: PolicyDecision.DENY, priority: 100 }, + { toolName: 'tool1', decision: PolicyDecision.ALLOW, priority: 10 }, + ], + expected: ['tool1'], + }, + { + name: 'should respect priority and ignore lower priority rules (ALLOW wins)', + rules: [ + { toolName: 'tool1', decision: PolicyDecision.ALLOW, priority: 100 }, + { toolName: 'tool1', decision: PolicyDecision.DENY, priority: 10 }, + ], + expected: [], + }, + { + name: 'should NOT include ASK_USER tools even in non-interactive mode', + rules: [{ toolName: 'tool1', decision: PolicyDecision.ASK_USER }], + nonInteractive: true, + expected: [], + }, + { + name: 'should ignore rules with argsPattern', + rules: [ + { + toolName: 'tool1', + decision: PolicyDecision.DENY, + argsPattern: /something/, + }, + ], + expected: [], + }, + { + name: 'should respect approval mode (PLAN mode)', + rules: [ + { + toolName: 'tool1', + decision: PolicyDecision.DENY, + modes: [ApprovalMode.PLAN], + }, + ], + approvalMode: ApprovalMode.PLAN, + expected: ['tool1'], + }, + { + name: 'should respect approval mode (DEFAULT mode)', + rules: [ + { + toolName: 'tool1', + decision: PolicyDecision.DENY, + modes: [ApprovalMode.PLAN], + }, + ], + approvalMode: ApprovalMode.DEFAULT, + expected: [], + }, + { + name: 'should respect wildcard ALLOW rules (e.g. YOLO mode)', + rules: [ + { + decision: PolicyDecision.ALLOW, + priority: 999, + modes: [ApprovalMode.YOLO], + }, + { + toolName: 'dangerous-tool', + decision: PolicyDecision.DENY, + priority: 10, + }, + ], + approvalMode: ApprovalMode.YOLO, + expected: [], + }, + { + name: 'should respect server wildcard DENY', + rules: [{ toolName: 'server__*', decision: PolicyDecision.DENY }], + expected: ['server__*'], + }, + { + name: 'should expand server wildcard for specific tools if already processed', + rules: [ + { + toolName: 'server__*', + decision: PolicyDecision.DENY, + priority: 100, + }, + { + toolName: 'server__tool1', + decision: PolicyDecision.DENY, + priority: 10, + }, + ], + expected: ['server__*', 'server__tool1'], + }, + { + name: 'should NOT exclude tool if covered by a higher priority wildcard ALLOW', + rules: [ + { + toolName: 'server__*', + decision: PolicyDecision.ALLOW, + priority: 100, + }, + { + toolName: 'server__tool1', + decision: PolicyDecision.DENY, + priority: 10, + }, + ], + expected: [], + }, + ]; + + it.each(testCases)( + '$name', + ({ rules, approvalMode, nonInteractive, expected }) => { + engine = new PolicyEngine({ + rules, + approvalMode: approvalMode ?? ApprovalMode.DEFAULT, + nonInteractive: nonInteractive ?? false, + }); + const excluded = engine.getExcludedTools(); + expect(Array.from(excluded).sort()).toEqual(expected.sort()); + }, + ); + }); + describe('YOLO mode with ask_user tool', () => { it('should return ASK_USER for ask_user tool even in YOLO mode', async () => { const rules: PolicyRule[] = [ diff --git a/packages/core/src/policy/policy-engine.ts b/packages/core/src/policy/policy-engine.ts index 8a643c8930..1fc5e7cde5 100644 --- a/packages/core/src/policy/policy-engine.ts +++ b/packages/core/src/policy/policy-engine.ts @@ -26,6 +26,22 @@ import { } from '../utils/shell-utils.js'; import { getToolAliases } from '../tools/tool-names.js'; +function isWildcardPattern(name: string): boolean { + return name.endsWith('__*'); +} + +function getWildcardPrefix(pattern: string): string { + return pattern.slice(0, -3); +} + +function matchesWildcard(pattern: string, toolName: string): boolean { + if (!isWildcardPattern(pattern)) { + return false; + } + const prefix = getWildcardPrefix(pattern); + return toolName.startsWith(prefix + '__'); +} + function ruleMatches( rule: PolicyRule | SafetyCheckerRule, toolCall: FunctionCall, @@ -43,8 +59,8 @@ function ruleMatches( // Check tool name if specified if (rule.toolName) { // Support wildcard patterns: "serverName__*" matches "serverName__anyTool" - if (rule.toolName.endsWith('__*')) { - const prefix = rule.toolName.slice(0, -3); // Remove "__*" + if (isWildcardPattern(rule.toolName)) { + const prefix = getWildcardPrefix(rule.toolName); if (serverName !== undefined) { // Robust check: if serverName is provided, it MUST match the prefix exactly. // This prevents "malicious-server" from spoofing "trusted-server" by naming itself "trusted-server__malicious". @@ -53,7 +69,7 @@ function ruleMatches( } } // Always verify the prefix, even if serverName matched - if (!toolCall.name || !toolCall.name.startsWith(prefix + '__')) { + if (!toolCall.name || !matchesWildcard(rule.toolName, toolCall.name)) { return false; } } else if (toolCall.name !== rule.toolName) { @@ -509,6 +525,90 @@ export class PolicyEngine { return this.hookCheckers; } + /** + * Get tools that are effectively denied by the current rules. + * This takes into account: + * 1. Global rules (no argsPattern) + * 2. Priority order (higher priority wins) + * 3. Non-interactive mode (ASK_USER becomes DENY) + */ + getExcludedTools(): Set { + const excludedTools = new Set(); + const processedTools = new Set(); + let globalVerdict: PolicyDecision | undefined; + + for (const rule of this.rules) { + // We only care about rules without args pattern for exclusion from the model + if (rule.argsPattern) { + continue; + } + + // Check if rule applies to current approval mode + if (rule.modes && rule.modes.length > 0) { + if (!rule.modes.includes(this.approvalMode)) { + continue; + } + } + + // Handle Global Rules + if (!rule.toolName) { + if (globalVerdict === undefined) { + globalVerdict = rule.decision; + if (globalVerdict !== PolicyDecision.DENY) { + // Global ALLOW/ASK found. + // Since rules are sorted by priority, this overrides any lower-priority rules. + // We can stop processing because nothing else will be excluded. + break; + } + // If Global DENY, we continue to find specific tools to add to excluded set + } + continue; + } + + const toolName = rule.toolName; + + // Check if already processed (exact match) + if (processedTools.has(toolName)) { + continue; + } + + // Check if covered by a processed wildcard + let coveredByWildcard = false; + for (const processed of processedTools) { + if ( + isWildcardPattern(processed) && + matchesWildcard(processed, toolName) + ) { + // It's covered by a higher-priority wildcard rule. + // If that wildcard rule resulted in exclusion, this tool should also be excluded. + if (excludedTools.has(processed)) { + excludedTools.add(toolName); + } + coveredByWildcard = true; + break; + } + } + if (coveredByWildcard) { + continue; + } + + processedTools.add(toolName); + + // Determine decision + let decision: PolicyDecision; + if (globalVerdict !== undefined) { + decision = globalVerdict; + } else { + decision = rule.decision; + } + + if (decision === PolicyDecision.DENY) { + excludedTools.add(toolName); + } + } + return excludedTools; + } + private applyNonInteractiveMode(decision: PolicyDecision): PolicyDecision { // In non-interactive mode, ASK_USER becomes DENY if (this.nonInteractive && decision === PolicyDecision.ASK_USER) { From a1148ea1f189e9839bccf33e6a9afe6b45e92729 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Wed, 11 Feb 2026 20:56:43 -0500 Subject: [PATCH 12/44] fix(workflows): improve maintainer detection for automated PR actions (#18869) --- .../gemini-scheduled-stale-pr-closer.yml | 65 ++++++++++++++----- .../pr-contribution-guidelines-notifier.yml | 26 +++++++- 2 files changed, 73 insertions(+), 18 deletions(-) diff --git a/.github/workflows/gemini-scheduled-stale-pr-closer.yml b/.github/workflows/gemini-scheduled-stale-pr-closer.yml index 90d7417b05..bd7fd0ddc9 100644 --- a/.github/workflows/gemini-scheduled-stale-pr-closer.yml +++ b/.github/workflows/gemini-scheduled-stale-pr-closer.yml @@ -43,23 +43,56 @@ jobs: // 1. Fetch maintainers for verification let maintainerLogins = new Set(); - let teamFetchSucceeded = false; - try { - const members = await github.paginate(github.rest.teams.listMembersInOrg, { - org: context.repo.owner, - team_slug: 'gemini-cli-maintainers' - }); - maintainerLogins = new Set(members.map(m => m.login.toLowerCase())); - teamFetchSucceeded = true; - core.info(`Successfully fetched ${maintainerLogins.size} team members from gemini-cli-maintainers`); - } catch (e) { - core.warning(`Failed to fetch team members from gemini-cli-maintainers: ${e.message}. Falling back to author_association only.`); + const teams = ['gemini-cli-maintainers', 'gemini-cli-askmode-approvers', 'gemini-cli-docs']; + + for (const team_slug of teams) { + try { + const members = await github.paginate(github.rest.teams.listMembersInOrg, { + org: context.repo.owner, + team_slug: team_slug + }); + for (const m of members) maintainerLogins.add(m.login.toLowerCase()); + core.info(`Successfully fetched ${members.length} team members from ${team_slug}`); + } catch (e) { + core.warning(`Failed to fetch team members from ${team_slug}: ${e.message}`); + } } - const isMaintainer = (login, assoc) => { + const isGooglerCache = new Map(); + const isGoogler = async (login) => { + if (isGooglerCache.has(login)) return isGooglerCache.get(login); + + try { + // Check membership in 'googlers' or 'google' orgs + const orgs = ['googlers', 'google']; + for (const org of orgs) { + try { + await github.rest.orgs.checkMembershipForUser({ + org: org, + username: login + }); + core.info(`User ${login} is a member of ${org} organization.`); + isGooglerCache.set(login, true); + return true; + } catch (e) { + // 404 just means they aren't a member, which is fine + if (e.status !== 404) throw e; + } + } + } catch (e) { + core.warning(`Failed to check org membership for ${login}: ${e.message}`); + } + + isGooglerCache.set(login, false); + return false; + }; + + const isMaintainer = async (login, assoc) => { const isTeamMember = maintainerLogins.has(login.toLowerCase()); const isRepoMaintainer = ['OWNER', 'MEMBER', 'COLLABORATOR'].includes(assoc); - return isTeamMember || isRepoMaintainer; + if (isTeamMember || isRepoMaintainer) return true; + + return await isGoogler(login); }; // 2. Determine which PRs to check @@ -81,7 +114,7 @@ jobs: } for (const pr of prs) { - const maintainerPr = isMaintainer(pr.user.login, pr.author_association); + const maintainerPr = await isMaintainer(pr.user.login, pr.author_association); const isBot = pr.user.type === 'Bot' || pr.user.login.endsWith('[bot]'); // Detection Logic for Linked Issues @@ -175,7 +208,7 @@ jobs: pull_number: pr.number }); for (const r of reviews) { - if (isMaintainer(r.user.login, r.author_association)) { + if (await isMaintainer(r.user.login, r.author_association)) { const d = new Date(r.submitted_at || r.updated_at); if (d > lastActivity) lastActivity = d; } @@ -186,7 +219,7 @@ jobs: issue_number: pr.number }); for (const c of comments) { - if (isMaintainer(c.user.login, c.author_association)) { + if (await isMaintainer(c.user.login, c.author_association)) { const d = new Date(c.updated_at); if (d > lastActivity) lastActivity = d; } diff --git a/.github/workflows/pr-contribution-guidelines-notifier.yml b/.github/workflows/pr-contribution-guidelines-notifier.yml index fdabd20f3d..2658520371 100644 --- a/.github/workflows/pr-contribution-guidelines-notifier.yml +++ b/.github/workflows/pr-contribution-guidelines-notifier.yml @@ -35,9 +35,31 @@ jobs: const pr_number = context.payload.pull_request.number; // 1. Check if the PR author is a maintainer + const isGoogler = async (login) => { + try { + const orgs = ['googlers', 'google']; + for (const org of orgs) { + try { + await github.rest.orgs.checkMembershipForUser({ + org: org, + username: login + }); + return true; + } catch (e) { + if (e.status !== 404) throw e; + } + } + } catch (e) { + core.warning(`Failed to check org membership for ${login}: ${e.message}`); + } + return false; + }; + const authorAssociation = context.payload.pull_request.author_association; - if (['OWNER', 'MEMBER', 'COLLABORATOR'].includes(authorAssociation)) { - core.info(`${username} is a maintainer (Association: ${authorAssociation}). No notification needed.`); + const isRepoMaintainer = ['OWNER', 'MEMBER', 'COLLABORATOR'].includes(authorAssociation); + + if (isRepoMaintainer || await isGoogler(username)) { + core.info(`${username} is a maintainer or Googler. No notification needed.`); return; } From fad9f462734670cc9431c9da34cc5183e9199b86 Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Wed, 11 Feb 2026 20:49:30 -0500 Subject: [PATCH 13/44] refactor(cli): consolidate useToolScheduler and delete legacy implementation (#18567) --- packages/cli/src/test-utils/mockConfig.ts | 1 + packages/cli/src/ui/App.test.tsx | 4 - packages/cli/src/ui/AppContainer.test.tsx | 2 +- .../useToolScheduler.test.ts.snap | 97 -- .../cli/src/ui/hooks/useGeminiStream.test.tsx | 1 - .../ui/hooks/useReactToolScheduler.test.ts | 77 - .../cli/src/ui/hooks/useReactToolScheduler.ts | 221 --- .../src/ui/hooks/useShellInactivityStatus.ts | 2 +- .../hooks/useToolExecutionScheduler.test.ts | 525 ------ .../src/ui/hooks/useToolExecutionScheduler.ts | 253 --- .../cli/src/ui/hooks/useToolScheduler.test.ts | 1534 +++++------------ packages/cli/src/ui/hooks/useToolScheduler.ts | 302 +++- .../ui/hooks/useTurnActivityMonitor.test.ts | 2 +- .../src/ui/hooks/useTurnActivityMonitor.ts | 2 +- 14 files changed, 721 insertions(+), 2302 deletions(-) delete mode 100644 packages/cli/src/ui/hooks/__snapshots__/useToolScheduler.test.ts.snap delete mode 100644 packages/cli/src/ui/hooks/useReactToolScheduler.test.ts delete mode 100644 packages/cli/src/ui/hooks/useReactToolScheduler.ts delete mode 100644 packages/cli/src/ui/hooks/useToolExecutionScheduler.test.ts delete mode 100644 packages/cli/src/ui/hooks/useToolExecutionScheduler.ts diff --git a/packages/cli/src/test-utils/mockConfig.ts b/packages/cli/src/test-utils/mockConfig.ts index ac2176c0e3..0a02e01889 100644 --- a/packages/cli/src/test-utils/mockConfig.ts +++ b/packages/cli/src/test-utils/mockConfig.ts @@ -18,6 +18,7 @@ export const createMockConfig = (overrides: Partial = {}): Config => getSandbox: vi.fn(() => undefined), getQuestion: vi.fn(() => ''), isInteractive: vi.fn(() => false), + isInitialized: vi.fn(() => true), setTerminalBackground: vi.fn(), storage: { getProjectTempDir: vi.fn().mockReturnValue('/tmp/gemini-test'), diff --git a/packages/cli/src/ui/App.test.tsx b/packages/cli/src/ui/App.test.tsx index 6a19d80184..7d817f44f5 100644 --- a/packages/cli/src/ui/App.test.tsx +++ b/packages/cli/src/ui/App.test.tsx @@ -220,10 +220,6 @@ describe('App', () => { } as UIState; const configWithExperiment = makeFakeConfig(); - vi.spyOn( - configWithExperiment, - 'isEventDrivenSchedulerEnabled', - ).mockReturnValue(true); vi.spyOn(configWithExperiment, 'isTrustedFolder').mockReturnValue(true); vi.spyOn(configWithExperiment, 'getIdeMode').mockReturnValue(false); diff --git a/packages/cli/src/ui/AppContainer.test.tsx b/packages/cli/src/ui/AppContainer.test.tsx index b6fdd53325..0c333176e0 100644 --- a/packages/cli/src/ui/AppContainer.test.tsx +++ b/packages/cli/src/ui/AppContainer.test.tsx @@ -20,7 +20,7 @@ import { cleanup } from 'ink-testing-library'; import { act, useContext, type ReactElement } from 'react'; import { AppContainer } from './AppContainer.js'; import { SettingsContext } from './contexts/SettingsContext.js'; -import { type TrackedToolCall } from './hooks/useReactToolScheduler.js'; +import { type TrackedToolCall } from './hooks/useToolScheduler.js'; import { type Config, makeFakeConfig, diff --git a/packages/cli/src/ui/hooks/__snapshots__/useToolScheduler.test.ts.snap b/packages/cli/src/ui/hooks/__snapshots__/useToolScheduler.test.ts.snap deleted file mode 100644 index 3195316980..0000000000 --- a/packages/cli/src/ui/hooks/__snapshots__/useToolScheduler.test.ts.snap +++ /dev/null @@ -1,97 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`useReactToolScheduler > should handle live output updates 1`] = ` -{ - "callId": "liveCall", - "contentLength": 12, - "data": undefined, - "error": undefined, - "errorType": undefined, - "outputFile": undefined, - "responseParts": [ - { - "functionResponse": { - "id": "liveCall", - "name": "mockToolWithLiveOutput", - "response": { - "output": "Final output", - }, - }, - }, - ], - "resultDisplay": "Final display", -} -`; - -exports[`useReactToolScheduler > should handle tool requiring confirmation - approved 1`] = ` -{ - "callId": "callConfirm", - "contentLength": 16, - "data": undefined, - "error": undefined, - "errorType": undefined, - "outputFile": undefined, - "responseParts": [ - { - "functionResponse": { - "id": "callConfirm", - "name": "mockToolRequiresConfirmation", - "response": { - "output": "Confirmed output", - }, - }, - }, - ], - "resultDisplay": "Confirmed display", -} -`; - -exports[`useReactToolScheduler > should handle tool requiring confirmation - cancelled by user 1`] = ` -{ - "callId": "callConfirmCancel", - "contentLength": 59, - "error": undefined, - "errorType": undefined, - "responseParts": [ - { - "functionResponse": { - "id": "callConfirmCancel", - "name": "mockToolRequiresConfirmation", - "response": { - "error": "[Operation Cancelled] Reason: User cancelled the operation.", - }, - }, - }, - ], - "resultDisplay": { - "fileDiff": "Mock tool requires confirmation", - "fileName": "mockToolRequiresConfirmation.ts", - "filePath": undefined, - "newContent": undefined, - "originalContent": undefined, - }, -} -`; - -exports[`useReactToolScheduler > should schedule and execute a tool call successfully 1`] = ` -{ - "callId": "call1", - "contentLength": 11, - "data": undefined, - "error": undefined, - "errorType": undefined, - "outputFile": undefined, - "responseParts": [ - { - "functionResponse": { - "id": "call1", - "name": "mockTool", - "response": { - "output": "Tool output", - }, - }, - }, - ], - "resultDisplay": "Formatted tool output", -} -`; diff --git a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx index 294c537af4..ed7168667a 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx +++ b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx @@ -246,7 +246,6 @@ describe('useGeminiStream', () => { getContentGenerator: vi.fn(), isInteractive: () => false, getExperiments: () => {}, - isEventDrivenSchedulerEnabled: vi.fn(() => false), getMaxSessionTurns: vi.fn(() => 100), isJitContextEnabled: vi.fn(() => false), getGlobalMemory: vi.fn(() => ''), diff --git a/packages/cli/src/ui/hooks/useReactToolScheduler.test.ts b/packages/cli/src/ui/hooks/useReactToolScheduler.test.ts deleted file mode 100644 index ed2c64d212..0000000000 --- a/packages/cli/src/ui/hooks/useReactToolScheduler.test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import { CoreToolScheduler } from '@google/gemini-cli-core'; -import type { Config } from '@google/gemini-cli-core'; -import { renderHook } from '../../test-utils/render.js'; -import { vi, describe, it, expect, beforeEach } from 'vitest'; -import { useReactToolScheduler } from './useReactToolScheduler.js'; - -vi.mock('@google/gemini-cli-core', async (importOriginal) => { - const actual = - await importOriginal(); - return { - ...actual, - CoreToolScheduler: vi.fn(), - }; -}); - -const mockCoreToolScheduler = vi.mocked(CoreToolScheduler); - -describe('useReactToolScheduler', () => { - beforeEach(() => { - vi.clearAllMocks(); - }); - - it('only creates one instance of CoreToolScheduler even if props change', () => { - const onComplete = vi.fn(); - const getPreferredEditor = vi.fn(); - const config = {} as Config; - - const { rerender } = renderHook( - (props) => - useReactToolScheduler( - props.onComplete, - props.config, - props.getPreferredEditor, - ), - { - initialProps: { - onComplete, - config, - getPreferredEditor, - }, - }, - ); - - expect(mockCoreToolScheduler).toHaveBeenCalledTimes(1); - - // Rerender with a new onComplete function - const newOnComplete = vi.fn(); - rerender({ - onComplete: newOnComplete, - config, - getPreferredEditor, - }); - expect(mockCoreToolScheduler).toHaveBeenCalledTimes(1); - - // Rerender with a new getPreferredEditor function - const newGetPreferredEditor = vi.fn(); - rerender({ - onComplete: newOnComplete, - config, - getPreferredEditor: newGetPreferredEditor, - }); - expect(mockCoreToolScheduler).toHaveBeenCalledTimes(1); - - rerender({ - onComplete: newOnComplete, - config, - getPreferredEditor: newGetPreferredEditor, - }); - expect(mockCoreToolScheduler).toHaveBeenCalledTimes(1); - }); -}); diff --git a/packages/cli/src/ui/hooks/useReactToolScheduler.ts b/packages/cli/src/ui/hooks/useReactToolScheduler.ts deleted file mode 100644 index cd17b305b5..0000000000 --- a/packages/cli/src/ui/hooks/useReactToolScheduler.ts +++ /dev/null @@ -1,221 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import type { - Config, - ToolCallRequestInfo, - OutputUpdateHandler, - AllToolCallsCompleteHandler, - ToolCallsUpdateHandler, - ToolCall, - EditorType, - CompletedToolCall, - ExecutingToolCall, - ScheduledToolCall, - ValidatingToolCall, - WaitingToolCall, - CancelledToolCall, -} from '@google/gemini-cli-core'; -import { CoreToolScheduler } from '@google/gemini-cli-core'; -import { useCallback, useState, useMemo, useEffect, useRef } from 'react'; - -export type ScheduleFn = ( - request: ToolCallRequestInfo | ToolCallRequestInfo[], - signal: AbortSignal, -) => Promise; -export type MarkToolsAsSubmittedFn = (callIds: string[]) => void; -export type CancelAllFn = (signal: AbortSignal) => void; - -export type TrackedScheduledToolCall = ScheduledToolCall & { - responseSubmittedToGemini?: boolean; -}; -export type TrackedValidatingToolCall = ValidatingToolCall & { - responseSubmittedToGemini?: boolean; -}; -export type TrackedWaitingToolCall = WaitingToolCall & { - responseSubmittedToGemini?: boolean; -}; -export type TrackedExecutingToolCall = ExecutingToolCall & { - responseSubmittedToGemini?: boolean; -}; -export type TrackedCompletedToolCall = CompletedToolCall & { - responseSubmittedToGemini?: boolean; -}; -export type TrackedCancelledToolCall = CancelledToolCall & { - responseSubmittedToGemini?: boolean; -}; - -export type TrackedToolCall = - | TrackedScheduledToolCall - | TrackedValidatingToolCall - | TrackedWaitingToolCall - | TrackedExecutingToolCall - | TrackedCompletedToolCall - | TrackedCancelledToolCall; - -/** - * Legacy scheduler implementation based on CoreToolScheduler callbacks. - * - * This is currently the default implementation used by useGeminiStream. - * It will be phased out once the event-driven scheduler migration is complete. - */ -export function useReactToolScheduler( - onComplete: (tools: CompletedToolCall[]) => Promise, - config: Config, - getPreferredEditor: () => EditorType | undefined, -): [ - TrackedToolCall[], - ScheduleFn, - MarkToolsAsSubmittedFn, - React.Dispatch>, - CancelAllFn, - number, -] { - const [toolCallsForDisplay, setToolCallsForDisplay] = useState< - TrackedToolCall[] - >([]); - const [lastToolOutputTime, setLastToolOutputTime] = useState(0); - - const onCompleteRef = useRef(onComplete); - const getPreferredEditorRef = useRef(getPreferredEditor); - - useEffect(() => { - onCompleteRef.current = onComplete; - }, [onComplete]); - - useEffect(() => { - getPreferredEditorRef.current = getPreferredEditor; - }, [getPreferredEditor]); - - const outputUpdateHandler: OutputUpdateHandler = useCallback( - (toolCallId, outputChunk) => { - setLastToolOutputTime(Date.now()); - setToolCallsForDisplay((prevCalls) => - prevCalls.map((tc) => { - if (tc.request.callId === toolCallId && tc.status === 'executing') { - const executingTc = tc; - return { ...executingTc, liveOutput: outputChunk }; - } - return tc; - }), - ); - }, - [], - ); - - const allToolCallsCompleteHandler: AllToolCallsCompleteHandler = useCallback( - async (completedToolCalls) => { - await onCompleteRef.current(completedToolCalls); - }, - [], - ); - - const toolCallsUpdateHandler: ToolCallsUpdateHandler = useCallback( - (allCoreToolCalls: ToolCall[]) => { - setToolCallsForDisplay((prevTrackedCalls) => { - const prevCallsMap = new Map( - prevTrackedCalls.map((c) => [c.request.callId, c]), - ); - - return allCoreToolCalls.map((coreTc): TrackedToolCall => { - const existingTrackedCall = prevCallsMap.get(coreTc.request.callId); - - const responseSubmittedToGemini = - existingTrackedCall?.responseSubmittedToGemini ?? false; - - if (coreTc.status === 'executing') { - // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion - const liveOutput = (existingTrackedCall as TrackedExecutingToolCall) - ?.liveOutput; - return { - ...coreTc, - responseSubmittedToGemini, - liveOutput, - }; - } else if ( - coreTc.status === 'success' || - coreTc.status === 'error' || - coreTc.status === 'cancelled' - ) { - return { - ...coreTc, - responseSubmittedToGemini, - }; - } else { - return { - ...coreTc, - responseSubmittedToGemini, - }; - } - }); - }); - }, - [setToolCallsForDisplay], - ); - - const stableGetPreferredEditor = useCallback( - () => getPreferredEditorRef.current(), - [], - ); - - const scheduler = useMemo( - () => - new CoreToolScheduler({ - outputUpdateHandler, - onAllToolCallsComplete: allToolCallsCompleteHandler, - onToolCallsUpdate: toolCallsUpdateHandler, - getPreferredEditor: stableGetPreferredEditor, - config, - }), - [ - config, - outputUpdateHandler, - allToolCallsCompleteHandler, - toolCallsUpdateHandler, - stableGetPreferredEditor, - ], - ); - - const schedule: ScheduleFn = useCallback( - ( - request: ToolCallRequestInfo | ToolCallRequestInfo[], - signal: AbortSignal, - ) => { - setToolCallsForDisplay([]); - return scheduler.schedule(request, signal); - }, - [scheduler, setToolCallsForDisplay], - ); - - const markToolsAsSubmitted: MarkToolsAsSubmittedFn = useCallback( - (callIdsToMark: string[]) => { - setToolCallsForDisplay((prevCalls) => - prevCalls.map((tc) => - callIdsToMark.includes(tc.request.callId) - ? { ...tc, responseSubmittedToGemini: true } - : tc, - ), - ); - }, - [], - ); - - const cancelAllToolCalls = useCallback( - (signal: AbortSignal) => { - scheduler.cancelAll(signal); - }, - [scheduler], - ); - - return [ - toolCallsForDisplay, - schedule, - markToolsAsSubmitted, - setToolCallsForDisplay, - cancelAllToolCalls, - lastToolOutputTime, - ]; -} diff --git a/packages/cli/src/ui/hooks/useShellInactivityStatus.ts b/packages/cli/src/ui/hooks/useShellInactivityStatus.ts index d0e5c0706d..092e58baae 100644 --- a/packages/cli/src/ui/hooks/useShellInactivityStatus.ts +++ b/packages/cli/src/ui/hooks/useShellInactivityStatus.ts @@ -12,7 +12,7 @@ import { SHELL_SILENT_WORKING_TITLE_DELAY_MS, } from '../constants.js'; import type { StreamingState } from '../types.js'; -import { type TrackedToolCall } from './useReactToolScheduler.js'; +import { type TrackedToolCall } from './useToolScheduler.js'; interface ShellInactivityStatusProps { activePtyId: number | string | null | undefined; diff --git a/packages/cli/src/ui/hooks/useToolExecutionScheduler.test.ts b/packages/cli/src/ui/hooks/useToolExecutionScheduler.test.ts deleted file mode 100644 index 797109499b..0000000000 --- a/packages/cli/src/ui/hooks/useToolExecutionScheduler.test.ts +++ /dev/null @@ -1,525 +0,0 @@ -/** - * @license - * Copyright 2026 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 { useToolExecutionScheduler } from './useToolExecutionScheduler.js'; -import { - MessageBusType, - ToolConfirmationOutcome, - Scheduler, - type Config, - type MessageBus, - type CompletedToolCall, - type ToolCallConfirmationDetails, - type ToolCallsUpdateMessage, - type AnyDeclarativeTool, - type AnyToolInvocation, - ROOT_SCHEDULER_ID, -} from '@google/gemini-cli-core'; -import { createMockMessageBus } from '@google/gemini-cli-core/src/test-utils/mock-message-bus.js'; - -// Mock Core Scheduler -vi.mock('@google/gemini-cli-core', async (importOriginal) => { - const actual = - await importOriginal(); - return { - ...actual, - Scheduler: vi.fn().mockImplementation(() => ({ - schedule: vi.fn().mockResolvedValue([]), - cancelAll: vi.fn(), - })), - }; -}); - -const createMockTool = ( - overrides: Partial = {}, -): AnyDeclarativeTool => - ({ - name: 'test_tool', - displayName: 'Test Tool', - description: 'A test tool', - kind: 'function', - parameterSchema: {}, - isOutputMarkdown: false, - build: vi.fn(), - ...overrides, - }) as AnyDeclarativeTool; - -const createMockInvocation = ( - overrides: Partial = {}, -): AnyToolInvocation => - ({ - getDescription: () => 'Executing test tool', - shouldConfirmExecute: vi.fn(), - execute: vi.fn(), - params: {}, - toolLocations: [], - ...overrides, - }) as AnyToolInvocation; - -describe('useToolExecutionScheduler', () => { - let mockConfig: Config; - let mockMessageBus: MessageBus; - - beforeEach(() => { - vi.clearAllMocks(); - mockMessageBus = createMockMessageBus() as unknown as MessageBus; - mockConfig = { - getMessageBus: () => mockMessageBus, - } as unknown as Config; - }); - - afterEach(() => { - vi.clearAllMocks(); - }); - - it('initializes with empty tool calls', () => { - const { result } = renderHook(() => - useToolExecutionScheduler( - vi.fn().mockResolvedValue(undefined), - mockConfig, - () => undefined, - ), - ); - const [toolCalls] = result.current; - expect(toolCalls).toEqual([]); - }); - - it('updates tool calls when MessageBus emits TOOL_CALLS_UPDATE', () => { - const { result } = renderHook(() => - useToolExecutionScheduler( - vi.fn().mockResolvedValue(undefined), - mockConfig, - () => undefined, - ), - ); - - const mockToolCall = { - status: 'executing' as const, - request: { - callId: 'call-1', - name: 'test_tool', - args: {}, - isClientInitiated: false, - prompt_id: 'p1', - }, - tool: createMockTool(), - invocation: createMockInvocation(), - liveOutput: 'Loading...', - }; - - act(() => { - void mockMessageBus.publish({ - type: MessageBusType.TOOL_CALLS_UPDATE, - toolCalls: [mockToolCall], - schedulerId: ROOT_SCHEDULER_ID, - } as ToolCallsUpdateMessage); - }); - - const [toolCalls] = result.current; - expect(toolCalls).toHaveLength(1); - // Expect Core Object structure, not Display Object - expect(toolCalls[0]).toMatchObject({ - request: { callId: 'call-1', name: 'test_tool' }, - status: 'executing', // Core status - liveOutput: 'Loading...', - responseSubmittedToGemini: false, - }); - }); - - it('injects onConfirm callback for awaiting_approval tools (Adapter Pattern)', async () => { - const { result } = renderHook(() => - useToolExecutionScheduler( - vi.fn().mockResolvedValue(undefined), - mockConfig, - () => undefined, - ), - ); - - const mockToolCall = { - status: 'awaiting_approval' as const, - request: { - callId: 'call-1', - name: 'test_tool', - args: {}, - isClientInitiated: false, - prompt_id: 'p1', - }, - tool: createMockTool(), - invocation: createMockInvocation({ - getDescription: () => 'Confirming test tool', - }), - confirmationDetails: { type: 'info', title: 'Confirm', prompt: 'Sure?' }, - correlationId: 'corr-123', - }; - - act(() => { - void mockMessageBus.publish({ - type: MessageBusType.TOOL_CALLS_UPDATE, - toolCalls: [mockToolCall], - schedulerId: ROOT_SCHEDULER_ID, - } as ToolCallsUpdateMessage); - }); - - const [toolCalls] = result.current; - const call = toolCalls[0]; - if (call.status !== 'awaiting_approval') { - throw new Error('Expected status to be awaiting_approval'); - } - const confirmationDetails = - call.confirmationDetails as ToolCallConfirmationDetails; - - expect(confirmationDetails).toBeDefined(); - expect(typeof confirmationDetails.onConfirm).toBe('function'); - - // Test that onConfirm publishes to MessageBus - const publishSpy = vi.spyOn(mockMessageBus, 'publish'); - await confirmationDetails.onConfirm(ToolConfirmationOutcome.ProceedOnce); - - expect(publishSpy).toHaveBeenCalledWith({ - type: MessageBusType.TOOL_CONFIRMATION_RESPONSE, - correlationId: 'corr-123', - confirmed: true, - requiresUserConfirmation: false, - outcome: ToolConfirmationOutcome.ProceedOnce, - payload: undefined, - }); - }); - - it('injects onConfirm with payload (Inline Edit support)', async () => { - const { result } = renderHook(() => - useToolExecutionScheduler( - vi.fn().mockResolvedValue(undefined), - mockConfig, - () => undefined, - ), - ); - - const mockToolCall = { - status: 'awaiting_approval' as const, - request: { - callId: 'call-1', - name: 'test_tool', - args: {}, - isClientInitiated: false, - prompt_id: 'p1', - }, - tool: createMockTool(), - invocation: createMockInvocation(), - confirmationDetails: { type: 'edit', title: 'Edit', filePath: 'test.ts' }, - correlationId: 'corr-edit', - }; - - act(() => { - void mockMessageBus.publish({ - type: MessageBusType.TOOL_CALLS_UPDATE, - toolCalls: [mockToolCall], - schedulerId: ROOT_SCHEDULER_ID, - } as ToolCallsUpdateMessage); - }); - - const [toolCalls] = result.current; - const call = toolCalls[0]; - if (call.status !== 'awaiting_approval') { - throw new Error('Expected awaiting_approval'); - } - const confirmationDetails = - call.confirmationDetails as ToolCallConfirmationDetails; - - const publishSpy = vi.spyOn(mockMessageBus, 'publish'); - const mockPayload = { newContent: 'updated code' }; - await confirmationDetails.onConfirm( - ToolConfirmationOutcome.ProceedOnce, - mockPayload, - ); - - expect(publishSpy).toHaveBeenCalledWith({ - type: MessageBusType.TOOL_CONFIRMATION_RESPONSE, - correlationId: 'corr-edit', - confirmed: true, - requiresUserConfirmation: false, - outcome: ToolConfirmationOutcome.ProceedOnce, - payload: mockPayload, - }); - }); - - it('preserves responseSubmittedToGemini flag across updates', () => { - const { result } = renderHook(() => - useToolExecutionScheduler( - vi.fn().mockResolvedValue(undefined), - mockConfig, - () => undefined, - ), - ); - - const mockToolCall = { - status: 'success' as const, - request: { - callId: 'call-1', - name: 'test', - args: {}, - isClientInitiated: false, - prompt_id: 'p1', - }, - tool: createMockTool(), - invocation: createMockInvocation(), - response: { - callId: 'call-1', - resultDisplay: 'OK', - responseParts: [], - error: undefined, - errorType: undefined, - }, - }; - - // 1. Initial success - act(() => { - void mockMessageBus.publish({ - type: MessageBusType.TOOL_CALLS_UPDATE, - toolCalls: [mockToolCall], - schedulerId: ROOT_SCHEDULER_ID, - } as ToolCallsUpdateMessage); - }); - - // 2. Mark as submitted - act(() => { - const [, , markAsSubmitted] = result.current; - markAsSubmitted(['call-1']); - }); - - expect(result.current[0][0].responseSubmittedToGemini).toBe(true); - - // 3. Receive another update (should preserve the true flag) - act(() => { - void mockMessageBus.publish({ - type: MessageBusType.TOOL_CALLS_UPDATE, - toolCalls: [mockToolCall], - schedulerId: ROOT_SCHEDULER_ID, - } as ToolCallsUpdateMessage); - }); - - expect(result.current[0][0].responseSubmittedToGemini).toBe(true); - }); - - it('updates lastToolOutputTime when tools are executing', () => { - vi.useFakeTimers(); - const { result } = renderHook(() => - useToolExecutionScheduler( - vi.fn().mockResolvedValue(undefined), - mockConfig, - () => undefined, - ), - ); - - const startTime = Date.now(); - vi.advanceTimersByTime(1000); - - act(() => { - void mockMessageBus.publish({ - type: MessageBusType.TOOL_CALLS_UPDATE, - toolCalls: [ - { - status: 'executing' as const, - request: { - callId: 'call-1', - name: 'test', - args: {}, - isClientInitiated: false, - prompt_id: 'p1', - }, - tool: createMockTool(), - invocation: createMockInvocation(), - }, - ], - schedulerId: ROOT_SCHEDULER_ID, - } as ToolCallsUpdateMessage); - }); - - const [, , , , , lastOutputTime] = result.current; - expect(lastOutputTime).toBeGreaterThan(startTime); - vi.useRealTimers(); - }); - - it('delegates cancelAll to the Core Scheduler', () => { - const { result } = renderHook(() => - useToolExecutionScheduler( - vi.fn().mockResolvedValue(undefined), - mockConfig, - () => undefined, - ), - ); - - const [, , , , cancelAll] = result.current; - const signal = new AbortController().signal; - - // We need to find the mock instance of Scheduler - // Since we used vi.mock at top level, we can get it from vi.mocked(Scheduler) - const schedulerInstance = vi.mocked(Scheduler).mock.results[0].value; - - cancelAll(signal); - - expect(schedulerInstance.cancelAll).toHaveBeenCalled(); - }); - - it('resolves the schedule promise when scheduler resolves', async () => { - const onComplete = vi.fn().mockResolvedValue(undefined); - - const completedToolCall = { - status: 'success' as const, - request: { - callId: 'call-1', - name: 'test', - args: {}, - isClientInitiated: false, - prompt_id: 'p1', - }, - tool: createMockTool(), - invocation: createMockInvocation(), - response: { - callId: 'call-1', - responseParts: [], - resultDisplay: 'Success', - error: undefined, - errorType: undefined, - }, - }; - - // Mock the specific return value for this test - const { Scheduler } = await import('@google/gemini-cli-core'); - vi.mocked(Scheduler).mockImplementation( - () => - ({ - schedule: vi.fn().mockResolvedValue([completedToolCall]), - cancelAll: vi.fn(), - }) as unknown as Scheduler, - ); - - const { result } = renderHook(() => - useToolExecutionScheduler(onComplete, mockConfig, () => undefined), - ); - - const [, schedule] = result.current; - const signal = new AbortController().signal; - - let completedResult: CompletedToolCall[] = []; - await act(async () => { - completedResult = await schedule( - { - callId: 'call-1', - name: 'test', - args: {}, - isClientInitiated: false, - prompt_id: 'p1', - }, - signal, - ); - }); - - expect(completedResult).toEqual([completedToolCall]); - expect(onComplete).toHaveBeenCalledWith([completedToolCall]); - }); - - it('setToolCallsForDisplay re-groups tools by schedulerId (Multi-Scheduler support)', () => { - const { result } = renderHook(() => - useToolExecutionScheduler( - vi.fn().mockResolvedValue(undefined), - mockConfig, - () => undefined, - ), - ); - - const callRoot = { - status: 'success' as const, - request: { - callId: 'call-root', - name: 'test', - args: {}, - isClientInitiated: false, - prompt_id: 'p1', - }, - tool: createMockTool(), - invocation: createMockInvocation(), - response: { - callId: 'call-root', - responseParts: [], - resultDisplay: 'OK', - error: undefined, - errorType: undefined, - }, - schedulerId: ROOT_SCHEDULER_ID, - }; - - const callSub = { - ...callRoot, - request: { ...callRoot.request, callId: 'call-sub' }, - schedulerId: 'subagent-1', - }; - - // 1. Populate state with multiple schedulers - act(() => { - void mockMessageBus.publish({ - type: MessageBusType.TOOL_CALLS_UPDATE, - toolCalls: [callRoot], - schedulerId: ROOT_SCHEDULER_ID, - } as ToolCallsUpdateMessage); - - void mockMessageBus.publish({ - type: MessageBusType.TOOL_CALLS_UPDATE, - toolCalls: [callSub], - schedulerId: 'subagent-1', - } as ToolCallsUpdateMessage); - }); - - let [toolCalls] = result.current; - expect(toolCalls).toHaveLength(2); - expect( - toolCalls.find((t) => t.request.callId === 'call-root')?.schedulerId, - ).toBe(ROOT_SCHEDULER_ID); - expect( - toolCalls.find((t) => t.request.callId === 'call-sub')?.schedulerId, - ).toBe('subagent-1'); - - // 2. Call setToolCallsForDisplay (e.g., simulate a manual update or clear) - act(() => { - const [, , , setToolCalls] = result.current; - setToolCalls((prev) => - prev.map((t) => ({ ...t, responseSubmittedToGemini: true })), - ); - }); - - // 3. Verify that tools are still present and maintain their scheduler IDs - // The internal map should have been re-grouped. - [toolCalls] = result.current; - expect(toolCalls).toHaveLength(2); - expect(toolCalls.every((t) => t.responseSubmittedToGemini)).toBe(true); - - const updatedRoot = toolCalls.find((t) => t.request.callId === 'call-root'); - const updatedSub = toolCalls.find((t) => t.request.callId === 'call-sub'); - - expect(updatedRoot?.schedulerId).toBe(ROOT_SCHEDULER_ID); - expect(updatedSub?.schedulerId).toBe('subagent-1'); - - // 4. Verify that a subsequent update to ONE scheduler doesn't wipe the other - act(() => { - void mockMessageBus.publish({ - type: MessageBusType.TOOL_CALLS_UPDATE, - toolCalls: [{ ...callRoot, status: 'executing' }], - schedulerId: ROOT_SCHEDULER_ID, - } as ToolCallsUpdateMessage); - }); - - [toolCalls] = result.current; - expect(toolCalls).toHaveLength(2); - expect( - toolCalls.find((t) => t.request.callId === 'call-root')?.status, - ).toBe('executing'); - expect( - toolCalls.find((t) => t.request.callId === 'call-sub')?.schedulerId, - ).toBe('subagent-1'); - }); -}); diff --git a/packages/cli/src/ui/hooks/useToolExecutionScheduler.ts b/packages/cli/src/ui/hooks/useToolExecutionScheduler.ts deleted file mode 100644 index 0c58e7fc41..0000000000 --- a/packages/cli/src/ui/hooks/useToolExecutionScheduler.ts +++ /dev/null @@ -1,253 +0,0 @@ -/** - * @license - * Copyright 2026 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import { - type Config, - type MessageBus, - type ToolCallRequestInfo, - type ToolCall, - type CompletedToolCall, - type ToolConfirmationPayload, - MessageBusType, - ToolConfirmationOutcome, - Scheduler, - type EditorType, - type ToolCallsUpdateMessage, - ROOT_SCHEDULER_ID, -} from '@google/gemini-cli-core'; -import { useCallback, useState, useMemo, useEffect, useRef } from 'react'; - -// Re-exporting types compatible with legacy hook expectations -export type ScheduleFn = ( - request: ToolCallRequestInfo | ToolCallRequestInfo[], - signal: AbortSignal, -) => Promise; - -export type MarkToolsAsSubmittedFn = (callIds: string[]) => void; -export type CancelAllFn = (signal: AbortSignal) => void; - -/** - * The shape expected by useGeminiStream. - * It matches the Core ToolCall structure + the UI metadata flag. - */ -export type TrackedToolCall = ToolCall & { - responseSubmittedToGemini?: boolean; -}; - -/** - * Modern tool scheduler hook using the event-driven Core Scheduler. - * - * This hook acts as an Adapter between the new MessageBus-driven Core - * and the legacy callback-based UI components. - */ -export function useToolExecutionScheduler( - onComplete: (tools: CompletedToolCall[]) => Promise, - config: Config, - getPreferredEditor: () => EditorType | undefined, -): [ - TrackedToolCall[], - ScheduleFn, - MarkToolsAsSubmittedFn, - React.Dispatch>, - CancelAllFn, - number, -] { - // State stores tool calls organized by their originating schedulerId - const [toolCallsMap, setToolCallsMap] = useState< - Record - >({}); - const [lastToolOutputTime, setLastToolOutputTime] = useState(0); - - const messageBus = useMemo(() => config.getMessageBus(), [config]); - - const onCompleteRef = useRef(onComplete); - useEffect(() => { - onCompleteRef.current = onComplete; - }, [onComplete]); - - const getPreferredEditorRef = useRef(getPreferredEditor); - useEffect(() => { - getPreferredEditorRef.current = getPreferredEditor; - }, [getPreferredEditor]); - - const scheduler = useMemo( - () => - new Scheduler({ - config, - messageBus, - getPreferredEditor: () => getPreferredEditorRef.current(), - schedulerId: ROOT_SCHEDULER_ID, - }), - [config, messageBus], - ); - - const internalAdaptToolCalls = useCallback( - (coreCalls: ToolCall[], prevTracked: TrackedToolCall[]) => - adaptToolCalls(coreCalls, prevTracked, messageBus), - [messageBus], - ); - - useEffect(() => { - const handler = (event: ToolCallsUpdateMessage) => { - // Update output timer for UI spinners (Side Effect) - if (event.toolCalls.some((tc) => tc.status === 'executing')) { - setLastToolOutputTime(Date.now()); - } - - setToolCallsMap((prev) => { - const adapted = internalAdaptToolCalls( - event.toolCalls, - prev[event.schedulerId] ?? [], - ); - - return { - ...prev, - [event.schedulerId]: adapted, - }; - }); - }; - - messageBus.subscribe(MessageBusType.TOOL_CALLS_UPDATE, handler); - return () => { - messageBus.unsubscribe(MessageBusType.TOOL_CALLS_UPDATE, handler); - }; - }, [messageBus, internalAdaptToolCalls]); - - const schedule: ScheduleFn = useCallback( - async (request, signal) => { - // Clear state for new run - setToolCallsMap({}); - - // 1. Await Core Scheduler directly - const results = await scheduler.schedule(request, signal); - - // 2. Trigger legacy reinjection logic (useGeminiStream loop) - // Since this hook instance owns the "root" scheduler, we always trigger - // onComplete when it finishes its batch. - await onCompleteRef.current(results); - - return results; - }, - [scheduler], - ); - - const cancelAll: CancelAllFn = useCallback( - (_signal) => { - scheduler.cancelAll(); - }, - [scheduler], - ); - - const markToolsAsSubmitted: MarkToolsAsSubmittedFn = useCallback( - (callIdsToMark: string[]) => { - setToolCallsMap((prevMap) => { - const nextMap = { ...prevMap }; - for (const [sid, calls] of Object.entries(nextMap)) { - nextMap[sid] = calls.map((tc) => - callIdsToMark.includes(tc.request.callId) - ? { ...tc, responseSubmittedToGemini: true } - : tc, - ); - } - return nextMap; - }); - }, - [], - ); - - // Flatten the map for the UI components that expect a single list of tools. - const toolCalls = useMemo( - () => Object.values(toolCallsMap).flat(), - [toolCallsMap], - ); - - // Provide a setter that maintains compatibility with legacy []. - const setToolCallsForDisplay = useCallback( - (action: React.SetStateAction) => { - setToolCallsMap((prev) => { - const currentFlattened = Object.values(prev).flat(); - const nextFlattened = - typeof action === 'function' ? action(currentFlattened) : action; - - if (nextFlattened.length === 0) { - return {}; - } - - // Re-group by schedulerId to preserve multi-scheduler state - const nextMap: Record = {}; - for (const call of nextFlattened) { - // All tool calls should have a schedulerId from the core. - // Default to ROOT_SCHEDULER_ID as a safeguard. - const sid = call.schedulerId ?? ROOT_SCHEDULER_ID; - if (!nextMap[sid]) { - nextMap[sid] = []; - } - nextMap[sid].push(call); - } - return nextMap; - }); - }, - [], - ); - - return [ - toolCalls, - schedule, - markToolsAsSubmitted, - setToolCallsForDisplay, - cancelAll, - lastToolOutputTime, - ]; -} - -/** - * ADAPTER: Merges UI metadata (submitted flag) and injects legacy callbacks. - */ -function adaptToolCalls( - coreCalls: ToolCall[], - prevTracked: TrackedToolCall[], - messageBus: MessageBus, -): TrackedToolCall[] { - const prevMap = new Map(prevTracked.map((t) => [t.request.callId, t])); - - return coreCalls.map((coreCall): TrackedToolCall => { - const prev = prevMap.get(coreCall.request.callId); - const responseSubmittedToGemini = prev?.responseSubmittedToGemini ?? false; - - // Inject onConfirm adapter for tools awaiting approval. - // The Core provides data-only (serializable) confirmationDetails. We must - // inject the legacy callback function that proxies responses back to the - // MessageBus. - if (coreCall.status === 'awaiting_approval' && coreCall.correlationId) { - const correlationId = coreCall.correlationId; - return { - ...coreCall, - confirmationDetails: { - ...coreCall.confirmationDetails, - onConfirm: async ( - outcome: ToolConfirmationOutcome, - payload?: ToolConfirmationPayload, - ) => { - await messageBus.publish({ - type: MessageBusType.TOOL_CONFIRMATION_RESPONSE, - correlationId, - confirmed: outcome !== ToolConfirmationOutcome.Cancel, - requiresUserConfirmation: false, - outcome, - payload, - }); - }, - }, - responseSubmittedToGemini, - }; - } - - return { - ...coreCall, - responseSubmittedToGemini, - }; - }); -} diff --git a/packages/cli/src/ui/hooks/useToolScheduler.test.ts b/packages/cli/src/ui/hooks/useToolScheduler.test.ts index 81cafb4f34..4a04d6225c 100644 --- a/packages/cli/src/ui/hooks/useToolScheduler.test.ts +++ b/packages/cli/src/ui/hooks/useToolScheduler.test.ts @@ -1,1135 +1,525 @@ /** * @license - * Copyright 2025 Google LLC + * Copyright 2026 Google LLC * SPDX-License-Identifier: Apache-2.0 */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import type { Mock } from 'vitest'; -import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; import { act } from 'react'; import { renderHook } from '../../test-utils/render.js'; -import { useReactToolScheduler } from './useReactToolScheduler.js'; -import { mapToDisplay } from './toolMapping.js'; -import type { PartUnion, FunctionResponse } from '@google/genai'; -import type { - Config, - ToolCallRequestInfo, - ToolRegistry, - ToolResult, - ToolCallConfirmationDetails, - ToolCallResponseInfo, - ToolCall, // Import from core - Status as ToolCallStatusType, - AnyDeclarativeTool, - AnyToolInvocation, -} from '@google/gemini-cli-core'; +import { useToolScheduler } from './useToolScheduler.js'; import { - DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD, + MessageBusType, ToolConfirmationOutcome, - ApprovalMode, - HookSystem, - PREVIEW_GEMINI_MODEL, - PolicyDecision, + Scheduler, + type Config, + type MessageBus, + type CompletedToolCall, + type ToolCallConfirmationDetails, + type ToolCallsUpdateMessage, + type AnyDeclarativeTool, + type AnyToolInvocation, + ROOT_SCHEDULER_ID, } 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'; -import { ToolCallStatus } from '../types.js'; -// Mocks -vi.mock('@google/gemini-cli-core', async () => { - const actual = await vi.importActual('@google/gemini-cli-core'); - // Patch CoreToolScheduler to have cancelAll if it's missing in the test environment - if ( - actual.CoreToolScheduler && - !actual.CoreToolScheduler.prototype.cancelAll - ) { - actual.CoreToolScheduler.prototype.cancelAll = vi.fn(); - } +// Mock Core Scheduler +vi.mock('@google/gemini-cli-core', async (importOriginal) => { + const actual = + await importOriginal(); return { ...actual, - ToolRegistry: vi.fn(), - Config: vi.fn(), + Scheduler: vi.fn().mockImplementation(() => ({ + schedule: vi.fn().mockResolvedValue([]), + cancelAll: vi.fn(), + })), }; }); -const mockToolRegistry = { - getTool: vi.fn(), - getAllToolNames: vi.fn(() => ['mockTool', 'anotherTool']), -}; +const createMockTool = ( + overrides: Partial = {}, +): AnyDeclarativeTool => + ({ + name: 'test_tool', + displayName: 'Test Tool', + description: 'A test tool', + kind: 'function', + parameterSchema: {}, + isOutputMarkdown: false, + build: vi.fn(), + ...overrides, + }) as AnyDeclarativeTool; -const mockConfig = { - getToolRegistry: vi.fn(() => mockToolRegistry as unknown as ToolRegistry), - getApprovalMode: vi.fn(() => ApprovalMode.DEFAULT), - getSessionId: () => 'test-session-id', - getUsageStatisticsEnabled: () => true, - getDebugMode: () => false, - getWorkingDir: () => '/working/dir', - storage: { - getProjectTempDir: () => '/tmp', - }, - getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD, - getAllowedTools: vi.fn(() => []), - getActiveModel: () => PREVIEW_GEMINI_MODEL, - getContentGeneratorConfig: () => ({ - model: 'test-model', - authType: 'oauth-personal', - }), - getGeminiClient: () => null, // No client needed for these tests - getShellExecutionConfig: () => ({ terminalWidth: 80, terminalHeight: 24 }), - getMessageBus: () => 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 }; - }, -}); +const createMockInvocation = ( + overrides: Partial = {}, +): AnyToolInvocation => + ({ + getDescription: () => 'Executing test tool', + shouldConfirmExecute: vi.fn(), + execute: vi.fn(), + params: {}, + toolLocations: [], + ...overrides, + }) as AnyToolInvocation; -function createMockConfigOverride(overrides: Partial = {}): Config { - return { ...mockConfig, ...overrides } as Config; -} - -const mockTool = new MockTool({ - name: 'mockTool', - displayName: 'Mock Tool', - execute: vi.fn(), - shouldConfirmExecute: vi.fn(), -}); -const mockToolWithLiveOutput = new MockTool({ - name: 'mockToolWithLiveOutput', - displayName: 'Mock Tool With Live Output', - description: 'A mock tool for testing', - params: {}, - isOutputMarkdown: true, - canUpdateOutput: true, - execute: vi.fn(), - shouldConfirmExecute: vi.fn(), -}); -let mockOnUserConfirmForToolConfirmation: Mock; -const mockToolRequiresConfirmation = new MockTool({ - name: 'mockToolRequiresConfirmation', - displayName: 'Mock Tool Requires Confirmation', - execute: vi.fn(), - shouldConfirmExecute: vi.fn(), -}); - -describe('useReactToolScheduler in YOLO Mode', () => { - let onComplete: Mock; +describe('useToolScheduler', () => { + let mockConfig: Config; + let mockMessageBus: MessageBus; beforeEach(() => { - onComplete = vi.fn(); - mockToolRegistry.getTool.mockClear(); - (mockToolRequiresConfirmation.execute as Mock).mockClear(); - (mockToolRequiresConfirmation.shouldConfirmExecute as Mock).mockClear(); - - // IMPORTANT: Enable YOLO mode for this test suite - (mockConfig.getApprovalMode as Mock).mockReturnValue(ApprovalMode.YOLO); - - vi.useFakeTimers(); + vi.clearAllMocks(); + mockMessageBus = createMockMessageBus() as unknown as MessageBus; + mockConfig = { + getMessageBus: () => mockMessageBus, + } as unknown as Config; }); afterEach(() => { - vi.clearAllTimers(); - vi.useRealTimers(); - // IMPORTANT: Disable YOLO mode after this test suite - (mockConfig.getApprovalMode as Mock).mockReturnValue(ApprovalMode.DEFAULT); + vi.clearAllMocks(); }); - const renderSchedulerInYoloMode = () => - renderHook(() => - useReactToolScheduler( - onComplete, - mockConfig as unknown as Config, + it('initializes with empty tool calls', () => { + const { result } = renderHook(() => + useToolScheduler( + vi.fn().mockResolvedValue(undefined), + mockConfig, + () => undefined, + ), + ); + const [toolCalls] = result.current; + expect(toolCalls).toEqual([]); + }); + + it('updates tool calls when MessageBus emits TOOL_CALLS_UPDATE', () => { + const { result } = renderHook(() => + useToolScheduler( + vi.fn().mockResolvedValue(undefined), + mockConfig, () => undefined, ), ); - it('should skip confirmation and execute tool directly when yoloMode is true', async () => { - mockToolRegistry.getTool.mockReturnValue(mockToolRequiresConfirmation); - const expectedOutput = 'YOLO Confirmed output'; - (mockToolRequiresConfirmation.execute as Mock).mockResolvedValue({ - llmContent: expectedOutput, - returnDisplay: 'YOLO Formatted tool output', - } as ToolResult); + const mockToolCall = { + status: 'executing' as const, + request: { + callId: 'call-1', + name: 'test_tool', + args: {}, + isClientInitiated: false, + prompt_id: 'p1', + }, + tool: createMockTool(), + invocation: createMockInvocation(), + liveOutput: 'Loading...', + }; - const { result } = renderSchedulerInYoloMode(); - const schedule = result.current[1]; - const request: ToolCallRequestInfo = { - callId: 'yoloCall', - name: 'mockToolRequiresConfirmation', - args: { data: 'any data' }, - } as any; - - await act(async () => { - await schedule(request, new AbortController().signal); + act(() => { + void mockMessageBus.publish({ + type: MessageBusType.TOOL_CALLS_UPDATE, + toolCalls: [mockToolCall], + schedulerId: ROOT_SCHEDULER_ID, + } as ToolCallsUpdateMessage); }); - await act(async () => { - await vi.advanceTimersByTimeAsync(0); // Process validation - }); - await act(async () => { - await vi.advanceTimersByTimeAsync(0); // Process scheduling - }); - await act(async () => { - await vi.advanceTimersByTimeAsync(0); // Process execution + const [toolCalls] = result.current; + expect(toolCalls).toHaveLength(1); + // Expect Core Object structure, not Display Object + expect(toolCalls[0]).toMatchObject({ + request: { callId: 'call-1', name: 'test_tool' }, + status: 'executing', // Core status + liveOutput: 'Loading...', + responseSubmittedToGemini: false, }); + }); - // Check that execute WAS called - expect(mockToolRequiresConfirmation.execute).toHaveBeenCalledWith( - request.args, + it('injects onConfirm callback for awaiting_approval tools (Adapter Pattern)', async () => { + const { result } = renderHook(() => + useToolScheduler( + vi.fn().mockResolvedValue(undefined), + mockConfig, + () => undefined, + ), ); - // Check that onComplete was called with success - expect(onComplete).toHaveBeenCalledWith([ - expect.objectContaining({ - status: 'success', - request, - response: expect.objectContaining({ - resultDisplay: 'YOLO Formatted tool output', - responseParts: [ - { - functionResponse: { - id: 'yoloCall', - name: 'mockToolRequiresConfirmation', - response: { output: expectedOutput }, - }, - }, - ], - }), + const mockToolCall = { + status: 'awaiting_approval' as const, + request: { + callId: 'call-1', + name: 'test_tool', + args: {}, + isClientInitiated: false, + prompt_id: 'p1', + }, + tool: createMockTool(), + invocation: createMockInvocation({ + getDescription: () => 'Confirming test tool', }), - ]); + confirmationDetails: { type: 'info', title: 'Confirm', prompt: 'Sure?' }, + correlationId: 'corr-123', + }; + + act(() => { + void mockMessageBus.publish({ + type: MessageBusType.TOOL_CALLS_UPDATE, + toolCalls: [mockToolCall], + schedulerId: ROOT_SCHEDULER_ID, + } as ToolCallsUpdateMessage); + }); + + const [toolCalls] = result.current; + const call = toolCalls[0]; + if (call.status !== 'awaiting_approval') { + throw new Error('Expected status to be awaiting_approval'); + } + const confirmationDetails = + call.confirmationDetails as ToolCallConfirmationDetails; + + expect(confirmationDetails).toBeDefined(); + expect(typeof confirmationDetails.onConfirm).toBe('function'); + + // Test that onConfirm publishes to MessageBus + const publishSpy = vi.spyOn(mockMessageBus, 'publish'); + await confirmationDetails.onConfirm(ToolConfirmationOutcome.ProceedOnce); + + expect(publishSpy).toHaveBeenCalledWith({ + type: MessageBusType.TOOL_CONFIRMATION_RESPONSE, + correlationId: 'corr-123', + confirmed: true, + requiresUserConfirmation: false, + outcome: ToolConfirmationOutcome.ProceedOnce, + payload: undefined, + }); }); -}); -describe('useReactToolScheduler', () => { - let onComplete: Mock; - let capturedOnConfirmForTest: - | ((outcome: ToolConfirmationOutcome) => void | Promise) - | undefined; - - const advanceAndSettle = async () => { - await act(async () => { - await vi.advanceTimersByTimeAsync(0); - }); - }; - - const scheduleAndWaitForExecution = async ( - schedule: ( - req: ToolCallRequestInfo | ToolCallRequestInfo[], - signal: AbortSignal, - ) => Promise, - request: ToolCallRequestInfo | ToolCallRequestInfo[], - ) => { - await act(async () => { - await schedule(request, new AbortController().signal); - }); - - await advanceAndSettle(); - await advanceAndSettle(); - await advanceAndSettle(); - }; - - beforeEach(() => { - onComplete = vi.fn(); - capturedOnConfirmForTest = undefined; - - mockToolRegistry.getTool.mockClear(); - (mockTool.execute as Mock).mockClear(); - (mockTool.shouldConfirmExecute as Mock).mockClear(); - (mockToolWithLiveOutput.execute as Mock).mockClear(); - (mockToolWithLiveOutput.shouldConfirmExecute as Mock).mockClear(); - (mockToolRequiresConfirmation.execute as Mock).mockClear(); - (mockToolRequiresConfirmation.shouldConfirmExecute as Mock).mockClear(); - - mockOnUserConfirmForToolConfirmation = vi.fn(); - ( - mockToolRequiresConfirmation.shouldConfirmExecute as Mock - ).mockImplementation( - async (): Promise => - ({ - onConfirm: mockOnUserConfirmForToolConfirmation, - fileName: 'mockToolRequiresConfirmation.ts', - fileDiff: 'Mock tool requires confirmation', - type: 'edit', - title: 'Mock Tool Requires Confirmation', - }) as any, + it('injects onConfirm with payload (Inline Edit support)', async () => { + const { result } = renderHook(() => + useToolScheduler( + vi.fn().mockResolvedValue(undefined), + mockConfig, + () => undefined, + ), ); - vi.useFakeTimers(); + const mockToolCall = { + status: 'awaiting_approval' as const, + request: { + callId: 'call-1', + name: 'test_tool', + args: {}, + isClientInitiated: false, + prompt_id: 'p1', + }, + tool: createMockTool(), + invocation: createMockInvocation(), + confirmationDetails: { type: 'edit', title: 'Edit', filePath: 'test.ts' }, + correlationId: 'corr-edit', + }; + + act(() => { + void mockMessageBus.publish({ + type: MessageBusType.TOOL_CALLS_UPDATE, + toolCalls: [mockToolCall], + schedulerId: ROOT_SCHEDULER_ID, + } as ToolCallsUpdateMessage); + }); + + const [toolCalls] = result.current; + const call = toolCalls[0]; + if (call.status !== 'awaiting_approval') { + throw new Error('Expected awaiting_approval'); + } + const confirmationDetails = + call.confirmationDetails as ToolCallConfirmationDetails; + + const publishSpy = vi.spyOn(mockMessageBus, 'publish'); + const mockPayload = { newContent: 'updated code' }; + await confirmationDetails.onConfirm( + ToolConfirmationOutcome.ProceedOnce, + mockPayload, + ); + + expect(publishSpy).toHaveBeenCalledWith({ + type: MessageBusType.TOOL_CONFIRMATION_RESPONSE, + correlationId: 'corr-edit', + confirmed: true, + requiresUserConfirmation: false, + outcome: ToolConfirmationOutcome.ProceedOnce, + payload: mockPayload, + }); }); - afterEach(() => { - vi.clearAllTimers(); + it('preserves responseSubmittedToGemini flag across updates', () => { + const { result } = renderHook(() => + useToolScheduler( + vi.fn().mockResolvedValue(undefined), + mockConfig, + () => undefined, + ), + ); + + const mockToolCall = { + status: 'success' as const, + request: { + callId: 'call-1', + name: 'test', + args: {}, + isClientInitiated: false, + prompt_id: 'p1', + }, + tool: createMockTool(), + invocation: createMockInvocation(), + response: { + callId: 'call-1', + resultDisplay: 'OK', + responseParts: [], + error: undefined, + errorType: undefined, + }, + }; + + // 1. Initial success + act(() => { + void mockMessageBus.publish({ + type: MessageBusType.TOOL_CALLS_UPDATE, + toolCalls: [mockToolCall], + schedulerId: ROOT_SCHEDULER_ID, + } as ToolCallsUpdateMessage); + }); + + // 2. Mark as submitted + act(() => { + const [, , markAsSubmitted] = result.current; + markAsSubmitted(['call-1']); + }); + + expect(result.current[0][0].responseSubmittedToGemini).toBe(true); + + // 3. Receive another update (should preserve the true flag) + act(() => { + void mockMessageBus.publish({ + type: MessageBusType.TOOL_CALLS_UPDATE, + toolCalls: [mockToolCall], + schedulerId: ROOT_SCHEDULER_ID, + } as ToolCallsUpdateMessage); + }); + + expect(result.current[0][0].responseSubmittedToGemini).toBe(true); + }); + + it('updates lastToolOutputTime when tools are executing', () => { + vi.useFakeTimers(); + const { result } = renderHook(() => + useToolScheduler( + vi.fn().mockResolvedValue(undefined), + mockConfig, + () => undefined, + ), + ); + + const startTime = Date.now(); + vi.advanceTimersByTime(1000); + + act(() => { + void mockMessageBus.publish({ + type: MessageBusType.TOOL_CALLS_UPDATE, + toolCalls: [ + { + status: 'executing' as const, + request: { + callId: 'call-1', + name: 'test', + args: {}, + isClientInitiated: false, + prompt_id: 'p1', + }, + tool: createMockTool(), + invocation: createMockInvocation(), + }, + ], + schedulerId: ROOT_SCHEDULER_ID, + } as ToolCallsUpdateMessage); + }); + + const [, , , , , lastOutputTime] = result.current; + expect(lastOutputTime).toBeGreaterThan(startTime); vi.useRealTimers(); }); - const renderScheduler = (config: Config = mockConfig) => - renderHook(() => - useReactToolScheduler(onComplete, config, () => undefined), - ); - - it('initial state should be empty', () => { - const { result } = renderScheduler(); - expect(result.current[0]).toEqual([]); - }); - - it('should schedule and execute a tool call successfully', async () => { - mockToolRegistry.getTool.mockReturnValue(mockTool); - (mockTool.execute as Mock).mockResolvedValue({ - llmContent: 'Tool output', - returnDisplay: 'Formatted tool output', - } as ToolResult); - (mockTool.shouldConfirmExecute as Mock).mockResolvedValue(null); - - const { result } = renderScheduler(); - const request: ToolCallRequestInfo = { - callId: 'call1', - name: 'mockTool', - args: { param: 'value' }, - } as any; - - let completedToolCalls: ToolCall[] = []; - onComplete.mockImplementation((calls) => { - completedToolCalls = calls; - }); - - await scheduleAndWaitForExecution(result.current[1], request); - - expect(mockTool.execute).toHaveBeenCalledWith(request.args); - expect(completedToolCalls).toHaveLength(1); - expect(completedToolCalls[0].status).toBe('success'); - expect(completedToolCalls[0].request).toBe(request); - - if ( - completedToolCalls[0].status === 'success' || - completedToolCalls[0].status === 'error' - ) { - expect(completedToolCalls[0].response).toMatchSnapshot(); - } - }); - - it('should clear previous tool calls when scheduling new ones', async () => { - mockToolRegistry.getTool.mockReturnValue(mockTool); - (mockTool.execute as Mock).mockImplementation(async () => { - await new Promise((r) => setTimeout(r, 10)); - return { - llmContent: 'Tool output', - returnDisplay: 'Formatted tool output', - }; - }); - - const { result } = renderScheduler(); - const schedule = result.current[1]; - const setToolCallsForDisplay = result.current[3]; - - // Manually set a tool call in the display. - const oldToolCall = { - request: { callId: 'oldCall' }, - status: 'success', - } as any; - act(() => { - setToolCallsForDisplay([oldToolCall]); - }); - expect(result.current[0]).toEqual([oldToolCall]); - - const newRequest: ToolCallRequestInfo = { - callId: 'newCall', - name: 'mockTool', - args: {}, - } as any; - let schedulePromise: Promise; - await act(async () => { - schedulePromise = schedule(newRequest, new AbortController().signal); - }); - - await advanceAndSettle(); - - // After scheduling, the old call should be gone, - // and the new one should be in the display in its initial state. - expect(result.current[0].length).toBe(1); - expect(result.current[0][0].request.callId).toBe('newCall'); - expect(result.current[0][0].request.callId).not.toBe('oldCall'); - - // Let the new call finish. - await act(async () => { - await vi.advanceTimersByTimeAsync(20); - }); - - await act(async () => { - await schedulePromise; - }); - - expect(onComplete).toHaveBeenCalled(); - }); - - it('should cancel all running tool calls', async () => { - mockToolRegistry.getTool.mockReturnValue(mockTool); - - let resolveExecute: (value: ToolResult) => void = () => {}; - const executePromise = new Promise((resolve) => { - resolveExecute = resolve; - }); - (mockTool.execute as Mock).mockReturnValue(executePromise); - (mockTool.shouldConfirmExecute as Mock).mockResolvedValue(null); - - const { result } = renderScheduler(); - const schedule = result.current[1]; - const cancelAllToolCalls = result.current[4]; - const request: ToolCallRequestInfo = { - callId: 'cancelCall', - name: 'mockTool', - args: {}, - } as any; - - let schedulePromise: Promise; - await act(async () => { - schedulePromise = schedule(request, new AbortController().signal); - }); - - await advanceAndSettle(); // validation - await advanceAndSettle(); // Process scheduling - - // At this point, the tool is 'executing' and waiting on the promise. - expect(result.current[0][0].status).toBe('executing'); - - const cancelController = new AbortController(); - act(() => { - cancelAllToolCalls(cancelController.signal); - }); - - await advanceAndSettle(); - - expect(onComplete).toHaveBeenCalledWith([ - expect.objectContaining({ - status: 'cancelled', - request, - }), - ]); - - // Clean up the pending promise to avoid open handles. - await act(async () => { - resolveExecute({ llmContent: 'output', returnDisplay: 'display' }); - }); - - // Now await the schedule promise - await act(async () => { - await schedulePromise; - }); - }); - - it.each([ - { - desc: 'tool not found', - setup: () => { - mockToolRegistry.getTool.mockReturnValue(undefined); - }, - request: { - callId: 'call1', - name: 'nonexistentTool', - args: {}, - } as any, - expectedErrorContains: [ - 'Tool "nonexistentTool" not found in registry', - 'Did you mean one of:', - ], - }, - { - desc: 'error during shouldConfirmExecute', - setup: () => { - mockToolRegistry.getTool.mockReturnValue(mockTool); - const confirmError = new Error('Confirmation check failed'); - (mockTool.shouldConfirmExecute as Mock).mockRejectedValue(confirmError); - }, - request: { - callId: 'call1', - name: 'mockTool', - args: {}, - } as any, - expectedError: new Error('Confirmation check failed'), - }, - { - desc: 'error during execute', - setup: () => { - mockToolRegistry.getTool.mockReturnValue(mockTool); - (mockTool.shouldConfirmExecute as Mock).mockResolvedValue(null); - const execError = new Error('Execution failed'); - (mockTool.execute as Mock).mockRejectedValue(execError); - }, - request: { - callId: 'call1', - name: 'mockTool', - args: {}, - } as any, - expectedError: new Error('Execution failed'), - }, - ])( - 'should handle $desc', - async ({ setup, request, expectedErrorContains, expectedError }) => { - setup(); - const { result } = renderScheduler(); - - let completedToolCalls: ToolCall[] = []; - onComplete.mockImplementation((calls) => { - completedToolCalls = calls; - }); - - await scheduleAndWaitForExecution(result.current[1], request); - - expect(completedToolCalls).toHaveLength(1); - expect(completedToolCalls[0].status).toBe('error'); - expect(completedToolCalls[0].request).toBe(request); - - if (expectedErrorContains) { - expectedErrorContains.forEach((errorText) => { - expect( - (completedToolCalls[0] as any).response.error.message, - ).toContain(errorText); - }); - } - - if (expectedError) { - expect((completedToolCalls[0] as any).response.error.message).toBe( - expectedError.message, - ); - } - }, - ); - - it('should handle tool requiring confirmation - approved', async () => { - mockToolRegistry.getTool.mockReturnValue(mockToolRequiresConfirmation); - const config = createMockConfigOverride({ - isInteractive: () => true, - }); - const expectedOutput = 'Confirmed output'; - (mockToolRequiresConfirmation.execute as Mock).mockResolvedValue({ - llmContent: expectedOutput, - returnDisplay: 'Confirmed display', - } as ToolResult); - - const { result } = renderScheduler(config); - const schedule = result.current[1]; - const request: ToolCallRequestInfo = { - callId: 'callConfirm', - name: 'mockToolRequiresConfirmation', - args: { data: 'sensitive' }, - } as any; - - let schedulePromise: Promise; - await act(async () => { - schedulePromise = schedule(request, new AbortController().signal); - }); - await advanceAndSettle(); - - const waitingCall = result.current[0][0] as any; - expect(waitingCall.status).toBe('awaiting_approval'); - capturedOnConfirmForTest = waitingCall.confirmationDetails?.onConfirm; - expect(capturedOnConfirmForTest).toBeDefined(); - - await act(async () => { - await capturedOnConfirmForTest?.(ToolConfirmationOutcome.ProceedOnce); - }); - - await advanceAndSettle(); - - // Now await the schedule promise as it should complete - await act(async () => { - await schedulePromise; - }); - - expect(mockOnUserConfirmForToolConfirmation).toHaveBeenCalledWith( - ToolConfirmationOutcome.ProceedOnce, - ); - expect(mockToolRequiresConfirmation.execute).toHaveBeenCalled(); - - const completedCalls = onComplete.mock.calls[0][0] as ToolCall[]; - expect(completedCalls[0].status).toBe('success'); - expect(completedCalls[0].request).toBe(request); - if ( - completedCalls[0].status === 'success' || - completedCalls[0].status === 'error' - ) { - expect(completedCalls[0].response).toMatchSnapshot(); - } - }); - - it('should handle tool requiring confirmation - cancelled by user', async () => { - mockToolRegistry.getTool.mockReturnValue(mockToolRequiresConfirmation); - const config = createMockConfigOverride({ - isInteractive: () => true, - }); - const { result } = renderScheduler(config); - const schedule = result.current[1]; - const request: ToolCallRequestInfo = { - callId: 'callConfirmCancel', - name: 'mockToolRequiresConfirmation', - args: {}, - } as any; - - let schedulePromise: Promise; - await act(async () => { - schedulePromise = schedule(request, new AbortController().signal); - }); - await advanceAndSettle(); - - const waitingCall = result.current[0][0] as any; - expect(waitingCall.status).toBe('awaiting_approval'); - capturedOnConfirmForTest = waitingCall.confirmationDetails?.onConfirm; - expect(capturedOnConfirmForTest).toBeDefined(); - - await act(async () => { - await capturedOnConfirmForTest?.(ToolConfirmationOutcome.Cancel); - }); - - await advanceAndSettle(); - - // Now await the schedule promise - await act(async () => { - await schedulePromise; - }); - - expect(mockOnUserConfirmForToolConfirmation).toHaveBeenCalledWith( - ToolConfirmationOutcome.Cancel, - ); - - const completedCalls = onComplete.mock.calls[0][0] as ToolCall[]; - expect(completedCalls[0].status).toBe('cancelled'); - expect(completedCalls[0].request).toBe(request); - if ( - completedCalls[0].status === 'success' || - completedCalls[0].status === 'error' || - completedCalls[0].status === 'cancelled' - ) { - expect(completedCalls[0].response).toMatchSnapshot(); - } - }); - - it('should handle live output updates', async () => { - mockToolRegistry.getTool.mockReturnValue(mockToolWithLiveOutput); - let liveUpdateFn: ((output: string) => void) | undefined; - let resolveExecutePromise: (value: ToolResult) => void; - const executePromise = new Promise((resolve) => { - resolveExecutePromise = resolve; - }); - - (mockToolWithLiveOutput.execute as Mock).mockImplementation( - async ( - _args: Record, - _signal: AbortSignal, - updateFn: ((output: string) => void) | undefined, - ) => { - liveUpdateFn = updateFn; - return executePromise; - }, - ); - (mockToolWithLiveOutput.shouldConfirmExecute as Mock).mockResolvedValue( - null, - ); - - const { result } = renderScheduler(); - const request: ToolCallRequestInfo = { - callId: 'liveCall', - name: 'mockToolWithLiveOutput', - args: {}, - } as any; - - let schedulePromise: Promise; - await act(async () => { - schedulePromise = result.current[1]( - request, - new AbortController().signal, - ); - }); - await advanceAndSettle(); - - expect(liveUpdateFn).toBeDefined(); - expect(result.current[0][0].status).toBe('executing'); - - await act(async () => { - liveUpdateFn?.('Live output 1'); - }); - await advanceAndSettle(); - - await act(async () => { - liveUpdateFn?.('Live output 2'); - }); - await advanceAndSettle(); - - act(() => { - resolveExecutePromise({ - llmContent: 'Final output', - returnDisplay: 'Final display', - } as ToolResult); - }); - await advanceAndSettle(); - - // Now await schedule - await act(async () => { - await schedulePromise; - }); - - const completedCalls = onComplete.mock.calls[0][0] as ToolCall[]; - expect(completedCalls[0].status).toBe('success'); - expect(completedCalls[0].request).toBe(request); - if ( - completedCalls[0].status === 'success' || - completedCalls[0].status === 'error' - ) { - expect(completedCalls[0].response).toMatchSnapshot(); - } - expect(result.current[0]).toEqual([]); - }); - - it('should schedule and execute multiple tool calls', async () => { - const tool1 = new MockTool({ - name: 'tool1', - displayName: 'Tool 1', - execute: vi.fn().mockResolvedValue({ - llmContent: 'Output 1', - returnDisplay: 'Display 1', - } as ToolResult), - }); - - const tool2 = new MockTool({ - name: 'tool2', - displayName: 'Tool 2', - execute: vi.fn().mockResolvedValue({ - llmContent: 'Output 2', - returnDisplay: 'Display 2', - } as ToolResult), - }); - - mockToolRegistry.getTool.mockImplementation((name) => { - if (name === 'tool1') return tool1; - if (name === 'tool2') return tool2; - return undefined; - }); - - const { result } = renderScheduler(); - const schedule = result.current[1]; - const requests: ToolCallRequestInfo[] = [ - { callId: 'multi1', name: 'tool1', args: { p: 1 } } as any, - { callId: 'multi2', name: 'tool2', args: { p: 2 } } as any, - ]; - - await act(async () => { - await schedule(requests, new AbortController().signal); - }); - await act(async () => { - await vi.advanceTimersByTimeAsync(0); - }); - await act(async () => { - await vi.advanceTimersByTimeAsync(0); - }); - await act(async () => { - await vi.advanceTimersByTimeAsync(0); - }); - await act(async () => { - await vi.advanceTimersByTimeAsync(0); - }); - - expect(onComplete).toHaveBeenCalledTimes(1); - const completedCalls = onComplete.mock.calls[0][0] as ToolCall[]; - expect(completedCalls.length).toBe(2); - - const call1Result = completedCalls.find( - (c) => c.request.callId === 'multi1', - ); - const call2Result = completedCalls.find( - (c) => c.request.callId === 'multi2', - ); - - expect(call1Result).toMatchObject({ - status: 'success', - request: requests[0], - response: expect.objectContaining({ - resultDisplay: 'Display 1', - responseParts: [ - { - functionResponse: { - id: 'multi1', - name: 'tool1', - response: { output: 'Output 1' }, - }, - }, - ], - }), - }); - expect(call2Result).toMatchObject({ - status: 'success', - request: requests[1], - response: expect.objectContaining({ - resultDisplay: 'Display 2', - responseParts: [ - { - functionResponse: { - id: 'multi2', - name: 'tool2', - response: { output: 'Output 2' }, - }, - }, - ], - }), - }); - - expect(completedCalls).toHaveLength(2); - expect(completedCalls.every((t) => t.status === 'success')).toBe(true); - }); - - it('should queue if scheduling while already running', async () => { - mockToolRegistry.getTool.mockReturnValue(mockTool); - const longExecutePromise = new Promise((resolve) => - setTimeout( - () => - resolve({ - llmContent: 'done', - returnDisplay: 'done display', - }), - 50, + it('delegates cancelAll to the Core Scheduler', () => { + const { result } = renderHook(() => + useToolScheduler( + vi.fn().mockResolvedValue(undefined), + mockConfig, + () => undefined, ), ); - (mockTool.execute as Mock).mockReturnValue(longExecutePromise); - (mockTool.shouldConfirmExecute as Mock).mockResolvedValue(null); - const { result } = renderScheduler(); - const schedule = result.current[1]; - const request1: ToolCallRequestInfo = { - callId: 'run1', - name: 'mockTool', - args: {}, - } as any; - const request2: ToolCallRequestInfo = { - callId: 'run2', - name: 'mockTool', - args: {}, - } as any; + const [, , , , cancelAll] = result.current; + const signal = new AbortController().signal; - let schedulePromise1: Promise; - let schedulePromise2: Promise; + // We need to find the mock instance of Scheduler + // Since we used vi.mock at top level, we can get it from vi.mocked(Scheduler) + const schedulerInstance = vi.mocked(Scheduler).mock.results[0].value; + cancelAll(signal); + + expect(schedulerInstance.cancelAll).toHaveBeenCalled(); + }); + + it('resolves the schedule promise when scheduler resolves', async () => { + const onComplete = vi.fn().mockResolvedValue(undefined); + + const completedToolCall = { + status: 'success' as const, + request: { + callId: 'call-1', + name: 'test', + args: {}, + isClientInitiated: false, + prompt_id: 'p1', + }, + tool: createMockTool(), + invocation: createMockInvocation(), + response: { + callId: 'call-1', + responseParts: [], + resultDisplay: 'Success', + error: undefined, + errorType: undefined, + }, + }; + + // Mock the specific return value for this test + const { Scheduler } = await import('@google/gemini-cli-core'); + vi.mocked(Scheduler).mockImplementation( + () => + ({ + schedule: vi.fn().mockResolvedValue([completedToolCall]), + cancelAll: vi.fn(), + }) as unknown as Scheduler, + ); + + const { result } = renderHook(() => + useToolScheduler(onComplete, mockConfig, () => undefined), + ); + + const [, schedule] = result.current; + const signal = new AbortController().signal; + + let completedResult: CompletedToolCall[] = []; await act(async () => { - schedulePromise1 = schedule(request1, new AbortController().signal); - }); - await act(async () => { - await vi.advanceTimersByTimeAsync(0); + completedResult = await schedule( + { + callId: 'call-1', + name: 'test', + args: {}, + isClientInitiated: false, + prompt_id: 'p1', + }, + signal, + ); }); - await act(async () => { - schedulePromise2 = schedule(request2, new AbortController().signal); + expect(completedResult).toEqual([completedToolCall]); + expect(onComplete).toHaveBeenCalledWith([completedToolCall]); + }); + + it('setToolCallsForDisplay re-groups tools by schedulerId (Multi-Scheduler support)', () => { + const { result } = renderHook(() => + useToolScheduler( + vi.fn().mockResolvedValue(undefined), + mockConfig, + () => undefined, + ), + ); + + const callRoot = { + status: 'success' as const, + request: { + callId: 'call-root', + name: 'test', + args: {}, + isClientInitiated: false, + prompt_id: 'p1', + }, + tool: createMockTool(), + invocation: createMockInvocation(), + response: { + callId: 'call-root', + responseParts: [], + resultDisplay: 'OK', + error: undefined, + errorType: undefined, + }, + schedulerId: ROOT_SCHEDULER_ID, + }; + + const callSub = { + ...callRoot, + request: { ...callRoot.request, callId: 'call-sub' }, + schedulerId: 'subagent-1', + }; + + // 1. Populate state with multiple schedulers + act(() => { + void mockMessageBus.publish({ + type: MessageBusType.TOOL_CALLS_UPDATE, + toolCalls: [callRoot], + schedulerId: ROOT_SCHEDULER_ID, + } as ToolCallsUpdateMessage); + + void mockMessageBus.publish({ + type: MessageBusType.TOOL_CALLS_UPDATE, + toolCalls: [callSub], + schedulerId: 'subagent-1', + } as ToolCallsUpdateMessage); }); - await act(async () => { - await vi.advanceTimersByTimeAsync(50); - await vi.advanceTimersByTimeAsync(0); + let [toolCalls] = result.current; + expect(toolCalls).toHaveLength(2); + expect( + toolCalls.find((t) => t.request.callId === 'call-root')?.schedulerId, + ).toBe(ROOT_SCHEDULER_ID); + expect( + toolCalls.find((t) => t.request.callId === 'call-sub')?.schedulerId, + ).toBe('subagent-1'); + + // 2. Call setToolCallsForDisplay (e.g., simulate a manual update or clear) + act(() => { + const [, , , setToolCalls] = result.current; + setToolCalls((prev) => + prev.map((t) => ({ ...t, responseSubmittedToGemini: true })), + ); }); - // Wait for first to complete - await act(async () => { - await schedulePromise1; + // 3. Verify that tools are still present and maintain their scheduler IDs + // The internal map should have been re-grouped. + [toolCalls] = result.current; + expect(toolCalls).toHaveLength(2); + expect(toolCalls.every((t) => t.responseSubmittedToGemini)).toBe(true); + + const updatedRoot = toolCalls.find((t) => t.request.callId === 'call-root'); + const updatedSub = toolCalls.find((t) => t.request.callId === 'call-sub'); + + expect(updatedRoot?.schedulerId).toBe(ROOT_SCHEDULER_ID); + expect(updatedSub?.schedulerId).toBe('subagent-1'); + + // 4. Verify that a subsequent update to ONE scheduler doesn't wipe the other + act(() => { + void mockMessageBus.publish({ + type: MessageBusType.TOOL_CALLS_UPDATE, + toolCalls: [{ ...callRoot, status: 'executing' }], + schedulerId: ROOT_SCHEDULER_ID, + } as ToolCallsUpdateMessage); }); - expect(onComplete).toHaveBeenCalledWith([ - expect.objectContaining({ - status: 'success', - request: request1, - response: expect.objectContaining({ resultDisplay: 'done display' }), - }), - ]); - - await act(async () => { - await vi.advanceTimersByTimeAsync(50); - await vi.advanceTimersByTimeAsync(0); - }); - - // Wait for second to complete - await act(async () => { - await schedulePromise2; - }); - - expect(onComplete).toHaveBeenCalledWith([ - expect.objectContaining({ - status: 'success', - request: request2, - response: expect.objectContaining({ resultDisplay: 'done display' }), - }), - ]); - const toolCalls = result.current[0]; - expect(toolCalls).toHaveLength(0); - }); -}); - -describe('mapToDisplay', () => { - const baseRequest: ToolCallRequestInfo = { - callId: 'testCallId', - name: 'testTool', - args: { foo: 'bar' }, - } as any; - - const baseTool = new MockTool({ - name: 'testTool', - displayName: 'Test Tool Display', - execute: vi.fn(), - shouldConfirmExecute: vi.fn(), - }); - - const baseResponse: ToolCallResponseInfo = { - callId: 'testCallId', - responseParts: [ - { - functionResponse: { - name: 'testTool', - id: 'testCallId', - response: { output: 'Test output' }, - } as FunctionResponse, - } as PartUnion, - ], - resultDisplay: 'Test display output', - error: undefined, - } as any; - - // Define a more specific type for extraProps for these tests - // This helps ensure that tool and confirmationDetails are only accessed when they are expected to exist. - type MapToDisplayExtraProps = - | { - tool?: AnyDeclarativeTool; - invocation?: AnyToolInvocation; - liveOutput?: string; - response?: ToolCallResponseInfo; - confirmationDetails?: ToolCallConfirmationDetails; - } - | { - tool: AnyDeclarativeTool; - invocation?: AnyToolInvocation; - response?: ToolCallResponseInfo; - confirmationDetails?: ToolCallConfirmationDetails; - } - | { - response: ToolCallResponseInfo; - tool?: undefined; - confirmationDetails?: ToolCallConfirmationDetails; - } - | { - confirmationDetails: ToolCallConfirmationDetails; - tool?: AnyDeclarativeTool; - invocation?: AnyToolInvocation; - response?: ToolCallResponseInfo; - }; - - const baseInvocation = baseTool.build(baseRequest.args); - const testCases: Array<{ - name: string; - status: ToolCallStatusType; - extraProps?: MapToDisplayExtraProps; - expectedStatus: ToolCallStatus; - expectedResultDisplay?: string; - expectedName?: string; - expectedDescription?: string; - }> = [ - { - name: 'validating', - status: 'validating', - extraProps: { tool: baseTool, invocation: baseInvocation }, - expectedStatus: ToolCallStatus.Pending, - expectedName: baseTool.displayName, - expectedDescription: baseInvocation.getDescription(), - }, - { - name: 'awaiting_approval', - status: 'awaiting_approval', - extraProps: { - tool: baseTool, - invocation: baseInvocation, - confirmationDetails: { - onConfirm: vi.fn(), - type: 'edit', - title: 'Test Tool Display', - serverName: 'testTool', - toolName: 'testTool', - toolDisplayName: 'Test Tool Display', - filePath: 'mock', - fileName: 'test.ts', - fileDiff: 'Test diff', - originalContent: 'Original content', - newContent: 'New content', - } as ToolCallConfirmationDetails, - }, - expectedStatus: ToolCallStatus.Confirming, - expectedName: baseTool.displayName, - expectedDescription: baseInvocation.getDescription(), - }, - { - name: 'scheduled', - status: 'scheduled', - extraProps: { tool: baseTool, invocation: baseInvocation }, - expectedStatus: ToolCallStatus.Pending, - expectedName: baseTool.displayName, - expectedDescription: baseInvocation.getDescription(), - }, - { - name: 'executing no live output', - status: 'executing', - extraProps: { tool: baseTool, invocation: baseInvocation }, - expectedStatus: ToolCallStatus.Executing, - expectedName: baseTool.displayName, - expectedDescription: baseInvocation.getDescription(), - }, - { - name: 'executing with live output', - status: 'executing', - extraProps: { - tool: baseTool, - invocation: baseInvocation, - liveOutput: 'Live test output', - }, - expectedStatus: ToolCallStatus.Executing, - expectedResultDisplay: 'Live test output', - expectedName: baseTool.displayName, - expectedDescription: baseInvocation.getDescription(), - }, - { - name: 'success', - status: 'success', - extraProps: { - tool: baseTool, - invocation: baseInvocation, - response: baseResponse, - }, - expectedStatus: ToolCallStatus.Success, - expectedResultDisplay: baseResponse.resultDisplay as any, - expectedName: baseTool.displayName, - expectedDescription: baseInvocation.getDescription(), - }, - { - name: 'error tool not found', - status: 'error', - extraProps: { - response: { - ...baseResponse, - error: new Error('Test error tool not found'), - resultDisplay: 'Error display tool not found', - }, - }, - expectedStatus: ToolCallStatus.Error, - expectedResultDisplay: 'Error display tool not found', - expectedName: baseRequest.name, - expectedDescription: JSON.stringify(baseRequest.args), - }, - { - name: 'error tool execution failed', - status: 'error', - extraProps: { - tool: baseTool, - response: { - ...baseResponse, - error: new Error('Tool execution failed'), - resultDisplay: 'Execution failed display', - }, - }, - expectedStatus: ToolCallStatus.Error, - expectedResultDisplay: 'Execution failed display', - expectedName: baseTool.displayName, // Changed from baseTool.name - expectedDescription: JSON.stringify(baseRequest.args), - }, - { - name: 'cancelled', - status: 'cancelled', - extraProps: { - tool: baseTool, - invocation: baseInvocation, - response: { - ...baseResponse, - resultDisplay: 'Cancelled display', - }, - }, - expectedStatus: ToolCallStatus.Canceled, - expectedResultDisplay: 'Cancelled display', - expectedName: baseTool.displayName, - expectedDescription: baseInvocation.getDescription(), - }, - ]; - - testCases.forEach( - ({ - name: testName, - status, - extraProps, - expectedStatus, - expectedResultDisplay, - expectedName, - expectedDescription, - }) => { - it(`should map ToolCall with status '${status}' (${testName}) correctly`, () => { - const toolCall: ToolCall = { - request: baseRequest, - status, - ...(extraProps || {}), - } as ToolCall; - - const display = mapToDisplay(toolCall); - expect(display.type).toBe('tool_group'); - expect(display.tools.length).toBe(1); - const toolDisplay = display.tools[0]; - - expect(toolDisplay.callId).toBe(baseRequest.callId); - expect(toolDisplay.status).toBe(expectedStatus); - expect(toolDisplay.resultDisplay).toBe(expectedResultDisplay); - - expect(toolDisplay.name).toBe(expectedName); - expect(toolDisplay.description).toBe(expectedDescription); - - expect(toolDisplay.renderOutputAsMarkdown).toBe( - extraProps?.tool?.isOutputMarkdown ?? false, - ); - if (status === 'awaiting_approval') { - expect(toolDisplay.confirmationDetails).toBe( - extraProps!.confirmationDetails, - ); - } else { - expect(toolDisplay.confirmationDetails).toBeUndefined(); - } - }); - }, - ); - - it('should map an array of ToolCalls correctly', () => { - const toolCall1: ToolCall = { - request: { ...baseRequest, callId: 'call1' }, - status: 'success', - tool: baseTool, - invocation: baseTool.build(baseRequest.args), - response: { ...baseResponse, callId: 'call1' }, - } as ToolCall; - const toolForCall2 = new MockTool({ - name: baseTool.name, - displayName: baseTool.displayName, - isOutputMarkdown: true, - execute: vi.fn(), - shouldConfirmExecute: vi.fn(), - }); - const toolCall2: ToolCall = { - request: { ...baseRequest, callId: 'call2' }, - status: 'executing', - tool: toolForCall2, - invocation: toolForCall2.build(baseRequest.args), - liveOutput: 'markdown output', - } as ToolCall; - - const display = mapToDisplay([toolCall1, toolCall2]); - expect(display.tools.length).toBe(2); - expect(display.tools[0].callId).toBe('call1'); - expect(display.tools[0].status).toBe(ToolCallStatus.Success); - expect(display.tools[0].renderOutputAsMarkdown).toBe(false); - expect(display.tools[1].callId).toBe('call2'); - expect(display.tools[1].status).toBe(ToolCallStatus.Executing); - expect(display.tools[1].resultDisplay).toBe('markdown output'); - expect(display.tools[1].renderOutputAsMarkdown).toBe(true); + [toolCalls] = result.current; + expect(toolCalls).toHaveLength(2); + expect( + toolCalls.find((t) => t.request.callId === 'call-root')?.status, + ).toBe('executing'); + expect( + toolCalls.find((t) => t.request.callId === 'call-sub')?.schedulerId, + ).toBe('subagent-1'); }); }); diff --git a/packages/cli/src/ui/hooks/useToolScheduler.ts b/packages/cli/src/ui/hooks/useToolScheduler.ts index b6835565e7..b50ed1b717 100644 --- a/packages/cli/src/ui/hooks/useToolScheduler.ts +++ b/packages/cli/src/ui/hooks/useToolScheduler.ts @@ -4,67 +4,273 @@ * SPDX-License-Identifier: Apache-2.0 */ -import type { - Config, - EditorType, - CompletedToolCall, - ToolCallRequestInfo, +import { + type Config, + type MessageBus, + type ToolCallRequestInfo, + type ToolCall, + type CompletedToolCall, + type ToolConfirmationPayload, + MessageBusType, + ToolConfirmationOutcome, + Scheduler, + type EditorType, + type ToolCallsUpdateMessage, + ROOT_SCHEDULER_ID, } from '@google/gemini-cli-core'; -import { - type TrackedScheduledToolCall, - type TrackedValidatingToolCall, - type TrackedWaitingToolCall, - type TrackedExecutingToolCall, - type TrackedCompletedToolCall, - type TrackedCancelledToolCall, - type MarkToolsAsSubmittedFn, - type CancelAllFn, -} from './useReactToolScheduler.js'; -import { - useToolExecutionScheduler, - type TrackedToolCall, -} from './useToolExecutionScheduler.js'; +import { useCallback, useState, useMemo, useEffect, useRef } from 'react'; -// Re-export specific state types from Legacy, as the structures are compatible -// and useGeminiStream relies on them for narrowing. -export type { - TrackedToolCall, - TrackedScheduledToolCall, - TrackedValidatingToolCall, - TrackedWaitingToolCall, - TrackedExecutingToolCall, - TrackedCompletedToolCall, - TrackedCancelledToolCall, - MarkToolsAsSubmittedFn, - CancelAllFn, -}; - -// Unified Schedule function (Promise | Promise) +// Re-exporting types compatible with legacy hook expectations export type ScheduleFn = ( request: ToolCallRequestInfo | ToolCallRequestInfo[], signal: AbortSignal, -) => Promise; +) => Promise; -export type UseToolSchedulerReturn = [ +export type MarkToolsAsSubmittedFn = (callIds: string[]) => void; +export type CancelAllFn = (signal: AbortSignal) => void; + +/** + * The shape expected by useGeminiStream. + * It matches the Core ToolCall structure + the UI metadata flag. + */ +export type TrackedToolCall = ToolCall & { + responseSubmittedToGemini?: boolean; +}; + +// Narrowed types for specific statuses (used by useGeminiStream) +export type TrackedScheduledToolCall = Extract< + TrackedToolCall, + { status: 'scheduled' } +>; +export type TrackedValidatingToolCall = Extract< + TrackedToolCall, + { status: 'validating' } +>; +export type TrackedWaitingToolCall = Extract< + TrackedToolCall, + { status: 'awaiting_approval' } +>; +export type TrackedExecutingToolCall = Extract< + TrackedToolCall, + { status: 'executing' } +>; +export type TrackedCompletedToolCall = Extract< + TrackedToolCall, + { status: 'success' | 'error' } +>; +export type TrackedCancelledToolCall = Extract< + TrackedToolCall, + { status: 'cancelled' } +>; + +/** + * Modern tool scheduler hook using the event-driven Core Scheduler. + */ +export function useToolScheduler( + onComplete: (tools: CompletedToolCall[]) => Promise, + config: Config, + getPreferredEditor: () => EditorType | undefined, +): [ TrackedToolCall[], ScheduleFn, MarkToolsAsSubmittedFn, React.Dispatch>, CancelAllFn, number, -]; +] { + // State stores tool calls organized by their originating schedulerId + const [toolCallsMap, setToolCallsMap] = useState< + Record + >({}); + const [lastToolOutputTime, setLastToolOutputTime] = useState(0); + + const messageBus = useMemo(() => config.getMessageBus(), [config]); + + const onCompleteRef = useRef(onComplete); + useEffect(() => { + onCompleteRef.current = onComplete; + }, [onComplete]); + + const getPreferredEditorRef = useRef(getPreferredEditor); + useEffect(() => { + getPreferredEditorRef.current = getPreferredEditor; + }, [getPreferredEditor]); + + const scheduler = useMemo( + () => + new Scheduler({ + config, + messageBus, + getPreferredEditor: () => getPreferredEditorRef.current(), + schedulerId: ROOT_SCHEDULER_ID, + }), + [config, messageBus], + ); + + const internalAdaptToolCalls = useCallback( + (coreCalls: ToolCall[], prevTracked: TrackedToolCall[]) => + adaptToolCalls(coreCalls, prevTracked, messageBus), + [messageBus], + ); + + useEffect(() => { + const handler = (event: ToolCallsUpdateMessage) => { + // Update output timer for UI spinners (Side Effect) + if (event.toolCalls.some((tc) => tc.status === 'executing')) { + setLastToolOutputTime(Date.now()); + } + + setToolCallsMap((prev) => { + const adapted = internalAdaptToolCalls( + event.toolCalls, + prev[event.schedulerId] ?? [], + ); + + return { + ...prev, + [event.schedulerId]: adapted, + }; + }); + }; + + messageBus.subscribe(MessageBusType.TOOL_CALLS_UPDATE, handler); + return () => { + messageBus.unsubscribe(MessageBusType.TOOL_CALLS_UPDATE, handler); + }; + }, [messageBus, internalAdaptToolCalls]); + + const schedule: ScheduleFn = useCallback( + async (request, signal) => { + // Clear state for new run + setToolCallsMap({}); + + // 1. Await Core Scheduler directly + const results = await scheduler.schedule(request, signal); + + // 2. Trigger legacy reinjection logic (useGeminiStream loop) + // Since this hook instance owns the "root" scheduler, we always trigger + // onComplete when it finishes its batch. + await onCompleteRef.current(results); + + return results; + }, + [scheduler], + ); + + const cancelAll: CancelAllFn = useCallback( + (_signal) => { + scheduler.cancelAll(); + }, + [scheduler], + ); + + const markToolsAsSubmitted: MarkToolsAsSubmittedFn = useCallback( + (callIdsToMark: string[]) => { + setToolCallsMap((prevMap) => { + const nextMap = { ...prevMap }; + for (const [sid, calls] of Object.entries(nextMap)) { + nextMap[sid] = calls.map((tc) => + callIdsToMark.includes(tc.request.callId) + ? { ...tc, responseSubmittedToGemini: true } + : tc, + ); + } + return nextMap; + }); + }, + [], + ); + + // Flatten the map for the UI components that expect a single list of tools. + const toolCalls = useMemo( + () => Object.values(toolCallsMap).flat(), + [toolCallsMap], + ); + + // Provide a setter that maintains compatibility with legacy []. + const setToolCallsForDisplay = useCallback( + (action: React.SetStateAction) => { + setToolCallsMap((prev) => { + const currentFlattened = Object.values(prev).flat(); + const nextFlattened = + typeof action === 'function' ? action(currentFlattened) : action; + + if (nextFlattened.length === 0) { + return {}; + } + + // Re-group by schedulerId to preserve multi-scheduler state + const nextMap: Record = {}; + for (const call of nextFlattened) { + // All tool calls should have a schedulerId from the core. + // Default to ROOT_SCHEDULER_ID as a safeguard. + const sid = call.schedulerId ?? ROOT_SCHEDULER_ID; + if (!nextMap[sid]) { + nextMap[sid] = []; + } + nextMap[sid].push(call); + } + return nextMap; + }); + }, + [], + ); + + return [ + toolCalls, + schedule, + markToolsAsSubmitted, + setToolCallsForDisplay, + cancelAll, + lastToolOutputTime, + ]; +} /** - * Hook that uses the Event-Driven scheduler for tool execution. + * ADAPTER: Merges UI metadata (submitted flag) and injects legacy callbacks. */ -export function useToolScheduler( - onComplete: (tools: CompletedToolCall[]) => Promise, - config: Config, - getPreferredEditor: () => EditorType | undefined, -): UseToolSchedulerReturn { - return useToolExecutionScheduler( - onComplete, - config, - getPreferredEditor, - ) as UseToolSchedulerReturn; +function adaptToolCalls( + coreCalls: ToolCall[], + prevTracked: TrackedToolCall[], + messageBus: MessageBus, +): TrackedToolCall[] { + const prevMap = new Map(prevTracked.map((t) => [t.request.callId, t])); + + return coreCalls.map((coreCall): TrackedToolCall => { + const prev = prevMap.get(coreCall.request.callId); + const responseSubmittedToGemini = prev?.responseSubmittedToGemini ?? false; + + // Inject onConfirm adapter for tools awaiting approval. + // The Core provides data-only (serializable) confirmationDetails. We must + // inject the legacy callback function that proxies responses back to the + // MessageBus. + if (coreCall.status === 'awaiting_approval' && coreCall.correlationId) { + const correlationId = coreCall.correlationId; + return { + ...coreCall, + confirmationDetails: { + ...coreCall.confirmationDetails, + onConfirm: async ( + outcome: ToolConfirmationOutcome, + payload?: ToolConfirmationPayload, + ) => { + await messageBus.publish({ + type: MessageBusType.TOOL_CONFIRMATION_RESPONSE, + correlationId, + confirmed: outcome !== ToolConfirmationOutcome.Cancel, + requiresUserConfirmation: false, + outcome, + payload, + }); + }, + }, + responseSubmittedToGemini, + }; + } + + return { + ...coreCall, + responseSubmittedToGemini, + }; + }); } diff --git a/packages/cli/src/ui/hooks/useTurnActivityMonitor.test.ts b/packages/cli/src/ui/hooks/useTurnActivityMonitor.test.ts index 9ac44c3ebc..f77ab7504d 100644 --- a/packages/cli/src/ui/hooks/useTurnActivityMonitor.test.ts +++ b/packages/cli/src/ui/hooks/useTurnActivityMonitor.test.ts @@ -9,7 +9,7 @@ import { renderHook } from '../../test-utils/render.js'; import { useTurnActivityMonitor } from './useTurnActivityMonitor.js'; import { StreamingState } from '../types.js'; import { hasRedirection } from '@google/gemini-cli-core'; -import { type TrackedToolCall } from './useReactToolScheduler.js'; +import { type TrackedToolCall } from './useToolScheduler.js'; vi.mock('@google/gemini-cli-core', async (importOriginal) => { const actual = await importOriginal>(); diff --git a/packages/cli/src/ui/hooks/useTurnActivityMonitor.ts b/packages/cli/src/ui/hooks/useTurnActivityMonitor.ts index cd6ee7ee8a..8cd7883007 100644 --- a/packages/cli/src/ui/hooks/useTurnActivityMonitor.ts +++ b/packages/cli/src/ui/hooks/useTurnActivityMonitor.ts @@ -7,7 +7,7 @@ import { useState, useEffect, useRef, useMemo } from 'react'; import { StreamingState } from '../types.js'; import { hasRedirection } from '@google/gemini-cli-core'; -import { type TrackedToolCall } from './useReactToolScheduler.js'; +import { type TrackedToolCall } from './useToolScheduler.js'; export interface TurnActivityStatus { operationStartTime: number; From fe75de3efb8d0e1c2a72e9a1edec2a1177f574b9 Mon Sep 17 00:00:00 2001 From: g-samroberts <158088236+g-samroberts@users.noreply.github.com> Date: Wed, 11 Feb 2026 18:03:00 -0800 Subject: [PATCH 14/44] Update changelog for v0.28.0 and v0.29.0-preview0 (#18819) --- docs/changelogs/index.md | 20 + docs/changelogs/latest.md | 722 +++++++++++++++---------------------- docs/changelogs/preview.md | 628 +++++++++++++++++--------------- 3 files changed, 659 insertions(+), 711 deletions(-) diff --git a/docs/changelogs/index.md b/docs/changelogs/index.md index 98e290c30d..013ee3281c 100644 --- a/docs/changelogs/index.md +++ b/docs/changelogs/index.md @@ -18,6 +18,26 @@ on GitHub. | [Preview](preview.md) | Experimental features ready for early feedback. | | [Stable](latest.md) | Stable, recommended for general use. | +## Announcements: v0.28.0 - 2026-02-03 + +- **Slash Command:** We've added a new `/prompt-suggest` slash command to help + you generate prompt suggestions + ([#17264](https://github.com/google-gemini/gemini-cli/pull/17264) by + @NTaylorMullen). +- **IDE Support:** Gemini CLI now supports the Positron IDE + ([#15047](https://github.com/google-gemini/gemini-cli/pull/15047) by + @kapsner). +- **Customization:** You can now use custom themes in extensions, and we've + implemented automatic theme switching based on your terminal's background + ([#17327](https://github.com/google-gemini/gemini-cli/pull/17327) by + @spencer426, [#17976](https://github.com/google-gemini/gemini-cli/pull/17976) + by @Abhijit-2592). +- **Authentication:** We've added interactive and non-interactive consent for + OAuth, and you can now include your auth method in bug reports + ([#17699](https://github.com/google-gemini/gemini-cli/pull/17699) by + @ehedlund, [#17569](https://github.com/google-gemini/gemini-cli/pull/17569) by + @erikus). + ## Announcements: v0.27.0 - 2026-02-03 - **Event-Driven Architecture:** The CLI now uses a new event-driven scheduler diff --git a/docs/changelogs/latest.md b/docs/changelogs/latest.md index ce0a0fdfff..6ba7b88e1c 100644 --- a/docs/changelogs/latest.md +++ b/docs/changelogs/latest.md @@ -1,6 +1,6 @@ -# Latest stable release: v0.27.0 +# Latest stable release: v0.28.0 -Released: February 3, 2026 +Released: February 10, 2026 For most users, our latest stable release is the recommended release. Install the latest stable version with: @@ -11,437 +11,305 @@ npm install -g @google/gemini-cli ## Highlights -- **Event-Driven Architecture:** The CLI now uses an event-driven scheduler for - tool execution, improving performance and responsiveness. This includes - migrating non-interactive flows and sub-agents to the new scheduler. -- **Enhanced User Experience:** This release introduces several UI/UX - improvements, including queued tool confirmations and the ability to expand - and collapse large pasted text blocks. The `Settings` dialog has been improved - to reduce jitter and preserve focus. -- **Agent and Skill Improvements:** Agent Skills have been promoted to a stable - feature. Sub-agents now use a JSON schema for input and are tracked by an - `AgentRegistry`. -- **New `/rewind` Command:** A new `/rewind` command has been implemented to - allow users to go back in their session history. -- **Improved Shell and File Handling:** The shell tool's output format has been - optimized, and the CLI now gracefully handles disk-full errors during chat - recording. A bug in detecting already added paths has been fixed. -- **Linux Clipboard Support:** Image pasting capabilities for Wayland and X11 on - Linux have been added. +- **Commands & UX Enhancements:** Introduced `/prompt-suggest` command, + alongside updated undo/redo keybindings and automatic theme switching. +- **Expanded IDE Support:** Now offering compatibility with Positron IDE, + expanding integration options for developers. +- **Enhanced Security & Authentication:** Implemented interactive and + non-interactive OAuth consent, improving both security and diagnostic + capabilities for bug reports. +- **Advanced Planning & Agent Tools:** Integrated a generic Checklist component + for structured task management and evolved subagent capabilities with dynamic + policy registration. +- **Improved Core Stability & Reliability:** Resolved critical environment + loading, authentication, and session management issues, ensuring a more robust + experience. +- **Background Shell Commands:** Enabled the execution of shell commands in the + background for increased workflow efficiency. ## What's Changed -- remove fireAgent and beforeAgent hook by @ishaanxgupta in - [#16919](https://github.com/google-gemini/gemini-cli/pull/16919) -- Remove unused modelHooks and toolHooks by @ved015 in - [#17115](https://github.com/google-gemini/gemini-cli/pull/17115) -- feat(cli): sanitize ANSI escape sequences in non-interactive output by - @sehoon38 in [#17172](https://github.com/google-gemini/gemini-cli/pull/17172) -- Update Attempt text to Retry when showing the retry happening to the … by - @sehoon38 in [#17178](https://github.com/google-gemini/gemini-cli/pull/17178) -- chore(skills): update pr-creator skill workflow by @sehoon38 in - [#17180](https://github.com/google-gemini/gemini-cli/pull/17180) -- feat(cli): implement event-driven tool execution scheduler by @abhipatel12 in - [#17078](https://github.com/google-gemini/gemini-cli/pull/17078) -- chore(release): bump version to 0.27.0-nightly.20260121.97aac696f by +- feat(commands): add /prompt-suggest slash command by @NTaylorMullen in + [#17264](https://github.com/google-gemini/gemini-cli/pull/17264) +- feat(cli): align hooks enable/disable with skills and improve completion by + @sehoon38 in [#16822](https://github.com/google-gemini/gemini-cli/pull/16822) +- docs: add CLI reference documentation by @leochiu-a in + [#17504](https://github.com/google-gemini/gemini-cli/pull/17504) +- chore(release): bump version to 0.28.0-nightly.20260128.adc8e11bb by @gemini-cli-robot in - [#17181](https://github.com/google-gemini/gemini-cli/pull/17181) -- Remove other rewind reference in docs by @chrstnb in - [#17149](https://github.com/google-gemini/gemini-cli/pull/17149) -- feat(skills): add code-reviewer skill by @sehoon38 in - [#17187](https://github.com/google-gemini/gemini-cli/pull/17187) -- feat(plan): Extend Shift+Tab Mode Cycling to include Plan Mode by @Adib234 in - [#17177](https://github.com/google-gemini/gemini-cli/pull/17177) -- feat(plan): refactor TestRig and eval helper to support configurable approval - modes by @jerop in - [#17171](https://github.com/google-gemini/gemini-cli/pull/17171) -- feat(workflows): support recursive workstream labeling and new IDs by - @bdmorgan in [#17207](https://github.com/google-gemini/gemini-cli/pull/17207) -- Run evals for all models. by @gundermanc in - [#17123](https://github.com/google-gemini/gemini-cli/pull/17123) -- fix(github): improve label-workstream-rollup efficiency with GraphQL by - @bdmorgan in [#17217](https://github.com/google-gemini/gemini-cli/pull/17217) -- Docs: Update changelogs for v.0.25.0 and v0.26.0-preview.0 releases. by - @g-samroberts in - [#17215](https://github.com/google-gemini/gemini-cli/pull/17215) -- Migrate beforeTool and afterTool hooks to hookSystem by @ved015 in - [#17204](https://github.com/google-gemini/gemini-cli/pull/17204) -- fix(github): improve label-workstream-rollup efficiency and fix bugs by - @bdmorgan in [#17219](https://github.com/google-gemini/gemini-cli/pull/17219) -- feat(cli): improve skill enablement/disablement verbiage by @NTaylorMullen in - [#17192](https://github.com/google-gemini/gemini-cli/pull/17192) -- fix(admin): Ensure CLI commands run in non-interactive mode by @skeshive in - [#17218](https://github.com/google-gemini/gemini-cli/pull/17218) -- feat(core): support dynamic variable substitution in system prompt override by - @NTaylorMullen in - [#17042](https://github.com/google-gemini/gemini-cli/pull/17042) -- fix(core,cli): enable recursive directory access for by @galz10 in - [#17094](https://github.com/google-gemini/gemini-cli/pull/17094) -- Docs: Marking for experimental features by @jkcinouye in - [#16760](https://github.com/google-gemini/gemini-cli/pull/16760) -- Support command/ctrl/alt backspace correctly by @scidomino in - [#17175](https://github.com/google-gemini/gemini-cli/pull/17175) -- feat(plan): add approval mode instructions to system prompt by @jerop in - [#17151](https://github.com/google-gemini/gemini-cli/pull/17151) -- feat(core): enable disableLLMCorrection by default by @SandyTao520 in - [#17223](https://github.com/google-gemini/gemini-cli/pull/17223) -- Remove unused slug from sidebar by @chrstnb in - [#17229](https://github.com/google-gemini/gemini-cli/pull/17229) -- drain stdin on exit by @scidomino in - [#17241](https://github.com/google-gemini/gemini-cli/pull/17241) -- refactor(cli): decouple UI from live tool execution via ToolActionsContext by + [#17725](https://github.com/google-gemini/gemini-cli/pull/17725) +- feat(skills): final stable promotion cleanup by @abhipatel12 in + [#17726](https://github.com/google-gemini/gemini-cli/pull/17726) +- test(core): mock fetch in OAuth transport fallback tests by @jw409 in + [#17059](https://github.com/google-gemini/gemini-cli/pull/17059) +- feat(cli): include auth method in /bug by @erikus in + [#17569](https://github.com/google-gemini/gemini-cli/pull/17569) +- Add a email privacy note to bug_report template by @nemyung in + [#17474](https://github.com/google-gemini/gemini-cli/pull/17474) +- Rewind documentation by @Adib234 in + [#17446](https://github.com/google-gemini/gemini-cli/pull/17446) +- fix: verify audio/video MIME types with content check by @maru0804 in + [#16907](https://github.com/google-gemini/gemini-cli/pull/16907) +- feat(core): add support for positron ide + ([#15045](https://github.com/google-gemini/gemini-cli/pull/15045)) by @kapsner + in [#15047](https://github.com/google-gemini/gemini-cli/pull/15047) +- /oncall dedup - wrap texts to nextlines by @sehoon38 in + [#17782](https://github.com/google-gemini/gemini-cli/pull/17782) +- fix(admin): rename advanced features admin setting by @skeshive in + [#17786](https://github.com/google-gemini/gemini-cli/pull/17786) +- [extension config] Make breaking optional value non-optional by @chrstnb in + [#17785](https://github.com/google-gemini/gemini-cli/pull/17785) +- Fix docs-writer skill issues by @g-samroberts in + [#17734](https://github.com/google-gemini/gemini-cli/pull/17734) +- fix(core): suppress duplicate hook failure warnings during streaming by @abhipatel12 in - [#17183](https://github.com/google-gemini/gemini-cli/pull/17183) -- fix(core): update token count and telemetry on /chat resume history load by - @psinha40898 in - [#16279](https://github.com/google-gemini/gemini-cli/pull/16279) -- fix: /policy to display policies according to mode by @ishaanxgupta in - [#16772](https://github.com/google-gemini/gemini-cli/pull/16772) -- fix(core): simplify replace tool error message by @SandyTao520 in - [#17246](https://github.com/google-gemini/gemini-cli/pull/17246) -- feat(cli): consolidate shell inactivity and redirection monitoring by - @NTaylorMullen in - [#17086](https://github.com/google-gemini/gemini-cli/pull/17086) -- fix(scheduler): prevent stale tool re-publication and fix stuck UI state by + [#17727](https://github.com/google-gemini/gemini-cli/pull/17727) +- test: add more tests for AskUser by @jackwotherspoon in + [#17720](https://github.com/google-gemini/gemini-cli/pull/17720) +- feat(cli): enable activity logging for non-interactive mode and evals by + @SandyTao520 in + [#17703](https://github.com/google-gemini/gemini-cli/pull/17703) +- feat(core): add support for custom deny messages in policy rules by + @allenhutchison in + [#17427](https://github.com/google-gemini/gemini-cli/pull/17427) +- Fix unintended credential exposure to MCP Servers by @Adib234 in + [#17311](https://github.com/google-gemini/gemini-cli/pull/17311) +- feat(extensions): add support for custom themes in extensions by @spencer426 + in [#17327](https://github.com/google-gemini/gemini-cli/pull/17327) +- fix: persist and restore workspace directories on session resume by + @korade-krushna in + [#17454](https://github.com/google-gemini/gemini-cli/pull/17454) +- Update release notes pages for 0.26.0 and 0.27.0-preview. by @g-samroberts in + [#17744](https://github.com/google-gemini/gemini-cli/pull/17744) +- feat(ux): update cell border color and created test file for table rendering + by @devr0306 in + [#17798](https://github.com/google-gemini/gemini-cli/pull/17798) +- Change height for the ToolConfirmationQueue. by @jacob314 in + [#17799](https://github.com/google-gemini/gemini-cli/pull/17799) +- feat(cli): add user identity info to stats command by @sehoon38 in + [#17612](https://github.com/google-gemini/gemini-cli/pull/17612) +- fix(ux): fixed off-by-some wrapping caused by fixed-width characters by + @devr0306 in [#17816](https://github.com/google-gemini/gemini-cli/pull/17816) +- feat(cli): update undo/redo keybindings to Cmd+Z/Alt+Z and + Shift+Cmd+Z/Shift+Alt+Z by @scidomino in + [#17800](https://github.com/google-gemini/gemini-cli/pull/17800) +- fix(evals): use absolute path for activity log directory by @SandyTao520 in + [#17830](https://github.com/google-gemini/gemini-cli/pull/17830) +- test: add integration test to verify stdout/stderr routing by @ved015 in + [#17280](https://github.com/google-gemini/gemini-cli/pull/17280) +- fix(cli): list installed extensions when update target missing by @tt-a1i in + [#17082](https://github.com/google-gemini/gemini-cli/pull/17082) +- fix(cli): handle PAT tokens and credentials in git remote URL parsing by + @afarber in [#14650](https://github.com/google-gemini/gemini-cli/pull/14650) +- fix(core): use returnDisplay for error result display by @Nubebuster in + [#14994](https://github.com/google-gemini/gemini-cli/pull/14994) +- Fix detection of bun as package manager by @Randomblock1 in + [#17462](https://github.com/google-gemini/gemini-cli/pull/17462) +- feat(cli): show hooksConfig.enabled in settings dialog by @abhipatel12 in + [#17810](https://github.com/google-gemini/gemini-cli/pull/17810) +- feat(cli): Display user identity (auth, email, tier) on startup by @yunaseoul + in [#17591](https://github.com/google-gemini/gemini-cli/pull/17591) +- fix: prevent ghost border for AskUserDialog by @jackwotherspoon in + [#17788](https://github.com/google-gemini/gemini-cli/pull/17788) +- docs: mark A2A subagents as experimental in subagents.md by @adamfweidman in + [#17863](https://github.com/google-gemini/gemini-cli/pull/17863) +- Resolve error thrown for sensitive values by @chrstnb in + [#17826](https://github.com/google-gemini/gemini-cli/pull/17826) +- fix(admin): Rename secureModeEnabled to strictModeDisabled by @skeshive in + [#17789](https://github.com/google-gemini/gemini-cli/pull/17789) +- feat(ux): update truncate dots to be shorter in tables by @devr0306 in + [#17825](https://github.com/google-gemini/gemini-cli/pull/17825) +- fix(core): resolve DEP0040 punycode deprecation via patch-package by + @ATHARVA262005 in + [#17692](https://github.com/google-gemini/gemini-cli/pull/17692) +- feat(plan): create generic Checklist component and refactor Todo by @Adib234 + in [#17741](https://github.com/google-gemini/gemini-cli/pull/17741) +- Cleanup post delegate_to_agent removal by @gundermanc in + [#17875](https://github.com/google-gemini/gemini-cli/pull/17875) +- fix(core): use GIT_CONFIG_GLOBAL to isolate shadow git repo configuration - + Fixes [#17877](https://github.com/google-gemini/gemini-cli/pull/17877) by + @cocosheng-g in + [#17803](https://github.com/google-gemini/gemini-cli/pull/17803) +- Disable mouse tracking e2e by @alisa-alisa in + [#17880](https://github.com/google-gemini/gemini-cli/pull/17880) +- fix(cli): use correct setting key for Cloud Shell auth by @sehoon38 in + [#17884](https://github.com/google-gemini/gemini-cli/pull/17884) +- chore: revert IDE specific ASCII logo by @jackwotherspoon in + [#17887](https://github.com/google-gemini/gemini-cli/pull/17887) +- Revert "fix(core): resolve DEP0040 punycode deprecation via patch-package" by + @sehoon38 in [#17898](https://github.com/google-gemini/gemini-cli/pull/17898) +- Refactoring of disabling of mouse tracking in e2e tests by @alisa-alisa in + [#17902](https://github.com/google-gemini/gemini-cli/pull/17902) +- feat(core): Add GOOGLE_GENAI_API_VERSION environment variable support by + @deyim in [#16177](https://github.com/google-gemini/gemini-cli/pull/16177) +- feat(core): Isolate and cleanup truncated tool outputs by @SandyTao520 in + [#17594](https://github.com/google-gemini/gemini-cli/pull/17594) +- Create skills page, update commands, refine docs by @g-samroberts in + [#17842](https://github.com/google-gemini/gemini-cli/pull/17842) +- feat: preserve EOL in files by @Thomas-Shephard in + [#16087](https://github.com/google-gemini/gemini-cli/pull/16087) +- Fix HalfLinePaddedBox in screenreader mode. by @jacob314 in + [#17914](https://github.com/google-gemini/gemini-cli/pull/17914) +- bug(ux) vim mode fixes. Start in insert mode. Fix bug blocking F12 and ctrl-X + in vim mode. by @jacob314 in + [#17938](https://github.com/google-gemini/gemini-cli/pull/17938) +- feat(core): implement interactive and non-interactive consent for OAuth by + @ehedlund in [#17699](https://github.com/google-gemini/gemini-cli/pull/17699) +- perf(core): optimize token calculation and add support for multimodal tool + responses by @abhipatel12 in + [#17835](https://github.com/google-gemini/gemini-cli/pull/17835) +- refactor(hooks): remove legacy tools.enableHooks setting by @abhipatel12 in + [#17867](https://github.com/google-gemini/gemini-cli/pull/17867) +- feat(ci): add npx smoke test to verify installability by @bdmorgan in + [#17927](https://github.com/google-gemini/gemini-cli/pull/17927) +- feat(core): implement dynamic policy registration for subagents by @abhipatel12 in - [#17227](https://github.com/google-gemini/gemini-cli/pull/17227) -- feat(config): default enableEventDrivenScheduler to true by @abhipatel12 in - [#17211](https://github.com/google-gemini/gemini-cli/pull/17211) -- feat(hooks): enable hooks system by default by @abhipatel12 in - [#17247](https://github.com/google-gemini/gemini-cli/pull/17247) -- feat(core): Enable AgentRegistry to track all discovered subagents by + [#17838](https://github.com/google-gemini/gemini-cli/pull/17838) +- feat: Implement background shell commands by @galz10 in + [#14849](https://github.com/google-gemini/gemini-cli/pull/14849) +- feat(admin): provide actionable error messages for disabled features by + @skeshive in [#17815](https://github.com/google-gemini/gemini-cli/pull/17815) +- Fix bugs where Rewind and Resume showed Ugly and 100X too verbose content. by + @jacob314 in [#17940](https://github.com/google-gemini/gemini-cli/pull/17940) +- Fix broken link in docs by @chrstnb in + [#17959](https://github.com/google-gemini/gemini-cli/pull/17959) +- feat(plan): reuse standard tool confirmation for AskUser tool by @jerop in + [#17864](https://github.com/google-gemini/gemini-cli/pull/17864) +- feat(core): enable overriding CODE_ASSIST_API_VERSION with env var by + @lottielin in [#17942](https://github.com/google-gemini/gemini-cli/pull/17942) +- run npx pointing to the specific commit SHA by @sehoon38 in + [#17970](https://github.com/google-gemini/gemini-cli/pull/17970) +- Add allowedExtensions setting by @kevinjwang1 in + [#17695](https://github.com/google-gemini/gemini-cli/pull/17695) +- feat(plan): refactor ToolConfirmationPayload to union type by @jerop in + [#17980](https://github.com/google-gemini/gemini-cli/pull/17980) +- lower the default max retries to reduce contention by @sehoon38 in + [#17975](https://github.com/google-gemini/gemini-cli/pull/17975) +- fix(core): ensure YOLO mode auto-approves complex shell commands when parsing + fails by @abhipatel12 in + [#17920](https://github.com/google-gemini/gemini-cli/pull/17920) +- Fix broken link. by @g-samroberts in + [#17972](https://github.com/google-gemini/gemini-cli/pull/17972) +- Support ctrl-C and Ctrl-D correctly Refactor so InputPrompt has priority over + AppContainer for input handling. by @jacob314 in + [#17993](https://github.com/google-gemini/gemini-cli/pull/17993) +- Fix truncation for AskQuestion by @jacob314 in + [#18001](https://github.com/google-gemini/gemini-cli/pull/18001) +- fix(workflow): update maintainer check logic to be inclusive and + case-insensitive by @bdmorgan in + [#18009](https://github.com/google-gemini/gemini-cli/pull/18009) +- Fix Esc cancel during streaming by @LyalinDotCom in + [#18039](https://github.com/google-gemini/gemini-cli/pull/18039) +- feat(acp): add session resume support by @bdmorgan in + [#18043](https://github.com/google-gemini/gemini-cli/pull/18043) +- fix(ci): prevent stale PR closer from incorrectly closing new PRs by @bdmorgan + in [#18069](https://github.com/google-gemini/gemini-cli/pull/18069) +- chore: delete autoAccept setting unused in production by @victorvianna in + [#17862](https://github.com/google-gemini/gemini-cli/pull/17862) +- feat(plan): use placeholder for choice question "Other" option by @jerop in + [#18101](https://github.com/google-gemini/gemini-cli/pull/18101) +- docs: update clearContext to hookSpecificOutput by @jackwotherspoon in + [#18024](https://github.com/google-gemini/gemini-cli/pull/18024) +- docs-writer skill: Update docs writer skill by @jkcinouye in + [#17928](https://github.com/google-gemini/gemini-cli/pull/17928) +- Sehoon/oncall filter by @sehoon38 in + [#18105](https://github.com/google-gemini/gemini-cli/pull/18105) +- feat(core): add setting to disable loop detection by @SandyTao520 in + [#18008](https://github.com/google-gemini/gemini-cli/pull/18008) +- Docs: Revise docs/index.md by @jkcinouye in + [#17879](https://github.com/google-gemini/gemini-cli/pull/17879) +- Fix up/down arrow regression and add test. by @jacob314 in + [#18108](https://github.com/google-gemini/gemini-cli/pull/18108) +- fix(ui): prevent content leak in MaxSizedBox bottom overflow by @jerop in + [#17991](https://github.com/google-gemini/gemini-cli/pull/17991) +- refactor: migrate checks.ts utility to core and deduplicate by @jerop in + [#18139](https://github.com/google-gemini/gemini-cli/pull/18139) +- feat(core): implement tool name aliasing for backward compatibility by @SandyTao520 in - [#17253](https://github.com/google-gemini/gemini-cli/pull/17253) -- feat(core): Have subagents use a JSON schema type for input. by @joshualitt in - [#17152](https://github.com/google-gemini/gemini-cli/pull/17152) -- feat: replace large text pastes with [Pasted Text: X lines] placeholder by - @jackwotherspoon in - [#16422](https://github.com/google-gemini/gemini-cli/pull/16422) -- security(hooks): Wrap hook-injected context in distinct XML tags by @yunaseoul - in [#17237](https://github.com/google-gemini/gemini-cli/pull/17237) -- Enable the ability to queue specific nightly eval tests by @gundermanc in - [#17262](https://github.com/google-gemini/gemini-cli/pull/17262) -- docs(hooks): comprehensive update of hook documentation and specs by - @abhipatel12 in - [#16816](https://github.com/google-gemini/gemini-cli/pull/16816) -- refactor: improve large text paste placeholder by @jacob314 in - [#17269](https://github.com/google-gemini/gemini-cli/pull/17269) -- feat: implement /rewind command by @Adib234 in - [#15720](https://github.com/google-gemini/gemini-cli/pull/15720) -- Feature/jetbrains ide detection by @SoLoHiC in - [#16243](https://github.com/google-gemini/gemini-cli/pull/16243) -- docs: update typo in mcp-server.md file by @schifferl in - [#17099](https://github.com/google-gemini/gemini-cli/pull/17099) -- Sanitize command names and descriptions by @ehedlund in - [#17228](https://github.com/google-gemini/gemini-cli/pull/17228) -- fix(auth): don't crash when initial auth fails by @skeshive in - [#17308](https://github.com/google-gemini/gemini-cli/pull/17308) -- Added image pasting capabilities for Wayland and X11 on Linux by @devr0306 in - [#17144](https://github.com/google-gemini/gemini-cli/pull/17144) -- feat: add AskUser tool schema by @jackwotherspoon in - [#16988](https://github.com/google-gemini/gemini-cli/pull/16988) -- fix cli settings: resolve layout jitter in settings bar by @Mag1ck in - [#16256](https://github.com/google-gemini/gemini-cli/pull/16256) -- fix: show whitespace changes in edit tool diffs by @Ujjiyara in - [#17213](https://github.com/google-gemini/gemini-cli/pull/17213) -- Remove redundant calls setting linuxClipboardTool. getUserLinuxClipboardTool() - now handles the caching internally by @jacob314 in - [#17320](https://github.com/google-gemini/gemini-cli/pull/17320) -- ci: allow failure in evals-nightly run step by @gundermanc in - [#17319](https://github.com/google-gemini/gemini-cli/pull/17319) -- feat(cli): Add state management and plumbing for agent configuration dialog by - @SandyTao520 in - [#17259](https://github.com/google-gemini/gemini-cli/pull/17259) -- bug: fix ide-client connection to ide-companion when inside docker via - ssh/devcontainer by @kapsner in - [#15049](https://github.com/google-gemini/gemini-cli/pull/15049) -- Emit correct newline type return by @scidomino in - [#17331](https://github.com/google-gemini/gemini-cli/pull/17331) -- New skill: docs-writer by @g-samroberts in - [#17268](https://github.com/google-gemini/gemini-cli/pull/17268) -- fix(core): Resolve AbortSignal MaxListenersExceededWarning (#5950) by - @spencer426 in - [#16735](https://github.com/google-gemini/gemini-cli/pull/16735) -- Disable tips after 10 runs by @Adib234 in - [#17101](https://github.com/google-gemini/gemini-cli/pull/17101) -- Fix so rewind starts at the bottom and loadHistory refreshes static content. - by @jacob314 in - [#17335](https://github.com/google-gemini/gemini-cli/pull/17335) -- feat(core): Remove legacy settings. by @joshualitt in - [#17244](https://github.com/google-gemini/gemini-cli/pull/17244) -- feat(plan): add 'communicate' tool kind by @jerop in - [#17341](https://github.com/google-gemini/gemini-cli/pull/17341) -- feat(routing): A/B Test Numerical Complexity Scoring for Gemini 3 by - @mattKorwel in - [#16041](https://github.com/google-gemini/gemini-cli/pull/16041) -- feat(plan): update UI Theme for Plan Mode by @Adib234 in - [#17243](https://github.com/google-gemini/gemini-cli/pull/17243) -- fix(ui): stabilize rendering during terminal resize in alternate buffer by - @lkk214 in [#15783](https://github.com/google-gemini/gemini-cli/pull/15783) -- feat(cli): add /agents config command and improve agent discovery by - @SandyTao520 in - [#17342](https://github.com/google-gemini/gemini-cli/pull/17342) -- feat(mcp): add enable/disable commands for MCP servers (#11057) by @jasmeetsb - in [#16299](https://github.com/google-gemini/gemini-cli/pull/16299) -- fix(cli)!: Default to interactive mode for positional arguments by - @ishaanxgupta in - [#16329](https://github.com/google-gemini/gemini-cli/pull/16329) -- Fix issue #17080 by @jacob314 in - [#17100](https://github.com/google-gemini/gemini-cli/pull/17100) -- feat(core): Refresh agents after loading an extension. by @joshualitt in - [#17355](https://github.com/google-gemini/gemini-cli/pull/17355) -- fix(cli): include source in policy rule display by @allenhutchison in - [#17358](https://github.com/google-gemini/gemini-cli/pull/17358) -- fix: remove obsolete CloudCode PerDay quota and 120s terminal threshold by + [#17974](https://github.com/google-gemini/gemini-cli/pull/17974) +- docs: fix help-wanted label spelling by @pavan-sh in + [#18114](https://github.com/google-gemini/gemini-cli/pull/18114) +- feat(cli): implement automatic theme switching based on terminal background by + @Abhijit-2592 in + [#17976](https://github.com/google-gemini/gemini-cli/pull/17976) +- fix(ide): no-op refactoring that moves the connection logic to helper + functions by @skeshive in + [#18118](https://github.com/google-gemini/gemini-cli/pull/18118) +- feat: update review-frontend-and-fix slash command to review-and-fix by + @galz10 in [#18146](https://github.com/google-gemini/gemini-cli/pull/18146) +- fix: improve Ctrl+R reverse search by @jackwotherspoon in + [#18075](https://github.com/google-gemini/gemini-cli/pull/18075) +- feat(plan): handle inconsistency in schedulers by @Adib234 in + [#17813](https://github.com/google-gemini/gemini-cli/pull/17813) +- feat(plan): add core logic and exit_plan_mode tool definition by @jerop in + [#18110](https://github.com/google-gemini/gemini-cli/pull/18110) +- feat(core): rename search_file_content tool to grep_search and add legacy + alias by @SandyTao520 in + [#18003](https://github.com/google-gemini/gemini-cli/pull/18003) +- fix(core): prioritize detailed error messages for code assist setup by @gsquared94 in - [#17236](https://github.com/google-gemini/gemini-cli/pull/17236) -- Refactor subagent delegation to be one tool per agent by @gundermanc in - [#17346](https://github.com/google-gemini/gemini-cli/pull/17346) -- fix(core): Include MCP server name in OAuth message by @jerop in - [#17351](https://github.com/google-gemini/gemini-cli/pull/17351) -- Fix pr-triage.sh script to update pull requests with tags "help wanted" and - "maintainer only" by @jacob314 in - [#17324](https://github.com/google-gemini/gemini-cli/pull/17324) -- feat(plan): implement simple workflow for planning in main agent by @jerop in - [#17326](https://github.com/google-gemini/gemini-cli/pull/17326) -- fix: exit with non-zero code when esbuild is missing by @yuvrajangadsingh in - [#16967](https://github.com/google-gemini/gemini-cli/pull/16967) -- fix: ensure @docs/cli/custom-commands.md UI message ordering and test by - @medic-code in - [#12038](https://github.com/google-gemini/gemini-cli/pull/12038) -- fix(core): add alternative command names for Antigravity editor detec… by - @baeseokjae in - [#16829](https://github.com/google-gemini/gemini-cli/pull/16829) -- Refactor: Migrate CLI appEvents to Core coreEvents by @Adib234 in - [#15737](https://github.com/google-gemini/gemini-cli/pull/15737) -- fix(core): await MCP initialization in non-interactive mode by @Ratish1 in - [#17390](https://github.com/google-gemini/gemini-cli/pull/17390) -- Fix modifyOtherKeys enablement on unsupported terminals by @seekskyworld in - [#16714](https://github.com/google-gemini/gemini-cli/pull/16714) -- fix(core): gracefully handle disk full errors in chat recording by - @godwiniheuwa in - [#17305](https://github.com/google-gemini/gemini-cli/pull/17305) -- fix(oauth): update oauth to use 127.0.0.1 instead of localhost by @skeshive in - [#17388](https://github.com/google-gemini/gemini-cli/pull/17388) -- fix(core): use RFC 9728 compliant path-based OAuth protected resource - discovery by @vrv in - [#15756](https://github.com/google-gemini/gemini-cli/pull/15756) -- Update Code Wiki README badge by @PatoBeltran in - [#15229](https://github.com/google-gemini/gemini-cli/pull/15229) -- Add conda installation instructions for Gemini CLI by @ishaanxgupta in - [#16921](https://github.com/google-gemini/gemini-cli/pull/16921) -- chore(refactor): extract BaseSettingsDialog component by @SandyTao520 in - [#17369](https://github.com/google-gemini/gemini-cli/pull/17369) -- fix(cli): preserve input text when declining tool approval (#15624) by - @ManojINaik in - [#15659](https://github.com/google-gemini/gemini-cli/pull/15659) -- chore: upgrade dep: diff 7.0.0-> 8.0.3 by @scidomino in - [#17403](https://github.com/google-gemini/gemini-cli/pull/17403) -- feat: add AskUserDialog for UI component of AskUser tool by @jackwotherspoon - in [#17344](https://github.com/google-gemini/gemini-cli/pull/17344) -- feat(ui): display user tier in about command by @sehoon38 in - [#17400](https://github.com/google-gemini/gemini-cli/pull/17400) -- feat: add clearContext to AfterAgent hooks by @jackwotherspoon in - [#16574](https://github.com/google-gemini/gemini-cli/pull/16574) -- fix(cli): change image paste location to global temp directory (#17396) by - @devr0306 in [#17396](https://github.com/google-gemini/gemini-cli/pull/17396) -- Fix line endings issue with Notice file by @scidomino in - [#17417](https://github.com/google-gemini/gemini-cli/pull/17417) -- feat(plan): implement persistent approvalMode setting by @Adib234 in - [#17350](https://github.com/google-gemini/gemini-cli/pull/17350) -- feat(ui): Move keyboard handling into BaseSettingsDialog by @SandyTao520 in - [#17404](https://github.com/google-gemini/gemini-cli/pull/17404) -- Allow prompt queueing during MCP initialization by @Adib234 in - [#17395](https://github.com/google-gemini/gemini-cli/pull/17395) -- feat: implement AgentConfigDialog for /agents config command by @SandyTao520 - in [#17370](https://github.com/google-gemini/gemini-cli/pull/17370) -- fix(agents): default to all tools when tool list is omitted in subagents by - @gundermanc in - [#17422](https://github.com/google-gemini/gemini-cli/pull/17422) -- feat(cli): Moves tool confirmations to a queue UX by @abhipatel12 in - [#17276](https://github.com/google-gemini/gemini-cli/pull/17276) -- fix(core): hide user tier name by @sehoon38 in - [#17418](https://github.com/google-gemini/gemini-cli/pull/17418) -- feat: Enforce unified folder trust for /directory add by @galz10 in - [#17359](https://github.com/google-gemini/gemini-cli/pull/17359) -- migrate fireToolNotificationHook to hookSystem by @ved015 in - [#17398](https://github.com/google-gemini/gemini-cli/pull/17398) -- Clean up dead code by @scidomino in - [#17443](https://github.com/google-gemini/gemini-cli/pull/17443) -- feat(workflow): add stale pull request closer with linked-issue enforcement by - @bdmorgan in [#17449](https://github.com/google-gemini/gemini-cli/pull/17449) -- feat(workflow): expand stale-exempt labels to include help wanted and Public - Roadmap by @bdmorgan in - [#17459](https://github.com/google-gemini/gemini-cli/pull/17459) -- chore(workflow): remove redundant label-enforcer workflow by @bdmorgan in - [#17460](https://github.com/google-gemini/gemini-cli/pull/17460) -- Resolves the confusing error message `ripgrep exited with code null that - occurs when a search operation is cancelled or aborted by @maximmasiutin in - [#14267](https://github.com/google-gemini/gemini-cli/pull/14267) -- fix: detect pnpm/pnpx in ~/.local by @rwakulszowa in - [#15254](https://github.com/google-gemini/gemini-cli/pull/15254) -- docs: Add instructions for MacPorts and uninstall instructions for Homebrew by - @breun in [#17412](https://github.com/google-gemini/gemini-cli/pull/17412) -- docs(hooks): clarify mandatory 'type' field and update hook schema - documentation by @abhipatel12 in - [#17499](https://github.com/google-gemini/gemini-cli/pull/17499) -- Improve error messages on failed onboarding by @gsquared94 in - [#17357](https://github.com/google-gemini/gemini-cli/pull/17357) -- Follow up to "enableInteractiveShell for external tooling relying on a2a - server" by @DavidAPierce in - [#17130](https://github.com/google-gemini/gemini-cli/pull/17130) -- Fix/issue 17070 by @alih552 in - [#17242](https://github.com/google-gemini/gemini-cli/pull/17242) -- fix(core): handle URI-encoded workspace paths in IdeClient by @dong-jun-shin - in [#17476](https://github.com/google-gemini/gemini-cli/pull/17476) -- feat(cli): add quick clear input shortcuts in vim mode by @harshanadim in - [#17470](https://github.com/google-gemini/gemini-cli/pull/17470) -- feat(core): optimize shell tool llmContent output format by @SandyTao520 in - [#17538](https://github.com/google-gemini/gemini-cli/pull/17538) -- Fix bug in detecting already added paths. by @jacob314 in - [#17430](https://github.com/google-gemini/gemini-cli/pull/17430) -- feat(scheduler): support multi-scheduler tool aggregation and nested call IDs - by @abhipatel12 in - [#17429](https://github.com/google-gemini/gemini-cli/pull/17429) -- feat(agents): implement first-run experience for project-level sub-agents by - @gundermanc in - [#17266](https://github.com/google-gemini/gemini-cli/pull/17266) -- Update extensions docs by @chrstnb in - [#16093](https://github.com/google-gemini/gemini-cli/pull/16093) -- Docs: Refactor left nav on the website by @jkcinouye in - [#17558](https://github.com/google-gemini/gemini-cli/pull/17558) -- fix(core): stream grep/ripgrep output to prevent OOM by @adamfweidman in - [#17146](https://github.com/google-gemini/gemini-cli/pull/17146) -- feat(plan): add persistent plan file storage by @jerop in - [#17563](https://github.com/google-gemini/gemini-cli/pull/17563) -- feat(agents): migrate subagents to event-driven scheduler by @abhipatel12 in - [#17567](https://github.com/google-gemini/gemini-cli/pull/17567) -- Fix extensions config error by @chrstnb in - [#17580](https://github.com/google-gemini/gemini-cli/pull/17580) -- fix(plan): remove subagent invocation from plan mode by @jerop in - [#17593](https://github.com/google-gemini/gemini-cli/pull/17593) -- feat(ui): add solid background color option for input prompt by @jacob314 in - [#16563](https://github.com/google-gemini/gemini-cli/pull/16563) -- feat(plan): refresh system prompt when approval mode changes (Shift+Tab) by - @jerop in [#17585](https://github.com/google-gemini/gemini-cli/pull/17585) -- feat(cli): add global setting to disable UI spinners by @galz10 in - [#17234](https://github.com/google-gemini/gemini-cli/pull/17234) -- fix(security): enforce strict policy directory permissions by @yunaseoul in - [#17353](https://github.com/google-gemini/gemini-cli/pull/17353) -- test(core): fix tests in windows by @scidomino in - [#17592](https://github.com/google-gemini/gemini-cli/pull/17592) -- feat(mcp/extensions): Allow users to selectively enable/disable MCP servers - included in an extension( Issue #11057 & #17402) by @jasmeetsb in - [#17434](https://github.com/google-gemini/gemini-cli/pull/17434) -- Always map mac keys, even on other platforms by @scidomino in - [#17618](https://github.com/google-gemini/gemini-cli/pull/17618) -- Ctrl-O by @jacob314 in - [#17617](https://github.com/google-gemini/gemini-cli/pull/17617) -- feat(plan): update cycling order of approval modes by @Adib234 in - [#17622](https://github.com/google-gemini/gemini-cli/pull/17622) -- fix(cli): restore 'Modify with editor' option in external terminals by - @abhipatel12 in - [#17621](https://github.com/google-gemini/gemini-cli/pull/17621) -- Slash command for helping in debugging by @gundermanc in - [#17609](https://github.com/google-gemini/gemini-cli/pull/17609) -- feat: add double-click to expand/collapse large paste placeholders by - @jackwotherspoon in - [#17471](https://github.com/google-gemini/gemini-cli/pull/17471) -- refactor(cli): migrate non-interactive flow to event-driven scheduler by - @abhipatel12 in - [#17572](https://github.com/google-gemini/gemini-cli/pull/17572) -- fix: loadcodeassist eligible tiers getting ignored for unlicensed users - (regression) by @gsquared94 in - [#17581](https://github.com/google-gemini/gemini-cli/pull/17581) -- chore(core): delete legacy nonInteractiveToolExecutor by @abhipatel12 in - [#17573](https://github.com/google-gemini/gemini-cli/pull/17573) -- feat(core): enforce server prefixes for MCP tools in agent definitions by - @abhipatel12 in - [#17574](https://github.com/google-gemini/gemini-cli/pull/17574) -- feat (mcp): Refresh MCP prompts on list changed notification by @MrLesk in - [#14863](https://github.com/google-gemini/gemini-cli/pull/14863) -- feat(ui): pretty JSON rendering tool outputs by @medic-code in - [#9767](https://github.com/google-gemini/gemini-cli/pull/9767) -- Fix iterm alternate buffer mode issue rendering backgrounds by @jacob314 in - [#17634](https://github.com/google-gemini/gemini-cli/pull/17634) -- feat(cli): add gemini extensions list --output-format=json by @AkihiroSuda in - [#14479](https://github.com/google-gemini/gemini-cli/pull/14479) -- fix(extensions): add .gitignore to extension templates by @godwiniheuwa in - [#17293](https://github.com/google-gemini/gemini-cli/pull/17293) -- paste transform followup by @jacob314 in - [#17624](https://github.com/google-gemini/gemini-cli/pull/17624) -- refactor: rename formatMemoryUsage to formatBytes by @Nubebuster in - [#14997](https://github.com/google-gemini/gemini-cli/pull/14997) -- chore: remove extra top margin from /hooks and /extensions by @jackwotherspoon - in [#17663](https://github.com/google-gemini/gemini-cli/pull/17663) -- feat(cli): add oncall command for issue triage by @sehoon38 in - [#17661](https://github.com/google-gemini/gemini-cli/pull/17661) -- Fix sidebar issue for extensions link by @chrstnb in - [#17668](https://github.com/google-gemini/gemini-cli/pull/17668) -- Change formatting to prevent UI redressing attacks by @scidomino in - [#17611](https://github.com/google-gemini/gemini-cli/pull/17611) -- Fix cluster of bugs in the settings dialog. by @jacob314 in - [#17628](https://github.com/google-gemini/gemini-cli/pull/17628) -- Update sidebar to resolve site build issues by @chrstnb in - [#17674](https://github.com/google-gemini/gemini-cli/pull/17674) -- fix(admin): fix a few bugs related to admin controls by @skeshive in - [#17590](https://github.com/google-gemini/gemini-cli/pull/17590) -- revert bad changes to tests by @scidomino in - [#17673](https://github.com/google-gemini/gemini-cli/pull/17673) -- feat(cli): show candidate issue state reason and duplicate status in triage by - @sehoon38 in [#17676](https://github.com/google-gemini/gemini-cli/pull/17676) -- Fix missing slash commands when Gemini CLI is in a project with a package.json - that doesn't follow semantic versioning by @Adib234 in - [#17561](https://github.com/google-gemini/gemini-cli/pull/17561) -- feat(core): Model family-specific system prompts by @joshualitt in - [#17614](https://github.com/google-gemini/gemini-cli/pull/17614) -- Sub-agents documentation. by @gundermanc in - [#16639](https://github.com/google-gemini/gemini-cli/pull/16639) -- feat: wire up AskUserTool with dialog by @jackwotherspoon in - [#17411](https://github.com/google-gemini/gemini-cli/pull/17411) -- Load extension settings for hooks, agents, skills by @chrstnb in - [#17245](https://github.com/google-gemini/gemini-cli/pull/17245) -- Fix issue where Gemini CLI can make changes when simply asked a question by - @gundermanc in - [#17608](https://github.com/google-gemini/gemini-cli/pull/17608) -- Update docs-writer skill for editing and add style guide for reference. by - @g-samroberts in - [#17669](https://github.com/google-gemini/gemini-cli/pull/17669) -- fix(ux): have user message display a short path for pasted images by @devr0306 - in [#17613](https://github.com/google-gemini/gemini-cli/pull/17613) -- feat(plan): enable AskUser tool in Plan mode for clarifying questions by - @jerop in [#17694](https://github.com/google-gemini/gemini-cli/pull/17694) -- GEMINI.md polish by @jacob314 in - [#17680](https://github.com/google-gemini/gemini-cli/pull/17680) -- refactor(core): centralize path validation and allow temp dir access for tools - by @NTaylorMullen in - [#17185](https://github.com/google-gemini/gemini-cli/pull/17185) -- feat(skills): promote Agent Skills to stable by @abhipatel12 in - [#17693](https://github.com/google-gemini/gemini-cli/pull/17693) -- refactor(cli): keyboard handling and AskUserDialog by @jacob314 in - [#17414](https://github.com/google-gemini/gemini-cli/pull/17414) -- docs: Add Experimental Remote Agent Docs by @adamfweidman in - [#17697](https://github.com/google-gemini/gemini-cli/pull/17697) -- revert: promote Agent Skills to stable (#17693) by @abhipatel12 in - [#17712](https://github.com/google-gemini/gemini-cli/pull/17712) -- feat(ux) Expandable (ctrl-O) and scrollable approvals in alternate buffer - mode. by @jacob314 in - [#17640](https://github.com/google-gemini/gemini-cli/pull/17640) -- feat(skills): promote skills settings to stable by @abhipatel12 in - [#17713](https://github.com/google-gemini/gemini-cli/pull/17713) -- fix(cli): Preserve settings dialog focus when searching by @SandyTao520 in - [#17701](https://github.com/google-gemini/gemini-cli/pull/17701) -- feat(ui): add terminal cursor support by @jacob314 in - [#17711](https://github.com/google-gemini/gemini-cli/pull/17711) -- docs(skills): remove experimental labels and update tutorials by @abhipatel12 - in [#17714](https://github.com/google-gemini/gemini-cli/pull/17714) -- docs: remove 'experimental' syntax for hooks in docs by @abhipatel12 in - [#17660](https://github.com/google-gemini/gemini-cli/pull/17660) -- Add support for an additional exclusion file besides .gitignore and - .geminiignore by @alisa-alisa in - [#16487](https://github.com/google-gemini/gemini-cli/pull/16487) -- feat: add review-frontend-and-fix command by @galz10 in - [#17707](https://github.com/google-gemini/gemini-cli/pull/17707) + [#17852](https://github.com/google-gemini/gemini-cli/pull/17852) +- fix(cli): resolve environment loading and auth validation issues in ACP mode + by @bdmorgan in + [#18025](https://github.com/google-gemini/gemini-cli/pull/18025) +- feat(core): add .agents/skills directory alias for skill discovery by + @NTaylorMullen in + [#18151](https://github.com/google-gemini/gemini-cli/pull/18151) +- chore(core): reassign telemetry keys to avoid server conflict by @mattKorwel + in [#18161](https://github.com/google-gemini/gemini-cli/pull/18161) +- Add link to rewind doc in commands.md by @Adib234 in + [#17961](https://github.com/google-gemini/gemini-cli/pull/17961) +- feat(core): add draft-2020-12 JSON Schema support with lenient fallback by + @afarber in [#15060](https://github.com/google-gemini/gemini-cli/pull/15060) +- refactor(core): robust trimPreservingTrailingNewline and regression test by + @adamfweidman in + [#18196](https://github.com/google-gemini/gemini-cli/pull/18196) +- Remove MCP servers on extension uninstall by @chrstnb in + [#18121](https://github.com/google-gemini/gemini-cli/pull/18121) +- refactor: localize ACP error parsing logic to cli package by @bdmorgan in + [#18193](https://github.com/google-gemini/gemini-cli/pull/18193) +- feat(core): Add A2A auth config types by @adamfweidman in + [#18205](https://github.com/google-gemini/gemini-cli/pull/18205) +- Set default max attempts to 3 and use the common variable by @sehoon38 in + [#18209](https://github.com/google-gemini/gemini-cli/pull/18209) +- feat(plan): add exit_plan_mode ui and prompt by @jerop in + [#18162](https://github.com/google-gemini/gemini-cli/pull/18162) +- fix(test): improve test isolation and enable subagent evaluations by + @cocosheng-g in + [#18138](https://github.com/google-gemini/gemini-cli/pull/18138) +- feat(plan): use custom deny messages in plan mode policies by @Adib234 in + [#18195](https://github.com/google-gemini/gemini-cli/pull/18195) +- Match on extension ID when stopping extensions by @chrstnb in + [#18218](https://github.com/google-gemini/gemini-cli/pull/18218) +- fix(core): Respect user's .gitignore preference by @xyrolle in + [#15482](https://github.com/google-gemini/gemini-cli/pull/15482) +- docs: document GEMINI_CLI_HOME environment variable by @adamfweidman in + [#18219](https://github.com/google-gemini/gemini-cli/pull/18219) +- chore(core): explicitly state plan storage path in prompt by @jerop in + [#18222](https://github.com/google-gemini/gemini-cli/pull/18222) +- A2a admin setting by @DavidAPierce in + [#17868](https://github.com/google-gemini/gemini-cli/pull/17868) +- feat(a2a): Add pluggable auth provider infrastructure by @adamfweidman in + [#17934](https://github.com/google-gemini/gemini-cli/pull/17934) +- Fix handling of empty settings by @chrstnb in + [#18131](https://github.com/google-gemini/gemini-cli/pull/18131) +- Reload skills when extensions change by @chrstnb in + [#18225](https://github.com/google-gemini/gemini-cli/pull/18225) +- feat: Add markdown rendering to ask_user tool by @jackwotherspoon in + [#18211](https://github.com/google-gemini/gemini-cli/pull/18211) +- Add telemetry to rewind by @Adib234 in + [#18122](https://github.com/google-gemini/gemini-cli/pull/18122) +- feat(admin): add support for MCP configuration via admin controls (pt1) by + @skeshive in [#18223](https://github.com/google-gemini/gemini-cli/pull/18223) +- feat(core): require user consent before MCP server OAuth by @ehedlund in + [#18132](https://github.com/google-gemini/gemini-cli/pull/18132) +- fix(sandbox): propagate GOOGLE_GEMINI_BASE_URL&GOOGLE_VERTEX_BASE_URL env vars + by @skeshive in + [#18231](https://github.com/google-gemini/gemini-cli/pull/18231) +- feat(ui): move user identity display to header by @sehoon38 in + [#18216](https://github.com/google-gemini/gemini-cli/pull/18216) +- fix: enforce folder trust for workspace settings, skills, and context by + @galz10 in [#17596](https://github.com/google-gemini/gemini-cli/pull/17596) -**Full changelog**: -https://github.com/google-gemini/gemini-cli/compare/v0.26.0...v0.27.0 +**Full Changelog**: +https://github.com/google-gemini/gemini-cli/compare/v0.27.0...v0.28.0 diff --git a/docs/changelogs/preview.md b/docs/changelogs/preview.md index 93ed5a2a9c..cab75c4446 100644 --- a/docs/changelogs/preview.md +++ b/docs/changelogs/preview.md @@ -1,6 +1,6 @@ -# Preview release: Release v0.28.0-preview.0 +# Preview release: Release v0.29.0-preview.0 -Released: February 3, 2026 +Released: February 10, 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). @@ -13,295 +13,355 @@ npm install -g @google/gemini-cli@preview ## Highlights -- **Improved Hooks Management:** Hooks enable/disable functionality now aligns - with skills and offers improved completion. -- **Custom Themes for Extensions:** Extensions can now support custom themes, - allowing for greater personalization. -- **User Identity Display:** User identity information (auth, email, tier) is - now displayed on startup and in the `stats` command. -- **Plan Mode Enhancements:** Plan mode has been improved with a generic - `Checklist` component and refactored `Todo`. -- **Background Shell Commands:** Implementation of background shell commands. +- **Plan Mode Enhancements**: Significant updates to Plan Mode, including new + commands, support for MCP servers, integration of planning artifacts, and + improved iteration guidance. +- **Core Agent Improvements**: Enhancements to the core agent, including better + system prompt rigor, improved subagent definitions, and enhanced tool + execution limits. +- **CLI UX/UI Updates**: Various UI and UX improvements, such as autocomplete in + the input prompt, updated approval mode labels, DevTools integration, and + improved header spacing. +- **Tooling & Extension Updates**: Improvements to existing tools like + `ask_user` and `grep_search`, and new features for extension management. +- **Bug Fixes**: Numerous bug fixes across the CLI and core, addressing issues + with interactive commands, memory leaks, permission checks, and more. +- **Context and Tool Output Management**: Features for observation masking for + tool outputs, session-linked tool output storage, and persistence for masked + tool outputs. ## What's Changed -- feat(commands): add /prompt-suggest slash command by NTaylorMullen in - [#17264](https://github.com/google-gemini/gemini-cli/pull/17264) -- feat(cli): align hooks enable/disable with skills and improve completion by - sehoon38 in [#16822](https://github.com/google-gemini/gemini-cli/pull/16822) -- docs: add CLI reference documentation by leochiu-a in - [#17504](https://github.com/google-gemini/gemini-cli/pull/17504) -- chore(release): bump version to 0.28.0-nightly.20260128.adc8e11bb by +- fix: remove ask_user tool from non-interactive modes by jackwotherspoon in + [#18154](https://github.com/google-gemini/gemini-cli/pull/18154) +- fix(cli): allow restricted .env loading in untrusted sandboxed folders by + galz10 in [#17806](https://github.com/google-gemini/gemini-cli/pull/17806) +- Encourage agent to utilize ecosystem tools to perform work by gundermanc in + [#17881](https://github.com/google-gemini/gemini-cli/pull/17881) +- feat(plan): unify workflow location in system prompt to optimize caching by + jerop in [#18258](https://github.com/google-gemini/gemini-cli/pull/18258) +- feat(core): enable getUserTierName in config by sehoon38 in + [#18265](https://github.com/google-gemini/gemini-cli/pull/18265) +- feat(core): add default execution limits for subagents by abhipatel12 in + [#18274](https://github.com/google-gemini/gemini-cli/pull/18274) +- Fix issue where agent gets stuck at interactive commands. by gundermanc in + [#18272](https://github.com/google-gemini/gemini-cli/pull/18272) +- chore(release): bump version to 0.29.0-nightly.20260203.71f46f116 by gemini-cli-robot in - [#17725](https://github.com/google-gemini/gemini-cli/pull/17725) -- feat(skills): final stable promotion cleanup by abhipatel12 in - [#17726](https://github.com/google-gemini/gemini-cli/pull/17726) -- test(core): mock fetch in OAuth transport fallback tests by jw409 in - [#17059](https://github.com/google-gemini/gemini-cli/pull/17059) -- feat(cli): include auth method in /bug by erikus in - [#17569](https://github.com/google-gemini/gemini-cli/pull/17569) -- Add a email privacy note to bug_report template by nemyung in - [#17474](https://github.com/google-gemini/gemini-cli/pull/17474) -- Rewind documentation by Adib234 in - [#17446](https://github.com/google-gemini/gemini-cli/pull/17446) -- fix: verify audio/video MIME types with content check by maru0804 in - [#16907](https://github.com/google-gemini/gemini-cli/pull/16907) -- feat(core): add support for positron ide (#15045) by kapsner in - [#15047](https://github.com/google-gemini/gemini-cli/pull/15047) -- /oncall dedup - wrap texts to nextlines by sehoon38 in - [#17782](https://github.com/google-gemini/gemini-cli/pull/17782) -- fix(admin): rename advanced features admin setting by skeshive in - [#17786](https://github.com/google-gemini/gemini-cli/pull/17786) -- [extension config] Make breaking optional value non-optional by chrstnb in - [#17785](https://github.com/google-gemini/gemini-cli/pull/17785) -- Fix docs-writer skill issues by g-samroberts in - [#17734](https://github.com/google-gemini/gemini-cli/pull/17734) -- fix(core): suppress duplicate hook failure warnings during streaming by + [#18243](https://github.com/google-gemini/gemini-cli/pull/18243) +- feat(core): remove hardcoded policy bypass for local subagents by abhipatel12 + in [#18153](https://github.com/google-gemini/gemini-cli/pull/18153) +- feat(plan): implement plan slash command by Adib234 in + [#17698](https://github.com/google-gemini/gemini-cli/pull/17698) +- feat: increase ask_user label limit to 16 characters by jackwotherspoon in + [#18320](https://github.com/google-gemini/gemini-cli/pull/18320) +- Add information about the agent skills lifecycle and clarify docs-writer skill + metadata. by g-samroberts in + [#18234](https://github.com/google-gemini/gemini-cli/pull/18234) +- feat(core): add enter_plan_mode tool by jerop in + [#18324](https://github.com/google-gemini/gemini-cli/pull/18324) +- Stop showing an error message in /plan by Adib234 in + [#18333](https://github.com/google-gemini/gemini-cli/pull/18333) +- fix(hooks): remove unnecessary logging for hook registration by abhipatel12 in + [#18332](https://github.com/google-gemini/gemini-cli/pull/18332) +- fix(mcp): ensure MCP transport is closed to prevent memory leaks by cbcoutinho + in [#18054](https://github.com/google-gemini/gemini-cli/pull/18054) +- feat(skills): implement linking for agent skills by MushuEE in + [#18295](https://github.com/google-gemini/gemini-cli/pull/18295) +- Changelogs for 0.27.0 and 0.28.0-preview0 by g-samroberts in + [#18336](https://github.com/google-gemini/gemini-cli/pull/18336) +- chore: correct docs as skills and hooks are stable by jackwotherspoon in + [#18358](https://github.com/google-gemini/gemini-cli/pull/18358) +- feat(admin): Implement admin allowlist for MCP server configurations by + skeshive in [#18311](https://github.com/google-gemini/gemini-cli/pull/18311) +- fix(core): add retry logic for transient SSL/TLS errors + ([#17318](https://github.com/google-gemini/gemini-cli/pull/17318)) by + ppgranger in [#18310](https://github.com/google-gemini/gemini-cli/pull/18310) +- Add support for /extensions config command by chrstnb in + [#17895](https://github.com/google-gemini/gemini-cli/pull/17895) +- fix(core): handle non-compliant mcpbridge responses from Xcode 26.3 by + peterfriese in + [#18376](https://github.com/google-gemini/gemini-cli/pull/18376) +- feat(cli): Add W, B, E Vim motions and operator support by ademuri in + [#16209](https://github.com/google-gemini/gemini-cli/pull/16209) +- fix: Windows Specific Agent Quality & System Prompt by scidomino in + [#18351](https://github.com/google-gemini/gemini-cli/pull/18351) +- feat(plan): support replace tool in plan mode to edit plans by jerop in + [#18379](https://github.com/google-gemini/gemini-cli/pull/18379) +- Improving memory tool instructions and eval testing by alisa-alisa in + [#18091](https://github.com/google-gemini/gemini-cli/pull/18091) +- fix(cli): color extension link success message green by MushuEE in + [#18386](https://github.com/google-gemini/gemini-cli/pull/18386) +- undo by jacob314 in + [#18147](https://github.com/google-gemini/gemini-cli/pull/18147) +- feat(plan): add guidance on iterating on approved plans vs creating new plans + by jerop in [#18346](https://github.com/google-gemini/gemini-cli/pull/18346) +- feat(plan): fix invalid tool calls in plan mode by Adib234 in + [#18352](https://github.com/google-gemini/gemini-cli/pull/18352) +- feat(plan): integrate planning artifacts and tools into primary workflows by + jerop in [#18375](https://github.com/google-gemini/gemini-cli/pull/18375) +- Fix permission check by scidomino in + [#18395](https://github.com/google-gemini/gemini-cli/pull/18395) +- ux(polish) autocomplete in the input prompt by jacob314 in + [#18181](https://github.com/google-gemini/gemini-cli/pull/18181) +- fix: resolve infinite loop when using 'Modify with external editor' by + ppgranger in [#17453](https://github.com/google-gemini/gemini-cli/pull/17453) +- feat: expand verify-release to macOS and Windows by yunaseoul in + [#18145](https://github.com/google-gemini/gemini-cli/pull/18145) +- feat(plan): implement support for MCP servers in Plan mode by Adib234 in + [#18229](https://github.com/google-gemini/gemini-cli/pull/18229) +- chore: update folder trust error messaging by galz10 in + [#18402](https://github.com/google-gemini/gemini-cli/pull/18402) +- feat(plan): create a metric for execution of plans generated in plan mode by + Adib234 in [#18236](https://github.com/google-gemini/gemini-cli/pull/18236) +- perf(ui): optimize stripUnsafeCharacters with regex by gsquared94 in + [#18413](https://github.com/google-gemini/gemini-cli/pull/18413) +- feat(context): implement observation masking for tool outputs by abhipatel12 + in [#18389](https://github.com/google-gemini/gemini-cli/pull/18389) +- feat(core,cli): implement session-linked tool output storage and cleanup by abhipatel12 in - [#17727](https://github.com/google-gemini/gemini-cli/pull/17727) -- test: add more tests for AskUser by jackwotherspoon in - [#17720](https://github.com/google-gemini/gemini-cli/pull/17720) -- feat(cli): enable activity logging for non-interactive mode and evals by - SandyTao520 in - [#17703](https://github.com/google-gemini/gemini-cli/pull/17703) -- feat(core): add support for custom deny messages in policy rules by - allenhutchison in - [#17427](https://github.com/google-gemini/gemini-cli/pull/17427) -- Fix unintended credential exposure to MCP Servers by Adib234 in - [#17311](https://github.com/google-gemini/gemini-cli/pull/17311) -- feat(extensions): add support for custom themes in extensions by spencer426 in - [#17327](https://github.com/google-gemini/gemini-cli/pull/17327) -- fix: persist and restore workspace directories on session resume by - korade-krushna in - [#17454](https://github.com/google-gemini/gemini-cli/pull/17454) -- Update release notes pages for 0.26.0 and 0.27.0-preview. by g-samroberts in - [#17744](https://github.com/google-gemini/gemini-cli/pull/17744) -- feat(ux): update cell border color and created test file for table rendering - by devr0306 in - [#17798](https://github.com/google-gemini/gemini-cli/pull/17798) -- Change height for the ToolConfirmationQueue. by jacob314 in - [#17799](https://github.com/google-gemini/gemini-cli/pull/17799) -- feat(cli): add user identity info to stats command by sehoon38 in - [#17612](https://github.com/google-gemini/gemini-cli/pull/17612) -- fix(ux): fixed off-by-some wrapping caused by fixed-width characters by - devr0306 in [#17816](https://github.com/google-gemini/gemini-cli/pull/17816) -- feat(cli): update undo/redo keybindings to Cmd+Z/Alt+Z and - Shift+Cmd+Z/Shift+Alt+Z by scidomino in - [#17800](https://github.com/google-gemini/gemini-cli/pull/17800) -- fix(evals): use absolute path for activity log directory by SandyTao520 in - [#17830](https://github.com/google-gemini/gemini-cli/pull/17830) -- test: add integration test to verify stdout/stderr routing by ved015 in - [#17280](https://github.com/google-gemini/gemini-cli/pull/17280) -- fix(cli): list installed extensions when update target missing by tt-a1i in - [#17082](https://github.com/google-gemini/gemini-cli/pull/17082) -- fix(cli): handle PAT tokens and credentials in git remote URL parsing by - afarber in [#14650](https://github.com/google-gemini/gemini-cli/pull/14650) -- fix(core): use returnDisplay for error result display by Nubebuster in - [#14994](https://github.com/google-gemini/gemini-cli/pull/14994) -- Fix detection of bun as package manager by Randomblock1 in - [#17462](https://github.com/google-gemini/gemini-cli/pull/17462) -- feat(cli): show hooksConfig.enabled in settings dialog by abhipatel12 in - [#17810](https://github.com/google-gemini/gemini-cli/pull/17810) -- feat(cli): Display user identity (auth, email, tier) on startup by yunaseoul - in [#17591](https://github.com/google-gemini/gemini-cli/pull/17591) -- fix: prevent ghost border for AskUserDialog by jackwotherspoon in - [#17788](https://github.com/google-gemini/gemini-cli/pull/17788) -- docs: mark A2A subagents as experimental in subagents.md by adamfweidman in - [#17863](https://github.com/google-gemini/gemini-cli/pull/17863) -- Resolve error thrown for sensitive values by chrstnb in - [#17826](https://github.com/google-gemini/gemini-cli/pull/17826) -- fix(admin): Rename secureModeEnabled to strictModeDisabled by skeshive in - [#17789](https://github.com/google-gemini/gemini-cli/pull/17789) -- feat(ux): update truncate dots to be shorter in tables by devr0306 in - [#17825](https://github.com/google-gemini/gemini-cli/pull/17825) -- fix(core): resolve DEP0040 punycode deprecation via patch-package by - ATHARVA262005 in - [#17692](https://github.com/google-gemini/gemini-cli/pull/17692) -- feat(plan): create generic Checklist component and refactor Todo by Adib234 in - [#17741](https://github.com/google-gemini/gemini-cli/pull/17741) -- Cleanup post delegate_to_agent removal by gundermanc in - [#17875](https://github.com/google-gemini/gemini-cli/pull/17875) -- fix(core): use GIT_CONFIG_GLOBAL to isolate shadow git repo configuration - - Fixes #17877 by cocosheng-g in - [#17803](https://github.com/google-gemini/gemini-cli/pull/17803) -- Disable mouse tracking e2e by alisa-alisa in - [#17880](https://github.com/google-gemini/gemini-cli/pull/17880) -- fix(cli): use correct setting key for Cloud Shell auth by sehoon38 in - [#17884](https://github.com/google-gemini/gemini-cli/pull/17884) -- chore: revert IDE specific ASCII logo by jackwotherspoon in - [#17887](https://github.com/google-gemini/gemini-cli/pull/17887) -- Revert "fix(core): resolve DEP0040 punycode deprecation via patch-package" by - sehoon38 in [#17898](https://github.com/google-gemini/gemini-cli/pull/17898) -- Refactoring of disabling of mouse tracking in e2e tests by alisa-alisa in - [#17902](https://github.com/google-gemini/gemini-cli/pull/17902) -- feat(core): Add GOOGLE_GENAI_API_VERSION environment variable support by deyim - in [#16177](https://github.com/google-gemini/gemini-cli/pull/16177) -- feat(core): Isolate and cleanup truncated tool outputs by SandyTao520 in - [#17594](https://github.com/google-gemini/gemini-cli/pull/17594) -- Create skills page, update commands, refine docs by g-samroberts in - [#17842](https://github.com/google-gemini/gemini-cli/pull/17842) -- feat: preserve EOL in files by Thomas-Shephard in - [#16087](https://github.com/google-gemini/gemini-cli/pull/16087) -- Fix HalfLinePaddedBox in screenreader mode. by jacob314 in - [#17914](https://github.com/google-gemini/gemini-cli/pull/17914) -- bug(ux) vim mode fixes. Start in insert mode. Fix bug blocking F12 and ctrl-X - in vim mode. by jacob314 in - [#17938](https://github.com/google-gemini/gemini-cli/pull/17938) -- feat(core): implement interactive and non-interactive consent for OAuth by - ehedlund in [#17699](https://github.com/google-gemini/gemini-cli/pull/17699) -- perf(core): optimize token calculation and add support for multimodal tool - responses by abhipatel12 in - [#17835](https://github.com/google-gemini/gemini-cli/pull/17835) -- refactor(hooks): remove legacy tools.enableHooks setting by abhipatel12 in - [#17867](https://github.com/google-gemini/gemini-cli/pull/17867) -- feat(ci): add npx smoke test to verify installability by bdmorgan in - [#17927](https://github.com/google-gemini/gemini-cli/pull/17927) -- feat(core): implement dynamic policy registration for subagents by abhipatel12 - in [#17838](https://github.com/google-gemini/gemini-cli/pull/17838) -- feat: Implement background shell commands by galz10 in - [#14849](https://github.com/google-gemini/gemini-cli/pull/14849) -- feat(admin): provide actionable error messages for disabled features by - skeshive in [#17815](https://github.com/google-gemini/gemini-cli/pull/17815) -- Fix bugs where Rewind and Resume showed Ugly and 100X too verbose content. by - jacob314 in [#17940](https://github.com/google-gemini/gemini-cli/pull/17940) -- Fix broken link in docs by chrstnb in - [#17959](https://github.com/google-gemini/gemini-cli/pull/17959) -- feat(plan): reuse standard tool confirmation for AskUser tool by jerop in - [#17864](https://github.com/google-gemini/gemini-cli/pull/17864) -- feat(core): enable overriding CODE_ASSIST_API_VERSION with env var by - lottielin in [#17942](https://github.com/google-gemini/gemini-cli/pull/17942) -- run npx pointing to the specific commit SHA by sehoon38 in - [#17970](https://github.com/google-gemini/gemini-cli/pull/17970) -- Add allowedExtensions setting by kevinjwang1 in - [#17695](https://github.com/google-gemini/gemini-cli/pull/17695) -- feat(plan): refactor ToolConfirmationPayload to union type by jerop in - [#17980](https://github.com/google-gemini/gemini-cli/pull/17980) -- lower the default max retries to reduce contention by sehoon38 in - [#17975](https://github.com/google-gemini/gemini-cli/pull/17975) -- fix(core): ensure YOLO mode auto-approves complex shell commands when parsing - fails by abhipatel12 in - [#17920](https://github.com/google-gemini/gemini-cli/pull/17920) -- Fix broken link. by g-samroberts in - [#17972](https://github.com/google-gemini/gemini-cli/pull/17972) -- Support ctrl-C and Ctrl-D correctly Refactor so InputPrompt has priority over - AppContainer for input handling. by jacob314 in - [#17993](https://github.com/google-gemini/gemini-cli/pull/17993) -- Fix truncation for AskQuestion by jacob314 in - [#18001](https://github.com/google-gemini/gemini-cli/pull/18001) -- fix(workflow): update maintainer check logic to be inclusive and - case-insensitive by bdmorgan in - [#18009](https://github.com/google-gemini/gemini-cli/pull/18009) -- Fix Esc cancel during streaming by LyalinDotCom in - [#18039](https://github.com/google-gemini/gemini-cli/pull/18039) -- feat(acp): add session resume support by bdmorgan in - [#18043](https://github.com/google-gemini/gemini-cli/pull/18043) -- fix(ci): prevent stale PR closer from incorrectly closing new PRs by bdmorgan - in [#18069](https://github.com/google-gemini/gemini-cli/pull/18069) -- chore: delete autoAccept setting unused in production by victorvianna in - [#17862](https://github.com/google-gemini/gemini-cli/pull/17862) -- feat(plan): use placeholder for choice question "Other" option by jerop in - [#18101](https://github.com/google-gemini/gemini-cli/pull/18101) -- docs: update clearContext to hookSpecificOutput by jackwotherspoon in - [#18024](https://github.com/google-gemini/gemini-cli/pull/18024) -- docs-writer skill: Update docs writer skill by jkcinouye in - [#17928](https://github.com/google-gemini/gemini-cli/pull/17928) -- Sehoon/oncall filter by sehoon38 in - [#18105](https://github.com/google-gemini/gemini-cli/pull/18105) -- feat(core): add setting to disable loop detection by SandyTao520 in - [#18008](https://github.com/google-gemini/gemini-cli/pull/18008) -- Docs: Revise docs/index.md by jkcinouye in - [#17879](https://github.com/google-gemini/gemini-cli/pull/17879) -- Fix up/down arrow regression and add test. by jacob314 in - [#18108](https://github.com/google-gemini/gemini-cli/pull/18108) -- fix(ui): prevent content leak in MaxSizedBox bottom overflow by jerop in - [#17991](https://github.com/google-gemini/gemini-cli/pull/17991) -- refactor: migrate checks.ts utility to core and deduplicate by jerop in - [#18139](https://github.com/google-gemini/gemini-cli/pull/18139) -- feat(core): implement tool name aliasing for backward compatibility by - SandyTao520 in - [#17974](https://github.com/google-gemini/gemini-cli/pull/17974) -- docs: fix help-wanted label spelling by pavan-sh in - [#18114](https://github.com/google-gemini/gemini-cli/pull/18114) -- feat(cli): implement automatic theme switching based on terminal background by + [#18416](https://github.com/google-gemini/gemini-cli/pull/18416) +- Shorten temp directory by joshualitt in + [#17901](https://github.com/google-gemini/gemini-cli/pull/17901) +- feat(plan): add behavioral evals for plan mode by jerop in + [#18437](https://github.com/google-gemini/gemini-cli/pull/18437) +- Add extension registry client by chrstnb in + [#18396](https://github.com/google-gemini/gemini-cli/pull/18396) +- Enable extension config by default by chrstnb in + [#18447](https://github.com/google-gemini/gemini-cli/pull/18447) +- Automatically generate change logs on release by g-samroberts in + [#18401](https://github.com/google-gemini/gemini-cli/pull/18401) +- Remove previewFeatures and default to Gemini 3 by sehoon38 in + [#18414](https://github.com/google-gemini/gemini-cli/pull/18414) +- feat(admin): apply MCP allowlist to extensions & gemini mcp list command by + skeshive in [#18442](https://github.com/google-gemini/gemini-cli/pull/18442) +- fix(cli): improve focus navigation for interactive and background shells by + galz10 in [#18343](https://github.com/google-gemini/gemini-cli/pull/18343) +- Add shortcuts hint and panel for discoverability by LyalinDotCom in + [#18035](https://github.com/google-gemini/gemini-cli/pull/18035) +- fix(config): treat system settings as read-only during migration and warn user + by spencer426 in + [#18277](https://github.com/google-gemini/gemini-cli/pull/18277) +- feat(plan): add positive test case and update eval stability policy by jerop + in [#18457](https://github.com/google-gemini/gemini-cli/pull/18457) +- fix- windows: add shell: true for spawnSync to fix EINVAL with .cmd editors by + zackoch in [#18408](https://github.com/google-gemini/gemini-cli/pull/18408) +- bug(core): Fix bug when saving plans. by joshualitt in + [#18465](https://github.com/google-gemini/gemini-cli/pull/18465) +- Refactor atCommandProcessor by scidomino in + [#18461](https://github.com/google-gemini/gemini-cli/pull/18461) +- feat(core): implement persistence and resumption for masked tool outputs by + abhipatel12 in + [#18451](https://github.com/google-gemini/gemini-cli/pull/18451) +- refactor: simplify tool output truncation to single config by SandyTao520 in + [#18446](https://github.com/google-gemini/gemini-cli/pull/18446) +- bug(core): Ensure storage is initialized early, even if config is not. by + joshualitt in [#18471](https://github.com/google-gemini/gemini-cli/pull/18471) +- chore: Update build-and-start script to support argument forwarding by Abhijit-2592 in - [#17976](https://github.com/google-gemini/gemini-cli/pull/17976) -- fix(ide): no-op refactoring that moves the connection logic to helper - functions by skeshive in - [#18118](https://github.com/google-gemini/gemini-cli/pull/18118) -- feat: update review-frontend-and-fix slash command to review-and-fix by galz10 - in [#18146](https://github.com/google-gemini/gemini-cli/pull/18146) -- fix: improve Ctrl+R reverse search by jackwotherspoon in - [#18075](https://github.com/google-gemini/gemini-cli/pull/18075) -- feat(plan): handle inconsistency in schedulers by Adib234 in - [#17813](https://github.com/google-gemini/gemini-cli/pull/17813) -- feat(plan): add core logic and exit_plan_mode tool definition by jerop in - [#18110](https://github.com/google-gemini/gemini-cli/pull/18110) -- feat(core): rename search_file_content tool to grep_search and add legacy - alias by SandyTao520 in - [#18003](https://github.com/google-gemini/gemini-cli/pull/18003) -- fix(core): prioritize detailed error messages for code assist setup by - gsquared94 in [#17852](https://github.com/google-gemini/gemini-cli/pull/17852) -- fix(cli): resolve environment loading and auth validation issues in ACP mode - by bdmorgan in - [#18025](https://github.com/google-gemini/gemini-cli/pull/18025) -- feat(core): add .agents/skills directory alias for skill discovery by + [#18241](https://github.com/google-gemini/gemini-cli/pull/18241) +- fix(core): prevent subagent bypass in plan mode by jerop in + [#18484](https://github.com/google-gemini/gemini-cli/pull/18484) +- feat(cli): add WebSocket-based network logging and streaming chunk support by + SandyTao520 in + [#18383](https://github.com/google-gemini/gemini-cli/pull/18383) +- feat(cli): update approval modes UI by jerop in + [#18476](https://github.com/google-gemini/gemini-cli/pull/18476) +- fix(cli): reload skills and agents on extension restart by NTaylorMullen in + [#18411](https://github.com/google-gemini/gemini-cli/pull/18411) +- fix(core): expand excludeTools with legacy aliases for renamed tools by + SandyTao520 in + [#18498](https://github.com/google-gemini/gemini-cli/pull/18498) +- feat(core): overhaul system prompt for rigor, integrity, and intent alignment + by NTaylorMullen in + [#17263](https://github.com/google-gemini/gemini-cli/pull/17263) +- Patch for generate changelog docs yaml file by g-samroberts in + [#18496](https://github.com/google-gemini/gemini-cli/pull/18496) +- Code review fixes for show question mark pr. by jacob314 in + [#18480](https://github.com/google-gemini/gemini-cli/pull/18480) +- fix(cli): add SS3 Shift+Tab support for Windows terminals by ThanhNguyxn in + [#18187](https://github.com/google-gemini/gemini-cli/pull/18187) +- chore: remove redundant planning prompt from final shell by jerop in + [#18528](https://github.com/google-gemini/gemini-cli/pull/18528) +- docs: require pr-creator skill for PR generation by NTaylorMullen in + [#18536](https://github.com/google-gemini/gemini-cli/pull/18536) +- chore: update colors for ask_user dialog by jackwotherspoon in + [#18543](https://github.com/google-gemini/gemini-cli/pull/18543) +- feat(core): exempt high-signal tools from output masking by abhipatel12 in + [#18545](https://github.com/google-gemini/gemini-cli/pull/18545) +- refactor(core): remove memory tool instructions from Gemini 3 prompt by NTaylorMullen in - [#18151](https://github.com/google-gemini/gemini-cli/pull/18151) -- chore(core): reassign telemetry keys to avoid server conflict by mattKorwel in - [#18161](https://github.com/google-gemini/gemini-cli/pull/18161) -- Add link to rewind doc in commands.md by Adib234 in - [#17961](https://github.com/google-gemini/gemini-cli/pull/17961) -- feat(core): add draft-2020-12 JSON Schema support with lenient fallback by - afarber in [#15060](https://github.com/google-gemini/gemini-cli/pull/15060) -- refactor(core): robust trimPreservingTrailingNewline and regression test by + [#18559](https://github.com/google-gemini/gemini-cli/pull/18559) +- chore: remove feedback instruction from system prompt by NTaylorMullen in + [#18560](https://github.com/google-gemini/gemini-cli/pull/18560) +- feat(context): add remote configuration for tool output masking thresholds by + abhipatel12 in + [#18553](https://github.com/google-gemini/gemini-cli/pull/18553) +- feat(core): pause agent timeout budget while waiting for tool confirmation by + abhipatel12 in + [#18415](https://github.com/google-gemini/gemini-cli/pull/18415) +- refactor(config): remove experimental.enableEventDrivenScheduler setting by + abhipatel12 in + [#17924](https://github.com/google-gemini/gemini-cli/pull/17924) +- feat(cli): truncate shell output in UI history and improve active shell + display by jwhelangoog in + [#17438](https://github.com/google-gemini/gemini-cli/pull/17438) +- refactor(cli): switch useToolScheduler to event-driven engine by abhipatel12 + in [#18565](https://github.com/google-gemini/gemini-cli/pull/18565) +- fix(core): correct escaped interpolation in system prompt by NTaylorMullen in + [#18557](https://github.com/google-gemini/gemini-cli/pull/18557) +- propagate abortSignal by scidomino in + [#18477](https://github.com/google-gemini/gemini-cli/pull/18477) +- feat(core): conditionally include ctrl+f prompt based on interactive shell + setting by NTaylorMullen in + [#18561](https://github.com/google-gemini/gemini-cli/pull/18561) +- fix(core): ensure enter_plan_mode tool registration respects experimental.plan + by jerop in [#18587](https://github.com/google-gemini/gemini-cli/pull/18587) +- feat(core): transition sub-agents to XML format and improve definitions by + NTaylorMullen in + [#18555](https://github.com/google-gemini/gemini-cli/pull/18555) +- docs: Add Plan Mode documentation by jerop in + [#18582](https://github.com/google-gemini/gemini-cli/pull/18582) +- chore: strengthen validation guidance in system prompt by NTaylorMullen in + [#18544](https://github.com/google-gemini/gemini-cli/pull/18544) +- Fix newline insertion bug in replace tool by werdnum in + [#18595](https://github.com/google-gemini/gemini-cli/pull/18595) +- fix(evals): update save_memory evals and simplify tool description by + NTaylorMullen in + [#18610](https://github.com/google-gemini/gemini-cli/pull/18610) +- chore(evals): update validation_fidelity_pre_existing_errors to USUALLY_PASSES + by NTaylorMullen in + [#18617](https://github.com/google-gemini/gemini-cli/pull/18617) +- fix: shorten tool call IDs and fix duplicate tool name in truncated output + filenames by SandyTao520 in + [#18600](https://github.com/google-gemini/gemini-cli/pull/18600) +- feat(cli): implement atomic writes and safety checks for trusted folders by + galz10 in [#18406](https://github.com/google-gemini/gemini-cli/pull/18406) +- Remove relative docs links by chrstnb in + [#18650](https://github.com/google-gemini/gemini-cli/pull/18650) +- docs: add legacy snippets convention to GEMINI.md by NTaylorMullen in + [#18597](https://github.com/google-gemini/gemini-cli/pull/18597) +- fix(chore): Support linting for cjs by aswinashok44 in + [#18639](https://github.com/google-gemini/gemini-cli/pull/18639) +- feat: move shell efficiency guidelines to tool description by NTaylorMullen in + [#18614](https://github.com/google-gemini/gemini-cli/pull/18614) +- Added "" as default value, since getText() used to expect a string only and + thus crashed when undefined... Fixes #18076 by 019-Abhi in + [#18099](https://github.com/google-gemini/gemini-cli/pull/18099) +- Allow @-includes outside of workspaces (with permission) by scidomino in + [#18470](https://github.com/google-gemini/gemini-cli/pull/18470) +- chore: make ask_user header description more clear by jackwotherspoon in + [#18657](https://github.com/google-gemini/gemini-cli/pull/18657) +- refactor(core): model-dependent tool definitions by aishaneeshah in + [#18563](https://github.com/google-gemini/gemini-cli/pull/18563) +- Harded code assist converter. by jacob314 in + [#18656](https://github.com/google-gemini/gemini-cli/pull/18656) +- bug(core): Fix minor bug in migration logic. by joshualitt in + [#18661](https://github.com/google-gemini/gemini-cli/pull/18661) +- feat: enable plan mode experiment in settings by jerop in + [#18636](https://github.com/google-gemini/gemini-cli/pull/18636) +- refactor: push isValidPath() into parsePastedPaths() by scidomino in + [#18664](https://github.com/google-gemini/gemini-cli/pull/18664) +- fix(cli): correct 'esc to cancel' position and restore duration display by + NTaylorMullen in + [#18534](https://github.com/google-gemini/gemini-cli/pull/18534) +- feat(cli): add DevTools integration with gemini-cli-devtools by SandyTao520 in + [#18648](https://github.com/google-gemini/gemini-cli/pull/18648) +- chore: remove unused exports and redundant hook files by SandyTao520 in + [#18681](https://github.com/google-gemini/gemini-cli/pull/18681) +- Fix number of lines being reported in rewind confirmation dialog by Adib234 in + [#18675](https://github.com/google-gemini/gemini-cli/pull/18675) +- feat(cli): disable folder trust in headless mode by galz10 in + [#18407](https://github.com/google-gemini/gemini-cli/pull/18407) +- Disallow unsafe type assertions by gundermanc in + [#18688](https://github.com/google-gemini/gemini-cli/pull/18688) +- Change event type for release by g-samroberts in + [#18693](https://github.com/google-gemini/gemini-cli/pull/18693) +- feat: handle multiple dynamic context filenames in system prompt by + NTaylorMullen in + [#18598](https://github.com/google-gemini/gemini-cli/pull/18598) +- Properly parse at-commands with narrow non-breaking spaces by scidomino in + [#18677](https://github.com/google-gemini/gemini-cli/pull/18677) +- refactor(core): centralize core tool definitions and support model-specific + schemas by aishaneeshah in + [#18662](https://github.com/google-gemini/gemini-cli/pull/18662) +- feat(core): Render memory hierarchically in context. by joshualitt in + [#18350](https://github.com/google-gemini/gemini-cli/pull/18350) +- feat: Ctrl+O to expand paste placeholder by jackwotherspoon in + [#18103](https://github.com/google-gemini/gemini-cli/pull/18103) +- fix(cli): Improve header spacing by NTaylorMullen in + [#18531](https://github.com/google-gemini/gemini-cli/pull/18531) +- Feature/quota visibility 16795 by spencer426 in + [#18203](https://github.com/google-gemini/gemini-cli/pull/18203) +- Inline thinking bubbles with summary/full modes by LyalinDotCom in + [#18033](https://github.com/google-gemini/gemini-cli/pull/18033) +- docs: remove TOC marker from Plan Mode header by jerop in + [#18678](https://github.com/google-gemini/gemini-cli/pull/18678) +- fix(ui): remove redundant newlines in Gemini messages by NTaylorMullen in + [#18538](https://github.com/google-gemini/gemini-cli/pull/18538) +- test(cli): fix AppContainer act() warnings and improve waitFor resilience by + NTaylorMullen in + [#18676](https://github.com/google-gemini/gemini-cli/pull/18676) +- refactor(core): refine Security & System Integrity section in system prompt by + NTaylorMullen in + [#18601](https://github.com/google-gemini/gemini-cli/pull/18601) +- Fix layout rounding. by gundermanc in + [#18667](https://github.com/google-gemini/gemini-cli/pull/18667) +- docs(skills): enhance pr-creator safety and interactivity by NTaylorMullen in + [#18616](https://github.com/google-gemini/gemini-cli/pull/18616) +- test(core): remove hardcoded model from TestRig by NTaylorMullen in + [#18710](https://github.com/google-gemini/gemini-cli/pull/18710) +- feat(core): optimize sub-agents system prompt intro by NTaylorMullen in + [#18608](https://github.com/google-gemini/gemini-cli/pull/18608) +- feat(cli): update approval mode labels and shortcuts per latest UX spec by + jerop in [#18698](https://github.com/google-gemini/gemini-cli/pull/18698) +- fix(plan): update persistent approval mode setting by Adib234 in + [#18638](https://github.com/google-gemini/gemini-cli/pull/18638) +- fix: move toasts location to left side by jackwotherspoon in + [#18705](https://github.com/google-gemini/gemini-cli/pull/18705) +- feat(routing): restrict numerical routing to Gemini 3 family by mattKorwel in + [#18478](https://github.com/google-gemini/gemini-cli/pull/18478) +- fix(ide): fix ide nudge setting by skeshive in + [#18733](https://github.com/google-gemini/gemini-cli/pull/18733) +- fix(core): standardize tool formatting in system prompts by NTaylorMullen in + [#18615](https://github.com/google-gemini/gemini-cli/pull/18615) +- chore: consolidate to green in ask user dialog by jackwotherspoon in + [#18734](https://github.com/google-gemini/gemini-cli/pull/18734) +- feat: add extensionsExplore setting to enable extensions explore UI. by + sripasg in [#18686](https://github.com/google-gemini/gemini-cli/pull/18686) +- feat(cli): defer devtools startup and integrate with F12 by SandyTao520 in + [#18695](https://github.com/google-gemini/gemini-cli/pull/18695) +- ui: update & subdue footer colors and animate progress indicator by + keithguerin in + [#18570](https://github.com/google-gemini/gemini-cli/pull/18570) +- test: add model-specific snapshots for coreTools by aishaneeshah in + [#18707](https://github.com/google-gemini/gemini-cli/pull/18707) +- ci: shard windows tests and fix event listener leaks by NTaylorMullen in + [#18670](https://github.com/google-gemini/gemini-cli/pull/18670) +- fix: allow ask_user tool in yolo mode by jackwotherspoon in + [#18541](https://github.com/google-gemini/gemini-cli/pull/18541) +- feat: redact disabled tools from system prompt + ([#13597](https://github.com/google-gemini/gemini-cli/pull/13597)) by + NTaylorMullen in + [#18613](https://github.com/google-gemini/gemini-cli/pull/18613) +- Update Gemini.md to use the curent year on creating new files by sehoon38 in + [#18460](https://github.com/google-gemini/gemini-cli/pull/18460) +- Code review cleanup for thinking display by jacob314 in + [#18720](https://github.com/google-gemini/gemini-cli/pull/18720) +- fix(cli): hide scrollbars when in alternate buffer copy mode by werdnum in + [#18354](https://github.com/google-gemini/gemini-cli/pull/18354) +- Fix issues with rip grep by gundermanc in + [#18756](https://github.com/google-gemini/gemini-cli/pull/18756) +- fix(cli): fix history navigation regression after prompt autocomplete by + sehoon38 in [#18752](https://github.com/google-gemini/gemini-cli/pull/18752) +- chore: cleanup unused and add unlisted dependencies in packages/cli by adamfweidman in - [#18196](https://github.com/google-gemini/gemini-cli/pull/18196) -- Remove MCP servers on extension uninstall by chrstnb in - [#18121](https://github.com/google-gemini/gemini-cli/pull/18121) -- refactor: localize ACP error parsing logic to cli package by bdmorgan in - [#18193](https://github.com/google-gemini/gemini-cli/pull/18193) -- feat(core): Add A2A auth config types by adamfweidman in - [#18205](https://github.com/google-gemini/gemini-cli/pull/18205) -- Set default max attempts to 3 and use the common variable by sehoon38 in - [#18209](https://github.com/google-gemini/gemini-cli/pull/18209) -- feat(plan): add exit_plan_mode ui and prompt by jerop in - [#18162](https://github.com/google-gemini/gemini-cli/pull/18162) -- fix(test): improve test isolation and enable subagent evaluations by - cocosheng-g in - [#18138](https://github.com/google-gemini/gemini-cli/pull/18138) -- feat(plan): use custom deny messages in plan mode policies by Adib234 in - [#18195](https://github.com/google-gemini/gemini-cli/pull/18195) -- Match on extension ID when stopping extensions by chrstnb in - [#18218](https://github.com/google-gemini/gemini-cli/pull/18218) -- fix(core): Respect user's .gitignore preference by xyrolle in - [#15482](https://github.com/google-gemini/gemini-cli/pull/15482) -- docs: document GEMINI_CLI_HOME environment variable by adamfweidman in - [#18219](https://github.com/google-gemini/gemini-cli/pull/18219) -- chore(core): explicitly state plan storage path in prompt by jerop in - [#18222](https://github.com/google-gemini/gemini-cli/pull/18222) -- A2a admin setting by DavidAPierce in - [#17868](https://github.com/google-gemini/gemini-cli/pull/17868) -- feat(a2a): Add pluggable auth provider infrastructure by adamfweidman in - [#17934](https://github.com/google-gemini/gemini-cli/pull/17934) -- Fix handling of empty settings by chrstnb in - [#18131](https://github.com/google-gemini/gemini-cli/pull/18131) -- Reload skills when extensions change by chrstnb in - [#18225](https://github.com/google-gemini/gemini-cli/pull/18225) -- feat: Add markdown rendering to ask_user tool by jackwotherspoon in - [#18211](https://github.com/google-gemini/gemini-cli/pull/18211) -- Add telemetry to rewind by Adib234 in - [#18122](https://github.com/google-gemini/gemini-cli/pull/18122) -- feat(admin): add support for MCP configuration via admin controls (pt1) by - skeshive in [#18223](https://github.com/google-gemini/gemini-cli/pull/18223) -- feat(core): require user consent before MCP server OAuth by ehedlund in - [#18132](https://github.com/google-gemini/gemini-cli/pull/18132) -- fix(sandbox): propagate GOOGLE_GEMINI_BASE_URL&GOOGLE_VERTEX_BASE_URL env vars - by skeshive in - [#18231](https://github.com/google-gemini/gemini-cli/pull/18231) -- feat(ui): move user identity display to header by sehoon38 in - [#18216](https://github.com/google-gemini/gemini-cli/pull/18216) -- fix: enforce folder trust for workspace settings, skills, and context by - galz10 in [#17596](https://github.com/google-gemini/gemini-cli/pull/17596) + [#18749](https://github.com/google-gemini/gemini-cli/pull/18749) +- Fix issue where Gemini CLI creates tests in a new file by gundermanc in + [#18409](https://github.com/google-gemini/gemini-cli/pull/18409) +- feat(telemetry): Ensure experiment IDs are included in OpenTelemetry logs by + kevin-ramdass in + [#18747](https://github.com/google-gemini/gemini-cli/pull/18747) **Full changelog**: -https://github.com/google-gemini/gemini-cli/compare/v0.27.0-preview.8...v0.28.0-preview.0 +https://github.com/google-gemini/gemini-cli/compare/v0.28.0-preview.0...v0.29.0-preview.0 From 099aa9621c530885fd69687953f5b1fe4bf006df Mon Sep 17 00:00:00 2001 From: matt korwel Date: Wed, 11 Feb 2026 20:12:01 -0600 Subject: [PATCH 15/44] fix(core): ensure sub-agents are registered regardless of tools.allowed (#18870) --- packages/core/src/config/config.test.ts | 38 +++++++++++++++++++++++++ packages/core/src/config/config.ts | 24 +++++----------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index 886e722ba0..4a732bbedb 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -1036,6 +1036,44 @@ describe('Server Config (config.ts)', () => { expect(registeredWrappers).toHaveLength(1); }); + it('should register subagents as tools even when they are not in allowedTools', async () => { + const params: ConfigParameters = { + ...baseParams, + allowedTools: ['read_file'], // codebase-investigator is NOT here + agents: { + overrides: { + codebase_investigator: { enabled: true }, + }, + }, + }; + const config = new Config(params); + + const mockAgentDefinition = { + name: 'codebase-investigator', + description: 'Agent 1', + instructions: 'Inst 1', + }; + + const AgentRegistryMock = ( + (await vi.importMock('../agents/registry.js')) as { + AgentRegistry: Mock; + } + ).AgentRegistry; + AgentRegistryMock.prototype.getAllDefinitions.mockReturnValue([ + mockAgentDefinition, + ]); + + const SubAgentToolMock = ( + (await vi.importMock('../agents/subagent-tool.js')) as { + SubagentTool: Mock; + } + ).SubagentTool; + + await config.initialize(); + + expect(SubAgentToolMock).toHaveBeenCalled(); + }); + it('should not register subagents as tools when agents are disabled', async () => { const params: ConfigParameters = { ...baseParams, diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index db4085c1fa..944d14fb39 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -2469,26 +2469,16 @@ export class Config { agentsOverrides['codebase_investigator']?.enabled !== false || agentsOverrides['cli_help']?.enabled !== false ) { - const allowedTools = this.getAllowedTools(); const definitions = this.agentRegistry.getAllDefinitions(); for (const definition of definitions) { - const isAllowed = - !allowedTools || allowedTools.includes(definition.name); - - if (isAllowed) { - try { - const tool = new SubagentTool( - definition, - this, - this.getMessageBus(), - ); - registry.registerTool(tool); - } catch (e: unknown) { - debugLogger.warn( - `Failed to register tool for agent ${definition.name}: ${getErrorMessage(e)}`, - ); - } + try { + const tool = new SubagentTool(definition, this, this.getMessageBus()); + registry.registerTool(tool); + } catch (e: unknown) { + debugLogger.warn( + `Failed to register tool for agent ${definition.name}: ${getErrorMessage(e)}`, + ); } } } From 2ca183ffc9d2ab38b4835de1b657003963abe643 Mon Sep 17 00:00:00 2001 From: christine betts Date: Thu, 12 Feb 2026 11:29:06 -0500 Subject: [PATCH 16/44] Show notification when there's a conflict with an extensions command (#17890) --- packages/cli/src/gemini.tsx | 6 + .../cli/src/services/CommandService.test.ts | 113 ++++++++++++++ packages/cli/src/services/CommandService.ts | 59 ++++++- .../services/SlashCommandConflictHandler.ts | 54 +++++++ .../ui/hooks/slashCommandProcessor.test.tsx | 144 +++++++++++++++++- .../cli/src/ui/hooks/slashCommandProcessor.ts | 5 + packages/core/src/utils/events.ts | 18 +++ 7 files changed, 395 insertions(+), 4 deletions(-) create mode 100644 packages/cli/src/services/SlashCommandConflictHandler.ts diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index e138cfe03a..31e8bd433b 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -104,6 +104,7 @@ import { TerminalProvider } from './ui/contexts/TerminalContext.js'; import { setupTerminalAndTheme } from './utils/terminalTheme.js'; import { profiler } from './ui/components/DebugProfiler.js'; import { runDeferredCommand } from './deferred.js'; +import { SlashCommandConflictHandler } from './services/SlashCommandConflictHandler.js'; const SLOW_RENDER_MS = 200; @@ -335,6 +336,11 @@ export async function main() { }); setupUnhandledRejectionHandler(); + + const slashCommandConflictHandler = new SlashCommandConflictHandler(); + slashCommandConflictHandler.start(); + registerCleanup(() => slashCommandConflictHandler.stop()); + const loadSettingsHandle = startupProfiler.start('load_settings'); const settings = loadSettings(); loadSettingsHandle?.end(); diff --git a/packages/cli/src/services/CommandService.test.ts b/packages/cli/src/services/CommandService.test.ts index 31dfdcace8..ea906a3da6 100644 --- a/packages/cli/src/services/CommandService.test.ts +++ b/packages/cli/src/services/CommandService.test.ts @@ -350,4 +350,117 @@ describe('CommandService', () => { expect(deployExtension).toBeDefined(); expect(deployExtension?.description).toBe('[gcp] Deploy to Google Cloud'); }); + + it('should report conflicts via getConflicts', async () => { + const builtinCommand = createMockCommand('deploy', CommandKind.BUILT_IN); + const extensionCommand = { + ...createMockCommand('deploy', CommandKind.FILE), + extensionName: 'firebase', + }; + + const mockLoader = new MockCommandLoader([ + builtinCommand, + extensionCommand, + ]); + + const service = await CommandService.create( + [mockLoader], + new AbortController().signal, + ); + + const conflicts = service.getConflicts(); + expect(conflicts).toHaveLength(1); + + expect(conflicts[0]).toMatchObject({ + name: 'deploy', + winner: builtinCommand, + losers: [ + { + renamedTo: 'firebase.deploy', + command: expect.objectContaining({ + name: 'deploy', + extensionName: 'firebase', + }), + }, + ], + }); + }); + + it('should report extension vs extension conflicts correctly', async () => { + // Both extensions try to register 'deploy' + const extension1Command = { + ...createMockCommand('deploy', CommandKind.FILE), + extensionName: 'firebase', + }; + const extension2Command = { + ...createMockCommand('deploy', CommandKind.FILE), + extensionName: 'aws', + }; + + const mockLoader = new MockCommandLoader([ + extension1Command, + extension2Command, + ]); + + const service = await CommandService.create( + [mockLoader], + new AbortController().signal, + ); + + const conflicts = service.getConflicts(); + expect(conflicts).toHaveLength(1); + + expect(conflicts[0]).toMatchObject({ + name: 'deploy', + winner: expect.objectContaining({ + name: 'deploy', + extensionName: 'firebase', + }), + losers: [ + { + renamedTo: 'aws.deploy', // ext2 is 'aws' and it lost because it was second in the list + command: expect.objectContaining({ + name: 'deploy', + extensionName: 'aws', + }), + }, + ], + }); + }); + + it('should report multiple conflicts for the same command name', async () => { + const builtinCommand = createMockCommand('deploy', CommandKind.BUILT_IN); + const ext1 = { + ...createMockCommand('deploy', CommandKind.FILE), + extensionName: 'ext1', + }; + const ext2 = { + ...createMockCommand('deploy', CommandKind.FILE), + extensionName: 'ext2', + }; + + const mockLoader = new MockCommandLoader([builtinCommand, ext1, ext2]); + + const service = await CommandService.create( + [mockLoader], + new AbortController().signal, + ); + + const conflicts = service.getConflicts(); + expect(conflicts).toHaveLength(1); + expect(conflicts[0].name).toBe('deploy'); + expect(conflicts[0].losers).toHaveLength(2); + expect(conflicts[0].losers).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + renamedTo: 'ext1.deploy', + command: expect.objectContaining({ extensionName: 'ext1' }), + }), + expect.objectContaining({ + renamedTo: 'ext2.deploy', + command: expect.objectContaining({ extensionName: 'ext2' }), + }), + ]), + ); + }); }); diff --git a/packages/cli/src/services/CommandService.ts b/packages/cli/src/services/CommandService.ts index 0e29a81d00..bd42226a32 100644 --- a/packages/cli/src/services/CommandService.ts +++ b/packages/cli/src/services/CommandService.ts @@ -4,10 +4,19 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { debugLogger } from '@google/gemini-cli-core'; +import { debugLogger, coreEvents } from '@google/gemini-cli-core'; import type { SlashCommand } from '../ui/commands/types.js'; import type { ICommandLoader } from './types.js'; +export interface CommandConflict { + name: string; + winner: SlashCommand; + losers: Array<{ + command: SlashCommand; + renamedTo: string; + }>; +} + /** * Orchestrates the discovery and loading of all slash commands for the CLI. * @@ -23,8 +32,12 @@ export class CommandService { /** * Private constructor to enforce the use of the async factory. * @param commands A readonly array of the fully loaded and de-duplicated commands. + * @param conflicts A readonly array of conflicts that occurred during loading. */ - private constructor(private readonly commands: readonly SlashCommand[]) {} + private constructor( + private readonly commands: readonly SlashCommand[], + private readonly conflicts: readonly CommandConflict[], + ) {} /** * Asynchronously creates and initializes a new CommandService instance. @@ -63,11 +76,14 @@ export class CommandService { } const commandMap = new Map(); + const conflictsMap = new Map(); + for (const cmd of allCommands) { let finalName = cmd.name; // Extension commands get renamed if they conflict with existing commands if (cmd.extensionName && commandMap.has(cmd.name)) { + const winner = commandMap.get(cmd.name)!; let renamedName = `${cmd.extensionName}.${cmd.name}`; let suffix = 1; @@ -78,6 +94,19 @@ export class CommandService { } finalName = renamedName; + + if (!conflictsMap.has(cmd.name)) { + conflictsMap.set(cmd.name, { + name: cmd.name, + winner, + losers: [], + }); + } + + conflictsMap.get(cmd.name)!.losers.push({ + command: cmd, + renamedTo: finalName, + }); } commandMap.set(finalName, { @@ -86,8 +115,23 @@ export class CommandService { }); } + const conflicts = Array.from(conflictsMap.values()); + if (conflicts.length > 0) { + coreEvents.emitSlashCommandConflicts( + conflicts.flatMap((c) => + c.losers.map((l) => ({ + name: c.name, + renamedTo: l.renamedTo, + loserExtensionName: l.command.extensionName, + winnerExtensionName: c.winner.extensionName, + })), + ), + ); + } + const finalCommands = Object.freeze(Array.from(commandMap.values())); - return new CommandService(finalCommands); + const finalConflicts = Object.freeze(conflicts); + return new CommandService(finalCommands, finalConflicts); } /** @@ -101,4 +145,13 @@ export class CommandService { getCommands(): readonly SlashCommand[] { return this.commands; } + + /** + * Retrieves the list of conflicts that occurred during command loading. + * + * @returns A readonly array of command conflicts. + */ + getConflicts(): readonly CommandConflict[] { + return this.conflicts; + } } diff --git a/packages/cli/src/services/SlashCommandConflictHandler.ts b/packages/cli/src/services/SlashCommandConflictHandler.ts new file mode 100644 index 0000000000..31e110732b --- /dev/null +++ b/packages/cli/src/services/SlashCommandConflictHandler.ts @@ -0,0 +1,54 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + coreEvents, + CoreEvent, + type SlashCommandConflictsPayload, +} from '@google/gemini-cli-core'; + +export class SlashCommandConflictHandler { + private notifiedConflicts = new Set(); + + constructor() { + this.handleConflicts = this.handleConflicts.bind(this); + } + + start() { + coreEvents.on(CoreEvent.SlashCommandConflicts, this.handleConflicts); + } + + stop() { + coreEvents.off(CoreEvent.SlashCommandConflicts, this.handleConflicts); + } + + private handleConflicts(payload: SlashCommandConflictsPayload) { + const newConflicts = payload.conflicts.filter((c) => { + const key = `${c.name}:${c.loserExtensionName}`; + if (this.notifiedConflicts.has(key)) { + return false; + } + this.notifiedConflicts.add(key); + return true; + }); + + if (newConflicts.length > 0) { + const conflictMessages = newConflicts + .map((c) => { + const winnerSource = c.winnerExtensionName + ? `extension '${c.winnerExtensionName}'` + : 'an existing command'; + return `- Command '/${c.name}' from extension '${c.loserExtensionName}' was renamed to '/${c.renamedTo}' because it conflicts with ${winnerSource}.`; + }) + .join('\n'); + + coreEvents.emitFeedback( + 'info', + `Command conflicts detected:\n${conflictMessages}`, + ); + } + } +} diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.tsx b/packages/cli/src/ui/hooks/slashCommandProcessor.test.tsx index 049720d58a..11f47e12d3 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.tsx +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.tsx @@ -18,10 +18,13 @@ import { FileCommandLoader } from '../../services/FileCommandLoader.js'; import { McpPromptLoader } from '../../services/McpPromptLoader.js'; import { type GeminiClient, + type UserFeedbackPayload, SlashCommandStatus, makeFakeConfig, coreEvents, + CoreEvent, } from '@google/gemini-cli-core'; +import { SlashCommandConflictHandler } from '../../services/SlashCommandConflictHandler.js'; const { logSlashCommand, @@ -182,6 +185,26 @@ describe('useSlashCommandProcessor', () => { mockFileLoadCommands.mockResolvedValue(Object.freeze(fileCommands)); mockMcpLoadCommands.mockResolvedValue(Object.freeze(mcpCommands)); + const conflictHandler = new SlashCommandConflictHandler(); + conflictHandler.start(); + + const handleFeedback = (payload: UserFeedbackPayload) => { + let type = MessageType.INFO; + if (payload.severity === 'error') { + type = MessageType.ERROR; + } else if (payload.severity === 'warning') { + type = MessageType.WARNING; + } + mockAddItem( + { + type, + text: payload.message, + }, + Date.now(), + ); + }; + coreEvents.on(CoreEvent.UserFeedback, handleFeedback); + let result!: { current: ReturnType }; let unmount!: () => void; let rerender!: (props?: unknown) => void; @@ -228,7 +251,11 @@ describe('useSlashCommandProcessor', () => { rerender = hook.rerender; }); - unmountHook = async () => unmount(); + unmountHook = async () => { + conflictHandler.stop(); + coreEvents.off(CoreEvent.UserFeedback, handleFeedback); + unmount(); + }; await waitFor(() => { expect(result.current.slashCommands).toBeDefined(); @@ -1052,4 +1079,119 @@ describe('useSlashCommandProcessor', () => { expect(result.current.slashCommands).toEqual([newCommand]), ); }); + + describe('Conflict Notifications', () => { + it('should display a warning when a command conflict occurs', async () => { + const builtinCommand = createTestCommand({ name: 'deploy' }); + const extensionCommand = createTestCommand( + { + name: 'deploy', + extensionName: 'firebase', + }, + CommandKind.FILE, + ); + + const result = await setupProcessorHook({ + builtinCommands: [builtinCommand], + fileCommands: [extensionCommand], + }); + + await waitFor(() => expect(result.current.slashCommands).toHaveLength(2)); + + expect(mockAddItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.INFO, + text: expect.stringContaining('Command conflicts detected'), + }), + expect.any(Number), + ); + + expect(mockAddItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.INFO, + text: expect.stringContaining( + "- Command '/deploy' from extension 'firebase' was renamed", + ), + }), + expect.any(Number), + ); + }); + + it('should deduplicate conflict warnings across re-renders', async () => { + const builtinCommand = createTestCommand({ name: 'deploy' }); + const extensionCommand = createTestCommand( + { + name: 'deploy', + extensionName: 'firebase', + }, + CommandKind.FILE, + ); + + const result = await setupProcessorHook({ + builtinCommands: [builtinCommand], + fileCommands: [extensionCommand], + }); + + await waitFor(() => expect(result.current.slashCommands).toHaveLength(2)); + + // First notification + expect(mockAddItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.INFO, + text: expect.stringContaining('Command conflicts detected'), + }), + expect.any(Number), + ); + + mockAddItem.mockClear(); + + // Trigger a reload or re-render + await act(async () => { + result.current.commandContext.ui.reloadCommands(); + }); + + // Wait a bit for effect to run + await new Promise((resolve) => setTimeout(resolve, 100)); + + // Should NOT have notified again + expect(mockAddItem).not.toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.INFO, + text: expect.stringContaining('Command conflicts detected'), + }), + expect.any(Number), + ); + }); + + it('should correctly identify the winner extension in the message', async () => { + const ext1Command = createTestCommand( + { + name: 'deploy', + extensionName: 'firebase', + }, + CommandKind.FILE, + ); + const ext2Command = createTestCommand( + { + name: 'deploy', + extensionName: 'aws', + }, + CommandKind.FILE, + ); + + const result = await setupProcessorHook({ + fileCommands: [ext1Command, ext2Command], + }); + + await waitFor(() => expect(result.current.slashCommands).toHaveLength(2)); + + expect(mockAddItem).toHaveBeenCalledWith( + expect.objectContaining({ + type: MessageType.INFO, + text: expect.stringContaining("conflicts with extension 'firebase'"), + }), + expect.any(Number), + ); + }); + }); }); diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index 7289906a36..2c6c463e42 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -329,6 +329,11 @@ export const useSlashCommandProcessor = ( ], controller.signal, ); + + if (controller.signal.aborted) { + return; + } + setCommands(commandService.getCommands()); })(); diff --git a/packages/core/src/utils/events.ts b/packages/core/src/utils/events.ts index 5bd3c0f206..8784da07a2 100644 --- a/packages/core/src/utils/events.ts +++ b/packages/core/src/utils/events.ts @@ -127,6 +127,17 @@ export interface AgentsDiscoveredPayload { agents: AgentDefinition[]; } +export interface SlashCommandConflict { + name: string; + renamedTo: string; + loserExtensionName?: string; + winnerExtensionName?: string; +} + +export interface SlashCommandConflictsPayload { + conflicts: SlashCommandConflict[]; +} + /** * Payload for the 'quota-changed' event. */ @@ -155,6 +166,7 @@ export enum CoreEvent { AgentsDiscovered = 'agents-discovered', RequestEditorSelection = 'request-editor-selection', EditorSelected = 'editor-selected', + SlashCommandConflicts = 'slash-command-conflicts', QuotaChanged = 'quota-changed', } @@ -185,6 +197,7 @@ export interface CoreEvents extends ExtensionEvents { [CoreEvent.AgentsDiscovered]: [AgentsDiscoveredPayload]; [CoreEvent.RequestEditorSelection]: never[]; [CoreEvent.EditorSelected]: [EditorSelectedPayload]; + [CoreEvent.SlashCommandConflicts]: [SlashCommandConflictsPayload]; } type EventBacklogItem = { @@ -322,6 +335,11 @@ export class CoreEventEmitter extends EventEmitter { this._emitOrQueue(CoreEvent.AgentsDiscovered, payload); } + emitSlashCommandConflicts(conflicts: SlashCommandConflict[]): void { + const payload: SlashCommandConflictsPayload = { conflicts }; + this._emitOrQueue(CoreEvent.SlashCommandConflicts, payload); + } + /** * Notifies subscribers that the quota has changed. */ From f603f4a12b36b7835b3f2655d4b1be44ee739658 Mon Sep 17 00:00:00 2001 From: Dmitry Lyalin Date: Thu, 12 Feb 2026 11:35:40 -0500 Subject: [PATCH 17/44] fix(cli): dismiss '?' shortcuts help on hotkeys and active states (#18583) Co-authored-by: jacob314 --- docs/cli/keyboard-shortcuts.md | 7 +- packages/cli/src/ui/AppContainer.test.tsx | 125 +++++++++++++++++- packages/cli/src/ui/AppContainer.tsx | 36 +++++ .../cli/src/ui/components/Composer.test.tsx | 44 +++++- packages/cli/src/ui/components/Composer.tsx | 54 ++++++-- .../src/ui/components/InputPrompt.test.tsx | 12 ++ .../cli/src/ui/components/InputPrompt.tsx | 5 + packages/cli/src/ui/utils/shortcutsHelp.ts | 12 ++ 8 files changed, 280 insertions(+), 15 deletions(-) create mode 100644 packages/cli/src/ui/utils/shortcutsHelp.ts diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index d377cfd3e2..91baedc8c9 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -130,9 +130,10 @@ available combinations. terminal isn't configured to send Meta with Option. - `!` on an empty prompt: Enter or exit shell mode. - `?` on an empty prompt: Toggle the shortcuts panel above the input. Press - `Esc`, `Backspace`, or any printable key to close it. Press `?` again to close - the panel and insert a `?` into the prompt. You can hide only the hint text - via `ui.showShortcutsHint`, without changing this keyboard behavior. + `Esc`, `Backspace`, any printable key, or a registered app hotkey to close it. + The panel also auto-hides while the agent is running/streaming or when + action-required dialogs are shown. Press `?` again to close the panel and + insert a `?` into the prompt. - `\` (at end of a line) + `Enter`: Insert a newline without leaving single-line mode. - `Esc` pressed twice quickly: Clear the input prompt if it is not empty, diff --git a/packages/cli/src/ui/AppContainer.test.tsx b/packages/cli/src/ui/AppContainer.test.tsx index 0c333176e0..063315f8ac 100644 --- a/packages/cli/src/ui/AppContainer.test.tsx +++ b/packages/cli/src/ui/AppContainer.test.tsx @@ -197,7 +197,8 @@ 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 { useKeypress } from './hooks/useKeypress.js'; +import { useKeypress, type Key } from './hooks/useKeypress.js'; +import * as useKeypressModule from './hooks/useKeypress.js'; import { measureElement } from 'ink'; import { useTerminalSize } from './hooks/useTerminalSize.js'; import { @@ -2091,6 +2092,128 @@ describe('AppContainer State Management', () => { }); }); + describe('Shortcuts Help Visibility', () => { + let handleGlobalKeypress: (key: Key) => boolean; + let mockedUseKeypress: Mock; + let rerender: () => void; + let unmount: () => void; + + const setupShortcutsVisibilityTest = async () => { + const renderResult = renderAppContainer(); + await act(async () => { + vi.advanceTimersByTime(0); + }); + rerender = () => renderResult.rerender(getAppContainer()); + unmount = renderResult.unmount; + }; + + const pressKey = (key: Partial) => { + act(() => { + handleGlobalKeypress({ + name: 'r', + shift: false, + alt: false, + ctrl: false, + cmd: false, + insertable: false, + sequence: '', + ...key, + } as Key); + }); + rerender(); + }; + + beforeEach(() => { + mockedUseKeypress = vi.spyOn(useKeypressModule, 'useKeypress') as Mock; + mockedUseKeypress.mockImplementation( + (callback: (key: Key) => boolean, options: { isActive: boolean }) => { + // AppContainer registers multiple keypress handlers; capture only + // active handlers so inactive copy-mode handler doesn't override. + if (options?.isActive) { + handleGlobalKeypress = callback; + } + }, + ); + vi.useFakeTimers(); + }); + + afterEach(() => { + mockedUseKeypress.mockRestore(); + vi.useRealTimers(); + vi.restoreAllMocks(); + }); + + it('dismisses shortcuts help when a registered hotkey is pressed', async () => { + await setupShortcutsVisibilityTest(); + + act(() => { + capturedUIActions.setShortcutsHelpVisible(true); + }); + rerender(); + expect(capturedUIState.shortcutsHelpVisible).toBe(true); + + pressKey({ name: 'r', ctrl: true, sequence: '\x12' }); // Ctrl+R + expect(capturedUIState.shortcutsHelpVisible).toBe(false); + + unmount(); + }); + + it('dismisses shortcuts help when streaming starts', async () => { + await setupShortcutsVisibilityTest(); + + act(() => { + capturedUIActions.setShortcutsHelpVisible(true); + }); + rerender(); + expect(capturedUIState.shortcutsHelpVisible).toBe(true); + + mockedUseGeminiStream.mockReturnValue({ + ...DEFAULT_GEMINI_STREAM_MOCK, + streamingState: 'responding', + }); + + await act(async () => { + rerender(); + }); + await waitFor(() => { + expect(capturedUIState.shortcutsHelpVisible).toBe(false); + }); + + unmount(); + }); + + it('dismisses shortcuts help when action-required confirmation appears', async () => { + await setupShortcutsVisibilityTest(); + + act(() => { + capturedUIActions.setShortcutsHelpVisible(true); + }); + rerender(); + expect(capturedUIState.shortcutsHelpVisible).toBe(true); + + mockedUseSlashCommandProcessor.mockReturnValue({ + handleSlashCommand: vi.fn(), + slashCommands: [], + pendingHistoryItems: [], + commandContext: {}, + shellConfirmationRequest: null, + confirmationRequest: { + prompt: 'Confirm this action?', + onConfirm: vi.fn(), + }, + }); + + await act(async () => { + rerender(); + }); + await waitFor(() => { + expect(capturedUIState.shortcutsHelpVisible).toBe(false); + }); + + unmount(); + }); + }); + describe('Copy Mode (CTRL+S)', () => { let rerender: () => void; let unmount: () => void; diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index 72fdb0ce48..7489d07e2a 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -147,6 +147,7 @@ import { isSlashCommand } from './utils/commandUtils.js'; import { useTerminalTheme } from './hooks/useTerminalTheme.js'; import { useTimedMessage } from './hooks/useTimedMessage.js'; import { isITerm2 } from './utils/terminalUtils.js'; +import { shouldDismissShortcutsHelpOnHotkey } from './utils/shortcutsHelp.js'; function isToolExecuting(pendingHistoryItems: HistoryItemWithoutId[]) { return pendingHistoryItems.some((item) => { @@ -1489,6 +1490,10 @@ Logging in with Google... Restarting Gemini CLI to continue. debugLogger.log('[DEBUG] Keystroke:', JSON.stringify(key)); } + if (shortcutsHelpVisible && shouldDismissShortcutsHelpOnHotkey(key)) { + setShortcutsHelpVisible(false); + } + if (isAlternateBuffer && keyMatchers[Command.TOGGLE_COPY_MODE](key)) { setCopyModeEnabled(true); disableMouseEvents(); @@ -1652,6 +1657,7 @@ Logging in with Google... Restarting Gemini CLI to continue. refreshStatic, setCopyModeEnabled, isAlternateBuffer, + shortcutsHelpVisible, backgroundCurrentShell, toggleBackgroundShell, backgroundShells, @@ -1811,6 +1817,36 @@ Logging in with Google... Restarting Gemini CLI to continue. [pendingSlashCommandHistoryItems, pendingGeminiHistoryItems], ); + const hasPendingToolConfirmation = useMemo( + () => isToolAwaitingConfirmation(pendingHistoryItems), + [pendingHistoryItems], + ); + + const hasPendingActionRequired = + hasPendingToolConfirmation || + !!commandConfirmationRequest || + !!authConsentRequest || + confirmUpdateExtensionRequests.length > 0 || + !!loopDetectionConfirmationRequest || + !!proQuotaRequest || + !!validationRequest || + !!customDialog; + + const isPassiveShortcutsHelpState = + isInputActive && + streamingState === StreamingState.Idle && + !hasPendingActionRequired; + + useEffect(() => { + if (shortcutsHelpVisible && !isPassiveShortcutsHelpState) { + setShortcutsHelpVisible(false); + } + }, [ + shortcutsHelpVisible, + isPassiveShortcutsHelpState, + setShortcutsHelpVisible, + ]); + const allToolCalls = useMemo( () => pendingHistoryItems diff --git a/packages/cli/src/ui/components/Composer.test.tsx b/packages/cli/src/ui/components/Composer.test.tsx index ee3a441c04..1a25d2bb56 100644 --- a/packages/cli/src/ui/components/Composer.test.tsx +++ b/packages/cli/src/ui/components/Composer.test.tsx @@ -189,6 +189,7 @@ const createMockUIActions = (): UIActions => setShellModeActive: vi.fn(), onEscapePromptChange: vi.fn(), vimHandleInput: vi.fn(), + setShortcutsHelpVisible: vi.fn(), }) as Partial as UIActions; const createMockConfig = (overrides = {}): Config => @@ -337,7 +338,7 @@ describe('Composer', () => { expect(output).toContain('LoadingIndicator: Thinking ...'); }); - it('keeps shortcuts hint visible while loading', () => { + it('hides shortcuts hint while loading', () => { const uiState = createMockUIState({ streamingState: StreamingState.Responding, elapsedTime: 1, @@ -347,7 +348,7 @@ describe('Composer', () => { const output = lastFrame(); expect(output).toContain('LoadingIndicator'); - expect(output).toContain('ShortcutsHint'); + expect(output).not.toContain('ShortcutsHint'); }); it('renders LoadingIndicator without thought when accessibility disables loading phrases', () => { @@ -686,4 +687,43 @@ describe('Composer', () => { expect(lastFrame()).toContain('ShortcutsHint'); }); }); + + describe('Shortcuts Help', () => { + it('shows shortcuts help in passive state', () => { + const uiState = createMockUIState({ + shortcutsHelpVisible: true, + streamingState: StreamingState.Idle, + }); + + const { lastFrame } = renderComposer(uiState); + + expect(lastFrame()).toContain('ShortcutsHelp'); + }); + + it('hides shortcuts help while streaming', () => { + const uiState = createMockUIState({ + shortcutsHelpVisible: true, + streamingState: StreamingState.Responding, + }); + + const { lastFrame } = renderComposer(uiState); + + expect(lastFrame()).not.toContain('ShortcutsHelp'); + }); + + it('hides shortcuts help when action is required', () => { + const uiState = createMockUIState({ + shortcutsHelpVisible: true, + customDialog: ( + + Dialog content + + ), + }); + + const { lastFrame } = renderComposer(uiState); + + expect(lastFrame()).not.toContain('ShortcutsHelp'); + }); + }); }); diff --git a/packages/cli/src/ui/components/Composer.tsx b/packages/cli/src/ui/components/Composer.tsx index e87e86e801..b5b88b4e15 100644 --- a/packages/cli/src/ui/components/Composer.tsx +++ b/packages/cli/src/ui/components/Composer.tsx @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { useState } from 'react'; +import { useState, useEffect, useMemo } from 'react'; import { Box, useIsScreenReaderEnabled } from 'ink'; import { LoadingIndicator } from './LoadingIndicator.js'; import { StatusDisplay } from './StatusDisplay.js'; @@ -28,7 +28,11 @@ import { useVimMode } from '../contexts/VimModeContext.js'; import { useConfig } from '../contexts/ConfigContext.js'; import { useSettings } from '../contexts/SettingsContext.js'; import { useAlternateBuffer } from '../hooks/useAlternateBuffer.js'; -import { StreamingState, ToolCallStatus } from '../types.js'; +import { + StreamingState, + type HistoryItemToolGroup, + ToolCallStatus, +} from '../types.js'; import { ConfigInitDisplay } from '../components/ConfigInitDisplay.js'; import { TodoTray } from './messages/Todo.js'; import { getInlineThinkingMode } from '../utils/inlineThinkingMode.js'; @@ -51,11 +55,19 @@ export const Composer = ({ isFocused = true }: { isFocused?: boolean }) => { const suggestionsPosition = isAlternateBuffer ? 'above' : 'below'; const hideContextSummary = suggestionsVisible && suggestionsPosition === 'above'; - const hasPendingToolConfirmation = (uiState.pendingHistoryItems ?? []).some( - (item) => - item.type === 'tool_group' && - item.tools.some((tool) => tool.status === ToolCallStatus.Confirming), + + const hasPendingToolConfirmation = useMemo( + () => + (uiState.pendingHistoryItems ?? []) + .filter( + (item): item is HistoryItemToolGroup => item.type === 'tool_group', + ) + .some((item) => + item.tools.some((tool) => tool.status === ToolCallStatus.Confirming), + ), + [uiState.pendingHistoryItems], ); + const hasPendingActionRequired = hasPendingToolConfirmation || Boolean(uiState.commandConfirmationRequest) || @@ -65,6 +77,31 @@ export const Composer = ({ isFocused = true }: { isFocused?: boolean }) => { Boolean(uiState.quota.proQuotaRequest) || Boolean(uiState.quota.validationRequest) || Boolean(uiState.customDialog); + const isPassiveShortcutsHelpState = + uiState.isInputActive && + uiState.streamingState === StreamingState.Idle && + !hasPendingActionRequired; + + const { setShortcutsHelpVisible } = uiActions; + + useEffect(() => { + if (uiState.shortcutsHelpVisible && !isPassiveShortcutsHelpState) { + setShortcutsHelpVisible(false); + } + }, [ + uiState.shortcutsHelpVisible, + isPassiveShortcutsHelpState, + setShortcutsHelpVisible, + ]); + + const showShortcutsHelp = + uiState.shortcutsHelpVisible && + uiState.streamingState === StreamingState.Idle && + !hasPendingActionRequired; + const showShortcutsHint = + settings.merged.ui.showShortcutsHint && + uiState.streamingState === StreamingState.Idle && + !hasPendingActionRequired; const hasToast = shouldShowToast(uiState); const showLoadingIndicator = (!uiState.embeddedShellFocused || uiState.isBackgroundShellVisible) && @@ -133,11 +170,10 @@ export const Composer = ({ isFocused = true }: { isFocused?: boolean }) => { flexDirection="column" alignItems={isNarrow ? 'flex-start' : 'flex-end'} > - {settings.merged.ui.showShortcutsHint && - !hasPendingActionRequired && } + {showShortcutsHint && } - {uiState.shortcutsHelpVisible && } + {showShortcutsHelp && } { vi.mocked(clipboardy.read).mockResolvedValue('clipboard text'); }, }, + { + name: 'Ctrl+R hotkey is pressed', + input: '\x12', + }, + { + name: 'Ctrl+X hotkey is pressed', + input: '\x18', + }, + { + name: 'F12 hotkey is pressed', + input: '\x1b[24~', + }, ])( 'should close shortcuts help when a $name', async ({ input, setupMocks, mouseEventsEnabled }) => { diff --git a/packages/cli/src/ui/components/InputPrompt.tsx b/packages/cli/src/ui/components/InputPrompt.tsx index f2f23f5506..22fd317c10 100644 --- a/packages/cli/src/ui/components/InputPrompt.tsx +++ b/packages/cli/src/ui/components/InputPrompt.tsx @@ -75,6 +75,7 @@ import { useMouseClick } from '../hooks/useMouseClick.js'; import { useMouse, type MouseEvent } from '../contexts/MouseContext.js'; import { useUIActions } from '../contexts/UIActionsContext.js'; import { useAlternateBuffer } from '../hooks/useAlternateBuffer.js'; +import { shouldDismissShortcutsHelpOnHotkey } from '../utils/shortcutsHelp.js'; /** * Returns if the terminal can be trusted to handle paste events atomically @@ -661,6 +662,10 @@ export const InputPrompt: React.FC = ({ return true; } + if (shortcutsHelpVisible && shouldDismissShortcutsHelpOnHotkey(key)) { + setShortcutsHelpVisible(false); + } + if (shortcutsHelpVisible) { if (key.sequence === '?' && key.insertable) { setShortcutsHelpVisible(false); diff --git a/packages/cli/src/ui/utils/shortcutsHelp.ts b/packages/cli/src/ui/utils/shortcutsHelp.ts new file mode 100644 index 0000000000..65ab8f2a13 --- /dev/null +++ b/packages/cli/src/ui/utils/shortcutsHelp.ts @@ -0,0 +1,12 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Command, keyMatchers } from '../keyMatchers.js'; +import type { Key } from '../hooks/useKeypress.js'; + +export function shouldDismissShortcutsHelpOnHotkey(key: Key): boolean { + return Object.values(Command).some((command) => keyMatchers[command](key)); +} From ddcfe5b1f2de77c708b5b4c1c3b3cb6d88740abe Mon Sep 17 00:00:00 2001 From: Abhijit Balaji Date: Thu, 12 Feb 2026 09:04:39 -0800 Subject: [PATCH 18/44] fix(core): prioritize conditional policy rules and harden Plan Mode (#18882) --- .../core/src/policy/policy-engine.test.ts | 113 ++++++++++++++++-- packages/core/src/policy/policy-engine.ts | 4 +- 2 files changed, 108 insertions(+), 9 deletions(-) diff --git a/packages/core/src/policy/policy-engine.test.ts b/packages/core/src/policy/policy-engine.test.ts index 26aecaa1eb..693ae3a4b2 100644 --- a/packages/core/src/policy/policy-engine.test.ts +++ b/packages/core/src/policy/policy-engine.test.ts @@ -2046,33 +2046,91 @@ describe('PolicyEngine', () => { rules: [], expected: [], }, + { + name: 'should apply rules without explicit modes to all modes', + rules: [{ toolName: 'tool1', decision: PolicyDecision.DENY }], + expected: ['tool1'], + }, + { + name: 'should NOT exclude tool if higher priority argsPattern rule exists', + rules: [ + { + toolName: 'tool1', + decision: PolicyDecision.ALLOW, + argsPattern: /safe/, + priority: 100, + modes: [ApprovalMode.DEFAULT], + }, + { + toolName: 'tool1', + decision: PolicyDecision.DENY, + priority: 10, + modes: [ApprovalMode.DEFAULT], + }, + ], + expected: [], + }, { name: 'should include tools with DENY decision', rules: [ - { toolName: 'tool1', decision: PolicyDecision.DENY }, - { toolName: 'tool2', decision: PolicyDecision.ALLOW }, + { + toolName: 'tool1', + decision: PolicyDecision.DENY, + modes: [ApprovalMode.DEFAULT], + }, + { + toolName: 'tool2', + decision: PolicyDecision.ALLOW, + modes: [ApprovalMode.DEFAULT], + }, ], expected: ['tool1'], }, { name: 'should respect priority and ignore lower priority rules (DENY wins)', rules: [ - { toolName: 'tool1', decision: PolicyDecision.DENY, priority: 100 }, - { toolName: 'tool1', decision: PolicyDecision.ALLOW, priority: 10 }, + { + toolName: 'tool1', + decision: PolicyDecision.DENY, + priority: 100, + modes: [ApprovalMode.DEFAULT], + }, + { + toolName: 'tool1', + decision: PolicyDecision.ALLOW, + priority: 10, + modes: [ApprovalMode.DEFAULT], + }, ], expected: ['tool1'], }, { name: 'should respect priority and ignore lower priority rules (ALLOW wins)', rules: [ - { toolName: 'tool1', decision: PolicyDecision.ALLOW, priority: 100 }, - { toolName: 'tool1', decision: PolicyDecision.DENY, priority: 10 }, + { + toolName: 'tool1', + decision: PolicyDecision.ALLOW, + priority: 100, + modes: [ApprovalMode.DEFAULT], + }, + { + toolName: 'tool1', + decision: PolicyDecision.DENY, + priority: 10, + modes: [ApprovalMode.DEFAULT], + }, ], expected: [], }, { name: 'should NOT include ASK_USER tools even in non-interactive mode', - rules: [{ toolName: 'tool1', decision: PolicyDecision.ASK_USER }], + rules: [ + { + toolName: 'tool1', + decision: PolicyDecision.ASK_USER, + modes: [ApprovalMode.DEFAULT], + }, + ], nonInteractive: true, expected: [], }, @@ -2083,6 +2141,7 @@ describe('PolicyEngine', () => { toolName: 'tool1', decision: PolicyDecision.DENY, argsPattern: /something/, + modes: [ApprovalMode.DEFAULT], }, ], expected: [], @@ -2123,6 +2182,7 @@ describe('PolicyEngine', () => { toolName: 'dangerous-tool', decision: PolicyDecision.DENY, priority: 10, + modes: [ApprovalMode.YOLO], }, ], approvalMode: ApprovalMode.YOLO, @@ -2130,7 +2190,13 @@ describe('PolicyEngine', () => { }, { name: 'should respect server wildcard DENY', - rules: [{ toolName: 'server__*', decision: PolicyDecision.DENY }], + rules: [ + { + toolName: 'server__*', + decision: PolicyDecision.DENY, + modes: [ApprovalMode.DEFAULT], + }, + ], expected: ['server__*'], }, { @@ -2140,15 +2206,44 @@ describe('PolicyEngine', () => { toolName: 'server__*', decision: PolicyDecision.DENY, priority: 100, + modes: [ApprovalMode.DEFAULT], }, { toolName: 'server__tool1', decision: PolicyDecision.DENY, priority: 10, + modes: [ApprovalMode.DEFAULT], }, ], expected: ['server__*', 'server__tool1'], }, + { + name: 'should exclude run_shell_command but NOT write_file in simulated Plan Mode', + approvalMode: ApprovalMode.PLAN, + rules: [ + { + // Simulates the high-priority allow for plans directory + toolName: 'write_file', + decision: PolicyDecision.ALLOW, + priority: 70, + argsPattern: /plans/, + modes: [ApprovalMode.PLAN], + }, + { + // Simulates the global deny in Plan Mode + decision: PolicyDecision.DENY, + priority: 60, + modes: [ApprovalMode.PLAN], + }, + { + // Simulates a tool from another policy (e.g. write.toml) + toolName: 'run_shell_command', + decision: PolicyDecision.ASK_USER, + priority: 10, + }, + ], + expected: ['run_shell_command'], + }, { name: 'should NOT exclude tool if covered by a higher priority wildcard ALLOW', rules: [ @@ -2156,11 +2251,13 @@ describe('PolicyEngine', () => { toolName: 'server__*', decision: PolicyDecision.ALLOW, priority: 100, + modes: [ApprovalMode.DEFAULT], }, { toolName: 'server__tool1', decision: PolicyDecision.DENY, priority: 10, + modes: [ApprovalMode.DEFAULT], }, ], expected: [], diff --git a/packages/core/src/policy/policy-engine.ts b/packages/core/src/policy/policy-engine.ts index 1fc5e7cde5..3f386edd8f 100644 --- a/packages/core/src/policy/policy-engine.ts +++ b/packages/core/src/policy/policy-engine.ts @@ -538,8 +538,10 @@ export class PolicyEngine { let globalVerdict: PolicyDecision | undefined; for (const rule of this.rules) { - // We only care about rules without args pattern for exclusion from the model if (rule.argsPattern) { + if (rule.toolName && rule.decision !== PolicyDecision.DENY) { + processedTools.add(rule.toolName); + } continue; } From 27a1bae03bc50657475bc0a31c6407a4a13a610a Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 12 Feb 2026 09:37:47 -0800 Subject: [PATCH 19/44] feat(core): refine Plan Mode system prompt for agentic execution (#18799) --- .../core/__snapshots__/prompts.test.ts.snap | 136 ++++++++--------- packages/core/src/core/prompts.test.ts | 2 +- packages/core/src/prompts/promptProvider.ts | 4 +- packages/core/src/prompts/snippets.ts | 138 ++++++++---------- 4 files changed, 125 insertions(+), 155 deletions(-) diff --git a/packages/core/src/core/__snapshots__/prompts.test.ts.snap b/packages/core/src/core/__snapshots__/prompts.test.ts.snap index e944565366..ed79a3a497 100644 --- a/packages/core/src/core/__snapshots__/prompts.test.ts.snap +++ b/packages/core/src/core/__snapshots__/prompts.test.ts.snap @@ -42,8 +42,8 @@ You are operating in **Plan Mode** - a structured planning workflow for designin ## Available Tools The following read-only tools are available in Plan Mode: -- \`glob\` -- \`grep_search\` + \`glob\` + \`grep_search\` - \`write_file\` - Save plans to the plans directory (see Plan Storage below) - \`replace\` - Update plans in the plans directory @@ -173,8 +173,8 @@ You are operating in **Plan Mode** - a structured planning workflow for designin ## Available Tools The following read-only tools are available in Plan Mode: -- \`glob\` -- \`grep_search\` + \`glob\` + \`grep_search\` - \`write_file\` - Save plans to the plans directory (see Plan Storage below) - \`replace\` - Update plans in the plans directory @@ -421,8 +421,8 @@ You are operating in **Plan Mode** - a structured planning workflow for designin ## Available Tools The following read-only tools are available in Plan Mode: -- \`glob\` -- \`grep_search\` + \`glob\` + \`grep_search\` - \`write_file\` - Save plans to the plans directory (see Plan Storage below) - \`replace\` - Update plans in the plans directory @@ -580,7 +580,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype. +2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user and obtain their approval before proceeding. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns). - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -588,10 +588,9 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. +4. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** +5. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. # Operational Guidelines @@ -695,7 +694,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets, describe the strategy for sourcing or generating placeholders. +2. **Plan:** Formulate an internal development plan. For applications requiring visual assets, describe the strategy for sourcing or generating placeholders. - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested. - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -703,7 +702,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. Implementation: Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\`. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons). Never link to external services or assume local paths for assets that have not been created. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\`. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons). Never link to external services or assume local paths for assets that have not been created. 4. **Verify:** Review work against the original request. Fix bugs and deviations. **Build the application and ensure there are no compile errors.** # Operational Guidelines @@ -791,7 +790,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets, describe the strategy for sourcing or generating placeholders. +2. **Plan:** Formulate an internal development plan. For applications requiring visual assets, describe the strategy for sourcing or generating placeholders. - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested. - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -799,7 +798,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. Implementation: Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\`. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons). Never link to external services or assume local paths for assets that have not been created. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\`. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons). Never link to external services or assume local paths for assets that have not been created. 4. **Verify:** Review work against the original request. Fix bugs and deviations. **Build the application and ensure there are no compile errors.** # Operational Guidelines @@ -1385,7 +1384,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype. +2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user and obtain their approval before proceeding. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns). - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -1393,10 +1392,9 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. +4. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** +5. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. # Operational Guidelines @@ -1499,7 +1497,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype. +2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user and obtain their approval before proceeding. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns). - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -1507,10 +1505,9 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. +4. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** +5. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. # Operational Guidelines @@ -1617,7 +1614,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype. +2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user and obtain their approval before proceeding. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns). - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -1625,10 +1622,9 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. +4. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** +5. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. # Operational Guidelines @@ -1735,7 +1731,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype. +2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user and obtain their approval before proceeding. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns). - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -1743,10 +1739,9 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. +4. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** +5. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. # Operational Guidelines @@ -1835,7 +1830,7 @@ For example: ## Development Lifecycle Operate using a **Research -> Strategy -> Execution** lifecycle. For the Execution phase, resolve each sub-task through an iterative **Plan -> Act -> Validate** cycle. -1. **Research:** Systematically map the codebase and validate assumptions. Use search tools extensively to understand file structures, existing code patterns, and conventions. Use \`read_file\` to validate all assumptions. **Prioritize empirical reproduction of reported issues to confirm the failure state.** For complex tasks, consider using the \`enter_plan_mode\` tool to enter a dedicated planning phase before starting implementation. +1. **Research:** Systematically map the codebase and validate assumptions. Use search tools extensively to understand file structures, existing code patterns, and conventions. Use \`read_file\` to validate all assumptions. **Prioritize empirical reproduction of reported issues to confirm the failure state.** If the request is ambiguous, broad in scope, or involves creating a new feature/application, you MUST use the \`enter_plan_mode\` tool to design your approach before making changes. Do NOT use Plan Mode for straightforward bug fixes, answering questions, or simple inquiries. 2. **Strategy:** Formulate a grounded plan based on your research. Share a concise summary of your strategy. 3. **Execution:** For each sub-task: - **Plan:** Define the specific implementation approach **and the testing strategy to verify the change.** @@ -1848,19 +1843,17 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. -1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype. For complex tasks, consider using the \`enter_plan_mode\` tool to enter a dedicated planning phase before starting implementation. - - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - - **Default Tech Stack:** - - **Web:** React (TypeScript) or Angular with Vanilla CSS. - - **APIs:** Node.js (Express) or Python (FastAPI). - - **Mobile:** Compose Multiplatform or Flutter. - - **Games:** HTML/CSS/JS (Three.js for 3D). - - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. +1. **Mandatory Planning:** You MUST use the \`enter_plan_mode\` tool to draft a comprehensive design document and obtain user approval before writing any code. +2. **Design Constraints:** When drafting your plan, adhere to these defaults unless explicitly overridden by the user: + - **Goal:** Autonomously design a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, typography, and interactive feedback. + - **Visuals:** Describe your strategy for sourcing or generating placeholders (e.g., stylized CSS shapes, gradients, procedurally generated patterns) to ensure a visually complete prototype. Never plan for assets that cannot be locally generated. + - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested. + - **Web:** React (TypeScript) or Angular with Vanilla CSS. + - **APIs:** Node.js (Express) or Python (FastAPI). + - **Mobile:** Compose Multiplatform or Flutter. + - **Games:** HTML/CSS/JS (Three.js for 3D). + - **CLIs:** Python or Go. +3. **Implementation:** Once the plan is approved, follow the standard **Execution** cycle to build the application, utilizing platform-native primitives to realize the rich aesthetic you planned. # Operational Guidelines @@ -1963,7 +1956,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype. +2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user and obtain their approval before proceeding. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns). - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -1971,10 +1964,9 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. +4. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** +5. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. # Operational Guidelines @@ -2316,7 +2308,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype. +2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user and obtain their approval before proceeding. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns). - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -2324,10 +2316,9 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. +4. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** +5. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. # Operational Guidelines @@ -2430,7 +2421,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype. +2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user and obtain their approval before proceeding. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns). - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -2438,10 +2429,9 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. +4. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** +5. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. # Operational Guidelines @@ -2655,7 +2645,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype. +2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user and obtain their approval before proceeding. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns). - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -2663,10 +2653,9 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. +4. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** +5. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. # Operational Guidelines @@ -2769,7 +2758,7 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi **Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, interactive feedback, and platform-appropriate design. 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype. +2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user and obtain their approval before proceeding. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns). - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -2777,10 +2766,9 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using \`run_shell_command\` for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. +4. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** +5. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype. # Operational Guidelines diff --git a/packages/core/src/core/prompts.test.ts b/packages/core/src/core/prompts.test.ts index 8f2739c389..54f8250fc7 100644 --- a/packages/core/src/core/prompts.test.ts +++ b/packages/core/src/core/prompts.test.ts @@ -612,7 +612,7 @@ describe('Core System Prompt (prompts.ts)', () => { const prompt = getCoreSystemPrompt(mockConfig); expect(prompt).toContain( - 'For complex tasks, consider using the `enter_plan_mode` tool to enter a dedicated planning phase before starting implementation.', + 'If the request is ambiguous, broad in scope, or involves creating a new feature/application, you MUST use the `enter_plan_mode` tool to design your approach before making changes. Do NOT use Plan Mode for straightforward bug fixes, answering questions, or simple inquiries.', ); expect(prompt).toMatchSnapshot(); }); diff --git a/packages/core/src/prompts/promptProvider.ts b/packages/core/src/prompts/promptProvider.ts index 47f7e936cf..51224555cf 100644 --- a/packages/core/src/prompts/promptProvider.ts +++ b/packages/core/src/prompts/promptProvider.ts @@ -67,7 +67,7 @@ export class PromptProvider { let planModeToolsList = PLAN_MODE_TOOLS.filter((t) => enabledToolNames.has(t), ) - .map((t) => `- \`${t}\``) + .map((t) => ` \`${t}\``) .join('\n'); // Add read-only MCP tools to the list @@ -79,7 +79,7 @@ export class PromptProvider { ); if (readOnlyMcpTools.length > 0) { const mcpToolsList = readOnlyMcpTools - .map((t) => `- \`${t.name}\` (${t.serverName})`) + .map((t) => ` \`${t.name}\` (${t.serverName})`) .join('\n'); planModeToolsList += `\n${mcpToolsList}`; } diff --git a/packages/core/src/prompts/snippets.ts b/packages/core/src/prompts/snippets.ts index 3dcf346de6..bd062373df 100644 --- a/packages/core/src/prompts/snippets.ts +++ b/packages/core/src/prompts/snippets.ts @@ -419,78 +419,48 @@ export function renderPlanningWorkflow( return ` # Active Approval Mode: Plan -You are operating in **Plan Mode** - a structured planning workflow for designing implementation strategies before execution. +You are operating in **Plan Mode**. Your goal is to produce a detailed implementation plan in \`${options.plansDir}/\` and get user approval before editing source code. ## Available Tools The following read-only tools are available in Plan Mode: + ${options.planModeToolsList} -- ${formatToolName(WRITE_FILE_TOOL_NAME)} - Save plans to the plans directory (see Plan Storage below) -- ${formatToolName(EDIT_TOOL_NAME)} - Update plans in the plans directory + ${formatToolName(WRITE_FILE_TOOL_NAME)} - Save plans to the plans directory + ${formatToolName(EDIT_TOOL_NAME)} - Update plans in the plans directory + -## Plan Storage -- Save your plans as Markdown (.md) files ONLY within: \`${options.plansDir}/\` -- You are restricted to writing files within this directory while in Plan Mode. -- Use descriptive filenames: \`feature-name.md\` or \`bugfix-description.md\` +## Rules +1. **Read-Only:** You cannot modify source code. You may ONLY use read-only tools to explore, and you can only write to \`${options.plansDir}/\`. +2. **Efficiency:** Autonomously combine discovery and drafting phases to minimize conversational turns. If the request is ambiguous, use ${formatToolName(ASK_USER_TOOL_NAME)} to clarify. Otherwise, explore the codebase and write the draft in one fluid motion. +3. **Plan Storage:** Save plans as Markdown (.md) using descriptive filenames (e.g., \`feature-x.md\`). -## Workflow Rules -1. Sequential Execution: Complete ONE phase at a time. Do NOT skip ahead or combine phases. -2. User Confirmation: Wait for user input/approval before proceeding to the next phase. -3. Step Back Protocol: If new information discovered during Exploration or Design invalidates previous assumptions or requirements, you MUST pause, inform the user, and request to return to the appropriate previous phase. +## Required Plan Structure +When writing the plan file, you MUST include the following structure: + # Objective + (A concise summary of what needs to be built or fixed) + # Key Files & Context + (List the specific files that will be modified, including helpful context like function signatures or code snippets) + # Implementation Steps + (Iterative development steps, e.g., "1. Implement X in [File]", "2. Verify with test Y") + # Verification & Testing + (Specific unit tests, manual checks, or build commands to verify success) -## Workflow Phases +## Workflow +1. **Explore & Analyze:** Analyze requirements and use search/read tools to explore the codebase. For complex tasks, identify at least two viable implementation approaches. +2. **Consult:** Present a concise summary of the identified approaches (including pros/cons and your recommendation) to the user via ${formatToolName(ASK_USER_TOOL_NAME)} and wait for their selection. For simple or canonical tasks, you may skip this and proceed to drafting. +3. **Draft:** Write the detailed implementation plan for the selected approach to the plans directory using ${formatToolName(WRITE_FILE_TOOL_NAME)}. +4. **Review & Approval:** Present a brief summary of the drafted plan in your chat response and concurrently call the ${formatToolName(EXIT_PLAN_MODE_TOOL_NAME)} tool to formally request approval. If rejected, iterate. -### Phase 1: Requirements -- Analyze the user's request to identify core requirements and constraints. -- Proactively identify ambiguities, implicit assumptions, and edge cases. -- Categorize questions: functional requirements, non-functional constraints (performance, compatibility), and scope boundaries. -- Use the ${formatToolName(ASK_USER_TOOL_NAME)} tool with well-structured options to clarify ambiguities. Prefer providing multiple-choice options for the user to select from when possible. - -### Phase 2: Exploration -- Only begin this phase after requirements are clear. -- Use the available read-only tools to explore the project. -- Map relevant code paths, dependencies, and architectural patterns. -- Identify existing utilities, patterns, and abstractions that can be reused. -- Note potential constraints (e.g., existing conventions, test infrastructure). -- Output: Summarize key findings to the user before proceeding to design. - -### Phase 3: Design -- Only begin this phase after exploration is complete. -- **Identify Approaches:** - - For Complex Tasks: Identify at least 2 viable implementation approaches. Document the approach summary, pros, cons, complexity estimate, and risk factors for each. - - For Canonical Tasks: If there is only one reasonable, standard approach (e.g., a standard library pattern or specific bug fix), detail it and explicitly explain why no other viable alternatives were considered. -- Mandatory User Interaction: Present the analysis to the user via ${formatToolName(ASK_USER_TOOL_NAME)} and recommend a preferred approach. -- Wait for Selection: You MUST pause and wait for the user to select an approach before proceeding. Do NOT assume the user will agree with your recommendation. - -### Phase 4: Planning -- Pre-requisite: You MUST have a user-selected approach from Phase 3 before generating the plan. -- Create a detailed implementation plan and save it to the designated plans directory. -- **Document Structure:** The plan MUST be a structured Markdown document (focused on implementation guidance, not workflow logging) using exactly these H2 headings: - - \`## Problem Statement\` - Describe the problem or need this change addresses. - - \`## Proposed Solution\` - Provide technical details of the implementation. - - \`## Implementation Plan\` - List ordered steps with specific file paths and the nature of each change. - - \`## Verification Plan\` - Define specific tests or manual steps to verify the change works and breaks nothing else. - - \`## Risks & Mitigations\` - Identify potential failure modes and mitigation strategies. - - \`## Alternatives Considered\` - Provide a brief analysis of other approaches considered and why they were rejected. - -### Phase 5: Approval -- Present the plan and request approval for the finalized plan using the ${formatToolName(EXIT_PLAN_MODE_TOOL_NAME)} tool -- If plan is approved, you can begin implementation. -- If plan is rejected, address the feedback and iterate on the plan. - -${renderApprovedPlanSection(options.approvedPlanPath)} - -## Constraints -- You may ONLY use the read-only tools listed above -- You MUST NOT modify source code, configs, or any files -- If asked to modify code, explain you are in Plan Mode and suggest exiting Plan Mode to enable edits`.trim(); +${renderApprovedPlanSection(options.approvedPlanPath)}`.trim(); } function renderApprovedPlanSection(approvedPlanPath?: string): string { if (!approvedPlanPath) return ''; return `## Approved Plan -An approved plan is available for this task. -- **Iterate:** You should default to refining the existing approved plan. -- **New Plan:** Only create a new plan file if the user explicitly asks for a "new plan" or if the current request is for a completely different feature or bug. +An approved plan is available for this task at \`${approvedPlanPath}\`. +- **Read First:** You MUST read this file using the ${formatToolName(READ_FILE_TOOL_NAME)} tool before proposing any changes or starting discovery. +- **Iterate:** Default to refining the existing approved plan. +- **New Plan:** Only create a new plan file if the user explicitly asks for a "new plan". `; } @@ -528,7 +498,7 @@ function mandateContinueWork(interactive: boolean): string { function workflowStepResearch(options: PrimaryWorkflowsOptions): string { let suggestion = ''; if (options.enableEnterPlanModeTool) { - suggestion = ` For complex tasks, consider using the ${formatToolName(ENTER_PLAN_MODE_TOOL_NAME)} tool to enter a dedicated planning phase before starting implementation.`; + suggestion = ` If the request is ambiguous, broad in scope, or involves creating a new feature/application, you MUST use the ${formatToolName(ENTER_PLAN_MODE_TOOL_NAME)} tool to design your approach before making changes. Do NOT use Plan Mode for straightforward bug fixes, answering questions, or simple inquiries.`; } const searchTools: string[] = []; @@ -558,7 +528,7 @@ function workflowStepResearch(options: PrimaryWorkflowsOptions): string { function workflowStepStrategy(options: PrimaryWorkflowsOptions): string { if (options.approvedPlan) { - return `2. **Strategy:** An approved plan is available for this task. Use this file as a guide for your implementation. You MUST read this file before proceeding. If you discover new requirements or need to change the approach, confirm with the user and update this plan file to reflect the updated design decisions or discovered requirements.`; + return `2. **Strategy:** An approved plan is available for this task. Treat this file as your single source of truth. You MUST read this file before proceeding. If you discover new requirements or need to change the approach, confirm with the user and update this plan file to reflect the updated design decisions or discovered requirements.`; } if (options.enableWriteTodosTool) { @@ -582,16 +552,35 @@ function newApplicationSteps(options: PrimaryWorkflowsOptions): string { if (options.approvedPlan) { return ` -1. **Understand:** Read the approved plan. Use this file as a guide for your implementation. -2. **Implement:** Implement the application according to the plan. If you discover new requirements or need to change the approach, confirm with the user and update this plan file to reflect the updated design decisions or discovered requirements. -3. **Verify:** Review work against the original request, the approved plan. Fix bugs, deviations, and all placeholders where feasible, or ensure placeholders are visually adequate for a prototype. Ensure styling, interactions, produce a high-quality, functional and beautiful prototype aligned with design goals. Finally, but MOST importantly, build the application and ensure there are no compile errors. +1. **Understand:** Read the approved plan. Treat this file as your single source of truth. +2. **Implement:** Implement the application according to the plan. When starting, scaffold the application using ${formatToolName(SHELL_TOOL_NAME)}. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, CSS animations, icons) to ensure a complete, rich, and coherent experience. Never link to external services or assume local paths for assets that have not been created. If you discover new requirements or need to change the approach, confirm with the user and update the plan file. +3. **Verify:** Review work against the original request and the approved plan. Fix bugs, deviations, and ensure placeholders are visually adequate. **Ensure styling and interactions produce a high-quality, polished, and beautiful prototype.** Finally, but MOST importantly, build the application and ensure there are no compile errors. 4. **Finish:** Provide a brief summary of what was built.`.trim(); } + // When Plan Mode is enabled globally, mandate its use for new apps and let the + // standard 'Execution' loop handle implementation once the plan is approved. + if (options.enableEnterPlanModeTool) { + return ` +1. **Mandatory Planning:** You MUST use the ${formatToolName(ENTER_PLAN_MODE_TOOL_NAME)} tool to draft a comprehensive design document and obtain user approval before writing any code. +2. **Design Constraints:** When drafting your plan, adhere to these defaults unless explicitly overridden by the user: + - **Goal:** Autonomously design a visually appealing, substantially complete, and functional prototype with rich aesthetics. Users judge applications by their visual impact; ensure they feel modern, "alive," and polished through consistent spacing, typography, and interactive feedback. + - **Visuals:** Describe your strategy for sourcing or generating placeholders (e.g., stylized CSS shapes, gradients, procedurally generated patterns) to ensure a visually complete prototype. Never plan for assets that cannot be locally generated. + - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested. + - **Web:** React (TypeScript) or Angular with Vanilla CSS. + - **APIs:** Node.js (Express) or Python (FastAPI). + - **Mobile:** Compose Multiplatform or Flutter. + - **Games:** HTML/CSS/JS (Three.js for 3D). + - **CLIs:** Python or Go. +3. **Implementation:** Once the plan is approved, follow the standard **Execution** cycle to build the application, utilizing platform-native primitives to realize the rich aesthetic you planned.`.trim(); + } + + // --- FALLBACK: Legacy workflow for when Plan Mode is disabled --- + if (interactive) { return ` 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. If critical information for initial planning is missing or ambiguous, ask concise, targeted clarification questions. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns) to ensure a visually complete initial prototype.${planningPhaseSuggestion(options)} +2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user and obtain their approval before proceeding. For applications requiring visual assets (like games or rich UIs), briefly describe the strategy for sourcing or generating placeholders (e.g., simple geometric shapes, procedurally generated patterns). - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested; if requested, confirm the specific version (e.g., v3 or v4). - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -599,14 +588,14 @@ function newApplicationSteps(options: PrimaryWorkflowsOptions): string { - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using ${formatToolName(SHELL_TOOL_NAME)} for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. -5. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** -6. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype.`.trim(); +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using ${formatToolName(SHELL_TOOL_NAME)} for commands like 'npm init', 'npx create-react-app'. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons) to ensure a complete, coherent experience. Never link to external services or assume local paths for assets that have not been created. +4. **Verify:** Review work against the original request. Fix bugs and deviations. Ensure styling and interactions produce a high-quality, functional, and beautiful prototype. **Build the application and ensure there are no compile errors.** +5. **Solicit Feedback:** Provide instructions on how to start the application and request user feedback on the prototype.`.trim(); } + return ` 1. **Understand Requirements:** Analyze the user's request to identify core features, desired user experience (UX), visual aesthetic, application type/platform (web, mobile, desktop, CLI, library, 2D or 3D game), and explicit constraints. -2. **Propose Plan:** Formulate an internal development plan. Present a clear, concise, high-level summary to the user. For applications requiring visual assets, describe the strategy for sourcing or generating placeholders. +2. **Plan:** Formulate an internal development plan. For applications requiring visual assets, describe the strategy for sourcing or generating placeholders. - **Styling:** **Prefer Vanilla CSS** for maximum flexibility. **Avoid TailwindCSS** unless explicitly requested. - **Default Tech Stack:** - **Web:** React (TypeScript) or Angular with Vanilla CSS. @@ -614,17 +603,10 @@ function newApplicationSteps(options: PrimaryWorkflowsOptions): string { - **Mobile:** Compose Multiplatform or Flutter. - **Games:** HTML/CSS/JS (Three.js for 3D). - **CLIs:** Python or Go. -3. Implementation: Autonomously implement each feature per the approved plan. When starting, scaffold the application using ${formatToolName(SHELL_TOOL_NAME)}. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons). Never link to external services or assume local paths for assets that have not been created. +3. **Implementation:** Autonomously implement each feature per the approved plan. When starting, scaffold the application using ${formatToolName(SHELL_TOOL_NAME)}. For visual assets, utilize **platform-native primitives** (e.g., stylized shapes, gradients, icons). Never link to external services or assume local paths for assets that have not been created. 4. **Verify:** Review work against the original request. Fix bugs and deviations. **Build the application and ensure there are no compile errors.**`.trim(); } -function planningPhaseSuggestion(options: PrimaryWorkflowsOptions): string { - if (options.enableEnterPlanModeTool) { - return ` For complex tasks, consider using the ${formatToolName(ENTER_PLAN_MODE_TOOL_NAME)} tool to enter a dedicated planning phase before starting implementation.`; - } - return ''; -} - function toneAndStyleNoChitchat(isGemini3: boolean): string { return isGemini3 ? ` From 868f43927e634ed7b8f97ecf893f643d605aed13 Mon Sep 17 00:00:00 2001 From: Adib234 <30782825+Adib234@users.noreply.github.com> Date: Thu, 12 Feb 2026 12:46:59 -0500 Subject: [PATCH 20/44] feat(plan): create metrics for usage of `AskUser` tool (#18820) Co-authored-by: Jerop Kipruto --- docs/cli/telemetry.md | 22 ++++- .../clearcut-logger/clearcut-logger.test.ts | 88 +++++++++++++++++++ .../clearcut-logger/clearcut-logger.ts | 32 +++++++ .../clearcut-logger/event-metadata-key.ts | 18 +++- packages/core/src/telemetry/loggers.test.ts | 48 ++++++++++ packages/core/src/telemetry/types.ts | 5 ++ packages/core/src/tools/ask-user.test.ts | 22 +++++ packages/core/src/tools/ask-user.ts | 20 +++++ 8 files changed, 250 insertions(+), 5 deletions(-) diff --git a/docs/cli/telemetry.md b/docs/cli/telemetry.md index 407ba101f2..ca44bccaf0 100644 --- a/docs/cli/telemetry.md +++ b/docs/cli/telemetry.md @@ -275,9 +275,9 @@ For local development and debugging, you can capture telemetry data locally: The following section describes the structure of logs and metrics generated for Gemini CLI. -The `session.id`, `installation.id`, and `user.email` (available only when -authenticated with a Google account) are included as common attributes on all -logs and metrics. +The `session.id`, `installation.id`, `active_approval_mode`, and `user.email` +(available only when authenticated with a Google account) are included as common +attributes on all logs and metrics. ### Logs @@ -360,7 +360,21 @@ Captures tool executions, output truncation, and Edit behavior. - `extension_name` (string, if applicable) - `extension_id` (string, if applicable) - `content_length` (int, if applicable) - - `metadata` (if applicable) + - `metadata` (if applicable), which includes for the `AskUser` tool: + - `ask_user` (object): + - `question_types` (array of strings) + - `ask_user_dismissed` (boolean) + - `ask_user_empty_submission` (boolean) + - `ask_user_answer_count` (number) + - `diffStat` (if applicable), which includes: + - `model_added_lines` (number) + - `model_removed_lines` (number) + - `model_added_chars` (number) + - `model_removed_chars` (number) + - `user_added_lines` (number) + - `user_removed_lines` (number) + - `user_added_chars` (number) + - `user_removed_chars` (number) - `gemini_cli.tool_output_truncated`: Output of a tool call was truncated. - **Attributes**: 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 3cad76b491..a5bed404d9 100644 --- a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts +++ b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts @@ -336,6 +336,10 @@ describe('ClearcutLogger', () => { gemini_cli_key: EventMetadataKey.GEMINI_CLI_USER_SETTINGS, value: logger?.getConfigJson(), }, + { + gemini_cli_key: EventMetadataKey.GEMINI_CLI_ACTIVE_APPROVAL_MODE, + value: 'default', + }, ]), ); }); @@ -1239,6 +1243,90 @@ describe('ClearcutLogger', () => { EventMetadataKey.GEMINI_CLI_AI_ADDED_LINES, ); }); + + it('logs AskUser tool metadata', () => { + const { logger } = setup(); + const completedToolCall = { + request: { + name: 'ask_user', + args: { questions: [] }, + prompt_id: 'prompt-123', + }, + response: { + resultDisplay: 'User answered: ...', + data: { + ask_user: { + question_types: ['choice', 'text'], + dismissed: false, + empty_submission: false, + answer_count: 2, + }, + }, + }, + status: 'success', + } as unknown as SuccessfulToolCall; + + logger?.logToolCallEvent(new ToolCallEvent(completedToolCall)); + + const events = getEvents(logger!); + expect(events.length).toBe(1); + expect(events[0]).toHaveEventName(EventNames.TOOL_CALL); + expect(events[0]).toHaveMetadataValue([ + EventMetadataKey.GEMINI_CLI_ASK_USER_QUESTION_TYPES, + JSON.stringify(['choice', 'text']), + ]); + expect(events[0]).toHaveMetadataValue([ + EventMetadataKey.GEMINI_CLI_ASK_USER_DISMISSED, + 'false', + ]); + expect(events[0]).toHaveMetadataValue([ + EventMetadataKey.GEMINI_CLI_ASK_USER_EMPTY_SUBMISSION, + 'false', + ]); + expect(events[0]).toHaveMetadataValue([ + EventMetadataKey.GEMINI_CLI_ASK_USER_ANSWER_COUNT, + '2', + ]); + }); + + it('does not log AskUser tool metadata for other tools', () => { + const { logger } = setup(); + const completedToolCall = { + request: { + name: 'some_other_tool', + args: {}, + prompt_id: 'prompt-123', + }, + response: { + resultDisplay: 'Result', + data: { + ask_user_question_types: ['choice', 'text'], + ask_user_dismissed: false, + ask_user_empty_submission: false, + ask_user_answer_count: 2, + }, + }, + status: 'success', + } as unknown as SuccessfulToolCall; + + logger?.logToolCallEvent(new ToolCallEvent(completedToolCall)); + + const events = getEvents(logger!); + expect(events.length).toBe(1); + expect(events[0]).toHaveEventName(EventNames.TOOL_CALL); + expect(events[0]).not.toHaveMetadataKey( + EventMetadataKey.GEMINI_CLI_ASK_USER_QUESTION_TYPES, + ); + expect(events[0]).not.toHaveMetadataKey( + EventMetadataKey.GEMINI_CLI_ASK_USER_DISMISSED, + ); + expect(events[0]).not.toHaveMetadataKey( + EventMetadataKey.GEMINI_CLI_ASK_USER_EMPTY_SUBMISSION, + ); + expect(events[0]).not.toHaveMetadataKey( + EventMetadataKey.GEMINI_CLI_ASK_USER_ANSWER_COUNT, + ); + }); }); describe('flushIfNeeded', () => { diff --git a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts index b63cac58eb..570725318a 100644 --- a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts +++ b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts @@ -56,6 +56,7 @@ import { safeJsonStringify, safeJsonStringifyBooleanValuesOnly, } from '../../utils/safeJsonStringify.js'; +import { ASK_USER_TOOL_NAME } from '../../tools/tool-names.js'; import { FixedDeque } from 'mnemonist'; import { GIT_COMMIT_INFO, CLI_VERSION } from '../../generated/git-commit.js'; import { @@ -704,6 +705,29 @@ export class ClearcutLogger { user_removed_chars: EventMetadataKey.GEMINI_CLI_USER_REMOVED_CHARS, }; + if ( + event.function_name === ASK_USER_TOOL_NAME && + event.metadata['ask_user'] + ) { + const askUser = event.metadata['ask_user']; + const askUserMapping: { [key: string]: EventMetadataKey } = { + question_types: EventMetadataKey.GEMINI_CLI_ASK_USER_QUESTION_TYPES, + dismissed: EventMetadataKey.GEMINI_CLI_ASK_USER_DISMISSED, + empty_submission: + EventMetadataKey.GEMINI_CLI_ASK_USER_EMPTY_SUBMISSION, + answer_count: EventMetadataKey.GEMINI_CLI_ASK_USER_ANSWER_COUNT, + }; + + for (const [key, gemini_cli_key] of Object.entries(askUserMapping)) { + if (askUser[key] !== undefined) { + data.push({ + gemini_cli_key, + value: JSON.stringify(askUser[key]), + }); + } + } + } + for (const [key, gemini_cli_key] of Object.entries(metadataMapping)) { if (event.metadata[key] !== undefined) { data.push({ @@ -1625,6 +1649,14 @@ export class ClearcutLogger { gemini_cli_key: EventMetadataKey.GEMINI_CLI_INTERACTIVE, value: this.config?.isInteractive().toString() ?? 'false', }, + { + gemini_cli_key: EventMetadataKey.GEMINI_CLI_ACTIVE_APPROVAL_MODE, + value: + typeof this.config?.getPolicyEngine === 'function' && + typeof this.config.getPolicyEngine()?.getApprovalMode === 'function' + ? this.config.getPolicyEngine().getApprovalMode() + : '', + }, ]; if (this.config?.getExperiments()) { defaultLogMetadata.push({ 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 25e6e18d13..8934db5570 100644 --- a/packages/core/src/telemetry/clearcut-logger/event-metadata-key.ts +++ b/packages/core/src/telemetry/clearcut-logger/event-metadata-key.ts @@ -7,7 +7,7 @@ // Defines valid event metadata keys for Clearcut logging. export enum EventMetadataKey { // Deleted enums: 24 - // Next ID: 152 + // Next ID: 156 GEMINI_CLI_KEY_UNKNOWN = 0, @@ -577,4 +577,20 @@ export enum EventMetadataKey { // Logs the total prunable tokens identified at the trigger point. GEMINI_CLI_TOOL_OUTPUT_MASKING_TOTAL_PRUNABLE_TOKENS = 151, + + // ========================================================================== + // Ask User Stats Event Keys + // ========================================================================== + + // Logs the types of questions asked in the ask_user tool. + GEMINI_CLI_ASK_USER_QUESTION_TYPES = 152, + + // Logs whether the ask_user dialog was dismissed. + GEMINI_CLI_ASK_USER_DISMISSED = 153, + + // Logs whether the ask_user dialog was submitted empty. + GEMINI_CLI_ASK_USER_EMPTY_SUBMISSION = 154, + + // Logs the number of questions answered in the ask_user tool. + GEMINI_CLI_ASK_USER_ANSWER_COUNT = 155, } diff --git a/packages/core/src/telemetry/loggers.test.ts b/packages/core/src/telemetry/loggers.test.ts index 16da103244..fd2d1bc221 100644 --- a/packages/core/src/telemetry/loggers.test.ts +++ b/packages/core/src/telemetry/loggers.test.ts @@ -5,6 +5,7 @@ */ import type { + AnyDeclarativeTool, AnyToolInvocation, CompletedToolCall, ContentGeneratorConfig, @@ -1184,6 +1185,53 @@ describe('loggers', () => { { function_name: 'test-function' }, ); }); + + it('should merge data from response into metadata', () => { + const call: CompletedToolCall = { + status: 'success', + request: { + name: 'ask_user', + args: { questions: [] }, + callId: 'test-call-id', + isClientInitiated: true, + prompt_id: 'prompt-id-1', + }, + response: { + callId: 'test-call-id', + responseParts: [{ text: 'test-response' }], + resultDisplay: 'User answered: ...', + error: undefined, + errorType: undefined, + data: { + ask_user: { + question_types: ['choice'], + dismissed: false, + }, + }, + }, + tool: undefined as unknown as AnyDeclarativeTool, + invocation: {} as AnyToolInvocation, + durationMs: 100, + outcome: ToolConfirmationOutcome.ProceedOnce, + }; + const event = new ToolCallEvent(call); + + logToolCall(mockConfig, event); + + expect(mockLogger.emit).toHaveBeenCalledWith({ + body: 'Tool call: ask_user. Decision: accept. Success: true. Duration: 100ms.', + attributes: expect.objectContaining({ + function_name: 'ask_user', + metadata: expect.objectContaining({ + ask_user: { + question_types: ['choice'], + dismissed: false, + }, + }), + }), + }); + }); + it('should log a tool call with a reject decision', () => { const call: ErroredToolCall = { status: 'error', diff --git a/packages/core/src/telemetry/types.ts b/packages/core/src/telemetry/types.ts index 0c438764f1..cf0e5f853f 100644 --- a/packages/core/src/telemetry/types.ts +++ b/packages/core/src/telemetry/types.ts @@ -304,6 +304,7 @@ export class ToolCallEvent implements BaseTelemetryEvent { const diffStat = fileDiff.diffStat; if (diffStat) { this.metadata = { + ...this.metadata, model_added_lines: diffStat.model_added_lines, model_removed_lines: diffStat.model_removed_lines, model_added_chars: diffStat.model_added_chars, @@ -315,6 +316,10 @@ export class ToolCallEvent implements BaseTelemetryEvent { }; } } + + if (call.status === 'success' && call.response.data) { + this.metadata = { ...this.metadata, ...call.response.data }; + } } else { // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion this.function_name = function_name as string; diff --git a/packages/core/src/tools/ask-user.test.ts b/packages/core/src/tools/ask-user.test.ts index 969a4f7f15..c7d64eae6e 100644 --- a/packages/core/src/tools/ask-user.test.ts +++ b/packages/core/src/tools/ask-user.test.ts @@ -337,6 +337,14 @@ describe('AskUserTool', () => { expect(JSON.parse(result.llmContent as string)).toEqual({ answers: { '0': 'Quick fix (Recommended)' }, }); + expect(result.data).toEqual({ + ask_user: { + question_types: [QuestionType.CHOICE], + dismissed: false, + empty_submission: false, + answer_count: 1, + }, + }); }); it('should display message when user submits without answering', async () => { @@ -368,6 +376,14 @@ describe('AskUserTool', () => { 'User submitted without answering questions.', ); expect(JSON.parse(result.llmContent as string)).toEqual({ answers: {} }); + expect(result.data).toEqual({ + ask_user: { + question_types: [QuestionType.CHOICE], + dismissed: false, + empty_submission: true, + answer_count: 0, + }, + }); }); it('should handle cancellation', async () => { @@ -405,6 +421,12 @@ describe('AskUserTool', () => { expect(result.llmContent).toBe( 'User dismissed ask_user dialog without answering.', ); + expect(result.data).toEqual({ + ask_user: { + question_types: [QuestionType.CHOICE], + dismissed: true, + }, + }); }); }); }); diff --git a/packages/core/src/tools/ask-user.ts b/packages/core/src/tools/ask-user.ts index 071dd1b317..db9103c720 100644 --- a/packages/core/src/tools/ask-user.ts +++ b/packages/core/src/tools/ask-user.ts @@ -192,16 +192,35 @@ export class AskUserInvocation extends BaseToolInvocation< } async execute(_signal: AbortSignal): Promise { + const questionTypes = this.params.questions.map( + (q) => q.type ?? QuestionType.CHOICE, + ); + if (this.confirmationOutcome === ToolConfirmationOutcome.Cancel) { return { llmContent: 'User dismissed ask_user dialog without answering.', returnDisplay: 'User dismissed dialog', + data: { + ask_user: { + question_types: questionTypes, + dismissed: true, + }, + }, }; } const answerEntries = Object.entries(this.userAnswers); const hasAnswers = answerEntries.length > 0; + const metrics: Record = { + ask_user: { + question_types: questionTypes, + dismissed: false, + empty_submission: !hasAnswers, + answer_count: answerEntries.length, + }, + }; + const returnDisplay = hasAnswers ? `**User answered:**\n${answerEntries .map(([index, answer]) => { @@ -219,6 +238,7 @@ export class AskUserInvocation extends BaseToolInvocation< return { llmContent: JSON.stringify({ answers: this.userAnswers }), returnDisplay, + data: metrics, }; } } From 375ebca2da8b82949ba263a0d9255f28d5472eec Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Thu, 12 Feb 2026 09:55:56 -0800 Subject: [PATCH 21/44] feat(cli): support Ctrl-Z suspension (#18931) Co-authored-by: Bharat Kunwar --- docs/cli/keyboard-shortcuts.md | 2 +- packages/cli/src/config/keyBindings.ts | 2 +- packages/cli/src/ui/AppContainer.test.tsx | 73 ++++--- packages/cli/src/ui/AppContainer.tsx | 61 ++++-- .../__snapshots__/InputPrompt.test.tsx.snap | 33 +++ packages/cli/src/ui/hooks/useSuspend.test.ts | 201 ++++++++++++++++++ packages/cli/src/ui/hooks/useSuspend.ts | 155 ++++++++++++++ packages/cli/src/ui/keyMatchers.test.ts | 12 ++ .../src/ui/utils/terminalCapabilityManager.ts | 37 ++-- 9 files changed, 515 insertions(+), 61 deletions(-) create mode 100644 packages/cli/src/ui/hooks/useSuspend.test.ts create mode 100644 packages/cli/src/ui/hooks/useSuspend.ts diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index 91baedc8c9..0dc32b7779 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -120,7 +120,7 @@ available combinations. | Move focus from the shell back to Gemini. | `Shift + Tab` | | Clear the terminal screen and redraw the UI. | `Ctrl + L` | | Restart the application. | `R` | -| Suspend the application (not yet implemented). | `Ctrl + Z` | +| Suspend the CLI and move it to the background. | `Ctrl + Z` | diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index 96e50f36d6..adf88d4d25 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -523,5 +523,5 @@ export const commandDescriptions: Readonly> = { [Command.UNFOCUS_SHELL_INPUT]: 'Move focus from the shell back to Gemini.', [Command.CLEAR_SCREEN]: 'Clear the terminal screen and redraw the UI.', [Command.RESTART_APP]: 'Restart the application.', - [Command.SUSPEND_APP]: 'Suspend the application (not yet implemented).', + [Command.SUSPEND_APP]: 'Suspend the CLI and move it to the background.', }; diff --git a/packages/cli/src/ui/AppContainer.test.tsx b/packages/cli/src/ui/AppContainer.test.tsx index 063315f8ac..ff84834c69 100644 --- a/packages/cli/src/ui/AppContainer.test.tsx +++ b/packages/cli/src/ui/AppContainer.test.tsx @@ -135,6 +135,7 @@ vi.mock('./hooks/vim.js'); vi.mock('./hooks/useFocus.js'); vi.mock('./hooks/useBracketedPaste.js'); vi.mock('./hooks/useLoadingIndicator.js'); +vi.mock('./hooks/useSuspend.js'); vi.mock('./hooks/useFolderTrust.js'); vi.mock('./hooks/useIdeTrustListener.js'); vi.mock('./hooks/useMessageQueue.js'); @@ -199,6 +200,7 @@ import { useLoadingIndicator } from './hooks/useLoadingIndicator.js'; import { useInputHistoryStore } from './hooks/useInputHistoryStore.js'; import { useKeypress, type Key } from './hooks/useKeypress.js'; import * as useKeypressModule from './hooks/useKeypress.js'; +import { useSuspend } from './hooks/useSuspend.js'; import { measureElement } from 'ink'; import { useTerminalSize } from './hooks/useTerminalSize.js'; import { @@ -271,6 +273,7 @@ describe('AppContainer State Management', () => { const mockedUseTextBuffer = useTextBuffer as Mock; const mockedUseLogger = useLogger as Mock; const mockedUseLoadingIndicator = useLoadingIndicator as Mock; + const mockedUseSuspend = useSuspend as Mock; const mockedUseInputHistoryStore = useInputHistoryStore as Mock; const mockedUseHookDisplayState = useHookDisplayState as Mock; const mockedUseTerminalTheme = useTerminalTheme as Mock; @@ -402,6 +405,9 @@ describe('AppContainer State Management', () => { elapsedTime: '0.0s', currentLoadingPhrase: '', }); + mockedUseSuspend.mockReturnValue({ + handleSuspend: vi.fn(), + }); mockedUseHookDisplayState.mockReturnValue([]); mockedUseTerminalTheme.mockReturnValue(undefined); mockedUseShellInactivityStatus.mockReturnValue({ @@ -441,8 +447,8 @@ describe('AppContainer State Management', () => { ...defaultMergedSettings.ui, showStatusInTitle: false, hideWindowTitle: false, + useAlternateBuffer: false, }, - useAlternateBuffer: false, }, } as unknown as LoadedSettings; @@ -728,10 +734,10 @@ describe('AppContainer State Management', () => { getChatRecordingService: vi.fn(() => mockChatRecordingService), }; - const configWithRecording = { - ...mockConfig, - getGeminiClient: vi.fn(() => mockGeminiClient), - } as unknown as Config; + const configWithRecording = makeFakeConfig(); + vi.spyOn(configWithRecording, 'getGeminiClient').mockReturnValue( + mockGeminiClient as unknown as ReturnType, + ); expect(() => { renderAppContainer({ @@ -762,11 +768,13 @@ describe('AppContainer State Management', () => { setHistory: vi.fn(), }; - const configWithRecording = { - ...mockConfig, - getGeminiClient: vi.fn(() => mockGeminiClient), - getSessionId: vi.fn(() => 'test-session-123'), - } as unknown as Config; + const configWithRecording = makeFakeConfig(); + vi.spyOn(configWithRecording, 'getGeminiClient').mockReturnValue( + mockGeminiClient as unknown as ReturnType, + ); + vi.spyOn(configWithRecording, 'getSessionId').mockReturnValue( + 'test-session-123', + ); expect(() => { renderAppContainer({ @@ -802,10 +810,10 @@ describe('AppContainer State Management', () => { getUserTier: vi.fn(), }; - const configWithRecording = { - ...mockConfig, - getGeminiClient: vi.fn(() => mockGeminiClient), - } as unknown as Config; + const configWithRecording = makeFakeConfig(); + vi.spyOn(configWithRecording, 'getGeminiClient').mockReturnValue( + mockGeminiClient as unknown as ReturnType, + ); renderAppContainer({ config: configWithRecording, @@ -836,10 +844,10 @@ describe('AppContainer State Management', () => { })), }; - const configWithClient = { - ...mockConfig, - getGeminiClient: vi.fn(() => mockGeminiClient), - } as unknown as Config; + const configWithClient = makeFakeConfig(); + vi.spyOn(configWithClient, 'getGeminiClient').mockReturnValue( + mockGeminiClient as unknown as ReturnType, + ); const resumedData = { conversation: { @@ -892,10 +900,10 @@ describe('AppContainer State Management', () => { getChatRecordingService: vi.fn(), }; - const configWithClient = { - ...mockConfig, - getGeminiClient: vi.fn(() => mockGeminiClient), - } as unknown as Config; + const configWithClient = makeFakeConfig(); + vi.spyOn(configWithClient, 'getGeminiClient').mockReturnValue( + mockGeminiClient as unknown as ReturnType, + ); const resumedData = { conversation: { @@ -945,10 +953,10 @@ describe('AppContainer State Management', () => { getUserTier: vi.fn(), }; - const configWithRecording = { - ...mockConfig, - getGeminiClient: vi.fn(() => mockGeminiClient), - } as unknown as Config; + const configWithRecording = makeFakeConfig(); + vi.spyOn(configWithRecording, 'getGeminiClient').mockReturnValue( + mockGeminiClient as unknown as ReturnType, + ); renderAppContainer({ config: configWithRecording, @@ -1943,6 +1951,19 @@ describe('AppContainer State Management', () => { }); }); + describe('CTRL+Z', () => { + it('should call handleSuspend', async () => { + const handleSuspend = vi.fn(); + mockedUseSuspend.mockReturnValue({ handleSuspend }); + await setupKeypressTest(); + + pressKey('\x1A'); // Ctrl+Z + + expect(handleSuspend).toHaveBeenCalledTimes(1); + unmount(); + }); + }); + describe('Focus Handling (Tab / Shift+Tab)', () => { beforeEach(() => { // Mock activePtyId to enable focus diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index 7489d07e2a..a2f25a71de 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -12,7 +12,14 @@ import { useRef, useLayoutEffect, } from 'react'; -import { type DOMElement, measureElement } from 'ink'; +import { + type DOMElement, + measureElement, + useApp, + useStdout, + useStdin, + type AppProps, +} from 'ink'; import { App } from './App.js'; import { AppContext } from './contexts/AppContext.js'; import { UIStateContext, type UIState } from './contexts/UIStateContext.js'; @@ -87,7 +94,6 @@ import { useVimMode } from './contexts/VimModeContext.js'; import { useConsoleMessages } from './hooks/useConsoleMessages.js'; import { useTerminalSize } from './hooks/useTerminalSize.js'; import { calculatePromptWidths } from './components/InputPrompt.js'; -import { useApp, useStdout, useStdin } from 'ink'; import { calculateMainAreaWidth } from './utils/ui-sizing.js'; import ansiEscapes from 'ansi-escapes'; import { basename } from 'node:path'; @@ -146,8 +152,8 @@ import { NewAgentsChoice } from './components/NewAgentsNotification.js'; import { isSlashCommand } from './utils/commandUtils.js'; import { useTerminalTheme } from './hooks/useTerminalTheme.js'; import { useTimedMessage } from './hooks/useTimedMessage.js'; -import { isITerm2 } from './utils/terminalUtils.js'; import { shouldDismissShortcutsHelpOnHotkey } from './utils/shortcutsHelp.js'; +import { useSuspend } from './hooks/useSuspend.js'; function isToolExecuting(pendingHistoryItems: HistoryItemWithoutId[]) { return pendingHistoryItems.some((item) => { @@ -201,6 +207,7 @@ export const AppContainer = (props: AppContainerProps) => { useMemoryMonitor(historyManager); const isAlternateBuffer = useAlternateBuffer(); const [corgiMode, setCorgiMode] = useState(false); + const [forceRerenderKey, setForceRerenderKey] = useState(0); const [debugMessage, setDebugMessage] = useState(''); const [quittingMessages, setQuittingMessages] = useState< HistoryItem[] | null @@ -347,7 +354,7 @@ export const AppContainer = (props: AppContainerProps) => { const { columns: terminalWidth, rows: terminalHeight } = useTerminalSize(); const { stdin, setRawMode } = useStdin(); const { stdout } = useStdout(); - const app = useApp(); + const app: AppProps = useApp(); // Additional hooks moved from App.tsx const { stats: sessionStats } = useSessionStats(); @@ -536,10 +543,13 @@ export const AppContainer = (props: AppContainerProps) => { setHistoryRemountKey((prev) => prev + 1); }, [setHistoryRemountKey, isAlternateBuffer, stdout]); + const shouldUseAlternateScreen = shouldEnterAlternateScreen( + isAlternateBuffer, + config.getScreenReader(), + ); + const handleEditorClose = useCallback(() => { - if ( - shouldEnterAlternateScreen(isAlternateBuffer, config.getScreenReader()) - ) { + if (shouldUseAlternateScreen) { // The editor may have exited alternate buffer mode so we need to // enter it again to be safe. enterAlternateScreen(); @@ -549,7 +559,7 @@ export const AppContainer = (props: AppContainerProps) => { } terminalCapabilityManager.enableSupportedModes(); refreshStatic(); - }, [refreshStatic, isAlternateBuffer, app, config]); + }, [refreshStatic, shouldUseAlternateScreen, app]); const [editorError, setEditorError] = useState(null); const { @@ -1370,6 +1380,24 @@ Logging in with Google... Restarting Gemini CLI to continue. }; }, [showTransientMessage]); + const handleWarning = useCallback( + (message: string) => { + showTransientMessage({ + text: message, + type: TransientMessageType.Warning, + }); + }, + [showTransientMessage], + ); + + const { handleSuspend } = useSuspend({ + handleWarning, + setRawMode, + refreshStatic, + setForceRerenderKey, + shouldUseAlternateScreen, + }); + useEffect(() => { if (ideNeedsRestart) { // IDE trust changed, force a restart. @@ -1510,6 +1538,9 @@ Logging in with Google... Restarting Gemini CLI to continue. } else if (keyMatchers[Command.EXIT](key)) { setCtrlDPressCount((prev) => prev + 1); return true; + } else if (keyMatchers[Command.SUSPEND_APP](key)) { + handleSuspend(); + return true; } let enteringConstrainHeightMode = false; @@ -1535,15 +1566,6 @@ Logging in with Google... Restarting Gemini CLI to continue. setShowErrorDetails((prev) => !prev); } return true; - } else if (keyMatchers[Command.SUSPEND_APP](key)) { - const undoMessage = isITerm2() - ? 'Undo has been moved to Option + Z' - : 'Undo has been moved to Alt/Option + Z or Cmd + Z'; - showTransientMessage({ - text: undoMessage, - type: TransientMessageType.Warning, - }); - return true; } else if (keyMatchers[Command.SHOW_FULL_TODOS](key)) { setShowFullTodos((prev) => !prev); return true; @@ -1652,10 +1674,12 @@ Logging in with Google... Restarting Gemini CLI to continue. handleSlashCommand, cancelOngoingRequest, activePtyId, + handleSuspend, embeddedShellFocused, settings.merged.general.debugKeystrokeLogging, refreshStatic, setCopyModeEnabled, + tabFocusTimeoutRef, isAlternateBuffer, shortcutsHelpVisible, backgroundCurrentShell, @@ -1664,7 +1688,6 @@ Logging in with Google... Restarting Gemini CLI to continue. isBackgroundShellVisible, setIsBackgroundShellListOpen, lastOutputTimeRef, - tabFocusTimeoutRef, showTransientMessage, settings.merged.general.devtools, showErrorDetails, @@ -2276,7 +2299,7 @@ Logging in with Google... Restarting Gemini CLI to continue. > - + diff --git a/packages/cli/src/ui/components/__snapshots__/InputPrompt.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/InputPrompt.test.tsx.snap index ff3818d6f8..05d128f738 100644 --- a/packages/cli/src/ui/components/__snapshots__/InputPrompt.test.tsx.snap +++ b/packages/cli/src/ui/components/__snapshots__/InputPrompt.test.tsx.snap @@ -77,6 +77,39 @@ exports[`InputPrompt > mouse interaction > should toggle paste expansion on doub ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄" `; +exports[`InputPrompt > mouse interaction > should toggle paste expansion on double-click 4`] = ` +"▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ + > [Pasted Text: 10 lines] +▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄" +`; + +exports[`InputPrompt > mouse interaction > should toggle paste expansion on double-click 5`] = ` +"▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ + > [Pasted Text: 10 lines]  +▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄" +`; + +exports[`InputPrompt > mouse interaction > should toggle paste expansion on double-click 6`] = ` +"▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ + > line1  + line2  + line3  + line4  + line5  + line6  + line7  + line8  + line9  + line10  +▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄" +`; + +exports[`InputPrompt > mouse interaction > should toggle paste expansion on double-click 7`] = ` +"▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ + > [Pasted Text: 10 lines]  +▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄" +`; + exports[`InputPrompt > snapshots > should not show inverted cursor when shell is focused 1`] = ` "▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ > Type your message or @path/to/file diff --git a/packages/cli/src/ui/hooks/useSuspend.test.ts b/packages/cli/src/ui/hooks/useSuspend.test.ts new file mode 100644 index 0000000000..9aa90d16b3 --- /dev/null +++ b/packages/cli/src/ui/hooks/useSuspend.test.ts @@ -0,0 +1,201 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + describe, + it, + expect, + vi, + beforeEach, + afterEach, + type Mock, +} from 'vitest'; +import { act } from 'react'; +import { renderHook } from '../../test-utils/render.js'; +import { useSuspend } from './useSuspend.js'; +import { + writeToStdout, + disableMouseEvents, + enableMouseEvents, + enterAlternateScreen, + exitAlternateScreen, + enableLineWrapping, + disableLineWrapping, +} from '@google/gemini-cli-core'; +import { + cleanupTerminalOnExit, + terminalCapabilityManager, +} from '../utils/terminalCapabilityManager.js'; + +vi.mock('@google/gemini-cli-core', async () => { + const actual = await vi.importActual('@google/gemini-cli-core'); + return { + ...actual, + writeToStdout: vi.fn(), + disableMouseEvents: vi.fn(), + enableMouseEvents: vi.fn(), + enterAlternateScreen: vi.fn(), + exitAlternateScreen: vi.fn(), + enableLineWrapping: vi.fn(), + disableLineWrapping: vi.fn(), + }; +}); + +vi.mock('../utils/terminalCapabilityManager.js', () => ({ + cleanupTerminalOnExit: vi.fn(), + terminalCapabilityManager: { + enableSupportedModes: vi.fn(), + }, +})); + +describe('useSuspend', () => { + const originalPlatform = process.platform; + let killSpy: Mock; + + const setPlatform = (platform: NodeJS.Platform) => { + Object.defineProperty(process, 'platform', { + value: platform, + configurable: true, + }); + }; + + beforeEach(() => { + vi.useFakeTimers(); + vi.clearAllMocks(); + killSpy = vi + .spyOn(process, 'kill') + .mockReturnValue(true) as unknown as Mock; + // Default tests to a POSIX platform so suspend path assertions are stable. + setPlatform('linux'); + }); + + afterEach(() => { + vi.useRealTimers(); + killSpy.mockRestore(); + setPlatform(originalPlatform); + }); + + it('cleans terminal state on suspend and restores/repaints on resume in alternate screen mode', () => { + const handleWarning = vi.fn(); + const setRawMode = vi.fn(); + const refreshStatic = vi.fn(); + const setForceRerenderKey = vi.fn(); + const enableSupportedModes = + terminalCapabilityManager.enableSupportedModes as unknown as Mock; + + const { result, unmount } = renderHook(() => + useSuspend({ + handleWarning, + setRawMode, + refreshStatic, + setForceRerenderKey, + shouldUseAlternateScreen: true, + }), + ); + + act(() => { + result.current.handleSuspend(); + }); + expect(handleWarning).toHaveBeenCalledWith( + 'Press Ctrl+Z again to suspend. Undo has moved to Cmd + Z or Alt/Opt + Z.', + ); + + act(() => { + result.current.handleSuspend(); + }); + + expect(exitAlternateScreen).toHaveBeenCalledTimes(1); + expect(enableLineWrapping).toHaveBeenCalledTimes(1); + expect(writeToStdout).toHaveBeenCalledWith('\x1b[2J\x1b[H'); + expect(disableMouseEvents).toHaveBeenCalledTimes(1); + expect(cleanupTerminalOnExit).toHaveBeenCalledTimes(1); + expect(setRawMode).toHaveBeenCalledWith(false); + expect(killSpy).toHaveBeenCalledWith(0, 'SIGTSTP'); + + act(() => { + process.emit('SIGCONT'); + vi.runAllTimers(); + }); + + expect(enterAlternateScreen).toHaveBeenCalledTimes(1); + expect(disableLineWrapping).toHaveBeenCalledTimes(1); + expect(enableSupportedModes).toHaveBeenCalledTimes(1); + expect(enableMouseEvents).toHaveBeenCalledTimes(1); + expect(setRawMode).toHaveBeenCalledWith(true); + expect(refreshStatic).toHaveBeenCalledTimes(1); + expect(setForceRerenderKey).toHaveBeenCalledTimes(1); + + unmount(); + }); + + it('does not toggle alternate screen or mouse restore when alternate screen mode is disabled', () => { + const handleWarning = vi.fn(); + const setRawMode = vi.fn(); + const refreshStatic = vi.fn(); + const setForceRerenderKey = vi.fn(); + + const { result, unmount } = renderHook(() => + useSuspend({ + handleWarning, + setRawMode, + refreshStatic, + setForceRerenderKey, + shouldUseAlternateScreen: false, + }), + ); + + act(() => { + result.current.handleSuspend(); + result.current.handleSuspend(); + process.emit('SIGCONT'); + vi.runAllTimers(); + }); + + expect(exitAlternateScreen).not.toHaveBeenCalled(); + expect(enterAlternateScreen).not.toHaveBeenCalled(); + expect(enableLineWrapping).not.toHaveBeenCalled(); + expect(disableLineWrapping).not.toHaveBeenCalled(); + expect(enableMouseEvents).not.toHaveBeenCalled(); + + unmount(); + }); + + it('warns and skips suspension on windows', () => { + setPlatform('win32'); + + const handleWarning = vi.fn(); + const setRawMode = vi.fn(); + const refreshStatic = vi.fn(); + const setForceRerenderKey = vi.fn(); + + const { result, unmount } = renderHook(() => + useSuspend({ + handleWarning, + setRawMode, + refreshStatic, + setForceRerenderKey, + shouldUseAlternateScreen: true, + }), + ); + + act(() => { + result.current.handleSuspend(); + }); + handleWarning.mockClear(); + + act(() => { + result.current.handleSuspend(); + }); + + expect(handleWarning).toHaveBeenCalledWith( + 'Ctrl+Z suspend is not supported on Windows.', + ); + expect(killSpy).not.toHaveBeenCalled(); + expect(cleanupTerminalOnExit).not.toHaveBeenCalled(); + + unmount(); + }); +}); diff --git a/packages/cli/src/ui/hooks/useSuspend.ts b/packages/cli/src/ui/hooks/useSuspend.ts new file mode 100644 index 0000000000..9c986d30d6 --- /dev/null +++ b/packages/cli/src/ui/hooks/useSuspend.ts @@ -0,0 +1,155 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { useState, useRef, useEffect, useCallback } from 'react'; +import { + writeToStdout, + disableMouseEvents, + enableMouseEvents, + enterAlternateScreen, + exitAlternateScreen, + enableLineWrapping, + disableLineWrapping, +} from '@google/gemini-cli-core'; +import process from 'node:process'; +import { + cleanupTerminalOnExit, + terminalCapabilityManager, +} from '../utils/terminalCapabilityManager.js'; +import { WARNING_PROMPT_DURATION_MS } from '../constants.js'; + +interface UseSuspendProps { + handleWarning: (message: string) => void; + setRawMode: (mode: boolean) => void; + refreshStatic: () => void; + setForceRerenderKey: (updater: (prev: number) => number) => void; + shouldUseAlternateScreen: boolean; +} + +export function useSuspend({ + handleWarning, + setRawMode, + refreshStatic, + setForceRerenderKey, + shouldUseAlternateScreen, +}: UseSuspendProps) { + const [ctrlZPressCount, setCtrlZPressCount] = useState(0); + const ctrlZTimerRef = useRef(null); + const onResumeHandlerRef = useRef<(() => void) | null>(null); + + useEffect( + () => () => { + if (ctrlZTimerRef.current) { + clearTimeout(ctrlZTimerRef.current); + ctrlZTimerRef.current = null; + } + if (onResumeHandlerRef.current) { + process.off('SIGCONT', onResumeHandlerRef.current); + onResumeHandlerRef.current = null; + } + }, + [], + ); + + useEffect(() => { + if (ctrlZTimerRef.current) { + clearTimeout(ctrlZTimerRef.current); + ctrlZTimerRef.current = null; + } + if (ctrlZPressCount > 1) { + setCtrlZPressCount(0); + if (process.platform === 'win32') { + handleWarning('Ctrl+Z suspend is not supported on Windows.'); + return; + } + + if (shouldUseAlternateScreen) { + // Leave alternate buffer before suspension so the shell stays usable. + exitAlternateScreen(); + enableLineWrapping(); + writeToStdout('\x1b[2J\x1b[H'); + } + + // Cleanup before suspend. + writeToStdout('\x1b[?25h'); // Show cursor + disableMouseEvents(); + cleanupTerminalOnExit(); + + if (process.stdin.isTTY) { + process.stdin.setRawMode(false); + } + setRawMode(false); + + const onResume = () => { + try { + // Restore terminal state. + if (process.stdin.isTTY) { + process.stdin.setRawMode(true); + process.stdin.resume(); + process.stdin.ref(); + } + setRawMode(true); + + if (shouldUseAlternateScreen) { + enterAlternateScreen(); + disableLineWrapping(); + writeToStdout('\x1b[2J\x1b[H'); + } + + terminalCapabilityManager.enableSupportedModes(); + writeToStdout('\x1b[?25l'); // Hide cursor + if (shouldUseAlternateScreen) { + enableMouseEvents(); + } + + // Force Ink to do a complete repaint by: + // 1. Emitting a resize event (tricks Ink into full redraw) + // 2. Remounting components via state changes + process.stdout.emit('resize'); + + // Give a tick for resize to process, then trigger remount + setImmediate(() => { + refreshStatic(); + setForceRerenderKey((prev) => prev + 1); + }); + } finally { + if (onResumeHandlerRef.current === onResume) { + onResumeHandlerRef.current = null; + } + } + }; + + if (onResumeHandlerRef.current) { + process.off('SIGCONT', onResumeHandlerRef.current); + } + onResumeHandlerRef.current = onResume; + process.once('SIGCONT', onResume); + + process.kill(0, 'SIGTSTP'); + } else if (ctrlZPressCount > 0) { + handleWarning( + 'Press Ctrl+Z again to suspend. Undo has moved to Cmd + Z or Alt/Opt + Z.', + ); + ctrlZTimerRef.current = setTimeout(() => { + setCtrlZPressCount(0); + ctrlZTimerRef.current = null; + }, WARNING_PROMPT_DURATION_MS); + } + }, [ + ctrlZPressCount, + handleWarning, + setRawMode, + refreshStatic, + setForceRerenderKey, + shouldUseAlternateScreen, + ]); + + const handleSuspend = useCallback(() => { + setCtrlZPressCount((prev) => prev + 1); + }, []); + + return { handleSuspend }; +} diff --git a/packages/cli/src/ui/keyMatchers.test.ts b/packages/cli/src/ui/keyMatchers.test.ts index 3b7c14d896..a014d2bdc1 100644 --- a/packages/cli/src/ui/keyMatchers.test.ts +++ b/packages/cli/src/ui/keyMatchers.test.ts @@ -330,6 +330,18 @@ describe('keyMatchers', () => { positive: [createKey('d', { ctrl: true })], negative: [createKey('d'), createKey('c', { ctrl: true })], }, + { + command: Command.SUSPEND_APP, + positive: [ + createKey('z', { ctrl: true }), + createKey('z', { ctrl: true, shift: true }), + ], + negative: [ + createKey('z'), + createKey('y', { ctrl: true }), + createKey('z', { alt: true }), + ], + }, { command: Command.SHOW_MORE_LINES, positive: [ diff --git a/packages/cli/src/ui/utils/terminalCapabilityManager.ts b/packages/cli/src/ui/utils/terminalCapabilityManager.ts index 94e3ecb8ff..8fa2146072 100644 --- a/packages/cli/src/ui/utils/terminalCapabilityManager.ts +++ b/packages/cli/src/ui/utils/terminalCapabilityManager.ts @@ -18,6 +18,23 @@ import { parseColor } from '../themes/color-utils.js'; export type TerminalBackgroundColor = string | undefined; +const TERMINAL_CLEANUP_SEQUENCE = '\x1b[4;0m\x1b[?2004l'; + +export function cleanupTerminalOnExit() { + try { + if (process.stdout?.fd !== undefined) { + fs.writeSync(process.stdout.fd, TERMINAL_CLEANUP_SEQUENCE); + return; + } + } catch (e) { + debugLogger.warn('Failed to synchronously cleanup terminal modes:', e); + } + + disableKittyKeyboardProtocol(); + disableModifyOtherKeys(); + disableBracketedPasteMode(); +} + export class TerminalCapabilityManager { private static instance: TerminalCapabilityManager | undefined; @@ -64,14 +81,6 @@ export class TerminalCapabilityManager { this.instance = undefined; } - private static cleanupOnExit(): void { - // don't bother catching errors since if one write - // fails, the other probably will too - disableKittyKeyboardProtocol(); - disableModifyOtherKeys(); - disableBracketedPasteMode(); - } - /** * Detects terminal capabilities (Kitty protocol support, terminal name, * background color). @@ -85,12 +94,12 @@ export class TerminalCapabilityManager { return; } - process.off('exit', TerminalCapabilityManager.cleanupOnExit); - process.off('SIGTERM', TerminalCapabilityManager.cleanupOnExit); - process.off('SIGINT', TerminalCapabilityManager.cleanupOnExit); - process.on('exit', TerminalCapabilityManager.cleanupOnExit); - process.on('SIGTERM', TerminalCapabilityManager.cleanupOnExit); - process.on('SIGINT', TerminalCapabilityManager.cleanupOnExit); + process.off('exit', cleanupTerminalOnExit); + process.off('SIGTERM', cleanupTerminalOnExit); + process.off('SIGINT', cleanupTerminalOnExit); + process.on('exit', cleanupTerminalOnExit); + process.on('SIGTERM', cleanupTerminalOnExit); + process.on('SIGINT', cleanupTerminalOnExit); return new Promise((resolve) => { const originalRawMode = process.stdin.isRaw; From 2d38623472284a5bf7ef7f644ef8eccb2e7dd2fd Mon Sep 17 00:00:00 2001 From: Sandy Tao Date: Thu, 12 Feb 2026 10:01:04 -0800 Subject: [PATCH 22/44] fix(github-actions): use robot PAT for release creation to trigger release notes (#18794) --- .github/actions/publish-release/action.yml | 5 ++++- .github/workflows/release-manual.yml | 1 + .github/workflows/release-nightly.yml | 3 ++- .github/workflows/release-patch-3-release.yml | 1 + .github/workflows/release-promote.yml | 4 +++- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/actions/publish-release/action.yml b/.github/actions/publish-release/action.yml index c37444498a..5c74524ddb 100644 --- a/.github/actions/publish-release/action.yml +++ b/.github/actions/publish-release/action.yml @@ -20,6 +20,9 @@ inputs: github-token: description: 'The GitHub token for creating the release.' required: true + github-release-token: + description: 'The GitHub token used specifically for creating the GitHub release (to trigger other workflows).' + required: false dry-run: description: 'Whether to run in dry-run mode.' type: 'string' @@ -254,7 +257,7 @@ runs: working-directory: '${{ inputs.working-directory }}' if: "${{ inputs.dry-run != 'true' && inputs.skip-github-release != 'true' && inputs.npm-tag != 'dev' && inputs.npm-registry-url != 'https://npm.pkg.github.com/' }}" env: - GITHUB_TOKEN: '${{ inputs.github-token }}' + GITHUB_TOKEN: '${{ inputs.github-release-token || inputs.github-token }}' shell: 'bash' run: | gh release create "${{ inputs.release-tag }}" \ diff --git a/.github/workflows/release-manual.yml b/.github/workflows/release-manual.yml index b393d87ea9..c9d2290a1c 100644 --- a/.github/workflows/release-manual.yml +++ b/.github/workflows/release-manual.yml @@ -110,6 +110,7 @@ jobs: wombat-token-cli: '${{ secrets.WOMBAT_TOKEN_CLI }}' wombat-token-a2a-server: '${{ secrets.WOMBAT_TOKEN_A2A_SERVER }}' github-token: '${{ secrets.GITHUB_TOKEN }}' + github-release-token: '${{ secrets.GEMINI_CLI_ROBOT_GITHUB_PAT }}' dry-run: '${{ github.event.inputs.dry_run }}' previous-tag: '${{ steps.release_info.outputs.PREVIOUS_TAG }}' skip-github-release: '${{ github.event.inputs.skip_github_release }}' diff --git a/.github/workflows/release-nightly.yml b/.github/workflows/release-nightly.yml index 5fe7bca115..0a04e93517 100644 --- a/.github/workflows/release-nightly.yml +++ b/.github/workflows/release-nightly.yml @@ -124,6 +124,7 @@ jobs: wombat-token-cli: '${{ secrets.WOMBAT_TOKEN_CLI }}' wombat-token-a2a-server: '${{ secrets.WOMBAT_TOKEN_A2A_SERVER }}' github-token: '${{ secrets.GITHUB_TOKEN }}' + github-release-token: '${{ secrets.GEMINI_CLI_ROBOT_GITHUB_PAT }}' dry-run: '${{ steps.vars.outputs.is_dry_run }}' previous-tag: '${{ steps.nightly_version.outputs.PREVIOUS_TAG }}' working-directory: './release' @@ -144,7 +145,7 @@ jobs: branch-name: 'release/${{ steps.nightly_version.outputs.RELEASE_TAG }}' pr-title: 'chore/release: bump version to ${{ steps.nightly_version.outputs.RELEASE_VERSION }}' pr-body: 'Automated version bump for nightly release.' - github-token: '${{ secrets.GEMINI_CLI_ROBOT_GITHUB_PAT }}' + github-token: '${{ secrets.GITHUB_TOKEN }}' dry-run: '${{ steps.vars.outputs.is_dry_run }}' working-directory: './release' diff --git a/.github/workflows/release-patch-3-release.yml b/.github/workflows/release-patch-3-release.yml index 19241b7396..b0d459f256 100644 --- a/.github/workflows/release-patch-3-release.yml +++ b/.github/workflows/release-patch-3-release.yml @@ -184,6 +184,7 @@ jobs: wombat-token-cli: '${{ secrets.WOMBAT_TOKEN_CLI }}' wombat-token-a2a-server: '${{ secrets.WOMBAT_TOKEN_A2A_SERVER }}' github-token: '${{ secrets.GITHUB_TOKEN }}' + github-release-token: '${{ secrets.GEMINI_CLI_ROBOT_GITHUB_PAT }}' dry-run: '${{ github.event.inputs.dry_run }}' previous-tag: '${{ steps.patch_version.outputs.PREVIOUS_TAG }}' gemini_api_key: '${{ secrets.GEMINI_API_KEY }}' diff --git a/.github/workflows/release-promote.yml b/.github/workflows/release-promote.yml index 486b9a2558..ebe16b1a39 100644 --- a/.github/workflows/release-promote.yml +++ b/.github/workflows/release-promote.yml @@ -239,6 +239,7 @@ jobs: wombat-token-cli: '${{ secrets.WOMBAT_TOKEN_CLI }}' wombat-token-a2a-server: '${{ secrets.WOMBAT_TOKEN_A2A_SERVER }}' github-token: '${{ secrets.GITHUB_TOKEN }}' + github-release-token: '${{ secrets.GEMINI_CLI_ROBOT_GITHUB_PAT }}' dry-run: '${{ github.event.inputs.dry_run }}' previous-tag: '${{ needs.calculate-versions.outputs.PREVIOUS_PREVIEW_TAG }}' working-directory: './release' @@ -305,6 +306,7 @@ jobs: wombat-token-cli: '${{ secrets.WOMBAT_TOKEN_CLI }}' wombat-token-a2a-server: '${{ secrets.WOMBAT_TOKEN_A2A_SERVER }}' github-token: '${{ secrets.GITHUB_TOKEN }}' + github-release-token: '${{ secrets.GEMINI_CLI_ROBOT_GITHUB_PAT }}' dry-run: '${{ github.event.inputs.dry_run }}' previous-tag: '${{ needs.calculate-versions.outputs.PREVIOUS_STABLE_TAG }}' working-directory: './release' @@ -390,7 +392,7 @@ jobs: branch-name: '${{ steps.release_branch.outputs.BRANCH_NAME }}' pr-title: 'chore(release): bump version to ${{ needs.calculate-versions.outputs.NEXT_NIGHTLY_VERSION }}' pr-body: 'Automated version bump to prepare for the next nightly release.' - github-token: '${{ secrets.GEMINI_CLI_ROBOT_GITHUB_PAT }}' + github-token: '${{ secrets.GITHUB_TOKEN }}' dry-run: '${{ github.event.inputs.dry_run }}' - name: 'Create Issue on Failure' From 2e91c03e08f485c21c0d991cead81436ae8635b9 Mon Sep 17 00:00:00 2001 From: Sandy Tao Date: Thu, 12 Feb 2026 10:33:54 -0800 Subject: [PATCH 23/44] feat: add strict seatbelt profiles and remove unusable closed profiles (#18876) --- CONTRIBUTING.md | 13 +- docs/cli/sandbox.md | 5 +- docs/get-started/configuration.md | 5 +- .../utils/sandbox-macos-permissive-closed.sb | 32 ----- ...closed.sb => sandbox-macos-strict-open.sb} | 46 +++++- .../src/utils/sandbox-macos-strict-proxied.sb | 133 ++++++++++++++++++ packages/cli/src/utils/sandboxUtils.ts | 4 +- packages/core/src/config/config.ts | 3 +- 8 files changed, 193 insertions(+), 48 deletions(-) delete mode 100644 packages/cli/src/utils/sandbox-macos-permissive-closed.sb rename packages/cli/src/utils/{sandbox-macos-restrictive-closed.sb => sandbox-macos-strict-open.sb} (64%) create mode 100644 packages/cli/src/utils/sandbox-macos-strict-proxied.sb diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e3ff7505c7..6d8252f86c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -408,12 +408,13 @@ On macOS, `gemini` uses Seatbelt (`sandbox-exec`) under a `permissive-open` profile (see `packages/cli/src/utils/sandbox-macos-permissive-open.sb`) that restricts writes to the project folder but otherwise allows all other operations and outbound network traffic ("open") by default. You can switch to a -`restrictive-closed` profile (see -`packages/cli/src/utils/sandbox-macos-restrictive-closed.sb`) that declines all -operations and outbound network traffic ("closed") by default by setting -`SEATBELT_PROFILE=restrictive-closed` in your environment or `.env` file. -Available built-in profiles are `{permissive,restrictive}-{open,closed,proxied}` -(see below for proxied networking). You can also switch to a custom profile +`strict-open` profile (see +`packages/cli/src/utils/sandbox-macos-strict-open.sb`) that restricts both reads +and writes to the working directory while allowing outbound network traffic by +setting `SEATBELT_PROFILE=strict-open` in your environment or `.env` file. +Available built-in profiles are `permissive-{open,proxied}`, +`restrictive-{open,proxied}`, and `strict-{open,proxied}` (see below for proxied +networking). You can also switch to a custom profile `SEATBELT_PROFILE=` if you also create a file `.gemini/sandbox-macos-.sb` under your project settings directory `.gemini`. diff --git a/docs/cli/sandbox.md b/docs/cli/sandbox.md index 28b54851c2..9f632693c7 100644 --- a/docs/cli/sandbox.md +++ b/docs/cli/sandbox.md @@ -82,10 +82,11 @@ gemini -p "run the test suite" Built-in profiles (set via `SEATBELT_PROFILE` env var): - `permissive-open` (default): Write restrictions, network allowed -- `permissive-closed`: Write restrictions, no network - `permissive-proxied`: Write restrictions, network via proxy - `restrictive-open`: Strict restrictions, network allowed -- `restrictive-closed`: Maximum restrictions +- `restrictive-proxied`: Strict restrictions, network via proxy +- `strict-open`: Read and write restrictions, network allowed +- `strict-proxied`: Read and write restrictions, network via proxy ### Custom sandbox flags diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 263dd815a8..32c0bf30b1 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -1290,7 +1290,10 @@ the `advanced.excludedEnvVars` setting in your `settings.json` file. 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. + - `restrictive-open`: Declines operations by default, allows network. + - `strict-open`: Restricts both reads and writes to the working directory, + allows network. + - `strict-proxied`: Same as `strict-open` but routes network through proxy. - ``: 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`). diff --git a/packages/cli/src/utils/sandbox-macos-permissive-closed.sb b/packages/cli/src/utils/sandbox-macos-permissive-closed.sb deleted file mode 100644 index cf64da9450..0000000000 --- a/packages/cli/src/utils/sandbox-macos-permissive-closed.sb +++ /dev/null @@ -1,32 +0,0 @@ -(version 1) - -;; allow everything by default -(allow default) - -;; deny all writes EXCEPT under specific paths -(deny file-write*) -(allow file-write* - (subpath (param "TARGET_DIR")) - (subpath (param "TMP_DIR")) - (subpath (param "CACHE_DIR")) - (subpath (string-append (param "HOME_DIR") "/.gemini")) - (subpath (string-append (param "HOME_DIR") "/.npm")) - (subpath (string-append (param "HOME_DIR") "/.cache")) - (subpath (string-append (param "HOME_DIR") "/.gitconfig")) - ;; Allow writes to included directories from --include-directories - (subpath (param "INCLUDE_DIR_0")) - (subpath (param "INCLUDE_DIR_1")) - (subpath (param "INCLUDE_DIR_2")) - (subpath (param "INCLUDE_DIR_3")) - (subpath (param "INCLUDE_DIR_4")) - (literal "/dev/stdout") - (literal "/dev/stderr") - (literal "/dev/null") -) - -;; deny all inbound network traffic EXCEPT on debugger port -(deny network-inbound) -(allow network-inbound (local ip "localhost:9229")) - -;; deny all outbound network traffic -(deny network-outbound) diff --git a/packages/cli/src/utils/sandbox-macos-restrictive-closed.sb b/packages/cli/src/utils/sandbox-macos-strict-open.sb similarity index 64% rename from packages/cli/src/utils/sandbox-macos-restrictive-closed.sb rename to packages/cli/src/utils/sandbox-macos-strict-open.sb index 17d0c07320..e5cbd1b334 100644 --- a/packages/cli/src/utils/sandbox-macos-restrictive-closed.sb +++ b/packages/cli/src/utils/sandbox-macos-strict-open.sb @@ -3,8 +3,43 @@ ;; deny everything by default (deny default) -;; allow reading files from anywhere on host -(allow file-read*) +;; allow reading ONLY from working directory, system paths, and essential user paths +(allow file-read* + (literal "/") + (subpath (param "TARGET_DIR")) + (subpath (param "TMP_DIR")) + (subpath (param "CACHE_DIR")) + ;; Only allow reading essential dotfiles/directories under HOME, not the entire HOME + (subpath (string-append (param "HOME_DIR") "/.gemini")) + (subpath (string-append (param "HOME_DIR") "/.npm")) + (subpath (string-append (param "HOME_DIR") "/.cache")) + (literal (string-append (param "HOME_DIR") "/.gitconfig")) + (subpath (string-append (param "HOME_DIR") "/.nvm")) + (subpath (string-append (param "HOME_DIR") "/.fnm")) + (subpath (string-append (param "HOME_DIR") "/.node")) + (subpath (string-append (param "HOME_DIR") "/.config")) + ;; Allow reads from included directories + (subpath (param "INCLUDE_DIR_0")) + (subpath (param "INCLUDE_DIR_1")) + (subpath (param "INCLUDE_DIR_2")) + (subpath (param "INCLUDE_DIR_3")) + (subpath (param "INCLUDE_DIR_4")) + ;; System paths required for Node.js, shell, and common tools + (subpath "/usr") + (subpath "/bin") + (subpath "/sbin") + (subpath "/Library") + (subpath "/System") + (subpath "/private") + (subpath "/dev") + (subpath "/etc") + (subpath "/opt") + (subpath "/Applications") +) + +;; allow path traversal everywhere (metadata only: stat/lstat, NOT readdir or file content) +;; this is needed for Node.js module resolution to traverse intermediate directories +(allow file-read-metadata) ;; allow exec/fork (children inherit policy) (allow process-exec) @@ -70,7 +105,7 @@ (subpath (string-append (param "HOME_DIR") "/.gemini")) (subpath (string-append (param "HOME_DIR") "/.npm")) (subpath (string-append (param "HOME_DIR") "/.cache")) - (subpath (string-append (param "HOME_DIR") "/.gitconfig")) + (literal (string-append (param "HOME_DIR") "/.gitconfig")) ;; Allow writes to included directories from --include-directories (subpath (param "INCLUDE_DIR_0")) (subpath (param "INCLUDE_DIR_1")) @@ -90,4 +125,7 @@ (allow file-ioctl (regex #"^/dev/tty.*")) ;; allow inbound network traffic on debugger port -(allow network-inbound (local ip "localhost:9229")) \ No newline at end of file +(allow network-inbound (local ip "localhost:9229")) + +;; allow all outbound network traffic +(allow network-outbound) diff --git a/packages/cli/src/utils/sandbox-macos-strict-proxied.sb b/packages/cli/src/utils/sandbox-macos-strict-proxied.sb new file mode 100644 index 0000000000..53b102f43e --- /dev/null +++ b/packages/cli/src/utils/sandbox-macos-strict-proxied.sb @@ -0,0 +1,133 @@ +(version 1) + +;; deny everything by default +(deny default) + +;; allow reading ONLY from working directory, system paths, and essential user paths +(allow file-read* + (literal "/") + (subpath (param "TARGET_DIR")) + (subpath (param "TMP_DIR")) + (subpath (param "CACHE_DIR")) + ;; Only allow reading essential dotfiles/directories under HOME, not the entire HOME + (subpath (string-append (param "HOME_DIR") "/.gemini")) + (subpath (string-append (param "HOME_DIR") "/.npm")) + (subpath (string-append (param "HOME_DIR") "/.cache")) + (literal (string-append (param "HOME_DIR") "/.gitconfig")) + (subpath (string-append (param "HOME_DIR") "/.nvm")) + (subpath (string-append (param "HOME_DIR") "/.fnm")) + (subpath (string-append (param "HOME_DIR") "/.node")) + (subpath (string-append (param "HOME_DIR") "/.config")) + ;; Allow reads from included directories + (subpath (param "INCLUDE_DIR_0")) + (subpath (param "INCLUDE_DIR_1")) + (subpath (param "INCLUDE_DIR_2")) + (subpath (param "INCLUDE_DIR_3")) + (subpath (param "INCLUDE_DIR_4")) + ;; System paths required for Node.js, shell, and common tools + (subpath "/usr") + (subpath "/bin") + (subpath "/sbin") + (subpath "/Library") + (subpath "/System") + (subpath "/private") + (subpath "/dev") + (subpath "/etc") + (subpath "/opt") + (subpath "/Applications") +) + +;; allow path traversal everywhere (metadata only: stat/lstat, NOT readdir or file content) +;; this is needed for Node.js module resolution to traverse intermediate directories +(allow file-read-metadata) + +;; allow exec/fork (children inherit policy) +(allow process-exec) +(allow process-fork) + +;; allow signals to self, e.g. SIGPIPE on write to closed pipe +(allow signal (target self)) + +;; allow read access to specific information about system +;; from https://source.chromium.org/chromium/chromium/src/+/main:sandbox/policy/mac/common.sb;l=273-319;drc=7b3962fe2e5fc9e2ee58000dc8fbf3429d84d3bd +(allow sysctl-read + (sysctl-name "hw.activecpu") + (sysctl-name "hw.busfrequency_compat") + (sysctl-name "hw.byteorder") + (sysctl-name "hw.cacheconfig") + (sysctl-name "hw.cachelinesize_compat") + (sysctl-name "hw.cpufamily") + (sysctl-name "hw.cpufrequency_compat") + (sysctl-name "hw.cputype") + (sysctl-name "hw.l1dcachesize_compat") + (sysctl-name "hw.l1icachesize_compat") + (sysctl-name "hw.l2cachesize_compat") + (sysctl-name "hw.l3cachesize_compat") + (sysctl-name "hw.logicalcpu_max") + (sysctl-name "hw.machine") + (sysctl-name "hw.ncpu") + (sysctl-name "hw.nperflevels") + (sysctl-name "hw.optional.arm.FEAT_BF16") + (sysctl-name "hw.optional.arm.FEAT_DotProd") + (sysctl-name "hw.optional.arm.FEAT_FCMA") + (sysctl-name "hw.optional.arm.FEAT_FHM") + (sysctl-name "hw.optional.arm.FEAT_FP16") + (sysctl-name "hw.optional.arm.FEAT_I8MM") + (sysctl-name "hw.optional.arm.FEAT_JSCVT") + (sysctl-name "hw.optional.arm.FEAT_LSE") + (sysctl-name "hw.optional.arm.FEAT_RDM") + (sysctl-name "hw.optional.arm.FEAT_SHA512") + (sysctl-name "hw.optional.armv8_2_sha512") + (sysctl-name "hw.packages") + (sysctl-name "hw.pagesize_compat") + (sysctl-name "hw.physicalcpu_max") + (sysctl-name "hw.tbfrequency_compat") + (sysctl-name "hw.vectorunit") + (sysctl-name "kern.hostname") + (sysctl-name "kern.maxfilesperproc") + (sysctl-name "kern.osproductversion") + (sysctl-name "kern.osrelease") + (sysctl-name "kern.ostype") + (sysctl-name "kern.osvariant_status") + (sysctl-name "kern.osversion") + (sysctl-name "kern.secure_kernel") + (sysctl-name "kern.usrstack64") + (sysctl-name "kern.version") + (sysctl-name "sysctl.proc_cputype") + (sysctl-name-prefix "hw.perflevel") +) + +;; allow writes to specific paths +(allow file-write* + (subpath (param "TARGET_DIR")) + (subpath (param "TMP_DIR")) + (subpath (param "CACHE_DIR")) + (subpath (string-append (param "HOME_DIR") "/.gemini")) + (subpath (string-append (param "HOME_DIR") "/.npm")) + (subpath (string-append (param "HOME_DIR") "/.cache")) + (literal (string-append (param "HOME_DIR") "/.gitconfig")) + ;; Allow writes to included directories from --include-directories + (subpath (param "INCLUDE_DIR_0")) + (subpath (param "INCLUDE_DIR_1")) + (subpath (param "INCLUDE_DIR_2")) + (subpath (param "INCLUDE_DIR_3")) + (subpath (param "INCLUDE_DIR_4")) + (literal "/dev/stdout") + (literal "/dev/stderr") + (literal "/dev/null") +) + +;; allow communication with sysmond for process listing (e.g. for pgrep) +(allow mach-lookup (global-name "com.apple.sysmond")) + +;; enable terminal access required by ink +;; fixes setRawMode EPERM failure (at node:tty:81:24) +(allow file-ioctl (regex #"^/dev/tty.*")) + +;; allow inbound network traffic on debugger port +(allow network-inbound (local ip "localhost:9229")) + +;; allow outbound network traffic through proxy on localhost:8877 +;; set `GEMINI_SANDBOX_PROXY_COMMAND=` to run proxy alongside sandbox +;; proxy must listen on :::8877 (see docs/examples/proxy-script.md) +(allow network-outbound (remote tcp "localhost:8877")) diff --git a/packages/cli/src/utils/sandboxUtils.ts b/packages/cli/src/utils/sandboxUtils.ts index 48cfb30f00..b33a1af3a3 100644 --- a/packages/cli/src/utils/sandboxUtils.ts +++ b/packages/cli/src/utils/sandboxUtils.ts @@ -15,11 +15,11 @@ export const SANDBOX_NETWORK_NAME = 'gemini-cli-sandbox'; export const SANDBOX_PROXY_NAME = 'gemini-cli-sandbox-proxy'; export const BUILTIN_SEATBELT_PROFILES = [ 'permissive-open', - 'permissive-closed', 'permissive-proxied', 'restrictive-open', - 'restrictive-closed', 'restrictive-proxied', + 'strict-open', + 'strict-proxied', ]; export function getContainerPath(hostPath: string): string { diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 944d14fb39..8aab58da08 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -1343,7 +1343,8 @@ export class Config { !!sandboxConfig && sandboxConfig.command === 'sandbox-exec' && !!seatbeltProfile && - seatbeltProfile.startsWith('restrictive-') + (seatbeltProfile.startsWith('restrictive-') || + seatbeltProfile.startsWith('strict-')) ); } From d243dfce142dcf252118f529817040f94cc72712 Mon Sep 17 00:00:00 2001 From: Adam Weidman <65992621+adamfweidman@users.noreply.github.com> Date: Thu, 12 Feb 2026 13:40:52 -0500 Subject: [PATCH 24/44] chore: cleanup unused and add unlisted dependencies in packages/a2a-server (#18916) --- package-lock.json | 2 ++ packages/a2a-server/package.json | 2 ++ 2 files changed, 4 insertions(+) diff --git a/package-lock.json b/package-lock.json index e8bb6e6902..c457eb7d55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17245,6 +17245,7 @@ "@google/gemini-cli-core": "file:../core", "express": "^5.1.0", "fs-extra": "^11.3.0", + "strip-json-comments": "^3.1.1", "tar": "^7.5.2", "uuid": "^13.0.0", "winston": "^3.17.0" @@ -17253,6 +17254,7 @@ "gemini-cli-a2a-server": "dist/a2a-server.mjs" }, "devDependencies": { + "@google/genai": "^1.30.0", "@types/express": "^5.0.3", "@types/fs-extra": "^11.0.4", "@types/supertest": "^6.0.3", diff --git a/packages/a2a-server/package.json b/packages/a2a-server/package.json index 774b2f5c83..96001898a0 100644 --- a/packages/a2a-server/package.json +++ b/packages/a2a-server/package.json @@ -30,11 +30,13 @@ "@google/gemini-cli-core": "file:../core", "express": "^5.1.0", "fs-extra": "^11.3.0", + "strip-json-comments": "^3.1.1", "tar": "^7.5.2", "uuid": "^13.0.0", "winston": "^3.17.0" }, "devDependencies": { + "@google/genai": "^1.30.0", "@types/express": "^5.0.3", "@types/fs-extra": "^11.0.4", "@types/supertest": "^6.0.3", From 0b3130cec7efd70b32806e2c7dfc86c0ca7ea83d Mon Sep 17 00:00:00 2001 From: Adib234 <30782825+Adib234@users.noreply.github.com> Date: Thu, 12 Feb 2026 14:02:59 -0500 Subject: [PATCH 25/44] fix(plan): isolate plan files per session (#18757) --- docs/cli/plan-mode.md | 2 +- .../src/config/policy-engine.integration.test.ts | 7 +++---- packages/core/src/config/config.ts | 2 +- packages/core/src/config/storage.test.ts | 14 +++++++++++++- packages/core/src/config/storage.ts | 14 +++++++++++++- packages/core/src/policy/policies/plan.toml | 2 +- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/docs/cli/plan-mode.md b/docs/cli/plan-mode.md index 751794996b..1e88560f7a 100644 --- a/docs/cli/plan-mode.md +++ b/docs/cli/plan-mode.md @@ -99,7 +99,7 @@ These are the only allowed tools: - **MCP Tools (Read):** Read-only [MCP tools] (e.g., `github_read_issue`, `postgres_read_schema`) are allowed. - **Planning (Write):** [`write_file`] and [`replace`] ONLY allowed for `.md` - files in the `~/.gemini/tmp//plans/` directory. + files in the `~/.gemini/tmp///plans/` directory. - **Skills:** [`activate_skill`] (allows loading specialized instructions and resources in a read-only manner) diff --git a/packages/cli/src/config/policy-engine.integration.test.ts b/packages/cli/src/config/policy-engine.integration.test.ts index 0568aa62bc..2c7ce599da 100644 --- a/packages/cli/src/config/policy-engine.integration.test.ts +++ b/packages/cli/src/config/policy-engine.integration.test.ts @@ -336,9 +336,9 @@ describe('Policy Engine Integration Tests', () => { // Valid plan file paths const validPaths = [ - '/home/user/.gemini/tmp/a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2/plans/my-plan.md', - '/home/user/.gemini/tmp/a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2/plans/feature_auth.md', - '/home/user/.gemini/tmp/new-temp_dir_123/plans/plan.md', // new style of temp directory + '/home/user/.gemini/tmp/a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2/session-1/plans/my-plan.md', + '/home/user/.gemini/tmp/a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2/session-1/plans/feature_auth.md', + '/home/user/.gemini/tmp/new-temp_dir_123/session-1/plans/plan.md', // new style of temp directory ]; for (const file_path of validPaths) { @@ -365,7 +365,6 @@ describe('Policy Engine Integration Tests', () => { '/project/src/file.ts', // Workspace '/home/user/.gemini/tmp/a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2/plans/script.js', // Wrong extension '/home/user/.gemini/tmp/a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2/plans/../../../etc/passwd.md', // Path traversal - '/home/user/.gemini/tmp/a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2/plans/subdir/plan.md', // Subdirectory '/home/user/.gemini/non-tmp/new-temp_dir_123/plans/plan.md', // outside of temp dir ]; diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 8aab58da08..6dfc62f322 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -823,7 +823,7 @@ export class Config { (params.shellToolInactivityTimeout ?? 300) * 1000; // 5 minutes this.extensionManagement = params.extensionManagement ?? true; this.enableExtensionReloading = params.enableExtensionReloading ?? false; - this.storage = new Storage(this.targetDir); + this.storage = new Storage(this.targetDir, this.sessionId); this.fakeResponses = params.fakeResponses; this.recordResponses = params.recordResponses; diff --git a/packages/core/src/config/storage.test.ts b/packages/core/src/config/storage.test.ts index 8232033c07..8d91ca1a3e 100644 --- a/packages/core/src/config/storage.test.ts +++ b/packages/core/src/config/storage.test.ts @@ -154,12 +154,24 @@ describe('Storage – additional helpers', () => { expect(Storage.getGlobalBinDir()).toBe(expected); }); - it('getProjectTempPlansDir returns ~/.gemini/tmp//plans', async () => { + it('getProjectTempPlansDir returns ~/.gemini/tmp//plans when no sessionId is provided', async () => { await storage.initialize(); const tempDir = storage.getProjectTempDir(); const expected = path.join(tempDir, 'plans'); expect(storage.getProjectTempPlansDir()).toBe(expected); }); + + it('getProjectTempPlansDir returns ~/.gemini/tmp///plans when sessionId is provided', async () => { + const sessionId = 'test-session-id'; + const storageWithSession = new Storage(projectRoot, sessionId); + ProjectRegistry.prototype.getShortId = vi + .fn() + .mockReturnValue(PROJECT_SLUG); + await storageWithSession.initialize(); + const tempDir = storageWithSession.getProjectTempDir(); + const expected = path.join(tempDir, sessionId, 'plans'); + expect(storageWithSession.getProjectTempPlansDir()).toBe(expected); + }); }); describe('Storage - System Paths', () => { diff --git a/packages/core/src/config/storage.ts b/packages/core/src/config/storage.ts index f407c29539..bd0fec1c8e 100644 --- a/packages/core/src/config/storage.ts +++ b/packages/core/src/config/storage.ts @@ -20,11 +20,13 @@ const AGENTS_DIR_NAME = '.agents'; export class Storage { private readonly targetDir: string; + private readonly sessionId: string | undefined; private projectIdentifier: string | undefined; private initPromise: Promise | undefined; - constructor(targetDir: string) { + constructor(targetDir: string, sessionId?: string) { this.targetDir = targetDir; + this.sessionId = sessionId; } static getGlobalGeminiDir(): string { @@ -242,9 +244,19 @@ export class Storage { } getProjectTempPlansDir(): string { + if (this.sessionId) { + return path.join(this.getProjectTempDir(), this.sessionId, 'plans'); + } return path.join(this.getProjectTempDir(), 'plans'); } + getProjectTempTasksDir(): string { + if (this.sessionId) { + return path.join(this.getProjectTempDir(), this.sessionId, 'tasks'); + } + return path.join(this.getProjectTempDir(), 'tasks'); + } + getExtensionsDir(): string { return path.join(this.getGeminiDir(), 'extensions'); } diff --git a/packages/core/src/policy/policies/plan.toml b/packages/core/src/policy/policies/plan.toml index 656c100845..12648fec5f 100644 --- a/packages/core/src/policy/policies/plan.toml +++ b/packages/core/src/policy/policies/plan.toml @@ -53,4 +53,4 @@ toolName = ["write_file", "replace"] decision = "allow" priority = 70 modes = ["plan"] -argsPattern = "\"file_path\":\"[^\"]+/\\.gemini/tmp/[a-zA-Z0-9_-]+/plans/[a-zA-Z0-9_-]+\\.md\"" +argsPattern = "\"file_path\":\"[^\"]+/\\.gemini/tmp/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+/plans/[a-zA-Z0-9_-]+\\.md\"" From b0cfbc6cd8546dfcf18087068811d1fce1329c2d Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Thu, 12 Feb 2026 14:16:56 -0500 Subject: [PATCH 26/44] fix: character truncation in raw markdown mode (#18938) --- .../components/messages/GeminiMessage.test.tsx | 17 +++++++++++++++++ .../ui/components/messages/GeminiMessage.tsx | 2 +- .../messages/GeminiMessageContent.tsx | 2 +- .../__snapshots__/GeminiMessage.test.tsx.snap | 9 +++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/ui/components/messages/GeminiMessage.test.tsx b/packages/cli/src/ui/components/messages/GeminiMessage.test.tsx index 06a551554a..e8209d884d 100644 --- a/packages/cli/src/ui/components/messages/GeminiMessage.test.tsx +++ b/packages/cli/src/ui/components/messages/GeminiMessage.test.tsx @@ -46,4 +46,21 @@ describe(' - Raw Markdown Display Snapshots', () => { expect(lastFrame()).toMatchSnapshot(); }, ); + + it('wraps long lines correctly in raw markdown mode', () => { + const terminalWidth = 20; + const text = + 'This is a long line that should wrap correctly without truncation'; + const { lastFrame } = renderWithProviders( + , + { + uiState: { renderMarkdown: false, streamingState: StreamingState.Idle }, + }, + ); + expect(lastFrame()).toMatchSnapshot(); + }); }); diff --git a/packages/cli/src/ui/components/messages/GeminiMessage.tsx b/packages/cli/src/ui/components/messages/GeminiMessage.tsx index 95e392dab7..3c17a3850f 100644 --- a/packages/cli/src/ui/components/messages/GeminiMessage.tsx +++ b/packages/cli/src/ui/components/messages/GeminiMessage.tsx @@ -47,7 +47,7 @@ export const GeminiMessage: React.FC = ({ ? undefined : Math.max(availableTerminalHeight - 1, 1) } - terminalWidth={terminalWidth} + terminalWidth={Math.max(terminalWidth - prefixWidth, 0)} renderMarkdown={renderMarkdown} /> = ({ ? undefined : Math.max(availableTerminalHeight - 1, 1) } - terminalWidth={terminalWidth} + terminalWidth={Math.max(terminalWidth - prefixWidth, 0)} renderMarkdown={renderMarkdown} /> - Raw Markdown Display Snapshots > renders with rende 1 const x = 1; " `; + +exports[` - Raw Markdown Display Snapshots > wraps long lines correctly in raw markdown mode 1`] = ` +"✦ This is a long + line that should + wrap correctly + without + truncation +" +`; From db00c5abf388e07202af227ac77b31e07238b379 Mon Sep 17 00:00:00 2001 From: Dmitry Lyalin Date: Thu, 12 Feb 2026 14:25:24 -0500 Subject: [PATCH 27/44] feat(cli): prototype clean UI toggle and minimal-mode bleed-through (#18683) --- docs/cli/commands.md | 2 + docs/cli/keyboard-shortcuts.md | 9 +- packages/cli/src/config/keyBindings.ts | 4 +- packages/cli/src/test-utils/render.tsx | 5 + packages/cli/src/ui/App.test.tsx | 1 + packages/cli/src/ui/AppContainer.test.tsx | 34 ++- packages/cli/src/ui/AppContainer.tsx | 92 +++++- packages/cli/src/ui/components/AppHeader.tsx | 11 +- .../cli/src/ui/components/Composer.test.tsx | 227 +++++++++++++- packages/cli/src/ui/components/Composer.tsx | 286 +++++++++++++----- .../src/ui/components/InputPrompt.test.tsx | 106 ++++++- .../cli/src/ui/components/InputPrompt.tsx | 37 ++- .../src/ui/components/MainContent.test.tsx | 94 +++++- .../cli/src/ui/components/MainContent.tsx | 18 +- .../src/ui/components/ShortcutsHelp.test.tsx | 6 + .../cli/src/ui/components/ShortcutsHelp.tsx | 29 +- .../cli/src/ui/components/ShortcutsHint.tsx | 7 +- .../__snapshots__/MainContent.test.tsx.snap | 19 +- .../__snapshots__/ShortcutsHelp.test.tsx.snap | 28 +- .../cli/src/ui/contexts/UIActionsContext.tsx | 4 + .../cli/src/ui/contexts/UIStateContext.tsx | 1 + packages/cli/src/ui/keyMatchers.test.ts | 2 +- packages/cli/src/utils/persistentState.ts | 1 + 23 files changed, 872 insertions(+), 151 deletions(-) diff --git a/docs/cli/commands.md b/docs/cli/commands.md index 6e563cda11..c5e6b6747f 100644 --- a/docs/cli/commands.md +++ b/docs/cli/commands.md @@ -120,6 +120,8 @@ Slash commands provide meta-level control over the CLI itself. - **`/shortcuts`** - **Description:** Toggle the shortcuts panel above the input. - **Shortcut:** Press `?` when the prompt is empty. + - **Note:** This is separate from the clean UI detail toggle on double-`Tab`, + which switches between minimal and full UI chrome. - **`/hooks`** - **Description:** Manage hooks, which allow you to intercept and customize diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index 0dc32b7779..ffc0a39fda 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -114,8 +114,8 @@ available combinations. | Dismiss background shell list. | `Esc` | | Move focus from background shell to Gemini. | `Shift + Tab` | | Move focus from background shell list to Gemini. | `Tab (no Shift)` | -| Show warning when trying to unfocus background shell via Tab. | `Tab (no Shift)` | -| Show warning when trying to unfocus shell input via Tab. | `Tab (no Shift)` | +| Show warning when trying to move focus away from background shell. | `Tab (no Shift)` | +| Show warning when trying to move focus away from shell input. | `Tab (no Shift)` | | Move focus from Gemini to the active shell. | `Tab (no Shift)` | | Move focus from the shell back to Gemini. | `Shift + Tab` | | Clear the terminal screen and redraw the UI. | `Ctrl + L` | @@ -134,6 +134,11 @@ available combinations. The panel also auto-hides while the agent is running/streaming or when action-required dialogs are shown. Press `?` again to close the panel and insert a `?` into the prompt. +- `Tab` + `Tab` (while typing in the prompt): Toggle between minimal and full UI + details when no completion/search interaction is active. The selected mode is + remembered for future sessions. Full UI remains the default on first run, and + single `Tab` keeps its existing completion/focus behavior. +- `Shift + Tab` (while typing in the prompt): Cycle approval modes. - `\` (at end of a line) + `Enter`: Insert a newline without leaving single-line mode. - `Esc` pressed twice quickly: Clear the input prompt if it is not empty, diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index adf88d4d25..c3f1f70fbe 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -516,9 +516,9 @@ export const commandDescriptions: Readonly> = { [Command.UNFOCUS_BACKGROUND_SHELL_LIST]: 'Move focus from background shell list to Gemini.', [Command.SHOW_BACKGROUND_SHELL_UNFOCUS_WARNING]: - 'Show warning when trying to unfocus background shell via Tab.', + 'Show warning when trying to move focus away from background shell.', [Command.SHOW_SHELL_INPUT_UNFOCUS_WARNING]: - 'Show warning when trying to unfocus shell input via Tab.', + 'Show warning when trying to move focus away from shell input.', [Command.FOCUS_SHELL_INPUT]: 'Move focus from Gemini to the active shell.', [Command.UNFOCUS_SHELL_INPUT]: 'Move focus from the shell back to Gemini.', [Command.CLEAR_SCREEN]: 'Clear the terminal screen and redraw the UI.', diff --git a/packages/cli/src/test-utils/render.tsx b/packages/cli/src/test-utils/render.tsx index 0c8eac325e..10ad4281ef 100644 --- a/packages/cli/src/test-utils/render.tsx +++ b/packages/cli/src/test-utils/render.tsx @@ -150,6 +150,7 @@ const baseMockUiState = { terminalWidth: 120, terminalHeight: 40, currentModel: 'gemini-pro', + cleanUiDetailsVisible: false, terminalBackgroundColor: undefined, activePtyId: undefined, backgroundShells: new Map(), @@ -204,6 +205,10 @@ const mockUIActions: UIActions = { handleApiKeyCancel: vi.fn(), setBannerVisible: vi.fn(), setShortcutsHelpVisible: vi.fn(), + setCleanUiDetailsVisible: vi.fn(), + toggleCleanUiDetailsVisible: vi.fn(), + revealCleanUiDetailsTemporarily: vi.fn(), + handleWarning: vi.fn(), setEmbeddedShellFocused: vi.fn(), dismissBackgroundShell: vi.fn(), setActiveBackgroundShellPid: vi.fn(), diff --git a/packages/cli/src/ui/App.test.tsx b/packages/cli/src/ui/App.test.tsx index 7d817f44f5..475a04e18e 100644 --- a/packages/cli/src/ui/App.test.tsx +++ b/packages/cli/src/ui/App.test.tsx @@ -66,6 +66,7 @@ describe('App', () => { const mockUIState: Partial = { streamingState: StreamingState.Idle, + cleanUiDetailsVisible: true, quittingMessages: null, dialogsVisible: false, mainControlsRef: { diff --git a/packages/cli/src/ui/AppContainer.test.tsx b/packages/cli/src/ui/AppContainer.test.tsx index ff84834c69..028584537d 100644 --- a/packages/cli/src/ui/AppContainer.test.tsx +++ b/packages/cli/src/ui/AppContainer.test.tsx @@ -14,7 +14,7 @@ import { type Mock, type MockedObject, } from 'vitest'; -import { render } from '../test-utils/render.js'; +import { render, persistentStateMock } from '../test-utils/render.js'; import { waitFor } from '../test-utils/async.js'; import { cleanup } from 'ink-testing-library'; import { act, useContext, type ReactElement } from 'react'; @@ -299,6 +299,7 @@ describe('AppContainer State Management', () => { }; beforeEach(() => { + persistentStateMock.reset(); vi.clearAllMocks(); mockIdeClient.getInstance.mockReturnValue(new Promise(() => {})); @@ -488,6 +489,37 @@ describe('AppContainer State Management', () => { await waitFor(() => expect(capturedUIState).toBeTruthy()); unmount!(); }); + + it('shows full UI details by default', async () => { + let unmount: () => void; + await act(async () => { + const result = renderAppContainer(); + unmount = result.unmount; + }); + + await waitFor(() => { + expect(capturedUIState.cleanUiDetailsVisible).toBe(true); + }); + unmount!(); + }); + + it('starts in minimal UI mode when Focus UI preference is persisted', async () => { + persistentStateMock.get.mockReturnValueOnce(true); + + let unmount: () => void; + await act(async () => { + const result = renderAppContainer({ + settings: mockSettings, + }); + unmount = result.unmount; + }); + + await waitFor(() => { + expect(capturedUIState.cleanUiDetailsVisible).toBe(false); + }); + expect(persistentStateMock.get).toHaveBeenCalledWith('focusUiEnabled'); + unmount!(); + }); }); describe('State Initialization', () => { diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index a2f25a71de..4c590c21eb 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -49,6 +49,7 @@ import { type UserTierId, type UserFeedbackPayload, type AgentDefinition, + type ApprovalMode, IdeClient, ideContextStore, getErrorMessage, @@ -133,6 +134,7 @@ import { ShellFocusContext } from './contexts/ShellFocusContext.js'; import { type ExtensionManager } from '../config/extension-manager.js'; import { requestConsentInteractive } from '../config/extensions/consent.js'; import { useSessionBrowser } from './hooks/useSessionBrowser.js'; +import { persistentState } from '../utils/persistentState.js'; import { useSessionResume } from './hooks/useSessionResume.js'; import { useIncludeDirsTrust } from './hooks/useIncludeDirsTrust.js'; import { isWorkspaceTrusted } from '../config/trustedFolders.js'; @@ -184,6 +186,9 @@ interface AppContainerProps { resumedSessionData?: ResumedSessionData; } +const APPROVAL_MODE_REVEAL_DURATION_MS = 1200; +const FOCUS_UI_ENABLED_STATE_KEY = 'focusUiEnabled'; + /** * The fraction of the terminal width to allocate to the shell. * This provides horizontal padding. @@ -796,7 +801,65 @@ Logging in with Google... Restarting Gemini CLI to continue. const setIsBackgroundShellListOpenRef = useRef<(open: boolean) => void>( () => {}, ); + const [focusUiEnabledByDefault] = useState( + () => persistentState.get(FOCUS_UI_ENABLED_STATE_KEY) === true, + ); const [shortcutsHelpVisible, setShortcutsHelpVisible] = useState(false); + const [cleanUiDetailsVisible, setCleanUiDetailsVisibleState] = useState( + !focusUiEnabledByDefault, + ); + const modeRevealTimeoutRef = useRef(null); + const cleanUiDetailsPinnedRef = useRef(!focusUiEnabledByDefault); + + const clearModeRevealTimeout = useCallback(() => { + if (modeRevealTimeoutRef.current) { + clearTimeout(modeRevealTimeoutRef.current); + modeRevealTimeoutRef.current = null; + } + }, []); + + const persistFocusUiPreference = useCallback((isFullUiVisible: boolean) => { + persistentState.set(FOCUS_UI_ENABLED_STATE_KEY, !isFullUiVisible); + }, []); + + const setCleanUiDetailsVisible = useCallback( + (visible: boolean) => { + clearModeRevealTimeout(); + cleanUiDetailsPinnedRef.current = visible; + setCleanUiDetailsVisibleState(visible); + persistFocusUiPreference(visible); + }, + [clearModeRevealTimeout, persistFocusUiPreference], + ); + + const toggleCleanUiDetailsVisible = useCallback(() => { + clearModeRevealTimeout(); + setCleanUiDetailsVisibleState((visible) => { + const nextVisible = !visible; + cleanUiDetailsPinnedRef.current = nextVisible; + persistFocusUiPreference(nextVisible); + return nextVisible; + }); + }, [clearModeRevealTimeout, persistFocusUiPreference]); + + const revealCleanUiDetailsTemporarily = useCallback( + (durationMs: number = APPROVAL_MODE_REVEAL_DURATION_MS) => { + if (cleanUiDetailsPinnedRef.current) { + return; + } + clearModeRevealTimeout(); + setCleanUiDetailsVisibleState(true); + modeRevealTimeoutRef.current = setTimeout(() => { + if (!cleanUiDetailsPinnedRef.current) { + setCleanUiDetailsVisibleState(false); + } + modeRevealTimeoutRef.current = null; + }, durationMs); + }, + [clearModeRevealTimeout], + ); + + useEffect(() => () => clearModeRevealTimeout(), [clearModeRevealTimeout]); const slashCommandActions = useMemo( () => ({ @@ -1057,11 +1120,25 @@ Logging in with Google... Restarting Gemini CLI to continue. const shouldShowActionRequiredTitle = inactivityStatus === 'action_required'; const shouldShowSilentWorkingTitle = inactivityStatus === 'silent_working'; + const handleApprovalModeChangeWithUiReveal = useCallback( + (mode: ApprovalMode) => { + void handleApprovalModeChange(mode); + if (!cleanUiDetailsVisible) { + revealCleanUiDetailsTemporarily(APPROVAL_MODE_REVEAL_DURATION_MS); + } + }, + [ + handleApprovalModeChange, + cleanUiDetailsVisible, + revealCleanUiDetailsTemporarily, + ], + ); + // Auto-accept indicator const showApprovalModeIndicator = useApprovalModeIndicator({ config, addItem: historyManager.addItem, - onApprovalModeChange: handleApprovalModeChange, + onApprovalModeChange: handleApprovalModeChangeWithUiReveal, isActive: !embeddedShellFocused, }); @@ -1377,6 +1454,9 @@ Logging in with Google... Restarting Gemini CLI to continue. if (tabFocusTimeoutRef.current) { clearTimeout(tabFocusTimeoutRef.current); } + if (modeRevealTimeoutRef.current) { + clearTimeout(modeRevealTimeoutRef.current); + } }; }, [showTransientMessage]); @@ -1977,6 +2057,7 @@ Logging in with Google... Restarting Gemini CLI to continue. ctrlDPressedOnce: ctrlDPressCount >= 1, showEscapePrompt, shortcutsHelpVisible, + cleanUiDetailsVisible, isFocused, elapsedTime, currentLoadingPhrase, @@ -2087,6 +2168,7 @@ Logging in with Google... Restarting Gemini CLI to continue. ctrlDPressCount, showEscapePrompt, shortcutsHelpVisible, + cleanUiDetailsVisible, isFocused, elapsedTime, currentLoadingPhrase, @@ -2188,6 +2270,10 @@ Logging in with Google... Restarting Gemini CLI to continue. handleApiKeyCancel, setBannerVisible, setShortcutsHelpVisible, + setCleanUiDetailsVisible, + toggleCleanUiDetailsVisible, + revealCleanUiDetailsTemporarily, + handleWarning, setEmbeddedShellFocused, dismissBackgroundShell, setActiveBackgroundShellPid, @@ -2264,6 +2350,10 @@ Logging in with Google... Restarting Gemini CLI to continue. handleApiKeyCancel, setBannerVisible, setShortcutsHelpVisible, + setCleanUiDetailsVisible, + toggleCleanUiDetailsVisible, + revealCleanUiDetailsTemporarily, + handleWarning, setEmbeddedShellFocused, dismissBackgroundShell, setActiveBackgroundShellPid, diff --git a/packages/cli/src/ui/components/AppHeader.tsx b/packages/cli/src/ui/components/AppHeader.tsx index 38b0f9b468..ad5e2f67d2 100644 --- a/packages/cli/src/ui/components/AppHeader.tsx +++ b/packages/cli/src/ui/components/AppHeader.tsx @@ -17,9 +17,10 @@ import { useTips } from '../hooks/useTips.js'; interface AppHeaderProps { version: string; + showDetails?: boolean; } -export const AppHeader = ({ version }: AppHeaderProps) => { +export const AppHeader = ({ version, showDetails = true }: AppHeaderProps) => { const settings = useSettings(); const config = useConfig(); const { nightly, terminalWidth, bannerData, bannerVisible } = useUIState(); @@ -27,6 +28,14 @@ export const AppHeader = ({ version }: AppHeaderProps) => { const { bannerText } = useBanner(bannerData); const { showTips } = useTips(); + if (!showDetails) { + return ( + +
+ + ); + } + return ( {!(settings.merged.ui.hideBanner || config.getScreenReader()) && ( diff --git a/packages/cli/src/ui/components/Composer.test.tsx b/packages/cli/src/ui/components/Composer.test.tsx index 1a25d2bb56..353e1ad535 100644 --- a/packages/cli/src/ui/components/Composer.test.tsx +++ b/packages/cli/src/ui/components/Composer.test.tsx @@ -4,9 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { describe, it, expect, vi, afterEach } from 'vitest'; +import { beforeEach, afterEach, describe, it, expect, vi } from 'vitest'; import { render } from '../../test-utils/render.js'; import { Box, Text } from 'ink'; +import { useEffect } from 'react'; import { Composer } from './Composer.js'; import { UIStateContext, type UIState } from '../contexts/UIStateContext.js'; import { @@ -23,13 +24,18 @@ vi.mock('../contexts/VimModeContext.js', () => ({ vimMode: 'INSERT', })), })); -import { ApprovalMode } from '@google/gemini-cli-core'; +import { ApprovalMode, tokenLimit } from '@google/gemini-cli-core'; import type { Config } from '@google/gemini-cli-core'; import { StreamingState, ToolCallStatus } from '../types.js'; import { TransientMessageType } from '../../utils/events.js'; import type { LoadedSettings } from '../../config/settings.js'; import type { SessionMetrics } from '../contexts/SessionContext.js'; +const composerTestControls = vi.hoisted(() => ({ + suggestionsVisible: false, + isAlternateBuffer: false, +})); + // Mock child components vi.mock('./LoadingIndicator.js', () => ({ LoadingIndicator: ({ @@ -90,9 +96,19 @@ vi.mock('./DetailedMessagesDisplay.js', () => ({ })); vi.mock('./InputPrompt.js', () => ({ - InputPrompt: ({ placeholder }: { placeholder?: string }) => ( - InputPrompt: {placeholder} - ), + InputPrompt: ({ + placeholder, + onSuggestionsVisibilityChange, + }: { + placeholder?: string; + onSuggestionsVisibilityChange?: (visible: boolean) => void; + }) => { + useEffect(() => { + onSuggestionsVisibilityChange?.(composerTestControls.suggestionsVisible); + }, [onSuggestionsVisibilityChange]); + + return InputPrompt: {placeholder}; + }, calculatePromptWidths: vi.fn(() => ({ inputWidth: 80, suggestionsWidth: 40, @@ -100,6 +116,10 @@ vi.mock('./InputPrompt.js', () => ({ })), })); +vi.mock('../hooks/useAlternateBuffer.js', () => ({ + useAlternateBuffer: () => composerTestControls.isAlternateBuffer, +})); + vi.mock('./Footer.js', () => ({ Footer: () => Footer, })); @@ -154,15 +174,19 @@ const createMockUIState = (overrides: Partial = {}): UIState => ctrlDPressedOnce: false, showEscapePrompt: false, shortcutsHelpVisible: false, + cleanUiDetailsVisible: true, ideContextState: null, geminiMdFileCount: 0, renderMarkdown: true, filteredConsoleMessages: [], history: [], sessionStats: { + sessionId: 'test-session', + sessionStartTime: new Date(), + // eslint-disable-next-line @typescript-eslint/no-explicit-any + metrics: {} as any, lastPromptTokenCount: 0, - sessionTokenCount: 0, - totalPrompts: 0, + promptCount: 0, }, branchName: 'main', debugMessage: '', @@ -187,6 +211,9 @@ const createMockUIActions = (): UIActions => handleFinalSubmit: vi.fn(), handleClearScreen: vi.fn(), setShellModeActive: vi.fn(), + setCleanUiDetailsVisible: vi.fn(), + toggleCleanUiDetailsVisible: vi.fn(), + revealCleanUiDetailsTemporarily: vi.fn(), onEscapePromptChange: vi.fn(), vimHandleInput: vi.fn(), setShortcutsHelpVisible: vi.fn(), @@ -233,6 +260,11 @@ const renderComposer = ( ); describe('Composer', () => { + beforeEach(() => { + composerTestControls.suggestionsVisible = false; + composerTestControls.isAlternateBuffer = false; + }); + afterEach(() => { vi.restoreAllMocks(); }); @@ -342,6 +374,7 @@ describe('Composer', () => { const uiState = createMockUIState({ streamingState: StreamingState.Responding, elapsedTime: 1, + cleanUiDetailsVisible: false, }); const { lastFrame } = renderComposer(uiState); @@ -514,6 +547,21 @@ describe('Composer', () => { }); describe('Input and Indicators', () => { + it('hides non-essential UI details in clean mode', () => { + const uiState = createMockUIState({ + cleanUiDetailsVisible: false, + }); + + const { lastFrame } = renderComposer(uiState); + + const output = lastFrame(); + expect(output).toContain('ShortcutsHint'); + expect(output).toContain('InputPrompt'); + expect(output).not.toContain('Footer'); + expect(output).not.toContain('ApprovalModeIndicator'); + expect(output).not.toContain('ContextSummaryDisplay'); + }); + it('renders InputPrompt when input is active', () => { const uiState = createMockUIState({ isInputActive: true, @@ -582,6 +630,92 @@ describe('Composer', () => { expect(lastFrame()).not.toContain('raw markdown mode'); }); + + it.each([ + [ApprovalMode.YOLO, 'YOLO'], + [ApprovalMode.PLAN, 'plan'], + [ApprovalMode.AUTO_EDIT, 'auto edit'], + ])( + 'shows minimal mode badge "%s" when clean UI details are hidden', + (mode, label) => { + const uiState = createMockUIState({ + cleanUiDetailsVisible: false, + showApprovalModeIndicator: mode, + }); + + const { lastFrame } = renderComposer(uiState); + expect(lastFrame()).toContain(label); + }, + ); + + it('hides minimal mode badge while loading in clean mode', () => { + const uiState = createMockUIState({ + cleanUiDetailsVisible: false, + streamingState: StreamingState.Responding, + elapsedTime: 1, + showApprovalModeIndicator: ApprovalMode.PLAN, + }); + + const { lastFrame } = renderComposer(uiState); + const output = lastFrame(); + expect(output).toContain('LoadingIndicator'); + expect(output).not.toContain('plan'); + expect(output).not.toContain('ShortcutsHint'); + }); + + it('hides minimal mode badge while action-required state is active', () => { + const uiState = createMockUIState({ + cleanUiDetailsVisible: false, + showApprovalModeIndicator: ApprovalMode.PLAN, + customDialog: ( + + Prompt + + ), + }); + + const { lastFrame } = renderComposer(uiState); + const output = lastFrame(); + expect(output).not.toContain('plan'); + expect(output).not.toContain('ShortcutsHint'); + }); + + it('shows Esc rewind prompt in minimal mode without showing full UI', () => { + const uiState = createMockUIState({ + cleanUiDetailsVisible: false, + showEscapePrompt: true, + history: [{ id: 1, type: 'user', text: 'msg' }], + }); + + const { lastFrame } = renderComposer(uiState); + const output = lastFrame(); + expect(output).toContain('ToastDisplay'); + expect(output).not.toContain('ContextSummaryDisplay'); + }); + + it('shows context usage bleed-through when over 60%', () => { + const model = 'gemini-2.5-pro'; + const uiState = createMockUIState({ + cleanUiDetailsVisible: false, + currentModel: model, + sessionStats: { + sessionId: 'test-session', + sessionStartTime: new Date(), + // eslint-disable-next-line @typescript-eslint/no-explicit-any + metrics: {} as any, + lastPromptTokenCount: Math.floor(tokenLimit(model) * 0.7), + promptCount: 0, + }, + }); + const settings = createMockSettings({ + ui: { + footer: { hideContextPercentage: false }, + }, + }); + + const { lastFrame } = renderComposer(uiState, settings); + expect(lastFrame()).toContain('%'); + }); }); describe('Error Details Display', () => { @@ -680,7 +814,84 @@ describe('Composer', () => { }); it('keeps shortcuts hint visible when no action is required', () => { - const uiState = createMockUIState(); + const uiState = createMockUIState({ + cleanUiDetailsVisible: false, + }); + + const { lastFrame } = renderComposer(uiState); + + expect(lastFrame()).toContain('ShortcutsHint'); + }); + + it('shows shortcuts hint when full UI details are visible', () => { + const uiState = createMockUIState({ + cleanUiDetailsVisible: true, + }); + + const { lastFrame } = renderComposer(uiState); + + expect(lastFrame()).toContain('ShortcutsHint'); + }); + + it('hides shortcuts hint while loading in minimal mode', () => { + const uiState = createMockUIState({ + cleanUiDetailsVisible: false, + streamingState: StreamingState.Responding, + elapsedTime: 1, + }); + + const { lastFrame } = renderComposer(uiState); + + expect(lastFrame()).not.toContain('ShortcutsHint'); + }); + + it('shows shortcuts help in minimal mode when toggled on', () => { + const uiState = createMockUIState({ + cleanUiDetailsVisible: false, + shortcutsHelpVisible: true, + }); + + const { lastFrame } = renderComposer(uiState); + + expect(lastFrame()).toContain('ShortcutsHelp'); + }); + + it('hides shortcuts hint when suggestions are visible above input in alternate buffer', () => { + composerTestControls.isAlternateBuffer = true; + composerTestControls.suggestionsVisible = true; + + const uiState = createMockUIState({ + cleanUiDetailsVisible: false, + showApprovalModeIndicator: ApprovalMode.PLAN, + }); + + const { lastFrame } = renderComposer(uiState); + + expect(lastFrame()).not.toContain('ShortcutsHint'); + expect(lastFrame()).not.toContain('plan'); + }); + + it('hides approval mode indicator when suggestions are visible above input in alternate buffer', () => { + composerTestControls.isAlternateBuffer = true; + composerTestControls.suggestionsVisible = true; + + const uiState = createMockUIState({ + cleanUiDetailsVisible: true, + showApprovalModeIndicator: ApprovalMode.YOLO, + }); + + const { lastFrame } = renderComposer(uiState); + + expect(lastFrame()).not.toContain('ApprovalModeIndicator'); + }); + + it('keeps shortcuts hint when suggestions are visible below input in regular buffer', () => { + composerTestControls.isAlternateBuffer = false; + composerTestControls.suggestionsVisible = true; + + const uiState = createMockUIState({ + cleanUiDetailsVisible: false, + }); const { lastFrame } = renderComposer(uiState); diff --git a/packages/cli/src/ui/components/Composer.tsx b/packages/cli/src/ui/components/Composer.tsx index b5b88b4e15..8101e7303c 100644 --- a/packages/cli/src/ui/components/Composer.tsx +++ b/packages/cli/src/ui/components/Composer.tsx @@ -5,7 +5,8 @@ */ import { useState, useEffect, useMemo } from 'react'; -import { Box, useIsScreenReaderEnabled } from 'ink'; +import { Box, Text, useIsScreenReaderEnabled } from 'ink'; +import { ApprovalMode, tokenLimit } from '@google/gemini-cli-core'; import { LoadingIndicator } from './LoadingIndicator.js'; import { StatusDisplay } from './StatusDisplay.js'; import { ToastDisplay, shouldShowToast } from './ToastDisplay.js'; @@ -19,6 +20,7 @@ import { InputPrompt } from './InputPrompt.js'; import { Footer } from './Footer.js'; import { ShowMoreLines } from './ShowMoreLines.js'; import { QueuedMessageDisplay } from './QueuedMessageDisplay.js'; +import { ContextUsageDisplay } from './ContextUsageDisplay.js'; import { HorizontalLine } from './shared/HorizontalLine.js'; import { OverflowProvider } from '../contexts/OverflowContext.js'; import { isNarrowWidth } from '../utils/isNarrowWidth.js'; @@ -36,6 +38,7 @@ import { import { ConfigInitDisplay } from '../components/ConfigInitDisplay.js'; import { TodoTray } from './messages/Todo.js'; import { getInlineThinkingMode } from '../utils/inlineThinkingMode.js'; +import { theme } from '../semantic-colors.js'; export const Composer = ({ isFocused = true }: { isFocused?: boolean }) => { const config = useConfig(); @@ -52,6 +55,7 @@ export const Composer = ({ isFocused = true }: { isFocused?: boolean }) => { const isAlternateBuffer = useAlternateBuffer(); const { showApprovalModeIndicator } = uiState; + const showUiDetails = uiState.cleanUiDetailsVisible; const suggestionsPosition = isAlternateBuffer ? 'above' : 'below'; const hideContextSummary = suggestionsVisible && suggestionsPosition === 'above'; @@ -98,17 +102,60 @@ export const Composer = ({ isFocused = true }: { isFocused?: boolean }) => { uiState.shortcutsHelpVisible && uiState.streamingState === StreamingState.Idle && !hasPendingActionRequired; - const showShortcutsHint = - settings.merged.ui.showShortcutsHint && - uiState.streamingState === StreamingState.Idle && - !hasPendingActionRequired; const hasToast = shouldShowToast(uiState); const showLoadingIndicator = (!uiState.embeddedShellFocused || uiState.isBackgroundShellVisible) && uiState.streamingState === StreamingState.Responding && !hasPendingActionRequired; - const showApprovalIndicator = !uiState.shellModeActive; + const hideUiDetailsForSuggestions = + suggestionsVisible && suggestionsPosition === 'above'; + const showApprovalIndicator = + !uiState.shellModeActive && !hideUiDetailsForSuggestions; const showRawMarkdownIndicator = !uiState.renderMarkdown; + const modeBleedThrough = + showApprovalModeIndicator === ApprovalMode.YOLO + ? { text: 'YOLO', color: theme.status.error } + : showApprovalModeIndicator === ApprovalMode.PLAN + ? { text: 'plan', color: theme.status.success } + : showApprovalModeIndicator === ApprovalMode.AUTO_EDIT + ? { text: 'auto edit', color: theme.status.warning } + : null; + const hideMinimalModeHintWhileBusy = + !showUiDetails && (showLoadingIndicator || hasPendingActionRequired); + const minimalModeBleedThrough = hideMinimalModeHintWhileBusy + ? null + : modeBleedThrough; + const hasMinimalStatusBleedThrough = shouldShowToast(uiState); + const contextTokenLimit = + typeof uiState.currentModel === 'string' && uiState.currentModel.length > 0 + ? tokenLimit(uiState.currentModel) + : 0; + const showMinimalContextBleedThrough = + !settings.merged.ui.footer.hideContextPercentage && + typeof uiState.currentModel === 'string' && + uiState.currentModel.length > 0 && + contextTokenLimit > 0 && + uiState.sessionStats.lastPromptTokenCount / contextTokenLimit > 0.6; + const hideShortcutsHintForSuggestions = hideUiDetailsForSuggestions; + const showShortcutsHint = + settings.merged.ui.showShortcutsHint && + !hideShortcutsHintForSuggestions && + !hideMinimalModeHintWhileBusy && + !hasPendingActionRequired && + (!showUiDetails || !showLoadingIndicator); + const showMinimalModeBleedThrough = + !hideUiDetailsForSuggestions && Boolean(minimalModeBleedThrough); + const showMinimalInlineLoading = !showUiDetails && showLoadingIndicator; + const showMinimalBleedThroughRow = + !showUiDetails && + (showMinimalModeBleedThrough || + hasMinimalStatusBleedThrough || + showMinimalContextBleedThrough); + const showMinimalMetaRow = + !showUiDetails && + (showMinimalInlineLoading || + showMinimalBleedThroughRow || + showShortcutsHint); return ( { /> )} - + {showUiDetails && ( + + )} - + {showUiDetails && } { alignItems="center" flexGrow={1} > - {showLoadingIndicator && ( + {showUiDetails && showLoadingIndicator && ( { flexDirection="column" alignItems={isNarrow ? 'flex-start' : 'flex-end'} > - {showShortcutsHint && } + {showUiDetails && showShortcutsHint && } - {showShortcutsHelp && } - - + {showMinimalMetaRow && ( - {hasToast ? ( - - ) : ( - !showLoadingIndicator && ( + + {showMinimalInlineLoading && ( + + )} + {showMinimalModeBleedThrough && minimalModeBleedThrough && ( + + ● {minimalModeBleedThrough.text} + + )} + {hasMinimalStatusBleedThrough && ( - {showApprovalIndicator && ( - - )} - {uiState.shellModeActive && ( - - - - )} - {showRawMarkdownIndicator && ( - - - - )} + - ) + )} + + {(showMinimalContextBleedThrough || showShortcutsHint) && ( + + {showMinimalContextBleedThrough && ( + + )} + {showShortcutsHint && ( + + + + )} + )} - + )} + {showShortcutsHelp && } + {showUiDetails && } + {showUiDetails && ( - {!showLoadingIndicator && ( - - )} + + {hasToast ? ( + + ) : ( + !showLoadingIndicator && ( + + {showApprovalIndicator && ( + + )} + {uiState.shellModeActive && ( + + + + )} + {showRawMarkdownIndicator && ( + + + + )} + + ) + )} + + + + {!showLoadingIndicator && ( + + )} + - + )} - {uiState.showErrorDetails && ( + {showUiDetails && uiState.showErrorDetails && ( { /> )} - {!settings.merged.ui.hideFooter && !isScreenReaderEnabled &&