Skip to content

fix: preserve BOM in text tool round-trips#23797

Merged
Hona merged 6 commits intoanomalyco:devfrom
Hona:fix/preserve-bom-in-text-tools
Apr 22, 2026
Merged

fix: preserve BOM in text tool round-trips#23797
Hona merged 6 commits intoanomalyco:devfrom
Hona:fix/preserve-bom-in-text-tools

Conversation

@Hona
Copy link
Copy Markdown
Member

@Hona Hona commented Apr 22, 2026

fixes THIS:

image

after

no weird BOM rendering! :)
image

Summary

  • preserve UTF-8 BOMs in write, edit, and apply_patch without leaking the BOM into visible diff or edit text
  • update patch application to carry BOM state through writes so formatter runs do not silently drop it
  • add regression tests covering BOM overwrite, first-line edits, and apply-patch preview diffs

Testing

  • bun test test/tool/write.test.ts test/tool/edit.test.ts test/tool/apply_patch.test.ts
  • bun typecheck

Copilot AI review requested due to automatic review settings April 22, 2026 06:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces BOM-aware read/write helpers and applies them across the write, edit, and apply_patch tools to preserve UTF-8 BOMs on disk while keeping BOMs out of visible diffs/patch previews, along with regression tests.

Changes:

  • Add util/bom.ts to split/join BOMs, read files while preserving BOM state, and re-sync BOM after formatting.
  • Update write, edit, and apply_patch flows to compute diffs on BOM-stripped text and to restore BOMs after formatter runs.
  • Add regression tests covering overwrite/edit/apply-patch scenarios involving BOM-prefixed files.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/opencode/src/util/bom.ts New shared BOM utilities (split/join/read/sync).
packages/opencode/src/tool/write.ts Preserve BOMs during write + after formatting, and keep BOM out of diff.
packages/opencode/src/tool/edit.ts Preserve BOMs for in-place edits and after formatting (with a couple of ordering/overwrite concerns).
packages/opencode/src/tool/apply_patch.ts Track BOM per file change and restore BOM after formatting so patches don’t invent first-line diffs.
packages/opencode/src/patch/index.ts Carry BOM state through patch-derived updates (but BOM detection depends on read semantics).
packages/opencode/test/tool/write.test.ts Regression test: overwriting existing BOM file preserves BOM.
packages/opencode/test/tool/edit.test.ts Regression test: first visible line edit in BOM file works and diff omits BOM.
packages/opencode/test/tool/apply_patch.test.ts Regression test: patch preview doesn’t show invented first-line diff; BOM preserved after apply.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/opencode/src/tool/edit.ts Outdated
Comment thread packages/opencode/src/patch/index.ts
Comment thread packages/opencode/src/tool/edit.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/opencode/src/format/index.ts Outdated
Comment thread packages/opencode/src/util/bom.ts
@Hona Hona enabled auto-merge (squash) April 22, 2026 07:57
@Hona Hona merged commit bb69648 into anomalyco:dev Apr 22, 2026
8 checks passed
erfianugrah pushed a commit to erfianugrah/opencode that referenced this pull request Apr 22, 2026
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.

2 participants