Skip to content

Commit fdbf72d

Browse files
committed
feat: add run_slash_command tool for executing slash commands
- Added new tool to allow LLM to run existing slash commands - Integrated with existing command service for retrieving commands - Added comprehensive unit tests with 100% coverage - Updated type definitions and tool prompts - Tool supports both command name and optional arguments
1 parent d4a16f4 commit fdbf72d

File tree

7 files changed

+520
-0
lines changed

7 files changed

+520
-0
lines changed

packages/types/src/tool.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const toolNames = [
3434
"fetch_instructions",
3535
"codebase_search",
3636
"update_todo_list",
37+
"run_slash_command",
3738
] as const
3839

3940
export const toolNamesSchema = z.enum(toolNames)

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { attemptCompletionTool } from "../tools/attemptCompletionTool"
2828
import { newTaskTool } from "../tools/newTaskTool"
2929

3030
import { updateTodoListTool } from "../tools/updateTodoListTool"
31+
import { runSlashCommandTool } from "../tools/runSlashCommandTool"
3132

3233
import { formatResponse } from "../prompts/responses"
3334
import { validateToolUse } from "../tools/validateToolUse"
@@ -221,6 +222,8 @@ export async function presentAssistantMessage(cline: Task) {
221222
const modeName = getModeBySlug(mode, customModes)?.name ?? mode
222223
return `[${block.name} in ${modeName} mode: '${message}']`
223224
}
225+
case "run_slash_command":
226+
return `[${block.name} for '${block.params.command}'${block.params.args ? ` with args: ${block.params.args}` : ""}]`
224227
}
225228
}
226229

@@ -546,6 +549,9 @@ export async function presentAssistantMessage(cline: Task) {
546549
askFinishSubTaskApproval,
547550
)
548551
break
552+
case "run_slash_command":
553+
await runSlashCommandTool(cline, block, askApproval, handleError, pushToolResult, removeClosingTag)
554+
break
549555
}
550556

551557
break

src/core/prompts/tools/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { getSwitchModeDescription } from "./switch-mode"
2525
import { getNewTaskDescription } from "./new-task"
2626
import { getCodebaseSearchDescription } from "./codebase-search"
2727
import { getUpdateTodoListDescription } from "./update-todo-list"
28+
import { getRunSlashCommandDescription } from "./run-slash-command"
2829
import { CodeIndexManager } from "../../../services/code-index/manager"
2930

3031
// Map of tool names to their description functions
@@ -56,6 +57,7 @@ const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined>
5657
apply_diff: (args) =>
5758
args.diffStrategy ? args.diffStrategy.getToolDescription({ cwd: args.cwd, toolOptions: args.toolOptions }) : "",
5859
update_todo_list: (args) => getUpdateTodoListDescription(args),
60+
run_slash_command: () => getRunSlashCommandDescription(),
5961
}
6062

6163
export function getToolDescriptionsForMode(
@@ -164,4 +166,5 @@ export {
164166
getInsertContentDescription,
165167
getSearchAndReplaceDescription,
166168
getCodebaseSearchDescription,
169+
getRunSlashCommandDescription,
167170
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Generates the run_slash_command tool description.
3+
*/
4+
export function getRunSlashCommandDescription(): string {
5+
return `## run_slash_command
6+
Description: Execute a slash command to get specific instructions or content. Slash commands are predefined templates that provide detailed guidance for common tasks. Commands can be built-in, defined globally, or project-specific.
7+
8+
Parameters:
9+
- command: (required) The name of the slash command to execute (e.g., "init", "test", "deploy")
10+
- args: (optional) Additional arguments or context to pass to the command
11+
12+
Usage:
13+
<run_slash_command>
14+
<command>command_name</command>
15+
<args>optional arguments</args>
16+
</run_slash_command>
17+
18+
Examples:
19+
20+
1. Running the init command to analyze a codebase:
21+
<run_slash_command>
22+
<command>init</command>
23+
</run_slash_command>
24+
25+
2. Running a command with additional context:
26+
<run_slash_command>
27+
<command>test</command>
28+
<args>focus on integration tests</args>
29+
</run_slash_command>
30+
31+
Note: Available commands depend on the project and global configuration. The tool will list available commands if an invalid command is specified. Commands can be:
32+
- Built-in: Predefined commands like "init" for codebase analysis
33+
- Global: Custom commands defined in ~/.roo/commands/
34+
- Project: Project-specific commands defined in .roo/commands/
35+
36+
The command content will be returned for you to execute or follow as instructions.`
37+
}

0 commit comments

Comments
 (0)