@agentsignalnet/claude-plugin 0.2.70 → 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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agentsignal",
3
3
  "displayName": "AgentSignal",
4
- "version": "0.2.70",
4
+ "version": "0.2.72",
5
5
  "description": "Page a human from inside Claude Code, or become an addressable agent that other agents can reach.",
6
6
  "author": {
7
7
  "name": "Data Group AI",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentsignalnet/claude-plugin",
3
- "version": "0.2.70",
3
+ "version": "0.2.72",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -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/');
@@ -902,7 +946,7 @@ const PAGE = `<!doctype html>
902
946
  </header>
903
947
  <div id="shell">
904
948
  <aside id="side" aria-label="Channels">
905
- <p class="rail-title">Channels</p>
949
+ <p class="rail-title" id="rail-title">Channels</p>
906
950
  <nav id="who-nav"></nav>
907
951
  <details id="setup"><summary>This machine</summary><div id="setupbody">reading…</div></details>
908
952
  </aside>
@@ -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
- if (m.pending > 0) return ['wait', m.pending + ' pending'];
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
 
@@ -1399,9 +1455,22 @@ const PAGE = `<!doctype html>
1399
1455
  group.channels.push(c);
1400
1456
  }
1401
1457
 
1402
- // Headings only when they distinguish something. One company, or a server
1403
- // that does not say, and the rail stays the plain list it was.
1404
- const sectioned = groups.length > 1 && groups.every((g) => g.at);
1458
+ /*
1459
+ THE COMPANY IS PART OF THE SHAPE, not a disambiguator.
1460
+
1461
+ This used to require groups.length > 1, on the reasoning that a label
1462
+ repeated above every row is furniture. That is true of a label and false
1463
+ of a level: the rail is company > channel > agent, and a hierarchy that
1464
+ hides its top level whenever there is one of them teaches the wrong shape
1465
+ and then changes under you the day a second company appears. Somebody
1466
+ running one company saw no company at all and reasonably asked whether it
1467
+ had been built.
1468
+
1469
+ The account must still be KNOWN. An older API does not send it, and
1470
+ inventing "Unnamed company" above everything would be the furniture the
1471
+ old rule was actually worried about.
1472
+ */
1473
+ const sectioned = groups.every((g) => g.at);
1405
1474
 
1406
1475
  const rows = (list) => list.map((c) => {
1407
1476
  const ref = c.ref ?? '';
@@ -1443,6 +1512,15 @@ const PAGE = `<!doctype html>
1443
1512
  return '<div class="chan">' + head + '<div class="chan-body">' + body + '</div></div>';
1444
1513
  }).join('');
1445
1514
 
1515
+ /*
1516
+ The title follows the shape rather than asserting one. When the accounts
1517
+ are known the top level of the rail IS the company, so "Channels" would
1518
+ name the second level while pointing at the first; when they are not, the
1519
+ rail really is a flat list of channels and "Companies" would name a level
1520
+ that is not on screen.
1521
+ */
1522
+ document.getElementById('rail-title').textContent = sectioned ? 'Companies' : 'Channels';
1523
+
1446
1524
  nav.innerHTML = groups
1447
1525
  .map((g) =>
1448
1526
  sectioned
@@ -3430,8 +3508,44 @@ const server = createServer(async (req, res) => {
3430
3508
  // leave a hole in whichever is quieter.
3431
3509
  const kept = readHistory(on.ref ?? channelRef);
3432
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;
3433
3547
  const body = await upstream(
3434
- '/v1/messages?limit=100' + (newest ? '&since=' + encodeURIComponent(newest) : ''),
3548
+ '/v1/messages?limit=100' + (from ? '&since=' + encodeURIComponent(from) : ''),
3435
3549
  on.key,
3436
3550
  );
3437
3551
 
@@ -3450,13 +3564,38 @@ const server = createServer(async (req, res) => {
3450
3564
  }
3451
3565
  channelRef = on.ref ?? channelRef;
3452
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
+
3453
3577
  const fresh = (body.messages ?? []).map(keepable).filter(Boolean);
3454
- // Deduplicated by id, because `since` is inclusive at the boundary on a
3455
- // shared timestamp and two messages in the same second are ordinary.
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.)
3456
3583
  const byId = new Map(kept.map((m) => [m.id, m]));
3457
3584
  for (const m of fresh) byId.set(m.id, m);
3458
3585
 
3459
- body.messages = writeHistory(on.ref ?? channelRef, [...byId.values()], settings().history_days);
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
+ );
3460
3599
  // Every channel this dashboard can open, so the page can offer them. The
3461
3600
  // key never leaves this process -- only the ref and the name.
3462
3601