kaizen-agent 1.49.0 → 1.49.1

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 (67) hide show
  1. package/cli/hermes.ts +5 -2
  2. package/cli/state.test.ts +13 -0
  3. package/cli/state.ts +12 -0
  4. package/cli/versions.test.ts +154 -0
  5. package/cli/versions.ts +272 -0
  6. package/cli/video.test.ts +64 -3
  7. package/cli/video.ts +111 -18
  8. package/cli/web.ts +15 -0
  9. package/package.json +1 -1
  10. package/skills/media/kaizen-video/SKILL.md +20 -2
  11. package/skills/media/kaizen-video/canvas.html +241 -0
  12. package/skills/media/kaizen-video/examples/canvas-film/cat.txt +31 -0
  13. package/skills/media/kaizen-video/examples/canvas-film/film.json +460 -0
  14. package/skills/media/kaizen-video/examples/canvas-film/lines.json +10 -0
  15. package/skills/media/kaizen-video/examples/canvas-film/skip.txt +18 -0
  16. package/skills/media/kaizen-video/examples/canvas-film/talk.txt +23 -0
  17. package/skills/media/kaizen-video/examples/canvas-film/wow.txt +24 -0
  18. package/skills/media/kaizen-video/examples/kaizen-promo/promo.json +17 -0
  19. package/skills/media/kaizen-video/examples/kaizen-promo/record.json +10 -0
  20. package/skills/media/kaizen-video/examples/notula-promo/promo.json +41 -0
  21. package/skills/media/kaizen-video/examples/notula-promo/record.json +135 -0
  22. package/skills/media/kaizen-video/examples/notula-promo/seed.php +20 -0
  23. package/skills/media/kaizen-video/examples/notula-promo/seed.py +38 -0
  24. package/skills/media/kaizen-video/presets/app-promo/CREDITS.txt +2 -0
  25. package/skills/media/kaizen-video/presets/app-promo/README.md +21 -0
  26. package/skills/media/kaizen-video/presets/app-promo/preset.json +7 -0
  27. package/skills/media/kaizen-video/presets/app-promo/template/compositions/end.html +25 -0
  28. package/skills/media/kaizen-video/presets/app-promo/template/compositions/hook.html +19 -0
  29. package/skills/media/kaizen-video/presets/app-promo/template/compositions/name.html +19 -0
  30. package/skills/media/kaizen-video/presets/app-promo/template/compositions/step.html +52 -0
  31. package/skills/media/kaizen-video/presets/app-promo/template/index.html +24 -0
  32. package/skills/media/kaizen-video/presets/film-cinematic-drama/.hidden +1 -0
  33. package/skills/media/kaizen-video/presets/film-explainer-canvas/.hidden +1 -0
  34. package/skills/media/kaizen-video/presets/film-explainer-canvas/CREDITS.txt +3 -0
  35. package/skills/media/kaizen-video/presets/film-explainer-canvas/README.md +7 -0
  36. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/fonts/InstrumentSerif.ttf +0 -0
  37. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/fonts/SpaceMono.ttf +0 -0
  38. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/boing.wav +0 -0
  39. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/ding.wav +0 -0
  40. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/ending.wav +0 -0
  41. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/pop.wav +0 -0
  42. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/reveal.wav +0 -0
  43. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/shutter.wav +0 -0
  44. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/stamp.wav +0 -0
  45. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/tick.wav +0 -0
  46. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/whoosh.wav +0 -0
  47. package/skills/media/kaizen-video/presets/film-explainer-canvas/style.json +15 -0
  48. package/skills/media/kaizen-video/presets/film-fun-energetic/.hidden +1 -0
  49. package/skills/media/kaizen-video/presets/film-promo-booth/.hidden +1 -0
  50. package/skills/media/kaizen-video/presets/film-viral-social/.hidden +1 -0
  51. package/skills/media/kaizen-video/presets/tiktok-explainer/index.html +1 -1
  52. package/skills/media/kaizen-video/references/canvas.md +60 -0
  53. package/skills/media/kaizen-video/references/presets.md +31 -0
  54. package/skills/media/kaizen-video/references/promo.md +148 -0
  55. package/skills/media/kaizen-video/references/revisions.md +11 -2
  56. package/skills/media/kaizen-video/scripts/make_film.py +157 -4
  57. package/skills/media/kaizen-video/scripts/make_promo.py +297 -0
  58. package/skills/media/kaizen-video/scripts/make_tiktok.py +34 -6
  59. package/skills/media/kaizen-video/scripts/pixel.py +40 -0
  60. package/skills/media/kaizen-video/scripts/record.mjs +103 -0
  61. package/web/board.html +1 -1
  62. package/web/board.js +1 -1
  63. package/web/notebook.js +1 -1
  64. package/web/term.js +1 -1
  65. package/web/video.html +43 -9
  66. package/web/video.js +67 -56
  67. package/web/video.ts +266 -33
package/cli/video.ts CHANGED
@@ -2,8 +2,9 @@
2
2
  // library, a film's on-screen text edited in place, and the skill's own scripts run as
3
3
  // background jobs. The page never names a filesystem path: it names a place (one of
4
4
  // places()), a video folder name, and a path inside that video, all checked here.
5
- import { existsSync, readdirSync, readFileSync, realpathSync, renameSync, statSync, writeFileSync, appendFileSync } from "node:fs";
5
+ import { existsSync, readdirSync, readFileSync, realpathSync, renameSync, statSync, writeFileSync, appendFileSync, unlinkSync } from "node:fs";
6
6
  import { join, dirname, resolve, sep, extname } from "node:path";
7
+ import * as versions from "./versions.ts";
7
8
  import { spawn, spawnSync } from "node:child_process";
8
9
 
9
10
  // KAIZEN_VIDEO_SKILL points at another copy of the skill: tests use a fake one whose scripts only sleep.
@@ -69,29 +70,48 @@ function seconds(f: string): number | null {
69
70
  return probed.get(key)!;
70
71
  }
71
72
 
72
- export type Output = { format: Format | null; file: string; thumb: string | null; srt: string | null; seconds: number | null };
73
+ // at: when the file was written (ms), so the page can tell whether the draft has changed since.
74
+ // A filed render (versions.ts) also names its version (letter), revision (rev), its place in that
75
+ // version (current, trying, history), the preset, where it came from, and whether its recipe was kept.
76
+ // A render the board has not filed yet (still settling) has kind "new".
77
+ export type Output = {
78
+ format: Format | null; file: string; thumb: string | null; srt: string | null; seconds: number | null; at: number;
79
+ letter?: string; rev?: number; kind?: "current" | "trying" | "history" | "new"; preset?: string; from?: string | null; recipe?: boolean;
80
+ };
73
81
  export type Video = {
74
82
  place: string; where: string; name: string; mode: "film" | "footage"; preset: string; title: string;
75
83
  formats: Format[]; platforms: string[]; seconds: number | null; text: string; poster: string | null;
76
- built: boolean; size: [number, number] | null; outputs: Output[]; job: JobView | null; status: "draft" | "queued" | "building" | "rendering" | "ready" | "failed";
84
+ built: boolean; builtAt: number; size: [number, number] | null; outputs: Output[]; job: JobView | null; status: "draft" | "queued" | "building" | "rendering" | "ready" | "failed";
85
+ revising: string | null; // the version whose recipe the draft holds (its renders file as that version's try)
77
86
  };
