diff --git a/src/core/Cline.ts b/src/core/Cline.ts index acd6a70..3037043 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -1601,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 diff --git a/src/core/prompts/tools/index.ts b/src/core/prompts/tools/index.ts index 2e3a514..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_content: (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 fa98433..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_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()}) -- 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}" + } +] +` +}