@gaoding/cli 1.7.1 → 1.9.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 (74) hide show
  1. package/contracts/operations/agent.send/input.schema.json +1 -1
  2. package/contracts/operations/model.get/input.schema.json +6 -0
  3. package/contracts/operations/model.get/output.schema.json +10 -1
  4. package/contracts/operations/tool.call/canvas-input.schema.json +60 -0
  5. package/contracts/operations/tool.call/models/image-edit-smart.schema.json +42 -0
  6. package/contracts/operations/tool.call/models/image-edit-standard.schema.json +33 -0
  7. package/contracts/operations/tool.call/models/image-enhance-smart.schema.json +27 -0
  8. package/contracts/operations/tool.call/models/image-enhance-standard.schema.json +27 -0
  9. package/contracts/operations/tool.call/models/image-expand-smart.schema.json +76 -0
  10. package/contracts/operations/tool.call/models/image-expand-standard.schema.json +61 -0
  11. package/contracts/operations/tool.call/models/image-layers-layout.schema.json +21 -0
  12. package/contracts/operations/tool.call/models/image-layers-smart.schema.json +28 -0
  13. package/contracts/operations/tool.call/models/image-matting-smart.schema.json +37 -0
  14. package/contracts/operations/tool.call/models/image-matting-standard.schema.json +26 -0
  15. package/contracts/operations/tool.call/models/image-ocr.schema.json +21 -0
  16. package/contracts/operations/tool.call/models/image-remove-smart.schema.json +32 -0
  17. package/contracts/operations/tool.call/models/image-remove-standard.schema.json +27 -0
  18. package/contracts/operations/tool.call/models/image-text-edit.schema.json +46 -0
  19. package/contracts/operations/tool.call/models/image-vectorize.schema.json +21 -0
  20. package/contracts/operations/tool.call/models/video-edit-smart.schema.json +76 -0
  21. package/contracts/operations/tool.call/models/video-enhance-smart.schema.json +33 -0
  22. package/contracts/operations/tool.call/models/video-enhance-standard.schema.json +27 -0
  23. package/contracts/operations/tool.call/ocr-payload.schema.json +66 -0
  24. package/contracts/operations/tool.call/output.schema.json +38 -0
  25. package/contracts/operations/tool.call/template-payload.schema.json +96 -0
  26. package/dist/src/bootstrap/create-runtime.js +61 -25
  27. package/dist/src/bootstrap/validators.js +1 -1
  28. package/dist/src/cli/action-binding.js +3 -0
  29. package/dist/src/cli/agent-commands.js +1 -0
  30. package/dist/src/cli/errors.js +43 -10
  31. package/dist/src/cli/model-commands.js +7 -4
  32. package/dist/src/cli/observed-errors.js +13 -5
  33. package/dist/src/cli/task-commands.js +1 -1
  34. package/dist/src/cli/tool-commands.js +3 -1
  35. package/dist/src/contracts/schema.js +4 -1
  36. package/dist/src/features/agent/creative-protocol.js +22 -5
  37. package/dist/src/features/agent/resource-authorizer.js +1 -0
  38. package/dist/src/features/agent/use-cases.js +15 -5
  39. package/dist/src/features/auth/sso-service.js +13 -4
  40. package/dist/src/features/dam/dam-api-adapter.js +1 -0
  41. package/dist/src/features/dam/file-downloader.js +23 -2
  42. package/dist/src/features/task/store.js +8 -4
  43. package/dist/src/features/task/use-cases.js +14 -11
  44. package/dist/src/features/tool/canvas-copy.js +61 -0
  45. package/dist/src/features/tool/canvas-media.js +193 -0
  46. package/dist/src/features/tool/canvas-models.js +109 -0
  47. package/dist/src/features/tool/canvas-pricing.js +81 -0
  48. package/dist/src/features/tool/canvas-recovery.js +68 -0
  49. package/dist/src/features/tool/canvas-results.js +144 -0
  50. package/dist/src/features/tool/canvas-tool-adapter.js +366 -0
  51. package/dist/src/features/tool/canvas-video.js +84 -0
  52. package/dist/src/features/tool/catalog.js +35 -13
  53. package/dist/src/features/tool/dynamic-schema.js +52 -23
  54. package/dist/src/features/tool/matting-billing.js +103 -0
  55. package/dist/src/features/tool/mns-catalog-adapter.js +66 -19
  56. package/dist/src/features/tool/resource-authorizer.js +34 -0
  57. package/dist/src/features/tool/scene-catalog-adapter.js +35 -0
  58. package/dist/src/features/tool/tool-api-adapter.js +24 -5
  59. package/dist/src/features/tool/use-cases.js +28 -3
  60. package/dist/src/features/update/update-service.js +4 -2
  61. package/dist/src/platform/file-lock.js +12 -0
  62. package/dist/src/platform/local-json-file.js +19 -5
  63. package/dist/src/platform/safe-upload-file.js +18 -10
  64. package/dist/src/platform/schema-issues.js +47 -2
  65. package/dist/src/platform/text-output.js +17 -4
  66. package/dist/src/product/config.js +12 -1
  67. package/dist/src/telemetry/failure-summary.js +18 -0
  68. package/package.json +5 -4
  69. package/skills/gd-cli/SKILL.md +2 -0
  70. package/skills/gd-cli/references/creation.md +2 -0
  71. package/skills/gd-cli/references/generation-constraints.md +3 -1
  72. package/skills/gd-cli/references/matting.md +29 -0
  73. package/skills/gd-cli/references/media-tools.md +40 -0
  74. package/skills/gd-cli/references/tool.md +5 -5
