@clipen/clipen-cli 1.0.0 → 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 (127) hide show
  1. package/README.md +60 -50
  2. package/package.json +7 -4
  3. package/pyproject.toml +18 -2
  4. package/requirements/dev.txt +2 -0
  5. package/src/clipen/__init__.py +1 -1
  6. package/src/clipen/analysis/__init__.py +7 -7
  7. package/src/clipen/analysis/artifacts.py +4 -10
  8. package/src/clipen/analysis/audio.py +10 -8
  9. package/src/clipen/analysis/evidence_service.py +345 -167
  10. package/src/clipen/analysis/image_similarity.py +5 -14
  11. package/src/clipen/analysis/keyframes.py +5 -17
  12. package/src/clipen/analysis/models.py +5 -7
  13. package/src/clipen/analysis/qwen_worker.py +19 -54
  14. package/src/clipen/analysis/resources.py +2 -1
  15. package/src/clipen/analysis/runtime.py +1 -3
  16. package/src/clipen/analysis/service.py +16 -48
  17. package/src/clipen/analysis/setup.py +11 -25
  18. package/src/clipen/analysis/setup_cli.py +5 -15
  19. package/src/clipen/analysis/storage.py +96 -278
  20. package/src/clipen/analysis/transcription.py +40 -82
  21. package/src/clipen/analysis/visual.py +109 -48
  22. package/src/clipen/annotations/__init__.py +5 -2
  23. package/src/clipen/annotations/models.py +1 -1
  24. package/src/clipen/annotations/storage.py +132 -84
  25. package/src/clipen/annotations/suggestions.py +3 -8
  26. package/src/clipen/asr_release.py +4 -11
  27. package/src/clipen/bootstrap.py +65 -54
  28. package/src/clipen/{planning/models.py → candidates.py} +29 -47
  29. package/src/clipen/cli.py +2 -2
  30. package/src/clipen/controller/app.py +401 -214
  31. package/src/clipen/controller/server.py +28 -38
  32. package/src/clipen/domain/__init__.py +1 -1
  33. package/src/clipen/domain/media_time.py +3 -10
  34. package/src/clipen/domain/timeline.py +45 -47
  35. package/src/clipen/domain/validation.py +0 -1
  36. package/src/clipen/editing/__init__.py +1 -1
  37. package/src/clipen/editing/agent_models.py +4 -11
  38. package/src/clipen/editing/agent_repository.py +391 -170
  39. package/src/clipen/editing/agent_tools.py +180 -99
  40. package/src/clipen/editing/alignment.py +92 -52
  41. package/src/clipen/editing/alignment_setup.py +118 -70
  42. package/src/clipen/editing/alignment_worker.py +11 -9
  43. package/src/clipen/editing/change_report.py +95 -38
  44. package/src/clipen/editing/compiler.py +0 -1
  45. package/src/clipen/editing/component_looks.py +58 -34
  46. package/src/clipen/editing/component_review.py +34 -38
  47. package/src/clipen/editing/coordinator.py +213 -90
  48. package/src/clipen/editing/editorial_review.py +217 -95
  49. package/src/clipen/editing/evidence_jobs.py +457 -200
  50. package/src/clipen/editing/history_changes.py +129 -68
  51. package/src/clipen/editing/music_choices.py +8 -5
  52. package/src/clipen/editing/production_catalog.py +573 -136
  53. package/src/clipen/editing/production_limits.py +43 -17
  54. package/src/clipen/editing/production_media.py +376 -167
  55. package/src/clipen/editing/production_preview.py +322 -129
  56. package/src/clipen/editing/production_progress.py +164 -69
  57. package/src/clipen/editing/production_requirements.py +106 -39
  58. package/src/clipen/editing/production_tools.py +1064 -462
  59. package/src/clipen/editing/program_audio.py +211 -81
  60. package/src/clipen/editing/program_direction.py +59 -25
  61. package/src/clipen/editing/program_story.py +83 -45
  62. package/src/clipen/editing/program_subtitles.py +194 -96
  63. package/src/clipen/editing/programme_review.py +98 -50
  64. package/src/clipen/editing/prompt_history.py +64 -27
  65. package/src/clipen/editing/recut.py +65 -25
  66. package/src/clipen/editing/refinement_references.py +176 -86
  67. package/src/clipen/editing/resolve_export.py +449 -218
  68. package/src/clipen/editing/resolve_titles.py +162 -105
  69. package/src/clipen/editing/skill_tools.py +530 -154
  70. package/src/clipen/editing/source_dialogue.py +177 -67
  71. package/src/clipen/editing/speech_coverage.py +42 -22
  72. package/src/clipen/editing/speech_quality.py +6 -1
  73. package/src/clipen/editing/tool_receipts.py +78 -32
  74. package/src/clipen/editing/versions.py +122 -64
  75. package/src/clipen/editing/visual_preview.py +157 -61
  76. package/src/clipen/editing/workbench.py +104 -42
  77. package/src/clipen/finishing/audio.py +69 -30
  78. package/src/clipen/finishing/catalog.py +176 -93
  79. package/src/clipen/finishing/models.py +1 -1
  80. package/src/clipen/finishing/renderer.py +33 -14
  81. package/src/clipen/mcp_editing/__main__.py +3 -1
  82. package/src/clipen/mcp_editing/server.py +77 -34
  83. package/src/clipen/media/__init__.py +3 -3
  84. package/src/clipen/media/discovery.py +7 -20
  85. package/src/clipen/media/models.py +7 -18
  86. package/src/clipen/media/preview.py +14 -24
  87. package/src/clipen/media/probe.py +16 -44
  88. package/src/clipen/media/service.py +6 -19
  89. package/src/clipen/media/storage.py +33 -81
  90. package/src/clipen/music_vocabulary.py +33 -4
  91. package/src/clipen/power.py +8 -3
  92. package/src/clipen/projects/__init__.py +1 -1
  93. package/src/clipen/projects/deletion.py +19 -32
  94. package/src/clipen/projects/finishing_schema.py +3 -1
  95. package/src/clipen/projects/models.py +2 -5
  96. package/src/clipen/projects/picker.py +13 -37
  97. package/src/clipen/projects/service.py +8 -24
  98. package/src/clipen/projects/storage.py +226 -246
  99. package/src/clipen/provider_registry.py +4 -2
  100. package/src/clipen/providers/account.py +86 -35
  101. package/src/clipen/providers/claude.py +59 -25
  102. package/src/clipen/providers/claude_editing.py +14 -7
  103. package/src/clipen/providers/codex.py +73 -118
  104. package/src/clipen/providers/codex_editing.py +2 -2
  105. package/src/clipen/providers/editing_agent.py +19 -17
  106. package/src/clipen/providers/recovery.py +7 -8
  107. package/src/clipen/rendering/cover.py +18 -5
  108. package/src/clipen/rendering/custom_components.py +167 -79
  109. package/src/clipen/rendering/custom_render.py +62 -41
  110. package/src/clipen/rendering/production_effects.py +77 -45
  111. package/src/clipen/rendering/program_components.py +134 -73
  112. package/src/clipen/rendering/program_creator.py +432 -277
  113. package/src/clipen/rendering/program_identities.py +277 -182
  114. package/src/clipen/rendering/program_motion.py +140 -95
  115. package/src/clipen/rendering/program_studio.py +175 -116
  116. package/src/clipen/rendering/program_styles.py +231 -145
  117. package/src/clipen/rendering/program_subtitles.py +71 -34
  118. package/src/clipen/rendering/renderer.py +150 -121
  119. package/src/clipen/rendering/storage.py +9 -22
  120. package/src/clipen/rendering/titles.py +193 -86
  121. package/src/clipen/skills/__init__.py +1 -0
  122. package/src/clipen/skills/catalog.py +151 -55
  123. package/src/clipen/skills/library.py +13 -7
  124. package/src/clipen/skills/package.py +46 -23
  125. package/src/clipen/skills/visual_styles.py +29 -18
  126. package/src/clipen/workspace.py +15 -44
  127. package/src/clipen/planning/__init__.py +0 -9
