Add unit tests for the Encoding namespace and extend the tool integration
suite with ApplyPatch delete and EditTool replaceAll paths for non-UTF-8
files.
Strip a leading U+FEFF from text before prepending a UTF-8/UTF-16 BOM so
round-tripping content that already carries a BOM character emits exactly
one BOM. Also clarifies the changeset that new files default to UTF-8.
Main moved the Patch namespace out of packages/opencode/src/patch/index.ts
into patch/patch.ts and switched tool imports to the new
@opencode-ai/shared/filesystem and ../../src/tool barrels. Reapply the
encoding-aware read/write changes on top of the refactored patch.ts, and
update the integration test imports to match the new module layout.
- Encoding.detect: lowercase-compare UTF-32 rejection so jschardet's
uppercase 'UTF-32'/'UTF-32BE'/'UTF-32LE' labels no longer slip through
(iconv-lite happens to have utf-32 codecs that would then be accepted).
- Encoding.read: drop redundant Buffer.from wrap around readFile's
already-Buffer return value.
- EncodedIO: switch to Effect.tryPromise so I/O failures surface as
typed errors that .pipe(Effect.catch(...)) can recover from; the
apply_patch delete branch relies on this to translate read errors
into 'apply_patch verification failed'.
- Shrink kilocode_change blocks in edit.ts, write.ts, apply_patch.ts,
patch/index.ts, and read.ts to per-line inline markers where each
block was only wrapping 1-3 changed lines.
- Collapse the 'if (exists) { let contentOld; let encoding; ... }'
blocks in edit.ts and write.ts into a single ternary + destructure
that keeps all three lines self-contained and each independently
annotated.
- Remove the unused 'latin1' sample and fix the 'providEncoded' typo
in the encoding integration test file.
- Strengthen the apply_patch Shift_JIS test to assert exact bytes
instead of the weak 'does not contain these two UTF-8 bytes' check.
- Drop the stray .kilo/ and .kilocode/ lockfiles that were re-added
by an upstream 'wip' commit.
iconv-lite's utf-8 codec strips any leading BOM on decode and never emits
one on encode, so files that started with EF BB BF would lose their BOM
after an edit. Track UTF-8-with-BOM as a distinct synthetic encoding label
and re-prepend the BOM bytes on write so the round-trip keeps the file
byte-identical (modulo any actual edits).
- Restore the streaming createInterface loop in the `lines` helper so the
diff against main stays small; decode bytes with iconv-lite up front and
feed the resulting text through Readable.from.
- Drop 'new file' kilocode_change markers from files under kilocode/
directories (those paths are exempt from the annotation check).
- Tighten the changeset copy to sound like a user-facing release note.
Exercise Read/Write/Edit/ApplyPatch tools directly against files in
UTF-8, UTF-16 LE/BE (with BOM), Shift_JIS, EUC-JP, GB2312, Big5, EUC-KR,
Windows-1251, and KOI8-R to verify the tools decode input correctly and
round-trip bytes back to the original encoding. Also ensure UTF-16
BOMs survive the write pipeline.