@gaoding/cli 2.1.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 (114) hide show
  1. package/contracts/operations/agent.send/input.schema.json +8 -84
  2. package/contracts/operations/agent.send/output.schema.json +6 -6
  3. package/contracts/operations/dam.folder.list/input.schema.json +1 -1
  4. package/contracts/operations/dam.folder.list/output.schema.json +1 -1
  5. package/contracts/operations/dam.list/input.schema.json +2 -5
  6. package/contracts/operations/dam.list/output.schema.json +1 -1
  7. package/contracts/operations/dam.search/input.schema.json +2 -5
  8. package/contracts/operations/dam.search/output.schema.json +1 -1
  9. package/contracts/operations/model.get/output.schema.json +6 -5
  10. package/contracts/operations/model.list/output.schema.json +5 -4
  11. package/contracts/operations/task.get/output.schema.json +22 -11
  12. package/contracts/operations/tool.call/models/image-edit-smart.schema.json +7 -5
  13. package/contracts/operations/tool.call/models/image-edit-standard.schema.json +6 -4
  14. package/contracts/operations/tool.call/models/image-enhance-smart.schema.json +5 -3
  15. package/contracts/operations/tool.call/models/image-enhance-standard.schema.json +3 -2
  16. package/contracts/operations/tool.call/models/image-expand-smart.schema.json +16 -10
  17. package/contracts/operations/tool.call/models/image-expand-standard.schema.json +13 -8
  18. package/contracts/operations/tool.call/models/image-layers-layout.schema.json +3 -2
  19. package/contracts/operations/tool.call/models/image-layers-smart.schema.json +3 -4
  20. package/contracts/operations/tool.call/models/image-matting-smart.schema.json +6 -4
  21. package/contracts/operations/tool.call/models/image-matting-standard.schema.json +3 -2
  22. package/contracts/operations/tool.call/models/image-ocr.schema.json +3 -2
  23. package/contracts/operations/tool.call/models/image-remove-smart.schema.json +6 -4
  24. package/contracts/operations/tool.call/models/image-remove-standard.schema.json +4 -3
  25. package/contracts/operations/tool.call/models/image-text-edit.schema.json +5 -3
  26. package/contracts/operations/tool.call/models/image-vectorize.schema.json +3 -2
  27. package/contracts/operations/tool.call/models/video-edit-smart.schema.json +6 -6
  28. package/contracts/operations/tool.call/models/video-enhance-smart.schema.json +7 -4
  29. package/contracts/operations/tool.call/models/video-enhance-standard.schema.json +5 -3
  30. package/contracts/operations/tool.call/ocr-payload.schema.json +4 -5
  31. package/contracts/operations/tool.call/output.schema.json +9 -8
  32. package/dist/bin/postinstall.js +22 -6
  33. package/dist/bin/task-worker.js +2 -2
  34. package/dist/src/bootstrap/create-cli.js +13 -6
  35. package/dist/src/bootstrap/create-runtime.js +98 -28
  36. package/dist/src/bootstrap/run-task-worker.js +6 -2
  37. package/dist/src/bootstrap/validators.js +1 -1
  38. package/dist/src/cli/action-binding.js +14 -37
  39. package/dist/src/cli/agent-commands.js +11 -11
  40. package/dist/src/cli/auth-commands.js +2 -1
  41. package/dist/src/cli/creation-help.js +9 -0
  42. package/dist/src/cli/dam-commands.js +10 -14
  43. package/dist/src/cli/editor-commands.js +7 -5
  44. package/dist/src/cli/errors.js +81 -22
  45. package/dist/src/cli/host-input.js +64 -5
  46. package/dist/src/cli/model-commands.js +9 -3
  47. package/dist/src/cli/observed-errors.js +7 -3
  48. package/dist/src/cli/org-commands.js +3 -1
  49. package/dist/src/cli/task-commands.js +6 -2
  50. package/dist/src/cli/tool-commands.js +12 -11
  51. package/dist/src/features/agent/creative-agent-adapter.js +6 -2
  52. package/dist/src/features/agent/creative-protocol.js +8 -29
  53. package/dist/src/features/agent/resource-authorizer.js +25 -17
  54. package/dist/src/features/agent/result-reader.js +31 -14
  55. package/dist/src/features/agent/use-cases.js +6 -31
  56. package/dist/src/features/credits/use-cases.js +55 -28
  57. package/dist/src/features/dam/asset-projection.js +3 -6
  58. package/dist/src/features/dam/dam-api-adapter.js +30 -15
  59. package/dist/src/features/dam/repository-catalog.js +30 -21
  60. package/dist/src/features/dam/use-cases.js +12 -7
  61. package/dist/src/features/editor/bridge-client.js +0 -2
  62. package/dist/src/features/editor/public-url.js +1 -36
  63. package/dist/src/features/editor/session.js +3 -2
  64. package/dist/src/features/editor/use-cases.js +27 -2
  65. package/dist/src/features/org/org-service.js +10 -1
  66. package/dist/src/features/org/use-cases.js +18 -4
  67. package/dist/src/features/task/process-owner.js +54 -0
  68. package/dist/src/features/task/store.js +37 -10
  69. package/dist/src/features/task/task-background.js +5 -2
  70. package/dist/src/features/task/use-cases.js +184 -84
  71. package/dist/src/features/tool/argument-paths.js +14 -0
  72. package/dist/src/features/tool/canvas-copy.js +28 -15
  73. package/dist/src/features/tool/canvas-matting.js +123 -0
  74. package/dist/src/features/tool/canvas-media.js +100 -52
  75. package/dist/src/features/tool/canvas-models.js +66 -33
  76. package/dist/src/features/tool/canvas-pricing.js +12 -0
  77. package/dist/src/features/tool/canvas-recovery.js +13 -30
  78. package/dist/src/features/tool/canvas-results.js +79 -87
  79. package/dist/src/features/tool/canvas-tool-adapter.js +134 -157
  80. package/dist/src/features/tool/canvas-video.js +44 -37
  81. package/dist/src/features/tool/dynamic-schema.js +39 -40
  82. package/dist/src/features/tool/ffprobe-executable.js +21 -0
  83. package/dist/src/features/tool/mns-catalog-adapter.js +61 -24
  84. package/dist/src/features/tool/resource-authorizer.js +11 -3
  85. package/dist/src/features/tool/tool-api-adapter.js +73 -82
  86. package/dist/src/features/tool/tool-errors.js +25 -0
  87. package/dist/src/features/tool/tool-output.js +15 -0
  88. package/dist/src/features/tool/use-cases.js +74 -98
  89. package/dist/src/features/update/update-service.js +95 -21
  90. package/dist/src/platform/media-type.js +46 -0
  91. package/dist/src/platform/public-url.js +35 -0
  92. package/dist/src/platform/remote-error-evidence.js +33 -6
  93. package/dist/src/platform/resource-auth-key.js +35 -1
  94. package/dist/src/platform/safe-upload-file.js +36 -41
  95. package/dist/src/platform/signature.js +2 -2
  96. package/dist/src/platform/signed-http-transport.js +4 -1
  97. package/dist/src/platform/url-safety.js +6 -1
  98. package/dist/src/platform/webm-header.js +41 -0
  99. package/dist/src/telemetry/command-route.js +38 -0
  100. package/dist/src/telemetry/command-routes.json +1 -0
  101. package/dist/src/telemetry/failure-summary.js +1 -1
  102. package/dist/src/telemetry/invocation.js +1 -2
  103. package/dist/src/telemetry/process-errors.js +17 -33
  104. package/dist/src/telemetry/sanitize.js +19 -4
  105. package/dist/src/telemetry/sls-sink.js +8 -0
  106. package/package.json +4 -4
  107. package/skills/gd-cli/SKILL.md +18 -5
  108. package/skills/gd-cli/references/agent.md +9 -4
  109. package/skills/gd-cli/references/creation.md +3 -1
  110. package/skills/gd-cli/references/editor.md +7 -5
  111. package/skills/gd-cli/references/errors.md +19 -8
  112. package/skills/gd-cli/references/matting.md +3 -5
  113. package/skills/gd-cli/references/media-tools.md +10 -4
  114. package/skills/gd-cli/references/tool.md +9 -15
@@ -1,3 +1,6 @@
1
+ import { validateHeaderValue } from "node:http";
2
+ import { concreteMediaType, mediaTypeForFormat } from "./media-type.js";
3
+ import { hasWebmDocType } from "./webm-header.js";
1
4
  import { isInterruption } from "./interruption.js";
2
5
  import { open, realpath, stat } from "node:fs/promises";
3
6
  import { basename, extname, sep } from "node:path";
@@ -20,6 +23,7 @@ const protectedSegments = new Set([
20
23
  ".docker",
21
24
  ".gd",
22
25
  ".gd-cli-dev",
26
+ ".insmind",
23
27
  ".git",
24
28
  ".gnupg",
25
29
  ".kube",
@@ -39,29 +43,16 @@ const protectedFilenames = new Set([
39
43
  "id_rsa",
40
44
  "known_hosts"
41
45
  ]);
42
- const mediaTypes = {
43
- avif: "image/avif",
44
- bmp: "image/bmp",
45
- gif: "image/gif",
46
- heic: "image/heic",
47
- heif: "image/heif",
48
- jpeg: "image/jpeg",
49
- m4v: "video/x-m4v",
50
- mkv: "video/x-matroska",
51
- mov: "video/quicktime",
52
- mp4: "video/mp4",
53
- png: "image/png",
54
- svg: "image/svg+xml",
55
- webm: "video/webm",
56
- webp: "image/webp"
57
- };
58
46
  function reject(reason) {
59
47
  throw new LocalFileInputError(undefined, reason);
60
48
  }
61
49
  function assertSafePath(filePath) {
62
50
  const segments = filePath.split(sep).filter(Boolean).map((segment) => segment.toLowerCase());
63
51
  const filename = segments.at(-1) ?? "";
64
- if (protectedFilenames.has(filename) || filename.startsWith(".")
52
+ const parent = segments.at(-2);
53
+ const hostCredential = (parent === ".codex" && filename === "auth.json")
54
+ || (parent === ".gemini" && filename === "oauth_creds.json");
55
+ if (hostCredential || protectedFilenames.has(filename) || filename.startsWith(".")
65
56
  || segments.some(segment => protectedSegments.has(segment))) {
66
57
  reject("path_restricted");
67
58
  }
@@ -80,10 +71,15 @@ function detectedFormat(header) {
80
71
  if (signature === "GIF87a" || signature === "GIF89a")
81
72
  return "gif";
82
73
  }
83
- if (header.length >= 12
84
- && header.subarray(0, 4).toString("ascii") === "RIFF"
85
- && header.subarray(8, 12).toString("ascii") === "WEBP")
86
- return "webp";
74
+ if (header.length >= 12 && header.toString("latin1", 0, 4) === "RIFF") {
75
+ const kind = header.toString("latin1", 8, 12);
76
+ if (kind === "WEBP")
77
+ return "webp";
78
+ if (kind === "WAVE")
79
+ return "wav";
80
+ }
81
+ if (hasWebmDocType(header))
82
+ return "webm";
87
83
  if (header.length >= 12 && header.subarray(4, 8).toString("ascii") === "ftyp") {
88
84
  const brand = header.subarray(8, 12).toString("ascii");
89
85
  if (["isom", "iso2", "iso5", "iso6", "mp41", "mp42", "avc1", "dash"].includes(brand))
@@ -103,7 +99,8 @@ async function readHeader(filePath, signal) {
103
99
  signal.throwIfAborted();
104
100
  const handle = await open(filePath, "r");
105
101
  try {
106
- const buffer = Buffer.alloc(32);
102
+ // Read a bounded prefix; the WebM DocType can extend past a 32-byte prefix.
103
+ const buffer = Buffer.alloc(4096);
107
104
  const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
108
105
  signal.throwIfAborted();
109
106
  return buffer.subarray(0, bytesRead);
@@ -135,31 +132,29 @@ export async function inspectUploadFile(input) {
135
132
  return reject("not_regular_file");
136
133
  const header = await readHeader(filePath, input.signal);
137
134
  const detected = detectedFormat(header);
138
- // Hidden host/workspace ancestors are not themselves secrets. Only known
139
- // media headers may pass there; named credential paths remain blocked on
140
- // both requested and canonical paths before any file is opened.
141
- if (input.allowSensitivePath !== true && detected === undefined
142
- && [requestedPath, filePath].some(path => path.split(sep).some(segment => segment.startsWith(".")))) {
143
- return reject("path_restricted");
144
- }
145
135
  const extension = extname(requestedPath).slice(1).toLowerCase();
146
- const format = detected ?? (extension === "jpg" ? "jpeg" : extension);
147
- if (format === "")
148
- return reject("format_missing");
149
- const detectedMediaType = detected === undefined ? undefined : mediaTypes[detected];
150
- if (detectedMediaType !== undefined
151
- && input.claimedMediaType !== undefined
152
- && input.claimedMediaType.trim().toLowerCase() !== detectedMediaType) {
153
- return reject("media_type_mismatch");
136
+ const declaration = input.claimedMediaType;
137
+ if (declaration !== undefined) {
138
+ try {
139
+ validateHeaderValue("Content-Type", declaration);
140
+ }
141
+ catch {
142
+ return reject("invalid_media_type_header");
143
+ }
154
144
  }
145
+ const claimed = concreteMediaType(declaration);
146
+ const subtype = claimed?.split("/")[1];
147
+ const declaredFormat = claimed === "image/svg+xml" ? "svg" : claimed === "video/quicktime" ? "mov"
148
+ : subtype && /^[a-z0-9]+$/u.test(subtype) ? subtype : undefined;
149
+ const format = detected ?? (extension === "jpg" ? "jpeg" : extension || declaredFormat || "bin");
155
150
  return {
156
151
  filePath,
157
152
  filename: basename(requestedPath),
158
153
  format,
159
- mediaType: detectedMediaType
160
- ?? input.claimedMediaType
161
- ?? mediaTypes[format]
162
- ?? `application/${format}`,
154
+ mediaType: declaration
155
+ ?? (detected ? mediaTypeForFormat(detected) : undefined)
156
+ ?? mediaTypeForFormat(format)
157
+ ?? (format === "bin" ? "application/octet-stream" : `application/${format}`),
163
158
  size: details.size
164
159
  };
165
160
  }
@@ -7,8 +7,8 @@ export function canonicalizeQuery(entries) {
7
7
  .replaceAll("%3A", ":");
8
8
  }
9
9
  export function createSigningString(input) {
10
- // The gateway signs literal base64 padding; keep its wire query URL-encoded.
11
- const signingQuery = input.canonicalQuery.replaceAll("%3D", "=");
10
+ // The gateway signs decoded form values. On the wire, a space is + and a literal plus is %2B.
11
+ const signingQuery = decodeURIComponent(input.canonicalQuery.replaceAll("+", " "));
12
12
  return `${input.method.toUpperCase()}@${input.pathname}@${signingQuery}@${input.timestamp}`;
13
13
  }
14
14
  export function signRequest(input) {
@@ -235,7 +235,10 @@ export function createSignedHttpTransport(options) {
235
235
  const { response } = received;
236
236
  if (!response.ok) {
237
237
  const body = await readText(received);
238
- throw new RemoteRequestError(response.status, false, remoteErrorEvidence(body), undefined, undefined, received.diagnostics());
238
+ const original = remoteErrorEvidence(body);
239
+ const evidence = request.sensitiveResponse
240
+ ? (original.remoteCode === undefined ? {} : { remoteCode: original.remoteCode }) : original;
241
+ throw new RemoteRequestError(response.status, false, evidence, undefined, undefined, received.diagnostics());
239
242
  }
240
243
  if (!response.body)
241
244
  throw new RemoteRequestError(response.status, false, {}, undefined, "RESPONSE_BODY_MISSING", received.diagnostics());
@@ -65,7 +65,7 @@ function isPrivateIpv6(parts) {
65
65
  }
66
66
  return unspecified || loopback || uniqueLocal || linkLocal;
67
67
  }
68
- export function parseSafeRemoteAssetUrl(value) {
68
+ export function parseHttpAssetUrl(value) {
69
69
  let url;
70
70
  try {
71
71
  url = new URL(value);
@@ -78,6 +78,11 @@ export function parseSafeRemoteAssetUrl(value) {
78
78
  || url.password !== "") {
79
79
  return fail();
80
80
  }
81
+ return url;
82
+ }
83
+ /** Only a process that opens the URL needs to enforce the local network boundary. */
84
+ export function parseSafeRemoteAssetUrl(value) {
85
+ const url = parseHttpAssetUrl(value);
81
86
  const hostname = url.hostname
82
87
  .replace(/^\[|\]$/g, "")
83
88
  .replace(/[.]+$/, "")
@@ -0,0 +1,41 @@
1
+ function vintWidth(first) {
2
+ if (!first)
3
+ return 0;
4
+ // The leading marker bit determines the width of an EBML variable-size integer.
5
+ return Math.clz32(first) - 23;
6
+ }
7
+ function ebmlPayload(bytes, sizeOffset, limit) {
8
+ const width = vintWidth(bytes[sizeOffset]);
9
+ const start = sizeOffset + width;
10
+ if (!width || start > limit)
11
+ return;
12
+ let length = bytes[sizeOffset] & (0xff >>> width);
13
+ for (let i = sizeOffset + 1; i < start; i++)
14
+ length = length * 256 + bytes[i];
15
+ if (length > limit - start || length === 2 ** (7 * width) - 1)
16
+ return;
17
+ return { start, end: start + length };
18
+ }
19
+ export function hasWebmDocType(bytes) {
20
+ if (bytes.length < 5 || bytes.readUInt32BE(0) !== 0x1a45dfa3)
21
+ return false;
22
+ const header = ebmlPayload(bytes, 4, bytes.length);
23
+ if (!header)
24
+ return false;
25
+ let found = false;
26
+ for (let offset = header.start; offset < header.end;) {
27
+ const idWidth = vintWidth(bytes[offset]);
28
+ if (!idWidth || idWidth > 4)
29
+ return false;
30
+ const field = ebmlPayload(bytes, offset + idWidth, header.end);
31
+ if (!field)
32
+ return false;
33
+ if (idWidth === 2 && bytes.readUInt16BE(offset) === 0x4282) {
34
+ if (found || field.end - field.start !== 4 || bytes.toString("latin1", field.start, field.end) !== "webm")
35
+ return false;
36
+ found = true;
37
+ }
38
+ offset = field.end;
39
+ }
40
+ return found;
41
+ }
@@ -0,0 +1,38 @@
1
+ import { Command } from "commander";
2
+ /** Read only argv. Commander owns option arity, the -- separator and the choice of subcommand. */
3
+ export function identifyInvocation(root, argv) {
4
+ let route = root;
5
+ let operands = [];
6
+ let unknown = argv;
7
+ let schema = false;
8
+ const selected = (operation, mode) => ({ operation, mode: () => mode });
9
+ while (true) {
10
+ // Parse the option declarations on a disposable command; the real flags, actions and I/O are untouched.
11
+ const parser = new Command().exitOverride().configureOutput({ writeErr() { } });
12
+ for (const flags of route.options)
13
+ parser.option(flags);
14
+ let parsed;
15
+ try {
16
+ parsed = parser.parseOptions(unknown);
17
+ }
18
+ catch {
19
+ if (parser.opts().version)
20
+ return selected("version", "version");
21
+ return selected(route.operation, schema || parser.opts().schema ? "schema" : "execute");
22
+ }
23
+ if (parser.opts().version)
24
+ return selected("version", "version");
25
+ schema ||= parser.opts().schema === true;
26
+ operands = operands.concat(parsed.operands);
27
+ unknown = parsed.unknown;
28
+ const name = operands[0];
29
+ if (name && Object.hasOwn(route.children, name)) {
30
+ route = route.children[name];
31
+ operands = operands.slice(1);
32
+ continue;
33
+ }
34
+ if (unknown.includes("--help") || unknown.includes("-h"))
35
+ return selected(route === root ? "help" : route.operation, "help");
36
+ return selected(name && !route.action ? "unknown" : route.operation, schema ? "schema" : "execute");
37
+ }
38
+ }
@@ -0,0 +1 @@
1
+ {"operation":"unknown","action":false,"options":["-V, --version","--json-errors"],"children":{"auth":{"operation":"auth","action":false,"options":[],"children":{"login":{"operation":"auth.login","action":true,"options":["--no-browser","--require-browser"],"children":{}},"status":{"operation":"auth.status","action":true,"options":["--json"],"children":{}},"logout":{"operation":"auth.logout","action":true,"options":[],"children":{}}}},"org":{"operation":"org","action":false,"options":[],"children":{"list":{"operation":"org.list","action":true,"options":["--json"],"children":{}},"current":{"operation":"org.current","action":true,"options":["--json"],"children":{}},"switch":{"operation":"org.switch","action":true,"options":["--org <org-id>"],"children":{}}}},"agent":{"operation":"agent","action":false,"options":[],"children":{"send":{"operation":"agent.send","action":true,"options":["--schema","--input <file|->","--async","--json"],"children":{}}}},"tool":{"operation":"tool","action":false,"options":[],"children":{"list":{"operation":"tool.list","action":true,"options":["--json"],"children":{}},"call":{"operation":"tool.call","action":true,"options":["--schema","--input <file|->","--async","--json"],"children":{}}}},"model":{"operation":"model","action":false,"options":[],"children":{"list":{"operation":"model.list","action":true,"options":["--tool <tool>","--json"],"children":{}},"get":{"operation":"model.get","action":true,"options":["--tool <tool>","--json"],"children":{}}}},"editor":{"operation":"editor","action":false,"options":[],"children":{"connect":{"operation":"editor.connect","action":true,"options":["--json"],"children":{}},"disconnect":{"operation":"editor.disconnect","action":true,"options":["--json"],"children":{}},"snapshot":{"operation":"editor.snapshot","action":true,"options":["--json"],"children":{}},"apply":{"operation":"editor.apply","action":true,"options":["--schema","--input <file|->","--json"],"children":{}},"screenshot":{"operation":"editor.screenshot","action":true,"options":["--json"],"children":{}},"save":{"operation":"editor.save","action":true,"options":["--json"],"children":{}}}},"dam":{"operation":"dam","action":false,"options":[],"children":{"repository":{"operation":"dam.repository","action":false,"options":[],"children":{"list":{"operation":"dam.repository.list","action":true,"options":["--json"],"children":{}}}},"folder":{"operation":"dam.folder","action":false,"options":[],"children":{"list":{"operation":"dam.folder.list","action":true,"options":["--repository-id <id>","--parent-id <id>","--query <text>","--page <n>","--page-size <number>","--json"],"children":{}}}},"tag":{"operation":"dam.tag","action":false,"options":[],"children":{"list":{"operation":"dam.tag.list","action":true,"options":["--repository-id <id>","--query <text>","--json"],"children":{}}}},"download":{"operation":"dam.download","action":true,"options":["--repository-id <id>","--output-dir <directory>","--json"],"children":{}},"rename":{"operation":"dam.rename","action":true,"options":["--kind <asset|folder>","--title <title>","--repository-id <id>","--json"],"children":{}},"move":{"operation":"dam.move","action":true,"options":["--kind <asset|folder>","--target-folder-id <id>","--repository-id <source-id>","--target-repository-id <target-id>","--json"],"children":{}},"copy":{"operation":"dam.copy","action":true,"options":["--kind <asset|folder>","--target-folder-id <id>","--repository-id <source-id>","--target-repository-id <target-id>","--json"],"children":{}},"list":{"operation":"dam.list","action":true,"options":["--repository-id <id>","--all-repositories","--folder-id <id>","--no-include-child-folder","--type <type>","--asset-format <csv>","--tag-ids <csv>","--page-size <number>","--cursor <id>","--json"],"children":{}},"search":{"operation":"dam.search","action":true,"options":["--repository-id <id>","--all-repositories","--folder-id <id>","--no-include-child-folder","--type <type>","--asset-format <csv>","--tag-ids <csv>","--page-size <number>","--cursor <id>","--json"],"children":{}},"get":{"operation":"dam.get","action":true,"options":["--json"],"children":{}},"upload":{"operation":"dam.upload","action":true,"options":["--repository-id <id>","--title <title>","--folder-id <id>","--tag-ids <csv>","--allow-sensitive-path","--wait-analysis","--json"],"children":{}},"delete":{"operation":"dam.delete","action":true,"options":["--repository-id <id>","--permanent"],"children":{}}}},"update":{"operation":"update","action":true,"options":[],"children":{"check":{"operation":"update.check","action":true,"options":["--for-display","--schema","--json"],"children":{}}}},"task":{"operation":"task","action":false,"options":[],"children":{"list":{"operation":"task.list","action":true,"options":["--limit <number>","--operation <operation>","--json"],"children":{}},"get":{"operation":"task.get","action":true,"options":["--json"],"children":{}}}},"credits":{"operation":"credits.get","action":true,"options":["--json","--schema"],"children":{"usage":{"operation":"credits.usage","action":false,"options":[],"children":{"list":{"operation":"credits.usage.list","action":true,"options":["--from <timestamp>","--to <timestamp>","--limit <number>","--cursor <cursor>","--json","--schema"],"children":{}},"get":{"operation":"credits.usage.get","action":true,"options":["--json","--schema"],"children":{}}}}}}}}
@@ -6,7 +6,7 @@ const flags = new Set(["bodyUsedAtReceipt", "bodyLockedAtReceipt", "bodyUsedBefo
6
6
  const counts = new Set(["messageCount", "invalidMessageCount", "systemErrorCount", "publicPartCount",
7
7
  "streamPayloadCount", "streamJsonValueCount"]);
8
8
  const localFileSteps = new Set(["directory_create", "directory_permissions", "directory_read", "stat", "parse", "validate", "open", "file_permissions", "read", "write", "sync", "close", "rename", "unlink"]);
9
- const inputReasons = new Set(["path_restricted", "not_regular_file", "format_missing", "media_type_mismatch", "file_read_failed",
9
+ const inputReasons = new Set(["path_restricted", "not_regular_file", "format_missing", "invalid_media_type_header", "file_read_failed",
10
10
  "json_read", "json_parse", "schema_validation", "invalid_task_id", "command_arguments", "model_required", "model_not_found",
11
11
  "model_tool_mismatch", "model_parameters", "tool_not_found", "invalid_asset_url", "commander.unknownOption",
12
12
  "commander.unknownCommand", "commander.missingArgument", "commander.excessArguments", "commander.help",
@@ -148,7 +148,7 @@ export function createTelemetryInvocation(options) {
148
148
  const snapshot = identity();
149
149
  const keys = ["host_invocation_id", "host_connector_version", "installation_owner", "invocation_purpose",
150
150
  "account_id", "organization_id", "tool_name", "model_id", "content_id", "task_id", "dify_task_id",
151
- "cli_task_id", "execution_mode", "parameters"];
151
+ "cli_task_id", "execution_mode", "execution_protocol", "parameters"];
152
152
  for (const key of keys) {
153
153
  if (context[key] !== undefined)
154
154
  Object.assign(snapshot, { [key]: context[key] });
@@ -207,7 +207,6 @@ export function createTelemetryInvocation(options) {
207
207
  const stage = completion.outcome === "success" ? "process" : classify(completion.error).failureStage ?? failureStage(completion.error) ?? "command";
208
208
  remember({ ...last, event_name: "stage_finished", stage, outcome: completion.outcome,
209
209
  ...(completion.outcome !== "success" && failedStep ? { failed_step: failedStep } : {}),
210
- ...(context.parameters && (!issued || last.command_kind === "technical") ? { parameters: context.parameters } : {}),
211
210
  duration_ms: Math.max(0, options.now() - startedAt),
212
211
  ...(completion.outcome === "success" ? {} : {
213
212
  failure_stage: classify(completion.error).failureStage ?? failureStage(completion.error) ?? "unknown"
@@ -1,42 +1,23 @@
1
- import { classifyTelemetryError, mapCliError } from "../cli/errors.js";
2
1
  import { isInterruption } from "../platform/interruption.js";
3
2
  import { randomBytes } from "node:crypto";
4
- import { readFile, readdir } from "node:fs/promises";
3
+ import { readFile } from "node:fs/promises";
5
4
  import { dirname, join } from "node:path";
6
5
  import { homedir } from "node:os";
7
6
  import { fileURLToPath } from "node:url";
8
7
  import { gaodingProduct, insmindProduct } from "../product/config.js";
9
8
  import { createTelemetryInvocation, hostTelemetryContext } from "./invocation.js";
10
9
  import { createSlsTelemetrySink } from "./sls-sink.js";
11
- // The CLI module graph may not be loadable. Use packaged operation names only,
12
- // so a user-supplied positional argument can never become an SLS operation name.
10
+ // The normal runtime or even Commander may be unavailable. Only package-owned names may enter SLS.
13
11
  async function bootstrapDefinition(argv) {
14
- const names = new Set(["agent.send", "tool.call", "editor.apply", "auth.login", "auth.logout", "org.switch", "credits", "update"]);
15
- const contracts = new URL("../../../contracts/operations/", import.meta.url);
16
- for (const name of await readdir(contracts).catch(() => []))
17
- names.add(name);
18
- const path = [];
19
- let mode = "execute";
20
- for (let i = 0; i < argv.length; i++) {
21
- const token = argv[i];
22
- if (token === "--")
23
- break;
24
- if (token === "--input" || token === "--locale") {
25
- i++;
26
- continue;
27
- }
28
- if (token === "--help" || token === "-h")
29
- mode = "help";
30
- else if (token === "--version" || token === "-V")
31
- mode = "version";
32
- else if (token === "--schema" && mode === "execute")
33
- mode = "schema";
34
- else if (!token.startsWith("-") && !names.has(path.join(".")) && path.length < 3)
35
- path.push(token);
12
+ try {
13
+ const [{ identifyInvocation }, catalog] = await Promise.all([
14
+ import("./command-route.js"), readFile(new URL("./command-routes.json", import.meta.url), "utf8")
15
+ ]);
16
+ return identifyInvocation(JSON.parse(catalog), argv);
17
+ }
18
+ catch {
19
+ return { operation: "bootstrap", mode: () => "execute" };
36
20
  }
37
- const name = path.join(".");
38
- const operation = mode === "version" ? "version" : names.has(name) ? name : !name && mode === "help" ? "help" : "bootstrap";
39
- return { operation, mode: () => mode };
40
21
  }
41
22
  /** Independent fallback for entrypoints which cannot construct the full runtime. */
42
23
  export async function reportProcessError(error, options) {
@@ -55,8 +36,11 @@ export async function reportProcessError(error, options) {
55
36
  catch { /* The package file may be unavailable during startup failure. */ }
56
37
  }
57
38
  const aborted = isInterruption(error, options.signal);
58
- const classification = classifyTelemetryError(error, { aborted, product });
59
- const mapped = mapCliError(error, { aborted, product });
39
+ // The application error mapper imports Commander and feature dependencies which can themselves fail to load.
40
+ const mapper = await import("../cli/errors.js").catch(() => undefined);
41
+ const classification = mapper?.classifyTelemetryError(error, { aborted, product })
42
+ ?? { outcome: aborted ? "interrupted" : "failure", errorCode: "INTERNAL_ERROR" };
43
+ const failure = mapper?.mapCliError(error, { aborted, product }).failure;
60
44
  const telemetry = createTelemetryInvocation({ cliName: product.commandName, cliVersion: version,
61
45
  env: options.environment ?? (process.env.CLI_TELEMETRY_ENV === "test" ? "test" : "production"),
62
46
  processRole: options.processRole ?? "cli", now: Date.now,
@@ -69,8 +53,8 @@ export async function reportProcessError(error, options) {
69
53
  telemetry.annotate(hostTelemetryContext(process.env));
70
54
  if ((options.processRole ?? "cli") === "cli")
71
55
  await telemetry.issue(definition);
72
- const events = telemetry.finish(mapped.kind === "interrupted" ? { outcome: "interrupted", error } : {
73
- outcome: "failure", error, errorCode: mapped.failure.code, errorMessage: mapped.failure.message,
56
+ const events = telemetry.finish(classification.outcome === "interrupted" ? { outcome: "interrupted", error } : {
57
+ outcome: "failure", error, errorCode: failure?.code ?? "INTERNAL_ERROR", errorMessage: failure?.message ?? "CLI startup failed.",
74
58
  ...(classification.httpStatus === undefined ? {} : { httpStatus: classification.httpStatus }),
75
59
  ...(classification.remoteErrorCode === undefined ? {} : { remoteErrorCode: classification.remoteErrorCode }),
76
60
  ...(classification.remoteErrorBody === undefined ? {} : { remoteErrorBody: classification.remoteErrorBody })
@@ -1,3 +1,4 @@
1
+ import { posix, win32 } from "node:path";
1
2
  import { isSensitiveKey, redactSensitiveText } from "../platform/redact.js";
2
3
  const ids = new Set(["account_id", "organization_id", "cli_task_id", "task_id", "dify_task_id", "content_id"]);
3
4
  function sensitive(key) {
@@ -28,7 +29,15 @@ export function cleanText(value) {
28
29
  }
29
30
  export function cleanDiagnostic(value) {
30
31
  const seen = new WeakSet();
31
- function clean(item, depth) {
32
+ const envelope = value && typeof value === "object" ? value : {};
33
+ const tool = envelope.operation === "tool.call";
34
+ const toolDiagnostic = (tool || (envelope.operation === "task.get" && ["dify", "toolkit", "sync"].includes(String(envelope.execution_protocol)))) && envelope.event_name === "stage_finished";
35
+ function clean(item, depth, inParameters = false) {
36
+ if (typeof item === "string" && inParameters) {
37
+ if (posix.isAbsolute(item) || win32.isAbsolute(item) || /^file:\/\//iu.test(item))
38
+ return "[Local file]";
39
+ item = item.replace(/file:\/\/[^\s<>"`]+/giu, "[Local file]");
40
+ }
32
41
  if (typeof item === "string")
33
42
  return /^data:[^,]*;base64,/iu.test(item) ? "[Binary omitted]" : cleanText(item);
34
43
  if (typeof item === "bigint")
@@ -45,9 +54,15 @@ export function cleanDiagnostic(value) {
45
54
  if (item instanceof Error)
46
55
  return errorEvidence(item);
47
56
  if (Array.isArray(item))
48
- return item.map(v => clean(v, depth + 1));
49
- return Object.fromEntries(Object.entries(item).map(([key, v]) => [key,
50
- depth === 0 && ids.has(key) ? v : sensitive(key) ? "[REDACTED]" : clean(v, depth + 1)]));
57
+ return item.map(v => clean(v, depth + 1, inParameters));
58
+ const entries = Object.entries(item);
59
+ const fields = depth === 0 && envelope.event_name === "stage_finished"
60
+ ? entries.filter(([key]) => key !== "parameters") : entries;
61
+ return Object.fromEntries(fields.map(([key, v]) => [key,
62
+ depth === 0 && toolDiagnostic && ["error_message", "error_stack", "remote_error_body"].includes(key)
63
+ ? (key === "error_message" ? envelope.error_code ?? "TOOL_ERROR" : "[User content omitted]") :
64
+ inParameters && tool && key === "prompt" ? "[User content omitted]" :
65
+ depth === 0 && ids.has(key) ? v : sensitive(key) || (inParameters && key === "answers") ? "[REDACTED]" : clean(v, depth + 1, inParameters || key === "parameters")]));
51
66
  }
52
67
  return clean(value, 0);
53
68
  }
@@ -120,6 +120,14 @@ export function createSlsTelemetrySink(options) {
120
120
  const entry = JSON.parse(raw);
121
121
  if (entry.event?.schema_version !== "6" || !Number.isFinite(entry.queuedAt) || !entry.event || eventKey(entry.event) !== name.slice(0, -5))
122
122
  throw new Error();
123
+ // Earlier v6 clients could queue input parameters and echoed Agent HTTP errors.
124
+ const event = entry.event;
125
+ if (event.event_name === "stage_finished") {
126
+ delete event.parameters;
127
+ const agent = event.operation === "agent.send" || (event.operation === "task.get" && !event.execution_protocol);
128
+ if (agent && Number(event.http_status) >= 400)
129
+ delete event.remote_error_body;
130
+ }
123
131
  entries.set(name.slice(0, -5), entry);
124
132
  }
125
133
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaoding/cli",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
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": "5a8acfd84d3ce5ed311d5442c66ebc6b62c9f680",
61
- "pipelineId": "241803",
62
- "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/241803"
60
+ "sourceCommit": "6bb95e37a8accaddd86c5219d536bd9db493ed32",
61
+ "pipelineId": "245407",
62
+ "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/245407"
63
63
  }
64
64
  }
@@ -1,28 +1,41 @@
1
1
  ---
2
2
  name: gd-cli
3
- description: Use when creating images, videos or text with GD CLI, operating the focused Gaoding editor, or managing Gaoding DAM assets.
3
+ description: 用稿定做业务策划和多轮创作,查询工具能力与稿豆价格,生成或处理图片、视频、文本,操作稿定编辑器或管理素材库。
4
4
  ---
5
5
 
6
6
  # GD CLI
7
7
 
8
8
  ## 按需发现当前能力
9
9
 
10
- - 调用 `agent send`、`tool call`、`editor apply` 时,在输入 JSON 顶层填写 `host_application`。值为发起命令的实际应用名,例如 `workbuddy`、`qwenwork`、`trae`;用户直接在终端运行时填 `terminal`。
10
+ - 调用 `agent send`、`tool call`、`editor apply` 时,在输入 JSON 顶层填写发起命令的应用名 `host_application`。Codex Agent 通过 shell 执行时填 `codex`,其他宿主同理,如 `workbuddy`、`qwenwork`、`trae`。仅当用户亲自在终端执行时填 `terminal`。
11
11
  - 首次使用时确认 `gd-cli --version`;不确定入口时读 `gd-cli --help`,沿相关命令组选择命令,执行前读其 `--help`。本 Skill 的示例不代表完整能力清单。
12
12
  - 用户前台使用时,把可用升级提醒随本次结果转述给用户,一小时最多一次。只读取标准输出的宿主见下方「更新」。
13
13
  - 结构化输入先读取命令公开支持的 `--schema`;模型、参数选项、价格与资源 ID 由对应目录或详情查询取得,不从旧示例猜值。发现不支持或查询失败时说明缺口,不静默替换用户明确约束。
14
+ - 先按操作对象选入口:附件图片、媒体链接及导出图片的改字、分层、矢量化等处理从 `tool list` 发现;作品 ID/编辑器链接中的元素操作才进入 Editor。只查过 Editor 不能判断图片工具是否支持。
15
+ - 用户明确要求用稿定策划、创作或处理时,以实际 CLI 调用和服务回复为完成依据;策划请求也应发现并调用 Agent,不能用宿主自行给出的建议冒充稿定回复。选定模型后读 `model get` 的详情再判断能否满足需求;不凭列表摘要宣布不支持,也不自行用本地插值、描图等替代稿定调用。本地脚本可用于素材准备;替代产物须单独说明,不能把指定的稿定任务报为完成。
16
+ - 先根据 Schema 构造并保存完整 JSON,再用 `--input request.json` 执行。命令不交互填参;若用 `--input -`,必须在同一条 shell 命令中通过管道或重定向送入完整 JSON,单独执行不会再向你提问。JSON 内的本地媒体用 `Path(path).resolve().as_uri()` 或 `pathToFileURL(path).href` 生成 URI;中文、空格和 `#` 保持原文件名并正确转义。
14
17
  - 同一会话可复用同一路径/版本的 help 和静态 Schema;CLI 变化后重查。动态信息在本次任务选能力或报价时查询,身份/组织变化或明确不匹配时刷新相关结果,不全量扫描无关目录。
15
18
  - 发现只说明当前实装 CLI 的能力,不等于升级,也不授予生成、写入或安装权限;未知结果的恢复按错误处理指引执行。
16
19
 
20
+ ## 创作执行边界
21
+
22
+ 选定路由后,执行前读取 [Tool](references/tool.md) 或 [Agent](references/agent.md) 的提交和交付流程;下方场景页用于选能力和准备素材,不能替代执行流程。
23
+
24
+ - 现在要结果时,默认同步。保留宿主返回的退出状态和进程句柄,等原进程交付完整结果。句柄丢失时,用 stderr 中的 CLI taskId 查原任务。running 时继续等,不让用户回来催取。
25
+ - 用户明确说稍后拿时,用 `--async`。收到受理回执就把 taskId 和当前状态给用户,本轮到此结束。等用户回来再取同一任务。
26
+ - 首次取得可用服务结果就先交付。不得为修正自己观察到的效果偏差,擅自换模型、调整选区或再次创作;需要返修时说明偏差并由用户决定。执行前的素材准备、原任务查询和结果下载不属于追加创作。
27
+ - 服务明确返回用于交付的资源 URL 是完整值,原样复制或保存后引用;不要手抄、拼接、截断或去掉查询参数。任务查询返回同一成品时仍使用实际返回的完整链接,不凭记忆重建。
28
+ - Tool 返回的价格区间只是估价,即使上下限相同也不能称为实扣;Agent 的实际用量与账本核对见 [费用来源](references/errors.md#费用来源)。
29
+
17
30
  ## 读取任务指引
18
31
 
19
32
  按用户目标只读取对应参考:
20
33
 
21
34
  - 按业务意图选择 Agent / Tool 创作路由、发现 Model 并生成图片、视频或文本:[创作](references/creation.md)
22
- - 选择图片/视频生成或专用处理工具、准备参考素材及复核 mask:[图片与视频工具选择](references/media-tools.md)
35
+ - 处理附件/链接中的图片或视频(含改字、分层、矢量化)、准备参考素材和 mask:[图片与视频工具选择](references/media-tools.md)
23
36
  - 去背景、提取主体、透明 PNG,或补全被遮挡的物体:[抠图](references/matting.md)
24
- - 操作当前 AI+ Editor 作品:[编辑器](references/editor.md)
37
+ - 操作已连接作品的 Shape/Connector 元素、预览、保存或断开:[编辑器](references/editor.md)
25
38
  - 发现资源库、文件夹与标签,查询、上传、下载或管理 DAM 资源:[素材管理](references/dam.md)
26
39
  - 登录或选择组织:[登录与组织](references/auth-org.md)
27
- - 处理输出、警告、失败、中断或找回丢失结果:[错误处理](references/errors.md)
40
+ - 创作已受理/仍在运行、取回异步结果、解释费用、警告、错误或中断:[状态与错误处理](references/errors.md)
28
41
  - 更新 CLI 与随包 Agent Skill:[更新](references/update.md)
@@ -1,6 +1,6 @@
1
1
  # Agent 创作
2
2
 
3
- 耗时较长的创作优先加 `--async`,提交一次后,使用返回的 `taskId` 执行 `gd-cli task get <taskId>`。running 时隔数秒查询同一 ID;completed 时读取 result。输出为空、查询超时、unknown 或宿主等待结束,都不能作为再次生成的依据。没有 ID 时用 task list 定位原任务。省略 --async 时命令仍同步等待,继续等待同一进程。状态处理见 [错误处理](errors.md)。
3
+ 现在要结果时默认同步,保留并等待宿主返回的原进程句柄。用户明确稍后取回时用 `--async`,受理后当轮交接原 taskId 和状态。回来取件或同步输出丢失时,按[状态处理](errors.md)查原任务。
4
4
 
5
5
  先读取输入规范。需要指定 Model 时,也先读取实时 Model detail:
6
6
 
@@ -8,8 +8,7 @@
8
8
  gd-cli agent send --schema
9
9
  gd-cli model list --tool <tool>
10
10
  gd-cli model get <model>
11
- gd-cli agent send --input request.json --async
12
- gd-cli task get <taskId>
11
+ gd-cli agent send --input request.json
13
12
  ```
14
13
 
15
14
  继续已有创作时,从上一条结果读取 `message.contextId`,原样填入下一次请求;同一创作的后续规划、生成和修改沿用该 Context。首次创作省略此字段。续聊示例:
@@ -23,11 +22,17 @@ gd-cli task get <taskId>
23
22
  }
24
23
  ```
25
24
 
25
+ completed 表示本轮回复完整,先读 `result.message.parts` 再决定下一步:资源按实际内容交付;策划或普通确认文本如实转述,需要用户决定时询问;结构化 `data.questions` 则把问题交给用户。它们都不能被概括为“没有提交”,也不都表示图片/视频已生成。
26
+
27
+ 交付本轮回复或资源时,一并报告 `usage.cost.amount` 的实际稿豆消耗。同步从原输出读,异步从 completed 任务的 `result` 读。返回 0 就报 0,缺失则说未取得。汇总只加不同 taskId 已取得的费用,同一任务重复取回只计一次。
28
+
29
+ 收到结构化问题的用户回答后,沿用该结果的 `message.contextId`,把 `message.messageId` 放入 `data.questionMessageId`,`answers` 保留 question 原文并填写用户 values。这个 data Part 是本轮 parts 唯一一项,具体结构见 `agent send --schema`。普通文本补充或确认使用 text Part。每轮回复先判断是否需要用户信息,再继续;不替用户编造确认。
30
+
26
31
  将用户要求和已确认信息放在 Text Part,区分图片可见特征与材质、功能等推断。未核实信息标为待确认,必要时向用户澄清;上一轮模型描述按其事实来源判断,不自动视为用户确认。交付文案保持相同的事实边界,风格、客群和场景设想作为建议表达。
27
32
 
28
33
  需要指定 Model、生成参数或首尾帧时,在组装请求前读取 [生成约束与媒体角色](generation-constraints.md)。
29
34
 
30
- 也可用 `--input -` 从 stdin 读取 JSON。同步输出(或异步任务 completed 时的 result)包含 `message` 和本次 `agent send` 调用的实际稿豆消耗 `usage`,不包含其他调用的消耗;将最终文本、资源、服务端续作标识和实际消耗交付给用户。报告多次调用的总消耗时,只汇总实际收到的不同调用的 `usage`;同一调用重复查询不重复计费。引用单次费用时说明对应调用,未取得的费用不猜测。
35
+ 本地素材按 Skill 根页构造标准 URI。也可用 `--input -` 从 stdin 传完整 JSON。
31
36
 
32
37
  交付多个资源时,将每个 URL Part 的 `url`、`filename`、本地保存路径和展示名称作为一条记录一起处理;下载、重命名或调整顺序时保持对应,不按请求中的顺序重新配对。交付前核对每个最终链接的文件内容与名称一致;名称不足以辨认时查看资源内容。
33
38
 
@@ -12,6 +12,8 @@
12
12
  - 反例:自行加上“没有原图,先生成一个示意商品”。即使标注“概念展示”,也改变了用户指定的对象;应先取得用户选择。
13
13
  - 自由创作的区别:“设计一件虚构商品并制作宣传图”已允许创造对象,可以直接创作;仅未指定配色或版式时,可自行设计这些风格细节。
14
14
 
15
+ 成品交付后用户要求修改,把本轮指定成品作为新任务的输入;先交付已有结果,后续创作以用户要求为准。持续策划或多轮创作对话使用 Agent。
16
+
15
17
  ## Creation Route
16
18
 
17
19
  先判断 Creation Route,再选择或校验 Model。Model 和参数不决定 Agent 或 Tool 路由;两条路由都支持指定 Model 及其参数,`model list` 和 `model get` 是共享的实时发现能力。
@@ -56,4 +58,4 @@
56
58
 
57
59
  用户本轮明确附图、点名文件或指定已有结果时,将该资源作为此次编辑目标;未指定时再从当前创作的最近相关结果选择。组装或复用请求 JSON 时,核对并更新全部资源字段中的 URL/本地路径、名称与角色,使其和本轮目标对应,不只替换文字。Agent 继续同一创作时,保留对应的 `message.contextId`。
58
60
 
59
- Agent 将本地媒体写成独立 `file://` URL Part;Tool 按所选 Model detail 写入对应媒体参数。CLI 会在内部通过 DAM 完成临时上传并把公网 URL 传给创作服务;不要自行伪造 URL,也不要读取用户未明确授权的路径。
61
+ Agent 将本地媒体写成独立 URL Part;Tool 按所选 Model detail 写入对应媒体参数。按 Skill 根页从真实路径生成标准 file URI,保持原图/参考/首尾帧角色、顺序及重复引用。CLI 会在内部通过 DAM 完成临时上传并把公网 URL 传给创作服务;不要自行伪造 URL,也不要读取用户未明确授权的路径。
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## 发现能力与使用边界
4
4
 
5
+ 本分支操作作品 ID/编辑器链接对应的可编辑元素。附件图片里的文字、分层或矢量化先读 [图片与视频工具选择](media-tools.md),不因 Editor 没有对应 Action 就说 CLI 不支持。
6
+
5
7
  首次进入此任务分支,读取当前安装版本的帮助;构造 Action 前查询输入 Schema:
6
8
 
7
9
  ```bash
@@ -16,14 +18,14 @@ gd-cli editor apply --schema
16
18
 
17
19
  ## 标准流程
18
20
 
19
- 完成标准是结构与视觉复查通过,且显式保存成功并得到公开作品 URL:
21
+ 按用户要求决定完成标准:只预览时交付截图和修改说明,明确尚未保存;要求持久化时,以保存成功和公开作品 URL 为准。复查不能覆盖用户“不保存”的要求。
20
22
 
21
- 1. 查询 `gd-cli editor connect --help`,按用户目标选择 `gd-cli editor connect [target]`。不为恢复已有作品而省略目标新建 Board。只有浏览器登录、加载、编辑/保存权限和内容检查通过后才成功;连接失败时停止作图。
23
+ 1. 查询 `gd-cli editor connect --help`。继续已有作品时用它的 ID 或链接连接;还不知道是哪份作品,先向用户索取。用户要新建 Board 时才省略目标。只有浏览器登录、加载、编辑/保存权限和内容检查通过后才成功;连接失败时停止作图。
22
24
  2. 读取 `gd-cli editor snapshot`。以最新 Snapshot 中的完整元素为基础,只改变目标字段;Update 提交完整元素,不能提交 patch。
23
25
  3. 根据 Schema 和 Snapshot 构造包含 `host_application` 和有序 `actions` 数组的对象,执行 `gd-cli editor apply --input actions.json`,或用 `--input -` 从 stdin 读取。使用简短语义 ID;Connector 的方向和目标必须符合业务关系。
24
26
  4. 每次 Apply 后重新读取 Snapshot。涉及布局、文字或 Connector 时,执行 `gd-cli editor screenshot --json` 并打开返回的绝对 `path` 对应的实际 PNG。文件存在或 Action 已提交都不代表渲染正确。
25
- 5. 结构和视觉复查均通过后,执行 `gd-cli editor save --json`,继续等待原命令完成,不因短暂无输出而中断或并发操作。只有保存成功才可声明作品已保存;把返回的 `workId` 和公开 `url` 交给用户,并保留 URL 中的环境参数。等待时限查 `editor save --help`。
26
- 6. 保存成功后执行 `gd-cli editor disconnect`;断开连接不代替保存。
27
+ 5. 需要持久化且已有用户授权时,执行 `gd-cli editor save --json`,继续等待原命令完成,不因短暂无输出而中断或并发操作。只有保存成功才可声明作品已保存;把返回的 `workId` 和公开 `url` 交给用户,并保留 URL 中的环境参数。只预览时跳过本步。等待时限查 `editor save --help`。
28
+ 6. 保存后无需继续操作,或用户表示不用再连接时,执行 `gd-cli editor disconnect` 并查看 disconnected 回执;断开连接不代替保存,也不授予保存权限。
27
29
 
28
30
  `connect` 会替换旧 Session 并打开作品页面。连接前置检查失败会清理本次 Session,但保留浏览器页面;用户在页面中完成登录或处理访问权限后,再重新执行 `connect`。GD CLI 的 AK/SK 登录不能替代浏览器 AI+ 登录,账号密码应由用户在浏览器登录界面输入。
29
31
 
@@ -45,7 +47,7 @@ gd-cli editor apply --schema
45
47
 
46
48
  发现可执行问题时,先读取最新 Snapshot,再提交修正。Update 必须包含完整元素,不能提交 patch。若 `fromId`、`toId` 正确,但截图中的 Connector 仍穿过端点 Shape,原样提交该 Connector 的完整 Update 以触发原生路径重算;业务关系正确时不为绕开渲染问题改动关系。
47
49
 
48
- 修正后再次执行 `snapshot`;涉及视觉变化时再次执行 `screenshot --json` 并打开图片。存在问题就继续修正;没有可执行问题时结束复查并保存。
50
+ 修正后再次执行 `snapshot`;涉及视觉变化时再次执行 `screenshot --json` 并打开图片。在用户授权的修改范围内处理可执行问题,随后按其预览/保存要求交付。
49
51
 
50
52
  ## 失败处理
51
53