Elffuss BraidHub

kikocis/continue public

18c867793b67 · 2.3 KiBRawPermalink
1import { Tool } from "../..";
2import { EDIT_CODE_INSTRUCTIONS } from "../../llm/defaultSystemMessages";
3import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
4import { createSystemMessageExampleCall } from "../systemMessageTools/buildToolsSystemMessage";
5import { NO_PARALLEL_TOOL_CALLING_INSRUCTION } from "./searchAndReplaceInFile";
6
7export interface EditToolArgs {
8 filepath: string;
9 changes: string;
10}
11
12const CHANGES_DESCRIPTION =
13 "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 ...'";
14
15export const editFileTool: Tool = {
16 type: "function",
17 displayTitle: "Edit File",
18 wouldLikeTo: "edit {{{ filepath }}}",
19 isCurrently: "editing {{{ filepath }}}",
20 hasAlready: "edited {{{ filepath }}}",
21 group: BUILT_IN_GROUP_NAME,
22 readonly: false,
23 isInstant: false,
24 function: {
25 name: BuiltInToolNames.EditExistingFile,
26 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}`,
27 parameters: {
28 type: "object",
29 required: ["filepath", "changes"],
30 properties: {
31 filepath: {
32 type: "string",
33 description:
34 "The path of the file to edit, relative to the root of the workspace.",
35 },
36 changes: {
37 type: "string",
38 description: CHANGES_DESCRIPTION,
39 },
40 },
41 },
42 },
43 defaultToolPolicy: "allowedWithPermission",
44 systemMessageDescription: createSystemMessageExampleCall(
45 BuiltInToolNames.EditExistingFile,
46 `To edit an EXISTING file, use the ${BuiltInToolNames.EditExistingFile} tool with
47- filepath: the relative filepath to the file.
48- changes: ${CHANGES_DESCRIPTION}
49Only 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.
50For example:`,
51 [
52 ["filepath", "path/to/the_file.ts"],
53 [
54 "changes",
55 "// ... existing code ...\nfunction subtract(a: number, b: number): number {\n return a - b;\n}\n// ... rest of code ...",
56 ],
57 ],
58 ),
59};