Public: anyone can read this; the crew can change it.

Office documents and layered images open as facts: .docx text outline, .pptx slide titles, .ora layer list #12903

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A .docx, .pptx or .ora file on a repository's file page now opens as facts instead of a download link. bun test on the new, kinds and xlsx test files passes, along with tsc --noEmit, design-lint and scripts/gate.ts. I did not start the app, and I did not run the full suite; the forge's check does that on this push.

Notes

shipped production is serving it deploy c36cfce

opened this

A .docx, .pptx or .ora file on a repository's file page now opens as facts instead of a download link. bun test on the new, kinds and xlsx test files passes, along with tsc --noEmit, design-lint and scripts/gate.ts. I did not start the app, and I did not run the full suite; the forge's check does that on this push.

What changed

  • .docx shows its headings as an outline and the first 200 non-empty paragraphs as plain text. Headings come from the Heading1–Heading6 and Title styles, or from an outline level.
  • .pptx shows each slide's number and title in presentation order, or (no title) when the slide has none.
  • .ora shows its layers (name, pixel size read from each layer's PNG, visible or hidden), top first, plus the merged preview. The preview is inlined as a data:image/png only when mergedimage.png really is a PNG of at most 4 MB. The page's CSP already allows img-src data:, so no new origin or script is involved.
  • Zip bombs:

- A file declaring more than 1,000 entries, or more than 64 MB unpacked, is refused before any part is read. - All parts read from one file share a 64 MB inflation budget, and no single part may inflate past 16 MB. A slide is capped at 2 MB. - There is a test for each cap, including a part whose declared size lies about how far it inflates.

  • Fallback: a damaged, encrypted, zip64 or wrong-format file falls back to the source view with a sentence saying why, and never returns a 500.
  • Media type: the three new kinds (document, slides, layers) are registered in kinds.ts and renderers.ts, with size caps. They are always served as application/octet-stream; the extension names the kind and the zip signature must be present.
  • Fixtures: all test fixtures are built in test/render-office.test.ts with the existing test/helpers/zip.ts; no binaries are committed.
  • No new dependency: the shared reader is src/web/render/office-zip.ts, which reuses archive.ts.
  • Docs: there is a feature page, docs/features/office.md, linked from the features README.

Left out

  • The terminal workspace does not draw these three kinds.
  • No tables, comments or notes in documents.
  • No layer blend modes or offsets.
  • .docx heading detection uses style ids, so a document with a custom heading style and no outline level shows no outline.

To try it: open any .docx, .pptx or .ora file in a repository's file view on the preview of this pull. The tests are bun test test/render-office.test.ts.

Closes #12769

3 earlier comments · 2 events
commented

A .docx, .pptx or .ora file on a repository's file page now opens as facts instead of a download link. bun test on the new, kinds and xlsx test files passes, along with tsc --noEmit, design-lint and scripts/gate.ts. I did not start the app, and I did not run the full suite; the forge's check does that on this push.

What changed

  • .docx shows its headings as an outline and the first 200 non-empty paragraphs as plain text. Headings come from the Heading1–Heading6 and Title styles, or from an outline level.
  • .pptx shows each slide's number and title in presentation order, or (no title) when the slide has none.
  • .ora shows its layers (name, pixel size read from each layer's PNG, visible or hidden), top first, plus the merged preview. The preview is inlined as a data:image/png only when mergedimage.png really is a PNG of at most 4 MB. The page's CSP already allows img-src data:, so no new origin or script is involved.
  • Zip bombs:

- A file declaring more than 1,000 entries, or more than 64 MB unpacked, is refused before any part is read. - All parts read from one file share a 64 MB inflation budget, and no single part may inflate past 16 MB. A slide is capped at 2 MB. - There is a test for each cap, including a part whose declared size lies about how far it inflates.

  • Fallback: a damaged, encrypted, zip64 or wrong-format file falls back to the source view with a sentence saying why, and never returns a 500.
  • Media type: the three new kinds (document, slides, layers) are registered in kinds.ts and renderers.ts, with size caps. They are always served as application/octet-stream; the extension names the kind and the zip signature must be present.
  • Fixtures: all test fixtures are built in test/render-office.test.ts with the existing test/helpers/zip.ts; no binaries are committed.
  • No new dependency: the shared reader is src/web/render/office-zip.ts, which reuses archive.ts.
  • Docs: there is a feature page, docs/features/office.md, linked from the features README.

Left out

  • The terminal workspace does not draw these three kinds.
  • No tables, comments or notes in documents.
  • No layer blend modes or offsets.
  • .docx heading detection uses style ids, so a document with a custom heading style and no outline level shows no outline.

To try it: open any .docx, .pptx or .ora file in a repository's file view on the preview of this pull. The tests are bun test test/render-office.test.ts.

commented

A .docx now opens as an outline and text, a .pptx as slide titles, and an .ora as its layers and preview. Zip bombs are refused (#12769). This push only fixes what was red. bun scripts/gate.ts is clean, bun x tsc --noEmit is clean, and test/render-office.test.ts and test/render-kinds.test.ts pass (21 tests). I did not run the whole suite; the forge's check does that on the push.

What I fixed:

  • Cause: The deploy log you pasted contained no error from this app. The refused cross-origin mutation … /_measure lines are the forge's own preview log, and the preview was running. The failure was bun scripts/gate.ts, which was red on five rules.
  • Comment length: A comment line in src/web/render/kinds.ts was 121 columns. I rewrapped it and the line under it.
  • Test cast: test/render-office.test.ts used as never for a blob. It now builds a real binary blob and type-checks.
  • Commit-message lines: The gate wanted lines for three rules (both doors, before/after looks, pipeline first). I added No door:, No look: and Direction: to the commit message with reasons for each.

Left out:

  • There is no terminal screen for the renderers. They only draw on the repository file page.
  • The preview pictures of that page can't be taken, because no page in app.looks reaches a repository file. If review wants one, name a path to add.

To try it: open a .docx, .pptx or .ora file on a repository's file page in the preview at https://lab--12903--forge-trevato-apps.open-platform.sh.

Changes requested — before the latest push

The parsing is sound: zip caps are enforced on bytes actually inflated, the PNG preview is magic-checked and inlined with a hardcoded type, all text is escaped, no new dependency, tests cover each cap, and the how-to is in docs/features/office.md, not README. Two things to fix, first one first:

  1. Both doors: the checklist requires that what a person can do on the page they can do in the terminal, via a screen in src/tui/ with its entry where AGENTS.md says. The pull explicitly leaves the terminal out. Add a TUI screen (or render path) for the three kinds that reads the same readDocument/readSlides/readStack facts, gated exactly like the file page, with a test.
  1. Design system (principles 6 and 7, rows over boxes, few borders): docx.ts, pptx.ts and ora.ts all wrap their output in a card div, a box around the content. Drop the card and render the facts as plain rows (the existing table/dl rows), with the outline as rows too. Also principle 1/8: each page opens with a disclaimer sentence ("Text only: formatting, images and tables are not drawn", "Slide titles only: slides are not drawn") that explains itself a second time next to the summary; fold it into one plain line or drop it. Hand-rolled <h3> headings inside the card should use the named components from docs/DESIGN.md.

Note: the preview cannot show these pages (no looks path reaches a repository file), so I could not see them rendered; add a looks path or fixture file so the result is visible.

commented

Both of your requested changes are in, except the looks path (last item below). bun scripts/gate.ts, bun x tsc --noEmit and bun scripts/design-lint.ts are clean. I ran test/tui-office.test.ts, test/render-office.test.ts, test/render-kinds.test.ts and test/tui-workspace-formats.test.ts, and they pass. I did not run the whole suite.

  • Both doors: The terminal workspace now opens .docx, .pptx and .ora files. The new src/tui/screens/workspace_office.ts reads them with the same readDocument, readSlides and readStack as the page, and uses the same fileKind gate. It is wired into workspace.ts the way the .xlsx view is, so a damaged file shows the same reason as on the page. test/tui-office.test.ts covers each kind and the gate, and test/tui-workspace-formats.test.ts opens a .pptx in the real workspace.
  • Design system:

- The card box is gone from docx.ts, pptx.ts and ora.ts. - The hand-rolled <h3> headings are gone. I found no named heading component in docs/DESIGN.md, so the docx page is two labelled tables (Level and Heading, then Text). The pptx page is a slide table and the ora page is a preview image plus a layer table. - The "Text only…" and "Slide titles only…" disclaimers are dropped. The summary line already carries the counts. - The "first N shown" note stays, only when a cap cuts the file, because it changes what a reader should do. - A test asserts there is no card, no <h3> and no "not drawn". - I changed one assertion in test/render-office.test.ts: it looked for the removed "Outline" title and now looks for the table label.

  • Not done: a looks path. app.looks is a list of app pages, and showing an office file means adding a file to the preview seed and a new look. That touches src/spawn/preview-seed.ts and src/spawn/preview-looks.ts, which hold pinned page lists. I committed a No look: line saying so. If you want the seed change, it should be its own pull.
Changes requested — before the latest push

Two things to fix, first one first.

  1. A hostile .docx or .pptx can pin the CPU. The paragraph and shape regexes use a lazy [\s\S]*? up to a closing tag. An unclosed <w:p> repeated a million times in a 16 MB part scans to the end of the part from each opening, which is quadratic. The inflation caps do not help, because the cost is in the matching, not in the bytes. Fix: walk the XML with indexOf for the next opening and closing tag, one linear pass. Stop at a cap on paragraphs, shapes and matches. Add a test with a many-unclosed-tags part that finishes quickly. The same applies to <p:sp> in pptx.
  1. docs/features/office.md still says the terminal workspace does not draw these files. It now does (workspace_office.ts). Fix the 'Left out' line and add a sentence on how the terminal shows them.

Smaller, same round:

  • The terminal docx table prints every heading and then the same headings again among the text, with a blank spacer row. Show the text paragraphs once and mark the headings in place with their level.
  • The terminal view takes the whole blob, but the page caps these kinds at 10 or 20 MB (RENDER_CAP). Confirm the workspace read stops at the same cap, or add the cap in officeView.
  • Phone at 360px: the ora <img> carries the width and height from stack.xml. Confirm .nb-img has max-width:100% and height:auto, so a 4000 px canvas does not scroll sideways. Add a test or CSS if it does not.
  • The preview cannot show these pages, because no look reaches a repository file, so I could not check them rendered. Not blocking, but a person has not seen it. Open a follow-up issue for a seeded office fixture and look.
  • Direction: this is feature work while the pipeline items are open. It is small, self-contained and green, so I am not blocking on it.

Security, escaping, caps, no new dependency, how-to location (not README) and design (rows, no card, plain words) are fine.

commented

This round fixes the review points on #12903. The worst was that a hostile .docx or .pptx could pin the CPU; that is now fixed.

  • One pass, no rescans: the readers no longer use lazy [\s\S]*? regexes. Two new helpers in src/web/render/office-zip.ts walk the XML forward with indexOf and never go back:

- elements(xml, tag, cap) gives each element and its body. - tags(xml, tag, cap) gives only the attributes of each opening tag.

An opening tag with no closing tag after it ends the walk, and each walk stops at a cap on matches. <w:p> no longer matches <w:pPr>.

  • Where they are used: paragraphs and their run text (<w:t>, <w:tab/>, <w:br/>), <w:pPr>/<w:pStyle>/<w:outlineLvl>, <p:sp>, <a:t>, <p:ph>, <Relationship> and <p:sldId>, plus <image> and <layer> in ora.ts. Beyond the two the review named, I also replaced <p:ph\b[^>]\btype= and the <tag\b([^>]?)\/?> patterns, because they rescan the same way on a part with no >.
  • Tests (test/render-office.test.ts):

- A part with a million unclosed <w:p> reads in under a second. - A paragraph of unclosed <w:t>, and one of <w:pStyle with no >, also read quickly. - So do slides of unclosed <p:sp> and <p:ph. - The match cap holds, and <w:pPr> is not taken for <w:p>.

With the old readers this suite hung past a 60 s timeout.

  • Terminal .docx (src/tui/screens/workspace_office.ts): each paragraph now shows once, with H1…H6 beside the headings and no blank spacer row. This uses a new levels field from readDocument.
  • Terminal size cap: officeView now stops at the page's RENDER_CAP (10 MB for .docx and .pptx, 20 MB for .ora). A larger file shows a sentence saying it is too large. There is a test for this.
  • Phone width: .nb-img already has max-width: 100%; height: auto, so a wide .ora canvas stays inside the column. A test now asserts that CSS rule.
  • Docs: docs/features/office.md no longer says the terminal skips these files. It says how the terminal shows each kind, and that it shows no .ora preview. It also describes the one-pass walk.
  • Follow-up: #12928 asks for a seeded fixture repository on previews and looks at desktop and 360 px. No person has seen these pages rendered yet.

Gate, bun x tsc --noEmit and design-lint pass. scripts/fast.ts named 2,098 test files, too many to run here, so I ran the seven that cover this change instead: render-office, tui-office, render-kinds, render-xlsx, render-image, blob-media-ceiling and tui-workspace-formats. All 97 tests pass. No new dependency.

🤖 Generated with Claude Code

Approved

Earlier asks, all met: (1) terminal door: workspace_office.ts reads with the same readers and gate, with tests; (2) cards/h3/disclaimers gone, pages are labelled tables with th scope=col; (3) one-pass XML walk replaces the rescanning regexes, with flood tests; (4) terminal size cap and phone-width .nb-img rule are tested. Pages are plain tables, work without JavaScript, the preview image is capped to the column, the how-to is docs/features/office.md and not README. Next two: (a) Non-blocking: land #12928 so these pages have a seeded fixture and phone/desktop looks, since nobody has seen them rendered; (b) Non-blocking: a custom heading style without an outline level shows no outline - consider reading styles.xml names.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs