@agentsignalnet/claude-plugin 0.2.72 → 0.2.74

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.74",
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.74",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -128,6 +128,20 @@ let apiKey = process.env.AGENTSIGNAL_API_KEY;
128
128
  let baseUrl = process.env.AGENTSIGNAL_BASE_URL;
129
129
  const port = Number(process.env.PORT ?? 8899);
130
130
 
131
+ /**
132
+ * The port actually BOUND, which is not always the one asked for.
133
+ *
134
+ * PORT=0 means "any free one", which is how anything automated starts a server
135
+ * without picking a number and hoping. The banner already prints the bound one;
136
+ * the Origin check below did not, and compared the page's real origin against
137
+ * http://127.0.0.1:0 -- so on an assigned port every non-GET from the page was
138
+ * refused with a flat "No.". Readable, and unable to send, answer, invite or
139
+ * connect, with nothing saying why.
140
+ *
141
+ * Set in the listen callback, which runs before any request can arrive.
142
+ */
143
+ let bound = port;
144
+
131
145
  /**
132
146
  * A token in the URL, and loopback only.
133
147
  *
@@ -190,6 +204,28 @@ const lastChase = new Map();
190
204
  */
191
205
  const repaired = new Set();
192
206
 
207
+ /**
208
+ * ANSWERS, which are not messages and were therefore invisible.
209
+ *
210
+ * `ask_agent` sends a question and the reply comes back as a RESPONSE attached
211
+ * to it, not as a message of its own. The channel log carries messages, so a
212
+ * conversation held in questions rendered as an unbroken column of outbound
213
+ * rows -- and read exactly as it looks: as somebody who never replied. It was
214
+ * reported that way, by somebody who had in fact been answered twice.
215
+ *
216
+ * The log cannot tell a question from a statement either: `agent_message_log`
217
+ * does not carry `options`. So each recent row is asked about once, and the
218
+ * answer is cached by message id.
219
+ *
220
+ * WHAT THIS COSTS, since every call to that endpoint is priced: a row that was
221
+ * never a question is refunded (`not_a_question`), and so is a question nobody
222
+ * has answered yet. The only charged call is the one that first comes back with
223
+ * an answer -- after which the row is settled and never asked about again. One
224
+ * credit per answered question, once.
225
+ */
226
+ const ANSWER_SCAN = 25;
227
+ const answerCache = new Map();
228
+
193
229
  /** The routes a person navigates to, as opposed to the ones the page polls. */
