@zhushanwen/pi-cw-tool 0.5.3 → 0.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-cw-tool",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Pi extension for cw 2.0: a read-only cw_query tool (status / frontier / tree / report passthrough) + the pi-cw skill (runner practical guide for multi-unit tasks: background run, monitoring, escalation, merge back).",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -41,6 +41,9 @@
41
41
  "optional": true
42
42
  }
43
43
  },
44
+ "dependencies": {
45
+ "@zhushanwen/pi-ext-guards": "0.4.0"
46
+ },
44
47
  "devDependencies": {
45
48
  "@vitest/coverage-v8": "^4.1.9",
46
49
  "vitest": "^4.1.8"
package/src/cw-runner.ts CHANGED
@@ -14,6 +14,8 @@
14
14
  * 与 Pi SDK 解耦(不 import pi 类型),纯逻辑 + 可注入 spawner,便于单测。
15
15
  * 所有错误路径返回 `{ ok: false, error }`,不抛异常(由调用方映射为 tool 返回)。
16
16
  */
17
+ import { toErrorMessage } from "@zhushanwen/pi-ext-guards";
18
+
17
19
  import type { CwSpawner } from "./cw-spawn.ts";
18
20
 
19
21
  /**
@@ -187,7 +189,7 @@ export async function executeCwAction(
187
189
  try {
188
190
  result = await spawner(args, undefined, cwd, combined.signal);
189
191
  } catch (err) {
190
- const msg = err instanceof Error ? err.message : String(err);
192
+ const msg = toErrorMessage(err);
191
193
  return { ok: false, ...base, error: `cw spawn 失败: ${msg}` };
192
194
  } finally {
193
195
  if (timer) clearTimeout(timer);
package/src/cw-spawn.ts CHANGED
@@ -15,6 +15,8 @@
15
15
  import { existsSync } from "node:fs";
16
16
  import { spawn } from "node:child_process";
17
17
 
18
+ import { isEnoentError } from "@zhushanwen/pi-ext-guards";
19
+
18
20
  /**
19
21
  * cwd 不存在时的可操作错误文案(错误 → 权威源 worktrees.json → 重试闭环)。
20
22
  * @param cwd 不存在的路径
@@ -122,8 +124,8 @@ export const defaultCwSpawner: CwSpawner = (args, input, cwd, signal) =>
122
124
  // [worktree-reaper-fix] 拼 cwd 进错误消息:ENOENT 的 err.message 只有 command 名,
123
125
  // 无 cwd 线索会导致误诊(2026-08-11 事故 AI 误判"node 被卸载")。
124
126
  // exitCode=-1 区分于正常退出码。
125
- const errCwd = err.code === "ENOENT" ? `\ncwd: ${cwd}` : "";
126
- const hint = err.code === "ENOENT" && !existsSync(cwd) ? `\n${cwdMissingError(cwd)}` : "";
127
+ const errCwd = isEnoentError(err) ? `\ncwd: ${cwd}` : "";
128
+ const hint = isEnoentError(err) && !existsSync(cwd) ? `\n${cwdMissingError(cwd)}` : "";
127
129
  finish({ stdout, stderr: `${stderr}\n[spawn error] ${err.message}${errCwd}${hint}`, exitCode: -1 });
128
130
  });
129
131
  child.on("close", (code: number | null) => {