Skip to content

Fix(command): line/block Comments Incorrectly Parsed as Slash Commands#6957

Merged
NTaylorMullen merged 8 commits intogoogle-gemini:mainfrom
lifefloating:fix-6953
Aug 26, 2025
Merged

Fix(command): line/block Comments Incorrectly Parsed as Slash Commands#6957
NTaylorMullen merged 8 commits intogoogle-gemini:mainfrom
lifefloating:fix-6953

Conversation

@lifefloating
Copy link
Copy Markdown
Contributor

TLDR

Fixed an issue where JavaScript comments starting with // were incorrectly parsed as slash commands, causing "Unknown command" errors and wrong UI coloring. The fix enhances the isSlashCommand function to properly distinguish between legitimate commands (/help) and code comments (//comment), ensuring comments are treated as normal text and sent directly to Gemini.

Key changes:

  • Enhanced command recognition logic to exclude // and /* comments
  • Updated UI components to use proper command detection
  • Added comprehensive test coverage
  • Fixed pink/purple UI coloring issue for comments

Dive Deeper

Root Cause Analysis

The issue occurred at multiple levels:

  1. Command Recognition Logic: The isSlashCommand function used simple startsWith('/') check, which caught both legitimate commands (/help) and JavaScript comments (//comment)

  2. UI Color Logic: Multiple UI components directly used text.startsWith('/') for styling decisions instead of using the proper isSlashCommand function

  3. Processing Flow: All inputs starting with / were unconditionally passed to the slash command processor, even when they weren't actual commands

Problem Example

// check if variants base info all filled.
if(!objDetCtrl.variantInfo.baseInfo.title) {
    toastr.error('[Title] cannot be empty.')
    return false
}

This resulted in:

  • ✗ "Unknown command" error
  • ✗ Pink/purple UI coloring (command style)
  • ✗ Input processed as potential command instead of normal text

Testing Matrix

🍏 🪟 🐧
npm run

Linked issues / bugs

#6953
#2240

@lifefloating lifefloating requested a review from a team as a code owner August 24, 2025 08:31
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.

Summary of Changes

Hello @lifefloating, 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 addresses a critical bug where JavaScript and C-style comments were mistakenly parsed as slash commands within the CLI, leading to "Unknown command" errors and incorrect UI coloring. The core of the fix involves refining the isSlashCommand utility function to accurately distinguish between actual commands and code comments. This improved logic is then consistently applied across various UI components and the command processing flow, ensuring that comments are treated as normal text and the UI reflects the correct state.

Highlights

  • Command Recognition Logic: The isSlashCommand utility function has been updated to correctly differentiate between legitimate slash commands (e.g., /help) and code comments (e.g., // comment or /* comment */). It now explicitly excludes strings starting with // or /*.
  • UI Component Updates: UI components like SuggestionsDisplay.tsx and UserMessage.tsx that previously used text.startsWith('/') for styling and command mode detection now correctly utilize the enhanced isSlashCommand utility function. This resolves the incorrect pink/purple coloring for comments.
  • Command Processing Flow: The useGeminiStream hook now only attempts to process a query as a slash command if isSlashCommand returns true, preventing comments from being sent to the slash command processor.
  • Test Coverage: New test cases have been added to useCommandCompletion.test.ts, useGeminiStream.test.tsx, and commandUtils.test.ts to ensure that JavaScript and C-style comments are correctly identified as non-commands and do not trigger command-related behaviors or prompt completions.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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.

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 effectively resolves the issue of JavaScript and C-style comments being misinterpreted as slash commands. The approach of centralizing the logic in the isSlashCommand utility function and updating all call sites is clean and correct. The addition of comprehensive unit tests for both the utility function and its usage in various hooks is excellent. I have one suggestion to make the new isSlashCommand function more concise and maintainable, but overall this is a solid contribution.

Comment thread packages/cli/src/ui/utils/commandUtils.ts
@lifefloating
Copy link
Copy Markdown
Contributor Author

lifefloating commented Aug 24, 2025

Examples:

Before:
image

After:
image

The test code examples in the related issue can also pass.

@abhipatel12 abhipatel12 self-requested a review August 24, 2025 20:05
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.

Hey! Thanks for the contribution! Left a few comments. Lmk what you think and then I can approve!

Comment thread packages/cli/src/ui/components/messages/UserMessage.tsx Outdated
Comment thread packages/cli/src/ui/hooks/useCommandCompletion.test.ts Outdated
Comment thread packages/cli/src/ui/hooks/useGeminiStream.test.tsx Outdated
Comment thread packages/cli/src/ui/hooks/useGeminiStream.ts Outdated
Comment thread packages/cli/src/ui/utils/commandUtils.test.ts Outdated
Comment thread packages/cli/src/ui/utils/commandUtils.ts Outdated
@lifefloating lifefloating changed the title Fix(command): JavaScript/C Comments Incorrectly Parsed as Slash Commands Fix(command): line/block Comments Incorrectly Parsed as Slash Commands Aug 25, 2025
@lifefloating
Copy link
Copy Markdown
Contributor Author

Hi @abhipatel12
Thanks for the thoughtful review feedback!

You're absolutely right that comments such as these are not limited to C++/JavaScript.
The generic terminology "line comments" and "block comments" is much more appropriate and language-agnostic.

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.

Looks great, thanks for making the changes!

LGTM, I'll get this set up for final approval and merged. Thanks again for the contribution.

@NTaylorMullen NTaylorMullen added this pull request to the merge queue Aug 26, 2025
Merged via the queue into google-gemini:main with commit 45fff8f Aug 26, 2025
18 checks passed
agmsb pushed a commit that referenced this pull request Aug 26, 2025
#6957)

Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Edilmo pushed a commit to Edilmo/gemini-cli that referenced this pull request Sep 1, 2025
google-gemini#6957)

Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
acoliver referenced this pull request in vybestack/llxprt-code Sep 11, 2025
…s (#6957)

Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
involvex pushed a commit to involvex/gemini-cli that referenced this pull request Sep 11, 2025
google-gemini#6957)

Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
reconsumeralization pushed a commit to reconsumeralization/gemini-cli that referenced this pull request Sep 19, 2025
google-gemini#6957)

Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants