@clipen/clipen-cli 1.0.7 → 1.0.9

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 (99) hide show
  1. package/README.md +16 -6
  2. package/apps/web/dist/assets/index-DPgSvXZ1.js +15 -0
  3. package/apps/web/dist/assets/index-DmPWV61v.css +1 -0
  4. package/apps/web/dist/index.html +2 -2
  5. package/bin/clipen.js +229 -68
  6. package/package.json +8 -2
  7. package/pyproject.toml +1 -1
  8. package/src/clipen/__init__.py +1 -1
  9. package/src/clipen/analysis/qwen_worker.py +13 -4
  10. package/src/clipen/analysis/setup.py +2 -1
  11. package/src/clipen/analysis/setup_cli.py +58 -12
  12. package/src/clipen/bootstrap.py +499 -167
  13. package/src/clipen/cli.py +40 -15
  14. package/src/clipen/controller/app.py +120 -38
  15. package/src/clipen/controller/server.py +70 -27
  16. package/src/clipen/editing/agent_repository.py +8 -0
  17. package/src/clipen/editing/agent_tools.py +1 -1
  18. package/src/clipen/editing/caption_design.py +134 -0
  19. package/src/clipen/editing/change_report.py +17 -0
  20. package/src/clipen/editing/component_looks.py +3 -3
  21. package/src/clipen/editing/component_review.py +0 -38
  22. package/src/clipen/editing/coordinator.py +20 -0
  23. package/src/clipen/editing/evidence_jobs.py +3 -1
  24. package/src/clipen/editing/history_changes.py +56 -27
  25. package/src/clipen/editing/production_catalog.py +67 -13
  26. package/src/clipen/editing/production_media.py +13 -2
  27. package/src/clipen/editing/production_preview.py +11 -9
  28. package/src/clipen/editing/production_progress.py +48 -3
  29. package/src/clipen/editing/production_tools.py +11 -20
  30. package/src/clipen/editing/program_subtitles.py +5 -13
  31. package/src/clipen/editing/resolve_export.py +2 -183
  32. package/src/clipen/editing/skill_tools.py +142 -218
  33. package/src/clipen/editing/tool_receipts.py +2 -1
  34. package/src/clipen/editing/versions.py +55 -10
  35. package/src/clipen/editing/visual_preview.py +62 -0
  36. package/src/clipen/editing/workbench.py +21 -1
  37. package/src/clipen/i18n.py +155 -0
  38. package/src/clipen/locale_en.py +546 -0
  39. package/src/clipen/mcp_editing/__main__.py +8 -0
  40. package/src/clipen/media/storage.py +2 -2
  41. package/src/clipen/own_ffmpeg.py +113 -0
  42. package/src/clipen/projects/models.py +16 -1
  43. package/src/clipen/projects/picker.py +3 -1
  44. package/src/clipen/projects/storage.py +17 -1
  45. package/src/clipen/providers/claude_editing.py +3 -1
  46. package/src/clipen/providers/codex_editing.py +3 -1
  47. package/src/clipen/providers/editing_agent.py +42 -5
  48. package/src/clipen/providers/liveness.py +39 -0
  49. package/src/clipen/rendering/custom_components.py +216 -25
  50. package/src/clipen/rendering/custom_render.py +90 -54
  51. package/src/clipen/rendering/fetched_fonts.py +127 -0
  52. package/src/clipen/rendering/production_effects.py +24 -2
  53. package/src/clipen/rendering/program_components.py +18 -240
  54. package/src/clipen/rendering/renderer.py +23 -17
  55. package/src/clipen/rendering/titles.py +29 -12
  56. package/src/clipen/skills/builtin/SKILL.md +3 -3
  57. package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
  58. package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
  59. package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
  60. package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
  61. package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
  62. package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
  63. package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
  64. package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
  65. package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
  66. package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
  67. package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
  68. package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
  69. package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
  70. package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
  71. package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
  72. package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
  73. package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
  74. package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
  75. package/src/clipen/skills/builtin/display.en.json +89 -0
  76. package/src/clipen/skills/builtin/references/captions.md +12 -0
  77. package/src/clipen/skills/builtin/references/graphics.md +6 -6
  78. package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +9 -4
  79. package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +10 -5
  80. package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +9 -4
  81. package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +10 -6
  82. package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +10 -6
  83. package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +9 -7
  84. package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +10 -5
  85. package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +10 -5
  86. package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +10 -7
  87. package/src/clipen/skills/catalog.py +22 -8
  88. package/src/clipen/skills/package.py +1 -10
  89. package/src/clipen/terminal.py +344 -0
  90. package/src/clipen/workspace.py +97 -28
  91. package/apps/web/dist/assets/index-C3Zw0WaM.js +0 -14
  92. package/apps/web/dist/assets/index-CaxEZKLc.css +0 -1
  93. package/src/clipen/editing/resolve_titles.py +0 -291
  94. package/src/clipen/rendering/program_creator.py +0 -804
  95. package/src/clipen/rendering/program_identities.py +0 -350
  96. package/src/clipen/rendering/program_motion.py +0 -186
  97. package/src/clipen/rendering/program_studio.py +0 -227
  98. package/src/clipen/rendering/program_styles.py +0 -321
  99. package/src/clipen/skills/builtin/components.json +0 -133
