diff --git a/.gitignore b/.gitignore
index 8072fb4..97cc305 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,6 @@ __pycache__/
.DS_Store
# The narration voice for the demo recording (docs/record-demo/setup-voice.sh).
/docs/record-demo/.tts/
+# The Paddock film's stills and fonts (docs/record-demo/paddock-film/film.mjs).
+/docs/record-demo/paddock-film/.shots/
+/docs/record-demo/paddock-film/.fonts/
diff --git a/docs/record-demo/README.md b/docs/record-demo/README.md
index 4bb67bb..1a150ee 100644
--- a/docs/record-demo/README.md
+++ b/docs/record-demo/README.md
@@ -68,3 +68,55 @@ pushes the music down while the voice speaks (ffmpeg's `sidechaincompress`), tak
tops off the loudest syllables with a limiter, and levels the result to about -16 LUFS.
The script prints how far under the voice the bed sits; `MUSIC.level` near the top moves
it.
+
+## The what's new film
+
+`--film whats-new` makes a 15-second square clip (1080×1080) of what is new in 2.6 and
+2.7, for a social feed rather than the README. It is made to be watched without sound:
+no voice, short headlines on the picture (`a.headline()`), zooms on what matters
+(`a.zoom()`), a cut every two or three seconds and a beat written by `beat()`. It opens on
+its point: what each prompt of one session cost. It makes no still, and writes
+`docs/whats-new.mp4`, or wherever `--out` says:
+
+```sh
+node docs/record-demo/record.mjs --film whats-new --out ~/Desktop/whats-new.mp4
+```
+
+Its demo home adds three sessions with real work in them (`WORK`, written by
+`workLines()`), since the loop check only judges sessions with edits, commands and enough
+tokens: one goes round in circles, the same test failing after every fix, and two healthy
+ones give "your usual" something to go on. It also says the tool was just updated from
+2.5.1, so the "Updated to" window can be shown. Its scenes are `tourWhatsNew()`.
+
+## The Paddock film
+
+`--film paddock` makes the film of 2.8 (`docs/paddock.mp4` in the top-level README, and
+the launch post). It is made differently from the others: `record.mjs` only takes stills
+of the real page, and `paddock-film/` makes the film from them.
+
+```sh
+cargo build --release
+node docs/record-demo/record.mjs --film paddock [--cut long|short|both] [--draft] [--out DIR]
+```
+
+- `record.mjs --film paddock` adds a Codex account to the demo home (`CODEX`: rollouts as
+ Codex writes them, two of them held open by a stand-in `codex` so they show as working),
+ takes stills of the page at four times its size with where things are on them
+ (`capturePaddock()`), and writes them to `paddock-film/.shots`. `--stills` stops there.
+- `paddock-film/film.mjs` draws every frame of `stage.html` on its own clock in headless
+ Chrome: the stills in a window on a dark stage, a camera on springs, headlines, labels, a
+ pointer and the end card. Frames are drawn at twice the size and 120 a second, and each
+ frame of the film is the blend of two, so moves get motion blur. It can be run on its own
+ once the stills are there: `node docs/record-demo/paddock-film/film.mjs --cut long --draft`.
+- `paddock-film/score.js` writes the sound in Chrome's offline Web Audio, with no samples:
+ a pad, drums, bass, a riser and an impact, and effects (whooshes, ticks, pops) on the
+ picture's cues. `film.mjs` mixes and masters it to -14 LUFS with true peaks under -1 dB,
+ and prints the loudness, the peak and how much is lost folded to mono.
+- `paddock-film/timeline.js` holds every time both use, in beats. There are two cuts:
+ `short` (15 s, 160 beats a minute) opens on the app; `long` (25 s, 128) opens on an
+ abstract intro of the sessions the author had open (`OPEN`) gathering into one window.
+
+Each cut and shape (4:5 and 1:1) gets an mp4, a contact sheet and thumbnails; the films
+go to the Desktop unless `--out` says otherwise. The fonts (Inter and JetBrains Mono, under
+the SIL Open Font License) are fetched once into `paddock-film/.fonts`. `--draft` takes
+about a minute; a finished cut takes about 30 minutes for each shape.
diff --git a/docs/record-demo/paddock-film/film.mjs b/docs/record-demo/paddock-film/film.mjs
new file mode 100644
index 0000000..e718a28
--- /dev/null
+++ b/docs/record-demo/paddock-film/film.mjs
@@ -0,0 +1,321 @@
+// Makes the Paddock film from the stills record.mjs --film paddock took: draws
+// every frame of stage.html on its own clock in headless Chrome, writes the score
+// (score.js, in Chrome's offline Web Audio), mixes and masters it, and encodes
+// both shapes of the film.
+//
+// node docs/record-demo/paddock-film/film.mjs [--cut long|short|both] [--draft] [--sheet] [--only 4x5|1x1] [--out DIR]
+//
+// --cut picks the cut: long (25 s, opening on the abstract intro), short (15 s,
+// opening on the app) or both, the default.
+// --draft is quick: 30 frames a second at the frame's own size, no motion blur.
+// --sheet makes only a contact sheet of each shape (six frames) and the sound.
+// --out is where the films go (default: the Desktop).
+//
+// The stills are read from paddock-film/.shots, where record.mjs puts them. The
+// fonts (Inter and JetBrains Mono, both under the SIL Open Font License) are
+// fetched once from Google Fonts into paddock-film/.fonts. Both folders are
+// ignored by git. Needs Google Chrome and ffmpeg with libx264; on macOS the AAC
+// is Apple's own encoder (aac_at), elsewhere ffmpeg's.
+
+import { spawn, spawnSync } from 'node:child_process';
+import { once } from 'node:events';
+import { createReadStream, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
+import { createServer } from 'node:http';
+import os from 'node:os';
+import path from 'node:path';
+import { fileURLToPath, pathToFileURL } from 'node:url';
+
+import { timeline } from './timeline.js';
+
+const HERE = path.dirname(fileURLToPath(import.meta.url));
+const SHOTS = path.join(HERE, '.shots');
+const FONTS = path.join(HERE, '.fonts');
+const CHROME = process.env.CHROME || '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
+const FFMPEG = process.env.FFMPEG || 'ffmpeg';
+const SHAPES = { '4x5': { w: 1080, h: 1350 }, '1x1': { w: 1080, h: 1080 } };
+// The loudness feeds play at: -14 LUFS integrated, true peaks under -1 dB.
+const MASTER = { loudness: -14, peak: -1, rate: 48000 };
+const log = (...words) => console.log(...words);
+const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
+
+function run(program, args, what) {
+ const out = spawnSync(program, args, { encoding: 'utf8', maxBuffer: 1 << 26 });
+ if (out.error) throw new Error(`${what}: ${out.error.message}`);
+ if (out.status !== 0) throw new Error(`${what} failed:\n${out.stderr.slice(-2000)}`);
+ return out;
+}
+
+// --------------------------------------------------------------------- fonts
+
+const FONT_CSS = 'https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,100..900&family=JetBrains+Mono:wght@500&display=block';
+
+async function fetchFonts() {
+ const want = { inter: 'Inter', 'jetbrains-mono': 'JetBrains Mono' };
+ if (Object.keys(want).every((name) => existsSync(path.join(FONTS, `${name}.woff2`)))) return;
+ mkdirSync(FONTS, { recursive: true });
+ // Google Fonts answers with woff2 for a browser it knows.
+ const agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0 Safari/537.36';
+ const text = await (await fetch(FONT_CSS, { headers: { 'user-agent': agent } })).text();
+ // Each face comes after a comment naming its script; the Latin ones are wanted.
+ const faces = [...text.matchAll(/\/\* latin \*\/\s*@font-face\s*\{([^}]*)\}/g)].map((m) => m[1]);
+ for (const [name, family] of Object.entries(want)) {
+ const face = faces.find((f) => f.includes(`font-family: '${family}'`));
+ const src = face && face.match(/url\((https:[^)]+\.woff2)\)/);
+ if (!src) throw new Error(`Google Fonts did not list ${family}.`);
+ writeFileSync(path.join(FONTS, `${name}.woff2`), Buffer.from(await (await fetch(src[1])).arrayBuffer()));
+ log(`Fetched the ${family} font`);
+ }
+}
+
+// ------------------------------------------------------------------ the page
+
+// The stage, the stills and the fonts, from one small local server.
+export function serve() {
+ const types = { '.html': 'text/html', '.js': 'text/javascript', '.json': 'application/json', '.png': 'image/png', '.woff2': 'font/woff2' };
+ const server = createServer((req, res) => {
+ const url = decodeURIComponent(new URL(req.url, 'http://x').pathname);
+ const [root, rest] = url.startsWith('/shots/') ? [SHOTS, url.slice(7)] : url.startsWith('/fonts/') ? [FONTS, url.slice(7)] : [HERE, url.slice(1)];
+ const file = path.join(root, rest);
+ if (!file.startsWith(root) || !existsSync(file) || !statSync(file).isFile()) { res.writeHead(404).end(); return; }
+ res.writeHead(200, { 'content-type': types[path.extname(file)] || 'application/octet-stream', 'cache-control': 'no-store' });
+ createReadStream(file).pipe(res);
+ });
+ return new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve(server)));
+}
+
+// A small Chrome DevTools Protocol client, as in record.mjs.
+export async function openChrome(profile) {
+ const chrome = spawn(CHROME, ['--headless=new', '--remote-debugging-port=0', `--user-data-dir=${profile}`, '--no-first-run',
+ '--no-default-browser-check', '--hide-scrollbars', '--force-color-profile=srgb', '--autoplay-policy=no-user-gesture-required',
+ 'about:blank'], { stdio: 'ignore' });
+ let port = 0;
+ for (let i = 0; i < 100 && !port; i++) {
+ await sleep(100);
+ try { port = Number(readFileSync(path.join(profile, 'DevToolsActivePort'), 'utf8').split('\n')[0]); } catch { /* not up yet */ }
+ }
+ if (!port) { chrome.kill(); throw new Error('Chrome did not start.'); }
+ const target = (await (await fetch(`http://127.0.0.1:${port}/json`)).json()).find((t) => t.type === 'page');
+ const ws = new WebSocket(target.webSocketDebuggerUrl);
+ await new Promise((resolve, reject) => { ws.addEventListener('open', resolve); ws.addEventListener('error', reject); });
+ let nextId = 1;
+ const pending = new Map();
+ const problems = [];
+ ws.addEventListener('message', (event) => {
+ const msg = JSON.parse(event.data);
+ if (msg.id && pending.has(msg.id)) {
+ const { resolve, reject } = pending.get(msg.id);
+ pending.delete(msg.id);
+ if (msg.error) reject(new Error(msg.error.message)); else resolve(msg.result);
+ } else if (msg.method === 'Runtime.exceptionThrown') {
+ problems.push(msg.params.exceptionDetails.exception?.description || msg.params.exceptionDetails.text);
+ } else if (msg.method === 'Runtime.consoleAPICalled' && msg.params.type === 'error') {
+ problems.push(msg.params.args.map((a) => a.value ?? a.description).join(' '));
+ }
+ });
+ const send = (method, params = {}) => new Promise((resolve, reject) => {
+ const id = nextId++;
+ pending.set(id, { resolve, reject });
+ ws.send(JSON.stringify({ id, method, params }));
+ });
+ const evaluate = async (expression) => {
+ const r = await send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true });
+ if (r.exceptionDetails) throw new Error(r.exceptionDetails.exception?.description || r.exceptionDetails.text);
+ return r.result.value;
+ };
+ await send('Page.enable');
+ await send('Runtime.enable');
+ return {
+ send, evaluate, problems,
+ async open(url, ready) {
+ await send('Page.navigate', { url });
+ for (let i = 0; i < 300; i++) {
+ if (problems.length) throw new Error(`The page failed: ${problems.join('\n')}`);
+ if (await evaluate(ready).catch(() => false)) return;
+ await sleep(100);
+ }
+ throw new Error(`${url} did not get ready.`);
+ },
+ async close() {
+ const gone = chrome.exitCode === null ? once(chrome, 'exit') : Promise.resolve();
+ send('Browser.close').catch(() => {});
+ const timer = setTimeout(() => chrome.kill('SIGKILL'), 5000);
+ await gone;
+ clearTimeout(timer);
+ },
+ };
+}
+
+// --------------------------------------------------------------- the picture
+
+export async function openStage(page, base, shape, scale, cut = 'short') {
+ await page.send('Emulation.setDeviceMetricsOverride', { width: shape.w, height: shape.h, deviceScaleFactor: scale, mobile: false });
+ await page.open(`${base}/stage.html?w=${shape.w}&h=${shape.h}&cut=${cut}`, 'window.ready === true');
+}
+
+async function frame(page, t, format = 'png') {
+ await page.evaluate(`render(${t})`);
+ const shot = await page.send('Page.captureScreenshot', { format, ...(format === 'jpeg' ? { quality: 95 } : {}), optimizeForSpeed: format === 'jpeg' });
+ return Buffer.from(shot.data, 'base64');
+}
+
+// The middle of each scene and the end card, in a grid; with the intro, four of its
+// moments first (scattered, the type, gathering, the drop).
+async function sheet(page, shape, file, work, T) {
+ const { SCENES, IMPACT, INTRO } = T;
+ const intro = INTRO ? [1.0, 2.3, INTRO - 0.9, INTRO - 0.08] : [];
+ const times = [...intro, SCENES.both + 1.6, SCENES.all + 1.9, SCENES.search + 1.0, SCENES.search + 2.6, SCENES.usage + 1.8, IMPACT + 2.2];
+ const files = [];
+ for (const [n, t] of times.entries()) {
+ const f = path.join(work, `sheet-${n}.png`);
+ writeFileSync(f, await frame(page, t));
+ files.push(f);
+ }
+ run(FFMPEG, ['-hide_banner', '-loglevel', 'error', '-y', '-i', path.join(work, 'sheet-%d.png'),
+ '-vf', `scale=${Math.round(shape.w / 2.5)}:-2:flags=lanczos,tile=${times.length / 2}x2:padding=12:color=0x202024`, '-frames:v', '1', file], 'Making the contact sheet');
+}
+
+// Every frame, drawn and piped to ffmpeg. The finished film runs at 60 a second
+// with each frame the blend of two drawn at 120: a 180° shutter's motion blur.
+async function picture(page, shape, { draft, sound, target, T }) {
+ const { LENGTH } = T;
+ const fps = draft ? 30 : 120;
+ const count = Math.round(LENGTH * fps);
+ const blur = draft ? '' : 'tmix=frames=2:weights=1 1,fps=60,';
+ const aac = process.platform === 'darwin' ? ['-c:a', 'aac_at', '-aac_at_mode', 'cbr', '-b:a', '320k'] : ['-c:a', 'aac', '-b:a', '320k'];
+ const ffmpeg = spawn(FFMPEG, [
+ '-hide_banner', '-loglevel', 'error', '-y',
+ '-f', 'image2pipe', '-framerate', String(fps), '-c:v', draft ? 'mjpeg' : 'png', '-i', '-',
+ '-i', sound,
+ '-vf', `${blur}scale=${shape.w}:${shape.h}:flags=lanczos:in_range=pc:out_range=tv:out_color_matrix=bt709,format=yuv420p`,
+ '-colorspace', 'bt709', '-color_primaries', 'bt709', '-color_trc', 'bt709', '-color_range', 'tv',
+ '-c:v', 'libx264', '-profile:v', 'high', '-preset', draft ? 'veryfast' : 'slower', '-crf', draft ? '20' : '14',
+ '-g', draft ? '60' : '120', '-r', draft ? '30' : '60',
+ '-map', '0:v', '-map', '1:a', ...aac, '-shortest', '-movflags', '+faststart', target,
+ ], { stdio: ['pipe', 'inherit', 'inherit'] });
+ const done = new Promise((resolve, reject) => {
+ ffmpeg.on('error', (err) => reject(new Error(`Could not run ${FFMPEG}: ${err.message}`)));
+ ffmpeg.on('exit', (code) => (code === 0 ? resolve() : reject(new Error(`ffmpeg failed (exit ${code}).`))));
+ });
+ ffmpeg.stdin.on('error', () => {});
+ const began = Date.now();
+ for (let n = 0; n < count; n++) {
+ const image = await frame(page, n / fps, draft ? 'jpeg' : 'png');
+ if (!ffmpeg.stdin.write(image)) await once(ffmpeg.stdin, 'drain');
+ if (n % (fps * 2) === 0 && n) {
+ const left = ((Date.now() - began) / n) * (count - n) / 1000;
+ log(` ${(n / fps).toFixed(0)}s of ${LENGTH}s drawn, about ${Math.ceil(left / 60)} min left`);
+ }
+ }
+ ffmpeg.stdin.end();
+ await done;
+}
+
+// ------------------------------------------------------------------ the sound
+
+// The score and the effects, rendered by score.js in the page, as two stems.
+async function score(page, base, work, T) {
+ await page.open(`${base}/score.html?cut=${T.cut}`, 'window.ready === true');
+ const stems = await page.evaluate(`renderStems(${JSON.stringify(T.cues())})`);
+ const files = {};
+ for (const [name, data] of Object.entries(stems)) {
+ files[name] = path.join(work, `${name}.wav`);
+ writeFileSync(files[name], Buffer.from(data, 'base64'));
+ }
+ return files;
+}
+
+// The mix and the master. The music is cleaned up and glued, and ducked a little
+// whenever an effect hits; the two are summed and compressed gently. Then it is
+// brought to -14 LUFS by one steady gain and its peaks caught by a limiter run at
+// four times the sample rate, so it holds true peaks (between the samples) too,
+// under -1 dB. The limiter takes a little loudness, so the gain is measured and set
+// twice. Then the result is measured, in stereo and folded to mono, and printed.
+function master(stems, file, { LENGTH }) {
+ const mix = '[0:a]highpass=f=28,acompressor=threshold=-20dB:ratio=2:attack=25:release=280:knee=4:makeup=1.5[music];'
+ + '[1:a]acompressor=threshold=-16dB:ratio=2.5:attack=5:release=120:knee=3,asplit[fx][key];'
+ + '[music][key]sidechaincompress=threshold=0.06:ratio=3:attack=8:release=320:knee=4[ducked];'
+ + '[ducked][fx]amix=inputs=2:duration=longest:normalize=0,'
+ + 'acompressor=threshold=-10dB:ratio=1.6:attack=30:release=300:knee=6';
+ const inputs = ['-i', stems.music, '-i', stems.fx];
+ // Under the target by enough to cover what going back to 48 kHz adds between samples.
+ const ceiling = 10 ** ((MASTER.peak - 0.9) / 20);
+ const chain = (gain) => `${mix},volume=${gain.toFixed(2)}dB,aresample=${MASTER.rate * 4},`
+ + `alimiter=limit=${ceiling.toFixed(4)}:attack=1:release=60:level=disabled,`
+ + `aresample=${MASTER.rate}:filter_size=64:phase_shift=10:cutoff=0.97,atrim=end=${LENGTH}`;
+ const loudness = (filter) => {
+ const out = run(FFMPEG, ['-hide_banner', '-nostats', ...inputs, '-filter_complex', `${filter},ebur128=framelog=quiet`, '-f', 'null', '-'], 'Measuring the mix');
+ return Number(out.stderr.slice(out.stderr.lastIndexOf('Summary:')).match(/I:\s+(-?[\d.]+) LUFS/)[1]);
+ };
+ let gain = MASTER.loudness - loudness(mix);
+ for (let pass = 0; pass < 2; pass++) gain += MASTER.loudness - loudness(chain(gain));
+ run(FFMPEG, ['-hide_banner', '-nostats', '-y', ...inputs, '-filter_complex', chain(gain), '-c:a', 'pcm_s24le', file], 'Mastering');
+ // The finished file, measured again: loudness and true peak, and how much is lost folded to mono.
+ const meter = (filter) => {
+ const out = run(FFMPEG, ['-hide_banner', '-nostats', '-i', file, '-af', `${filter}ebur128=peak=true:framelog=quiet`, '-f', 'null', '-'], 'Metering');
+ const tail = out.stderr.slice(out.stderr.lastIndexOf('Summary:'));
+ return { i: Number(tail.match(/I:\s+(-?[\d.]+) LUFS/)[1]), peak: Number(tail.match(/Peak:\s+(-?[\d.]+) dBFS/)[1]) };
+ };
+ const stereo = meter('');
+ // Mono as a phone speaker plays it: the two sides summed, in both channels.
+ const mono = meter('pan=stereo|c0=0.5*c0+0.5*c1|c1=0.5*c0+0.5*c1,');
+ log(`Master: ${stereo.i} LUFS, true peak ${stereo.peak} dBTP (gain ${gain.toFixed(1)} dB); `
+ + `folded to mono ${mono.i} LUFS, ${(stereo.i - mono.i).toFixed(1)} dB down.`);
+ return { stereo, mono };
+}
+
+// ---------------------------------------------------------------------- main
+
+export async function makeFilm({ cut = 'both', draft = false, sheetOnly = false, only = null, out = path.join(os.homedir(), 'Desktop') } = {}) {
+ if (!existsSync(path.join(SHOTS, 'shots.json'))) throw new Error(`No stills in ${SHOTS}. Run: node docs/record-demo/record.mjs --film paddock`);
+ if (!existsSync(CHROME)) throw new Error(`Google Chrome was not found at ${CHROME}. Set CHROME to its path.`);
+ await fetchFonts();
+ mkdirSync(out, { recursive: true });
+ const work = mkdtempSync(path.join(os.tmpdir(), 'paddock-film-'));
+ const server = await serve();
+ const base = `http://127.0.0.1:${server.address().port}`;
+ const page = await openChrome(path.join(work, 'chrome'));
+ try {
+ for (const which of cut === 'both' ? ['long', 'short'] : [cut]) {
+ const T = timeline(which);
+ const label = `${T.LENGTH}s`;
+ const sound = path.join(out, `paddock-2.8-${label}-sound.wav`);
+ master(await score(page, base, work, T), sound, T);
+ for (const [name, shape] of Object.entries(SHAPES)) {
+ if (only && only !== name) continue;
+ await openStage(page, base, shape, sheetOnly || !draft ? 2 : 1, which);
+ const stem = `paddock-2.8-${label}-${name}`;
+ const sheetFile = path.join(out, `${stem}-sheet.png`);
+ await sheet(page, shape, sheetFile, work, T);
+ log(`Wrote ${sheetFile}`);
+ // The thumbnail: the first app scene with its whole headline up.
+ writeFileSync(path.join(out, `${stem}-thumbnail.png`), await frame(page, T.SCENES.both + 2.4));
+ // And with the intro, its three lines all up: the post's own hook.
+ if (T.INTRO) writeFileSync(path.join(out, `${stem}-thumbnail-intro.png`), await frame(page, T.SAID[2] + 1.1));
+ if (sheetOnly) continue;
+ const target = path.join(out, `${stem}${draft ? '-draft' : ''}.mp4`);
+ log(`Drawing the ${label} ${name} film${draft ? ' (draft)' : ''}…`);
+ await picture(page, shape, { draft, sound, target, T });
+ log(`Wrote ${target} (${(statSync(target).size / 1e6).toFixed(1)} MB)`);
+ }
+ }
+ if (page.problems.length) log(`Page errors:\n${page.problems.join('\n')}`);
+ } finally {
+ await page.close();
+ server.close();
+ rmSync(work, { recursive: true, force: true, maxRetries: 20, retryDelay: 250 });
+ }
+}
+
+if (import.meta.url === pathToFileURL(process.argv[1]).href) {
+ const option = (name) => { const i = process.argv.indexOf(name); return i < 0 ? null : process.argv[i + 1] || null; };
+ makeFilm({
+ cut: option('--cut') || 'both',
+ draft: process.argv.includes('--draft'),
+ sheetOnly: process.argv.includes('--sheet'),
+ only: option('--only'),
+ out: option('--out') ? path.resolve(option('--out')) : undefined,
+ }).catch((err) => {
+ console.error(`paddock-film: ${err.message}`);
+ process.exit(1);
+ });
+}
diff --git a/docs/record-demo/paddock-film/score.html b/docs/record-demo/paddock-film/score.html
new file mode 100644
index 0000000..3b87de2
--- /dev/null
+++ b/docs/record-demo/paddock-film/score.html
@@ -0,0 +1,5 @@
+
+
+
Paddock film: score
+
+
diff --git a/docs/record-demo/paddock-film/score.js b/docs/record-demo/paddock-film/score.js
new file mode 100644
index 0000000..8557918
--- /dev/null
+++ b/docs/record-demo/paddock-film/score.js
@@ -0,0 +1,767 @@
+// The Paddock film's sound, synthesized here in Chrome's offline Web Audio: no
+// samples and no loops, so it is the project's own. Two stems come out as 32-bit
+// float WAVs, the music and the effects, for film.mjs to mix and master.
+//
+// The music is in A minor at the cut's tempo (timeline.js), felt in half time, two bars to a
+// scene: a wide pad that opens up over the first scene, the drums and bass from
+// the second, a build into the end card, a drop-out under the riser, and the
+// impact on the name. The effects follow the picture's cues (timeline.js).
+
+import { timeline } from './timeline.js';
+
+// ?cut=long is the 25 s cut, with the intro: a drone and the pad opening up, a blip
+// for each outline, the pull of the gathering and a drop as the window lands.
+const CUT = new URLSearchParams(location.search).get('cut') || 'short';
+const LONG = CUT === 'long';
+const { BEAT, BAR, STEP, LENGTH, INTRO, SCENES, RISE, IMPACT, GROOVE, GATHER } = timeline(CUT);
+
+const RATE = 48000;
+const TAIL = 0.5;
+
+const hz = (midi) => 440 * 2 ** ((midi - 69) / 12);
+
+// Seeded random numbers: the same noise and the same feel every run.
+function seeded(seed) {
+ return () => {
+ seed = (seed + 0x6d2b79f5) >>> 0;
+ let t = seed;
+ t = Math.imul(t ^ (t >>> 15), t | 1);
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
+ };
+}
+
+// ----------------------------------------------------------------- building blocks
+
+// White noise; `wide` makes each ear its own, for things meant to fill the field
+// (air, cymbals, risers). Drums and clicks stay in the middle.
+function noise(ctx, seconds, seed = 1, wide = false) {
+ const buffer = ctx.createBuffer(wide ? 2 : 1, Math.ceil(seconds * RATE), RATE);
+ for (let ch = 0; ch < buffer.numberOfChannels; ch++) {
+ const random = seeded(seed * 31 + ch);
+ const data = buffer.getChannelData(ch);
+ for (let i = 0; i < data.length; i++) data[i] = random() * 2 - 1;
+ }
+ return buffer;
+}
+
+// A plate reverb's impulse: decorrelated noise in each ear, dying away and darkening
+// as it goes, after a short gap before the first reflections.
+function plate(ctx, seconds, seed) {
+ const buffer = ctx.createBuffer(2, Math.ceil(seconds * RATE), RATE);
+ const gap = Math.round(0.018 * RATE);
+ for (let ch = 0; ch < 2; ch++) {
+ const random = seeded(seed * 17 + ch);
+ const data = buffer.getChannelData(ch);
+ let low = 0;
+ for (let i = gap; i < data.length; i++) {
+ const t = (i - gap) / RATE;
+ const k = 0.9 * Math.exp(-t / (seconds * 0.28)) + 0.06; // brightness, falling
+ low += k * ((random() * 2 - 1) - low);
+ data[i] = low * Math.exp(-6.9 * t / seconds);
+ }
+ }
+ return buffer;
+}
+
+function bus(ctx, out, { reverb = null, wet = 0, delay = null, echo = 0, gain = 1 } = {}) {
+ const input = ctx.createGain();
+ input.gain.value = gain;
+ input.connect(out);
+ if (reverb && wet) { const send = ctx.createGain(); send.gain.value = wet; input.connect(send).connect(reverb); }
+ if (delay && echo) { const send = ctx.createGain(); send.gain.value = echo; input.connect(send).connect(delay); }
+ return input;
+}
+
+function reverbOf(ctx, out, seconds, seed, level = 1) {
+ const conv = ctx.createConvolver();
+ conv.normalize = true;
+ conv.buffer = plate(ctx, seconds, seed);
+ const hp = ctx.createBiquadFilter();
+ hp.type = 'highpass';
+ hp.frequency.value = 180;
+ const g = ctx.createGain();
+ g.gain.value = level;
+ conv.connect(hp).connect(g).connect(out);
+ return conv;
+}
+
+// A ping-pong delay: each repeat crosses to the other ear and loses a little top.
+function pingPong(ctx, out, time, feedback = 0.38) {
+ const input = ctx.createGain();
+ const left = ctx.createDelay(2);
+ const right = ctx.createDelay(2);
+ left.delayTime.value = right.delayTime.value = time;
+ const fbL = ctx.createGain();
+ const fbR = ctx.createGain();
+ fbL.gain.value = fbR.gain.value = feedback;
+ const tone = ctx.createBiquadFilter();
+ tone.type = 'lowpass';
+ tone.frequency.value = 4200;
+ const merge = ctx.createChannelMerger(2);
+ input.connect(tone).connect(left);
+ left.connect(fbL).connect(right);
+ right.connect(fbR).connect(left);
+ left.connect(merge, 0, 0);
+ right.connect(merge, 0, 1);
+ merge.connect(out);
+ return input;
+}
+
+function shaper(ctx, drive) {
+ const s = ctx.createWaveShaper();
+ const curve = new Float32Array(2048);
+ for (let i = 0; i < curve.length; i++) {
+ const x = (i / (curve.length - 1)) * 2 - 1;
+ curve[i] = Math.tanh(drive * x) / Math.tanh(drive);
+ }
+ s.curve = curve;
+ s.oversample = '4x';
+ return s;
+}
+
+// An envelope on a gain: up to `peak` in `attack`, then down exponentially over `decay`.
+function hit(param, at, peak, attack, decay) {
+ param.setValueAtTime(0, at);
+ param.linearRampToValueAtTime(peak, at + attack);
+ param.setTargetAtTime(0, at + attack, decay / 4);
+}
+
+function play(ctx, node, at, until) {
+ node.start(at);
+ node.stop(until);
+}
+
+// ------------------------------------------------------------------- the music
+
+// A chord to each bar: Am9, Fmaj9, Cadd9, G6, twice; then the impact on Am9 and
+// out on Fmaj9. [root, voices].
+const CHORDS = [
+ [33, [57, 60, 64, 67, 71]],
+ [29, [53, 57, 60, 64, 67]],
+ [36, [55, 60, 62, 64, 67]],
+ [31, [55, 59, 62, 64, 69]],
+];
+// `bar` counts from the start; the intro's three bars (Am, F, G) lead into the first scene's Am.
+const chordAt = (bar) => {
+ const b = bar - Math.round(INTRO / BAR);
+ if (b < 0) return [CHORDS[0], CHORDS[1], CHORDS[3]][b + 3];
+ return b >= 9 ? CHORDS[1] : CHORDS[b % 4];
+};
+const BARS = Math.ceil(LENGTH / BAR);
+
+// Where the kick falls in a bar of sixteenths: half time, with a push before the backbeat.
+const KICKS = [0, 3, 10];
+const kickTimes = [];
+for (let t = GROOVE.from; t < GROOVE.until - 1e-6; t += BAR) for (const s of KICKS) kickTimes.push(t + s * STEP);
+
+// The pump: a level that dips on every kick and comes back, for the pad and bass.
+function pump(param, level, depth) {
+ param.setValueAtTime(level, 0);
+ for (const k of kickTimes) {
+ param.setValueAtTime(level, k - 0.005);
+ param.linearRampToValueAtTime(level * (1 - depth), k + 0.01);
+ param.setTargetAtTime(level, k + 0.03, 0.06);
+ }
+}
+
+function compose(ctx, out) {
+ const glue = ctx.createDynamicsCompressor();
+ glue.threshold.value = -16;
+ glue.ratio.value = 2;
+ glue.attack.value = 0.02;
+ glue.release.value = 0.25;
+ glue.knee.value = 8;
+ glue.connect(out);
+ const room = reverbOf(ctx, glue, 2.4, 3, 0.9);
+ const hall = reverbOf(ctx, glue, 4.2, 5, 1);
+ const echoes = pingPong(ctx, glue, BEAT * 0.75, 0.36);
+
+ // The whole mix fades over the last second, so the film ends on air, not a cut.
+ const ending = ctx.createGain();
+ ending.gain.setValueAtTime(1, LENGTH - 1.1);
+ ending.gain.linearRampToValueAtTime(0, LENGTH - 0.02);
+ ending.connect(glue);
+
+ pad(ctx, bus(ctx, ending, { reverb: hall, wet: 0.5 }));
+ arp(ctx, bus(ctx, ending, { reverb: room, wet: 0.25, delay: echoes, echo: 0.3 }));
+ if (LONG) drone(ctx, bus(ctx, ending, { reverb: hall, wet: 0.4 })); else sub(ctx, ending);
+ bass(ctx, ending);
+ drums(ctx, ending, room);
+ build(ctx, ending, room);
+ stab(ctx, bus(ctx, ending, { reverb: hall, wet: 0.7 }));
+}
+
+// Seven detuned saws to a voice, spread across the stereo field, through one filter
+// that opens over the first scene, breathes with the groove and opens fully on the impact.
+function pad(ctx, out) {
+ const filter = ctx.createBiquadFilter();
+ filter.type = 'lowpass';
+ filter.Q.value = 0.7;
+ const f = filter.frequency;
+ if (LONG) {
+ // Nearly shut over the scattered outlines, opening as they gather, then on with the app.
+ f.setValueAtTime(220, 0);
+ f.exponentialRampToValueAtTime(700, GATHER);
+ f.exponentialRampToValueAtTime(3200, INTRO - 0.02);
+ f.setValueAtTime(1500, INTRO);
+ } else {
+ f.setValueAtTime(320, 0);
+ }
+ f.exponentialRampToValueAtTime(2300, SCENES.all);
+ f.linearRampToValueAtTime(2600, SCENES.usage);
+ f.exponentialRampToValueAtTime(4800, RISE);
+ f.setValueAtTime(900, RISE);
+ f.setValueAtTime(7000, IMPACT);
+ f.exponentialRampToValueAtTime(2200, LENGTH);
+ const level = ctx.createGain();
+ // Fuller alone at the start, back in the mix under the drums, out under the riser.
+ pump(level.gain, 0.16, 0.45);
+ level.gain.setValueAtTime(LONG ? 0.15 : 0.2, 0);
+ level.gain.setValueAtTime(0.16, LONG ? INTRO : SCENES.all);
+ level.gain.setValueAtTime(0.16, RISE);
+ level.gain.linearRampToValueAtTime(0.05, RISE + 0.15);
+ level.gain.setValueAtTime(0.05, IMPACT - 0.01);
+ level.gain.linearRampToValueAtTime(0.22, IMPACT + 0.02);
+ filter.connect(level).connect(out);
+
+ const detune = [-14, -9, -4, 0, 4, 9, 14];
+ for (let b = 0; b < BARS; b++) {
+ const at = b * BAR;
+ const until = Math.min(LENGTH + TAIL, at + BAR + 0.5);
+ const [, voices] = chordAt(b);
+ for (const note of voices) {
+ detune.forEach((cents, i) => {
+ const osc = ctx.createOscillator();
+ osc.type = 'sawtooth';
+ osc.frequency.value = hz(note);
+ osc.detune.value = cents;
+ const pan = ctx.createStereoPanner();
+ pan.pan.value = (i / (detune.length - 1)) * 1.1 - 0.55;
+ const g = ctx.createGain();
+ g.gain.setValueAtTime(0, at);
+ g.gain.linearRampToValueAtTime(0.05, at + (b === 0 ? 0.25 : 0.12));
+ g.gain.setValueAtTime(0.05, at + BAR);
+ g.gain.linearRampToValueAtTime(0, until);
+ osc.connect(g).connect(pan).connect(filter);
+ play(ctx, osc, at, until);
+ });
+ }
+ }
+}
+
+// Sixteenths up the chord, plucked, bouncing between the ears.
+function arp(ctx, out) {
+ const filter = ctx.createBiquadFilter();
+ filter.type = 'lowpass';
+ filter.frequency.value = 3400;
+ filter.connect(out);
+ const random = seeded(11);
+ for (let t = LONG ? BAR : BEAT * 2, n = 0; t < RISE - 1e-6; t += STEP, n++) {
+ const [, voices] = chordAt(Math.floor(t / BAR));
+ const ladder = [...voices.slice(1), ...voices.slice(1).map((v) => v + 12)];
+ const note = ladder[n % ladder.length] + 12;
+ const osc = ctx.createOscillator();
+ osc.type = 'triangle';
+ osc.frequency.value = hz(note);
+ const g = ctx.createGain();
+ const lift = t < INTRO ? 0.45 : t < SCENES.all ? 0.6 : t > SCENES.usage ? 1.15 : 1;
+ hit(g.gain, t, (0.028 + random() * 0.012) * lift, 0.003, 0.16);
+ osc.connect(g).connect(filter);
+ play(ctx, osc, t, t + 0.35);
+ }
+}
+
+// A low pulse in eighths under the first scene, before the bass comes in.
+function sub(ctx, out) {
+ for (let t = 0; t < SCENES.all - 1e-6; t += BEAT / 2) {
+ const osc = ctx.createOscillator();
+ osc.frequency.value = hz(chordAt(Math.floor(t / BAR))[0] + 12);
+ const g = ctx.createGain();
+ hit(g.gain, t, 0.12 + 0.08 * (t / SCENES.all), 0.01, 0.22);
+ osc.connect(g).connect(out);
+ play(ctx, osc, t, t + 0.3);
+ }
+}
+
+// Under the intro: a low A held and slowly breathing, with a band of dark noise over it,
+// swelling as the outlines gather and stopping on the drop.
+function drone(ctx, out) {
+ const level = ctx.createGain();
+ level.gain.setValueAtTime(0, 0);
+ level.gain.linearRampToValueAtTime(0.5, 0.8);
+ level.gain.linearRampToValueAtTime(0.65, GATHER);
+ level.gain.exponentialRampToValueAtTime(1, INTRO - 0.03);
+ level.gain.linearRampToValueAtTime(0, INTRO);
+ level.connect(out);
+ for (const [note, detune, gain] of [[33, -4, 0.5], [33, 4, 0.5], [45, 0, 0.18]]) {
+ const osc = ctx.createOscillator();
+ osc.frequency.value = hz(note);
+ osc.detune.value = detune;
+ const g = ctx.createGain();
+ g.gain.value = gain;
+ osc.connect(g).connect(level);
+ play(ctx, osc, 0, INTRO);
+ }
+ const air = ctx.createBufferSource();
+ air.buffer = noise(ctx, INTRO, 83, true);
+ const band = ctx.createBiquadFilter();
+ band.type = 'bandpass';
+ band.Q.value = 0.8;
+ band.frequency.setValueAtTime(260, 0);
+ band.frequency.exponentialRampToValueAtTime(1400, INTRO);
+ const g = ctx.createGain();
+ g.gain.value = 0.12;
+ air.connect(band).connect(g).connect(level);
+ play(ctx, air, 0, INTRO);
+}
+
+// The bass: a saw and a sine an octave down, through a filter that snaps open on each note.
+function bass(ctx, out) {
+ const level = ctx.createGain();
+ pump(level.gain, 0.32, 0.7);
+ const warm = shaper(ctx, 1.6);
+ warm.connect(level).connect(out);
+ const STEPS = [0, 3, 6, 8, 11, 14];
+ for (let bar = GROOVE.from; bar < GROOVE.until - 1e-6; bar += BAR) {
+ const root = chordAt(Math.round(bar / BAR))[0] + 12;
+ for (const [i, s] of STEPS.entries()) {
+ const at = bar + s * STEP;
+ const note = i === 4 ? root + 12 : root;
+ const saw = ctx.createOscillator();
+ saw.type = 'sawtooth';
+ saw.frequency.value = hz(note);
+ const sine = ctx.createOscillator();
+ sine.frequency.value = hz(note - 12);
+ const filter = ctx.createBiquadFilter();
+ filter.type = 'lowpass';
+ filter.Q.value = 4;
+ filter.frequency.setValueAtTime(1800, at);
+ filter.frequency.exponentialRampToValueAtTime(260, at + 0.16);
+ const g = ctx.createGain();
+ hit(g.gain, at, 0.55, 0.004, 0.22);
+ const gs = ctx.createGain();
+ hit(gs.gain, at, 0.6, 0.004, 0.26);
+ saw.connect(filter).connect(g).connect(warm);
+ sine.connect(gs).connect(warm);
+ play(ctx, saw, at, at + 0.4);
+ play(ctx, sine, at, at + 0.4);
+ }
+ }
+}
+
+function kick(ctx, out, at, size = 1, buffer) {
+ const osc = ctx.createOscillator();
+ osc.frequency.setValueAtTime(165 * size, at);
+ osc.frequency.exponentialRampToValueAtTime(46, at + 0.085);
+ osc.frequency.exponentialRampToValueAtTime(38, at + 0.4);
+ const g = ctx.createGain();
+ hit(g.gain, at, 0.95 * size, 0.002, 0.42 * size);
+ const drive = shaper(ctx, 2.2);
+ osc.connect(g).connect(drive).connect(out);
+ play(ctx, osc, at, at + 0.7);
+ // The beater: a few milliseconds of bright noise.
+ const click = ctx.createBufferSource();
+ click.buffer = buffer;
+ const hp = ctx.createBiquadFilter();
+ hp.type = 'highpass';
+ hp.frequency.value = 1400;
+ const gc = ctx.createGain();
+ hit(gc.gain, at, 0.35 * size, 0.0005, 0.012);
+ click.connect(hp).connect(gc).connect(out);
+ play(ctx, click, at, at + 0.05);
+}
+
+function snare(ctx, out, at, level, buffer, room) {
+ // A clap: three quick bursts and a tail, over a snare's crack and body.
+ const body = ctx.createOscillator();
+ body.type = 'triangle';
+ body.frequency.setValueAtTime(210, at);
+ body.frequency.exponentialRampToValueAtTime(170, at + 0.08);
+ const gb = ctx.createGain();
+ hit(gb.gain, at, 0.32 * level, 0.001, 0.09);
+ body.connect(gb).connect(out);
+ play(ctx, body, at, at + 0.2);
+ const parts = [[0, 0.5, 0.008], [0.011, 0.45, 0.008], [0.022, 0.55, 0.16]];
+ for (const [dt, peak, decay] of parts) {
+ const src = ctx.createBufferSource();
+ src.buffer = buffer;
+ src.playbackRate.value = 1 + dt * 4;
+ const bp = ctx.createBiquadFilter();
+ bp.type = 'bandpass';
+ bp.frequency.value = 1500;
+ bp.Q.value = 0.9;
+ const g = ctx.createGain();
+ hit(g.gain, at + dt, peak * level, 0.0008, decay);
+ src.connect(bp).connect(g);
+ g.connect(out);
+ const send = ctx.createGain();
+ send.gain.value = 0.35;
+ g.connect(send).connect(room);
+ play(ctx, src, at + dt, at + dt + 0.35);
+ }
+}
+
+function hat(ctx, out, at, level, open, buffer) {
+ const src = ctx.createBufferSource();
+ src.buffer = buffer;
+ const hp = ctx.createBiquadFilter();
+ hp.type = 'highpass';
+ hp.frequency.value = 7200;
+ const peak = ctx.createBiquadFilter();
+ peak.type = 'peaking';
+ peak.frequency.value = 10500;
+ peak.gain.value = 6;
+ const g = ctx.createGain();
+ hit(g.gain, at, level, 0.0008, open ? 0.24 : 0.04);
+ src.connect(hp).connect(peak).connect(g).connect(out);
+ play(ctx, src, at, at + (open ? 0.5 : 0.12));
+}
+
+function drums(ctx, out, room) {
+ const kit = ctx.createGain();
+ kit.gain.value = 0.9;
+ kit.connect(out);
+ const hats = ctx.createStereoPanner();
+ hats.pan.value = 0.22;
+ hats.connect(kit);
+ const buffer = noise(ctx, 1, 7);
+ const random = seeded(23);
+ // After the intro the first beat is the drop's (build), not the groove's.
+ for (const k of kickTimes) if (!(LONG && k === GROOVE.from)) kick(ctx, kit, k, 1, buffer);
+ for (let bar = GROOVE.from; bar < GROOVE.until - 1e-6; bar += BAR) {
+ // The backbeat on the third beat; the last bar before the build is left to the roll.
+ if (bar < SCENES.usage + BAR - 1e-6) snare(ctx, kit, bar + 8 * STEP, 1, buffer, room);
+ for (let s = 0; s < 16; s++) {
+ const busy = bar >= SCENES.search;
+ if (s % 2 && !busy) continue;
+ const open = s === 14;
+ const accent = s % 4 === 2 ? 1 : s % 2 ? 0.45 : 0.7;
+ hat(ctx, hats, bar + s * STEP + (s % 2 ? 0.006 : 0), (0.1 + random() * 0.05) * accent * (open ? 0.8 : 1), open, buffer);
+ }
+ }
+}
+
+// Into the end card: a snare roll that speeds up and climbs, then everything drops
+// out for the riser (the effects stem's), and the impact lands on the name.
+function build(ctx, out, room) {
+ const buffer = noise(ctx, 1, 13);
+ const from = SCENES.usage + BAR;
+ const rolls = [];
+ for (let t = from; t < from + BEAT * 2 - 1e-6; t += BEAT / 2) rolls.push(t);
+ for (let t = from + BEAT * 2; t < from + BEAT * 3 - 1e-6; t += STEP) rolls.push(t);
+ for (let t = from + BEAT * 3; t < RISE - 1e-6; t += STEP / 2) rolls.push(t);
+ rolls.forEach((t, i) => snare(ctx, out, t, 0.35 + 0.65 * (i / rolls.length), buffer, room));
+ // The impact's drums: a big low kick, and a crash that rings out; a smaller pair on the drop.
+ const crash = (at, size) => {
+ kick(ctx, out, at, size, buffer);
+ const src = ctx.createBufferSource();
+ src.buffer = noise(ctx, 3, 29, true);
+ const hp = ctx.createBiquadFilter();
+ hp.type = 'highpass';
+ hp.frequency.value = 4200;
+ const g = ctx.createGain();
+ hit(g.gain, at, 0.22 * (size - 0.25), 0.002, 2.2 * (size - 0.25));
+ src.connect(hp).connect(g).connect(out);
+ const send = ctx.createGain();
+ send.gain.value = 0.4;
+ g.connect(send).connect(room);
+ play(ctx, src, at, at + 3);
+ };
+ crash(IMPACT, 1.25);
+ if (LONG) crash(INTRO, 1.1);
+}
+
+// The chord on the impact: all the saws at once, the filter wide open and closing.
+function stab(ctx, out) {
+ const [root, voices] = chordAt(Math.round(IMPACT / BAR));
+ const filter = ctx.createBiquadFilter();
+ filter.type = 'lowpass';
+ filter.frequency.setValueAtTime(9000, IMPACT);
+ filter.frequency.exponentialRampToValueAtTime(1400, IMPACT + 1.2);
+ filter.connect(out);
+ for (const note of [root + 24, ...voices, voices[2] + 12]) {
+ for (const cents of [-12, 0, 12]) {
+ const osc = ctx.createOscillator();
+ osc.type = 'sawtooth';
+ osc.frequency.value = hz(note);
+ osc.detune.value = cents;
+ const g = ctx.createGain();
+ hit(g.gain, IMPACT, 0.035, 0.004, 1.4);
+ osc.connect(g).connect(filter);
+ play(ctx, osc, IMPACT, IMPACT + 2.5);
+ }
+ }
+}
+
+// ----------------------------------------------------------------- the effects
+
+function effects(ctx, out, cues) {
+ const room = reverbOf(ctx, out, 1.8, 41, 0.9);
+ const hall = reverbOf(ctx, out, 3.8, 43, 1);
+ const echoes = pingPong(ctx, out, BEAT * 0.75, 0.42);
+ const buffer = noise(ctx, 1, 51);
+ const air = noise(ctx, 4, 53, true);
+ const random = seeded(61);
+ let ticks = 0;
+ for (const cue of cues) {
+ const at = cue.at;
+ if (cue.kind === 'whoosh') whoosh(ctx, out, room, air, at, cue.pan, cue.size);
+ else if (cue.kind === 'key') key(ctx, out, at, 1 + (random() - 0.5) * 0.12, buffer);
+ else if (cue.kind === 'click') { key(ctx, out, at, 0.62, buffer, 1.3); key(ctx, out, at + 0.075, 0.7, buffer, 0.8); }
+ else if (cue.kind === 'pop') blip(ctx, bus(ctx, out, { reverb: room, wet: 0.2 }), at, 620, 1120, 0.16);
+ else if (cue.kind === 'tick') { blip(ctx, bus(ctx, out, { reverb: room, wet: 0.25 }), at, hz(76 + [0, 3, 7, 10, 12][ticks % 5]), null, 0.08); ticks++; }
+ else if (cue.kind === 'chime') bell(ctx, bus(ctx, out, { reverb: hall, wet: 0.45, delay: echoes, echo: 0.25 }), at, hz(88), 0.09);
+ else if (cue.kind === 'riser') riser(ctx, out, hall, at, cue.until);
+ else if (cue.kind === 'impact') impact(ctx, out, hall, at);
+ else if (cue.kind === 'drop') impact(ctx, out, hall, at, 0.65);
+ else if (cue.kind === 'gather') gather(ctx, out, hall, air, at, cue.until);
+ else if (cue.kind === 'blip') data(ctx, bus(ctx, out, { reverb: room, wet: 0.3, delay: echoes, echo: 0.18 }), at, cue.pan, cue.depth, random);
+ else if (cue.kind === 'shimmer') [81, 84, 88, 93, 95, 100].forEach((n, i) => bell(ctx, bus(ctx, out, { reverb: hall, wet: 0.6, delay: echoes, echo: 0.3 }), at + i * 0.045, hz(n), 0.05));
+ }
+}
+
+// Air rushing past as the camera moves: noise through a band that sweeps up into the
+// cut and falls away after it, travelling across the stereo field the way the move goes.
+function whoosh(ctx, out, room, buffer, at, pan, size) {
+ const src = ctx.createBufferSource();
+ src.buffer = buffer;
+ const bp = ctx.createBiquadFilter();
+ bp.type = 'bandpass';
+ bp.Q.value = 1.1;
+ bp.frequency.setValueAtTime(260, at - 0.45);
+ bp.frequency.exponentialRampToValueAtTime(3800, at);
+ bp.frequency.exponentialRampToValueAtTime(520, at + 0.4);
+ const g = ctx.createGain();
+ g.gain.setValueAtTime(0.0001, at - 0.45);
+ g.gain.exponentialRampToValueAtTime(0.55 * size, at);
+ g.gain.exponentialRampToValueAtTime(0.0001, at + 0.42);
+ const p = ctx.createStereoPanner();
+ p.pan.setValueAtTime(-pan * 0.8, at - 0.45);
+ p.pan.linearRampToValueAtTime(pan * 0.8, at + 0.4);
+ src.connect(bp).connect(g).connect(p).connect(out);
+ const send = ctx.createGain();
+ send.gain.value = 0.25;
+ p.connect(send).connect(room);
+ play(ctx, src, at - 0.45, at + 0.5);
+ if (size >= 0.8) {
+ // Under the bigger moves, a soft low thump on the cut itself.
+ const thump = ctx.createOscillator();
+ thump.frequency.setValueAtTime(90, at);
+ thump.frequency.exponentialRampToValueAtTime(45, at + 0.18);
+ const gt = ctx.createGain();
+ hit(gt.gain, at, 0.4 * size, 0.004, 0.22);
+ thump.connect(gt).connect(out);
+ play(ctx, thump, at, at + 0.4);
+ }
+}
+
+// A key or button: a tiny bright tick with a little body under it.
+function key(ctx, out, at, pitch, buffer, level = 1) {
+ const osc = ctx.createOscillator();
+ osc.frequency.setValueAtTime(2900 * pitch, at);
+ osc.frequency.exponentialRampToValueAtTime(1700 * pitch, at + 0.012);
+ const g = ctx.createGain();
+ hit(g.gain, at, 0.09 * level, 0.0006, 0.018);
+ osc.connect(g).connect(out);
+ play(ctx, osc, at, at + 0.06);
+ const src = ctx.createBufferSource();
+ src.buffer = buffer;
+ const hp = ctx.createBiquadFilter();
+ hp.type = 'highpass';
+ hp.frequency.value = 4500;
+ const gn = ctx.createGain();
+ hit(gn.gain, at, 0.12 * level, 0.0004, 0.006);
+ src.connect(hp).connect(gn).connect(out);
+ play(ctx, src, at, at + 0.03);
+}
+
+// A soft rounded blip, gliding up when `to` is given.
+function blip(ctx, out, at, from, to, level) {
+ const osc = ctx.createOscillator();
+ osc.frequency.setValueAtTime(from, at);
+ if (to) osc.frequency.exponentialRampToValueAtTime(to, at + 0.07);
+ const g = ctx.createGain();
+ hit(g.gain, at, level, 0.004, 0.14);
+ osc.connect(g).connect(out);
+ play(ctx, osc, at, at + 0.3);
+}
+
+// A bell: a few inharmonic partials, the higher ones dying first.
+function bell(ctx, out, at, f, level) {
+ for (const [ratio, part, decay] of [[1, 1, 1.4], [2.76, 0.45, 0.6], [5.4, 0.25, 0.3], [8.93, 0.12, 0.15]]) {
+ const osc = ctx.createOscillator();
+ osc.frequency.value = f * ratio;
+ const g = ctx.createGain();
+ hit(g.gain, at, level * part, 0.002, decay);
+ osc.connect(g).connect(out);
+ play(ctx, osc, at, at + decay * 1.6 + 0.1);
+ }
+}
+
+// The rise into the impact: noise sweeping up, a saw climbing two octaves, and a
+// reversed-cymbal swell in the last moments, all stopping dead on the impact.
+function riser(ctx, out, hall, from, until) {
+ const length = until - from;
+ const src = ctx.createBufferSource();
+ src.buffer = noise(ctx, length + 0.1, 71, true);
+ const bp = ctx.createBiquadFilter();
+ bp.type = 'bandpass';
+ bp.Q.value = 1.4;
+ bp.frequency.setValueAtTime(380, from);
+ bp.frequency.exponentialRampToValueAtTime(9000, until);
+ const g = ctx.createGain();
+ g.gain.setValueAtTime(0.0001, from);
+ g.gain.exponentialRampToValueAtTime(0.42, until - 0.01);
+ g.gain.linearRampToValueAtTime(0, until);
+ src.connect(bp).connect(g).connect(out);
+ const send = ctx.createGain();
+ send.gain.value = 0.35;
+ g.connect(send).connect(hall);
+ play(ctx, src, from, until);
+
+ const saw = ctx.createOscillator();
+ saw.type = 'sawtooth';
+ saw.frequency.setValueAtTime(hz(45), from);
+ saw.frequency.exponentialRampToValueAtTime(hz(69), until);
+ const lp = ctx.createBiquadFilter();
+ lp.type = 'lowpass';
+ lp.frequency.setValueAtTime(400, from);
+ lp.frequency.exponentialRampToValueAtTime(5000, until);
+ const gs = ctx.createGain();
+ gs.gain.setValueAtTime(0.0001, from);
+ gs.gain.exponentialRampToValueAtTime(0.08, until - 0.01);
+ gs.gain.linearRampToValueAtTime(0, until);
+ saw.connect(lp).connect(gs).connect(out);
+ play(ctx, saw, from, until);
+
+ const swell = ctx.createBufferSource();
+ swell.buffer = noise(ctx, 0.6, 73, true);
+ const hp = ctx.createBiquadFilter();
+ hp.type = 'highpass';
+ hp.frequency.value = 5200;
+ const gw = ctx.createGain();
+ gw.gain.setValueAtTime(0.0001, until - 0.5);
+ gw.gain.exponentialRampToValueAtTime(0.3, until - 0.01);
+ gw.gain.linearRampToValueAtTime(0, until);
+ swell.connect(hp).connect(gw).connect(out);
+ play(ctx, swell, until - 0.5, until);
+}
+
+// The impact: a sub drop you feel more than hear, a burst of noise into a long
+// plate, and a low boom under both.
+function impact(ctx, out, hall, at, size = 1) {
+ out = bus(ctx, out, { gain: size });
+ const sub = ctx.createOscillator();
+ sub.frequency.setValueAtTime(62, at);
+ sub.frequency.exponentialRampToValueAtTime(29, at + 1.4);
+ const gs = ctx.createGain();
+ hit(gs.gain, at, 0.9, 0.003, 2.0);
+ const warm = shaper(ctx, 1.4);
+ sub.connect(gs).connect(warm).connect(out);
+ play(ctx, sub, at, at + 2.6);
+
+ const burst = ctx.createBufferSource();
+ burst.buffer = noise(ctx, 1.2, 79, true);
+ const lp = ctx.createBiquadFilter();
+ lp.type = 'lowpass';
+ lp.frequency.setValueAtTime(5200, at);
+ lp.frequency.exponentialRampToValueAtTime(300, at + 0.8);
+ const gb = ctx.createGain();
+ hit(gb.gain, at, 0.55, 0.002, 0.7);
+ burst.connect(lp).connect(gb).connect(out);
+ const send = ctx.createGain();
+ send.gain.value = 0.9;
+ gb.connect(send).connect(hall);
+ play(ctx, burst, at, at + 1.2);
+
+ const boom = ctx.createOscillator();
+ boom.type = 'triangle';
+ boom.frequency.setValueAtTime(110, at);
+ boom.frequency.exponentialRampToValueAtTime(52, at + 0.3);
+ const gm = ctx.createGain();
+ hit(gm.gain, at, 0.45, 0.002, 0.5);
+ boom.connect(gm).connect(out);
+ play(ctx, boom, at, at + 0.8);
+}
+
+// An outline appearing: a short digital blip where it is, higher the further away.
+function data(ctx, out, at, pan, depth, random) {
+ const f = [740, 1110, 1480][depth] * (1 + (random() - 0.5) * 0.04);
+ const osc = ctx.createOscillator();
+ osc.type = 'triangle';
+ osc.frequency.setValueAtTime(f * 1.5, at);
+ osc.frequency.exponentialRampToValueAtTime(f, at + 0.02);
+ const g = ctx.createGain();
+ hit(g.gain, at, [0.075, 0.06, 0.045][depth], 0.002, 0.07);
+ const p = ctx.createStereoPanner();
+ p.pan.value = pan * 0.75;
+ osc.connect(g).connect(p).connect(out);
+ play(ctx, osc, at, at + 0.15);
+}
+
+// The gathering: air drawn in, narrowing and rising, and a tone sweeping up under it,
+// stopping dead on the drop.
+function gather(ctx, out, hall, air, from, until) {
+ const src = ctx.createBufferSource();
+ src.buffer = air;
+ const lp = ctx.createBiquadFilter();
+ lp.type = 'lowpass';
+ lp.Q.value = 2;
+ lp.frequency.setValueAtTime(300, from);
+ lp.frequency.exponentialRampToValueAtTime(7000, until);
+ const g = ctx.createGain();
+ g.gain.setValueAtTime(0.0001, from);
+ g.gain.exponentialRampToValueAtTime(0.38, until - 0.01);
+ g.gain.linearRampToValueAtTime(0, until);
+ src.connect(lp).connect(g).connect(out);
+ const send = ctx.createGain();
+ send.gain.value = 0.3;
+ g.connect(send).connect(hall);
+ play(ctx, src, from, until);
+ const tone = ctx.createOscillator();
+ tone.frequency.setValueAtTime(180, from);
+ tone.frequency.exponentialRampToValueAtTime(1300, until);
+ const gt = ctx.createGain();
+ gt.gain.setValueAtTime(0.0001, from);
+ gt.gain.exponentialRampToValueAtTime(0.09, until - 0.01);
+ gt.gain.linearRampToValueAtTime(0, until);
+ tone.connect(gt).connect(out);
+ play(ctx, tone, from, until);
+}
+
+// --------------------------------------------------------------------- output
+
+async function render(build) {
+ const ctx = new OfflineAudioContext(2, Math.ceil((LENGTH + TAIL) * RATE), RATE);
+ const out = ctx.createGain();
+ out.connect(ctx.destination);
+ build(ctx, out);
+ return ctx.startRendering();
+}
+
+// A 32-bit float WAV, so nothing is clipped before the master, as base64.
+function wav(buffer) {
+ const frames = buffer.length;
+ const bytes = new DataView(new ArrayBuffer(44 + frames * 8));
+ const text = (at, s) => [...s].forEach((c, i) => bytes.setUint8(at + i, c.charCodeAt(0)));
+ text(0, 'RIFF'); bytes.setUint32(4, 36 + frames * 8, true); text(8, 'WAVE');
+ text(12, 'fmt '); bytes.setUint32(16, 16, true); bytes.setUint16(20, 3, true); bytes.setUint16(22, 2, true);
+ bytes.setUint32(24, RATE, true); bytes.setUint32(28, RATE * 8, true); bytes.setUint16(32, 8, true); bytes.setUint16(34, 32, true);
+ text(36, 'data'); bytes.setUint32(40, frames * 8, true);
+ const [left, right] = [buffer.getChannelData(0), buffer.getChannelData(1)];
+ for (let i = 0; i < frames; i++) {
+ bytes.setFloat32(44 + i * 8, left[i], true);
+ bytes.setFloat32(48 + i * 8, right[i], true);
+ }
+ const all = new Uint8Array(bytes.buffer);
+ let out = '';
+ for (let i = 0; i < all.length; i += 0x8000) out += String.fromCharCode(...all.subarray(i, i + 0x8000));
+ return btoa(out);
+}
+
+window.renderStems = async (cues) => ({
+ music: wav(await render((ctx, out) => compose(ctx, out))),
+ fx: wav(await render((ctx, out) => effects(ctx, out, cues))),
+});
+window.ready = true;
diff --git a/docs/record-demo/paddock-film/stage.html b/docs/record-demo/paddock-film/stage.html
new file mode 100644
index 0000000..047e9a9
--- /dev/null
+++ b/docs/record-demo/paddock-film/stage.html
@@ -0,0 +1,59 @@
+
+
+
+
+Paddock film
+
+
+
+
+
+
+
diff --git a/docs/record-demo/paddock-film/stage.js b/docs/record-demo/paddock-film/stage.js
new file mode 100644
index 0000000..34b0113
--- /dev/null
+++ b/docs/record-demo/paddock-film/stage.js
@@ -0,0 +1,538 @@
+// The Paddock film's picture. `render(t)` draws the frame at `t` seconds and
+// nothing else: no CSS transitions or animations, so film.mjs can draw any frame
+// in any order and get the same picture every time.
+//
+// The page is the real app's stills (record.mjs --film paddock) in a window on a
+// dark stage, moved by a camera, with headlines, labels, a pointer and the end
+// card drawn over it. ?w=&h= is the frame's size: 1080×1350 (4:5) or 1080×1080.
+// ?cut=long opens on the abstract intro (timeline.js) before the app.
+
+import { seeded, timeline } from './timeline.js';
+
+const params = new URLSearchParams(location.search);
+const W = Number(params.get('w') || 1080);
+const H = Number(params.get('h') || 1350);
+const TALL = H / W > 1.1;
+const CUT = params.get('cut') || 'short';
+const LONG = CUT === 'long';
+const {
+ BEAT, BAR, LENGTH, INTRO, SCENES, RISE, IMPACT, GATHER, OUTLINES, SAID, WORD, typedAt, PICK, RESUME, LABELS, RING, barAt,
+} = timeline(CUT);
+
+// ------------------------------------------------------------------- easing
+
+const clamp = (v, lo = 0, hi = 1) => Math.min(hi, Math.max(lo, v));
+const lerp = (a, b, p) => a + (b - a) * p;
+const progress = (t, from, length) => clamp((t - from) / length);
+const outExpo = (p) => (p >= 1 ? 1 : 1 - 2 ** (-10 * p));
+const outCubic = (p) => 1 - (1 - p) ** 3;
+const inCubic = (p) => p ** 3;
+const inOutSine = (p) => 0.5 - 0.5 * Math.cos(Math.PI * p);
+const inOutCubic = (p) => (p < 0.5 ? 4 * p ** 3 : 1 - (-2 * p + 2) ** 3 / 2);
+// A critically damped spring, reaching exactly 1 at p = 1.
+const spring = (p) => {
+ const w = 7.5;
+ const f = (x) => 1 - (1 + w * x) * Math.exp(-w * x);
+ return f(p) / f(1);
+};
+// An underdamped one, for things that pop: a little past 1 and back.
+const pop = (p) => (p >= 1 ? 1 : 1 - Math.exp(-6 * p) * Math.cos(9 * p));
+
+// --------------------------------------------------------------------- DOM
+
+const css = (el, rules) => { for (const [k, v] of Object.entries(rules)) el.style.setProperty(k, typeof v === 'number' ? `${v}px` : v); return el; };
+const make = (tag, attrs = {}, ...children) => {
+ const el = document.createElement(tag);
+ for (const [k, v] of Object.entries(attrs)) {
+ if (k === 'style') css(el, v); else if (k === 'class') el.className = v; else el.setAttribute(k, v);
+ }
+ el.append(...children);
+ return el;
+};
+const $ = (id) => document.getElementById(id);
+
+const shots = await (await fetch('/shots/shots.json')).json();
+const VIEW = shots.view;
+const shot = Object.fromEntries(shots.shots.map((s) => [s.name, s]));
+const box = (name, key) => shot[name].boxes[key];
+const mid = (b) => ({ x: b.x + b.w / 2, y: b.y + b.h / 2 });
+
+// The window: as wide as the frame allows, below the headline.
+const PAD = Math.round(W * 0.055);
+const HEAD = { top: Math.round(H * (TALL ? 0.07 : 0.06)), size: TALL ? 78 : 66 };
+const HEAD_BOTTOM = HEAD.top + HEAD.size * 2.1;
+const WIN_W = W - 2 * PAD;
+const SCALE = WIN_W / VIEW.width;
+const TITLE = Math.round(WIN_W * 0.032);
+const WIN_H = TITLE + VIEW.height * SCALE;
+// Where the camera's focus sits on screen: the middle of the room under the headline.
+const ANCHOR = { x: W / 2, y: HEAD_BOTTOM + (H - HEAD_BOTTOM) / 2 + (TALL ? 10 : 6) };
+
+const stage = css($('stage'), { width: W, height: H });
+const aurora = make('div', { class: 'layer', id: 'aurora' });
+const warm = make('div', { class: 'glow' });
+const cool = make('div', { class: 'glow' });
+const deep = make('div', { class: 'glow' });
+aurora.append(deep, warm, cool);
+
+const content = make('div', { id: 'content', style: { width: WIN_W, height: VIEW.height * SCALE } });
+const images = {};
+for (const s of shots.shots) {
+ const img = make('img', { src: `/shots/${s.file}`, alt: '' });
+ images[s.name] = img;
+ content.append(img);
+}
+const marks = make('div', { class: 'mark', style: { transform: `scale(${SCALE})`, width: VIEW.width, height: VIEW.height, left: 0, top: 0 } });
+content.append(marks);
+const lights = make('div', { id: 'lights', style: { left: TITLE * 0.55, gap: TITLE * 0.28 } },
+ ...['#ff5f57', '#febc2e', '#28c840'].map((c) => make('i', { style: { width: TITLE * 0.4, height: TITLE * 0.4, background: c } })));
+const titlebar = make('div', { id: 'titlebar', style: { height: TITLE, 'font-size': TITLE * 0.42 } }, lights, 'Paddock');
+const win = make('div', { id: 'window', style: { width: WIN_W, height: WIN_H } }, titlebar, content);
+const camera = make('div', { id: 'camera', style: { width: WIN_W, height: WIN_H } }, win);
+
+// Marks drawn on the page, in its own pixels (they move and scale with it).
+const ring = (b, color) => marks.appendChild(make('div', { class: 'ring', style: {
+ left: b.x - 5, top: b.y - 5, width: b.w + 10, height: b.h + 10, border: `2.5px solid ${color}`,
+ 'box-shadow': `0 0 0 4px ${color}33, 0 0 28px 6px ${color}66`, opacity: 0 } }));
+const codexRing = ring(box('all', 'codexChip'), '#2fd3bd');
+const resumeRing = ring(box('picked', 'resume'), '#2fd3bd');
+const covers = box('usage', 'bars').map((bar, n) => {
+ const value = box('usage', 'values')[n];
+ const right = value.x + value.w + 4;
+ return marks.appendChild(make('div', { class: 'cover', style: { left: bar.x - 2, top: Math.min(bar.y, value.y) - 2, width: right - bar.x + 2, height: Math.max(bar.h, value.h) + 4 } }));
+});
+
+// Labels and the pointer: pinned to the page but kept one size on screen.
+const toolPill = (text, color) => make('div', { class: 'pill', style: {
+ 'font-size': 25, gap: 10, padding: '9px 18px 9px 13px', background: `linear-gradient(180deg, ${color[0]}, ${color[1]})`,
+ 'box-shadow': `0 8px 26px ${color[1]}88, inset 0 1px 0 rgb(255 255 255 / 0.35)` } },
+ make('b', { style: { width: 11, height: 11, background: 'rgb(255 255 255 / 0.95)' } }), text);
+const claudePill = toolPill('Claude Code', ['#f7a15a', '#d9692f']);
+const codexPill = toolPill('Codex', ['#3ad8c2', '#16998b']);
+const pointer = make('div', { id: 'pointer' });
+pointer.innerHTML = '';
+const ripple = make('div', { class: 'ring', style: { 'border-radius': '50%', border: '3px solid #ffffff', opacity: 0 } });
+const pinned = make('div', { class: 'mark', style: { left: 0, top: 0 } }, claudePill, codexPill, ripple, pointer);
+win.append(pinned);
+
+// Headlines: words that rise into place, sharpen and settle, a line at a time
+// (`starts` says when each line begins). The intro's are bigger, in the middle.
+const headline = make('div', { class: 'headline', style: { top: HEAD.top, 'font-size': HEAD.size, 'line-height': '1.06' } });
+const INTRO_SIZE = TALL ? 88 : 76;
+const introType = make('div', { class: 'headline', style: { top: H / 2 - INTRO_SIZE * 1.65, 'font-size': INTRO_SIZE, 'line-height': '1.08' } });
+const HEADLINES = [
+ ...(LONG ? [{ parent: introType, from: SAID[0], to: GATHER - 0.25, starts: SAID,
+ lines: [[['23'], ['sessions'], ['open.']], [['15', 'done'], ['already', 'done'], ['done.', 'done']], [['3', 'waiting'], ['waiting', 'waiting'], ['on'], ['me.']]] }] : []),
+ { from: LONG ? INTRO + 0.05 : -0.32, to: SCENES.all, lines: [[['Claude Code', 'claude'], ['and'], ['Codex.', 'codex']], [['One'], ['place.']]], second: SCENES.both + BAR - 0.05 },
+ { from: SCENES.all + 0.08, to: SCENES.search, lines: [[['Every'], ['session.']], [['Every'], ['account.', 'both']]], second: SCENES.all + BAR * 0.5 },
+ { from: SCENES.search + 0.08, to: SCENES.usage, lines: [[['Search'], ['both.']], [['Resume'], ['either.', 'both']]], second: PICK - 0.05 },
+ { from: SCENES.usage + 0.08, to: RISE + 0.1, lines: [[['Tokens'], ['from'], ['both,']], [['by'], ['model.', 'both']]], second: SCENES.usage + BAR * 0.5 },
+].map((spec) => {
+ const lines = spec.lines.map((words) => make('div', { class: 'line' }, ...words.flatMap(([text, kind], i) => [
+ ...(i ? [' '] : []), make('span', { class: `word ${kind || ''}` }, text)])));
+ const el = make('div', {}, ...lines);
+ (spec.parent || headline).append(el);
+ return { size: spec.parent ? INTRO_SIZE : HEAD.size, starts: spec.starts || [spec.from, spec.second], ...spec, el,
+ words: lines.map((line) => [...line.querySelectorAll('.word')]) };
+});
+
+// The end card: the old name, which breaks up on the impact as the new one forms.
+const letters = (text) => [...text].map((ch) => make('span', {}, ch));
+const oldName = make('div', { id: 'old', style: { 'font-size': TALL ? 116 : 104, color: '#d8d8de' } }, ...letters('cc-sessions'));
+const newName = make('div', { id: 'name', style: { 'font-size': TALL ? 168 : 150 } }, ...letters('Paddock'));
+const names = make('div', { id: 'names' }, oldName, newName);
+const sub = make('div', { id: 'sub', style: { 'font-size': TALL ? 40 : 36, 'margin-top': TALL ? 26 : 20 } }, 'Claude Code + Codex, in one place');
+const small = make('div', { id: 'small', style: { 'font-size': TALL ? 26 : 24, 'margin-top': 18 } }, 'Formerly cc-sessions · Free and open source · macOS, Windows, Linux');
+const url = make('div', { id: 'url', style: { 'font-size': TALL ? 27 : 25, 'margin-top': TALL ? 46 : 36, padding: '13px 24px' } }, 'github.com/barath-dev/paddock');
+const bloom = make('div', { id: 'bloom', style: { width: W * 1.1, height: W * 0.7, left: -W * 0.05, top: H / 2 - W * 0.35 } });
+const end = make('div', { id: 'end', class: 'layer' }, names, sub, small, url);
+const endLayer = make('div', { class: 'layer' }, bloom, end);
+
+// Film grain: a few tiles of noise, one per frame at 24 a second, like film.
+const grain = make('div', { class: 'layer', id: 'grain' });
+const GRAIN = Array.from({ length: 8 }, (_, n) => {
+ const c = document.createElement('canvas');
+ c.width = c.height = 256;
+ const g = c.getContext('2d');
+ const data = g.createImageData(256, 256);
+ const random = seeded(n + 1);
+ for (let i = 0; i < data.data.length; i += 4) {
+ const v = 128 + (random() + random() + random() - 1.5) * 150;
+ data.data[i] = data.data[i + 1] = data.data[i + 2] = v;
+ data.data[i + 3] = 255;
+ }
+ g.putImageData(data, 0, 0);
+ return `url(${c.toDataURL()})`;
+});
+
+// A dark fall-off at the top, so a headline reads however close the camera is.
+const scrim = make('div', { class: 'layer', style: {
+ background: `linear-gradient(180deg, rgb(6 7 10 / 0.97) 0px, rgb(6 7 10 / 0.9) ${HEAD_BOTTOM - 30}px, rgb(6 7 10 / 0) ${HEAD_BOTTOM + 70}px)` } });
+
+// The intro: the open sessions as terminal outlines, each a title rule, a few lines
+// of text and sometimes a cursor, in the colours Paddock gives their states (working
+// blue, idle grey; done green and waiting amber once the type has said so); a pool
+// of dark behind the type; and the flash the window arrives in.
+const STATE = { neutral: [205, 210, 222], working: [96, 165, 250], idle: [140, 146, 160], done: [74, 222, 128], waiting: [245, 165, 36] };
+const DEPTH = [{ scale: 1, blur: 0, alpha: 1, drift: 16 }, { scale: 0.74, blur: 1.4, alpha: 0.72, drift: 10 }, { scale: 0.54, blur: 3.2, alpha: 0.48, drift: 6 }];
+const BASE = W * 0.17;
+const outlines = OUTLINES.map((o) => {
+ const random = seeded(o.seed);
+ const bars = Array.from({ length: o.lines }, () => make('i', { style: { display: 'block', height: 3, 'border-radius': 2,
+ width: `${35 + random() * 50}%`, margin: '0 0 7px 0' } }));
+ const cursor = make('i', { style: { display: o.cursor || o.state === 'working' ? 'block' : 'none', width: 8, height: 12, 'border-radius': 1 } });
+ const tick = make('div', { style: { position: 'absolute', right: 8, top: 6, opacity: 0 } });
+ tick.innerHTML = '';
+ const rule = make('i', { style: { display: 'block', height: 0, 'border-top': '1.5px solid', margin: '0 0 10px 0' } });
+ const el = make('div', { style: { position: 'absolute', left: 0, top: 0, 'border-radius': 10, padding: '0 12px', overflow: 'hidden',
+ 'border-width': '1.5px', 'border-style': 'solid', 'transform-origin': '50% 50%' } }, rule, ...bars, cursor, tick);
+ const angle = random() * Math.PI * 2;
+ return { ...o, el, rule, bars, cursor, tick, dir: [Math.cos(angle), Math.sin(angle)], phase: random() * 10 };
+});
+const introLayer = make('div', { class: 'layer' }, ...outlines.map((o) => o.el));
+const pool = make('div', { class: 'glow', style: { width: W * 1.05, height: INTRO_SIZE * 5.2, left: -W * 0.025, top: H / 2 - INTRO_SIZE * 2.6,
+ background: 'radial-gradient(closest-side, rgb(6 7 10 / 0.88), rgb(6 7 10 / 0.6) 55%, transparent)' } });
+const flash = make('div', { class: 'glow', style: { width: W * 1.6, height: W * 1.2, left: -W * 0.3, top: H / 2 - W * 0.6,
+ background: 'radial-gradient(closest-side, rgb(255 250 240 / 0.95), rgb(255 220 180 / 0.35) 40%, transparent)', opacity: 0 } });
+introLayer.append(pool, introType);
+
+// The name in a corner once the app is on screen, for anyone who scrolls on before the end card.
+const mark = make('div', { style: { position: 'absolute', left: PAD, bottom: Math.round(PAD * 0.75), display: 'flex', 'align-items': 'center', gap: 10,
+ 'font-size': 26, 'font-weight': 740, 'letter-spacing': '-0.03em', color: '#ffffff', padding: '9px 16px 9px 13px', 'border-radius': 14,
+ background: 'rgb(10 12 16 / 0.78)', 'box-shadow': '0 0 0 1px rgb(255 255 255 / 0.12), 0 8px 24px rgb(0 0 0 / 0.35)', 'backdrop-filter': 'blur(10px)' } },
+ make('b', { style: { display: 'block', width: 14, height: 14, 'border-radius': 4, background: 'linear-gradient(135deg, #f7a35c, #39d5c0)',
+ 'box-shadow': '0 0 14px rgb(120 200 190 / 0.6)' } }), 'Paddock');
+stage.append(aurora, introLayer, camera, scrim, headline, flash, mark, endLayer, make('div', { class: 'layer', id: 'vignette' }), grain);
+
+// ------------------------------------------------------------------ camera
+
+// Where the camera looks (a point on the page, in its pixels), how close, and how
+// the window is turned. A move eases from wherever the last one had got to; `cut`
+// starts from its own `start` instead, as a cut to a new picture does.
+const folderMid = { x: 680, y: (box('folder', 'claude').y + box('folder', 'codex').y + box('folder', 'codex').h) / 2 };
+const search = mid(box('search', 'search'));
+const picked = box('picked', 'panel');
+const models = box('usage', 'byModel');
+// After the intro the window arrives whole, where the outlines gathered, and the
+// camera then moves in on the two sessions as it does from the start of the short cut.
+const ARRIVE = { x: VIEW.width / 2, y: VIEW.height / 2, z: 1.0, rx: 0, ry: 0 };
+const MOVES = [
+ ...(LONG ? [{ t: 0, dur: 0.01, ...ARRIVE }, { t: INTRO + 0.05, dur: SCENES.all - INTRO - 0.1, ease: inOutCubic, x: folderMid.x, y: folderMid.y, z: 1.9, rx: 5, ry: -3 }]
+ : [{ t: 0, dur: 0.01, x: folderMid.x - 40, y: folderMid.y + 6, z: 1.72, rx: 16, ry: -14 },
+ { t: 0, dur: SCENES.all - 0.05, ease: inOutSine, x: folderMid.x, y: folderMid.y, z: 1.9, rx: 5, ry: -3 }]),
+ { t: SCENES.all, dur: 0.95, x: VIEW.width / 2, y: VIEW.height / 2 + 10, z: 1.0, rx: 0, ry: 0 },
+ { t: SCENES.all + 1.25, dur: 1.4, x: mid(box('all', 'chips')).x, y: box('all', 'chips').y + 120, z: 1.32, rx: 0, ry: 0 },
+ { t: SCENES.search, dur: 0.6, x: search.x + 60, y: search.y + 40, z: 2.0, rx: 0, ry: 0 },
+ { t: typedAt(WORD.length - 1) + 0.22, dur: 0.7, x: VIEW.width * 0.52, y: 380, z: 1.22, rx: 0, ry: 0 },
+ { t: PICK + 0.1, dur: 0.75, x: picked.x + picked.w * 0.42, y: picked.y + 230, z: 1.75, rx: 0, ry: 0 },
+ { t: SCENES.usage, dur: 0.95, cut: true, start: { x: mid(models).x + 60, y: mid(models).y + 30, z: 1.7, rx: 18, ry: 16 },
+ x: mid(models).x, y: mid(models).y, z: 2.3, rx: 0, ry: 0 },
+ { t: SCENES.usage + 1.1, dur: RISE - SCENES.usage - 1.1, ease: inOutSine, x: mid(models).x + 10, y: mid(models).y, z: 2.42, rx: 0, ry: 0 },
+ { t: RISE, dur: IMPACT - RISE, ease: inCubic, x: mid(models).x, y: mid(models).y, z: 1.5, rx: -16, ry: 0 },
+];
+const KEYS = ['x', 'y', 'z', 'rx', 'ry'];
+// Each move's starting point: where the moves before it had got to by then.
+const starts = [];
+for (let i = 0; i < MOVES.length; i++) {
+ const m = MOVES[i];
+ starts.push(m.cut || i === 0 ? { ...(m.start || m) } : moveAt(i - 1, m.t));
+}
+function moveAt(i, t) {
+ const m = MOVES[i];
+ const p = (m.ease || spring)(progress(t, m.t, m.dur));
+ return Object.fromEntries(KEYS.map((k) => [k, lerp(starts[i][k], m[k], p)]));
+}
+function cameraAt(t) {
+ let i = 0;
+ while (i + 1 < MOVES.length && MOVES[i + 1].t <= t) i++;
+ return moveAt(i, t);
+}
+
+// The picture on the window at `t`.
+const PICTURES = [
+ [0, 'folder'], [SCENES.all, 'all'],
+ ...[...WORD].map((_, n) => [typedAt(n), `search-${n + 1}`]),
+ [typedAt(WORD.length - 1) + 0.2, 'search'], [PICK, 'picked'], [SCENES.usage, 'usage'],
+];
+const pictureAt = (t) => PICTURES.filter(([at]) => at <= t).at(-1)[1];
+
+// The pointer's path in the search scene: [time, x, y] on the page.
+const flaky = mid(box('search', 'codex'));
+const resume = mid(box('picked', 'resume'));
+const PATH = [
+ [PICK - 0.62, VIEW.width * 0.66, 640], [PICK - 0.05, flaky.x - 120, flaky.y + 4], [PICK + 0.32, flaky.x - 120, flaky.y + 4],
+ [RESUME - 0.08, resume.x + 6, resume.y + 4], [SCENES.usage, resume.x + 6, resume.y + 4],
+];
+function pointerAt(t) {
+ if (t < PATH[0][0] || t >= SCENES.usage) return null;
+ let i = 0;
+ while (i + 1 < PATH.length && PATH[i + 1][0] <= t) i++;
+ const [t0, x0, y0] = PATH[i];
+ const [t1, x1, y1] = PATH[Math.min(i + 1, PATH.length - 1)];
+ const p = t1 > t0 ? inOutCubic(progress(t, t0, t1 - t0)) : 1;
+ return { x: lerp(x0, x1, p), y: lerp(y0, y1, p), shown: outCubic(progress(t, PATH[0][0], 0.2)) };
+}
+
+// ------------------------------------------------------------------ render
+
+function backdrop(t) {
+ const lift = Math.exp(-((t - IMPACT - 0.2) ** 2) / 0.5);
+ const endGlow = clamp((t - RISE) / (IMPACT - RISE));
+ const size = Math.max(W, H);
+ css(deep, { width: size * 1.4, height: size * 1.4, left: W / 2 - size * 0.7, top: H * 0.55 - size * 0.7,
+ background: 'radial-gradient(closest-side, rgb(40 46 72 / 0.55), transparent)' });
+ css(warm, { width: size * 0.95, height: size * 0.75,
+ left: W * (0.02 + 0.05 * Math.sin(t * 0.35)) - size * 0.2, top: H * (0.1 + 0.04 * Math.cos(t * 0.3)) - size * 0.2,
+ background: `radial-gradient(closest-side, rgb(245 140 60 / ${0.34 + 0.25 * lift + 0.1 * endGlow}), transparent)` });
+ css(cool, { width: size * 0.95, height: size * 0.8,
+ left: W * (0.62 + 0.05 * Math.cos(t * 0.3)) - size * 0.2, top: H * (0.62 + 0.05 * Math.sin(t * 0.33)) - size * 0.2,
+ background: `radial-gradient(closest-side, rgb(40 205 185 / ${0.3 + 0.25 * lift + 0.1 * endGlow}), transparent)` });
+ grain.style.backgroundImage = GRAIN[Math.floor(t * 24) % GRAIN.length];
+}
+
+function drawWindow(t) {
+ const c = cameraAt(t);
+ // On the rise the window falls back into the dark and goes out of focus.
+ const away = inCubic(progress(t, RISE, IMPACT - RISE - 0.15));
+ // After the intro it comes in under the flash, where the outlines gathered.
+ const arrive = LONG ? outCubic(progress(t, INTRO - 0.12, 0.22)) : 1;
+ camera.style.opacity = String(arrive * (1 - away));
+ camera.style.visibility = arrive > 0 ? 'visible' : 'hidden';
+ scrim.style.opacity = String(arrive);
+ camera.style.filter = away > 0 ? `blur(${away * 18}px)` : 'none';
+ const ex = c.x * SCALE;
+ const ey = TITLE + c.y * SCALE;
+ camera.style.transform = `translate(${ANCHOR.x - ex * c.z}px, ${ANCHOR.y - ey * c.z}px) scale(${c.z})`;
+ win.style.transformOrigin = `${ex}px ${ey}px`;
+ win.style.transform = `perspective(${WIN_W * 2.2}px) rotateX(${c.rx}deg) rotateY(${c.ry}deg)`;
+
+ const now = pictureAt(t);
+ for (const [name, img] of Object.entries(images)) img.style.visibility = name === now ? 'visible' : 'hidden';
+
+ // Rings: the Codex account, then Resume, each drawn in and held.
+ const ringShow = (el, at, until) => {
+ const p = progress(t, at, 0.35);
+ const shown = t < until ? p : 0;
+ el.style.opacity = String(shown);
+ el.style.transform = `scale(${lerp(1.25, 1, outCubic(p))})`;
+ };
+ ringShow(codexRing, RING, SCENES.search);
+ ringShow(resumeRing, RESUME, SCENES.usage);
+
+ // Usage's bars grow in: the cover over each one slides off to the right.
+ covers.forEach((cover, n) => {
+ const p = outCubic(progress(t, barAt(n), 0.5));
+ cover.style.visibility = now === 'usage' ? 'visible' : 'hidden';
+ cover.style.transform = `scaleX(${1 - p})`;
+ });
+
+ // Labels and the pointer stay one size on screen however close the camera is.
+ const at = (el, x, y, scale = 1) => { el.style.transform = `translate(${x * SCALE}px, ${TITLE + y * SCALE}px) scale(${scale / c.z})`; };
+ const label = (el, row, when) => {
+ const b = box('folder', row);
+ const p = progress(t, when, 0.55);
+ el.style.opacity = String(t < SCENES.all ? clamp(p * 3) : 0);
+ // Hung on the row's top edge, its right end just short of the account column,
+ // where the row and the one above have nothing to cover.
+ el.style.transformOrigin = '0 0';
+ at(el, b.x + b.w * 0.56, b.y + 1, lerp(0.6, 1, pop(p)));
+ el.style.translate = `${-el.offsetWidth}px ${-el.offsetHeight / 2}px`;
+ el.style.transformOrigin = `${el.offsetWidth}px ${el.offsetHeight / 2}px`;
+ };
+ label(claudePill, 'claude', LABELS[0]);
+ label(codexPill, 'codex', LABELS[1]);
+
+ const p = pointerAt(t);
+ pointer.style.opacity = p ? String(p.shown) : '0';
+ if (p) at(pointer, p.x, p.y);
+ const click = [PICK, RESUME].find((when) => t >= when && t < when + 0.45);
+ ripple.style.opacity = '0';
+ if (click !== undefined && p) {
+ const q = progress(t, click, 0.45);
+ const r = lerp(8, 34, outCubic(q));
+ ripple.style.opacity = String(0.9 * (1 - q));
+ ripple.style.width = ripple.style.height = `${2 * r}px`;
+ ripple.style.left = ripple.style.top = `${-r}px`;
+ at(ripple, p.x, p.y);
+ }
+}
+
+function drawHeadline(t) {
+ for (const h of HEADLINES) {
+ const shown = t >= h.from - 0.01 && t < h.to;
+ h.el.style.display = shown ? 'block' : 'none';
+ if (!shown) continue;
+ const leaving = outCubic(progress(t, h.to - 0.24, 0.24));
+ h.words.forEach((words, line) => {
+ const start = h.starts[line];
+ words.forEach((word, i) => {
+ const p = progress(t, start + i * 0.07, 0.62);
+ const e = outExpo(p);
+ const y = lerp(0.55, 0, e) * h.size - leaving * 0.35 * h.size;
+ const blur = lerp(14, 0, outCubic(p)) + leaving * 10;
+ word.style.opacity = String(clamp(p * 2.2) * (1 - leaving));
+ word.style.transform = `translateY(${y}px) scale(${lerp(1.06, 1, e)})`;
+ word.style.filter = blur > 0.05 ? `blur(${blur}px)` : 'none';
+ });
+ });
+ }
+}
+
+const scatter = [...oldName.children].map((_, i) => {
+ const random = seeded(i * 7 + 3);
+ return { dx: (random() - 0.5) * 260, dy: (random() - 0.5) * 180, r: (random() - 0.5) * 50, delay: random() * 0.08 };
+});
+
+function drawEnd(t) {
+ const on = t >= RISE;
+ endLayer.style.display = on ? 'block' : 'none';
+ if (!on) return;
+ // The old name comes up out of the dark as the window goes, and breaks up on the impact.
+ const rise = outCubic(progress(t, RISE + 0.25, 0.6));
+ [...oldName.children].forEach((el, i) => {
+ const s = scatter[i];
+ const p = outExpo(progress(t, IMPACT + s.delay, 0.75));
+ el.style.opacity = String(rise * (1 - clamp(p * 1.4)));
+ el.style.transform = `translate(${s.dx * p}px, ${s.dy * p + lerp(18, 0, rise)}px) rotate(${s.r * p}deg) scale(${lerp(1, 1.3, p)})`;
+ const blur = lerp(8, 0, rise) + p * 22;
+ el.style.filter = blur > 0.05 ? `blur(${blur}px)` : 'none';
+ });
+ // The new one forms from the middle out, letter by letter.
+ const count = newName.children.length;
+ [...newName.children].forEach((el, i) => {
+ const order = Math.abs(i - (count - 1) / 2);
+ const p = progress(t, IMPACT + 0.04 + order * 0.045, 0.8);
+ const e = spring(p);
+ el.style.opacity = String(clamp(p * 2.5));
+ el.style.transform = `translateY(${lerp(42, 0, e)}px) scale(${lerp(1.35, 1, e)})`;
+ const blur = lerp(26, 0, outCubic(p));
+ el.style.filter = blur > 0.05 ? `blur(${blur}px)` : 'none';
+ });
+ // A light runs across it once it has formed: one gradient laid across the whole
+ // name, each letter showing its own part of it.
+ // The gradient is three names wide with the light in its middle, so every letter
+ // is covered wherever the light is.
+ const w = newName.offsetWidth;
+ const light = lerp(-0.35, 1.35, inOutCubic(progress(t, IMPACT + 0.55, 1.0))) * w;
+ for (const el of newName.children) {
+ el.style.backgroundSize = `${w * 3}px 100%`;
+ el.style.backgroundPosition = `${light - el.offsetLeft - w * 1.5}px 0`;
+ }
+ const fade = (el, at) => {
+ const p = progress(t, at, 0.7);
+ el.style.opacity = String(outCubic(p));
+ el.style.transform = `translateY(${lerp(16, 0, outExpo(p))}px)`;
+ const blur = lerp(10, 0, outCubic(p));
+ el.style.filter = blur > 0.05 ? `blur(${blur}px)` : 'none';
+ };
+ fade(sub, IMPACT + 0.55);
+ fade(small, IMPACT + 0.8);
+ fade(url, IMPACT + 1.05);
+ // The flash of the impact, settling into a glow behind the name.
+ const flash = Math.exp(-Math.max(0, t - IMPACT) / 0.35) * (t >= IMPACT ? 1 : 0);
+ bloom.style.opacity = String(clamp(0.25 * outCubic(progress(t, IMPACT, 0.6)) + 0.75 * flash));
+ bloom.style.transform = `scale(${lerp(0.7, 1.05, outCubic(progress(t, IMPACT, 1.2)))})`;
+}
+
+// Where the window is on screen when it arrives: the grid the outlines gather into.
+function arrivalRect() {
+ const ex = ARRIVE.x * SCALE;
+ const ey = TITLE + ARRIVE.y * SCALE;
+ return { x: ANCHOR.x - ex * ARRIVE.z, y: ANCHOR.y - ey * ARRIVE.z, w: WIN_W * ARRIVE.z, h: WIN_H * ARRIVE.z };
+}
+const GRID = { cols: 6, rows: 4, gap: 12 };
+// Each outline's tile: outlines sorted top to bottom into rows, each row left to right,
+// so every one travels to a tile near where it was and the paths do not cross much.
+const tiles = (() => {
+ const order = outlines.map((o, i) => i).sort((a, b) => outlines[a].y - outlines[b].y);
+ const slot = new Array(outlines.length);
+ for (let r = 0; r < GRID.rows; r++) {
+ const row = order.slice(r * GRID.cols, (r + 1) * GRID.cols).sort((a, b) => outlines[a].x - outlines[b].x);
+ row.forEach((i, c) => { slot[i] = { col: c, row: r }; });
+ }
+ return slot;
+})();
+
+function drawIntro(t) {
+ const on = LONG && t < INTRO + 0.35;
+ introLayer.style.display = on ? 'block' : 'none';
+ const f = LONG ? Math.exp(-Math.abs(t - INTRO) / (t < INTRO ? 0.06 : 0.3)) : 0;
+ flash.style.opacity = String(on || t < INTRO + 1.5 ? clamp(f * 0.85) : 0);
+ if (!on) return;
+ const rect = arrivalRect();
+ const tw = (rect.w - GRID.gap * (GRID.cols + 1)) / GRID.cols;
+ const th = (rect.h - GRID.gap * (GRID.rows + 1)) / GRID.rows;
+ const fill = inCubic(progress(t, INTRO - 0.4, 0.4));
+ const gone = outCubic(progress(t, INTRO - 0.05, 0.3));
+ pool.style.opacity = String(1 - outCubic(progress(t, GATHER - 0.4, 0.5)));
+ outlines.forEach((o, n) => {
+ const d = DEPTH[o.depth];
+ const shown = clamp(progress(t, o.at, 0.25) * 1.4);
+ const popIn = pop(progress(t, o.at, 0.45));
+ // Scattered: drifting, nearer ones faster, and flickering a little.
+ const drift = d.drift * t;
+ const sx = o.x * W + o.dir[0] * drift;
+ const sy = o.y * H + o.dir[1] * drift;
+ const sw = BASE * o.size * d.scale;
+ const sh = sw * 0.66;
+ // Gathered: each into its tile, the middle ones first.
+ const tile = tiles[n];
+ const tx = rect.x + GRID.gap + tile.col * (tw + GRID.gap) + tw / 2;
+ const ty = rect.y + GRID.gap + tile.row * (th + GRID.gap) + th / 2;
+ const far = Math.hypot(tx - W / 2, ty - H / 2) / Math.hypot(W / 2, H / 2);
+ const g = spring(progress(t, GATHER + far * 0.35, 0.85));
+ const x = lerp(sx, tx, g);
+ const y = lerp(sy, ty, g);
+ const w = lerp(sw, tw, g);
+ const h = lerp(sh, th, g);
+ const flicker = 0.88 + 0.12 * Math.sin(t * 17 + o.phase) * Math.sin(t * 5.3 + o.phase * 2);
+ // Its state's colour, once the type has said it; done ones also dim a little and
+ // get a tick, waiting ones pulse on the beat.
+ const said = o.state === 'done' ? progress(t, SAID[1] + 0.1, 0.35) : o.state === 'waiting' ? progress(t, SAID[2] + 0.1, 0.35) : 1;
+ const hue = STATE[o.state].map((c, k) => lerp(STATE.neutral[k], c, said));
+ const [r, gg, b] = hue.map((c) => Math.round(lerp(c, 236, g * 0.7)));
+ const color = (a) => `rgb(${r} ${gg} ${b} / ${a})`;
+ const pulse = o.state === 'waiting' ? said * (0.5 + 0.5 * Math.cos((2 * Math.PI * t) / BEAT)) * (1 - g) : 0;
+ const dim = o.state === 'done' ? lerp(1, 0.72, said * (1 - g)) : o.state === 'idle' ? 0.8 : 1;
+ o.tick.style.opacity = String(o.state === 'done' ? outCubic(said) * (1 - g) : 0);
+ o.tick.style.transform = `scale(${lerp(0.4, 1, pop(said))})`;
+ const el = o.el;
+ el.style.width = `${w}px`;
+ el.style.height = `${h}px`;
+ el.style.padding = `0 ${Math.max(4, w * 0.07)}px`;
+ el.style.transform = `translate(${x - w / 2}px, ${y - h / 2}px) scale(${lerp(0.6, 1, popIn)})`;
+ el.style.opacity = String(shown * lerp(d.alpha * flicker * dim, 1, g) * (1 - gone));
+ const blur = lerp(d.blur, 0, g) + (1 - clamp(popIn)) * 4;
+ el.style.filter = `${blur > 0.05 ? `blur(${blur}px) ` : ''}brightness(${lerp(1.9, 1, outCubic(progress(t, o.at, 0.4))) + fill * 0.8})`;
+ el.style.borderColor = color(0.9);
+ el.style.background = color(lerp(0.06, 0.85, fill));
+ el.style.boxShadow = `0 0 ${18 + fill * 30 + pulse * 26}px ${color(0.35 + fill * 0.4 + pulse * 0.4)}, inset 0 0 14px ${color(0.15 + pulse * 0.2)}`;
+ o.rule.style.borderColor = color(0.5);
+ o.rule.style.marginTop = `${h * 0.2}px`;
+ for (const bar of o.bars) bar.style.background = color(0.45);
+ o.cursor.style.background = color(Math.floor(t / BEAT + o.phase) % 2 ? 0.95 : 0.1);
+ });
+}
+
+function drawMark(t) {
+ const shown = outCubic(progress(t, SCENES.both + 0.6, 0.6)) * (1 - outCubic(progress(t, RISE - 0.1, 0.4)));
+ mark.style.opacity = String(0.9 * shown);
+}
+
+window.render = (t) => {
+ t = clamp(t, 0, LENGTH);
+ backdrop(t);
+ drawMark(t);
+ drawIntro(t);
+ drawWindow(t);
+ drawHeadline(t);
+ drawEnd(t);
+};
+
+await document.fonts.load(`720 ${HEAD.size}px Inter`);
+await document.fonts.load('500 20px "JetBrains Mono"');
+await Promise.all(Object.values(images).map((img) => img.decode()));
+window.render(0);
+window.ready = true;
diff --git a/docs/record-demo/paddock-film/timeline.js b/docs/record-demo/paddock-film/timeline.js
new file mode 100644
index 0000000..c4525ef
--- /dev/null
+++ b/docs/record-demo/paddock-film/timeline.js
@@ -0,0 +1,127 @@
+// The Paddock film's timing, shared by the picture (stage.js) and the sound
+// (score.js): every cut, move and click is a time here, so the music and the
+// effects land on the frame they belong to. Times are seconds from the start.
+//
+// The music is felt in half time and each scene is two bars, so every cut falls on
+// a downbeat. Everything in a cut is counted in its beats, so its tempo sets its pace.
+//
+// There are two cuts. `short` (15 s, 160 beats a minute) opens on the app. `long`
+// (25 s, 128 beats a minute: the same film, given more time to read) opens on an
+// abstract intro, three bars long: the sessions the author had open, scattered in the
+// dark, gathered into one window as the beat drops; the app scenes follow, and the
+// end card is held longer.
+
+// Seeded random numbers, so the outlines fall the same way every run.
+export function seeded(seed) {
+ return () => {
+ seed = (seed + 0x6d2b79f5) >>> 0;
+ let t = seed;
+ t = Math.imul(t ^ (t >>> 15), t | 1);
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
+ };
+}
+
+// The intro's terminal outlines: the sessions the author had open the day the film
+// was made, 23 of them, as Paddock counted them (15 done but not closed, 3 waiting
+// for an answer, 2 working, 3 idle). Each has when it appears (on a sixteenth from
+// `from`; the first few are already there in the first frame, which is what a feed
+// shows before anyone presses play), where (as fractions of the frame), how deep
+// (0 near, 2 far) and its state. Placed on a loose grid with jitter, so they fill
+// the frame without piling up.
+export const OPEN = { total: 23, done: 15, waiting: 3, working: 2, idle: 3 };
+
+function outlines(step, from) {
+ const random = seeded(97);
+ const cells = [];
+ for (let row = 0; row < 6; row++) for (let col = 0; col < 5; col++) cells.push([col, row]);
+ const shuffle = (list) => {
+ for (let i = list.length - 1; i > 0; i--) {
+ const j = Math.floor(random() * (i + 1));
+ [list[i], list[j]] = [list[j], list[i]];
+ }
+ return list;
+ };
+ shuffle(cells);
+ const states = shuffle([...Array(OPEN.done).fill('done'), ...Array(OPEN.waiting).fill('waiting'),
+ ...Array(OPEN.working).fill('working'), ...Array(OPEN.idle).fill('idle')]);
+ const early = 6;
+ return cells.slice(0, OPEN.total).map(([col, row], n) => ({
+ at: n < early ? -1 : from + (n - early) * step,
+ x: (col + 0.2 + random() * 0.6) / 5,
+ y: (row + 0.2 + random() * 0.6) / 6,
+ depth: random() < 0.35 ? 0 : random() < 0.6 ? 1 : 2,
+ state: states[n],
+ size: 0.8 + random() * 0.45,
+ lines: 2 + Math.floor(random() * 2),
+ cursor: random() < 0.35,
+ seed: Math.floor(random() * 1e9),
+ }));
+}
+
+export function timeline(cut = 'short') {
+ const long = cut === 'long';
+ const BPM = long ? 128 : 160;
+ const BEAT = 60 / BPM;
+ const BAR = 4 * BEAT;
+ const STEP = BEAT / 4;
+ const INTRO = long ? 3 * BAR : 0;
+ const SCENES = { both: INTRO, all: INTRO + 2 * BAR, search: INTRO + 4 * BAR, usage: INTRO + 6 * BAR, end: INTRO + 8 * BAR };
+ const LENGTH = long ? 25 : 15;
+ // The music drops out and rises into the end card; the impact is the name.
+ const RISE = SCENES.end - BAR * 2 / 3;
+ const IMPACT = SCENES.end;
+ // The drums come in with the second scene, or with the app itself after the intro.
+ const GROOVE = { from: long ? SCENES.both : SCENES.all, until: RISE };
+ // In the intro: scattered until GATHER, gathered into the window's grid by the drop.
+ const GATHER = INTRO - BAR;
+ const OUTLINES = long ? outlines(STEP, 0.05) : [];
+ // The intro's three lines: open (already up in the first frame), done, waiting.
+ // The outlines answer each: the done ones go green on the second, the waiting ones
+ // start to pulse on the third.
+ const SAID = long ? [-0.3, 2 * BEAT, 4 * BEAT] : [];
+
+ // The search, typed a letter to each eighth note from the second beat of its scene.
+ const WORD = 'cart';
+ const typedAt = (n) => SCENES.search + BEAT + n * (BEAT / 2);
+ // The pointer picks the Codex conversation on the third beat, then points at Resume.
+ const PICK = SCENES.search + 4 * BEAT;
+ const RESUME = SCENES.search + 6 * BEAT;
+ // The labels on the first scene's two sessions, and the ring on the Codex account.
+ const LABELS = [SCENES.both + 2 * BEAT, SCENES.both + 2.5 * BEAT];
+ const RING = SCENES.all + 2 * BEAT;
+ // The bars of Usage grow in one after another, an eighth note apart.
+ const barAt = (n) => SCENES.usage + BEAT + n * (BEAT / 2);
+
+ // What the sound follows: whooshes on camera moves (`pan` is where the move goes,
+ // -1 left to 1 right), ticks on keys and clicks, pops on labels, and in the intro
+ // a blip for each outline (one per sixteenth), the gathering and the drop.
+ function cues(bars = 5) {
+ const blips = [];
+ for (const o of OUTLINES) if (o.at >= 0 && !blips.some((b) => Math.abs(b.at - o.at) < 1e-6)) blips.push({ kind: 'blip', at: o.at, pan: o.x * 2 - 1, depth: o.depth });
+ return [
+ ...blips,
+ ...(long ? [{ kind: 'chime', at: SAID[1] + 0.05 }, ...[0, 1, 2].map((n) => ({ kind: 'pop', at: SAID[2] + 0.05 + n * STEP })),
+ { kind: 'gather', at: GATHER, until: INTRO }, { kind: 'drop', at: INTRO }] : []),
+ { kind: 'whoosh', at: SCENES.all, pan: 0, size: 1 },
+ { kind: 'whoosh', at: SCENES.search, pan: -0.5, size: 0.8 },
+ { kind: 'whoosh', at: PICK + 0.12, pan: 0.6, size: 0.5 },
+ { kind: 'whoosh', at: SCENES.usage, pan: -0.4, size: 0.9 },
+ ...LABELS.map((at) => ({ kind: 'pop', at })),
+ { kind: 'pop', at: RING },
+ ...[...WORD].map((_, n) => ({ kind: 'key', at: typedAt(n) })),
+ { kind: 'click', at: PICK },
+ { kind: 'click', at: RESUME },
+ { kind: 'chime', at: RESUME + 0.05 },
+ ...Array.from({ length: bars }, (_, n) => ({ kind: 'tick', at: barAt(n) })),
+ { kind: 'riser', at: RISE, until: IMPACT },
+ { kind: 'impact', at: IMPACT },
+ { kind: 'shimmer', at: IMPACT + 0.05 },
+ ];
+ }
+
+ return {
+ cut, BPM, BEAT, BAR, STEP, LENGTH, INTRO, SCENES, RISE, IMPACT, GROOVE, GATHER, OUTLINES, SAID,
+ WORD, typedAt, PICK, RESUME, LABELS, RING, barAt, cues,
+ };
+}
diff --git a/docs/record-demo/record.mjs b/docs/record-demo/record.mjs
index 54936c4..fb5e6ab 100644
--- a/docs/record-demo/record.mjs
+++ b/docs/record-demo/record.mjs
@@ -14,10 +14,13 @@
//
// sh docs/record-demo/setup-voice.sh (once, for the Kokoro voice)
// cargo build --release
-// node docs/record-demo/record.mjs [--keep] [--still] [--no-music]
+// node docs/record-demo/record.mjs [--keep] [--still] [--no-music] [--film whats-new] [--out file.mp4]
//
// --keep leaves the demo home and the captured frames in place for a look.
// --still makes only docs/demo.png. --no-music leaves out the music bed.
+// --film whats-new makes a 15-second square clip of what is new in 2.6 and 2.7, for
+// a social feed (docs/whats-new.mp4), instead of the launch film, and no still.
+// --out writes the film somewhere else.
// CHROME, FFMPEG, FFPROBE and SAY name the programs if they are not in the usual place.
// DEMO_WORK_DIR is where the frames go while recording (about 500 MB; default
// the system's temporary folder).
@@ -35,7 +38,7 @@ import { fileURLToPath } from 'node:url';
const HERE = path.dirname(fileURLToPath(import.meta.url));
const REPO = path.resolve(HERE, '..', '..');
-const EXE = path.join(REPO, 'target', 'release', 'cc-sessions');
+const EXE = path.join(REPO, 'target', 'release', 'paddock');
const FAKE_CLAUDE = path.join(REPO, 'target', 'release', 'fake-claude');
const CHROME = process.env.CHROME || '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
const FFMPEG = process.env.FFMPEG || 'ffmpeg';
@@ -45,21 +48,31 @@ const KEEP = process.argv.includes('--keep');
// Only docs/demo.png: no narration, no recording.
const STILL_ONLY = process.argv.includes('--still');
const NO_MUSIC = process.argv.includes('--no-music');
+// --film paddock --stills takes the Paddock film's stills and stops, for paddock-film/film.mjs to be run on its own.
+const STILLS_ONLY = process.argv.includes('--stills');
+// The word after a flag, or null.
+const option = (name) => { const i = process.argv.indexOf(name); return i < 0 ? null : process.argv[i + 1] || null; };
+// Which film: 'launch' (the README's) or 'whats-new' (a short square clip for a feed).
+const FILM = option('--film') || 'launch';
+const OUT = option('--out');
// Short on purpose: the resume command in a session's details prints this path.
const HOME = '/tmp/alex';
const MARKER = path.join(HOME, '.cc-sessions-demo');
-const STATE = path.join(HOME, '.config', 'cc-sessions');
+const STATE = path.join(HOME, '.config', 'paddock');
const BIN = path.join(HOME, 'bin');
const PORT = 47999;
-// The page is laid out at 1280x800 and drawn at twice that, then scaled to the
-// video size, which keeps small text sharp.
-const VIEW = { width: 1280, height: 800 };
+// The page is laid out at 1280x800 (960x960 for the square clip) and drawn at twice
+// that, then scaled to the video size, which keeps small text sharp.
+const SQUARE = FILM === 'whats-new';
+const VIEW = SQUARE ? { width: 960, height: 960 } : FILM === 'paddock' ? { width: 1180, height: 820 } : { width: 1280, height: 800 };
// The still is wider than the video, so a session's details fit in the panel beside the list.
const STILL = { width: 1600, height: 1000, scale: 1.125 };
-const SCALE = 2;
-const VIDEO = { width: 1600, height: 1000, fps: 30, crf: 20 };
+// The Paddock film's footage is filmed at 4×, so the camera can push in on it 2.4 times
+// in a frame drawn at twice its size and stay sharp.
+const SCALE = FILM === 'paddock' ? 4 : 2;
+const VIDEO = SQUARE ? { width: 1080, height: 1080, fps: 30, crf: 20 } : { width: 1600, height: 1000, fps: 30, crf: 20 };
// The narration voice. Kokoro is used when setup-voice.sh has made its Python
// environment; speak.py knows where the model is. `speed` 1 is the voice's own pace.
@@ -203,6 +216,99 @@ const HISTORY = [
'Use a 1.2 ratio on small screens and 1.25 on large ones']],
];
+// For the Paddock film: a Codex account beside the three Claude Code ones, found by
+// its folder (~/.codex-work, listed as codex-work). Its conversations are rollouts
+// as Codex writes them; `running` ones are held open by a stand-in `codex` process,
+// mid-turn, so they show as working. [folder, title, model, last activity ago, prompts].
+const CODEX = {
+ dir: '.codex-work',
+ claims: { email: 'alex@northwind.example', 'https://api.openai.com/auth': { chatgpt_plan_type: 'pro' } },
+ running: [
+ ['storefront', 'Add Apple Pay to the checkout', 'gpt-6.1-sol', 20 * 1000, [
+ 'Add Apple Pay as a payment option on the checkout page, behind the payments feature flag.']],
+ ['gateway', 'Speed up the orders query', 'gpt-6-astra', 50 * 1000, [
+ 'The orders list query does a full scan for large accounts. Find a better plan and add the index.']],
+ ],
+ saved: [
+ ['storefront', 'Fix the flaky cart tests', 'gpt-6.1-sol', 3 * HOUR, [
+ 'The cart tests fail about one run in five on CI. Find out why.', 'Make the clock in those tests fixed']],
+ ['design', 'Audit button contrast', 'gpt-6-astra', 2 * DAY, [
+ 'Check every button variant against WCAG AA contrast and list the ones that fail.']],
+ ['gateway', 'OpenAPI docs for the webhooks', 'gpt-6.1-sol', 5 * DAY, [
+ 'Write the OpenAPI description for the webhook endpoints.', 'Add examples for each event type']],
+ ['storefront', 'Search suggestions as you type', 'gpt-6-astra', 9 * DAY, [
+ 'Show search suggestions under the box as people type, from the product titles.']],
+ ],
+};
+
+// A Codex rollout ending `ago` before `now`: its turns, with token counts that add up
+// as Codex records them (each event carries the running total). A running one stops
+// mid-turn: started, never completed.
+function rollout(now, folder, title, model, ago, prompts, running) {
+ const { random, between } = seeded(`codex ${title}`);
+ const id = uuid(`codex ${title}`);
+ const cwd = FOLDERS[folder];
+ const end = now - ago;
+ const turns = running ? between(8, 14) : between(16, 40);
+ const start = end - turns * between(3, 9) * MIN;
+ const iso = (at) => new Date(at).toISOString();
+ const lines = [
+ { timestamp: iso(start), type: 'session_meta', payload: { id, cwd, timestamp: iso(start), originator: 'codex-tui', cli_version: '0.170.0', model_provider: 'openai' } },
+ { timestamp: iso(start), type: 'turn_context', payload: { cwd, model } },
+ ];
+ const total = { input_tokens: 0, cached_input_tokens: 0, output_tokens: 0 };
+ for (let i = 0; i < turns; i++) {
+ const at = start + ((end - start) * i) / turns;
+ if (i < prompts.length) {
+ lines.push({ timestamp: iso(at), type: 'response_item', payload: { type: 'message', role: 'user', content: [{ type: 'input_text', text: prompts[i] }] } });
+ }
+ lines.push({ timestamp: iso(at + 1000), type: 'event_msg', payload: { type: 'task_started' } });
+ const context = between(60000, 150000) + i * between(12000, 26000);
+ total.input_tokens += context;
+ total.cached_input_tokens += Math.round(context * (0.82 + random() * 0.12));
+ total.output_tokens += between(300, 2600);
+ lines.push({ timestamp: iso(at + 60000), type: 'event_msg', payload: { type: 'token_count', info: { total_token_usage: { ...total } } } });
+ if (!(running && i === turns - 1)) lines.push({ timestamp: iso(at + 61000), type: 'event_msg', payload: { type: 'task_complete' } });
+ }
+ return { id, start, cwd, lines };
+}
+
+function buildCodex(now) {
+ const dir = path.join(HOME, CODEX.dir);
+ const claims = Buffer.from(JSON.stringify(CODEX.claims)).toString('base64url');
+ writeJson(path.join(dir, 'auth.json'), { auth_mode: 'chatgpt', tokens: { id_token: `x.${claims}.sig` } });
+ const index = [];
+ const write = ([folder, title, model, ago, prompts], running) => {
+ const { id, start, cwd, lines } = rollout(now, folder, title, model, ago, prompts, running);
+ // Named in local time, as Codex names them.
+ const at = new Date(start);
+ const two = (n) => String(n).padStart(2, '0');
+ const [y, mo, d] = [String(at.getFullYear()), two(at.getMonth() + 1), two(at.getDate())];
+ const day = path.join(dir, 'sessions', y, mo, d);
+ const stamp = `${y}-${mo}-${d}T${two(at.getHours())}-${two(at.getMinutes())}-${two(at.getSeconds())}`;
+ const file = path.join(day, `rollout-${stamp}-${id}.jsonl`);
+ mkdirSync(day, { recursive: true });
+ writeFileSync(file, lines.map((line) => JSON.stringify(line)).join('\n') + '\n');
+ utimesSync(file, new Date(now - ago), new Date(now - ago));
+ index.push({ id, thread_name: title });
+ return { file, cwd };
+ };
+ for (const s of CODEX.saved) write(s, false);
+ const held = CODEX.running.map((s) => write(s, true));
+ writeFileSync(path.join(dir, 'session_index.jsonl'), index.map((line) => JSON.stringify(line)).join('\n') + '\n');
+ return held;
+}
+
+// The running Codex sessions: a stand-in `codex` holding each one's rollout open, in its folder.
+// `fake-claude hold` lives two minutes, so these are started just before they are filmed.
+function holdCodex(held) {
+ copyFileSync(FAKE_CLAUDE, path.join(BIN, 'codex'));
+ chmodSync(path.join(BIN, 'codex'), 0o755);
+ for (const { file, cwd } of held) {
+ standIns.push(spawn(path.join(BIN, 'codex'), ['hold', file], { cwd, stdio: 'ignore', env: { PATH: '/usr/bin:/bin' } }));
+ }
+}
+
function writeJson(file, value) {
mkdirSync(path.dirname(file), { recursive: true });
writeFileSync(file, JSON.stringify(value, null, 2));
@@ -272,7 +378,16 @@ function buildDemo() {
writeJson(path.join(dir, 'fake-agents.json'), agents);
}
+ const save = (account, cwd, sessionId, ago, lines) => {
+ const file = path.join(HOME, `.claude-${account}`, 'projects', cwd.replaceAll('/', '-'), `${sessionId}.jsonl`);
+ mkdirSync(path.dirname(file), { recursive: true });
+ writeFileSync(file, lines.map((line) => JSON.stringify(line)).join('\n') + '\n');
+ // The page shows the file's modification time as the conversation's date.
+ utimesSync(file, new Date(now - ago), new Date(now - ago));
+ };
+ const work = FILM === 'whats-new' ? WORK : [];
for (const [account, folder, title, ago, prompts] of HISTORY) {
+ if (work.some((w) => w[2] === title)) continue;
const cwd = FOLDERS[folder];
const sessionId = uuid(title);
const started = ago + (prompts.length * 9 + 4) * MIN;
@@ -281,20 +396,25 @@ function buildDemo() {
}));
lines.splice(1, 0, { type: 'ai-title', aiTitle: title, sessionId });
lines.push(...replies(title, sessionId, now - ago));
- const file = path.join(HOME, `.claude-${account}`, 'projects', cwd.replaceAll('/', '-'), `${sessionId}.jsonl`);
- mkdirSync(path.dirname(file), { recursive: true });
- writeFileSync(file, lines.map((line) => JSON.stringify(line)).join('\n') + '\n');
- // The page shows the file's modification time as the conversation's date.
- utimesSync(file, new Date(now - ago), new Date(now - ago));
+ save(account, cwd, sessionId, ago, lines);
+ }
+ for (const [account, folder, title, ago, size, steps] of work) {
+ const cwd = FOLDERS[folder];
+ const sessionId = uuid(title);
+ save(account, cwd, sessionId, ago, workLines(title, cwd, sessionId, now - ago, size, steps));
}
// One favourite, so the Finder layout's sidebar shows what pinning a folder does.
writeJson(path.join(STATE, 'pins.json'), { version: 1, sessions: [], folders: ['~/code/storefront'] });
+ // The what's new film shows the window an update opens: as if it had just come from 2.5.1.
+ if (FILM === 'whats-new') {
+ writeJson(path.join(STATE, 'update.json'), { latest: 'v2.7.2', checkedAt: now, justUpdated: { from: 'v2.5.1', to: 'v2.7.2', at: now - 5 * MIN } });
+ }
+ // The Paddock film adds a Codex account; its running sessions are returned, to be held open when filmed.
+ return FILM === 'paddock' ? buildCodex(now) : [];
}
-// A few weeks of model replies before `end`, so the Usage view has a year that
-// looks lived in: mostly weekday working hours, three models, sizes like real
-// ones. Seeded by the title, so every run makes the same.
-function replies(title, sessionId, end) {
+// Random numbers seeded by a title, so every run makes the same.
+function seeded(title) {
let seed = parseInt(createHash('sha1').update(title).digest('hex').slice(0, 8), 16);
const random = () => {
seed = (seed + 0x6d2b79f5) >>> 0;
@@ -303,7 +423,14 @@ function replies(title, sessionId, end) {
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
- const between = (low, high) => Math.round(low + random() * (high - low));
+ return { random, between: (low, high) => Math.round(low + random() * (high - low)) };
+}
+
+// A few weeks of model replies before `end`, so the Usage view has a year that
+// looks lived in: mostly weekday working hours, three models, sizes like real
+// ones. Seeded by the title, so every run makes the same.
+function replies(title, sessionId, end) {
+ const { random, between } = seeded(title);
const span = between(3, 21);
const out = [];
for (let i = 0, count = between(25, 70); i < count; i++) {
@@ -331,17 +458,115 @@ function replies(title, sessionId, end) {
return out;
}
+// For the what's new film: sessions with real work in them, written in the order it
+// happened, as the loop check (src/loops.rs) reads them. One goes round in
+// circles; the two healthy ones give "your usual" something to go on, so only
+// the loop is flagged. A step is ['say', prompt], ['read', file],
+// ['edit', file, old text, new text], ['write', file, content] or ['run', command, error].
+// A title that matches a saved conversation above replaces it.
+const CALLBACK = 'src/auth/callback.ts';
+const SESSION_SETUP = 'src/auth/session.ts';
+const REDIRECT = ' return res.redirect(req.session.returnTo);';
+const REDIRECT_SAFE = " return res.redirect(req.session?.returnTo ?? '/dashboard');";
+const EXCHANGE = ' const user = await exchangeCode(code);';
+const EXCHANGE_STATE = ' const user = await exchangeCode(code, { state });';
+const SAVE_OFF = ' saveUninitialized: false,';
+const SAVE_ON = ' saveUninitialized: true,';
+// The same failure each time, from a different line as the file changes.
+const redirectFails = (line) => ['run', 'npm test -- auth', `Exit code 1\nFAIL test/auth/callback.test.ts\n ● OAuth callback › sends the user back where they started\n\n TypeError: Cannot read properties of undefined (reading 'returnTo')\n\n at handleCallback (src/auth/callback.ts:${line}:38)`];
+
+// Steps for a healthy session: per prompt, a look round, new files written, the tests passing.
+function healthy(prompts, folder) {
+ return prompts.flatMap((prompt, p) => [
+ ['say', prompt],
+ ...[1, 2, 3, 4, 5].map((n) => ['read', `src/${folder}/part${n}.ts`]),
+ ...[1, 2, 3, 4].map((n) => ['write', `src/${folder}/step${p + 1}-${n}.ts`, `// ${prompt}\nexport const step = ${n};\nexport const part = ${p + 1};\n`]),
+ ['run', 'npm test', ''],
+ ['run', 'npm run lint', ''],
+ ]);
+}
+
+const WORK = [
+ ['work', 'gateway', 'Fix the login redirect after OAuth', 35 * MIN, { base: 800000, grow: 50000 }, [
+ ['say', 'After signing in with Google, people land on a blank page instead of their dashboard. Find out why and fix it.'],
+ ['read', CALLBACK], ['read', SESSION_SETUP],
+ redirectFails(41),
+ ['edit', CALLBACK, REDIRECT, REDIRECT_SAFE], redirectFails(41),
+ ['edit', CALLBACK, EXCHANGE, EXCHANGE_STATE], redirectFails(44),
+ ['say', 'still getting the same error'],
+ ['read', CALLBACK],
+ ['edit', CALLBACK, EXCHANGE_STATE, EXCHANGE], ['edit', SESSION_SETUP, SAVE_OFF, SAVE_ON], redirectFails(41),
+ ['edit', CALLBACK, REDIRECT_SAFE, REDIRECT], redirectFails(41),
+ ['say', "that didn't work, it still doesn't redirect"],
+ ['read', CALLBACK],
+ ['edit', CALLBACK, REDIRECT, REDIRECT_SAFE], ['edit', SESSION_SETUP, SAVE_ON, SAVE_OFF], redirectFails(41),
+ ['edit', CALLBACK, EXCHANGE, EXCHANGE_STATE], redirectFails(44),
+ ['say', 'same error again. Can you step back and look at how the session is set up?'],
+ ['read', SESSION_SETUP], ['read', 'src/app.ts'],
+ ['edit', SESSION_SETUP, " cookie: { sameSite: 'strict' },", " cookie: { sameSite: 'lax' },"], redirectFails(44),
+ redirectFails(44),
+ ]],
+ ['client', 'gateway', 'Webhook retries with exponential backoff', 8 * DAY, { base: 30000, grow: 6000 }, healthy([
+ 'Failed webhooks are retried straight away and flood the receiver. Add exponential backoff with jitter.',
+ 'Cap it at six attempts and log the final failure'], 'webhooks')],
+ ['work', 'gateway', 'Trace slow requests on the orders endpoint', 3 * DAY, { base: 30000, grow: 6000 }, healthy([
+ 'GET /orders takes over two seconds for large accounts. Find out where the time goes.',
+ 'Add an index for the query you found and measure again'], 'orders')],
+];
+
+// A WORK session's transcript, ending at `end`: each step a minute or so after the
+// last; every step but a prompt is a model reply, with the conversation it re-reads
+// growing as it goes (`size`).
+function workLines(title, cwd, sessionId, end, size, steps) {
+ const { between } = seeded(title);
+ const out = [];
+ const at = (i) => new Date(end - (steps.length - i) * 70 * 1000).toISOString();
+ const user = (i, content, extra = {}) => out.push({ type: 'user', cwd, sessionId, timestamp: at(i), ...extra, message: { role: 'user', content } });
+ steps.forEach(([what, ...args], i) => {
+ if (what === 'say') {
+ user(i, args[0]);
+ if (!i) out.push({ type: 'ai-title', aiTitle: title, sessionId });
+ return;
+ }
+ const id = `toolu_${sessionId.slice(0, 8)}_${i}`;
+ const [file] = args;
+ const use = {
+ read: () => ({ name: 'Read', input: { file_path: `${cwd}/${file}` } }),
+ edit: () => ({ name: 'Edit', input: { file_path: `${cwd}/${file}`, old_string: args[1], new_string: args[2] } }),
+ write: () => ({ name: 'Write', input: { file_path: `${cwd}/${file}`, content: args[1] } }),
+ run: () => ({ name: 'Bash', input: { command: args[0] } }),
+ }[what]();
+ out.push({
+ type: 'assistant', cwd, sessionId, timestamp: at(i),
+ message: {
+ model: 'claude-opus-5-5', id: `msg_${sessionId.slice(0, 8)}_${i}`, role: 'assistant',
+ content: [{ type: 'tool_use', id, ...use }],
+ usage: {
+ input_tokens: between(2, 30),
+ output_tokens: between(150, 1400),
+ cache_creation_input_tokens: between(12000, 18000),
+ cache_read_input_tokens: size.base + i * size.grow,
+ },
+ },
+ });
+ const error = what === 'run' && args[1];
+ user(i, [{ type: 'tool_result', tool_use_id: id, content: error || (what === 'run' ? 'All tests passed.' : 'Done.'), is_error: Boolean(error) }]);
+ });
+ return out;
+}
+
// ----------------------------------------------------------------- the tool
// A clean environment: nothing from this shell (or from a Claude Code session
// this may be run inside, which sets CLAUDE_* variables) reaches the tool.
const TOOL_ENV = {
- HOME, CC_SESSIONS_HOME: STATE, CC_SESSIONS_PORT: String(PORT), SHELL: '/bin/zsh', PATH: `${BIN}:/usr/bin:/bin`,
+ // /usr/sbin has lsof, which tells which conversation a running Codex holds open.
+ HOME, PADDOCK_HOME: STATE, PADDOCK_PORT: String(PORT), SHELL: '/bin/zsh', PATH: `${BIN}:/usr/bin:/bin:/usr/sbin`,
};
function tool(...args) {
const out = spawnSync(EXE, args, { env: TOOL_ENV, cwd: HOME, encoding: 'utf8' });
- if (out.status !== 0) throw new Error(`cc-sessions ${args.join(' ')} failed: ${out.stderr || out.stdout}`);
+ if (out.status !== 0) throw new Error(`paddock ${args.join(' ')} failed: ${out.stderr || out.stdout}`);
return out.stdout.trim();
}
@@ -482,7 +707,27 @@ function installOverlay() {
stack.append(title, subtitle, line);
card.append(stack);
- layer.append(caption, ring, pointer, card);
+ // Headlines, for a film watched without sound: large and short, one at a time, at
+ // the top or the bottom. Words between *stars* are picked out in amber.
+ const headline = css(document.createElement('div'), {
+ position: 'absolute', left: '50%', 'max-width': '88%', padding: '15px 28px 17px', 'border-radius': '20px', 'box-sizing': 'border-box',
+ background: 'rgb(12 14 20 / 0.93)', color: '#ffffff', 'text-align': 'center', 'box-shadow': '0 14px 40px rgb(0 0 0 / 0.32)',
+ opacity: '0', transform: 'translateX(-50%) scale(0.92)', transition: 'opacity 150ms ease, transform 280ms cubic-bezier(0.2, 0.9, 0.3, 1.25)',
+ });
+ const big = css(document.createElement('div'), { font: `800 44px/1.1 ${face}`, 'letter-spacing': '-0.03em', 'white-space': 'nowrap' });
+ const small = css(document.createElement('div'), { font: `500 22px/1.3 ${face}`, color: '#c9c9cf', 'margin-top': '7px' });
+ headline.append(big, small);
+ const amber = () => css(document.createElement('span'), { color: '#ffb547' });
+ const words = (text) => text.split('*').map((part, i) => {
+ if (i % 2 === 0) return document.createTextNode(part);
+ const span = amber();
+ span.textContent = part;
+ return span;
+ });
+ // The page under the overlay, zoomed: how far, and moved by how much.
+ let zoomed = { s: 1, x: 0, y: 0 };
+
+ layer.append(caption, ring, pointer, headline, card);
document.body.append(layer);
layer.showPopover();
// A title glows from white into a soft blue and violet; plain ones stay white.
@@ -523,7 +768,10 @@ function installOverlay() {
place(ring, x, y, 'scale(1.15)');
},
// Shows a card, or changes the one showing: the old words fade out and the new ones in.
+ // `see` lets the page show through, dimmed and blurred.
card(words) {
+ card.style.background = words.see ? 'rgb(8 10 14 / 0.8)' : '#000000';
+ card.style.backdropFilter = words.see ? 'blur(12px)' : 'none';
if (!carded) {
subtitle.style.opacity = '0';
line.style.opacity = '0';
@@ -545,6 +793,53 @@ function installOverlay() {
card.style.opacity = '0';
carded = false;
},
+ // A headline ({ text, sub, at: 'top' or 'bottom', count }), or none. With `count`
+ // ({ to, decimals, suffix }) the amber number runs up to `to` as it appears.
+ headline(next) {
+ const show = () => {
+ if (!next) return;
+ big.replaceChildren(...words(next.text || ''));
+ if (next.count) {
+ const number = amber();
+ big.prepend(number);
+ const began = performance.now();
+ const tick = (now) => {
+ const t = Math.min(1, (now - began) / 900);
+ number.textContent = `${(next.count.to * (1 - (1 - t) ** 3)).toFixed(next.count.decimals || 0)}${next.count.suffix || ''}`;
+ if (t < 1) requestAnimationFrame(tick);
+ };
+ requestAnimationFrame(tick);
+ }
+ small.textContent = next.sub || '';
+ small.style.display = next.sub ? 'block' : 'none';
+ headline.style.top = next.at === 'bottom' ? 'auto' : '34px';
+ headline.style.bottom = next.at === 'bottom' ? '40px' : 'auto';
+ headline.style.opacity = '1';
+ headline.style.transform = 'translateX(-50%) scale(1)';
+ };
+ const showing = headline.style.opacity === '1';
+ headline.style.opacity = '0';
+ headline.style.transform = 'translateX(-50%) scale(0.92)';
+ if (showing) setTimeout(show, 150); else show();
+ },
+ // Zooms the page in `s` times on the middle of `box` (measured as it is now), kept
+ // inside the window; no box, or s = 1, zooms back out.
+ zoom(box, s, ms) {
+ const page = document.body;
+ page.style.transformOrigin = '0 0';
+ page.style.transition = `transform ${ms}ms cubic-bezier(0.3, 0.7, 0.2, 1)`;
+ if (!box || s === 1) {
+ zoomed = { s: 1, x: 0, y: 0 };
+ page.style.transform = '';
+ return;
+ }
+ // Where the box's middle is on the page itself, without the zoom already on.
+ const cx = (box.x + box.w / 2 - zoomed.x) / zoomed.s;
+ const cy = (box.y + box.h / 2 - zoomed.y) / zoomed.s;
+ const keep = (v, size) => Math.min(0, Math.max(size - size * s, v));
+ zoomed = { s, x: keep(innerWidth / 2 - cx * s, innerWidth), y: keep(innerHeight / 2 - cy * s, innerHeight) };
+ page.style.transform = `translate(${zoomed.x}px, ${zoomed.y}px) scale(${s})`;
+ },
caption(text) {
caption.style.opacity = '0';
if (!text) return;
@@ -572,6 +867,7 @@ function installOverlay() {
const KEYS = {
space: [' ', 'Space', 32, ' '],
escape: ['Escape', 'Escape', 27],
+ '2': ['2', 'Digit2', 50, '2'],
'3': ['3', 'Digit3', 51, '3'],
',': [',', 'Comma', 188, ','],
};
@@ -589,6 +885,26 @@ function actor(page) {
caption: (text) => js`__demo.caption(${text})`,
card: (words) => js`__demo.card(${words})`,
uncard: () => js`__demo.uncard()`,
+ headline: (words) => js`__demo.headline(${words})`,
+ raise: () => js`__demo.raise()`,
+ run: (expression) => page.evaluate(expression),
+ // The text of the first `selector` element containing `text` (or of `inside`, within it).
+ text: (selector, text, inside) => js`(() => {
+ let el = [...document.querySelectorAll(${selector})].find((e) => e.textContent.includes(${text}));
+ if (el && ${inside}) el = el.querySelector(${inside});
+ return el ? el.textContent.trim() : '';
+ })()`,
+ // Zooms in on an element, `scale` times, taking `over` milliseconds; zoomOut goes back.
+ async zoom(selector, { text, inside, scale = 1.6, over = 650 } = {}) {
+ const box = await js`__demo.box(${selector}, ${text || ''}, ${inside || ''})`;
+ if (!box) throw new Error(`Nothing on the page to zoom in on for ${selector} ${text || ''}`);
+ await js`__demo.zoom(${box}, ${scale}, ${over})`;
+ await sleep(over);
+ },
+ async zoomOut(over = 550) {
+ await js`__demo.zoom(null, 1, ${over})`;
+ await sleep(over);
+ },
async start() {
await page.evaluate(`(${installOverlay})()`);
await js`__demo.point(${at.x}, ${at.y}, 0)`;
@@ -631,6 +947,15 @@ function actor(page) {
await js`__demo.raise()`;
await sleep(140);
},
+ async rightClick(selector, where = {}) {
+ await me.moveTo(selector, where);
+ await js`__demo.press(${at.x}, ${at.y})`;
+ await mouse('mousePressed', { button: 'right', clickCount: 1 });
+ await sleep(70);
+ await mouse('mouseReleased', { button: 'right', clickCount: 1 });
+ await js`__demo.raise()`;
+ await sleep(140);
+ },
// A native