@clipen/clipen-cli 1.0.9 → 1.1.0

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 (53) hide show
  1. package/README.md +53 -43
  2. package/README.zh-TW.md +99 -0
  3. package/apps/web/dist/assets/index-BHFCflzf.js +15 -0
  4. package/apps/web/dist/assets/index-BtenOBwP.css +1 -0
  5. package/apps/web/dist/favicon.svg +1 -1
  6. package/apps/web/dist/index.html +2 -2
  7. package/bin/clipen.js +4 -2
  8. package/package.json +2 -2
  9. package/pyproject.toml +1 -1
  10. package/src/clipen/__init__.py +1 -1
  11. package/src/clipen/annotations/suggestions.py +1 -1
  12. package/src/clipen/bootstrap.py +70 -15
  13. package/src/clipen/cli.py +4 -1
  14. package/src/clipen/controller/app.py +102 -1
  15. package/src/clipen/controller/server.py +14 -6
  16. package/src/clipen/editing/agent_repository.py +29 -3
  17. package/src/clipen/editing/agent_tools.py +1 -0
  18. package/src/clipen/editing/aspect.py +27 -0
  19. package/src/clipen/editing/production_catalog.py +10 -3
  20. package/src/clipen/editing/production_media.py +1 -1
  21. package/src/clipen/editing/production_preview.py +7 -0
  22. package/src/clipen/editing/production_tools.py +7 -2
  23. package/src/clipen/editing/skill_tools.py +8 -0
  24. package/src/clipen/editing/slip.py +109 -0
  25. package/src/clipen/editing/tool_receipts.py +1 -0
  26. package/src/clipen/editing/versions.py +2 -0
  27. package/src/clipen/editing/visual_preview.py +11 -3
  28. package/src/clipen/editing/workbench.py +33 -1
  29. package/src/clipen/locale_en.py +18 -0
  30. package/src/clipen/mcp_editing/server.py +3 -1
  31. package/src/clipen/media/discovery.py +2 -2
  32. package/src/clipen/media/preview.py +5 -0
  33. package/src/clipen/media/storage.py +5 -2
  34. package/src/clipen/projects/models.py +2 -0
  35. package/src/clipen/projects/storage.py +84 -4
  36. package/src/clipen/providers/account.py +37 -6
  37. package/src/clipen/providers/claude.py +5 -3
  38. package/src/clipen/providers/claude_editing.py +5 -6
  39. package/src/clipen/providers/codex.py +19 -7
  40. package/src/clipen/providers/codex_editing.py +2 -1
  41. package/src/clipen/providers/editing_agent.py +24 -2
  42. package/src/clipen/providers/model_selection.py +67 -0
  43. package/src/clipen/rendering/cover.py +1 -1
  44. package/src/clipen/rendering/program_subtitles.py +3 -1
  45. package/src/clipen/rendering/renderer.py +13 -3
  46. package/src/clipen/skills/builtin/references/graphics.md +1 -1
  47. package/src/clipen/skills/builtin/templates.json +9 -0
  48. package/src/clipen/workspace.py +21 -0
  49. package/apps/web/dist/assets/index-DPgSvXZ1.js +0 -15
  50. package/apps/web/dist/assets/index-DmPWV61v.css +0 -1
  51. package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +0 -38
  52. package/src/clipen/editing/REFACTOR_DESIGN.md +0 -241
  53. package/src/clipen/editing/REFACTOR_HANDOFF.md +0 -73
