kaizen-agent 1.48.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 (232) hide show
  1. package/README.md +2 -2
  2. package/cli/build-web.ts +4 -2
  3. package/cli/hermes.ts +68 -0
  4. package/cli/install.ts +18 -5
  5. package/cli/localsend.test.ts +84 -0
  6. package/cli/localsend.ts +131 -0
  7. package/cli/notes.test.ts +6 -4
  8. package/cli/settings.ts +1 -0
  9. package/cli/state.test.ts +50 -0
  10. package/cli/state.ts +47 -20
  11. package/cli/versions.test.ts +154 -0
  12. package/cli/versions.ts +272 -0
  13. package/cli/video.test.ts +540 -0
  14. package/cli/video.ts +600 -0
  15. package/cli/web.ts +142 -1
  16. package/package.json +1 -1
  17. package/skills/kaizen/config.default.yml +4 -0
  18. package/skills/media/kaizen-book/SKILL.md +107 -0
  19. package/skills/media/kaizen-book/assets/reader.html +440 -0
  20. package/skills/media/kaizen-book/assets/styles.json +45 -0
  21. package/skills/media/kaizen-book/examples/book.json +14 -0
  22. package/skills/media/kaizen-book/examples/images/reach.svg +1 -0
  23. package/skills/media/kaizen-book/examples/manuscript.md +127 -0
  24. package/skills/media/kaizen-book/references/interview.md +85 -0
  25. package/skills/media/kaizen-book/references/proofread.md +47 -0
  26. package/skills/media/kaizen-book/references/writing.md +53 -0
  27. package/skills/media/kaizen-book/scripts/build_book.py +279 -0
  28. package/skills/media/kaizen-book/scripts/check.sh +10 -0
  29. package/skills/media/kaizen-book/scripts/check_book.py +128 -0
  30. package/skills/media/kaizen-book/scripts/deploy.py +58 -0
  31. package/skills/media/kaizen-book/scripts/pdf.mjs +99 -0
  32. package/skills/media/kaizen-book/scripts/setup.sh +9 -0
  33. package/skills/media/kaizen-book/scripts/verify.mjs +95 -0
  34. package/skills/{story-deck → media/kaizen-deck}/SKILL.md +1 -1
  35. package/skills/{story-deck → media/kaizen-deck}/scripts/check.sh +1 -1
  36. package/skills/{story-deck → media/kaizen-deck}/scripts/install_fonts.py +2 -2
  37. package/skills/media/kaizen-video/SKILL.md +130 -0
  38. package/skills/{kaizen-video → media/kaizen-video}/assets/CREDITS.txt +5 -0
  39. package/skills/media/kaizen-video/assets/film-fonts/Fraunces.ttf +0 -0
  40. package/skills/media/kaizen-video/assets/film-fonts/Inter.ttf +0 -0
  41. package/skills/media/kaizen-video/assets/film-fonts/PlayfairDisplay-Italic.ttf +0 -0
  42. package/skills/media/kaizen-video/assets/film-fonts/PlayfairDisplay.ttf +0 -0
  43. package/skills/media/kaizen-video/canvas.html +241 -0
  44. package/skills/media/kaizen-video/examples/canvas-film/cat.txt +31 -0
  45. package/skills/media/kaizen-video/examples/canvas-film/film.json +460 -0
  46. package/skills/media/kaizen-video/examples/canvas-film/lines.json +10 -0
  47. package/skills/media/kaizen-video/examples/canvas-film/skip.txt +18 -0
  48. package/skills/media/kaizen-video/examples/canvas-film/talk.txt +23 -0
  49. package/skills/media/kaizen-video/examples/canvas-film/wow.txt +24 -0
  50. package/skills/media/kaizen-video/examples/kaizen-promo/promo.json +17 -0
  51. package/skills/media/kaizen-video/examples/kaizen-promo/record.json +10 -0
  52. package/skills/media/kaizen-video/examples/notula-promo/promo.json +41 -0
  53. package/skills/media/kaizen-video/examples/notula-promo/record.json +135 -0
  54. package/skills/media/kaizen-video/examples/notula-promo/seed.php +20 -0
  55. package/skills/media/kaizen-video/examples/notula-promo/seed.py +38 -0
  56. package/skills/media/kaizen-video/examples/sample-film/README.md +10 -0
  57. package/skills/media/kaizen-video/examples/sample-film/film.json +63 -0
  58. package/skills/media/kaizen-video/film.html +246 -0
  59. package/skills/media/kaizen-video/presets/app-promo/CREDITS.txt +2 -0
  60. package/skills/media/kaizen-video/presets/app-promo/README.md +21 -0
  61. package/skills/media/kaizen-video/presets/app-promo/preset.json +7 -0
  62. package/skills/media/kaizen-video/presets/app-promo/template/compositions/end.html +25 -0
  63. package/skills/media/kaizen-video/presets/app-promo/template/compositions/hook.html +19 -0
  64. package/skills/media/kaizen-video/presets/app-promo/template/compositions/name.html +19 -0
  65. package/skills/media/kaizen-video/presets/app-promo/template/compositions/step.html +52 -0
  66. package/skills/media/kaizen-video/presets/app-promo/template/index.html +24 -0
  67. package/skills/media/kaizen-video/presets/film-cinematic-drama/.hidden +1 -0
  68. package/skills/media/kaizen-video/presets/film-cinematic-drama/CREDITS.txt +1 -0
  69. package/skills/media/kaizen-video/presets/film-cinematic-drama/README.md +2 -0
  70. package/skills/media/kaizen-video/presets/film-cinematic-drama/style.json +39 -0
  71. package/skills/media/kaizen-video/presets/film-explainer-canvas/.hidden +1 -0
  72. package/skills/media/kaizen-video/presets/film-explainer-canvas/CREDITS.txt +3 -0
  73. package/skills/media/kaizen-video/presets/film-explainer-canvas/README.md +7 -0
  74. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/fonts/InstrumentSerif.ttf +0 -0
  75. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/fonts/SpaceMono.ttf +0 -0
  76. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/boing.wav +0 -0
  77. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/ding.wav +0 -0
  78. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/ending.wav +0 -0
  79. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/pop.wav +0 -0
  80. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/reveal.wav +0 -0
  81. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/shutter.wav +0 -0
  82. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/stamp.wav +0 -0
  83. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/tick.wav +0 -0
  84. package/skills/media/kaizen-video/presets/film-explainer-canvas/assets/sfx/whoosh.wav +0 -0
  85. package/skills/media/kaizen-video/presets/film-explainer-canvas/style.json +15 -0
  86. package/skills/media/kaizen-video/presets/film-fun-energetic/.hidden +1 -0
  87. package/skills/media/kaizen-video/presets/film-fun-energetic/CREDITS.txt +1 -0
  88. package/skills/media/kaizen-video/presets/film-fun-energetic/README.md +2 -0
  89. package/skills/media/kaizen-video/presets/film-fun-energetic/style.json +39 -0
  90. package/skills/media/kaizen-video/presets/film-promo-booth/.hidden +1 -0
  91. package/skills/media/kaizen-video/presets/film-promo-booth/CREDITS.txt +1 -0
  92. package/skills/media/kaizen-video/presets/film-promo-booth/README.md +2 -0
  93. package/skills/media/kaizen-video/presets/film-promo-booth/style.json +39 -0
  94. package/skills/media/kaizen-video/presets/film-viral-social/.hidden +1 -0
  95. package/skills/media/kaizen-video/presets/film-viral-social/CREDITS.txt +1 -0
  96. package/skills/media/kaizen-video/presets/film-viral-social/README.md +2 -0
  97. package/skills/media/kaizen-video/presets/film-viral-social/style.json +39 -0
  98. package/skills/media/kaizen-video/presets/tiktok-explainer/CREDITS.txt +3 -0
  99. package/skills/media/kaizen-video/presets/tiktok-explainer/README.md +52 -0
  100. package/skills/media/kaizen-video/presets/tiktok-explainer/assets/fonts/InstrumentSerif.ttf +0 -0
  101. package/skills/media/kaizen-video/presets/tiktok-explainer/assets/fonts/SpaceMono.ttf +0 -0
  102. package/skills/media/kaizen-video/presets/tiktok-explainer/assets/sfx/boing.wav +0 -0
  103. package/skills/media/kaizen-video/presets/tiktok-explainer/assets/sfx/ding.wav +0 -0
  104. package/skills/media/kaizen-video/presets/tiktok-explainer/assets/sfx/ending.wav +0 -0
  105. package/skills/media/kaizen-video/presets/tiktok-explainer/assets/sfx/pop.wav +0 -0
  106. package/skills/media/kaizen-video/presets/tiktok-explainer/assets/sfx/reveal.wav +0 -0
  107. package/skills/media/kaizen-video/presets/tiktok-explainer/assets/sfx/shutter.wav +0 -0
  108. package/skills/media/kaizen-video/presets/tiktok-explainer/assets/sfx/stamp.wav +0 -0
  109. package/skills/media/kaizen-video/presets/tiktok-explainer/assets/sfx/tick.wav +0 -0
  110. package/skills/media/kaizen-video/presets/tiktok-explainer/assets/sfx/whoosh.wav +0 -0
  111. package/skills/media/kaizen-video/presets/tiktok-explainer/index.html +272 -0
  112. package/skills/media/kaizen-video/presets/tiktok-explainer/package.json +10 -0
  113. package/skills/media/kaizen-video/references/canvas.md +60 -0
  114. package/skills/media/kaizen-video/references/presets.md +107 -0
  115. package/skills/{story-video → media/kaizen-video}/references/production.md +2 -2
  116. package/skills/media/kaizen-video/references/promo.md +148 -0
  117. package/skills/media/kaizen-video/references/revisions.md +34 -0
  118. package/skills/media/kaizen-video/scripts/__pycache__/intake.cpython-314.pyc +0 -0
  119. package/skills/media/kaizen-video/scripts/__pycache__/make_film.cpython-314.pyc +0 -0
  120. package/skills/media/kaizen-video/scripts/__pycache__/make_tiktok.cpython-314.pyc +0 -0
  121. package/skills/media/kaizen-video/scripts/__pycache__/render_cut.cpython-314.pyc +0 -0
  122. package/skills/media/kaizen-video/scripts/__pycache__/sfx.cpython-314.pyc +0 -0
  123. package/skills/media/kaizen-video/scripts/__pycache__/srt.cpython-314.pyc +0 -0
  124. package/skills/media/kaizen-video/scripts/__pycache__/transcribe.cpython-314.pyc +0 -0
  125. package/skills/media/kaizen-video/scripts/__pycache__/vo.cpython-314.pyc +0 -0
  126. package/skills/{kaizen-video → media/kaizen-video}/scripts/check.sh +8 -0
  127. package/skills/{story-video → media/kaizen-video}/scripts/intake.py +2 -2
  128. package/skills/media/kaizen-video/scripts/make_film.py +416 -0
  129. package/skills/media/kaizen-video/scripts/make_promo.py +297 -0
  130. package/skills/{kaizen-video → media/kaizen-video}/scripts/make_tiktok.py +42 -9
  131. package/skills/{story-video → media/kaizen-video}/scripts/master.sh +12 -11
  132. package/skills/media/kaizen-video/scripts/pixel.py +40 -0
  133. package/skills/media/kaizen-video/scripts/record.mjs +103 -0
  134. package/skills/{story-video → media/kaizen-video}/scripts/sfx.py +3 -3
  135. package/skills/media/kaizen-video/scripts/srt.py +9 -0
  136. package/skills/media/kaizen-video/scripts/still.sh +7 -0
  137. package/web/board/views.ts +1 -1
  138. package/web/board.html +3 -1
  139. package/web/board.js +2 -2
  140. package/web/notebook.js +1 -1
  141. package/web/notes.html +2 -0
  142. package/web/term.js +1 -1
  143. package/web/video.html +332 -0
  144. package/web/video.js +92 -0
  145. package/web/video.ts +843 -0
  146. package/skills/kaizen-video/SKILL.md +0 -73
  147. package/skills/kaizen-video/references/presets.md +0 -54
  148. package/skills/story-video/SKILL.md +0 -108
  149. package/skills/story-video/engine/package.json +0 -12
  150. package/skills/story-video/engine/src/Root.tsx +0 -24
  151. package/skills/story-video/engine/src/engine/Film.tsx +0 -405
  152. package/skills/story-video/engine/src/engine/presets.json +0 -58
  153. package/skills/story-video/engine/src/index.ts +0 -3
  154. package/skills/story-video/engine/tsconfig.json +0 -1
  155. package/skills/story-video/examples/sample-film/README.md +0 -12
  156. package/skills/story-video/examples/sample-film/film.json +0 -16
  157. package/skills/story-video/references/presets.md +0 -21
  158. package/skills/story-video/references/revisions.md +0 -25
  159. package/skills/story-video/scripts/check.sh +0 -19
  160. package/skills/story-video/scripts/setup.sh +0 -25
  161. package/skills/story-video/scripts/srt.py +0 -30
  162. package/skills/story-video/scripts/still.sh +0 -10
  163. /package/skills/{story-deck → media/kaizen-deck}/examples/build-example.js +0 -0
  164. /package/skills/{story-deck → media/kaizen-deck}/references/rules.md +0 -0
  165. /package/skills/{story-deck → media/kaizen-deck}/references/story-arc.md +0 -0
  166. /package/skills/{story-deck → media/kaizen-deck}/scripts/kit.js +0 -0
  167. /package/skills/{story-deck → media/kaizen-deck}/scripts/prep_images.py +0 -0
  168. /package/skills/{story-deck → media/kaizen-deck}/scripts/qa.sh +0 -0
  169. /package/skills/{kaizen-video → media/kaizen-video}/assets/fonts/Fredoka.ttf +0 -0
  170. /package/skills/{kaizen-video → media/kaizen-video}/assets/fonts/Montserrat.ttf +0 -0
  171. /package/skills/{kaizen-video → media/kaizen-video}/assets/fonts/SpecialElite.ttf +0 -0
  172. /package/skills/{kaizen-video → media/kaizen-video}/assets/music/investigations.mp3 +0 -0
  173. /package/skills/{kaizen-video → media/kaizen-video}/assets/music/lights.mp3 +0 -0
  174. /package/skills/{kaizen-video → media/kaizen-video}/assets/music/sunny.mp3 +0 -0
  175. /package/skills/{kaizen-video → media/kaizen-video}/examples/config.json +0 -0
  176. /package/skills/{story-video → media/kaizen-video}/examples/sample-film/lines.json +0 -0
  177. /package/skills/{kaizen-video → media/kaizen-video}/hyperframes.json +0 -0
  178. /package/skills/{kaizen-video → media/kaizen-video}/presets/educational-warning/CREDITS.txt +0 -0
  179. /package/skills/{kaizen-video → media/kaizen-video}/presets/educational-warning/README.md +0 -0
  180. /package/skills/{kaizen-video → media/kaizen-video}/presets/educational-warning/assets/sfx/ending.wav +0 -0
  181. /package/skills/{kaizen-video → media/kaizen-video}/presets/educational-warning/assets/sfx/reveal.wav +0 -0
  182. /package/skills/{kaizen-video → media/kaizen-video}/presets/educational-warning/assets/sfx/shutter.wav +0 -0
  183. /package/skills/{kaizen-video → media/kaizen-video}/presets/educational-warning/assets/sfx/stamp.wav +0 -0
  184. /package/skills/{kaizen-video → media/kaizen-video}/presets/educational-warning/index.html +0 -0
  185. /package/skills/{kaizen-video → media/kaizen-video}/presets/educational-warning/package.json +0 -0
  186. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/CREDITS.txt +0 -0
  187. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/README.md +0 -0
  188. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/assets/sfx/boing.wav +0 -0
  189. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/assets/sfx/chime.wav +0 -0
  190. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/assets/sfx/ding.wav +0 -0
  191. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/assets/sfx/ending.wav +0 -0
  192. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/assets/sfx/pop.wav +0 -0
  193. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/assets/sfx/reveal.wav +0 -0
  194. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/assets/sfx/shutter.wav +0 -0
  195. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/assets/sfx/stamp.wav +0 -0
  196. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/assets/sfx/whoosh.wav +0 -0
  197. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/index.html +0 -0
  198. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-cheerful/package.json +0 -0
  199. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/CREDITS.txt +0 -0
  200. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/README.md +0 -0
  201. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/assets/sfx/clock.wav +0 -0
  202. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/assets/sfx/ding.wav +0 -0
  203. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/assets/sfx/ending.wav +0 -0
  204. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/assets/sfx/heart.wav +0 -0
  205. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/assets/sfx/projector.wav +0 -0
  206. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/assets/sfx/reveal.wav +0 -0
  207. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/assets/sfx/shutter.wav +0 -0
  208. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/assets/sfx/stamp.wav +0 -0
  209. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/assets/sfx/whoosh.wav +0 -0
  210. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/index.html +0 -0
  211. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-mystery/package.json +0 -0
  212. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/CREDITS.txt +0 -0
  213. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/README.md +0 -0
  214. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/assets/sfx/clock.wav +0 -0
  215. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/assets/sfx/ding.wav +0 -0
  216. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/assets/sfx/ending.wav +0 -0
  217. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/assets/sfx/heart.wav +0 -0
  218. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/assets/sfx/reveal.wav +0 -0
  219. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/assets/sfx/shutter.wav +0 -0
  220. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/assets/sfx/stamp.wav +0 -0
  221. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/assets/sfx/whoosh.wav +0 -0
  222. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/index.html +0 -0
  223. /package/skills/{kaizen-video → media/kaizen-video}/presets/tiktok-scam-alert/package.json +0 -0
  224. /package/skills/{story-video → media/kaizen-video}/references/licensing.md +0 -0
  225. /package/skills/{story-video → media/kaizen-video}/references/script.md +0 -0
  226. /package/skills/{story-video → media/kaizen-video}/scripts/music.sh +0 -0
  227. /package/skills/{kaizen-video → media/kaizen-video}/scripts/render_cut.py +0 -0
  228. /package/skills/{kaizen-video → media/kaizen-video}/scripts/setup.sh +0 -0
  229. /package/skills/{kaizen-video → media/kaizen-video}/scripts/transcribe.py +0 -0
  230. /package/skills/{story-video → media/kaizen-video}/scripts/vo.py +0 -0
  231. /package/skills/{kaizen-video → media/kaizen-video}/tools/carve.mjs +0 -0
  232. /package/skills/{kaizen-video → media/kaizen-video}/tools/lib/main-module.mjs +0 -0
