ai-agentmanager 1.30.0 → 1.31.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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.31.0 (2026-11-08)
4
+
5
+ - **Bugs on the Map.** The Map has a *Bugs* view (next to *Agents*): each folder is coloured by the bugs hunts found in it, the worst weighing most, plus a little for how often it changed in the last 30 days, and its bug count shows on it. Bugs that come with their path through the code (`file:line` steps) are drawn as arrows from folder to folder along it: the hot paths, thicker where more (and worse) bugs go the same way. Folders no hunt has looked at are hatched. Click a folder or an arrow for its bugs, with *Fix* and *Evidence*, or *Hunt here* to start a hunt on that folder.
6
+
3
7
  ## 1.30.0 (2026-11-07)
4
8
 
5
9
  - **Bug hunts fix what they find.** Turn on *Fix automatically* on a hunt, and the bugs it finds at or above the severity you pick (high and up by default) are fixed without you: each by its own agent on its own branch, which must add a test that fails before the fix and passes after, and pass the whole suite. The hunt's test command (optional) is run on the fix too, and the AI judge, when it's on, reviews the change. Only then is a **draft** pull request opened, with the bug, the test and the checks in its description; nothing is merged. They show in Today as *Fix ready* and under Bugs → *Draft PRs*. At most 3 a run, within the hunt's cost limit. A fix that doesn't hold up stays in the list with the reason, and with *file it as an issue* on, it's filed on GitHub so it isn't lost.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-agentmanager",
