ai-agentmanager 1.71.0 → 1.72.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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.72.0 (2026-11-25)
4
+
5
+ - **Try the other path.** Agents write down the paths they weighed, the one they take first. Each other path now has **Try this path** (or `agentmgr try-path <agent> <n>`). It starts a second agent from the same commit the first one started from, told to take that path and not the first, and races the two. You get the race scoreboard (outcome, checks, size, cost, time), a test command run in both, and keep the one you pick. More paths join the same race. Only you can start one, not an agent.
6
+ - **Why is this line here?** In Review changes, each added line has a **?** that shows the moment in the agent's conversation that wrote it: what it had been asked, what it said just before, the commands it had just run, and how many times it wrote that line. It is read from the agent's own transcripts and its subagents', so a line no edit wrote is said to be not found rather than guessed. Also `agentmgr why <agent> <file>:<line>`. Claude Code agents for now.
7
+ - **Scope fence.** An agent changing code outside what it was asked and planned shows under **To fix** in Glance and in its Results: "Drifting: changes src/payments (2 files, 65 lines), not in its task". The areas of code it changed are set against its intent, spec, plan and brief; tests, docs and config never count, nor does a line or two. **Allow** an area (in scope from then on), or **Pull it back** (it is told to stay within the task and undo those changes unless they are needed). No model is asked, and a task that names no area is not judged. Also `agentmgr fence <agent>`.
8
+ - **Bug echo.** When you accept a lesson in a repository's standards (such as the one proposed from an incident), every agent at work in that repository with changes is checked for the same mistake: a model reads its diff against the lesson. One that repeats it shows under **To fix** with where, and you **Tell it** or say **Not the same**. A diff is not checked twice against the same lesson.
9
+ - **Night watch.** For work merged in the last 14 days, the agent's recorded proof commands are run again against the latest main, in a checkout of their own (the agent's folder is left alone, its installed dependencies lent). One that no longer gives the recorded result shows under **To fix**, with the commits since its merge that changed the same files. Off until you turn it on: **Night watch** at the foot of Glance (on or off, the hour, Run now, and what it found), or `agentmgr night-watch --on` (every night at 3) and `--run` to run it now. Commands that change things are never run.
10
+ - **Your calibration.** When you start an agent you can guess, privately: whether it finishes, how long it takes, and how much reading its work will need. Once the work settles, **Your calibration** (in Glance, or `agentmgr calibration`) sets your guesses against what happened, says which kind of work you misjudge most, and how the agents' own confidence held up on the same work. It stays on this computer. Also `agentmgr guess <agent>`.
11
+ - **A message typed into an agent is sent, not left in its input box.** The box under the terminal sent the text and then Enter as two keystrokes. On a phone, where keystrokes go one request at a time and are joined while one is on its way, the two could arrive together as one paste, and Claude Code took the Enter as a line break inside it. The daemon now types the text and presses Enter itself. The longer the text, the longer it waits before pressing Enter. If the text is still in the input box a few seconds later and the agent is not working, it presses Enter again, at most twice. The same goes for messages from the assistant and the app, where an Enter could also be taken by a suggestion list (a message ending in `@name` or `/path`).
12
+
3
13
  ## 1.71.0 (2026-11-24)
4
14
 
5
15
  - **At a glance.** A new **Glance** button in the top bar, and `agentmgr glance`, show every agent on one line, grouped by what it needs from you: needs you now (a prompt, a question it stopped at, a sign-in, an error, stuck), to fix (failing checks, changes requested, a merge conflict, blocked, the same files as another agent), to review (with its Read first level, or a pull request ready to merge), to answer (questions it asked without stopping), working, follow up, tidy up, and idle. Each line says why, from what the app already knows. The badge counts what needs you now and what is to fix, and a click opens the agent. `--all` lists the idle ones too, `-o` writes Markdown, and the command exits with 1 when something needs you.
package/README.md CHANGED
@@ -1465,6 +1465,30 @@ Agents started this way are marked **⚡ GitHub** or **⚡ webhook**, Slack aler
1465
1465
  }
1466
1466
  ```
1467
1467
 
1468
+ ## Try the other path
1469
+
1470
+ Agents write down the paths they weighed before building, the one they take first (**Paths it weighed** in their Results). Each other path has **Try this path**, or `agentmgr try-path <agent> <n>`. It starts a second agent from the commit the first one started from, told to take that path, and races the two: the [race](#races) scoreboard, a test command run in both, and **Pick** to keep one. More paths join the same race. Only you start one, not an agent.
1471
+
1472
+ ## Why is this line here?
1473
+
1474
+ In **Review changes**, each added line has a **?**. It shows the moment in the agent's conversation that wrote the line: what it had been asked, what it said just before, the commands it had just run, and how many times it wrote that line. `agentmgr why <agent> src/cart.js:42` prints the same, with the edit. It is read from the agent's own transcripts (and its subagents'), so a line no edit wrote is reported as not found rather than guessed. Claude Code agents for now.
1475
+
1476
+ ## Scope fence
1477
+
1478
+ An agent asked to fix login that starts rewriting payments is not stuck; it is wandering. The areas of code it changes (a folder such as `src/payments`) are set against what it was asked and planned: its intent, spec, plan and brief. An area none of them names, changed in more than a line or two, shows in Glance and its Results as drifting. Tests, docs and config never count. **Allow** puts an area in scope; **Pull it back** tells it to stay within the task. `agentmgr fence <agent> [--allow <area> | --pull]`. No model is asked.
1479
+
1480
+ ## Bug echo
1481
+
1482
+ Accepting a lesson in a repository's standards gives it to every later agent there. Bug echo also checks the agents already at work: a model reads each one's diff against the lesson, and one that repeats the mistake shows in Glance with where, to **Tell it** or mark **Not the same**. Off with `"echo": { "enabled": false }` in config.json.
1483
+
1484
+ ## Night watch
1485
+
1486
+ Does merged work still hold? For work merged in the last 14 days, the agent's recorded proof commands are run again against the latest main, in a checkout of their own. One that no longer gives the recorded result shows in Glance, with the commits since its merge that changed the same files. Off until you turn it on: **Night watch** at the foot of Glance (on or off, the hour, **Run now**, and what it found), or `agentmgr night-watch --on` (every night at 3, `--hour` to change) and `--run` to run it now. Commands that change things are never run.
1487
+
1488
+ ## Your calibration
1489
+
1490
+ Under **Your guess** in New agent (or `agentmgr guess <agent> --finish yes --hours 2 --review look`), say whether it will finish, how long it will take, and how much reading its work will need. Once the work settles, **Your calibration** (at the foot of Glance, or `agentmgr calibration`) sets your guesses against what happened, names the kind of work you misjudge most, and shows how the agents' own confidence held up on the same work. Private to this computer.
1491
+
1468
1492
  ## At a glance: every agent, and what to act on
1469
1493
 
1470
1494
  **Glance** in the top bar, or `agentmgr glance`, puts every agent on one line, grouped by what it needs from you:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-agentmanager",
3
- "version": "1.71.0",
3
+ "version": "1.72.0",
4
4
  "description": "Run background coding agents (Claude Code, Codex) per intent, and keep track of them from a web UI, your phone or the CLI",
5
5
  "keywords": [
6
6
  "claude",
package/public/app.js CHANGED
@@ -228,7 +228,7 @@ initWorklog({ api, esc, toast, $ });
228
228
  initWeekly({ api, esc, toast, $, md: (t) => md(t) });
229
229
  const understandUi = initUnderstand({ $, esc, api, toast: (m, ms) => toast(m, ms), openChanges: (id) => (showTab('agents'), select(id), reviewUi.open(id)), agentOf: (id) => agents.get(id) });
230
230
  const readFirstUi = initReadFirst({ $, esc, ago: (t) => ago(t), agents, openAgent: (id) => (showTab('agents'), select(id)), openChanges: (id) => (showTab('agents'), select(id), reviewUi.open(id)), projectOf: (a) => a.projectInfo?.name ?? null, api, toast: (m, ms) => toast(m, ms), understand: (id) => understandUi.open(id) });
231
- const glanceUi = initGlance({ $, esc, ago: (t) => ago(t), agents, openAgent: (id) => (showTab('agents'), select(id)), readFirst: () => readFirstUi.open() });
231
+ const glanceUi = initGlance({ $, esc, ago: (t) => ago(t), agents, openAgent: (id) => (showTab('agents'), select(id)), readFirst: () => readFirstUi.open(), api });
232
232
  initSetup({ api, esc, $ });
233
233
  const updateUi = initUpdate({ api, esc, toast, $ });
234
234
  initMenu({ api, esc, toast, $ });
@@ -1125,8 +1125,10 @@ function resultsCard(a) {
1125
1125
  ${r.confidence ? `<p class="own-conf"><span class="tag conf-${esc(r.confidence.level)}" title="The agent's own confidence in what it built, as it wrote it in its brief. The review scorecard is the separate check.">Its own confidence: ${r.confidence.percent}%</span> ${esc(r.confidence.why)}</p>` : r.fromAgent && ['done', 'partial'].includes(r.outcome) ? '<p class="hint own-conf">The agent has not said how confident it is in this.</p>' : ''}
1126
1126
  ${r.blockers.length ? `<ul class="blockers">${r.blockers.map((x) => item(x, 'blocker')).join('')}</ul>` : ''}
1127
1127
  ${readFirstRow(a, esc)}
1128
+ ${fenceRow(a)}
1129
+ ${echoRow(a)}
1128
1130
  ${privateRow(a, esc)}
1129
- ${optionsRows(a, esc)}
1131
+ ${optionsRows(a, esc, pathTries(a))}
1130
1132
  ${proofRows(a, esc)}
1131
1133
  ${r.delivered.length ? `<ul class="delivered">${r.delivered.map((x) => item(x, 'delivered')).join('')}</ul>` : '<p class="hint">Nothing delivered yet.</p>'}
1132
1134
  ${r.notes ? `<div class="md">${md(r.notes)}</div>` : ''}
@@ -2446,6 +2448,39 @@ function raceBanner(a) {
2446
2448
  <span class="spacer"></span><button class="small primary" data-race-open="${a.raceId}">Compare</button></div>`;
2447
2449
  }
2448
2450
 
