Conversation
The V2 edit leaf matched oldString with a single literal indexOf scan and hard-failed on anything inexact. V1's replace() already handled the common near-miss cases with nine ordered strategies; this ports the lenient ones as pure synchronous helpers and consults them only after exact matching returns zero. Adds line-trimmed, block-anchor, whitespace-normalized, indentation-flexible, escape-normalized, trimmed-boundary and context-aware matching, each bounded to the region oldString describes. An ambiguous candidate is skipped rather than guessed, so it still surfaces a multiple-matches error. The tool schema is unchanged, permission ordering is unchanged, and writes still go through writeIfUnchanged so stale-read protection is preserved. Clears the deferred fuzzy-parity TODOs in tool/edit.ts and tool/builtins.ts.
Fixes anomalyco#41872: replace() committed the first byte-unique candidate from a strategy, so two candidates that normalize to the same oldString but differ in bytes bypassed the multiple-match safeguard. Resolve a whole strategy before committing and dedupe by span rather than matched bytes. Fixes anomalyco#45199: block-anchor scored two blank lines as 0 instead of 1, so any block with enough blank lines could never clear the similarity threshold no matter how similar the rest was. Blank lines are an exact match. Both tests assert the old behavior fails, so they pin the fixes rather than the surrounding logic.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
This was referenced Sep 27, 2026
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.
Issue for this PR
Closes #51706
Fixes #41872
Fixes #45199
Type of change
What does this PR do?
The V2 edit tool matched
oldStringwith one literalindexOfscan, so a model that reproduced it with trailing whitespace, an indentation slip, or an extra blank line got a hard failure instead of an edit. This ports V1's lenient strategies intopackages/core/src/tool/edit-match.tsas pure synchronous helpers, consulted only after exact matching returns zero.It also fixes two open bugs in that logic rather than importing them:
replace()committed the first byte-unique candidate from a strategy, so two candidates that normalize to the sameoldStringbut differ in bytes bypassed the multiple-match safeguard. A strategy is now fully resolved and deduped by span before anything is committed.0instead of1, so a block with enough blank lines could never clear the similarity threshold however similar the rest was.Unchanged: the tool schema, permission ordering, and
writeIfUnchanged, so stale-read protection is untouched. Exact matching is still the fast path and still wins.I filed this as a bug fix rather than a feature because most of it is parity with shipped V1 behavior plus two verified bug fixes. If you'd rather treat the port itself as a design-review item, happy to split or hold it.
How did you verify your code works?
bun testinpackages/core: 1109 pass, 0 fail.contextAwarewas matching the input instead ofblock-anchor; the test now uses an input where only block-anchor can match.bunx oxlinton the four touched files: 0 warnings, 0 errors. Prettier clean.Not done: no runtime smoke test against a live model, and
isDisproportionateMatchis carried over as-is. I could not construct an input that trips it, since every strategy is structurally bounded below both its thresholds — but #31785 reported it as a real single-line bypass, so I did not want to assert it is dead without someone who knows the history confirming it.Screenshots / recordings
Not a UI change.
Checklist