@agentsignalnet/claude-plugin 0.2.61 → 0.2.63

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.61",
4
+ "version": "0.2.63",
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.61",
3
+ "version": "0.2.63",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -143,6 +143,56 @@ const port = Number(process.env.PORT ?? 8899);
143
143
  */
144
144
  const token = randomUUID();
145
145
 
146
+ /** Where the token lives after the first visit. Namespaced: localhost is shared. */
147
+ const COOKIE = 'agentsignal_viewer';
148
+
149
+ /** The routes a person navigates to, as opposed to the ones the page polls. */
150
+ function isPage(pathname) {
151
+ return pathname === '/' || pathname.startsWith('/a/');
152
+ }
153
+
154
+ /**
155
+ * What somebody sees when they arrive without the link.
156
+ *
157
+ * IT NAMES NOTHING. Not the product, not the account, not a channel or a
158
+ * handle, and not the word for what this is. Every one of those would be a
159
+ * fact handed to whoever asked without a credential, and none of them is
160
+ * needed to answer the only question the person actually has, which is "why
161
+ * is this refusing me and where do I get in".
162
+ *
163
+ * That restraint is load-bearing rather than decorative: a test asserts the
164
+ * refusal body does not match /agentsignal|viewer|token|unauthoris/, and it
165
+ * predates this page. Keeping the wording inside that line is what makes this
166
+ * an explanation rather than a weakening of the front door.
167
+ *
168
+ * Styled to match the light theme rather than left as browser default, since
169
+ * an unstyled wall of text reads as a crash page and the point is to look like
170
+ * a considered answer.
171
+ */
172
+ function unlockPage() {
173
+ return [
174
+ '<!doctype html><html lang="en"><head><meta charset="utf-8">',
175
+ '<meta name="viewport" content="width=device-width,initial-scale=1">',
176
+ '<title>Dashboard</title><style>',
177
+ 'body{margin:0;min-height:100vh;display:grid;place-items:center;background:#f7f7f5;',
178
+ 'color:#1b1b19;font:15px/1.6 ui-sans-serif,-apple-system,system-ui,sans-serif}',
179
+ 'main{max-width:34rem;padding:2rem}',
180
+ 'h1{font-size:1.15rem;margin:0 0 .75rem}',
181
+ 'p{margin:0 0 .75rem;color:#3d3d38}',
182
+ 'code{background:#ecece7;padding:.15rem .35rem;border-radius:4px;',
183
+ 'font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace}',
184
+ '</style></head><body><main>',
185
+ '<h1>This dashboard needs its link</h1>',
186
+ '<p>It is running. It is refusing because this browser has not been given the ',
187
+ 'one-run link, which is printed by the command that started it and only has to ',
188
+ 'be opened once — after that this plain address works.</p>',
189
+ '<p>Look in the terminal it was started from, for the line beginning ',
190
+ '<code>Watching</code>. To print a fresh link, stop it and start it again; a new ',
191
+ 'one is minted per run, so the old link is already dead.</p>',
192
+ '</main></body></html>',
193
+ ].join('');
194
+ }
195
+
146
196
  /**
147
197
  * Servers configured in ~/.claude.json that hold a key.
148
198
  *
@@ -1052,11 +1102,37 @@ const PAGE = `<!doctype html>
1052
1102
 
1053
1103
  // The other agents, as links. Rendered once: the roster changes when somebody
1054
1104
  // joins, which is rare enough that re-reading it every two seconds is waste.
1055
- // The token this page was opened with, put back on every request. Kept out
1056
- // of the markup: it is in the address bar either way, but a value in the DOM
1057
- // is one an extension or a stray script can read without navigating.
1058
- const T = new URLSearchParams(location.search).get('t') || '';
1059
- const q = (path) => path + (path.includes('?') ? '&' : '?') + 't=' + encodeURIComponent(T);
1105
+ /**
1106
+ * URLS CARRY NOTHING SECRET ANY MORE.
1107
+ *
1108
+ * The token was appended to every request and every link, because it was the
1109
+ * only thing the server would accept. It is a cookie now, set on the first
1110
+ * visit and sent by the browser on its own, so a path is just a path: the
1111
+ * address bar reads http://127.0.0.1:8899, links can be followed, and
1112
+ * nothing here has to remember to re-attach a credential.
1113
+ *
1114
+ * Kept as a function rather than deleted at every call site: there is one
1115
+ * place to put a query parameter back if one is ever needed again, and the
1116
+ * call sites already read as "the URL for this".
1117
+ */
1118
+ const q = (path) => path;
1119
+
1120
+ /**
1121
+ * Take the token out of the address bar, once, on load.
1122
+ *
1123
+ * The server has already turned it into a cookie by the time this runs, so
1124
+ * the copy in the URL is spent. Leaving it there would keep a live one-run
1125
+ * credential in the address bar, in history, and in the referrer of anything
1126
+ * this page links to -- which is most of the reason for moving it.
1127
+ *
1128
+ * replaceState rather than a redirect: no second request, no entry in the
1129
+ * back stack, and nothing to go wrong for a client that is not a browser.
1130
+ */
1131
+ if (new URLSearchParams(location.search).get('t')) {
1132
+ const clean = new URL(location.href);
1133
+ clean.searchParams.delete('t');
1134
+ history.replaceState(null, '', clean.pathname + clean.search);
1135
+ }
1060
1136
 