2451
+ /** In its Results: a lesson of the repository its changes look like they repeat (echo.js). */
2452
+ function echoRow(a) {
2453
+ const open = Object.entries(a.echoes ?? {}).filter(([, e]) => e.repeats && e.state === 'open');
2454
+ if (!open.length) return '';
2455
+ return `<div class="fence-row echo-row"><b>Repeats a past mistake?</b> <span class="hint">A lesson of this repository, learned from a change that went wrong; a model read its changes against it.</span>
2456
+ <ul>${open.map(([id, e]) => `<li><span>${esc(e.lesson)}</span>${e.where ? ` <code>${esc(e.where)}</code>` : ''}${e.why ? `<div class="hint">${esc(e.why)}</div>` : ''}
2457
+ <button class="small" data-act="echo-tell" data-lesson="${esc(id)}" title="Send it the lesson and where it looks repeated">Tell it</button> <button class="small ghost" data-act="echo-dismiss" data-lesson="${esc(id)}">Not the same</button></li>`).join('')}</ul></div>`;
2458
+ }
2459
+
2460
+ /** In its Results: changing code outside its task (fence.js), with Allow and Pull it back. */
2461
+ function fenceRow(a) {
2462
+ const drift = a.fence?.drift ?? [];
2463
+ if (!drift.length) return '';
2464
+ return `<div class="fence-row"><b>Outside its task</b> <span class="hint">It changes code that what it was asked and planned does not name.</span>
2465
+ <ul>${drift.map((d) => `<li><code>${esc(d.area)}</code> <span class="hint">${d.files.length} file${d.files.length === 1 ? '' : 's'}, ${d.lines} lines: ${esc(d.files.slice(0, 3).join(', '))}${d.files.length > 3 ? '…' : ''}</span> <button class="small" data-act="fence-allow" data-area="${esc(d.area)}" title="It belongs to the task: in scope from now on">Allow</button></li>`).join('')}</ul>
2466
+ <button class="small" data-act="fence-pull" title="Tell it to stay within the task and undo those changes unless they are needed">Pull it back</button></div>`;
2467
+ }
2468
+
2469
+ /**
2470
+ * Its other paths being tried ({ n: { id, name } }), for Try this path in its Results; null when
2471
+ * none can be tried here (no repository, in a race of another kind, or itself trying a path).
2472
+ */
2473
+ function pathTries(a) {
2474
+ const own = /^path-(\d+)$/.exec(a.variant?.label ?? '');
2475
+ if (a.kind !== 'task' || a.team || !(a.repo || a.workdir) || (a.raceId && !own) || (own && own[1] !== '1')) return null;
2476
+ const tries = {};
2477
+ for (const o of agents.values()) {
2478
+ const m = o.id !== a.id && a.raceId && o.raceId === a.raceId && /^path-(\d+)$/.exec(o.variant?.label ?? '');
2479
+ if (m) tries[m[1]] = { id: o.id, name: o.name };
2480
+ }
2481
+ return tries;
2482
+ }
2483
+
2449
2484
  function openRace(id) {
2450
2485
  openRaceId = id;
2451
2486
  raceDiff = null;
@@ -4245,6 +4280,26 @@ $('#detail-body').addEventListener('click', async (e) => {
4245
4280
  });
4246
4281
  case 'readfirst-open':
4247
4282
  return readFirstUi.open(a.id);
4283
+ case 'try-path':
4284
+ return act(async () => {
4285
+ const race = await api('POST', `/agents/${a.id}/try-path`, { path: Number(btn.dataset.path) });
4286
+ toast(`${race.rows.at(-1)?.name ?? 'An agent'} takes path ${btn.dataset.path}: compare them in the race`);
4287
+ openRace(race.id);
4288
+ });
4289
+ case 'echo-tell':
4290
+ case 'echo-dismiss':
4291
+ return act(async () => {
4292
+ upsert(await api('POST', `/agents/${a.id}/echo`, { lesson: btn.dataset.lesson, act: btn.dataset.act === 'echo-tell' ? 'tell' : 'dismiss' }));
4293
+ toast(btn.dataset.act === 'echo-tell' ? 'Told: it checks and fixes it' : 'Marked as not the same');
4294
+ });
4295
+ case 'fence-allow':
4296
+ case 'fence-pull':
4297
+ return act(async () => {
4298
+ upsert(await api('POST', `/agents/${a.id}/fence`, btn.dataset.act === 'fence-allow' ? { allow: btn.dataset.area } : { pull: true }));
4299
+ toast(btn.dataset.act === 'fence-allow' ? `${btn.dataset.area} is in scope for it now` : 'Told to stay within its task');
4300
+ });
4301
+ case 'try-path-open':
4302
+ return select(btn.dataset.agent);
4248
4303
  case 'proof-open':
4249
4304
  return proofUi.open(a.id);
4250
4305
  case 'auto-open':
@@ -4666,6 +4721,7 @@ $('#new-form').addEventListener('submit', async (e) => {
4666
4721
  autonomy: f.get('autonomy') || undefined,
4667
4722
  designDoc: Boolean(f.get('designDoc')),
4668
4723
  start: Boolean(f.get('start')),
4724
+ guess: f.get('guessFinish') || f.get('guessHours') || f.get('guessReview') ? { finish: f.get('guessFinish') || undefined, hours: f.get('guessHours') || undefined, review: f.get('guessReview') || undefined } : undefined,
4669
4725
  ...containerChoice(e.target),
4670
4726
  });
4671
4727
  created.forEach((a) => agents.set(a.id, a));
@@ -4996,11 +5052,16 @@ $('#compose').addEventListener('submit', (e) => {
4996
5052
  const box = $('#compose-text');
4997
5053
  const text = box.value;
4998
5054
  if (!text.trim()) return;
4999
- term.send({ t: 'i', d: text });
5000
- // Enter separately, so Claude reads the text as typed input and then submits it.
5001
- setTimeout(() => term.send({ t: 'i', d: '\r' }), 150);
5055
+ if (!term.agentId) return;
5056
+ // The daemon types it and presses Enter once the program has taken it in, and again if it is
5057
+ // still in the input box (manager.typeIn): sent from here as two keystrokes, the Enter could
5058
+ // arrive too early and a long message stayed unsent.
5002
5059
  box.value = '';
5003
5060
  box.style.height = '';
5061
+ api('POST', `/agents/${term.agentId}/term/send`, { text, kind: term.kind }).catch((err) => {
5062
+ box.value ||= text;
5063
+ toast(`Not sent: ${err.message}`, 6000);
5064
+ });
5004
5065
  });
5005
5066
  $('#compose-text').addEventListener('keydown', (e) => {
5006
5067
  if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) {
package/public/glance.js CHANGED
@@ -54,6 +54,12 @@ export function glanceOf(a) {
54
54
  for (const p of open.filter((p) => p.land === 'fix' || fixWhy(p) !== 'needs fixes')) out.fix.push(`Pull request ${prNo(p)}: ${fixWhy(p)}`);
55
55
  if (outcome === 'blocked') out.fix.push(`Blocked${a.results?.blockers?.[0]?.text ? `: ${clip(a.results.blockers[0].text)}` : ''}`);
56
56
  for (const c of a.conflicts ?? []) out.fix.push(`Changes the same files as ${c.agent?.name ?? 'another agent'}`);
57
+ // Merged, and its recorded checks no longer pass on the latest main (nightwatch.js).
58
+ if (a.nightWatch?.status === 'broken') out.fix.push(`No longer holds on main: ${clip(a.nightWatch.broken.join('; '), 100)}${a.nightWatch.suspects?.[0] ? ` (since ${clip(`${a.nightWatch.suspects[0].sha} ${a.nightWatch.suspects[0].subject}`, 80)})` : ''}`);
59
+ // Repeats a mistake a lesson of the repository was learned from (echo.js).
60
+ for (const e of Object.values(a.echoes ?? {}).filter((e) => e.repeats && e.state === 'open')) out.fix.push(`Repeats a past mistake: ${clip(e.lesson, 100)}${e.where ? ` (at ${e.where})` : ''}`);
61
+ // Changing code outside what it was asked and planned (fence.js).
62
+ for (const d of a.fence?.drift ?? []) out.fix.push(`Drifting: changes ${d.area} (${plural(d.files.length, 'file')}, ${plural(d.lines, 'line')}), not in its task`);
57
63
 
58
64
  // To review: finished, or a pull request ready to merge.
59
65
  if (a.readFirst) out.review.push(`${LEVEL[a.readFirst.level]}${a.readFirst.reasons?.[0] ? `: ${clip(a.readFirst.reasons[0].text, 120)}` : ''}`);
@@ -129,9 +135,42 @@ export function glanceMarkdown(g, { all = false } = {}) {
129
135
  return out.join('\n').trimEnd();
130
136
  }
131
137
 
132
- export function initGlance({ $, esc, ago, agents, openAgent, readFirst }) {
138
+ /** Your calibration (calibration.js), in the Glance dialog. */
139
+ export function calibrationHtml(c, esc) {
140
+ const word = { skim: 'skim', look: 'look', close: 'read closely', yes: 'yes', no: 'no' };
141
+ const cell = (g, a, unit = '') => (g == null ? '–' : `${esc(word[g] ?? `${g}${unit}`)} → ${a == null ? '?' : esc(word[a] ?? `${a}${unit}`)}`);
142
+ return `<p><button class="link" data-gl-back>‹ Back to the glance</button></p>
143
+ <h3>Your calibration</h3>
144
+ <ul class="cal-lines">${c.lines.map((l) => `<li>${esc(l)}</li>`).join('')}</ul>
145
+ ${c.rows.length ? `<table class="cal-table"><tr><th>Agent</th><th>Finishes</th><th>Hours</th><th>Reading</th></tr>${c.rows.map((r) => `<tr><td>${esc(r.name)}</td><td>${cell(r.guess.finish, r.actual.finish)}</td><td>${cell(r.guess.hours, r.actual.hours, 'h')}</td><td>${cell(r.guess.review, r.actual.review)}</td></tr>`).join('')}</table>` : ''}
146
+ <p class="hint">Your guesses stay on this computer. Guess when you start an agent: New agent, Your guess.</p>`;
147
+ }
148
+
149
+ /** Night watch (nightwatch.js), in the Glance dialog: on or off, its hour, Run now, and what it found. */
150
+ export function nightHtml(v, esc, ago) {
151
+ const st = { broken: 'No longer holds', holds: 'Holds', skipped: 'Not checked' };
152
+ const hours = Array.from({ length: 24 }, (_, h) => `<option value="${h}"${h === v.settings.hour ? ' selected' : ''}>${String(h).padStart(2, '0')}:00</option>`).join('');
153
+ return `<p><button class="link" data-gl-back>‹ Back to the glance</button></p>
154
+ <h3>Night watch</h3>
155
+ <p class="hint">Merged work of the last ${v.settings.days} days: the agent's recorded checks run again against the latest main, in a checkout of their own. Commands that change things are never run.</p>
156
+ <div class="row nw-controls">
157
+ <label class="check"><input type="checkbox" data-nw="enabled"${v.settings.enabled ? ' checked' : ''} /> Every night at</label>
158
+ <select data-nw="hour" aria-label="The hour it runs at">${hours}</select>
159
+ <button class="small" data-nw="run"${v.running ? ' disabled' : ''}>${v.running ? 'Running…' : 'Run now'}</button>
160
+ </div>
161
+ <p class="hint">${v.lastRunAt ? `Last run ${esc(ago(v.lastRunAt))}: ${v.broken} of ${v.runs.length} no longer hold on main.` : 'Not run yet.'}</p>
162
+ ${v.runs.length ? `<ul class="gl-list">${v.runs.map((r) => `<li class="gl-item ${r.status === 'broken' ? 'gl-fix' : r.status === 'holds' ? 'gl-working' : ''}"${r.agentId ? ` data-gl-agent="${esc(r.agentId)}" tabindex="0"` : ''}>
163
+ <div class="gl-head"><b>${st[r.status] ?? esc(r.status)}</b> <span class="hint">${r.number ? `#${r.number} ` : ''}${esc(r.title ?? r.url)}</span></div>
164
+ ${r.why ? `<div class="gl-why hint">${esc(r.why)}</div>` : ''}
165
+ ${(r.results ?? []).filter((x) => x.status === 'differs').map((x) => `<div class="gl-why">${esc(x.title)} <code>${esc(x.command)}</code> exit ${x.code}</div>`).join('')}
166
+ ${r.suspects?.length ? `<div class="gl-more hint">Changed the same files since: ${r.suspects.slice(0, 3).map((x) => esc(`${x.sha} ${x.subject}`)).join(' · ')}</div>` : ''}
167
+ </li>`).join('')}</ul>` : ''}`;
168
+ }
169
+
170
+ export function initGlance({ $, esc, ago, agents, openAgent, readFirst, api }) {
133
171
  const dlg = $('#glance-dialog');
134
172
  let showIdle = false;
173
+ let aside = null; // 'calibration' or 'night' showing instead of the glance: live updates leave it be
135
174
 
136
175
  function render() {
137
176
  const g = glance(agents.values());
@@ -139,7 +178,7 @@ export function initGlance({ $, esc, ago, agents, openAgent, readFirst }) {
139
178
  const badge = $('#glance-count');
140
179
  badge.textContent = n || '';
141
180
  badge.title = n ? `${g.counts.act} need you now, ${g.counts.fix} to fix` : '';
142
- if (!dlg.open) return;
181
+ if (!dlg.open || aside) return;
143
182
  const row = (i) => `<li class="gl-item gl-${i.group}" data-gl-agent="${esc(i.id)}" tabindex="0">
144
183
  <div class="gl-head"><b>${esc(i.name)}</b> <span class="hint">${esc(i.project ?? '')}${i.since ? ` · ${ago(i.since)}` : ''}${i.running ? ' · open' : ''}</span></div>
145
184
  <div class="gl-why">${esc(i.why[0])}</div>
@@ -156,17 +195,44 @@ export function initGlance({ $, esc, ago, agents, openAgent, readFirst }) {
156
195
  }
157
196
 
158
197
  function open() {
198
+ aside = null;
159
199
  if (!dlg.open) dlg.showModal();
160
200
  render();
161
201
  }
162
202
  $('#glance-btn').onclick = () => open();
163
- dlg.addEventListener('click', (e) => {
203
+ dlg.addEventListener('click', async (e) => {
164
204
  if (e.target.closest('[data-gl="close"]')) return dlg.close();
205
+ if (e.target.closest('[data-gl="calibration"]')) return show('calibration');
206
+ if (e.target.closest('[data-gl="night"]')) return show('night');
207
+ if (e.target.closest('[data-nw="run"]')) {
208
+ e.target.disabled = true;
209
+ e.target.textContent = 'Running…';
210
+ return show('night', () => api('POST', '/night-watch/run', {}));
211
+ }
212
+ if (e.target.closest('[data-gl-back]')) return ((aside = null), render());
165
213
  if (e.target.closest('[data-gl-idle]')) return ((showIdle = true), render());
166
214
  if (e.target.closest('[data-gl-readfirst]')) return (dlg.close(), readFirst());
167
215
  const it = e.target.closest('[data-gl-agent]');
168
216
  if (it) return (dlg.close(), openAgent(it.dataset.glAgent));
169
217
  });
218
+ // Night watch settings: saved as they change.
219
+ dlg.addEventListener('change', (e) => {
220
+ const k = e.target.dataset?.nw;
221
+ if (k === 'enabled' || k === 'hour') show('night', () => api('PUT', '/night-watch', k === 'enabled' ? { enabled: e.target.checked } : { hour: Number(e.target.value) }));
222
+ });
223
+
224
+ /** Calibration or night watch in place of the glance; `first`: a change to make before showing it. */
225
+ async function show(what, first = null) {
226
+ aside = what;
227
+ if (!first) $('#glance-body').innerHTML = `<p class="hint">${what === 'night' ? 'Reading the night watch…' : 'Reading your guesses…'}</p>`;
228
+ try {
229
+ const v = (await first?.()) ?? (await api('GET', what === 'night' ? '/night-watch' : '/calibration'));
230
+ if (aside === what) $('#glance-body').innerHTML = what === 'night' ? nightHtml(v, esc, ago) : calibrationHtml(v, esc);
231
+ } catch (err) {
232
+ if (aside === what) $('#glance-body').innerHTML = `<p><button class="link" data-gl-back>‹ Back to the glance</button></p><p class="error">${esc(err.message)}</p>`;
233
+ }
234
+ }
235
+
170
236
  dlg.addEventListener('keydown', (e) => {
171
237
  const it = e.target.closest?.('[data-gl-agent]');
172
238
  if (it && e.key === 'Enter') (dlg.close(), openAgent(it.dataset.glAgent));
package/public/index.html CHANGED
@@ -368,6 +368,20 @@
368
368
  </select>
369
369
  </label>
370
370
  </div>
371
+ <details class="guess-row">
372
+ <summary>Your guess <span class="hint">(private: set against what happens, in Your calibration)</span></summary>
373
+ <div class="row">
374
+ <label class="check">Finishes?
375
+ <select name="guessFinish"><option value="">–</option><option value="yes">Yes</option><option value="no">No</option></select>
376
+ </label>
377
+ <label class="check">Takes
378
+ <select name="guessHours"><option value="">–</option><option value="0.5">under an hour</option><option value="2">a few hours</option><option value="8">a day</option><option value="24">longer</option></select>
379
+ </label>
380
+ <label class="check">Reading it needs
381
+ <select name="guessReview"><option value="">–</option><option value="skim">skim</option><option value="look">look</option><option value="close">read closely</option></select>
382
+ </label>
383
+ </div>
384
+ </details>
371
385
  <div class="race-only" hidden>
372
386
  <label>
373
387
  Variants <span class="hint">one per line: <code>model</code>, <code>model | approach</code>, or <code>| approach</code>. At least two.</span>
@@ -464,7 +478,7 @@
464
478
  <dialog id="glance-dialog" class="update-dialog readfirst-dialog" aria-label="At a glance">
465
479
  <h2>At a glance</h2>
466
480
  <div id="glance-body"></div>
467
- <div class="dialog-actions"><span class="spacer"></span><button type="button" class="small primary" data-gl="close">Close</button></div>
481
+ <div class="dialog-actions"><button type="button" class="small" data-gl="calibration" title="Your guesses when you started agents, against what happened">Your calibration</button><button type="button" class="small" data-gl="night" title="Does merged work still hold on the latest main? Its recorded checks, run again">Night watch</button><span class="spacer"></span><button type="button" class="small primary" data-gl="close">Close</button></div>
468
482
  </dialog>
469
483
  <dialog id="readfirst-dialog" class="update-dialog readfirst-dialog" aria-label="Read first">
470
484
  <h2>Read first</h2>
package/public/review.js CHANGED
@@ -60,7 +60,7 @@ const BIG = 600; // files with more changed lines start collapsed
60
60
  export function initReview({ api, esc, toast, agents, $ }) {
61
61
  const dlg = $('#review-dialog');
62
62
  const body = $('#review-body');
63
- const st = { id: null, data: null, files: [], comments: [], collapsed: new Set(), editing: null, loading: false, step: null };
63
+ const st = { id: null, data: null, files: [], comments: [], collapsed: new Set(), editing: null, loading: false, step: null, why: null };
64
64
  const walk = () => walkthroughOf(agents.get(st.id), st.data?.diffHash);
65
65
 
66
66
  const key = (id) => `agentmgr.review.${id}`;
@@ -145,8 +145,9 @@ export function initReview({ api, esc, toast, agents, $ }) {
145
145
  const line = side === 'old' ? l.old : l.new;
146
146
  const k = lineKey(f.path, side, line);
147
147
  rows.push(`<tr class="rv-${l.t}" data-rv-line="${esc(k)}">
148
- <td class="rv-no">${l.old ?? ''}</td><td class="rv-no">${l.new ?? ''}<button type="button" class="rv-plus" title="Comment on this line">+</button></td>
148
+ <td class="rv-no">${l.old ?? ''}</td><td class="rv-no">${l.new ?? ''}<button type="button" class="rv-plus" title="Comment on this line">+</button>${l.t === 'add' && l.text.trim() ? '<button type="button" class="rv-why" title="Why is this line here? The moment in its conversation that wrote it">?</button>' : ''}</td>
149
149
  <td class="rv-code"><span class="rv-sign">${l.t === 'add' ? '+' : l.t === 'del' ? '−' : ' '}</span>${esc(l.text)}</td></tr>`);
150
+ if (st.why?.key === k) rows.push(`<tr class="rv-note rv-why-row"><td colspan="3">${whyHtml(st.why)}</td></tr>`);
150
151
  st.comments.forEach((c, i) => {
151
152
  if (c.file === f.path && c.side === side && c.line === line) {
152
153
  rows.push(`<tr class="rv-note"><td colspan="3">${st.editing?.index === i ? formHtml(c.text) : commentHtml(c, i)}</td></tr>`);
@@ -158,6 +159,23 @@ export function initReview({ api, esc, toast, agents, $ }) {
158
159
  return `<div class="rv-file" id="rv-${encodeURIComponent(f.path)}">${head}<table class="rv-table">${rows.join('')}</table></div>`;
159
160
  }
160
161
 
162
+ /** Why is this line here (blame.js): what it was asked, what it said, what it ran, and the edit. */
163
+ function whyHtml(w) {
164
+ const close = '<button type="button" class="link" data-rv-why-close>Close</button>';
165
+ if (w.loading) return '<p class="hint">Looking in its conversation…</p>';
166
+ if (w.error) return `<p class="error">${esc(w.error)}</p> ${close}`;
167
+ const b = w.data;
168
+ if (!b.found) return `<p class="hint">${esc(b.why)}</p> ${close}`;
169
+ const when = b.at ? new Date(b.at).toLocaleString() : '';
170
+ return `<div class="rv-why-body">
171
+ <p><b>Why is this line here?</b> <span class="hint">Written by ${esc(b.tool)}${when ? ` on ${esc(when)}` : ''}${b.times > 1 ? `, ${b.times} times in all` : ''}</span></p>
172
+ ${b.prompt ? `<p class="rv-why-label">What it was asked</p><blockquote>${esc(b.prompt)}</blockquote>` : ''}
173
+ ${b.said.length ? `<p class="rv-why-label">What it said just before</p>${b.said.map((x) => `<blockquote>${esc(x)}</blockquote>`).join('')}` : ''}
174
+ ${b.ran.length ? `<p class="rv-why-label">Commands it had just run</p><ul>${b.ran.map((c) => `<li><code>${esc(c)}</code></li>`).join('')}</ul>` : ''}
175
+ ${close}
176
+ </div>`;
177
+ }
178
+
161
179
  /** The review scorecard at the top: scores, verdict and where to look, or the button to score. */
162
180
  function scorePanel() {
163
181
  if (!st.data?.files.length) return '';
@@ -314,6 +332,26 @@ export function initReview({ api, esc, toast, agents, $ }) {
314
332
 
315
333
  body.addEventListener('click', async (e) => {
316
334
  const t = e.target;
335
+ if (t.closest('[data-rv-why-close]')) return keepInputs(), (st.why = null), render();
336
+ const why = t.closest('.rv-why');
337
+ if (why) {
338
+ const row = why.closest('[data-rv-line]');
339
+ const key = row.dataset.rvLine;
340
+ if (st.why?.key === key) return keepInputs(), (st.why = null), render();
341
+ const file = key.split('\t')[0];
342
+ const text = row.querySelector('.rv-code').textContent.slice(1);
343
+ keepInputs();
344
+ st.why = { key, loading: true };
345
+ render();
346
+ try {
347
+ const data = await api('GET', `/agents/${st.id}/why?${new URLSearchParams({ file, text })}`);
348
+ if (st.why?.key === key) st.why = { key, data };
349
+ } catch (err) {
350
+ if (st.why?.key === key) st.why = { key, error: err.message };
351
+ }
352
+ keepInputs();
353
+ return render();
354
+ }
317
355
  if (t.closest('[data-rv-reload]')) return keepInputs(), reload();
318
356
  const stepBtn = t.closest('[data-rv-step]');
319
357
  if (stepBtn) return step(Number(stepBtn.dataset.rvStep));
package/public/style.css CHANGED
@@ -391,6 +391,16 @@ body.term-max .term-agent, .term-wrap:fullscreen .term-agent { display: inline-b
391
391
  .readfirst-dialog { width: min(760px, calc(100vw - 24px)); }
392
392
  #readfirst-body { max-height: min(66vh, 680px); overflow: auto; }
393
393
  #glance-body { max-height: min(70vh, 720px); overflow: auto; overflow-wrap: anywhere; }
394
+ .vl-try { margin-top: 4px; }
395
+ .fence-row { margin: 8px 0; padding: 6px 10px; border-left: 3px solid var(--yellow); background: var(--panel-2); border-radius: 4px; overflow-wrap: anywhere; }
396
+ .fence-row ul { margin: 4px 0; padding-left: 18px; }
397
+ .fence-row li { margin: 2px 0; }
398
+ .guess-row { margin: 6px 0; }
399
+ .nw-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
400
+ .guess-row summary { cursor: pointer; }
401
+ .cal-lines { padding-left: 18px; }
402
+ .cal-table { border-collapse: collapse; width: 100%; font-size: 13px; }
403
+ .cal-table th, .cal-table td { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--border); }
394
404
  .gl-line { font-weight: 600; margin: 0 0 8px; }
395
405
  .gl-group h3 { font-size: 14px; margin: 12px 0 4px; }
396
406
  .gl-list { list-style: none; margin: 0; padding: 0; }
@@ -919,6 +929,14 @@ tr.rv-hunk td { color: var(--accent); background: color-mix(in srgb, var(--accen
919
929
  .rv-plus { display: none; position: absolute; left: 2px; top: 1px; padding: 0 5px; font-size: 11px; line-height: 16px; border-radius: 3px; background: var(--accent); color: var(--accent-text); border: 0; cursor: pointer; }
920
930
  tr[data-rv-line]:hover .rv-plus { display: inline-block; }
921
931
  @media (hover: none) { .rv-plus { display: inline-block; opacity: .6; } }
932
+ .rv-why { display: none; position: absolute; right: 2px; top: 1px; padding: 0 5px; font-size: 11px; line-height: 16px; border-radius: 3px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); cursor: pointer; }
933
+ tr[data-rv-line]:hover .rv-why { display: inline-block; }
934
+ @media (hover: none) { .rv-why { display: inline-block; opacity: .6; } }
935
+ .rv-why-body { padding: 6px 10px; font-family: inherit; white-space: normal; overflow-wrap: anywhere; }
936
+ .rv-why-body p { margin: 4px 0; }
937
+ .rv-why-label { font-size: 12px; color: var(--muted); margin-top: 8px !important; }
938
+ .rv-why-body blockquote { margin: 2px 0 6px; padding: 4px 8px; border-left: 3px solid var(--border); white-space: pre-wrap; max-height: 12em; overflow: auto; }
939
+ .rv-why-body ul { margin: 2px 0 6px; padding-left: 18px; }
922
940
  tr.rv-note td { padding: 6px 10px; background: var(--panel); font-family: inherit; }
923
941
  .rv-comment { display: flex; gap: 8px; align-items: flex-start; border-left: 3px solid var(--accent); padding: 4px 8px; background: var(--panel-2); border-radius: 4px; font: 13px/1.45 system-ui, sans-serif; }
924
942
  .rv-comment-text { white-space: pre-wrap; }
@@ -77,8 +77,19 @@ export function kindHtml(k, esc) {
77
77
  ${k.kind === 'patent' ? '<p class="hint">A first read, not legal advice. Publishing before filing can cost the right to a patent: keep it private until you have talked to a patent attorney.</p>' : ''}`;
78
78
  }
79
79
 
80
- export function pathsHtml(p, esc) {
80
+ /**
81
+ * The paths, preferred first. `tries` (in an agent's Results): each other path gets a Try this
82
+ * path button, or the agent already trying it: { 2: { id, name } }.
83
+ */
84
+ export function pathsHtml(p, esc, tries = null) {
81
85
  if (!p?.paths.length) return '';
86
+ const tryOf = (i) => {
87
+ if (!tries || i === 0) return '';
88
+ const t = tries[i + 1];
89
+ return t
90
+ ? `<div class="vl-try hint">Being tried by <button class="link" data-act="try-path-open" data-agent="${esc(t.id)}">${esc(t.name)}</button></div>`
91
+ : `<div class="vl-try"><button class="small" data-act="try-path" data-path="${i + 1}" title="Start this path as a second agent from the same commit, and compare the two">Try this path</button></div>`;
92
+ };
82
93
  const chip = (label, l, good) => (l ? `<span class="vl-chip ${good.includes(l) ? 'vl-good' : l === 'medium' ? '' : 'vl-poor'}">${label} ${l}</span>` : '');
83
94
  return `<ol class="vl-paths">${p.paths
84
95
  .map(
@@ -86,18 +97,22 @@ export function pathsHtml(p, esc) {
86
97
  <div class="vl-name">${i === 0 ? '<span class="tag vl-pick">Preferred</span> ' : ''}<b>${esc(x.name)}</b>${x.what ? ` <span class="hint">${esc(x.what)}</span>` : ''}</div>
87
98
  <div class="vl-chips">${chip('now', x.now, ['high'])}${chip('later', x.later, ['high'])}${chip('cost', x.cost, ['small'])}${chip('risk', x.risk, ['low'])}</div>
88
99
  ${x.when ? `<div class="hint">Pick when: ${esc(x.when)}</div>` : ''}
100
+ ${tryOf(i)}
89
101
  </li>`,
90
102
  )
91
103
  .join('')}</ol>
92
104
  ${p.preferred ? `<p class="vl-line"><b>Why the first</b> ${esc(p.preferred)}</p>` : ''}`;
93
105
  }
94
106
 
95
- /** In the agent's Results: the ways it weighed before building, preferred first. */
96
- export function optionsRows(a, esc) {
107
+ /**
108
+ * In the agent's Results: the ways it weighed before building, preferred first. `tries`: the
109
+ * agents trying its other paths ({ n: { id, name } }), or null where none can be tried.
110
+ */
111
+ export function optionsRows(a, esc, tries = null) {
97
112
  const o = a.brief?.options;
98
113
  if (!o?.paths?.length && !o?.new) return '';
99
114
  return `<details class="vl-options"${o.new ? ' open' : ''}><summary><b>Paths it weighed</b> <span class="hint">${o.paths.length ? `${o.paths.length}, preferred first${o.paths[0] ? `: ${esc(o.paths[0].name)}` : ''}` : ''}</span></summary>
100
- ${pathsHtml(o, esc)}
115
+ ${pathsHtml(o, esc, tries)}
101
116
  ${o.new ? `<p class="vl-line"><span class="tag vl-kind vl-kind-paper">Possibly new</span> ${esc(o.new)} <span class="hint">Kept inside the repository; whether it is worth a paper or a patent is yours to decide.</span></p>` : ''}
102
117
  </details>`;
103
118
  }
package/src/blame.js ADDED
@@ -0,0 +1,146 @@
1
+ // Conversation blame: why is this line here? `git blame` names a commit; this names the moment in
2
+ // the agent's conversation that wrote the line: what it had been asked, what it said just before,
3
+ // the commands it had just run, and the edit itself. Read from its own transcripts (Claude Code's
4
+ // JSONL, its subagents' too), so nothing is guessed: a line no edit wrote is said to be not found.
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+
8
+ const EDITS = new Set(['Edit', 'MultiEdit', 'Write', 'NotebookEdit']);
9
+ const clip = (s, n) => {
10
+ const t = String(s ?? '').trim();
11
+ return t.length > n ? `${t.slice(0, n - 1)}…` : t;
12
+ };
13
+ // Code keeps its indentation: only the line breaks at its ends go.
14
+ const clipCode = (s, n) => {
15
+ const t = String(s ?? '').replace(/^\n+|\s+$/g, '');
16
+ return t.length > n ? `${t.slice(0, n - 1)}…` : t;
17
+ };
18
+ const norm = (s) => String(s ?? '').trim().replace(/\s+/g, ' ');
19
+
20
+ /** Text of a message's content: a string, or its text parts. */
21
+ function textOf(content) {
22
+ if (typeof content === 'string') return content;
23
+ return (Array.isArray(content) ? content : [])
24
+ .filter((c) => c?.type === 'text' && typeof c.text === 'string')
25
+ .map((c) => c.text)
26
+ .join('\n');
27
+ }
28
+
29
+ /** What an edit wrote, as lines (each write of a MultiEdit, a file's whole content). */
30
+ function written(c) {
31
+ const i = c.input ?? {};
32
+ if (c.name === 'Write') return [{ before: null, after: String(i.content ?? '') }];
33
+ if (c.name === 'MultiEdit') return (i.edits ?? []).map((e) => ({ before: String(e.old_string ?? ''), after: String(e.new_string ?? '') }));
34
+ if (c.name === 'NotebookEdit') return [{ before: null, after: String(i.new_source ?? '') }];
35
+ return [{ before: String(i.old_string ?? ''), after: String(i.new_string ?? '') }];
36
+ }
37
+
38
+ /** A user's own words: not a tool result, not a note the program added (isMeta, reminders). */
39
+ function promptOf(entry) {
40
+ if (entry.type !== 'user' || entry.isMeta) return null;
41
+ const content = entry.message?.content;
42
+ if (Array.isArray(content) && content.some((c) => c?.type === 'tool_result')) return null;
43
+ const t = textOf(content).replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g, '').trim();
44
+ if (!t || /^<(command-|local-command)/.test(t)) return null;
45
+ return t;
46
+ }
47
+
48
+ /**
49
+ * The transcript entries, oldest first, from JSONL text. Lines that are not JSON are skipped.
50
+ */
51
+ export function parseTranscript(text) {
52
+ const out = [];
53
+ for (const line of String(text ?? '').split('\n')) {
54
+ if (!line.trim()) continue;
55
+ try {
56
+ out.push(JSON.parse(line));
57
+ } catch {}
58
+ }
59
+ return out;
60
+ }
61
+
62
+ /**
63
+ * Why `line` (its text) is in `file`: the edits in the transcripts that wrote it, and the last
64
+ * one's moment. `file` is relative to `workdir`; edits name absolute paths or relative ones.
65
+ * Returns { found: false } or { found: true, at, tool, prompt, promptAt, said, ran, edit: { before,
66
+ * after }, times, firstAt, session }.
67
+ */
68
+ export function blameLine(transcripts, { file, line, workdir }) {
69
+ const want = norm(line);
70
+ if (!want) return { found: false, why: 'The line is empty' };
71
+ const root = workdir ? path.resolve(workdir) : null;
72
+ const sameFile = (p) => {
73
+ if (typeof p !== 'string') return false;
74
+ const abs = path.isAbsolute(p) ? path.resolve(p) : root ? path.resolve(root, p) : p;
75
+ return root ? abs === path.resolve(root, file) : abs.endsWith(`/${file}`) || abs === file;
76
+ };
77
+ const hits = [];
78
+ for (const { session, entries } of transcripts) {
79
+ let prompt = null;
80
+ let promptAt = null;
81
+ let said = [];
82
+ let ran = [];
83
+ for (const entry of entries) {
84
+ const p = promptOf(entry);
85
+ if (p) {
86
+ prompt = p;
87
+ promptAt = entry.timestamp ?? null;
88
+ said = [];
89
+ ran = [];
90
+ continue;
91
+ }
92
+ if (entry.type !== 'assistant') continue;
93
+ for (const c of entry.message?.content ?? []) {
94
+ if (c?.type === 'text' && c.text?.trim()) said = [...said, c.text.trim()].slice(-2);
95
+ else if (c?.type === 'thinking' && c.thinking?.trim()) said = [...said, c.thinking.trim()].slice(-2);
96
+ else if (c?.type === 'tool_use' && c.name === 'Bash' && typeof c.input?.command === 'string') ran = [...ran, c.input.command].slice(-3);
97
+ else if (c?.type === 'tool_use' && EDITS.has(c.name) && sameFile(c.input?.file_path ?? c.input?.notebook_path)) {
98
+ // An edit that adds the line, not one that only carries it along as context.
99
+ const count = (t) => (t ?? '').split('\n').filter((l) => norm(l) === want).length;
100
+ const edit = written(c).find((w) => count(w.after) > count(w.before));
101
+ if (edit) hits.push({ at: entry.timestamp ?? null, tool: c.name, prompt, promptAt, said: [...said], ran: [...ran], edit, session });
102
+ }
103
+ }
104
+ }
105
+ }
106
+ if (!hits.length) return { found: false, why: 'No edit in its conversation wrote this line: it was there before, or written by a command' };
107
+ hits.sort((a, b) => String(a.at).localeCompare(String(b.at)));
108
+ const last = hits.at(-1);
109
+ return {
110
+ found: true,
111
+ at: last.at,
112
+ tool: last.tool,
113
+ prompt: last.prompt ? clip(last.prompt, 1500) : null,
114
+ promptAt: last.promptAt,
115
+ said: last.said.map((s) => clip(s, 800)),
116
+ ran: last.ran.map((s) => clip(s, 300)),
117
+ edit: { before: last.edit.before === null ? null : clipCode(last.edit.before, 1500), after: clipCode(last.edit.after, 1500) },
118
+ times: hits.length,
119
+ firstAt: hits[0].at,
120
+ session: last.session,
121
+ };
122
+ }
123
+
124
+ /** The transcripts of an agent's sessions (and their subagents'), read from disk. */
125
+ export function readTranscripts(files) {
126
+ const out = [];
127
+ for (const { session, file } of files) {
128
+ try {
129
+ out.push({ session, entries: parseTranscript(fs.readFileSync(file, 'utf8')) });
130
+ } catch {}
131
+ }
132
+ return out;
133
+ }
134
+
135
+ export function blameMarkdown(b, { file, lineNo, line } = {}) {
136
+ const out = [`# Why is this line here?`, '', `\`${file}${lineNo ? `:${lineNo}` : ''}\`: \`${clip(line, 200)}\``, ''];
137
+ if (!b.found) return [...out, b.why].join('\n');
138
+ out.push(`Written by ${b.tool} at ${b.at}${b.times > 1 ? ` (written ${b.times} times, first at ${b.firstAt})` : ''}.`, '');
139
+ if (b.prompt) out.push('## What it was asked', '', b.prompt, '');
140
+ if (b.said.length) out.push('## What it said just before', '', ...b.said.flatMap((s) => [s, '']));
141
+ if (b.ran.length) out.push('## Commands it had just run', '', ...b.ran.map((c) => `- \`${c}\``), '');
142
+ out.push('## The edit', '');
143
+ if (b.edit.before !== null) out.push('```diff', ...b.edit.before.split('\n').map((l) => `- ${l}`), ...b.edit.after.split('\n').map((l) => `+ ${l}`), '```');
144
+ else out.push('```', b.edit.after, '```');
145
+ return out.join('\n').trimEnd();
146
+ }