Skip to content

refactor: refactor slash command parsing to a util function.#8381

Merged
allenhutchison merged 1 commit into
google-gemini:mainfrom
capachino:refactor-command-parser
Sep 16, 2025
Merged

refactor: refactor slash command parsing to a util function.#8381
allenhutchison merged 1 commit into
google-gemini:mainfrom
capachino:refactor-command-parser

Conversation

@capachino

Copy link
Copy Markdown
Contributor

TLDR

Refactors slash command parsing logic to make progress on Issue #5435 i.e. re-use the same parser in the non-interactive CLI runner.

Dive Deeper

Note: ideally the function would have returned an undefined object if no runnable command was resolved, but that would have required a bit of refactoring in slashCommandProcessor.ts as it assumes args and paths are at a high level scope.

Reviewer Test Plan

No regressions with slash commands (custom, built-in, MCP prompts).

Testing Matrix

🍏 🪟 🐧
npm run X
npx
Docker
Podman - -
Seatbelt X - -

Linked issues / bugs

This PR makes progress on #5435

@capachino capachino requested a review from a team as a code owner September 12, 2025 22:08

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

Summary of Changes

Hello @capachino, 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 refactors the way slash commands are parsed within the CLI. By extracting the command parsing logic into a new, reusable utility function, it centralizes this functionality and paves the way for its integration into a non-interactive CLI runner, which is a key step towards resolving Issue #5435. This change improves modularity and maintainability without altering the existing behavior of slash commands.

Highlights

  • Refactored Slash Command Parsing: The core logic for parsing slash commands has been extracted from slashCommandProcessor.ts into a dedicated utility function.
  • Improved Reusability: This refactoring enables the parsing logic to be reused in other contexts, specifically for a non-interactive CLI runner, which addresses Issue #5435.
  • New Utility Function and Tests: A new file packages/cli/src/utils/commands.ts was introduced to house the parseSlashCommand function, accompanied by comprehensive unit tests in packages/cli/src/utils/commands.test.ts.
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.

@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 effectively refactors the slash command parsing logic into a reusable utility function parseSlashCommand, which is a great step towards improving code structure and reusability for the non-interactive CLI. The new function is well-tested, covering a variety of cases including subcommands, aliases, and edge cases like extra whitespace.

I've found one issue in the new parseSlashCommand function related to handling input strings that don't start with a slash. I've left a detailed comment with a suggestion to make the function more robust. Otherwise, the refactoring is well-executed.

Comment thread packages/cli/src/utils/commands.ts Outdated
@gemini-cli gemini-cli Bot added kind/bug priority/p1 Important and should be addressed in the near term. area/core Issues related to User Interface, OS Support, Core Functionality labels Sep 12, 2025
@allenhutchison allenhutchison self-assigned this Sep 15, 2025

@allenhutchison allenhutchison 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.

This is a great refactoring. Really helps to clean up the ui hook and separate concerns for making this usable in non-interactive mode.

@jerop jerop 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.

🚀

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 15, 2025
@allenhutchison allenhutchison added this pull request to the merge queue Sep 15, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 15, 2025
@allenhutchison allenhutchison added this pull request to the merge queue Sep 15, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 15, 2025
@allenhutchison allenhutchison added this pull request to the merge queue Sep 15, 2025
Merged via the queue into google-gemini:main with commit c079421 Sep 16, 2025
40 of 41 checks passed
nagendrareddy10 pushed a commit to nagendrareddy10/gemini-cli that referenced this pull request Sep 22, 2025
yashv6655 added a commit to yashv6655/gemini-cli that referenced this pull request Sep 22, 2025
thacio added a commit to thacio/auditaria that referenced this pull request Oct 2, 2025
giraffe-tree pushed a commit to giraffe-tree/gemini-cli that referenced this pull request Oct 10, 2025
@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/core Issues related to User Interface, OS Support, Core Functionality priority/p1 Important and should be addressed in the near term. size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants