@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
@@ -3,7 +3,16 @@ import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { LingjingAwbCliError, createEnvelope, toBool, toInt } from './common.js';
5
5
  import { registerAwbCommands } from './commands.js';
6
- import { formatTextError, formatTextOutput, normalizeJsonData } from './output.js';
6
+ import { checkCliUpdate } from './update.js';
7
+ import {
8
+ formatCsvOutput,
9
+ formatPrettyError,
10
+ formatPrettyOutput,
11
+ formatTextError,
12
+ formatTextOutput,
13
+ formatYamlEnvelope,
14
+ normalizeJsonData,
15
+ } from './output.js';
7
16
 
8
17
  function normalizeKey(value) {
9
18
  return String(value || '').replace(/-([a-z])/g, (_, char) => char.toUpperCase());
@@ -24,10 +33,13 @@ const OPTION_SYNONYMS = {
24
33
  threads: ['concurrency'],
25
34
  output: ['format'],
26
35
  json: ['format'],
36
+ keyword: ['model'],
27
37
  input: ['inputFile'],
28
38
  in: ['inputFile'],
29
39
  dry: ['dryRun'],
30
40
  force: ['yes'],
41
+ remoteTaskId: ['taskId'],
42
+ publicId: ['taskId'],
31
43
  };
32
44
 
33
45
  function levenshtein(a, b) {
@@ -58,6 +70,16 @@ function suggestSimilarOptions(unknownKey, allowedKeys) {
58
70
  for (const syn of synonyms) {
59
71
  if (allowedKeys.includes(syn)) record(syn, -1);
60
72
  }
73
+ if (unknownKey.length === 1) {
74
+ const ch = unknownKey.toLowerCase();
75
+ for (const allowed of allowedKeys) {
76
+ if (allowed.toLowerCase().startsWith(ch)) record(allowed, 1);
77
+ }
78
+ return [...scored.entries()]
79
+ .sort((x, y) => x[1] - y[1])
80
+ .slice(0, 3)
81
+ .map(([key]) => formatOptionName(key));
82
+ }
61
83
  for (const allowed of allowedKeys) {
62
84
  const a = unknownKey.toLowerCase();
63
85
  const b = allowed.toLowerCase();
@@ -83,6 +105,57 @@ function renderCliText(value) {
83
105
  return String(value ?? '').replace(/\blj-awb\b/g, commandPrefix());
84
106
  }
85
107
 
108
+ function shouldColorOutput() {
109
+ if (String(process.env.LINGJING_AWB_COLOR || '').toLowerCase() === '0') return false;
110
+ if (String(process.env.LINGJING_AWB_COLOR || '').toLowerCase() === 'false') return false;
111
+ if (String(process.env.FORCE_COLOR || '').trim() && process.env.FORCE_COLOR !== '0') return true;
112
+ if (String(process.env.LINGJING_AWB_COLOR || '').toLowerCase() === '1') return true;
113
+ if (String(process.env.LINGJING_AWB_COLOR || '').toLowerCase() === 'true') return true;
114
+ if (process.env.NO_COLOR) return false;
115
+ return Boolean(process.stdout.isTTY);
116
+ }
117
+
118
+ function colorText(value, code) {
119
+ const text = String(value ?? '');
120
+ return shouldColorOutput() && text ? `\u001b[${code}m${text}\u001b[0m` : text;
121
+ }
122
+
123
+ const HELP_COLOR = {
124
+ title: '1;38;5;39',
125
+ accent: '1;38;5;208',
126
+ heading: '1;38;5;75',
127
+ command: '38;5;82',
128
+ group: '38;5;215',
129
+ muted: '2;38;5;245',
130
+ option: '38;5;111',
131
+ };
132
+
133
+ function helpTitle(value) {
134
+ if (!shouldColorOutput()) return String(value ?? '');
135
+ return `${colorText('◆', HELP_COLOR.accent)} ${colorText(value, HELP_COLOR.title)}`;
136
+ }
137
+
138
+ function helpHeading(value) {
139
+ if (!shouldColorOutput()) return String(value ?? '');
140
+ return `${colorText('▸', HELP_COLOR.accent)} ${colorText(value, HELP_COLOR.heading)}`;
141
+ }
142
+
143
+ function helpCommand(value) {
144
+ return colorText(value, HELP_COLOR.command);
145
+ }
146
+
147
+ function helpGroup(value) {
148
+ return colorText(value, HELP_COLOR.group);
149
+ }
150
+
151
+ function helpMuted(value) {
152
+ return colorText(value, HELP_COLOR.muted);
153
+ }
154
+
155
+ function helpOption(value) {
156
+ return colorText(value, HELP_COLOR.option);
157
+ }
158
+
86
159
  function shellArg(value) {
87
160
  const text = String(value ?? '');
88
161
  return /^[A-Za-z0-9_./:=@,+-]+$/.test(text) ? text : JSON.stringify(text);
@@ -116,7 +189,7 @@ function commandInvocation(commandName, kwargs = {}, options = {}) {
116
189
 
117
190
  function buildOutputContext(command, kwargs = {}) {
118
191
  const optionKeys = new Set((command.args || []).map((arg) => normalizeKey(arg.name)));
119
- const canSuggestDryRunExecution = command.name !== 'auth login-key';
192
+ const canSuggestDryRunExecution = command.name !== 'auth login';
120
193
  const withoutDryRun = { omit: ['dryRun'] };
121
194
  const isModelList = command.name === 'model image-models' || command.name === 'model video-models';
122
195
  const modelListAll = isModelList && toBool(kwargs.all);
@@ -128,6 +201,8 @@ function buildOutputContext(command, kwargs = {}) {
128
201
  : null;
129
202
  return {
130
203
  jsonCommand: `${commandInvocation(command.name, kwargs)} -f json`,
204
+ textCommand: `${commandInvocation(command.name, kwargs)} -f text`,
205
+ outputKind: buildCommandWorkflow(command).outputKind,
131
206
  executeCommand: canSuggestDryRunExecution && toBool(kwargs.dryRun) ? commandInvocation(command.name, kwargs, withoutDryRun) : null,
132
207
  confirmCommand: canSuggestDryRunExecution && toBool(kwargs.dryRun) && optionKeys.has('yes')
133
208
  ? commandInvocation(command.name, kwargs, { omit: ['dryRun'], set: { yes: true } })
@@ -136,6 +211,43 @@ function buildOutputContext(command, kwargs = {}) {
136
211
  };
137
212
  }
138
213
 
214
+ function updateCheckDisabledByEnv() {
215
+ return ['1', 'true', 'yes', 'on'].includes(String(process.env.LINGJING_AWB_DISABLE_UPDATE_CHECK || '').trim().toLowerCase())
216
+ || ['1', 'true', 'yes', 'on'].includes(String(process.env.AWB_DISABLE_UPDATE_CHECK || '').trim().toLowerCase());
217
+ }
218
+
219
+ function shouldSkipUpdateCheck(argv = [], commandName = '') {
220
+ if (updateCheckDisabledByEnv()) return true;
221
+ return commandName === 'update';
222
+ }
223
+
224
+ async function resolveUpdateNotice(argv = [], commandName = '', version = 'unknown') {
225
+ if (shouldSkipUpdateCheck(argv, commandName)) return null;
226
+ return await checkCliUpdate({ currentVersion: version }).catch(() => null);
227
+ }
228
+
229
+ const OUTPUT_FORMAT_ALIASES = {
230
+ agent: 'text',
231
+ table: 'pretty',
232
+ human: 'pretty',
233
+ compact: 'text',
234
+ 'compact-text': 'text',
235
+ };
236
+
237
+ const SUPPORTED_OUTPUT_FORMATS = new Set(['auto', 'pretty', 'text', 'json', 'yaml', 'csv']);
238
+
239
+ function resolveOutputFormat(format) {
240
+ const raw = String(format || 'pretty').trim().toLowerCase();
241
+ const normalized = OUTPUT_FORMAT_ALIASES[raw] || raw;
242
+ if (normalized === 'auto') return process.stdout.isTTY ? 'pretty' : 'text';
243
+ if (SUPPORTED_OUTPUT_FORMATS.has(normalized)) return normalized;
244
+ throw new LingjingAwbCliError(`未知输出格式:${format}`, {
245
+ type: 'argument_error',
246
+ exitCode: 2,
247
+ hint: '可用格式:pretty、text、json、yaml、csv、auto。Agent 建议使用 -f text;严格脚本解析再用 -f json。',
248
+ });
249
+ }
250
+
139
251
  function assignKwarg(kwargs, key, value) {
140
252
  if (kwargs[key] === undefined) {
141
253
  kwargs[key] = value;
@@ -151,7 +263,8 @@ function assignKwarg(kwargs, key, value) {
151
263
  function parseArgv(argv) {
152
264
  const commandParts = [];
153
265
  const kwargs = {};
154
- let format = 'text';
266
+ const kwargRawFlags = {};
267
+ let format = 'pretty';
155
268
 
156
269
  for (let index = 0; index < argv.length; index += 1) {
157
270
  const token = argv[index];
@@ -180,10 +293,27 @@ function parseArgv(argv) {
180
293
  }
181
294
  continue;
182
295
  }
296
+ if (token.length > 1 && token.startsWith('-') && /^-[A-Za-z]/.test(token)) {
297
+ const raw = token.slice(1);
298
+ const eqIndex = raw.indexOf('=');
299
+ const keyPart = eqIndex >= 0 ? raw.slice(0, eqIndex) : raw;
300
+ const inlineValue = eqIndex >= 0 ? raw.slice(eqIndex + 1) : undefined;
301
+ const key = normalizeKey(keyPart);
302
+ if (!(key in kwargRawFlags)) kwargRawFlags[key] = token;
303
+ if (inlineValue !== undefined) {
304
+ assignKwarg(kwargs, key, inlineValue);
305
+ } else if (argv[index + 1] && !argv[index + 1].startsWith('-')) {
306
+ assignKwarg(kwargs, key, argv[index + 1]);
307
+ index += 1;
308
+ } else {
309
+ assignKwarg(kwargs, key, true);
310
+ }
311
+ continue;
312
+ }
183
313
  commandParts.push(token);
184
314
  }
185
315
 
186
- return { commandName: commandParts.join(' '), kwargs, format };
316
+ return { commandName: commandParts.join(' '), kwargs, kwargRawFlags, format };
187
317
  }
188
318
 
189
319
  async function readVersion() {
@@ -201,20 +331,49 @@ const VIRTUAL_COMMANDS = [
201
331
  '输出机器可读命令 schema,供 Agent / 脚本理解命令、参数和示例',
202
332
  '',
203
333
  'Examples:',
334
+ ' lj-awb schema --brief -f json',
204
335
  ' lj-awb schema -f json',
205
- ' lj-awb schema --domain video -f json',
206
- ' lj-awb schema --domain image --command create -f json',
336
+ ' lj-awb schema --domain create -f json',
337
+ ' lj-awb schema --domain create --command image -f json',
207
338
  '',
208
- 'Hint: Agent 应优先读取 schema,而不是解析自然语言 help。',
339
+ 'Hint: Agent 先读 --brief 掌握能力地图;执行具体命令前再读精确 schema。',
209
340
  ].join('\n'),
210
341
  args: [
211
- { name: 'domain', valueName: 'name', description: '按命令域过滤,如 image / video / task / system' },
212
- { name: 'command', valueName: 'name', description: '按子命令过滤,如 create / wait / doctor' },
342
+ { name: 'brief', description: '输出面向 Agent 的轻量能力摘要,不展开每个参数' },
343
+ { name: 'domain', valueName: 'name', description: '按命令域过滤,如 create / task / artifact / system' },
344
+ { name: 'command', valueName: 'name', description: '按子命令过滤,如 image / video / wait / doctor' },
213
345
  ],
214
346
  },
215
347
  ];
216
348
 
217
349
  const RENAMED_COMMAND_HINTS = {
350
+ image: 'create image',
351
+ 'image fee': 'create image-fee',
352
+ 'image create': 'create image',
353
+ 'image create-batch': 'create image-batch',
354
+ 'image status': 'task image-status',
355
+ video: 'create video',
356
+ 'video fee': 'create video-fee',
357
+ 'video create': 'create video',
358
+ 'video create-batch': 'create video-batch',
359
+ 'video status': 'task video-status',
360
+ 'video subtitle-remove': 'create video-subtitle-removal',
361
+ 'video subtitle-status': 'task video-subtitle-status',
362
+ asset: 'create asset',
363
+ 'asset match-actor': 'create asset-match-actor',
364
+ 'asset groups': 'create asset-groups',
365
+ 'asset group': 'create asset-group-get',
366
+ 'asset group-create': 'create asset-group',
367
+ 'asset group-update': 'create asset-group-update',
368
+ 'asset register': 'create asset',
369
+ subject: 'create subject',
370
+ 'subject list': 'create subject-list',
371
+ 'subject publish': 'create subject',
372
+ 'subject wait': 'create subject-wait',
373
+ 'subject publish-batch': 'create subject-batch',
374
+ 'subject voice list': 'create subject-voice-list',
375
+ 'subject voice create': 'create subject-voice',
376
+ 'subject voice wait': 'create subject-voice-wait',
218
377
  'workspace me': 'account info',
219
378
  'workspace teams': 'account teams',
220
379
  'workspace team-select': 'account switch-team',
@@ -229,6 +388,16 @@ const RENAMED_COMMAND_HINTS = {
229
388
  'billing usage-summary': 'credits usage',
230
389
  };
231
390
 
391
+ const MODEL_LIST_GUESS_HINT = `按任务类型分开查询:生图候选用 ${'`'}lj-awb model image-models${'`'},生视频候选用 ${'`'}lj-awb model video-models${'`'}。运行 lj-awb model -h 查看 model 域全部命令。`;
392
+ const COMMAND_GUESS_HINTS = {
393
+ 'model list': MODEL_LIST_GUESS_HINT,
394
+ 'model models': MODEL_LIST_GUESS_HINT,
395
+ 'model ls': MODEL_LIST_GUESS_HINT,
396
+ 'model image': MODEL_LIST_GUESS_HINT,
397
+ 'model video': MODEL_LIST_GUESS_HINT,
398
+ 'models': MODEL_LIST_GUESS_HINT,
399
+ };
400
+
232
401
  function buildRegistry() {
233
402
  const commands = [];
234
403
  registerAwbCommands((spec) => commands.push(spec));
@@ -249,6 +418,23 @@ function isCommandGroupName(commandName, commands) {
249
418
  return Boolean(commandName && commands.some((command) => commandGroup(command) === commandName));
250
419
  }
251
420
 
421
+ function commandSubgroupTokens(command) {
422
+ const parts = String(command.name || '').split(' ').filter(Boolean);
423
+ if (parts.length < 3) return null;
424
+ return [parts[0], parts[1]];
425
+ }
426
+
427
+ function isCommandSubgroupName(commandName, commands) {
428
+ const parts = String(commandName || '').split(' ').filter(Boolean);
429
+ if (parts.length !== 2) return false;
430
+ const [group, subgroup] = parts;
431
+ if (!SUBGROUP_DESCRIPTIONS[group]?.[subgroup]) return false;
432
+ return commands.some((command) => {
433
+ const tokens = commandSubgroupTokens(command);
434
+ return tokens && tokens[0] === group && tokens[1] === subgroup;
435
+ });
436
+ }
437
+
252
438
  function resolveCommandName(commandName, commands) {
253
439
  const exact = commands.find((command) => command.name === commandName);
254
440
  if (exact) return commandName;
@@ -268,27 +454,59 @@ const GROUP_DESCRIPTIONS = {
268
454
  project: '项目:查看、切换、创建和更新项目组',
269
455
  credits: '积分:查询可扣积分余额、项目组预算和用量统计',
270
456
  model: '模型:查询生图 / 生视频模型、参数约束和创建用法',
457
+ create: '创建:统一提交图片、视频、主体、音色、素材和视频去字幕任务',
271
458
  upload: '上传:把本地文件上传为平台可访问素材',
272
- image: '图片:估价、提交、批量提交和查询生图任务',
273
- video: '视频:估价、提交、批量提交、查询和去字幕',
274
459
  task: '任务:任务列表、等待和本地任务台账',
275
- asset: '资产:素材库匹配、素材组和素材注册',
276
- artifact: '最终产物:Workbench 剧本、资产、视频 CRUD 与本地 JSON 导入',
277
- subject: '主体:发布和查询可复用主体资产',
460
+ artifact: '最终产物:剧本、资产、视频、剪辑 CRUD 与本地 JSON 导入',
461
+ };
462
+
463
+ const SUBGROUP_DESCRIPTIONS = {
464
+ artifact: {
465
+ script: '剧本:document / asset / state / speaker / episode / scene / action 行 CRUD 与 script.json 批量导入',
466
+ asset: '资产:角色 / 道具 / 场景 及其状态 CRUD,actors/props/locations JSON 批量导入',
467
+ video: '视频:集 / 场 / clip 三级最终产物 CRUD 与 storyboard 批量导入',
468
+ clip: '剪辑:按集组织的剪辑宽表 CRUD 与状态更新',
469
+ },
470
+ };
471
+
472
+ const SUBGROUP_EXAMPLES = {
473
+ 'artifact script': [
474
+ 'lj-awb artifact script import --project-id <projectId> --input-file 1_script/output/script.json --dry-run',
475
+ 'lj-awb artifact script get --project-id <projectId>',
476
+ 'lj-awb artifact script rows --project-id <projectId> --row-kind scene',
477
+ ],
478
+ 'artifact asset': [
479
+ 'lj-awb artifact asset import --project-id <projectId> --input-dir 2_asset/output --dry-run',
480
+ 'lj-awb artifact asset actors --project-id <projectId> --include-states true',
481
+ 'lj-awb artifact asset props --project-id <projectId>',
482
+ ],
483
+ 'artifact video': [
484
+ 'lj-awb artifact video import-storyboard --project-id <projectId> --input-file 3_footage/output/ep001/ep001_storyboard.json --dry-run',
485
+ 'lj-awb artifact video episodes --project-id <projectId>',
486
+ 'lj-awb artifact video clips --project-id <projectId> --episode-id ep_001 --scene-id scn_001',
487
+ ],
488
+ 'artifact clip': [
489
+ 'lj-awb artifact clip upsert-episode --project-id <projectId> --input-file 4_clip/output/ep001_clip_output.json --dry-run',
490
+ 'lj-awb artifact clip episodes --project-id <projectId>',
491
+ 'lj-awb artifact clip episode-by-id --project-id <projectId> --episode-id ep_001',
492
+ ],
278
493
  };
279
494
 
280
495
  const GROUP_EXAMPLES = {
281
496
  system: [
282
497
  'lj-awb doctor',
283
498
  'lj-awb doctor --verify',
499
+ 'lj-awb update --check',
500
+ 'lj-awb update',
501
+ 'lj-awb schema --brief -f json',
284
502
  'lj-awb schema -f json',
285
- 'lj-awb schema --domain video -f json',
503
+ 'lj-awb schema --domain create -f json',
286
504
  ],
287
505
  auth: [
288
506
  'lj-awb auth status',
289
507
  'lj-awb auth verify',
290
- 'lj-awb auth login-key --access-key <access-key>',
291
- 'LINGJING_AWB_ACCESS_KEY=<access-key> lj-awb auth login-key --from-env',
508
+ 'lj-awb auth login --access-key <access-key>',
509
+ 'LINGJING_AWB_ACCESS_KEY=<access-key> lj-awb auth login',
292
510
  'lj-awb auth clear --dry-run',
293
511
  ],
294
512
  account: [
@@ -309,6 +527,7 @@ const GROUP_EXAMPLES = {
309
527
  model: [
310
528
  'lj-awb model image-models --model Banana',
311
529
  'lj-awb model video-models --model Seedance',
530
+ 'lj-awb model asset-review-models --platform JIMENG',
312
531
  'lj-awb model input-guide',
313
532
  'lj-awb model options --model-group-code <code>',
314
533
  'lj-awb model create-spec --model-group-code <code>',
@@ -316,34 +535,29 @@ const GROUP_EXAMPLES = {
316
535
  upload: [
317
536
  'lj-awb upload files --files ./a.png,./b.mp4 --dry-run',
318
537
  ],
319
- image: [
320
- 'lj-awb image fee --model-group-code <code> --prompt "一只小狗"',
321
- 'lj-awb image create --model-group-code <code> --prompt "一只小狗" --dry-run',
322
- 'lj-awb image status --task-id <id>',
323
- ],
324
- video: [
325
- 'lj-awb video fee --model-group-code <code> --prompt "雨夜奔跑" --duration 5',
326
- 'lj-awb video create --model-group-code <code> --prompt "镜头推进" --resource image:first_frame=./actor.png --dry-run',
327
- 'lj-awb video create --model-group-code <code> --prompt "镜头推进" --resource image:first_frame=asset:<assetId> --dry-run',
328
- 'lj-awb video subtitle-status --remote-task-id <id>',
538
+ create: [
539
+ 'lj-awb create image --model-group-code <code> --prompt "一只小狗" --dry-run',
540
+ 'lj-awb create image-fee --model-group-code <code> --prompt "一只小狗"',
541
+ 'lj-awb create video --model-group-code <code> --prompt "镜头推进" --resource image:first_frame=./actor.png --dry-run',
542
+ 'lj-awb create video-fee --model-group-code <code> --prompt "雨夜奔跑" --duration 5',
543
+ 'lj-awb create subject --model-code tx --name 女主 --resource primary:./three-view.png --dry-run',
544
+ 'lj-awb create subject-wait --element-id <elementId> --wait-seconds 300',
545
+ 'lj-awb create asset --group-id <id> --platform JIMENG --file ./actor.png --name "女主正面" --dry-run',
546
+ 'lj-awb create asset-groups --platform JIMENG --name "女主"',
329
547
  ],
330
548
  task: [
331
549
  'lj-awb task list --task-type IMAGE_CREATE --project-group-no <no>',
550
+ 'lj-awb task image-status --task-id <imageTaskId>',
551
+ 'lj-awb task video-status --task-id <videoTaskId>',
552
+ 'lj-awb task video-subtitle-status --task-id <subtitleTaskId>',
332
553
  'lj-awb task wait --task-id <id> --task-type IMAGE_CREATE --wait-seconds 180',
333
554
  'lj-awb task records --task-record-file .awb/tasks.jsonl',
334
555
  ],
335
- asset: [
336
- 'lj-awb asset match-actor --description "十八岁少女,古风" --tags-json \'{"gender":"女"}\'',
337
- 'lj-awb asset group-create --name "女主素材组" --dry-run',
338
- ],
339
556
  artifact: [
340
557
  'lj-awb artifact script import --project-id <projectId> --input-file 1_script/output/script.json --dry-run',
341
558
  'lj-awb artifact asset import --project-id <projectId> --input-dir 2_asset/output --dry-run',
342
559
  'lj-awb artifact video import-storyboard --project-id <projectId> --input-file 3_footage/output/ep001/ep001_storyboard.json --dry-run',
343
- ],
344
- subject: [
345
- 'lj-awb subject list --name "女主"',
346
- 'lj-awb subject publish --name 女主 --primary-file ./three-view.png --dry-run',
560
+ 'lj-awb artifact clip upsert-episode --project-id <projectId> --input-file 4_clip/output/ep001_clip_output.json --dry-run',
347
561
  ],
348
562
  };
349
563
 
@@ -353,21 +567,22 @@ const COMMAND_REQUIRED_OPTIONS = {
353
567
  'project ensure': ['name'],
354
568
  'model options': ['modelGroupCode'],
355
569
  'model create-spec': ['modelGroupCode'],
356
- 'image fee': ['modelGroupCode', 'prompt'],
357
- 'image create': ['modelGroupCode', 'prompt'],
358
- 'image create-batch': ['inputFile', 'modelGroupCode'],
359
- 'image status': ['taskId'],
360
- 'video fee': ['modelGroupCode'],
361
- 'video create': ['modelGroupCode'],
362
- 'video create-batch': ['inputFile', 'modelGroupCode'],
363
- 'video status': ['taskId'],
364
- 'video subtitle-remove': ['videoUrl'],
570
+ 'create image-fee': ['modelGroupCode', 'prompt'],
571
+ 'create image': ['modelGroupCode', 'prompt'],
572
+ 'create image-batch': ['inputFile', 'modelGroupCode'],
573
+ 'task image-status': ['taskId'],
574
+ 'create video-fee': ['modelGroupCode'],
575
+ 'create video': ['modelGroupCode'],
576
+ 'create video-batch': ['inputFile', 'modelGroupCode'],
577
+ 'task video-status': ['taskId'],
578
+ 'task video-subtitle-status': ['taskId'],
365
579
  'task wait': ['taskId', 'taskType'],
366
- 'asset match-actor': ['description'],
367
- 'asset group-get': ['groupId'],
368
- 'asset group-create': ['name'],
369
- 'asset group-update': ['groupId'],
370
- 'asset register': ['groupId', 'name'],
580
+ 'create asset-match-actor': ['description'],
581
+ 'create asset-groups': ['platform'],
582
+ 'create asset-group-get': ['groupId', 'platform'],
583
+ 'create asset-group': ['name', 'platform'],
584
+ 'create asset-group-update': ['groupId', 'platform'],
585
+ 'create asset': ['groupId', 'name', 'platform'],
371
586
  'artifact script row': ['rowKind', 'entityKey'],
372
587
  'artifact script children': ['parentKey'],
373
588
  'artifact script delete-row': ['rowKind', 'entityKey'],
@@ -390,24 +605,29 @@ const COMMAND_REQUIRED_OPTIONS = {
390
605
  'artifact video clip': ['episodeId', 'sceneId', 'clipId'],
391
606
  'artifact video upsert-scene': ['episodeId'],
392
607
  'artifact video upsert-clip': ['episodeId', 'sceneId'],
393
- 'artifact video update-clip-video-urls': ['episodeId', 'sceneId', 'clipId', 'videoUrlsJson'],
608
+ 'artifact video update-clip-urls': ['episodeId', 'sceneId', 'clipId', 'videoUrlsJson'],
394
609
  'artifact video delete-episode': ['episodeId'],
395
610
  'artifact video delete-scene': ['episodeId', 'sceneId'],
396
611
  'artifact video delete-clip': ['episodeId', 'sceneId', 'clipId'],
397
612
  'artifact video import-storyboard': ['inputFile'],
398
- 'subject publish': ['name'],
399
- 'subject wait': ['elementId'],
400
- 'subject publish-batch': ['inputFile'],
613
+ 'artifact clip episode': ['videoEpisodeId'],
614
+ 'artifact clip episode-by-id': ['episodeId'],
615
+ 'artifact clip update-status': ['videoEpisodeId', 'status'],
616
+ 'artifact clip delete-episode': ['videoEpisodeId'],
617
+ 'create subject': ['name'],
618
+ 'create subject-wait': ['elementId'],
619
+ 'create subject-voice': ['name'],
620
+ 'create subject-batch': ['inputFile'],
401
621
  };
402
622
 
403
623
  const COMMAND_REQUIRED_ANY_OPTIONS = {
404
- 'auth login-key': [['accessKey', 'fromEnv']],
405
624
  'project update': [['name', 'point']],
406
625
  'upload files': [['file', 'files', 'filesJson']],
407
- 'video fee': [['prompt', 'resource', 'resourcesJson']],
408
- 'video create': [['prompt', 'resource', 'resourcesJson']],
409
- 'asset group-update': [['name', 'description', 'projectName']],
410
- 'asset register': [['file', 'url', 'backendPath']],
626
+ 'create video-fee': [['prompt', 'resource', 'resourcesJson']],
627
+ 'create video': [['prompt', 'resource', 'resourcesJson']],
628
+ 'create video-subtitle-removal': [['sourceTaskId']],
629
+ 'create asset-group-update': [['name', 'description', 'projectName']],
630
+ 'create asset': [['file', 'url', 'backendPath']],
411
631
  'artifact script upsert-row': [['bodyJson', 'inputFile']],
412
632
  'artifact asset upsert-actor': [['bodyJson', 'inputFile']],
413
633
  'artifact asset upsert-prop': [['bodyJson', 'inputFile']],
@@ -418,7 +638,12 @@ const COMMAND_REQUIRED_ANY_OPTIONS = {
418
638
  'artifact video upsert-episode': [['bodyJson', 'inputFile']],
419
639
  'artifact video upsert-scene': [['bodyJson', 'inputFile']],
420
640
  'artifact video upsert-clip': [['bodyJson', 'inputFile']],
421
- 'subject publish': [['primaryFile', 'primaryUrl', 'threeViewFile', 'threeViewUrl']],
641
+ 'artifact clip upsert-episode': [['bodyJson', 'inputFile']],
642
+ 'artifact clip upsert-batch': [['bodyJson', 'inputFile']],
643
+ 'create subject': [['resource'], ['modelCode']],
644
+ 'create subject-batch': [['modelCode']],
645
+ 'create subject-voice': [['file', 'voiceUrl', 'audioUrl', 'videoId']],
646
+ 'create subject-voice-wait': [['voiceRecordId', 'reqTaskId']],
422
647
  };
423
648
 
424
649
  const ARTIFACT_WRITE_COMMANDS = [
@@ -441,11 +666,15 @@ const ARTIFACT_WRITE_COMMANDS = [
441
666
  'artifact video upsert-episode',
442
667
  'artifact video upsert-scene',
443
668
  'artifact video upsert-clip',
444
- 'artifact video update-clip-video-urls',
669
+ 'artifact video update-clip-urls',
445
670
  'artifact video delete-episode',
446
671
  'artifact video delete-scene',
447
672
  'artifact video delete-clip',
448
673
  'artifact video import-storyboard',
674
+ 'artifact clip upsert-episode',
675
+ 'artifact clip upsert-batch',
676
+ 'artifact clip update-status',
677
+ 'artifact clip delete-episode',
449
678
  ];
450
679
 
451
680
  const ARTIFACT_DELETE_COMMANDS = ARTIFACT_WRITE_COMMANDS.filter((name) => name.includes(' delete-'));
@@ -457,24 +686,26 @@ const CONFIRMATION_COMMANDS = new Set([
457
686
  'project create',
458
687
  'project update',
459
688
  'project ensure',
460
- 'image create',
461
- 'image create-batch',
462
- 'video create',
463
- 'video create-batch',
464
- 'video subtitle-remove',
465
- 'asset group-create',
466
- 'asset group-update',
467
- 'asset register',
689
+ 'create image',
690
+ 'create image-batch',
691
+ 'create video',
692
+ 'create video-batch',
693
+ 'create video-subtitle-removal',
694
+ 'create asset-group',
695
+ 'create asset-group-update',
696
+ 'create asset',
468
697
  ...ARTIFACT_WRITE_COMMANDS,
469
- 'subject publish',
470
- 'subject publish-batch',
698
+ 'create subject',
699
+ 'create subject-voice',
700
+ 'create subject-batch',
471
701
  ]);
472
702
 
473
703
  const COST_COMMANDS = new Set([
474
- 'image create',
475
- 'image create-batch',
476
- 'video create',
477
- 'video create-batch',
704
+ 'create image',
705
+ 'create image-batch',
706
+ 'create video',
707
+ 'create video-batch',
708
+ 'create video-subtitle-removal',
478
709
  ]);
479
710
 
480
711
  const REMOTE_WRITE_COMMANDS = new Set([
@@ -484,21 +715,23 @@ const REMOTE_WRITE_COMMANDS = new Set([
484
715
  'project update',
485
716
  'project ensure',
486
717
  'upload files',
487
- 'image create',
488
- 'image create-batch',
489
- 'video create',
490
- 'video create-batch',
491
- 'video subtitle-remove',
492
- 'asset group-create',
493
- 'asset group-update',
494
- 'asset register',
718
+ 'create image',
719
+ 'create image-batch',
720
+ 'create video',
721
+ 'create video-batch',
722
+ 'create video-subtitle-removal',
723
+ 'create asset-group',
724
+ 'create asset-group-update',
725
+ 'create asset',
495
726
  ...ARTIFACT_WRITE_COMMANDS,
496
- 'subject publish',
497
- 'subject publish-batch',
727
+ 'create subject',
728
+ 'create subject-voice',
729
+ 'create subject-batch',
498
730
  ]);
499
731
 
500
732
  const LOCAL_STATE_WRITE_COMMANDS = new Set([
501
- 'auth login-key',
733
+ 'update',
734
+ 'auth login',
502
735
  'auth clear',
503
736
  'project use',
504
737
  'project create',
@@ -506,16 +739,17 @@ const LOCAL_STATE_WRITE_COMMANDS = new Set([
506
739
  ]);
507
740
 
508
741
  const DESTRUCTIVE_COMMANDS = new Set(['auth clear', ...ARTIFACT_DELETE_COMMANDS]);
509
- const LONG_RUNNING_COMMANDS = new Set(['task wait', 'task record-poll', 'subject wait']);
742
+ const LONG_RUNNING_COMMANDS = new Set(['task wait', 'task record-poll', 'create subject-wait', 'create subject-voice-wait']);
510
743
  const NETWORK_NONE_COMMANDS = new Set(['schema', 'auth status', 'auth clear', 'model input-guide', 'task records']);
511
- const NETWORK_CONDITIONAL_COMMANDS = new Set(['doctor', 'auth login-key']);
744
+ const NETWORK_CONDITIONAL_COMMANDS = new Set(['doctor', 'auth login']);
512
745
 
513
746
  const OUTPUT_KIND_BY_COMMAND = {
514
747
  doctor: 'environment_report',
748
+ update: 'update_result',
515
749
  schema: 'command_schema',
516
750
  'auth status': 'auth_status',
517
751
  'auth verify': 'auth_status',
518
- 'auth login-key': 'auth_result',
752
+ 'auth login': 'auth_result',
519
753
  'account info': 'account_summary',
520
754
  'account teams': 'team_list',
521
755
  'project list': 'project_list',
@@ -525,47 +759,102 @@ const OUTPUT_KIND_BY_COMMAND = {
525
759
  'credits usage': 'credits_usage',
526
760
  'model image-models': 'model_list',
527
761
  'model video-models': 'model_list',
762
+ 'model asset-review-models': 'asset_review_model_list',
528
763
  'model options': 'model_options',
529
764
  'model create-spec': 'model_create_spec',
530
765
  'model input-guide': 'model_input_guide',
531
766
  'upload files': 'upload_result',
532
- 'image fee': 'fee_estimate',
533
- 'image create': 'task_submission',
534
- 'image create-batch': 'batch_task_submission',
535
- 'image status': 'task_status',
536
- 'video fee': 'fee_estimate',
537
- 'video create': 'task_submission',
538
- 'video create-batch': 'batch_task_submission',
539
- 'video status': 'task_status',
540
- 'video subtitle-remove': 'subtitle_task_submission',
541
- 'video subtitle-status': 'subtitle_task_status',
767
+ 'create image-fee': 'fee_estimate',
768
+ 'create image': 'task_submission',
769
+ 'create image-batch': 'batch_task_submission',
770
+ 'task image-status': 'task_status',
771
+ 'create video-fee': 'fee_estimate',
772
+ 'create video': 'task_submission',
773
+ 'create video-batch': 'batch_task_submission',
774
+ 'task video-status': 'task_status',
775
+ 'create video-subtitle-removal': 'subtitle_task_submission',
776
+ 'task video-subtitle-status': 'subtitle_task_status',
542
777
  'task list': 'task_list',
543
778
  'task wait': 'task_status',
544
779
  'task records': 'local_task_records',
545
780
  'task record-poll': 'batch_task_status',
546
- 'asset match-actor': 'asset_match_list',
547
- 'asset group-list': 'asset_group_list',
548
- 'asset group-get': 'asset_group_detail',
549
- 'asset group-create': 'asset_group_write_result',
550
- 'asset group-update': 'asset_group_write_result',
551
- 'asset register': 'asset_register_result',
552
- 'subject list': 'subject_list',
553
- 'subject publish': 'subject_publish_result',
554
- 'subject wait': 'subject_status',
555
- 'subject publish-batch': 'batch_subject_publish_result',
781
+ 'create asset-match-actor': 'asset_match_list',
782
+ 'create asset-groups': 'asset_group_list',
783
+ 'create asset-group-get': 'asset_group_detail',
784
+ 'create asset-group': 'asset_group_write_result',
785
+ 'create asset-group-update': 'asset_group_write_result',
786
+ 'create asset': 'asset_register_result',
787
+ 'create subject-list': 'subject_list',
788
+ 'create subject': 'subject_publish_result',
789
+ 'create subject-wait': 'subject_status',
790
+ 'create subject-voice-list': 'subject_voice_list',
791
+ 'create subject-voice': 'subject_voice_create_result',
792
+ 'create subject-voice-wait': 'subject_voice_status',
793
+ 'create subject-batch': 'batch_subject_publish_result',
794
+ 'artifact script get': 'artifact_full',
795
+ 'artifact script document': 'artifact_record',
796
+ 'artifact script rows': 'artifact_list',
797
+ 'artifact script row': 'artifact_record',
798
+ 'artifact script children': 'artifact_list',
799
+ 'artifact script upsert-row': 'artifact_write_result',
800
+ 'artifact script delete-row': 'artifact_delete_result',
801
+ 'artifact script import': 'artifact_import_result',
802
+ 'artifact asset get': 'artifact_full',
803
+ 'artifact asset actors': 'artifact_list',
804
+ 'artifact asset actor': 'artifact_record',
805
+ 'artifact asset props': 'artifact_list',
806
+ 'artifact asset prop': 'artifact_record',
807
+ 'artifact asset locations': 'artifact_list',
808
+ 'artifact asset location': 'artifact_record',
809
+ 'artifact asset upsert-actor': 'artifact_write_result',
810
+ 'artifact asset upsert-prop': 'artifact_write_result',
811
+ 'artifact asset upsert-location': 'artifact_write_result',
812
+ 'artifact asset upsert-actor-state': 'artifact_write_result',
813
+ 'artifact asset upsert-prop-state': 'artifact_write_result',
814
+ 'artifact asset upsert-location-state': 'artifact_write_result',
815
+ 'artifact asset delete-actor': 'artifact_delete_result',
816
+ 'artifact asset delete-prop': 'artifact_delete_result',
817
+ 'artifact asset delete-location': 'artifact_delete_result',
818
+ 'artifact asset delete-actor-state': 'artifact_delete_result',
819
+ 'artifact asset delete-prop-state': 'artifact_delete_result',
820
+ 'artifact asset delete-location-state': 'artifact_delete_result',
821
+ 'artifact asset import': 'artifact_import_result',
822
+ 'artifact video get': 'artifact_full',
823
+ 'artifact video episodes': 'artifact_list',
824
+ 'artifact video episode': 'artifact_record',
825
+ 'artifact video scenes': 'artifact_list',
826
+ 'artifact video scene': 'artifact_record',
827
+ 'artifact video clips': 'artifact_list',
828
+ 'artifact video clip': 'artifact_record',
829
+ 'artifact video upsert-episode': 'artifact_write_result',
830
+ 'artifact video upsert-scene': 'artifact_write_result',
831
+ 'artifact video upsert-clip': 'artifact_write_result',
832
+ 'artifact video update-clip-urls': 'artifact_write_result',
833
+ 'artifact video delete-episode': 'artifact_delete_result',
834
+ 'artifact video delete-scene': 'artifact_delete_result',
835
+ 'artifact video delete-clip': 'artifact_delete_result',
836
+ 'artifact video import-storyboard': 'artifact_import_result',
837
+ 'artifact clip get': 'artifact_full',
838
+ 'artifact clip episodes': 'artifact_list',
839
+ 'artifact clip episode': 'artifact_record',
840
+ 'artifact clip episode-by-id': 'artifact_record',
841
+ 'artifact clip upsert-episode': 'artifact_write_result',
842
+ 'artifact clip upsert-batch': 'artifact_import_result',
843
+ 'artifact clip update-status': 'artifact_status_update',
844
+ 'artifact clip delete-episode': 'artifact_delete_result',
556
845
  };
557
846
 
558
847
  const PREFLIGHTS_BY_COMMAND = {
559
- 'image create': ['doctor --verify', 'model image-models', 'model options', 'model create-spec', 'confirm missing key params', 'image fee', 'image create --dry-run'],
560
- 'image create-batch': ['doctor --verify', 'model image-models', 'model options', 'model create-spec', 'prepare JSONL input', 'image create-batch --dry-run'],
561
- 'video create': ['doctor --verify', 'model video-models', 'model options', 'model create-spec', 'confirm missing key params', 'video fee', 'video create --dry-run'],
562
- 'video create-batch': ['doctor --verify', 'model video-models', 'model options', 'model create-spec', 'prepare JSONL input', 'video create-batch --dry-run'],
563
- 'subject publish': ['doctor --verify', 'subject publish --dry-run'],
564
- 'subject publish-batch': ['doctor --verify', 'prepare JSONL input', 'subject publish-batch --dry-run'],
565
- 'video subtitle-remove': ['doctor --verify', 'video subtitle-remove --dry-run'],
566
- 'asset group-create': ['asset group-create --dry-run'],
567
- 'asset group-update': ['asset group-update --dry-run'],
568
- 'asset register': ['asset register --dry-run'],
848
+ 'create image': ['doctor --verify', 'model image-models', 'model options', 'model create-spec', 'confirm missing key params', 'create image-fee', 'create image --dry-run'],
849
+ 'create image-batch': ['doctor --verify', 'model image-models', 'model options', 'model create-spec', 'prepare JSONL input', 'create image-batch --dry-run'],
850
+ 'create video': ['doctor --verify', 'model video-models', 'model options', 'model create-spec', 'confirm missing key params', 'create video-fee', 'create video --dry-run'],
851
+ 'create video-batch': ['doctor --verify', 'model video-models', 'model options', 'model create-spec', 'prepare JSONL input', 'create video-batch --dry-run'],
852
+ 'create subject': ['doctor --verify', 'create subject --model-code tx|vidu --dry-run'],
853
+ 'create subject-batch': ['doctor --verify', 'prepare JSONL input with modelCode', 'create subject-batch --dry-run'],
854
+ 'create video-subtitle-removal': ['doctor --verify', 'create video-subtitle-removal --source-task-id <videoTaskId> --dry-run'],
855
+ 'create asset-group': ['model asset-review-models', 'create asset-group --platform <platform> --dry-run'],
856
+ 'create asset-group-update': ['create asset-group-update --platform <platform> --dry-run'],
857
+ 'create asset': ['model asset-review-models', 'create asset --platform <platform> --dry-run'],
569
858
  'upload files': ['upload files --dry-run'],
570
859
  };
571
860
 
@@ -606,6 +895,8 @@ function commandNetworkMode(commandName) {
606
895
  function unknownCommandHint(commandName) {
607
896
  const replacement = RENAMED_COMMAND_HINTS[commandName];
608
897
  if (replacement) return `该命令已产品化命名为 ${commandPrefix()} ${replacement}。运行 ${commandPrefix()} ${replacement.split(' ')[0]} -h 查看同组命令。`;
898
+ const guess = COMMAND_GUESS_HINTS[commandName];
899
+ if (guess) return guess;
609
900
  const group = String(commandName || '').split(' ').filter(Boolean)[0];
610
901
  if (group === 'workspace') return `账号用 ${commandPrefix()} account ...,项目组用 ${commandPrefix()} project ...。运行 ${commandPrefix()} --help 查看可用命令。`;
611
902
  if (group === 'billing') return `积分查询用 ${commandPrefix()} credits ...。运行 ${commandPrefix()} credits -h 查看可用命令。`;
@@ -620,9 +911,10 @@ function buildCommandSafety(command, optionKeys) {
620
911
  const costsPoints = COST_COMMANDS.has(name);
621
912
  const destructive = DESTRUCTIVE_COMMANDS.has(name);
622
913
  const supportsDryRun = optionKeys.has('dryRun');
914
+ const updateInstall = name === 'update';
623
915
  return {
624
- safeToAutoRun: !(remoteWrite || localStateWrite || requiresConfirmation || costsPoints || destructive),
625
- network: commandNetworkMode(name),
916
+ safeToAutoRun: !(remoteWrite || localStateWrite || requiresConfirmation || costsPoints || destructive || updateInstall),
917
+ network: updateInstall ? 'conditional' : commandNetworkMode(name),
626
918
  remoteWrite,
627
919
  localStateWrite,
628
920
  costsPoints,
@@ -636,15 +928,44 @@ function buildCommandSafety(command, optionKeys) {
636
928
  }
637
929
 
638
930
  function buildCommandWorkflow(command) {
639
- const outputKind = OUTPUT_KIND_BY_COMMAND[command.name] || (commandGroup(command) === 'artifact' ? 'artifact_result' : 'generic');
931
+ const outputKind = OUTPUT_KIND_BY_COMMAND[command.name] || 'generic';
640
932
  const next = [];
641
- if (['image create', 'video create'].includes(command.name)) {
642
- next.push('读取 data.taskId 和 data.nextCommand', '运行 task wait 等待结果');
933
+ if (command.name === 'create image') {
934
+ next.push('读取 data.taskId 和 data.nextCommand', '立即运行响应里的 nextCommand,或 task wait --task-type IMAGE_CREATE 等待结果');
935
+ }
936
+ if (command.name === 'create video') {
937
+ next.push('读取 data.taskId 和 data.nextCommand', '立即运行响应里的 nextCommand,或 task wait --task-type VIDEO_GROUP 等待结果');
938
+ }
939
+ if (command.name === 'create video-subtitle-removal') {
940
+ next.push('读取 data.taskId 和 data.nextCommand', '运行 task video-subtitle-status 或响应里的 nextCommand 等待结果');
643
941
  }
644
- if (command.name === 'subject publish') {
645
- next.push('读取 data.elementId', '运行 subject wait 获取 externalId / nextRefSubject');
942
+ if (command.name === 'create subject') {
943
+ next.push('读取 data.elementId / data.externalId', 'externalId 为空时立刻运行 create subject-wait 获取 nextRefSubject');
646
944
  }
647
- if (['image create-batch', 'video create-batch', 'subject publish-batch'].includes(command.name)) {
945
+ if (command.name === 'create subject-voice') {
946
+ next.push('读取 data.voiceRecordId / data.externalId', 'externalId 为空时立刻运行 create subject-voice-wait 获取 nextVoiceArg');
947
+ }
948
+ if (command.name === 'create asset') {
949
+ next.push('读取 data.assetPath', '若后端返回审核 taskId,再运行 task wait --task-type ASSET_REGISTER');
950
+ }
951
+ if (command.name === 'model image-models' || command.name === 'model video-models') {
952
+ next.push('读取 data.models[] 得到全部候选;用户给了模型口语名时保留同族全部候选,不只取第一个');
953
+ next.push('对每个候选运行 model options --model-group-code <modelGroupCode> 查看真实参数和素材约束');
954
+ next.push('向用户展示候选模型 + 参数取值 + 资源能力后 STOP;等待用户选择或明确授权默认,未确认不得进入 create-spec/fee/dry-run/create');
955
+ }
956
+ if (command.name === 'model asset-review-models') {
957
+ next.push('读取 data.models[].platform', '用 create asset-groups --platform <platform> 查重或创建素材组');
958
+ }
959
+ if (command.name === 'model options') {
960
+ next.push('读取 params/resources/constraints 确认参数与素材约束', '运行 model create-spec --model-group-code <code> 查看创建写法和示例');
961
+ }
962
+ if (command.name === 'model create-spec') {
963
+ next.push('按 examples / supportedIntents 组装命令', '用户确认关键参数后先运行 create image-fee 或 create video-fee,再 dry-run');
964
+ }
965
+ if (command.name === 'model input-guide') {
966
+ next.push('运行 model image-models 或 model video-models 选择模型', '选定模型后运行 model options --model-group-code <code>');
967
+ }
968
+ if (['create image-batch', 'create video-batch', 'create subject-batch'].includes(command.name)) {
648
969
  next.push('读取每项 status / taskId / error', '使用 task record-poll 或对应 wait 命令恢复批量结果');
649
970
  }
650
971
  return {
@@ -654,17 +975,210 @@ function buildCommandWorkflow(command) {
654
975
  };
655
976
  }
656
977
 
978
+ function buildDomainSummaries(commands) {
979
+ const domains = new Map();
980
+ for (const command of commands) {
981
+ const group = commandGroup(command);
982
+ domains.set(group, {
983
+ name: group,
984
+ description: GROUP_DESCRIPTIONS[group] || '',
985
+ commandCount: (domains.get(group)?.commandCount || 0) + 1,
986
+ });
987
+ }
988
+ return Array.from(domains.values()).sort((a, b) => a.name.localeCompare(b.name));
989
+ }
990
+
991
+ function requiredOptionsForCommand(command) {
992
+ const requiredOptions = new Set();
993
+ if (commandGroup(command) === 'artifact') requiredOptions.add('projectId');
994
+ for (const key of COMMAND_REQUIRED_OPTIONS[command.name] || []) requiredOptions.add(key);
995
+ return [...requiredOptions];
996
+ }
997
+
998
+ function requiredAnyOptionsForCommand(command) {
999
+ return COMMAND_REQUIRED_ANY_OPTIONS[command.name] || [];
1000
+ }
1001
+
1002
+ function buildCommandSchemaEntry(command) {
1003
+ const requiredOptions = requiredOptionsForCommand(command);
1004
+ const requiredAnyOptions = requiredAnyOptionsForCommand(command);
1005
+ const optionKeys = new Set((command.args || []).map((arg) => normalizeKey(arg.name)));
1006
+ return {
1007
+ name: command.name,
1008
+ domain: commandGroup(command),
1009
+ command: commandSubcommand(command),
1010
+ invocation: `${commandPrefix()} ${command.name}`,
1011
+ helpCommand: `${commandPrefix()} ${command.name} -h`,
1012
+ summary: summaryOf(command),
1013
+ description: renderCliText(summaryOf(command)),
1014
+ examples: extractExamples(command).map(renderCliText),
1015
+ jsonExamples: extractExamples(command).map(asJsonExample),
1016
+ requiredOptions,
1017
+ requiredAnyOptions,
1018
+ safety: buildCommandSafety(command, optionKeys),
1019
+ workflow: buildCommandWorkflow(command),
1020
+ options: (command.args || []).map((arg) => {
1021
+ const key = normalizeKey(arg.name);
1022
+ return {
1023
+ name: arg.name,
1024
+ key,
1025
+ flag: formatOptionName(arg.name),
1026
+ valueName: arg.valueName || null,
1027
+ required: requiredOptions.includes(key),
1028
+ requiredAnyGroup: requiredAnyOptions.find((group) => group.includes(key)) || null,
1029
+ description: arg.description || '',
1030
+ };
1031
+ }),
1032
+ };
1033
+ }
1034
+
1035
+ function namesWhere(entries, predicate) {
1036
+ return entries.filter(predicate).map((entry) => entry.name);
1037
+ }
1038
+
1039
+ function buildAgentBrief(commands, version = 'unknown') {
1040
+ const contract = buildAgentContract();
1041
+ const entries = commands.map(buildCommandSchemaEntry);
1042
+ const domains = buildDomainSummaries(commands).map((domain) => ({
1043
+ ...domain,
1044
+ commands: entries
1045
+ .filter((entry) => entry.domain === domain.name)
1046
+ .map((entry) => entry.name),
1047
+ }));
1048
+ return {
1049
+ schemaVersion: 1,
1050
+ kind: 'agent_brief',
1051
+ cli: {
1052
+ name: 'lj-awb',
1053
+ version,
1054
+ commandPrefix: commandPrefix(),
1055
+ },
1056
+ commandCount: entries.length,
1057
+ domains,
1058
+ outputPolicy: {
1059
+ agentRecommendedOutputFormat: contract.agentRecommendedOutputFormat,
1060
+ scriptRecommendedOutputFormat: contract.scriptRecommendedOutputFormat,
1061
+ textFlag: contract.textFlag,
1062
+ jsonFlag: contract.jsonFlag,
1063
+ policy: contract.outputPolicy,
1064
+ },
1065
+ statePolicy: contract.statePolicy,
1066
+ workflowPolicy: contract.workflowPolicy,
1067
+ safetyPolicy: {
1068
+ confirmationPolicy: contract.confirmationPolicy,
1069
+ dryRunPolicy: contract.dryRunPolicy,
1070
+ remoteWriteCount: namesWhere(entries, (entry) => entry.safety.remoteWrite).length,
1071
+ costsPointsCount: namesWhere(entries, (entry) => entry.safety.costsPoints).length,
1072
+ localStateWriteCount: namesWhere(entries, (entry) => entry.safety.localStateWrite).length,
1073
+ destructiveCount: namesWhere(entries, (entry) => entry.safety.destructive).length,
1074
+ longRunningCount: namesWhere(entries, (entry) => entry.safety.longRunning).length,
1075
+ },
1076
+ commandClasses: {
1077
+ costsPoints: namesWhere(entries, (entry) => entry.safety.costsPoints),
1078
+ remoteWrite: namesWhere(entries, (entry) => entry.safety.remoteWrite),
1079
+ localStateWrite: namesWhere(entries, (entry) => entry.safety.localStateWrite),
1080
+ destructive: namesWhere(entries, (entry) => entry.safety.destructive),
1081
+ longRunning: namesWhere(entries, (entry) => entry.safety.longRunning),
1082
+ safeRead: namesWhere(entries, (entry) => entry.safety.safeToAutoRun && entry.safety.network !== 'none'),
1083
+ offlineRead: namesWhere(entries, (entry) => entry.safety.safeToAutoRun && entry.safety.network === 'none'),
1084
+ },
1085
+ routing: [
1086
+ {
1087
+ intent: '环境、认证、账号、团队、项目组、积分',
1088
+ start: ['doctor --verify', 'account info', 'project current', 'credits balance'],
1089
+ rule: '只读查询可自动运行;切换团队、切换/创建/更新项目组和清空认证按 safety dry-run/confirm 处理。',
1090
+ },
1091
+ {
1092
+ intent: '模型发现和创作任务',
1093
+ start: ['model image-models', 'model video-models', 'model options', 'model create-spec'],
1094
+ rule: '先展示候选模型、真实参数和资源能力并 STOP;用户选择或明确授权默认后,关键参数确认,再只跑一次 fee、dry-run 和最终 --yes。',
1095
+ },
1096
+ {
1097
+ intent: '上传、主体、音色、素材加白',
1098
+ start: ['upload files', 'create subject-list', 'create subject-voice-list', 'model asset-review-models'],
1099
+ rule: '复用已上传 backendPath、已有主体/音色/素材组;素材加白平台来自 model asset-review-models 或用户明确选择。',
1100
+ },
1101
+ {
1102
+ intent: '异步任务和批量恢复',
1103
+ start: ['task wait', 'task record-poll', 'task records'],
1104
+ rule: '优先复用 create 返回的 nextCommand;批量任务使用 task-record-file,失败项单独重试。',
1105
+ },
1106
+ {
1107
+ intent: '最终产物 artifact',
1108
+ start: ['artifact script', 'artifact asset', 'artifact video', 'artifact clip'],
1109
+ rule: 'artifact 使用 project-id,不是 project-group-no;写入/删除/导入先 dry-run,再一次性确认写入面。',
1110
+ },
1111
+ ],
1112
+ lookup: {
1113
+ preciseSchema: `${commandPrefix()} schema --domain <domain> --command <command> -f json`,
1114
+ fullSchema: `${commandPrefix()} schema -f json`,
1115
+ commandHelp: `${commandPrefix()} <domain> <command> -h`,
1116
+ modelInputGuide: contract.modelInputGuide.textCommand,
1117
+ schemaPolicy: contract.schemaPolicy,
1118
+ },
1119
+ canonicalFields: contract.canonicalFields,
1120
+ resourceShortcut: contract.resourceShortcut,
1121
+ resourcesJson: contract.resourcesJson,
1122
+ modelCandidatePresentation: contract.modelCandidatePresentation,
1123
+ taskTypes: contract.taskTypes,
1124
+ exitCodes: contract.exitCodes,
1125
+ };
1126
+ }
1127
+
657
1128
  function buildAgentContract() {
658
1129
  return {
659
- defaultOutputFormat: 'compact-text',
1130
+ defaultOutputFormat: 'pretty',
1131
+ humanDefaultOutputFormat: 'pretty',
1132
+ agentRecommendedOutputFormat: 'text',
1133
+ agentCompactOutputFormat: 'text',
1134
+ scriptRecommendedOutputFormat: 'json',
660
1135
  jsonFlag: '-f json',
661
- outputPolicy: '默认输出精简 key=value 文本,只保留决策字段;需要稳定 JSON 或完整嵌套结构时显式传 -f json 或 --json。',
662
- schemaPolicy: 'schema 是机器契约,只给摘要、参数 key、安全规则和示例;查看长帮助用 schema.commands[].helpCommand 或 lj-awb <domain> <command> -h。',
1136
+ textFlag: '-f text',
1137
+ outputFormats: ['pretty', 'text', 'json', 'yaml', 'csv', 'auto'],
1138
+ outputPolicy: '默认输出 pretty 人类友好视图,包含标题、摘要表格、列表表格和下一步建议;Agent 推荐显式传 -f text 读取稳定的分区 key=value 输出;脚本严格解析或需要完整嵌套结构时再传 -f json 或 --json。JSON envelope 字段已做归一化,见 canonicalFields。',
1139
+ statePolicy: {
1140
+ purpose: 'Agent 应在同一轮 / 同一项目中维护 AWB 上下文账本,减少重复查询和重复提交。',
1141
+ cacheKeys: [
1142
+ 'schema version / domains / commands',
1143
+ 'auth / account / team / current projectGroup',
1144
+ 'modelCandidates by taskKind + keyword',
1145
+ 'assetReviewModels by modelGroupCode / platform',
1146
+ 'modelOptions / modelCreateSpec by modelGroupCode',
1147
+ 'uploaded backendPath by local file path or remote URL',
1148
+ 'taskId -> taskType / projectGroupNo / resultUrls / errorMessage',
1149
+ 'subject name + modelCode -> elementId / externalId / nextRefSubject',
1150
+ 'subject voice name + source -> voiceRecordId / externalId / nextVoiceArg',
1151
+ 'artifact projectId and imported file paths',
1152
+ ],
1153
+ invalidation: '用户切换账号、团队、项目组、模型、素材、prompt 或关键参数后,只刷新受影响的缓存;不要重复跑未变化的 model options / create-spec / fee。',
1154
+ },
1155
+ workflowPolicy: [
1156
+ '模型口语名命中后必须先展示候选模型、真实参数取值和资源能力,并在清单后 STOP 等用户选择或明确授权默认;没有完成用户可见候选清单和确认前,不得代选默认模型 / 参数,也不得进入 create-spec、fee、dry-run 或 create。',
1157
+ '模型探索阶段只读 model list / options / create-spec;fee 只在用户确认关键参数后跑一次。',
1158
+ 'model options.params[] 中带 cliArg/genericModelParam 的新增模型配置参数可通过 --model-param key=value、--model-params-json 或同名下划线长参数传入;defaultValue 只能展示为候选默认,不能静默代选。',
1159
+ 'supportsDryRun=true 的写入 / 扣费命令先 dry-run,确认后 yes;不要把 dry-run 当参数探索工具反复跑。',
1160
+ '用户给出多条同模型同参数任务时优先 batch + task-record-file,不要单条循环 create。',
1161
+ '命令返回 nextCommand / nextRefSubject / nextVoiceArg 时优先复用返回值,不手拼等价命令。',
1162
+ '素材加白平台先通过 model asset-review-models 或用户明确输入确定;create asset-* 必须显式传 --platform,不要依赖默认平台。',
1163
+ '旧根域 image / video / asset / subject 已移除;只使用 create / task / artifact 等 schema 暴露的 domain。',
1164
+ ],
1165
+ canonicalFields: {
1166
+ purpose: 'CLI 输出对上游平台多版本字段做了归一化。Agent 只识别 canonical 列,遇到 aliases 列出的旧字段名时说明是上游原始返回,CLI 已在 text / 归一化层做了 fallback。不要把旧名当成独立新字段对外报告。',
1167
+ fields: [
1168
+ { canonical: 'billingPointBalance', aliases: ['teamPointBalance'], meaning: '实际可扣积分余额(/api/anime/member/benefits/queryGroupPoint)' },
1169
+ { canonical: 'billingPointRemainingAfter', aliases: ['teamPointRemainingAfter'], meaning: '本次任务后预计可扣积分余额' },
1170
+ { canonical: 'projectBudgetBalance', aliases: ['projectPointBalance'], meaning: '项目组预算 / ROI 余额(不是积分)' },
1171
+ { canonical: 'projectBudgetMax', aliases: ['projectPointMax'], meaning: '项目组预算上限' },
1172
+ { canonical: 'projectBudgetRemainingAfter', aliases: ['projectPointRemainingAfter'], meaning: '本次任务后预计项目组预算余额' },
1173
+ { canonical: 'pointCost', aliases: ['points', 'point', 'costPoint', 'estimatePoint'], meaning: '本次任务预计 / 实际消耗积分' },
1174
+ ],
1175
+ },
1176
+ schemaPolicy: 'Agent 先读 schema --brief 建立能力地图;执行具体命令前再读精确 schema --domain <domain> --command <command>。完整 schema -f json 只用于覆盖校验、脚本生成或调试 schema 本身;查看长帮助用 schema.commands[].helpCommand 或 lj-awb <domain> <command> -h。',
663
1177
  confirmationPolicy: 'schema.commands[].safety.requiresConfirmation=true 的命令,Agent 必须先向用户确认,再追加 --yes。',
664
1178
  dryRunPolicy: 'schema.commands[].safety.supportsDryRun=true 的写入 / 扣费命令,正式执行前优先跑 --dry-run。',
665
1179
  resourceShortcut: {
666
1180
  flag: '--resource',
667
- syntax: 'type:usage[:reference_key]=path|url|asset:<id>; image create uses image:reference=... without key',
1181
+ syntax: 'type:usage[:reference_key]=path|url|asset:<id>; create image uses image:reference=... without key',
668
1182
  examples: [
669
1183
  'image:reference=./ref.png',
670
1184
  'image:first_frame=./hero.png',
@@ -678,34 +1192,48 @@ function buildAgentContract() {
678
1192
  {
679
1193
  type: 'image|video|audio|subject',
680
1194
  usage: 'reference|first_frame|last_frame|keyframe',
681
- reference_key: 'video reference placeholder key; not used by image create image:reference',
1195
+ reference_key: 'video reference placeholder key; not used by create image image:reference',
682
1196
  source: { kind: 'url|asset_id', value: '<local-file-or-http-url-or-material-backendPath-or-asset-id>' },
683
1197
  },
684
1198
  ],
685
1199
  },
1200
+ modelCandidatePresentation: {
1201
+ purpose: '把 model image-models / video-models 与每个候选的 model options 转成用户可见清单,避免 Agent 内部看完 options 后直接代选。',
1202
+ trigger: '用户问有哪些模型、给出口语名、或模型列表返回候选时都触发;即使只有一个候选也要展示真实可选项。',
1203
+ gateType: 'hard_stop',
1204
+ stopAfterPresentation: true,
1205
+ resumeCondition: '用户选择模型和关键参数,或明确说“按默认 / 你来选”。',
1206
+ requiredVisibleFields: ['displayName', 'modelDesc', 'taskQueueNum', 'quality values/default', 'ratio values/default', 'duration or generateNum values/default', 'resource modes/media/usages', 'channel or fast/pro differences'],
1207
+ blockedBeforePresentation: ['model create-spec', 'create image-fee', 'create video-fee', 'create image-batch --dry-run', 'create video-batch --dry-run', 'create image --dry-run', 'create video --dry-run', 'create image', 'create video', 'default model recommendation', 'default quality/ratio/duration choice'],
1208
+ },
686
1209
  modelOptions: {
687
1210
  command: `${commandPrefix()} model options --model-group-code <code>`,
1211
+ textCommand: `${commandPrefix()} model options --model-group-code <code> -f text`,
688
1212
  jsonCommand: `${commandPrefix()} model options --model-group-code <code> -f json`,
689
- purpose: '查询指定模型支持的 CLI 参数、枚举值、默认值、素材约束和条件约束。',
690
- useBefore: ['model create-spec', 'image fee', 'image create', 'video fee', 'video create'],
691
- keyFields: ['params[].values', 'params[].defaultValue', 'resources[].mediaType', 'resources[].usage', 'resources[].fileTypes', 'resources[].maxFiles', 'resources[].supportLastFrameOnly', 'resources[].minDurationMs', 'resources[].maxDurationMs', 'constraints[].target', 'constraints[].conditions', 'constraints[].effect'],
1213
+ purpose: '查询指定模型支持的 CLI 参数、枚举值、默认值、素材约束和条件约束。Agent 默认读 textCommand;只有程序化校验完整嵌套结构时读 jsonCommand。',
1214
+ useBefore: ['model create-spec', 'create image-fee', 'create image', 'create video-fee', 'create video'],
1215
+ keyFields: ['params[].key', 'params[].cliArg', 'params[].genericModelParam', 'params[].values', 'params[].defaultValue', 'resources[].mediaType', 'resources[].usage', 'resources[].fileTypes', 'resources[].maxFiles', 'resources[].supportLastFrameOnly', 'resources[].minDurationMs', 'resources[].maxDurationMs', 'constraints[].target', 'constraints[].conditions', 'constraints[].effect'],
692
1216
  },
693
1217
  modelCreateSpec: {
694
1218
  command: `${commandPrefix()} model create-spec --model-group-code <code>`,
1219
+ textCommand: `${commandPrefix()} model create-spec --model-group-code <code> -f text`,
695
1220
  jsonCommand: `${commandPrefix()} model create-spec --model-group-code <code> -f json`,
696
- purpose: '查看指定模型如何组织 create 命令:输入模式、素材绑定规则、示例和创建前检查项。',
697
- useBefore: ['image fee', 'image create', 'video fee', 'video create'],
1221
+ purpose: '查看指定模型如何组织 create 命令:输入模式、素材绑定规则、示例和创建前检查项。Agent 默认读 textCommand;只有程序化校验完整嵌套结构时读 jsonCommand。',
1222
+ useBefore: ['create image-fee', 'create image', 'create video-fee', 'create video'],
698
1223
  keyFields: ['inputRequirement', 'supportedIntents', 'validationRules', 'agentGuidance', 'preflight', 'examples'],
699
1224
  },
700
1225
  modelInputGuide: {
701
1226
  command: `${commandPrefix()} model input-guide`,
1227
+ textCommand: `${commandPrefix()} model input-guide -f text`,
702
1228
  jsonCommand: `${commandPrefix()} model input-guide -f json`,
703
- purpose: '查看跨模型统一创建参数、resources 字段和素材绑定规则。',
1229
+ purpose: '查看跨模型统一创建参数、resources 字段和素材绑定规则。Agent 默认读 textCommand;脚本严格解析时读 jsonCommand。',
704
1230
  useBefore: ['model options', 'model create-spec'],
705
1231
  },
706
1232
  taskTypes: {
707
1233
  image: 'IMAGE_CREATE',
708
1234
  video: 'VIDEO_GROUP',
1235
+ subtitleRemoval: 'VIDEO_SUBTITLE_REMOVAL',
1236
+ assetRegister: 'ASSET_REGISTER',
709
1237
  },
710
1238
  exitCodes: [
711
1239
  { code: 0, type: 'success', meaning: '命令成功' },
@@ -713,24 +1241,21 @@ function buildAgentContract() {
713
1241
  { code: 2, type: 'argument_error|unknown_command|unknown_option', meaning: '参数或命令错误' },
714
1242
  { code: 3, type: 'auth_required|auth_failed', meaning: '缺少认证或认证失败' },
715
1243
  { code: 10, type: 'confirmation_required', meaning: '需要用户确认后追加 --yes' },
716
- { code: 20, type: 'task_still_running|subject_still_pending', meaning: '任务仍在运行,本轮等待窗口结束' },
1244
+ { code: 1, type: 'subject_failed', meaning: '主体创建任务已失败(error.type=subject_failed)。查看 error.details.errorMessage 后调整参考资源或模型重新创建。' },
1245
+ { code: 1, type: 'subject_voice_failed', meaning: '主体音色创建任务已失败(error.type=subject_voice_failed)。查看 error.details.errorMessage 后调整音频或视频来源重新创建。' },
1246
+ { code: 20, type: 'task_still_running', meaning: '生图 / 生视频任务仍在运行,本轮等待窗口结束(error.type=task_still_running)。可继续 task wait 或 record-poll 续等。' },
1247
+ { code: 20, type: 'subject_still_pending', meaning: '主体 externalId 尚未回填,本轮等待窗口结束(error.type=subject_still_pending)。可继续 create subject-wait 续等。' },
1248
+ { code: 20, type: 'subject_voice_still_pending', meaning: '主体音色 externalId 尚未回填,本轮等待窗口结束(error.type=subject_voice_still_pending)。可继续 create subject-voice-wait 续等。' },
717
1249
  { code: 30, type: 'network_error', meaning: '网络、TLS、HTTP 或外部平台不可用' },
718
1250
  ],
719
1251
  };
720
1252
  }
721
1253
 
722
1254
  function buildCommandSchema(commands, kwargs = {}, version = 'unknown') {
1255
+ if (toBool(kwargs.brief)) return buildAgentBrief(commands, version);
723
1256
  const domainFilter = String(kwargs.domain ?? '').trim();
724
1257
  const commandFilter = String(kwargs.command ?? '').trim();
725
- const domains = new Map();
726
- for (const command of commands) {
727
- const group = commandGroup(command);
728
- domains.set(group, {
729
- name: group,
730
- description: GROUP_DESCRIPTIONS[group] || '',
731
- commandCount: (domains.get(group)?.commandCount || 0) + 1,
732
- });
733
- }
1258
+ const domains = buildDomainSummaries(commands);
734
1259
  const filteredCommands = commands
735
1260
  .filter((command) => !domainFilter || commandGroup(command) === domainFilter)
736
1261
  .filter((command) => !commandFilter || command.name === commandFilter || commandSubcommand(command) === commandFilter);
@@ -754,48 +1279,16 @@ function buildCommandSchema(commands, kwargs = {}, version = 'unknown') {
754
1279
  `${commandPrefix()} <domain> <command> -h`,
755
1280
  ],
756
1281
  globalOptions: [
757
- { flag: '-f, --format json', key: 'format', description: '输出 JSON;默认不传时输出精简文本' },
1282
+ { flag: '-f, --format <format>', key: 'format', description: '输出格式:pretty(默认)、text、json、yaml、csv、auto' },
758
1283
  { flag: '--json', key: 'format', value: 'json', description: '等同于 -f json' },
759
1284
  { flag: '-h, --help', key: 'help', description: '查看帮助' },
760
1285
  { flag: '-v, --version', key: 'version', description: '查看版本' },
761
1286
  ],
762
1287
  agentContract: buildAgentContract(),
763
- domains: Array.from(domains.values())
1288
+ domains: domains
764
1289
  .filter((domain) => !shouldFilterDomains || matchedDomains.has(domain.name))
765
1290
  .sort((a, b) => a.name.localeCompare(b.name)),
766
- commands: filteredCommands.map((command) => {
767
- const requiredOptions = new Set(COMMAND_REQUIRED_OPTIONS[command.name] || []);
768
- if (commandGroup(command) === 'artifact') requiredOptions.add('projectId');
769
- const requiredAnyOptions = COMMAND_REQUIRED_ANY_OPTIONS[command.name] || [];
770
- const optionKeys = new Set((command.args || []).map((arg) => normalizeKey(arg.name)));
771
- return {
772
- name: command.name,
773
- domain: commandGroup(command),
774
- command: commandSubcommand(command),
775
- invocation: `${commandPrefix()} ${command.name}`,
776
- helpCommand: `${commandPrefix()} ${command.name} -h`,
777
- summary: summaryOf(command),
778
- description: renderCliText(summaryOf(command)),
779
- examples: extractExamples(command).map(renderCliText),
780
- jsonExamples: extractExamples(command).map(asJsonExample),
781
- requiredOptions: [...requiredOptions],
782
- requiredAnyOptions,
783
- safety: buildCommandSafety(command, optionKeys),
784
- workflow: buildCommandWorkflow(command),
785
- options: (command.args || []).map((arg) => {
786
- const key = normalizeKey(arg.name);
787
- return {
788
- name: arg.name,
789
- key,
790
- flag: formatOptionName(arg.name),
791
- valueName: arg.valueName || null,
792
- required: requiredOptions.has(key),
793
- requiredAnyGroup: requiredAnyOptions.find((group) => group.includes(key)) || null,
794
- description: arg.description || '',
795
- };
796
- }),
797
- };
798
- }),
1291
+ commands: filteredCommands.map(buildCommandSchemaEntry),
799
1292
  };
800
1293
  }
801
1294
 
@@ -808,140 +1301,283 @@ function printRootHelp(commands, version) {
808
1301
  }
809
1302
 
810
1303
  const lines = [
811
- `lj-awb v${version}`,
1304
+ helpTitle(`lj-awb v${version}`),
812
1305
  '',
813
- '灵境 AWB 命令行工具。默认输出精简文本;需要 JSON 时传 -f json。',
1306
+ '灵境 AWB 命令行工具。默认输出人类友好的 pretty 视图;Agent 建议显式传 -f text,脚本严格解析用 -f json。',
814
1307
  '',
815
- 'Usage:',
816
- ` ${commandPrefix()} <domain> <command> [options]`,
817
- ` ${commandPrefix()} <command> [options]`,
818
- ` ${commandPrefix()} <domain> -h`,
819
- ` ${commandPrefix()} <domain> <command> -h`,
1308
+ helpHeading('Usage:'),
1309
+ helpCommand(` ${commandPrefix()} <domain> <command> [options]`),
1310
+ helpCommand(` ${commandPrefix()} <command> [options]`),
1311
+ helpCommand(` ${commandPrefix()} <domain> -h`),
1312
+ helpCommand(` ${commandPrefix()} <domain> <command> -h`),
820
1313
  '',
821
- 'Quick start:',
822
- ` ${commandPrefix()} auth status`,
823
- ` ${commandPrefix()} auth login-key --access-key <access-key>`,
824
- ` ${commandPrefix()} model image-models --model Banana`,
825
- ` ${commandPrefix()} model input-guide`,
826
- ` ${commandPrefix()} model options --model-group-code <code>`,
827
- ` ${commandPrefix()} model create-spec --model-group-code <code>`,
828
- ` ${commandPrefix()} image create --model-group-code <code> --prompt "一只小狗" --dry-run`,
1314
+ helpHeading('Quick start:'),
1315
+ helpCommand(` ${commandPrefix()} auth status`),
1316
+ helpCommand(` ${commandPrefix()} auth login --access-key <access-key>`),
1317
+ helpCommand(` ${commandPrefix()} model image-models --model Banana`),
1318
+ helpCommand(` ${commandPrefix()} model input-guide`),
1319
+ helpCommand(` ${commandPrefix()} model options --model-group-code <code>`),
1320
+ helpCommand(` ${commandPrefix()} model create-spec --model-group-code <code>`),
1321
+ helpCommand(` ${commandPrefix()} create image --model-group-code <code> --prompt "一只小狗" --dry-run`),
829
1322
  '',
830
- 'Command groups:',
1323
+ helpHeading('Command groups:'),
831
1324
  ];
832
1325
  for (const [group] of groups.entries()) {
833
- lines.push(` ${group.padEnd(12)} ${GROUP_DESCRIPTIONS[group] || ''}`);
1326
+ lines.push(` ${helpGroup(group.padEnd(12))} ${GROUP_DESCRIPTIONS[group] || ''}`);
834
1327
  }
835
1328
  lines.push(
836
1329
  '',
837
- 'More help:',
838
- ` ${commandPrefix()} <domain> -h`,
839
- ` ${commandPrefix()} <domain> <command> -h`,
840
- ` ${commandPrefix()} schema -f json`,
841
- ` ${commandPrefix()} doctor -h`,
1330
+ helpHeading('More help:'),
1331
+ helpCommand(` ${commandPrefix()} <domain> -h`),
1332
+ helpCommand(` ${commandPrefix()} <domain> <command> -h`),
1333
+ helpCommand(` ${commandPrefix()} schema --brief -f json`),
1334
+ helpCommand(` ${commandPrefix()} schema -f json`),
1335
+ helpCommand(` ${commandPrefix()} doctor -h`),
842
1336
  '',
843
- 'Global options:',
844
- ' -f, --format json 输出 JSON;默认不传时输出精简文本',
845
- ' --json 等同于 -f json',
846
- ' -h, --help 查看帮助',
847
- ' -v, --version 查看版本',
1337
+ helpHeading('Global options:'),
1338
+ ` ${helpOption('-f, --format <format>')} 输出格式:pretty(默认)、text、json、yaml、csv、auto`,
1339
+ ` ${helpOption('--json'.padEnd(22))} 等同于 -f json`,
1340
+ ` ${helpOption('-h, --help'.padEnd(22))} 查看帮助`,
1341
+ ` ${helpOption('-v, --version'.padEnd(22))} 查看版本`,
848
1342
  );
849
1343
  process.stdout.write(`${lines.join('\n')}\n`);
850
1344
  }
851
1345
 
852
1346
  function printGroupHelp(group, commands, version) {
853
1347
  const items = commands.filter((command) => commandGroup(command) === group);
1348
+ const subgroupMap = SUBGROUP_DESCRIPTIONS[group];
1349
+ const hasSubgroups = Boolean(subgroupMap && Object.keys(subgroupMap).length);
1350
+ const directItems = hasSubgroups ? items.filter((command) => !commandSubgroupTokens(command)) : [];
1351
+
854
1352
  const lines = [
855
- `lj-awb v${version}`,
1353
+ helpTitle(`lj-awb v${version}`),
856
1354
  '',
857
1355
  GROUP_DESCRIPTIONS[group] || `${group} 命令组`,
858
1356
  '',
859
- 'Usage:',
860
- group === 'system' ? ` ${commandPrefix()} <command> [options]` : ` ${commandPrefix()} ${group} <command> [options]`,
861
- '',
862
- group === 'system'
863
- ? `提示:system 是命令组;下面的命令可直接运行,例如 ${commandPrefix()} doctor。`
864
- : `提示:${group} 是命令组;请选择下面的子命令运行。`,
865
- '',
866
- 'Commands:',
1357
+ helpHeading('Usage:'),
867
1358
  ];
868
- for (const command of items) {
869
- const subcommand = commandSubcommand(command);
870
- lines.push(` ${subcommand.padEnd(28)} ${summaryOf(command)}`);
1359
+ if (group === 'system') {
1360
+ lines.push(helpCommand(` ${commandPrefix()} <command> [options]`));
1361
+ } else if (hasSubgroups) {
1362
+ if (directItems.length) lines.push(helpCommand(` ${commandPrefix()} ${group} <command> [options]`));
1363
+ lines.push(helpCommand(` ${commandPrefix()} ${group} <subdomain> <command> [options]`));
1364
+ } else {
1365
+ lines.push(helpCommand(` ${commandPrefix()} ${group} <command> [options]`));
871
1366
  }
1367
+ lines.push('');
1368
+ if (group === 'system') {
1369
+ lines.push(helpMuted(`提示:system 是命令组;下面的命令可直接运行,例如 ${commandPrefix()} doctor。`));
1370
+ } else if (hasSubgroups) {
1371
+ lines.push(helpMuted(`提示:${group} 下按子领域分组;先选子领域再看具体命令。`));
1372
+ } else {
1373
+ lines.push(helpMuted(`提示:${group} 是命令组;请选择下面的子命令运行。`));
1374
+ }
1375
+ lines.push('');
1376
+
1377
+ if (hasSubgroups) {
1378
+ const presentSubgroups = new Set(
1379
+ items
1380
+ .map((command) => commandSubgroupTokens(command))
1381
+ .filter(Boolean)
1382
+ .map(([, subgroup]) => subgroup),
1383
+ );
1384
+ lines.push(helpHeading('Subdomains:'));
1385
+ for (const [subgroup, description] of Object.entries(subgroupMap)) {
1386
+ if (!presentSubgroups.has(subgroup)) continue;
1387
+ lines.push(` ${helpGroup(subgroup.padEnd(10))} ${description}`);
1388
+ }
1389
+ if (directItems.length) {
1390
+ lines.push('', helpHeading('Commands:'));
1391
+ for (const command of directItems) {
1392
+ const subcommand = commandSubcommand(command);
1393
+ lines.push(` ${helpCommand(subcommand.padEnd(28))} ${summaryOf(command)}`);
1394
+ }
1395
+ }
1396
+ } else {
1397
+ lines.push(helpHeading('Commands:'));
1398
+ for (const command of items) {
1399
+ const subcommand = commandSubcommand(command);
1400
+ lines.push(` ${helpCommand(subcommand.padEnd(28))} ${summaryOf(command)}`);
1401
+ }
1402
+ }
1403
+
872
1404
  if (GROUP_EXAMPLES[group]?.length) {
873
- lines.push('', 'Examples:');
1405
+ lines.push('', helpHeading('Examples:'));
874
1406
  for (const example of GROUP_EXAMPLES[group]) {
875
- lines.push(` ${renderCliText(example)}`);
1407
+ lines.push(helpCommand(` ${renderCliText(example)}`));
876
1408
  }
877
1409
  }
878
- lines.push('', 'More help:');
1410
+ lines.push('', helpHeading('More help:'));
879
1411
  if (group === 'system') {
880
- for (const command of items) lines.push(` ${commandPrefix()} ${command.name} -h`);
1412
+ for (const command of items) lines.push(helpCommand(` ${commandPrefix()} ${command.name} -h`));
1413
+ } else if (hasSubgroups) {
1414
+ lines.push(helpCommand(` ${commandPrefix()} ${group} <subdomain> -h`));
1415
+ lines.push(helpCommand(` ${commandPrefix()} ${group} <subdomain> <command> -h`));
881
1416
  } else {
882
- lines.push(` ${commandPrefix()} ${group} <command> -h`);
1417
+ lines.push(helpCommand(` ${commandPrefix()} ${group} <command> -h`));
1418
+ }
1419
+ process.stdout.write(`${lines.join('\n')}\n`);
1420
+ }
1421
+
1422
+ function printSubgroupHelp(group, subgroup, commands, version) {
1423
+ const items = commands.filter((command) => {
1424
+ const tokens = commandSubgroupTokens(command);
1425
+ return tokens && tokens[0] === group && tokens[1] === subgroup;
1426
+ });
1427
+ const description = SUBGROUP_DESCRIPTIONS[group]?.[subgroup] || `${group} ${subgroup} 子领域`;
1428
+ const lines = [
1429
+ helpTitle(`lj-awb v${version}`),
1430
+ '',
1431
+ description,
1432
+ '',
1433
+ helpHeading('Usage:'),
1434
+ helpCommand(` ${commandPrefix()} ${group} ${subgroup} <command> [options]`),
1435
+ '',
1436
+ helpHeading('Commands:'),
1437
+ ];
1438
+ for (const command of items) {
1439
+ const parts = String(command.name || '').split(' ').filter(Boolean);
1440
+ const tail = parts.slice(2).join(' ');
1441
+ lines.push(` ${helpCommand(tail.padEnd(28))} ${summaryOf(command)}`);
1442
+ }
1443
+ const examples = SUBGROUP_EXAMPLES[`${group} ${subgroup}`];
1444
+ if (examples?.length) {
1445
+ lines.push('', helpHeading('Examples:'));
1446
+ for (const example of examples) {
1447
+ lines.push(helpCommand(` ${renderCliText(example)}`));
1448
+ }
883
1449
  }
1450
+ lines.push('', helpHeading('More help:'));
1451
+ lines.push(helpCommand(` ${commandPrefix()} ${group} ${subgroup} <command> -h`));
884
1452
  process.stdout.write(`${lines.join('\n')}\n`);
885
1453
  }
886
1454
 
887
1455
  function printCommandHelp(command) {
888
- const lines = [`Usage: ${commandPrefix()} ${command.name} [options]`, '', renderCliText(command.description || '')];
1456
+ const lines = [helpHeading(`Usage: ${commandPrefix()} ${command.name} [options]`), '', renderCliText(command.description || '')];
889
1457
  if (command.args?.length) {
890
- lines.push('', 'Options:');
1458
+ lines.push('', helpHeading('Options:'));
891
1459
  for (const arg of command.args) {
892
1460
  const value = arg.valueName ? ` <${arg.valueName}>` : '';
893
1461
  const description = arg.description ? ` ${arg.description}` : '';
894
- lines.push(` --${arg.name}${value}${description}`);
1462
+ lines.push(` ${helpOption(`--${arg.name}${value}`)}${description}`);
895
1463
  }
896
1464
  }
897
- lines.push('', 'Global options:', ' -f, --format json 输出 JSON;默认不传时输出精简文本', ' --json 等同于 -f json');
1465
+ lines.push(
1466
+ '',
1467
+ helpHeading('Global options:'),
1468
+ ` ${helpOption('-f, --format <format>')} 输出格式:pretty(默认)、text、json、yaml、csv、auto`,
1469
+ ` ${helpOption('--json'.padEnd(22))} 等同于 -f json`,
1470
+ );
898
1471
  process.stdout.write(`${lines.join('\n')}\n`);
899
1472
  }
900
1473
 
901
- function validateCommandOptions(command, kwargs) {
1474
+ function validateCommandOptions(command, kwargs, kwargRawFlags = {}) {
902
1475
  const allowedKeys = (command.args || []).map((arg) => normalizeKey(arg.name));
903
1476
  const allowed = new Set(allowedKeys);
904
- const unknown = Object.keys(kwargs).filter((key) => !allowed.has(key));
1477
+ const unknown = Object.keys(kwargs).filter((key) => (
1478
+ !allowed.has(key)
1479
+ && !(command.allowDynamicModelParams && key.includes('_'))
1480
+ ));
905
1481
  if (!unknown.length) return;
1482
+ const displayFlag = (key) => kwargRawFlags[key] || formatOptionName(key);
906
1483
  const suggestions = {};
907
1484
  for (const unk of unknown) {
908
1485
  const matches = suggestSimilarOptions(unk, allowedKeys);
909
- if (matches.length) suggestions[formatOptionName(unk)] = matches;
1486
+ if (matches.length) suggestions[displayFlag(unk)] = matches;
910
1487
  }
1488
+ const usedShortForm = unknown.some((key) => {
1489
+ const flag = kwargRawFlags[key];
1490
+ return flag && flag.startsWith('-') && !flag.startsWith('--');
1491
+ });
911
1492
  const baseHint = `运行 ${commandPrefix()} ${command.name} -h 查看可用参数。`;
1493
+ const shortHint = usedShortForm
1494
+ ? `本 CLI 仅支持 -f / -h / -v 等少数短选项,业务参数请使用 --xxx 长形式。`
1495
+ : '';
912
1496
  const suggestionParts = Object.entries(suggestions).map(([opt, matches]) => `${opt} → ${matches.join(' / ')}`);
913
- const hint = suggestionParts.length
914
- ? `你是不是想用:${suggestionParts.join(';')}?否则 ${baseHint}`
915
- : baseHint;
916
- throw new LingjingAwbCliError(`未知参数:${unknown.map(formatOptionName).join(', ')}`, {
1497
+ const hintParts = [];
1498
+ if (suggestionParts.length) hintParts.push(`你是不是想用:${suggestionParts.join(';')}?`);
1499
+ if (shortHint) hintParts.push(shortHint);
1500
+ hintParts.push(baseHint);
1501
+ throw new LingjingAwbCliError(`未知参数:${unknown.map(displayFlag).join(', ')}`, {
917
1502
  type: 'unknown_option',
918
1503
  exitCode: 2,
919
- hint,
1504
+ hint: hintParts.join(' '),
920
1505
  details: {
921
1506
  command: command.name,
922
- unknownOptions: unknown.map(formatOptionName),
1507
+ unknownOptions: unknown.map(displayFlag),
923
1508
  ...(Object.keys(suggestions).length ? { suggestions } : {}),
924
1509
  },
925
1510
  });
926
1511
  }
927
1512
 
1513
+ function normalizeDynamicModelParamFlags(command, kwargs = {}, kwargRawFlags = {}) {
1514
+ if (!command.allowDynamicModelParams) return;
1515
+ const allowed = new Set((command.args || []).map((arg) => normalizeKey(arg.name)));
1516
+ for (const key of Object.keys(kwargs)) {
1517
+ if (allowed.has(key) || key.includes('_')) continue;
1518
+ const flag = kwargRawFlags[key] || formatOptionName(key);
1519
+ if (!flag.startsWith('--') || !flag.includes('-')) continue;
1520
+ const normalized = flag.slice(2).replaceAll('-', '_');
1521
+ if (!normalized || normalized === key || allowed.has(normalized)) continue;
1522
+ if (kwargs[normalized] === undefined) kwargs[normalized] = kwargs[key];
1523
+ delete kwargs[key];
1524
+ if (kwargRawFlags[key] && !kwargRawFlags[normalized]) kwargRawFlags[normalized] = kwargRawFlags[key];
1525
+ }
1526
+ }
1527
+
928
1528
  function printData(data, format, meta = {}, context = {}) {
929
- if (format === 'json') {
1529
+ const outputFormat = resolveOutputFormat(format);
1530
+ if (outputFormat === 'json') {
930
1531
  process.stdout.write(`${JSON.stringify(createEnvelope({ status: 'success', data: normalizeJsonData(meta.command, data), meta }), null, 2)}\n`);
931
1532
  return;
932
1533
  }
933
- process.stdout.write(formatTextOutput(meta.command, data, context));
1534
+ if (outputFormat === 'yaml') {
1535
+ process.stdout.write(formatYamlEnvelope(createEnvelope({ status: 'success', data: normalizeJsonData(meta.command, data), meta })));
1536
+ return;
1537
+ }
1538
+ if (outputFormat === 'csv') {
1539
+ process.stdout.write(formatCsvOutput(meta.command, data, context));
1540
+ return;
1541
+ }
1542
+ if (outputFormat === 'text') {
1543
+ process.stdout.write(formatTextOutput(meta.command, data, context));
1544
+ return;
1545
+ }
1546
+ process.stdout.write(formatPrettyOutput(meta.command, data, context));
1547
+ }
1548
+
1549
+ function printUpdateNotice(updateNotice) {
1550
+ if (!updateNotice?.message) return;
1551
+ process.stderr.write(`${updateNotice.message}\n`);
1552
+ }
1553
+
1554
+ function isStructuredOutputFormat(format) {
1555
+ try {
1556
+ return ['json', 'yaml'].includes(resolveOutputFormat(format));
1557
+ } catch {
1558
+ return false;
1559
+ }
934
1560
  }
935
1561
 
936
1562
  function printError(error, format, meta = {}) {
1563
+ let outputFormat = 'text';
1564
+ try {
1565
+ outputFormat = resolveOutputFormat(format);
1566
+ } catch {
1567
+ outputFormat = 'text';
1568
+ }
937
1569
  const payload = {
938
1570
  type: error.type || 'error',
939
1571
  message: error.message || String(error),
940
1572
  ...(error.hint ? { hint: error.hint } : {}),
941
1573
  ...(error.details ? { details: error.details } : {}),
942
1574
  };
943
- if (format === 'json') {
1575
+ if (outputFormat === 'json') {
944
1576
  process.stderr.write(`${JSON.stringify(createEnvelope({ status: 'error', error: payload, meta }), null, 2)}\n`);
1577
+ } else if (outputFormat === 'yaml') {
1578
+ process.stderr.write(formatYamlEnvelope(createEnvelope({ status: 'error', error: payload, meta })));
1579
+ } else if (outputFormat === 'pretty') {
1580
+ process.stderr.write(formatPrettyError(payload));
945
1581
  } else {
946
1582
  process.stderr.write(formatTextError(payload));
947
1583
  }
@@ -958,10 +1594,20 @@ export async function runStandaloneCli(argv = process.argv.slice(2)) {
958
1594
  const command = commands.find((item) => item.name === resolvedCommandName);
959
1595
  if (command) {
960
1596
  printCommandHelp(command);
1597
+ } else if (isCommandSubgroupName(parsed.commandName, commands)) {
1598
+ const [group, subgroup] = parsed.commandName.split(' ');
1599
+ printSubgroupHelp(group, subgroup, commands, version);
961
1600
  } else if (isCommandGroupName(parsed.commandName, commands)) {
962
1601
  printGroupHelp(parsed.commandName, commands, version);
963
- } else {
1602
+ } else if (!parsed.commandName) {
964
1603
  printRootHelp(commands, version);
1604
+ } else {
1605
+ printError(new LingjingAwbCliError(`未知命令: ${parsed.commandName}`, {
1606
+ type: 'unknown_command',
1607
+ exitCode: 2,
1608
+ hint: unknownCommandHint(parsed.commandName),
1609
+ }), parsed.format, { command: parsed.commandName });
1610
+ process.exitCode = 2;
965
1611
  }
966
1612
  return;
967
1613
  }
@@ -971,10 +1617,16 @@ export async function runStandaloneCli(argv = process.argv.slice(2)) {
971
1617
  return;
972
1618
  }
973
1619
 
974
- const { commandName: rawCommandName, kwargs, format } = parseArgv(argv);
1620
+ const { commandName: rawCommandName, kwargs, kwargRawFlags, format } = parseArgv(argv);
975
1621
  const commandName = resolveCommandName(rawCommandName, commands);
976
1622
  const command = commands.find((item) => item.name === commandName);
1623
+ const updateNotice = await resolveUpdateNotice(argv, commandName || rawCommandName, version);
977
1624
  if (!command) {
1625
+ if (isCommandSubgroupName(rawCommandName, commands)) {
1626
+ const [group, subgroup] = rawCommandName.split(' ');
1627
+ printSubgroupHelp(group, subgroup, commands, version);
1628
+ return;
1629
+ }
978
1630
  if (isCommandGroupName(rawCommandName, commands)) {
979
1631
  printGroupHelp(rawCommandName, commands, version);
980
1632
  return;
@@ -983,18 +1635,27 @@ export async function runStandaloneCli(argv = process.argv.slice(2)) {
983
1635
  type: 'unknown_command',
984
1636
  exitCode: 2,
985
1637
  hint: unknownCommandHint(rawCommandName),
986
- }), format, { command: rawCommandName });
1638
+ }), format, {
1639
+ command: rawCommandName,
1640
+ ...(updateNotice ? { _notice: { update: updateNotice } } : {}),
1641
+ });
987
1642
  process.exitCode = 2;
1643
+ if (!isStructuredOutputFormat(format)) printUpdateNotice(updateNotice);
988
1644
  return;
989
1645
  }
990
1646
 
991
1647
  const startedAt = Date.now();
992
1648
  try {
993
- validateCommandOptions(command, kwargs);
1649
+ const outputFormat = resolveOutputFormat(format);
1650
+ normalizeDynamicModelParamFlags(command, kwargs, kwargRawFlags);
1651
+ validateCommandOptions(command, kwargs, kwargRawFlags);
994
1652
  const data = command.virtual === 'schema'
995
1653
  ? buildCommandSchema(commands, kwargs, version)
996
1654
  : await command.func({ command }, kwargs);
997
- printData(data, format, { command: command.name, elapsedMs: Date.now() - startedAt }, buildOutputContext(command, kwargs));
1655
+ const meta = { command: command.name, elapsedMs: Date.now() - startedAt };
1656
+ if (updateNotice) meta._notice = { update: updateNotice };
1657
+ printData(data, outputFormat, meta, buildOutputContext(command, kwargs));
1658
+ if (outputFormat !== 'json' && outputFormat !== 'yaml') printUpdateNotice(updateNotice);
998
1659
  } catch (error) {
999
1660
  const cliError = error instanceof LingjingAwbCliError
1000
1661
  ? error