agent-run-inspector 0.10.6 → 0.11.0
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/README.md +2 -0
- package/package.json +1 -1
- package/src/model/redact.js +2 -0
- package/src/server/api.js +25 -4
- package/src/server/static.js +1 -0
- package/src/server/system.js +51 -0
- package/web/api.js +2 -0
- package/web/app.css +133 -0
- package/web/app.js +24 -2
- package/web/home.js +552 -0
- package/web/index.html +1 -1
- package/web/session-list.js +20 -1
- package/web/strings.js +16 -0
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ It opens the inspector in your browser and runs until you press Ctrl+C.
|
|
|
34
34
|
|
|
35
35
|
## What you see
|
|
36
36
|
|
|
37
|
+
- **Home** (the first screen, also the app name at the top left): this machine's CPU, memory and load, and how many agents are at work, each with a graph of the last 15 minutes (point at it for a value). Below, a live flow of every running session: its main agent, the agents working for it (what each is doing now) and the latest finished ones, joined by lines that move while they work; sessions that finished earlier today follow, dimmed. Beside it, an event stream of the newest calls that keeps scrolling. Home asks for these numbers only while it is on screen.
|
|
37
38
|
- **Session list**: running sessions on top, then recent ones (fold them with a click). Filter by tool (Claude Code, Codex CLI) and period (Today by default), or search by title or project. **Groups**: make one with "+ New group", then drag sessions onto it or right-click a session; pick a group to see only its sessions. Groups are kept in `~/.config/agent-run-inspector/groups.json`. Agent-team teammates and [Orca workers](#orca-bots) are folded into the run that started them instead of being listed on their own.
|
|
38
39
|
- **Graph**: one card per agent, from the orchestrator down. Each card shows its latest calls, status, cost, time and call count. Click a card to total that agent; "Hide finished agents" keeps only the ones still working.
|
|
39
40
|
- **Timeline**: every agent and call on one time axis, with turns and context compactions. Open a call to see its details.
|
|
@@ -126,6 +127,7 @@ Run logs can hold customer data and secrets, so nothing leaves your machine exce
|
|
|
126
127
|
- The server listens on `127.0.0.1` only.
|
|
127
128
|
- Each run makes a random token. The first address carries it once, then it becomes an HttpOnly, SameSite=Strict cookie and disappears from the address bar. Requests without the cookie get 401, except the web app manifest and its icons (browsers fetch them without cookies; they hold nothing about your logs). Host and Origin headers are checked.
|
|
128
129
|
- The service (`ari service install`) instead keeps one token in `~/.config/agent-run-inspector/service.json` (readable by you only), and its cookie lasts a year. The token is never in the LaunchAgent file, the process arguments or the log. `ari service uninstall` deletes it; installing again keeps it.
|
|
130
|
+
- Home's CPU, memory and load are read on this machine (Node's `os` module; on macOS, `sysctl kern.memorystatus_level` for memory) and stay on it.
|
|
129
131
|
- Outside requests are update checks only. The CLI asks GitHub (`api.github.com`, the latest release of this project) once an hour and prints a line in the terminal if there is a newer version. The Mac app asks the same every hour, and before it offers a newer version it checks that npm (`registry.npmjs.org`) has that version's package. Neither sends anything about you or your logs. Turn the CLI check off with `--no-update-check` or `ARI_NO_UPDATE_CHECK=1` (also off when `CI` or `NO_UPDATE_NOTIFIER` is set). Scripts and icons ship in the package and text uses the system's own fonts: no CDN, web fonts or telemetry.
|
|
130
132
|
- Updates install only when you press Update in the Mac app: it runs `npm i -g agent-run-inspector` (the newest release, not unreleased work) and `ari service install`, and writes what happened to `~/Library/Logs/agent-run-inspector-update.log`.
|
|
131
133
|
- Found a security problem? See [SECURITY.md](SECURITY.md).
|
package/package.json
CHANGED
package/src/model/redact.js
CHANGED
|
@@ -57,6 +57,8 @@ export function createRedactor({ mode = 'off' } = {}) {
|
|
|
57
57
|
switch (kind) {
|
|
58
58
|
case 'sessions':
|
|
59
59
|
return { ...body, sessions: body.sessions.map(summary) };
|
|
60
|
+
case 'live': // running sessions for the menu bar and Home: their recent calls are spans
|
|
61
|
+
return { ...body, sessions: body.sessions.map((s) => ({ ...summary(s), ...(s.recent ? { recent: s.recent.map(span) } : {}) })), ...(body.today ? { today: body.today.map((s) => ({ ...summary(s), ...(s.recent ? { recent: s.recent.map(span) } : {}) })) } : {}) };
|
|
60
62
|
case 'session':
|
|
61
63
|
return {
|
|
62
64
|
...body,
|
package/src/server/api.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// JSON API for the session views. Plug into startServer({ handler }).
|
|
2
2
|
// Sessions and spans are addressed by opaque ids only; no response carries a record-file path.
|
|
3
3
|
import { computeTotals } from '../model/totals.js';
|
|
4
|
+
import { createSystemSampler } from './system.js';
|
|
4
5
|
import { createRedactor } from '../model/redact.js';
|
|
5
6
|
import { createDetailRoutes } from './api-detail.js';
|
|
6
7
|
import { createLiveHub } from '../live/sse.js';
|
|
@@ -41,7 +42,7 @@ const fail = (res, status, error) => json(res, status, { error });
|
|
|
41
42
|
export function briefAgents(spans) {
|
|
42
43
|
const agents = new Map();
|
|
43
44
|
for (const s of spans) {
|
|
44
|
-
if (s.kind === 'agent') agents.set(s.id, { id: s.id, name: s.name, role: s.role, depth: s.depth ?? 0, status: s.status, start: s.start, end: s.end, calls: 0, now: null, nowStart: 0 });
|
|
45
|
+
if (s.kind === 'agent') agents.set(s.id, { id: s.id, parentId: s.parentId ?? null, name: s.name, role: s.role, depth: s.depth ?? 0, status: s.status, start: s.start, end: s.end, model: s.model ?? null, calls: 0, now: null, nowStart: 0 });
|
|
45
46
|
}
|
|
46
47
|
for (const s of spans) {
|
|
47
48
|
const a = s.kind === 'tool' ? agents.get(s.parentId) : null;
|
|
@@ -52,12 +53,24 @@ export function briefAgents(spans) {
|
|
|
52
53
|
return [...agents.values()].sort((x, y) => x.depth - y.depth || x.start - y.start);
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
const TODAY_MAX = 8; // finished sessions Home shows from earlier today
|
|
57
|
+
|
|
58
|
+
/** A session's newest calls for Home's event stream: what each was, who made it, when. */
|
|
59
|
+
export function recentCalls(spans, max = 12) {
|
|
60
|
+
const names = new Map(spans.filter((s) => s.kind === 'agent').map((s) => [s.id, s.name]));
|
|
61
|
+
return spans.filter((s) => (s.kind === 'llm' || s.kind === 'tool') && names.has(s.parentId))
|
|
62
|
+
.sort((a, b) => b.start - a.start).slice(0, max)
|
|
63
|
+
.map((s) => ({ id: s.id, kind: s.kind, name: s.name, agentId: s.parentId, agent: names.get(s.parentId), status: s.status, start: s.start, end: s.end ?? null,
|
|
64
|
+
...(s.model ? { model: s.model } : {}), ...(s.toolCategory ? { toolCategory: s.toolCategory } : {}), ...(s.toolBrand ? { toolBrand: s.toolBrand } : {}),
|
|
65
|
+
...(typeof s.command === 'string' ? { command: s.command.slice(0, 160) } : {}) }));
|
|
66
|
+
}
|
|
67
|
+
|
|
55
68
|
/**
|
|
56
69
|
* @param {{ index: { list(): object[], open(id: string): object },
|
|
57
70
|
* roots: { claude?: {path:string, origin?:string}[], codex?: {path:string, origin?:string}[] } }} opts
|
|
58
71
|
* @returns {(req, res) => Promise<boolean>}
|
|
59
72
|
*/
|
|
60
|
-
export function createApiHandler({ index, roots = {}, meta = { version: null, latest: null }, redactor = createRedactor(), groups = createGroupStore(), pingMs, live = createLiveHub({ index, redactor, pingMs }) }) {
|
|
73
|
+
export function createApiHandler({ index, roots = {}, meta = { version: null, latest: null }, redactor = createRedactor(), groups = createGroupStore(), pingMs, live = createLiveHub({ index, redactor, pingMs }), system = createSystemSampler() }) {
|
|
61
74
|
// Every response is serialized here, so redaction cannot be skipped by a route.
|
|
62
75
|
const send = (res, status, kind, body) => json(res, status, redactor.apply(kind, body));
|
|
63
76
|
const detail = createDetailRoutes({ index, redactor, send });
|
|
@@ -91,12 +104,20 @@ export function createApiHandler({ index, roots = {}, meta = { version: null, la
|
|
|
91
104
|
const saved = groups.set(await readJson(req, MAX_GROUPS_BODY));
|
|
92
105
|
return saved ? send(res, 200, 'raw', saved) : fail(res, 400, 'bad_request');
|
|
93
106
|
}
|
|
107
|
+
if (pathname === '/api/system' && req.method === 'GET') return send(res, 200, 'system', await system(Number(url.searchParams.get('since')) || 0)); // Home: this machine's load
|
|
94
108
|
if (pathname === '/api/live' && req.method === 'GET') { // running sessions with their agents (menu bar)
|
|
95
109
|
const sessions = index.list().filter((x) => x.status === 'running')
|
|
96
|
-
.map((x) => { const o = openSession(x.id); return o && { ...o.summary, agents: briefAgents(o.spans) }; })
|
|
110
|
+
.map((x) => { const o = openSession(x.id); return o && { ...o.summary, agents: briefAgents(o.spans), recent: recentCalls(o.spans) }; })
|
|
97
111
|
.filter(Boolean)
|
|
98
112
|
.sort((a, b) => b.lastWrite - a.lastWrite);
|
|
99
|
-
return send(res, 200, '
|
|
113
|
+
if (url.searchParams.get('today') !== '1') return send(res, 200, 'live', { sessions });
|
|
114
|
+
// Home also shows what ran earlier today (finished; Orca's scheduled runs left out), newest first
|
|
115
|
+
const midnight = new Date().setHours(0, 0, 0, 0);
|
|
116
|
+
const today = index.list().filter((x) => x.status !== 'running' && !x.routine && (x.end ?? x.lastWrite) >= midnight)
|
|
117
|
+
.sort((a, b) => (b.end ?? b.lastWrite) - (a.end ?? a.lastWrite)).slice(0, TODAY_MAX)
|
|
118
|
+
.map((x) => { const o = openSession(x.id); return o && { ...o.summary, agents: briefAgents(o.spans), recent: recentCalls(o.spans) }; })
|
|
119
|
+
.filter(Boolean);
|
|
120
|
+
return send(res, 200, 'live', { sessions, today });
|
|
100
121
|
}
|
|
101
122
|
if (pathname !== '/api/roots' && pathname !== '/api/sessions' && !pathname.startsWith('/api/sessions/')) return false;
|
|
102
123
|
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
package/src/server/static.js
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// This machine's load for the Home screen: CPU, memory, load average. Nothing about it leaves the machine.
|
|
2
|
+
// Sampled only when asked (GET /api/system), so no timer runs while nobody looks.
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import { execFile } from 'node:child_process';
|
|
5
|
+
|
|
6
|
+
const cpuTimes = (cpus) => cpus.reduce((a, c) => {
|
|
7
|
+
const t = c.times;
|
|
8
|
+
a.idle += t.idle;
|
|
9
|
+
a.total += t.user + t.nice + t.sys + t.idle + t.irq;
|
|
10
|
+
return a;
|
|
11
|
+
}, { idle: 0, total: 0 });
|
|
12
|
+
|
|
13
|
+
// macOS counts cached files as used memory (os.freemem() is near zero on a busy Mac); the kernel's own
|
|
14
|
+
// "free" level is what Activity Monitor's memory pressure reflects.
|
|
15
|
+
const darwinUsed = () => new Promise((resolve) => {
|
|
16
|
+
execFile('sysctl', ['-n', 'kern.memorystatus_level'], { timeout: 1000 }, (err, out) => {
|
|
17
|
+
const free = Number(String(out).trim());
|
|
18
|
+
resolve(err || !Number.isFinite(free) ? null : Math.min(1, Math.max(0, 1 - free / 100)));
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const HISTORY_MS = 15 * 60 * 1000;
|
|
23
|
+
export const MIN_GAP_MS = 1500; // several pages asking at once share one sample: CPU over even steps
|
|
24
|
+
|
|
25
|
+
/** Returns sample(since) -> { cpu (0..1, since the last sample; null on the first), cores, load: [1, 5, 15 min],
|
|
26
|
+
* mem: { total, used (0..1) }, history: [{ t, cpu, mem, load }] newer than `since` (the last 15 minutes at most:
|
|
27
|
+
* a page that comes back gets the graph it left). */
|
|
28
|
+
export function createSystemSampler({ cpus = () => os.cpus(), platform = process.platform, memUsed, clock = Date.now } = {}) {
|
|
29
|
+
let prev = null;
|
|
30
|
+
let last = null; // the latest sample (a promise while it is being taken)
|
|
31
|
+
const hist = [];
|
|
32
|
+
const used = memUsed ?? (platform === 'darwin' ? darwinUsed : async () => 1 - os.freemem() / os.totalmem());
|
|
33
|
+
const withHistory = async (p, since) => ({ ...(await p), history: hist.filter((h) => h.t > since) });
|
|
34
|
+
return function sample(since = 0) {
|
|
35
|
+
if (last && clock() - last.at < MIN_GAP_MS) return withHistory(last.p, since);
|
|
36
|
+
last = { at: clock(), p: take() };
|
|
37
|
+
return withHistory(last.p, since);
|
|
38
|
+
};
|
|
39
|
+
async function take() {
|
|
40
|
+
const list = cpus();
|
|
41
|
+
const now = cpuTimes(list);
|
|
42
|
+
const cpu = prev && now.total > prev.total ? Math.min(1, Math.max(0, 1 - (now.idle - prev.idle) / (now.total - prev.total))) : null;
|
|
43
|
+
prev = now;
|
|
44
|
+
const load = os.loadavg();
|
|
45
|
+
const mem = { total: os.totalmem(), used: await used() };
|
|
46
|
+
const t = clock();
|
|
47
|
+
if (cpu !== null) hist.push({ t, cpu, mem: mem.used, load: load[0] });
|
|
48
|
+
while (hist.length && hist[0].t < t - HISTORY_MS) hist.shift();
|
|
49
|
+
return { t, cpu, cores: list.length, load, mem };
|
|
50
|
+
}
|
|
51
|
+
}
|
package/web/api.js
CHANGED
|
@@ -26,6 +26,8 @@ async function getJson(path) {
|
|
|
26
26
|
export const fetchSessions = async () => (await getJson('/api/sessions')).sessions;
|
|
27
27
|
export const fetchRoots = async () => (await getJson('/api/roots')).roots;
|
|
28
28
|
export const fetchMeta = () => getJson('/api/meta');
|
|
29
|
+
export const fetchLive = () => getJson('/api/live?today=1'); // { sessions: running, today: finished earlier today }
|
|
30
|
+
export const fetchSystem = (since = 0) => getJson(`/api/system?since=${since}`);
|
|
29
31
|
export const fetchSession = (id) => getJson(`/api/sessions/${encodeURIComponent(id)}`);
|
|
30
32
|
export const fetchSpanDetail = (spanId, sessionId) =>
|
|
31
33
|
getJson(`/api/spans/${encodeURIComponent(spanId)}/detail${sessionId ? `?session=${encodeURIComponent(sessionId)}` : ''}`);
|
package/web/app.css
CHANGED
|
@@ -474,3 +474,136 @@ body.mini { height: auto; background: var(--bg); }
|
|
|
474
474
|
.grp-menu-i.on { color: var(--llm); }
|
|
475
475
|
.grp-menu-i.danger { color: var(--err); }
|
|
476
476
|
.grp-menu .grp-new { margin: 2px 4px; }
|
|
477
|
+
|
|
478
|
+
/* ---- Home: this machine and everything running (home.js) ---- */
|
|
479
|
+
.sess.home-row { margin-bottom: 18px; border-bottom: 1px solid var(--line); } /* same gap as between Running and Recent */
|
|
480
|
+
.sess.home-row .t { gap: 8px; }
|
|
481
|
+
.home-ico { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
|
|
482
|
+
.home-n { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
|
|
483
|
+
.home {
|
|
484
|
+
--glow: color-mix(in srgb, var(--llm) 22%, transparent);
|
|
485
|
+
flex: 1; box-sizing: border-box; padding: 18px 22px 28px; display: flex; flex-direction: column; gap: 16px;
|
|
486
|
+
background-image: radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--faint) 32%, transparent) 1px, transparent 0);
|
|
487
|
+
background-size: 22px 22px;
|
|
488
|
+
}
|
|
489
|
+
.h-hud { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
|
|
490
|
+
.h-tile { position: relative; padding: 12px 14px 10px; border: 1px solid var(--line); border-radius: 10px; background: color-mix(in srgb, var(--panel) 90%, transparent); box-sizing: border-box; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
|
|
491
|
+
/* HUD corner brackets */
|
|
492
|
+
.h-tile::before, .h-tile::after { content: ''; position: absolute; width: 10px; height: 10px; border: 0 solid color-mix(in srgb, var(--accent) 70%, transparent); pointer-events: none; }
|
|
493
|
+
.h-tile::before { top: 5px; left: 5px; border-top-width: 1.5px; border-left-width: 1.5px; border-top-left-radius: 4px; }
|
|
494
|
+
.h-tile::after { bottom: 5px; right: 5px; border-bottom-width: 1.5px; border-right-width: 1.5px; border-bottom-right-radius: 4px; }
|
|
495
|
+
.h-tile-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
|
|
496
|
+
.h-tile-k { font: 600 10.5px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
|
|
497
|
+
.h-tile-v { font: 600 24px/1 var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }
|
|
498
|
+
.h-tile-u { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 2px; }
|
|
499
|
+
.h-tile-sub { font: 11px/1.3 var(--mono); color: var(--muted); min-height: 1.3em; }
|
|
500
|
+
.h-tile-sub.hot { color: var(--text); }
|
|
501
|
+
.h-tile.hot .h-tile-v { color: var(--run); }
|
|
502
|
+
.h-chart-wrap { display: flex; flex-direction: column; gap: 3px; }
|
|
503
|
+
.h-chart { --c: var(--tool); position: relative; height: 70px; border-left: 1px solid var(--line-2); border-bottom: 1px solid var(--line); cursor: crosshair; }
|
|
504
|
+
.h-chart.c-mem { --c: var(--llm); }
|
|
505
|
+
.h-chart.c-load { --c: var(--run); }
|
|
506
|
+
.h-chart.c-act { --c: var(--flow); }
|
|
507
|
+
.h-chart svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
|
|
508
|
+
.h-grid { stroke: var(--line-2); stroke-width: 1; stroke-dasharray: 2 4; vector-effect: non-scaling-stroke; }
|
|
509
|
+
.h-line { fill: none; stroke: var(--c); stroke-width: 1.6; stroke-linejoin: round; vector-effect: non-scaling-stroke; filter: drop-shadow(0 0 3px color-mix(in srgb, var(--c) 45%, transparent)); }
|
|
510
|
+
.h-area { fill: color-mix(in srgb, var(--c) 14%, transparent); }
|
|
511
|
+
.h-ylab { position: absolute; top: -1px; left: 4px; font-size: 9.5px; color: var(--faint); }
|
|
512
|
+
.h-axis { display: flex; justify-content: space-between; font-size: 9.5px; color: var(--faint); }
|
|
513
|
+
.h-cursor { position: absolute; top: 0; bottom: 0; width: 1px; background: color-mix(in srgb, var(--c) 70%, transparent); opacity: 0; pointer-events: none; }
|
|
514
|
+
.h-cdot { position: absolute; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px var(--panel); opacity: 0; pointer-events: none; }
|
|
515
|
+
.h-chart.hover .h-cursor, .h-chart.hover .h-cdot { opacity: 1; }
|
|
516
|
+
.h-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); gap: 14px; align-items: start; }
|
|
517
|
+
.h-stream { border: 1px solid var(--line); border-radius: 12px; background: color-mix(in srgb, var(--panel) 84%, transparent); padding: 14px 0 0; display: flex; flex-direction: column; height: 560px; min-width: 0; overflow: hidden; }
|
|
518
|
+
.h-stream .h-flow-head { padding: 0 14px 8px; border-bottom: 1px solid var(--line-2); }
|
|
519
|
+
/* a log that keeps scrolling up, faded at both edges */
|
|
520
|
+
.h-ev-list { position: relative; flex: 1; min-height: 0; overflow: hidden;
|
|
521
|
+
-webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 48px, #000 calc(100% - 48px), transparent 100%);
|
|
522
|
+
mask-image: linear-gradient(to bottom, transparent 0, #000 48px, #000 calc(100% - 48px), transparent 100%); }
|
|
523
|
+
.h-ev-track { will-change: transform; }
|
|
524
|
+
.h-ev-track:not(.looping) .h-ev-copy + .h-ev-wrap, .h-ev-track:not(.looping) .h-ev-copy ~ .h-ev-copy, .h-ev-track:not(.looping) .h-ev-wrap { display: none; }
|
|
525
|
+
.h-ev-wrap { padding: 10px 14px; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); text-align: center; border-bottom: 1px dashed var(--line); }
|
|
526
|
+
.h-ev-none[hidden] { display: none; }
|
|
527
|
+
.h-ev { display: grid; grid-template-columns: 58px 16px minmax(0, auto) minmax(0, 1fr) auto; align-items: center; gap: 7px; width: 100%; padding: 6px 14px; font: inherit; font-size: 12px; text-align: left; color: var(--text); background: none; border: 0; border-bottom: 1px solid var(--line-2); cursor: pointer; }
|
|
528
|
+
.h-ev:hover { background: var(--panel-2); }
|
|
529
|
+
.h-ev.new { animation: h-ev-in .9s ease-out; }
|
|
530
|
+
@keyframes h-ev-in { from { background: color-mix(in srgb, var(--llm) 22%, transparent); opacity: 0; } }
|
|
531
|
+
.h-ev-t { color: var(--faint); font-size: 11px; }
|
|
532
|
+
.h-ev-i { display: inline-grid; place-items: center; }
|
|
533
|
+
.h-ev-i svg { width: 13px; height: 13px; }
|
|
534
|
+
.h-ev-who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; color: var(--llm); }
|
|
535
|
+
.h-ev-who.root { color: var(--run); }
|
|
536
|
+
.h-ev-who.bot { color: var(--bot); }
|
|
537
|
+
.h-ev-what { font-family: var(--mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
538
|
+
.h-ev-d { font-size: 11px; color: var(--faint); }
|
|
539
|
+
.h-ev.err .h-ev-what { color: var(--err); }
|
|
540
|
+
.h-ev-none { padding: 28px 14px; color: var(--muted); text-align: center; font-size: 12.5px; }
|
|
541
|
+
.h-flow { position: relative; flex: 1; border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px 8px; background: color-mix(in srgb, var(--panel) 84%, transparent); }
|
|
542
|
+
.h-flow-head { display: flex; align-items: center; gap: 10px; }
|
|
543
|
+
.h-flow-live { font-size: 11px; color: var(--muted); }
|
|
544
|
+
.h-flow-empty { padding: 48px 12px; display: flex; flex-direction: column; gap: 6px; align-items: center; color: var(--muted); text-align: center; }
|
|
545
|
+
.h-flow-empty b { color: var(--text); font-weight: 600; }
|
|
546
|
+
.h-lane { position: relative; display: grid; grid-template-columns: minmax(220px, 300px) minmax(190px, 300px) minmax(190px, 300px); column-gap: 64px; align-items: center; padding: 18px 0; }
|
|
547
|
+
.h-lane + .h-lane { border-top: 1px dashed var(--line-2); }
|
|
548
|
+
.h-lane.routine { opacity: .6; }
|
|
549
|
+
.h-past-head { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
|
|
550
|
+
.h-lane.past .h-node.root { --c: var(--faint); box-shadow: none; }
|
|
551
|
+
.h-lane.past.bot .h-node.root { --c: color-mix(in srgb, var(--bot) 55%, var(--faint)); }
|
|
552
|
+
.h-lane.past .h-node.root .h-orb::before { animation: none; border-style: solid; opacity: .5; }
|
|
553
|
+
.h-lane.past { opacity: .78; }
|
|
554
|
+
.h-lane.past:hover { opacity: 1; }
|
|
555
|
+
.h-lane-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
|
|
556
|
+
.h-lane-col:empty { display: none; }
|
|
557
|
+
.h-lane-wires { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
|
|
558
|
+
.h-wire { fill: none; stroke: var(--line); stroke-width: 1.5; }
|
|
559
|
+
.h-wire.run { stroke: var(--llm); stroke-width: 1.6; stroke-linecap: round; stroke-dasharray: 1 7; animation: wire-flow 1.1s linear infinite; }
|
|
560
|
+
@keyframes wire-flow { to { stroke-dashoffset: -16; } }
|
|
561
|
+
.h-spark-dot { fill: var(--llm); filter: drop-shadow(0 0 4px var(--llm)); }
|
|
562
|
+
|
|
563
|
+
.h-node { position: relative; z-index: 1; display: flex; align-items: center; gap: 10px; min-width: 0; text-align: left; font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
|
|
564
|
+
.h-node:hover { border-color: var(--accent); }
|
|
565
|
+
.h-node .h-nd-t { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
|
566
|
+
.h-node .h-nm { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
|
|
567
|
+
.h-node .h-now { font: 11.5px/1.3 var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
568
|
+
.h-node .h-meta { font: 11px/1.3 var(--mono); color: var(--faint); }
|
|
569
|
+
.h-node .h-orb { position: relative; display: inline-grid; place-items: center; flex: none; }
|
|
570
|
+
.h-node.agent { border-color: color-mix(in srgb, var(--llm) 45%, var(--line)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--llm) 8%, transparent); }
|
|
571
|
+
.h-node.agent .h-orb::after { content: ''; position: absolute; right: -3px; bottom: -3px; width: 7px; height: 7px; border-radius: 50%; background: var(--run); box-shadow: 0 0 0 2px var(--panel); animation: pulse 1.8s ease-in-out infinite; }
|
|
572
|
+
/* the session's main agent: its own colour (orchestrator orange, bot gold), a turning ring while it runs */
|
|
573
|
+
.h-node.root { --c: var(--run); padding: 12px 14px; border-radius: 12px; border-color: color-mix(in srgb, var(--c) 55%, var(--line));
|
|
574
|
+
box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 10%, transparent), 0 10px 32px -14px color-mix(in srgb, var(--c) 60%, transparent); }
|
|
575
|
+
.h-lane.bot .h-node.root { --c: var(--bot); }
|
|
576
|
+
.h-node.root .h-orb { width: 34px; height: 34px; }
|
|
577
|
+
.h-node.root .h-orb .prov { width: 26px; height: 26px; border-radius: 8px; }
|
|
578
|
+
.h-node.root .h-orb .prov .pi { width: 16px; height: 16px; }
|
|
579
|
+
.h-node.root .h-orb::before { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 1.5px dashed color-mix(in srgb, var(--c) 75%, transparent); animation: spin 12s linear infinite; }
|
|
580
|
+
.h-node.root .h-nm { font-size: 14px; }
|
|
581
|
+
.h-node.agent.off { border-color: var(--line); box-shadow: none; opacity: .62; padding: 5px 10px; gap: 8px; }
|
|
582
|
+
.h-node.agent.off .h-nd-t { flex-direction: row; align-items: baseline; gap: 8px; min-width: 0; flex: 1; }
|
|
583
|
+
.h-node.agent.off .h-nm { flex: 1; min-width: 0; }
|
|
584
|
+
.h-node.agent.off .h-now { flex: none; }
|
|
585
|
+
.h-node.agent.off .h-nm { font-size: 12px; font-weight: 500; }
|
|
586
|
+
.h-node.agent.off .h-orb .prov { width: 16px; height: 16px; border-radius: 5px; }
|
|
587
|
+
.h-node.agent.off .h-orb .prov .pi { width: 10px; height: 10px; }
|
|
588
|
+
.h-node.agent.off:hover { opacity: 1; }
|
|
589
|
+
.h-node.agent.off .h-orb::after { display: none; }
|
|
590
|
+
.h-node.agent.off .h-orb .prov { filter: grayscale(.6); }
|
|
591
|
+
.h-node.agent.failed .h-now { color: var(--err); }
|
|
592
|
+
.h-node.h-done-chip, .h-node.h-more { color: var(--muted); font-size: 12px; background: transparent; border-style: dashed; padding: 6px 10px; align-self: flex-start; }
|
|
593
|
+
.h-node.h-more { cursor: default; }
|
|
594
|
+
@media (prefers-reduced-motion: reduce) {
|
|
595
|
+
.h-wire.run, .h-node.root .h-orb::before, .h-node.agent .h-orb::after, .h-ev.new { animation: none; }
|
|
596
|
+
}
|
|
597
|
+
@container main (max-width: 1100px) {
|
|
598
|
+
.h-body { grid-template-columns: 1fr; }
|
|
599
|
+
.h-stream { max-height: 360px; }
|
|
600
|
+
}
|
|
601
|
+
@container main (max-width: 760px) {
|
|
602
|
+
.h-lane { grid-template-columns: 1fr; row-gap: 8px; }
|
|
603
|
+
.h-lane-col { padding-left: 28px; }
|
|
604
|
+
.h-lane-wires { display: none; }
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
.brand-home { display: inline-flex; align-items: center; gap: inherit; color: inherit; text-decoration: none; border-radius: 6px; }
|
|
608
|
+
.brand-home:hover #appName { color: var(--accent); }
|
|
609
|
+
.brand-home:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
package/web/app.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { S } from './strings.js';
|
|
2
2
|
import { parseState, toSearch } from './state.js';
|
|
3
|
-
import { onAuthLost, fetchSession, fetchRoots, watchList, watchSession, mergeSpan, trimSpans, upsertSession, ApiError, fetchMeta } from './api.js';
|
|
3
|
+
import { onAuthLost, fetchSession, fetchRoots, watchList, watchSession, mergeSpan, trimSpans, upsertSession, ApiError, fetchMeta, fetchLive, fetchSystem } from './api.js';
|
|
4
4
|
import { liveState, createFlushGate } from './live-follow.js';
|
|
5
5
|
import { mount, emptyBlock } from './session-list.js';
|
|
6
6
|
import { createRunHeader } from './run-header.js';
|
|
@@ -8,6 +8,7 @@ import { createTimeline } from './timeline.js';
|
|
|
8
8
|
import { createGraph } from './graph.js';
|
|
9
9
|
import { createAgentPanel } from './agent-panel.js';
|
|
10
10
|
import { startMini } from './mini.js';
|
|
11
|
+
import { createHome } from './home.js';
|
|
11
12
|
import { mountListResize } from './list-resize.js';
|
|
12
13
|
import { createGroupPicker, getGroups, loadGroups, onGroups } from './groups.js';
|
|
13
14
|
|
|
@@ -83,6 +84,7 @@ let head = null; // { id, header } - rebuilt per session so numbers do not roll
|
|
|
83
84
|
let view = null;
|
|
84
85
|
let timeline = null; // rebuilt per session, like the head
|
|
85
86
|
let graph = null; // { id, graph } - one per session, like the head
|
|
87
|
+
let home = null; // the Home screen while no session is chosen
|
|
86
88
|
let stopStream = null;
|
|
87
89
|
|
|
88
90
|
function ensureHead() {
|
|
@@ -119,11 +121,18 @@ function renderMain() {
|
|
|
119
121
|
graph?.panel.destroy();
|
|
120
122
|
graph = null;
|
|
121
123
|
if (listEmpty()) {
|
|
124
|
+
home?.destroy();
|
|
125
|
+
home = null;
|
|
122
126
|
loadRoots();
|
|
123
127
|
return void main.replaceChildren(emptyBlock(roots));
|
|
124
128
|
}
|
|
125
|
-
|
|
129
|
+
// nothing chosen: Home (this machine and everything running)
|
|
130
|
+
home ??= createHome({ onOpen: openFromHome, fetchLive, fetchSystem });
|
|
131
|
+
if (main.firstChild !== home.el) main.replaceChildren(home.el);
|
|
132
|
+
return void home.start();
|
|
126
133
|
}
|
|
134
|
+
home?.destroy();
|
|
135
|
+
home = null;
|
|
127
136
|
const header = ensureHead();
|
|
128
137
|
const full = run.id === state.s ? run.data?.summary : null; // the detail summary has the title; the list one may not
|
|
129
138
|
const fromList = sessions?.find((s) => s.id === state.s);
|
|
@@ -165,6 +174,12 @@ function renderMain() {
|
|
|
165
174
|
if (main.firstChild !== header.el) main.replaceChildren(header.el, header.tabs, view);
|
|
166
175
|
}
|
|
167
176
|
|
|
177
|
+
function openFromHome(id, agentId) {
|
|
178
|
+
state = { ...state, s: id, tab: 'graph', sel: null, open: null, gsel: agentId, gopen: null };
|
|
179
|
+
writeUrl(true);
|
|
180
|
+
render();
|
|
181
|
+
}
|
|
182
|
+
|
|
168
183
|
function selectAgent(id) {
|
|
169
184
|
state = { ...state, gsel: state.gsel === id ? null : id, gopen: null };
|
|
170
185
|
writeUrl(false);
|
|
@@ -302,6 +317,13 @@ if (state.mini) {
|
|
|
302
317
|
setInterval(showMeta, 60 * 60 * 1000);
|
|
303
318
|
setLive('connecting');
|
|
304
319
|
|
|
320
|
+
// the app name at the top left goes Home (a real link: a modified click still opens a new tab)
|
|
321
|
+
$('brandHome').title = S.home.rowTip;
|
|
322
|
+
$('brandHome').addEventListener('click', (e) => {
|
|
323
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return;
|
|
324
|
+
e.preventDefault();
|
|
325
|
+
if (state.s) select(null);
|
|
326
|
+
});
|
|
305
327
|
$('list').addEventListener('click', (e) => {
|
|
306
328
|
const row = e.target.closest('.sess');
|
|
307
329
|
if (row) select(row.dataset.id);
|
package/web/home.js
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
// Home: this machine's load (GET /api/system) and every running session as a live flow (GET /api/live):
|
|
2
|
+
// the session's main agent on the left, its working agents to the right, joined by wires that light up
|
|
3
|
+
// while they work. Polled only while Home is on screen and the page is visible.
|
|
4
|
+
import { S } from './strings.js';
|
|
5
|
+
import { fmtDuration } from './format.js';
|
|
6
|
+
import { providerTile, iconNode, callIcon, toolLabel } from './card.js';
|
|
7
|
+
import { nowOf } from './mini.js';
|
|
8
|
+
|
|
9
|
+
const LIVE_MS = 3000;
|
|
10
|
+
const SYS_MS = 2000;
|
|
11
|
+
const SHOWN = 6; // working agents drawn per session; the rest are counted
|
|
12
|
+
const SHOWN_DONE = 4; // finished agents drawn per session, latest first
|
|
13
|
+
const SPARKS_MAX = 12;
|
|
14
|
+
const EVENTS = 40; // rows in the event stream
|
|
15
|
+
const SCROLL_PX_S = 18; // how fast the event stream scrolls
|
|
16
|
+
const SVG = 'http://www.w3.org/2000/svg';
|
|
17
|
+
const reduceMotion = () => globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
|
18
|
+
|
|
19
|
+
function el(tag, cls, text) {
|
|
20
|
+
const e = document.createElement(tag);
|
|
21
|
+
if (cls) e.className = cls;
|
|
22
|
+
if (text !== undefined) e.textContent = text;
|
|
23
|
+
return e;
|
|
24
|
+
}
|
|
25
|
+
const svgEl = (tag, attrs = {}) => {
|
|
26
|
+
const e = document.createElementNS(SVG, tag);
|
|
27
|
+
for (const [k, v] of Object.entries(attrs)) e.setAttribute(k, String(v));
|
|
28
|
+
return e;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** One session's flow: its main agent, then its agents in two columns (depth 1, deeper), each with the
|
|
32
|
+
* node it hangs from: the working ones (up to `max`), then the latest finished ones (up to `maxDone`), dimmed.
|
|
33
|
+
* `done` / `more` count the finished and working ones that did not fit. */
|
|
34
|
+
export function laneOf(session, max = SHOWN, maxDone = SHOWN_DONE) {
|
|
35
|
+
const agents = session.agents ?? [];
|
|
36
|
+
const root = agents.find((a) => a.depth === 0) ?? null;
|
|
37
|
+
const kids = agents.filter((a) => a.depth > 0);
|
|
38
|
+
const running = kids.filter((a) => a.status === 'running').sort((a, b) => (b.nowStart || b.start) - (a.nowStart || a.start));
|
|
39
|
+
const finished = kids.filter((a) => a.status !== 'running').sort((a, b) => (b.end ?? b.start) - (a.end ?? a.start));
|
|
40
|
+
const shown = [...running.slice(0, max), ...finished.slice(0, maxDone)];
|
|
41
|
+
const ids = new Set(shown.map((a) => a.id));
|
|
42
|
+
const hangs = (a) => a.depth > 1 && a.parentId && ids.has(a.parentId);
|
|
43
|
+
const nodes = shown.map((a) => ({ ...a, from: hangs(a) ? a.parentId : root?.id ?? null, col: hangs(a) ? 2 : 1 }));
|
|
44
|
+
return { root, nodes, done: Math.max(0, finished.length - maxDone), more: Math.max(0, running.length - max) };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Calls per minute: the calls each agent made since the last look (`seen`: agent id -> calls then), over `dt` ms.
|
|
48
|
+
* An agent seen for the first time brings its whole past, so it counts from the next look. Updates `seen`. */
|
|
49
|
+
export function callsPerMin(sessions, seen, dt) {
|
|
50
|
+
let n = 0;
|
|
51
|
+
const now = new Map();
|
|
52
|
+
for (const s of sessions) for (const a of s.agents ?? []) {
|
|
53
|
+
const c = a.calls ?? 0;
|
|
54
|
+
if (seen.has(a.id)) n += Math.max(0, c - seen.get(a.id));
|
|
55
|
+
now.set(a.id, c);
|
|
56
|
+
}
|
|
57
|
+
seen.clear();
|
|
58
|
+
for (const [k, v] of now) seen.set(k, v);
|
|
59
|
+
return dt > 0 ? (n / dt) * 60000 : 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const pct = (v) => (v == null ? '—' : String(Math.round(v * 100)));
|
|
63
|
+
const WINDOW = 15 * 60 * 1000; // the charts show the last 15 minutes
|
|
64
|
+
const clockOf = (t) => new Date(t).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
|
|
65
|
+
|
|
66
|
+
// Kept for the page's life, so Home picks up where it left off (the server keeps the system's last 15 min too).
|
|
67
|
+
const sysHist = []; // { t, cpu, mem, load }
|
|
68
|
+
const actHist = []; // { t, rate, working }
|
|
69
|
+
const trim = (arr, now) => { while (arr.length && arr[0].t < now - WINDOW) arr.shift(); };
|
|
70
|
+
/** Adds samples newer than the last one held: two answers can overlap, and a graph must never run backwards. */
|
|
71
|
+
export function mergeHistory(arr, samples) {
|
|
72
|
+
for (const h of samples) if (!arr.length || h.t > arr.at(-1).t) arr.push(h);
|
|
73
|
+
return arr;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A chart of one value over the last 15 minutes: area and line, grid at quarters, a time axis, and a
|
|
77
|
+
* readout of the nearest sample under the pointer. */
|
|
78
|
+
function createChart({ cls, fmt }) {
|
|
79
|
+
const W = 300;
|
|
80
|
+
const H = 70;
|
|
81
|
+
const box = el('div', `h-chart ${cls}`);
|
|
82
|
+
const svg = svgEl('svg', { viewBox: `0 0 ${W} ${H}`, preserveAspectRatio: 'none', 'aria-hidden': 'true' });
|
|
83
|
+
for (const y of [0.25, 0.5, 0.75]) svg.append(svgEl('line', { class: 'h-grid', x1: 0, x2: W, y1: H * y, y2: H * y }));
|
|
84
|
+
const area = svgEl('path', { class: 'h-area' });
|
|
85
|
+
const line = svgEl('path', { class: 'h-line' });
|
|
86
|
+
svg.append(area, line);
|
|
87
|
+
const top = el('span', 'h-ylab num');
|
|
88
|
+
const cursor = el('i', 'h-cursor');
|
|
89
|
+
const dot = el('i', 'h-cdot');
|
|
90
|
+
const axis = el('div', 'h-axis num');
|
|
91
|
+
for (const m of [15, 10, 5, 0]) axis.append(el('span', '', S.home.ago(m)));
|
|
92
|
+
box.append(svg, top, cursor, dot);
|
|
93
|
+
const wrap = el('div', 'h-chart-wrap');
|
|
94
|
+
wrap.append(box, axis);
|
|
95
|
+
let pts = [];
|
|
96
|
+
let max = 1;
|
|
97
|
+
let onHover = () => {};
|
|
98
|
+
const xOf = (t, now) => ((t - (now - WINDOW)) / WINDOW) * W;
|
|
99
|
+
box.addEventListener('pointermove', (e) => {
|
|
100
|
+
if (!pts.length) return;
|
|
101
|
+
const r = box.getBoundingClientRect();
|
|
102
|
+
const fx = Math.min(1, Math.max(0, (e.clientX - r.left) / r.width));
|
|
103
|
+
const now = Date.now();
|
|
104
|
+
const t = now - WINDOW + fx * WINDOW;
|
|
105
|
+
let best = pts[0];
|
|
106
|
+
for (const p of pts) if (Math.abs(p.t - t) < Math.abs(best.t - t)) best = p;
|
|
107
|
+
const x = xOf(best.t, now) / W;
|
|
108
|
+
const y = 1 - Math.min(1, best.v / max);
|
|
109
|
+
cursor.style.left = dot.style.left = `${(x * 100).toFixed(2)}%`;
|
|
110
|
+
dot.style.top = `${(y * 100).toFixed(2)}%`;
|
|
111
|
+
box.classList.add('hover');
|
|
112
|
+
onHover(S.home.at(clockOf(best.t), fmt(best.v)));
|
|
113
|
+
});
|
|
114
|
+
box.addEventListener('pointerleave', () => { box.classList.remove('hover'); onHover(null); });
|
|
115
|
+
return {
|
|
116
|
+
el: wrap,
|
|
117
|
+
hover(fn) { onHover = fn; },
|
|
118
|
+
update(points, now, top_) {
|
|
119
|
+
pts = points.filter((p) => p.v != null && p.t >= now - WINDOW);
|
|
120
|
+
max = top_;
|
|
121
|
+
top.textContent = fmt(top_);
|
|
122
|
+
if (!pts.length) { line.setAttribute('d', ''); area.setAttribute('d', ''); return; }
|
|
123
|
+
const xy = pts.map((p) => [xOf(p.t, now), H - Math.min(1, p.v / max) * (H - 2)]);
|
|
124
|
+
const d = xy.map(([x, y], i) => `${i ? 'L' : 'M'}${x.toFixed(1)} ${y.toFixed(1)}`).join(' ');
|
|
125
|
+
line.setAttribute('d', d);
|
|
126
|
+
area.setAttribute('d', `${d} L${xy.at(-1)[0].toFixed(1)} ${H} L${xy[0][0].toFixed(1)} ${H} Z`);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function tile(key, chart) {
|
|
132
|
+
const t = el('div', 'h-tile');
|
|
133
|
+
const head = el('div', 'h-tile-h');
|
|
134
|
+
const v = el('div', 'h-tile-v num');
|
|
135
|
+
head.append(el('span', 'h-tile-k', key), v);
|
|
136
|
+
const sub = el('div', 'h-tile-sub num');
|
|
137
|
+
t.append(head, chart.el, sub);
|
|
138
|
+
let text = '';
|
|
139
|
+
chart.hover((h) => { sub.textContent = h ?? text; sub.classList.toggle('hot', Boolean(h)); });
|
|
140
|
+
return { el: t, v, setSub(x) { text = x; if (!sub.classList.contains('hot')) sub.textContent = x; } };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function createHud() {
|
|
144
|
+
const box = el('div', 'h-hud');
|
|
145
|
+
const charts = {
|
|
146
|
+
cpu: createChart({ cls: 'c-cpu', fmt: (v) => `${Math.round(v * 100)}%` }),
|
|
147
|
+
mem: createChart({ cls: 'c-mem', fmt: (v) => `${Math.round(v * 100)}%` }),
|
|
148
|
+
load: createChart({ cls: 'c-load', fmt: (v) => v.toFixed(1) }),
|
|
149
|
+
act: createChart({ cls: 'c-act', fmt: (v) => S.home.perMin(Math.round(v)) }),
|
|
150
|
+
};
|
|
151
|
+
const cpu = tile(S.home.cpu, charts.cpu);
|
|
152
|
+
const mem = tile(S.home.memory, charts.mem);
|
|
153
|
+
const load = tile(S.home.load, charts.load);
|
|
154
|
+
const act = tile(S.home.live, charts.act);
|
|
155
|
+
box.append(cpu.el, mem.el, load.el, act.el);
|
|
156
|
+
return {
|
|
157
|
+
el: box,
|
|
158
|
+
system(s) {
|
|
159
|
+
const now = Date.now();
|
|
160
|
+
cpu.v.replaceChildren(pct(s.cpu), el('span', 'h-tile-u', '%'));
|
|
161
|
+
cpu.setSub(S.home.cores(s.cores));
|
|
162
|
+
mem.v.replaceChildren(pct(s.mem.used), el('span', 'h-tile-u', '%'));
|
|
163
|
+
mem.setSub(S.home.memOf(Math.round(s.mem.total / 2 ** 30)));
|
|
164
|
+
const [l1, l5, l15] = s.load;
|
|
165
|
+
load.v.replaceChildren(l1.toFixed(1));
|
|
166
|
+
load.setSub(S.home.loadAvg(l5.toFixed(1), l15.toFixed(1)));
|
|
167
|
+
load.el.classList.toggle('hot', l1 > s.cores * 0.85);
|
|
168
|
+
charts.cpu.update(sysHist.map((h) => ({ t: h.t, v: h.cpu })), now, 1);
|
|
169
|
+
charts.mem.update(sysHist.map((h) => ({ t: h.t, v: h.mem })), now, 1);
|
|
170
|
+
const peak = Math.max(...sysHist.map((h) => h.load), 0);
|
|
171
|
+
charts.load.update(sysHist.map((h) => ({ t: h.t, v: h.load })), now, Math.max(s.cores, Math.ceil(peak)));
|
|
172
|
+
},
|
|
173
|
+
live({ sessions, agents, rate }) {
|
|
174
|
+
const now = Date.now();
|
|
175
|
+
act.v.replaceChildren(String(agents), el('span', 'h-tile-u', S.home.agentsUnit));
|
|
176
|
+
act.setSub(S.home.liveSub(sessions, Math.round(rate)));
|
|
177
|
+
const peak = Math.max(...actHist.map((h) => h.rate), 0);
|
|
178
|
+
charts.act.update(actHist.map((h) => ({ t: h.t, v: h.rate })), now, Math.max(10, Math.ceil((peak * 1.2) / 10) * 10));
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The newest calls of running (and today's) sessions as a log that never stops: it scrolls up slowly
|
|
184
|
+
* through the last EVENTS calls in time order and starts over after a divider. New calls join the end;
|
|
185
|
+
* the pointer over it, or a hidden page, holds it still. */
|
|
186
|
+
function createStream() {
|
|
187
|
+
const box = el('section', 'h-stream');
|
|
188
|
+
const head = el('div', 'h-flow-head');
|
|
189
|
+
const count = el('span', 'h-flow-live num');
|
|
190
|
+
head.append(el('span', 'h-tile-k', S.home.events), count);
|
|
191
|
+
const list = el('div', 'h-ev-list');
|
|
192
|
+
const track = el('div', 'h-ev-track');
|
|
193
|
+
// two copies of the log, each followed by a divider: when the first has scrolled by, the view jumps back
|
|
194
|
+
// by one copy and nothing visible changes
|
|
195
|
+
const copies = [el('div', 'h-ev-copy'), el('div', 'h-ev-copy')];
|
|
196
|
+
const divs = copies.map(() => el('div', 'h-ev-wrap num', S.home.loop));
|
|
197
|
+
track.append(copies[0], divs[0], copies[1], divs[1]);
|
|
198
|
+
copies[1].setAttribute('aria-hidden', 'true');
|
|
199
|
+
copies[1].inert = true;
|
|
200
|
+
const none = el('div', 'h-ev-none', S.home.eventsNone);
|
|
201
|
+
list.append(track, none);
|
|
202
|
+
box.append(head, list);
|
|
203
|
+
const rows = new Map(); // id -> [row, its copy]
|
|
204
|
+
const seen = new Set();
|
|
205
|
+
let y = 0;
|
|
206
|
+
let last = 0;
|
|
207
|
+
let raf = 0;
|
|
208
|
+
let held = false;
|
|
209
|
+
list.addEventListener('pointerenter', () => { held = true; });
|
|
210
|
+
list.addEventListener('pointerleave', () => { held = false; });
|
|
211
|
+
list.addEventListener('focusin', () => { held = true; });
|
|
212
|
+
list.addEventListener('focusout', () => { held = false; });
|
|
213
|
+
|
|
214
|
+
function rowOf(e) {
|
|
215
|
+
const b = el('button', 'h-ev');
|
|
216
|
+
b.type = 'button';
|
|
217
|
+
b.dataset.sid = e.sid;
|
|
218
|
+
b.dataset.aid = e.agentId;
|
|
219
|
+
b.dataset.eid = e.id;
|
|
220
|
+
const ico = el('span', 'h-ev-i');
|
|
221
|
+
ico.append(iconNode(callIcon(e)));
|
|
222
|
+
b.append(el('span', 'h-ev-t num', clockOf(e.start)), ico, el('span', `h-ev-who ${e.role}`, e.who),
|
|
223
|
+
el('span', 'h-ev-what', e.kind === 'llm' ? S.home.model : toolLabel(e)), el('span', 'h-ev-d num'));
|
|
224
|
+
return b;
|
|
225
|
+
}
|
|
226
|
+
function paintRow(pair, e) {
|
|
227
|
+
for (const r of pair) {
|
|
228
|
+
r.lastChild.replaceChildren(e.end ? document.createTextNode(fmtDuration(e.end - e.start)) : el('span', 'dot pulse'));
|
|
229
|
+
r.classList.toggle('err', e.status === 'error');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function add(e, isNew) {
|
|
233
|
+
const pair = [rowOf(e), rowOf(e)];
|
|
234
|
+
if (isNew) pair.forEach((r) => r.classList.add('new'));
|
|
235
|
+
copies[0].append(pair[0]);
|
|
236
|
+
copies[1].append(pair[1]);
|
|
237
|
+
rows.set(e.id, pair);
|
|
238
|
+
paintRow(pair, e);
|
|
239
|
+
while (copies[0].children.length > EVENTS) {
|
|
240
|
+
rows.delete(copies[0].firstElementChild.dataset.eid);
|
|
241
|
+
copies[0].firstElementChild.remove();
|
|
242
|
+
copies[1].firstElementChild.remove();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function frame(t) {
|
|
246
|
+
raf = requestAnimationFrame(frame);
|
|
247
|
+
const dt = last ? Math.min(100, t - last) : 0;
|
|
248
|
+
last = t;
|
|
249
|
+
const cycle = copies[0].offsetHeight + divs[0].offsetHeight;
|
|
250
|
+
const moving = !held && !document.hidden && !reduceMotion() && copies[0].offsetHeight > list.clientHeight;
|
|
251
|
+
track.classList.toggle('looping', copies[0].offsetHeight > list.clientHeight);
|
|
252
|
+
if (!moving) return;
|
|
253
|
+
y += (SCROLL_PX_S * dt) / 1000;
|
|
254
|
+
if (y >= cycle) y -= cycle;
|
|
255
|
+
track.style.transform = `translateY(${(-y).toFixed(1)}px)`;
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
el: box,
|
|
259
|
+
update(sessions) {
|
|
260
|
+
const now = Date.now();
|
|
261
|
+
const all = [];
|
|
262
|
+
for (const s of sessions) {
|
|
263
|
+
const root = (s.agents ?? []).find((a) => a.depth === 0);
|
|
264
|
+
for (const e of s.recent ?? []) all.push({ ...e, sid: s.id, who: e.agentId === root?.id ? (s.bot ? `${S.list.bot} · ${s.bot}` : rootTitle(s)) : e.agent, role: e.agentId === root?.id ? (s.bot ? 'bot' : 'root') : 'agent' });
|
|
265
|
+
}
|
|
266
|
+
all.sort((a, b) => a.start - b.start);
|
|
267
|
+
for (const e of all) { const pair = rows.get(e.id); if (pair) paintRow(pair, e); }
|
|
268
|
+
const first = seen.size === 0;
|
|
269
|
+
const fresh = all.filter((e) => !seen.has(e.id)).slice(-EVENTS);
|
|
270
|
+
for (const e of fresh) { seen.add(e.id); add(e, !first); }
|
|
271
|
+
const keep = new Set([...rows.keys(), ...all.map((e) => e.id)]);
|
|
272
|
+
for (const id of seen) if (!keep.has(id)) seen.delete(id);
|
|
273
|
+
none.hidden = rows.size > 0;
|
|
274
|
+
track.hidden = rows.size === 0;
|
|
275
|
+
count.textContent = S.home.perMin(all.filter((e) => e.start > now - 60000).length);
|
|
276
|
+
if (!raf) raf = requestAnimationFrame(frame);
|
|
277
|
+
},
|
|
278
|
+
destroy() { cancelAnimationFrame(raf); },
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function rootTitle(s) {
|
|
283
|
+
return s.bot ? `${S.list.bot} · ${s.title && !s.routine ? s.title : s.bot}` : s.title || s.project || S.list.untitled;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function nowText(a, now) {
|
|
287
|
+
if (!a) return '';
|
|
288
|
+
if (a.status !== 'running') return `${S.home.mark[a.status] ?? S.home.mark.ok}${a.end ? ` ${fmtDuration(a.end - a.start)}` : ''}`; // one line: the name keeps the room
|
|
289
|
+
if (a.now) return `${a.now}${a.nowStart ? ` · ${fmtDuration(now - a.nowStart)}` : ''}`;
|
|
290
|
+
return S.home.thinking;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function createHome({ onOpen, fetchLive, fetchSystem }) {
|
|
294
|
+
const root = el('div', 'home');
|
|
295
|
+
const hud = createHud();
|
|
296
|
+
const flow = el('section', 'h-flow');
|
|
297
|
+
const head = el('div', 'h-flow-head');
|
|
298
|
+
head.append(el('span', 'h-tile-k', S.home.flow), el('span', 'h-flow-live num'));
|
|
299
|
+
const lanesBox = el('div', 'h-lanes');
|
|
300
|
+
// what ran earlier today, finished: the same lanes, quiet
|
|
301
|
+
const pastHead = el('div', 'h-flow-head h-past-head');
|
|
302
|
+
const pastCount = el('span', 'h-flow-live num');
|
|
303
|
+
pastHead.append(el('span', 'h-tile-k', S.home.earlier), pastCount);
|
|
304
|
+
const pastBox = el('div', 'h-lanes h-past');
|
|
305
|
+
flow.append(head, lanesBox, pastHead, pastBox);
|
|
306
|
+
const stream = createStream();
|
|
307
|
+
const body = el('div', 'h-body');
|
|
308
|
+
body.append(flow, stream.el);
|
|
309
|
+
root.append(hud.el, body);
|
|
310
|
+
root.addEventListener('click', (e) => {
|
|
311
|
+
const n = e.target.closest('[data-sid]');
|
|
312
|
+
if (n) onOpen(n.dataset.sid, n.dataset.aid || null);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
const lanes = new Map(); // session id -> { el, svg, rootBtn, cols, chips: Map, lane }
|
|
316
|
+
const lastCalls = new Map(); // agent id -> calls seen
|
|
317
|
+
let sparks = 0;
|
|
318
|
+
let prevT = 0;
|
|
319
|
+
const seenCalls = new Map(); // agent id -> calls at the last look (calls/min)
|
|
320
|
+
let rate = 0;
|
|
321
|
+
let timers = [];
|
|
322
|
+
let alive = true;
|
|
323
|
+
|
|
324
|
+
function chipFor(lane, a, sid) {
|
|
325
|
+
let c = lane.chips.get(a.id);
|
|
326
|
+
if (!c) {
|
|
327
|
+
const b = el('button', 'h-node agent');
|
|
328
|
+
b.type = 'button';
|
|
329
|
+
b.dataset.sid = sid;
|
|
330
|
+
b.dataset.aid = a.id;
|
|
331
|
+
const tileBox = el('span', 'h-orb');
|
|
332
|
+
tileBox.append(providerTile(a.model));
|
|
333
|
+
const txt = el('span', 'h-nd-t');
|
|
334
|
+
const nm = el('span', 'h-nm');
|
|
335
|
+
const now = el('span', 'h-now num');
|
|
336
|
+
txt.append(nm, now);
|
|
337
|
+
b.append(tileBox, txt);
|
|
338
|
+
c = { el: b, nm, now };
|
|
339
|
+
lane.chips.set(a.id, c);
|
|
340
|
+
}
|
|
341
|
+
c.nm.textContent = a.name;
|
|
342
|
+
return c;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function laneFor(s) {
|
|
346
|
+
let l = lanes.get(s.id);
|
|
347
|
+
if (!l) {
|
|
348
|
+
const box = el('div', 'h-lane');
|
|
349
|
+
const svg = svgEl('svg', { class: 'h-lane-wires', 'aria-hidden': 'true' });
|
|
350
|
+
const rootBtn = el('button', 'h-node root');
|
|
351
|
+
rootBtn.type = 'button';
|
|
352
|
+
rootBtn.dataset.sid = s.id;
|
|
353
|
+
const orb = el('span', 'h-orb');
|
|
354
|
+
const txt = el('span', 'h-nd-t');
|
|
355
|
+
const nm = el('span', 'h-nm');
|
|
356
|
+
const now = el('span', 'h-now num');
|
|
357
|
+
const meta = el('span', 'h-meta num');
|
|
358
|
+
txt.append(nm, now, meta);
|
|
359
|
+
rootBtn.append(orb, txt);
|
|
360
|
+
const c1 = el('div', 'h-lane-col');
|
|
361
|
+
const c2 = el('div', 'h-lane-col');
|
|
362
|
+
box.append(svg, rootBtn, c1, c2);
|
|
363
|
+
l = { el: box, svg, rootBtn, orb, nm, now, meta, cols: [c1, c2], chips: new Map(), wires: new Map(), model: null };
|
|
364
|
+
lanes.set(s.id, l);
|
|
365
|
+
}
|
|
366
|
+
return l;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function place(parent, kids) {
|
|
370
|
+
const same = parent.children.length === kids.length && kids.every((k, i) => parent.children[i] === k);
|
|
371
|
+
if (!same) parent.replaceChildren(...kids); // moving nodes restarts their animations: only when the order changed
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function paintLive(sessions, today = []) {
|
|
375
|
+
const now = Date.now();
|
|
376
|
+
const order = sessions.map((s) => paintLane(s, now, false));
|
|
377
|
+
const past = today.map((s) => paintLane(s, now, true));
|
|
378
|
+
let agents = 0;
|
|
379
|
+
for (const s of sessions) for (const a of s.agents ?? []) if (a.status === 'running') agents += 1;
|
|
380
|
+
const ids = new Set([...sessions, ...today].map((s) => s.id));
|
|
381
|
+
for (const [id, l] of lanes) if (!ids.has(id)) { l.el.remove(); lanes.delete(id); }
|
|
382
|
+
if (!sessions.length) lanesBox.replaceChildren(emptyNote());
|
|
383
|
+
else place(lanesBox, order);
|
|
384
|
+
place(pastBox, past);
|
|
385
|
+
pastHead.hidden = !past.length;
|
|
386
|
+
pastCount.textContent = past.length ? String(past.length) : '';
|
|
387
|
+
return { agents };
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function paintLane(s, now, past) {
|
|
391
|
+
const model = laneOf(s);
|
|
392
|
+
const l = laneFor(s);
|
|
393
|
+
l.model = model;
|
|
394
|
+
l.el.classList.toggle('bot', Boolean(s.bot));
|
|
395
|
+
l.el.classList.toggle('routine', Boolean(s.routine));
|
|
396
|
+
if (!l.orb.firstChild || l.orb.dataset.m !== (model.root?.model ?? s.models?.[0] ?? '')) {
|
|
397
|
+
l.orb.dataset.m = model.root?.model ?? s.models?.[0] ?? '';
|
|
398
|
+
l.orb.replaceChildren(providerTile(l.orb.dataset.m || null));
|
|
399
|
+
}
|
|
400
|
+
l.nm.replaceChildren(...(s.bot ? [el('span', 'badge bot', S.list.bot), document.createTextNode(s.routine ? s.title ?? s.bot : s.bot)] : [document.createTextNode(rootTitle(s))]));
|
|
401
|
+
l.el.classList.toggle('past', past);
|
|
402
|
+
const n = past ? null : nowOf(s.agents ?? []);
|
|
403
|
+
l.now.textContent = past ? S.home.endedAt(S.home.ended[s.status] ?? S.home.ended.ok, clockOf(s.end ?? s.lastWrite))
|
|
404
|
+
: n ? `${n.agent.depth > 0 ? `${n.agent.name} · ` : ''}${n.tool ?? S.home.thinking}${n.since ? ` · ${fmtDuration(now - n.since)}` : ''}` : s.background ? S.status.background : S.home.idle;
|
|
405
|
+
l.meta.textContent = S.home.rootMeta((s.agents?.length ?? 1), fmtDuration((past ? s.end ?? s.lastWrite : now) - (s.start || now)));
|
|
406
|
+
const cols = [[], []];
|
|
407
|
+
const keep = new Set();
|
|
408
|
+
for (const a of model.nodes) {
|
|
409
|
+
const c = chipFor(l, a, s.id);
|
|
410
|
+
c.now.textContent = nowText(a, now);
|
|
411
|
+
c.el.classList.toggle('off', a.status !== 'running');
|
|
412
|
+
c.el.classList.toggle('failed', a.status === 'error');
|
|
413
|
+
cols[a.col - 1].push(c.el);
|
|
414
|
+
keep.add(a.id);
|
|
415
|
+
}
|
|
416
|
+
for (const [id, c] of l.chips) if (!keep.has(id)) { c.el.remove(); l.chips.delete(id); }
|
|
417
|
+
const tail = [];
|
|
418
|
+
if (model.more) tail.push(el('span', 'h-node h-more num', S.home.more(model.more)));
|
|
419
|
+
if (model.done) {
|
|
420
|
+
const d = el('button', 'h-node h-done-chip num', S.home.done(model.done));
|
|
421
|
+
d.type = 'button';
|
|
422
|
+
d.dataset.sid = s.id;
|
|
423
|
+
tail.push(d);
|
|
424
|
+
}
|
|
425
|
+
place(l.cols[0], [...cols[0], ...tail]);
|
|
426
|
+
place(l.cols[1], cols[1]);
|
|
427
|
+
l.el.classList.toggle('solo', !cols[0].length && !tail.length);
|
|
428
|
+
return l.el;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function emptyNote() {
|
|
432
|
+
const n = el('div', 'h-flow-empty');
|
|
433
|
+
n.append(el('b', '', S.home.nothing), el('span', '', S.home.nothingHint));
|
|
434
|
+
return n;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// wires: from the main agent (or the agent it hangs from) to each working agent; redrawn after layout
|
|
438
|
+
function drawWires() {
|
|
439
|
+
for (const l of lanes.values()) {
|
|
440
|
+
const box = l.el.getBoundingClientRect();
|
|
441
|
+
if (!box.width) continue;
|
|
442
|
+
const at = (node, side) => {
|
|
443
|
+
const r = node.getBoundingClientRect();
|
|
444
|
+
return { x: (side === 'r' ? r.right : r.left) - box.left, y: r.top + r.height / 2 - box.top };
|
|
445
|
+
};
|
|
446
|
+
const paths = [];
|
|
447
|
+
const from = (a) => (a.from && a.from !== l.model.root?.id ? l.chips.get(a.from)?.el : l.rootBtn) ?? l.rootBtn;
|
|
448
|
+
for (const a of l.model.nodes) {
|
|
449
|
+
const c = l.chips.get(a.id);
|
|
450
|
+
if (c) paths.push({ id: a.id, a: at(from(a), 'r'), b: at(c.el, 'l'), run: a.status === 'running' });
|
|
451
|
+
}
|
|
452
|
+
for (const n of l.cols[0].querySelectorAll('.h-done-chip, .h-more')) paths.push({ id: `~${n.className}`, a: at(l.rootBtn, 'r'), b: at(n, 'l'), run: false });
|
|
453
|
+
const keep = new Set();
|
|
454
|
+
for (const p of paths) {
|
|
455
|
+
const dx = Math.max(24, (p.b.x - p.a.x) / 2);
|
|
456
|
+
const d = `M${p.a.x.toFixed(1)} ${p.a.y.toFixed(1)} C${(p.a.x + dx).toFixed(1)} ${p.a.y.toFixed(1)} ${(p.b.x - dx).toFixed(1)} ${p.b.y.toFixed(1)} ${p.b.x.toFixed(1)} ${p.b.y.toFixed(1)}`;
|
|
457
|
+
let w = l.wires.get(p.id);
|
|
458
|
+
if (!w) { w = svgEl('path'); l.svg.append(w); l.wires.set(p.id, w); }
|
|
459
|
+
w.setAttribute('d', d);
|
|
460
|
+
w.setAttribute('class', p.run ? 'h-wire run' : 'h-wire');
|
|
461
|
+
keep.add(p.id);
|
|
462
|
+
}
|
|
463
|
+
for (const [id, w] of l.wires) if (!keep.has(id)) { w.remove(); l.wires.delete(id); }
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// a dot runs down the wire of an agent that made calls since the last look: activity, not decoration
|
|
468
|
+
function sparkle(sessions) {
|
|
469
|
+
if (reduceMotion() || document.hidden) return;
|
|
470
|
+
for (const s of sessions) {
|
|
471
|
+
const l = lanes.get(s.id);
|
|
472
|
+
for (const a of s.agents ?? []) {
|
|
473
|
+
const before = lastCalls.get(a.id);
|
|
474
|
+
lastCalls.set(a.id, a.calls ?? 0);
|
|
475
|
+
if (before === undefined || (a.calls ?? 0) <= before || sparks >= SPARKS_MAX) continue;
|
|
476
|
+
const w = l?.wires.get(a.id);
|
|
477
|
+
if (!w) continue;
|
|
478
|
+
const len = w.getTotalLength();
|
|
479
|
+
const dot = svgEl('circle', { class: 'h-spark-dot', r: 3 });
|
|
480
|
+
l.svg.append(dot);
|
|
481
|
+
sparks += 1;
|
|
482
|
+
const t0 = performance.now();
|
|
483
|
+
const step = (t) => {
|
|
484
|
+
const k = Math.min(1, (t - t0) / 900);
|
|
485
|
+
const p = w.getPointAtLength(len * (1 - (1 - k) ** 2));
|
|
486
|
+
dot.setAttribute('cx', p.x.toFixed(1));
|
|
487
|
+
dot.setAttribute('cy', p.y.toFixed(1));
|
|
488
|
+
dot.style.opacity = String(k < 0.85 ? 1 : (1 - k) / 0.15);
|
|
489
|
+
if (k < 1 && alive) requestAnimationFrame(step);
|
|
490
|
+
else { dot.remove(); sparks -= 1; }
|
|
491
|
+
};
|
|
492
|
+
requestAnimationFrame(step);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const ro = new ResizeObserver(() => drawWires());
|
|
498
|
+
ro.observe(lanesBox);
|
|
499
|
+
|
|
500
|
+
let busyLive = false;
|
|
501
|
+
let busySys = false;
|
|
502
|
+
async function pollLive() {
|
|
503
|
+
if (document.hidden || busyLive) return; // one request at a time
|
|
504
|
+
busyLive = true;
|
|
505
|
+
try {
|
|
506
|
+
const { sessions, today } = await fetchLive();
|
|
507
|
+
if (!alive) return;
|
|
508
|
+
const t = Date.now();
|
|
509
|
+
const { agents } = paintLive(sessions, today ?? []);
|
|
510
|
+
const r = callsPerMin(sessions, seenCalls, prevT ? t - prevT : 0);
|
|
511
|
+
if (prevT) {
|
|
512
|
+
rate = rate * 0.5 + r * 0.5;
|
|
513
|
+
actHist.push({ t, rate, working: agents });
|
|
514
|
+
trim(actHist, t);
|
|
515
|
+
}
|
|
516
|
+
prevT = t;
|
|
517
|
+
hud.live({ sessions: sessions.length, agents, rate });
|
|
518
|
+
stream.update([...sessions, ...(today ?? [])]); // calls of what ran earlier today too: the log is never blank between runs
|
|
519
|
+
head.lastChild.textContent = S.home.flowCount(sessions.length);
|
|
520
|
+
requestAnimationFrame(() => { drawWires(); sparkle(sessions); });
|
|
521
|
+
} catch { /* offline: the next poll tries again */ } finally { busyLive = false; }
|
|
522
|
+
}
|
|
523
|
+
async function pollSystem() {
|
|
524
|
+
if (document.hidden || busySys) return;
|
|
525
|
+
busySys = true;
|
|
526
|
+
try {
|
|
527
|
+
const s = await fetchSystem(sysHist.at(-1)?.t ?? 0);
|
|
528
|
+
if (!alive) return;
|
|
529
|
+
mergeHistory(sysHist, s.history);
|
|
530
|
+
trim(sysHist, s.t);
|
|
531
|
+
hud.system(s);
|
|
532
|
+
} catch { /* next poll */ } finally { busySys = false; }
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
return {
|
|
536
|
+
el: root,
|
|
537
|
+
start() {
|
|
538
|
+
if (timers.length) return;
|
|
539
|
+
pollLive();
|
|
540
|
+
pollSystem();
|
|
541
|
+
timers = [setInterval(pollLive, LIVE_MS), setInterval(pollSystem, SYS_MS)];
|
|
542
|
+
},
|
|
543
|
+
destroy() {
|
|
544
|
+
alive = false;
|
|
545
|
+
stream.destroy();
|
|
546
|
+
timers.forEach(clearInterval);
|
|
547
|
+
timers = [];
|
|
548
|
+
ro.disconnect();
|
|
549
|
+
root.remove();
|
|
550
|
+
},
|
|
551
|
+
};
|
|
552
|
+
}
|
package/web/index.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
</head>
|
|
15
15
|
<body data-view="list">
|
|
16
16
|
<header class="top">
|
|
17
|
-
<div class="brand"><!-- same mark as the app icon (scripts/build-app-icons.js) --><svg class="brand-mark" viewBox="0 0 100 100" aria-hidden="true"><defs><linearGradient id="brandMarkG" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#4c6ef5"/><stop offset="1" stop-color="#0c8599"/></linearGradient></defs><rect width="100" height="100" rx="22.5" fill="url(#brandMarkG)"/><path d="M50 31L31 69M50 31L69 69" stroke="#fff" stroke-width="6.4" stroke-linecap="round"/><circle cx="50" cy="31" r="9.5" fill="#fff"/><circle cx="31" cy="69" r="8.5" fill="#fff"/><circle cx="69" cy="69" r="8.5" fill="#fff"/></svg><span id="appName"></span><span class="ver num" id="ver"></span><span class="upd" id="upd" hidden></span></div>
|
|
17
|
+
<div class="brand"><a class="brand-home" id="brandHome" href="/"><!-- same mark as the app icon (scripts/build-app-icons.js) --><svg class="brand-mark" viewBox="0 0 100 100" aria-hidden="true"><defs><linearGradient id="brandMarkG" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#4c6ef5"/><stop offset="1" stop-color="#0c8599"/></linearGradient></defs><rect width="100" height="100" rx="22.5" fill="url(#brandMarkG)"/><path d="M50 31L31 69M50 31L69 69" stroke="#fff" stroke-width="6.4" stroke-linecap="round"/><circle cx="50" cy="31" r="9.5" fill="#fff"/><circle cx="31" cy="69" r="8.5" fill="#fff"/><circle cx="69" cy="69" r="8.5" fill="#fff"/></svg><span id="appName"></span></a><span class="ver num" id="ver"></span><span class="upd" id="upd" hidden></span></div>
|
|
18
18
|
<div class="spacer"></div>
|
|
19
19
|
<span class="live" id="live"><span class="dot" id="liveDot"></span><span id="liveText"></span></span>
|
|
20
20
|
<button class="icon-btn" id="themeBtn" type="button">◐</button>
|
package/web/session-list.js
CHANGED
|
@@ -220,8 +220,24 @@ export function mount(box, { onSelect, getSelected, onFilter, getGroups = () =>
|
|
|
220
220
|
grpChips.setAttribute('role', 'group');
|
|
221
221
|
grpChips.setAttribute('aria-label', S.groups.label);
|
|
222
222
|
head.append(search, filters, chips, grpChips);
|
|
223
|
+
// Home sits above the list, outside the filters: a filter that matches nothing cannot hide it
|
|
224
|
+
const home = el('button', 'sess home-row');
|
|
225
|
+
home.type = 'button';
|
|
226
|
+
home.dataset.id = '';
|
|
227
|
+
home.title = S.home.rowTip;
|
|
228
|
+
const homeT = el('div', 't');
|
|
229
|
+
const house = document.createElementNS(SVG, 'svg');
|
|
230
|
+
house.setAttribute('viewBox', '0 0 24 24');
|
|
231
|
+
house.setAttribute('class', 'home-ico');
|
|
232
|
+
house.setAttribute('aria-hidden', 'true');
|
|
233
|
+
const roof = document.createElementNS(SVG, 'path');
|
|
234
|
+
roof.setAttribute('d', 'M3.5 11 12 4l8.5 7M6 9.5V20h4.5v-5.5h3V20H18V9.5');
|
|
235
|
+
house.append(roof);
|
|
236
|
+
const homeN = el('span', 'home-n num');
|
|
237
|
+
homeT.append(house, el('span', 'name', S.home.row), homeN);
|
|
238
|
+
home.append(homeT);
|
|
223
239
|
const body = el('div', 'list-body');
|
|
224
|
-
box.replaceChildren(head, body);
|
|
240
|
+
box.replaceChildren(head, home, body);
|
|
225
241
|
|
|
226
242
|
function note(text, ...extra) {
|
|
227
243
|
const n = el('div', 'note', text);
|
|
@@ -249,6 +265,9 @@ export function mount(box, { onSelect, getSelected, onFilter, getGroups = () =>
|
|
|
249
265
|
add.title = S.groups.dropHint;
|
|
250
266
|
grpChips.replaceChildren(...chipsOut, add);
|
|
251
267
|
}
|
|
268
|
+
home.setAttribute('aria-current', String(!getSelected()));
|
|
269
|
+
const live = data.sessions?.filter((s) => s.status === 'running').length ?? 0;
|
|
270
|
+
homeN.replaceChildren(...(live ? [el('span', 'dot pulse'), document.createTextNode(String(live))] : []));
|
|
252
271
|
const { sessions, error } = data;
|
|
253
272
|
if (!sessions) return void body.replaceChildren(note(error ? S.list.loadFailed : S.list.loading));
|
|
254
273
|
if (!sessions.length) return void body.replaceChildren(note(S.list.none));
|
package/web/strings.js
CHANGED
|
@@ -3,6 +3,22 @@ export const S = {
|
|
|
3
3
|
appName: 'Run Inspector',
|
|
4
4
|
theme: { toggle: 'Switch light / dark', toDark: 'Switch to dark theme', toLight: 'Switch to light theme' },
|
|
5
5
|
live: { connected: 'Live · 127.0.0.1', connecting: 'Connecting…', reconnecting: 'Disconnected · reconnecting…', retry: 'Reconnect' },
|
|
6
|
+
home: {
|
|
7
|
+
row: 'Home', rowTip: 'This machine and everything running now',
|
|
8
|
+
cpu: 'CPU', memory: 'Memory', load: 'Load', live: 'Agents at work', callsMin: 'calls/min',
|
|
9
|
+
cores: (n) => `${n} cores`, memOf: (gb) => `in use · ${gb} GB`, loadAvg: (a, b) => `5m ${a} · 15m ${b}`,
|
|
10
|
+
agentsUnit: ' working', liveSub: (n, r) => `${n} ${n === 1 ? 'session' : 'sessions'} · ${r} calls/min`,
|
|
11
|
+
flow: 'Live flow', flowCount: (n) => (n ? `${n} running` : ''),
|
|
12
|
+
thinking: 'Thinking', idle: 'Waiting for its agents',
|
|
13
|
+
rootMeta: (n, t) => `${n} ${n === 1 ? 'agent' : 'agents'} · ${t}`,
|
|
14
|
+
done: (n) => `+${n} more done`, more: (n) => `+${n} more working`,
|
|
15
|
+
ended: { ok: '✓ Done', error: '▲ Failed', cancelled: 'Stopped', unknown: 'Ended' },
|
|
16
|
+
mark: { ok: '✓', error: '▲', cancelled: '■', unknown: '·' },
|
|
17
|
+
earlier: 'Earlier today', endedAt: (word, t) => `${word} · ${t}`,
|
|
18
|
+
events: 'Event stream', loop: '↻ from the start', eventsNone: 'Calls show up here as agents work.', perMin: (n) => `${n}/min`,
|
|
19
|
+
model: 'Model', at: (t, v) => `${t} · ${v}`, ago: (m) => (m ? `-${m}m` : 'now'),
|
|
20
|
+
nothing: 'Nothing is running right now.', nothingHint: 'Start Claude Code or Codex: its agents show up here as they work.',
|
|
21
|
+
},
|
|
6
22
|
mini: {
|
|
7
23
|
none: 'Nothing running right now.', offline: 'The inspector service is not answering.',
|
|
8
24
|
running: (n) => (n ? `Running · ${n}` : 'Running'),
|