@gaoding/cli 2.0.0 → 2.1.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 (132) hide show
  1. package/README.md +5 -0
  2. package/contracts/operations/agent.send/input.schema.json +8 -84
  3. package/contracts/operations/agent.send/output.schema.json +6 -6
  4. package/contracts/operations/credits.get/input.schema.json +9 -0
  5. package/contracts/operations/credits.get/output.schema.json +107 -0
  6. package/contracts/operations/credits.usage.get/input.schema.json +18 -0
  7. package/contracts/operations/credits.usage.get/output.schema.json +53 -0
  8. package/contracts/operations/credits.usage.list/input.schema.json +32 -0
  9. package/contracts/operations/credits.usage.list/output.schema.json +144 -0
  10. package/contracts/operations/dam.folder.list/input.schema.json +1 -1
  11. package/contracts/operations/dam.folder.list/output.schema.json +1 -1
  12. package/contracts/operations/dam.list/input.schema.json +2 -5
  13. package/contracts/operations/dam.list/output.schema.json +1 -1
  14. package/contracts/operations/dam.search/input.schema.json +2 -5
  15. package/contracts/operations/dam.search/output.schema.json +1 -1
  16. package/contracts/operations/model.get/output.schema.json +6 -5
  17. package/contracts/operations/model.list/output.schema.json +5 -4
  18. package/contracts/operations/task.get/output.schema.json +22 -11
  19. package/contracts/operations/tool.call/models/image-edit-smart.schema.json +7 -5
  20. package/contracts/operations/tool.call/models/image-edit-standard.schema.json +6 -4
  21. package/contracts/operations/tool.call/models/image-enhance-smart.schema.json +5 -3
  22. package/contracts/operations/tool.call/models/image-enhance-standard.schema.json +3 -2
  23. package/contracts/operations/tool.call/models/image-expand-smart.schema.json +16 -10
  24. package/contracts/operations/tool.call/models/image-expand-standard.schema.json +13 -8
  25. package/contracts/operations/tool.call/models/image-layers-layout.schema.json +3 -2
  26. package/contracts/operations/tool.call/models/image-layers-smart.schema.json +3 -4
  27. package/contracts/operations/tool.call/models/image-matting-smart.schema.json +6 -4
  28. package/contracts/operations/tool.call/models/image-matting-standard.schema.json +3 -2
  29. package/contracts/operations/tool.call/models/image-ocr.schema.json +3 -2
  30. package/contracts/operations/tool.call/models/image-remove-smart.schema.json +6 -4
  31. package/contracts/operations/tool.call/models/image-remove-standard.schema.json +4 -3
  32. package/contracts/operations/tool.call/models/image-text-edit.schema.json +5 -3
  33. package/contracts/operations/tool.call/models/image-vectorize.schema.json +3 -2
  34. package/contracts/operations/tool.call/models/video-edit-smart.schema.json +6 -6
  35. package/contracts/operations/tool.call/models/video-enhance-smart.schema.json +7 -4
  36. package/contracts/operations/tool.call/models/video-enhance-standard.schema.json +5 -3
  37. package/contracts/operations/tool.call/ocr-payload.schema.json +4 -5
  38. package/contracts/operations/tool.call/output.schema.json +9 -8
  39. package/dist/bin/postinstall.js +22 -6
  40. package/dist/bin/task-worker.js +2 -2
  41. package/dist/src/bootstrap/create-cli.js +31 -15
  42. package/dist/src/bootstrap/create-runtime.js +103 -30
  43. package/dist/src/bootstrap/run-task-worker.js +6 -2
  44. package/dist/src/bootstrap/validators.js +4 -1
  45. package/dist/src/cli/action-binding.js +17 -50
  46. package/dist/src/cli/agent-commands.js +11 -11
  47. package/dist/src/cli/auth-commands.js +2 -1
  48. package/dist/src/cli/creation-help.js +9 -0
  49. package/dist/src/cli/credits-command.js +127 -16
  50. package/dist/src/cli/dam-commands.js +10 -14
  51. package/dist/src/cli/editor-commands.js +7 -5
  52. package/dist/src/cli/errors.js +81 -22
  53. package/dist/src/cli/host-input.js +64 -5
  54. package/dist/src/cli/model-commands.js +9 -3
  55. package/dist/src/cli/observed-errors.js +7 -3
  56. package/dist/src/cli/org-commands.js +3 -1
  57. package/dist/src/cli/presenter.js +4 -0
  58. package/dist/src/cli/task-commands.js +6 -2
  59. package/dist/src/cli/tool-commands.js +12 -11
  60. package/dist/src/cli/update-command.js +24 -1
  61. package/dist/src/features/agent/creative-agent-adapter.js +6 -2
  62. package/dist/src/features/agent/creative-protocol.js +8 -29
  63. package/dist/src/features/agent/resource-authorizer.js +25 -17
  64. package/dist/src/features/agent/result-reader.js +31 -14
  65. package/dist/src/features/agent/use-cases.js +6 -31
  66. package/dist/src/features/credits/amount.js +51 -0
  67. package/dist/src/features/credits/response.js +11 -0
  68. package/dist/src/features/credits/use-cases.js +200 -30
  69. package/dist/src/features/dam/asset-projection.js +3 -6
  70. package/dist/src/features/dam/dam-api-adapter.js +30 -15
  71. package/dist/src/features/dam/repository-catalog.js +30 -21
  72. package/dist/src/features/dam/use-cases.js +12 -7
  73. package/dist/src/features/editor/bridge-client.js +0 -2
  74. package/dist/src/features/editor/public-url.js +1 -36
  75. package/dist/src/features/editor/session.js +3 -2
  76. package/dist/src/features/editor/use-cases.js +27 -2
  77. package/dist/src/features/org/org-service.js +10 -1
  78. package/dist/src/features/org/use-cases.js +18 -4
  79. package/dist/src/features/task/process-owner.js +54 -0
  80. package/dist/src/features/task/store.js +37 -10
  81. package/dist/src/features/task/task-background.js +5 -2
  82. package/dist/src/features/task/use-cases.js +184 -84
  83. package/dist/src/features/tool/argument-paths.js +14 -0
  84. package/dist/src/features/tool/canvas-copy.js +28 -15
  85. package/dist/src/features/tool/canvas-matting.js +123 -0
  86. package/dist/src/features/tool/canvas-media.js +100 -52
  87. package/dist/src/features/tool/canvas-models.js +66 -33
  88. package/dist/src/features/tool/canvas-pricing.js +12 -0
  89. package/dist/src/features/tool/canvas-recovery.js +13 -30
  90. package/dist/src/features/tool/canvas-results.js +79 -87
  91. package/dist/src/features/tool/canvas-tool-adapter.js +134 -157
  92. package/dist/src/features/tool/canvas-video.js +44 -37
  93. package/dist/src/features/tool/dynamic-schema.js +39 -40
  94. package/dist/src/features/tool/ffprobe-executable.js +21 -0
  95. package/dist/src/features/tool/mns-catalog-adapter.js +61 -24
  96. package/dist/src/features/tool/resource-authorizer.js +11 -3
  97. package/dist/src/features/tool/tool-api-adapter.js +73 -82
  98. package/dist/src/features/tool/tool-errors.js +25 -0
  99. package/dist/src/features/tool/tool-output.js +15 -0
  100. package/dist/src/features/tool/use-cases.js +74 -98
  101. package/dist/src/features/update/check-schema.js +17 -0
  102. package/dist/src/features/update/host-receipt.js +30 -0
  103. package/dist/src/features/update/notice-output.js +30 -0
  104. package/dist/src/features/update/update-lock.js +80 -0
  105. package/dist/src/features/update/update-notification.js +129 -240
  106. package/dist/src/features/update/update-service.js +95 -21
  107. package/dist/src/platform/media-type.js +46 -0
  108. package/dist/src/platform/public-url.js +35 -0
  109. package/dist/src/platform/remote-error-evidence.js +33 -6
  110. package/dist/src/platform/resource-auth-key.js +35 -1
  111. package/dist/src/platform/safe-upload-file.js +36 -41
  112. package/dist/src/platform/signature.js +3 -1
  113. package/dist/src/platform/signed-http-transport.js +14 -6
  114. package/dist/src/platform/url-safety.js +6 -1
  115. package/dist/src/platform/webm-header.js +41 -0
  116. package/dist/src/telemetry/command-route.js +38 -0
  117. package/dist/src/telemetry/command-routes.json +1 -0
  118. package/dist/src/telemetry/failure-summary.js +1 -1
  119. package/dist/src/telemetry/invocation.js +1 -2
  120. package/dist/src/telemetry/process-errors.js +17 -33
  121. package/dist/src/telemetry/sanitize.js +19 -4
  122. package/dist/src/telemetry/sls-sink.js +8 -0
  123. package/package.json +4 -4
  124. package/skills/gd-cli/SKILL.md +19 -5
  125. package/skills/gd-cli/references/agent.md +9 -4
  126. package/skills/gd-cli/references/creation.md +3 -1
  127. package/skills/gd-cli/references/editor.md +7 -5
  128. package/skills/gd-cli/references/errors.md +19 -8
  129. package/skills/gd-cli/references/matting.md +3 -5
  130. package/skills/gd-cli/references/media-tools.md +10 -4
  131. package/skills/gd-cli/references/tool.md +9 -15
  132. package/skills/gd-cli/references/update.md +6 -0
