chore: streamline prompts and tool descriptions for token efficiency

This commit is contained in:
Adam Weidman
2026-04-21 09:55:16 -07:00
parent a38e2f0048
commit 257ca50157
4 changed files with 9 additions and 25 deletions
+2 -4
View File
@@ -170,9 +170,7 @@ ${renderUserMemory(userMemory, contextFilenames)}
export function renderPreamble(options?: PreambleOptions): string {
if (!options) return '';
return options.interactive
? 'You are Gemini CLI, an interactive CLI agent specializing in software engineering tasks. Your primary goal is to help users safely and effectively.'
: 'You are Gemini CLI, an autonomous CLI agent specializing in software engineering tasks. Your primary goal is to help users safely and effectively.';
return 'You are Gemini CLI, a software engineering assistant focused on safety and efficiency.';
}
export function renderCoreMandates(options?: CoreMandatesOptions): string {
@@ -194,7 +192,7 @@ export function renderCoreMandates(options?: CoreMandatesOptions): string {
# Core Mandates
## Security & System Integrity
- **Credential Protection:** Never log, print, or commit secrets, API keys, or sensitive credentials. Rigorously protect \`.env\` files, \`.git\`, and system configuration folders.
- **Credential Protection:** Never log, print, or commit secrets, API keys, or credentials. Rigorously protect \`.env\` files, \`.git\`, and system configuration folders.
- **Source Control:** Do not stage or commit changes unless specifically requested by the user.
## Context Efficiency:
@@ -58,12 +58,12 @@ export function getShellToolDescription(
if (os.platform() === 'win32') {
const backgroundInstructions = enableInteractiveShell
? `To run a command in the background, set the \`${SHELL_PARAM_IS_BACKGROUND}\` parameter to true. Do NOT use PowerShell background constructs.`
? `For background execution, use is_background: true instead of PowerShell background constructs.`
: 'Command can start background processes using PowerShell constructs such as `Start-Process -NoNewWindow` or `Start-Job`.';
return `This tool executes a given shell command as \`powershell.exe -NoProfile -Command <command>\`. ${backgroundInstructions}${efficiencyGuidelines}${returnedInfo}`;
} else {
const backgroundInstructions = enableInteractiveShell
? `To run a command in the background, set the \`${SHELL_PARAM_IS_BACKGROUND}\` parameter to true. Do NOT use \`&\` to background commands.`
? `For background execution, use is_background: true instead of &.`
: 'Command can start background processes using `&`.';
return `This tool executes a given shell command as \`bash -c <command>\`. ${backgroundInstructions} Command is executed as a subprocess that leads its own process group. Command process group can be terminated as \`kill -- -PGID\` or signaled as \`kill -s SIGNAL -- -PGID\`.${efficiencyGuidelines}${returnedInfo}`;
}
@@ -95,8 +95,7 @@ export const DEFAULT_LEGACY_SET: CoreToolSet = {
type: 'string',
},
[READ_FILE_PARAM_START_LINE]: {
description:
'Optional: The 1-based line number to start reading from.',
description: 'Optional 1-based starting line number.',
type: 'number',
},
[READ_FILE_PARAM_END_LINE]: {
@@ -348,18 +347,7 @@ export const DEFAULT_LEGACY_SET: CoreToolSet = {
replace: {
name: EDIT_TOOL_NAME,
description: `Replaces text within a file. By default, the tool expects to find and replace exactly ONE occurrence of \`old_string\`. If you want to replace multiple occurrences of the exact same string, set \`allow_multiple\` to true. This tool requires providing significant context around the change to ensure precise targeting. Always use the ${READ_FILE_TOOL_NAME} tool to examine the file's current content before attempting a text replacement.
The user has the ability to modify the \`new_string\` content. If modified, this will be stated in the response.
Expectation for required parameters:
1. \`old_string\` MUST be the exact literal text to replace (including all whitespace, indentation, newlines, and surrounding code etc.).
2. \`new_string\` MUST be the exact literal text to replace \`old_string\` with (also including all whitespace, indentation, newlines, and surrounding code etc.). Ensure the resulting code is correct and idiomatic and that \`old_string\` and \`new_string\` are different.
3. \`instruction\` is the detailed instruction of what needs to be changed. It is important to Make it specific and detailed so developers or large language models can understand what needs to be changed and perform the changes on their own if necessary.
4. NEVER escape \`old_string\` or \`new_string\`, that would break the exact literal text requirement.
**Important:** If ANY of the above are not satisfied, the tool will fail. CRITICAL for \`old_string\`: Must uniquely identify the instance(s) to change. Include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. If this string matches multiple locations and \`allow_multiple\` is not true, the tool will fail.
5. Prefer to break down complex and long changes into multiple smaller atomic calls to this tool. Always check the content of the file after changes or not finding a string to match.
**Multiple replacements:** Set \`allow_multiple\` to true if you want to replace ALL occurrences that match \`old_string\` exactly.`,
description: `Replaces exact old_string with new_string. Fails if not exactly one match, unless allow_multiple is true.`,
parametersJsonSchema: {
type: 'object',
properties: {
@@ -104,8 +104,7 @@ export const GEMINI_3_SET: CoreToolSet = {
type: 'string',
},
[READ_FILE_PARAM_START_LINE]: {
description:
'Optional: The 1-based line number to start reading from.',
description: 'Optional 1-based starting line number.',
type: 'number',
},
[READ_FILE_PARAM_END_LINE]: {
@@ -188,7 +187,7 @@ export const GEMINI_3_SET: CoreToolSet = {
grep_search_ripgrep: {
name: GREP_TOOL_NAME,
description:
'Searches for a regular expression pattern within file contents. This tool is FAST and optimized, powered by ripgrep. PREFERRED over standard `run_shell_command("grep ...")` due to better performance and automatic output limiting (defaults to 100 matches, but can be increased via `total_max_matches`).',
"Fast ripgrep-powered search. Always prefer this over run_shell_command('grep').",
parametersJsonSchema: {
type: 'object',
properties: {
@@ -355,8 +354,7 @@ export const GEMINI_3_SET: CoreToolSet = {
replace: {
name: EDIT_TOOL_NAME,
description: `Replaces text within a file. By default, the tool expects to find and replace exactly ONE occurrence of \`old_string\`. If you want to replace multiple occurrences of the exact same string, set \`allow_multiple\` to true. This tool requires providing significant context around the change to ensure precise targeting.
The user has the ability to modify the \`new_string\` content. If modified, this will be stated in the response.`,
description: `Replaces exact old_string with new_string. Fails if not exactly one match, unless allow_multiple is true.`,
parametersJsonSchema: {
type: 'object',
properties: {