@oh-story/dsh 0.1.4 → 0.1.5

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 (479) hide show
  1. package/README.md +56 -12
  2. package/lib/client.js +2692 -268
  3. package/lib/client.js.map +4 -4
  4. package/lib/drama/manifest.json +136 -101
  5. package/lib/drama/skills/short-drama/SKILL.md +61 -1
  6. package/lib/drama/skills/short-drama/references/contract-and-ownership.md +7 -4
  7. package/lib/drama/skills/short-drama/references/creator-documents.md +133 -8
  8. package/lib/drama/skills/short-drama/references/creator-workflow.md +38 -2
  9. package/lib/drama/skills/short-drama/references/knowhow-index.md +3 -0
  10. package/lib/drama/skills/short-drama/references/reference-roles.md +10 -7
  11. package/lib/drama/skills/short-drama/references/runtime-preflight.md +3 -0
  12. package/lib/drama/skills/short-drama/scripts/creator_markdown_check.py +1002 -0
  13. package/lib/drama/skills/short-drama/scripts/project_tool.py +485 -5
  14. package/lib/drama/skills/short-drama-assets/SKILL.md +13 -3
  15. package/lib/drama/skills/short-drama-assets/references/continuity-lock.md +116 -0
  16. package/lib/drama/skills/short-drama-assets/references/identity-vs-variant.md +2 -1
  17. package/lib/drama/skills/short-drama-assets/references/prop-and-state.md +19 -0
  18. package/lib/drama/skills/short-drama-assets/references/stage-contract.md +2 -0
  19. package/lib/drama/skills/short-drama-assets/scripts/asset_check.py +1 -1
  20. package/lib/drama/skills/short-drama-image-prompts/SKILL.md +6 -2
  21. package/lib/drama/skills/short-drama-image-prompts/references/common-recipe.md +4 -3
  22. package/lib/drama/skills/short-drama-image-prompts/references/lookdev-frame.md +1 -1
  23. package/lib/drama/skills/short-drama-image-prompts/references/review-and-fixtures.md +1 -1
  24. package/lib/drama/skills/short-drama-image-prompts/references/stage-contract.md +3 -1
  25. package/lib/drama/skills/short-drama-image-prompts/scripts/image_prompt_check.py +8 -8
  26. package/lib/drama/skills/short-drama-image-prompts/scripts/selftest.py +4 -2
  27. package/lib/drama/skills/short-drama-produce/SKILL.md +46 -10
  28. package/lib/drama/skills/short-drama-produce/references/adapter-contract.md +65 -8
  29. package/lib/drama/skills/short-drama-produce/references/providers/minimax-h3-video.md +85 -0
  30. package/lib/drama/skills/short-drama-produce/references/providers/seedance.md +27 -10
  31. package/lib/drama/skills/short-drama-produce/scripts/production_tool.py +362 -3
  32. package/lib/drama/skills/short-drama-produce/scripts/provider_adapters.py +627 -40
  33. package/lib/drama/skills/short-drama-produce/scripts/selftest.py +5 -4
  34. package/lib/drama/skills/short-drama-review/references/rubric-visual-motion.md +12 -0
  35. package/lib/drama/skills/short-drama-review/scripts/review_check.py +1 -1
  36. package/lib/drama/skills/short-drama-storyboard/SKILL.md +76 -7
  37. package/lib/drama/skills/short-drama-storyboard/assets/shot-template.jsonl +1 -1
  38. package/lib/drama/skills/short-drama-storyboard/references/keyframe-craft.md +6 -2
  39. package/lib/drama/skills/short-drama-storyboard/references/production-shot-grammar.md +19 -4
  40. package/lib/drama/skills/short-drama-storyboard/references/review-and-fixtures.md +5 -2
  41. package/lib/drama/skills/short-drama-storyboard/references/screenplay-to-keyframe-example.md +16 -0
  42. package/lib/drama/skills/short-drama-storyboard/references/stage-contract.md +8 -3
  43. package/lib/drama/skills/short-drama-storyboard/scripts/storyboard_check.py +1 -1
  44. package/lib/drama/skills/short-drama-video-prompts/SKILL.md +81 -13
  45. package/lib/drama/skills/short-drama-video-prompts/assets/motion-spec.jsonl.md +6 -1
  46. package/lib/drama/skills/short-drama-video-prompts/assets/video-prompts.md +17 -1
  47. package/lib/drama/skills/short-drama-video-prompts/references/delivery-profile.md +21 -1
  48. package/lib/drama/skills/short-drama-video-prompts/references/minimax-h3.md +154 -0
  49. package/lib/drama/skills/short-drama-video-prompts/references/motion-recipe.md +24 -6
  50. package/lib/drama/skills/short-drama-video-prompts/references/production-prompt-grammar.md +11 -7
  51. package/lib/drama/skills/short-drama-video-prompts/references/seedance-2.0.md +41 -0
  52. package/lib/drama/skills/short-drama-video-prompts/references/seedance-2.5.md +66 -0
  53. package/lib/drama/skills/short-drama-video-prompts/references/stage-contract.md +5 -2
  54. package/lib/drama/skills/short-drama-video-prompts/references/target-model-profile.md +115 -0
  55. package/lib/drama/skills/short-drama-video-prompts/scripts/container_check.py +1 -1
  56. package/lib/drama/skills/short-drama-video-prompts/scripts/music_spec_check.py +1 -1
  57. package/lib/drama/skills/short-drama-write/SKILL.md +3 -2
  58. package/lib/drama/skills/short-drama-write/scripts/duration_estimate.py +1 -1
  59. package/lib/drama/skills/short-drama-write/scripts/screenplay_index.py +2 -2
  60. package/lib/drama/skills/short-drama-write/scripts/voice_sheet_check.py +1 -1
  61. package/lib/index.js +865 -33
  62. package/lib/index.js.map +4 -4
  63. package/lib/novel-to-game/LICENSE +21 -0
  64. package/lib/novel-to-game/README.md +180 -0
  65. package/lib/novel-to-game/README_ZH.md +178 -0
  66. package/lib/novel-to-game/VERSION +1 -0
  67. package/lib/novel-to-game/examples/jin-ping-mei/build/BUILD_BRIEF.md +217 -0
  68. package/lib/novel-to-game/examples/jin-ping-mei/build/app/.vercelignore +3 -0
  69. package/lib/novel-to-game/examples/jin-ping-mei/build/app/RUN.md +130 -0
  70. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/bg/compound_new_guofeng.webp +0 -0
  71. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/fate_coda.webp +0 -0
  72. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/meng.webp +0 -0
  73. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/pan.webp +0 -0
  74. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/pinger.webp +0 -0
  75. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/xuee.webp +0 -0
  76. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/yue.webp +0 -0
  77. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/inner_court_accord_five.webp +0 -0
  78. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/inner_court_afterglow_five.webp +0 -0
  79. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/inner_court_alliance.webp +0 -0
  80. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/public_day10.webp +0 -0
  81. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/public_day15.webp +0 -0
  82. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/public_day5.webp +0 -0
  83. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/title_new_guofeng.webp +0 -0
  84. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/joint/pan_pinger.webp +0 -0
  85. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/joint/pan_xuee.webp +0 -0
  86. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/joint/yue_meng.webp +0 -0
  87. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/joint/yue_pan.webp +0 -0
  88. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/joint/yue_pinger.webp +0 -0
  89. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/meng/explicit.webp +0 -0
  90. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/meng/prelude.webp +0 -0
  91. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/milestone/meng.webp +0 -0
  92. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/milestone/pan.webp +0 -0
  93. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/milestone/pinger.webp +0 -0
  94. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/milestone/xuee.webp +0 -0
  95. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/milestone/yue.webp +0 -0
  96. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/pan/explicit.webp +0 -0
  97. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/pan/prelude.webp +0 -0
  98. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/pinger/explicit.webp +0 -0
  99. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/pinger/prelude.webp +0 -0
  100. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/xuee/explicit.webp +0 -0
  101. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/xuee/prelude.webp +0 -0
  102. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/yue/explicit.webp +0 -0
  103. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/yue/prelude.webp +0 -0
  104. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/heroine/meng/night.webp +0 -0
  105. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/heroine/pan/night.webp +0 -0
  106. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/heroine/pinger/night.webp +0 -0
  107. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/heroine/xuee/night.webp +0 -0
  108. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/heroine/yue/night.webp +0 -0
  109. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/household/li_jiaoer.webp +0 -0
  110. package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/scene/gate_collector.webp +0 -0
  111. package/lib/novel-to-game/examples/jin-ping-mei/build/app/css/new-guofeng.css +1105 -0
  112. package/lib/novel-to-game/examples/jin-ping-mei/build/app/css/style.css +2539 -0
  113. package/lib/novel-to-game/examples/jin-ping-mei/build/app/index.html +18 -0
  114. package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/assets.js +147 -0
  115. package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/audio.js +332 -0
  116. package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/data.js +7472 -0
  117. package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/engine.js +13077 -0
  118. package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/main.js +3028 -0
  119. package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/text.js +32 -0
  120. package/lib/novel-to-game/examples/jin-ping-mei/build/app/package.json +10 -0
  121. package/lib/novel-to-game/examples/jin-ping-mei/build/app/vercel.json +23 -0
  122. package/lib/novel-to-game/examples/jin-ping-mei/build/art/generated-art.json +161 -0
  123. package/lib/novel-to-game/examples/jin-ping-mei/example.json +12 -0
  124. package/lib/novel-to-game/examples/jin-ping-mei/qa/README.md +31 -0
  125. package/lib/novel-to-game/examples/jin-ping-mei/qa/playable-model.json +99 -0
  126. package/lib/novel-to-game/examples/jin-ping-mei/qa/verification.json +41 -0
  127. package/lib/novel-to-game/examples/jin-ping-mei/qa/verify_playable_model.mjs +129 -0
  128. package/lib/novel-to-game/manifest.json +508 -0
  129. package/lib/novel-to-game/skills/game-art-direction/SKILL.md +73 -0
  130. package/lib/novel-to-game/skills/game-art-direction/agents/openai.yaml +4 -0
  131. package/lib/novel-to-game/skills/game-art-direction/references/art-direction-method.md +119 -0
  132. package/lib/novel-to-game/skills/game-build/SKILL.md +84 -0
  133. package/lib/novel-to-game/skills/game-build/agents/openai.yaml +4 -0
  134. package/lib/novel-to-game/skills/game-build/references/build-brief-contract.md +109 -0
  135. package/lib/novel-to-game/skills/game-build/references/generative-media-pipeline.md +56 -0
  136. package/lib/novel-to-game/skills/game-build/references/playable-model-contract.md +81 -0
  137. package/lib/novel-to-game/skills/game-build/references/tts-production-contract.md +37 -0
  138. package/lib/novel-to-game/skills/game-concept/SKILL.md +72 -0
  139. package/lib/novel-to-game/skills/game-concept/agents/openai.yaml +4 -0
  140. package/lib/novel-to-game/skills/game-concept/references/concept-method.md +94 -0
  141. package/lib/novel-to-game/skills/game-qa/SKILL.md +50 -0
  142. package/lib/novel-to-game/skills/game-qa/agents/openai.yaml +4 -0
  143. package/lib/novel-to-game/skills/game-qa/references/qa-contract.md +66 -0
  144. package/lib/novel-to-game/skills/game-qa/references/test-design-method.md +45 -0
  145. package/lib/novel-to-game/skills/game-world-design/SKILL.md +63 -0
  146. package/lib/novel-to-game/skills/game-world-design/agents/openai.yaml +4 -0
  147. package/lib/novel-to-game/skills/game-world-design/references/dialogue-design-method.md +59 -0
  148. package/lib/novel-to-game/skills/game-world-design/references/game-writing-craft.md +53 -0
  149. package/lib/novel-to-game/skills/game-world-design/references/narrative-design-method.md +84 -0
  150. package/lib/novel-to-game/skills/game-world-design/references/numeric-design-method.md +56 -0
  151. package/lib/novel-to-game/skills/game-world-design/references/world-design-method.md +124 -0
  152. package/lib/novel-to-game/skills/novel-game-analyze/SKILL.md +77 -0
  153. package/lib/novel-to-game/skills/novel-game-analyze/agents/openai.yaml +4 -0
  154. package/lib/novel-to-game/skills/novel-game-analyze/references/gameability-protocol.md +65 -0
  155. package/lib/novel-to-game/skills/novel-to-game/SKILL.md +71 -0
  156. package/lib/novel-to-game/skills/novel-to-game/agents/openai.yaml +4 -0
  157. package/lib/novel-to-game/skills/novel-to-game/references/intake-benchmark-reference.md +42 -0
  158. package/lib/novel-to-game/skills/novel-to-game/references/intake-method.md +51 -0
  159. package/lib/novel-to-game/skills/novel-to-game/references/pipeline-contract.md +65 -0
  160. package/lib/oh-story/manifest.json +415 -305
  161. package/lib/oh-story/roles/consistency-checker.md +1 -1
  162. package/lib/oh-story/roles/narrative-writer.md +32 -33
  163. package/lib/oh-story/roles/story-architect.md +16 -26
  164. package/lib/oh-story/skills/browser-cdp/SKILL.md +1 -1
  165. package/lib/oh-story/skills/story/SKILL.md +16 -9
  166. package/lib/oh-story/skills/story/VERSION +1 -1
  167. package/lib/oh-story/skills/story/references/author-memory.md +163 -0
  168. package/lib/oh-story/skills/story/scripts/author_memory_commit.py +871 -0
  169. package/lib/oh-story/skills/story-cover/SKILL.md +1 -1
  170. package/lib/oh-story/skills/story-deslop/SKILL.md +10 -5
  171. package/lib/oh-story/skills/story-deslop/references/anti-ai-writing.md +2 -1
  172. package/lib/oh-story/skills/story-deslop/references/author-memory.md +163 -0
  173. package/lib/oh-story/skills/story-deslop/references/banned-words.md +6 -4
  174. package/lib/oh-story/skills/story-deslop/scripts/author_memory_commit.py +871 -0
  175. package/lib/oh-story/skills/story-deslop/scripts/check-ai-patterns.js +64 -1
  176. package/lib/oh-story/skills/story-import/SKILL.md +19 -10
  177. package/lib/oh-story/skills/story-import/references/format-and-structure.md +9 -10
  178. package/lib/oh-story/skills/story-import/references/structure-mapping-long.md +2 -2
  179. package/lib/oh-story/skills/story-import/references/structure-mapping-short.md +1 -1
  180. package/lib/oh-story/skills/story-import/references/tracking-transaction.md +14 -6
  181. package/lib/oh-story/skills/story-import/scripts/check-outline-contract.js +251 -0
  182. package/lib/oh-story/skills/story-import/scripts/tracking_commit.py +98 -9
  183. package/lib/oh-story/skills/story-import/scripts/wordcount_core.py +246 -0
  184. package/lib/oh-story/skills/story-long-analyze/SKILL.md +4 -4
  185. package/lib/oh-story/skills/story-long-scan/SKILL.md +1 -1
  186. package/lib/oh-story/skills/story-long-write/SKILL.md +35 -21
  187. package/lib/oh-story/skills/story-long-write/references/anti-ai-writing.md +2 -1
  188. package/lib/oh-story/skills/story-long-write/references/artifact-protocols.md +7 -3
  189. package/lib/oh-story/skills/story-long-write/references/author-memory.md +163 -0
  190. package/lib/oh-story/skills/story-long-write/references/banned-words.md +6 -4
  191. package/lib/oh-story/skills/story-long-write/references/cross-book-recall.md +6 -6
  192. package/lib/oh-story/skills/story-long-write/references/genre-prose-cards.md +1 -1
  193. package/lib/oh-story/skills/story-long-write/references/genre-readers.md +1 -1
  194. package/lib/oh-story/skills/{story-setup/references/agent-references/hooks-chapter.md → story-long-write/references/long-chapter-hooks.md} +5 -5
  195. package/lib/oh-story/skills/story-long-write/references/{quality-checklist.md → long-chapter-quality.md} +2 -1
  196. package/lib/oh-story/skills/story-long-write/references/long-format.md +42 -0
  197. package/lib/oh-story/skills/{story-setup/references/agent-references/genre-catalog.md → story-long-write/references/long-genre-catalog.md} +11 -97
  198. package/lib/oh-story/skills/{story-setup/references/agent-references/genre-core-mechanics.md → story-long-write/references/long-genre-mechanics.md} +1 -1
  199. package/lib/oh-story/skills/{story-short-write/references/reversal-toolkit.md → story-long-write/references/long-reversal.md} +18 -32
  200. package/lib/oh-story/skills/story-long-write/references/{hooks-suspense.md → long-suspense.md} +6 -6
  201. package/lib/oh-story/skills/story-long-write/references/opening-design.md +1 -1
  202. package/lib/oh-story/skills/story-long-write/references/outline-structure-theory.md +1 -1
  203. package/lib/oh-story/skills/story-long-write/references/style-genre-modules.md +1 -1
  204. package/lib/oh-story/skills/story-long-write/references/tracking-transaction.md +14 -6
  205. package/lib/oh-story/skills/story-long-write/references/workflow-chapter.md +32 -27
  206. package/lib/oh-story/skills/story-long-write/references/workflow-daily.md +4 -4
  207. package/lib/oh-story/skills/story-long-write/references/workflow-revision.md +2 -2
  208. package/lib/oh-story/skills/story-long-write/references/workflow-setup.md +14 -14
  209. package/lib/oh-story/skills/story-long-write/references/writing-craft.md +54 -54
  210. package/lib/oh-story/skills/story-long-write/scripts/author_memory_commit.py +871 -0
  211. package/lib/oh-story/skills/story-long-write/scripts/check-ai-patterns.js +64 -1
  212. package/lib/oh-story/skills/story-long-write/scripts/check-outline-contract.js +251 -0
  213. package/lib/oh-story/skills/story-long-write/scripts/storyctl.py +303 -0
  214. package/lib/oh-story/skills/story-long-write/scripts/tracking_commit.py +98 -9
  215. package/lib/oh-story/skills/story-long-write/scripts/wordcount_core.py +246 -0
  216. package/lib/oh-story/skills/story-review/SKILL.md +26 -17
  217. package/lib/oh-story/skills/story-review/references/anti-ai-writing.md +2 -1
  218. package/lib/oh-story/skills/story-review/references/author-memory.md +163 -0
  219. package/lib/oh-story/skills/story-review/references/banned-words.md +6 -4
  220. package/lib/oh-story/skills/story-review/references/{quality-checklist.md → review-quality.md} +22 -21
  221. package/lib/oh-story/skills/story-review/references/tracking-transaction.md +14 -6
  222. package/lib/oh-story/skills/story-review/scripts/author_memory_commit.py +871 -0
  223. package/lib/oh-story/skills/story-review/scripts/check-ai-patterns.js +64 -1
  224. package/lib/oh-story/skills/story-review/scripts/tracking_commit.py +98 -9
  225. package/lib/oh-story/skills/story-review/scripts/wordcount_core.py +246 -0
  226. package/lib/oh-story/skills/story-setup/SKILL.md +74 -33
  227. package/lib/oh-story/skills/story-setup/references/agent-references/agent-quality.md +72 -0
  228. package/lib/oh-story/skills/story-setup/references/agent-references/agent-reference-profiles.md +55 -0
  229. package/lib/oh-story/skills/story-setup/references/agent-references/anti-ai-writing.md +2 -1
  230. package/lib/oh-story/skills/story-setup/references/agent-references/banned-words.md +6 -4
  231. package/lib/oh-story/skills/story-setup/references/agent-references/format-and-structure.md +9 -10
  232. package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards.md +1 -1
  233. package/lib/oh-story/skills/story-setup/references/agent-references/genre-readers.md +1 -1
  234. package/lib/oh-story/skills/{story-short-analyze/references/hooks-chapter.md → story-setup/references/agent-references/long-chapter-hooks.md} +5 -5
  235. package/lib/oh-story/skills/story-setup/references/agent-references/long-emotional-methods.md +209 -0
  236. package/lib/oh-story/skills/{story-long-write/references/genre-catalog.md → story-setup/references/agent-references/long-genre-catalog.md} +11 -97
  237. package/lib/oh-story/skills/{story-long-write/references/genre-core-mechanics.md → story-setup/references/agent-references/long-genre-mechanics.md} +1 -1
  238. package/lib/oh-story/skills/story-setup/references/agent-references/long-quality.md +40 -0
  239. package/lib/oh-story/skills/story-setup/references/agent-references/{reversal-toolkit.md → long-reversal.md} +18 -32
  240. package/lib/oh-story/skills/{story-short-write/references/hooks-suspense.md → story-setup/references/agent-references/long-suspense.md} +6 -6
  241. package/lib/oh-story/skills/story-setup/references/agent-references/opening-design.md +1 -1
  242. package/lib/oh-story/skills/story-setup/references/agent-references/{emotional-methods.md → short-emotional-methods.md} +4 -4
  243. package/lib/oh-story/skills/{story-long-write/references/genre-writing-formulas.md → story-setup/references/agent-references/short-genre-formulas.md} +32 -44
  244. package/lib/oh-story/skills/story-setup/references/agent-references/short-quality.md +39 -0
  245. package/lib/oh-story/skills/{story-long-write/references/reversal-toolkit.md → story-setup/references/agent-references/short-reversal.md} +29 -23
  246. package/lib/oh-story/skills/story-setup/references/agent-references/{hooks-suspense.md → short-suspense.md} +31 -31
  247. package/lib/oh-story/skills/story-setup/references/agent-references/style-genre-modules.md +1 -1
  248. package/lib/oh-story/skills/story-setup/references/agent-references/writing-craft.md +55 -55
  249. package/lib/oh-story/skills/story-short-analyze/SKILL.md +28 -28
  250. package/lib/oh-story/skills/story-short-analyze/references/{character-basics.md → analysis-character-basics.md} +1 -1
  251. package/lib/oh-story/skills/story-short-analyze/references/{character-design-methods.md → analysis-character-design.md} +1 -1
  252. package/lib/oh-story/skills/story-short-analyze/references/{character-relations.md → analysis-character-relations.md} +1 -1
  253. package/lib/oh-story/skills/story-short-analyze/references/{hooks-paragraph.md → analysis-paragraph-hooks.md} +1 -1
  254. package/lib/oh-story/skills/story-short-analyze/references/{genre-readers.md → analysis-reader-profile.md} +2 -2
  255. package/lib/oh-story/skills/story-short-analyze/references/analysis-report-style.md +45 -0
  256. package/lib/oh-story/skills/story-short-analyze/references/analysis-short-genres.md +65 -0
  257. package/lib/oh-story/skills/story-short-analyze/references/analysis-short-hooks.md +77 -0
  258. package/lib/oh-story/skills/story-short-analyze/references/analysis-short-mechanics.md +82 -0
  259. package/lib/oh-story/skills/story-short-analyze/references/analysis-short-patterns.md +50 -0
  260. package/lib/oh-story/skills/story-short-analyze/references/analysis-short-suspense.md +98 -0
  261. package/lib/oh-story/skills/story-short-analyze/references/{genre-writing-techniques.md → analysis-writing-techniques.md} +21 -19
  262. package/lib/oh-story/skills/story-short-analyze/references/deconstruction-examples.md +1 -1
  263. package/lib/oh-story/skills/story-short-analyze/references/material-decomposition.md +21 -28
  264. package/lib/oh-story/skills/story-short-analyze/references/output-contract.md +1 -1
  265. package/lib/oh-story/skills/story-short-analyze/references/output-templates.md +17 -17
  266. package/lib/oh-story/skills/story-short-analyze/references/{quality-checklist.md → source-story-quality.md} +28 -49
  267. package/lib/oh-story/skills/story-short-analyze/references/zhihu-style.md +2 -2
  268. package/lib/oh-story/skills/story-short-scan/SKILL.md +1 -1
  269. package/lib/oh-story/skills/story-short-write/SKILL.md +78 -55
  270. package/lib/oh-story/skills/story-short-write/references/author-memory.md +163 -0
  271. package/lib/oh-story/skills/story-short-write/references/banned-words.md +6 -4
  272. package/lib/oh-story/skills/story-short-write/references/cross-book-recall.md +3 -3
  273. package/lib/oh-story/skills/story-short-write/references/emotional-methods.md +4 -4
  274. package/lib/oh-story/skills/story-short-write/references/genre-styles//344/270/226/346/203/205/346/211/223/350/204/270.md +3 -3
  275. package/lib/oh-story/skills/story-short-write/references/genre-styles//345/217/214/347/224/267/344/270/273.md +2 -2
  276. package/lib/oh-story/skills/story-short-write/references/genre-styles//345/244/215/344/273/207/346/211/223/350/204/270.md +3 -3
  277. package/lib/oh-story/skills/story-short-write/references/genre-styles//345/256/205/346/226/227/345/256/253/346/226/227.md +6 -6
  278. package/lib/oh-story/skills/story-short-write/references/genre-styles//346/200/273/350/243/201/350/261/252/351/227/250.md +3 -3
  279. package/lib/oh-story/skills/story-short-write/references/genre-styles//346/202/254/347/226/221.md +4 -4
  280. package/lib/oh-story/skills/story-short-write/references/genre-styles//346/260/221/344/277/227/346/200/252/350/260/210.md +7 -7
  281. package/lib/oh-story/skills/story-short-write/references/genre-styles//346/262/231/351/233/225/350/204/221/346/264/236.md +5 -5
  282. package/lib/oh-story/skills/story-short-write/references/genre-styles//347/224/234/345/256/240.md +4 -4
  283. package/lib/oh-story/skills/story-short-write/references/genre-styles//350/277/275/345/246/273/347/201/253/350/221/254/345/234/272.md +3 -3
  284. package/lib/oh-story/skills/story-short-write/references/genre-writing-formulas.md +32 -44
  285. package/lib/oh-story/skills/story-short-write/references/genre-writing-techniques.md +20 -18
  286. package/lib/oh-story/skills/story-short-write/references/output-contract.md +1 -1
  287. package/lib/oh-story/skills/story-short-write/references/short-craft.md +18 -18
  288. package/lib/oh-story/skills/story-short-write/references/short-deslop.md +1 -1
  289. package/lib/oh-story/skills/story-short-write/references/short-format.md +38 -8
  290. package/lib/oh-story/skills/story-short-write/references/{quality-checklist.md → short-prose-quality.md} +22 -21
  291. package/lib/oh-story/skills/story-short-write/references/short-reversal.md +355 -0
  292. package/lib/oh-story/skills/{story-short-analyze/references/hooks-suspense.md → story-short-write/references/short-suspense.md} +31 -31
  293. package/lib/oh-story/skills/story-short-write/references/submission-craft.md +2 -2
  294. package/lib/oh-story/skills/story-short-write/references/writing-workflow.md +31 -22
  295. package/lib/oh-story/skills/story-short-write/scripts/author_memory_commit.py +871 -0
  296. package/lib/oh-story/skills/story-short-write/scripts/check-ai-patterns.js +64 -1
  297. package/lib/oh-story/skills/story-short-write/scripts/check-delivery-contract.js +212 -0
  298. package/lib/oh-story/skills/story-short-write/scripts/check-phase2-contract.js +363 -0
  299. package/lib/types/client/drama-production-view.d.ts +34 -0
  300. package/lib/types/client/drama-production-view.d.ts.map +1 -0
  301. package/lib/types/client/drama-production.d.ts +92 -0
  302. package/lib/types/client/drama-production.d.ts.map +1 -0
  303. package/lib/types/client/file-activity.d.ts +4 -2
  304. package/lib/types/client/file-activity.d.ts.map +1 -1
  305. package/lib/types/client/index.d.ts +1 -1
  306. package/lib/types/client/index.d.ts.map +1 -1
  307. package/lib/types/client/production-intents.d.ts +9 -0
  308. package/lib/types/client/production-intents.d.ts.map +1 -0
  309. package/lib/types/client/production-prompts.d.ts +9 -0
  310. package/lib/types/client/production-prompts.d.ts.map +1 -0
  311. package/lib/types/client/production-runtime.d.ts +58 -0
  312. package/lib/types/client/production-runtime.d.ts.map +1 -0
  313. package/lib/types/client/video-studio.d.ts +41 -0
  314. package/lib/types/client/video-studio.d.ts.map +1 -0
  315. package/lib/types/client/workbench-ui.d.ts +5 -0
  316. package/lib/types/client/workbench-ui.d.ts.map +1 -0
  317. package/lib/types/game-verification.d.ts +16 -0
  318. package/lib/types/game-verification.d.ts.map +1 -0
  319. package/lib/types/index.d.ts +3 -1
  320. package/lib/types/index.d.ts.map +1 -1
  321. package/lib/types/production-intent.d.ts +21 -0
  322. package/lib/types/production-intent.d.ts.map +1 -0
  323. package/lib/types/production-tool.d.ts +5 -0
  324. package/lib/types/production-tool.d.ts.map +1 -0
  325. package/lib/types/role-tool.d.ts.map +1 -1
  326. package/lib/types/skill-provider.d.ts +7 -0
  327. package/lib/types/skill-provider.d.ts.map +1 -1
  328. package/lib/types/video-project.d.ts +42 -0
  329. package/lib/types/video-project.d.ts.map +1 -0
  330. package/lib/types/workspace-request-trust.d.ts +6 -0
  331. package/lib/types/workspace-request-trust.d.ts.map +1 -1
  332. package/lib/types/workspace-route.d.ts +20 -0
  333. package/lib/types/workspace-route.d.ts.map +1 -1
  334. package/lib/video-recap/CHANGELOG.md +282 -0
  335. package/lib/video-recap/LICENSE +21 -0
  336. package/lib/video-recap/README.en.md +257 -0
  337. package/lib/video-recap/README.md +255 -0
  338. package/lib/video-recap/manifest.json +684 -0
  339. package/lib/video-recap/skills/video-assemble/SKILL.md +97 -0
  340. package/lib/video-recap/skills/video-assemble/references/jianying/LICENSE.duo-video +21 -0
  341. package/lib/video-recap/skills/video-assemble/references/jianying/SOURCE.md +15 -0
  342. package/lib/video-recap/skills/video-assemble/references/jianying/empty_draft_meta_info.json +69 -0
  343. package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_combination_segment.json +84 -0
  344. package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_combination_video_material.json +98 -0
  345. package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_draft.json +204 -0
  346. package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_material_video.json +83 -0
  347. package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_meta_material_value.json +23 -0
  348. package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_project_info.json +133 -0
  349. package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_segment.json +70 -0
  350. package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_text_styles.json +30 -0
  351. package/lib/video-recap/skills/video-assemble/references/jianying/empty_yj_material_audio.json +41 -0
  352. package/lib/video-recap/skills/video-assemble/references/jianying/empty_yj_material_text.json +109 -0
  353. package/lib/video-recap/skills/video-assemble/scripts/artifacts.py +88 -0
  354. package/lib/video-recap/skills/video-assemble/scripts/assemble.py +345 -0
  355. package/lib/video-recap/skills/video-assemble/scripts/assemble_constants.py +34 -0
  356. package/lib/video-recap/skills/video-assemble/scripts/assembly_contract.py +305 -0
  357. package/lib/video-recap/skills/video-assemble/scripts/assembly_settings.py +94 -0
  358. package/lib/video-recap/skills/video-assemble/scripts/audio_automation.py +205 -0
  359. package/lib/video-recap/skills/video-assemble/scripts/audio_mix.py +555 -0
  360. package/lib/video-recap/skills/video-assemble/scripts/export_jianying.py +261 -0
  361. package/lib/video-recap/skills/video-assemble/scripts/jianying_builders.py +767 -0
  362. package/lib/video-recap/skills/video-assemble/scripts/jianying_model.py +111 -0
  363. package/lib/video-recap/skills/video-assemble/scripts/jianying_optional.py +24 -0
  364. package/lib/video-recap/skills/video-assemble/scripts/jianying_schema.py +109 -0
  365. package/lib/video-recap/skills/video-assemble/scripts/jianying_templates.py +37 -0
  366. package/lib/video-recap/skills/video-assemble/scripts/jianying_timeline_contract.py +191 -0
  367. package/lib/video-recap/skills/video-assemble/scripts/jianying_tracks.py +75 -0
  368. package/lib/video-recap/skills/video-assemble/scripts/jianying_writer.py +394 -0
  369. package/lib/video-recap/skills/video-assemble/scripts/lib.py +239 -0
  370. package/lib/video-recap/skills/video-assemble/scripts/media.py +243 -0
  371. package/lib/video-recap/skills/video-assemble/scripts/narration_audio.py +477 -0
  372. package/lib/video-recap/skills/video-assemble/scripts/render_preflight.py +46 -0
  373. package/lib/video-recap/skills/video-assemble/scripts/source_subtitles.py +486 -0
  374. package/lib/video-recap/skills/video-assemble/scripts/subtitle_core.py +376 -0
  375. package/lib/video-recap/skills/video-assemble/scripts/subtitle_render.py +88 -0
  376. package/lib/video-recap/skills/video-assemble/scripts/timeline.py +248 -0
  377. package/lib/video-recap/skills/video-assemble/scripts/timeline_emit.py +89 -0
  378. package/lib/video-recap/skills/video-assemble/scripts/visual_render.py +512 -0
  379. package/lib/video-recap/skills/video-cut/SKILL.md +90 -0
  380. package/lib/video-recap/skills/video-cut/scripts/cut.py +67 -0
  381. package/lib/video-recap/skills/video-cut/scripts/cut_cli.py +320 -0
  382. package/lib/video-recap/skills/video-cut/scripts/cut_contract.py +545 -0
  383. package/lib/video-recap/skills/video-cut/scripts/cut_render.py +348 -0
  384. package/lib/video-recap/skills/video-cut/scripts/lib.py +77 -0
  385. package/lib/video-recap/skills/video-cut/scripts/media_geometry.py +341 -0
  386. package/lib/video-recap/skills/video-cut/scripts/narration_mapping.py +249 -0
  387. package/lib/video-recap/skills/video-cut/scripts/sentence_boundaries.py +745 -0
  388. package/lib/video-recap/skills/video-recap/SKILL.md +216 -0
  389. package/lib/video-recap/skills/video-recap/references/config-playbook.md +61 -0
  390. package/lib/video-recap/skills/video-recap/references/creative-editing-playbook.md +225 -0
  391. package/lib/video-recap/skills/video-recap/references/data-schema.md +534 -0
  392. package/lib/video-recap/skills/video-recap/references/research-guide.md +74 -0
  393. package/lib/video-recap/skills/video-recap/references/shift-left-qc-schema.md +23 -0
  394. package/lib/video-recap/skills/video-recap/references/timeline-and-jianying.md +251 -0
  395. package/lib/video-recap/skills/video-recap/scripts/doctor.py +483 -0
  396. package/lib/video-recap/skills/video-recap/scripts/final_qc.py +737 -0
  397. package/lib/video-recap/skills/video-recap/scripts/lib.py +242 -0
  398. package/lib/video-recap/skills/video-recap/scripts/materials.py +457 -0
  399. package/lib/video-recap/skills/video-recap/scripts/mimo_qc.py +95 -0
  400. package/lib/video-recap/skills/video-recap/scripts/mimo_qc_client.py +18 -0
  401. package/lib/video-recap/skills/video-recap/scripts/mimo_qc_contract.py +9 -0
  402. package/lib/video-recap/skills/video-recap/scripts/mimo_qc_evidence.py +371 -0
  403. package/lib/video-recap/skills/video-recap/scripts/mimo_qc_observations.py +201 -0
  404. package/lib/video-recap/skills/video-recap/scripts/mimo_qc_payload.py +227 -0
  405. package/lib/video-recap/skills/video-recap/scripts/mimo_qc_report.py +362 -0
  406. package/lib/video-recap/skills/video-recap/scripts/mimo_qc_runner.py +129 -0
  407. package/lib/video-recap/skills/video-recap/scripts/qc_contract.py +338 -0
  408. package/lib/video-recap/skills/video-recap/scripts/recap.py +9 -0
  409. package/lib/video-recap/skills/video-recap/scripts/recap_cli.py +140 -0
  410. package/lib/video-recap/skills/video-recap/scripts/recap_inspect.py +550 -0
  411. package/lib/video-recap/skills/video-recap/scripts/recap_review.py +77 -0
  412. package/lib/video-recap/skills/video-recap/scripts/recap_runner.py +654 -0
  413. package/lib/video-recap/skills/video-recap/scripts/recap_runtime.py +335 -0
  414. package/lib/video-recap/skills/video-recap/scripts/recap_stage_qc.py +217 -0
  415. package/lib/video-recap/skills/video-recap/scripts/recap_timeline.py +795 -0
  416. package/lib/video-recap/skills/video-script/SKILL.md +248 -0
  417. package/lib/video-recap/skills/video-script/references/creative-editing-playbook.md +225 -0
  418. package/lib/video-recap/skills/video-script/references/research-guide.md +75 -0
  419. package/lib/video-recap/skills/video-script/scripts/agent_brief.py +399 -0
  420. package/lib/video-recap/skills/video-script/scripts/agent_text.py +410 -0
  421. package/lib/video-recap/skills/video-script/scripts/brief_context.py +403 -0
  422. package/lib/video-recap/skills/video-script/scripts/brief_inputs.py +332 -0
  423. package/lib/video-recap/skills/video-script/scripts/brief_timeline.py +442 -0
  424. package/lib/video-recap/skills/video-script/scripts/deslop_qc.py +237 -0
  425. package/lib/video-recap/skills/video-script/scripts/evidence_bundle.py +492 -0
  426. package/lib/video-recap/skills/video-script/scripts/lib.py +327 -0
  427. package/lib/video-recap/skills/video-script/scripts/narration.py +12 -0
  428. package/lib/video-recap/skills/video-script/scripts/narration_lint.py +678 -0
  429. package/lib/video-recap/skills/video-script/scripts/review.py +42 -0
  430. package/lib/video-recap/skills/video-script/scripts/review_grounding.py +262 -0
  431. package/lib/video-recap/skills/video-script/scripts/review_response.py +761 -0
  432. package/lib/video-recap/skills/video-script/scripts/review_runner.py +200 -0
  433. package/lib/video-recap/skills/video-script/scripts/speech_ownership.py +204 -0
  434. package/lib/video-recap/skills/video-script/scripts/timeline_fusion.py +199 -0
  435. package/lib/video-recap/skills/video-script/scripts/validate.py +164 -0
  436. package/lib/video-recap/skills/video-understanding/SKILL.md +75 -0
  437. package/lib/video-recap/skills/video-understanding/references/data-schema.md +299 -0
  438. package/lib/video-recap/skills/video-understanding/references/prompt-templates.md +37 -0
  439. package/lib/video-recap/skills/video-understanding/references/research-guide.md +74 -0
  440. package/lib/video-recap/skills/video-understanding/scripts/agent_brief.py +399 -0
  441. package/lib/video-recap/skills/video-understanding/scripts/agent_text.py +410 -0
  442. package/lib/video-recap/skills/video-understanding/scripts/asr.py +260 -0
  443. package/lib/video-recap/skills/video-understanding/scripts/brief.py +12 -0
  444. package/lib/video-recap/skills/video-understanding/scripts/brief_context.py +403 -0
  445. package/lib/video-recap/skills/video-understanding/scripts/brief_inputs.py +332 -0
  446. package/lib/video-recap/skills/video-understanding/scripts/brief_timeline.py +442 -0
  447. package/lib/video-recap/skills/video-understanding/scripts/consolidate.py +647 -0
  448. package/lib/video-recap/skills/video-understanding/scripts/deslop_qc.py +237 -0
  449. package/lib/video-recap/skills/video-understanding/scripts/detect.py +513 -0
  450. package/lib/video-recap/skills/video-understanding/scripts/extract.py +62 -0
  451. package/lib/video-recap/skills/video-understanding/scripts/lib.py +470 -0
  452. package/lib/video-recap/skills/video-understanding/scripts/narration_lint.py +678 -0
  453. package/lib/video-recap/skills/video-understanding/scripts/speech_ownership.py +204 -0
  454. package/lib/video-recap/skills/video-understanding/scripts/storyboard.py +507 -0
  455. package/lib/video-recap/skills/video-understanding/scripts/timeline_fusion.py +199 -0
  456. package/lib/video-recap/skills/video-understanding/scripts/understand.py +9 -0
  457. package/lib/video-recap/skills/video-understanding/scripts/understanding_brief.py +216 -0
  458. package/lib/video-recap/skills/video-understanding/scripts/understanding_cache.py +327 -0
  459. package/lib/video-recap/skills/video-understanding/scripts/understanding_runner.py +367 -0
  460. package/lib/video-recap/skills/video-understanding/scripts/understanding_storyboard.py +162 -0
  461. package/lib/video-recap/skills/video-understanding/scripts/vlm.py +705 -0
  462. package/lib/video-recap/skills/video-voiceover/SKILL.md +81 -0
  463. package/lib/video-recap/skills/video-voiceover/scripts/dub.py +637 -0
  464. package/lib/video-recap/skills/video-voiceover/scripts/fish_audio.py +109 -0
  465. package/lib/video-recap/skills/video-voiceover/scripts/lib.py +421 -0
  466. package/lib/video-recap/skills/video-voiceover/scripts/tts_audio.py +113 -0
  467. package/lib/video-recap/skills/video-voiceover/scripts/voiceover.py +782 -0
  468. package/package.json +55 -40
  469. package/lib/oh-story/skills/story-deslop/scripts/check-outline-copy.js +0 -241
  470. package/lib/oh-story/skills/story-long-write/references/format-and-structure.md +0 -169
  471. package/lib/oh-story/skills/story-setup/references/agent-references/genre-writing-formulas.md +0 -444
  472. package/lib/oh-story/skills/story-setup/references/agent-references/quality-checklist.md +0 -247
  473. package/lib/oh-story/skills/story-short-analyze/references/anti-ai-writing.md +0 -582
  474. package/lib/oh-story/skills/story-short-analyze/references/banned-words.md +0 -147
  475. package/lib/oh-story/skills/story-short-analyze/references/genre-catalog.md +0 -490
  476. package/lib/oh-story/skills/story-short-analyze/references/genre-core-mechanics.md +0 -425
  477. package/lib/oh-story/skills/story-short-analyze/references/genre-writing-formulas.md +0 -453
  478. /package/lib/oh-story/skills/{story-long-write/references/hooks-chapter.md → story-setup/references/agent-references/short-chapter-hooks.md} +0 -0
  479. /package/lib/oh-story/skills/{story-long-write/references/hooks-paragraph.md → story-setup/references/agent-references/short-paragraph-hooks.md} +0 -0