@@ -8,12 +8,10 @@ from dataclasses import dataclass, replace
8
8
  from clipen.domain import TextClip, Track, TrackKind
9
9
  from clipen.projects import ProjectError
10
10
  from clipen.skills import list_skills
11
- from clipen.skills.visual_styles import font_presets, public_font_styles, public_styles, style_presets
12
11
 
13
12
  from .agent_models import ToolResult
14
13
 
15
14
  # The colours a person may change on a graphic: its accent, its light and its dark colour.
16
- COMPONENT_COLORS = frozenset({"accent", "paper", "ink"})
17
15
 
18
16
 
19
17
  @dataclass(frozen=True)
@@ -119,6 +117,7 @@ class SkillTools:
119
117
 
120
118
  def _production_list_program_components(self, args):
121
119
  """How graphics are made now, the looks they share, and the ones already in the film."""
120
+ from clipen.rendering import fetched_fonts
122
121
  from clipen.rendering.custom_components import FONT_CHOICES
123
122
 
124
123
  from . import component_looks
@@ -150,20 +149,24 @@ class SkillTools:
150
149
  "existing_graphics": existing,
151
150
  "looks": component_looks.listing(self),
152
151
  "font_choices": [{"family": family, "label": label} for family, label in FONT_CHOICES.items()],
153
- "older_graphics": "Graphics not designed_freely use retired built-in templates. Keep them, remove them with remove_program_component, "
154
- "or replace them: remove, then design the new one with add_custom_component.",
152
+ "fonts": {
153
+ "carried_and_suggested": "font_choices above",
154
+ "fetched": sorted(fetched_fonts.available()),
155
+ "anything_else": "any font installed on this Mac by name, or any open Google Fonts family after get_font",
156
+ },
157
+ "older_graphics": "Graphics not designed_freely use retired built-in templates; they are no longer drawn and cannot be "
158
+ "changed. Remove them with remove_program_component, and design a new one with add_custom_component where the film needs it.",
155
159
  }
156
160
  )
157
161
 
158
- def _component_draft(self, args):
162
+ def _component_draft(self, args, *, checked=True):
159
163
  """A programme graphic as a person's changes would leave it, checked but not saved.
160
164
 
161
- args holds element_id plus any of text, detail, x, y, scale, colors ({accent, paper, ink}
162
- as #rrggbb), visual_style_id, font_style_id, start_offset_frames and duration_frames;
163
- anything left out keeps its current value.
165
+ args holds element_id plus any of texts, colors, x, y, look_id, start_offset_frames and
166
+ duration_frames; anything left out keeps its current value. frames are more frames of a free design to draw
167
+ in the same Chrome run as its check, for a preview that will want them; checked=False skips
168
+ that Chrome run, for the page that plays the design live in the person's own browser.
164
169
  Returns the changed clip, its style profile and the clip as it is now."""
165
- from clipen.finishing.models import digest
166
-
167
170
  from .production_media import load_text_styles
168
171
 
169
172
  if not isinstance(args, dict) or not isinstance(args.get("element_id"), str):
@@ -188,114 +191,15 @@ class SkillTools:
188
191
  raise ProjectError(
189
192
  "component_not_found", "找不到這個畫面元件,影片可能已經更新,請重新讀取。", status_code=404
190
193
  )
191
- if profile.get("component_id") == "custom":
192
- return self._custom_draft(args, timeline, item, profile)
193
- saved_text, _, saved_detail = item.text.partition("\n")
194
- text, detail = args.get("text", saved_text), args.get("detail", saved_detail)
195
- if not isinstance(text, str) or not isinstance(detail, str):
196
- raise ProjectError("agent_input_invalid", "元件文字格式不正確。", status_code=422)
197
- text, detail = text.strip(), detail.strip()
198
- if not text:
199
- raise ProjectError("component_text_empty", "元件的主要文字不能空白。", status_code=422)
200
- if "\n" in text or "\n" in detail:
194
+ if profile.get("component_id") != "custom":
201
195
  raise ProjectError(
202
- "component_text_overflow", "主要文字與補充文字各寫一行,換行由元件處理。", status_code=422
203
- )
204
- skill = self._skill_value()
205
- component = next((c for c in skill["components"] if c["component_id"] == profile.get("component_id")), None)
206
- limit = component["max_characters"] if component else 48
207
- if len(text) > limit or len(detail) > 48:
208
- raise ProjectError(
209
- "component_text_overflow",
210
- f"這個元件的主要文字最多 {limit} 個字,補充文字最多 48 個字。",
196
+ "component_retired",
197
+ "這個元件用的是已停用的內建模板,不能再修改;刪掉它,或請 AI 重新設計一個。",
211
198
  status_code=422,
212
199
  )