@@ -3,6 +3,7 @@
3
3
  Coverage proves which stills were delivered, never that motion or sound was
4
4
  understood. Findings expose the model's decisions rather than inventing a score.
5
5
  """
6
+
6
7
  import hashlib
7
8
  import json
8
9
  from fractions import Fraction
@@ -10,6 +11,7 @@ from fractions import Fraction
10
11
  from clipen.domain import EditTimeline, TrackKind
11
12
  from clipen.media import MediaPreviewRepository
12
13
  from clipen.projects import ProjectError
14
+
13
15
  from .agent_models import ToolResult
14
16
  from .production_media import sample_frames
15
17
  from .production_preview import _event, inspect_preview
@@ -17,8 +19,11 @@ from .production_preview import _event, inspect_preview
17
19
 
18
20
  def shot_offsets(item, fps):
19
21
  # First/last real frames, not the following shot at the outgoing boundary.
20
- return [item.start_frame/fps, (item.start_frame+(item.duration_frames-1)/2)/fps,
21
- (item.start_frame+item.duration_frames-1)/fps]
22
+ return [
23
+ item.start_frame / fps,
24
+ (item.start_frame + (item.duration_frames - 1) / 2) / fps,
25
+ (item.start_frame + item.duration_frames - 1) / fps,
26
+ ]
22
27
 
23
28
 
24
29
  def _effects(item):
@@ -43,12 +48,28 @@ def shot_fingerprints(timeline):
43
48
  for index, clip in enumerate(clips):
44
49
  end = clip.start_frame + clip.duration_frames
45
50
  following = clips[index + 1] if index + 1 < len(clips) else None
46
- over = sorted((t.text, t.style_id, t.start_frame - clip.start_frame, t.duration_frames)
47
- for t in texts if t.start_frame < end and clip.start_frame < t.start_frame + t.duration_frames)
48
- result[clip.item_id] = _fingerprint({
49
- 'source': clip.source.span.to_storage(), 'duration': clip.duration_frames, 'effects': _effects(clip),
50
- 'next_transition': [e for e in _effects(following) if e[0] == 'video.transition'] if following else None,
51
- 'texts': over, 'canvas': [timeline.width, timeline.height, timeline.frame_rate.numerator, timeline.frame_rate.denominator]})
51
+ over = sorted(
52
+ (t.text, t.style_id, t.start_frame - clip.start_frame, t.duration_frames)
53
+ for t in texts
54
+ if t.start_frame < end and clip.start_frame < t.start_frame + t.duration_frames
55
+ )
56
+ result[clip.item_id] = _fingerprint(
57
+ {
58
+ "source": clip.source.span.to_storage(),
59
+ "duration": clip.duration_frames,
60
+ "effects": _effects(clip),
61
+ "next_transition": [e for e in _effects(following) if e[0] == "video.transition"]
62
+ if following
63
+ else None,
64
+ "texts": over,
65
+ "canvas": [
66
+ timeline.width,
67
+ timeline.height,
68
+ timeline.frame_rate.numerator,
69
+ timeline.frame_rate.denominator,
70
+ ],
71
+ }
72
+ )
52
73
  return result
53
74
 
54
75
 
@@ -63,9 +84,15 @@ def text_fingerprints(timeline):
63
84
  for item in t.items:
64
85
  middle = item.start_frame + (item.duration_frames - 1) / 2
65
86
  under = next((c for c in clips if c.start_frame <= middle < c.start_frame + c.duration_frames), None)
66
- result[item.item_id] = _fingerprint({'text': item.text, 'style': item.style_id, 'duration': item.duration_frames,
67
- 'offset': None if under is None else middle - under.start_frame,
68
- 'shot': None if under is None else shots[under.item_id]})
87
+ result[item.item_id] = _fingerprint(
88
+ {
89
+ "text": item.text,
90
+ "style": item.style_id,
91
+ "duration": item.duration_frames,
92
+ "offset": None if under is None else middle - under.start_frame,
93
+ "shot": None if under is None else shots[under.item_id],
94
+ }
95
+ )
69
96
  return result
70
97
 
71
98
 
@@ -77,111 +104,206 @@ def carried_reviews(tools, revision, recipe_id):
77
104
  """
