@gaoding/cli 3.0.1 → 3.0.3
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/README.md +7 -3
- package/contracts/operations/agent.send/input.schema.json +1 -1
- package/contracts/operations/credits.get/output.schema.json +3 -3
- package/contracts/operations/dam.copy/input.schema.json +3 -3
- package/contracts/operations/dam.copy/output.schema.json +1 -1
- package/contracts/operations/dam.list/output.schema.json +2 -2
- package/contracts/operations/dam.move/input.schema.json +3 -3
- package/contracts/operations/dam.search/output.schema.json +2 -2
- package/contracts/operations/feedback.submit/input.schema.json +231 -0
- package/contracts/operations/feedback.submit/output.schema.json +29 -0
- package/contracts/operations/task.get/output.schema.json +2 -2
- package/contracts/presentations/task.get.schema.json +2 -2
- package/dist/bin/gd-cli.js +1 -6
- package/dist/bin/insmind-cli.js +1 -6
- package/dist/src/bootstrap/create-cli.js +34 -19
- package/dist/src/bootstrap/create-runtime.js +13 -2
- package/dist/src/bootstrap/run-task-worker.js +6 -2
- package/dist/src/bootstrap/validators.js +1 -8
- package/dist/src/cli/agent-commands.js +7 -6
- package/dist/src/cli/dam-commands.js +14 -6
- package/dist/src/cli/errors.js +23 -6
- package/dist/src/cli/feedback-command.js +31 -0
- package/dist/src/cli/model-commands.js +4 -4
- package/dist/src/cli/skill-output.js +13 -4
- package/dist/src/cli/task-commands.js +3 -2
- package/dist/src/cli/tool-commands.js +12 -5
- package/dist/src/cli/update-command.js +3 -3
- package/dist/src/contracts/creation-input.js +0 -3
- package/dist/src/features/dam/file-downloader.js +19 -9
- package/dist/src/features/dam/operation-executor.js +2 -0
- package/dist/src/features/dam/use-cases.js +53 -29
- package/dist/src/features/feedback/submit.js +86 -0
- package/dist/src/features/skill/catalog.js +17 -1
- package/dist/src/features/skill/manual.js +37 -31
- package/dist/src/features/task/store.js +7 -0
- package/dist/src/features/task/use-cases.js +66 -10
- package/dist/src/features/update/check-schema.js +22 -16
- package/dist/src/features/update/update-notification.js +8 -4
- package/dist/src/features/update/update-service.js +37 -16
- package/dist/src/telemetry/command-routes.json +1 -1
- package/dist/src/telemetry/invocation.js +8 -4
- package/dist/src/telemetry/process-errors.js +7 -2
- package/dist/src/telemetry/sanitize.js +18 -7
- package/dist/src/telemetry/sls-sink.js +38 -15
- package/package.json +7 -7
- package/skills/gd-cli/SKILL.md +2 -2
- package/dist/src/features/editor/bridge-client.js +0 -107
- package/dist/src/features/editor/bridge-process.js +0 -237
- package/dist/src/features/editor/bridge-server.js +0 -339
- package/dist/src/features/editor/protocol.js +0 -1
- package/dist/src/features/editor/public-url.js +0 -1
- package/dist/src/features/editor/session-state.js +0 -81
- package/dist/src/features/editor/session.js +0 -232
- package/dist/src/features/editor/use-cases.js +0 -118
|
@@ -25,7 +25,8 @@ export class UpdateError extends Error {
|
|
|
25
25
|
}
|
|
26
26
|
export function detectInstallSource(input) {
|
|
27
27
|
const binaryPath = normalizePath(input.binaryPath);
|
|
28
|
-
const
|
|
28
|
+
const realPath = input.realBinaryPath ?? safeRealpath(input.binaryPath);
|
|
29
|
+
const realBinaryPath = normalizePath(realPath);
|
|
29
30
|
const packageRoot = normalizePath(input.packageRoot);
|
|
30
31
|
const cwd = normalizePath(resolve(input.cwd));
|
|
31
32
|
const userAgent = input.env.npm_config_user_agent ?? "";
|
|
@@ -35,10 +36,10 @@ export function detectInstallSource(input) {
|
|
|
35
36
|
return unsupported("Yarn 安装不支持自动更新");
|
|
36
37
|
}
|
|
37
38
|
if (containsTemporaryRunner(binaryPath) || containsTemporaryRunner(packageRoot)) {
|
|
38
|
-
return unsupported("临时运行方式不支持自动更新");
|
|
39
|
+
return unsupported("临时运行方式不支持自动更新", "temporary");
|
|
39
40
|
}
|
|
40
41
|
if (binaryPath.includes("/node_modules/.bin/")) {
|
|
41
|
-
return unsupported("项目依赖不支持自动更新");
|
|
42
|
+
return unsupported("项目依赖不支持自动更新", "project");
|
|
42
43
|
}
|
|
43
44
|
if (!isWithin(realBinaryPath, packageRoot)) {
|
|
44
45
|
return unsupported("CLI binary 与 package 不匹配");
|
|
@@ -50,7 +51,7 @@ export function detectInstallSource(input) {
|
|
|
50
51
|
const pnpmDirectory = pnpmSnapshotDirectory(binaryPath, packageName, command);
|
|
51
52
|
const pnpmLauncher = pnpmLaunchers(input.env, command).find(entry => entry.target === resolve(input.binaryPath));
|
|
52
53
|
if (realBinaryPath === `${packageRoot}/dist/bin/${command}.js` && pnpmDirectory && pnpmLauncher
|
|
53
|
-
&& safeRealpath(input.binaryPath) ===
|
|
54
|
+
&& safeRealpath(input.binaryPath) === realPath
|
|
54
55
|
&& packageManifestMatches(input.packageRoot, packageName)
|
|
55
56
|
&& (!binaryPath.includes("/5/.pnpm/") || legacyManifestMatches(pnpmDirectory, packageName))) {
|
|
56
57
|
return { kind: "global", manager: "pnpm", packageRoot: input.packageRoot, directory: pnpmDirectory, launcher: pnpmLauncher.launcher };
|
|
@@ -64,8 +65,8 @@ export function detectInstallSource(input) {
|
|
|
64
65
|
try {
|
|
65
66
|
const shim = readFileSync(launcher, "utf8");
|
|
66
67
|
const target = windowsShimTarget(shim);
|
|
67
|
-
if (target && realpathSync(resolve(prefix, target)) ===
|
|
68
|
-
&& safeRealpath(input.binaryPath) ===
|
|
68
|
+
if (target && realpathSync(resolve(prefix, target)) === realPath
|
|
69
|
+
&& safeRealpath(input.binaryPath) === realPath) {
|
|
69
70
|
return { kind: "global", manager: "npm", packageRoot: input.packageRoot, directory: prefix, launcher };
|
|
70
71
|
}
|
|
71
72
|
}
|
|
@@ -76,15 +77,15 @@ export function detectInstallSource(input) {
|
|
|
76
77
|
const prefix = dirname(dirname(dirname(dirname(input.packageRoot))));
|
|
77
78
|
try {
|
|
78
79
|
const launcher = join(prefix, "bin", command);
|
|
79
|
-
if (lstatSync(launcher).isSymbolicLink() && realpathSync(launcher) ===
|
|
80
|
-
&& safeRealpath(input.binaryPath) ===
|
|
80
|
+
if (lstatSync(launcher).isSymbolicLink() && realpathSync(launcher) === realPath
|
|
81
|
+
&& safeRealpath(input.binaryPath) === realPath) {
|
|
81
82
|
return { kind: "global", manager: "npm", packageRoot: input.packageRoot, directory: prefix, launcher };
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
catch { /* no matching global launcher */ }
|
|
85
86
|
}
|
|
86
87
|
if (packageRoot.startsWith(`${cwd}/node_modules/`))
|
|
87
|
-
return unsupported("项目依赖不支持自动更新");
|
|
88
|
+
return unsupported("项目依赖不支持自动更新", "project");
|
|
88
89
|
return unsupported("无法确认 npm 或 pnpm 全局安装");
|
|
89
90
|
}
|
|
90
91
|
function pnpmSnapshotDirectory(binaryPath, name, command) {
|
|
@@ -160,6 +161,20 @@ function pnpmLaunchers(env, command) {
|
|
|
160
161
|
export function pnpmLauncherTargets(env, command) {
|
|
161
162
|
return pnpmLaunchers(env, command).map(entry => entry.target);
|
|
162
163
|
}
|
|
164
|
+
export function legacyQwenBridge(env) {
|
|
165
|
+
return env.CLI_HOST_APPLICATION === "qwenwork" && env.CLI_INVOCATION_PURPOSE !== undefined;
|
|
166
|
+
}
|
|
167
|
+
export function updateGuidance(channel, command) {
|
|
168
|
+
const en = command === "insmind-cli";
|
|
169
|
+
switch (channel) {
|
|
170
|
+
case "global": return en ? `Run ${command} update to update.` : `运行 ${command} update 即可更新。`;
|
|
171
|
+
case "project": return en ? "Update this dependency in the project that installed it." : "请在安装这项依赖的项目中更新。";
|
|
172
|
+
case "temporary": return en ? "Select the new version in the runner used to launch this CLI." : "请用本次的临时运行器选择新版本。";
|
|
173
|
+
case "unknown": return en
|
|
174
|
+
? `For a user-owned global npm or pnpm installation, run ${command} update. Otherwise update through the original project, host, or temporary runner.`
|
|
175
|
+
: `自己用 npm 或 pnpm 全局安装的,可运行 ${command} update。其他安装请通过原项目、宿主或临时运行器更新。`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
163
178
|
export function createUpdateService(options) {
|
|
164
179
|
const fetchPackage = options.fetch ?? globalThis.fetch;
|
|
165
180
|
const runProcess = options.runProcess ?? spawnPackageManager;
|
|
@@ -174,12 +189,15 @@ export function createUpdateService(options) {
|
|
|
174
189
|
signal.throwIfAborted();
|
|
175
190
|
const owner = options.installationOwner
|
|
176
191
|
?? readInstallationOwner(options.packageRoot);
|
|
192
|
+
if (owner === "user" && !insmind && legacyQwenBridge(env)) {
|
|
193
|
+
throw new UpdateError("UPDATE_FAILED", "这是旧版千问办公连接器的 CLI 入口。", ["请在千问办公中更新或重新安装稿定连接器。"], undefined, "UPDATE_MANAGED_BY_HOST");
|
|
194
|
+
}
|
|
177
195
|
if (owner === "workbuddy") {
|
|
178
196
|
throw new UpdateError("UPDATE_FAILED", insmind
|
|
179
197
|
? "This insMind CLI installation is managed by WorkBuddy."
|
|
180
|
-
: "此 gd-cli
|
|
198
|
+
: "此 gd-cli 由旧版 WorkBuddy 连接器管理。", [insmind
|
|
181
199
|
? "Update the insMind connector in WorkBuddy."
|
|
182
|
-
: "请在 WorkBuddy
|
|
200
|
+
: "请在 WorkBuddy 中更新「稿定AI」连接器,再使用宿主提供的稿定工具。"], undefined, "UPDATE_MANAGED_BY_HOST");
|
|
183
201
|
}
|
|
184
202
|
if (owner === "invalid") {
|
|
185
203
|
throw new UpdateError("UPDATE_FAILED", insmind
|
|
@@ -224,11 +242,14 @@ export function createUpdateService(options) {
|
|
|
224
242
|
packageName,
|
|
225
243
|
binaryName: commandName
|
|
226
244
|
});
|
|
227
|
-
const nextSteps = [insmind ? "Choose the command for your original package manager:" : "按原安装工具选择下面一条命令执行:", ...manualCommands(latest, packageName)];
|
|
228
245
|
if (source.kind === "unsupported") {
|
|
229
246
|
throw new UpdateError("UPDATE_FAILED", insmind
|
|
230
247
|
? "The current installation method does not support automatic updates."
|
|
231
|
-
: `当前安装方式不支持自动更新:${source.reason}。`,
|
|
248
|
+
: `当前安装方式不支持自动更新:${source.reason}。`, [source.channel === "unknown"
|
|
249
|
+
? (insmind ? "Update through the channel that provided this installation." : "请通过最初提供这份 CLI 的渠道更新。")
|
|
250
|
+
: updateGuidance(source.channel, commandName), insmind
|
|
251
|
+
? "To install a separate global CLI, choose one of these commands:"
|
|
252
|
+
: "若要另行安装全局 CLI,可选择以下命令:", ...manualCommands(latest, packageName)]);
|
|
232
253
|
}
|
|
233
254
|
if (!gt(latest, options.currentVersion)) {
|
|
234
255
|
await options.telemetry.stage("sync", async () => {
|
|
@@ -280,7 +301,7 @@ export function createUpdateService(options) {
|
|
|
280
301
|
catch (error) {
|
|
281
302
|
throw new UpdateError("UPDATE_FAILED", insmind
|
|
282
303
|
? `The package manager finished, but the ${latest} installation could not be confirmed; the installation may have changed.`
|
|
283
|
-
: `包管理器已结束,但无法确认原安装目录已更新到 ${latest};安装状态可能已改变。`, [installNextSteps[0], insmind ? `
|
|
304
|
+
: `包管理器已结束,但无法确认原安装目录已更新到 ${latest};安装状态可能已改变。`, [installNextSteps[0], insmind ? `Run the original launcher at ${source.launcher} with --version.` : `请用原启动文件 ${source.launcher} 执行 --version。`], error);
|
|
284
305
|
}
|
|
285
306
|
const targetSkills = options.bundledSkills.map((skill) => ({
|
|
286
307
|
...skill,
|
|
@@ -367,6 +388,6 @@ function safeRealpath(path) {
|
|
|
367
388
|
return path;
|
|
368
389
|
}
|
|
369
390
|
}
|
|
370
|
-
function unsupported(reason) {
|
|
371
|
-
return { kind: "unsupported", reason };
|
|
391
|
+
function unsupported(reason, channel = "unknown") {
|
|
392
|
+
return { kind: "unsupported", reason, channel };
|
|
372
393
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"operation":"unknown","action":false,"options":["-V, --version","--json-errors"],"children":{"auth":{"operation":"auth","action":false,"options":[],"children":{"login":{"operation":"auth.login","action":true,"options":["--no-browser","--require-browser"],"children":{}},"status":{"operation":"auth.status","action":true,"options":["--json"],"children":{}},"logout":{"operation":"auth.logout","action":true,"options":[],"children":{}}}},"org":{"operation":"org","action":false,"options":[],"children":{"list":{"operation":"org.list","action":true,"options":["--json"],"children":{}},"current":{"operation":"org.current","action":true,"options":["--json"],"children":{}},"switch":{"operation":"org.switch","action":true,"options":["--org <org-id>"],"children":{}}}},"agent":{"operation":"agent","action":false,"options":[],"children":{"send":{"operation":"agent.send","action":true,"options":["--schema","--input <file|->","--async","--json","--with-skills"],"children":{}}}},"tool":{"operation":"tool","action":false,"options":[],"children":{"list":{"operation":"tool.list","action":true,"options":["--json"],"children":{}},"call":{"operation":"tool.call","action":true,"options":["--schema","--input <file|->","--async","--json","--with-skills"],"children":{}}}},"model":{"operation":"model","action":false,"options":[],"children":{"list":{"operation":"model.list","action":true,"options":["--tool <tool>","--json","--with-skills"],"children":{}},"get":{"operation":"model.get","action":true,"options":["--tool <tool>","--json","--with-skills"],"children":{}}}},"dam":{"operation":"dam","action":false,"options":[],"children":{"repository":{"operation":"dam.repository","action":false,"options":[],"children":{"list":{"operation":"dam.repository.list","action":true,"options":["--json"],"children":{}}}},"folder":{"operation":"dam.folder","action":false,"options":[],"children":{"list":{"operation":"dam.folder.list","action":true,"options":["--repository-id <id>","--parent-id <id>","--query <text>","--page <n>","--page-size <number>","--json"],"children":{}}}},"tag":{"operation":"dam.tag","action":false,"options":[],"children":{"list":{"operation":"dam.tag.list","action":true,"options":["--repository-id <id>","--query <text>","--json"],"children":{}}}},"download":{"operation":"dam.download","action":true,"options":["--repository-id <id>","--output-dir <directory>","--json"],"children":{}},"rename":{"operation":"dam.rename","action":true,"options":["--kind <asset|folder>","--title <title>","--repository-id <id>","--json"],"children":{}},"move":{"operation":"dam.move","action":true,"options":["--kind <asset|folder>","--target-folder-id <id>","--repository-id <source-id>","--target-repository-id <target-id>","--json"],"children":{}},"copy":{"operation":"dam.copy","action":true,"options":["--kind <asset|folder>","--target-folder-id <id>","--repository-id <source-id>","--target-repository-id <target-id>","--json"],"children":{}},"list":{"operation":"dam.list","action":true,"options":["--repository-id <id>","--all-repositories","--folder-id <id>","--no-include-child-folder","--type <type>","--asset-format <csv>","--tag-ids <csv>","--page-size <number>","--cursor <id>","--json"],"children":{}},"search":{"operation":"dam.search","action":true,"options":["--repository-id <id>","--all-repositories","--folder-id <id>","--no-include-child-folder","--type <type>","--asset-format <csv>","--tag-ids <csv>","--page-size <number>","--cursor <id>","--json"],"children":{}},"get":{"operation":"dam.get","action":true,"options":["--json"],"children":{}},"upload":{"operation":"dam.upload","action":true,"options":["--repository-id <id>","--title <title>","--folder-id <id>","--tag-ids <csv>","--allow-sensitive-path","--wait-analysis","--json"],"children":{}},"delete":{"operation":"dam.delete","action":true,"options":["--repository-id <id>","--permanent"],"children":{}}}},"update":{"operation":"update","action":true,"options":[],"children":{"check":{"operation":"update.check","action":true,"options":["--for-display","--schema","--json"],"children":{}}}},"task":{"operation":"task","action":false,"options":[],"children":{"list":{"operation":"task.list","action":true,"options":["--limit <number>","--operation <operation>","--json"],"children":{}},"get":{"operation":"task.get","action":true,"options":["--json"],"children":{}}}},"credits":{"operation":"credits.get","action":true,"options":["--json","--schema"],"children":{"usage":{"operation":"credits.usage","action":false,"options":[],"children":{"list":{"operation":"credits.usage.list","action":true,"options":["--from <timestamp>","--to <timestamp>","--limit <number>","--cursor <cursor>","--json","--schema"],"children":{}},"get":{"operation":"credits.usage.get","action":true,"options":["--json","--schema"],"children":{}}}}}}}}
|
|
1
|
+
{"operation":"unknown","action":false,"options":["-V, --version","--json-errors"],"children":{"auth":{"operation":"auth","action":false,"options":[],"children":{"login":{"operation":"auth.login","action":true,"options":["--no-browser","--require-browser"],"children":{}},"status":{"operation":"auth.status","action":true,"options":["--json"],"children":{}},"logout":{"operation":"auth.logout","action":true,"options":[],"children":{}}}},"org":{"operation":"org","action":false,"options":[],"children":{"list":{"operation":"org.list","action":true,"options":["--json"],"children":{}},"current":{"operation":"org.current","action":true,"options":["--json"],"children":{}},"switch":{"operation":"org.switch","action":true,"options":["--org <org-id>"],"children":{}}}},"agent":{"operation":"agent","action":false,"options":[],"children":{"send":{"operation":"agent.send","action":true,"options":["--schema","--input <file|->","--async","--json","--with-skills"],"children":{}}}},"tool":{"operation":"tool","action":false,"options":[],"children":{"list":{"operation":"tool.list","action":true,"options":["--json","--with-skills"],"children":{}},"call":{"operation":"tool.call","action":true,"options":["--schema","--input <file|->","--async","--json","--with-skills"],"children":{}}}},"model":{"operation":"model","action":false,"options":[],"children":{"list":{"operation":"model.list","action":true,"options":["--tool <tool>","--json","--with-skills"],"children":{}},"get":{"operation":"model.get","action":true,"options":["--tool <tool>","--json","--with-skills"],"children":{}}}},"dam":{"operation":"dam","action":false,"options":[],"children":{"repository":{"operation":"dam.repository","action":false,"options":[],"children":{"list":{"operation":"dam.repository.list","action":true,"options":["--json"],"children":{}}}},"folder":{"operation":"dam.folder","action":false,"options":[],"children":{"list":{"operation":"dam.folder.list","action":true,"options":["--repository-id <id>","--parent-id <id>","--query <text>","--page <n>","--page-size <number>","--json"],"children":{}}}},"tag":{"operation":"dam.tag","action":false,"options":[],"children":{"list":{"operation":"dam.tag.list","action":true,"options":["--repository-id <id>","--query <text>","--json"],"children":{}}}},"download":{"operation":"dam.download","action":true,"options":["--repository-id <id>","--output-dir <directory>","--json"],"children":{}},"rename":{"operation":"dam.rename","action":true,"options":["--kind <asset|folder>","--title <title>","--repository-id <id>","--json"],"children":{}},"move":{"operation":"dam.move","action":true,"options":["--kind <asset|folder>","--target-folder-id <id>","--repository-id <source-id>","--target-repository-id <target-id>","--json"],"children":{}},"copy":{"operation":"dam.copy","action":true,"options":["--kind <asset|folder>","--target-folder-id <id>","--repository-id <source-id>","--target-repository-id <target-id>","--json"],"children":{}},"list":{"operation":"dam.list","action":true,"options":["--repository-id <id>","--all-repositories","--folder-id <id>","--no-include-child-folder","--type <type>","--asset-format <csv>","--tag-ids <csv>","--page-size <number>","--cursor <id>","--json"],"children":{}},"search":{"operation":"dam.search","action":true,"options":["--repository-id <id>","--all-repositories","--folder-id <id>","--no-include-child-folder","--type <type>","--asset-format <csv>","--tag-ids <csv>","--page-size <number>","--cursor <id>","--json"],"children":{}},"get":{"operation":"dam.get","action":true,"options":["--json"],"children":{}},"upload":{"operation":"dam.upload","action":true,"options":["--repository-id <id>","--title <title>","--folder-id <id>","--tag-ids <csv>","--allow-sensitive-path","--wait-analysis","--json"],"children":{}},"delete":{"operation":"dam.delete","action":true,"options":["--repository-id <id>","--permanent"],"children":{}}}},"update":{"operation":"update","action":true,"options":[],"children":{"check":{"operation":"update.check","action":true,"options":["--for-display","--schema","--json"],"children":{}}}},"task":{"operation":"task","action":false,"options":[],"children":{"list":{"operation":"task.list","action":true,"options":["--limit <number>","--operation <operation>","--json"],"children":{}},"get":{"operation":"task.get","action":true,"options":["--json"],"children":{}}}},"credits":{"operation":"credits.get","action":true,"options":["--json","--schema"],"children":{"usage":{"operation":"credits.usage","action":false,"options":[],"children":{"list":{"operation":"credits.usage.list","action":true,"options":["--from <timestamp>","--to <timestamp>","--limit <number>","--cursor <cursor>","--json","--schema"],"children":{}},"get":{"operation":"credits.usage.get","action":true,"options":["--json","--schema"],"children":{}}}}}},"feedback":{"operation":"feedback.submit","action":true,"options":["--schema","--input <file|->","--json"],"children":{}}}}
|
|
@@ -5,8 +5,9 @@ export function hostName(value) {
|
|
|
5
5
|
return typeof value === "string" && value.trim() ? value.trim().slice(0, 128) : undefined;
|
|
6
6
|
}
|
|
7
7
|
export function hostTelemetryContext(env) {
|
|
8
|
+
const host = hostName(env.CLI_HOST_APPLICATION) ?? "unknown";
|
|
8
9
|
return {
|
|
9
|
-
host_application:
|
|
10
|
+
host_application: host, host_application_source: host === "unknown" ? "unknown" : "environment",
|
|
10
11
|
...(["auth_status", "version_check"].includes(env.CLI_INVOCATION_PURPOSE ?? "")
|
|
11
12
|
? { invocation_purpose: env.CLI_INVOCATION_PURPOSE } : {}),
|
|
12
13
|
...(/^[a-f0-9]{32}$/u.test(env.CLI_HOST_INVOCATION_ID ?? "") ? { host_invocation_id: env.CLI_HOST_INVOCATION_ID } : {}),
|
|
@@ -39,7 +40,7 @@ export function createTelemetryInvocation(options) {
|
|
|
39
40
|
function identity() {
|
|
40
41
|
const mode = definition?.mode?.();
|
|
41
42
|
const creation = mode === "execute" && (definition?.operation === "agent.send" || definition?.operation === "tool.call");
|
|
42
|
-
return { host_application: context.host_application ?? "unknown", schema_version: "6", started_at_ms: startedAt, command_kind: creation ? "creation" : "technical", cli_name: options.cliName ?? "gd-cli",
|
|
43
|
+
return { host_application: context.host_application ?? "unknown", host_application_source: context.host_application_source ?? "unknown", schema_version: "6", started_at_ms: startedAt, command_kind: creation ? "creation" : "technical", cli_name: options.cliName ?? "gd-cli",
|
|
43
44
|
env: options.env ?? "production", process_role: options.processRole ?? "cli",
|
|
44
45
|
trace_id: traceId,
|
|
45
46
|
operation: definition?.operation ?? "unknown", ...(mode ? { mode } : {}),
|
|
@@ -123,8 +124,11 @@ export function createTelemetryInvocation(options) {
|
|
|
123
124
|
await publish(remember({ ...base(), occurred_at_ms: startedAt, event_name: "command_step", step: "issued", outcome: "success" }));
|
|
124
125
|
},
|
|
125
126
|
observeHost(value) {
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
const host = hostName(value);
|
|
128
|
+
if (host && host !== "unknown" && (!context.host_application || context.host_application === "unknown")) {
|
|
129
|
+
context.host_application = host;
|
|
130
|
+
context.host_application_source = "input";
|
|
131
|
+
}
|
|
128
132
|
},
|
|
129
133
|
useSignal(next) { signal = next; },
|
|
130
134
|
annotate(annotation) {
|
|
@@ -8,8 +8,13 @@ import { gaodingProduct, insmindProduct } from "../product/config.js";
|
|
|
8
8
|
import { createTelemetryInvocation, hostTelemetryContext } from "./invocation.js";
|
|
9
9
|
import { createSlsTelemetrySink } from "./sls-sink.js";
|
|
10
10
|
// The normal runtime or even Commander may be unavailable. Only package-owned names may enter SLS.
|
|
11
|
-
async function bootstrapDefinition(argv) {
|
|
11
|
+
async function bootstrapDefinition(argv, product) {
|
|
12
12
|
try {
|
|
13
|
+
if (argv.includes("--skill")) {
|
|
14
|
+
const { skillManualArguments } = await import("../features/skill/manual.js");
|
|
15
|
+
if (skillManualArguments(argv, product))
|
|
16
|
+
return { operation: "skill", mode: () => "help" };
|
|
17
|
+
}
|
|
13
18
|
const [{ identifyInvocation }, catalog] = await Promise.all([
|
|
14
19
|
import("./command-route.js"), readFile(new URL("./command-routes.json", import.meta.url), "utf8")
|
|
15
20
|
]);
|
|
@@ -48,7 +53,7 @@ export async function reportProcessError(error, options) {
|
|
|
48
53
|
traceIdFactory: () => options.traceId ?? randomBytes(16).toString("hex"), spanIdFactory: () => randomBytes(8).toString("hex"),
|
|
49
54
|
runtime: { os: process.platform, arch: process.arch, nodeMajor: Number(process.versions.node.split(".")[0]) },
|
|
50
55
|
classifyError: () => classification });
|
|
51
|
-
const definition = options.argv ? await bootstrapDefinition(options.argv) : { operation: options.operation };
|
|
56
|
+
const definition = options.argv ? await bootstrapDefinition(options.argv, product.commandName) : { operation: options.operation };
|
|
52
57
|
telemetry.select(definition);
|
|
53
58
|
telemetry.annotate(hostTelemetryContext(process.env));
|
|
54
59
|
if ((options.processRole ?? "cli") === "cli")
|
|
@@ -4,25 +4,26 @@ const ids = new Set(["account_id", "organization_id", "cli_task_id", "task_id",
|
|
|
4
4
|
function sensitive(key) {
|
|
5
5
|
return isSensitiveKey(key) || /(?:token|secret)$/iu.test(key) || /^(?:x[-_]?)?(?:bridge[-_]?token|signature|access[-_]?key|cookie|authorization)$/iu.test(key);
|
|
6
6
|
}
|
|
7
|
-
export function cleanText(value) {
|
|
7
|
+
export function cleanText(value, omitUrlPath = false) {
|
|
8
8
|
try {
|
|
9
9
|
const parsed = JSON.parse(value);
|
|
10
10
|
if (parsed !== null && typeof parsed === "object")
|
|
11
11
|
return JSON.stringify(cleanDiagnostic(parsed));
|
|
12
12
|
}
|
|
13
13
|
catch { /* Most messages are prose, not JSON. */ }
|
|
14
|
-
return redactSensitiveText(value.replace(/https?:\/\/[^\s<>"
|
|
14
|
+
return redactSensitiveText(value.replace(/https?:\/\/[^\s<>"`]+/giu, raw => {
|
|
15
15
|
try {
|
|
16
16
|
const url = new URL(raw);
|
|
17
|
+
if (omitUrlPath)
|
|
18
|
+
return url.origin;
|
|
17
19
|
url.username = "";
|
|
18
20
|
url.password = "";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
url.searchParams.set(key, "[REDACTED]");
|
|
21
|
+
url.search = "";
|
|
22
|
+
url.hash = "";
|
|
22
23
|
return url.href;
|
|
23
24
|
}
|
|
24
25
|
catch {
|
|
25
|
-
return
|
|
26
|
+
return "[Invalid URL]";
|
|
26
27
|
}
|
|
27
28
|
})).replace(/\b(?:Bearer\s+)[^\s,;"']+/giu, "Bearer [REDACTED]")
|
|
28
29
|
.replace(/("(?:[^"\s]*token|[^"\s]*secret|(?:x[-_]?)?access[-_]?key(?:[-_]?id)?|authorization|cookie|signature|ak|sk)"\s*:\s*)"[^"\r\n]*"/giu, '$1"[REDACTED]"');
|
|
@@ -34,12 +35,22 @@ export function cleanDiagnostic(value) {
|
|
|
34
35
|
const toolDiagnostic = (tool || (envelope.operation === "task.get" && ["dify", "toolkit", "sync"].includes(String(envelope.execution_protocol)))) && envelope.event_name === "stage_finished";
|
|
35
36
|
function clean(item, depth, inParameters = false) {
|
|
36
37
|
if (typeof item === "string" && inParameters) {
|
|
38
|
+
// Some adapters store nested arguments as JSON text. Keep the surrounding
|
|
39
|
+
// Tool context when redacting those fields, and retain the wire type.
|
|
40
|
+
if (/^\s*[\[{]/u.test(item)) {
|
|
41
|
+
if (depth > 20)
|
|
42
|
+
return "[Truncated]";
|
|
43
|
+
try {
|
|
44
|
+
return JSON.stringify(clean(JSON.parse(item), depth + 1, true));
|
|
45
|
+
}
|
|
46
|
+
catch { /* Ordinary parameter text may start with a bracket. */ }
|
|
47
|
+
}
|
|
37
48
|
if (posix.isAbsolute(item) || win32.isAbsolute(item) || /^file:\/\//iu.test(item))
|
|
38
49
|
return "[Local file]";
|
|
39
50
|
item = item.replace(/file:\/\/[^\s<>"`]+/giu, "[Local file]");
|
|
40
51
|
}
|
|
41
52
|
if (typeof item === "string")
|
|
42
|
-
return /^data:[^,]*;base64,/iu.test(item) ? "[Binary omitted]" : cleanText(item);
|
|
53
|
+
return /^data:[^,]*;base64,/iu.test(item) ? "[Binary omitted]" : cleanText(item, inParameters);
|
|
43
54
|
if (typeof item === "bigint")
|
|
44
55
|
return String(item);
|
|
45
56
|
if (item === null || typeof item !== "object")
|
|
@@ -16,7 +16,31 @@ export function eventKey(event) {
|
|
|
16
16
|
return createHash("sha256").update(JSON.stringify(key)).digest("hex");
|
|
17
17
|
}
|
|
18
18
|
export function wireEvent(event) {
|
|
19
|
-
const
|
|
19
|
+
const fields = { ...event };
|
|
20
|
+
const agent = fields.operation === "agent.send" || (fields.operation === "task.get" && !fields.execution_protocol);
|
|
21
|
+
if (fields.event_name === "stage_finished" && agent && Number(fields.http_status) >= 400)
|
|
22
|
+
delete fields.remote_error_body;
|
|
23
|
+
// Old queues store structured fields as JSON strings. Keep their event context
|
|
24
|
+
// when applying current rules for Tool prompts and failure evidence.
|
|
25
|
+
for (const key of ["parameters", "diagnostic_summary"]) {
|
|
26
|
+
const value = fields[key];
|
|
27
|
+
if (typeof value !== "string")
|
|
28
|
+
continue;
|
|
29
|
+
try {
|
|
30
|
+
fields[key] = JSON.parse(value);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
delete fields[key];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const parameters = fields.parameters;
|
|
37
|
+
if (parameters !== undefined && (typeof parameters !== "object" || parameters === null || Array.isArray(parameters))) {
|
|
38
|
+
delete fields.parameters;
|
|
39
|
+
}
|
|
40
|
+
else if (typeof parameters === "object" && parameters && "truncated" in parameters && parameters.truncated === true && "preview" in parameters) {
|
|
41
|
+
fields.parameters = { truncated: true };
|
|
42
|
+
}
|
|
43
|
+
const safe = cleanDiagnostic(fields);
|
|
20
44
|
if ("diagnostic_summary" in safe) {
|
|
21
45
|
const summary = safeFailureSummary(safe.diagnostic_summary);
|
|
22
46
|
if (summary)
|
|
@@ -24,9 +48,9 @@ export function wireEvent(event) {
|
|
|
24
48
|
else
|
|
25
49
|
delete safe.diagnostic_summary;
|
|
26
50
|
}
|
|
27
|
-
const wire = { event_id: eventKey(
|
|
51
|
+
const wire = { event_id: eventKey(event) };
|
|
28
52
|
for (const [key, value] of Object.entries(safe)) {
|
|
29
|
-
if (value !== undefined)
|
|
53
|
+
if (key !== "event_id" && value !== undefined)
|
|
30
54
|
wire[key] = typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
31
55
|
}
|
|
32
56
|
for (const key of ["error_stack", "remote_error_body", "error_message"]) {
|
|
@@ -36,7 +60,7 @@ export function wireEvent(event) {
|
|
|
36
60
|
}
|
|
37
61
|
}
|
|
38
62
|
if (wire.parameters && Buffer.byteLength(wire.parameters) > 32 * 1024) {
|
|
39
|
-
wire.parameters = JSON.stringify({ truncated: true
|
|
63
|
+
wire.parameters = JSON.stringify({ truncated: true });
|
|
40
64
|
wire.truncated = "true";
|
|
41
65
|
}
|
|
42
66
|
if (Buffer.byteLength(JSON.stringify(wire)) > 64 * 1024) {
|
|
@@ -135,24 +159,23 @@ export function createSlsTelemetrySink(options) {
|
|
|
135
159
|
}
|
|
136
160
|
return;
|
|
137
161
|
}
|
|
162
|
+
let entry;
|
|
138
163
|
try {
|
|
139
|
-
|
|
164
|
+
entry = JSON.parse(raw);
|
|
140
165
|
if (entry.event?.schema_version !== "6" || !Number.isFinite(entry.queuedAt) || eventKey(entry.event) !== name.slice(0, -5))
|
|
141
166
|
throw new Error();
|
|
142
|
-
|
|
143
|
-
const event = entry.event;
|
|
144
|
-
if (event.event_name === "stage_finished") {
|
|
145
|
-
delete event.parameters;
|
|
146
|
-
const agent = event.operation === "agent.send" || (event.operation === "task.get" && !event.execution_protocol);
|
|
147
|
-
if (agent && Number(event.http_status) >= 400)
|
|
148
|
-
delete event.remote_error_body;
|
|
149
|
-
}
|
|
150
|
-
entries.set(name.slice(0, -5), entry);
|
|
167
|
+
entry.event = wireEvent(entry.event);
|
|
151
168
|
}
|
|
152
169
|
catch {
|
|
153
170
|
await unlink(join(directory, name)).catch(() => undefined);
|
|
154
171
|
await dropped("corrupt", 1);
|
|
172
|
+
return;
|
|
155
173
|
}
|
|
174
|
+
const id = name.slice(0, -5);
|
|
175
|
+
if (JSON.stringify(entry) !== raw)
|
|
176
|
+
await persist(id, entry);
|
|
177
|
+
else
|
|
178
|
+
entries.set(id, entry);
|
|
156
179
|
}
|
|
157
180
|
async function saveStatus() {
|
|
158
181
|
// Health recording must never stop the original event acknowledgement/backoff path.
|
|
@@ -204,7 +227,7 @@ export function createSlsTelemetrySink(options) {
|
|
|
204
227
|
const id = eventKey(event);
|
|
205
228
|
if (entries.has(id))
|
|
206
229
|
continue;
|
|
207
|
-
// Persist the sanitized, bounded
|
|
230
|
+
// Persist only the sanitized, bounded payload.
|
|
208
231
|
await persist(id, { event: wireEvent(event), queuedAt: now(), nextAttempt: 0, attempts: 0 });
|
|
209
232
|
}
|
|
210
233
|
await trim(deadline);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gaoding/cli",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Gaoding command-line interface for agents and people.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"tag": "latest"
|
|
11
11
|
},
|
|
12
12
|
"engines": {
|
|
13
|
-
"node": ">=20.
|
|
13
|
+
"node": ">=20.10.0"
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
16
|
"gd-cli": "dist/bin/gd-cli.js"
|
|
@@ -44,8 +44,7 @@
|
|
|
44
44
|
"open": "11.0.0",
|
|
45
45
|
"qrcode": "1.5.4",
|
|
46
46
|
"semver": "7.8.5",
|
|
47
|
-
"sharp": "0.35.5"
|
|
48
|
-
"ws": "8.23.0"
|
|
47
|
+
"sharp": "0.35.5"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
50
|
"@gaoding/gd-connector-contracts": "workspace:*",
|
|
@@ -56,6 +55,7 @@
|
|
|
56
55
|
"@types/ws": "8.18.1",
|
|
57
56
|
"typescript": "7.0.2",
|
|
58
57
|
"vitest": "4.1.10",
|
|
58
|
+
"ws": "8.23.0",
|
|
59
59
|
"@gaoding/model-catalog": "workspace:*"
|
|
60
60
|
},
|
|
61
61
|
"imports": {
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
"gaodingRelease": {
|
|
68
|
-
"sourceCommit": "
|
|
69
|
-
"pipelineId": "
|
|
70
|
-
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/
|
|
68
|
+
"sourceCommit": "1606633d4ce7d82216ad9c1bf1d1e1bc1e11ebd4",
|
|
69
|
+
"pipelineId": "290481",
|
|
70
|
+
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/290481"
|
|
71
71
|
}
|
|
72
72
|
}
|
package/skills/gd-cli/SKILL.md
CHANGED
|
@@ -15,8 +15,8 @@ description: 用户希望通过稿定 CLI 创作或处理图片、视频、文
|
|
|
15
15
|
|
|
16
16
|
## 查找具体指引
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
查模型或工具时,可以从结果找到对应的用法。用户要开始创作或继续加工,而你还缺用法时,用 `gd-cli --skill <章节>` 读对应章节。要浏览目录,用 `gd-cli --skill`。
|
|
19
19
|
|
|
20
20
|
## 续作和交付
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
续作沿用上轮的上下文,上次提交后如果没看到结果,先用 `gd-cli task get <上次返回的任务号>` 查进度。交付实际返回的正文或完整成品链接,说明回执中的估价或实扣。
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
export class EditorBridgeError extends Error {
|
|
2
|
-
code;
|
|
3
|
-
constructor(code, message, options) {
|
|
4
|
-
super(message, options);
|
|
5
|
-
this.name = "EditorBridgeError";
|
|
6
|
-
this.code = code;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export class EditorBridgeUnavailableError extends Error {
|
|
10
|
-
constructor(cause) {
|
|
11
|
-
super("Editor Bridge is unavailable.", { cause });
|
|
12
|
-
this.name = "EditorBridgeUnavailableError";
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export function createEditorBridgeClient(options) {
|
|
16
|
-
const fetch = options.fetch ?? globalThis.fetch;
|
|
17
|
-
const baseUrl = `http://127.0.0.1:${options.state.port}`;
|
|
18
|
-
return {
|
|
19
|
-
async health(signal) {
|
|
20
|
-
const value = await request("/health", "GET", undefined, signal);
|
|
21
|
-
if (!isRecord(value) ||
|
|
22
|
-
value.status !== "ok" ||
|
|
23
|
-
typeof value.pageConnected !== "boolean" ||
|
|
24
|
-
typeof value.protocolVersion !== "number") {
|
|
25
|
-
throw invalidResponse();
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
status: "ok",
|
|
29
|
-
pageConnected: value.pageConnected,
|
|
30
|
-
protocolVersion: value.protocolVersion
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
async rpc(method, payload, signal) {
|
|
34
|
-
const value = await request("/rpc", "POST", { method, ...(payload === undefined ? {} : { payload }) }, signal);
|
|
35
|
-
if (!isRecord(value) ||
|
|
36
|
-
(!hasExactKeys(value, []) && (!Object.hasOwn(value, "result") || Object.hasOwn(value, "error")))) {
|
|
37
|
-
throw invalidResponse();
|
|
38
|
-
}
|
|
39
|
-
return value.result;
|
|
40
|
-
},
|
|
41
|
-
async disconnect(signal) {
|
|
42
|
-
const value = await request("/disconnect", "POST", {}, signal);
|
|
43
|
-
if (!isRecord(value) ||
|
|
44
|
-
value.status !== "disconnected") {
|
|
45
|
-
throw invalidResponse();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
async function request(pathname, method, body, signal) {
|
|
50
|
-
signal.throwIfAborted();
|
|
51
|
-
let response;
|
|
52
|
-
try {
|
|
53
|
-
response = await fetch(`${baseUrl}${pathname}`, {
|
|
54
|
-
method,
|
|
55
|
-
headers: {
|
|
56
|
-
Authorization: `Bearer ${options.state.token}`,
|
|
57
|
-
...(body === undefined ? {} : { "Content-Type": "application/json" })
|
|
58
|
-
},
|
|
59
|
-
redirect: "error",
|
|
60
|
-
signal,
|
|
61
|
-
...(body === undefined ? {} : { body: JSON.stringify(body) })
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
signal.throwIfAborted();
|
|
66
|
-
throw new EditorBridgeUnavailableError(error);
|
|
67
|
-
}
|
|
68
|
-
let value;
|
|
69
|
-
try {
|
|
70
|
-
value = await response.json();
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
throw invalidResponse();
|
|
74
|
-
}
|
|
75
|
-
if (!response.ok) {
|
|
76
|
-
const error = readStructuredError(value);
|
|
77
|
-
if (!error)
|
|
78
|
-
throw invalidResponse();
|
|
79
|
-
throw new EditorBridgeError(error.code, error.message);
|
|
80
|
-
}
|
|
81
|
-
return value;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function readStructuredError(value) {
|
|
85
|
-
if (!isRecord(value) || !isRecord(value.error))
|
|
86
|
-
return null;
|
|
87
|
-
const { code, message } = value.error;
|
|
88
|
-
if (typeof code !== "string" ||
|
|
89
|
-
!/^[A-Z][A-Z0-9_]*$/.test(code) ||
|
|
90
|
-
typeof message !== "string" ||
|
|
91
|
-
message.trim().length === 0) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
return { code, message };
|
|
95
|
-
}
|
|
96
|
-
function invalidResponse() {
|
|
97
|
-
return new EditorBridgeError("EDITOR_BRIDGE_INVALID_RESPONSE", "Editor Bridge 返回了无效响应。");
|
|
98
|
-
}
|
|
99
|
-
function isRecord(value) {
|
|
100
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
101
|
-
}
|
|
102
|
-
function hasExactKeys(value, keys) {
|
|
103
|
-
const actual = Object.keys(value).sort();
|
|
104
|
-
const expected = [...keys].sort();
|
|
105
|
-
return actual.length === expected.length &&
|
|
106
|
-
actual.every((key, index) => key === expected[index]);
|
|
107
|
-
}
|