@tekyzinc/gsd-t 3.10.13 → 3.10.15
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/CHANGELOG.md +32 -0
- package/bin/gsd-t-unattended-platform.cjs +381 -0
- package/bin/gsd-t-unattended-safety.cjs +766 -0
- package/bin/gsd-t-unattended.cjs +1259 -0
- package/bin/gsd-t.js +7 -1
- package/bin/handoff-lock.cjs +249 -0
- package/bin/headless-auto-spawn.cjs +328 -0
- package/bin/runway-estimator.cjs +242 -0
- package/bin/token-optimizer.cjs +471 -0
- package/bin/token-telemetry.cjs +246 -0
- package/commands/gsd-t-backlog-list.md +2 -2
- package/commands/gsd-t-complete-milestone.md +1 -1
- package/commands/gsd-t-debug.md +5 -5
- package/commands/gsd-t-doc-ripple.md +1 -1
- package/commands/gsd-t-execute.md +3 -3
- package/commands/gsd-t-integrate.md +3 -3
- package/commands/gsd-t-optimization-apply.md +3 -3
- package/commands/gsd-t-optimization-reject.md +3 -3
- package/commands/gsd-t-quick.md +3 -3
- package/commands/gsd-t-resume.md +1 -1
- package/commands/gsd-t-status.md +1 -1
- package/commands/gsd-t-unattended.md +2 -2
- package/commands/gsd-t-wave.md +3 -3
- package/package.json +1 -1
- package/scripts/context-meter/transcript-parser.js +63 -1
- package/scripts/context-meter/transcript-parser.test.js +53 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to GSD-T are documented here. Updated with each release.
|
|
4
4
|
|
|
5
|
+
## [3.10.15] - 2026-04-15
|
|
6
|
+
|
|
7
|
+
### Fixed — bin tools not propagated to downstream projects (unattended launch fails)
|
|
8
|
+
|
|
9
|
+
**Background**: The unattended supervisor (`/gsd-t-unattended`) and several other commands reference bin files via `require('./bin/<tool>.js')` resolved against the project cwd. These files only existed in the GSD-T source repo — downstream projects that use GSD-T as tooling (installed via npm) never received them because `PROJECT_BIN_TOOLS` only listed 5 of the 13 needed files. Additionally, `.js` files fail in downstream projects with `"type": "module"` in their `package.json`.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
- **`bin/gsd-t.js`** `PROJECT_BIN_TOOLS` — expanded from 5 to 13 entries. Now includes: `gsd-t-unattended.cjs`, `gsd-t-unattended-platform.cjs`, `gsd-t-unattended-safety.cjs`, `handoff-lock.cjs`, `headless-auto-spawn.cjs`, `runway-estimator.cjs`, `token-telemetry.cjs`, `token-optimizer.cjs` (plus existing 5).
|
|
13
|
+
- **8 new `.cjs` files** created in `bin/` — copies of existing `.js` files with internal cross-requires updated to `.cjs` (e.g., `gsd-t-unattended.cjs` requires `./gsd-t-unattended-safety.cjs` instead of `.js`).
|
|
14
|
+
- **15 command files updated** — all `require('./bin/<tool>.js')` calls switched to `.cjs` for the 8 newly-propagated tools: `gsd-t-execute`, `gsd-t-wave`, `gsd-t-quick`, `gsd-t-integrate`, `gsd-t-debug`, `gsd-t-doc-ripple`, `gsd-t-unattended`, `gsd-t-resume`, `gsd-t-status`, `gsd-t-complete-milestone`, `gsd-t-optimization-apply`, `gsd-t-optimization-reject`, `gsd-t-backlog-list`.
|
|
15
|
+
- 1229/1229 tests pass.
|
|
16
|
+
|
|
17
|
+
### Impact
|
|
18
|
+
- `/gsd-t-unattended` can now launch from any downstream project (Tekyz-CRM, etc.)
|
|
19
|
+
- Runway estimator, headless auto-spawn, and token telemetry brackets work in downstream projects
|
|
20
|
+
- Token optimizer hooks in complete-milestone and backlog-list work in downstream projects
|
|
21
|
+
|
|
22
|
+
## [3.10.14] - 2026-04-15
|
|
23
|
+
|
|
24
|
+
### Fixed — transcript parser orphaned tool_use blocks cause count_tokens 400
|
|
25
|
+
|
|
26
|
+
**Background**: With `ANTHROPIC_API_KEY` now set (v3.10.12-13 fix), the context meter hook passed the key check but the `count_tokens` API returned HTTP 400: `"tool_use ids were found without tool_result blocks immediately after"`. The transcript parser (`scripts/context-meter/transcript-parser.js`) faithfully reconstructed the JSONL transcript but didn't enforce the API's strict adjacency constraint: every assistant `tool_use` must be immediately followed by a user `tool_result` with matching ids. Mid-session compaction and summarization can orphan these blocks.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
- **`scripts/context-meter/transcript-parser.js`** — added `sanitizeToolPairs()` post-processing pass after message reconstruction. Walks the message list enforcing adjacency: assistant `tool_use` blocks are kept only if the immediately following user message contains a `tool_result` with a matching id, and vice versa. Messages that become empty after stripping are dropped. This is a structural fix — any transcript shape (compacted, summarized, interrupted) now produces a valid `count_tokens` payload.
|
|
30
|
+
- **`scripts/context-meter/transcript-parser.test.js`** — updated 2 existing tests that created orphaned `tool_result` messages (now include matching `tool_use` predecessors). Added 1 new test: `orphaned tool_use without matching tool_result is stripped`. 1229/1229 tests pass.
|
|
31
|
+
|
|
32
|
+
### Verification
|
|
33
|
+
- Real transcript (626→649 messages, 473KB payload) now returns HTTP 200 with `input_tokens: 153597` (was 400 before fix)
|
|
34
|
+
- Context meter state file flipped from `lastError: api_error` to `lastError: null`, `inputTokens: 158543`, `pct: 79.3%`, `threshold: warn`
|
|
35
|
+
- First successful real-time context measurement since M34 was built
|
|
36
|
+
|
|
5
37
|
## [3.10.13] - 2026-04-15
|
|
6
38
|
|
|
7
39
|
### Fixed — P0 v3.10.12 propagation gap (same regression, downstream projects)
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gsd-t-unattended-platform.js
|
|
3
|
+
*
|
|
4
|
+
* Cross-platform helpers for the unattended supervisor (M36).
|
|
5
|
+
*
|
|
6
|
+
* This module is the SINGLE place where `process.platform` branches live.
|
|
7
|
+
* Supervisor-core, watch-loop, and safety-rails import from here so that
|
|
8
|
+
* the rest of the supervisor can stay platform-agnostic.
|
|
9
|
+
*
|
|
10
|
+
* Contract: .gsd-t/contracts/unattended-supervisor-contract.md v1.0.0
|
|
11
|
+
* §5 Exit Code Table (timeout = 3, OS process-timeout = 124)
|
|
12
|
+
* §7 Launch Handshake (spawn semantics)
|
|
13
|
+
*
|
|
14
|
+
* Task 1 of m36-cross-platform delivers:
|
|
15
|
+
* - resolveClaudePath()
|
|
16
|
+
* - isAlive(pid)
|
|
17
|
+
* - spawnWorker(projectDir, timeoutMs)
|
|
18
|
+
*
|
|
19
|
+
* Cross-platform notes:
|
|
20
|
+
* - darwin / linux paths are runtime-tested.
|
|
21
|
+
* - win32 paths are implementation-complete but NOT runtime-tested on the
|
|
22
|
+
* dev host (macOS). Spike C and the full Windows caveats matrix ship in
|
|
23
|
+
* Task 3 (`docs/unattended-windows-caveats.md`).
|
|
24
|
+
*
|
|
25
|
+
* Zero external dependencies — Node built-ins only.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
"use strict";
|
|
29
|
+
|
|
30
|
+
const { spawnSync, spawn } = require("node:child_process");
|
|
31
|
+
|
|
32
|
+
// ─── resolveClaudePath ───────────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Resolve the executable name for the `claude` CLI on the current platform.
|
|
36
|
+
*
|
|
37
|
+
* Returns `'claude.cmd'` on win32 and `'claude'` everywhere else.
|
|
38
|
+
*
|
|
39
|
+
* This is intentionally a simple platform branch — it does NOT shell out to
|
|
40
|
+
* `which` / `where`. The resolver assumes `claude` is on PATH; PATH lookup is
|
|
41
|
+
* delegated to `spawnSync`, which is cross-platform and quoting-safe.
|
|
42
|
+
*
|
|
43
|
+
* Cross-platform:
|
|
44
|
+
* - darwin / linux: returns `'claude'`. The macOS / Linux installer puts
|
|
45
|
+
* `claude` on PATH via `/usr/local/bin` or `/opt/homebrew/bin`.
|
|
46
|
+
* - win32: returns `'claude.cmd'`. The Anthropic Windows installer ships a
|
|
47
|
+
* `.cmd` shim. Using the `.cmd` filename explicitly (instead of bare
|
|
48
|
+
* `claude`) avoids `spawnSync` falling through to `cmd.exe /c claude`,
|
|
49
|
+
* which would re-introduce the Spike C PowerShell quoting hazard.
|
|
50
|
+
*
|
|
51
|
+
* @returns {string} `'claude'` or `'claude.cmd'`
|
|
52
|
+
*/
|
|
53
|
+
function resolveClaudePath() {
|
|
54
|
+
return process.platform === "win32" ? "claude.cmd" : "claude";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ─── isAlive ─────────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Cross-platform liveness check for a PID.
|
|
61
|
+
*
|
|
62
|
+
* Uses the POSIX trick `kill(pid, 0)` — sends signal 0, which performs all
|
|
63
|
+
* permission and existence checks but delivers no signal. Node's
|
|
64
|
+
* `process.kill` implements the same semantics on Windows.
|
|
65
|
+
*
|
|
66
|
+
* Errors:
|
|
67
|
+
* - `ESRCH` → no such process. Returns `false`.
|
|
68
|
+
* - `EPERM` → process exists but we don't own it. Returns `true` (we got
|
|
69
|
+
* permission feedback, which proves the PID is live).
|
|
70
|
+
* - other → unexpected; rethrown.
|
|
71
|
+
*
|
|
72
|
+
* @param {number} pid
|
|
73
|
+
* @returns {boolean}
|
|
74
|
+
*/
|
|
75
|
+
function isAlive(pid) {
|
|
76
|
+
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
process.kill(pid, 0);
|
|
81
|
+
return true;
|
|
82
|
+
} catch (err) {
|
|
83
|
+
if (err && err.code === "ESRCH") return false;
|
|
84
|
+
if (err && err.code === "EPERM") return true; // exists, not ours
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ─── spawnWorker ─────────────────────────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Spawn a synchronous `claude -p '/gsd-t-resume'` worker iteration for the
|
|
93
|
+
* unattended supervisor.
|
|
94
|
+
*
|
|
95
|
+
* Returns a normalized result object: `{ status, stdout, stderr, signal,
|
|
96
|
+
* timedOut, error }`. Never throws — spawn errors are returned in `error`.
|
|
97
|
+
*
|
|
98
|
+
* Timeout semantics: when `spawnSync`'s `timeout` fires, the child is sent
|
|
99
|
+
* SIGTERM (or the equivalent on win32), `status` is `null`, and `signal` is
|
|
100
|
+
* non-null. We surface this as `timedOut: true` so callers can map to exit
|
|
101
|
+
* code 3 per contract §5.
|
|
102
|
+
*
|
|
103
|
+
* Spawn recipe (uniform across platforms):
|
|
104
|
+
* - `shell: false` → no shell quoting hazards
|
|
105
|
+
* - `windowsHide: true` → no flashed window on win32
|
|
106
|
+
* - explicit `claude.cmd` filename on win32 (see resolveClaudePath JSDoc)
|
|
107
|
+
*
|
|
108
|
+
* @todo Spike C: verify `claude.cmd -p "/gsd-t-resume"` dispatches correctly
|
|
109
|
+
* under PowerShell + cmd.exe + Git Bash. See
|
|
110
|
+
* `docs/unattended-windows-caveats.md` (Task 3 of m36-cross-platform).
|
|
111
|
+
*
|
|
112
|
+
* @param {string} projectDir Absolute path to the project directory (cwd).
|
|
113
|
+
* @param {number} timeoutMs Wall-clock cap per worker iteration in ms.
|
|
114
|
+
* @param {object} [opts] Optional overrides (test-mode hooks).
|
|
115
|
+
* @param {string} [opts.bin] Override the resolved binary (test-mode only).
|
|
116
|
+
* @param {string[]} [opts.args] Override args (defaults to `['-p', '/gsd-t-resume']`).
|
|
117
|
+
* @param {object} [opts.env] Override env (defaults to `process.env`).
|
|
118
|
+
* @returns {{
|
|
119
|
+
* status: number|null,
|
|
120
|
+
* stdout: string,
|
|
121
|
+
* stderr: string,
|
|
122
|
+
* signal: string|null,
|
|
123
|
+
* timedOut: boolean,
|
|
124
|
+
* error: Error|null
|
|
125
|
+
* }}
|
|
126
|
+
*/
|
|
127
|
+
function spawnWorker(projectDir, timeoutMs, opts = {}) {
|
|
128
|
+
const bin = opts.bin || resolveClaudePath();
|
|
129
|
+
const args = opts.args || ["-p", "/gsd-t-resume"];
|
|
130
|
+
const env = opts.env || process.env;
|
|
131
|
+
|
|
132
|
+
const result = spawnSync(bin, args, {
|
|
133
|
+
cwd: projectDir,
|
|
134
|
+
encoding: "utf8",
|
|
135
|
+
timeout: timeoutMs,
|
|
136
|
+
env,
|
|
137
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
138
|
+
shell: false,
|
|
139
|
+
windowsHide: true,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Normalize. spawnSync may return error if the binary cannot be launched
|
|
143
|
+
// (ENOENT etc.) — surface it instead of throwing.
|
|
144
|
+
const stdout = typeof result.stdout === "string" ? result.stdout : "";
|
|
145
|
+
const stderr = typeof result.stderr === "string" ? result.stderr : "";
|
|
146
|
+
const signal = result.signal || null;
|
|
147
|
+
const status = typeof result.status === "number" ? result.status : null;
|
|
148
|
+
|
|
149
|
+
// Timeout detection: when spawnSync's `timeout` option fires it sets
|
|
150
|
+
// - status === null
|
|
151
|
+
// - signal !== null (SIGTERM on POSIX, equivalent on win32)
|
|
152
|
+
// - error.code === 'ETIMEDOUT' (Node surfaces it as a synthetic Error)
|
|
153
|
+
// The ETIMEDOUT code is the authoritative signal — checking it
|
|
154
|
+
// discriminates a genuine timeout from an ENOENT/spawn failure.
|
|
155
|
+
const errCode = result.error && result.error.code;
|
|
156
|
+
const timedOut =
|
|
157
|
+
errCode === "ETIMEDOUT" || (status === null && signal !== null && !result.error);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
status,
|
|
161
|
+
stdout,
|
|
162
|
+
stderr,
|
|
163
|
+
signal,
|
|
164
|
+
timedOut,
|
|
165
|
+
// Suppress the synthetic ETIMEDOUT error so callers can rely on
|
|
166
|
+
// `timedOut` for the timeout case and `error` for genuine spawn failures.
|
|
167
|
+
error: errCode === "ETIMEDOUT" ? null : result.error || null,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ─── spawnSupervisor ─────────────────────────────────────────────────────────
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Spawn a detached unattended supervisor process.
|
|
175
|
+
*
|
|
176
|
+
* Implements the Launch Handshake from contract §7: the interactive launch
|
|
177
|
+
* command forks a long-lived supervisor that outlives the parent, reads the
|
|
178
|
+
* state file, and relays `claude -p` workers until the milestone terminates.
|
|
179
|
+
*
|
|
180
|
+
* Spawn recipe:
|
|
181
|
+
* - `node {binPath} unattended {...args}` — the `unattended` subcommand is
|
|
182
|
+
* prepended automatically so callers pass only user-facing args.
|
|
183
|
+
* - `detached: true` — the child becomes a process-group leader on POSIX
|
|
184
|
+
* (darwin/linux) so it survives the parent closing its terminal. On win32
|
|
185
|
+
* the equivalent flag produces a separate process tree.
|
|
186
|
+
* - `stdio: 'ignore'` — no pipes held open that would block the parent
|
|
187
|
+
* from exiting.
|
|
188
|
+
* - `windowsHide: true` (win32 only) — no flashed console window.
|
|
189
|
+
* - `child.unref()` — the parent event loop will not wait on the child.
|
|
190
|
+
*
|
|
191
|
+
* Cross-platform notes:
|
|
192
|
+
* - darwin / linux: runtime-tested.
|
|
193
|
+
* - win32: implementation-complete; documented in
|
|
194
|
+
* `docs/unattended-windows-caveats.md` (Task 3).
|
|
195
|
+
*
|
|
196
|
+
* @param {object} params
|
|
197
|
+
* @param {string} params.binPath Absolute path to `bin/gsd-t.js`.
|
|
198
|
+
* @param {string[]} params.args Extra args appended after `unattended`.
|
|
199
|
+
* @param {string} params.cwd Project directory (supervisor's cwd).
|
|
200
|
+
* @returns {{ pid: number }} The detached child's PID.
|
|
201
|
+
*/
|
|
202
|
+
function spawnSupervisor({ binPath, args, cwd }) {
|
|
203
|
+
const spawnArgs = [binPath, "unattended", ...(args || [])];
|
|
204
|
+
const opts = {
|
|
205
|
+
cwd,
|
|
206
|
+
detached: true,
|
|
207
|
+
stdio: "ignore",
|
|
208
|
+
};
|
|
209
|
+
if (process.platform === "win32") {
|
|
210
|
+
opts.windowsHide = true;
|
|
211
|
+
}
|
|
212
|
+
const child = spawn("node", spawnArgs, opts);
|
|
213
|
+
child.unref();
|
|
214
|
+
return { pid: child.pid };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// ─── preventSleep ────────────────────────────────────────────────────────────
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Prevent the OS from going to sleep while the supervisor is running.
|
|
221
|
+
*
|
|
222
|
+
* Returns a handle that must be passed to `releaseSleep` when the supervisor
|
|
223
|
+
* terminates.
|
|
224
|
+
*
|
|
225
|
+
* Cross-platform:
|
|
226
|
+
* - darwin: `caffeinate -i -w <supervisor-pid>` — the `-w` flag ties the
|
|
227
|
+
* caffeinate lifetime to the supervisor's PID. Even if the supervisor
|
|
228
|
+
* forgets to call `releaseSleep`, caffeinate will self-exit when the
|
|
229
|
+
* supervisor dies. Returns the caffeinate child PID as the handle.
|
|
230
|
+
* - linux: returns `null`. Reliable sleep prevention requires
|
|
231
|
+
* `systemd-inhibit`, which only works under a user session bus and is
|
|
232
|
+
* not universally available. v1 documents the gap; v2 may add opt-in
|
|
233
|
+
* systemd-inhibit. Prints a one-line notice to stderr.
|
|
234
|
+
* - win32: returns `null`. `SetThreadExecutionState` is the native API but
|
|
235
|
+
* requires a C binding. v1 documents the gap; see
|
|
236
|
+
* `docs/unattended-windows-caveats.md` (Task 3).
|
|
237
|
+
*
|
|
238
|
+
* @param {string} [reason] Informational label (reserved; not currently used
|
|
239
|
+
* — darwin's caffeinate has no reason field, and
|
|
240
|
+
* linux/win32 don't have sleep prevention yet).
|
|
241
|
+
* @returns {number|null} PID handle on darwin, `null` elsewhere.
|
|
242
|
+
*/
|
|
243
|
+
function preventSleep(reason) {
|
|
244
|
+
void reason; // reserved for future implementations
|
|
245
|
+
if (process.platform === "darwin") {
|
|
246
|
+
try {
|
|
247
|
+
const child = spawn("caffeinate", ["-i", "-w", String(process.pid)], {
|
|
248
|
+
detached: true,
|
|
249
|
+
stdio: "ignore",
|
|
250
|
+
});
|
|
251
|
+
child.unref();
|
|
252
|
+
return typeof child.pid === "number" ? child.pid : null;
|
|
253
|
+
} catch (err) {
|
|
254
|
+
process.stderr.write(
|
|
255
|
+
`[platform] caffeinate failed to spawn: ${err && err.message}\n`,
|
|
256
|
+
);
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (process.platform === "linux") {
|
|
261
|
+
process.stderr.write(
|
|
262
|
+
"[platform] sleep prevention not implemented on linux\n",
|
|
263
|
+
);
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
process.stderr.write(
|
|
267
|
+
"[platform] sleep prevention not implemented on win32 (see docs/unattended-windows-caveats.md)\n",
|
|
268
|
+
);
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ─── releaseSleep ────────────────────────────────────────────────────────────
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Release a sleep-prevention handle obtained from `preventSleep`.
|
|
276
|
+
*
|
|
277
|
+
* Idempotent and tolerant:
|
|
278
|
+
* - `null` / non-number handle → no-op.
|
|
279
|
+
* - handle is a dead PID → no-op (ESRCH is swallowed).
|
|
280
|
+
* - handle is a live PID → `SIGTERM` is delivered (EPERM and other unusual
|
|
281
|
+
* errors are swallowed — caller cannot reasonably act on them).
|
|
282
|
+
*
|
|
283
|
+
* @param {number|null} handle
|
|
284
|
+
* @returns {void}
|
|
285
|
+
*/
|
|
286
|
+
function releaseSleep(handle) {
|
|
287
|
+
if (handle == null) return;
|
|
288
|
+
if (typeof handle !== "number" || !Number.isInteger(handle) || handle <= 0) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (!isAlive(handle)) return;
|
|
292
|
+
try {
|
|
293
|
+
process.kill(handle, "SIGTERM");
|
|
294
|
+
} catch (_err) {
|
|
295
|
+
// Swallow — releaseSleep must never throw. A dead/gone process is fine;
|
|
296
|
+
// an EPERM on an adopted PID is also fine (not ours to reap).
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// ─── notify ──────────────────────────────────────────────────────────────────
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Emit an OS-level desktop notification. Fire-and-forget — never throws.
|
|
304
|
+
*
|
|
305
|
+
* Cross-platform:
|
|
306
|
+
* - darwin: `osascript -e 'display notification "msg" with title "title"'`.
|
|
307
|
+
* - linux: `notify-send "title" "message"` (requires libnotify).
|
|
308
|
+
* - win32: `msg.exe * "title: message"` (console msg; ships with Windows).
|
|
309
|
+
*
|
|
310
|
+
* All platform helpers are fire-and-forget `spawn` calls. Errors are caught
|
|
311
|
+
* and logged to stderr so a missing binary (e.g., no libnotify installed on a
|
|
312
|
+
* headless Linux box) does NOT break the supervisor.
|
|
313
|
+
*
|
|
314
|
+
* @param {string} title
|
|
315
|
+
* @param {string} message
|
|
316
|
+
* @param {string} [level] `info` | `warn` | `done` | `failed` — accepted but
|
|
317
|
+
* currently unused. Reserved for future formatting.
|
|
318
|
+
* @returns {void}
|
|
319
|
+
*/
|
|
320
|
+
function notify(title, message, level) {
|
|
321
|
+
void level; // reserved for future formatting
|
|
322
|
+
const safeTitle = String(title || "");
|
|
323
|
+
const safeMessage = String(message || "");
|
|
324
|
+
try {
|
|
325
|
+
if (process.platform === "darwin") {
|
|
326
|
+
// Escape double-quotes and backslashes for the AppleScript string
|
|
327
|
+
// literal. osascript uses double-quoted string syntax.
|
|
328
|
+
const esc = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
329
|
+
const script =
|
|
330
|
+
`display notification "${esc(safeMessage)}" ` +
|
|
331
|
+
`with title "${esc(safeTitle)}"`;
|
|
332
|
+
const child = spawn("osascript", ["-e", script], { stdio: "ignore" });
|
|
333
|
+
child.on("error", (err) => {
|
|
334
|
+
process.stderr.write(
|
|
335
|
+
`[platform] notify(osascript) failed: ${err && err.message}\n`,
|
|
336
|
+
);
|
|
337
|
+
});
|
|
338
|
+
child.unref && child.unref();
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (process.platform === "linux") {
|
|
342
|
+
const child = spawn("notify-send", [safeTitle, safeMessage], {
|
|
343
|
+
stdio: "ignore",
|
|
344
|
+
});
|
|
345
|
+
child.on("error", (err) => {
|
|
346
|
+
process.stderr.write(
|
|
347
|
+
`[platform] notify(notify-send) failed: ${err && err.message}\n`,
|
|
348
|
+
);
|
|
349
|
+
});
|
|
350
|
+
child.unref && child.unref();
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
// win32
|
|
354
|
+
const child = spawn("msg.exe", ["*", `${safeTitle}: ${safeMessage}`], {
|
|
355
|
+
stdio: "ignore",
|
|
356
|
+
windowsHide: true,
|
|
357
|
+
});
|
|
358
|
+
child.on("error", (err) => {
|
|
359
|
+
process.stderr.write(
|
|
360
|
+
`[platform] notify(msg.exe) failed: ${err && err.message}\n`,
|
|
361
|
+
);
|
|
362
|
+
});
|
|
363
|
+
child.unref && child.unref();
|
|
364
|
+
} catch (err) {
|
|
365
|
+
// Defense in depth — spawn() itself can throw synchronously on certain
|
|
366
|
+
// argument errors. Never propagate.
|
|
367
|
+
process.stderr.write(
|
|
368
|
+
`[platform] notify synchronous error: ${err && err.message}\n`,
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
module.exports = {
|
|
374
|
+
resolveClaudePath,
|
|
375
|
+
isAlive,
|
|
376
|
+
spawnWorker,
|
|
377
|
+
spawnSupervisor,
|
|
378
|
+
preventSleep,
|
|
379
|
+
releaseSleep,
|
|
380
|
+
notify,
|
|
381
|
+
};
|