@lingjingai/lj-awb-cli 0.3.15 → 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 +28 -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 +279 -118
  16. package/packages/awb-core/src/common.js +3 -2
  17. package/packages/awb-core/src/output.js +2310 -106
  18. package/packages/awb-core/src/services.js +855 -113
  19. package/packages/awb-core/src/standalone.js +841 -242
  20. package/skills/lj-awb/SKILL.md +84 -74
  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 +31 -52
  29. package/skills/lj-awb/modules/asset.md +50 -11
  30. package/skills/lj-awb/modules/auth.md +10 -4
  31. package/skills/lj-awb/modules/create-contract.md +21 -12
  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 -12
  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 +32 -28
  41. package/skills/lj-awb/modules/task.md +70 -8
  42. package/skills/lj-awb/modules/upload.md +16 -2
  43. package/skills/lj-awb/modules/video.md +30 -28
  44. package/skills/lj-awb/modules/workflows.md +232 -169
  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,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
 
@@ -83,13 +80,13 @@ macOS 本地 wrapper `packages/awb-cli/bin/lj-awb` 会自动补充 Node 证书
83
80
  保存 access key 到本地认证文件:
84
81
 
85
82
  ```bash
86
- lj-awb auth login-key --access-key <access_key>
83
+ lj-awb auth login --access-key <access_key>
87
84
  ```
88
85
 
89
86
  从环境变量读取并保存:
90
87
 
91
88
  ```bash
92
- LINGJING_AWB_ACCESS_KEY=<access_key> lj-awb auth login-key --from-env
89
+ LINGJING_AWB_ACCESS_KEY=<access_key> lj-awb auth login
93
90
  ```
94
91
 
95
92
  不落盘,直接让每次调用读取环境变量:
@@ -113,8 +110,9 @@ lj-awb account info
113
110
  ```bash
114
111
  lj-awb doctor
115
112
  lj-awb doctor --verify
113
+ lj-awb schema --brief -f json
116
114
  lj-awb schema -f json
117
- lj-awb schema --domain video -f json
115
+ lj-awb schema --domain create -f json
118
116
  lj-awb auth status
119
117
  lj-awb auth verify
120
118
  lj-awb account info
@@ -136,29 +134,30 @@ lj-awb artifact video import-storyboard --project-id <projectId> --input-file 3_
136
134
  正式写入、切换上下文、批量和扣费命令都支持安全确认:
137
135
 
138
136
  ```bash
139
- lj-awb image create ... --dry-run
140
- lj-awb image create ... --yes
137
+ lj-awb create image ... --dry-run
138
+ lj-awb create image ... --yes
141
139
  ```
142
140
 
143
141
  缺少 `--yes` 时,CLI 返回 `confirmation_required`,退出码为 `10`。`task wait` 超时返回 `task_still_running`,退出码为 `20`。
144
142
 
145
143
  ## Agent 接入建议
146
144
 
147
- Agent 不应该靠记忆猜命令参数。进入任务前推荐先读取机器可读契约:
145
+ Agent 不应该靠记忆猜命令参数。进入任务前先读轻量能力摘要;执行具体命令前再按需读取精确契约:
148
146
 
149
147
  ```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
148
+ lj-awb schema --brief -f json
149
+ lj-awb schema --domain create --command video -f json
153
150
  ```
154
151
 
152
+ 只有做覆盖校验、生成脚本或调试 schema 本身时,才需要读取完整 `lj-awb schema -f json`。
153
+
155
154
  正式创作前推荐做一次体检:
156
155
 
157
156
  ```bash
158
157
  lj-awb doctor --verify
159
158
  ```
160
159
 
161
- `auth status` 只检查本地是否配置 access key;`auth verify` 会联网校验 key 是否远端有效。`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。
162
161
 
163
162
  `schema` 还包含面向 Agent 的执行约束:
164
163
 
@@ -177,7 +176,7 @@ lj-awb model options --model-group-code <modelGroupCode>
177
176
  lj-awb model create-spec --model-group-code <modelGroupCode>
178
177
  ```
179
178
 
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`。
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`。
181
180
 
182
181
  ## 示例:参考图生成视频
183
182
 
@@ -188,7 +187,7 @@ lj-awb model input-guide -f json
188
187
  lj-awb model options --model-group-code <modelGroupCode> -f json
189
188
  lj-awb model create-spec --model-group-code <modelGroupCode> -f json
190
189
 
191
- lj-awb video fee \
190
+ lj-awb create video-fee \
192
191
  --model-group-code <modelGroupCode> \
193
192
  --prompt "参考女主首帧,在雨夜街头奔跑,电影感运镜" \
194
193
  --resource image:first_frame=./actor.png \
@@ -197,7 +196,7 @@ lj-awb video fee \
197
196
  --duration 5 \
198
197
  --project-group-no <projectGroupNo>
199
198
 
200
- lj-awb video create \
199
+ lj-awb create video \
201
200
  --model-group-code <modelGroupCode> \
202
201
  --prompt "参考女主首帧,在雨夜街头奔跑,电影感运镜" \
203
202
  --resource image:first_frame=./actor.png \
@@ -218,7 +217,7 @@ lj-awb task wait \
218
217
  帧素材也可以直接使用平台资产 ID;是否可传尾帧以 `model options.resources[].usage` 是否包含 `last_frame` 为准:
219
218
 
220
219
  ```bash
221
- lj-awb video create \
220
+ lj-awb create video \
222
221
  --model-group-code <modelGroupCode> \
223
222
  --prompt "参考首帧生成一段镜头推进视频" \
224
223
  --resource image:first_frame=asset:<assetId> \
@@ -235,9 +234,9 @@ lj-awb video create \
235
234
  如果参考图会复用,推荐先发布主体资产:
236
235
 
237
236
  ```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 \
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 \
241
240
  --model-group-code <modelGroupCode> \
242
241
  --prompt "<<<女主>>> 在雨夜街头奔跑,电影感运镜" \
243
242
  --resource subject:reference:女主=asset:<externalId> \
@@ -245,9 +244,11 @@ lj-awb video create \
245
244
  --yes
246
245
  ```
247
246
 
248
- ## 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`。
249
250
 
250
- 默认输出是 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`。
251
252
 
252
253
  输出字段只保留后续动作不可替代的信息。默认不返回平台原始 `raw`、COS 签名细节、重复的首个结果字段;任务结果统一使用 `resultUrls` 表达。
253
254
 
@@ -273,7 +274,7 @@ lj-awb video create \
273
274
  "error": {
274
275
  "type": "auth_required",
275
276
  "message": "缺少 access key",
276
- "hint": "请设置 LINGJING_AWB_ACCESS_KEY / AWB_ACCESS_KEY,或运行 lj-awb auth login-key。"
277
+ "hint": "请设置 LINGJING_AWB_ACCESS_KEY,或运行 lj-awb auth login。"
277
278
  },
278
279
  "meta": {
279
280
  "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') {