@lingjingai/lj-awb-cli 0.3.14 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +36 -28
  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 +15 -51
  6. package/build/prod.mjs +25 -68
  7. package/install.mjs +1 -0
  8. package/package.json +10 -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 +7 -2
  12. package/packages/awb-core/src/api.js +33 -64
  13. package/packages/awb-core/src/artifact.js +936 -0
  14. package/packages/awb-core/src/auth.js +1 -1
  15. package/packages/awb-core/src/commands.js +668 -97
  16. package/packages/awb-core/src/common.js +3 -2
  17. package/packages/awb-core/src/output.js +2380 -106
  18. package/packages/awb-core/src/services.js +868 -114
  19. package/packages/awb-core/src/standalone.js +985 -235
  20. package/skills/lj-awb/SKILL.md +84 -73
  21. package/skills/lj-awb/VERSION +1 -1
  22. package/skills/lj-awb/compat.json +3 -3
  23. package/skills/lj-awb/modules/account.md +20 -7
  24. package/skills/lj-awb/modules/artifact/asset.md +64 -0
  25. package/skills/lj-awb/modules/artifact/clip.md +65 -0
  26. package/skills/lj-awb/modules/artifact/script.md +37 -0
  27. package/skills/lj-awb/modules/artifact/video.md +65 -0
  28. package/skills/lj-awb/modules/artifact.md +65 -0
  29. package/skills/lj-awb/modules/asset.md +50 -11
  30. package/skills/lj-awb/modules/auth.md +12 -5
  31. package/skills/lj-awb/modules/create-contract.md +23 -14
  32. package/skills/lj-awb/modules/create.md +37 -0
  33. package/skills/lj-awb/modules/credits.md +6 -0
  34. package/skills/lj-awb/modules/driver.md +125 -0
  35. package/skills/lj-awb/modules/evals.md +84 -36
  36. package/skills/lj-awb/modules/image.md +19 -10
  37. package/skills/lj-awb/modules/model.md +31 -31
  38. package/skills/lj-awb/modules/project.md +7 -0
  39. package/skills/lj-awb/modules/subject.md +28 -7
  40. package/skills/lj-awb/modules/task-manual.md +40 -28
  41. package/skills/lj-awb/modules/task.md +70 -8
  42. package/skills/lj-awb/modules/upload.md +18 -2
  43. package/skills/lj-awb/modules/video.md +30 -26
  44. package/skills/lj-awb/modules/workflows.md +274 -145
  45. package/skills/lj-awb/references/error-codes.md +109 -0
  46. package/skills/lj-awb/references/model-options-read.md +19 -12
  47. package/skills/lj-awb/references/output-fields.md +118 -0
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,11 +22,9 @@ CLI 本身只负责平台调用、参数校验、精简输出和安全确认;
22
22
  | 积分 | `credits` | 可扣积分余额、项目组预算、任务用量统计 |
23
23
  | 模型 | `model` | 生图 / 生视频模型发现、模型参数白名单 |
24
24
  | 上传 | `upload` | 本地图片 / 视频 / 音频上传为平台可访问素材 |
25
- | 图片 | `image` | 生图估价、提交、批量提交、状态查询 |
26
- | 视频 | `video` | 生视频估价、提交、批量提交、状态查询、去字幕 |
25
+ | 创建 | `create` | 生图、生视频、主体、音色、素材和去字幕提交 |
27
26
  | 任务 | `task` | 任务列表、等待、任务台账和台账轮询 |
28
- | 资产 | `asset` | 素材库匹配、素材组、素材注册 |
29
- | 主体 | `subject` | 可复用主体资产发布与查询 |
27
+ | 最终产物 | `artifact` | Workbench 剧本、资产、视频最终产物 CRUD 与本地 JSON 导入 |
30
28
 
31
29
  ## 环境要求
32
30
 
@@ -41,7 +39,7 @@ export LINGJING_AWB_API_ORIGIN=https://animeworkbench.lingjingai.cn
41
39
  export LINGJING_AWB_ACCESS_KEY=<access_key>
42
40
  ```
43
41
 
44
- 兼容的 access key 变量:`LINGJING_AWB_ACCESS_KEY`、`AWB_ACCESS_KEY`、`AWB_CODE`、`ANIME_ACCESS_KEY`。
42
+ `lj-awb` 只读取 `LINGJING_AWB_ACCESS_KEY` 作为环境变量 access key。
45
43
 
46
44
  ## 安装与运行
47
45
 
@@ -51,6 +49,7 @@ export LINGJING_AWB_ACCESS_KEY=<access_key>
51
49
  npm install -g @lingjingai/lj-awb-cli
52
50
  lj-awb --help
53
51
  lj-awb auth status
52
+ lj-awb auth verify
54
53
  ```
