@insmind/cli 1.3.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/LICENSE +21 -0
- package/README.md +11 -0
- package/contracts/operations/agent.send/input.schema.json +335 -0
- package/contracts/operations/agent.send/output.schema.json +248 -0
- package/contracts/operations/auth.status/input.schema.json +7 -0
- package/contracts/operations/auth.status/output.schema.json +119 -0
- package/contracts/operations/dam.copy/input.schema.json +42 -0
- package/contracts/operations/dam.copy/output.schema.json +43 -0
- package/contracts/operations/dam.delete/input.schema.json +24 -0
- package/contracts/operations/dam.delete/output.schema.json +5 -0
- package/contracts/operations/dam.download/input.schema.json +28 -0
- package/contracts/operations/dam.download/output.schema.json +51 -0
- package/contracts/operations/dam.folder.list/input.schema.json +36 -0
- package/contracts/operations/dam.folder.list/output.schema.json +104 -0
- package/contracts/operations/dam.get/input.schema.json +16 -0
- package/contracts/operations/dam.get/output.schema.json +107 -0
- package/contracts/operations/dam.list/input.schema.json +73 -0
- package/contracts/operations/dam.list/output.schema.json +145 -0
- package/contracts/operations/dam.move/input.schema.json +42 -0
- package/contracts/operations/dam.move/output.schema.json +40 -0
- package/contracts/operations/dam.rename/input.schema.json +42 -0
- package/contracts/operations/dam.rename/output.schema.json +43 -0
- package/contracts/operations/dam.repository.list/input.schema.json +7 -0
- package/contracts/operations/dam.repository.list/output.schema.json +65 -0
- package/contracts/operations/dam.search/input.schema.json +79 -0
- package/contracts/operations/dam.search/output.schema.json +145 -0
- package/contracts/operations/dam.tag.list/input.schema.json +21 -0
- package/contracts/operations/dam.tag.list/output.schema.json +52 -0
- package/contracts/operations/dam.upload/input.schema.json +43 -0
- package/contracts/operations/dam.upload/output.schema.json +107 -0
- package/contracts/operations/editor.apply/input.schema.json +177 -0
- package/contracts/operations/editor.apply/output.schema.json +15 -0
- package/contracts/operations/editor.connect/input.schema.json +13 -0
- package/contracts/operations/editor.connect/output.schema.json +17 -0
- package/contracts/operations/editor.disconnect/input.schema.json +7 -0
- package/contracts/operations/editor.disconnect/output.schema.json +14 -0
- package/contracts/operations/editor.save/input.schema.json +7 -0
- package/contracts/operations/editor.save/output.schema.json +23 -0
- package/contracts/operations/editor.screenshot/input.schema.json +7 -0
- package/contracts/operations/editor.screenshot/output.schema.json +16 -0
- package/contracts/operations/editor.snapshot/input.schema.json +7 -0
- package/contracts/operations/editor.snapshot/output.schema.json +148 -0
- package/contracts/operations/model.get/input.schema.json +16 -0
- package/contracts/operations/model.get/output.schema.json +167 -0
- package/contracts/operations/model.list/input.schema.json +13 -0
- package/contracts/operations/model.list/output.schema.json +97 -0
- package/contracts/operations/task.get/input.schema.json +14 -0
- package/contracts/operations/task.get/output.schema.json +103 -0
- package/contracts/operations/task.list/input.schema.json +18 -0
- package/contracts/operations/task.list/output.schema.json +53 -0
- package/contracts/operations/tool.call/input.schema.json +31 -0
- package/contracts/operations/tool.call/output.schema.json +115 -0
- package/contracts/operations/tool.list/input.schema.json +6 -0
- package/contracts/operations/tool.list/output.schema.json +40 -0
- package/dist/bin/agent-worker.js +41 -0
- package/dist/bin/insmind-cli.js +60 -0
- package/dist/bin/postinstall.js +69 -0
- package/dist/src/bootstrap/create-cli.js +124 -0
- package/dist/src/bootstrap/create-runtime.js +451 -0
- package/dist/src/bootstrap/run-agent-worker.js +37 -0
- package/dist/src/bootstrap/validators.js +169 -0
- package/dist/src/cli/action-binding.js +109 -0
- package/dist/src/cli/agent-commands.js +75 -0
- package/dist/src/cli/auth-commands.js +58 -0
- package/dist/src/cli/credits-command.js +23 -0
- package/dist/src/cli/dam-commands.js +470 -0
- package/dist/src/cli/editor-commands.js +74 -0
- package/dist/src/cli/errors.js +208 -0
- package/dist/src/cli/model-commands.js +62 -0
- package/dist/src/cli/org-commands.js +58 -0
- package/dist/src/cli/presenter.js +123 -0
- package/dist/src/cli/prompt.js +30 -0
- package/dist/src/cli/task-commands.js +48 -0
- package/dist/src/cli/tool-commands.js +101 -0
- package/dist/src/cli/update-command.js +15 -0
- package/dist/src/contracts/schema.js +4 -0
- package/dist/src/features/agent/creative-agent-adapter.js +42 -0
- package/dist/src/features/agent/creative-protocol.js +421 -0
- package/dist/src/features/agent/creative-stream.js +138 -0
- package/dist/src/features/agent/filems-resource-auth-key-provider.js +23 -0
- package/dist/src/features/agent/resource-authorizer.js +47 -0
- package/dist/src/features/agent/result-reader.js +30 -0
- package/dist/src/features/agent/use-cases.js +153 -0
- package/dist/src/features/auth/access-policy.js +101 -0
- package/dist/src/features/auth/credential-store.js +62 -0
- package/dist/src/features/auth/sso-service.js +196 -0
- package/dist/src/features/auth/state.js +129 -0
- package/dist/src/features/auth/use-cases.js +162 -0
- package/dist/src/features/credits/use-cases.js +52 -0
- package/dist/src/features/dam/asset-projection.js +278 -0
- package/dist/src/features/dam/dam-api-adapter.js +562 -0
- package/dist/src/features/dam/file-downloader.js +242 -0
- package/dist/src/features/dam/object-storage.js +193 -0
- package/dist/src/features/dam/operation-executor.js +72 -0
- package/dist/src/features/dam/registered-uploader.js +247 -0
- package/dist/src/features/dam/repository-catalog.js +127 -0
- package/dist/src/features/dam/storage-upload.js +141 -0
- package/dist/src/features/dam/transient-uploader.js +17 -0
- package/dist/src/features/dam/use-cases.js +470 -0
- package/dist/src/features/editor/bridge-client.js +109 -0
- package/dist/src/features/editor/bridge-process.js +229 -0
- package/dist/src/features/editor/bridge-server.js +337 -0
- package/dist/src/features/editor/protocol.js +1 -0
- package/dist/src/features/editor/public-url.js +36 -0
- package/dist/src/features/editor/session-state.js +78 -0
- package/dist/src/features/editor/session.js +213 -0
- package/dist/src/features/editor/use-cases.js +88 -0
- package/dist/src/features/org/org-service.js +76 -0
- package/dist/src/features/org/use-cases.js +163 -0
- package/dist/src/features/skill/bundled-skills.js +63 -0
- package/dist/src/features/skill/installer.js +271 -0
- package/dist/src/features/task/agent-background.js +63 -0
- package/dist/src/features/task/store.js +97 -0
- package/dist/src/features/task/types.js +1 -0
- package/dist/src/features/task/use-cases.js +139 -0
- package/dist/src/features/tool/catalog.js +83 -0
- package/dist/src/features/tool/dynamic-schema.js +128 -0
- package/dist/src/features/tool/mns-catalog-adapter.js +265 -0
- package/dist/src/features/tool/tool-api-adapter.js +369 -0
- package/dist/src/features/tool/use-cases.js +180 -0
- package/dist/src/features/update/latest-version.js +37 -0
- package/dist/src/features/update/update-notification.js +271 -0
- package/dist/src/features/update/update-service.js +226 -0
- package/dist/src/platform/installation-owner.js +81 -0
- package/dist/src/platform/json-input.js +67 -0
- package/dist/src/platform/local-json-file.js +59 -0
- package/dist/src/platform/open-browser.js +8 -0
- package/dist/src/platform/redact.js +80 -0
- package/dist/src/platform/remote-error-evidence.js +80 -0
- package/dist/src/platform/remote-protocol.js +10 -0
- package/dist/src/platform/resource-auth-key.js +1 -0
- package/dist/src/platform/safe-upload-file.js +146 -0
- package/dist/src/platform/signature.js +20 -0
- package/dist/src/platform/signed-http-transport.js +144 -0
- package/dist/src/platform/task-observer.js +1 -0
- package/dist/src/platform/url-safety.js +100 -0
- package/dist/src/product/billing.js +47 -0
- package/dist/src/product/config.js +85 -0
- package/dist/src/product/locale.js +38 -0
- package/dist/src/product/text.js +3 -0
- package/dist/src/telemetry/invocation.js +156 -0
- package/dist/src/telemetry/sls-sink.js +30 -0
- package/package.json +53 -0
- package/skills/insmind-cli/SKILL.md +15 -0
- package/skills/insmind-cli/references/agent.md +34 -0
- package/skills/insmind-cli/references/auth.md +8 -0
- package/skills/insmind-cli/references/creation.md +40 -0
- package/skills/insmind-cli/references/dam.md +51 -0
- package/skills/insmind-cli/references/editor.md +184 -0
- package/skills/insmind-cli/references/errors.md +29 -0
- package/skills/insmind-cli/references/generation-constraints.md +36 -0
- package/skills/insmind-cli/references/tool.md +31 -0
- package/skills/insmind-cli/references/update.md +11 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Private one-task process; not a public CLI command or a resident service.
|
|
2
|
+
import { once } from "node:events";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
import { gaodingProduct, insmindProduct } from "../src/product/config.js";
|
|
5
|
+
import { createProductionRuntime } from "../src/bootstrap/create-runtime.js";
|
|
6
|
+
import { runAgentWorker } from "../src/bootstrap/run-agent-worker.js";
|
|
7
|
+
if (!process.send) {
|
|
8
|
+
process.exitCode = 2;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
const controller = new AbortController();
|
|
12
|
+
const interrupt = () => controller.abort(new Error("SIGINT"));
|
|
13
|
+
process.once("SIGINT", interrupt);
|
|
14
|
+
process.once("SIGTERM", interrupt);
|
|
15
|
+
const send = (message) => {
|
|
16
|
+
if (process.connected)
|
|
17
|
+
process.send?.(message, () => undefined);
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
const [job] = await once(process, "message");
|
|
21
|
+
const product = job.product === "insmind" ? insmindProduct : gaodingProduct;
|
|
22
|
+
const endpoints = { ...product.endpoints };
|
|
23
|
+
for (const key of Object.keys(endpoints))
|
|
24
|
+
endpoints[key] = new URL(job.endpoints[key]);
|
|
25
|
+
const runtime = createProductionRuntime({
|
|
26
|
+
product, endpoints, homeDirectory: job.homeDirectory, locale: job.locale,
|
|
27
|
+
io: { input: Readable.from([]), stdout: { write() { } }, stderr: { write() { } } }
|
|
28
|
+
});
|
|
29
|
+
await runAgentWorker({ runtime, job, signal: controller.signal, send });
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
send({ type: "error", failure: { code: "TASK_WORKER_UNAVAILABLE", message: "The background task could not start. Check task list/get before submitting again." }, exitCode: 1 });
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
if (process.connected)
|
|
37
|
+
process.disconnect();
|
|
38
|
+
process.removeListener("SIGINT", interrupt);
|
|
39
|
+
process.removeListener("SIGTERM", interrupt);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { insmindProduct } from "../src/product/config.js";
|
|
3
|
+
import { localeOption } from "../src/product/locale.js";
|
|
4
|
+
const controller = new AbortController();
|
|
5
|
+
const interrupt = () => controller.abort(new Error("SIGINT"));
|
|
6
|
+
process.once("SIGINT", interrupt);
|
|
7
|
+
let runtime;
|
|
8
|
+
let mapCliError;
|
|
9
|
+
let redact;
|
|
10
|
+
try {
|
|
11
|
+
const [cliModule, runtimeModule, errorsModule, redactModule] = await Promise.all([
|
|
12
|
+
import("../src/bootstrap/create-cli.js"),
|
|
13
|
+
import("../src/bootstrap/create-runtime.js"),
|
|
14
|
+
import("../src/cli/errors.js"),
|
|
15
|
+
import("../src/platform/redact.js")
|
|
16
|
+
]);
|
|
17
|
+
mapCliError = errorsModule.mapCliError;
|
|
18
|
+
redact = redactModule.redact;
|
|
19
|
+
const selectedLocale = localeOption(process.argv.slice(2));
|
|
20
|
+
runtime = runtimeModule.createProductionRuntime({
|
|
21
|
+
product: insmindProduct,
|
|
22
|
+
...(selectedLocale === undefined ? {} : { locale: selectedLocale })
|
|
23
|
+
});
|
|
24
|
+
const program = cliModule.createCli(runtime, { signal: controller.signal });
|
|
25
|
+
process.exitCode = await cliModule.executeCli({
|
|
26
|
+
program,
|
|
27
|
+
argv: process.argv.slice(2),
|
|
28
|
+
presenter: runtime.presenter,
|
|
29
|
+
signal: controller.signal,
|
|
30
|
+
telemetry: runtime.telemetry,
|
|
31
|
+
telemetrySink: runtime.telemetrySink,
|
|
32
|
+
updateNotification: runtime.updateNotification,
|
|
33
|
+
product: runtime.product
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (mapCliError === undefined || redact === undefined) {
|
|
38
|
+
process.stderr.write("INTERNAL_ERROR: CLI failed to start.\n");
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const outcome = redact(mapCliError(error, { aborted: controller.signal.aborted, product: insmindProduct }));
|
|
43
|
+
if (runtime) {
|
|
44
|
+
runtime.presenter.error(outcome, { json: process.argv.includes("--json") });
|
|
45
|
+
}
|
|
46
|
+
else if (outcome.kind === "interrupted") {
|
|
47
|
+
process.stderr.write("Cancelled.\n");
|
|
48
|
+
}
|
|
49
|
+
else if (process.argv.includes("--json")) {
|
|
50
|
+
process.stderr.write(`${JSON.stringify({ error: outcome.failure })}\n`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
process.stderr.write(`${outcome.failure.code}: ${outcome.failure.message}\n`);
|
|
54
|
+
}
|
|
55
|
+
process.exitCode = outcome.exitCode;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
process.removeListener("SIGINT", interrupt);
|
|
60
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { loadBundledSkills } from "../src/features/skill/bundled-skills.js";
|
|
4
|
+
import { syncBundledSkills } from "../src/features/skill/installer.js";
|
|
5
|
+
import { markWorkBuddyInstallation, readInstallationOwner } from "../src/platform/installation-owner.js";
|
|
6
|
+
export function isSupportedGlobalLifecycle(env) {
|
|
7
|
+
const userAgent = env.npm_config_user_agent ?? "";
|
|
8
|
+
if (env.npm_config_global === "true") {
|
|
9
|
+
return /^(?:npm|pnpm)\//u.test(userAgent);
|
|
10
|
+
}
|
|
11
|
+
const initialDirectory = (env.INIT_CWD ?? "").replace(/\\/gu, "/");
|
|
12
|
+
return userAgent.startsWith("pnpm/")
|
|
13
|
+
&& env.npm_command === "add"
|
|
14
|
+
&& env.npm_lifecycle_event === "postinstall"
|
|
15
|
+
&& (env.npm_package_name === "@gaoding/cli" || env.npm_package_name === "@insmind/cli")
|
|
16
|
+
&& /\/v\d+\/[0-9a-f]+-[0-9a-f]+-[0-9a-f]{16}$/u.test(initialDirectory);
|
|
17
|
+
}
|
|
18
|
+
export async function runPostinstall(options = {}) {
|
|
19
|
+
const env = options.env ?? process.env;
|
|
20
|
+
if (!isSupportedGlobalLifecycle(env))
|
|
21
|
+
return;
|
|
22
|
+
const writeError = options.writeError ?? ((text) => process.stderr.write(text));
|
|
23
|
+
let skills;
|
|
24
|
+
try {
|
|
25
|
+
skills = (options.loadSkills ?? loadBundledSkills)(options.startFile ?? fileURLToPath(import.meta.url));
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (env.GD_CLI_INSTALL_OWNER === "workbuddy") {
|
|
29
|
+
throw new Error("无法确认当前安装的 package。");
|
|
30
|
+
}
|
|
31
|
+
writeError(`警告: ${oneLineMessage(error)}\n`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const primarySkill = skills.find((skill) => skill.skill === "gd-cli");
|
|
35
|
+
if (!primarySkill)
|
|
36
|
+
throw new Error("Bundled gd-cli Skill is missing.");
|
|
37
|
+
const packageRoot = dirname(dirname(primarySkill.sourceDirectory));
|
|
38
|
+
if (env.GD_CLI_INSTALL_OWNER === "workbuddy") {
|
|
39
|
+
markWorkBuddyInstallation(packageRoot);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const owner = readInstallationOwner(packageRoot);
|
|
43
|
+
if (owner === "workbuddy")
|
|
44
|
+
return;
|
|
45
|
+
if (owner === "invalid")
|
|
46
|
+
throw new Error("无法确认当前安装的托管信息。");
|
|
47
|
+
try {
|
|
48
|
+
await (options.syncSkills ?? syncBundledSkills)(skills, {
|
|
49
|
+
env,
|
|
50
|
+
...(options.homeDirectory ? { homeDirectory: options.homeDirectory } : {})
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
writeError(`警告: ${oneLineMessage(error)}\n`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function oneLineMessage(error) {
|
|
58
|
+
const value = error instanceof Error ? error.message : String(error);
|
|
59
|
+
return value.replace(/\s+/gu, " ").trim() || "Agent Skill 自动安装失败";
|
|
60
|
+
}
|
|
61
|
+
const entryPath = process.argv[1];
|
|
62
|
+
const isDirectEntry = entryPath !== undefined
|
|
63
|
+
&& resolve(entryPath) === fileURLToPath(import.meta.url);
|
|
64
|
+
if (isDirectEntry || process.env.npm_lifecycle_event === "postinstall") {
|
|
65
|
+
void runPostinstall().catch((error) => {
|
|
66
|
+
process.stderr.write(`${oneLineMessage(error)}\n`);
|
|
67
|
+
process.exitCode = 1;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { registerTaskCommands } from "../cli/task-commands.js";
|
|
2
|
+
import { Command, CommanderError } from "commander";
|
|
3
|
+
import { assertAllLeafCommandsBound, configureActionEnvironment } from "../cli/action-binding.js";
|
|
4
|
+
import { registerAgentCommands } from "../cli/agent-commands.js";
|
|
5
|
+
import { registerAuthCommands } from "../cli/auth-commands.js";
|
|
6
|
+
import { classifyTelemetryError, isHelpOutcome, mapCliError } from "../cli/errors.js";
|
|
7
|
+
import { registerOrgCommands } from "../cli/org-commands.js";
|
|
8
|
+
import { registerToolCommands } from "../cli/tool-commands.js";
|
|
9
|
+
import { registerModelCommands } from "../cli/model-commands.js";
|
|
10
|
+
import { registerEditorCommands } from "../cli/editor-commands.js";
|
|
11
|
+
import { registerDamCommands } from "../cli/dam-commands.js";
|
|
12
|
+
import { registerUpdateCommand } from "../cli/update-command.js";
|
|
13
|
+
import { registerCreditsCommand } from "../cli/credits-command.js";
|
|
14
|
+
import { redact } from "../platform/redact.js";
|
|
15
|
+
export { assertAllLeafCommandsBound, bindAction } from "../cli/action-binding.js";
|
|
16
|
+
export function createCli(runtime, options) {
|
|
17
|
+
const program = new Command()
|
|
18
|
+
.name(runtime.product.commandName)
|
|
19
|
+
.description(runtime.product.description)
|
|
20
|
+
.version(runtime.version)
|
|
21
|
+
.helpCommand(false)
|
|
22
|
+
.showHelpAfterError(false)
|
|
23
|
+
.showSuggestionAfterError(false)
|
|
24
|
+
.allowExcessArguments(false)
|
|
25
|
+
.exitOverride()
|
|
26
|
+
.configureOutput({
|
|
27
|
+
writeOut: runtime.io.writeOut,
|
|
28
|
+
writeErr: () => undefined
|
|
29
|
+
});
|
|
30
|
+
if (runtime.product.id === "insmind") {
|
|
31
|
+
program.option("--locale <locale>", "locale for service-owned business descriptions");
|
|
32
|
+
}
|
|
33
|
+
configureActionEnvironment(program, {
|
|
34
|
+
policies: runtime.accessPolicies,
|
|
35
|
+
signal: options.signal,
|
|
36
|
+
telemetry: runtime.telemetry,
|
|
37
|
+
updateNotification: runtime.updateNotification
|
|
38
|
+
});
|
|
39
|
+
registerAuthCommands(program, runtime);
|
|
40
|
+
if (runtime.product.exposesOrganizations)
|
|
41
|
+
registerOrgCommands(program, runtime);
|
|
42
|
+
else
|
|
43
|
+
registerCreditsCommand(program, runtime);
|
|
44
|
+
registerAgentCommands(program, runtime);
|
|
45
|
+
registerToolCommands(program, runtime);
|
|
46
|
+
registerModelCommands(program, runtime);
|
|
47
|
+
registerEditorCommands(program, runtime);
|
|
48
|
+
registerDamCommands(program, runtime);
|
|
49
|
+
registerUpdateCommand(program, runtime);
|
|
50
|
+
registerTaskCommands(program, runtime);
|
|
51
|
+
assertAllLeafCommandsBound(program);
|
|
52
|
+
return program;
|
|
53
|
+
}
|
|
54
|
+
export async function executeCli(options) {
|
|
55
|
+
try {
|
|
56
|
+
await options.program.parseAsync(options.argv, { from: "user" });
|
|
57
|
+
await sendFinished(options, { outcome: "success" });
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (isHelpOutcome(error)) {
|
|
62
|
+
if (options.argv[0] !== "update") {
|
|
63
|
+
await checkUpdateNotification(options.updateNotification, options.signal);
|
|
64
|
+
}
|
|
65
|
+
if (options.signal.aborted) {
|
|
66
|
+
options.presenter.error({ kind: "interrupted", exitCode: 130 }, { json: options.argv.includes("--json") });
|
|
67
|
+
await sendFinished(options, { outcome: "interrupted" });
|
|
68
|
+
return 130;
|
|
69
|
+
}
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
if (options.telemetry.selected && error instanceof CommanderError) {
|
|
73
|
+
try {
|
|
74
|
+
await options.telemetry.stage("input", () => { throw error; });
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// The original Commander error is mapped and presented below.
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const outcome = redact(mapCliError(error, {
|
|
81
|
+
aborted: options.signal.aborted,
|
|
82
|
+
...(options.product ? { product: options.product } : {})
|
|
83
|
+
}));
|
|
84
|
+
const telemetryError = classifyTelemetryError(error);
|
|
85
|
+
const traceId = options.telemetry.selected
|
|
86
|
+
? options.telemetry.traceId
|
|
87
|
+
: undefined;
|
|
88
|
+
options.presenter.error(outcome, {
|
|
89
|
+
json: options.argv.includes("--json"),
|
|
90
|
+
...(traceId ? { traceId } : {})
|
|
91
|
+
});
|
|
92
|
+
await sendFinished(options, outcome.kind === "interrupted"
|
|
93
|
+
? { outcome: "interrupted", error }
|
|
94
|
+
: {
|
|
95
|
+
outcome: "failure",
|
|
96
|
+
error,
|
|
97
|
+
errorCode: outcome.failure.code,
|
|
98
|
+
errorMessage: outcome.failure.message,
|
|
99
|
+
...(telemetryError.httpStatus === undefined
|
|
100
|
+
? {}
|
|
101
|
+
: { httpStatus: telemetryError.httpStatus }),
|
|
102
|
+
...(telemetryError.remoteErrorCode === undefined
|
|
103
|
+
? {}
|
|
104
|
+
: { remoteErrorCode: telemetryError.remoteErrorCode }),
|
|
105
|
+
...(telemetryError.remoteErrorBody === undefined
|
|
106
|
+
? {}
|
|
107
|
+
: { remoteErrorBody: telemetryError.remoteErrorBody })
|
|
108
|
+
});
|
|
109
|
+
return outcome.exitCode;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function checkUpdateNotification(updateNotification, signal) {
|
|
113
|
+
try {
|
|
114
|
+
await updateNotification.check(signal);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Version availability must never change the requested command outcome.
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async function sendFinished(options, completion) {
|
|
121
|
+
const events = options.telemetry.finish(completion);
|
|
122
|
+
if (events.length > 0)
|
|
123
|
+
await options.telemetrySink.send(events);
|
|
124
|
+
}
|