From d5ac15923a85608c96965a0f1b01b990eadde84a Mon Sep 17 00:00:00 2001 From: "Steven T. Cramer" Date: Mon, 16 Jun 2025 00:03:54 +0700 Subject: [PATCH] Refactor: Move tool directives to individual files in tool-directives directory --- src/core/message-parsing/ParsingState.ts | 3 +- .../directives/ToolDirective.ts | 2 +- src/core/message-parsing/directives/index.ts | 3 + .../AccessMcpResourceToolDirective.ts | 10 ++ .../AskFollowupQuestionToolDirective.ts | 10 ++ .../AttemptCompletionToolDirective.ts | 10 ++ .../BrowserActionToolDirective.ts | 10 ++ .../CodebaseSearchToolDirective.ts | 10 ++ .../ExecuteCommandToolDirective.ts | 11 ++ .../FetchInstructionsToolDirective.ts | 10 ++ .../InsertCodeBlockToolDirective.ts | 10 ++ .../ListCodeDefinitionNamesToolDirective.ts | 10 ++ .../tool-directives/ListFilesToolDirective.ts | 10 ++ .../tool-directives/NewTaskToolDirective.ts | 10 ++ .../tool-directives/ReadFileToolDirective.ts | 10 ++ .../SearchAndReplaceToolDirective.ts | 11 ++ .../SearchFilesToolDirective.ts | 10 ++ .../SwitchModeToolDirective.ts | 10 ++ .../tool-directives/ToolParamName.ts | 46 ++++++ .../tool-directives/ToolResponse.ts | 6 + .../UseMcpToolToolDirective.ts | 10 ++ .../WriteToFileToolDirective.ts | 10 ++ .../directives/tool-directives/index.ts | 21 +++ .../handlers/ToolDirectiveHandler.ts | 3 +- .../parseAssistantMessageV2.ts | 2 +- .../presentAssistantMessage.ts | 3 +- src/core/tools/__tests__/readFileTool.test.ts | 6 +- .../tools/__tests__/writeToFileTool.test.ts | 3 +- src/core/tools/attemptCompletionTool.ts | 3 +- src/core/tools/executeCommandTool.ts | 4 +- src/shared/tools.ts | 133 +----------------- 31 files changed, 264 insertions(+), 146 deletions(-) create mode 100644 src/core/message-parsing/directives/tool-directives/AccessMcpResourceToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/AskFollowupQuestionToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/AttemptCompletionToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/BrowserActionToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/CodebaseSearchToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/ExecuteCommandToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/FetchInstructionsToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/InsertCodeBlockToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/ListCodeDefinitionNamesToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/ListFilesToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/NewTaskToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/ReadFileToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/SearchAndReplaceToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/SearchFilesToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/SwitchModeToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/ToolParamName.ts create mode 100644 src/core/message-parsing/directives/tool-directives/ToolResponse.ts create mode 100644 src/core/message-parsing/directives/tool-directives/UseMcpToolToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/WriteToFileToolDirective.ts create mode 100644 src/core/message-parsing/directives/tool-directives/index.ts diff --git a/src/core/message-parsing/ParsingState.ts b/src/core/message-parsing/ParsingState.ts index debdf25b9d..56a553b901 100644 --- a/src/core/message-parsing/ParsingState.ts +++ b/src/core/message-parsing/ParsingState.ts @@ -1,5 +1,4 @@ -import { TextDirective, Directive, LogDirective, ToolDirective } from "./directives" -import { ToolParamName } from "../../shared/tools" +import { TextDirective, Directive, LogDirective, ToolDirective, ToolParamName } from "./directives" export interface ParsingState { contentBlocks: Directive[] diff --git a/src/core/message-parsing/directives/ToolDirective.ts b/src/core/message-parsing/directives/ToolDirective.ts index 6a9437e67c..29da68773d 100644 --- a/src/core/message-parsing/directives/ToolDirective.ts +++ b/src/core/message-parsing/directives/ToolDirective.ts @@ -1,5 +1,5 @@ import { ToolName } from "@roo-code/types" -import { ToolParamName } from "../../../shared/tools" +import { ToolParamName } from "./tool-directives" export interface ToolDirective { type: "tool_use" diff --git a/src/core/message-parsing/directives/index.ts b/src/core/message-parsing/directives/index.ts index 36f7aa9260..2ecbab16f2 100644 --- a/src/core/message-parsing/directives/index.ts +++ b/src/core/message-parsing/directives/index.ts @@ -2,3 +2,6 @@ export type { Directive } from "./Directive" export type { TextDirective } from "./TextDirective" export type { ToolDirective } from "./ToolDirective" export type { LogDirective } from "./LogDirective" +export type { ToolParamName, ToolResponse } from "./tool-directives" + +export { toolParamNames } from "./tool-directives" diff --git a/src/core/message-parsing/directives/tool-directives/AccessMcpResourceToolDirective.ts b/src/core/message-parsing/directives/tool-directives/AccessMcpResourceToolDirective.ts new file mode 100644 index 0000000000..143441ce7f --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/AccessMcpResourceToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for accessing a resource provided by an MCP server. + */ +export interface AccessMcpResourceToolDirective extends ToolDirective { + name: "access_mcp_resource" + params: Partial, "server_name" | "uri">> +} diff --git a/src/core/message-parsing/directives/tool-directives/AskFollowupQuestionToolDirective.ts b/src/core/message-parsing/directives/tool-directives/AskFollowupQuestionToolDirective.ts new file mode 100644 index 0000000000..c99cdac341 --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/AskFollowupQuestionToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for asking a follow-up question to the user. + */ +export interface AskFollowupQuestionToolDirective extends ToolDirective { + name: "ask_followup_question" + params: Partial, "question" | "follow_up">> +} diff --git a/src/core/message-parsing/directives/tool-directives/AttemptCompletionToolDirective.ts b/src/core/message-parsing/directives/tool-directives/AttemptCompletionToolDirective.ts new file mode 100644 index 0000000000..43d426fb0a --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/AttemptCompletionToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for attempting to complete a task. + */ +export interface AttemptCompletionToolDirective extends ToolDirective { + name: "attempt_completion" + params: Partial, "result" | "command">> +} diff --git a/src/core/message-parsing/directives/tool-directives/BrowserActionToolDirective.ts b/src/core/message-parsing/directives/tool-directives/BrowserActionToolDirective.ts new file mode 100644 index 0000000000..6b75ec9d45 --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/BrowserActionToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for performing browser actions. + */ +export interface BrowserActionToolDirective extends ToolDirective { + name: "browser_action" + params: Partial, "action" | "url" | "coordinate" | "text" | "size">> +} diff --git a/src/core/message-parsing/directives/tool-directives/CodebaseSearchToolDirective.ts b/src/core/message-parsing/directives/tool-directives/CodebaseSearchToolDirective.ts new file mode 100644 index 0000000000..35a066972b --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/CodebaseSearchToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for searching the codebase. + */ +export interface CodebaseSearchToolDirective extends ToolDirective { + name: "codebase_search" + params: Partial, "query" | "path">> +} diff --git a/src/core/message-parsing/directives/tool-directives/ExecuteCommandToolDirective.ts b/src/core/message-parsing/directives/tool-directives/ExecuteCommandToolDirective.ts new file mode 100644 index 0000000000..097d966554 --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/ExecuteCommandToolDirective.ts @@ -0,0 +1,11 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for executing a command on the system. + */ +export interface ExecuteCommandToolDirective extends ToolDirective { + name: "execute_command" + // Pick, "command"> makes "command" required, but Partial<> makes it optional + params: Partial, "command" | "cwd">> +} diff --git a/src/core/message-parsing/directives/tool-directives/FetchInstructionsToolDirective.ts b/src/core/message-parsing/directives/tool-directives/FetchInstructionsToolDirective.ts new file mode 100644 index 0000000000..d895eda3be --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/FetchInstructionsToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for fetching instructions to perform a task. + */ +export interface FetchInstructionsToolDirective extends ToolDirective { + name: "fetch_instructions" + params: Partial, "task">> +} diff --git a/src/core/message-parsing/directives/tool-directives/InsertCodeBlockToolDirective.ts b/src/core/message-parsing/directives/tool-directives/InsertCodeBlockToolDirective.ts new file mode 100644 index 0000000000..6e589e0462 --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/InsertCodeBlockToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for inserting content into a file at a specific line. + */ +export interface InsertCodeBlockToolDirective extends ToolDirective { + name: "insert_content" + params: Partial, "path" | "line" | "content">> +} diff --git a/src/core/message-parsing/directives/tool-directives/ListCodeDefinitionNamesToolDirective.ts b/src/core/message-parsing/directives/tool-directives/ListCodeDefinitionNamesToolDirective.ts new file mode 100644 index 0000000000..2a710ed0ce --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/ListCodeDefinitionNamesToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for listing definition names from source code. + */ +export interface ListCodeDefinitionNamesToolDirective extends ToolDirective { + name: "list_code_definition_names" + params: Partial, "path">> +} diff --git a/src/core/message-parsing/directives/tool-directives/ListFilesToolDirective.ts b/src/core/message-parsing/directives/tool-directives/ListFilesToolDirective.ts new file mode 100644 index 0000000000..85d3d8677f --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/ListFilesToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for listing files and directories. + */ +export interface ListFilesToolDirective extends ToolDirective { + name: "list_files" + params: Partial, "path" | "recursive">> +} diff --git a/src/core/message-parsing/directives/tool-directives/NewTaskToolDirective.ts b/src/core/message-parsing/directives/tool-directives/NewTaskToolDirective.ts new file mode 100644 index 0000000000..005a2fa590 --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/NewTaskToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for creating a new task instance. + */ +export interface NewTaskToolDirective extends ToolDirective { + name: "new_task" + params: Partial, "mode" | "message">> +} diff --git a/src/core/message-parsing/directives/tool-directives/ReadFileToolDirective.ts b/src/core/message-parsing/directives/tool-directives/ReadFileToolDirective.ts new file mode 100644 index 0000000000..3b83aa50fe --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/ReadFileToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for reading the contents of a file. + */ +export interface ReadFileToolDirective extends ToolDirective { + name: "read_file" + params: Partial, "args" | "path" | "start_line" | "end_line">> +} diff --git a/src/core/message-parsing/directives/tool-directives/SearchAndReplaceToolDirective.ts b/src/core/message-parsing/directives/tool-directives/SearchAndReplaceToolDirective.ts new file mode 100644 index 0000000000..8cb46e89f7 --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/SearchAndReplaceToolDirective.ts @@ -0,0 +1,11 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for searching and replacing text or patterns in a file. + */ +export interface SearchAndReplaceToolDirective extends ToolDirective { + name: "search_and_replace" + params: Required, "path" | "search" | "replace">> & + Partial, "use_regex" | "ignore_case" | "start_line" | "end_line">> +} diff --git a/src/core/message-parsing/directives/tool-directives/SearchFilesToolDirective.ts b/src/core/message-parsing/directives/tool-directives/SearchFilesToolDirective.ts new file mode 100644 index 0000000000..f0d4d4f9d0 --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/SearchFilesToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for performing a regex search across files. + */ +export interface SearchFilesToolDirective extends ToolDirective { + name: "search_files" + params: Partial, "path" | "regex" | "file_pattern">> +} diff --git a/src/core/message-parsing/directives/tool-directives/SwitchModeToolDirective.ts b/src/core/message-parsing/directives/tool-directives/SwitchModeToolDirective.ts new file mode 100644 index 0000000000..45da6383c4 --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/SwitchModeToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for switching to a different mode. + */ +export interface SwitchModeToolDirective extends ToolDirective { + name: "switch_mode" + params: Partial, "mode_slug" | "reason">> +} diff --git a/src/core/message-parsing/directives/tool-directives/ToolParamName.ts b/src/core/message-parsing/directives/tool-directives/ToolParamName.ts new file mode 100644 index 0000000000..3f3e7dc10c --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/ToolParamName.ts @@ -0,0 +1,46 @@ +/** + * List of parameter names that can be used in tool directives. + */ +export const toolParamNames = [ + "command", + "path", + "content", + "line_count", + "regex", + "file_pattern", + "recursive", + "action", + "url", + "coordinate", + "text", + "server_name", + "tool_name", + "arguments", + "uri", + "question", + "result", + "diff", + "mode_slug", + "reason", + "line", + "mode", + "message", + "cwd", + "follow_up", + "task", + "size", + "search", + "replace", + "use_regex", + "ignore_case", + "args", + "start_line", + "end_line", + "query", + "args", +] as const + +/** + * Type representing a parameter name for tool directives. + */ +export type ToolParamName = (typeof toolParamNames)[number] diff --git a/src/core/message-parsing/directives/tool-directives/ToolResponse.ts b/src/core/message-parsing/directives/tool-directives/ToolResponse.ts new file mode 100644 index 0000000000..9d85661e0e --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/ToolResponse.ts @@ -0,0 +1,6 @@ +import { Anthropic } from "@anthropic-ai/sdk" + +/** + * Type representing the response from a tool execution. + */ +export type ToolResponse = string | Array diff --git a/src/core/message-parsing/directives/tool-directives/UseMcpToolToolDirective.ts b/src/core/message-parsing/directives/tool-directives/UseMcpToolToolDirective.ts new file mode 100644 index 0000000000..694620e038 --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/UseMcpToolToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for using a tool provided by an MCP server. + */ +export interface UseMcpToolToolDirective extends ToolDirective { + name: "use_mcp_tool" + params: Partial, "server_name" | "tool_name" | "arguments">> +} diff --git a/src/core/message-parsing/directives/tool-directives/WriteToFileToolDirective.ts b/src/core/message-parsing/directives/tool-directives/WriteToFileToolDirective.ts new file mode 100644 index 0000000000..eda995cbab --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/WriteToFileToolDirective.ts @@ -0,0 +1,10 @@ +import { ToolDirective } from "../ToolDirective" +import { ToolParamName } from "./ToolParamName" + +/** + * Directive for writing content to a file. + */ +export interface WriteToFileToolDirective extends ToolDirective { + name: "write_to_file" + params: Partial, "path" | "content" | "line_count">> +} diff --git a/src/core/message-parsing/directives/tool-directives/index.ts b/src/core/message-parsing/directives/tool-directives/index.ts new file mode 100644 index 0000000000..55dec78b20 --- /dev/null +++ b/src/core/message-parsing/directives/tool-directives/index.ts @@ -0,0 +1,21 @@ +export type { ToolResponse } from "./ToolResponse" +export type { ToolParamName } from "./ToolParamName" +export type { ExecuteCommandToolDirective } from "./ExecuteCommandToolDirective" +export type { ReadFileToolDirective } from "./ReadFileToolDirective" +export type { FetchInstructionsToolDirective } from "./FetchInstructionsToolDirective" +export type { WriteToFileToolDirective } from "./WriteToFileToolDirective" +export type { InsertCodeBlockToolDirective } from "./InsertCodeBlockToolDirective" +export type { CodebaseSearchToolDirective } from "./CodebaseSearchToolDirective" +export type { SearchFilesToolDirective } from "./SearchFilesToolDirective" +export type { ListFilesToolDirective } from "./ListFilesToolDirective" +export type { ListCodeDefinitionNamesToolDirective } from "./ListCodeDefinitionNamesToolDirective" +export type { BrowserActionToolDirective } from "./BrowserActionToolDirective" +export type { UseMcpToolToolDirective } from "./UseMcpToolToolDirective" +export type { AccessMcpResourceToolDirective } from "./AccessMcpResourceToolDirective" +export type { AskFollowupQuestionToolDirective } from "./AskFollowupQuestionToolDirective" +export type { AttemptCompletionToolDirective } from "./AttemptCompletionToolDirective" +export type { SwitchModeToolDirective } from "./SwitchModeToolDirective" +export type { NewTaskToolDirective } from "./NewTaskToolDirective" +export type { SearchAndReplaceToolDirective } from "./SearchAndReplaceToolDirective" + +export { toolParamNames } from "./ToolParamName" diff --git a/src/core/message-parsing/handlers/ToolDirectiveHandler.ts b/src/core/message-parsing/handlers/ToolDirectiveHandler.ts index a480aebbb5..4f37558d80 100644 --- a/src/core/message-parsing/handlers/ToolDirectiveHandler.ts +++ b/src/core/message-parsing/handlers/ToolDirectiveHandler.ts @@ -1,8 +1,7 @@ import * as sax from "sax" import { BaseDirectiveHandler } from "./BaseDirectiveHandler" import { ParseContext } from "../ParseContext" -import { ToolParamName } from "../../../shared/tools" -import { ToolDirective } from "../directives" +import { ToolDirective, ToolParamName } from "../directives" export class ToolDirectiveHandler extends BaseDirectiveHandler { readonly tagName: string diff --git a/src/core/message-parsing/parseAssistantMessageV2.ts b/src/core/message-parsing/parseAssistantMessageV2.ts index 3d18994dc1..d54b776e62 100644 --- a/src/core/message-parsing/parseAssistantMessageV2.ts +++ b/src/core/message-parsing/parseAssistantMessageV2.ts @@ -1,6 +1,6 @@ import { type ToolName, toolNames } from "@roo-code/types" import { TextDirective, ToolDirective } from "./directives" -import { ToolParamName, toolParamNames } from "../../shared/tools" +import { ToolParamName, toolParamNames } from "./directives" export type AssistantMessageContent = TextDirective | ToolDirective diff --git a/src/core/message-parsing/presentAssistantMessage.ts b/src/core/message-parsing/presentAssistantMessage.ts index 8d64acef66..6818c322c9 100644 --- a/src/core/message-parsing/presentAssistantMessage.ts +++ b/src/core/message-parsing/presentAssistantMessage.ts @@ -4,10 +4,9 @@ import { serializeError } from "serialize-error" import type { ToolName, ClineAsk, ToolProgressStatus } from "@roo-code/types" import { TelemetryService } from "@roo-code/telemetry" -import type { LogDirective } from "./directives/LogDirective" +import type { LogDirective, ToolParamName, ToolResponse } from "./directives" import { defaultModeSlug, getModeBySlug } from "../../shared/modes" -import type { ToolParamName, ToolResponse } from "../../shared/tools" import { fetchInstructionsTool } from "../tools/fetchInstructionsTool" import { listFilesTool } from "../tools/listFilesTool" diff --git a/src/core/tools/__tests__/readFileTool.test.ts b/src/core/tools/__tests__/readFileTool.test.ts index 1a1b2da0a8..6c215a3bbf 100644 --- a/src/core/tools/__tests__/readFileTool.test.ts +++ b/src/core/tools/__tests__/readFileTool.test.ts @@ -7,7 +7,11 @@ import { readLines } from "../../../integrations/misc/read-lines" import { extractTextFromFile } from "../../../integrations/misc/extract-text" import { parseSourceCodeDefinitionsForFile } from "../../../services/tree-sitter" import { isBinaryFile } from "isbinaryfile" -import { ReadFileToolDirective, ToolParamName, ToolResponse } from "../../../shared/tools" +import { + ToolParamName, + ToolResponse, + ReadFileToolDirective, +} from "../../../core/message-parsing/directives/tool-directives" import { readFileTool } from "../readFileTool" import { formatResponse } from "../../prompts/responses" diff --git a/src/core/tools/__tests__/writeToFileTool.test.ts b/src/core/tools/__tests__/writeToFileTool.test.ts index a8b942bb95..a406647ca3 100644 --- a/src/core/tools/__tests__/writeToFileTool.test.ts +++ b/src/core/tools/__tests__/writeToFileTool.test.ts @@ -6,9 +6,8 @@ import { isPathOutsideWorkspace } from "../../../utils/pathUtils" import { getReadablePath } from "../../../utils/path" import { unescapeHtmlEntities } from "../../../utils/text-normalization" import { everyLineHasLineNumbers, stripLineNumbers } from "../../../integrations/misc/extract-text" -import { ToolResponse } from "../../../shared/tools" import { writeToFileTool } from "../writeToFileTool" -import { ToolDirective } from "../../message-parsing/directives" +import { ToolDirective, ToolResponse } from "../../message-parsing/directives" jest.mock("path", () => { const originalPath = jest.requireActual("path") diff --git a/src/core/tools/attemptCompletionTool.ts b/src/core/tools/attemptCompletionTool.ts index 523380405f..01d4d68f59 100644 --- a/src/core/tools/attemptCompletionTool.ts +++ b/src/core/tools/attemptCompletionTool.ts @@ -4,7 +4,6 @@ import { TelemetryService } from "@roo-code/telemetry" import { Task } from "../task/Task" import { - ToolResponse, AskApproval, HandleError, PushToolResult, @@ -15,7 +14,7 @@ import { import { formatResponse } from "../prompts/responses" import { type ExecuteCommandOptions, executeCommand } from "./executeCommandTool" import { EXPERIMENT_IDS, experiments, experimentDefault } from "../../shared/experiments" -import { ToolDirective } from "../message-parsing/directives" +import { ToolDirective, ToolResponse } from "../message-parsing/directives" export async function attemptCompletionTool( cline: Task, diff --git a/src/core/tools/executeCommandTool.ts b/src/core/tools/executeCommandTool.ts index 3dda433d11..565b6a4b02 100644 --- a/src/core/tools/executeCommandTool.ts +++ b/src/core/tools/executeCommandTool.ts @@ -8,13 +8,13 @@ import { TelemetryService } from "@roo-code/telemetry" import { Task } from "../task/Task" -import { AskApproval, HandleError, PushToolResult, RemoveClosingTag, ToolResponse } from "../../shared/tools" +import { AskApproval, HandleError, PushToolResult, RemoveClosingTag } from "../../shared/tools" import { formatResponse } from "../prompts/responses" import { unescapeHtmlEntities } from "../../utils/text-normalization" import { ExitCodeDetails, RooTerminalCallbacks, RooTerminalProcess } from "../../integrations/terminal/types" import { TerminalRegistry } from "../../integrations/terminal/TerminalRegistry" import { Terminal } from "../../integrations/terminal/Terminal" -import { ToolDirective } from "../message-parsing/directives" +import { ToolDirective, ToolResponse } from "../message-parsing/directives" class ShellIntegrationError extends Error {} diff --git a/src/shared/tools.ts b/src/shared/tools.ts index bea13447f6..6eb4bba754 100644 --- a/src/shared/tools.ts +++ b/src/shared/tools.ts @@ -1,9 +1,6 @@ -import { Anthropic } from "@anthropic-ai/sdk" - import type { ClineAsk, ToolProgressStatus, ToolGroup, ToolName } from "@roo-code/types" import { ToolDirective } from "../core/message-parsing/directives/" - -export type ToolResponse = string | Array +import { ToolResponse } from "../core/message-parsing/directives/tool-directives" export type AskApproval = ( type: ClineAsk, @@ -21,133 +18,7 @@ export type AskFinishSubTaskApproval = () => Promise export type ToolDescription = () => string -export const toolParamNames = [ - "command", - "path", - "content", - "line_count", - "regex", - "file_pattern", - "recursive", - "action", - "url", - "coordinate", - "text", - "server_name", - "tool_name", - "arguments", - "uri", - "question", - "result", - "diff", - "mode_slug", - "reason", - "line", - "mode", - "message", - "cwd", - "follow_up", - "task", - "size", - "search", - "replace", - "use_regex", - "ignore_case", - "args", - "start_line", - "end_line", - "query", - "args", -] as const - -export type ToolParamName = (typeof toolParamNames)[number] - -export interface ExecuteCommandToolDirective extends ToolDirective { - name: "execute_command" - // Pick, "command"> makes "command" required, but Partial<> makes it optional - params: Partial, "command" | "cwd">> -} - -export interface ReadFileToolDirective extends ToolDirective { - name: "read_file" - params: Partial, "args" | "path" | "start_line" | "end_line">> -} - -export interface FetchInstructionsToolDirective extends ToolDirective { - name: "fetch_instructions" - params: Partial, "task">> -} - -export interface WriteToFileToolDirective extends ToolDirective { - name: "write_to_file" - params: Partial, "path" | "content" | "line_count">> -} - -export interface InsertCodeBlockToolDirective extends ToolDirective { - name: "insert_content" - params: Partial, "path" | "line" | "content">> -} - -export interface CodebaseSearchToolDirective extends ToolDirective { - name: "codebase_search" - params: Partial, "query" | "path">> -} - -export interface SearchFilesToolDirective extends ToolDirective { - name: "search_files" - params: Partial, "path" | "regex" | "file_pattern">> -} - -export interface ListFilesToolDirective extends ToolDirective { - name: "list_files" - params: Partial, "path" | "recursive">> -} - -export interface ListCodeDefinitionNamesToolDirective extends ToolDirective { - name: "list_code_definition_names" - params: Partial, "path">> -} - -export interface BrowserActionToolDirective extends ToolDirective { - name: "browser_action" - params: Partial, "action" | "url" | "coordinate" | "text" | "size">> -} - -export interface UseMcpToolToolDirective extends ToolDirective { - name: "use_mcp_tool" - params: Partial, "server_name" | "tool_name" | "arguments">> -} - -export interface AccessMcpResourceToolDirective extends ToolDirective { - name: "access_mcp_resource" - params: Partial, "server_name" | "uri">> -} - -export interface AskFollowupQuestionToolDirective extends ToolDirective { - name: "ask_followup_question" - params: Partial, "question" | "follow_up">> -} - -export interface AttemptCompletionToolDirective extends ToolDirective { - name: "attempt_completion" - params: Partial, "result" | "command">> -} - -export interface SwitchModeToolDirective extends ToolDirective { - name: "switch_mode" - params: Partial, "mode_slug" | "reason">> -} - -export interface NewTaskToolDirective extends ToolDirective { - name: "new_task" - params: Partial, "mode" | "message">> -} - -export interface SearchAndReplaceToolDirective extends ToolDirective { - name: "search_and_replace" - params: Required, "path" | "search" | "replace">> & - Partial, "use_regex" | "ignore_case" | "start_line" | "end_line">> -} +import { toolParamNames, ToolParamName } from "../core/message-parsing/directives/tool-directives" // Define tool group configuration export type ToolGroupConfig = {