@a2f0/agent-tool 0.1.60 → 0.1.61

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": "@a2f0/agent-tool",
3
- "version": "0.1.60",
3
+ "version": "0.1.61",
4
4
  "packageManager": "bun@1.4.4",
5
5
  "type": "module",
6
6
  "description": "Portable cross-agent review, PR workflows, and shared skills",
@@ -8,6 +8,22 @@ export const FORWARDED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"] as const;
8
8
 
9
9
  export interface RunReceipt { status: string; label?: string; exitCode: number; signal: string | null; durationMs: number; outputBytes: number; log: string; leftoverProcessGroup?: number }
10
10
 
11
+ /**
12
+ * Whether a process group still has members. macOS answers EPERM, not ESRCH,
13
+ * for a group whose only members are zombies awaiting their reaper, such as a
14
+ * descendant that exited after its parent and before launchd reaped it, and
15
+ * for a group holding only processes this user cannot signal. Both still exist.
16
+ */
17
+ export function processGroupExists(group: number): boolean {
18
+ try { process.kill(-group, 0); return true; }
19
+ catch (error) {
20
+ const code = (error as NodeJS.ErrnoException).code;
21
+ if (code === "ESRCH") return false;
22
+ if (code === "EPERM") return true;
23
+ throw error;
24
+ }
25
+ }
26
+
11
27
  /**
12
28
  * Run directly into a private file: child output never accumulates in memory.
13
29
  * A caller that must record the interruption before exiting passes
@@ -46,7 +62,10 @@ export async function runCommand(args: string[], record?: (receipt: RunReceipt)
46
62
  if (grouped) process.kill(-child.pid, value);
47
63
  else child.kill(value);
48
64
  } catch (error) {
49
- if ((error as NodeJS.ErrnoException).code !== "ESRCH") throw error;
65
+ // ESRCH: the group is gone. EPERM: no member could be signalled, as in
66
+ // a group of zombies on macOS; there is nothing left to stop.
67
+ const code = (error as NodeJS.ErrnoException).code;
68
+ if (code !== "ESRCH" && code !== "EPERM") throw error;
50
69
  }
51
70
  };
52
71
  for (const value of FORWARDED_SIGNALS) {
@@ -72,12 +91,7 @@ export async function runCommand(args: string[], record?: (receipt: RunReceipt)
72
91
  if (interrupted) {
73
92
  // The direct child can exit before its descendants finish cleanup. Keep
74
93
  // the original grace period for the remaining process group as well.
75
- while (grouped && child.pid && performance.now() < cancelDeadline) {
76
- try { process.kill(-child.pid, 0); }
77
- catch (error) {
78
- if ((error as NodeJS.ErrnoException).code === "ESRCH") break;
79
- throw error;
80
- }
94
+ while (grouped && child.pid && performance.now() < cancelDeadline && processGroupExists(child.pid)) {
81
95
  await new Promise(resolve => setTimeout(resolve, 25));
82
96
  }
83
97
  forward("SIGKILL");