@seavideo/cli 0.3.1 → 0.3.5

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 (50) hide show
  1. package/README.md +18 -4
  2. package/README.publish.md +18 -4
  3. package/dist/skills/seavideo-canvas-tools/SKILL.md +323 -0
  4. package/dist/skills/seavideo-command/SKILL.md +213 -0
  5. package/dist/skills/seavideo-prompt-design/SKILL.md +734 -0
  6. package/dist/skills/seavideo-setup/SKILL.md +195 -0
  7. package/dist/skills/seavideo-setup/references/agents/claude-code.md +31 -0
  8. package/dist/skills/seavideo-setup/references/agents/codex.md +28 -0
  9. package/dist/skills/seavideo-setup/references/authentication.md +69 -0
  10. package/dist/skills/seavideo-setup/references/install-skills.md +68 -0
  11. package/dist/skills/seavideo-setup/references/install.md +92 -0
  12. package/dist/skills/seavideo-setup/references/platforms/linux.md +29 -0
  13. package/dist/skills/seavideo-setup/references/platforms/macos.md +31 -0
  14. package/dist/skills/seavideo-setup/references/platforms/windows.md +55 -0
  15. package/dist/skills/seavideo-setup/references/troubleshooting.md +69 -0
  16. package/dist/skills/seavideo-setup/scripts/install-cli.ps1 +109 -0
  17. package/dist/skills/seavideo-setup/scripts/install-cli.sh +89 -0
  18. package/dist/skills/seavideo-setup/scripts/install-skills.mjs +130 -0
  19. package/dist/skills/seavideo-setup/scripts/preflight.ps1 +60 -0
  20. package/dist/skills/seavideo-setup/scripts/preflight.sh +25 -0
  21. package/dist/skills/seavideo-setup/scripts/setup.ps1 +74 -0
  22. package/dist/skills/seavideo-setup/scripts/setup.sh +78 -0
  23. package/dist/skills/seavideo-workflow-draft/SKILL.md +202 -0
  24. package/dist/skills/seavideo-workflow-image/SKILL.md +282 -0
  25. package/dist/skills/seavideo-workflow-video/SKILL.md +351 -0
  26. package/dist/src/agent-skills/agents.js +62 -0
  27. package/dist/src/agent-skills/backup.js +17 -0
  28. package/dist/src/agent-skills/install.js +155 -0
  29. package/dist/src/agent-skills/manifest.js +68 -0
  30. package/dist/src/agent-skills/payload.js +46 -0
  31. package/dist/src/agent-skills/store.js +38 -0
  32. package/dist/src/canvas/browser.js +5 -0
  33. package/dist/src/canvas/launch.js +77 -42
  34. package/dist/src/canvas/lifecycle.js +21 -4
  35. package/dist/src/canvas/puppeteer.js +56 -6
  36. package/dist/src/cli/commands/agent-skills.js +249 -0
  37. package/dist/src/cli/commands/canvas/session.js +3 -1
  38. package/dist/src/cli/main.js +36 -6
  39. package/dist/src/cli/program.js +27 -2
  40. package/dist/src/cli/session.js +2 -0
  41. package/dist/src/config/envs/envs.enc.json +25 -0
  42. package/dist/src/config/envs/envs.json +13 -0
  43. package/dist/src/config/presets.js +47 -13
  44. package/dist/src/config/sops.js +48 -0
  45. package/dist/src/deps.js +8 -1
  46. package/dist/src/i18n.js +88 -4
  47. package/dist/src/update/check-cache.js +0 -1
  48. package/dist/src/update/notify.js +6 -4
  49. package/dist/src/update/passive.js +9 -17
  50. package/package.json +3 -2