@@ -0,0 +1,34 @@
1
+ # Revisions
2
+
3
+ Clients revise. Make every revision cheap, traceable and reversible.
4
+
5
+ ## Classify the request, then touch only that layer
6
+ | request | what changes | redo |
7
+ |---|---|---|
8
+ | "change this sentence / say it warmer / mispronounced X" | `lines.json` entry | `vo.py <film-dir> "" v04` (only that key; empty voice = use film.json), then build and render |
9
+ | "different text on screen" | beat `kick/title/sub/items` in `film.json` | build + master |
10
+ | "swap this picture" | beat `img` (+ intake for new photos) | build + render |
11
+ | "slower / faster / shorter" | preset `pace`, beat `hold`, drop or merge beats | build + render |
12
+ | "music too loud / different mood" | preset `music.base/lift` or `music.sh` new track | build + render |
13
+ | "other colours / logo / font" | `film.brand`, `logo` | build + render |
14
+ | "make a vertical / 15 s version" | new film entry with its own (shorter) script | vo + master |
15
+ | "different style" | `preset` (and usually a rewritten script) | vo + master |
16
+
17
+ Never regenerate all narration for a one-line change: voices vary between takes and credits cost money.
18
+
19
+ ## Versioning
20
+ - Renders still land in `output/<name>/<preset>/<name>.mp4`. The kaizen board then files each one as a
21
+ **version** (a, b, c…) under `output/<name>/versions/<letter>/<n>/`. Next to it goes its **recipe**, a
22
+ copy of the video folder's small files (film.json or config.json, lines, words, voice lines,
23
+ pictures, transcript JSON), in `videos/<name>/versions/<letter>/<n>/`. Do not move or rename these
24
+ folders by hand.
25
+ - `videos/<name>/versions.json` says which version the draft is revising (`revising`).
26
+ - When it is set, the user picked that version on the Video page, and its recipe is in the draft. Keep
27
+ its preset. Your render becomes that version's **try**, which the user keeps or reverts on the page.
28
+ - When it is unset, a render becomes a new version.
29
+ - Append to `videos/<name>/REVISIONS.md`: date, the user's words verbatim, what changed, output file.
30
+ - A rejected revision is reverted on the Video page, not re-rendered. Older renders sit in each version's
31
+ history there.
32
+
33
+ ## Before re-delivering
34
+ Re-check stills of the beats that changed, master, and say exactly what changed and what did not.
@@ -11,4 +11,12 @@ need npx "comes with Node.js"
11
11
  need python3 "Python 3.9+"
