Elffuss BraidHub

kikocis/continue public

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