@insmind/cli 1.5.13 → 1.7.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 +9 -5
- package/dist/src/bootstrap/create-cli.js +17 -2
- package/dist/src/cli/action-binding.js +4 -2
- package/dist/src/cli/auth-commands.js +6 -2
- package/dist/src/cli/errors.js +3 -1
- package/dist/src/features/auth/use-cases.js +11 -1
- package/dist/src/platform/error-output-mode.js +6 -0
- package/package.json +4 -4
- package/skills/insmind-cli/references/errors.md +1 -1
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
|
}
|
|
@@ -96,6 +99,18 @@ export async function executeCli(options) {
|
|
|
96
99
|
aborted: isInterruption(error, options.signal),
|
|
97
100
|
...(options.product ? { product: options.product } : {})
|
|
98
101
|
}));
|
|
102
|
+
// The invocation already carries the task created by this command, even on interruption.
|
|
103
|
+
// Preserve it in the public error as well as progress so hosts can suppress non-JSON diagnostics.
|
|
104
|
+
const { cli_task_id: taskId, operation } = options.telemetry.creationContext();
|
|
105
|
+
if (taskId && outcome.failure && ["agent.send", "tool.call"].includes(operation)) {
|
|
106
|
+
const details = outcome.failure.details;
|
|
107
|
+
outcome.failure.details = { ...details, cli_task_id: taskId, next_steps: [
|
|
108
|
+
...(details?.next_steps ?? []),
|
|
109
|
+
`${options.product?.commandName ?? "gd-cli"} task get ${taskId}`,
|
|
110
|
+
options.product?.id === "insmind" ? "Keep this task ID; do not automatically resubmit creation."
|
|
111
|
+
: "保留此任务 ID,不要自动重新提交创作。"
|
|
112
|
+
] };
|
|
113
|
+
}
|
|
99
114
|
const telemetryError = classifyTelemetryError(error, { aborted: isInterruption(error, options.signal), ...(options.product ? { product: options.product } : {}) });
|
|
100
115
|
const traceId = options.telemetry.selected
|
|
101
116
|
? options.telemetry.traceId
|
|
@@ -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);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
1
2
|
import { bindAction } from "./action-binding.js";
|
|
2
3
|
import { authStatusViewFor } from "./presenter.js";
|
|
3
4
|
import { productText as text } from "../product/text.js";
|
|
@@ -8,12 +9,15 @@ export function registerAuthCommands(program, runtime) {
|
|
|
8
9
|
const login = leaf(auth.command("login"))
|
|
9
10
|
.description(text(runtime.product, "登录稿定", "Sign in to insMind"))
|
|
10
11
|
.option("--no-browser", text(runtime.product, "不自动打开浏览器", "do not open a browser automatically"))
|
|
12
|
+
.addOption(new Option("--require-browser", text(runtime.product, "必须成功打开浏览器,否则立即失败;不回退到手动链接", "fail if the browser cannot open; do not fall back to a manual link")).conflicts("browser"))
|
|
11
13
|
.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."));
|
|
12
14
|
bindAction(login, "none", async (_context, signal) => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
+
const { browser, requireBrowser } = login.opts();
|
|
16
|
+
const noBrowser = browser === false;
|
|
17
|
+
runtime.telemetry.annotate({ parameters: { noBrowser, ...(requireBrowser ? { requireBrowser: true } : {}) } });
|
|
15
18
|
const result = await runtime.auth.login({
|
|
16
19
|
noBrowser,
|
|
20
|
+
...(requireBrowser ? { requireBrowser: true } : {}),
|
|
17
21
|
signal,
|
|
18
22
|
interaction: {
|
|
19
23
|
showAuthorization: (url) => runtime.presenter.authorization({
|
package/dist/src/cli/errors.js
CHANGED
|
@@ -5,7 +5,7 @@ import { CommanderError } from "commander";
|
|
|
5
5
|
import { AuthExpiredError, AuthRequiredError } from "../features/auth/access-policy.js";
|
|
6
6
|
import { AuthStateInvalidError, UserIdentityMissingError } from "../features/auth/state.js";
|
|
7
7
|
import { SsoRequestError } from "../features/auth/sso-service.js";
|
|
8
|
-
import { AuthorizedAccountContextMissingError, DeviceAuthorizationExpiredError } from "../features/auth/use-cases.js";
|
|
8
|
+
import { AuthorizedAccountContextMissingError, BrowserOpenError, DeviceAuthorizationExpiredError } from "../features/auth/use-cases.js";
|
|
9
9
|
import { AgentInputError } from "../features/agent/use-cases.js";
|
|
10
10
|
import { ToolInputError } from "../features/tool/catalog.js";
|
|
11
11
|
import { ToolTaskFailedError } from "../features/tool/tool-api-adapter.js";
|
|
@@ -185,6 +185,8 @@ export function mapCliError(error, options) {
|
|
|
185
185
|
return failure("DAM_REPOSITORY_NOT_FOUND", "No accessible asset repository is available for this account.", 1, ["Check asset repository access for this account, then run insmind-cli dam repository list."]);
|
|
186
186
|
return failure("DAM_REPOSITORY_NOT_FOUND", "当前组织没有可用的 DAM 资源库。", 1, ["gd-cli org list", "gd-cli org switch --org <org-id>"]);
|
|
187
187
|
}
|
|
188
|
+
if (error instanceof BrowserOpenError)
|
|
189
|
+
return failure("INTERNAL_ERROR", text("无法打开授权浏览器,本次登录已停止。请检查系统默认浏览器与启动权限后重新登录。", "The authorization browser could not open. Login stopped; check the default browser and launch permissions before signing in again."), 1, [`${command} auth login --require-browser`], { reason: "browser_open_failed" });
|
|
188
190
|
if (error instanceof DeviceAuthorizationExpiredError)
|
|
189
191
|
return failure("REMOTE_REQUEST_FAILED", text("本次登录授权已过期,请重新开始授权。", "This login authorization expired; start authorization again."), 1, [`${command} auth login`], { reason: "authorization_expired" });
|
|
190
192
|
if (error instanceof RemoteRequestError
|
|
@@ -6,6 +6,12 @@ export class DeviceAuthorizationExpiredError extends Error {
|
|
|
6
6
|
this.name = "DeviceAuthorizationExpiredError";
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
export class BrowserOpenError extends Error {
|
|
10
|
+
constructor(cause) {
|
|
11
|
+
super("Could not open the authorization browser.", { cause });
|
|
12
|
+
this.name = "BrowserOpenError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
9
15
|
export class AuthorizedAccountContextMissingError extends Error {
|
|
10
16
|
constructor() {
|
|
11
17
|
super("The authorized insMind account did not provide its account context.");
|
|
@@ -81,7 +87,11 @@ export function createAuthUseCases(dependencies) {
|
|
|
81
87
|
try {
|
|
82
88
|
await dependencies.telemetry.stage("browser", () => input.interaction.openBrowser(authorizationUrl));
|
|
83
89
|
}
|
|
84
|
-
catch {
|
|
90
|
+
catch (cause) {
|
|
91
|
+
if (isInterruption(cause, input.signal))
|
|
92
|
+
throw input.signal.reason;
|
|
93
|
+
if (input.requireBrowser)
|
|
94
|
+
throw new BrowserOpenError(cause);
|
|
85
95
|
input.interaction.warn(insmind
|
|
86
96
|
? "Could not open the browser. Open the authorization URL manually."
|
|
87
97
|
: "无法自动打开浏览器,请手动访问授权链接。");
|
|
@@ -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.7.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": "c1f9db85d5bf4c74b6b808bad8119c9c50b50970",
|
|
50
|
+
"pipelineId": "226274",
|
|
51
|
+
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/226274"
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
## Missing creation output
|
|
12
12
|
|
|
13
|
-
If an Agent or Tool request may already have been submitted, empty output, long execution or a host's completed-script message does not justify another creation. The original command prints a Task ID to stderr. Continue waiting if its execution session remains available; otherwise query the original task:
|
|
13
|
+
If an Agent or Tool request may already have been submitted, empty output, long execution or a host's completed-script message does not justify another creation. The original command prints a Task ID to stderr; a known ID is also retained in the final error recovery details. Continue waiting if its execution session remains available; otherwise query the original task:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
insmind-cli task list
|