78
105
  with tools.repository.projects.connect(tools.project_id) as db:
79
106
  reports = {}
80
- for row in db.execute("SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='editorial_review' ORDER BY sequence",
81
- (tools.run_id,)):
82
- report = json.loads(row['payload_json'])
83
- if report.get('recipe_id') == recipe_id and report['revision_id'] != revision.revision_id:
84
- reports[report['revision_id']] = report
85
- payloads = {row['revision_id']: row['payload_json'] for row in db.execute(
86
- f"SELECT revision_id,payload_json FROM edit_agent_revisions WHERE run_id=? AND revision_id IN ({','.join('?' for _ in reports)})",
87
- (tools.run_id, *reports))} if reports else {}
107
+ for row in db.execute(
108
+ "SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='editorial_review' ORDER BY sequence",
109
+ (tools.run_id,),
110
+ ):
111
+ report = json.loads(row["payload_json"])
112
+ if report.get("recipe_id") == recipe_id and report["revision_id"] != revision.revision_id:
113
+ reports[report["revision_id"]] = report
114
+ payloads = (
115
+ {
116
+ row["revision_id"]: row["payload_json"]
117
+ for row in db.execute(
118
+ f"SELECT revision_id,payload_json FROM edit_agent_revisions WHERE run_id=? AND revision_id IN ({','.join('?' for _ in reports)})",
119
+ (tools.run_id, *reports),
120
+ )
121
+ }
122
+ if reports
123
+ else {}
124
+ )
88
125
  accepted_shots, accepted_texts = set(), set()
