kaizen-agent 1.49.0 → 1.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/agents/kaizen-reviewer.md +1 -1
  2. package/cli/hermes.ts +5 -2
  3. package/cli/notes.test.ts +1 -1
  4. package/cli/settings.test.ts +2 -0
  5. package/cli/settings.ts +2 -2
  6. package/cli/state.test.ts +24 -0
  7. package/cli/state.ts +18 -0
  8. package/cli/versions.test.ts +154 -0
  9. package/cli/versions.ts +272 -0
  10. package/cli/video.test.ts +64 -3
  11. package/cli/video.ts +111 -18
  12. package/cli/web.ts +15 -0
  13. package/package.json +1 -1
  14. package/skills/kaizen/README.md +5 -5
  15. package/skills/kaizen/SKILL.md +10 -14
  16. package/skills/kaizen/config.default.yml +3 -3
  17. package/skills/kaizen/spec-main.md +18 -16
  18. package/skills/kaizen/spec-plan.md +6 -6
  19. package/skills/kaizen/spec-review.md +2 -2
  20. package/skills/kaizen-help/SKILL.md +6 -5
  21. package/skills/media/kaizen-video/SKILL.md +20 -2
  22. package/skills/media/kaizen-video/canvas.html +241 -0
  23. package/skills/media/kaizen-video/examples/canvas-film/cat.txt +31 -0
  24. package/skills/media/kaizen-video/examples/canvas-film/film.json +460 -0
  25. package/skills/media/kaizen-video/examples/canvas-film/lines.json +10 -0
  26. package/skills/media/kaizen-video/examples/canvas-film/skip.txt +18 -0
  27. package/skills/media/kaizen-video/examples/canvas-film/talk.txt +23 -0
  28. package/skills/media/kaizen-video/examples/canvas-film/wow.txt +24 -0
  29. package/skills/media/kaizen-video/examples/kaizen-promo/promo.json +17 -0
  30. package/skills/media/kaizen-video/examples/kaizen-promo/record.json +10 -0
  31. package/skills/media/kaizen-video/examples/notula-promo/promo.json +41 -0
  32. package/skills/media/kaizen-video/examples/notula-promo/record.json +135 -0
  33. package/skills/media/kaizen-video/examples/notula-promo/seed.php +20 -0
  34. package/skills/media/kaizen-video/examples/notula-promo/seed.py +38 -0
  35. package/skills/media/kaizen-video/presets/app-promo/CREDITS.txt +2 -0
  36. package/skills/media/kaizen-video/presets/app-promo/README.md +21 -0
  37. package/skills/media/kaizen-video/presets/app-promo/preset.json +7 -0
  38. package/skills/media/kaizen-video/presets/app-promo/template/compositions/end.html +25 -0
  39. package/skills/media/kaizen-video/presets/app-promo/template/compositions/hook.html +19 -0
  40. package/skills/media/kaizen-video/presets/app-promo/template/compositions/name.html +19 -0
  41. package/skills/media/kaizen-video/presets/app-promo/template/compositions/step.html +52 -0
  42. package/skills/media/kaizen-video/presets/app-promo/template/index.html +24 -0
  43. package/skills/media/kaizen-video/presets/film-cinematic-drama/.hidden +1 -0
  44. package/skills/media/kaizen-video/presets/film-explainer-canvas/.hidden +1 -0
  45. package/skills/media/kaizen-video/presets/film-explainer-canvas/CREDITS.txt +3 -0
  46. package/skills/media/kaizen-video/presets/film-explainer-canvas/README.md +7 -0
  47. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/fonts/InstrumentSerif.ttf +0 -0
  48. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/fonts/SpaceMono.ttf +0 -0
  49. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/boing.wav +0 -0
  50. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/ding.wav +0 -0
  51. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/ending.wav +0 -0
  52. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/pop.wav +0 -0
  53. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/reveal.wav +0 -0
  54. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/shutter.wav +0 -0
  55. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/stamp.wav +0 -0
  56. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/tick.wav +0 -0
  57. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/whoosh.wav +0 -0
  58. package/skills/media/kaizen-video/presets/film-explainer-canvas/style.json +15 -0
  59. package/skills/media/kaizen-video/presets/film-fun-energetic/.hidden +1 -0
  60. package/skills/media/kaizen-video/presets/film-promo-booth/.hidden +1 -0
  61. package/skills/media/kaizen-video/presets/film-viral-social/.hidden +1 -0
  62. package/skills/media/kaizen-video/presets/tiktok-explainer/index.html +1 -1
  63. package/skills/media/kaizen-video/references/canvas.md +60 -0
  64. package/skills/media/kaizen-video/references/presets.md +31 -0
  65. package/skills/media/kaizen-video/references/promo.md +148 -0
  66. package/skills/media/kaizen-video/references/revisions.md +11 -2
  67. package/skills/media/kaizen-video/scripts/make_film.py +157 -4
  68. package/skills/media/kaizen-video/scripts/make_promo.py +297 -0
  69. package/skills/media/kaizen-video/scripts/make_tiktok.py +34 -6
  70. package/skills/media/kaizen-video/scripts/pixel.py +40 -0
  71. package/skills/media/kaizen-video/scripts/record.mjs +103 -0
  72. package/web/board/approvals.ts +2 -2
  73. package/web/board/cards.ts +4 -4
  74. package/web/board/icebox.ts +6 -5
  75. package/web/board/panel.ts +2 -2
  76. package/web/board.html +24 -9
  77. package/web/board.js +24 -24
  78. package/web/notebook.js +10 -10
  79. package/web/notebook.ts +5 -1
  80. package/web/notes.html +19 -3
  81. package/web/term.js +1 -1
  82. package/web/video.html +62 -12
  83. package/web/video.js +67 -56
  84. package/web/video.ts +266 -33
package/web/video.ts CHANGED
@@ -5,10 +5,14 @@
5
5
 
6
6
  type Format = "9x16" | "16x9" | "4x5";
7
7
  type Job = { id: number; kind: string; state: string; step: number; total: number; label: string[]; error: string | null; place: number; name: string };
