Skip to content

fix(edit): auto-correct whitespace mismatches in edit tool - #3452

Merged
taciturnaxolotl merged 2 commits into
mainfrom
better-tabs
Jul 30, 2026
Merged

fix(edit): auto-correct whitespace mismatches in edit tool#3452
taciturnaxolotl merged 2 commits into
mainfrom
better-tabs

Conversation

@taciturnaxolotl

Copy link
Copy Markdown
Member

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

taciturnaxolotl and others added 2 commits July 30, 2026 14:51
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
taciturnaxolotl merged commit 15d2e1a into main Jul 30, 2026
12 checks passed
@taciturnaxolotl
taciturnaxolotl deleted the better-tabs branch July 30, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants