# tt-demo-maker

[![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)

A reusable, project-agnostic toolkit for authoring **demo recordings and draft posts** from
inside any project. Point it at a TUI/CLI, describe what you want captured, and it turns
that into recorded footage (asciicast / GIF / MP4) **and** a first-draft Markdown post that
pairs each *directive* with the *reaction* it caused.

It exists so recording machinery (tmux + asciinema/VHS + ffmpeg + agg, idle-trimming, a demo
registry, inference-server-aware readiness gating) isn't reinvented per-project.

## See it in action

Three scenes recorded by this toolkit on real hardware — a QuietBox with 4× P300C
(Blackhole) boards — from this repo's own [`demo/demos.yaml`](demo/demos.yaml). In each,
the left pane runs a real ttnn matmul burst on device 0
([`demo/tt-burst.sh`](demo/tt-burst.sh)) and the right pane is
`tt-toplike --backend hybrid` watching live board telemetry. Scenes were captured with
`tt-demo record all` and idle-trimmed with `tt-demo compress`; GIF encoding used
hand-tuned `agg` flags — the exact values now expressed as `defaults.render` in the
manifest since v1.1 added render tuning (see limitations below).

**A short burst (starfield)** — a five-second matmul burst on device 0: clocks jump
800→1350 MHz, power spikes toward 140 W, the starfield flares, then everything settles.

![Short matmul burst reflected in the starfield visualization](media/short-burst.gif)

**Sustained load (arcade)** — nine seconds of sustained matmuls; the arcade hero climbs
as device 0 ramps from ~16 W idle toward ~140 W.

![Sustained matmul load driving the arcade visualization](media/sustained-load.gif)

**Load ends, power collapses (table)** — when the burst stops, device 0 falls from
~120 W back to idle and clocks drop back to 800 MHz in the live table view.

![Power collapsing back to idle in the live telemetry table](media/power-collapse.gif)

And the section below was placed here by `tt-demo publish ouroboros --readme README.md`
— footage of the tool recording the footage above, end-to-end through the v1.1 flow
(`rehearse → record → compress → render → verify → publish`):

<!-- tt-demo:gallery:begin -->
**Ouroboros: tt-demo recording tt-demo** — The tool films itself — the left pane runs a real `tt-demo record short-burst` (matmul burst included), while the right pane watches the board react to its own filming.

![Ouroboros: tt-demo recording tt-demo](media/ouroboros.gif)
<!-- tt-demo:gallery:end -->

## How it works

You describe scenes in a small YAML manifest; the toolkit does the terminal ballet:

```yaml
project: tt-toplike
theme: tt-brand
defaults: { cols: 200, rows: 50, backend: "--host", outputs: [cast, gif] }
scenes:
  - id: cold-load
    title: "Cold model load (host proxy)"
    layout: split
    left:  { run: "yes > /dev/null & sleep 6; kill %1" }
    right: { run: "tt-toplike {backend} --mode arcade" }
    duration: 8s
    split_ratio: 40
    caption: "Load ramps the host; the arcade hero climbs as power rises."
```

The full field reference lives in [`skill/manifest-schema.md`](skill/manifest-schema.md).

### Layers

```
description ──▶ /tt-demo skill (LLM: Claude or local Qwen)
                 │  authors/edits demo/demos.yaml, writes narration
                 ▼
            bin/tt-demo  (Rust orchestrator — the stable interface)
                 │  parse+validate manifest, compile scenes, drive flow
                 ▼
            lib/*.sh     (bash capture primitives — the terminal ballet)
                 │  spawn: tmux · asciinema · vhs · Xvfb · xterm · ffmpeg · agg
                 ▼
            demo/assets/*  +  demo/POST.draft.md
```

Full design: [`docs/superpowers/specs/2026-07-18-tt-demo-maker-design.md`](docs/superpowers/specs/2026-07-18-tt-demo-maker-design.md).

## How recordings look

Every recording uses the same defaults, with nothing to configure:

- **Truecolor.** `lib/tmux-record.conf` turns on 24-bit color for the recording tmux and sets
  `COLORTERM=truecolor`. Without it tmux reduces gradients to the 256-color palette.
- **One font everywhere.** `lib/look.sh` picks the first installed family from Berkeley Mono,
  JetBrainsMono Nerd Font, JetBrains Mono, Iosevka Term, Hack, DejaVu Sans Mono. The GIF (agg),
  MP4 and VHS renders all use it. Pin one with `TT_DEMO_FONT=<family>` or
  `defaults.render.font_family` in the manifest.
- **alacritty for MP4**, with the theme's palette (the same `themes/<theme>.agg` string the GIF
  uses). It falls back to xterm when alacritty is absent; `TT_DEMO_TERMINAL=xterm|alacritty`
  forces one.

