-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: CLI file duplication bug when writing files (#5318) #5340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: d8980fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge OverviewThis PR fixes a CLI file duplication bug where content was written twice when creating or editing files. The changes include:
Code Quality Notes
Files Reviewed (4 files)
|
| // File doesn't exist, start with empty content | ||
| } | ||
|
|
||
| const originalLines = content.split("\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this hardcoded newline character work as intended on window?
Summary
Fixes #5318 - CLI writes file content twice when creating or editing files.
Problem
When the Kilo Code CLI creates or edits files, the content was being duplicated at the end of the file. This was visible in logs and caused issues where:
Root Causes
1. Multi-line Edit Logic in
applyEdit(Primary)In
packages/agent-runtime/src/host/VSCode.ts, the line-based edit logic had a bug:When
endChar = 0,lastLine.substring(0)returns the entire last line, causing duplication.2. Multiple
applyEditCalls in CLI Mode (Secondary)In
src/integrations/editor/DiffViewProvider.ts, theupdate()method made up to 3applyEditcalls when finalizing. In CLI mode, each call writes to disk, causing race conditions and potential duplication.Solution
VSCode.ts Changes
slice()operations[...edits]spread to prevent mutation of the original edit arrayDiffViewProvider.ts Changes
applyEditcall to replace the entire document contentTesting
packages/agent-runtime/src/host/__tests__/VSCode.applyEdit.spec.tssrc/integrations/editor/__tests__/DiffViewProvider.spec.ts