3
- "version": "1.30.0",
3
+ "version": "1.31.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
@@ -203,7 +203,7 @@ const watchUi = initWatch({
203
203
  $('#watch-btn').onclick = () => (mapUi.isOpen() && mapUi.show(false), watchUi.show(!watchUi.isOpen()));
204
204
 
205
205
  // Map: where each agent is in the code, and who is about to collide.
206
- const mapUi = initCodeMap({ api, $, esc, agents, toast: (m, ms) => toast(m, ms), openAgent: (id) => (showTab('agents'), select(id)) });
206
+ const mapUi = initCodeMap({ api, $, esc, agents, toast: (m, ms, a) => toast(m, ms, a), openAgent: (id) => (showTab('agents'), select(id)), openBugs: () => bugsUi.open({ show: 'open' }) });
207
207
  $('#map-btn').onclick = () => (watchUi.isOpen() && watchUi.show(false), mapUi.show(!mapUi.isOpen()));
208
208
 
209
209
  // The standup: each agent's news read aloud, stopping on the ones that need you.
package/public/codemap.js CHANGED
@@ -1,8 +1,13 @@
1
1
  // Map: a repository's folders as tiles sized by their files, with each agent as a badge on the
2
2
  // folders it is changing (solid) or reading (ring) now. A red line joins two agents that changed
3
3
  // the same file; a dashed one runs from an agent reading a file to the agent that changed it.
4
+ // The Bugs view colours each folder by the bugs hunts found there (worst weigh most) and how much it
5
+ // changed lately, draws the paths through the code those bugs take as arrows between folders, and
6
+ // hatches the folders no hunt has looked at. Click a folder or an arrow for its bugs, or Hunt here.
4
7
 
5
8
  const SAVED = 'agentmgr.mapProject';
9
+ const LAYER = 'agentmgr.mapLayer';
10
+ const SEV = { critical: 'Critical', high: 'High', medium: 'Medium', low: 'Low' };
6
11
  const EVERY_MS = 8000;
7
12
 
8
13
  const hue = (id) => [...String(id)].reduce((h, c) => (h * 31 + c.charCodeAt(0)) % 360, 17);
@@ -53,14 +58,17 @@ export function squarify(items, x, y, w, h) {
53
58
  return out;
54
59
  }
55
60
 
56
- export function initCodeMap({ api, $, esc, agents, openAgent, toast }) {
61
+ export function initCodeMap({ api, $, esc, agents, openAgent, openBugs, toast }) {
57
62
  const view = $('#map-view');
58
63
  let open = false;
59
64
  let data = null;
60
65
  let timer = null;
61
66
  let project = null;
67
+ let layer = 'agents';
68
+ let picked = null; // in the Bugs view: { module } or { from, to }
62
69
  try {
63
70
  project = localStorage.getItem(SAVED) || null;
71
+ layer = localStorage.getItem(LAYER) === 'bugs' ? 'bugs' : 'agents';
64
72
  } catch {}
65
73
 
66
74
  const nameOf = (id) => data?.map.agents.find((a) => a.id === id)?.name ?? agents.get(id)?.name ?? id;
@@ -68,7 +76,8 @@ export function initCodeMap({ api, $, esc, agents, openAgent, toast }) {
68
76
 
69
77
  async function load() {
70
78
  try {
71
- data = await api('GET', `/codemap${project ? `?project=${encodeURIComponent(project)}` : ''}`);
79
+ const q = new URLSearchParams({ ...(project ? { project } : {}), ...(layer === 'bugs' ? { layer } : {}) });
80
+ data = await api('GET', `/codemap${q.size ? `?${q}` : ''}`);
72
81
  if (data.project && data.project.key !== project) project = data.project.key;
73
82
  } catch (e) {
74
83
  toast?.(e.message, 5000);
@@ -92,10 +101,14 @@ export function initCodeMap({ api, $, esc, agents, openAgent, toast }) {
92
101
  $('#map-bar').innerHTML = `
93
102
  <b>Map</b>
94
103
  ${projects.length ? `<select data-map-set="project" aria-label="Project">${projects.map((p) => `<option value="${esc(p.key)}" ${p.key === data?.project?.key ? 'selected' : ''}>${esc(p.name)} (${p.running} running)</option>`).join('')}</select>` : ''}
95
- <span class="map-legend"><span class="map-key solid"></span>changing <span class="map-key ring"></span>reading <span class="map-key red"></span>same file changed <span class="map-key dash"></span>reading what another changed</span>
104
+ <span class="chips map-layers" role="tablist"><button class="chip ${layer === 'agents' ? 'active' : ''}" data-map-layer="agents" role="tab" aria-selected="${layer === 'agents'}">Agents</button><button class="chip ${layer === 'bugs' ? 'active' : ''}" data-map-layer="bugs" role="tab" aria-selected="${layer === 'bugs'}" title="Where hunts found bugs, and the paths through the code they take">Bugs</button></span>
105
+ ${layer === 'bugs'
106
+ ? '<span class="map-legend"><span class="map-key heat"></span>bugs (worst weigh most) and recent changes <span class="map-key arrow"></span>path a bug takes <span class="map-key cold"></span>no hunt has looked here</span>'
107
+ : '<span class="map-legend"><span class="map-key solid"></span>changing <span class="map-key ring"></span>reading <span class="map-key red"></span>same file changed <span class="map-key dash"></span>reading what another changed</span>'}
96
108
  <span class="spacer"></span>
97
109
  <button class="small" data-map="refresh" title="Look again now (it refreshes every few seconds)">↻</button>
98
110
  <button class="small" data-map="close" title="Back (Esc)">Close</button>`;
111
+ if (layer === 'bugs') return drawBugs();
99
112
  const warn = (m?.links ?? []).filter((l) => l.kind !== 'near');
100
113
  $('#map-warn').innerHTML = warn.length ? `<ul>${warn.map(sentence).join('')}</ul>` : m?.agents.length ? '<p class="hint">No agents are on the same code.</p>' : '';
101
114
  const box = $('#map-box');
@@ -165,6 +178,129 @@ export function initCodeMap({ api, $, esc, agents, openAgent, toast }) {
165
178
  svg.innerHTML = lines.join('');
166
179
  }
167
180
 
181
+ const finding = (id) => data?.heat?.findings.find((f) => f.id === id);
182
+
183
+ /** The Bugs view: folders by heat, arrows along bugs' paths, cold spots hatched. */
184
+ function drawBugs() {
185
+ const m = data?.map;
186
+ const heat = data?.heat;
187
+ const box = $('#map-box');
188
+ $('#map-agents').innerHTML = '';
189
+ if (!m || !heat || !m.modules.length) {
190
+ box.innerHTML = `<p class="hint map-empty">${data?.project ? 'No files to show for this project yet.' : 'No projects with a repository yet.'}</p>`;
191
+ $('#map-warn').innerHTML = '';
192
+ return;
193
+ }
194
+ const of = (key) => heat.modules[key] ?? { score: 0, bugs: {}, churn: 0, covered: false, files: [], findings: [] };
195
+ // Hot folders get more room, so their names and counts show.
196
+ const items = m.modules.map((mod) => ({ ...mod, weight: Math.max(1, mod.files) + of(mod.key).score * 3 })).sort((a, b) => b.weight - a.weight);
197
+ const W = box.clientWidth;
198
+ const H = Math.max(320, view.clientHeight - box.offsetTop - 24);
199
+ box.style.height = `${H}px`;
200
+ const big = items.slice(0, 100);
201
+ const rest = items.slice(100);
202
+ if (rest.length) big.push({ key: `${rest.length} more folders`, files: rest.reduce((s2, x) => s2 + x.files, 0), weight: rest.reduce((s2, x) => s2 + x.weight, 0), more: true });
203
+ const rects = squarify(big, 0, 0, W, H);
204
+ const at = new Map(rects.map((r) => [r.item.key, r]));
205
+ const tiles = rects
206
+ .map(({ x, y, w, h, item }) => {
207
+ const t = of(item.key);
208
+ const n = Object.values(t.bugs).reduce((a, b) => a + b, 0);
209
+ const r = heat.max ? t.score / heat.max : 0;
210
+ const worst = ['critical', 'high', 'medium', 'low'].find((k) => t.bugs[k]);
211
+ const cold = heat.hunted && !t.covered && !item.more;
212
+ const sel = picked?.module === item.key || picked?.from === item.key || picked?.to === item.key;
213
+ const tip = `${item.key}: ${item.files} files${n ? ` · ${n} bug${n === 1 ? '' : 's'}` : ''}${t.churn ? ` · changed ${t.churn}× in 30 days` : ''}${cold ? ' · no hunt has looked here' : ''}`;
214
+ return `<div class="map-tile heat ${n ? 'buggy' : ''} ${cold ? 'cold' : ''} ${sel ? 'picked' : ''} ${item.more ? 'more' : ''}" data-map-mod="${esc(item.more ? '' : item.key)}" style="left:${x}px;top:${y}px;width:${w}px;height:${h}px;--heat:${r.toFixed(3)}" title="${esc(tip)}">
215
+ ${w > 46 && h > 22 ? `<span class="map-name">${esc(item.key === '.' ? '(top level)' : item.key)}</span>` : ''}
216
+ ${n && w > 40 && h > 38 ? `<span class="map-bugs ${worst}">${n} bug${n === 1 ? '' : 's'}</span>` : w > 46 && h > 38 ? `<span class="map-count">${item.files}</span>` : ''}
217
+ </div>`;
218
+ })
219
+ .join('');
220
+ // Arrows from the middle of one folder to the next, thicker the more (and worse) bugs go that way.
221
+ const maxW = Math.max(1, ...heat.paths.map((p) => p.weight));
222
+ const mid = (r) => [r.x + r.w / 2, r.y + r.h / 2];
223
+ const arrows = heat.paths
224
+ .map((p, i) => {
225
+ const a = at.get(p.from);
226
+ const b = at.get(p.to);
227
+ if (!a || !b || a === b) return '';
228
+ const [x1, y1] = mid(a);
229
+ const [x2, y2] = mid(b);
230
+ // A slight curve, so arrows both ways between two folders don't overlap.
231
+ const cx = (x1 + x2) / 2 - (y2 - y1) * 0.15;
232
+ const cy = (y1 + y2) / 2 + (x2 - x1) * 0.15;
233
+ const sel = picked?.from === p.from && picked?.to === p.to;
234
+ const sw = 1.5 + (4.5 * p.weight) / maxW;
235
+ // Each arrow its own head, sized to its width.
236
+ const head = Math.max(10, Math.min(20, sw * 3)).toFixed(1);
237
+ return `<marker id="map-arrow-${i}" class="${sel ? 'picked' : ''}" viewBox="0 0 10 10" refX="7" refY="5" markerUnits="userSpaceOnUse" markerWidth="${head}" markerHeight="${head}" orient="auto"><path d="M0,0 L10,5 L0,10 z" /></marker><path class="bug-path ${sel ? 'picked' : ''}" data-map-path="${i}" d="M${x1},${y1} Q${cx},${cy} ${x2},${y2}" stroke-width="${sw.toFixed(1)}" marker-end="url(#map-arrow-${i})"><title>${esc(`${p.from} → ${p.to}: ${p.findings.length} bug${p.findings.length === 1 ? '' : 's'}`)}</title></path>`;
238
+ })
239
+ .join('');
240
+ box.innerHTML = `${tiles}<svg class="map-links bug-paths" width="${W}" height="${H}">${arrows}</svg>`;
241
+ $('#map-warn').innerHTML = bugPanel(of);
242
+ }
243
+
244
+ function bugRow(f) {
245
+ return `<li data-map-finding="${esc(f.id)}"><span class="bug-sev ${esc(f.severity)}">${esc(SEV[f.severity] ?? f.severity)}</span> ${esc(f.title)} <span class="hint">${esc(f.file)}${f.line ? `:${f.line}` : ''}${f.status === 'pr' ? ' · draft PR' : f.status === 'fixing' ? ' · being fixed' : f.status === 'snoozed' ? ' · snoozed' : ''}</span>
246
+ ${f.status === 'open' ? '<button class="small" data-map-bug="fix" title="Start an agent on it">Fix</button>' : ''}
247
+ ${f.prUrl ? `<a class="small-link" href="${esc(f.prUrl)}" target="_blank" rel="noopener">PR ↗</a>` : ''}
248
+ <button class="small" data-map-bug="evidence" title="See it in Bugs">Evidence</button></li>`;
249
+ }
250
+
251
+ /** Under the map: the picked folder's or path's bugs, else the hottest folders. */
252
+ function bugPanel(of) {
253
+ const heat = data.heat;
254
+ const hunt = data.project?.shortcut ? `<button class="small primary" data-map-hunt title="A hunt on this folder, the whole module a part at a time">Hunt here</button>` : '';
255
+ if (picked?.module !== undefined) {
256
+ const t = of(picked.module);
257
+ const list = t.findings.map(finding).filter(Boolean);
258
+ const name = picked.module === '.' ? '(top level)' : picked.module;
259
+ return `<div class="map-pick"><b>${esc(name)}</b> <span class="hint">${list.length ? `${list.length} bug${list.length === 1 ? '' : 's'}` : 'no bugs found'}${t.churn ? ` · changed ${t.churn}× in 30 days` : ''}${heat.hunted && !t.covered ? ' · no hunt has looked here yet' : ''}${t.files.length ? ` · hottest: ${t.files.map((x) => `<code>${esc(x.file)}</code>`).join(', ')}` : ''}</span> ${hunt} <button class="small" data-map-unpick>×</button>
260
+ ${list.length ? `<ul class="map-bug-list">${list.map(bugRow).join('')}</ul>` : ''}</div>`;
261
+ }
262
+ if (picked?.from !== undefined) {
263
+ const p = heat.paths.find((x) => x.from === picked.from && x.to === picked.to);
264
+ const list = (p?.findings ?? []).map(finding).filter(Boolean);
265
+ return `<div class="map-pick"><b>${esc(picked.from)} → ${esc(picked.to)}</b> <span class="hint">the path ${list.length === 1 ? 'this bug takes' : `${list.length} bugs take`} through the code</span> <button class="small" data-map-unpick>×</button>
266
+ <ul class="map-bug-list">${list.map(bugRow).join('')}</ul></div>`;
267
+ }
268
+ const hot = Object.entries(heat.modules).filter(([, t]) => t.findings.length).sort((a, b) => b[1].score - a[1].score).slice(0, 5);
269
+ if (!heat.hunted) return '<p class="hint">No bug hunts on this project yet: set one up under Bugs (b), and what it finds shows here. Folders are coloured by recent changes until then.</p>';
270
+ if (!hot.length) return `<p class="hint">No open bugs in this project.${heat.findings.length ? '' : ' Hatched folders are ones no hunt has looked at.'} Click a folder to hunt there.</p>`;
271
+ return `<p class="hint">Hottest: ${hot.map(([k, t]) => `<button class="link" data-map-mod="${esc(k)}">${esc(k === '.' ? '(top level)' : k)}</button> (${t.findings.length})`).join(', ')}. ${heat.paths.length ? 'Arrows are the paths bugs take through the code; click one for its bugs.' : ''} Hatched folders are ones no hunt has looked at.</p>`;
272
+ }
273
+
274
+ async function bugAct(id, what) {
275
+ if (what === 'evidence') {
276
+ show(false);
277
+ return openBugs?.();
278
+ }
279
+ if (what === 'fix') {
280
+ try {
281
+ const r = await api('POST', `/findings/${id}/fix`, {});
282
+ toast?.(r.existing ? `${r.agent.name} is on it already` : `Agent ${r.agent.name} started on it`, 4000, { label: 'Open', run: () => (show(false), openAgent(r.agent.id)) });
283
+ } catch (e) {
284
+ toast?.(e.message, 6000);
285
+ }
286
+ load();
287
+ }
288
+ }
289
+
290
+ /** Hunt the picked folder: its hunt if there is one, else a new whole-module hunt; then run it. */
291
+ async function huntHere() {
292
+ const folder = picked?.module === '.' ? '' : picked?.module ?? '';
293
+ try {
294
+ const { hunts } = await api('GET', '/hunts');
295
+ let h = hunts.find((x) => x.project === data.project.shortcut && x.path === folder);
296
+ h ??= await api('POST', '/hunts', { project: data.project.shortcut, path: folder, focus: 'module' });
297
+ const r = await api('POST', `/hunts/${h.id}/run`, {});
298
+ toast?.(`${r.agent.name} is hunting in ${folder || 'the whole project'}. Its findings come in when it's done.`, 5000);
299
+ } catch (e) {
300
+ toast?.(e.message, 6000);
301
+ }
302
+ }
303
+
168
304
  function show(on) {
169
305
  open = on;
170
306
  view.hidden = !on;
@@ -179,6 +315,28 @@ export function initCodeMap({ api, $, esc, agents, openAgent, toast }) {
179
315
  }
180
316
 
181
317
  view.addEventListener('click', (e) => {
318
+ const lay = e.target.closest('[data-map-layer]');
319
+ if (lay) {
320
+ layer = lay.dataset.mapLayer;
321
+ picked = null;
322
+ try {
323
+ localStorage.setItem(LAYER, layer);
324
+ } catch {}
325
+ return load();
326
+ }
327
+ if (layer === 'bugs') {
328
+ const ba = e.target.closest('[data-map-bug]');
329
+ if (ba) return bugAct(ba.closest('[data-map-finding]')?.dataset.mapFinding, ba.dataset.mapBug);
330
+ if (e.target.closest('[data-map-hunt]')) return huntHere();
331
+ if (e.target.closest('[data-map-unpick]')) return (picked = null), draw();
332
+ const path = e.target.closest('[data-map-path]');
333
+ if (path) {
334
+ const p = data.heat.paths[Number(path.dataset.mapPath)];
335
+ return (picked = p ? { from: p.from, to: p.to } : null), draw();
336
+ }
337
+ const mod = e.target.closest('[data-map-mod]');
338
+ if (mod?.dataset.mapMod) return (picked = picked?.module === mod.dataset.mapMod ? null : { module: mod.dataset.mapMod }), draw();
339
+ }
182
340
  const o = e.target.closest('[data-map-open]');
183
341
  if (o) {
184
342
  show(false);
@@ -191,6 +349,7 @@ export function initCodeMap({ api, $, esc, agents, openAgent, toast }) {
191
349
  view.addEventListener('change', (e) => {
192
350
  if (e.target.dataset.mapSet !== 'project') return;
193
351
  project = e.target.value;
352
+ picked = null;
194
353
  try {
195
354
  localStorage.setItem(SAVED, project);
196
355
  } catch {}
package/public/style.css CHANGED
@@ -1126,6 +1126,28 @@ body.mapping .layout, body.mapping .watch-view { display: none; }
1126
1126
  .map-agents { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; }
1127
1127
  .map-agent { display: inline-flex; align-items: center; gap: 6px; background: none; border: none; padding: 2px 0; cursor: pointer; font-size: 13px; color: inherit; }
1128
1128
  #map-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
1129
+ /* Map, Bugs view: heat, the paths bugs take, cold spots */
1130
+ .map-layers { display: inline-flex; gap: 4px; }
1131
+ .map-layers .chip { font-size: 12px; padding: 3px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); color: inherit; cursor: pointer; }
1132
+ .map-layers .chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
1133
+ .map-key.heat { background: linear-gradient(90deg, color-mix(in srgb, var(--red) 12%, var(--panel)), var(--red)); }
1134
+ .map-key.arrow { height: 0; border-top: 3px solid var(--accent); }
1135
+ .map-key.cold { background: repeating-linear-gradient(45deg, var(--border) 0 2px, transparent 2px 5px); border: 1px solid var(--border); }
1136
+ .map-tile.heat { cursor: pointer; background: color-mix(in srgb, var(--red) calc(var(--heat) * 70%), color-mix(in srgb, var(--border) 45%, var(--panel))); }
1137
+ .map-tile.heat.cold { background-image: repeating-linear-gradient(45deg, color-mix(in srgb, var(--border) 80%, transparent) 0 2px, transparent 2px 7px); }
1138
+ .map-tile.heat.picked { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
1139
+ .map-tile.heat:hover { filter: brightness(1.08); }
1140
+ .map-bugs { display: inline-block; margin-top: 2px; padding: 0 6px; border-radius: 8px; font-size: 10.5px; font-weight: 700; background: var(--panel); border: 1px solid currentColor; }
1141
+ .map-bugs.critical, .map-bugs.high { color: var(--red); }
1142
+ .map-bugs.medium { color: var(--amber, #c98a12); }
1143
+ .map-bugs.low { color: var(--muted); }
1144
+ .bug-paths path.bug-path { fill: none; stroke: var(--accent); stroke-linecap: round; opacity: 0.8; pointer-events: stroke; cursor: pointer; }
1145
+ .bug-paths path.bug-path:hover, .bug-paths path.bug-path.picked { opacity: 1; stroke: var(--text, currentColor); }
1146
+ .bug-paths marker path { fill: var(--accent); }
1147
+ .bug-paths marker.picked path { fill: var(--text, currentColor); }
1148
+ .map-pick { padding: 6px 10px; margin-bottom: 8px; border-radius: 6px; background: var(--panel); font-size: 13px; }
1149
+ .map-warn .map-bug-list li { border-left: none; padding: 4px 0; margin: 0; background: none; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
1150
+ .map-bug-list { margin: 6px 0 0 !important; }
1129
1151
 
1130
1152
  /* ---------- Jira: issues agents work on */
1131
1153
  .issues-dialog { width: min(1100px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 16px; }
package/src/codemap.js CHANGED
@@ -113,3 +113,88 @@ export function buildMap({ files = [], agents = [], depth = 2 }) {
113
113
  links,
114
114
  };
115
115
  }
116
+
117
+ // Bugs on the map: each folder's heat is its open bugs, weighted by severity, plus a little for how
118
+ // much it changed lately (new bugs come from changed code). A finding that names its path through
119
+ // the code ("a.js:3 -> b/c.js:9") is drawn as arrows from folder to folder along it: the hot paths,
120
+ // thicker where several bugs go the same way. Folders no hunt has looked at are the cold spots.
121
+
122
+ export const SEVERITY_WEIGHT = { critical: 8, high: 4, medium: 2, low: 1 };
123
+ // Still in the code: not a bug, not kept, or done with are left out.
124
+ const LIVE = new Set(['open', 'fixing', 'pr', 'filed', 'snoozed']);
125
+ const CHURN_WEIGHT = 0.25;
126
+ const MAX_CHURN = 20;
127
+
128
+ /** A path as the repository lists it: as given, without "./" or an absolute prefix, or by its unique end. */
129
+ export function resolveFile(p, files, set = new Set(files)) {
130
+ const v = String(p ?? '').trim().replace(/\\/g, '/').replace(/^\.\//, '');
131
+ if (!v) return null;
132
+ if (set.has(v)) return v;
133
+ const tail = v.replace(/^\/+/, '');
134
+ if (set.has(tail)) return tail;
135
+ const hits = files.filter((f) => f === tail || f.endsWith(`/${tail}`) || tail.endsWith(`/${f}`));
136
+ return hits.length === 1 ? hits[0] : null;
137
+ }
138
+
139
+ /** The files, in order, of a path through the code written as file:line steps. */
140
+ export function traceFiles(detail, files, set = new Set(files)) {
141
+ const out = [];
142
+ for (const m of String(detail ?? '').matchAll(/([\w@.\-/\\]+\.[A-Za-z]\w*):(\d+)/g)) {
143
+ const f = resolveFile(m[1], files, set);
144
+ if (f && out[out.length - 1] !== f) out.push(f);
145
+ }
146
+ return out;
147
+ }
148
+
149
+ /**
150
+ * The bugs layer: { modules: { key: { score, bugs, churn, covered, files, findings } }, paths, findings, max, hunted }.
151
+ * `findings` are a hunt's findings in this repository; `churn` the recent commits, each a list of
152
+ * the files it changed (a folder's churn is how many commits touched it, however many files); `hunts`
153
+ * the project's hunts (their folder, focus, what they covered, and whether one has run).
154
+ */
155
+ export function bugHeat({ files = [], findings = [], churn = [], hunts = [], depth = 2 }) {
156
+ const set = new Set(files);
157
+ const modules = {};
158
+ const mod = (key) => (modules[key] ??= { score: 0, bugs: { critical: 0, high: 0, medium: 0, low: 0 }, churn: 0, covered: false, files: {}, findings: [] });
159
+ for (const commit of churn) for (const key of new Set(commit.filter((f) => set.has(f)).map((f) => moduleOf(f, depth)))) mod(key).churn += 1;
160
+ const paths = new Map();
161
+ const shown = [];
162
+ for (const f of findings) {
163
+ if (!LIVE.has(f.status)) continue;
164
+ const file = resolveFile(f.file, files, set);
165
+ const steps = f.evidence?.type === 'trace' ? traceFiles(f.evidence.detail, files, set) : [];
166
+ if (file && steps[steps.length - 1] !== file) steps.push(file);
167
+ const at = file ?? steps[steps.length - 1];
168
+ if (!at) continue;
169
+ const w = SEVERITY_WEIGHT[f.severity] ?? 1;
170
+ const m = mod(moduleOf(at, depth));
171
+ m.bugs[f.severity in m.bugs ? f.severity : 'medium'] += 1;
172
+ m.score += w;
173
+ m.files[at] = (m.files[at] ?? 0) + w;
174
+ m.findings.push(f.id);
175
+ shown.push({ id: f.id, title: f.title, severity: f.severity, status: f.status, file: at, line: f.line ?? null, module: moduleOf(at, depth), prUrl: f.prUrl ?? null, steps: steps.length });
176
+ // Folder to folder along its path; staying in one folder isn't an arrow.
177
+ const route = steps.map((s) => moduleOf(s, depth)).filter((x, i, a) => i === 0 || a[i - 1] !== x);
178
+ for (let i = 1; i < route.length; i++) {
179
+ const key = `${route[i - 1]}\u0000${route[i]}`;
180
+ const p = paths.get(key) ?? paths.set(key, { from: route[i - 1], to: route[i], weight: 0, findings: [] }).get(key);
181
+ p.weight += w;
182
+ if (!p.findings.includes(f.id)) p.findings.push(f.id);
183
+ }
184
+ }
185
+ // Covered: a hunt that has run looks at this folder (its folder, and for a whole-module hunt, the parts it went through).
186
+ const ran = hunts.filter((h) => h.ran);
187
+ const inside = (key, p) => !p || key === p || key.startsWith(`${p}/`) || p.startsWith(`${key}/`);
188
+ for (const key of new Set(files.slice(0, 20_000).map((f) => moduleOf(f, depth)))) {
189
+ const m = mod(key);
190
+ m.covered = ran.some((h) => inside(key, h.path) && (h.focus !== 'module' || !h.covered?.length || h.covered.some((c) => inside(key, String(c).replace(/^\.?\/+|\/+$/g, '')))));
191
+ }
192
+ let max = 0;
193
+ for (const m of Object.values(modules)) {
194
+ m.score += Math.min(m.churn, MAX_CHURN) * CHURN_WEIGHT;
195
+ m.score = Math.round(m.score * 100) / 100;
196
+ max = Math.max(max, m.score);
197
+ m.files = Object.entries(m.files).sort((a, b) => b[1] - a[1]).slice(0, 3).map(([file, score]) => ({ file, score }));
198
+ }
199
+ return { modules, paths: [...paths.values()].sort((a, b) => b.weight - a.weight).slice(0, 60), findings: shown, max, hunted: hunts.length > 0 };
200
+ }
package/src/manager.js CHANGED
@@ -105,7 +105,7 @@ async function repoLayout(dir) {
105
105
  }
106
106
  import { spawn } from 'node:child_process';
107
107
  import * as git from './git.js';
108
- import { buildMap, touchedFiles } from './codemap.js';
108
+ import { bugHeat, buildMap, touchedFiles } from './codemap.js';
109
109
  import { parseDiff } from '../public/review.js';
110
110
  import { assignedIssues, issueFields, issueSummary, jiraProblem, leadingIssue, loadJira, wordsAfterLink } from './jira.js';
111
111
  import { issueRows } from './issues.js';
@@ -803,7 +803,11 @@ export class AgentManager extends EventEmitter {
803
803
  * The codebase map of one project (its key, else the one with the most running agents): its
804
804
  * folders, and where each of its agents is changing and reading code now (codemap.js).
805
805
  */
806
- async codeMap(projectKey) {
806
+ /**
807
+ * The code map of a project (the one with the most going on, unless named). With `bugs`
808
+ * ({ findings, hunts } of the bug hunts), it also has the bugs layer (codemap.js bugHeat).
809
+ */
810
+ async codeMap(projectKey, { bugs = null } = {}) {
807
811
  const withCode = this.store.list().filter((a) => a.workdir && !NO_REPO.has(a.kind) && fs.existsSync(a.workdir));
808
812
  const groups = new Map();
809
813
  for (const a of withCode) {
@@ -829,7 +833,20 @@ export class AgentManager extends EventEmitter {
829
833
  } catch {}
830
834
  return { id: a.id, name: a.name, busy: rt?.busy, attention: rt?.attention, changed: this.changeSets.get(a.id)?.files ?? {}, touched };
831
835
  });
832
- return { project: { key: g.key, name: g.name }, projects: list, map: buildMap({ files, agents }) };
836
+ const out = { project: { key: g.key, name: g.name }, projects: list, map: buildMap({ files, agents }) };
837
+ if (bugs) {
838
+ // Hunts and findings name the project by its shortcut.
839
+ const mine = (shortcut) => this.resolveProject(shortcut)?.key === g.key;
840
+ const hunts = (bugs.hunts ?? []).filter((h) => mine(h.project));
841
+ out.project.shortcut = Object.values(this.store.data.projects ?? {}).find((p) => p.key === g.key)?.shortcut ?? null;
842
+ out.heat = bugHeat({
843
+ files,
844
+ findings: (bugs.findings ?? []).filter((f) => mine(f.project)),
845
+ churn: await this.churn(root),
846
+ hunts: hunts.map((h) => ({ path: h.path, focus: h.focus, covered: h.covered ?? [], ran: (h.runs ?? []).some((r) => r.status === 'done') })),
847
+ });
848
+ }
849
+ return out;
833
850
  }
834
851
 
835
852
  /**
@@ -887,6 +904,17 @@ export class AgentManager extends EventEmitter {
887
904
  }
888
905
 
889
906
  /** A repository's tracked files, for the map (kept a few minutes). */
907
+ /** The commits of the last 30 days, each as the files it changed (kept ten minutes). */
908
+ async churn(dir) {
909
+ this.churns ??= new Map();
910
+ const hit = this.churns.get(dir);
911
+ if (hit && Date.now() - hit.at < 10 * 60_000) return hit.commits;
912
+ const out = await git.run('git', ['log', '--since=30.days', '--name-only', '--format=%x01', '--no-renames', '-n', '2000'], { cwd: dir, timeout: 30_000 }).catch(() => '');
913
+ const commits = out.split('\x01').map((c) => c.split('\n').filter(Boolean)).filter((c) => c.length);
914
+ this.churns.set(dir, { at: Date.now(), commits });
915
+ return commits;
916
+ }
917
+
890
918
  async repoFiles(dir) {
891
919
  this.fileLists ??= new Map();
892
920
  const hit = this.fileLists.get(dir);
package/src/server.js CHANGED
@@ -858,7 +858,8 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
858
858
  const days = req.query.days === undefined ? 30 : Math.max(0, Math.min(3650, Math.floor(Number(req.query.days)) || 0));
859
859
  return stats(store.list(), { days, projectOf: (a) => manager.projectInfo(a)?.name ?? null });
860
860
  }));
861
- api.get('/codemap', wrap((req) => manager.codeMap(req.query.project ? String(req.query.project) : null)));
861
+ // ?layer=bugs adds where the bug hunts found bugs: heat per folder, and the paths through the code.
862
+ api.get('/codemap', wrap((req) => manager.codeMap(req.query.project ? String(req.query.project) : null, { bugs: req.query.layer === 'bugs' ? { findings: hunts.findings, hunts: hunts.hunts } : null })));
862
863
  // Issues agents work on, for the summary; ?group=you|agent|done and ?format=markdown to paste.
863
864
  api.get('/issues', wrap(async (req) => {
864
865
  // ?fresh=1 (the ↻ button) asks Jira again: the issues assigned to you and each issue's status.