@@ -1,6 +1,7 @@
1
1
  import { parseSafeRemoteAssetUrl, UrlSafetyError } from "../../platform/url-safety.js";
2
2
  import { findToolModel, defaultToolDefinitions, projectModelDetail, projectModelList, projectToolList, ToolInputError } from "./catalog.js";
3
3
  import { assertModelArguments, buildToolArgumentsSchema } from "./dynamic-schema.js";
4
+ import { hasCanvasMetering } from "./canvas-pricing.js";
4
5
  const mediaTypes = {
5
6
  avif: "image/avif",
6
7
  gif: "image/gif",
@@ -66,6 +67,17 @@ export function createToolUseCases(dependencies) {
66
67
  throw new ToolInputError("model_required", "/arguments/model");
67
68
  const selected = findToolModel(catalog, input.name, modelName);
68
69
  assertModelArguments(selected, input.arguments);
70
+ if (selected.execution?.kind === "canvas") {
71
+ for (const parameter of selected.parameters) {
72
+ const value = input.arguments[parameter.name];
73
+ const uris = parameter.type === "uri[]" ? value
74
+ : parameter.type === "uri" && typeof value === "string" ? [value] : undefined;
75
+ for (const [index, uri] of (uris ?? []).entries()) {
76
+ if (!uri.startsWith("file:"))
77
+ remoteMedia(uri, parameter.type === "uri[]" ? `${parameter.name}/${index}` : parameter.name);
78
+ }
79
+ }
80
+ }
69
81
  return selected;
70
82
  });
71
83
  const { model: ignoredModel, ...parameters } = input.arguments;
@@ -75,6 +87,11 @@ export function createToolUseCases(dependencies) {
75
87
  model_id: model.model,
76
88
  parameters
77
89
  });
90
+ if (model.execution?.kind === "canvas") {
91
+ const usage = { model: model.model, ...(model.cost === undefined || hasCanvasMetering(model) ? {} : { cost: model.cost }) };
92
+ await observe?.({ toolUsage: usage, generation: { tool: model.tool, model: model.model } });
93
+ return { invocation: { kind: "canvas", model, arguments: input.arguments }, usage };
94
+ }
78
95
  const prompt = [];
79
96
  const requestParameters = {};
80
97
  const directArguments = {};
@@ -166,14 +183,22 @@ export function createToolUseCases(dependencies) {
166
183
  return projectModelList(await load(access, signal), input.tool, dependencies.tools ?? defaultToolDefinitions);
167
184
  },
168
185
  async getModel({ input, access, signal }) {
169
- return projectModelDetail(await load(access, signal), input.model);
186
+ return projectModelDetail(await load(access, signal), input.model, input.tool);
170
187
  },
171
188
  async getArgumentsSchema({ name, access, signal }) {
172
189
  return buildToolArgumentsSchema(await load(access, signal), name, dependencies.modelDescription);
173
190
  },
174
191
  async call(input) {
175
- const { invocation, usage } = await prepare(input);
176
- const content = await dependencies.execution.execute({ invocation, access: input.access, signal: input.signal, ...(input.observe ? { observe: input.observe } : {}) });
192
+ const prepared = await prepare(input);
193
+ const { invocation } = prepared;
194
+ let usage = prepared.usage;
195
+ const observe = async (progress) => {
196
+ if (progress.toolUsage)
197
+ usage = progress.toolUsage;
198
+ await input.observe?.(progress);
199
+ };
200
+ const observer = invocation.kind === "canvas" ? observe : input.observe;
201
+ const content = await dependencies.execution.execute({ invocation, access: input.access, signal: input.signal, ...(observer ? { observe: observer } : {}) });
177
202
  return { content, usage };
178
203
  },
