fix(core): prevent omission placeholder deletions in replace/write_file (#19870)

Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
This commit is contained in:
Nick Salerni
2026-02-22 11:58:31 -08:00
committed by GitHub
parent d96bd05d36
commit faa1ec3044
9 changed files with 282 additions and 8 deletions
+14
View File
@@ -54,6 +54,7 @@ import { debugLogger } from '../utils/debugLogger.js';
import levenshtein from 'fast-levenshtein';
import { EDIT_DEFINITION } from './definitions/coreTools.js';
import { resolveToolDeclaration } from './definitions/resolver.js';
import { detectOmissionPlaceholders } from './omissionPlaceholderDetector.js';
const ENABLE_FUZZY_MATCH_RECOVERY = true;
const FUZZY_MATCH_THRESHOLD = 0.1; // Allow up to 10% weighted difference
@@ -973,6 +974,19 @@ export class EditTool
}
params.file_path = filePath;
const newPlaceholders = detectOmissionPlaceholders(params.new_string);
if (newPlaceholders.length > 0) {
const oldPlaceholders = new Set(
detectOmissionPlaceholders(params.old_string),
);
for (const placeholder of newPlaceholders) {
if (!oldPlaceholders.has(placeholder)) {
return "`new_string` contains an omission placeholder (for example 'rest of methods ...'). Provide exact literal replacement text.";
}
}
}
return this.config.validatePathAccess(params.file_path);
}