Preview fallback for fake docx artifacts and readable Office errors #22

Merged
weichen merged 3 commits from feature/preview-sniff-fallback into main 2026-10-01 05:20:16 +00:00
Owner

Track 2 of the fake-docx remediation (siblings: feature/docx-generation handles the generation-side root cause).

Why

Agent-generated ".docx" artifacts were historically plain-text bytes; the docx preview fed them straight to mammoth/JSZip which threw Can't find end of central directory (reproduced verbatim with JSZip.loadAsync on text bytes).

Changes

  • @ui previewKindOf: .docx stays docx; legacy .doc (binary Word, not OOXML) routes to binary + download fallback instead of a guaranteed JSZip explosion.
  • @ui OfficePreview: user-facing error converges to one actionable line (corrupted / not a valid DOCX / pseudo-Office file); raw error goes to console.
  • frontend docxLoader: sniff ZIP magic (PK\x03\x04 / PK\x05\x06) before mammoth; non-ZIP bytes render as markdown with a readable note — stock fake docx artifacts become readable immediately.
  • parent: .gitignore gains .mimosa/ (Mimosa plugin per-session state kept dirtying the tree and blocking precheck).

Verification

  • make test-ui: tsc --noEmit clean + vitest 49/49 (new: 旧文档.doc → binary, error-note assertion)
  • make test-frontend: vitest 33/33; frontend tsc --noEmit clean
  • task-sync checkpoint: sync_base=d64742c71c tested_head=af13fba (2026-09-30T17:51:59Z)

Impact

Preview-layer only, no contract change. Until the generation-side track merges, newly written .docx remains text but previews readably.

Refs: .task/feature-preview-sniff-fallback.md; merge order: Agent-System-UI / Agent-System-Frontend PRs first, then this parent PR (pins those heads).

Track 2 of the fake-docx remediation (siblings: feature/docx-generation handles the generation-side root cause). ## Why Agent-generated ".docx" artifacts were historically plain-text bytes; the docx preview fed them straight to mammoth/JSZip which threw `Can't find end of central directory` (reproduced verbatim with JSZip.loadAsync on text bytes). ## Changes - @ui `previewKindOf`: `.docx` stays docx; legacy `.doc` (binary Word, not OOXML) routes to binary + download fallback instead of a guaranteed JSZip explosion. - @ui `OfficePreview`: user-facing error converges to one actionable line (corrupted / not a valid DOCX / pseudo-Office file); raw error goes to console. - frontend `docxLoader`: sniff ZIP magic (PK\x03\x04 / PK\x05\x06) before mammoth; non-ZIP bytes render as markdown with a readable note — stock fake docx artifacts become readable immediately. - parent: `.gitignore` gains `.mimosa/` (Mimosa plugin per-session state kept dirtying the tree and blocking precheck). ## Verification - make test-ui: tsc --noEmit clean + vitest 49/49 (new: `旧文档.doc → binary`, error-note assertion) - make test-frontend: vitest 33/33; frontend tsc --noEmit clean - task-sync checkpoint: sync_base=d64742c71c tested_head=af13fba (2026-09-30T17:51:59Z) ## Impact Preview-layer only, no contract change. Until the generation-side track merges, newly written .docx remains text but previews readably. Refs: .task/feature-preview-sniff-fallback.md; merge order: Agent-System-UI / Agent-System-Frontend PRs first, then this parent PR (pins those heads).
weichen added 1 commit 2026-09-30 17:52:46 +00:00
Why: agent-generated ".docx" artifacts were historically plain text bytes
written via string-only write tools; the docx preview loader fed them
straight to mammoth/JSZip, which threw "Can't find end of central directory"
on the meeting-notes docx from the review session.

Evidence: docxLoader now checks the PK\x03\x04 (or empty-archive PK\x05\x06)
magic before mammoth; non-ZIP bytes render as markdown with a readable note
instead of an error. vitest 33/33 pass, tsc --noEmit clean.

Impact: stock fake-docx artifacts become readable immediately; real docx
previews unchanged. Rendering only, no API/contract change.

Refs: .task/feature-preview-sniff-fallback.md
weichen added 2 commits 2026-10-01 04:07:07 +00:00
Why: docx preview already sniffs ZIP magic so a text file renamed to
.docx stays readable. xlsx and pptx loaders still fed those bytes to
the parser and surfaced a raw library error.

Evidence: npx tsc --noEmit and npx vitest run (40 tests) on this branch
after merging origin/main. Legacy .xls/.ppt skip the sniff because they
are not OOXML.

Impact: pseudo xlsx/pptx render as text with a short note. Real ZIP
workbooks and decks still use the existing parsers.

Refs: Dev PR #96, task feature/preview-sniff-fallback
Co-authored-by: Cursor <cursoragent@cursor.com>
weichen merged commit 53d38c8ccb into main 2026-10-01 05:20:16 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weichen/Agent-System-Frontend#22