194
230
  function isPage(pathname) {
195
231
  return pathname === '/' || pathname.startsWith('/a/');
@@ -422,6 +458,17 @@ if (apiKey) {
422
458
  if (byChannel.has(at)) continue;
423
459
  byChannel.set(at, {
424
460
  key,
461
+ /*
462
+ WHO on this machine is a member of this channel, kept because minting an
463
+ invitation needs one. A join code carries who extended it -- that is
464
+ what fills in sponsored_by and lets a fleet work out who leads -- so the
465
+ API refuses to mint from an account key and refuses a member of some
466
+ other channel. Without this the dashboard had one notion of "me",
467
+ resolved once at startup against the default channel, and offered it as
468
+ the inviter for every channel: correct for the first and refused for all
469
+ the rest.
470
+ */
471
+ holder: holder.key ?? null,
425
472
  via: `${holder.handle ?? holder.key}${holder.archived ? ' (previously)' : ''}`,
426
473
  // WHERE it came from, kept so startup can say it. A dashboard that goes
427
474
  // looking for credentials silently is indistinguishable from one that
@@ -682,6 +729,20 @@ const PAGE = `<!doctype html>
682
729
  margin: 0 0 6px; padding: 0 2px;
683
730
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
684
731
  }
732
+ /* An answer belongs WITH its question, not as a row of its own further down:
733
+ it is a reply to this and to nothing else, and a separate line would put an
734
+ unrelated message between them the moment one arrives in between. */
735
+ .answer {
736
+ margin: 6px 0 0; padding: 5px 8px 5px 10px;
737
+ border-left: 2px solid var(--accent, var(--line));
738
+ background: var(--surface-2, transparent);
739
+ border-radius: 0 6px 6px 0;
740
+ font-size: 13px; color: var(--fg);
741
+ display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap;
742
+ }
743
+ .answer .who { color: var(--dim); font-weight: 500; }
744
+ .answer .time { color: var(--dim); font-size: 12px; margin-left: auto; }
745
+
685
746
  .chan { margin-bottom: 4px; }
686
747
  .chan-head { display: flex; align-items: center; gap: 2px; }
687
748
  .twist {
@@ -1770,6 +1831,9 @@ const PAGE = `<!doctype html>
1770
1831
  </div>
1771
1832
  \${m.title && m.title !== who ? '<div class="title">' + esc(m.title) + '</div>' : ''}
1772
1833
  <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>
1834
+ \${(m.answers ?? []).map((a) =>
1835
+ '<div class="answer"><span class="who">' + esc(a.who) + '</span> answered <b>' +
1836
+ esc(a.option) + '</b><span class="time">' + esc(stamp(a.at)) + '</span></div>').join('')}
1773
1837
  </div>\`;
1774
1838
  }).join('');
1775
1839
 
@@ -2525,6 +2589,51 @@ function channelFor(ref) {
2525
2589
  }
2526
2590
 
2527
2591
  /** One upstream call, one place that turns a non-2xx into something readable. */
2592
+ /**
2593
+ * Attach answers to the rows that have them.
2594
+ *
2595
+ * Only the newest ANSWER_SCAN rows: an answer arrives minutes after its
2596
+ * question, not days, and probing the whole history on every poll would be a
2597
+ * request per row forever. Settled rows -- not a question, or a question every
2598
+ * recipient has answered -- are cached and never asked about again, which is
2599
+ * what keeps this from being a per-poll cost.
2600
+ */
2601
+ async function withAnswers(key, messages) {
2602
+ const recent = messages.slice(0, ANSWER_SCAN);
2603
+
2604
+ await Promise.all(
2605
+ recent.map(async (m) => {
2606
+ const known = answerCache.get(m.id);
2607
+ // Settled: either it was never a question, or nobody is still to reply.
2608
+ if (known && (known.settled || Date.now() - known.at < CHASE_EVERY)) return;
2609
+
2610
+ const body = await upstream('/v1/messages/' + encodeURIComponent(m.id) + '/responses', key);
2611
+ if (body.error) {
2612
+ // A 400 here is the API saying "sent without options", which is a
2613
+ // permanent fact about the row rather than a failure to retry.
2614
+ const notAQuestion = /without options/i.test(body.error);
2615
+ answerCache.set(m.id, { at: Date.now(), settled: notAQuestion, answers: null });
2616
+ return;
2617
+ }
2618
+ answerCache.set(m.id, {
2619
+ at: Date.now(),
2620
+ settled: (body.awaiting ?? 0) === 0,
2621
+ answers: (body.responses ?? []).map((r) => ({
2622
+ who: r.name || r.recipient_key,
2623
+ option: (body.options ?? [])[r.option_index] ?? String(r.option_index),
2624
+ at: r.responded_at,
2625
+ })),
2626
+ awaiting: body.awaiting ?? 0,
2627
+ });
2628
+ }),
2629
+ );
2630
+
2631
+ return messages.map((m) => {
2632
+ const known = answerCache.get(m.id);
2633
+ return known?.answers?.length ? { ...m, answers: known.answers } : m;
2634
+ });
2635
+ }
2636
+
2528
2637
  async function upstream(path, key = apiKey) {
2529
2638
  try {
2530
2639
  const response = await fetch(`${baseUrl}${path}`, {
@@ -2697,7 +2806,7 @@ const server = createServer(async (req, res) => {
2697
2806
  * no Origin at all.
2698
2807
  */
2699
2808
  const origin = req.headers.origin;
2700
- if (req.method !== 'GET' && origin && origin !== `http://127.0.0.1:${port}` && origin !== `http://localhost:${port}`) {
2809
+ if (req.method !== 'GET' && origin && origin !== `http://127.0.0.1:${bound}` && origin !== `http://localhost:${bound}`) {
2701
2810
  res.writeHead(403, { 'Content-Type': 'text/plain; charset=utf-8' });
2702
2811
  res.end('No.');
2703
2812
  return;
@@ -3173,7 +3282,29 @@ const server = createServer(async (req, res) => {
3173
3282
  // what fills in `sponsored_by` and therefore what lets the fleet work out
3174
3283
  // who leads. A code minted with the account key would arrive sponsored by
3175
3284
  // nobody -- a root, silently.
3176
- const inviter = identities.find((i) => i.credential && i.key === (self && self.key));
3285
+ /*
3286
+ The member of THE CHANNEL BEING INVITED INTO, not the machine's idea of
3287
+ itself. `self` is resolved once at startup against the default channel, so
3288
+ using it here meant an invitation to any other channel was extended by
3289
+ somebody who is not in it -- which the API rightly refuses, with a message
3290
+ about the channel rather than about the inviter, so it read as a missing
3291
+ permission rather than as the wrong signature.
3292
+
3293
+ Falls back to `self` when the channel is not one of the known ones, which
3294
+ is the old behaviour for the only case it was ever right for.
3295
+ */
3296
+ const into = channelFor(payload.channel);
3297
+ const wanted = into?.holder ?? (self && self.key);
3298
+ /*
3299
+ Searched across every holder, not just the live ones. `identities` is what
3300
+ this machine currently IS; the channels it can open come from
3301
+ everyHolder(), which includes identities that were superseded and still
3302
+ hold a credential. The Sandbox channel is exactly that case -- it is
3303
+ opened by an identity this agent used to be -- so looking only at the live
3304
+ list found nobody and reported "connect this project first" about a
3305
+ project that was already connected.
3306
+ */
3307
+ const inviter = everyHolder().find((i) => i.credential && i.key === wanted);
3177
3308
  if (!inviter) {
3178
3309
  res.writeHead(400, { 'Content-Type': 'application/json' });
3179
3310
  res.end(
@@ -3591,11 +3722,17 @@ const server = createServer(async (req, res) => {
3591
3722
  * NOW -- a row written to disk as fresh is stale an hour later, and a
3592
3723
  * cached flag would be the same frozen answer one level down.
3593
3724
  */
3594
- body.messages = merged.map((m) =>
3725
+ const marked = merged.map((m) =>
3595
3726
  (m.pending ?? 0) > 0 && Date.now() - Date.parse(m.created_at) >= CHASE_FOR
3596
3727
  ? { ...m, stale: true }
3597
3728
  : m,
3598
3729
  );
3730
+
3731
+ // Answers last, so a row carries both what became of it and what came
3732
+ // back. Not written to history: an answer can arrive after the row is
3733
+ // stored, and a cached copy would freeze exactly the way the delivery
3734
+ // counts did.
3735
+ body.messages = await withAnswers(on.key, marked);
3599
3736
  // Every channel this dashboard can open, so the page can offer them. The
3600
3737
  // key never leaves this process -- only the ref and the name.
3601
3738
 
@@ -3783,7 +3920,7 @@ server.listen(port, '127.0.0.1', () => {
3783
3920
  // whenever PORT is 0 -- which is how anything automated starts a server
3784
3921
  // without picking a number and hoping -- and printing the request rather
3785
3922
  // than the result hands out a link to port 0, which connects to nothing.
3786
- const bound = server.address()?.port ?? port;
3923
+ bound = server.address()?.port ?? port;
3787
3924
  console.error(`Watching ${baseUrl} on http://127.0.0.1:${bound}/?t=${token}`);
3788
3925
  console.error('Loopback only, and the link carries a one-run token: it can now send and answer.');
3789
3926
  console.error('The key stays in this process; the page only ever talks to this server.');