@agentsignalnet/claude-plugin 0.2.56 → 0.2.58

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.56",
4
+ "version": "0.2.58",
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/.mcp.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "mcpServers": {
3
3
  "agentsignal": {
4
4
  "command": "npx",
5
- "args": ["-y", "@agentsignalnet/mcp@0.2.53"],
5
+ "args": ["-y", "@agentsignalnet/mcp@0.2.54"],
6
6
  "env": {
7
7
  "AGENTSIGNAL_API_KEY": "${user_config.api_key}",
8
8
  "AGENTSIGNAL_JOIN_TOKEN": "${user_config.join_token}",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentsignalnet/claude-plugin",
3
- "version": "0.2.56",
3
+ "version": "0.2.58",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -165,36 +165,137 @@ const identities = identitiesHere(baseUrl);
165
165
  * Announced, like the borrowed one, because a viewer that goes looking for
166
166
  * credentials silently is indistinguishable from one that steals them.
167
167
  */
168
- if (!apiKey) {
169
- const holders = identities.filter((who) => who.api_key_ref || who.api_key);
170
- const distinct = new Set(holders.map((who) => who.api_key_ref ?? who.api_key));
171
- if (distinct.size > 1) {
168
+ /**
169
+ * EVERY CHANNEL THIS MACHINE CAN OPEN, not one of them.
170
+ *
171
+ * This used to refuse: two different keys meant two channels, and rather than
172
+ * choose wrong it stopped and asked for AGENTSIGNAL_API_KEY. Choosing wrong
173
+ * would indeed be bad -- it shows somebody else's conversation -- but refusing
174
+ * is not the only alternative to guessing. Showing both and saying which is
175
+ * which is the other, and it is what somebody who joined two channels
176
+ * actually wanted.
177
+ *
178
+ * ARCHIVED IDENTITIES COUNT. Joining a second channel mints a new recipient,
179
+ * because a recipient belongs to one channel, and the previous identity is
180
+ * moved to `previous/` rather than deleted -- deliberately, so nothing is
181
+ * lost. That archive is therefore exactly where the FIRST channel's key lives
182
+ * once a second channel has been joined, which is the moment somebody most
183
+ * wants to see both. Read here, never written, and any key the API refuses is
184
+ * dropped quietly at startup rather than taken as a reason not to run.
185
+ */
186
+ /**
187
+ * Which channel a key opens, read off the key.
188
+ *
189
+ * Local, so the rail can name the channels before a single request is made,
190
+ * and so two keys for one channel can be recognised as one entry rather than
191
+ * shown as two.
192
+ */
193
+ function channelOfKey(key) {
194
+ const parts = String(key).split('_');
195
+ return parts.length >= 4 && parts[0] === 'as' && (parts[1] === 'live' || parts[1] === 'test')
196
+ ? parts[2]
197
+ : null;
198
+ }
199
+
200
+ function keyOf(holder) {
201
+ try {
202
+ return holder.api_key_ref ? readKeychain(holder.api_key_ref) : holder.api_key;
203
+ } catch (error) {
204
+ // Named rather than swallowed. A key that exists and cannot be read is a
205
+ // locked keychain, not a missing key, and the fix is different.
172
206
  console.error(
173
- `Agents here hold different channel keys (${holders
174
- .map((who) => who.handle ?? who.key)
175
- .join(', ')}).\n` +
176
- 'Those are different channels, so set AGENTSIGNAL_API_KEY to say which.',
207
+ `${holder.handle ?? holder.key} holds a key at ${holder.api_key_ref}, ` +
208
+ `and it could not be read (${error.message}). That channel is not shown.`,
177
209
  );
178
- process.exit(1);
210
+ return null;
179
211
  }
180
- const holder = holders[0];
181
- if (holder) {
212
+ }
213
+
214
+ /** Identities this machine has been, including the ones it no longer is. */
215
+ function everyHolder() {
216
+ const holders = identities.filter((who) => who.api_key_ref || who.api_key);
217
+ const seen = new Set(holders.map((who) => who.key));
218
+
219
+ for (const who of identities) {
220
+ let names;
182
221
  try {
183
- apiKey = holder.api_key_ref ? readKeychain(holder.api_key_ref) : holder.api_key;
184
- } catch (error) {
185
- // Named rather than swallowed. Falling through to "no key is set" would
186
- // be a lie -- there is one, it is exactly where it says, and the fix is
187
- // to unlock the keychain rather than to go and find a key.
188
- console.error(
189
- `${holder.handle ?? holder.key} holds a key at ${holder.api_key_ref}, ` +
190
- `and it could not be read.\n${error.message}\n` +
191
- 'Unlock the keychain, or set AGENTSIGNAL_API_KEY for this run.',
192
- );
193
- process.exit(1);
222
+ names = readdirSync(join(who.dir, 'previous'));
223
+ } catch {
224
+ continue;
225
+ }
226
+ for (const name of names) {
227
+ if (!name.endsWith('.json')) continue;
228
+ try {
229
+ const past = JSON.parse(readFileSync(join(who.dir, 'previous', name), 'utf8'));
230
+ if (past.base_url !== baseUrl) continue;
231
+ if (!past.api_key && !past.api_key_ref) continue;
232
+ if (seen.has(past.key)) continue;
233
+ seen.add(past.key);
234
+ holders.push({ ...past, dir: who.dir, archived: true });
235
+ } catch {
236
+ /* not an identity */
237
+ }
194
238
  }
239
+ }
240
+ return holders;
241
+ }
242
+
243
+ /**
244
+ * The channels, in the order they will be offered.
245
+ *
246
+ * An explicit AGENTSIGNAL_API_KEY still wins outright: somebody who named a
247
+ * key meant that key, and quietly adding channels beside it would undo the
248
+ * only way there is to say "just this one".
249
+ */
250
+ const channels = [];
251
+
252
+ if (apiKey) {
253
+ channels.push({ key: apiKey, via: 'AGENTSIGNAL_API_KEY', ref: null, name: null });
254
+ } else {
255
+ /**
256
+ * DEDUPED BY CHANNEL, not by key.
257
+ *
258
+ * Every agent gets its OWN key, so two agents this machine has been in the
259
+ * same channel are two different keys opening one conversation -- and keyed
260
+ * by value they both appeared, listing the same channel twice under two
261
+ * handles. The channel is in the key: they are minted
262
+ * as_{live|test}_{channelRef}_{secret}, the same shape a join code has and
263
+ * the same position.
264
+ *
265
+ * A key of an unrecognised shape keys on its own value, which lists it
266
+ * separately rather than silently merging it with something it may not be.
267
+ */
268
+ const byChannel = new Map();
269
+ for (const holder of everyHolder()) {
270
+ const key = keyOf(holder);
271
+ if (!key) continue;
272
+ const ref = channelOfKey(key);
273
+ const at = ref ?? key;
274
+ // First wins, and the live identity is first, so a channel this machine
275
+ // is still in is opened with the key it currently holds rather than with
276
+ // a displaced one that may since have been revoked.
277
+ if (byChannel.has(at)) continue;
278
+ byChannel.set(at, {
279
+ key,
280
+ via: `${holder.handle ?? holder.key}${holder.archived ? ' (previously)' : ''}`,
281
+ // WHERE it came from, kept so startup can say it. A viewer that goes
282
+ // looking for credentials silently is indistinguishable from one that
283
+ // steals them, and naming the holder is not naming the source.
284
+ from: holder.api_key_ref ?? join(holder.dir, holder.archived ? 'previous' : '', 'agent.json'),
285
+ ref,
286
+ name: null,
287
+ });
288
+ }
289
+ channels.push(...byChannel.values());
290
+ // The first is the default, and the tools that act rather than read use it.
291
+ apiKey = channels[0]?.key;
292
+
293
+ if (channels.length) {
195
294
  console.log(
196
- `Using ${holder.handle ?? holder.key}'s own channel key, from ` +
197
- `${holder.api_key_ref ?? join(holder.dir, 'agent.json')}.`,
295
+ channels.length === 1
296
+ ? `Using ${channels[0].via}'s own channel key, from ${channels[0].from}.`
297
+ : `Watching ${channels.length} channels:\n` +
298
+ channels.map((c) => ` ${c.ref ?? 'channel'} — ${c.via}'s key, from ${c.from}`).join('\n'),
198
299
  );
199
300
  }
200
301
  }
@@ -670,7 +771,8 @@ const PAGE = `<!doctype html>
670
771
  </header>
671
772
  <div id="shell">
672
773
  <aside id="side" aria-label="Channel">
673
- <p class="rail-title">Channel</p>
774
+ <div id="channels" hidden><p class="rail-title">Channels</p><nav id="chan-nav"></nav></div>
775
+ <p class="rail-title">In this channel</p>
674
776
  <nav id="who-nav"></nav>
675
777
  <details id="setup"><summary>This machine</summary><div id="setupbody">reading…</div></details>
676
778
  </aside>
@@ -902,7 +1004,10 @@ const PAGE = `<!doctype html>
902
1004
  async function roster() {
903
1005
  let list;
904
1006
  try {
905
- list = await (await fetch(q('/agents'))).json();
1007
+ // Same channel the log is showing, carried from the URL for the same
1008
+ // reason the poll carries it.
1009
+ const on = new URLSearchParams(location.search).get('channel');
1010
+ list = await (await fetch(q('/agents' + (on ? '?channel=' + encodeURIComponent(on) : '')))).json();
906
1011
  } catch {
907
1012
  return;
908
1013
  }
@@ -1039,6 +1144,41 @@ const PAGE = `<!doctype html>
1039
1144
  branch(null, 0);
1040
1145
  }
1041
1146
 
1147
+ /**
1148
+ * The channels this machine can open, when there is more than one.
1149
+ *
1150
+ * HIDDEN AT ONE, because a switcher offering a single choice is furniture:
1151
+ * it takes rail space to say what the header already says. It appears the
1152
+ * moment a second channel exists and not before.
1153
+ *
1154
+ * A real link rather than in-page filtering, unlike the agent nav below.
1155
+ * Switching channel changes which KEY the server polls with and which
1156
+ * history file it reads, so it is a different conversation rather than a
1157
+ * subset of this one -- and reloading is honest about that. The token is
1158
+ * carried through, because dropping it is what made the agent links
1159
+ * answer "Not found" before they stopped being links at all.
1160
+ */
1161
+ function renderChannels(list) {
1162
+ const box = document.getElementById('channels');
1163
+ if (!box) return;
1164
+ if (!list || list.length < 2) {
1165
+ box.hidden = true;
1166
+ return;
1167
+ }
1168
+ box.hidden = false;
1169
+ document.getElementById('chan-nav').innerHTML = list
1170
+ .map((c) => {
1171
+ const href = c.ref ? q('/?channel=' + encodeURIComponent(c.ref)) : q('/');
1172
+ return (
1173
+ '<a href="' + esc(href) + '" class="' + (c.active ? 'on' : '') + '">' +
1174
+ '<span class="stack"><span class="nm">' + esc(c.name || c.ref || 'channel') + '</span>' +
1175
+ (c.ref ? '<small class="alias">' + esc(c.ref) + '</small>' : '') +
1176
+ '</span></a>'
1177
+ );
1178
+ })
1179
+ .join('');
1180
+ }
1181
+
1042
1182
  /** Whether a nav link is the one currently filtering. Key or handle, either may be in the URL. */
1043
1183
  function matchesNav(link) {
1044
1184
  const at = link.dataset.agent ?? '';
@@ -1143,7 +1283,20 @@ const PAGE = `<!doctype html>
1143
1283
  async function tick() {
1144
1284
  let data;
1145
1285
  try {
1146
- data = await (await fetch(q('/messages' + (AGENT ? '?agent=' + encodeURIComponent(AGENT) : '')))).json();
1286
+ /**
1287
+ * The channel comes from the URL, not from memory.
1288
+ *
1289
+ * Switching is a navigation, so the selection lives in location.search
1290
+ * and the poll has to carry it -- without this the page would sit at
1291
+ * /?channel=other while every two seconds asking for, and rendering,
1292
+ * the default channel's traffic. The address bar would say one thing
1293
+ * and the conversation another.
1294
+ */
1295
+ const chan = new URLSearchParams(location.search).get('channel');
1296
+ const params = [];
1297
+ if (AGENT) params.push('agent=' + encodeURIComponent(AGENT));
1298
+ if (chan) params.push('channel=' + encodeURIComponent(chan));
1299
+ data = await (await fetch(q('/messages' + (params.length ? '?' + params.join('&') : '')))).json();
1147
1300
  } catch {
1148
1301
  document.getElementById('dot').style.background = '#f85149';
1149
1302
  return;
@@ -1159,6 +1312,7 @@ const PAGE = `<!doctype html>
1159
1312
 
1160
1313
  document.getElementById('channel').textContent =
1161
1314
  data.channel ? data.channel.name + ' · ' + data.channel.ref : '';
1315
+ renderChannels(data.channels);
1162
1316
  document.getElementById('count').textContent = data.messages.length;
1163
1317
 
1164
1318
  const log = document.getElementById('log');
@@ -1436,7 +1590,15 @@ const PAGE = `<!doctype html>
1436
1590
  const note = document.getElementById('sent');
1437
1591
  if (!to || !say.value.trim()) return;
1438
1592
  note.textContent = 'sending…';
1439
- const result = await post('/send', { to, body: say.value.trim() });
1593
+ // The channel on screen, said explicitly. A message composed under a
1594
+ // Sandbox header and delivered into a different channel is the worst
1595
+ // outcome this switcher could produce, so the view names its own channel
1596
+ // rather than letting the server assume the default.
1597
+ const result = await post('/send', {
1598
+ to,
1599
+ body: say.value.trim(),
1600
+ channel: new URLSearchParams(location.search).get('channel') ?? undefined,
1601
+ });
1440
1602
  if (result.error) {
1441
1603
  note.textContent = result.error;
1442
1604
  return;
@@ -1874,11 +2036,23 @@ const PAGE = `<!doctype html>
1874
2036
  </body>
1875
2037
  </html>`;
1876
2038
 
2039
+ /**
2040
+ * The channel a request is for.
2041
+ *
2042
+ * Matched on ref once known, and otherwise the first -- which is the identity
2043
+ * this machine currently is. An unknown ref falls back rather than erroring:
2044
+ * a stale bookmark should show something, not a stack trace.
2045
+ */
2046
+ function channelFor(ref) {
2047
+ if (!ref) return channels[0];
2048
+ return channels.find((c) => c.ref === ref) ?? channels[0];
2049
+ }
2050
+
1877
2051
  /** One upstream call, one place that turns a non-2xx into something readable. */
1878
- async function upstream(path) {
2052
+ async function upstream(path, key = apiKey) {
1879
2053
  try {
1880
2054
  const response = await fetch(`${baseUrl}${path}`, {
1881
- headers: { Authorization: `Bearer ${apiKey}` },
2055
+ headers: { Authorization: `Bearer ${key}` },
1882
2056
  });
1883
2057
  const body = await response.json();
1884
2058
  return response.ok
@@ -2710,7 +2884,7 @@ const server = createServer(async (req, res) => {
2710
2884
  const body = await upstreamPost(
2711
2885
  '/v1/messages',
2712
2886
  { to: payload.to, body: payload.body, ...(payload.title ? { title: payload.title } : {}) },
2713
- `Bearer ${apiKey}`,
2887
+ `Bearer ${channelFor(payload.channel ?? url.searchParams.get('channel')).key}`,
2714
2888
  );
2715
2889
  res.writeHead(body.error ? 400 : 200, { 'Content-Type': 'application/json' });
2716
2890
  res.end(JSON.stringify(body));
@@ -2732,16 +2906,34 @@ const server = createServer(async (req, res) => {
2732
2906
  * messages newer than a moment that has not happened yet and never see
2733
2907
  * the ones in between.
2734
2908
  */
2735
- const kept = readHistory(channelRef);
2909
+ /**
2910
+ * WHICH CHANNEL, and therefore which key.
2911
+ *
2912
+ * Defaults to the first, which is the identity this machine is now. The
2913
+ * page names the others and links to them; nothing is guessed from the
2914
+ * traffic.
2915
+ */
2916
+ const want = url.searchParams.get('channel');
2917
+ const on = channelFor(want);
2918
+
2919
+ // Per channel, because history is per channel: sharing one `since` across
2920
+ // two would make each ask for messages newer than the other's newest and
2921
+ // leave a hole in whichever is quieter.
2922
+ const kept = readHistory(on.ref ?? channelRef);
2736
2923
  const newest = kept.length ? kept[0].created_at : null;
2737
2924
  const body = await upstream(
2738
2925
  '/v1/messages?limit=100' + (newest ? '&since=' + encodeURIComponent(newest) : ''),
2926
+ on.key,
2739
2927
  );
2740
2928
 
2741
2929
  if (!body.error) {
2742
2930
  // The ref is only known once the API has answered once; until then the
2743
2931
  // history lands in a generic file and is adopted on the next start.
2744
- channelRef = body.channel?.ref ?? channelRef;
2932
+ if (body.channel?.ref) {
2933
+ on.ref = body.channel.ref;
2934
+ on.name = body.channel.name ?? on.name;
2935
+ }
2936
+ channelRef = on.ref ?? channelRef;
2745
2937
 
2746
2938
  const fresh = (body.messages ?? []).map(keepable).filter(Boolean);
2747
2939
  // Deduplicated by id, because `since` is inclusive at the boundary on a
@@ -2749,7 +2941,15 @@ const server = createServer(async (req, res) => {
2749
2941
  const byId = new Map(kept.map((m) => [m.id, m]));
2750
2942
  for (const m of fresh) byId.set(m.id, m);
2751
2943
 
2752
- body.messages = writeHistory(channelRef, [...byId.values()], settings().history_days);
2944
+ body.messages = writeHistory(on.ref ?? channelRef, [...byId.values()], settings().history_days);
2945
+ // Every channel this viewer can open, so the page can offer them. The
2946
+ // key never leaves this process -- only the ref and the name.
2947
+ body.channels = channels.map((c) => ({
2948
+ ref: c.ref,
2949
+ name: c.name ?? c.via,
2950
+ via: c.via,
2951
+ active: c === on,
2952
+ }));
2753
2953
  // What this call actually cost, so the page can say so rather than
2754
2954
  // implying every refresh is free or that every refresh is billed.
2755
2955
  body.fetched = fresh.length;
@@ -2794,7 +2994,12 @@ const server = createServer(async (req, res) => {
2794
2994
  * than kept beside its replacement. Two paths to one value is how the
2795
2995
  * copies in this codebase drift.
2796
2996
  */
2797
- const body = await upstream('/v1/agents');
2997
+ // The SELECTED channel's roster, not the default one's. Without this the
2998
+ // conversation switched and the list of who is in it did not, so the rail
2999
+ // named agents that had never been in the channel on screen -- which reads
3000
+ // as the directory being wrong rather than as the viewer asking the wrong
3001
+ // one.
3002
+ const body = await upstream('/v1/agents', channelFor(url.searchParams.get('channel')).key);
2798
3003
 
2799
3004
 
2800
3005
  res.writeHead(200, { 'Content-Type': 'application/json' });
@@ -2817,6 +3022,41 @@ const server = createServer(async (req, res) => {
2817
3022
 
2818
3023
  resolveSelf();
2819
3024
 
3025
+ /**
3026
+ * Learn what the other channels are CALLED, once, in the background.
3027
+ *
3028
+ * The ref comes free out of the key, but the name does not, and a rail that
3029
+ * lists one channel by name and the rest by whichever handle happens to hold
3030
+ * their key is a rail that looks broken. The active channel names itself on
3031
+ * its first poll; this is for the ones nobody has opened yet.
3032
+ *
3033
+ * `since` set to now so the read comes back EMPTY and is refunded -- the
3034
+ * channel block arrives either way. Naming the rail should not cost a
3035
+ * delivery per channel per start.
3036
+ *
3037
+ * Failures are left alone deliberately: a key that has been revoked since it
3038
+ * was archived simply keeps its ref as a label, and the channel is still
3039
+ * listed rather than vanishing. Finding out it does not work by clicking it
3040
+ * is better than being quietly shown one channel and told nothing.
3041
+ */
3042
+ async function nameChannels() {
3043
+ const now = new Date().toISOString();
3044
+ await Promise.all(
3045
+ // SKIP THE FIRST. It is the one the page opens on, so its first poll names
3046
+ // it for free -- asking here as well is a second request for an answer
3047
+ // already on its way, and it breaks the property that a viewer watching
3048
+ // one channel makes exactly one call to fetch and one to keep up.
3049
+ channels.slice(1).map(async (c) => {
3050
+ if (c.name) return;
3051
+ const body = await upstream(`/v1/messages?limit=1&since=${encodeURIComponent(now)}`, c.key);
3052
+ if (body?.channel?.name) {
3053
+ c.name = body.channel.name;
3054
+ c.ref = body.channel.ref ?? c.ref;
3055
+ }
3056
+ }),
3057
+ );
3058
+ }
3059
+
2820
3060
  server.listen(port, '127.0.0.1', () => {
2821
3061
  // The port the OS actually gave us, not the one asked for. They differ
2822
3062
  // whenever PORT is 0 -- which is how anything automated starts a server
@@ -2826,4 +3066,9 @@ server.listen(port, '127.0.0.1', () => {
2826
3066
  console.error(`Watching ${baseUrl} on http://127.0.0.1:${bound}/?t=${token}`);
2827
3067
  console.error('Loopback only, and the link carries a one-run token: it can now send and answer.');
2828
3068
  console.error('The key stays in this process; the page only ever talks to this server.');
3069
+ // After the link is printed, not before: the viewer should be usable the
3070
+ // moment it says it is, and the names arrive a beat later.
3071
+ nameChannels().catch(() => {
3072
+ /* the rail falls back to refs, which is a label and not a failure */
3073
+ });
2829
3074
  });