MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / execute

Method execute

src/core/tools/ApplyDiffTool.ts:27–270  ·  view source on GitHub ↗
(params: ApplyDiffParams, task: Task, callbacks: ToolCallbacks)

Source from the content-addressed store, hash-verified

25 readonly name = "apply_diff" as const
26
27 async execute(params: ApplyDiffParams, task: Task, callbacks: ToolCallbacks): Promise<void> {
28 const { askApproval, handleError, pushToolResult } = callbacks
29 let { path: relPath, diff: diffContent } = params
30
31 if (diffContent && !task.api.getModel().id.includes("claude")) {
32 diffContent = unescapeHtmlEntities(diffContent)
33 }
34
35 try {
36 if (!relPath) {
37 task.consecutiveMistakeCount++
38 task.recordToolError("apply_diff")
39 pushToolResult(await task.sayAndCreateMissingParamError("apply_diff", "path"))
40 return
41 }
42
43 if (!diffContent) {
44 task.consecutiveMistakeCount++
45 task.recordToolError("apply_diff")
46 pushToolResult(await task.sayAndCreateMissingParamError("apply_diff", "diff"))
47 return
48 }
49
50 const accessAllowed = task.rooIgnoreController?.validateAccess(relPath)
51
52 if (!accessAllowed) {
53 await task.say("rooignore_error", relPath)
54 pushToolResult(formatResponse.rooIgnoreError(relPath))
55 return
56 }
57
58 const absolutePath = path.resolve(task.cwd, relPath)
59 const fileExists = await fileExistsAtPath(absolutePath)
60
61 if (!fileExists) {
62 task.consecutiveMistakeCount++
63 task.recordToolError("apply_diff")
64 const formattedError = `File does not exist at path: ${absolutePath}\n\n<error_details>\nThe specified file could not be found. Please verify the file path and try again.\n</error_details>`
65 await task.say("error", formattedError)
66 task.didToolFailInCurrentTurn = true
67 pushToolResult(formattedError)
68 return
69 }
70
71 const originalContent: string = await fs.readFile(absolutePath, "utf-8")
72
73 // Apply the diff to the original content
74 const diffResult = (await task.diffStrategy?.applyDiff(
75 originalContent,
76 diffContent,
77 parseInt(params.diff.match(/:start_line:(\d+)/)?.[1] ?? ""),
78 )) ?? {
79 success: false,
80 error: "No diff strategy available",
81 }
82
83 if (!diffResult.success) {
84 task.consecutiveMistakeCount++

Callers

nothing calls this directly

Calls 15

unescapeHtmlEntitiesFunction · 0.90
fileExistsAtPathFunction · 0.90
sanitizeUnifiedDiffFunction · 0.90
computeDiffStatsFunction · 0.90
getReadablePathFunction · 0.90
pushToolResultFunction · 0.85
askApprovalFunction · 0.85
handleErrorFunction · 0.85
recordToolErrorMethod · 0.80
sayMethod · 0.80

Tested by

no test coverage detected