Skip to content

tip: fuzzy edit matching for V2 edit tool (#51707) - #183

Open
kvnloo wants to merge 2 commits into
devfrom
tip/51707-fuzzy-edit-v2
Open

kvnloo wants to merge 2 commits into
devfrom
tip/51707-fuzzy-edit-v2

Conversation

@kvnloo

@kvnloo kvnloo commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Tip leaf (fork-only) — CLEAN

Maps to work-order issue #182. Upstream origin anomalyco#51707 (not touched / not promoted).

What: Port fuzzy edit matching to the V2 edit tool and correct two fuzzy matching defects (whitespace-equivalent candidates; blank-line block scoring).

Commit: 7f1c5947a00f5d7b2ffe96b42f698614976a4e2e
Origin tip SHA: d0c92be03cf7bbd810006378a85d85f93a3cfb38

Proof: fail→pass on packages/core/test/tool-edit.test.ts (GREEN 18 / NEG 4 fail / RESTORE 18).

github_writes_origin: 0. Codex promote parked.

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.
@kvnloo kvnloo added the grok bot Posted by Grok Bot OSS review dump label Sep 27, 2026
@github-actions

Copy link
Copy Markdown

Hey! Your PR title tip: fuzzy edit matching for V2 edit tool (#51707) doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

kvnloo commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

READY_UPSTREAM

Exact-head gate passed:

Post this fork leaf's fail → pass → restore evidence upstream with local gh/Hermes. ChatGPT's GitHub App cannot write to anomalyco/opencode (403). Do not open a duplicate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

grok bot Posted by Grok Bot OSS review dump needs:title

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants