Elffuss BraidHub

kikocis/continue public

dc42dd67a510 · 2.2 KiBRawPermalink
1import { Tool } from "../..";
2import { EDIT_CODE_INSTRUCTIONS } from "../../llm/defaultSystemMessages";
3import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
4import { NO_PARALLEL_TOOL_CALLING_INSRUCTION } from "./searchAndReplaceInFile";
5
6export interface EditToolArgs {
7 filepath: string;
8 changes: string;
9}
10
11const CHANGES_DESCRIPTION =
12 "Any modifications to the file, showing only needed changes. Do NOT wrap this in a codeblock or write anything besides the code changes. In larger files, use brief language-appropriate placeholders for large unmodified sections, e.g. '// ... existing code ...'";
13
14export const editFileTool: Tool = {
15 type: "function",
16 displayTitle: "Edit File",
17 wouldLikeTo: "edit {{{ filepath }}}",
18 isCurrently: "editing {{{ filepath }}}",
19 hasAlready: "edited {{{ filepath }}}",
20 group: BUILT_IN_GROUP_NAME,
21 readonly: false,
22 isInstant: false,
23 function: {
24 name: BuiltInToolNames.EditExistingFile,
25 description: `Use this tool to edit an existing file. If you don't know the contents of the file, read it first.\n${EDIT_CODE_INSTRUCTIONS}\n${NO_PARALLEL_TOOL_CALLING_INSRUCTION}`,
26 parameters: {
27 type: "object",
28 required: ["filepath", "changes"],
29 properties: {
30 filepath: {
31 type: "string",
32 description:
33 "The path of the file to edit, relative to the root of the workspace.",
34 },
35 changes: {
36 type: "string",
37 description: CHANGES_DESCRIPTION,
38 },
39 },
40 },
41 },
42 defaultToolPolicy: "allowedWithPermission",
43 systemMessageDescription: {
44 prefix: `To edit an EXISTING file, use the ${BuiltInToolNames.EditExistingFile} tool with
45- filepath: the relative filepath to the file.
46- changes: ${CHANGES_DESCRIPTION}
47Only use this tool if you already know the contents of the file. Otherwise, use the ${BuiltInToolNames.ReadFile} or ${BuiltInToolNames.ReadCurrentlyOpenFile} tool to read it first.
48For example:`,
49 exampleArgs: [
50 ["filepath", "path/to/the_file.ts"],
51 [
52 "changes",
53 "// ... existing code ...\nfunction subtract(a: number, b: number): number {\n return a - b;\n}\n// ... rest of code ...",
54 ],
55 ],
56 },
57};