@lingjingai/lj-awb-cli 0.3.15 → 0.4.1

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 (49) hide show
  1. package/README.md +46 -27
  2. package/build/_shared.mjs +130 -0
  3. package/build/build.mjs +3 -0
  4. package/build/pre-publish.mjs +57 -0
  5. package/build/pre.mjs +8 -107
  6. package/build/prod.mjs +9 -78
  7. package/install.mjs +1 -0
  8. package/package.json +8 -3
  9. package/packages/awb-cli/README.md +0 -3
  10. package/packages/awb-cli/package.json +2 -2
  11. package/packages/awb-core/package.json +6 -2
  12. package/packages/awb-core/src/api.js +33 -64
  13. package/packages/awb-core/src/artifact.js +75 -6
  14. package/packages/awb-core/src/auth.js +1 -1
  15. package/packages/awb-core/src/commands.js +316 -120
  16. package/packages/awb-core/src/common.js +3 -2
  17. package/packages/awb-core/src/output.js +2353 -105
  18. package/packages/awb-core/src/services.js +1311 -135
  19. package/packages/awb-core/src/standalone.js +908 -247
  20. package/packages/awb-core/src/update.js +327 -0
  21. package/skills/lj-awb/SKILL.md +105 -76
  22. package/skills/lj-awb/VERSION +1 -1
  23. package/skills/lj-awb/compat.json +3 -3
  24. package/skills/lj-awb/modules/account.md +20 -7
  25. package/skills/lj-awb/modules/artifact/asset.md +64 -0
  26. package/skills/lj-awb/modules/artifact/clip.md +65 -0
  27. package/skills/lj-awb/modules/artifact/script.md +37 -0
  28. package/skills/lj-awb/modules/artifact/video.md +65 -0
  29. package/skills/lj-awb/modules/artifact.md +31 -52
  30. package/skills/lj-awb/modules/asset.md +50 -11
  31. package/skills/lj-awb/modules/auth.md +10 -4
  32. package/skills/lj-awb/modules/create-contract.md +25 -13
  33. package/skills/lj-awb/modules/create.md +37 -0
  34. package/skills/lj-awb/modules/credits.md +6 -0
  35. package/skills/lj-awb/modules/driver.md +126 -0
  36. package/skills/lj-awb/modules/evals.md +84 -36
  37. package/skills/lj-awb/modules/image.md +22 -13
  38. package/skills/lj-awb/modules/model.md +34 -33
  39. package/skills/lj-awb/modules/project.md +7 -0
  40. package/skills/lj-awb/modules/subject.md +28 -7
  41. package/skills/lj-awb/modules/task-manual.md +32 -28
  42. package/skills/lj-awb/modules/task.md +70 -8
  43. package/skills/lj-awb/modules/upload.md +16 -2
  44. package/skills/lj-awb/modules/video.md +33 -29
  45. package/skills/lj-awb/modules/workflows.md +232 -169
  46. package/skills/lj-awb/references/error-codes.md +109 -0
  47. package/skills/lj-awb/references/model-options-read.md +25 -17
  48. package/skills/lj-awb/references/output-fields.md +119 -0
  49. package/skills/lj-awb/scripts/resolve-lj-awb-cmd.sh +106 -4
package/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  `lj-awb` 是灵境 AWB / 动漫创作平台的命令行客户端。它把平台底层能力封装成稳定、可脚本化、Agent 友好的命令,并随包分发一套 `lj-awb` skill,方便 Codex、Claude 等 Agent 把自然语言任务编排成确定性的 CLI 调用。
4
4
 
5
- CLI 本身只负责平台调用、参数校验、精简输出和安全确认;自然语言理解、任务规划、项目产物写回由上层 Agent / skill 完成。
5
+ CLI 本身只负责平台调用、参数校验、人类友好输出、机器可读输出和安全确认;自然语言理解、任务规划、项目产物写回由上层 Agent / skill 完成。
6
6
 
7
7
  ```text
8
8
  用户 / Agent / CI
9
9
  -> lj-awb
10
10
  -> 灵境 AWB / 动漫平台 API
11
- -> compact text / JSON 结果
11
+ -> pretty / text / JSON / YAML / CSV 结果
12
12
  ```
13
13
 
14
14
  ## 能力概览
@@ -22,12 +22,9 @@ CLI 本身只负责平台调用、参数校验、精简输出和安全确认;
22
22
  | 积分 | `credits` | 可扣积分余额、项目组预算、任务用量统计 |
23
23
  | 模型 | `model` | 生图 / 生视频模型发现、模型参数白名单 |
24
24
  | 上传 | `upload` | 本地图片 / 视频 / 音频上传为平台可访问素材 |
25
- | 图片 | `image` | 生图估价、提交、批量提交、状态查询 |
26
- | 视频 | `video` | 生视频估价、提交、批量提交、状态查询、去字幕 |
25
+ | 创建 | `create` | 生图、生视频、主体、音色、素材和去字幕提交 |
27
26
  | 任务 | `task` | 任务列表、等待、任务台账和台账轮询 |
