Expand description
Mirrors packages/agent/src/harness/tools/edit-diff.ts — the diff/fuzzy/apply
engine backing the edit tool.
Pipeline: detect_line_ending → strip_bom → normalize_to_lf →
apply_edits_to_normalized_content (fuzzy find, not-found/duplicate/overlap/
no-change errors, line-preserving replacement when fuzzy) →
restore_line_endings → generate_diff_string + generate_unified_patch.
Structs§
- Apply
Result - Result of
apply_edits_to_normalized_content. - BomResult
- Result of
strip_bom. - Diff
Result { diff, first_changed_line }. MirrorsgenerateDiffString.- Fuzzy
Match Result - Result of
fuzzy_find_text. - Replace
Edit - A single replacement
{ old_text, new_text }.
Functions§
- apply_
edits_ to_ normalized_ content - Empty-
old_text/ not-found / duplicate / overlap / no-change →Err. MirrorsapplyEditsToNormalizedContent. - count_
occurrences - Count occurrences of
old_textincontent(both fuzzy-normalized). MirrorscountOccurrences. - detect_
line_ ending - Detect the dominant line ending:
\r\nor\n. MirrorsdetectLineEnding. Lone\ris treated as\n(the normalizer maps both to\n). - fuzzy_
find_ text - Find
old_textincontent: exact first, then fuzzy-normalized. MirrorsfuzzyFindText. - generate_
diff_ string - A display-oriented diff (NOT a unified patch) with line-number prefixes.
Mirrors
generateDiffStringwith a 4-line context window. - generate_
unified_ patch - A unified-diff patch with 4 lines of context, file headers only (no
timestamps). Mirrors
generateUnifiedPatch(via thesimilarcrate, which is the Rust equivalent of the npmdiffpackage). - normalize_
for_ fuzzy_ match - NFKC + per-line trimEnd + smart-quote/dash/space normalization. Mirrors
normalizeForFuzzyMatch. - normalize_
to_ lf \r\nand lone\r→\n. MirrorsnormalizeToLF.- restore_
line_ endings \n→ending. MirrorsrestoreLineEndings.- strip_
bom - Strip a leading U+FEFF BOM. Mirrors
stripBom(returns the BOM string + the text without it).