refactor: refactor slash command parsing to a util function.#8381
Conversation
There was a problem hiding this comment.
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.tsinto 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.tswas introduced to house theparseSlashCommandfunction, accompanied by comprehensive unit tests inpackages/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
-
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. ↩
There was a problem hiding this comment.
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.
allenhutchison
left a comment
There was a problem hiding this comment.
This is a great refactoring. Really helps to clean up the ui hook and separate concerns for making this usable in non-interactive mode.
c079421
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.tsas it assumesargsandpathsare at a high level scope.Reviewer Test Plan
No regressions with slash commands (custom, built-in, MCP prompts).
Testing Matrix
Linked issues / bugs
This PR makes progress on #5435