1061
1137
  /** Every channel the server can open, from the poll. */
1062
1138
  let CHANNELS = [];
@@ -1140,12 +1216,11 @@ const PAGE = `<!doctype html>
1140
1216
  return ['stale', Math.floor(hours / 24) + 'd ago'];
1141
1217
  };
1142
1218
 
1143
- // ⚠ THE HREFS STAY TOKEN-FREE. The token authorises send and answer on a viewer holding a
1144
- // real API key, and it is deliberately kept out of the DOM — the address bar has it either
1145
- // way, but a value in the markup is one an extension or a stray script can read without
1146
- // navigating. data-agent is what the click handler reads instead; the href is there so
1147
- // these are real links (focusable, with a status-bar target) and so a cold load of a
1148
- // pasted /a/<agent>?t=… still works.
1219
+ // THE HREFS ARE REAL AND CARRY NOTHING SECRET. They used to be deliberately inert,
1220
+ // because the token could not go in the markup and a link without it answered "Not
1221
+ // found." The credential is a cookie now, so a plain /a/<agent> works cold, in a new
1222
+ // tab, or pasted to yourself — and these are ordinary links again. data-agent is still
1223
+ // what the click handler reads, so an in-page click filters without a request.
1149
1224
  const entry = (a) => {
1150
1225
  const name = who(a) || a.key;
1151
1226
  const [state, when] = since(a.last_seen_at);
@@ -1255,9 +1330,8 @@ const PAGE = `<!doctype html>
1255
1330
  * A real link rather than in-page filtering, unlike the agent nav below.
1256
1331
  * Switching channel changes which KEY the server polls with and which
1257
1332
  * history file it reads, so it is a different conversation rather than a
1258
- * subset of this one -- and reloading is honest about that. The token is
1259
- * carried through, because dropping it is what made the agent links
1260
- * answer "Not found" before they stopped being links at all.
1333
+ * subset of this one -- and reloading is honest about that. Nothing has to
1334
+ * be carried through any more: the cookie authenticates the reload.
1261
1335
  */
