Elffuss BraidHub

kikocis/continue public

6d66081d22d3 · 3.7 KiBRawPermalink
1import { Tool } from "../..";
2import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
3
4export interface SearchAndReplaceInFileArgs {
5 filepath: string;
6 diff: string;
7}
8
9// Currently unsupported and filtered out in `gui/src/redux/slices/sessionSlice.ts`
10export const NO_PARALLEL_TOOL_CALLING_INSRUCTION =
11 "Note this tool CANNOT be called in parallel.";
12
13/**
14 * This tool is in an experimental state.
15 * Our starting point is heavily inspired by Cline's `replace_in_file` tool: https://github.com/cline/cline/blob/2709ccefcddc616e89a70962f017bcbbca1f17bf/src/core/prompts/system.ts#L87-L121
16 */
17export const searchAndReplaceInFileTool: Tool = {
18 type: "function",
19 displayTitle: "Edit File",
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.SearchAndReplaceInFile,
28 description: `Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file. ${NO_PARALLEL_TOOL_CALLING_INSRUCTION}`,
29 parameters: {
30 type: "object",
31 required: ["filepath", "diff"],
32 properties: {
33 filepath: {
34 type: "string",
35 description:
36 "The path of the file to modify, relative to the root of the workspace.",
37 },
38 diff: {
39 type: "string",
40 description: `One or more SEARCH/REPLACE blocks following this exact format:
41\`\`\`
42------- SEARCH
43[exact content to find]
44=======
45[new content to replace with]
46+++++++ REPLACE
47\`\`\`
48
49Critical rules:
501. SEARCH content must match the associated file section to find EXACTLY:
51 * Match character-for-character including whitespace, indentation, line endings
52 * Include all comments, docstrings, etc.
532. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
54 * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
55 * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
56 * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
573. Keep SEARCH/REPLACE blocks concise:
58 * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
59 * Include just the changing lines, and a few surrounding lines if needed for uniqueness.
60 * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
61 * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
624. Splitting up tool calls:
63 * When making multiple closely related edits to the same file, you should try to use multiple SEARCH/REPLACE blocks in a single tool call, rather than making multiple separate tool calls
64 * If you need to make follow up edits or group your work into logical segments, it is okay to perform additional tool calls
65 * DO NOT make back-to-back tool calls. Instead interleave with brief explanation of what each will do. For example, instead of [explanation, tool call, tool call] you should do [explanation, tool call, explanation, tool call]
665. Special operations:
67 * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
68 * To delete code: Use empty REPLACE section
69
70Usage:
71\`\`\`
72------- SEARCH
73[exact content to find]
74=======
75[new content to replace with]
76+++++++ REPLACE
77
78------- SEARCH
79[exact content to find]
80=======
81[new content to replace with]
82+++++++ REPLACE
83 \`\`\`
84`,
85 },
86 },
87 },
88 },
89};