`tt-demo setup` installs the font (JetBrainsMono Nerd Font v3.4.0, SHA-256 checked, into
`~/.local/share/fonts/tt-demo`, no root) and prints the package command for anything it can't
install itself, such as `alacritty`. `tt-demo doctor` reports the same items in its `look`
section. They are advisory: a machine with only stock fonts still records.

## Requirements

- **Rust toolchain** (to build the `tt-demo` binary; edition 2021)
- **Capture tools**, checked by `tt-demo doctor`: `tmux`, `asciinema`, `vhs`, `agg`,
  `ffmpeg`, and — only for MP4 rendering — `Xvfb` + `xterm`. You only need the tools for
  the engines and outputs your scenes actually use.
- **For the best-looking output** (advisory; `tt-demo setup` handles it): a code font
  with full glyph coverage (JetBrainsMono Nerd Font, installed for you), `alacritty` for
  MP4 (xterm is the fallback), and tmux 3.2+ with the `tmux-256color` terminfo.
- **Screen capture only** (the GUI path below): `obs` for video *or* `spectacle` for
  stills, plus `python3` with Pillow for the blank-frame check, and `ffmpeg`/`ffprobe`.
  `systemd-inhibit` and `loginctl` are used when present. `tt-demo doctor` reports these
  but never fails on them — most projects demo a terminal and will never record a GUI
  window. Pass `tt-demo doctor --require-screen` to make their absence an error, and
  `lib/screen_capture.sh detect` to see which backend actually works on this box.
- **QEMU/libvirt guest capture** (`lib/qemu_capture.sh`, `lib/qb2_capture.sh`): `virsh`,
  `ffmpeg`/`ffprobe`, `python3` + Pillow. Records a guest's own framebuffer from the first
  firmware frame, so it needs no OBS/portal and no viewer window; it cannot show the mouse
  pointer. The QB2 front door is `lib/qb2_capture.sh begin --fresh` … `end`; see the QEMU
  section of `skill/SKILL.md`. To record on another machine instead (pointer + up to 60 fps),
  use `begin --no-capture` here and `lib/qb2_view_remote.sh` there (SPICE over an ssh tunnel).