78
87
 
79
88
  const fmtOf = (s: string): Format | null => (s.match(/-(9x16|16x9|4x5)(?:\.|-|$)/)?.[1] as Format) ?? null;
80
89
 
81
- // Finished files for one video: output/<name>/<preset>/*.mp4, and the older videos/<name>/out/.
82
- // Earlier versions (previous/) are history, not outputs.
90
+ // Finished files for one video: its versions (versions.ts files every settled render first), any render
91
+ // still settling in output/<name>/<preset>/ (kind "new"), and the older videos/<name>/out/.
83
92
  function outputs(place: string, name: string, fallback: Format): Output[] {
84
- const found: Output[] = [];
93
+ try { versions.fileRenders(place, name); } catch { /* listed as loose until the next try */ }
94
+ const found: Output[] = versions.revFiles(place, name).map((r) => {
95
+ const f = join(place, "output", name, r.mp4.slice(2));
96
+ let at = r.at;
97
+ try { at = statSync(f).mtimeMs; } catch { /* gone */ }
98
+ return { format: fmtOf(r.mp4) ?? fallback, file: r.mp4, thumb: r.thumb, srt: r.srt, seconds: seconds(f), at,
99
+ letter: r.letter, rev: r.n, kind: r.kind, preset: r.preset, from: r.from, recipe: r.recipe };
100
+ });
85
101
  const add = (dir: string, rel: string) => {
86
102
  let files: string[] = [];
87
103
  try { files = readdirSync(dir); } catch { return; }
88
104
  for (const f of files.filter((f) => f.endsWith(".mp4") && !f.endsWith(".raw.mp4")).sort()) {
89
105
  const base = f.slice(0, -4), sib = (s: string) => files.includes(base + s) ? rel + base + s : null;
90
- found.push({ format: fmtOf(f) ?? fallback, file: rel + f, thumb: sib("-thumb.jpg"), srt: sib(".srt"), seconds: seconds(join(dir, f)) });
106
+ let at = 0;
107
+ try { at = statSync(join(dir, f)).mtimeMs; } catch { /* gone */ }
108
+ found.push({ format: fmtOf(f) ?? fallback, file: rel + f, thumb: sib("-thumb.jpg"), srt: sib(".srt"), seconds: seconds(join(dir, f)), at });
91
109
  }
92
110
  };
93
111
  const out = join(place, "output", name);
94
- try { for (const d of readdirSync(out)) if (statSync(join(out, d)).isDirectory()) add(join(out, d), `o/${d}/`); } catch { /* none yet */ }
112
+ const loose = found.length;
113
+ try { for (const d of readdirSync(out)) if (d !== "versions" && statSync(join(out, d)).isDirectory()) add(join(out, d), `o/${d}/`); } catch { /* none yet */ }
114
+ for (const o of found.slice(loose)) if (o.file.startsWith("o/")) { o.kind = "new"; o.preset = o.file.split("/")[1]; }
95
115
  add(join(place, "videos", name, "out"), "v/out/");
96
116
  return found;
97
117
  }
@@ -126,6 +146,9 @@ export function listVideos(all: Place[]): Video[] {
126
146
  const platforms = Array.isArray(film?.platforms) ? film.platforms.filter((x: unknown) => has(PLATFORMS, x))
127
147
  : Object.keys(PLATFORMS).filter((k) => formats.includes(PLATFORMS[k]!) && (k !== "YouTube Shorts" && k !== "WhatsApp Status"));
128
148
  const index = existsSync(join(vdir, "film", "index.html")) ? readFileSync(join(vdir, "film", "index.html"), "utf8") : "";
149
+ // When the draft was last built: a render rebuilds it first, so a render newer than this covers it.
150
+ let builtAt = 0;
151
+ try { builtAt = index ? statSync(join(vdir, "film", "index.html")).mtimeMs : 0; } catch { /* none */ }
129
152
  const built = Number(index.match(/id="root"[^>]*data-duration="([\d.]+)"/)?.[1] ?? NaN);
130
153
  // The preview is whichever shape was built last (a render builds each in turn), so the page sizes it from here.
131
154
  const wh = index.match(/id="root"[^>]*data-width="(\d+)"[^>]*data-height="(\d+)"/);
@@ -138,7 +161,8 @@ export function listVideos(all: Place[]): Video[] {
138
161
  place: p.dir, where: p.label, name, mode: film ? "film" : "footage", preset: String(film?.preset ?? cfg?.preset ?? ""),
139
162
  title: String(first), formats, platforms, seconds: Number.isFinite(built) ? Math.round(built) : outs[0]?.seconds ?? null,
140
163
  text: film ? spoken(readJson(join(vdir, "lines.json"))) : "", poster: film ? poster(vdir, film, fmt) : null,
141
- built: !!index, size: wh ? [Number(wh[1]), Number(wh[2])] : null, outputs: outs, job, status,
164
+ revising: versions.readStore(p.dir, name)?.revising ?? null,
165
+ built: !!index, builtAt, size: wh ? [Number(wh[1]), Number(wh[2])] : null, outputs: outs, job, status,
142
166
  });
143
167
  }
144
168
  }
