diff --git a/.changeset/khaki-zoos-share.md b/.changeset/khaki-zoos-share.md new file mode 100644 index 0000000..e3ba489 --- /dev/null +++ b/.changeset/khaki-zoos-share.md @@ -0,0 +1,5 @@ +--- +"roo-cline": patch +--- + +v3.3.5 diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 82a4314..3037043 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 } @@ -1603,7 +1601,7 @@ export class Cline { if (!userEdits) { pushToolResult( - `The code block was successfully inserted in ${relPath.toPosix()}.${newProblemsMessage}`, + `The content was successfully inserted in ${relPath.toPosix()}.${newProblemsMessage}`, ) await this.diffViewProvider.reset() 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..8ad785c 100644 --- a/src/core/prompts/tools/index.ts +++ b/src/core/prompts/tools/index.ts @@ -3,7 +3,7 @@ import { getReadFileDescription } from "./read-file" import { getWriteToFileDescription } from "./write-to-file" import { getSearchFilesDescription } from "./search-files" import { getListFilesDescription } from "./list-files" -import { getInsertCodeBlockDescription } from "./insert-code-block" +import { getInsertContentDescription } from "./insert-content" import { getSearchAndReplaceDescription } from "./search-and-replace" import { getListCodeDefinitionNamesDescription } from "./list-code-definition-names" import { getBrowserActionDescription } from "./browser-action" @@ -15,7 +15,7 @@ import { getSwitchModeDescription } from "./switch-mode" import { DiffStrategy } from "../../diff/DiffStrategy" import { McpHub } from "../../../services/mcp/McpHub" import { Mode, ModeConfig, getModeConfig, isToolAllowedForMode, getGroupName } from "../../../shared/modes" -import { ToolName, getToolName, getToolOptions, TOOL_GROUPS, ALWAYS_AVAILABLE_TOOLS } from "../../../shared/tool-groups" +import { ToolName, TOOL_GROUPS, ALWAYS_AVAILABLE_TOOLS } from "../../../shared/tool-groups" import { ToolArgs } from "./types" // Map of tool names to their description functions @@ -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) => getInsertContentDescription(args), search_and_replace: (args) => getSearchAndReplaceDescription(args), apply_diff: (args) => args.diffStrategy ? args.diffStrategy.getToolDescription({ cwd: args.cwd, toolOptions: args.toolOptions }) : "", @@ -105,6 +105,6 @@ export { getUseMcpToolDescription, getAccessMcpResourceDescription, getSwitchModeDescription, - getInsertCodeBlockDescription, + getInsertContentDescription, getSearchAndReplaceDescription, } diff --git a/src/core/prompts/tools/insert-code-block.ts b/src/core/prompts/tools/insert-code-block.ts deleted file mode 100644 index 7dce56e..0000000 --- a/src/core/prompts/tools/insert-code-block.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { ToolArgs } from "./types" - -export function getInsertCodeBlockDescription(args: ToolArgs): string { - return `## insert_code_block -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()}) -- operations: (required) A JSON array of insertion operations. Each operation is an object with: - * 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 -[ - { - "start_line": 10, - "content": "Your code block here" - } -] - -Example: Insert a new function and its import statement - -src/app.ts -[ - { - "start_line": 1, - "content": "import { sum } from './utils';" - }, - { - "start_line": 10, - "content": "function calculateTotal(items: number[]): number {\n return items.reduce((sum, item) => sum + item, 0);\n}" - } -] -` -} diff --git a/src/core/prompts/tools/insert-content.ts b/src/core/prompts/tools/insert-content.ts new file mode 100644 index 0000000..92204f0 --- /dev/null +++ b/src/core/prompts/tools/insert-content.ts @@ -0,0 +1,35 @@ +import { ToolArgs } from "./types" + +export function getInsertContentDescription(args: ToolArgs): string { + return `## insert_content +Description: Inserts content at specific line positions in a file. This is the primary tool for adding new content and 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 content and code to files. +Parameters: +- path: (required) The path of the file to insert content into (relative to the current working directory ${args.cwd.toPosix()}) +- operations: (required) A JSON array of insertion operations. Each operation is an object with: + * start_line: (required) The line number where the content should be inserted. The content currently at that line will end up below the inserted content. + * content: (required) The content 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. Make sure to include the correct indentation for the content. +Usage: + +File path here +[ + { + "start_line": 10, + "content": "Your content here" + } +] + +Example: Insert a new function and its import statement + +File path here +[ + { + "start_line": 1, + "content": "import { sum } from './utils';" + }, + { + "start_line": 10, + "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"],