Expand description
Exact-replace edit application + unified-diff generation
(core/tools/edit-diff.ts).
Structs§
- Edit
- One targeted replacement.
old_textmust match a unique, non-overlapping region of the original file.
Enums§
Functions§
- apply_
edits - Apply a set of edits to LF-normalized content. Each
old_textis matched against the original (not incrementally); edits must be unique and non-overlapping. As a fallback, when an exact match fails the search retries in fuzzy-normalized space (mirrors pi’sapplyEditsToNormalizedContent). If any edit needs fuzzy matching, all edits are applied in that space and then overlaid onto the original line-by-line so untouched lines keep their bytes. Returns(base, new)for diffing. - detect_
line_ ending - generate_
diff - Generate a unified diff between two strings (line-based, 3 lines of
context). Returns
(diff_string, first_changed_line)wherefirst_changed_lineis 1-indexed in the new file. - normalize_
for_ fuzzy_ match - Normalize text for fuzzy matching, mirroring pi’s
normalizeForFuzzyMatch: NFKC-fold, strip per-line trailing whitespace, and fold smart quotes / dashes / special spaces to their ASCII equivalents. Lets an edit land when the model’soldTextdiffers only in cosmetic whitespace or Unicode look-alikes. - normalize_
to_ lf - Normalize all line endings to LF.
- restore_
line_ endings - Restore the original line ending style.
- strip_
bom - Strip a UTF-8 BOM if present. Returns (bom, text).