28
- | 资产 | `asset` | 素材库匹配、素材组、素材注册 |
29
27
  | 最终产物 | `artifact` | Workbench 剧本、资产、视频最终产物 CRUD 与本地 JSON 导入 |
30
- | 主体 | `subject` | 可复用主体资产发布与查询 |
31
28
 
32
29
  ## 环境要求
33
30
 
@@ -42,7 +39,7 @@ export LINGJING_AWB_API_ORIGIN=https://animeworkbench.lingjingai.cn
42
39
  export LINGJING_AWB_ACCESS_KEY=<access_key>
43
40
  ```
44
41
 
45
- 兼容的 access key 变量:`LINGJING_AWB_ACCESS_KEY`、`AWB_ACCESS_KEY`、`AWB_CODE`、`ANIME_ACCESS_KEY`。
42
+ `lj-awb` 只读取 `LINGJING_AWB_ACCESS_KEY` 作为环境变量 access key。
46
43
 
47
44
  ## 安装与运行
48
45
 
@@ -66,6 +63,18 @@ lj-awb auth verify
66
63
 
67
64
  可用 `LINGJING_AWB_SKILL_INSTALL_DIR` 指定单一安装目录;如果传入的是以 `skills` 结尾的根目录,安装器会自动追加 `lj-awb`。也可用 `LINGJING_AWB_SKIP_SKILL_INSTALL=1` 跳过 skill 安装。
68
65
 
66
+ 只分发 skill 也可以作为完整入口:`skills/lj-awb/scripts/resolve-lj-awb-cmd.sh` 会在首次使用时检查 `lj-awb`,缺失或版本低于 `skills/lj-awb/compat.json` 的 `minCliVersion` 时自动执行:
67
+
68
+ ```bash
69
+ npm install -g @lingjingai/lj-awb-cli@<minCliVersion>
70
+ ```
71
+
72
+ 预发环境可在 bootstrap 前设置:
73
+
74
+ ```bash
75
+ export LINGJING_AWB_CLI_PACKAGE=@lingjingai/lj-awb-cli-pre
76
+ ```
77
+
69
78
  源码运行:
70
79
 
71
80
  ```bash
@@ -78,18 +87,20 @@ packages/awb-cli/bin/lj-awb auth status
78
87
 
79
88
  macOS 本地 wrapper `packages/awb-cli/bin/lj-awb` 会自动补充 Node 证书链,适合直接调试 HTTPS 平台接口。
80
89
 
90
+ 自动更新检查默认每天最多访问一次 npm registry,并会在源码 checkout、CI 或设置 `LINGJING_AWB_DISABLE_UPDATE_CHECK=1` / `AWB_DISABLE_UPDATE_CHECK=1` 时跳过。调试时可用 `LINGJING_AWB_UPDATE_CHECK=force` 强制检查。
91
+
81
92
  ## 认证
82
93
 
83
94
  保存 access key 到本地认证文件:
84
95
 
85
96
  ```bash
86
- lj-awb auth login-key --access-key <access_key>
97
+ lj-awb auth login --access-key <access_key>
87
98
  ```
88
99
 
89
100
  从环境变量读取并保存:
90
101
 
91
102
  ```bash
92
- LINGJING_AWB_ACCESS_KEY=<access_key> lj-awb auth login-key --from-env
103
+ LINGJING_AWB_ACCESS_KEY=<access_key> lj-awb auth login
93
104
  ```
94
105
 
95
106
  不落盘,直接让每次调用读取环境变量:
@@ -113,8 +124,11 @@ lj-awb account info
113
124
  ```bash
114
125
  lj-awb doctor
115
126
  lj-awb doctor --verify
127
+ lj-awb update --check
128
+ lj-awb update
129
+ lj-awb schema --brief -f json
116
130
  lj-awb schema -f json
117
- lj-awb schema --domain video -f json
131
+ lj-awb schema --domain create -f json
118
132
  lj-awb auth status
119
133
  lj-awb auth verify
120
134
  lj-awb account info
@@ -136,29 +150,32 @@ lj-awb artifact video import-storyboard --project-id <projectId> --input-file 3_
136
150
  正式写入、切换上下文、批量和扣费命令都支持安全确认:
137
151
 
138
152
  ```bash
139
- lj-awb image create ... --dry-run
140
- lj-awb image create ... --yes
153
+ lj-awb create image ... --dry-run
154
+ lj-awb create image ... --yes
141
155
  ```
142
156
 
143
157
  缺少 `--yes` 时,CLI 返回 `confirmation_required`,退出码为 `10`。`task wait` 超时返回 `task_still_running`,退出码为 `20`。
144
158
 
145
159
  ## Agent 接入建议
146
160
 
147
- Agent 不应该靠记忆猜命令参数。进入任务前推荐先读取机器可读契约:
161
+ Agent 不应该靠记忆猜命令参数。进入任务前先读轻量能力摘要;执行具体命令前再按需读取精确契约:
148
162
 
149
163
  ```bash
