Repository navigation
fix(prompt): Make interactive command avoidance conditional - #11225
Conversation
Summary of ChangesHello @galz10, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request optimizes the core system prompt by making the 'Interactive Commands' section conditional. The guidance, which advises against using interactive shell commands, will now only be present in non-interactive CLI sessions. This ensures that the prompt remains concise and relevant, avoiding unnecessary instructions and token consumption when the user can directly manage interactive prompts. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to conditionally include the 'Interactive Commands' guidance in the system prompt based on whether the session is interactive. The approach of using a self-executing function within the template literal is consistent with other parts of the file. However, I've found a formatting issue with the current implementation that adds an extra newline in interactive mode, which I've detailed in a specific comment. Addressing this will ensure the prompt remains well-formatted.
| ${(function () { | ||
| if (!config.isInteractive()) { | ||
| return `- **Interactive Commands:** Try to avoid shell commands that are likely to require user interaction (e.g. \`git rebase -i\`). Use non-interactive versions of commands (e.g. \`npm init -y\` instead of \`npm init\`) when available, and otherwise remind the user that interactive shell commands are not supported and may cause hangs until canceled by the user.`; | ||
| } | ||
| return ''; | ||
| })()} |
There was a problem hiding this comment.
This implementation introduces an extra newline in the prompt when running in interactive mode. When config.isInteractive() is true, this function returns an empty string. Because the ${...} expression is on its own line within the template literal, an unwanted blank line is rendered, which disrupts the formatting of the bulleted list.
In interactive mode, the list will incorrectly appear as:
- **Background Processes:** ...
- **Remembering Facts:** ...A more robust approach would be to build this list of guidelines as an array of strings and then use join('\n') to insert it into the prompt. This would handle conditional list items cleanly.
Alternatively, a minimal fix would be to use a ternary operator and attach it to the end of the previous line to control the newline's inclusion, though this would require changing line 209 which is outside this diff.
|
Size Change: +788 B (0%) Total Size: 20.1 MB ℹ️ View Unchanged
|
…le-gemini/gemini-cli into galzahavi/fix/system-prompt
This commit introduces a more precise way to detect if the interactive shell is enabled and improves the guidance provided to the user in the system prompt.
|
/patch preview |
|
✅ Patch workflow(s) dispatched successfully! 📋 Details:
🔗 Track Progress: |
|
❌ Patch creation failed! There was an error creating the patch release. 🔍 Troubleshooting:
🔗 Links: |
|
/patch preview |
|
✅ Patch workflow(s) dispatched successfully! 📋 Details:
🔗 Track Progress: |
|
❌ Patch creation failed! There was an error creating the patch release. 🔍 Troubleshooting:
🔗 Links: |
|
🚀 Patch Release Started! 📋 Release Details:
⏳ Status: The patch release is now running. You'll receive another update when it completes. 🔗 Track Progress: |
|
❌ Patch Release Failed! 📋 Details:
🔍 Next Steps:
🔗 Troubleshooting: |
TLDR
This pull request makes the "- Interactive Commands" section of the core system prompt conditional. This instruction will now only be included when the CLI is running in a non-interactive mode (
config.isInteractiveisfalse).This change is to reduce the size and complexity of the system prompt for interactive sessions where this guidance is not relevant.
Dive Deeper
The system prompt contains guidance for the model on how to behave. One piece of guidance is to avoid using interactive shell commands (like
git rebase -i) because they can cause the CLI to hang in non-interactive or automated environments.However, when a user is in an interactive session, they can handle these prompts directly, making the warning unnecessary. Removing it in interactive mode saves tokens and simplifies the instructions for the model.
The implementation uses a small, self-executing function within the template literal for
basePromptinpackages/core/src/core/prompts.ts. This conditionally returns the text block based on theconfig.isInteractiveflag, which is a clean way to handle this and is consistent with other conditional logic in the same file.Reviewer Test Plan
To test this change, a reviewer can inspect the generated system prompt in both interactive and non-interactive modes.
console.log(basePrompt);at the end of thegetCoreSystemPromptfunction inpackages/core/src/core/prompts.ts.npm run build.npx dist/gemini.js. The logged prompt should NOT contain the "Interactive Commands" section.npx dist/gemini.js -p "list files". The logged prompt SHOULD contain the "Interactive Commands" section.console.logbefore merging.Testing Matrix
Linked issues / bugs
None