@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.
- package/README.md +16 -6
- package/apps/web/dist/assets/index-DPgSvXZ1.js +15 -0
- package/apps/web/dist/assets/index-DmPWV61v.css +1 -0
- package/apps/web/dist/index.html +2 -2
- package/bin/clipen.js +229 -68
- package/package.json +8 -2
- package/pyproject.toml +1 -1
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/analysis/qwen_worker.py +13 -4
- package/src/clipen/analysis/setup.py +2 -1
- package/src/clipen/analysis/setup_cli.py +58 -12
- package/src/clipen/bootstrap.py +499 -167
- package/src/clipen/cli.py +40 -15
- package/src/clipen/controller/app.py +120 -38
- package/src/clipen/controller/server.py +70 -27
- package/src/clipen/editing/agent_repository.py +8 -0
- package/src/clipen/editing/agent_tools.py +1 -1
- package/src/clipen/editing/caption_design.py +134 -0
- package/src/clipen/editing/change_report.py +17 -0
- package/src/clipen/editing/component_looks.py +3 -3
- package/src/clipen/editing/component_review.py +0 -38
- package/src/clipen/editing/coordinator.py +20 -0
- package/src/clipen/editing/evidence_jobs.py +3 -1
- package/src/clipen/editing/history_changes.py +56 -27
- package/src/clipen/editing/production_catalog.py +67 -13
- package/src/clipen/editing/production_media.py +13 -2
- package/src/clipen/editing/production_preview.py +11 -9
- package/src/clipen/editing/production_progress.py +48 -3
- package/src/clipen/editing/production_tools.py +11 -20
- package/src/clipen/editing/program_subtitles.py +5 -13
- package/src/clipen/editing/resolve_export.py +2 -183
- package/src/clipen/editing/skill_tools.py +142 -218
- package/src/clipen/editing/tool_receipts.py +2 -1
- package/src/clipen/editing/versions.py +55 -10
- package/src/clipen/editing/visual_preview.py +62 -0
- package/src/clipen/editing/workbench.py +21 -1
- package/src/clipen/i18n.py +155 -0
- package/src/clipen/locale_en.py +546 -0
- package/src/clipen/mcp_editing/__main__.py +8 -0
- package/src/clipen/media/storage.py +2 -2
- package/src/clipen/own_ffmpeg.py +113 -0
- package/src/clipen/projects/models.py +16 -1
- package/src/clipen/projects/picker.py +3 -1
- package/src/clipen/projects/storage.py +17 -1
- package/src/clipen/providers/claude_editing.py +3 -1
- package/src/clipen/providers/codex_editing.py +3 -1
- package/src/clipen/providers/editing_agent.py +42 -5
- package/src/clipen/providers/liveness.py +39 -0
- package/src/clipen/rendering/custom_components.py +216 -25
- package/src/clipen/rendering/custom_render.py +90 -54
- package/src/clipen/rendering/fetched_fonts.py +127 -0
- package/src/clipen/rendering/production_effects.py +24 -2
- package/src/clipen/rendering/program_components.py +18 -240
- package/src/clipen/rendering/renderer.py +23 -17
- package/src/clipen/rendering/titles.py +29 -12
- package/src/clipen/skills/builtin/SKILL.md +3 -3
- package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
- package/src/clipen/skills/builtin/display.en.json +89 -0
- package/src/clipen/skills/builtin/references/captions.md +12 -0
- package/src/clipen/skills/builtin/references/graphics.md +6 -6
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +9 -4
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +9 -4
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +10 -6
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +10 -6
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +9 -7
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +10 -7
- package/src/clipen/skills/catalog.py +22 -8
- package/src/clipen/skills/package.py +1 -10
- package/src/clipen/terminal.py +344 -0
- package/src/clipen/workspace.py +97 -28
- package/apps/web/dist/assets/index-C3Zw0WaM.js +0 -14
- package/apps/web/dist/assets/index-CaxEZKLc.css +0 -1
- package/src/clipen/editing/resolve_titles.py +0 -291
- package/src/clipen/rendering/program_creator.py +0 -804
- package/src/clipen/rendering/program_identities.py +0 -350
- package/src/clipen/rendering/program_motion.py +0 -186
- package/src/clipen/rendering/program_studio.py +0 -227
- package/src/clipen/rendering/program_styles.py +0 -321
- package/src/clipen/skills/builtin/components.json +0 -133
|
@@ -187,3 +187,65 @@ def frame(repository, project_id, run_id, expected_revision_id, frame_number, co
|
|
|
187
187
|
"scope": "editing_still",
|
|
188
188
|
"component_box": box,
|
|
189
189
|
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def live_page(repository, project_id, run_id, expected_revision_id, component):
|
|
193
|
+
"""A free design as a page the person's browser plays live, with their unsaved changes."""
|
|
194
|
+
from clipen.rendering import custom_components
|
|
195
|
+
|
|
196
|
+
from .workbench import tools_for
|
|
197
|
+
|
|
198
|
+
revision = repository.current_revision(project_id, run_id)
|
|
199
|
+
if revision.revision_id != expected_revision_id:
|
|
200
|
+
raise ProjectError("revision_conflict", "影片已更新,正在重新讀取編輯畫面。", status_code=409)
|
|
201
|
+
draft, profile, _ = tools_for(repository, project_id, run_id)._component_draft(component, checked=False)
|
|
202
|
+
if not custom_components.is_custom(profile):
|
|
203
|
+
raise ProjectError("component_not_live", "這個元件不能在瀏覽器即時播放。", status_code=422)
|
|
204
|
+
return custom_components.live_page(revision.timeline, draft, profile)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def caption_page(repository, project_id, run_id, expected_revision_id, item_id, draft=None):
|
|
208
|
+
"""A caption as its design draws it, as a page the person's browser plays live; draft holds
|
|
209
|
+
a person's unsaved words, delivery and emphasis."""
|
|
210
|
+
from clipen.rendering import custom_components
|
|
211
|
+
|
|
212
|
+
revision = repository.current_revision(project_id, run_id)
|
|
213
|
+
if revision.revision_id != expected_revision_id:
|
|
214
|
+
raise ProjectError("revision_conflict", "影片已更新,正在重新讀取編輯畫面。", status_code=409)
|
|
215
|
+
styles = load_text_styles(repository.projects, project_id)
|
|
216
|
+
item = next(
|
|
217
|
+
(
|
|
218
|
+
i
|
|
219
|
+
for t in revision.timeline.tracks
|
|
220
|
+
if t.track_id == "agent-subtitles"
|
|
221
|
+
for i in t.items
|
|
222
|
+
if i.item_id == item_id
|
|
223
|
+
),
|
|
224
|
+
None,
|
|
225
|
+
)
|
|
226
|
+
profile = styles.get(item.style_id, {}) if item is not None else {}
|
|
227
|
+
if item is not None and draft:
|
|
228
|
+
from .workbench import tools_for
|
|
229
|
+
|
|
230
|
+
item, edited = tools_for(repository, project_id, run_id)._caption_draft({**draft, "element_id": item_id})
|
|
231
|
+
profile = edited or profile
|
|
232
|
+
design = styles.get(profile.get("design") or "")
|
|
233
|
+
if design is None:
|
|
234
|
+
raise ProjectError("caption_not_live", "這句字幕不是 AI 設計的樣式,不能即時播放。", status_code=422)
|
|
235
|
+
page = custom_components.caption_profile(
|
|
236
|
+
design, item.text, profile.get("emphasis", ()), profile.get("delivery", "dialogue")
|
|
237
|
+
)
|
|
238
|
+
return custom_components.live_page(revision.timeline, item, page)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def kept_cut(repository, project_id, run_id, expected_revision_id):
|
|
242
|
+
"""The film without its text layer, as the last render left it, to play under a live design."""
|
|
243
|
+
revision = repository.current_revision(project_id, run_id)
|
|
244
|
+
if revision.revision_id != expected_revision_id:
|
|
245
|
+
raise ProjectError("revision_conflict", "影片已更新,正在重新讀取編輯畫面。", status_code=409)
|
|
246
|
+
path = FfmpegPreviewRenderer(MediaPreviewRepository(repository.projects)).media_cache_path(
|
|
247
|
+
project_id, revision.timeline
|
|
248
|
+
)
|
|
249
|
+
if path is None or not path.is_file():
|
|
250
|
+
raise ProjectError("clip_needs_render", "先輸出一次這一版影片,才能看動態預覽。", status_code=409)
|
|
251
|
+
return path
|
|
@@ -12,10 +12,29 @@ 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
|
-
{"restore_revision", "
|
|
15
|
+
{"restore_revision", "edit_component", "edit_component_look", "remove_program_component", "edit_caption"}
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
def _captions(repository, project_id, timeline):
|
|
20
|
+
"""Every caption a person may correct: its delivery and emphasis, and whether its design plays live."""
|
|
21
|
+
from .production_media import load_text_styles
|
|
22
|
+
|
|
23
|
+
styles = load_text_styles(repository.projects, project_id)
|
|
24
|
+
result = {}
|
|
25
|
+
for track in timeline.tracks:
|
|
26
|
+
if track.track_id != "agent-subtitles":
|
|
27
|
+
continue
|
|
28
|
+
for item in track.items:
|
|
29
|
+
profile = styles.get(item.style_id, {})
|
|
30
|
+
result[item.item_id] = {
|
|
31
|
+
"delivery": profile.get("delivery", "dialogue"),
|
|
32
|
+
"emphasis": profile.get("emphasis", []),
|
|
33
|
+
"live": bool(styles.get(profile.get("design") or "")),
|
|
34
|
+
}
|
|
35
|
+
return result
|
|
36
|
+
|
|
37
|
+
|
|
19
38
|
def idle(repository, project_id, run_id):
|
|
20
39
|
run = repository.get(project_id, run_id)
|
|
21
40
|
latest = repository.latest(project_id)
|
|
@@ -72,6 +91,7 @@ def state(repository, project_id, run_id):
|
|
|
72
91
|
return {
|
|
73
92
|
"revision": revision.to_public(include_timeline=True),
|
|
74
93
|
"component_editing": editing,
|
|
94
|
+
"captions": _captions(repository, project_id, revision.timeline),
|
|
75
95
|
"history": history,
|
|
76
96
|
"ai_usage": usage,
|
|
77
97
|
"references": public_state(intent, revision.timeline),
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""The language Clipen speaks: Traditional Chinese (``zh-TW``) or English (``en``).
|
|
2
|
+
|
|
3
|
+
Chinese is the source text everywhere. A string shown to people is written ``tr("中文", "English")``
|
|
4
|
+
where it is used; error messages keep their Chinese text and find their English in
|
|
5
|
+
:mod:`clipen.locale_en`, keyed by that text, so a raise site needs no change.
|
|
6
|
+
|
|
7
|
+
Each command line entry point speaks the system language for its run: ``CLIPEN_LANG``, then the
|
|
8
|
+
choice saved with ``clipen language``, then the Mac's preferred language, then ``LANG``. Each
|
|
9
|
+
browser request names its own language (``X-Clipen-Locale``), so the page and the terminal may
|
|
10
|
+
differ. The AI's attempt inherits the language of the request that started it through
|
|
11
|
+
``CLIPEN_LANG``.
|
|
12
|
+
|
|
13
|
+
Standard library only: the installer reads it before any dependency exists.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
import os
|
|
20
|
+
import subprocess
|
|
21
|
+
import sys
|
|
22
|
+
from contextlib import contextmanager
|
|
23
|
+
from contextvars import ContextVar
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from typing import Iterator
|
|
26
|
+
|
|
27
|
+
LOCALES = ("zh-TW", "en")
|
|
28
|
+
ENVIRONMENT = "CLIPEN_LANG"
|
|
29
|
+
_SETTINGS = "settings.json"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def normalize(value: object) -> str | None:
|
|
33
|
+
"""``zh``, ``zh_TW.UTF-8``, ``zh-Hant-TW`` and the like read as zh-TW; ``en…`` as en."""
|
|
34
|
+
if not isinstance(value, str):
|
|
35
|
+
return None
|
|
36
|
+
lower = value.strip().lower().replace("_", "-")
|
|
37
|
+
if lower.startswith("zh"):
|
|
38
|
+
return "zh-TW"
|
|
39
|
+
if lower.startswith("en"):
|
|
40
|
+
return "en"
|
|
41
|
+
return None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def data_root() -> Path:
|
|
45
|
+
if sys.platform == "darwin":
|
|
46
|
+
return Path.home() / "Library" / "Application Support" / "Clipen"
|
|
47
|
+
xdg_data = os.environ.get("XDG_DATA_HOME")
|
|
48
|
+
return Path(xdg_data) / "clipen" if xdg_data else Path.home() / ".local" / "share" / "clipen"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def saved_language(root: Path | None = None) -> str | None:
|
|
52
|
+
"""The language saved with ``clipen language``; None means follow the system."""
|
|
53
|
+
try:
|
|
54
|
+
value = json.loads((root or data_root()).joinpath(_SETTINGS).read_text(encoding="utf-8"))
|
|
55
|
+
except (OSError, ValueError):
|
|
56
|
+
return None
|
|
57
|
+
return normalize(value.get("language")) if isinstance(value, dict) else None
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def save_language(language: str | None, root: Path | None = None) -> None:
|
|
61
|
+
"""Save a language, or None to follow the system again."""
|
|
62
|
+
folder = root or data_root()
|
|
63
|
+
path = folder / _SETTINGS
|
|
64
|
+
try:
|
|
65
|
+
settings = json.loads(path.read_text(encoding="utf-8"))
|
|
66
|
+
except (OSError, ValueError):
|
|
67
|
+
settings = {}
|
|
68
|
+
if not isinstance(settings, dict):
|
|
69
|
+
settings = {}
|
|
70
|
+
if language is None:
|
|
71
|
+
settings.pop("language", None)
|
|
72
|
+
else:
|
|
73
|
+
settings["language"] = language
|
|
74
|
+
folder.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
75
|
+
staging = path.with_name(path.name + ".tmp")
|
|
76
|
+
staging.write_text(json.dumps(settings, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
77
|
+
os.replace(staging, path)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _mac_language() -> str | None:
|
|
81
|
+
if sys.platform != "darwin":
|
|
82
|
+
return None
|
|
83
|
+
try:
|
|
84
|
+
result = subprocess.run(
|
|
85
|
+
["/usr/bin/defaults", "read", "-g", "AppleLanguages"],
|
|
86
|
+
capture_output=True,
|
|
87
|
+
text=True,
|
|
88
|
+
timeout=2,
|
|
89
|
+
check=False,
|
|
90
|
+
)
|
|
91
|
+
except (OSError, subprocess.SubprocessError):
|
|
92
|
+
return None
|
|
93
|
+
# The list prints as ( "en-TW", "zh-Hant-TW" ); the first one Clipen speaks wins.
|
|
94
|
+
for entry in result.stdout.replace("(", " ").replace(")", " ").split(","):
|
|
95
|
+
found = normalize(entry.strip().strip('"'))
|
|
96
|
+
if found:
|
|
97
|
+
return found
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def system_language() -> str:
|
|
102
|
+
"""The language this process speaks when nothing more specific asks for one."""
|
|
103
|
+
for value in (os.environ.get(ENVIRONMENT), saved_language()):
|
|
104
|
+
found = normalize(value)
|
|
105
|
+
if found:
|
|
106
|
+
return found
|
|
107
|
+
# A Terminal often says en_US.UTF-8 whatever the person reads, so the Mac's own setting comes first.
|
|
108
|
+
found = _mac_language()
|
|
109
|
+
if found:
|
|
110
|
+
return found
|
|
111
|
+
for name in ("LC_ALL", "LC_MESSAGES", "LANG"):
|
|
112
|
+
found = normalize(os.environ.get(name))
|
|
113
|
+
if found:
|
|
114
|
+
return found
|
|
115
|
+
return "en"
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# Chinese unless something asks otherwise: an entry point speaking the system language for its
|
|
119
|
+
# run, or a request naming its own. Library code never guesses, so tests read the same anywhere.
|
|
120
|
+
_current: ContextVar[str] = ContextVar("clipen_locale", default="zh-TW")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def current() -> str:
|
|
124
|
+
return _current.get()
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def english() -> bool:
|
|
128
|
+
return current() == "en"
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@contextmanager
|
|
132
|
+
def speaking(language: str | None) -> Iterator[None]:
|
|
133
|
+
"""Speak this language inside the block (for one request, say); None keeps the current one."""
|
|
134
|
+
token = _current.set(normalize(language) or current())
|
|
135
|
+
try:
|
|
136
|
+
yield
|
|
137
|
+
finally:
|
|
138
|
+
_current.reset(token)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def tr(zh: str, en: str | None = None) -> str:
|
|
142
|
+
"""The text in the current language. Without English given, the catalog is asked."""
|
|
143
|
+
if current() != "en":
|
|
144
|
+
return zh
|
|
145
|
+
if en is not None:
|
|
146
|
+
return en
|
|
147
|
+
from clipen.locale_en import MESSAGES, PATTERNS
|
|
148
|
+
|
|
149
|
+
if zh in MESSAGES:
|
|
150
|
+
return MESSAGES[zh]
|
|
151
|
+
for pattern, english_text in PATTERNS:
|
|
152
|
+
found = pattern.fullmatch(zh)
|
|
153
|
+
if found:
|
|
154
|
+
return english_text.format(*found.groups())
|
|
155
|
+
return zh
|