refactor: remove debug functionality

This commit is contained in:
Daniel Riccio
2025-01-14 18:03:03 -05:00
parent e6d3db6075
commit f696f8e0f1
2 changed files with 7 additions and 28 deletions

View File

@@ -253,12 +253,11 @@ export async function applyEdit(
hunk: Hunk, hunk: Hunk,
content: string[], content: string[],
matchPosition: number, matchPosition: number,
confidence: number, confidence: number,
debug: string = '',
minConfidence: number = 0.9 minConfidence: number = 0.9
): Promise<EditResult> { ): Promise<EditResult> {
// Don't attempt regular edits if confidence is too low // Don't attempt regular edits if confidence is too low
if (confidence < minConfidence && debug === '') { if (confidence < minConfidence) {
console.log(`Search confidence (${confidence}) below minimum threshold (${minConfidence}), trying git fallback...`); console.log(`Search confidence (${confidence}) below minimum threshold (${minConfidence}), trying git fallback...`);
return applyGitFallback(hunk, content); return applyGitFallback(hunk, content);
} }
@@ -270,30 +269,10 @@ export async function applyEdit(
{ name: 'git-fallback', apply: () => applyGitFallback(hunk, content) } { name: 'git-fallback', apply: () => applyGitFallback(hunk, content) }
]; ];
if (debug !== '') { // Try strategies sequentially until one succeeds
// In debug mode, try all strategies including git fallback for (const strategy of strategies) {
const results = await Promise.all([ const result = await strategy.apply();
...strategies.map(async strategy => { if (result.confidence >= minConfidence) {
console.log(`Attempting edit with ${strategy.name} strategy...`);
const result = await strategy.apply();
console.log(`Strategy ${strategy.name} succeeded with confidence ${result.confidence}`);
return result;
})
]);
return results.find(result => result.strategy === debug) || { confidence: 0, result: content, strategy: 'none' };
} else {
// Normal mode - try strategies sequentially until one succeeds
for (const strategy of strategies) {
const result = await strategy.apply();
if (result.confidence === 1) {
return result;
}
}
// If all strategies fail, try git fallback
const result = await applyGitFallback(hunk, content);
if(result.confidence === 1) {
return result; return result;
} }
} }

View File

@@ -206,7 +206,7 @@ Your diff here
const contextStr = prepareSearchString(hunk.changes) const contextStr = prepareSearchString(hunk.changes)
const { index: matchPosition, confidence, strategy } = findBestMatch(contextStr, result, 0, this.confidenceThreshold) const { index: matchPosition, confidence, strategy } = findBestMatch(contextStr, result, 0, this.confidenceThreshold)
const editResult = await applyEdit(hunk, result, matchPosition, confidence, '', this.confidenceThreshold) const editResult = await applyEdit(hunk, result, matchPosition, confidence, this.confidenceThreshold)
if (editResult.confidence >= this.confidenceThreshold) { if (editResult.confidence >= this.confidenceThreshold) {
result = editResult.result result = editResult.result
} else { } else {