Closed as not planned
Labels
Description
Problem
ui-packages/web/src/features/reader/text-file-reader.tsx:61decodes plain text withTextDecoder('utf-8', { fatal: true }). A GBK/GB18030-encoded.txt— still the default on many Chinese sites and services, and Shift-JIS likewise in Japan — lands on "Preview unavailable: This text file is not valid UTF-8."- The assistant's path fails identically, and its advice (
ui-packages/web/src/features/assistant/text-source.ts:19–21) is "If it is text in another encoding, import a UTF-8 copy." Transcoding a file is not an action PRODUCT.md's reader can perform: "ordinary readers… without a technical workspace." - The audience is demonstrably CJK — the codebase already tunes for it (
formats/docx.ts:116picksemDelimiterbecause "CJK text is all letters";composer/file-mentions.ts:8recognises an @ after Chinese punctuation). Meanwhile the WHATWG Encoding standard, supported by every target browser, shipsgb18030,shift_jis,big5and BOM-detected UTF-16 decoders — none of them used.
Proposal
- On fatal UTF-8 failure, retry a small fixed fallback ladder instead of failing: BOM-detected UTF-16/32 first, then
gb18030, thenshift_jis. UTF-8 stays strict-first, so valid UTF-8 never changes. - Put the ladder in
decodeUtf8(ui-packages/web/src/utils/text.ts:5), the one place both paths already meet, so the reader's tab and the assistant'sread/searchsee the same text. - Replace the "import a UTF-8 copy" instruction; the file the reader already imported is the one that should become readable.
Goal
After this, a GBK or Shift-JIS plain-text file opens as readable text in its tab, and the assistant reads the same text through read and search — no "Preview unavailable" state and no transcode-the-file instruction for a .txt.
Verification
# GB18030 and Shift-JIS byte fixtures decode to their original sentences,
# and a non-UTF-8 .txt opens through the text reader instead of the error state
cd ui-packages/web && pnpm vitest run --project unit src/utils/text.test.ts src/features/reader/text-file-reader.test.tsxRefs
ui-packages/web/src/features/reader/text-file-reader.tsx:61— fatal UTF-8 decode behind the error stateui-packages/web/src/features/assistant/text-source.ts:17— the same refusal on the agent path, with the transcode adviceui-packages/web/src/utils/text.ts:5—decodeUtf8, the shared seam for the fixui-packages/web/src/core/files.ts:63—txt/logroute into this pathui-packages/web/PRODUCT.mdUsers — ordinary readers without a technical workspace- CJK-aware precedent:
formats/docx.ts:116,composer/file-mentions.ts:8 - Adjacent in spirit to Teach import paths and assistant capabilities at the empty states, not only in the README #39: the repair belongs where the reader meets the failure, not in the README
Activity
bencode commentedon Oct 21, 2026
Independent review — posted by the scheduled issue-reviewer loop (a session separate from the one that files these issues), under the maintainer's standing instruction to evaluate, sharpen, or retire
source:scheduledproposals. Audited againstmain@ebb0ee0.Evidence audit: behavior confirmed; one premise needs correcting.
text-file-reader.tsx:61—new TextDecoder('utf-8', { fatal: true })in a try whose catch sets{ status: 'error', message: 'This text file is not valid UTF-8.' }(:72); the assistant path fails identically —text-source.ts:17→decodeUtf8→'This file is not UTF-8 text. If it is text in another encoding, import a UTF-8 copy.'(:19-21), verbatim.gb18030/shift_jis/big5decoder anywhere in the source;core/files.ts:63routes.txt/.loghere; CJK-aware precedents real (docx.ts:115-117emDelimiter comment;file-mentions.ts:10-12Chinese-punctuation comment — cited as :8, trivial drift); PRODUCT.md:10 backs the no-technical-workspace framing.decodeUtf8(utils/text.ts:5) is not "the one place both paths already meet" today. Its callers are the assistant'stext-source.ts:17and the markdown embed paths (embed-frame.tsx:104,embed-resize.ts:18); the text reader at:61inlines its ownnew TextDecoder(...). The fix's first step must routetext-file-reader.tsxthroughdecodeUtf8— the right move (one seam, and the embed paths then get the ladder for free), but as written the Refs claim is ahead of the code.Duplicate check: none (encoding/charset has no other issue). Sensor: lint ✓, verify ✗ — right reason: both named test files don't exist yet, so the anchor passes only when the described fixtures and tests are added. No repair needed.
Verdict: valid, keep open. One sharpening that affects the Goal: the proposed ladder puts
gb18030beforeshift_jis, but gb18030 accepts nearly every byte sequence — a Shift-JIS file will "successfully" decode into mojibake at the gb18030 rung and never reachshift_jis. Since the Goal promises both GBK and Shift-JIS readability, either order the ladder by a detection heuristic (e.g. decode-and-score, or BOM/locale hint), or scope the Goal to gb18030-family first with Shift-JIS behind an explicit encoding choice. As specified, a Shift-JIS fixture in the Verification block may expose exactly this.bencode commentedon Oct 25, 2026
Re-audit — posted by the scheduled issue-reviewer loop, independent of the authoring session. Audited against
main@90b046f.Evidence audit: anchors hold. No commit since the last review (
ebb0ee0→90b046f) touchestext-file-reader.tsx,text-source.ts,utils/text.tsorcore/files.ts. The reader still inlinesnew TextDecoder('utf-8', { fatal: true })(text-file-reader.tsx:61) with the rejection message now at:71(was:72, one-line drift, no behavior change); the assistant's'import a UTF-8 copy'message is verbatim attext-source.ts:20; still nogb18030/shift_jis/big5decoder anywhere in the source. The premise correction from the first review (the reader does not yet route throughdecodeUtf8) is still true.Duplicate check: none — #162 covers binary files being mislabeled text-readable, an adjacent but distinct defect; worth cross-referencing if #162's fix ever lands encoding advice here.
Sensor: lint ✓; verify ✗ for the right reason — both named test files (
utils/text.test.ts,text-file-reader.test.tsx) don't exist yet.Verdict: valid, stays open. The ladder-order sharpening from the first review (gb18030 accepts nearly any bytes, so a Shift-JIS fixture will decode into mojibake before
shift_jisis reached) still stands and should shape the implementation.bencode commentedon Oct 26, 2026
Closing as not planned. Gamma Reader reads plain text as UTF-8 only; we are not adding legacy encodings such as GBK or Shift-JIS.
To read a GBK or Shift-JIS text file, save it as UTF-8 first (for example with Save As → UTF-8 in Notepad, TextEdit or VS Code) and import that copy.