Skip to main content

Module str_replace

Module str_replace 

Source
Expand description

str_replace: 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)
  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.

Structsยง

StrReplaceTool