55
54
 
56
55
  安装包的 `postinstall` 会默认把随包分发的 `lj-awb` skill 安装到:
@@ -81,13 +80,13 @@ macOS 本地 wrapper `packages/awb-cli/bin/lj-awb` 会自动补充 Node 证书
81
80
  保存 access key 到本地认证文件:
82
81
 
83
82
  ```bash
84
- lj-awb auth login-key --access-key <access_key>
83
+ lj-awb auth login --access-key <access_key>
85
84
  ```
86
85
 
87
86
  从环境变量读取并保存:
88
87
 
89
88
  ```bash
90
- LINGJING_AWB_ACCESS_KEY=<access_key> lj-awb auth login-key --from-env
89
+ LINGJING_AWB_ACCESS_KEY=<access_key> lj-awb auth login
91
90
  ```
92
91
 
93
92
  不落盘,直接让每次调用读取环境变量:
@@ -111,9 +110,11 @@ lj-awb account info
111
110
  ```bash
112
111
  lj-awb doctor
113
112
  lj-awb doctor --verify
113
+ lj-awb schema --brief -f json
114
114
  lj-awb schema -f json
115
- lj-awb schema --domain video -f json
115
+ lj-awb schema --domain create -f json
116
116
  lj-awb auth status
117
+ lj-awb auth verify
117
118
  lj-awb account info
118
119
  lj-awb account teams
119
120
  lj-awb project list
@@ -125,34 +126,38 @@ lj-awb model video-models --model Seedance
125
126
  lj-awb model input-guide
126
127
  lj-awb model options --model-group-code <modelGroupCode>
127
128
  lj-awb model create-spec --model-group-code <modelGroupCode>
129
+ lj-awb artifact script import --project-id <projectId> --input-file 1_script/output/script.json --dry-run
130
+ lj-awb artifact asset import --project-id <projectId> --input-dir 2_asset/output --dry-run
131
+ lj-awb artifact video import-storyboard --project-id <projectId> --input-file 3_footage/output/ep001/ep001_storyboard.json --dry-run
128
132
  ```
129
133
 
130
134
  正式写入、切换上下文、批量和扣费命令都支持安全确认:
131
135
 
132
136
  ```bash
133
- lj-awb image create ... --dry-run
134
- lj-awb image create ... --yes
137
+ lj-awb create image ... --dry-run
138
+ lj-awb create image ... --yes
135
139
  ```
136
140
 
137
141
  缺少 `--yes` 时,CLI 返回 `confirmation_required`,退出码为 `10`。`task wait` 超时返回 `task_still_running`,退出码为 `20`。
138
142
 
139
143
  ## Agent 接入建议
140
144
 
141
- Agent 不应该靠记忆猜命令参数。进入任务前推荐先读取机器可读契约:
145
+ Agent 不应该靠记忆猜命令参数。进入任务前先读轻量能力摘要;执行具体命令前再按需读取精确契约:
142
146
 
143
147
  ```bash
144
- lj-awb schema -f json
145
- lj-awb schema --domain image -f json
146
- lj-awb schema --domain video --command create -f json
148
+ lj-awb schema --brief -f json
149
+ lj-awb schema --domain create --command video -f json
147
150
  ```
148
151
 
152
+ 只有做覆盖校验、生成脚本或调试 schema 本身时,才需要读取完整 `lj-awb schema -f json`。
153
+
149
154
  正式创作前推荐做一次体检:
150
155
 
151
156
  ```bash
152
157
  lj-awb doctor --verify
153
158
  ```
154
159
 
155
- `doctor` 默认只做本地检查;追加 `--verify` 后会联网校验 access key、当前用户和项目组。`schema` 返回每个命令的 `options[].key`,Agent 应使用这些 key 生成 CLI 参数,而不是解析自然语言 help。
160
+ `auth status` 只检查本地是否配置 access key;`auth verify` 会联网校验 key 是否远端有效。`doctor` 默认只做本地检查;追加 `--verify` 后会联网校验 access key、当前用户和项目组。精确 `schema` 返回每个命令的 `options[].key`,Agent 应使用这些 key 生成 CLI 参数,而不是解析自然语言 help。
156
161
 
