Skip to main content

Module edit_replacers

Module edit_replacers 

Source
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):

  1. Simple — exact string match
  2. LineTrimmed — trim leading/trailing whitespace per line
  3. BlockAnchor — match by first/last lines as anchors, similarity for middle
  4. WhitespaceNormalized — collapse all whitespace to single space
  5. IndentationFlexible — strip indentation, match stripped content
  6. EscapeNormalized — normalize escape sequences
  7. TrimmedBoundary — trim first/last lines of old_content
  8. ContextAware — use surrounding context lines to locate position
  9. MultiOccurrence — trimmed line-by-line match as last resort

Structs§

MatchResult
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 original that matches old_content, or None if no pass succeeds.
find_occurrence_positions
Find line numbers (1-indexed) of all occurrences of needle in haystack.
normalize_line_endings
Normalize line endings to \n.
unified_diff
Generate a unified diff between two strings (like diff -u).