@@ -13,7 +13,8 @@
13
13
  "properties": {
14
14
  "model": {
15
15
  "type": "string",
16
- "const": "video-edit-smart"
16
+ "const": "video-edit-smart",
17
+ "description": "本次调用的模型机器标识;使用当前 model list/get 返回值。"
17
18
  },
18
19
  "video": {
19
20
  "type": "string",
@@ -29,12 +30,14 @@
29
30
  "resolution": {
30
31
  "type": "string",
31
32
  "minLength": 1,
32
- "pattern": ".*\\S.*"
33
+ "pattern": ".*\\S.*",
34
+ "description": "请求的输出分辨率档位字符串;使用当前模型 options[].value,不用展示 label。"
33
35
  },
34
36
  "audioEnabled": {
35
37
  "type": "string",
36
38
  "minLength": 1,
37
- "pattern": ".*\\S.*"
39
+ "pattern": ".*\\S.*",
40
+ "description": "是否生成音轨的模型选项字符串,按当前 options[].value 填写;不是 JSON 布尔值,也不保证保留原声内容。"
38
41
  },
39
42
  "referenceImages": {
40
43
  "type": "array",
@@ -44,7 +47,6 @@
44
47
  "description": "单个 HTTP(S) 或 CLI file:// 素材 URI。"
45
48
  },
46
49
  "minItems": 1,
47
- "uniqueItems": true,
48
50
  "maxItems": 10,
49
51
  "description": "额外参考图片,按顺序对应图1、图2等。"
50
52
  },
@@ -56,7 +58,6 @@
56
58
  "description": "单个 HTTP(S) 或 CLI file:// 素材 URI。"
57
59
  },