157
162
  `schema` 还包含面向 Agent 的执行约束:
158
163
 
@@ -171,7 +176,7 @@ lj-awb model options --model-group-code <modelGroupCode>
171
176
  lj-awb model create-spec --model-group-code <modelGroupCode>
172
177
  ```
173
178
 
174
- `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`。
179
+ `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`。
175
180
 
176
181
  ## 示例:参考图生成视频
177
182
 
@@ -182,7 +187,7 @@ lj-awb model input-guide -f json
182
187
  lj-awb model options --model-group-code <modelGroupCode> -f json
183
188
  lj-awb model create-spec --model-group-code <modelGroupCode> -f json
184
189
 
185
- lj-awb video fee \
190
+ lj-awb create video-fee \
186
191
  --model-group-code <modelGroupCode> \
187
192
  --prompt "参考女主首帧,在雨夜街头奔跑,电影感运镜" \
188
193
  --resource image:first_frame=./actor.png \
@@ -191,7 +196,7 @@ lj-awb video fee \
191
196
  --duration 5 \
192
197
  --project-group-no <projectGroupNo>
193
198
 
194
- lj-awb video create \
199
+ lj-awb create video \
195
200
  --model-group-code <modelGroupCode> \
196
201
  --prompt "参考女主首帧,在雨夜街头奔跑,电影感运镜" \
197
202
  --resource image:first_frame=./actor.png \
@@ -212,7 +217,7 @@ lj-awb task wait \
212
217
  帧素材也可以直接使用平台资产 ID;是否可传尾帧以 `model options.resources[].usage` 是否包含 `last_frame` 为准:
213
218
 
214
219
  ```bash
215
- lj-awb video create \
220
+ lj-awb create video \
216
221
  --model-group-code <modelGroupCode> \
217
222
  --prompt "参考首帧生成一段镜头推进视频" \
218
223
  --resource image:first_frame=asset:<assetId> \
@@ -229,9 +234,9 @@ lj-awb video create \
229
234
  如果参考图会复用,推荐先发布主体资产:
230
235
 
231
236
  ```bash
232
- lj-awb subject publish --name 女主 --primary-file ./actor.png --yes
233
- lj-awb subject wait --element-id <elementId> --wait-seconds 300
234
- lj-awb video create \
237
+ lj-awb create subject --model-code tx --name 女主 --resource primary:./actor.png --yes
238
+ lj-awb create subject-wait --element-id <elementId> --wait-seconds 300
239
+ lj-awb create video \
235
240
  --model-group-code <modelGroupCode> \
236
241
  --prompt "<<<女主>>> 在雨夜街头奔跑,电影感运镜" \
237
242
  --resource subject:reference:女主=asset:<externalId> \
@@ -239,9 +244,11 @@ lj-awb video create \
239
244
  --yes
240
245
  ```
241
246
 
242
- ## JSON 输出契约
247
+ ## 输出契约
248
+
249
+ 默认输出是 `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`。
243
250
 
244
- 默认输出是 compact text,适合终端和 Agent 低 token 读取;只有需要完整嵌套结构、稳定 JSON envelope 或脚本严格解析时才追加 `-f json` 或 `--json`。`schema` 通常使用 JSON;`model options` 和 `model create-spec` 默认 text 先读,必要时再切 JSON。
251
+ `schema` 通常使用 JSON;`model options` 和 `model create-spec` 面向人类时可直接读默认 pretty,Agent 做参数决策时建议使用 `-f text`,脚本严格解析或需要完整嵌套结构时再切 `-f json`。
245
252
 
246
253
  输出字段只保留后续动作不可替代的信息。默认不返回平台原始 `raw`、COS 签名细节、重复的首个结果字段;任务结果统一使用 `resultUrls` 表达。
247
254
 
@@ -267,7 +274,7 @@ lj-awb video create \
267
274
  "error": {
268
275
  "type": "auth_required",
269
276
  "message": "缺少 access key",
270
- "hint": "请设置 LINGJING_AWB_ACCESS_KEY / AWB_ACCESS_KEY,或运行 lj-awb auth login-key。"
277
+ "hint": "请设置 LINGJING_AWB_ACCESS_KEY,或运行 lj-awb auth login。"
271
278
  },