200
+ return self._custom_draft(args, timeline, item, profile, checked)
213
201
 
214
- def number(key, low, high):
215
- value = args.get(key, profile.get(key))
216
- if isinstance(value, bool) or not isinstance(value, (int, float)) or not low <= value <= high:
217
- raise ProjectError("component_unsafe_position", "元件要留在畫面裡。", status_code=422)
218
- return round(float(value), 4)
219
-
220
- x, y = number("x", 0, 0.95), number("y", 0, 0.95)
221
- shot, start, duration = self._component_time(args, item, profile)
222
- visual_style, presets = style_presets(skill, args.get("visual_style_id", profile.get("visual_style_id")))
223
- font_style, presets = font_presets(skill, presets, args.get("font_style_id", profile.get("font_style_id")))
224
- scale = args.get("scale", profile.get("scale", 1))
225
- if isinstance(scale, bool) or not isinstance(scale, (int, float)) or not 0.6 <= scale <= 1.6:
226
- raise ProjectError("component_scale_invalid", "元件大小要在 60% 到 160% 之間。", status_code=422)
227
- colors = args.get("colors", profile.get("colors", {}))
228
- if (
229
- not isinstance(colors, dict)
230
- or not set(colors) <= COMPONENT_COLORS
231
- or not all(
232
- isinstance(v, str) and len(v) == 7 and v[0] == "#" and all(c in "0123456789abcdefABCDEF" for c in v[1:])
233
- for v in colors.values()
234
- )
235
- ):
236
- raise ProjectError("component_color_invalid", "顏色格式不正確。", status_code=422)
237
- # A person's colours replace the style's, keeping each colour's own transparency.
238
- for name, value in colors.items():
239
- presets["palette"][name] = [
240
- int(value[1:3], 16),
241
- int(value[3:5], 16),
242
- int(value[5:7], 16),
243
- presets["palette"][name][3],
244
- ]
245
- changed_profile = {key: value for key, value in profile.items() if key not in {"scale", "colors"}}
246
- changed_profile.update(
247
- {
248
- "presets": presets,
249
- "visual_style_id": visual_style,
250
- "font_style_id": font_style,
251
- "x": x,
252
- "y": y,
253
- "anchor_item_id": shot.item_id,
254
- "start_offset_frames": start,
255
- }
256
- )
257
- # Designed size and the style's colours are left out, so untouched graphics keep their identity.
258
- if round(float(scale), 2) != 1:
259
- changed_profile["scale"] = round(float(scale), 2)
260
- if colors:
261
- changed_profile["colors"] = {name: value.lower() for name, value in sorted(colors.items())}
262
- style_id = "agent.component." + digest(changed_profile)[:24]
263
- draft = replace(
264
- item,
265
- text=text + ("\n" + detail if detail else ""),
266
- start_frame=shot.start_frame + start,
267
- duration_frames=duration,
268
- style_id=style_id,
269
- )
270
- from PIL import Image, ImageDraw
271
-
272
- from clipen.rendering.program_components import draw_program_component
273
- from clipen.rendering.titles import TitleCardRenderer, TitleRenderError
274
-
275
- font = TitleCardRenderer._font_path()
276
- if font is None:
277
- raise ProjectError("preview_title_font_missing", "缺少可用的中文字型。", status_code=409)
278
- try:
279
- draw_program_component(
280
- ImageDraw.Draw(Image.new("RGBA", (timeline.width, timeline.height))),
281
- font,
282
- timeline,
283
- draft,
284
- changed_profile,
285
- 8,
286
- )
287
- except TitleRenderError as error:
288
- message = (
289
- "這套字型無法顯示部分字元,請換個寫法或換字體。"
290
- if error.code == "program_component_missing_glyph"
291
- else "缺少這套字型,請換一套字體。"
292
- if error.code == "program_font_unavailable"
293
- else "元件超出畫面了,請縮小一點、縮短文字或往左上移。"
294
- )
295
- raise ProjectError(error.code, message, status_code=422) from error
296
- return draft, changed_profile, item
297
-
298
- def _custom_draft(self, args, timeline, item, profile):
202
+ def _custom_draft(self, args, timeline, item, profile, checked=True):
299
203
  """A free design as a person's move or retime would leave it: x, y shift the whole page."""
