Conversation
|
Hi @jacob314, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
Summary of ChangesHello @jacob314, 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 command-line interface's autocompletion system by addressing several usability, stability, and platform-specific issues. It refines the submission behavior to prevent unintended actions, eliminates UI flickering during completion, and reduces visual clutter by intelligently disabling completion for empty prompts. Furthermore, it improves the autocompletion experience for Windows users by including built-in commands and optimizes suggestion relevance by prioritizing shorter command names. The underlying completion logic has also been refactored for better maintainability and to prevent race conditions. Highlights
Changelog
Activity
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 introduces valuable fixes and refactorings to the shell autocompletion functionality, enhancing user experience by addressing issues like accidental submission, UI flicker, and suggestion relevance, and improving overall robustness, including support for Windows shell built-ins and improved navigation. However, a critical high-severity command injection vulnerability was identified on Windows. The current implementation fails to properly escape or quote shell metacharacters in autocompleted filenames and commands, which could lead to arbitrary command execution. It is strongly recommended to address this by ensuring proper quoting/escaping within the escapeShellPath utility. Additionally, a performance improvement can be achieved by adding a dependency array to a useEffect hook to prevent it from running on every render.
|
Size Change: +858 B (0%) Total Size: 25.7 MB ℹ️ View Unchanged
|
… autocomplete suggestion When using shell autocomplete, pressing Down then Up returns the activeSuggestionIndex to 0. If the first suggestion happened to be an exact match, the InputPrompt would bypass the normal autocomplete logic and eagerly submit the prompt on Enter because it ignored whether the user had actively navigated. This fix updates the isPerfectMatch check to require that the user has not navigated the suggestions list, ensuring that explicitly selected items always autocomplete instead of submitting. fix(cli): prevent autocomplete UI flicker by decoupling disabled state reset from completion refresh When typing outside of shell mode (e.g., using `@` completion), the `useShellCompletion` hook was continuously re-rendering and executing its `useEffect` because `performCompletion` was recreated on every keystroke (since its `query` dependency changed). Because `enabled` was false, the effect unconditionally called `setSuggestions([])`, rapidly overriding the suggestions populated by `useAtCompletion` and causing severe UI flickering. This splits the effect to ensure `setSuggestions([])` is only called once when `enabled` becomes false, stabilizing the suggestions list. fix(cli): disable shell autocompletion on completely empty prompts To reduce visual noise and distraction, autocompletion is now suppressed when the shell prompt is entirely empty (or only contains whitespace). It remains active as soon as the user starts typing or moves the cursor to a position that would suggest paths/commands. fix(cli): add Windows shell built-in commands to autocomplete list On Windows, many common commands like `dir`, `copy`, `del`, etc., are internal to `cmd.exe` and do not exist as separate executables on the disk. This updates `scanPathExecutables` to explicitly include these built-ins when running on Windows, ensuring a consistent autocomplete experience for Windows users. test(cli): update snapshots for shell autocompletion refinements fix(cli): prioritize shorter command names in shell autocomplete results refactor(cli): simplify command completion orchestration and fix shell cache race - Simplified `useCommandCompletion.tsx` by moving shell-specific tokenization into `useShellCompletion.ts`. - Reverted most changes to the `useCommandCompletion` `useMemo` block to keep it clean and consistent with other modes. - Fixed a potential race condition in `useShellCompletion.ts` where `scanPathExecutables` could be called multiple times if it was slow. It now caches the Promise itself. - Updated tests to match the refined hook interfaces.
460cc02 to
3cfdbd4
Compare
|
Could you clean up the description? It's a bit hard to read. |
Highlights
useCommandCompletionby moving shell-specific tokenization intouseShellCompletionand addressed a potential race condition inscanPathExecutablesby caching the promise itself.Changelog
useShellCompletionfor testing.useShellCompletionto return default completion range and query.setupMocksto acceptshellSuggestionsandshellCompletionRangefor comprehensive testing.useShellCompletionwithinsetupMocksto simulate its behavior.getTokenAtCursorimport as its logic was moved.useMemoblock to remove shell-specific token parsing, delegating it entirely touseShellCompletion.memoQueryto distinguish the query derived fromuseMemofrom the one returned byuseShellCompletion.completionModelogic to setCompletionMode.IDLEwhen the shell prompt is empty.shellTokenIsCommand,shellTokens,shellCursorIndex, andshellCommandTokenfrom the memoized return value.useShellCompletioncall to passlineandcursorColinstead of pre-parsed tokens.shellCompletionRangeto capture the return value fromuseShellCompletion.queryvariable to correctly useshellCompletionRange.querywhen in shell completion mode.getCompletedTextandgetCompletionRangeto useshellCompletionRangefor shell mode.shellCompletionRangeto the dependency arrays ofuseCallbackfunctions.scanPathExecutablestest to verify the inclusion of specific Windows built-in commands (dir,cls,copy) when running on a Windows platform.useMemohook.scanPathExecutablesto explicitly add a predefined list of Windows built-in commands to the executable list if the operating system is Windows.UseShellCompletionPropsto acceptlineandcursorColinstead of pre-parsed token information.UseShellCompletionReturninterface to define the return type of the hook.getTokenAtCursorlogic into auseMemoblock withinuseShellCompletionto derive token information fromlineandcursorCol.pathCacheReftopathCachePromiseRefto store a Promise, preventing multiple calls toscanPathExecutablesand addressing a potential race condition.performCompletionto prioritize shorter command names in shell autocomplete results.useEffecthooks: one for resetting suggestions whenenabledbecomes false, and another for debounced completion.performCompletionuseCallbackand the debounceduseEffect.useShellCompletionhook to returncompletionStart,completionEnd, andquery.Fixes #20410
How to test, try shell autocomplete and make sure it is reasonable on windows, mac, and linux