anomalyco / anomalyco/opencode
apply_patch: `*** End of File` anchor is dead code and never anchors to the end
@kitlangton is already working on this.
Since Aug 19, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Bug description
The *** End of File anchor in apply_patch updates is parsed but never takes effect: packages/opencode/src/patch/index.ts parseUpdateFileChunks guards the change-line loop with !lines[i].startsWith("***"), so the *** End of File line can never enter the loop body and is_end_of_file stays undefined forever. The tryMatch EOF branch (match from end of file first) therefore never runs, and EOF-anchored patches silently fall back to plain forward matching, editing the first occurrence of the pattern instead of the last.
The reference parser in packages/core/src/patch.ts implements the same marker correctly (loop only excludes @@; the EOF marker is checked inside the body, and other *** lines break the loop).
Reproduction
File eof_anchor.txt containing marker\nend\nmiddle\nmarker\nend (no trailing newline), patch:
*** Begin Patch
*** Update File: eof_anchor.txt
@@
-marker
-end
+marker-changed
+end
*** End of File
*** End Patch
Expected: last marker occurrence edited (marker\nend\nmiddle\nmarker-changed\nend). Actual: first occurrence edited.
Environment
- OS: Windows
- opencode version: dev branch
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.