anomalyco / anomalyco/opencode

apply_patch forces a trailing newline onto files that lacked one

Open
#45,912 2 comments 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.