Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@marius-kilocode
Copy link
Collaborator

Summary

Follow-up to #5340 - Addresses PR review feedback about hardcoded newline characters not working correctly on Windows systems that use CRLF (\r\n) line endings.

Problem

The original fix for CLI file duplication (#5340) used hardcoded "\n" characters which don't work correctly on Windows:

  • When splitting by "\n" only, CRLF files leave \r at end of lines, causing incorrect byte offset calculations
  • When adding trailing newlines, using "\n" doesn't preserve the original file's EOL style

Solution

VSCode.ts Changes

  • Added CRLF normalization before offset calculation: content.replace(/\r\n/g, "\n")
  • This follows the established codebase pattern used in SearchReplaceTool.ts, EditFileTool.ts, and 88+ other locations

DiffViewProvider.ts Changes

  • Added EOL detection to preserve original file's line ending style
  • Uses content.includes("\r\n") ? "\r\n" : "\n" pattern when adding trailing newlines

Testing

  • Added 2 new test cases in VSCode.applyEdit.spec.ts for CRLF handling
  • Added 1 new test case in DiffViewProvider.spec.ts for CRLF preservation in CLI mode
  • All tests pass (4 in VSCode.applyEdit.spec.ts, 20 in DiffViewProvider.spec.ts)

@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2026

⚠️ No Changeset found

Latest commit: 9a58d4a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 1 package
Name Type
kilo-code Patch

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@marius-kilocode marius-kilocode force-pushed the fix-cli-file-dulication-follow-up branch from 716d1db to 9a58d4a Compare January 23, 2026 10:18
@marius-kilocode marius-kilocode requested a review from a team January 23, 2026 10:22
@marius-kilocode marius-kilocode enabled auto-merge (squash) January 23, 2026 10:23
@marius-kilocode marius-kilocode merged commit a6fdc14 into main Jan 23, 2026
20 of 21 checks passed
@marius-kilocode marius-kilocode deleted the fix-cli-file-dulication-follow-up branch January 23, 2026 10:38
maywzh pushed a commit to maywzh/kilocode that referenced this pull request Jan 25, 2026
maywzh pushed a commit to maywzh/kilocode that referenced this pull request Jan 25, 2026
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.

3 participants