@agentsignalnet/claude-plugin 0.2.100 → 0.2.102
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-daemon.mjs +171 -10
package/package.json
CHANGED
package/scripts/inbox-daemon.mjs
CHANGED
|
@@ -202,6 +202,23 @@ function identities() {
|
|
|
202
202
|
dir,
|
|
203
203
|
spool: join(dir, 'inbox-spool.json'),
|
|
204
204
|
handle: stored.handle ?? null,
|
|
205
|
+
/*
|
|
206
|
+
THE CHECKOUT THIS IDENTITY BELONGS TO, and the reason this line is
|
|
207
|
+
worth a comment is that its absence is the drift state.mjs exists
|
|
208
|
+
to prevent.
|
|
209
|
+
|
|
210
|
+
That file says so in its own header: three copies of "where do
|
|
211
|
+
identities live" drifted apart and each drift failed the same
|
|
212
|
+
silent way. This function is a fourth copy, and it had been missing
|
|
213
|
+
`repo` while state.mjs carried it -- so the responder read
|
|
214
|
+
`identity.repo`, got undefined, and ran every session in the plugin
|
|
215
|
+
data directory instead of the code. Nothing failed; `act` mode just
|
|
216
|
+
could not see anything.
|
|
217
|
+
|
|
218
|
+
Unifying the two is the real repair and is not this change: this
|
|
219
|
+
copy has a by-hand branch above that state.mjs has no notion of.
|
|
220
|
+
*/
|
|
221
|
+
repo: stored.repo ?? null,
|
|
205
222
|
});
|
|
206
223
|
}
|
|
207
224
|
} catch {
|
|
@@ -387,12 +404,80 @@ async function considerResponding(watched) {
|
|
|
387
404
|
title: message.title ?? null });
|
|
388
405
|
say(`responder answering ${message.delivery_id} (${config.mode}) from ${verdict.peer ?? 'unknown'}`);
|
|
389
406
|
|
|
390
|
-
|
|
407
|
+
/*
|
|
408
|
+
WHERE THE WORK IS, not where the credential is.
|
|
409
|
+
|
|
410
|
+
This passed `identity.dir`, which is the plugin's data directory --
|
|
411
|
+
`~/.claude/plugins/data/.../agents/AgentSignal-<id>/`, holding agent.json
|
|
412
|
+
and the spool and nothing else. In `answer` mode that is invisible,
|
|
413
|
+
because the session cannot reach a file anyway. In `act` mode it is the
|
|
414
|
+
whole feature: a session told "you may read, search and run commands to
|
|
415
|
+
establish the answer" was sitting in a folder with two JSON files in it,
|
|
416
|
+
unable to see a single line of the code it was asked about.
|
|
417
|
+
|
|
418
|
+
`agent.json` has recorded `repo` all along -- the checkout the identity
|
|
419
|
+
was created in -- and `identities()` surfaces it. It was simply never
|
|
420
|
+
used. Checked before it is trusted, because a repo can be moved or
|
|
421
|
+
deleted after an agent joined, and a cwd that does not exist fails the
|
|
422
|
+
spawn outright rather than degrading.
|
|
423
|
+
*/
|
|
424
|
+
let where = identity.dir;
|
|
425
|
+
if (identity.repo) {
|
|
426
|
+
try {
|
|
427
|
+
if (statSync(identity.repo).isDirectory()) where = identity.repo;
|
|
428
|
+
else complain(`${identity.repo} is not a directory; answering from ${identity.dir}`);
|
|
429
|
+
} catch {
|
|
430
|
+
complain(
|
|
431
|
+
`the repo this agent joined from (${identity.repo}) is gone; ` +
|
|
432
|
+
`answering from ${identity.dir}, where it can see nothing`,
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const child = spawnResponder(message, config, where);
|
|
438
|
+
|
|
439
|
+
/*
|
|
440
|
+
READ WHAT IT SAYS, for two reasons and the second is worse.
|
|
441
|
+
|
|
442
|
+
The ledger recorded `exit_code: 1` and nothing else, so five spawns on
|
|
443
|
+
this machine looked identical and none of them could be explained. They
|
|
444
|
+
were not the same: the first two died because --allowed-tools had eaten
|
|
445
|
+
the prompt, and the last three because the spawned session could not
|
|
446
|
+
authenticate. Same code, same silence, different faults -- and the
|
|
447
|
+
second was invisible until the first was fixed.
|
|
448
|
+
|
|
449
|
+
The worse reason: stdout and stderr were piped and never read. A pipe
|
|
450
|
+
has a finite buffer, so a session that printed more than about 64KB
|
|
451
|
+
would BLOCK on the write, forever. It holds the single-flight lock
|
|
452
|
+
while it does, which means one talkative session stops this machine
|
|
453
|
+
ever running a responder again. Draining is what prevents that; keeping
|
|
454
|
+
the tail is what makes it useful.
|
|
455
|
+
|
|
456
|
+
Bounded, because this ends up in a ledger that has to stay readable,
|
|
457
|
+
and the interesting part of a failure is at the end.
|
|
458
|
+
*/
|
|
459
|
+
let tail = '';
|
|
460
|
+
const keep = (chunk) => {
|
|
461
|
+
tail = (tail + chunk).slice(-2000);
|
|
462
|
+
};
|
|
463
|
+
child.stdout?.on('data', keep);
|
|
464
|
+
child.stderr?.on('data', keep);
|
|
465
|
+
|
|
391
466
|
child.on('exit', (code) => {
|
|
392
467
|
releaseLock();
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
468
|
+
const why = tail.trim().split('\n').filter(Boolean).at(-1) ?? null;
|
|
469
|
+
recordResponder({
|
|
470
|
+
event: 'finished', at: Date.now(),
|
|
471
|
+
delivery_id: message.delivery_id, exit_code: code,
|
|
472
|
+
// Only when something went wrong. A successful answer has nothing to
|
|
473
|
+
// explain, and its output is the reply itself -- which belongs in
|
|
474
|
+
// the channel, not in a log on this machine.
|
|
475
|
+
...(code === 0 ? {} : { why: why ? why.slice(0, 300) : null }),
|
|
476
|
+
});
|
|
477
|
+
say(
|
|
478
|
+
`responder finished ${message.delivery_id} with code ${code}` +
|
|
479
|
+
(code === 0 || !why ? '' : `: ${why.slice(0, 200)}`),
|
|
480
|
+
);
|
|
396
481
|
});
|
|
397
482
|
|
|
398
483
|
// One per pass. The lock enforces this anyway; returning makes it true
|
|
@@ -911,7 +996,33 @@ const startupLockPath = join(lockRoot, 'starting.lock');
|
|
|
911
996
|
const LONGEST_HOLD_MS = 10_000;
|
|
912
997
|
const WAIT_STEP_MS = 100;
|
|
913
998
|
const WAIT_ATTEMPTS = Math.ceil((LONGEST_HOLD_MS * 3) / WAIT_STEP_MS);
|
|
914
|
-
|
|
999
|
+
/*
|
|
1000
|
+
STALE MUST BE REACHED BEFORE THE WAITER GIVES UP, or it is not a timeout a
|
|
1001
|
+
waiter can ever act on.
|
|
1002
|
+
|
|
1003
|
+
This was `* 6`, sixty seconds, against a wait budget of thirty. A waiter that
|
|
1004
|
+
arrives to find a FRESH lock sleeps 300 times at 100ms and gives up at thirty
|
|
1005
|
+
seconds -- it can never observe a lock reach sixty, so for that waiter the
|
|
1006
|
+
threshold did not exist. It fired only when the lock was already old on
|
|
1007
|
+
arrival, which is the case that was never the problem.
|
|
1008
|
+
|
|
1009
|
+
The case that is: a holder wedges at t=0, a waiter arrives at t=1s, waits its
|
|
1010
|
+
full budget, and proceeds WITHOUT the lock at t=31s while the lock sits there
|
|
1011
|
+
at thirty-one seconds old and still counted as valid. Two watchers, and the
|
|
1012
|
+
timeout meant to prevent exactly this was twice as far away as the waiter
|
|
1013
|
+
could see.
|
|
1014
|
+
|
|
1015
|
+
`* 2` rather than `* 3`: equal to the budget would mean breaking the lock on
|
|
1016
|
+
the final attempt with no attempts left to take it, which is the same
|
|
1017
|
+
unlocked start with an extra step. Twenty seconds leaves ten to acquire.
|
|
1018
|
+
|
|
1019
|
+
The ceiling itself is right, and worth restating because it is load-bearing.
|
|
1020
|
+
Rivals are signalled in one pass and waited for in another, so their five
|
|
1021
|
+
second waits OVERLAP -- five rivals cost about five seconds, not twenty-five
|
|
1022
|
+
-- and a stale incumbent adds one more five. Ten is the worst legitimate
|
|
1023
|
+
hold, thirty is three times it, and twenty sits between them.
|
|
1024
|
+
*/
|
|
1025
|
+
const HELD_TOO_LONG_MS = LONGEST_HOLD_MS * 2;
|
|
915
1026
|
// Ten steps is a second. Writing a forty-byte file does not take a second, so
|
|
916
1027
|
// anything still unparseable after that is genuinely broken rather than in
|
|
917
1028
|
// flight.
|
|
@@ -950,7 +1061,23 @@ async function claimStartup() {
|
|
|
950
1061
|
}
|
|
951
1062
|
};
|
|
952
1063
|
} catch (error) {
|
|
953
|
-
if (error?.code !== 'EEXIST')
|
|
1064
|
+
if (error?.code !== 'EEXIST') {
|
|
1065
|
+
/*
|
|
1066
|
+
PROCEEDING WITHOUT THE LOCK, and saying so.
|
|
1067
|
+
|
|
1068
|
+
Any error that is not "somebody already holds it" -- EACCES on the
|
|
1069
|
+
lock file, EROFS, ENOSPC, a lockRoot that is not a directory -- ends
|
|
1070
|
+
here, and this used to return silently. A daemon that could not take
|
|
1071
|
+
the lock then started anyway and looked exactly like one that had
|
|
1072
|
+
taken it.
|
|
1073
|
+
*/
|
|
1074
|
+
complain(
|
|
1075
|
+
`could not take the startup lock (${error?.code ?? error?.message ?? 'unknown'}) ` +
|
|
1076
|
+
`at ${startupLockPath}. Starting WITHOUT it, so two watchers are possible; ` +
|
|
1077
|
+
'the reconciliation after registration is what stops that being permanent.',
|
|
1078
|
+
);
|
|
1079
|
+
return () => {};
|
|
1080
|
+
}
|
|
954
1081
|
|
|
955
1082
|
let held;
|
|
956
1083
|
try {
|
|
@@ -973,6 +1100,11 @@ async function claimStartup() {
|
|
|
973
1100
|
*/
|
|
974
1101
|
unreadable += 1;
|
|
975
1102
|
if (unreadable > UNREADABLE_BEFORE_DEBRIS) {
|
|
1103
|
+
complain(
|
|
1104
|
+
`the startup lock has been unreadable for ${unreadable * WAIT_STEP_MS}ms; ` +
|
|
1105
|
+
'treating it as debris and deleting it. If a live holder wrote it, ' +
|
|
1106
|
+
'this is the moment two watchers become possible.',
|
|
1107
|
+
);
|
|
976
1108
|
try {
|
|
977
1109
|
unlinkSync(startupLockPath);
|
|
978
1110
|
} catch {
|
|
@@ -992,7 +1124,21 @@ async function claimStartup() {
|
|
|
992
1124
|
alive = false;
|
|
993
1125
|
}
|
|
994
1126
|
|
|
995
|
-
|
|
1127
|
+
const heldFor = Date.now() - (held.at ?? 0);
|
|
1128
|
+
if (!alive || heldFor > HELD_TOO_LONG_MS) {
|
|
1129
|
+
/*
|
|
1130
|
+
BREAKING SOMEBODY ELSE'S LOCK is the most consequential thing in this
|
|
1131
|
+
function and it used to happen in silence. The read-decide-unlink is
|
|
1132
|
+
not atomic: between believing the holder is gone and deleting the
|
|
1133
|
+
file, the holder can have released it and a third process taken it,
|
|
1134
|
+
and what gets deleted is a live lock. That is the shape that produces
|
|
1135
|
+
two watchers, and without this line there is nothing afterwards that
|
|
1136
|
+
says it happened.
|
|
1137
|
+
*/
|
|
1138
|
+
say(
|
|
1139
|
+
`breaking the startup lock held by pid ${held.pid} ` +
|
|
1140
|
+
(alive ? `after ${heldFor}ms, which is longer than any legitimate hold` : '(no such process)'),
|
|
1141
|
+
);
|
|
996
1142
|
try {
|
|
997
1143
|
unlinkSync(startupLockPath);
|
|
998
1144
|
} catch {
|
|
@@ -1005,9 +1151,24 @@ async function claimStartup() {
|
|
|
1005
1151
|
}
|
|
1006
1152
|
}
|
|
1007
1153
|
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1154
|
+
/*
|
|
1155
|
+
Outlasted three times the longest legitimate hold and still never got it,
|
|
1156
|
+
so something is wrong that waiting will not fix. Carry on unlocked rather
|
|
1157
|
+
than never watching: being unable to serialise is not a reason to refuse.
|
|
1158
|
+
|
|
1159
|
+
LOUDLY, though. This is the other way two watchers happen, and it was as
|
|
1160
|
+
silent as the first -- so a log showing two `started` lines and nothing
|
|
1161
|
+
else was consistent with this, with the fail-open above, and with the lock
|
|
1162
|
+
working perfectly and something else being wrong. Three explanations, no
|
|
1163
|
+
evidence, which is why two attempts at diagnosing the real incident got
|
|
1164
|
+
nowhere.
|
|
1165
|
+
*/
|
|
1166
|
+
complain(
|
|
1167
|
+
`waited ${(WAIT_ATTEMPTS * WAIT_STEP_MS) / 1000}s for the startup lock at ` +
|
|
1168
|
+
`${startupLockPath} and never got it. Starting WITHOUT it, so two watchers ` +
|
|
1169
|
+
'are possible; the reconciliation after registration is what stops that ' +
|
|
1170
|
+
'being permanent.',
|
|
1171
|
+
);
|
|
1011
1172
|
return () => {};
|
|
1012
1173
|
}
|
|
1013
1174
|
|