300
204
  from clipen.finishing.models import digest
301
205
  from clipen.rendering import custom_components
@@ -365,20 +269,72 @@ class SkillTools:
365
269
  duration_frames=duration,
366
270
  style_id="agent.component." + digest(changed)[:24],
367
271
  )
272
+ if not checked:
273
+ return draft, changed, item
368
274
  try:
369
275
  custom_components.check(timeline, draft, changed)
370
- if changed.get("look") != profile.get("look"):
371
- custom_components.check_fonts(timeline, draft, changed)
372
276
  except custom_components.CustomRenderError as error:
373
- if error.code == "custom_component_font_outside_look":
374
- raise ProjectError(
375
- error.code,
376
- f"這個元件的設計用了「{changed['look']['name']}」外觀沒有的字型({error.detail}),換不過去;請交給 AI 改。",
377
- status_code=422,
378
- ) from error
379
277
  raise ProjectError(error.code, _custom_problem(error), status_code=422) from error
380
278
  return draft, changed, item
381
279
 
280
+ def _caption_draft(self, args):
281
+ """A caption as a person's correction would leave it: its words, delivery and emphasis."""
282
+ from clipen.finishing.models import digest
283
+
284
+ from .production_media import load_text_styles
285
+
286
+ item = next(
287
+ (
288
+ i
289
+ for t in self._timeline().tracks
290
+ if t.track_id == "agent-subtitles"
291
+ for i in t.items
292
+ if i.item_id == args.get("element_id")
293
+ ),
294
+ None,
295
+ )
296
+ if item is None:
297
+ raise ProjectError("caption_not_found", "找不到這句字幕,影片可能已經更新,請重新讀取。", status_code=404)
298
+ text = args.get("text", item.text)
299
+ if not isinstance(text, str) or not text.strip() or len(text.strip()) > 80 or "\n" in text:
300
+ raise ProjectError("caption_text_invalid", "字幕要是一行、1–80 個字。", status_code=422)
301
+ text = text.strip()
302
+ profile = load_text_styles(self.repository.projects, self.project_id).get(item.style_id, {})
303
+ if profile.get("kind") != "program_subtitle":
304
+ return replace(item, text=text), None
305
+ delivery = args.get("delivery", profile.get("delivery", "dialogue"))
306
+ if delivery not in {"dialogue", "punchline", "quiet"}:
307
+ raise ProjectError("caption_delivery_invalid", "語氣只能是一般對話、重點句或小聲帶過。", status_code=422)
308
+ emphasis = args.get("emphasis", profile.get("emphasis", []))
309
+ if not isinstance(emphasis, list) or not all(isinstance(w, str) for w in emphasis):
310
+ raise ProjectError("caption_emphasis_invalid", "強調的字要是字串清單。", status_code=422)
311
+ emphasis = [w.strip() for w in emphasis if w.strip() and w.strip() in text][:4]
312
+ changed = {**profile, "delivery": delivery, "emphasis": emphasis}
313
+ if text != item.text:
314
+ # A person's own wording: what they heard, taking over from the draft transcript.
315
+ changed.update({"caption_text_edited": True, "wording_authority": "user", "verification": "user_corrected"})
316
+ return replace(item, text=text, style_id="agent.text." + digest(changed)[:24]), changed
317
+
318
+ def _edit_caption(self, args):
319
+ """A person corrects one caption: its words, how it is delivered, which words stand out."""
320
+ from .production_media import atomic_json, load_text_styles, text_style_path
321
+
322
+ draft, profile = self._caption_draft(args)
323
+ current = next(i for t in self._timeline().tracks for i in t.items if i.item_id == draft.item_id)
324
+ if (draft.text, draft.style_id) == (current.text, current.style_id):
325
+ raise ProjectError("caption_unchanged", "沒有任何變動。", status_code=422)
326
+ if profile is not None:
327
+ styles = load_text_styles(self.repository.projects, self.project_id)
328
+ styles[draft.style_id] = profile
329
+ atomic_json(text_style_path(self.repository.projects, self.project_id), styles)
330
+ tracks = tuple(
331
+ replace(t, items=tuple(draft if i.item_id == draft.item_id else i for i in t.items))
332
+ if t.track_id == "agent-subtitles"
333
+ else t
334
+ for t in self._timeline().tracks
335
+ )
336
+ return self._save(replace(self._timeline(), tracks=tracks), args.get("summary") or "使用者修改字幕")
337
+
382
338
  def _edit_component(self, args):
383
339
  """A person changes one programme graphic: wording, place, look, typeface or timing."""
384
340
  from .production_media import atomic_json, load_text_styles, text_style_path
@@ -403,6 +359,29 @@ class SkillTools:
403
359
  atomic_json(text_style_path(self.repository.projects, self.project_id), styles)