12
12
  command -v uv >/dev/null 2>&1 && echo "ok uv" || { echo "MISSING uv — https://docs.astral.sh/uv/ (installs Python 3.11 for WhisperX)"; miss=1; }
13
13
  [ -x "$HOME_DIR/whisperx-venv/bin/python" ] && echo "ok WhisperX ($HOME_DIR/whisperx-venv)" || echo "todo WhisperX — run setup.sh (about 2 GB of packages, plus a 3 GB model on the first transcription)"
14
+ # From-scratch films (make_film.py) need these too; WhisperX is footage-only.
15
+ opt(){ command -v "$1" >/dev/null 2>&1 && echo "ok $1" || echo "opt $1 — $2"; }
16
+ opt soffice "LibreOffice — only for importing .pptx decks"
17
+ opt pdftoppm "poppler-utils — only for importing decks"
18
+ python3 -c "import PIL" 2>/dev/null && echo "ok Pillow" || echo "opt Pillow — pip install pillow (from-scratch: intake.py)"
19
+ python3 -c "import edge_tts" 2>/dev/null && echo "ok edge-tts (free voices)" || echo "opt edge-tts — pip install edge-tts (from-scratch voice without an ElevenLabs key)"
20
+ python3 -c "import qrcode" 2>/dev/null && echo "ok qrcode" || echo "opt qrcode — pip install 'qrcode[pil]' (QR on the CTA)"
21
+ [ -n "${ELEVENLABS_API_KEY:-}" ] && echo "ok ELEVENLABS_API_KEY set" || echo "info no ELEVENLABS_API_KEY — from-scratch uses edge-tts and synthesized sound effects"
14
22
  exit $miss
