@gaoding/cli 3.0.1 → 3.0.3

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 (54) hide show
  1. package/README.md +7 -3
  2. package/contracts/operations/agent.send/input.schema.json +1 -1
  3. package/contracts/operations/credits.get/output.schema.json +3 -3
  4. package/contracts/operations/dam.copy/input.schema.json +3 -3
  5. package/contracts/operations/dam.copy/output.schema.json +1 -1
  6. package/contracts/operations/dam.list/output.schema.json +2 -2
  7. package/contracts/operations/dam.move/input.schema.json +3 -3
  8. package/contracts/operations/dam.search/output.schema.json +2 -2
  9. package/contracts/operations/feedback.submit/input.schema.json +231 -0
  10. package/contracts/operations/feedback.submit/output.schema.json +29 -0
  11. package/contracts/operations/task.get/output.schema.json +2 -2
  12. package/contracts/presentations/task.get.schema.json +2 -2
  13. package/dist/bin/gd-cli.js +1 -6
  14. package/dist/bin/insmind-cli.js +1 -6
  15. package/dist/src/bootstrap/create-cli.js +34 -19
  16. package/dist/src/bootstrap/create-runtime.js +13 -2
  17. package/dist/src/bootstrap/run-task-worker.js +6 -2
  18. package/dist/src/bootstrap/validators.js +1 -8
  19. package/dist/src/cli/agent-commands.js +7 -6
  20. package/dist/src/cli/dam-commands.js +14 -6
  21. package/dist/src/cli/errors.js +23 -6
  22. package/dist/src/cli/feedback-command.js +31 -0
  23. package/dist/src/cli/model-commands.js +4 -4
  24. package/dist/src/cli/skill-output.js +13 -4
  25. package/dist/src/cli/task-commands.js +3 -2
  26. package/dist/src/cli/tool-commands.js +12 -5
  27. package/dist/src/cli/update-command.js +3 -3
  28. package/dist/src/contracts/creation-input.js +0 -3
  29. package/dist/src/features/dam/file-downloader.js +19 -9
  30. package/dist/src/features/dam/operation-executor.js +2 -0
  31. package/dist/src/features/dam/use-cases.js +53 -29
  32. package/dist/src/features/feedback/submit.js +86 -0
  33. package/dist/src/features/skill/catalog.js +17 -1
  34. package/dist/src/features/skill/manual.js +37 -31
  35. package/dist/src/features/task/store.js +7 -0
  36. package/dist/src/features/task/use-cases.js +66 -10
  37. package/dist/src/features/update/check-schema.js +22 -16
  38. package/dist/src/features/update/update-notification.js +8 -4
  39. package/dist/src/features/update/update-service.js +37 -16
  40. package/dist/src/telemetry/command-routes.json +1 -1
  41. package/dist/src/telemetry/invocation.js +8 -4
  42. package/dist/src/telemetry/process-errors.js +7 -2
  43. package/dist/src/telemetry/sanitize.js +18 -7
  44. package/dist/src/telemetry/sls-sink.js +38 -15
  45. package/package.json +7 -7
  46. package/skills/gd-cli/SKILL.md +2 -2
  47. package/dist/src/features/editor/bridge-client.js +0 -107
  48. package/dist/src/features/editor/bridge-process.js +0 -237
  49. package/dist/src/features/editor/bridge-server.js +0 -339
  50. package/dist/src/features/editor/protocol.js +0 -1
  51. package/dist/src/features/editor/public-url.js +0 -1
  52. package/dist/src/features/editor/session-state.js +0 -81
  53. package/dist/src/features/editor/session.js +0 -232
  54. package/dist/src/features/editor/use-cases.js +0 -118
@@ -57,6 +57,7 @@ export function createContractValidators(options = {}) {
57
57
  }
58
58
  const unavailable = assertion(() => unavailableValidator, OutputContractError);
