# Scenes and clips — design

Design, 2026-11-23, by Claude Opus 5.5 from conversation with Paul the
same day. Draft 2 after a builder check (§8). Approved by Paul 2026-11-24 ("Go ahead"). Builds on the editor-tidy design §9 (the
order of slices) and the steps slice (presses, the presenter window).

## 0. Intent

The HalfStack Vienna talk explained itself with moving pictures: one
small world (the corporate district, Paul's garden, the buildings he
owns) shown from slide to slide, changing a little with each press, and
short screen recordings of apps in use. Slides could not do either, so
the talk ran on a custom deck. This slice lets a deck carry both.

**Success** is that the HalfStack world can be a scene in a Slides deck:
written by an agent, its words and pieces adjustable by Paul in the
editor, carried from slide to slide as he presses, and shown as a still
picture wherever code can't run.

### 0.1 Goals

1. A **scene** is code (HTML, CSS, JavaScript, WebGL) that belongs to a
   deck and draws named **states**.
2. Any slide can show a scene and walk it through a range of its states,
   one per press.
3. When the next slide shows the same scene in the same place, the scene
   **carries on**: it stays on screen and moves to the new state.
4. A scene runs **sealed**: no network, no cookies, no way into Slides or
   the person's account.
5. Every state has a **still picture**, used wherever the scene doesn't
   run, and a text **description** for assistive technology.
6. Paul can change a scene by asking an agent, or by hand in the editor:
   its words, its data, which states a slide shows, and its code.
7. A **clip** is a short video uploaded to a deck, played on a press,
   looped or played once.

### 0.2 Non-goals

- Dragging a scene's pieces on the slide (the data table covers it).
- Scenes that talk to the network, play sound, or read the camera.
- Server-side rendering of stills (no headless browser on our side).
- A separate origin for scenes (approach B, possible later).
- Editing or trimming video; streaming; captions files (later).

### 0.3 Anti-goals

- **A scene that can reach anything.** A scene that reads a cookie, calls
  the network or touches the page around it is a failure even if it
  draws beautifully.
- **A blank where a scene should be.** The PDF, a thumbnail, the phone,
  the presenter's Next preview, reduced motion and scripts-off all show
  the state's still.
- **A press with no visible answer**, as in the steps slice.
- **A cut between slides that share a scene.** Carrying on is the point.

## 1. Decisions

| # | Decision | Whose |
|---|---|---|
| C1 | A scene is code an agent writes, run sealed, told only its state, size, words, data and whether to reduce motion. Slides keeps the presses. | Paul (editor-tidy §9) |
| C2 | Stored as a fixed bundle with a named author. | Paul (§9) |
| C3 | A still picture per state, used by the PDF, thumbnails, phone view and checks. | Paul (§9) |
| C4 | A scene can appear on several slides and carries on between them. | Paul, 23 Nov |
| C5 | Changed by asking an agent, and by hand in the editor. | Paul, 23 Nov |
| C6 | Approach A: a sealed frame on the same site; stills made by whoever writes the scene. | Paul, 23 Nov |
| C7 | Editing by hand has three layers: words and states in the slide's card, data as a table, code in a panel with a live preview. | Paul ("Seems good") |
| C8 | States are named and absolute, like positions. | This design |
| C9 | A scene's words and data live in the deck, not in its code. | This design |
| C10 | Clips are stored like pictures; their still is their first frame, captured in the uploader's browser. | This design |

## 2. The document

**Scenes** are a deck-level map, `scenes`, keyed by scene id:

- `name`: shown in the editor.
- `author`: the agent or person who wrote the current code.
- `code`: the ref of a stored bundle, one HTML document (≤ 2 MiB) holding
  all its script and style inline.
- `states`: an ordered list of `{id, name, description}`. `id` is stable;
  `name` shows in the editor; `description` is the text assistive
  technology reads for that state.
- `words`: a map of key → text, the scene's labels.
- `data`: one JSON value (≤ 2 MiB), the scene's model. For the world:
  its pieces, and a per-state table (camera, sky, which pieces show,
  signs, figures, routes), with routes worked out when the data is made,
  never by the scene at run time.
- `version`: a hash the server computes over the code ref, the data and
  the words; it changes with any of them.
- `stills`: a map of state id → `{ref, made}`, where `made` is the
  `version` the still was drawn from.

**A scene block** on a slide: `type: "scene"`, `props: {scene, from,
to}` where `from` and `to` are state ids. The block arrives with the
slide at `from`; each press then moves one state towards `to`. It takes
part in presses exactly as an `each` list does: its own `step` says
which press starts it (absent means right after arrival), and
`deck.Presses` gives it one press per state after `from`.

