You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
xxd after Edit: file now starts with 2320 (# ) — BOM stripped
So the bug persists in 2.3.1. Impact for us matches OP exactly: PowerShell 5.1 reads BOM-less .ps1 as ANSI/GBK → Chinese comments mojibake → parse errors. We currently mitigate with a team rule (agents forbidden from editing BOM files directly; BOM re-added + xxd-verified after any edit), but a proper fix (preserve BOM and line-ending style on write-back) would be much appreciated.
Activity
dvd233 commentedon Sep 16, 2026
我已定位根因并准备好了修复,想确认一下方向后再提交 PR。
根因:
FileEditService.edit读文件走fs.readText(path, { errors: 'strict' })→decodeTextWithErrors里TextDecoder的ignoreBOM默认 false → BOM 被剥掉;写回时fs.writeText直接用解码后的内容,BOM 不会加回。所以编辑带 BOM 的 UTF-8 文件后 BOM 丢失。Windows 下 PowerShell 5.1 / MSVC 依赖 BOM 判定 UTF-8,剥掉后中文会被按 GBK 误读。修复(本地已完成红绿测试):
fileEditService.ts在读前先fs.readBytes(path, 3)检测 BOM,写回时若原文件有 BOM 则补回 `` 前缀;无 BOM 的文件不受影响。已在test/app/edit/tools/edit.test.ts加了两个回归用例(带 BOM 保留 / 无 BOM 不新增)。按仓库政策(外部 PR 需维护者
/approve的 issue),想先确认这个方向是否可接受,以及是否只覆盖 Edit(Write 的 overwrite 语义不同,我暂未动)。如果方向 OK 我就开 PR。(声明:我使用 AI 编码助手辅助,以上根因定位与测试均在本人 Windows 机器本地执行验证。)
skywolf commentedon Sep 18, 2026
能解决一半问题也好了。最好也能覆盖Wirte,agent 经常也会用 Write 重写整个脚本。
突然醒悟,有AI可以自己修改源码了,我按你的方案试试。
fix(agent-core-v2): preserve BOM and line endings when Edit/Write mod…
skywolf commentedon Sep 18, 2026
@dvd233 我把Editor也修了,先自己用上。 1efd6ad
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
11 remaining items
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
NoX-programer commentedon Oct 24, 2026
补充一下最新情况(2026-10-24):
最新版 @moonshot-ai/[email protected](2026-10-23 发布)中该问题依然存在。
本机复现:对带 BOM 的 UTF-8 文件执行任意一次 Edit,BOM 即被剥离,
其余内容(包括文件末尾无换行的情况)均保持不变。0.42.0 上同样可复现。
核对了 2.3.1 的 dist/main.mjs 与 main 分支源码:FileEditService.edit
仍然是 readText({ errors: 'strict' }) → 替换 → writeText 的链路,
decodeTextWithErrors 中 TextDecoder 的 ignoreBOM 仍为默认值 false,
读写两侧都没有 BOM 的保留/恢复逻辑。
之前提到的修复提交 1efd6ad(preserve BOM and line endings when
Edit/Write modify existing files)目前不在 main 分支上
(compare 结果为 diverged),也没有关联到任何 PR,未进入任何已发布版本。
所以想麻烦维护者:能否 review 一下 1efd6ad 并合入,或者基于它开一个正式
PR?如果需要按仓库规范拆分、补测试或调整实现,我可以配合。
环境:Windows,@moonshot-ai/[email protected](0.42.0 同样复现)。
更新:我已按仓库规范开了 PR #4371(含 changeset 与回归测试)。该修复不仅覆盖 UTF-8 BOM,还覆盖全部 5 种带 BOM 的 Unicode 编码(UTF-8/UTF-16LE/UTF-16BE/UTF-32LE/UTF-32BE):Edit 保留原文件的 BOM 与编码;无 BOM 的文件走原有代码路径,行为不变。
AngieOdin commentedon Oct 24, 2026
Confirmed still reproducing on Windows + Kimi Code 2.3.1 (2026-10-24).
Environment: Windows 11 x64, Kimi Code CLI 2.3.1 (native installer, up-to-date per
kimi upgrade).Repro (same steps as OP):
printf '\xef\xbb\xbf# 中文註釋測試 BOM\nWrite-Host "hello"\n' > bom-test.ps1→ xxd showsefbb bf23(BOM present)hello→hello22320(#) — BOM strippedSo the bug persists in 2.3.1. Impact for us matches OP exactly: PowerShell 5.1 reads BOM-less .ps1 as ANSI/GBK → Chinese comments mojibake → parse errors. We currently mitigate with a team rule (agents forbidden from editing BOM files directly; BOM re-added + xxd-verified after any edit), but a proper fix (preserve BOM and line-ending style on write-back) would be much appreciated.
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…
fix: preserve BOM/line endings on Edit/Write, honor .editorconfig for…