@clipen/clipen-cli 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -2
  3. package/apps/web/dist/assets/index-D5D2HiB1.js +14 -0
  4. package/apps/web/dist/assets/index-DIMuOXSu.css +1 -0
  5. package/apps/web/dist/favicon.svg +1 -0
  6. package/apps/web/dist/index.html +16 -0
  7. package/bin/clipen.js +157 -0
  8. package/clipen +18 -0
  9. package/install +25 -0
  10. package/package.json +55 -4
  11. package/pyproject.toml +44 -0
  12. package/requirements/asr-runtime.txt +13 -0
  13. package/requirements/dev.txt +2 -0
  14. package/requirements/runtime.txt +20 -0
  15. package/src/clipen/__init__.py +3 -0
  16. package/src/clipen/analysis/__init__.py +89 -0
  17. package/src/clipen/analysis/artifacts.py +410 -0
  18. package/src/clipen/analysis/audio.py +394 -0
  19. package/src/clipen/analysis/evidence.py +102 -0
  20. package/src/clipen/analysis/evidence_service.py +929 -0
  21. package/src/clipen/analysis/image_similarity.py +134 -0
  22. package/src/clipen/analysis/keyframes.py +159 -0
  23. package/src/clipen/analysis/models.py +228 -0
  24. package/src/clipen/analysis/qwen_worker.py +594 -0
  25. package/src/clipen/analysis/resources.py +22 -0
  26. package/src/clipen/analysis/runtime.py +62 -0
  27. package/src/clipen/analysis/service.py +594 -0
  28. package/src/clipen/analysis/setup.py +921 -0
  29. package/src/clipen/analysis/setup_cli.py +107 -0
  30. package/src/clipen/analysis/storage.py +1864 -0
  31. package/src/clipen/analysis/transcription.py +906 -0
  32. package/src/clipen/analysis/visual.py +237 -0
  33. package/src/clipen/annotations/__init__.py +13 -0
  34. package/src/clipen/annotations/models.py +22 -0
  35. package/src/clipen/annotations/storage.py +428 -0
  36. package/src/clipen/annotations/suggestions.py +115 -0
  37. package/src/clipen/asr_release.py +132 -0
  38. package/src/clipen/bootstrap.py +978 -0
  39. package/src/clipen/candidates.py +222 -0
  40. package/src/clipen/cli.py +84 -0
  41. package/src/clipen/controller/__init__.py +17 -0
  42. package/src/clipen/controller/app.py +1657 -0
  43. package/src/clipen/controller/server.py +533 -0
  44. package/src/clipen/domain/__init__.py +30 -0
  45. package/src/clipen/domain/errors.py +5 -0
  46. package/src/clipen/domain/media_time.py +110 -0
  47. package/src/clipen/domain/timeline.py +582 -0
  48. package/src/clipen/domain/validation.py +14 -0
  49. package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +38 -0
  50. package/src/clipen/editing/PROGRAM_FORMAT.md +102 -0
  51. package/src/clipen/editing/README.md +115 -0
  52. package/src/clipen/editing/REFACTOR_DESIGN.md +241 -0
  53. package/src/clipen/editing/REFACTOR_HANDOFF.md +73 -0
  54. package/src/clipen/editing/__init__.py +15 -0
  55. package/src/clipen/editing/agent.py +13 -0
  56. package/src/clipen/editing/agent_models.py +127 -0
  57. package/src/clipen/editing/agent_repository.py +978 -0
  58. package/src/clipen/editing/agent_tools.py +613 -0
  59. package/src/clipen/editing/alignment.py +150 -0
  60. package/src/clipen/editing/alignment_setup.py +156 -0
  61. package/src/clipen/editing/alignment_worker.py +24 -0
  62. package/src/clipen/editing/change_report.py +128 -0
  63. package/src/clipen/editing/compiler.py +40 -0
  64. package/src/clipen/editing/component_looks.py +131 -0
  65. package/src/clipen/editing/component_review.py +74 -0
  66. package/src/clipen/editing/coordinator.py +497 -0
  67. package/src/clipen/editing/editorial_review.py +309 -0
  68. package/src/clipen/editing/evidence_jobs.py +552 -0
  69. package/src/clipen/editing/history_changes.py +192 -0
  70. package/src/clipen/editing/music_choices.py +18 -0
  71. package/src/clipen/editing/production_catalog.py +629 -0
  72. package/src/clipen/editing/production_limits.py +85 -0
  73. package/src/clipen/editing/production_media.py +435 -0
  74. package/src/clipen/editing/production_preview.py +373 -0
  75. package/src/clipen/editing/production_progress.py +236 -0
  76. package/src/clipen/editing/production_requirements.py +117 -0
  77. package/src/clipen/editing/production_tools.py +1198 -0
  78. package/src/clipen/editing/program_audio.py +248 -0
  79. package/src/clipen/editing/program_direction.py +83 -0
  80. package/src/clipen/editing/program_story.py +91 -0
  81. package/src/clipen/editing/program_subtitles.py +232 -0
  82. package/src/clipen/editing/programme_review.py +121 -0
  83. package/src/clipen/editing/prompt_history.py +84 -0
  84. package/src/clipen/editing/recut.py +167 -0
  85. package/src/clipen/editing/refinement_references.py +278 -0
  86. package/src/clipen/editing/resolve_export.py +847 -0
  87. package/src/clipen/editing/resolve_titles.py +291 -0
  88. package/src/clipen/editing/skill_tools.py +951 -0
  89. package/src/clipen/editing/source_dialogue.py +192 -0
  90. package/src/clipen/editing/speech_coverage.py +50 -0
  91. package/src/clipen/editing/speech_quality.py +11 -0
  92. package/src/clipen/editing/tool_receipts.py +98 -0
  93. package/src/clipen/editing/versions.py +219 -0
  94. package/src/clipen/editing/visual_preview.py +189 -0
  95. package/src/clipen/editing/workbench.py +136 -0
  96. package/src/clipen/filesystem.py +25 -0
  97. package/src/clipen/finishing/README.md +103 -0
  98. package/src/clipen/finishing/__init__.py +1 -0
  99. package/src/clipen/finishing/audio.py +188 -0
  100. package/src/clipen/finishing/catalog.py +264 -0
  101. package/src/clipen/finishing/models.py +14 -0
  102. package/src/clipen/finishing/renderer.py +45 -0
  103. package/src/clipen/mcp_editing/__init__.py +5 -0
  104. package/src/clipen/mcp_editing/__main__.py +42 -0
  105. package/src/clipen/mcp_editing/server.py +396 -0
  106. package/src/clipen/media/__init__.py +50 -0
  107. package/src/clipen/media/discovery.py +253 -0
  108. package/src/clipen/media/models.py +349 -0
  109. package/src/clipen/media/preview.py +137 -0
  110. package/src/clipen/media/probe.py +418 -0
  111. package/src/clipen/media/service.py +304 -0
  112. package/src/clipen/media/storage.py +694 -0
  113. package/src/clipen/music_vocabulary.py +34 -0
  114. package/src/clipen/power.py +28 -0
  115. package/src/clipen/projects/__init__.py +26 -0
  116. package/src/clipen/projects/agent_schema.py +94 -0
  117. package/src/clipen/projects/annotation_schema.py +40 -0
  118. package/src/clipen/projects/deletion.py +256 -0
  119. package/src/clipen/projects/evidence_schema.py +52 -0
  120. package/src/clipen/projects/finishing_schema.py +36 -0
  121. package/src/clipen/projects/models.py +189 -0
  122. package/src/clipen/projects/picker.py +232 -0
  123. package/src/clipen/projects/preview_schema.py +29 -0
  124. package/src/clipen/projects/service.py +159 -0
  125. package/src/clipen/projects/storage.py +1458 -0
  126. package/src/clipen/projects/timeline_schema.py +32 -0
  127. package/src/clipen/projects/validation_schema.py +28 -0
  128. package/src/clipen/provider_registry.py +77 -0
  129. package/src/clipen/providers/__init__.py +43 -0
  130. package/src/clipen/providers/account.py +245 -0
  131. package/src/clipen/providers/claude.py +409 -0
  132. package/src/clipen/providers/claude_editing.py +118 -0
  133. package/src/clipen/providers/codex.py +991 -0
  134. package/src/clipen/providers/codex_editing.py +91 -0
  135. package/src/clipen/providers/editing_agent.py +567 -0
  136. package/src/clipen/providers/errors.py +51 -0
  137. package/src/clipen/providers/recovery.py +269 -0
  138. package/src/clipen/py.typed +1 -0
  139. package/src/clipen/rendering/__init__.py +12 -0
  140. package/src/clipen/rendering/cover.py +139 -0
  141. package/src/clipen/rendering/custom_components.py +328 -0
  142. package/src/clipen/rendering/custom_render.py +218 -0
  143. package/src/clipen/rendering/fonts/anton-OFL.txt +93 -0
  144. package/src/clipen/rendering/fonts/bebasneue-OFL.txt +93 -0
  145. package/src/clipen/rendering/fonts/caveat-OFL.txt +93 -0
  146. package/src/clipen/rendering/fonts/chenyu-OFL.txt +93 -0
  147. package/src/clipen/rendering/fonts/delagothicone-OFL.txt +93 -0
  148. package/src/clipen/rendering/fonts/hachimarupop-OFL.txt +93 -0
  149. package/src/clipen/rendering/fonts/iansui-OFL.txt +93 -0
  150. package/src/clipen/rendering/fonts/manifest.json +145 -0
  151. package/src/clipen/rendering/fonts/playfairdisplay-OFL.txt +93 -0
  152. package/src/clipen/rendering/fonts/rocknrollone-OFL.txt +93 -0
  153. package/src/clipen/rendering/fonts/yomogi-OFL.txt +94 -0
  154. package/src/clipen/rendering/fonts/yuseimagic-OFL.txt +93 -0
  155. package/src/clipen/rendering/fonts/zenkurenaido-OFL.txt +93 -0
  156. package/src/clipen/rendering/fonts/zenmarugothic-OFL.txt +93 -0
  157. package/src/clipen/rendering/production_effects.py +96 -0
  158. package/src/clipen/rendering/program_components.py +254 -0
  159. package/src/clipen/rendering/program_creator.py +804 -0
  160. package/src/clipen/rendering/program_identities.py +350 -0
  161. package/src/clipen/rendering/program_motion.py +186 -0
  162. package/src/clipen/rendering/program_studio.py +227 -0
  163. package/src/clipen/rendering/program_styles.py +321 -0
  164. package/src/clipen/rendering/program_subtitles.py +89 -0
  165. package/src/clipen/rendering/renderer.py +737 -0
  166. package/src/clipen/rendering/storage.py +230 -0
  167. package/src/clipen/rendering/titles.py +467 -0
  168. package/src/clipen/skills/__init__.py +5 -0
  169. package/src/clipen/skills/builtin/SKILL.md +72 -0
  170. package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
  171. package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
  172. package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
  173. package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
  174. package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
  175. package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
  176. package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
  177. package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
  178. package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
  179. package/src/clipen/skills/builtin/assets/style-cinema.png +0 -0
  180. package/src/clipen/skills/builtin/assets/style-editorial.png +0 -0
  181. package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
  182. package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
  183. package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
  184. package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
  185. package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
  186. package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
  187. package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
  188. package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
  189. package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
  190. package/src/clipen/skills/builtin/assets/style-variety.png +0 -0
  191. package/src/clipen/skills/builtin/components.json +133 -0
  192. package/src/clipen/skills/builtin/font_sources.json +20 -0
  193. package/src/clipen/skills/builtin/font_styles.json +329 -0
  194. package/src/clipen/skills/builtin/manifest.json +32 -0
  195. package/src/clipen/skills/builtin/presets.json +8 -0
  196. package/src/clipen/skills/builtin/references/captions.md +14 -0
  197. package/src/clipen/skills/builtin/references/channel-design.md +37 -0
  198. package/src/clipen/skills/builtin/references/editing.md +30 -0
  199. package/src/clipen/skills/builtin/references/font-chenyu-OFL.txt +93 -0
  200. package/src/clipen/skills/builtin/references/font-iansui-OFL.txt +93 -0
  201. package/src/clipen/skills/builtin/references/graphics.md +59 -0
  202. package/src/clipen/skills/builtin/references/review.md +16 -0
  203. package/src/clipen/skills/builtin/references/sound.md +8 -0
  204. package/src/clipen/skills/builtin/references/story.md +7 -0
  205. package/src/clipen/skills/builtin/skills/travel-program/SKILL.md +27 -0
  206. package/src/clipen/skills/builtin/skills/travel-program/manifest.json +6 -0
  207. package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +33 -0
  208. package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/manifest.json +8 -0
  209. package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +34 -0
  210. package/src/clipen/skills/builtin/template-skills/clipen-event-recap/manifest.json +8 -0
  211. package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +33 -0
  212. package/src/clipen/skills/builtin/template-skills/clipen-food-review/manifest.json +8 -0
  213. package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +35 -0
  214. package/src/clipen/skills/builtin/template-skills/clipen-product-demo/manifest.json +8 -0
  215. package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +36 -0
  216. package/src/clipen/skills/builtin/template-skills/clipen-product-review/manifest.json +8 -0
  217. package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +39 -0
  218. package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/manifest.json +8 -0
  219. package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +38 -0
  220. package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/manifest.json +8 -0
  221. package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +34 -0
  222. package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/manifest.json +8 -0
  223. package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +37 -0
  224. package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/manifest.json +8 -0
  225. package/src/clipen/skills/builtin/templates.json +284 -0
  226. package/src/clipen/skills/builtin/visual_styles.json +1074 -0
  227. package/src/clipen/skills/catalog.py +314 -0
  228. package/src/clipen/skills/library.py +137 -0
  229. package/src/clipen/skills/package.py +254 -0
  230. package/src/clipen/skills/visual_styles.py +55 -0
  231. package/src/clipen/workspace.py +181 -0
  232. package/uninstall +25 -0
