Skip to content

fix(cli): Polish shell autocomplete rendering to be a little more shell native feeling.#20931

Merged
jacob314 merged 5 commits intomainfrom
jacob314_fix_shell
Mar 4, 2026
Merged

fix(cli): Polish shell autocomplete rendering to be a little more shell native feeling.#20931
jacob314 merged 5 commits intomainfrom
jacob314_fix_shell

Conversation

@jacob314
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 commented Mar 3, 2026

Summary

Render shell completions as ghost text
Fixes #20930

@jacob314 jacob314 requested a review from a team as a code owner March 3, 2026 07:29
jacob314 added 4 commits March 2, 2026 23:29
Update the shell completion behavior to align with standard shell practices. Show common prefix as ghost text. Pressing tab once autocompletes the ghost text. Pressing tab again explicitly shows the suggestion list.
…ing space

Immediately clear suggestions during render if the token range has changed, ensuring stale ghost text (e.g. 'ls ls') is never rendered.
@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 significantly enhances the user experience for shell completion within the CLI. It addresses issues related to the visibility and interaction of suggestions, particularly when using the tab key. By introducing more precise control over when suggestions and ghost text are displayed, and by preventing stale completion data from appearing, the changes aim to make the shell prompt more intuitive and robust for users.

Highlights

  • Improved Shell Completion Visibility: Introduced new state and logic to control when shell suggestions are visible, preventing flickering and ensuring suggestions appear at appropriate times, especially with tab completion.
  • Refined Tab Key Behavior: Modified the tab key handling in shell mode to correctly accept prompt completions and to force the display of shell suggestions when appropriate, enhancing the interactive experience.
  • Enhanced Ghost Text Logic: Implemented a getCommonPrefix utility and refined the ghost text generation for shell completions, ensuring ghost text is only shown when it provides a meaningful completion and preventing stale ghost text.
  • Stale Suggestion Prevention: Added an activeStart state to useShellCompletion to immediately clear stale suggestions when the token range changes, improving the responsiveness and accuracy of the completion UI.
Changelog
  • packages/cli/src/ui/components/InputPrompt.tsx
    • Added forceShowShellSuggestions state to manage suggestion visibility.
    • Introduced getActiveCompletion, isShellSuggestionsVisible, and shouldShowSuggestions for dynamic suggestion display logic.
    • Updated conditions for ShellModeActiveIndicator's isActive prop to incorporate isShellSuggestionsVisible.
    • Modified isSuggestionsNav logic to use the new shouldShowSuggestions variable.
    • Implemented logic to reset forceShowShellSuggestions when non-tab keys are pressed.
    • Adjusted tab key handling in shell mode to accept prompt completions and force shell suggestions.
    • Updated conditions for ! key and escape key presses to consider isShellSuggestionsVisible.
    • Modified SUBMIT and COMPLETION_UP/DOWN key handling to respect isShellSuggestionsVisible.
    • Removed redundant getActiveCompletion and shouldShowSuggestions definitions.
  • packages/cli/src/ui/hooks/useCommandCompletion.test.tsx
    • Added activeStart property to the shellCompletionRange mock object.
    • Included new test cases to verify ghost text behavior when typed text exceeds the common prefix.
    • Added a test to confirm ghost text clears after a user types a space following an exact match.
  • packages/cli/src/ui/hooks/useCommandCompletion.tsx
    • Introduced a new utility function getCommonPrefix to find the longest common prefix among an array of strings.
    • Refactored promptCompletion to use useMemo for optimized ghost text generation.
    • Implemented custom logic for shell completion ghost text, including common prefix calculation, appending spaces for single suggestions, and preventing ghost text for exact matches or when activeStart does not match completionStart.
  • packages/cli/src/ui/hooks/useShellCompletion.ts
    • Imported useState hook for managing component state.
    • Added activeStart to the UseShellCompletionReturn interface.
    • Introduced an activeStart state variable to track the start position of the active completion token.
    • Implemented logic to immediately clear suggestions and reset activeStart if the completionStart changes while completion is enabled, preventing stale suggestions.
    • Updated calls to setSuggestions to also set the activeStart value.
    • Added completionStart to the dependencies array of the useCallback hook.
    • Reset activeStart to -1 when shell completion is disabled.
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.

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

  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-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 Mar 3, 2026
Copy link
Copy Markdown
Contributor

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

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 significant improvements to the shell completion experience by adding an inline 'ghost text' feature for command completions and changing the behavior of shell suggestions to be hidden by default, appearing only on Tab. It also addresses potential race conditions and UI flickering with stale suggestions by introducing a mechanism to track the validity of completion data (activeStart). However, a high-severity command injection vulnerability was identified on Windows due to missing shell escaping for file paths containing metacharacters; it is recommended to implement proper quoting for Windows paths in the escapeShellPath function to mitigate this. Additionally, one issue was found in useCommandCompletion.tsx where a condition appears to be unreachable.

Comment on lines +276 to +278
if (textToInsert === query) {
return basePromptCompletion;
}
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

This if condition appears to be unreachable. The preceding if statement on line 258 ensures that commonPrefix.length > query.length. Since textToInsert is derived from commonPrefix (it's either commonPrefix or commonPrefix + ' '), its length will always be greater than query.length. Therefore, textToInsert === query can never be true. This block of code and its preceding comment can be safely removed to improve clarity.

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.

if true, we should fix?

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 3, 2026

Size Change: +3.38 kB (+0.01%)

Total Size: 25.9 MB

Filename Size Change
./bundle/gemini.js 25.5 MB +3.38 kB (+0.01%)
ℹ️ View Unchanged
Filename Size
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB

compressed-size-action

@jacob314 jacob314 changed the title Jacob314 fix shell Polish shell autocomplete rendering to be a little more shell native feeling. Mar 3, 2026
@jacob314 jacob314 changed the title Polish shell autocomplete rendering to be a little more shell native feeling. fix(cli): Polish shell autocomplete rendering to be a little more shell native feeling. Mar 3, 2026
@jacob314 jacob314 enabled auto-merge March 4, 2026 00:56
Copy link
Copy Markdown
Contributor

@abhipatel12 abhipatel12 left a comment

Choose a reason for hiding this comment

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

LGTM

@jacob314 jacob314 added this pull request to the merge queue Mar 4, 2026
@abhipatel12 abhipatel12 removed this pull request from the merge queue due to a manual request Mar 4, 2026
@jacob314 jacob314 force-pushed the jacob314_fix_shell branch from 3ca1ea4 to 49c165e Compare March 4, 2026 06:41
@jacob314 jacob314 enabled auto-merge March 4, 2026 06:41
@jacob314
Copy link
Copy Markdown
Contributor Author

jacob314 commented Mar 4, 2026

Cleaned up dead code and did some minor refactors using /review-frontend to de-slop the code a bit.

@jacob314 jacob314 added this pull request to the merge queue Mar 4, 2026
Merged via the queue into main with commit 12957ea Mar 4, 2026
27 checks passed
@jacob314 jacob314 deleted the jacob314_fix_shell branch March 4, 2026 07:06
neeraj-par pushed a commit to neeraj-par/gemini-cli that referenced this pull request Mar 4, 2026
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
struckoff pushed a commit to struckoff/gemini-cli that referenced this pull request Mar 6, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
yashodipmore pushed a commit to yashodipmore/geemi-cli that referenced this pull request Mar 21, 2026
SUNDRAM07 pushed a commit to SUNDRAM07/gemini-cli that referenced this pull request Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell completions are too in your face

2 participants