diff --git a/packages/cli/src/config/config.test.ts b/packages/cli/src/config/config.test.ts index 15e9fdd24b..cdcc1dfdcb 100644 --- a/packages/cli/src/config/config.test.ts +++ b/packages/cli/src/config/config.test.ts @@ -8,13 +8,13 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import * as os from 'node:os'; import * as path from 'node:path'; import { - ShellTool, EditTool, WriteFileTool, DEFAULT_GEMINI_MODEL, DEFAULT_GEMINI_MODEL_AUTO, OutputFormat, type GeminiCLIExtension, + SHELL_TOOL_NAME, } from '@google/gemini-cli-core'; import { loadCliConfig, @@ -740,7 +740,7 @@ describe('mergeMcpServers', () => { }); describe('mergeExcludeTools', () => { - const defaultExcludes = [ShellTool.Name, EditTool.Name, WriteFileTool.Name]; + const defaultExcludes = [SHELL_TOOL_NAME, EditTool.Name, WriteFileTool.Name]; const originalIsTTY = process.stdin.isTTY; beforeEach(() => { @@ -981,7 +981,7 @@ describe('Approval mode tool exclusion logic', () => { ); const excludedTools = config.getExcludeTools(); - expect(excludedTools).toContain(ShellTool.Name); + expect(excludedTools).toContain(SHELL_TOOL_NAME); expect(excludedTools).toContain(EditTool.Name); expect(excludedTools).toContain(WriteFileTool.Name); }); @@ -1008,7 +1008,7 @@ describe('Approval mode tool exclusion logic', () => { ); const excludedTools = config.getExcludeTools(); - expect(excludedTools).toContain(ShellTool.Name); + expect(excludedTools).toContain(SHELL_TOOL_NAME); expect(excludedTools).toContain(EditTool.Name); expect(excludedTools).toContain(WriteFileTool.Name); }); @@ -1035,7 +1035,7 @@ describe('Approval mode tool exclusion logic', () => { ); const excludedTools = config.getExcludeTools(); - expect(excludedTools).toContain(ShellTool.Name); + expect(excludedTools).toContain(SHELL_TOOL_NAME); expect(excludedTools).not.toContain(EditTool.Name); expect(excludedTools).not.toContain(WriteFileTool.Name); }); @@ -1062,7 +1062,7 @@ describe('Approval mode tool exclusion logic', () => { ); const excludedTools = config.getExcludeTools(); - expect(excludedTools).not.toContain(ShellTool.Name); + expect(excludedTools).not.toContain(SHELL_TOOL_NAME); expect(excludedTools).not.toContain(EditTool.Name); expect(excludedTools).not.toContain(WriteFileTool.Name); }); @@ -1082,7 +1082,7 @@ describe('Approval mode tool exclusion logic', () => { ); const excludedTools = config.getExcludeTools(); - expect(excludedTools).not.toContain(ShellTool.Name); + expect(excludedTools).not.toContain(SHELL_TOOL_NAME); expect(excludedTools).not.toContain(EditTool.Name); expect(excludedTools).not.toContain(WriteFileTool.Name); }); @@ -1113,7 +1113,7 @@ describe('Approval mode tool exclusion logic', () => { ); const excludedTools = config.getExcludeTools(); - expect(excludedTools).not.toContain(ShellTool.Name); + expect(excludedTools).not.toContain(SHELL_TOOL_NAME); expect(excludedTools).not.toContain(EditTool.Name); expect(excludedTools).not.toContain(WriteFileTool.Name); } @@ -1142,7 +1142,7 @@ describe('Approval mode tool exclusion logic', () => { const excludedTools = config.getExcludeTools(); expect(excludedTools).toContain('custom_tool'); // From settings - expect(excludedTools).toContain(ShellTool.Name); // From approval mode + expect(excludedTools).toContain(SHELL_TOOL_NAME); // From approval mode expect(excludedTools).not.toContain(EditTool.Name); // Should be allowed in auto_edit expect(excludedTools).not.toContain(WriteFileTool.Name); // Should be allowed in auto_edit }); @@ -2087,7 +2087,7 @@ describe('loadCliConfig tool exclusions', () => { 'test-session', argv, ); - expect(config.getExcludeTools()).not.toContain(ShellTool.Name); + expect(config.getExcludeTools()).not.toContain(SHELL_TOOL_NAME); }); it('should not exclude shell tool in non-interactive mode when --allowed-tools="run_shell_command" is set', async () => { @@ -2108,7 +2108,7 @@ describe('loadCliConfig tool exclusions', () => { 'test-session', argv, ); - expect(config.getExcludeTools()).not.toContain(ShellTool.Name); + expect(config.getExcludeTools()).not.toContain(SHELL_TOOL_NAME); }); it('should not exclude shell tool in non-interactive mode when --allowed-tools="ShellTool(wc)" is set', async () => { @@ -2129,7 +2129,7 @@ describe('loadCliConfig tool exclusions', () => { 'test-session', argv, ); - expect(config.getExcludeTools()).not.toContain(ShellTool.Name); + expect(config.getExcludeTools()).not.toContain(SHELL_TOOL_NAME); }); }); diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index f64296fc79..0c13dd4b3a 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -29,10 +29,10 @@ import { DEFAULT_GEMINI_EMBEDDING_MODEL, DEFAULT_MEMORY_FILE_FILTERING_OPTIONS, FileDiscoveryService, - ShellTool, EditTool, WRITE_FILE_TOOL_NAME, SHELL_TOOL_NAMES, + SHELL_TOOL_NAME, resolveTelemetrySettings, FatalConfigError, getPty, @@ -352,7 +352,7 @@ function createToolExclusionFilter( allowedToolsSet: Set, ) { return (tool: string): boolean => { - if (tool === ShellTool.Name) { + if (tool === SHELL_TOOL_NAME) { // If any of the allowed tools is ShellTool (even with subcommands), don't exclude it. return !allowedTools.some((allowed) => SHELL_TOOL_NAMES.some((shellName) => allowed.startsWith(shellName)), @@ -505,11 +505,11 @@ export async function loadCliConfig( const extraExcludes: string[] = []; if (!interactive && !argv.experimentalAcp) { const defaultExcludes = [ - ShellTool.Name, + SHELL_TOOL_NAME, EditTool.Name, WRITE_FILE_TOOL_NAME, ]; - const autoEditExcludes = [ShellTool.Name]; + const autoEditExcludes = [SHELL_TOOL_NAME]; const toolExclusionFilter = createToolExclusionFilter( allowedTools, diff --git a/packages/cli/src/config/policy.ts b/packages/cli/src/config/policy.ts index 7c72fa26de..85226540ee 100644 --- a/packages/cli/src/config/policy.ts +++ b/packages/cli/src/config/policy.ts @@ -19,7 +19,7 @@ import { // Write tools EditTool, MemoryTool, - ShellTool, + SHELL_TOOL_NAME, WRITE_FILE_TOOL_NAME, WEB_FETCH_TOOL_NAME, WebSearchTool, @@ -47,7 +47,7 @@ const READ_ONLY_TOOLS = new Set([ const WRITE_TOOLS = new Set([ EditTool.Name, MemoryTool.Name, - ShellTool.Name, + SHELL_TOOL_NAME, WRITE_FILE_TOOL_NAME, WEB_FETCH_TOOL_NAME, ]); diff --git a/packages/core/src/core/coreToolScheduler.ts b/packages/core/src/core/coreToolScheduler.ts index f3a28fa96f..57eee15359 100644 --- a/packages/core/src/core/coreToolScheduler.ts +++ b/packages/core/src/core/coreToolScheduler.ts @@ -25,10 +25,10 @@ import { ReadFileTool, ToolErrorType, ToolCallEvent, - ShellTool, logToolOutputTruncated, ToolOutputTruncatedEvent, } from '../index.js'; +import { SHELL_TOOL_NAME } from '../tools/tool-names.js'; import type { Part, PartListUnion } from '@google/genai'; import { getResponseTextFromParts } from '../utils/generateContentResponseUtilities.js'; import type { ModifyContext } from '../tools/modifiable-tool.js'; @@ -1038,7 +1038,7 @@ export class CoreToolScheduler { typeof content === 'string' ? content.length : undefined; if ( typeof content === 'string' && - toolName === ShellTool.Name && + toolName === SHELL_TOOL_NAME && this.config.getEnableToolOutputTruncation() && this.config.getTruncateToolOutputThreshold() > 0 && this.config.getTruncateToolOutputLines() > 0 diff --git a/packages/core/src/core/prompts.ts b/packages/core/src/core/prompts.ts index b22ddc8a5b..2b3bbae4cc 100644 --- a/packages/core/src/core/prompts.ts +++ b/packages/core/src/core/prompts.ts @@ -11,8 +11,11 @@ import { GlobTool } from '../tools/glob.js'; import { GrepTool } from '../tools/grep.js'; import { ReadFileTool } from '../tools/read-file.js'; import { ReadManyFilesTool } from '../tools/read-many-files.js'; -import { ShellTool } from '../tools/shell.js'; -import { EDIT_TOOL_NAME, WRITE_FILE_TOOL_NAME } from '../tools/tool-names.js'; +import { + EDIT_TOOL_NAME, + SHELL_TOOL_NAME, + WRITE_FILE_TOOL_NAME, +} from '../tools/tool-names.js'; import process from 'node:process'; import { isGitRepository } from '../utils/gitUtils.js'; import { MemoryTool } from '../tools/memoryTool.js'; @@ -135,14 +138,14 @@ ${(function () { 1. **Understand:** Think about the user's request and the relevant codebase context. Use '${GrepTool.Name}' and '${GlobTool.Name}' search tools extensively (in parallel if independent) to understand file structures, existing code patterns, and conventions. Use '${ReadFileTool.Name}' and '${ReadManyFilesTool.Name}' to understand context and validate any assumptions you may have. 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution.`; })()} -3. **Implement:** Use the available tools (e.g., '${EDIT_TOOL_NAME}', '${WRITE_FILE_TOOL_NAME}' '${ShellTool.Name}' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). +3. **Implement:** Use the available tools (e.g., '${EDIT_TOOL_NAME}', '${WRITE_FILE_TOOL_NAME}' '${SHELL_TOOL_NAME}' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates'). 4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands. 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to. 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction. ## New Applications -**Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype. Utilize all tools at your disposal to implement the application. Some tools you may especially find useful are '${WRITE_FILE_TOOL_NAME}', '${EDIT_TOOL_NAME}' and '${ShellTool.Name}'. +**Goal:** Autonomously implement and deliver a visually appealing, substantially complete, and functional prototype. Utilize all tools at your disposal to implement the application. Some tools you may especially find useful are '${WRITE_FILE_TOOL_NAME}', '${EDIT_TOOL_NAME}' and '${SHELL_TOOL_NAME}'. 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. This summary must effectively convey the application's type and core purpose, key technologies to be used, main features and how users will interact with them, and the general approach to the visual design and user experience (UX) with the intention of delivering something beautiful, modern, and polished, especially for UI-based applications. 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, or open-source assets if feasible and licenses permit) to ensure a visually complete initial prototype. Ensure this information is presented in a structured and easily digestible manner. @@ -155,7 +158,7 @@ ${(function () { - **3d Games:** HTML/CSS/JavaScript with Three.js. - **2d Games:** HTML/CSS/JavaScript. 3. **User Approval:** Obtain user approval for the proposed plan. -4. **Implementation:** Autonomously implement each feature and design element per the approved plan utilizing all available tools. When starting ensure you scaffold the application using '${ShellTool.Name}' for commands like 'npm init', 'npx create-react-app'. Aim for full scope completion. Proactively create or source necessary placeholder assets (e.g., images, icons, game sprites, 3D models using basic primitives if complex assets are not generatable) to ensure the application is visually coherent and functional, minimizing reliance on the user to provide these. If the model can generate simple assets (e.g., a uniformly colored square sprite, a simple 3D cube), it should do so. Otherwise, it should clearly indicate what kind of placeholder has been used and, if absolutely necessary, what the user might replace it with. Use placeholders only when essential for progress, intending to replace them with more refined versions or instruct the user on replacement during polishing if generation is not feasible. +4. **Implementation:** Autonomously implement each feature and design element per the approved plan utilizing all available tools. When starting ensure you scaffold the application using '${SHELL_TOOL_NAME}' for commands like 'npm init', 'npx create-react-app'. Aim for full scope completion. Proactively create or source necessary placeholder assets (e.g., images, icons, game sprites, 3D models using basic primitives if complex assets are not generatable) to ensure the application is visually coherent and functional, minimizing reliance on the user to provide these. If the model can generate simple assets (e.g., a uniformly colored square sprite, a simple 3D cube), it should do so. Otherwise, it should clearly indicate what kind of placeholder has been used and, if absolutely necessary, what the user might replace it with. Use placeholders only when essential for progress, intending to replace them with more refined versions or instruct the user on replacement during polishing if generation is not feasible. 5. **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. 6. **Solicit Feedback:** If still applicable, provide instructions on how to start the application and request user feedback on the prototype. @@ -168,7 +171,7 @@ ${(function () { IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. -- Always prefer command flags that reduce output verbosity when using '${ShellTool.Name}'. +- Always prefer command flags that reduce output verbosity when using '${SHELL_TOOL_NAME}'. - Aim to minimize tool output tokens while still capturing necessary information. - If a command is expected to produce a lot of output, use quiet or silent flags where available and appropriate. - Always consider the trade-off between output verbosity and the need for information. If a command's full output is essential for understanding the result, avoid overly aggressive quieting that might obscure important details. @@ -198,13 +201,13 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION. - **Handling Inability:** If unable/unwilling to fulfill a request, state so briefly (1-2 sentences) without excessive justification. Offer alternatives if appropriate. ## Security and Safety Rules -- **Explain Critical Commands:** Before executing commands with '${ShellTool.Name}' that modify the file system, codebase, or system state, you *must* provide a brief explanation of the command's purpose and potential impact. Prioritize user understanding and safety. You should not ask permission to use the tool; the user will be presented with a confirmation dialogue upon use (you do not need to tell them this). +- **Explain Critical Commands:** Before executing commands with '${SHELL_TOOL_NAME}' that modify the file system, codebase, or system state, you *must* provide a brief explanation of the command's purpose and potential impact. Prioritize user understanding and safety. You should not ask permission to use the tool; the user will be presented with a confirmation dialogue upon use (you do not need to tell them this). - **Security First:** Always apply security best practices. Never introduce code that exposes, logs, or commits secrets, API keys, or other sensitive information. ## Tool Usage - **File Paths:** Always use absolute paths when referring to files with tools like '${ReadFileTool.Name}' or '${WRITE_FILE_TOOL_NAME}'. Relative paths are not supported. You must provide an absolute path. - **Parallelism:** Execute multiple independent tool calls in parallel when feasible (i.e. searching the codebase). -- **Command Execution:** Use the '${ShellTool.Name}' tool for running shell commands, remembering the safety rule to explain modifying commands first. +- **Command Execution:** Use the '${SHELL_TOOL_NAME}' tool for running shell commands, remembering the safety rule to explain modifying commands first. - **Background Processes:** Use background processes (via \`&\`) for commands that are unlikely to stop on their own, e.g. \`node server.js &\`. If unsure, ask the user. ${(function () { if (!config.isInteractiveShellEnabled()) { diff --git a/packages/core/src/tools/shell.test.ts b/packages/core/src/tools/shell.test.ts index a45183af7a..21f380b66c 100644 --- a/packages/core/src/tools/shell.test.ts +++ b/packages/core/src/tools/shell.test.ts @@ -44,6 +44,7 @@ import { ToolErrorType } from './tool-error.js'; import { ToolConfirmationOutcome } from './tools.js'; import { OUTPUT_UPDATE_INTERVAL_MS } from './shell.js'; import { createMockWorkspaceContext } from '../test-utils/mockWorkspaceContext.js'; +import { SHELL_TOOL_NAME } from './tool-names.js'; const originalComSpec = process.env['ComSpec']; const itWindowsOnly = process.platform === 'win32' ? it : it.skip; @@ -306,7 +307,7 @@ describe('ShellTool', () => { it('should summarize output when configured', async () => { (mockConfig.getSummarizeToolOutputConfig as Mock).mockReturnValue({ - [shellTool.name]: { tokenBudget: 1000 }, + [SHELL_TOOL_NAME]: { tokenBudget: 1000 }, }); vi.mocked(summarizer.summarizeToolOutput).mockResolvedValue( 'summarized output', diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index df1d828306..06024e4000 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -40,6 +40,7 @@ import { stripShellWrapper, } from '../utils/shell-utils.js'; import { doesToolInvocationMatch } from '../utils/tool-utils.js'; +import { SHELL_TOOL_NAME } from './tool-names.js'; export const OUTPUT_UPDATE_INTERVAL_MS = 1000; @@ -298,12 +299,12 @@ export class ShellToolInvocation extends BaseToolInvocation< }, } : {}; - if (summarizeConfig && summarizeConfig[ShellTool.Name]) { + if (summarizeConfig && summarizeConfig[SHELL_TOOL_NAME]) { const summary = await summarizeToolOutput( llmContent, this.config.getGeminiClient(), signal, - summarizeConfig[ShellTool.Name].tokenBudget, + summarizeConfig[SHELL_TOOL_NAME].tokenBudget, ); return { llmContent: summary, @@ -359,7 +360,6 @@ export class ShellTool extends BaseDeclarativeTool< ShellToolParams, ToolResult > { - static Name: string = 'run_shell_command'; private allowlist: Set = new Set(); constructor(private readonly config: Config) { @@ -367,7 +367,7 @@ export class ShellTool extends BaseDeclarativeTool< // Errors are surfaced when parsing commands. }); super( - ShellTool.Name, + SHELL_TOOL_NAME, 'Shell', getShellToolDescription(), Kind.Execute, diff --git a/packages/core/src/tools/tool-names.ts b/packages/core/src/tools/tool-names.ts index 546fe13fd3..9ad1ce4408 100644 --- a/packages/core/src/tools/tool-names.ts +++ b/packages/core/src/tools/tool-names.ts @@ -14,6 +14,7 @@ export const WRITE_FILE_TOOL_NAME = 'write_file'; export const WEB_SEARCH_TOOL_NAME = 'google_web_search'; export const WEB_FETCH_TOOL_NAME = 'web_fetch'; export const EDIT_TOOL_NAME = 'replace'; +export const SHELL_TOOL_NAME = 'run_shell_command'; // TODO: Migrate other tool names here to follow this pattern and prevent future circular dependencies. // Candidates for migration: