Skip to content

fix(tools): count StrReplaceFile replacements against the running content#2524

Open
Sreekant13 wants to merge 1 commit into
MoonshotAI:mainfrom
Sreekant13:fix/str-replace-count
Open

fix(tools): count StrReplaceFile replacements against the running content#2524
Sreekant13 wants to merge 1 commit into
MoonshotAI:mainfrom
Sreekant13:fix/str-replace-count

Conversation

@Sreekant13

@Sreekant13 Sreekant13 commented Jul 20, 2026

Copy link
Copy Markdown

Related Issue

Resolves #2526

Description

StrReplaceFile applies its edits sequentially, but it 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.

For example, on a file containing hello world:

edits = [
    Edit(old="hello",   new="goodbye"),
    Edit(old="goodbye", new="farewell"),
]

both edits replace text and the file correctly becomes farewell world, but the tool reported:

File successfully edited. Applied 2 edit(s) with 1 total replacement(s).

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

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any. (StrReplaceFile reports too few total replacements for chained edits #2526)
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog. (Entry added to the Unreleased section by hand in the existing style; make gen-changelog drives Kimi CLI itself, which I could not run locally.)
  • I have run make gen-docs to update the user documentation. (N/A: no user-facing docs change.)

Open in Devin Review

…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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StrReplaceFile reports too few total replacements for chained edits

1 participant