gaoding-cli 1.0.0-alpha.5
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/CHANGELOG.md +88 -0
- package/LICENSE +21 -0
- package/README.md +136 -0
- package/SECURITY.md +34 -0
- package/dist/bin/gd-cli.d.ts +2 -0
- package/dist/bin/gd-cli.js +10 -0
- package/dist/src/api/app-runner.d.ts +33 -0
- package/dist/src/api/app-runner.js +1177 -0
- package/dist/src/api/dam-client.d.ts +111 -0
- package/dist/src/api/dam-client.js +897 -0
- package/dist/src/api/direct-auth.d.ts +3 -0
- package/dist/src/api/direct-auth.js +11 -0
- package/dist/src/api/direct-client.d.ts +27 -0
- package/dist/src/api/direct-client.js +151 -0
- package/dist/src/api/direct-tools.d.ts +43 -0
- package/dist/src/api/direct-tools.js +1155 -0
- package/dist/src/api/hub-client.d.ts +20 -0
- package/dist/src/api/hub-client.js +99 -0
- package/dist/src/api/sso-client.d.ts +60 -0
- package/dist/src/api/sso-client.js +140 -0
- package/dist/src/api/task-poller.d.ts +38 -0
- package/dist/src/api/task-poller.js +72 -0
- package/dist/src/api/tool-invoker.d.ts +12 -0
- package/dist/src/api/tool-invoker.js +11 -0
- package/dist/src/api/usage-client.d.ts +39 -0
- package/dist/src/api/usage-client.js +179 -0
- package/dist/src/auth/credential-store-v2.d.ts +12 -0
- package/dist/src/auth/credential-store-v2.js +59 -0
- package/dist/src/commands/auth.d.ts +2 -0
- package/dist/src/commands/auth.js +191 -0
- package/dist/src/commands/dam.d.ts +2 -0
- package/dist/src/commands/dam.js +293 -0
- package/dist/src/commands/models.d.ts +2 -0
- package/dist/src/commands/models.js +78 -0
- package/dist/src/commands/org.d.ts +2 -0
- package/dist/src/commands/org.js +137 -0
- package/dist/src/commands/skills.d.ts +2 -0
- package/dist/src/commands/skills.js +213 -0
- package/dist/src/commands/tools.d.ts +4 -0
- package/dist/src/commands/tools.js +383 -0
- package/dist/src/commands/update.d.ts +2 -0
- package/dist/src/commands/update.js +167 -0
- package/dist/src/commands/usage.d.ts +7 -0
- package/dist/src/commands/usage.js +43 -0
- package/dist/src/commands/workflows.d.ts +3 -0
- package/dist/src/commands/workflows.js +398 -0
- package/dist/src/core/auth/auth-provider.d.ts +8 -0
- package/dist/src/core/auth/auth-provider.js +12 -0
- package/dist/src/core/auth/device-oauth-provider.d.ts +12 -0
- package/dist/src/core/auth/device-oauth-provider.js +124 -0
- package/dist/src/core/auth/org-manager.d.ts +26 -0
- package/dist/src/core/auth/org-manager.js +224 -0
- package/dist/src/core/auth/signature.d.ts +19 -0
- package/dist/src/core/auth/signature.js +33 -0
- package/dist/src/core/auth/types.d.ts +52 -0
- package/dist/src/core/auth/types.js +3 -0
- package/dist/src/core/output/cli-error.d.ts +5 -0
- package/dist/src/core/output/cli-error.js +8 -0
- package/dist/src/core/output/detector.d.ts +5 -0
- package/dist/src/core/output/detector.js +14 -0
- package/dist/src/core/output/engine.d.ts +32 -0
- package/dist/src/core/output/engine.js +77 -0
- package/dist/src/core/output/envelope.d.ts +40 -0
- package/dist/src/core/output/envelope.js +119 -0
- package/dist/src/core/output/index.d.ts +4 -0
- package/dist/src/core/output/index.js +4 -0
- package/dist/src/core/output/live-display.d.ts +15 -0
- package/dist/src/core/output/live-display.js +111 -0
- package/dist/src/core/output/result-card.d.ts +18 -0
- package/dist/src/core/output/result-card.js +39 -0
- package/dist/src/core/prompt/index.d.ts +31 -0
- package/dist/src/core/prompt/index.js +36 -0
- package/dist/src/io.d.ts +14 -0
- package/dist/src/io.js +31 -0
- package/dist/src/middleware/auth.d.ts +3 -0
- package/dist/src/middleware/auth.js +74 -0
- package/dist/src/middleware/error-handler.d.ts +3 -0
- package/dist/src/middleware/error-handler.js +431 -0
- package/dist/src/middleware/interactive-params.d.ts +14 -0
- package/dist/src/middleware/interactive-params.js +53 -0
- package/dist/src/middleware/output.d.ts +14 -0
- package/dist/src/middleware/output.js +546 -0
- package/dist/src/models/model-catalog.d.ts +26 -0
- package/dist/src/models/model-catalog.js +216 -0
- package/dist/src/program.d.ts +2 -0
- package/dist/src/program.js +152 -0
- package/dist/src/registry/agent-contracts.d.ts +43 -0
- package/dist/src/registry/agent-contracts.js +483 -0
- package/dist/src/registry/app-loader.d.ts +2 -0
- package/dist/src/registry/app-loader.js +70 -0
- package/dist/src/registry/direct-registry.d.ts +11 -0
- package/dist/src/registry/direct-registry.js +234 -0
- package/dist/src/registry/registry-cache.d.ts +10 -0
- package/dist/src/registry/registry-cache.js +52 -0
- package/dist/src/registry/registry-client.d.ts +28 -0
- package/dist/src/registry/registry-client.js +50 -0
- package/dist/src/registry/types.d.ts +69 -0
- package/dist/src/registry/types.js +1 -0
- package/dist/src/tty/auth-presenter.d.ts +3 -0
- package/dist/src/tty/auth-presenter.js +21 -0
- package/dist/src/update/install-source.d.ts +19 -0
- package/dist/src/update/install-source.js +139 -0
- package/dist/src/update/notifier.d.ts +2 -0
- package/dist/src/update/notifier.js +59 -0
- package/dist/src/update/update-checker.d.ts +22 -0
- package/dist/src/update/update-checker.js +110 -0
- package/dist/src/update/version.d.ts +9 -0
- package/dist/src/update/version.js +52 -0
- package/dist/src/utils/agent-skill-installer.d.ts +57 -0
- package/dist/src/utils/agent-skill-installer.js +389 -0
- package/dist/src/utils/capability-metadata.d.ts +18 -0
- package/dist/src/utils/capability-metadata.js +88 -0
- package/dist/src/utils/capability-presenter.d.ts +4 -0
- package/dist/src/utils/capability-presenter.js +190 -0
- package/dist/src/utils/config.d.ts +16 -0
- package/dist/src/utils/config.js +54 -0
- package/dist/src/utils/credential-permissions.d.ts +2 -0
- package/dist/src/utils/credential-permissions.js +22 -0
- package/dist/src/utils/ecommerce-input-guidance.d.ts +15 -0
- package/dist/src/utils/ecommerce-input-guidance.js +85 -0
- package/dist/src/utils/endpoints.d.ts +52 -0
- package/dist/src/utils/endpoints.js +258 -0
- package/dist/src/utils/enrich-upload-params.d.ts +6 -0
- package/dist/src/utils/enrich-upload-params.js +11 -0
- package/dist/src/utils/entitlement.d.ts +17 -0
- package/dist/src/utils/entitlement.js +146 -0
- package/dist/src/utils/gd-home.d.ts +7 -0
- package/dist/src/utils/gd-home.js +26 -0
- package/dist/src/utils/help-verify.d.ts +9 -0
- package/dist/src/utils/help-verify.js +41 -0
- package/dist/src/utils/input-json.d.ts +3 -0
- package/dist/src/utils/input-json.js +61 -0
- package/dist/src/utils/list-output-format.d.ts +10 -0
- package/dist/src/utils/list-output-format.js +34 -0
- package/dist/src/utils/logger.d.ts +6 -0
- package/dist/src/utils/logger.js +19 -0
- package/dist/src/utils/matting-compose.d.ts +10 -0
- package/dist/src/utils/matting-compose.js +45 -0
- package/dist/src/utils/open-browser.d.ts +1 -0
- package/dist/src/utils/open-browser.js +4 -0
- package/dist/src/utils/output-path.d.ts +5 -0
- package/dist/src/utils/output-path.js +70 -0
- package/dist/src/utils/redact.d.ts +3 -0
- package/dist/src/utils/redact.js +96 -0
- package/dist/src/utils/reference-image.d.ts +8 -0
- package/dist/src/utils/reference-image.js +43 -0
- package/dist/src/utils/resolve-app-local-images.d.ts +8 -0
- package/dist/src/utils/resolve-app-local-images.js +84 -0
- package/dist/src/utils/sensitive-path.d.ts +6 -0
- package/dist/src/utils/sensitive-path.js +69 -0
- package/dist/src/utils/settings-store.d.ts +42 -0
- package/dist/src/utils/settings-store.js +50 -0
- package/dist/src/utils/sleep.d.ts +1 -0
- package/dist/src/utils/sleep.js +3 -0
- package/dist/src/utils/spinner.d.ts +2 -0
- package/dist/src/utils/spinner.js +4 -0
- package/dist/src/utils/static-help.d.ts +2 -0
- package/dist/src/utils/static-help.js +3 -0
- package/dist/src/utils/tool-display.d.ts +10 -0
- package/dist/src/utils/tool-display.js +55 -0
- package/dist/src/utils/transient-network-error.d.ts +4 -0
- package/dist/src/utils/transient-network-error.js +40 -0
- package/dist/src/utils/url-safety.d.ts +6 -0
- package/dist/src/utils/url-safety.js +67 -0
- package/dist/src/utils/write-app-deliverables.d.ts +18 -0
- package/dist/src/utils/write-app-deliverables.js +386 -0
- package/package.json +91 -0
- package/skills/gd-cli/SKILL.md +57 -0
- package/skills/gd-cli/references/auth.md +31 -0
- package/skills/gd-cli/references/deliverables.md +22 -0
- package/skills/gd-cli/references/entitlement.md +21 -0
- package/skills/gd-cli/references/errors.md +19 -0
- package/skills/gd-cli/references/org.md +18 -0
- package/skills/gd-cli/references/sop.md +25 -0
- package/skills/gd-cli/references/tools.md +29 -0
- package/skills/gd-cli/references/update.md +16 -0
- package/skills/gd-cli/references/workflows.md +22 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
3
|
+
export class LiveDisplay {
|
|
4
|
+
steps = [];
|
|
5
|
+
frameIndex = 0;
|
|
6
|
+
timer = null;
|
|
7
|
+
isTTY;
|
|
8
|
+
startedAt = 0;
|
|
9
|
+
constructor(tty) {
|
|
10
|
+
this.isTTY = tty ?? !!process.stderr.isTTY;
|
|
11
|
+
}
|
|
12
|
+
addStep(label) {
|
|
13
|
+
const idx = this.steps.length;
|
|
14
|
+
this.steps.push({ label, status: "pending" });
|
|
15
|
+
return idx;
|
|
16
|
+
}
|
|
17
|
+
startStep(idx) {
|
|
18
|
+
if (idx < this.steps.length) {
|
|
19
|
+
this.steps[idx].status = "running";
|
|
20
|
+
this.steps[idx].startedAt = Date.now();
|
|
21
|
+
}
|
|
22
|
+
if (!this.timer && this.isTTY) {
|
|
23
|
+
this.startedAt = this.startedAt || Date.now();
|
|
24
|
+
this.timer = setInterval(() => this.render(), 80);
|
|
25
|
+
}
|
|
26
|
+
if (!this.isTTY) {
|
|
27
|
+
this.emitProgress(idx);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
completeStep(idx) {
|
|
31
|
+
if (idx < this.steps.length) {
|
|
32
|
+
this.steps[idx].status = "done";
|
|
33
|
+
}
|
|
34
|
+
if (!this.isTTY) {
|
|
35
|
+
this.emitProgress(idx);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
failStep(idx) {
|
|
39
|
+
if (idx < this.steps.length) {
|
|
40
|
+
this.steps[idx].status = "failed";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
stop() {
|
|
44
|
+
if (this.timer) {
|
|
45
|
+
clearInterval(this.timer);
|
|
46
|
+
this.timer = null;
|
|
47
|
+
}
|
|
48
|
+
if (this.isTTY) {
|
|
49
|
+
this.render();
|
|
50
|
+
process.stderr.write("\n");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
render() {
|
|
54
|
+
if (!this.isTTY)
|
|
55
|
+
return;
|
|
56
|
+
this.frameIndex = (this.frameIndex + 1) % SPINNER_FRAMES.length;
|
|
57
|
+
const spinner = SPINNER_FRAMES[this.frameIndex];
|
|
58
|
+
const elapsed = ((Date.now() - this.startedAt) / 1000).toFixed(1);
|
|
59
|
+
const lines = [];
|
|
60
|
+
for (let i = 0; i < this.steps.length; i++) {
|
|
61
|
+
const step = this.steps[i];
|
|
62
|
+
let icon;
|
|
63
|
+
let text;
|
|
64
|
+
switch (step.status) {
|
|
65
|
+
case "pending":
|
|
66
|
+
icon = chalk.dim("○");
|
|
67
|
+
text = chalk.dim(step.label);
|
|
68
|
+
break;
|
|
69
|
+
case "running": {
|
|
70
|
+
icon = chalk.cyan(spinner);
|
|
71
|
+
const stepElapsed = step.startedAt ? ((Date.now() - step.startedAt) / 1000).toFixed(0) : "0";
|
|
72
|
+
text = chalk.cyan(`${step.label} (${stepElapsed}s)`);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case "done":
|
|
76
|
+
icon = chalk.green("✓");
|
|
77
|
+
text = chalk.green(step.label);
|
|
78
|
+
break;
|
|
79
|
+
case "failed":
|
|
80
|
+
icon = chalk.red("✗");
|
|
81
|
+
text = chalk.red(step.label);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
lines.push(` ${icon} ${text}`);
|
|
85
|
+
}
|
|
86
|
+
lines.push(chalk.dim(` ⏱ ${elapsed}s`));
|
|
87
|
+
const output = `\x1b[${this.steps.length + 1}A\x1b[0J` + lines.join("\n") + "\n";
|
|
88
|
+
if (this.frameIndex <= 1) {
|
|
89
|
+
process.stderr.write(lines.join("\n") + "\n");
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
process.stderr.write(output);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
emitProgress(idx) {
|
|
96
|
+
const step = this.steps[idx];
|
|
97
|
+
if (!step)
|
|
98
|
+
return;
|
|
99
|
+
const total = this.steps.length;
|
|
100
|
+
const completed = this.steps.filter((s) => s.status === "done").length;
|
|
101
|
+
const progress = {
|
|
102
|
+
type: "progress",
|
|
103
|
+
current: completed,
|
|
104
|
+
total,
|
|
105
|
+
step: step.label,
|
|
106
|
+
status: step.status,
|
|
107
|
+
percent: Math.round((completed / total) * 100),
|
|
108
|
+
};
|
|
109
|
+
process.stderr.write(JSON.stringify(progress) + "\n");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface CommandResult {
|
|
2
|
+
title?: string;
|
|
3
|
+
status: "success" | "error" | "info";
|
|
4
|
+
data: Record<string, unknown>;
|
|
5
|
+
nextSteps?: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare class ResultCard {
|
|
8
|
+
static render(result: CommandResult): void;
|
|
9
|
+
static success(data: Record<string, unknown>, opts?: {
|
|
10
|
+
title?: string;
|
|
11
|
+
nextSteps?: string[];
|
|
12
|
+
}): void;
|
|
13
|
+
static error(data: Record<string, unknown>, opts?: {
|
|
14
|
+
title?: string;
|
|
15
|
+
nextSteps?: string[];
|
|
16
|
+
}): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
export class ResultCard {
|
|
3
|
+
static render(result) {
|
|
4
|
+
const statusIcon = result.status === "success" ? chalk.green("✓") :
|
|
5
|
+
result.status === "error" ? chalk.red("✗") :
|
|
6
|
+
chalk.blue("ℹ");
|
|
7
|
+
const title = result.title ?? (result.status === "success" ? "完成" : result.status === "error" ? "失败" : "信息");
|
|
8
|
+
console.log("");
|
|
9
|
+
console.log(`${statusIcon} ${chalk.bold(title)}`);
|
|
10
|
+
console.log(chalk.dim("─".repeat(40)));
|
|
11
|
+
for (const [key, value] of Object.entries(result.data)) {
|
|
12
|
+
if (value === undefined || value === null)
|
|
13
|
+
continue;
|
|
14
|
+
if (typeof value === "string" && (value.startsWith("http://") || value.startsWith("https://"))) {
|
|
15
|
+
console.log(` ${chalk.dim(key + ":")} ${chalk.cyan.underline(value)}`);
|
|
16
|
+
}
|
|
17
|
+
else if (typeof value === "object") {
|
|
18
|
+
console.log(` ${chalk.dim(key + ":")} ${JSON.stringify(value)}`);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
console.log(` ${chalk.dim(key + ":")} ${String(value)}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (result.nextSteps && result.nextSteps.length > 0) {
|
|
25
|
+
console.log("");
|
|
26
|
+
console.log(chalk.dim(" 下一步:"));
|
|
27
|
+
for (const step of result.nextSteps) {
|
|
28
|
+
console.log(` ${chalk.dim("→")} ${step}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
console.log("");
|
|
32
|
+
}
|
|
33
|
+
static success(data, opts) {
|
|
34
|
+
this.render({ status: "success", data, ...opts });
|
|
35
|
+
}
|
|
36
|
+
static error(data, opts) {
|
|
37
|
+
this.render({ status: "error", data, ...opts });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare class ValidationError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class Prompt {
|
|
5
|
+
private static guard;
|
|
6
|
+
static select<T>(opts: {
|
|
7
|
+
message: string;
|
|
8
|
+
choices: {
|
|
9
|
+
name: string;
|
|
10
|
+
value: T;
|
|
11
|
+
description?: string;
|
|
12
|
+
}[];
|
|
13
|
+
}): Promise<T>;
|
|
14
|
+
static multiSelect<T>(opts: {
|
|
15
|
+
message: string;
|
|
16
|
+
choices: {
|
|
17
|
+
name: string;
|
|
18
|
+
value: T;
|
|
19
|
+
description?: string;
|
|
20
|
+
checked?: boolean;
|
|
21
|
+
disabled?: boolean | string;
|
|
22
|
+
}[];
|
|
23
|
+
}): Promise<T[]>;
|
|
24
|
+
static confirm(message: string, defaultValue?: boolean): Promise<boolean>;
|
|
25
|
+
static text(opts: {
|
|
26
|
+
message: string;
|
|
27
|
+
default?: string;
|
|
28
|
+
validate?: (value: string) => string | true;
|
|
29
|
+
}): Promise<string>;
|
|
30
|
+
}
|
|
31
|
+
export { ValidationError };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { select, checkbox, confirm, input } from "@inquirer/prompts";
|
|
2
|
+
class ValidationError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "ValidationError";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class Prompt {
|
|
9
|
+
static guard(actionDesc) {
|
|
10
|
+
if (!process.stdout.isTTY) {
|
|
11
|
+
throw new ValidationError(`此操作需要交互式输入(${actionDesc}),请通过参数直接指定。\n` +
|
|
12
|
+
` 示例: gd-cli auth login --org <org-id>`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
static async select(opts) {
|
|
16
|
+
this.guard(opts.message);
|
|
17
|
+
return select(opts);
|
|
18
|
+
}
|
|
19
|
+
static async multiSelect(opts) {
|
|
20
|
+
this.guard(opts.message);
|
|
21
|
+
return checkbox(opts);
|
|
22
|
+
}
|
|
23
|
+
static async confirm(message, defaultValue = true) {
|
|
24
|
+
this.guard(message);
|
|
25
|
+
return confirm({ message, default: defaultValue });
|
|
26
|
+
}
|
|
27
|
+
static async text(opts) {
|
|
28
|
+
this.guard(opts.message);
|
|
29
|
+
return input({
|
|
30
|
+
message: opts.message,
|
|
31
|
+
default: opts.default,
|
|
32
|
+
validate: opts.validate,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export { ValidationError };
|
package/dist/src/io.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一 TTY / 输出流检测(借鉴 gh IOStreams 思路,轻量实现)。
|
|
3
|
+
*/
|
|
4
|
+
export declare class IOStreams {
|
|
5
|
+
readonly stdinIsTTY: boolean;
|
|
6
|
+
readonly stdoutIsTTY: boolean;
|
|
7
|
+
readonly stderrIsTTY: boolean;
|
|
8
|
+
constructor();
|
|
9
|
+
/** Agent / CI:stdout 非 TTY 时默认 JSON */
|
|
10
|
+
prefersJsonOutput(explicitFormat?: string): boolean;
|
|
11
|
+
/** 授权等人机交互场景 */
|
|
12
|
+
isInteractiveAuth(): boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function getIO(): IOStreams;
|
package/dist/src/io.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一 TTY / 输出流检测(借鉴 gh IOStreams 思路,轻量实现)。
|
|
3
|
+
*/
|
|
4
|
+
export class IOStreams {
|
|
5
|
+
stdinIsTTY;
|
|
6
|
+
stdoutIsTTY;
|
|
7
|
+
stderrIsTTY;
|
|
8
|
+
constructor() {
|
|
9
|
+
this.stdinIsTTY = !!process.stdin.isTTY;
|
|
10
|
+
this.stdoutIsTTY = !!process.stdout.isTTY;
|
|
11
|
+
this.stderrIsTTY = !!process.stderr.isTTY;
|
|
12
|
+
}
|
|
13
|
+
/** Agent / CI:stdout 非 TTY 时默认 JSON */
|
|
14
|
+
prefersJsonOutput(explicitFormat) {
|
|
15
|
+
if (explicitFormat && explicitFormat !== "json")
|
|
16
|
+
return false;
|
|
17
|
+
if (explicitFormat === "json")
|
|
18
|
+
return true;
|
|
19
|
+
return !this.stdoutIsTTY;
|
|
20
|
+
}
|
|
21
|
+
/** 授权等人机交互场景 */
|
|
22
|
+
isInteractiveAuth() {
|
|
23
|
+
return this.stdoutIsTTY && this.stdinIsTTY;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
let _io = null;
|
|
27
|
+
export function getIO() {
|
|
28
|
+
if (!_io)
|
|
29
|
+
_io = new IOStreams();
|
|
30
|
+
return _io;
|
|
31
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CredentialStoreV2 } from "../auth/credential-store-v2.js";
|
|
2
|
+
import { OrgManager } from "../core/auth/org-manager.js";
|
|
3
|
+
function commandPath(cmd) {
|
|
4
|
+
const names = [];
|
|
5
|
+
let c = cmd;
|
|
6
|
+
while (c) {
|
|
7
|
+
const n = c.name();
|
|
8
|
+
if (n && !n.startsWith("-"))
|
|
9
|
+
names.unshift(n);
|
|
10
|
+
c = c.parent;
|
|
11
|
+
}
|
|
12
|
+
return names;
|
|
13
|
+
}
|
|
14
|
+
function shouldSkipAuth(cmd) {
|
|
15
|
+
const path = commandPath(cmd);
|
|
16
|
+
if (path.length === 0)
|
|
17
|
+
return false;
|
|
18
|
+
if (path[0] === "config")
|
|
19
|
+
return true;
|
|
20
|
+
if (path.includes("auth")) {
|
|
21
|
+
const sub = path[path.length - 1];
|
|
22
|
+
return sub === "login" || sub === "logout";
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
function isDirectBusinessCommand(cmd) {
|
|
27
|
+
const path = commandPath(cmd);
|
|
28
|
+
return path.includes("tools") || path.includes("workflows") || path.includes("dam");
|
|
29
|
+
}
|
|
30
|
+
export function withAuth(handler) {
|
|
31
|
+
return async (...args) => {
|
|
32
|
+
const command = args[args.length - 1];
|
|
33
|
+
if (shouldSkipAuth(command)) {
|
|
34
|
+
return handler(...args);
|
|
35
|
+
}
|
|
36
|
+
const v2Store = new CredentialStoreV2();
|
|
37
|
+
const v2 = v2Store.read();
|
|
38
|
+
if (v2) {
|
|
39
|
+
if (v2Store.isAkExpired()) {
|
|
40
|
+
console.error("Error: AK/SK 已过期");
|
|
41
|
+
console.error("\n 请重新登录:\n gd-cli auth login\n");
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
if (v2Store.isBindExpired() && v2.current_org?.id) {
|
|
45
|
+
try {
|
|
46
|
+
const orgMgr = new OrgManager();
|
|
47
|
+
await orgMgr.switchOrg(v2.current_org.id);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
console.error("Error: 组织绑定已过期");
|
|
51
|
+
console.error("\n 请切换组织:\n gd-cli org switch\n");
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (isDirectBusinessCommand(command) && !v2Store.read()?.current_org?.id) {
|
|
56
|
+
console.error("Error: 当前未绑定组织");
|
|
57
|
+
console.error("\n 请先切换组织:");
|
|
58
|
+
console.error(" gd-cli org switch\n");
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
return handler(...args);
|
|
62
|
+
}
|
|
63
|
+
if (isDirectBusinessCommand(command)) {
|
|
64
|
+
console.error("Error: 未找到 AK/SK 凭证");
|
|
65
|
+
console.error("\n 请先登录并绑定组织:");
|
|
66
|
+
console.error(" gd-cli auth login\n");
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
console.error("Error: 未找到 AK/SK 凭证");
|
|
70
|
+
console.error("\n 请先登录:");
|
|
71
|
+
console.error(" gd-cli auth login\n");
|
|
72
|
+
process.exit(1);
|
|
73
|
+
};
|
|
74
|
+
}
|