@@ -0,0 +1,737 @@
1
+ #!/usr/bin/env python3
2
+ """Final post-render QC and golden-eval reports for video-recap.
3
+
4
+ Local deterministic/report-only checks only: no network, no repair, no secrets.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import argparse
9
+ import json
10
+ import math
11
+ import shutil
12
+ import subprocess
13
+ from pathlib import Path
14
+ from typing import Any, Callable, Mapping, Sequence
15
+
16
+ import qc_contract
17
+
18
+ FINAL_QC_ARTIFACT = "final_qc.json"
19
+ GOLDEN_EVAL_ARTIFACT = "golden_eval.json"
20
+ POST_RENDER_STAGE = "post_render"
21
+ GOLDEN_STAGE = "golden"
22
+ _COLLECT_ARTIFACTS = (
23
+ "assembly_manifest.json",
24
+ "assembly_qc.json",
25
+ "visual_qc.json",
26
+ "preflight_qc.json",
27
+ "mimo_qc.json",
28
+ )
29
+ ProbeRunner = Callable[[Path], Mapping[str, Any]]
30
+
31
+
32
+ def redact_secrets(value: Any) -> Any:
33
+ """Return a JSON-safe copy with likely credentials removed."""
34
+ return qc_contract.redact_secrets(value)
35
+
36
+
37
+ def safe_load_json(path_or_value: str | Path | Mapping[str, Any] | Sequence[Any] | None) -> Any:
38
+ """Safely load JSON from a path or return a redacted JSON-like fixture value."""
39
+ if path_or_value is None:
40
+ return None
41
+ if isinstance(path_or_value, (Mapping, list, tuple)):
42
+ return redact_secrets(path_or_value)
43
+ path = Path(path_or_value)
44
+ try:
45
+ return redact_secrets(json.loads(path.read_text(encoding="utf-8")))
46
+ except (OSError, ValueError, TypeError):
47
+ return None
48
+
49
+
50
+ def fingerprint_file(path: str | Path) -> str | None:
51
+ path = Path(path)
52
+ try:
53
+ if path.exists() and path.is_file():
54
+ return qc_contract.artifact_fingerprint(path)
55
+ except OSError:
56
+ return None
57
+ return None
58
+
59
+
60
+ def _json_safe(value: Any) -> Any:
61
+ if isinstance(value, Path):
62
+ return str(value)
63
+ if isinstance(value, Mapping):
64
+ return {str(k): _json_safe(v) for k, v in value.items()}
65
+ if isinstance(value, (list, tuple)):
66
+ return [_json_safe(v) for v in value]
67
+ return value
68
+
69
+
70
+ def _resolve_in_work_dir(work_dir: Path, path: str | Path | None) -> Path | None:
71
+ if path is None or str(path) == "":
72
+ return None
73
+ p = Path(path)
74
+ return p if p.is_absolute() else work_dir / p
75
+
76
+
77
+ def _candidate_final_outputs(work_dir: Path, final_output: str | Path | None) -> list[Path]:
78
+ candidates: list[Path] = []
79
+ explicit = _resolve_in_work_dir(work_dir, final_output)
80
+ if explicit is not None:
81
+ candidates.append(explicit)
82
+ manifest = safe_load_json(work_dir / "assembly_manifest.json")
83
+ if isinstance(manifest, Mapping):
84
+ for key in ("final_output", "output", "output_path", "video_path"):
85
+ if manifest.get(key):
86
+ p = _resolve_in_work_dir(work_dir, str(manifest[key]))
87
+ if p is not None:
88
+ candidates.append(p)
89
+ for name in ("output.mp4", "recap.mp4", "final.mp4"):
90
+ candidates.append(work_dir / name)
91
+ deduped: list[Path] = []
92
+ seen: set[str] = set()
93
+ for p in candidates:
94
+ key = str(p)
95
+ if key not in seen:
96
+ seen.add(key)
97
+ deduped.append(p)
98
+ return deduped
99
+
100
+
101
+ def _select_final_output(work_dir: Path, final_output: str | Path | None) -> Path | None:
102
+ candidates = _candidate_final_outputs(work_dir, final_output)
103
+ if final_output is not None:
104
+ return candidates[0] if candidates else _resolve_in_work_dir(work_dir, final_output)
105
+ for p in candidates:
106
+ try:
107
+ if p.exists() and p.is_file() and p.stat().st_size > 0:
108
+ return p
109
+ except OSError:
110
+ continue
111
+ return candidates[0] if candidates else None
112
+
113
+
114
+ def _file_metadata(path: Path | None, work_dir: Path | None = None) -> dict[str, Any]:
115
+ if path is None:
116
+ return {"path": None, "exists": False, "bytes": 0, "fingerprint": None}
117
+ display = str(path)
118
+ if work_dir is not None:
119
+ try:
120
+ display = path.relative_to(work_dir).as_posix()
121
+ except ValueError:
122
+ pass
123
+ item: dict[str, Any] = {"path": display}
124
+ try:
125
+ exists = path.exists() and path.is_file()
126
+ item["exists"] = exists
127
+ item["bytes"] = path.stat().st_size if exists else 0
128
+ item["fingerprint"] = fingerprint_file(path) if exists else None
129
+ except OSError as exc:
130
+ item.update({"exists": False, "bytes": 0, "fingerprint": None, "error": str(exc)})
131
+ return redact_secrets(item)
132
+
133
+
134
+ def _artifact_summary(work_dir: Path, name: str) -> dict[str, Any]:
135
+ path = work_dir / name
136
+ meta = _file_metadata(path, work_dir)
137
+ if meta.get("exists") and path.suffix.lower() == ".json":
138
+ data = safe_load_json(path)
139
+ if isinstance(data, Mapping):
140
+ meta["summary"] = {
141
+ "schema_version": data.get("schema_version"),
142
+ "artifact": data.get("artifact"),
143
+ "stage": data.get("stage"),
144
+ "ok": data.get("ok"),
145
+ "blocker_count": data.get("blocker_count"),
146
+ "finding_count": data.get("finding_count"),
147
+ }
148
+ elif data is not None:
149
+ meta["summary"] = {"type": type(data).__name__}
150
+ return redact_secrets(meta)
151
+
152
+
153
+ def _artifact_fingerprints(*paths: Path | None) -> dict[str, str]:
154
+ out: dict[str, str] = {}
155
+ for path in paths:
156
+ if path is None:
157
+ continue
158
+ fp = fingerprint_file(path)
159
+ if fp:
160
+ out[path.name] = fp
161
+ return out
162
+
163
+
164
+ def _finding(*, finding_id: str, code: str, message: str, category: str = "schema_invalid",
165
+ stage: str = POST_RENDER_STAGE, source: Mapping[str, Any] | None = None,
166
+ evidence: Mapping[str, Any] | None = None, fingerprints: Mapping[str, Any] | None = None,
167
+ next_action: str = "manual_review") -> dict[str, Any]:
168
+ return qc_contract.build_finding(
169
+ finding_id=finding_id,
170
+ stage=stage,
171
+ severity="blocker",
172
+ confidence="objective",
173
+ sample_policy={"type": "deterministic"},
174
+ category=category,
175
+ code=code,
176
+ message=message,
177
+ deterministic=True,
178
+ blocking=True,
179
+ source=redact_secrets(source or {}),
180
+ evidence=redact_secrets(evidence or {}),
181
+ artifact_fingerprints=redact_secrets(fingerprints or {}),
182
+ next_action=next_action,
183
+ model_used="local_deterministic_final_qc_v1",
184
+ )
185
+
186
+
187
+ def _run_ffprobe(path: Path) -> Mapping[str, Any]:
188
+ if shutil.which("ffprobe") is None:
189
+ raise RuntimeError("ffprobe unavailable")
190
+ cmd = [
191
+ "ffprobe", "-v", "error", "-print_format", "json",
192
+ "-show_format", "-show_streams", str(path),
193
+ ]
194
+ res = subprocess.run(cmd, capture_output=True, text=True)
195
+ if res.returncode != 0:
196
+ detail = (res.stderr or res.stdout or "ffprobe failed").strip()
197
+ raise RuntimeError(detail)
198
+ try:
199
+ data = json.loads(res.stdout or "{}")
200
+ except ValueError as exc:
201
+ raise RuntimeError(f"ffprobe returned invalid JSON: {exc}") from exc
202
+ if not isinstance(data, Mapping):
203
+ raise RuntimeError("ffprobe JSON must be an object")
204
+ return data
205
+
206
+
207
+ def _tail_decode_check(path: Path) -> tuple[bool | None, str | None]:
208
+ """Cheaply verify the final ~2s actually decodes. Returns (ok, detail).
209
+
210
+ Header probing (ffprobe -show_format/-show_streams) passes a container-valid but
211
+ media-truncated/corrupt payload (moov intact + mdat cut — realistic with +faststart on
212
+ disk-full or partial upload). Decoding the tail catches it. Returns (None, ...) when ffmpeg
213
+ is unavailable or the probe cannot run, so the caller skips rather than false-blocks.
214
+ """
215
+ if shutil.which("ffmpeg") is None:
216
+ return None, "ffmpeg unavailable"
217
+ try:
218
+ res = subprocess.run(
219
+ ["ffmpeg", "-v", "error", "-xerror", "-sseof", "-2", "-i", str(path), "-f", "null", "-"],
220
+ capture_output=True, text=True, timeout=60,
221
+ )
222
+ except (OSError, subprocess.SubprocessError) as exc:
223
+ return None, f"decode probe could not run: {exc}"
224
+ if res.returncode != 0:
225
+ return False, (res.stderr or "tail decode failed").strip()[:500]
226
+ return True, None
227
+
228
+
229
+ def _probe_metadata(path: Path, *, probe_fixture: Any = None, probe_runner: ProbeRunner | None = None) -> tuple[dict[str, Any] | None, dict[str, Any] | None]:
230
+ """Return (probe, error). Existing non-empty media gets deterministic error on failure."""
231
+ if probe_fixture is not None:
232
+ data = safe_load_json(probe_fixture)
233
+ if isinstance(data, Mapping):
234
+ return redact_secrets(dict(data)), None
235
+ return None, {"code": "probe_failed", "message": "probe_fixture is missing or invalid JSON"}
236
+ try:
237
+ runner = probe_runner or _run_ffprobe
238
+ data = runner(path)
239
+ if not isinstance(data, Mapping):
240
+ raise RuntimeError("probe_runner must return an object")
241
+ return redact_secrets(dict(data)), None
242
+ except Exception as exc: # deterministic report-only blocker, no crash
243
+ return None, {"code": "probe_failed", "message": str(exc) or "ffprobe failed"}
244
+
245
+
246
+ def _first_video_stream(probe: Mapping[str, Any] | None) -> Mapping[str, Any] | None:
247
+ if not isinstance(probe, Mapping):
248
+ return None
249
+ streams = probe.get("streams")
250
+ if not isinstance(streams, list):
251
+ return None
252
+ for stream in streams:
253
+ if isinstance(stream, Mapping) and stream.get("codec_type") == "video":
254
+ return stream
255
+ return None
256
+
257
+
258
+ def _parse_positive_finite_number(value: Any) -> float | None:
259
+ if value is None:
260
+ return None
261
+ if isinstance(value, str):
262
+ value = value.strip()
263
+ if not value:
264
+ return None
265
+ if "/" in value:
266
+ numerator, denominator = value.split("/", 1)
267
+ try:
268
+ den = float(denominator)
269
+ if den == 0:
270
+ return None
271
+ number = float(numerator) / den
272
+ except (TypeError, ValueError):
273
+ return None
274
+ else:
275
+ try:
276
+ number = float(value)
277
+ except (TypeError, ValueError):
278
+ return None
279
+ else:
280
+ try:
281
+ number = float(value)
282
+ except (TypeError, ValueError):
283
+ return None
284
+ if math.isfinite(number) and number > 0:
285
+ return number
286
+ return None
287
+
288
+
289
+ def _probe_duration_status(probe: Mapping[str, Any] | None) -> tuple[float | None, str | None, Any]:
290
+ if not isinstance(probe, Mapping):
291
+ return None, "missing_duration", None
292
+ candidates: list[Any] = []
293
+ fmt = probe.get("format")
294
+ if isinstance(fmt, Mapping):
295
+ candidates.append(fmt.get("duration"))
296
+ candidates.append(probe.get("duration"))
297
+ seen = [value for value in candidates if value not in (None, "")]
298
+ if not seen:
299
+ return None, "missing_duration", None
300
+ for value in seen:
301
+ duration = _parse_positive_finite_number(value)
302
+ if duration is not None:
303
+ return duration, None, value
304
+ return None, "invalid_duration", seen[0]
305
+
306
+
307
+ def _probe_fps_status(video_stream: Mapping[str, Any] | None, probe: Mapping[str, Any] | None) -> tuple[float | None, str | None, Any]:
308
+ candidates: list[Any] = []
309
+ if isinstance(video_stream, Mapping):
310
+ for key in ("avg_frame_rate", "r_frame_rate", "fps", "frame_rate"):
311
+ candidates.append(video_stream.get(key))
312
+ if isinstance(probe, Mapping):
313
+ for key in ("fps", "frame_rate"):
314
+ candidates.append(probe.get(key))
315
+ seen = [value for value in candidates if value not in (None, "")]
316
+ if not seen:
317
+ return None, "missing_fps", None
318
+ for value in seen:
319
+ fps = _parse_positive_finite_number(value)
320
+ if fps is not None:
321
+ return fps, None, value
322
+ return None, "invalid_fps", seen[0]
323
+
324
+ def _duration_from_probe(probe: Mapping[str, Any] | None) -> float | None:
325
+ if not isinstance(probe, Mapping):
326
+ return None
327
+ candidates: list[Any] = []
328
+ fmt = probe.get("format")
329
+ if isinstance(fmt, Mapping):
330
+ candidates.append(fmt.get("duration"))
331
+ candidates.append(probe.get("duration"))
332
+ for value in candidates:
333
+ try:
334
+ duration = float(value)
335
+ except (TypeError, ValueError):
336
+ continue
337
+ if duration >= 0:
338
+ return duration
339
+ return None
340
+
341
+
342
+ def _codec_from_probe(probe: Mapping[str, Any] | None) -> str | None:
343
+ vs = _first_video_stream(probe)
344
+ name = vs.get("codec_name") if isinstance(vs, Mapping) else None
345
+ return str(name) if name else None
346
+
347
+
348
+
349
+ def _probe_contract_findings(probe: Mapping[str, Any] | None, *, final_meta: Mapping[str, Any], fingerprints: Mapping[str, Any]) -> list[dict[str, Any]]:
350
+ findings: list[dict[str, Any]] = []
351
+ video_stream = _first_video_stream(probe)
352
+ if video_stream is None:
353
+ findings.append(_finding(
354
+ finding_id="final-qc-missing-video-stream",
355
+ code="missing_video_stream",
356
+ message="final output probe metadata has no video stream",
357
+ category="stream",
358
+ source={"artifact": final_meta.get("path")},
359
+ evidence={"streams": probe.get("streams") if isinstance(probe, Mapping) else None},
360
+ fingerprints=fingerprints,
361
+ next_action="rerender_final_output_with_video_stream",
362
+ ))
363
+
364
+ _duration, duration_code, duration_value = _probe_duration_status(probe)
365
+ if duration_code is not None:
366
+ findings.append(_finding(
367
+ finding_id=f"final-qc-{duration_code.replace('_', '-')}",
368
+ code=duration_code,
369
+ message="final output probe metadata is missing a positive finite duration" if duration_code == "missing_duration" else "final output probe metadata duration is not positive and finite",
370
+ category="duration",
371
+ source={"artifact": final_meta.get("path")},
372
+ evidence={"duration": duration_value},
373
+ fingerprints=fingerprints,
374
+ next_action="rerender_final_output_with_valid_duration",
375
+ ))
376
+
377
+ codec = str(video_stream.get("codec_name")).strip() if isinstance(video_stream, Mapping) and video_stream.get("codec_name") is not None else ""
378
+ if not codec:
379
+ findings.append(_finding(
380
+ finding_id="final-qc-missing-codec",
381
+ code="missing_codec",
382
+ message="final output probe metadata is missing a video codec",
383
+ category="stream",
384
+ source={"artifact": final_meta.get("path")},
385
+ evidence={"video_stream": video_stream},
386
+ fingerprints=fingerprints,
387
+ next_action="rerender_final_output_with_video_codec",
388
+ ))
389
+
390
+ _fps, fps_code, fps_value = _probe_fps_status(video_stream, probe)
391
+ if fps_code is not None:
392
+ findings.append(_finding(
393
+ finding_id=f"final-qc-{fps_code.replace('_', '-')}",
394
+ code=fps_code,
395
+ message="final output probe metadata is missing a positive finite video fps" if fps_code == "missing_fps" else "final output probe metadata video fps is not positive and finite",
396
+ category="stream",
397
+ source={"artifact": final_meta.get("path")},
398
+ evidence={"fps": fps_value, "video_stream": video_stream},
399
+ fingerprints=fingerprints,
400
+ next_action="rerender_final_output_with_valid_fps",
401
+ ))
402
+ return findings
403
+
404
+
405
+ def _blocking_codes(value: Any) -> list[str]:
406
+ if isinstance(value, str):
407
+ values: Sequence[Any] = [value]
408
+ elif isinstance(value, Sequence) and not isinstance(value, (str, bytes, bytearray)):
409
+ values = value
410
+ else:
411
+ return []
412
+ codes: list[str] = []
413
+ for item in values:
414
+ code = str(item).strip()
415
+ if code:
416
+ codes.append(code)
417
+ return codes
418
+
419
+
420
+ def _failing_verdict(value: Any) -> bool:
421
+ if not isinstance(value, str):
422
+ return False
423
+ verdict = value.strip().lower()
424
+ return verdict in {"fail", "failed", "failing", "blocker", "blocked", "error", "errored", "reject", "rejected"}
425
+
426
+
427
+ def _upstream_blockers(work_dir: Path, artifact_name: str) -> list[dict[str, Any]]:
428
+ path = work_dir / artifact_name
429
+ data = safe_load_json(path)
430
+ if not isinstance(data, Mapping):
431
+ return []
432
+ findings = data.get("findings")
433
+ blocker_count = data.get("blocker_count")
434
+ ok = data.get("ok")
435
+ blocked: list[Mapping[str, Any]] = []
436
+ if isinstance(findings, list):
437
+ blocked.extend(f for f in findings if isinstance(f, Mapping) and f.get("blocking") is True)
438
+ elif ok is False or (isinstance(blocker_count, int) and blocker_count > 0):
439
+ blocked.append({"code": "reported_blocker", "message": f"{artifact_name} reported blockers"})
440
+
441
+ blocking_codes = _blocking_codes(data.get("blocking_codes"))
442
+ if data.get("blocking") is True or _failing_verdict(data.get("verdict")):
443
+ if not blocking_codes:
444
+ blocking_codes = ["reported_blocker"]
445
+ for code in blocking_codes:
446
+ blocked.append({
447
+ "code": code,
448
+ "message": f"{artifact_name} reported {code}",
449
+ "artifact": data.get("artifact"),
450
+ "verdict": data.get("verdict"),
451
+ "blocking": data.get("blocking"),
452
+ })
453
+
454
+ out = []
455
+ fp = fingerprint_file(path)
456
+ for idx, item in enumerate(blocked):
457
+ code = str(item.get("code") or item.get("rule_id") or "reported_blocker")
458
+ out.append(_finding(
459
+ finding_id=f"final-qc-upstream-{artifact_name}-{idx}",
460
+ code=f"upstream_{artifact_name.replace('.', '_')}_{code}",
461
+ message=f"{artifact_name} has blocking finding: {item.get('message') or item.get('decision_reason') or code}",
462
+ category="schema_invalid",
463
+ source={"artifact": artifact_name, "finding_id": item.get("finding_id") or item.get("id")},
464
+ evidence={
465
+ "upstream_code": code,
466
+ "upstream_message": item.get("message") or item.get("decision_reason"),
467
+ "upstream_artifact": item.get("artifact"),
468
+ "upstream_verdict": item.get("verdict"),
469
+ "upstream_blocking": item.get("blocking"),
470
+ },
471
+ fingerprints={artifact_name: fp} if fp else {},
472
+ next_action="fix_upstream_qc_blocker",
473
+ ))
474
+ return out
475
+
476
+
477
+ def collect_metadata(work_dir: str | Path, *, final_output: str | Path | None = None,
478
+ probe_fixture: Any = None, probe_runner: ProbeRunner | None = None) -> dict[str, Any]:
479
+ root = Path(work_dir)
480
+ selected = _select_final_output(root, final_output)
481
+ probe = probe_error = None
482
+ final_meta = _file_metadata(selected, root)
483
+ if final_meta.get("exists") and final_meta.get("bytes", 0) > 0:
484
+ probe, probe_error = _probe_metadata(selected, probe_fixture=probe_fixture, probe_runner=probe_runner)
485
+ artifacts = {name: _artifact_summary(root, name) for name in _COLLECT_ARTIFACTS}
486
+ metadata = {
487
+ "work_dir": str(root),
488
+ "final_output": final_meta,
489
+ "final_output_candidates": [_file_metadata(p, root) for p in _candidate_final_outputs(root, final_output)],
490
+ "artifacts": artifacts,
491
+ "probe": probe,
492
+ "probe_error": probe_error,
493
+ # mimo_qc.json is advisory metadata only and is not rolled into final blockers.
494
+ "auto_repair": False,
495
+ }
496
+ return redact_secrets(_json_safe(metadata))
497
+
498
+
499
+ def build_final_qc(work_dir: str | Path, final_output: str | Path | None = None,
500
+ probe_fixture: Any = None, probe_runner: ProbeRunner | None = None,
501
+ decode_runner: Callable[[Path], tuple[bool | None, str | None]] | None = None) -> dict[str, Any]:
502
+ root = Path(work_dir)
503
+ selected = _select_final_output(root, final_output)
504
+ metadata = collect_metadata(root, final_output=final_output, probe_fixture=probe_fixture, probe_runner=probe_runner)
505
+ final_meta = metadata["final_output"]
506
+ findings: list[dict[str, Any]] = []
507
+ fps = _artifact_fingerprints(selected)
508
+ if not final_meta.get("exists"):
509
+ findings.append(_finding(
510
+ finding_id="final-qc-missing-final-output",
511
+ code="missing_final_output",
512
+ message="final output mp4 is missing",
513
+ category="missing_artifact",
514
+ source={"artifact": str(final_output) if final_output else "final_output"},
515
+ evidence={"final_output": final_meta},
516
+ fingerprints=fps,
517
+ next_action="render_final_output",
518
+ ))
519
+ elif int(final_meta.get("bytes") or 0) <= 0:
520
+ findings.append(_finding(
521
+ finding_id="final-qc-empty-final-output",
522
+ code="empty_final_output",
523
+ message="final output mp4 is empty",
524
+ category="missing_artifact",
525
+ source={"artifact": final_meta.get("path")},
526
+ evidence={"final_output": final_meta},
527
+ fingerprints=fps,
528
+ next_action="rerender_final_output",
529
+ ))
530
+ else:
531
+ probe_error = metadata.get("probe_error")
532
+ if isinstance(probe_error, Mapping):
533
+ findings.append(_finding(
534
+ finding_id="final-qc-probe-failed",
535
+ code="probe_failed",
536
+ message="ffprobe failed or was unavailable for existing non-empty final output",
537
+ category="stream",
538
+ source={"artifact": final_meta.get("path")},
539
+ evidence=probe_error,
540
+ fingerprints=fps,
541
+ next_action="inspect_or_rerender_final_output",
542
+ ))
543
+ else:
544
+ probe = metadata.get("probe")
545
+ probe_findings = _probe_contract_findings(
546
+ probe if isinstance(probe, Mapping) else None,
547
+ final_meta=final_meta,
548
+ fingerprints=fps,
549
+ )
550
+ findings.extend(probe_findings)
551
+ # Header probing cannot see a container-valid but media-truncated/corrupt payload.
552
+ # A cheap tail decode catches it; skip for offline fixtures and when ffmpeg is absent
553
+ # (decode_ok is None). Only add on a definite decode failure to avoid false-blocking.
554
+ if probe_fixture is None and not probe_findings:
555
+ decode_ok, decode_detail = (decode_runner or _tail_decode_check)(selected)
556
+ if decode_ok is False:
557
+ findings.append(_finding(
558
+ finding_id="final-qc-undecodable-stream",
559
+ code="undecodable_stream",
560
+ message="final output tail failed to decode (truncated or corrupt media payload)",
561
+ category="stream",
562
+ source={"artifact": final_meta.get("path")},
563
+ evidence={"decode_error": decode_detail},
564
+ fingerprints=fps,
565
+ next_action="rerender_final_output",
566
+ ))
567
+ findings.extend(_upstream_blockers(root, "assembly_qc.json"))
568
+ findings.extend(_upstream_blockers(root, "visual_qc.json"))
569
+ report = qc_contract.build_report(
570
+ artifact=FINAL_QC_ARTIFACT,
571
+ stage=POST_RENDER_STAGE,
572
+ findings=findings,
573
+ metadata=metadata,
574
+ )
575
+ qc_contract.validate_report(report)
576
+ return report
577
+
578
+
579
+ def _load_or_build_final_qc(work_dir: Path, final_qc_report: Mapping[str, Any] | None) -> dict[str, Any]:
580
+ if final_qc_report is not None:
581
+ report = dict(redact_secrets(final_qc_report))
582
+ else:
583
+ existing = safe_load_json(work_dir / FINAL_QC_ARTIFACT)
584
+ report = dict(existing) if isinstance(existing, Mapping) else build_final_qc(work_dir)
585
+ qc_contract.validate_report(report)
586
+ return report
587
+
588
+
589
+ def build_golden_eval(work_dir: str | Path, final_qc_report: Mapping[str, Any] | None = None,
590
+ golden_fixture: Any = None) -> dict[str, Any]:
591
+ root = Path(work_dir)
592
+ final_report = _load_or_build_final_qc(root, final_qc_report)
593
+ fixture = safe_load_json(golden_fixture)
594
+ fixture = fixture if isinstance(fixture, Mapping) else {}
595
+ metadata = {
596
+ "work_dir": str(root),
597
+ "fixture": fixture,
598
+ "final_qc": {
599
+ "ok": final_report.get("ok"),
600
+ "blocker_count": final_report.get("blocker_count"),
601
+ "artifact": final_report.get("artifact"),
602
+ "stage": final_report.get("stage"),
603
+ },
604
+ "final_qc_fingerprint": fingerprint_file(root / FINAL_QC_ARTIFACT),
605
+ "auto_repair": False,
606
+ }
607
+ findings: list[dict[str, Any]] = []
608
+ expected_ok = fixture.get("expected_final_qc_ok", True)
609
+ if isinstance(expected_ok, bool) and bool(final_report.get("ok")) != expected_ok:
610
+ findings.append(_finding(
611
+ finding_id="golden-final-qc-ok-mismatch",
612
+ stage=GOLDEN_STAGE,
613
+ code="expected_final_qc_ok_mismatch",
614
+ message="final_qc ok state does not match golden expectation",
615
+ category="schema_invalid",
616
+ source={"artifact": FINAL_QC_ARTIFACT},
617
+ evidence={"expected": expected_ok, "actual": final_report.get("ok")},
618
+ fingerprints={FINAL_QC_ARTIFACT: metadata["final_qc_fingerprint"]} if metadata["final_qc_fingerprint"] else {},
619
+ next_action="fix_final_qc_blockers",
620
+ ))
621
+ final_meta = {}
622
+ probe = None
623
+ if isinstance(final_report.get("metadata"), Mapping):
624
+ final_meta = final_report["metadata"].get("final_output") or {}
625
+ probe = final_report["metadata"].get("probe")
626
+ duration = _duration_from_probe(probe)
627
+ codec = _codec_from_probe(probe)
628
+ if fixture.get("min_duration") is not None and (duration is None or duration < float(fixture["min_duration"])):
629
+ findings.append(_finding(
630
+ finding_id="golden-min-duration-mismatch",
631
+ stage=GOLDEN_STAGE,
632
+ code="min_duration_mismatch",
633
+ message="final output duration is below golden minimum",
634
+ category="duration",
635
+ source={"artifact": final_meta.get("path")},
636
+ evidence={"expected_min_duration": fixture.get("min_duration"), "actual_duration": duration},
637
+ next_action="adjust_render_duration",
638
+ ))
639
+ if fixture.get("max_duration") is not None and (duration is None or duration > float(fixture["max_duration"])):
640
+ findings.append(_finding(
641
+ finding_id="golden-max-duration-mismatch",
642
+ stage=GOLDEN_STAGE,
643
+ code="max_duration_mismatch",
644
+ message="final output duration is above golden maximum",
645
+ category="duration",
646
+ source={"artifact": final_meta.get("path")},
647
+ evidence={"expected_max_duration": fixture.get("max_duration"), "actual_duration": duration},
648
+ next_action="adjust_render_duration",
649
+ ))
650
+ expected_codec = fixture.get("expected_codec") or fixture.get("expected_video_codec")
651
+ if expected_codec is not None and codec != str(expected_codec):
652
+ findings.append(_finding(
653
+ finding_id="golden-codec-mismatch",
654
+ stage=GOLDEN_STAGE,
655
+ code="codec_mismatch",
656
+ message="final output video codec does not match golden expectation",
657
+ category="stream",
658
+ source={"artifact": final_meta.get("path")},
659
+ evidence={"expected_codec": expected_codec, "actual_codec": codec},
660
+ next_action="adjust_render_codec",
661
+ ))
662
+ required = fixture.get("required_artifacts") or []
663
+ if isinstance(required, Sequence) and not isinstance(required, (str, bytes)):
664
+ for idx, name in enumerate(required):
665
+ artifact_path = root / str(name)
666
+ if not artifact_path.exists() or not artifact_path.is_file() or artifact_path.stat().st_size <= 0:
667
+ findings.append(_finding(
668
+ finding_id=f"golden-required-artifact-missing-{idx}",
669
+ stage=GOLDEN_STAGE,
670
+ code="required_artifact_missing",
671
+ message="golden fixture requires an artifact that is missing or empty",
672
+ category="missing_artifact",
673
+ source={"artifact": str(name)},
674
+ evidence={"required_artifact": str(name)},
675
+ next_action="produce_required_artifact",
676
+ ))
677
+ metadata["observed"] = {"duration": duration, "codec": codec, "final_output": final_meta}
678
+ report = qc_contract.build_report(
679
+ artifact=GOLDEN_EVAL_ARTIFACT,
680
+ stage=GOLDEN_STAGE,
681
+ findings=findings,
682
+ metadata=redact_secrets(_json_safe(metadata)),
683
+ )
684
+ qc_contract.validate_report(report)
685
+ return report
686
+
687
+
688
+ def _write_report(path: Path, report: Mapping[str, Any]) -> None:
689
+ qc_contract.validate_report(report)
690
+ path.write_text(json.dumps(redact_secrets(report), ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
691
+ qc_contract.validate_report(json.loads(path.read_text(encoding="utf-8")))
692
+
693
+
694
+ def run(work_dir: str | Path, final_output: str | Path | None = None,
695
+ probe_fixture: Any = None, golden_fixture: Any = None,
696
+ probe_runner: ProbeRunner | None = None, only: str | None = None) -> dict[str, Any]:
697
+ root = Path(work_dir)
698
+ root.mkdir(parents=True, exist_ok=True)
699
+ mode = {"final": "final_qc", "golden": "golden_eval"}.get(only or "all", only or "all")
700
+ if mode not in {"all", "final_qc", "golden_eval"}:
701
+ raise ValueError("only must be one of all, final_qc, golden_eval, final, golden")
702
+ result: dict[str, Any] = {"work_dir": str(root), "written": []}
703
+ final_report: dict[str, Any] | None = None
704
+ if mode in {"all", "final_qc"}:
705
+ final_report = build_final_qc(root, final_output=final_output, probe_fixture=probe_fixture, probe_runner=probe_runner)
706
+ _write_report(root / FINAL_QC_ARTIFACT, final_report)
707
+ result.update({"final_qc": {"ok": final_report["ok"], "blocker_count": final_report["blocker_count"]}})
708
+ result["written"].append(FINAL_QC_ARTIFACT)
709
+ if mode in {"all", "golden_eval"}:
710
+ golden_report = build_golden_eval(root, final_qc_report=final_report, golden_fixture=golden_fixture)
711
+ _write_report(root / GOLDEN_EVAL_ARTIFACT, golden_report)
712
+ result.update({"golden_eval": {"ok": golden_report["ok"], "blocker_count": golden_report["blocker_count"]}})
713
+ result["written"].append(GOLDEN_EVAL_ARTIFACT)
714
+ return result
715
+
716
+
717
+ def main(argv: Sequence[str] | None = None) -> int:
718
+ ap = argparse.ArgumentParser(description="Write final_qc.json and golden_eval.json for a video-recap work_dir.")
719
+ ap.add_argument("--work-dir", required=True)
720
+ ap.add_argument("--final-output", default=None)
721
+ ap.add_argument("--probe-fixture", default=None)
722
+ ap.add_argument("--golden-fixture", default=None)
723
+ ap.add_argument("--only", choices=["all", "final_qc", "golden_eval", "final", "golden"], default="all")
724
+ args = ap.parse_args(argv)
725
+ summary = run(
726
+ args.work_dir,
727
+ final_output=args.final_output,
728
+ probe_fixture=args.probe_fixture,
729
+ golden_fixture=args.golden_fixture,
730
+ only=args.only,
731
+ )
732
+ print(json.dumps(summary, ensure_ascii=False, sort_keys=True))
733
+ return 0
734
+
735
+
736
+ if __name__ == "__main__":
737
+ raise SystemExit(main())