kasaframe 0.0.0-stage → 0.1.3

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 (442) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +148 -0
  3. package/README.md +92 -2
  4. package/app/package.json +12 -0
  5. package/app/server/engine.ts +533 -0
  6. package/app/server/main.ts +209 -0
  7. package/app/web/env.d.ts +2 -0
  8. package/app/web/icons.ts +31 -0
  9. package/app/web/index.html +21 -0
  10. package/app/web/main.ts +1195 -0
  11. package/app/web/style.css +463 -0
  12. package/bin/hooks.mjs +64 -0
  13. package/bin/kf.mjs +32 -0
  14. package/docs/AGENTS.md +286 -0
  15. package/music/README.md +37 -0
  16. package/package.json +44 -4
  17. package/packages/adapters/package.json +36 -0
  18. package/packages/adapters/src/css.ts +11 -0
  19. package/packages/adapters/src/gsap.ts +26 -0
  20. package/packages/adapters/src/index.ts +9 -0
  21. package/packages/adapters/src/lottie.ts +22 -0
  22. package/packages/adapters/src/media.ts +59 -0
  23. package/packages/adapters/src/page.ts +229 -0
  24. package/packages/adapters/src/project.ts +214 -0
  25. package/packages/adapters/src/react.ts +36 -0
  26. package/packages/adapters/src/svelte.ts +22 -0
  27. package/packages/adapters/src/three.ts +18 -0
  28. package/packages/adapters/src/vue.ts +27 -0
  29. package/packages/check/package.json +19 -0
  30. package/packages/check/src/check.ts +280 -0
  31. package/packages/check/src/cli.ts +70 -0
  32. package/packages/check/src/image.ts +146 -0
  33. package/packages/check/src/index.ts +9 -0
  34. package/packages/check/src/ocr.swift +37 -0
  35. package/packages/check/src/probe.ts +328 -0
  36. package/packages/check/src/report.ts +44 -0
  37. package/packages/check/src/rules/assets.ts +45 -0
  38. package/packages/check/src/rules/beats.ts +212 -0
  39. package/packages/check/src/rules/camera.ts +217 -0
  40. package/packages/check/src/rules/captions.ts +49 -0
  41. package/packages/check/src/rules/flash.ts +235 -0
  42. package/packages/check/src/rules/frames.ts +136 -0
  43. package/packages/check/src/rules/layout.ts +281 -0
  44. package/packages/check/src/rules/page.ts +87 -0
  45. package/packages/check/src/rules/runs.ts +20 -0
  46. package/packages/check/src/rules/text.ts +326 -0
  47. package/packages/check/src/scan.ts +240 -0
  48. package/packages/check/src/serve.ts +67 -0
  49. package/packages/check/src/types.ts +80 -0
  50. package/packages/check/src/video.ts +137 -0
  51. package/packages/cli/package.json +30 -0
  52. package/packages/cli/src/blur.ts +80 -0
  53. package/packages/cli/src/browser.ts +203 -0
  54. package/packages/cli/src/command.ts +44 -0
  55. package/packages/cli/src/commands/app.ts +25 -0
  56. package/packages/cli/src/commands/beats.ts +36 -0
  57. package/packages/cli/src/commands/bench.ts +123 -0
  58. package/packages/cli/src/commands/blender.ts +293 -0
  59. package/packages/cli/src/commands/check.ts +25 -0
  60. package/packages/cli/src/commands/direct.ts +210 -0
  61. package/packages/cli/src/commands/doctor.ts +30 -0
  62. package/packages/cli/src/commands/gen.ts +173 -0
  63. package/packages/cli/src/commands/look.ts +46 -0
  64. package/packages/cli/src/commands/lyrics.ts +157 -0
  65. package/packages/cli/src/commands/make.ts +1121 -0
  66. package/packages/cli/src/commands/music.ts +78 -0
  67. package/packages/cli/src/commands/narrate.ts +238 -0
  68. package/packages/cli/src/commands/new.ts +185 -0
  69. package/packages/cli/src/commands/preview.ts +43 -0
  70. package/packages/cli/src/commands/render.ts +250 -0
  71. package/packages/cli/src/commands/series.ts +110 -0
  72. package/packages/cli/src/commands/setup.ts +102 -0
  73. package/packages/cli/src/commands/sheet.ts +114 -0
  74. package/packages/cli/src/commands/skill.ts +43 -0
  75. package/packages/cli/src/commands/still.ts +40 -0
  76. package/packages/cli/src/commands/theme.ts +172 -0
  77. package/packages/cli/src/commands/transitions.ts +40 -0
  78. package/packages/cli/src/deps.ts +122 -0
  79. package/packages/cli/src/ffmpeg.ts +81 -0
  80. package/packages/cli/src/index.ts +8 -0
  81. package/packages/cli/src/kf.ts +64 -0
  82. package/packages/cli/src/lock.ts +72 -0
  83. package/packages/cli/src/mix.ts +131 -0
  84. package/packages/cli/src/out.ts +13 -0
  85. package/packages/cli/src/pool.ts +34 -0
  86. package/packages/cli/src/segments.ts +402 -0
  87. package/packages/cli/src/serve.ts +124 -0
  88. package/packages/clock/package.json +14 -0
  89. package/packages/clock/src/index.ts +25 -0
  90. package/packages/clock/src/install.ts +351 -0
  91. package/packages/clock/src/types.ts +45 -0
  92. package/packages/core/package.json +9 -0
  93. package/packages/core/src/beats.ts +283 -0
  94. package/packages/core/src/ease.ts +87 -0
  95. package/packages/core/src/frame.ts +99 -0
  96. package/packages/core/src/index.ts +27 -0
  97. package/packages/core/src/project.ts +157 -0
  98. package/packages/core/src/rand.ts +56 -0
  99. package/packages/core/src/spring.ts +52 -0
  100. package/packages/core/src/style.ts +100 -0
  101. package/packages/core/src/time.ts +88 -0
  102. package/packages/director/package.json +23 -0
  103. package/packages/director/src/assemble.ts +361 -0
  104. package/packages/director/src/brief.ts +122 -0
  105. package/packages/director/src/catalog.ts +49 -0
  106. package/packages/director/src/content.ts +343 -0
  107. package/packages/director/src/fallback.ts +58 -0
  108. package/packages/director/src/index.ts +13 -0
  109. package/packages/director/src/pattern.ts +90 -0
  110. package/packages/director/src/patterns/fill/cells.ts +115 -0
  111. package/packages/director/src/patterns/formula/stack.ts +93 -0
  112. package/packages/director/src/patterns/util.ts +58 -0
  113. package/packages/director/src/scene.ts +62 -0
  114. package/packages/director/src/select.ts +163 -0
  115. package/packages/director/src/transitions.ts +115 -0
  116. package/packages/gen/PROVIDERS.md +90 -0
  117. package/packages/gen/package.json +9 -0
  118. package/packages/gen/src/ask.ts +132 -0
  119. package/packages/gen/src/audio.ts +91 -0
  120. package/packages/gen/src/blender.ts +54 -0
  121. package/packages/gen/src/capabilities.ts +151 -0
  122. package/packages/gen/src/generate.ts +206 -0
  123. package/packages/gen/src/image/codex.ts +117 -0
  124. package/packages/gen/src/image/og.ts +133 -0
  125. package/packages/gen/src/index.ts +26 -0
  126. package/packages/gen/src/keys.ts +86 -0
  127. package/packages/gen/src/media.ts +150 -0
  128. package/packages/gen/src/music/elevenlabs.ts +41 -0
  129. package/packages/gen/src/music/index.ts +120 -0
  130. package/packages/gen/src/music/library.ts +73 -0
  131. package/packages/gen/src/music/lyria.ts +52 -0
  132. package/packages/gen/src/music/types.ts +28 -0
  133. package/packages/gen/src/plan.ts +106 -0
  134. package/packages/gen/src/registry.ts +54 -0
  135. package/packages/gen/src/seam.ts +103 -0
  136. package/packages/gen/src/tts/dashscope.ts +64 -0
  137. package/packages/gen/src/tts/elevenlabs.ts +84 -0
  138. package/packages/gen/src/tts/gemini.ts +73 -0
  139. package/packages/gen/src/tts/index.ts +241 -0
  140. package/packages/gen/src/tts/local.ts +42 -0
  141. package/packages/gen/src/tts/types.ts +44 -0
  142. package/packages/gen/src/types.ts +90 -0
  143. package/packages/gen/src/video/fal.ts +140 -0
  144. package/packages/gen/src/video/h3.ts +112 -0
  145. package/packages/gen/src/video/http.ts +44 -0
  146. package/packages/gen/src/video/ltx.ts +60 -0
  147. package/packages/gen/src/video/minimax.ts +55 -0
  148. package/packages/gen/src/video/veo.ts +71 -0
  149. package/packages/jizura/package.json +16 -0
  150. package/packages/jizura/src/deny.ts +73 -0
  151. package/packages/jizura/src/index.ts +7 -0
  152. package/packages/jizura/src/install.ts +269 -0
  153. package/packages/jizura/src/layer.ts +325 -0
  154. package/packages/jizura/src/lyrics.ts +81 -0
  155. package/packages/jizura/src/pin.ts +8 -0
  156. package/packages/jizura/src/vendor.ts +140 -0
  157. package/packages/jizura/src/vite.ts +63 -0
  158. package/packages/jizura/vendor/JIZURA_LICENSE.txt +21 -0
  159. package/packages/jizura/vendor/NOTICE +43 -0
  160. package/packages/jizura/vendor/engine.json +47 -0
  161. package/packages/jizura/vendor/fonts/BlackHanSans-Regular.woff2 +0 -0
  162. package/packages/jizura/vendor/fonts/DotGothic16-Regular.woff2 +0 -0
  163. package/packages/jizura/vendor/fonts/GowunBatang-Bold.woff2 +0 -0
  164. package/packages/jizura/vendor/fonts/IBMPlexMono-Medium.ttf +0 -0
  165. package/packages/jizura/vendor/fonts/IBMPlexMono-SemiBold.ttf +0 -0
  166. package/packages/jizura/vendor/fonts/NotoSansKR-VF.woff2 +0 -0
  167. package/packages/jizura/vendor/fonts/NotoSerifKR-VF.woff2 +0 -0
  168. package/packages/jizura/vendor/fonts/OFL-blackhansans.txt +93 -0
  169. package/packages/jizura/vendor/fonts/OFL-dotgothic16.txt +93 -0
  170. package/packages/jizura/vendor/fonts/OFL-gowunbatang.txt +94 -0
  171. package/packages/jizura/vendor/fonts/OFL-ibmplexmono.txt +93 -0
  172. package/packages/jizura/vendor/fonts/OFL-notosanskr.txt +93 -0
  173. package/packages/jizura/vendor/fonts/OFL-notoserifkr.txt +94 -0
  174. package/packages/jizura/vendor/fonts/fonts.json +52 -0
  175. package/packages/jizura/vendor/jizura_engine.js +35024 -0
  176. package/packages/motion/README.md +153 -0
  177. package/packages/motion/package.json +30 -0
  178. package/packages/motion/src/camera.ts +97 -0
  179. package/packages/motion/src/captions.ts +487 -0
  180. package/packages/motion/src/enter.ts +128 -0
  181. package/packages/motion/src/hangul.ts +129 -0
  182. package/packages/motion/src/impact.ts +100 -0
  183. package/packages/motion/src/index.ts +17 -0
  184. package/packages/motion/src/moves/brushWipe.ts +103 -0
  185. package/packages/motion/src/moves/cloneArray.ts +111 -0
  186. package/packages/motion/src/moves/curtains.ts +81 -0
  187. package/packages/motion/src/moves/dress.ts +191 -0
  188. package/packages/motion/src/moves/echoStack.ts +70 -0
  189. package/packages/motion/src/moves/fit.ts +70 -0
  190. package/packages/motion/src/moves/flood.ts +61 -0
  191. package/packages/motion/src/moves/ghostStack.ts +88 -0
  192. package/packages/motion/src/moves/gridFloor.ts +100 -0
  193. package/packages/motion/src/moves/imageSwarm.ts +113 -0
  194. package/packages/motion/src/moves/index.ts +38 -0
  195. package/packages/motion/src/moves/irisBlades.ts +113 -0
  196. package/packages/motion/src/moves/karaokeLine.ts +108 -0
  197. package/packages/motion/src/moves/ledBoard.ts +94 -0
  198. package/packages/motion/src/moves/liquidTab.ts +72 -0
  199. package/packages/motion/src/moves/markerWrite.ts +63 -0
  200. package/packages/motion/src/moves/menu.ts +138 -0
  201. package/packages/motion/src/moves/morphBox.ts +96 -0
  202. package/packages/motion/src/moves/neonSign.ts +78 -0
  203. package/packages/motion/src/moves/panelPop.ts +78 -0
  204. package/packages/motion/src/moves/paperTear.ts +75 -0
  205. package/packages/motion/src/moves/path.ts +64 -0
  206. package/packages/motion/src/moves/pathText.ts +107 -0
  207. package/packages/motion/src/moves/pointSphere.ts +109 -0
  208. package/packages/motion/src/moves/ransomLetters.ts +73 -0
  209. package/packages/motion/src/moves/shapeMorph.ts +143 -0
  210. package/packages/motion/src/moves/slamWords.ts +96 -0
  211. package/packages/motion/src/moves/sparkTrail.ts +130 -0
  212. package/packages/motion/src/moves/speedLines.ts +91 -0
  213. package/packages/motion/src/moves/splitFlap.ts +149 -0
  214. package/packages/motion/src/moves/stepWords.ts +128 -0
  215. package/packages/motion/src/moves/strikeOut.ts +98 -0
  216. package/packages/motion/src/moves/sunburst.ts +58 -0
  217. package/packages/motion/src/moves/tickerRows.ts +91 -0
  218. package/packages/motion/src/moves/tokenPicker.ts +115 -0
  219. package/packages/motion/src/moves/truchet.ts +85 -0
  220. package/packages/motion/src/moves/wordWall.ts +78 -0
  221. package/packages/motion/src/moves/worldRoll.ts +32 -0
  222. package/packages/motion/src/particles.ts +102 -0
  223. package/packages/motion/src/react/index.tsx +21 -0
  224. package/packages/motion/src/react/parts.tsx +431 -0
  225. package/packages/motion/src/react/time.tsx +97 -0
  226. package/packages/motion/src/text.ts +103 -0
  227. package/packages/motion/src/transition.ts +82 -0
  228. package/packages/motion/src/transition3d/cards.ts +65 -0
  229. package/packages/motion/src/transition3d/chain.ts +84 -0
  230. package/packages/motion/src/transition3d/dive.ts +181 -0
  231. package/packages/motion/src/transition3d/fold.ts +110 -0
  232. package/packages/motion/src/transition3d/gl.ts +219 -0
  233. package/packages/motion/src/transition3d/index.ts +235 -0
  234. package/packages/motion/src/transition3d/live.ts +70 -0
  235. package/packages/motion/src/transition3d/portal.ts +115 -0
  236. package/packages/motion/src/transition3d/react.tsx +29 -0
  237. package/packages/motion/src/transition3d/rig.ts +600 -0
  238. package/packages/motion/src/transition3d/shatter.ts +104 -0
  239. package/packages/motion/src/transition3d/space.ts +173 -0
  240. package/packages/motion/src/transition3d/whip.ts +78 -0
  241. package/packages/motion/src/transition3d/world.ts +737 -0
  242. package/packages/motion/src/transition3d/zoomOut.ts +114 -0
  243. package/packages/motion/src/transitions2d/catalog.ts +127 -0
  244. package/packages/motion/src/transitions2d/css.d.ts +2 -0
  245. package/packages/motion/src/transitions2d/cult-ui/LICENSE.md +9 -0
  246. package/packages/motion/src/transitions2d/cult-ui/RollingNumber.tsx +43 -0
  247. package/packages/motion/src/transitions2d/gl-transitions/LICENSE +25 -0
  248. package/packages/motion/src/transitions2d/gl-transitions/shaders.ts +1931 -0
  249. package/packages/motion/src/transitions2d/index.ts +2 -0
  250. package/packages/motion/src/transitions2d/kokonutui/LICENSE +21 -0
  251. package/packages/motion/src/transitions2d/kokonutui/MatrixText.css +16 -0
  252. package/packages/motion/src/transitions2d/kokonutui/MatrixText.tsx +94 -0
  253. package/packages/motion/src/transitions2d/magicui/HyperText.css +15 -0
  254. package/packages/motion/src/transitions2d/magicui/HyperText.tsx +115 -0
  255. package/packages/motion/src/transitions2d/magicui/LICENSE.md +21 -0
  256. package/packages/motion/src/transitions2d/magicui/MorphingText.css +25 -0
  257. package/packages/motion/src/transitions2d/magicui/MorphingText.tsx +130 -0
  258. package/packages/motion/src/transitions2d/magicui/WordRotate.tsx +42 -0
  259. package/packages/motion/src/transitions2d/react.ts +13 -0
  260. package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.css +39 -0
  261. package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.tsx +32 -0
  262. package/packages/motion/src/transitions2d/smoothui/LICENSE +21 -0
  263. package/packages/motion/src/transitions2d/smoothui/SharedAxisY.tsx +50 -0
  264. package/packages/motion/src/transitions2d/smoothui/TextMorph.tsx +90 -0
  265. package/packages/motion/src/transitions2d/smoothui/shaders.ts +223 -0
  266. package/packages/motion/src/transitions2d/unlumen/LICENSE +21 -0
  267. package/packages/motion/src/transitions2d/unlumen/ScrambleText.tsx +114 -0
  268. package/packages/motion/src/transitions2d/vengeance-ui/LICENSE +21 -0
  269. package/packages/motion/src/transitions2d/vengeance-ui/MorphText.css +69 -0
  270. package/packages/motion/src/transitions2d/vengeance-ui/MorphText.tsx +45 -0
  271. package/packages/motion/src/type.ts +131 -0
  272. package/packages/motion/src/ui.ts +172 -0
  273. package/packages/patterns/package.json +15 -0
  274. package/packages/patterns/src/bars/rank.ts +119 -0
  275. package/packages/patterns/src/before-after/shrink.ts +127 -0
  276. package/packages/patterns/src/before-after/strike.ts +125 -0
  277. package/packages/patterns/src/code/terminal.ts +133 -0
  278. package/packages/patterns/src/compare/bars.ts +142 -0
  279. package/packages/patterns/src/compare/duel.ts +103 -0
  280. package/packages/patterns/src/end/lockup.ts +85 -0
  281. package/packages/patterns/src/end/slam.ts +91 -0
  282. package/packages/patterns/src/flow/graph.ts +250 -0
  283. package/packages/patterns/src/hook-number/counter.ts +101 -0
  284. package/packages/patterns/src/hook-number/roll.ts +179 -0
  285. package/packages/patterns/src/hook-number/slam.ts +91 -0
  286. package/packages/patterns/src/index.ts +38 -0
  287. package/packages/patterns/src/kit.ts +449 -0
  288. package/packages/patterns/src/limit/gauge.ts +117 -0
  289. package/packages/patterns/src/list/cards.ts +131 -0
  290. package/packages/patterns/src/list/cycle.ts +22 -0
  291. package/packages/patterns/src/media/panels.ts +100 -0
  292. package/packages/patterns/src/objects.ts +234 -0
  293. package/packages/patterns/src/quote/karaoke.ts +126 -0
  294. package/packages/patterns/src/quote/slam.ts +22 -0
  295. package/packages/patterns/src/screen/focus.ts +85 -0
  296. package/packages/patterns/src/steps/path.ts +137 -0
  297. package/packages/patterns/src/steps/stack.ts +111 -0
  298. package/packages/patterns/src/term-reveal/chips.ts +92 -0
  299. package/packages/patterns/src/term-reveal/expand.ts +127 -0
  300. package/packages/patterns/src/timeline/axis.ts +144 -0
  301. package/packages/patterns/src/title/mask.ts +85 -0
  302. package/packages/patterns/src/title/slam.ts +23 -0
  303. package/packages/patterns/src/toggle-sim/switch.ts +92 -0
  304. package/packages/patterns/src/trend/columns.ts +108 -0
  305. package/packages/patterns/src/trend/draw.ts +140 -0
  306. package/packages/patterns/src/types.ts +67 -0
  307. package/packages/patterns/src/words/moves.ts +42 -0
  308. package/packages/patterns/src/words/slam.ts +4 -0
  309. package/packages/plan/package.json +15 -0
  310. package/packages/plan/src/asks.ts +256 -0
  311. package/packages/plan/src/brief.ts +383 -0
  312. package/packages/plan/src/captions.ts +78 -0
  313. package/packages/plan/src/detect.ts +93 -0
  314. package/packages/plan/src/index.ts +27 -0
  315. package/packages/plan/src/layout.ts +176 -0
  316. package/packages/plan/src/llm.ts +172 -0
  317. package/packages/plan/src/look.ts +222 -0
  318. package/packages/plan/src/plan.ts +179 -0
  319. package/packages/plan/src/request.ts +55 -0
  320. package/packages/plan/src/series.ts +76 -0
  321. package/packages/plan/src/studio.ts +53 -0
  322. package/packages/plan/src/templates.ts +42 -0
  323. package/packages/plan/src/themes.ts +48 -0
  324. package/packages/plan/src/types.ts +157 -0
  325. package/packages/studio/package.json +12 -0
  326. package/packages/studio/src/index.ts +1 -0
  327. package/packages/studio/src/plugin.ts +236 -0
  328. package/packages/studio/src/ui/main.ts +503 -0
  329. package/packages/studio/src/ui/studio.css +165 -0
  330. package/packages/studio/src/ui/timeline.ts +317 -0
  331. package/packages/themes/kit/THEME-MAKE.md +68 -0
  332. package/packages/themes/kit/THEME.md +30 -0
  333. package/packages/themes/kit/briefs/og-intro-15s/brief.json +16 -0
  334. package/packages/themes/kit/briefs/og-intro-15s/facts.ts +29 -0
  335. package/packages/themes/kit/briefs/og-intro-15s/logo.svg +12 -0
  336. package/packages/themes/kit/effects.ts +5 -0
  337. package/packages/themes/kit/sample/index.html +11 -0
  338. package/packages/themes/kit/sample/main.ts +9 -0
  339. package/packages/themes/kit/sample/scenes/scene.ts +15 -0
  340. package/packages/themes/package.json +19 -0
  341. package/packages/themes/src/factory.ts +296 -0
  342. package/packages/themes/src/fx.ts +14 -0
  343. package/packages/themes/src/index.ts +114 -0
  344. package/packages/themes/src/slotkit.ts +79 -0
  345. package/packages/themes/src/slots.ts +46 -0
  346. package/packages/themes/src/stage3d.ts +197 -0
  347. package/packages/themes/src/types.ts +58 -0
  348. package/presets/kawaii-pastel.json +94 -0
  349. package/presets/neutral-dark.json +82 -0
  350. package/presets/og.json +98 -0
  351. package/series/og-shorts.json +14 -0
  352. package/skills/kasaframe/SKILL.md +33 -0
  353. package/templates/_shared/project/index.html +11 -0
  354. package/templates/_shared/project/lib/react.ts +22 -0
  355. package/templates/_shared/project/lib/stage.ts +292 -0
  356. package/templates/_shared/project/main.ts +9 -0
  357. package/templates/_shared/scenes/default.ts +21 -0
  358. package/templates/_shared/scenes/drop.ts +33 -0
  359. package/templates/_shared/scenes/end.ts +26 -0
  360. package/templates/_shared/scenes/hook.ts +18 -0
  361. package/templates/_shared/scenes/seam.ts +41 -0
  362. package/templates/_shared/scenes/step.ts +49 -0
  363. package/templates/ad/preview.png +0 -0
  364. package/templates/ad/template.json +151 -0
  365. package/templates/demo/preview.png +0 -0
  366. package/templates/demo/template.json +141 -0
  367. package/templates/explainer/preview.png +0 -0
  368. package/templates/explainer/template.json +193 -0
  369. package/templates/launch/preview.png +0 -0
  370. package/templates/launch/template.json +163 -0
  371. package/templates/mv/preview.png +0 -0
  372. package/templates/mv/scenes/default.ts +98 -0
  373. package/templates/mv/template.json +178 -0
  374. package/templates/promo/preview.png +0 -0
  375. package/templates/promo/template.json +185 -0
  376. package/templates/shorts/preview.png +0 -0
  377. package/templates/shorts/scenes/hook.ts +37 -0
  378. package/templates/shorts/template.json +196 -0
  379. package/templates/square/preview.png +0 -0
  380. package/templates/square/template.json +133 -0
  381. package/themes/debug-hud/THEME.md +39 -0
  382. package/themes/debug-hud/effects.ts +389 -0
  383. package/themes/debug-hud/sample/assets/og/logo.svg +12 -0
  384. package/themes/debug-hud/sample/beats.json +1 -0
  385. package/themes/debug-hud/sample/index.html +11 -0
  386. package/themes/debug-hud/sample/kf.json +59 -0
  387. package/themes/debug-hud/sample/lib/hudkit.ts +49 -0
  388. package/themes/debug-hud/sample/lib/og.ts +29 -0
  389. package/themes/debug-hud/sample/main.ts +9 -0
  390. package/themes/debug-hud/sample/scenes/end.ts +62 -0
  391. package/themes/debug-hud/sample/scenes/gather.ts +67 -0
  392. package/themes/debug-hud/sample/scenes/models.ts +70 -0
  393. package/themes/debug-hud/sample/scenes/price.ts +79 -0
  394. package/themes/debug-hud/sample/style.json +91 -0
  395. package/themes/debug-hud/slots.ts +99 -0
  396. package/themes/debug-hud/still.png +0 -0
  397. package/themes/debug-hud/style.json +91 -0
  398. package/themes/debug-hud/theme.json +68 -0
  399. package/themes/og-measure/THEME.md +47 -0
  400. package/themes/og-measure/effects.ts +432 -0
  401. package/themes/og-measure/sample/assets/brand/og-logo-full.svg +12 -0
  402. package/themes/og-measure/sample/assets/brand/og-logo.svg +12 -0
  403. package/themes/og-measure/sample/assets/data/measure.json +353 -0
  404. package/themes/og-measure/sample/beats.json +1 -0
  405. package/themes/og-measure/sample/index.html +11 -0
  406. package/themes/og-measure/sample/kf.json +66 -0
  407. package/themes/og-measure/sample/lib/data.ts +62 -0
  408. package/themes/og-measure/sample/main.ts +9 -0
  409. package/themes/og-measure/sample/measure.ts +78 -0
  410. package/themes/og-measure/sample/scenes/end.ts +47 -0
  411. package/themes/og-measure/sample/scenes/gather.ts +51 -0
  412. package/themes/og-measure/sample/scenes/models.ts +34 -0
  413. package/themes/og-measure/sample/scenes/one.ts +39 -0
  414. package/themes/og-measure/sample/scenes/price.ts +56 -0
  415. package/themes/og-measure/sample/style.json +97 -0
  416. package/themes/og-measure/slots.ts +88 -0
  417. package/themes/og-measure/still.png +0 -0
  418. package/themes/og-measure/style.json +97 -0
  419. package/themes/og-measure/theme.json +79 -0
  420. package/themes/riso-zine/THEME.md +43 -0
  421. package/themes/riso-zine/effects.ts +321 -0
  422. package/themes/riso-zine/sample/assets/og/logo.svg +12 -0
  423. package/themes/riso-zine/sample/beats.json +1 -0
  424. package/themes/riso-zine/sample/index.html +11 -0
  425. package/themes/riso-zine/sample/kf.json +59 -0
  426. package/themes/riso-zine/sample/lib/og.ts +29 -0
  427. package/themes/riso-zine/sample/lib/shot.ts +86 -0
  428. package/themes/riso-zine/sample/lib/zine.ts +42 -0
  429. package/themes/riso-zine/sample/main.ts +9 -0
  430. package/themes/riso-zine/sample/scenes/end.ts +61 -0
  431. package/themes/riso-zine/sample/scenes/gather.ts +62 -0
  432. package/themes/riso-zine/sample/scenes/models.ts +52 -0
  433. package/themes/riso-zine/sample/scenes/price.ts +82 -0
  434. package/themes/riso-zine/sample/style.json +99 -0
  435. package/themes/riso-zine/slots.ts +81 -0
  436. package/themes/riso-zine/still.png +0 -0
  437. package/themes/riso-zine/style.json +99 -0
  438. package/themes/riso-zine/theme.json +75 -0
  439. package/tools/beats/beats.py +372 -0
  440. package/tools/beats/requirements.txt +3 -0
  441. package/tools/lyrics/align.py +164 -0
  442. package/tools/lyrics/requirements.txt +9 -0
