fix(edit): auto-correct whitespace mismatches in edit tool - #3452
Merged
Conversation
taciturnaxolotl
force-pushed
the
better-tabs
branch
from
July 30, 2026 16:38
21b4f6d to
a2c2536
Compare
meowgorithm
approved these changes
Jul 30, 2026
taciturnaxolotl
force-pushed
the
better-tabs
branch
from
July 30, 2026 17:05
a2c2536 to
69bc0e1
Compare
Models frequently send old_string with the wrong indentation style (spaces when the file uses tabs, or vice versa), causing exact-match edits to fail. Weaker models then fall back to sed or python to perform the edit, which is slower and error-prone. When an exact match fails, the edit tool now normalizes whitespace per line and searches again. If a unique normalized match is found, it extracts the actual text from the file, detects the file's indent style (tabs vs N spaces, using the shallowest indented line as one unit), adapts new_string's indentation to match, and performs the replacement. Ambiguous or missing matches still return the existing diagnostic error with a whitespace-visualized hint. Covers both edit and multiedit since they share findAndReplace. fixes CHARM-1789 Co-authored-by: Christian Rocha <christian@rocha.is>
taciturnaxolotl
force-pushed
the
better-tabs
branch
from
July 30, 2026 18:51
69bc0e1 to
15d2e1a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Models frequently send old_string with the wrong indentation style (spaces when the file uses tabs, or vice versa), causing exact-match edits to fail. Weaker models then fall back to sed or python to perform the edit, which is slower and error-prone.
When an exact match fails, the edit tool now normalizes whitespace per line and searches again. If a unique normalized match is found, it extracts the actual text from the file, detects the file's indent style (tabs vs N spaces, using the shallowest indented line as one unit), adapts new_string's indentation to match, and performs the replacement. Ambiguous or missing matches still return the existing diagnostic error with a whitespace-visualized hint.
Covers both edit and multiedit since they share findAndReplace.
fixes CHARM-1789