@agentsignalnet/claude-plugin 0.2.71 → 0.2.72
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/dashboard.mjs +122 -5
package/package.json
CHANGED
package/scripts/dashboard.mjs
CHANGED
|
@@ -146,6 +146,50 @@ const token = randomUUID();
|
|
|
146
146
|
/** Where the token lives after the first visit. Namespaced: localhost is shared. */
|
|
147
147
|
const COOKIE = 'agentsignal_viewer';
|
|
148
148
|
|
|
149
|
+
/**
|
|
150
|
+
* RE-READING A PENDING ROW, briefly, because delivery state changes after the
|
|
151
|
+
* row is cached and `since` guarantees it is never looked at again.
|
|
152
|
+
*
|
|
153
|
+
* A message is first seen a second or two after it is sent -- when everything
|
|
154
|
+
* is pending -- and cached with those counts. It delivers a moment later and
|
|
155
|
+
* nothing ever asks again, so the dashboard showed "1 pending" for hours about
|
|
156
|
+
* messages that had landed. Its own note calls pending "the one state that
|
|
157
|
+
* reads, to somebody watching a conversation, as it never arrived", which is
|
|
158
|
+
* exactly how it was read: a working channel was reported as broken.
|
|
159
|
+
*
|
|
160
|
+
* Why not simply re-read everything: the log endpoint CHARGES A CREDIT per call
|
|
161
|
+
* that returns rows and refunds one that returns none. That refund is what makes
|
|
162
|
+
* watching free, and re-fetching the last hundred every two seconds is the
|
|
163
|
+
* eighteen-hundred-calls-an-hour bill the local copy was built to stop.
|
|
164
|
+
*
|
|
165
|
+
* So the chase is bounded on both axes. CHASE_FOR is how long a pending row is
|
|
166
|
+
* worth money at all -- delivery settles in seconds, and a row still pending
|
|
167
|
+
* after two minutes is waiting on a device that is off, which no amount of
|
|
168
|
+
* asking changes. CHASE_EVERY is how often, so a chase costs about six credits
|
|
169
|
+
* rather than sixty. Past the window the row stops being chased and stops
|
|
170
|
+
* claiming to be pending; see `state` on the page.
|
|
171
|
+
*/
|
|
172
|
+
const CHASE_FOR = 120_000;
|
|
173
|
+
const CHASE_EVERY = 20_000;
|
|
174
|
+
|
|
175
|
+
/** When each channel was last re-read for status, so the throttle is per channel. */
|
|
176
|
+
const lastChase = new Map();
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Channels whose stored counts have been reconciled once in THIS run.
|
|
180
|
+
*
|
|
181
|
+
* Every row cached before the chase existed carries whatever its counts were a
|
|
182
|
+
* second after it was sent, and the chase only reaches back two minutes -- so
|
|
183
|
+
* without this, a message delivered last week reads as "sent" forever, when the
|
|
184
|
+
* answer is one call away. The first poll of each channel therefore drops
|
|
185
|
+
* `since` and takes the last hundred rows as the API currently sees them.
|
|
186
|
+
*
|
|
187
|
+
* Once per process, not once per poll: a cold cache already paid for exactly
|
|
188
|
+
* this call before any of it was written, so the cost is one billed read per
|
|
189
|
+
* channel per dashboard start and nothing after it.
|
|
190
|
+
*/
|
|
191
|
+
const repaired = new Set();
|
|
192
|
+
|
|
149
193
|
/** The routes a person navigates to, as opposed to the ones the page polls. */
|
|
150
194
|
function isPage(pathname) {
|
|
151
195
|
return pathname === '/' || pathname.startsWith('/a/');
|
|
@@ -972,7 +1016,19 @@ const PAGE = `<!doctype html>
|
|
|
972
1016
|
if (m.failed > 0) return ['bad', m.failed + ' failed'];
|
|
973
1017
|
if (m.read > 0) return ['', m.read + ' read'];
|
|
974
1018
|
if (m.delivered > 0) return ['', m.delivered + ' delivered'];
|
|
975
|
-
|
|
1019
|
+
/*
|
|
1020
|
+
A PENDING COUNT NOTHING IS RE-READING IS NOT NEWS, and calling it
|
|
1021
|
+
"pending" is a claim this page cannot support. The row was cached seconds
|
|
1022
|
+
after it was sent, when everything is pending, and the log endpoint bills
|
|
1023
|
+
per re-read so it is not re-read forever. Messages sat here marked pending
|
|
1024
|
+
for hours after they were delivered, and read exactly as the note above
|
|
1025
|
+
predicts -- as "it never arrived".
|
|
1026
|
+
|
|
1027
|
+
So a row nobody is chasing any more says the thing that is still true: it
|
|
1028
|
+
was sent. The server sets stale, because it is the side that knows when it
|
|
1029
|
+
stopped looking.
|
|
1030
|
+
*/
|
|
1031
|
+
if (m.pending > 0) return m.stale ? ['', 'sent'] : ['wait', m.pending + ' pending'];
|
|
976
1032
|
return ['', 'no devices'];
|
|
977
1033
|
}
|
|
978
1034
|
|
|
@@ -3452,8 +3508,44 @@ const server = createServer(async (req, res) => {
|
|
|
3452
3508
|
// leave a hole in whichever is quieter.
|
|
3453
3509
|
const kept = readHistory(on.ref ?? channelRef);
|
|
3454
3510
|
const newest = kept.length ? kept[0].created_at : null;
|
|
3511
|
+
|
|
3512
|
+
/**
|
|
3513
|
+
* Wind `since` back to the oldest row still worth asking about.
|
|
3514
|
+
*
|
|
3515
|
+
* Normally it is the newest row held, which is what keeps an idle poll
|
|
3516
|
+
* empty and free. When something recent is still pending, it becomes that
|
|
3517
|
+
* row instead -- so the answer includes it and its counts are refreshed --
|
|
3518
|
+
* and then only once per CHASE_EVERY, because that answer is not empty and
|
|
3519
|
+
* is therefore billed.
|
|
3520
|
+
*
|
|
3521
|
+
* `kept` is newest-first, so the last match is the oldest one.
|
|
3522
|
+
*/
|
|
3523
|
+
const key = on.ref ?? channelRef ?? '';
|
|
3524
|
+
const now = Date.now();
|
|
3525
|
+
const chasing = kept.filter(
|
|
3526
|
+
(m) => (m.pending ?? 0) > 0 && now - Date.parse(m.created_at) < CHASE_FOR,
|
|
3527
|
+
);
|
|
3528
|
+
const due = chasing.length > 0 && now - (lastChase.get(key) ?? 0) >= CHASE_EVERY;
|
|
3529
|
+
if (due) lastChase.set(key, now);
|
|
3530
|
+
|
|
3531
|
+
/*
|
|
3532
|
+
A MILLISECOND BEFORE IT, because `since` is EXCLUSIVE: the SQL is
|
|
3533
|
+
`created_at > p_since`, so asking from a row's own stamp asks for
|
|
3534
|
+
everything after it and returns everything except the row we came for.
|
|
3535
|
+
Date.parse truncates the microseconds Postgres stores, which would happen
|
|
3536
|
+
to work here, but relying on a rounding artefact for correctness is how
|
|
3537
|
+
this breaks the day the column changes precision.
|
|
3538
|
+
*/
|
|
3539
|
+
const repair = !repaired.has(key);
|
|
3540
|
+
repaired.add(key);
|
|
3541
|
+
|
|
3542
|
+
const from = repair
|
|
3543
|
+
? null
|
|
3544
|
+
: due
|
|
3545
|
+
? new Date(Date.parse(chasing[chasing.length - 1].created_at) - 1).toISOString()
|
|
3546
|
+
: newest;
|
|
3455
3547
|
const body = await upstream(
|
|
3456
|
-
'/v1/messages?limit=100' + (
|
|
3548
|
+
'/v1/messages?limit=100' + (from ? '&since=' + encodeURIComponent(from) : ''),
|
|
3457
3549
|
on.key,
|
|
3458
3550
|
);
|
|
3459
3551
|
|
|
@@ -3472,13 +3564,38 @@ const server = createServer(async (req, res) => {
|
|
|
3472
3564
|
}
|
|
3473
3565
|
channelRef = on.ref ?? channelRef;
|
|
3474
3566
|
|
|
3567
|
+
/*
|
|
3568
|
+
Mark the repair under the ref the SERVER resolved as well as the one we
|
|
3569
|
+
asked with. At boot there is no ref yet, so the first poll is keyed on
|
|
3570
|
+
the empty string and the second -- now knowing the real ref -- would
|
|
3571
|
+
find nothing, repair again, and re-download the last hundred rows every
|
|
3572
|
+
poll forever. The roster cache had this exact bug and it presented as
|
|
3573
|
+
"reading..." that never finished; here it would present as a bill.
|
|
3574
|
+
*/
|
|
3575
|
+
repaired.add(on.ref ?? channelRef);
|
|
3576
|
+
|
|
3475
3577
|
const fresh = (body.messages ?? []).map(keepable).filter(Boolean);
|
|
3476
|
-
// Deduplicated by id
|
|
3477
|
-
//
|
|
3578
|
+
// Deduplicated by id: a chase deliberately asks from before a row it
|
|
3579
|
+
// already holds, so the same message arrives twice by design. (An older
|
|
3580
|
+
// comment here said `since` was inclusive at the boundary. It is not --
|
|
3581
|
+
// the SQL is a strict `>` -- and the dedup is what makes the re-ask safe
|
|
3582
|
+
// rather than what compensates for the boundary.)
|
|
3478
3583
|
const byId = new Map(kept.map((m) => [m.id, m]));
|
|
3479
3584
|
for (const m of fresh) byId.set(m.id, m);
|
|
3480
3585
|
|
|
3481
|
-
|
|
3586
|
+
const merged = writeHistory(on.ref ?? channelRef, [...byId.values()], settings().history_days);
|
|
3587
|
+
|
|
3588
|
+
/**
|
|
3589
|
+
* Mark what is no longer being chased, so the page can stop calling it
|
|
3590
|
+
* pending. Computed here rather than stored, because it is a fact about
|
|
3591
|
+
* NOW -- a row written to disk as fresh is stale an hour later, and a
|
|
3592
|
+
* cached flag would be the same frozen answer one level down.
|
|
3593
|
+
*/
|
|
3594
|
+
body.messages = merged.map((m) =>
|
|
3595
|
+
(m.pending ?? 0) > 0 && Date.now() - Date.parse(m.created_at) >= CHASE_FOR
|
|
3596
|
+
? { ...m, stale: true }
|
|
3597
|
+
: m,
|
|
3598
|
+
);
|
|
3482
3599
|
// Every channel this dashboard can open, so the page can offer them. The
|
|
3483
3600
|
// key never leaves this process -- only the ref and the name.
|
|
3484
3601
|
|