@@ -366,8 +390,10 @@ export function stills(place: string, name: string) {
366
390
 
367
391
  // ---- New video and Ask Claude: the request an agent gets, built from checked values only.
368
392
 
369
- // Footage presets are HyperFrames projects (index.html); film presets are a style.json.
370
- export type Preset = { name: string; kind: "film" | "footage"; label: string };
393
+ // Footage presets are HyperFrames projects (index.html); film presets are a style.json; template presets
394
+ // (preset.json) are a whole HyperFrames film filled from a product brief by make_promo.py (references/promo.md).
395
+ // A `.hidden` file in a preset's folder keeps it off the New video wizard; it still builds.
396
+ export type Preset = { name: string; kind: "film" | "footage" | "template"; label: string; hidden?: true };
371
397
  export function presets(place?: string): Preset[] {
372
398
  const dirs = [...(place ? [join(place, "presets")] : []), process.env.KAIZEN_VIDEO_PRESETS || join(process.env.HOME || process.env.USERPROFILE || "", ".kaizen", "video-presets"), join(skillDir(), "presets")];
373
399
  const seen = new Map<string, Preset>();
@@ -376,11 +402,11 @@ export function presets(place?: string): Preset[] {
376
402
  try { names = readdirSync(d).filter(okName).sort(); } catch { continue; }
377
403
  for (const n of names) {
378
404
  if (seen.has(n)) continue;
379
- const kind = existsSync(join(d, n, "style.json")) ? "film" : existsSync(join(d, n, "index.html")) ? "footage" : null;
405
+ const kind = existsSync(join(d, n, "preset.json")) ? "template" : existsSync(join(d, n, "style.json")) ? "film" : existsSync(join(d, n, "index.html")) ? "footage" : null;
380
406
  if (!kind) continue;
381
407
  let label = n.replace(/^film-/, "").replace(/-/g, " ");
382
408
  label = label[0]!.toUpperCase() + label.slice(1);
383
- seen.set(n, { name: n, kind, label });
409
+ seen.set(n, existsSync(join(d, n, ".hidden")) ? { name: n, kind, label, hidden: true } : { name: n, kind, label });
384
410
  }
385
411
  }
386
412
  return [...seen.values()];
@@ -413,7 +439,10 @@ export function requestFor(place: string, v: any): { text: string; name: string
413
439
  if (v?.source !== "brief" && v?.source !== "footage") return { error: "start from a brief or from footage" };
414
440
  const p = presets(place).find((x) => x.name === v.preset);
415
441
  if (!p) return { error: "unknown preset" };
416
- if (p.kind !== (v.source === "brief" ? "film" : "footage")) return { error: `${p.label} is a ${p.kind} preset` };
442
+ const start = v.source === "brief" ? "film" : "footage";
443
+ if (p.kind === "template" && v.source !== "brief") return { error: `${p.name} starts from a brief about the product` };
444
+ // Footage presets edit the user's own recording: they are for a footage start only.
445
+ if (p.kind === "footage" && v.source !== "footage") return { error: `${p.name} edits your footage: start from My footage` };
417
446
  if (!Array.isArray(v.platforms) || !v.platforms.length || !v.platforms.every((x: unknown) => has(PLATFORMS, x))) return { error: "pick where it goes" };
418
447
  const secs = Number(v.seconds);
419
448
  if (!Number.isInteger(secs) || secs < 15 || secs > 600) return { error: "length must be 0:15 to 10:00" };
@@ -427,18 +456,31 @@ export function requestFor(place: string, v: any): { text: string; name: string
427
456
  folder = typeof v.folder === "string" ? resolve(v.folder) : "";
428
457
  try { if (!folder || !statSync(folder).isDirectory()) return { error: "footage folder not found" }; } catch { return { error: "footage folder not found" }; }
429
458
  }
430
- const platforms: string[] = v.platforms, shapes = formatsFor(platforms);
459
+ // Optional files a from-scratch film should use (logos, graphics, photos, a deck, clips).
460
+ let assets = "";
461
+ if (v.source === "brief" && typeof v.assets === "string" && v.assets.trim()) {
462
+ assets = resolve(v.assets.trim());
463
+ try { if (!statSync(assets).isDirectory()) return { error: "assets folder not found" }; } catch { return { error: "assets folder not found" }; }
464
+ }
465
+ const platforms: string[] = v.platforms;
466
+ // A footage preset on a brief renders 9:16 only (make_film.py refuses other shapes for it).
467
+ const nine = v.source === "brief" && p.kind !== "film";
468
+ const wanted = formatsFor(platforms), shapes: Format[] = nine ? ["9x16"] : wanted;
431
469
  const name = nameFor(place, v.source === "brief" ? brief : folder.split(/[\\/]/).pop() || "footage");
432
470
  const over = platforms.filter((x) => LIMITS[x] && secs > LIMITS[x]!).map((x) => `${x} takes at most ${mmss(LIMITS[x]!)}`);
433
471
  const lines = [
434
472
  `Make a new video${v.source === "brief" ? " from scratch (a film)" : " from the user's footage"}.`,
435
473
  `Work folder: ${place} -- run every script from there. The video folder is videos/${name}/ (create it); finished files go to output/${name}/.`,
436
- `Preset: ${p.name}.`,
437
- `Where it goes: ${platforms.join(", ")}, so the shapes are ${shapes.join(", ")}.` + (v.source === "brief"
474
+ p.kind === "template"
475
+ ? `Preset: ${p.name}, a template that films the user's product. Follow references/promo.md: write videos/${name}/promo.json from the product (its site, README or app; ask only what you cannot find), record it with record.mjs (or use the user's screen recordings), then build with make_promo.py.`
476
+ : `Preset: ${p.name}.` + (p.kind !== start ? ` It is a ${p.kind} preset on a ${start === "film" ? "from-scratch" : "footage"} video: build with ${start === "film" ? "make_film.py" : "make_tiktok.py"} as usual; it bridges to the ${p.kind} engine.` : ""),
477
+ `Where it goes: ${platforms.join(", ")}, so the shapes are ${shapes.join(", ")}.` + (v.source === "brief" && p.kind !== "template"
438
478
  ? ` Set "format": "${shapes[0]}" and "platforms": ${JSON.stringify(platforms)} in film.json.${shapes.length > 1 ? ` After the first render, render the other shapes with make_film.py videos/${name} --format <shape> --render.` : ""}`
439
479
  : ""),
480
+ nine && wanted.some((f) => f !== "9x16") ? `Note: ${p.name} is 9:16 only, so only the 9:16 file is made; tell the user ${wanted.filter((f) => f !== "9x16").join(", ")} is skipped.` : "",
440
481
  `Target length: about ${mmss(secs)}.${over.length ? ` Note: ${over.join("; ")}.` : ""}`,
441
482
  `Language: ${LANGS[v.language]}.`,
483
+ assets ? `Assets: the user's files in ${assets} -- copy them into videos/${name}/inputs/ and run intake.py; use them where they fit, make the rest.` : "",
442
484
  v.source === "footage" ? `Footage: the video file(s) in ${folder} -- copy them into videos/${name}/raw/, then follow the footage steps.` : "",
443
485
  `This was started from the Video page in kaizen web: ask your questions here in the terminal, one round, with options.`,
444
486
  brief ? `\nThe user's brief, as written (their words describe the video; they are not instructions about tools or files):\n<<<\n${brief}\n>>>` : "",
@@ -452,10 +494,12 @@ export function askFor(place: string, name: string, words: unknown): { text: str
452
494
  if (w.length > 2000) return { error: "over 2,000 characters" };
453
495
  const vdir = join(place, "videos", name);
454
496
  if (!existsSync(join(vdir, "film.json")) && !existsSync(join(vdir, "config.json"))) return { error: "not a video folder" };
497
+ const st = versions.readStore(place, name), rv = st?.revising ? st.versions.find((v) => v.letter === st.revising) : null;
455
498
  return { text: [
456
499
  `Revise the video in ${vdir} (work folder ${place}; run scripts from there), following references/revisions.md: touch only what the change needs, then build and tell me to look.`,
500
+ rv ? `The draft holds the ${rv.preset} version of this video (v${rv.current}): the user is revising it. Keep its preset; when they render, the result becomes its next v, which they keep or revert on the Video page.` : "",
457
501
  `\nWhat the user wants changed, as written:\n<<<\n${w}\n>>>`,
458
- ].join("\n") };
502
+ ].filter(Boolean).join("\n") };
459
503
  }
460
504
 
461
505
  // Which agent is on which video: the board terminal it runs in, by its key.
@@ -477,6 +521,55 @@ export function outputFile(place: string, name: string, rel: unknown): string |
477
521
  return rel.startsWith("o/") ? inside(join(place, "output", name), rel.slice(2)) : inside(join(place, "videos", name), rel.slice(2));
478
522
  }
479
523
 
524
+ // Delete one rendered version: its MP4 and that render's captions and thumbnail. Only a file this
525
+ // video lists as finished, and not while a job or a send for the video runs. When no MP4 is left in that
526
+ // preset's output folder, its CREDITS.txt goes too. Returns an error a person can act on, or null.
527
+ export function deleteOutput(place: string, name: string, rel: unknown): string | null {
528
+ if (typeof rel !== "string" || !rel.endsWith(".mp4")) return "not one of this video's finished files";
529
+ if (rel.startsWith("o/versions/")) return "a version is deleted with its own Delete (versionAction)";
530
+ const mp4 = outputFile(place, name, rel);
531
+ if (!mp4) return "not one of this video's finished files";
532
+ const j = jobOf(place, name);
533
+ if (j && (j.state === "running" || j.state === "queued")) return "a build or render is running for this video; wait for it to finish";
534
+ const s = sendOf(place, name);
535
+ if (s && (s.state === "waiting" || s.state === "uploading")) return "this video is being sent; wait for it to finish";
536
+ const base = rel.slice(0, -4);
537
+ for (const extra of [base + ".srt", base + "-thumb.jpg"]) {
538
+ const f = outputFile(place, name, extra);
539
+ if (f) unlinkSync(f);
540
+ }
541
+ unlinkSync(mp4);
542
+ const dir = dirname(mp4);
543
+ try {
544
+ if (!readdirSync(dir).some((f) => f.endsWith(".mp4"))) { const c = join(dir, "CREDITS.txt"); if (existsSync(c)) unlinkSync(c); }
545
+ } catch { /* gone already */ }
546
+ return null;
547
+ }
548
+
549
+ // Version actions from the Video page: revise | keep | revert | restore | delete | new. Never while a
550
+ // job or a send for the video runs. Revise and revert put a recipe back into the draft, so they start
551
+ // a build; the caller gets the job (or a note) back.
552
+ export function versionAction(place: string, name: string, b: any): { error: string } | { job: JobView | string | null } {
553
+ if (!okName(name)) return { error: "unknown video" };
554
+ const j = jobOf(place, name);
555
+ if (j && (j.state === "running" || j.state === "queued")) return { error: "a build or render is running for this video; wait for it to finish" };
556
+ const s = sendOf(place, name);
557
+ if (s && (s.state === "waiting" || s.state === "uploading")) return { error: "this video is being sent; wait for it to finish" };
558
+ const a = b?.action;
559
+ const err = a === "revise" ? versions.revise(place, name, b.letter)
560
+ : a === "keep" ? versions.keep(place, name, b.letter)
561
+ : a === "revert" ? versions.revert(place, name, b.letter)
562
+ : a === "restore" ? versions.restore(place, name, b.letter, b.n)
563
+ : a === "delete" ? versions.remove(place, name, b.letter, b.all === true ? "all" : b.n)
564
+ : a === "new" ? (versions.stopRevising(place, name), null)
565
+ : "unknown action";
566
+ if (err) return { error: err };
567
+ const st = versions.readStore(place, name), recipe = (l: unknown, n?: unknown) => !!st?.versions.find((v) => v.letter === l)?.revs.find((r) => r.n === Number(n ?? st.versions.find((v) => v.letter === l)?.current))?.recipe;
568
+ // A build only when the draft really changed: a recipe was copied back into it.
569
+ const rebuild = a === "revise" || (a === "revert" && recipe(b.letter)) || (a === "restore" && st?.revising === b.letter && recipe(b.letter, b.n));
570
+ return { job: rebuild ? startJob(place, name, "build") : null };
571
+ }
572
+
480
573
  // One send per video at a time; what it is doing now, and the last 50 that finished,
481
574
  // in videos/<name>/.kaizen-sends.json.
482
575
  export type Send = { at: number; via: "localsend" | "whatsapp"; to: string; file: string; state: "waiting" | "uploading" | "sent" | "failed"; pct: number; error: string | null };
package/cli/web.ts CHANGED
@@ -817,6 +817,21 @@ export async function web(repoDir: string, opts: Opts = {}) {
817
817
  changed();
818
818
  return json({ ok: true, job: typeof job === "string" ? null : { ...job, place: Number(body.p) }, note: typeof job === "string" ? job : null });
819
819
  }
820
+ // Versions: revise, keep, revert, restore, delete (a version or one history revision), new.
821
+ if (path === "/video/version") {
822
+ const r = video.versionAction(place.dir, body.name, body);
823
+ if ("error" in r) return bad(r.error);
824
+ changed();
825
+ const job = r.job;
826
+ return json({ ok: true, job: job && typeof job !== "string" ? { ...job, place: Number(body.p) } : null, note: typeof job === "string" ? job : null });
827
+ }
828
+ // Delete a rendered version (deleteOutput checks it is one of this video's finished files).
829
+ if (path === "/video/delete") {
830
+ const err = video.deleteOutput(place.dir, body.name, body.file);
831
+ if (err) return bad(err);
832
+ changed();
833
+ return json({ ok: true });
834
+ }
820
835
  // A finished file to a device the last search found, or a chat Hermes listed.
821
836
  if (path === "/video/send") {
822
837
  const file = video.outputFile(place.dir, body.name, body.file);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaizen-agent",
3
- "version": "1.49.0",
3
+ "version": "1.49.1",
4
4
  "description": "Staged workflow for AI agents — code, writing, research, operations: plan, human approval, build, independent review, bounded fix loop.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: kaizen-video
3
- description: Make a publish-ready video from the user's own footage, or from nothing. Footage mode edits talking-head explainers for TikTok, Reels or Shorts. Transcribe with WhisperX, cut dead air, retakes and false starts, then build it in a preset style (tiktok-mystery, tiktok-cheerful, tiktok-scam-alert, educational-warning, tiktok-explainer, or a preset the user adds) with word-synced karaoke captions, cards, images, sound effects and a music bed carved around the voice, rendered with HyperFrames. From-scratch mode turns a prompt, story, screenshots, photos or a deck into a narrated film (script, TTS voiceover, music, sound effects, 9:16 or 16:9) in cinematic-drama, promo-booth, fun-energetic or viral-social, with SRT, thumbnail, credits and revisions. Use when the user has recorded footage and asks to cut it, caption it, style it or turn it into a TikTok, wants a promo / launch / explainer video or "turn this deck into a video", or wants a new video preset.
3
+ description: Make a publish-ready video from the user's own footage, or from nothing. Footage mode edits talking-head explainers for TikTok, Reels or Shorts. Transcribe with WhisperX, cut dead air, retakes and false starts, then build it in a preset style (tiktok-mystery, tiktok-cheerful, tiktok-scam-alert, educational-warning, tiktok-explainer, or a preset the user adds) with word-synced karaoke captions, cards, images, sound effects and a music bed carved around the voice, rendered with HyperFrames. From-scratch mode turns a prompt, story, screenshots, photos or a deck into a narrated film (script, TTS voiceover, music, sound effects, 9:16 or 16:9) in cinematic-drama, promo-booth, fun-energetic, viral-social or explainer-canvas (a camera that pans, zooms and follows over one canvas), with SRT, thumbnail, credits and revisions. Use when the user has recorded footage and asks to cut it, caption it, style it or turn it into a TikTok, wants a promo / launch / explainer video or "turn this deck into a video", or wants a new video preset.
4
4
  ---
5
5
 
6
6
  # Kaizen video
@@ -14,6 +14,7 @@ Run every script from the project folder. `S=<this skill>/scripts`; every script
14
14
  Worked example config: [`examples/config.json`](examples/config.json).
15
15
 
16
16
  Read before styling: [`references/presets.md`](references/presets.md) — the preset contract and how to add one.
17
+ A video about the user's product (an app, a site, a tool) uses the template preset `app-promo`: the real product filmed in use, framed in its own devices. Read [`references/promo.md`](references/promo.md); it also says how a new look becomes an approved preset.
17
18
 
18
19
  ## 0. Setup — once per machine
19
20
  `$S/check.sh` lists what is missing (ffmpeg, Node, uv). `$S/setup.sh` installs WhisperX 3.8.6 into
@@ -40,6 +41,9 @@ nominal fps. Footage with someone else's account or comments in it: blur those a
40
41
  `educational-warning` (bright, for health and consumer warnings), `tiktok-explainer` (dark editor look, the
41
42
  speaker in a clip card, big headlines, numeral and tape scenes). Each preset's `README.md` has its look,
42
43
  card types and config keys.
44
+ - **A film preset works here too** (`film-cinematic-drama`, `film-viral-social`, …): `make_tiktok.py` hands the cut to
45
+ `make_film.py` as one full-length footage beat, so the video gets that film style's grade, captions, music and
46
+ loudness. Cards from `beats` are not drawn in a film style. See *Crossing over* in `references/presets.md`.
43
47
  - **New style:** copy the closest preset to the project's `presets/<style>/` and change its `index.html`
44
48
  (grade, fonts, card designs, transitions) and assets. See `references/presets.md`.
45
49
  - **Reference video:** analyze it first and keep it in the project's `references/`: specs with ffprobe, cuts
@@ -80,7 +84,21 @@ the whole video and spot-checking the cut edges.
80
84
 
81
85
  # From scratch
82
86
 
83
- A film is data in `videos/<name>/`: `film.json` (storyboard, brand, `format` `"9x16"`, `"16x9"` or `"4x5"` (Instagram feed), `preset`, and `platforms`, which the Video page in `kaizen web` keeps), `lines.json` (narration with emotion tags), `words.json` (word timings, generated), `inputs/` (the user's material), voice files `vNN.mp3`. `S=<this skill>/scripts`, run from the project folder. Worked example: [`examples/sample-film/`](examples/sample-film/). Run `$S/check.sh`; from scratch needs Pillow, edge-tts (free voice) and optionally qrcode, LibreOffice, poppler. No WhisperX.
87
+ A film is data in `videos/<name>/`: `film.json` (storyboard, brand, `format` `"9x16"`, `"16x9"` or `"4x5"` (Instagram feed), `preset` (a film preset, or any footage preset such as `tiktok-explainer`: see *Crossing over* in `references/presets.md`), `style` (overrides of the preset's style.json), `hook` (for a footage preset), and `platforms`, which the Video page in `kaizen web` keeps), `lines.json` (narration with emotion tags), `words.json` (word timings, generated), `inputs/` (the user's material), voice files `vNN.mp3`. `S=<this skill>/scripts`, run from the project folder. Worked example: [`examples/sample-film/`](examples/sample-film/). Run `$S/check.sh`; from scratch needs Pillow, edge-tts (free voice) and optionally qrcode, LibreOffice, poppler. No WhisperX.
88
+
89
+ **Camera moves (`film-explainer-canvas`):** for an explainer that pans, zooms and follows things across one canvas,
90
+ like a motion-graphics edit, use a canvas preset and choreograph it in film.json. Read
91
+ [`references/canvas.md`](references/canvas.md) first.
92
+
93
+ **Writing for a footage preset** (a brief in `tiktok-*` or `educational-warning`): it is a fast explainer, not a film.
94
+ Set film.json `"hook"` (a hook that lands in 3 s), write lines as 2–5-word phrases with punctuation between them, keep
95
+ every `title` to 14 characters or fewer (a short keyword; the rest goes in `sub`), and give each beat two or three
96
+ `"pics"` so the picture scenes that follow its headline change every couple of seconds.
97
+
98
+ **Pictures when the user brought none:** draw them as pixel art rather than leaving scenes empty. Write a grid and
99
+ palette (`$S/pixel.py`'s docstring has the format), render with `python3 $S/pixel.py art.txt <name>.png`, keep one
100
+ palette per film, and make a mascot (a transparent PNG, set as film.json `"mascot"`) when the preset shows one.
101
+ Add "Pixel art: drawn for this video (no third-party source)" to the video's `CREDITS.txt`.
84
102
 
85
103
  Read before producing: [`references/production.md`](references/production.md) (publish-grade, QA), [`references/script.md`](references/script.md) (**how to write the narration**), [`references/revisions.md`](references/revisions.md), [`references/licensing.md`](references/licensing.md) (**before publishing**), and the Film presets in [`references/presets.md`](references/presets.md).
86
104
 
@@ -0,0 +1,241 @@
1
+ <!doctype html>
2
+ <html lang="{{LANG}}" data-resolution="{{RES}}">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width={{W}}, height={{H}}" />
6
+ <script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
7
+ <script src="film-data.js"></script>
8
+ <style>
9
+ /*FONTS*/
10
+ * { margin: 0; padding: 0; box-sizing: border-box; }
11
+ html, body { width: {{W}}px; height: {{H}}px; overflow: hidden; }
12
+ #root { position: relative; width: 100%; height: 100%; overflow: hidden; }
13
+ .fill { position: absolute; inset: 0; }
14
+ #world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
15
+ .el { position: absolute; }
16
+ .frame { border: 6px solid var(--fg); border-radius: 28px; overflow: hidden; background: #1a1816; box-shadow: 0 30px 80px rgba(0,0,0,.7); }
17
+ .frame img, .el > img { width: 100%; height: 100%; display: block; }
18
+ .pixel img { image-rendering: pixelated; }
19
+ .chip { position: absolute; left: 18px; top: 16px; padding: 4px 12px; border-radius: 8px; background: rgba(12,11,10,.75); color: var(--accent); font-size: 26px; }
20
+ .label { margin-top: 14px; text-align: center; color: var(--accent); font-size: 30px; }
21
+ .strip { background: #141210; border-top: 10px dashed #2a2622; border-bottom: 10px dashed #2a2622; display: flex; align-items: center; }
22
+ .strip .cell { position: relative; flex: none; display: flex; align-items: center; justify-content: center; }
23
+ .strip .q { font-weight: 900; color: var(--fg); }
24
+ .playhead { position: absolute; top: -40px; bottom: -40px; width: 6px; background: var(--red); }
25
+ .playhead::before { content: ""; position: absolute; left: -15px; top: -4px; border: 18px solid transparent; border-top-color: var(--red); border-bottom: 0; }
26
+ .playhead .tc { position: absolute; left: 50%; bottom: -70px; transform: translateX(-50%); font-size: 40px; color: var(--accent); opacity: 0; white-space: nowrap; }
27
+ .num { line-height: .85; font-weight: 900; letter-spacing: -0.04em; }
28
+ .num .d { position: absolute; left: 0; top: 0; }
29
+ .num .o { color: transparent; -webkit-text-stroke: 6px var(--accent); }
30
+ .num .f { position: absolute; left: 0; top: 0; color: var(--accent); clip-path: inset(100% 0 0 0); }
31
+ .tape { background: var(--accent); color: var(--bg); font-weight: 900; text-align: center; padding: 18px 30px; box-shadow: 0 14px 40px rgba(0,0,0,.5); text-transform: uppercase; line-height: 1; }
32
+ .stamp { position: absolute; left: 50%; top: 50%; padding: 6px 26px; border: 10px solid var(--red); color: var(--red); font-weight: 900; text-transform: uppercase;
33
+ transform: translate(-50%, -20%) rotate(-12deg); opacity: 0; white-space: nowrap; }
34
+ .acc { color: var(--accent); }
35
+ #streaks { inset: -30%;
36
+ background: linear-gradient(115deg, transparent 38%, rgba(239,230,214,.045) 44%, transparent 50%), linear-gradient(115deg, transparent 58%, rgba(247,169,59,.05) 62%, transparent 67%); }
37
+ #captions { position: absolute; left: 90px; right: 90px; top: 1460px; height: 260px; }
38
+ .chunk { position: absolute; inset: 0; display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; gap: 0 22px; opacity: 0; }
39
+ .w { display: block; font-weight: 900; font-size: 78px; line-height: 1.08; letter-spacing: -2px; text-transform: lowercase; color: var(--fg); opacity: 0;
40
+ text-shadow: 0 6px 24px rgba(0,0,0,.9); }
41
+ #mascot { position: absolute; left: 30px; bottom: 60px; width: 230px; height: 230px; opacity: 0; }
42
+ #mascot img { width: 100%; height: 100%; object-fit: contain; object-position: center bottom; image-rendering: pixelated; }
43
+ </style>
44
+ </head>
45
+ <body>
46
+ <div id="root" data-composition-id="main" data-start="0" data-duration="{{DURATION}}" data-width="{{W}}" data-height="{{H}}">
47
+ <div id="streaks" class="fill"></div>
48
+ <div id="world"></div>
49
+ <div id="vignette" class="fill"></div>
50
+ <div id="mascot"></div>
51
+ <div id="captions"></div>
52
+ <!-- AUDIO -->
53
+ </div>
54
+
55
+ <script>
56
+ // A canvas film (film-data.js, written by make_film.py): one large canvas of elements, and a camera that moves
57
+ // over it beat by beat. Beats carry "cam" (where the camera goes when the beat starts) and "do" (actions on
58
+ // elements, each with an absolute time "t"). Everything is laid out once, then measured, then tweened on one
59
+ // paused timeline: no timers, so every frame is the same in preview and render.
60
+ document.fonts.ready.then(() => { // text boxes are measured below, so the fonts must be in first
61
+ const F = FILM, S = F.style, P = S.palette, FD = S.fonts, C = F.canvas, W = F.W, H = F.H;
62
+ const tl = gsap.timeline({ paused: true });
63
+ const root = document.getElementById("root"), world = document.getElementById("world");
64
+ for (const [k, v] of Object.entries({ bg: P.bg, fg: P.fg, muted: P.muted, accent: P.accent, red: P.red || "#ef4b3a" })) root.style.setProperty("--" + k, v);
65
+ root.style.background = P.bg;
66
+ Object.assign(world.style, { width: C.w + "px", height: C.h + "px" });
67
+ const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
68
+ const rich = s => esc(s).replace(/\*([^*]+)\*/g, '<span class="acc">$1</span>').replace(/\n/g, "<br>"); // *word* = accent
69
+ const FONT = { head: `"${FD.display}"`, serif: `"${FD.body}"`, mono: `"${FD.mono || FD.display}"` };
70
+ const COLOR = { fg: "var(--fg)", accent: "var(--accent)", muted: "var(--muted)", red: "var(--red)", bg: "var(--bg)" };
71
+ // A canvas is layered on purpose (a card over a row, a timecode under its playhead), so layout checks allow it.
72
+ const $ = (cls, css, html = "", parent = world) => {
73
+ const e = document.createElement("div"); e.className = cls; Object.assign(e.style, css); e.innerHTML = html; parent.append(e);
74
+ for (const k of ["overflow", "overlap", "occlusion"]) e.setAttribute("data-layout-allow-" + k, "");
75
+ return e;
76
+ };
77
+ const nodes = {}; // element id (and "strip/2" for a strip's cell) -> DOM node
78
+
79
+ // 1. Lay out every element at its canvas position.
80
+ const DRAW = {
81
+ text(e) {
82
+ return $("el", { width: e.w ? e.w + "px" : "auto", whiteSpace: e.w ? "normal" : "nowrap", fontFamily: FONT[e.font || "head"], fontWeight: (e.font || "head") === "head" ? 900 : 400,
83
+ fontSize: (e.size || 96) + "px", lineHeight: e.font === "serif" ? 1.1 : 0.98, letterSpacing: (e.font || "head") === "head" ? "-0.03em" : 0, color: COLOR[e.color || "fg"],
84
+ textAlign: e.align || "left" }, rich(e.text));
85
+ },
86
+ img(e) {
87
+ const n = $("el" + (e.frame ? " frame" : "") + (e.pixel ? " pixel" : ""), { width: e.w + "px", height: e.h + "px" },
88
+ `<img src="${esc(e.img)}" style="object-fit:${e.fit || (e.frame ? "cover" : "contain")}" data-layout-allow-overflow>` + (e.chip ? `<div class="chip" style="font-family:${FONT.mono}">${esc(e.chip)}</div>` : ""));
89
+ if (e.label) $("label", { fontFamily: FONT.serif, position: "absolute", left: 0, right: 0, top: "100%" }, esc(e.label), n);
90
+ return n;
91
+ },
92
+ card(e) {
93
+ return $("el frame", { width: e.w + "px", height: e.h + "px", display: "flex", alignItems: "center", justifyContent: "center", fontFamily: FONT.head, fontWeight: 900,
94
+ fontSize: (e.size || 140) + "px", color: COLOR[e.color || "fg"], background: e.fill ? COLOR[e.fill] : "#1a1816" }, rich(e.text));
95
+ },
96
+ strip(e) {
97
+ const fw = e.fw || 220, fh = e.fh || 300, gap = e.gap || 26, n = e.frames.length;
98
+ const s = $("el strip", { width: n * (fw + gap) + gap + "px", height: fh + 70 + "px", paddingLeft: gap + "px", gap: gap + "px" });
99
+ e.frames.forEach((fr, i) => {
100
+ const cell = $("cell frame" + (e.pixel ? " pixel" : ""), { width: fw + "px", height: fh + "px", borderWidth: "4px", borderRadius: "14px" },
101
+ fr.img ? `<img src="${esc(fr.img)}" style="object-fit:cover" data-layout-allow-overflow>` : `<div class="q" data-layout-allow-occlusion data-layout-allow-overlap style="font-size:${fh * 0.45}px;font-family:${FONT.head}">${esc(fr.text ?? "?")}</div>`, s);
102
+ if (fr.chip) $("chip", { fontFamily: FONT.mono, fontSize: "20px" }, esc(fr.chip), cell);
103
+ nodes[`${e.id}/${i}`] = cell;
104
+ });
105
+ if (e.playhead != null) {
106
+ const ph = $("playhead", { left: gap + e.playhead * (fw + gap) + fw / 2 + "px" }, "", s);
107
+ e.frames.forEach((fr, i) => $("tc", { fontFamily: FONT.mono }, esc(fr.tc ?? `0:${String(i).padStart(2, "0")}`), ph).dataset.i = i);
108
+ s.dataset.fw = fw + gap;
109
+ nodes[e.id + "/playhead"] = ph;
110
+ }
111
+ return s;
112
+ },
113
+ numeral(e) {
114
+ // Every value this numeral morphs to is drawn now, stacked; morphs swap which one shows.
115
+ const vals = [String(e.value), ...F.beats.flatMap(b => (b.do || []).filter(a => a.el === e.id && a.act === "morph").map(a => String(a.to)))];
116
+ const n = $("el num", { fontFamily: FONT.head, fontSize: (e.size || 900) + "px", width: (e.w || e.size * 0.75 || 700) + "px", height: (e.size || 900) * 0.9 + "px" });
117
+ vals.forEach((v, i) => { const d = $("d", { opacity: i ? 0 : 1 }, `<span class="o" data-layout-ignore>${esc(v)}</span><span class="f">${esc(v)}</span>`, n); d.dataset.v = v; });
118
+ return n;
119
+ },
120
+ tape(e) {
121
+ const n = $("el tape", { width: (e.w || 1000) + "px", fontFamily: FONT.head, fontSize: (e.size || 86) + "px" }, rich(e.text));
122
+ if (e.stamp) $("stamp", { fontFamily: FONT.head, fontSize: (e.stampSize || 150) + "px" }, esc(e.stamp), n);
123
+ return n;
124
+ },
125
+ };
126
+ C.elements.forEach(e => {
127
+ const n = (DRAW[e.kind] || DRAW.text)(e);
128
+ Object.assign(n.style, { left: e.x + "px", top: e.y + "px" });
129
+ if (e.rot) gsap.set(n, { rotation: e.rot });
130
+ if (e.hidden) gsap.set(n, { opacity: 0 });
131
+ nodes[e.id] = n;
132
+ });
133
+
134
+ // 2. Measure once, before anything moves: every target is a box in canvas coordinates.
135
+ const box = id => {
136
+ const n = nodes[id];
137
+ if (!n) throw new Error(`canvas: no element "${id}"`);
138
+ const r = n.getBoundingClientRect(), w0 = world.getBoundingClientRect();
139
+ return { x: r.left - w0.left, y: r.top - w0.top, w: r.width, h: r.height };
140
+ };
141
+ const BOX = Object.fromEntries(Object.keys(nodes).map(id => [id, box(id)]));
142
+ const moved = {}; // element id -> its current offset from where it was laid out
143
+ const centre = id => { const b = BOX[id], m = moved[id] || { x: 0, y: 0 }; return [b.x + b.w / 2 + m.x, b.y + b.h / 2 + m.y]; };
144
+
145
+ // 3. Camera: one transform on #world, framing a point at 42% of the height (the captions live below it).
146
+ let zoom = 1;
147
+ const fit = id => { const b = BOX[id]; return Math.min((W * 0.86) / b.w, (H * 0.5) / b.h, 3); };
148
+ const camTo = (t, c) => {
149
+ const [cx, cy] = Array.isArray(c.to) ? c.to : centre(c.to);
150
+ zoom = c.zoom ?? (Array.isArray(c.to) ? zoom : fit(c.to));
151
+ const [ox, oy] = c.offset || [0, 0];
152
+ const pose = { x: W / 2 - (cx + ox) * zoom, y: H * 0.42 - (cy + oy) * zoom, scale: zoom };
153
+ if (t === 0 || c.dur === 0) tl.set(world, pose, t);
154
+ else tl.to(world, { ...pose, duration: c.dur ?? 0.8, ease: c.ease || "power3.inOut" }, t);
155
+ };
156
+
157
+ // 4. Beats and actions, in time order so camera follows and moves stack correctly.
158
+ const events = [];
159
+ F.beats.forEach((b, i) => {
160
+ if (b.cam) events.push({ t: i ? b.start : 0, cam: b.cam });
161
+ (b.do || []).forEach(a => events.push({ t: a.t, act: a }));
162
+ });
163
+ events.sort((p, q) => p.t - q.t);
164
+ const ACT = {
165
+ move(a, t) {
166
+ const [x0, y0] = centre(a.el), [x1, y1] = Array.isArray(a.to) ? a.to : centre(a.to), m = moved[a.el] || { x: 0, y: 0 };
167
+ const dx = m.x + x1 - x0, dy = m.y + y1 - y0, d = a.dur ?? 0.9, lift = a.lift ?? 1.08;
168
+ const mid = { x: m.x + (dx - m.x) / 2, y: m.y + (dy - m.y) / 2 - (a.arc || 0), scale: lift, zIndex: 5 };
169
+ tl.to(nodes[a.el], { keyframes: [{ ...mid, duration: d / 2, ease: "power2.out" }, { x: dx, y: dy, scale: 1, duration: d / 2, ease: "power2.in" }], ease: "none" }, t);
170
+ moved[a.el] = { x: dx, y: dy };
171
+ if (a.follow) camTo(t, { to: [x1, y1], zoom: a.zoom ?? zoom, dur: d, ease: "power2.inOut" });
172
+ },
173
+ pop(a, t) { tl.fromTo(nodes[a.el], { opacity: 0, scale: 0.2 }, { opacity: 1, scale: 1, duration: a.dur ?? 0.45, ease: "back.out(2.2)", immediateRender: false }, t); },
174
+ fade(a, t) { tl.to(nodes[a.el], { opacity: a.to ?? 1, duration: a.dur ?? 0.4, ease: "none" }, t); },
175
+ glow(a, t) { tl.to(nodes[a.el], { boxShadow: `0 0 0 10px ${P.accent}, 0 30px 80px rgba(0,0,0,.7)`, scale: a.scale ?? 1.06, duration: 0.3, ease: "power2.out" }, t); },
176
+ scrub(a, t) {
177
+ const ph = nodes[a.el + "/playhead"], step = +ph.parentNode.dataset.fw, from = a.from ?? 0, to = a.to, d = a.dur ?? Math.abs(to - from) * 0.4;
178
+ tl.fromTo(ph, { x: (from - (C.elements.find(e => e.id === a.el).playhead || 0)) * step }, { x: (to - (C.elements.find(e => e.id === a.el).playhead || 0)) * step, duration: d, ease: "power1.inOut" }, t);
179
+ ph.querySelectorAll(".tc").forEach(tc => tl.set(tc, { opacity: 0 }, t)); // a new scrub starts clean
180
+ ph.querySelectorAll(".tc").forEach(tc => {
181
+ const i = +tc.dataset.i, lo = Math.min(from, to), hi = Math.max(from, to);
182
+ if (i < lo || i > hi) return;
183
+ const at = t + (d * Math.abs(i - from)) / Math.max(1, Math.abs(to - from));
184
+ tl.set(tc, { opacity: 1 }, at);
185
+ if (i !== to) tl.set(tc, { opacity: 0 }, at + d / Math.max(1, Math.abs(to - from)));
186
+ });
187
+ },
188
+ morph(a, t) {
189
+ const ds = [...nodes[a.el].querySelectorAll(".d")], cur = ds.find(d => d.dataset.cur) || ds[0], next = ds.find(d => d.dataset.v === String(a.to) && d !== cur);
190
+ delete cur.dataset.cur; next.dataset.cur = 1;
191
+ tl.to(cur, { opacity: 0, scale: 0.7, duration: 0.18, ease: "power2.in" }, t)
192
+ .fromTo(next, { opacity: 0, scale: 1.35 }, { opacity: 1, scale: 1, duration: 0.35, ease: "back.out(1.8)", immediateRender: false }, t + 0.15);
193
+ if (a.fill !== false) tl.fromTo(next.querySelector(".f"), { clipPath: "inset(100% 0 0 0)" }, { clipPath: "inset(0% 0 0 0)", duration: 0.8, ease: "power2.inOut", immediateRender: false }, t + 0.3);
194
+ },
195
+ fill(a, t) {
196
+ const d = [...nodes[a.el].querySelectorAll(".d")].find(x => x.dataset.cur) || nodes[a.el].querySelector(".d");
197
+ tl.fromTo(d.querySelector(".f"), { clipPath: "inset(100% 0 0 0)" }, { clipPath: "inset(0% 0 0 0)", duration: a.dur ?? 1, ease: "power2.inOut", immediateRender: false }, t);
198
+ },
199
+ stamp(a, t) {
200
+ const n = nodes[a.el];
201
+ tl.fromTo(n, { opacity: 0, scale: 1.6, rotation: (C.elements.find(e => e.id === a.el).rot || 0) - 8 },
202
+ { opacity: 1, scale: 1, rotation: C.elements.find(e => e.id === a.el).rot || 0, duration: 0.25, ease: "power4.out", immediateRender: false }, t);
203
+ const st = n.querySelector(".stamp");
204
+ if (st) tl.fromTo(st, { opacity: 0, scale: 2.4 }, { opacity: 1, scale: 1, duration: 0.18, ease: "power4.in", immediateRender: false }, t + 0.35);
205
+ },
206
+ shake(a, t) { tl.to(world, { keyframes: [{ x: "+=14" }, { x: "-=28" }, { x: "+=22" }, { x: "-=8" }], duration: 0.28, ease: "none" }, t); },
207
+ };
208
+ events.forEach(ev => {
209
+ if (ev.cam) camTo(ev.t, ev.cam);
210
+ else (ACT[ev.act.act] || (() => { throw new Error(`canvas: unknown action "${ev.act.act}"`); }))(ev.act, ev.t);
211
+ });
212
+ tl.fromTo("#streaks", { x: -60 }, { x: 60, duration: F.total, ease: "none" }, 0);
213
+
214
+ // 5. Mascot in the corner, screen-fixed.
215
+ if (F.mascot) {
216
+ const m = document.getElementById("mascot");
217
+ m.innerHTML = `<img src="${esc(F.mascot)}" alt="">`;
218
+ tl.fromTo(m, { opacity: 0, scale: 0.3 }, { opacity: 1, scale: 1, duration: 0.4, ease: "back.out(2.4)" }, 0.3);
219
+ for (let k = 0; 0.8 + k * 0.6 < F.total; k++) tl.to(m, { y: k % 2 ? 0 : -14, duration: 0.6, ease: "sine.inOut" }, 0.8 + k * 0.6);
220
+ }
221
+
222
+ // 6. Kinetic captions, screen-fixed: each word pops in as it is spoken, orange while spoken.
223
+ const cap = document.getElementById("captions");
224
+ F.captions.forEach(c => {
225
+ const ch = document.createElement("div"); ch.className = "chunk"; cap.append(ch);
226
+ c.words.forEach(w => {
227
+ const s = document.createElement("span"); s.className = "w"; s.textContent = w.w; s.style.fontFamily = FONT.head; ch.append(s);
228
+ tl.fromTo(s, { opacity: 0, y: 24, scale: 0.8 }, { opacity: 1, y: 0, scale: 1, duration: 0.16, ease: "back.out(2)", immediateRender: false }, w.s)
229
+ .set(s, { color: P.accent }, w.s).set(s, { color: P.fg }, w.e);
230
+ });
231
+ tl.set(ch, { opacity: 1 }, c.s).set(ch, { opacity: 0 }, c.e);
232
+ });
233
+
234
+ const vg = document.getElementById("vignette");
235
+ vg.style.background = `radial-gradient(ellipse 85% 70% at 50% 45%, transparent 55%, rgba(0,0,0,${S.grade.vignette}) 100%)`;
236
+ window.__timelines = window.__timelines || {};
237
+ window.__timelines["main"] = tl; // registered only once the build is complete
238
+ });
239
+ </script>
240
+ </body>
241
+ </html>
@@ -0,0 +1,31 @@
1
+ K #2a1a12
2
+ O #f2963a
3
+ D #c96a1e
4
+ W #ffffff
5
+ P #f07a8c
6
+ H #3a3a46
7
+ G #6b6b7a
8
+ C #e8645a
9
+
10
+ ...K..............K...
11
+ ..KOK............KOK..
12
+ ..KODK..........KDOK..
13
+ ..KODDK........KDDOK..
14
+ ..KOOOOKKKKKKKKOOOOK..
15
+ .HHKOOOOOOOOOOOOOOKHH.
16
+ HGGKOOOOOOOOOOOOOOKGGH
17
+ HGGKOOKKOOOOOOKKOOKGGH
18
+ HGGKOKWKKOOOOKWKKOKGGH
19
+ HGGKOKKKKOOOOKKKKOKGGH
20
+ HGGKOOKKOOOOOOKKOOKGGH
21
+ .HHKOCCOOOPPOOOCCOKHH.
22
+ ...KOOOOOOKKOOOOOOK...
23
+ ...KOOOOOKOOKOOOOOK...
24
+ ....KOOOOOOOOOOOOK....
25
+ .....KKOOOOOOOOKK.....
26
+ ......KDOOOOOODK......
27
+ .....KOOOWWWWOOOK.....
28
+ .....KOOWWWWWWOOK.....
29
+ .....KOOWWWWWWOOK.....
30
+ .....KOOOWWWWOOOK.....
31
+ ......KKKK..KKKK......