@@ -0,0 +1,361 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { dressSeed, type Dress } from "@kasaframe/motion/menu";
5
+ import { loadTemplate, sceneSkeleton, type Template } from "@kasaframe/plan";
6
+ import { catalog } from "./catalog.ts";
7
+ import { TYPES, type Content, type Scene, type SceneType } from "./content.ts";
8
+ import type { AspectName, Energy, TextPolicy } from "./pattern.ts";
9
+ import { type Entry, type Pick, repick, selectAll, type Slot } from "./select.ts";
10
+ import { type BeatsLite, cyclingText, dressAll, energyOf, seamKinds, seamSpots, type Spot } from "./transitions.ts";
11
+
12
+ // content.json → 장면 시간표·장면 파일. 두 단계로 나뉜다 — 그 사이에 kf narrate 가 목소리로 장면 길이를 정한다.
13
+ // 1. layout: 내용 장면 + 이음매를 kf.json 에 놓고 들릴 말을 captions.json 에(길이는 어림)
14
+ // 2. build: 정해진 길이·곡 구간으로 패턴을 고르고 장면 파일·director.json 을 쓴다(LLM 없이 템플릿 조립)
15
+ // 같은 content.json·틀·테마·씨앗이면 쓰는 파일이 바이트까지 같다 — 시각·경로·난수 없이 씨앗으로만 고른다.
16
+
17
+ export const MARK = "// kf direct 가 지은 장면";
18
+ // kf new 뼈대(무대·이음매) — 감독이 처음 들어설 때 지워도 되는 파일
19
+ const SKELETON = /makeStage\(root, ctx, \{ dress: DRESS \}\)|transition3d\(root, ctx, \{ kind: KIND/;
20
+
21
+ interface KfScene {
22
+ id: string;
23
+ from: number;
24
+ dur: number;
25
+ file: string;
26
+ role: string;
27
+ idea: string;
28
+ type?: SceneType;
29
+ space?: "2d" | "3d";
30
+ pattern?: string;
31
+ transition?: string;
32
+ dress?: Dress;
33
+ [k: string]: unknown;
34
+ }
35
+
36
+ const readJson = <T = any>(p: string): T => JSON.parse(readFileSync(p, "utf8"));
37
+ const writeJson = (p: string, v: unknown) => writeFileSync(p, `${JSON.stringify(v, null, 2)}\n`);
38
+
39
+ // say 가 없을 때 장면 길이 — 숫자·이름 하나는 짧게, 구조를 보이는 것은 길게
40
+ const TYPE_SEC: Partial<Record<SceneType, number>> = { "hook-number": 3, title: 2.5, words: 2.5, end: 2.5, quote: 4, limit: 3, "term-reveal": 3.5 };
41
+ const CHARS_PER_SEC = 4.5;
42
+
43
+ function roleOf(s: Scene, i: number): string {
44
+ if (s.type === "end") return "end";
45
+ if (i === 0) return "hook";
46
+ if (s.type === "term-reveal" || s.type === "title") return "reveal";
47
+ if (s.type === "limit") return "limit";
48
+ return "explain";
49
+ }
50
+
51
+ const spaceOf = (s: { space?: string }): "2d" | "3d" => (s.space === "3d" ? "3d" : "2d");
52
+
53
+ export function contentHash(c: Content): string {
54
+ return createHash("sha256").update(JSON.stringify(c)).digest("hex").slice(0, 16);
55
+ }
56
+
57
+ /** 1단계 — 내용 장면과 이음매를 시간표에. 길이는 어림(kf narrate 가 목소리로 고친다) */
58
+ export function layout(dir: string, content: Content, o: { keepTiming?: boolean } = {}): { scenes: KfScene[]; seams: number } {
59
+ const kfPath = join(dir, "kf.json");
60
+ const kf = readJson(kfPath);
61
+ const tpl = loadTemplate(kf.template);
62
+ const fps: number = kf.fps;
63
+ const frame = (x: number) => Math.max(1, Math.round(x * fps)) / fps;
64
+ const n = tpl.narration ?? { lead: 0.25, tail: 0.5 };
65
+ // keepTiming(kf narrate 를 건너뛸 때) — 같은 장면(id·type)에 들릴 말도 같으면 앞 길이(목소리로 잰 것)를 그대로 둔다.
66
+ // 내레이션을 다시 돌릴 땐 늘 어림에서 시작한다 — 말 없는 장면·이음매에 앞 실행의 길이가 남으면 같은 content.json 이 다른 시간표를 낸다
67
+ const capPath = join(dir, "captions.json");
68
+ const oldCaps: { scene: string; text: string; from?: number }[] = existsSync(capPath) ? readJson(capPath) : [];
69
+ const said = (id: string) => oldCaps.filter((l) => l.scene === id).map((l) => l.text.trim()).join(" ");
70
+ const oldScenes = new Map<string, KfScene>((kf.scenes ?? []).map((x: KfScene) => [x.id, x]));
71
+ const est = (s: Scene) => {
72
+ const old = oldScenes.get(s.id);
73
+ if (o.keepTiming && old && old.type === s.type && said(s.id) === (s.say?.trim() ?? "")) return old.dur;
74
+ return s.say ? n.lead + [...s.say].length / CHARS_PER_SEC + n.tail : (s.dur ?? TYPE_SEC[s.type] ?? 5);
75
+ };
76
+
77
+ const tplSeams = tpl.scenes.filter((s) => s.role === "seam");
78
+ const seamSec = tplSeams[0]?.sec ?? 1.2;
79
+ // 투영을 맞춰 구운 3D 샷(kf blender 가 kf.json 장면에 남긴 matched)은 다시 놓아도 잃지 않는다
80
+ const matched = new Set<string>((kf.scenes ?? []).filter((s: KfScene) => s.matched).map((s: KfScene) => s.id));
81
+ const spots = seamSpots(content.scenes.map((s) => s.type), content.scenes.map(spaceOf), tplSeams.length, content.scenes.map((s) => matched.has(s.id)));
82
+ const taken = new Set(content.scenes.map((s) => s.id));
83
+ const seamIds: string[] = [];
84
+ for (let k = 0; seamIds.length < spots.length; k++) {
85
+ const id = tplSeams[k]?.id ?? `seam-${k + 1}`;
86
+ if (!taken.has(id) && !seamIds.includes(id)) seamIds.push(id);
87
+ }
88
+ const scenes: KfScene[] = [];
89
+ let t = 0;
90
+ const put = (s: { id: string; role: string; dur: number; idea: string; [k: string]: unknown }) => {
91
+ const dur = frame(s.dur);
92
+ scenes.push({ ...s, from: +t.toFixed(4), dur: +dur.toFixed(4), file: `scenes/${s.id}.ts` });
93
+ t += dur;
94
+ };
95
+ for (const [i, s] of content.scenes.entries()) {
96
+ const sp = spots.findIndex((x) => x.at === i);
97
+ // 이음매도 앞 길이(박에 붙인 것)를 그대로 — 안 그러면 뒤 장면 시각이 다 밀린다
98
+ if (sp >= 0) put({ id: seamIds[sp], role: "seam", dur: o.keepTiming && oldScenes.get(seamIds[sp])?.role === "seam" ? oldScenes.get(seamIds[sp])!.dur : seamSec, idea: spots[sp].bridge ? "공간 잇기 — 2D 와 3D 장면 사이(감독이 고른 전환)" : "이음매 — 감독이 고른 3D 전환", ...(spots[sp].bridge ? { bridge: spots[sp].bridge } : {}) });
99
+ put({ id: s.id, role: roleOf(s, i), dur: est(s), idea: s.type === "custom" ? String(s.idea ?? "") : `${s.type} — ${TYPES[s.type].does}`, type: s.type, ...(s.space ? { space: s.space } : {}), ...(matched.has(s.id) ? { matched: true } : {}) });
100
+ }
101
+ kf.title = content.title;
102
+ kf.scenes = scenes;
103
+ kf.duration = +t.toFixed(4);
104
+ writeJson(kfPath, kf);
105
+
106
+ // 낱말 시각(kf narrate 가 단 것)은 말이 같으면 남긴다
107
+ const lines = content.scenes.filter((s) => s.say?.trim()).map((s) => oldCaps.find((l) => l.scene === s.id && l.text.trim() === s.say!.trim() && l.from !== undefined) ?? { scene: s.id, text: s.say!.trim() });
108
+ if (lines.length) writeJson(capPath, lines);
109
+ const planPath = join(dir, "plan.json");
110
+ if (existsSync(planPath)) {
111
+ const plan = readJson(planPath);
112
+ plan.title = content.title;
113
+ plan.duration = kf.duration;
114
+ plan.scenes = scenes.map((s) => ({ id: s.id, role: s.role, from: s.from, dur: s.dur, idea: s.idea, assets: [] }));
115
+ const end = content.scenes.find((s) => s.type === "end");
116
+ if (typeof end?.line === "string") plan.line = end.line;
117
+ writeJson(planPath, plan);
118
+ }
119
+ return { scenes, seams: spots.length };
120
+ }
121
+
122
+ export interface BuildOpts {
123
+ seed?: string;
124
+ /** 장면 id → kf check 에서 떨어진 패턴 id */
125
+ failed?: Record<string, string[]>;
126
+ /** 이음매 장면 id → 떨어진 전환 종류 */
127
+ seamFailed?: Record<string, string[]>;
128
+ entries?: Entry[];
129
+ /** 이 장면만 다시 짓는다 — 나머지 장면 파일·고름·이음매는 손대지 않는다(조각 렌더가 바뀐 장면만 다시 굽게) */
130
+ only?: string[];
131
+ /** 사람이 고른 것 — 장면 id → 패턴 id·장면 씨앗. director.json 의 pinned 에 남아 다음 kf direct 가 덮지 않는다 */
132
+ pins?: Record<string, Pin>;
133
+ /** 장면마다 진행 줄(「장면 <id>: 쓰는 중|씀|실패 <까닭>」 — 굽기·검사까지 끝난 「끝」은 작업실·render 몫) */
134
+ log?: (line: string) => void;
135
+ }
136
+
137
+ export interface Pin {
138
+ pattern?: string;
139
+ seed?: string;
140
+ }
141
+
142
+ export interface SceneReport {
143
+ id: string;
144
+ role: string;
145
+ from: number;
146
+ dur: number;
147
+ type?: string;
148
+ energy?: Energy;
149
+ pattern?: string;
150
+ transition?: string;
151
+ dress?: Dress;
152
+ custom?: "kept" | "skeleton";
153
+ order?: { id: string; score: number; why: string[] }[];
154
+ rejected?: { id: string; why: string }[];
155
+ attempt?: number;
156
+ /** 그 장면 내용의 해시 — 안 바뀐 장면은 고름을 그대로 둔다 */
157
+ hash?: string;
158
+ }
159
+
160
+ export interface Report {
161
+ version: 1;
162
+ seed: string;
163
+ key: string;
164
+ content: string;
165
+ purpose: string;
166
+ theme: string | null;
167
+ aspect: AspectName;
168
+ scenes: SceneReport[];
169
+ failed: Record<string, string[]>;
170
+ seamFailed: Record<string, string[]>;
171
+ pinned: Record<string, Pin>;
172
+ }
173
+
174
+ const aspectOf = (w: number, h: number): AspectName => (w > h ? "16:9" : w < h ? "9:16" : "1:1");
175
+
176
+ function fill(src: string, vars: Record<string, string>): string {
177
+ return src.replace(/\{\{(\w+)\}\}/g, (_, k) => (vars[k] ?? "").replace(/["\\]/g, "\\$&"));
178
+ }
179
+
180
+ /** 장면에서 패턴에 넘길 내용 — 장면 칸(id·type·say·dur·space)을 뺀 나머지 */
181
+ function payload(s: Scene): Record<string, unknown> {
182
+ const { id: _i, type: _t, say: _s, dur: _d, space: _p, ...rest } = s;
183
+ return rest;
184
+ }
185
+
186
+ const sceneHash = (s: Scene): string => createHash("sha256").update(JSON.stringify([s.type, payload(s)])).digest("hex").slice(0, 12);
187
+
188
+ function patternFile(spec: string, d: Record<string, unknown>): string {
189
+ return `${MARK} — 정본은 content.json 이다. 고치려면 content.json 을 고치고 kf direct 를 다시 부른다(이 파일은 덮인다).
190
+ import pattern from "${spec}";
191
+ import { directed } from "@kasaframe/director/scene";
192
+ import { makeStage } from "../lib/stage.ts";
193
+
194
+ const captions = import.meta.glob("../captions.json", { eager: true, import: "default" });
195
+
196
+ export default directed(pattern, ${JSON.stringify(d, null, 2)}, { makeStage, captions });
197
+ `;
198
+ }
199
+
200
+ /** 2단계 — 패턴·전환·바탕을 고르고 장면 파일을 쓴다 */
201
+ export async function build(dir: string, content: Content, o: BuildOpts = {}): Promise<Report> {
202
+ const kf = readJson(join(dir, "kf.json"));
203
+ const plan = existsSync(join(dir, "plan.json")) ? readJson(join(dir, "plan.json")) : {};
204
+ const tpl: Template = loadTemplate(kf.template);
205
+ const entries = o.entries ?? (await catalog());
206
+ const beats: BeatsLite | null = kf.beats && existsSync(join(dir, kf.beats)) ? readJson(join(dir, kf.beats)) : null;
207
+ const theme: string | null = kf.theme ?? null;
208
+ const purpose: string = kf.template;
209
+ const aspect = aspectOf(kf.width, kf.height);
210
+ const policy: TextPolicy = kf.text?.policy ?? tpl.text.policy;
211
+ const seed = o.seed ?? content.seed ?? "0";
212
+ const key = dressSeed(content.title, purpose, theme ?? plan.style, seed);
213
+ const hash = contentHash(content);
214
+ const scenes: KfScene[] = kf.scenes;
215
+ const byId = new Map(content.scenes.map((s) => [s.id, s]));
216
+
217
+ const prevPath = join(dir, "director.json");
218
+ const prev: Report | null = existsSync(prevPath) ? readJson(prevPath) : null;
219
+ // 씨앗 열쇠가 같고 내용이 같은 장면만 앞 기록(떨어진 패턴·핀)을 이어 간다
220
+ const same = !!prev && prev.key === key;
221
+ const prevHash = new Map((same ? prev.scenes : []).map((x) => [x.id, x.hash]));
222
+ const unchanged = (id: string) => byId.has(id) && prevHash.get(id) === sceneHash(byId.get(id)!);
223
+ // 떨어진 기록은 「패턴 id@판」 — 그 패턴이 그 뒤 고쳐졌으면(판이 다르면) 다시 후보로 돌아온다
224
+ const revOf = new Map(entries.map((e) => [e.meta.id, e.rev ?? ""]));
225
+ const tag = (id: string) => `${id}@${revOf.get(id) ?? ""}`;
226
+ const stored: Record<string, string[]> = {};
227
+ for (const [id, list] of Object.entries(same ? prev.failed : {})) if (unchanged(id)) stored[id] = list.filter((x) => x.includes("@") && revOf.has(x.slice(0, x.indexOf("@"))) && x === tag(x.slice(0, x.indexOf("@"))));
228
+ for (const [id, list] of Object.entries(o.failed ?? {})) stored[id] = [...new Set([...(stored[id] ?? []), ...list.map(tag)])];
229
+ const failed: Record<string, string[]> = Object.fromEntries(Object.entries(stored).filter(([, l]) => l.length).map(([id, l]) => [id, l.map((x) => x.slice(0, x.indexOf("@")))]));
230
+ const seamFailed = { ...(same ? prev.seamFailed : {}), ...o.seamFailed };
231
+ const pinned: Record<string, Pin> = { ...(same ? (prev.pinned ?? {}) : {}) };
232
+ for (const [id, p] of Object.entries(o.pins ?? {})) pinned[id] = { ...pinned[id], ...p };
233
+ const only = o.only ? new Set(o.only) : null;
234
+ for (const id of only ?? []) if (!scenes.some((s) => s.id === id)) throw new Error(`--scenes: 시간표에 없는 장면 ${id}`);
235
+
236
+ // 패턴 자리
237
+ const slotScenes = scenes.filter((s) => s.role !== "seam" && s.type && s.type !== "custom");
238
+ const slots: Slot[] = slotScenes.map((s) => ({ id: s.id, type: s.type!, content: payload(byId.get(s.id)!), dur: s.dur, energy: energyOf(beats, s.from, s.dur, s === scenes[0]) }));
239
+ const ctx = { aspect, purpose, theme, policy, seed: key };
240
+ const entryOf = new Map(entries.map((e) => [e.meta.id, e]));
241
+ const prevOf = new Map((same ? prev.scenes : []).filter((s) => s.pattern).map((s) => [s.id, s]));
242
+ // 전체 짓기는 늘 처음부터 같은 길(selectAll) — 고름이 (내용·씨앗·떨어진 기록)에만 달려 앞 실행의 이력이 안 남는다.
243
+ // 고른 장면만(only)일 때만 앞 고름을 핀으로 두고 그 장면만 앞뒤와 다시 따진다
244
+ let picks: Pick[];
245
+ if (only && slots.every((s) => prevOf.has(s.id))) {
246
+ picks = slots.map((s) => {
247
+ const p = prevOf.get(s.id)!;
248
+ return { scene: s.id, pattern: p.pattern!, order: p.order ?? [], rejected: p.rejected ?? [], attempt: (failed[s.id] ?? []).length };
249
+ });
250
+ for (const [i, s] of slots.entries()) {
251
+ if (!only.has(s.id)) continue;
252
+ const r = repick(picks, i, slots, entries, ctx, failed[s.id] ?? []);
253
+ if (!r) throw new Error(`장면 ${s.id}: 남은 패턴 후보가 없다 — 떨어진 것 ${(failed[s.id] ?? []).join(", ")}`);
254
+ picks[i] = r;
255
+ }
256
+ } else picks = selectAll(slots, entries, ctx, failed);
257
+ // 사람이 고른 패턴이 이긴다 — 그 type 의 패턴이어야 한다
258
+ for (const [i, s] of slots.entries()) {
259
+ const want = pinned[s.id]?.pattern;
260
+ if (!want || picks[i].pattern === want) continue;
261
+ const e = entryOf.get(want);
262
+ if (!e || (!e.fallback && e.meta.type !== s.type)) throw new Error(`--pattern ${s.id}=${want}: ${e ? `${s.type} 장면에 ${e.meta.type} 패턴` : "없는 패턴"} — 후보는 director.json 의 order`);
263
+ picks[i] = { ...picks[i], pattern: want };
264
+ }
265
+ const pickOf = new Map(picks.map((p) => [p.scene, p]));
266
+
267
+ // 이음매 종류 — 2D↔3D 경계는 공간 잇기
268
+ const seamIdx = scenes.flatMap((s, i) => (s.role === "seam" ? [i] : []));
269
+ const spots: Spot[] = seamIdx.map((i) => {
270
+ const a = spaceOf(scenes[i - 1] ?? {});
271
+ const b = spaceOf(scenes[i + 1] ?? {});
272
+ return { at: i, bridge: a === b ? false : b === "3d" ? "up" : "down" };
273
+ });
274
+ const kinds = seamKinds(spots, key, tpl.scenes.find((s) => s.role === "seam")?.transition ?? "dive", Object.fromEntries(seamIdx.map((i, k) => [k, seamFailed[scenes[i].id] ?? []])));
275
+
276
+ const dress = dressAll(key, scenes, tpl.moves, theme);
277
+ const scenesDir = join(dir, "scenes");
278
+ mkdirSync(scenesDir, { recursive: true });
279
+ const report: SceneReport[] = [];
280
+ const keep = new Set<string>();
281
+ const log = o.log ?? (() => {});
282
+ for (const [i, s] of scenes.entries()) {
283
+ const file = join(dir, s.file);
284
+ keep.add(s.file);
285
+ const base = { id: s.id, role: s.role, from: s.from, dur: s.dur };
286
+ if (only && !only.has(s.id)) {
287
+ const kept = prev?.scenes.find((x) => x.id === s.id);
288
+ if (kept) report.push(kept);
289
+ continue;
290
+ }
291
+ log(`장면 ${s.id}: 쓰는 중`);
292
+ if (s.role === "seam") {
293
+ const kind = kinds[seamIdx.indexOf(i)];
294
+ s.transition = kind;
295
+ delete s.dress;
296
+ writeOwned(file, `${MARK} — 이음매(전환은 director.json)\n${fill(sceneSkeleton(kf.template, s.id, "seam"), { transition: kind, title: content.title })}`, !prev);
297
+ report.push({ ...base, transition: kind });
298
+ log(`장면 ${s.id}: 씀`);
299
+ continue;
300
+ }
301
+ const c = byId.get(s.id)!;
302
+ if (c.type === "custom") {
303
+ const own = typeof c.file === "string" ? c.file : s.file;
304
+ if (own !== s.file) {
305
+ keep.add(own);
306
+ s.file = own;
307
+ }
308
+ s.dress = dress[i];
309
+ if (existsSync(join(dir, own)) && !SKELETON.test(readFileSync(join(dir, own), "utf8"))) {
310
+ report.push({ ...base, type: "custom", custom: "kept" });
311
+ log(`장면 ${s.id}: 씀`);
312
+ continue;
313
+ }
314
+ writeFileSync(join(dir, own), fill(sceneSkeleton(kf.template, s.id, s.role), { word: content.title, title: content.title, line: String(plan.line ?? ""), move: "rise", transition: "dive", ...dress[i] }));
315
+ report.push({ ...base, type: "custom", custom: "skeleton" });
316
+ log(`장면 ${s.id}: 씀`);
317
+ continue;
318
+ }
319
+ const p = pickOf.get(s.id)!;
320
+ const e = entryOf.get(p.pattern)!;
321
+ // 감독 기본은 무대 글 수가 낱말을 돌려 띄운다 — 판 넘김·유령 줄만(자르거나 겹쳐 흐리는 수는 안 쓴다)
322
+ const prevText = scenes[i - 1]?.dress?.text;
323
+ const d = e.fallback ? { ...dress[i], text: cyclingText(key, s.id, prevText) } : dress[i];
324
+ s.dress = d;
325
+ s.pattern = p.pattern;
326
+ s.idea = `${s.type} — ${e.meta.does}`;
327
+ const directedArgs = { scene: s.id, type: s.type, content: payload(c), seed: pinned[s.id]?.seed ?? `${key}|${s.id}`, theme, dress: d, policy, first: i === 0, last: i === scenes.length - 1, loop: !!tpl.loop };
328
+ writeOwned(file, patternFile(e.spec, directedArgs), !prev);
329
+ report.push({ ...base, type: s.type, energy: slots.find((x) => x.id === s.id)!.energy, pattern: p.pattern, dress: d, order: p.order.slice(0, 5), rejected: p.rejected, attempt: p.attempt, hash: sceneHash(c) });
330
+ log(`장면 ${s.id}: 씀`);
331
+ }
332
+
333
+ // 시간표에 없는 장면 파일 — 뼈대는 지우고, 손으로 쓴 것은 scenes/_unused/ 로 비켜 둔다(main.ts 가 안 싣는다)
334
+ for (const f of readdirSync(scenesDir)) {
335
+ if (!f.endsWith(".ts") || keep.has(`scenes/${f}`)) continue;
336
+ const p = join(scenesDir, f);
337
+ const body = readFileSync(p, "utf8");
338
+ if (body.startsWith(MARK) || SKELETON.test(body)) unlinkSync(p);
339
+ else stash(dir, f);
340
+ }
341
+
342
+ writeJson(join(dir, "kf.json"), kf);
343
+ const out: Report = { version: 1, seed, key, content: hash, purpose, theme, aspect, scenes: report, failed: Object.fromEntries(Object.entries(failed).map(([id, l]) => [id, l.map(tag)])), seamFailed, pinned };
344
+ writeJson(prevPath, out);
345
+ return out;
346
+ }
347
+
348
+ function stash(dir: string, name: string): void {
349
+ mkdirSync(join(dir, "scenes", "_unused"), { recursive: true });
350
+ renameSync(join(dir, "scenes", name), join(dir, "scenes", "_unused", name));
351
+ }
352
+
353
+ // 감독 몫 파일만 덮는다 — 손으로 쓴 파일이 같은 자리에 있으면 _unused 로 비켜 두고 쓴다(처음 들어설 땐 뼈대도 지운다)
354
+ function writeOwned(file: string, body: string, first: boolean): void {
355
+ if (existsSync(file)) {
356
+ const old = readFileSync(file, "utf8");
357
+ if (old === body) return;
358
+ if (!old.startsWith(MARK) && !(first && SKELETON.test(old))) stash(join(file, "..", ".."), file.split("/").at(-1)!);
359
+ }
360
+ writeFileSync(file, body);
361
+ }
@@ -0,0 +1,122 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { type Question, questionsMarkdown } from "@kasaframe/gen";
4
+ import { loadTemplate, parseDuration } from "@kasaframe/plan";
5
+ import { contentGuide } from "./content.ts";
6
+
7
+ // 감독 모드에서 모델이 쓰는 것은 content.json 하나 — 지시서(Claude Code)와 OG 프롬프트가 같은 칸 표·요령을 쓴다.
8
+
9
+ const readJson = <T = any>(p: string): T => JSON.parse(readFileSync(p, "utf8"));
10
+
11
+ const EXAMPLE = {
12
+ title: "MLA",
13
+ request: "OG 쇼츠 — MLA 가 뭔지 45초",
14
+ scenes: [
15
+ { id: "hook", type: "hook-number", value: 57, unit: "×", prefix: "1/", label: "KV 캐시", say: "KV 캐시가, 57분의 1로 줄어듭니다.", source: "DeepSeek-V2 논문 표 1" },
16
+ { id: "cost", type: "fill", total: 80, filled: 80, label: "GPU 한 장 80GB", unit: "GB", say: "…", source: "…" },
17
+ { id: "how", type: "formula", parts: "K = c × W_UK", say: "…" },
18
+ { id: "name", type: "term-reveal", term: "MLA", full: "Multi-head Latent Attention", ko: "멀티헤드 잠재 어텐션", say: "…" },
19
+ { id: "end", type: "end", title: "MLA", line: "캐시를 57배 줄이는 어텐션", say: "…" },
20
+ ],
21
+ };
22
+
23
+ interface Brief {
24
+ request: string;
25
+ title: string;
26
+ purpose: string;
27
+ label: string;
28
+ aspect: string;
29
+ target: number;
30
+ policy: string;
31
+ maxOnScreen: number;
32
+ theme: string | null;
33
+ voice: string;
34
+ music: string;
35
+ }
36
+
37
+ function facts(dir: string): Brief {
38
+ const kf = readJson(join(dir, "kf.json"));
39
+ const plan = existsSync(join(dir, "plan.json")) ? readJson(join(dir, "plan.json")) : {};
40
+ const tpl = loadTemplate(kf.template);
41
+ return {
42
+ request: plan.request ?? kf.title,
43
+ title: kf.title,
44
+ purpose: kf.template,
45
+ label: tpl.label,
46
+ aspect: plan.aspect ?? (kf.width > kf.height ? "16:9" : kf.width < kf.height ? "9:16" : "1:1"),
47
+ target: parseDuration(plan.request ?? "") ?? tpl.duration.default,
48
+ policy: kf.text?.policy ?? tpl.text.policy,
49
+ maxOnScreen: kf.text?.maxOnScreen ?? tpl.text.maxOnScreen,
50
+ theme: kf.theme ?? null,
51
+ voice: plan.voice ?? plan.answers?.voice ?? tpl.narration?.voice ?? "none",
52
+ music: plan.answers?.music ?? kf.music ?? "none",
53
+ };
54
+ }
55
+
56
+ function rules(b: Brief): string[] {
57
+ const chars = Math.round(b.target * 4.5);
58
+ return [
59
+ `- **say** 가 장면 길이를 정한다(목소리 먼저) — 차분한 설명체, 마디는 쉼표·문장은 마침표, 1초에 4–5글자. 영상 ${b.target}초면 say 를 다 합쳐 ${chars}자 안팎. 훅은 한 마디.`,
60
+ `- **화면 글은 칸에만** — 글 정책 \`${b.policy}\`${b.policy === "terms-only" ? "(전문 낱말·숫자만 — 문장은 say 로)" : ""}, 한 화면 ${b.maxOnScreen}개 안팎. 칸은 짧게.`,
61
+ "- **숫자는 value 와 unit 을 따로**(\"9.2 GB\" 가 아니라 value 9.2 · unit \"GB\"), 숫자가 있는 장면은 **source**(출처) 를 꼭.",
62
+ "- 첫 장면은 결과 먼저(`hook-number`·`compare`·`words`), 마지막은 `end`. 같은 type 을 잇달아 쓰지 않는다 — 내용이 같은 꼴이면 다른 type 으로 바꿔 보인다(막대 → 칸 채우기 → 식).",
63
+ "- 장면 6–9개. 화면 문법·움직임·전환·카메라·바탕은 감독이 고른다 — content.json 에 쓰지 않는다. 패턴에 없는 화면만 `custom`(idea 를 적으면 kf direct 가 뼈대를 두고, 그 파일은 직접 쓴다).",
64
+ ];
65
+ }
66
+
67
+ /** Claude Code 감독 모드 지시서 — MAKE.md */
68
+ export function directBrief(dir: string): string {
69
+ const b = facts(dir);
70
+ const plan = existsSync(join(dir, "plan.json")) ? readJson(join(dir, "plan.json")) : {};
71
+ const asks: Question[] = plan.asks ?? [];
72
+ const answers: Record<string, string> = plan.answers ?? {};
73
+ const pending = (id: string) => asks.some((q) => q.id === id);
74
+ const gen = [
75
+ answers.image && answers.image !== "none" ? `- 그림이 필요한 장면(\`media\`·\`screen\`)은 \`npx kf gen img "<구체적 프롬프트>" --id <id> --provider ${answers.image} --project ${dir}\` 로 만들고 칸에 \`gen/<id>.png\`. 받은 자산·실제 화면으로 되면 만들지 않는다.` : "- 그림 생성은 하지 않는다(고른 답 none) — `media`·`screen` 은 받은 자산만.",
76
+ answers.blender && answers.blender !== "none" ? `- 주인공 3D 샷이 맞는 장면은 \`"space": "3d"\` — 3D 장면은 ${answers.blender === "three" ? "three(stage3d)" : "Blender 툰 샷(kf blender)"}로, 2D 장면과의 경계엔 감독이 공간 잇기 전환을 넣는다.` : "",
77
+ answers.video && answers.video !== "none" ? `- 캐릭터가 실제로 움직여야 하면 \`npx kf gen vid … --provider ${answers.video} --yes\` 로 만든 클립을 \`media\` 장면 assets 에.` : "",
78
+ ].filter(Boolean);
79
+ return [
80
+ `# 감독 모드 — ${b.title}`,
81
+ "",
82
+ `요청: ${b.request}`,
83
+ `${b.label}(${b.purpose}) · ${b.aspect} · 목표 ${b.target}초 · ${pending("theme") ? `테마 아직 — 맨 위 질문의 답(지금 깔린 것 ${b.theme ?? "프리셋"})` : b.theme ? `테마 ${b.theme}` : "프리셋"} · 목소리 ${pending("voice") ? "아직 — 맨 위 질문의 답" : b.voice} · 곡 ${pending("music") ? "아직 — 맨 위 질문의 답" : b.music}`,
84
+ "",
85
+ ...questionsMarkdown(asks, (flags) => `npx kf make --answer ${dir} ${flags}`),
86
+ "## 할 일 — 장면 코드는 쓰지 않는다",
87
+ "",
88
+ `1. \`${dir}/content.json\` 을 쓴다 — **무엇을** 보일지만(장면마다 type·칸·say·source). 아래 칸 표가 정본이다.`,
89
+ `2. \`npx kf direct ${dir}\` — 감독이 장면마다 검증된 장면 문법(패턴)을 테마·용도·곡 구간 에너지·앞뒤 장면과 안 겹치기로 골라 장면 파일을 조립하고, 내레이션으로 길이를 맞추고, \`kf check\` 가 떨어진 장면은 다음 후보로 다시 짓는다. 칸이 틀렸으면 어느 칸인지 찍고 멈춘다.`,
90
+ `3. \`npx kf look ${dir}\` 의 장면 모음·확인표를 직접 본다. 마음에 안 들면 content.json 을 고치거나 \`--seed <아무 글>\` 로 다른 고름을 본다(같은 씨앗이면 늘 같은 그림).`,
91
+ `4. \`npx kf make --finish ${dir}\` — 렌더·검사·표지·자막.`,
92
+ "",
93
+ "## 쓰는 요령",
94
+ "",
95
+ ...rules(b),
96
+ ...gen,
97
+ "",
98
+ "## content.json 꼴",
99
+ "",
100
+ "```json",
101
+ JSON.stringify(EXAMPLE, null, 2),
102
+ "```",
103
+ "",
104
+ contentGuide(),
105
+ "",
106
+ ].join("\n");
107
+ }
108
+
109
+ /** OG 모드 — 모델이 content.json 을 한 번에 쓰게 하는 메시지 */
110
+ export function contentPrompt(dir: string, fix?: string): { role: "system" | "user"; content: string }[] {
111
+ const b = facts(dir);
112
+ return [
113
+ {
114
+ role: "system",
115
+ content: `너는 짧은 영상의 내용만 정한다 — 장면마다 무엇을 보일지(type 과 칸)와 들릴 말(say). 화면 문법·움직임·전환·카메라·바탕은 알고리즘이 고르니 쓰지 않는다. JSON 하나로만 답한다.\n\n${contentGuide()}`,
116
+ },
117
+ {
118
+ role: "user",
119
+ content: `요청: ${b.request}\n용도: ${b.label}(${b.purpose}) · ${b.aspect} · 목표 ${b.target}초 · 이름 후보: ${b.title}\n\n요령:\n${rules(b).join("\n")}\n\n꼴(예시 — 내용은 요청에 맞게 새로):\n${JSON.stringify(EXAMPLE)}${fix ? `\n\n앞 답의 고칠 곳:\n${fix}` : ""}`,
120
+ },
121
+ ];
122
+ }
@@ -0,0 +1,49 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFileSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ import fallback from "./fallback.ts";
5
+ import type { Pattern } from "./pattern.ts";
6
+ import fillCells from "./patterns/fill/cells.ts";
7
+ import formulaStack from "./patterns/formula/stack.ts";
8
+ import type { Entry } from "./select.ts";
9
+
10
+ // 고를 수 있는 패턴 전부 — 패턴 라이브러리(@kasaframe/patterns, 장면 문법 담당)가 있으면 그 PATTERNS 와, 감독이 엔진을 세우려고 둔 것.
11
+ // 같은 id 면 라이브러리 쪽이 이긴다(감독 쪽은 라이브러리로 옮겨 가는 중인 것).
12
+
13
+ const OWN: Pattern<any>[] = [fillCells, formulaStack];
14
+
15
+ const specOf = (pkg: string, id: string): string => {
16
+ const dot = id.indexOf(".");
17
+ return `${pkg}/${id.slice(0, dot)}/${id.slice(dot + 1)}`;
18
+ };
19
+
20
+ export async function catalog(): Promise<Entry[]> {
21
+ let lib: Pattern<any>[] = [];
22
+ try {
23
+ const mod = (await import("@kasaframe/patterns" as string)) as { PATTERNS?: Pattern<any>[] };
24
+ lib = mod.PATTERNS ?? [];
25
+ } catch (e) {
26
+ // 라이브러리가 아직 없으면 감독 쪽 것만 — 깨진 패턴은 숨기지 않는다
27
+ if (!/Cannot find (package|module)|ERR_MODULE_NOT_FOUND/.test(String(e))) throw e;
28
+ }
29
+ const ids = new Set(lib.map((p) => p.id));
30
+ const entries: Entry[] = [
31
+ ...lib.map((p) => ({ meta: p, spec: specOf("@kasaframe/patterns", p.id) })),
32
+ ...OWN.filter((p) => !ids.has(p.id)).map((p) => ({ meta: p, spec: specOf("@kasaframe/director/patterns", p.id) })),
33
+ { meta: fallback, spec: "@kasaframe/director/fallback", fallback: true },
34
+ ];
35
+ for (const e of entries) {
36
+ if (!e.fallback && !/^[a-z0-9-]+\.[a-z0-9-]+$/.test(e.meta.id)) throw new Error(`패턴 id "${e.meta.id}" 는 <type>.<이름> 꼴이어야 한다`);
37
+ e.rev = revOf(e.spec);
38
+ }
39
+ return entries.sort((a, b) => (a.meta.id < b.meta.id ? -1 : a.meta.id > b.meta.id ? 1 : 0));
40
+ }
41
+
42
+ // 패턴 파일 내용의 해시 — 장면 문법 쪽이 패턴을 고치면 판이 바뀐다
43
+ function revOf(spec: string): string | undefined {
44
+ try {
45
+ return createHash("sha256").update(readFileSync(fileURLToPath(import.meta.resolve(spec)))).digest("hex").slice(0, 8);
46
+ } catch {
47
+ return undefined;
48
+ }
49
+ }