Skip to content

Commit f3d0f4e

Browse files
committed
fix: reduce redundant context in apply_diff error messages
- Remove redundant "Search Content" section that repeats what the model just sent - Remove verbose "Original Content" section that consumes context window space - Keep only the essential "Best Match Found" section for debugging - Maintains similarity score, threshold, and helpful tip to use read_file Fixes #5795
1 parent a92ee56 commit f3d0f4e

File tree

2 files changed

+2
-28
lines changed

2 files changed

+2
-28
lines changed

src/core/diff/strategies/multi-file-search-replace.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -615,19 +615,6 @@ Each file requires its own path, start_line, and diff elements.
615615
replaceLines = replaceContent ? replaceContent.split(/\r?\n/) : []
616616
} else {
617617
// No match found with either method
618-
const originalContentSection =
619-
startLine !== undefined && endLine !== undefined
620-
? `\n\nOriginal Content:\n${addLineNumbers(
621-
resultLines
622-
.slice(
623-
Math.max(0, startLine - 1 - this.bufferLines),
624-
Math.min(resultLines.length, endLine + this.bufferLines),
625-
)
626-
.join("\n"),
627-
Math.max(1, startLine - this.bufferLines),
628-
)}`
629-
: `\n\nOriginal Content:\n${addLineNumbers(resultLines.join("\n"))}`
630-
631618
const bestMatchSection = bestMatchContent
632619
? `\n\nBest Match Found:\n${addLineNumbers(bestMatchContent, matchIndex + 1)}`
633620
: `\n\nBest Match Found:\n(no match)`
@@ -644,7 +631,7 @@ Each file requires its own path, start_line, and diff elements.
644631
bestMatchScore * 100,
645632
)}%\n- Required Threshold: ${Math.floor(this.fuzzyThreshold * 100)}%\n- Search Range: ${
646633
startLine ? `starting at line ${startLine}` : "start to end"
647-
}\n- Tried both standard and aggressive line number stripping\n- Tip: Use the read_file tool to get the latest content of the file before attempting to use the apply_diff tool again, as the file content may have changed\n\nSearch Content:\n${searchChunk}${bestMatchSection}${originalContentSection}`,
634+
}\n- Tried both standard and aggressive line number stripping\n- Tip: Use the read_file tool to get the latest content of the file before attempting to use the apply_diff tool again, as the file content may have changed${bestMatchSection}`,
648635
})
649636
continue
650637
}

src/core/diff/strategies/multi-search-replace.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -521,19 +521,6 @@ Only use a single line of '=======' between search and replacement content, beca
521521
replaceLines = replaceContent ? replaceContent.split(/\r?\n/) : []
522522
} else {
523523
// No match found with either method
524-
const originalContentSection =
525-
startLine !== undefined && endLine !== undefined
526-
? `\n\nOriginal Content:\n${addLineNumbers(
527-
resultLines
528-
.slice(
529-
Math.max(0, startLine - 1 - this.bufferLines),
530-
Math.min(resultLines.length, endLine + this.bufferLines),
531-
)
532-
.join("\n"),
533-
Math.max(1, startLine - this.bufferLines),
534-
)}`
535-
: `\n\nOriginal Content:\n${addLineNumbers(resultLines.join("\n"))}`
536-
537524
const bestMatchSection = bestMatchContent
538525
? `\n\nBest Match Found:\n${addLineNumbers(bestMatchContent, matchIndex + 1)}`
539526
: `\n\nBest Match Found:\n(no match)`
@@ -542,7 +529,7 @@ Only use a single line of '=======' between search and replacement content, beca
542529

543530
diffResults.push({
544531
success: false,
545-
error: `No sufficiently similar match found${lineRange} (${Math.floor(bestMatchScore * 100)}% similar, needs ${Math.floor(this.fuzzyThreshold * 100)}%)\n\nDebug Info:\n- Similarity Score: ${Math.floor(bestMatchScore * 100)}%\n- Required Threshold: ${Math.floor(this.fuzzyThreshold * 100)}%\n- Search Range: ${startLine ? `starting at line ${startLine}` : "start to end"}\n- Tried both standard and aggressive line number stripping\n- Tip: Use the read_file tool to get the latest content of the file before attempting to use the apply_diff tool again, as the file content may have changed\n\nSearch Content:\n${searchChunk}${bestMatchSection}${originalContentSection}`,
532+
error: `No sufficiently similar match found${lineRange} (${Math.floor(bestMatchScore * 100)}% similar, needs ${Math.floor(this.fuzzyThreshold * 100)}%)\n\nDebug Info:\n- Similarity Score: ${Math.floor(bestMatchScore * 100)}%\n- Required Threshold: ${Math.floor(this.fuzzyThreshold * 100)}%\n- Search Range: ${startLine ? `starting at line ${startLine}` : "start to end"}\n- Tried both standard and aggressive line number stripping\n- Tip: Use the read_file tool to get the latest content of the file before attempting to use the apply_diff tool again, as the file content may have changed${bestMatchSection}`,
546533
})
547534
continue
548535
}

0 commit comments

Comments
 (0)