Elffuss BraidHub

kikocis/continue public

4e08584b8e1b · 4.7 KiBRawPermalink
1import { Tool } from "../..";
2import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
3import { NO_PARALLEL_TOOL_CALLING_INTSRUCTION } from "./editFile";
4
5export interface EditOperation {
6 old_string: string;
7 new_string: string;
8 replace_all?: boolean;
9}
10
11export interface MultiEditArgs {
12 filepath: string;
13 edits: EditOperation[];
14}
15
16export const multiEditTool: Tool = {
17 type: "function",
18 displayTitle: "Multi Edit",
19 wouldLikeTo: "edit {{{ filepath }}}",
20 isCurrently: "editing {{{ filepath }}}",
21 hasAlready: "edited {{{ filepath }}}",
22 group: BUILT_IN_GROUP_NAME,
23 readonly: false,
24 isInstant: false,
25 function: {
26 name: BuiltInToolNames.MultiEdit,
27 description: `This is a tool for making multiple edits to a single file in one operation. It
28is built on top of the single find and replace tool and allows you to perform multiple
29find-and-replace operations efficiently. Prefer this tool over the single find and replace tool
30when you need to make multiple edits to the same file.
31
32Before using this tool:
33
341. Use the read_file tool to understand the file's contents and context
352. Verify the directory path is correct
36
37To make multiple file edits, provide the following:
38
391. filepath: The path to the file to modify (relative to the root of the workspace)
402. edits: An array of edit operations to perform, where each edit contains:
41 - old_string: The text to replace (must match the file contents exactly, including all whitespace and indentation)
42 - new_string: The edited text to replace the old_string
43 - replace_all: Replace all occurrences of old_string. This parameter is optional and defaults to false.
44
45IMPORTANT:
46- All edits are applied in sequence, in the order they are provided
47- Each edit operates on the result of the previous edit
48- All edits must be valid for the operation to succeed - if any edit fails,
49none will be applied
50- This tool is ideal when you need to make several changes to different parts
51of the same file
52
53CRITICAL REQUIREMENTS:
54
551. All edits follow the same requirements as the single find and replace tool
562. The edits are atomic - either all succeed or none are applied
573. Plan your edits carefully to avoid conflicts between sequential operations
584. ${NO_PARALLEL_TOOL_CALLING_INTSRUCTION}
59
60WARNING:
61
62- The tool will fail if edits.old_string doesn't match the file contents
63exactly (including whitespace)
64- The tool will fail if edits.old_string and edits.new_string are the same
65- Since edits are applied in sequence, ensure that earlier edits don't affect
66the text that later edits are trying to find
67
68When making edits:
69
70- Ensure all edits result in idiomatic, correct code
71- Do not leave the code in a broken state
72- Only use emojis if the user explicitly requests it. Avoid adding emojis to
73files unless asked.
74- Use replace_all for replacing and renaming strings across the file. This
75parameter is useful if you want to rename a variable for instance.
76
77If you want to create a new file, use:
78- A new file path
79- First edit: empty old_string and the new file's contents as new_string
80- Subsequent edits are not allowed - there is no need since you are creating`,
81 parameters: {
82 type: "object",
83 required: ["filepath", "edits"],
84 properties: {
85 filepath: {
86 type: "string",
87 description:
88 "The path to the file to modify, relative to the root of the workspace",
89 },
90 edits: {
91 type: "array",
92 description:
93 "Array of edit operations to perform sequentially on the file",
94 items: {
95 type: "object",
96 required: ["old_string", "new_string"],
97 properties: {
98 old_string: {
99 type: "string",
100 description: "The text to replace",
101 },
102 new_string: {
103 type: "string",
104 description: "The text to replace it with",
105 },
106 replace_all: {
107 type: "boolean",
108 description:
109 "Replace all occurrences of old_string (default false)",
110 },
111 },
112 },
113 },
114 },
115 },
116 },
117 systemMessageDescription: {
118 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.
119
120 For example, you could respond with:`,
121 exampleArgs: [
122 ["filepath", "path/to/file.ts"],
123 [
124 "edits",
125 `[
126 { "old_string": "const oldVar = 'value'", "new_string": "const newVar = 'updated'" },
127 { "old_string": "oldFunction()", "new_string": "newFunction()", "replace_all": true }
128]`,
129 ],
130 ],
131 },
132 defaultToolPolicy: "allowedWithPermission",
133};