ai-agentmanager 1.46.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 +19 -0
- package/README.md +79 -0
- package/package.json +1 -1
- package/public/app.js +51 -4
- package/public/index.html +9 -0
- package/public/keys.js +4 -2
- package/public/plan.js +323 -0
- package/public/style.css +87 -2
- package/public/system.js +151 -0
- package/public/today.js +102 -2
- package/src/calendar.js +385 -0
- package/src/cli.js +113 -0
- package/src/config.js +4 -0
- package/src/debt.js +276 -0
- package/src/decisions.js +188 -0
- package/src/milestones.js +282 -0
- package/src/notify.js +1 -0
- package/src/server.js +107 -3
- package/src/system.js +239 -0
- package/src/today.js +3 -1
package/public/plan.js
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
// Plan: looking ahead, in three tabs.
|
|
2
|
+
// Dates a project's commitments (code complete, release candidate, GA): how far each is,
|
|
3
|
+
// whether it is at risk, what is still open for it, and the reminders planned
|
|
4
|
+
// Decisions what was decided on each project and why, gathered from plan reviews, your answers
|
|
5
|
+
// and design docs, plus your own
|
|
6
|
+
// Debt where the code costs the most to change, from git history and the files themselves
|
|
7
|
+
// What is open can be handed to an agent from each (it goes to the backlog).
|
|
8
|
+
|
|
9
|
+
import { expandButton, expandable } from './expand.js';
|
|
10
|
+
|
|
11
|
+
const TABS = [
|
|
12
|
+
['dates', 'Dates'],
|
|
13
|
+
['decisions', 'Decisions'],
|
|
14
|
+
['debt', 'Debt'],
|
|
15
|
+
];
|
|
16
|
+
const SAVED = 'agentmgr.planTab';
|
|
17
|
+
const STATUS = { 'on-track': 'On track', 'at-risk': 'At risk', late: 'Late', reached: 'Reached' };
|
|
18
|
+
|
|
19
|
+
export function initPlan({ api, $, esc, ago, toast, projects = () => [], openTab = () => {} }) {
|
|
20
|
+
const dialog = $('#plan-dialog');
|
|
21
|
+
const body = $('#plan-body');
|
|
22
|
+
let tab = 'dates';
|
|
23
|
+
let data = {}; // per tab
|
|
24
|
+
let pending = false; // a change arrived while you were typing
|
|
25
|
+
let adding = false; // the "add dates" or "add a decision" form is open
|
|
26
|
+
const filter = { project: '', q: '' };
|
|
27
|
+
try {
|
|
28
|
+
tab = localStorage.getItem(SAVED) || 'dates';
|
|
29
|
+
} catch {}
|
|
30
|
+
if (!TABS.some(([k]) => k === tab)) tab = 'dates';
|
|
31
|
+
|
|
32
|
+
const route = () => (tab === 'dates' ? '/milestones' : tab === 'debt' ? '/debt' : `/decisions?project=${encodeURIComponent(filter.project)}&q=${encodeURIComponent(filter.q)}`);
|
|
33
|
+
async function load({ quiet = false } = {}) {
|
|
34
|
+
const t = tab;
|
|
35
|
+
try {
|
|
36
|
+
data[t] = await api('GET', route());
|
|
37
|
+
} catch (e) {
|
|
38
|
+
if (!quiet) toast?.(e.message, 5000);
|
|
39
|
+
}
|
|
40
|
+
if (t === 'dates') badge();
|
|
41
|
+
render();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** On the button: the dates that are late or at risk. */
|
|
45
|
+
function badge() {
|
|
46
|
+
const el = $('#plan-count');
|
|
47
|
+
if (!el || !data.dates) return;
|
|
48
|
+
const n = data.dates.projects.flatMap((p) => p.stages).filter((s) => s.status === 'late' || s.status === 'at-risk').length;
|
|
49
|
+
el.textContent = n ? String(n) : '';
|
|
50
|
+
el.title = n ? `${n} date${n === 1 ? '' : 's'} late or at risk` : '';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const day = (iso) => new Date(`${iso}T12:00:00`).toLocaleDateString([], { weekday: 'short', month: 'short', day: 'numeric' });
|
|
54
|
+
const typing = () => body.contains(document.activeElement) && /^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement.tagName);
|
|
55
|
+
|
|
56
|
+
// ------------------------------------------------------------ Dates
|
|
57
|
+
function dateInputs(stages, values = {}) {
|
|
58
|
+
return stages.map((s) => `<label class="plan-date">${esc(s.label)} <input type="date" name="${s.id}" value="${esc(values[s.id] ?? '')}" /></label>`).join('');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function checkItem(p, s, i) {
|
|
62
|
+
if (i.auto) {
|
|
63
|
+
return `<li class="plan-check ${i.ok ? 'ok' : 'open'}" title="${esc(i.names.join('\n'))}"><span class="plan-mark">${i.ok ? '✓' : i.count}</span><span>${esc(i.text)}</span>${!i.ok && i.go ? ` <button class="link" data-plan-go="${esc(i.go)}">Show</button>` : ''}</li>`;
|
|
64
|
+
}
|
|
65
|
+
return `<li class="plan-check ${i.done ? 'ok' : 'mine'}"><label><input type="checkbox" data-plan-check="${esc(p.shortcut)}|${s.id}|${esc(i.key)}" ${i.done ? 'checked' : ''} /> ${esc(i.text)}</label>${i.task && !i.done ? (i.asked ? ` <span class="hint">asked an agent ${esc(ago(i.asked))}</span>` : ` <button class="small" data-plan-task="${esc(p.shortcut)}|${s.id}|${esc(i.key)}" title="An agent does it: the task goes to this project's backlog">Have an agent do it</button>`) : ''}</li>`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function stageHtml(p, s) {
|
|
69
|
+
const reminders = s.reminders.map((r) => `<span class="plan-reminder${r.sent ? ' sent' : r.past ? ' past' : ''}" title="${esc(r.label)}${r.sent ? ': sent' : r.past ? ': passed before it was set' : ''}">${esc(day(r.on))}${r.sent ? ' ✓' : ''}</span>`).join('');
|
|
70
|
+
return `<section class="plan-stage ${esc(s.status)}">
|
|
71
|
+
<div class="plan-stage-head">
|
|
72
|
+
<b>${esc(s.label)}</b> <span class="hint">${esc(day(s.date))}</span>
|
|
73
|
+
<span class="tag plan-${esc(s.status)}">${esc(STATUS[s.status])}</span> <span class="plan-left">${esc(s.words)}</span>
|
|
74
|
+
<span class="spacer"></span>
|
|
75
|
+
<button class="small" data-plan-reach="${esc(p.shortcut)}|${s.id}|${s.reached ? '0' : '1'}" title="${s.reached ? 'Not reached after all: its reminders come back' : 'The date was met: no more reminders for it'}">${s.reached ? 'Not reached' : 'Mark reached'}</button>
|
|
76
|
+
</div>
|
|
77
|
+
<ul class="plan-checks">${s.checklist.map((i) => checkItem(p, s, i)).join('')}</ul>
|
|
78
|
+
${s.reached ? '' : `<div class="hint plan-reminders">Reminders: ${reminders}</div>`}
|
|
79
|
+
</section>`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function datesHtml() {
|
|
83
|
+
const d = data.dates;
|
|
84
|
+
if (!d) return '<p class="hint">Loading…</p>';
|
|
85
|
+
const form = adding
|
|
86
|
+
? `<form class="plan-form" data-plan-dates="">
|
|
87
|
+
<select name="project" required><option value="">pick a project</option>${d.others.map((p) => `<option value="${esc(p.shortcut)}">${esc(p.name)}</option>`).join('')}</select>
|
|
88
|
+
${dateInputs(d.stages)}
|
|
89
|
+
<button class="small primary">Save</button> <button type="button" class="small" data-plan="add">Cancel</button>
|
|
90
|
+
</form>`
|
|
91
|
+
: '';
|
|
92
|
+
const cards = d.projects
|
|
93
|
+
.map((p) => `<div class="plan-project">
|
|
94
|
+
<form class="plan-project-head" data-plan-dates="${esc(p.shortcut)}">
|
|
95
|
+
<h3>${esc(p.name)}</h3>
|
|
96
|
+
${dateInputs(d.stages, Object.fromEntries(p.stages.map((s) => [s.id, s.date])))}
|
|
97
|
+
<button class="small" title="Save the dates. A date that moves gets its reminders again; an emptied one is removed">Save dates</button>
|
|
98
|
+
</form>
|
|
99
|
+
<div class="plan-stages">${p.stages.map((s) => stageHtml(p, s)).join('')}</div>
|
|
100
|
+
</div>`)
|
|
101
|
+
.join('');
|
|
102
|
+
return `<p class="hint">A project's commitments and what stands between now and each. The app counts what it can see (agents still working, backlog, pull requests, serious bugs); you tick the rest, or hand it to an agent. A date a week or less away with counted work open is <b>at risk</b>. Reminders go to Slack ${d.remindDays.filter((n) => n).join(', ')} days before and on the day (Alerts), and the dates show in Today from two weeks out.</p>
|
|
103
|
+
<div class="plan-bar"><button class="small ${d.projects.length ? '' : 'primary'}" data-plan="add" ${d.others.length ? '' : 'disabled'}>+ Dates for a project</button></div>
|
|
104
|
+
${form}
|
|
105
|
+
${cards || (adding ? '' : '<p class="hint issues-empty">No dates yet. Add a project\'s code complete, release candidate and GA dates to get its checklists and reminders.</p>')}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ------------------------------------------------------------ Decisions
|
|
109
|
+
function decisionsList() {
|
|
110
|
+
const d = data.decisions;
|
|
111
|
+
if (!d) return '<p class="hint">Loading…</p>';
|
|
112
|
+
if (!d.items.length) return `<p class="hint issues-empty">${d.total ? 'Nothing matches.' : 'No decisions yet. They are gathered as you approve plans and answer agents\' questions, and from design docs; or add your own.'}</p>`;
|
|
113
|
+
return `<ul class="plan-decisions">${d.items
|
|
114
|
+
.map((i) => `<li class="plan-decision${i.superseded ? ' superseded' : ''}">
|
|
115
|
+
<div class="plan-decision-head"><b>${esc(i.title)}</b><span class="spacer"></span><button class="link" data-plan-remove="${esc(i.id)}" title="Take it off the log">×</button></div>
|
|
116
|
+
<div><span class="hint">Decided:</span> ${esc(i.decision)}</div>
|
|
117
|
+
${i.why ? `<div><span class="hint">Why:</span> ${esc(i.why)}</div>` : ''}
|
|
118
|
+
<div class="hint">${esc(i.project.name)} · ${esc(i.kindLabel)}${i.agentName ? ` · ${i.agentGone ? esc(i.agentName) : `<button class="link" data-plan-agent="${esc(i.agentId)}">${esc(i.agentName)}</button>`}` : ''} · <span title="${esc(new Date(i.at).toLocaleString())}">${esc(ago(i.at))}</span>${i.superseded ? ' · <b>replaced since</b>' : ''}</div>
|
|
119
|
+
</li>`)
|
|
120
|
+
.join('')}</ul>`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function decisionsHtml() {
|
|
124
|
+
const d = data.decisions;
|
|
125
|
+
const all = projects();
|
|
126
|
+
const form = adding
|
|
127
|
+
? `<form class="plan-form plan-decision-form" data-plan-decision>
|
|
128
|
+
<select name="project" required><option value="">pick a project</option>${all.map((p) => `<option value="${esc(p.key)}" ${p.key === filter.project ? 'selected' : ''}>${esc(p.name)}</option>`).join('')}</select>
|
|
129
|
+
<input name="title" placeholder="What was the question? (Cursor or offset paging)" required />
|
|
130
|
+
<input name="decision" placeholder="What was decided" required />
|
|
131
|
+
<input name="why" placeholder="Why (optional)" />
|
|
132
|
+
<button class="small primary">Add</button> <button type="button" class="small" data-plan="add">Cancel</button>
|
|
133
|
+
</form>`
|
|
134
|
+
: '';
|
|
135
|
+
return `<p class="hint">What was decided on each project and why: the plans you approved or sent back (with your notes), your answers to agents' questions, and the decisions in each design doc. They stay after the agent is deleted.</p>
|
|
136
|
+
<div class="plan-bar">
|
|
137
|
+
<select data-plan-project aria-label="Project"><option value="">All projects${d ? ` (${d.total})` : ''}</option>${(d?.projects ?? []).map((p) => `<option value="${esc(p.key)}" ${p.key === filter.project ? 'selected' : ''}>${esc(p.name)} (${p.count})</option>`).join('')}</select>
|
|
138
|
+
<input type="search" data-plan-find placeholder="Find…" value="${esc(filter.q)}" aria-label="Find a decision" />
|
|
139
|
+
<span class="spacer"></span>
|
|
140
|
+
<button class="small" data-plan="copy" title="The log${filter.project ? ' of this project' : ''} as Markdown, on the clipboard">Copy as Markdown</button>
|
|
141
|
+
<button class="small" data-plan="add" ${all.length ? '' : 'disabled'}>+ Add a decision</button>
|
|
142
|
+
</div>
|
|
143
|
+
${form}
|
|
144
|
+
<div id="plan-decisions-list">${decisionsList()}</div>`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ------------------------------------------------------------ Debt
|
|
148
|
+
function debtHtml() {
|
|
149
|
+
const d = data.debt;
|
|
150
|
+
if (!d) return '<p class="hint">Loading…</p>';
|
|
151
|
+
const cards = d.projects
|
|
152
|
+
.map((p) => {
|
|
153
|
+
const meta = p.scanning ? 'Scanning…' : p.error ? `<span class="fail">Couldn't scan: ${esc(p.error)}</span>` : p.at ? `Scanned ${esc(ago(p.at))}: ${p.commits} commits in ${p.days} days, ${p.scanned} changed files read${p.dismissed ? `, ${p.dismissed} set aside` : ''}` : p.hasRepo ? 'Not scanned yet' : 'No local repository yet: start an agent in it first';
|
|
154
|
+
const rows = p.spots
|
|
155
|
+
.map((h) => `<tr>
|
|
156
|
+
<td class="plan-score"><span class="plan-bar-fill" style="width:${h.score}%"></span><b>${h.score}</b></td>
|
|
157
|
+
<td><code>${esc(h.file)}</code><div class="hint">${esc(h.reasons.join(' · '))}</div></td>
|
|
158
|
+
<td class="nowrap">${h.queued ? `<span class="hint">handed over ${esc(ago(h.queued))}</span>` : `<button class="small" data-plan-debt="${esc(p.shortcut)}" data-file="${esc(h.file)}" title="An agent covers it with tests, then refactors in small steps: the task goes to this project's backlog">Hand to an agent</button>`} <button class="small" data-plan-notdebt="${esc(p.shortcut)}" data-file="${esc(h.file)}" title="Generated, or meant to be this way: off the list, also after the next scan">Not debt</button></td>
|
|
159
|
+
</tr>`)
|
|
160
|
+
.join('');
|
|
161
|
+
return `<div class="plan-project">
|
|
162
|
+
<div class="plan-project-head"><h3>${esc(p.name)}</h3><span class="hint">${meta}</span><span class="spacer"></span><button class="small" data-plan-scan="${esc(p.shortcut)}" ${p.hasRepo && !p.scanning ? '' : 'disabled'}>${p.at ? 'Scan again' : 'Scan'}</button></div>
|
|
163
|
+
${rows ? `<table class="issues plan-debt"><tbody>${rows}</tbody></table>` : p.at && !p.error ? '<p class="hint">No hot spots: nothing here is both changed often and hard to read.</p>' : ''}
|
|
164
|
+
</div>`;
|
|
165
|
+
})
|
|
166
|
+
.join('');
|
|
167
|
+
return `<p class="hint">Where the code costs the most to change: files that changed often in the last ${d.settings.days} days (and how many of those changes were fixes) and are tangled (long, branching, deeply nested, with TODOs), plus the open bugs found there. Read from git and the files; no model is called. Scanned again every ${d.settings.autoDays} days.</p>
|
|
168
|
+
${cards || '<p class="hint issues-empty">No projects yet.</p>'}`;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function draw() {
|
|
172
|
+
if (!dialog.open) return;
|
|
173
|
+
body.innerHTML = `
|
|
174
|
+
<div class="issues-head">
|
|
175
|
+
<h2>Plan</h2>
|
|
176
|
+
<div class="chips" role="tablist">${TABS.map(([k, label]) => `<button class="chip ${k === tab ? 'active' : ''}" role="tab" aria-selected="${k === tab}" data-plan-tab="${k}">${label}</button>`).join('')}</div>
|
|
177
|
+
<span class="spacer"></span>
|
|
178
|
+
<button class="small" data-plan="refresh" title="Look again">↻</button>
|
|
179
|
+
${expandButton(dialog)}
|
|
180
|
+
<button class="small" data-plan="close" title="Close (Esc)">Close</button>
|
|
181
|
+
</div>
|
|
182
|
+
<div class="issues-scroll plan-scroll">${tab === 'dates' ? datesHtml() : tab === 'decisions' ? decisionsHtml() : debtHtml()}</div>`;
|
|
183
|
+
}
|
|
184
|
+
// A change from the daemon doesn't take what you are typing: it is drawn when you are done.
|
|
185
|
+
function render() {
|
|
186
|
+
if (typing()) {
|
|
187
|
+
pending = true;
|
|
188
|
+
// The decision list can still follow the search box.
|
|
189
|
+
const list = body.querySelector('#plan-decisions-list');
|
|
190
|
+
if (tab === 'decisions' && list) list.innerHTML = decisionsList();
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
pending = false;
|
|
194
|
+
const top = body.querySelector('.plan-scroll')?.scrollTop ?? 0;
|
|
195
|
+
draw();
|
|
196
|
+
const sc = body.querySelector('.plan-scroll');
|
|
197
|
+
if (sc) sc.scrollTop = top;
|
|
198
|
+
}
|
|
199
|
+
body.addEventListener('focusout', () => setTimeout(() => pending && !typing() && render(), 0));
|
|
200
|
+
|
|
201
|
+
const run = async (fn, done) => {
|
|
202
|
+
try {
|
|
203
|
+
const r = await fn();
|
|
204
|
+
if (r && tab !== 'decisions') data[tab] = r;
|
|
205
|
+
if (done) toast?.(done, 2500);
|
|
206
|
+
} catch (e) {
|
|
207
|
+
toast?.(e.message, 6000);
|
|
208
|
+
}
|
|
209
|
+
document.activeElement?.blur?.();
|
|
210
|
+
if (tab === 'decisions') return load();
|
|
211
|
+
if (tab === 'dates') badge();
|
|
212
|
+
render();
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
body.addEventListener('submit', (e) => {
|
|
216
|
+
e.preventDefault();
|
|
217
|
+
const f = Object.fromEntries(new FormData(e.target));
|
|
218
|
+
if (e.target.matches('[data-plan-dates]')) {
|
|
219
|
+
const project = e.target.dataset.planDates || f.project;
|
|
220
|
+
if (!project) return toast?.('Pick a project', 3000);
|
|
221
|
+
adding = false;
|
|
222
|
+
return run(() => api('PUT', `/milestones/${encodeURIComponent(project)}`, { codeComplete: f.codeComplete || null, rc: f.rc || null, ga: f.ga || null }), 'Dates saved');
|
|
223
|
+
}
|
|
224
|
+
if (e.target.matches('[data-plan-decision]')) {
|
|
225
|
+
adding = false;
|
|
226
|
+
return run(() => api('POST', '/decisions', f), 'Added to the log');
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
let finding = null;
|
|
231
|
+
body.addEventListener('input', (e) => {
|
|
232
|
+
if (e.target.dataset.planFind === undefined) return;
|
|
233
|
+
filter.q = e.target.value;
|
|
234
|
+
clearTimeout(finding);
|
|
235
|
+
finding = setTimeout(() => load({ quiet: true }), 200);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
body.addEventListener('change', (e) => {
|
|
239
|
+
const c = e.target.dataset.planCheck;
|
|
240
|
+
if (c) {
|
|
241
|
+
const [project, stage, item] = c.split('|');
|
|
242
|
+
return run(() => api('POST', `/milestones/${encodeURIComponent(project)}/check`, { stage, item, done: e.target.checked }));
|
|
243
|
+
}
|
|
244
|
+
if (e.target.dataset.planProject !== undefined) {
|
|
245
|
+
filter.project = e.target.value;
|
|
246
|
+
e.target.blur();
|
|
247
|
+
load();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
body.addEventListener('click', async (e) => {
|
|
252
|
+
const t = e.target.closest('[data-plan-tab]');
|
|
253
|
+
if (t) return show(t.dataset.planTab);
|
|
254
|
+
const ds = (name) => e.target.closest(`[data-plan-${name}]`)?.dataset;
|
|
255
|
+
const split = (v) => v.split('|');
|
|
256
|
+
if (ds('task')) {
|
|
257
|
+
const [project, stage, item] = split(ds('task').planTask);
|
|
258
|
+
return run(() => api('POST', `/milestones/${encodeURIComponent(project)}/task`, { stage, item }), "In the project's backlog: an agent picks it up");
|
|
259
|
+
}
|
|
260
|
+
if (ds('reach')) {
|
|
261
|
+
const [project, stage, on] = split(ds('reach').planReach);
|
|
262
|
+
return run(() => api('POST', `/milestones/${encodeURIComponent(project)}/reach`, { stage, reached: on === '1' }));
|
|
263
|
+
}
|
|
264
|
+
if (ds('go')) {
|
|
265
|
+
dialog.close();
|
|
266
|
+
return openTab(ds('go').planGo);
|
|
267
|
+
}
|
|
268
|
+
if (ds('agent')) {
|
|
269
|
+
dialog.close();
|
|
270
|
+
return openTab('agent', ds('agent').planAgent);
|
|
271
|
+
}
|
|
272
|
+
if (ds('remove')) return run(() => api('DELETE', `/decisions/${encodeURIComponent(ds('remove').planRemove)}`), 'Removed from the log');
|
|
273
|
+
if (ds('scan')) return run(() => api('POST', `/debt/${encodeURIComponent(ds('scan').planScan)}/scan`, {}), 'Scanning the repository');
|
|
274
|
+
if (ds('debt')) return run(() => api('POST', `/debt/${encodeURIComponent(ds('debt').planDebt)}/queue`, { file: ds('debt').file }), "In the project's backlog: an agent picks it up");
|
|
275
|
+
if (ds('notdebt')) return run(() => api('POST', `/debt/${encodeURIComponent(ds('notdebt').planNotdebt)}/dismiss`, { file: ds('notdebt').file }), 'Set aside');
|
|
276
|
+
const b = e.target.closest('[data-plan]')?.dataset.plan;
|
|
277
|
+
if (b === 'close') return dialog.close();
|
|
278
|
+
if (b === 'refresh') return load();
|
|
279
|
+
if (b === 'add') {
|
|
280
|
+
adding = !adding;
|
|
281
|
+
return draw();
|
|
282
|
+
}
|
|
283
|
+
if (b === 'copy') {
|
|
284
|
+
try {
|
|
285
|
+
const res = await fetch(`/api/decisions?format=markdown&project=${encodeURIComponent(filter.project)}`);
|
|
286
|
+
const ok = await navigator.clipboard?.writeText(await res.text()).then(() => true, () => false);
|
|
287
|
+
toast?.(ok ? 'The decision log is on the clipboard, as Markdown' : "Couldn't copy it", 3000);
|
|
288
|
+
} catch (err) {
|
|
289
|
+
toast?.(err.message, 5000);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
function show(next) {
|
|
295
|
+
tab = TABS.some(([k]) => k === next) ? next : 'dates';
|
|
296
|
+
adding = false;
|
|
297
|
+
try {
|
|
298
|
+
localStorage.setItem(SAVED, tab);
|
|
299
|
+
} catch {}
|
|
300
|
+
draw();
|
|
301
|
+
load();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function open(which) {
|
|
305
|
+
if (dialog.open && !which) return dialog.close();
|
|
306
|
+
if (!dialog.open) dialog.showModal();
|
|
307
|
+
show(which ?? tab);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
let again = null;
|
|
311
|
+
/** The daemon says something here changed: look again while open; the count now and then. */
|
|
312
|
+
function changed() {
|
|
313
|
+
clearTimeout(again);
|
|
314
|
+
again = setTimeout(() => {
|
|
315
|
+
if (dialog.open) load({ quiet: true });
|
|
316
|
+
else api('GET', '/milestones').then((v) => ((data.dates = v), badge()), () => {});
|
|
317
|
+
}, dialog.open ? 400 : 3000);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
expandable(dialog, draw);
|
|
321
|
+
api('GET', '/milestones').then((v) => ((data.dates = v), badge()), () => {});
|
|
322
|
+
return { open, changed, isOpen: () => dialog.open };
|
|
323
|
+
}
|
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; }
|
|
@@ -1349,6 +1349,24 @@ table.today-table .today-label { font-size: 11px; font-weight: 600; text-transfo
|
|
|
1349
1349
|
table.today-table tr.pressing .today-label { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
|
|
1350
1350
|
table.today-table tr.today-prompt .today-label, table.today-table tr.today-waiting .today-label, table.today-table tr.today-question .today-label { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
|
|
1351
1351
|
table.today-table .today-title { color: var(--text); }
|
|
1352
|
+
/* The day on top of Today: meetings and the free time between them. */
|
|
1353
|
+
.today-day { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 8px 12px; margin: 0 0 10px; }
|
|
1354
|
+
.today-day-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
|
|
1355
|
+
.day-rows { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow: auto; }
|
|
1356
|
+
.day-rows > li { display: flex; gap: 12px; padding: 5px 8px; border-radius: 6px; border-left: 3px solid var(--border); }
|
|
1357
|
+
.day-rows .day-meeting { background: var(--panel-2); border-left-color: var(--accent); }
|
|
1358
|
+
.day-rows .day-meeting.now { outline: 1px solid var(--accent); }
|
|
1359
|
+
.day-rows .day-meeting.free { border-left-style: dashed; opacity: .8; }
|
|
1360
|
+
.day-rows .day-free { border-left-color: var(--green); }
|
|
1361
|
+
.day-time { flex: none; width: 132px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
|
|
1362
|
+
.day-what { flex: 1; min-width: 0; }
|
|
1363
|
+
.day-free-label { color: var(--green); font-weight: 600; }
|
|
1364
|
+
.day-what ol { margin: 2px 0 0; padding-left: 20px; }
|
|
1365
|
+
.today-cal { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
|
|
1366
|
+
.today-cal input[name="ics"] { flex: 1 1 320px; min-width: 0; }
|
|
1367
|
+
.today-cal p { flex: 1 0 100%; margin: 0; }
|
|
1368
|
+
table.today-table tr.day-flash td { background: color-mix(in srgb, var(--accent) 14%, transparent); transition: background .3s; }
|
|
1369
|
+
table.today-table tr.today-milestone .today-label { background: color-mix(in srgb, var(--yellow) 18%, transparent); color: var(--yellow); }
|
|
1352
1370
|
table.today-table .today-why { margin-top: 2px; }
|
|
1353
1371
|
table.today-table .today-acts { width: 1%; text-align: right; }
|
|
1354
1372
|
table.today-table .small-link { font-size: 12px; margin-left: 4px; }
|
|
@@ -1388,7 +1406,74 @@ table.issues tr.stage-proposed.ticked { background: color-mix(in srgb, var(--acc
|
|
|
1388
1406
|
table.issues tr.stage-proposed .issue-note { color: var(--accent); }
|
|
1389
1407
|
|
|
1390
1408
|
/* ---------- Value */
|
|
1409
|
+
/* Plan: project dates, the decision log and the tech debt radar. */
|
|
1410
|
+
.plan-dialog { width: min(1080px, calc(100% - 32px)); }
|
|
1411
|
+
.plan-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0 0 10px; }
|
|
1412
|
+
.plan-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: var(--radius); }
|
|
1413
|
+
.plan-decision-form input { flex: 1 1 220px; min-width: 0; }
|
|
1414
|
+
.plan-date { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
|
|
1415
|
+
.plan-project { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 10px 12px; margin-bottom: 12px; }
|
|
1416
|
+
.plan-project-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
|
|
1417
|
+
.plan-project-head h3 { margin: 0 8px 0 0; font-size: 15px; }
|
|
1418
|
+
.plan-stages { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 10px; margin-top: 10px; }
|
|
1419
|
+
.plan-stage { border: 1px solid var(--border); border-left-width: 3px; border-radius: 6px; padding: 8px 10px; background: var(--bg); }
|
|
1420
|
+
.plan-stage.at-risk { border-left-color: var(--yellow); }
|
|
1421
|
+
.plan-stage.late { border-left-color: var(--red); }
|
|
1422
|
+
.plan-stage.on-track, .plan-stage.reached { border-left-color: var(--green); }
|
|
1423
|
+
.plan-stage.reached { opacity: .75; }
|
|
1424
|
+
.plan-stage-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
|
|
1425
|
+
.tag.plan-at-risk { color: var(--yellow); }
|
|
1426
|
+
.tag.plan-late { color: var(--red); }
|
|
1427
|
+
.tag.plan-on-track, .tag.plan-reached { color: var(--green); }
|
|
1428
|
+
.plan-left { font-size: 12.5px; color: var(--muted); }
|
|
1429
|
+
.plan-checks { list-style: none; margin: 8px 0 6px; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
|
|
1430
|
+
.plan-check { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
|
|
1431
|
+
.plan-check > span:nth-child(2) { flex: 1 1 160px; min-width: 0; }
|
|
1432
|
+
.plan-check label { flex: 1 1 160px; min-width: 0; display: flex; flex-direction: row; align-items: baseline; gap: 6px; margin: 0; font-weight: normal; }
|
|
1433
|
+
.plan-check input[type="checkbox"] { flex: none; width: auto; margin: 0; position: relative; top: 2px; }
|
|
1434
|
+
.plan-mark { flex: none; min-width: 18px; text-align: center; font-weight: 600; font-size: 12px; border-radius: 9px; padding: 0 4px; }
|
|
1435
|
+
.plan-check.ok .plan-mark { color: var(--green); }
|
|
1436
|
+
.plan-check.open .plan-mark { background: color-mix(in srgb, var(--yellow) 20%, transparent); color: var(--yellow); }
|
|
1437
|
+
.plan-check.ok { color: var(--muted); }
|
|
1438
|
+
.plan-reminders { display: flex; flex-wrap: wrap; gap: 4px 8px; }
|
|
1439
|
+
.plan-reminder.sent { color: var(--green); }
|
|
1440
|
+
.plan-reminder.past { text-decoration: line-through; }
|
|
1441
|
+
.plan-decisions { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
|
|
1442
|
+
.plan-decision { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 8px 12px; display: flex; flex-direction: column; gap: 3px; }
|
|
1443
|
+
.plan-decision.superseded { opacity: .7; }
|
|
1444
|
+
.plan-decision-head { display: flex; gap: 8px; }
|
|
1445
|
+
table.plan-debt { margin-top: 8px; }
|
|
1446
|
+
table.plan-debt .plan-score { width: 90px; position: relative; }
|
|
1447
|
+
table.plan-debt .plan-score b { position: relative; padding-left: 6px; }
|
|
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
|
+
table.plan-debt code { overflow-wrap: anywhere; }
|
|
1391
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
|
+
|
|
1392
1477
|
.news-dialog { width: min(980px, calc(100% - 32px)); }
|
|
1393
1478
|
.news-find { width: 150px; }
|
|
1394
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
|
+
}
|