8
- type Output = { format: Format | null; file: string; thumb: string | null; srt: string | null; seconds: number | null };
8
+ // letter..recipe: a filed version's revision (cli/versions.ts); kind "new" is a render still being filed.
9
+ type Output = {
10
+ format: Format | null; file: string; thumb: string | null; srt: string | null; seconds: number | null; at: number;
11
+ letter?: string; rev?: number; kind?: "current" | "trying" | "history" | "new"; preset?: string; from?: string | null; recipe?: boolean;
12
+ };
9
13
  type Video = {
10
14
  place: number; where: string; name: string; mode: "film" | "footage"; preset: string; title: string; formats: Format[];
11
- platforms: string[]; seconds: number | null; text: string; poster: string | null; built: boolean; size: [number, number] | null; outputs: Output[];
15
+ platforms: string[]; seconds: number | null; text: string; poster: string | null; built: boolean; builtAt: number; size: [number, number] | null; outputs: Output[]; revising: string | null;
12
16
  job: Job | null; status: "draft" | "queued" | "building" | "rendering" | "ready" | "failed"; send: Send | null; sends: Send[];
13
17
  };
14
18
  type Send = { at: number; via: "localsend" | "whatsapp"; to: string; file: string; state: "waiting" | "uploading" | "sent" | "failed"; pct: number; error: string | null };