89
126
  for revision_id, report in reports.items():
90
127
  if revision_id not in payloads:
91
128
  continue
92
129
  earlier = EditTimeline.from_payload(json.loads(payloads[revision_id]))
93
130
  shots, texts = shot_fingerprints(earlier), text_fingerprints(earlier)
94
- accepted_shots |= {shots[s['item_id']] for s in report.get('shots', []) if s.get('decision') != 'revise' and s['item_id'] in shots}
95
- accepted_texts |= {texts[c['item_id']] for c in report.get('text_checks', []) if c.get('matches') and c['item_id'] in texts}
96
- accepted_shots |= set(report.get('carried_shots', []))
97
- accepted_texts |= set(report.get('carried_texts', []))
131
+ accepted_shots |= {
132
+ shots[s["item_id"]]
133
+ for s in report.get("shots", [])
134
+ if s.get("decision") != "revise" and s["item_id"] in shots
135
+ }
136
+ accepted_texts |= {
137
+ texts[c["item_id"]] for c in report.get("text_checks", []) if c.get("matches") and c["item_id"] in texts
138
+ }
139
+ accepted_shots |= set(report.get("carried_shots", []))
140
+ accepted_texts |= set(report.get("carried_texts", []))
98
141
  current_shots, current_texts = shot_fingerprints(revision.timeline), text_fingerprints(revision.timeline)
99
- return ({item: print_ for item, print_ in current_shots.items() if print_ in accepted_shots},
100
- {item: print_ for item, print_ in current_texts.items() if print_ in accepted_texts})
142
+ return (
143
+ {item: print_ for item, print_ in current_shots.items() if print_ in accepted_shots},
144
+ {item: print_ for item, print_ in current_texts.items() if print_ in accepted_texts},
145
+ )
101
146
 
102
147
 
103
148
  def coverage_targets(timeline):
104
- fps=timeline.frame_rate.numerator/timeline.frame_rate.denominator
105
- return {item.item_id:shot_offsets(item,fps) for t in timeline.tracks if t.kind is TrackKind.VIDEO for item in t.items}
149
+ fps = timeline.frame_rate.numerator / timeline.frame_rate.denominator
150
+ return {
151
+ item.item_id: shot_offsets(item, fps) for t in timeline.tracks if t.kind is TrackKind.VIDEO for item in t.items
152
+ }
106
153
 
107
154
 
108
155
  def text_targets(timeline):