- **Layout verification with no live session** (recommended for checking a GTK/Qt/GL app's
  layout at a given window size, e.g. during a responsive-design change): `weston`
  (`apt install weston`), run headless — see
  [`docs/screen-capture.md`'s "Headless verification"](docs/screen-capture.md#headless-verification-no-live-session-at-all)
  section for the exact recipe and the two flags that are load-bearing but not obvious
  (`--renderer=pixman`, `--debug`).

## Install

```bash
./install.sh
```

This builds the `tt-demo` release binary, symlinks it to `~/.local/bin/tt-demo`, and
symlinks `skill/` to `~/.claude/skills/tt-demo` (so the `/tt-demo` Claude skill is
available in any project). If you invoke `tt-demo` from outside this repo, set
`TT_DEMO_HOME=/path/to/tt-demo-maker` so it can find `lib/`, `templates/`, and `themes/`.

## Quickstart

From the root of any project you want to demo:

```bash
tt-demo setup                  # install the font; say what else is missing (--dry-run to preview)
tt-demo doctor                 # check for tmux, asciinema, vhs, agg, ffmpeg, Xvfb, xterm + the look
tt-demo init                   # scaffold demo/demos.yaml, demo/assets/, demo/.gitignore
$EDITOR demo/demos.yaml        # describe your scenes — see skill/manifest-schema.md
tt-demo record --dry-run       # validate + print the capture plan; touches no hardware
tt-demo rehearse <id>          # preflight: does the directive move real telemetry?
tt-demo record all             # capture every scene (single/split/serve-wait as declared)
tt-demo compress demo/assets/<id>.cast   # idle-trim -> <id>.min.cast (render prefers it)
tt-demo render <id> --gif      # (or --mp4) themed + tuned via defaults.render
tt-demo verify <id>            # contact-sheet PNG of the rendered footage
tt-demo publish all --readme README.md   # copy artifacts + splice the gallery
tt-demo post --narrate claude  # assemble demo/POST.draft.md (narration written by the skill)
```

`tt-demo list` shows every scene's resolved engine (`vhs`/`asciinema`) and whether it's been
recorded yet.

## Recording a GUI app, not a terminal

Everything above drives tmux and asciinema, which only ever see a terminal. For a graphical
demo — a GTK/Qt/GL kiosk whose whole point is what it *draws* —
[`lib/screen_capture.sh`](lib/screen_capture.sh) records the screen instead:

```bash
lib/screen_capture.sh detect                 # which backend works here, and why
lib/screen_capture.sh record 120 out.mp4     # OBS + PipeWire, 1080p60
lib/screen_capture.sh burst  120 frames/     # Spectacle stills, any compositor
lib/screen_capture.sh verify out.mp4         # refuses to pass a black capture
```

This is a **bash-only backend**: it is not a `tt-demo` subcommand and has no manifest
representation yet, so call it directly or from a project's own recording script.
`tt-demo doctor` reports its tools in a separate optional section (`--require-screen` to
make them mandatory), and `screen_capture.sh detect` says which backend works here and why.

**The backend choice is measured, not assumed.** On a KWin/Wayland box, `ffmpeg -f x11grab`
records *pure black at exit 0*; `wf-recorder` and `grim` are wlroots-only and refuse
outright; Spectacle works but is stills-only at the version Ubuntu 24.04 packages (~5.9 fps);
OBS + PipeWire is the real answer at 1920×1080 @ 60 fps.
[`docs/screen-capture.md`](docs/screen-capture.md) has the full table and the xdg ScreenCast
portal caveat that otherwise costs an hour — OBS's first run in a login session must have the
screen-share dialog approved *interactively*, because a saved restore token is not sufficient
from a detached process and the resulting file is black.

**Every capture verifies itself**, because three of those backends fail by producing a
plausible file full of black — the worst failure available, since it looks like a working
recording until someone plays it. `verify` samples five points across the duration and fails
only if *every* sample is a single colour (a recorder's first second is routinely black while
the compositor hands over the first buffer, so judging the file on one early frame condemns
good footage). It also refuses outright when `loginctl` reports the session locked — a lock
screen photographs beautifully and passes every not-black check there is — and `record` wraps
the recorder in `systemd-inhibit --what=idle:sleep` so the lock cannot arrive mid-take.

**In use:** `tt-bio-demo` records its protein-folding booth through this path. Its
`scripts/record-demo-video.sh` follows the same recipe `record` does (OBS started first with
`systemd-inhibit`, never `setsid`, then the fullscreen app raised over it), adds an
app-specific screenshot precheck for leftover desktop chrome, and its
`recordings/README.md` runs `lib/screen_capture.sh verify` on every cut before it ships.

## Using the `/tt-demo` skill

Once installed, ask your agent (in any project) something like "record a short demo of the
cold-load causing the arcade viz to react" and the `/tt-demo` skill will author/edit
`demo/demos.yaml`, drive the CLI above, and write the narration in `demo/POST.draft.md`.
See [`skill/SKILL.md`](skill/SKILL.md) for the exact steps it follows and
[`skill/manifest-schema.md`](skill/manifest-schema.md) for the full manifest field reference.

## Reference example

[`examples/demos.yaml`](examples/demos.yaml) is the tt-toplike reference manifest — three
scenes (`qa-short`, `cold-load`, `reset-lightshow`) built entirely from `tt-toplike --host`
(no ASIC needed), so the whole pipeline is runnable and CI-testable without hardware. Copy
it into a project as a starting point:

```bash
mkdir -p demo && cp examples/demos.yaml demo/demos.yaml
```

This repo's own [`demo/demos.yaml`](demo/demos.yaml) is the complementary *real-hardware*
example — the manifest behind the footage at the top of this README.

## Non-invasive by default

Demo scene commands should prefer `--host` or `--backend hybrid` (interpolated via the
`{backend}` token in `defaults.backend`) over touching real hardware directly — this keeps
demos safe to record on shared boxes and runnable in CI via `--dry-run`.

## Repository layout

```
bin/        Rust orchestrator (the tt-demo CLI): manifest parsing, scene
            compilation, record/compress/render/post subcommands
lib/        bash capture primitives: tmux_capture.sh, split.sh, serve.sh,
            render.sh, verify.sh, driver.sh, and screen_capture.sh
            (the GUI/screen backend — OBS or Spectacle, self-verifying)
skill/      the /tt-demo Claude skill + manifest schema reference
templates/  minijinja templates: VHS tape, asciinema driver, POST.draft.md
themes/     VHS theme tapes (tt-brand, dracula) + agg palettes (*.agg)
examples/   the tt-toplike reference manifest
tests/      hardware-free end-to-end golden test
docs/       design spec, implementation plans, and screen-capture.md
            (measured GUI-recording findings for Wayland boxes)
```

## Testing

Everything here is hardware-free and network-free:

```bash
(cd bin && cargo test)                  # manifest, compile, orchestrate, ready, doctor, ...
bash lib/tests/capture_test.sh          # tmux capture -> cast -> GIF, through lib/
bash lib/tests/driver_test.sh           # the asciinema driver helpers
bash lib/tests/screen_capture_test.sh   # the blank-capture verifier, both directions
./tests/e2e_golden.sh                   # the whole pipeline, end to end
```

The golden test walks init → record (real single-pane capture) → compress → render GIF →
post, building the release binary if needed and running everything in a throwaway temp
directory.

`screen_capture_test.sh` synthesises its fixtures with ffmpeg's lavfi sources, so it needs
no display: real content must pass, synthetic black must be rejected, a black *first
second* must not condemn an otherwise good take, and a box that can't judge the frames at
all (no Pillow) must refuse rather than wave the footage through. It skips itself if ffmpeg
or Pillow is missing, or if the session is locked.

## v1 limitations / v1.1

**Added since v1.1** (born from recording the `tt-bio-demo` booth, which is a GUI):

- `lib/screen_capture.sh` — GUI/screen capture (`detect`/`record`/`burst`/`verify`) with a
  self-verifying blank-frame check and a locked-session refusal. See the GUI section above
  and [`docs/screen-capture.md`](docs/screen-capture.md).

**Delivered in v1.1** (born from recording the footage above by hand):

- `tt-demo compress` writes `<id>.min.cast` by default (the name `render` prefers);
  `--stdout` restores the old pipe behavior.
- `defaults.render` manifest options (`fps_cap`, `font_size`, `speed`) and theme-matched
  agg palettes (`themes/<theme>.agg`) — `render --gif` is now themed and size-tunable.
- `tt-demo rehearse <id>` — run a scene's directive while sampling `tt-smi`, report the
  idle→load delta per device, and (with `--require-reaction`) hard-fail when the board
  wouldn't visibly react. Catches quiet-board footage before it's recorded.
- `tt-demo verify <id>` — tile frames of the rendered artifact into a contact-sheet PNG
  for visual QA without playing it.
- `tt-demo publish` — copy artifacts from gitignored `demo/assets/` into a committed dir
  and emit/splice a markdown gallery (between `<!-- tt-demo:gallery:begin/end -->` markers).

`tt-demo record` (non-dry-run) drives declarative (`left`/`right`) scenes straight through
the tested `lib/*.sh` capture primitives, using each scene's raw `run:` commands.

**Delivered in 0.2.2** (born from wrapping a guide's hand-written VHS tapes as `raw_tape`
scenes and finding `record` still just printed and skipped them):

- **Raw-hatch CLI capture.** `tt-demo record <id>` now actually runs `vhs <tape>` for a
  `raw_tape` scene, or `asciinema rec <id>.cast --command "bash <script>"` for a
  `raw_script` scene, instead of printing "not yet CLI-captured" and skipping. A raw_tape's
  own `Output` line still decides where its artifact lands (not rewritten) — `record` just
  reports whether the conventional `demo/assets/<id>.{gif,mp4}` path showed up afterward, so
  a tape that doesn't follow convention fails loudly at `verify`/`publish` time rather than
  silently. Covered by a new `e2e_golden.sh` case (a 2-second marker tape, hardware-free).

The following remain deferred:

- **Screen capture is not in the CLI or the manifest.** `lib/screen_capture.sh` is invoked
  directly: there is no `tt-demo record` path to it and no scene shape for a GUI window.
  (`tt-demo doctor` does now check its tools, and
  `lib/tests/screen_capture_test.sh` covers the verifier — but the capture backends
  themselves still can't be tested here, since OBS needs a real graphical session and an
  interactively granted portal.)
- **Compiled-tape/driver execution.** `compile_scene`'s rendered VHS tape / asciinema
  driver text (`Compiled.text`) is produced and validated (compile-time only) but never
  executed by `record`; real capture goes through `lib/tmux_capture.sh`/`lib/split.sh`
  directly against the scene's raw commands instead. The compiled-driver's own shell
  quoting (`Debug`-repr, in `compile.rs`) also isn't POSIX-shell-safe yet — fine for the
  unexecuted text today, but must be fixed before that path is wired up.
- **MP4 rendering is unexercised.** `lib/render.sh mp4` (Xvfb + xterm + ffmpeg) exists but
  has no automated coverage here — it needs a display server most CI runners don't have.
- **Server stop / board reset on switch.** `Step::Switch` starts the next scene's server
  and waits for its readiness gate, but never stops whatever was running before it or runs
  a `tt-smi -r` board reset — switching between two exclusive hardware-backed servers back
  to back is not yet safe to automate.
- **Single-pane scenes with multi-statement commands.** When `right.run` is a multi-statement
  sequence (e.g. `"setup; long-viz"`), the entire command is backgrounded as a subshell,
  but individual non-terminating sub-steps are not separately managed — the kill/wait safety
  net covers the whole sequence, not intermediate steps.
- **Automated server start/readiness testing.** The `Step::Switch` server start + readiness-gating
  path (`serve.sh` + `poll_http`/log-wait) is verified manually but has no automated test
  coverage yet — planned for v1.1.

## License

[Apache-2.0](LICENSE)
