Refactor edit strategies and confidence validation in unified diff processing

- Enhanced the applyContextMatching and applyDMP functions to improve handling of context and edit changes.
- Updated confidence validation logic to ensure stricter checks, now requiring a minimum confidence of 1 for successful edits.
- Refined the way changes are processed, including better tracking of removal and addition changes.
- Improved the validation of edit results by incorporating strategy-specific checks and logging for better debugging.
- Adjusted the applyEdit function to ensure strategies are applied in a more robust manner, with clearer handling of debug mode.
This commit is contained in:
Daniel Riccio
2025-01-08 17:13:46 -05:00
parent 995692c48e
commit 9591ae062a
3 changed files with 136 additions and 105 deletions

View File

@@ -160,7 +160,7 @@ Your diff here
startLine?: number,
endLine?: number
): Promise<DiffResult> {
const MIN_CONFIDENCE = 0.9
const MIN_CONFIDENCE = 1
const parsedDiff = this.parseUnifiedDiff(diffContent)
const originalLines = originalContent.split("\n")
let result = [...originalLines]
@@ -170,7 +170,7 @@ Your diff here
const { index: matchPosition, confidence } = findBestMatch(contextStr, result)
const editResult = await applyEdit(hunk, result, matchPosition, confidence)
if (editResult.confidence > MIN_CONFIDENCE) {
if (editResult.confidence >= MIN_CONFIDENCE) {
result = editResult.result
} else {
return { success: false, error: `Failed to apply edit using ${editResult.strategy} strategy` }