google-gemini / google-gemini/gemini-cli
refactor(cli): optimize slash command resolution parsing with pre-computed map
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### What happened?
Currently, slash command resolution in [commands.ts](https://github.com/google-gemini/gemini-cli/blob/main/packages/cli/src/utils/commands.ts#L39-L43) uses a two-pass linear search to match commands and aliases:
` ypescript
// First pass: check for an exact match on the primary command name.
let foundCommand = currentCommands.find((cmd) => cmd.name === part);
// Second pass: if no primary name matches, check for an alias.
if (!foundCommand) {
foundCommand = currentCommands.find((cmd) =>
cmd.altNames?.includes(part),
);
}
`
### What did you expect to happen?
For better performance and architectural clarity, this two-pass search could be replaced. A more optimal approach would be to pre-compute a single lookup map in CommandService.ts that resolves all name and alias conflicts during the initial loading phase. The processor would then perform a single, fast O(1) lookup on that map.
### Client information
N/A - Architectural Refactoring
Contributor guide
Research direction
Start with commands.ts, then trace command loading in CommandService.ts. Define how primary names and aliases are represented in the pre-computed lookup map, including conflict resolution during initial loading. Done means slash command resolution uses one map lookup while preserving existing name and alias behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100