Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

Docs: pre-launch review — accuracy pass, format spec, changelog, security policy

nyblnet821adb15d399
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 00000000..9257aa42
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,27 @@
+---
+name: Bug report
+about: Something in the app or a .bento.html file isn't working
+title: ''
+labels: bug
+---
+
+**What happened**
+A clear description of the bug and what you expected instead.
+
+**Steps to reproduce**
+1. …
+2. …
+
+**A minimal repro**
+If you can, attach a small `.bento.html` that reproduces it (drag it onto the
+issue). Please strip anything private first — the document carries your content.
+
+**Environment**
+- App version (About dialog, or the shell's `APP_VERSION`):
+- Browser + version:
+- OS:
+
+**Notes**
+Console errors, screenshots, or anything else that helps.
+
+<!-- Security issue? Do NOT file it here — see SECURITY.md for private reporting. -->
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 00000000..5953fd87
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,5 @@
+blank_issues_enabled: true
+contact_links:
+ - name: Security vulnerability
+ url: https://github.com/nyblnet/bento/blob/main/SECURITY.md
+ about: Please report security issues privately — do not open a public issue.
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
new file mode 100644
index 00000000..b57925ae
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,17 @@
+---
+name: Feature request
+about: Suggest an idea for Bento
+title: ''
+labels: enhancement
+---
+
+**The problem / use case**
+What are you trying to do that's hard or impossible today?
+
+**What you'd like**
+Describe the feature or change.
+
+**Keep in mind**
+Bento is a single self-contained file with a ~400 KB runtime budget and a
+stable, additive document format. Ideas that respect those constraints (or
+explain the trade-off) are easiest to move on.
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 00000000..e05b2c89
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,16 @@
+<!-- Thanks for contributing! Keep PRs focused — one concern each. -->
+
+**What & why**
+What does this change, and what problem does it solve?
+
+**How I verified it**
+<!-- e.g. ran `npm run build:single`; for CRDT changes ran `node scripts/test-sync.ts`;
+ real-mouse QA for canvas/Moveable changes -->
+
+**Checklist**
+- [ ] Read the relevant parts of CLAUDE.md / docs before changing them
+- [ ] `npm run build:single` succeeds (from `slides/`)
+- [ ] Ran `node scripts/test-sync.ts` if I touched `slides/src/sync/`
+- [ ] New UI strings added to every catalog in `slides/src/i18n/`
+- [ ] Document format changes are additive and backward-compatible
+- [ ] Did not bump the version or cut a release (maintainers sign releases)
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 00000000..46ff015c
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,126 @@
+# Changelog
+
+All notable changes to **Bento Slides**. The app version is baked into every
+shell as `APP_VERSION` (from `slides/package.json`) and shown in the About
+dialog; a shipped file updates itself through the signed release channel.
+
+The format (`bento/slides`, version `1`) is additive and stable — every version
+below opens files from every earlier version, and unknown fields are preserved.
+This project's versions roughly follow semantic-ish `0.MINOR.PATCH` while it is
+pre-1.0.
+
+## [0.9.20] — 2026-07
+
+- Audio: render the native control as-is; add an "insert media from a link"
+ entry point.
+
+## [0.9.19]
+
+- Fix audio-player shape (don't wrap the native control in a box).
+
+## [0.9.18]
+
+- **Signed writes / enforced read-only tiers.** Rooms carry an ECDSA P-256
+ writer keypair (public half in every copy, private half in writer copies
+ only); the room id commits to the pubkey and the blind relay drops mutating
+ frames without a valid signature. A read-only copy is a writer copy with the
+ private key stripped — enforced at the edge, not by client courtesy. Three
+ file modes now: presentation package, read-only live viewer, and writer.
+ (Full design + threat model in `docs/collab-design.md`.)
+
+## [0.9.15 – 0.9.17]
+
+- Directional slide-in entrances (`slide-left/right/up/down`, x-channel).
+- Second-screen speaker permission moved out of present into the editor's Slide
+ panel; Presenter display folded into the Speaker-notes section.
+- i18n: the new UI strings translated across all locale catalogs.
+
+## [0.9.10 – 0.9.14]
+
+- **Dynamic field tags** — `{{page}}`, `{{pages}}`, `{{title}}`, `{{date}}`,
+ `{{time}}`, resolved at render time (page numbering re-flows as slides move).
+- **Dual-screen speaker view**: notes open directly on a second display, via a
+ one-click permission grant that sidesteps the activation deadlock.
+- Dual-axis linked chart in the starter deck; scatter state; topbar regroup.
+
+## [0.9.8 – 0.9.9]
+
+- **Auto-save + local version history** (IndexedDB): a crash-recovery snapshot
+ plus a capped version timeline; restore from the About dialog (undoable).
+ Encrypted decks are never snapshotted to disk.
+- **Live table→chart binding**: a chart can track a table (`chart.source`);
+ edit the table's numbers and the chart follows.
+- **System-clipboard copy/paste**: elements or whole slides, across decks and
+ tabs; external images and text paste in. A `?` help overlay and richer
+ tooltips.
+
+## [0.9.6 – 0.9.7]
+
+- **Dual y-axis charts** and a **visual chart editor** (structured UI over the
+ option: type, series, per-axis min/max, an editable data grid).
+- Variable-speed motion-path loops (per-lap easing + per-anchor speeds).
+- Fixes for live collaboration and speaker-view while presenting in fullscreen;
+ a "Live" status dot.
+
+## [0.9.3 – 0.9.5]
+
+- **First-class `table` element** — a real HTML table with inline cell editing,
+ style presets, and a table→chart bridge.
+- New charts inherit the deck's palette (`theme.chartPalette`, or derived from
+ the accent); table→chart charts every numeric column.
+
+## [0.9.0 – 0.9.2]
+
+- **File modes**: read-only **player** files (boot straight into the show) and
+ **password encryption** (`bento/enc` envelope, PBKDF2 + AES-GCM; the block
+ stays spliceable).
+- Live-by-default decks, gated so the anonymous demo never phones home.
+- **AI-native**: an embedded agent briefing + cookbook, the `bento-deck` skill,
+ and `window.bento.loadDoc` round-trip.
+
+## [0.8.0 – 0.8.11]
+
+- **Live collaboration (bento-sync)** — an in-house op-based CRDT with
+ same-machine sync (BroadcastChannel) and an optional end-to-end-encrypted
+ blind relay (Cloudflare Durable Object). Offline forks merge two-way. The
+ saved file stays a complete standalone document.
+- Offline mode, distributable templates, the Collaborate/Live UI, the Save
+ menu, and identity (display name).
+- Fullscreen presenting, responsive topbar, drag modifiers (duplicate,
+ center-resize), swipe navigation, per-deck page sizes, and a mobile pass.
+
+## [0.7.0 – 0.7.1]
+
+- **charts-lite** — the in-house, dependency-free chart engine (bar/line/pie/
+ scatter). ECharts/zrender removed (it was ~47% of the shell).
+- **Compressed self-extracting shell**: runtime JS+CSS deflated into base64
+ blocks with a ~1 KB loader; the `#bento-doc` block stays plaintext. Shell
+ dropped from ~1.33 MB to ~373 KB.
+- **AI round-trip**: copy/replace document JSON; the shell points agents at the
+ document block and API.
+
+## [0.6.0 – 0.6.2]
+
+- **Internationalization** — the viewer follows its own locale; catalogs for
+ Japanese, Simplified & Traditional Chinese, Spanish, French, German, Italian.
+ Language never enters the document format.
+
+## [0.5.0 – 0.5.5]
+
+- **Signed self-updates**: launch-time (opt-out) and on-demand update checks,
+ with a visible topbar affordance; ECDSA-signed manifest verified in-app.
+- Identity/branding pass (Bento/Slides lockup, splash, About).
+
+## [0.1.0 – 0.4.2]
+
+- The showcase **starter deck** that doubles as the feature tour (id-continuity
+ morph demo, chart data morph, speaker-notes tour).
+- In-place **self-update** (rewrite the open file into a new version).
+- The core editor, present mode, morph engine, the typography panel, shadows,
+ and the midnight-and-peach identity.
+
+---
+
+*This changelog was distilled from the git history for the public launch. Tags
+`v0.9.15`+ carry signed releases; earlier entries summarize the pre-tag commit
+line. See [docs/RELEASING.md](docs/RELEASING.md) for how a release is cut.*
diff --git a/CLAUDE.md b/CLAUDE.md
index f68a73f4..70ae960a 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -133,7 +133,8 @@ One HTML file = the document + viewer + editor. See `README.md` for the vision.
Scripting: `window.bento.updates.{version,check,build,apply}`.
- `src/i18n.ts` + `src/i18n/*.ts` — internationalization: ~1KB t() with
ENGLISH-STRING-AS-KEY (gettext style; missing key = English fallback),
- {placeholder} interpolation, catalogs compiled in (ja, zh-Hans, es, fr, de);
+ {placeholder} interpolation, catalogs compiled in (ja, zh-Hans, zh-Hant, es,
+ fr, de, it — 7 locales + English fallback = 8 UI languages);
locale follows the VIEWER (navigator.language; localStorage 'bento-lang'
override; picker in About rebuilds the workspace). Language never enters the
document format. select() localizes DISPLAY labels only (values stay model
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 00000000..4ce93572
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,112 @@
+# Contributing to Bento
+
+Thanks for being here. Bento is "the office suite that fits in a file" — a
+single self-contained HTML document that is also its own viewer, presenter, and
+editor. Contributions of all sizes are welcome: bug reports, docs fixes,
+templates, and code.
+
+## Getting set up
+
+You need **Node 20+** and npm (the build uses Vite 7). There is no backend to
+run and no account to create — the whole app builds to one HTML file.
+
+```bash
+git clone https://github.com/nyblnet/bento.git
+cd bento/slides
+npm install
+npm run dev # dev server at http://localhost:5199
+```
+
+The current app lives in `slides/`. Common commands (run from `slides/`):
+
+| Command | What it does |
+|---|---|
+| `npm run dev` | Vite dev server with hot reload. |
+| `npm run build:single` | Produces the shippable `dist-single/Bento_Slides.bento.html` — one file with the runtime, editor, and an empty document block. |
+| `node scripts/test-sync.ts` | The CRDT convergence rig. Run it after **any** change to `slides/src/sync/crdt.ts`; it has caught many ordering bugs. `SEEDS`, `STEPS`, and `ACTORS` env vars tune the fuzzing. |
+
+## Where things live
+
+- `slides/src/model.ts` — the `bento/slides` JSON document model. **This is the
+ format.**
+- `slides/src/render.ts` — the single model→DOM renderer shared by the editor
+ canvas, thumbnails, present mode, and print.
+- `slides/src/editor/` — the vanilla-TypeScript editor (Moveable + Selecto).
+- `slides/src/sync/` — the in-house CRDT and the E2EE relay transport.
+- `server/sync-worker/` — the blind Cloudflare Worker relay (ciphertext only).
+- `scripts/` — build, release, and gallery tooling.
+- `docs/` — architecture, the `bento/slides` [format spec](docs/format.md),
+ collaboration design, the AI agent guide, and releasing (index in
+ [docs/README.md](docs/README.md)).
+
+Two documents are the source of truth for how the codebase fits together, and
+they go deep — **read them before a non-trivial change**:
+
+- [CLAUDE.md](CLAUDE.md) — the architecture + development guide, module by
+ module, with the hard-won gotchas that must not regress.
+- [docs/architecture.md](docs/architecture.md) — the on-disk file format, the
+ self-save loop, and the runtime layout.
+
+## Coding conventions
+
+- **Vanilla TypeScript, no framework.** The editor is hand-written DOM. Match
+ the surrounding style rather than introducing new patterns or dependencies.
+- **Earn every dependency.** Bento replaced GSAP, ECharts, and Yjs with small
+ in-house engines shaped to its needs, because the whole runtime has to fit in
+ a ~400 KB shell that travels inside every document. New runtime dependencies
+ are a hard sell — bring numbers.
+- **The format is additive and stable.** `bento/slides` JSON is the interchange
+ contract: old files must open in newer shells, and unknown fields are
+ preserved through parse → serialize. Add optional fields; never repurpose or
+ remove one. Element `id`s are identity (morphs, states, and links all key off
+ them) — keep them stable and deterministic.
+- **Keep the document pure data.** Text HTML is sanitized and chart options are
+ pure JSON (no functions) so a document can never smuggle executable code
+ through the model. Don't add a path for code to ride in the format.
+
+## The single-file build & the splice contract
+
+`npm run build:single` inlines and compresses all JS + CSS into one HTML shell.
+The document lives in a **plaintext** `<script id="bento-doc">` block near the
+top of the file, and everything downstream depends on that block staying
+spliceable:
+
+- The block JSON escapes every `<` as `<`, so a literal `</script>` can
+ never terminate it.
+- The runtime source never contains a literal script-close tag (the one place
+ that needs it builds it by string concatenation).
+- On save, the app clones the pristine shell captured at boot, swaps the data
+ block, and rewrites the file — so an old file always opens with its own pinned
+ runtime, and outside tooling (and AI agents) can always find and edit the JSON.
+
+If you touch the boot, save, or build path, keep these invariants intact — the
+release process gates on them. The details are in
+[docs/architecture.md](docs/architecture.md).
+
+## Pull requests
+
+- Branch off `main` and keep PRs focused — one concern per PR is easier to
+ review than a grab-bag.
+- Describe **what** changed and **why**, and how you verified it. For anything
+ touching the editor canvas, note that synthetic pointer events don't drive
+ Moveable/Selecto — real-mouse QA is expected (see the testing notes in
+ CLAUDE.md).
+- Run `npm run build:single` and, for CRDT changes, `node scripts/test-sync.ts`
+ before opening the PR.
+- New user-facing UI strings must be added to **all** locale catalogs under
+ `slides/src/i18n/` (English is the key; missing keys fall back to English).
+- Please don't bump the version or cut releases in a PR — releases are signed
+ and cut locally by a maintainer (see [docs/RELEASING.md](docs/RELEASING.md)).
+
+## Reporting bugs & ideas
+
+Open a GitHub issue. For bugs, include your browser and OS, what you expected,
+what happened, and — when you can — a minimal `.bento.html` that reproduces it.
+
+Security issues are different: please **do not** open a public issue. Follow
+[SECURITY.md](SECURITY.md) instead.
+
+## License
+
+By contributing, you agree that your contributions are licensed under the
+project's [MIT License](LICENSE).
diff --git a/README.md b/README.md
index e301566b..7aa3cd05 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,12 @@ nothing: the file *is* the software.
feature tour. Or grab a designed template from the
[gallery](https://bento.page/) and make it yours.
+**Download the app:** grab the single `Bento_Slides.bento.html` from the
+[GitHub Releases](https://github.com/nyblnet/bento/releases) page or straight
+from [bento.page](https://bento.page/releases/slides/Bento_Slides.bento.html)
+(~470 KB, no account, no installer). Open it in any modern browser and it *is*
+the editor. Save, and it rewrites itself with your deck inside.
+
## Why this exists
Office documents used to be things you *had*. Now they're things you rent —
@@ -37,6 +43,24 @@ company keeps its servers on. Bento takes the other path:
| **Signed self-updates** | Releases are ECDSA-signed and offered in-app. Updating writes a *new* file — the old one stays as your rollback. No server ever touches your documents. |
| **Everything else** | Speaker view, comments, layouts, hidden interactive states, hover reveals, motion paths, PDF export, page sizes, 8 UI languages — in a ~400 KB shell. |
+## Use it with AI
+
+Because the document is plain JSON living in one plaintext block near the top
+of the file, any assistant that can read and write a file can edit your deck —
+no plugin, no API. Two ways in:
+
+- **File harnesses** edit the `#bento-doc` JSON in place:
+ [Claude Code](https://claude.com/claude-code), Cursor, Aider, or any agent
+ with filesystem access. Claude Code users get a packaged `bento-deck` skill.
+- **Chat round-trip** for any chatbot: copy the document JSON out (*About →
+ Copy document JSON*), let the assistant rewrite it, paste it back.
+
+**It works fully offline with local open-weight models** — point
+[Ollama](https://ollama.com), llama.cpp, or LM Studio at the deck and nothing
+leaves your machine. The agent guide is a single page you can drop into any
+model's context: [bento.page/agents.md](https://bento.page/agents.md) (also in
+this repo at [docs/agents.md](docs/agents.md)).
+
## Architecture in one paragraph
`slides/src/model.ts` defines the JSON document model; one renderer
@@ -63,12 +87,15 @@ deep dive: [docs/architecture.md](docs/architecture.md).
a collaborator's concurrent edit to the same property; editing is
desktop-first (phones view and present well).
-## Building
+## Build from source
+
+Node 20+ and npm are all you need — the app is a single-page build with no
+backend to stand up.
```bash
cd slides
npm install
-npm run dev # dev server
+npm run dev # dev server (http://localhost:5199)
npm run build:single # → dist-single/Bento_Slides.bento.html (the product)
```
@@ -76,11 +103,32 @@ npm run build:single # → dist-single/Bento_Slides.bento.html (the product)
locally so the signing key never leaves the maintainer's machine — see
[docs/RELEASING.md](docs/RELEASING.md).
-## Status
-
-**Bento/Slides** is the first app of Bento/Suite — Docs and Sheets are
-coming. The current release lives on [bento.page](https://bento.page) and
-reaches every existing file through the signed update channel.
+## Where to read more
+
+- [CLAUDE.md](CLAUDE.md) — the deep architecture + development guide (also what
+ AI agents read to work in this repo).
+- [docs/architecture.md](docs/architecture.md) — how a `.bento.html` file is
+ built, the on-disk format, and the runtime layout.
+- [docs/format.md](docs/format.md) — the normative `bento/slides` document-model
+ spec (every element type, slide/state/layout shape, and collab fields).
+- [docs/collab-design.md](docs/collab-design.md) — the CRDT, E2EE relay, and
+ signed-write RBAC design + threat model.
+- [docs/agents.md](docs/agents.md) — the document format, for AI agents.
+- [CHANGELOG.md](CHANGELOG.md) — the version history.
+- **Layout:** `slides/` is the app (source in `slides/src/`);
+ `server/sync-worker/` is the blind relay; `docs/` and `scripts/` are the
+ guides and build tooling.
+
+Contributions welcome — start with [CONTRIBUTING.md](CONTRIBUTING.md). Found a
+security issue? See [SECURITY.md](SECURITY.md).
+
+## Roadmap
+
+**Bento/Slides** is the first app of Bento/Suite — a PowerPoint alternative,
+shipping now. **Docs** (`bento/docs`) and **Sheets** (`bento/sheets`) follow,
+each as its own self-contained `.bento.html` distributable. The current release
+lives on [bento.page](https://bento.page) and reaches every existing file
+through the signed update channel.
## License
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 00000000..4f5e3e2f
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,97 @@
+# Security Policy
+
+Bento takes security seriously — the whole project is built around a
+local-first, keys-never-leave-your-file model. This document explains how to
+report a vulnerability and summarizes the security posture so reports can be
+precise.
+
+## Reporting a vulnerability
+
+**Please do not open a public GitHub issue for security vulnerabilities.**
+
+Report privately through **GitHub's private vulnerability reporting**: open the
+repository's **Security** tab → **Report a vulnerability**. This opens a private
+advisory visible only to you and the maintainers. (If you can't use that channel,
+open a normal issue that says only "security — please enable private reporting"
+with no details, and we'll follow up.)
+
+When you report, please include:
+
+- A description of the issue and the impact you believe it has.
+- Steps to reproduce, ideally with a minimal `.bento.html` file or a short
+ script.
+- The affected version (the app version is shown in the About dialog and baked
+ into every shell as `APP_VERSION`), plus your browser and OS.
+
+What to expect:
+
+- We aim to acknowledge a report within a few days.
+- We'll work with you to confirm the issue, assess severity, and prepare a fix.
+- Because updates ship as **signed releases** through the in-app update channel,
+ a fix reaches existing files once the maintainer cuts and signs a new version.
+- Please give us reasonable time to release a fix before any public disclosure.
+ We're happy to credit reporters who want it.
+
+## Scope
+
+In scope:
+
+- The Slides app and runtime (`slides/`).
+- The document format and its parsing/sanitization (`slides/src/model.ts`,
+ `render.ts`).
+- The collaboration engine and E2EE transport (`slides/src/sync/`).
+- The blind sync relay (`server/sync-worker/`).
+- The signed self-update mechanism (`slides/src/update.ts`).
+
+Out of scope: vulnerabilities in third-party browsers or operating systems,
+and issues that require a user to run a `.bento.html` file they already know to
+be malicious from an untrusted source (a Bento document is code-adjacent — treat
+files from strangers like any other HTML you'd open).
+
+## Security posture (for context)
+
+These are the design guarantees a report can be measured against. The full
+design and threat model live in
+[docs/collab-design.md](docs/collab-design.md) and
+[docs/architecture.md](docs/architecture.md).
+
+- **End-to-end encryption, keys in the file.** Live collaboration frames are
+ AES-GCM encrypted under a room key that is minted client-side and lives only
+ inside the document. Possession of the file is membership; "Rotate keys" is
+ revocation.
+- **Blind relay.** The optional sync relay stores and forwards ciphertext only.
+ It sees connection timing and a hash of the room key — never content, names,
+ or document structure.
+- **Signed writes / cryptographic read-only.** Rooms carry an ECDSA P-256 writer
+ keypair; the private half travels only in writer copies. The room id commits
+ to the public key, and the relay verifies a signature over each mutating frame
+ before persisting or fanning it out — so a read-only copy (private key
+ stripped) is enforced at the edge, not by client-side courtesy. The relay
+ stays blind: it verifies authorship over ciphertext without decrypting.
+- **Signed self-updates.** Update manifests are ECDSA P-256 signed; the app
+ verifies the signature against a public key embedded in every shell, checks
+ the SHA-256 of the fetched shell, and requires the version to be strictly
+ newer (no downgrade replay). The signing private key is kept offline and never
+ enters the repo or CI. An update writes a **new** file — the original stays as
+ a rollback.
+- **Pure-data documents.** Text HTML is sanitized and chart options are pure
+ JSON with no functions, so a document cannot smuggle executable code through
+ the model. The plaintext document block is JSON with every `<` escaped so it
+ can never break out of its `<script>` container.
+- **Offline by choice, provably.** An Offline switch hard-blocks every network
+ touch (update checks and the relay). Update checks are otherwise a bare GET
+ carrying no identifiers about you or your document.
+
+## Known trade-offs (documented, not vulnerabilities)
+
+These are deliberate design limits, called out so they aren't reported as bugs:
+
+- **Presence names are claims, not proofs.** Within a shared-key room, displayed
+ collaborator names are self-asserted; verified identity would require the
+ (designed, not yet built) signed-identity layer.
+- **LWW conflict resolution.** Two people editing the same property concurrently
+ resolve last-writer-wins; undo during live collaboration is snapshot-based and
+ can revert a collaborator's concurrent edit to the same property.
+- **The writer file is the write capability.** Anyone holding a writer copy can
+ write — that is the intended model; the file's protection is the file's
+ protection.
diff --git a/docs/README.md b/docs/README.md
new file mode 100644
index 00000000..bee1bba6
--- /dev/null
+++ b/docs/README.md
@@ -0,0 +1,21 @@
+# Bento docs
+
+Engineering and format documentation for Bento Slides. Start here.
+
+| Document | What it covers |
+|---|---|
+| [architecture.md](architecture.md) | How a `.bento.html` file is built, the on-disk anatomy, the self-save loop, the runtime layout, and signed updates. |
+| [format.md](format.md) | **Normative reference for the `bento/slides` JSON document model** — every element type, slide/state/layout shape, `fx`, and the collab fields. The format IS the product. |
+| [agents.md](agents.md) | The AI-agent guide: how to author a *great* deck (mapping content to the right feature), the schema, and copy-paste recipes. Also published at `bento.page/agents.md`. |
+| [collab-design.md](collab-design.md) | The live-collaboration design: the in-house CRDT, the E2EE blind relay, signed-write RBAC, and the threat model. |
+| [RELEASING.md](RELEASING.md) | How a signed release is cut locally, the two-repo site publish, and deploying the sync relay. |
+
+Related, outside `docs/`:
+
+- [../CLAUDE.md](../CLAUDE.md) — the deep, module-by-module development guide
+ with the hard-won gotchas (also what AI agents read to work in this repo).
+- [../CHANGELOG.md](../CHANGELOG.md) — the version history.
+- [../CONTRIBUTING.md](../CONTRIBUTING.md) — setup, conventions, the splice
+ contract, and how to open a PR.
+- [../SECURITY.md](../SECURITY.md) — the security posture and how to report a
+ vulnerability.
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index d222c2d6..7dd66281 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -121,14 +121,14 @@ automatically after every push:
- It fetches the daemon's **own** current deck, so the live room + walls are
preserved (the walls live in the relay room; the KV deck only carries the
- shell + creds), re-shells that doc onto the fresh shell, and `PUT`s it back to
- `/guestbook-admin/seed`.
+ shell + creds), re-shells that doc onto the fresh shell, and `PUT`s it back
+ through the daemon's maintainer-only admin endpoint.
- Idempotent — a no-op when the daemon already serves the current shell.
-- Best-effort — needs the admin bearer key at `working/guestbook-admin-key.txt`
- (gitignored); a missing key or unreachable daemon is a warning, never a failed
- publish. Run it by hand any time with `node scripts/reseed-guestbook.mjs`
- (`--dry` to preview).
-
-An epoch **roll** (fresh room + blank walls) is a separate, deliberate act
-(`build-guestbook.mjs` locally, or `POST /guestbook-admin/roll`) — re-seeding
-never rolls.
+- Best-effort — needs the maintainer's local admin bearer token (kept in a
+ gitignored working file, never committed); a missing token or unreachable
+ daemon is a warning, never a failed publish. Run it by hand any time with
+ `node scripts/reseed-guestbook.mjs` (`--dry` to preview).
+
+An epoch **roll** (fresh room + blank walls) is a separate, deliberate
+maintainer action (`build-guestbook.mjs` locally, or the daemon's admin roll
+endpoint) — re-seeding never rolls.
diff --git a/docs/agents.md b/docs/agents.md
index 5e8825de..c7efa9b2 100644
--- a/docs/agents.md
+++ b/docs/agents.md
@@ -162,7 +162,7 @@ each kind of content to the feature built for it:
- **text**: `html` (inline `<b> <i> <br>` ok), `fontSize`, `fontFamily`,
`fontWeight`, `color`, `align` (`left|center|right`), `valign`,
`lineHeight`, optional `letterSpacing`.
-- **shape**: `shape` = `rect|ellipse|triangle|line|path`, `fill`, `stroke`,
+- **shape**: `shape` = `rect|ellipse|triangle|arrow|line|path`, `fill`, `stroke`,
`strokeWidth`, `radius` (rect corner). Optional `fillGradient`
`{angle, stops:[{at:0..1, color}]}` (CSS-convention angle). Lines take
their color from `fill` and draw horizontally across the box (rotate for
diff --git a/docs/architecture.md b/docs/architecture.md
index d57854cf..a1d63a4f 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -177,7 +177,7 @@ The data block holds one JSON object. Sketch of the current shape — see
BentoDoc
├─ format: "bento/slides"
├─ title
-├─ size: { width: 1600, height: 900 }
+├─ size: { width: 1280, height: 720 } ← canonical 16:9; per-doc, presets in the slide panel
├─ theme: { fontFamily, … }
├─ present?: { slideNumber?, controls?, progress? }
├─ assets?: { key → data URI } ← images, fonts; referenced as "asset:key"
@@ -200,15 +200,28 @@ BentoDoc
│ lineStart?/lineEnd? (none|arrow|dot|bar) · d?/pathBox? (path kind)
├─ image: src ("asset:key" or data URI) · fit · radius
├─ svg: asset?/markup? · css? (scoped per element at render)
- └─ chart: preset? · option ← PURE-JSON ECharts option (template-string
- formatters only — functions can't serialize)
+ ├─ chart: preset? · option · source? ← ECharts-SHAPED pure-JSON option
+ │ (template-string formatters only — functions can't serialize);
+ │ drawn by the in-house charts-lite engine; source={tableId}
+ │ binds it live to a table element
+ ├─ table: columns[{w}] · rows[{cells[{html,align?,color?,bg?,bold?}]}]
+ │ · header · style{headerBg,zebra?,borderColor,cellPad…,radius…}
+ │ ← a real HTML <table>, rendered by the shared renderer
+ └─ media: kind (video|audio) · src (data URI | URL | "asset:key")
+ · poster? fit? radius? · controls/autoplay/loop/muted
+ ← autoplay fires in present mode only
```
+Text also resolves dynamic-field tokens at render time — `{{page}}`,
+`{{pages}}`, `{{title}}`, `{{date}}`, `{{time}}` (page/pages take a zero-pad
+width, `{{page:2}}`) — so page numbering re-flows when slides move. The MODEL
+stores the raw token; only the rendered output is resolved.
+
`fx` carries all presentation behavior:
| Field | Meaning |
|---|---|
-| `enter: 'fade' \| 'fade-up'`, `order` | staggered entrance; equal `order` values enter together |
+| `enter: 'fade' \| 'fade-up' \| 'fade-down' \| 'slide-left/right/up/down'`, `order` | staggered entrance; equal `order` values enter together |
| `countUp` | numbers in the text animate 0 → final |
| `ambient: 'kenburns'`, `ken: {dir, scale, duration}` | photo drift loop, or one-shot zoom-in/out settle |
| `loop: {type:'dash-march', …}` | marching dashed strokes |
@@ -218,8 +231,8 @@ Interactivity is composed from three primitives, all plain data: element
`link` (click → jump to slide id), slide `stateOf` (hidden variants reached by
links, morphing on shared element ids), and `showOnHover` sets with slide
`hover` (in-slide hover reveals). Charts on either side of a morph with the
-same element id additionally animate their *data* (ECharts universal
-transition).
+same element id additionally animate their *data* — the in-house chart engine
+tweens the option's numeric leaves (a bar⇄pie type change stages a fade+sweep).
## 5. Runtime organization
@@ -231,7 +244,7 @@ flowchart TB
STORE["store.ts<br/>doc · selection · undo/redo (JSON snapshots)"]
RENDER["render.ts<br/>single model→DOM renderer"]
ANIM["anim.ts<br/>in-house tween engine"]
- CHARTS["charts.ts<br/>ECharts: SSR snapshots + live mounts"]
+ CHARTS["charts.ts<br/>in-house engine: SVG snapshots + live mounts"]
PRESENT["present.ts<br/>Reveal overlay · morph · fx · states · hover"]
ED["editor/*<br/>editor · canvas (Moveable/Selecto) · panels<br/>patheditor · markdown"]
@@ -350,3 +363,11 @@ its registers defend its edits, the room's replay fills in what it missed.
"Duplicate as new deck" re-mints identity for genuinely new documents.
The relay never sees plaintext, and every saved copy stays a complete,
standalone document (sync is a layer beside the file, never a replacement).
+
+**Signed writes (v0.9.18).** `doc.collab` gained an ECDSA P-256 writer keypair
+(`writerPub` in every copy, `writerPriv` in writer copies only) SEPARATE from
+the symmetric read key. The room id COMMITS to the pubkey (`w`+b64url(sha256))
+so the blind relay pins the writer key trustlessly and DROPS mutating frames
+without a valid signature — a read-only copy is a writer copy with `writerPriv`
+stripped, enforced at the edge, not by client courtesy. Legacy `r`-rooms stay
+permissive. Full design + threat model: `collab-design.md`.
diff --git a/docs/collab-design.md b/docs/collab-design.md
index 50a62ecc..89a5d15e 100644
--- a/docs/collab-design.md
+++ b/docs/collab-design.md
@@ -174,6 +174,14 @@ The saved `.bento.html` format changes by **one additive optional field**:
}
```
+> **Shipped:** the version-vector `vv` sketched here was superseded by
+> stamping the whole CRDT state under `collab.sync` (`SyncStateJSON`) — that,
+> not a bare vv, is what a rejoining offline fork restores to merge two-way.
+> The live `collab` shape also carries `key`/`on`/`writerPub`/`writerPriv`/
+> `role` (see `BentoDoc['collab']` in `model.ts` and the Signed-writes section
+> below). The single-additive-field spirit holds: it's still one optional
+> `collab` object the format never requires to open.
+
- The document JSON in the file is always the *compacted merged state* — a
file never needs the op log to open. Every invariant we shipped
(plaintext block, splice contract, AI round-trip, old updaters) is
diff --git a/docs/format.md b/docs/format.md
new file mode 100644
index 00000000..df2b07ea
--- /dev/null
+++ b/docs/format.md
@@ -0,0 +1,371 @@
+# The `bento/slides` document format
+
+*Normative reference for the JSON document model, current as of Bento Slides
+**v0.9.20** (format version `1`). The authoritative source is
+[`slides/src/model.ts`](../slides/src/model.ts) — this document tracks it. If
+the two disagree, the code wins; please file that as a docs bug.*
+
+A `.bento.html` file carries one JSON document inside a single plaintext block:
+
+```html
+<script type="application/bento+json" id="bento-doc">
+{ "format": "bento/slides", "version": 1, ... }
+</script>
+```
+
+Everything else in the HTML file is the fixed *shell* (the runtime, styles,
+license notices). The document block is the only part that changes between
+saves. See [architecture.md](architecture.md) for how the file is built and
+saves itself; this document specifies the JSON.
+
+This spec is for people writing tools, generators, or agents against the
+format. If you want to *author a good-looking deck*, read
+[agents.md](agents.md) — it maps content to the right feature. This one is the
+dry reference of every field.
+
+---
+
+## Conventions
+
+- **Coordinates** are pixels in the slide space defined by `doc.size` (default
+ `1280 × 720`, a 16:9 canvas). `x,y` is an element's top-left corner.
+- **Colors** are any CSS color string, including `rgba(...)` for alpha.
+- **Angles** are degrees. Rotation is clockwise. Gradient angles follow the CSS
+ convention (`0` = bottom→top, `90` = left→right).
+- **Ids are identity.** Elements that share an `id` across adjacent slides
+ *morph* into each other; slide `stateOf` and element `link` both reference
+ slide ids. Generators must emit deterministic, stable ids.
+- **Additive & forward-compatible.** Unknown fields are preserved through
+ parse → serialize. Old files must open in newer shells. Never repurpose or
+ remove a field; add optional ones.
+- **Pure data.** Text HTML is sanitized to an inline whitelist; chart options
+ are pure JSON (no functions). A document can never carry executable code.
+- **Self-contained.** Everything a view needs is in the file. External
+ references (image/media URLs) are allowed but break the offline guarantee;
+ embedded `data:`/`asset:` sources keep it intact.
+
+When writing the JSON into the file block, **escape every `<` as `<`** so
+the string `</script>` can never appear and terminate the block.
+
+---
+
+## Top-level: `BentoDoc`
+
+| Field | Type | Required | Notes |
+|---|---|---|---|
+| `format` | `"bento/slides"` | yes | Format discriminant. Check it before editing. |
+| `version` | `number` | yes | Format version. Current: `1`. |
+| `docId` | `string` (uuid) | yes* | Stable per-document identity, minted at creation. **Never regenerate it.** *Minted on load if a pre-`docId` file lacks one. |
+| `title` | `string` | yes | Deck title; also synced to the HTML `<title>`. |
+| `size` | `{ width, height }` | yes | Slide coordinate space in px. Default `1280 × 720`. |
+| `theme` | `Theme` | yes | Deck-wide defaults (see below). |
+| `slides` | `Slide[]` | yes | Linear order; state slides sit right after their parent. Must be non-empty. |
+| `modified` | `string` (ISO) | yes | Last-modified timestamp. |
+| `present?` | `{ slideNumber?, controls?, progress? }` | no | Present-mode Reveal chrome toggles. |
+| `assets?` | `Record<string,string>` | no | Shared blobs (raw SVG markup or `data:` URIs), referenced by key as `"asset:<key>"`. |
+| `fonts?` | `Array<{ family, asset, weight?, style? }>` | no | Embedded `@font-face`s injected at boot; `asset` is a key into `assets` (a woff2 data URI). |
+| `layouts?` | `Slide[]` | no | Slide-shaped templates (see [Layouts](#layouts)). Absent = the built-in starter layouts are offered. |
+| `collab?` | `Collab` | no | Live-collaboration credentials + CRDT state (see [Collaboration fields](#collaboration-fields)). |
+| `template?` | `boolean` | no | Template file: every open mints a fresh `docId` and drops `collab` (see [File modes](#file-modes)). |
+| `readonly?` | `boolean` | no | Player file: boots straight into the presentation, no editor. |
+
+### `Theme`
+
+| Field | Type | Notes |
+|---|---|---|
+| `background` | `string` | Default slide/canvas background. |
+| `color` | `string` | Default text color. |
+| `accent` | `string` | Single accent color; also seeds derived chart palettes. |
+| `fontFamily` | `string` | Default font stack. |
+| `chartPalette?` | `string[]` | Ordered series colors for new charts. Absent = derived from `accent`. |
+
+---
+
+## `Slide`
+
+| Field | Type | Required | Notes |
+|---|---|---|---|
+| `id` | `string` | yes | Stable slide id. Link + morph targets reference it. |
+| `background` | `string` | yes | Slide background (CSS color). |
+| `transition` | `TransitionKind` | yes | `none \| fade \| slide \| zoom \| morph`. `morph` tweens matched element ids from the previous slide. |
+| `elements` | `SlideElement[]` | yes | **Array order = paint order (z).** First element is at the back. |
+| `notes` | `string` | yes | Speaker notes (travel in the file; shown in speaker view). |
+| `name?` | `string` | no | Friendly label for link pickers / state badges. |
+| `stateOf?` | `string` | no | Marks this slide a hidden *state* variant of the slide with this id (see [Interactive states](#interactive-states)). |
+| `hover?` | `{ type, dim?, default? }` | no | Present-mode hover behaviour: `type: 'focus-group'` (dim elements outside the hovered group) or `'reveal'` (`showOnHover` set swap; `default` names the resting set). |
+| `comments?` | `Comment[]` | no | Review threads. Editor-only — never rendered in present/print, but saved in the file. |
+
+### `Comment`
+
+`{ id, author, text, at (ISO) }` plus an optional anchor and thread:
+
+- Anchor: `elementId?` (thread pinned to an element), or `x?`/`y?` (a point in
+ slide coordinates), or neither/dangling (the whole slide).
+- `resolved?: boolean`; `replies?: Array<{ id, author, text, at }>`.
+
+`window.bento.comments()` returns the flat, typed-anchor list — the entry point
+for tooling that processes flagged issues in a deck.
+
+---
+
+## Elements
+
+Every element carries the common `ElementBase` fields, plus type-specific ones.
+
+### `ElementBase` (shared by all)
+
+| Field | Type | Notes |
+|---|---|---|
+| `id` | `string` | Identity. Shared ids across adjacent slides morph. |
+| `x, y, w, h` | `number` | Frame in slide px (top-left origin). |
+| `rotation` | `number` | Degrees, clockwise. |
+| `opacity` | `number` | `0..1`. |
+| `shadow?` | `ShadowSpec \| ShadowSpec[]` | Drop shadow(s): `{ x?, y?, blur, color }`. An array stacks (e.g. elevation + glow). Follows the element's alpha shape. |
+| `fx?` | `Fx` | Presentation behaviour — runs in present mode only (see [`fx`](#fx-presentation-effects)). |
+| `link?` | `string` | While presenting, clicking jumps to this slide id. |
+| `group?` | `string` | Semantic group tag — hover focus + multi-element present behaviours target it. |
+| `groupId?` | `string` | *Editor* grouping (select/move as one). Distinct from `group`. |
+| `showOnHover?` | `string` | In-slide hover reveal: visible only while an element whose `group` equals this value is hovered (with `slide.hover.type='reveal'`). |
+| `role?` | `string` | Layout role (`title`/`subtitle`/`body`/`kicker` by convention) — drives cross-layout content moves. Free-form. |
+
+The element `type` discriminant is one of: `text`, `shape`, `image`, `svg`,
+`chart`, `table`, `media`.
+
+### `text`
+
+`type: "text"` — `html` (sanitized inline subset: `b/i/u/s/code/br/span`),
+`fontSize`, `fontFamily`, `fontWeight`, `color`, `align` (`left|center|right`),
+`valign` (`top|middle|bottom`), `lineHeight`. Optional `letterSpacing` (px) and
+`placeholder` (a dimmed prompt shown while `html` is empty; hidden in
+present/print).
+
+Text also resolves dynamic-field tokens at render time — `{{page}}`,
+`{{pages}}`, `{{title}}`, `{{date}}`, `{{time}}` — with an optional zero-pad
+width on page/pages (`{{page:2}}` → `06`). The model stores the raw token;
+only the rendered output is resolved, so numbering re-flows when slides move.
+
+### `shape`
+
+`type: "shape"` — `shape: rect | ellipse | triangle | arrow | line | path`,
+plus `fill`, `stroke`, `strokeWidth`, `radius` (rect corner). Options:
+
+- `fillGradient?`: `{ angle, stops: [{ at: 0..1, color }] }` — linear gradient;
+ when set it wins over `fill` (kept as the solid fallback).
+- `strokeStyle?`: `solid | dashed | dotted` (wins over legacy `strokeDash?`).
+- **line** shapes take their color from `fill`, draw horizontally across the
+ box (rotate for vertical), and accept tips `lineStart?`/`lineEnd?` =
+ `none | arrow | dot | bar`.
+- **path** shapes carry `d?` (SVG path data) authored in the `pathBox?`
+ viewBox `[x, y, w, h]`.
+
+### `image`
+
+`type: "image"` — `src` (a `data:` URI or `"asset:<key>"`), `fit`
+(`contain|cover|fill`), `radius`. Embed images as `data:` URIs in `doc.assets`
+and reference them to keep the file self-contained.
+
+### `svg`
+
+`type: "svg"` — `asset?` (key into `doc.assets` holding raw SVG markup;
+preferred, dedupes) or `markup?` (inline SVG). `css?` is injected inside the
+svg and scoped to it at render (hover/focus/animation styles stay contained).
+Prefer composing native `shape`/`text`/`path` elements when they can morph;
+use `svg` for static artwork/geography.
+
+### `chart`
+
+`type: "chart"` — `option` is a **pure-JSON, ECharts-*shaped*** option object
+(the format is ECharts-compatible; the renderer is the in-house `charts-lite`
+engine, not ECharts). Static SVG snapshots on the editor canvas / thumbnails /
+print; a live interactive instance (tooltips, wheel-zoom, drag-pan) while
+presenting.
+
+- `preset?`: `bar | line | pie | scatter` — the panel's re-seed key.
+- `source?`: `{ tableId }` — live binding; the chart's labels + series values
+ track that table element (data only; styling/axes preserved).
+
+**Chart rules that bite:**
+
+- Bar/line series `data` must be **plain numbers**. `{value, itemStyle}` item
+ objects coerce to `0`; only **pie** takes `{name, value}`.
+- Color **by series**, not per bar — per-item bar colors are unsupported.
+- Formatters are **template strings only** (`{b}`, `{c}`, `{d}`) — never
+ functions (they can't serialize).
+- **Dual y-axis**: `yAxis` may be an array of two `{type:"value"}` axes; a
+ series selects one via `yAxisIndex: 0|1`. Give the second axis
+ `axisLabel:{formatter:"{value}%"}` for a percentage scale.
+- Unknown option keys degrade gracefully (ignored, never fatal).
+
+### `table`
+
+`type: "table"` — a real HTML `<table>` (table-layout fixed), rendered
+identically on canvas/thumbnails/present/print.
+
+- `columns`: `Array<{ w }>` — fractional column weights, normalised at render.
+- `rows`: `Array<{ cells: TableCell[] }>` where `TableCell` = `{ html, align?,
+ color?, bg?, bold? }` (`html` is the same sanitized inline subset as text).
+- `header`: `boolean` — treat row 0 as a styled header.
+- `style`: `TableStyle` = `{ headerBg, headerColor, zebra?, borderColor,
+ borderWidth, cellPadX, cellPadY, fontSize, fontFamily?, color, radius }`.
+
+Cohesion lives in `style`; cells carry only overrides. Morphs as a box —
+cell *content* does not morph. Under live collaboration `rows` is a whole-value
+LWW register (concurrent different-cell edits are last-writer-wins).
+
+### `media`
+
+`type: "media"` — `kind: video | audio`, `src` (a `data:` URI = embedded, an
+external URL / relative path = referenced, or `"asset:<key>"`). Video also
+takes `poster?` (`data:`/`asset:`/URL), `fit?` (`contain|cover|fill`),
+`radius?`. Playback flags: `controls?`, `autoplay?`, `loop?`, `muted?`.
+
+- **Autoplay fires only in present mode** (never on the canvas or in
+ thumbnails), and browsers require `muted: true` for a video to autoplay — so
+ `defaultMedia` mutes video by default.
+- Embed only **short** clips. The editor warns above `MEDIA_EMBED_BUDGET`
+ (8 MB) and offers a URL instead — a big data URI makes the file slow to open
+ and save.
+
+---
+
+## `fx` (presentation effects)
+
+All `fx` behaviour runs in **present mode only**.
+
+| Field | Type | Meaning |
+|---|---|---|
+| `enter?` | `'fade-up' \| 'fade' \| 'fade-down' \| 'slide-left' \| 'slide-right' \| 'slide-up' \| 'slide-down'` | Entrance animation. `fade-*` nudge ~16px; `slide-*` sweep ~120px from an edge. Only runs on non-morph arrivals. |
+| `order?` | `number` | Stagger step in the entrance sequence; **equal values enter together**. |
+| `countUp?` | `boolean` | Animate numeric parts of the text from 0 to their final value. |
+| `ambient?` | `'kenburns'` | Continuous ambient motion for full-bleed photos. |
+| `ken?` | `{ dir?, scale?, duration? }` | Ken-burns tuning. `dir: 'drift'` (default) is an endless slow yoyo zoom; `'out'`/`'in'` play once per slide entry (`'out'` starts zoomed by `scale` and settles). `duration` in seconds. |
+| `loop?` | dash-march or motion-path | Continuous loop (below). |
+
+`loop` is one of:
+
+- `{ type: 'dash-march', distance?, duration? }` — marching dashed strokes.
+- `{ type: 'motion-path', path, duration, delay?, ease?, speeds? }` — the
+ element travels an SVG path **relative to its rest position** (the first
+ anchor is `0,0`). `ease` sets per-lap tempo; `speeds[]` gives per-anchor speed
+ multipliers (`1` = normal, `<1` dwells, `>1` rushes; length matches the
+ anchor count). Never combine a motion-path loop with an entrance tween.
+
+---
+
+## Interactive states
+
+A slide with `stateOf: "<parent-id>"` is a hidden variant of its parent:
+
+- Skipped by linear navigation. Reached only by element `link`s.
+- While on a state, `ArrowLeft` returns to the parent, `ArrowRight` continues
+ *past* it.
+- If it shares element ids with its parent (or a sibling state) and the
+ transition is `morph`, the matched elements glide between the two.
+
+State slides live adjacent to their parent in `slides[]` and render nested in
+the editor sidebar. A clickable trigger should be a padded transparent hit
+rect, not the label text itself.
+
+---
+
+## Layouts
+
+`doc.layouts` holds `Slide`-shaped templates (plus the built-ins in `model.ts`).
+Instantiating a layout **keeps element ids** — slides born from the same layout
+share ids, so their common chrome morphs across transitions and stays traceable
+for a re-apply merge.
+
+Applying a layout to an existing slide matches donors first by id, then by
+`role` (same element type required); the layout supplies frame + typography
+while content (text `html`, `link`) rides along. Layout-owned leftovers are
+dropped unless they are text someone actually wrote; user extras survive on top.
+
+---
+
+## Collaboration fields
+
+`doc.collab` is optional and additive; a file with no `collab` opens as a
+standalone document forever. Full design and threat model:
+[collab-design.md](collab-design.md).
+
+| Field | Type | Notes |
+|---|---|---|
+| `room` | `string` | Relay WebSocket URL. Room id is **random** — never derived from `docId`. Signed-scheme rooms start `w`; legacy rooms start `r`. |
+| `key` | `string` | base64url AES-GCM room key — the **read** capability. Travels in every copy. |
+| `on?` | `boolean` | Gates auto-join. Absent = `true` (v0.8.0 files only carried `collab` while actively shared). |
+| `sync?` | `SyncStateJSON` | CRDT state (registers / liveness / text) stamped at save on shared documents. Lets an offline-edited copy rejoin as a true fork and merge two-way. Never transmitted as ops. |
+| `writerPub?` | `string` | ECDSA P-256 public key (raw SPKI, base64url) — the **write** capability's public half. Travels in every copy; the relay verifies authorship against it. |
+| `writerPriv?` | `string` | ECDSA private key (PKCS#8, base64url). Travels **only** in writer copies. A read-only copy is a writer copy with this stripped. |
+| `role?` | `'writer' \| 'reader'` | `'reader'` = a live viewer: receives updates, never sends. |
+
+Possession of a copy is the capability; **"Rotate keys" re-mints them to cut
+old copies off** (and upgrades a legacy `r`-room to an enforced `w`-room).
+
+---
+
+## File modes
+
+| Mode | Set by | Behaviour |
+|---|---|---|
+| **Editable deck** | (default) | Boots the editor; saves rewrite the file in place. |
+| **Template** | `template: true` | Every open mints a fresh `docId` and drops `collab` (`parseDoc` strips the flag) — each opener gets an independent deck. The template file itself never changes. |
+| **Player / presentation package** | `readonly: true` | Boots straight into the presentation; never shows the editor. Collab is stripped from the saved copy. |
+| **Read-only live viewer** | `collab.role: 'reader'` (`writerPriv` stripped) | Boots the editor locked; receives live updates but the relay drops any write. |
+
+Encryption is orthogonal: the `#bento-doc` block may hold a `bento/enc`
+envelope (PBKDF2-SHA-256 + AES-GCM over the doc JSON) instead of plaintext
+document JSON — boot shows a password gate. The envelope is still plaintext
+JSON in the block, so the splice contract holds.
+
+---
+
+## Format invariants (do not break)
+
+1. `format: "bento/slides"` plus **additive, optional** fields — old files open
+ in newer shells; unknown fields survive parse → serialize.
+2. Element **ids are identity** — morph, states, and links all key off them.
+ Generators must emit deterministic ids.
+3. The data-block JSON stays `<`-escaped; text HTML and chart options stay pure
+ data (no functions, sanitized HTML) — a document can never smuggle code.
+4. Asset references are `asset:` keys into `doc.assets`; a self-contained file
+ fetches nothing external at view time.
+5. Motion paths are stored **relative** to the element's rest position; the
+ first path anchor is that position by definition.
+6. Every document carries a stable `docId` — never derive it from content,
+ never regenerate it on save.
+
+## Minimal valid document
+
+```json
+{
+ "format": "bento/slides",
+ "version": 1,
+ "title": "My deck",
+ "size": { "width": 1280, "height": 720 },
+ "theme": {
+ "background": "#101418", "color": "#F2F0EA",
+ "accent": "#FF9E8A", "fontFamily": "system-ui, sans-serif"
+ },
+ "slides": [
+ {
+ "id": "s1", "background": "#101418", "transition": "none",
+ "notes": "speaker notes here",
+ "elements": [
+ {
+ "id": "t1", "type": "text",
+ "x": 96, "y": 260, "w": 1088, "h": 160,
+ "rotation": 0, "opacity": 1,
+ "html": "Hello from a tool.",
+ "fontSize": 88, "fontFamily": "system-ui, sans-serif",
+ "fontWeight": 800, "color": "#F2F0EA",
+ "align": "left", "valign": "top", "lineHeight": 1.1
+ }
+ ]
+ }
+ ],
+ "modified": "2026-07-19T00:00:00.000Z"
+}
+```
+
+`docId` is omitted above for brevity — `parseDoc` mints one on load. When a
+tool *creates* a document from scratch, generate a fresh uuid for `docId`.