Skip to content

feat(init): add fuzzy edit replacers and edits-based apply-patchset#698

Merged
betegon merged 1 commit intomainfrom
feat/fuzzy-edit-replacers
Apr 9, 2026
Merged

feat(init): add fuzzy edit replacers and edits-based apply-patchset#698
betegon merged 1 commit intomainfrom
feat/fuzzy-edit-replacers

Conversation

@betegon
Copy link
Copy Markdown
Member

@betegon betegon commented Apr 9, 2026

Summary

Adds a fuzzy find-and-replace engine (ported from opencode) and extends apply-patchset to support oldString/newString edit pairs for file modifications.

Currently the codemod-planner outputs the complete file content for every modification, which wastes output tokens and makes retry expensive. This PR adds the client-side infrastructure for a more efficient approach: the server can send targeted edits instead, and the CLI applies them with fuzzy matching that tolerates minor whitespace/indentation differences from LLM output.

What's new

  1. replacers.ts -- 9 cascading fuzzy matching strategies (exact, line-trimmed, block-anchor+Levenshtein, whitespace-normalized, indentation-flexible, escape-normalized, trimmed-boundary, context-aware, multi-occurrence). Pure string functions, zero external deps.

  2. ApplyPatchsetPatch type -- Extended to support { action: "modify", edits: [{ oldString, newString }] } alongside the existing { action: "modify", patch: "full content" }.

  3. applySinglePatch in local-ops -- When a modify patch has an edits array, applies each edit sequentially using the fuzzy replacer. On failure, returns a pinpointed error: "Edit #N failed on 'file.ts': Could not find oldString...".

Backward compatibility

Patches with action: "modify" and a patch field (no edits) still use the existing full-content write path. Old server versions work with this client unchanged.

Server-side counterpart

This PR is client-only. The server-side changes (updating codemodEntrySchema, agent instructions, and buildPatches() in cli-init-api) will come in a separate PR.

Test plan

  • 15 unit tests for replace() covering each fuzzy strategy and real-world Sentry codemod scenarios
  • 5 integration tests for edits-based apply-patchset: success, failure, fuzzy matching, backward compat, mixed create+edits batch
  • All 186 existing init tests still pass
  • Linter clean

Made with Cursor

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (commands) Add buildRouteMap wrapper with standard subcommand aliases by BYK in #690
  • (init) Add fuzzy edit replacers and edits-based apply-patchset by betegon in #698

Bug Fixes 🐛

Dashboard

  • Add --layout flag to widget add for predictable placement by BYK in #700
  • Render tracemetrics widgets in dashboard view by BYK in #695

Other

  • (init) Narrow command validation to actual shell injection vectors by betegon in #697
  • (init,feedback) Default to tracing only in feature select and attach user email to feedback by MathurAditya724 in #688

Internal Changes 🔧

  • (docs) Gitignore generated command docs, extract fragments by BYK in #696
  • (eval) Replace OpenAI with Anthropic SDK in init-eval judge by betegon in #683
  • (init) Use markdown pipeline for spinner messages by betegon in #686
  • Regenerate skill files and command docs by github-actions[bot] in 584ec0e0

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/pr-preview/pr-698/

Built to branch gh-pages at 2026-04-09 13:20 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Codecov Results 📊

134 passed | Total: 134 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1513 uncovered lines.
❌ Project coverage is 95.43%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.48%    95.43%    -0.05%
==========================================
  Files          224       226        +2
  Lines        32591     33072      +481
  Branches         0         0         —
==========================================
+ Hits         31115     31559      +444
- Misses        1476      1513       +37
- Partials         0         0         —

Generated by Codecov Action

@betegon betegon force-pushed the feat/fuzzy-edit-replacers branch 3 times, most recently from 6774576 to b0cee7f Compare April 9, 2026 13:16
@betegon betegon marked this pull request as ready for review April 9, 2026 13:16
Port opencode's 9-strategy fuzzy matching chain as replacers.ts for
finding and replacing text in files despite minor whitespace, indentation,
or escape differences from LLM output.

Extend apply-patchset so modify actions use edits (oldString/newString
pairs) applied sequentially with the fuzzy replacer chain. Create actions
still use full-content patch strings. Errors pinpoint the exact failing
edit by file and index.

Made-with: Cursor
@betegon betegon force-pushed the feat/fuzzy-edit-replacers branch from b0cee7f to 1c79754 Compare April 9, 2026 13:19
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1c79754. Configure here.

@betegon betegon merged commit 4599ad1 into main Apr 9, 2026
27 checks passed
@betegon betegon deleted the feat/fuzzy-edit-replacers branch April 9, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant