@agentsignalnet/claude-plugin 0.2.60 → 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 +193 -40
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.
|
|
@@ -1543,6 +1575,12 @@ const PAGE = `<!doctype html>
|
|
|
1543
1575
|
document.getElementById('dot').style.background = '#3fb950';
|
|
1544
1576
|
SELF = data.self ?? SELF;
|
|
1545
1577
|
|
|
1578
|
+
// BEFORE the error check, for the same reason the server sends it anyway:
|
|
1579
|
+
// the channel you cannot read is the one where you most need the list of
|
|
1580
|
+
// the others. Returning first left the page knowing about two channels and
|
|
1581
|
+
// showing neither.
|
|
1582
|
+
renderChannels(data.channels);
|
|
1583
|
+
|
|
1546
1584
|
if (data.error) {
|
|
1547
1585
|
document.getElementById('log').className = 'empty';
|
|
1548
1586
|
document.getElementById('log').textContent = data.error;
|
|
@@ -1551,7 +1589,6 @@ const PAGE = `<!doctype html>
|
|
|
1551
1589
|
|
|
1552
1590
|
document.getElementById('channel').textContent =
|
|
1553
1591
|
data.channel ? data.channel.name + ' · ' + data.channel.ref : '';
|
|
1554
|
-
renderChannels(data.channels);
|
|
1555
1592
|
document.getElementById('count').textContent = data.messages.length;
|
|
1556
1593
|
|
|
1557
1594
|
const log = document.getElementById('log');
|
|
@@ -2247,11 +2284,10 @@ const PAGE = `<!doctype html>
|
|
|
2247
2284
|
}
|
|
2248
2285
|
|
|
2249
2286
|
// ⚠ EVERY CLICK IS INTERCEPTED, modified ones included, and that is deliberate rather than
|
|
2250
|
-
// careless.
|
|
2251
|
-
//
|
|
2252
|
-
//
|
|
2253
|
-
//
|
|
2254
|
-
// 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.
|
|
2255
2291
|
document.getElementById('who-nav').addEventListener('click', (event) => {
|
|
2256
2292
|
// The twisty opens and closes without going anywhere. Checked first
|
|
2257
2293
|
// because it sits inside the same row as the link beside it.
|
|
@@ -2265,6 +2301,13 @@ const PAGE = `<!doctype html>
|
|
|
2265
2301
|
const link = event.target.closest('a');
|
|
2266
2302
|
if (!link) return;
|
|
2267
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
|
+
|
|
2268
2311
|
/**
|
|
2269
2312
|
* AN AGENT IN ANOTHER CHANNEL IS A NAVIGATION, not a filter.
|
|
2270
2313
|
*
|
|
@@ -2388,15 +2431,94 @@ const server = createServer(async (req, res) => {
|
|
|
2388
2431
|
// an origin it can parse.
|
|
2389
2432
|
const url = new URL(req.url, `http://localhost:${port}`);
|
|
2390
2433
|
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
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) {
|
|
2395
2479
|
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
2396
2480
|
res.end('Not found.');
|
|
2397
2481
|
return;
|
|
2398
2482
|
}
|
|
2399
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
|
+
|
|
2400
2522
|
// WHAT THIS MACHINE IS. The question people keep having to reconstruct by
|
|
2401
2523
|
// hand: which agents live here, which project each belongs to, and which
|
|
2402
2524
|
// account that puts them in. It is read straight off disk, so it is what the
|
|
@@ -3209,19 +3331,37 @@ const server = createServer(async (req, res) => {
|
|
|
3209
3331
|
body.messages = writeHistory(on.ref ?? channelRef, [...byId.values()], settings().history_days);
|
|
3210
3332
|
// Every channel this viewer can open, so the page can offer them. The
|
|
3211
3333
|
// key never leaves this process -- only the ref and the name.
|
|
3212
|
-
|
|
3213
|
-
ref: c.ref,
|
|
3214
|
-
name: c.name ?? c.via,
|
|
3215
|
-
via: c.via,
|
|
3216
|
-
account: c.account ?? null,
|
|
3217
|
-
company: c.company ?? null,
|
|
3218
|
-
active: c === on,
|
|
3219
|
-
}));
|
|
3334
|
+
|
|
3220
3335
|
// What this call actually cost, so the page can say so rather than
|
|
3221
3336
|
// implying every refresh is free or that every refresh is billed.
|
|
3222
3337
|
body.fetched = fresh.length;
|
|
3223
3338
|
}
|
|
3224
3339
|
|
|
3340
|
+
/**
|
|
3341
|
+
* THE RAIL IS SENT EVEN WHEN THE READ FAILED.
|
|
3342
|
+
*
|
|
3343
|
+
* This used to live inside the success branch, so any channel whose poll
|
|
3344
|
+
* errored took the whole rail down with it -- no channels, no agents,
|
|
3345
|
+
* nothing to click. Which is precisely backwards: a channel you cannot
|
|
3346
|
+
* read is the moment you most need the list, because the other one in it
|
|
3347
|
+
* probably works and switching is the fix.
|
|
3348
|
+
*
|
|
3349
|
+
* Found by pointing the viewer at two accounts with no credit. Reading a
|
|
3350
|
+
* log costs a delivery, both polls came back 402, and a page that knew
|
|
3351
|
+
* about two channels rendered neither.
|
|
3352
|
+
*
|
|
3353
|
+
* The key never leaves this process -- only the ref, the name and whose
|
|
3354
|
+
* it is.
|
|
3355
|
+
*/
|
|
3356
|
+
body.channels = channels.map((c) => ({
|
|
3357
|
+
ref: c.ref,
|
|
3358
|
+
name: c.name ?? c.via,
|
|
3359
|
+
via: c.via,
|
|
3360
|
+
account: c.account ?? null,
|
|
3361
|
+
company: c.company ?? null,
|
|
3362
|
+
active: c === on,
|
|
3363
|
+
}));
|
|
3364
|
+
|
|
3225
3365
|
const agent = url.searchParams.get('agent');
|
|
3226
3366
|
|
|
3227
3367
|
// Filtered here rather than in the page, so the browser never holds
|
|
@@ -3278,7 +3418,7 @@ const server = createServer(async (req, res) => {
|
|
|
3278
3418
|
// of a path rather than a port: several agents run at once, and a port each
|
|
3279
3419
|
// means a port to remember each and a viewer to start each.
|
|
3280
3420
|
if (url.pathname === '/' || url.pathname.startsWith('/a/')) {
|
|
3281
|
-
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
3421
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', ...grant });
|
|
3282
3422
|
res.end(PAGE);
|
|
3283
3423
|
return;
|
|
3284
3424
|
}
|
|
@@ -3307,15 +3447,28 @@ resolveSelf();
|
|
|
3307
3447
|
* is better than being quietly shown one channel and told nothing.
|
|
3308
3448
|
*/
|
|
3309
3449
|
async function nameChannels() {
|
|
3310
|
-
const now = new Date().toISOString();
|
|
3311
3450
|
await Promise.all(
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3451
|
+
/**
|
|
3452
|
+
* ALL OF THEM, including the one the page opens on.
|
|
3453
|
+
*
|
|
3454
|
+
* It used to skip the first, because its own poll named it and asking
|
|
3455
|
+
* twice cost a delivery. That reasoning went with the endpoint: the
|
|
3456
|
+
* directory is free, and the poll does NOT always answer -- an account
|
|
3457
|
+
* with no credit gets a 402 for its log, so the channel it is looking at
|
|
3458
|
+
* stayed labelled by whichever key opened it while every other channel
|
|
3459
|
+
* was named properly.
|
|
3460
|
+
*/
|
|
3461
|
+
channels.map(async (c) => {
|
|
3317
3462
|
if (c.name && c.account) return;
|
|
3318
|
-
|
|
3463
|
+
/**
|
|
3464
|
+
* THE DIRECTORY, not the log.
|
|
3465
|
+
*
|
|
3466
|
+
* Reading messages costs a delivery. Naming the rail should not, and for
|
|
3467
|
+
* an account holding no credit it could not: the call 402s and the
|
|
3468
|
+
* channel stays labelled by whichever server's key opened it. The
|
|
3469
|
+
* directory answers the same two questions for nothing.
|
|
3470
|
+
*/
|
|
3471
|
+
const body = await upstream('/v1/recipients', c.key);
|
|
3319
3472
|
if (body?.channel?.name) {
|
|
3320
3473
|
c.name = body.channel.name;
|
|
3321
3474
|
c.ref = body.channel.ref ?? c.ref;
|