150
- lj-awb schema -f json
151
- lj-awb schema --domain image -f json
152
- lj-awb schema --domain video --command create -f json
164
+ lj-awb schema --brief -f json
165
+ lj-awb schema --domain create --command video -f json
153
166
  ```
154
167
 
168
+ 只有做覆盖校验、生成脚本或调试 schema 本身时,才需要读取完整 `lj-awb schema -f json`。
169
+
155
170
  正式创作前推荐做一次体检:
156
171
 
157
172
  ```bash
158
173
  lj-awb doctor --verify
159
174
  ```
160
175
 
161
- `auth status` 只检查本地是否配置 access key;`auth verify` 会联网校验 key 是否远端有效。`doctor` 默认只做本地检查;追加 `--verify` 后会联网校验 access key、当前用户和项目组。`schema` 返回每个命令的 `options[].key`,Agent 应使用这些 key 生成 CLI 参数,而不是解析自然语言 help。
176
+ `auth status` 只检查本地是否配置 access key;`auth verify` 会联网校验 key 是否远端有效。`doctor` 默认只做本地检查;追加 `--verify` 后会联网校验 access key、当前用户和项目组。精确 `schema` 返回每个命令的 `options[].key`,Agent 应使用这些 key 生成 CLI 参数,而不是解析自然语言 help。
177
+
178
+ `lj-awb` 在普通命令结束后会做非阻塞更新检查;如果有新版本,JSON 输出会在 `meta._notice.update` 里带上更新提示。Skill / Agent 看到这个提示后,应在完成当前任务后告诉用户当前版本和最新版本,并建议或直接运行 `lj-awb update`。真正安装更新只走显式 `lj-awb update`,`--check` 只检查不安装。
162
179
 
163
180
  `schema` 还包含面向 Agent 的执行约束:
164
181
 
@@ -177,7 +194,7 @@ lj-awb model options --model-group-code <modelGroupCode>
177
194
  lj-awb model create-spec --model-group-code <modelGroupCode>
178
195
  ```
179
196
 
180
- `model input-guide` 返回跨模型统一参数、`resources` 字段和 `reference_key` 规则。`model options` 专门返回模型参数、资源媒体约束和条件约束,例如 `params[].values`、`params[].defaultValue`、`resources[].mediaType`、`resources[].usage`、`resources[].fileTypes`、`resources[].maxFiles`、`resources[].supportLastFrameOnly`、`resources[].minDurationMs/maxDurationMs`、`constraints[].target`、`constraints[].conditions`。`model create-spec` 专门返回如何创建任务,例如 `inputRequirement`、`supportedIntents`、`preflight` 和 `examples`。默认 text 已经覆盖常用决策字段;只有脚本严格解析或需要完整嵌套结构时才追加 `-f json`。Agent 应用 `options` 选参数值、校验素材并判断联动约束,再用 `create-spec` 组装 `image create` / `video create`,不要直接把平台旧参数传给 create。上传音频是 `resources` 素材输入,具体 `audio:reference` 写法看 `input-guide` / `create-spec`;是否需要输出音效才使用 `--need-audio true/false`。
197
+ `model input-guide` 返回跨模型统一参数、`resources` 字段和 `reference_key` 规则。`model options` 专门返回模型参数、资源媒体约束和条件约束,例如 `params[].values`、`params[].defaultValue`、`resources[].mediaType`、`resources[].usage`、`resources[].fileTypes`、`resources[].maxFiles`、`resources[].supportLastFrameOnly`、`resources[].minDurationMs/maxDurationMs`、`constraints[].target`、`constraints[].conditions`。`model create-spec` 专门返回如何创建任务,例如 `inputRequirement`、`supportedIntents`、`preflight` 和 `examples`。默认 text 已经覆盖常用决策字段;只有脚本严格解析或需要完整嵌套结构时才追加 `-f json`。Agent 应用 `options` 选参数值、校验素材并判断联动约束,再用 `create-spec` 组装 `create image` / `create video`,不要直接把平台旧参数传给 create。上传音频是 `resources` 素材输入,具体 `audio:reference` 写法看 `input-guide` / `create-spec`;是否需要输出音效才使用 `--need-audio true/false`。
181
198
 
182
199
  ## 示例:参考图生成视频
183
200
 
@@ -188,7 +205,7 @@ lj-awb model input-guide -f json
188
205
  lj-awb model options --model-group-code <modelGroupCode> -f json
189
206
  lj-awb model create-spec --model-group-code <modelGroupCode> -f json
190
207
 
191
- lj-awb video fee \
208
+ lj-awb create video-fee \
192
209
  --model-group-code <modelGroupCode> \
193
210
  --prompt "参考女主首帧,在雨夜街头奔跑,电影感运镜" \
