@clipen/clipen-cli 1.0.9 → 1.0.10
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.
- package/README.md +52 -43
- package/README.zh-TW.md +98 -0
- package/apps/web/dist/assets/index-BHFCflzf.js +15 -0
- package/apps/web/dist/assets/index-BtenOBwP.css +1 -0
- package/apps/web/dist/favicon.svg +1 -1
- package/apps/web/dist/index.html +2 -2
- package/bin/clipen.js +4 -2
- package/package.json +2 -2
- package/pyproject.toml +1 -1
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/annotations/suggestions.py +1 -1
- package/src/clipen/bootstrap.py +70 -15
- package/src/clipen/controller/app.py +102 -1
- package/src/clipen/controller/server.py +14 -6
- package/src/clipen/editing/agent_repository.py +29 -3
- package/src/clipen/editing/agent_tools.py +1 -0
- package/src/clipen/editing/aspect.py +27 -0
- package/src/clipen/editing/production_catalog.py +10 -3
- package/src/clipen/editing/production_media.py +1 -1
- package/src/clipen/editing/production_preview.py +7 -0
- package/src/clipen/editing/production_tools.py +7 -2
- package/src/clipen/editing/skill_tools.py +8 -0
- package/src/clipen/editing/slip.py +109 -0
- package/src/clipen/editing/tool_receipts.py +1 -0
- package/src/clipen/editing/versions.py +2 -0
- package/src/clipen/editing/visual_preview.py +11 -3
- package/src/clipen/editing/workbench.py +33 -1
- package/src/clipen/locale_en.py +18 -0
- package/src/clipen/mcp_editing/server.py +3 -1
- package/src/clipen/media/discovery.py +2 -2
- package/src/clipen/media/preview.py +5 -0
- package/src/clipen/media/storage.py +5 -2
- package/src/clipen/projects/models.py +2 -0
- package/src/clipen/projects/storage.py +84 -4
- package/src/clipen/providers/account.py +37 -6
- package/src/clipen/providers/claude.py +5 -3
- package/src/clipen/providers/claude_editing.py +5 -6
- package/src/clipen/providers/codex.py +19 -7
- package/src/clipen/providers/codex_editing.py +2 -1
- package/src/clipen/providers/editing_agent.py +24 -2
- package/src/clipen/providers/model_selection.py +67 -0
- package/src/clipen/rendering/cover.py +1 -1
- package/src/clipen/rendering/program_subtitles.py +3 -1
- package/src/clipen/rendering/renderer.py +13 -3
- package/src/clipen/skills/builtin/references/graphics.md +1 -1
- package/src/clipen/skills/builtin/templates.json +9 -0
- package/apps/web/dist/assets/index-DPgSvXZ1.js +0 -15
- package/apps/web/dist/assets/index-DmPWV61v.css +0 -1
- package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +0 -38
- package/src/clipen/editing/REFACTOR_DESIGN.md +0 -241
- package/src/clipen/editing/REFACTOR_HANDOFF.md +0 -73
|
@@ -12,7 +12,14 @@ from .refinement_references import public_state, sent
|
|
|
12
12
|
|
|
13
13
|
# Changes go through review notes to the AI; the user picks which version is current and edits graphics directly.
|
|
14
14
|
USER_TOOLS = frozenset(
|
|
15
|
-
{
|
|
15
|
+
{
|
|
16
|
+
"restore_revision",
|
|
17
|
+
"edit_component",
|
|
18
|
+
"edit_component_look",
|
|
19
|
+
"remove_program_component",
|
|
20
|
+
"edit_caption",
|
|
21
|
+
"slip_clip",
|
|
22
|
+
}
|
|
16
23
|
)
|
|
17
24
|
|
|
18
25
|
|
|
@@ -35,6 +42,30 @@ def _captions(repository, project_id, timeline):
|
|
|
35
42
|
return result
|
|
36
43
|
|
|
37
44
|
|
|
45
|
+
def _shots(repository, project_id, run_id, timeline):
|
|
46
|
+
"""How far each shot can slip in its footage, in frames earlier and later."""
|
|
47
|
+
from clipen.domain import TrackKind
|
|
48
|
+
|
|
49
|
+
from .slip import room
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
tools = tools_for(repository, project_id, run_id)
|
|
53
|
+
video = next(t for t in timeline.tracks if t.kind is TrackKind.VIDEO)
|
|
54
|
+
except (ProjectError, StopIteration):
|
|
55
|
+
return {}
|
|
56
|
+
result = {}
|
|
57
|
+
for item in video.items:
|
|
58
|
+
earlier, later = room(tools, item)
|
|
59
|
+
span = item.source.span
|
|
60
|
+
unit = span.time_base.numerator / span.time_base.denominator
|
|
61
|
+
result[item.item_id] = {
|
|
62
|
+
"earlier": earlier,
|
|
63
|
+
"later": later,
|
|
64
|
+
"source_start_seconds": round(int(span.start_pts) * unit, 3),
|
|
65
|
+
}
|
|
66
|
+
return result
|
|
67
|
+
|
|
68
|
+
|
|
38
69
|
def idle(repository, project_id, run_id):
|
|
39
70
|
run = repository.get(project_id, run_id)
|
|
40
71
|
latest = repository.latest(project_id)
|
|
@@ -92,6 +123,7 @@ def state(repository, project_id, run_id):
|
|
|
92
123
|
"revision": revision.to_public(include_timeline=True),
|
|
93
124
|
"component_editing": editing,
|
|
94
125
|
"captions": _captions(repository, project_id, revision.timeline),
|
|
126
|
+
"shots": _shots(repository, project_id, run_id, revision.timeline),
|
|
95
127
|
"history": history,
|
|
96
128
|
"ai_usage": usage,
|
|
97
129
|
"references": public_state(intent, revision.timeline),
|
package/src/clipen/locale_en.py
CHANGED
|
@@ -263,6 +263,19 @@ MESSAGES = {
|
|
|
263
263
|
"指定來源沒有這個影像串流。": "That source has no such video stream.",
|
|
264
264
|
"取樣時間沒有可解碼畫面。": "There is no decodable frame at that time.",
|
|
265
265
|
"混音片段超出影片或來源長度。": "An audio piece runs past the film or its source.",
|
|
266
|
+
# controller/app.py: footage added later
|
|
267
|
+
"只能加入影片或聲音檔。": "Only video or sound files can be added.",
|
|
268
|
+
"檔名無效。": "The file name is invalid.",
|
|
269
|
+
"檔案是空的。": "The file is empty.",
|
|
270
|
+
"素材正在檢查,等檢查完成再加入。": "The footage is being checked; add files once it is done.",
|
|
271
|
+
# projects/storage.py
|
|
272
|
+
"追加素材資料夾不安全。": "The added-footage folder is unsafe.",
|
|
273
|
+
# editing/slip.py
|
|
274
|
+
"請指定要往前或往後移動幾格。": "Say how many frames to move it earlier or later.",
|
|
275
|
+
"找不到這個鏡頭。": "That shot was not found.",
|
|
276
|
+
"微調設定無效。": "The slip settings are invalid.",
|
|
277
|
+
# editing/aspect.py
|
|
278
|
+
"畫面比例必須是 16:9、9:16、1:1 或 4:5。": "The aspect ratio must be 16:9, 9:16, 1:1 or 4:5.",
|
|
266
279
|
# editing/production_preview.py
|
|
267
280
|
"請先使用 validate_sequence 修正時間軸。": "Fix the timeline with validate_sequence first.",
|
|
268
281
|
"這一版用到的配樂或音效找不到了,請重新選一首配樂再輸出。": "The music or sound effects in this version are missing; pick the music again, then render.",
|
|
@@ -543,4 +556,9 @@ PATTERNS = (
|
|
|
543
556
|
),
|
|
544
557
|
(re.compile(r"畫自由設計元件 (\d+)/(\d+)"), "Drawing custom graphic {0}/{1}"),
|
|
545
558
|
(re.compile(r"畫字幕 (\d+) 句"), "Drawing {0} captions"),
|
|
559
|
+
(
|
|
560
|
+
re.compile(r"這個鏡頭最多只能往前 ([0-9.]+) 秒、往後 ([0-9.]+) 秒,再過去就沒有毛片了。"),
|
|
561
|
+
"This shot can move at most {0} s earlier and {1} s later; past that there is no footage.",
|
|
562
|
+
),
|
|
563
|
+
(re.compile(r"這支影片是 (\S+),畫布只能是 (\S+)。"), "This film is {0}; its canvas can only be {1}."),
|
|
546
564
|
)
|
|
@@ -124,7 +124,9 @@ _TOOLS = (
|
|
|
124
124
|
"description": (
|
|
125
125
|
"Use {} for safe defaults, or exact numeric keys: "
|
|
126
126
|
"punch_in {scale,center_x,center_y}; slow_push "
|
|
127
|
-
"{scale_from,scale_to}; reframe {x,y}; speed_ramp {rate}."
|
|
127
|
+
"{scale_from,scale_to}; reframe {x,y}; speed_ramp {rate}. "
|
|
128
|
+
"Footage always fills the film's frame and the overflow is cropped; reframe "
|
|
129
|
+
"{x,y} picks what stays: x 0 keeps the left edge, 1 the right; y 0 the top, 1 the bottom."
|
|
128
130
|
),
|
|
129
131
|
"properties": {
|
|
130
132
|
"scale": {"type": "number", "minimum": 1.01, "maximum": 2},
|
|
@@ -188,7 +188,7 @@ class MediaDiscovery:
|
|
|
188
188
|
"non_media",
|
|
189
189
|
)
|
|
190
190
|
continue
|
|
191
|
-
kind =
|
|
191
|
+
kind = kind_for_name(name)
|
|
192
192
|
yield DiscoveredAsset(
|
|
193
193
|
role,
|
|
194
194
|
relative,
|
|
@@ -205,7 +205,7 @@ class MediaDiscovery:
|
|
|
205
205
|
raise DiscoveryError("too_many_files")
|
|
206
206
|
|
|
207
207
|
|
|
208
|
-
def
|
|
208
|
+
def kind_for_name(name: str) -> AssetKind:
|
|
209
209
|
extension = PurePosixPath(name).suffix.lower()
|
|
210
210
|
if extension in _VIDEO_EXTENSIONS:
|
|
211
211
|
return AssetKind.VIDEO
|
|
@@ -106,6 +106,11 @@ class MediaPreviewRepository:
|
|
|
106
106
|
row["inode"],
|
|
107
107
|
row["saved_at"],
|
|
108
108
|
)
|
|
109
|
+
if root.role is DirectoryRole.ADDED:
|
|
110
|
+
# The project's own folder: wherever the project is now, not where it was checked.
|
|
111
|
+
folder = self.projects.added_footage_folder(project_id)
|
|
112
|
+
info = folder.stat()
|
|
113
|
+
root = InventoryRoot(DirectoryRole.ADDED, str(folder), info.st_dev, info.st_ino, row["saved_at"])
|
|
109
114
|
descriptor = open_file_beneath(root, row["relative_path"])
|
|
110
115
|
details = os.fstat(descriptor)
|
|
111
116
|
if details.st_size != row["size_bytes"] or details.st_mtime_ns != row["mtime_ns"]:
|
|
@@ -89,6 +89,9 @@ class InventoryRepository:
|
|
|
89
89
|
revision = validate_revision(expected_revision)
|
|
90
90
|
request_hash = command_digest({"expected_revision": revision})
|
|
91
91
|
run_id = make_run_id(project_id, normalized_request)
|
|
92
|
+
# Added footage lives in the project's own folder; point at it where the project is now.
|
|
93
|
+
if (self.projects.root / project_id / self.projects.ADDED_FOOTAGE).is_dir():
|
|
94
|
+
self.projects.added_footage_folder(project_id)
|
|
92
95
|
with self.projects.connect(project_id) as connection:
|
|
93
96
|
try:
|
|
94
97
|
connection.execute("BEGIN IMMEDIATE")
|
|
@@ -119,7 +122,7 @@ class InventoryRepository:
|
|
|
119
122
|
status_code=409,
|
|
120
123
|
)
|
|
121
124
|
rows = connection.execute(
|
|
122
|
-
"SELECT role, canonical_path, device, inode, saved_at FROM project_directories WHERE role
|
|
125
|
+
"SELECT role, canonical_path, device, inode, saved_at FROM project_directories WHERE role IN ('source', 'added') ORDER BY role"
|
|
123
126
|
).fetchall()
|
|
124
127
|
roots = tuple(
|
|
125
128
|
InventoryRoot(
|
|
@@ -399,7 +402,7 @@ class InventoryRepository:
|
|
|
399
402
|
status_code=409,
|
|
400
403
|
)
|
|
401
404
|
root_rows = connection.execute(
|
|
402
|
-
"SELECT role, canonical_path, device, inode, saved_at FROM project_directories WHERE role
|
|
405
|
+
"SELECT role, canonical_path, device, inode, saved_at FROM project_directories WHERE role IN ('source', 'added') ORDER BY role"
|
|
403
406
|
).fetchall()
|
|
404
407
|
current_roots = tuple(
|
|
405
408
|
InventoryRoot(
|
|
@@ -35,6 +35,8 @@ class ProjectError(RuntimeError):
|
|
|
35
35
|
class DirectoryRole(str, Enum):
|
|
36
36
|
SOURCE = "source"
|
|
37
37
|
REFERENCE = "reference"
|
|
38
|
+
# Footage added later, from anywhere: copied into the project's own folder, checked beside the footage folder.
|
|
39
|
+
ADDED = "added"
|
|
38
40
|
|
|
39
41
|
|
|
40
42
|
class DirectoryAvailability(str, Enum):
|
|
@@ -36,7 +36,7 @@ from .preview_schema import PREVIEW_SCHEMA
|
|
|
36
36
|
from .timeline_schema import TIMELINE_SCHEMA
|
|
37
37
|
from .validation_schema import VALIDATION_WORKFLOW_SCHEMA
|
|
38
38
|
|
|
39
|
-
PROJECT_SCHEMA_VERSION =
|
|
39
|
+
PROJECT_SCHEMA_VERSION = 20
|
|
40
40
|
# Tables of the retired confirmed-plan flow, children before parents. Version 19
|
|
41
41
|
# archives any rows they still hold beside the database and drops them.
|
|
42
42
|
RETIRED_PLANNING_TABLES = ("current_plan", "plan_revisions", "planning_runs", "plan_command_receipts")
|
|
@@ -76,7 +76,7 @@ CREATE TABLE inventory_command_receipts (
|
|
|
76
76
|
CREATE TABLE assets (
|
|
77
77
|
asset_id TEXT PRIMARY KEY,
|
|
78
78
|
project_id TEXT NOT NULL REFERENCES project(project_id),
|
|
79
|
-
role TEXT NOT NULL CHECK (role IN ('source', 'reference')),
|
|
79
|
+
role TEXT NOT NULL CHECK (role IN ('source', 'reference', 'added')),
|
|
80
80
|
relative_path TEXT NOT NULL,
|
|
81
81
|
first_seen_at TEXT NOT NULL,
|
|
82
82
|
UNIQUE(project_id, role, relative_path)
|
|
@@ -452,6 +452,40 @@ class ProjectRepository:
|
|
|
452
452
|
),
|
|
453
453
|
)
|
|
454
454
|
|
|
455
|
+
ADDED_FOOTAGE = "added-footage"
|
|
456
|
+
|
|
457
|
+
def added_footage_folder(self, project_id: str) -> Path:
|
|
458
|
+
"""The project's own folder for footage added later, made and registered on first use.
|
|
459
|
+
|
|
460
|
+
It is the project's, so it is found where the project now is: a project copied, restored or
|
|
461
|
+
moved keeps its added footage, though the folder's path and inode change with it."""
|
|
462
|
+
validate_project_id(project_id)
|
|
463
|
+
folder = self.root / project_id / self.ADDED_FOOTAGE
|
|
464
|
+
if folder.is_symlink():
|
|
465
|
+
raise ProjectError("storage_unsafe", "追加素材資料夾不安全。", status_code=409)
|
|
466
|
+
folder.mkdir(mode=0o700, exist_ok=True)
|
|
467
|
+
info = folder.stat()
|
|
468
|
+
with self.connect(project_id) as connection:
|
|
469
|
+
connection.execute("BEGIN IMMEDIATE")
|
|
470
|
+
row = connection.execute(
|
|
471
|
+
"SELECT canonical_path, device, inode FROM project_directories WHERE role = 'added'"
|
|
472
|
+
).fetchone()
|
|
473
|
+
if row is None or (row["canonical_path"], row["device"], row["inode"]) != (
|
|
474
|
+
str(folder),
|
|
475
|
+
info.st_dev,
|
|
476
|
+
info.st_ino,
|
|
477
|
+
):
|
|
478
|
+
connection.execute(
|
|
479
|
+
"INSERT INTO project_directories "
|
|
480
|
+
"(role, canonical_path, display_path, display_name, device, inode, saved_at) "
|
|
481
|
+
"VALUES ('added', ?, ?, ?, ?, ?, ?) "
|
|
482
|
+
"ON CONFLICT(role) DO UPDATE SET canonical_path = excluded.canonical_path, "
|
|
483
|
+
"display_path = excluded.display_path, device = excluded.device, inode = excluded.inode",
|
|
484
|
+
(str(folder), str(folder), "追加素材", info.st_dev, info.st_ino, utc_now()),
|
|
485
|
+
)
|
|
486
|
+
connection.commit()
|
|
487
|
+
return folder
|
|
488
|
+
|
|
455
489
|
def set_directory(
|
|
456
490
|
self,
|
|
457
491
|
project_id: str,
|
|
@@ -621,7 +655,7 @@ class ProjectRepository:
|
|
|
621
655
|
updated_at TEXT NOT NULL
|
|
622
656
|
);
|
|
623
657
|
CREATE TABLE project_directories (
|
|
624
|
-
role TEXT PRIMARY KEY CHECK (role IN ('source', 'reference')),
|
|
658
|
+
role TEXT PRIMARY KEY CHECK (role IN ('source', 'reference', 'added')),
|
|
625
659
|
canonical_path TEXT NOT NULL,
|
|
626
660
|
display_path TEXT NOT NULL,
|
|
627
661
|
display_name TEXT NOT NULL,
|
|
@@ -649,7 +683,7 @@ class ProjectRepository:
|
|
|
649
683
|
+ PRODUCTION_SESSION_SCHEMA
|
|
650
684
|
+ FINISHING_SCHEMA
|
|
651
685
|
+ """
|
|
652
|
-
PRAGMA user_version =
|
|
686
|
+
PRAGMA user_version = 20;
|
|
653
687
|
"""
|
|
654
688
|
)
|
|
655
689
|
connection.execute(
|
|
@@ -746,6 +780,9 @@ class ProjectRepository:
|
|
|
746
780
|
if version == 18:
|
|
747
781
|
self._migrate_v18_to_v19(connection, project_dir)
|
|
748
782
|
version = 19
|
|
783
|
+
if version == 19:
|
|
784
|
+
self._migrate_v19_to_v20(connection)
|
|
785
|
+
version = 20
|
|
749
786
|
if version != PROJECT_SCHEMA_VERSION:
|
|
750
787
|
connection.close()
|
|
751
788
|
raise ProjectError(
|
|
@@ -787,6 +824,49 @@ class ProjectRepository:
|
|
|
787
824
|
finally:
|
|
788
825
|
connection.execute("PRAGMA foreign_keys=ON")
|
|
789
826
|
|
|
827
|
+
@staticmethod
|
|
828
|
+
def _migrate_v19_to_v20(connection: sqlite3.Connection) -> None:
|
|
829
|
+
"""Let footage added later sit beside the footage folder, under its own 'added' role.
|
|
830
|
+
|
|
831
|
+
SQLite cannot change a CHECK in place, so both tables are rebuilt with the new role allowed
|
|
832
|
+
and their rows copied; foreign keys are off for the swap and must still hold afterwards."""
|
|
833
|
+
connection.execute("PRAGMA foreign_keys = OFF")
|
|
834
|
+
try:
|
|
835
|
+
connection.execute("BEGIN IMMEDIATE")
|
|
836
|
+
connection.execute(
|
|
837
|
+
"CREATE TABLE project_directories_v20 ("
|
|
838
|
+
"role TEXT PRIMARY KEY CHECK (role IN ('source', 'reference', 'added')), "
|
|
839
|
+
"canonical_path TEXT NOT NULL, display_path TEXT NOT NULL, display_name TEXT NOT NULL, "
|
|
840
|
+
"device INTEGER NOT NULL, inode INTEGER NOT NULL, saved_at TEXT NOT NULL)"
|
|
841
|
+
)
|
|
842
|
+
connection.execute(
|
|
843
|
+
"INSERT INTO project_directories_v20 SELECT role, canonical_path, display_path, display_name, "
|
|
844
|
+
"device, inode, saved_at FROM project_directories"
|
|
845
|
+
)
|
|
846
|
+
connection.execute("DROP TABLE project_directories")
|
|
847
|
+
connection.execute("ALTER TABLE project_directories_v20 RENAME TO project_directories")
|
|
848
|
+
connection.execute(
|
|
849
|
+
"CREATE TABLE assets_v20 ("
|
|
850
|
+
"asset_id TEXT PRIMARY KEY, project_id TEXT NOT NULL REFERENCES project(project_id), "
|
|
851
|
+
"role TEXT NOT NULL CHECK (role IN ('source', 'reference', 'added')), "
|
|
852
|
+
"relative_path TEXT NOT NULL, first_seen_at TEXT NOT NULL, "
|
|
853
|
+
"UNIQUE(project_id, role, relative_path))"
|
|
854
|
+
)
|
|
855
|
+
connection.execute(
|
|
856
|
+
"INSERT INTO assets_v20 SELECT asset_id, project_id, role, relative_path, first_seen_at FROM assets"
|
|
857
|
+
)
|
|
858
|
+
connection.execute("DROP TABLE assets")
|
|
859
|
+
connection.execute("ALTER TABLE assets_v20 RENAME TO assets")
|
|
860
|
+
if connection.execute("PRAGMA foreign_key_check").fetchone() is not None:
|
|
861
|
+
raise sqlite3.DatabaseError("allowing added footage broke foreign keys")
|
|
862
|
+
connection.execute("PRAGMA user_version = 20")
|
|
863
|
+
connection.commit()
|
|
864
|
+
except Exception:
|
|
865
|
+
connection.rollback()
|
|
866
|
+
raise
|
|
867
|
+
finally:
|
|
868
|
+
connection.execute("PRAGMA foreign_keys = ON")
|
|
869
|
+
|
|
790
870
|
@staticmethod
|
|
791
871
|
def _migrate_v18_to_v19(connection: sqlite3.Connection, project_dir: Path) -> None:
|
|
792
872
|
"""Drop the retired confirmed-plan tables without losing what they held.
|
|
@@ -154,16 +154,36 @@ def resolve_codex_model(preferences: tuple[str | None, str | None], models: list
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
def codex_account(
|
|
157
|
+
def codex_account(
|
|
158
|
+
binary: str | Path,
|
|
159
|
+
environment: Mapping[str, str],
|
|
160
|
+
timeout: float = 10.0,
|
|
161
|
+
*,
|
|
162
|
+
model_override: str | None = None,
|
|
163
|
+
include_models: bool = False,
|
|
164
|
+
) -> dict:
|
|
158
165
|
"""The model Clipen runs (see resolve_codex_model) and live usage limits."""
|
|
159
166
|
from .codex import codex_preferences
|
|
160
167
|
|
|
161
168
|
answers = _rpc(str(binary), environment, [("account/rateLimits/read", None), ("model/list", {})], timeout)
|
|
162
169
|
limits = (answers.get(1) or {}).get("rateLimits")
|
|
163
|
-
|
|
170
|
+
models = _models((answers.get(2) or {}).get("data"))
|
|
171
|
+
configured, effort = codex_preferences(environment)
|
|
172
|
+
resolved = resolve_codex_model((model_override or configured, effort), models)
|
|
164
173
|
model = (
|
|
165
174
|
None if resolved is None else {key: resolved[key] for key in ("id", "name", "effort", "source", "unavailable")}
|
|
166
175
|
)
|
|
176
|
+
if model_override:
|
|
177
|
+
if model and model["id"] == model_override:
|
|
178
|
+
model["source"] = "clipen"
|
|
179
|
+
else:
|
|
180
|
+
model = {
|
|
181
|
+
"id": model_override,
|
|
182
|
+
"name": model_override,
|
|
183
|
+
"effort": None,
|
|
184
|
+
"source": "clipen",
|
|
185
|
+
"unavailable": model_override if models else None,
|
|
186
|
+
}
|
|
167
187
|
quota = None
|
|
168
188
|
if isinstance(limits, dict):
|
|
169
189
|
windows = [w for w in (_window(limits.get("primary")), _window(limits.get("secondary"))) if w]
|
|
@@ -173,7 +193,10 @@ def codex_account(binary: str | Path, environment: Mapping[str, str], timeout: f
|
|
|
173
193
|
"windows": windows,
|
|
174
194
|
"limited": bool(limits.get("rateLimitReachedType")),
|
|
175
195
|
}
|
|
176
|
-
|
|
196
|
+
result = {"model": model, "quota": quota}
|
|
197
|
+
if include_models:
|
|
198
|
+
result["models"] = [{"id": entry["model"], "name": entry["name"] or entry["model"]} for entry in models]
|
|
199
|
+
return result
|
|
177
200
|
|
|
178
201
|
|
|
179
202
|
def record_claude_account(attempt_root: Path, events: list[dict], requested: str | None = None) -> None:
|
|
@@ -209,12 +232,16 @@ def _claude_name(model: str) -> str:
|
|
|
209
232
|
return " ".join(words) or model
|
|
210
233
|
|
|
211
234
|
|
|
212
|
-
def claude_account(
|
|
235
|
+
def claude_account(
|
|
236
|
+
attempt_root: Path, environment: Mapping[str, str] | None = None, *, model_override: str | None = None
|
|
237
|
+
) -> dict:
|
|
213
238
|
"""The last run's model and limit status, with the effort and model chosen in Claude Code settings."""
|
|
214
239
|
from .claude import claude_preferences
|
|
215
240
|
|
|
216
241
|
wanted, effort = claude_preferences(environment)
|
|
217
242
|
source = "claude_config" if wanted or effort else "default"
|
|
243
|
+
if model_override:
|
|
244
|
+
wanted, source = model_override, "clipen"
|
|
218
245
|
path = attempt_root / _SNAPSHOT
|
|
219
246
|
try:
|
|
220
247
|
if path.is_symlink() or path.stat().st_size > 4096:
|
|
@@ -228,11 +255,15 @@ def claude_account(attempt_root: Path, environment: Mapping[str, str] | None = N
|
|
|
228
255
|
# A model chosen after the last run is what the next run uses.
|
|
229
256
|
if wanted and (not isinstance(model, str) or snapshot.get("requested") != wanted):
|
|
230
257
|
model = wanted
|
|
258
|
+
elif not wanted and snapshot.get("requested"):
|
|
259
|
+
model = None
|
|
231
260
|
limit = snapshot.get("limit") if isinstance(snapshot.get("limit"), dict) else {}
|
|
261
|
+
reset = limit.get("resetsAt")
|
|
262
|
+
resets_at = reset if type(reset) is int and reset > 0 else None
|
|
232
263
|
observed = snapshot.get("observed_at") if isinstance(snapshot.get("observed_at"), int) else None
|
|
233
264
|
quota = (
|
|
234
265
|
None
|
|
235
|
-
if not limit
|
|
266
|
+
if not limit or (resets_at is not None and resets_at <= time.time())
|
|
236
267
|
else {
|
|
237
268
|
"source": "last_run",
|
|
238
269
|
"observed_at": observed,
|
|
@@ -240,7 +271,7 @@ def claude_account(attempt_root: Path, environment: Mapping[str, str] | None = N
|
|
|
240
271
|
"windows": [],
|
|
241
272
|
"limited": limit.get("status") not in (None, "allowed", "allowed_warning"),
|
|
242
273
|
"warning": limit.get("status") == "allowed_warning",
|
|
243
|
-
"resets_at":
|
|
274
|
+
"resets_at": resets_at,
|
|
244
275
|
"kind": limit.get("rateLimitType") if isinstance(limit.get("rateLimitType"), str) else None,
|
|
245
276
|
}
|
|
246
277
|
)
|
|
@@ -36,6 +36,7 @@ from .errors import (
|
|
|
36
36
|
ProviderUnavailable,
|
|
37
37
|
ProviderUsageLimitError,
|
|
38
38
|
)
|
|
39
|
+
from .model_selection import selected_model
|
|
39
40
|
from .recovery import ProviderUsage
|
|
40
41
|
|
|
41
42
|
# Flags the bounded editing attempt depends on; an older CLI without them
|
|
@@ -86,8 +87,9 @@ def claude_preferences(environment: Mapping[str, str] | None = None) -> tuple[st
|
|
|
86
87
|
)
|
|
87
88
|
|
|
88
89
|
|
|
89
|
-
def model_arguments(environment: Mapping[str, str] | None = None) -> tuple[str, ...]:
|
|
90
|
-
|
|
90
|
+
def model_arguments(environment: Mapping[str, str] | None = None, *, model: str | None = None) -> tuple[str, ...]:
|
|
91
|
+
configured, effort = claude_preferences(environment)
|
|
92
|
+
model = model or configured
|
|
91
93
|
return (*(("--model", model) if model else ()), *(("--effort", effort) if effort else ()))
|
|
92
94
|
|
|
93
95
|
|
|
@@ -329,7 +331,7 @@ class ClaudeExecAdapter(CodexExecAdapter):
|
|
|
329
331
|
"project",
|
|
330
332
|
"--no-session-persistence",
|
|
331
333
|
"--disable-slash-commands",
|
|
332
|
-
*model_arguments(self._environment),
|
|
334
|
+
*model_arguments(self._environment, model=selected_model(self._attempt_root, "claude")),
|
|
333
335
|
)
|
|
334
336
|
|
|
335
337
|
def _stdin_payload(self, attempt: CodexAttempt) -> bytes:
|
|
@@ -9,7 +9,6 @@ from typing import Mapping
|
|
|
9
9
|
from .claude import (
|
|
10
10
|
_stream_events,
|
|
11
11
|
claude_environment,
|
|
12
|
-
claude_preferences,
|
|
13
12
|
model_arguments,
|
|
14
13
|
raise_for_claude_failure,
|
|
15
14
|
raise_for_failed_result,
|
|
@@ -19,6 +18,7 @@ from .claude import (
|
|
|
19
18
|
from .codex import _decode_capture
|
|
20
19
|
from .editing_agent import _MAX_CAPTURE_BYTES, _MCP_TOOLS, BoundedEditingAgent, mcp_server_arguments
|
|
21
20
|
from .errors import ProviderProtocolError
|
|
21
|
+
from .model_selection import selected_model
|
|
22
22
|
from .recovery import ProviderUsage
|
|
23
23
|
|
|
24
24
|
MCP_SERVER = "clipen"
|
|
@@ -76,21 +76,20 @@ class ClaudeEditingAgent(BoundedEditingAgent):
|
|
|
76
76
|
"--setting-sources",
|
|
77
77
|
"project",
|
|
78
78
|
"--disable-slash-commands",
|
|
79
|
-
*model_arguments(self.environment),
|
|
79
|
+
*model_arguments(self.environment, model=selected_model(self.attempt_root, "claude")),
|
|
80
80
|
)
|
|
81
81
|
|
|
82
82
|
def events_and_usage(self, stdout: bytes) -> tuple[tuple[str, ...], ProviderUsage | None]:
|
|
83
83
|
events = _stream_events(stdout, _MAX_CAPTURE_BYTES)
|
|
84
84
|
return stream_event_types(events), stream_usage(events)
|
|
85
85
|
|
|
86
|
-
def record_account(self, stdout: bytes) -> None:
|
|
86
|
+
def record_account(self, stdout: bytes, command: tuple[str, ...]) -> None:
|
|
87
87
|
# Claude Code has no quota query; keep what this attempt reported.
|
|
88
88
|
from .account import record_claude_account
|
|
89
89
|
|
|
90
90
|
try:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
)
|
|
91
|
+
model = command[command.index("--model") + 1] if "--model" in command else None
|
|
92
|
+
record_claude_account(self.attempt_root, _stream_events(stdout, _MAX_CAPTURE_BYTES), model)
|
|
94
93
|
except (OSError, ProviderProtocolError):
|
|
95
94
|
pass
|
|
96
95
|
|
|
@@ -34,6 +34,7 @@ from .errors import (
|
|
|
34
34
|
ProviderUnavailable,
|
|
35
35
|
ProviderUsageLimitError,
|
|
36
36
|
)
|
|
37
|
+
from .model_selection import model_lock, selected_model
|
|
37
38
|
from .recovery import (
|
|
38
39
|
AttemptReceiptError,
|
|
39
40
|
AttemptReceiptStore,
|
|
@@ -150,19 +151,26 @@ def codex_preferences(environment: Mapping[str, str] | None = None) -> tuple[str
|
|
|
150
151
|
return (model if model and _MODEL.fullmatch(model) else None, effort if effort in _EFFORTS else None)
|
|
151
152
|
|
|
152
153
|
|
|
153
|
-
def model_config(
|
|
154
|
+
def model_config(
|
|
155
|
+
binary: str | Path, environment: Mapping[str, str] | None = None, *, model: str | None = None
|
|
156
|
+
) -> tuple[str, ...]:
|
|
154
157
|
"""`-c` overrides for the user's model and effort, kept only when this account supports them."""
|
|
155
|
-
|
|
158
|
+
configured, effort = codex_preferences(environment)
|
|
159
|
+
preferences = (model or configured, effort)
|
|
156
160
|
if preferences == (None, None):
|
|
157
161
|
return ()
|
|
158
162
|
from .account import available_models, resolve_codex_model
|
|
159
163
|
|
|
160
164
|
resolved = resolve_codex_model(preferences, available_models(binary, environment or os.environ))
|
|
161
|
-
if resolved
|
|
162
|
-
|
|
165
|
+
applied_model = model or (resolved["id"] if resolved and resolved["apply_model"] else None)
|
|
166
|
+
applied_effort = (
|
|
167
|
+
resolved["effort"]
|
|
168
|
+
if resolved and resolved["apply_effort"] and (model is None or resolved["id"] == model)
|
|
169
|
+
else None
|
|
170
|
+
)
|
|
163
171
|
return (
|
|
164
|
-
*(("-c", f"model={json.dumps(
|
|
165
|
-
*(("-c", f"model_reasoning_effort={json.dumps(
|
|
172
|
+
*(("-c", f"model={json.dumps(applied_model)}") if applied_model else ()),
|
|
173
|
+
*(("-c", f"model_reasoning_effort={json.dumps(applied_effort)}") if applied_effort else ()),
|
|
166
174
|
)
|
|
167
175
|
|
|
168
176
|
|
|
@@ -510,7 +518,7 @@ class CodexExecAdapter:
|
|
|
510
518
|
"--output-last-message",
|
|
511
519
|
str(resolved_output),
|
|
512
520
|
*(part for image in attempt.images for part in ("--image", str(image.resolve()))),
|
|
513
|
-
*model_config(self._binary, self._environment),
|
|
521
|
+
*model_config(self._binary, self._environment, model=selected_model(self._attempt_root, "codex")),
|
|
514
522
|
"--cd",
|
|
515
523
|
str(workspace),
|
|
516
524
|
"-",
|
|
@@ -521,6 +529,10 @@ class CodexExecAdapter:
|
|
|
521
529
|
attempt: CodexAttempt,
|
|
522
530
|
cancel_token: CancellationToken | None = None,
|
|
523
531
|
) -> CodexAttemptResult:
|
|
532
|
+
with model_lock(self._attempt_root):
|
|
533
|
+
return self._execute(attempt, cancel_token)
|
|
534
|
+
|
|
535
|
+
def _execute(self, attempt: CodexAttempt, cancel_token: CancellationToken | None) -> CodexAttemptResult:
|
|
524
536
|
if cancel_token is not None and cancel_token.is_set():
|
|
525
537
|
raise ProviderCancelled(f"Codex attempt {attempt.attempt_id} was cancelled")
|
|
526
538
|
workspace = _isolated_workspace(attempt.workspace)
|
|
@@ -23,6 +23,7 @@ from .editing_agent import (
|
|
|
23
23
|
EditingResult,
|
|
24
24
|
mcp_server_arguments,
|
|
25
25
|
)
|
|
26
|
+
from .model_selection import selected_model
|
|
26
27
|
from .recovery import ProviderUsage
|
|
27
28
|
|
|
28
29
|
__all__ = ["CodexEditingAgent", "CodexEditingResult", "_MCP_TOOLS", "_PRODUCTION_PROMPT", "_PROMPT"]
|
|
@@ -78,7 +79,7 @@ class CodexEditingAgent(BoundedEditingAgent):
|
|
|
78
79
|
'mcp_servers.clipen.default_tools_approval_mode="approve"',
|
|
79
80
|
"-c",
|
|
80
81
|
f"mcp_servers.clipen.enabled_tools={json.dumps(_MCP_TOOLS)}",
|
|
81
|
-
*model_config(self.binary, self.environment),
|
|
82
|
+
*model_config(self.binary, self.environment, model=selected_model(self.attempt_root, "codex")),
|
|
82
83
|
"--cd",
|
|
83
84
|
str(workspace),
|
|
84
85
|
"-",
|
|
@@ -23,6 +23,7 @@ from typing import Mapping
|
|
|
23
23
|
from clipen.editing.agent import AgentRun, EditAgentRepository
|
|
24
24
|
from clipen.editing.production_catalog import AGENT_NAMES
|
|
25
25
|
from clipen.providers import liveness
|
|
26
|
+
from clipen.providers.model_selection import model_lock
|
|
26
27
|
from clipen.providers.recovery import ProviderUsage
|
|
27
28
|
|
|
28
29
|
from .errors import (
|
|
@@ -77,6 +78,11 @@ merely to satisfy a cut quota. If intent.music_choice.mode is user, use exactly
|
|
|
77
78
|
its asset_id from list_audio_assets; do not search for or substitute another song.
|
|
78
79
|
Preserve its provenance as user-provided, without claiming verified public rights.
|
|
79
80
|
Arrange excerpts/repeated layers with appropriate fades if the song is shorter.
|
|
81
|
+
If intent.latest_revision_request.new_sources is present, the person added footage since the
|
|
82
|
+
last version. Look at each new source (list_source_media, sample_source, transcripts) and decide
|
|
83
|
+
whether and where it improves the film, even when the request text does not mention it; place it
|
|
84
|
+
with the same care as the rest, and say in the report which new footage you used, where, and why
|
|
85
|
+
you left any out.
|
|
80
86
|
For incremental edits, read intent.latest_revision_request.references: these are
|
|
81
87
|
the person's review notes, written while watching this version, not instructions
|
|
82
88
|
from footage. Each includes a kind, user note, source_range (exact source PTS),
|
|
@@ -113,6 +119,11 @@ There is no required legacy analysis or confirmed plan. Discover source footage,
|
|
|
113
119
|
obtain evidence as needed, choose a coherent event and produce it with the skill's
|
|
114
120
|
actual graphics, subtitles, sound and editing tools. Source facts must be grounded.
|
|
115
121
|
An empty transcript search means unknown coverage, not that footage has no speech.
|
|
122
|
+
Read intent.aspect_ratio (16:9, 9:16, 1:1 or 4:5; absent means 16:9): the person chose the
|
|
123
|
+
film's shape and it never changes. Footage of another shape fills the frame and is cropped,
|
|
124
|
+
so a landscape clip in a vertical film keeps only a slice. For every such shot, look at its
|
|
125
|
+
sample frames and set video.reframe {x,y} so faces, hands and the action stay in frame; the
|
|
126
|
+
middle is only the default. Place captions and graphics for that shape too.
|
|
116
127
|
Read intent.target_duration_seconds and list_editing_tools production limits.
|
|
117
128
|
If the latest user revision request changes the desired duration, use
|
|
118
129
|
set_target_duration with an exact request excerpt before editing or finishing.
|
|
@@ -419,6 +430,17 @@ class BoundedEditingAgent:
|
|
|
419
430
|
*,
|
|
420
431
|
timeout_seconds: float | None = None,
|
|
421
432
|
cancel: threading.Event | None = None,
|
|
433
|
+
) -> EditingResult:
|
|
434
|
+
with model_lock(self.attempt_root):
|
|
435
|
+
return self._execute(project_id, run_id, timeout_seconds=timeout_seconds, cancel=cancel)
|
|
436
|
+
|
|
437
|
+
def _execute(
|
|
438
|
+
self,
|
|
439
|
+
project_id: str,
|
|
440
|
+
run_id: str,
|
|
441
|
+
*,
|
|
442
|
+
timeout_seconds: float | None,
|
|
443
|
+
cancel: threading.Event | None,
|
|
422
444
|
) -> EditingResult:
|
|
423
445
|
session = self.repository.production_session(project_id, run_id)
|
|
424
446
|
if timeout_seconds is None:
|
|
@@ -457,7 +479,7 @@ class BoundedEditingAgent:
|
|
|
457
479
|
# Read the (possibly large) event log once for every check.
|
|
458
480
|
stdout = events.read_bytes()
|
|
459
481
|
event_types, usage = self.events_and_usage(stdout)
|
|
460
|
-
self.record_account(stdout)
|
|
482
|
+
self.record_account(stdout, command)
|
|
461
483
|
self.raise_for_failure(stdout, diagnostics.read_bytes(), returncode)
|
|
462
484
|
del stdout
|
|
463
485
|
finished = self.repository.get(project_id, run_id)
|
|
@@ -561,7 +583,7 @@ class BoundedEditingAgent:
|
|
|
561
583
|
except OSError:
|
|
562
584
|
pass
|
|
563
585
|
|
|
564
|
-
def record_account(self, stdout: bytes) -> None:
|
|
586
|
+
def record_account(self, stdout: bytes, command: tuple[str, ...]) -> None:
|
|
565
587
|
"""Remember account details the provider reported, for the status bar."""
|
|
566
588
|
|
|
567
589
|
def closing_message(self, stdout: bytes, final_message: Path) -> str | None:
|