109
- fps=timeline.frame_rate.numerator/timeline.frame_rate.denominator
110
- return {item.item_id:(item.start_frame+(item.duration_frames-1)/2)/fps
111
- for t in timeline.tracks if t.kind is TrackKind.TITLE for item in t.items}
112
-
113
-
114
- def inspect_cut(tools,args):
115
- revision=tools.repository.current_revision(tools.project_id,tools.run_id)
116
- timeline=revision.timeline;targets=coverage_targets(timeline)
117
- clips={i.item_id:i for i in tools._video().items}
118
- if any(i not in clips for i in args['item_ids']):
119
- raise ProjectError('timeline_item_not_found','指定鏡頭不在目前剪輯。',status_code=404)
120
- fps=Fraction(timeline.frame_rate.numerator,timeline.frame_rate.denominator)
121
- speech=tools._production_list_transcripts({'include_drafts':True}).payload
122
- cues,limitations=speech['cues'],speech['limitations']
123
- images=[];shots=[]
124
- for identifier in args['item_ids']:
125
- item=clips[identifier]
126
- texts=[i for t in timeline.tracks if t.kind is TrackKind.TITLE for i in t.items
127
- if i.start_frame<item.start_frame+item.duration_frames and item.start_frame<i.start_frame+i.duration_frames]
128
- if args.get('render_id'):
129
- offsets=targets[identifier]+[text_targets(timeline)[i.item_id] for i in texts[:1]]
156
+ fps = timeline.frame_rate.numerator / timeline.frame_rate.denominator
157
+ return {
158
+ item.item_id: (item.start_frame + (item.duration_frames - 1) / 2) / fps
159
+ for t in timeline.tracks
160
+ if t.kind is TrackKind.TITLE
161
+ for item in t.items
162
+ }
163
+
164
+
165
+ def inspect_cut(tools, args):
166
+ revision = tools.repository.current_revision(tools.project_id, tools.run_id)
167
+ timeline = revision.timeline
168
+ targets = coverage_targets(timeline)
169
+ clips = {i.item_id: i for i in tools._video().items}
170
+ if any(i not in clips for i in args["item_ids"]):
171
+ raise ProjectError("timeline_item_not_found", "指定鏡頭不在目前剪輯。", status_code=404)
172
+ fps = Fraction(timeline.frame_rate.numerator, timeline.frame_rate.denominator)
173
+ speech = tools._production_list_transcripts({"include_drafts": True}).payload
174
+ cues, limitations = speech["cues"], speech["limitations"]
175
+ images = []
176
+ shots = []
177
+ for identifier in args["item_ids"]:
178
+ item = clips[identifier]
179
+ texts = [
180
+ i
181
+ for t in timeline.tracks
182
+ if t.kind is TrackKind.TITLE
183
+ for i in t.items
184
+ if i.start_frame < item.start_frame + item.duration_frames
185
+ and item.start_frame < i.start_frame + i.duration_frames
186
+ ]
187
+ if args.get("render_id"):
188
+ offsets = targets[identifier] + [text_targets(timeline)[i.item_id] for i in texts[:1]]
130
189
  # Text can span shots; its midpoint must still be inspected, once.
131
- offsets=sorted(set(offsets))
132
- for start in range(0,len(offsets),8):
133
- result=inspect_preview(tools,{'render_id':args['render_id'],'offsets_seconds':offsets[start:start+8]})
134
- if result.payload['render']['state']!='succeeded' or result.payload['stale']:
190
+ offsets = sorted(set(offsets))
191
+ for start in range(0, len(offsets), 8):
192
+ result = inspect_preview(
193
+ tools, {"render_id": args["render_id"], "offsets_seconds": offsets[start : start + 8]}
194
+ )
195
+ if result.payload["render"]["state"] != "succeeded" or result.payload["stale"]:
135
196
  return ToolResult(result.payload)
136
197
  images.extend(result.images)
137
- samples=[{'timeline_seconds':o} for o in offsets]
198
+ samples = [{"timeline_seconds": o} for o in offsets]
138
199
  else:
139
- span=item.source.span;unit=Fraction(span.time_base.numerator,span.time_base.denominator)
140
- duration=span.duration_pts*unit
141
- last=min(Fraction(item.duration_frames-1,1)/fps,duration-Fraction(1,1)/fps)
142
- offsets=[0,float(max(0,last)/2),float(max(0,last))]
143
- media=getattr(tools,'media',None) or MediaPreviewRepository(tools.repository.projects)
144
- paths,samples=sample_frames(media,tools.project_id,span,offsets,tools._workdir('samples'),tools._cancel_event())
200
+ span = item.source.span
201
+ unit = Fraction(span.time_base.numerator, span.time_base.denominator)
202
+ duration = span.duration_pts * unit
203
+ last = min(Fraction(item.duration_frames - 1, 1) / fps, duration - Fraction(1, 1) / fps)
204
+ offsets = [0, float(max(0, last) / 2), float(max(0, last))]
205
+ media = getattr(tools, "media", None) or MediaPreviewRepository(tools.repository.projects)
206
+ paths, samples = sample_frames(
207
+ media, tools.project_id, span, offsets, tools._workdir("samples"), tools._cancel_event()
208
+ )
145
209
  images.extend(paths)
