refactor(cli): simplify isBinaryFile check to UTF-16 BOM only

Per review: CJK and legacy single-byte encodings already passed the old
control-char heuristic (their bytes are all >= 0x80, never NUL), so the
full Encoding.detect pass in isBinaryFile was solving a non-problem for
them. The only realistic regression in the old heuristic is UTF-16 with
BOM, where the second byte of every ASCII character is 0x00 and fires
the NUL-byte early-return.

Replace the detect call with a 2-byte BOM check via a new
Encoding.hasUtf16Bom helper. Also reword the move/add inline markers in
patch/index.ts to note that Encoding.write handles mkdir.
This commit is contained in:
kiloconnect[bot]
2026-04-22 13:04:30 +00:00
parent cce5e459bc
commit dfbdc97cd3
3 changed files with 9 additions and 5 deletions
+1 -1
View File
@@ -549,7 +549,7 @@ export namespace Patch {
if (hunk.move_path) {
// Handle file move
await Encoding.write(hunk.move_path, fileUpdate.content, fileUpdate.encoding) // kilocode_change
await Encoding.write(hunk.move_path, fileUpdate.content, fileUpdate.encoding) // kilocode_change - encoding-aware write (mkdirs)
await fs.unlink(hunk.path)
modified.push(hunk.move_path)
log.info(`Moved file: ${hunk.path} -> ${hunk.move_path}`)