@gaoding/cli 1.9.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/contracts/operations/agent.send/output.schema.json +1 -1
  2. package/dist/bin/gd-cli.js +32 -25
  3. package/dist/bin/insmind-cli.js +32 -25
  4. package/dist/bin/task-worker.js +4 -1
  5. package/dist/src/analytics/device.js +2 -2
  6. package/dist/src/bootstrap/create-cli.js +10 -8
  7. package/dist/src/bootstrap/create-runtime.js +29 -23
  8. package/dist/src/bootstrap/run-task-worker.js +7 -2
  9. package/dist/src/bootstrap/validators.js +15 -6
  10. package/dist/src/cli/action-binding.js +39 -0
  11. package/dist/src/cli/agent-commands.js +8 -12
  12. package/dist/src/cli/dam-commands.js +6 -5
  13. package/dist/src/cli/editor-commands.js +10 -5
  14. package/dist/src/cli/errors.js +60 -12
  15. package/dist/src/cli/host-input.js +34 -0
  16. package/dist/src/cli/model-commands.js +4 -3
  17. package/dist/src/cli/observed-errors.js +3 -1
  18. package/dist/src/cli/tool-commands.js +7 -9
  19. package/dist/src/contracts/creation-input.js +20 -0
  20. package/dist/src/features/agent/creative-agent-adapter.js +37 -11
  21. package/dist/src/features/agent/creative-protocol.js +21 -19
  22. package/dist/src/features/agent/creative-stream.js +54 -6
  23. package/dist/src/features/agent/result-reader.js +3 -1
  24. package/dist/src/features/agent/use-cases.js +6 -31
  25. package/dist/src/features/auth/access-policy.js +1 -3
  26. package/dist/src/features/auth/credential-store.js +6 -10
  27. package/dist/src/features/auth/sso-service.js +28 -10
  28. package/dist/src/features/auth/state.js +6 -0
  29. package/dist/src/features/auth/use-cases.js +91 -32
  30. package/dist/src/features/credits/use-cases.js +1 -1
  31. package/dist/src/features/dam/asset-projection.js +10 -1
  32. package/dist/src/features/dam/dam-api-adapter.js +30 -15
  33. package/dist/src/features/dam/file-downloader.js +2 -1
  34. package/dist/src/features/dam/input.js +23 -0
  35. package/dist/src/features/dam/use-cases.js +39 -29
  36. package/dist/src/features/editor/bridge-client.js +1 -1
  37. package/dist/src/features/editor/use-cases.js +6 -8
  38. package/dist/src/features/org/use-cases.js +3 -3
  39. package/dist/src/features/skill/installer.js +24 -22
  40. package/dist/src/features/task/store.js +31 -17
  41. package/dist/src/features/task/task-background.js +67 -19
  42. package/dist/src/features/task/use-cases.js +131 -88
  43. package/dist/src/features/tool/canvas-media.js +82 -27
  44. package/dist/src/features/tool/canvas-models.js +21 -4
  45. package/dist/src/features/tool/canvas-tool-adapter.js +29 -20
  46. package/dist/src/features/tool/canvas-video.js +2 -4
  47. package/dist/src/features/tool/dynamic-schema.js +32 -63
  48. package/dist/src/features/tool/matting-billing.js +38 -26
  49. package/dist/src/features/tool/mns-catalog-adapter.js +9 -2
  50. package/dist/src/features/tool/scene-catalog-adapter.js +0 -1
  51. package/dist/src/features/tool/tool-api-adapter.js +19 -16
  52. package/dist/src/features/tool/use-cases.js +24 -35
  53. package/dist/src/platform/file-lock.js +58 -15
  54. package/dist/src/platform/input-uri.js +105 -0
  55. package/dist/src/platform/json-input.js +1 -1
  56. package/dist/src/platform/local-json-file.js +7 -4
  57. package/dist/src/platform/remote-error-evidence.js +23 -1
  58. package/dist/src/platform/safe-upload-file.js +24 -4
  59. package/dist/src/platform/schema-issues.js +18 -0
  60. package/dist/src/platform/signed-http-transport.js +95 -37
  61. package/dist/src/platform/text-output.js +55 -13
  62. package/dist/src/telemetry/failure-summary.js +53 -2
  63. package/dist/src/telemetry/host-diagnostics.js +95 -0
  64. package/dist/src/telemetry/invocation.js +107 -23
  65. package/dist/src/telemetry/process-errors.js +38 -4
  66. package/dist/src/telemetry/sls-sink.js +71 -26
  67. package/package.json +4 -4
  68. package/skills/gd-cli/SKILL.md +1 -0
  69. package/skills/gd-cli/references/editor.md +1 -1
  70. package/skills/gd-cli/references/generation-constraints.md +3 -1
  71. package/skills/gd-cli/references/tool.md +2 -3
@@ -2,22 +2,28 @@ import { createHash } from "node:crypto";
2
2
  import { readdir, readFile, unlink, mkdir, chmod } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { cleanDiagnostic } from "./sanitize.js";
5
+ import { safeFailureSummary } from "./failure-summary.js";
5
6
  import { createLocalJsonFile } from "../platform/local-json-file.js";
6
7
  import { withFileLock } from "../platform/file-lock.js";
7
8
  const TTL = 7 * 86_400_000;
8
9
  const CAPACITY = 10 * 1024 * 1024;
9
10
  const BUDGET = 2_000;
10
11
  export function eventKey(event) {
11
- const key = event.event_name === "task_state"
12
- ? [event.cli_name, event.env, event.cli_task_id, "task_state", Number(event.task_revision)]
13
- : event.event_name === "request_sent" || event.event_name === "result_ready"
14
- ? [event.cli_name, event.env, event.cli_task_id, event.event_name]
15
- : [event.cli_name, event.env, event.trace_id, event.process_role, Number(event.record_seq)];
12
+ const key = event.event_name === "command_step"
13
+ ? [event.cli_name, event.env, event.trace_id, event.step]
14
+ : [event.cli_name, event.env, event.trace_id, event.process_role, Number(event.record_seq)];
16
15
  return createHash("sha256").update(JSON.stringify(key)).digest("hex");
17
16
  }
18
17
  export function wireEvent(event) {
19
18
  const safe = cleanDiagnostic(event);
20
- const wire = {};
19
+ if ("diagnostic_summary" in safe) {
20
+ const summary = safeFailureSummary(safe.diagnostic_summary);
21
+ if (summary)
22
+ safe.diagnostic_summary = summary;
23
+ else
24
+ delete safe.diagnostic_summary;
25
+ }
26
+ const wire = { event_id: eventKey(safe) };
21
27
  for (const [key, value] of Object.entries(safe)) {
22
28
  if (value !== undefined)
23
29
  wire[key] = typeof value === "object" ? JSON.stringify(value) : String(value);
@@ -40,8 +46,12 @@ export function wireEvent(event) {
40
46
  break;
41
47
  }
42
48
  // Keep the envelope valid even for unexpectedly large identity or adapter fields.
43
- for (const [key, value] of Object.entries(wire))
44
- wire[key] = utf8Prefix(value, 1024);
49
+ for (const [key, value] of Object.entries(wire)) {
50
+ // The bounded summary is structured JSON and contains the primary
51
+ // correlation evidence. Slicing it would make every field unreadable.
52
+ if (key !== "diagnostic_summary")
53
+ wire[key] = utf8Prefix(value, 1024);
54
+ }
45
55
  }
46
56
  return wire;
47
57
  }
