A local-first multi-agent app development platform, built on PenguinHarness
Word and PDF files preview in the Files panel
- Date: 2026-10-28
- Type: feat
- Scope:
web,server,docs - Breaking: no
Selecting a .docx in the Files panel used to answer "Preview not supported for this type; download
instead" — a Word file is the one kind of document people hand an Agent most often, and the panel had
nothing to say about it. It now opens: the document's headings, paragraphs, bold and italic runs, lists
and tables, laid out as read-only text in the pane. The extraction runs on the server (a .docx is a zip
of XML, and reading it needs no office suite installed) and comes back as Markdown, so the panel renders
it through the Markdown pipeline it already trusts. A Word preview is a preview: no editor, no source
view, because what is on screen is not the file. A legacy .doc says to save it as .docx; a .docx
that cannot be read says so instead of rendering as garbage.
PDFs stop depending on the client. The pane used to hand the file to the browser's own PDF viewer in an iframe, which worked on a desktop Chrome and left a blank rectangle wherever that viewer is missing or set to download instead — a blank pane that reads exactly like a broken file. The panel now paints the pages itself, one canvas per page as it scrolls into view, so a PDF looks the same in the desktop app, in any browser, and on a machine with no PDF plugin at all.
Details
packages/server/src/services/docx-preview.ts(new):docxToMarkdown— inflates onlyword/document.xml(its declared size capped before inflation), then walks the body's tags into Markdown: headings fromw:pStyle/w:outlineLvl(the outline level wins, as Word's own navigation pane has it), list items indented byw:ilvl,**bold**/*italic*runs, GFM tables whose first row is the header,w:tab/w:bras spaces, and the XML entities decoded. Every character Markdown would read as syntax is escaped, and only the tail of a block is trimmed so a nested item keeps its indent. The output is capped at 200,000 characters withtruncated; a zip without the document part, or bytes that are not a zip at all, is aDocxPreviewError.packages/server/src/http/routes/workspace-files.ts:GET <base>/preview-text?path=…serves that Markdown with the read's version asETag,no-store,nosniffandX-Content-Truncatedwhen the extraction was cut. A.docis 415doc_legacy, any other type 415preview_unavailable— this route serves a derived document, never the file's own bytes. Registered in both scopes, so the new-chat draft and a sidebar Workspace group get it too.packages/server/src/app.ts:.mjsjoins the static content types. The web build now emits one ES module worker (pdf.js's), and a browser refuses a module script served asapplication/octet-stream.packages/web/src/features/chat/pdf-preview.tsx(new):PdfPreviewfetches the bytes with the session's credentials, loads pdf.js lazily (its worker as its own asset, so parsing is off the main thread), and paints each page at the pane's width — redrawn on resize rather than stretched, at most 2× device pixel ratio and a 16MP canvas ceiling, with a placeholder holding each page's height until it renders. The loading task is what gets destroyed on unmount, not the document proxy (which has nodestroyin this version).packages/web/src/lib/workspace-tree.ts:previewKindForgainsdocfor.docx/.doc;previewKindOf(the read-only UIFileBrowser, which does no extraction fetch) names it unsupported.packages/web/src/features/chat/workspace-browser.tsx: thedocbranch fetchespreview-textand presents a read-only Markdown view, with its own message for a legacy.docand for a.docxthe server could not read; thepdfbranch drawsPdfPreviewinstead of an iframe.fetchTextPreviewalso honours the server'sX-Content-Truncated.packages/web/src/api/{endpoints,workspace-files}.ts:workspaceFileTextUrl/workspaceDirFileTextUrl, andtextUrlonFilesApifor both scopes (with the machine routing the other file URLs already carry).- Strings:
previewDocLegacy,previewDocxFailed,pdfLoading,pdfFailed. - Docs:
packages/docs/content/files.{zh,en}.md— the preview table gains the two types, plus what each keeps and drops, the read-only rule, and the legacy.docanswer. The context-menu note no longer claims PDFs, which are ordinary DOM now. packages/web/package.json:pdfjs-dist@^6.4.299(Apache-2.0, code-split into its own chunk; perTHIRD-PARTY-NOTICES.mda bundled npm package needs no entry there).
Compatibility
preview-textis a new route; nothing existing changed shape.- A
.docxcan no longer be mistaken for a text file: it has its own preview kind now. - PDF previews no longer need the browser's PDF viewer, so no configuration on the client side.