@insmind/cli 1.5.1 → 1.5.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 (67) hide show
  1. package/contracts/operations/auth.status/output.schema.json +3 -4
  2. package/dist/bin/insmind-cli.js +12 -7
  3. package/dist/bin/postinstall.js +7 -5
  4. package/dist/bin/{agent-worker.js → task-worker.js} +5 -4
  5. package/dist/src/analytics/device.js +23 -0
  6. package/dist/src/analytics/wind.js +54 -0
  7. package/dist/src/bootstrap/create-cli.js +33 -19
  8. package/dist/src/bootstrap/create-runtime.js +45 -16
  9. package/dist/src/bootstrap/{run-agent-worker.js → run-task-worker.js} +20 -10
  10. package/dist/src/bootstrap/validators.js +10 -5
  11. package/dist/src/cli/action-binding.js +14 -0
  12. package/dist/src/cli/agent-commands.js +9 -4
  13. package/dist/src/cli/auth-commands.js +5 -3
  14. package/dist/src/cli/credits-command.js +2 -2
  15. package/dist/src/cli/dam-commands.js +51 -52
  16. package/dist/src/cli/editor-commands.js +13 -15
  17. package/dist/src/cli/errors.js +97 -44
  18. package/dist/src/cli/model-commands.js +6 -4
  19. package/dist/src/cli/presenter.js +13 -10
  20. package/dist/src/cli/task-commands.js +13 -5
  21. package/dist/src/cli/tool-commands.js +11 -5
  22. package/dist/src/features/agent/use-cases.js +11 -5
  23. package/dist/src/features/auth/access-policy.js +2 -0
  24. package/dist/src/features/auth/credential-store.js +2 -2
  25. package/dist/src/features/auth/sso-service.js +5 -4
  26. package/dist/src/features/auth/state.js +11 -1
  27. package/dist/src/features/auth/use-cases.js +43 -40
  28. package/dist/src/features/credits/use-cases.js +2 -0
  29. package/dist/src/features/dam/file-downloader.js +38 -16
  30. package/dist/src/features/dam/object-storage.js +23 -11
  31. package/dist/src/features/dam/operation-executor.js +46 -37
  32. package/dist/src/features/dam/registered-uploader.js +39 -29
  33. package/dist/src/features/dam/storage-upload.js +5 -4
  34. package/dist/src/features/dam/use-cases.js +81 -60
  35. package/dist/src/features/editor/bridge-client.js +6 -6
  36. package/dist/src/features/editor/bridge-process.js +2 -1
  37. package/dist/src/features/editor/session-state.js +6 -4
  38. package/dist/src/features/editor/session.js +26 -8
  39. package/dist/src/features/editor/use-cases.js +10 -3
  40. package/dist/src/features/org/use-cases.js +2 -1
  41. package/dist/src/features/task/store.js +4 -0
  42. package/dist/src/features/task/{agent-background.js → task-background.js} +5 -4
  43. package/dist/src/features/task/use-cases.js +123 -28
  44. package/dist/src/features/tool/catalog.js +11 -5
  45. package/dist/src/features/tool/dynamic-schema.js +9 -7
  46. package/dist/src/features/tool/mns-catalog-adapter.js +1 -0
  47. package/dist/src/features/tool/tool-api-adapter.js +8 -7
  48. package/dist/src/features/tool/use-cases.js +8 -4
  49. package/dist/src/features/update/update-notification.js +75 -70
  50. package/dist/src/features/update/update-service.js +24 -20
  51. package/dist/src/platform/file-lock.js +36 -9
  52. package/dist/src/platform/interruption.js +13 -0
  53. package/dist/src/platform/json-input.js +12 -9
  54. package/dist/src/platform/local-json-file.js +8 -4
  55. package/dist/src/platform/redact.js +7 -1
  56. package/dist/src/platform/remote-protocol.js +2 -2
  57. package/dist/src/platform/safe-upload-file.js +2 -1
  58. package/dist/src/platform/schema-issues.js +8 -0
  59. package/dist/src/platform/signed-http-transport.js +8 -7
  60. package/dist/src/platform/text-output.js +33 -0
  61. package/dist/src/telemetry/invocation.js +19 -4
  62. package/dist/src/telemetry/process-errors.js +14 -4
  63. package/dist/src/telemetry/sanitize.js +4 -2
  64. package/dist/src/telemetry/sls-sink.js +36 -20
  65. package/dist/vendor/README.md +10 -0
  66. package/dist/vendor/gd-tracker-node.mjs +1175 -0
  67. package/package.json +4 -4
