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

Method handleUpdateFile

src/core/tools/ApplyPatchTool.ts:290–451  ·  view source on GitHub ↗
(
		change: ApplyPatchFileChange,
		absolutePath: string,
		relPath: string,
		task: Task,
		callbacks: ToolCallbacks,
		isWriteProtected: boolean,
	)

Source from the content-addressed store, hash-verified

288 }
289
290 private async handleUpdateFile(
291 change: ApplyPatchFileChange,
292 absolutePath: string,
293 relPath: string,
294 task: Task,
295 callbacks: ToolCallbacks,
296 isWriteProtected: boolean,
297 ): Promise<void> {
298 const { askApproval, pushToolResult } = callbacks
299
300 // Check if file exists
301 const fileExists = await fileExistsAtPath(absolutePath)
302 if (!fileExists) {
303 task.consecutiveMistakeCount++
304 task.recordToolError("apply_patch")
305 const errorMessage = `File not found: ${relPath}. Cannot update a non-existent file.`
306 await task.say("error", errorMessage)
307 pushToolResult(formatResponse.toolError(errorMessage))
308 return
309 }
310
311 const originalContent = change.originalContent || ""
312 const newContent = change.newContent || ""
313 const isOutsideWorkspace = isPathOutsideWorkspace(absolutePath)
314
315 // Initialize diff view
316 task.diffViewProvider.editType = "modify"
317 task.diffViewProvider.originalContent = originalContent
318
319 // Generate and validate diff
320 const diff = formatResponse.createPrettyPatch(relPath, originalContent, newContent)
321 if (!diff) {
322 pushToolResult(`No changes needed for '${relPath}'`)
323 await task.diffViewProvider.reset()
324 return
325 }
326
327 // Check experiment settings
328 const provider = task.providerRef.deref()
329 const state = await provider?.getState()
330 const diagnosticsEnabled = state?.diagnosticsEnabled ?? true
331 const writeDelayMs = state?.writeDelayMs ?? DEFAULT_WRITE_DELAY_MS
332 const isPreventFocusDisruptionEnabled = experiments.isEnabled(
333 state?.experiments ?? {},
334 EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION,
335 )
336
337 const sanitizedDiff = sanitizeUnifiedDiff(diff)
338 const diffStats = computeDiffStats(sanitizedDiff) || undefined
339
340 const sharedMessageProps: ClineSayTool = {
341 tool: "appliedDiff",
342 path: getReadablePath(task.cwd, relPath),
343 diff: sanitizedDiff,
344 originalContent,
345 isOutsideWorkspace,
346 }
347

Callers 1

executeMethod · 0.95

Calls 15

fileExistsAtPathFunction · 0.90
isPathOutsideWorkspaceFunction · 0.90
sanitizeUnifiedDiffFunction · 0.90
computeDiffStatsFunction · 0.90
getReadablePathFunction · 0.90
pushToolResultFunction · 0.85
askApprovalFunction · 0.85
recordToolErrorMethod · 0.80
sayMethod · 0.80
isEnabledMethod · 0.80
openMethod · 0.80
scrollToFirstDiffMethod · 0.80

Tested by

no test coverage detected