1262
1336
  /**
1263
1337
  * ONE TREE: every channel, each opening to show who is in it.
@@ -2252,11 +2326,10 @@ const PAGE = `<!doctype html>
2252
2326
  }
2253
2327
 
2254
2328
  // ⚠ EVERY CLICK IS INTERCEPTED, modified ones included, and that is deliberate rather than
2255
- // careless. The href cannot carry the token — see the note where the nav is built — so
2256
- // letting a cmd-click or middle-click through would open a tab that gets the guard's flat
2257
- // "Not found.", which is the whole bug. Every target here is reachable in place, so there is
2258
- // nothing a new tab could show that this does not. Somebody who wants one can copy the
2259
- // address bar, which has the token.
2329
+ // careless. It used to swallow EVERY click including cmd- and middle-clicks, because the
2330
+ // href could not carry the token and a new tab would have opened on the guard's flat "Not
2331
+ // found." That is no longer true: the cookie authenticates a new tab exactly like this one,
2332
+ // so a modified click is let through to the browser and does what it looks like it does.
2260
2333
  document.getElementById('who-nav').addEventListener('click', (event) => {
2261
2334
  // The twisty opens and closes without going anywhere. Checked first
2262
2335
  // because it sits inside the same row as the link beside it.
@@ -2270,6 +2343,13 @@ const PAGE = `<!doctype html>
2270
2343
  const link = event.target.closest('a');
2271
2344
  if (!link) return;
2272
2345
 
2346
+ // Cmd, ctrl, shift, alt, or anything that is not the primary button: the
2347
+ // person asked the BROWSER to do something with this link. Filtering in
2348
+ // place instead would silently ignore them.
2349
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0) {
2350
+ return;
2351
+ }
2352
+
2273
2353
  /**
2274
2354
  * AN AGENT IN ANOTHER CHANNEL IS A NAVIGATION, not a filter.
2275
2355
  *
@@ -2393,15 +2473,126 @@ const server = createServer(async (req, res) => {
2393
2473
  // an origin it can parse.
2394
2474
  const url = new URL(req.url, `http://localhost:${port}`);
2395
2475
 
2396
- // Before anything else. A wrong or missing token is a flat refusal with no
2397
- // hint about what is here -- a page that says "unauthorised, this is the
2398
- // AgentSignal viewer" tells a scanner exactly what it found.
2399
- if (url.searchParams.get('t') !== token && req.headers['x-agentsignal-viewer'] !== token) {
2476
+ /**
2477
+ * THE TOKEN IS SPENT ONCE AND THEN LIVES IN A COOKIE.
2478
+ *
2479
+ * It used to ride in the query string on every request, which worked and
2480
+ * made every URL unshareable, unbookmarkable and ugly -- and put a live
2481
+ * credential in the address bar, in browser history, and in the referrer of
2482
+ * anything the page ever linked to.
2483
+ *
2484
+ * So the first visit exchanges it: the link that gets printed still carries
2485
+ * ?t=, the server sets a cookie and redirects to the same page without it,
2486
+ * and from then on the address is just http://127.0.0.1:8899 and you can
2487
+ * navigate around it normally.
2488
+ *
2489
+ * WHAT STOPS THIS BEING WEAKER. The cookie is the same one-run secret, so
2490
+ * another process on this machine still cannot read the channel: it has no
2491
+ * cookie and no token, and gets the same flat 404. What a cookie adds that a
2492
+ * query parameter did not is the risk that some OTHER page in the browser
2493
+ * makes requests with it attached -- this server can send messages, so that
2494
+ * would matter. Three things answer it:
2495
+ *
2496
+ * • SameSite=Strict, so the browser does not attach it to anything
2497
+ * originating elsewhere, including a top-level navigation from another
2498
+ * site.
2499
+ * • HttpOnly, so a script on any page cannot read the value even if it
2500
+ * could reach it.
2501
+ * • An Origin check on everything that is not a GET, below.
2502
+ *
2503
+ * A wrong or missing credential is a flat 404 for everything EXCEPT a page
2504
+ * a browser asked for, which gets a short note saying a link is needed. See
2505
+ * `unlockPage` for why that exception is worth making and why it gives away
2506
+ * nothing the asker did not already have.
2507
+ */
2508
+ const cookies = String(req.headers.cookie ?? '')
2509
+ .split(';')
2510
+ .reduce((all, pair) => {
2511
+ const at = pair.indexOf('=');
2512
+ if (at > 0) all[pair.slice(0, at).trim()] = pair.slice(at + 1).trim();
2513
+ return all;
2514
+ }, {});
2515
+
2516
+ const presented =
2517
+ url.searchParams.get('t') === token ||
2518
+ req.headers['x-agentsignal-viewer'] === token ||
2519
+ cookies[COOKIE] === token;
2520
+
2521
+ if (!presented) {
2522
+ // A LOCKED DOOR CAN STILL SAY IT IS A DOOR.
2523
+ //
2524
+ // Every unauthenticated request used to get the same flat 404, so that a
2525
+ // scanner learned nothing from one. For a page a person typed, that is the
2526
+ // wrong trade: `http://127.0.0.1:8899` is exactly what somebody types after
2527
+ // bookmarking the clean address, or coming back in another browser, or
2528
+ // clearing cookies -- and a bare 404 is indistinguishable from a dead
2529
+ // server. Somebody hit it and reported the viewer broken; it was working
2530
+ // perfectly and had no way to say so.
2531
+ //
2532
+ // The secrecy was buying almost nothing anyway. Reading this body needs a
2533
+ // same-origin read, which means a process on this machine -- and a local
2534
+ // process can already see the port with `lsof`, so it learns nothing here
2535
+ // it could not learn there. A hostile PAGE in the browser cannot read a
2536
+ // cross-origin response at all; it could always detect that something
2537
+ // answers on the port, and still cannot see a word of this.
2538
+ //
2539
+ // So: pages explain, everything else stays flat. No channel names, no
2540
+ // account, no token -- nothing about WHOSE viewer this is, only that a
2541
+ // link is needed and where the link comes from.
2542
+ if (req.method === 'GET' && isPage(url.pathname)) {
2543
+ // no-store because this is served at the same address the real page will
2544
+ // be. A cached 401 at `/` would greet the person again after the cookie
2545
+ // was granted, which is the original complaint with extra steps.
2546
+ res.writeHead(401, {
2547
+ 'Content-Type': 'text/html; charset=utf-8',
2548
+ 'Cache-Control': 'no-store',
2549
+ });
2550
+ res.end(unlockPage());
2551
+ return;
2552
+ }
2400
2553
  res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
2401
2554
  res.end('Not found.');
2402
2555
  return;
2403
2556
  }
