From d836548c19cabd67b229e6bbbb38e510ac82e59d Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Tue, 28 Jan 2025 14:36:12 -0500 Subject: [PATCH] insert_code_block -> insert_content --- src/core/Cline.ts | 12 +++++------ src/core/assistant-message/index.ts | 4 ++-- src/core/prompts/__tests__/system.test.ts | 4 ++-- src/core/prompts/sections/rules.ts | 8 +++---- src/core/prompts/tools/index.ts | 2 +- src/core/prompts/tools/insert-code-block.ts | 10 ++++----- src/shared/__tests__/modes.test.ts | 24 +++++---------------- src/shared/experiments.ts | 6 +++--- src/shared/tool-groups.ts | 2 +- 9 files changed, 28 insertions(+), 44 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 86a4ec5..4f5206e 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -1010,7 +1010,7 @@ export class Cline { return `[${block.name} for '${block.params.regex}'${ block.params.file_pattern ? ` in '${block.params.file_pattern}'` : "" }]` - case "insert_code_block": + case "insert_content": return `[${block.name} for '${block.params.path}']` case "search_and_replace": return `[${block.name} for '${block.params.path}']` @@ -1486,7 +1486,7 @@ export class Cline { } } - case "insert_code_block": { + case "insert_content": { const relPath: string | undefined = block.params.path const operations: string | undefined = block.params.operations @@ -1505,15 +1505,13 @@ export class Cline { // Validate required parameters if (!relPath) { this.consecutiveMistakeCount++ - pushToolResult(await this.sayAndCreateMissingParamError("insert_code_block", "path")) + pushToolResult(await this.sayAndCreateMissingParamError("insert_content", "path")) break } if (!operations) { this.consecutiveMistakeCount++ - pushToolResult( - await this.sayAndCreateMissingParamError("insert_code_block", "operations"), - ) + pushToolResult(await this.sayAndCreateMissingParamError("insert_content", "operations")) break } @@ -1629,7 +1627,7 @@ export class Cline { ) await this.diffViewProvider.reset() } catch (error) { - handleError("insert block", error) + handleError("insert content", error) await this.diffViewProvider.reset() } break diff --git a/src/core/assistant-message/index.ts b/src/core/assistant-message/index.ts index 092dd06..c2a2d62 100644 --- a/src/core/assistant-message/index.ts +++ b/src/core/assistant-message/index.ts @@ -13,7 +13,7 @@ export const toolUseNames = [ "read_file", "write_to_file", "apply_diff", - "insert_code_block", + "insert_content", "search_and_replace", "search_files", "list_files", @@ -82,7 +82,7 @@ export interface WriteToFileToolUse extends ToolUse { } export interface InsertCodeBlockToolUse extends ToolUse { - name: "insert_code_block" + name: "insert_content" params: Partial, "path" | "operations">> } diff --git a/src/core/prompts/__tests__/system.test.ts b/src/core/prompts/__tests__/system.test.ts index 276a06e..d4edea8 100644 --- a/src/core/prompts/__tests__/system.test.ts +++ b/src/core/prompts/__tests__/system.test.ts @@ -544,7 +544,7 @@ describe("SYSTEM_PROMPT", () => { // Verify base instruction lists all available tools expect(prompt).toContain("apply_diff (for replacing lines in existing files)") expect(prompt).toContain("write_to_file (for creating new files or complete file rewrites)") - expect(prompt).toContain("insert_code_block (for adding sections to existing files)") + expect(prompt).toContain("insert_content (for adding lines to existing files)") expect(prompt).toContain("search_and_replace (for finding and replacing individual pieces of text)") }) @@ -574,7 +574,7 @@ describe("SYSTEM_PROMPT", () => { expect(prompt).toContain( "You should always prefer using other editing tools over write_to_file when making changes to existing files since write_to_file is much slower and cannot handle large files.", ) - expect(prompt).toContain("The insert_code_block tool adds code snippets or content blocks to files") + expect(prompt).toContain("The insert_content tool adds lines of text to files") expect(prompt).toContain("The search_and_replace tool finds and replaces text or regex in files") }) }) diff --git a/src/core/prompts/sections/rules.ts b/src/core/prompts/sections/rules.ts index cb944a1..b6e19eb 100644 --- a/src/core/prompts/sections/rules.ts +++ b/src/core/prompts/sections/rules.ts @@ -11,8 +11,8 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor if (diffStrategy) { availableTools.push("apply_diff (for replacing lines in existing files)") } - if (experiments?.["insert_code_block"]) { - availableTools.push("insert_code_block (for adding sections to existing files)") + if (experiments?.["insert_content"]) { + availableTools.push("insert_content (for adding lines to existing files)") } if (experiments?.["search_and_replace"]) { availableTools.push("search_and_replace (for finding and replacing individual pieces of text)") @@ -24,9 +24,9 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor } // Additional details for experimental features - if (experiments?.["insert_code_block"]) { + if (experiments?.["insert_content"]) { instructions.push( - "- The insert_code_block tool adds code snippets or content blocks to files, such as adding a new function to a JavaScript file or inserting a new route in a Python file. This tool will insert it at the specified line location. It can support multiple operations at once.", + "- The insert_content tool adds lines of text to files, such as adding a new function to a JavaScript file or inserting a new route in a Python file. This tool will insert it at the specified line location. It can support multiple operations at once.", ) } diff --git a/src/core/prompts/tools/index.ts b/src/core/prompts/tools/index.ts index 23e77fb..2e3a514 100644 --- a/src/core/prompts/tools/index.ts +++ b/src/core/prompts/tools/index.ts @@ -32,7 +32,7 @@ const toolDescriptionMap: Record string | undefined> use_mcp_tool: (args) => getUseMcpToolDescription(args), access_mcp_resource: (args) => getAccessMcpResourceDescription(args), switch_mode: () => getSwitchModeDescription(), - insert_code_block: (args) => getInsertCodeBlockDescription(args), + insert_content: (args) => getInsertCodeBlockDescription(args), search_and_replace: (args) => getSearchAndReplaceDescription(args), apply_diff: (args) => args.diffStrategy ? args.diffStrategy.getToolDescription({ cwd: args.cwd, toolOptions: args.toolOptions }) : "", diff --git a/src/core/prompts/tools/insert-code-block.ts b/src/core/prompts/tools/insert-code-block.ts index 7dce56e..fa98433 100644 --- a/src/core/prompts/tools/insert-code-block.ts +++ b/src/core/prompts/tools/insert-code-block.ts @@ -1,7 +1,7 @@ import { ToolArgs } from "./types" export function getInsertCodeBlockDescription(args: ToolArgs): string { - return `## insert_code_block + return `## insert_content Description: Inserts code blocks at specific line positions in a file. This is the primary tool for adding new code (functions/methods/classes, imports, attributes etc.) as it allows for precise insertions without overwriting existing content. The tool uses an efficient line-based insertion system that maintains file integrity and proper ordering of multiple insertions. Beware to use the proper indentation. This tool is the preferred way to add new code to files. Parameters: - path: (required) The path of the file to insert code into (relative to the current working directory ${args.cwd.toPosix()}) @@ -9,7 +9,7 @@ Parameters: * start_line: (required) The line number where the code block should be inserted. The content currently at that line will end up below the inserted code block. * content: (required) The code block to insert at the specified position. IMPORTANT NOTE: If the content is a single line, it can be a string. If it's a multi-line content, it should be a string with newline characters (\n) for line breaks. Usage: - + File path here [ { @@ -17,9 +17,9 @@ Usage: "content": "Your code block here" } ] - + Example: Insert a new function and its import statement - + src/app.ts [ { @@ -31,5 +31,5 @@ Example: Insert a new function and its import statement "content": "function calculateTotal(items: number[]): number {\n return items.reduce((sum, item) => sum + item, 0);\n}" } ] -` +` } diff --git a/src/shared/__tests__/modes.test.ts b/src/shared/__tests__/modes.test.ts index b9e46cb..44d2376 100644 --- a/src/shared/__tests__/modes.test.ts +++ b/src/shared/__tests__/modes.test.ts @@ -251,7 +251,7 @@ describe("isToolAllowedForMode", () => { it("disables tools when experiment is disabled", () => { const experiments = { search_and_replace: false, - insert_code_block: false, + insert_content: false, } expect( @@ -266,21 +266,14 @@ describe("isToolAllowedForMode", () => { ).toBe(false) expect( - isToolAllowedForMode( - "insert_code_block", - "test-exp-mode", - customModes, - undefined, - undefined, - experiments, - ), + isToolAllowedForMode("insert_content", "test-exp-mode", customModes, undefined, undefined, experiments), ).toBe(false) }) it("allows tools when experiment is enabled", () => { const experiments = { search_and_replace: true, - insert_code_block: true, + insert_content: true, } expect( @@ -295,21 +288,14 @@ describe("isToolAllowedForMode", () => { ).toBe(true) expect( - isToolAllowedForMode( - "insert_code_block", - "test-exp-mode", - customModes, - undefined, - undefined, - experiments, - ), + isToolAllowedForMode("insert_content", "test-exp-mode", customModes, undefined, undefined, experiments), ).toBe(true) }) it("allows non-experimental tools when experiments are disabled", () => { const experiments = { search_and_replace: false, - insert_code_block: false, + insert_content: false, } expect( diff --git a/src/shared/experiments.ts b/src/shared/experiments.ts index 71eda74..9849e22 100644 --- a/src/shared/experiments.ts +++ b/src/shared/experiments.ts @@ -1,7 +1,7 @@ export const EXPERIMENT_IDS = { DIFF_STRATEGY: "experimentalDiffStrategy", SEARCH_AND_REPLACE: "search_and_replace", - INSERT_BLOCK: "insert_code_block", + INSERT_BLOCK: "insert_content", } as const export type ExperimentKey = keyof typeof EXPERIMENT_IDS @@ -29,10 +29,10 @@ export const experimentConfigsMap: Record = { enabled: false, }, INSERT_BLOCK: { - name: "Use experimental insert block tool", + name: "Use experimental insert content tool", description: - "Enable the experimental insert block tool, allowing Roo to insert multiple code blocks at once at specific line numbers without needing to create a diff.", + "Enable the experimental insert content tool, allowing Roo to insert content at specific line numbers without needing to create a diff.", enabled: false, }, } diff --git a/src/shared/tool-groups.ts b/src/shared/tool-groups.ts index d95b16e..19f43a5 100644 --- a/src/shared/tool-groups.ts +++ b/src/shared/tool-groups.ts @@ -21,7 +21,7 @@ export const TOOL_DISPLAY_NAMES = { // Define available tool groups export const TOOL_GROUPS: Record = { read: ["read_file", "search_files", "list_files", "list_code_definition_names"], - edit: ["write_to_file", "apply_diff", "insert_code_block", "search_and_replace"], + edit: ["write_to_file", "apply_diff", "insert_content", "search_and_replace"], browser: ["browser_action"], command: ["execute_command"], mcp: ["use_mcp_tool", "access_mcp_resource"],