58
60
  "minItems": 1,
59
- "uniqueItems": true,
60
61
  "maxItems": 4,
61
62
  "description": "额外参考视频,按顺序对应视频2、视频3等;视频1固定为原片。原片与全部参考视频的合计时长不超过15秒。"
62
63
  },
@@ -68,7 +69,6 @@
68
69
  "description": "单个 HTTP(S) 或 CLI file:// 素材 URI。"
69
70
  },
70
71
  "minItems": 1,
71
- "uniqueItems": true,
72
72
  "maxItems": 5,
73
73
  "description": "额外参考音频,按顺序对应音频1、音频2等。"
74
74
  }
@@ -12,22 +12,25 @@
12
12
  "properties": {
13
13
  "model": {
14
14
  "type": "string",
15
- "const": "video-enhance-smart"
15
+ "const": "video-enhance-smart",
16
+ "description": "本次调用的模型机器标识;使用当前 model list/get 返回值。"
16
17
  },
17
18
  "video": {
18
19
  "type": "string",
19
20
  "format": "uri",
20
- "description": "单个 HTTP(S) 或 CLI file:// 素材 URI。"
21
+ "description": "本次要处理的原视频 URI;HTTP(S) URL 或标准 file URI。"
21
22
  },
22
23
  "prompt": {
23
24
  "type": "string",
24
25
  "minLength": 1,
25
- "pattern": ".*\\S.*"
26
+ "pattern": ".*\\S.*",
27
+ "description": "说明本次处理目标、需要的变化和需保留内容;按用户要求填写,媒体本身放在对应 URI 字段。"
26
28
  },
27
29
  "resolution": {
28
30
  "type": "string",
29
31
  "minLength": 1,
30
- "pattern": ".*\\S.*"
32
+ "pattern": ".*\\S.*",
33
+ "description": "请求的输出分辨率档位字符串;使用当前模型 options[].value,不用展示 label。"
31
34
  }
32
35
  }
