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.
- package/LICENSE +21 -0
- package/NOTICE +148 -0
- package/README.md +92 -2
- package/app/package.json +12 -0
- package/app/server/engine.ts +533 -0
- package/app/server/main.ts +209 -0
- package/app/web/env.d.ts +2 -0
- package/app/web/icons.ts +31 -0
- package/app/web/index.html +21 -0
- package/app/web/main.ts +1195 -0
- package/app/web/style.css +463 -0
- package/bin/hooks.mjs +64 -0
- package/bin/kf.mjs +32 -0
- package/docs/AGENTS.md +286 -0
- package/music/README.md +37 -0
- package/package.json +44 -4
- package/packages/adapters/package.json +36 -0
- package/packages/adapters/src/css.ts +11 -0
- package/packages/adapters/src/gsap.ts +26 -0
- package/packages/adapters/src/index.ts +9 -0
- package/packages/adapters/src/lottie.ts +22 -0
- package/packages/adapters/src/media.ts +59 -0
- package/packages/adapters/src/page.ts +229 -0
- package/packages/adapters/src/project.ts +214 -0
- package/packages/adapters/src/react.ts +36 -0
- package/packages/adapters/src/svelte.ts +22 -0
- package/packages/adapters/src/three.ts +18 -0
- package/packages/adapters/src/vue.ts +27 -0
- package/packages/check/package.json +19 -0
- package/packages/check/src/check.ts +280 -0
- package/packages/check/src/cli.ts +70 -0
- package/packages/check/src/image.ts +146 -0
- package/packages/check/src/index.ts +9 -0
- package/packages/check/src/ocr.swift +37 -0
- package/packages/check/src/probe.ts +328 -0
- package/packages/check/src/report.ts +44 -0
- package/packages/check/src/rules/assets.ts +45 -0
- package/packages/check/src/rules/beats.ts +212 -0
- package/packages/check/src/rules/camera.ts +217 -0
- package/packages/check/src/rules/captions.ts +49 -0
- package/packages/check/src/rules/flash.ts +235 -0
- package/packages/check/src/rules/frames.ts +136 -0
- package/packages/check/src/rules/layout.ts +281 -0
- package/packages/check/src/rules/page.ts +87 -0
- package/packages/check/src/rules/runs.ts +20 -0
- package/packages/check/src/rules/text.ts +326 -0
- package/packages/check/src/scan.ts +240 -0
- package/packages/check/src/serve.ts +67 -0
- package/packages/check/src/types.ts +80 -0
- package/packages/check/src/video.ts +137 -0
- package/packages/cli/package.json +30 -0
- package/packages/cli/src/blur.ts +80 -0
- package/packages/cli/src/browser.ts +203 -0
- package/packages/cli/src/command.ts +44 -0
- package/packages/cli/src/commands/app.ts +25 -0
- package/packages/cli/src/commands/beats.ts +36 -0
- package/packages/cli/src/commands/bench.ts +123 -0
- package/packages/cli/src/commands/blender.ts +293 -0
- package/packages/cli/src/commands/check.ts +25 -0
- package/packages/cli/src/commands/direct.ts +210 -0
- package/packages/cli/src/commands/doctor.ts +30 -0
- package/packages/cli/src/commands/gen.ts +173 -0
- package/packages/cli/src/commands/look.ts +46 -0
- package/packages/cli/src/commands/lyrics.ts +157 -0
- package/packages/cli/src/commands/make.ts +1121 -0
- package/packages/cli/src/commands/music.ts +78 -0
- package/packages/cli/src/commands/narrate.ts +238 -0
- package/packages/cli/src/commands/new.ts +185 -0
- package/packages/cli/src/commands/preview.ts +43 -0
- package/packages/cli/src/commands/render.ts +250 -0
- package/packages/cli/src/commands/series.ts +110 -0
- package/packages/cli/src/commands/setup.ts +102 -0
- package/packages/cli/src/commands/sheet.ts +114 -0
- package/packages/cli/src/commands/skill.ts +43 -0
- package/packages/cli/src/commands/still.ts +40 -0
- package/packages/cli/src/commands/theme.ts +172 -0
- package/packages/cli/src/commands/transitions.ts +40 -0
- package/packages/cli/src/deps.ts +122 -0
- package/packages/cli/src/ffmpeg.ts +81 -0
- package/packages/cli/src/index.ts +8 -0
- package/packages/cli/src/kf.ts +64 -0
- package/packages/cli/src/lock.ts +72 -0
- package/packages/cli/src/mix.ts +131 -0
- package/packages/cli/src/out.ts +13 -0
- package/packages/cli/src/pool.ts +34 -0
- package/packages/cli/src/segments.ts +402 -0
- package/packages/cli/src/serve.ts +124 -0
- package/packages/clock/package.json +14 -0
- package/packages/clock/src/index.ts +25 -0
- package/packages/clock/src/install.ts +351 -0
- package/packages/clock/src/types.ts +45 -0
- package/packages/core/package.json +9 -0
- package/packages/core/src/beats.ts +283 -0
- package/packages/core/src/ease.ts +87 -0
- package/packages/core/src/frame.ts +99 -0
- package/packages/core/src/index.ts +27 -0
- package/packages/core/src/project.ts +157 -0
- package/packages/core/src/rand.ts +56 -0
- package/packages/core/src/spring.ts +52 -0
- package/packages/core/src/style.ts +100 -0
- package/packages/core/src/time.ts +88 -0
- package/packages/director/package.json +23 -0
- package/packages/director/src/assemble.ts +361 -0
- package/packages/director/src/brief.ts +122 -0
- package/packages/director/src/catalog.ts +49 -0
- package/packages/director/src/content.ts +343 -0
- package/packages/director/src/fallback.ts +58 -0
- package/packages/director/src/index.ts +13 -0
- package/packages/director/src/pattern.ts +90 -0
- package/packages/director/src/patterns/fill/cells.ts +115 -0
- package/packages/director/src/patterns/formula/stack.ts +93 -0
- package/packages/director/src/patterns/util.ts +58 -0
- package/packages/director/src/scene.ts +62 -0
- package/packages/director/src/select.ts +163 -0
- package/packages/director/src/transitions.ts +115 -0
- package/packages/gen/PROVIDERS.md +90 -0
- package/packages/gen/package.json +9 -0
- package/packages/gen/src/ask.ts +132 -0
- package/packages/gen/src/audio.ts +91 -0
- package/packages/gen/src/blender.ts +54 -0
- package/packages/gen/src/capabilities.ts +151 -0
- package/packages/gen/src/generate.ts +206 -0
- package/packages/gen/src/image/codex.ts +117 -0
- package/packages/gen/src/image/og.ts +133 -0
- package/packages/gen/src/index.ts +26 -0
- package/packages/gen/src/keys.ts +86 -0
- package/packages/gen/src/media.ts +150 -0
- package/packages/gen/src/music/elevenlabs.ts +41 -0
- package/packages/gen/src/music/index.ts +120 -0
- package/packages/gen/src/music/library.ts +73 -0
- package/packages/gen/src/music/lyria.ts +52 -0
- package/packages/gen/src/music/types.ts +28 -0
- package/packages/gen/src/plan.ts +106 -0
- package/packages/gen/src/registry.ts +54 -0
- package/packages/gen/src/seam.ts +103 -0
- package/packages/gen/src/tts/dashscope.ts +64 -0
- package/packages/gen/src/tts/elevenlabs.ts +84 -0
- package/packages/gen/src/tts/gemini.ts +73 -0
- package/packages/gen/src/tts/index.ts +241 -0
- package/packages/gen/src/tts/local.ts +42 -0
- package/packages/gen/src/tts/types.ts +44 -0
- package/packages/gen/src/types.ts +90 -0
- package/packages/gen/src/video/fal.ts +140 -0
- package/packages/gen/src/video/h3.ts +112 -0
- package/packages/gen/src/video/http.ts +44 -0
- package/packages/gen/src/video/ltx.ts +60 -0
- package/packages/gen/src/video/minimax.ts +55 -0
- package/packages/gen/src/video/veo.ts +71 -0
- package/packages/jizura/package.json +16 -0
- package/packages/jizura/src/deny.ts +73 -0
- package/packages/jizura/src/index.ts +7 -0
- package/packages/jizura/src/install.ts +269 -0
- package/packages/jizura/src/layer.ts +325 -0
- package/packages/jizura/src/lyrics.ts +81 -0
- package/packages/jizura/src/pin.ts +8 -0
- package/packages/jizura/src/vendor.ts +140 -0
- package/packages/jizura/src/vite.ts +63 -0
- package/packages/jizura/vendor/JIZURA_LICENSE.txt +21 -0
- package/packages/jizura/vendor/NOTICE +43 -0
- package/packages/jizura/vendor/engine.json +47 -0
- package/packages/jizura/vendor/fonts/BlackHanSans-Regular.woff2 +0 -0
- package/packages/jizura/vendor/fonts/DotGothic16-Regular.woff2 +0 -0
- package/packages/jizura/vendor/fonts/GowunBatang-Bold.woff2 +0 -0
- package/packages/jizura/vendor/fonts/IBMPlexMono-Medium.ttf +0 -0
- package/packages/jizura/vendor/fonts/IBMPlexMono-SemiBold.ttf +0 -0
- package/packages/jizura/vendor/fonts/NotoSansKR-VF.woff2 +0 -0
- package/packages/jizura/vendor/fonts/NotoSerifKR-VF.woff2 +0 -0
- package/packages/jizura/vendor/fonts/OFL-blackhansans.txt +93 -0
- package/packages/jizura/vendor/fonts/OFL-dotgothic16.txt +93 -0
- package/packages/jizura/vendor/fonts/OFL-gowunbatang.txt +94 -0
- package/packages/jizura/vendor/fonts/OFL-ibmplexmono.txt +93 -0
- package/packages/jizura/vendor/fonts/OFL-notosanskr.txt +93 -0
- package/packages/jizura/vendor/fonts/OFL-notoserifkr.txt +94 -0
- package/packages/jizura/vendor/fonts/fonts.json +52 -0
- package/packages/jizura/vendor/jizura_engine.js +35024 -0
- package/packages/motion/README.md +153 -0
- package/packages/motion/package.json +30 -0
- package/packages/motion/src/camera.ts +97 -0
- package/packages/motion/src/captions.ts +487 -0
- package/packages/motion/src/enter.ts +128 -0
- package/packages/motion/src/hangul.ts +129 -0
- package/packages/motion/src/impact.ts +100 -0
- package/packages/motion/src/index.ts +17 -0
- package/packages/motion/src/moves/brushWipe.ts +103 -0
- package/packages/motion/src/moves/cloneArray.ts +111 -0
- package/packages/motion/src/moves/curtains.ts +81 -0
- package/packages/motion/src/moves/dress.ts +191 -0
- package/packages/motion/src/moves/echoStack.ts +70 -0
- package/packages/motion/src/moves/fit.ts +70 -0
- package/packages/motion/src/moves/flood.ts +61 -0
- package/packages/motion/src/moves/ghostStack.ts +88 -0
- package/packages/motion/src/moves/gridFloor.ts +100 -0
- package/packages/motion/src/moves/imageSwarm.ts +113 -0
- package/packages/motion/src/moves/index.ts +38 -0
- package/packages/motion/src/moves/irisBlades.ts +113 -0
- package/packages/motion/src/moves/karaokeLine.ts +108 -0
- package/packages/motion/src/moves/ledBoard.ts +94 -0
- package/packages/motion/src/moves/liquidTab.ts +72 -0
- package/packages/motion/src/moves/markerWrite.ts +63 -0
- package/packages/motion/src/moves/menu.ts +138 -0
- package/packages/motion/src/moves/morphBox.ts +96 -0
- package/packages/motion/src/moves/neonSign.ts +78 -0
- package/packages/motion/src/moves/panelPop.ts +78 -0
- package/packages/motion/src/moves/paperTear.ts +75 -0
- package/packages/motion/src/moves/path.ts +64 -0
- package/packages/motion/src/moves/pathText.ts +107 -0
- package/packages/motion/src/moves/pointSphere.ts +109 -0
- package/packages/motion/src/moves/ransomLetters.ts +73 -0
- package/packages/motion/src/moves/shapeMorph.ts +143 -0
- package/packages/motion/src/moves/slamWords.ts +96 -0
- package/packages/motion/src/moves/sparkTrail.ts +130 -0
- package/packages/motion/src/moves/speedLines.ts +91 -0
- package/packages/motion/src/moves/splitFlap.ts +149 -0
- package/packages/motion/src/moves/stepWords.ts +128 -0
- package/packages/motion/src/moves/strikeOut.ts +98 -0
- package/packages/motion/src/moves/sunburst.ts +58 -0
- package/packages/motion/src/moves/tickerRows.ts +91 -0
- package/packages/motion/src/moves/tokenPicker.ts +115 -0
- package/packages/motion/src/moves/truchet.ts +85 -0
- package/packages/motion/src/moves/wordWall.ts +78 -0
- package/packages/motion/src/moves/worldRoll.ts +32 -0
- package/packages/motion/src/particles.ts +102 -0
- package/packages/motion/src/react/index.tsx +21 -0
- package/packages/motion/src/react/parts.tsx +431 -0
- package/packages/motion/src/react/time.tsx +97 -0
- package/packages/motion/src/text.ts +103 -0
- package/packages/motion/src/transition.ts +82 -0
- package/packages/motion/src/transition3d/cards.ts +65 -0
- package/packages/motion/src/transition3d/chain.ts +84 -0
- package/packages/motion/src/transition3d/dive.ts +181 -0
- package/packages/motion/src/transition3d/fold.ts +110 -0
- package/packages/motion/src/transition3d/gl.ts +219 -0
- package/packages/motion/src/transition3d/index.ts +235 -0
- package/packages/motion/src/transition3d/live.ts +70 -0
- package/packages/motion/src/transition3d/portal.ts +115 -0
- package/packages/motion/src/transition3d/react.tsx +29 -0
- package/packages/motion/src/transition3d/rig.ts +600 -0
- package/packages/motion/src/transition3d/shatter.ts +104 -0
- package/packages/motion/src/transition3d/space.ts +173 -0
- package/packages/motion/src/transition3d/whip.ts +78 -0
- package/packages/motion/src/transition3d/world.ts +737 -0
- package/packages/motion/src/transition3d/zoomOut.ts +114 -0
- package/packages/motion/src/transitions2d/catalog.ts +127 -0
- package/packages/motion/src/transitions2d/css.d.ts +2 -0
- package/packages/motion/src/transitions2d/cult-ui/LICENSE.md +9 -0
- package/packages/motion/src/transitions2d/cult-ui/RollingNumber.tsx +43 -0
- package/packages/motion/src/transitions2d/gl-transitions/LICENSE +25 -0
- package/packages/motion/src/transitions2d/gl-transitions/shaders.ts +1931 -0
- package/packages/motion/src/transitions2d/index.ts +2 -0
- package/packages/motion/src/transitions2d/kokonutui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/kokonutui/MatrixText.css +16 -0
- package/packages/motion/src/transitions2d/kokonutui/MatrixText.tsx +94 -0
- package/packages/motion/src/transitions2d/magicui/HyperText.css +15 -0
- package/packages/motion/src/transitions2d/magicui/HyperText.tsx +115 -0
- package/packages/motion/src/transitions2d/magicui/LICENSE.md +21 -0
- package/packages/motion/src/transitions2d/magicui/MorphingText.css +25 -0
- package/packages/motion/src/transitions2d/magicui/MorphingText.tsx +130 -0
- package/packages/motion/src/transitions2d/magicui/WordRotate.tsx +42 -0
- package/packages/motion/src/transitions2d/react.ts +13 -0
- package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.css +39 -0
- package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.tsx +32 -0
- package/packages/motion/src/transitions2d/smoothui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/smoothui/SharedAxisY.tsx +50 -0
- package/packages/motion/src/transitions2d/smoothui/TextMorph.tsx +90 -0
- package/packages/motion/src/transitions2d/smoothui/shaders.ts +223 -0
- package/packages/motion/src/transitions2d/unlumen/LICENSE +21 -0
- package/packages/motion/src/transitions2d/unlumen/ScrambleText.tsx +114 -0
- package/packages/motion/src/transitions2d/vengeance-ui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/vengeance-ui/MorphText.css +69 -0
- package/packages/motion/src/transitions2d/vengeance-ui/MorphText.tsx +45 -0
- package/packages/motion/src/type.ts +131 -0
- package/packages/motion/src/ui.ts +172 -0
- package/packages/patterns/package.json +15 -0
- package/packages/patterns/src/bars/rank.ts +119 -0
- package/packages/patterns/src/before-after/shrink.ts +127 -0
- package/packages/patterns/src/before-after/strike.ts +125 -0
- package/packages/patterns/src/code/terminal.ts +133 -0
- package/packages/patterns/src/compare/bars.ts +142 -0
- package/packages/patterns/src/compare/duel.ts +103 -0
- package/packages/patterns/src/end/lockup.ts +85 -0
- package/packages/patterns/src/end/slam.ts +91 -0
- package/packages/patterns/src/flow/graph.ts +250 -0
- package/packages/patterns/src/hook-number/counter.ts +101 -0
- package/packages/patterns/src/hook-number/roll.ts +179 -0
- package/packages/patterns/src/hook-number/slam.ts +91 -0
- package/packages/patterns/src/index.ts +38 -0
- package/packages/patterns/src/kit.ts +449 -0
- package/packages/patterns/src/limit/gauge.ts +117 -0
- package/packages/patterns/src/list/cards.ts +131 -0
- package/packages/patterns/src/list/cycle.ts +22 -0
- package/packages/patterns/src/media/panels.ts +100 -0
- package/packages/patterns/src/objects.ts +234 -0
- package/packages/patterns/src/quote/karaoke.ts +126 -0
- package/packages/patterns/src/quote/slam.ts +22 -0
- package/packages/patterns/src/screen/focus.ts +85 -0
- package/packages/patterns/src/steps/path.ts +137 -0
- package/packages/patterns/src/steps/stack.ts +111 -0
- package/packages/patterns/src/term-reveal/chips.ts +92 -0
- package/packages/patterns/src/term-reveal/expand.ts +127 -0
- package/packages/patterns/src/timeline/axis.ts +144 -0
- package/packages/patterns/src/title/mask.ts +85 -0
- package/packages/patterns/src/title/slam.ts +23 -0
- package/packages/patterns/src/toggle-sim/switch.ts +92 -0
- package/packages/patterns/src/trend/columns.ts +108 -0
- package/packages/patterns/src/trend/draw.ts +140 -0
- package/packages/patterns/src/types.ts +67 -0
- package/packages/patterns/src/words/moves.ts +42 -0
- package/packages/patterns/src/words/slam.ts +4 -0
- package/packages/plan/package.json +15 -0
- package/packages/plan/src/asks.ts +256 -0
- package/packages/plan/src/brief.ts +383 -0
- package/packages/plan/src/captions.ts +78 -0
- package/packages/plan/src/detect.ts +93 -0
- package/packages/plan/src/index.ts +27 -0
- package/packages/plan/src/layout.ts +176 -0
- package/packages/plan/src/llm.ts +172 -0
- package/packages/plan/src/look.ts +222 -0
- package/packages/plan/src/plan.ts +179 -0
- package/packages/plan/src/request.ts +55 -0
- package/packages/plan/src/series.ts +76 -0
- package/packages/plan/src/studio.ts +53 -0
- package/packages/plan/src/templates.ts +42 -0
- package/packages/plan/src/themes.ts +48 -0
- package/packages/plan/src/types.ts +157 -0
- package/packages/studio/package.json +12 -0
- package/packages/studio/src/index.ts +1 -0
- package/packages/studio/src/plugin.ts +236 -0
- package/packages/studio/src/ui/main.ts +503 -0
- package/packages/studio/src/ui/studio.css +165 -0
- package/packages/studio/src/ui/timeline.ts +317 -0
- package/packages/themes/kit/THEME-MAKE.md +68 -0
- package/packages/themes/kit/THEME.md +30 -0
- package/packages/themes/kit/briefs/og-intro-15s/brief.json +16 -0
- package/packages/themes/kit/briefs/og-intro-15s/facts.ts +29 -0
- package/packages/themes/kit/briefs/og-intro-15s/logo.svg +12 -0
- package/packages/themes/kit/effects.ts +5 -0
- package/packages/themes/kit/sample/index.html +11 -0
- package/packages/themes/kit/sample/main.ts +9 -0
- package/packages/themes/kit/sample/scenes/scene.ts +15 -0
- package/packages/themes/package.json +19 -0
- package/packages/themes/src/factory.ts +296 -0
- package/packages/themes/src/fx.ts +14 -0
- package/packages/themes/src/index.ts +114 -0
- package/packages/themes/src/slotkit.ts +79 -0
- package/packages/themes/src/slots.ts +46 -0
- package/packages/themes/src/stage3d.ts +197 -0
- package/packages/themes/src/types.ts +58 -0
- package/presets/kawaii-pastel.json +94 -0
- package/presets/neutral-dark.json +82 -0
- package/presets/og.json +98 -0
- package/series/og-shorts.json +14 -0
- package/skills/kasaframe/SKILL.md +33 -0
- package/templates/_shared/project/index.html +11 -0
- package/templates/_shared/project/lib/react.ts +22 -0
- package/templates/_shared/project/lib/stage.ts +292 -0
- package/templates/_shared/project/main.ts +9 -0
- package/templates/_shared/scenes/default.ts +21 -0
- package/templates/_shared/scenes/drop.ts +33 -0
- package/templates/_shared/scenes/end.ts +26 -0
- package/templates/_shared/scenes/hook.ts +18 -0
- package/templates/_shared/scenes/seam.ts +41 -0
- package/templates/_shared/scenes/step.ts +49 -0
- package/templates/ad/preview.png +0 -0
- package/templates/ad/template.json +151 -0
- package/templates/demo/preview.png +0 -0
- package/templates/demo/template.json +141 -0
- package/templates/explainer/preview.png +0 -0
- package/templates/explainer/template.json +193 -0
- package/templates/launch/preview.png +0 -0
- package/templates/launch/template.json +163 -0
- package/templates/mv/preview.png +0 -0
- package/templates/mv/scenes/default.ts +98 -0
- package/templates/mv/template.json +178 -0
- package/templates/promo/preview.png +0 -0
- package/templates/promo/template.json +185 -0
- package/templates/shorts/preview.png +0 -0
- package/templates/shorts/scenes/hook.ts +37 -0
- package/templates/shorts/template.json +196 -0
- package/templates/square/preview.png +0 -0
- package/templates/square/template.json +133 -0
- package/themes/debug-hud/THEME.md +39 -0
- package/themes/debug-hud/effects.ts +389 -0
- package/themes/debug-hud/sample/assets/og/logo.svg +12 -0
- package/themes/debug-hud/sample/beats.json +1 -0
- package/themes/debug-hud/sample/index.html +11 -0
- package/themes/debug-hud/sample/kf.json +59 -0
- package/themes/debug-hud/sample/lib/hudkit.ts +49 -0
- package/themes/debug-hud/sample/lib/og.ts +29 -0
- package/themes/debug-hud/sample/main.ts +9 -0
- package/themes/debug-hud/sample/scenes/end.ts +62 -0
- package/themes/debug-hud/sample/scenes/gather.ts +67 -0
- package/themes/debug-hud/sample/scenes/models.ts +70 -0
- package/themes/debug-hud/sample/scenes/price.ts +79 -0
- package/themes/debug-hud/sample/style.json +91 -0
- package/themes/debug-hud/slots.ts +99 -0
- package/themes/debug-hud/still.png +0 -0
- package/themes/debug-hud/style.json +91 -0
- package/themes/debug-hud/theme.json +68 -0
- package/themes/og-measure/THEME.md +47 -0
- package/themes/og-measure/effects.ts +432 -0
- package/themes/og-measure/sample/assets/brand/og-logo-full.svg +12 -0
- package/themes/og-measure/sample/assets/brand/og-logo.svg +12 -0
- package/themes/og-measure/sample/assets/data/measure.json +353 -0
- package/themes/og-measure/sample/beats.json +1 -0
- package/themes/og-measure/sample/index.html +11 -0
- package/themes/og-measure/sample/kf.json +66 -0
- package/themes/og-measure/sample/lib/data.ts +62 -0
- package/themes/og-measure/sample/main.ts +9 -0
- package/themes/og-measure/sample/measure.ts +78 -0
- package/themes/og-measure/sample/scenes/end.ts +47 -0
- package/themes/og-measure/sample/scenes/gather.ts +51 -0
- package/themes/og-measure/sample/scenes/models.ts +34 -0
- package/themes/og-measure/sample/scenes/one.ts +39 -0
- package/themes/og-measure/sample/scenes/price.ts +56 -0
- package/themes/og-measure/sample/style.json +97 -0
- package/themes/og-measure/slots.ts +88 -0
- package/themes/og-measure/still.png +0 -0
- package/themes/og-measure/style.json +97 -0
- package/themes/og-measure/theme.json +79 -0
- package/themes/riso-zine/THEME.md +43 -0
- package/themes/riso-zine/effects.ts +321 -0
- package/themes/riso-zine/sample/assets/og/logo.svg +12 -0
- package/themes/riso-zine/sample/beats.json +1 -0
- package/themes/riso-zine/sample/index.html +11 -0
- package/themes/riso-zine/sample/kf.json +59 -0
- package/themes/riso-zine/sample/lib/og.ts +29 -0
- package/themes/riso-zine/sample/lib/shot.ts +86 -0
- package/themes/riso-zine/sample/lib/zine.ts +42 -0
- package/themes/riso-zine/sample/main.ts +9 -0
- package/themes/riso-zine/sample/scenes/end.ts +61 -0
- package/themes/riso-zine/sample/scenes/gather.ts +62 -0
- package/themes/riso-zine/sample/scenes/models.ts +52 -0
- package/themes/riso-zine/sample/scenes/price.ts +82 -0
- package/themes/riso-zine/sample/style.json +99 -0
- package/themes/riso-zine/slots.ts +81 -0
- package/themes/riso-zine/still.png +0 -0
- package/themes/riso-zine/style.json +99 -0
- package/themes/riso-zine/theme.json +75 -0
- package/tools/beats/beats.py +372 -0
- package/tools/beats/requirements.txt +3 -0
- package/tools/lyrics/align.py +164 -0
- package/tools/lyrics/requirements.txt +9 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import type { Command } from "../command.ts";
|
|
7
|
+
import { num, parseFlags } from "../command.ts";
|
|
8
|
+
|
|
9
|
+
const kfBin = fileURLToPath(new URL("../kf.ts", import.meta.url));
|
|
10
|
+
|
|
11
|
+
const USAGE = `kf bench "<대충 한 요청>" [--runs 3] [--model claude-code|<OG 모델>] [--out 폴더] [kf make 에 넘길 플래그…]
|
|
12
|
+
|
|
13
|
+
같은 요청으로 kf make 를 여러 번 돌려 나란히 본다 — 「대충 말해도 같은 결과」를 재는 시험 틀.
|
|
14
|
+
같아야 할 것: 용도·시리즈·테마·스타일·목소리·곡·자막·길이·장면 수·장면 시간표·장면 연출·생성 거리·3D 샷·고른 답·물을 것
|
|
15
|
+
달라도 되는 것: 검사 점수·장면 모음(모델이 장면을 쓰는 OG 모드에서만 나온다)
|
|
16
|
+
claude-code 모드(기본)는 kf make 가 지시서에서 멈추니 계획까지 본다. --model <OG 모델> 이면 끝까지 굽고 검사·장면 모음까지(실행마다 렌더 — 오래 걸린다)
|
|
17
|
+
결과: <out>/report.md · report.json · (OG) sheets.png. 같아야 할 것이 달라지면 빨간 「다름」, 종료 코드 1`;
|
|
18
|
+
|
|
19
|
+
const RED = (s: string) => (process.stdout.isTTY ? `\x1b[31m${s}\x1b[0m` : s);
|
|
20
|
+
const DIM = (s: string) => (process.stdout.isTTY ? `\x1b[2m${s}\x1b[0m` : s);
|
|
21
|
+
|
|
22
|
+
const read = (f: string) => (existsSync(f) ? JSON.parse(readFileSync(f, "utf8")) : null);
|
|
23
|
+
const short = (v: unknown) => createHash("sha256").update(JSON.stringify(v ?? null)).digest("hex").slice(0, 8);
|
|
24
|
+
|
|
25
|
+
interface Run {
|
|
26
|
+
dir: string;
|
|
27
|
+
code: number;
|
|
28
|
+
same: Record<string, string>;
|
|
29
|
+
vary: Record<string, string>;
|
|
30
|
+
sheet?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 실행 하나에서 비교할 값 — 긴 것(시간표·연출·생성 거리)은 지문으로 줄이고 report.json 에 원본을 둔다
|
|
34
|
+
function measure(dir: string, code: number): Run {
|
|
35
|
+
const plan = read(join(dir, "plan.json")) ?? {};
|
|
36
|
+
const kf = read(join(dir, "kf.json")) ?? {};
|
|
37
|
+
const scenes: { id: string; from: number; dur: number; dress?: unknown }[] = kf.scenes ?? plan.scenes ?? [];
|
|
38
|
+
const same: Record<string, string> = {
|
|
39
|
+
용도: plan.purpose ?? "-",
|
|
40
|
+
시리즈: plan.series ?? "-",
|
|
41
|
+
테마: plan.theme ?? "-",
|
|
42
|
+
스타일: plan.style ?? "-",
|
|
43
|
+
목소리: plan.voice ?? plan.answers?.voice ?? "-",
|
|
44
|
+
곡: (kf.music ?? plan.music ?? plan.answers?.music ?? "-").toString().split("/").pop(),
|
|
45
|
+
자막: kf.captions ?? plan.captions ?? "-",
|
|
46
|
+
길이: String(kf.duration ?? plan.duration ?? "-"),
|
|
47
|
+
"장면 수": String(scenes.length),
|
|
48
|
+
시간표: short(scenes.map((s) => [s.id, s.from, s.dur])),
|
|
49
|
+
연출: short(scenes.map((s) => s.dress ?? null)),
|
|
50
|
+
"생성 거리": (plan.gen ?? []).map((g: { kind: string; id: string; provider?: string }) => `${g.kind}:${g.id}${g.provider ? `@${g.provider}` : ""}`).join(" ") || "-",
|
|
51
|
+
"3D 샷": (plan.shots ?? []).map((s: { id: string; tool: string }) => `${s.id}@${s.tool}`).join(" ") || "-",
|
|
52
|
+
"고른 답": Object.entries(plan.answers ?? {}).map(([k, v]) => `${k}=${String(v).split("/").pop()}`).sort().join(" ") || "-",
|
|
53
|
+
"물을 것": (plan.asks ?? []).map((q: { id: string }) => q.id).join(" ") || "-",
|
|
54
|
+
};
|
|
55
|
+
const check = read(join(dir, "out", "check.json"));
|
|
56
|
+
const vary: Record<string, string> = {};
|
|
57
|
+
if (check) {
|
|
58
|
+
const fs: { severity: string }[] = check.findings ?? [];
|
|
59
|
+
vary["검사"] = `오류 ${fs.filter((f) => f.severity === "error").length} · 경고 ${fs.filter((f) => f.severity === "warn").length}`;
|
|
60
|
+
}
|
|
61
|
+
vary["종료 코드"] = String(code);
|
|
62
|
+
const sheet = join(dir, "out", "look-sheet.png");
|
|
63
|
+
return { dir, code, same, vary, ...(existsSync(sheet) ? { sheet } : {}) };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function table(runs: Run[]): { lines: string[]; diff: string[] } {
|
|
67
|
+
const keys = Object.keys(runs[0].same);
|
|
68
|
+
const diff = keys.filter((k) => new Set(runs.map((r) => r.same[k])).size > 1);
|
|
69
|
+
const w = Math.max(...keys.map((k) => [...k].length * 2)) + 2;
|
|
70
|
+
const pad = (s: string, n: number) => s + " ".repeat(Math.max(0, n - [...s].reduce((a, c) => a + (/[ㄱ-]/.test(c) ? 2 : 1), 0)));
|
|
71
|
+
const lines = [pad("", w) + runs.map((_, i) => `실행 ${i + 1}`).join(" | ")];
|
|
72
|
+
for (const k of keys) {
|
|
73
|
+
const row = `${pad(k, w)}${runs.map((r) => r.same[k]).join(" | ")}`;
|
|
74
|
+
lines.push(diff.includes(k) ? RED(`${row} 다름`) : row);
|
|
75
|
+
}
|
|
76
|
+
for (const k of Object.keys(runs[0].vary)) lines.push(DIM(`${pad(k, w)}${runs.map((r) => r.vary[k] ?? "-").join(" | ")}`));
|
|
77
|
+
return { lines, diff };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const cmd: Command = {
|
|
81
|
+
summary: "일관성 시험 — 같은 요청으로 kf make 를 여러 번, 같아야 할 것이 달라지면 빨갛게",
|
|
82
|
+
usage: USAGE,
|
|
83
|
+
async run(argv) {
|
|
84
|
+
const { args, opts } = parseFlags(argv);
|
|
85
|
+
const request = args.join(" ").trim();
|
|
86
|
+
if (!request) {
|
|
87
|
+
console.error(USAGE);
|
|
88
|
+
return 2;
|
|
89
|
+
}
|
|
90
|
+
const runs = Math.max(2, Math.round(num(opts.runs, 3)));
|
|
91
|
+
const model = typeof opts.model === "string" ? opts.model : "claude-code";
|
|
92
|
+
const out = resolve(typeof opts.out === "string" ? opts.out : `bench-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`);
|
|
93
|
+
mkdirSync(out, { recursive: true });
|
|
94
|
+
// kf make 로 그대로 넘길 플래그(--yes·--no-gen·--allow·--image 등) — bench 자신의 것은 뺀다
|
|
95
|
+
const pass: string[] = [];
|
|
96
|
+
for (const [k, v] of Object.entries(opts)) {
|
|
97
|
+
if (["runs", "model", "out"].includes(k)) continue;
|
|
98
|
+
pass.push(`--${k}`, ...(v === true ? [] : [String(v)]));
|
|
99
|
+
}
|
|
100
|
+
const done: Run[] = [];
|
|
101
|
+
for (let i = 1; i <= runs; i++) {
|
|
102
|
+
const dir = join(out, `run-${i}`);
|
|
103
|
+
console.error(`실행 ${i}/${runs} — kf make (${model}) → ${dir}`);
|
|
104
|
+
const r = spawnSync(process.execPath, [kfBin, "make", request, "--out", dir, "--model", model, "--force", ...pass], { stdio: ["ignore", "ignore", "inherit"] });
|
|
105
|
+
done.push(measure(dir, r.status ?? 1));
|
|
106
|
+
}
|
|
107
|
+
const { lines, diff } = table(done);
|
|
108
|
+
console.log(`\n「${request}」 × ${runs} (${model})\n`);
|
|
109
|
+
console.log(lines.join("\n"));
|
|
110
|
+
const sheets = done.filter((r) => r.sheet).map((r) => r.sheet!);
|
|
111
|
+
if (sheets.length > 1) {
|
|
112
|
+
const png = join(out, "sheets.png");
|
|
113
|
+
const r = spawnSync("ffmpeg", ["-v", "error", "-y", ...sheets.flatMap((s) => ["-i", s]), "-filter_complex", `${sheets.map((_, i) => `[${i}]scale=-2:900[s${i}]`).join(";")};${sheets.map((_, i) => `[s${i}]`).join("")}hstack=${sheets.length}`, png]);
|
|
114
|
+
if (r.status === 0) console.log(`\n장면 모음 나란히: ${png}`);
|
|
115
|
+
}
|
|
116
|
+
const md = [`# kf bench — 「${request}」 × ${runs} (${model})`, "", "```", ...lines.map((l) => l.replace(/\x1b\[[0-9;]*m/g, "")), "```", "", diff.length ? `같아야 하는데 달라진 것: ${diff.join(" · ")}` : "같아야 할 것이 모두 같다.", ""].join("\n");
|
|
117
|
+
writeFileSync(join(out, "report.md"), md);
|
|
118
|
+
writeFileSync(join(out, "report.json"), `${JSON.stringify({ request, runs, model, diff, results: done.map((r) => ({ ...r, plan: read(join(r.dir, "plan.json")), scenes: read(join(r.dir, "kf.json"))?.scenes })) }, null, 2)}\n`);
|
|
119
|
+
console.log(`\n${diff.length ? RED(`다름 ${diff.length}가지: ${diff.join(" · ")}`) : "같아야 할 것이 모두 같다"}\n보고서: ${join(out, "report.md")}`);
|
|
120
|
+
return diff.length ? 1 : 0;
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
export default cmd;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { blenderLibDir, findBlender, hasBlenderLib } from "@kasaframe/gen";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
|
+
import type { Command } from "../command.ts";
|
|
6
|
+
import { num, parseFlags } from "../command.ts";
|
|
7
|
+
import { openSession } from "../browser.ts";
|
|
8
|
+
import { encoder } from "../ffmpeg.ts";
|
|
9
|
+
import { acquireRenderLock } from "../lock.ts";
|
|
10
|
+
import { fmtTime } from "../out.ts";
|
|
11
|
+
|
|
12
|
+
// 이 파일은 Blender 를 바깥 프로그램으로 띄우기만 한다(bpy 를 가져오지 않는다). bpy 를 쓰는 헬퍼·샷은 GPL 로 갈라 둔
|
|
13
|
+
// tools/blender 에 있고 npm 묶음에는 없다 — 근거는 tools/blender/README.md.
|
|
14
|
+
|
|
15
|
+
interface KfJson {
|
|
16
|
+
fps: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
duration: number;
|
|
20
|
+
beats?: string | null;
|
|
21
|
+
scenes?: { id: string; from: number; dur: number }[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function blenderLib(): string {
|
|
25
|
+
const dir = blenderLibDir();
|
|
26
|
+
if (!hasBlenderLib(dir)) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Blender 헬퍼(kfb.py·run.py)가 없다: ${dir}\n` +
|
|
29
|
+
"헬퍼는 bpy 를 써서 GPL-3.0 으로 갈라 두었고 npm 묶음에는 넣지 않았다 — 레포의 tools/blender 를 받아 KF_BLENDER_LIB=<그 폴더> 로 가리켜라.",
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return dir;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function findProject(given: string | undefined, shot: string): string {
|
|
36
|
+
if (given) {
|
|
37
|
+
if (!existsSync(join(resolve(given), "kf.json"))) throw new Error(`kf.json 이 없다: ${resolve(given)}`);
|
|
38
|
+
return resolve(given);
|
|
39
|
+
}
|
|
40
|
+
for (const start of [dirname(shot), process.cwd()]) {
|
|
41
|
+
for (let d = start; ; d = dirname(d)) {
|
|
42
|
+
if (existsSync(join(d, "kf.json"))) return d;
|
|
43
|
+
if (dirname(d) === d) break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
throw new Error("프로젝트(kf.json)를 못 찾았다 — --project <폴더>. fps·크기·beats.json 을 거기서 읽는다");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const cmd: Command = {
|
|
50
|
+
summary: "Blender 툰 3D 샷을 프로젝트 fps mp4 로 — 장면엔 <video data-kf-from>",
|
|
51
|
+
usage: `kf blender <샷.py> [--project <폴더>] [--scene <id> | --from 초 --to 초] [--id 이름]
|
|
52
|
+
--project kf.json 이 있는 폴더(기본: 샷 파일이나 지금 폴더에서 위로 찾는다) — fps·크기·beats.json 을 읽는다
|
|
53
|
+
--scene 그 장면의 시작·끝을 구간으로. 아니면 --from·--to(프로젝트 초, 기본 0..duration)
|
|
54
|
+
--id 결과 이름(기본 샷 파일 이름) → <프로젝트>/assets/blender/<id>.mp4 + <id>.json
|
|
55
|
+
--res 100 해상도 %(50 이면 절반 크기로 빨리 — 페이지가 늘려 보인다)
|
|
56
|
+
--samples 16 EEVEE 샘플
|
|
57
|
+
--step 1 N 프레임마다 한 장만 찍고 그 사이는 붙든다(2 = 애니메이션 「2코마」, 시간 반)
|
|
58
|
+
--still 1.2,4.5 그 시각들만 PNG 로(out/blender/<id>/still-<t>.png) — 굽기 전에 그림부터 본다
|
|
59
|
+
--blend 만든 장면을 out/blender/<id>.blend 로 저장(Blender 에서 열어 보기)
|
|
60
|
+
--match 앞 장면 마지막 화면·뒤 장면 첫 화면과 그 주인공 상자를 찍어 샷에 넘긴다 — 샷이 kfb.match_start·match_end 로
|
|
61
|
+
첫·끝 프레임을 그 2D 화면과 같은 구도로 맞추면(투영 일치) 경계가 컷이어도 공간이 이어진다. --scene 과 함께
|
|
62
|
+
--blender <실행 파일> 기본: BLENDER 환경 변수 → PATH 의 blender → /Applications/Blender*.app (4.3 이상)
|
|
63
|
+
--keep 다 묶은 뒤에도 PNG 를 out/blender/<id>/ 에 남긴다
|
|
64
|
+
--no-lock · --lock-wait 900 렌더 잠금(kf render 와 같은 것 — 무거운 일은 한 번에 하나)
|
|
65
|
+
|
|
66
|
+
샷 스크립트는 tools/blender/kfb.py 헬퍼로 짠다(예: tools/blender/shots/lighthouse.py). update(t) 가 t(프로젝트 초)만 보고 자세를 정하고,
|
|
67
|
+
카메라 열쇠는 S.downbeats·S.drops 같은 beats.json 박에 둔다. 헬퍼 위치는 KF_BLENDER_LIB 로 바꾼다.`,
|
|
68
|
+
async run(argv) {
|
|
69
|
+
const { args, opts } = parseFlags(argv);
|
|
70
|
+
if (!args[0]) {
|
|
71
|
+
console.error("kf blender: 샷 스크립트를 줘라 — kf blender <샷.py> --project <폴더>");
|
|
72
|
+
return 2;
|
|
73
|
+
}
|
|
74
|
+
const shot = resolve(args[0]);
|
|
75
|
+
if (!existsSync(shot)) throw new Error(`샷 스크립트가 없다: ${shot}`);
|
|
76
|
+
const lib = blenderLib();
|
|
77
|
+
const proj = findProject(typeof opts.project === "string" ? opts.project : undefined, shot);
|
|
78
|
+
const kf = JSON.parse(readFileSync(join(proj, "kf.json"), "utf8")) as KfJson;
|
|
79
|
+
const fps = kf.fps;
|
|
80
|
+
const id = typeof opts.id === "string" ? opts.id : basename(shot).replace(/\.py$/, "");
|
|
81
|
+
|
|
82
|
+
let from = num(opts.from, 0);
|
|
83
|
+
let to = num(opts.to, kf.duration);
|
|
84
|
+
if (typeof opts.scene === "string") {
|
|
85
|
+
const sc = kf.scenes?.find((s) => s.id === opts.scene);
|
|
86
|
+
if (!sc) throw new Error(`장면 ${opts.scene} 이 kf.json 에 없다 — ${(kf.scenes ?? []).map((s) => s.id).join(", ")}`);
|
|
87
|
+
from = sc.from;
|
|
88
|
+
to = sc.from + sc.dur;
|
|
89
|
+
}
|
|
90
|
+
// 프레임 시각은 어디서나 f / fps — kf render 처럼 [from, to) 에 드는 프레임을 센다. 클립 0 번은 전체 영상의 startF 번 프레임
|
|
91
|
+
const startF = Math.ceil(from * fps - 1e-6);
|
|
92
|
+
const endF = Math.min(Math.round(kf.duration * fps), Math.ceil(to * fps - 1e-6));
|
|
93
|
+
const count = endF - startF;
|
|
94
|
+
if (count <= 0) throw new Error(`구간이 비었다 (${from}..${to})`);
|
|
95
|
+
const t0 = startF / fps;
|
|
96
|
+
const step = Math.max(1, Math.round(num(opts.step, 1)));
|
|
97
|
+
const res = Math.max(1, Math.min(100, Math.round(num(opts.res, 100))));
|
|
98
|
+
|
|
99
|
+
const stills = typeof opts.still === "string" ? opts.still.split(",").map((s) => num(s.trim(), 0)) : null;
|
|
100
|
+
const frames = stills ? stills.map((t) => Math.max(0, Math.min(count - 1, Math.round((t - t0) * fps)))) : [];
|
|
101
|
+
if (!stills) for (let f = 0; f < count; f += step) frames.push(f);
|
|
102
|
+
const names = stills ? stills.map((t) => `still-${fmtTime(t)}`) : frames.map((f) => `f_${String(f).padStart(5, "0")}`);
|
|
103
|
+
|
|
104
|
+
const work = join(proj, "out", "blender", id);
|
|
105
|
+
rmSync(work, { recursive: true, force: true });
|
|
106
|
+
mkdirSync(work, { recursive: true });
|
|
107
|
+
const beats = kf.beats ? resolve(proj, kf.beats) : null;
|
|
108
|
+
const cfg = {
|
|
109
|
+
shot,
|
|
110
|
+
from: t0,
|
|
111
|
+
to: endF / fps,
|
|
112
|
+
fps,
|
|
113
|
+
width: kf.width,
|
|
114
|
+
height: kf.height,
|
|
115
|
+
res,
|
|
116
|
+
samples: Math.round(num(opts.samples, 16)),
|
|
117
|
+
frames,
|
|
118
|
+
names,
|
|
119
|
+
out: work,
|
|
120
|
+
beats: beats && existsSync(beats) ? beats : null,
|
|
121
|
+
blend: opts.blend ? join(proj, "out", "blender", `${id}.blend`) : null,
|
|
122
|
+
};
|
|
123
|
+
const cfgPath = join(proj, "out", "blender", `${id}.cfg.json`);
|
|
124
|
+
|
|
125
|
+
const { exe, version } = findBlender(typeof opts.blender === "string" ? opts.blender : undefined, (l) => console.error(`kf blender: ${l}`));
|
|
126
|
+
const release = opts["no-lock"] ? () => {} : await acquireRenderLock(proj, num(opts["lock-wait"], 900));
|
|
127
|
+
const started = Date.now();
|
|
128
|
+
try {
|
|
129
|
+
const match = opts.match && typeof opts.scene === "string" ? await matchFrames(proj, kf, opts.scene, work) : null;
|
|
130
|
+
writeFileSync(cfgPath, JSON.stringify({ ...cfg, match }, null, 2));
|
|
131
|
+
console.error(
|
|
132
|
+
`Blender ${version.join(".")} · ${relative(process.cwd(), shot)} · ${fmtTime(t0)}–${fmtTime(endF / fps)}초 · ` +
|
|
133
|
+
`${stills ? `스틸 ${frames.length}장` : `${count}프레임${step > 1 ? ` (${step}장마다 찍음 ${frames.length}장)` : ""}`} · ${Math.round((kf.width * res) / 100)}x${Math.round((kf.height * res) / 100)}`,
|
|
134
|
+
);
|
|
135
|
+
const perFrame = await runBlender(exe, lib, cfgPath);
|
|
136
|
+
|
|
137
|
+
if (stills) {
|
|
138
|
+
for (const n of names) console.log(join(work, `${n}.png`));
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
141
|
+
const usedFile = join(work, "match-used.json");
|
|
142
|
+
const used: string[] = existsSync(usedFile) ? JSON.parse(readFileSync(usedFile, "utf8")) : [];
|
|
143
|
+
|
|
144
|
+
const outDir = join(proj, "assets", "blender");
|
|
145
|
+
mkdirSync(outDir, { recursive: true });
|
|
146
|
+
const mp4 = join(outDir, `${id}.mp4`);
|
|
147
|
+
const enc = encoder(mp4, fps, "h264");
|
|
148
|
+
for (let f = 0; f < count; f++) {
|
|
149
|
+
const held = Math.floor(f / step) * step;
|
|
150
|
+
await enc.write(readFileSync(join(work, `f_${String(held).padStart(5, "0")}.png`)));
|
|
151
|
+
}
|
|
152
|
+
await enc.end();
|
|
153
|
+
|
|
154
|
+
// 디코더가 프레임 경계에서 앞 프레임을 집지 않게 반 프레임 앞을 0 으로 잡는다
|
|
155
|
+
const kfFrom = Number((t0 - 0.5 / fps).toFixed(6));
|
|
156
|
+
const elapsed = (Date.now() - started) / 1000;
|
|
157
|
+
const meta = {
|
|
158
|
+
shot: relative(proj, shot),
|
|
159
|
+
blender: version.join("."),
|
|
160
|
+
from: t0,
|
|
161
|
+
to: endF / fps,
|
|
162
|
+
fps,
|
|
163
|
+
frames: count,
|
|
164
|
+
step,
|
|
165
|
+
res,
|
|
166
|
+
samples: cfg.samples,
|
|
167
|
+
width: Math.round((kf.width * res) / 100),
|
|
168
|
+
height: Math.round((kf.height * res) / 100),
|
|
169
|
+
secPerFrame: Number(perFrame.toFixed(3)),
|
|
170
|
+
elapsedSec: Number(elapsed.toFixed(1)),
|
|
171
|
+
dataKfFrom: kfFrom,
|
|
172
|
+
...(used.length ? { match: { in: used.includes("in"), out: used.includes("out") } } : {}),
|
|
173
|
+
renderedAt: new Date().toISOString(),
|
|
174
|
+
};
|
|
175
|
+
writeFileSync(join(outDir, `${id}.json`), `${JSON.stringify(meta, null, 2)}\n`);
|
|
176
|
+
// 첫·끝 프레임을 앞뒤 2D 화면과 투영 일치로 맞췄으면 그 장면에 적는다 — 감독은 matched 장면 경계에 이음매를 넣지 않는다(컷으로 이어진다)
|
|
177
|
+
if (used.length && typeof opts.scene === "string") {
|
|
178
|
+
const file = join(proj, "kf.json");
|
|
179
|
+
const doc = JSON.parse(readFileSync(file, "utf8"));
|
|
180
|
+
const sc = doc.scenes?.find((x: { id: string }) => x.id === opts.scene);
|
|
181
|
+
if (sc) {
|
|
182
|
+
sc.matched = true;
|
|
183
|
+
writeFileSync(file, `${JSON.stringify(doc, null, 2)}\n`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (!opts.keep) rmSync(work, { recursive: true, force: true });
|
|
187
|
+
console.error(`${count}프레임 · 한 장 ${perFrame.toFixed(2)}초 · 모두 ${Math.round(elapsed)}초`);
|
|
188
|
+
console.error(`장면에서: <video src="\${ctx.asset("blender/${id}.mp4")}" data-kf-from="${kfFrom}" muted playsinline>`);
|
|
189
|
+
console.log(mp4);
|
|
190
|
+
return 0;
|
|
191
|
+
} finally {
|
|
192
|
+
release();
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
export default cmd;
|
|
197
|
+
|
|
198
|
+
interface Rect {
|
|
199
|
+
x: number;
|
|
200
|
+
y: number;
|
|
201
|
+
w: number;
|
|
202
|
+
h: number;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 샷 앞 장면의 마지막 프레임·뒤 장면의 첫 프레임과 그 장면이 짚은 주인공([data-kf-hero]) 상자(화면 비율, 왼쪽 위 0).
|
|
206
|
+
// 샷 자리의 장면은 찍지 않으니 샷 영상이 아직 없어도 된다
|
|
207
|
+
async function matchFrames(proj: string, kf: KfJson, sceneId: string, work: string): Promise<{ in?: string; inHero?: Rect; out?: string; outHero?: Rect } | null> {
|
|
208
|
+
const list = kf.scenes ?? [];
|
|
209
|
+
const i = list.findIndex((s) => s.id === sceneId);
|
|
210
|
+
const prev = list[i - 1];
|
|
211
|
+
const next = list[i + 1];
|
|
212
|
+
if (i < 0 || (!prev && !next)) return null;
|
|
213
|
+
const s = await openSession(proj);
|
|
214
|
+
try {
|
|
215
|
+
const grab = async (t: number, id: string, file: string) => {
|
|
216
|
+
await s.first.seek(t);
|
|
217
|
+
writeFileSync(file, await s.first.capture());
|
|
218
|
+
const hero = await s.first.page.evaluate((sid) => {
|
|
219
|
+
const stage = document.getElementById("stage") ?? document.body;
|
|
220
|
+
const el = document.querySelector(`[data-kf-scene="${sid}"] [data-kf-hero]`);
|
|
221
|
+
if (!el) return null;
|
|
222
|
+
const b = stage.getBoundingClientRect();
|
|
223
|
+
const r = el.getBoundingClientRect();
|
|
224
|
+
return { x: (r.left - b.left) / b.width, y: (r.top - b.top) / b.height, w: r.width / b.width, h: r.height / b.height };
|
|
225
|
+
}, id);
|
|
226
|
+
return { file, hero: hero ?? undefined };
|
|
227
|
+
};
|
|
228
|
+
const out: { in?: string; inHero?: Rect; out?: string; outHero?: Rect } = {};
|
|
229
|
+
if (prev) {
|
|
230
|
+
const g = await grab(prev.from + prev.dur - 1 / kf.fps, prev.id, join(work, "match-in.png"));
|
|
231
|
+
out.in = g.file;
|
|
232
|
+
out.inHero = g.hero;
|
|
233
|
+
}
|
|
234
|
+
if (next) {
|
|
235
|
+
const g = await grab(next.from, next.id, join(work, "match-out.png"));
|
|
236
|
+
out.out = g.file;
|
|
237
|
+
out.outHero = g.hero;
|
|
238
|
+
}
|
|
239
|
+
console.error(`kf blender: 맞출 화면 — ${prev ? `앞 ${prev.id} 끝` : ""}${prev && next ? " · " : ""}${next ? `뒤 ${next.id} 처음` : ""}`);
|
|
240
|
+
return out;
|
|
241
|
+
} finally {
|
|
242
|
+
await s.close();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Blender 를 헤드리스로 돌리고 KFB 줄로 진행을 센다. 평균 한 장 시간(첫 장의 셰이더 컴파일 빼고)을 돌려준다.
|
|
247
|
+
function runBlender(exe: string, lib: string, cfgPath: string): Promise<number> {
|
|
248
|
+
return new Promise((resolveRun, reject) => {
|
|
249
|
+
const proc = spawn(exe, ["-b", "--factory-startup", "--python-exit-code", "1", "-P", join(lib, "run.py"), "--", cfgPath], {
|
|
250
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
251
|
+
});
|
|
252
|
+
const tail: string[] = [];
|
|
253
|
+
const times: number[] = [];
|
|
254
|
+
let total = 0;
|
|
255
|
+
let lastShown = 0;
|
|
256
|
+
let buf = "";
|
|
257
|
+
const onData = (d: Buffer) => {
|
|
258
|
+
buf += d.toString();
|
|
259
|
+
let nl: number;
|
|
260
|
+
while ((nl = buf.indexOf("\n")) >= 0) {
|
|
261
|
+
const line = buf.slice(0, nl).trimEnd();
|
|
262
|
+
buf = buf.slice(nl + 1);
|
|
263
|
+
tail.push(line);
|
|
264
|
+
if (tail.length > 60) tail.shift();
|
|
265
|
+
const m = /^KFB (start|frame) (\d+)(?: (\d+) ([\d.]+))?/.exec(line);
|
|
266
|
+
if (!m) continue;
|
|
267
|
+
if (m[1] === "start") {
|
|
268
|
+
total = Number(m[2]);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
times.push(Number(m[4]));
|
|
272
|
+
const i = Number(m[2]);
|
|
273
|
+
if (i === total || Date.now() - lastShown > 5000) {
|
|
274
|
+
lastShown = Date.now();
|
|
275
|
+
const steady = times.length > 1 ? times.slice(1) : times;
|
|
276
|
+
const avg = steady.reduce((a, b) => a + b, 0) / steady.length;
|
|
277
|
+
console.error(` ${i}/${total} · 한 장 ${avg.toFixed(2)}초 · 남은 ~${Math.ceil(((total - i) * avg) / 60)}분`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
proc.stdout.on("data", onData);
|
|
282
|
+
proc.stderr.on("data", onData);
|
|
283
|
+
proc.on("error", (e) => reject(new Error(`Blender 를 못 띄웠다: ${e.message}`)));
|
|
284
|
+
proc.on("close", (code) => {
|
|
285
|
+
if (code === 0 && times.length === total && total > 0) {
|
|
286
|
+
const steady = times.length > 1 ? times.slice(1) : times;
|
|
287
|
+
resolveRun(steady.reduce((a, b) => a + b, 0) / steady.length);
|
|
288
|
+
} else {
|
|
289
|
+
reject(new Error(`Blender 가 실패했다 (종료 ${code}, ${times.length}/${total}장)\n${tail.join("\n")}`));
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import type { Command } from "../command.ts";
|
|
3
|
+
import { parseFlags } from "../command.ts";
|
|
4
|
+
import { acquireRenderLock } from "../lock.ts";
|
|
5
|
+
import { run, usage } from "@kasaframe/check";
|
|
6
|
+
|
|
7
|
+
// 검사도 크롬으로 영상 전체를 훑는 무거운 일이라 렌더와 같은 잠금을 잡는다 — 한 기계에서 하나씩
|
|
8
|
+
const cmd: Command = {
|
|
9
|
+
summary: "검사 — 멈춤·빈 화면·화면 글(undefined·두부)·화면 밖 글·대비·결정성·박 경계·움직임 규칙",
|
|
10
|
+
usage: `${usage}\n --no-lock 렌더 잠금(.render-lock) 없이 — 짧은 구간 시험용\n --captions on|off|fit 화면 자막을 켜고(끄고) 훑는다 — kf render --captions 로 구운 판과 같은 화면`,
|
|
11
|
+
async run(argv) {
|
|
12
|
+
// --captions 는 페이지 질의로 넘긴다(mountProject 가 읽는다)
|
|
13
|
+
const at = argv.indexOf("--captions");
|
|
14
|
+
if (at >= 0) argv = [...argv.slice(0, at), "--query", `captions=${argv[at + 1]}`, ...argv.slice(at + 2)];
|
|
15
|
+
const { args, opts } = parseFlags(argv);
|
|
16
|
+
if (opts["no-lock"] || !args[0]) return run(argv.filter((a) => a !== "--no-lock"));
|
|
17
|
+
const release = await acquireRenderLock(resolve(args[0]), 900);
|
|
18
|
+
try {
|
|
19
|
+
return await run(argv);
|
|
20
|
+
} finally {
|
|
21
|
+
release();
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
export default cmd;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { copyFileSync, existsSync, readFileSync, rmSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { build, checkContent, type Content, layout, type Problem, type Report } from "@kasaframe/director";
|
|
6
|
+
import { questionsText } from "@kasaframe/gen";
|
|
7
|
+
import { parseDuration } from "@kasaframe/plan";
|
|
8
|
+
import { type Command, num, parseFlags } from "../command.ts";
|
|
9
|
+
|
|
10
|
+
const kfBin = fileURLToPath(new URL("../kf.ts", import.meta.url));
|
|
11
|
+
// 검사가 떨어뜨려도 패턴 탓이 아닌 규칙 — 장면 경계(시간표)·생성 자산·자막 판
|
|
12
|
+
const NOT_PATTERN = /^(beat\.|asset\.|caption\.)/;
|
|
13
|
+
// 생성 능력 질문의 답 — kf make 로 그대로 넘긴다
|
|
14
|
+
const PASS = ["image", "video", "blender", "voice", "music", "allow", "series", "theme", "purpose"];
|
|
15
|
+
|
|
16
|
+
const cmd: Command = {
|
|
17
|
+
summary: "감독 모드 — content.json(무엇을 보일지)에서 장면 문법·전환·바탕을 골라 장면 파일을 조립(LLM 없이)",
|
|
18
|
+
usage: `kf direct <content.json|프로젝트 폴더> [--out 폴더] [--seed 글] [--series id] [--voice …] [--music …]
|
|
19
|
+
content.json 의 장면마다(type·칸·say·source) 감독이 검증된 장면 문법(패턴) 후보에 점수를 매겨 — 테마 궁합·용도·곡 구간 에너지(벌스·후렴·드롭)·
|
|
20
|
+
앞뒤 장면과 계열·카메라 안 겹치기 — 씨앗 고정 난수로 고르고, 패턴 매개변수를 내용으로 채워 장면 파일을 쓴다. 장면 사이 이음매(3D 전환)도
|
|
21
|
+
감독이 고른다(기본 dive, 같은 전환 연속 금지, 2D↔3D 경계는 공간 잇기). 같은 content.json·시리즈·씨앗이면 장면 파일이 바이트까지 같다.
|
|
22
|
+
|
|
23
|
+
폴더가 아직 없으면 content.json 의 request(없으면 title)로 kf make 뼈대(용도·테마·목소리·곡 묻기 포함)를 먼저 세운다 — 기본 폴더는 content.json 옆 같은 이름.
|
|
24
|
+
순서: 칸 검사 → 시간표(이음매 포함) → kf narrate(say 를 읽혀 장면 길이를 목소리에) → 패턴 고르기·장면 파일 → kf check(떨어진 장면만 다음 후보로, --retries 번)
|
|
25
|
+
|
|
26
|
+
--seed 다른 고름을 본다(같은 씨앗이면 늘 같은 그림). 기본 content.json 의 seed, 없으면 0
|
|
27
|
+
--scenes a,b 그 장면만 다시 짓는다 — 시간표·다른 장면 파일·이음매는 바이트까지 그대로(조각 렌더가 바뀐 장면만 다시 굽게)
|
|
28
|
+
--pattern a=<패턴 id>[,b=…] 사람이 고른 후보(director.json 의 order) · --scene-seed a=<글>[,…] 그 장면만 다른 그림
|
|
29
|
+
고른 값은 director.json 의 pinned 에 남아 다음 kf direct 도 지킨다
|
|
30
|
+
진행 줄(stderr): 「장면 <id>: 쓰는 중」·「장면 <id>: 씀」·「장면 <id>: 실패 <까닭>」(굽기·검사까지 끝난 「끝」은 작업실·render 몫)
|
|
31
|
+
--no-narrate 목소리 없이 어림 길이로 · --no-check 검사 없이 · --retries N(기본 2) · --finish 다 되면 kf make --finish(렌더·표지·자막)
|
|
32
|
+
--no-lock 검사 고리만 렌더 잠금 없이(남의 긴 굽기 뒤에서 기다리지 않게) — --finish 의 굽기는 그대로 잠금
|
|
33
|
+
--image · --video · --blender · --voice · --music · --allow · --yes · --no-gen 뼈대를 세울 때 묻기 답(kf make 와 같다)
|
|
34
|
+
결과: kf.json(장면·패턴·전환) · scenes/*.ts · captions.json · director.json(장면마다 후보 점수·까닭·떨어진 것)`,
|
|
35
|
+
async run(argv) {
|
|
36
|
+
const { args, opts } = parseFlags(argv);
|
|
37
|
+
const str = (k: string) => (typeof opts[k] === "string" ? (opts[k] as string) : undefined);
|
|
38
|
+
const target = args[0] ? resolve(args[0]) : undefined;
|
|
39
|
+
if (!target || !existsSync(target)) {
|
|
40
|
+
console.error("kf direct: content.json 이나 그것이 든 프로젝트 폴더가 필요하다 — kf direct --help");
|
|
41
|
+
return 2;
|
|
42
|
+
}
|
|
43
|
+
const isDir = !extname(target) || existsSync(join(target, "kf.json"));
|
|
44
|
+
const file = isDir ? join(target, "content.json") : target;
|
|
45
|
+
if (!existsSync(file)) {
|
|
46
|
+
console.error(`kf direct: ${file} 가 없다 — 지시서(MAKE.md)의 「content.json 꼴」대로 먼저 쓴다`);
|
|
47
|
+
return 2;
|
|
48
|
+
}
|
|
49
|
+
const dir = isDir ? target : existsSync(join(dirname(target), "kf.json")) ? dirname(target) : resolve(str("out") ?? join(dirname(target), basename(target, extname(target))));
|
|
50
|
+
|
|
51
|
+
let raw: unknown;
|
|
52
|
+
try {
|
|
53
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.error(`kf direct: ${file} 가 JSON 이 아니다 — ${e instanceof Error ? e.message : e}`);
|
|
56
|
+
return 1;
|
|
57
|
+
}
|
|
58
|
+
const checked = checkContent(raw);
|
|
59
|
+
const say = (p: Problem) => ` ${p.at}: ${p.msg}`;
|
|
60
|
+
if (checked.warnings.length) console.error(`content.json 고친 곳·볼 곳 ${checked.warnings.length}:\n${checked.warnings.map(say).join("\n")}`);
|
|
61
|
+
if (checked.errors.length) {
|
|
62
|
+
console.error(`kf direct: content.json 칸이 틀렸다 ${checked.errors.length}곳 — 고치고 다시:\n${checked.errors.map(say).join("\n")}`);
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
const content: Content = checked.content;
|
|
66
|
+
|
|
67
|
+
// 뼈대 — 용도·테마·목소리·곡 묻기는 kf make 와 같은 길을 지난다
|
|
68
|
+
if (!existsSync(join(dir, "kf.json"))) {
|
|
69
|
+
const req = content.request ?? content.title;
|
|
70
|
+
const request = content.duration && parseDuration(req) === undefined ? `${req} ${content.duration}초` : req;
|
|
71
|
+
const make = [kfBin, "make", request, "--out", dir, "--model", "claude-code", "--title", content.title];
|
|
72
|
+
for (const [k, v] of [["series", content.series], ["purpose", content.purpose], ["theme", content.theme], ["voice", content.voice], ["music", content.music]] as const) if (v && str(k) === undefined) make.push(`--${k}`, v);
|
|
73
|
+
for (const k of PASS) if (str(k)) make.push(`--${k}`, str(k)!);
|
|
74
|
+
for (const k of ["yes", "no-gen"]) if (opts[k]) make.push(`--${k}`);
|
|
75
|
+
const r = spawnSync(process.execPath, make, { stdio: ["inherit", "inherit", "inherit"] });
|
|
76
|
+
if (r.status !== 0) return r.status ?? 1;
|
|
77
|
+
} else if (PASS.some((k) => str(k)) && planAsks(dir).length) {
|
|
78
|
+
const flags = PASS.filter((k) => str(k)).flatMap((k) => [`--${k}`, str(k)!]);
|
|
79
|
+
const r = spawnSync(process.execPath, [kfBin, "make", "--answer", dir, ...flags], { stdio: "inherit" });
|
|
80
|
+
if (r.status !== 0) return r.status ?? 1;
|
|
81
|
+
}
|
|
82
|
+
const open = planAsks(dir);
|
|
83
|
+
if (open.length) {
|
|
84
|
+
console.error(`kf direct: 만들기 전에 정할 것이 ${open.length}가지 — 사람에게 묻고 플래그로 답해 다시 부른다\n\n${questionsText(open as never)}\n\n kf direct ${args[0]} ${open.map((q) => `${q.flag} <값>`).join(" ")}`);
|
|
85
|
+
return 3;
|
|
86
|
+
}
|
|
87
|
+
if (resolve(file) !== join(dir, "content.json")) copyFileSync(file, join(dir, "content.json"));
|
|
88
|
+
|
|
89
|
+
const only = str("scenes")?.split(",").map((x) => x.trim()).filter(Boolean);
|
|
90
|
+
const pins: Record<string, { pattern?: string; seed?: string }> = {};
|
|
91
|
+
for (const [flag, k] of [["pattern", "pattern"], ["scene-seed", "seed"]] as const)
|
|
92
|
+
for (const pair of (str(flag) ?? "").split(",").filter(Boolean)) {
|
|
93
|
+
const eq = pair.indexOf("=");
|
|
94
|
+
if (eq < 1) {
|
|
95
|
+
console.error(`kf direct: --${flag} 는 <장면>=<값> — "${pair}"`);
|
|
96
|
+
return 2;
|
|
97
|
+
}
|
|
98
|
+
(pins[pair.slice(0, eq)] ??= {})[k] = pair.slice(eq + 1);
|
|
99
|
+
}
|
|
100
|
+
// 고른 장면만이면 시간표를 다시 놓지 않는다 — 다른 장면의 시각이 한 프레임도 안 움직이게
|
|
101
|
+
if (!only) {
|
|
102
|
+
const { seams } = layout(dir, content, { keepTiming: !!opts["no-narrate"] });
|
|
103
|
+
console.error(`시간표: 장면 ${content.scenes.length} + 이음매 ${seams}`);
|
|
104
|
+
}
|
|
105
|
+
if (!opts["no-narrate"]) {
|
|
106
|
+
const hasSay = content.scenes.some((s) => s.say?.trim());
|
|
107
|
+
const n = [kfBin, "narrate", dir];
|
|
108
|
+
const voice = str("voice") ?? content.voice ?? (hasSay ? undefined : "none");
|
|
109
|
+
if (voice) n.push("--voice", voice);
|
|
110
|
+
if (str("music") ?? content.music) n.push("--music", (str("music") ?? content.music)!);
|
|
111
|
+
const r = spawnSync(process.execPath, n, { stdio: ["inherit", "inherit", "inherit"] });
|
|
112
|
+
if (r.status !== 0) {
|
|
113
|
+
console.error("kf direct: 내레이션(kf narrate)에서 멈췄다 — 위 보기대로 답하거나 --no-narrate 로 어림 길이");
|
|
114
|
+
return r.status ?? 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const seed = str("seed");
|
|
119
|
+
const log = (l: string) => console.error(l);
|
|
120
|
+
let report: Report;
|
|
121
|
+
try {
|
|
122
|
+
report = await build(dir, content, { seed, only, pins, log });
|
|
123
|
+
} catch (e) {
|
|
124
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
125
|
+
for (const id of only ?? []) console.error(`장면 ${id}: 실패 ${msg}`);
|
|
126
|
+
console.error(`kf direct: ${msg}`);
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
print(dir, report);
|
|
130
|
+
let code = 0;
|
|
131
|
+
if (!opts["no-check"]) {
|
|
132
|
+
const retries = num(opts.retries, 2);
|
|
133
|
+
for (let round = 0; ; round++) {
|
|
134
|
+
// 옛 결과를 치우고 돌린다 — 검사가 돌지 못하고 끝나면 옛 check.json 을 이번 결과로 읽게 된다
|
|
135
|
+
const report_ = join(dir, "out", "check.json");
|
|
136
|
+
const fresh = () => {
|
|
137
|
+
rmSync(report_, { force: true });
|
|
138
|
+
return spawnSync(process.execPath, [kfBin, "check", dir, ...(opts["no-lock"] ? ["--no-lock"] : [])], { encoding: "utf8" });
|
|
139
|
+
};
|
|
140
|
+
let r = fresh();
|
|
141
|
+
// 남의 긴 굽기가 잠금을 쥐면 검사가 15분 기다리다 물러난다 — 한 시간까지 다시 줄을 선다
|
|
142
|
+
for (let wait = 0; /잠금을 못 얻었다/.test(r.stderr ?? "") && wait < 4; wait++) {
|
|
143
|
+
console.error("kf check: 다른 굽기가 잠금을 쥐고 있어 다시 기다린다");
|
|
144
|
+
r = fresh();
|
|
145
|
+
}
|
|
146
|
+
code = r.status ?? 1;
|
|
147
|
+
if (code === 0) {
|
|
148
|
+
console.log("kf check 통과");
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
if (code !== 1 || !existsSync(report_)) {
|
|
152
|
+
console.error(`kf check 를 못 돌렸다(종료 ${code}) — ${`${r.stderr ?? ""}`.trim().split("\n").slice(-3).join(" / ")}`);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
const blame = blameScenes(dir, report);
|
|
156
|
+
console.error(`kf check 오류 — ${blame.lines.join(" · ")}`);
|
|
157
|
+
if (round >= retries || (!Object.keys(blame.failed).length && !Object.keys(blame.seamFailed).length)) break;
|
|
158
|
+
try {
|
|
159
|
+
report = await build(dir, content, { seed, failed: blame.failed, seamFailed: blame.seamFailed, log });
|
|
160
|
+
} catch (e) {
|
|
161
|
+
console.error(`kf direct: ${e instanceof Error ? e.message : e}`);
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
console.error(`다시 지음(${round + 1}/${retries}) — ${[...Object.entries(blame.failed), ...Object.entries(blame.seamFailed)].map(([id]) => `${id} → ${report.scenes.find((s) => s.id === id)?.pattern ?? report.scenes.find((s) => s.id === id)?.transition}`).join(" · ")}`);
|
|
165
|
+
}
|
|
166
|
+
if (code !== 0) console.error(`kf check 가 아직 떨어진다 — ${dir}/out/check.json 을 보고 content.json 을 고치거나 --seed 를 바꿔 다시`);
|
|
167
|
+
}
|
|
168
|
+
if (opts.finish && code === 0) {
|
|
169
|
+
const r = spawnSync(process.execPath, [kfBin, "make", "--finish", dir], { stdio: "inherit" });
|
|
170
|
+
return r.status ?? 1;
|
|
171
|
+
}
|
|
172
|
+
if (!opts.finish) console.log(`\n다음: kf look ${dir} 로 장면 모음을 보고 → kf make --finish ${dir}`);
|
|
173
|
+
return code;
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
export default cmd;
|
|
177
|
+
|
|
178
|
+
function planAsks(dir: string): { id: string; flag: string }[] {
|
|
179
|
+
const p = join(dir, "plan.json");
|
|
180
|
+
return existsSync(p) ? (JSON.parse(readFileSync(p, "utf8")).asks ?? []) : [];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function print(dir: string, r: Report): void {
|
|
184
|
+
console.log(`${dir} — 씨앗 ${r.seed} · ${r.purpose} ${r.aspect}${r.theme ? ` · 테마 ${r.theme}` : ""}`);
|
|
185
|
+
for (const s of r.scenes) {
|
|
186
|
+
const what = s.transition ? `이음매 ${s.transition}` : s.custom ? `custom(${s.custom === "kept" ? "있는 파일" : "뼈대 — 직접 쓴다"})` : `${s.pattern}${s.energy ? ` · ${s.energy}` : ""}${s.attempt ? ` · ${s.attempt + 1}번째 후보` : ""}`;
|
|
187
|
+
console.log(` ${s.from.toFixed(2).padStart(6)}–${(s.from + s.dur).toFixed(2).padEnd(6)} ${s.id.padEnd(10)} ${(s.type ?? "").padEnd(12)} ${what}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// out/check.json 의 오류를 시각으로 장면에 묶는다 — 패턴 장면은 그 패턴을, 이음매는 그 전환을 떨어뜨린다
|
|
192
|
+
function blameScenes(dir: string, r: Report): { failed: Record<string, string[]>; seamFailed: Record<string, string[]>; lines: string[] } {
|
|
193
|
+
const p = join(dir, "out", "check.json");
|
|
194
|
+
const failed: Record<string, string[]> = {};
|
|
195
|
+
const seamFailed: Record<string, string[]> = {};
|
|
196
|
+
const lines: string[] = [];
|
|
197
|
+
if (!existsSync(p)) return { failed, seamFailed, lines };
|
|
198
|
+
const findings = (JSON.parse(readFileSync(p, "utf8")).findings ?? []) as { rule: string; severity: string; from: number }[];
|
|
199
|
+
for (const f of findings) {
|
|
200
|
+
if (f.severity !== "error") continue;
|
|
201
|
+
const s = r.scenes.find((x) => f.from >= x.from - 1e-6 && f.from < x.from + x.dur) ?? r.scenes.at(-1)!;
|
|
202
|
+
lines.push(`${s.id} ${f.rule}`);
|
|
203
|
+
if (NOT_PATTERN.test(f.rule)) continue;
|
|
204
|
+
if (s.pattern) failed[s.id] = [...new Set([...(failed[s.id] ?? []), s.pattern])];
|
|
205
|
+
else if (s.transition) seamFailed[s.id] = [...new Set([...(seamFailed[s.id] ?? []), s.transition])];
|
|
206
|
+
}
|
|
207
|
+
const count = new Map<string, number>();
|
|
208
|
+
for (const l of lines) count.set(l, (count.get(l) ?? 0) + 1);
|
|
209
|
+
return { failed, seamFailed, lines: [...count].map(([l, n]) => (n > 1 ? `${l}×${n}` : l)) };
|
|
210
|
+
}
|