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

未关闭
#2,432 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
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 小时
30 天内合并 PR
103

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Zoo-Code-Org/Zoo-Code 的其他 Issue

查看 Zoo-Code-Org/Zoo-Code 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。