-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: add execute_slash_command tool for LLM slash command execution #7472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| # Slash Command Tool Implementation Plan | ||
|
|
||
| ## Overview | ||
|
|
||
| Add a new tool `execute_slash_command` that allows the LLM to trigger slash commands within the Roo-Code system. This will enable the LLM to programmatically execute commands that are typically invoked by users through the chat interface. | ||
|
|
||
| ## Background | ||
|
|
||
| Currently, the system has various slash commands that users can invoke manually (like `/review`, `/mode`, etc.). The LLM cannot directly trigger these commands, limiting its ability to orchestrate complex workflows that might benefit from using these commands. | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| ### 1. Tool Definition | ||
|
|
||
| - **Tool Name**: `execute_slash_command` | ||
| - **Purpose**: Execute slash commands programmatically | ||
| - **Parameters**: | ||
| - `command`: The slash command to execute (e.g., "review", "mode", etc.) | ||
| - `args`: Optional arguments for the command (as a string) | ||
|
|
||
| ### 2. Architecture | ||
|
|
||
| #### Component Structure: | ||
|
|
||
| ``` | ||
| src/ | ||
| ├── shared/ | ||
| │ └── tools.ts # Add ExecuteSlashCommandToolUse interface | ||
| ├── core/ | ||
| │ ├── tools/ | ||
| │ │ └── executeSlashCommandTool.ts # New tool implementation | ||
| │ └── assistant-message/ | ||
| │ └── presentAssistantMessage.ts # Add case for execute_slash_command | ||
| └── tests/ | ||
| └── executeSlashCommandTool.spec.ts # Tests for the new tool | ||
| ``` | ||
|
|
||
| ### 3. Key Components | ||
|
|
||
| #### A. Type Definition (src/shared/tools.ts) | ||
|
|
||
| ```typescript | ||
| export interface ExecuteSlashCommandToolUse extends ToolUse { | ||
| name: "execute_slash_command" | ||
| params: Partial<Pick<Record<ToolParamName, string>, "command" | "args">> | ||
| } | ||
| ``` | ||
|
|
||
| #### B. Tool Implementation (src/core/tools/executeSlashCommandTool.ts) | ||
|
|
||
| The tool will: | ||
|
|
||
| 1. Parse the command and arguments | ||
| 2. Validate the command exists and is allowed | ||
| 3. Execute the command through the appropriate handler | ||
| 4. Return the result or error | ||
|
|
||
| #### C. Integration Points | ||
|
|
||
| 1. Add to tool registry in `TOOL_DISPLAY_NAMES` | ||
| 2. Add to tool groups if needed | ||
| 3. Add case in `presentAssistantMessage.ts` | ||
| 4. Update system prompt to include the new tool | ||
|
|
||
| ### 4. Command Execution Strategy | ||
|
|
||
| Since slash commands are typically handled through the chat interface and may involve complex interactions with the Task instance, we have several options: | ||
|
|
||
| **Option 1: Direct Command Execution** | ||
|
|
||
| - Parse and execute commands directly within the tool | ||
| - Requires mapping each command to its implementation | ||
|
|
||
| **Option 2: Command Router Pattern** | ||
|
|
||
| - Create a command router that maps command names to handlers | ||
| - More extensible for future commands | ||
|
|
||
| **Option 3: Leverage Existing Infrastructure** | ||
|
|
||
| - Use the existing command handling infrastructure if available | ||
| - Most consistent with current architecture | ||
|
|
||
| **Recommended: Option 2** - Command Router Pattern for extensibility | ||
|
|
||
| ### 5. Security Considerations | ||
|
|
||
| 1. **Command Whitelist**: Only allow specific commands to be executed | ||
| 2. **Permission Checks**: Ensure the LLM respects mode restrictions | ||
| 3. **Argument Validation**: Validate and sanitize command arguments | ||
| 4. **Audit Logging**: Log all slash command executions for debugging | ||
|
|
||
| ### 6. Supported Commands (Initial) | ||
|
|
||
| For the initial implementation, support these commands: | ||
|
|
||
| - `/review` - Trigger code review | ||
| - `/mode [mode_name]` - Switch modes | ||
| - `/checkpoint` - Create a checkpoint | ||
| - `/diff` - Show diff view | ||
| - `/test` - Run tests | ||
|
|
||
| ### 7. Error Handling | ||
|
|
||
| 1. Invalid command: Return clear error message | ||
| 2. Missing arguments: Provide helpful feedback | ||
| 3. Permission denied: Explain why command cannot be executed | ||
| 4. Command failure: Return detailed error information | ||
|
|
||
| ### 8. Testing Strategy | ||
|
|
||
| 1. Unit tests for the tool implementation | ||
| 2. Integration tests for command execution | ||
| 3. Test permission checks and restrictions | ||
| 4. Test error scenarios | ||
|
|
||
| ### 9. Documentation | ||
|
|
||
| 1. Update tool documentation | ||
| 2. Add examples to system prompt | ||
| 3. Document supported commands and their arguments | ||
|
|
||
| ## Implementation Steps | ||
|
|
||
| 1. **Phase 1: Core Implementation** | ||
|
|
||
| - Create type definitions | ||
| - Implement basic tool structure | ||
| - Add to tool registry | ||
|
|
||
| 2. **Phase 2: Command Handling** | ||
|
|
||
| - Implement command router | ||
| - Add initial command handlers | ||
| - Implement validation and security | ||
|
|
||
| 3. **Phase 3: Integration** | ||
|
|
||
| - Integrate with presentAssistantMessage | ||
| - Update system prompt | ||
| - Add to tool groups | ||
|
|
||
| 4. **Phase 4: Testing & Documentation** | ||
| - Write comprehensive tests | ||
| - Document the feature | ||
| - Add usage examples | ||
|
|
||
| ## Success Criteria | ||
|
|
||
| 1. LLM can successfully execute slash commands | ||
| 2. Commands respect mode restrictions | ||
| 3. Clear error messages for invalid commands | ||
| 4. All tests pass | ||
| 5. No regression in existing functionality | ||
|
|
||
| ## Future Enhancements | ||
|
|
||
| 1. Support for more complex command arguments | ||
| 2. Command chaining capabilities | ||
| 3. Custom command definitions | ||
| 4. Command history and undo functionality | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { ToolArgs } from "./types" | ||
|
|
||
| export function getExecuteSlashCommandDescription(args: ToolArgs): string { | ||
| return `## execute_slash_command | ||
| Description: Execute slash commands programmatically. This tool allows you to trigger commands that are typically invoked by users through the chat interface using the "/" prefix. | ||
| Parameters: | ||
| - slash_command: (required) The name of the slash command to execute (without the "/" prefix). Available commands: | ||
| - review: Trigger code review for current changes (requires args like "slack comment: <message>" or "github issue #123") | ||
| - mode: Switch to a different mode (requires mode name as args, e.g., "code", "architect", "debug") | ||
| - checkpoint: Create a checkpoint of current changes | ||
| - diff: Show diff view for current changes | ||
| - test: Run tests for the project (optionally specify test command as args) | ||
| - args: (optional) Arguments to pass to the slash command. Required for some commands like "review" and "mode". | ||
|
|
||
| Usage: | ||
| <execute_slash_command> | ||
| <slash_command>command_name</slash_command> | ||
| <args>optional arguments</args> | ||
| </execute_slash_command> | ||
|
|
||
| Examples: | ||
|
|
||
| 1. Trigger a code review: | ||
| <execute_slash_command> | ||
| <slash_command>review</slash_command> | ||
| <args>slack comment: Please review the authentication implementation</args> | ||
| </execute_slash_command> | ||
|
|
||
| 2. Switch to architect mode: | ||
| <execute_slash_command> | ||
| <slash_command>mode</slash_command> | ||
| <args>architect</args> | ||
| </execute_slash_command> | ||
|
|
||
| 3. Create a checkpoint: | ||
| <execute_slash_command> | ||
| <slash_command>checkpoint</slash_command> | ||
| </execute_slash_command> | ||
|
|
||
| 4. Show diff view: | ||
| <execute_slash_command> | ||
| <slash_command>diff</slash_command> | ||
| </execute_slash_command> | ||
|
|
||
| 5. Run tests with custom command: | ||
| <execute_slash_command> | ||
| <slash_command>test</slash_command> | ||
| <args>npm run test:unit</args> | ||
| </execute_slash_command> | ||
|
|
||
| Note: Some commands may have limited functionality when executed programmatically compared to user invocation. The tool will provide feedback if a command cannot be fully executed.` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This planning document is helpful but might get lost here. Consider either:
What do you think would be most helpful for future maintainers?