146
- shots.append({'item_id':identifier,'source':item.source.span.to_storage(),'samples':samples,
147
- 'image_count':len(samples),'texts':[{'item_id':i.item_id,'text':i.text,'start_frame':i.start_frame,'duration_frames':i.duration_frames} for i in texts],
148
- 'dialogue':[c for c in cues if c['item_id']==identifier],
149
- 'dialogue_problems':[c for c in limitations if c['item_id']==identifier]})
210
+ shots.append(
211
+ {
212
+ "item_id": identifier,
213
+ "source": item.source.span.to_storage(),
214
+ "samples": samples,
215
+ "image_count": len(samples),
216
+ "texts": [
217
+ {
218
+ "item_id": i.item_id,
219
+ "text": i.text,
220
+ "start_frame": i.start_frame,
221
+ "duration_frames": i.duration_frames,
222
+ }
223
+ for i in texts
224
+ ],
225
+ "dialogue": [c for c in cues if c["item_id"] == identifier],
226
+ "dialogue_problems": [c for c in limitations if c["item_id"] == identifier],
227
+ }
228
+ )
150
229
  from .programme_review import pacing
151
- return ToolResult({'revision_id':revision.revision_id,'shots':shots,'pacing':pacing(timeline),
152
- 'image_order':'shots in requested order; frames in sample order',
153
- 'coverage':'start/middle/end stills; continuous motion and audio remain unreviewed',
154
- 'text_coverage':'At most one additional text midpoint per shot; validate_sequence lists remaining text samples for inspect_preview.',
155
- 'editorial_questions':['Does this show the event or only preparation/empty wall?',
156
- 'Does the scene establish a place and then deliver action/reaction?',
157
- 'Is each location/day assertion supported by this exact shot?',
158
- 'Does retained speech finish naturally? Repair source spans before captions.']},tuple(images))
159
230
 
231
+ return ToolResult(
232
+ {
233
+ "revision_id": revision.revision_id,
234
+ "shots": shots,
235
+ "pacing": pacing(timeline),
236
+ "image_order": "shots in requested order; frames in sample order",
237
+ "coverage": "start/middle/end stills; continuous motion and audio remain unreviewed",
238
+ "text_coverage": "At most one additional text midpoint per shot; validate_sequence lists remaining text samples for inspect_preview.",
239
+ "editorial_questions": [
240
+ "Does this show the event or only preparation/empty wall?",
241
+ "Does the scene establish a place and then deliver action/reaction?",
242
+ "Is each location/day assertion supported by this exact shot?",
243
+ "Does retained speech finish naturally? Repair source spans before captions.",
244
+ ],
245
+ },
246
+ tuple(images),
247
+ )
160
248
 
161
- def review_cut(tools,args):
249
+
250
+ def review_cut(tools, args):
162
251
  from .production_preview import finish_review_status
163
- revision=tools.repository.current_revision(tools.project_id,tools.run_id)
164
- status=finish_review_status(tools)
165
- if not status['render_coverage_complete']:
166
- raise ProjectError('agent_preview_review_required','請先檢視每個鏡頭的頭、中、尾及所有文字顯示畫面。',status_code=409)
167
- every_shot=set(coverage_targets(revision.timeline));every_text=set(text_targets(revision.timeline))
168
- carried_shots,carried_texts=set(status.get('carried_shots',())),set(status.get('carried_texts',()))
169
- shots=args['shots'];checks=args['text_checks']
170
- listed_shots=[s['item_id'] for s in shots];listed_texts=[c['item_id'] for c in checks]
252
+
253
+ revision = tools.repository.current_revision(tools.project_id, tools.run_id)
254
+ status = finish_review_status(tools)
255
+ if not status["render_coverage_complete"]:
256
+ raise ProjectError(
257
+ "agent_preview_review_required", "請先檢視每個鏡頭的頭、中、尾及所有文字顯示畫面。", status_code=409
258
+ )
259
+ every_shot = set(coverage_targets(revision.timeline))
260
+ every_text = set(text_targets(revision.timeline))
261
+ carried_shots, carried_texts = set(status.get("carried_shots", ())), set(status.get("carried_texts", ()))
262
+ shots = args["shots"]
263
+ checks = args["text_checks"]
264
+ listed_shots = [s["item_id"] for s in shots]
265
+ listed_texts = [c["item_id"] for c in checks]
171
266
  # Every changed shot and text must be judged; unchanged, already accepted ones may be listed or left out.
