@agentsignalnet/claude-plugin 0.2.112 → 0.2.113
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/.claude-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/scripts/inbox-hook.mjs +58 -22
package/package.json
CHANGED
package/scripts/inbox-hook.mjs
CHANGED
|
@@ -298,7 +298,16 @@ if (mode === 'watch') {
|
|
|
298
298
|
silent.
|
|
299
299
|
*/
|
|
300
300
|
const sessionKey = (process.env.CLAUDE_CODE_HOST_SESSION_ID ?? '').replace(/[^A-Za-z0-9_-]/g, '_');
|
|
301
|
-
|
|
301
|
+
/*
|
|
302
|
+
`let`, because losing the lease must DEGRADE rather than throw.
|
|
303
|
+
|
|
304
|
+
It is an optimisation -- it stops sixty-seven pollers becoming sixty-seven
|
|
305
|
+
node runtimes -- and the watcher's actual job is to notice messages. So
|
|
306
|
+
every failure below sets this to null and carries on WITHOUT single-flight,
|
|
307
|
+
which is exactly what this file did before the lease existed. Wasteful
|
|
308
|
+
beats absent, and a brake fails closed while an optimisation must not.
|
|
309
|
+
*/
|
|
310
|
+
let watchFile = sessionKey
|
|
302
311
|
? join(lockDir(), 'watching', `${sessionKey}.json`)
|
|
303
312
|
: null;
|
|
304
313
|
|
|
@@ -324,30 +333,57 @@ if (mode === 'watch') {
|
|
|
324
333
|
const until = () => Date.now() + WATCH_SECONDS * 1000;
|
|
325
334
|
|
|
326
335
|
if (watchFile) {
|
|
327
|
-
|
|
328
|
-
|
|
336
|
+
/*
|
|
337
|
+
A DISK THAT CANNOT BE WRITTEN TO MUST NOT COST THE WATCHER.
|
|
338
|
+
|
|
339
|
+
This block was unguarded, and on 2026-08-23 a full disk crashed the hook
|
|
340
|
+
here twice -- ENOSPC out of `writeAtomic`, once on the rename and once on
|
|
341
|
+
the open, both in hook.log with a stack trace and nothing watching
|
|
342
|
+
afterwards. Before the lease existed, `watch` on a quiet channel wrote
|
|
343
|
+
nothing at all, so this file had made a previously read-only path into a
|
|
344
|
+
write on EVERY tool call, and then let that write be fatal.
|
|
345
|
+
|
|
346
|
+
The trade is deliberate. Failing here means no single-flight, so the old
|
|
347
|
+
one-poller-per-tool-call behaviour comes back and the machine is
|
|
348
|
+
wasteful. Failing the other way means no watcher, and an urgent message
|
|
349
|
+
that never interrupts anybody. Waste is recoverable; a message nobody
|
|
350
|
+
saw is not.
|
|
351
|
+
|
|
352
|
+
Losing the lease mid-run is covered too: the poll loop treats a lease it
|
|
353
|
+
cannot read as "no longer mine" and stands down, which is right when
|
|
354
|
+
another watcher took over and wrong when the disk simply filled. So the
|
|
355
|
+
claim is what decides -- once it fails, single-flight is off for this
|
|
356
|
+
process and the loop stops consulting a file it knows it never wrote.
|
|
357
|
+
*/
|
|
358
|
+
try {
|
|
359
|
+
mkdirSync(dirname(watchFile), { recursive: true });
|
|
360
|
+
const held = readWatcher();
|
|
329
361
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
362
|
+
if (held && held.pid !== process.pid && alive(held.pid)) {
|
|
363
|
+
// Somebody is already watching for this session. Push their deadline out
|
|
364
|
+
// to cover the tool call that just finished, and stop.
|
|
365
|
+
writeAtomic(watchFile, { pid: held.pid, until: until() });
|
|
366
|
+
process.exit(0);
|
|
367
|
+
}
|
|
336
368
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
369
|
+
// Nobody, or a pid that died with its file still on disk -- a watcher lost
|
|
370
|
+
// to SIGKILL or a reboot leaves exactly that, and it is not an error.
|
|
371
|
+
writeAtomic(watchFile, { pid: process.pid, until: until() });
|
|
372
|
+
|
|
373
|
+
// Runs on process.exit() too, so the wake path below cleans up as well.
|
|
374
|
+
process.on('exit', () => {
|
|
375
|
+
if (readWatcher()?.pid === process.pid) {
|
|
376
|
+
try {
|
|
377
|
+
unlinkSync(watchFile);
|
|
378
|
+
} catch {
|
|
379
|
+
/* somebody else tidied it, or took over */
|
|
380
|
+
}
|
|
348
381
|
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
382
|
+
});
|
|
383
|
+
} catch {
|
|
384
|
+
// No lease, so no single-flight -- and this process still watches.
|
|
385
|
+
watchFile = null;
|
|
386
|
+
}
|
|
351
387
|
}
|
|
352
388
|
|
|
353
389
|
// Exit 2 is the wake. Anything else is silence.
|