Elffuss BraidHub

kikocis/continue public

main · 4.7 KiBRawPermalink
1import { Tool } from "../..";
2import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
3import { NO_PARALLEL_TOOL_CALLING_INSTRUCTION } 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: `Use this tool to make multiple edits to a single file in one operation. It allows you to perform multiple find-and-replace operations efficiently.
28
29To make multiple edits to a file, provide the following:
301. filepath: The path to the file to modify, RELATIVE to the project/workspace root (verify the directory path is correct)
312. edits: An array of edit operations to perform, where each edit contains:
32 - old_string: The text to replace (must match the old file contents exactly, including all whitespace/indentation)
33 - new_string: The edited text to replace the old_string
34 - replace_all: Replace all occurrences of old_string. This parameter is optional and defaults to false.
35
36IMPORTANT:
37- Files may be modified between tool calls by users, linters, etc, so always make all edits in one tool call where possible. For example, do not only edit imports if there are other changes in the file, as unused imports may be removed by a linter between tool calls.
38- All edits are applied in sequence, in the order they are provided
39- Each edit operates on the result of the previous edit, so plan your edits carefully to avoid conflicts between sequential operations
40- Edits are atomic - all edits must be valid for the operation to succeed - if any edit fails, none will be applied
41- This tool is ideal when you need to make several changes to different parts of the same file
42
43CRITICAL REQUIREMENTS:
441. 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.
452. ${NO_PARALLEL_TOOL_CALLING_INSTRUCTION}
463. When making edits:
47- Ensure all edits result in idiomatic, correct code
48- Do not leave the code in a broken state
49- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked
50- 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
51
52WARNINGS:
53- If earlier edits affect the text that later edits are trying to find, files can become mangled
54- The tool will fail if edits.old_string doesn't match the file contents exactly (including whitespace)
55- The tool will fail if edits.old_string and edits.new_string are the same - they MUST be different`,
56 parameters: {
57 type: "object",
58 required: ["filepath", "edits"],
59 properties: {
60 filepath: {
61 type: "string",
62 description:
63 "The path to the file to modify, relative to the root of the workspace",
64 },
65 edits: {
66 type: "array",
67 description:
68 "Array of edit operations to perform sequentially on the file",
69 items: {
70 type: "object",
71 required: ["old_string", "new_string"],
72 properties: {
73 old_string: {
74 type: "string",
75 description:
76 "The text to replace (exact match including whitespace/indentation)",
77 },
78 new_string: {
79 type: "string",
80 description:
81 "The text to replace it with. MUST be different than old_string.",
82 },
83 replace_all: {
84 type: "boolean",
85 description:
86 "Replace all occurrences of old_string (default false) in the file",
87 },
88 },
89 },
90 },
91 },
92 },
93 },
94 systemMessageDescription: {
95 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.
96
97 For example, you could respond with:`,
98 exampleArgs: [
99 ["filepath", "path/to/file.ts"],
100 [
101 "edits",
102 `[
103 { "old_string": "const oldVar = 'value'", "new_string": "const newVar = 'updated'" },
104 { "old_string": "oldFunction()", "new_string": "newFunction()", "replace_all": true }
105]`,
106 ],
107 ],
108 },
109 defaultToolPolicy: "allowedWithPermission",
110};