@gaoding/cli 2.1.8 → 3.0.1
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 +6 -3
- package/contracts/operations/tool.call/canvas-input.schema.json +0 -3
- package/contracts/presentations/agent.send.schema.json +303 -0
- package/contracts/presentations/model.get.schema.json +246 -0
- package/contracts/presentations/model.list.schema.json +144 -0
- package/contracts/presentations/task.get.schema.json +146 -0
- package/contracts/presentations/tool.call.schema.json +200 -0
- package/dist/bin/gd-cli.js +9 -3
- package/dist/bin/insmind-cli.js +6 -1
- package/dist/src/bootstrap/create-cli.js +7 -4
- package/dist/src/bootstrap/create-runtime.js +7 -32
- package/dist/src/cli/action-binding.js +2 -2
- package/dist/src/cli/agent-commands.js +5 -4
- package/dist/src/cli/auth-commands.js +1 -1
- package/dist/src/cli/dam-commands.js +18 -10
- package/dist/src/cli/errors.js +1 -35
- package/dist/src/cli/host-input.js +0 -11
- package/dist/src/cli/model-commands.js +6 -5
- package/dist/src/cli/skill-output.js +13 -0
- package/dist/src/cli/tool-commands.js +9 -5
- package/dist/src/features/skill/catalog.js +152 -0
- package/dist/src/features/skill/manual.js +71 -0
- package/dist/src/features/tool/archived-ocr-result.js +74 -0
- package/dist/src/features/tool/canvas-copy.js +2 -3
- package/dist/src/features/tool/canvas-models.js +2 -4
- package/dist/src/features/tool/canvas-recovery.js +3 -2
- package/dist/src/features/tool/canvas-results.js +1 -55
- package/dist/src/features/tool/canvas-tool-adapter.js +7 -10
- package/dist/src/features/tool/resource-authorizer.js +1 -1
- package/dist/src/features/tool/scene-catalog-adapter.js +20 -22
- package/dist/src/features/tool/tool-definitions.js +0 -1
- package/dist/src/product/config.js +0 -7
- package/dist/src/telemetry/command-routes.json +1 -1
- package/package.json +5 -5
- package/skills/gd-cli/SKILL.md +10 -29
- package/contracts/operations/editor.apply/input.schema.json +0 -134
- package/contracts/operations/editor.apply/output.schema.json +0 -15
- package/contracts/operations/editor.connect/input.schema.json +0 -15
- package/contracts/operations/editor.connect/output.schema.json +0 -17
- package/contracts/operations/editor.disconnect/input.schema.json +0 -8
- package/contracts/operations/editor.disconnect/output.schema.json +0 -14
- package/contracts/operations/editor.save/input.schema.json +0 -8
- package/contracts/operations/editor.save/output.schema.json +0 -23
- package/contracts/operations/editor.screenshot/input.schema.json +0 -8
- package/contracts/operations/editor.screenshot/output.schema.json +0 -16
- package/contracts/operations/editor.snapshot/input.schema.json +0 -8
- package/contracts/operations/editor.snapshot/output.schema.json +0 -113
- package/contracts/operations/tool.call/models/image-ocr.schema.json +0 -22
- package/contracts/operations/tool.call/ocr-payload.schema.json +0 -65
- package/dist/src/cli/editor-commands.js +0 -136
- package/skills/gd-cli/references/agent.md +0 -39
- package/skills/gd-cli/references/auth-org.md +0 -11
- package/skills/gd-cli/references/creation.md +0 -61
- package/skills/gd-cli/references/dam.md +0 -53
- package/skills/gd-cli/references/editor.md +0 -67
- package/skills/gd-cli/references/errors.md +0 -46
- package/skills/gd-cli/references/generation-constraints.md +0 -40
- package/skills/gd-cli/references/matting.md +0 -27
- package/skills/gd-cli/references/media-tools.md +0 -46
- package/skills/gd-cli/references/tool.md +0 -24
- package/skills/gd-cli/references/update.md +0 -22
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { skillOutput, writeSkillResult } from "./skill-output.js";
|
|
1
2
|
import { creationTaskHelp } from "./creation-help.js";
|
|
2
3
|
import { hostSchema, readHostInput } from "./host-input.js";
|
|
3
4
|
import { readAgentInputSchema } from "../contracts/creation-input.js";
|
|
4
|
-
import {
|
|
5
|
+
import { bindPreparedAction } from "./action-binding.js";
|
|
5
6
|
import { CliUsageError } from "./errors.js";
|
|
6
7
|
import { productText as text } from "../product/text.js";
|
|
7
8
|
export function registerAgentCommands(program, runtime) {
|
|
@@ -30,7 +31,7 @@ export function registerAgentCommands(program, runtime) {
|
|
|
30
31
|
text(runtime.product, "素材用独立 URL Part;本地文件用 Path(path).resolve().as_uri() 或 pathToFileURL(path).href 生成标准 URI,保留顺序和 metadata.role。--input 的 JSON 文件参数仍使用路径。", "Supply assets as separate URL Parts, preserving order and metadata.role. Generate local URIs with Path(path).resolve().as_uri() or pathToFileURL(path).href. The --input JSON file argument remains a path."),
|
|
31
32
|
""
|
|
32
33
|
].join("\n"));
|
|
33
|
-
|
|
34
|
+
skillOutput(send, runtime);
|
|
34
35
|
bindPreparedAction(send, "organization", async (signal) => {
|
|
35
36
|
signal.throwIfAborted();
|
|
36
37
|
const options = send.opts();
|
|
@@ -57,7 +58,7 @@ export function registerAgentCommands(program, runtime) {
|
|
|
57
58
|
const result = await runtime.startBackgroundTask({ operation: "agent.send", state: context.state, label: task.label, input }, signal);
|
|
58
59
|
await runtime.telemetry.stage("output", async () => {
|
|
59
60
|
runtime.validators.taskResult(result);
|
|
60
|
-
runtime.
|
|
61
|
+
await writeSkillResult(runtime, send, result, "agent.send");
|
|
61
62
|
});
|
|
62
63
|
return;
|
|
63
64
|
}
|
|
@@ -66,7 +67,7 @@ export function registerAgentCommands(program, runtime) {
|
|
|
66
67
|
access: { credential: context.state.credential, organizationId: context.state.organization.id }, signal });
|
|
67
68
|
const result = await runtime.tasks.track({ ...task, run });
|
|
68
69
|
await runtime.telemetry.stage("output", async () => {
|
|
69
|
-
runtime.
|
|
70
|
+
await writeSkillResult(runtime, send, result, "agent.send");
|
|
70
71
|
});
|
|
71
72
|
}, {
|
|
72
73
|
operation: "agent.send",
|
|
@@ -6,7 +6,7 @@ export function registerAuthCommands(program, runtime) {
|
|
|
6
6
|
const auth = program.command("auth")
|
|
7
7
|
.description(text(runtime.product, "登录与本机凭证", "Authentication and local credentials"))
|
|
8
8
|
.helpCommand(false);
|
|
9
|
-
auth.addHelpText("after", text(runtime.product, "\n管理本机 CLI
|
|
9
|
+
auth.addHelpText("after", text(runtime.product, "\n管理本机 CLI 登录。status 只读状态,login 等待浏览器授权完成,logout 清除本机共享登录。授权链接不等于登录成功;无需提供或读取 AK/SK、Cookie 等凭证。\n", "\nManages the local CLI identity. status reads state, login waits for browser authorization, and logout clears the shared local sign-in. An authorization URL is not successful login; do not provide or read credential values.\n"));
|
|
10
10
|
const login = leaf(auth.command("login"))
|
|
11
11
|
.description(text(runtime.product, "登录稿定", "Sign in to insMind"))
|
|
12
12
|
.option("--no-browser", text(runtime.product, "不自动打开浏览器", "do not open a browser automatically"))
|
|
@@ -27,7 +27,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
27
27
|
signal
|
|
28
28
|
})));
|
|
29
29
|
await runtime.telemetry.stage("output", async () => {
|
|
30
|
-
runtime.
|
|
30
|
+
await presentDamResult(runtime, result, "dam.repository.list", {
|
|
31
31
|
json: repositoryList.opts().json === true,
|
|
32
32
|
view: value => repositoryListView(value, runtime.product)
|
|
33
33
|
});
|
|
@@ -64,7 +64,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
64
64
|
signal
|
|
65
65
|
});
|
|
66
66
|
await runtime.telemetry.stage("output", async () => {
|
|
67
|
-
runtime.
|
|
67
|
+
await presentDamResult(runtime, result, "dam.folder.list", {
|
|
68
68
|
json: folderList.opts().json === true,
|
|
69
69
|
view: value => folderListView(value, runtime.product)
|
|
70
70
|
});
|
|
@@ -95,7 +95,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
95
95
|
signal
|
|
96
96
|
});
|
|
97
97
|
await runtime.telemetry.stage("output", async () => {
|
|
98
|
-
runtime.
|
|
98
|
+
await presentDamResult(runtime, result, "dam.tag.list", {
|
|
99
99
|
json: tagList.opts().json === true,
|
|
100
100
|
view: value => tagListView(value, runtime.product)
|
|
101
101
|
});
|
|
@@ -126,7 +126,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
126
126
|
signal
|
|
127
127
|
});
|
|
128
128
|
await runtime.telemetry.stage("output", async () => {
|
|
129
|
-
runtime
|
|
129
|
+
await presentDamResult(runtime, result, "dam.download", {
|
|
130
130
|
json: download.opts().json === true,
|
|
131
131
|
view: value => downloadView(value, runtime.product)
|
|
132
132
|
});
|
|
@@ -159,7 +159,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
159
159
|
signal
|
|
160
160
|
});
|
|
161
161
|
await runtime.telemetry.stage("output", async () => {
|
|
162
|
-
runtime
|
|
162
|
+
await presentDamResult(runtime, result, "dam.rename", {
|
|
163
163
|
json: rename.opts().json === true,
|
|
164
164
|
view: value => renameView(value, runtime.product)
|
|
165
165
|
});
|
|
@@ -209,7 +209,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
209
209
|
signal
|
|
210
210
|
});
|
|
211
211
|
await runtime.telemetry.stage("output", async () => {
|
|
212
|
-
runtime
|
|
212
|
+
await presentDamResult(runtime, result, `dam.${operation}`, {
|
|
213
213
|
json: command.opts().json === true,
|
|
214
214
|
view: value => operation === "move" ? moveView(value, runtime.product) : copyView(value, runtime.product)
|
|
215
215
|
});
|
|
@@ -231,7 +231,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
231
231
|
signal
|
|
232
232
|
});
|
|
233
233
|
await runtime.telemetry.stage("output", async () => {
|
|
234
|
-
runtime
|
|
234
|
+
await presentDamResult(runtime, result, "dam.list", {
|
|
235
235
|
json: list.opts().json === true,
|
|
236
236
|
view: value => assetListView(value, runtime.product)
|
|
237
237
|
});
|
|
@@ -256,7 +256,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
256
256
|
signal
|
|
257
257
|
});
|
|
258
258
|
await runtime.telemetry.stage("output", async () => {
|
|
259
|
-
runtime
|
|
259
|
+
await presentDamResult(runtime, result, "dam.search", {
|
|
260
260
|
json: search.opts().json === true,
|
|
261
261
|
view: value => assetListView(value, runtime.product)
|
|
262
262
|
});
|
|
@@ -279,7 +279,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
279
279
|
signal
|
|
280
280
|
});
|
|
281
281
|
await runtime.telemetry.stage("output", async () => {
|
|
282
|
-
runtime
|
|
282
|
+
await presentDamResult(runtime, result, "dam.get", {
|
|
283
283
|
json: get.opts().json === true,
|
|
284
284
|
view: value => assetDetailView(value, runtime.product)
|
|
285
285
|
});
|
|
@@ -318,7 +318,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
318
318
|
signal
|
|
319
319
|
});
|
|
320
320
|
await runtime.telemetry.stage("output", async () => {
|
|
321
|
-
runtime
|
|
321
|
+
await presentDamResult(runtime, result, "dam.upload", {
|
|
322
322
|
json: upload.opts().json === true,
|
|
323
323
|
view: value => assetDetailView(value, runtime.product)
|
|
324
324
|
});
|
|
@@ -354,6 +354,14 @@ export function registerDamCommands(program, runtime) {
|
|
|
354
354
|
});
|
|
355
355
|
}, { operation: "dam.delete" });
|
|
356
356
|
}
|
|
357
|
+
async function presentDamResult(runtime, result, operation, presentation) {
|
|
358
|
+
runtime.presenter.result(result, presentation);
|
|
359
|
+
if (presentation.json || !runtime.skillCatalog)
|
|
360
|
+
return;
|
|
361
|
+
const hints = await runtime.skillCatalog.recommendations(operation);
|
|
362
|
+
for (const hint of hints)
|
|
363
|
+
runtime.presenter.notice(hint.title + " — " + hint.description + " (" + hint.command + ")");
|
|
364
|
+
}
|
|
357
365
|
function leaf(command) {
|
|
358
366
|
return command.allowExcessArguments(false);
|
|
359
367
|
}
|
package/dist/src/cli/errors.js
CHANGED
|
@@ -25,10 +25,8 @@ import { RemoteProtocolError } from "../platform/remote-protocol.js";
|
|
|
25
25
|
import { InputContractError, OutputContractError } from "../bootstrap/validators.js";
|
|
26
26
|
import { JsonInputError } from "../platform/json-input.js";
|
|
27
27
|
import { LocalFileInputError } from "../platform/safe-upload-file.js";
|
|
28
|
-
import { EditorBridgeError, EditorBridgeUnavailableError } from "../features/editor/bridge-client.js";
|
|
29
28
|
import { LocalFileError } from "../platform/local-json-file.js";
|
|
30
29
|
import { redactSensitiveText } from "../platform/redact.js";
|
|
31
|
-
import { EditorNotReadyError, EditorSessionNotFoundError, EditorTargetError } from "../features/editor/session.js";
|
|
32
30
|
import { UpdateError } from "../features/update/update-service.js";
|
|
33
31
|
import { WindAnalyticsError } from "../analytics/wind.js";
|
|
34
32
|
import { safeFailureSummary } from "../telemetry/failure-summary.js";
|
|
@@ -121,7 +119,7 @@ function mapBaseCliError(error, options) {
|
|
|
121
119
|
code: "INTERRUPTED", message: text("已停止本地等待;已派发的任务或写操作可能仍在继续。", "Local waiting stopped; dispatched tasks or writes may still be active."),
|
|
122
120
|
details: { ...(error instanceof DamOperationUnconfirmedError ? { operation: error.operation, ...error.context } : {}),
|
|
123
121
|
...(error instanceof DamDownloadError ? { phase: error.phase, remaining_paths: error.remainingPaths } : {}),
|
|
124
|
-
next_steps: [text(`创作用 ${command} task list 找到原任务,再用 task get <id>
|
|
122
|
+
next_steps: [text(`创作用 ${command} task list 找到原任务,再用 task get <id> 查询。不要直接重复提交。`, `For creation, find the original task with ${command} task list, then task get <id>. Do not resubmit directly.`)] }
|
|
125
123
|
} };
|
|
126
124
|
if (error instanceof TaskBackgroundError)
|
|
127
125
|
return { kind: "failure", failure: error.failure, exitCode: error.exitCode };
|
|
@@ -159,11 +157,6 @@ function mapBaseCliError(error, options) {
|
|
|
159
157
|
return failure("AUTH_STATE_INVALID", "The account context is unavailable. Sign out and sign in again.", 1, [`${command} auth logout`, `${command} auth login`]);
|
|
160
158
|
return failure("ORG_INVALID", "所选组织不可用,请重新选择组织。", 1, ["gd-cli org list", "gd-cli org switch --org <org-id>"]);
|
|
161
159
|
}
|
|
162
|
-
if (error instanceof EditorTargetError) {
|
|
163
|
-
if (insmind)
|
|
164
|
-
return failure(error.code, "Editor target must be a work ID or a complete trusted insMind Editor URL.", 2);
|
|
165
|
-
return failure(error.code, error.message, 2);
|
|
166
|
-
}
|
|
167
160
|
if (error instanceof JsonInputError)
|
|
168
161
|
return failure("USAGE_ERROR", error.reason === "read"
|
|
169
162
|
? text("无法读取 JSON 输入。", "Cannot read the JSON input.")
|
|
@@ -300,33 +293,6 @@ function mapBaseCliError(error, options) {
|
|
|
300
293
|
}
|
|
301
294
|
if (error instanceof LocalFileError)
|
|
302
295
|
return failure("LOCAL_STATE_ERROR", text("无法访问或解析本地文件,操作未完成。", "A local file could not be accessed or parsed; the operation did not complete."), 1, [text("先检查所列文件的权限、可用空间和内容;不要删除凭证来处理文件故障。", "Check the file's permissions, available space and contents; do not delete credentials to resolve a file failure.")], { reason: error.reason, file: error.file, system_code: systemErrorCode(error) });
|
|
303
|
-
if (error instanceof EditorBridgeUnavailableError || error instanceof EditorBridgeError
|
|
304
|
-
|| error instanceof EditorSessionNotFoundError || error instanceof EditorNotReadyError) {
|
|
305
|
-
const unavailable = error instanceof EditorBridgeUnavailableError;
|
|
306
|
-
const code = unavailable ? "EDITOR_NOT_READY" : error.code;
|
|
307
|
-
let message = redactSensitiveText(error.message).slice(0, 1024);
|
|
308
|
-
if (unavailable)
|
|
309
|
-
message = text("本地 Editor Bridge 连接不可用。", "The local Editor Bridge connection is unavailable.");
|
|
310
|
-
else if (insmind) {
|
|
311
|
-
if (error instanceof EditorSessionNotFoundError)
|
|
312
|
-
message = "No Editor session is available.";
|
|
313
|
-
else if (error instanceof EditorNotReadyError)
|
|
314
|
-
message = "The Editor page did not become ready in time.";
|
|
315
|
-
else
|
|
316
|
-
message = code === "EDITOR_BRIDGE_INVALID_RESPONSE" ? "The Editor Bridge returned an invalid response." : `Editor: ${message}`;
|
|
317
|
-
}
|
|
318
|
-
const connectionError = ["EDITOR_SESSION_NOT_FOUND", "EDITOR_NOT_CONNECTED", "EDITOR_DISCONNECTED", "EDITOR_NOT_READY", "EDITOR_RPC_TIMEOUT"].includes(code);
|
|
319
|
-
let nextStep = text(`按 ${command} editor --help 中该错误的说明处理。`, `Follow the instructions for this error in ${command} editor --help.`);
|
|
320
|
-
if (connectionError && (options.operation === "editor.snapshot" || options.operation === "editor.screenshot")) {
|
|
321
|
-
const read = options.operation === "editor.snapshot" ? "snapshot" : "screenshot";
|
|
322
|
-
nextStep = text(`要继续原作品,若还没有作品链接或 ID,先向用户索取。省略目标会新建线上 Board。拿到原作品的链接或 ID 后,用 ${command} editor connect <target> 连接,再执行 ${command} editor ${read}。`, `To continue the original work, ask the user for its link or ID if you don't have it. Omitting the target creates a new production Board. With the link or ID, run ${command} editor connect <target>, then ${command} editor ${read}.`);
|
|
323
|
-
}
|
|
324
|
-
else if ((options.operation === "editor.apply" || options.operation === "editor.save")
|
|
325
|
-
&& (connectionError || ["EDITOR_ROLLBACK_FAILED", "APPLY_FAILED", "SAVE_FAILED", "EDITOR_BRIDGE_INVALID_RESPONSE"].includes(code))) {
|
|
326
|
-
nextStep = text("先检查原作品的实际状态,再决定后续操作。无法确认状态时停止写入,不重复 apply 或 save。", "Inspect the original work before taking further action. If the state is uncertain, stop writing without repeating apply or save.");
|
|
327
|
-
}
|
|
328
|
-
return failure(code, message, 1, [nextStep], unavailable ? { phase: "editor_connection" } : undefined);
|
|
329
|
-
}
|
|
330
296
|
if (systemErrorCode(error) === "ECONNRESET")
|
|
331
297
|
return failure("REMOTE_REQUEST_FAILED", text("连接中断,未能完整收到结果。", "The connection closed before the full result was received."), 1);
|
|
332
298
|
return failure("INTERNAL_ERROR", insmind ? "The CLI encountered an internal error." : "CLI 发生内部错误。", 1);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { lazySchemaCompiler } from "../platform/schema-compiler.js";
|
|
2
|
-
import { InputContractError } from "../bootstrap/validators.js";
|
|
3
2
|
import { productText } from "../product/text.js";
|
|
4
3
|
function object(value) {
|
|
5
4
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
@@ -79,13 +78,3 @@ export function hostSchema(runtime, schema, tool) {
|
|
|
79
78
|
}
|
|
80
79
|
return result;
|
|
81
80
|
}
|
|
82
|
-
export function editorActions(raw) {
|
|
83
|
-
if (!object(raw) || !Array.isArray(raw.actions))
|
|
84
|
-
throw new InputContractError([
|
|
85
|
-
{ field: "/actions", rule: "type", message: "expected an array of editor actions" }
|
|
86
|
-
]);
|
|
87
|
-
const extra = Object.keys(raw).find(key => key !== "actions");
|
|
88
|
-
if (extra)
|
|
89
|
-
throw new InputContractError([{ field: "/" + extra, rule: "additionalProperties", message: "editor action fields belong inside actions" }]);
|
|
90
|
-
return raw.actions;
|
|
91
|
-
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { skillOutput, writeSkillResult } from "./skill-output.js";
|
|
1
2
|
import { hostSchema } from "./host-input.js";
|
|
2
|
-
import {
|
|
3
|
+
import { bindAction } from "./action-binding.js";
|
|
3
4
|
import { CliUsageError } from "./errors.js";
|
|
4
5
|
import { productText as text } from "../product/text.js";
|
|
5
6
|
export function registerModelCommands(program, runtime) {
|
|
@@ -11,7 +12,7 @@ export function registerModelCommands(program, runtime) {
|
|
|
11
12
|
.option("--tool <tool>", text(runtime.product, "按工具筛选", "filter by tool"))
|
|
12
13
|
.allowExcessArguments(false);
|
|
13
14
|
list.addHelpText("after", text(runtime.product, "\n列表只提供模型摘要。选择后用 model get <model> --tool <tool> 读取完整输入、用途与保留范围,再判断是否符合需求;不能仅凭摘要推断整个工具不支持。\n", "\nThis list is a summary. Read model get <model> --tool <tool> for full inputs, purpose and preservation scope before deciding whether it meets the request; the summary alone cannot establish that the whole Tool is unsupported.\n"));
|
|
14
|
-
|
|
15
|
+
skillOutput(list, runtime);
|
|
15
16
|
bindAction(list, "organization", async (context, signal) => {
|
|
16
17
|
const selectedTool = list.opts().tool;
|
|
17
18
|
if (selectedTool !== undefined)
|
|
@@ -30,7 +31,7 @@ export function registerModelCommands(program, runtime) {
|
|
|
30
31
|
});
|
|
31
32
|
await runtime.telemetry.stage("output", async () => {
|
|
32
33
|
runtime.validators.modelListOutput(result);
|
|
33
|
-
runtime
|
|
34
|
+
await writeSkillResult(runtime, list, result, selectedTool);
|
|
34
35
|
});
|
|
35
36
|
}, { operation: "model.list" });
|
|
36
37
|
const get = model.command("get")
|
|
@@ -50,7 +51,7 @@ export function registerModelCommands(program, runtime) {
|
|
|
50
51
|
text(runtime.product, "公开 Schema 指导构参;CLI 仅检查自身读取、转换、授权和交付所必需的条件。服务端决定业务参数是否可接受,返回明确错误时按实际原因处理,不能静默替换用户值。", "The public Schema guides input construction. The CLI checks only what it needs for reading, conversion, authorization and delivery. The service decides business validity; handle its stated error without silently replacing user values."),
|
|
51
52
|
""
|
|
52
53
|
].join("\n"));
|
|
53
|
-
|
|
54
|
+
skillOutput(get, runtime);
|
|
54
55
|
bindAction(get, "organization", async (context, signal) => {
|
|
55
56
|
const modelName = get.processedArgs[0];
|
|
56
57
|
if (typeof modelName !== "string" || modelName.trim() === "")
|
|
@@ -74,7 +75,7 @@ export function registerModelCommands(program, runtime) {
|
|
|
74
75
|
const projected = result.inputSchema ? hostSchema(runtime, result.inputSchema, result.tool) : undefined;
|
|
75
76
|
const output = { ...result, ...(projected ? { inputSchema: projected } : {}) };
|
|
76
77
|
runtime.validators.modelGetOutput(output);
|
|
77
|
-
runtime
|
|
78
|
+
await writeSkillResult(runtime, get, output, result.tool);
|
|
78
79
|
});
|
|
79
80
|
}, {
|
|
80
81
|
operation: "model.get"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsonOutput } from "./action-binding.js";
|
|
2
|
+
import { productText } from "../product/text.js";
|
|
3
|
+
export function skillOutput(command, runtime) {
|
|
4
|
+
jsonOutput(command, productText(runtime.product, "仅输出原业务 JSON,供按原 Schema 校验的脚本使用", "output only the business JSON for scripts that validate its original schema"));
|
|
5
|
+
command.option("--with-skills", productText(runtime.product, "在 JSON 的 relatedSkills 中附上匹配指引(默认),也可与 --json 合用", "include matching guides in relatedSkills (default), including when used with --json"));
|
|
6
|
+
}
|
|
7
|
+
export async function writeSkillResult(runtime, command, result, operation) {
|
|
8
|
+
const { withSkills, json } = command.opts();
|
|
9
|
+
const relatedSkills = operation && (!json || withSkills)
|
|
10
|
+
? await runtime.skillCatalog?.recommendations(operation)
|
|
11
|
+
: undefined;
|
|
12
|
+
runtime.io.writeOut(JSON.stringify(relatedSkills?.length ? { ...result, relatedSkills } : result) + "\n");
|
|
13
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ToolInputError } from "../features/tool/catalog.js";
|
|
2
|
+
import { skillOutput, writeSkillResult } from "./skill-output.js";
|
|
1
3
|
import { creationTaskHelp } from "./creation-help.js";
|
|
2
4
|
import { hostSchema, readHostInput } from "./host-input.js";
|
|
3
5
|
import { jsonOutput, bindAction, bindPreparedAction } from "./action-binding.js";
|
|
@@ -7,7 +9,7 @@ export function registerToolCommands(program, runtime) {
|
|
|
7
9
|
const tool = program.command("tool")
|
|
8
10
|
.description(text(runtime.product, "生成及附件图片/视频处理:改字、抠图、分层等", "Generate and process attached images/videos: text, cutouts, layers and more"))
|
|
9
11
|
.helpCommand(false);
|
|
10
|
-
tool.addHelpText("after", text(runtime.product, "\n附件、素材链接或导出图片的处理从 tool list 发现,再用 model list --tool <tool> 和 model get <model> --tool <tool>
|
|
12
|
+
tool.addHelpText("after", text(runtime.product, "\n附件、素材链接或导出图片的处理从 tool list 发现,再用 model list --tool <tool> 和 model get <model> --tool <tool> 选择实现。模型选择和参数不决定 Agent/Tool 路线;业务策划或持续多轮创作用 agent send。\n", "\nDiscover processing for attachments, asset links and exported images with tool list, then model list --tool <tool> and model get <model> --tool <tool>. Model choices and controls do not determine Agent/Tool routing; use agent send for planning or multi-turn creation.\n"));
|
|
11
13
|
const list = tool.command("list")
|
|
12
14
|
.description(text(runtime.product, "列出可用工具", "List available tools"))
|
|
13
15
|
.allowExcessArguments(false);
|
|
@@ -40,12 +42,12 @@ export function registerToolCommands(program, runtime) {
|
|
|
40
42
|
text(runtime.product, "最终错误为 stderr 中的 JSON error 对象;stderr 也可能有进度和警告。中断退出码 130 只表示本地停止等待。", "The final error is a JSON error object on stderr, which may also contain progress and warnings. Exit code 130 means local waiting stopped."),
|
|
41
43
|
...creationTaskHelp(runtime.product),
|
|
42
44
|
text(runtime.product, "媒体 URI 字段支持 HTTP(S) 与本地 file URI;本地路径用 Python Path(path).resolve().as_uri() 或 Node.js pathToFileURL(path).href 生成,正确转义中文、空格和 #。CLI 按调用上传素材;原图、参考和选区分别放入对应字段,数组保留顺序和重复项。", "Media URI fields accept HTTP(S) and local file URIs. Generate local URIs with Python Path(path).resolve().as_uri() or Node.js pathToFileURL(path).href to escape Unicode, spaces and #. The CLI uploads them for the call; keep sources, references and masks in their own fields and preserve array order and duplicates."),
|
|
43
|
-
text(runtime.product, "完整结果为 {content,usage}。content 项为 text、resource_link(uri/name/mimeType)或 resource(resource.uri/mimeType/text
|
|
45
|
+
text(runtime.product, "完整结果为 {content,usage}。content 项为 text、resource_link(uri/name/mimeType)或 resource(resource.uri/mimeType/text)。分层返回原生模板 JSON 链接,不是 PSD。交付资源链接时原样保留完整 URI 及查询参数,不截断、拼接或去掉授权参数。", "Complete results are {content,usage}. Content items are text, resource_link (uri/name/mimeType), or resource (resource.uri/mimeType/text). Layer decomposition returns a native template JSON link, not PSD. Preserve each complete delivery URI and its query parameters without truncating, splicing or stripping authorization parameters."),
|
|
44
46
|
text(runtime.product, "Tool usage.cost 的 minimum/maximum 是目录估价,即使相等也不是实际扣费;缺失表示未提供估价,不是免费。实扣须查询可对应的 credits usage 账本;同一 taskId 重复读取不累计费用。", "Tool usage.cost minimum/maximum are catalog estimates even when equal; missing cost means no estimate, not free. Actual charges require matching credits usage ledger records. Repeated reads of one taskId do not add usage."),
|
|
45
47
|
text(runtime.product, "先交付服务返回的已有结果。效果与用户预期有差异时如实说明,后续新创作按用户要求执行;CLI 不按效果阈值判失败或自动重做。本地插值、描图等替代文件不能报告为本工具的服务结果。", "Deliver the existing service result first. Describe any difference from the user's goal and follow the user's instructions for further creation; the CLI does not fail or regenerate based on aesthetic thresholds. Files produced by local interpolation or tracing are not this Tool's service results."),
|
|
46
48
|
""
|
|
47
49
|
].join("\n"));
|
|
48
|
-
|
|
50
|
+
skillOutput(call, runtime);
|
|
49
51
|
bindPreparedAction(call, "organization", async (signal) => {
|
|
50
52
|
signal.throwIfAborted();
|
|
51
53
|
const name = call.processedArgs[0];
|
|
@@ -55,6 +57,8 @@ export function registerToolCommands(program, runtime) {
|
|
|
55
57
|
const modes = Number(options.schema === true) + Number(options.input !== undefined);
|
|
56
58
|
if (modes !== 1 || (options.schema && options.async))
|
|
57
59
|
throw new CliUsageError();
|
|
60
|
+
if (!runtime.product.tools.some(tool => tool.name === name))
|
|
61
|
+
throw new ToolInputError("tool_not_found", "/tool");
|
|
58
62
|
if (options.schema === true) {
|
|
59
63
|
return { handled: false, input: { mode: "schema", name } };
|
|
60
64
|
}
|
|
@@ -89,7 +93,7 @@ export function registerToolCommands(program, runtime) {
|
|
|
89
93
|
const result = await runtime.startBackgroundTask({ ...task, input: prepared.input }, signal);
|
|
90
94
|
await runtime.telemetry.stage("output", async () => {
|
|
91
95
|
runtime.validators.taskResult(result);
|
|
92
|
-
runtime.
|
|
96
|
+
await writeSkillResult(runtime, call, result, prepared.input.name);
|
|
93
97
|
});
|
|
94
98
|
return;
|
|
95
99
|
}
|
|
@@ -97,7 +101,7 @@ export function registerToolCommands(program, runtime) {
|
|
|
97
101
|
...(observe ? { observe } : {}) });
|
|
98
102
|
const result = await runtime.tasks.track({ ...task, run, signal });
|
|
99
103
|
await runtime.telemetry.stage("output", async () => {
|
|
100
|
-
runtime.
|
|
104
|
+
await writeSkillResult(runtime, call, result, prepared.input.name);
|
|
101
105
|
});
|
|
102
106
|
}, {
|
|
103
107
|
operation: "tool.call",
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
const edition = "cli-3.0-v1";
|
|
6
|
+
const validId = /^[a-z][a-z0-9-]{0,63}$/u;
|
|
7
|
+
const maxBytes = 256 * 1024;
|
|
8
|
+
const maxAge = 60 * 60 * 1000;
|
|
9
|
+
function parseCatalog(body) {
|
|
10
|
+
const value = JSON.parse(body);
|
|
11
|
+
if (value?.edition !== edition || !Array.isArray(value.skills) || value.skills.length > 512)
|
|
12
|
+
throw Error("Invalid skill catalog");
|
|
13
|
+
const ids = new Set();
|
|
14
|
+
for (const item of value.skills) {
|
|
15
|
+
if (!item || typeof item.id !== "string" || !validId.test(item.id) || ids.has(item.id) ||
|
|
16
|
+
typeof item.title !== "string" || !item.title.trim() || typeof item.description !== "string" || !item.description.trim() ||
|
|
17
|
+
!Array.isArray(item.operations) || !item.operations.every((op) => typeof op === "string"))
|
|
18
|
+
throw Error("Invalid skill entry");
|
|
19
|
+
ids.add(item.id);
|
|
20
|
+
}
|
|
21
|
+
return value.skills;
|
|
22
|
+
}
|
|
23
|
+
async function readCache(path) {
|
|
24
|
+
try {
|
|
25
|
+
const cached = JSON.parse(await readFile(path, "utf8"));
|
|
26
|
+
if (Number.isFinite(cached.checked) && (cached.etag === null || typeof cached.etag === "string")
|
|
27
|
+
&& typeof cached.body === "string" && Buffer.byteLength(cached.body) <= maxBytes)
|
|
28
|
+
return cached;
|
|
29
|
+
}
|
|
30
|
+
catch { /* A missing or incomplete cache can be fetched again. */ }
|
|
31
|
+
}
|
|
32
|
+
async function bodyText(response) {
|
|
33
|
+
if (!response.body || Number(response.headers.get("content-length")) > maxBytes)
|
|
34
|
+
throw Error("Invalid guide size");
|
|
35
|
+
const chunks = [];
|
|
36
|
+
let total = 0;
|
|
37
|
+
const reader = response.body.getReader();
|
|
38
|
+
try {
|
|
39
|
+
for (;;) {
|
|
40
|
+
const { done, value } = await reader.read();
|
|
41
|
+
if (done)
|
|
42
|
+
break;
|
|
43
|
+
total += value.length;
|
|
44
|
+
if (total > maxBytes) {
|
|
45
|
+
await reader.cancel();
|
|
46
|
+
throw Error("Invalid guide size");
|
|
47
|
+
}
|
|
48
|
+
chunks.push(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
reader.releaseLock();
|
|
53
|
+
}
|
|
54
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
55
|
+
}
|
|
56
|
+
export function createSkillCatalog(client, options = {}) {
|
|
57
|
+
const now = options.now ?? Date.now;
|
|
58
|
+
const dir = join(options.home ?? homedir(), client === "gd-cli" ? ".gd" : ".insmind", "skill-cache", edition);
|
|
59
|
+
async function load(chapter, parse, timeout) {
|
|
60
|
+
// Both language editions come from the public documentation service. No business payload or credentials are sent.
|
|
61
|
+
const url = new URL(options.endpoint ?? process.env[client === "gd-cli" ? "GD_CLI_SKILL_URL" : "INSMIND_CLI_SKILL_URL"] ?? "https://www.gaoding.com/mcp");
|
|
62
|
+
if (url.username || url.password || url.search || url.hash ||
|
|
63
|
+
!(url.protocol === "https:" || (url.protocol === "http:" && ["127.0.0.1", "[::1]", "localhost"].includes(url.hostname))))
|
|
64
|
+
throw Error("Invalid skill endpoint");
|
|
65
|
+
url.searchParams.set("handbook", edition);
|
|
66
|
+
url.searchParams.set("client", client);
|
|
67
|
+
if (chapter !== undefined)
|
|
68
|
+
url.searchParams.set("chapter", chapter);
|
|
69
|
+
const path = join(dir, createHash("sha256").update(url.href).digest("hex") + ".json");
|
|
70
|
+
let cached = await readCache(path);
|
|
71
|
+
let previous;
|
|
72
|
+
if (cached) {
|
|
73
|
+
try {
|
|
74
|
+
previous = parse(cached.body);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
cached = undefined;
|
|
78
|
+
}
|
|
79
|
+
if (cached && previous !== undefined && cached.checked <= now() && now() - cached.checked < maxAge)
|
|
80
|
+
return previous;
|
|
81
|
+
}
|
|
82
|
+
let response;
|
|
83
|
+
try {
|
|
84
|
+
response = await (options.fetch ?? globalThis.fetch)(url, {
|
|
85
|
+
headers: cached?.etag ? { "If-None-Match": cached.etag } : {},
|
|
86
|
+
credentials: "omit", redirect: "error", signal: AbortSignal.timeout(timeout),
|
|
87
|
+
});
|
|
88
|
+
let record;
|
|
89
|
+
if (response.status === 304 && cached)
|
|
90
|
+
record = { ...cached, checked: now() };
|
|
91
|
+
else {
|
|
92
|
+
if (response.status === 404 && chapter !== undefined) {
|
|
93
|
+
await rm(path, { force: true }).catch(() => undefined);
|
|
94
|
+
throw new MissingSkill();
|
|
95
|
+
}
|
|
96
|
+
if (response.status !== 200)
|
|
97
|
+
throw Error("Handbook HTTP " + response.status);
|
|
98
|
+
const mime = response.headers.get("content-type")?.split(";")[0]?.trim();
|
|
99
|
+
if (mime !== (chapter ? "text/markdown" : "application/json"))
|
|
100
|
+
throw Error("Invalid guide format");
|
|
101
|
+
record = { checked: now(), etag: response.headers.get("etag"), body: await bodyText(response) };
|
|
102
|
+
}
|
|
103
|
+
const value = parse(record.body);
|
|
104
|
+
const temporary = path + "." + randomUUID() + ".tmp";
|
|
105
|
+
try {
|
|
106
|
+
await mkdir(dir, { recursive: true });
|
|
107
|
+
await writeFile(temporary, JSON.stringify(record), { flag: "wx", mode: 0o600 });
|
|
108
|
+
await rename(temporary, path);
|
|
109
|
+
}
|
|
110
|
+
catch { /* A read-only filesystem still permits online documentation. */ }
|
|
111
|
+
finally {
|
|
112
|
+
await rm(temporary, { force: true }).catch(() => undefined);
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (error instanceof MissingSkill)
|
|
118
|
+
throw error;
|
|
119
|
+
if (previous !== undefined)
|
|
120
|
+
return previous;
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
if (response?.body && !response.bodyUsed)
|
|
125
|
+
await response.body.cancel().catch(() => undefined);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
list: () => load(undefined, parseCatalog, 3500),
|
|
130
|
+
read(id) {
|
|
131
|
+
if (!validId.test(id))
|
|
132
|
+
throw new MissingSkill();
|
|
133
|
+
return load(id, body => {
|
|
134
|
+
if (!/^#\s+\S/mu.test(body))
|
|
135
|
+
throw Error("Invalid guide document");
|
|
136
|
+
return body;
|
|
137
|
+
}, 3500);
|
|
138
|
+
},
|
|
139
|
+
async recommendations(operation) {
|
|
140
|
+
try {
|
|
141
|
+
const items = await load(undefined, parseCatalog, 650);
|
|
142
|
+
return items.filter(item => item.operations.some(op => op.endsWith(".*") ? operation.startsWith(op.slice(0, -1)) : op === operation))
|
|
143
|
+
.map(({ id, title, description }) => ({ id, title, description, command: client + " --skill " + id }));
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
export class MissingSkill extends Error {
|
|
152
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { createSkillCatalog, MissingSkill } from "./catalog.js";
|
|
5
|
+
/** Return undefined for normal commands. Documentation also works with lifecycle scripts disabled. */
|
|
6
|
+
export async function runSkillManual(argv, name, jsonErrors) {
|
|
7
|
+
if (!argv.includes("--skill"))
|
|
8
|
+
return;
|
|
9
|
+
const end = argv.indexOf("--");
|
|
10
|
+
const options = end < 0 ? argv : argv.slice(0, end);
|
|
11
|
+
const words = [];
|
|
12
|
+
for (let index = 0; index < options.length; index++) {
|
|
13
|
+
const argument = options[index];
|
|
14
|
+
if (argument === "--json-errors")
|
|
15
|
+
continue;
|
|
16
|
+
if (name === "insmind-cli") {
|
|
17
|
+
if (argument === "--locale") {
|
|
18
|
+
index++;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (argument.startsWith("--locale="))
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
words.push(argument);
|
|
25
|
+
}
|
|
26
|
+
if (words.shift() !== "--skill")
|
|
27
|
+
return;
|
|
28
|
+
if (end >= 0)
|
|
29
|
+
words.push(...argv.slice(end + 1));
|
|
30
|
+
const english = name === "insmind-cli";
|
|
31
|
+
const usage = english ? "Usage: insmind-cli --skill [chapter]" : "用法:gd-cli --skill [章节]";
|
|
32
|
+
const [chapter] = words;
|
|
33
|
+
const help = chapter === "--help" || chapter === "-h";
|
|
34
|
+
if (words.length > 1 || (chapter && !help && !/^[a-z][a-z0-9-]{0,63}$/u.test(chapter))) {
|
|
35
|
+
writeError("USAGE_ERROR", usage, jsonErrors);
|
|
36
|
+
return 2;
|
|
37
|
+
}
|
|
38
|
+
const catalog = createSkillCatalog(name);
|
|
39
|
+
try {
|
|
40
|
+
if (chapter !== undefined && !help) {
|
|
41
|
+
process.stdout.write(await catalog.read(chapter));
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
if (!help) {
|
|
45
|
+
const { loadBundledSkills } = await import("./bundled-skills.js");
|
|
46
|
+
const skill = loadBundledSkills(fileURLToPath(import.meta.url)).find(entry => entry.skill === name);
|
|
47
|
+
if (!skill)
|
|
48
|
+
throw Error("Missing entry Skill");
|
|
49
|
+
const entry = await readFile(join(skill.sourceDirectory, "SKILL.md"), "utf8");
|
|
50
|
+
process.stdout.write(entry.replace(/^---\n[\s\S]*?\n---\n/u, "") + "\n");
|
|
51
|
+
}
|
|
52
|
+
process.stdout.write(usage + "\n");
|
|
53
|
+
const skills = await catalog.list();
|
|
54
|
+
for (const item of skills)
|
|
55
|
+
process.stdout.write(name + " --skill " + item.id + " " + item.title + " — " + item.description + "\n");
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error instanceof MissingSkill) {
|
|
60
|
+
writeError("USAGE_ERROR", (english ? "Unknown chapter. " : "未找到该章节。") + usage, jsonErrors);
|
|
61
|
+
return 2;
|
|
62
|
+
}
|
|
63
|
+
const message = english ? "The guide is unavailable. Use command --help for basic usage."
|
|
64
|
+
: "当前无法取得指引,可用命令的 --help 查看基础用法。";
|
|
65
|
+
writeError("SKILL_UNAVAILABLE", message, jsonErrors);
|
|
66
|
+
return 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function writeError(code, message, json) {
|
|
70
|
+
process.stderr.write((json ? JSON.stringify({ error: { code, message } }) : message) + "\n");
|
|
71
|
+
}
|