172
- if (len(listed_shots)!=len(set(listed_shots)) or not every_shot-carried_shots<=set(listed_shots)<=every_shot
173
- or len(listed_texts)!=len(set(listed_texts)) or not every_text-carried_texts<=set(listed_texts)<=every_text):
174
- raise ProjectError('agent_review_incomplete','審片紀錄必須逐一列出所有改過的鏡頭與文字,不可重複或遺漏;沒改過且已通過的可以省略。',status_code=422)
175
- if status['unresolved']:
176
- still_unresolved={s['item_id'] for s in shots if s['decision']=='revise'}|{c['item_id'] for c in checks if not c['matches']}
177
- if not set(status['unresolved'])<=still_unresolved:
178
- raise ProjectError('agent_revision_required','這個版本已記錄待修問題;請先實際修改時間軸,再輸出並檢視新版,不能只改評語清除問題。',status_code=409)
267
+ if (
268
+ len(listed_shots) != len(set(listed_shots))
269
+ or not every_shot - carried_shots <= set(listed_shots) <= every_shot
270
+ or len(listed_texts) != len(set(listed_texts))
271
+ or not every_text - carried_texts <= set(listed_texts) <= every_text
272
+ ):
273
+ raise ProjectError(
274
+ "agent_review_incomplete",
275
+ "審片紀錄必須逐一列出所有改過的鏡頭與文字,不可重複或遺漏;沒改過且已通過的可以省略。",
276
+ status_code=422,
277
+ )
278
+ if status["unresolved"]:
279
+ still_unresolved = {s["item_id"] for s in shots if s["decision"] == "revise"} | {
280
+ c["item_id"] for c in checks if not c["matches"]
281
+ }
282
+ if not set(status["unresolved"]) <= still_unresolved:
283
+ raise ProjectError(
284
+ "agent_revision_required",
285
+ "這個版本已記錄待修問題;請先實際修改時間軸,再輸出並檢視新版,不能只改評語清除問題。",
286
+ status_code=409,
287
+ )
179
288
  from .production_preview import render_recipe_id
180
- shot_prints,text_prints=shot_fingerprints(revision.timeline),text_fingerprints(revision.timeline)
181
- report={'revision_id':revision.revision_id,'recipe_id':render_recipe_id(),'authority':'model_authored',**args,
182
- # Carried items keep their earlier acceptance for later revisions.
183
- 'carried_shots':sorted(shot_prints[i] for i in carried_shots-set(listed_shots)),
184
- 'carried_texts':sorted(text_prints[i] for i in carried_texts-set(listed_texts))}
185
- _event(tools,'editorial_review',report)
186
- return ToolResult({'assessment':report,'unresolved':[s['item_id'] for s in shots if s['decision']=='revise']+[c['item_id'] for c in checks if not c['matches']],
187
- 'human_review':'pending','quality_claim':'This records model findings, not independent approval.'})
289
+
290
+ shot_prints, text_prints = shot_fingerprints(revision.timeline), text_fingerprints(revision.timeline)
291
+ report = {
292
+ "revision_id": revision.revision_id,
293
+ "recipe_id": render_recipe_id(),
294
+ "authority": "model_authored",
295
+ **args,
296
+ # Carried items keep their earlier acceptance for later revisions.
297
+ "carried_shots": sorted(shot_prints[i] for i in carried_shots - set(listed_shots)),
298
+ "carried_texts": sorted(text_prints[i] for i in carried_texts - set(listed_texts)),
299
+ }
300
+ _event(tools, "editorial_review", report)
301
+ return ToolResult(
302
+ {
303
+ "assessment": report,
304
+ "unresolved": [s["item_id"] for s in shots if s["decision"] == "revise"]
305
+ + [c["item_id"] for c in checks if not c["matches"]],
306
+ "human_review": "pending",
307
+ "quality_claim": "This records model findings, not independent approval.",
308
+ }
309
+ )