gaoding-cli 1.0.0-alpha.10

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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -0
  3. package/contracts/operations/agent.send/input.schema.json +354 -0
  4. package/contracts/operations/agent.send/output.schema.json +271 -0
  5. package/contracts/operations/auth.status/input.schema.json +7 -0
  6. package/contracts/operations/auth.status/output.schema.json +132 -0
  7. package/contracts/operations/dam.delete/input.schema.json +23 -0
  8. package/contracts/operations/dam.delete/output.schema.json +6 -0
  9. package/contracts/operations/dam.get/input.schema.json +16 -0
  10. package/contracts/operations/dam.get/output.schema.json +46 -0
  11. package/contracts/operations/dam.list/input.schema.json +44 -0
  12. package/contracts/operations/dam.list/output.schema.json +71 -0
  13. package/contracts/operations/dam.search/input.schema.json +46 -0
  14. package/contracts/operations/dam.search/output.schema.json +71 -0
  15. package/contracts/operations/dam.upload/input.schema.json +31 -0
  16. package/contracts/operations/dam.upload/output.schema.json +46 -0
  17. package/contracts/operations/editor.apply/input.schema.json +134 -0
  18. package/contracts/operations/editor.apply/output.schema.json +15 -0
  19. package/contracts/operations/editor.connect/input.schema.json +15 -0
  20. package/contracts/operations/editor.connect/output.schema.json +17 -0
  21. package/contracts/operations/editor.disconnect/input.schema.json +8 -0
  22. package/contracts/operations/editor.disconnect/output.schema.json +14 -0
  23. package/contracts/operations/editor.save/input.schema.json +8 -0
  24. package/contracts/operations/editor.save/output.schema.json +23 -0
  25. package/contracts/operations/editor.screenshot/input.schema.json +8 -0
  26. package/contracts/operations/editor.screenshot/output.schema.json +16 -0
  27. package/contracts/operations/editor.snapshot/input.schema.json +8 -0
  28. package/contracts/operations/editor.snapshot/output.schema.json +113 -0
  29. package/contracts/operations/model.get/input.schema.json +18 -0
  30. package/contracts/operations/model.get/output.schema.json +190 -0
  31. package/contracts/operations/model.list/input.schema.json +15 -0
  32. package/contracts/operations/model.list/output.schema.json +111 -0
  33. package/contracts/operations/org.current/input.schema.json +7 -0
  34. package/contracts/operations/org.current/output.schema.json +49 -0
  35. package/contracts/operations/org.list/input.schema.json +7 -0
  36. package/contracts/operations/org.list/output.schema.json +71 -0
  37. package/contracts/operations/tool.call/input.schema.json +35 -0
  38. package/contracts/operations/tool.call/output.schema.json +129 -0
  39. package/contracts/operations/tool.list/input.schema.json +7 -0
  40. package/contracts/operations/tool.list/output.schema.json +45 -0
  41. package/dist/bin/gd-cli.js +38 -0
  42. package/dist/bin/postinstall.js +42 -0
  43. package/dist/src/bootstrap/create-cli.js +55 -0
  44. package/dist/src/bootstrap/create-runtime.js +222 -0
  45. package/dist/src/bootstrap/validators.js +118 -0
  46. package/dist/src/cli/action-binding.js +63 -0
  47. package/dist/src/cli/agent-commands.js +39 -0
  48. package/dist/src/cli/auth-commands.js +47 -0
  49. package/dist/src/cli/dam-commands.js +207 -0
  50. package/dist/src/cli/editor-commands.js +73 -0
  51. package/dist/src/cli/errors.js +90 -0
  52. package/dist/src/cli/model-commands.js +47 -0
  53. package/dist/src/cli/org-commands.js +52 -0
  54. package/dist/src/cli/presenter.js +80 -0
  55. package/dist/src/cli/prompt.js +30 -0
  56. package/dist/src/cli/tool-commands.js +65 -0
  57. package/dist/src/cli/update-command.js +12 -0
  58. package/dist/src/contracts/schema.js +4 -0
  59. package/dist/src/features/agent/creative-agent-adapter.js +31 -0
  60. package/dist/src/features/agent/creative-protocol.js +324 -0
  61. package/dist/src/features/agent/creative-stream.js +127 -0
  62. package/dist/src/features/agent/use-cases.js +113 -0
  63. package/dist/src/features/auth/access-policy.js +101 -0
  64. package/dist/src/features/auth/credential-store.js +62 -0
  65. package/dist/src/features/auth/sso-service.js +179 -0
  66. package/dist/src/features/auth/state.js +129 -0
  67. package/dist/src/features/auth/use-cases.js +106 -0
  68. package/dist/src/features/dam/asset-projection.js +270 -0
  69. package/dist/src/features/dam/dam-api-adapter.js +206 -0
  70. package/dist/src/features/dam/object-storage.js +191 -0
  71. package/dist/src/features/dam/registered-uploader.js +224 -0
  72. package/dist/src/features/dam/storage-upload.js +141 -0
  73. package/dist/src/features/dam/transient-uploader.js +17 -0
  74. package/dist/src/features/dam/use-cases.js +151 -0
  75. package/dist/src/features/editor/bridge-client.js +96 -0
  76. package/dist/src/features/editor/bridge-process.js +222 -0
  77. package/dist/src/features/editor/bridge-server.js +311 -0
  78. package/dist/src/features/editor/protocol.js +1 -0
  79. package/dist/src/features/editor/session-state.js +78 -0
  80. package/dist/src/features/editor/session.js +193 -0
  81. package/dist/src/features/editor/use-cases.js +61 -0
  82. package/dist/src/features/org/org-service.js +76 -0
  83. package/dist/src/features/org/use-cases.js +140 -0
  84. package/dist/src/features/skill/bundled-skills.js +55 -0
  85. package/dist/src/features/skill/installer.js +265 -0
  86. package/dist/src/features/tool/catalog.js +79 -0
  87. package/dist/src/features/tool/dynamic-schema.js +96 -0
  88. package/dist/src/features/tool/mns-catalog-adapter.js +262 -0
  89. package/dist/src/features/tool/tool-api-adapter.js +200 -0
  90. package/dist/src/features/tool/use-cases.js +126 -0
  91. package/dist/src/features/update/update-service.js +194 -0
  92. package/dist/src/platform/json-input.js +64 -0
  93. package/dist/src/platform/local-json-file.js +59 -0
  94. package/dist/src/platform/open-browser.js +8 -0
  95. package/dist/src/platform/redact.js +80 -0
  96. package/dist/src/platform/safe-upload-file.js +146 -0
  97. package/dist/src/platform/signature.js +19 -0
  98. package/dist/src/platform/signed-http-transport.js +109 -0
  99. package/dist/src/platform/url-safety.js +100 -0
  100. package/package.json +56 -0
  101. package/skills/gd-cli/SKILL.md +15 -0
  102. package/skills/gd-cli/references/auth-org.md +9 -0
  103. package/skills/gd-cli/references/creation.md +38 -0
  104. package/skills/gd-cli/references/dam.md +20 -0
  105. package/skills/gd-cli/references/editor.md +12 -0
  106. package/skills/gd-cli/references/errors.md +10 -0
  107. package/skills/gd-cli/references/update.md +11 -0
