diff --git a/src/core/diff/strategies/multi-file-search-replace.ts b/src/core/diff/strategies/multi-file-search-replace.ts index 57503da5f4..d35f32685e 100644 --- a/src/core/diff/strategies/multi-file-search-replace.ts +++ b/src/core/diff/strategies/multi-file-search-replace.ts @@ -410,7 +410,13 @@ Each file requires its own path, start_line, and diff elements. resultContent = singleResult.content successCount++ } else { - allFailParts.push(singleResult) + // If singleResult has failParts, push those directly to avoid nesting + if (singleResult.failParts && singleResult.failParts.length > 0) { + allFailParts.push(...singleResult.failParts) + } else { + // Otherwise push the single result itself + allFailParts.push(singleResult) + } } } diff --git a/src/core/tools/multiApplyDiffTool.ts b/src/core/tools/multiApplyDiffTool.ts index ba36cd3759..02ade08e4c 100644 --- a/src/core/tools/multiApplyDiffTool.ts +++ b/src/core/tools/multiApplyDiffTool.ts @@ -161,7 +161,6 @@ Expected structure: Original error: ${errorMessage}` throw new Error(detailedError) } - } else if (legacyPath && typeof legacyDiffContent === "string") { // Handle legacy parameters (old way) usingLegacyParams = true @@ -221,6 +220,7 @@ Original error: ${errorMessage}` try { // First validate all files and prepare for batch approval const operationsToApprove: OperationResult[] = [] + const allDiffErrors: string[] = [] // Collect all diff errors for (const operation of operations) { const { path: relPath, diff: diffItems } = operation @@ -427,6 +427,9 @@ Original error: ${errorMessage}` continue } + // Collect error for later reporting + allDiffErrors.push(`${relPath} - Diff ${i + 1}: ${failPart.error}`) + const errorDetails = failPart.details ? JSON.stringify(failPart.details, null, 2) : "" formattedError += ` Diff ${i + 1} failed for file: ${relPath} @@ -471,6 +474,17 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""} } cline.recordToolError("apply_diff", formattedError) results.push(formattedError) + + // For single file operations, we need to send a complete message to stop the spinner + if (operationsToApprove.length === 1) { + const sharedMessageProps: ClineSayTool = { + tool: "appliedDiff", + path: getReadablePath(cline.cwd, relPath), + diff: diffItems.map((item) => item.content).join("\n\n"), + } + // Send a complete message (partial: false) to update the UI and stop the spinner + await cline.ask("tool", JSON.stringify(sharedMessageProps), false).catch(() => {}) + } } continue } @@ -559,6 +573,11 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""} results.push(...filteredOperationErrors) } + // Report all diff errors at once if any + if (allDiffErrors.length > 0) { + await cline.say("diff_error", allDiffErrors.join("\n")) + } + // Push the final result combining all operation results pushToolResult(results.join("\n\n")) return