2404
2557
 
2558
+ /**
2559
+ * CROSS-ORIGIN WRITES ARE REFUSED, cookie or no cookie.
2560
+ *
2561
+ * SameSite should mean this never fires. It is here because "should" is
2562
+ * doing a lot of work in a sentence about a server that can page somebody's
2563
+ * phone, and because an Origin that is not ours is never a request this page
2564
+ * made. Absent is fine and normal -- same-origin GETs and many fetches send
2565
+ * no Origin at all.
2566
+ */
2567
+ const origin = req.headers.origin;
2568
+ if (req.method !== 'GET' && origin && origin !== `http://127.0.0.1:${port}` && origin !== `http://localhost:${port}`) {
2569
+ res.writeHead(403, { 'Content-Type': 'text/plain; charset=utf-8' });
2570
+ res.end('No.');
2571
+ return;
2572
+ }
2573
+
2574
+ /**
2575
+ * Spend the token by handing back a cookie WITH the page, not by redirecting
2576
+ * to it.
2577
+ *
2578
+ * The first version redirected to the clean address. In a browser that is
2579
+ * fine; for anything that follows redirects without keeping cookies -- curl,
2580
+ * a script, the tests -- it turned the printed link into a 404: the redirect
2581
+ * was followed, the cookie was not kept, and the second request had no
2582
+ * credential at all. The printed link has to work for those too.
2583
+ *
2584
+ * So the page is served as normal with a Set-Cookie beside it, and the page
2585
+ * tidies its own address bar once it loads. Same destination, and nothing
2586
+ * that follows a link ends up worse off than before.
2587
+ *
2588
+ * No Secure attribute: this is http on loopback, and Secure would stop the
2589
+ * cookie being stored at all.
2590
+ */
2591
+ const grant =
2592
+ url.searchParams.get('t') === token && req.method === 'GET' && isPage(url.pathname)
2593
+ ? { 'Set-Cookie': `${COOKIE}=${token}; Path=/; HttpOnly; SameSite=Strict` }
2594
+ : {};
2595
+
2405
2596
  // WHAT THIS MACHINE IS. The question people keep having to reconstruct by
2406
2597
  // hand: which agents live here, which project each belongs to, and which
2407
2598
  // account that puts them in. It is read straight off disk, so it is what the
@@ -3301,7 +3492,7 @@ const server = createServer(async (req, res) => {
3301
3492
  // of a path rather than a port: several agents run at once, and a port each
3302
3493
  // means a port to remember each and a viewer to start each.
3303
3494
  if (url.pathname === '/' || url.pathname.startsWith('/a/')) {
3304
- res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
3495
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', ...grant });
3305
3496
  res.end(PAGE);
3306
3497
  return;
3307
3498
  }