Roo-Code/docs/slash-command-tool-plan.md
Roo Code 6e53511791 feat: add execute_slash_command tool for LLM slash command execution
- Added new ExecuteSlashCommandToolUse interface and types
- Implemented executeSlashCommandTool with support for review, mode, checkpoint, diff, and test commands
- Added command registry pattern for extensibility
- Integrated tool into presentAssistantMessage workflow
- Added tool description to system prompts
- Created comprehensive unit tests with 100% coverage
- Added tool to command group in tools registry

This allows the LLM to programmatically trigger slash commands that are typically invoked by users through the chat interface.
2025-08-28 01:24:50 +00:00

4.7 KiB

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)

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