# Conflicts: # core/index.d.ts # core/tools/definitions/codebaseTool.ts # core/tools/definitions/createNewFile.ts # core/tools/definitions/createRuleBlock.ts # core/tools/definitions/editFile.ts # core/tools/definitions/fetchUrlContent.ts # core/tools/definitions/globSearch.ts # core/tools/definitions/grepSearch.ts # core/tools/definitions/ls.ts # core/tools/definitions/readCurrentlyOpenFile.ts # core/tools/definitions/readFile.ts # core/tools/definitions/requestRule.ts # core/tools/definitions/runTerminalCommand.ts # core/tools/definitions/searchAndReplaceInFile.ts # core/tools/definitions/searchWeb.ts # core/tools/definitions/viewDiff.ts # core/tools/definitions/viewRepoMap.ts # core/tools/definitions/viewSubdirectory.ts
59 lines
2.3 KiB
TypeScript
59 lines
2.3 KiB
TypeScript
import { Tool } from "../..";
|
|
import { EDIT_CODE_INSTRUCTIONS } from "../../llm/defaultSystemMessages";
|
|
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
|
import { createSystemMessageExampleCall } from "../systemMessageTools/buildToolsSystemMessage";
|
|
import { NO_PARALLEL_TOOL_CALLING_INSRUCTION } from "./searchAndReplaceInFile";
|
|
|
|
export interface EditToolArgs {
|
|
filepath: string;
|
|
changes: string;
|
|
}
|
|
|
|
const CHANGES_DESCRIPTION =
|
|
"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 ...'";
|
|
|
|
export const editFileTool: Tool = {
|
|
type: "function",
|
|
displayTitle: "Edit File",
|
|
wouldLikeTo: "edit {{{ filepath }}}",
|
|
isCurrently: "editing {{{ filepath }}}",
|
|
hasAlready: "edited {{{ filepath }}}",
|
|
group: BUILT_IN_GROUP_NAME,
|
|
readonly: false,
|
|
isInstant: false,
|
|
function: {
|
|
name: BuiltInToolNames.EditExistingFile,
|
|
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}`,
|
|
parameters: {
|
|
type: "object",
|
|
required: ["filepath", "changes"],
|
|
properties: {
|
|
filepath: {
|
|
type: "string",
|
|
description:
|
|
"The path of the file to edit, relative to the root of the workspace.",
|
|
},
|
|
changes: {
|
|
type: "string",
|
|
description: CHANGES_DESCRIPTION,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
defaultToolPolicy: "allowedWithPermission",
|
|
systemMessageDescription: createSystemMessageExampleCall(
|
|
BuiltInToolNames.EditExistingFile,
|
|
`To edit an EXISTING file, use the ${BuiltInToolNames.EditExistingFile} tool with
|
|
- filepath: the relative filepath to the file.
|
|
- changes: ${CHANGES_DESCRIPTION}
|
|
Only 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.
|
|
For example:`,
|
|
[
|
|
["filepath", "path/to/the_file.ts"],
|
|
[
|
|
"changes",
|
|
"// ... existing code ...\nfunction subtract(a: number, b: number): number {\n return a - b;\n}\n// ... rest of code ...",
|
|
],
|
|
],
|
|
),
|
|
};
|