404
360
  return self._save(replace(self._timeline(), tracks=tracks), args.get("summary") or "使用者修改元件")
405
361
 
362
+ def _production_get_font(self, args):
363
+ """Fetch an open font from Google Fonts so pages can use it by name."""
364
+ from clipen.rendering import fetched_fonts
365
+
366
+ try:
367
+ entry = fetched_fonts.fetch(args["family"])
368
+ except fetched_fonts.FontUnavailable as error:
369
+ raise ProjectError("font_unavailable", str(error), status_code=422) from error
370
+ return ToolResult(
371
+ {
372
+ "family": entry["family"],
373
+ "license": entry["license"],
374
+ "source": entry["source"],
375
+ "use": f"font-family: '{entry['family']}'",
376
+ "note": "Check that it has every character your text needs; a missing character falls back to another face.",
377
+ }
378
+ )
379
+
380
+ def _production_set_caption_design(self, args):
381
+ from . import caption_design
382
+
383
+ return caption_design.apply(self, args)
384
+
406
385
  def _production_set_component_look(self, args):
407
386
  """The Agent creates or changes a look; graphics already using it follow."""
408
387
  from . import component_looks
@@ -440,7 +419,6 @@ class SkillTools:
440
419
  def _apply_look(self, look, summary):
441
420
  """Save a look and redraw every graphic that uses it; refused if one would then need a typeface the look lacks."""
442
421
  from clipen.finishing.models import digest
443
- from clipen.rendering import custom_components
444
422
 
445
423
  from . import component_looks
446
424
  from .production_media import atomic_json, load_text_styles, text_style_path
@@ -453,27 +431,12 @@ class SkillTools:
453
431
  status_code=422,
454
432
  )
455
433
  timeline = self._timeline()
456
- changed, problems = {}, []
434
+ changed = {}
457
435
  for item, profile in component_looks.on_film(self, timeline):
458
436
  if (profile.get("look") or {}).get("look_id") != look["look_id"] or profile["look"] == look:
459
437
  continue
460
438
  updated = {**profile, "look": look}
461
- draft = replace(item, style_id="agent.component." + digest(updated)[:24])
462
- try:
463
- custom_components.check_fonts(timeline, draft, updated)
464
- except custom_components.CustomRenderError as error:
465
- if error.code != "custom_component_font_outside_look":
466
- raise ProjectError(error.code, _custom_problem(error), status_code=422) from error
467
- problems.append(f"「{item.text}」({error.detail})")
468
- changed[item.item_id] = (draft, updated)
469
- if problems:
470
- raise ProjectError(
471
- "custom_component_font_outside_look",
472
- "改了之後,這些元件會用到外觀以外的字型:"
473
- + "、".join(problems)
474
- + "。保留它們用到的字型 key,或先更新這些元件。",
475
- status_code=422,
476
- )
439
+ changed[item.item_id] = (replace(item, style_id="agent.component." + digest(updated)[:24]), updated)
477
440
  looks[look["look_id"]] = look
478
441
  component_looks.store(self, looks)
479
442
  public = component_looks.public(look, len(changed))
@@ -557,65 +520,44 @@ class SkillTools:
557
520
  )
558
521
 
559
522
  def _component_editing(self):
560
- """What the review page needs to edit graphics: each one's settings and the run's styles."""
523
+ """What the review page needs to edit graphics: each free design's settings and the run's looks.
524
+
525
+ Graphics left from the retired built-in templates are not listed; they are no longer drawn."""
526
+ from clipen.rendering.custom_components import FONT_CHOICES
527
+
528
+ from . import component_looks
561
529
  from .production_media import load_text_styles
562
530
 
563
- skill = self._skill_value()
564
531
  styles = load_text_styles(self.repository.projects, self.project_id)
565
532
  shots = {i.item_id: i for i in self._video().items}
566
- limits = {c["component_id"]: c["max_characters"] for c in skill["components"]}
567
- names = {c["component_id"]: c.get("name", c["component_id"]) for c in skill["components"]}
568
533
  result = {}
569
- for track in self._timeline().tracks:
570
- if not (track.track_id == "program-components" or track.track_id.startswith("program-components-")):
571
- continue
534
+ for track in self._component_tracks():
572
535
  for item in track.items:
573
536
  profile = styles.get(item.style_id, {})
574
537
  shot = shots.get(profile.get("anchor_item_id"))
575
- if profile.get("kind") != "program_component" or shot is None:
538
+ if (
539
+ profile.get("kind") != "program_component"
540
+ or profile.get("component_id") != "custom"
541
+ or shot is None
542
+ ):
576
543
  continue