@@ -0,0 +1,351 @@
1
+ ---
2
+ name: seavideo-workflow-video
3
+ description: 在画布上落地视频工作流并跑出片:建资产图片节点、按草稿建 N 个 video clip 节点、写 @资产名 引用、按引用连线、逐个执行、用合成节点聚合成片、验收。当用户要生成视频、做多镜头短片、把多个 clip 拼成成片,且分镜与资产已定时使用。单张图片请用 image 技能。
4
+ ---
5
+
6
+ # 视频工作流落地
7
+
8
+ 把 `seavideo-workflow-draft` 产出的视频草稿变成画布上的真实节点,跑出成片。
9
+
10
+ ## 开始之前:画布从哪来
11
+
12
+ 本文档假设已经有张打开的画布。**先判断用哪张:**
13
+
14
+ | 用户怎么说 | 怎么做 |
15
+ | --- | --- |
16
+ | 「新建一个画布 / 新画布」 | `canvas create "<名字>" --use` |
17
+ | 给了画布 id 或链接 | `canvas use <canvas_id>` |
18
+ | 没提画布 | **新建一张**,别去翻他已有的画布 |
19
+
20
+ ```bash
21
+ # 新建(--use 表示建完立刻加载,等同 canvas use)
22
+ seavideo canvas create "画布名字" --use
23
+
24
+ # 用已有的
25
+ seavideo canvas use <canvas_id>
26
+ ```
27
+
28
+ **默认新建,不要复用用户已有的画布。** 用户已有的画布里可能已经有他手动摆好的节点,再往里建会把它搞乱。只有用户明确指了某张画布,才 `canvas use` 进去。
29
+
30
+ `canvas use` 与 `canvas create --use` 都可能要几十秒(起浏览器 + 等 WebMCP 工具注册,上限 90 秒),**这两条命令不受 `--timeout` 影响**,慢是正常的。
31
+
32
+ **没有草稿就先做草稿。** 本文档假设「目标、资产、clip 清单、引用关系」已经定了。
33
+
34
+ ## 落地顺序(不能乱)
35
+
36
+ ```
37
+ 1. 资产节点 image-upload / image-generation-v2 ← 人物、道具、场景
38
+ 2. clip 节点 video-generation × N ← 一个 clip 一个节点
39
+ 3. 合成节点 drama-compose-node ← 聚合所有 clip
40
+ 4. 写 prompt 每个 clip 的 prompt 里写 @资产名
41
+ 5. 连线 资产→clip,clip→合成(合成必须给端口)
42
+ 6. 执行 资产先跑完 → clip 按序 → 最后合成
43
+ 7. 验收 成片 URL + 一致性核对
44
+ ```
45
+
46
+ 顺序的理由:`@资产名` 要求资产节点先存在;合成要求所有 clip `completed`。
47
+
48
+ ## 一个 clip = 一个视频播放单元 = 一个节点
49
+
50
+ 这是本工作流最核心的约定。
51
+
52
+ **不要把多个动作塞进一个 clip 节点。** 单个节点的时长有硬上限(实测:Seedance 4–15 秒,Kling 3–15 秒),而且一个节点里塞多个动作,生成结果会糊。
53
+
54
+ **也不要一个动作拆成多个 clip。** 每多一个 clip 就多一次生成、多一处衔接。
55
+
56
+ clip 怎么切,草稿阶段就定好了。这里只照做。
57
+
58
+ ## 第 1 步:建资产节点
59
+
60
+ 人物、道具、场景都建成**图片节点**。视频节点接受 `image-upload` / `image-generation-v2` 作为输入(`allowed_sources` 实测确认),图片是画布上唯一能承载「视觉形象」并被视频引用的载体。
61
+
62
+ 用户已有图:
63
+
64
+ ```bash
65
+ seavideo tool call seaflow_canvas_instance_batch_create_nodes --args '{
66
+ "nodes": [{
67
+ "node_type": "image-upload",
68
+ "config": { "name": "女主", "location_x": 150, "location_y": 150,
69
+ "url": "<用户提供的真实图片地址>" },
70
+ "create_keys": ["name", "location_x", "location_y", "url"]
71
+ }]
72
+ }'
73
+ ```
74
+
75
+ 要生成:
76
+
77
+ ```bash
78
+ seavideo tool call seaflow_canvas_instance_batch_create_nodes --args '{
79
+ "nodes": [{
80
+ "node_type": "image-generation-v2",
81
+ "config": { "name": "厨房", "location_x": 150, "location_y": 500 },
82
+ "create_keys": ["name", "location_x", "location_y"]
83
+ }]
84
+ }'
85
+ ```
86
+
87
+ `name` 就是后面 `@` 引用用的名字,必须和草稿一致且唯一。
88
+
89
+ **生成型资产先单独执行完**,下游 clip 才能引用:
90
+
91
+ ```bash
92
+ seavideo tool call seaflow_canvas_instance_async_run_nodes \
93
+ --args '{"node_ids":["<资产id>"]}' --timeout 300
94
+ ```
95
+
96
+ ## 第 2 步:建 clip 节点
97
+
98
+ ```bash
99
+ seavideo tool call seaflow_canvas_instance_batch_create_nodes --args '{
100
+ "nodes": [
101
+ { "node_type": "video-generation",
102
+ "config": { "name": "clip1", "location_x": 600, "location_y": 150 },
103
+ "create_keys": ["name", "location_x", "location_y"] },
104
+ { "node_type": "video-generation",
105
+ "config": { "name": "clip2", "location_x": 600, "location_y": 400 },
106
+ "create_keys": ["name", "location_x", "location_y"] },
107
+ { "node_type": "video-generation",
108
+ "config": { "name": "clip3", "location_x": 600, "location_y": 650 },
109
+ "create_keys": ["name", "location_x", "location_y"] }
110
+ ]
111
+ }'
112
+ ```
113
+
114
+ `clip1` 建的时候**不带 prompt、不带参数**。下一步统一写。
115
+
116
+ 先查字段再决定给哪些参数:
117
+
118
+ ```bash
119
+ seavideo tool call seaflow_canvas_definition_batch_get_node_types_properties --args '{"node_types":["video-generation"]}'
120
+ ```
121
+
122
+ 看 `agent_editable_model_profiles` 的 `create_editable_fields` 和 `field_options`。实测(会变,以接口返回为准):
123
+
124
+ | 模型 | 时长 | 画幅 | 分辨率 |
125
+ | --- | --- | --- | --- |
126
+ | Seedance 2.0 Mini | 4–15 秒 | 16:9 / 9:16 / 1:1 / 4:3 / 3:4 / 21:9 | 480p / 720p |
127
+ | Kling v3 | 3–15 秒 | 无该字段 | 无该字段 |
128
+
129
+ `duration` 只能是上面列的整数,**不要传 3.5 这种值**。
130
+
131
+ `duration` / `aspect_ratio` / `resolution` 到底能在建节点时给、还是只能事后改,取决于当前模型的 `create_editable_fields` 与 `update_editable_fields` —— 这两个列表**不一样**。查一次接口返回,按它来。本文档的示例统一用「先建空节点、第 4 步统一写」的方式,这样参数在哪个列表里都不会卡住。
132
+
133
+ ## 第 3 步:建合成节点
134
+
135
+ ```bash
136
+ seavideo tool call seaflow_canvas_instance_batch_create_nodes --args '{
137
+ "nodes": [{
138
+ "node_type": "drama-compose-node",
139
+ "config": { "name": "成片", "location_x": 1100, "location_y": 400 },
140
+ "create_keys": ["name", "location_x", "location_y"]
141
+ }]
142
+ }'
143
+ ```
144
+
145
+ 合成节点的可改字段:`output_size`(9:16 / 16:9 / 1:1)、`autospeed`。放在最后写。
146
+
147
+ ## 第 4 步:写 prompt,引用资产
148
+
149
+ **prompt 怎么设计看 `seavideo-prompt-design`** —— 那里有官方公式、运镜词汇、动作量化写法、情绪外化、多镜头分镜、常见质量问题速查。本节只讲本工作流的硬约束。
150
+
151
+ ### clip 的 prompt 结构
152
+
153
+ 官方给的结构是:`主体 + 动作细节 + 场景 + 光影 + 运镜 + 风格 + 画质 + 约束`。落到本工作流:
154
+
155
+ ```text
156
+ @女主 作为主角,@厨房 作为场景,@主厨刀 作为道具。
157
+
158
+ 镜头:固定机位中景,略微俯拍,窗外自然光从左侧入射,台面有暖色补光。
159
+ 动作:右手缓慢抬起握住刀柄 → 刀刃落在番茄上 → 切下第一片 → 略微低头看砧板。
160
+ 表情:专注,嘴角轻微放松。
161
+ 约束:不要字幕、不要水印。
162
+
163
+ 高清商业摄影质感,色调温暖,光影柔和;人物外观与 @女主 稳定一致,
164
+ 道具与 @主厨刀 一致,场景与 @厨房 一致。
165
+ ```
166
+
167
+ **不要在这个 prompt 里写「5 秒」这类时长。** 官方明确:模型对精确时间支持不稳定,强行写会导致生成异常。**时长用节点的 `duration` 参数给**(见第 2 步)。
168
+
169
+ **每个引用都要写成 `@名字`。** 这不是可选优化:
170
+
171
+ - 只连线不写 `@`,模型不知道要用资产的哪一部分
172
+ - 只写 `@` 不连线,模型拿不到那张图
173
+
174
+ 两者都做,形象才一致。
175
+
176
+ ### 相邻 clip 的衔接
177
+
178
+ 上一镜结尾的姿态要写进下一镜的开头:
179
+
180
+ ```text
181
+ clip 1 结尾:女主的手已搭在刀柄上
182
+ clip 2 开头:承接上一镜,女主已握住菜刀,刀抬起
183
+ ```
184
+
185
+ 不写的话,两个 clip 接起来会看到人物姿态跳变。
186
+
187
+ ### 一次写完
188
+
189
+ ```bash
190
+ seavideo tool call seaflow_canvas_instance_batch_update_nodes --args '{
191
+ "updates": [
192
+ { "node_id": "<clip1id>", "config": { "prompt": "..." }, "update_keys": ["prompt"] },
193
+ { "node_id": "<clip2id>", "config": { "prompt": "..." }, "update_keys": ["prompt"] }
194
+ ]
195
+ }'
196
+ ```
197
+
198
+ 单次最多 10 条。`duration`、`aspect_ratio` 等参数**只有在 `update_editable_fields` 里**才能用这条路径写;不在的话按第 2 步的说明改在建节点时给。写在 `config` 里的每一个键都**必须同时出现在 `update_keys`**,否则静默丢弃。
199
+
200
+ ## 第 5 步:连线
201
+
202
+ ### 资产 → clip
203
+
204
+ 按引用表逐条建:
205
+
206
+ ```bash
207
+ seavideo tool call seaflow_canvas_instance_batch_create_relations --args '{
208
+ "relations": [
209
+ { "start_node_id": "<女主id>", "end_node_id": "<clip2id>" },
210
+ { "start_node_id": "<厨房id>", "end_node_id": "<clip2id>" },
211
+ { "start_node_id": "<主厨刀id>", "end_node_id": "<clip2id>" }
212
+ ],
213
+ "dry_run": true
214
+ }'
215
+ ```
216
+
217
+ 资产到 clip 之间**省略端口**即可,系统按节点对匹配。
218
+
219
+ ### clip → 合成(必须给端口)
220
+
221
+ ```bash
222
+ seavideo tool call seaflow_canvas_instance_batch_create_relations --args '{
223
+ "relations": [
224
+ { "start_node_id": "<clip1id>", "end_node_id": "<合成id>", "end_port_code": "video" },
225
+ { "start_node_id": "<clip2id>", "end_node_id": "<合成id>", "end_port_code": "video" },
226
+ { "start_node_id": "<clip3id>", "end_node_id": "<合成id>", "end_port_code": "video" }
227
+ ],
228
+ "dry_run": true
229
+ }'
230
+ ```
231
+
232
+ **`drama-compose-node` 不给 `end_port_code` 直接报错:**
233
+
234
+ ```json
235
+ { "status": "error", "message": "连接到短剧合成节点时必须传递链接类型 end_port_code",
236
+ "error_code": "MISSING_END_PORT_CODE" }
237
+ ```
238
+
239
+ 实测合法端口:`video`、`image`、`subtitle`、`audio`。
240
+
241
+ > `bgm` 和 `background_music` **都不是合法值**,会被归到音频类并报 `Type mismatch`。上游接口文档写的 `bgm` 是错的。
242
+
243
+ 旁白和字幕各接哪个端口:
244
+
245
+ | 端口 | 接什么 | 产出它的节点类型 |
246
+ | --- | --- | --- |
247
+ | `video` | 视频素材 | `video-generation` / `video-upload` |
248
+ | `image` | 图片素材 | `image-generation-v2` / `image-upload` |
249
+ | `audio` | 音频(配音、音乐、音效) | `audio-upload`(已确认存在) |
250
+ | `subtitle` | 字幕 | **未确认** |
251
+
252
+ > **旁白与字幕两类节点没有实测过。** 端口 `audio` / `subtitle` 确实存在(端口本身实测过),但产出它们的节点类型不在实测的 8 种里。
253
+ > 要加旁白或字幕时,**先调 `definition_get_node_types` 看当前画布有没有对应节点类型**,别按本文档猜名字。
254
+
255
+ **先 `dry_run`。** 失败返回里有 `allowed_sources` / `allowed_targets` / `reference_doc`,比猜快得多。连不通时它给出的 `allowed_sources` 就是权威答案。
256
+
257
+ **但 `dry_run` 通过不等于边建好了。** 它只校验、不写边。预校验通过后必须去掉 `dry_run` 再调一次,两次返回文本几乎一样,很容易漏。建完用 `get_canvas_state` 数 `relations` 确认。
258
+
259
+ ## 第 6 步:执行
260
+
261
+ 严格的依赖顺序,三步。
262
+
263
+ > **会等模型出结果的那几个调用必须显式给 `--timeout`。** 默认超时只有 30 秒,而视频一次生成要几分钟。不给就会误报「超时」,看起来像画布没准备好。
264
+ >
265
+ > 需要加 `--timeout` 的是:`async_run_nodes` 与 `query_run_nodes_status`。建节点、改配置、连线、查产物是快操作,30 秒够用,不用加。本文档的示例统一按这个规则标注。
266
+
267
+ ### 6a. 资产先生成完
268
+
269
+ 生成型资产如果还没跑完,先跑完。clip 引用它们。
270
+
271
+ ```bash
272
+ seavideo tool call seaflow_canvas_instance_async_run_nodes \
273
+ --args '{"node_ids":["<资产id>"]}' --timeout 300
274
+ ```
275
+
276
+ ### 6b. 逐个提交 clip
277
+
278
+ ```bash
279
+ seavideo tool call seaflow_canvas_instance_async_run_nodes \
280
+ --args '{"node_ids":["<clip1id>"]}' --timeout 300
281
+ seavideo tool call seaflow_canvas_instance_async_run_nodes \
282
+ --args '{"node_ids":["<clip2id>"]}' --timeout 300
283
+ ```
284
+
285
+ `node_ids` 一次只能一个(`maxItems: 1`)。
286
+
287
+ **clip 之间没有依赖关系**(都只依赖资产),可以连着提交,不用等 clip1 跑完再提交 clip2。上游有依赖的节点必须等它 `completed`。
288
+
289
+ ### 6c. 全部 clip 完成后才提交合成
290
+
291
+ ```bash
292
+ seavideo tool call seaflow_canvas_instance_async_run_nodes \
293
+ --args '{"node_ids":["<合成id>"]}' --timeout 300
294
+ ```
295
+
296
+ **合成节点有前置条件:所有上游必须 `completed`。** 有 clip 还在 `running` 就提交,会被拒。
297
+
298
+ ## 第 7 步:轮询与取产物
299
+
300
+ ```bash
301
+ seavideo tool call seaflow_canvas_instance_query_run_nodes_status \
302
+ --args '{"node_ids":["<clip1id>","<clip2id>","<clip3id>"]}' --timeout 120
303
+ ```
304
+
305
+ 视频比图片慢得多,单 clip 可能几分钟。轮询间隔给足。
306
+
307
+ 全部 `completed` 后取成片:
308
+
309
+ ```bash
310
+ seavideo tool call seaflow_canvas_instance_batch_query_nodes_outputs --args '{
311
+ "filters": [{ "field": "id", "value": "<合成id>", "operator": "equals" }]
312
+ }'
313
+ ```
314
+
315
+ 成片在 `output_metadata.url`。**这个 URL 才是交付物** —— 不是各 clip 的 URL。
316
+
317
+ 如果用户要看单个 clip,也把 clip 的 URL 一并给他。
318
+
319
+ **提醒用户:产物 URL 只保留 24 小时**(官方 Seedream 文档明确),超时自动清除。要长期保存就在 24 小时内下载。
320
+
321
+ ## 验收
322
+
323
+ - [ ] 草稿里每个资产都有节点,生成型的 `completed`
324
+ - [ ] 草稿里每个 clip 都有节点,全部 `completed`
325
+ - [ ] 合成节点 `completed`,拿到 `output_metadata.url`
326
+ - [ ] 成片时长接近草稿规划的总时长
327
+ - [ ] **各 clip 里的人物、道具、场景确实一致**(播 URL 核对,不要假设)
328
+ - [ ] 用户要的声音(旁白/配乐)确实在成片里
329
+ - [ ] 连线数 = 引用关系数 + clip 数
330
+
331
+ 第 5 项最容易漏:拿到 URL 不等于形象一致,模型可能没听 `@引用`。
332
+
333
+ ## 失败处理
334
+
335
+ | 现象 | 处理 |
336
+ | --- | --- |
337
+ | 建生成节点报「模型权限尚未加载完成或获取失败」 | **确定性失败,重试无用**。告知用户是认证模式限制,引导到 Web 界面建节点。详见 `seavideo-canvas-tools` 的「已知限制」 |
338
+ | 连合成报 `MISSING_END_PORT_CODE` | 补 `end_port_code: "video"` |
339
+ | 连合成报 `Type mismatch` | 端口值不对或源类型不兼容。看返回里的 `allowed_*` |
340
+ | 合成提交被拒 | 还有 clip 没 `completed`。查一遍全部 clip 状态 |
341
+ | 各 clip 形象不一致 | prompt 没写 `@资产名`,或资产连线没建。两者都查 |
342
+ | 相邻 clip 姿态跳变 | 衔接描述没写进下一镜 prompt |
343
+ | 单 clip 时长超限 | 上限 15 秒。拆成两个 clip |
344
+ | `failed` | 看 `execution_message`,多为 prompt 触发内容策略 |
345
+
346
+ ## 批量
347
+
348
+ - 建节点 ≤10 / 次,改节点 ≤10 / 次,截图 ≤2 / 次
349
+ - clip 多于 10 个分批建,但**资产节点和合成节点一次建好**
350
+ - 无依赖的 clip 可并行提交;合成永远排最后
351
+ - 每建完一批先 `get_canvas_state` 复查,别等执行才发现漏建
@@ -0,0 +1,62 @@
1
+ import { join } from 'node:path';
2
+ export const AGENT_IDS = ['codex', 'claude-code', 'workbuddy'];
3
+ const AGENTS = {
4
+ codex: {
5
+ user: ({ home, env }) => join(env['CODEX_HOME'] || join(home, '.codex'), 'skills'),
6
+ project: ({ project }) => join(project, '.agents', 'skills'),
7
+ userRoot: ({ home, env }) => env['CODEX_HOME'] || join(home, '.codex'),
8
+ projectRoot: ({ project }) => join(project, '.agents'),
9
+ },
10
+ 'claude-code': {
11
+ user: ({ home }) => join(home, '.claude', 'skills'),
12
+ project: ({ project }) => join(project, '.claude', 'skills'),
13
+ userRoot: ({ home }) => join(home, '.claude'),
14
+ projectRoot: ({ project }) => join(project, '.claude'),
15
+ },
16
+ workbuddy: {
17
+ user: ({ home }) => join(home, '.workbuddy', 'skills'),
18
+ project: ({ project }) => join(project, '.workbuddy', 'skills'),
19
+ userRoot: ({ home }) => join(home, '.workbuddy'),
20
+ projectRoot: ({ project }) => join(project, '.workbuddy'),
21
+ },
22
+ };
23
+ export function isAgentId(value) {
24
+ return AGENT_IDS.includes(value);
25
+ }
26
+ function agentRootOf(agent, scope, input) {
27
+ let result;
28
+ if (scope === 'user') {
29
+ result = AGENTS[agent].userRoot(input);
30
+ }
31
+ else {
32
+ result = AGENTS[agent].projectRoot(input);
33
+ }
34
+ return result;
35
+ }
36
+ export function skillsDirOf(agent, scope, input) {
37
+ return AGENTS[agent][scope](input);
38
+ }
39
+ async function exists(deps, path) {
40
+ let result;
41
+ try {
42
+ await deps.fs.stat(path);
43
+ result = true;
44
+ }
45
+ catch {
46
+ result = false;
47
+ }
48
+ return result;
49
+ }
50
+ export async function detectAgents(scope, input, deps) {
51
+ const detected = [];
52
+ for (const agent of AGENT_IDS) {
53
+ const root = agentRootOf(agent, scope, input);
54
+ const found = await exists(deps, root);
55
+ if (found) {
56
+ detected.push(agent);
57
+ }
58
+ else {
59
+ }
60
+ }
61
+ return detected;
62
+ }
@@ -0,0 +1,17 @@
1
+ import { join } from 'node:path';
2
+ export function timestampOf(date) {
3
+ return date
4
+ .toISOString()
5
+ .replace(/[-:]/gu, '')
6
+ .replace(/\.\d+Z$/u, 'Z');
7
+ }
8
+ export function backupRoot(home, timestamp) {
9
+ return join(home, '.seavideo', 'backups', 'agent-skills', timestamp);
10
+ }
11
+ const MODE_DIR = 0o700;
12
+ export async function backupDirectory(deps, home, timestamp, agentKey, skill, sourcePath) {
13
+ const target = join(backupRoot(home, timestamp), agentKey, skill);
14
+ await deps.fs.mkdir(join(target, '..'), { recursive: true, mode: MODE_DIR });
15
+ await deps.fs.rename(sourcePath, target);
16
+ return target;
17
+ }
@@ -0,0 +1,155 @@
1
+ import { join, resolve } from 'node:path';
2
+ import { CliError } from "../errors.js";
3
+ import { t } from "../i18n.js";
4
+ import { AGENT_IDS, detectAgents, skillsDirOf as agentSkillsDirOf, } from "./agents.js";
5
+ import { backupDirectory } from "./backup.js";
6
+ import { CUSTOM_AGENT, normalizeRoot } from "./manifest.js";
7
+ export async function resolveTargets(deps, options) {
8
+ const input = {
9
+ home: deps.homeDir(),
10
+ project: resolve(options.project),
11
+ env: deps.env,
12
+ };
13
+ let targets;
14
+ if (options.skillsDir !== undefined) {
15
+ const root = resolve(options.customBase, options.skillsDir);
16
+ targets = [{ agent: CUSTOM_AGENT, scope: options.scope, root }];
17
+ }
18
+ else {
19
+ const agents = await selectAgents(deps, options, input);
20
+ targets = agents.map((agent) => ({
21
+ agent,
22
+ scope: options.scope,
23
+ root: agentSkillsDirOf(agent, options.scope, input),
24
+ }));
25
+ }
26
+ return targets;
27
+ }
28
+ async function selectAgents(deps, options, input) {
29
+ let agents;
30
+ if (options.agents === 'all') {
31
+ agents = AGENT_IDS;
32
+ }
33
+ else if (options.agents !== undefined) {
34
+ agents = options.agents;
35
+ }
36
+ else {
37
+ agents = await detectAgents(options.scope, input, deps);
38
+ if (agents.length === 0) {
39
+ throw new CliError('usage', t('agentSkills.noAgentDetected', { scope: options.scope }, deps.env), {
40
+ detail: t('agentSkills.noAgentDetectedDetail', { agents: AGENT_IDS.join(', '), home: input.home }, deps.env),
41
+ });
42
+ }
43
+ }
44
+ return agents;
45
+ }
46
+ function entriesOf(entries, root) {
47
+ const key = normalizeRoot(root);
48
+ return entries.filter((entry) => normalizeRoot(entry.root) === key);
49
+ }
50
+ export async function installTargets(deps, home, targets, existing, options) {
51
+ const result = {
52
+ installed: [],
53
+ removed: [],
54
+ backedUp: [],
55
+ failures: [],
56
+ entries: [],
57
+ };
58
+ const untouched = existing.filter((entry) => !targets.some((target) => normalizeRoot(target.root) === normalizeRoot(entry.root)));
59
+ result.entries.push(...untouched);
60
+ for (const target of targets) {
61
+ await syncTarget(deps, home, target, existing, options, result);
62
+ }
63
+ return result;
64
+ }
65
+ async function syncTarget(deps, home, target, existing, options, result) {
66
+ const manifestAgent = target.agent;
67
+ const previous = entriesOf(existing, target.root);
68
+ const previousSkills = new Set(previous.map((entry) => entry.skill));
69
+ const current = new Set(options.skills);
70
+ const targetEntries = [];
71
+ let failed = false;
72
+ await deps.fs.mkdir(target.root, { recursive: true, mode: 0o700 });
73
+ const installed = [];
74
+ for (const skill of options.skills) {
75
+ const destination = join(target.root, skill);
76
+ const source = options.sources.get(skill);
77
+ const known = previousSkills.has(skill);
78
+ try {
79
+ if (!known && (await pathExists(deps, destination))) {
80
+ if (!options.force) {
81
+ throw new CliError('usage', t('agentSkills.conflict', { skill, path: destination }, deps.env), { detail: t('agentSkills.conflictDetail', {}, deps.env) });
82
+ }
83
+ const backup = await backupDirectory(deps, home, options.timestamp, manifestAgent === CUSTOM_AGENT ? 'custom' : manifestAgent, skill, destination);
84
+ result.backedUp.push({ target, skill, backup });
85
+ }
86
+ else if (known) {
87
+ await deps.fs.rm(destination, { recursive: true, force: true });
88
+ }
89
+ else {
90
+ }
91
+ await deps.fs.cp(source, destination, { recursive: true });
92
+ installed.push(skill);
93
+ targetEntries.push(entryOf(target, skill, destination, options, backupOf(result, target, skill)));
94
+ }
95
+ catch (error) {
96
+ failed = true;
97
+ result.failures.push({
98
+ target,
99
+ skill,
100
+ reason: errorMessage(error),
101
+ hint: error instanceof CliError ? (error.detail ?? null) : null,
102
+ });
103
+ }
104
+ }
105
+ result.installed.push({ target, skills: installed });
106
+ const stale = previous.filter((entry) => !current.has(entry.skill));
107
+ if (failed) {
108
+ const recorded = new Set(targetEntries.map((entry) => entry.skill));
109
+ result.entries.push(...previous.filter((entry) => !recorded.has(entry.skill)));
110
+ result.entries.push(...targetEntries);
111
+ }
112
+ else {
113
+ const removed = [];
114
+ for (const entry of stale) {
115
+ await deps.fs.rm(entry.path, { recursive: true, force: true });
116
+ removed.push(entry.skill);
117
+ }
118
+ if (removed.length > 0) {
119
+ result.removed.push({ target, skills: removed });
120
+ }
121
+ else {
122
+ }
123
+ result.entries.push(...targetEntries);
124
+ }
125
+ }
126
+ function backupOf(result, target, skill) {
127
+ const found = result.backedUp.find((item) => item.target.root === target.root && item.skill === skill);
128
+ return found?.backup ?? null;
129
+ }
130
+ function entryOf(target, skill, destination, options, backup) {
131
+ return {
132
+ agent: target.agent,
133
+ scope: target.scope,
134
+ root: target.root,
135
+ skill,
136
+ path: destination,
137
+ installedAt: options.timestamp,
138
+ cliVersion: options.cliVersion,
139
+ backup,
140
+ };
141
+ }
142
+ async function pathExists(deps, path) {
143
+ let result;
144
+ try {
145
+ await deps.fs.lstat(path);
146
+ result = true;
147
+ }
148
+ catch {
149
+ result = false;
150
+ }
151
+ return result;
152
+ }
153
+ function errorMessage(error) {
154
+ return error instanceof Error ? error.message : String(error);
155
+ }
@@ -0,0 +1,68 @@
1
+ import { join } from 'node:path';
2
+ export const MANIFEST_VERSION = 1;
3
+ export const MANIFEST_FILE = 'agent-skills.json';
4
+ export const CUSTOM_AGENT = 'custom';
5
+ export function emptyManifest() {
6
+ return { version: MANIFEST_VERSION, entries: [] };
7
+ }
8
+ export function manifestPath(home) {
9
+ return join(home, '.seavideo', MANIFEST_FILE);
10
+ }
11
+ export function normalizeRoot(path) {
12
+ return path.replace(/\\/gu, '/').replace(/\/+$/u, '').toLowerCase();
13
+ }
14
+ export class ManifestCorruptError extends Error {
15
+ path;
16
+ reason;
17
+ constructor(path, reason) {
18
+ super(`${path}: ${reason}`);
19
+ this.name = 'ManifestCorruptError';
20
+ this.path = path;
21
+ this.reason = reason;
22
+ }
23
+ }
24
+ function isEntry(value) {
25
+ const e = (typeof value === 'object' && value !== null ? value : {});
26
+ const strings = ['scope', 'root', 'skill', 'path', 'installedAt', 'cliVersion'];
27
+ const valid = typeof value === 'object' &&
28
+ value !== null &&
29
+ typeof e['agent'] === 'string' &&
30
+ strings.every((key) => typeof e[key] === 'string') &&
31
+ (e['backup'] === null || typeof e['backup'] === 'string');
32
+ return valid;
33
+ }
34
+ export function parseManifest(text, path) {
35
+ let raw;
36
+ try {
37
+ raw = JSON.parse(text);
38
+ }
39
+ catch {
40
+ throw new ManifestCorruptError(path, 'not valid JSON');
41
+ }
42
+ if (typeof raw !== 'object' || raw === null) {
43
+ throw new ManifestCorruptError(path, 'not an object');
44
+ }
45
+ const data = raw;
46
+ const entries = data['entries'];
47
+ if (data['version'] !== MANIFEST_VERSION || !Array.isArray(entries)) {
48
+ throw new ManifestCorruptError(path, 'unexpected shape');
49
+ }
50
+ for (const entry of entries) {
51
+ if (!isEntry(entry))
52
+ throw new ManifestCorruptError(path, 'invalid entry');
53
+ }
54
+ return { version: MANIFEST_VERSION, entries };
55
+ }
56
+ export async function readManifest(deps, home) {
57
+ const path = manifestPath(home);
58
+ let text;
59
+ try {
60
+ text = await deps.fs.readFile(path, 'utf8');
61
+ }
62
+ catch (error) {
63
+ text = '';
64
+ if (error.code !== 'ENOENT')
65
+ throw error;
66
+ }
67
+ return text === '' ? emptyManifest() : parseManifest(text, path);
68
+ }