179
204
  async submit(input) {
@@ -9,10 +9,12 @@ import { readInstallationOwner } from "../../platform/installation-owner.js";
9
9
  export class UpdateError extends Error {
10
10
  code;
11
11
  nextSteps;
12
- constructor(code, message, nextSteps, cause) {
12
+ diagnosticReason;
13
+ constructor(code, message, nextSteps, cause, diagnosticReason) {
13
14
  super(message, { cause });
14
15
  this.code = code;
15
16
  this.nextSteps = nextSteps;
17
+ this.diagnosticReason = diagnosticReason;
16
18
  this.name = "UpdateError";
17
19
  }
18
20
  get details() {
@@ -73,7 +75,7 @@ export function createUpdateService(options) {
73
75
  ? "This insMind CLI installation is managed by WorkBuddy."
74
76
  : "此 gd-cli 由 WorkBuddy 连接器管理。", [insmind
75
77
  ? "Update the insMind connector in WorkBuddy."
76
- : "请在 WorkBuddy 中更新「稿定」连接器。"]);
78
+ : "请在 WorkBuddy 中更新「稿定」连接器。"], undefined, "UPDATE_MANAGED_BY_HOST");
77
79
  }
78
80
  if (owner === "invalid") {
79
81
  throw new UpdateError("UPDATE_FAILED", insmind
@@ -118,6 +118,18 @@ async function acquireFileLock(path, run, options) {
118
118
  if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) {
119
119
  // Only our finished owner is retired. Old clients also ignore this suffix.
120
120
  await rename(ownPath, `${ownPath}.released`).catch(cause => {
121
+ // A host may have removed the source before throwing from unlink.
122
+ // Verify our own owner is gone; ENOENT on the rename alone can also
123
+ // mean the destination directory disappeared.
124
+ if (cause instanceof Error && "code" in cause && cause.code === "ENOENT") {
125
+ return readFile(ownPath).then(() => {
126
+ releaseErrors.push(new AggregateError([error, cause], "Cannot retire the local lock owner."));
127
+ }, verification => {
128
+ if (!(verification instanceof Error && "code" in verification && verification.code === "ENOENT")) {
129
+ releaseErrors.push(new AggregateError([error, cause, verification], "Cannot verify the local lock owner."));
130
+ }
131
+ });
132
+ }
121
133
  releaseErrors.push(new AggregateError([error, cause], "Cannot retire the local lock owner."));
122
134
  });
123
135
  }
@@ -4,10 +4,12 @@ import { join } from "node:path";
4
4
  export class LocalFileError extends Error {
5
5
  file;
6
6
  reason;
7
- constructor(cause, file, reason = "io") {
7
+ diagnostic;
8
+ constructor(cause, file, reason = "io", diagnostic) {
8
9
  super("无法访问本地状态文件。", { cause });
9
10
  this.file = file;
10
11
  this.reason = reason;
12
+ this.diagnostic = diagnostic;
11
13
  this.name = "LocalFileError";
12
14
  }
13
15
  }
@@ -19,10 +21,14 @@ export function createLocalJsonFile(options) {
19
21
  let handle;
20
22
  let failed = false;
21
23
  let primaryError;
24
+ let step = "directory_permissions";
22
25
  try {
23
26
  await fileSystem.chmod(options.directory, 0o700);
27
+ step = "open";
24
28
  handle = await fileSystem.open(path, "r");
29
+ step = "file_permissions";
25
30
  await handle.chmod(0o600);
31
+ step = "read";
26
32
  return await handle.readFile("utf8");
27
33
  }
28
34
  catch (cause) {
@@ -30,7 +36,7 @@ export function createLocalJsonFile(options) {
30
36
  return null;
31
37
  failed = true;
32
38
  primaryError = cause;
33
- throw new LocalFileError(cause, options.filename);
39
+ throw new LocalFileError(cause, options.filename, "io", { operation: "read", step });
34
40
  }
35
41
  finally {
36
42
  try {
@@ -39,28 +45,36 @@ export function createLocalJsonFile(options) {
39
45
  catch (cause) {
40
46
  throw new LocalFileError(failed
41
47
  ? new AggregateError([primaryError, cause], "Cannot read and close local state.", { cause: primaryError })
42
- : cause, options.filename);
48
+ : cause, options.filename, "io", { operation: "read", step: failed ? step : "close" });
43
49
  }
44
50
  }
45
51
  },
46
52
  async writeTextAtomically(value) {
47
53
  const temporaryPath = join(options.directory, `${options.filename}.tmp-${randomUUID()}`);
48
54
  let handle;
55
+ let step = "directory_create";
49
56
  try {
50
57
  await fileSystem.mkdir(options.directory, { mode: 0o700, recursive: true });
58
+ step = "directory_permissions";
51
59
  await fileSystem.chmod(options.directory, 0o700);
60
+ step = "open";
52
61
  handle = await fileSystem.open(temporaryPath, "wx", 0o600);
62
+ step = "file_permissions";
53
63
  await handle.chmod(0o600);
64
+ step = "write";
54
65
  await handle.writeFile(value, "utf8");
66
+ step = "sync";
55
67
  await handle.sync();
68
+ step = "close";
56
69
  await handle.close();
57
70
  handle = undefined;
71
+ step = "rename";
58
72
  await fileSystem.rename(temporaryPath, path);
59
73
  }
60
74
  catch (cause) {
61
75
  await handle?.close().catch(() => undefined);
62
76
  await fileSystem.unlink(temporaryPath).catch(() => undefined);
63
- throw new LocalFileError(cause, options.filename);
77
+ throw new LocalFileError(cause, options.filename, "io", { operation: "write", step });
64
78
  }
65
79
  },
66
80
  async remove() {
@@ -69,7 +83,7 @@ export function createLocalJsonFile(options) {
69
83
  }
70
84
  catch (cause) {
71
85
  if (!isMissing(cause))
72
- throw new LocalFileError(cause, options.filename);
86
+ throw new LocalFileError(cause, options.filename, "io", { operation: "remove", step: "unlink" });
73
87
  }
74
88
  }
75
89
  };
@@ -3,8 +3,10 @@ import { open, realpath, stat } from "node:fs/promises";
3
3
  import { basename, extname, sep } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  export class LocalFileInputError extends Error {
6
- constructor(cause) {
6
+ reason;
7
+ constructor(cause, reason = "file_read_failed") {
7
8
  super("本地文件不可用于上传。", { cause });
9
+ this.reason = reason;
8
10
  this.name = "LocalFileInputError";
9
11
  }
10
12
  }
@@ -50,16 +52,15 @@ const mediaTypes = {
50
52
  webm: "video/webm",
51
53
  webp: "image/webp"
52
54
  };
53
- function reject() {
54
- throw new LocalFileInputError();
55
+ function reject(reason) {
56
+ throw new LocalFileInputError(undefined, reason);
55
57
  }
56
58
  function assertSafePath(filePath) {
57
59
  const segments = filePath.split(sep).filter(Boolean).map((segment) => segment.toLowerCase());
58
60
  const filename = segments.at(-1) ?? "";
59
- if (protectedFilenames.has(filename) || /^\.env(?:\.|$)/.test(filename))
60
- reject();
61
- if (segments.some((segment) => segment.startsWith(".") || protectedSegments.has(segment))) {
62
- reject();
61
+ if (protectedFilenames.has(filename) || filename.startsWith(".")
62
+ || segments.some(segment => protectedSegments.has(segment))) {
63
+ reject("path_restricted");
63
64
  }
64
65
  }
65
66
  function detectedFormat(header) {
@@ -113,18 +114,25 @@ export async function inspectUploadFile(input) {
113
114
  assertSafePath(filePath);
114
115
  const details = await stat(filePath);
115
116
  if (!details.isFile())
116
- return reject();
117
+ return reject("not_regular_file");
117
118
  const header = await readHeader(filePath, input.signal);
118
119
  const detected = detectedFormat(header);
120
+ // Hidden host/workspace ancestors are not themselves secrets. Only known
121
+ // media headers may pass there; named credential paths remain blocked on
122
+ // both requested and canonical paths before any file is opened.
123
+ if (input.allowSensitivePath !== true && detected === undefined
124
+ && [requestedPath, filePath].some(path => path.split(sep).some(segment => segment.startsWith(".")))) {
125
+ return reject("path_restricted");
126
+ }
119
127
  const extension = extname(requestedPath).slice(1).toLowerCase();
120
128
  const format = detected ?? (extension === "jpg" ? "jpeg" : extension);
121
129
  if (format === "")
122
- return reject();
130
+ return reject("format_missing");
123
131
  const detectedMediaType = detected === undefined ? undefined : mediaTypes[detected];
124
132
  if (detectedMediaType !== undefined
125
133
  && input.claimedMediaType !== undefined
126
134
  && input.claimedMediaType.trim().toLowerCase() !== detectedMediaType) {
127
- return reject();
135
+ return reject("media_type_mismatch");
128
136
  }
129
137
  return {
130
138
  filePath,
@@ -1,5 +1,50 @@
1
- export function validationIssues(errors) {
2
- return (errors ?? []).slice(0, 8).map(error => ({
1
+ export function validationIssues(errors, value, schema) {
2
+ let selected = errors ?? [];
3
+ const at = (root, pointer) => pointer.replace(/^#\/?/u, "").split("/").filter(Boolean)
4
+ .reduce((node, key) => node && typeof node === "object" ? node[key.replace(/~1/gu, "/").replace(/~0/gu, "~")] : undefined, root);
5
+ const unions = [];
6
+ const visit = (node) => {
7
+ if (!node || typeof node !== "object")
8
+ return;
9
+ if ("oneOf" in node && Array.isArray(node.oneOf))
10
+ unions.push(node.oneOf);
11
+ for (const child of Object.values(node))
12
+ visit(child);
13
+ };
14
+ visit(schema);
15
+ for (const union of errors ?? []) {
16
+ if (union.keyword !== "oneOf")
17
+ continue;
18
+ // AJV may emit #/oneOf for an inlined $ref. Recover that group only when
19
+ // its referenced branches are evidenced at this exact input location.
20
+ const branches = at(schema, union.schemaPath) ?? unions.find(group => group.every(branch => branch && typeof branch === "object" && "$ref" in branch && typeof branch.$ref === "string"
21
+ && selected.some(error => (error.instancePath === union.instancePath || error.instancePath.startsWith(`${union.instancePath}/`))
22
+ && error.schemaPath.startsWith(`${branch.$ref}/`))));
23
+ const input = at(value, union.instancePath);
24
+ if (!Array.isArray(branches) || !input || typeof input !== "object")
25
+ continue;
26
+ const refs = branches.map(branch => typeof branch?.$ref === "string" && branch.$ref.startsWith("#/") ? branch.$ref : undefined);
27
+ if (refs.some(ref => !ref))
28
+ continue;
29
+ const matches = refs.filter(ref => {
30
+ const branch = at(schema, ref);
31
+ if (!branch || !Array.isArray(branch.required) || !branch.required.length)
32
+ return false;
33
+ return branch.required.every(key => typeof key === "string" && Object.hasOwn(input, key))
34
+ && Object.entries(branch.properties ?? {}).every(([key, property]) => !Object.hasOwn(property, "const")
35
+ || input[key] === property.const);
36
+ });
37
+ if (matches.length !== 1)
38
+ continue;
39
+ const blocked = refs.filter(ref => ref !== matches[0]);
40
+ selected = selected.filter(error => {
41
+ if (error === union)
42
+ return false;
43
+ const related = error.instancePath === union.instancePath || error.instancePath.startsWith(`${union.instancePath}/`);
44
+ return !related || !blocked.some(ref => error.schemaPath.startsWith(`${ref}/`));
45
+ });
46
+ }
47
+ return selected.slice(0, 8).map(error => ({
3
48
  field: `${error.instancePath}${typeof error.params.missingProperty === "string" ? `/${error.params.missingProperty}`
4
49
  : typeof error.params.additionalProperty === "string" ? `/${error.params.additionalProperty}` : ""}`.slice(0, 256) || "/",
5
50
  rule: error.keyword,
@@ -1,9 +1,22 @@
1
1
  import { Writable } from "node:stream";
2
+ export class OutputStreamError extends Error {
3
+ outputStream;
4
+ constructor(outputStream, cause) {
5
+ super("结果未能完整返回。", { cause });
6
+ this.outputStream = outputStream;
7
+ this.name = "OutputStreamError";
8
+ }
9
+ }
2
10
  /** Writes remain synchronous for command presenters; flush acknowledges delivery. */
3
- export function createTextOutput(stream) {
11
+ export function createTextOutput(stream, outputStream = "stdout") {
4
12
  if (!(stream instanceof Writable))
5
13
  return {
6
- write: text => { stream.write(text); }, flush: async () => { }
14
+ write: text => { try {
15
+ stream.write(text);
16
+ }
17
+ catch (cause) {
18
+ throw new OutputStreamError(outputStream, cause);
19
+ } }, flush: async () => { }
7
20
  };
8
21
  const pending = new Set();
9
22
  let failure;
@@ -11,7 +24,7 @@ export function createTextOutput(stream) {
11
24
  return {
12
25
  write(text) {
13
26
  if (failure)
14
- throw failure;
27
+ throw new OutputStreamError(outputStream, failure);
15
28
  const writing = new Promise(resolve => {
16
29
  try {
17
30
  stream.write(text, error => { failure ??= error ?? undefined; resolve(); });
@@ -27,7 +40,7 @@ export function createTextOutput(stream) {
27
40
  async flush() {
28
41
  await Promise.all(pending);
29
42
  if (failure)
30
- throw failure;
43
+ throw new OutputStreamError(outputStream, failure);
31
44
  }
32
45
  };
33
46
  }
@@ -75,6 +75,17 @@ export const insmindProduct = freezeProduct({
75
75
  name: "video.generate",
76
76
  title: "Video generation",
77
77
  description: "Generate videos with published video models using text and optional images, video, or audio."
78
- }
78
+ },
79
+ { "name": "image.edit", "title": "Image editing", "description": "Change a selected area or edit an image from instructions." },
80
+ { "name": "image.matting", "title": "Background removal", "description": "Separate original foreground pixels or reconstruct an occluded subject, returning a transparent PNG." },
81
+ { "name": "image.remove", "title": "Object removal", "description": "Remove selected or described content from an image." },
82
+ { "name": "image.enhance", "title": "Image enhancement", "description": "Upscale pixels or restore image details." },
83
+ { "name": "image.expand", "title": "Image expansion", "description": "Extend a canvas with explicit source placement." },
84
+ { "name": "image.text_edit", "title": "Image text editing", "description": "Replace specified text in an image." },
85
+ { "name": "image.ocr", "title": "Text recognition", "description": "Recognize text and its pixel coordinates." },
86
+ { "name": "image.layers", "title": "Image decomposition", "description": "Convert an image to an editable native template." },
87
+ { "name": "image.vectorize", "title": "Image vectorization", "description": "Convert a bitmap to vector SVG." },
88
+ { "name": "video.edit", "title": "Video editing", "description": "Edit a video using instructions and optional references." },
89
+ { "name": "video.enhance", "title": "Video enhancement", "description": "Upscale or restore a video." }
79
90
  ]
80
91
  });
@@ -2,6 +2,11 @@ const flags = new Set(["bodyUsedAtReceipt", "bodyLockedAtReceipt", "bodyUsedBefo
2
2
  "bodyLockedBeforeRead", "reusedResponse", "contextIdPresent", "streamHadBytes"]);
3
3
  const counts = new Set(["messageCount", "invalidMessageCount", "systemErrorCount", "publicPartCount",
4
4
  "streamPayloadCount", "streamJsonValueCount"]);
5
+ const localFileSteps = new Set(["directory_create", "directory_permissions", "directory_read", "stat", "parse", "validate", "open", "file_permissions", "read", "write", "sync", "close", "rename", "unlink"]);
6
+ const inputReasons = new Set(["path_restricted", "not_regular_file", "format_missing", "media_type_mismatch", "file_read_failed",
7
+ "json_read", "json_parse", "schema_validation", "invalid_task_id", "command_arguments", "model_required", "model_not_found",
8
+ "model_tool_mismatch", "model_parameters", "tool_not_found", "invalid_asset_url", "commander.unknownOption",
9
+ "commander.unknownCommand", "commander.missingArgument", "commander.excessArguments", "commander.help"]);
5
10
  /** Fixed diagnostic facts, never arbitrary response fields or error messages. */
6
11
  export function safeFailureSummary(value) {
7
12
  if (!value || typeof value !== "object" || Array.isArray(value))
@@ -12,6 +17,19 @@ export function safeFailureSummary(value) {
12
17
  result[key] = field;
13
18
  if (counts.has(key) && typeof field === "number" && Number.isSafeInteger(field) && field >= 0 && field <= 100_000)
14
19
  result[key] = field;
20
+ if (key === "inputReason" && typeof field === "string" && inputReasons.has(field))
21
+ result[key] = field;
22
+ if (key === "ssoPhase" && (field === "authorize" || field === "token"))
23
+ result[key] = field;
24
+ if (key === "outputStream" && (field === "stdout" || field === "stderr"))
25
+ result[key] = field;
26
+ if (key === "localFileOperation" && (field === "read" || field === "write" || field === "remove" || field === "list"))
27
+ result[key] = field;
28
+ if (key === "localFileStep" && typeof field === "string" && localFileSteps.has(field))
29
+ result[key] = field;
30
+ if (key === "ssoInvalidFields" && typeof field === "string"
31
+ && /^(?:authorize_code|device_code|expires_in|interval|ak|sk|expires_at|scope)(?:,(?:authorize_code|device_code|expires_in|interval|ak|sk|expires_at|scope))*$/u.test(field))
32
+ result[key] = field;
15
33
  if (key === "systemCode" && typeof field === "string"
16
34
  && /^(?:E[A-Z0-9_]{1,40}|UND_ERR_[A-Z0-9_]{1,40}|LOCAL_LOCK_TIMEOUT)$/u.test(field))
17
35
  result[key] = field;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaoding/cli",
3
- "version": "1.7.1",
3
+ "version": "1.9.0",
4
4
  "description": "Gaoding command-line interface for agents and people.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,6 +35,7 @@
35
35
  "prepare:tracker": "node scripts/prepare-gd-tracker.mjs"
36
36
  },
37
37
  "dependencies": {
38
+ "@ffprobe-installer/ffprobe": "2.1.2",
38
39
  "ajv": "8.20.0",
39
40
  "ajv-formats": "3.0.1",
40
41
  "ali-oss": "6.23.0",
@@ -56,8 +57,8 @@
56
57
  "vitest": "4.1.10"
57
58
  },
58
59
  "gaodingRelease": {
59
- "sourceCommit": "53aa55169df83ca3437874f7d002c741b694be76",
60
- "pipelineId": "229607",
61
- "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/229607"
60
+ "sourceCommit": "2836058427780a95d4b9ed152f122b81997df34e",
61
+ "pipelineId": "231960",
62
+ "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/231960"
62
63
  }
63
64
  }
@@ -17,6 +17,8 @@ description: Use when creating images, videos or text with GD CLI, operating the
17
17
  按用户目标只读取对应参考:
18
18
 
19
19
  - 按业务意图选择 Agent / Tool 创作路由、发现 Model 并生成图片、视频或文本:[创作](references/creation.md)
20
+ - 选择图片/视频生成或专用处理工具、准备参考素材及复核 mask:[图片与视频工具选择](references/media-tools.md)
21
+ - 去背景、提取主体、透明 PNG,或补全被遮挡的物体:[抠图](references/matting.md)
20
22
  - 操作当前 AI+ Editor 作品:[编辑器](references/editor.md)
21
23
  - 发现资源库、文件夹与标签,查询、上传、下载或管理 DAM 资源:[素材管理](references/dam.md)
22
24
  - 登录或选择组织:[登录与组织](references/auth-org.md)
@@ -19,6 +19,8 @@
19
19
  - Agent:用户要的是业务交付物,或过程需要澄清、规划、多步骤、多产物或继续已有创作。下列十类业务意图通常优先走 Agent;它们只帮助选择 Creation Route,具体 Business Skill 由服务端 Agent 选择。
20
20
  - Tool:任务是一个无需业务编排的原子单次调用,具体能力由 `tool list` 发现;或用户明确要求直接调用可用 Tool。
21
21
 
22
+ 选择 Tool 后,新图/新视频创作、依参考素材整体重创分别以 `image.generate` / `video.generate` 为发现方向;现有媒体的具体处理按 [图片与视频工具选择](media-tools.md) 判断。参考图本身不决定使用 `image.edit`,工具内部有多个处理阶段也不等于用户需要业务 Agent 编排。
23
+
22
24
  业务意图参考(语义匹配,不是只能逐字命中):
23
25
 
24
26
  | 业务意图 | 常见说法 | 素材与边界 |
@@ -1,6 +1,8 @@
1
1
  # 生成约束与媒体角色
2
2
 
3
- 指定 Model 和动态参数时,只增加一个 Generation Constraints Part;`model` 使用 Model 机器标识,`arguments` 的字段和值取自 `model get`,并如实保留用户指定值:
3
+ 指定 Model 和动态参数时,只增加一个 Generation Constraints Part;`model` 使用 Model 机器标识,生成控制项和值取自 `model get`,结合 `agent send --help` 核对 Agent 接受的控制参数范围,并如实保留用户指定值。Model detail 的完整 Tool `inputSchema` 不等于 Agent `arguments` 的字段列表;Tool 的选区、画布、文字替换等执行输入不直接放入生成约束。交给 Agent 规划时,用文本与素材 Part 描述这些任务要求;逐字段直接调用时使用对应 Tool 的 Schema。
4
+
5
+ 生成约束示例:
4
6
 
5
7
  ```json
6
8
  {
@@ -0,0 +1,29 @@
1
+ # 抠图与透明结果
2
+
3
+ 抠图前先区分“保留原图可见像素”与“重新绘制完整主体”。白底图、带棋盘格的图片和真正有透明通道的文件是不同交付物。
4
+
5
+ ## 选择处理方式
6
+
7
+ | 用户目标 | 处理流程 | 交付边界 |
8
+ | --- | --- | --- |
9
+ | 主体完整,只去背景;保留商品结构、文字、人脸或纹理 | 标准抠图:从原图分离前景,保留可见主体 | 不补出原图看不到的部位;细边、毛发、半透明材质和遮挡需复查 |
10
+ | 提取被遮挡的物品,并补全被挡部分;从复杂画面中重新呈现指定主体 | 用户允许重建时,先用参考图重绘主体,再对重绘图做标准抠图 | 补全内容是生成推测,可能改变结构和纹理;不能称为原物的精确恢复 |
11
+
12
+ 仅有背景复杂并不等于必须重绘。用户要求保真、不能重绘时,优先标准抠图;效果不足就说明限制或请求更完整的原图,不能自行改为 AI 重建。用户明确要补全被挡主体时,可按其要求执行重建。
13
+
14
+ ## 发现能力与执行
15
+
16
+ 1. 按 [创作](creation.md) 发现当前 Tool 和 Model,读取相关 `--help`、公开 Schema 和选定 Model detail。确认该能力交付透明图,还是只交付中间重绘图;模型标题中的“抠图”不能替代输出契约。模型、参数与费用以当前地区和组织的查询结果为准。
17
+ 2. 标准抠图与已包含重绘/分割的智能抠图都可作为原子 [Tool](tool.md);用户需要业务规划、多步骤编排或多产物时再选 [Agent](agent.md)。有 mask 时先按 [选区复核](media-tools.md#提交前复核-mask) 查看原图、mask 及叠加预览。不能把未公开的算法接口、编辑器入口或历史测试套件名称当成 CLI Model。
18
+ 3. 输入必须使用本次指定的原图。AI 重建时明确主体、需要补全部位、必须保留的结构与比例;若选定的智能抠图已承诺交付透明 PNG,直接验收最终文件,避免再调用一次标准抠图。仅在模型只交付重绘图时才另做分割。不要继续对原始遮挡图做第二步,也不要使用上一次结果的尺寸代替当前图片尺寸。
19
+ 4. 当前 CLI 没有可发现的透明抠图能力时,明确说明缺口。不要用“生成透明背景”的提示词、白底图或棋盘格图替代用户要求,也不要调用内部接口绕过产品权益结算。已完成的重绘图可作为中间产物交付,但必须说明透明步骤未完成。
20
+
21
+ 重建提示词的结构可以是:“以参考图中的〔指定主体〕为依据,补全〔被遮挡部位〕,保持〔可见结构、纹理、比例〕。主体完整、边缘清楚,置于易分离的纯色背景,不画棋盘格、不添加文字或其他物品。”具体约束来自用户;提示词本身不会产生真正的 alpha 通道。
22
+
23
+ ## 验收与交付
24
+
25
+ - 由调用 Agent 或用户下载实际输出,查看真实格式、尺寸和透明区域;扩展名、MIME 声明和模型文字说明不能证明抠图效果。透明背景与有效主体都要结合画面判断,不能只检查“存在 alpha”。alpha 最大值不必等于 255;毛发、玻璃和阴影可合理半透明,不按最大值设通过阈值或自动拉满透明度。
26
+ - 在明暗两种底色上检查边缘、孔洞、毛发与半透明区域,确认没有烘焙棋盘格、明显背景残留或误删主体。保持原尺寸或裁到主体边缘按用户要求处理。
27
+ - AI 重建另外对比商品结构、标识、人物身份和可见细节;说明哪些部位是生成补全,不能承诺像素级一致。
28
+ - 使用结果文件或已授权下载链接交付。只完成重绘或拿到蒙版时,不宣布透明抠图完成;保留可用中间结果和未完成步骤。
29
+ - 多阶段生成按各次真实用量解释费用,估算不当实扣。任务已受理后中断、超时或后处理失败时,先按 [错误处理](errors.md) 查询原任务,不能为拿到透明图而盲目重做已完成的收费生成。
@@ -0,0 +1,40 @@
1
+ # 图片与视频处理
2
+
3
+ 先按 [创作](creation.md) 判断 Agent / Tool 路由。以下选择适用于单次 Tool 任务;业务编排仍交给 Agent,用户明确指定的路线与模型优先。
4
+
5
+ ## 按目的选择 Tool
6
+
7
+ | 用户目标 | 发现方向 |
8
+ | --- | --- |
9
+ | 生成新图,依参考图重新创作、整体换风格或融合多图 | `image.generate`;有参考图或使用“改”字不等于必须走 `image.edit` |
10
+ | 生成新视频,包括文生、图生、首尾帧或参考素材生成 | `video.generate`;具体素材组合看所选模型 Schema |
11
+ | 在现有图片上做有明确目标或选区的编辑 | `image.edit` |
12
+ | 去背景、消除物体、修复清晰度、扩画布、改字/识字、分层或转矢量 | 按目的查询相应专用 Tool;不把全部图片操作归为 `image.edit` |
13
+ | 以已有视频为主体修改内容,或提升已有视频清晰度 | 分别查询 `video.edit` 或 `video.enhance`;从图片生成视频仍属 `video.generate` |
14
+
15
+ 查询 `tool list`,再按相关 Tool 查询 `model list --tool <tool>` 与 `model get <model> --tool <tool>`。读取完整 `inputSchema`、用途与费用;模型可用性、参数及档位以本次查询为准。不能把某个模型的字段套到另一 Tool。
16
+
17
+ ## 选择模型与准备素材
18
+
19
+ 读取公开模型标识及用途,不依赖后端展示名称做字符串匹配。“标准”和“智能”是稳定的公开分类,但每个工具的具体差异仍看模型详情:标准抠图分离原图可见像素,智能抠图先重绘补全;标准超分和生成式修复的保真边界也不同。标准改图、消除和扩图同样可能生成内容,不能把“标准”理解成所有工具都无损。用户要求保真时核对可保留的范围;重绘可能改变商品结构、文字、人脸或纹理,补全细节是推测。抠图另读 [抠图](matting.md)。
20
+
21
+ 确认本次主图/原视频、修改目标和需保留内容。只带完成任务必需的参考,每张参考明确提供主体、风格、配色或布局中的哪一项;无关参考不上传。Prompt 按“修改对象 → 需要的变化 → 保留内容 → 各参考用途 → 输出要求”组织,取自用户需求与已确认素材。对于只参考风格的图片,说明借鉴范围;通常选语义相关的参考,减少一边提供强主体、一边要求忽略主体的冲突。模型已有的结构化参数放入对应字段。
22
+
23
+ 扩图用自然像素明确目标画布和原图左上角位置,不隐式缩放。主图、选区与参考图各自放入 Schema 指定字段,参考图不能代替 mask。
24
+
25
+ ## 提交前复核 mask
26
+
27
+ 1. 读取所选模型的 mask 说明,确认必填/可选、文件要求及选区语义;按该说明准备与本次原图对应的文件。文件格式合格不代表选区位置正确。
28
+ 2. 实际查看自动转正后的原图和 mask,再将选区叠加到原图上做预览。逐项确认白区覆盖需处理的主体/部位、没有漏选,黑区包含需保护的内容;核对轮廓、孔洞、边缘及坐标,没有平移、拉伸或选到背景。叠加预览只供复核,提交的仍是 Schema 要求的原始 mask。
29
+ 3. 白区须非空;全白仅适用于用户明确要处理全图。局部物体需要对应目标轮廓,不能用随意矩形代替;若用户本来指定矩形区域,则按其区域。发现选错先修正再提交,无法可靠定位时请用户圈选或补充目标。
30
+ 4. 智能模型的可选 mask 可能仅转换成视觉边界提示;按模型详情判断,不能保证选区外像素完全不变。对保护内容有要求时,交付前实际对比。
31
+
32
+ ## 执行与交付
33
+
34
+ 按 [Tool](tool.md) 提交一次并等待同一任务。计量模型先看当前单价与公式;估价不是实扣。未知或中断时查原任务,查询不会补做处理、上传或结算。
35
+
36
+ 结果的视觉/声音效果由调用 Agent 或用户查看,不由 CLI 的效果阈值判通过:改图/消除对比保护区;扩图核对位置及画布;改字核对目标及其他文字;OCR 使用返回识别图坐标;分层检查原生模板和资源;矢量查看实际 SVG 内容;视频查看时长、画面与声音。音轨存在不能证明原声保持。保留服务返回的实际结果,说明观察到的偏差;后续修改按用户授权执行,不因效果不理想自动换模型或重跑。
37
+
38
+ 分层时区分用途:图文分层侧重文字、图片与版式的可编辑结构;智能分层侧重把物件拆成独立图层。层数上限不是实际图层数的保证,不把智能分层当逐字 OCR。交付原生 JSON 及资源,不能称为 PSD。用户要求导入编辑器时,按 [编辑器](editor.md) 发现实际支持的导入/编辑流程,确认可编辑文字、图层与字体替换情况。
39
+
40
+ 多参考改视频时,按模型 Schema 中的素材编号写清每份参考的用途及需保留的原片内容。CLI 会补充原文件名与编号映射;用户文件名在上传后会变化,引用不能只靠下载链接中的文件名判断。
@@ -7,16 +7,16 @@
7
7
  ```bash
8
8
  gd-cli tool list
9
9
  gd-cli model list --tool <tool>
10
- gd-cli model get <model>
10
+ gd-cli model get <model> --tool <tool>
11
11
  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` 的 `parameters` 是所选 Model 的实际调用元数据:遵循 `required`、`type`、`description`,SELECT 参数使用 `options[].value`,required 参数带 `default` 时在用户未指定时显式传入默认值。`usageDescription` 描述跨字段规则,例如视频 mode 对首尾帧或素材字段的要求;这类组合不能只从单个字段推断。不要把列表值固化在提示或脚本中。
15
+ `tool list` 给出可用 Tool;`model list` 和 `model get` 给出当前可用 Model、说明、费用、预估耗时和结构化参数。`model get` 的 `inputSchema` 是完整模型输入契约,包含嵌套对象、数组和条件;`parameters` 是摘要元数据:遵循 `required`、`type`、`description`,SELECT 参数使用 `options[].value`,required 参数带 `default` 时在用户未指定时显式传入默认值。`usageDescription` 描述跨字段规则,例如视频 mode 对首尾帧或素材字段的要求;这类组合不能只从单个字段推断。不要把列表值固化在提示或脚本中。
16
16
 
17
- 按所选 Model detail 构造 JSON:提供全部 required 字段;SELECT 参数使用 `options[].value`;required 字段带 default 且用户未指定时,在输入中显式使用该 default。存在 width、height、resolution 等专用字段时,将用户要求写入对应结构化参数,不要只写在 prompt 中。`tool call <tool> --schema` 返回整个 Tool 下所有 Model 的参数并集,只用于 Tool 级发现;选定 Model 后以 `model get` 的参数和 `usageDescription` 为准。
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`。
18
18
 
19
- 务必将 `model get <model>` 返回的 `model` 原样放在请求 JSON 的顶层 `model` 字段(即运行时的 `arguments.model`),与所选 Model 的参数字段并列;不要只复制 `parameters`。例如:
19
+ 务必将 `model get <model> --tool <tool>` 返回的 `model` 原样放在请求 JSON 的顶层 `model` 字段(即运行时的 `arguments.model`),与所选 Model 的参数字段并列;不要只复制 `parameters`。例如:
20
20
 
21
21
  ```json
22
22
  {
@@ -26,6 +26,6 @@ gd-cli task get <taskId>
26
26
  }
27
27
  ```
28
28
 
29
- 同步输出(或异步任务 completed 时的 result)包含 `content` 和 `usage`。`content` 是文本或资源链接;`usage` 包含所选模型及模型目录公布的稿豆价格区间,不表示实际扣费。
29
+ 同步输出(或异步任务 completed 时的 result)包含 `content` 和 `usage`。`content` 是文本、资源链接或带 JSON 文本的内嵌资源;`usage` 包含所选模型及模型目录公布的稿豆价格区间,不表示实际扣费。
30
30
 
31
31
  交付多个资源时,将每个资源链接、返回名称、本地保存路径和展示名称作为一条记录一起处理;下载、重命名或调整顺序时保持对应,不按请求中的顺序重新配对。交付前核对每个最终链接的文件内容与名称一致;名称不足以辨认时查看资源内容。