Skip to main content

Module edit_diff

Module edit_diff 

Source
Expand description

Exact-replace edit application + unified-diff generation (core/tools/edit-diff.ts).

Structs§

Edit
One targeted replacement. old_text must match a unique, non-overlapping region of the original file.

Enums§

LineEnding

Functions§

apply_edits
Apply a set of edits to LF-normalized content. Each old_text is 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’s applyEditsToNormalizedContent). 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) where first_changed_line is 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’s oldText differs 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).