@insmind/cli 1.5.13 → 1.6.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.
package/dist/bin/insmind-cli.js
CHANGED
|
@@ -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(
|
|
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:
|
|
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
|
|
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
|
-
|
|
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": "@insmind/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "insMind command-line interface for agents and people.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@gaoding/cli": "workspace:*"
|
|
47
47
|
},
|
|
48
48
|
"gaodingRelease": {
|
|
49
|
-
"sourceCommit": "
|
|
50
|
-
"pipelineId": "
|
|
51
|
-
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/
|
|
49
|
+
"sourceCommit": "f696623bd177753f9bbdee5a8cc648e2a2b46f38",
|
|
50
|
+
"pipelineId": "224261",
|
|
51
|
+
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/224261"
|
|
52
52
|
}
|
|
53
53
|
}
|