@@ -0,0 +1,111 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "ModelListResult",
4
+ "description": "当前可用的创作模型摘要。",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "models"
9
+ ],
10
+ "properties": {
11
+ "models": {
12
+ "type": "array",
13
+ "description": "当前已发布且至少有一个上架 SKU 的创作模型。",
14
+ "items": {
15
+ "$ref": "#/$defs/ModelSummary"
16
+ }
17
+ }
18
+ },
19
+ "$defs": {
20
+ "NonBlankString": {
21
+ "type": "string",
22
+ "minLength": 1,
23
+ "pattern": ".*\\S.*"
24
+ },
25
+ "CostRange": {
26
+ "type": "object",
27
+ "additionalProperties": false,
28
+ "required": [
29
+ "unit",
30
+ "minimum",
31
+ "maximum"
32
+ ],
33
+ "properties": {
34
+ "unit": {
35
+ "const": "gaodou",
36
+ "description": "稿豆计价单位。"
37
+ },
38
+ "minimum": {
39
+ "type": "number",
40
+ "minimum": 0,
41
+ "description": "当前可用配置中的最低稿豆消耗。"
42
+ },
43
+ "maximum": {
44
+ "type": "number",
45
+ "minimum": 0,
46
+ "description": "当前可用配置中的最高稿豆消耗。"
47
+ }
48
+ }
49
+ },
50
+ "EstimatedTimeRange": {
51
+ "type": "object",
52
+ "additionalProperties": false,
53
+ "required": [
54
+ "unit",
55
+ "minimum",
56
+ "maximum"
57
+ ],
58
+ "properties": {
59
+ "unit": {
60
+ "const": "second",
61
+ "description": "秒级耗时单位。"
62
+ },
63
+ "minimum": {
64
+ "type": "number",
65
+ "minimum": 0,
66
+ "description": "当前可用配置中的最短预估耗时。"
67
+ },
68
+ "maximum": {
69
+ "type": "number",
70
+ "minimum": 0,
71
+ "description": "当前可用配置中的最长预估耗时。"
72
+ }
73
+ }
74
+ },
75
+ "ModelSummary": {
76
+ "type": "object",
77
+ "additionalProperties": false,
78
+ "required": [
79
+ "tool",
80
+ "model",
81
+ "title"
82
+ ],
83
+ "properties": {
84
+ "tool": {
85
+ "$ref": "#/$defs/NonBlankString",
86
+ "description": "模型所属的产品创作工具。"
87
+ },
88
+ "model": {
89
+ "$ref": "#/$defs/NonBlankString",
90
+ "description": "调用模型时使用的机器标识。"
91
+ },
92
+ "title": {
93
+ "$ref": "#/$defs/NonBlankString",
94
+ "description": "模型的展示名称。"
95
+ },
96
+ "description": {
97
+ "$ref": "#/$defs/NonBlankString",
98
+ "description": "模型的用途说明。"
99
+ },
100
+ "cost": {
101
+ "$ref": "#/$defs/CostRange",
102
+ "description": "模型当前可用配置的稿豆消耗区间。"
103
+ },
104
+ "estimatedTime": {
105
+ "$ref": "#/$defs/EstimatedTimeRange",
106
+ "description": "模型当前可用配置的预估耗时区间。"
107
+ }
108
+ }
109
+ }
110
+ }
111
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.gaoding.com/operations/org.current/input.schema.json",
4
+ "title": "OrgCurrentInput",
5
+ "type": "object",
6
+ "additionalProperties": false
7
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.gaoding.com/operations/org.current/output.schema.json",
4
+ "title": "OrgCurrentResult",
5
+ "description": "本机当前选择的组织。",
6
+ "type": "object",
7
+ "required": [
8
+ "organization",
9
+ "next_steps"
10
+ ],
11
+ "properties": {
12
+ "organization": {
13
+ "description": "本机当前选择的组织;尚未选择时为 null。",
14
+ "oneOf": [
15
+ {
16
+ "type": "null"
17
+ },
18
+ {
19
+ "type": "object",
20
+ "required": [
21
+ "id",
22
+ "name"
23
+ ],
24
+ "properties": {
25
+ "id": {
26
+ "type": "string",
27
+ "minLength": 1,
28
+ "description": "当前组织 ID。"
29
+ },
30
+ "name": {
31
+ "type": "string",
32
+ "minLength": 1,
33
+ "description": "当前组织名称。"
34
+ }
35
+ },
36
+ "additionalProperties": false
37
+ }
38
+ ]
39
+ },
40
+ "next_steps": {
41
+ "type": "array",
42
+ "description": "尚未选择组织时的下一步命令。",
43
+ "items": {
44
+ "type": "string"
45
+ }
46
+ }
47
+ },
48
+ "additionalProperties": false
49
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.gaoding.com/operations/org.list/input.schema.json",
4
+ "title": "OrgListInput",
5
+ "type": "object",
6
+ "additionalProperties": false
7
+ }
@@ -0,0 +1,71 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.gaoding.com/operations/org.list/output.schema.json",
4
+ "title": "OrgListResult",
5
+ "description": "当前账号可以访问的组织列表。",
6
+ "type": "object",
7
+ "required": [
8
+ "orgs",
9
+ "current_org_id"
10
+ ],
11
+ "properties": {
12
+ "orgs": {
13
+ "type": "array",
14
+ "description": "当前账号可以访问的组织。",
15
+ "items": {
16
+ "$ref": "#/$defs/OrgSummary"
17
+ }
18
+ },
19
+ "current_org_id": {
20
+ "type": [
21
+ "string",
22
+ "null"
23
+ ],
24
+ "description": "本机当前选择的组织 ID;尚未选择时为 null。"
25
+ }
26
+ },
27
+ "additionalProperties": false,
28
+ "$defs": {
29
+ "OrgSummary": {
30
+ "type": "object",
31
+ "required": [
32
+ "id",
33
+ "name"
34
+ ],
35
+ "properties": {
36
+ "id": {
37
+ "type": "string",
38
+ "minLength": 1,
39
+ "description": "组织 ID。"
40
+ },
41
+ "name": {
42
+ "type": "string",
43
+ "minLength": 1,
44
+ "description": "组织名称。"
45
+ },
46
+ "type": {
47
+ "type": "string",
48
+ "description": "组织类型。"
49
+ },
50
+ "status": {
51
+ "type": "string",
52
+ "description": "组织状态。"
53
+ },
54
+ "product_name": {
55
+ "type": "string",
56
+ "description": "当前产品版本名称。"
57
+ },
58
+ "product_type": {
59
+ "type": "string",
60
+ "description": "当前产品版本类型。"
61
+ },
62
+ "expires_at": {
63
+ "type": "string",
64
+ "format": "date-time",
65
+ "description": "产品到期时间,ISO 8601。"
66
+ }
67
+ },
68
+ "additionalProperties": false
69
+ }
70
+ }
71
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "ToolCallInput",
4
+ "description": "调用一个产品创作工具的结构化输入。",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "name",
9
+ "arguments"
10
+ ],
11
+ "properties": {
12
+ "name": {
13
+ "type": "string",
14
+ "minLength": 1,
15
+ "pattern": ".*\\S.*",
16
+ "description": "要调用的产品创作工具机器标识。"
17
+ },
18
+ "arguments": {
19
+ "type": "object",
20
+ "description": "当前工具与模型接受的动态参数。",
21
+ "required": [
22
+ "model"
23
+ ],
24
+ "properties": {
25
+ "model": {
26
+ "type": "string",
27
+ "minLength": 1,
28
+ "pattern": ".*\\S.*",
29
+ "description": "要调用的创作模型机器标识。"
30
+ }
31
+ },
32
+ "additionalProperties": true
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,129 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "ToolCallOutput",
4
+ "description": "创作工具同步返回的最终内容与所选模型成本。",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "content",
9
+ "usage"
10
+ ],
11
+ "properties": {
12
+ "content": {
13
+ "type": "array",
14
+ "description": "创作工具最终产出的文本或资源链接。",
15
+ "items": {
16
+ "oneOf": [
17
+ {
18
+ "$ref": "#/$defs/TextContent"
19
+ },
20
+ {
21
+ "$ref": "#/$defs/ResourceLink"
22
+ }
23
+ ]
24
+ }
25
+ },
26
+ "usage": {
27
+ "$ref": "#/$defs/ToolUsage",
28
+ "description": "本次调用所选模型及 Model Catalog 声明的成本。"
29
+ }
30
+ },
31
+ "$defs": {
32
+ "CostRange": {
33
+ "type": "object",
34
+ "additionalProperties": false,
35
+ "required": [
36
+ "unit",
37
+ "minimum",
38
+ "maximum"
39
+ ],
40
+ "properties": {
41
+ "unit": {
42
+ "const": "gaodou",
43
+ "description": "稿豆计价单位。"
44
+ },
45
+ "minimum": {
46
+ "type": "number",
47
+ "minimum": 0,
48
+ "description": "当前可用配置中的最低稿豆消耗。"
49
+ },
50
+ "maximum": {
51
+ "type": "number",
52
+ "minimum": 0,
53
+ "description": "当前可用配置中的最高稿豆消耗。"
54
+ }
55
+ }
56
+ },
57
+ "ToolUsage": {
58
+ "type": "object",
59
+ "additionalProperties": false,
60
+ "required": [
61
+ "model"
62
+ ],
63
+ "properties": {
64
+ "model": {
65
+ "type": "string",
66
+ "minLength": 1,
67
+ "pattern": ".*\\S.*",
68
+ "description": "本次调用选择的模型机器标识。"
69
+ },
70
+ "cost": {
71
+ "$ref": "#/$defs/CostRange",
72
+ "description": "Model Catalog 声明的稿豆消耗区间。"
73
+ }
74
+ }
75
+ },
76
+ "TextContent": {
77
+ "type": "object",
78
+ "additionalProperties": false,
79
+ "required": [
80
+ "type",
81
+ "text"
82
+ ],
83
+ "properties": {
84
+ "type": {
85
+ "const": "text",
86
+ "description": "文本内容的固定类型。"
87
+ },
88
+ "text": {
89
+ "type": "string",
90
+ "minLength": 1,
91
+ "pattern": ".*\\S.*",
92
+ "description": "创作工具返回的文本。"
93
+ }
94
+ }
95
+ },
96
+ "ResourceLink": {
97
+ "type": "object",
98
+ "additionalProperties": false,
99
+ "required": [
100
+ "type",
101
+ "uri",
102
+ "name"
103
+ ],
104
+ "properties": {
105
+ "type": {
106
+ "const": "resource_link",
107
+ "description": "资源链接的固定类型。"
108
+ },
109
+ "uri": {
110
+ "type": "string",
111
+ "format": "uri",
112
+ "description": "创作工具生成资源的 URI。"
113
+ },
114
+ "name": {
115
+ "type": "string",
116
+ "minLength": 1,
117
+ "pattern": ".*\\S.*",
118
+ "description": "资源的文件名。"
119
+ },
120
+ "mimeType": {
121
+ "type": "string",
122
+ "minLength": 1,
123
+ "pattern": ".*\\S.*",
124
+ "description": "资源的 MIME type。"
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "ToolListInput",
4
+ "description": "列出当前可用产品创作工具的输入。",
5
+ "type": "object",
6
+ "additionalProperties": false
7
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "ToolListResult",
4
+ "description": "当前可用的产品创作工具。",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "tools"
9
+ ],
10
+ "properties": {
11
+ "tools": {
12
+ "type": "array",
13
+ "description": "当前至少有一个可用模型的产品创作工具。",
14
+ "items": {
15
+ "type": "object",
16
+ "additionalProperties": false,
17
+ "required": [
18
+ "name",
19
+ "title",
20
+ "description"
21
+ ],
22
+ "properties": {
23
+ "name": {
24
+ "type": "string",
25
+ "minLength": 1,
26
+ "pattern": ".*\\S.*",
27
+ "description": "调用创作工具时使用的机器标识。"
28
+ },
29
+ "title": {
30
+ "type": "string",
31
+ "minLength": 1,
32
+ "pattern": ".*\\S.*",
33
+ "description": "创作工具的展示名称。"
34
+ },
35
+ "description": {
36
+ "type": "string",
37
+ "minLength": 1,
38
+ "pattern": ".*\\S.*",
39
+ "description": "创作工具的用途说明。"
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ import { createCli, executeCli } from "../src/bootstrap/create-cli.js";
3
+ import { createProductionRuntime } from "../src/bootstrap/create-runtime.js";
4
+ import { mapCliError } from "../src/cli/errors.js";
5
+ import { redact } from "../src/platform/redact.js";
6
+ const controller = new AbortController();
7
+ const interrupt = () => controller.abort(new Error("SIGINT"));
8
+ process.once("SIGINT", interrupt);
9
+ let runtime;
10
+ try {
11
+ runtime = createProductionRuntime();
12
+ const program = createCli(runtime, { signal: controller.signal });
13
+ process.exitCode = await executeCli({
14
+ program,
15
+ argv: process.argv.slice(2),
16
+ presenter: runtime.presenter,
17
+ signal: controller.signal
18
+ });
19
+ }
20
+ catch (error) {
21
+ const outcome = redact(mapCliError(error, { aborted: controller.signal.aborted }));
22
+ if (runtime) {
23
+ runtime.presenter.error(outcome, { json: process.argv.includes("--json") });
24
+ }
25
+ else if (outcome.kind === "interrupted") {
26
+ process.stderr.write("已取消。\n");
27
+ }
28
+ else if (process.argv.includes("--json")) {
29
+ process.stderr.write(`${JSON.stringify({ error: outcome.failure })}\n`);
30
+ }
31
+ else {
32
+ process.stderr.write(`${outcome.failure.code}: ${outcome.failure.message}\n`);
33
+ }
34
+ process.exitCode = outcome.exitCode;
35
+ }
36
+ finally {
37
+ process.removeListener("SIGINT", interrupt);
38
+ }
@@ -0,0 +1,42 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { resolve } from "node:path";
3
+ import { loadBundledSkills } from "../src/features/skill/bundled-skills.js";
4
+ import { syncBundledSkills } from "../src/features/skill/installer.js";
5
+ export function isSupportedGlobalLifecycle(env) {
6
+ const userAgent = env.npm_config_user_agent ?? "";
7
+ if (env.npm_config_global === "true") {
8
+ return /^(?:npm|pnpm)\//u.test(userAgent);
9
+ }
10
+ const initialDirectory = (env.INIT_CWD ?? "").replace(/\\/gu, "/");
11
+ return userAgent.startsWith("pnpm/")
12
+ && env.npm_command === "add"
13
+ && env.npm_lifecycle_event === "postinstall"
14
+ && env.npm_package_name === "gaoding-cli"
15
+ && /\/v\d+\/[0-9a-f]+-[0-9a-f]+-[0-9a-f]{16}$/u.test(initialDirectory);
16
+ }
17
+ export async function runPostinstall(options = {}) {
18
+ const env = options.env ?? process.env;
19
+ if (!isSupportedGlobalLifecycle(env))
20
+ return;
21
+ const writeError = options.writeError ?? ((text) => process.stderr.write(text));
22
+ try {
23
+ const skills = (options.loadSkills ?? loadBundledSkills)(options.startFile ?? fileURLToPath(import.meta.url));
24
+ await (options.syncSkills ?? syncBundledSkills)(skills, {
25
+ env,
26
+ ...(options.homeDirectory ? { homeDirectory: options.homeDirectory } : {})
27
+ });
28
+ }
29
+ catch (error) {
30
+ writeError(`警告: ${oneLineMessage(error)}\n`);
31
+ }
32
+ }
33
+ function oneLineMessage(error) {
34
+ const value = error instanceof Error ? error.message : String(error);
35
+ return value.replace(/\s+/gu, " ").trim() || "Agent Skill 自动安装失败";
36
+ }
37
+ const entryPath = process.argv[1];
38
+ const isDirectEntry = entryPath !== undefined
39
+ && resolve(entryPath) === fileURLToPath(import.meta.url);
40
+ if (isDirectEntry || process.env.npm_lifecycle_event === "postinstall") {
41
+ void runPostinstall();
42
+ }
@@ -0,0 +1,55 @@
1
+ import { Command } from "commander";
2
+ import { assertAllLeafCommandsBound, configureActionEnvironment } from "../cli/action-binding.js";
3
+ import { registerAgentCommands } from "../cli/agent-commands.js";
4
+ import { registerAuthCommands } from "../cli/auth-commands.js";
5
+ import { isHelpOutcome, mapCliError } from "../cli/errors.js";
6
+ import { registerOrgCommands } from "../cli/org-commands.js";
7
+ import { registerToolCommands } from "../cli/tool-commands.js";
8
+ import { registerModelCommands } from "../cli/model-commands.js";
9
+ import { registerEditorCommands } from "../cli/editor-commands.js";
10
+ import { registerDamCommands } from "../cli/dam-commands.js";
11
+ import { registerUpdateCommand } from "../cli/update-command.js";
12
+ import { redact } from "../platform/redact.js";
13
+ export { assertAllLeafCommandsBound, bindAction } from "../cli/action-binding.js";
14
+ export function createCli(runtime, options) {
15
+ const program = new Command()
16
+ .name("gd-cli")
17
+ .description("稿定命令行工具")
18
+ .version(runtime.version)
19
+ .helpCommand(false)
20
+ .showHelpAfterError(false)
21
+ .showSuggestionAfterError(false)
22
+ .allowExcessArguments(false)
23
+ .exitOverride()
24
+ .configureOutput({
25
+ writeOut: runtime.io.writeOut,
26
+ writeErr: () => undefined
27
+ });
28
+ configureActionEnvironment(program, {
29
+ policies: runtime.accessPolicies,
30
+ signal: options.signal
31
+ });
32
+ registerAuthCommands(program, runtime);
33
+ registerOrgCommands(program, runtime);
34
+ registerAgentCommands(program, runtime);
35
+ registerToolCommands(program, runtime);
36
+ registerModelCommands(program, runtime);
37
+ registerEditorCommands(program, runtime);
38
+ registerDamCommands(program, runtime);
39
+ registerUpdateCommand(program, runtime);
40
+ assertAllLeafCommandsBound(program);
41
+ return program;
42
+ }
43
+ export async function executeCli(options) {
44
+ try {
45
+ await options.program.parseAsync(options.argv, { from: "user" });
46
+ return 0;
47
+ }
48
+ catch (error) {
49
+ if (isHelpOutcome(error))
50
+ return 0;
51
+ const outcome = redact(mapCliError(error, { aborted: options.signal.aborted }));
52
+ options.presenter.error(outcome, { json: options.argv.includes("--json") });
53
+ return outcome.exitCode;
54
+ }
55
+ }