59
59
  return {
60
+ feedbackInput: input("feedback.submit"),
60
61
  creditsOutput: output("credits.get"),
61
62
  creditsUsageListOutput: output("credits.usage.list"),
62
63
  creditsUsageGetOutput: output("credits.usage.get"),
@@ -90,14 +91,6 @@ export function createContractValidators(options = {}) {
90
91
  damMoveOutput: output("dam.move"),
91
92
  damCopyInput: input("dam.copy"),
92
93
  damCopyOutput: output("dam.copy"),
93
- editorConnectInput: input("editor.connect"),
94
- editorConnectOutput: output("editor.connect"),
95
- editorDisconnectOutput: output("editor.disconnect"),
96
- editorSnapshotOutput: output("editor.snapshot"),
97
- editorApplyInput: input("editor.apply"),
98
- editorApplyOutput: output("editor.apply"),
99
- editorScreenshotOutput: output("editor.screenshot"),
100
- editorSaveOutput: output("editor.save"),
101
94
  toolListOutput: output("tool.list"),
102
95
  modelListInput: input("model.list"),
103
96
  modelListOutput: output("model.list"),
@@ -1,4 +1,4 @@
1
- import { skillOutput, writeSkillResult } from "./skill-output.js";
1
+ import { skillOutput, writeSkillResult, writeTaskResult } from "./skill-output.js";
2
2
  import { creationTaskHelp } from "./creation-help.js";
3
3
  import { hostSchema, readHostInput } from "./host-input.js";
4
4
  import { readAgentInputSchema } from "../contracts/creation-input.js";
@@ -17,14 +17,14 @@ export function registerAgentCommands(program, runtime) {
17
17
  .allowExcessArguments(false);
18
18
  send.addHelpText("after", [
19
19
  "",
20
- text(runtime.product, "用于业务策划、多步骤或持续创作;明确的单次媒体处理也可从 tool list 发现。先保存完整 JSON 再用 --input request.json 执行;--input - 必须在同一条 shell 命令中经管道或重定向提供完整 JSON,不交互填参。", "Use for planning, multiple steps or continuing creation; discover atomic media processing with tool list. Save complete JSON before using --input request.json. With --input -, pipe or redirect complete JSON in the same shell command; input is not an interactive form."),
20
+ text(runtime.product, "用于业务策划、多步骤或持续创作;明确的单次媒体处理也可从 tool list 发现。先保存完整 JSON 再用 --input request.json 执行;--input - 必须在同一条 shell 命令中经管道或重定向提供完整 JSON,不交互填参。", "Use agent send to plan a design, complete a task in several steps, or continue earlier work. For a single media edit, run tool list to find a tool. Save complete JSON before using --input request.json. With --input -, pipe or redirect complete JSON in the same shell command; input is not an interactive form."),
21
21
  text(runtime.product, "完整结果已校验但最终本地记录保存失败时仍返回结果和退出码 0;stderr 警告 task get 可能无法恢复,请保留输出。", "A validated complete result is delivered with exit code 0 even if its final local record cannot be saved; stderr warns that task get may not recover it. Keep the output."),
22
22
  text(runtime.product, "最终错误为 stderr 中的 JSON error 对象;stderr 也可能有进度和警告。中断退出码 130 只表示本地停止等待。", "The final error is a JSON error object on stderr, which may also contain progress and warnings. Exit code 130 means local waiting stopped."),
23
23
  ...creationTaskHelp(runtime.product),
24
24
  text(runtime.product, "本机后台进程终止或关机可能使 Agent 任务变为 unknown。", "If the local background process stops or the machine shuts down, an Agent task may become unknown."),
25
25
  text(runtime.product, "首次创作省略 JSON 中的 message.contextId;续聊时传入上次结果的 message.contextId。", "Omit message.contextId for the first creation. Continue a conversation using message.contextId from the previous result."),
26
- text(runtime.product, "completed 表示本轮 Agent 已完整回复,可能是文本、资源或补充/确认问题,并不保证已生成成品。转述实际回复;需要用户回答时询问用户,收到回答后沿用 contextId 发送下一轮。", "completed means the Agent's turn has fully replied with text, assets or clarification/confirmation questions; it does not guarantee a finished asset. Relay the actual reply, ask the user when an answer is needed, then continue with the same contextId."),
27
- text(runtime.product, "把本轮实际回复或资源连同 usage.cost.amount 的实际消耗一并交付。同步从输出读取,异步从 completed 的 result 读取。返回 0 就报 0,缺失则说明未取得。汇总按不同 taskId,同一任务重复读取只计一次。Tool minimum/maximum 是目录估价。", "Deliver this turn's reply or assets together with the actual charge in usage.cost.amount. Read it from the synchronous output or the completed task's result. Report 0 when present, and unknown when absent. Count each distinct taskId once. Tool minimum/maximum are catalog estimates."),
26
+ text(runtime.product, "completed 表示这一轮已回复。返回正文或作品就交给用户;返回问题就请用户回答,再用原 contextId 继续对话。只有实际收到作品才能说已生成。", "completed means this turn has replied. Deliver returned text or assets; if it asks a question, ask the user and continue with the same contextId. Say an asset was created only when one was returned."),
27
+ text(runtime.product, "交付本轮回复或资源,并说明 usage.cost.amount:同步从输出读取,异步从 completed 的 result 读取。记录完整时按实扣报告;若警告有记录缺少金额,报告已知合计并说明总额待核对、以账单为准,即使已知合计为 0 也不能说免费。未取得金额时说明暂时查不到。不同 taskId 分别汇总,同一任务重复读取只计一次。Tool minimum/maximum 是目录或按输入估价,实扣查对应账单。", "Deliver this turn's reply or assets and explain usage.cost.amount, read from synchronous output or the completed task's result. When records are complete, report the actual charge. If a warning says amounts are missing, report the known subtotal and say the total needs checking against the ledger, even if the subtotal is 0. If no amount is available, say so. Count each taskId once. Tool minimum/maximum are catalog or input-based estimates; check the matching ledger for actual charges."),
28
28
  text(runtime.product, "结构化问题位于 message.parts[].data.questions;回答时将 message.messageId 写入 data.questionMessageId,answers 保留 question 原文及用户 values,该 data Part 是本轮 parts 唯一一项。普通文本续聊使用 text Part。", "Structured questions are in message.parts[].data.questions. Reply with message.messageId as data.questionMessageId and answers containing the original question and the user's values; this data Part must be the sole Part. Use a text Part for ordinary follow-up conversation."),
29
29
  text(runtime.product, "可用 model 和参数示例见 model list / model get。显式 model 和 arguments 会传给 Agent,编辑模型的已知别名转换为服务字段。文本和素材用独立 Part。", "Discover models and example controls with model list and model get. Explicit model and arguments are sent to the Agent, with known editing aliases mapped to service fields. Supply text and assets as separate Parts."),
30
30
  text(runtime.product, "交付服务返回的资源时,原样使用完整 URL 及查询参数;不凭记忆重写、拼接或去掉授权参数。诊断凭证脱敏不改变可交付资源链接。", "Deliver service resources using the complete returned URL and query parameters. Do not reconstruct, splice or strip authorization parameters. Diagnostic credential redaction does not alter delivery links."),
@@ -58,7 +58,7 @@ export function registerAgentCommands(program, runtime) {
58
58
  const result = await runtime.startBackgroundTask({ operation: "agent.send", state: context.state, label: task.label, input }, signal);
59
59
  await runtime.telemetry.stage("output", async () => {
60
60
  runtime.validators.taskResult(result);
61
- await writeSkillResult(runtime, send, result, "agent.send");
61
+ writeTaskResult(runtime, result);
62
62
  });
63
63
  return;
64
64
  }
@@ -67,7 +67,8 @@ export function registerAgentCommands(program, runtime) {
67
67
  access: { credential: context.state.credential, organizationId: context.state.organization.id }, signal });
68
68
  const result = await runtime.tasks.track({ ...task, run });
69
69
  await runtime.telemetry.stage("output", async () => {
70
- await writeSkillResult(runtime, send, result, "agent.send");
70
+ const question = result.message.parts.some(part => "data" in part && part.data && "questions" in part.data);
71
+ await writeSkillResult(runtime, send, result, question ? undefined : "agent.send");
71
72
  });
72
73
  }, {
73
74
  operation: "agent.send",
@@ -3,6 +3,9 @@ import { bindAction, bindPreparedAction } from "./action-binding.js";
3
3
  import { CliUsageError } from "./errors.js";
4
4
  import { repositoryListView } from "./presenter.js";
5
5
  import { productText as text } from "../product/text.js";
6
+ function defaultRepositoryHelp(product) {
7
+ return text(product, "省略 --repository-id 时优先用个人库。目录完整且没有个人库时,用第一项。有些库未能列出且未找到个人库时,请用 dam repository list 查看可用的 ID,再传 --repository-id。", "Without --repository-id, the CLI uses your personal repository if available. If the full list has no personal repository, it uses the first entry. If the list is incomplete and shows no personal repository, choose an ID from dam repository list and pass --repository-id.");
8
+ }
6
9
  export function registerDamCommands(program, runtime) {
7
10
  const dam = program.command("dam")
8
11
  .description(text(runtime.product, "DAM 素材管理", "Asset management"))
@@ -11,7 +14,8 @@ export function registerDamCommands(program, runtime) {
11
14
  "",
12
15
  text(runtime.product, "先通过 repository list、folder list、tag list 或资源查询取得真实 ID,再操作;名称、前端 URL 和旧缓存不能代替 ID。", "Discover real IDs with repository list, folder list, tag list or asset queries before acting; names, frontend URLs and old caches are not IDs."),
13
16
  text(runtime.product, "支持的命令以本 help 为准;读取所选子命令的 --help 获取参数、作用范围和输出形式。", "Available commands are listed here; read the selected subcommand's --help for parameters, scope and output mode."),
14
- text(runtime.product, "资源库 ID 与组织 ID 不同。团队/企业资料显式传查询到的 repository_id;list/search/upload 省略资源库时默认个人库。素材处理使用详情中的资源链接或下载后的本地文件,再从 tool list 发现处理能力。", "Repository IDs differ from organization IDs. Pass a discovered repository_id for team/enterprise assets; list/search/upload default to the personal repository when omitted. To process an asset, use its resource link or downloaded file and discover processing with tool list."),
17
+ defaultRepositoryHelp(runtime.product),
18
+ text(runtime.product, "团队和企业素材请传资源库 ID。处理素材时,用详情中的链接或下载的文件,运行 tool list 查看可用工具。", "For team and enterprise assets, pass the repository ID. To process an asset, use the link from its details or the downloaded file. Run tool list to see available tools."),
15
19
  text(runtime.product, "写入结果未确认时先查询实际状态,不重复提交。跨资源库查询、受保护路径上传和永久删除须有用户明确授权。", "Inspect actual state before retrying an unconfirmed write. Cross-repository queries, protected-path uploads and permanent deletion require explicit user authorization."),
16
20
  ""
17
21
  ].join("\n"));
@@ -295,7 +299,7 @@ export function registerDamCommands(program, runtime) {
295
299
  .option("--allow-sensitive-path", text(runtime.product, "明确允许受保护路径", "allow a protected local path"))
296
300
  .option("--wait-analysis", text(runtime.product, "等待素材分析结束", "wait for asset analysis"))
297
301
  .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
298
- upload.addHelpText("after", text(runtime.product, "\n<file> 是本地文件路径(不是 file URI);路径含空格时按 shell 规则引用。默认上传个人库根目录 0,标题默认取不含扩展名的文件名;团队位置显式传资源库和文件夹 ID。返回素材详情表示已创建;--wait-analysis 额外等待分析,未知写入先查目标位置,不重复上传。\n", "\n<file> is a local path, not a file URI; quote spaces for the shell. Defaults to personal repository root 0 and a title from the filename without its extension. Specify repository/folder IDs for team destinations. Returned asset details confirm creation; --wait-analysis also waits for analysis. Inspect the destination before repeating an unconfirmed upload.\n"));
302
+ upload.addHelpText("after", "\n" + defaultRepositoryHelp(runtime.product) + "\n" + text(runtime.product, "\n<file> 是本地文件路径(不是 file URI);路径含空格时按 shell 规则引用。省略 --folder-id 时上传到所选库的根目录 0。标题默认用去掉扩展名的文件名。返回素材详情表示已创建;--wait-analysis 额外等待分析,未知写入先查目标位置,不重复上传。\n", "\n<file> is a local path, not a file URI; quote spaces for the shell. Omit --folder-id to upload to the selected repository’s root folder (0). The title defaults to the filename without its extension. Returned asset details confirm creation; --wait-analysis also waits for analysis. Inspect the destination before repeating an unconfirmed upload.\n"));
299
303
  bindPreparedAction(upload, "organization", async (signal) => {
300
304
  signal.throwIfAborted();
301
305
  const options = upload.opts();
@@ -329,7 +333,11 @@ export function registerDamCommands(program, runtime) {
329
333
  .argument("<asset>", text(runtime.product, "素材 ID", "asset ID"))
330
334
  .option("--repository-id <id>", text(runtime.product, "所属资源库 ID", "repository ID"))
331
335
  .option("--permanent", text(runtime.product, "移入回收站后永久删除", "permanently delete after moving to trash"));
332
- deleteCommand.addHelpText("after", `\n${text(runtime.product, "默认移入回收站;--permanent 不可恢复,仅在用户明确要求永久删除时使用。支持的回收站操作请查 dam --help,不推断未列出的命令。", "Moves to the recycle bin by default; --permanent is irreversible and requires an explicit request. Consult dam --help for available recycle-bin operations rather than assuming unlisted commands exist.")}\n`);
336
+ deleteCommand.addHelpText("after", [
337
+ "", defaultRepositoryHelp(runtime.product),
338
+ text(runtime.product, "先用 dam repository list 核对素材所在的库,再移入回收站。只有用户明确要求永久删除时,才加 --permanent。永久删除无法撤销。", "Check the repository with dam repository list before moving the asset to the recycle bin. Add --permanent only when the user explicitly requests permanent deletion. This cannot be undone."),
339
+ `${runtime.product.commandName} dam delete <asset> --repository-id <id>`, ""
340
+ ].join("\n"));
333
341
  bindPreparedAction(deleteCommand, "organization", async (signal) => {
334
342
  signal.throwIfAborted();
335
343
  const options = deleteCommand.opts();
@@ -377,7 +385,7 @@ function browseCommand(command, runtime) {
377
385
  .option("--page-size <number>", text(runtime.product, "请求分页大小", "request page size"), positiveInteger)
378
386
  .option("--cursor <id>", text(runtime.product, "原样使用上一页 next_cursor,并保持相同筛选", "reuse the previous next_cursor unchanged with the same filters"))
379
387
  .option("--json", text(runtime.product, "输出 JSON", "output JSON"))
380
- .addHelpText("after", text(runtime.product, "\n默认个人资源库,每页 20 条,包含子文件夹;finish=false 时用 next_cursor 继续同范围查询,本页不代表全部结果。空结果不证明其他资源库不存在该素材;按用户指定范围核对资源库和筛选。\n", "\nDefaults to the personal repository, 20 items and inclusion of child folders. When finish=false, continue with next_cursor and unchanged scope; one page is not the entire result. An empty page says nothing about other repositories; check the user's intended repository and filters.\n"));
388
+ .addHelpText("after", "\n" + defaultRepositoryHelp(runtime.product) + "\n" + text(runtime.product, "\n默认每页 20 条,包含子文件夹。finish=false 时用 next_cursor 继续同范围查询,本页不代表全部结果。空结果不证明其他资源库不存在该素材;按用户指定范围核对资源库和筛选。\n", "\nBy default, each page includes up to 20 items and includes child folders. When finish=false, continue with next_cursor and unchanged scope; one page is not the entire result. An empty page says nothing about other repositories; check the user's intended repository and filters.\n"));
381
389
  }
382
390
  function browseInput(command) {
383
391
  const options = command.opts();
@@ -425,8 +433,8 @@ function assetListView(value, product) {
425
433
  const result = value;
426
434
  return [
427
435
  `${text(product, "资源库", "Repositories")}: ${result.repository_ids.join(", ")}`,
428
- `${text(product, "本批 / 总数", "This batch / total")}: ${result.assets.length} / ${result.total}`,
429
- result.finish ? text(product, "已到最后一页。", "Last page.")
436
+ `${text(product, "本批 / 返回计数(服务未提供总数时为本批数)", "This batch / returned count (batch size when total is unavailable)")}: ${result.assets.length} / ${result.total}`,
437
+ result.finish ? text(product, "返回结束标记:是。若提示分页信息不完整,请核对结果范围。", "End marker: yes. If pagination information is incomplete, verify the result scope.")
430
438
  : !result.next_cursor ? text(product, "服务提示还有结果,但未返回可用游标,无法续页。", "More results are indicated, but the service supplied no cursor.")
431
439
  : text(product, `还有下一页;保留筛选条件,使用 --cursor ${result.next_cursor ?? "<cursor>"} 查询。`, `More results; keep the same filters and query with --cursor ${result.next_cursor ?? "<cursor>"}.`),
432
440
  ...(result.assets.length ? [text(product, "ID\t标题\t类型\t格式", "ID\tTitle\tType\tFormat"), ...result.assets.map(assetRow)]
@@ -1,3 +1,5 @@
1
+ import { FeedbackDeliveryError } from "../features/feedback/submit.js";
2
+ import { SkillManualError } from "../features/skill/manual.js";
1
3
  import { CreditsPageCursorError } from "../features/credits/use-cases.js";
2
4
  import { observedErrorCategory, observedErrorMessage } from "./observed-errors.js";
3
5
  import { TaskBackgroundError } from "../features/task/task-background.js";
@@ -46,6 +48,12 @@ export function isHelpOutcome(error) {
46
48
  && (error.code === "commander.helpDisplayed" || error.code === "commander.version");
47
49
  }
48
50
  export function mapCliError(error, options) {
51
+ if (error instanceof FeedbackDeliveryError) {
52
+ return failure("FEEDBACK_" + error.outcome.toUpperCase(), error.messageFor(options.product?.id === "insmind"), 1, undefined, error.feedbackId ? { feedbackId: error.feedbackId } : undefined);
53
+ }
54
+ if (!options.aborted && error instanceof SkillManualError) {
55
+ return failure(error.code, error.message, error.code === "USAGE_ERROR" ? 2 : 1);
56
+ }
49
57
  const outcome = mapBaseCliError(error instanceof CreationInputUploadError ? error.cause : error, options);
50
58
  if (outcome.kind === "interrupted")
51
59
  return { ...outcome, failure: { code: "INTERRUPTED",
@@ -114,11 +122,17 @@ function mapBaseCliError(error, options) {
114
122
  failure: { code: "INTERRUPTED", message: text("生成任务已取消。", "The creation task was canceled.") } };
115
123
  if (error instanceof UpdateError)
116
124
  return failure(error.code, error.message, 1, error.nextSteps, error.details);
125
+ if (options.aborted && options.operation === "dam.download") {
126
+ const paths = error instanceof DamDownloadError || error instanceof DamDownloadDestinationExistsError ? error.remainingPaths : [];
127
+ return { kind: "interrupted", exitCode: 130, failure: { code: "INTERRUPTED",
128
+ message: text("素材下载已中断。", "The download was interrupted."),
129
+ ...(paths.length ? { details: { phase: "interrupted", remaining_paths: paths,
130
+ next_steps: [text("请检查列出的文件,再决定是否重新下载。", "Check the listed files before downloading again.")] } } : {}) } };
131
+ }
117
132
  if (options.aborted)
118
133
  return { kind: "interrupted", exitCode: 130, failure: {
119
134
  code: "INTERRUPTED", message: text("已停止本地等待;已派发的任务或写操作可能仍在继续。", "Local waiting stopped; dispatched tasks or writes may still be active."),
120
135
  details: { ...(error instanceof DamOperationUnconfirmedError ? { operation: error.operation, ...error.context } : {}),
121
- ...(error instanceof DamDownloadError ? { phase: error.phase, remaining_paths: error.remainingPaths } : {}),
122
136
  next_steps: [text(`创作用 ${command} task list 找到原任务,再用 task get <id> 查询。不要直接重复提交。`, `For creation, find the original task with ${command} task list, then task get <id>. Do not resubmit directly.`)] }
123
137
  } };
124
138
  if (error instanceof TaskBackgroundError)
@@ -128,8 +142,10 @@ function mapBaseCliError(error, options) {
128
142
  if (error instanceof TaskStoreError)
129
143
  return failure("LOCAL_STATE_ERROR", insmind
130
144
  ? "Cannot read or write local task records. Check permissions and file integrity in ~/.insmind/tasks."
131
- : "无法读写本地执行记录;请检查 ~/.gd/tasks 的权限和文件完整性。", 1, error.context ? [text("保留已有输出;恢复文件访问后查询原任务,不要重新提交创作。", "Keep any output; restore file access and query the original task without submitting again."),
132
- `${command} task get ${error.context.cli_task_id}`] : undefined, { ...error.context, reason: "task_storage", system_code: systemErrorCode(error) });
145
+ : "无法读写本地执行记录;请检查 ~/.gd/tasks 的权限和文件完整性。", 1, error.context?.phase === "before_dispatch" && error.context.request_sent === false && error.context.accepted === false
146
+ ? [text("这次创作还没提交。请恢复任务目录的写入权限,再运行刚才的命令。", "The creation request was not sent. Restore write access to the task directory, then run the original command again.")]
147
+ : error.context ? [text("保留已有输出;恢复文件访问后查询原任务,不要重新提交创作。", "Keep any output; restore file access and query the original task without submitting again."),
148
+ `${command} task get ${error.context.cli_task_id}`] : undefined, { ...error.context, reason: "task_storage", system_code: systemErrorCode(error) });
133
149
  if (error instanceof UserIdentityMissingError) {
134
150
  return failure("AUTH_REQUIRED", text("登录身份缺少用户 ID,请重新登录。", "The login identity has no user ID. Please sign in again."), 1, [`${command} auth login`]);
135
151
  }
@@ -162,6 +178,8 @@ function mapBaseCliError(error, options) {
162
178
  ? text("无法读取 JSON 输入。", "Cannot read the JSON input.")
163
179
  : text("JSON 输入语法无效。", "The input is not valid JSON."), 2, [error.reason === "read" ? text("检查输入文件是否存在、是否可读,或 stdin 是否可用。", "Check that the input file exists and is readable, or that stdin is available.")
164
180
  : text("修正 JSON 语法后重新执行;输入尚未提交。", "Correct the JSON syntax and run again; the input has not been submitted.")], { reason: `json_${error.reason}`, system_code: systemErrorCode(error) });
181
+ if (error instanceof InputContractError && options.operation === "feedback.submit")
182
+ return failure("USAGE_ERROR", text("反馈还没提交。请按提示补齐或修正字段。", "The report has not been sent. Correct the indicated fields."), 2, [command + " feedback --schema"], { reason: "schema_validation", issues: error.issues });
165
183
  if (error instanceof InputContractError)
166
184
  return failure("USAGE_ERROR", text("输入不符合命令要求,请修正所列字段。", "The input does not match the command requirements; correct the listed fields."), 2, [text("使用该命令 --help 中的 Schema 发现入口核对输入。file URL 请用 pathToFileURL(path).href 生成,中文文件名无需改名。", "Use the Schema discovery described in this command's --help. Generate file URLs with pathToFileURL(path).href; Unicode filenames are supported.")], { reason: "schema_validation", issues: error.issues });
167
185
  if (error instanceof ToolInputError || error instanceof AgentInputError) {
@@ -240,9 +258,8 @@ function mapBaseCliError(error, options) {
240
258
  return failure("DAM_ASSET_NOT_DOWNLOADABLE", "该素材当前没有可下载的源文件;请先查看素材状态。", 1, ["gd-cli dam get <asset-id>"]);
241
259
  }
242
260
  if (error instanceof DamDownloadDestinationExistsError) {
243
- return failure("DAM_DOWNLOAD_DESTINATION_EXISTS", insmind
244
- ? "The destination file already exists and was not overwritten. Choose another output directory."
245
- : "目标文件已存在,未覆盖任何文件;请更换输出目录或移走同名文件。", 1);
261
+ const paths = error.remainingPaths;
262
+ return failure("DAM_DOWNLOAD_DESTINATION_EXISTS", text("目标目录已有同名文件。请换一个目录下载。", "A file with this name already exists. Choose another download directory."), 1, paths.length ? [text("请先检查 remaining_paths 列出的文件。", "Check the files listed in remaining_paths first.")] : undefined, paths.length ? { phase: "destination", remaining_paths: paths } : undefined);
246
263
  }
247
264
  if (error instanceof DamDownloadError)
248
265
  return failure("DAM_DOWNLOAD_FAILED", text("素材下载未完成;请按失败阶段检查源文件访问或目标目录。", "The asset download did not complete; check source access or the destination for the reported phase."), 1, [text("已有素材无需重新生成;先检查文件状态再决定是否重新下载。", "Do not regenerate the asset; inspect file state before downloading again.")], { phase: error.phase, system_code: systemErrorCode(error), http_status: error.status,
@@ -0,0 +1,31 @@
1
+ import { contractSchema } from "../contracts/schema.js";
2
+ import { productText } from "../product/text.js";
3
+ import { bindPreparedAction, jsonOutput } from "./action-binding.js";
4
+ import { CliUsageError } from "./errors.js";
5
+ export function registerFeedbackCommand(program, runtime) {
6
+ const text = (zh, en) => productText(runtime.product, zh, en);
7
+ const name = runtime.product.commandName;
8
+ const feedback = program.command("feedback")
9
+ .description(text("向产品团队反馈问题或需求,取得反馈编号", "Report a problem or request a feature and get a feedback ID"))
10
+ .option("--schema", text("查看必填字段及问题、需求示例", "show the required fields and examples for bugs and feature requests"))
11
+ .option("--input <file|->", text("从文件或标准输入读取反馈 JSON", "read the report as JSON from a file or stdin"))
12
+ .allowExcessArguments(false)
13
+ .addHelpText("after", text("\n用户要反馈时,整理已发生的操作、实际现象和预期结果。提需求时写清使用场景和期望。带上能确认的宿主、用户设备和原错误信息。提交反馈无需登录。\n", "\nWhen the user asks to send feedback, describe what happened and what they expected. For a feature, describe when they need it. Include the host, user device and available error details. No sign-in is required.\n")
14
+ + name + " feedback --schema\n" + name + " feedback --input bug.json\n" + name + " feedback --input - < feature.json\n");
15
+ jsonOutput(feedback);
16
+ bindPreparedAction(feedback, "none", async (signal) => {
17
+ const { schema, input } = feedback.opts();
18
+ if (Boolean(schema) === (input !== undefined))
19
+ throw new CliUsageError();
20
+ if (schema) {
21
+ runtime.io.writeOut(JSON.stringify(contractSchema("feedback.submit", "input")) + "\n");
22
+ return { handled: true };
23
+ }
24
+ const report = await runtime.jsonInput.read(input, signal);
25
+ runtime.validators.feedbackInput(report);
26
+ return { handled: false, input: report };
27
+ }, async (_context, report, signal) => {
28
+ const result = await runtime.telemetry.stage("feedback", () => runtime.submitFeedback(report, signal));
29
+ runtime.io.writeOut(JSON.stringify(result) + "\n");
30
+ }, { operation: "feedback.submit", mode: () => feedback.opts().schema ? "schema" : "execute" });
31
+ }
@@ -12,7 +12,7 @@ export function registerModelCommands(program, runtime) {
12
12
  .option("--tool <tool>", text(runtime.product, "按工具筛选", "filter by tool"))
13
13
  .allowExcessArguments(false);
14
14
  list.addHelpText("after", text(runtime.product, "\n列表只提供模型摘要。选择后用 model get <model> --tool <tool> 读取完整输入、用途与保留范围,再判断是否符合需求;不能仅凭摘要推断整个工具不支持。\n", "\nThis list is a summary. Read model get <model> --tool <tool> for full inputs, purpose and preservation scope before deciding whether it meets the request; the summary alone cannot establish that the whole Tool is unsupported.\n"));
15
- skillOutput(list, runtime);
15
+ skillOutput(list, runtime, true);
16
16
  bindAction(list, "organization", async (context, signal) => {
17
17
  const selectedTool = list.opts().tool;
18
18
  if (selectedTool !== undefined)
@@ -31,7 +31,7 @@ export function registerModelCommands(program, runtime) {
31
31
  });
32
32
  await runtime.telemetry.stage("output", async () => {
33
33
  runtime.validators.modelListOutput(result);
34
- await writeSkillResult(runtime, list, result, selectedTool);
34
+ await writeSkillResult(runtime, list, result, selectedTool, true);
35
35
  });
36
36
  }, { operation: "model.list" });
37
37
  const get = model.command("get")
@@ -51,7 +51,7 @@ export function registerModelCommands(program, runtime) {
51
51
  text(runtime.product, "公开 Schema 指导构参;CLI 仅检查自身读取、转换、授权和交付所必需的条件。服务端决定业务参数是否可接受,返回明确错误时按实际原因处理,不能静默替换用户值。", "The public Schema guides input construction. The CLI checks only what it needs for reading, conversion, authorization and delivery. The service decides business validity; handle its stated error without silently replacing user values."),
52
52
  ""
53
53
  ].join("\n"));
54
- skillOutput(get, runtime);
54
+ skillOutput(get, runtime, true);
55
55
  bindAction(get, "organization", async (context, signal) => {
56
56
  const modelName = get.processedArgs[0];
57
57
  if (typeof modelName !== "string" || modelName.trim() === "")
@@ -75,7 +75,7 @@ export function registerModelCommands(program, runtime) {
75
75
  const projected = result.inputSchema ? hostSchema(runtime, result.inputSchema, result.tool) : undefined;
76
76
  const output = { ...result, ...(projected ? { inputSchema: projected } : {}) };
77
77
  runtime.validators.modelGetOutput(output);
78
- await writeSkillResult(runtime, get, output, result.tool);
78
+ await writeSkillResult(runtime, get, output, result.tool, true);
79
79
  });
80
80
  }, {
81
81
  operation: "model.get"
@@ -1,13 +1,22 @@
1
1
  import { jsonOutput } from "./action-binding.js";
2
2
  import { productText } from "../product/text.js";
3
- export function skillOutput(command, runtime) {
3
+ export function skillOutput(command, runtime, discovery = false) {
4
4
  jsonOutput(command, productText(runtime.product, "仅输出原业务 JSON,供按原 Schema 校验的脚本使用", "output only the business JSON for scripts that validate its original schema"));
5
- command.option("--with-skills", productText(runtime.product, "在 JSON 的 relatedSkills 中附上匹配指引(默认),也可与 --json 合用", "include matching guides in relatedSkills (default), including when used with --json"));
5
+ command.option("--with-skills", productText(runtime.product, discovery ? "附上与本次查询匹配的选读指引,可与 --json 合用" : "在完整结果中附上选读指引,可与 --json 合用", discovery ? "include optional guides for this query, including with --json" : "include optional guides with the completed result, including with --json"));
6
6
  }
7
- export async function writeSkillResult(runtime, command, result, operation) {
7
+ export async function writeSkillResult(runtime, command, result, operation, discovery = false) {
8
8
  const { withSkills, json } = command.opts();
9
- const relatedSkills = operation && (!json || withSkills)
9
+ const relatedSkills = operation && (withSkills || (discovery && !json))
10
10
  ? await runtime.skillCatalog?.recommendations(operation)
11
11
  : undefined;
12
12
  runtime.io.writeOut(JSON.stringify(relatedSkills?.length ? { ...result, relatedSkills } : result) + "\n");
13
13
  }
14
+ export function writeTaskResult(runtime, result) {
15
+ if (result.state !== "running") {
16
+ runtime.io.writeOut(JSON.stringify(result) + "\n");
17
+ return;
18
+ }
19
+ const lookup = runtime.product.commandName + " task get " + result.taskId;
20
+ const next = productText(runtime.product, "任务已受理,生成可能需要几分钟。请用 " + lookup + " 取回结果。仍在处理时,隔几秒继续查同一任务,请勿重复提交。", "Task accepted. Generation can take a few minutes. Run " + lookup + " to get the result. If it is still running, check the same task after a few seconds without resubmitting.");
21
+ runtime.io.writeOut(JSON.stringify({ ...result, note: result.note ? result.note + " " + next : next }) + "\n");
22
+ }
@@ -1,3 +1,4 @@
1
+ import { writeTaskResult } from "./skill-output.js";
1
2
  import { productText } from "../product/text.js";
2
3
  import { validTaskId } from "../features/task/store.js";
3
4
  import { jsonOutput, bindPreparedAction } from "./action-binding.js";
@@ -40,7 +41,7 @@ export function registerTaskCommands(program, runtime) {
40
41
  text("读取本地状态不请求组织绑定;查询远端进度或获取下载授权仍需联网授权。查询请求失败不代表生成失败,可用原 taskId 重查。", "Local status reads do not bind the organization. Remote progress and download authorization still require network access. A failed query does not mean generation failed; query the same taskId again."),
41
42
  text("查询得到完整结果但最终缓存保存失败时仍返回结果和退出码 0;请保留 stderr 警告所指的输出,后续可能无法恢复。", "A complete result is delivered with exit code 0 if only final cache persistence fails; keep the output as warned on stderr because later recovery may be unavailable."),
42
43
  text("最终错误为 stderr 中的 JSON error 对象;stderr 也可能有进度和警告,中断不代表远端任务取消。", "The final error is a JSON error object on stderr, which may also contain progress and warnings. Interruption does not mean the remote task was cancelled."),
43
- text("查询不重新提交创作。同一任务的 usage 不重复相加;Agent usage.cost.amount 为本轮实扣,Tool minimum/maximum 为目录估价,即使相等也不是实扣。", "Queries never resubmit creation or add usage for repeated reads. Agent usage.cost.amount is this turn's actual charge; Tool minimum/maximum are catalog estimates even when equal."),
44
+ text("查询不重新提交创作。同一任务的 usage 不重复相加;Agent usage.cost.amount 是已确认扣费合计,若提示记录缺少金额则总额待核对,以账单为准。Tool minimum/maximum 是目录或按输入估价,即使相等也不是实扣。", "Queries never resubmit creation or add usage for repeated reads. Agent usage.cost.amount is the confirmed subtotal; if a warning says amounts are missing, check the total against the ledger. Tool minimum/maximum are catalog or input-based estimates even when equal."),
44
45
  text(`记录仅来自本机执行;保留至用户删除 ~/${runtime.product.stateDirectory}/tasks。切换身份或组织后只显示对应记录。`, `Tasks are local to this machine and identity context; they remain until you remove ~/${runtime.product.stateDirectory}/tasks.`),
45
46
  text("Agent 首次回执未取得或原连接中断时可能只能确认未知;不会自动选择最近 Context 或重新生成。", "A missing first Agent receipt or interrupted connection may leave the outcome unknown; the CLI does not select another Context or generate again."),
46
47
  ""
@@ -55,7 +56,7 @@ export function registerTaskCommands(program, runtime) {
55
56
  const result = await tasks.get({ id, state: context.state, signal });
56
57
  await runtime.telemetry.stage("output", async () => {
57
58
  runtime.validators.taskResult(result);
58
- runtime.io.writeOut(`${JSON.stringify(result)}\n`);
59
+ writeTaskResult(runtime, result);
59
60
  });
60
61
  }, { operation: "task.get" });
61
62
  }
@@ -1,8 +1,8 @@
1
1
  import { ToolInputError } from "../features/tool/catalog.js";
2
- import { skillOutput, writeSkillResult } from "./skill-output.js";
2
+ import { skillOutput, writeSkillResult, writeTaskResult } from "./skill-output.js";
3
3
  import { creationTaskHelp } from "./creation-help.js";
4
4
  import { hostSchema, readHostInput } from "./host-input.js";
5
- import { jsonOutput, bindAction, bindPreparedAction } from "./action-binding.js";
5
+ import { bindAction, bindPreparedAction } from "./action-binding.js";
6
6
  import { CliUsageError } from "./errors.js";
7
7
  import { productText as text } from "../product/text.js";
8
8
  export function registerToolCommands(program, runtime) {
@@ -13,7 +13,7 @@ export function registerToolCommands(program, runtime) {
13
13
  const list = tool.command("list")
14
14
  .description(text(runtime.product, "列出可用工具", "List available tools"))
15
15
  .allowExcessArguments(false);
16
- jsonOutput(list);
16
+ skillOutput(list, runtime, true);
17
17
  bindAction(list, "organization", async (context, signal) => {
18
18
  const result = await runtime.tool.listTools({
19
19
  access: {
@@ -24,7 +24,14 @@ export function registerToolCommands(program, runtime) {
24
24
  });
25
25
  await runtime.telemetry.stage("output", async () => {
26
26
  runtime.validators.toolListOutput(result);
27
- runtime.io.writeOut(`${JSON.stringify(result)}\n`);
27
+ const { json, withSkills } = list.opts();
28
+ const guides = (!json || withSkills) && runtime.skillCatalog?.guidesForTools
29
+ ? await runtime.skillCatalog.guidesForTools(result.tools.map(tool => tool.name)) : undefined;
30
+ const tools = result.tools.map(tool => {
31
+ const guide = guides?.get(tool.name);
32
+ return guide ? { ...tool, description: tool.description + text(runtime.product, " 需要用法时运行 ", " For help, run ") + guide } : tool;
33
+ });
34
+ runtime.io.writeOut(JSON.stringify({ ...result, tools }) + "\n");
28
35
  });
29
36
  }, { operation: "tool.list" });
30
37
  const call = tool.command("call")
@@ -93,7 +100,7 @@ export function registerToolCommands(program, runtime) {
93
100
  const result = await runtime.startBackgroundTask({ ...task, input: prepared.input }, signal);
94
101
  await runtime.telemetry.stage("output", async () => {
95
102
  runtime.validators.taskResult(result);
96
- await writeSkillResult(runtime, call, result, prepared.input.name);
103
+ writeTaskResult(runtime, result);
97
104
  });
98
105
  return;
99
106
  }
@@ -11,12 +11,12 @@ export function registerUpdateCommand(program, runtime) {
11
11
  text(runtime.product, `检查 ${runtime.product.npmPackage} 的 npm latest,更新受支持的全局 npm/pnpm 安装;CLI 已最新时仍同步随包 Skill。`, `Checks npm latest for ${runtime.product.npmPackage}, updates supported global npm/pnpm installations and synchronizes the bundled Skill even when the CLI is current.`),
12
12
  text(runtime.product, `只授权本包安装脚本:npm --allow-scripts=${runtime.product.npmPackage},pnpm --allow-build=${runtime.product.npmPackage}。`, `Enables lifecycle scripts only for this package: npm --allow-scripts=${runtime.product.npmPackage}, pnpm --allow-build=${runtime.product.npmPackage}.`),
13
13
  text(runtime.product, "普通使用只检查/提醒,不自动安装或同步 Skill。宿主管理的安装拒绝自行升级,并返回对应渠道的处理步骤;遵循该渠道,不覆盖其他宿主的 Skill。", "Normal use only checks/notifies; it does not install or synchronize Skills automatically. Host-managed installations reject self-update and return channel-specific instructions; follow that channel without overwriting other hosts' Skills."),
14
- text(runtime.product, "若 CLI 更新成功但 Skill 验收失败,保留已更新版本,按错误中的下一步修复;不支持的安装来源也以命令返回的指引为准。", "If the CLI updates but Skill verification fails, keep the updated version and follow the error's next steps. Unsupported installation sources also receive channel-specific guidance."),
14
+ text(runtime.product, "若 CLI 更新成功但 Skill 验收失败,保留已更新版本,按错误中的下一步修复;项目依赖请在原项目更新;临时运行请用原运行器选择新版;宿主安装请在宿主中更新。", "If the CLI updates but Skill verification fails, keep the updated version and follow the error's next steps. Update a project dependency in the original project, select a new version in a temporary runner, or update a host installation through that host."),
15
15
  ""
16
16
  ].join("\n"));
17
17
  const check = update.command("check")
18
18
  .description(text(runtime.product, "只读查询是否有可用升级,无需登录", "Check for an available update without signing in or installing"))
19
- .option("--for-display", text(runtime.product, "为当前前台入口交付一次到期提醒,写出成功后开始 60 分钟计时", "Deliver a due notice to the current foreground surface and start its 60-minute window on output"))
19
+ .option("--for-display", text(runtime.product, "提醒到期时,返回一条可展示的升级提示。成功写出后,同一入口在 60 分钟内不会再收到这条提醒。", "Return a due update notice. Once written successfully, the same surface will not receive it again for 60 minutes."))
20
20
  .option("--schema", text(runtime.product, "输出本地查询结果的 Schema,不查询 npm", "Print the local output schema without checking npm"))
21
21
  .allowExcessArguments(false);
22
22
  jsonOutput(check);
@@ -27,7 +27,7 @@ export function registerUpdateCommand(program, runtime) {
27
27
  await runtime.io.flush?.();
28
28
  });
29
29
  if (check.opts().schema)
30
- return write({ outputSchema: updateCheckSchema });
30
+ return write({ outputSchema: updateCheckSchema(runtime.product.id === "insmind") });
31
31
  const forDisplay = check.opts().forDisplay === true;
32
32
  await runtime.updateNotification.report(signal, forDisplay, async (result) => {
33
33
  await write(result);
@@ -7,9 +7,6 @@ export function readAgentInputSchema() {
7
7
  delete definitions.FirstFramePart;
8
8
  delete definitions.LastFramePart;
9
9
  const generation = definitions.GenerationConstraintsPart.properties.data;
10
- const model = generation.properties.model;
11
- if (model.description)
12
- model.description = "可选创作模型标识;已知编辑模型别名会映射到服务端 code,其余标识原样发送。";
13
10
  delete generation.properties.arguments.minProperties;
14
11
  const question = { $ref: "#/$defs/QuestionAnswerPart" };
15
12
  definitions.UserMessage.allOf = [
@@ -16,8 +16,10 @@ export class DamDownloadError extends Error {
16
16
  }
17
17
  }
18
18
  export class DamDownloadDestinationExistsError extends Error {
19
- constructor() {
19
+ remainingPaths;
20
+ constructor(remainingPaths = []) {
20
21
  super("目标文件已存在,未覆盖任何文件。");
22
+ this.remainingPaths = remainingPaths;
21
23
  this.name = "DamDownloadDestinationExistsError";
22
24
  }
23
25
  }
@@ -234,6 +236,7 @@ export function createDamFileDownloader(options = {}) {
234
236
  item.open = false;
235
237
  }
236
238
  for (const item of pending) {
239
+ input.signal.throwIfAborted();
237
240
  try {
238
241
  await dependencies.fileSystem.link(item.temporaryPath, item.finalPath);
239
242
  }
@@ -258,28 +261,35 @@ export function createDamFileDownloader(options = {}) {
258
261
  }));
259
262
  }
260
263
  catch (error) {
261
- const remainingPaths = [];
264
+ // Another process can replace a published name. Only remove the private temporaries.
265
+ const remainingPaths = [...createdFinalPaths];
262
266
  const cleanupErrors = [];
263
267
  let temporaryCleanupFailed = false;
264
268
  await Promise.all(pending.map(async (item) => {
265
269
  if (item.open)
266
270
  await item.handle.close().catch(cause => { cleanupErrors.push(cause); });
267
- await dependencies.fileSystem.rm(item.temporaryPath, { force: true }).catch(cause => {
271
+ await dependencies.fileSystem.rm(item.temporaryPath, { force: true }).catch(() => {
268
272
  remainingPaths.push(item.temporaryPath);
269
273
  temporaryCleanupFailed = true;
270
274
  });
271
275
  }));
272
- await Promise.all(createdFinalPaths.map((path) => (dependencies.fileSystem.rm(path, { force: true }).catch(cause => { remainingPaths.push(path); cleanupErrors.push(cause); }))));
273
276
  if (temporaryCleanupFailed)
274
277
  warnCleanup();
275
278
  if (cleanupErrors.length)
276
279
  throw new DamDownloadError(new AggregateError([error, ...cleanupErrors], "Download cleanup failed.", { cause: error }), "cleanup", undefined, remainingPaths);
277
- if (isInterruption(error, input.signal))
280
+ if (isInterruption(error, input.signal)) {
281
+ if (remainingPaths.length)
282
+ throw new DamDownloadError(input.signal.reason, "interrupted", undefined, remainingPaths);
278
283
  throw input.signal.reason;
279
- if (error instanceof DamDownloadDestinationExistsError
280
- || error instanceof DamDownloadError)
281
- throw error;
282
- throw new DamDownloadError(error, "write");
284
+ }
285
+ if (error instanceof DamDownloadDestinationExistsError)
286
+ throw new DamDownloadDestinationExistsError(remainingPaths);
287
+ if (error instanceof DamDownloadError) {
288
+ if (!remainingPaths.length)
289
+ throw error;
290
+ throw new DamDownloadError(error.cause, error.phase, error.status, remainingPaths);
291
+ }
292
+ throw new DamDownloadError(error, "write", undefined, remainingPaths);
283
293
  }
284
294
  }
285
295
  };
@@ -51,6 +51,8 @@ export function createDamOperationExecutor(dependencies) {
51
51
  if (task.fail_count !== null && task.fail_count > 0) {
52
52
  throw new DamOperationFailedError(input.operation);
53
53
  }
54
+ if (input.operation === "move")
55
+ return { task_id: taskId };
54
56
  if (input.operation !== "copy" || input.inspectResult === undefined)
55
57
  return {};
56
58
  const result = await input.inspectResult(taskId, input.signal);