@gaoding/cli 1.5.13 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { randomBytes } from "node:crypto";
3
+ import { jsonErrorsRequested } from "../src/platform/error-output-mode.js";
3
4
  import { isInterruption } from "../src/platform/interruption.js";
5
+ const jsonErrors = jsonErrorsRequested(process.argv.slice(2));
4
6
  const startedAt = Date.now();
5
7
  const bootstrapTraceId = randomBytes(16).toString("hex");
6
8
  const controller = new AbortController();
@@ -46,20 +48,22 @@ catch (error) {
46
48
  // Dynamic module loading can fail before the error mapper is available.
47
49
  // Keep that rare startup failure bounded and avoid an unhandled rejection.
48
50
  if (mapCliError === undefined || redact === undefined) {
49
- process.stderr.write(`INTERNAL_ERROR: CLI 启动失败。诊断 ID: ${traceId}\n`);
51
+ process.stderr.write(jsonErrors
52
+ ? `${JSON.stringify({ error: { code: "INTERNAL_ERROR", message: "CLI 启动失败。", trace_id: traceId } })}\n`
53
+ : `INTERNAL_ERROR: CLI 启动失败。诊断 ID: ${traceId}\n`);
50
54
  process.exitCode = 1;
51
55
  }
52
56
  else {
53
57
  const outcome = redact(mapCliError(error, { aborted: isInterruption(error, controller.signal) }));
54
58
  if (runtime) {
55
- runtime.presenter.error(outcome, { json: process.argv.includes("--json"), traceId });
59
+ runtime.presenter.error(outcome, { json: jsonErrors, traceId });
60
+ }
61
+ else if (jsonErrors) {
62
+ process.stderr.write(`${JSON.stringify({ error: { ...(outcome.failure ?? { code: "INTERRUPTED", message: "Local waiting stopped; dispatched operations may still be active." }), trace_id: traceId } })}\n`);
56
63
  }
57
64
  else if (outcome.kind === "interrupted") {
58
65
  process.stderr.write(`已停止本地等待;已派发操作可能仍在继续。诊断 ID: ${traceId}\n`);
59
66
  }
60
- else if (process.argv.includes("--json")) {
61
- process.stderr.write(`${JSON.stringify({ error: { ...outcome.failure, trace_id: traceId } })}\n`);
62
- }
63
67
  else {
64
68
  process.stderr.write(`${outcome.failure.code}: ${outcome.failure.message}\nDiagnostic ID: ${traceId}\n`);
65
69
  }
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import { randomBytes } from "node:crypto";
3
+ import { jsonErrorsRequested } from "../src/platform/error-output-mode.js";
3
4
  import { isInterruption } from "../src/platform/interruption.js";
4
5
  import { insmindProduct } from "../src/product/config.js";
5
6
  import { localeOption } from "../src/product/locale.js";
7
+ const jsonErrors = jsonErrorsRequested(process.argv.slice(2));
6
8
  const startedAt = Date.now();
7
9
  const bootstrapTraceId = randomBytes(16).toString("hex");
8
10
  const controller = new AbortController();
@@ -46,20 +48,22 @@ catch (error) {
46
48
  }
47
49
  catch { /* Retain startup error output even if diagnostic modules cannot load. */ }
48
50
  if (mapCliError === undefined || redact === undefined) {
49
- process.stderr.write(`INTERNAL_ERROR: CLI failed to start. Diagnostic ID: ${traceId}\n`);
51
+ process.stderr.write(jsonErrors
52
+ ? `${JSON.stringify({ error: { code: "INTERNAL_ERROR", message: "CLI failed to start.", trace_id: traceId } })}\n`
53
+ : `INTERNAL_ERROR: CLI failed to start. Diagnostic ID: ${traceId}\n`);
50
54
  process.exitCode = 1;
51
55
  }
52
56
  else {
53
57
  const outcome = redact(mapCliError(error, { aborted: isInterruption(error, controller.signal), product: insmindProduct }));
54
58
  if (runtime) {
55
- runtime.presenter.error(outcome, { json: process.argv.includes("--json"), traceId });
59
+ runtime.presenter.error(outcome, { json: jsonErrors, traceId });
60
+ }
61
+ else if (jsonErrors) {
62
+ process.stderr.write(`${JSON.stringify({ error: { ...(outcome.failure ?? { code: "INTERRUPTED", message: "Local waiting stopped; dispatched operations may still be active." }), trace_id: traceId } })}\n`);
56
63
  }
57
64
  else if (outcome.kind === "interrupted") {
58
65
  process.stderr.write(`Local waiting stopped; dispatched operations may still be active. Diagnostic ID: ${traceId}\n`);
59
66
  }
60
- else if (process.argv.includes("--json")) {
61
- process.stderr.write(`${JSON.stringify({ error: { ...outcome.failure, trace_id: traceId } })}\n`);
62
- }
63
67
  else {
64
68
  process.stderr.write(`${outcome.failure.code}: ${outcome.failure.message}\nDiagnostic ID: ${traceId}\n`);
65
69
  }
@@ -22,6 +22,9 @@ export function createCli(runtime, options) {
22
22
  .name(runtime.product.commandName)
23
23
  .description(runtime.product.description)
24
24
  .version(runtime.version)
25
+ .option("--json-errors", runtime.product.id === "insmind"
26
+ ? "output final errors as JSON; successful output is unchanged"
27
+ : "最终错误输出 JSON;成功输出保持原样")
25
28
  .helpCommand(false)
26
29
  .showHelpAfterError(false)
27
30
  .showSuggestionAfterError(false)
@@ -32,8 +35,8 @@ export function createCli(runtime, options) {
32
35
  writeErr: () => undefined
33
36
  });
34
37
  program.addHelpText("after", runtime.product.id === "insmind"
35
- ? "\nstdout contains command results; stderr contains progress, warnings and errors. Fixed JSON commands and --json use {error:{code,message,details?,trace_id?}} for final errors. stderr may contain multiple messages.\nExit codes: 0 success, 1 execution failure, 2 invalid input, 130 local interruption; dispatched work may still be active.\n"
36
- : "\nstdout 输出命令结果;stderr 输出进度、警告和错误。固定 JSON 命令和 --json 的最终错误使用 {error:{code,message,details?,trace_id?}},stderr 可能包含多条信息。\n退出码:0 成功,1 执行失败,2 输入无效,130 本地中断;已派发的工作可能仍在继续。\n");
38
+ ? "\nstdout contains command results; stderr contains progress, warnings and errors. Fixed JSON commands, --json and --json-errors use {error:{code,message,details?,trace_id?}} for final errors. stderr may contain multiple messages.\nExit codes: 0 success, 1 execution failure, 2 invalid input, 130 local interruption; dispatched work may still be active.\n"
39
+ : "\nstdout 输出命令结果;stderr 输出进度、警告和错误。固定 JSON 命令、--json 和 --json-errors 的最终错误使用 {error:{code,message,details?,trace_id?}},stderr 可能包含多条信息。\n退出码:0 成功,1 执行失败,2 输入无效,130 本地中断;已派发的工作可能仍在继续。\n");
37
40
  if (runtime.product.id === "insmind") {
38
41
  program.option("--locale <locale>", "locale for service-owned business descriptions");
39
42
  }
@@ -1,3 +1,4 @@
1
+ import { jsonErrorsRequested } from "../platform/error-output-mode.js";
1
2
  const environments = new WeakMap();
2
3
  const boundPolicies = new WeakMap();
3
4
  const jsonCommands = new WeakSet();
@@ -7,11 +8,12 @@ export function jsonOutput(command) {
7
8
  jsonCommands.add(command);
8
9
  }
9
10
  export function errorUsesJson(program, argv) {
11
+ if (program.opts().jsonErrors === true)
12
+ return true;
10
13
  const command = selectedCommands.get(program);
11
14
  if (command)
12
15
  return jsonCommands.has(command) || command.opts().json === true;
13
- const end = argv.indexOf("--");
14
- return (end < 0 ? argv : argv.slice(0, end)).includes("--json");
16
+ return jsonErrorsRequested(argv);
15
17
  }
16
18
  export function configureActionEnvironment(program, environment) {
17
19
  environments.set(program, environment);
@@ -0,0 +1,6 @@
1
+ /** Bootstrap cannot parse commands yet; never interpret values after -- as options. */
2
+ export function jsonErrorsRequested(argv) {
3
+ const end = argv.indexOf("--");
4
+ return (end < 0 ? argv : argv.slice(0, end))
5
+ .some(argument => argument === "--json" || argument === "--json-errors");
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaoding/cli",
3
- "version": "1.5.13",
3
+ "version": "1.6.1",
4
4
  "description": "Gaoding command-line interface for agents and people.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -56,8 +56,8 @@
56
56
  "vitest": "4.1.10"
57
57
  },
58
58
  "gaodingRelease": {
59
- "sourceCommit": "3cfa7151f00ae7207dbb5d7148adaeb5b6c3a413",
60
- "pipelineId": "221754",
61
- "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/221754"
59
+ "sourceCommit": "aabd8273b44c48f7226609c37f81d8da1c0265da",
60
+ "pipelineId": "225218",
61
+ "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/225218"
62
62
  }
63
63
  }
@@ -6,4 +6,6 @@
6
6
  4. 让用户从真实列表中选择,再执行 `gd-cli org switch --org <org-id>`;不要猜组织 ID。
7
7
  5. 用户要求退出或登录状态失效时执行 `gd-cli auth logout`;状态失效后重新登录。
8
8
 
9
- 不要向用户索要或回显 Bearer Token、Cookie、AK、SK 或签名。组织不可用时先切换组织;仍无法恢复时退出后重新登录。
9
+ 在千问办公桌面连接器中,使用平台入口 `gd-cli auth show --status` 检查 `status`;`unauthorized` 时执行 `gd-cli auth init`,请用户在自动打开的浏览器中完成授权,等待命令结束并检查为 `authorized` 后执行业务。账号展示用 `gd-cli identity whoami`。连接器沿用 CLI 的共享本地身份,凭证到期重新登录;显式 logout 会影响同一系统用户的其他入口,禁用或卸载套件不会自动退出。
10
+
11
+ 不要向用户索要或回显 Bearer Token、Cookie、AK、SK 或签名,也不要读取本地凭证文件。组织不可用时先切换组织;仍无法恢复时退出后重新登录。