Skip to main content

Module edit_diff

Module edit_diff 

Source
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§

ApplyResult
Result of apply_edits_to_normalized_content.
BomResult
Result of strip_bom.
DiffResult
{ diff, first_changed_line }. Mirrors generateDiffString.
FuzzyMatchResult
Result of fuzzy_find_text.
ReplaceEdit
A single replacement { old_text, new_text }.

Functions§

apply_edits_to_normalized_content
Empty-old_text / not-found / duplicate / overlap / no-change → Err. Mirrors applyEditsToNormalizedContent.
count_occurrences
Count occurrences of old_text in content (both fuzzy-normalized). Mirrors countOccurrences.
detect_line_ending
Detect the dominant line ending: \r\n or \n. Mirrors detectLineEnding. Lone \r is treated as \n (the normalizer maps both to \n).
fuzzy_find_text
Find old_text in content: exact first, then fuzzy-normalized. Mirrors fuzzyFindText.
generate_diff_string
A display-oriented diff (NOT a unified patch) with line-number prefixes. Mirrors generateDiffString with 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 the similar crate, which is the Rust equivalent of the npm diff package).
normalize_for_fuzzy_match
NFKC + per-line trimEnd + smart-quote/dash/space normalization. Mirrors normalizeForFuzzyMatch.
normalize_to_lf
\r\n and lone \r → \n. Mirrors normalizeToLF.
restore_line_endings
\n → ending. Mirrors restoreLineEndings.
strip_bom
Strip a leading U+FEFF BOM. Mirrors stripBom (returns the BOM string + the text without it).