Elffuss BraidHub

kikocis/continue public

76a3b5039c4e · 4.7 KiBRawPermalink
1import { Tool } from "../..";
2import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
3import { NO_PARALLEL_TOOL_CALLING_INSTRUCTION } from "./editFile";
4import { singleFindAndReplaceTool } from "./singleFindAndReplace";
5
6export interface EditOperation {
7 old_string: string;
8 new_string: string;
9 replace_all?: boolean;
10}
11
12export interface MultiEditArgs {
13 filepath: string;
14 edits: EditOperation[];
15}
16
17export const multiEditTool: Tool = {
18 type: "function",
19 displayTitle: "Multi Edit",
20 wouldLikeTo: "edit {{{ filepath }}}",
21 isCurrently: "editing {{{ filepath }}}",
22 hasAlready: "edited {{{ filepath }}}",
23 group: BUILT_IN_GROUP_NAME,
24 readonly: false,
25 isInstant: false,
26 function: {
27 name: BuiltInToolNames.MultiEdit,
28 description: `This is a tool for making multiple edits to a single file in one operation. It is built on top of the ${singleFindAndReplaceTool.function.name} and allows you to perform multiple find-and-replace operations efficiently.
29Prefer this tool over the ${singleFindAndReplaceTool.function.name} tool when you need to make multiple edits to the same file.
30
31To make multiple edits to a file, provide the following:
321. filepath: The path to the file to modify, RELATIVE to the project/workspace root (verify the directory path is correct)
332. edits: An array of edit operations to perform, where each edit contains:
34 - old_string: The text to replace (must match the old file contents exactly, including all whitespace/indentation)
35 - new_string: The edited text to replace the old_string
36 - replace_all: Replace all occurrences of old_string. This parameter is optional and defaults to false.
37
38IMPORTANT:
39- All edits are applied in sequence, in the order they are provided
40- Each edit operates on the result of the previous edit, so plan your edits carefully to avoid conflicts between sequential operations
41- Edits are atomic - all edits must be valid for the operation to succeed - if any edit fails, none will be applied
42- This tool is ideal when you need to make several changes to different parts of the same file
43
44CRITICAL REQUIREMENTS:
451. ALWAYS use the ${BuiltInToolNames.ReadFile} tool just before making edits, to understand the file's up-to-date contents and context. The user can also edit the file while you are working with it.
462. ${NO_PARALLEL_TOOL_CALLING_INSTRUCTION}
473. When making edits:
48- Ensure all edits result in idiomatic, correct code
49- Do not leave the code in a broken state
50- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked
51- Use replace_all for replacing and renaming all matches for a string across the file. This parameter is useful if you want to rename a variable, for instance
52
53WARNINGS:
54- If earlier edits affect the text that later edits are trying to find, files can become mangled
55- The tool will fail if edits.old_string doesn't match the file contents exactly (including whitespace)
56- The tool will fail if edits.old_string and edits.new_string are the same - they MUST be different`,
57 parameters: {
58 type: "object",
59 required: ["filepath", "edits"],
60 properties: {
61 filepath: {
62 type: "string",
63 description:
64 "The path to the file to modify, relative to the root of the workspace",
65 },
66 edits: {
67 type: "array",
68 description:
69 "Array of edit operations to perform sequentially on the file",
70 items: {
71 type: "object",
72 required: ["old_string", "new_string"],
73 properties: {
74 old_string: {
75 type: "string",
76 description:
77 "The text to replace (exact match including whitespace/indentation)",
78 },
79 new_string: {
80 type: "string",
81 description:
82 "The text to replace it with. MUST be different than old_string.",
83 },
84 replace_all: {
85 type: "boolean",
86 description:
87 "Replace all occurrences of old_string (default false) in the file",
88 },
89 },
90 },
91 },
92 },
93 },
94 },
95 systemMessageDescription: {
96 prefix: `To make multiple edits to a single file, use the ${BuiltInToolNames.MultiEdit} tool with a filepath (relative to the root of the workspace) and an array of edit operations.
97
98 For example, you could respond with:`,
99 exampleArgs: [
100 ["filepath", "path/to/file.ts"],
101 [
102 "edits",
103 `[
104 { "old_string": "const oldVar = 'value'", "new_string": "const newVar = 'updated'" },
105 { "old_string": "oldFunction()", "new_string": "newFunction()", "replace_all": true }
106]`,
107 ],
108 ],
109 },
110 defaultToolPolicy: "allowedWithPermission",
111};