anomalyco / anomalyco/opencode
apply_patch forces a trailing newline onto files that lacked one
@kitlangton is already working on this.
Since Aug 28, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Describe the bug
packages/core/src/patch.ts derive() unconditionally appends a trailing newline to the result: if (updated.at(-1) !== "") updated.push("").
So apply_patch on a file that lacks a trailing newline adds one even when the patch doesn't touch the last line. patchFile then diffs before (no trailing newline) against after (with one), reporting a change the model never requested.
Repro: derive("f", [{ oldLines: ["line1"], newLines: ["LINE1"] }], "line1\nline2\nline3") → "LINE1\nline2\nline3\n".
Question
Is the forced trailing newline intentional (normalize EOF newline), or should the result preserve whether the original file ended with a newline?
Environment
- opencode version: latest dev
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.