gaoding-cli 1.0.0-alpha.8 → 1.0.0-alpha.9
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 +18 -0
- package/README.md +47 -64
- package/dist/bin/gd-cli.js +2 -2
- package/dist/src/api/app-runner.d.ts +1 -4
- package/dist/src/api/app-runner.js +10 -42
- package/dist/src/api/dam-client.d.ts +0 -7
- package/dist/src/api/dam-client.js +0 -17
- package/dist/src/commands/auth.js +5 -41
- package/dist/src/commands/creative.js +37 -45
- package/dist/src/commands/dam.js +248 -110
- package/dist/src/commands/org.js +17 -39
- package/dist/src/commands/skills.js +24 -114
- package/dist/src/commands/update.js +10 -85
- package/dist/src/commands/usage.js +4 -17
- package/dist/src/commands/workflows.d.ts +1 -1
- package/dist/src/commands/workflows.js +283 -199
- package/dist/src/core/output/envelope.d.ts +1 -0
- package/dist/src/core/output/envelope.js +76 -6
- package/dist/src/creative/contract.d.ts +28 -80
- package/dist/src/creative/contract.js +23 -44
- package/dist/src/creative/protocol.js +6 -6
- package/dist/src/io.d.ts +0 -2
- package/dist/src/io.js +0 -8
- package/dist/src/middleware/error-handler.d.ts +7 -1
- package/dist/src/middleware/error-handler.js +59 -54
- package/dist/src/program.d.ts +1 -0
- package/dist/src/program.js +138 -41
- package/dist/src/registry/agent-contracts.d.ts +14 -26
- package/dist/src/registry/agent-contracts.js +214 -64
- package/dist/src/utils/capability-presenter.js +6 -29
- package/dist/src/utils/config.d.ts +2 -2
- package/dist/src/utils/config.js +1 -1
- package/dist/src/utils/sensitive-path.js +1 -4
- package/package.json +2 -1
- package/skills/gd-cli/SKILL.md +6 -6
- package/skills/gd-cli/references/auth.md +3 -10
- package/skills/gd-cli/references/creative.md +11 -11
- package/skills/gd-cli/references/entitlement.md +2 -2
- package/skills/gd-cli/references/errors.md +4 -4
- package/skills/gd-cli/references/org.md +3 -3
- package/skills/gd-cli/references/sop.md +5 -5
- package/skills/gd-cli/references/update.md +4 -3
- package/skills/gd-cli/references/workflows.md +6 -5
- package/dist/src/utils/list-output-format.d.ts +0 -10
- package/dist/src/utils/list-output-format.js +0 -34
package/dist/src/commands/org.js
CHANGED
|
@@ -3,28 +3,25 @@ import { withErrorHandler } from "../middleware/error-handler.js";
|
|
|
3
3
|
import { setAuthRequirement } from "../middleware/auth.js";
|
|
4
4
|
import { OrgManager } from "../core/auth/org-manager.js";
|
|
5
5
|
import { formatOutput } from "../middleware/output.js";
|
|
6
|
-
import { resolveInvokeOutputFormat, resolveListOutputFormat, } from "../utils/list-output-format.js";
|
|
7
6
|
import { getIO } from "../io.js";
|
|
8
7
|
import { emitJson, wrapEnvelope } from "../core/output/envelope.js";
|
|
9
|
-
import {
|
|
8
|
+
import { CliUsageError } from "../core/output/cli-error.js";
|
|
10
9
|
import { registerUsageCommand } from "./usage.js";
|
|
11
10
|
export function registerOrgCommand(program) {
|
|
12
11
|
const org = program
|
|
13
12
|
.command("org")
|
|
14
13
|
.usage("<command> [options]")
|
|
15
|
-
.description("查看与切换当前组织")
|
|
16
|
-
.configureHelp({ showGlobalOptions: true });
|
|
17
|
-
setStaticHelp(org, ORG_HELP);
|
|
14
|
+
.description("查看与切换当前组织");
|
|
18
15
|
const list = org
|
|
19
16
|
.command("list")
|
|
20
|
-
.alias("ls")
|
|
21
17
|
.description("列出可用组织")
|
|
18
|
+
.option("--json", "输出机器可读 JSON")
|
|
22
19
|
.action(withErrorHandler(async (_opts, command) => {
|
|
23
20
|
const cmd = command;
|
|
24
21
|
const manager = new OrgManager();
|
|
25
22
|
const orgs = await manager.listOrgs();
|
|
26
23
|
const current = manager.getCurrentOrgId();
|
|
27
|
-
const
|
|
24
|
+
const json = cmd.opts().json === true;
|
|
28
25
|
const rows = orgs.map((o) => ({
|
|
29
26
|
current: o.id === current ? "yes" : "",
|
|
30
27
|
name: o.name,
|
|
@@ -34,21 +31,17 @@ export function registerOrgCommand(program) {
|
|
|
34
31
|
status: o.status ?? "",
|
|
35
32
|
expires: formatExpireDate(o.expire_date),
|
|
36
33
|
}));
|
|
37
|
-
if (
|
|
34
|
+
if (json) {
|
|
38
35
|
emitJson(wrapEnvelope({ orgs, current_org_id: current }, { command: "org list" }));
|
|
39
36
|
return;
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
formatOutput({ orgs, current_org_id: current }, format);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
formatOutput(rows, format === "table" ? "table" : "text");
|
|
46
|
-
}
|
|
38
|
+
formatOutput(rows, "table");
|
|
47
39
|
}));
|
|
48
40
|
setAuthRequirement(list, "credential");
|
|
49
41
|
const current = org
|
|
50
42
|
.command("current")
|
|
51
43
|
.description("快速查询当前组织")
|
|
44
|
+
.option("--json", "输出机器可读 JSON")
|
|
52
45
|
.action(withErrorHandler(async (_opts, command) => {
|
|
53
46
|
const cmd = command;
|
|
54
47
|
const manager = new OrgManager();
|
|
@@ -59,9 +52,8 @@ export function registerOrgCommand(program) {
|
|
|
59
52
|
current_org: current ?? null,
|
|
60
53
|
next_command: current ? undefined : "gd-cli org list",
|
|
61
54
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
formatOutput(payload, "json");
|
|
55
|
+
if (cmd.opts().json === true) {
|
|
56
|
+
emitJson(wrapEnvelope(payload, { command: "org current" }));
|
|
65
57
|
return;
|
|
66
58
|
}
|
|
67
59
|
if (!current) {
|
|
@@ -76,9 +68,7 @@ export function registerOrgCommand(program) {
|
|
|
76
68
|
.command("switch")
|
|
77
69
|
.description("切换当前 CLI 组织(TTY 下可交互选择)")
|
|
78
70
|
.option("--org <org-id>", "组织 ID")
|
|
79
|
-
.action(withErrorHandler(async (options
|
|
80
|
-
const cmd = command;
|
|
81
|
-
const format = resolveListOutputFormat(cmd);
|
|
71
|
+
.action(withErrorHandler(async (options) => {
|
|
82
72
|
const manager = new OrgManager();
|
|
83
73
|
let orgId = options.org;
|
|
84
74
|
if (!orgId) {
|
|
@@ -100,34 +90,22 @@ export function registerOrgCommand(program) {
|
|
|
100
90
|
});
|
|
101
91
|
}
|
|
102
92
|
else {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
93
|
+
throw new CliUsageError({
|
|
94
|
+
code: "ORG_SELECTION_REQUIRED",
|
|
95
|
+
type: "validation",
|
|
96
|
+
message: "非交互环境请通过 --org <org-id> 指定要切换的组织。",
|
|
97
|
+
hint: "先执行 gd-cli org list 查看可用组织。",
|
|
98
|
+
retryable: false,
|
|
99
|
+
});
|
|
107
100
|
}
|
|
108
101
|
}
|
|
109
102
|
const result = await manager.switchOrg(orgId);
|
|
110
|
-
if (getIO().prefersJsonOutput(format)) {
|
|
111
|
-
emitJson(wrapEnvelope({ org: result }, { command: "org switch" }));
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
103
|
console.log(chalk.green(`\n✓ 已切换到组织: ${result.name} (${result.id})`));
|
|
115
104
|
console.log(chalk.yellow("\n请 60s 后再调用能力,即可按新组织的权益执行~\n"));
|
|
116
105
|
}));
|
|
117
106
|
setAuthRequirement(switchCommand, "credential");
|
|
118
107
|
registerUsageCommand(org);
|
|
119
108
|
}
|
|
120
|
-
const ORG_HELP = `
|
|
121
|
-
Usage: gd-cli org <command> [options]
|
|
122
|
-
|
|
123
|
-
用于查看和切换当前组织
|
|
124
|
-
|
|
125
|
-
常用命令:
|
|
126
|
-
list/ls 列出可用组织
|
|
127
|
-
current 查询当前组织
|
|
128
|
-
switch 切换当前组织
|
|
129
|
-
credits 查询当前组织的稿豆余额
|
|
130
|
-
`;
|
|
131
109
|
function formatOrgChoice(org, currentOrgId) {
|
|
132
110
|
const product = org.product_name ? ` · ${org.product_name}` : "";
|
|
133
111
|
const current = org.id === currentOrgId ? " ← 当前" : "";
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { CliUsageError } from "../core/output/cli-error.js";
|
|
2
|
-
import { emitJson,
|
|
3
|
-
import { Prompt } from "../core/prompt/index.js";
|
|
2
|
+
import { emitJson, wrapEnvelope, } from "../core/output/envelope.js";
|
|
4
3
|
import { withErrorHandler } from "../middleware/error-handler.js";
|
|
5
4
|
import { formatOutput } from "../middleware/output.js";
|
|
6
5
|
import { AgentSkillInstaller, AgentSkillOperationError, } from "../utils/agent-skill-installer.js";
|
|
7
6
|
import { collectArg } from "../utils/input-json.js";
|
|
8
|
-
import { resolveInvokeOutputFormat } from "../utils/list-output-format.js";
|
|
9
|
-
import { setStaticHelp } from "../utils/static-help.js";
|
|
10
7
|
import { setAuthRequirement } from "../middleware/auth.js";
|
|
11
8
|
const TARGET_IDS = [
|
|
12
9
|
"universal",
|
|
@@ -21,109 +18,73 @@ export function registerSkillsCommand(program) {
|
|
|
21
18
|
const skills = program
|
|
22
19
|
.command("skills")
|
|
23
20
|
.description("安装和管理 gd-cli Agent Skill");
|
|
24
|
-
setStaticHelp(skills, SKILLS_HELP);
|
|
25
21
|
const install = skills
|
|
26
22
|
.command("install")
|
|
27
23
|
.description("安装 gd-cli Agent Skill")
|
|
28
|
-
.option("
|
|
24
|
+
.option("--agent <id>", "目标 Agent,可重复", collectArg, [])
|
|
29
25
|
.option("--all", "安装到全部已知 Agent")
|
|
30
|
-
.option("-y, --yes", "跳过确认")
|
|
31
26
|
.allowExcessArguments(false)
|
|
32
|
-
.action(withErrorHandler(async (options
|
|
27
|
+
.action(withErrorHandler(async (options) => {
|
|
33
28
|
const installer = new AgentSkillInstaller();
|
|
34
|
-
const agents =
|
|
35
|
-
await confirmMutation("install", options, command);
|
|
29
|
+
const agents = resolveMutationTargets(options);
|
|
36
30
|
const result = runInstaller(() => installer.install(agents));
|
|
37
|
-
|
|
31
|
+
printMutationResult(result);
|
|
38
32
|
}));
|
|
39
33
|
setAuthRequirement(install, "none");
|
|
40
34
|
const status = skills
|
|
41
35
|
.command("status")
|
|
42
36
|
.description("查看七个固定 Agent target 的安装状态")
|
|
37
|
+
.option("--json", "输出机器可读 JSON")
|
|
43
38
|
.allowExcessArguments(false)
|
|
44
39
|
.action(withErrorHandler(async (_options, command) => {
|
|
45
|
-
|
|
40
|
+
const result = new AgentSkillInstaller().status();
|
|
41
|
+
if (command.opts().json === true) {
|
|
42
|
+
emitJson(wrapEnvelope(result, { command: "skills status" }));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
printMutationResult(result);
|
|
46
46
|
}));
|
|
47
47
|
setAuthRequirement(status, "none");
|
|
48
48
|
const update = skills
|
|
49
49
|
.command("update")
|
|
50
50
|
.description("刷新已安装的 gd-cli Agent Skill")
|
|
51
51
|
.allowExcessArguments(false)
|
|
52
|
-
.action(withErrorHandler(async (_options
|
|
52
|
+
.action(withErrorHandler(async (_options) => {
|
|
53
53
|
const installer = new AgentSkillInstaller();
|
|
54
54
|
const result = runInstaller(() => installer.update());
|
|
55
|
-
|
|
55
|
+
printMutationResult(result);
|
|
56
56
|
}));
|
|
57
57
|
setAuthRequirement(update, "none");
|
|
58
58
|
const uninstall = skills
|
|
59
59
|
.command("uninstall")
|
|
60
60
|
.description("卸载 gd-cli 托管的 Agent Skill")
|
|
61
|
-
.option("
|
|
61
|
+
.option("--agent <id>", "目标 Agent,可重复", collectArg, [])
|
|
62
62
|
.option("--all", "卸载全部已知 Agent target")
|
|
63
|
-
.option("-y, --yes", "跳过确认")
|
|
64
63
|
.allowExcessArguments(false)
|
|
65
|
-
.action(withErrorHandler(async (options
|
|
64
|
+
.action(withErrorHandler(async (options) => {
|
|
66
65
|
const installer = new AgentSkillInstaller();
|
|
67
|
-
const agents =
|
|
66
|
+
const agents = resolveMutationTargets(options);
|
|
68
67
|
if (agents.length === 0) {
|
|
69
|
-
|
|
68
|
+
printMutationResult(installer.uninstall([]));
|
|
70
69
|
return;
|
|
71
70
|
}
|
|
72
|
-
await confirmMutation("uninstall", options, command);
|
|
73
71
|
const result = runInstaller(() => installer.uninstall(agents));
|
|
74
|
-
|
|
72
|
+
printMutationResult(result);
|
|
75
73
|
}));
|
|
76
74
|
setAuthRequirement(uninstall, "none");
|
|
77
75
|
}
|
|
78
|
-
|
|
76
|
+
function resolveMutationTargets(options) {
|
|
79
77
|
const explicit = Array.isArray(options.agent)
|
|
80
78
|
? options.agent.map(String)
|
|
81
79
|
: [];
|
|
82
80
|
if (options.all && explicit.length > 0) {
|
|
83
81
|
throw usageError("--all 与 --agent 不能同时使用");
|
|
84
82
|
}
|
|
85
|
-
if (options.all)
|
|
83
|
+
if (options.all || explicit.length === 0)
|
|
86
84
|
return [...TARGET_IDS];
|
|
87
85
|
if (explicit.length > 0)
|
|
88
86
|
return validateTargets(explicit);
|
|
89
|
-
|
|
90
|
-
throw usageError(`非交互环境必须通过 --agent <id> 或 --all 指定目标,并使用 --yes;例如 gd-cli skills ${operation} --agent codex --yes`);
|
|
91
|
-
}
|
|
92
|
-
if (operation === "install") {
|
|
93
|
-
const detected = new Set(installer.detectedTargets());
|
|
94
|
-
const selected = await Prompt.multiSelect({
|
|
95
|
-
message: "选择要安装 gd-cli Skill 的 Agent",
|
|
96
|
-
choices: installer.listTargets().map((target) => ({
|
|
97
|
-
name: `${target.name} ${target.path}`,
|
|
98
|
-
value: target.id,
|
|
99
|
-
description: target.id === "universal"
|
|
100
|
-
? "canonical copy"
|
|
101
|
-
: "链接到 canonical copy",
|
|
102
|
-
checked: target.id === "universal" || detected.has(target.id),
|
|
103
|
-
disabled: target.id === "universal" ? "始终安装" : false,
|
|
104
|
-
})),
|
|
105
|
-
});
|
|
106
|
-
return validateTargets(selected.filter((target) => target !== "universal"));
|
|
107
|
-
}
|
|
108
|
-
const status = installer.status();
|
|
109
|
-
const installed = new Set(status.targets
|
|
110
|
-
.filter((target) => target.status === "installed" || target.status === "outdated")
|
|
111
|
-
.map((target) => target.agent));
|
|
112
|
-
if (installed.size === 0)
|
|
113
|
-
return [];
|
|
114
|
-
const selected = await Prompt.multiSelect({
|
|
115
|
-
message: "选择要卸载 gd-cli Skill 的 Agent",
|
|
116
|
-
choices: installer.listTargets()
|
|
117
|
-
.filter((target) => installed.has(target.id))
|
|
118
|
-
.map((target) => ({
|
|
119
|
-
name: `${target.name} ${target.path}`,
|
|
120
|
-
value: target.id,
|
|
121
|
-
description: target.id === "universal"
|
|
122
|
-
? "仅当没有其他 Agent 依赖时可删除"
|
|
123
|
-
: "只删除该 Agent target",
|
|
124
|
-
})),
|
|
125
|
-
});
|
|
126
|
-
return validateTargets(selected);
|
|
87
|
+
return [];
|
|
127
88
|
}
|
|
128
89
|
function validateTargets(values) {
|
|
129
90
|
const targets = [];
|
|
@@ -137,18 +98,6 @@ function validateTargets(values) {
|
|
|
137
98
|
}
|
|
138
99
|
return targets;
|
|
139
100
|
}
|
|
140
|
-
async function confirmMutation(operation, options, command) {
|
|
141
|
-
if (options.yes || rootYes(command))
|
|
142
|
-
return;
|
|
143
|
-
if (!canPrompt(command)) {
|
|
144
|
-
throw usageError(`非交互环境必须使用 --yes 确认 gd-cli skills ${operation}`);
|
|
145
|
-
}
|
|
146
|
-
const accepted = await Prompt.confirm(operation === "install"
|
|
147
|
-
? "是否安装 gd-cli Agent Skill?"
|
|
148
|
-
: "是否卸载所选 gd-cli Agent Skill?", false);
|
|
149
|
-
if (!accepted)
|
|
150
|
-
throw usageError("已取消,未修改任何文件");
|
|
151
|
-
}
|
|
152
101
|
function runInstaller(operation) {
|
|
153
102
|
try {
|
|
154
103
|
return operation();
|
|
@@ -166,14 +115,8 @@ function runInstaller(operation) {
|
|
|
166
115
|
throw error;
|
|
167
116
|
}
|
|
168
117
|
}
|
|
169
|
-
function
|
|
170
|
-
|
|
171
|
-
if (shouldEmitEnvelope(format)) {
|
|
172
|
-
emitJson(wrapEnvelope(result, { command: commandName }));
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
formatOutput(result, format);
|
|
176
|
-
}
|
|
118
|
+
function printMutationResult(result) {
|
|
119
|
+
formatOutput(result, "human");
|
|
177
120
|
}
|
|
178
121
|
function usageError(message) {
|
|
179
122
|
return new CliUsageError({
|
|
@@ -183,36 +126,3 @@ function usageError(message) {
|
|
|
183
126
|
retryable: false,
|
|
184
127
|
});
|
|
185
128
|
}
|
|
186
|
-
function canPrompt(command) {
|
|
187
|
-
const options = rootOptions(command);
|
|
188
|
-
return options.noInput !== true
|
|
189
|
-
&& options.input !== false
|
|
190
|
-
&& Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
191
|
-
}
|
|
192
|
-
function rootYes(command) {
|
|
193
|
-
return Boolean(rootOptions(command).yes);
|
|
194
|
-
}
|
|
195
|
-
function rootOptions(command) {
|
|
196
|
-
let current = command;
|
|
197
|
-
while (current.parent)
|
|
198
|
-
current = current.parent;
|
|
199
|
-
return current.opts();
|
|
200
|
-
}
|
|
201
|
-
const SKILLS_HELP = `
|
|
202
|
-
gd-cli skills <command> [options]
|
|
203
|
-
|
|
204
|
-
安装和管理随 gaoding-cli 发布的 gd-cli Agent Skill。
|
|
205
|
-
|
|
206
|
-
命令:
|
|
207
|
-
install 安装 canonical Skill,并连接所选 Agent
|
|
208
|
-
status 查看七个固定 Agent target
|
|
209
|
-
update 刷新已安装的 canonical 和 fallback copy
|
|
210
|
-
uninstall 删除所选 gd-cli 托管 target
|
|
211
|
-
|
|
212
|
-
示例:
|
|
213
|
-
gd-cli skills install
|
|
214
|
-
gd-cli skills install --agent codex --yes --format json
|
|
215
|
-
gd-cli skills status --format json
|
|
216
|
-
gd-cli skills update
|
|
217
|
-
gd-cli skills uninstall --all --yes
|
|
218
|
-
`;
|
|
@@ -1,108 +1,42 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
-
import { confirm } from "@inquirer/prompts";
|
|
4
3
|
import { withErrorHandler } from "../middleware/error-handler.js";
|
|
5
4
|
import { buildUpdateCommand, detectInstallSource } from "../update/install-source.js";
|
|
6
|
-
import { checkForUpdate
|
|
5
|
+
import { checkForUpdate } from "../update/update-checker.js";
|
|
7
6
|
import { AgentSkillInstaller } from "../utils/agent-skill-installer.js";
|
|
8
7
|
import { setAuthRequirement } from "../middleware/auth.js";
|
|
9
8
|
export function registerUpdateCommand(program) {
|
|
10
9
|
const update = program
|
|
11
10
|
.command("update")
|
|
12
11
|
.description("检查并升级 gd-cli")
|
|
13
|
-
.option("--channel <tag>", "npm dist-tag: latest / next / alpha", "latest")
|
|
14
|
-
.option("--manager <name>", "指定包管理器: npm / pnpm / yarn / brew")
|
|
15
|
-
.option("--dry-run", "只显示升级命令,不执行")
|
|
16
|
-
.option("-y, --yes", "跳过确认直接升级")
|
|
17
|
-
.action(withErrorHandler(async (options, command) => {
|
|
18
|
-
await runUpdate(options, command);
|
|
19
|
-
}));
|
|
20
|
-
setAuthRequirement(update, "none");
|
|
21
|
-
const check = update
|
|
22
|
-
.command("check")
|
|
23
|
-
.description("检查是否有新版本")
|
|
24
|
-
.option("--channel <tag>", "npm dist-tag: latest / next / alpha", "latest")
|
|
25
|
-
.option("--force", "忽略 24 小时缓存,强制请求 registry")
|
|
26
|
-
.action(withErrorHandler(async (options, command) => {
|
|
27
|
-
const info = await checkForUpdate({
|
|
28
|
-
channel: options.channel,
|
|
29
|
-
force: options.force,
|
|
30
|
-
});
|
|
31
|
-
printUpdateInfo(info, outputFormat(command));
|
|
32
|
-
}));
|
|
33
|
-
setAuthRequirement(check, "none");
|
|
34
|
-
const clearCache = update
|
|
35
|
-
.command("clear-cache")
|
|
36
|
-
.description("清除本地升级检查缓存")
|
|
37
12
|
.action(withErrorHandler(async () => {
|
|
38
|
-
|
|
39
|
-
console.log(chalk.green("✓ 已清除升级检查缓存"));
|
|
13
|
+
await runUpdate();
|
|
40
14
|
}));
|
|
41
|
-
setAuthRequirement(
|
|
15
|
+
setAuthRequirement(update, "none");
|
|
42
16
|
}
|
|
43
|
-
async function runUpdate(
|
|
17
|
+
async function runUpdate() {
|
|
44
18
|
const info = await checkForUpdate({
|
|
45
|
-
channel:
|
|
19
|
+
channel: "latest",
|
|
46
20
|
force: true,
|
|
47
21
|
});
|
|
48
|
-
const source = detectInstallSource(
|
|
22
|
+
const source = detectInstallSource();
|
|
49
23
|
const updateCommand = buildUpdateCommand(info.latest_version, source);
|
|
50
|
-
const format = outputFormat(command);
|
|
51
24
|
if (!info.update_available) {
|
|
52
|
-
printUpdateInfo({ ...info, install_source: source }
|
|
25
|
+
printUpdateInfo({ ...info, install_source: source });
|
|
53
26
|
return;
|
|
54
27
|
}
|
|
55
28
|
if (source.kind !== "global") {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
install_source: source,
|
|
59
|
-
update_command: updateCommand.display,
|
|
60
|
-
blocked: true,
|
|
61
|
-
reason: source.reason,
|
|
62
|
-
};
|
|
63
|
-
if (format === "json") {
|
|
64
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
console.log(chalk.yellow(`${source.reason},gd-cli update 不会修改全局环境。`));
|
|
68
|
-
console.log(`如需升级全局安装,请手动执行: ${chalk.cyan(updateCommand.display)}`);
|
|
69
|
-
}
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (options.dryRun) {
|
|
73
|
-
printUpdateInfo({
|
|
74
|
-
...info,
|
|
75
|
-
install_source: source,
|
|
76
|
-
}, format, updateCommand.display);
|
|
29
|
+
console.log(chalk.yellow(`${source.reason},gd-cli update 不会修改全局环境。`));
|
|
30
|
+
console.log(`如需升级全局安装,请手动执行: ${chalk.cyan(updateCommand.display)}`);
|
|
77
31
|
return;
|
|
78
32
|
}
|
|
79
|
-
if (!options.yes && process.stdin.isTTY) {
|
|
80
|
-
const ok = await confirm({
|
|
81
|
-
message: `将执行 ${updateCommand.display},是否继续?`,
|
|
82
|
-
default: true,
|
|
83
|
-
});
|
|
84
|
-
if (!ok) {
|
|
85
|
-
console.log("已取消升级。");
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else if (!options.yes && !process.stdin.isTTY) {
|
|
90
|
-
throw new Error(`非交互环境请加 --yes,或手动执行: ${updateCommand.display}`);
|
|
91
|
-
}
|
|
92
33
|
const shouldRefreshAgentSkill = hasInstalledCanonicalSkill();
|
|
93
34
|
await spawnUpdate(updateCommand.command, updateCommand.args);
|
|
94
35
|
if (shouldRefreshAgentSkill) {
|
|
95
36
|
await refreshAgentSkillAfterUpdate();
|
|
96
37
|
}
|
|
97
38
|
}
|
|
98
|
-
function printUpdateInfo(info,
|
|
99
|
-
if (format === "json") {
|
|
100
|
-
console.log(JSON.stringify({
|
|
101
|
-
...info,
|
|
102
|
-
update_command: updateCommand ?? buildUpdateCommand(info.latest_version, info.install_source).display,
|
|
103
|
-
}, null, 2));
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
39
|
+
function printUpdateInfo(info, updateCommand) {
|
|
106
40
|
console.log(chalk.bold("\ngd-cli 版本检查\n"));
|
|
107
41
|
console.log(` 当前版本: ${chalk.cyan(info.current_version)}`);
|
|
108
42
|
console.log(` 最新版本: ${chalk.cyan(info.latest_version)} (${info.channel})`);
|
|
@@ -123,15 +57,6 @@ function printUpdateInfo(info, format, updateCommand) {
|
|
|
123
57
|
}
|
|
124
58
|
console.log("");
|
|
125
59
|
}
|
|
126
|
-
function outputFormat(command) {
|
|
127
|
-
return rootCommand(command).opts().format ?? "human";
|
|
128
|
-
}
|
|
129
|
-
function rootCommand(command) {
|
|
130
|
-
let cur = command;
|
|
131
|
-
while (cur.parent)
|
|
132
|
-
cur = cur.parent;
|
|
133
|
-
return cur;
|
|
134
|
-
}
|
|
135
60
|
function spawnUpdate(command, args) {
|
|
136
61
|
return new Promise((resolve, reject) => {
|
|
137
62
|
const child = spawn(command, args, {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { UsageClient } from "../api/usage-client.js";
|
|
3
3
|
import { withErrorHandler } from "../middleware/error-handler.js";
|
|
4
|
-
import { formatOutput } from "../middleware/output.js";
|
|
5
4
|
import { setAuthRequirement } from "../middleware/auth.js";
|
|
5
|
+
import { emitJson, wrapEnvelope } from "../core/output/envelope.js";
|
|
6
6
|
export function registerUsageCommand(org, deps = {}) {
|
|
7
7
|
const credits = org
|
|
8
8
|
.command("credits")
|
|
9
9
|
.description("查询当前组织的稿豆余额")
|
|
10
|
+
.option("--json", "输出机器可读 JSON")
|
|
10
11
|
.action(withErrorHandler(async (_options, command) => {
|
|
11
12
|
const client = deps.createClient?.() ?? new UsageClient();
|
|
12
13
|
const payload = await client.getCreditsOverview();
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
formatOutput(payload, "json");
|
|
14
|
+
if (command.opts().json === true) {
|
|
15
|
+
emitJson(wrapEnvelope(payload, { command: "org credits" }));
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
printUsageHuman(payload);
|
|
@@ -30,16 +30,3 @@ function printUsageHuman(payload) {
|
|
|
30
30
|
console.log(` 待生效: ${credits.wait}`);
|
|
31
31
|
console.log("");
|
|
32
32
|
}
|
|
33
|
-
function outputFormat(command) {
|
|
34
|
-
const root = rootCommand(command);
|
|
35
|
-
const opts = root.opts();
|
|
36
|
-
if (opts.json)
|
|
37
|
-
return "json";
|
|
38
|
-
return opts.format ?? "human";
|
|
39
|
-
}
|
|
40
|
-
function rootCommand(command) {
|
|
41
|
-
let current = command;
|
|
42
|
-
while (current.parent)
|
|
43
|
-
current = current.parent;
|
|
44
|
-
return current;
|
|
45
|
-
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
export declare function registerWorkflowsCommand(program: Command): void;
|
|
3
|
-
export declare function runAppCall(appId: string,
|
|
3
|
+
export declare function runAppCall(appId: string, opts: Record<string, unknown>): Promise<void>;
|