ai-agentmanager 1.48.0 → 1.50.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/keys.js CHANGED
@@ -30,6 +30,7 @@ export const SHORTCUTS = [
30
30
  [['l'], 'AI News: the latest frontier releases', 'news'],
31
31
  [['c'], 'Plan: project dates, decisions and tech debt', 'plan'],
32
32
  [['u'], 'OS: this computer and its load', 'os'],
33
+ [['q'], 'Decide: recommendations, standing decisions, impact, dates at risk', 'decide'],
33
34
  [['1'], 'Agents tab', 'tab:agents'],
34
35
  [['2'], 'Inbox: what needs you', 'tab:inbox'],
35
36
  [['3'], 'Backlog', 'tab:backlog'],
@@ -73,11 +74,11 @@ export const SHORTCUTS = [
73
74
  // A single key, as an event names it, to its action.
74
75
  export const SINGLE = {
75
76
  j: 'next', k: 'prev', Enter: 'terminal', t: 'terminal',
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',
77
+ 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', q: 'decide', y: 'today', b: 'bugs', '?': 'help',
77
78
  1: 'tab:agents', 2: 'tab:inbox', 3: 'tab:backlog', 4: 'tab:land', 5: 'tab:built',
78
79
  };
79
80
  // While Watch is open: only what makes sense there.
80
- const ON_WATCH = new Set(['today', 'new', 'ask', 'watch', 'standup', 'map', 'issues', 'actions', 'assistant', 'settings', 'designs', 'reviews', 'value', 'news', 'plan', 'os', 'bugs', 'help']);
81
+ const ON_WATCH = new Set(['today', 'new', 'ask', 'watch', 'standup', 'map', 'issues', 'actions', 'assistant', 'settings', 'designs', 'reviews', 'value', 'news', 'plan', 'os', 'decide', 'bugs', 'help']);
81
82
 
82
83
  /** Typing somewhere: a field, an editor or a terminal (xterm types through a textarea). */
83
84
  const typing = (el) => Boolean(el?.closest?.('input, textarea, select, [contenteditable=""], [contenteditable="true"], .xterm, .cm-editor'));
package/public/news.js CHANGED
@@ -40,7 +40,8 @@ export function initNews({ api, $, esc, ago, toast }) {
40
40
  const d = new Date(`${date}T12:00:00`);
41
41
  const today = new Date();
42
42
  const days = Math.round((new Date(today.toDateString()) - new Date(d.toDateString())) / 86_400_000);
43
- if (days === 0) return 'Today';
43
+ // A release dated today somewhere ahead of this time zone is still today's news here.
44
+ if (days <= 0) return 'Today';
44
45
  if (days === 1) return 'Yesterday';
45
46
  return d.toLocaleDateString([], { weekday: 'long', month: 'short', day: 'numeric', ...(d.getFullYear() === today.getFullYear() ? {} : { year: 'numeric' }) });
46
47
  }
package/public/plan.js CHANGED
@@ -7,16 +7,18 @@
7
7
  // What is open can be handed to an agent from each (it goes to the backlog).
8
8
 
9
9
  import { expandButton, expandable } from './expand.js';
10
+ import { initRunbooks } from './runbooks.js';
10
11
 
11
12
  const TABS = [
12
13
  ['dates', 'Dates'],
13
14
  ['decisions', 'Decisions'],
14
15
  ['debt', 'Debt'],
16
+ ['runbooks', 'Runbooks'],
15
17
  ];
16
18
  const SAVED = 'agentmgr.planTab';
17
19
  const STATUS = { 'on-track': 'On track', 'at-risk': 'At risk', late: 'Late', reached: 'Reached' };
18
20
 
19
- export function initPlan({ api, $, esc, ago, toast, projects = () => [], openTab = () => {} }) {
21
+ export function initPlan({ api, $, esc, ago, toast, projects = () => [], openTab = () => {}, md = (t) => `<pre>${esc(t)}</pre>` }) {
20
22
  const dialog = $('#plan-dialog');
21
23
  const body = $('#plan-body');
22
24
  let tab = 'dates';
@@ -32,6 +34,7 @@ export function initPlan({ api, $, esc, ago, toast, projects = () => [], openTab
32
34
  const route = () => (tab === 'dates' ? '/milestones' : tab === 'debt' ? '/debt' : `/decisions?project=${encodeURIComponent(filter.project)}&q=${encodeURIComponent(filter.q)}`);
33
35
  async function load({ quiet = false } = {}) {
34
36
  const t = tab;
37
+ if (t === 'runbooks') return runbooks.load();
35
38
  try {
36
39
  data[t] = await api('GET', route());
37
40
  } catch (e) {
@@ -50,6 +53,17 @@ export function initPlan({ api, $, esc, ago, toast, projects = () => [], openTab
50
53
  el.title = n ? `${n} date${n === 1 ? '' : 's'} late or at risk` : '';
51
54
  }
52
55
 
56
+ // Runbooks for the support team: their own tab, drawn and driven by runbooks.js.
57
+ const runbooks = initRunbooks({ api, esc, ago, toast, projects, md, redraw: (force) => {
58
+ // News from the daemon doesn't take what you are typing; your own click always draws.
59
+ if (tab !== 'runbooks' || !dialog.open || (!force && typing())) return;
60
+ const top = body.querySelector('.plan-scroll')?.scrollTop ?? 0;
61
+ draw();
62
+ const sc = body.querySelector('.plan-scroll');
63
+ if (sc) sc.scrollTop = top;
64
+ },
65
+ });
66
+
53
67
  const day = (iso) => new Date(`${iso}T12:00:00`).toLocaleDateString([], { weekday: 'short', month: 'short', day: 'numeric' });
54
68
  const typing = () => body.contains(document.activeElement) && /^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement.tagName);
55
69
 
@@ -179,7 +193,7 @@ export function initPlan({ api, $, esc, ago, toast, projects = () => [], openTab
179
193
  ${expandButton(dialog)}
180
194
  <button class="small" data-plan="close" title="Close (Esc)">Close</button>
181
195
  </div>
182
- <div class="issues-scroll plan-scroll">${tab === 'dates' ? datesHtml() : tab === 'decisions' ? decisionsHtml() : debtHtml()}</div>`;
196
+ <div class="issues-scroll plan-scroll">${tab === 'dates' ? datesHtml() : tab === 'decisions' ? decisionsHtml() : tab === 'runbooks' ? runbooks.html() : debtHtml()}</div>`;
183
197
  }
184
198
  // A change from the daemon doesn't take what you are typing: it is drawn when you are done.
185
199
  function render() {
@@ -213,6 +227,7 @@ export function initPlan({ api, $, esc, ago, toast, projects = () => [], openTab
213
227
  };
214
228
 
215
229
  body.addEventListener('submit', (e) => {
230
+ if (tab === 'runbooks' && runbooks.submit(e)) return;
216
231
  e.preventDefault();
217
232
  const f = Object.fromEntries(new FormData(e.target));
218
233
  if (e.target.matches('[data-plan-dates]')) {
@@ -251,6 +266,7 @@ export function initPlan({ api, $, esc, ago, toast, projects = () => [], openTab
251
266
  body.addEventListener('click', async (e) => {
252
267
  const t = e.target.closest('[data-plan-tab]');
253
268
  if (t) return show(t.dataset.planTab);
269
+ if (tab === 'runbooks' && runbooks.click(e)) return;
254
270
  const ds = (name) => e.target.closest(`[data-plan-${name}]`)?.dataset;
255
271
  const split = (v) => v.split('|');
256
272
  if (ds('task')) {
@@ -0,0 +1,145 @@
1
+ // Runbooks for the support team (the Runbooks tab of Plan): written from a release ticket, the
2
+ // tickets of an epic, or the code changes of a time frame. Read one, edit it, ask for a revision,
3
+ // copy or download it as Markdown, or print it.
4
+
5
+ const STATUS = { writing: 'Writing…', ready: 'Ready', failed: 'Failed' };
6
+
7
+ export function initRunbooks({ api, esc, ago, toast, projects, md, redraw }) {
8
+ let list = null;
9
+ let open = null; // the runbook being read: { ...meta, markdown }
10
+ let editing = false;
11
+ let source = 'ticket';
12
+ let again = null;
13
+
14
+ async function load() {
15
+ try {
16
+ list = await api('GET', '/runbooks');
17
+ if (open) {
18
+ const meta = list.items.find((r) => r.id === open.id);
19
+ // Written again, or finished, since it was opened: read it again (not over your edits).
20
+ if (!meta) open = null;
21
+ else if (!editing && (meta.updatedAt !== open.updatedAt || meta.status !== open.status)) open = await api('GET', `/runbooks/${open.id}`);
22
+ }
23
+ } catch (e) {
24
+ toast?.(e.message, 5000);
25
+ }
26
+ redraw();
27
+ // One being written reports its steps, then arrives.
28
+ clearTimeout(again);
29
+ if (list?.items.some((r) => r.status === 'writing')) again = setTimeout(load, 2500);
30
+ }
31
+
32
+ const sourceWords = (r) => (r.source.kind === 'code' ? `${r.source.project}: code changes ${r.source.until ? `${r.source.since} to ${r.source.until}` : `since ${r.source.since}`}` : `${list.sources[r.source.kind]} ${r.source.key}`);
33
+ const factWords = (f) => (f ? [f.tickets && `${f.tickets} ticket${f.tickets === 1 ? '' : 's'}`, f.commits && `${f.commits} commit${f.commits === 1 ? '' : 's'}`, f.files && `${f.files} file${f.files === 1 ? '' : 's'}`].filter(Boolean).join(', ') : '');
34
+
35
+ function formHtml() {
36
+ const ps = projects();
37
+ const tab = (k, label) => `<button type="button" class="chip ${k === source ? 'active' : ''}" data-rb-source="${k}" aria-pressed="${k === source}">${label}</button>`;
38
+ return `<form class="plan-form rb-form" data-rb-form="new">
39
+ <div class="chips">${tab('ticket', 'A release ticket')}${tab('epic', 'An epic')}${tab('code', 'Code changes')}</div>
40
+ ${source === 'code'
41
+ ? `<select name="project" aria-label="Project" required><option value="">Project…</option>${ps.map((p) => `<option value="${esc(p.key)}">${esc(p.name)}</option>`).join('')}</select>
42
+ <label class="plan-date">since <input type="date" name="since" required /></label>
43
+ <label class="plan-date">until <input type="date" name="until" title="Empty: until now" /></label>`
44
+ : `<input name="key" placeholder="${source === 'epic' ? "The epic's key or link (PROJ-100)" : "The release ticket's key or link (REL-42)"}" required />`}
45
+ <input name="note" placeholder="Anything to cover in particular (optional)" />
46
+ <button class="small primary">Write the runbook</button>
47
+ </form>
48
+ <p class="hint">${source === 'ticket' ? "Read from Jira: the ticket, what it links to, its sub-tasks, and every ticket in its fix versions." : source === 'epic' ? 'Read from Jira: every ticket of the epic.' : "Read from the project's repository: the commits of the time frame, the diffs of the most changed files, and the Jira tickets the commits name."} One model call writes it, on your own plan. It states only what those facts support and lists the rest under <i>To confirm with engineering</i>: have an engineer check it before support relies on it.</p>`;
49
+ }
50
+
51
+ function listHtml() {
52
+ if (!list) return '<p class="hint">Loading…</p>';
53
+ const rows = list.items
54
+ .map((r) => `<tr>
55
+ <td><button class="link rb-title" data-rb-open="${esc(r.id)}" ${r.status === 'failed' && !r.facts ? 'disabled' : ''}>${esc(r.title)}</button><div class="hint">${esc(sourceWords(r))}${r.facts ? ` · ${esc(factWords(r.facts))}` : ''}${r.edited ? ' · edited by you' : ''}</div>${r.error ? `<div class="issues-problem">${esc(r.error)}</div>` : ''}</td>
56
+ <td class="nowrap"><span class="tag rb-status ${esc(r.status)}">${esc(r.status === 'writing' && r.step ? `${r.step}…` : STATUS[r.status])}</span></td>
57
+ <td class="hint nowrap">${esc(ago(r.updatedAt))}</td>
58
+ <td class="nowrap">${r.status === 'failed' ? `<button class="small" data-rb-again="${esc(r.id)}">Try again</button> ` : ''}<button class="link" data-rb-remove="${esc(r.id)}" title="Delete" ${r.status === 'writing' ? 'disabled' : ''}>✕</button></td>
59
+ </tr>`)
60
+ .join('');
61
+ return `${formHtml()}${rows ? `<table class="issues rb-list"><tbody>${rows}</tbody></table>` : '<p class="hint issues-empty">No runbooks yet.</p>'}`;
62
+ }
63
+
64
+ function openHtml() {
65
+ const r = open;
66
+ const busy = r.status === 'writing';
67
+ return `<div class="plan-bar rb-bar">
68
+ <button class="small" data-rb="back">← Runbooks</button>
69
+ <span class="hint">${esc(sourceWords(r))}${r.facts ? ` · written from ${esc(factWords(r.facts))}` : ''} · ${esc(ago(r.updatedAt))}${r.edited ? ' · edited by you' : ''}</span>
70
+ <span class="spacer"></span>
71
+ ${editing
72
+ ? '<button class="small primary" data-rb="save">Save</button><button class="small" data-rb="cancel">Cancel</button>'
73
+ : `<button class="small" data-rb="edit" ${busy ? 'disabled' : ''}>Edit</button><button class="small" data-rb="copy" title="Copy as Markdown, to paste into your knowledge base">Copy</button><a class="button small" href="/api/runbooks/${esc(r.id)}?format=markdown" download>Download .md</a><button class="small" data-rb="print">Print</button>`}
74
+ </div>
75
+ ${busy ? `<p class="hint">${esc(r.step ?? 'Writing')}…</p>` : ''}
76
+ ${r.error ? `<p class="issues-problem">${esc(r.error)}</p>` : ''}
77
+ ${editing
78
+ ? `<textarea class="rb-edit" data-rb-text aria-label="The runbook, as Markdown">${esc(r.markdown)}</textarea>`
79
+ : `<article class="doc-body rb-doc" id="rb-doc">${md(r.markdown)}</article>
80
+ <form class="plan-form rb-form" data-rb-form="revise"><input name="note" placeholder="What to change or add (the on-call rotation, a missing workaround…)" ${busy ? 'disabled' : ''} /><button class="small" ${busy ? 'disabled' : ''} title="Written again from the tickets and code as they are now, keeping what still holds and your edits">Revise</button></form>`}`;
81
+ }
82
+
83
+ const run = async (fn, done) => {
84
+ try {
85
+ await fn();
86
+ if (done) toast?.(done, 3000);
87
+ } catch (e) {
88
+ toast?.(e.message, 6000);
89
+ }
90
+ document.activeElement?.blur?.();
91
+ await load();
92
+ };
93
+
94
+ /** A click in the tab; true when it was one of ours. */
95
+ function click(e) {
96
+ const s = e.target.closest('[data-rb-source]');
97
+ if (s) return (source = s.dataset.rbSource), redraw(true), true;
98
+ const o = e.target.closest('[data-rb-open]');
99
+ if (o) {
100
+ run(async () => {
101
+ open = await api('GET', `/runbooks/${o.dataset.rbOpen}`);
102
+ editing = false;
103
+ });
104
+ return true;
105
+ }
106
+ const rm = e.target.closest('[data-rb-remove]');
107
+ if (rm) return run(() => api('DELETE', `/runbooks/${rm.dataset.rbRemove}`), 'Deleted'), true;
108
+ const ag = e.target.closest('[data-rb-again]');
109
+ if (ag) return run(() => api('POST', `/runbooks/${ag.dataset.rbAgain}/regenerate`, {}), 'Writing it again'), true;
110
+ const b = e.target.closest('[data-rb]')?.dataset.rb;
111
+ if (!b) return false;
112
+ if (b === 'back') (open = null), (editing = false), redraw(true);
113
+ else if (b === 'edit') (editing = true), redraw(true);
114
+ else if (b === 'cancel') (editing = false), redraw(true);
115
+ else if (b === 'save') {
116
+ const text = document.querySelector('[data-rb-text]').value;
117
+ run(async () => {
118
+ open = await api('PUT', `/runbooks/${open.id}`, { markdown: text });
119
+ editing = false;
120
+ }, 'Saved');
121
+ } else if (b === 'copy') navigator.clipboard?.writeText(open.markdown).then(() => toast?.('The runbook is on the clipboard, as Markdown', 3000), () => toast?.("Couldn't copy it", 3000));
122
+ else if (b === 'print') {
123
+ const w = window.open('', '_blank');
124
+ if (!w) return toast?.('The browser blocked the print window', 4000), true;
125
+ w.document.write(`<!doctype html><meta charset="utf-8"><title>${esc(open.title)}</title><style>body{font:14px/1.5 system-ui,sans-serif;max-width:820px;margin:24px auto;padding:0 16px}table{border-collapse:collapse;width:100%}td,th{border:1px solid #bbb;padding:4px 8px;text-align:left;vertical-align:top}code{background:#f2f2f2;padding:0 3px}</style>${document.querySelector('#rb-doc').innerHTML}`);
126
+ w.document.close();
127
+ w.focus();
128
+ w.print();
129
+ }
130
+ return true;
131
+ }
132
+
133
+ /** A form sent in the tab; true when it was one of ours. */
134
+ function submit(e) {
135
+ const kind = e.target.dataset.rbForm;
136
+ if (!kind) return false;
137
+ e.preventDefault();
138
+ const f = Object.fromEntries(new FormData(e.target));
139
+ if (kind === 'new') run(() => api('POST', '/runbooks', { source, ...f }), 'Gathering the facts; it is written in the background');
140
+ else run(() => api('POST', `/runbooks/${open.id}/regenerate`, { note: f.note }), 'Revising it');
141
+ return true;
142
+ }
143
+
144
+ return { html: () => (open ? openHtml() : listHtml()), click, submit, load, changed: () => load(), editing: () => editing };
145
+ }
package/public/side.js CHANGED
@@ -1,7 +1,8 @@
1
1
  // The split view: the terminal (Claude, a shell or a browser tab) stays on the left, and the right
2
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
3
+ // one, 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; or Reverse engineer: the
5
+ // same for how something in an app, a binary or a website works, with REA's tools. On, the tab and the
5
6
  // document are remembered in this browser.
6
7
  import { parseDiff } from '/review.js';
7
8
  import { cardHtml, explainButton, listenParts as walkParts, walkthroughOf } from '/walkthrough.js';
@@ -66,97 +67,150 @@ export function initSide({ api, esc, toast, $, agents, codeUi, docHtml, renderDi
66
67
  if (st.tab === 'code') codeUi.open(st.agentId);
67
68
  else if (st.tab === 'docs') renderDocs(true);
68
69
  else if (st.tab === 'debug') renderDebug(true);
70
+ else if (st.tab === 'reverse') renderReverse(true);
69
71
  else renderChanges(true);
70
72
  refit();
71
73
  }
72
74
 
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
75
+ // ------------------------------------------------------------ Debug and Reverse engineer
76
+ // Two investigations of the same shape: you ask, the agent investigates in its session, and its
77
+ // report grows here. They differ in their words, in what follows the report (fixes, or building
78
+ // your own), and Reverse engineer also names a target and needs REA's tools.
79
+ const ASK = {
80
+ debug: {
81
+ 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'],
82
+ first: 'What should it debug? For example: E2E tests fail at max scale after about 20 minutes',
83
+ more: 'A follow-up: what you know, what to look at next, or which fixes to apply',
84
+ go: 'Debug',
85
+ short: 'Say what to debug',
86
+ sent: 'Sent to the agent: it investigates in its session',
87
+ then: { key: 'fix', label: 'Apply fixes', sent: 'Asked the agent to apply the fixes', 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" },
88
+ waiting: 'the report shows here once it has the code path',
89
+ empty: '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 ask for a fix.',
90
+ },
91
+ reverse: {
92
+ ideas: ['How does search work?', 'How is data stored and synced?', 'What does it send over the network?', 'How does the plugin system load code?', 'What file format does it save?'],
93
+ first: 'What do you want to understand? For example: how does search work in this app',
94
+ more: 'A follow-up: where to look next, or which part to build',
95
+ go: 'Investigate',
96
+ short: 'Say what you want to understand',
97
+ sent: 'Sent to the agent: it investigates in its session',
98
+ then: { key: 'build', label: 'Build it in my project', sent: 'Asked the agent to build it from the report', title: 'Ask the agent to build your own version in this project from what the report describes: its own code, nothing copied from the target, with tests. Name the part you want in the box, or leave it empty for the plan under "Build it"' },
99
+ waiting: 'the report shows here once it knows the shape of the target',
100
+ empty: "Name a target (an app's folder, a binary, a website) and what you want to understand about it. The agent investigates in its session with REA's tools and writes a report here: how it works with animated diagrams, the evidence behind each claim, what is confirmed and what is inferred, what could not be determined, and a plan for building your own version. It changes nothing until you ask it to build.",
101
+ },
102
+ };
103
+ const drafts = new Map(); // "<agent>:<kind>" -> what's typed and not sent
104
+ const rea = new Map(); // agent id -> whether REA is registered for its folder
76
105
  /** Read the report; `want` is the change time the agent's record names, so each version is read once. */
77
- async function loadDebug(want) {
106
+ async function loadAsk(kind, want) {
78
107
  const id = st.agentId;
79
- const key = `${id}:debug`;
108
+ const key = `${id}:${kind}`;
80
109
  files.set(key, { ...files.get(key), loading: true });
81
- const r = await api('GET', `/agents/${id}/specs/debug`).catch(() => null);
110
+ const r = await api('GET', `/agents/${id}/specs/${kind}`).catch(() => null);
82
111
  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);
112
+ if (st.agentId === id && st.on && st.tab === kind) renderAsk(kind, false);
113
+ }
114
+ async function loadRea() {
115
+ const id = st.agentId;
116
+ rea.set(id, { loading: true });
117
+ rea.set(id, (await api('GET', `/agents/${id}/reverse/rea`).catch(() => null)) ?? { unknown: true });
118
+ if (st.agentId === id && st.on && st.tab === 'reverse') renderAsk('reverse', true);
119
+ }
120
+
121
+ /** What Reverse engineer needs said above its box: whether REA is there, and what it is for. */
122
+ function reverseNotes(a) {
123
+ const r = rea.get(a?.id);
124
+ if (!r && a?.workdir) loadRea();
125
+ const setup = r?.registered
126
+ ? `<p class="hint reverse-rea ok">REA is registered in ${esc(r.where)}. Native binaries also need Hopper, Ghidra, IDA or Kuna; JavaScript, Electron and websites need nothing more.</p>`
127
+ : r && !r.loading && !r.unknown
128
+ ? `<p class="hint reverse-rea missing"><b>REA was not found</b> in Claude Code's settings for this agent. Set it up in a terminal with <code>${esc(r.setup)}</code>, then restart this agent's session. (If REA came with a plugin, it is not seen here and will still work.) <button type="button" class="link" data-reverse-recheck>Check again</button></p>`
129
+ : '';
130
+ return `${setup}<p class="hint reverse-note">For software you own or are allowed to analyse: a licence or the law may restrict reverse engineering someone else's product. The agent is told to analyse only, not to get around licence checks or sign-in, and to build from behaviour without copying code or assets.</p>`;
84
131
  }
85
132
 
86
- function renderDebug(force) {
133
+ function renderAsk(kind, force) {
134
+ const w = ASK[kind];
87
135
  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 ?? [];
136
+ const d = files.get(`${st.agentId}:${kind}`);
137
+ const want = a?.specDocs?.[kind] ?? null;
138
+ if ((!d || (d.loaded && d.want !== want)) && !d?.loading) loadAsk(kind, want);
139
+ const asks = a?.[kind]?.asks ?? [];
92
140
  const working = Boolean(a?.runtime?.busy || a?.outbox);
93
141
  const has = Boolean(d?.markdown);
94
- const sig = `debug|${st.agentId}|${d?.at}|${Boolean(d?.loaded)}|${asks.length}|${working}|${Boolean(a?.workdir)}`;
142
+ const r = rea.get(st.agentId);
143
+ const sig = `${kind}|${st.agentId}|${d?.at}|${Boolean(d?.loaded)}|${asks.length}|${working}|${Boolean(a?.workdir)}|${kind === 'reverse' ? `${r?.registered}|${Boolean(r?.loading)}|${a?.reverse?.target ?? ''}` : ''}`;
95
144
  if (!force && sig === st.sig) return;
96
145
  st.sig = sig;
97
146
  // 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;
147
+ const old = body.querySelector(`[data-${kind}-text]`);
148
+ const key = `${st.agentId}:${kind}`;
149
+ if (old) drafts.set(key, old.value);
150
+ const oldTarget = body.querySelector('[data-reverse-target]');
151
+ if (kind === 'reverse' && oldTarget) drafts.set(`${key}:target`, oldTarget.value);
152
+ const focused = [old, oldTarget].find((el) => el && document.activeElement === el);
153
+ const typing = focused ? [focused === old ? `[data-${kind}-text]` : '[data-reverse-target]', focused.selectionStart, focused.selectionEnd] : null;
101
154
  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>`;
155
+ const draft = drafts.get(key) ?? '';
156
+ const ideas = has || asks.length ? '' : `<div class="debug-ideas">${w.ideas.map((t) => `<button type="button" class="chip" data-ask-idea data-${kind}-idea>${esc(t)}</button>`).join('')}</div>`;
104
157
  const status = !asks.length
105
158
  ? ''
106
159
  : 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>`
160
+ ? `<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' : `; ${w.waiting}`}.</p>`
108
161
  : has
109
162
  ? ''
110
163
  : '<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
164
  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>`
165
+ ? `<details class="debug-asked"><summary>Asked (${asks.length})</summary><ol>${asks.map((x) => `<li>${x.kind === w.then.key ? `<span class="tag">${w.then.key}</span> ` : ''}${esc(x.text)}</li>`).join('')}</ol></details>`
113
166
  : '';
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>
167
+ const report = has ? `<div class="md debug-report">${docHtml(d.markdown)}</div>` : d?.loaded ? (asks.length ? '' : `<p class="hint">${esc(w.empty)}</p>`) : '<p class="hint">Loading…</p>';
168
+ const target = kind === 'reverse' ? `<input data-reverse-target ${a?.workdir ? '' : 'disabled'} value="${esc(drafts.get(`${key}:target`) ?? a?.reverse?.target ?? '')}" placeholder="The target: /Applications/Notes.app, ~/Downloads/app.asar, a binary's path, or https://example.com" aria-label="The target" />` : '';
169
+ body.innerHTML = `<div class="side-scroll debug-view ${kind}-view">
170
+ <form class="debug-ask" data-ask-form="${kind}" data-${kind}-form>
171
+ ${target}
172
+ <textarea data-${kind}-text rows="2" ${a?.workdir ? '' : 'disabled'} placeholder="${esc(has ? w.more : w.first)}">${esc(draft)}</textarea>
124
173
  ${ideas}
125
174
  <div class="debug-actions">
126
175
  <span class="hint">${has && d.at ? `Report updated ${esc(new Date(d.at).toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' }))}` : ''}</span>
127
176
  <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>
177
+ ${has ? `<button type="button" class="small" data-${kind}-${w.then.key} title="${esc(w.then.title)}">${esc(w.then.label)}</button>` : ''}
178
+ <button class="small primary" ${a?.workdir ? '' : 'disabled'}>${has ? 'Ask' : w.go}</button>
130
179
  </div>
131
180
  </form>
181
+ ${kind === 'reverse' ? reverseNotes(a) : ''}
132
182
  ${status}${asked}${report}
133
183
  </div>`;
134
- const text = body.querySelector('[data-debug-text]');
135
184
  if (typing) {
136
- text.focus();
137
- text.setSelectionRange(...typing);
185
+ const el = body.querySelector(typing[0]);
186
+ el.focus();
187
+ el.setSelectionRange(typing[1], typing[2]);
138
188
  }
139
189
  body.querySelector('.side-scroll').scrollTop = top;
140
190
  renderDiagrams(body);
141
191
  }
192
+ const renderDebug = (force) => renderAsk('debug', force);
193
+ const renderReverse = (force) => renderAsk('reverse', force);
142
194
 
143
- async function sendDebug(payload) {
195
+ async function sendAsk(kind, payload) {
144
196
  const id = st.agentId;
197
+ const w = ASK[kind];
145
198
  try {
146
- agents.set(id, await api('POST', `/agents/${id}/debug`, payload));
147
- drafts.delete(id);
148
- const text = body.querySelector('[data-debug-text]');
199
+ agents.set(id, await api('POST', `/agents/${id}/${kind}`, payload));
200
+ drafts.delete(`${id}:${kind}`);
201
+ const text = body.querySelector(`[data-${kind}-text]`);
149
202
  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);
203
+ toast(payload[w.then.key] ? w.then.sent : w.sent, 3000);
151
204
  } catch (err) {
152
205
  toast(`Error: ${err.message}`, 5000);
153
206
  }
154
- if (st.agentId === id && st.tab === 'debug') renderDebug(true);
207
+ if (st.agentId === id && st.tab === kind) renderAsk(kind, true);
155
208
  }
156
209
  // While the agent works, the report is read again now and then: it writes it as it goes.
157
210
  setInterval(() => {
158
211
  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);
212
+ const kind = st.tab;
213
+ if (st.on && ASK[kind] && a?.[kind] && (a.runtime?.busy || a.outbox) && !files.get(`${a.id}:${kind}`)?.loading) loadAsk(kind, a.specDocs?.[kind] ?? null);
160
214
  }, 5000);
161
215
 
162
216
  // ------------------------------------------------------------ Docs
@@ -248,13 +302,15 @@ export function initSide({ api, esc, toast, $, agents, codeUi, docHtml, renderDi
248
302
  if (tab) return setTab(tab.dataset.side);
249
303
  if (e.target.closest('#side-close')) return toggle(false);
250
304
  if (e.target.closest('[data-side-reload]')) return loadChanges();
251
- const idea = e.target.closest('[data-debug-idea]');
305
+ const idea = e.target.closest('[data-ask-idea]');
252
306
  if (idea) {
253
- const text = body.querySelector('[data-debug-text]');
307
+ const text = body.querySelector(`[data-${st.tab}-text]`);
254
308
  text.value = idea.textContent;
255
309
  return text.focus();
256
310
  }
257
- if (e.target.closest('[data-debug-fix]')) return sendDebug({ fix: body.querySelector('[data-debug-text]').value.trim() || true });
311
+ if (e.target.closest('[data-debug-fix]')) return sendAsk('debug', { fix: body.querySelector('[data-debug-text]').value.trim() || true });
312
+ if (e.target.closest('[data-reverse-build]')) return sendAsk('reverse', { build: body.querySelector('[data-reverse-text]').value.trim() || true });
313
+ if (e.target.closest('[data-reverse-recheck]')) return loadRea();
258
314
  try {
259
315
  if (e.target.closest('[data-side-explain]')) {
260
316
  agents.set(st.agentId, await api('POST', `/agents/${st.agentId}/docs/walkthrough?background=1`));
@@ -270,15 +326,19 @@ export function initSide({ api, esc, toast, $, agents, codeUi, docHtml, renderDi
270
326
  }
271
327
  });
272
328
  pane.addEventListener('submit', (e) => {
273
- if (!e.target.matches('[data-debug-form]')) return;
329
+ const kind = e.target.dataset.askForm;
330
+ if (!ASK[kind]) return;
274
331
  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 });
332
+ const question = body.querySelector(`[data-${kind}-text]`).value.trim();
333
+ if (question.length < 3) return toast(ASK[kind].short, 3000);
334
+ if (kind === 'debug') return sendAsk('debug', { question });
335
+ const target = body.querySelector('[data-reverse-target]').value.trim();
336
+ if (!target) return toast("Name the target: an app's folder, a binary's path, or a website's address", 4000);
337
+ sendAsk('reverse', { question, target });
278
338
  });
279
339
  // Enter sends; Shift+Enter is a new line.
280
340
  pane.addEventListener('keydown', (e) => {
281
- if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && e.target.matches('[data-debug-text]')) {
341
+ if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && e.target.matches('[data-debug-text], [data-reverse-text]')) {
282
342
  e.preventDefault();
283
343
  e.target.form.requestSubmit();
284
344
  }
@@ -345,6 +405,7 @@ export function initSide({ api, esc, toast, $, agents, codeUi, docHtml, renderDi
345
405
  if (!st.on || a.id !== st.agentId) return;
346
406
  if (st.tab === 'docs') renderDocs(false);
347
407
  else if (st.tab === 'debug') renderDebug(false);
408
+ else if (st.tab === 'reverse') renderReverse(false);
348
409
  else if (st.tab === 'changes') renderChanges(false);
349
410
  },
350
411
  };
package/public/style.css CHANGED
@@ -999,6 +999,10 @@ form.dropping { outline: 2px dashed var(--accent, #6b8cff); outline-offset: 4px;
999
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
1000
  @keyframes debug-pulse { 50% { opacity: .25; } }
1001
1001
  @media (prefers-reduced-motion: reduce) { .debug-dot { animation: none; } }
1002
+ .reverse-view input[data-reverse-target] { width: 100%; box-sizing: border-box; }
1003
+ .reverse-rea, .reverse-note { margin: 0; }
1004
+ .reverse-rea.missing { padding: 6px 10px; border-left: 3px solid var(--yellow); }
1005
+ .reverse-rea.ok { color: var(--green); }
1002
1006
  .debug-asked summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
1003
1007
  .debug-asked ol { margin: 6px 0 0; padding-left: 22px; }
1004
1008
  .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); }
@@ -1291,7 +1295,7 @@ table.bench-cases tr.faster td:nth-child(5) { color: var(--green); font-weight:
1291
1295
  .issues-dialog { width: min(1100px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 16px; }
1292
1296
  /* Only while open: a display on the dialog itself would keep a closed one on screen. */
1293
1297
  .issues-dialog[open] { display: flex; flex-direction: column; }
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; }
1298
+ #issues-body, #actions-body, #designs-body, #reviews-body, #bugs-body, #plan-body, #news-body, #os-body, #decide-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
1295
1299
  /* The lists: drag the corner to any size, or fill the window (⤢ or f). */
1296
1300
  .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
1301
  .issues-dialog.expanded { width: calc(100% - 16px); height: calc(100% - 16px); }
@@ -1448,6 +1452,64 @@ table.plan-debt .plan-score b { position: relative; padding-left: 6px; }
1448
1452
  .plan-bar-fill { position: absolute; left: 0; top: 6px; bottom: 6px; background: color-mix(in srgb, var(--red) 22%, transparent); border-radius: 3px; }
1449
1453
  table.plan-debt code { overflow-wrap: anywhere; }
1450
1454
  /* AI News: a day heading, then each release with its lab, summary and links. */
1455
+ /* ---------- Runbooks for the support team (a tab of Plan) */
1456
+ .rb-form input[name="key"] { flex: 1 1 240px; min-width: 0; }
1457
+ .rb-form input[name="note"] { flex: 2 1 260px; min-width: 0; }
1458
+ table.rb-list { width: 100%; margin-top: 6px; }
1459
+ .rb-title { font-weight: 600; text-align: left; padding: 0; color: var(--text); }
1460
+ .rb-status.ready { color: var(--green); }
1461
+ .rb-status.failed { color: var(--red); }
1462
+ .rb-status.writing { color: var(--yellow); }
1463
+ .rb-bar a.button { text-decoration: none; padding: 3px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; color: var(--text); }
1464
+ .rb-doc { padding: 4px 4px 12px; overflow: visible; }
1465
+ .rb-doc table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
1466
+ .rb-doc th, .rb-doc td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }
1467
+ .rb-doc input[type="checkbox"] { width: auto; display: inline; margin: 0 6px 0 0; vertical-align: middle; }
1468
+ .rb-doc li:has(> input[type="checkbox"]) { list-style: none; margin-left: -18px; }
1469
+ .rb-form .chips .chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
1470
+ .rb-edit { width: 100%; min-height: 52vh; font-family: var(--mono, ui-monospace, monospace); font-size: 13px; line-height: 1.45; }
1471
+
1472
+ /* ---------- Decide: recommendations, standing decisions, impact, dates at risk, looking back */
1473
+ .decide-dialog { width: min(1080px, calc(100% - 32px)); }
1474
+ .decide-scroll { border: 0; }
1475
+ .decide-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
1476
+ .decide-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 10px 12px; }
1477
+ .decide-card.new, .decide-card.offer { border-left: 3px solid var(--accent); }
1478
+ .decide-card.revisit { border-left: 3px solid var(--yellow); }
1479
+ .decide-card.off { opacity: .6; }
1480
+ .decide-card-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }
1481
+ .decide-advice { margin: 8px 0; padding: 8px 10px; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); border-radius: 0 6px 6px 0; }
1482
+ .decide-card .decide-advice { margin: 0; padding: 0; border: 0; background: none; }
1483
+ .decide-rec { margin: 0 0 4px; overflow-wrap: anywhere; }
1484
+ .decide-why { margin: 0 0 6px; line-height: 1.45; }
1485
+ .decide-tag { color: var(--accent); border-color: var(--accent); }
1486
+ .decide-hard { color: var(--red); border-color: var(--red); }
1487
+ .decide-sure { white-space: nowrap; }
1488
+ .decide-sure.high { color: var(--green); }
1489
+ .decide-sure.mid { color: var(--yellow); }
1490
+ .decide-evidence, .decide-options, .decide-cut { margin: 4px 0 6px; padding-left: 18px; font-size: 13px; }
1491
+ .decide-options li.rec { list-style: '★ '; }
1492
+ .decide-none { margin: 4px 0; }
1493
+ .decide-form input[name="when"] { flex: 2 1 260px; min-width: 0; }
1494
+ .decide-form input[name="text"] { flex: 1 1 200px; min-width: 0; }
1495
+ .decide-on { display: inline-flex; flex-direction: row; gap: 4px; align-items: center; margin: 0; font-size: 12px; }
1496
+ .decide-h { margin: 18px 0 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
1497
+ table.decide-autonomy { width: auto; }
1498
+ table.decide-autonomy td { padding: 4px 12px 4px 0; border: 0; }
1499
+ table.decide-impact { width: 100%; }
1500
+ table.decide-impact .num { width: 28px; text-align: right; }
1501
+ .decide-level.high { color: var(--red); border-color: var(--red); }
1502
+ .decide-level.medium { color: var(--yellow); }
1503
+ .decide-choices { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; }
1504
+ .decide-choices > li { border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; background: var(--bg); }
1505
+ .decide-choices > li.rec { border-color: var(--accent); }
1506
+ .decide-choices p { margin: 4px 0; font-size: 13px; }
1507
+ .decide-outcome.revisit { color: var(--yellow); border-color: var(--yellow); }
1508
+ .decide-outcome.held { color: var(--green); }
1509
+ .decide-lessons { margin: 0 0 12px; padding: 8px 12px; border: 1px dashed var(--border); border-radius: var(--radius); font-size: 13px; }
1510
+ .decide-lessons ul { margin: 4px 0 0; padding-left: 18px; }
1511
+ .nowrap { white-space: nowrap; }
1512
+
1451
1513
  /* ---------- OS: this computer and its load */
1452
1514
  .os-dialog { width: min(1080px, calc(100% - 32px)); }
1453
1515
  .os-scroll { border: 0; }