@insmind/cli 2.1.2 → 2.1.4

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.
@@ -27,21 +27,22 @@ const messages = {
27
27
  request: ["本次请求未能完成。", "This request could not be completed."],
28
28
  client: ["程序运行遇到问题,本次操作未能完成。", "The app encountered a problem and could not complete this operation."]
29
29
  };
30
- const reviewCodes = new Set(["12020751", "12020752", "12020757", "12020758", "12020760", "12020790"]);
30
+ const reviewCodes = new Set(["12020751", "12020752", "12020756", "12020757", "12020758", "12020760", "12020790"]);
31
31
  export function observedErrorCategory(e) {
32
32
  const gd = e.product === "gaoding", ins = e.product === "insmind";
33
33
  const toolOrQuery = e.operation === "tool.call" || e.operation === "task.get";
34
34
  if (e.code === "INSUFFICIENT_CREDITS" || gd && e.operation === "tool.call" && e.remoteCode === "12020770")
35
35
  return "credits";
36
36
  if (e.errorType === "AgentAuditRejectedError" || e.diagnosticReason === "AGENT_INPUT_AUDIT_REJECTED"
37
- || gd && (toolOrQuery && reviewCodes.has(e.remoteCode ?? "") || e.operation === "agent.send" && e.remoteCode === "-1006")
38
- || ins && toolOrQuery && e.remoteCode === "12020760")
37
+ || e.diagnosticReason !== "TASK_QUERY_FAILED" && (gd && (toolOrQuery && reviewCodes.has(e.remoteCode ?? "") || e.operation === "agent.send" && e.remoteCode === "-1006")
38
+ || ins && toolOrQuery && e.remoteCode === "12020760"))
39
39
  return "review";
40
40
  if (gd && e.operation === "agent.send" && e.httpStatus === 409)
41
41
  return "session_busy";
42
42
  if (gd && e.operation === "agent.send" && e.httpStatus === 429)
43
43
  return "service_busy";
44
44
  if (gd && e.operation === "auth.login" && e.httpStatus === 504 || e.code === "EDITOR_RPC_TIMEOUT"
45
+ || gd && toolOrQuery && e.remoteCode === "12020792"
45
46
  || (gd || ins) && e.operation === "tool.call" && e.remoteCode === "-31994" && e.diagnosticReason === "IMAGE_AUDIT_TIMEOUT")
46
47
  return "timeout";
47
48
  if (ins && e.operation === "tool.call" && e.remoteCode === "-31993")
@@ -106,6 +107,9 @@ export function observedErrorMessage(category, e) {
106
107
  return text("已收到本页流水,但服务未返回可用的下一页游标。请查看 details.partial_result,本次无法续页。", "This page was received without a usable cursor. Its records are in details.partial_result; the next page cannot be requested.");
107
108
  if (category === "timeout" && e.diagnosticReason === "IMAGE_AUDIT_TIMEOUT")
108
109
  return text("图片审核处理超时,尚未取得结果。", "The image check did not finish in time.");
110
+ if (category === "timeout" && e.product === "gaoding" && (e.operation === "tool.call" || e.operation === "task.get")
111
+ && e.remoteCode === "12020792")
112
+ return "内容审核处理超时,尚未取得结果。";
109
113
  if (category === "login" && e.errorType === "DeviceAuthorizationExpiredError")
110
114
  return text("本次登录已超时,请重新登录。", "This sign-in timed out. Please sign in again.");
111
115
  if (category === "account" && e.code === "ORG_INVALID")
@@ -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
- if (!isFile(join(sourceDirectory, "SKILL.md"))) {
24
- throw new SkillSyncError(`Agent Skill source 不存在: ${sourceDirectory}`, []);
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
- return dirname(absolute);
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
- return false;
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
- constructor(message, results) {
8
- super(message);
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
- const targets = await skillTargets(skill.skill, homeDirectory, options.env ?? {});
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
- throw new Error(conflict.reason ?? conflict.path);
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) => inspectTarget(target, skill, canonical.path, platform)));
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
- let resolved;
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
  }
@@ -3,12 +3,14 @@ import { ToolTaskFailedError } from "../tool/tool-api-adapter.js";
3
3
  import { RemoteRequestError } from "../../platform/signed-http-transport.js";
4
4
  import { RemoteProtocolError } from "../../platform/remote-protocol.js";
5
5
  // Scope numeric codes to the product/entry where they have a confirmed meaning.
6
- const CONTENT_REVIEW_CODES = new Set(["12020751", "12020752", "12020757", "12020758", "12020760", "12020790"]);
6
+ const CONTENT_REVIEW_CODES = new Set(["12020751", "12020752", "12020756", "12020757", "12020758", "12020760", "12020790"]);
7
7
  export function isContentReviewRejection(error, context = {}) {
8
8
  if (error instanceof AgentAuditRejectedError)
9
9
  return true;
10
10
  if (!(error instanceof RemoteRequestError || error instanceof RemoteProtocolError || error instanceof ToolTaskFailedError))
11
11
  return false;
12
+ if (error.diagnosticReason === "TASK_QUERY_FAILED")
13
+ return false;
12
14
  if (error.diagnosticReason === "AGENT_INPUT_AUDIT_REJECTED")
13
15
  return true;
14
16
  const toolOrQuery = context.operation === "tool.call" || context.operation === "task.get";
@@ -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"],
@@ -129,7 +129,9 @@ export function createSlsTelemetrySink(options) {
129
129
  // All writers hold the same lock, so remaining write temporaries are orphaned.
130
130
  if (/^(?:[a-f0-9]{64}|delivery-status)\.json\.tmp-[a-f0-9-]+$/u.test(name)) {
131
131
  await unlink(join(directory, name)).catch(() => undefined);
132
- await dropped("interrupted_write", 1);
132
+ // The health snapshot is not an event; its interrupted write loses no queued event.
133
+ if (!name.startsWith("delivery-status.json.tmp-"))
134
+ await dropped("interrupted_write", 1);
133
135
  }
134
136
  return;
135
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insmind/cli",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
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": "db01676824330fe8f15c190fe71b3516b8b1924e",
51
- "pipelineId": "246753",
52
- "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/246753"
50
+ "sourceCommit": "9d9d3d0eae22cb0d07d2cf07f455f162938f65f4",
51
+ "pipelineId": "257445",
52
+ "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/257445"
53
53
  }
54
54
  }