@@ -68,7 +72,9 @@ async function load() {
68
72
  // One tile per rendered shape; a video with nothing rendered yet shows once, at its own shape.
69
73
  function tiles() {
70
74
  return videos.flatMap((v) => {
71
- const outs = v.outputs.length ? v.outputs : [null];
75
+ // A version's tries and history stay on its page; the library shows what each version is now.
76
+ const live = v.outputs.filter((o) => o.kind !== "history" && o.kind !== "trying");
77
+ const outs = live.length ? live : [null];
72
78
  const shapes = new Map<string, Output | null>();
73
79
  for (const o of outs) if (!shapes.has(o?.format ?? v.formats[0]!)) shapes.set(o?.format ?? v.formats[0]!, o);
74
80
  return [...shapes].map(([f, o]) => ({ v, f: f as Format, o }));
@@ -85,6 +91,7 @@ function drawGrid() {
85
91
  });
86
92
  // Videos an agent is still setting up: no film.json yet, so only the agent knows them.
87
93
  const making = agents.filter((a) => a.alive && !videos.some((v) => v.place === a.place && v.name === a.name) && words.every((w) => a.name.includes(w)) && (!filter || filter === "busy" || filter === "draft"));
94
+ $("grid").removeAttribute("aria-busy");
88
95
  $("grid").innerHTML = making.map((a) => `<article class="vid" tabindex="0" data-p="${a.place}" data-n="${esc(a.name)}" aria-label="${esc(a.name)}, being made">
89
96
  <div class="thumb making" style="--ar:9/16"><span class="t">${a.asking ? "Claude is asking you something" : "Claude is making this"}</span></div>
90
97
  <div class="meta"><b>${esc(a.name)}</b><div class="plats"><i class="where">${esc(places[a.place]?.label ?? "")}</i></div>
@@ -148,10 +155,19 @@ function route() {
148
155
  $("wiz").hidden = !wiz;
149
156
  film = null;
150
157
  edits = new Map();
158
+ rtab = "form";
159
+ shown = null;
151
160
  sp = null;
152
161
  $("sendp").innerHTML = "";
162
+ // Opening a video: placeholders for the player and the form until its data arrives, as the board shows.
163
+ if (open && !cur()) {
164
+ parkDock();
165
+ // Not class "ed": refreshEditor takes a missing .ed to mean "draw the editor now".
166
+ $("editbody").innerHTML = `<div class="edskel" aria-busy="true"><span class="skel" style="aspect-ratio:9/16"></span>
167
+ <div style="display:grid;gap:10px"><span class="skel" style="height:36px;width:180px"></span><span class="skel" style="height:56px"></span><span class="skel" style="height:56px"></span><span class="skel" style="height:56px"></span></div></div>`;
168
+ }
153
169
  if (open) refreshEditor(true);
154
- else $("editbody").innerHTML = "";
170
+ else { parkDock(); $("editbody").innerHTML = ""; }
155
171
  if (wiz) drawWizard();
156
172
  drawDock();
157
173
  }
@@ -162,26 +178,29 @@ const cur = () => open && videos.find((v) => v.place === open!.place && v.name =
162
178
  async function refreshEditor(first = false) {
163
179
  const v = cur();
164
180
  if (!v) {
181
+ parkDock();
165
182
  const a = open && agentOn(open.place, open.name);
166
- if (a) $("editbody").innerHTML = `<div class="crumb"><button data-back>Videos</button> / ${esc(places[a.place]?.label ?? "")}</div>
183
+ if (a) $("editbody").innerHTML = `<div class="crumb"><button data-back>‹ Back to videos</button></div>
167
184
  <div class="ehead"><h2>${esc(a.name)}</h2></div><p class="note">Claude is setting this video up. Answer its questions above; the editor opens here once the video has its storyboard.</p>`;
168
185
  else if (videos.length) $("editbody").innerHTML = `<p class="blank">That video is gone. <button class="btn" data-back>Back to videos</button></p>`;
169
186
  return;
170
187
  }
171
- const jobKey = JSON.stringify(v.job && [v.job.id, v.job.state, v.job.step]);
172
- if (!first && film && jobKey === lastJob) return;
188
+ // What, when it changes, needs a redraw: the job, the set of rendered versions (a render or a delete),
189
+ // or the draft rebuilt (an edit or an Ask Claude change: Render final comes back).
190
+ const jobKey = JSON.stringify([v.job && [v.job.id, v.job.state, v.job.step], v.outputs.map((o) => [o.file, o.kind]), v.builtAt, v.revising]);
191
+ if (!first && (film || v.mode !== "film") && jobKey === lastJob) return;
173
192
  const builtNow = lastJob && v.job?.state === "done" && jobKey !== lastJob;
174
193
  lastJob = jobKey;
175
194
  // Nothing drawn for this video yet: the first answer after opening it, however it arrives.
176
195
  const fresh = first || !$("edit").querySelector(".ed");
177
196
  if (v.mode === "film") {
178
197
  const r = await fetch(`/video/film?p=${v.place}&name=${encodeURIComponent(v.name)}`);
179
- if (!r.ok) { $("editbody").innerHTML = `<p class="blank">Could not read this film's film.json.</p>`; return; }
198
+ if (!r.ok) { parkDock(); $("editbody").innerHTML = `<p class="blank">Could not read this film's film.json.</p>`; return; }
180
199
  film = await r.json();
181
200
  }
182
201
  if (fresh) picked = new Set(film?.platforms.length ? film.platforms : v.platforms);
183
- if (fresh || v.mode !== "film") drawEditor(v);
184
- else { drawJob(v); drawFiles(v); if (builtNow) reloadPreview(v); }
202
+ if (fresh) drawEditor(v);
203
+ else { drawJob(v); drawFiles(v); drawRender(v); if (builtNow && !shown) reloadPreview(v); }
185
204
  }
186
205
 
187
206
  function drawEditor(v: Video) {
@@ -190,35 +209,47 @@ function drawEditor(v: Video) {
190
209
  const [w, h] = v.size ?? SIZE[f];
191
210
  const beats = film?.beats ?? [];
192
211
  dur = beats.reduce((a, b) => Math.max(a, b.start + (b.len ?? 0)), 0) || v.seconds || 0;
212
+ // The live terminal (#dock) is parked outside the editor while it is redrawn, then put back in the
213
+ // Terminal tab: the same element, so its session stays connected.
214
+ const dock = parkDock();
193
215
  $("editbody").innerHTML = `
194
- <div class="crumb"><button data-back>Videos</button> / ${esc(v.where)}</div>
216
+ <div class="crumb"><button data-back>‹ Back to videos</button></div>
195
217
  <div class="ehead"><h2>${esc(v.name)}</h2><span class="pill ${v.status}" id="stat">${LABEL[v.status]}</span>
196
218
  <div class="acts">${v.mode === "film" ? `<button class="btn" id="stillsBtn" title="Build the film and take three still frames">Preview stills</button>` : ""}
197
- <button class="btn pri" id="render">Render final</button></div></div>
219
+ <span class="pill ready" id="rdone" hidden title="Nothing changed since the last render">Rendered</span><button class="btn pri" id="render">Render final</button></div></div>
198
220
  <div class="ed">
199
221
  <div class="player">
200
222
  <div class="screen" style="--ar:${w}/${h}" id="screen">${v.built
201
223
  ? `<iframe id="frame" title="Preview" src="${esc(fileUrl(v, "v/film/index.html"))}" width="${w}" height="${h}"></iframe>`
202
224
  : `<div class="none">No preview yet. Press <b>Preview stills</b> or save a change to build it.</div>`}</div>
203
- <div class="ctrl"><button class="play" id="play" aria-label="Play" ${v.built ? "" : "disabled"}><svg><use href="#i-play"/></svg></button><span id="time">0:00 / ${mmss(dur)}</span><span class="sp"></span><span id="shape">${ratio(f)} · ${esc(v.preset)}</span></div>
225
+ <div class="ctrl"><button class="play" id="play" aria-label="Play" ${v.built ? "" : "disabled"}><svg><use href="#i-play"/></svg></button><span id="time">0:00 / ${mmss(dur)}</span><span class="sp"></span><span id="shape">${v.built ? `Draft · ${esc(v.preset)}` : `${ratio(f)} · ${esc(v.preset)}`}</span></div>
204
226
  ${beats.length ? `<div class="strip" id="strip">${beats.map((b, i) => `<button style="flex:${Math.max(1, b.len ?? 1)};--c:${COLORS[i % COLORS.length]}" data-b="${i}" title="${esc(b.kind)} ${mmss(b.start)}">${i + 1}</button>`).join("")}<span class="head" id="head" style="left:0"></span></div>` : ""}
205
227
  <div class="stills" id="stills">${(film?.stills ?? []).map((s) => `<a href="${esc(fileUrl(v, s))}" target="_blank" rel="noopener"><img src="${esc(fileUrl(v, s))}?t=${Date.now()}" alt="Still frame"></a>`).join("")}</div>
206
228
  </div>
207
- <div class="beats">
229
+ <div class="rcol">
230
+ <div class="tabs" role="tablist" aria-label="Edit or talk to Claude">
231
+ <button role="tab" id="tab-form" data-tab="form" aria-controls="formpane">Form</button><button role="tab" id="tab-term" data-tab="term" aria-controls="termpane">Terminal<i class="tdot" aria-hidden="true"></i><span class="sr" id="tdotsr"></span></button></div>
232
+ <div class="termpane" id="termpane" role="tabpanel" aria-labelledby="tab-term"><p class="note tnone">No Claude session for this video yet. Ask Claude for a change in the Form tab and it opens here.</p></div>
233
+ <div class="beats" id="formpane" role="tabpanel" aria-labelledby="tab-form">
208
234
  <div id="job"></div>
209
235
  ${v.mode === "film" ? beats.map((b, i) => beatRow(b, i)).join("") : `<p class="note">A video made from your footage. Its words come from what you said; change them by asking the kaizen-video skill. Render it again here.</p>`}
210
236
  <div class="savebar"><div class="chips" id="plats" role="group" aria-label="Where it goes">${Object.keys(PLATFORMS).map((p) => `<button class="chip${picked.has(p) ? " on" : ""}" data-p="${esc(p)}">${esc(p)}</button>`).join("")}</div>
211
237
  ${v.mode === "film" ? `<button class="btn pri" id="save">Save changes</button>` : ""}</div>
212
238
  <p class="note" id="platnote"></p>
213
239
  <div class="ask"><input id="askin" maxlength="2000" placeholder="Ask Claude for a bigger change, like a new voice line or a punchier hook" aria-label="Ask Claude to change this video"><button class="btn pri" id="askgo">Send</button></div>
214
- <p class="note">Claude works in a terminal at the top of this page; answer it there.</p>
240
+ <p class="note">Claude works in the Terminal tab; answer it there.</p>
215
241
  <div class="files" id="files"></div>
216
242
  </div>
243
+ </div>
217
244
  </div>`;
245
+ $("termpane").append(dock);
246
+ showTab();
218
247
  fit();
219
248
  drawPlats();
220
249
  drawJob(v);
221
250
  drawFiles(v);
251
+ drawRender(v);
252
+ if (shown) showVersion(v);
222
253
  }
223
254
 
224
255
  function beatRow(b: Beat, i: number) {
@@ -273,13 +304,110 @@ function drawJob(v: Video) {
273
304
  ${j.state === "failed" && film?.log ? `<pre>${esc(film.log.split("\n").slice(-25).join("\n"))}</pre>` : ""}</div>`;
274
305
  }
275
306
 
307
+ // Versions: the draft (the live build, not rendered) first, then each rendered file, labelled with the
308
+ // preset it was rendered in (output/<name>/<preset>/<file>). Clicking a row shows it in the player.
309
+ let shown: string | null = null; // null: the draft; else a rendered file's path ("o/<preset>/<file>")
310
+ const presetOf = (file: string) => file.split("/")[1] ?? "";
311
+ // The draft's preset for a file: a filed revision carries it; a loose render sits in output/<name>/<preset>/.
312
+ const presetIn = (o: Output) => o.preset ?? presetOf(o.file);
313
+ const stamp = (ms: number) => new Date(ms).toLocaleString(undefined, { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" });
314
+ // The draft has a render newer than its last build, in its own preset: nothing new to render.
315
+ const draftDone = (v: Video) => v.built && v.outputs.some((o) => presetIn(o) === v.preset && o.kind !== "history" && o.at >= v.builtAt);
316
+
317
+ // What a person sees for a version: the video's name and its preset (letters are only the store's key),
318
+ // with "(2)", "(3)" when the same preset was rendered as more than one version.
319
+ function vtitle(v: Video, l: string) {
320
+ const firsts = v.outputs.filter((o) => o.letter && o.kind === "current");
321
+ const me = firsts.find((o) => o.letter === l);
322
+ if (!me) return v.name;
323
+ const same = firsts.filter((o) => presetIn(o) === presetIn(me));
324
+ const i = same.indexOf(me);
325
+ return `${v.name} · ${presetIn(me)}${same.length > 1 && i > 0 ? ` (${i + 1})` : ""}`;
326
+ }
327
+
328
+ // One row: a button that shows it in the player, a line of facts, then its actions (wrapping under the
329
+ // name on a phone).
330
+ function verRow(v: Video, o: Output, label: string, facts: string, acts: string, cls = "") {
331
+ return `<div class="file ver${cls}${shown === o.file ? " on" : ""}" data-show="${esc(o.file)}">
332
+ <button class="vname" data-show="${esc(o.file)}" aria-pressed="${shown === o.file}">${label}</button>
333
+ <span class="vfacts">${facts}</span>
334
+ <span class="acts">${acts}</span></div>`;
335
+ }
336
+ const openLinks = (v: Video, o: Output) => `<a href="${esc(fileUrl(v, o.file))}" target="_blank" rel="noopener">Open</a>${o.srt ? `<a href="${esc(fileUrl(v, o.srt))}" target="_blank" rel="noopener">Captions</a>` : ""}`;
337
+ const vact = (a: string, l: string, text: string, cls = "btn", n?: number, aria?: string) =>
338
+ `<button class="${cls}" data-vact="${a}" data-l="${esc(l)}"${n != null ? ` data-n="${n}"` : ""}${aria ? ` aria-label="${esc(aria)}"` : ""}>${text}</button>`;
339
+
276
340
  function drawFiles(v: Video) {
277
341
  const el = document.getElementById("files");
278
342
  if (!el) return;
279
- el.innerHTML = v.outputs.length ? `<p class="note" style="margin:0">Finished files</p>` + v.outputs.map((o) => `<div class="file"><span class="pill ready">${ratio(o.format)}</span><b>${esc(o.file.split("/").pop())}</b>
280
- ${o.seconds != null ? `<span class="note" style="margin:0">${mmss(o.seconds)}</span>` : ""}
281
- <a href="${esc(fileUrl(v, o.file))}" target="_blank" rel="noopener">Open</a>${o.srt ? `<a href="${esc(fileUrl(v, o.srt))}" target="_blank" rel="noopener">Captions</a>` : ""}
282
- <button class="btn" data-sendfile="${esc(o.file)}">Send</button></div>`).join("") : "";
343
+ if (shown && !v.outputs.some((o) => o.file === shown)) shown = null;
344
+ const dur = (o: Output) => o.seconds != null ? ` · ${mmss(o.seconds)}` : "";
345
+ const draft = v.built ? `<div class="file ver${shown ? "" : " on"}" data-show="">
346
+ <button class="vname" data-show="" aria-pressed="${!shown}"><span class="pill draft">Draft</span><b>${esc(v.preset)}</b></button>
347
+ <span class="vfacts">${v.revising ? `revising ${esc(vtitle(v, v.revising))}; a render becomes its next v` : "live preview, not rendered"}</span>
348
+ ${v.revising ? `<span class="acts">${vact("new", v.revising, "Make a new version instead", "btn ghost")}</span>` : ""}</div>` : "";
349
+ // Filed versions, by letter: the current revision, its try (if any) and its history.
350
+ const letters = [...new Set(v.outputs.filter((o) => o.letter).map((o) => o.letter!))];
351
+ const groups = letters.map((l) => {
352
+ const revs = v.outputs.filter((o) => o.letter === l);
353
+ const cur = revs.find((o) => o.kind === "current"), tr = revs.find((o) => o.kind === "trying");
354
+ const hist = revs.filter((o) => o.kind === "history").sort((a, b) => b.rev! - a.rev!);
355
+ if (!cur) return "";
356
+ const N = vtitle(v, l);
357
+ const head = verRow(v, cur, `<b>${esc(N)}</b><span class="pill ver-l">v${cur.rev}</span>`,
358
+ `${dur(cur).slice(3)}${v.revising === l ? `${cur.seconds != null ? " · " : ""}in the draft` : ""}`,
359
+ (cur.recipe ? vact("revise", l, "Revise", "btn", undefined, `Revise ${N}`) : "")
360
+ + openLinks(v, cur) + `<button class="btn" data-sendfile="${esc(cur.file)}">Send</button>`
361
+ + vact("delete", l, "Delete", "btn danger", undefined, `Delete ${N} and its history`));
362
+ const tryRow = tr ? verRow(v, tr, `<span class="pill draft">Trying</span><b>v${tr.rev}</b>`,
363
+ `from v${esc((tr.from ?? "").replace(/^[a-z]+/, "") || String(cur.rev))}${dur(tr)} · compare, then keep or revert`,
364
+ vact("keep", l, "Keep", "btn pri", undefined, `Keep v${tr.rev} as ${N}`) + vact("revert", l, "Revert", "btn", undefined, `Revert ${N} to v${cur.rev}`) + openLinks(v, tr), " sub") : "";
365
+ const histRows = hist.length ? `<details class="hist"${hist.some((o) => o.file === shown) ? " open" : ""}><summary>Earlier versions (${hist.length})</summary>${hist.map((o) =>
366
+ verRow(v, o, `<b>v${o.rev}</b>`, `${stamp(o.at)}${dur(o)}`,
367
+ vact("restore", l, "Restore", "btn", o.rev, `Restore v${o.rev} as ${N}`) + openLinks(v, o) + vact("delete", l, "Delete", "btn danger", o.rev, `Delete v${o.rev} of ${N}`), " sub")).join("")}</details>` : "";
368
+ return `<div class="vgroup">${head}${tryRow}${histRows}</div>`;
369
+ });
370
+ // Renders still being filed (a few seconds after they finish) and the older videos/<name>/out/ files.
371
+ const rest = v.outputs.filter((o) => !o.letter).map((o) => verRow(v, o,
372
+ `<span class="pill ready">${ratio(o.format)}</span><b>${esc(presetIn(o))} · ${esc(o.file.split("/").pop())}</b>`,
373
+ o.kind === "new" ? `just rendered; becoming a version${dur(o)}` : dur(o).slice(3),
374
+ openLinks(v, o) + (o.kind === "new" ? "" : `<button class="btn" data-sendfile="${esc(o.file)}">Send</button><button class="btn danger" data-delfile="${esc(o.file)}" aria-label="Delete ${esc(presetIn(o))} version">Delete</button>`)));
375
+ el.innerHTML = draft || v.outputs.length ? `<p class="note" style="margin:0">Versions</p>` + draft + groups.join("") + rest.join("") : "";
376
+ }
377
+ // Render final turns the draft into files. Nothing to do while a rendered version is shown, or when the
378
+ // draft was rendered in its current preset after its last build; an edit or an Ask Claude change rebuilds
379
+ // the draft, and the button comes back.
380
+ function drawRender(v: Video) {
381
+ const b = document.getElementById("render"), done = document.getElementById("rdone");
382
+ if (!b || !done) return;
383
+ const off = !!shown || draftDone(v);
384
+ b.hidden = off; done.hidden = !off;
385
+ done.textContent = shown ? "Rendered version" : "Rendered";
386
+ b.textContent = v.revising ? "Render new v" : "Render final";
387
+ }
388
+ // The player shows the draft (the built page, driven by the play button) or a rendered MP4 (its own controls).
389
+ function showVersion(v: Video) {
390
+ const box = document.getElementById("screen"), label = document.getElementById("shape"), play = document.getElementById("play") as HTMLButtonElement | null;
391
+ const o = shown && v.outputs.find((x) => x.file === shown);
392
+ if (!box) return;
393
+ // A rendered file plays with its own controls; the draft's play button and beat strip step aside.
394
+ box.closest(".player")?.classList.toggle("file", !!o);
395
+ if (!o) {
396
+ shown = null;
397
+ if (v.built) reloadPreview(v);
398
+ if (label) label.textContent = `Draft · ${v.preset}`;
399
+ const t = document.getElementById("time"), p = document.getElementById("play");
400
+ if (t) t.textContent = `0:00 / ${mmss(dur)}`;
401
+ if (p) { playing = false; p.innerHTML = `<svg><use href="#i-play"/></svg>`; p.setAttribute("aria-label", "Play"); }
402
+ } else {
403
+ box.innerHTML = `<video id="vid" src="${esc(fileUrl(v, o.file))}" controls playsinline preload="metadata" aria-label="Rendered ${esc(presetIn(o))} video"></video>`;
404
+ if (play) play.disabled = true;
405
+ const t = document.getElementById("time");
406
+ if (t) t.textContent = o.seconds != null ? mmss(o.seconds) : "";
407
+ if (label) label.textContent = `${o.letter ? `${vtitle(v, o.letter)} · v${o.rev}${o.kind === "trying" ? " (trying)" : o.kind === "history" ? " (history)" : ""}` : "Rendered · ${presetIn(o)}"}${o.seconds != null ? ` · ${mmss(o.seconds)}` : ""}`;
408
+ }
409
+ drawFiles(v);
410
+ drawRender(v);
283
411
  }
284
412
 
285
413
  // ---- Send: the panel under the editor. Drawn on the person's own actions only, so a
@@ -392,20 +520,76 @@ addEventListener("message", (e) => {
392
520
  }
393
521
  });
394
522
 
523
+ // Tabs: arrow keys move between Form and Terminal (the WAI-ARIA tabs pattern).
524
+ $("edit").addEventListener("keydown", (e) => {
525
+ const t = (e.target as HTMLElement).closest<HTMLElement>("[data-tab]");
526
+ if (!t || (e.key !== "ArrowLeft" && e.key !== "ArrowRight")) return;
527
+ e.preventDefault();
528
+ rtab = rtab === "form" ? "term" : "form";
529
+ showTab();
530
+ document.querySelector<HTMLElement>(`[data-tab=${rtab}]`)?.focus();
531
+ });
395
532
  $("edit").addEventListener("click", async (e) => {
396
533
  const t = e.target as HTMLElement;
397
534
  const v = cur();
398
535
  if (t.closest("[data-back]")) return go(null);
536
+ const tab = t.closest<HTMLElement>("[data-tab]");
537
+ if (tab) { rtab = tab.dataset.tab as "form" | "term"; return showTab(); }
399
538
  if (!v) return;
400
539
  const beat = t.closest<HTMLElement>(".beat>button");
401
540
  if (beat) return selectBeat(Number(beat.parentElement!.dataset.b));
402
541
  const seg = t.closest<HTMLElement>("#strip button");
403
542
  if (seg) return selectBeat(Number(seg.dataset.b));
404
543
  if (t.closest("#play")) return send({ kz: playing ? "pause" : "play" });
544
+ const ver = t.closest<HTMLElement>("[data-show]");
545
+ if (ver && (t.closest(".vname") || !t.closest("a, button"))) {
546
+ const want = ver.dataset.show || null;
547
+ if (want === shown) return; // already showing: a second click must not reload the draft
548
+ shown = want;
549
+ return showVersion(v);
550
+ }
405
551
  const chip = t.closest<HTMLElement>("#plats .chip");
406
552
  if (chip) { const p = chip.dataset.p!; picked.has(p) ? picked.delete(p) : picked.add(p); chip.classList.toggle("on", picked.has(p)); return drawPlats(); }
407
553
  const sf = t.closest<HTMLElement>("[data-sendfile]");
408
554
  if (sf) return openSend(sf.dataset.sendfile!);
555
+ // Version actions (cli/versions.ts). Each asks first where something is replaced or removed.
556
+ const va = t.closest<HTMLElement>("[data-vact]");
557
+ if (va) {
558
+ const a = va.dataset.vact!, l = va.dataset.l!, n = va.dataset.n ? Number(va.dataset.n) : undefined;
559
+ const tr = v.outputs.find((o) => o.letter === l && o.kind === "trying"), cur = v.outputs.find((o) => o.letter === l && o.kind === "current");
560
+ const N = vtitle(v, l);
561
+ const unrendered = edits.size > 0 || (v.built && !draftDone(v));
562
+ const ask = a === "revise" ? (unrendered ? `The draft has changes that are not rendered. Revising ${N} replaces the draft with ${N}'s recipe, and those changes are lost. Go on?` : null)
563
+ : a === "keep" ? `Keep v${tr?.rev} as ${N}? The current v${cur?.rev} moves to ${N}'s history, where you can restore it.`
564
+ : a === "revert" ? `Revert ${N}? The try v${tr?.rev} is deleted from disk${cur?.recipe ? `, and the draft goes back to ${N}${unrendered ? "; its changes that are not rendered are lost" : ""}` : ""}.`
565
+ : a === "restore" ? `Restore v${n} for ${N}? The current v${cur?.rev} moves to the history.${v.revising === l && v.outputs.find((o) => o.letter === l && o.rev === n)?.recipe ? ` The draft becomes v${n}${unrendered ? "; its changes that are not rendered are lost" : ""}.` : ""}`
566
+ : a === "delete" ? (n != null ? `Delete v${n} from ${N}'s history? Its video, captions and thumbnail are removed from disk.` : `Delete ${N} with its try and its whole history? Every one of its videos is removed from disk. Other versions and the draft stay.`)
567
+ : null;
568
+ if (ask && !confirm(ask)) return;
569
+ try {
570
+ const r = await post("/video/version", { p: v.place, name: v.name, action: a, letter: l, n, all: a === "delete" && n == null });
571
+ if (a === "revise" || a === "revert") { edits = new Map(); shown = null; }
572
+ if (a === "delete" && shown && v.outputs.find((o) => o.file === shown)?.letter === l && (n == null || shown.includes(`/${l}/${n}/`))) shown = null;
573
+ toast(a === "revise" ? `The draft is now ${N}. Change it, then render a try.` : a === "keep" ? `Kept: ${N} is now v${tr?.rev}` : a === "revert" ? `Reverted ${N}` : a === "restore" ? `Version ${l} is v${n} again` : a === "new" ? "The next render makes a new version" : "Deleted");
574
+ if (r.note) toast(r.note);
575
+ showVersion(v);
576
+ load();
577
+ } catch (err) { toast(err instanceof Error ? err.message : String(err)); }
578
+ return;
579
+ }
580
+ // Delete a rendered version: asks first, names what goes, and only touches that render's files.
581
+ const del = t.closest<HTMLElement>("[data-delfile]");
582
+ if (del) {
583
+ const f = del.dataset.delfile!, o = v.outputs.find((x) => x.file === f);
584
+ if (!o || !confirm(`Delete the ${presetOf(f)} version (${f.split("/").pop()})? Its rendered video${o.srt ? ", captions" : ""}${o.thumb ? ", thumbnail" : ""} are removed from disk. The draft and other versions stay.`)) return;
585
+ try {
586
+ await post("/video/delete", { p: v.place, name: v.name, file: f });
587
+ if (shown === f) { shown = null; showVersion(v); }
588
+ toast("Version deleted");
589
+ load();
590
+ } catch (err) { toast(err instanceof Error ? err.message : String(err)); }
591
+ return;
592
+ }
409
593
  const cancel = t.closest<HTMLElement>("[data-cancel]");
410
594
  try {
411
595
  if (cancel) { await post("/video/cancel", { id: Number(cancel.dataset.cancel) }); toast("Cancelled"); }
@@ -465,6 +649,26 @@ const loadTerm = () => termLib ??= new Promise((ok, no) => {
465
649
  document.head.append(sc);
466
650
  });
467
651
  let mounted: { key: string; off: () => void } | null = null;
652
+ // The editor's right column: the form (default) or Claude's terminal. Reset to the form for each video.
653
+ let rtab: "form" | "term" = "form";
654
+ // #dock lives in the Terminal tab, which is inside #editbody: move it out before #editbody is rewritten,
655
+ // or the rewrite deletes it (and the live terminal with it). Parked, it shows above the editor, as in the
656
+ // "Claude is setting this video up" state, which has no tabs.
657
+ function parkDock() {
658
+ const d = $("dock");
659
+ if (d.parentElement !== $("edit")) $("edit").prepend(d);
660
+ return d;
661
+ }
662
+ function showTab() {
663
+ const f = document.getElementById("formpane"), t = document.getElementById("termpane");
664
+ if (!f || !t) return;
665
+ f.hidden = rtab !== "form"; t.hidden = rtab !== "term";
666
+ for (const b of document.querySelectorAll<HTMLElement>("[data-tab]")) {
667
+ b.setAttribute("aria-selected", String(b.dataset.tab === rtab));
668
+ b.tabIndex = b.dataset.tab === rtab ? 0 : -1;
669
+ }
670
+ if (rtab === "term") drawDock();
671
+ }
468
672
 
469
673
  async function drawDock() {
470
674
  const dock = $("dock");
@@ -472,15 +676,25 @@ async function drawDock() {
472
676
  if (!a) {
473
677
  mounted?.off(); mounted = null;
474
678
  dock.innerHTML = "";
679
+ document.querySelector("[data-tab=term]")?.classList.remove("ask");
680
+ const sr = document.getElementById("tdotsr");
681
+ if (sr) sr.textContent = "";
475
682
  return;
476
683
  }
477
- if (mounted?.key !== a.pty) {
684
+ if (mounted?.key !== a.pty && !document.getElementById("term")?.dataset.pty?.includes(a.pty)) {
478
685
  mounted?.off(); mounted = null;
479
- dock.innerHTML = `<div class="agentbar" id="abar"></div><div class="term" id="term"></div>`;
686
+ dock.innerHTML = `<div class="agentbar" id="abar"></div><div class="term" id="term" data-pty="${esc(a.pty)}"></div>`;
687
+ }
688
+ // The terminal starts only once it can be seen: started in a hidden tab, at zero size, it draws nothing.
689
+ // A placeholder claims the slot before the await, so two overlapping calls never mount it twice.
690
+ const seen = !dock.closest("#termpane") || rtab === "term";
691
+ if (mounted?.key !== a.pty && seen) {
692
+ const slot = { key: a.pty, off: () => {} };
693
+ mounted = slot;
480
694
  try {
481
695
  const mount = await loadTerm();
482
696
  const el = document.getElementById("term");
483
- if (el && !mounted) mounted = { key: a.pty, off: mount(el, a.pty, () => load()) };
697
+ if (el && mounted === slot) slot.off = mount(el, a.pty, () => load());
484
698
  } catch {
485
699
  // Keep the message: the next poll would rebuild the dock and try again, every few seconds.
486
700
  mounted = { key: a.pty, off: () => {} };
@@ -488,6 +702,9 @@ async function drawDock() {
488
702
  if (el) el.textContent = "The terminal could not load. Open it on the board instead.";
489
703
  }
490
704
  }
705
+ document.querySelector("[data-tab=term]")?.classList.toggle("ask", a.alive && a.asking);
706
+ const sr = document.getElementById("tdotsr");
707
+ if (sr) sr.textContent = a.alive && a.asking ? " (Claude is asking you something)" : "";
491
708
  const bar = document.getElementById("abar");
492
709
  if (!bar) return;
493
710
  bar.className = "agentbar" + (a.alive && a.asking ? " asking" : "");
@@ -498,8 +715,8 @@ async function drawDock() {
498
715
  // ---- New video: one form, the mockup's. Every choice goes into the agent's request.
499
716
 
500
717
  const LANG_NAMES: Record<string, string> = { id: "Indonesian", en: "English" };
501
- const wiz = { source: "brief" as "brief" | "footage", brief: "", folder: "", preset: "", platforms: new Set(["TikTok"]), seconds: 60, language: "id", place: 0 };
502
- let wizPresets: { name: string; kind: "film" | "footage"; label: string }[] = [];
718
+ const wiz = { source: "brief" as "brief" | "footage", brief: "", folder: "", assets: "", preset: "", platforms: new Set(["TikTok"]), seconds: 60, language: "id", place: 0 };
719
+ let wizPresets: { name: string; kind: "film" | "footage" | "template"; label: string; hidden?: true }[] = [];
503
720
  let limits: Record<string, number> = {};
504
721
  const LEN_MIN = 15, LEN_MAX = 300;
505
722
  const tick = (s: number) => `${((s - LEN_MIN) / (LEN_MAX - LEN_MIN)) * 100}%`;
@@ -509,11 +726,13 @@ async function drawWizard() {
509
726
  const d = await (await fetch(`/video/presets?p=${wiz.place}`)).json();
510
727
  wizPresets = d.presets; limits = d.limits;
511
728
  } catch { toast("The board is not running"); return; }
512
- const kind = wiz.source === "brief" ? "film" : "footage";
513
- const list = wizPresets.filter((p) => p.kind === kind);
514
- if (!list.some((p) => p.name === wiz.preset)) wiz.preset = list[0]?.name ?? "";
729
+ // A template preset films a product, so it needs a brief; a footage preset edits the user's recording,
730
+ // so it needs footage; a film preset works from either start. Hidden presets stay off the list.
731
+ const list = wizPresets.filter((p) => !p.hidden && (p.kind === "film" || (p.kind === "template") === (wiz.source === "brief")));
732
+ const kind = wiz.source === "brief" ? "film" : "footage"; // the default is one of the start's own kind
733
+ if (!list.some((p) => p.name === wiz.preset)) wiz.preset = (list.find((p) => p.kind === kind) ?? list.find((p) => p.kind === "template") ?? list[0])?.name ?? "";
515
734
  $("wiz").innerHTML = `
516
- <div class="crumb"><button data-back>Videos</button> /</div>
735
+ <div class="crumb"><button data-back>‹ Back to videos</button></div>
517
736
  <div class="ehead"><h2>New video</h2></div>
518
737
  <form class="card" id="wform" novalidate>
519
738
  <div><h3>Start from</h3><div class="src">
@@ -521,10 +740,12 @@ async function drawWizard() {
521
740
  <button type="button" class="opt${wiz.source === "footage" ? " on" : ""}" data-src="footage"><b>My footage</b><small>A talking-head video already on this computer. Claude cuts dead air and retakes, then captions it.</small></button>
522
741
  </div></div>
523
742
  ${wiz.source === "brief"
524
- ? `<label style="display:grid;gap:6px"><h3 style="margin:0">Brief</h3><textarea id="wbrief" maxlength="4000" placeholder="60-second promo for … in Indonesian, friendly, ends with …">${esc(wiz.brief)}</textarea></label>`
743
+ ? `<label style="display:grid;gap:6px"><h3 style="margin:0">Brief</h3><textarea id="wbrief" maxlength="4000" placeholder="60-second promo for … in Indonesian, friendly, ends with …">${esc(wiz.brief)}</textarea></label>
744
+ <div><h3>Your assets <small>(optional)</small></h3><div class="pickrow"><input type="text" id="wassets" value="${esc(wiz.assets)}" placeholder="/home/you/Pictures/brand" aria-label="Assets folder"><button type="button" class="btn" id="wpicka">Pick…</button></div>
745
+ <p class="note">PNGs, logos, graphics, photos, a deck or clips Claude should use. Leave empty to make everything from scratch.</p></div>`
525
746
  : `<div><h3>Footage folder</h3><div class="pickrow"><input type="text" id="wfolder" value="${esc(wiz.folder)}" placeholder="/home/you/Videos/recording" aria-label="Footage folder"><button type="button" class="btn" id="wpick">Pick…</button></div>
526
747
  <p class="note">Claude copies the video from this folder into the video's own folder; the original stays where it is.</p></div>`}
527
- <div><h3>Style preset</h3><div class="styles">${list.map((p) => `<button type="button" class="sty${p.name === wiz.preset ? " on" : ""}" data-preset="${esc(p.name)}"><b>${esc(p.label)}</b><small>${esc(p.name)}</small></button>`).join("") || `<p class="note">No ${kind} presets found.</p>`}</div></div>
748
+ <div><h3>Style preset</h3><div class="styles">${list.map((p) => `<button type="button" class="sty${p.name === wiz.preset ? " on" : ""}" data-preset="${esc(p.name)}"><b>${esc(p.label)}</b><small>${esc(p.name)} · ${p.kind}</small></button>`).join("") || `<p class="note">No presets found.</p>`}</div></div>
528
749
  <div><h3>Where it goes <small>(pick one or more)</small></h3><div class="chips" id="wplats">${Object.keys(PLATFORMS).map((p) => `<button type="button" class="chip${wiz.platforms.has(p) ? " on" : ""}" data-plat="${esc(p)}">${esc(p)}</button>`).join("")}</div><p class="note" id="wplatnote"></p></div>
529
750
  <div><h3>Length</h3>
530
751
  <div class="lenrow"><input type="range" id="wlen" min="${LEN_MIN}" max="${LEN_MAX}" step="5" value="${Math.min(LEN_MAX, wiz.seconds)}" aria-label="Length in seconds"><input type="text" id="wlentxt" value="${mmss(wiz.seconds)}" inputmode="numeric" aria-label="Length as minutes:seconds"></div>
@@ -558,6 +779,11 @@ $("wiz").addEventListener("click", async (e) => {
558
779
  if (pr) { wiz.preset = pr.dataset.preset!; for (const b of $("wiz").querySelectorAll("[data-preset]")) b.classList.toggle("on", b === pr); return; }
559
780
  const pl = t.closest<HTMLElement>("[data-plat]");
560
781
  if (pl) { const p = pl.dataset.plat!; wiz.platforms.has(p) ? wiz.platforms.delete(p) : wiz.platforms.add(p); pl.classList.toggle("on", wiz.platforms.has(p)); return wizNotes(); }
782
+ if (t.closest("#wpicka")) {
783
+ try { const r = await post("/pick-folder", {}); if (r.path) { wiz.assets = r.path; ($("wassets") as HTMLInputElement).value = r.path; } }
784
+ catch (err) { toast(err instanceof Error ? err.message : String(err)); }
785
+ return;
786
+ }
561
787
  if (t.closest("#wpick")) {
562
788
  try { const r = await post("/pick-folder", {}); if (r.path) { wiz.folder = r.path; ($("wfolder") as HTMLInputElement).value = r.path; } }
563
789
  catch (err) { toast(err instanceof Error ? err.message : String(err)); }
@@ -567,11 +793,13 @@ const keepText = () => {
567
793
  const b = document.getElementById("wbrief") as HTMLTextAreaElement | null, f = document.getElementById("wfolder") as HTMLInputElement | null;
568
794
  if (b) wiz.brief = b.value;
569
795
  if (f) wiz.folder = f.value;
796
+ const a = document.getElementById("wassets") as HTMLInputElement | null;
797
+ if (a) wiz.assets = a.value;
570
798
  };
571
799
  $("wiz").addEventListener("input", (e) => {
572
800
  const t = e.target as HTMLInputElement;
573
801
  if (t.id === "wlen") { wiz.seconds = Number(t.value); ($("wlentxt") as HTMLInputElement).value = mmss(wiz.seconds); wizNotes(); }
574
- else if (t.id === "wbrief" || t.id === "wfolder") keepText();
802
+ else if (t.id === "wbrief" || t.id === "wfolder" || t.id === "wassets") keepText();
575
803
  });
576
804
  $("wiz").addEventListener("change", (e) => {
577
805
  const t = e.target as HTMLInputElement;
@@ -590,8 +818,8 @@ $("wiz").addEventListener("submit", async (e) => {
590
818
  const btn = $("wgo") as HTMLButtonElement;
591
819
  btn.disabled = true;
592
820
  try {
593
- const r = await post("/video/new", { p: wiz.place, source: wiz.source, brief: wiz.brief, folder: wiz.folder, preset: wiz.preset, platforms: [...wiz.platforms], seconds: wiz.seconds, language: wiz.language });
594
- wiz.brief = ""; wiz.folder = "";
821
+ const r = await post("/video/new", { p: wiz.place, source: wiz.source, brief: wiz.brief, folder: wiz.folder, assets: wiz.source === "brief" ? wiz.assets : "", preset: wiz.preset, platforms: [...wiz.platforms], seconds: wiz.seconds, language: wiz.language });
822
+ wiz.brief = ""; wiz.folder = ""; wiz.assets = "";
595
823
  await load();
596
824
  go(wiz.place, r.name);
597
825
  toast(r.pty ? "Claude started. Answer its questions in the terminal at the top." : "Claude opened in a terminal window.");
@@ -605,6 +833,11 @@ function listen() {
605
833
  es.onmessage = () => load();
606
834
  }
607
835
 
836
+ // The board only watches its own state, not video folders: a draft Claude rebuilds in its terminal (an Ask
837
+ // Claude change) lands unannounced. While a video is open and the tab is visible, look again every 5 s,
838
+ // so its Versions and Render final follow. Cheap: a few stat calls, durations are cached.
839
+ setInterval(() => { if (open && document.visibilityState === "visible") load(); }, 5000);
840
+
608
841
  route();
609
842
  load();
610
843
  listen();