@@ -62,10 +72,13 @@ export function createSlsTelemetrySink(options) {
62
72
  let writes = Promise.resolve();
63
73
  let enqueueFailures = 0;
64
74
  let lastEnqueueError;
65
- const file = (id) => createLocalJsonFile({ directory: options.directory, filename: `${id}.json` });
75
+ let status = { count: 0, delivery_failures: 0 };
76
+ let healthReady = false;
77
+ const statusFile = () => createLocalJsonFile({ directory: options.directory, filename: "delivery-status.json", role: "sls_queue" });
78
+ const file = (id) => createLocalJsonFile({ directory: options.directory, filename: `${id}.json`, role: "sls_queue" });
66
79
  let exitDeadline = Infinity;
67
80
  const locked = (run, deadline) => options.directory
68
- ? withFileLock(join(options.directory, ".lock"), run, { deadline: Math.min(deadline ?? Infinity, exitDeadline) }) : run();
81
+ ? withFileLock(join(options.directory, ".lock"), run, { deadline: Math.min(deadline ?? Infinity, exitDeadline), action: "sls_queue" }) : run();
69
82
  function checkBudget(deadline) {
70
83
  if (Date.now() >= deadline)
71
84
  throw new Error("Telemetry delivery budget exhausted.");
@@ -76,6 +89,21 @@ export function createSlsTelemetrySink(options) {
76
89
  entries.clear();
77
90
  await mkdir(options.directory, { recursive: true, mode: 0o700 });
78
91
  await chmod(options.directory, 0o700);
92
+ let rawStatus;
93
+ try {
94
+ rawStatus = JSON.parse(await statusFile().readText() ?? "{}");
95
+ }
96
+ catch { /* A malformed health file must not prevent replaying intact events. */ }
97
+ if (rawStatus && typeof rawStatus === "object" && !Array.isArray(rawStatus)) {
98
+ const value = rawStatus;
99
+ const count = (key) => typeof value[key] === "number" && Number.isSafeInteger(value[key]) && value[key] >= 0 ? value[key] : 0;
100
+ status = { count: count("count"), delivery_failures: count("delivery_failures"),
101
+ ...(["interrupted_write", "corrupt", "expired", "capacity", "http_rejected"].includes(String(value.reason)) ? { reason: value.reason } : {}),
102
+ ...(["accepted", "http_rejected", "http_retryable", "network_error"].includes(String(value.result)) ? { result: value.result } : {}),
103
+ ...(typeof value.http_status === "number" && value.http_status >= 100 && value.http_status <= 599 ? { http_status: value.http_status } : {}),
104
+ ...(count("first_at_ms") ? { first_at_ms: count("first_at_ms") } : {}),
105
+ ...(count("last_at_ms") ? { last_at_ms: count("last_at_ms") } : {}) };
106
+ }
79
107
  for (const name of await readdir(options.directory)) {
80
108
  checkBudget(deadline);
81
109
  // All writers hold the same lock, so remaining atomic-write temporaries are orphaned.
@@ -90,7 +118,7 @@ export function createSlsTelemetrySink(options) {
90
118
  const raw = await readFile(join(options.directory, name), "utf8");
91
119
  try {
92
120
  const entry = JSON.parse(raw);
93
- if (!Number.isFinite(entry.queuedAt) || !entry.event || eventKey(entry.event) !== name.slice(0, -5))
121
+ if (entry.event?.schema_version !== "6" || !Number.isFinite(entry.queuedAt) || !entry.event || eventKey(entry.event) !== name.slice(0, -5))
94
122
  throw new Error();
95
123
  entries.set(name.slice(0, -5), entry);
96
124
  }
@@ -99,18 +127,16 @@ export function createSlsTelemetrySink(options) {
99
127
  await dropped("corrupt", 1);
100
128
  }
101
129
  }
130
+ healthReady = true;
131
+ }
132
+ async function saveStatus() {
133
+ // Health recording must never stop the original event acknowledgement/backoff path.
134
+ if (options.directory)
135
+ await statusFile().writeTextAtomically(JSON.stringify(status)).catch(() => undefined);
102
136
  }
103
137
  async function dropped(reason, count) {
104
- if (!options.directory)
105
- return;
106
- const status = createLocalJsonFile({ directory: options.directory, filename: "delivery-status.json" });
107
- let prior = {};
108
- try {
109
- prior = JSON.parse(await status.readText() ?? "{}");
110
- }
111
- catch { /* Replace corrupt diagnostic status. */ }
112
- await status.writeTextAtomically(JSON.stringify({ count: (prior.count ?? 0) + count,
113
- first_at_ms: prior.first_at_ms ?? now(), last_at_ms: now(), reason }));
138
+ status = { ...status, count: status.count + count, first_at_ms: status.first_at_ms ?? now(), last_at_ms: now(), reason };
139
+ await saveStatus();
114
140
  }
115
141
  async function remove(id) {
116
142
  entries.delete(id);
@@ -131,8 +157,8 @@ export function createSlsTelemetrySink(options) {
131
157
  }
132
158
  }
133
159
  let size = [...entries.values()].reduce((sum, e) => sum + Buffer.byteLength(JSON.stringify(e)), 0);
134
- const priority = (e) => e.event.event_name === "task_state" || e.event.event_name === "request_sent" || e.event.event_name === "result_ready" ? 2
135
- : "outcome" in e.event && e.event.outcome !== "success" ? 1 : 0;
160
+ const priority = (e) => e.event.event_name === "command_step" ? 2
161
+ : e.event.event_name === "host_diagnostic" || "outcome" in e.event && e.event.outcome !== "success" ? 1 : 0;
136
162
  for (const [id, entry] of [...entries].sort((a, b) => priority(a[1]) - priority(b[1]) || a[1].queuedAt - b[1].queuedAt)) {
137
163
  checkBudget(deadline);
138
164
  if (size <= (options.maxBytes ?? CAPACITY))
@@ -208,6 +234,11 @@ export function createSlsTelemetrySink(options) {
208
234
  return; // Original records remain safe for at-least-once replay.
209
235
  await locked(async () => {
210
236
  await load(deadline);
237
+ status = { ...status, delivery_failures: status.delivery_failures + (accepted ? 0 : 1),
238
+ result: accepted ? "accepted" : rejected ? "http_rejected" : response ? "http_retryable" : "network_error",
239
+ ...(response ? { http_status: response.status } : {}) };
240
+ if (!response)
241
+ delete status.http_status;
211
242
  for (const [id, original] of batch) {
212
243
  checkBudget(deadline);
213
244
  const entry = entries.get(id);
@@ -220,7 +251,9 @@ export function createSlsTelemetrySink(options) {
220
251
  nextAttempt: now() + Math.max(retryAfter, attempt === 0 ? 0 : Math.min(60_000, 1000 * 2 ** Math.min(6, original.attempts))) });
221
252
  }
222
253
  if (rejected)
223
- await dropped(`http_${response.status}`, batch.length);
254
+ await dropped("http_rejected", batch.length);
255
+ else
256
+ await saveStatus();
224
257
  }, deadline);
225
258
  if (!accepted && (retryAfter > 0 || rejected))
226
259
  return;
@@ -231,9 +264,21 @@ export function createSlsTelemetrySink(options) {
231
264
  return sending;
232
265
  }
233
266
  return { enqueue,
234
- // This snapshot describes enqueue attempts before final flush, not SLS acceptance.
267
+ async refreshDiagnostics() {
268
+ // Read persisted facts without triggering an extra send or adding business events.
269
+ const deadline = Date.now() + 100;
270
+ await writes;
271
+ await locked(() => load(deadline), deadline).catch(() => undefined);
272
+ },
273
+ // The final flush is observable by a later invocation, never retroactively on this event.
235
274
  diagnostics: () => ({ sls_enqueue_failures: enqueueFailures,
236
- ...(lastEnqueueError ? { sls_last_enqueue_error: lastEnqueueError } : {}) }),
275
+ ...(lastEnqueueError ? { sls_last_enqueue_error: lastEnqueueError } : {}),
276
+ ...(healthReady ? { sls_queue_size: entries.size,
277
+ ...(entries.size ? { sls_queue_oldest_age_ms: Math.max(0, now() - Math.min(...[...entries.values()].map(entry => entry.queuedAt))) } : {}),
278
+ sls_delivery_failures: status.delivery_failures, sls_dropped_events: status.count,
279
+ ...(status.result ? { sls_last_delivery_result: status.result } : {}),
280
+ ...(status.http_status ? { sls_last_delivery_http_status: status.http_status } : {}),
281
+ ...(status.reason ? { sls_last_drop_reason: status.reason } : {}) } : {}) }),
237
282
  async send(events) {
238
283
  const deadline = exitDeadline = Date.now() + BUDGET;
239
284
  await enqueue(events, deadline);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaoding/cli",
3
- "version": "1.9.0",
3
+ "version": "2.0.0",
4
4
  "description": "Gaoding command-line interface for agents and people.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -57,8 +57,8 @@
57
57
  "vitest": "4.1.10"
58
58
  },
59
59
  "gaodingRelease": {
60
- "sourceCommit": "2836058427780a95d4b9ed152f122b81997df34e",
61
- "pipelineId": "231960",
62
- "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/231960"
60
+ "sourceCommit": "216c910373e0a89ff902e655f3cda89cae32887b",
61
+ "pipelineId": "241612",
62
+ "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/241612"
63
63
  }
64
64
  }
@@ -7,6 +7,7 @@ description: Use when creating images, videos or text with GD CLI, operating the
7
7
 
8
8
  ## 按需发现当前能力
9
9
 
10
+ - 调用 `agent send`、`tool call`、`editor apply` 时,在输入 JSON 顶层填写 `host_application`。值为发起命令的实际应用名,例如 `workbuddy`、`qwenwork`、`trae`;用户直接在终端运行时填 `terminal`。
10
11
  - 首次使用时确认 `gd-cli --version`;不确定入口时读 `gd-cli --help`,沿相关命令组选择命令,执行前读其 `--help`。本 Skill 的示例不代表完整能力清单。
11
12
  - 结构化输入先读取命令公开支持的 `--schema`;模型、参数选项、价格与资源 ID 由对应目录或详情查询取得,不从旧示例猜值。发现不支持或查询失败时说明缺口,不静默替换用户明确约束。
12
13
  - 同一会话可复用同一路径/版本的 help 和静态 Schema;CLI 变化后重查。动态信息在本次任务选能力或报价时查询,身份/组织变化或明确不匹配时刷新相关结果,不全量扫描无关目录。
@@ -20,7 +20,7 @@ gd-cli editor apply --schema
20
20
 
21
21
  1. 查询 `gd-cli editor connect --help`,按用户目标选择 `gd-cli editor connect [target]`。不为恢复已有作品而省略目标新建 Board。只有浏览器登录、加载、编辑/保存权限和内容检查通过后才成功;连接失败时停止作图。
22
22
  2. 读取 `gd-cli editor snapshot`。以最新 Snapshot 中的完整元素为基础,只改变目标字段;Update 提交完整元素,不能提交 patch。
23
- 3. 根据 Schema 和 Snapshot 构造完整、有序的 Action JSON 数组,执行 `gd-cli editor apply --input actions.json`,或用 `--input -` 从 stdin 读取。使用简短语义 ID;Connector 的方向和目标必须符合业务关系。
23
+ 3. 根据 Schema 和 Snapshot 构造包含 `host_application` 和有序 `actions` 数组的对象,执行 `gd-cli editor apply --input actions.json`,或用 `--input -` 从 stdin 读取。使用简短语义 ID;Connector 的方向和目标必须符合业务关系。
24
24
  4. 每次 Apply 后重新读取 Snapshot。涉及布局、文字或 Connector 时,执行 `gd-cli editor screenshot --json` 并打开返回的绝对 `path` 对应的实际 PNG。文件存在或 Action 已提交都不代表渲染正确。
25
25
  5. 结构和视觉复查均通过后,执行 `gd-cli editor save --json`,继续等待原命令完成,不因短暂无输出而中断或并发操作。只有保存成功才可声明作品已保存;把返回的 `workId` 和公开 `url` 交给用户,并保留 URL 中的环境参数。等待时限查 `editor save --help`。
26
26
  6. 保存成功后执行 `gd-cli editor disconnect`;断开连接不代替保存。
@@ -6,6 +6,7 @@
6
6
 
7
7
  ```json
8
8
  {
9
+ "host_application": "<invoking application>",
9
10
  "message": {
10
11
  "parts": [
11
12
  { "text": "<用户要求>" },
@@ -22,10 +23,11 @@
22
23
  }
23
24
  ```
24
25
 
25
- `arguments` 可以在不指定 `model` 时单独提交,由服务端 Agent 选择 Model。指定 `model` 时,CLI 会按实时 Model detail 校验已提供参数;不要为了 Agent 调用补齐 Tool 的全部 required 字段。Prompt 使用 Text Part,素材使用独立 URL Part,不放入 `arguments`。素材保持消息 Part 的输入顺序;`metadata.role` 可标记 `reference`、`first_frame` 或 `last_frame`,不注入“首帧”或“尾帧”文本。例如:
26
+ `arguments` 可以在不指定 `model` 时单独提交,由服务端 Agent 选择 Model。指定 `model` 时,CLI 转发显式控制参数,将已知编辑模型别名映射成服务字段。Prompt 使用 Text Part,素材使用独立 URL Part,不放入 `arguments`。素材保持消息 Part 的输入顺序;`metadata.role` 可标记 `reference`、`first_frame` 或 `last_frame`,不注入“首帧”或“尾帧”文本。例如:
26
27
 
27
28
  ```json
28
29
  {
30
+ "host_application": "<invoking application>",
29
31
  "message": {
30
32
  "parts": [
31
33
  { "text": "生成一段转场视频" },
@@ -12,14 +12,13 @@ gd-cli tool call <tool> --input request.json --async
12
12
  gd-cli task get <taskId>
13
13
  ```
14
14
 
15
- `tool list` 给出可用 Tool;`model list` 和 `model get` 给出当前可用 Model、说明、费用、预估耗时和结构化参数。`model get` 的 `inputSchema` 是完整模型输入契约,包含嵌套对象、数组和条件;`parameters` 是摘要元数据:遵循 `required`、`type`、`description`,SELECT 参数使用 `options[].value`,required 参数带 `default` 时在用户未指定时显式传入默认值。`usageDescription` 描述跨字段规则,例如视频 mode 对首尾帧或素材字段的要求;这类组合不能只从单个字段推断。不要把列表值固化在提示或脚本中。
16
-
17
- 按所选 Model detail 构造 JSON:提供全部 required 字段;SELECT 参数使用 `options[].value`;required 字段带 default 且用户未指定时,在输入中显式使用该 default。存在 width、height、resolution 等专用字段时,将用户要求写入对应结构化参数,不要只写在 prompt 中。`tool call <tool> --schema` 按 model 选择对应的必填字段、参数和范围;`model get` 补充 step、参数默认值及 `usageDescription` 中的组合要求。固定 JSON 命令可显式添加 `--json`。
15
+ 用 `gd-cli tool call <tool> --schema` 查工具输入,用 `model get` 看选定模型的价格和预计耗时。`required` 标出模型所需输入,`default` 标出服务默认值;用户未指定有默认值的字段时可以省略。选择目录列出的选项时用 `options[].value`。尺寸和分辨率写进 `width`、`height`、`resolution` 等字段,用户显式指定的值原样发送。`usageDescription` 描述跨字段规则,例如视频 mode 对首尾帧或素材字段的要求。
18
16
 
19
17
  务必将 `model get <model> --tool <tool>` 返回的 `model` 原样放在请求 JSON 的顶层 `model` 字段(即运行时的 `arguments.model`),与所选 Model 的参数字段并列;不要只复制 `parameters`。例如:
20
18
 
21
19
  ```json
22
20
  {
21
+ "host_application": "<invoking application>",
23
22
  "model": "<model>",
24
23
  "prompt": "<required prompt>",
25
24
  "<parameter>": "<value>"