@@ -0,0 +1,629 @@
1
+ """Discoverable contracts for the agent's production tools, shared by MCP and dispatch."""
2
+
3
+ import json
4
+
5
+ from jsonschema import Draft202012Validator
6
+
7
+ from clipen.music_vocabulary import MUSIC_TAGS
8
+ from clipen.projects import ProjectError
9
+
10
+
11
+ def schema(name, description, properties=None, required=None):
12
+ properties = properties or {}
13
+ return {
14
+ "name": name,
15
+ "description": description,
16
+ "inputSchema": {
17
+ "type": "object",
18
+ "properties": properties,
19
+ "required": list(properties if required is None else required),
20
+ "additionalProperties": False,
21
+ },
22
+ }
23
+
24
+
25
+ ID = {"type": "string", "minLength": 1, "maxLength": 160}
26
+ TEXT = {"type": "string", "minLength": 1, "maxLength": 500}
27
+ FRAME = {"type": "integer", "minimum": 0, "maximum": 108000}
28
+ LENGTH = {"type": "integer", "minimum": 1, "maximum": 108000}
29
+ UNIT = {"type": "number", "minimum": 0, "maximum": 1}
30
+ GAIN = {"type": "number", "minimum": -60, "maximum": 12}
31
+ SPAN = {"start_frame": FRAME, "duration_frames": LENGTH}
32
+ SUMMARY = {"summary": TEXT}
33
+ RECT = {
34
+ **SPAN,
35
+ "x": UNIT,
36
+ "y": UNIT,
37
+ "width": {"type": "number", "exclusiveMinimum": 0, "maximum": 1},
38
+ "height": {"type": "number", "exclusiveMinimum": 0, "maximum": 1},
39
+ "block_size": {"type": "integer", "minimum": 4, "maximum": 96},
40
+ }
41
+ EXTRA_TOOLS = (
42
+ schema("list_editing_tools", "Discover executable tools, limits and explicitly unsupported capabilities."),
43
+ schema(
44
+ "search_source_dialogue",
45
+ "Search all current source transcripts before choosing clips. Empty query browses complete utterances. Includes adjacent speech for context; inspect actual footage before inferring events.",
46
+ {
47
+ "query": {"type": "string", "maxLength": 120},
48
+ "version_id": ID,
49
+ "include_drafts": {"type": "boolean"},
50
+ "offset": {"type": "integer", "minimum": 0, "maximum": 100000},
51
+ "limit": {"type": "integer", "minimum": 1, "maximum": 30},
52
+ },
53
+ [],
54
+ ),
55
+ schema(
56
+ "list_source_media",
57
+ "Page through all currently inventoried source streams, including material absent from earlier candidate selection. Never copies reference footage.",
58
+ {
59
+ "offset": {"type": "integer", "minimum": 0, "maximum": 100000},
60
+ "limit": {"type": "integer", "minimum": 1, "maximum": 50},
61
+ },
62
+ [],
63
+ ),
64
+ schema(
65
+ "register_source_range",
66
+ "Create an executable candidate anywhere inside an inventoried source stream. Record observations as model-authored evidence, not verified transcript.",
67
+ {
68
+ "version_id": ID,
69
+ "stream_index": {"type": "integer", "minimum": 0, "maximum": 4096},
70
+ "start_offset_seconds": {"type": "number", "minimum": 0},
71
+ "duration_seconds": {"type": "number", "exclusiveMinimum": 0, "maximum": 3600},
72
+ "description": TEXT,
73
+ },
74
+ ),
75
+ schema(
76
+ "record_story_plan",
77
+ "Persist the agent-authored story plan and uncertainties against real candidates; this does not pretend the user confirmed the new treatment.",
78
+ {
79
+ "intent": TEXT,
80
+ "sections": {
81
+ "type": "array",
82
+ "minItems": 1,
83
+ "maxItems": 30,
84
+ "items": {
85
+ "type": "object",
86
+ "properties": {
87
+ "purpose": TEXT,
88
+ "candidate_ids": {"type": "array", "items": ID, "maxItems": 30},
89
+ "treatment": TEXT,
90
+ },
91
+ "required": ["purpose", "candidate_ids", "treatment"],
92
+ "additionalProperties": False,
93
+ },
94
+ },
95
+ "uncertainties": {"type": "array", "items": TEXT, "maxItems": 30},
96
+ },
97
+ ),
98
+ schema(
99
+ "read_story_plan",
100
+ "Read the last model-authored story plan for this run; the confirmed user intent remains separately available.",
101
+ ),
102
+ schema(
103
+ "plan_episode",
104
+ "Plan a dialogue-led programme: audience question, real experience, response/payoff and a purpose for every selected shot. Optional start_frame/duration_frames mark beats within continuous shots without artificial cuts; beats must cover the timeline once in order. Link retained cue IDs when quoting speech. This is an authored treatment, not evidence that the story is entertaining.",
105
+ {
106
+ "premise": TEXT,
107
+ "audience_question": TEXT,
108
+ "payoff": TEXT,
109
+ "beats": {
110
+ "type": "array",
111
+ "minItems": 1,
112
+ "maxItems": 30,
113
+ "items": {
114
+ "type": "object",
115
+ "properties": {
116
+ "beat_id": ID,
117
+ "role": {"enum": ["hook", "setup", "experience", "response", "payoff", "bridge"]},
118
+ **SPAN,
119
+ "item_ids": {"type": "array", "items": ID, "minItems": 1, "maxItems": 30, "uniqueItems": True},
120
+ "dialogue_ids": {"type": "array", "items": ID, "maxItems": 30, "uniqueItems": True},
121
+ "source_evidence": TEXT,
122
+ "audience_takeaway": TEXT,
123
+ },
124
+ "required": ["beat_id", "role", "item_ids", "dialogue_ids", "source_evidence", "audience_takeaway"],
125
+ "additionalProperties": False,
126
+ },
127
+ },
128
+ },
129
+ ),
130
+ schema(
131
+ "set_canvas",
132
+ "Choose a bounded SDR preview canvas before styling. Changes the revision and invalidates previous render review; source media and timing remain intact.",
133
+ {"width": {"enum": [640, 1280, 1920]}, "height": {"enum": [360, 720, 1080]}, **SUMMARY},
134
+ ),
135
+ schema(
136
+ "set_target_duration",
137
+ "Update the production duration only when the latest user revision request changes the desired length (including matching selected music). Cite an exact request_excerpt and derive seconds from the request or measured music. Never lower the target just to pass delivery checks. Saves an audit event without changing shots, graphics, audio or render review.",
138
+ {
139
+ "target_duration_seconds": {"type": "integer", "minimum": 30, "maximum": 1200},
140
+ "request_excerpt": TEXT,
141
+ **SUMMARY,
142
+ },
143
+ ),
144
+ schema(
145
+ "sample_source",
146
+ "Choose exact sample offsets inside a candidate. Returns actual frames with source timestamps; does not infer unseen motion.",
147
+ {
148
+ "candidate_id": ID,
149
+ "offsets_seconds": {
150
+ "type": "array",
151
+ "items": {"type": "number", "minimum": 0},
152
+ "minItems": 1,
153
+ "maxItems": 8,
154
+ },
155
+ },
156
+ ),
157
+ schema(
158
+ "inspect_candidates",
159
+ "Audition up to three candidate source ranges before choosing shots. Returns start/middle/end images, transcripts and evidence limitations in one call. Prefer this to repeatedly requesting single cached stills; refine with sample_source when action is missed.",
160
+ {"candidate_ids": {"type": "array", "items": ID, "minItems": 1, "maxItems": 3, "uniqueItems": True}},
161
+ ),
162
+ schema(
163
+ "inspect_cut",
164
+ "Inspect start/middle/end of up to three current shots in one call, with exact source ranges, speech repair spans and overlapping text. Omit render_id to inspect sources before decorating; provide render_id for rendered review. All shots and text must be covered before finish.",
165
+ {
166
+ "item_ids": {"type": "array", "items": ID, "minItems": 1, "maxItems": 3, "uniqueItems": True},
167
+ "render_id": ID,
168
+ },
169
+ ["item_ids"],
170
+ ),
171
+ schema(
172
+ "inspect_pacing",
173
+ "Inspect actual source continuity across the current timeline. Adjacent pieces of the same take are grouped even when split; use this to find prolonged stretches to review. This does not decide whether a scene is interesting.",
174
+ ),
175
+ schema(
176
+ "review_cut",
177
+ "Save an editorial assessment of the exact current revision after inspecting every changed rendered shot (unchanged shots accepted earlier in this run are carried and may be omitted). Keep specific unresolved problems as revise/matches=false; these block finish. This is a model assessment, not human approval.",
178
+ {
179
+ "shots": {
180
+ "type": "array",
181
+ "maxItems": 180,
182
+ "items": {
183
+ "type": "object",
184
+ "properties": {"item_id": ID, "observation": TEXT, "decision": {"enum": ["keep", "revise"]}},
185
+ "required": ["item_id", "observation", "decision"],
186
+ "additionalProperties": False,
187
+ },
188
+ },
189
+ "text_checks": {
190
+ "type": "array",
191
+ "maxItems": 960,
192
+ "items": {
193
+ "type": "object",
194
+ "properties": {"item_id": ID, "evidence": TEXT, "matches": {"type": "boolean"}},
195
+ "required": ["item_id", "evidence", "matches"],
196
+ "additionalProperties": False,
197
+ },
198
+ },
199
+ "story_assessment": TEXT,
200
+ "audio_limitations": TEXT,
201
+ },
202
+ ),
203
+ schema(
204
+ "replace_clip_source",
205
+ "Replace one shot with an exact inventoried source span, including expansion to a complete utterance returned by list_transcripts. Reflows the timeline and invalidates overlays. Does not restrict selection to earlier candidate windows.",
206
+ {
207
+ "item_id": ID,
208
+ "source": {
209
+ "type": "object",
210
+ "properties": {
211
+ "version_id": ID,
212
+ "stream_index": {"type": "integer", "minimum": 0},
213
+ "start_pts": {"type": "string", "pattern": "^-?[0-9]+$"},
214
+ "end_pts": {"type": "string", "pattern": "^-?[0-9]+$"},
215
+ "time_base": {
216
+ "type": "object",
217
+ "properties": {
218
+ "num": {"type": "integer", "minimum": 1},
219
+ "den": {"type": "integer", "minimum": 1},
220
+ },
221
+ "required": ["num", "den"],
222
+ "additionalProperties": False,
223
+ },
224
+ },
225
+ "required": ["version_id", "stream_index", "start_pts", "end_pts", "time_base"],
226
+ "additionalProperties": False,
227
+ },
228
+ **SUMMARY,
229
+ },
230
+ ),
231
+ schema(
232
+ "list_transcripts",
233
+ "Read complete source utterances remapped to the current cut, or a candidate before cutting. include_drafts explicitly exposes low-confidence ASR as unverified draft cues, not human-approved speech.",
234
+ {"candidate_id": ID, "include_drafts": {"type": "boolean"}},
235
+ [],
236
+ ),
237
+ schema(
238
+ "replace_subtitles",
239
+ "Replace the editable subtitle track using returned cue IDs and faithful text; [] removes subtitles. source_excerpt selects an exact character range [start,end) in the source cue, with estimated timing, to omit uncertain ASR without inventing replacement speech. Omit unreliable cues entirely when needed; original audio is preserved.",
240
+ {
241
+ "captions": {
242
+ "type": "array",
243
+ "items": {
244
+ "type": "object",
245
+ "properties": {
246
+ "cue_id": ID,
247
+ "text": TEXT,
248
+ "source_excerpt": {
249
+ "type": "object",
250
+ "properties": {
251
+ "start": {"type": "integer", "minimum": 0, "maximum": 500},
252
+ "end": {"type": "integer", "minimum": 1, "maximum": 500},
253
+ },
254
+ "required": ["start", "end"],
255
+ "additionalProperties": False,
256
+ },
257
+ "delivery": {"enum": ["dialogue", "punchline", "quiet"]},
258
+ "emphasis": {
259
+ "type": "array",
260
+ "items": {"type": "string", "minLength": 1, "maxLength": 16},
261
+ "maxItems": 4,
262
+ "uniqueItems": True,
263
+ },
264
+ },
265
+ "required": ["cue_id", "text"],
266
+ "additionalProperties": False,
267
+ },
268
+ "maxItems": 960,
269
+ },
270
+ "allow_asr_draft": {"type": "boolean"},
271
+ **SUMMARY,
272
+ },
273
+ ["captions", "summary"],
274
+ ),
275
+ schema(
276
+ "remove_item",
277
+ "Delete a selected timeline element; video deletion closes the gap and invalidates time-bound overlays.",
278
+ {"item_id": ID, **SUMMARY},
279
+ ),
280
+ schema(
281
+ "trim_clip",
282
+ "Trim within the current source span, close the gap, and invalidate overlays/audio placements whose timing changed.",
283
+ {"item_id": ID, "start_offset_frames": FRAME, "duration_frames": LENGTH, **SUMMARY},
284
+ ),
285
+ schema(
286
+ "reorder_clips",
287
+ "Reorder all video item IDs exactly once. Clears overlays and audio placements; inspect and reapply them against the new cut.",
288
+ {"item_ids": {"type": "array", "items": ID, "minItems": 1, "maxItems": 180}, **SUMMARY},
289
+ ),
290
+ schema(
291
+ "split_clip",
292
+ "Split a video clip at a relative frame. Existing effects/placements on that clip are cleared for explicit reapplication.",
293
+ {"item_id": ID, "offset_frames": LENGTH, **SUMMARY},
294
+ ),
295
+ schema(
296
+ "insert_clip",
297
+ "Insert a precisely trimmed candidate before a video item, or at end when before_item_id is null. Invalidates overlays.",
298
+ {
299
+ "candidate_id": ID,
300
+ "start_offset_seconds": {"type": "number", "minimum": 0},
301
+ "duration_seconds": {"type": "number", "minimum": 0.75, "maximum": 30},
302
+ "before_item_id": {"anyOf": [ID, {"type": "null"}]},
303
+ **SUMMARY,
304
+ },
305
+ ),
306
+ schema(
307
+ "set_source_audio",
308
+ "Choose camera sound treatment and gain for one video clip.",
309
+ {"item_id": ID, "mode": {"enum": ["keep", "mute", "dialogue"]}, "gain_db": GAIN, **SUMMARY},
310
+ ),
311
+ schema(
312
+ "set_color_grade",
313
+ "Set explicit per-clip exposure/contrast/saturation; neutral values remove the visual grade.",
314
+ {
315
+ "item_id": ID,
316
+ "contrast": {"type": "number", "minimum": 0.5, "maximum": 2},
317
+ "saturation": {"type": "number", "minimum": 0, "maximum": 2},
318
+ "brightness": {"type": "number", "minimum": -0.3, "maximum": 0.3},
319
+ **SUMMARY,
320
+ },
321
+ ),
322
+ schema(
323
+ "set_mosaic",
324
+ "Set static timed rectangular mosaic regions in final canvas coordinates. Multiple intervals permit manual tracking; no automatic tracking claim. [] clears.",
325
+ {
326
+ "item_id": ID,
327
+ "regions": {
328
+ "type": "array",
329
+ "items": {"type": "object", "properties": RECT, "required": list(RECT), "additionalProperties": False},
330
+ "maxItems": 32,
331
+ },
332
+ **SUMMARY,
333
+ },
334
+ ),
335
+ schema(
336
+ "set_transition",
337
+ "Set a dip to black/white at the incoming clip boundary, or none. Duration is in timeline frames.",
338
+ {
339
+ "item_id": ID,
340
+ "kind": {"enum": ["dip_black", "dip_white", "none"]},
341
+ "duration_frames": {"type": "integer", "minimum": 2, "maximum": 60},
342
+ **SUMMARY,
343
+ },
344
+ ),
345
+ schema(
346
+ "set_fade",
347
+ "Fade the beginning/end of THIS shot to black. Use fade_out_frames on the final shot for an actual ending. This is independent of incoming scene transitions. Zero removes that fade.",
348
+ {"item_id": ID, "fade_in_frames": FRAME, "fade_out_frames": FRAME, **SUMMARY},
349
+ ),
350
+ schema(
351
+ "remove_clip_effect",
352
+ "Remove any named semantic effect from a video/audio clip.",
353
+ {"item_id": ID, "effect_id": ID, **SUMMARY},
354
+ ),
355
+ schema(
356
+ "search_music",
357
+ "Search and acquire up to three public instrumental candidates. Only generic music tags leave the project; preserve source/license evidence.",
358
+ {"tags": {"type": "array", "items": {"enum": MUSIC_TAGS}, "minItems": 1, "maxItems": 4}},
359
+ ),
360
+ schema("list_audio_assets", "List acquired audio candidates and provenance without filesystem paths."),
361
+ schema(
362
+ "extract_audio",
363
+ "Prepare a local source range as an audio asset for ambience, dialogue or sound effects. No ownership/license claim is invented.",
364
+ {
365
+ "candidate_id": ID,
366
+ "start_offset_seconds": {"type": "number", "minimum": 0},
367
+ "duration_seconds": {"type": "number", "exclusiveMinimum": 0, "maximum": 90},
368
+ },
369
+ ),
370
+ schema(
371
+ "inspect_audio",
372
+ "Read measured loudness, peaks, onsets, BPM and source/license metadata. This is analysis, not listening.",
373
+ {"asset_id": ID},
374
+ ),
375
+ schema(
376
+ "place_audio",
377
+ "Add/update a named audio layer anchored to a video clip. Supports independent offsets, gain, fades and dialogue ducking.",
378
+ {
379
+ "item_id": ID,
380
+ "layer_id": ID,
381
+ "asset_id": ID,
382
+ **SPAN,
383
+ "source_offset_seconds": {"type": "number", "minimum": 0, "maximum": 3600},
384
+ "gain_db": GAIN,
385
+ "duck": {"type": "boolean"},
386
+ "fade_seconds": {"type": "number", "minimum": 0, "maximum": 5},
387
+ **SUMMARY,
388
+ },
389
+ ),
390
+ schema("remove_audio", "Remove one named audio layer from the current timeline.", {"layer_id": ID, **SUMMARY}),
391
+ schema(
392
+ "render_preview",
393
+ "Render the current immutable revision locally for review. Asynchronous: inspect_preview reads the actual result. Reuses a successful exact-revision render.",
394
+ ),
395
+ schema(
396
+ "inspect_preview",
397
+ "Wait at most 30 seconds for a run-owned preview and inspect exact output timestamps. Does not claim audio listening or full-motion review.",
398
+ {
399
+ "render_id": ID,
400
+ "offsets_seconds": {"type": "array", "items": {"type": "number", "minimum": 0}, "maxItems": 8},
401
+ "wait_seconds": {"type": "number", "minimum": 0, "maximum": 30},
402
+ },
403
+ ["render_id", "offsets_seconds"],
404
+ ),
405
+ schema("cancel_preview", "Cancel a preview started in this run; preserves the timeline.", {"render_id": ID}),
406
+ schema(
407
+ "validate_sequence",
408
+ "Check executable timing, effects, audio references and render freshness. Returns actionable issues; never aesthetic approval.",
409
+ ),
410
+ schema(
411
+ "get_edit_history",
412
+ "Read this run's versions (one per complete edit) and its most recent tool events, newest first. Page back with before_sequence.",
413
+ {
414
+ "before_sequence": {"type": "integer", "minimum": 1},
415
+ "limit": {"type": "integer", "minimum": 1, "maximum": 80},
416
+ },
417
+ required=[],
418
+ ),
419
+ schema(
420
+ "restore_revision",
421
+ "Restore a run-owned immutable revision as a new current selection.",
422
+ {"revision_id": ID, **SUMMARY},
423
+ ),
424
+ schema(
425
+ "export_edit",
426
+ "Save native editable timeline JSON and source/license credits for the current revision. This is not a Resolve project.",
427
+ ),
428
+ )
429
+ CUSTOM_COMPONENT_HELP = (
430
+ "Design an in-picture graphic freely as one self-contained web page: any HTML, CSS, SVG, Canvas or JavaScript, any layout, "
431
+ "typeface, colour, shape or motion. Use it when the built-in components cannot give the look the film needs. "
432
+ "The page is the whole picture (window.clipen.width x window.clipen.height pixels, e.g. 1920x1080); draw only the graphic and leave "
433
+ "the rest transparent, so the footage shows through. Clipen sets the time: CSS animations and the Web Animations API play by "
434
+ "themselves, frame-accurately; for script-driven drawing define window.clipenFrame = (frame, seconds) => {...} (may be async) "
435
+ "and draw that exact frame there. requestAnimationFrame loops, timers and real clocks do not advance. Frame 0 is the first frame "
436
+ "of the graphic; window.clipen also gives fps and durationFrames. The page has no network: inline everything (data: URLs, inline SVG). "
437
+ "Looks: graphics of one kind (chapters, places, reactions...) share a look you define first with set_component_look: its typefaces and "
438
+ "colours. Pass its look_id; Clipen gives the page that look as CSS variables, font-family: var(--look-font-<key>) and colour var(--look-<key>). "
439
+ "Text may only use the look's typefaces (anything else is refused); colours, layout, shapes and motion stay free. To use another typeface, "
440
+ "change the look or make a new one; every graphic using a look follows its changes. Only technical checks apply otherwise: the page must load, run without "
441
+ "errors, draw each frame within 10 seconds, draw something, and stay under 200 KB. The result returns two images: a still of the graphic at rest over the footage, and a sheet of frames from entry to exit (labelled by frame number), so you can judge the motion; look at both and fix what does not read. "
442
+ 'Mark what people may change themselves: put each main wording as plain text in an element with data-clipen-text="key" '
443
+ '(optional data-clipen-label="主標"), and declare main colours as :root custom properties named --clipen-<name> (e.g. --clipen-主色) used via var(). '
444
+ "Their changes are applied before your scripts run; split text into letters on DOMContentLoaded or later, from the element's current text."
445
+ )
446
+ CUSTOM_COMPONENT_FIELDS = {
447
+ "element_id": ID,
448
+ "item_id": {
449
+ **ID,
450
+ "description": "The shot the graphic starts in; it follows that footage on a recut and may run on past the cut.",
451
+ },
452
+ "start_offset_frames": FRAME,
453
+ "duration_frames": LENGTH,
454
+ "name": {
455
+ "type": "string",
456
+ "minLength": 1,
457
+ "maxLength": 40,
458
+ "description": "Short label people see on the timeline, e.g. 澀谷地標標題.",
459
+ },
460
+ "html": {"type": "string", "minLength": 1, "maxLength": 200000},
461
+ "look_id": {
462
+ **ID,
463
+ "description": "The look (typefaces and colours) this graphic uses, from set_component_look. Required when adding.",
464
+ },
465
+ "evidence": TEXT,
466
+ **SUMMARY,
467
+ }
468
+ LOOK_KEY = {"type": "string", "minLength": 1, "maxLength": 24}
469
+ LOOK_HELP = (
470
+ "Create or change a look: a named set of typefaces and colours that graphics of one kind share (e.g. a chapter look, a place look, "
471
+ "a reaction look). Design each look for its role; looks may differ completely. Pages use the look through CSS variables: "
472
+ "font-family: var(--look-font-<key>) and color var(--look-<key>). Graphics already using this look_id are redrawn with it; a change is "
473
+ "refused if one of them would then need a typeface the look no longer has. Typefaces: list_program_components gives font_choices "
474
+ "(system fonts, plus fonts Clipen carries: Chinese handwriting 'Clipen Chenyu' and brush 'Clipen Iansui', Japanese handwriting "
475
+ "'Yusei Magic', 'Yomogi', 'Zen Kurenaido', 'Hachi Maru Pop', Japanese display 'Dela Gothic One', 'RocknRoll One', 'Zen Maru Gothic', "
476
+ "Latin 'Bebas Neue', 'Anton', 'Caveat', 'Playfair Display'). A character a typeface lacks is drawn by a face of the same feel "
477
+ "(Japanese kana in Clipen Chenyu fall to Yomogi), so mixed Chinese and Japanese keep one style; prefer a Japanese face for mainly "
478
+ "Japanese text. At most 8 looks, 3 typefaces and 6 colours each."
479
+ )
480
+ SKILL_TOOLS = (
481
+ schema(
482
+ "list_production_skills", "List bundled production skills; selecting one never analyzes or uploads footage."
483
+ ),
484
+ schema(
485
+ "read_production_skill",
486
+ "Read one resource from the skill version frozen for this session. Start with SKILL.md, then load relevant references.",
487
+ {"resource": {"type": "string", "maxLength": 120}},
488
+ [],
489
+ ),
490
+ schema(
491
+ "list_program_components",
492
+ "Read executable components, visual presets, exact tool parameters and limitations for the selected skill.",
493
+ ),
494
+ schema(
495
+ "remove_program_component",
496
+ "Remove one programme graphic without changing the cut, captions or music.",
497
+ {"element_id": ID, **SUMMARY},
498
+ ),
499
+ schema(
500
+ "set_component_look",
501
+ LOOK_HELP,
502
+ {
503
+ "look_id": ID,
504
+ "name": {
505
+ "type": "string",
506
+ "minLength": 1,
507
+ "maxLength": 24,
508
+ "description": "What people see, e.g. 章節, 地點, 反應字.",
509
+ },
510
+ "fonts": {
511
+ "type": "array",
512
+ "minItems": 1,
513
+ "maxItems": 3,
514
+ "items": {
515
+ "type": "object",
516
+ "properties": {"key": LOOK_KEY, "label": LOOK_KEY, "family": {"type": "string", "maxLength": 40}},
517
+ "required": ["key", "family"],
518
+ "additionalProperties": False,
519
+ },
520
+ },
521
+ "colors": {
522
+ "type": "array",
523
+ "maxItems": 6,
524
+ "items": {
525
+ "type": "object",
526
+ "properties": {
527
+ "key": LOOK_KEY,
528
+ "label": LOOK_KEY,
529
+ "value": {"type": "string", "pattern": "^#[0-9a-fA-F]{6}$"},
530
+ },
531
+ "required": ["key", "value"],
532
+ "additionalProperties": False,
533
+ },
534
+ },
535
+ **SUMMARY,
536
+ },
537
+ ["look_id", "name", "fonts", "summary"],
538
+ ),
539
+ schema(
540
+ "add_custom_component",
541
+ CUSTOM_COMPONENT_HELP,
542
+ CUSTOM_COMPONENT_FIELDS,
543
+ ["element_id", "item_id", "start_offset_frames", "duration_frames", "name", "html", "look_id", "summary"],
544
+ ),
545
+ schema(
546
+ "update_custom_component",
547
+ "Replace any part of a graphic made with add_custom_component (its page, name, shot, timing or look); anything left out stays as it is. An older graphic without a look needs look_id. Preserves its identity and supports exact revision undo.",
548
+ CUSTOM_COMPONENT_FIELDS,
549
+ ["element_id", "summary"],
550
+ ),
551
+ )
552
+
553
+ EXTRA_TOOLS += SKILL_TOOLS
554
+ EXTRA_TOOLS += (
555
+ schema(
556
+ "transcribe_source_range",
557
+ "Transcribe one registered source range locally, on demand. No old analysis/plan needed. Async job with explicit coverage; does not invent word timing.",
558
+ {"candidate_id": ID, "language": {"enum": ["zh", "en", "ja"]}, "align_words": {"type": "boolean"}},
559
+ ["candidate_id"],
560
+ ),
561
+ schema(
562
+ "align_source_speech",
563
+ "Align the exact ASR text from a successful transcription job to its source audio using an installed offline aligner. Does not verify wording or upload audio.",
564
+ {"transcript_job_id": ID},
565
+ ),
566
+ schema(
567
+ "read_evidence_job",
568
+ "Read a run-owned local evidence job. Wait up to 15 seconds; polling never repeats inference.",
569
+ {"job_id": ID, "wait_seconds": {"type": "number", "minimum": 0, "maximum": 15}},
570
+ ["job_id"],
571
+ ),
572
+ schema(
573
+ "cancel_evidence_job",
574
+ "Cancel local source transcription/alignment; preserves completed evidence and edit revisions.",
575
+ {"job_id": ID},
576
+ ),
577
+ schema(
578
+ "inspect_mix",
579
+ "Read measurements and dialogue-driven duck envelopes from an actual run-owned render. Reports camera/music/final stems separately; numeric evidence is not audio listening.",
580
+ {"render_id": ID},
581
+ ),
582
+ schema(
583
+ "prepare_local_speech",
584
+ "Prepare the fixed local transcription or word-alignment runtime when unavailable. Requires the session model-download grant. Async and cancellable; never uploads source audio.",
585
+ {"target": {"enum": ["transcription", "alignment"]}},
586
+ ),
587
+ schema(
588
+ "retry_evidence_job",
589
+ "Explicitly retry a failed/cancelled/interrupted LOCAL evidence job as a new attempt. The old outcome is preserved; reuse request_id to avoid starting the same retry twice.",
590
+ {"job_id": ID, "request_id": ID},
591
+ ),
592
+ schema(
593
+ "revise_source_speech",
594
+ "Propose a grounded correction to one source utterance and re-align it locally. Preserves original ASR, reason and model-authored authority; never claims human verification.",
595
+ {
596
+ "transcript_job_id": ID,
597
+ "segment_ordinal": {"type": "integer", "minimum": 0, "maximum": 99},
598
+ "text": TEXT,
599
+ "evidence": TEXT,
600
+ },
601
+ ),
602
+ schema(
603
+ "read_mutation_receipt",
604
+ "Read one run-owned mutation outcome after a lost response. A started receipt means outcome unknown: inspect the current revision before choosing another action.",
605
+ {"mutation_id": ID},
606
+ ),
607
+ )
608
+ EXTRA_NAMES = tuple(t["name"] for t in EXTRA_TOOLS)
609
+ # Older films keep graphics made with the retired built-in templates; Clipen still draws them, and the
610
+ # AI may remove one, but it designs every new graphic itself (add_custom_component).
611
+ AGENT_TOOLS = EXTRA_TOOLS
612
+ AGENT_NAMES = EXTRA_NAMES
613
+ BY_NAME = {t["name"]: t for t in EXTRA_TOOLS}
614
+
615
+
616
+ def validate_arguments(name, arguments):
617
+ errors = list(Draft202012Validator(BY_NAME[name]["inputSchema"]).iter_errors(arguments))
618
+ if errors:
619
+ # Report the failing field and constraint, never echo source text/IDs or
620
+ # a potentially huge value. Models otherwise repeat the same invalid call.
621
+ error = errors[0]
622
+ field = ".".join(str(p) for p in error.absolute_path) or "arguments"
623
+ constraint = error.validator
624
+ expected = json.dumps(error.validator_value, ensure_ascii=False)[:240]
625
+ raise ProjectError(
626
+ "agent_input_invalid",
627
+ f"{name}: {field} 不符合 {constraint}={expected};請依工具 schema 修正。",
628
+ status_code=422,
629
+ )