ai-agentmanager 1.47.0 → 1.48.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/CHANGELOG.md +10 -0
- package/README.md +15 -0
- package/package.json +1 -1
- package/public/app.js +23 -4
- package/public/index.html +4 -0
- package/public/keys.js +3 -2
- package/public/style.css +28 -2
- package/public/system.js +151 -0
- package/src/cli.js +21 -0
- package/src/server.js +9 -0
- package/src/system.js +239 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.48.0 (2026-11-13)
|
|
4
|
+
|
|
5
|
+
- **OS.** **OS** in the top bar (or `u`, `#os`, `agentmgr os`) shows the computer the agents run on and how loaded it is right now: the processor in use and the load average against the number of cores, memory and swap, and the free space on your disks, with a line of the last ten minutes for processor and memory. A tag sums it up: light load, busy or heavy load.
|
|
6
|
+
- **What takes it.** Each open agent session with the processor and memory it takes, counting everything it started (click a name to open the agent), and the busiest processes on the whole computer. Also the basics: name, system, kernel, processor and cores, memory, uptime, addresses and the app's version. It reads again every 3 seconds while open; nothing leaves the computer.
|
|
7
|
+
- **Running, as a filter.** **N running** above the agent list is clickable: it lists only the agents whose session is open; click again for all.
|
|
8
|
+
|
|
9
|
+
## 1.47.1 (2026-11-13)
|
|
10
|
+
|
|
11
|
+
- **Lists scroll on a small screen.** In AI News, Plan and Bugs the list ran past the bottom of the window on a phone (or any screen shorter than the list) and was cut off; it now scrolls inside the window.
|
|
12
|
+
|
|
3
13
|
## 1.47.0 (2026-11-13)
|
|
4
14
|
|
|
5
15
|
- **Plan.** **Plan** in the top bar (or `c`, `#plan`) has three tabs: Dates, Decisions and Debt. Its badge counts dates that are late or at risk.
|
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ Run one background [Claude Code](https://claude.com/claude-code) agent per inten
|
|
|
30
30
|
- **Plan.** A project's commitment dates (code complete, release candidate, GA) with a checklist of what is still open for each, reminders as they come near, and an at-risk or late flag. A **decision log** gathered from plan reviews, your answers and design docs. A **tech debt radar** from git history and the code. What is open can be handed to an agent.
|
|
31
31
|
- **Your day.** Connect your calendar and Today lays the day out around your meetings: the free time between them with what needs you placed in it, and what each meeting is about.
|
|
32
32
|
- **Debug.** Say what to debug (a failure, E2E instability at max scale, slowness under load) in the **Debug** tab beside an agent's session. The agent investigates there and writes a report next to it: animated diagrams of the code path and the data flow with where it breaks, findings with evidence, likely causes and recommended fixes. It changes no code until you press **Apply fixes**.
|
|
33
|
+
- **OS.** The computer the agents run on and how loaded it is right now: processor, load average, memory, swap and disks with the last ten minutes, what each open agent session takes, and the busiest processes.
|
|
33
34
|
- **AI News.** The frontier labs' latest releases in one list, newest first: Claude Platform, Claude Code, the OpenAI API and the Gemini API from their release notes, and the other top labs from a daily web search. Each is summarized in a sentence or two, with its links.
|
|
34
35
|
- **MCP servers and tools.** See every MCP server Claude Code has in a folder (yours, the project's, claude.ai connectors and plugins) with its tools, sign in to the ones that need it, and run any tool directly, through Claude Code, or in an agent's session.
|
|
35
36
|
- **Human vs AI.** It splits the open questions about the work into the top 5 that need your judgment and the ones a model can answer from the evidence. It answers those, then a second model double-checks every answer.
|
|
@@ -189,6 +190,7 @@ agentmgr debug <agent> "what goes wrong" # debug with an agent; no questio
|
|
|
189
190
|
agentmgr dates <project> --cc 2026-12-01 --rc 2026-12-10 --ga 2026-12-20 # commitment dates; no dates: where each stands
|
|
190
191
|
agentmgr decisions [project] [--md] # the decision log; --add "<question>" --decision "<what>" adds one
|
|
191
192
|
agentmgr debt <project> --scan # the tech debt radar: files that change often and are hard to read
|
|
193
|
+
agentmgr os # this computer and its load: processor, memory, disks, what each open session takes (--json)
|
|
192
194
|
agentmgr news # the frontier labs' latest releases, summarized (--refresh, --lab, --days)
|
|
193
195
|
agentmgr inbox # prompts, questions, stuck agents and overlaps waiting on you
|
|
194
196
|
agentmgr answer <agent> <question-id> "…" # answer a question from the inbox
|
|
@@ -1237,6 +1239,19 @@ The agent investigates in its own session, with everything it already knows abou
|
|
|
1237
1239
|
|
|
1238
1240
|
`agentmgr debug <agent> "<what goes wrong>"` asks from the terminal, `agentmgr debug <agent>` prints the report, and `--fix ["1 and 3"]` applies fixes.
|
|
1239
1241
|
|
|
1242
|
+
## OS
|
|
1243
|
+
|
|
1244
|
+
**OS** in the top bar (or `u`, `#os`, or `agentmgr os`) shows the computer the agents run on and how loaded it is right now:
|
|
1245
|
+
|
|
1246
|
+
- **Load**: the processor in use and the load average against the number of cores, memory and swap in use, and the free space on the disks under your home folder and the app's data. Processor and memory come with a line of their last ten minutes. A word sums it up: light load, busy, or heavy load.
|
|
1247
|
+
- **This computer**: its name, system and kernel, processor and cores, memory, how long it has been up, its network addresses, and the app's version and uptime.
|
|
1248
|
+
- **Agent sessions**: each open session with the processor and memory it takes, counting everything it started (Claude Code, the tools and tests it runs). Click a name to open the agent.
|
|
1249
|
+
- **Busiest processes**: the top of everything running on the computer.
|
|
1250
|
+
|
|
1251
|
+
It reads again every 3 seconds while open, with `ps` and the system's own counters; nothing leaves the computer.
|
|
1252
|
+
|
|
1253
|
+
Above the agent list, **N running** is a filter: click it to list only the agents whose session is open, and again to list them all.
|
|
1254
|
+
|
|
1240
1255
|
## AI News
|
|
1241
1256
|
|
|
1242
1257
|
**AI News** in the top bar (or `l`, `#news`, or `agentmgr news`) lists what the frontier labs released in the last 30 days, newest first and grouped by day. Each entry has its lab, a summary of a sentence or two, a link to the release and the links from the note. Filter by lab or by words. What arrived since you last looked is marked *new* and counted on the button.
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -40,6 +40,7 @@ import { drawDiagram } from '/diagram.js';
|
|
|
40
40
|
import { initValue } from '/value.js';
|
|
41
41
|
import { initNews } from '/news.js';
|
|
42
42
|
import { initPlan } from '/plan.js';
|
|
43
|
+
import { initSystem } from '/system.js';
|
|
43
44
|
import { initMcp } from '/mcp.js';
|
|
44
45
|
import { initCodeMap } from '/codemap.js';
|
|
45
46
|
import { initKeys } from '/keys.js';
|
|
@@ -71,13 +72,16 @@ const valueOnLoad = hashId === 'value';
|
|
|
71
72
|
const newsOnLoad = hashId === 'news';
|
|
72
73
|
// "#plan" or "#plan/<dates|decisions|debt>".
|
|
73
74
|
const planOnLoad = hashId === 'plan';
|
|
75
|
+
const osOnLoad = hashId === 'os';
|
|
74
76
|
const reviewsOnLoad = hashId === 'reviews';
|
|
75
77
|
// "#mcp" or "#mcp/<agent>": the MCP window on its own.
|
|
76
78
|
const mcpOnLoad = hashId === 'mcp';
|
|
77
79
|
let watchShown = false;
|
|
78
|
-
let selectedId = (watchOnLoad || standupOnLoad || mapOnLoad || valueOnLoad || newsOnLoad || planOnLoad || reviewsOnLoad || mcpOnLoad ? null : hashId) || null;
|
|
80
|
+
let selectedId = (watchOnLoad || standupOnLoad || mapOnLoad || valueOnLoad || newsOnLoad || planOnLoad || osOnLoad || reviewsOnLoad || mcpOnLoad ? null : hashId) || null;
|
|
79
81
|
let openTermOnLoad = hashView === 'term' || hashView === 'code' || isShell(hashView) || isBrowser(hashView);
|
|
80
82
|
let filterText = '';
|
|
83
|
+
// Only agents whose session is open (the "running" count above the list, clicked).
|
|
84
|
+
let listRunning = false;
|
|
81
85
|
// "Only agents created in the last N days": remembered in this browser.
|
|
82
86
|
const recent = (() => {
|
|
83
87
|
try {
|
|
@@ -323,6 +327,9 @@ const planUi = initPlan({
|
|
|
323
327
|
},
|
|
324
328
|
});
|
|
325
329
|
$('#plan-btn').onclick = () => planUi.open();
|
|
330
|
+
// OS: this computer and its load right now.
|
|
331
|
+
const osUi = initSystem({ api, $, esc, toast: (m, ms) => toast(m, ms), openAgent: (id) => (showTab('agents'), select(id)) });
|
|
332
|
+
$('#os-btn').onclick = () => osUi.open();
|
|
326
333
|
// MCP: the MCP servers and tools Claude Code has in a folder, and running one.
|
|
327
334
|
const mcpUi = initMcp({ api, $, esc, ago, md: (t) => md(t), toast: (m, ms) => toast(m, ms), agents: () => [...agents.values()] });
|
|
328
335
|
$('#mcp-btn').onclick = () => mcpUi.open(selectedId && agents.get(selectedId)?.workdir ? selectedId : null);
|
|
@@ -378,6 +385,7 @@ function shortcut(act) {
|
|
|
378
385
|
if (act === 'value') return valueUi.open();
|
|
379
386
|
if (act === 'news') return newsUi.open();
|
|
380
387
|
if (act === 'plan') return planUi.open();
|
|
388
|
+
if (act === 'os') return osUi.open();
|
|
381
389
|
if (act === 'today') return todayUi.open();
|
|
382
390
|
if (act.startsWith('tab:')) return showTab(act.slice(4));
|
|
383
391
|
return false;
|
|
@@ -1177,7 +1185,9 @@ function renderList() {
|
|
|
1177
1185
|
const at = filterText.startsWith('@') ? filterText.slice(1) : null;
|
|
1178
1186
|
renderProjectPicker([...agents.values()]);
|
|
1179
1187
|
const list = [...agents.values()].filter((a) =>
|
|
1180
|
-
|
|
1188
|
+
listRunning && !a.runtime.running
|
|
1189
|
+
? false
|
|
1190
|
+
: listProject && (a.projectInfo?.key ?? 'other') !== listProject
|
|
1181
1191
|
? false
|
|
1182
1192
|
: !filterText
|
|
1183
1193
|
? true
|
|
@@ -1201,7 +1211,7 @@ function renderList() {
|
|
|
1201
1211
|
const running = all.filter((a) => a.runtime.running).length;
|
|
1202
1212
|
const open = all.filter((a) => a.runtime.running && a.kind !== 'assistant').length;
|
|
1203
1213
|
$('#counts').innerHTML = agents.size
|
|
1204
|
-
? `<span title="Projects">${projects} project${projects === 1 ? '' : 's'}</span><span>${agents.size} agents</span><
|
|
1214
|
+
? `<span title="Projects">${projects} project${projects === 1 ? '' : 's'}</span><span>${agents.size} agents</span><button class="link count-running${listRunning ? ' active' : ''}" id="running-btn" aria-pressed="${listRunning}" title="${listRunning ? 'Showing only agents whose session is open. Click to show all' : 'Show only the agents whose session is open'}">${running} running${listRunning ? ' ✕' : ''}</button>
|
|
1205
1215
|
${waiting ? `<span class="fail">${waiting} need${waiting === 1 ? 's' : ''} input</span>` : ''}
|
|
1206
1216
|
<span class="spacer"></span><button class="link" id="import-btn" title="Continue Claude sessions you started in a terminal or the Claude desktop app on this machine">Import</button>${open ? `<button class="link" id="close-all-btn" title="Close every open agent session (the assistant's stays); they resume when you open them">Close all</button>` : ''}<button class="link" id="flush-btn" title="Save session IDs, terminal scrollback and state to disk now (also automatic every 30s)">Save now</button>`
|
|
1207
1217
|
: '';
|
|
@@ -1217,7 +1227,7 @@ function renderList() {
|
|
|
1217
1227
|
const total = totals.get(g.key) ?? g.agents.length;
|
|
1218
1228
|
const n = g.agents.length;
|
|
1219
1229
|
// While filtering, show every match; otherwise respect collapsed projects.
|
|
1220
|
-
const open = filterText || !collapsed.has(g.key) || g.agents.some((a) => a.id === selectedId);
|
|
1230
|
+
const open = filterText || listRunning || !collapsed.has(g.key) || g.agents.some((a) => a.id === selectedId);
|
|
1221
1231
|
return `<li class="project ${open ? 'open' : ''}" data-key="${esc(g.key)}" data-move="${esc(dropRef(g))}">
|
|
1222
1232
|
<button class="project-head" data-toggle="${esc(g.key)}" aria-expanded="${open}" title="${esc(g.full || g.name)}">
|
|
1223
1233
|
<span class="caret">${open ? '▾' : '▸'}</span>
|
|
@@ -3719,6 +3729,10 @@ async function closeAll(working = false) {
|
|
|
3719
3729
|
|
|
3720
3730
|
$('#counts').addEventListener('click', (e) => {
|
|
3721
3731
|
if (e.target.id === 'import-btn') return openImport();
|
|
3732
|
+
if (e.target.id === 'running-btn') {
|
|
3733
|
+
listRunning = !listRunning;
|
|
3734
|
+
return renderList();
|
|
3735
|
+
}
|
|
3722
3736
|
if (e.target.id === 'close-all-btn') return closeAll();
|
|
3723
3737
|
if (e.target.id !== 'flush-btn') return;
|
|
3724
3738
|
act(async () => {
|
|
@@ -4445,6 +4459,11 @@ function handleEvent(msg) {
|
|
|
4445
4459
|
history.replaceState(null, '', '#');
|
|
4446
4460
|
planUi.open(hashView || 'dates');
|
|
4447
4461
|
}
|
|
4462
|
+
if (osOnLoad && !watchShown) {
|
|
4463
|
+
watchShown = true;
|
|
4464
|
+
history.replaceState(null, '', '#');
|
|
4465
|
+
osUi.open();
|
|
4466
|
+
}
|
|
4448
4467
|
if (newsOnLoad && !watchShown) {
|
|
4449
4468
|
watchShown = true;
|
|
4450
4469
|
history.replaceState(null, '', '#');
|
package/public/index.html
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
<button id="map-btn" title="The codebase map: where each agent is changing and reading code, and who is about to collide">Map</button>
|
|
46
46
|
<button id="watch-btn" title="Running agents' sessions side by side, live: follow them all without clicking from one to the next">Watch</button>
|
|
47
47
|
<button id="mcp-btn" title="MCP: the MCP servers Claude Code has (yours, projects', claude.ai connectors and plugins), their tools, and running one in an agent's session or workspace">MCP</button>
|
|
48
|
+
<button id="os-btn" title="OS: this computer and how loaded it is right now: processor, memory, disks, what each open agent session takes, and the busiest processes">OS</button>
|
|
48
49
|
<button id="machine-btn" title="A terminal on this computer (your home folder), from any device you're signed in on">Terminal</button>
|
|
49
50
|
<button id="ask-btn" title="A general session with no repo or folder, on Claude Code or another engine you have (Codex, Muse Code, …)">Ask Agent</button>
|
|
50
51
|
<div class="menu-wrap top-more" id="top-more" hidden>
|
|
@@ -421,6 +422,9 @@
|
|
|
421
422
|
<dialog id="plan-dialog" class="issues-dialog plan-dialog" aria-label="Plan">
|
|
422
423
|
<div id="plan-body"></div>
|
|
423
424
|
</dialog>
|
|
425
|
+
<dialog id="os-dialog" class="issues-dialog os-dialog" aria-label="OS">
|
|
426
|
+
<div id="os-body"></div>
|
|
427
|
+
</dialog>
|
|
424
428
|
<dialog id="news-dialog" class="issues-dialog news-dialog" aria-label="AI News">
|
|
425
429
|
<div id="news-body"></div>
|
|
426
430
|
</dialog>
|
package/public/keys.js
CHANGED
|
@@ -29,6 +29,7 @@ export const SHORTCUTS = [
|
|
|
29
29
|
[['v'], 'Value: what the work is worth', 'value'],
|
|
30
30
|
[['l'], 'AI News: the latest frontier releases', 'news'],
|
|
31
31
|
[['c'], 'Plan: project dates, decisions and tech debt', 'plan'],
|
|
32
|
+
[['u'], 'OS: this computer and its load', 'os'],
|
|
32
33
|
[['1'], 'Agents tab', 'tab:agents'],
|
|
33
34
|
[['2'], 'Inbox: what needs you', 'tab:inbox'],
|
|
34
35
|
[['3'], 'Backlog', 'tab:backlog'],
|
|
@@ -72,11 +73,11 @@ export const SHORTCUTS = [
|
|
|
72
73
|
// A single key, as an event names it, to its action.
|
|
73
74
|
export const SINGLE = {
|
|
74
75
|
j: 'next', k: 'prev', Enter: 'terminal', t: 'terminal',
|
|
75
|
-
r: 'changes', s: 'start', X: 'stop', e: 'edit', n: 'new', a: 'ask', '/': 'filter', w: 'watch', p: 'standup', m: 'map', i: 'issues', o: 'actions', h: 'assistant', ',': 'settings', d: 'designs', g: 'reviews', v: 'value', l: 'news', c: 'plan', y: 'today', b: 'bugs', '?': 'help',
|
|
76
|
+
r: 'changes', s: 'start', X: 'stop', e: 'edit', n: 'new', a: 'ask', '/': 'filter', w: 'watch', p: 'standup', m: 'map', i: 'issues', o: 'actions', h: 'assistant', ',': 'settings', d: 'designs', g: 'reviews', v: 'value', l: 'news', c: 'plan', u: 'os', y: 'today', b: 'bugs', '?': 'help',
|
|
76
77
|
1: 'tab:agents', 2: 'tab:inbox', 3: 'tab:backlog', 4: 'tab:land', 5: 'tab:built',
|
|
77
78
|
};
|
|
78
79
|
// While Watch is open: only what makes sense there.
|
|
79
|
-
const ON_WATCH = new Set(['today', 'new', 'ask', 'watch', 'standup', 'map', 'issues', 'actions', 'assistant', 'settings', 'designs', 'reviews', 'value', 'news', 'plan', 'bugs', 'help']);
|
|
80
|
+
const ON_WATCH = new Set(['today', 'new', 'ask', 'watch', 'standup', 'map', 'issues', 'actions', 'assistant', 'settings', 'designs', 'reviews', 'value', 'news', 'plan', 'os', 'bugs', 'help']);
|
|
80
81
|
|
|
81
82
|
/** Typing somewhere: a field, an editor or a terminal (xterm types through a textarea). */
|
|
82
83
|
const typing = (el) => Boolean(el?.closest?.('input, textarea, select, [contenteditable=""], [contenteditable="true"], .xterm, .cm-editor'));
|
package/public/style.css
CHANGED
|
@@ -1291,7 +1291,7 @@ table.bench-cases tr.faster td:nth-child(5) { color: var(--green); font-weight:
|
|
|
1291
1291
|
.issues-dialog { width: min(1100px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 16px; }
|
|
1292
1292
|
/* Only while open: a display on the dialog itself would keep a closed one on screen. */
|
|
1293
1293
|
.issues-dialog[open] { display: flex; flex-direction: column; }
|
|
1294
|
-
#issues-body, #actions-body, #designs-body, #reviews-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
|
|
1294
|
+
#issues-body, #actions-body, #designs-body, #reviews-body, #bugs-body, #plan-body, #news-body, #os-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
|
|
1295
1295
|
/* The lists: drag the corner to any size, or fill the window (⤢ or f). */
|
|
1296
1296
|
.issues-dialog { resize: both; overflow: hidden; min-width: min(520px, calc(100% - 32px)); min-height: 240px; max-width: calc(100% - 16px); max-height: calc(100% - 16px); }
|
|
1297
1297
|
.issues-dialog.expanded { width: calc(100% - 16px); height: calc(100% - 16px); }
|
|
@@ -1304,7 +1304,7 @@ table.bench-cases tr.faster td:nth-child(5) { color: var(--green); font-weight:
|
|
|
1304
1304
|
.issues-head .chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; }
|
|
1305
1305
|
.issues-head .chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
|
|
1306
1306
|
.issues-head .chip .count { opacity: 0.75; margin-left: 2px; }
|
|
1307
|
-
.issues-scroll { overflow: auto; min-height: 0; border: 1px solid var(--border); border-radius: var(--radius); }
|
|
1307
|
+
.issues-scroll { overflow: auto; -webkit-overflow-scrolling: touch; min-height: 0; border: 1px solid var(--border); border-radius: var(--radius); }
|
|
1308
1308
|
table.issues { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
1309
1309
|
table.issues th { position: sticky; top: 0; background: var(--panel-2); text-align: left; font-weight: 600; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
|
|
1310
1310
|
table.issues td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
|
|
@@ -1448,6 +1448,32 @@ table.plan-debt .plan-score b { position: relative; padding-left: 6px; }
|
|
|
1448
1448
|
.plan-bar-fill { position: absolute; left: 0; top: 6px; bottom: 6px; background: color-mix(in srgb, var(--red) 22%, transparent); border-radius: 3px; }
|
|
1449
1449
|
table.plan-debt code { overflow-wrap: anywhere; }
|
|
1450
1450
|
/* AI News: a day heading, then each release with its lab, summary and links. */
|
|
1451
|
+
/* ---------- OS: this computer and its load */
|
|
1452
|
+
.os-dialog { width: min(1080px, calc(100% - 32px)); }
|
|
1453
|
+
.os-scroll { border: 0; }
|
|
1454
|
+
.os-host { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
|
|
1455
|
+
.os-level.light { color: var(--green); }
|
|
1456
|
+
.os-level.busy { color: var(--yellow); }
|
|
1457
|
+
.os-level.heavy { color: var(--red); border-color: var(--red); }
|
|
1458
|
+
.os-meter { height: 6px; margin: 4px 0 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
|
|
1459
|
+
.os-meter span { display: block; height: 100%; border-radius: 3px; background: var(--green); transition: width .4s; }
|
|
1460
|
+
.os-meter.busy span { background: var(--yellow); }
|
|
1461
|
+
.os-meter.heavy span { background: var(--red); }
|
|
1462
|
+
.os-spark { display: block; width: 100%; height: 44px; margin-top: 8px; font-size: 12px; }
|
|
1463
|
+
svg.os-spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
|
|
1464
|
+
svg.os-spark polygon { fill: color-mix(in srgb, var(--accent) 14%, transparent); }
|
|
1465
|
+
.os-disk + .os-disk { margin-top: 8px; }
|
|
1466
|
+
.os-cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 18px; }
|
|
1467
|
+
.os-cols h3 { margin: 10px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
|
|
1468
|
+
.os-facts { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
1469
|
+
.os-facts th { text-align: left; font-weight: 400; color: var(--muted); padding: 4px 12px 4px 0; white-space: nowrap; vertical-align: top; }
|
|
1470
|
+
.os-facts td { padding: 4px 0; overflow-wrap: anywhere; }
|
|
1471
|
+
table.os-table { width: 100%; }
|
|
1472
|
+
table.os-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
1473
|
+
@media (max-width: 760px) { .os-cols { grid-template-columns: minmax(0, 1fr); } }
|
|
1474
|
+
#counts .count-running { padding: 0; font-size: inherit; text-decoration: underline dotted; text-underline-offset: 3px; cursor: pointer; }
|
|
1475
|
+
#counts .count-running.active { color: var(--accent); font-weight: 600; }
|
|
1476
|
+
|
|
1451
1477
|
.news-dialog { width: min(980px, calc(100% - 32px)); }
|
|
1452
1478
|
.news-find { width: 150px; }
|
|
1453
1479
|
.news-source.failed, .news-source.failed a { color: var(--red); }
|
package/public/system.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// OS: the computer the agents run on and how loaded it is right now. The basics (name, system,
|
|
2
|
+
// processor, memory, disks), the load with its last ten minutes, what each open agent session
|
|
3
|
+
// takes, and the busiest processes. Read again every few seconds while the window is open.
|
|
4
|
+
|
|
5
|
+
import { expandButton, expandable } from './expand.js';
|
|
6
|
+
import { morph } from './morph.js';
|
|
7
|
+
|
|
8
|
+
const EVERY_MS = 3000;
|
|
9
|
+
const LEVEL = { light: 'Light load', busy: 'Busy', heavy: 'Heavy load' };
|
|
10
|
+
|
|
11
|
+
/** 1536 MB, 12.4 GB. */
|
|
12
|
+
export const bytes = (n) => (n >= 1024 ** 3 ? `${(n / 1024 ** 3).toFixed(1)} GB` : `${Math.round((n ?? 0) / 1024 ** 2)} MB`);
|
|
13
|
+
/** 3d 4h, 5h 12m, 9m. */
|
|
14
|
+
export const span = (sec) => (sec >= 86400 ? `${Math.floor(sec / 86400)}d ${Math.floor((sec % 86400) / 3600)}h` : sec >= 3600 ? `${Math.floor(sec / 3600)}h ${Math.floor((sec % 3600) / 60)}m` : `${Math.floor(sec / 60)}m`);
|
|
15
|
+
|
|
16
|
+
export function initSystem({ api, $, esc, toast, openAgent }) {
|
|
17
|
+
const dialog = $('#os-dialog');
|
|
18
|
+
const body = $('#os-body');
|
|
19
|
+
let data = null;
|
|
20
|
+
let problem = null;
|
|
21
|
+
let timer = null;
|
|
22
|
+
|
|
23
|
+
async function load() {
|
|
24
|
+
try {
|
|
25
|
+
data = await api('GET', '/system');
|
|
26
|
+
problem = null;
|
|
27
|
+
} catch (e) {
|
|
28
|
+
problem = e.message;
|
|
29
|
+
}
|
|
30
|
+
if (dialog.open) render();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const tone = (p) => (p >= 90 ? 'heavy' : p >= 70 ? 'busy' : 'light');
|
|
34
|
+
const meter = (p) => `<div class="os-meter ${tone(p)}" role="img" aria-label="${p}%"><span style="width:${Math.min(100, Math.max(0, p))}%"></span></div>`;
|
|
35
|
+
|
|
36
|
+
/** The last ten minutes of one measure (0 to 100) as a small line. */
|
|
37
|
+
function spark(points, label) {
|
|
38
|
+
if (points.length < 2) return '<div class="os-spark hint">Its last ten minutes are drawn as they pass.</div>';
|
|
39
|
+
const w = 240;
|
|
40
|
+
const h = 44;
|
|
41
|
+
const top = Math.max(100, ...points);
|
|
42
|
+
const xy = points.map((v, i) => `${((i / (points.length - 1)) * w).toFixed(1)},${(h - 2 - (v / top) * (h - 4)).toFixed(1)}`);
|
|
43
|
+
return `<svg class="os-spark" viewBox="0 0 ${w} ${h}" preserveAspectRatio="none" role="img" aria-label="${esc(label)}">
|
|
44
|
+
<polygon points="0,${h} ${xy.join(' ')} ${w},${h}"></polygon><polyline points="${xy.join(' ')}"></polyline></svg>`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const row = (k, v) => (v ? `<tr><th>${esc(k)}</th><td>${v}</td></tr>` : '');
|
|
48
|
+
|
|
49
|
+
function draw() {
|
|
50
|
+
if (!data) return `<div class="issues-head"><h2>OS</h2><span class="spacer"></span><button class="small" data-os="close">Close</button></div><p class="hint">${problem ? esc(problem) : 'Loading…'}</p>`;
|
|
51
|
+
const { host, cpu, memory: mem, disks, agents, processes, app, history } = data;
|
|
52
|
+
const minutes = Math.max(1, Math.round((history.length * data.sampleSeconds) / 60));
|
|
53
|
+
return `
|
|
54
|
+
<div class="issues-head">
|
|
55
|
+
<h2>OS</h2>
|
|
56
|
+
<span class="tag os-level ${esc(data.level)}" title="From the processor in use, the load per core and the memory in use">${esc(LEVEL[data.level] ?? data.level)}</span>
|
|
57
|
+
<span class="hint os-host">${esc(host.name)} · ${esc(host.os)}</span>
|
|
58
|
+
<span class="spacer"></span>
|
|
59
|
+
${expandButton(dialog)}
|
|
60
|
+
<button class="small" data-os="close" title="Close (Esc)">Close</button>
|
|
61
|
+
</div>
|
|
62
|
+
${problem ? `<p class="issues-problem">${esc(problem)}</p>` : ''}
|
|
63
|
+
<div class="issues-scroll os-scroll">
|
|
64
|
+
<div class="value-cards os-cards">
|
|
65
|
+
<div class="value-card" data-os-card="cpu">
|
|
66
|
+
<div class="hint">Processor</div>
|
|
67
|
+
<div class="value-big">${cpu.percent}%</div>
|
|
68
|
+
${meter(cpu.percent)}
|
|
69
|
+
<div class="hint" title="How many processes wanted the processor, averaged over 1, 5 and 15 minutes. Above the number of cores (${cpu.cores}), work is waiting">Load ${cpu.load.map((l) => l.toFixed(2)).join(' · ')} on ${cpu.cores} cores</div>
|
|
70
|
+
${spark(history.map((p) => p.cpu), `Processor in use, last ${minutes} minutes`)}
|
|
71
|
+
</div>
|
|
72
|
+
<div class="value-card" data-os-card="memory">
|
|
73
|
+
<div class="hint">Memory</div>
|
|
74
|
+
<div class="value-big">${mem.percent}%</div>
|
|
75
|
+
${meter(mem.percent)}
|
|
76
|
+
<div class="hint">${bytes(mem.used)} of ${bytes(mem.total)} in use${mem.swap ? ` · swap ${bytes(mem.swap.used)} of ${bytes(mem.swap.total)}` : ''}</div>
|
|
77
|
+
${spark(history.map((p) => p.mem), `Memory in use, last ${minutes} minutes`)}
|
|
78
|
+
</div>
|
|
79
|
+
<div class="value-card" data-os-card="disk">
|
|
80
|
+
<div class="hint">Disk</div>
|
|
81
|
+
${disks.length
|
|
82
|
+
? disks.map((d) => `<div class="os-disk" title="${esc(d.path)}"><div class="value-big">${d.percent}%</div>${meter(d.percent)}<div class="hint">${esc(d.label)}: ${bytes(d.free)} free of ${bytes(d.total)}</div></div>`).join('')
|
|
83
|
+
: '<div class="hint">Not available on this system.</div>'}
|
|
84
|
+
</div>
|
|
85
|
+
<div class="value-card" data-os-card="agents">
|
|
86
|
+
<div class="hint">Agent sessions</div>
|
|
87
|
+
<div class="value-big">${agents.open}</div>
|
|
88
|
+
<div class="hint">open${agents.open ? `, taking ${agents.cpu}% of a core and ${bytes(agents.mem)}` : ''}</div>
|
|
89
|
+
<div class="hint" title="AI Agent Manager's own background process">The app itself: ${bytes(app.mem)}${app.cpu != null ? ` · ${app.cpu}%` : ''}</div>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
<div class="os-cols">
|
|
93
|
+
<section>
|
|
94
|
+
<h3>This computer</h3>
|
|
95
|
+
<table class="os-facts"><tbody>
|
|
96
|
+
${row('Name', esc(host.name))}
|
|
97
|
+
${row('System', esc(host.os))}
|
|
98
|
+
${row('Kernel', `${esc(host.kernel)} · ${esc(host.arch)}`)}
|
|
99
|
+
${row('Processor', cpu.model ? `${esc(cpu.model)} · ${cpu.cores} cores` : `${cpu.cores} cores`)}
|
|
100
|
+
${row('Memory', bytes(mem.total))}
|
|
101
|
+
${row('Up for', span(host.uptime))}
|
|
102
|
+
${row('User', host.user ? esc(host.user) : '')}
|
|
103
|
+
${row('Addresses', host.addresses.map((a) => `${esc(a.address)} <span class="hint">${esc(a.nic)}</span>`).join(', '))}
|
|
104
|
+
${row('AI Agent Manager', `${app.version ? `${esc(app.version)} · ` : ''}up ${span(app.uptime)} · Node ${esc(app.node.replace(/^v/, ''))}`)}
|
|
105
|
+
</tbody></table>
|
|
106
|
+
</section>
|
|
107
|
+
<section>
|
|
108
|
+
<h3>Agent sessions <span class="hint">${agents.open}</span></h3>
|
|
109
|
+
${agents.list.length
|
|
110
|
+
? `<table class="issues os-table"><thead><tr><th>Agent</th><th class="num" title="Of one core: 200% is two cores busy">Processor</th><th class="num">Memory</th><th class="num" title="The session and everything it started">Processes</th></tr></thead><tbody>
|
|
111
|
+
${agents.list.map((a) => `<tr><td><button class="link" data-os-agent="${esc(a.id)}">${esc(a.name)}</button></td><td class="num">${a.cpu}%</td><td class="num">${bytes(a.mem)}</td><td class="num">${a.count}</td></tr>`).join('')}
|
|
112
|
+
</tbody></table>`
|
|
113
|
+
: '<p class="hint">No agent session is open.</p>'}
|
|
114
|
+
<h3>Busiest processes <span class="hint">of ${processes.count}</span></h3>
|
|
115
|
+
<table class="issues os-table"><thead><tr><th>Process</th><th class="num" title="Of one core: 200% is two cores busy">Processor</th><th class="num">Memory</th><th class="num">PID</th></tr></thead><tbody>
|
|
116
|
+
${processes.top.map((p) => `<tr><td title="${esc(p.command)}">${esc(p.name)}</td><td class="num">${p.cpu}%</td><td class="num">${bytes(p.mem)}</td><td class="num hint">${p.pid}</td></tr>`).join('')}
|
|
117
|
+
</tbody></table>
|
|
118
|
+
</section>
|
|
119
|
+
</div>
|
|
120
|
+
<p class="hint">Read again every ${EVERY_MS / 1000} seconds while this is open. Processor and memory per process come from <code>ps</code>; nothing leaves this computer.</p>
|
|
121
|
+
</div>`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Redrawn in place, so the list keeps its scroll and a pointer over a row doesn't lose it.
|
|
125
|
+
const render = () => morph(body, draw());
|
|
126
|
+
|
|
127
|
+
body.addEventListener('click', (e) => {
|
|
128
|
+
if (e.target.closest('[data-os="close"]')) return dialog.close();
|
|
129
|
+
const a = e.target.closest('[data-os-agent]');
|
|
130
|
+
if (a) {
|
|
131
|
+
dialog.close();
|
|
132
|
+
openAgent?.(a.dataset.osAgent);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
dialog.addEventListener('close', () => {
|
|
137
|
+
clearInterval(timer);
|
|
138
|
+
timer = null;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
function open() {
|
|
142
|
+
if (dialog.open) return dialog.close();
|
|
143
|
+
dialog.showModal();
|
|
144
|
+
render();
|
|
145
|
+
load().catch((e) => toast?.(e.message, 5000));
|
|
146
|
+
timer = setInterval(load, EVERY_MS);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
expandable(dialog, render);
|
|
150
|
+
return { open, isOpen: () => dialog.open };
|
|
151
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -823,6 +823,27 @@ export async function main(argv) {
|
|
|
823
823
|
}
|
|
824
824
|
});
|
|
825
825
|
|
|
826
|
+
program
|
|
827
|
+
.command('os')
|
|
828
|
+
.description('This computer and its load right now: processor, memory, disks, and what each open agent session takes')
|
|
829
|
+
.option('--json', 'print JSON')
|
|
830
|
+
.action(async (opts) => {
|
|
831
|
+
await daemon();
|
|
832
|
+
const v = await api('GET', '/system');
|
|
833
|
+
if (opts.json) return console.log(JSON.stringify(v, null, 2));
|
|
834
|
+
const gb = (n) => (n >= 1024 ** 3 ? `${(n / 1024 ** 3).toFixed(1)} GB` : `${Math.round(n / 1024 ** 2)} MB`);
|
|
835
|
+
const up = (sec) => (sec >= 86400 ? `${Math.floor(sec / 86400)}d ${Math.floor((sec % 86400) / 3600)}h` : sec >= 3600 ? `${Math.floor(sec / 3600)}h ${Math.floor((sec % 3600) / 60)}m` : `${Math.floor(sec / 60)}m`);
|
|
836
|
+
const tone = { light: green, busy: yellow, heavy: red }[v.level] ?? ((x) => x);
|
|
837
|
+
console.log(`${bold(v.host.name)} ${v.host.os} · ${v.host.arch} · up ${up(v.host.uptime)} ${tone(`load: ${v.level}`)}`);
|
|
838
|
+
console.log(`Processor ${v.cpu.percent}% of ${v.cpu.cores} cores · load ${v.cpu.load.join(' ')}${v.cpu.model ? dim(` ${v.cpu.model}`) : ''}`);
|
|
839
|
+
console.log(`Memory ${v.memory.percent}% · ${gb(v.memory.used)} of ${gb(v.memory.total)}${v.memory.swap ? ` · swap ${gb(v.memory.swap.used)} of ${gb(v.memory.swap.total)}` : ''}`);
|
|
840
|
+
for (const d of v.disks) console.log(`Disk ${d.percent}% · ${gb(d.free)} free of ${gb(d.total)} ${dim(`${d.label}: ${d.path}`)}`);
|
|
841
|
+
console.log(`Agents ${v.agents.open} open session${v.agents.open === 1 ? '' : 's'} · ${v.agents.cpu}% of a core · ${gb(v.agents.mem)}`);
|
|
842
|
+
for (const a of v.agents.list.slice(0, 10)) console.log(` ${String(a.cpu).padStart(6)}% ${gb(a.mem).padStart(9)} ${a.name}`);
|
|
843
|
+
console.log(dim('Busiest processes'));
|
|
844
|
+
for (const p of v.processes.top.slice(0, 8)) console.log(` ${String(p.cpu).padStart(6)}% ${gb(p.mem).padStart(9)} ${p.name} ${dim(String(p.pid))}`);
|
|
845
|
+
});
|
|
846
|
+
|
|
826
847
|
program
|
|
827
848
|
.command('news')
|
|
828
849
|
.description("AI News: the frontier labs' latest releases, each summarized, with links")
|
package/src/server.js
CHANGED
|
@@ -50,6 +50,7 @@ import { Builder } from './builder.js';
|
|
|
50
50
|
import { Standup } from './standup.js';
|
|
51
51
|
import { Value, valueSlack } from './value.js';
|
|
52
52
|
import { News } from './news.js';
|
|
53
|
+
import { System } from './system.js';
|
|
53
54
|
import { Milestones } from './milestones.js';
|
|
54
55
|
import { Decisions } from './decisions.js';
|
|
55
56
|
import { Debt } from './debt.js';
|
|
@@ -361,6 +362,12 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
361
362
|
});
|
|
362
363
|
const pkgVersion = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')).version;
|
|
363
364
|
// "Open on this machine" links from the hub point at remote access, when it's on.
|
|
365
|
+
// OS: this computer and its load right now, and what each open session takes (system.js).
|
|
366
|
+
const system = new System({
|
|
367
|
+
agents: () => store.list().map((x) => ({ id: x.id, name: x.name, pid: x.pid })),
|
|
368
|
+
folders: () => [['Home', os.homedir()], ['Agents and data', paths.home]],
|
|
369
|
+
version: pkgVersion,
|
|
370
|
+
});
|
|
364
371
|
const hubLink = new HubLink({ manager, config, backlog, version: pkgVersion, urls: () => (remoteServer ? linkUrls(remote.remoteUrls(remotePort)) : []) });
|
|
365
372
|
|
|
366
373
|
/** Returns an error string if the request may not proceed, else null. Sets req.device for remote sessions. */
|
|
@@ -1099,6 +1106,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
1099
1106
|
api.get('/calendar', wrap(() => calendar.status()));
|
|
1100
1107
|
api.put('/calendar', wrap((req) => calendar.set(req.body ?? {}, saveConfig)));
|
|
1101
1108
|
// AI News: the entries, a refresh now (answers at once; the page hears when it's done), and "seen".
|
|
1109
|
+
api.get('/system', wrap(() => system.view()));
|
|
1102
1110
|
api.get('/news', wrap(() => news.view()));
|
|
1103
1111
|
api.post('/news/refresh', wrap((req) => {
|
|
1104
1112
|
news.refresh({ search: req.body?.search === true ? true : null }).catch(() => {});
|
|
@@ -1596,6 +1604,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
1596
1604
|
standup.close();
|
|
1597
1605
|
value.close();
|
|
1598
1606
|
news.close();
|
|
1607
|
+
system.close();
|
|
1599
1608
|
milestones.close();
|
|
1600
1609
|
decisions.close();
|
|
1601
1610
|
debt.close();
|
package/src/system.js
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// OS: the computer the agents run on, and how loaded it is right now. The basics (name, system,
|
|
2
|
+
// processor, memory, disks, uptime), the load (processor, load average, memory, swap) with the last
|
|
3
|
+
// ten minutes of it, what each open agent session takes (its whole process tree), and the busiest
|
|
4
|
+
// processes. Read from the system itself with `ps` and the like; nothing is sent anywhere.
|
|
5
|
+
|
|
6
|
+
import { execFile } from 'node:child_process';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
|
|
11
|
+
const SAMPLE_MS = 5000;
|
|
12
|
+
const KEEP = 120; // ten minutes of samples
|
|
13
|
+
const run = (cmd, args, timeout = 4000) =>
|
|
14
|
+
new Promise((resolve) => execFile(cmd, args, { timeout, maxBuffer: 8 * 1024 * 1024 }, (e, out) => resolve(e ? '' : String(out))));
|
|
15
|
+
const pct = (part, whole) => (whole > 0 ? Math.round((part / whole) * 1000) / 10 : 0);
|
|
16
|
+
|
|
17
|
+
/** Processor time so far, summed over the cores: { busy, total } in ms. */
|
|
18
|
+
export function cpuTimes(cpus = os.cpus()) {
|
|
19
|
+
let busy = 0;
|
|
20
|
+
let total = 0;
|
|
21
|
+
for (const c of cpus) {
|
|
22
|
+
const t = c.times;
|
|
23
|
+
const all = t.user + t.nice + t.sys + t.irq + t.idle;
|
|
24
|
+
total += all;
|
|
25
|
+
busy += all - t.idle;
|
|
26
|
+
}
|
|
27
|
+
return { busy, total };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** `vm_stat` (macOS) as bytes: what is free or can be freed at once, and what is compressed. */
|
|
31
|
+
export function parseVmStat(text) {
|
|
32
|
+
const page = Number(text.match(/page size of (\d+) bytes/)?.[1] ?? 4096);
|
|
33
|
+
const n = (name) => Number(text.match(new RegExp(`^${name}:\\s+(\\d+)`, 'm'))?.[1] ?? 0) * page;
|
|
34
|
+
if (!/^Pages free:/m.test(text)) return null;
|
|
35
|
+
return {
|
|
36
|
+
available: n('Pages free') + n('Pages inactive') + n('Pages purgeable') + n('Pages speculative'),
|
|
37
|
+
wired: n('Pages wired down'),
|
|
38
|
+
compressed: n('Pages occupied by compressor'),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** `/proc/meminfo` (Linux) as bytes. */
|
|
43
|
+
export function parseMeminfo(text) {
|
|
44
|
+
const n = (name) => {
|
|
45
|
+
const m = text.match(new RegExp(`^${name}:\\s+(\\d+)\\s*kB`, 'm'));
|
|
46
|
+
return m ? Number(m[1]) * 1024 : null;
|
|
47
|
+
};
|
|
48
|
+
const total = n('MemTotal');
|
|
49
|
+
if (total === null) return null;
|
|
50
|
+
const swapTotal = n('SwapTotal') ?? 0;
|
|
51
|
+
return { total, available: n('MemAvailable') ?? (n('MemFree') ?? 0) + (n('Buffers') ?? 0) + (n('Cached') ?? 0), swap: { total: swapTotal, used: swapTotal - (n('SwapFree') ?? 0) } };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** `sysctl -n vm.swapusage` (macOS): "total = 2048.00M used = 1024.50M free = …". */
|
|
55
|
+
export function parseSwapUsage(text) {
|
|
56
|
+
const n = (name) => {
|
|
57
|
+
const m = text.match(new RegExp(`${name} = ([\\d.]+)([KMG])`));
|
|
58
|
+
return m ? Math.round(Number(m[1]) * { K: 1024, M: 1024 ** 2, G: 1024 ** 3 }[m[2]]) : null;
|
|
59
|
+
};
|
|
60
|
+
const total = n('total');
|
|
61
|
+
return total === null ? null : { total, used: n('used') ?? 0 };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** `ps -Ao pid=,ppid=,pcpu=,rss=,comm=` as [{ pid, ppid, cpu (% of one core), mem (bytes), name, command }]. */
|
|
65
|
+
export function parsePs(text) {
|
|
66
|
+
const out = [];
|
|
67
|
+
for (const line of String(text).split('\n')) {
|
|
68
|
+
const m = line.match(/^\s*(\d+)\s+(\d+)\s+([\d.,]+)\s+(\d+)\s+(.+?)\s*$/);
|
|
69
|
+
if (!m) continue;
|
|
70
|
+
const command = m[5];
|
|
71
|
+
out.push({ pid: Number(m[1]), ppid: Number(m[2]), cpu: Number(m[3].replace(',', '.')) || 0, mem: Number(m[4]) * 1024, name: command.startsWith('/') ? path.basename(command) : command, command });
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** What a process and everything under it takes: { cpu, mem, count }. */
|
|
77
|
+
export function treeUsage(procs, rootPid) {
|
|
78
|
+
const kids = new Map();
|
|
79
|
+
for (const p of procs) kids.set(p.ppid, [...(kids.get(p.ppid) ?? []), p]);
|
|
80
|
+
const root = procs.find((p) => p.pid === rootPid);
|
|
81
|
+
if (!root) return null;
|
|
82
|
+
let cpu = 0;
|
|
83
|
+
let mem = 0;
|
|
84
|
+
let count = 0;
|
|
85
|
+
const seen = new Set();
|
|
86
|
+
for (const todo = [root]; todo.length; ) {
|
|
87
|
+
const p = todo.pop();
|
|
88
|
+
if (seen.has(p.pid)) continue;
|
|
89
|
+
seen.add(p.pid);
|
|
90
|
+
cpu += p.cpu;
|
|
91
|
+
mem += p.mem;
|
|
92
|
+
count++;
|
|
93
|
+
todo.push(...(kids.get(p.pid) ?? []));
|
|
94
|
+
}
|
|
95
|
+
return { cpu: Math.round(cpu * 10) / 10, mem, count };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** How busy a computer is, in a word: load per core and memory in use decide it. */
|
|
99
|
+
export function loadLevel({ cpuPercent = 0, load1 = 0, cores = 1, memPercent = 0 } = {}) {
|
|
100
|
+
const perCore = load1 / Math.max(1, cores);
|
|
101
|
+
if (cpuPercent >= 90 || perCore >= 1.5 || memPercent >= 92) return 'heavy';
|
|
102
|
+
if (cpuPercent >= 60 || perCore >= 0.8 || memPercent >= 80) return 'busy';
|
|
103
|
+
return 'light';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** "macOS 15.1", "Ubuntu 24.04.1 LTS", or what the system calls itself. */
|
|
107
|
+
async function osName() {
|
|
108
|
+
if (process.platform === 'darwin') {
|
|
109
|
+
const v = (await run('sw_vers', ['-productVersion'])).trim();
|
|
110
|
+
if (v) return `macOS ${v}`;
|
|
111
|
+
}
|
|
112
|
+
if (process.platform === 'linux') {
|
|
113
|
+
try {
|
|
114
|
+
const pretty = fs.readFileSync('/etc/os-release', 'utf8').match(/^PRETTY_NAME="?([^"\n]+)"?/m)?.[1];
|
|
115
|
+
if (pretty) return pretty;
|
|
116
|
+
} catch {}
|
|
117
|
+
}
|
|
118
|
+
return `${os.type()} ${os.release()}`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function memory() {
|
|
122
|
+
const total = os.totalmem();
|
|
123
|
+
let available = os.freemem();
|
|
124
|
+
let swap = null;
|
|
125
|
+
let compressed = null;
|
|
126
|
+
if (process.platform === 'darwin') {
|
|
127
|
+
const [vm, sw] = await Promise.all([run('vm_stat', []), run('sysctl', ['-n', 'vm.swapusage'])]);
|
|
128
|
+
const v = parseVmStat(vm);
|
|
129
|
+
if (v) ({ available, compressed } = v);
|
|
130
|
+
swap = parseSwapUsage(sw);
|
|
131
|
+
} else if (process.platform === 'linux') {
|
|
132
|
+
try {
|
|
133
|
+
const m = parseMeminfo(fs.readFileSync('/proc/meminfo', 'utf8'));
|
|
134
|
+
if (m) ({ available, swap } = m);
|
|
135
|
+
} catch {}
|
|
136
|
+
}
|
|
137
|
+
available = Math.min(total, Math.max(0, available));
|
|
138
|
+
return { total, available, used: total - available, percent: pct(total - available, total), compressed, swap: swap?.total ? { ...swap, percent: pct(swap.used, swap.total) } : null };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The disks behind the folders named, one row a disk: [{ label, path, total, free, used, percent }]. */
|
|
142
|
+
async function disks(folders) {
|
|
143
|
+
const out = [];
|
|
144
|
+
const seen = new Set();
|
|
145
|
+
for (const [label, dir] of folders) {
|
|
146
|
+
try {
|
|
147
|
+
const s = await fs.promises.statfs(dir);
|
|
148
|
+
const total = s.blocks * s.bsize;
|
|
149
|
+
const free = s.bavail * s.bsize;
|
|
150
|
+
const key = `${total}:${s.bfree}`;
|
|
151
|
+
if (!total || seen.has(key)) continue;
|
|
152
|
+
seen.add(key);
|
|
153
|
+
out.push({ label, path: dir, total, free, used: total - free, percent: pct(total - free, total) });
|
|
154
|
+
} catch {}
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export class System {
|
|
160
|
+
/** `agents()` lists the agent records (id, name, pid of its open session); `folders()` the [label, dir] pairs whose disks to show. */
|
|
161
|
+
constructor({ agents = () => [], folders = () => [['Home', os.homedir()]], version = null, timer = true } = {}) {
|
|
162
|
+
Object.assign(this, { agents, folders, version });
|
|
163
|
+
this.history = [];
|
|
164
|
+
this.last = cpuTimes();
|
|
165
|
+
this.cpuPercent = 0;
|
|
166
|
+
this.started = Date.now();
|
|
167
|
+
if (timer) {
|
|
168
|
+
this.timer = setInterval(() => this.sample(), SAMPLE_MS);
|
|
169
|
+
this.timer.unref?.();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
close() {
|
|
174
|
+
clearInterval(this.timer);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** One more point of the last ten minutes: processor and memory in use. */
|
|
178
|
+
sample() {
|
|
179
|
+
const now = cpuTimes();
|
|
180
|
+
const total = now.total - this.last.total;
|
|
181
|
+
if (total > 0) this.cpuPercent = pct(now.busy - this.last.busy, total);
|
|
182
|
+
this.last = now;
|
|
183
|
+
this.history.push({ at: Date.now(), cpu: this.cpuPercent, mem: pct(os.totalmem() - os.freemem(), os.totalmem()), load: Math.round(os.loadavg()[0] * 100) / 100 });
|
|
184
|
+
if (this.history.length > KEEP) this.history.splice(0, this.history.length - KEEP);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async view() {
|
|
188
|
+
const cpus = os.cpus();
|
|
189
|
+
const cores = cpus.length || 1;
|
|
190
|
+
const [name, mem, disk, ps] = await Promise.all([(this.osName ??= osName()), memory(), disks(this.folders()), run('ps', ['-Ao', 'pid=,ppid=,pcpu=,rss=,comm='])]);
|
|
191
|
+
const procs = parsePs(ps);
|
|
192
|
+
// The memory in the history is the same measure as the one shown (what can't be freed at once).
|
|
193
|
+
if (this.history.length) this.history[this.history.length - 1].mem = mem.percent;
|
|
194
|
+
const load = os.loadavg().map((n) => Math.round(n * 100) / 100);
|
|
195
|
+
const sessions = this.agents()
|
|
196
|
+
.filter((a) => a.pid)
|
|
197
|
+
.map((a) => ({ id: a.id, name: a.name, pid: a.pid, ...(treeUsage(procs, a.pid) ?? { cpu: 0, mem: 0, count: 0 }) }))
|
|
198
|
+
.filter((a) => a.count)
|
|
199
|
+
.sort((x, y) => y.cpu - x.cpu || y.mem - x.mem);
|
|
200
|
+
const self = treeUsage(procs, process.pid);
|
|
201
|
+
const nets = Object.entries(os.networkInterfaces())
|
|
202
|
+
.flatMap(([nic, list]) => (list ?? []).filter((n) => !n.internal && n.family === 'IPv4').map((n) => ({ nic, address: n.address })));
|
|
203
|
+
return {
|
|
204
|
+
at: new Date().toISOString(),
|
|
205
|
+
level: loadLevel({ cpuPercent: this.cpuPercent, load1: load[0], cores, memPercent: mem.percent }),
|
|
206
|
+
host: {
|
|
207
|
+
name: os.hostname(),
|
|
208
|
+
os: name,
|
|
209
|
+
kernel: `${os.type()} ${os.release()}`,
|
|
210
|
+
arch: os.arch(),
|
|
211
|
+
uptime: Math.round(os.uptime()),
|
|
212
|
+
user: (() => {
|
|
213
|
+
try {
|
|
214
|
+
return os.userInfo().username;
|
|
215
|
+
} catch {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
})(),
|
|
219
|
+
addresses: nets,
|
|
220
|
+
},
|
|
221
|
+
cpu: { model: cpus[0]?.model?.trim() || null, cores, percent: this.cpuPercent, load, loadPerCore: Math.round((load[0] / cores) * 100) / 100 },
|
|
222
|
+
memory: mem,
|
|
223
|
+
disks: disk,
|
|
224
|
+
app: { version: this.version, node: process.version, pid: process.pid, uptime: Math.round((Date.now() - this.started) / 1000), mem: process.memoryUsage().rss, cpu: self?.cpu ?? null },
|
|
225
|
+
agents: {
|
|
226
|
+
open: sessions.length,
|
|
227
|
+
cpu: Math.round(sessions.reduce((n, a) => n + a.cpu, 0) * 10) / 10,
|
|
228
|
+
mem: sessions.reduce((n, a) => n + a.mem, 0),
|
|
229
|
+
list: sessions,
|
|
230
|
+
},
|
|
231
|
+
processes: {
|
|
232
|
+
count: procs.length,
|
|
233
|
+
top: [...procs].sort((x, y) => y.cpu - x.cpu || y.mem - x.mem).slice(0, 12).map(({ pid, cpu, mem: m, name: n, command }) => ({ pid, cpu, mem: m, name: n, command })),
|
|
234
|
+
},
|
|
235
|
+
history: this.history,
|
|
236
|
+
sampleSeconds: SAMPLE_MS / 1000,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|