194
211
  --resource image:first_frame=./actor.png \
@@ -197,7 +214,7 @@ lj-awb video fee \
197
214
  --duration 5 \
198
215
  --project-group-no <projectGroupNo>
199
216
 
200
- lj-awb video create \
217
+ lj-awb create video \
201
218
  --model-group-code <modelGroupCode> \
202
219
  --prompt "参考女主首帧,在雨夜街头奔跑,电影感运镜" \
203
220
  --resource image:first_frame=./actor.png \
@@ -218,7 +235,7 @@ lj-awb task wait \
218
235
  帧素材也可以直接使用平台资产 ID;是否可传尾帧以 `model options.resources[].usage` 是否包含 `last_frame` 为准:
219
236
 
220
237
  ```bash
221
- lj-awb video create \
238
+ lj-awb create video \
222
239
  --model-group-code <modelGroupCode> \
223
240
  --prompt "参考首帧生成一段镜头推进视频" \
224
241
  --resource image:first_frame=asset:<assetId> \
@@ -235,9 +252,9 @@ lj-awb video create \
235
252
  如果参考图会复用,推荐先发布主体资产:
236
253
 
237
254
  ```bash
238
- lj-awb subject publish --name 女主 --primary-file ./actor.png --yes
239
- lj-awb subject wait --element-id <elementId> --wait-seconds 300
240
- lj-awb video create \
255
+ lj-awb create subject --model-code tx --name 女主 --resource primary:./actor.png --yes
256
+ lj-awb create subject-wait --element-id <elementId> --wait-seconds 300
257
+ lj-awb create video \
241
258
  --model-group-code <modelGroupCode> \
242
259
  --prompt "<<<女主>>> 在雨夜街头奔跑,电影感运镜" \
243
260
  --resource subject:reference:女主=asset:<externalId> \
@@ -245,9 +262,11 @@ lj-awb video create \
245
262
  --yes
