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