apply_diff reports a user edit that removed the BOM, and write_to_file drops the BOM it was given

オープン
#2,432 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
50/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

Start by tracing the apply_diff and write_to_file implementations in the extension, then inspect how they read and write files containing a UTF-8 BOM. Reproduce the report with the provided marked-file steps and compare the reported hunk with the file bytes; done means existing marks are preserved without a false user edit, and created files retain a supplied mark with an accurate report.

索引モデルが issue の本文から書いたものです。

説明

Summary

A write to a file that carries a byte-order mark comes back reporting that the user edited line 1 to remove the mark. The mark is still there. A file this tool creates with a mark loses it silently, and reports the same hunk.

It is every write to a marked file, not an occasional one: four writes to marked files in one session today produced four hunks, on three edits of an existing file and one creation.

Version

Zoo Code 3.96.0 (zoocodeorganization.zoo-code), Windows 11, after a window reload, in a Git repository whose files are LF in the working tree (text=auto eol=lf, w/lf).

To reproduce

  1. Write a file to disk with a mark, outside the extension: bytes EF BB BF, then # probe two, a blank line, alpha line, omega line, LF only.
  2. apply_diff that file, one block, changing only omega line on line 5.
  3. Read the tool result's user-edits hunk: it reads the mark stripped from line 1.
  4. Read the file's bytes: BOM True, first bytes b'\xef\xbb\xbf# probe two', line 5 changed.

The same hunk came back on each of three separate apply_diff calls to another marked file (PROJECT_SPEC_WALKS.md), with a byte read after each write printing BOM True. On a file created by write_to_file whose content began with U+FEFF, the same hunk came back and the bytes on disk began b'# diff p' - there the mark really was dropped.

Expected

Either the mark is preserved and no user edit is reported, or the report matches what is on disk. A write's answer should never describe a change that did not happen.

Why this matters

  • It invents a person's edit. The tool result carries a user-edits hunk saying line 1 was changed by the user. A session reads that as the person's own change to a file it is editing: it re-reads and re-quotes, or it "restores" a mark that was never missing. Our project recorded the same fault on 2026-10-18, where the repair was to read the file's bytes and find the mark intact both times.
  • The create path changes the file's encoding in silence. A file written by write_to_file with a mark is written without one, and nothing says so: the first commit records a whole-file change, and every later reader loses the encoding the author chose.
  • It makes real user edits hard to see. A change report that is always present is a report nobody reads, which is precisely when a person's real edit to line 1 goes by.

What we do meanwhile

  • Read the exact lines immediately before the diff and copy whole lines from that read. A stale quote is what produces the refusals described below: one failing block was 149 characters against a 143-character match, six characters of drift.
  • Keep a block small and on unique lines, so a refusal names one line rather than four.
  • After two refusals, stop re-quoting: rewrite the whole file with write_to_file from a fresh read, or make the change as a byte-level rewrite in a script.
  • Check the mark with a byte read, never with the tool's answer - open(p,'rb').read(3) == b'\xef\xbb\xbf'.
  • Keep no marked file in a state that depends on this report: a file the tool creates is re-marked by the script that needs one.

Related, not the same fault

Three apply_diff refusals in one session read No sufficiently similar match found … needs 100% at 95%, 88% and 49%, on LF files (one with a mark, one without), so this is not line endings. The exact requirement is the intended default in dist/extension.js (fuzzyThreshold built from Hpe = 1), so it is not filed as a fault - but a person editing long wrapped Markdown meets it often, and the extension's 19 contributed settings name nothing about diffs, so there is no way to buy tolerance short of switching tool.

主要言語
TypeScript
スター
2k
フォーク
301
平均マージ
3日 14時間
マージ済み PR(30日)
103

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Zoo-Code-Org/Zoo-Code のほかの issue

Zoo-Code-Org/Zoo-Code の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。