insert_code_block -> insert_content

This commit is contained in:
Matt Rubens
2025-01-28 14:36:12 -05:00
parent 68035507af
commit d836548c19
9 changed files with 28 additions and 44 deletions

View File

@@ -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

View File

@@ -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<Pick<Record<ToolParamName, string>, "path" | "operations">>
}

View File

@@ -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")
})
})

View File

@@ -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.",
)
}

View File

@@ -32,7 +32,7 @@ const toolDescriptionMap: Record<string, (args: ToolArgs) => 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 }) : "",

View File

@@ -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:
<insert_code_block>
<insert_content>
<path>File path here</path>
<operations>[
{
@@ -17,9 +17,9 @@ Usage:
"content": "Your code block here"
}
]</operations>
</insert_code_block>
</insert_content>
Example: Insert a new function and its import statement
<insert_code_block>
<insert_content>
<path>src/app.ts</path>
<operations>[
{
@@ -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}"
}
]</operations>
</insert_code_block>`
</insert_content>`
}

View File

@@ -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(

View File

@@ -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<ExperimentKey, ExperimentConfig> = {
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,
},
}

View File

@@ -21,7 +21,7 @@ export const TOOL_DISPLAY_NAMES = {
// Define available tool groups
export const TOOL_GROUPS: Record<string, ToolGroupValues> = {
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"],