| 1 | # AGENTS.md |
| 2 | |
| 3 | Guidance for AI coding agents working in this repository. This is the |
| 4 | canonical agent-instructions file; `CLAUDE.md` points here and duplicates |
| 5 | nothing, because two copies drift and the drift is silent. |
| 6 | |
| 7 | Slides is a presentation editor for the Oficina suite: a deck that looks |
| 8 | like a Keynote deck on a desktop, reads like a document on a phone, |
| 9 | presents from a laptop and is driven from a phone. One instance per team |
| 10 | on the CARLOS platform, at `slides.oficina.works` for the first team. |
| 11 | It is built beside [Docs](https://amadan.net/oficina/docs), |
| 12 | [Sheets](https://amadan.net/oficina/sheets) and the suite |
| 13 | [doctrine](https://amadan.net/oficina/suite); where a decision is already |
| 14 | made over there, this repo consumes it rather than restating it. |
| 15 | |
| 16 | Design: `docs/superpowers/specs/2026-09-07-slides-design.md` (revision 1, |
| 17 | still unreviewed — §12 puts the review pass after slice 1 ships, so the |
| 18 | reviewer gets a running instance instead of a document; ruling 12 was |
| 19 | added during slice 2 and §2.6 rewritten with it). Plans: |
| 20 | `docs/superpowers/plans/2026-09-07-slice-1-live.md` and |
| 21 | `2026-09-07-slice-2-editor.md`. Read the spec section behind whatever you |
| 22 | touch. Read rastrillo's own `SKILL.md` (repo root, or in the module |
| 23 | cache) before writing handlers or models — it is the whole app story in |
| 24 | about 15KB, and you should assume none of it is in your training data. |
| 25 | |
| 26 | ## The one rule |
| 27 | |
| 28 | **A slide is one block tree, rendered many ways** (spec §0.1). The tree is |
| 29 | the only truth. The viewer renders it, the phone reflows it, the presenter |
| 30 | shows it, the drive API patches it, and the editor edits that same tree |
| 31 | through the same operations — its stage is the server's own HTML for the |
| 32 | slide, not a second rendering of it. There is never a desktop version and |
| 33 | a mobile version of a deck, only one deck and a viewport. |
| 34 | |
| 35 | Everything else follows. `flow` and `canvas` are two ways of placing the |
| 36 | same blocks, not two kinds of slide (§2.3). The phone overrides are entries |
| 37 | in the tree, not a second file (§2.5). The drive API is the inspector's |
| 38 | operations with a JSON body (§7). If a change you are making needs a second |
| 39 | representation of a deck, you have almost certainly taken a wrong turn. |
| 40 | |
| 41 | ## What is actually built |
| 42 | |
| 43 | Slices 1, 2 and 3. A deck is edited in the browser at `/d/{sqid}/edit`, |
| 44 | driven through the API (`docs/api.md`), or arrives as the sample deck |
| 45 | seeded on first sign-in — and comes back out as a PDF. |
| 46 | |
| 47 | - **Sign-in** (`internal/slides/auth.go`, `signin.go`, |
| 48 | `signin_return.go`) is Keymail for an address |
| 49 | whose domain runs Keymail and an emailed magic link for every other |
| 50 | address — decided by the domain alone, never by |
| 51 | `SLIDES_ALLOWED_ADDRESSES`, or the endpoint becomes a membership |
| 52 | oracle. **The door is the smart door** (Home spec |
| 53 | `2026-11-19-smart-door.md`, step 6; home/connect `MIGRATING.md`): |
| 54 | rastrillo's sign-in screen (`SigninScreen`, `SigninOneWay`) drawn in |
| 55 | estilo's door by `estilo-signin-screen`, one way in per page — the way |
| 56 | this browser used last, else Continue with Oficina ID with Home |
| 57 | configured — and "Other ways to sign in". Every state (door, chooser, |
| 58 | Sent, the Keymail continuation, a problem, the confirm step) is that one |
| 59 | template, in rastrillo's approved words; the tab title is rastrillo's |
| 60 | for the state. A Keymail address, permitted or not, continues on the |
| 61 | door (`/signin?continue=`, whose meta refresh leaves for Keymail; never |
| 62 | a 303 out of the form POST: Safari applies `form-action` to it); any |
| 63 | other gets `303 ?sent=1`, and only a permitted one is mailed, by a |
| 64 | worker after the response (`mailQueue`), so not even the response time |
| 65 | differs. Admission is |
| 66 | rastrillo/auth's `Authorize`, after verification, and its refusal is |
| 67 | the door with the refusal in the screen's app-problem slot, in the |
| 68 | refusal's own 403, by auth's `Refused` hook |
| 69 | (`refused`; never a query anyone could type). An emailed link opens on |
| 70 | a confirm step (auth's `RenderConfirm`): the door with one Sign in |
| 71 | button, which POSTs the token back to `/auth/verify` — the GET spends |
| 72 | nothing, so a mail scanner fetching the link cannot burn it. Both |
| 73 | methods of `/auth/verify` are mounted in both modes. The list is also |
| 74 | **rechecked on every request** that resolves a principal, so taking an |
| 75 | address off it signs that person out of every device and refuses their |
| 76 | agents' tokens rather than leaving them everything they already held |
| 77 | (spec §6.1, ruling 16, codex 6), and lands them on |
| 78 | `/signin?err=removed`, which says so. On a team instance Home's roster |
| 79 | replaces that recheck (spec §6.4, "Team mode" below). |
| 80 | - With Home, `/signin` is connect's `SigninDoor`, `/signin/local` its |
| 81 | `SigninLocal` (email only, where connect sends people Oficina ID |
| 82 | cannot help, and every step-up), `/signin/oficina` its |
| 83 | `SigninOficina`; all three behind `admittedOnly`, which runs the |
| 84 | signed-in routes' own gate on a probe (`admission`). A session that |
| 85 | gate refuses gets the refusal on the plain door (never the chooser or |
| 86 | a way's page, so Other ways still works), its cookie cleared on that |
| 87 | response, and a remembered Oficina ID forgotten; a gate that cannot |
| 88 | decide (a 5xx) is not a refusal. Standalone, `/signin` does the same |
| 89 | and offers email only. |
| 90 | - `MintHomeSession` remembers Oficina ID (`rememberOficina`), with the |
| 91 | address connect resolved for this sign-in, only for a session the |
| 92 | gate admits, and never carries an address over. |
| 93 | - The page a sign-in began from is kept in Slides' sealed return |
| 94 | memory: `beginSignin` takes `return_to` off Begin's form (even when |
| 95 | the body fails to parse), remembers it (`/` when absent, unsafe or |
| 96 | `/signed-out`) and puts it back on Begin's redirect to the door; |
| 97 | `/auth/landed` (standalone) and `homeLocalComplete` (Home, in place |
| 98 | of connect's landing `/`) land there once. Forget and Sign out |
| 99 | forget it. |
| 100 | - `/signed-out` offers Forget me on this device (`/signin/forget`, |
| 101 | auth's `Forget`); with Home the form chains on to |
| 102 | `{issuer}/forget?return=<origin>/signed-out`. |
| 103 | - Begin's own problems (`?err=rate`, `?err=address`) are answered as |
| 104 | they are, the same for an address on the list and off it; the old |
| 105 | `sameAnswer` rewrite to Sent is gone (it told a mistyped address "We |
| 106 | sent a link" and dropped `force=1`). A step-up's `reauth=1` and the |
| 107 | `return_to` survive every answer. |
| 108 | - **Decks**: list, create, settings, delete, three rungs (private, |
| 109 | granted, team) per suite ruling 15. A deck opens in the editor, as a |
| 110 | document does in Docs: the list links `/d/{sqid}/edit`, and the bare |
| 111 | `/d/{sqid}` is a 303 there (after `deckFor`, so a stranger still gets |
| 112 | the 404). Who can open a deck is chosen on its share page |
| 113 | (`POST /d/{sqid}/share/access`, `mayChangeRung`), as general access |
| 114 | is under Share in Docs; the settings page is the scriptless title and |
| 115 | theme form, linked only from the editor's `<noscript>`. |
| 116 | - **The viewer** (`internal/slides/viewer.go`): `/d/{sqid}?slide=N`, |
| 117 | one slide per page, previous and next as ordinary links (changed in |
| 118 | place with a script, `fixtures/viewer-nav.mjs`), notes in a |
| 119 | `<details>`, the slides as a rail at its side from 1100px. Shaped as |
| 120 | Docs shapes a document: the deck's title is the bar's context and |
| 121 | Share… the bar's action; the page's own row is Edit, Present and an |
| 122 | overflow. The owner, |
| 123 | a team member and a stranger holding a share link all get the same page |
| 124 | from the same template with `mode` as a field, because the day those |
| 125 | three drift is the day one of them leaks the speaker notes. |
| 126 | - **Share links** (`share.go`): a read-only capability, SHA-256 stored, |
| 127 | URL shown once, revocable. A missing token and a revoked one 404 alike. |
| 128 | - **Follow-along codes** (block type `qr`, `qrlink.go`, `qr/`): a QR |
| 129 | code on a slide for the audience to follow the talk on their own |
| 130 | phones. Its `props.url` is the follow address of an audience share |
| 131 | link (`http(s)://<host>/s/<token>?follow=1`, the one shape core, |
| 132 | fixtures and `deck.FollowAddress` accept); the box stores the address |
| 133 | because only the token's hash is kept. `POST /d/{sqid}/qr-link` |
| 134 | (`mayShareDeck`, as the share page) mints the link, marked |
| 135 | `Audience` on `ShareLink` and named so on the share page, and |
| 136 | answers the address; the editor writes it into the box through |
| 137 | `commit()`. render and layout draw the same modules (`qr.Modules`; |
| 138 | layout's are crisp rects), with the short address under the code, |
| 139 | but only what `followCodes` vouches for (`render.Options.QR`, |
| 140 | `layout.Options.QR`, nil draws none): this origin's address whose |
| 141 | token is a live share link of this deck. On `/s/` surfaces the code |
| 142 | is the reader's own link, never the stored one. Anything else is an |
| 143 | empty frame on the editor's stage and nothing for readers. Slide |
| 144 | caches carry `linksStamp`, so a revoke changes their tags. Insert's |
| 145 | row and the card's button are for sharers only (`InsertTypes`). |
| 146 | - **Presenting** (`presentation.go`, `present/hub.go`): a server-side |
| 147 | session with a pairing code, the fullscreen surface, the presenter view |
| 148 | with notes and a clock, the phone remote, and audience follow from a |
| 149 | share link — which **stays on** `/s/{token}` routes, stream included, |
| 150 | so revoking the link ends the follow. The session sqid is a projector |
| 151 | address and is never rendered onto a follow page (spec §3.4, codex 5). |
| 152 | - **The editor** (`editor.go`, `templates/editor.html`, |
| 153 | `static/editor.css`, and the committed bundle built from `fixtures/`): |
| 154 | the strip of server-rendered thumbnails, the stage, the inspector for |
| 155 | the slide and the selected block, the deck's settings in a dialog |
| 156 | under File, text edited in place through |
| 157 | ProseMirror bound to the server's own HTML, canvas drag and resize with |
| 158 | snapping, the desktop/phone switcher whose phone-view edits become |
| 159 | `set_phone` overrides, undo scoped to the person who made the change, |
| 160 | presence, and image upload when a store is bound. |
| 161 | - **Live sync** (`live.go`, `live/hub.go`, `snapshot.go`): the update log |
| 162 | served by cursor, an SSE stream of advisory seqs and whole presence |
| 163 | sets, and a snapshot every 200 updates so opening a long-lived deck is |
| 164 | not a full replay. |
| 165 | - **Assets** (`assets.go`, `svg.go`): presigned PUT browser-to-bucket |
| 166 | into a **staging key this app mints** (never an address the client |
| 167 | named), registration that resolves the upload receipt for it, re-reads |
| 168 | and sniffs what actually landed, sanitises an SVG, and **promotes the |
| 169 | bytes to a final object keyed by their own hash** — then three |
| 170 | capability-checked routes serving them back. The receipt is the |
| 171 | `asset_uploads` row (`models.go`, migration |
| 172 | `0008_create_asset_uploads.sql`): one deck, one actor, single use, two |
| 173 | hours. A ref alone registers nothing, and no PUT is ever signed for an |
| 174 | address something is already served from (spec §2.7, codex 1 and 2). |
| 175 | An agent uploads with the bearer instead (`agent_assets.go`, |
| 176 | `POST /api/v1/decks/{sqid}/assets`): the bytes are the body, at most |
| 177 | 20 MiB, a PNG, JPEG or WebP by its magic that `image.DecodeConfig` |
| 178 | reads within `maxAssetDimension` and `svg.MaxDecodePixels` (no SVG; the |
| 179 | header only, not a full decode), stored under their hash, |
| 180 | the `deck_assets` row written, then `register_asset` (with width, |
| 181 | height and `?alt=`) applied as the agent through `applyAgentOpsFrom`, |
| 182 | which builds the batch from the document it lands on. The same bytes |
| 183 | twice are one asset: 200 with the existing id, nothing written. |
| 184 | - **The font library** (`library.go`, `fonts.html`, estilo's `typeface` |
| 185 | package): `/fonts` is a person's own set of fonts, uploaded through |
| 186 | the app (TTF, OTF, WOFF, WOFF2; `typeface.Inspect` reads the family, |
| 187 | weight, italic and whether a face may go in a picture or PDF, as |
| 188 | `Pictures()`). Limits: 10 MiB a file, 16 faces to a family, 32 |
| 189 | families. `typeface.Inspect` also refuses tables that overlap or sum |
| 190 | past the file, and checks outline structure (loca against glyf and |
| 191 | maxp, CFF/CFF2 INDEXes; not a WOFF2's transformed glyf). A name is |
| 192 | made by `deck.FontCSSName`'s one pattern, the one the document and |
| 193 | layout take; a catalog family's or a CSS generic keyword's gets a |
| 194 | number. Uploads and deletes take `fontMu`, so the limits hold under |
| 195 | two at once. A file lives in the object store under its own hash, and |
| 196 | `typeface.Headers` serves it with private caching; the page shows each |
| 197 | family's name set in it, from `/fonts/files/{ref}` (its owner only), |
| 198 | and answers its families as JSON for Deck settings, which asks again |
| 199 | when the editor's window has focus. Deck settings |
| 200 | picks a library family (`POST /d/{sqid}/fonts`: `DeckFont` rows and |
| 201 | the `meta.fontFiles` set_meta). The deck names the family, not the |
| 202 | library: a listed family sharing a file with it keeps its name, any |
| 203 | other gets a number while a listed family has the name in any case, |
| 204 | so two people's Brands are Brand and Brand 2. Agents can write `meta.fontFiles` but |
| 205 | cannot upload bytes: a ref is served only through a deck that |
| 206 | recorded it **and** lists it (`/d`, `/s`, `/p` `.../fonts/{ref}`; `/d` |
| 207 | also serves a recorded ref to its library owner, so a pick loads |
| 208 | before its set_meta lands). The TrueType parser in `fonts/` reads |
| 209 | untrusted bytes, so every offset and count is bounds-checked. |
| 210 | - **The layout engine and thumbnails** (`layout/`, `svg/`, `fonts/`, |
| 211 | `thumbs.go`): every slide measured into a paint list with the same |
| 212 | embedded Liberation faces the browser sets it in, written as an SVG, |
| 213 | and served as `{surface}/slides/{id}.svg` from all four capabilities. |
| 214 | A deck stack that names an uploaded family first is set in its static |
| 215 | TrueType faces (`meta.fontFiles` faces marked `pictures`: static TrueType whose |
| 216 | flags allow subsetting), read from |
| 217 | the object store (`fontstore.go`) and parsed once per render through |
| 218 | `layout.New`, a face chosen for 400 and 700 as CSS font matching |
| 219 | chooses (a bold with no bold face is the face CSS picks, unthickened); |
| 220 | anything else (variable, CFF, no subsetting) falls |
| 221 | back down the stack. A thumbnail carries each uploaded face it draws |
| 222 | in as an `@font-face` of a web subset (`fonts.WebSubset`, |
| 223 | `svg.Options.EmbedFonts`), since an SVG in an `<img>` sees no page |
| 224 | font; the export |
| 225 | hands the PDF module those faces renamed to the deck's CSS name |
| 226 | (`fonts.Renamed`, never more than twice the file), because the module |
| 227 | matches the name inside a font. |
| 228 | The editor strip and the remote are that picture. The presenter |
| 229 | window is not: it draws live slides (see the last section); only |
| 230 | sessions begun before positions keep the pictures. |
| 231 | - **PDF export** (`export.go`, `exports.go`, `pdfcore/`, `core/pdf/`): |
| 232 | `POST /d/{sqid}/export` starts a rastrillo job, the status page polls |
| 233 | itself (and works with scripts off), and the file comes back from |
| 234 | `GET /d/{sqid}/export/{job}.pdf`. One page per slide, optionally the |
| 235 | speaker notes as pages of their own, text as embedded glyphs, images |
| 236 | inlined. The API twins are `POST /api/v1/decks/{sqid}/export` and its |
| 237 | two GETs. The file is answerable for an hour and **the status page |
| 238 | says so for the whole hour**: rastrillo/jobs forgets a finished job |
| 239 | after ten minutes, so the page, its fragment and the API's status all |
| 240 | fall back to this app's own held record (`exportFallback`) rather than |
| 241 | 404ing while `.pdf` at the same address still works. |
| 242 | |
| 243 | - **The assistant** (`assist.go`, `assist_ops.go`, `assist_prompt.go`, |
| 244 | `config_ai.go`, `assist/`, `fixtures/assist.mjs`, |
| 245 | `fixtures/assist-panel.mjs`): an Assistant button in the editor's |
| 246 | header, present only with `SLIDES_AI=on`. **The model proposes, the |
| 247 | editor applies.** `POST /d/{sqid}/assist` sends the request and a |
| 248 | compact view of the deck (its slides, its assets each with a kind — |
| 249 | image, video, poster or still — and its scenes, bounded: ids, names, |
| 250 | states, words, code ref and data size, the data itself only up to |
| 251 | 4 KiB) to TensorX (OpenAI-compatible, host pinned, |
| 252 | memoria's provider posture), rebuilds what comes back op by op |
| 253 | (only the drive vocabulary less the asset ops, only each op's keys, |
| 254 | every new id minted here from the model's placeholders, the chosen |
| 255 | scope enforced), applies it to a scratch copy through the core |
| 256 | (`Ops`, `Check`, `deck.Parse`; never the log), refuses an answer that |
| 257 | would empty the deck, gives the model one repair round with the |
| 258 | reason, and answers the checked batch. The browser applies it through |
| 259 | `commit()`, so it is the person's own change: font-gated, one undo |
| 260 | step, saved through the queue, live to everybody. Deck text is |
| 261 | untrusted input to the model; the op rebuild and the scratch check |
| 262 | are the boundary, not the instructions. Config: `SLIDES_AI` is |
| 263 | exactly `on` or unset (anything else refuses boot; a key alone turns |
| 264 | nothing on), `SLIDES_TENSORX_API_KEY`, `SLIDES_AI_MODELS` |
| 265 | (comma-separated ids, first preselected, default |
| 266 | `deepseek/deepseek-v4-flash-0731`), and `SLIDES_AI_DEV_BASE_URL` |
| 267 | (another OpenAI-compatible base for a local run; refuses boot |
| 268 | outside development). Nothing about a deck is logged. |
| 269 | |
| 270 | Not built, and don't write around their absence: charts from Sheets, |
| 271 | embeds, an MCP adapter, aspect ratios other than 16:9, comments, and |
| 272 | version history. Those are the triggers in spec §9. |
| 273 | |
| 274 | **Clips** are built (`internal/slides/clips.go`, `clipcache.go`, |
| 275 | `fixtures/clip*.mjs`): a `clip` block plays a video asset, `play` being |
| 276 | `press`, `loop` or `once`. The video is an MP4 or WebM of 50 MiB at |
| 277 | most, its kind read from the bytes, uploaded and registered like a |
| 278 | picture with two more fields: `poster`, the ref of a PNG or WebP of its |
| 279 | first frame (4 MiB, drawn by the uploader's browser), and `duration`. |
| 280 | Clips play muted, inline and without controls; wherever a video does |
| 281 | not play (scripts off, thumbnails, the PDF, the presenter's Next, the |
| 282 | remote, the editor's stage, and for a reader who asked for less motion |
| 283 | a loop, a once or a press not yet made) the poster shows. Videos are |
| 284 | served in ranges from an on-disk, content-addressed cache of 1 GiB, |
| 285 | read from the store once; a presenting window warms clips one at a |
| 286 | time, up to 300 MiB; and a staged video goes back only to whoever |
| 287 | staged it (`GET /d/{sqid}/uploads/{ref}`). There is no sound, no |
| 288 | trimming and no embed from another site. |
| 289 | `docs/api.md` is the reference for the API, written for a person and an |
| 290 | agent both. |
| 291 | |
| 292 | **Scenes** are a deck's own HTML documents, each drawing a set of named |
| 293 | states, run in a sealed frame and carried from slide to slide. |
| 294 | `docs/scenes.md` is the contract a scene keeps, with a worked example |
| 295 | in `docs/scenes/example.html` (its browser test is |
| 296 | `TestTheExampleSceneAnswersReady`), and the steps for building a deck |
| 297 | with a scene through the API: the bundle, one batch for the scene and |
| 298 | its slides, the version, a still per state. The code: `core/src/scene.rs` |
| 299 | and `internal/slides/deck/scenes.go` (the document and the version), |
| 300 | `internal/slides/scenes.go` and `scenestills.go` (the sealed routes and |
| 301 | the stills), `fixtures/scene-*.mjs` (the frame, its layer and the |
| 302 | editor's card). |
| 303 | |
| 304 | **The deployment's object store is bound (2026-11-11, bucket |
| 305 | `carlos-store-bds-slides`) and served through the app**, not presigned: |
| 306 | `cmd/slides` wraps it in `slides.ThroughApp`, so the browser uploads to |
| 307 | `PUT /d/{sqid}/uploads/{key}` and pictures and exports stream back from |
| 308 | this app. The presigned path below is the design and still what a |
| 309 | presigning store would take, but the page's CSP (`default-src 'self'`, |
| 310 | `img-src 'self' data:`) refuses a browser PUT to the bucket and a picture |
| 311 | from it, and the bucket has no CORS for this origin; going direct needs |
| 312 | both changed. With no store bound at all the upload endpoints answer |
| 313 | `503` and the editor's image field says so. |
| 314 | |
| 315 | ## Layout |
| 316 | |
| 317 | `internal/slides/` is the app in SKILL.md's five-file shape — `models.go`, |
| 318 | `migrations.go` plus `migrations/`, `app.go`, `handlers.go`, `render.go` |
| 319 | plus `templates/` — with one file per screen area beside them (`auth.go`, |
| 320 | `decks.go`, `viewer.go`, `share.go`, `presentation.go`, `sample.go`, |
| 321 | `live.go`, `editor.go`, `snapshot.go`, `assets.go`, `svg.go`, |
| 322 | `thumbs.go`, `export.go`, `exports.go`, `api.go`, `agents.go`, |
| 323 | `agent_assets.go`, |
| 324 | `assets_embed.go`, and team mode's `team_*.go`) and one |
| 325 | package per concern nested underneath: `core` (the wazero host), `deck` |
| 326 | (Go types for the core's JSON view), `render` (slide HTML), `layout` |
| 327 | (the paint list), `svg` (the paint list as a picture), `fonts` (the |
| 328 | embedded faces and their metrics), `pdfcore` (the PDF module's wazero |
| 329 | host), `present` (the presentation SSE hub), `live` (the deck's own |
| 330 | hub: seqs and presence), `teamstate` (team mode's Home-only users). |
| 331 | `internal/slides/static/` holds the vendored |
| 332 | stylesheets and the committed editor bundle. `core/` at the repo root is |
| 333 | the Rust crate. `manifest/` and `gen/` are rastrillo's declarative path, |
| 334 | unused here: `gen/` and `api/v1.json` are what `rastrillo generate` writes |
| 335 | for an app with no resources (empty stubs nothing imports, plus |
| 336 | `gen/locales`, the English pack), committed so that `rastrillo doctor` |
| 337 | is clean. Keep it clean on every rastrillo upgrade: `doctor --fix`, |
| 338 | `migrate-templates -write internal/slides/templates` (templates take |
| 339 | their localizer first, `$L`), `generate`, then `doctor` exits 0. |
| 340 | |
| 341 | `core/pdf/` is a second Rust crate beside the CRDT core: `slides_pdf.wasm` |
| 342 | wraps `krilla` and `krilla-svg` and takes one SVG per page plus the |
| 343 | Liberation TTFs, and writes one PDF with the text as subset, embedded |
| 344 | glyphs. It wrapped `svg2pdf` until 2026-09-09; that repository was |
| 345 | archived on 2026-07-10 naming krilla as its successor, and the swap kept |
| 346 | the ABI byte-identical (spec §1 ruling 13). `internal/slides/pdfcore` |
| 347 | hosts it under wazero with the same containment as `core` but a simpler |
| 348 | shape — a fresh module instance per `Render`, discarded afterwards, under |
| 349 | a sixty-second job deadline rather than the CRDT host's one-second call |
| 350 | deadline. `internal/slides/export.go` is the pipeline over it |
| 351 | (`layout.Layout` → `svg.Encode` with every image inlined → `Render`), |
| 352 | including the notes pages, which are paint lists typeset here with the |
| 353 | fonts package. `scripts/build-pdf-wasm.sh` builds the module; the |
| 354 | artifact is committed at `internal/slides/pdfcore/testdata/slides_pdf.wasm` |
| 355 | and the gate checks its input stamp and, on Linux amd64, its bytes, |
| 356 | exactly as it does the CRDT core's. |
| 357 | `internal/slides/exports.go` is everything around that pipeline: the |
| 358 | screens, the job, and the bytes. |
| 359 | |
| 360 | Both wasm hosts cap the memory one instance may take — 512 MiB for |
| 361 | `pdfcore`, 256 MiB for `core` (`defaultMemoryPages` in each) — because |
| 362 | both run a parser over bytes a deck author controls on an instance |
| 363 | shared with everything else. Past the cap the guest's allocator aborts |
| 364 | and the host reports an ordinary error, which is what the two |
| 365 | `…PastTheMemoryLimitIsAnErrorNotACrash` tests hold. |
| 366 | |
| 367 | `fixtures/` at the repo root is the browser half and the contract that |
| 368 | keeps it honest: the editor's ES modules, their `node --test` tests, |
| 369 | `build-bundles.mjs` (esbuild, output committed), and `generate.mjs` with |
| 370 | `data/` and `vectors/`. It is a Node package with a committed lockfile; |
| 371 | `node_modules/` is not. |
| 372 | |
| 373 | ## The seams |
| 374 | |
| 375 | A handful of functions carry most of the app's invariants. Go through them |
| 376 | rather than around them; a new handler that reaches past one is the usual |
| 377 | way a rule stops holding. |
| 378 | |
| 379 | `currentUser(w, r)` (`auth.go`) maps `sessions.Current(r).Subject` — an |
| 380 | email address under rastrillo/auth, never a user id — to the `users` row, |
| 381 | making it on first sign-in. It is also **the admission recheck**: an |
| 382 | address no longer on `SLIDES_ALLOWED_ADDRESSES` is signed out here |
| 383 | (`offboard` — every session row for it deleted, live talks ended, share |
| 384 | links left alone) and told so on the sign-in page, which is why it takes |
| 385 | a ResponseWriter and answers `sessionOffboarded` rather than a bare |
| 386 | false. The bearer middleware does the same for an agent's operator. |
| 387 | Without both, taking an address off the list removed nothing that address |
| 388 | already held (spec §6.1, codex 6). `actorFor(u)` turns the row into the |
| 389 | `person:<id>` string every write records (§6.2); the API's bearer |
| 390 | middleware produces `agent:<id>` the same way, and a presentation remote |
| 391 | produces `remote:<session>`, the one deliberately anonymous actor (§6.2). |
| 392 | |
| 393 | `visibleDecks(ctx, viewer)` is the read scope: owner, team rung, or a |
| 394 | grant. Its `OR` chain is parenthesised inside the string on purpose — |
| 395 | every caller chains another `Where` on, and an unparenthesised `OR` widens |
| 396 | it to "or this deck is on the team rung", defeating the whole seam by |
| 397 | operator precedence. `deckFor` is a deck the person may read; `ownedDeckFor` |
| 398 | is one they own. Both answer **404, never 403**, so a stranger holding a |
| 399 | sqid cannot learn whether it is real. |
| 400 | |
| 401 | `openDeck` instantiates the Y.Doc: a fresh wasm module, the newest |
| 402 | `deck_snapshots` row applied, every update after it replayed in seq order, |
| 403 | and the JSON view that produces. The handle is the caller's to close. A |
| 404 | snapshot is derived data and never the truth (`snapshot.go`) — the log |
| 405 | alone still is the deck, so a missing or unreadable snapshot means a slower |
| 406 | open and nothing else. |
| 407 | |
| 408 | `applyOps` and `appendUpdate` are the two write paths into a document, and |
| 409 | the only two. Each puts the update row, the `seq` bump and any deck-row |
| 410 | columns in one transaction with the seq as an optimistic lock, so the row |
| 411 | and the log commit or roll back together, then publishes the new seq and |
| 412 | takes a snapshot if it crossed the boundary. They differ in one line and in |
| 413 | what a failure of it means: `applyOps` (`editDeck` wraps it with the |
| 414 | handle's life and one retry on `errDeckBusy`) hands the core an op batch |
| 415 | this app wrote, so a refusal is a bug; `appendUpdate` (`live.go`) hands it |
| 416 | bytes off the wire, so a refusal is ordinary and comes back as a 422. |
| 417 | |
| 418 | "Refusal" there is **two** checks on the fresh handle, both before the |
| 419 | transaction opens, and they look at different things: |
| 420 | |
| 421 | - `Handle.Check(ctx)` — the core's `slides_core_check` (ABI 2, |
| 422 | `core/src/check.rs`, mirrored in `fixtures/check.mjs`) — walks the |
| 423 | **document**: every notes fragment, every block `text`, every table |
| 424 | cell, and refuses anything outside §2.6 (a formatting attribute other |
| 425 | than `b i c h href`, a non-`paragraph` child, an element or fragment |
| 426 | inside a paragraph, an embed). This is the gate that has to exist, |
| 427 | because y-prosemirror 1.3.7 *deletes* an `XmlText` whose attributes it |
| 428 | cannot map to a mark: the words are lost in the browser while the |
| 429 | server sees nothing wrong (spec ruling 19, codex 3). |
| 430 | - `deck.Parse` on the JSON view — the **projection** — which is what |
| 431 | keeps a shape the host's typed structs cannot read out of the log. |
| 432 | |
| 433 | The projection alone is not enough and that is the whole point: the view |
| 434 | is deliberately tolerant (`core/src/view.rs`, mirrored in |
| 435 | `fixtures/view.mjs`) and reads straight past an unknown mark. Bytes off |
| 436 | the wire can put any shape at any key, and what these two keep out of |
| 437 | the log is what would otherwise brick every `openDeck` after it, or |
| 438 | quietly eat somebody's sentence. Nothing else may append to |
| 439 | `deck_updates`. |
| 440 | |
| 441 | `schema::ordered_maps` (`core/src/schema.rs`) and `orderedMaps` |
| 442 | (`fixtures/ydoc.mjs`) are the reading order, and there is one of them |
| 443 | because there is one idea. **Both ordered arrays in the document — the |
| 444 | deck's `slides` and a slide's `blocks` — are SETS**, and the order is an |
| 445 | `order` key on each map in them: a number, absent ranking at the array |
| 446 | index, array index breaking ties (spec §2.1–2.3, rulings 18 and 21, |
| 447 | codex 4). A reorder writes that key and never moves an array entry, |
| 448 | because moving one means deleting the map and inserting a copy, and |
| 449 | every edit a peer had in flight against the original — a sentence being |
| 450 | typed into a block, or into any block of the slide — is then addressing |
| 451 | a deleted type and is lost on merge. `move_slide`, `move_block`, |
| 452 | `add_*`, `duplicate_slide` and canvas-to-flow all go through |
| 453 | `place_entry`/`placeEntry`. **The view sorts by the key and does not |
| 454 | expose it**, so `deck.go`, `render/`, `layout/`, the viewer, the |
| 455 | presenter and the exporter all read one sequence and none of them knows |
| 456 | the key is there — which is also why adding a reader is not a reason to |
| 457 | teach it about `order`. |
| 458 | |
| 459 | `render.Slide(d, index, viewport)` is the only place slide HTML is |
| 460 | produced, for every surface — the viewer, the presenter, the API's |
| 461 | `.html` twin, the editor's stage and its thumbnails. It builds markup by |
| 462 | hand rather than templating it, because `html/template` cannot take a |
| 463 | dynamic tag or attribute name; read the package doc comment for the four |
| 464 | invariants that make that safe before adding a block type. |
| 465 | |
| 466 | `render.SlideWith(..., render.Options{AssetBase})` is that function when |
| 467 | the slide has pictures on it, and **every real surface has to pass its |
| 468 | own base**: `/d/{sqid}/assets` signed in, `/s/{token}/assets` over a share |
| 469 | link, `/p/{session}/assets` while presenting. One slide is rendered on |
| 470 | surfaces authenticated four different ways, and the `<img>` has to be |
| 471 | fetchable by whoever is looking at it. `Slide` stays for callers that have |
| 472 | no pictures to worry about (a test, a fixture) and falls back to |
| 473 | `render.DefaultAssetBase`, which is deliberately a path nothing is mounted |
| 474 | at: forget to say which surface you are and you get visibly broken images |
| 475 | rather than a URL that quietly works from the wrong place. Note also that |
| 476 | the `<img src>` carries the asset's **ref**, never its id — the id is the |
| 477 | deck's own name for it and stays out of URLs. |
| 478 | |
| 479 | `serveAsset` (`assets.go`) is the one body behind all three of those |
| 480 | routes, and the check inside it is the security property, not a |
| 481 | formality: a ref is a content address, so knowing one is knowing the |
| 482 | SHA-256 of somebody's file. It resolves the deck and confirms *this* |
| 483 | deck's `assets` map refers to *this* ref before it serves a byte; |
| 484 | without that, any capability for any deck would fetch any object in the |
| 485 | bucket. It costs an `openDeck` per image request, which is known and |
| 486 | noted rather than forgotten. It also requires a `deck_assets` row for |
| 487 | the pair, written only by `registerAsset` (or the agent's upload, |
| 488 | `apiPostAsset`) after it read, sniffed and sanitised or decoded the |
| 489 | bytes: `register_asset` is an op any member can apply with |
| 490 | any ref, and a presigned PUT lands whatever the browser sent, so the map |
| 491 | alone would let an unverified object be served. |
| 492 | |
| 493 | `layout.Layout(d, index)` is the other renderer, and the rule about it |
| 494 | is the one in the plan: **the paint list is the only input to SVG and to |
| 495 | PDF.** Nothing under `svg/`, `pdfcore/` or `export.go` reads a deck. |
| 496 | Layout measures with the same embedded Liberation faces the browser sets |
| 497 | the slide in (`fonts/`, served as woff2 from `static/fonts/` and put on |
| 498 | the page by the font gate, below), so the two agree on everything but |
| 499 | where a line breaks. Every warning it makes carries the slide it is about |
| 500 | (`layout.Warning.Slide`), because the export's status page lists the |
| 501 | warnings of a whole deck and a line that cannot name its slide is a line |
| 502 | nobody can act on. |
| 503 | |
| 504 | `Export(ctx, view, ExportOptions)` (`export.go`) is that pipeline — |
| 505 | `layout.Layout` → `svg.Encode` with every image inlined → the module's |
| 506 | `Render` — and `exports.go` is everything around it. Two things there |
| 507 | are worth knowing before touching it. The PDF module is compiled once |
| 508 | per app, lazily, and closed with the app (`pdfRuntime`), because |
| 509 | compiling it costs the best part of a second and most processes never |
| 510 | export. And **with no object store bound the finished PDF is held in |
| 511 | memory for an hour**, capped at 50 MiB per deck and 200 MiB per instance: |
| 512 | over either cap the job fails with a sentence the person can act on |
| 513 | rather than the instance failing with an OOM nobody can read. When a |
| 514 | store IS bound the same job uploads it and drops the held bytes, and the |
| 515 | download route 302s to a presigned GET. Both paths are in one handler |
| 516 | (`serveExport`) so neither can rot. |
| 517 | |
| 518 | `present.Hub` is the in-memory fan-out for a live presentation. Its events |
| 519 | are whole state, never deltas, so a subscriber that falls behind is dropped |
| 520 | and reconnects rather than having events skipped — a skipped event leaves a |
| 521 | projector showing slide 4 for the rest of a talk with nothing to notice it. |
| 522 | |
| 523 | `live.Hub` is the same shape for a deck being edited: a seq, which is |
| 524 | advisory ("there is something at least this new" — the bytes come from |
| 525 | `GET /d/{sqid}/updates?since=`), and the whole presence set, which is not. |
| 526 | Presence lives there and nowhere else — it is not document state, so it |
| 527 | never reaches the log, is never snapshotted, and is gone with the process. |
| 528 | |
| 529 | ## The wire the editor speaks |
| 530 | |
| 531 | Docs' live-sync design, adopted as written (spec §3.3). Four routes, all |
| 532 | in the signed-in group, all behind `deckFor`, all 404 for a stranger. |
| 533 | |
| 534 | `GET /d/{sqid}/updates?since=N` answers `application/octet-stream`: every |
| 535 | update after seq N, each framed as a 4-byte big-endian length then the |
| 536 | bytes, in seq order. `Slides-Seq` is the highest seq in the body, or N |
| 537 | when the body is empty — derived from the bytes in hand, never from a |
| 538 | second `MAX(seq)` query, which could see an update this response does not |
| 539 | carry and leave the client holding a cursor for bytes it never received. |
| 540 | At `since=0` the answer may start from the newest snapshot, and |
| 541 | `Slides-Snapshot: <seq>` says when it did. |
| 542 | |
| 543 | `POST /d/{sqid}/updates` takes one Yjs v1 update, 1 MiB cap. It goes |
| 544 | through `appendUpdate`, is stored with the poster's actor, and answers |
| 545 | `204` with `Slides-Seq`. A refusal from the core is a 422 and an ordinary |
| 546 | event: these are bytes off the wire, not a batch this app wrote. |
| 547 | |
| 548 | `GET /d/{sqid}/stream` is SSE and carries no document bytes at all: |
| 549 | `event: update` with `data: <seq>` (advisory — go and fetch), `event: |
| 550 | presence` with the whole set as JSON, `: ping` every 15 s, one of each on |
| 551 | connect, 5 minute TTL. Whole state rather than deltas, so a subscriber |
| 552 | that falls behind is dropped and reconnects. |
| 553 | |
| 554 | `POST /d/{sqid}/presence` takes `{client, slide, block}` every 20 s and on |
| 555 | change. **The server stamps the name and the colour** from the `users` |
| 556 | row; a client that sends its own is ignored, or presence becomes a place |
| 557 | to write somebody else's name. Two missed heartbeats and the sweeper |
| 558 | drops it. |
| 559 | |
| 560 | ## The fixtures rule |
| 561 | |
| 562 | `fixtures/ops.mjs` and `core/src/ops.rs` are two implementations of one op |
| 563 | vocabulary (spec §7.2), because the browser writes the document the core |
| 564 | reads. `fixtures/data/*.json` are op batches; `node fixtures/generate.mjs` |
| 565 | runs each through the JS side and writes `vectors/<name>.yjs` (the Y |
| 566 | update) and `vectors/<name>.view.json` (the JS view of it). |
| 567 | `internal/slides/core/vectors_test.go` loads the same bytes through the |
| 568 | core and requires the same view, and also runs the same op batch through |
| 569 | the core's own `Ops` and compares again. `generate.mjs` also runs |
| 570 | `checkDoc` over every vector before it writes one, so a vector that |
| 571 | would not pass the write gate never gets committed in the first place. |
| 572 | |
| 573 | So: **an op changes on both sides or on neither.** Regenerate in the same |
| 574 | commit as the change. Never edit a vector to make a test pass — a vector |
| 575 | that was quietly adjusted leaves the Go test comparing the core against a |
| 576 | JS implementation that no longer exists, and it passes while the two sides |
| 577 | drift. The gate regenerates and diffs. |
| 578 | |
| 579 | It has already caught something real. **`href` is stored as the one-key map |
| 580 | `{"href": url}`, and the ProseMirror marks are named `b`, `i`, `c`, `h`, |
| 581 | `href`** — spec §1 ruling 12, §2.6. y-prosemirror 1.3.7 has no hook to map |
| 582 | mark names to Y attribute names: it writes |
| 583 | `attributes[mark.type.name] = mark.attrs` and reads |
| 584 | `schema.mark(attrName, attrValue)`. So the mark's name has to be the |
| 585 | attribute's name, and a plain-string `href` throws inside `schema.mark` — |
| 586 | and y-prosemirror deletes the `XmlText` when a read throws, which loses |
| 587 | the text and not just the link. Naming the marks after the attributes |
| 588 | makes the mapping the identity and keeps mapping code out of the editor. |
| 589 | The writer is exact; both readers are tolerant, taking any truthy value |
| 590 | for `b`/`i`/`c`/`h` (y-prosemirror writes `{}`) and either the map or a |
| 591 | plain string for `href` (documents written before the ruling). |
| 592 | |
| 593 | ## How the editor is put together |
| 594 | |
| 595 | Read this before changing anything under `fixtures/`. |
| 596 | |
| 597 | The browser is not a second renderer. The stage shows the server's own |
| 598 | HTML for the current slide, fetched from |
| 599 | `GET /d/{sqid}/slides/{id}.html?vp=desktop|phone|thumb`, and the client |
| 600 | binds a ProseMirror `EditorView` into each text block already in it. After |
| 601 | any structural change lands, the slide is re-fetched. Thumbnails come from |
| 602 | the server too. If you find yourself building slide markup in JS, stop. |
| 603 | |
| 604 | Structural edits go through `fixtures/ops.mjs`'s `applyOps` — the same |
| 605 | vocabulary the API takes — inside one Y transaction, and reach the server |
| 606 | as ordinary Yjs updates through the save queue. Undo is a single |
| 607 | `Y.UndoManager` over the four roots (`ydoc.mjs`'s `undoScope`: slides, |
| 608 | meta, assets and scenes) with this client's origins tracked, |
| 609 | driven directly rather than through `yUndoPlugin` (whose view hook |
| 610 | destroys a manager shared by many views the moment the first view goes). |
| 611 | `commit()` calls `stopCapturing()` first, so each batch is its own undo |
| 612 | step. |
| 613 | |
| 614 | `editor-entry.js` is wiring and nothing else; every other module under |
| 615 | `fixtures/` is one concern and is meant to stay under 300 lines — one |
| 616 | does not: `canvas.mjs` (drag, resize and snapping are one concern and |
| 617 | run to about 335), which is noted rather than split. `live-updates.mjs`, |
| 618 | `save-queue.mjs` and `resync-controller.mjs` are Docs' modules copied |
| 619 | verbatim with a header saying so — this is the second implementation, and |
| 620 | extracting them to something shared is slice 4's problem, not yours. |
| 621 | `save-queue.mjs` has since changed here first (its header says how): |
| 622 | one save on the wire at a time, each edit numbered, `flush()` resolving |
| 623 | once every edit made before the call is answered (edits made during it |
| 624 | are not waited for): true if all were saved, false if one was refused; |
| 625 | `ok` said only when nothing is owed, `saving` while an answered save |
| 626 | leaves more queued. Docs has the same queue (#87). |
| 627 | |
| 628 | The bundle is built by hand and committed: |
| 629 | |
| 630 | ```sh |
| 631 | cd fixtures && npm ci && node build-bundles.mjs |
| 632 | ``` |
| 633 | |
| 634 | `assets_embed.go` resolves `editor.<16 hex>.js` out of the embedded |
| 635 | `static/` at package init and **panics unless there is exactly one**, so a |
| 636 | build that stopped emitting one, or a merge that left two, refuses to boot |
| 637 | rather than serving an editor that disagrees with the server. |
| 638 | |
| 639 | ## Traps |
| 640 | |
| 641 | - **Never call `sessions.UserID`.** Under rastrillo/auth the Subject is |
| 642 | the email address, so it answers `(0, false)` and would scope every |
| 643 | owned query to `user_id = 0`. Map the address to the row first. |
| 644 | - **Neither committed wasm is rebuilt for you.** `go:embed` will happily |
| 645 | embed a stale `internal/slides/core/testdata/slides_core.wasm` and the |
| 646 | Go tests will pass against it; the same is true of |
| 647 | `internal/slides/pdfcore/testdata/slides_pdf.wasm`. **The gate |
| 648 | checks both**: on every host it recomputes a hash of each module's |
| 649 | inputs (`scripts/wasm-stamp.sh`) and compares it with the `.stamp` |
| 650 | committed beside the wasm, and on Linux amd64 it also rebuilds and |
| 651 | `cmp`s the bytes. When it fails, run `scripts/build-wasm.sh` or |
| 652 | `scripts/build-pdf-wasm.sh`, copy the module from `core/target` or |
| 653 | `core/pdf/target` into its `testdata/`, and commit the wasm with its |
| 654 | `.stamp`, rather than arguing with it. |
| 655 | - **The core ABI is version 2 and the host's check is exact-match.** Add |
| 656 | or change an export in `core/src/abi.rs` and you bump both |
| 657 | `slides_core_abi_version()` in `core/src/lib.rs` and `abiVersion` in |
| 658 | `internal/slides/core/core.go`, in the same commit, or the host |
| 659 | refuses to instantiate the module — which is the point: it turns |
| 660 | "unknown export" deep inside a request into a refusal at load time. |
| 661 | Version 2 is where `slides_core_check` arrived (codex 3). |
| 662 | - **`Doc::new()` and `Doc::with_client_id()` are banned in the Rust core** |
| 663 | (`clippy.toml`) — both draw entropy this wasm build has no safe source |
| 664 | for. Use `Options::with_guid_and_client_id`. A doc comment alone was got |
| 665 | around more than once, which is why it is a lint. |
| 666 | - **The committed editor bundle is not rebuilt for you either.** Change a |
| 667 | `.mjs` under `fixtures/` and `internal/slides/static/editor.<hash>.js` |
| 668 | is stale until you run `node fixtures/build-bundles.mjs` and commit what |
| 669 | it writes. Nothing builds it at run time and CI does not build it for |
| 670 | you — the gate rebuilds and diffs, which is a check, not a fix. |
| 671 | - **A stale vector passes.** `vectors_test.go` compares the core against |
| 672 | whatever is committed under `fixtures/vectors`, so a vector nobody |
| 673 | regenerated makes it compare the core against a JS implementation that |
| 674 | no longer exists. Run `node fixtures/generate.mjs` in the same commit as |
| 675 | any op change. |
| 676 | - **Exactly one directory under `internal/`.** `rastrillo migration check` |
| 677 | requires it, which is why every package is nested under |
| 678 | `internal/slides/` (`core`, `deck`, `render`, `layout`, `svg`, `fonts`, |
| 679 | `pdfcore`, `present`, `live`) rather than sitting beside it. |
| 680 | - **A job outlives its request, so it cannot hold one.** The export's |
| 681 | sentences — its name, its progress line, every failure it can report — |
| 682 | are resolved from the catalog while the request is still here |
| 683 | (`exportWords`) and carried into the goroutine. `rastrillo.T` reads the |
| 684 | locale off a request; a job that called it would either be holding a |
| 685 | request it must not hold or answering in the wrong language. The same |
| 686 | goes for the context: use the job's, never the request's. |
| 687 | - **A hardcoded English string is a bug.** Every user-visible string is a |
| 688 | key in `internal/slides/locales/en.toml`, resolved through `rastrillo.T` |
| 689 | at render time. Twelve locales are the suite target; this slice ships |
| 690 | `en` and leaves the keys ready. Deck titles and timestamps are data, not |
| 691 | copy, and are correctly not keys. |
| 692 | - **Every screen but the editor works with scripts off** (spec §8) — |
| 693 | including the remote, where each button is a form that POSTs and |
| 694 | redirects back. The editor is the one stated exception, and it says so |
| 695 | in a `<noscript>` that links the viewer. Everywhere else JavaScript is |
| 696 | an enhancement and nothing depends on it. |
| 697 | - **Every user-facing string the bundle shows is still a catalog key.** |
| 698 | It reaches the browser as a `data-text-*` attribute the template |
| 699 | renders from `en.toml`; an English literal in a `.mjs` file is the same |
| 700 | bug it would be in Go. |
| 701 | - **The page's policy loads no `blob:` media.** `ContentSecurityPolicy` |
| 702 | is rastrillo's default bar `style-src` (and a test holds it there), so |
| 703 | `media-src` falls back to `'self'` and a `<video>` given an object URL |
| 704 | is refused ("rejected by URL safety check"). A clip's poster is drawn |
| 705 | from the video's staged bytes, which `GET /d/{sqid}/uploads/{ref}` |
| 706 | serves back to whoever staged them (`internal/slides/clips.go`). |
| 707 | - **`cargo fmt --check` covers `core/`.** It was not in the gate until |
| 708 | 2026-09-07 and three files had drifted by then; they were reformatted in |
| 709 | the same commit that added the check. |
| 710 | |
| 711 | ## Rules the family holds hard |
| 712 | |
| 713 | - Every query touching user-owned rows goes through the seams above — |
| 714 | reads and writes, transactions included. |
| 715 | - Never bind a request body onto a GORM model: explicit `map[string]any` |
| 716 | plus a `.Select` allowlist. |
| 717 | - Migrations apply at boot, once each, and are never re-run or reversed. |
| 718 | Change `models.go`, then run `rastrillo migration generate` and *read |
| 719 | the SQL* — it may be a full table rebuild rather than an `ADD COLUMN`. |
| 720 | Never edit a migration that has shipped. Renames are hand-written |
| 721 | (`rastrillo migration new rename_x`), because a rename is |
| 722 | indistinguishable from a drop plus an add. |
| 723 | - Every state-changing route is a POST behind `csrf.Protect`. Destructive |
| 724 | actions get their own confirm-page URL, never a modal. |
| 725 | - Markup is the bare `rst-*` attribute grammar (`<a rst-btn="primary">`), |
| 726 | never `class="rst-*"`. This app's own attributes are `slides-*`. |
| 727 | - WCAG 2.2 AA with no exemptions: 24×24 targets, 320px reflow, colour |
| 728 | never the only carrier of state, `alt` on every image. |
| 729 | - **Spacing is the scale's** (Paul, 2026-11-22: no ad-hoc spacing). |
| 730 | A page's blocks sit in Fiesta's `rst-stack` (layout.html's `<main |
| 731 | rst-page rst-stack>`, and a box, section or form with blocks of its |
| 732 | own), with `rst-section` where a section opens and `rst-actions` for |
| 733 | a row of buttons; never hand margins between blocks. Every other |
| 734 | margin, padding and gap is `var(--rst-sp-N)`, or says why not with |
| 735 | `/* spacing-allow: why */`: the slide itself (slides.css: the deck's |
| 736 | cqw, percentages and its type's em, not the page's), what is drawn |
| 737 | over the stage, estilo's inspector and menu geometry, the presenter's |
| 738 | notes in their own em. `make spacing` (in `make ci`) checks static/; |
| 739 | `TestEveryStylesheetIsOnTheSpacingScale` checks the templates' |
| 740 | `<style>` blocks, which the tool does not read. `make browser` runs |
| 741 | Fiesta's rhythm audit (`TestEveryScreenKeepsTheRhythm`) over every |
| 742 | screen at 1440 and 390px, reading around the slide (`rhythmCanvas`) |
| 743 | and nothing else; a new screen joins its list. A hidden input between |
| 744 | two of a stack's blocks hides the first from the stack's rule: write |
| 745 | hidden inputs first. A stack's `position: fixed` or `absolute` child |
| 746 | still takes its margin: zero it. |
| 747 | - `CGO_ENABLED=0` throughout. The stack is cgo-free by design and the |
| 748 | binary that ships is `linux/arm64`. |
| 749 | - A save is a keepalive request, at most 32KiB, and gzipped from 1KB |
| 750 | (`fixtures/save-queue.mjs`; found in Docs, #94, 2026-10-26, and the |
| 751 | same code here). While a link the page opened is waiting for its |
| 752 | answer, WebKit refuses every ordinary `fetch`, XHR and Blob read the |
| 753 | page starts, at once and with nothing sent, and the page stays editable |
| 754 | all the while; keepalive requests and `sendBeacon` still go. Keepalive |
| 755 | requests and beacons share one 64KiB quota, so the unload beacon never |
| 756 | repeats a keepalive save already on the wire. WebKit never settles a |
| 757 | keepalive save answered while its page is in the back/forward cache, |
| 758 | so the queue sends again on `pageshow` and gives up on a save left |
| 759 | unanswered. A save refused with no answer is "retrying" only if a probe |
| 760 | of `/healthz` cannot reach the server either, and quiet retries back off |
| 761 | to 4s. Compress through `CompressionStream`'s writer, never a Blob. A |
| 762 | gzipped save answered 400, 415 or 422 (a server that does not gunzip: a |
| 763 | rollback, or a hop that strips `Content-Encoding`) is sent again |
| 764 | uncompressed, and the page stops gzipping, before the queue, which drops |
| 765 | a batch a 4xx answers, sees it. Corrupt gzip is a 400 here as in Docs, |
| 766 | not the 422 of an update the core refuses. |
| 767 | - Slides drains its streams on SIGTERM (`internal/slides/drain.go`, |
| 768 | `cmd/slides/main.go`). `net/http`'s graceful shutdown cancels no |
| 769 | request, so an open editor or projector held it for rastrillo's whole |
| 770 | ten seconds and the process exited 1, as Docs' did on 2026-10-26. |
| 771 | `rastrillo.Serve` owns the signal and has no hook, so Slides registers |
| 772 | its own. A stream opened while stopping gets a clean end with a |
| 773 | `retry:` delay, never an error status, which would end a projector's |
| 774 | EventSource for good. Any new long-lived handler must also return on |
| 775 | `a.draining.done()`. |
| 776 | |
| 777 | ## Team mode (roster, `SLIDES_TEAM_*`) |
| 778 | |
| 779 | Home `implementation/team-members.md` Part B and |
| 780 | `implementation/teammode-package.md` §7.1 ("Slides. As Sheets."), on the |
| 781 | shared `home/teammode` package; Sheets main `8e28205` is the reference |
| 782 | port. With the five `SLIDES_TEAM_*` variables set (`_ID`, |
| 783 | `_DIRECTORY_ORIGIN`, `_PROVISIONING_BASE64`, `_OPERATOR_KEYS_BASE64`, |
| 784 | `_ROSTER_TOKEN`; all or none, and only beside `SLIDES_HOME_*`), Home's |
| 785 | roster decides standing on every request and `SLIDES_ALLOWED_ADDRESSES` |
| 786 | becomes optional: if set it only admits local sign-in, empty it admits |
| 787 | nobody locally, and it gives nobody standing. Without them nothing in |
| 788 | `team_*.go` runs and every rule above stands; the one difference on a |
| 789 | non-team instance is `GET /api/team` answering `{"team_mode":false}` |
| 790 | (Paul's ruling on Sheets #52). |
| 791 | |
| 792 | - **Configuration, the marker, the runtime and the probe are |
| 793 | `home/teammode`'s** (`team_config.go`): `teamSettings` verifies the |
| 794 | record against the Home credentials `newApp` decoded, before anything |
| 795 | migrates; `teamBootSchema` reads `slides_team_required` first and |
| 796 | refuses an activated database without the same binding; `teamBoot` |
| 797 | merges teammode's `slides_team` set and this repo's |
| 798 | `slides_team_home` (`teamstate/`) after Slides' and linkstore's; |
| 799 | `configureTeam` opens the runtime with the census over |
| 800 | `home_identity_links` and `slides_team_home_users`. Do not grow a |
| 801 | private copy back. A team-mode database stays in team mode: do not |
| 802 | "fix" a refused boot by deleting the marker (its triggers refuse that |
| 803 | anyway). |
| 804 | - **Standing is the roster's, per request** (`team_access.go`): |
| 805 | `currentUser` hands team mode to `teamCurrentUser`, which resolves the |
| 806 | session to its user and Home subject and attaches `teammode.Access` as |
| 807 | `User.team` (never a column). That replaces the allowlist recheck: |
| 808 | Member is the team rung (own decks, team-rung decks, ownership of |
| 809 | their own); NotMember reaches grants only; Unknown reaches grants with |
| 810 | a partial list and answers a retryable 503 for anything else |
| 811 | (`deckFor`, `ownedDeckFor`, create). Removed people keep their session, |
| 812 | as in Docs and Sheets; a session whose identity cannot be read is a |
| 813 | 503, never a sign-out. The bearer middleware does the same for an |
| 814 | agent's operator. |
| 815 | - **Home-only members** (`team_home_only.go`, `teamstate/`): connect's |
| 816 | `Admit`/`Unlinked`/`HomeOnly` hooks, set only in team mode (connect |
| 817 | wants all three or none). A roster Member with no account here is asked |
| 818 | to choose first (connect's choose page, `/account/home/choose`, drawn by |
| 819 | `home_link.html`): "Connect my existing account" goes to the email-only |
| 820 | door, "I'm new here" gives them an addressless `users` row |
| 821 | (`email NULL`), and the sample deck. Identity, never standing. They are shown as "Oficina |
| 822 | account …xxxx" wherever an address would be (`homeOnlyLabel`). |
| 823 | - **Every write is guarded inside its own transaction** |
| 824 | (`team_guard.go`): `deckFor`/`ownedDeckFor` decide whether a write may |
| 825 | start, `teammode.Guard` re-checks standing before and after it in the |
| 826 | writer transaction. `applyOps`, `editDeck`, `appendUpdate` and |
| 827 | `createDeckRow` take a `writeGuard`; app writes go through |
| 828 | `a.guarded`. `deckGuard` for a write any reader makes (a grant carries |
| 829 | it without standing), `memberGuard` for create and every owner action. |
| 830 | Refusals answer through `guardRefused`. Nil outside team mode, and the |
| 831 | write is then its old path exactly. |
| 832 | `TestTeamEveryWriteRouteRefusesALapseBeforeCommit` lists every write |
| 833 | route and reads the database back; add yours to it. |
| 834 | - **Streams and talks re-decide.** The deck stream re-asks before every |
| 835 | delivery and when a Member lease runs out (`teamStreamAccess`). A |
| 836 | presentation stands on its presenter's reach (`team_present.go`): every |
| 837 | `/p/…` request and every projector or follower delivery re-decides; a |
| 838 | presenter who is gone ends the talk (as offboarding does), one whose |
| 839 | standing is unknown gets a 503 on pages and the talk waits. While |
| 840 | standing is unknown both streams are **held**, not ended: open, |
| 841 | delivering nothing but comment pings, re-asked at `streamHoldRetry` |
| 842 | (the roster's `RetryAfter`), and caught up when standing returns — a |
| 843 | projector's EventSource fails for good on a 503, so `presentStream` |
| 844 | opens under Unknown too. Without a Member lease only a grant holds — |
| 845 | asked after the reach query, because `State` latches. |
| 846 | - **Ownership and orphans** (`team_owner.go`; Paul, 2026-10-30, #33): an |
| 847 | owner owns their deck only while Member. On an orphan — a team-rung |
| 848 | deck whose owner the roster says is gone — a roster owner may share it |
| 849 | and change its title and theme, and may not delete it or change its |
| 850 | rung. One predicate per power (`mayShareDeck`, `mayRetitleDeck`, |
| 851 | `mayChangeRung`, `mayDeleteDeck`), passed to `ownedDeckFor`: an owner |
| 852 | screen asks for the one power it needs. A departed member's private |
| 853 | deck is nobody's orphan. |
| 854 | - **Lists under Unknown** (Paul, 2026-10-28): the deck list shows the |
| 855 | grants with a notice (`teamPartial`, asked after listing, never for |
| 856 | NotMember); the dashboard feed and the API's JSON list are unavailable |
| 857 | instead, since neither can carry the notice. |
| 858 | - **No object store on team instances.** When one is bound, presigned |
| 859 | GETs are capped at the standing they were minted on (`presignTTLFor`). |
| 860 | |
| 861 | ## Fonts: never a flash (Paul, 2026-10-26) |
| 862 | |
| 863 | **"No flashing, ever!"** Slide text is never painted in one face and |
| 864 | then another; a visible gap of invisible text counts too, and so does a |
| 865 | layout that moves after the slide is shown. This is Docs' design |
| 866 | (`polish-audit/fonts/NO-FOUT.md`, oficina/docs `fontgate.go` and |
| 867 | `fixtures/font-session.mjs`, nine review rounds) on Slides' model; read |
| 868 | Docs' AGENTS.md fonts section for the reasoning behind each rule. |
| 869 | |
| 870 | - **No stylesheet declares a web face.** `slides.css` used to, with |
| 871 | `font-display: swap`, which is a flash by definition. The three |
| 872 | Liberation families exist on a page only once the font gate has loaded |
| 873 | all four styles of one and added them to `document.fonts` together |
| 874 | (`fixtures/font-session.mjs`). Every stack names its system faces |
| 875 | after the Liberation name, so a page with no script, or whose gate |
| 876 | never arrived, is in those system faces for the whole visit: nothing |
| 877 | held, fetched for the text, or swapped. |
| 878 | - **Families, not faces.** `render.FamiliesUsed` is the deck's: every |
| 879 | family its heading and body stacks name (the theme's, or `meta.fonts` |
| 880 | where it passes `safeFontStack`), anywhere in the stack, and Mono if |
| 881 | any slide carries code (a code block, or a code mark in any block's |
| 882 | text or table cell). `fixtures/font-families.mjs` is the browser's |
| 883 | copy, held to the same answers by `fixtures/vectors/font-families.json` |
| 884 | (both sides read it; hand-written, like Docs' font-stacks.json — a |
| 885 | case changes with the rule on both sides in one commit). Speaker |
| 886 | notes are drawn in the chrome's face and never count. |
| 887 | - **A deck's own fonts** (`meta.fontFiles`) are families too, keyed |
| 888 | `"u:" + css` in the manifest's `uploaded` (left out when there are |
| 889 | none, so an existing deck's manifest is byte for byte what it was). |
| 890 | One is needed when the heading or body stack leads with its css name |
| 891 | (`render.UploadedUsed`; `familiesOfView` returns its key after the |
| 892 | catalog's); one only listed, or named later in a stack, is not |
| 893 | waited for and stays out of `document.fonts`. Each face is fetched |
| 894 | under the page's own base (`/d/{sqid}`, `/s/{token}`, `/p/{session}` |
| 895 | plus `/fonts/{ref}`), in its own `format()`, with a variable face's |
| 896 | weight as its range (`"100 900"`); `FontFace` gets the name unquoted |
| 897 | (it takes it literally). Same preloads, deadline and commit as the |
| 898 | catalog's. In the editor every change is checked on its scratch copy |
| 899 | (`editor-fonts.mjs`'s `familiesAfter`): an uploaded family the |
| 900 | changed deck names — this person's pick, a collaborator's — is |
| 901 | learned from it (`font-session.mjs`'s `learn`, under `/d/{sqid}`) and |
| 902 | the change waits for it like any family it brings in; one the deck |
| 903 | already shows that the tab never learned is committed where it is. |
| 904 | An uploaded family is known by its name and its set of faces: a new |
| 905 | set (a bold added, the family picked again) is learned again, waited |
| 906 | for, and put on in place of the old set in one task; undo and redo |
| 907 | swap sets with the change (`afterHistory`). Readers learn too: the |
| 908 | viewer's in-place paging and `static/present.js` learn the incoming |
| 909 | page's `manifest.uploaded`, and the talk payload carries `uploaded` |
| 910 | for `talk-store.mjs` (`learnUploaded`), so a font the deck takes on |
| 911 | mid-visit is waited for, not fallen back from. |
| 912 | `/d/{sqid}/fonts/{ref}` serves a recorded ref the deck does not list |
| 913 | yet to the person whose library holds it, so a pick can load before |
| 914 | its set_meta lands. A library never gives a family a catalog |
| 915 | family's name or a CSS generic keyword (`library.go`'s |
| 916 | `reservedFontName`): those get the collision suffix. |
| 917 | - **The page** (`fontgate.go`, `layout.html`'s font-head, on the |
| 918 | viewer in every mode, the projector and follow view, and the editor): |
| 919 | in `<head>`, ahead of every stylesheet, one preload per face of every |
| 920 | family the whole deck uses (exact: no more, no fewer, and the gate's |
| 921 | own load uses them), `<meta name="slides-fonts">` with the manifest |
| 922 | (the needed families, every family's faces, the theme stacks), the |
| 923 | hold (`fixtures/fonts-hold.js`, a blocking classic script that sets |
| 924 | `data-slides-fonts="pending"`, which `slides.css` answers by hiding |
| 925 | every slide, with a 6 s fail-safe), and the gate |
| 926 | (`fixtures/fonts-gate.mjs`, a module). The server never renders the |
| 927 | hold. The presenter window (`presenter_window.go`) draws live slides |
| 928 | at 1920×1080, scaled, so it takes the gate like the viewer. The |
| 929 | remote, and the presenter view of a session begun before positions, |
| 930 | still show SVG pictures and notes in the chrome's face, so they carry |
| 931 | no gate and fetch no font. |
| 932 | - **The gate**: waits for the needed families until 2.5 s from |
| 933 | navigation start, commits any family still missing to its system |
| 934 | fallback for the visit (it never joins `document.fonts`, so it cannot |
| 935 | swap in later; `data-slides-fonts-fallback` names it), puts the rest |
| 936 | on, on the editor waits for the editor's first mount (`settled()`) up |
| 937 | to 3.5 s, on the presenter window for the pictures of the slides it |
| 938 | opens on (Now and Next) to decode, up to the same 3.5 s, then shows |
| 939 | the slides once. On the editor it then prefetches |
| 940 | the other families at idle (not with Save-Data or on 2G); |
| 941 | `data-slides-fonts-prefetch="done"` marks the end. |
| 942 | - **After the reveal nothing paints in a family that has not loaded.** |
| 943 | A person's own change — an op batch through `commit()` (theme, font |
| 944 | override, code block, new slide, duplicate…), a code mark typed, |
| 945 | pasted or dropped in a slide's text (`fontGatePlugin`), undo, redo — |
| 946 | that needs a family not in is held before anything changes: the |
| 947 | stage, strip, inspector and Slide menu go `inert`, the status row |
| 948 | under the bar (`[slides-fonts-status]`, `fixtures/font-status.mjs`, a |
| 949 | polite live region with its own fixed-height row) says a font is |
| 950 | loading, and then the change runs once, or is refused after 4 s and |
| 951 | the row says so. Nothing is queued or replayed; a second change during |
| 952 | a wait is refused and said; Backspace, Space and the scrolling keys do |
| 953 | nothing on the page during a wait (WebKit's Backspace went back in |
| 954 | history), and leaving asks first. A wait never begins in an IME |
| 955 | composition. Content from elsewhere is never refused: a collaborator's |
| 956 | update (checked on a scratch copy of the doc before it reaches Yjs, |
| 957 | FIFO, after any local wait, `live-updates.mjs` awaits it), a resync, |
| 958 | every slide the stage installs (`stage.mjs`'s `beforeInstall`: the |
| 959 | server can be ahead of the tab) and the projector's next slide |
| 960 | (`static/present.js`) wait up to 3 s for a new family and commit it |
| 961 | past that. |
| 962 | - **A wait never loses anything, and always lets go.** However a wait |
| 963 | ends — loaded, failed, timed out, or something in it throwing — the |
| 964 | editor comes back and every waiter queued behind it is released in |
| 965 | order, in a `finally` (`fixtures/editor-fonts.mjs`; a refusal that |
| 966 | threw once stalled every collaborator's change after it). And nothing |
| 967 | replaces the views a waiting change belongs to while it waits: a |
| 968 | stage install (`beforeInstall`) and a resync wait for the change, not |
| 969 | the other way round, so a refresh already on its way can no longer |
| 970 | throw away a paste whose font then loads. A resync rebuilds from the |
| 971 | server but carries every local update the server has not acknowledged |
| 972 | onto the rebuilt doc and sends it again; the diverged doc takes a |
| 973 | fresh Yjs client ID first, since Yjs drops an update from a client |
| 974 | whose earlier clocks it never saw (`editor-entry.js`). The carried |
| 975 | updates go into the rebuilt doc before any view of it is mounted, so |
| 976 | the words are never off the slide for a frame (`fixtures/carry.mjs`). |
| 977 | Each update is judged from its own structs and delete ranges — a |
| 978 | delete range counting as taken in part once the rebuilt doc holds its |
| 979 | start, since Yjs deletes up to what it holds and keeps the rest |
| 980 | pending: one of which nothing integrates (written on top of the |
| 981 | refused text) is not posted; of one that partly integrates, only the |
| 982 | part that did is posted, so the server holds what the page shows and |
| 983 | nothing of it pending. Client ids while diverged come from the keeper |
| 984 | (`createKeeper`, driven by the doc's `beforeTransaction`): Yjs |
| 985 | integrates one client's structs in clock order, so one change held |
| 986 | back would strand every later one under its id. A ProseMirror change |
| 987 | takes a fresh id once per 500 ms window (every later ProseMirror |
| 988 | change has its transactions to replay, so it is never stranded); any |
| 989 | other — an undo, a redo, an inspector change — takes one of its own. |
| 990 | A fresh id per change was quadratic over a long divergence and left a |
| 991 | client per keystroke in the deck; `carry` is linear too (clocks read |
| 992 | from the struct store, one running probe copy), and |
| 993 | `carry.test.mjs` holds its growth to linear (4000 changes against |
| 994 | 1000). Local changes made while diverged — typing, a paste, a |
| 995 | delete, a change that waited for its font — are kept as their ProseMirror |
| 996 | transactions too (the one dispatched and every one the plugins |
| 997 | appended: `stage.mjs`'s `bindView` takes a `dispatchTransaction`, and |
| 998 | `editor-entry.js`'s `aroundDispatch` holds them; transactions ySync |
| 999 | makes to mirror Yjs are left alone), because Paul ranks a lost edit |
| 1000 | worse than a flash. When a change's updates cannot integrate — written |
| 1001 | on the refused text, or on an earlier change that could not be carried |
| 1002 | as its own updates — it is replayed: its steps mapped through the one |
| 1003 | span where the rebuilt text differs from what it was made on (the two |
| 1004 | ends moved past any overlap, as prosemirror-view's `findDiff` does), |
| 1005 | written back with y-prosemirror in a `carried` transaction, and that |
| 1006 | update posted. The carried changes undo in the steps they were made |
| 1007 | in: the keeper stamps each, and the undo manager stops capturing where |
| 1008 | two were made further apart than its 500 ms window. A multi-step |
| 1009 | change is mapped prosemirror-collab's way (each step through the |
| 1010 | inverses of those before it, the span, and their replayed forms), not |
| 1011 | every step through the one span map. An undo or a redo made while |
| 1012 | diverged is the undo manager's Yjs change, kept with a replay derived |
| 1013 | from ySync's mirror of it (`carry.mjs`'s `derivedStep`: one step from |
| 1014 | the mirror's before and after, set in `aroundDispatch` and taken by the |
| 1015 | next `keep` in the same Yjs transaction), so the resync makes it again |
| 1016 | as the person saw it — taking text away or putting it back — whatever |
| 1017 | ids the change it undoes was replayed under; that includes bringing |
| 1018 | the refused text back when an undo or a redo put it back on screen. |
| 1019 | Where ProseMirror |
| 1020 | refuses a mapped step (typing into a paragraph the refused change |
| 1021 | made) the change falls back to what of its own updates integrates — |
| 1022 | nothing, there — and the rest are carried as before: nothing posted |
| 1023 | for it, the save line saying failed, the clipboard as it was. |
| 1024 | `carry.test.mjs`, `TestFontEnginesAWaitingPasteSurvivesARefusedSave` |
| 1025 | (Claude Fable's eleven paste cases) and |
| 1026 | `TestEnginesEveryChangeWhileARefusalIsPendingIsKept` (mixed edits, |
| 1027 | undo, a change that cannot be kept in the middle), both in Chromium |
| 1028 | and WebKit (`fixtures/engines/replay.mjs`, `diverged.mjs`), and |
| 1029 | `TestEnginesUndoAndRedoWhileARefusalIsPendingEndAsSeen` (Claude |
| 1030 | Fable's seventeen undo and redo cases, `undo.mjs`) hold it. **What is |
| 1031 | still not kept:** a change whose replay cannot be made (the |
| 1032 | structural case above); a change made elsewhere in the same 500 ms id |
| 1033 | window as one on the refused text, when its own replay cannot be made |
| 1034 | either; an undo or a redo that ySync mirrors in more than one view |
| 1035 | (one across blocks), which goes as its own updates and is kept only |
| 1036 | where they integrate; and a change outside the text views (an |
| 1037 | inspector op) written on the refused text. A tab closed while diverged beacons the kept |
| 1038 | updates with the queue's bytes. Edits |
| 1039 | made between a batch leaving and its refusal arriving are still lost |
| 1040 | with it (same client, after the refused clocks). A slide made |
| 1041 | in an empty deck goes up only once its save is acknowledged |
| 1042 | (`commands.mjs` awaits a `flush()` that is true). A change that could |
| 1043 | no longer be made once its font was in is said as `interrupted`, |
| 1044 | never as a font that failed. |
| 1045 | - **The first reveal is the final layout.** No script measures slide |
| 1046 | text, so the gate holding until the families are on is what makes the |
| 1047 | layout final; on the editor it also holds for the first mount. And |
| 1048 | the editor's stage is served in ProseMirror's own markup |
| 1049 | (`render.Options.Editing`, `render/editing.go`: one element per |
| 1050 | paragraph in stage.mjs's tag, the trailing break in an empty one, |
| 1051 | marks nested and kept open as its serialiser does), with |
| 1052 | `editor.css` giving it, before binding, what the editable node gets |
| 1053 | after (pre-wrap, break-word, contenteditable's `line-break: |
| 1054 | after-white-space`). So an editor that arrives after the reveal binds |
| 1055 | without moving a pixel: `TestFontALateEditorMovesNothing` holds |
| 1056 | markup, layout and pixels equal across a 6 s late mount on generated |
| 1057 | decks carrying every empty and trailing-empty shape in every bound |
| 1058 | type. The empty presence overlay is not drawn (it changed the |
| 1059 | antialiasing of the text under it). A stored phone or both view is |
| 1060 | not applied by an editor that mounts after the slide was shown. |
| 1061 | - **Slides change in place.** A page load hides its slide until the |
| 1062 | gate has confirmed the faces — an empty stage between two slides. So |
| 1063 | the viewer and `?present=1` (`fixtures/viewer-nav.mjs`, in the gate |
| 1064 | bundle) and the projector (`static/present.js`: a watcher's links; follow, |
| 1065 | remote and sessions begun before positions only. The presenter window |
| 1066 | and the slide windows of a positional session are driven by the |
| 1067 | `presenter` bundle instead: `presenter-entry.mjs` with `talk-*.mjs` |
| 1068 | and `presenter-*.mjs`, behind `static/presskeys.js`, a blocking |
| 1069 | script that keeps the keys pressed before the bundle mounts) fetch |
| 1070 | the next page, make its families |
| 1071 | ready, decode its pictures and then swap it in one task, moving the |
| 1072 | address with `pushState`; Back and Forward do the same. The current |
| 1073 | slide stays until the next is complete, never a blank. The links and |
| 1074 | forms are ordinary without a script. Neighbours are prefetched and |
| 1075 | their families loaded at idle. The follow view's 5 s refresh is |
| 1076 | `<noscript>` only. A presenter form whose in-place answer fails |
| 1077 | reloads the page, never posts again (the server may have applied it). |
| 1078 | The projector is latest-state-wins, not a queue of |
| 1079 | every advance: every request for a slide (a watcher's link, the |
| 1080 | presenter's button, a stream message) takes the next number of one |
| 1081 | counter in `present.js`, and an answer is applied only while its |
| 1082 | number is still the newest, so a slow old answer changes nothing — |
| 1083 | not the slide, the counter or a blackout. After a change, focus stays |
| 1084 | on the control that made it (the same pager link or button), or goes |
| 1085 | to the slide when that control is gone, and "Slide N of M: title" |
| 1086 | (the page's `data-announce`) is said through a polite `role=status` |
| 1087 | region that is in the page from the start (`[slides-announce]`). |
| 1088 | - **Leaving a page lets go of its streams** (Docs #86, dadf9c1). |
| 1089 | Chrome and WebKit keep left pages in the back/forward cache; each one |
| 1090 | held its EventSource, and after five the next page stalled on |
| 1091 | HTTP/1.1's six connections. `live-updates.mjs`'s `pageLifecycle` |
| 1092 | (Docs' copy) and `present.js` close every stream on `pagehide`, open |
| 1093 | none while away, and on a `pageshow` from the cache reopen on the next |
| 1094 | task (WebKit fails one opened inside it) and catch up. The font and |
| 1095 | viewer prefetches stop too. `TestLeavingAPageLetsGoOfItsStream` runs |
| 1096 | the editor, projector, follow view, presenter and remote in Chromium |
| 1097 | with its cache on (`fixtures/engines/leaving.mjs`) and in WKWebView |
| 1098 | (`leaving-webkit.swift`, built with swiftc). |
| 1099 | - **The files**: `static/fonts/*.woff2` are Docs' lossless woff2 of the |
| 1100 | same TTFs `fonts/files/` holds for the engine and the PDF (decoded, |
| 1101 | only `head`'s checksum and flag bit 11 differ, as WOFF2 defines); |
| 1102 | `TestServedWebFacesAreTheseFaces` holds each header to its TTF. The |
| 1103 | TTFs in `static/fonts/` stay served for pages cached before this. |
| 1104 | - **Tests.** Node: `font-session.test.mjs`, `font-families.test.mjs`, |
| 1105 | `font-uploaded.test.mjs`, `editor-fonts.test.mjs` (in the gate). Go: `fontgate_test.go` (which pages carry the gate, |
| 1106 | exact preloads), `fonts_test.go`. Browser |
| 1107 | (`go test -tags browser -run Font ./internal/slidestest/`), through |
| 1108 | the production serving stack with font files slowed or refused: a DOM |
| 1109 | probe on every frame and DOM change fails on slide text visible in a |
| 1110 | face that is in the page but not loaded, a run seen in two faces, a |
| 1111 | slide whose text vanished after it was shown, and a layout that |
| 1112 | changed after the first reveal; `TestFontEveryInputPathWaitsForItsFamily` |
| 1113 | is the table of input paths; `TestFontTheGateCoversEveryFaceADeckUses` |
| 1114 | runs decks from `fixtures/generate-random-decks.mjs`, which walks the |
| 1115 | op vocabulary, the text schema's marks and the server's themes and |
| 1116 | stacks and fails unless every one appeared, and every empty and |
| 1117 | trailing-empty text shape in every type the editor binds and in table |
| 1118 | cells. **WebKit too:** `TestFontEnginesFirstRevealIsTheFinalLayout`, |
| 1119 | `TestFontEnginesSlidesChangeWithoutAGap` and |
| 1120 | `TestFontEnginesAWaitKeepsThePage` drive Chromium (the full browser, |
| 1121 | not the headless shell, which re-rasterises some glyphs) and WebKit through |
| 1122 | Playwright (`fixtures/engines`; `npm ci` and `npx playwright install |
| 1123 | chromium webkit` there once), comparing the slide's pixels capture by |
| 1124 | capture, with two controls that flash on purpose and must be caught. |
| 1125 | `races_browser_test.go` holds Astra's second-round interleavings on |
| 1126 | #27 (a resync during a waiting paste, a first slide through a retried |
| 1127 | save, stale projector answers, focus and announcements). |
| 1128 | None of the browser checks is in the gate: run them when you touch a |
| 1129 | slide surface, `slides.css`, `editor.css` or anything under |
| 1130 | `fixtures/` that reaches the stage. |
| 1131 | |
| 1132 | **Pushing a branch that adds fonts:** the hub may drop a chunked |
| 1133 | receive-pack and answer 200 with an empty body, which git reports as |
| 1134 | "unexpected disconnect while reading sideband packet". Push with |
| 1135 | `git -c http.postBuffer=157286400 push` so the pack goes out with a |
| 1136 | length (Docs hit it). |
| 1137 | |
| 1138 | ## Running it locally |
| 1139 | |
| 1140 | `./scripts/run-dev.sh` builds and runs the app on `localhost:8091` |
| 1141 | (`$SLIDES_DEV_PORT` to move it) against a scratch database under `$TMPDIR` |
| 1142 | that starts empty every run. Sign in with any address; the magic link is |
| 1143 | logged to the terminal instead of being mailed, and it is a real link |
| 1144 | through the real flow. |
| 1145 | |
| 1146 | Development mode is the only place four settings default — a fixed public |
| 1147 | instance key, mail to the terminal, an allowlist that admits everyone, and |
| 1148 | a directory-backed object store — and it can only be selected by the `-env |
| 1149 | development` flag. `$SLIDES_ENV` cannot reach it, deliberately: platform |
| 1150 | config *is* environment variables, so a stray `SLIDES_ENV=development` |
| 1151 | beside the real ones would otherwise be a production-reachable path to a |
| 1152 | public instance key and to every magic link landing in the instance log. |
| 1153 | Anywhere but development, a missing `SLIDES_ORIGIN`, |
| 1154 | `SLIDES_INSTANCE_KEY`, `SLIDES_SMTP_*` or `SLIDES_ALLOWED_ADDRESSES` is a |
| 1155 | startup refusal rather than a default — except the allowlist in team |
| 1156 | mode, where it is optional and empty admits nobody locally. |
| 1157 | |
| 1158 | ## The gate |
| 1159 | |
| 1160 | `.amadan/ci.d/10-gate` is the only CI this repo has, it runs on every push |
| 1161 | to the amadan remote, and it is the same script you run locally: |
| 1162 | |
| 1163 | ```sh |
| 1164 | ./.amadan/ci.d/10-gate |
| 1165 | ``` |
| 1166 | |
| 1167 | It does rustfmt, clippy with the disallowed-methods lint, the wasm build, |
| 1168 | the `cmp` against the committed artifact, the Rust tests; then the JS half |
| 1169 | — `npm ci`, `node --test`, the vectors regenerated and the bundle rebuilt |
| 1170 | and both diffed against what is committed; then `make ci` (vet, gofmt, Go |
| 1171 | tests, migration check). `make ci` alone is the fast loop between edits; |
| 1172 | the full gate is what you run before pushing. |
| 1173 | |
| 1174 | Since slice 2 it needs Node 20+ and `npm`, and `npm ci` wants the registry |
| 1175 | reachable while it runs — the one part of this gate that is not offline |
| 1176 | once its caches are warm. `.amadan/README.md` says why that trade is worth |
| 1177 | making, what each step catches, and the runner's own two traps. In a |
| 1178 | sandbox, point `NPM_CACHE` somewhere writable or npm fails on its cache |
| 1179 | rather than on the install. |
| 1180 | |
| 1181 | ## Deploying |
| 1182 | |
| 1183 | One static binary, stamped: `make release` (refuses an empty version or a |
| 1184 | dirty tree — a `-dirty` stamp names a commit plus changes nobody can name, |
| 1185 | so two different binaries can carry the same string). Then `carlos deploy |
| 1186 | --app slides --account oficina`, with `carlos store create` for the object |
| 1187 | store and `carlos domains attach slides.oficina.works`. |
| 1188 | `SLIDES_INSTANCE_KEY` and `SLIDES_SMTP_PASS` go in via `carlos secrets`, |
| 1189 | the rest via `carlos env`, mirroring Docs' set (spec §6.3). |
| 1190 | |
| 1191 | **Mail submission.** Ship every build with `--mail submit`: it declares |
| 1192 | that the build sends through CARLOS mail submission (`mail.FromCarlos`, |
| 1193 | `newMailer` in `cmd/slides`, From `$CARLOS_MAIL_FROM`). Until `carlos |
| 1194 | email submission on --app slides` runs Slides keeps sending over SMTP |
| 1195 | (`SLIDES_SMTP_*`, else `CARLOS_SMTP_*`, per variable); after it the agent sets |
| 1196 | `CARLOS_MAIL=submit` and Slides holds no SMTP credential, and every |
| 1197 | instance must run a build shipped with the flag. `carlos deploy` has no |
| 1198 | `--mail` flag yet (carlos main 9eec0236), so until it does use `carlos |
| 1199 | ship --app slides --account oficina --mail submit <binary>` and then |
| 1200 | `carlos promote --app slides --account oficina <version>` (or `carlos |
| 1201 | deploy --mail submit` once that ships). |
| 1202 | |
| 1203 | Verify against `x-carlos-version` on the real host or let `carlos deploy` |
| 1204 | watch the URL. `carlos channels` reports which release a channel *points |
| 1205 | at*, which is not the question of what the box is *serving* — adoption runs |
| 1206 | on a timer and the two can disagree for up to an hour, with nothing saying |
| 1207 | "not live yet". |
| 1208 | |
| 1209 | ## Working through amadan |
| 1210 | |
| 1211 | This repo is hosted on an amadan hub, not GitHub: no `gh`, no pull request, |
| 1212 | no GitHub Actions. Post as the agent account (`<name>~<operator keymail>`), |
| 1213 | never as Paul. Work happens on a worktree branch and reaches `main` only by |
| 1214 | squash merge, after review and with the gate green — `amadan ci status |
| 1215 | -branch <n>` exit 0 is the merge gate; exit 2 is pending and exit 3 means |
| 1216 | nothing ran, and neither is green. |
| 1217 | |
| 1218 | **Every branch gets a discussion, opened before the merge, and it is the |
| 1219 | review record.** A squash merge flattens the history that carried the |
| 1220 | branch's reasoning; the discussion is where that survives. If it does not |
| 1221 | exist before the merge, the reasoning is not scattered, it is gone. |
| 1222 | |
| 1223 | ## UX conventions (seeded from profile: considered) |
| 1224 | |
| 1225 | Accessible by construction, progressively enhanced, and never dependent on |
| 1226 | JavaScript to be usable. |
| 1227 | |
| 1228 | - [x] Icons — lucide, inline — `internal/slides/icons` |
| 1229 | - [ ] Screen flow — one job per screen — a link, then a page for that action alone, then a confirmation; never two ways to start work side by side |
| 1230 | - [x] Fields — label, hint, help and error in one envelope, wired with aria-describedby — `ui/field, ui/field-select, ui/field-text` |
| 1231 | - [x] Destructive actions — their own confirm-page URL, never a modal — `ui/confirm-form` |
| 1232 | - [x] State — never colour alone — always a text label too — `ui/status-pill, ui/badge` |
| 1233 | - [ ] Dates — relative, with the absolute date in a title attribute |
| 1234 | - [ ] Errors — server-rendered beside the field, in plain language |
| 1235 | - [x] Empty states — say what the screen is for, not just that it is empty — `ui/empty-state` |
| 1236 | |
| 1237 | `[x]` is enforced by a vendored component: use it, do not hand-roll an |
| 1238 | equivalent. `[ ]` is guidance to apply by hand. A convention absent from |
| 1239 | this list is one rastrillo has no opinion about. |
| 1240 | |
| 1241 | Edit any line. **This file is the source of truth, not the profile name.** |
| 1242 | Nothing re-reads the profile, so changing a line here changes what the app |
| 1243 | does, and a convention deleted from this file is not one to reinstate. |
| 1244 | |
| 1245 | ## Work in a worktree, and catch main up first |
| 1246 | |
| 1247 | Take a worktree for the work. Do not work in the shared checkout. |
| 1248 | |
| 1249 | git -C <repo> fetch origin |
| 1250 | git -C <repo> worktree add ../<repo>-<task> -b <branch> origin/main |
| 1251 | |
| 1252 | Both halves matter, for different reasons. |
| 1253 | |
| 1254 | **The worktree**, because several sessions share this machine and some |
| 1255 | share this repository, and a checkout has one HEAD, one index and one |
| 1256 | working tree between all of them. A branch switch under somebody else's |
| 1257 | uncommitted work destroys it with nothing on screen to say so, and two |
| 1258 | sessions editing the same paths disagree quietly instead of conflicting |
| 1259 | loudly. A worktree gives the work its own HEAD and its own files, and |
| 1260 | costs a directory. |
| 1261 | |
| 1262 | **From `origin/main`, after a fetch** — not from whatever the checkout |
| 1263 | happens to be sitting on. A branch cut from a stale main is a merge |
| 1264 | conflict scheduled for later, against files somebody else has renamed in |
| 1265 | the meantime. A branch cut from another task's branch is worse: it |
| 1266 | carries that task's commits into yours, where they are reviewed as |
| 1267 | though you wrote them, and the two can only be separated by hand. |
| 1268 | |
| 1269 | Remove it when the work has landed — `git worktree remove` — so that |
| 1270 | `git worktree list` keeps saying something true. |
| 1271 | |
| 1272 | Written down because of 2026-09-17, in `meet`. The shared checkout was |
| 1273 | sitting on one task's branch while holding a *different* task's feature |
| 1274 | uncommitted on disk — some four hundred lines, a new migration among |
| 1275 | them — put there by a session nobody else knew was working in that tree. |
| 1276 | Two other sessions were meanwhile coordinating over the same checkout by |
| 1277 | asking each other not to touch it, which is the arrangement a worktree |
| 1278 | makes unnecessary. Nothing was lost. Nothing about the arrangement would |
| 1279 | have said so if it had been, and by then the same feature existed twice, |
| 1280 | once on each side of a rename, because the two sessions had branched |
| 1281 | from different starting points. |
| 1282 | |
| 1283 | ## Steps, the talk and the presenter's position |
| 1284 | |
| 1285 | - **The document** says what arrives and what is in the talk: a block's |
| 1286 | `step` (a number; 1.5 sits between 1 and 2; none means there when the |
| 1287 | slide is) and, on a list, `items: each`; a slide's `talk` (`full` |
| 1288 | shows only in the full version, `parked` is left out of the talk); the |
| 1289 | deck meta's `arrive`. Core, fixtures and Go move together, with shared |
| 1290 | vectors. In `deck`: `presses.go` (`Presses`, `ArrivalOf`, `NoteParts`) |
| 1291 | and `talk.go` (`TalkOrder`, `Position`, `Advance`, `SettleNear`, |
| 1292 | `ForReaders`); the JS twins are `fixtures/presses.mjs` and `moves.mjs`. |
| 1293 | - **Readers.** `ForReaders()` is called at each reader boundary, so a |
| 1294 | parked slide reaches no share, follow or presenting reader. `/d/` and |
| 1295 | the API stay complete. |
| 1296 | - **Presenting** keeps an absolute position on `Presentation` (`SlideID`, |
| 1297 | `Step`, `Mode`, `Seq`, `Positional`, `TimerAt`). A press carries an id, |
| 1298 | and each window a link id, each with a rising counter |
| 1299 | (`presentation_presses`, `presentation_links`), so a repeated or stale |
| 1300 | press is answered, never applied twice. `POST /p/{session}/pair` pairs |
| 1301 | a phone; `GET /p/{session}/talk` reads the talk's order. |
| 1302 | - **The editor** has the Appears row and the box-menu rows, press |
| 1303 | numerals, a play-through control, the strip's count, dashed outline |
| 1304 | and slim bar, the talk toggles, and Deck settings' "How things arrive". |
| 1305 | |