272
279
  "meta": {
273
280
  "command": "account info",
@@ -309,12 +316,13 @@ anime-cli/
309
316
  ## 开发命令
310
317
 
311
318
  ```bash
319
+ npm run check:local
312
320
  npm run check
313
321
  npm run smoke
314
322
  npm run version:sync -- 0.3.5
315
323
  ```
316
324
 
317
- `npm run check` 会做 Node 语法检查、shell wrapper 检查和 skill 元数据校验。`npm run smoke` 会运行帮助命令和无网络写入风险的认证状态检查。
325
+ `npm run check:local` 会做 Node 语法检查、shell wrapper 检查、skill 元数据和 schema 校验,不需要 access key。`npm run check` 会额外执行真实平台契约校验,需要本地或环境变量中有可用 access key。`npm run build:pre` / `npm run build:prod` 发布构建只自动执行 `check:local`,避免被本机过期平台凭据阻断;需要真实平台回归时单独运行 `npm run check:real`。`npm run smoke` 会运行帮助命令和无网络写入风险的认证状态检查。
318
326
 
319
327
  ## 文档索引
320
328
 
@@ -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,64 +1,28 @@
1
1
  #!/usr/bin/env node
2
- import { spawnSync } from 'node:child_process';
3
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';
7
-
8
- const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
5
+ import {
6
+ copyPackageFiles,
7
+ packTarball,
8
+ patchDefaultApiOrigin,
9
+ run,
10
+ } from './_shared.mjs';
11
+
12
+ const PRE_API_ORIGIN = 'https://animeworkbench-pre.lingjingai.cn';
9
13
  const dryRun = process.env.NPM_INSTALL_DRY_RUN === '1' || process.argv.slice(2).includes('--dry-run');
10
14
  const forceInstall = process.env.NPM_INSTALL_FORCE === '1' || process.argv.slice(2).includes('--force');
11
15
 
12
- function run(command, args, options = {}) {
13
- process.stderr.write(`$ ${[command, ...args].join(' ')}\n`);
14
- const result = spawnSync(command, args, {
15
- cwd: repoRoot,
16
- env: process.env,
17
- stdio: 'inherit',
18
- ...options,
19
- });
20
-
21
- if (result.error) {
22
- process.stderr.write(`${result.error.message}\n`);
23
- process.exit(1);
24
- }
25
- if (result.status !== 0) {
26
- process.exit(result.status || 1);
27
- }
28
- }
29
-
30
- function packToTempDir(packDir) {
31
- process.stderr.write(`$ npm pack --pack-destination ${packDir} --silent\n`);
32
- const result = spawnSync('npm', ['pack', '--pack-destination', packDir, '--silent'], {
33
- cwd: repoRoot,
34
- env: process.env,
35
- encoding: 'utf8',
36
- stdio: ['inherit', 'pipe', 'inherit'],
37
- });
38
-
39
- if (result.error) {
40
- process.stderr.write(`${result.error.message}\n`);
41
- process.exit(1);
42
- }
43
- if (result.status !== 0) {
44
- process.exit(result.status || 1);
45
- }
46
-
47
- const tarball = result.stdout.trim().split(/\r?\n/).filter(Boolean).at(-1);
48
- if (!tarball) {
49
- process.stderr.write('npm pack did not return a tarball name.\n');
50
- process.exit(1);
51
- }
52
- return path.join(packDir, tarball);
53
- }
54
-
55
16
  if (process.env.SKIP_CHECK !== '1') {
56
- run('npm', ['run', 'check']);
17
+ run('npm', ['run', 'check:local']);
57
18
  }
58
19
 
59
- const packDir = mkdtempSync(path.join(tmpdir(), 'lj-awb-pack-'));
20
+ const stageDir = mkdtempSync(path.join(tmpdir(), 'lj-awb-pre-src-'));
60
21
  try {
61
- const tarballPath = packToTempDir(packDir);
22
+ process.stderr.write(`Preparing local pre build with default API origin ${PRE_API_ORIGIN}.\n`);
23
+ copyPackageFiles(stageDir);
24
+ patchDefaultApiOrigin(stageDir, PRE_API_ORIGIN);
25
+ const tarballPath = packTarball(stageDir);
62
26
  run('npm', [
63
27
  'install',
64
28
  '-g',
@@ -74,5 +38,5 @@ try {
74
38
  process.stderr.write('Installed local pre build globally from packed tarball.\n');
75
39
  }
76
40
  } finally {
77
- rmSync(packDir, { recursive: true, force: true });
41
+ rmSync(stageDir, { recursive: true, force: true });
78
42
  }
package/build/prod.mjs CHANGED
@@ -1,89 +1,46 @@
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
-
13
- function findArgValue(args, name) {
14
- for (let index = 0; index < args.length; index += 1) {
15
- const arg = args[index];
16
- if (arg === name) return args[index + 1];
17
- if (arg.startsWith(`${name}=`)) return arg.slice(name.length + 1);
18
- }
19
- return undefined;
20
- }
21
-
22
- function run(command, args, options = {}) {
23
- process.stderr.write(`$ ${[command, ...args].join(' ')}\n`);
24
- const result = spawnSync(command, args, {
25
- cwd: repoRoot,
26
- env: process.env,
27
- stdio: 'inherit',
28
- ...options,
29
- });
30
-
31
- if (result.error) {
32
- process.stderr.write(`${result.error.message}\n`);
16
+ const PROD_API_ORIGIN = 'https://animeworkbench.lingjingai.cn';
17
+
18
+ function ensureProductionDefaultApiOrigin() {
19
+ const commonPath = path.join(repoRoot, 'packages/awb-core/src/common.js');
20
+ const source = readFileSync(commonPath, 'utf8');
21
+ const match = source.match(/export const DEFAULT_API_ORIGIN = '([^']+)';/);
22
+ const actual = match?.[1] || null;
23
+ if (actual !== PROD_API_ORIGIN) {
24
+ process.stderr.write([
25
+ `Refusing to publish prod build with DEFAULT_API_ORIGIN=${actual || '(missing)'}.`,
26
+ `Expected ${PROD_API_ORIGIN}.`,
27
+ '',
28
+ ].join('\n'));
33
29
  process.exit(1);
34
30
  }
35
- if (result.status !== 0) {
36
- process.exit(result.status || 1);
37
- }
38
- }
39
-
40
- function capture(command, args) {
41
- return spawnSync(command, args, {
42
- cwd: repoRoot,
43
- env: process.env,
44
- encoding: 'utf8',
45
- stdio: ['inherit', 'pipe', 'pipe'],
46
- });
47
31
  }
48
32
 
49
- function ensureLoggedIn() {
50
- const result = capture('npm', ['whoami', `--registry=${registry}`]);
51
- if (result.status === 0) {
52
- process.stderr.write(`npm user: ${result.stdout.trim()}\n`);
53
- return;
54
- }
55
-
56
- process.stderr.write([
57
- `npm is not logged in for ${registry}.`,
58
- `Run: npm login --registry=${registry}`,
59
- '',
60
- ].join('\n'));
61
- process.exit(1);
62
- }
63
-
64
- function ensureVersionNotPublished() {
65
- const spec = `${pkg.name}@${pkg.version}`;
66
- const result = capture('npm', ['view', spec, 'version', `--registry=${registry}`]);
67
- if (result.status === 0) {
68
- process.stderr.write(`${spec} already exists on npm. Bump the version before publishing.\n`);
69
- process.exit(1);
70
- }
71
- if (!/E404|404 Not Found|Not found/i.test(`${result.stderr}\n${result.stdout}`)) {
72
- process.stderr.write(`Could not verify whether ${spec} exists on npm.\n`);
73
- process.stderr.write(result.stderr || result.stdout || '');
74
- process.exit(1);
75
- }
76
- }
33
+ ensureProductionDefaultApiOrigin();
77
34
 
78
- process.stderr.write(`Preparing ${pkg.name}@${pkg.version} for npm ${dryRun ? 'dry-run' : 'publish'}.\n`);
35
+ process.stderr.write(`Preparing ${pkg.name}@${pkg.version} for npm ${dryRun ? 'dry-run' : 'publish'} with default API origin ${PROD_API_ORIGIN}.\n`);
79
36
 
80
37
  if (process.env.SKIP_CHECK !== '1') {
81
- run('npm', ['run', 'check']);
38
+ run('npm', ['run', 'check:local']);
82
39
  }
83
40
 
84
- ensureVersionNotPublished();
41
+ ensureVersionNotPublished({ name: pkg.name, version: pkg.version, registry });
85
42
  if (!dryRun) {
86
- ensureLoggedIn();
43
+ ensureLoggedIn(registry);
87
44
  }
88
45
 
89
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') {
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@lingjingai/lj-awb-cli",
3
- "version": "0.3.14",
3
+ "version": "0.4.0",
4
4
  "description": "Lingjing AWB CLI monorepo with shared core, standalone CLI, and agent skills",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {
8
8
  "lj-awb": "packages/awb-cli/bin/lj-awb"
9
9
  },
10
+ "dependencies": {
11
+ "chalk": "^5.6.2",
12
+ "cli-table3": "^0.6.5"
13
+ },
10
14
  "engines": {
11
15
  "node": ">=20"
12
16
  },
@@ -16,10 +20,13 @@
16
20
  "scripts": {
17
21
  "build": "node build/build.mjs",
18
22
  "build:pre": "node build/pre.mjs",
23
+ "build:pre-publish": "node build/pre-publish.mjs",
19
24
  "build:prod": "node build/prod.mjs",
20
- "check": "node --check install.mjs && node --check packages/awb-core/src/common.js && node --check packages/awb-core/src/api.js && node --check packages/awb-core/src/auth.js && node --check packages/awb-core/src/output.js && node --check packages/awb-core/src/services.js && node --check packages/awb-core/src/commands.js && node --check packages/awb-core/src/standalone.js && sh -n packages/awb-cli/bin/lj-awb && node --check packages/awb-cli/bin/lj-awb.js && node --check build/build.mjs && node --check build/pre.mjs && node --check build/prod.mjs && node --check scripts/run-openapi-cli-examples-real.mjs && node --check scripts/validate-cli-schema.mjs && node --check scripts/validate-cli-output-contract.mjs && node scripts/validate-skill-meta.mjs && node scripts/validate-cli-schema.mjs && node scripts/validate-cli-output-contract.mjs && node scripts/validate-openapi-cli-examples.mjs",
25
+ "check": "npm run check:local && npm run check:real",
26
+ "check:local": "node --check install.mjs && node --check packages/awb-core/src/common.js && node --check packages/awb-core/src/api.js && node --check packages/awb-core/src/artifact.js && node --check packages/awb-core/src/auth.js && node --check packages/awb-core/src/output.js && node --check packages/awb-core/src/services.js && node --check packages/awb-core/src/commands.js && node --check packages/awb-core/src/standalone.js && sh -n packages/awb-cli/bin/lj-awb && node --check packages/awb-cli/bin/lj-awb.js && node --check build/build.mjs && node --check build/_shared.mjs && node --check build/pre.mjs && node --check build/pre-publish.mjs && node --check build/prod.mjs && node --check scripts/run-openapi-cli-examples-real.mjs && node --check scripts/validate-cli-schema.mjs && node --check scripts/validate-cli-output-contract.mjs && node --check scripts/validate-cli-command-coverage.mjs && node scripts/validate-skill-meta.mjs && node scripts/validate-cli-schema.mjs && node scripts/validate-cli-command-coverage.mjs",
27
+ "check:real": "node scripts/validate-cli-output-contract.mjs && node scripts/validate-openapi-cli-examples.mjs",
21
28
  "test:openapi-real": "node scripts/run-openapi-cli-examples-real.mjs",
22
- "smoke": "packages/awb-cli/bin/lj-awb --help && packages/awb-cli/bin/lj-awb auth status -f json",
29
+ "smoke": "packages/awb-cli/bin/lj-awb --help && packages/awb-cli/bin/lj-awb auth status -f json && packages/awb-cli/bin/lj-awb system && packages/awb-cli/bin/lj-awb auth && packages/awb-cli/bin/lj-awb account && packages/awb-cli/bin/lj-awb project && packages/awb-cli/bin/lj-awb credits && packages/awb-cli/bin/lj-awb upload && packages/awb-cli/bin/lj-awb model && packages/awb-cli/bin/lj-awb create && packages/awb-cli/bin/lj-awb task && packages/awb-cli/bin/lj-awb artifact && packages/awb-cli/bin/lj-awb schema -f json >/dev/null",
23
30
  "postinstall": "node install.mjs",
24
31
  "version:sync": "node scripts/sync-versions.mjs"
25
32
  },
@@ -13,7 +13,4 @@ node bin/lj-awb.js auth status -f json
13
13
 
14
14
  ```bash
15
15
  export LINGJING_AWB_ACCESS_KEY=<access_key>
16
- # 兼容 AWB 既有变量:
17
- export AWB_ACCESS_KEY=<access_key>
18
- export AWB_CODE=<access_key>
19
16
  ```