@@ -0,0 +1,67 @@
1
+ """Clipen's local model override, stored independently for each provider."""
2
+
3
+ import fcntl
4
+ import os
5
+ import re
6
+ import tempfile
7
+ from contextlib import contextmanager
8
+ from pathlib import Path
9
+
10
+ CLAUDE_MODELS = {"sonnet": "Sonnet", "opus": "Opus", "haiku": "Haiku"}
11
+ _MODEL_ID = re.compile(r"[A-Za-z0-9][A-Za-z0-9._:\[\]-]{0,127}")
12
+
13
+
14
+ def valid_model_id(value: object) -> bool:
15
+ return isinstance(value, str) and _MODEL_ID.fullmatch(value) is not None
16
+
17
+
18
+ def selected_model(root: Path, provider: str) -> str | None:
19
+ path = root / f"{provider}-model"
20
+ try:
21
+ if path.is_symlink() or path.stat().st_size > 128:
22
+ return None
23
+ value = path.read_text(encoding="utf-8")
24
+ except (OSError, UnicodeError):
25
+ return None
26
+ return value if valid_model_id(value) else None
27
+
28
+
29
+ @contextmanager
30
+ def model_lock(root: Path, *, exclusive: bool = False):
31
+ # A shared lock covers each AI invocation, including nested evidence calls.
32
+ flags = os.O_RDWR | os.O_CREAT | getattr(os, "O_NOFOLLOW", 0)
33
+ descriptor = os.open(root / ".model-selection.lock", flags, 0o600)
34
+ try:
35
+ operation = fcntl.LOCK_EX | fcntl.LOCK_NB if exclusive else fcntl.LOCK_SH
36
+ fcntl.flock(descriptor, operation)
37
+ yield
38
+ finally:
39
+ os.close(descriptor)
40
+
41
+
42
+ def model_selection_locked(root: Path) -> bool:
43
+ try:
44
+ with model_lock(root, exclusive=True):
45
+ return False
46
+ except BlockingIOError:
47
+ return True
48
+
49
+
50
+ def save_model(root: Path, provider: str, model: str | None) -> None:
51
+ with model_lock(root, exclusive=True):
52
+ _write_model(root, provider, model)
53
+
54
+
55
+ def _write_model(root: Path, provider: str, model: str | None) -> None:
56
+ path = root / f"{provider}-model"
57
+ if model is None:
58
+ path.unlink(missing_ok=True)
59
+ return
60
+ with tempfile.NamedTemporaryFile(dir=root, mode="w", encoding="utf-8", delete=False) as file:
61
+ temporary = Path(file.name)
62
+ try:
63
+ file.write(model)
64
+ file.close()
65
+ os.replace(temporary, path)
66
+ finally:
67
+ temporary.unlink(missing_ok=True)
@@ -71,7 +71,7 @@ class ProjectCoverRepository:
71
71
  videos = database.execute(
72
72
  "SELECT versions.version_id FROM asset_versions AS versions "
73
73
  "JOIN assets ON assets.asset_id=versions.asset_id "
74
- "WHERE assets.project_id=? AND assets.role='source' AND versions.probe_status='ready' "
74
+ "WHERE assets.project_id=? AND assets.role IN ('source','added') AND versions.probe_status='ready' "
75
75
  "AND EXISTS(SELECT 1 FROM media_streams AS streams "
76
76
  "WHERE streams.version_id=versions.version_id AND streams.kind='video') "
77
77
  "ORDER BY assets.relative_path, versions.created_at DESC LIMIT ?",
@@ -56,7 +56,9 @@ def draw_program_subtitle(draw, font_path, timeline, item, profile, relative_fra
56
56
  opacity = 255 if item.duration_frames - relative > 2 else 180
57
57
  stroke = max(2, round(size * 0.095))
58
58
  line_height = round(size * 1.35)
59
- baseline = round(timeline.height * 0.90) - (len(lines) - 1) * line_height
59
+ # A tall film is watched in Reels, Shorts and TikTok, whose buttons and captions cover its lowest fifth.
60
+ low = 0.78 if timeline.height > timeline.width * 1.5 else 0.90
61
+ baseline = round(timeline.height * low) - (len(lines) - 1) * line_height
60
62
  offset = 0
61
63
  for line in lines:
62
64
  x = (timeline.width - draw.textlength(line, font=font)) / 2
@@ -258,9 +258,7 @@ class FfmpegPreviewRenderer:
258
258
  base_label = f"vbase{len(video_labels)}"
259
259
  filters.append(
260
260
  f"[{input_index}:{stream}]trim=duration={duration},setpts=PTS-STARTPTS,"
261
- f"scale={timeline.width}:{timeline.height}:"
262
- "force_original_aspect_ratio=decrease,"
263
- f"pad={timeline.width}:{timeline.height}:(ow-iw)/2:(oh-ih)/2,"
261
+ f"{self.fill_filter(item, timeline)},"
264
262
  f"fps={timeline.frame_rate.numerator}/"
265
263
  f"{timeline.frame_rate.denominator}[{base_label}]"
266
264
  )
@@ -607,6 +605,18 @@ class FfmpegPreviewRenderer:
607
605
  if code != 0 or not output.is_file() or output.stat().st_size < 1:
608
606
  raise PreviewRenderError("ffmpeg_render_failed")
609
607
 
608
+ @staticmethod
609
+ def fill_filter(item: MediaClip, timeline: EditTimeline) -> str:
610
+ """Scale footage to cover the film's frame and crop the rest: footage of another shape (a landscape
611
+ clip in a vertical film) keeps the part the shot's reframe points at, the middle unless the AI chose."""
612
+ frame = next((e.parameters for e in item.effects if e.effect_id == "video.reframe"), {})
613
+ x = min(1.0, max(0.0, float(frame.get("x", 0.5))))
614
+ y = min(1.0, max(0.0, float(frame.get("y", 0.5))))
615
+ return (
616
+ f"scale={timeline.width}:{timeline.height}:force_original_aspect_ratio=increase,"
617
+ f"crop={timeline.width}:{timeline.height}:(iw-ow)*{x:.4f}:(ih-oh)*{y:.4f},setsar=1"
618
+ )
619
+
610
620
  @staticmethod
611
621
  def _video_effect_filters(item: MediaClip, timeline: EditTimeline) -> str:
612
622
  """Map allowlisted semantic effects to bounded FFmpeg video filters."""
@@ -37,7 +37,7 @@
37
37
 
38
38
  ## 寫法
39
39
 
40
- - 頁面就是整個畫面(window.clipen.width × height,例如 1920×1080)。只畫元件本身,其餘保持透明,讓素材透出來。用 vw/vh 或依 window.clipen 計算尺寸,不同解析度才會一致。
40
+ - 頁面就是整個畫面(window.clipen.width × height,依影片比例而定,例如 16:9 是 1920×1080、9:16 是 1080×1920)。只畫元件本身,其餘保持透明,讓素材透出來。用 vw/vh 或依 window.clipen 計算尺寸,不同解析度才會一致。
41
41
  - 時間由 Clipen 控制:CSS 動畫與 Web Animations 會逐格精準播放;用程式畫的話,定義 `window.clipenFrame = (frame, seconds) => {...}`,在裡面畫出那一格。requestAnimationFrame 迴圈、計時器與真實時鐘不會前進。第 0 格是元件出現的第一格,window.clipen 也提供 fps 與 durationFrames。
42
42
  - 沒有網路:圖片與圖形請內嵌(data: URL、inline SVG)。
43
43
  - 字型完全自由:用字型名稱就能用(`font-family: '名稱'`)。可用的有這台 Mac 安裝的所有字型、Clipen 內附的字型(中文手寫 Clipen Chenyu、楷書筆意 Clipen Iansui;日文手寫 Yusei Magic、Yomogi、Zen Kurenaido、Hachi Maru Pop;日文標題 Dela Gothic One、RocknRoll One、Zen Maru Gothic;英文 Bebas Neue、Anton、Caveat、Playfair Display),以及 Google Fonts 上任何開源字型:先用 get_font 取得(例如 Noto Serif TC、LXGW WenKai TC),之後就能用名稱。用外觀時寫成 `var(--look-font-鍵名)`,缺字會整組換成同感覺且字齊全的字型。選字型前確認它有你要顯示的每個字,繁體中文要選有繁體字的字型。
@@ -6,6 +6,7 @@
6
6
  "description": "第一人稱帶觀眾走一趟:出發、路上、到了、感想。",
7
7
  "visual_style_id": "tpl-travel-vlog",
8
8
  "font_style_id": "handnote-tw",
9
+ "aspect_ratio": "16:9",
9
10
  "editorial_direction": "跟著你的行程走,保留路上真實的對話與反應;地點、交通與花費在需要時才標出來。",
10
11
  "design_direction": "手札體描邊標題、膠帶風格的「地點|英文」小標,好笑或驚訝的瞬間才用黃色貼圖字。",
11
12
  "music_direction": "輕快的木吉他或 lo-fi 節拍,說話時退到背景。",
@@ -42,6 +43,7 @@
42
43
  "description": "從包裝、內容物到第一印象,讓觀眾知道買到什麼。",
43
44
  "visual_style_id": "tpl-product-unboxing",
44
45
  "font_style_id": "variety-tw",
46
+ "aspect_ratio": "16:9",
45
47
  "editorial_direction": "依開箱順序:外盒、配件、本體、第一次使用;規格與價格只用素材或使用者提供的資訊。",
46
48
  "design_direction": "斜切色塊大標開場,規格用黑底標籤貼在產品旁邊,真心驚訝時才用爆炸星形反應字。",
47
49
  "music_direction": "乾淨的電子節拍,開箱與說明時降低音量。",
@@ -72,6 +74,7 @@
72
74
  "description": "把整趟旅程濃縮成 3 分鐘內的精華,畫面與音樂為主。",
73
75
  "visual_style_id": "tpl-travel-highlight",
74
76
  "font_style_id": "cinematic-tw",
77
+ "aspect_ratio": "16:9",
75
78
  "editorial_direction": "挑整趟最好看、最有代表性的瞬間,跟著音樂節奏剪;說話只留最有感的一兩句。",
76
79
  "design_direction": "寬字距宋體標題與細線地點小標,不用貼圖,全部緩慢淡入,畫面盡量留給風景。",
77
80
  "music_direction": "有起伏的配樂主導節奏,剪點跟著拍子。",
@@ -102,6 +105,7 @@
102
105
  "description": "帶觀眾吃一家店:為什麼來、點了什麼、第一口的感想。",
103
106
  "visual_style_id": "tpl-food-review",
104
107
  "font_style_id": "rounded-tw",
108
+ "aspect_ratio": "16:9",
105
109
  "editorial_direction": "交代來的理由與點了什麼,第一口和真實反應完整保留;價格與店名要有依據。",
106
110
  "design_direction": "圓體膠囊店名、價格吊牌貼在食物旁邊,真心好吃或驚訝時才用對話框反應。",
107
111
  "music_direction": "輕快節拍,吃東西與說感想時降低。",
@@ -138,6 +142,7 @@
138
142
  "description": "記錄一天裡發生的小事,像跟朋友聊天。",
139
143
  "visual_style_id": "tpl-daily-vlog",
140
144
  "font_style_id": "pen-tw",
145
+ "aspect_ratio": "16:9",
141
146
  "editorial_direction": "依一天的時間順序,留下有趣的對話與小事;空景和移動短短帶過。",
142
147
  "design_direction": "翩翩體手寫標題配波浪底線,像寫字一樣出現;反應字可愛但不要太多。",
143
148
  "music_direction": "溫暖的 lo-fi 或木吉他,說話時退到背景。",
@@ -168,6 +173,7 @@
168
173
  "description": "一步一步示範產品怎麼用,讓觀眾看得懂、學得會。",
169
174
  "visual_style_id": "tpl-product-demo",
170
175
  "font_style_id": "interface-tw",
176
+ "aspect_ratio": "16:9",
171
177
  "editorial_direction": "依操作順序分步驟,每一步先說要做什麼,再給清楚的特寫。",
172
178
  "design_direction": "深色介面面板標題、「STEP|步驟」鍵帽小標,直線箭頭指出按鍵與畫面。",
173
179
  "music_direction": "低調的電子節拍,講解時明顯降低。",
@@ -198,6 +204,7 @@
198
204
  "description": "實際用過之後的心得:優點、缺點、適合誰。",
199
205
  "visual_style_id": "tpl-product-review",
200
206
  "font_style_id": "verdict-tw",
207
+ "aspect_ratio": "16:9",
201
208
  "editorial_direction": "先說測了什麼、怎麼測,再分優點與缺點,最後給適合誰的結論;評價只來自素材裡講者實際的使用經驗。",
202
209
  "design_direction": "螢光筆劃重點標題,優點打勾、缺點打叉逐項標示,結論用印章字。",
203
210
  "music_direction": "穩定的節拍,說明與比較時降低。",
@@ -228,6 +235,7 @@
228
235
  "description": "婚禮、聚會、展覽的重點回顧,保留現場的氣氛。",
229
236
  "visual_style_id": "tpl-event-recap",
230
237
  "font_style_id": "ceremony-tw",
238
+ "aspect_ratio": "16:9",
231
239
  "editorial_direction": "依活動流程挑重點時刻:開場、主要時刻、大家的反應與收尾;致詞或誓詞保留完整的關鍵句。",
232
240
  "design_direction": "楷書金色標題配細線、時間地點小標,人物名字加細底線,全部典雅淡入。",
233
241
  "music_direction": "溫暖的鋼琴或弦樂,致詞時停或大幅降低。",
@@ -258,6 +266,7 @@
258
266
  "description": "直式 30–60 秒的精華短片,第一秒就要抓住目光。",
259
267
  "visual_style_id": "tpl-shorts-highlight",
260
268
  "font_style_id": "variety-tw",
269
+ "aspect_ratio": "9:16",
261
270
  "editorial_direction": "開頭直接放最好笑或最驚人的瞬間,接著快速交代來龍去脈;每 2–3 秒要有新畫面或新資訊。",
262
271
  "design_direction": "直式紅黑雙描邊大字、螢光色塊小標,重點字跟著台詞跳出,字幕放大。",
263
272
  "music_direction": "節奏明快的配樂,剪點跟著拍子。",
@@ -155,6 +155,27 @@ def prepare_workspace(current_directory: Path) -> WorkspacePaths:
155
155
  )
156
156
 
157
157
 
158
+ def remember_workspace(instance_root: Path, workspace: WorkspacePaths) -> None:
159
+ """Note where this workspace lives, so a later Clipen can list the workspaces it has opened.
160
+
161
+ Best effort: the record only helps find workspaces again, so failing to write it never stops Clipen."""
162
+ try:
163
+ instance_root.mkdir(mode=0o700, parents=True, exist_ok=True)
164
+ if instance_root.is_symlink() or not instance_root.is_dir():
165
+ return
166
+ _atomic_json(
167
+ instance_root / "workspace.json",
168
+ {
169
+ "schema": _WORKSPACE_SCHEMA,
170
+ "workspace_id": workspace.workspace_id,
171
+ "path": str(workspace.root),
172
+ "last_opened_at": _utc_now(),
173
+ },
174
+ )
175
+ except OSError:
176
+ pass
177
+
178
+
158
179
  def _read_project(database: Path) -> tuple:
159
180
  """The integrity check, schema version and project id, read without changing the project.
160
181