**Clips**: a picture-like asset of kind video (MP4 or WebM, ≤ 50 MiB)
with a poster still; a `clip` block, `props: {asset, play: "press" |
"loop" | "once"}`. Clips play muted in this slice (screen recordings;
sound needs a gesture in the window that plays it, which the slide
window doesn't get). `play: press` takes one press, like an `each` item;
going back pauses and rewinds it. `loop` and `once` start when the block
arrives.

All of it travels on existing ops plus `add_scene`, `set_scene`,
`remove_scene`, in Rust, JS and Go with vectors, as the fixtures rule
requires.

## 3. Running a scene

- **The frame.** A scene runs in an `<iframe>` whose document comes from
  `/{surface}/scenes/{id}/{code}` with the response header
  `Content-Security-Policy: sandbox allow-scripts; default-src 'none';
  script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:
  blob:; font-src data:; media-src data: blob:`. The sandbox without
  `allow-same-origin` gives it an opaque origin: no cookies, no storage,
  nothing of the page around it, no network, no forms, no popups, no
  navigation of the top window.
- **The conversation.** Slides sends `{type: "init", state, size, words,
  data, reducedMotion, fonts}` and then `{type: "state", state, animate}`;
  the scene answers `{type: "ready"}` once and nothing else matters.
  Messages are checked by source window. A scene that doesn't answer
  within 3 seconds is shown as its still.
- **A small contract**, `docs/scenes.md`, with a 40-line example, is all
  an agent needs to write one.
- **Carrying on.** When the next slide in the talk has a scene block for
  the same scene with the same box, the presenting windows keep the
  frame and send the new state with `animate: true`. Otherwise the new
  slide's frame starts at its `from` state. Going back moves it back.
  Jumps send the target state with `animate: false`. Two blocks of one
  scene on a slide each run a frame; they pair with the next slide's
  blocks of that scene by order (first with first), and only a pair in
  the same box carries on (final review ruling).
- **Where it runs live:** the editor stage (while the block is selected
  or the play-through runs), the slide and presenter windows' Now panel,
  the viewer and share link, the follow link. **Where the still shows:**
  thumbnails, the PDF, the phone view, the presenter's Next preview,
  scripts off, reduced motion (the scene still runs, told to reduce
  motion, but readers who asked for less motion get the still until a
  state settles), and any frame that isn't ready.
- **Next previews the next press**, so its still is the state that press
  arrives at, while thumbnails and the PDF show each scene block at its
  `to` state (final review ruling).

## 4. Stills

- The agent that writes or changes a scene renders each state in its own
  browser and uploads the stills through the API
  (`PUT /api/v1/decks/{sqid}/scenes/{id}/stills/{state}`, PNG or WebP,
  ≤ 4 MiB), recording the version they came from.
- When code, data or words change, the editor marks the scene's stills as
  out of date (a small note on the block's card) and offers to ask the
  deck's agent to redo them. Out-of-date stills are still used rather
  than nothing.
- A clip's still is its first frame, drawn by the uploader's browser onto
  a canvas and uploaded with it.

## 5. Editing by hand

- **The slide's card** for a scene block: the scene's name, *From* and
  *To* state menus, its words as text fields, and the out-of-date note.
- **Data**: a table for a list of objects (rows and columns from the
  data), with a raw JSON view for anything else; changes redraw the
  selected block live.
- **Code**: a panel with the bundle's text and a live preview in the same
  sealed frame. Saving makes a new bundle and marks the stills out of
  date. Paul is the named author of a hand edit.
- Agents use the API ops and the stills route; they see scenes in the
  deck's JSON like everything else.

## 6. Constraints and testing

From AGENTS.md: no flash, scripts-off works, 320px reflow, WCAG 2.2 AA,
every UI string a catalog key through Paul's copy review first. A
scene's own words are deck content, edited by the deck's people, not UI
copy.

Tests, each written first:
- The sandbox: a scene that tries `fetch`, `document.cookie`,
  `localStorage`, `top.location` and a form post gets nothing and
  changes nothing.
- Presses: a scene block's states as presses beside other steps, with
  the same vectors in Go and JS.
- Carrying on: two slides sharing a scene keep one frame and animate; a
  jump lands on the right state; a different box starts fresh.
- Stills everywhere a scene can't run, and out-of-date marking.
- Clips: play on a press, loop, once; the poster in pictures and PDF.
- Existing decks render byte for byte.
- The HalfStack world as the worked example: a scene built from
  `acts/world.py`'s model and drawn with its CSS 3D kit, walked through
  a short deck.

## 7. Order of building

1. The document: scenes, scene and clip blocks, ops, presses, vectors.
2. Serving and the sealed frame, the contract and the example.
3. Running scenes on every surface, carrying on, stills in pictures and
   PDF.
4. The stills API and out-of-date marking.
5. The editor: the card, the data table, the code panel.
6. Clips.
7. The HalfStack world as a scene, in a deck.

## 8. Calls from the builder check

A builder read draft 1 and asked nine questions. None needed Paul; these
are this design's calls, each reversible:

1. **The HalfStack world** becomes one scene, ported from
   `acts/worldsvg.py` and `paintWorld()` (SVG, iso and flat looks as part
   of each state), with `acts/world.py`'s model exported as `data`,
   routes precomputed. Not a CSS 3D rewrite.
2. **Pictures of a range** show the block's `to` state, the slide fully
   built, as steps already do; the PDF stays one page a slide.
3. **A state with no still** shows a plain panel in the scene's box with
   the scene's name and the state's description, drawn by Slides; a
   check in the editor lists scenes missing stills.
4. **The bundle** is a new asset kind, `scene`, through the existing
   upload, register and verify flow (sniffed as one HTML document,
   served only through the sealed route); **stills** go through the
   picture flow, PNG or WebP as pictures already allow. The sealed
   route checks the same capability as pictures on `/d`, `/s` and `/p`;
   the remote shows stills only.
5. **`version`** is computed by the server (above); the stills route
   takes the `version` the agent read and refuses one that isn't
   current. Any change to code, data or words marks stills out of date.
6. **The code panel's preview** posts the unsaved text to a
   preview-only route for signed-in editors, which answers it under the
   same sealed policy. The sealed route sets `frame-ancestors 'self'`,
   so the app's one-policy test gains this exception.
7. **The same box** means the same `box` on canvas slides and the same
   region on flow slides. Carrying on keeps one frame in a layer outside
   the slide's DOM on every scripted surface; with scripts off each
   slide shows its still.
8. **Clips** play muted (§2).
9. **`author`** is filled in by the server from whoever acted;
   `set_scene` patches fields; `words` merges per key, `data` is
   replaced whole.

## 9. Left to the builder

Table and column layouts; the message field names beyond those above;
how the data table infers columns; exact size limits if a real scene
needs more.
