Refactor util functions out of claude dev

This commit is contained in:
Saoud Rizwan
2024-09-29 02:52:43 -04:00
parent 9e01aaa3d3
commit ab327e3bbf
5 changed files with 89 additions and 81 deletions

View File

@@ -1,5 +1,6 @@
import { Anthropic } from "@anthropic-ai/sdk"
import * as path from "path"
import * as diff from "diff"
export const formatResponse = {
toolDenied: () => `The user denied this operation.`,
@@ -74,6 +75,14 @@ export const formatResponse = {
return sorted.join("\n")
}
},
createPrettyPatch: (filename = "file", oldStr: string, newStr: string) => {
// strings cannot be undefined or diff throws exception
const patch = diff.createPatch(filename.toPosix(), oldStr || "", newStr || "")
const lines = patch.split("\n")
const prettyPatchLines = lines.slice(4)
return prettyPatchLines.join("\n")
},
}
// to avoid circular dependency

View File

@@ -338,5 +338,15 @@ open http://localhost:3000
</command>
</attempt_completion>
By following this approach, you are able to make informed decisions at each step, using tools one at a time and ensuring each action is based on the previous step's result and logical progression of the task.
`
By following this approach, you are able to make informed decisions at each step, using tools one at a time and ensuring each action is based on the previous step's result and logical progression of the task.`
export function addCustomInstructions(customInstructions: string): string {
return `
====
USER'S CUSTOM INSTRUCTIONS
The following additional instructions are provided by the user. They should be followed and given precedence in case of conflicts with previous instructions.
${customInstructions.trim()}`
}