MoonshotAI / MoonshotAI/kimi-cli
StrReplaceFile reports too few total replacements for chained edits
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 11.4k
- Forks
- 1.3k
- Avg merge
- 9h 47m
- Merged PRs (30d)
- 2
Description
What issue are you seeing?
StrReplaceFile applies its edits sequentially, but it counts the total number of replacements against the original file content instead of the running (progressively edited) content. When one edit's old string is text produced by an earlier edit, that edit is not present in the original content, so it is counted as zero even though it is applied correctly.
The file is written correctly; only the "total replacement(s)" number in the tool result message is wrong.
Steps to reproduce
Apply two chained edits to a file containing hello world:
edits = [
Edit(old="hello", new="goodbye"),
Edit(old="goodbye", new="farewell"),
]
The file correctly becomes farewell world, but the tool reports:
File successfully edited. Applied 2 edit(s) with 1 total replacement(s).
The second edit (goodbye -> farewell) is counted as 0 because goodbye does not appear in the original content, only in the content produced by the first edit.
Expected behavior
The reported count should reflect the replacements actually performed, i.e. 2 total replacement(s) for the example above. Each edit should be counted against the content it is applied to (the running content), not the original.
Additional information
Found by reading the tool source. I have a fix ready with a regression test.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the StrReplaceFile tool implementation and trace how each edit is applied and counted. Reproduce the chained hello-to-goodbye-to-farewell example, then add or run the regression test mentioned in the issue; done means the file remains correct and the result reports 2 total replacements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100