577
- custom = profile["component_id"] == "custom"
578
544
  result[item.item_id] = {
579
- "component_id": profile["component_id"],
580
- "custom": custom,
581
- "name": item.text if custom else names.get(profile["component_id"], profile["component_id"]),
582
- "max_characters": limits.get(profile["component_id"], 48),
545
+ "name": item.text,
583
546
  "x": profile.get("x"),
584
547
  "y": profile.get("y"),
585
- "visual_style_id": profile.get("visual_style_id"),
586
- "font_style_id": profile.get("font_style_id"),
587
- "scale": profile.get("scale", 1),
588
- "colors": profile.get("colors", {}),
589
- **(
590
- {
591
- "fields": profile.get("fields") or {"texts": [], "colors": []},
592
- "edits": profile.get("edits") or {},
593
- "look_id": (profile.get("look") or {}).get("look_id"),
594
- }
595
- if custom
596
- else {}
597
- ),
548
+ "fields": profile.get("fields") or {"texts": [], "colors": []},
549
+ "edits": profile.get("edits") or {},
550
+ "look_id": (profile.get("look") or {}).get("look_id"),
598
551
  "shot_start_frame": shot.start_frame,
599
552
  "shot_duration_frames": shot.duration_frames,
600
553
  }
554
+ from clipen.rendering import fetched_fonts
601
555
 
602
- def palette(identifier):
603
- colours = style_presets(skill, identifier)[1]["palette"]
604
- return {name: "#%02x%02x%02x" % tuple(colours[name][:3]) for name in sorted(COMPONENT_COLORS)}
605
-
606
- from clipen.rendering.custom_components import FONT_CHOICES
607
-
608
- from . import component_looks
609
-
556
+ fetched = {family: f"{family}(Google Fonts)" for family in fetched_fonts.available()}
610
557
  return {
611
558
  "looks": component_looks.listing(self),
612
- "font_choices": [{"family": f, "label": l} for f, l in FONT_CHOICES.items()],
559
+ "font_choices": [{"family": f, "label": l} for f, l in {**FONT_CHOICES, **fetched}.items()],
613
560
  "components": result,
614
- "visual_styles": [
615
- {"id": v["visual_style_id"], "name": v["name"], "colors": palette(v["visual_style_id"])}
616
- for v in public_styles(skill)
617
- ],
618
- "font_styles": [{"id": f["font_style_id"], "name": f["name"]} for f in public_font_styles(skill)],
619
561
  }
620
562
 
621
563
  def _component_issues(self):
@@ -644,6 +586,16 @@ class SkillTools:
644
586
  if profile.get("kind") != "program_component" or anchor is None:
645
587
  issues.append({"code": "component_anchor_missing", "item_id": element.item_id})
646
588
  continue
