@agentsignalnet/claude-plugin 0.2.61 → 0.2.62
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.
- package/.claude-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/scripts/chat-viewer.mjs +141 -24
package/package.json
CHANGED
package/scripts/chat-viewer.mjs
CHANGED
|
@@ -143,6 +143,14 @@ 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
|
+
|
|
146
154
|
/**
|
|
147
155
|
* Servers configured in ~/.claude.json that hold a key.
|
|
148
156
|
*
|
|
@@ -1052,11 +1060,37 @@ const PAGE = `<!doctype html>
|
|
|
1052
1060
|
|
|
1053
1061
|
// The other agents, as links. Rendered once: the roster changes when somebody
|
|
1054
1062
|
// joins, which is rare enough that re-reading it every two seconds is waste.
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1063
|
+
/**
|
|
1064
|
+
* URLS CARRY NOTHING SECRET ANY MORE.
|
|
1065
|
+
*
|
|
1066
|
+
* The token was appended to every request and every link, because it was the
|
|
1067
|
+
* only thing the server would accept. It is a cookie now, set on the first
|
|
1068
|
+
* visit and sent by the browser on its own, so a path is just a path: the
|
|
1069
|
+
* address bar reads http://127.0.0.1:8899, links can be followed, and
|
|
1070
|
+
* nothing here has to remember to re-attach a credential.
|
|
1071
|
+
*
|
|
1072
|
+
* Kept as a function rather than deleted at every call site: there is one
|
|
1073
|
+
* place to put a query parameter back if one is ever needed again, and the
|
|
1074
|
+
* call sites already read as "the URL for this".
|
|
1075
|
+
*/
|
|
1076
|
+
const q = (path) => path;
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* Take the token out of the address bar, once, on load.
|
|
1080
|
+
*
|
|
1081
|
+
* The server has already turned it into a cookie by the time this runs, so
|
|
1082
|
+
* the copy in the URL is spent. Leaving it there would keep a live one-run
|
|
1083
|
+
* credential in the address bar, in history, and in the referrer of anything
|
|
1084
|
+
* this page links to -- which is most of the reason for moving it.
|
|
1085
|
+
*
|
|
1086
|
+
* replaceState rather than a redirect: no second request, no entry in the
|
|
1087
|
+
* back stack, and nothing to go wrong for a client that is not a browser.
|
|
1088
|
+
*/
|
|
1089
|
+
if (new URLSearchParams(location.search).get('t')) {
|
|
1090
|
+
const clean = new URL(location.href);
|
|
1091
|
+
clean.searchParams.delete('t');
|
|
1092
|
+
history.replaceState(null, '', clean.pathname + clean.search);
|
|
1093
|
+
}
|
|
1060
1094
|
|
|
1061
1095
|
/** Every channel the server can open, from the poll. */
|
|
1062
1096
|
let CHANNELS = [];
|
|
@@ -1140,12 +1174,11 @@ const PAGE = `<!doctype html>
|
|
|
1140
1174
|
return ['stale', Math.floor(hours / 24) + 'd ago'];
|
|
1141
1175
|
};
|
|
1142
1176
|
|
|
1143
|
-
//
|
|
1144
|
-
//
|
|
1145
|
-
//
|
|
1146
|
-
//
|
|
1147
|
-
//
|
|
1148
|
-
// pasted /a/<agent>?t=… still works.
|
|
1177
|
+
// THE HREFS ARE REAL AND CARRY NOTHING SECRET. They used to be deliberately inert,
|
|
1178
|
+
// because the token could not go in the markup and a link without it answered "Not
|
|
1179
|
+
// found." The credential is a cookie now, so a plain /a/<agent> works cold, in a new
|
|
1180
|
+
// tab, or pasted to yourself — and these are ordinary links again. data-agent is still
|
|
1181
|
+
// what the click handler reads, so an in-page click filters without a request.
|
|
1149
1182
|
const entry = (a) => {
|
|
1150
1183
|
const name = who(a) || a.key;
|
|
1151
1184
|
const [state, when] = since(a.last_seen_at);
|
|
@@ -1255,9 +1288,8 @@ const PAGE = `<!doctype html>
|
|
|
1255
1288
|
* A real link rather than in-page filtering, unlike the agent nav below.
|
|
1256
1289
|
* Switching channel changes which KEY the server polls with and which
|
|
1257
1290
|
* history file it reads, so it is a different conversation rather than a
|
|
1258
|
-
* subset of this one -- and reloading is honest about that.
|
|
1259
|
-
* carried through
|
|
1260
|
-
* answer "Not found" before they stopped being links at all.
|
|
1291
|
+
* subset of this one -- and reloading is honest about that. Nothing has to
|
|
1292
|
+
* be carried through any more: the cookie authenticates the reload.
|
|
1261
1293
|
*/
|
|
1262
1294
|
/**
|
|
1263
1295
|
* ONE TREE: every channel, each opening to show who is in it.
|
|
@@ -2252,11 +2284,10 @@ const PAGE = `<!doctype html>
|
|
|
2252
2284
|
}
|
|
2253
2285
|
|
|
2254
2286
|
// ⚠ EVERY CLICK IS INTERCEPTED, modified ones included, and that is deliberate rather than
|
|
2255
|
-
// careless.
|
|
2256
|
-
//
|
|
2257
|
-
//
|
|
2258
|
-
//
|
|
2259
|
-
// address bar, which has the token.
|
|
2287
|
+
// careless. It used to swallow EVERY click including cmd- and middle-clicks, because the
|
|
2288
|
+
// href could not carry the token and a new tab would have opened on the guard's flat "Not
|
|
2289
|
+
// found." That is no longer true: the cookie authenticates a new tab exactly like this one,
|
|
2290
|
+
// so a modified click is let through to the browser and does what it looks like it does.
|
|
2260
2291
|
document.getElementById('who-nav').addEventListener('click', (event) => {
|
|
2261
2292
|
// The twisty opens and closes without going anywhere. Checked first
|
|
2262
2293
|
// because it sits inside the same row as the link beside it.
|
|
@@ -2270,6 +2301,13 @@ const PAGE = `<!doctype html>
|
|
|
2270
2301
|
const link = event.target.closest('a');
|
|
2271
2302
|
if (!link) return;
|
|
2272
2303
|
|
|
2304
|
+
// Cmd, ctrl, shift, alt, or anything that is not the primary button: the
|
|
2305
|
+
// person asked the BROWSER to do something with this link. Filtering in
|
|
2306
|
+
// place instead would silently ignore them.
|
|
2307
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0) {
|
|
2308
|
+
return;
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2273
2311
|
/**
|
|
2274
2312
|
* AN AGENT IN ANOTHER CHANNEL IS A NAVIGATION, not a filter.
|
|
2275
2313
|
*
|
|
@@ -2393,15 +2431,94 @@ const server = createServer(async (req, res) => {
|
|
|
2393
2431
|
// an origin it can parse.
|
|
2394
2432
|
const url = new URL(req.url, `http://localhost:${port}`);
|
|
2395
2433
|
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2434
|
+
/**
|
|
2435
|
+
* THE TOKEN IS SPENT ONCE AND THEN LIVES IN A COOKIE.
|
|
2436
|
+
*
|
|
2437
|
+
* It used to ride in the query string on every request, which worked and
|
|
2438
|
+
* made every URL unshareable, unbookmarkable and ugly -- and put a live
|
|
2439
|
+
* credential in the address bar, in browser history, and in the referrer of
|
|
2440
|
+
* anything the page ever linked to.
|
|
2441
|
+
*
|
|
2442
|
+
* So the first visit exchanges it: the link that gets printed still carries
|
|
2443
|
+
* ?t=, the server sets a cookie and redirects to the same page without it,
|
|
2444
|
+
* and from then on the address is just http://127.0.0.1:8899 and you can
|
|
2445
|
+
* navigate around it normally.
|
|
2446
|
+
*
|
|
2447
|
+
* WHAT STOPS THIS BEING WEAKER. The cookie is the same one-run secret, so
|
|
2448
|
+
* another process on this machine still cannot read the channel: it has no
|
|
2449
|
+
* cookie and no token, and gets the same flat 404. What a cookie adds that a
|
|
2450
|
+
* query parameter did not is the risk that some OTHER page in the browser
|
|
2451
|
+
* makes requests with it attached -- this server can send messages, so that
|
|
2452
|
+
* would matter. Three things answer it:
|
|
2453
|
+
*
|
|
2454
|
+
* • SameSite=Strict, so the browser does not attach it to anything
|
|
2455
|
+
* originating elsewhere, including a top-level navigation from another
|
|
2456
|
+
* site.
|
|
2457
|
+
* • HttpOnly, so a script on any page cannot read the value even if it
|
|
2458
|
+
* could reach it.
|
|
2459
|
+
* • An Origin check on everything that is not a GET, below.
|
|
2460
|
+
*
|
|
2461
|
+
* A wrong or missing credential is still a flat 404 with no hint about what
|
|
2462
|
+
* is here: a page that says "unauthorised, this is the AgentSignal viewer"
|
|
2463
|
+
* tells a scanner exactly what it found.
|
|
2464
|
+
*/
|
|
2465
|
+
const cookies = String(req.headers.cookie ?? '')
|
|
2466
|
+
.split(';')
|
|
2467
|
+
.reduce((all, pair) => {
|
|
2468
|
+
const at = pair.indexOf('=');
|
|
2469
|
+
if (at > 0) all[pair.slice(0, at).trim()] = pair.slice(at + 1).trim();
|
|
2470
|
+
return all;
|
|
2471
|
+
}, {});
|
|
2472
|
+
|
|
2473
|
+
const presented =
|
|
2474
|
+
url.searchParams.get('t') === token ||
|
|
2475
|
+
req.headers['x-agentsignal-viewer'] === token ||
|
|
2476
|
+
cookies[COOKIE] === token;
|
|
2477
|
+
|
|
2478
|
+
if (!presented) {
|
|
2400
2479
|
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
2401
2480
|
res.end('Not found.');
|
|
2402
2481
|
return;
|
|
2403
2482
|
}
|
|
2404
2483
|
|
|
2484
|
+
/**
|
|
2485
|
+
* CROSS-ORIGIN WRITES ARE REFUSED, cookie or no cookie.
|
|
2486
|
+
*
|
|
2487
|
+
* SameSite should mean this never fires. It is here because "should" is
|
|
2488
|
+
* doing a lot of work in a sentence about a server that can page somebody's
|
|
2489
|
+
* phone, and because an Origin that is not ours is never a request this page
|
|
2490
|
+
* made. Absent is fine and normal -- same-origin GETs and many fetches send
|
|
2491
|
+
* no Origin at all.
|
|
2492
|
+
*/
|
|
2493
|
+
const origin = req.headers.origin;
|
|
2494
|
+
if (req.method !== 'GET' && origin && origin !== `http://127.0.0.1:${port}` && origin !== `http://localhost:${port}`) {
|
|
2495
|
+
res.writeHead(403, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
2496
|
+
res.end('No.');
|
|
2497
|
+
return;
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2500
|
+
/**
|
|
2501
|
+
* Spend the token by handing back a cookie WITH the page, not by redirecting
|
|
2502
|
+
* to it.
|
|
2503
|
+
*
|
|
2504
|
+
* The first version redirected to the clean address. In a browser that is
|
|
2505
|
+
* fine; for anything that follows redirects without keeping cookies -- curl,
|
|
2506
|
+
* a script, the tests -- it turned the printed link into a 404: the redirect
|
|
2507
|
+
* was followed, the cookie was not kept, and the second request had no
|
|
2508
|
+
* credential at all. The printed link has to work for those too.
|
|
2509
|
+
*
|
|
2510
|
+
* So the page is served as normal with a Set-Cookie beside it, and the page
|
|
2511
|
+
* tidies its own address bar once it loads. Same destination, and nothing
|
|
2512
|
+
* that follows a link ends up worse off than before.
|
|
2513
|
+
*
|
|
2514
|
+
* No Secure attribute: this is http on loopback, and Secure would stop the
|
|
2515
|
+
* cookie being stored at all.
|
|
2516
|
+
*/
|
|
2517
|
+
const grant =
|
|
2518
|
+
url.searchParams.get('t') === token && req.method === 'GET' && isPage(url.pathname)
|
|
2519
|
+
? { 'Set-Cookie': `${COOKIE}=${token}; Path=/; HttpOnly; SameSite=Strict` }
|
|
2520
|
+
: {};
|
|
2521
|
+
|
|
2405
2522
|
// WHAT THIS MACHINE IS. The question people keep having to reconstruct by
|
|
2406
2523
|
// hand: which agents live here, which project each belongs to, and which
|
|
2407
2524
|
// account that puts them in. It is read straight off disk, so it is what the
|
|
@@ -3301,7 +3418,7 @@ const server = createServer(async (req, res) => {
|
|
|
3301
3418
|
// of a path rather than a port: several agents run at once, and a port each
|
|
3302
3419
|
// means a port to remember each and a viewer to start each.
|
|
3303
3420
|
if (url.pathname === '/' || url.pathname.startsWith('/a/')) {
|
|
3304
|
-
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
3421
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', ...grant });
|
|
3305
3422
|
res.end(PAGE);
|
|
3306
3423
|
return;
|
|
3307
3424
|
}
|