Expand description
9-pass fuzzy matching chain for the edit tool.
LLMs frequently produce slightly different whitespace, indentation, or escaping
in old_content. This module implements a chain of increasingly flexible
matching strategies, tried in order until one succeeds.
Pass order (strictest to most flexible):
- Simple — exact string match
- LineTrimmed — trim leading/trailing whitespace per line
- BlockAnchor — match by first/last lines as anchors, similarity for middle
- WhitespaceNormalized — collapse all whitespace to single space
- IndentationFlexible — strip indentation, match stripped content
- EscapeNormalized — normalize escape sequences
- TrimmedBoundary — trim first/last lines of old_content
- ContextAware — use surrounding context lines to locate position
- MultiOccurrence — trimmed line-by-line match as last resort
Structs§
- Match
Result - Result of a successful fuzzy match: the actual substring found in the original.
Functions§
- find_
match - Run the 9-pass replacer chain. Returns the actual substring in
originalthat matchesold_content, orNoneif no pass succeeds. - find_
occurrence_ positions - Find line numbers (1-indexed) of all occurrences of
needleinhaystack. - normalize_
line_ endings - Normalize line endings to
\n. - unified_
diff - Generate a unified diff between two strings (like
diff -u).