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

Method requestApproval

src/core/tools/ReadFileTool.ts:427–534  ·  view source on GitHub ↗

* Request user approval for file reads.

(
		task: Task,
		filesToApprove: FileResult[],
		updateFileResult: (path: string, updates: Partial<FileResult>) => void,
	)

Source from the content-addressed store, hash-verified

425 * Request user approval for file reads.
426 */
427 private async requestApproval(
428 task: Task,
429 filesToApprove: FileResult[],
430 updateFileResult: (path: string, updates: Partial<FileResult>) => void,
431 ): Promise<void> {
432 if (filesToApprove.length === 0) return
433
434 if (filesToApprove.length > 1) {
435 // Batch approval
436 const batchFiles = filesToApprove.map((fileResult) => {
437 const relPath = fileResult.path
438 const fullPath = path.resolve(task.cwd, relPath)
439 const isOutsideWorkspace = isPathOutsideWorkspace(fullPath)
440 const readablePath = getReadablePath(task.cwd, relPath)
441
442 const lineSnippet = this.getLineSnippet(fileResult.entry!)
443 const key = `${readablePath}${lineSnippet ? ` (${lineSnippet})` : ""}`
444
445 return { path: readablePath, lineSnippet, isOutsideWorkspace, key, content: fullPath }
446 })
447
448 const completeMessage = JSON.stringify({ tool: "readFile", batchFiles } satisfies ClineSayTool)
449 const { response, text, images } = await task.ask("tool", completeMessage, false)
450
451 if (response === "yesButtonClicked") {
452 if (text) await task.say("user_feedback", text, images)
453 filesToApprove.forEach((fr) => {
454 updateFileResult(fr.path, { status: "approved", feedbackText: text, feedbackImages: images })
455 })
456 } else if (response === "noButtonClicked") {
457 if (text) await task.say("user_feedback", text, images)
458 task.didRejectTool = true
459 filesToApprove.forEach((fr) => {
460 updateFileResult(fr.path, {
461 status: "denied",
462 nativeContent: `File: ${fr.path}\nStatus: Denied by user`,
463 feedbackText: text,
464 feedbackImages: images,
465 })
466 })
467 } else {
468 // Individual permissions
469 try {
470 const individualPermissions = JSON.parse(text || "{}")
471 let hasAnyDenial = false
472
473 batchFiles.forEach((batchFile, index) => {
474 const fileResult = filesToApprove[index]
475 const approved = individualPermissions[batchFile.key] === true
476
477 if (approved) {
478 updateFileResult(fileResult.path, { status: "approved" })
479 } else {
480 hasAnyDenial = true
481 updateFileResult(fileResult.path, {
482 status: "denied",
483 nativeContent: `File: ${fileResult.path}\nStatus: Denied by user`,
484 })

Callers 1

executeNewMethod · 0.95

Calls 8

getLineSnippetMethod · 0.95
getStartLineMethod · 0.95
isPathOutsideWorkspaceFunction · 0.90
getReadablePathFunction · 0.90
askMethod · 0.80
sayMethod · 0.80
forEachMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected