ai-agentmanager 1.30.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 +8 -0
- package/package.json +1 -1
- package/public/app.js +1 -1
- package/public/codemap.js +276 -3
- package/public/style.css +42 -0
- package/public/today.js +8 -0
- package/src/benchmarks.js +309 -0
- package/src/codemap.js +85 -0
- package/src/jira.js +7 -4
- package/src/manager.js +90 -7
- package/src/server.js +20 -2
- package/src/today.js +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
7
|
+
## 1.31.0 (2026-11-08)
|
|
8
|
+
|
|
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.
|
|
10
|
+
|
|
3
11
|
## 1.30.0 (2026-11-07)
|
|
4
12
|
|
|
5
13
|
- **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
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 and Speed views: { module } or { from, to }
|
|
62
69
|
try {
|
|
63
70
|
project = localStorage.getItem(SAVED) || null;
|
|
71
|
+
layer = ['bugs', 'speed'].includes(localStorage.getItem(LAYER)) ? localStorage.getItem(LAYER) : '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
|
-
|
|
79
|
+
const q = new URLSearchParams({ ...(project ? { project } : {}), ...(layer !== 'agents' ? { 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,17 @@ 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-
|
|
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'
|
|
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>'
|
|
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>'}
|
|
96
110
|
<span class="spacer"></span>
|
|
97
111
|
<button class="small" data-map="refresh" title="Look again now (it refreshes every few seconds)">↻</button>
|
|
98
112
|
<button class="small" data-map="close" title="Back (Esc)">Close</button>`;
|
|
113
|
+
if (layer === 'bugs') return drawBugs();
|
|
114
|
+
if (layer === 'speed') return drawSpeed();
|
|
99
115
|
const warn = (m?.links ?? []).filter((l) => l.kind !== 'near');
|
|
100
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>' : '';
|
|
101
117
|
const box = $('#map-box');
|
|
@@ -165,6 +181,227 @@ export function initCodeMap({ api, $, esc, agents, openAgent, toast }) {
|
|
|
165
181
|
svg.innerHTML = lines.join('');
|
|
166
182
|
}
|
|
167
183
|
|
|
184
|
+
const finding = (id) => data?.heat?.findings.find((f) => f.id === id);
|
|
185
|
+
|
|
186
|
+
/** The Bugs view: folders by heat, arrows along bugs' paths, cold spots hatched. */
|
|
187
|
+
function drawBugs() {
|
|
188
|
+
const m = data?.map;
|
|
189
|
+
const heat = data?.heat;
|
|
190
|
+
const box = $('#map-box');
|
|
191
|
+
$('#map-agents').innerHTML = '';
|
|
192
|
+
if (!m || !heat || !m.modules.length) {
|
|
193
|
+
box.innerHTML = `<p class="hint map-empty">${data?.project ? 'No files to show for this project yet.' : 'No projects with a repository yet.'}</p>`;
|
|
194
|
+
$('#map-warn').innerHTML = '';
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const of = (key) => heat.modules[key] ?? { score: 0, bugs: {}, churn: 0, covered: false, files: [], findings: [] };
|
|
198
|
+
// Hot folders get more room, so their names and counts show.
|
|
199
|
+
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);
|
|
200
|
+
const W = box.clientWidth;
|
|
201
|
+
const H = Math.max(320, view.clientHeight - box.offsetTop - 24);
|
|
202
|
+
box.style.height = `${H}px`;
|
|
203
|
+
const big = items.slice(0, 100);
|
|
204
|
+
const rest = items.slice(100);
|
|
205
|
+
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 });
|
|
206
|
+
const rects = squarify(big, 0, 0, W, H);
|
|
207
|
+
const at = new Map(rects.map((r) => [r.item.key, r]));
|
|
208
|
+
const tiles = rects
|
|
209
|
+
.map(({ x, y, w, h, item }) => {
|
|
210
|
+
const t = of(item.key);
|
|
211
|
+
const n = Object.values(t.bugs).reduce((a, b) => a + b, 0);
|
|
212
|
+
const r = heat.max ? t.score / heat.max : 0;
|
|
213
|
+
const worst = ['critical', 'high', 'medium', 'low'].find((k) => t.bugs[k]);
|
|
214
|
+
const cold = heat.hunted && !t.covered && !item.more;
|
|
215
|
+
const sel = picked?.module === item.key || picked?.from === item.key || picked?.to === item.key;
|
|
216
|
+
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' : ''}`;
|
|
217
|
+
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)}">
|
|
218
|
+
${w > 46 && h > 22 ? `<span class="map-name">${esc(item.key === '.' ? '(top level)' : item.key)}</span>` : ''}
|
|
219
|
+
${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>` : ''}
|
|
220
|
+
</div>`;
|
|
221
|
+
})
|
|
222
|
+
.join('');
|
|
223
|
+
// Arrows from the middle of one folder to the next, thicker the more (and worse) bugs go that way.
|
|
224
|
+
const maxW = Math.max(1, ...heat.paths.map((p) => p.weight));
|
|
225
|
+
const mid = (r) => [r.x + r.w / 2, r.y + r.h / 2];
|
|
226
|
+
const arrows = heat.paths
|
|
227
|
+
.map((p, i) => {
|
|
228
|
+
const a = at.get(p.from);
|
|
229
|
+
const b = at.get(p.to);
|
|
230
|
+
if (!a || !b || a === b) return '';
|
|
231
|
+
const [x1, y1] = mid(a);
|
|
232
|
+
const [x2, y2] = mid(b);
|
|
233
|
+
// A slight curve, so arrows both ways between two folders don't overlap.
|
|
234
|
+
const cx = (x1 + x2) / 2 - (y2 - y1) * 0.15;
|
|
235
|
+
const cy = (y1 + y2) / 2 + (x2 - x1) * 0.15;
|
|
236
|
+
const sel = picked?.from === p.from && picked?.to === p.to;
|
|
237
|
+
const sw = 1.5 + (4.5 * p.weight) / maxW;
|
|
238
|
+
// Each arrow its own head, sized to its width.
|
|
239
|
+
const head = Math.max(10, Math.min(20, sw * 3)).toFixed(1);
|
|
240
|
+
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>`;
|
|
241
|
+
})
|
|
242
|
+
.join('');
|
|
243
|
+
box.innerHTML = `${tiles}<svg class="map-links bug-paths" width="${W}" height="${H}">${arrows}</svg>`;
|
|
244
|
+
$('#map-warn').innerHTML = bugPanel(of);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function bugRow(f) {
|
|
248
|
+
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>
|
|
249
|
+
${f.status === 'open' ? '<button class="small" data-map-bug="fix" title="Start an agent on it">Fix</button>' : ''}
|
|
250
|
+
${f.prUrl ? `<a class="small-link" href="${esc(f.prUrl)}" target="_blank" rel="noopener">PR ↗</a>` : ''}
|
|
251
|
+
<button class="small" data-map-bug="evidence" title="See it in Bugs">Evidence</button></li>`;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Under the map: the picked folder's or path's bugs, else the hottest folders. */
|
|
255
|
+
function bugPanel(of) {
|
|
256
|
+
const heat = data.heat;
|
|
257
|
+
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>` : '';
|
|
258
|
+
if (picked?.module !== undefined) {
|
|
259
|
+
const t = of(picked.module);
|
|
260
|
+
const list = t.findings.map(finding).filter(Boolean);
|
|
261
|
+
const name = picked.module === '.' ? '(top level)' : picked.module;
|
|
262
|
+
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>
|
|
263
|
+
${list.length ? `<ul class="map-bug-list">${list.map(bugRow).join('')}</ul>` : ''}</div>`;
|
|
264
|
+
}
|
|
265
|
+
if (picked?.from !== undefined) {
|
|
266
|
+
const p = heat.paths.find((x) => x.from === picked.from && x.to === picked.to);
|
|
267
|
+
const list = (p?.findings ?? []).map(finding).filter(Boolean);
|
|
268
|
+
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>
|
|
269
|
+
<ul class="map-bug-list">${list.map(bugRow).join('')}</ul></div>`;
|
|
270
|
+
}
|
|
271
|
+
const hot = Object.entries(heat.modules).filter(([, t]) => t.findings.length).sort((a, b) => b[1].score - a[1].score).slice(0, 5);
|
|
272
|
+
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>';
|
|
273
|
+
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>`;
|
|
274
|
+
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>`;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async function bugAct(id, what) {
|
|
278
|
+
if (what === 'evidence') {
|
|
279
|
+
show(false);
|
|
280
|
+
return openBugs?.();
|
|
281
|
+
}
|
|
282
|
+
if (what === 'fix') {
|
|
283
|
+
try {
|
|
284
|
+
const r = await api('POST', `/findings/${id}/fix`, {});
|
|
285
|
+
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)) });
|
|
286
|
+
} catch (e) {
|
|
287
|
+
toast?.(e.message, 6000);
|
|
288
|
+
}
|
|
289
|
+
load();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Hunt the picked folder: its hunt if there is one, else a new whole-module hunt; then run it. */
|
|
294
|
+
async function huntHere() {
|
|
295
|
+
const folder = picked?.module === '.' ? '' : picked?.module ?? '';
|
|
296
|
+
try {
|
|
297
|
+
const { hunts } = await api('GET', '/hunts');
|
|
298
|
+
let h = hunts.find((x) => x.project === data.project.shortcut && x.path === folder);
|
|
299
|
+
h ??= await api('POST', '/hunts', { project: data.project.shortcut, path: folder, focus: 'module' });
|
|
300
|
+
const r = await api('POST', `/hunts/${h.id}/run`, {});
|
|
301
|
+
toast?.(`${r.agent.name} is hunting in ${folder || 'the whole project'}. Its findings come in when it's done.`, 5000);
|
|
302
|
+
} catch (e) {
|
|
303
|
+
toast?.(e.message, 6000);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
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
|
+
|
|
168
405
|
function show(on) {
|
|
169
406
|
open = on;
|
|
170
407
|
view.hidden = !on;
|
|
@@ -179,6 +416,35 @@ export function initCodeMap({ api, $, esc, agents, openAgent, toast }) {
|
|
|
179
416
|
}
|
|
180
417
|
|
|
181
418
|
view.addEventListener('click', (e) => {
|
|
419
|
+
const lay = e.target.closest('[data-map-layer]');
|
|
420
|
+
if (lay) {
|
|
421
|
+
layer = lay.dataset.mapLayer;
|
|
422
|
+
picked = null;
|
|
423
|
+
try {
|
|
424
|
+
localStorage.setItem(LAYER, layer);
|
|
425
|
+
} catch {}
|
|
426
|
+
return load();
|
|
427
|
+
}
|
|
428
|
+
if (layer === 'bugs') {
|
|
429
|
+
const ba = e.target.closest('[data-map-bug]');
|
|
430
|
+
if (ba) return bugAct(ba.closest('[data-map-finding]')?.dataset.mapFinding, ba.dataset.mapBug);
|
|
431
|
+
if (e.target.closest('[data-map-hunt]')) return huntHere();
|
|
432
|
+
if (e.target.closest('[data-map-unpick]')) return (picked = null), draw();
|
|
433
|
+
const path = e.target.closest('[data-map-path]');
|
|
434
|
+
if (path) {
|
|
435
|
+
const p = data.heat.paths[Number(path.dataset.mapPath)];
|
|
436
|
+
return (picked = p ? { from: p.from, to: p.to } : null), draw();
|
|
437
|
+
}
|
|
438
|
+
const mod = e.target.closest('[data-map-mod]');
|
|
439
|
+
if (mod?.dataset.mapMod) return (picked = picked?.module === mod.dataset.mapMod ? null : { module: mod.dataset.mapMod }), draw();
|
|
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
|
+
}
|
|
182
448
|
const o = e.target.closest('[data-map-open]');
|
|
183
449
|
if (o) {
|
|
184
450
|
show(false);
|
|
@@ -188,9 +454,16 @@ export function initCodeMap({ api, $, esc, agents, openAgent, toast }) {
|
|
|
188
454
|
if (b?.dataset.map === 'close') return show(false);
|
|
189
455
|
if (b?.dataset.map === 'refresh') return load();
|
|
190
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
|
+
});
|
|
191
463
|
view.addEventListener('change', (e) => {
|
|
192
464
|
if (e.target.dataset.mapSet !== 'project') return;
|
|
193
465
|
project = e.target.value;
|
|
466
|
+
picked = null;
|
|
194
467
|
try {
|
|
195
468
|
localStorage.setItem(SAVED, project);
|
|
196
469
|
} catch {}
|
package/public/style.css
CHANGED
|
@@ -1126,6 +1126,48 @@ 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; }
|
|
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; }
|
|
1129
1171
|
|
|
1130
1172
|
/* ---------- Jira: issues agents work on */
|
|
1131
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/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/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
|
@@ -105,10 +105,11 @@ 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
|
-
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);
|
|
@@ -803,7 +847,11 @@ export class AgentManager extends EventEmitter {
|
|
|
803
847
|
* The codebase map of one project (its key, else the one with the most running agents): its
|
|
804
848
|
* folders, and where each of its agents is changing and reading code now (codemap.js).
|
|
805
849
|
*/
|
|
806
|
-
|
|
850
|
+
/**
|
|
851
|
+
* The code map of a project (the one with the most going on, unless named). With `bugs`
|
|
852
|
+
* ({ findings, hunts } of the bug hunts), it also has the bugs layer (codemap.js bugHeat).
|
|
853
|
+
*/
|
|
854
|
+
async codeMap(projectKey, { bugs = null, speed = null } = {}) {
|
|
807
855
|
const withCode = this.store.list().filter((a) => a.workdir && !NO_REPO.has(a.kind) && fs.existsSync(a.workdir));
|
|
808
856
|
const groups = new Map();
|
|
809
857
|
for (const a of withCode) {
|
|
@@ -829,7 +877,22 @@ export class AgentManager extends EventEmitter {
|
|
|
829
877
|
} catch {}
|
|
830
878
|
return { id: a.id, name: a.name, busy: rt?.busy, attention: rt?.attention, changed: this.changeSets.get(a.id)?.files ?? {}, touched };
|
|
831
879
|
});
|
|
832
|
-
|
|
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);
|
|
883
|
+
if (bugs) {
|
|
884
|
+
// Hunts and findings name the project by its shortcut.
|
|
885
|
+
const mine = (shortcut) => this.resolveProject(shortcut)?.key === g.key;
|
|
886
|
+
const hunts = (bugs.hunts ?? []).filter((h) => mine(h.project));
|
|
887
|
+
out.project.shortcut = Object.values(this.store.data.projects ?? {}).find((p) => p.key === g.key)?.shortcut ?? null;
|
|
888
|
+
out.heat = bugHeat({
|
|
889
|
+
files,
|
|
890
|
+
findings: (bugs.findings ?? []).filter((f) => mine(f.project)),
|
|
891
|
+
churn: await this.churn(root),
|
|
892
|
+
hunts: hunts.map((h) => ({ path: h.path, focus: h.focus, covered: h.covered ?? [], ran: (h.runs ?? []).some((r) => r.status === 'done') })),
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
return out;
|
|
833
896
|
}
|
|
834
897
|
|
|
835
898
|
/**
|
|
@@ -887,6 +950,17 @@ export class AgentManager extends EventEmitter {
|
|
|
887
950
|
}
|
|
888
951
|
|
|
889
952
|
/** A repository's tracked files, for the map (kept a few minutes). */
|
|
953
|
+
/** The commits of the last 30 days, each as the files it changed (kept ten minutes). */
|
|
954
|
+
async churn(dir) {
|
|
955
|
+
this.churns ??= new Map();
|
|
956
|
+
const hit = this.churns.get(dir);
|
|
957
|
+
if (hit && Date.now() - hit.at < 10 * 60_000) return hit.commits;
|
|
958
|
+
const out = await git.run('git', ['log', '--since=30.days', '--name-only', '--format=%x01', '--no-renames', '-n', '2000'], { cwd: dir, timeout: 30_000 }).catch(() => '');
|
|
959
|
+
const commits = out.split('\x01').map((c) => c.split('\n').filter(Boolean)).filter((c) => c.length);
|
|
960
|
+
this.churns.set(dir, { at: Date.now(), commits });
|
|
961
|
+
return commits;
|
|
962
|
+
}
|
|
963
|
+
|
|
890
964
|
async repoFiles(dir) {
|
|
891
965
|
this.fileLists ??= new Map();
|
|
892
966
|
const hit = this.fileLists.get(dir);
|
|
@@ -1225,7 +1299,16 @@ export class AgentManager extends EventEmitter {
|
|
|
1225
1299
|
const dir = fs.realpathSync(briefDir(agent.id));
|
|
1226
1300
|
writableDir ??= dir;
|
|
1227
1301
|
if (agent.demoPage) prompts.push(demoPagePrompt(path.join(dir, path.basename(demoPath(agent.id)))));
|
|
1228
|
-
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));
|
|
1229
1312
|
}
|
|
1230
1313
|
if (agent.reviewing && task) {
|
|
1231
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.
|
|
@@ -858,7 +869,13 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
|
|
|
858
869
|
const days = req.query.days === undefined ? 30 : Math.max(0, Math.min(3650, Math.floor(Number(req.query.days)) || 0));
|
|
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.
|
|
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)));
|
|
862
879
|
// Issues agents work on, for the summary; ?group=you|agent|done and ?format=markdown to paste.
|
|
863
880
|
api.get('/issues', wrap(async (req) => {
|
|
864
881
|
// ?fresh=1 (the ↻ button) asks Jira again: the issues assigned to you and each issue's status.
|
|
@@ -975,7 +992,7 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
|
|
|
975
992
|
got('reviews', () => reviews.rows()),
|
|
976
993
|
]);
|
|
977
994
|
const findings = hunts.list().findings.filter((x) => x.status === 'open' || x.status === 'pr');
|
|
978
|
-
const items = todayItems({ inbox, issues, actions, reviews: prs, findings });
|
|
995
|
+
const items = todayItems({ inbox, issues, actions, reviews: prs, findings, slower: benches.slower() });
|
|
979
996
|
return { items, aside: todayAside({ issues, actions }), speech: todaySpeech(items), features: f, errors };
|
|
980
997
|
}));
|
|
981
998
|
// Support tickets: kept on this computer, each with a filled-in link to a new GitHub issue.
|
|
@@ -1418,6 +1435,7 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
|
|
|
1418
1435
|
value.close();
|
|
1419
1436
|
reviews.close();
|
|
1420
1437
|
hunts.close();
|
|
1438
|
+
benches.close();
|
|
1421
1439
|
autopilot.close();
|
|
1422
1440
|
goals.close();
|
|
1423
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
|
|