@agentsignalnet/claude-plugin 0.2.72 → 0.2.73

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.72",
4
+ "version": "0.2.73",
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.72",
3
+ "version": "0.2.73",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -190,6 +190,28 @@ const lastChase = new Map();
190
190
  */
191
191
  const repaired = new Set();
192
192
 
193
+ /**
194
+ * ANSWERS, which are not messages and were therefore invisible.
195
+ *
196
+ * `ask_agent` sends a question and the reply comes back as a RESPONSE attached
197
+ * to it, not as a message of its own. The channel log carries messages, so a
198
+ * conversation held in questions rendered as an unbroken column of outbound
199
+ * rows -- and read exactly as it looks: as somebody who never replied. It was
200
+ * reported that way, by somebody who had in fact been answered twice.
201
+ *
202
+ * The log cannot tell a question from a statement either: `agent_message_log`
203
+ * does not carry `options`. So each recent row is asked about once, and the
204
+ * answer is cached by message id.
205
+ *
206
+ * WHAT THIS COSTS, since every call to that endpoint is priced: a row that was
207
+ * never a question is refunded (`not_a_question`), and so is a question nobody
208
+ * has answered yet. The only charged call is the one that first comes back with
209
+ * an answer -- after which the row is settled and never asked about again. One
210
+ * credit per answered question, once.
211
+ */
212
+ const ANSWER_SCAN = 25;
213
+ const answerCache = new Map();
214
+
193
215
  /** The routes a person navigates to, as opposed to the ones the page polls. */
194
216
  function isPage(pathname) {
195
217
  return pathname === '/' || pathname.startsWith('/a/');
@@ -682,6 +704,20 @@ const PAGE = `<!doctype html>
682
704
  margin: 0 0 6px; padding: 0 2px;
683
705
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
684
706
  }
707
+ /* An answer belongs WITH its question, not as a row of its own further down:
708
+ it is a reply to this and to nothing else, and a separate line would put an
709
+ unrelated message between them the moment one arrives in between. */
710
+ .answer {
711
+ margin: 6px 0 0; padding: 5px 8px 5px 10px;
712
+ border-left: 2px solid var(--accent, var(--line));
713
+ background: var(--surface-2, transparent);
714
+ border-radius: 0 6px 6px 0;
715
+ font-size: 13px; color: var(--fg);
716
+ display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap;
717
+ }
718
+ .answer .who { color: var(--dim); font-weight: 500; }
719
+ .answer .time { color: var(--dim); font-size: 12px; margin-left: auto; }
720
+
685
721
  .chan { margin-bottom: 4px; }
686
722
  .chan-head { display: flex; align-items: center; gap: 2px; }
687
723
  .twist {
@@ -1770,6 +1806,9 @@ const PAGE = `<!doctype html>
1770
1806
  </div>
1771
1807
  \${m.title && m.title !== who ? '<div class="title">' + esc(m.title) + '</div>' : ''}
1772
1808
  <div class="clipwrap" data-wrap="\${esc(m.id)}"><div class="body" data-body="\${esc(m.id)}">\${esc(m.body ?? m.preview)}\${m.truncated ? '…' : ''}</div></div>
1809
+ \${(m.answers ?? []).map((a) =>
1810
+ '<div class="answer"><span class="who">' + esc(a.who) + '</span> answered <b>' +
1811
+ esc(a.option) + '</b><span class="time">' + esc(stamp(a.at)) + '</span></div>').join('')}
1773
1812
  </div>\`;
1774
1813
  }).join('');
1775
1814
 
@@ -2525,6 +2564,51 @@ function channelFor(ref) {
2525
2564
  }
2526
2565
 
2527
2566
  /** One upstream call, one place that turns a non-2xx into something readable. */
2567
+ /**
2568
+ * Attach answers to the rows that have them.
2569
+ *
2570
+ * Only the newest ANSWER_SCAN rows: an answer arrives minutes after its
2571
+ * question, not days, and probing the whole history on every poll would be a
2572
+ * request per row forever. Settled rows -- not a question, or a question every
2573
+ * recipient has answered -- are cached and never asked about again, which is
2574
+ * what keeps this from being a per-poll cost.
2575
+ */
2576
+ async function withAnswers(key, messages) {
2577
+ const recent = messages.slice(0, ANSWER_SCAN);
2578
+
2579
+ await Promise.all(
2580
+ recent.map(async (m) => {
2581
+ const known = answerCache.get(m.id);
2582
+ // Settled: either it was never a question, or nobody is still to reply.
2583
+ if (known && (known.settled || Date.now() - known.at < CHASE_EVERY)) return;
2584
+
2585
+ const body = await upstream('/v1/messages/' + encodeURIComponent(m.id) + '/responses', key);
2586
+ if (body.error) {
2587
+ // A 400 here is the API saying "sent without options", which is a
2588
+ // permanent fact about the row rather than a failure to retry.
2589
+ const notAQuestion = /without options/i.test(body.error);
2590
+ answerCache.set(m.id, { at: Date.now(), settled: notAQuestion, answers: null });
2591
+ return;
2592
+ }
2593
+ answerCache.set(m.id, {
2594
+ at: Date.now(),
2595
+ settled: (body.awaiting ?? 0) === 0,
2596
+ answers: (body.responses ?? []).map((r) => ({
2597
+ who: r.name || r.recipient_key,
2598
+ option: (body.options ?? [])[r.option_index] ?? String(r.option_index),
2599
+ at: r.responded_at,
2600
+ })),
2601
+ awaiting: body.awaiting ?? 0,
2602
+ });
2603
+ }),
2604
+ );
2605
+
2606
+ return messages.map((m) => {
2607
+ const known = answerCache.get(m.id);
2608
+ return known?.answers?.length ? { ...m, answers: known.answers } : m;
2609
+ });
2610
+ }
2611
+
2528
2612
  async function upstream(path, key = apiKey) {
2529
2613
  try {
2530
2614
  const response = await fetch(`${baseUrl}${path}`, {
@@ -3591,11 +3675,17 @@ const server = createServer(async (req, res) => {
3591
3675
  * NOW -- a row written to disk as fresh is stale an hour later, and a
3592
3676
  * cached flag would be the same frozen answer one level down.
3593
3677
  */
3594
- body.messages = merged.map((m) =>
3678
+ const marked = merged.map((m) =>
3595
3679
  (m.pending ?? 0) > 0 && Date.now() - Date.parse(m.created_at) >= CHASE_FOR
3596
3680
  ? { ...m, stale: true }
3597
3681
  : m,
3598
3682
  );
3683
+
3684
+ // Answers last, so a row carries both what became of it and what came
3685
+ // back. Not written to history: an answer can arrive after the row is
3686
+ // stored, and a cached copy would freeze exactly the way the delivery
3687
+ // counts did.
3688
+ body.messages = await withAnswers(on.key, marked);
3599
3689
  // Every channel this dashboard can open, so the page can offer them. The
3600
3690
  // key never leaves this process -- only the ref and the name.
3601
3691