589
+ if profile.get("component_id") != "custom":
590
+ issues.append(
591
+ {
592
+ "code": "component_retired",
593
+ "item_id": element.item_id,
594
+ "advisory": True,
595
+ "message": "這個元件用的是已停用的內建模板,不會出現在影片裡;用 remove_program_component 刪掉,需要的話重新設計一個。",
596
+ }
597
+ )
598
+ continue
647
599
  if (
648
600
  not anchor.start_frame <= element.start_frame < anchor.start_frame + anchor.duration_frames
649
601
  or element.start_frame + element.duration_frames > timeline.duration_frames
@@ -660,26 +612,6 @@ class SkillTools:
660
612
  boxes.append((element, box))
661
613
  except TitleRenderError as error:
662
614
  issues.append({"code": error.code, "item_id": element.item_id})
663
- # Subtitles may be rebuilt after a graphic was placed; recheck the pair here.
664
- from .component_review import RESTATE_RATIO, concurrent_subtitles, restated_ratio
665
-
666
- if (
667
- profile.get("authority") != "user"
668
- and profile.get("component_id") != "custom"
669
- and restated_ratio(
670
- element.text.partition("\n")[0],
671
- concurrent_subtitles(timeline, element.start_frame, element.duration_frames),
672
- )
673
- >= RESTATE_RATIO
674
- ):
675
- issues.append(
676
- {
677
- "code": "component_restates_subtitle",
678
- "item_id": element.item_id,
679
- "advisory": True,
680
- "message": "元件文字和同時出現的字幕大部分重複;不是刻意強調的話可以改寫。",
681
- }
682
- )
683
615
  for n, (a, left) in enumerate(boxes):
684
616
  for b, right in boxes[n + 1 :]:
685
617
  if (
@@ -771,21 +703,17 @@ class SkillTools:
771
703
  }
772
704
  from . import component_looks
773
705
 
706
+ # A look is optional: graphics of one kind may share one, or a page may set its own type and colour.
774
707
  look_id = args.get("look_id") or (previous.get("look") or {}).get("look_id")
775
- if not look_id:
776
- raise ProjectError(
777
- "component_look_required",
778
- "先用 set_component_look 定下這類元件的外觀(字型與配色),再用 look_id 指定。",
779
- status_code=422,
780
- )
781
- look = component_looks.current(self).get(look_id)
782
- if look is None:
783
- raise ProjectError(
784
- "component_look_not_found",
785
- "沒有這個外觀;先用 set_component_look 建立,或從 list_program_components 的 looks 選一個。",
786
- status_code=422,
787
- )
788
- profile["look"] = look
708
+ if look_id:
709
+ look = component_looks.current(self).get(look_id)
710
+ if look is None:
711
+ raise ProjectError(
712
+ "component_look_not_found",
713
+ "沒有這個外觀;先用 set_component_look 建立,或從 list_program_components 的 looks 選一個。",
714
+ status_code=422,
715
+ )
716
+ profile["look"] = look
789
717
  item = TextClip(
790
718
  args["element_id"],
791
719
  shot.start_frame + settings["start_offset_frames"],
@@ -812,7 +740,6 @@ class SkillTools:
812
740
  profile["edits"] = {kind: values for kind, values in keep.items() if values}
813
741
  item = replace(item, style_id="agent.component." + digest(profile)[:24])
814
742
  custom_components.check(timeline, item, profile)
815
- custom_components.check_fonts(timeline, item, profile)
816
743
  except custom_components.CustomRenderError as error:
817
744
  raise ProjectError(error.code, _custom_problem(error), status_code=422) from error
818
745
  styles[item.style_id] = profile
@@ -939,9 +866,6 @@ def _custom_problem(error):
939
866
  "custom_component_script_error": "頁面的程式出錯" + detail + "。",
940
867
  "custom_component_frame_timeout": "有一格超過 10 秒還沒畫完;clipenFrame 要能直接畫出指定的那一格。",
941
868
  "custom_component_renderer_missing": "這台電腦沒有可用的 Chrome,無法繪製自由元件" + detail + "。",
942
- "custom_component_font_outside_look": "頁面用了外觀以外的字型"
943
- + detail
944
- + ";文字的字型要寫成 var(--look-font-鍵名)。想換字或加一套字,先用 set_component_look 改外觀。",
945
869
  }.get(error.code, "自由元件繪製失敗" + detail + "。")
946
870
 
947
871
 
@@ -35,9 +35,10 @@ TIMELINE_MUTATIONS = frozenset(
35
35
  "remove_program_component",
36
36
  "add_custom_component",
37
37
  "update_custom_component",
38
- "set_component_text",
39
38
  "edit_component",
39
+ "edit_caption",
40
40
  "set_component_look",
41
+ "set_caption_design",
41
42
  "edit_component_look",
42
43
  }
43
44
  )
@@ -9,6 +9,7 @@ Projects from before review notes may also hold manual edits, still labelled bel
9
9
  import json
10
10
  import sqlite3
11
11
 
12
+ from clipen.i18n import english, tr
12
13
  from clipen.provider_registry import get_provider
13
14
 
14
15
  _STOPS = {"provider_failed", "run_cancelled", "run_interrupted", "budget_exhausted"}
@@ -20,6 +21,14 @@ _STOP_REASONS = {
20
21
  "delivery_blocked": "交付檢查未通過",
21
22
  "provider_network_error": "連線中斷時停下",
22
23
  }
24
+ _STOP_REASONS_EN = {
25
+ "provider_usage_limit": "stopped at a usage limit",
26
+ "provider_timed_out": "stopped at the time limit",
27
+ "provider_authentication_required": "stopped when the sign-in expired",
28
+ "provider_stopped_early": "the AI stopped early",
29
+ "delivery_blocked": "delivery checks not passed",
30
+ "provider_network_error": "stopped when the connection dropped",
31
+ }
23
32
  # Labels for manual edits: rewording a graphic now, and the edits earlier Clipen versions allowed.
24
33
  _MANUAL = {
25
34
  "edit_text": "文字與時間",
@@ -43,9 +52,36 @@ _MANUAL = {
43
52
  "update_custom_component": "修改自由設計元件",
44
53
  "set_component_text": "元件文字",
45
54
  "edit_component": "修改元件",
55
+ "edit_caption": "修改字幕",
46
56
  "edit_component_look": "元件外觀",
47
57
  }
48
58
 
59
+ _MANUAL_EN = {
60
+ "edit_text": "text and timing",
61
+ "configure_text_style": "text look",
62
+ "remove_item": "removed an element",
63
+ "trim_clip": "trimmed a clip",
64
+ "reorder_clips": "reordered clips",
65
+ "split_clip": "split a clip",
66
+ "replace_clip_source": "replaced a source",
67
+ "insert_clip": "inserted a clip",
68
+ "set_source_audio": "original sound",
69
+ "set_color_grade": "colour",
70
+ "set_mosaic": "mosaic",
71
+ "set_transition": "transition",
72
+ "set_fade": "fade",
73
+ "remove_clip_effect": "removed an effect",
74
+ "place_audio": "music and effects",
75
+ "remove_audio": "removed sound",
76
+ "remove_program_component": "removed a graphic",
77
+ "add_custom_component": "added a custom graphic",
78
+ "update_custom_component": "changed a custom graphic",
79
+ "set_component_text": "graphic text",
80
+ "edit_component": "edited a graphic",
81
+ "edit_caption": "edited a caption",
82
+ "edit_component_look": "graphic look",
83
+ }
84
+
49
85
 
50
86
  def _name(provider_id):
51
87
  try:
@@ -113,7 +149,10 @@ def versions(database, run_id, provider, styles=None, current=None):
113
149
  elif kind == "provider_switched":
114
150
  current_ai = payload.get("to", current_ai)
115
151
  elif kind == "run_finished":
116
- label = f"{_name(current_ai)} {'打磨' if request else '製作'}完成"
152
+ label = tr(
153
+ f"{_name(current_ai)} {'打磨' if request else '製作'}完成",
154
+ f"{_name(current_ai)} {'revision' if request else 'first cut'} finished",
155
+ )
117
156
  add("ai_complete", label, row["created_at"], request)
118
157
  if result and result[-1]["revision_id"] == latest:
119
158
  # A stopped request that was continued and then finished without further changes ends
@@ -125,14 +164,22 @@ def versions(database, run_id, provider, styles=None, current=None):
125
164
  elif kind in _STOPS:
126
165
  # A stop that changed nothing is not a version.
127
166
  if latest != start:
128
- reason = _STOP_REASONS.get(payload.get("error_code"), "製作中斷")
129
- add("ai_partial", f"{_name(current_ai)} 未完成({reason})", row["created_at"], request)
167
+ reasons = _STOP_REASONS_EN if english() else _STOP_REASONS
168
+ reason = reasons.get(payload.get("error_code"), tr("製作中斷", "interrupted"))
169
+ add(
170
+ "ai_partial",
171
+ tr(f"{_name(current_ai)} 未完成({reason})", f"{_name(current_ai)} unfinished ({reason})"),
172
+ row["created_at"],
173
+ request,
174
+ )
130
175
  start = latest
131
176
  elif kind == "tool_completed" and payload.get("authority") == "user":
132
177
  tool = payload.get("tool")
133
178
  add(
134
179
  "restore" if tool == "restore_revision" else "manual",
135
- "還原版本" if tool == "restore_revision" else f"手動修改:{_MANUAL.get(tool, '編輯')}",
180
+ tr("還原版本", "Restored a version")
181
+ if tool == "restore_revision"
182
+ else tr(f"手動修改:{_MANUAL.get(tool, '編輯')}", f"Your edit: {_MANUAL_EN.get(tool, 'edit')}"),
136
183
  row["created_at"],
137
184
  )
138
185
  start = latest
@@ -148,29 +195,27 @@ def versions(database, run_id, provider, styles=None, current=None):
148
195
 
149
196
  def _report(payload, sent):
150
197
  """What the AI said it changed, with each answer placed next to the note it answers."""
151
- from .change_report import OUTCOMES
198
+ from .change_report import outcome_label, reason_label
152
199
 
153
200
  report = payload.get("report") or {}
154
201
  notes = [
155
202
  {
156
203
  **note,
157
- "outcome_label": OUTCOMES.get(note.get("outcome"), ""),
204
+ "outcome_label": outcome_label(note.get("outcome")),
158
205
  "kind": (sent.get(note.get("reference_id")) or {}).get("kind"),
159
206
  "note": (sent.get(note.get("reference_id")) or {}).get("note", ""),
160
207
  }
161
208
  for note in report.get("notes", [])
162
209
  ]
163
- from .change_report import REASONS
164
-
165
210
  # Reports written before reasons were required hold plain lines.
166
211
  left = [
167
212
  {"what": item, "reason": None, "reason_label": "", "detail": ""}
168
213
  if isinstance(item, str)
169
- else {**item, "reason_label": REASONS.get(item.get("reason"), "")}
214
+ else {**item, "reason_label": reason_label(item.get("reason"))}
170
215
  for item in report.get("not_done", [])
171
216
  ]
172
217
  for note in notes:
173
- note["reason_label"] = REASONS.get(note.get("reason"), "")
218
+ note["reason_label"] = reason_label(note.get("reason"))
174
219
  return {
175
220
  "summary": payload.get("summary") or "",
176
221
  "changes": report.get("changes", []),