@@ -1,5 +1,5 @@
1
1
  import { contractSchema } from "../contracts/schema.js";
2
- import { bindPreparedAction } from "./action-binding.js";
2
+ import { jsonOutput, bindPreparedAction } from "./action-binding.js";
3
3
  import { CliUsageError } from "./errors.js";
4
4
  import { productText as text } from "../product/text.js";
5
5
  const agentSendInputSchema = contractSchema("agent.send", "input");
@@ -15,6 +15,8 @@ export function registerAgentCommands(program, runtime) {
15
15
  .allowExcessArguments(false);
16
16
  send.addHelpText("after", [
17
17
  "",
18
+ 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."),
19
+ 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."),
18
20
  text(runtime.product, "--async 在服务端受理后输出包含 taskId 和 state 的 JSON;退出码 0 仅表示受理。", "--async returns JSON with taskId and state after acceptance; exit code 0 means accepted only."),
19
21
  text(runtime.product, "用 task get <taskId> 查询原任务;completed 时 result 为完整结果,running/unknown 或查询超时不应重新提交。", "Query the same taskId with task get; completed includes result. Do not resubmit on running, unknown, or a query timeout."),
20
22
  text(runtime.product, "Agent 异步由本机后台进程继续执行;进程终止或关机可能使状态变为 unknown。", "Agent async continues in a local background process; termination or shutdown may leave its state unknown."),
@@ -27,6 +29,7 @@ export function registerAgentCommands(program, runtime) {
27
29
  text(runtime.product, "usage 仅覆盖本次调用,不包含其他命令调用的消耗。", "usage covers this invocation only, excluding other command invocations."),
28
30
  ""
29
31
  ].join("\n"));
32
+ jsonOutput(send);
30
33
  bindPreparedAction(send, "organization", async (signal) => {
31
34
  signal.throwIfAborted();
32
35
  const options = send.opts();
@@ -50,9 +53,11 @@ export function registerAgentCommands(program, runtime) {
50
53
  label: input.message.parts.map(part => part && typeof part === "object" && "text" in part ? String(part.text) : text(runtime.product, "[素材或结构化输入]", "[asset or structured input]")).join(" ")
51
54
  };
52
55
  if (send.opts().async) {
53
- const result = await runtime.startAgentTask({ state: context.state, label: task.label, input }, signal);
54
- runtime.validators.taskResult(result);
55
- runtime.io.writeOut(`${JSON.stringify(result)}\n`);
56
+ const result = await runtime.startBackgroundTask({ operation: "agent.send", state: context.state, label: task.label, input }, signal);
57
+ await runtime.telemetry.stage("output", async () => {
58
+ runtime.validators.taskResult(result);
59
+ runtime.io.writeOut(`${JSON.stringify(result)}\n`);
60
+ });
56
61
  return;
57
62
  }
58
63
  const run = async (observe) => {
@@ -7,7 +7,8 @@ export function registerAuthCommands(program, runtime) {
7
7
  .helpCommand(false);
8
8
  const login = leaf(auth.command("login"))
9
9
  .description(text(runtime.product, "登录稿定", "Sign in to insMind"))
10
- .option("--no-browser", text(runtime.product, "不自动打开浏览器", "do not open a browser automatically"));
10
+ .option("--no-browser", text(runtime.product, "不自动打开浏览器", "do not open a browser automatically"))
11
+ .addHelpText("after", text(runtime.product, "\n登录成功必须包含用户 ID;缺少用户 ID 的旧登录态需重新授权。", "\nSuccessful sign-in requires a user ID. Sign in again if an older local login has no user ID."));
11
12
  bindAction(login, "none", async (_context, signal) => {
12
13
  const noBrowser = login.opts().browser === false;
13
14
  runtime.telemetry.annotate({ parameters: { noBrowser } });
@@ -28,13 +29,14 @@ export function registerAuthCommands(program, runtime) {
28
29
  ? text(runtime.product, "已登录。", "Already signed in.")
29
30
  : text(runtime.product, "登录成功。", "Signed in successfully."));
30
31
  if (result.status === "already_logged_in" && !result.organizationSelected) {
31
- runtime.presenter.warning("尚未选择组织,请执行 gd-cli org switch。");
32
+ runtime.presenter.warning("尚未选择组织,请执行 gd-cli org list,再执行 gd-cli org switch --org <org-id>。");
32
33
  }
33
34
  });
34
35
  }, { operation: "auth.login" });
35
36
  const status = leaf(auth.command("status"))
36
37
  .description(text(runtime.product, "查看登录状态", "Show authentication status"))
37
- .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
38
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"))
39
+ .addHelpText("after", text(runtime.product, "\n本地登录态缺少用户 ID 时返回错误,请执行 auth login 重新登录。", "\nA local login without a user ID returns an error. Run auth login to sign in again."));
38
40
  bindAction(status, "none", async () => {
39
41
  const result = await runtime.auth.status({ now: runtime.now() });
40
42
  await runtime.telemetry.stage("output", async () => {
@@ -5,11 +5,11 @@ export function registerCreditsCommand(program, runtime) {
5
5
  .option("--json", "output JSON")
6
6
  .allowExcessArguments(false);
7
7
  bindAction(credits, "organization", async (context, signal) => {
8
- const result = await runtime.credits.get({
8
+ const result = await runtime.telemetry.stage("request", () => runtime.credits.get({
9
9
  credential: context.state.credential,
10
10
  organizationId: context.state.organization.id,
11
11
  signal
12
- });
12
+ }));
13
13
  await runtime.telemetry.stage("output", async () => {
14
14
  runtime.presenter.result(result, {
15
15
  json: credits.opts().json === true,
@@ -27,7 +27,7 @@ export function registerDamCommands(program, runtime) {
27
27
  await runtime.telemetry.stage("output", async () => {
28
28
  runtime.presenter.result(result, {
29
29
  json: repositoryList.opts().json === true,
30
- view: repositoryListView
30
+ view: value => repositoryListView(value, runtime.product)
31
31
  });
32
32
  });
33
33
  }, { operation: "dam.repository.list" });
@@ -64,7 +64,7 @@ export function registerDamCommands(program, runtime) {
64
64
  await runtime.telemetry.stage("output", async () => {
65
65
  runtime.presenter.result(result, {
66
66
  json: folderList.opts().json === true,
67
- view: folderListView
67
+ view: value => folderListView(value, runtime.product)
68
68
  });
69
69
  });
70
70
  }, { operation: "dam.folder.list" });
@@ -95,7 +95,7 @@ export function registerDamCommands(program, runtime) {
95
95
  await runtime.telemetry.stage("output", async () => {
96
96
  runtime.presenter.result(result, {
97
97
  json: tagList.opts().json === true,
98
- view: tagListView
98
+ view: value => tagListView(value, runtime.product)
99
99
  });
100
100
  });
101
101
  }, { operation: "dam.tag.list" });
@@ -126,7 +126,7 @@ export function registerDamCommands(program, runtime) {
126
126
  await runtime.telemetry.stage("output", async () => {
127
127
  runtime.presenter.result(result, {
128
128
  json: download.opts().json === true,
129
- view: downloadView
129
+ view: value => downloadView(value, runtime.product)
130
130
  });
131
131
  });
132
132
  }, { operation: "dam.download" });
@@ -159,7 +159,7 @@ export function registerDamCommands(program, runtime) {
159
159
  await runtime.telemetry.stage("output", async () => {
160
160
  runtime.presenter.result(result, {
161
161
  json: rename.opts().json === true,
162
- view: renameView
162
+ view: value => renameView(value, runtime.product)
163
163
  });
164
164
  });
165
165
  }, { operation: "dam.rename" });
@@ -209,7 +209,7 @@ export function registerDamCommands(program, runtime) {
209
209
  await runtime.telemetry.stage("output", async () => {
210
210
  runtime.presenter.result(result, {
211
211
  json: command.opts().json === true,
212
- view: operation === "move" ? moveView : copyView
212
+ view: value => operation === "move" ? moveView(value, runtime.product) : copyView(value, runtime.product)
213
213
  });
214
214
  });
215
215
  }, { operation: `dam.${operation}` });
@@ -231,7 +231,7 @@ export function registerDamCommands(program, runtime) {
231
231
  await runtime.telemetry.stage("output", async () => {
232
232
  runtime.presenter.result(result, {
233
233
  json: list.opts().json === true,
234
- view: assetListView
234
+ view: value => assetListView(value, runtime.product)
235
235
  });
236
236
  });
237
237
  }, { operation: "dam.list" });
@@ -256,7 +256,7 @@ export function registerDamCommands(program, runtime) {
256
256
  await runtime.telemetry.stage("output", async () => {
257
257
  runtime.presenter.result(result, {
258
258
  json: search.opts().json === true,
259
- view: assetListView
259
+ view: value => assetListView(value, runtime.product)
260
260
  });
261
261
  });
262
262
  }, { operation: "dam.search" });
@@ -279,7 +279,7 @@ export function registerDamCommands(program, runtime) {
279
279
  await runtime.telemetry.stage("output", async () => {
280
280
  runtime.presenter.result(result, {
281
281
  json: get.opts().json === true,
282
- view: assetDetailView
282
+ view: value => assetDetailView(value, runtime.product)
283
283
  });
284
284
  });
285
285
  }, { operation: "dam.get" });
@@ -317,7 +317,7 @@ export function registerDamCommands(program, runtime) {
317
317
  await runtime.telemetry.stage("output", async () => {
318
318
  runtime.presenter.result(result, {
319
319
  json: upload.opts().json === true,
320
- view: assetDetailView
320
+ view: value => assetDetailView(value, runtime.product)
321
321
  });
322
322
  });
323
323
  }, { operation: "dam.upload" });
@@ -417,70 +417,69 @@ function organizationAccess(state) {
417
417
  organizationId: state.organization.id
418
418
  };
419
419
  }
420
- function assetListView(value) {
421
- const assets = value.assets;
422
- if (assets.length === 0)
423
- return "暂无素材。";
420
+ function assetListView(value, product) {
421
+ const result = value;
424
422
  return [
425
- "ID\t标题\t类型\t格式",
426
- ...assets.map(assetRow)
423
+ `${text(product, "资源库", "Repositories")}: ${result.repository_ids.join(", ")}`,
424
+ `${text(product, "本批 / 总数", "This batch / total")}: ${result.assets.length} / ${result.total}`,
425
+ result.finish ? text(product, "已到最后一页。", "Last page.")
426
+ : text(product, `还有下一页;保留筛选条件,使用 --cursor ${result.next_cursor ?? "<cursor>"} 查询。`, `More results; keep the same filters and query with --cursor ${result.next_cursor ?? "<cursor>"}.`),
427
+ ...(result.assets.length ? [text(product, "ID\t标题\t类型\t格式", "ID\tTitle\tType\tFormat"), ...result.assets.map(assetRow)]
428
+ : [text(product, "暂无素材。", "No assets.")])
427
429
  ].join("\n");
428
430
  }
429
431
  function assetRow(asset) {
430
432
  return [asset.asset_id, asset.title ?? "", asset.type ?? "", asset.format ?? ""].join("\t");
431
433
  }
432
- function assetDetailView(value) {
434
+ function assetDetailView(value, product) {
433
435
  const asset = value;
434
436
  return [
435
- `素材:${asset.title ?? asset.asset_id}`,
436
- `ID:${asset.asset_id}`,
437
- ...(asset.type === undefined ? [] : [`类型:${asset.type}`]),
438
- ...(asset.format === undefined ? [] : [`格式:${asset.format}`]),
439
- ...(asset.url === undefined ? [] : [`URL:${asset.url}`])
437
+ `${text(product, "素材", "Asset")}: ${asset.title ?? asset.asset_id}`,
438
+ `ID: ${asset.asset_id}`,
439
+ ...(asset.repository_id === undefined ? [] : [`${text(product, "资源库", "Repository")}: ${asset.repository_id}`]),
440
+ ...(asset.folder_id === undefined ? [] : [`${text(product, "文件夹", "Folder")}: ${asset.folder_id}`]),
441
+ ...(asset.type === undefined ? [] : [`${text(product, "类型", "Type")}: ${asset.type}`]),
442
+ ...(asset.format === undefined ? [] : [`${text(product, "格式", "Format")}: ${asset.format}`]),
443
+ `${text(product, "分析状态", "Analysis status")}: ${asset.analysis_status ?? text(product, "未提供", "not provided")}`,
444
+ ...(asset.url === undefined ? [] : [`URL: ${asset.url}`])
440
445
  ].join("\n");
441
446
  }
442
- function folderListView(value) {
443
- const folders = value.folders;
444
- if (folders.length === 0)
445
- return "暂无文件夹。";
447
+ function folderListView(value, product) {
448
+ const result = value;
446
449
  return [
447
- "ID\t名称\t子文件夹数\t素材数",
448
- ...folders.map((folder) => [
449
- folder.folder_id,
450
- folder.title,
451
- folder.child_folder_count,
452
- folder.asset_count
453
- ].join("\t"))
450
+ `${text(product, "资源库 / 父文件夹", "Repository / parent folder")}: ${result.repository_id} / ${result.parent_id}`,
451
+ `${text(product, "页码 / 分页大小 / 总数", "Page / page size / total")}: ${result.page} / ${result.page_size} / ${result.total}`,
452
+ ...(result.page * result.page_size < result.total ? [text(product, `还有下一页;保留筛选条件,使用 --page ${result.page + 1}。`, `More results; keep the same filters and use --page ${result.page + 1}.`)] : []),
453
+ ...(result.folders.length ? [text(product, "ID\t名称\t子文件夹数\t素材数", "ID\tName\tChild folders\tAssets"),
454
+ ...result.folders.map(folder => [folder.folder_id, folder.title, folder.child_folder_count, folder.asset_count].join("\t"))]
455
+ : [text(product, "暂无文件夹。", "No folders.")])
454
456
  ].join("\n");
455
457
  }
456
- function tagListView(value) {
457
- const tags = value.tags;
458
- if (tags.length === 0)
459
- return "暂无标签。";
458
+ function tagListView(value, product) {
459
+ const result = value;
460
460
  return [
461
- "ID\t名称\t素材数",
462
- ...tags.map((tag) => [tag.tag_id, tag.name, tag.asset_count].join("\t"))
461
+ `${text(product, "资源库", "Repository")}: ${result.repository_id}`,
462
+ ...(result.tags.length ? [text(product, "ID\t名称\t素材数", "ID\tName\tAssets"),
463
+ ...result.tags.map(tag => [tag.tag_id, tag.name, tag.asset_count].join("\t"))]
464
+ : [text(product, "暂无标签。", "No tags.")])
463
465
  ].join("\n");
464
466
  }
465
- function downloadView(value) {
466
- return value.files
467
- .map((file) => `已下载:${file.path}`)
468
- .join("\n");
467
+ function downloadView(value, product) {
468
+ return value.files.map(file => `${text(product, "已下载", "Downloaded")}: ${file.path}`).join("\n");
469
469
  }
470
- function renameView(value) {
470
+ function renameView(value, product) {
471
471
  const result = value;
472
- return `已重命名:${result.title} (${result.entry_id})`;
472
+ return `${text(product, "已重命名", "Renamed")}: ${result.title} (${result.entry_id})`;
473
473
  }
474
- function moveView(value) {
474
+ function moveView(value, product) {
475
475
  const result = value;
476
- return `已移动至:${result.repository_id} / ${result.folder_id}`;
476
+ return `${text(product, "已移动", "Moved")}: ${result.entry_id} → ${result.repository_id} / ${result.folder_id}`;
477
477
  }
478
- function copyView(value) {
478
+ function copyView(value, product) {
479
479
  const result = value;
480
480
  return [
481
- `已复制至:${result.repository_id} / ${result.folder_id}`,
482
- ...(result.copied_entry_id === undefined
483
- ? []
484
- : [`复制条目 ID:${result.copied_entry_id}`])
481
+ `${text(product, "已复制", "Copied")}: ${result.source_entry_id} → ${result.repository_id} / ${result.folder_id}`,
482
+ result.copied_entry_id !== undefined ? `${text(product, "复制条目 ID", "Copied entry ID")}: ${result.copied_entry_id}`
483
+ : text(product, `未返回新 ID;使用 ${product.commandName} dam list --repository-id ${result.repository_id} --folder-id ${result.folder_id} 查询目标位置。`, `No new ID returned; inspect the destination with ${product.commandName} dam list --repository-id ${result.repository_id} --folder-id ${result.folder_id}.`)
485
484
  ].join("\n");
486
485
  }
@@ -1,4 +1,4 @@
1
- import { bindAction, bindPreparedAction } from "./action-binding.js";
1
+ import { jsonOutput, bindAction, bindPreparedAction } from "./action-binding.js";
2
2
  import { contractSchema } from "../contracts/schema.js";
3
3
  import { CliUsageError } from "./errors.js";
4
4
  import { productText as text } from "../product/text.js";
@@ -27,6 +27,7 @@ export function registerEditorCommands(program, runtime) {
27
27
  text(runtime.product, "页面切换作品会断开 Session;EDITOR_NOT_READY、EDITOR_SESSION_NOT_FOUND 或 EDITOR_NOT_CONNECTED 时确认目标后重连,不轮询旧 Session。", "Switching works disconnects the Session. On EDITOR_NOT_READY, EDITOR_SESSION_NOT_FOUND or EDITOR_NOT_CONNECTED, verify the target and reconnect instead of polling the old Session."),
28
28
  ""
29
29
  ].join("\n"));
30
+ jsonOutput(connect);
30
31
  bindPreparedAction(connect, "none", async (signal) => {
31
32
  signal.throwIfAborted();
32
33
  const target = connect.processedArgs[0];
@@ -34,14 +35,15 @@ export function registerEditorCommands(program, runtime) {
34
35
  runtime.validators.editorConnectInput(input);
35
36
  return { handled: false, input };
36
37
  }, async (_context, input, signal) => {
37
- const result = await runtime.editor.connect({ input, signal });
38
+ const result = await runtime.telemetry.stage("editor.connect", () => runtime.editor.connect({ input, signal }));
38
39
  writeJson(runtime, result);
39
40
  });
40
41
  const disconnect = leaf(editor.command("disconnect"))
41
42
  .description(text(runtime.product, "断开当前 Editor 连接", "Disconnect the current Editor"));
42
43
  disconnect.addHelpText("after", `\n${text(runtime.product, "输出 JSON {disconnected};断开连接不保存作品,需先显式执行 editor save。", "Returns JSON {disconnected}. Disconnecting does not save the work; run editor save explicitly first.")}\n`);
44
+ jsonOutput(disconnect);
43
45
  bindAction(disconnect, "none", async (_context, signal) => {
44
- writeJson(runtime, await runtime.editor.disconnect({ signal }));
46
+ writeJson(runtime, await runtime.telemetry.stage("editor.disconnect", () => runtime.editor.disconnect({ signal })));
45
47
  });
46
48
  const snapshot = leaf(editor.command("snapshot"))
47
49
  .description(text(runtime.product, "读取当前作品快照", "Read the current work snapshot"));
@@ -51,8 +53,9 @@ export function registerEditorCommands(program, runtime) {
51
53
  text(runtime.product, "修改时以最新 Snapshot 中的完整元素为基础;每次 apply 后重新读取。UNSUPPORTED_PAGE_CONTENT 时停止并保留原作品。", "Base changes on complete elements from the latest Snapshot and read again after every Apply. On UNSUPPORTED_PAGE_CONTENT, stop and preserve the work."),
52
54
  ""
53
55
  ].join("\n"));
56
+ jsonOutput(snapshot);
54
57
  bindAction(snapshot, "none", async (_context, signal) => {
55
- writeJson(runtime, await runtime.editor.snapshot({ signal }));
58
+ writeJson(runtime, await runtime.telemetry.stage("editor.snapshot", () => runtime.editor.snapshot({ signal })));
56
59
  });
57
60
  const apply = leaf(editor.command("apply"))
58
61
  .description(text(runtime.product, "按顺序应用元素操作", "Apply element operations in order"))
@@ -68,6 +71,7 @@ export function registerEditorCommands(program, runtime) {
68
71
  text(runtime.product, "成功不表示已保存或视觉正确;读取新 Snapshot,涉及布局/文字/连线时查看截图,再显式 save。超时、取消或断连后先检查真实状态,不重复提交。", "Success proves neither persistence nor correct rendering. Read a new Snapshot, view a screenshot for layout/text/connectors, then explicitly save. Inspect real state after timeout, cancellation or disconnection instead of resubmitting."),
69
72
  ""
70
73
  ].join("\n"));
74
+ jsonOutput(apply);
71
75
  bindPreparedAction(apply, "none", async (signal) => {
72
76
  signal.throwIfAborted();
73
77
  const options = apply.opts();
@@ -81,7 +85,7 @@ export function registerEditorCommands(program, runtime) {
81
85
  runtime.validators.editorApplyInput(input);
82
86
  return { handled: false, input };
83
87
  }, async (_context, input, signal) => {
84
- writeJson(runtime, await runtime.editor.apply({ input, signal }));
88
+ writeJson(runtime, await runtime.telemetry.stage("editor.apply", () => runtime.editor.apply({ input, signal })));
85
89
  }, {
86
90
  operation: "editor.apply",
87
91
  mode: () => apply.opts().schema === true ? "schema" : "execute"
@@ -91,10 +95,10 @@ export function registerEditorCommands(program, runtime) {
91
95
  .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
92
96
  screenshot.addHelpText("after", `\n${text(runtime.product, "将当前作品截图写入本机 PNG;--json 输出 {path},path 为绝对路径。打开实际图片检查文字、布局与连线,不以文件存在代替视觉验收。", "Writes a PNG screenshot locally; --json returns {path} with an absolute path. View the actual image to check text, layout and connectors; file existence is not visual verification.")}\n`);
93
97
  bindAction(screenshot, "none", async (_context, signal) => {
94
- const result = await runtime.editor.screenshot({ signal });
98
+ const result = await runtime.telemetry.stage("editor.screenshot", () => runtime.editor.screenshot({ signal }));
95
99
  runtime.presenter.result(result, {
96
100
  json: screenshot.opts().json === true,
97
- view: screenshotView
101
+ view: value => text(runtime.product, `截图已保存至 ${value.path}`, `Screenshot saved to ${value.path}`)
98
102
  });
99
103
  });
100
104
  const save = leaf(editor.command("save"))
@@ -108,10 +112,10 @@ export function registerEditorCommands(program, runtime) {
108
112
  ""
109
113
  ].join("\n"));
110
114
  bindAction(save, "none", async (_context, signal) => {
111
- const result = await runtime.editor.save({ signal });
115
+ const result = await runtime.telemetry.stage("editor.save", () => runtime.editor.save({ signal }));
112
116
  runtime.presenter.result(result, {
113
117
  json: save.opts().json === true,
114
- view: saveView
118
+ view: value => text(runtime.product, `作品已保存:${value.url}`, `Work saved: ${value.url}`)
115
119
  });
116
120
  });
117
121
  }
@@ -121,9 +125,3 @@ function leaf(command) {
121
125
  function writeJson(runtime, value) {
122
126
  runtime.io.writeOut(`${JSON.stringify(value)}\n`);
123
127
  }
124
- function screenshotView(value) {
125
- return `截图已保存至 ${value.path}`;
126
- }
127
- function saveView(value) {
128
- return `作品已保存:${value.url}`;
129
- }