fix(tools): count StrReplaceFile replacements against the running content#2524
Open
Sreekant13 wants to merge 1 commit into
Open
fix(tools): count StrReplaceFile replacements against the running content#2524Sreekant13 wants to merge 1 commit into
Sreekant13 wants to merge 1 commit into
Conversation
…tent StrReplaceFile applies its edits sequentially but computed the reported replacement count against the original file content. A chained edit whose `old` string is produced by an earlier edit is not present in the original, so it was counted as zero: editing "hello" -> "goodbye" then "goodbye" -> "farewell" reported "1 total replacement(s)" instead of 2. Count each edit against the content it is actually applied to, and add a regression test.
This was referenced Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Resolves #2526
Description
StrReplaceFileapplies its edits sequentially, but it computed the reported replacement count against the original file content. A chained edit whoseoldstring is produced by an earlier edit is not present in the original, so it was counted as zero.For example, on a file containing
hello world:both edits replace text and the file correctly becomes
farewell world, but the tool reported:because
"goodbye"was not found in the original content. This counts each edit against the content it is actually applied to (the running content), so the reported number matches what happened (2 total replacement(s)above).The file output itself is unchanged; only the reported count is corrected. A regression test is added that fails on the current code.
Checklist
make gen-changelogto update the changelog. (Entry added to the Unreleased section by hand in the existing style;make gen-changelogdrives Kimi CLI itself, which I could not run locally.)make gen-docsto update the user documentation. (N/A: no user-facing docs change.)