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