@@ -1,7 +1,7 @@
1
1
  """Turn whatever the user brought into film-ready assets.
2
2
  Usage: python3 scripts/intake.py <film-dir> [input_dir] (default input_dir: <film-dir>/inputs)
3
3
  <input_dir> may contain, in any mix:
4
- photos/ story photos -> <name>-16x9.jpg + <name>-9x16.jpg (cropped, light grade)
4
+ photos/ story photos -> <name>-16x9.jpg, -9x16.jpg, -4x5.jpg (cropped, light grade)
5
5
  screens/ app/web screenshots -> copied untouched; ratio recorded (use kind "shot")
6
6
  footage/ video clips (.mp4/.mov) -> <name>.mp4 (H.264, no audio, 1080p max)
7
7
  logo*.png logo(s) -> copied; dominant colours suggested for brand.palette
@@ -36,7 +36,7 @@ def grade(im):
36
36
  for f in sorted((src / "photos").glob("*")) if (src / "photos").exists() else []:
37
37
  if f.suffix.lower() not in IMG: continue
38
38
  im = Image.open(f).convert("RGB")
39
- for tag, size in (("16x9", (1920, 1080)), ("9x16", (1080, 1920))):
39
+ for tag, size in (("16x9", (1920, 1080)), ("9x16", (1080, 1920)), ("4x5", (1080, 1350))):
40
40
  grade(crop(im, *size)).save(out / f"{f.stem}-{tag}.jpg", quality=88)
41
41
  manifest["photos"].append(f.stem)
42
42
  for f in sorted((src / "screens").glob("*")) if (src / "screens").exists() else []:
@@ -0,0 +1,416 @@
1
+ """Build (and optionally render) a film made from nothing: narration, pictures, music, sound effects.
2
+
3
+ python3 scripts/make_film.py videos/<name> [--render] [--format 9x16|16x9|4x5]
4
+
5
+ Run from the project folder. videos/<name>/ holds film.json (storyboard + brand), lines.json (the script),
6
+ words.json (word timings from vo.py), the voice files vNN.mp3 and the pictures. Writes the HyperFrames project
7
+ into videos/<name>/film/; with --render, scripts/master.sh renders it, masters the loudness and writes
8
+ output/<name>/<preset>/<name>.mp4 with the .srt, thumbnail and credits.
9
+
10
+ film.json: "preset" (a folder under presets/ with a style.json, e.g. film-cinematic-drama), "format"
11
+ ("9x16" default, "16x9", or "4x5" for an Instagram feed post), "beats", "brand", "labels", "cta", "logo", "qr", "music" (a bundled track name;
12
+ without it videos/<name>/music.mp3 is used). The preset is found in ./presets/, $KAIZEN_VIDEO_PRESETS
13
+ (default ~/.kaizen/video-presets/), then the skill's presets/, like make_tiktok.py.
14
+ "style" overrides keys of the preset's style.json for this film (a dict merges into the preset's, e.g.
15
+ {"pace": {"lead": 0, "tail": 0}}). A footage preset (a folder with index.html) works too: the film is
16
+ rendered once with no captions and no music, then make_tiktok.py styles that video like recorded footage
17
+ (videos/<name>/footage-bridge/; film.json "hook" {"line1", "line2", "sub"} sets its hook, else the first words).
18
+ The film's scenes become the template's (title, stat as a big numeral, question as "?", items as item rows, cta as
19
+ end), each at the start of its line; film.json "footage_beats" (template beats, placed with "t" seconds or "word")
20
+ replaces that mapping, "mascot" (a picture in the video folder) adds the template's corner mascot, and a beat's "pics"
21
+ (pictures in the video folder) feed the picture scenes after its headline. The clip card is hidden (no real footage).
22
+ --format overrides film.json's format for one build and adds -<format> to the output name, so one film can be
23
+ rendered for several shapes (the Video page in kaizen web does this) without one render replacing another.
24
+ """
25
+ import json
26
+ import os
27
+ import re
28
+ import shutil
29
+ import subprocess
30
+ import sys
31
+ from pathlib import Path
32
+
33
+ SKILL = Path(__file__).resolve().parent.parent
34
+ WORK = Path.cwd()
35
+ HF = "hyperframes@0.8.176"
36
+ FPS = 30
37
+ HOME = Path(os.environ.get("KAIZEN_VIDEO_HOME", Path.home() / ".kaizen/kaizen-video"))
38
+ SIZES = {"9x16": (1080, 1920, "portrait"), "16x9": (1920, 1080, "landscape"), "4x5": (1080, 1350, "portrait")}
39
+
40
+ vdir = Path(sys.argv[1]).resolve()
41
+ proj = vdir / "film"
42
+ film = json.loads((vdir / "film.json").read_text())
43
+ words = json.loads((vdir / "words.json").read_text())
44
+ forced = sys.argv[sys.argv.index("--format") + 1] if "--format" in sys.argv[:-1] else None
45
+ fmt = forced or film.get("format", "9x16")
46
+ if fmt not in SIZES:
47
+ sys.exit(f"film.json format {fmt!r} must be one of {', '.join(SIZES)}")
48
+ W, H, RES = SIZES[fmt]
49
+ LANG = film.get("language", "id")
50
+
51
+ # 1. Preset: a folder with style.json.
52
+ dirs = [WORK / "presets", Path(os.environ.get("KAIZEN_VIDEO_PRESETS", Path.home() / ".kaizen/video-presets")), SKILL / "presets"]
53
+ want = film["preset"]
54
+ preset = next((d / n for n in (want, "film-" + want) for d in dirs if (d / n / "style.json").exists()), None)
55
+ # A footage preset: build pass 1 in a plain base style with no captions, no music and no cut sounds; it is styled after.
56
+ footage = None if preset else next((d / want for d in dirs if (d / want / "index.html").exists()), None)
57
+ if footage:
58
+ if fmt != "9x16" and forced: # the Video page renders every shape the platforms need; this one has no other shape
59
+ print(f"skipped {fmt}: footage preset {want!r} is 9:16 only")
60
+ sys.exit(0)
61
+ if fmt != "9x16":
62
+ sys.exit(f"footage preset {want!r} is 9:16 only; set film.json format to 9x16")
63
+ preset = next(d / "film-viral-social" for d in dirs if (d / "film-viral-social" / "style.json").exists())
64
+ if not preset:
65
+ names = sorted({p.parent.name for d in dirs if d.exists() for p in d.glob("*/style.json")})
66
+ sys.exit(f"preset {want!r} not found in {', '.join(map(str, dirs))}; available: {', '.join(names)}")
67
+ print(f"preset {preset}")
68
+ style = json.loads((preset / "style.json").read_text())
69
+ over = {**film.get("style", {}), **({"captions": "none", "music": {"base": 0, "lift": 0}, "sfx": {"cut": "", "text": "", "reveal": "", "question": ""}} if footage else {})}
70
+ for k, v in over.items():
71
+ style[k] = {**style.get(k, {}), **v} if isinstance(v, dict) else v
72
+ brand = film.get("brand", {})
73
+ style["palette"] = {**style["palette"], **brand.get("palette", {})}
74
+ style["fonts"] = {**style["fonts"], **brand.get("fonts", {})}
75
+ pace = style["pace"]
76
+ shutil.rmtree(proj / "assets", ignore_errors=True)
77
+ for d in ("img", "video", "sfx", "fonts"):
78
+ (proj / "assets" / d).mkdir(parents=True)
79
+
80
+
81
+ def probe(f, entry, kind="format"):
82
+ out = subprocess.check_output(["ffprobe", "-v", "error", "-show_entries", f"{kind}={entry}", "-of", "csv=p=0", str(f)])
83
+ return out.decode().strip()
84
+
85
+
86
+ def run(*cmd, cwd=proj):
87
+ subprocess.run(cmd, check=True, cwd=cwd)
88
+
89
+
90
+ # 2. Timeline: every beat is lead + its voice line + tail (+ hold), in whole frames, one after another.
91
+ canvas = style.get("engine") == "canvas" # a canvas film: one large canvas and a camera (canvas.html, references/canvas.md)
92
+ if canvas:
93
+ for b in film["beats"]:
94
+ b.setdefault("kind", "canvas")
95
+ t, beats = 0, []
96
+ for n, b in enumerate(film["beats"]):
97
+ v = b.get("vo")
98
+ if v and v not in words:
99
+ sys.exit(f"beat {n + 1}: voice {v!r} is not in words.json; run vo.py first")
100
+ frames = round(((pace["lead"] + words[v]["dur"] + pace["tail"]) if v else 0) * FPS + b.get("hold", 0) * FPS)
101
+ if frames:
102
+ beats.append({**b, "n": n, "start": t / FPS, "len": frames / FPS, "dur": words[v]["dur"] if v else 0})
103
+ else:
104
+ print(f"warning: beat {n + 1} ({b['kind']}) has no voice and no hold, so it is skipped")
105
+ t += frames
106
+ total = t / FPS
107
+ reveal = next((b["start"] for b in beats if b["kind"] == "reveal"), total / 2)
108
+
109
+ # 3. Pictures, footage, logo, QR into the project (a photo name may be a stem: intake writes <stem>-9x16.jpg).
110
+ def stage(name, sub):
111
+ if not name:
112
+ return name
113
+ src = vdir / name
114
+ for tag in (fmt, "9x16") if fmt == "4x5" else (fmt,): # a film intaken before 4x5 existed uses its 9x16 crops
115
+ if not src.exists():
116
+ src = vdir / f"{Path(name).stem}-{tag}.jpg"
117
+ if not src.exists():
118
+ sys.exit(f"file {name!r} not found in {vdir}")
119
+ flat = re.sub(r"[\\/]", "_", str(src.relative_to(vdir)))
120
+ shutil.copy(src, proj / "assets" / sub / flat)
121
+ return f"assets/{sub}/{flat}"
122
+
123
+
124
+ scenes = []
125
+ if footage:
126
+ # Pass 1 carries pictures only: the footage template draws the words, from these scenes.
127
+ scenes = [dict(b) for b in beats]
128
+ keep = ("n", "start", "len", "dur", "vo", "hold", "ambience", "sfx", "img", "video", "shotRatio")
129
+ beats = [{**{k: b[k] for k in keep if k in b}, "kind": b["kind"] if b["kind"] in ("footage", "shot") else "media",
130
+ **({"img": b["panels"][0]["img"]} if b.get("panels") and not b.get("img") else {})} for b in beats]
131
+ for b in beats:
132
+ b["img"], b["video"] = stage(b.get("img"), "img"), stage(b.get("video"), "video")
133
+ if b.get("panels"):
134
+ b["panels"] = [{**p, "img": stage(p["img"], "img")} for p in b["panels"]]
135
+ if b["kind"] == "shot" and b["img"] and not b.get("shotRatio"):
136
+ b["shotRatio"] = round(int(probe(proj / b["img"], "width", "stream")) / int(probe(proj / b["img"], "height", "stream")), 3)
137
+ labels = {"source": "Sumber" if LANG == "id" else "Source", "next": "Langkah berikutnya" if LANG == "id" else "Next step", **film.get("labels", {})}
138
+
139
+ # 4. Captions: subtitle chunks of up to 7 words (also the .srt cues), or kinetic groups of 2-3 words.
140
+ def chunks(ws):
141
+ out, cur = [], []
142
+ for w in ws:
143
+ cur.append(w)
144
+ if len(cur) >= 7 or re.search(r"[.,?!]$", w["w"]):
145
+ out.append(cur)
146
+ cur = []
147
+ return out + ([cur] if cur else [])
148
+
149
+
150
+ def groups(ws):
151
+ out, i = [], 0
152
+ while i < len(ws):
153
+ k = 2 if len("".join(w["w"] for w in ws[i:i + 3])) > 16 else 3
154
+ out.append(ws[i:i + k])
155
+ i += k
156
+ return out
157
+
158
+
159
+ captions, cues, spoken = [], [], []
160
+ for b in beats:
161
+ if not b.get("vo"):
162
+ continue
163
+ t0 = b["start"] + pace["lead"]
164
+ ws = [{"w": w["w"], "s": round(t0 + w["s"], 3), "e": round(t0 + w["e"], 3)} for w in words[b["vo"]]["words"]]
165
+ spoken += ws
166
+ cues += [[c[0]["s"], c[-1]["e"] + 0.2, " ".join(w["w"] for w in c)] for c in chunks(ws)]
167
+ if b["kind"] == "cta" or style["captions"] == "none":
168
+ continue
169
+ gs = chunks(ws) if style["captions"] == "subtitle" else groups(ws)
170
+ for i, g in enumerate(gs):
171
+ nxt = gs[i + 1][0]["s"] if i + 1 < len(gs) else min(g[-1]["e"] + 0.4, b["start"] + b["len"])
172
+ captions.append({"s": round(max(b["start"], g[0]["s"] - (0.05 if i == 0 else 0)), 3), "e": round(nxt, 3), "words": g})
173
+ for a, c in zip(cues, cues[1:]):
174
+ a[1] = round(min(a[1], c[0] - 0.02), 3) # no overlapping cues
175
+ proj.mkdir(exist_ok=True)
176
+ (proj / "cues.json").write_text(json.dumps(cues, ensure_ascii=False))
177
+
178
+ # A canvas film's pictures, and its actions' times: "at" is seconds from the beat's start, or "word:<w>" the moment
179
+ # the beat's first word starting with <w> is spoken.
180
+ CANVAS_SFX = {"move": "whoosh", "pop": "pop", "stamp": "stamp", "scrub": "tick", "morph": "shutter", "fill": "reveal"}
181
+ if canvas:
182
+ if fmt != "9x16" or not film.get("canvas"):
183
+ sys.exit("a canvas preset needs film.json \"canvas\" (see references/canvas.md) and the 9x16 format")
184
+ for e in film["canvas"]["elements"]:
185
+ if e.get("img"):
186
+ e["img"] = stage(e["img"], "img")
187
+ for fr in e.get("frames", []):
188
+ if fr.get("img"):
189
+ fr["img"] = stage(fr["img"], "img")
190
+ for b in beats:
191
+ bw = [{"w": w["w"], "s": b["start"] + pace["lead"] + w["s"]} for w in words[b["vo"]]["words"]] if b.get("vo") else []
192
+ for a in b.get("do", []):
193
+ at = a.get("at", 0)
194
+ if isinstance(at, str) and at.startswith("word:"):
195
+ key = at[5:].lower()
196
+ hit = next((w["s"] for w in bw if w["w"].lower().strip(",.?!\"'").startswith(key)), None)
197
+ if hit is None:
198
+ sys.exit(f"beat {b['n'] + 1}: no word starting with {key!r} for {a}")
199
+ a["t"] = round(hit, 3)
200
+ else:
201
+ a["t"] = round(b["start"] + float(at), 3)
202
+
203
+ film_data = {"fmt": fmt, "W": W, "H": H, "language": LANG, "style": style, "labels": labels, "total": total, "beats": beats, "captions": captions,
204
+ "cta": film.get("cta"), "logo": stage(film.get("logo"), "img"), "logoOnLight": stage(film.get("logoOnLight"), "img"), "qr": stage(film.get("qr"), "img"),
205
+ **({"canvas": film["canvas"], "mascot": stage(film.get("mascot"), "img")} if canvas else {})}
206
+ (proj / "film-data.js").write_text("window.FILM = " + json.dumps(film_data, ensure_ascii=False) + ";\n")
207
+
208
+ # 5. Audio: the voice lines on one track, the music bed with the style's levels, sound effects and room tone.
209
+ def ffmpeg(*args):
210
+ run("ffmpeg", "-v", "error", "-y", *args)
211
+
212
+
213
+ ins, graph = [], []
214
+ for i, b in enumerate(x for x in beats if x.get("vo")):
215
+ ins += ["-i", str(vdir / f"{b['vo']}.mp3")]
216
+ ms = round((b["start"] + pace["lead"]) * 1000)
217
+ graph.append(f"[{i}:a]aformat=sample_rates=48000:channel_layouts=stereo,atrim=start={words[b['vo']]['offset']},asetpts=PTS-STARTPTS,adelay={ms}|{ms}[a{i}]")
218
+ if not graph:
219
+ sys.exit("no beat has a voice line (vo); a film needs narration")
220
+ mix = "".join(f"[a{i}]" for i in range(len(graph)))
221
+ ffmpeg(*ins, "-filter_complex", ";".join(graph) + f";{mix}amix=inputs={len(graph)}:normalize=0:duration=longest,apad[o]",
222
+ "-map", "[o]", "-t", str(total), "-ar", "48000", "assets/vo.wav")
223
+
224
+ music = style["music"]
225
+ track = vdir / music["track"]
226
+ if film.get("music"):
227
+ track = SKILL / "assets/music" / f"{film['music']}.mp3"
228
+ if footage and not track.exists(): # pass 1 is silent music; any bundled track will do
229
+ track = SKILL / "assets/music/sunny.mp3"
230
+ if not track.exists():
231
+ sys.exit(f"no music: put {music['track']} in {vdir} (scripts/music.sh) or set film.json \"music\" to one of: "
232
+ + ", ".join(sorted(p.stem for p in (SKILL / "assets/music").glob("*.mp3"))))
233
+ pts = [(0, 0), (1, music["base"]), (max(1, reveal - 0.5), music["base"]), (reveal + 1 / 3, music["lift"]), (reveal + 3, music["base"] + 0.04),
234
+ (total - 2, music["base"] + 0.04), (total, 0)]
235
+ pts = [p for i, p in enumerate(pts) if i == 0 or p[0] > pts[i - 1][0]] # a short film can fold the points back on themselves
236
+ expr = f"{pts[-1][1]}"
237
+ for (t0, a0), (t1, a1) in reversed(list(zip(pts, pts[1:]))):
238
+ expr = f"if(lt(t,{t1}),{a0}+({a1}-{a0})*(t-{t0})/({t1}-{t0}),{expr})"
239
+ ffmpeg("-i", str(track), "-af", f"aloop=loop=-1:size=2e9,atrim=0:{total},loudnorm=I=-16:TP=-1.5,volume='{expr}':eval=frame,aformat=sample_rates=48000:channel_layouts=stereo", "assets/music.wav")
240
+
241
+ LIB = HOME / "sfx"
242
+
243
+
244
+ def sound(name):
245
+ def find():
246
+ return next((f for d in (vdir / "sfx", preset / "assets/sfx", LIB) for e in (".wav", ".mp3") if (f := d / (name + e)).exists()), None)
247
+ if not find() and not (LIB / "whoosh.mp3").exists(): # make the shared library once, synthesized (no ElevenLabs credits spent unless SFX_PROVIDER says so)
248
+ run("python3", str(SKILL / "scripts/sfx.py"), "--provider", os.environ.get("SFX_PROVIDER", "synth"))
249
+ f = find()
250
+ if not f:
251
+ sys.exit(f"sound {name!r} not found in {vdir / 'sfx'}, {preset / 'assets/sfx'} or {LIB}")
252
+ shutil.copy(f, proj / "assets/sfx" / f.name)
253
+ return f.name
254
+
255
+
256
+ fx = style["sfx"]
257
+ sfx, amb = [], [] # (file, start, volume)
258
+ for i, b in enumerate(beats):
259
+ cut = fx["reveal"] if b["kind"] == "reveal" else fx["question"] if b["kind"] == "question" else fx["cut"] if i else ""
260
+ if cut:
261
+ sfx.append((sound(cut), b["start"], 0.7 if b["kind"] == "reveal" else 0.35))
262
+ sfx += [(sound(s), b["start"] + pace["lead"], 0.45) for s in b.get("sfx", [])]
263
+ for a in b.get("do", []) if canvas else []: # each camera action carries its sound, unless "sfx": "" turns it off
264
+ name = a.get("sfx", CANVAS_SFX.get(a["act"], ""))
265
+ if name:
266
+ sfx.append((sound(name), a["t"] + (0.35 if a["act"] == "stamp" else 0), a.get("vol", 0.4)))
267
+ if fx["text"] and b.get("title") and i:
268
+ sfx.append((sound(fx["text"]), b["start"] + pace["lead"] + 0.2, 0.25))
269
+ if b.get("ambience"):
270
+ a = sound(b["ambience"])
271
+ ffmpeg("-stream_loop", "-1", "-i", f"assets/sfx/{a}", "-t", str(b["len"]), "-af", f"afade=t=in:d=0.3,afade=t=out:st={max(0, b['len'] - 0.3)}:d=0.3,aformat=sample_rates=48000:channel_layouts=stereo", f"assets/amb-{i}.wav")
272
+ amb.append((f"amb-{i}.wav", b["start"], b["len"]))
273
+ tracks, tags = {}, [] # greedy track numbers from 3, so no two sounds overlap on one track (HyperFrames lint)
274
+
275
+
276
+ def place(tag, start, dur):
277
+ k = next(k for k in range(3, 99) if tracks.get(k, -1) <= start)
278
+ tracks[k] = start + dur
279
+ tags.append(tag.replace("TRACK", str(k)))
280
+
281
+
282
+ for i, (name, start, vol) in enumerate(sorted(sfx, key=lambda x: x[1])):
283
+ d = round(float(probe(proj / "assets/sfx" / name, "duration")), 2)
284
+ place(f'<audio id="sfx-{i}" src="assets/sfx/{name}" data-start="{start:.2f}" data-duration="{d}" data-track-index="TRACK" data-volume="{vol}"></audio>', start, d)
285
+ for i, (name, start, dur) in enumerate(amb):
286
+ place(f'<audio id="amb-{i}" src="assets/{name}" data-start="{start:.2f}" data-duration="{dur}" data-track-index="TRACK" data-volume="0.18"></audio>', start, dur)
287
+ audio = "\n ".join([f'<audio id="vo" src="assets/vo.wav" data-start="0" data-duration="{total}" data-track-index="1"></audio>',
288
+ f'<audio id="music" src="assets/music.wav" data-start="0" data-duration="{total}" data-track-index="2"></audio>'] + tags)
289
+
290
+ # 6. Fonts (the style's, plus Inter for kinetic captions), the page, carve the music around the voice, check.
291
+ faces = []
292
+ fonts = set(style["fonts"].values()) | ({"Inter"} if style["captions"] == "kinetic" else set())
293
+ for fam in sorted(fonts):
294
+ stem = fam.replace(" ", "")
295
+ for suffix, slant in (("", "normal"), ("-Italic", "italic")):
296
+ src = next((f for d in (preset / "assets/fonts", SKILL / "assets/film-fonts", SKILL / "assets/fonts") if (f := d / f"{stem}{suffix}.ttf").exists()), None)
297
+ if src:
298
+ shutil.copy(src, proj / "assets/fonts" / src.name)
299
+ faces.append(f'@font-face {{ font-family: "{fam}"; src: url("assets/fonts/{src.name}"); font-weight: 100 900; font-style: {slant}; }}')
300
+ elif not suffix:
301
+ sys.exit(f"font {fam!r} not found: add {stem}.ttf to the preset's assets/fonts or the skill's assets/film-fonts")
302
+ page = (SKILL / ("canvas.html" if canvas else "film.html")).read_text()
303
+ for k, v in {"W": W, "H": H, "RES": RES, "DURATION": total, "LANG": LANG}.items():
304
+ page = page.replace("{{" + k + "}}", str(v))
305
+ page = page.replace("/*FONTS*/", "\n ".join(faces)).replace("<!-- AUDIO -->", audio)
306
+ (proj / "index.html").write_text(page)
307
+ shutil.copy(SKILL / "hyperframes.json", proj / "hyperframes.json")
308
+ (proj / "package.json").write_text(json.dumps({"name": "kaizen-film", "private": True, "type": "module", "devDependencies": {"@hyperframes/core": HF.split("@")[1]}}, indent=2))
309
+ if not (proj / "node_modules/@hyperframes/core").exists():
310
+ run("npm", "install", "--silent")
311
+ run("node", str(SKILL / "tools/carve.mjs"), "--comp", "index.html", "--bed", "music", "--voice", "vo")
312
+ run("npx", "--yes", HF, "check")
313
+ print(f"{len(beats)} beats, {len(captions)} caption groups, {len(sfx)} sfx, {fmt}, {total}s")
314
+
315
+ # 7. Credits and master data, then render + master with --render.
316
+ name = film.get("name", vdir.name) + (f"-{fmt}" if forced else "")
317
+ line = re.compile(rf"^- {re.escape(music['track'] if not film.get('music') else film['music'])}\.mp3: (.+)$", re.M)
318
+ bundled = (SKILL / "assets/CREDITS.txt").read_text() if (SKILL / "assets/CREDITS.txt").exists() else ""
319
+ credits = [f.read_text().strip() for f in [vdir / "CREDITS.txt", *sorted(vdir.glob("CREDITS-*.txt"))] if f.exists()]
320
+ if film.get("music") and (m := line.search(bundled)):
321
+ credits.append("Music: " + m.group(1))
322
+ credits += [f.read_text().strip() for f in (preset / "CREDITS.txt",) if f.exists()]
323
+ credits.append("Voice and sound effects: see the voice provider in film.json (ElevenLabs commercial use requires a paid plan).")
324
+ (proj / "CREDITS.txt").write_text("\n\n".join(credits) + "\n")
325
+ (proj / "meta.json").write_text(json.dumps({"name": name, "folder": film.get("name", vdir.name), "preset": preset.name, "loudness": style["loudness"]}))
326
+ if footage:
327
+ # ponytail: pass 1 renders on every build, so a footage preset's build takes a render longer; cache it if that hurts.
328
+ tmp = proj / ".render-tmp"
329
+ tmp.mkdir(exist_ok=True)
330
+ subprocess.run(["npx", "--yes", HF, "render", "--crf", "16", "-o", str(proj / "pass1.mp4")], check=True, cwd=proj, env={**os.environ, "TMPDIR": str(tmp)})
331
+ shutil.rmtree(tmp, ignore_errors=True)
332
+ shutil.rmtree(proj / "renders", ignore_errors=True)
333
+ bridge = vdir / "footage-bridge"
334
+ bridge.mkdir(exist_ok=True)
335
+ (bridge / "words.json").write_text(json.dumps({"segments": [{"words": [{"word": w["w"], "start": w["s"], "end": w["e"]} for w in spoken]}]}, ensure_ascii=False))
336
+ # The film's scenes as the template's, paced like an explainer (or film.json "footage_beats" as written):
337
+ # each scene opens on a headline scene, then picture scenes change at its phrase breaks, about every 2 s.
338
+ (bridge / "images").mkdir(exist_ok=True)
339
+
340
+ def copy_pic(name, staged=None):
341
+ src = proj / staged if staged else next((f for f in (vdir / name, vdir / f"{Path(name).stem}-9x16.jpg") if f.exists()), None)
342
+ if not src:
343
+ sys.exit(f"picture {name!r} not found in {vdir}")
344
+ shutil.copy(src, bridge / "images" / src.name)
345
+ return src.name
346
+
347
+ def headline(text):
348
+ if len(text) > 14: # the template shrinks longer headlines to unreadable sizes
349
+ print(f"warning: headline {text!r} is over 14 characters; shown as the serif line instead")
350
+ return "", text
351
+ return text.upper(), ""
352
+
353
+ mapped, cursor = [], 3.2 # the hook holds the first 3 s
354
+ for i, s in enumerate(scenes):
355
+ start, end = max(s["start"] + pace["lead"], cursor), s["start"] + s["len"]
356
+ if end - start < 0.8:
357
+ continue
358
+ cursor = end
359
+ if s["kind"] == "cta":
360
+ c = film.get("cta") or {}
361
+ mapped.append({"kind": "end", "t": round(start, 3), "title": s.get("title") or c.get("title", ""), "sub": c.get("url") or c.get("sub", "") or s.get("sub", "")})
362
+ continue
363
+ if s.get("items"):
364
+ mapped += [{"kind": "item", "t": round(start + 0.3 + (end - start - 0.6) * k / len(s["items"]), 3), "label": f"{k + 1:02d}", "text": it,
365
+ **({"head": s["title"]} if k == 0 and s.get("title") else {})} for k, it in enumerate(s["items"])]
366
+ continue
367
+ pics = ([copy_pic(beats[i]["img"], beats[i]["img"])] if beats[i].get("img") else []) + [copy_pic(n) for n in s.get("pics", [])]
368
+ head = {"kind": "title", "t": round(start, 3), "kicker": s.get("kick", "")}
369
+ if s["kind"] == "stat" and s.get("stat"):
370
+ st = s["stat"][0]
371
+ head["title"], long = headline(st.get("suffix", "").strip())
372
+ head.update(big=str(st["value"]), sub=" ".join(x for x in (long, st.get("label", "")) if x))
373
+ elif s["kind"] == "question":
374
+ head.update(big="?", sub=s.get("title", ""))
375
+ else:
376
+ head["title"], long = headline(s.get("title", ""))
377
+ head["sub"] = long or s.get("sub", "")
378
+ # Phrase breaks after the headline: a word that starts 1.6 s or more after the last break, sooner at punctuation.
379
+ cuts, last, prev = [], start + min(2.2, end - start), {"w": "-"}
380
+ for w in (w for w in spoken if last + 0.3 < w["s"] < end - 0.8):
381
+ if w["s"] - last >= 2.4 or (w["s"] - last >= 1.6 and prev["w"][-1] in ",.?!;:"):
382
+ cuts.append(w["s"])
383
+ last = w["s"]
384
+ prev = w
385
+ if not pics: # nothing to show between headlines: the headline holds the whole scene
386
+ mapped.append({**head, "dur": round(end - start, 3)})
387
+ continue
388
+ stops = [start + min(2.2, end - start)] + cuts + [end]
389
+ # No picture holds longer than 2.5 s: split a long gap evenly where no phrase break fell.
390
+ stops = [round(a + (b - a) * k / -(-(b - a) // 2.5), 3) for a, b in zip(stops, stops[1:]) for k in range(int(-(-(b - a) // 2.5)))] + [end]
391
+ mapped.append({**head, "dur": round(stops[0] - start, 3), "img": pics[0]})
392
+ mapped += [{"kind": "photo", "t": round(a, 3), "dur": round(b - a, 3), "img": pics[(k + 1) % len(pics)]} for k, (a, b) in enumerate(zip(stops, stops[1:])) if b - a > 0.5]
393
+ first = next((b["img"] for b in mapped if b.get("img")), None)
394
+ if first: # something to look at under the hook
395
+ mapped.insert(0, {"kind": "photo", "t": 0.2, "dur": 2.95, "img": first})
396
+ if film.get("mascot"):
397
+ mapped.append({"kind": "mascot", "t": 0.3, "img": copy_pic(film["mascot"])})
398
+ fb = film.get("footage_beats", mapped)
399
+ for b in film.get("footage_beats", []):
400
+ if b.get("img"):
401
+ copy_pic(b["img"])
402
+ first = [w["w"] for w in spoken]
403
+ hook = film.get("hook") or {"line1": " ".join(first[:3]).upper(), "line2": " ".join(first[3:6]).upper(), "sub": ""}
404
+ own = [f.read_text().strip() for f in [vdir / "CREDITS.txt", *sorted(vdir.glob("CREDITS-*.txt"))] if f.exists()]
405
+ if own: # make_tiktok.py puts the video's own credits first in the render's CREDITS.txt
406
+ (bridge / "CREDITS.txt").write_text("\n\n".join(own) + "\n")
407
+ # One plan segment per scene, back to back over the whole film: the template treats each as a jump cut
408
+ # (card tilt, lists leave), and the last one keeps the tail after the last word.
409
+ (bridge / "plan.json").write_text(json.dumps({"segments": [{"start_time": b["start"], "end_time": b["start"] + b["len"]} for b in beats]}))
410
+ (bridge / "config.json").write_text(json.dumps({"name": film.get("name", vdir.name), "preset": want, "video": str(proj / "pass1.mp4"),
411
+ "words": str(bridge / "words.json"), "plan": str(bridge / "plan.json"), "hook": hook, "music": film.get("music", "sunny"),
412
+ "beats": fb, "card": False, "tail": 1.5 if any(b.get("kind") == "end" for b in fb) else 0}, ensure_ascii=False, indent=1))
413
+ print(f"footage preset {want}: styling pass 1 with make_tiktok.py")
414
+ run("python3", str(SKILL / "scripts/make_tiktok.py"), str(bridge), *(["--render"] if "--render" in sys.argv else []), cwd=WORK)
415
+ elif "--render" in sys.argv:
416
+ run("bash", str(SKILL / "scripts/master.sh"), str(vdir), cwd=WORK)