Skip to content

feat(cli): add /enhance command to improve user prompts - #25135

Closed
akh64bit wants to merge 14 commits into
mainfrom
feat/enhance-command
Closed

feat(cli): add /enhance command to improve user prompts#25135
akh64bit wants to merge 14 commits into
mainfrom
feat/enhance-command

Conversation

@akh64bit

Copy link
Copy Markdown
Contributor

Summary

This PR introduces the /enhance command, allowing users to leverage the LLM to refine and expand their prompts. It uses the conversation history as context for generating high-quality prompt rephrasings.

Details

The new command reads the user's initial prompt draft, requests an enhancement from the configured model, and automatically populates the input buffer with the refined prompt via a new setInput method on CommandContext. It also updates settings.json to organize plan settings.

Related Issues

Resolves #25133

How to Validate

  1. Check out the branch: gh pr checkout <pr-number>
  2. Run the application: npm run start
  3. Enter a basic prompt and use the command: /enhance write a function
  4. The CLI should replace the text in the input buffer with a more detailed, enhanced version of the prompt.
  5. Unit tests should pass: npm test -w @google/gemini-cli -- packages/cli/src/ui/commands/enhanceCommand.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

This adds the /enhance command which uses an LLM to refine user prompts
based on conversation history.

Closes #25133
@akh64bit
akh64bit requested a review from a team as a code owner April 10, 2026 18:08
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 implements a new /enhance command for the CLI, enabling users to improve their prompt drafts through LLM-based rephrasing. By integrating with the existing conversation history and adding a mechanism to update the input buffer, the feature provides a seamless workflow for refining prompts directly within the terminal interface.

Highlights

  • New /enhance command: Added a new slash command that allows users to refine and expand their prompts using the LLM.
  • Input buffer management: Introduced a new setInput method in CommandContext to allow commands to programmatically update the user's input buffer.
  • Context-aware enhancement: The enhancement process leverages the existing conversation history to provide better, context-aware prompt improvements.
