ai-agentmanager 1.31.0 → 1.32.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 +4 -0
- package/package.json +1 -1
- package/public/codemap.js +119 -5
- package/public/style.css +20 -0
- package/public/today.js +8 -0
- package/src/benchmarks.js +309 -0
- package/src/jira.js +7 -4
- package/src/manager.js +60 -5
- package/src/server.js +19 -2
- package/src/today.js +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.32.0 (2026-11-08)
|
|
4
|
+
|
|
5
|
+
- **Micro benchmarks per module, for Jira issues.** The Map has a *Speed* view: click a folder where speed matters, *Benchmark this folder*, and optionally name the Jira components or labels that mean it. An agent on a Jira issue then benchmarks that module when its issue names it (a component or label, or the folder in the request), or when its change touches it: if it says it's done without having measured it, it's asked to once. It runs every case before and after its change on the same machine, and adds cases for what it changed. A module's benchmarks are kept on this computer, outside the repository, so the next issue on it runs the same ones and the numbers line up. Each issue's numbers show on the module (case, before, after, change), and the folder is coloured by what the last issue did to its speed. A case more than 5% slower shows in Today as *Slower*, with *Ask to fix* (the agent makes it as fast as before, or says why it can't be) and *It's fine*. Jira issues' components and labels are now read along with their summary.
|
|
6
|
+
|
|
3
7
|
## 1.31.0 (2026-11-08)
|
|
4
8
|
|
|
5
9
|
- **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.
|
package/package.json
CHANGED
package/public/codemap.js
CHANGED
|
@@ -65,10 +65,10 @@ export function initCodeMap({ api, $, esc, agents, openAgent, openBugs, toast })
|
|
|
65
65
|
let timer = null;
|
|
66
66
|
let project = null;
|
|
67
67
|
let layer = 'agents';
|
|
68
|
-
let picked = null; // in the Bugs
|
|
68
|
+
let picked = null; // in the Bugs and Speed views: { module } or { from, to }
|
|
69
69
|
try {
|
|
70
70
|
project = localStorage.getItem(SAVED) || null;
|
|
71
|
-
layer = localStorage.getItem(LAYER)
|
|
71
|
+
layer = ['bugs', 'speed'].includes(localStorage.getItem(LAYER)) ? localStorage.getItem(LAYER) : 'agents';
|
|
72
72
|
} catch {}
|
|
73
73
|
|
|
74
74
|
const nameOf = (id) => data?.map.agents.find((a) => a.id === id)?.name ?? agents.get(id)?.name ?? id;
|
|
@@ -76,7 +76,7 @@ export function initCodeMap({ api, $, esc, agents, openAgent, openBugs, toast })
|
|
|
76
76
|
|
|
77
77
|
async function load() {
|
|
78
78
|
try {
|
|
79
|
-
const q = new URLSearchParams({ ...(project ? { project } : {}), ...(layer
|
|
79
|
+
const q = new URLSearchParams({ ...(project ? { project } : {}), ...(layer !== 'agents' ? { layer } : {}) });
|
|
80
80
|
data = await api('GET', `/codemap${q.size ? `?${q}` : ''}`);
|
|
81
81
|
if (data.project && data.project.key !== project) project = data.project.key;
|
|
82
82
|
} catch (e) {
|
|
@@ -101,14 +101,17 @@ export function initCodeMap({ api, $, esc, agents, openAgent, openBugs, toast })
|
|
|
101
101
|
$('#map-bar').innerHTML = `
|
|
102
102
|
<b>Map</b>
|
|
103
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>` : ''}
|
|
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 === '
|
|
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><button class="chip ${layer === 'speed' ? 'active' : ''}" data-map-layer="speed" role="tab" aria-selected="${layer === 'speed'}" title="Modules where speed matters: micro benchmarks for the Jira issues that change them">Speed</button></span>
|
|
105
|
+
${layer === 'speed'
|
|
106
|
+
? `<span class="map-legend"><span class="map-key watched"></span>benchmarked <span class="map-key slower"></span>last issue made it over ${data?.speed?.slowerPct ?? 5}% slower <span class="map-key faster"></span>faster</span>`
|
|
107
|
+
: layer === 'bugs'
|
|
106
108
|
? '<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
109
|
: '<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>'}
|
|
108
110
|
<span class="spacer"></span>
|
|
109
111
|
<button class="small" data-map="refresh" title="Look again now (it refreshes every few seconds)">↻</button>
|
|
110
112
|
<button class="small" data-map="close" title="Back (Esc)">Close</button>`;
|
|
111
113
|
if (layer === 'bugs') return drawBugs();
|
|
114
|
+
if (layer === 'speed') return drawSpeed();
|
|
112
115
|
const warn = (m?.links ?? []).filter((l) => l.kind !== 'near');
|
|
113
116
|
$('#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>' : '';
|
|
114
117
|
const box = $('#map-box');
|
|
@@ -301,6 +304,104 @@ export function initCodeMap({ api, $, esc, agents, openAgent, openBugs, toast })
|
|
|
301
304
|
}
|
|
302
305
|
}
|
|
303
306
|
|
|
307
|
+
/** The benchmarked modules a map folder has, or is in (a folder can be deeper or shallower than a tile). */
|
|
308
|
+
const watchedIn = (key) => (data?.speed?.modules ?? []).filter((w) => !w.path || key === w.path || key.startsWith(`${w.path}/`) || w.path.startsWith(`${key === '.' ? '' : key}/`));
|
|
309
|
+
const pct = (n) => (n === null || n === undefined ? '' : `${n > 0 ? '+' : n < 0 ? '−' : '±'}${Math.abs(n)}%`);
|
|
310
|
+
const trend = (n, limit) => (n === null || n === undefined ? '' : n > limit ? 'slower' : n < -limit ? 'faster' : 'same');
|
|
311
|
+
|
|
312
|
+
/** The Speed view: benchmarked folders, coloured by what the last issue on them did to their speed. */
|
|
313
|
+
function drawSpeed() {
|
|
314
|
+
const m = data?.map;
|
|
315
|
+
const sp = data?.speed;
|
|
316
|
+
const box = $('#map-box');
|
|
317
|
+
$('#map-agents').innerHTML = '';
|
|
318
|
+
if (!m || !sp || !m.modules.length) {
|
|
319
|
+
box.innerHTML = `<p class="hint map-empty">${data?.project ? 'No files to show for this project yet.' : 'No projects with a repository yet.'}</p>`;
|
|
320
|
+
$('#map-warn').innerHTML = '';
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const limit = sp.slowerPct;
|
|
324
|
+
const last = (key) => watchedIn(key).flatMap((w) => w.runs).sort((a, b) => String(b.at).localeCompare(String(a.at)))[0] ?? null;
|
|
325
|
+
// Benchmarked folders get more room, so their numbers show.
|
|
326
|
+
const items = m.modules.map((mod) => ({ ...mod, weight: Math.max(1, mod.files) + (watchedIn(mod.key).length ? 20 : 0) })).sort((a, b) => b.weight - a.weight);
|
|
327
|
+
const W = box.clientWidth;
|
|
328
|
+
const H = Math.max(320, view.clientHeight - box.offsetTop - 24);
|
|
329
|
+
box.style.height = `${H}px`;
|
|
330
|
+
const big = items.slice(0, 100);
|
|
331
|
+
const rest = items.slice(100);
|
|
332
|
+
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 });
|
|
333
|
+
box.innerHTML = squarify(big, 0, 0, W, H)
|
|
334
|
+
.map(({ x, y, w, h, item }) => {
|
|
335
|
+
const on = !item.more && watchedIn(item.key).length > 0;
|
|
336
|
+
const r = on ? last(item.key) : null;
|
|
337
|
+
const t = trend(r?.worst, limit);
|
|
338
|
+
const sel = picked?.module === item.key;
|
|
339
|
+
const tip = `${item.key}: ${item.files} files${on ? ` · benchmarked${r ? ` · ${r.issue ?? r.agent}: ${pct(r.worst)} at worst` : ', no issue has measured it yet'}` : ''}`;
|
|
340
|
+
return `<div class="map-tile speed ${on ? 'watched' : ''} ${t} ${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" title="${esc(tip)}">
|
|
341
|
+
${w > 46 && h > 22 ? `<span class="map-name">${esc(item.key === '.' ? '(top level)' : item.key)}</span>` : ''}
|
|
342
|
+
${on && w > 40 && h > 38 ? `<span class="map-speed ${t}">${r ? esc(`${r.issue ?? 'last'} ${pct(r.worst)}`) : 'benchmarked'}</span>` : w > 46 && h > 38 ? `<span class="map-count">${item.files}</span>` : ''}
|
|
343
|
+
</div>`;
|
|
344
|
+
})
|
|
345
|
+
.join('');
|
|
346
|
+
$('#map-warn').innerHTML = speedPanel(limit);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function runRow(r, limit) {
|
|
350
|
+
const cases = r.cases
|
|
351
|
+
.map((c) => `<tr class="${trend(c.change, limit)}"><td>${esc(c.name)}</td><td>${c.before ?? '—'}</td><td>${c.after}</td><td>${esc(c.unit ?? '')}</td><td>${pct(c.change) || '—'}</td><td>${esc(c.note ?? '')}</td></tr>`)
|
|
352
|
+
.join('');
|
|
353
|
+
return `<li><details><summary><b>${esc(r.issue ?? '(no issue)')}</b> <button class="link" data-map-open="${esc(r.agentId)}" title="Open its agent">${esc(r.agent && r.agent !== r.issue ? r.agent : 'its agent')}</button> <span class="map-speed ${trend(r.worst, limit)}">${r.worst === null ? 'no before numbers' : `${pct(r.worst)} at worst`}</span> <span class="hint">${esc(new Date(r.at).toLocaleDateString())} · ${r.cases.length} case${r.cases.length === 1 ? '' : 's'}${r.accepted ? ' · marked fine' : ''}</span></summary>
|
|
354
|
+
<table class="bench-cases"><thead><tr><th>Case</th><th>Before</th><th>After</th><th>Unit</th><th>Change</th><th>Note</th></tr></thead><tbody>${cases}</tbody></table>
|
|
355
|
+
${r.command ? `<p class="hint">Run with <code>${esc(r.command)}</code>${r.env ? ` · ${esc(r.env)}` : ''}</p>` : ''}</details></li>`;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Under the map: the picked folder's benchmarks and the issues that ran them, else a summary. */
|
|
359
|
+
function speedPanel(limit) {
|
|
360
|
+
const sp = data.speed;
|
|
361
|
+
if (picked?.module !== undefined) {
|
|
362
|
+
const name = picked.module === '.' ? '(top level)' : picked.module;
|
|
363
|
+
const ws = watchedIn(picked.module);
|
|
364
|
+
const unpick = '<button class="small" data-map-unpick>×</button>';
|
|
365
|
+
if (!ws.length) {
|
|
366
|
+
return `<div class="map-pick"><b>${esc(name)}</b> <span class="hint">not benchmarked</span> ${unpick}
|
|
367
|
+
<form class="bench-watch" data-bench-watch="${esc(picked.module === '.' ? '' : picked.module)}"><input name="components" placeholder="Jira components or labels for it (optional, comma-separated)" autocomplete="off" /> <button class="small primary">Benchmark this folder</button></form>
|
|
368
|
+
<p class="hint">Agents on Jira issues that name it (a component or label, or the folder in the request), or whose change touches it, run its micro benchmarks before and after. The benchmarks are kept on this computer, outside the repository, and reused by the next issue.</p></div>`;
|
|
369
|
+
}
|
|
370
|
+
return ws
|
|
371
|
+
.map((w) => `<div class="map-pick"><b>${esc(w.path || '(whole repository)')}</b> <span class="hint">${w.runs.length ? `${w.runs.length} issue${w.runs.length === 1 ? '' : 's'} measured` : 'no issue has measured it yet'} · kept in <code>${esc(w.dir)}</code></span> ${unpick}
|
|
372
|
+
<form class="bench-watch" data-bench-watch="${esc(w.path)}"><input name="components" value="${esc(w.components.join(', '))}" placeholder="Jira components or labels for it (comma-separated)" autocomplete="off" /> <button class="small">Save</button> <button type="button" class="small" data-bench-unwatch="${esc(w.id)}" title="Agents stop benchmarking it; what was measured stays">Stop benchmarking</button></form>
|
|
373
|
+
${w.runs.length ? `<ul class="map-bug-list bench-runs">${w.runs.map((r) => runRow(r, limit)).join('')}</ul>` : ''}</div>`)
|
|
374
|
+
.join('');
|
|
375
|
+
}
|
|
376
|
+
if (!sp.modules.length) return `<p class="hint">No folder is benchmarked in this project yet. Click one where speed matters, then <b>Benchmark this folder</b>: agents on Jira issues about it measure its speed before and after their change.${sp.other.length ? ` ${sp.other.length} run${sp.other.length === 1 ? '' : 's'} from agents with benchmarks on are kept too.` : ''}</p>`;
|
|
377
|
+
return `<p class="hint">Benchmarked: ${sp.modules
|
|
378
|
+
.map((w) => {
|
|
379
|
+
const r = w.runs[0];
|
|
380
|
+
return `<button class="link" data-map-mod="${esc(w.path ? w.path.split('/').slice(0, 2).join('/') : '.')}">${esc(w.path || '(whole repository)')}</button>${r ? ` <span class="map-speed ${trend(r.worst, limit)}">${esc(r.issue ?? 'last')} ${pct(r.worst)}</span>` : ''}`;
|
|
381
|
+
})
|
|
382
|
+
.join(', ')}. Click a folder for its issues and numbers.</p>`;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
async function benchWatch(form) {
|
|
386
|
+
try {
|
|
387
|
+
await api('POST', '/benchmodules', { project: data.project.key, path: form.dataset.benchWatch, components: form.components.value });
|
|
388
|
+
toast?.('Saved: agents on Jira issues about it will benchmark it', 4000);
|
|
389
|
+
} catch (e) {
|
|
390
|
+
toast?.(e.message, 6000);
|
|
391
|
+
}
|
|
392
|
+
load();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
async function benchUnwatch(id) {
|
|
396
|
+
try {
|
|
397
|
+
await api('DELETE', `/benchmodules/${id}`);
|
|
398
|
+
toast?.('Not benchmarked any more', 3000);
|
|
399
|
+
} catch (e) {
|
|
400
|
+
toast?.(e.message, 6000);
|
|
401
|
+
}
|
|
402
|
+
load();
|
|
403
|
+
}
|
|
404
|
+
|
|
304
405
|
function show(on) {
|
|
305
406
|
open = on;
|
|
306
407
|
view.hidden = !on;
|
|
@@ -337,6 +438,13 @@ export function initCodeMap({ api, $, esc, agents, openAgent, openBugs, toast })
|
|
|
337
438
|
const mod = e.target.closest('[data-map-mod]');
|
|
338
439
|
if (mod?.dataset.mapMod) return (picked = picked?.module === mod.dataset.mapMod ? null : { module: mod.dataset.mapMod }), draw();
|
|
339
440
|
}
|
|
441
|
+
if (layer === 'speed') {
|
|
442
|
+
const un = e.target.closest('[data-bench-unwatch]');
|
|
443
|
+
if (un) return benchUnwatch(un.dataset.benchUnwatch);
|
|
444
|
+
if (e.target.closest('[data-map-unpick]')) return (picked = null), draw();
|
|
445
|
+
const mod = e.target.closest('[data-map-mod]');
|
|
446
|
+
if (mod?.dataset.mapMod) return (picked = picked?.module === mod.dataset.mapMod ? null : { module: mod.dataset.mapMod }), draw();
|
|
447
|
+
}
|
|
340
448
|
const o = e.target.closest('[data-map-open]');
|
|
341
449
|
if (o) {
|
|
342
450
|
show(false);
|
|
@@ -346,6 +454,12 @@ export function initCodeMap({ api, $, esc, agents, openAgent, openBugs, toast })
|
|
|
346
454
|
if (b?.dataset.map === 'close') return show(false);
|
|
347
455
|
if (b?.dataset.map === 'refresh') return load();
|
|
348
456
|
});
|
|
457
|
+
view.addEventListener('submit', (e) => {
|
|
458
|
+
const f = e.target.closest('[data-bench-watch]');
|
|
459
|
+
if (!f) return;
|
|
460
|
+
e.preventDefault();
|
|
461
|
+
benchWatch(f);
|
|
462
|
+
});
|
|
349
463
|
view.addEventListener('change', (e) => {
|
|
350
464
|
if (e.target.dataset.mapSet !== 'project') return;
|
|
351
465
|
project = e.target.value;
|
package/public/style.css
CHANGED
|
@@ -1148,6 +1148,26 @@ body.mapping .layout, body.mapping .watch-view { display: none; }
|
|
|
1148
1148
|
.map-pick { padding: 6px 10px; margin-bottom: 8px; border-radius: 6px; background: var(--panel); font-size: 13px; }
|
|
1149
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
1150
|
.map-bug-list { margin: 6px 0 0 !important; }
|
|
1151
|
+
.map-tile.speed { cursor: pointer; }
|
|
1152
|
+
.map-tile.speed.watched { background: color-mix(in srgb, var(--accent) 22%, var(--panel)); border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
|
|
1153
|
+
.map-tile.speed.watched.slower { background: color-mix(in srgb, var(--red) 30%, var(--panel)); }
|
|
1154
|
+
.map-tile.speed.watched.faster { background: color-mix(in srgb, var(--green) 26%, var(--panel)); }
|
|
1155
|
+
.map-tile.speed.picked { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
|
|
1156
|
+
.map-tile.speed:hover { filter: brightness(1.08); }
|
|
1157
|
+
.map-key.watched { background: color-mix(in srgb, var(--accent) 35%, var(--panel)); }
|
|
1158
|
+
.map-key.slower { background: color-mix(in srgb, var(--red) 45%, var(--panel)); }
|
|
1159
|
+
.map-key.faster { background: color-mix(in srgb, var(--green) 45%, var(--panel)); }
|
|
1160
|
+
.map-speed { 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; color: var(--muted); }
|
|
1161
|
+
.map-speed.slower { color: var(--red); }
|
|
1162
|
+
.map-speed.faster { color: var(--green); }
|
|
1163
|
+
.bench-watch { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
|
|
1164
|
+
.bench-watch input { flex: 1; min-width: 200px; }
|
|
1165
|
+
.map-warn .bench-runs li { display: block; }
|
|
1166
|
+
.bench-runs summary { cursor: pointer; }
|
|
1167
|
+
table.bench-cases { margin: 6px 0; border-collapse: collapse; font-size: 12px; width: 100%; }
|
|
1168
|
+
table.bench-cases th, table.bench-cases td { text-align: left; padding: 2px 8px 2px 0; border-bottom: 1px solid var(--border); }
|
|
1169
|
+
table.bench-cases tr.slower td:nth-child(5) { color: var(--red); font-weight: 600; }
|
|
1170
|
+
table.bench-cases tr.faster td:nth-child(5) { color: var(--green); font-weight: 600; }
|
|
1151
1171
|
|
|
1152
1172
|
/* ---------- Jira: issues agents work on */
|
|
1153
1173
|
.issues-dialog { width: min(1100px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 16px; }
|
package/public/today.js
CHANGED
|
@@ -61,6 +61,7 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
|
|
|
61
61
|
if (it.kind === 'pr-requested') return [btn('review', 'Review it', 'A reviewer agent reads it and finds what blocks approval (a)', true), link(it.url, 'PR')].join(' ');
|
|
62
62
|
if (it.kind === 'pr-ready') return [btn('open-reviews', 'Open review', 'Pick what to post (Enter)', true), link(it.url, 'PR')].join(' ');
|
|
63
63
|
if (it.kind === 'rule') return btn('inbox', 'Inbox', 'Decide in the inbox (Enter)', true);
|
|
64
|
+
if (it.kind === 'bench') return [btn('fix', 'Ask to fix', 'Ask the agent to make it as fast as before, or say why it can\'t be (a)', true), btn('done', "It's fine", 'The slowdown is expected: off the list (d)'), btn('open', 'Open', "Open the agent's session (Enter)")].join(' ');
|
|
64
65
|
if (it.kind === 'bug-pr') return [link(it.url, 'Open PR'), btn('done', 'Done', 'You looked at it: off the list (d)'), btn('bugs', 'Details', 'The bug and how the fix was checked (Enter)')].join(' ');
|
|
65
66
|
if (it.kind === 'bug') return [btn('fix', 'Fix', 'Start an agent on it, with the failing test (a)', true), btn('skip', 'Snooze', 'Until tomorrow 9am (s)'), btn('notbug', 'Not a bug', "It won't be reported again"), btn('bugs', 'Evidence', 'See it in Bugs (Enter)')].join(' ');
|
|
66
67
|
return [it.agentId ? btn('open', 'Open', "Open the agent's session (Enter)", it.score < 20) : '', link(it.url, it.issueKey ? 'Jira' : 'Link')].join(' ');
|
|
@@ -282,6 +283,13 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
|
|
|
282
283
|
t.setHours(9, 0, 0, 0);
|
|
283
284
|
await api('POST', '/findings/set', { ids: [it.findingId], status: what === 'skip' ? 'snoozed' : 'notbug', until: what === 'skip' ? t.toISOString() : null });
|
|
284
285
|
changedWith(what === 'skip' ? 'Snoozed until tomorrow 9am' : "Not a bug: it won't be reported again", what === 'skip' ? 'snoozed' : 'not a bug', () => api('POST', '/findings/set', { ids: [it.findingId], status: 'open' }));
|
|
286
|
+
} else if (it.kind === 'bench' && (what === 'fix' || what === 'assign')) {
|
|
287
|
+
await api('POST', `/benchruns/${it.runId}/fix`, {});
|
|
288
|
+
toast?.('Asked the agent to fix it, or say why it can\'t be', 4000);
|
|
289
|
+
return;
|
|
290
|
+
} else if (it.kind === 'bench' && what === 'done') {
|
|
291
|
+
await api('POST', `/benchruns/${it.runId}/accept`, { accepted: true });
|
|
292
|
+
changedWith("It's fine: off the list", 'accepted', () => api('POST', `/benchruns/${it.runId}/accept`, { accepted: false }));
|
|
285
293
|
} else if (it.kind === 'bug-pr' && what === 'done') {
|
|
286
294
|
await api('POST', '/findings/set', { ids: [it.findingId], status: 'done' });
|
|
287
295
|
changedWith('Done: off the list', 'done', () => api('POST', '/findings/set', { ids: [it.findingId], status: 'pr' }));
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// Micro benchmarks per module, for the Jira issues that change them. You mark the modules of a
|
|
2
|
+
// project where speed matters (on the Map's Speed view), each with the Jira components or labels
|
|
3
|
+
// that mean it. An agent working a Jira issue benchmarks a module when its issue names it (a
|
|
4
|
+
// component or label, or the folder in the request), or when its change touches the module: if it
|
|
5
|
+
// says it's done without having measured one, it's asked to before it counts as done.
|
|
6
|
+
//
|
|
7
|
+
// The benchmarks of a module are kept on this computer, outside the repository (bench/ in the home
|
|
8
|
+
// folder), and reused: the next issue on the module runs the same ones again, before and after its
|
|
9
|
+
// change, and adds its own cases, so the numbers line up from one issue to the next. Each run
|
|
10
|
+
// leaves its numbers in BENCH.json next to the agent's brief; they are kept here per module and
|
|
11
|
+
// issue, and a case more than 5% slower is shown in Today.
|
|
12
|
+
|
|
13
|
+
import crypto from 'node:crypto';
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { briefDir } from './brief.js';
|
|
17
|
+
import { cleanPath } from './bughunt.js';
|
|
18
|
+
import { paths } from './config.js';
|
|
19
|
+
|
|
20
|
+
export const RESULTS_FILE = 'BENCH.json';
|
|
21
|
+
export const resultsPath = (agentId) => path.join(briefDir(agentId), RESULTS_FILE);
|
|
22
|
+
// Slower than this (in percent) and the run shows in Today.
|
|
23
|
+
export const SLOWER_PCT = 5;
|
|
24
|
+
const MAX_RUNS = 500;
|
|
25
|
+
const MAX_CASES = 40;
|
|
26
|
+
const err = (status, message) => Object.assign(new Error(message), { status });
|
|
27
|
+
const clip = (s, n) => {
|
|
28
|
+
const t = String(s ?? '').trim();
|
|
29
|
+
return t.length > n ? `${t.slice(0, n - 1)}…` : t;
|
|
30
|
+
};
|
|
31
|
+
const now = () => new Date().toISOString();
|
|
32
|
+
|
|
33
|
+
/** Where a module's benchmarks are kept: bench/<project>-<hash>/<module> in the home folder. */
|
|
34
|
+
export function moduleDir(projectKey, modulePath, home = paths.home) {
|
|
35
|
+
const name = String(projectKey).split(/[/:]/).filter(Boolean).pop()?.replace(/[^\w.-]+/g, '-').slice(0, 40) || 'project';
|
|
36
|
+
const hash = crypto.createHash('sha1').update(String(projectKey)).digest('hex').slice(0, 8);
|
|
37
|
+
return path.join(home, 'bench', `${name}-${hash}`, (modulePath || '_root').replace(/\//g, '__'));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Whether a repository file is in the module (a folder; '' is the whole repository). */
|
|
41
|
+
export const inModule = (file, modulePath) => !modulePath || file === modulePath || file.startsWith(`${modulePath}/`);
|
|
42
|
+
|
|
43
|
+
/** Component or label names: trimmed, no duplicates (case aside), at most 20. */
|
|
44
|
+
function names(list) {
|
|
45
|
+
const out = [];
|
|
46
|
+
for (const n of (Array.isArray(list) ? list : String(list ?? '').split(',')).map((x) => clip(x, 80)).filter(Boolean)) {
|
|
47
|
+
if (!out.some((o) => o.toLowerCase() === n.toLowerCase())) out.push(n);
|
|
48
|
+
}
|
|
49
|
+
return out.slice(0, 20);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The watched modules a Jira issue is about: a component or label of the issue is one of the
|
|
54
|
+
* module's (or its folder's name), or the request names the folder ("src/storage").
|
|
55
|
+
*/
|
|
56
|
+
export function matchModules(modules, { components = [], labels = [], text = '' } = {}) {
|
|
57
|
+
const tags = new Set([...components, ...labels].map((x) => String(x).trim().toLowerCase()).filter(Boolean));
|
|
58
|
+
const body = String(text ?? '');
|
|
59
|
+
return modules.filter((m) => {
|
|
60
|
+
const own = [...(m.components ?? []), m.path.split('/').pop()].map((x) => String(x).toLowerCase()).filter(Boolean);
|
|
61
|
+
if (own.some((x) => tags.has(x))) return true;
|
|
62
|
+
// The folder by its path, not its last name alone: "api" in a sentence says little.
|
|
63
|
+
return m.path.includes('/') && new RegExp(`(^|[\\s\`'"(])${m.path.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(/|[\\s\`'".,)]|$)`).test(body);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A case's numbers, checked: { name, unit, before, after, better, change, note }. `change` is how
|
|
69
|
+
* much worse it got in percent (negative is faster), whichever way is better for the unit.
|
|
70
|
+
*/
|
|
71
|
+
export function normalizeCase(c) {
|
|
72
|
+
if (!c || typeof c !== 'object') return null;
|
|
73
|
+
const before = Number(c.before);
|
|
74
|
+
const after = Number(c.after);
|
|
75
|
+
const name = clip(c.name, 120);
|
|
76
|
+
if (!name || !Number.isFinite(after) || after < 0) return null;
|
|
77
|
+
const unit = clip(c.unit, 20) || null;
|
|
78
|
+
// Throughput (ops/s, MB/s) is better higher; time is better lower.
|
|
79
|
+
const better = c.better === 'higher' || c.better === 'lower' ? c.better : /\/s(ec)?$|ops|per sec|throughput/i.test(unit ?? '') ? 'higher' : 'lower';
|
|
80
|
+
const has = Number.isFinite(before) && before > 0;
|
|
81
|
+
const change = has ? Math.round(((better === 'lower' ? after / before : before / after) - 1) * 1000) / 10 : null;
|
|
82
|
+
return { name, unit, before: has ? before : null, after, better, change, ...(c.note ? { note: clip(c.note, 300) } : {}) };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** An agent's BENCH.json, checked: { runs: [{ module, command, cases }], env } (null when missing or unreadable). */
|
|
86
|
+
export function readResults(agentId) {
|
|
87
|
+
let raw;
|
|
88
|
+
try {
|
|
89
|
+
raw = JSON.parse(fs.readFileSync(resultsPath(agentId), 'utf8'));
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return normalizeResults(raw);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function normalizeResults(raw) {
|
|
97
|
+
// One module's results on their own, or a list of them.
|
|
98
|
+
const list = Array.isArray(raw?.modules) ? raw.modules : Array.isArray(raw) ? raw : raw && typeof raw === 'object' ? [raw] : [];
|
|
99
|
+
const runs = [];
|
|
100
|
+
for (const r of list) {
|
|
101
|
+
const cases = (Array.isArray(r?.cases) ? r.cases : []).map(normalizeCase).filter(Boolean).slice(0, MAX_CASES);
|
|
102
|
+
if (!cases.length) continue;
|
|
103
|
+
let module = '';
|
|
104
|
+
try {
|
|
105
|
+
module = cleanPath(r.module ?? '');
|
|
106
|
+
} catch {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
runs.push({ module, command: clip(r.command, 300) || null, cases });
|
|
110
|
+
}
|
|
111
|
+
return runs.length ? { runs, env: clip(raw?.env ?? list[0]?.env, 300) || null } : null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The agent's instructions for the modules it benchmarks: [{ path, dir, existing }]. */
|
|
115
|
+
export function moduleBenchPrompt(file, json, modules) {
|
|
116
|
+
const list = modules
|
|
117
|
+
.map((m) => `- ${m.path || '(the whole repository)'}: the benchmarks are kept in ${m.dir}${m.existing ? ' (earlier issues left benchmarks there: read its README.md and run them as they are, then add cases for your change)' : ' (none yet: start them there, with a README.md that says what each measures and the one command that runs them)'}`)
|
|
118
|
+
.join('\n');
|
|
119
|
+
return (
|
|
120
|
+
'Measure the speed of these modules with micro benchmarks, once your change works (tests pass):\n' +
|
|
121
|
+
`${list}\n` +
|
|
122
|
+
"Each module's benchmarks are kept outside the repository in the folder named, and reused from one issue to the next, " +
|
|
123
|
+
'so the numbers can be compared: keep the existing cases and their names as they are (fix one only if your change breaks it, and say so), ' +
|
|
124
|
+
'and add cases for the code you changed, with realistic inputs at two or three sizes. Never copy them into the repository or commit them. ' +
|
|
125
|
+
'Warm up, run enough iterations for stable numbers, and take the median. Run every case on the base commit ' +
|
|
126
|
+
'(check it out in a temporary git worktree) and on your change, back to back on this machine. ' +
|
|
127
|
+
`Write the results to ${file} (Markdown: what was measured and the command, a table case | before | after | change, the environment, notes), and the numbers to ${json} as JSON:\n` +
|
|
128
|
+
'{"modules": [{"module": "<folder as listed>", "command": "<how to run them>", "cases": [{"name": "<case>", "unit": "ns/op", "before": 1234, "after": 1100, "note": "<only when it got slower>"}]}], "env": "<CPU, OS, runtime>"}\n' +
|
|
129
|
+
`A case more than ${SLOWER_PCT}% slower needs a note on why, or a fix. If you open a pull request, put the table in its description. ` +
|
|
130
|
+
'Only real measurements: never estimate a number. Run them again if you change the code afterwards.'
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** What the agent is told when it says it's done but changed a module without measuring it. */
|
|
135
|
+
export function askMessage(file, json, modules) {
|
|
136
|
+
return `Before this is done: your change touches ${modules.map((m) => m.path || 'the repository').join(', ')}, where speed matters, and there are no benchmark results for it yet. ${moduleBenchPrompt(file, json, modules)} Then mark the brief done again.`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export class ModuleBenchmarks {
|
|
140
|
+
/**
|
|
141
|
+
* `changedFiles(agent)` gives the files an agent's branch changed (repository paths), and
|
|
142
|
+
* `read(agentId)` its results (both for tests); `home` is where the benchmarks are kept.
|
|
143
|
+
*/
|
|
144
|
+
constructor({ manager, store, changedFiles = async () => [], read = readResults, home = paths.home, log = () => {} }) {
|
|
145
|
+
this.manager = manager;
|
|
146
|
+
this.store = store;
|
|
147
|
+
this.changedFiles = changedFiles;
|
|
148
|
+
this.read = read;
|
|
149
|
+
this.home = home;
|
|
150
|
+
this.log = log;
|
|
151
|
+
this.onFinished = (agent) => {
|
|
152
|
+
if (agent) this.finished(agent.id).catch((e) => this.log(`benchmarks: ${e.message}`));
|
|
153
|
+
};
|
|
154
|
+
manager.on('finished', this.onFinished);
|
|
155
|
+
// The manager asks which modules an agent benchmarks, and how to tell it (manager.js).
|
|
156
|
+
manager.benchModules = this;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
close() {
|
|
160
|
+
this.manager.off('finished', this.onFinished);
|
|
161
|
+
if (this.manager.benchModules === this) this.manager.benchModules = null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
get modules() {
|
|
165
|
+
return (this.store.data.benchModules ??= []);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
get runs() {
|
|
169
|
+
return (this.store.data.benchRuns ??= []);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Mark a module of a project for benchmarks, or change its components: { project, path, components }. */
|
|
173
|
+
watch({ project, path: p, components } = {}) {
|
|
174
|
+
const key = String(project ?? '').trim();
|
|
175
|
+
if (!key) throw err(400, 'Which project?');
|
|
176
|
+
const folder = cleanPath(p ?? '');
|
|
177
|
+
let m = this.modules.find((x) => x.project === key && x.path === folder);
|
|
178
|
+
if (!m) this.modules.push((m = { id: crypto.randomBytes(3).toString('hex'), project: key, path: folder, components: [], addedAt: now() }));
|
|
179
|
+
if (components !== undefined) m.components = names(components);
|
|
180
|
+
this.store.save();
|
|
181
|
+
return this.view(m);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
unwatch(id) {
|
|
185
|
+
const i = this.modules.findIndex((x) => x.id === id);
|
|
186
|
+
if (i < 0) throw err(404, 'No such module');
|
|
187
|
+
this.modules.splice(i, 1);
|
|
188
|
+
this.store.save();
|
|
189
|
+
return { ok: true };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
view(m) {
|
|
193
|
+
const dir = moduleDir(m.project, m.path, this.home);
|
|
194
|
+
return { ...m, dir, existing: fs.existsSync(dir) && fs.readdirSync(dir).length > 0 };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The watched modules of a project (by key). */
|
|
198
|
+
of(projectKey) {
|
|
199
|
+
return this.modules.filter((m) => m.project === projectKey);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** An agent this applies to: a task with a Jira issue, not a hunter, fixer, reviewer or team member. */
|
|
203
|
+
eligible(agent) {
|
|
204
|
+
return Boolean(agent && agent.kind === 'task' && !agent.hunting && !agent.fixing && !agent.reviewing && !agent.team && !agent.builds && this.manager.issueKey(agent));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The modules an agent should benchmark from its issue: { components, labels } and its request. */
|
|
208
|
+
forIssue(agent, fields = {}) {
|
|
209
|
+
if (!this.eligible(agent)) return [];
|
|
210
|
+
const key = this.manager.projectInfo(agent)?.key;
|
|
211
|
+
return matchModules(this.of(key), { ...fields, text: agent.intent }).map((m) => this.view(m));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** The modules an agent was given to benchmark, as it should be told them. */
|
|
215
|
+
forAgent(agent) {
|
|
216
|
+
const key = this.manager.projectInfo(agent)?.key;
|
|
217
|
+
return (agent.benchModules ?? []).map((p) => this.view(this.of(key).find((m) => m.path === p) ?? { project: key, path: p }));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** It says it's done: keep its numbers, or ask for them when its change touched a watched module. */
|
|
221
|
+
async finished(agentId) {
|
|
222
|
+
const agent = this.store.get(agentId);
|
|
223
|
+
if (!agent) return null;
|
|
224
|
+
const recorded = this.record(agent);
|
|
225
|
+
if (!this.eligible(agent)) return { recorded, asked: [] };
|
|
226
|
+
const key = this.manager.projectInfo(agent)?.key;
|
|
227
|
+
const watched = this.of(key);
|
|
228
|
+
if (!watched.length) return { recorded, asked: [] };
|
|
229
|
+
const changed = await this.changedFiles(agent).catch(() => []);
|
|
230
|
+
const measured = new Set((this.read(agent.id)?.runs ?? []).map((r) => r.module));
|
|
231
|
+
const asked = new Set(agent.benchAsked ?? []);
|
|
232
|
+
const missing = watched.filter((m) => changed.some((f) => inModule(f, m.path)) && !measured.has(m.path) && !asked.has(m.path)).map((m) => this.view(m));
|
|
233
|
+
if (!missing.length) return { recorded, asked: [] };
|
|
234
|
+
// Asked once per module: a second "done" without numbers stands.
|
|
235
|
+
this.manager.addBenchModules(agent.id, missing, { asked: true });
|
|
236
|
+
return { recorded, asked: missing.map((m) => m.path) };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Keep an agent's numbers, one run per module (a new run of the same agent replaces its last). */
|
|
240
|
+
record(agent) {
|
|
241
|
+
const res = this.read(agent.id);
|
|
242
|
+
if (!res) return 0;
|
|
243
|
+
const projectKey = this.manager.projectInfo(agent)?.key ?? null;
|
|
244
|
+
const issue = this.manager.issueKey(agent);
|
|
245
|
+
let n = 0;
|
|
246
|
+
for (const r of res.runs) {
|
|
247
|
+
const at = this.runs.findIndex((x) => x.agentId === agent.id && x.module === r.module);
|
|
248
|
+
const prev = at >= 0 ? this.runs[at] : null;
|
|
249
|
+
const worst = r.cases.reduce((w, c) => (c.change !== null && (w === null || c.change > w) ? c.change : w), null);
|
|
250
|
+
const run = {
|
|
251
|
+
id: prev?.id ?? crypto.randomBytes(3).toString('hex'),
|
|
252
|
+
agentId: agent.id,
|
|
253
|
+
agent: agent.name,
|
|
254
|
+
issue,
|
|
255
|
+
project: projectKey,
|
|
256
|
+
module: r.module,
|
|
257
|
+
command: r.command,
|
|
258
|
+
env: res.env,
|
|
259
|
+
cases: r.cases,
|
|
260
|
+
worst,
|
|
261
|
+
at: now(),
|
|
262
|
+
...(prev?.accepted ? { accepted: prev.accepted } : {}),
|
|
263
|
+
};
|
|
264
|
+
if (prev && JSON.stringify(prev.cases) === JSON.stringify(run.cases)) continue;
|
|
265
|
+
if (at >= 0) this.runs.splice(at, 1);
|
|
266
|
+
this.runs.unshift(run);
|
|
267
|
+
n++;
|
|
268
|
+
}
|
|
269
|
+
if (this.runs.length > MAX_RUNS) this.runs.length = MAX_RUNS;
|
|
270
|
+
if (n) this.store.save();
|
|
271
|
+
return n;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** Slower than it should be, and nobody has said it's fine. */
|
|
275
|
+
slower() {
|
|
276
|
+
return this.runs.filter((r) => r.worst !== null && r.worst > SLOWER_PCT && !r.accepted);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** "It's fine" for a slower run (Undo: `accepted` false). */
|
|
280
|
+
accept(runId, accepted = true) {
|
|
281
|
+
const r = this.runs.find((x) => x.id === runId);
|
|
282
|
+
if (!r) throw err(404, 'No such benchmark run');
|
|
283
|
+
if (accepted) r.accepted = now();
|
|
284
|
+
else delete r.accepted;
|
|
285
|
+
this.store.save();
|
|
286
|
+
return r;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** Ask the agent that made it slower to fix it, or explain. */
|
|
290
|
+
askToFix(runId) {
|
|
291
|
+
const r = this.runs.find((x) => x.id === runId);
|
|
292
|
+
if (!r) throw err(404, 'No such benchmark run');
|
|
293
|
+
const cases = r.cases.filter((c) => c.change !== null && c.change > SLOWER_PCT);
|
|
294
|
+
const lines = cases.map((c) => `- ${c.name}: ${c.before} → ${c.after}${c.unit ? ` ${c.unit}` : ''} (${c.change}% slower)`).join('\n');
|
|
295
|
+
this.manager.tell(r.agentId, `Your change made ${r.module || 'the repository'} slower in the micro benchmarks:\n${lines}\nFind out why and make it at least as fast as before, or, if it can't be, say why in the benchmark notes. Then run the benchmarks again and update the results.`, { source: 'benchmarks' });
|
|
296
|
+
return { ok: true };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** For the Map's Speed view: the project's watched modules, each with its issues' runs, newest first. */
|
|
300
|
+
speed(projectKey) {
|
|
301
|
+
const runs = this.runs.filter((r) => r.project === projectKey);
|
|
302
|
+
return {
|
|
303
|
+
modules: this.of(projectKey).map((m) => ({ ...this.view(m), runs: runs.filter((r) => r.module === m.path).slice(0, 20) })),
|
|
304
|
+
// Measured in modules nobody marked (an agent with benchmarks on).
|
|
305
|
+
other: runs.filter((r) => !this.of(projectKey).some((m) => m.path === r.module)).slice(0, 20),
|
|
306
|
+
slowerPct: SLOWER_PCT,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
}
|
package/src/jira.js
CHANGED
|
@@ -226,8 +226,8 @@ export async function issueSummary(issue, opts = {}) {
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
/**
|
|
229
|
-
* The issue's summary and workflow status ({ summary, status, category }:
|
|
230
|
-
* "new", "indeterminate" or "done"), or null when it can't be had.
|
|
229
|
+
* The issue's summary and workflow status ({ summary, status, category, components, labels }:
|
|
230
|
+
* category is Jira's "new", "indeterminate" or "done"), or null when it can't be had.
|
|
231
231
|
*/
|
|
232
232
|
export async function issueFields({ key, site }, { jira = loadJira(), fetchImpl = fetch, timeoutMs = 6000, allow = null } = {}) {
|
|
233
233
|
const host = (() => {
|
|
@@ -245,7 +245,7 @@ export async function issueFields({ key, site }, { jira = loadJira(), fetchImpl
|
|
|
245
245
|
if (!allowed) return null;
|
|
246
246
|
const headers = { accept: 'application/json' };
|
|
247
247
|
if (configured) headers.authorization = authOf(jira);
|
|
248
|
-
const q = `${encodeURIComponent(key)}?fields=summary,status,description`;
|
|
248
|
+
const q = `${encodeURIComponent(key)}?fields=summary,status,description,components,labels`;
|
|
249
249
|
try {
|
|
250
250
|
// Your site as saved: it may have a path (https://host/jira) that the link's origin leaves out.
|
|
251
251
|
const res = await jiraGet(fetchImpl, configured ? jira.site : site, { path: `/rest/api/3/issue/${q}` }, configured ? { path: `/rest/api/2/issue/${q}` } : null, { headers, signal: AbortSignal.timeout(timeoutMs) });
|
|
@@ -258,7 +258,10 @@ export async function issueFields({ key, site }, { jira = loadJira(), fetchImpl
|
|
|
258
258
|
const status = typeof f.status?.name === 'string' ? f.status.name.slice(0, 60) : null;
|
|
259
259
|
if (!summary && !status) return null;
|
|
260
260
|
const synopsis = synopsisOf(f.description);
|
|
261
|
-
|
|
261
|
+
// What part of the product it's in: the issue's components and labels.
|
|
262
|
+
const components = (Array.isArray(f.components) ? f.components : []).map((c) => c?.name).filter((n) => typeof n === 'string').map((n) => n.slice(0, 80));
|
|
263
|
+
const labels = (Array.isArray(f.labels) ? f.labels : []).filter((n) => typeof n === 'string').map((n) => n.slice(0, 80));
|
|
264
|
+
return { summary, status, category: typeof f.status?.statusCategory?.key === 'string' ? f.status.statusCategory.key : null, ...(synopsis ? { synopsis } : {}), ...(components.length ? { components } : {}), ...(labels.length ? { labels } : {}) };
|
|
262
265
|
} catch (e) {
|
|
263
266
|
if (configured) problem = { at: new Date().toISOString(), reason: reasonOf(jira.site, null, e) };
|
|
264
267
|
return null;
|
package/src/manager.js
CHANGED
|
@@ -107,8 +107,9 @@ import { spawn } from 'node:child_process';
|
|
|
107
107
|
import * as git from './git.js';
|
|
108
108
|
import { bugHeat, buildMap, touchedFiles } from './codemap.js';
|
|
109
109
|
import { parseDiff } from '../public/review.js';
|
|
110
|
-
import { assignedIssues, issueFields,
|
|
111
|
-
import { issueRows } from './issues.js';
|
|
110
|
+
import { assignedIssues, issueFields, jiraProblem, leadingIssue, loadJira, wordsAfterLink } from './jira.js';
|
|
111
|
+
import { issueOf, issueRows } from './issues.js';
|
|
112
|
+
import { askMessage, moduleBenchPrompt, resultsPath } from './benchmarks.js';
|
|
112
113
|
import { designRows } from './designs.js';
|
|
113
114
|
import { reviewPath, reviewerPrompt } from './reviews.js';
|
|
114
115
|
import { findingsPath, fixPath, fixerPrompt, hunterPrompt } from './bughunt.js';
|
|
@@ -736,6 +737,9 @@ export class AgentManager extends EventEmitter {
|
|
|
736
737
|
// and until then by the words after the link.
|
|
737
738
|
const issue = leadingIssue(intent);
|
|
738
739
|
if (issue) agent.synopsis = { text: wordsAfterLink(intent), source: 'request', key: issue.key };
|
|
740
|
+
// Modules where speed matters that the request names: benchmarked (benchmarks.js).
|
|
741
|
+
const named = this.benchModules?.forIssue(agent) ?? [];
|
|
742
|
+
if (named.length) agent.benchModules = named.map((m) => m.path);
|
|
739
743
|
this.store.put(agent);
|
|
740
744
|
this.registerProject(agent);
|
|
741
745
|
this.changed(agent);
|
|
@@ -758,8 +762,14 @@ export class AgentManager extends EventEmitter {
|
|
|
758
762
|
const agent = this.store.get(this.store.resolve(ref)?.id ?? ref);
|
|
759
763
|
const issue = agent && leadingIssue(agent.intent);
|
|
760
764
|
if (!issue) return null;
|
|
761
|
-
const
|
|
765
|
+
const fields = await issueFields(issue, this.jiraOptions ?? {});
|
|
766
|
+
const summary = fields?.summary ?? null;
|
|
762
767
|
const cur = this.store.get(agent.id);
|
|
768
|
+
// Its components and labels may name modules to benchmark.
|
|
769
|
+
if (cur && fields) {
|
|
770
|
+
const mods = this.benchModules?.forIssue(cur, { components: fields.components, labels: fields.labels }) ?? [];
|
|
771
|
+
if (mods.length) this.addBenchModules(cur.id, mods);
|
|
772
|
+
}
|
|
763
773
|
if (!summary || !cur) return null;
|
|
764
774
|
const bug = cur.bugs?.[issue.key];
|
|
765
775
|
this.patch(cur.id, {
|
|
@@ -770,6 +780,40 @@ export class AgentManager extends EventEmitter {
|
|
|
770
780
|
return summary;
|
|
771
781
|
}
|
|
772
782
|
|
|
783
|
+
/** The Jira issue (or other tracker key) an agent works on, or null. */
|
|
784
|
+
issueKey(agent) {
|
|
785
|
+
return agent ? issueOf({ ...agent, bugs: Object.values(agent.bugs ?? {}) })?.key ?? null : null;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* More modules for an agent to benchmark ([{ path, dir, existing }], benchmarks.js). A running
|
|
790
|
+
* agent is told now; one not started yet gets them with its instructions. `asked`: it said it was
|
|
791
|
+
* done without them.
|
|
792
|
+
*/
|
|
793
|
+
addBenchModules(id, modules, { asked = false } = {}) {
|
|
794
|
+
const agent = this.store.get(id);
|
|
795
|
+
if (!agent) return null;
|
|
796
|
+
const have = new Set(agent.benchModules ?? []);
|
|
797
|
+
const fresh = modules.filter((m) => !have.has(m.path));
|
|
798
|
+
if (!fresh.length && !asked) return null;
|
|
799
|
+
this.patch(id, {
|
|
800
|
+
benchModules: [...have, ...fresh.map((m) => m.path)],
|
|
801
|
+
...(asked ? { benchAsked: [...new Set([...(agent.benchAsked ?? []), ...modules.map((m) => m.path)])] } : {}),
|
|
802
|
+
});
|
|
803
|
+
for (const m of modules) fs.mkdirSync(m.dir, { recursive: true });
|
|
804
|
+
const { md, json } = this.benchFiles(id);
|
|
805
|
+
if (asked) this.tell(id, askMessage(md, json, modules), { source: 'benchmarks' });
|
|
806
|
+
else if (this.runtimes.get(id)?.pty && fresh.length) this.tell(id, `This issue is about ${fresh.map((m) => m.path || 'the repository').join(', ')}, where speed matters. ${moduleBenchPrompt(md, json, fresh)}`, { source: 'benchmarks' });
|
|
807
|
+
return this.view(this.store.get(id));
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/** Where an agent writes its benchmark results: BENCHMARK.md and BENCH.json in its brief folder. */
|
|
811
|
+
benchFiles(id) {
|
|
812
|
+
fs.mkdirSync(briefDir(id), { recursive: true });
|
|
813
|
+
const dir = fs.realpathSync(briefDir(id));
|
|
814
|
+
return { md: path.join(dir, path.basename(benchPath(id))), json: path.join(dir, path.basename(resultsPath(id))) };
|
|
815
|
+
}
|
|
816
|
+
|
|
773
817
|
/** INTENT.md for a task agent: the request as given and where it came from (see brief.js). */
|
|
774
818
|
writeIntent(id) {
|
|
775
819
|
const agent = this.store.get(id);
|
|
@@ -807,7 +851,7 @@ export class AgentManager extends EventEmitter {
|
|
|
807
851
|
* The code map of a project (the one with the most going on, unless named). With `bugs`
|
|
808
852
|
* ({ findings, hunts } of the bug hunts), it also has the bugs layer (codemap.js bugHeat).
|
|
809
853
|
*/
|
|
810
|
-
async codeMap(projectKey, { bugs = null } = {}) {
|
|
854
|
+
async codeMap(projectKey, { bugs = null, speed = null } = {}) {
|
|
811
855
|
const withCode = this.store.list().filter((a) => a.workdir && !NO_REPO.has(a.kind) && fs.existsSync(a.workdir));
|
|
812
856
|
const groups = new Map();
|
|
813
857
|
for (const a of withCode) {
|
|
@@ -834,6 +878,8 @@ export class AgentManager extends EventEmitter {
|
|
|
834
878
|
return { id: a.id, name: a.name, busy: rt?.busy, attention: rt?.attention, changed: this.changeSets.get(a.id)?.files ?? {}, touched };
|
|
835
879
|
});
|
|
836
880
|
const out = { project: { key: g.key, name: g.name }, projects: list, map: buildMap({ files, agents }) };
|
|
881
|
+
// The Speed view: modules to benchmark and their issues' numbers (benchmarks.js).
|
|
882
|
+
if (speed) out.speed = speed.speed(g.key);
|
|
837
883
|
if (bugs) {
|
|
838
884
|
// Hunts and findings name the project by its shortcut.
|
|
839
885
|
const mine = (shortcut) => this.resolveProject(shortcut)?.key === g.key;
|
|
@@ -1253,7 +1299,16 @@ export class AgentManager extends EventEmitter {
|
|
|
1253
1299
|
const dir = fs.realpathSync(briefDir(agent.id));
|
|
1254
1300
|
writableDir ??= dir;
|
|
1255
1301
|
if (agent.demoPage) prompts.push(demoPagePrompt(path.join(dir, path.basename(demoPath(agent.id)))));
|
|
1256
|
-
if (agent.benchmarks) prompts.push(benchmarksPrompt(path.join(dir, path.basename(benchPath(agent.id))), path.join(dir, 'bench')));
|
|
1302
|
+
if (agent.benchmarks && !agent.benchModules?.length) prompts.push(benchmarksPrompt(path.join(dir, path.basename(benchPath(agent.id))), path.join(dir, 'bench')));
|
|
1303
|
+
}
|
|
1304
|
+
// Modules where speed matters: their kept benchmarks, run before and after (benchmarks.js).
|
|
1305
|
+
const benchMods = task && !planning && agent.benchModules?.length && this.benchModules ? this.benchModules.forAgent(agent) : [];
|
|
1306
|
+
if (benchMods.length) {
|
|
1307
|
+
const { md, json } = this.benchFiles(agent.id);
|
|
1308
|
+
writableDir ??= path.dirname(md);
|
|
1309
|
+
for (const m of benchMods) fs.mkdirSync(m.dir, { recursive: true });
|
|
1310
|
+
writableDir = [writableDir, ...benchMods.map((m) => fs.realpathSync(m.dir))].flat();
|
|
1311
|
+
prompts.push(moduleBenchPrompt(md, json, benchMods));
|
|
1257
1312
|
}
|
|
1258
1313
|
if (agent.reviewing && task) {
|
|
1259
1314
|
fs.mkdirSync(briefDir(agent.id), { recursive: true });
|
package/src/server.js
CHANGED
|
@@ -54,6 +54,7 @@ import { about, latestRelease } from './about.js';
|
|
|
54
54
|
import { Support } from './support.js';
|
|
55
55
|
import { ghBin, leadingJiraKey } from './tracker.js';
|
|
56
56
|
import { BugHunts } from './bughunt.js';
|
|
57
|
+
import { ModuleBenchmarks } from './benchmarks.js';
|
|
57
58
|
import * as git from './git.js';
|
|
58
59
|
|
|
59
60
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -140,6 +141,16 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
|
|
|
140
141
|
});
|
|
141
142
|
const hunts = new BugHunts({ manager, store, judge: manager.judge, git: huntGit, log: (m) => console.log(`[agentmgr] ${m}`) });
|
|
142
143
|
hunts.startTimer();
|
|
144
|
+
// Micro benchmarks of the modules where speed matters, for the Jira issues that change them.
|
|
145
|
+
const benches = new ModuleBenchmarks({
|
|
146
|
+
manager,
|
|
147
|
+
store,
|
|
148
|
+
changedFiles: async (a) => {
|
|
149
|
+
const base = await review.base(a);
|
|
150
|
+
return base ? Object.keys((await git.changes(a.workdir, base.sha))?.files ?? {}) : [];
|
|
151
|
+
},
|
|
152
|
+
log: (m) => console.log(`[agentmgr] ${m}`),
|
|
153
|
+
});
|
|
143
154
|
const races = new Races({ manager, store });
|
|
144
155
|
const review = new Review({ manager });
|
|
145
156
|
// The walkthrough explains the same diff the review screen shows.
|
|
@@ -859,7 +870,12 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
|
|
|
859
870
|
return stats(store.list(), { days, projectOf: (a) => manager.projectInfo(a)?.name ?? null });
|
|
860
871
|
}));
|
|
861
872
|
// ?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 })));
|
|
873
|
+
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, speed: req.query.layer === 'speed' ? benches : null })));
|
|
874
|
+
// Modules to benchmark, and what their benchmarks found (benchmarks.js).
|
|
875
|
+
api.post('/benchmodules', wrap((req) => benches.watch(req.body ?? {})));
|
|
876
|
+
api.delete('/benchmodules/:id', wrap((req) => benches.unwatch(req.params.id)));
|
|
877
|
+
api.post('/benchruns/:id/accept', wrap((req) => benches.accept(req.params.id, req.body?.accepted !== false)));
|
|
878
|
+
api.post('/benchruns/:id/fix', wrap((req) => benches.askToFix(req.params.id)));
|
|
863
879
|
// Issues agents work on, for the summary; ?group=you|agent|done and ?format=markdown to paste.
|
|
864
880
|
api.get('/issues', wrap(async (req) => {
|
|
865
881
|
// ?fresh=1 (the ↻ button) asks Jira again: the issues assigned to you and each issue's status.
|
|
@@ -976,7 +992,7 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
|
|
|
976
992
|
got('reviews', () => reviews.rows()),
|
|
977
993
|
]);
|
|
978
994
|
const findings = hunts.list().findings.filter((x) => x.status === 'open' || x.status === 'pr');
|
|
979
|
-
const items = todayItems({ inbox, issues, actions, reviews: prs, findings });
|
|
995
|
+
const items = todayItems({ inbox, issues, actions, reviews: prs, findings, slower: benches.slower() });
|
|
980
996
|
return { items, aside: todayAside({ issues, actions }), speech: todaySpeech(items), features: f, errors };
|
|
981
997
|
}));
|
|
982
998
|
// Support tickets: kept on this computer, each with a filled-in link to a new GitHub issue.
|
|
@@ -1419,6 +1435,7 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
|
|
|
1419
1435
|
value.close();
|
|
1420
1436
|
reviews.close();
|
|
1421
1437
|
hunts.close();
|
|
1438
|
+
benches.close();
|
|
1422
1439
|
autopilot.close();
|
|
1423
1440
|
goals.close();
|
|
1424
1441
|
worklog.close();
|
package/src/today.js
CHANGED
|
@@ -59,7 +59,7 @@ const INBOX = {
|
|
|
59
59
|
* The list: [{ id, kind, label, title, why, score, at, agentId?, url?, actionId?, issueKey?, reviewUrl? }],
|
|
60
60
|
* most pressing first. Each source may be missing (turned off, or it couldn't be had).
|
|
61
61
|
*/
|
|
62
|
-
export function todayItems({ inbox = [], issues = [], actions = [], reviews = [], findings = [], now = new Date() } = {}) {
|
|
62
|
+
export function todayItems({ inbox = [], issues = [], actions = [], reviews = [], findings = [], slower = [], now = new Date() } = {}) {
|
|
63
63
|
const items = [];
|
|
64
64
|
// The issue each agent works on: named on its questions, and not listed twice.
|
|
65
65
|
const issueOfAgent = new Map(issues.filter((r) => r.agent?.id).map((r) => [r.agent.id, r]));
|
|
@@ -120,6 +120,13 @@ export function todayItems({ inbox = [], issues = [], actions = [], reviews = []
|
|
|
120
120
|
const failed = f.auto?.state === 'failed' ? ` · the automatic fix didn't hold up: ${f.auto.reason}` : '';
|
|
121
121
|
items.push({ id: `bug:${f.id}`, kind: 'bug', label: 'Bug', title: f.title, why: `${f.severity === 'critical' ? 'Critical' : 'High'}: found by the ${f.hunt ?? 'bug'} hunt${f.file ? ` in ${f.file}${f.line ? `:${f.line}` : ''}` : ''}${f.evidence?.type === 'test' ? ' · a test fails' : ''}${failed}`, score: f.severity === 'critical' ? 28 : 38, at: f.at ?? null, findingId: f.id });
|
|
122
122
|
}
|
|
123
|
+
// An issue's change made a module slower in its micro benchmarks (benchmarks.js).
|
|
124
|
+
for (const r of slower) {
|
|
125
|
+
const worst = r.cases.filter((c) => c.change !== null).sort((a, b) => b.change - a.change)[0];
|
|
126
|
+
const title = `${r.issue ? `${r.issue}: ` : ''}${r.module || 'the repository'} is ${r.worst}% slower`;
|
|
127
|
+
const why = `Micro benchmarks${r.agent && r.agent !== r.issue ? ` by ${r.agent}` : ''}${worst ? `: ${worst.name} ${worst.before} → ${worst.after}${worst.unit ? ` ${worst.unit}` : ''}` : ''}${worst?.note ? ` · its note: ${worst.note}` : ''}`;
|
|
128
|
+
items.push({ id: `bench:${r.id}`, kind: 'bench', label: 'Slower', title, why, score: r.worst > 20 ? 27 : 36, at: r.at ?? null, agentId: r.agentId, runId: r.id, issueKey: r.issue ?? null });
|
|
129
|
+
}
|
|
123
130
|
return items.sort((x, y) => x.score - y.score || String(y.at ?? '').localeCompare(String(x.at ?? '')));
|
|
124
131
|
}
|
|
125
132
|
|