@agentsignalnet/claude-plugin 0.2.102 → 0.2.104
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 +91 -50
package/package.json
CHANGED
package/scripts/inbox-daemon.mjs
CHANGED
|
@@ -95,6 +95,18 @@ let longPoll = true;
|
|
|
95
95
|
/** The shortest a cycle may take, so a busy inbox cannot spin this hot. */
|
|
96
96
|
const FLOOR_MS = 250;
|
|
97
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Output that means the session never ran, as opposed to ran and went wrong.
|
|
100
|
+
*
|
|
101
|
+
* Deliberately narrow. A responder that stops itself on the wrong signal is
|
|
102
|
+
* worse than one that retries a few times too often: these are all conditions
|
|
103
|
+
* a message cannot influence and a retry cannot clear.
|
|
104
|
+
*/
|
|
105
|
+
const CANNOT_START = /Failed to authenticate|not logged in|command not found|ENOENT|Invalid API key/i;
|
|
106
|
+
|
|
107
|
+
/** Why this machine cannot run a responder at all, once something proves it. */
|
|
108
|
+
let unavailable = null;
|
|
109
|
+
|
|
98
110
|
/**
|
|
99
111
|
* Where the identity lives -- ALL the places, matching the MCP server exactly.
|
|
100
112
|
*
|
|
@@ -122,17 +134,24 @@ const FLOOR_MS = 250;
|
|
|
122
134
|
* Choosing a directory independently is how the two came apart before.
|
|
123
135
|
*/
|
|
124
136
|
function credential() {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
/*
|
|
138
|
+
THE FIRST OF THE SHARED ANSWER, rather than a fifth scan of the same
|
|
139
|
+
directories.
|
|
140
|
+
|
|
141
|
+
This walked stateDirs(), read agent.json, and filtered on base_url -- which
|
|
142
|
+
is exactly what state.mjs does, and exactly what the identities() copy
|
|
143
|
+
below it did before that copy was removed. Three readers of one file in one
|
|
144
|
+
process, and the one that drifted took `act` mode with it.
|
|
145
|
+
|
|
146
|
+
Same result by construction: identities() preserves stateDirs() order and
|
|
147
|
+
dedupes by credential, so its first element is the first directory that
|
|
148
|
+
holds a credential for this API. Keyed on base URL for the same reason the
|
|
149
|
+
MCP server is -- a production credential must not be reused against
|
|
150
|
+
localhost, or the reverse -- and that check now lives in one place.
|
|
151
|
+
*/
|
|
152
|
+
const [first] = storedIdentities(baseUrl);
|
|
153
|
+
if (first) return { secret: first.secret, dir: first.dir };
|
|
154
|
+
|
|
136
155
|
// An explicit secret has no directory of its own, so it falls back to the
|
|
137
156
|
// one the server would have written to -- the same one the hooks fall back
|
|
138
157
|
// to.
|
|
@@ -180,52 +199,41 @@ const spoolPath = flag('spool', join(stateDir, 'inbox-spool.json'));
|
|
|
180
199
|
* unrelated killed this process. The cost is a readdir of a few directories
|
|
181
200
|
* beside an HTTPS request, which is nothing.
|
|
182
201
|
*/
|
|
202
|
+
/**
|
|
203
|
+
* WHO THIS MACHINE WATCHES, answered in one place.
|
|
204
|
+
*
|
|
205
|
+
* This used to be a second implementation of `identities()` sitting beside the
|
|
206
|
+
* import of the first -- `storedIdentities` was imported at the top of this
|
|
207
|
+
* file and never called, while forty lines here re-derived the same answer
|
|
208
|
+
* from the same directories.
|
|
209
|
+
*
|
|
210
|
+
* state.mjs was created because three copies of this logic drifted apart and
|
|
211
|
+
* "each drift failed the same silent way". This was the fourth, and it failed
|
|
212
|
+
* exactly as advertised: it omitted `repo`, so the responder read
|
|
213
|
+
* `identity.repo`, got undefined, and started every session in the plugin data
|
|
214
|
+
* directory rather than the checkout. Nothing went red; `act` mode simply
|
|
215
|
+
* could not see any code.
|
|
216
|
+
*
|
|
217
|
+
* The copy is gone. What remains here is the one thing state.mjs genuinely has
|
|
218
|
+
* no notion of: the by-hand invocation.
|
|
219
|
+
*/
|
|
183
220
|
function identities() {
|
|
184
221
|
// An explicitly named spool means one inbox and that inbox only: it is the
|
|
185
222
|
// by-hand invocation, and quietly watching several while writing one file
|
|
186
223
|
// would be worse than the limitation.
|
|
224
|
+
//
|
|
225
|
+
// Shaped like the shared answer even though it is built here, because a
|
|
226
|
+
// consumer that has to know which branch produced its identity is a fifth
|
|
227
|
+
// copy of this problem waiting to happen.
|
|
187
228
|
if (flag('spool', null) || process.env.AGENTSIGNAL_DEVICE_SECRET) {
|
|
188
|
-
return secret
|
|
229
|
+
return secret
|
|
230
|
+
? [{ secret, credential: secret, dir: stateDir, spool: spoolPath, handle: null, repo: null }]
|
|
231
|
+
: [];
|
|
189
232
|
}
|
|
190
233
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const stored = JSON.parse(readFileSync(join(dir, 'agent.json'), 'utf8'));
|
|
195
|
-
if (!stored?.credential || stored.base_url !== baseUrl) continue;
|
|
196
|
-
// Keyed on the credential, not the directory: the same identity found
|
|
197
|
-
// through a plugin directory and through a sibling is one agent, and
|
|
198
|
-
// polling it twice would deliver everything to it twice.
|
|
199
|
-
if (!seen.has(stored.credential)) {
|
|
200
|
-
seen.set(stored.credential, {
|
|
201
|
-
secret: stored.credential,
|
|
202
|
-
dir,
|
|
203
|
-
spool: join(dir, 'inbox-spool.json'),
|
|
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,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
} catch {
|
|
225
|
-
/* no identity in this directory, which is the ordinary case */
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return [...seen.values()];
|
|
234
|
+
// Keyed on the credential rather than the directory, deduped, filtered to
|
|
235
|
+
// this API -- all of it, once, over there.
|
|
236
|
+
return storedIdentities(baseUrl);
|
|
229
237
|
}
|
|
230
238
|
|
|
231
239
|
if (!secret) {
|
|
@@ -335,6 +343,10 @@ async function tick() {
|
|
|
335
343
|
async function considerResponding(watched) {
|
|
336
344
|
const config = responderSettings();
|
|
337
345
|
|
|
346
|
+
// Set once a spawn proves this machine cannot start a session at all. Every
|
|
347
|
+
// later message would fail the same way and spend a slot doing it.
|
|
348
|
+
if (unavailable) return;
|
|
349
|
+
|
|
338
350
|
const now = Date.now();
|
|
339
351
|
const ledger = readLedger();
|
|
340
352
|
const lockHeldBy = heldBy();
|
|
@@ -466,6 +478,35 @@ async function considerResponding(watched) {
|
|
|
466
478
|
child.on('exit', (code) => {
|
|
467
479
|
releaseLock();
|
|
468
480
|
const why = tail.trim().split('\n').filter(Boolean).at(-1) ?? null;
|
|
481
|
+
|
|
482
|
+
/*
|
|
483
|
+
A SESSION THAT COULD NOT START IS NOT A MESSAGE THAT WAS ANSWERED
|
|
484
|
+
BADLY, and the difference decides whether trying again is sensible.
|
|
485
|
+
|
|
486
|
+
"Failed to authenticate: OAuth session expired and could not be
|
|
487
|
+
refreshed" is the same for every message and will be the same for the
|
|
488
|
+
next one. Without this, each arriving message spawns, dies in under a
|
|
489
|
+
second, and spends one of six hourly slots -- so a machine that
|
|
490
|
+
cannot start a session at all burns its whole budget every hour,
|
|
491
|
+
forever, on sessions that never ran.
|
|
492
|
+
|
|
493
|
+
Measured here: exit 1 in well under a second, with the daemon's own
|
|
494
|
+
arguments and the right working directory.
|
|
495
|
+
|
|
496
|
+
Held until the daemon restarts rather than for a timer, because what
|
|
497
|
+
fixes it is a person signing in -- and a restart is what happens the
|
|
498
|
+
next time they open a session, which is also when signing in becomes
|
|
499
|
+
possible. A timer would just resume the same doomed spawns.
|
|
500
|
+
*/
|
|
501
|
+
if (code !== 0 && why && CANNOT_START.test(why)) {
|
|
502
|
+
unavailable = why;
|
|
503
|
+
recordResponder({ event: 'unavailable', at: Date.now(), why: why.slice(0, 300) });
|
|
504
|
+
complain(
|
|
505
|
+
`the responder cannot start sessions on this machine: ${why.slice(0, 200)}. ` +
|
|
506
|
+
'Not trying again until this watcher restarts. If that is a sign-in ' +
|
|
507
|
+
'problem, running `claude` once and signing in is the fix.',
|
|
508
|
+
);
|
|
509
|
+
}
|
|
469
510
|
recordResponder({
|
|
470
511
|
event: 'finished', at: Date.now(),
|
|
471
512
|
delivery_id: message.delivery_id, exit_code: code,
|