33
36
  }
@@ -11,17 +11,19 @@
11
11
  "properties": {
12
12
  "model": {
13
13
  "type": "string",
14
- "const": "video-enhance-standard"
14
+ "const": "video-enhance-standard",
15
+ "description": "本次调用的模型机器标识;使用当前 model list/get 返回值。"
15
16
  },
16
17
  "video": {
17
18
  "type": "string",
18
19
  "format": "uri",
19
- "description": "单个 HTTP(S) 或 CLI file:// 素材 URI。"
20
+ "description": "本次要处理的原视频 URI;HTTP(S) URL 或标准 file URI。"
20
21
  },
21
22
  "resolution": {
22
23
  "type": "string",
23
24
  "minLength": 1,
24
- "pattern": ".*\\S.*"
25
+ "pattern": ".*\\S.*",
26
+ "description": "请求的输出分辨率档位字符串;使用当前模型 options[].value,不用展示 label。"
25
27
  }
26
28
  }
27
29
  }
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "title": "OcrPayload",
4
4
  "type": "object",
5
- "additionalProperties": false,
5
+ "additionalProperties": true,
6
6
  "required": [
7
7
  "image",
8
8
  "blocks"
@@ -10,7 +10,7 @@
10
10
  "properties": {
11
11
  "image": {
12
12
  "type": "object",
13
- "additionalProperties": false,
13
+ "additionalProperties": true,
14
14
  "required": [
15
15
  "uri",
16
16
  "width",
@@ -36,7 +36,7 @@
36
36
  "type": "array",
37
37
  "items": {
38
38
  "type": "object",
39
- "additionalProperties": false,
39
+ "additionalProperties": true,
40
40
  "required": [
41
41
  "bbox",
42
42
  "category"
@@ -47,8 +47,7 @@
47
47
  "minItems": 4,
48
48
  "maxItems": 4,
49
49
  "items": {
50
- "type": "number",
51
- "minimum": 0
50
+ "type": "number"
52
51
  }
53
52
  },
54
53
  "category": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "title": "ToolCallOutput",
4
- "description": "创作工具同步返回的最终内容与所选模型成本。",
4
+ "description": "创作工具返回的最终内容、所选模型及目录估价;不提供实际扣费金额。",
5
5
  "type": "object",
6
6
  "additionalProperties": false,
7
7
  "required": [
@@ -11,7 +11,7 @@
11
11
  "properties": {
12
12
  "content": {
13
13
  "type": "array",
14
- "description": "创作工具最终产出的文本或资源链接。",
14
+ "description": "服务按顺序返回的正文、资源链接和附件。按实际类型交付;只有封面时不能称已收到视频。保留所有完整链接,包括签名与查询参数。",
15
15
  "items": {
16
16
  "oneOf": [
17
17
  {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "usage": {
30
30
  "$ref": "#/$defs/ToolUsage",
31
- "description": "本次调用所选模型及 Model Catalog 声明的成本。"
31
+ "description": "所选模型与本次目录估价。缺少 cost 表示未取得估价,不表示免费。"
32
32
  }
33
33
  },
34
34
  "$defs": {
@@ -48,14 +48,15 @@
48
48
  "minimum": {
49
49
  "type": "number",
50
50
  "minimum": 0,
51
- "description": "当前可用配置中的最低稿豆消耗。"
51
+ "description": "目录预估价格区间的下限。"
52
52
  },
53
53
  "maximum": {
54
54
  "type": "number",
55
55
  "minimum": 0,
56
- "description": "当前可用配置中的最高稿豆消耗。"
56
+ "description": "目录预估价格区间的上限。"
57
57
  }
58
- }
58
+ },
59
+ "description": "Model Catalog 目录估价,不是实际扣费;minimum 与 maximum 相等也仍是估价。"
59
60
  },
60
61
  "ToolUsage": {
61
62
  "type": "object",
@@ -72,7 +73,7 @@
72
73
  },
73
74
  "cost": {
74
75
  "$ref": "#/$defs/CostRange",
75
- "description": "Model Catalog 声明的稿豆消耗区间。"
76
+ "description": "Model Catalog 目录估价,计量模型按实际输入估算;即使 minimum=maximum 也不表示实际扣费。实扣以可对应的账本记录为准。"
76
77
  }
77
78
  }
78
79
  },
@@ -112,7 +113,7 @@
112
113
  "uri": {
113
114
  "type": "string",
114
115
  "format": "uri",
115
- "description": "创作工具生成资源的 URI。"
116
+ "description": "创作工具生成资源的完整 URI。交付时原样保留查询参数,不截断、拼接或按诊断日志脱敏规则删除授权参数。"
116
117
  },
117
118
  "name": {
118
119
  "type": "string",
@@ -1,7 +1,8 @@
1
1
  import { reportProcessError } from "../src/telemetry/process-errors.js";
2
2
  import { cleanText } from "../src/telemetry/sanitize.js";
3
3
  import { fileURLToPath } from "node:url";
4
- import { dirname, resolve } from "node:path";
4
+ import { existsSync, realpathSync, statSync } from "node:fs";
5
+ import { dirname, join, resolve } from "node:path";
5
6
  import { loadBundledSkills } from "../src/features/skill/bundled-skills.js";
6
7
  import { syncBundledSkills } from "../src/features/skill/installer.js";
7
8
  import { markWorkBuddyInstallation, readInstallationOwner } from "../src/platform/installation-owner.js";
@@ -12,11 +13,26 @@ export function isSupportedGlobalLifecycle(env) {
12
13
  return /^(?:npm|pnpm)\//u.test(userAgent);
13
14
  }
14
15
  const initialDirectory = (env.INIT_CWD ?? "").replace(/\\/gu, "/");
15
- return userAgent.startsWith("pnpm/")
16
- && env.npm_command === "add"
17
- && env.npm_lifecycle_event === "postinstall"
18
- && (env.npm_package_name === "@gaoding/cli" || env.npm_package_name === "@insmind/cli")
19
- && /\/v\d+\/[0-9a-f]+-[0-9a-f]+-[0-9a-f]{16}$/u.test(initialDirectory);
16
+ const name = env.npm_package_name;
17
+ if (!userAgent.startsWith("pnpm/") || env.npm_command !== "add" || env.npm_lifecycle_event !== "postinstall"
18
+ || (name !== "@gaoding/cli" && name !== "@insmind/cli"))
19
+ return false;
20
+ if (/\/v\d+\/[0-9a-f]+-[0-9a-f]+-[0-9a-f]{16}$/u.test(initialDirectory))
21
+ return true;
22
+ // pnpm 12 runs postinstall before publishing its global launcher. Its staging
23
+ // directory has no consumer manifest and links directly to the package being built.
24
+ if (!/\/v\d+\/[0-9a-f]+-[0-9a-f]{16}-\d+$/u.test(initialDirectory)
25
+ || !env.npm_package_json || !env.PNPM_SCRIPT_SRC_DIR)
26
+ return false;
27
+ try {
28
+ return !existsSync(join(initialDirectory, "package.json"))
29
+ && statSync(join(dirname(initialDirectory), "pnpm-workspace.yaml")).isFile()
30
+ && realpathSync(join(initialDirectory, "node_modules", name, "package.json")) === realpathSync(env.npm_package_json)
31
+ && realpathSync(join(env.PNPM_SCRIPT_SRC_DIR, "package.json")) === realpathSync(env.npm_package_json);
32
+ }
33
+ catch {
34
+ return false;
35
+ }
20
36
  }
21
37
  export async function runPostinstall(options = {}) {
22
38
  const startedAt = Date.now();
@@ -28,7 +28,7 @@ else {
28
28
  for (const key of Object.keys(endpoints))
29
29
  endpoints[key] = new URL(job.endpoints[key]);
30
30
  const runtime = createProductionRuntime({
31
- processRole: job.operation === "tool.call" ? "tool_worker" : "agent_worker",
31
+ processRole: job.operation === "agent.send" ? "agent_worker" : "tool_worker",
32
32
  ...(job.telemetryVersion ? { telemetryVersion: job.telemetryVersion } : {}),
33
33
  ...(job.telemetryTrackingUrl ? { telemetryTrackingUrl: new URL(job.telemetryTrackingUrl) } : {}),
34
34
  ...(job.telemetryEnvironment ? { telemetryEnvironment: job.telemetryEnvironment } : {}),
@@ -38,7 +38,7 @@ else {
38
38
  await runTaskWorker({ runtime, job, signal: controller.signal, send });
39
39
  }
40
40
  catch (error) {
41
- await reportProcessError(error, { operation: "bootstrap", processRole: currentJob?.operation === "tool.call" ? "tool_worker" : "agent_worker", startedAt, signal: controller.signal,
41
+ await reportProcessError(error, { operation: "bootstrap", processRole: currentJob?.operation === "agent.send" ? "agent_worker" : "tool_worker", startedAt, signal: controller.signal,
42
42
  stateDirectory: currentJob?.product === "insmind" ? ".insmind" : ".gd",
43
43
  ...(currentJob?.telemetryTrackingUrl ? { trackingUrl: new URL(currentJob.telemetryTrackingUrl) } : {}),
44
44
  ...(currentJob?.telemetryEnvironment ? { environment: currentJob.telemetryEnvironment } : {}),
@@ -35,22 +35,19 @@ export function createCli(runtime, options) {
35
35
  writeErr: () => undefined
36
36
  });
37
37
  program.addHelpText("after", runtime.product.id === "insmind"
38
- ? "\nstdout contains command results; stderr contains progress, warnings and errors. Fixed JSON commands, --json and --json-errors use {error:{code,message,details?,trace_id?}} for final errors. stderr may contain multiple messages.\nExit codes: 0 success, 1 execution failure, 2 invalid input, 130 local interruption; dispatched work may still be active.\n"
39
- : "\nstdout 输出命令结果;stderr 输出进度、警告和错误。固定 JSON 命令、--json 和 --json-errors 的最终错误使用 {error:{code,message,details?,trace_id?}},stderr 可能包含多条信息。\n退出码:0 成功,1 执行失败,2 输入无效,130 本地中断;已派发的工作可能仍在继续。\n");
38
+ ? "\nChoose by the object and goal: tool list discovers generation and processing of attached images/videos (including text replacement, layers and vectors); editor operates elements in a connected work; agent send handles planning and multi-turn creation. A capability absent from Editor may be available as a Tool.\nRead the selected command's --help. Use its advertised --schema for JSON structure and model get for live model inputs. --input takes a JSON file path or - with complete JSON on stdin; media URI fields inside JSON take URLs.\nstdout contains command results; human-readable views can include an update notice. stderr contains progress, warnings and errors. Fixed JSON commands, --json and --json-errors use {error:{code,message,details?,trace_id?}} for final errors. stderr may contain multiple messages.\nExit codes: 0 command success (async acceptance and successful queries still require checking task state), 1 execution failure, 2 invalid input, 130 local interruption; dispatched work may still be active.\n"
39
+ : "\n按对象和目标选入口:tool list 发现生成及附件图片/视频处理能力(含改字、分层、矢量化);editor 操作已连接作品的元素;agent send 负责策划和持续多轮创作。Editor 未提供的操作仍可能由 Tool 提供。\n先读所选命令 --help;结构化输入从其公开的 --schema 发现,模型参数从 model get 查询。--input 接收 JSON 文件路径,或用 - 从 stdin 传完整 JSON;JSON 内的媒体 URI 字段接收 URL。\nstdout 输出命令结果,人类可读视图可以附带升级提醒;stderr 输出进度、警告和错误。固定 JSON 命令、--json 和 --json-errors 的最终错误使用 {error:{code,message,details?,trace_id?}},stderr 可能包含多条信息。\n退出码:0 命令成功(异步受理、查询成功仍须查看任务状态),1 执行失败,2 输入无效,130 本地中断;已派发的工作可能仍在继续。\n");
40
40
  if (runtime.product.id === "insmind") {
41
41
  program.option("--locale <locale>", "locale for service-owned business descriptions");
42
42
  }
43
43
  configureActionEnvironment(program, {
44
44
  policies: runtime.accessPolicies,
45
45
  signal: options.signal,
46
- telemetry: runtime.telemetry,
47
- updateNotification: runtime.updateNotification
46
+ telemetry: runtime.telemetry
48
47
  });
49
48
  registerAuthCommands(program, runtime);
50
49
  if (runtime.product.exposesOrganizations)
51
50
  registerOrgCommands(program, runtime);
52
- else
53
- registerCreditsCommand(program, runtime);
54
51
  registerAgentCommands(program, runtime);
55
52
  registerToolCommands(program, runtime);
56
53
  registerModelCommands(program, runtime);
@@ -58,6 +55,7 @@ export function createCli(runtime, options) {
58
55
  registerDamCommands(program, runtime);
59
56
  registerUpdateCommand(program, runtime);
60
57
  registerTaskCommands(program, runtime);
58
+ registerCreditsCommand(program, runtime);
61
59
  assertAllLeafCommandsBound(program);
62
60
  outputs.set(program, runtime);
63
61
  if (runtime.analytics)
@@ -65,7 +63,11 @@ export function createCli(runtime, options) {
65
63
  return program;
66
64
  }
67
65
  export async function executeCli(options) {
68
- await options.telemetry.issue(invocationDefinition(options.program, options.argv));
66
+ const definition = invocationDefinition(options.program, options.argv);
67
+ await options.telemetry.issue(definition);
68
+ const automaticNotice = definition.operation !== "update" && !definition.operation.startsWith("update.");
69
+ let informational = false;
70
+ let help = false;
69
71
  try {
70
72
  try {
71
73
  await options.program.parseAsync(options.argv, { from: "user" });
@@ -73,12 +75,16 @@ export async function executeCli(options) {
73
75
  catch (error) {
74
76
  if (!isHelpOutcome(error))
75
77
  throw error;
76
- if (options.argv[0] !== "update")
77
- await checkUpdateNotification(options.updateNotification, options.signal);
78
+ informational = true;
79
+ help = error instanceof CommanderError && error.code === "commander.helpDisplayed";
78
80
  options.signal.throwIfAborted();
79
81
  }
80
82
  await options.telemetry.stage("output", async () => { await outputs.get(options.program)?.io.flush?.(); });
81
83
  await outputs.get(options.program)?.tasks.outputCompleted();
84
+ if (automaticNotice)
85
+ await checkUpdateNotification(options.updateNotification, options.signal, help || options.presenter.humanResult ? "text" : "machine");
86
+ if (informational)
87
+ options.signal.throwIfAborted();
82
88
  await sendFinished(options, { outcome: "success" });
83
89
  return 0;
84
90
  }
@@ -103,12 +109,19 @@ export async function executeCli(options) {
103
109
  const { cli_task_id: taskId, operation } = options.telemetry.creationContext();
104
110
  if (taskId && outcome.failure && ["agent.send", "tool.call"].includes(operation)) {
105
111
  const details = outcome.failure.details;
106
- outcome.failure.details = { ...details, cli_task_id: taskId, next_steps: [
112
+ const refused = ["TOOL_TASK_FAILED", "INSUFFICIENT_CREDITS"].includes(outcome.failure.code)
113
+ || ["audit_rejected", "input_audit_rejected", "output_audit_rejected"].includes(details?.reason ?? "");
114
+ const recovery = { ...details, cli_task_id: taskId };
115
+ if (outcome.exitCode !== 2 && !refused && details?.phase !== "input_upload_before_dispatch") {
116
+ recovery.next_steps = [
107
117
  ...(details?.next_steps ?? []),
108
118
  `${options.product?.commandName ?? "gd-cli"} task get ${taskId}`,
109
- options.product?.id === "insmind" ? "Keep this task ID; do not automatically resubmit creation."
110
- : "保留此任务 ID,不要自动重新提交创作。"
111
- ] };
119
+ options.product?.id === "insmind"
120
+ ? "If the outcome is still unknown, tell the user and keep this ID for recovery. Do not start another creation."
121
+ : "原任务结果仍未知时,向用户说明并保留此 ID 供取回。不要另发创作。"
122
+ ];
123
+ }
124
+ outcome.failure.details = recovery;
112
125
  }
113
126
  const telemetryError = classifyTelemetryError(error, { aborted: isInterruption(error, options.signal),
114
127
  operation: options.telemetry.creationContext().operation, failureStage: options.telemetry.failureStage(error), ...(options.product ? { product: options.product } : {}) });
@@ -129,6 +142,9 @@ export async function executeCli(options) {
129
142
  }
130
143
  if (errorDelivered)
131
144
  await outputs.get(options.program)?.tasks.outputCompleted(error);
145
+ if (errorDelivered && automaticNotice && outcome.exitCode === 1 && definition.operation !== "unknown") {
146
+ await checkUpdateNotification(options.updateNotification, options.signal, "machine");
147
+ }
132
148
  await sendFinished(options, outcome.kind === "interrupted"
133
149
  ? { outcome: "interrupted", error }
134
150
  : {
@@ -149,9 +165,9 @@ export async function executeCli(options) {
149
165
  return outcome.exitCode;
150
166
  }
151
167
  }
152
- async function checkUpdateNotification(updateNotification, signal) {
168
+ async function checkUpdateNotification(updateNotification, signal, output) {
153
169
  try {
154
- await updateNotification.check(signal);
170
+ await updateNotification.check(signal, output);
155
171
  }
156
172
  catch {
157
173
  // Version availability must never change the requested command outcome.