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.
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/contracts/operations/agent.send/input.schema.json +354 -0
- package/contracts/operations/agent.send/output.schema.json +271 -0
- package/contracts/operations/auth.status/input.schema.json +7 -0
- package/contracts/operations/auth.status/output.schema.json +132 -0
- package/contracts/operations/dam.delete/input.schema.json +23 -0
- package/contracts/operations/dam.delete/output.schema.json +6 -0
- package/contracts/operations/dam.get/input.schema.json +16 -0
- package/contracts/operations/dam.get/output.schema.json +46 -0
- package/contracts/operations/dam.list/input.schema.json +44 -0
- package/contracts/operations/dam.list/output.schema.json +71 -0
- package/contracts/operations/dam.search/input.schema.json +46 -0
- package/contracts/operations/dam.search/output.schema.json +71 -0
- package/contracts/operations/dam.upload/input.schema.json +31 -0
- package/contracts/operations/dam.upload/output.schema.json +46 -0
- package/contracts/operations/editor.apply/input.schema.json +134 -0
- package/contracts/operations/editor.apply/output.schema.json +15 -0
- package/contracts/operations/editor.connect/input.schema.json +15 -0
- package/contracts/operations/editor.connect/output.schema.json +17 -0
- package/contracts/operations/editor.disconnect/input.schema.json +8 -0
- package/contracts/operations/editor.disconnect/output.schema.json +14 -0
- package/contracts/operations/editor.save/input.schema.json +8 -0
- package/contracts/operations/editor.save/output.schema.json +23 -0
- package/contracts/operations/editor.screenshot/input.schema.json +8 -0
- package/contracts/operations/editor.screenshot/output.schema.json +16 -0
- package/contracts/operations/editor.snapshot/input.schema.json +8 -0
- package/contracts/operations/editor.snapshot/output.schema.json +113 -0
- package/contracts/operations/model.get/input.schema.json +18 -0
- package/contracts/operations/model.get/output.schema.json +190 -0
- package/contracts/operations/model.list/input.schema.json +15 -0
- package/contracts/operations/model.list/output.schema.json +111 -0
- package/contracts/operations/org.current/input.schema.json +7 -0
- package/contracts/operations/org.current/output.schema.json +49 -0
- package/contracts/operations/org.list/input.schema.json +7 -0
- package/contracts/operations/org.list/output.schema.json +71 -0
- package/contracts/operations/tool.call/input.schema.json +35 -0
- package/contracts/operations/tool.call/output.schema.json +129 -0
- package/contracts/operations/tool.list/input.schema.json +7 -0
- package/contracts/operations/tool.list/output.schema.json +45 -0
- package/dist/bin/gd-cli.js +38 -0
- package/dist/bin/postinstall.js +42 -0
- package/dist/src/bootstrap/create-cli.js +55 -0
- package/dist/src/bootstrap/create-runtime.js +222 -0
- package/dist/src/bootstrap/validators.js +118 -0
- package/dist/src/cli/action-binding.js +63 -0
- package/dist/src/cli/agent-commands.js +39 -0
- package/dist/src/cli/auth-commands.js +47 -0
- package/dist/src/cli/dam-commands.js +207 -0
- package/dist/src/cli/editor-commands.js +73 -0
- package/dist/src/cli/errors.js +90 -0
- package/dist/src/cli/model-commands.js +47 -0
- package/dist/src/cli/org-commands.js +52 -0
- package/dist/src/cli/presenter.js +80 -0
- package/dist/src/cli/prompt.js +30 -0
- package/dist/src/cli/tool-commands.js +65 -0
- package/dist/src/cli/update-command.js +12 -0
- package/dist/src/contracts/schema.js +4 -0
- package/dist/src/features/agent/creative-agent-adapter.js +31 -0
- package/dist/src/features/agent/creative-protocol.js +324 -0
- package/dist/src/features/agent/creative-stream.js +127 -0
- package/dist/src/features/agent/use-cases.js +113 -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 +179 -0
- package/dist/src/features/auth/state.js +129 -0
- package/dist/src/features/auth/use-cases.js +106 -0
- package/dist/src/features/dam/asset-projection.js +270 -0
- package/dist/src/features/dam/dam-api-adapter.js +206 -0
- package/dist/src/features/dam/object-storage.js +191 -0
- package/dist/src/features/dam/registered-uploader.js +224 -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 +151 -0
- package/dist/src/features/editor/bridge-client.js +96 -0
- package/dist/src/features/editor/bridge-process.js +222 -0
- package/dist/src/features/editor/bridge-server.js +311 -0
- package/dist/src/features/editor/protocol.js +1 -0
- package/dist/src/features/editor/session-state.js +78 -0
- package/dist/src/features/editor/session.js +193 -0
- package/dist/src/features/editor/use-cases.js +61 -0
- package/dist/src/features/org/org-service.js +76 -0
- package/dist/src/features/org/use-cases.js +140 -0
- package/dist/src/features/skill/bundled-skills.js +55 -0
- package/dist/src/features/skill/installer.js +265 -0
- package/dist/src/features/tool/catalog.js +79 -0
- package/dist/src/features/tool/dynamic-schema.js +96 -0
- package/dist/src/features/tool/mns-catalog-adapter.js +262 -0
- package/dist/src/features/tool/tool-api-adapter.js +200 -0
- package/dist/src/features/tool/use-cases.js +126 -0
- package/dist/src/features/update/update-service.js +194 -0
- package/dist/src/platform/json-input.js +64 -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/safe-upload-file.js +146 -0
- package/dist/src/platform/signature.js +19 -0
- package/dist/src/platform/signed-http-transport.js +109 -0
- package/dist/src/platform/url-safety.js +100 -0
- package/package.json +56 -0
- package/skills/gd-cli/SKILL.md +15 -0
- package/skills/gd-cli/references/auth-org.md +9 -0
- package/skills/gd-cli/references/creation.md +38 -0
- package/skills/gd-cli/references/dam.md +20 -0
- package/skills/gd-cli/references/editor.md +12 -0
- package/skills/gd-cli/references/errors.md +10 -0
- package/skills/gd-cli/references/update.md +11 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { isIP } from "node:net";
|
|
2
|
+
export class UrlSafetyError extends Error {
|
|
3
|
+
constructor() {
|
|
4
|
+
super("URL 不可用于远程素材。");
|
|
5
|
+
this.name = "UrlSafetyError";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function fail() {
|
|
9
|
+
throw new UrlSafetyError();
|
|
10
|
+
}
|
|
11
|
+
function parseIpv4(hostname) {
|
|
12
|
+
if (isIP(hostname) !== 4)
|
|
13
|
+
return null;
|
|
14
|
+
return hostname.split(".").map(Number);
|
|
15
|
+
}
|
|
16
|
+
function isPrivateIpv4(parts) {
|
|
17
|
+
const first = parts[0] ?? -1;
|
|
18
|
+
const second = parts[1] ?? -1;
|
|
19
|
+
return first === 0
|
|
20
|
+
|| first === 10
|
|
21
|
+
|| first === 127
|
|
22
|
+
|| (first === 169 && second === 254)
|
|
23
|
+
|| (first === 172 && second >= 16 && second <= 31)
|
|
24
|
+
|| (first === 192 && second === 168);
|
|
25
|
+
}
|
|
26
|
+
function expandIpv6(hostname) {
|
|
27
|
+
if (isIP(hostname) !== 6)
|
|
28
|
+
return null;
|
|
29
|
+
const [left = "", right = "", ...rest] = hostname.split("::");
|
|
30
|
+
if (rest.length > 0)
|
|
31
|
+
return null;
|
|
32
|
+
const leftParts = left === "" ? [] : left.split(":");
|
|
33
|
+
const rightParts = right === "" ? [] : right.split(":");
|
|
34
|
+
const missing = 8 - leftParts.length - rightParts.length;
|
|
35
|
+
if (!hostname.includes("::") && missing !== 0)
|
|
36
|
+
return null;
|
|
37
|
+
if (hostname.includes("::") && missing < 1)
|
|
38
|
+
return null;
|
|
39
|
+
const values = [
|
|
40
|
+
...leftParts,
|
|
41
|
+
...Array.from({ length: missing }, () => "0"),
|
|
42
|
+
...rightParts
|
|
43
|
+
].map((part) => Number.parseInt(part, 16));
|
|
44
|
+
return values.length === 8 && values.every((part) => Number.isInteger(part))
|
|
45
|
+
? values
|
|
46
|
+
: null;
|
|
47
|
+
}
|
|
48
|
+
function isPrivateIpv6(parts) {
|
|
49
|
+
const first = parts[0] ?? -1;
|
|
50
|
+
const unspecified = parts.every((part) => part === 0);
|
|
51
|
+
const loopback = parts.slice(0, 7).every((part) => part === 0) && parts[7] === 1;
|
|
52
|
+
const uniqueLocal = (first & 0xfe00) === 0xfc00;
|
|
53
|
+
const linkLocal = (first & 0xffc0) === 0xfe80;
|
|
54
|
+
const mappedIpv4 = parts.slice(0, 5).every((part) => part === 0)
|
|
55
|
+
&& parts[5] === 0xffff;
|
|
56
|
+
if (mappedIpv4) {
|
|
57
|
+
const high = parts[6] ?? 0;
|
|
58
|
+
const low = parts[7] ?? 0;
|
|
59
|
+
return isPrivateIpv4([
|
|
60
|
+
high >> 8,
|
|
61
|
+
high & 0xff,
|
|
62
|
+
low >> 8,
|
|
63
|
+
low & 0xff
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
return unspecified || loopback || uniqueLocal || linkLocal;
|
|
67
|
+
}
|
|
68
|
+
export function parseSafeRemoteAssetUrl(value) {
|
|
69
|
+
let url;
|
|
70
|
+
try {
|
|
71
|
+
url = new URL(value);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return fail();
|
|
75
|
+
}
|
|
76
|
+
if ((url.protocol !== "http:" && url.protocol !== "https:")
|
|
77
|
+
|| url.username !== ""
|
|
78
|
+
|| url.password !== "") {
|
|
79
|
+
return fail();
|
|
80
|
+
}
|
|
81
|
+
const hostname = url.hostname
|
|
82
|
+
.replace(/^\[|\]$/g, "")
|
|
83
|
+
.replace(/[.]+$/, "")
|
|
84
|
+
.toLowerCase();
|
|
85
|
+
if (hostname === "localhost"
|
|
86
|
+
|| hostname.endsWith(".localhost")
|
|
87
|
+
|| hostname.endsWith(".local")
|
|
88
|
+
|| hostname === "metadata"
|
|
89
|
+
|| hostname === "metadata.google.internal"
|
|
90
|
+
|| hostname === "169.254.169.254") {
|
|
91
|
+
return fail();
|
|
92
|
+
}
|
|
93
|
+
const ipv4 = parseIpv4(hostname);
|
|
94
|
+
if (ipv4 !== null && isPrivateIpv4(ipv4))
|
|
95
|
+
return fail();
|
|
96
|
+
const ipv6 = expandIpv6(hostname);
|
|
97
|
+
if (ipv6 !== null && isPrivateIpv6(ipv6))
|
|
98
|
+
return fail();
|
|
99
|
+
return url;
|
|
100
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gaoding-cli",
|
|
3
|
+
"version": "1.0.0-alpha.10",
|
|
4
|
+
"description": "Gaoding command-line interface for agents and people.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"registry": "https://registry.npmjs.org/",
|
|
10
|
+
"tag": "alpha"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=24"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"gd-cli": "dist/bin/gd-cli.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"contracts",
|
|
20
|
+
"dist",
|
|
21
|
+
"skills",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"ajv": "8.20.0",
|
|
27
|
+
"ajv-formats": "3.0.1",
|
|
28
|
+
"ali-oss": "6.23.0",
|
|
29
|
+
"commander": "15.0.0",
|
|
30
|
+
"open": "11.0.0",
|
|
31
|
+
"qrcode": "1.5.4",
|
|
32
|
+
"semver": "7.8.5",
|
|
33
|
+
"sharp": "0.35.3",
|
|
34
|
+
"ws": "8.21.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/ali-oss": "6.23.3",
|
|
38
|
+
"@types/node": "24.13.3",
|
|
39
|
+
"@types/qrcode": "1.5.6",
|
|
40
|
+
"@types/semver": "7.7.1",
|
|
41
|
+
"@types/ws": "8.18.1",
|
|
42
|
+
"typescript": "7.0.2",
|
|
43
|
+
"vitest": "4.1.10",
|
|
44
|
+
"@gaoding/gd-connector-contracts": "0.1.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"contracts:build": "pnpm --filter @gaoding/gd-connector-contracts build",
|
|
48
|
+
"clean": "node -e \"for (const p of ['contracts', 'dist']) require('node:fs').rmSync(p, { recursive: true, force: true })\"",
|
|
49
|
+
"bundle:contracts": "node scripts/bundle-contracts.mjs",
|
|
50
|
+
"build": "pnpm contracts:build && pnpm clean && tsc -p tsconfig.build.json && pnpm bundle:contracts",
|
|
51
|
+
"test": "pnpm contracts:build && vitest run",
|
|
52
|
+
"typecheck": "pnpm contracts:build && tsc -p tsconfig.json",
|
|
53
|
+
"check": "pnpm contracts:build && vitest run && tsc -p tsconfig.json && pnpm clean && tsc -p tsconfig.build.json && pnpm bundle:contracts",
|
|
54
|
+
"postinstall": "node -e \"const p='./dist/bin/postinstall.js'; if (require('node:fs').existsSync(p)) import(p)\""
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gd-cli
|
|
3
|
+
description: Use when creating images, videos or text with GD CLI, operating the focused Gaoding editor, or managing Gaoding DAM assets.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# GD CLI
|
|
7
|
+
|
|
8
|
+
按用户目标只读取对应参考:
|
|
9
|
+
|
|
10
|
+
- 开放式创作、工具发现与模型调用:[创作](references/creation.md)
|
|
11
|
+
- 操作当前 AI+ Editor 作品:[编辑器](references/editor.md)
|
|
12
|
+
- 查询、上传或删除 DAM 素材:[素材管理](references/dam.md)
|
|
13
|
+
- 登录或选择组织:[登录与组织](references/auth-org.md)
|
|
14
|
+
- 处理输出、警告、失败或中断:[错误处理](references/errors.md)
|
|
15
|
+
- 更新 CLI 与随包 Agent Skill:[更新](references/update.md)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# 登录与组织
|
|
2
|
+
|
|
3
|
+
1. 用 `gd-cli auth status` 检查登录状态;需要机器读取时使用 `--json`。
|
|
4
|
+
2. 未登录时执行 `gd-cli auth login`,按终端提示在浏览器完成授权;无法自动打开浏览器时使用 `--no-browser`。
|
|
5
|
+
3. 用 `gd-cli org list` 查看当前账号可用的组织,用 `gd-cli org current` 查看当前选择。
|
|
6
|
+
4. 让用户从真实列表中选择,再执行 `gd-cli org switch --org <org-id>`;不要猜组织 ID。
|
|
7
|
+
5. 用户要求退出或登录状态失效时执行 `gd-cli auth logout`;状态失效后重新登录。
|
|
8
|
+
|
|
9
|
+
不要向用户索要或回显 Bearer Token、Cookie、AK、SK 或签名。组织不可用时先切换组织;仍无法恢复时退出后重新登录。
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# 创作
|
|
2
|
+
|
|
3
|
+
## 选择入口
|
|
4
|
+
|
|
5
|
+
- 目标开放、需要稿定 Agent 完成创作时,使用 `gd-cli agent send`。
|
|
6
|
+
- 已知要调用具体图片、视频或文本能力时,依次发现 Tool、选择 Model、读取输入 Schema,再调用 Tool。
|
|
7
|
+
- 不猜 Tool 名、Model 名或参数;以当前命令输出为准。
|
|
8
|
+
|
|
9
|
+
## Agent 创作
|
|
10
|
+
|
|
11
|
+
先读取输入规范,再提交同一份结构化对象:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
gd-cli agent send --schema
|
|
15
|
+
gd-cli agent send --input request.json
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
也可用 `--input -` 从 stdin 读取 JSON。成功结果包含 `message` 和本轮实际稿豆消耗 `usage`;将文本、资源与实际消耗交付给用户。
|
|
19
|
+
|
|
20
|
+
## Tool 创作
|
|
21
|
+
|
|
22
|
+
按顺序执行:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
gd-cli tool list
|
|
26
|
+
gd-cli model list --tool <tool>
|
|
27
|
+
gd-cli model get <model>
|
|
28
|
+
gd-cli tool call <tool> --schema
|
|
29
|
+
gd-cli tool call <tool> --input request.json
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`tool list` 给出可用 Tool;`model list` 和 `model get` 给出当前可用 Model、费用与预估耗时等信息;`tool call --schema` 给出所选 Tool 的实时输入要求。不要把列表值固化在提示或脚本中。
|
|
33
|
+
|
|
34
|
+
成功结果包含 `content` 和 `usage`。`content` 是文本或资源链接;`usage` 包含所选模型及模型目录公布的稿豆价格区间,不表示实际扣费。
|
|
35
|
+
|
|
36
|
+
## 本地媒体
|
|
37
|
+
|
|
38
|
+
按所选 Schema 在输入中提交本地媒体引用。CLI 会在内部通过 DAM 完成临时上传并把公网 URL 传给创作服务;不要自行伪造 URL,也不要读取用户未明确授权的路径。
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# DAM 素材管理
|
|
2
|
+
|
|
3
|
+
## 查询
|
|
4
|
+
|
|
5
|
+
- `gd-cli dam list --repository-id <id>` 查看资源库中的最近素材。
|
|
6
|
+
- `gd-cli dam search <query> --repository-id <id>` 按关键词搜索。
|
|
7
|
+
- `gd-cli dam get <asset>` 获取某个素材的完整信息与可用 URL。
|
|
8
|
+
- 跨资源库查询仅在用户明确要求时使用 `--all-repositories`。
|
|
9
|
+
|
|
10
|
+
列表与搜索支持文件夹、类型、格式、标签、数量和游标筛选。先使用命令 `--help` 核对当前选项,不猜资源库 ID、文件夹 ID 或素材 ID。
|
|
11
|
+
|
|
12
|
+
## 写入
|
|
13
|
+
|
|
14
|
+
- 用 `gd-cli dam upload <file> --repository-id <id>` 上传本地文件;按需补充标题、文件夹或标签。
|
|
15
|
+
- 只有用户明确允许受保护路径时才加 `--allow-sensitive-path`。
|
|
16
|
+
- 需要等素材分析完成时加 `--wait-analysis`。
|
|
17
|
+
- 用 `gd-cli dam delete <asset> --repository-id <id>` 移入回收站。
|
|
18
|
+
- 只有用户明确要求永久删除时才加 `--permanent`。
|
|
19
|
+
|
|
20
|
+
上传和删除前确认目标资源库;不得从本地登录状态或历史输出中替用户猜测目标。
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# AI+ Editor
|
|
2
|
+
|
|
3
|
+
只操作当前连接的作品,并在修改前后读取真实画布状态。
|
|
4
|
+
|
|
5
|
+
1. 用 `gd-cli editor connect [target]` 打开并连接作品;`target` 可以是作品 ID 或完整 URL,省略时打开新作品。
|
|
6
|
+
2. 用 `gd-cli editor snapshot` 读取元素与选择状态。
|
|
7
|
+
3. 把有序元素操作写入 JSON,再用 `gd-cli editor apply --input actions.json` 应用;也可用 `--input -`。
|
|
8
|
+
4. 再次执行 `gd-cli editor snapshot`,必要时执行 `gd-cli editor screenshot` 做视觉复核。
|
|
9
|
+
5. 用 `gd-cli editor save` 保存;需要机器可读结果时仅对支持的命令使用 `--json`。
|
|
10
|
+
6. 完成后用 `gd-cli editor disconnect` 断开连接。
|
|
11
|
+
|
|
12
|
+
不要在未读取快照时猜测元素 ID。修改结果与目标不符时,先重新读取快照或截图,再生成下一组操作。
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# 输出与错误
|
|
2
|
+
|
|
3
|
+
- `stdout` 只承载命令结果;结构化命令的 JSON 可直接解析。
|
|
4
|
+
- `stderr` 承载警告、授权提示和错误;不要把警告混入结果。
|
|
5
|
+
- 退出码 `0` 表示成功。
|
|
6
|
+
- 退出码 `1` 表示运行、服务或状态失败;读取错误码与“下一步”,处理后再重试。
|
|
7
|
+
- 退出码 `2` 表示命令或参数错误;执行对应命令的 `--help` 后修正调用。
|
|
8
|
+
- 退出码 `130` 表示用户中断;立即停止,不自动重试。
|
|
9
|
+
|
|
10
|
+
不要从未知错误中推断内部实现,也不要输出本地凭证、请求签名或带敏感查询参数的 URL。命令失败且没有安全恢复步骤时,保留原始 stderr 的公开错误码并向用户说明。
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# 更新
|
|
2
|
+
|
|
3
|
+
执行:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
gd-cli update
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
该命令检查 npm `latest`,更新受支持的 npm 或 pnpm 全局安装,并确保随包 `gd-cli` Agent Skill 已同步;CLI 已是最新版本时仍会同步 Agent Skill。pnpm 更新只为 `gaoding-cli` 启用安装脚本。
|
|
10
|
+
|
|
11
|
+
命令不接收参数或 `--json`。不支持自动更新的安装来源会给出明确的 npm、pnpm 全局安装命令。若 CLI 已更新但 Agent Skill 验收失败,保留已更新版本,按 stderr 的下一步修复后重新执行 `gd-cli update`。
|