MoonshotAI / MoonshotAI/kimi-code

Kimi code内置Edit工具剥掉BOM问题

Open
#3,825 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

你运行的 Kimi Code 版本是?

0.43.1

你使用的是哪个开放平台/订阅?

Kimi Code (kimi.com/code)

你使用的是哪个模型?

K2.7 Code Highspeed

你的电脑平台是?

Microsoft Windows NT 10.0.19045.0 x64

你遇到了什么问题?

用 Edit(或 Write)修改一个带 BOM 的 UTF-8 文件后,保存出来的文件 BOM 丢失,变成无 BOM UTF-8。每次编辑都发生,不是偶发。

影响(Windows 生态下是真实事故,不是洁癖)

  1. PowerShell 5.1 对 .ps1 的编码判定规则是"有 BOM 按 BOM,无 BOM 按 ANSI(GBK)"。
    BOM 被剥掉后,脚本里的中文注释/字符串被当 GBK 误读,直接报一堆引号/括号解析错误。
    我们项目已多次踩坑,现在被迫给 agent 立规矩"每次 Edit 后手动 sed 补 BOM 并 xxd 验证"。

  2. 项目 .editorconfig 约定 cpp/h 用 UTF-8 BOM(VS/MSVC 中文场景事实标准),
    agent 一次普通编辑就悄悄违反约定,git diff 里还看不出来。

  3. 同类问题还有换行符:CRLF 文件经编辑后行尾风格是否保留也应明确。

复现步骤?
  1. 创建带 BOM 的 UTF-8 文件

      printf '\xef\xbb\xbfhello\n中文\n' > /c/Users/zjj/temp_bom_test/t.txt
    

    初始状态:

      --- initial bytes ---
      00000000: efbb bf68 656c                           ...hel
      --- file info ---
      .../t.txt: Unicode text, UTF-8 (with BOM) text
    

    前三个字节是 ef bb bf,确认带 BOM。

    1. 用 Edit 工具修改

    把第一行 hello 改成 hello2。

    1. 再次检查文件头
      --- bytes after Edit ---
      00000000: 6865 6c6c 6f32                           hello2
      --- file info ---
      .../t.txt: Unicode text, UTF-8 text
    

    BOM 已消失:前三个字节从 ef bb bf 变成了 68 65 6c(即 hel),file 命令也从 UTF-8 (with BOM) text 变成了 UTF-8 text。

    结论

    当前版本 Kimi Code 的 Edit 工具仍然会剥掉 UTF-8 BOM。复现文件我留在:

期望的行为是什么?
  • Edit/Write 写回文件时检测并保留原文件的 BOM(UTF-8/UTF-16LE/BE)与换行风格;新文件再按 .editorconfig 或配置决定。
  • 如果短期不改,请在工具描述里明确写出"会丢 BOM",免得各项目各自踩坑后才发现。
补充信息

No response

Contribution
  • 我愿意自己提交修复此 bug 的 PR(请先等待维护者在本 issue 中批准)

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.

Research direction

Start by locating the Edit and Write tool entry points and the file-writing path they share. Reproduce the supplied BOM case on Windows, then verify that edits preserve the original UTF-8/UTF-16 BOM and line-ending style without changing the requested content.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.