@insmind/cli 2.1.3 → 2.1.5
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/dist/src/features/agent/creative-agent-adapter.js +11 -10
- package/dist/src/features/skill/bundled-skills.js +19 -7
- package/dist/src/features/skill/installer.js +41 -15
- package/dist/src/platform/signed-http-transport.js +10 -2
- package/dist/src/telemetry/failure-summary.js +4 -1
- package/package.json +4 -4
|
@@ -22,7 +22,7 @@ export function createCreativeAgentAdapter(dependencies) {
|
|
|
22
22
|
await observe?.({ submissionStarted: true });
|
|
23
23
|
const startedAt = Date.now();
|
|
24
24
|
let httpStatus;
|
|
25
|
-
const
|
|
25
|
+
const streamed = await dependencies.transport.postStream({
|
|
26
26
|
path: "/ai-agent/v1/thread/completion",
|
|
27
27
|
sensitiveResponse: true,
|
|
28
28
|
...(observe ? { onDispatch: (dispatchedAt) => observe({ dispatchedAt }) } : {}),
|
|
@@ -32,15 +32,16 @@ export function createCreativeAgentAdapter(dependencies) {
|
|
|
32
32
|
credential: access.credential,
|
|
33
33
|
organizationId: access.organizationId,
|
|
34
34
|
signal
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
}, async (stream) => {
|
|
36
|
+
await observe?.({ accepted: true });
|
|
37
|
+
return parseCreativeStream(stream, signal, async (contextId) => {
|
|
38
|
+
correlation.agentContextId = contextId;
|
|
39
|
+
dependencies.telemetry.annotate({ diagnostic_summary: { agentContextId: contextId } });
|
|
40
|
+
await observe?.({ contextId });
|
|
41
|
+
}, {
|
|
42
|
+
startedAt, ...(httpStatus === undefined ? {} : { httpStatus }),
|
|
43
|
+
onDiagnostics: diagnostic_summary => dependencies.telemetry.annotate({ diagnostic_summary })
|
|
44
|
+
});
|
|
44
45
|
});
|
|
45
46
|
const contextId = creativeContextId(streamed);
|
|
46
47
|
dependencies.telemetry.annotate({ diagnostic_summary: { agentContextId: contextId } });
|
|
@@ -12,7 +12,7 @@ export function loadBundledSkills(startFile) {
|
|
|
12
12
|
metadata = JSON.parse(readFileSync(packageFile, "utf8"));
|
|
13
13
|
}
|
|
14
14
|
catch (error) {
|
|
15
|
-
throw new SkillSyncError(`无法读取 @gaoding/cli package metadata: ${message(error)}`, []);
|
|
15
|
+
throw new SkillSyncError(`无法读取 @gaoding/cli package metadata: ${message(error)}`, [], { cause: error, phase: "load_package" });
|
|
16
16
|
}
|
|
17
17
|
const product = packageProduct(metadata.name);
|
|
18
18
|
if (product) {
|
|
@@ -20,8 +20,13 @@ export function loadBundledSkills(startFile) {
|
|
|
20
20
|
throw new SkillSyncError(`${product.packageName} package version is invalid.`, []);
|
|
21
21
|
}
|
|
22
22
|
const sourceDirectory = join(directory, "skills", product.skillName);
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
try {
|
|
24
|
+
if (!lstatSync(join(sourceDirectory, "SKILL.md")).isFile()) {
|
|
25
|
+
throw new Error("SKILL.md is not a file.");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (cause) {
|
|
29
|
+
throw new SkillSyncError(`Agent Skill source 不存在: ${sourceDirectory}`, [], { cause, phase: "load_package" });
|
|
25
30
|
}
|
|
26
31
|
return [{
|
|
27
32
|
skill: product.skillName,
|
|
@@ -46,18 +51,25 @@ function directoryFrom(path) {
|
|
|
46
51
|
try {
|
|
47
52
|
return lstatSync(absolute).isDirectory() ? absolute : dirname(absolute);
|
|
48
53
|
}
|
|
49
|
-
catch {
|
|
50
|
-
|
|
54
|
+
catch (cause) {
|
|
55
|
+
if (isAbsentPath(cause))
|
|
56
|
+
return dirname(absolute);
|
|
57
|
+
throw new SkillSyncError("Unable to inspect the CLI package entry.", [], { cause, phase: "load_package" });
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
function isFile(path) {
|
|
54
61
|
try {
|
|
55
62
|
return lstatSync(path).isFile();
|
|
56
63
|
}
|
|
57
|
-
catch {
|
|
58
|
-
|
|
64
|
+
catch (cause) {
|
|
65
|
+
if (isAbsentPath(cause))
|
|
66
|
+
return false;
|
|
67
|
+
throw new SkillSyncError("Unable to inspect CLI package metadata.", [], { cause, phase: "load_package" });
|
|
59
68
|
}
|
|
60
69
|
}
|
|
70
|
+
function isAbsentPath(error) {
|
|
71
|
+
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
72
|
+
}
|
|
61
73
|
function message(error) {
|
|
62
74
|
return error instanceof Error ? error.message : String(error);
|
|
63
75
|
}
|
|
@@ -4,10 +4,20 @@ import { homedir } from "node:os";
|
|
|
4
4
|
import { dirname, join, relative, resolve } from "node:path";
|
|
5
5
|
export class SkillSyncError extends Error {
|
|
6
6
|
results;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
diagnosticSummary;
|
|
8
|
+
constructor(message, results, options) {
|
|
9
|
+
super(message, options);
|
|
9
10
|
this.results = results;
|
|
10
11
|
this.name = "SkillSyncError";
|
|
12
|
+
this.diagnosticSummary = { localFileRole: "skill",
|
|
13
|
+
...(options?.phase ? { skillPhase: options.phase } : {}),
|
|
14
|
+
...(options?.host ? { skillTargetHost: options.host } : {}) };
|
|
15
|
+
for (let cause = options?.cause, depth = 0; cause instanceof Error && depth < 10; cause = cause.cause, depth++) {
|
|
16
|
+
if ("syscall" in cause && typeof cause.syscall === "string") {
|
|
17
|
+
this.diagnosticSummary.skillFileOperation = cause.syscall;
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
11
21
|
}
|
|
12
22
|
}
|
|
13
23
|
export async function syncBundledSkills(skills, options = {}) {
|
|
@@ -16,46 +26,58 @@ export async function syncBundledSkills(skills, options = {}) {
|
|
|
16
26
|
const results = [];
|
|
17
27
|
for (const skill of skills) {
|
|
18
28
|
assertDescriptor(skill, results);
|
|
19
|
-
|
|
29
|
+
let targets = [];
|
|
20
30
|
const targetResults = [];
|
|
31
|
+
let phase = "discover";
|
|
32
|
+
const failures = new Map();
|
|
21
33
|
try {
|
|
34
|
+
targets = await skillTargets(skill.skill, homeDirectory, options.env ?? {});
|
|
22
35
|
const canonical = targets[0];
|
|
36
|
+
phase = "inspect";
|
|
23
37
|
let current = await inspectTarget(canonical, skill, canonical.path, platform);
|
|
24
38
|
if (current.status === "conflict" || current.status === "broken") {
|
|
25
39
|
targetResults.push(current);
|
|
26
40
|
throw new Error(current.reason ?? "canonical Skill conflict");
|
|
27
41
|
}
|
|
28
42
|
if (current.status === "missing" || current.status === "outdated") {
|
|
43
|
+
phase = "install";
|
|
29
44
|
await replaceManagedDirectory(skill, canonical.path, current.status === "outdated");
|
|
30
45
|
current = installed(canonical, "canonical", true);
|
|
31
46
|
}
|
|
32
47
|
targetResults.push(current);
|
|
33
48
|
for (const target of targets.slice(1)) {
|
|
34
49
|
try {
|
|
50
|
+
phase = "inspect";
|
|
35
51
|
current = await inspectTarget(target, skill, canonical.path, platform);
|
|
36
52
|
if (current.status === "conflict" || current.status === "broken") {
|
|
37
53
|
targetResults.push(current);
|
|
38
54
|
continue;
|
|
39
55
|
}
|
|
40
56
|
if (current.status === "missing") {
|
|
57
|
+
phase = "install";
|
|
41
58
|
current = await createLinkOrCopy(skill, target, canonical.path, {
|
|
42
59
|
platform,
|
|
43
60
|
createLink: options.createLink ?? symlink
|
|
44
61
|
});
|
|
45
62
|
}
|
|
46
63
|
else if (current.status === "outdated") {
|
|
64
|
+
phase = "install";
|
|
47
65
|
await replaceManagedDirectory(skill, target.path, true);
|
|
48
66
|
current = installed(target, "copy", true);
|
|
49
67
|
}
|
|
50
68
|
targetResults.push(current);
|
|
51
69
|
}
|
|
52
70
|
catch (error) {
|
|
71
|
+
failures.set(target.host, { cause: error, phase });
|
|
53
72
|
targetResults.push({ host: target.host, path: target.path, status: "conflict", changed: false, reason: message(error) });
|
|
54
73
|
}
|
|
55
74
|
}
|
|
56
75
|
const conflict = targetResults.find(target => target.status === "conflict" || target.status === "broken");
|
|
57
|
-
if (conflict)
|
|
58
|
-
|
|
76
|
+
if (conflict) {
|
|
77
|
+
const failure = failures.get(conflict.host);
|
|
78
|
+
phase = failure?.phase ?? "inspect";
|
|
79
|
+
throw failure?.cause ?? new Error(conflict.reason ?? conflict.path);
|
|
80
|
+
}
|
|
59
81
|
results.push(syncResult(skill, targetResults));
|
|
60
82
|
}
|
|
61
83
|
catch (error) {
|
|
@@ -64,7 +86,7 @@ export async function syncBundledSkills(skills, options = {}) {
|
|
|
64
86
|
targetResults.push({ host: active.host, path: active.path, status: "conflict", changed: false, reason: message(error) });
|
|
65
87
|
}
|
|
66
88
|
results.push(syncResult(skill, targetResults));
|
|
67
|
-
throw new SkillSyncError(`Agent Skill ${skill.skill} 同步失败${active ? ` (${active.path})` : ""}: ${message(error)}`, results);
|
|
89
|
+
throw new SkillSyncError(`Agent Skill ${skill.skill} 同步失败${active ? ` (${active.path})` : ""}: ${message(error)}`, results, { cause: error, phase, ...(active ? { host: active.host } : {}) });
|
|
68
90
|
}
|
|
69
91
|
}
|
|
70
92
|
return results;
|
|
@@ -73,17 +95,27 @@ export async function verifyBundledSkills(skills, options = {}) {
|
|
|
73
95
|
const homeDirectory = options.homeDirectory ?? homedir();
|
|
74
96
|
const platform = options.platform ?? process.platform;
|
|
75
97
|
const results = [];
|
|
98
|
+
const failures = new Map();
|
|
76
99
|
for (const skill of skills) {
|
|
77
100
|
assertDescriptor(skill, results);
|
|
78
101
|
const targets = await skillTargets(skill.skill, homeDirectory, options.env ?? {});
|
|
79
102
|
const canonical = targets[0];
|
|
80
|
-
const inspected = await Promise.all(targets.map((target) =>
|
|
103
|
+
const inspected = await Promise.all(targets.map(async (target) => {
|
|
104
|
+
try {
|
|
105
|
+
return await inspectTarget(target, skill, canonical.path, platform);
|
|
106
|
+
}
|
|
107
|
+
catch (cause) {
|
|
108
|
+
const failed = targetResult(target, "conflict", undefined, message(cause));
|
|
109
|
+
failures.set(failed, cause);
|
|
110
|
+
return failed;
|
|
111
|
+
}
|
|
112
|
+
}));
|
|
81
113
|
results.push(syncResult(skill, inspected));
|
|
82
114
|
}
|
|
83
115
|
const invalid = results.flatMap((result) => result.targets)
|
|
84
116
|
.find((target) => target.status !== "installed");
|
|
85
117
|
if (invalid) {
|
|
86
|
-
throw new SkillSyncError(`Agent Skill 验收失败 (${invalid.path}): ${invalid.reason ?? invalid.status}`, results);
|
|
118
|
+
throw new SkillSyncError(`Agent Skill 验收失败 (${invalid.path}): ${invalid.reason ?? invalid.status}`, results, { cause: failures.get(invalid), phase: "verify", host: invalid.host });
|
|
87
119
|
}
|
|
88
120
|
return results;
|
|
89
121
|
}
|
|
@@ -125,13 +157,7 @@ async function inspectTarget(target, skill, canonical, platform) {
|
|
|
125
157
|
return targetResult(target, marker.legacy || marker.version !== skill.version ? "outdated" : "installed", "canonical");
|
|
126
158
|
}
|
|
127
159
|
if (stat.isSymbolicLink()) {
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
resolved = resolve(dirname(target.path), await readlink(target.path));
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
return targetResult(target, "conflict", linkMode(platform), message(error));
|
|
134
|
-
}
|
|
160
|
+
const resolved = resolve(dirname(target.path), await readlink(target.path));
|
|
135
161
|
if (!samePath(resolved, canonical, platform)) {
|
|
136
162
|
return targetResult(target, "conflict", linkMode(platform), "链接未指向 canonical Skill");
|
|
137
163
|
}
|
|
@@ -230,7 +230,7 @@ export function createSignedHttpTransport(options) {
|
|
|
230
230
|
async putJson(request) {
|
|
231
231
|
return json(await send("PUT", request, "application/json", JSON.stringify(request.body), true));
|
|
232
232
|
},
|
|
233
|
-
async postStream(request) {
|
|
233
|
+
async postStream(request, consume) {
|
|
234
234
|
const received = await send("POST", request, request.accept, JSON.stringify(request.body), false);
|
|
235
235
|
const { response } = received;
|
|
236
236
|
if (!response.ok) {
|
|
@@ -242,7 +242,15 @@ export function createSignedHttpTransport(options) {
|
|
|
242
242
|
}
|
|
243
243
|
if (!response.body)
|
|
244
244
|
throw new RemoteRequestError(response.status, false, {}, undefined, "RESPONSE_BODY_MISSING", received.diagnostics());
|
|
245
|
-
|
|
245
|
+
try {
|
|
246
|
+
return await consume(response.body);
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
// Keep Response reachable across consumer awaits: Undici otherwise may
|
|
250
|
+
// GC-cancel an unread body before its reader is acquired. Also close an
|
|
251
|
+
// unread body when the consumer exits early; cleanup cannot mask it or hang.
|
|
252
|
+
void response.body.cancel().catch(() => undefined);
|
|
253
|
+
}
|
|
246
254
|
}
|
|
247
255
|
};
|
|
248
256
|
}
|
|
@@ -22,7 +22,10 @@ const enums = Object.fromEntries(Object.entries({
|
|
|
22
22
|
lockWaitScope: ["same_process", "cross_process"], lockWaitPhase: ["local_queue", "owner_files"],
|
|
23
23
|
lockOwnerAction: ["task_write", "task_update", "sls_queue", "analytics_device"],
|
|
24
24
|
lockContenderAction: ["task_write", "task_update", "sls_queue", "analytics_device"],
|
|
25
|
-
localFileRole: ["credentials", "task", "sls_queue", "analytics_device"],
|
|
25
|
+
localFileRole: ["credentials", "task", "sls_queue", "analytics_device", "skill"],
|
|
26
|
+
skillPhase: ["discover", "inspect", "install", "verify", "load_package"],
|
|
27
|
+
skillTargetHost: ["canonical", "claude-code", "codex", "cursor", "opencode", "openclaw", "workbuddy"],
|
|
28
|
+
skillFileOperation: ["mkdir", "lstat", "stat", "readlink", "symlink", "open", "read", "write", "rename", "unlink", "rmdir", "scandir", "copyfile", "cp"],
|
|
26
29
|
workerPhase: ["spawn", "bootstrap", "before_started", "before_accepted", "ipc_send", "ipc_disconnect"],
|
|
27
30
|
quotaDecisionSource: ["cli_precheck"], quotaUnit: ["gaodou"], quotaLimitScope: ["account", "member_period"],
|
|
28
31
|
outputWritePhase: ["write_sync", "write_callback", "stream_error"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insmind/cli",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "insMind command-line interface for agents and people.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"@gaoding/cli": "workspace:*"
|
|
48
48
|
},
|
|
49
49
|
"gaodingRelease": {
|
|
50
|
-
"sourceCommit": "
|
|
51
|
-
"pipelineId": "
|
|
52
|
-
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/
|
|
50
|
+
"sourceCommit": "dd07bc1432494f88eaa2d3a0976e6415cda8bc1b",
|
|
51
|
+
"pipelineId": "259288",
|
|
52
|
+
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/259288"
|
|
53
53
|
}
|
|
54
54
|
}
|