246
263
  ```
247
264
 
248
- ## JSON 输出契约
265
+ ## 输出契约
266
+
267
+ 默认输出是 `pretty`:面向人类阅读的彩色标题、摘要区、自动换行表格和下一步建议。表格由 `cli-table3` 做终端渲染,不是 CSV;颜色由 `chalk` 渲染,设置 `NO_COLOR=1` 可关闭,`FORCE_COLOR=1` 或 `LINGJING_AWB_COLOR=1` 可强制开启。Agent / 脚本不要依赖默认 pretty 解析字段:需要稳定 envelope 时显式追加 `-f json` 或 `--json`;需要低 token 的紧凑 key-value 兼容输出时传 `-f text`;列表导出可用 `-f csv`,可读结构化输出可用 `-f yaml`。
249
268
 
250
- 默认输出是 compact text,适合终端和 Agent 低 token 读取;只有需要完整嵌套结构、稳定 JSON envelope 或脚本严格解析时才追加 `-f json` 或 `--json`。`schema` 通常使用 JSON;`model options` 和 `model create-spec` 默认 text 先读,必要时再切 JSON。
269
+ `schema` 通常使用 JSON;`model options` 和 `model create-spec` 面向人类时可直接读默认 pretty,Agent 做参数决策时建议使用 `-f text`,脚本严格解析或需要完整嵌套结构时再切 `-f json`。
251
270
 
252
271
  输出字段只保留后续动作不可替代的信息。默认不返回平台原始 `raw`、COS 签名细节、重复的首个结果字段;任务结果统一使用 `resultUrls` 表达。
253
272
 
@@ -273,7 +292,7 @@ lj-awb video create \
273
292
  "error": {
274
293
  "type": "auth_required",
275
294
  "message": "缺少 access key",
276
- "hint": "请设置 LINGJING_AWB_ACCESS_KEY / AWB_ACCESS_KEY,或运行 lj-awb auth login-key。"
295
+ "hint": "请设置 LINGJING_AWB_ACCESS_KEY,或运行 lj-awb auth login。"
277
296
  },
278
297
  "meta": {
279
298
  "command": "account info",
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { cpSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ export const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
8
+
9
+ export function findArgValue(args, name) {
10
+ for (let index = 0; index < args.length; index += 1) {
11
+ const arg = args[index];
12
+ if (arg === name) return args[index + 1];
13
+ if (arg.startsWith(`${name}=`)) return arg.slice(name.length + 1);
14
+ }
15
+ return undefined;
16
+ }
17
+
18
+ export function run(command, args, options = {}) {
19
+ process.stderr.write(`$ ${[command, ...args].join(' ')}\n`);
20
+ const result = spawnSync(command, args, {
21
+ cwd: options.cwd || repoRoot,
22
+ stdio: 'inherit',
23
+ });
24
+ if (result.error) {
25
+ process.stderr.write(`${result.error.message}\n`);
26
+ process.exit(1);
27
+ }
28
+ if (result.status !== 0) {
29
+ process.exit(result.status || 1);
30
+ }
31
+ }
32
+
33
+ export function capture(command, args, options = {}) {
34
+ return spawnSync(command, args, {
35
+ cwd: options.cwd || repoRoot,
36
+ encoding: 'utf8',
37
+ stdio: ['inherit', 'pipe', 'pipe'],
38
+ });
39
+ }
40
+
41
+ export function packageFilePaths(cwd = repoRoot) {
42
+ const result = capture('npm', ['pack', '--dry-run', '--json'], { cwd });
43
+ if (result.error) {
44
+ process.stderr.write(`${result.error.message}\n`);
45
+ process.exit(1);
46
+ }
47
+ if (result.status !== 0) {
48
+ process.exit(result.status || 1);
49
+ }
50
+ const packPlan = JSON.parse(result.stdout || '[]');
51
+ const files = packPlan[0]?.files?.map((item) => item.path).filter(Boolean) || [];
52
+ if (!files.length) {
53
+ process.stderr.write('npm pack --dry-run did not return package files.\n');
54
+ process.exit(1);
55
+ }
56
+ return files;
57
+ }
58
+
59
+ export function copyPackageFiles(stageDir, sourceRoot = repoRoot) {
60
+ for (const relativePath of packageFilePaths(sourceRoot)) {
61
+ const sourcePath = path.join(sourceRoot, relativePath);
62
+ const targetPath = path.join(stageDir, relativePath);
63
+ mkdirSync(path.dirname(targetPath), { recursive: true });
64
+ cpSync(sourcePath, targetPath, { recursive: true });
65
+ }
66
+ }
67
+
68
+ export function patchDefaultApiOrigin(stageDir, apiOrigin) {
69
+ const commonPath = path.join(stageDir, 'packages/awb-core/src/common.js');
70
+ const source = readFileSync(commonPath, 'utf8');
71
+ const next = source.replace(
72
+ /export const DEFAULT_API_ORIGIN = '[^']+';/,
73
+ `export const DEFAULT_API_ORIGIN = '${apiOrigin}';`,
74
+ );
75
+ if (next === source) {
76
+ process.stderr.write(`Could not patch DEFAULT_API_ORIGIN in ${commonPath}.\n`);
77
+ process.exit(1);
78
+ }
79
+ writeFileSync(commonPath, next, 'utf8');
80
+ }
81
+
82
+ export function packTarball(stageDir) {
83
+ process.stderr.write(`$ npm pack --pack-destination ${stageDir} --silent\n`);
84
+ const result = spawnSync('npm', ['pack', '--pack-destination', stageDir, '--silent'], {
85
+ cwd: stageDir,
86
+ encoding: 'utf8',
87
+ stdio: ['inherit', 'pipe', 'inherit'],
88
+ });
89
+ if (result.error) {
90
+ process.stderr.write(`${result.error.message}\n`);
91
+ process.exit(1);
92
+ }
93
+ if (result.status !== 0) {
94
+ process.exit(result.status || 1);
95
+ }
96
+ const tarball = result.stdout.trim().split(/\r?\n/).filter(Boolean).at(-1);
97
+ if (!tarball) {
98
+ process.stderr.write('npm pack did not return a tarball name.\n');
99
+ process.exit(1);
100
+ }
101
+ return path.join(stageDir, tarball);
102
+ }
103
+
104
+ export function ensureLoggedIn(registry) {
105
+ const result = capture('npm', ['whoami', `--registry=${registry}`]);
106
+ if (result.status === 0) {
107
+ process.stderr.write(`npm user: ${result.stdout.trim()}\n`);
108
+ return;
109
+ }
110
+ process.stderr.write([
111
+ `npm is not logged in for ${registry}.`,
112
+ `Run: npm login --registry=${registry}`,
113
+ '',
114
+ ].join('\n'));
115
+ process.exit(1);
116
+ }
117
+
118
+ export function ensureVersionNotPublished({ name, version, registry }) {
119
+ const spec = `${name}@${version}`;
120
+ const result = capture('npm', ['view', spec, 'version', `--registry=${registry}`]);
121
+ if (result.status === 0) {
122
+ process.stderr.write(`${spec} already exists on npm. Bump the version before publishing.\n`);
123
+ process.exit(1);
124
+ }
125
+ if (!/E404|404 Not Found|Not found/i.test(`${result.stderr}\n${result.stdout}`)) {
126
+ process.stderr.write(`Could not verify whether ${spec} exists on npm.\n`);
127
+ process.stderr.write(result.stderr || result.stdout || '');
128
+ process.exit(1);
129
+ }
130
+ }
package/build/build.mjs CHANGED
@@ -10,6 +10,7 @@ const passthroughArgs = target === rawArgs[0] ? rawArgs.slice(1) : rawArgs;
10
10
 
11
11
  const scriptByTarget = {
12
12
  pre: 'pre.mjs',
13
+ 'pre-publish': 'pre-publish.mjs',
13
14
  prod: 'prod.mjs',
14
15
  };
15
16
 
@@ -18,6 +19,8 @@ function printUsage() {
18
19
  'Usage:',
19
20
  ' npm run build -- pre',
20
21
  ' npm run build -- pre --dry-run',
22
+ ' npm run build -- pre-publish',
23
+ ' npm run build -- pre-publish --dry-run',
21
24
  ' npm run build -- prod',
22
25
  ' npm run build -- prod --dry-run',
23
26
  '',
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import path from 'node:path';
5
+ import {
6
+ copyPackageFiles,
7
+ ensureLoggedIn,
8
+ ensureVersionNotPublished,
9
+ findArgValue,
10
+ patchDefaultApiOrigin,
11
+ repoRoot,
12
+ run,
13
+ } from './_shared.mjs';
14
+
15
+ const pkg = JSON.parse(readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));
16
+ const passthroughArgs = process.argv.slice(2);
17
+ const registry = findArgValue(passthroughArgs, '--registry') || process.env.NPM_CONFIG_REGISTRY || 'https://registry.npmjs.org/';
18
+ const dryRun = process.env.NPM_PUBLISH_DRY_RUN === '1' || passthroughArgs.includes('--dry-run');
19
+ const PRE_API_ORIGIN = 'https://animeworkbench-pre.lingjingai.cn';
20
+ const PRE_PACKAGE_NAME = '@lingjingai/lj-awb-cli-pre';
21
+
22
+ function patchPackageName(stageDir) {
23
+ const pkgPath = path.join(stageDir, 'package.json');
24
+ const stagedPkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
25
+ stagedPkg.name = PRE_PACKAGE_NAME;
26
+ if (typeof stagedPkg.description === 'string') {
27
+ stagedPkg.description = `${stagedPkg.description} (pre-release build pointing to ${PRE_API_ORIGIN})`;
28
+ }
29
+ writeFileSync(pkgPath, `${JSON.stringify(stagedPkg, null, 2)}\n`, 'utf8');
30
+ }
31
+
32
+ process.stderr.write(`Preparing ${PRE_PACKAGE_NAME}@${pkg.version} for npm ${dryRun ? 'dry-run' : 'publish'} with default API origin ${PRE_API_ORIGIN}.\n`);
33
+
34
+ if (process.env.SKIP_CHECK !== '1') {
35
+ run('npm', ['run', 'check:local']);
36
+ }
37
+
38
+ ensureVersionNotPublished({ name: PRE_PACKAGE_NAME, version: pkg.version, registry });
39
+ if (!dryRun) {
40
+ ensureLoggedIn(registry);
41
+ }
42
+
43
+ const stageDir = mkdtempSync(path.join(tmpdir(), 'lj-awb-pre-publish-'));
44
+ try {
45
+ copyPackageFiles(stageDir);
46
+ patchDefaultApiOrigin(stageDir, PRE_API_ORIGIN);
47
+ patchPackageName(stageDir);
48
+ run('npm', [
49
+ 'publish',
50
+ '--access',
51
+ 'public',
52
+ `--registry=${registry}`,
53
+ ...passthroughArgs,
54
+ ], { cwd: stageDir });
55
+ } finally {
56
+ rmSync(stageDir, { recursive: true, force: true });
57
+ }
package/build/pre.mjs CHANGED
@@ -1,126 +1,28 @@
1
1
  #!/usr/bin/env node
2
- import { spawnSync } from 'node:child_process';
3
- import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { mkdtempSync, rmSync } from 'node:fs';
4
3
  import { tmpdir } from 'node:os';
5
4
  import path from 'node:path';
6
- import { fileURLToPath } from 'node:url';
5
+ import {
6
+ copyPackageFiles,
7
+ packTarball,
8
+ patchDefaultApiOrigin,
9
+ run,
10
+ } from './_shared.mjs';
7
11
 
8
- const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
9
12
  const PRE_API_ORIGIN = 'https://animeworkbench-pre.lingjingai.cn';
10
13
  const dryRun = process.env.NPM_INSTALL_DRY_RUN === '1' || process.argv.slice(2).includes('--dry-run');
11
14
  const forceInstall = process.env.NPM_INSTALL_FORCE === '1' || process.argv.slice(2).includes('--force');
12
15
 
13
- function commandEnv(overrides = {}) {
14
- return {
15
- ...process.env,
16
- LINGJING_AWB_API_ORIGIN: PRE_API_ORIGIN,
17
- ...overrides,
18
- };
19
- }
20
-
21
- function run(command, args, options = {}) {
22
- process.stderr.write(`$ ${[command, ...args].join(' ')}\n`);
23
- const result = spawnSync(command, args, {
24
- cwd: options.cwd || repoRoot,
25
- env: commandEnv(options.env),
26
- stdio: 'inherit',
27
- });
28
-
29
- if (result.error) {
30
- process.stderr.write(`${result.error.message}\n`);
31
- process.exit(1);
32
- }
33
- if (result.status !== 0) {
34
- process.exit(result.status || 1);
35
- }
36
- }
37
-
38
- function capture(command, args, options = {}) {
39
- return spawnSync(command, args, {
40
- cwd: options.cwd || repoRoot,
41
- env: commandEnv(options.env),
42
- encoding: 'utf8',
43
- stdio: ['inherit', 'pipe', 'inherit'],
44
- });
45
- }
46
-
47
- function packageFilePaths() {
48
- const result = capture('npm', ['pack', '--dry-run', '--json']);
49
- if (result.error) {
50
- process.stderr.write(`${result.error.message}\n`);
51
- process.exit(1);
52
- }
53
- if (result.status !== 0) {
54
- process.exit(result.status || 1);
55
- }
56
- const packPlan = JSON.parse(result.stdout || '[]');
57
- const files = packPlan[0]?.files?.map((item) => item.path).filter(Boolean) || [];
58
- if (!files.length) {
59
- process.stderr.write('npm pack --dry-run did not return package files.\n');
60
- process.exit(1);
61
- }
62
- return files;
63
- }
64
-
65
- function copyPackageFiles(stageDir) {
66
- for (const relativePath of packageFilePaths()) {
67
- const sourcePath = path.join(repoRoot, relativePath);
68
- const targetPath = path.join(stageDir, relativePath);
69
- mkdirSync(path.dirname(targetPath), { recursive: true });
70
- cpSync(sourcePath, targetPath, { recursive: true });
71
- }
72
- }
73
-
74
- function patchDefaultApiOrigin(stageDir, apiOrigin) {
75
- const commonPath = path.join(stageDir, 'packages/awb-core/src/common.js');
76
- const source = readFileSync(commonPath, 'utf8');
77
- const next = source.replace(
78
- /export const DEFAULT_API_ORIGIN = '[^']+';/,
79
- `export const DEFAULT_API_ORIGIN = '${apiOrigin}';`,
80
- );
81
- if (next === source) {
82
- process.stderr.write(`Could not patch DEFAULT_API_ORIGIN in ${commonPath}.\n`);
83
- process.exit(1);
84
- }
85
- writeFileSync(commonPath, next, 'utf8');
86
- }
87
-
88
- function packToTempDir(packDir, cwd = repoRoot) {
89
- process.stderr.write(`$ npm pack --pack-destination ${packDir} --silent\n`);
90
- const result = spawnSync('npm', ['pack', '--pack-destination', packDir, '--silent'], {
91
- cwd,
92
- env: commandEnv(),
93
- encoding: 'utf8',
94
- stdio: ['inherit', 'pipe', 'inherit'],
95
- });
96
-
97
- if (result.error) {
98
- process.stderr.write(`${result.error.message}\n`);
99
- process.exit(1);
100
- }
101
- if (result.status !== 0) {
102
- process.exit(result.status || 1);
103
- }
104
-
105
- const tarball = result.stdout.trim().split(/\r?\n/).filter(Boolean).at(-1);
106
- if (!tarball) {
107
- process.stderr.write('npm pack did not return a tarball name.\n');
108
- process.exit(1);
109
- }
110
- return path.join(packDir, tarball);
111
- }
112
-
113
16
  if (process.env.SKIP_CHECK !== '1') {
114
17
  run('npm', ['run', 'check:local']);
115
18
  }
116
19
 
117
- const packDir = mkdtempSync(path.join(tmpdir(), 'lj-awb-pack-'));
118
20
  const stageDir = mkdtempSync(path.join(tmpdir(), 'lj-awb-pre-src-'));
119
21
  try {
120
22
  process.stderr.write(`Preparing local pre build with default API origin ${PRE_API_ORIGIN}.\n`);
121
23
  copyPackageFiles(stageDir);
122
24
  patchDefaultApiOrigin(stageDir, PRE_API_ORIGIN);
123
- const tarballPath = packToTempDir(packDir, stageDir);
25
+ const tarballPath = packTarball(stageDir);
124
26
  run('npm', [
125
27
  'install',
126
28
  '-g',
@@ -136,6 +38,5 @@ try {
136
38
  process.stderr.write('Installed local pre build globally from packed tarball.\n');
137
39
  }
138
40
  } finally {
139
- rmSync(packDir, { recursive: true, force: true });
140
41
  rmSync(stageDir, { recursive: true, force: true });
141
42
  }
package/build/prod.mjs CHANGED
@@ -1,60 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync } from 'node:fs';
3
- import { spawnSync } from 'node:child_process';
4
3
  import path from 'node:path';
5
- import { fileURLToPath } from 'node:url';
4
+ import {
5
+ ensureLoggedIn,
6
+ ensureVersionNotPublished,
7
+ findArgValue,
8
+ repoRoot,
9
+ run,
10
+ } from './_shared.mjs';
6
11
 
7
- const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
8
12
  const pkg = JSON.parse(readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));
9
13
  const passthroughArgs = process.argv.slice(2);
10
14
  const registry = findArgValue(passthroughArgs, '--registry') || process.env.NPM_CONFIG_REGISTRY || 'https://registry.npmjs.org/';
11
15
  const dryRun = process.env.NPM_PUBLISH_DRY_RUN === '1' || passthroughArgs.includes('--dry-run');
12
16
  const PROD_API_ORIGIN = 'https://animeworkbench.lingjingai.cn';
13
17
 
14
- function commandEnv(overrides = {}) {
15
- return {
16
- ...process.env,
17
- LINGJING_AWB_API_ORIGIN: PROD_API_ORIGIN,
18
- ...overrides,
19
- };
20
- }
21
-
22
- function findArgValue(args, name) {
23
- for (let index = 0; index < args.length; index += 1) {
24
- const arg = args[index];
25
- if (arg === name) return args[index + 1];
26
- if (arg.startsWith(`${name}=`)) return arg.slice(name.length + 1);
27
- }
28
- return undefined;
29
- }
30
-
31
- function run(command, args, options = {}) {
32
- process.stderr.write(`$ ${[command, ...args].join(' ')}\n`);
33
- const result = spawnSync(command, args, {
34
- cwd: repoRoot,
35
- env: commandEnv(options.env),
36
- stdio: 'inherit',
37
- ...options,
38
- });
39
-
40
- if (result.error) {
41
- process.stderr.write(`${result.error.message}\n`);
42
- process.exit(1);
43
- }
44
- if (result.status !== 0) {
45
- process.exit(result.status || 1);
46
- }
47
- }
48
-
49
- function capture(command, args) {
50
- return spawnSync(command, args, {
51
- cwd: repoRoot,
52
- env: commandEnv(),
53
- encoding: 'utf8',
54
- stdio: ['inherit', 'pipe', 'pipe'],
55
- });
56
- }
57
-
58
18
  function ensureProductionDefaultApiOrigin() {
59
19
  const commonPath = path.join(repoRoot, 'packages/awb-core/src/common.js');
60
20
  const source = readFileSync(commonPath, 'utf8');
@@ -70,35 +30,6 @@ function ensureProductionDefaultApiOrigin() {
70
30
  }
71
31
  }
72
32
 
73
- function ensureLoggedIn() {
74
- const result = capture('npm', ['whoami', `--registry=${registry}`]);
75
- if (result.status === 0) {
76
- process.stderr.write(`npm user: ${result.stdout.trim()}\n`);
77
- return;
78
- }
79
-
80
- process.stderr.write([
81
- `npm is not logged in for ${registry}.`,
82
- `Run: npm login --registry=${registry}`,
83
- '',
84
- ].join('\n'));
85
- process.exit(1);
86
- }
87
-
88
- function ensureVersionNotPublished() {
89
- const spec = `${pkg.name}@${pkg.version}`;
90
- const result = capture('npm', ['view', spec, 'version', `--registry=${registry}`]);
91
- if (result.status === 0) {
92
- process.stderr.write(`${spec} already exists on npm. Bump the version before publishing.\n`);
93
- process.exit(1);
94
- }
95
- if (!/E404|404 Not Found|Not found/i.test(`${result.stderr}\n${result.stdout}`)) {
96
- process.stderr.write(`Could not verify whether ${spec} exists on npm.\n`);
97
- process.stderr.write(result.stderr || result.stdout || '');
98
- process.exit(1);
99
- }
100
- }
101
-
102
33
  ensureProductionDefaultApiOrigin();
103
34
 
104
35
  process.stderr.write(`Preparing ${pkg.name}@${pkg.version} for npm ${dryRun ? 'dry-run' : 'publish'} with default API origin ${PROD_API_ORIGIN}.\n`);
@@ -107,9 +38,9 @@ if (process.env.SKIP_CHECK !== '1') {
107
38
  run('npm', ['run', 'check:local']);
108
39
  }
109
40
 
110
- ensureVersionNotPublished();
41
+ ensureVersionNotPublished({ name: pkg.name, version: pkg.version, registry });
111
42
  if (!dryRun) {
112
- ensureLoggedIn();
43
+ ensureLoggedIn(registry);
113
44
  }
114
45
 
115
46
  run('npm', [
package/install.mjs CHANGED
@@ -34,6 +34,7 @@ const skillTargetDirs = explicitSkillTargetDir
34
34
  : [
35
35
  join(homedir(), '.cc-switch', 'skills', 'lj-awb'),
36
36
  join(codexHomeDir, 'skills', 'lj-awb'),
37
+ join(homedir(), '.claude', 'skills', 'lj-awb'),
37
38
  ];
38
39
 
39
40
  if (process.env.LINGJING_AWB_SKIP_SKILL_INSTALL === '1' || process.env.ANIME_SKIP_SKILL_INSTALL === '1') {