Ignored Files
  • Ignored by pattern: .gemini/** (1)
    • .gemini/settings.json
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new /enhance built-in command to the CLI, which uses a Gemini model to rephrase and add context to user prompts based on the conversation history. The changes include the command implementation, a new setInput method in the UI context to update the input buffer with the enhanced text, and comprehensive unit tests. Feedback is provided to set autoExecute to false to prevent errors when selecting the command from autocomplete without arguments, and to improve the robustness of response parsing by handling 'thought' parts and sanitizing the output to prevent prompt injection.

name: 'enhance',
description: 'Enhance a prompt with additional context and rephrasing',
kind: CommandKind.BUILT_IN,
autoExecute: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Since the /enhance command requires a prompt argument to function correctly, autoExecute should be set to false. When autoExecute is true, selecting the command from the autocomplete list (e.g., by pressing Enter) will trigger it immediately with empty arguments, resulting in an error message. Setting it to false allows the user to complete the command name and then type the prompt they wish to enhance.

Suggested change
autoExecute: true,
autoExecute: false,

LlmRole.UTILITY_TOOL,
);

const enhancedText = response.candidates?.[0]?.content?.parts?.[0]?.text;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The current implementation assumes the enhanced prompt is always in the first part of the first candidate. Gemini 2.0 models often include a 'thought' part before the actual response text. It is safer to find the first text part that isn't a thought. Additionally, to prevent prompt injection, sanitize the output by removing newlines and context-breaking characters like ']' before it is used in further prompts, as per repository rules.

Suggested change
const enhancedText = response.candidates?.[0]?.content?.parts?.[0]?.text;
const enhancedText = response.candidates?.[0]?.content?.parts?.find((part) => part.text !== undefined && !part.thought)?.text?.replace(/\n/g, '').replace(/]/g, '');
References
  1. Sanitize data from LLM-driven tools before injecting it into a system prompt to prevent prompt injection. At a minimum, remove newlines and context-breaking characters (e.g., ']').

@gemini-cli gemini-cli Bot added area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Apr 10, 2026
This adds the Alt+E keyboard shortcut to quickly trigger the prompt
enhancement functionality alongside the existing /enhance slash command.
@akh64bit
akh64bit force-pushed the feat/enhance-command branch from fb93c4f to 48d7a72 Compare April 10, 2026 18:38
@github-actions

github-actions Bot commented Apr 11, 2026

Copy link
Copy Markdown

Size Change: +4.53 kB (+0.01%)

Total Size: 33.9 MB

Filename Size Change
./bundle/chunk-2Q4PB7YS.js 0 B -14.7 MB (removed) 🏆
./bundle/chunk-73TSBNTA.js 0 B -49.2 kB (removed) 🏆
./bundle/chunk-A2MK3BAK.js 0 B -3.43 kB (removed) 🏆
./bundle/chunk-BDVFNQBM.js 0 B -2.72 MB (removed) 🏆
./bundle/chunk-LUNQ6A63.js 0 B -19.5 kB (removed) 🏆
./bundle/chunk-SRKHEXJ2.js 0 B -655 kB (removed) 🏆
./bundle/chunk-UWSFVGPF.js 0 B -12.6 kB (removed) 🏆
./bundle/chunk-ZO5ZCG6U.js 0 B -3.8 kB (removed) 🏆
./bundle/core-SQ5LYTQZ.js 0 B -48.2 kB (removed) 🏆
./bundle/devtoolsService-OPH4MPYV.js 0 B -28 kB (removed) 🏆
./bundle/gemini-WK4FVCLD.js 0 B -575 kB (removed) 🏆
./bundle/interactiveCli-IYIA5LS7.js 0 B -1.31 MB (removed) 🏆
./bundle/liteRtServerManager-V5J7K3ZX.js 0 B -2.11 kB (removed) 🏆
./bundle/oauth2-provider-LTUUWNH3.js 0 B -9.16 kB (removed) 🏆
./bundle/chunk-34YM6DMH.js 12.6 kB +12.6 kB (new file) 🆕
./bundle/chunk-CZ2XXK52.js 14.7 MB +14.7 MB (new file) 🆕
./bundle/chunk-EEP66A3J.js 19.5 kB +19.5 kB (new file) 🆕
./bundle/chunk-M7GBOI5T.js 2.72 MB +2.72 MB (new file) 🆕
./bundle/chunk-VEURSOCE.js 3.43 kB +3.43 kB (new file) 🆕
./bundle/chunk-VUCL7CQZ.js 3.8 kB +3.8 kB (new file) 🆕
./bundle/chunk-WSPCKBGA.js 656 kB +656 kB (new file) 🆕
./bundle/chunk-XUFA75WN.js 49.2 kB +49.2 kB (new file) 🆕
./bundle/core-SAA2RKL7.js 48.2 kB +48.2 kB (new file) 🆕
./bundle/devtoolsService-WTTPM6ZP.js 28 kB +28 kB (new file) 🆕
./bundle/gemini-KXAK4NON.js 575 kB +575 kB (new file) 🆕
./bundle/interactiveCli-6IAEHDBF.js 1.32 MB +1.32 MB (new file) 🆕
./bundle/liteRtServerManager-R23FU2RJ.js 2.11 kB +2.11 kB (new file) 🆕
./bundle/oauth2-provider-2ORUEV34.js 9.16 kB +9.16 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/bundled/third_party/index.js 8 MB 0 B
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-5PS3AYFU.js 1.18 kB 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-RJTRUG2J.js 39.8 kB 0 B
./bundle/chunk-XRLFHCHC.js 1.97 MB 0 B
./bundle/cleanup-YSNNIHOD.js 0 B -932 B (removed) 🏆
./bundle/devtools-36NN55EP.js 696 kB 0 B
./bundle/dist-T73EYRDX.js 356 B 0 B
./bundle/events-XB7DADIJ.js 418 B 0 B
./bundle/examples/hooks/scripts/on-start.js 188 B 0 B
./bundle/examples/mcp-server/example.js 1.43 kB 0 B
./bundle/gemini.js 5.1 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/memoryDiscovery-FN3IAPBT.js 980 B 0 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 222 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 229 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 13.4 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B
./bundle/src-QVCVGIUX.js 47 kB 0 B
./bundle/start-C7CXLYJK.js 0 B -652 B (removed) 🏆
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/cleanup-WL224V7I.js 932 B +932 B (new file) 🆕
./bundle/start-JYBUV2N3.js 652 B +652 B (new file) 🆕

compressed-size-action

@Adib234 Adib234 closed this Apr 13, 2026
@Adib234 Adib234 reopened this Apr 13, 2026
@gemini-cli gemini-cli Bot added the area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality label Apr 13, 2026
This commit resolves the merge conflicts that were present in several SVG snapshot files by regenerating them via 'vitest run -u'.
This commit addresses feedback by setting autoExecute to false for the enhance command, filtering out 'thought' parts from model responses, and sanitizing the output to prevent prompt injection.
@akh64bit

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! I've pushed a new commit that addresses these issues:

  1. autoExecute is now set to false so the command won't fire prematurely from autocomplete.
  2. The response parsing logic has been updated to explicitly filter out 'thought' parts, and the output is now sanitized (stripping newlines and ] characters) to prevent prompt injection. I also added a unit test to verify this behavior.

@akh64bit

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I have fully addressed the comments by gemini-code-assist:

  1. autoExecute: Changed autoExecute to false in enhanceCommand.ts to prevent the command from firing immediately when selected via autocomplete without arguments.
  2. Output Parsing & Sanitization: Updated the response parsing to find the first text part that isn't a thought (!'thought' in part), and sanitized the output by removing newlines and context-breaking characters (]) to prevent prompt injection. Added unit tests to cover this behavior.

@akh64bit
akh64bit requested a review from a team as a code owner April 28, 2026 22:01
@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt priority/p3 Backlog - a good idea but not currently a priority. labels May 8, 2026
@sehoon38

Copy link
Copy Markdown
Contributor

Per our guidelines, we do not accept pull requests from external contributors unless they are linked to issues with the 'help wanted' label. Thank you for understanding!

@sehoon38 sehoon38 closed this May 29, 2026
auto-merge was automatically disabled May 29, 2026 01:44

Pull request was closed

@sripasg sripasg added the size/l A large sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality area/core Issues related to User Interface, OS Support, Core Functionality area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. priority/p2 Important but can be addressed in a future release. priority/p3 Backlog - a good idea but not currently a priority. size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add /enhance command to improve user prompts

4 participants