ai-agentmanager 1.44.0 → 1.47.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/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/side.js CHANGED
@@ -1,6 +1,8 @@
1
1
  // The split view: the terminal (Claude, a shell or a browser tab) stays on the left, and the right
2
- // pane shows the same agent's Code, its Docs (Diagrams by default) or its Changes explained one by
3
- // one. On, the tab and the document are remembered in this browser.
2
+ // pane shows the same agent's Code, its Docs (Diagrams by default), its Changes explained one by
3
+ // one, or Debug: you say what to debug, the agent investigates in its session on the left and its
4
+ // report (animated code path and data flow, findings, fixes) grows here. On, the tab and the
5
+ // document are remembered in this browser.
4
6
  import { parseDiff } from '/review.js';
5
7
  import { cardHtml, explainButton, listenParts as walkParts, walkthroughOf } from '/walkthrough.js';
6
8
 
@@ -63,10 +65,100 @@ export function initSide({ api, esc, toast, $, agents, codeUi, docHtml, renderDi
63
65
  if (!on) return refit();
64
66
  if (st.tab === 'code') codeUi.open(st.agentId);
65
67
  else if (st.tab === 'docs') renderDocs(true);
68
+ else if (st.tab === 'debug') renderDebug(true);
66
69
  else renderChanges(true);
67
70
  refit();
68
71
  }
69
72
 
73
+ // ------------------------------------------------------------ Debug
74
+ const DEBUG_IDEAS = ['E2E tests unstable at max scale', 'Slow or failing under load', 'A flaky test', 'A memory or connection leak', 'Wrong data end to end'];
75
+ const drafts = new Map(); // agent id -> what's typed and not sent
76
+ /** Read the report; `want` is the change time the agent's record names, so each version is read once. */
77
+ async function loadDebug(want) {
78
+ const id = st.agentId;
79
+ const key = `${id}:debug`;
80
+ files.set(key, { ...files.get(key), loading: true });
81
+ const r = await api('GET', `/agents/${id}/specs/debug`).catch(() => null);
82
+ files.set(key, { markdown: r?.markdown ?? null, at: r?.updatedAt ?? null, want, loaded: true });
83
+ if (st.agentId === id && st.on && st.tab === 'debug') renderDebug(false);
84
+ }
85
+
86
+ function renderDebug(force) {
87
+ const a = agents.get(st.agentId);
88
+ const d = files.get(`${st.agentId}:debug`);
89
+ const want = a?.specDocs?.debug ?? null;
90
+ if ((!d || (d.loaded && d.want !== want)) && !d?.loading) loadDebug(want);
91
+ const asks = a?.debug?.asks ?? [];
92
+ const working = Boolean(a?.runtime?.busy || a?.outbox);
93
+ const has = Boolean(d?.markdown);
94
+ const sig = `debug|${st.agentId}|${d?.at}|${Boolean(d?.loaded)}|${asks.length}|${working}|${Boolean(a?.workdir)}`;
95
+ if (!force && sig === st.sig) return;
96
+ st.sig = sig;
97
+ // What's being typed, and where the caret is, survive the redraw.
98
+ const old = body.querySelector('[data-debug-text]');
99
+ if (old) drafts.set(st.agentId, old.value);
100
+ const typing = old && document.activeElement === old ? [old.selectionStart, old.selectionEnd] : null;
101
+ const top = body.querySelector('.side-scroll')?.scrollTop ?? 0;
102
+ const draft = drafts.get(st.agentId) ?? '';
103
+ const ideas = has || asks.length ? '' : `<div class="debug-ideas">${DEBUG_IDEAS.map((t) => `<button type="button" class="chip" data-debug-idea>${esc(t)}</button>`).join('')}</div>`;
104
+ const status = !asks.length
105
+ ? ''
106
+ : working
107
+ ? `<p class="hint debug-status"><span class="debug-dot"></span> The agent is investigating in its session${has ? '; the report below updates as it writes' : '; the report shows here once it has the code path'}.</p>`
108
+ : has
109
+ ? ''
110
+ : '<p class="hint debug-status">Asked. The report shows here when the agent has written it; its session on the left has what it is doing or asking.</p>';
111
+ const asked = asks.length
112
+ ? `<details class="debug-asked"><summary>Asked (${asks.length})</summary><ol>${asks.map((x) => `<li>${x.kind === 'fix' ? '<span class="tag">fix</span> ' : ''}${esc(x.text)}</li>`).join('')}</ol></details>`
113
+ : '';
114
+ const report = has
115
+ ? `<div class="md debug-report">${docHtml(d.markdown)}</div>`
116
+ : d?.loaded
117
+ ? asks.length
118
+ ? ''
119
+ : `<p class="hint">Say what is going wrong: a failure, instability at scale, slowness under load. The agent investigates in its session (it reads the code and logs, reproduces and measures where it can) and writes a report here: animated diagrams of the code path and the data flow with where it breaks, what it found with evidence, the likely causes, and the fixes it recommends. It changes no code until you press <b>Apply fixes</b>.</p>`
120
+ : '<p class="hint">Loading…</p>';
121
+ body.innerHTML = `<div class="side-scroll debug-view">
122
+ <form class="debug-ask" data-debug-form>
123
+ <textarea data-debug-text rows="2" ${a?.workdir ? '' : 'disabled'} placeholder="${has ? 'A follow-up: what you know, what to look at next, or which fixes to apply' : 'What should it debug? For example: E2E tests fail at max scale after about 20 minutes'}">${esc(draft)}</textarea>
124
+ ${ideas}
125
+ <div class="debug-actions">
126
+ <span class="hint">${has && d.at ? `Report updated ${esc(new Date(d.at).toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' }))}` : ''}</span>
127
+ <span class="spacer"></span>
128
+ ${has ? `<button type="button" class="small" data-debug-fix title="Ask the agent to make the report's fixes, verify each and record the result. Name the ones you want in the box (for example: 1 and 3), or leave it empty for the ones it recommends">Apply fixes</button>` : ''}
129
+ <button class="small primary" ${a?.workdir ? '' : 'disabled'}>${has ? 'Ask' : 'Debug'}</button>
130
+ </div>
131
+ </form>
132
+ ${status}${asked}${report}
133
+ </div>`;
134
+ const text = body.querySelector('[data-debug-text]');
135
+ if (typing) {
136
+ text.focus();
137
+ text.setSelectionRange(...typing);
138
+ }
139
+ body.querySelector('.side-scroll').scrollTop = top;
140
+ renderDiagrams(body);
141
+ }
142
+
143
+ async function sendDebug(payload) {
144
+ const id = st.agentId;
145
+ try {
146
+ agents.set(id, await api('POST', `/agents/${id}/debug`, payload));
147
+ drafts.delete(id);
148
+ const text = body.querySelector('[data-debug-text]');
149
+ if (text) text.value = '';
150
+ toast(payload.fix ? 'Asked the agent to apply the fixes' : 'Sent to the agent: it investigates in its session', 3000);
151
+ } catch (err) {
152
+ toast(`Error: ${err.message}`, 5000);
153
+ }
154
+ if (st.agentId === id && st.tab === 'debug') renderDebug(true);
155
+ }
156
+ // While the agent works, the report is read again now and then: it writes it as it goes.
157
+ setInterval(() => {
158
+ const a = agents.get(st.agentId);
159
+ if (st.on && st.tab === 'debug' && a?.debug && (a.runtime?.busy || a.outbox) && !files.get(`${a.id}:debug`)?.loading) loadDebug(a.specDocs?.debug ?? null);
160
+ }, 5000);
161
+
70
162
  // ------------------------------------------------------------ Docs
71
163
  function renderDocs(force) {
72
164
  const a = agents.get(st.agentId);
@@ -156,6 +248,13 @@ export function initSide({ api, esc, toast, $, agents, codeUi, docHtml, renderDi
156
248
  if (tab) return setTab(tab.dataset.side);
157
249
  if (e.target.closest('#side-close')) return toggle(false);
158
250
  if (e.target.closest('[data-side-reload]')) return loadChanges();
251
+ const idea = e.target.closest('[data-debug-idea]');
252
+ if (idea) {
253
+ const text = body.querySelector('[data-debug-text]');
254
+ text.value = idea.textContent;
255
+ return text.focus();
256
+ }
257
+ if (e.target.closest('[data-debug-fix]')) return sendDebug({ fix: body.querySelector('[data-debug-text]').value.trim() || true });
159
258
  try {
160
259
  if (e.target.closest('[data-side-explain]')) {
161
260
  agents.set(st.agentId, await api('POST', `/agents/${st.agentId}/docs/walkthrough?background=1`));
@@ -170,6 +269,20 @@ export function initSide({ api, esc, toast, $, agents, codeUi, docHtml, renderDi
170
269
  toast(`Error: ${err.message}`, 5000);
171
270
  }
172
271
  });
272
+ pane.addEventListener('submit', (e) => {
273
+ if (!e.target.matches('[data-debug-form]')) return;
274
+ e.preventDefault();
275
+ const question = body.querySelector('[data-debug-text]').value.trim();
276
+ if (question.length < 3) return toast('Say what to debug', 3000);
277
+ sendDebug({ question });
278
+ });
279
+ // Enter sends; Shift+Enter is a new line.
280
+ pane.addEventListener('keydown', (e) => {
281
+ if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && e.target.matches('[data-debug-text]')) {
282
+ e.preventDefault();
283
+ e.target.form.requestSubmit();
284
+ }
285
+ });
173
286
  pane.addEventListener('change', (e) => {
174
287
  if (!e.target.matches('[data-side-doc]')) return;
175
288
  st.doc = e.target.value;
@@ -211,6 +324,12 @@ export function initSide({ api, esc, toast, $, agents, codeUi, docHtml, renderDi
211
324
  }
212
325
  },
213
326
  showing: (tab) => st.on && Boolean(st.agentId) && st.tab === tab,
327
+ /** Open the split on a tab (Debug, from the agent's detail). */
328
+ open(tab) {
329
+ st.on = true;
330
+ pref.set('on', '1');
331
+ setTab(tab);
332
+ },
214
333
  /** What Listen reads in Changes: each change, scrolled to and marked as it is read. */
215
334
  listenParts() {
216
335
  const w = walkthroughOf(agents.get(st.agentId), st.changes?.diffHash);
@@ -225,6 +344,7 @@ export function initSide({ api, esc, toast, $, agents, codeUi, docHtml, renderDi
225
344
  agentChanged(a) {
226
345
  if (!st.on || a.id !== st.agentId) return;
227
346
  if (st.tab === 'docs') renderDocs(false);
347
+ else if (st.tab === 'debug') renderDebug(false);
228
348
  else if (st.tab === 'changes') renderChanges(false);
229
349
  },
230
350
  };
package/public/style.css CHANGED
@@ -988,6 +988,19 @@ form.dropping { outline: 2px dashed var(--accent, #6b8cff); outline-offset: 4px;
988
988
  .split-pane { flex: none; width: 0; }
989
989
  .split-pane::after { top: 0; bottom: 0; left: -4px; width: 8px; cursor: col-resize; }
990
990
  .split-pane[hidden], .side-pane[hidden] { display: none !important; }
991
+ /* Debug in the split: the question box, what was asked, then the agent's report. */
992
+ .debug-view { display: flex; flex-direction: column; gap: 10px; }
993
+ .debug-ask { display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; z-index: 2; background: var(--bg); padding-bottom: 6px; border-bottom: 1px solid var(--border); }
994
+ .debug-ask textarea { width: 100%; box-sizing: border-box; resize: vertical; min-height: 44px; }
995
+ .debug-ideas { display: flex; flex-wrap: wrap; gap: 6px; }
996
+ .debug-ideas .chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); color: inherit; cursor: pointer; }
997
+ .debug-actions { display: flex; align-items: center; gap: 6px; }
998
+ .debug-status { margin: 0; }
999
+ .debug-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: debug-pulse 1.2s ease-in-out infinite; }
1000
+ @keyframes debug-pulse { 50% { opacity: .25; } }
1001
+ @media (prefers-reduced-motion: reduce) { .debug-dot { animation: none; } }
1002
+ .debug-asked summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
1003
+ .debug-asked ol { margin: 6px 0 0; padding-left: 22px; }
991
1004
  .side-pane { flex: none; width: var(--pane-w, 45%); display: flex; flex-direction: column; min-height: 0; border-left: 1px solid #30363d; background: var(--bg); color: var(--text); }
992
1005
  .side-bar { display: flex; align-items: center; gap: 6px; padding: 4px 8px; background: #161a22; color: #c9d1d9; font-size: 12.5px; }
993
1006
  .side-bar button { color: #c9d1d9; border-color: #30363d; }
@@ -1336,6 +1349,24 @@ table.today-table .today-label { font-size: 11px; font-weight: 600; text-transfo
1336
1349
  table.today-table tr.pressing .today-label { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
1337
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); }
1338
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); }
1339
1370
  table.today-table .today-why { margin-top: 2px; }
1340
1371
  table.today-table .today-acts { width: 1%; text-align: right; }
1341
1372
  table.today-table .small-link { font-size: 12px; margin-left: 4px; }
@@ -1375,6 +1406,67 @@ table.issues tr.stage-proposed.ticked { background: color-mix(in srgb, var(--acc
1375
1406
  table.issues tr.stage-proposed .issue-note { color: var(--accent); }
1376
1407
 
1377
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; }
1450
+ /* AI News: a day heading, then each release with its lab, summary and links. */
1451
+ .news-dialog { width: min(980px, calc(100% - 32px)); }
1452
+ .news-find { width: 150px; }
1453
+ .news-source.failed, .news-source.failed a { color: var(--red); }
1454
+ .news-day { margin: 14px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
1455
+ .news-list .news-day:first-child { margin-top: 4px; }
1456
+ .news-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
1457
+ .news-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; background: var(--panel); }
1458
+ .news-item.new { border-left: 3px solid var(--accent); }
1459
+ .news-meta { font-size: 12px; margin-bottom: 4px; }
1460
+ .news-lab { font-weight: 600; }
1461
+ .news-lab[data-lab="Anthropic"] { color: #c15f3c; }
1462
+ .news-lab[data-lab="OpenAI"] { color: var(--green); }
1463
+ .news-lab[data-lab="Google"] { color: var(--accent); }
1464
+ .news-new { color: var(--accent); }
1465
+ .news-title { font-weight: 600; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
1466
+ .news-title:hover { text-decoration: underline; }
1467
+ .news-summary { margin: 4px 0 0; line-height: 1.45; }
1468
+ .news-links { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 12px; }
1469
+ .news-links a { overflow-wrap: anywhere; }
1378
1470
  .value-dialog { width: min(1180px, calc(100% - 32px)); }
1379
1471
  .value-dialog[open] { overflow: auto; }
1380
1472
  .value-period { margin: 0 0 8px; }