Skip to content

fix: unify on SEARCH/REPLACE parsing to stop literal bleed#10

Merged
cachebag merged 2 commits into
masterfrom
fix/search-replace
May 21, 2026
Merged

fix: unify on SEARCH/REPLACE parsing to stop literal bleed#10
cachebag merged 2 commits into
masterfrom
fix/search-replace

Conversation

@cachebag

Copy link
Copy Markdown
Owner

Reprompt responses previously went straight into the buffer via vim.split("\n"), with the user message asking for "ONLY replacement lines" while the system prompt mandated SEARCH/REPLACE format. The conflicting instructions occasionally caused the model to emit literal "<<<< SEARCH / ==== / >>>> REPLACE" lines, which landed verbatim in the source code.

This PR fixes it such that we route the reprompt path through patch.apply and update the user message to ask for SEARCH/REPLACE blocks against the proposed block.

We fall back to raw split when no blocks are present, and notify on unmatched blocks instead of silently corrupting the hunk.

Reprompt responses previously went straight into the buffer via
vim.split("\n"), with the user message asking for "ONLY replacement lines"
while the system prompt mandated SEARCH/REPLACE format. The conflicting
instructions occasionally caused the model to emit literal
"<<<< SEARCH / ==== / >>>> REPLACE" lines, which landed verbatim in the
source code.

Route the reprompt path through patch.apply (the same parser used for
initial requests) and update the user message to ask for SEARCH/REPLACE
blocks against the proposed block. One canonical format, one parser, no
contradictions. Falls back to raw split when no blocks are present, and
notifies on unmatched blocks instead of silently corrupting the hunk.
@cachebag cachebag self-assigned this May 21, 2026
@cachebag cachebag added bug Something is broken area:llm Providers, API calls, system prompt area:patch SEARCH/REPLACE parsing and application labels May 21, 2026
@cachebag cachebag merged commit 1b5f0d2 into master May 21, 2026
3 checks passed
@cachebag cachebag deleted the fix/search-replace branch May 21, 2026 13:36
@cachebag cachebag mentioned this pull request May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:llm Providers, API calls, system prompt area:patch SEARCH/REPLACE parsing and application bug Something is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant