@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,12 +3,10 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import asyncio
6
- from dataclasses import dataclass
7
6
  import errno
8
7
  import http.client
9
8
  import json
10
9
  import os
11
- from pathlib import Path
12
10
  import secrets
13
11
  import signal
14
12
  import socket
@@ -16,8 +14,10 @@ import stat
16
14
  import sys
17
15
  import threading
18
16
  import time
19
- from typing import Callable
20
17
  import webbrowser
18
+ from dataclasses import dataclass
19
+ from pathlib import Path
20
+ from typing import Callable
21
21
 
22
22
  try:
23
23
  import fcntl as _fcntl
@@ -27,19 +27,19 @@ except ImportError: # Windows does not provide POSIX advisory file locks.
27
27
  import uvicorn
28
28
 
29
29
  from clipen.analysis import (
30
- ASRSetupManager,
31
30
  ArtifactStore,
31
+ ASRSetupManager,
32
32
  ManagedAnalysisRuntime,
33
33
  PreparationRepository,
34
34
  )
35
- from clipen.media import InventoryCoordinator, InventoryRepository, MediaPreviewRepository
36
- from clipen.editing import EditAgentCoordinator, EditAgentRepository
37
- from clipen.providers import CodexExecAdapter, ProviderUnavailable
38
- from clipen.providers.claude import ClaudeCliAdapter
39
- from clipen.provider_registry import exec_adapter_factory
40
35
  from clipen.analysis.evidence_service import EvidenceService
41
36
  from clipen.annotations import AnnotationRepository
37
+ from clipen.editing import EditAgentCoordinator, EditAgentRepository
38
+ from clipen.media import InventoryCoordinator, InventoryRepository, MediaPreviewRepository
42
39
  from clipen.projects import ProjectWorkspace
40
+ from clipen.provider_registry import exec_adapter_factory
41
+ from clipen.providers import CodexExecAdapter, ProviderUnavailable
42
+ from clipen.providers.claude import ClaudeCliAdapter
43
43
 
44
44
  from .app import (
45
45
  ControllerConfig,
@@ -49,7 +49,6 @@ from .app import (
49
49
  create_app,
50
50
  )
51
51
 
52
-
53
52
  HOST = "127.0.0.1"
54
53
  PRIMARY_PORT = 4200
55
54
  _INSTANCE_SCHEMA = 1
@@ -73,9 +72,7 @@ class _InstanceLease:
73
72
  @classmethod
74
73
  def acquire(cls, root: Path) -> "_InstanceLease | None":
75
74
  if _fcntl is None:
76
- raise RuntimeError(
77
- "這個開發版本尚不支援 Windows;本機工作台需要 POSIX 檔案鎖"
78
- )
75
+ raise RuntimeError("這個開發版本尚不支援 Windows;本機工作台需要 POSIX 檔案鎖")
79
76
  lock_path = root / ".controller.lock"
80
77
  flags = os.O_RDWR | os.O_CREAT | getattr(os, "O_NOFOLLOW", 0)
81
78
  descriptor = os.open(lock_path, flags, 0o600)
@@ -97,9 +94,7 @@ class _InstanceLease:
97
94
  sort_keys=True,
98
95
  separators=(",", ":"),
99
96
  ).encode("utf-8")
100
- temporary = self.registry_path.with_name(
101
- f".{self.registry_path.name}.tmp-{os.getpid()}-{secrets.token_hex(4)}"
102
- )
97
+ temporary = self.registry_path.with_name(f".{self.registry_path.name}.tmp-{os.getpid()}-{secrets.token_hex(4)}")
103
98
  flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, "O_NOFOLLOW", 0)
104
99
  descriptor = os.open(temporary, flags, 0o600)
105
100
  try:
@@ -155,20 +150,20 @@ class ServerPaths:
155
150
  if self.instance_root.is_symlink() or not self.instance_root.is_dir():
156
151
  raise ValueError("instance root cannot be a symbolic link")
157
152
  self.instance_root.chmod(0o700)
158
- if self.asr_requirements is not None and not self.asr_requirements.resolve(
159
- strict=True
160
- ).is_file():
153
+ if self.asr_requirements is not None and not self.asr_requirements.resolve(strict=True).is_file():
161
154
  raise ValueError("ASR runtime requirements are missing")
162
155
 
163
156
 
164
- def provider_account(provider_id: str, attempt_root: Path, ttl: float = 60.) -> Callable[[], dict]:
157
+ def provider_account(provider_id: str, attempt_root: Path, ttl: float = 60.0) -> Callable[[], dict]:
165
158
  """A cached, read-only lookup of the running model and remaining quota."""
166
159
  from clipen.providers.account import claude_account, codex_account
160
+
167
161
  lock, cache = threading.Lock(), {}
168
162
 
169
163
  def lookup() -> dict:
170
164
  if provider_id == "claude":
171
165
  from clipen.providers.claude import claude_environment
166
+
172
167
  return claude_account(attempt_root, claude_environment())
173
168
  if provider_id != "codex":
174
169
  return {"model": None, "quota": None}
@@ -203,9 +198,7 @@ def probe_codex(attempt_root: Path) -> ProviderStatus:
203
198
  if not result.capabilities.supports_bounded_attempts:
204
199
  return ProviderStatus("Codex", ProviderState.UNSUPPORTED, "Codex 版本需要更新")
205
200
  if not result.confinement_verified:
206
- return ProviderStatus(
207
- "Codex", ProviderState.CONFINEMENT_FAILED, "Codex 安全檢查未通過"
208
- )
201
+ return ProviderStatus("Codex", ProviderState.CONFINEMENT_FAILED, "Codex 安全檢查未通過")
209
202
  return ProviderStatus("Codex", ProviderState.READY, "AI 已連接,可以開始使用")
210
203
 
211
204
 
@@ -248,11 +241,7 @@ def _read_instance_record(path: Path) -> tuple[int, str] | None:
248
241
  try:
249
242
  descriptor = os.open(path, os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0))
250
243
  info = os.fstat(descriptor)
251
- if (
252
- not stat.S_ISREG(info.st_mode)
253
- or info.st_size > 4096
254
- or info.st_mode & 0o077
255
- ):
244
+ if not stat.S_ISREG(info.st_mode) or info.st_size > 4096 or info.st_mode & 0o077:
256
245
  return None
257
246
  raw = os.read(descriptor, 4097)
258
247
  if len(raw) > 4096:
@@ -365,11 +354,7 @@ async def _serve(
365
354
  edit_agents = None
366
355
  try:
367
356
  lease.publish(port)
368
- workspace = (
369
- ProjectWorkspace(paths.projects_root)
370
- if paths.projects_root is not None
371
- else None
372
- )
357
+ workspace = ProjectWorkspace(paths.projects_root) if paths.projects_root is not None else None
373
358
  if workspace is not None:
374
359
  annotations = AnnotationRepository(workspace.repository)
375
360
  media_previews = MediaPreviewRepository(workspace.repository)
@@ -381,7 +366,9 @@ async def _serve(
381
366
  edit_agent_repository,
382
367
  paths.attempt_root,
383
368
  provider_id=provider.provider_id,
384
- local_runtime=(paths.attempt_root.parent, paths.asr_requirements) if paths.asr_requirements else None,
369
+ local_runtime=(paths.attempt_root.parent, paths.asr_requirements)
370
+ if paths.asr_requirements
371
+ else None,
385
372
  )
386
373
  edit_agents.recover()
387
374
  else:
@@ -389,11 +376,12 @@ async def _serve(
389
376
  edit_agent_repository.interrupt_incomplete(project.project_id)
390
377
  repository = InventoryRepository(workspace.repository)
391
378
  inventories = InventoryCoordinator(repository)
392
- inventories.recover_incomplete(
393
- project.project_id for project in workspace.repository.list_projects()
379
+ inventories.recover_incomplete(project.project_id for project in workspace.repository.list_projects())
380
+ evidence_service = EvidenceService(
381
+ workspace.repository,
382
+ paths.attempt_root if provider.state is ProviderState.READY else None,
383
+ adapter_factory=exec_adapter,
394
384
  )
395
- evidence_service = EvidenceService(workspace.repository, paths.attempt_root if provider.state is ProviderState.READY else None,
396
- adapter_factory=exec_adapter)
397
385
  evidence_service.recover()
398
386
  preparation_repository = PreparationRepository(workspace.repository)
399
387
  for project in workspace.repository.list_projects():
@@ -437,6 +425,7 @@ async def _serve(
437
425
  lifespan="off",
438
426
  )
439
427
  server = uvicorn.Server(config)
428
+
440
429
  async def announce_when_started() -> None:
441
430
  while not server.started and not server.should_exit:
442
431
  await asyncio.sleep(0.02)
@@ -503,6 +492,7 @@ def run_server(
503
492
  ) -> int:
504
493
  paths.prepare()
505
494
  from clipen.skills import configure_library
495
+
506
496
  # Custom skills live beside other Clipen data and are shared by all workspaces.
507
497
  configure_library(paths.attempt_root.parent / "skills")
508
498
  instance_root = paths.instance_root or paths.attempt_root.parent
@@ -1,5 +1,6 @@
1
1
  """Pure product-domain types without transport or provider dependencies."""
2
2
 
3
+ from .errors import InvalidTransition
3
4
  from .media_time import Rational, SourceSpan
4
5
  from .timeline import (
5
6
  ClipSource,
@@ -12,7 +13,6 @@ from .timeline import (
12
13
  Track,
13
14
  TrackKind,
14
15
  )
15
- from .errors import InvalidTransition
16
16
 
17
17
  __all__ = [
18
18
  "InvalidTransition",
@@ -2,11 +2,10 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from dataclasses import dataclass
6
5
  import re
6
+ from dataclasses import dataclass
7
7
  from typing import Any, Mapping
8
8
 
9
-
10
9
  _DECIMAL_INTEGER = re.compile(r"-?(?:0|[1-9][0-9]*)\Z")
11
10
  _VERSION_ID = re.compile(r"av_[0-9a-f]{32}\Z")
12
11
  _MAX_TIME_BASE_COMPONENT = 1_000_000_000
@@ -37,10 +36,7 @@ class Rational:
37
36
  for value in (self.numerator, self.denominator)
38
37
  ):
39
38
  raise ValueError("time base must contain positive integers")
40
- if (
41
- self.numerator > _MAX_TIME_BASE_COMPONENT
42
- or self.denominator > _MAX_TIME_BASE_COMPONENT
43
- ):
39
+ if self.numerator > _MAX_TIME_BASE_COMPONENT or self.denominator > _MAX_TIME_BASE_COMPONENT:
44
40
  raise ValueError("time base is outside supported bounds")
45
41
 
46
42
  def to_storage(self) -> dict[str, int]:
@@ -64,10 +60,7 @@ class SourceSpan:
64
60
  time_base: Rational
65
61
 
66
62
  def __post_init__(self) -> None:
67
- if (
68
- not isinstance(self.version_id, str)
69
- or _VERSION_ID.fullmatch(self.version_id) is None
70
- ):
63
+ if not isinstance(self.version_id, str) or _VERSION_ID.fullmatch(self.version_id) is None:
71
64
  raise ValueError("source span version is invalid")
72
65
  if (
73
66
  isinstance(self.stream_index, bool)
@@ -2,18 +2,17 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from dataclasses import dataclass
6
- from enum import Enum
7
- from fractions import Fraction
8
5
  import json
9
6
  import math
10
7
  import re
8
+ from dataclasses import dataclass
9
+ from enum import Enum
10
+ from fractions import Fraction
11
11
  from typing import Mapping, TypeAlias
12
12
 
13
13
  from .media_time import Rational, SourceSpan
14
14
  from .validation import require_identifier
15
15
 
16
-
17
16
  _EFFECT_ID = re.compile(r"[a-z][a-z0-9_.-]{0,127}\Z")
18
17
  _SHA256 = re.compile(r"[0-9a-f]{64}\Z")
19
18
  _MAX_FRAME = 2**63 - 1
@@ -25,20 +24,12 @@ _MAX_EFFECTS_PER_CLIP = 128
25
24
 
26
25
 
27
26
  def _positive_integer(value: int, field: str, maximum: int = _MAX_FRAME) -> None:
28
- if (
29
- isinstance(value, bool)
30
- or not isinstance(value, int)
31
- or not 1 <= value <= maximum
32
- ):
27
+ if isinstance(value, bool) or not isinstance(value, int) or not 1 <= value <= maximum:
33
28
  raise ValueError(f"{field} must be a positive integer")
34
29
 
35
30
 
36
31
  def _non_negative_integer(value: int, field: str, maximum: int = _MAX_FRAME) -> None:
37
- if (
38
- isinstance(value, bool)
39
- or not isinstance(value, int)
40
- or not 0 <= value <= maximum
41
- ):
32
+ if isinstance(value, bool) or not isinstance(value, int) or not 0 <= value <= maximum:
42
33
  raise ValueError(f"{field} must be a non-negative integer")
43
34
 
44
35
 
@@ -193,12 +184,7 @@ class TextClip:
193
184
 
194
185
  def __post_init__(self) -> None:
195
186
  _validate_item(self.item_id, self.start_frame, self.duration_frames)
196
- if (
197
- not isinstance(self.text, str)
198
- or not self.text.strip()
199
- or "\x00" in self.text
200
- or len(self.text) > 4_000
201
- ):
187
+ if not isinstance(self.text, str) or not self.text.strip() or "\x00" in self.text or len(self.text) > 4_000:
202
188
  raise ValueError("text clip content is invalid")
203
189
  require_identifier(self.style_id, "style_id")
204
190
 
@@ -367,15 +353,11 @@ class EditTimeline:
367
353
  if isinstance(item, MediaClip):
368
354
  source = item.source.span
369
355
  source_frames = Fraction(
370
- source.duration_pts
371
- * source.time_base.numerator
372
- * self.frame_rate.numerator,
356
+ source.duration_pts * source.time_base.numerator * self.frame_rate.numerator,
373
357
  source.time_base.denominator * self.frame_rate.denominator,
374
358
  )
375
359
  if abs(source_frames - item.duration_frames) > 1:
376
- raise ValueError(
377
- "media source duration does not match timeline duration"
378
- )
360
+ raise ValueError("media source duration does not match timeline duration")
379
361
  if any(marker.frame > self.duration_frames for marker in self.markers):
380
362
  raise ValueError("timeline marker exceeds timeline duration")
381
363
  object.__setattr__(
@@ -398,11 +380,15 @@ class EditTimeline:
398
380
  "schema_version": 2 if self.production_session_id is not None else 1,
399
381
  "timeline_id": self.timeline_id,
400
382
  "project_id": self.project_id,
401
- **({"production_session_id": self.production_session_id} if self.production_session_id is not None else {
402
- "plan_id": self.plan_id,
403
- "plan_revision": self.plan_revision,
404
- "plan_content_hash": self.plan_content_hash,
405
- }),
383
+ **(
384
+ {"production_session_id": self.production_session_id}
385
+ if self.production_session_id is not None
386
+ else {
387
+ "plan_id": self.plan_id,
388
+ "plan_revision": self.plan_revision,
389
+ "plan_content_hash": self.plan_content_hash,
390
+ }
391
+ ),
406
392
  "frame_rate": self.frame_rate.to_storage(),
407
393
  "canvas": {"width": self.width, "height": self.height},
408
394
  "duration_frames": self.duration_frames,
@@ -425,9 +411,15 @@ class EditTimeline:
425
411
  "markers",
426
412
  }
427
413
  if not isinstance(value, dict) or not (
428
- (value.get("schema_version") == 1 and set(value) == common | {"plan_id", "plan_revision", "plan_content_hash"})
429
- or (value.get("schema_version") == 2 and set(value) == common | {"production_session_id"}
430
- and isinstance(value.get("production_session_id"), str))
414
+ (
415
+ value.get("schema_version") == 1
416
+ and set(value) == common | {"plan_id", "plan_revision", "plan_content_hash"}
417
+ )
418
+ or (
419
+ value.get("schema_version") == 2
420
+ and set(value) == common | {"production_session_id"}
421
+ and isinstance(value.get("production_session_id"), str)
422
+ )
431
423
  ):
432
424
  raise ValueError("stored timeline is invalid")
433
425
  canvas = value["canvas"]
@@ -442,11 +434,16 @@ class EditTimeline:
442
434
  raise ValueError("stored timeline collections are invalid")
443
435
  parsed_tracks: list[Track] = []
444
436
  for raw_track in tracks:
445
- if not isinstance(raw_track, dict) or set(raw_track) != {
446
- "track_id",
447
- "kind",
448
- "items",
449
- } or not isinstance(raw_track["items"], list):
437
+ if (
438
+ not isinstance(raw_track, dict)
439
+ or set(raw_track)
440
+ != {
441
+ "track_id",
442
+ "kind",
443
+ "items",
444
+ }
445
+ or not isinstance(raw_track["items"], list)
446
+ ):
450
447
  raise ValueError("stored timeline track is invalid")
451
448
  kind = TrackKind(raw_track["kind"])
452
449
  parsed_items: list[TimelineItem] = []
@@ -484,7 +481,9 @@ class EditTimeline:
484
481
  parsed_effects = []
485
482
  for effect in effects:
486
483
  if not isinstance(effect, dict) or set(effect) != {
487
- "effect_id", "version", "parameters",
484
+ "effect_id",
485
+ "version",
486
+ "parameters",
488
487
  }:
489
488
  raise ValueError("stored effect is invalid")
490
489
  parsed_effects.append(
@@ -501,12 +500,8 @@ class EditTimeline:
501
500
  raw_item["duration_frames"],
502
501
  ClipSource(
503
502
  SourceSpan.from_storage(span_payload),
504
- _stored_non_negative_integer(
505
- source["handle_before_pts"], "handle_before_pts"
506
- ),
507
- _stored_non_negative_integer(
508
- source["handle_after_pts"], "handle_after_pts"
509
- ),
503
+ _stored_non_negative_integer(source["handle_before_pts"], "handle_before_pts"),
504
+ _stored_non_negative_integer(source["handle_after_pts"], "handle_after_pts"),
510
505
  ),
511
506
  tuple(parsed_effects),
512
507
  )
@@ -549,7 +544,10 @@ class EditTimeline:
549
544
  parsed_markers = []
550
545
  for marker in markers:
551
546
  if not isinstance(marker, dict) or set(marker) != {
552
- "marker_id", "frame", "label", "note",
547
+ "marker_id",
548
+ "frame",
549
+ "label",
550
+ "note",
553
551
  }:
554
552
  raise ValueError("stored timeline marker is invalid")
555
553
  parsed_markers.append(
@@ -4,7 +4,6 @@ from __future__ import annotations
4
4
 
5
5
  import re
6
6
 
7
-
8
7
  _IDENTIFIER = re.compile(r"[A-Za-z0-9][A-Za-z0-9._:-]{0,127}\Z")
9
8
 
10
9
 
@@ -1,7 +1,7 @@
1
1
  """Compilation and persistence for executable Clipen edit timelines."""
2
2
 
3
- from .compiler import OutputSettings
4
3
  from .agent import AgentRevision, AgentRun, EditAgentRepository, EditAgentTools, ToolResult
4
+ from .compiler import OutputSettings
5
5
  from .coordinator import EditAgentCoordinator
6
6
 
7
7
  __all__ = [
@@ -2,17 +2,16 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from dataclasses import dataclass
6
5
  import hashlib
7
6
  import json
8
- from pathlib import Path
9
7
  import re
8
+ from dataclasses import dataclass
9
+ from pathlib import Path
10
10
  from typing import Mapping
11
11
 
12
12
  from clipen.domain import EditTimeline
13
13
  from clipen.projects import ProjectError
14
14
 
15
-
16
15
  RUN_ID_PATTERN = re.compile(r"editrun_[0-9a-f]{32}\Z")
17
16
  REVISION_ID_PATTERN = re.compile(r"editrev_[0-9a-f]{32}\Z")
18
17
  ALLOWED_EFFECTS = frozenset(
@@ -38,12 +37,7 @@ def bounded_text(
38
37
  *,
39
38
  empty: bool = False,
40
39
  ) -> str:
41
- if (
42
- not isinstance(value, str)
43
- or "\x00" in value
44
- or len(value) > maximum
45
- or (not empty and not value.strip())
46
- ):
40
+ if not isinstance(value, str) or "\x00" in value or len(value) > maximum or (not empty and not value.strip()):
47
41
  raise ProjectError("agent_input_invalid", f"{label}內容無效。", status_code=422)
48
42
  return value.strip()
49
43
 
@@ -78,8 +72,7 @@ class AgentRun:
78
72
  if self.usage is not None:
79
73
  usage = {
80
74
  **self.usage,
81
- "total_tokens": self.usage["input_tokens"]
82
- + self.usage["output_tokens"],
75
+ "total_tokens": self.usage["input_tokens"] + self.usage["output_tokens"],
83
76
  }
84
77
  return {
85
78
  "run_id": self.run_id,