Elffuss BraidHub

kikocis/continue public

825624809c09 · 3.1 KiBRawPermalink
1import { Tool } from "../..";
2import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
3import { NO_PARALLEL_TOOL_CALLING_INTSRUCTION } from "./editFile";
4
5export interface SingleFindAndReplaceArgs {
6 filepath: string;
7 old_string: string;
8 new_string: string;
9 replace_all?: boolean;
10}
11
12export const singleFindAndReplaceTool: Tool = {
13 type: "function",
14 displayTitle: "Find and Replace",
15 wouldLikeTo: "find and replace in {{{ filepath }}}",
16 isCurrently: "finding and replacing in {{{ filepath }}}",
17 hasAlready: "found and replaced in {{{ filepath }}}",
18 group: BUILT_IN_GROUP_NAME,
19 readonly: false,
20 isInstant: false,
21 function: {
22 name: BuiltInToolNames.SingleFindAndReplace,
23 description: `Performs exact string replacements in files.
24
25Usage:
26
27- You must use your \`read_file\` tool at least once in the conversation before
28editing. This tool will error if you attempt an edit without reading the file.
29
30- When editing text from read_file tool output, ensure you preserve the exact
31indentation (tabs/spaces) as it appears AFTER the line number prefix. The line
32number prefix format is: spaces + line number + tab. Everything after that tab
33is the actual file content to match. Never include any part of the line number
34prefix in the old_string or new_string.
35
36- ALWAYS prefer editing existing files in the codebase. NEVER write new files
37unless explicitly required.
38
39- Only use emojis if the user explicitly requests it. Avoid adding emojis to
40files unless asked.
41
42- ${NO_PARALLEL_TOOL_CALLING_INTSRUCTION}
43
44- The edit will FAIL if \`old_string\` is not unique in the file. Either provide
45a larger string with more surrounding context to make it unique or use
46\`replace_all\` to change every instance of \`old_string\`.
47
48- Use \`replace_all\` for replacing and renaming strings across the file. This
49parameter is useful if you want to rename a variable for instance.`,
50 parameters: {
51 type: "object",
52 required: ["filepath", "old_string", "new_string"],
53 properties: {
54 filepath: {
55 type: "string",
56 description:
57 "The path to the file to modify, relative to the root of the workspace",
58 },
59 old_string: {
60 type: "string",
61 description: "The text to replace",
62 },
63 new_string: {
64 type: "string",
65 description:
66 "The text to replace it with (must be different from old_string)",
67 },
68 replace_all: {
69 type: "boolean",
70 description: "Replace all occurrences of old_string (default false)",
71 },
72 },
73 },
74 },
75 systemMessageDescription: {
76 prefix: `To perform exact string replacements in files, use the ${BuiltInToolNames.SingleFindAndReplace} tool with a filepath (relative to the root of the workspace) and the strings to find and replace.
77
78 For example, you could respond with:`,
79 exampleArgs: [
80 ["filepath", "path/to/file.ts"],
81 ["old_string", "const oldVariable = 'value'"],
82 ["new_string", "const newVariable = 'updated'"],
83 ["replace_all", "false"],
84 ],
85 },
86 defaultToolPolicy: "allowedWithPermission",
87};