MoonshotAI / MoonshotAI/kimi-cli

CRLF issue with StrReplaceFile

Open
#1,952 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
11.4k
Forks
1.3k
Avg merge
9h 47m
Merged PRs (30d)
2

Description

What version of Kimi Code CLI is running?

1.35.0

Which open platform/subscription were you using?

/login

Which model were you using?

kimi k2.6

What platform is your computer?

MacOS

What issue are you seeing?

When Kimi CLI edits files with CRLF line endings, a small StrReplaceFile edit can rewrite the whole file with LF line endings, causing large unrelated diffs.

What steps can reproduce the bug?
  1. Create a repo with Git text normalization disabled:
mkdir /tmp/kimi-crlf-repro
cd /tmp/kimi-crlf-repro
git init
git config core.autocrlf false
printf '* -text\n' > .gitattributes
printf 'const a = 1;\r\nconst b = 2;\r\n' > test.ts
git add .
git commit -m 'init'
  1. Run Kimi CLI and ask it to edit one line:
kimi --work-dir /tmp/kimi-crlf-repro --print --prompt 'Read test.ts and change const b = 2; to const b = 3;'
  1. Check the diff and bytes:
git diff -- test.ts
python - <<'PY'
from pathlib import Path
raw = Path("test.ts").read_bytes()
print(repr(raw))
print("CRLF:", raw.count(b"\r\n"))
print("bare LF:", raw.count(b"\n") - raw.count(b"\r\n"))
PY

What is the expected behavior?

Kimi CLI should preserve the original line endings when reading and editing files, so the diff only contains the real content change.
The content change is small, but the file may be rewritten from CRLF to LF, producing noisy line-ending churn.

Additional information

No response

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 StrReplaceFile implementation and reproduce the issue with the commands in this report, especially the byte-count check for test.ts. Trace how the file is read and written when changing one line. Done means the original CRLF endings remain and git diff shows only the requested content change.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.