Skip to main content

Module edit

Module edit 

Source
Expand description

Edit: edit a file by replacing an exact string.

This is the recommended editing tool for single-file changes. The LLM provides an old_string (text to find) and new_string (replacement), and the tool does a precise search-and-replace with a fuzzy-match fallback chain that recovers from common LLM output quirks.

Fuzzy-match chain (first success wins):

  1. Exact match
  2. Quote normalization (curly to straight quotes) — both needle and haystack are normalised; the match position is used to extract the original bytes from the haystack so the replacement is exact.
  3. Trailing whitespace strip (rstrip each line of old_string)
  4. Quote normalization + trailing whitespace strip combined
  5. XML-tag desanitization (model-escaped tags to real tags)

When the match succeeds via quote normalization, curly-quote style is preserved in new_string so the edit does not silently change typography.

new_string has trailing whitespace stripped from each line before being written (matching the normalisation applied to old_string in step 3/4), unless the file is a Markdown file where trailing spaces are significant.

Structs§

EditTool