@remixmate/cli 0.9.58 → 0.9.59

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "version": "0.9.58",
4
- "generatedAt": "2026-09-29T10:20:23.290Z",
3
+ "version": "0.9.59",
4
+ "generatedAt": "2026-09-29T12:43:37.496Z",
5
5
  "skills": [
6
6
  {
7
7
  "id": "doc-parse",
@@ -82,7 +82,7 @@
82
82
  "tier": "orchestration",
83
83
  "category": "consuming",
84
84
  "title": "Jianying (CapCut) Draft Export",
85
- "summary": "Jianying (CapCut) draft export: package asset URLs into a draft ZIP that Jianying can import. Supports automatic conversion from a RenderPlan.",
85
+ "summary": "Jianying (CapCut) draft export: package asset URLs into a draft ZIP that Jianying can import. By default exports the latest prepared render job of the current conversation (no scenes needed).",
86
86
  "triggers": [
87
87
  "Export to Jianying, Jianying draft, package for Jianying, import into Jianying",
88
88
  "Export materials to the Jianying format, generate a Jianying project",
@@ -102,13 +102,17 @@
102
102
  "parameters": {
103
103
  "type": "object",
104
104
  "properties": {
105
+ "from_job_id": {
106
+ "type": "number",
107
+ "description": "Render job id to export (the `jobId` printed by prepare_video_assets). Omit it together with scenes to export the latest prepared job of the current conversation — preferred, because asset URLs copied from chat history go stale after re-renders"
108
+ },
105
109
  "from_render_plan": {
106
110
  "type": "string",
107
- "description": "Build the draft from a RenderPlan JSON (replaces --scenes)"
111
+ "description": "Build the draft from a local RenderPlan JSON file (local debugging only)"
108
112
  },
109
113
  "scenes": {
110
114
  "type": "string",
111
- "description": "Scene array as JSON (inline string or file path)"
115
+ "description": "Hand-written scene array as JSON — only for assets that never went through prepare_video_assets. Fields per scene: imageUrl | videoUrl (one required), duration (seconds, required), audioUrl, audioDuration, subtitleText, textLayers, width, height. Any other field (text, image, audio…) is rejected"
112
116
  },
113
117
  "title": {
114
118
  "type": "string",
@@ -128,15 +132,15 @@
128
132
  "mac",
129
133
  "windows"
130
134
  ],
131
- "description": "Draft-root preset"
135
+ "description": "OS of the computer that will open the draft"
132
136
  },
133
137
  "draft_root_path": {
134
138
  "type": "string",
135
- "description": "Explicit Jianying draft root path (overrides --system)"
139
+ "description": "Absolute Jianying draft root on the user's computer (Jianying → Settings → Draft location), e.g. /Users/<username>/Movies/JianyingPro/User Data/Projects/com.lveditor.draft or C:/Users/<username>/AppData/Local/JianyingPro/User Data/Projects/com.lveditor.draft. Required when the agent runs on a server; never guess the username, ask the user"
136
140
  },
137
141
  "no_download": {
138
142
  "type": "boolean",
139
- "description": "Do not download the ZIP; print the URL only"
143
+ "description": "Do not keep a local copy of the ZIP; print the download URL only"
140
144
  },
141
145
  "output": {
142
146
  "type": "string",
@@ -147,7 +151,8 @@
147
151
  },
148
152
  "ui": {
149
153
  "primary": [
150
- "system"
154
+ "system",
155
+ "draft_root_path"
151
156
  ],
152
157
  "advanced": [],
153
158
  "hidden": [
@@ -155,9 +160,9 @@
155
160
  "width",
156
161
  "height",
157
162
  "output",
163
+ "from_job_id",
158
164
  "from_render_plan",
159
165
  "scenes",
160
- "draft_root_path",
161
166
  "no_download"
162
167
  ]
163
168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remixmate/cli",
3
- "version": "0.9.58",
3
+ "version": "0.9.59",
4
4
  "description": "AI media generation skills for Claude Code / Codex — 12 skills covering image, video, voice, digital human, web screenshot, web recording, script, template registry, rendering, Jianying export, and video deconstruction.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -44,24 +44,37 @@ There is no dedicated env file; the **process environment** variables of the cal
44
44
 
45
45
  1. **Script path**: read the system-injected `Base directory for this skill: <path>` as `<SkillDir>`. Every command below uses `<SkillDir>/scripts/gen_jianying_draft.py`; never hard-code paths.
46
46
  2. **Pick the input form**:
47
- - **Form A (recommended)**: `--from-job-id` — load the RenderPlan from the database without passing a file path (safe for multi-user concurrent flows).
48
- - **Form B (fallback, single-user / local debugging)**: `--from-render-plan` — read a local `render-plan.json`.
49
- 3. **Draft root**: by default the `--system mac` preset resolves the target Jianying draft directory; switch with `--system windows`, or override with `--draft-root-path`. This path is sent to the API as `draftRootPath` and embedded in the draft files.
50
- 4. **By default download the ZIP** locally (`--output` sets the path); pass `--no-download` if you only need the download URL (this flag is ignored when scenes contain `textLayers` / `subtitleText`).
47
+ - **Default (recommended)**: pass **no** `--scenes` / `--from-job-id`. When `CONVERSATION_ID` is set (always true inside the agent), the script exports the latest render job of this conversation that has prepared assets — i.e. whatever the user last re-rendered, including voices or images they changed in the editor.
48
+ - **`--from-job-id <jobId>`**: export a specific earlier job.
49
+ - **`--scenes`**: only for assets that never went through `prepare_video_assets`. **Never** rebuild scenes from URLs in the chat history: earlier tables go stale after every re-render, and you cannot see previous tool results.
50
+ - `--from-render-plan`: local debugging only.
51
+ 3. **Draft root**: pass the user's real Jianying draft directory via `--draft-root-path` (an absolute path on **the user's computer**). It is sent to the API as `draftRootPath` and embedded in the draft files, so a wrong path makes Jianying lose the media. If the user already gave a path (e.g. a `草稿目录` / `Draft folder` line in their message), use it verbatim. Otherwise ask for it — never guess the username. The path is only optional when this script runs on the user's own computer of the `--system` OS; anywhere else (e.g. a server-side agent) the script exits with an error asking for it.
52
+ 4. **Download URL**: pass `--no-download` in the agent (no local copy is kept). When subtitles / textLayers need styling the script still fetches the ZIP to a temp file, styles it, uploads it back and prints the URL of the **styled** ZIP. The printed `download URL:` is a signed link that expires after 7 days — give it to the user exactly as printed, including the whole `?Expires=…&Signature=…` query; never strip or re-encode it.
51
53
  5. **Async job**: draft generation is async (assets must be downloaded and packaged); the script polls until completion.
54
+ 6. **Report what is actually in the draft**: repeat the `📦 Draft contents` block (scene count, narration audio N/N, subtitles N/N, draft root). Don't claim subtitles or a particular voice version the block doesn't show.
52
55
 
53
- ### Load the RenderPlan from the database (recommended, multi-user safe)
56
+ ### Export the latest prepared job of this conversation (default)
54
57
 
55
- When `prepare_video_assets` was invoked with `--save-job` (default) and persisted the RenderPlan, load it directly via `--from-job-id` — no file path required:
58
+ ```bash
59
+ python3 <SkillDir>/scripts/gen_jianying_draft.py \
60
+ --system mac \
61
+ --draft-root-path "/Users/<username>/Movies/JianyingPro/User Data/Projects/com.lveditor.draft" \
62
+ --no-download
63
+ ```
64
+
65
+ - Requires `PRIV_TOKEN` and `CONVERSATION_ID` (both injected by the agent). The title defaults to the plan's title.
66
+ - Fails with a clear message if the conversation has no prepared job yet — run `prepare_video_assets` first.
67
+
68
+ ### Load a specific job from the database
56
69
 
57
70
  ```bash
58
71
  python3 <SkillDir>/scripts/gen_jianying_draft.py \
59
72
  --from-job-id <jobId> \
60
- --title "My Video"
73
+ --system mac \
74
+ --draft-root-path "/Users/<username>/Movies/JianyingPro/User Data/Projects/com.lveditor.draft"
61
75
  ```
62
76
 
63
77
  - `<jobId>` is the task id printed by `prepare_video_assets` (the line `📦 render job jobId: N`).
64
- - Requires the `PRIV_TOKEN` and `MM_BACKEND_API_URL` env vars.
65
78
 
66
79
  ### Read from a RenderPlan file (fallback, single-user / local debugging)
67
80
 
@@ -145,23 +158,26 @@ python3 <SkillDir>/scripts/gen_jianying_draft.py \
145
158
 
146
159
  ### Specify the Jianying draft root
147
160
 
148
- Default is `--system mac`. Switch to the Windows preset:
161
+ macOS:
149
162
 
150
163
  ```bash
151
164
  python3 <SkillDir>/scripts/gen_jianying_draft.py \
152
- --title "Win draft" --system windows \
165
+ --title "Mac draft" --system mac \
166
+ --draft-root-path "/Users/<username>/Movies/JianyingPro/User Data/Projects/com.lveditor.draft" \
153
167
  --scenes '[{"videoUrl":"https://example.com/v.mp4","duration":5}]'
154
168
  ```
155
169
 
156
- Explicitly specify a path (overrides `--system`):
170
+ Windows:
157
171
 
158
172
  ```bash
159
173
  python3 <SkillDir>/scripts/gen_jianying_draft.py \
160
- --title "Custom path" \
161
- --draft-root-path "/Users/yourname/Movies/JianyingPro/User Data/Projects/com.lveditor.draft" \
174
+ --title "Win draft" --system windows \
175
+ --draft-root-path "C:/Users/<username>/AppData/Local/JianyingPro/User Data/Projects/com.lveditor.draft" \
162
176
  --scenes '[{"videoUrl":"https://example.com/v.mp4","duration":5}]'
163
177
  ```
164
178
 
179
+ `<username>` is a placeholder for the user's real value — the script rejects paths that still contain `<...>`, start with `~`, contain `%VAR%` / `$VAR`, or are not absolute. Users who moved their draft folder can copy the exact path from Jianying → Settings → Draft location.
180
+
165
181
  ### Only print the download URL (no file write)
166
182
 
167
183
  ```bash
@@ -170,7 +186,7 @@ python3 <SkillDir>/scripts/gen_jianying_draft.py \
170
186
  --scenes '[{"videoUrl":"https://example.com/v.mp4","duration":5}]'
171
187
  ```
172
188
 
173
- 6. **Show the result**: by default the script prints the download URL and saves the ZIP to `--output`. At the end it prints "extract into the draft root → restart Jianying" to import. With `--no-download`, only the download URL is printed.
189
+ **Show the result**: the script prints `📦 Draft contents`, the signed `download URL:` and the import steps. Without `--no-download` it also keeps the ZIP at `--output`.
174
190
 
175
191
  See every option: `python3 <SkillDir>/scripts/gen_jianying_draft.py --help`.
176
192
 
@@ -178,31 +194,31 @@ See every option: `python3 <SkillDir>/scripts/gen_jianying_draft.py --help`.
178
194
 
179
195
  | Flag | Description | Default |
180
196
  |------|-------------|---------|
181
- | `--from-render-plan` | Convert from a RenderPlan JSON automatically (replaces `--scenes`). | — |
182
- | `--from-job-id` | Load the RenderPlan from the database (pass a jobId, replaces `--from-render-plan`). | — |
183
- | `--scenes` | Scenes JSON (inline string or file path). | required (unless using `--from-render-plan` or `--from-job-id`) |
184
- | `--title` | Draft title. | required (optional when using `--from-render-plan`) |
197
+ | `--from-job-id` | Load the RenderPlan of a specific job from the database. | latest prepared job of `CONVERSATION_ID` when no source is given |
198
+ | `--from-render-plan` | Convert a local RenderPlan JSON (local debugging). | — |
199
+ | `--scenes` | Hand-written scenes JSON (inline string or file path); unknown fields are rejected. | — |
200
+ | `--title` | Draft title. | plan title (required with `--scenes`) |
185
201
  | `--width` | Canvas width in pixels. | `1080` |
186
202
  | `--height` | Canvas height in pixels. | `1920` |
187
203
  | `--draft-name` | Jianying draft name. | same as title |
188
- | `--system` | Draft-root preset: `mac` / `windows`. | `mac` |
189
- | `--draft-root-path` | Explicit Jianying draft root path (overrides `--system`). | resolved from `--system` |
190
- | `--no-download` | Skip the ZIP download; print only the URL (ignored when textLayers / subtitleText is present). | off |
204
+ | `--system` | OS of the computer that will open the draft: `mac` / `windows`. | `mac` |
205
+ | `--draft-root-path` | Absolute Jianying draft root on the user's computer. | required unless the script runs on that computer |
206
+ | `--no-download` | Keep no local copy; print only the (post-processed, signed) URL. | off |
191
207
  | `-o` / `--output` | Download path. | `jianying_draft.zip` |
192
208
  | `--poll-interval` | Polling interval (seconds). | `5` |
193
209
  | `--max-wait` | Maximum wait time (seconds). | `300` |
194
210
  | `--private-token` | Override the token. | see table above |
195
211
 
196
- ### Draft-root presets
212
+ ### Default draft roots
197
213
 
198
- | `--system` | Resolved path |
199
- |------------|---------------|
200
- | `mac` | `~/Movies/JianyingPro/User Data/Projects/com.lveditor.draft` (`~` expands on the runner machine). |
201
- | `windows` | `%LOCALAPPDATA%/JianyingPro/User Data/Projects/com.lveditor.draft` (literal, not expanded — the target Windows machine resolves it). |
214
+ | `--system` | Jianying default (replace `<username>`) | Derived automatically only when |
215
+ |------------|------------------------------------------|---------------------------------|
216
+ | `mac` | `/Users/<username>/Movies/JianyingPro/User Data/Projects/com.lveditor.draft` | the script runs on macOS |
217
+ | `windows` | `C:/Users/<username>/AppData/Local/JianyingPro/User Data/Projects/com.lveditor.draft` | the script runs on Windows with `LOCALAPPDATA` set |
202
218
 
203
219
  ## Scene JSON shape
204
220
 
205
- Fields supported per scene:
221
+ Fields supported per scene (anything else — e.g. `text`, `image`, `audio` — makes the script exit with the correct field name; `id` is ignored):
206
222
 
207
223
  | Field | Type | Description |
208
224
  |-------|------|-------------|
@@ -240,11 +256,8 @@ When `textLayers` is present the script downloads the ZIP and post-processes `dr
240
256
 
241
257
  ## How to import into Jianying
242
258
 
243
- 1. By default the draft ZIP is saved to `--output` (default `jianying_draft.zip`).
244
- 2. Extract the ZIP into the "draft root" the script prints — i.e. the `draftRootPath` passed to the API:
245
- - mac default: `~/Movies/JianyingPro/User Data/Projects/com.lveditor.draft/`
246
- - windows default: `%LOCALAPPDATA%/JianyingPro/User Data/Projects/com.lveditor.draft/`
247
- - custom: the path passed via `--draft-root-path`
259
+ 1. Download the ZIP from the printed `download URL:` (or use the local `--output` file).
260
+ 2. Extract the ZIP into exactly the draft root that was passed as `--draft-root-path` (the script prints it as `draft root:`). Tell the user that path verbatim — not a generic `~/...` one.
248
261
  3. Start (or restart) Jianying; the draft appears in the project list.
249
262
 
250
263
  > The backend embeds `draftRootPath` into `draft_content.json` / `draft_meta_info.json`. As long as the extraction directory matches the path that was passed in, Jianying resolves the material paths correctly without extra rewrites.
@@ -253,5 +266,8 @@ When `textLayers` is present the script downloads the ZIP and post-processes `dr
253
266
 
254
267
  - **401** / **token missing** (non-OpenClaw): check or set the token via the Feishu link above.
255
268
  - **Business `code != 0`**: read the `msg` printed on stderr.
269
+ - **`unsupported field(s)`**: rename the field as the message says — or better, drop `--scenes` and export the latest job.
270
+ - **`no render job with a saved RenderPlan`**: the conversation has no prepared assets yet; run `prepare_video_assets` first.
271
+ - **`--draft-root-path is required` / `invalid --draft-root-path`**: ask the user for the real path; don't retry with a guessed one.
256
272
  - **Generation timeout**: increase `--max-wait` or retry later.
257
273
  - **Network**: check connectivity and `MM_API_BASE_URL`.
@@ -22,7 +22,9 @@ from __future__ import annotations
22
22
  import argparse
23
23
  import json
24
24
  import os
25
+ import re
25
26
  import sys
27
+ import tempfile
26
28
  import time
27
29
  import urllib.error
28
30
  import urllib.parse
@@ -75,30 +77,87 @@ PILL_SUBTITLE_POSITION_Y = -0.458
75
77
  # 剪映草稿根目录解析
76
78
  # ---------------------------------------------------------------------------
77
79
 
78
- DRAFT_ROOT_PRESETS = {
79
- "mac": "~/Movies/JianyingPro/User Data/Projects/com.lveditor.draft",
80
- # Windows 预设保留字面量 %LOCALAPPDATA%:在 Mac 上执行时不展开,
81
- # 原样传给 API;用户在 Windows 解压时目录会自然匹配。
82
- "windows": "%LOCALAPPDATA%/JianyingPro/User Data/Projects/com.lveditor.draft",
80
+ # 剪映把 draftRootPath 原样写进 draft_meta_info.json(draft_root_path / draft_fold_path),
81
+ # 所以它必须是**用户电脑上**的绝对路径。
82
+ #
83
+ # 2026-09-29 事故:agent 在服务器上跑本脚本,mac 预设 `~/...` 被 expanduser 成
84
+ # `/root/Movies/...` 写进了草稿,用户 Mac 上根本没有这个目录。`~` / `%LOCALAPPDATA%`
85
+ # 只能在「脚本就跑在那台目标电脑上」时展开,其余情况必须由调用方显式给出路径。
86
+ DRAFT_ROOT_SUFFIX = ("JianyingPro", "User Data", "Projects", "com.lveditor.draft")
87
+
88
+ # 报错时给调用方看的路径样例(<username> 要换成用户电脑上的真实用户名)。
89
+ DRAFT_ROOT_TEMPLATES = {
90
+ "mac": "/Users/<username>/Movies/JianyingPro/User Data/Projects/com.lveditor.draft",
91
+ "windows": "C:/Users/<username>/AppData/Local/JianyingPro/User Data/Projects/com.lveditor.draft",
83
92
  }
84
93
 
94
+ _WINDOWS_ABS_PATH = re.compile(r"^[A-Za-z]:[\\/]")
95
+
96
+
97
+ def draft_root_path_error(path: str) -> str:
98
+ """校验显式给出的草稿根目录;合法返回空串,否则返回原因。"""
99
+ if "<" in path or ">" in path:
100
+ return "still contains a placeholder such as <username>; replace it with the real value"
101
+ if path.startswith("~"):
102
+ return "'~' would expand on the machine running this script, not on the user's computer; pass an absolute path"
103
+ if "%" in path or "$" in path:
104
+ return "environment variables are not expanded; pass an absolute path"
105
+ if not (path.startswith("/") or _WINDOWS_ABS_PATH.match(path)):
106
+ return "must be an absolute path (/Users/... on macOS, C:/... on Windows)"
107
+ return ""
108
+
109
+
110
+ def _local_draft_root(system: str) -> str:
111
+ """脚本恰好跑在目标系统上时,按本机环境推出草稿根目录;推不出返回空串。"""
112
+ if system == "mac" and sys.platform == "darwin":
113
+ return os.path.join(os.path.expanduser("~/Movies"), *DRAFT_ROOT_SUFFIX)
114
+ if system == "windows" and os.name == "nt":
115
+ local_app_data = os.environ.get("LOCALAPPDATA", "")
116
+ if local_app_data:
117
+ return os.path.join(local_app_data, *DRAFT_ROOT_SUFFIX)
118
+ return ""
119
+
85
120
 
86
121
  def resolve_draft_root_path(explicit: str, system: str) -> str:
87
122
  """
88
123
  解析剪映草稿根目录,按优先级:
89
- 1. 显式 --draft-root-path(做 expanduser)
90
- 2. --system 预设(mac → expanduser,windows → 字面量)
124
+ 1. 显式 --draft-root-path:原样使用(不做 expanduser),但必须是绝对路径;
125
+ 2. 未给路径且脚本就跑在 --system 指定的系统上:按本机 HOME / LOCALAPPDATA 推出;
126
+ 3. 其余情况(典型是服务端 agent):报错,要求调用方向用户要路径。
91
127
  返回值始终作为 draftRootPath 传给 API。
92
128
  """
93
- if explicit:
94
- return os.path.expanduser(explicit)
95
- preset = DRAFT_ROOT_PRESETS.get(system)
96
- if not preset:
129
+ if system not in DRAFT_ROOT_TEMPLATES:
97
130
  print(f"❌ unsupported --system value: {system} (supported: mac / windows)", file=sys.stderr)
98
131
  sys.exit(1)
99
- if system == "mac":
100
- return os.path.expanduser(preset)
101
- return preset
132
+ template = DRAFT_ROOT_TEMPLATES[system]
133
+
134
+ if explicit:
135
+ path = explicit.strip()
136
+ # 去掉末尾分隔符,但保留 "C:/" 与 "/" 这种根本身。
137
+ while len(path) > 3 and path[-1] in "/\\":
138
+ path = path[:-1]
139
+ reason = draft_root_path_error(path)
140
+ if reason:
141
+ print(f"❌ invalid --draft-root-path {path!r}: {reason}", file=sys.stderr)
142
+ print(f" expected shape on {system}: {template}", file=sys.stderr)
143
+ sys.exit(1)
144
+ return path
145
+
146
+ local = _local_draft_root(system)
147
+ if local:
148
+ return local
149
+
150
+ print(
151
+ f"❌ --draft-root-path is required: this script is not running on the user's {system} computer, "
152
+ f"so the Jianying draft directory cannot be derived here.",
153
+ file=sys.stderr,
154
+ )
155
+ print(f" expected shape: {template}", file=sys.stderr)
156
+ print(
157
+ " Ask the user for the real path (Jianying → Settings → Draft location) and pass it via --draft-root-path.",
158
+ file=sys.stderr,
159
+ )
160
+ sys.exit(1)
102
161
 
103
162
 
104
163
  def resolve_token() -> str:
@@ -456,6 +515,42 @@ def convert_render_plan_to_scenes(render_plan: dict) -> tuple:
456
515
  return scenes, width, height
457
516
 
458
517
 
518
+ # --scenes 里认的字段。后端 JianYingSceneInput 只收前 8 个,textLayers 由本脚本后处理消费。
519
+ SCENE_FIELDS = (
520
+ "videoUrl", "imageUrl", "duration", "width", "height",
521
+ "audioUrl", "audioDuration", "subtitleText", "textLayers",
522
+ )
523
+ # 纯标识、不影响草稿内容的字段:写了也无害,放行。
524
+ SCENE_IGNORED_FIELDS = ("id", "sceneId")
525
+ # 常见误写 → 正确字段名。
526
+ #
527
+ # 2026-09-29 线上会话:模型先写 image/audio 被拦,改成 imageUrl/audioUrl 后却把旁白
528
+ # 写成了 text —— 这个字段以前被静默丢掉,草稿里没有字幕,模型还告诉用户「已包含字幕」。
529
+ # 未知字段一律报错,比静默丢值强。
530
+ SCENE_FIELD_ALIASES = {
531
+ "image": "imageUrl", "img": "imageUrl", "imageURL": "imageUrl", "image_url": "imageUrl",
532
+ "video": "videoUrl", "videoURL": "videoUrl", "video_url": "videoUrl",
533
+ "audio": "audioUrl", "audioURL": "audioUrl", "audio_url": "audioUrl",
534
+ "narration": "subtitleText", "text": "subtitleText", "subtitle": "subtitleText",
535
+ "caption": "subtitleText", "subtitle_text": "subtitleText",
536
+ "audio_duration": "audioDuration",
537
+ }
538
+
539
+
540
+ def unknown_field_error(index: int, scene: dict) -> None:
541
+ """scene 里出现不认识的字段就退出,并指出该用哪个字段名。"""
542
+ unknown = [k for k in scene if k not in SCENE_FIELDS and k not in SCENE_IGNORED_FIELDS]
543
+ if not unknown:
544
+ return
545
+ hints = []
546
+ for key in unknown:
547
+ target = SCENE_FIELD_ALIASES.get(key)
548
+ hints.append(f"'{key}' → use '{target}'" if target else f"'{key}' is not supported")
549
+ print(f"❌ scene {index + 1} has unsupported field(s): {'; '.join(hints)}", file=sys.stderr)
550
+ print(f" supported fields: {', '.join(SCENE_FIELDS)}", file=sys.stderr)
551
+ sys.exit(1)
552
+
553
+
459
554
  def parse_scenes(scenes_arg: str) -> list:
460
555
  """解析 --scenes 参数:支持 inline JSON 字符串或文件路径"""
461
556
  # 尝试作为文件路径读取
@@ -489,6 +584,7 @@ def parse_scenes(scenes_arg: str) -> list:
489
584
  if not isinstance(scene, dict):
490
585
  print(f"❌ scene {i + 1} is malformed: must be an object", file=sys.stderr)
491
586
  sys.exit(1)
587
+ unknown_field_error(i, scene)
492
588
  if not scene.get("videoUrl") and not scene.get("imageUrl"):
493
589
  print(f"❌ scene {i + 1} is missing videoUrl or imageUrl", file=sys.stderr)
494
590
  sys.exit(1)
@@ -626,13 +722,77 @@ def poll_task_status(task_id: str, poll_interval: int = 5, max_wait: int = 300)
626
722
  def _encode_url(raw_url: str) -> str:
627
723
  """对 URL 中的非 ASCII 字符做 percent-encoding(保留已编码部分和合法字符)"""
628
724
  parsed = urllib.parse.urlparse(raw_url)
629
- encoded_path = urllib.parse.quote(parsed.path, safe="/:@!$&'()*+,;=-._~")
725
+ # '%' 必须留在 safe 里:ab-api 返回的地址已经是编码过的(中文文件名 → %E9%A3…),
726
+ # 再编一次会变成 %25E9,对象 key 对不上;带签名的地址还会 SignatureDoesNotMatch。
727
+ encoded_path = urllib.parse.quote(parsed.path, safe="/:@!$&'()*+,;=-._~%")
630
728
  return urllib.parse.urlunparse(parsed._replace(path=encoded_path))
631
729
 
632
730
 
731
+ def _url_without_query(raw_url: str) -> str:
732
+ """日志里只打对象地址:带签名的 query(Signature / OSSAccessKeyId)不进日志。"""
733
+ parsed = urllib.parse.urlparse(raw_url)
734
+ return urllib.parse.urlunparse(parsed._replace(query="", fragment=""))
735
+
736
+
737
+ def upload_draft_zip(zip_path: str, file_name: str) -> str:
738
+ """
739
+ 把后处理过的 ZIP 传回 ab-api(POST /file/uploadJianYingDraft),返回带签名的下载地址。
740
+
741
+ 为什么必须传回:后处理(字幕样式 / textLayers)是在跑脚本的这台机器上做的。
742
+ 服务端 agent 的本地文件用户拿不到,不传回的话用户下载到的仍是后端生成的原始 ZIP,
743
+ 后处理等于白做。
744
+ """
745
+ boundary = "----RemixmateJianYing" + uuid.uuid4().hex
746
+ with open(zip_path, "rb") as f:
747
+ zip_data = f.read()
748
+ # filename 里放 ASCII 占位,真实(可能含中文的)文件名走独立的 fileName 字段,
749
+ # 避免 multipart 头部编码在不同服务端实现间的差异。
750
+ parts = [
751
+ f"--{boundary}".encode(),
752
+ b'Content-Disposition: form-data; name="fileName"',
753
+ b"",
754
+ file_name.encode("utf-8"),
755
+ f"--{boundary}".encode(),
756
+ b'Content-Disposition: form-data; name="file"; filename="draft.zip"',
757
+ b"Content-Type: application/zip",
758
+ b"",
759
+ zip_data,
760
+ f"--{boundary}--".encode(),
761
+ b"",
762
+ ]
763
+ body = b"\r\n".join(parts)
764
+
765
+ print(f"\n⬆️ Uploading post-processed draft ({len(zip_data) / 1024 / 1024:.1f} MB)...")
766
+ req = urllib.request.Request(
767
+ f"{API_BASE_URL}/file/uploadJianYingDraft",
768
+ data=body,
769
+ headers=_build_headers(f"multipart/form-data; boundary={boundary}"),
770
+ method="POST",
771
+ )
772
+ try:
773
+ with urllib.request.urlopen(req, timeout=600) as resp:
774
+ result = json.loads(resp.read().decode("utf-8"))
775
+ except urllib.error.HTTPError as e:
776
+ print(f"❌ draft upload failed (HTTP {e.code})", file=sys.stderr)
777
+ sys.exit(1)
778
+ except (urllib.error.URLError, OSError, ConnectionError) as e:
779
+ print(f"❌ draft upload failed: {e}", file=sys.stderr)
780
+ sys.exit(1)
781
+
782
+ if result.get("code") != 0:
783
+ print(f"❌ draft upload failed: {result.get('msg', 'unknown error')}", file=sys.stderr)
784
+ sys.exit(1)
785
+ url = (result.get("data") or {}).get("downloadUrl", "")
786
+ if not url:
787
+ print("❌ draft upload succeeded but no download URL was returned", file=sys.stderr)
788
+ sys.exit(1)
789
+ print(" ✅ uploaded")
790
+ return url
791
+
792
+
633
793
  def download_zip(download_url: str, output_path: str) -> None:
634
794
  """下载 ZIP 文件到本地"""
635
- print(f"\n⬇️ Downloading draft ZIP: {download_url[:80]}...")
795
+ print(f"\n⬇️ Downloading draft ZIP: {_url_without_query(download_url)}")
636
796
  safe_url = _encode_url(download_url)
637
797
  try:
638
798
  urllib.request.urlretrieve(safe_url, output_path)
@@ -906,6 +1066,39 @@ def has_text_layers(scenes: list) -> bool:
906
1066
  return any(scene.get("textLayers") for scene in scenes)
907
1067
 
908
1068
 
1069
+ def _render_job_client():
1070
+ """
1071
+ 导入共享的 render_job_client(在 skills/template-registry/scripts/,跨 skill 共享
1072
+ Python 的约定位置,render-video 也是这么引的)。
1073
+ """
1074
+ shared = os.path.join(os.path.dirname(__file__), "..", "..", "template-registry", "scripts")
1075
+ if shared not in sys.path:
1076
+ sys.path.insert(0, shared)
1077
+ import render_job_client # noqa: PLC0415 — 路径注入之后才能导入
1078
+
1079
+ return render_job_client
1080
+
1081
+
1082
+ def print_draft_summary(scenes: list, width: int, height: int, draft_root_path: str) -> None:
1083
+ """
1084
+ 打印草稿里**实际**装了什么。
1085
+
1086
+ 调用方(agent)要据此向用户转述,而不是凭自己传了什么去猜——线上会话里模型把
1087
+ 被丢掉的字幕也说成「已包含」。
1088
+ """
1089
+ total = len(scenes)
1090
+ video = sum(1 for s in scenes if s.get("videoUrl"))
1091
+ image = sum(1 for s in scenes if s.get("imageUrl") and not s.get("videoUrl"))
1092
+ audio = sum(1 for s in scenes if s.get("audioUrl"))
1093
+ subtitle = sum(1 for s in scenes if s.get("subtitleText") or s.get("textLayers"))
1094
+ duration = sum(float(s.get("duration") or 0) for s in scenes)
1095
+ print("\n📦 Draft contents:")
1096
+ print(f" scenes: {total} (video {video}, image {image}), total {duration:.1f}s, canvas {width}x{height}")
1097
+ print(f" narration audio: {audio}/{total} scene(s)")
1098
+ print(f" subtitles / text layers: {subtitle}/{total} scene(s)")
1099
+ print(f" draft root written into the draft: {draft_root_path}")
1100
+
1101
+
909
1102
  def main() -> None:
910
1103
  parser = argparse.ArgumentParser(
911
1104
  description="Jianying draft generator — packages asset URLs into a Jianying-importable draft ZIP",
@@ -941,7 +1134,10 @@ Scene fields:
941
1134
  "--from-job-id",
942
1135
  type=int,
943
1136
  default=0,
944
- help="Load the RenderPlan from the database (pass a jobId, replaces --from-render-plan; requires PRIV_TOKEN)",
1137
+ help=(
1138
+ "Load the RenderPlan from the database (pass a jobId; requires PRIV_TOKEN). When no source is given "
1139
+ "and CONVERSATION_ID is set, the latest prepared job of that conversation is used automatically"
1140
+ ),
945
1141
  )
946
1142
  parser.add_argument("--width", type=int, default=1080, help="Canvas width (default 1080)")
947
1143
  parser.add_argument("--height", type=int, default=1920, help="Canvas height (default 1920)")
@@ -950,17 +1146,24 @@ Scene fields:
950
1146
  "--system",
951
1147
  choices=["mac", "windows"],
952
1148
  default="mac",
953
- help="Pick the draft-root preset by OS (default: mac)",
1149
+ help="OS of the computer that will open the draft (default: mac)",
954
1150
  )
955
1151
  parser.add_argument(
956
1152
  "--draft-root-path",
957
1153
  default="",
958
- help="Explicitly specify the Jianying draft root path (overrides the --system preset)",
1154
+ help=(
1155
+ "Absolute Jianying draft root on the user's computer, e.g. "
1156
+ f"{DRAFT_ROOT_TEMPLATES['mac']} or {DRAFT_ROOT_TEMPLATES['windows']}. "
1157
+ "Required unless this script runs on that computer itself; '~' and %%VARS%% are rejected"
1158
+ ),
959
1159
  )
960
1160
  parser.add_argument(
961
1161
  "--no-download",
962
1162
  action="store_true",
963
- help="Skip the ZIP download; only print the download URL (ignored when scenes include textLayers / subtitleText)",
1163
+ help=(
1164
+ "Do not keep a local copy of the ZIP; only print the download URL. When subtitles / textLayers "
1165
+ "need post-processing the ZIP is fetched to a temp file, styled, uploaded back and the temp file removed"
1166
+ ),
964
1167
  )
965
1168
  parser.add_argument("-o", "--output", default=None, help="Download path (default jianying_draft_{timestamp}.zip, prevents multi-user collisions)")
966
1169
  parser.add_argument("--poll-interval", type=int, default=5, help="Polling interval (seconds, default 5)")
@@ -980,22 +1183,38 @@ Scene fields:
980
1183
  print("❌ PrivToken not configured", file=sys.stderr)
981
1184
  sys.exit(1)
982
1185
 
1186
+ conversation_id = os.environ.get("CONVERSATION_ID", "").strip()
1187
+
1188
+ # 没给任何素材来源、但处在一个会话里(ab-agent 会注入 CONVERSATION_ID):
1189
+ # 默认导出这个会话最近一版已准备好素材的任务。
1190
+ if not (args.from_job_id or args.from_render_plan or args.scenes) and conversation_id:
1191
+ rjc = _render_job_client()
1192
+ try:
1193
+ latest = rjc.latest_job(conversation_id, PRIVATE_TOKEN)
1194
+ except RuntimeError as e:
1195
+ print(f"❌ could not find the latest prepared render job of this conversation: {e}", file=sys.stderr)
1196
+ print(" run prepare_video_assets first, or pass --from-job-id / --scenes", file=sys.stderr)
1197
+ sys.exit(1)
1198
+ args.from_job_id = int(latest["jobId"])
1199
+ print(
1200
+ f"📋 using the latest prepared render job of this conversation: "
1201
+ f"jobId={args.from_job_id} (attempt {latest.get('attempt', '?')}, updated {latest.get('updateTime', '?')})"
1202
+ )
1203
+ elif args.scenes and conversation_id:
1204
+ # 手写 scenes 时模型只能从聊天记录里拼素材 URL,而多轮之间它看不到之前的工具结果,
1205
+ # 很容易拼出过期的旧版素材(线上会话里就是把用户改过的 v3 配音换回了 v1)。
1206
+ print(
1207
+ "⚠️ --scenes was hand-written; omit --scenes/--from-job-id to export the latest prepared "
1208
+ "render job of this conversation instead of URLs copied from chat history",
1209
+ file=sys.stderr,
1210
+ )
1211
+
983
1212
  # --from-job-id 模式:从数据库加载 RenderPlan
984
1213
  if args.from_job_id:
985
1214
  print(f"📋 loading RenderPlan from database (jobId={args.from_job_id})...")
986
- if not PRIVATE_TOKEN:
987
- print("❌ --from-job-id mode requires PRIV_TOKEN", file=sys.stderr)
988
- sys.exit(1)
989
- # render_job_client lives in skills/template-registry/scripts/ — the
990
- # shared location for cross-skill Python helpers (matches the pattern
991
- # render-video uses for the same import).
992
- _template_registry_scripts = os.path.join(
993
- os.path.dirname(__file__), "..", "..", "template-registry", "scripts"
994
- )
995
- sys.path.insert(0, _template_registry_scripts)
996
- from render_job_client import get_plan as rjc_get_plan
1215
+ rjc = _render_job_client()
997
1216
  try:
998
- render_plan_str = rjc_get_plan(args.from_job_id, PRIVATE_TOKEN)
1217
+ render_plan_str = rjc.get_plan(args.from_job_id, PRIVATE_TOKEN)
999
1218
  except RuntimeError as e:
1000
1219
  print(f"❌ failed to fetch RenderPlan: {e}", file=sys.stderr)
1001
1220
  sys.exit(1)
@@ -1029,7 +1248,7 @@ Scene fields:
1029
1248
  else:
1030
1249
  # 传统模式:必须提供 --scenes 和 --title
1031
1250
  if not args.scenes:
1032
- print("❌ provide --scenes or --from-render-plan", file=sys.stderr)
1251
+ print("❌ provide --from-job-id, --from-render-plan or --scenes", file=sys.stderr)
1033
1252
  parser.print_help()
1034
1253
  sys.exit(1)
1035
1254
  if not args.title:
@@ -1063,34 +1282,45 @@ Scene fields:
1063
1282
  result_data = poll_task_status(task_id, args.poll_interval, args.max_wait)
1064
1283
 
1065
1284
  download_url = result_data.get("downloadUrl", "")
1066
- file_name = result_data.get("fileName", "")
1285
+ file_name = result_data.get("fileName", "") or "jianying_draft.zip"
1067
1286
 
1068
1287
  if not download_url:
1069
1288
  print("❌ generation finished but no download URL was returned", file=sys.stderr)
1070
1289
  sys.exit(1)
1071
1290
 
1072
1291
  print(f"\n🎉 Jianying draft generated successfully!")
1073
- if file_name:
1074
- print(f" filename: {file_name}")
1075
- print(f" download URL: {download_url}")
1076
-
1077
- # 默认下载 ZIP;含 textLayers/subtitleText 时强制下载以便后处理
1078
- if args.no_download and not needs_postprocess:
1079
- print(f"\n💡 To download the ZIP, drop --no-download (or open the URL above)")
1080
- return
1292
+ print(f" filename: {file_name}")
1081
1293
 
1082
- if args.no_download and needs_postprocess:
1083
- print("⚠️ textLayers/subtitleText detected; --no-download is ignored (post-processing is local)")
1084
-
1085
- output_path = args.output or f"jianying_draft_{int(time.time())}.zip"
1086
- download_zip(download_url, output_path)
1087
-
1088
- # 后处理 textLayers / Pill 字幕样式
1294
+ output_path = ""
1089
1295
  if needs_postprocess:
1090
- postprocess_draft_zip(output_path, scenes)
1296
+ # 后处理必须先把 ZIP 拿到本地。--no-download 时落到临时文件,传回后删掉,
1297
+ # 不在跑脚本的机器(常常是服务器)上留垃圾。
1298
+ keep_local = not args.no_download
1299
+ if keep_local:
1300
+ output_path = args.output or f"jianying_draft_{int(time.time())}.zip"
1301
+ else:
1302
+ fd, output_path = tempfile.mkstemp(prefix="jianying_draft_", suffix=".zip")
1303
+ os.close(fd)
1304
+ try:
1305
+ download_zip(download_url, output_path)
1306
+ postprocess_draft_zip(output_path, scenes)
1307
+ # 用户拿到的链接必须指向后处理之后的版本,否则字幕样式 / textLayers 全部丢失。
1308
+ download_url = upload_draft_zip(output_path, file_name)
1309
+ finally:
1310
+ if not keep_local and os.path.exists(output_path):
1311
+ os.remove(output_path)
1312
+ output_path = ""
1313
+ elif not args.no_download:
1314
+ output_path = args.output or f"jianying_draft_{int(time.time())}.zip"
1315
+ download_zip(download_url, output_path)
1316
+
1317
+ print_draft_summary(scenes, args.width, args.height, draft_root_path)
1318
+ print(f"\n download URL: {download_url}")
1319
+ if output_path:
1320
+ print(f" local file: {output_path}")
1091
1321
 
1092
1322
  print(f"\n💡 How to import into Jianying:")
1093
- print(f" 1. Extract {output_path} into the Jianying draft directory:")
1323
+ print(f" 1. Download and extract the ZIP into exactly this directory on the user's computer:")
1094
1324
  print(f" {draft_root_path}")
1095
1325
  print(f" 2. Start or restart Jianying; the draft will appear in your project list")
1096
1326
 
@@ -4,7 +4,7 @@
4
4
  "tier": "orchestration",
5
5
  "category": "consuming",
6
6
  "title": "Jianying (CapCut) Draft Export",
7
- "description": "Jianying (CapCut) draft export: package asset URLs into a draft ZIP that Jianying can import. Supports automatic conversion from a RenderPlan.",
7
+ "description": "Jianying (CapCut) draft export: package asset URLs into a draft ZIP that Jianying can import. By default exports the latest prepared render job of the current conversation (no scenes needed).",
8
8
  "auth": "required",
9
9
  "envVars": [
10
10
  "PRIV_TOKEN",
@@ -15,13 +15,17 @@
15
15
  "parameters": {
16
16
  "type": "object",
17
17
  "properties": {
18
+ "from_job_id": {
19
+ "type": "number",
20
+ "description": "Render job id to export (the `jobId` printed by prepare_video_assets). Omit it together with scenes to export the latest prepared job of the current conversation — preferred, because asset URLs copied from chat history go stale after re-renders"
21
+ },
18
22
  "from_render_plan": {
19
23
  "type": "string",
20
- "description": "Build the draft from a RenderPlan JSON (replaces --scenes)"
24
+ "description": "Build the draft from a local RenderPlan JSON file (local debugging only)"
21
25
  },
22
26
  "scenes": {
23
27
  "type": "string",
24
- "description": "Scene array as JSON (inline string or file path)"
28
+ "description": "Hand-written scene array as JSON — only for assets that never went through prepare_video_assets. Fields per scene: imageUrl | videoUrl (one required), duration (seconds, required), audioUrl, audioDuration, subtitleText, textLayers, width, height. Any other field (text, image, audio…) is rejected"
25
29
  },
26
30
  "title": {
27
31
  "type": "string",
@@ -41,15 +45,15 @@
41
45
  "mac",
42
46
  "windows"
43
47
  ],
44
- "description": "Draft-root preset"
48
+ "description": "OS of the computer that will open the draft"
45
49
  },
46
50
  "draft_root_path": {
47
51
  "type": "string",
48
- "description": "Explicit Jianying draft root path (overrides --system)"
52
+ "description": "Absolute Jianying draft root on the user's computer (Jianying → Settings → Draft location), e.g. /Users/<username>/Movies/JianyingPro/User Data/Projects/com.lveditor.draft or C:/Users/<username>/AppData/Local/JianyingPro/User Data/Projects/com.lveditor.draft. Required when the agent runs on a server; never guess the username, ask the user"
49
53
  },
50
54
  "no_download": {
51
55
  "type": "boolean",
52
- "description": "Do not download the ZIP; print the URL only"
56
+ "description": "Do not keep a local copy of the ZIP; print the download URL only"
53
57
  },
54
58
  "output": {
55
59
  "type": "string",
@@ -60,7 +64,8 @@
60
64
  },
61
65
  "ui": {
62
66
  "primary": [
63
- "system"
67
+ "system",
68
+ "draft_root_path"
64
69
  ],
65
70
  "advanced": [],
66
71
  "hidden": [
@@ -68,9 +73,9 @@
68
73
  "width",
69
74
  "height",
70
75
  "output",
76
+ "from_job_id",
71
77
  "from_render_plan",
72
78
  "scenes",
73
- "draft_root_path",
74
79
  "no_download"
75
80
  ]
76
81
  }
@@ -2,6 +2,6 @@
2
2
  "skillName": "export-jianying",
3
3
  "repoName": "agent-skill-media-maker",
4
4
  "skillId": "554",
5
- "version": "V4",
5
+ "version": "V6",
6
6
  "skillDescription": "Jianying (CapCut) draft-generation skill. Packages asset URLs into a draft ZIP that Jianying can import; supports automatic conversion from a RenderPlan (calls ab-api /file/generateJianYing).\n\nUse this skill as soon as the user mentions any of these intents:\n- Export to Jianying, Jianying draft, package for Jianying, import into Jianying\n- Export materials to the Jianying format, generate a Jianying project\n- Bundle video / image / audio into a Jianying draft\n- Export a Jianying draft from a RenderPlan\n\nEven when the user does not say \"Jianying\" explicitly, use this skill whenever they want to package materials into a draft that can be edited in Jianying."
7
7
  }
@@ -172,6 +172,23 @@ def save_manifest(job_id: int, manifest: dict, priv_token: str) -> None:
172
172
  _post("/renderJob/saveManifest", {"jobId": job_id, "manifest": manifest}, priv_token)
173
173
 
174
174
 
175
+ def latest_job(conversation_id: str, priv_token: str) -> dict:
176
+ """
177
+ 按会话取最近一次**已存 RenderPlan** 的渲染任务摘要(POST /renderJob/latest)。
178
+
179
+ 多轮对话里模型看不到之前的工具结果,拿不到 jobId;消费上一轮成果的 skill
180
+ (如 export-jianying)用注入的 CONVERSATION_ID 反查最新一版,而不是让模型从
181
+ 聊天记录里拼素材 URL —— 那样会拿到过期的旧版素材。
182
+
183
+ Returns:
184
+ {"jobId": int, "status": str, "attempt": int, "createTime": str, "updateTime": str}
185
+ """
186
+ data = _post("/renderJob/latest", {"conversationId": conversation_id}, priv_token)
187
+ if not data.get("jobId"):
188
+ raise RuntimeError("no render job with a saved RenderPlan in this conversation")
189
+ return data
190
+
191
+
175
192
  def get_job(job_id: int, priv_token: str) -> dict:
176
193
  """
177
194
  获取渲染任务完整详情。
@@ -2,6 +2,6 @@
2
2
  "skillName": "template-registry",
3
3
  "repoName": "agent-skill-media-maker",
4
4
  "skillId": "475",
5
- "version": "V25",
5
+ "version": "V26",
6
6
  "skillDescription": "Video-template registry skill. Stores every video-template definition and lists the available templates (templateId / name / aspect ratio / style tags).\n\nUse this skill as soon as the user mentions any of these intents:\n- View available templates / list every template\n\nNote: DSL→TemplateBinding is no longer a separate exposed step — once prepare_video_assets receives a template_id it builds the binding internally."
7
7
  }