ai-agentmanager 1.19.0 → 1.21.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 +13 -0
- package/README.md +13 -3
- package/package.json +1 -1
- package/public/app.js +130 -7
- package/public/codemap.js +209 -0
- package/public/index.html +27 -0
- package/public/keys.js +93 -0
- package/public/land.js +9 -2
- package/public/speak.js +4 -2
- package/public/standup.js +348 -0
- package/public/style.css +96 -0
- package/public/voice.js +16 -0
- package/public/watch.js +254 -0
- package/src/backlog.js +7 -3
- package/src/brief.js +31 -3
- package/src/cli.js +7 -2
- package/src/codemap.js +115 -0
- package/src/config.js +6 -0
- package/src/drive.js +1 -0
- package/src/landing.js +88 -9
- package/src/livebrowser.js +5 -2
- package/src/manager.js +81 -1
- package/src/notify.js +1 -0
- package/src/server.js +41 -2
- package/src/standup.js +209 -0
- package/src/tracker.js +57 -0
package/public/watch.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// Watch: several agents' live sessions side by side on one page, so they can be followed without
|
|
2
|
+
// clicking from one to the next. Each tile shows its session at the session's own size, with the
|
|
3
|
+
// font scaled to fit the tile; tiles never resize a session. Click a tile to type into it.
|
|
4
|
+
|
|
5
|
+
const SAVED = 'agentmgr.watch';
|
|
6
|
+
const MAX_TILES = 12;
|
|
7
|
+
// What a terminal answers to the program's queries (cursor position, colors, focus): never typing.
|
|
8
|
+
const REPLY = /^(\x1b\[[\d;?>]*[IOcRnt]|\x1b\][\d;]*[^\x07\x1b]*(\x07|\x1b\\))+$/;
|
|
9
|
+
const SHOW = [
|
|
10
|
+
['running', 'Running agents'],
|
|
11
|
+
['attention', 'Waiting on you'],
|
|
12
|
+
['working', 'Working now'],
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export function initWatch({ agents, $, esc, Terminal, openStream, statusOf, pillText, projectKey, projectLabel, openAgent }) {
|
|
16
|
+
const view = $('#watch-view');
|
|
17
|
+
const grid = $('#watch-grid');
|
|
18
|
+
const tiles = new Map(); // agent id -> { el, xterm, conn, cols, rows, replaying }
|
|
19
|
+
let open = false;
|
|
20
|
+
let prefs = { show: 'running', project: '', hidden: [], cols: 0 };
|
|
21
|
+
try {
|
|
22
|
+
prefs = { ...prefs, ...JSON.parse(localStorage.getItem(SAVED) ?? '{}') };
|
|
23
|
+
} catch {}
|
|
24
|
+
const save = () => {
|
|
25
|
+
try {
|
|
26
|
+
localStorage.setItem(SAVED, JSON.stringify(prefs));
|
|
27
|
+
} catch {}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** The agents to show, in a fixed order (oldest first) so tiles don't jump about as they work. */
|
|
31
|
+
function wanted() {
|
|
32
|
+
const all = [...agents.values()].filter((a) => a.runtime?.running);
|
|
33
|
+
const shown = all
|
|
34
|
+
.filter((a) => !prefs.project || projectKey(a) === prefs.project)
|
|
35
|
+
.filter((a) => (prefs.show === 'attention' ? a.runtime.attention : prefs.show === 'working' ? a.runtime.busy || a.runtime.attention : true))
|
|
36
|
+
.filter((a) => !prefs.hidden.includes(a.id));
|
|
37
|
+
shown.sort((x, y) => String(x.createdAt ?? '').localeCompare(String(y.createdAt ?? '')) || x.id.localeCompare(y.id));
|
|
38
|
+
return { all, shown: shown.slice(0, MAX_TILES), more: Math.max(0, shown.length - MAX_TILES) };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Line height in xterm is about 1.2 of the font size; monospace glyphs about 0.6 of it wide.
|
|
42
|
+
const LINE = 1.2;
|
|
43
|
+
const GLYPH = 0.6;
|
|
44
|
+
const MIN_FONT = 7;
|
|
45
|
+
const HEAD = 30;
|
|
46
|
+
const GAP = 10;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Fit: as many columns as gives the biggest text with every tile on screen; each tile is then as
|
|
50
|
+
* tall as a screen row. With a fixed number per row, tiles are as tall as their sessions.
|
|
51
|
+
*/
|
|
52
|
+
function layout() {
|
|
53
|
+
const fit = !Number(prefs.cols);
|
|
54
|
+
grid.classList.toggle('fit', fit);
|
|
55
|
+
if (!fit) {
|
|
56
|
+
grid.style.gridTemplateColumns = `repeat(${Number(prefs.cols)}, minmax(0, 1fr))`;
|
|
57
|
+
grid.style.removeProperty('--watch-term-h');
|
|
58
|
+
} else {
|
|
59
|
+
const n = Math.max(1, tiles.size);
|
|
60
|
+
const W = grid.clientWidth;
|
|
61
|
+
const H = view.clientHeight - (grid.getBoundingClientRect().top - view.getBoundingClientRect().top) - 16;
|
|
62
|
+
const cols = Math.max(80, ...[...tiles.values()].map((t) => t.cols || 120));
|
|
63
|
+
const rows = Math.max(20, ...[...tiles.values()].map((t) => t.rows || 34));
|
|
64
|
+
let best = { c: 1, font: 0, h: 0 };
|
|
65
|
+
for (let c = 1; c <= Math.min(4, n); c++) {
|
|
66
|
+
const r = Math.ceil(n / c);
|
|
67
|
+
const w = (W - GAP * (c - 1)) / c - 8;
|
|
68
|
+
const h = Math.max(140, (H - GAP * (r - 1)) / r - HEAD);
|
|
69
|
+
const font = Math.min(w / (cols * GLYPH), h / (rows * LINE));
|
|
70
|
+
if (font > best.font) best = { c, font, h };
|
|
71
|
+
}
|
|
72
|
+
grid.style.gridTemplateColumns = `repeat(${best.c}, minmax(0, 1fr))`;
|
|
73
|
+
grid.style.setProperty('--watch-term-h', `${Math.floor(best.h)}px`);
|
|
74
|
+
}
|
|
75
|
+
tiles.forEach(fitFont);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The font that fits the session in its tile; when it can't, the newest lines stay in view. */
|
|
79
|
+
function fitFont(t) {
|
|
80
|
+
const box = t.el.querySelector('.watch-term');
|
|
81
|
+
const w = box.clientWidth - 8;
|
|
82
|
+
if (!(w > 0) || !t.cols) return;
|
|
83
|
+
let size = w / (t.cols * GLYPH);
|
|
84
|
+
if (grid.classList.contains('fit')) size = Math.min(size, (box.clientHeight - 8) / (t.rows * LINE));
|
|
85
|
+
size = Math.max(Number(prefs.cols) ? 5 : MIN_FONT, Math.min(13, Math.floor(size * 10) / 10));
|
|
86
|
+
if (t.xterm.options.fontSize !== size) t.xterm.options.fontSize = size;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function addTile(a) {
|
|
90
|
+
const el = document.createElement('div');
|
|
91
|
+
el.className = 'watch-tile';
|
|
92
|
+
el.dataset.agent = a.id;
|
|
93
|
+
el.innerHTML = `<div class="watch-head">
|
|
94
|
+
<button class="link watch-name" data-watch="open" title="Open this agent"></button>
|
|
95
|
+
<span class="pill watch-pill"></span>
|
|
96
|
+
<span class="hint watch-what"></span>
|
|
97
|
+
<span class="spacer"></span>
|
|
98
|
+
<button class="link watch-x" data-watch="hide" title="Stop watching this agent (Show all brings it back)">×</button>
|
|
99
|
+
</div>
|
|
100
|
+
<div class="watch-term" title="Click to type into this agent's session"></div>`;
|
|
101
|
+
const xterm = new Terminal({
|
|
102
|
+
cursorBlink: false,
|
|
103
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
|
|
104
|
+
fontSize: 9,
|
|
105
|
+
scrollback: 2000,
|
|
106
|
+
theme: { background: '#0f1117' },
|
|
107
|
+
allowProposedApi: true,
|
|
108
|
+
});
|
|
109
|
+
const t = { el, xterm, conn: null, cols: 0, rows: 0, replaying: false };
|
|
110
|
+
xterm.open(el.querySelector('.watch-term'));
|
|
111
|
+
// Only your typing goes to the agent: the session's own terminal already answers its queries.
|
|
112
|
+
xterm.onData((d) => {
|
|
113
|
+
if (t.replaying || REPLY.test(d) || !el.contains(document.activeElement)) return;
|
|
114
|
+
t.conn?.send({ t: 'i', d });
|
|
115
|
+
});
|
|
116
|
+
const size = (cols, rows) => {
|
|
117
|
+
if (!(cols > 0 && rows > 0)) return;
|
|
118
|
+
t.cols = cols;
|
|
119
|
+
t.rows = rows;
|
|
120
|
+
if (xterm.cols !== cols || xterm.rows !== rows) xterm.resize(cols, rows);
|
|
121
|
+
layout();
|
|
122
|
+
};
|
|
123
|
+
t.conn = openStream(
|
|
124
|
+
{ agentId: a.id, kind: 'claude' },
|
|
125
|
+
{
|
|
126
|
+
onMessage: (msg) => {
|
|
127
|
+
if (msg.t === 'o') return xterm.write(msg.d);
|
|
128
|
+
if (msg.t === 'hello') {
|
|
129
|
+
xterm.reset();
|
|
130
|
+
size(msg.cols, msg.rows);
|
|
131
|
+
t.replaying = true;
|
|
132
|
+
xterm.write(msg.backlog ?? '', () => (t.replaying = false));
|
|
133
|
+
} else if (msg.t === 'size') size(msg.cols, msg.rows);
|
|
134
|
+
else if (msg.t === 'exit') xterm.write(`\r\n\x1b[2m[session ended with code ${msg.code}]\x1b[0m\r\n`);
|
|
135
|
+
},
|
|
136
|
+
onClose: () => (t.conn = null),
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
tiles.set(a.id, t);
|
|
140
|
+
return t;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function dropTile(id) {
|
|
144
|
+
const t = tiles.get(id);
|
|
145
|
+
if (!t) return;
|
|
146
|
+
t.conn?.close();
|
|
147
|
+
t.xterm.dispose();
|
|
148
|
+
t.el.remove();
|
|
149
|
+
tiles.delete(id);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function renderBar(all, shown, more) {
|
|
153
|
+
const projects = new Map();
|
|
154
|
+
for (const a of all) projects.set(projectKey(a), projectLabel(a));
|
|
155
|
+
if (prefs.project && !projects.has(prefs.project)) projects.set(prefs.project, prefs.project);
|
|
156
|
+
const hidden = prefs.hidden.filter((id) => agents.get(id)?.runtime?.running).length;
|
|
157
|
+
const waiting = shown.filter((a) => a.runtime.attention).length;
|
|
158
|
+
$('#watch-bar').innerHTML = `
|
|
159
|
+
<b>Watching ${shown.length} of ${all.length} running</b>
|
|
160
|
+
${waiting ? `<span class="pill attention">${waiting} waiting on you</span>` : ''}
|
|
161
|
+
<select data-watch-set="show" aria-label="Which agents">${SHOW.map(([k, l]) => `<option value="${k}" ${k === prefs.show ? 'selected' : ''}>${l}</option>`).join('')}</select>
|
|
162
|
+
${projects.size > 1 || prefs.project ? `<select data-watch-set="project" aria-label="Project"><option value="">All projects</option>${[...projects].map(([k, l]) => `<option value="${esc(k)}" ${k === prefs.project ? 'selected' : ''}>${esc(l)}</option>`).join('')}</select>` : ''}
|
|
163
|
+
<select data-watch-set="cols" aria-label="Tiles per row" title="Tiles per row">${[[0, 'Fit'], [1, '1 per row'], [2, '2 per row'], [3, '3 per row'], [4, '4 per row']].map(([k, l]) => `<option value="${k}" ${k === Number(prefs.cols) ? 'selected' : ''}>${l}</option>`).join('')}</select>
|
|
164
|
+
${hidden ? `<button class="link" data-watch="unhide">Show all (${hidden} hidden)</button>` : ''}
|
|
165
|
+
${more ? `<span class="hint">${more} more not shown (at most ${MAX_TILES})</span>` : ''}
|
|
166
|
+
<span class="spacer"></span>
|
|
167
|
+
<button class="small" data-watch="close" title="Back to the agents (Esc)">Close</button>`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function render() {
|
|
171
|
+
if (!open) return;
|
|
172
|
+
const { all, shown, more } = wanted();
|
|
173
|
+
renderBar(all, shown, more);
|
|
174
|
+
const ids = new Set(shown.map((a) => a.id));
|
|
175
|
+
for (const id of [...tiles.keys()]) if (!ids.has(id)) dropTile(id);
|
|
176
|
+
shown.forEach((a, i) => {
|
|
177
|
+
const t = tiles.get(a.id) ?? addTile(a);
|
|
178
|
+
// Keep the order without moving tiles that are already in place (a move would redraw them).
|
|
179
|
+
if (grid.children[i] !== t.el) grid.insertBefore(t.el, grid.children[i] ?? null);
|
|
180
|
+
const st = statusOf(a);
|
|
181
|
+
t.el.classList.toggle('attention', st === 'attention');
|
|
182
|
+
t.el.classList.toggle('working', st === 'working');
|
|
183
|
+
const name = t.el.querySelector('.watch-name');
|
|
184
|
+
if (name.textContent !== a.name) name.textContent = a.name;
|
|
185
|
+
const pill = t.el.querySelector('.watch-pill');
|
|
186
|
+
pill.className = `pill watch-pill ${st}`;
|
|
187
|
+
pill.textContent = pillText(st);
|
|
188
|
+
const what = a.runtime.attention || a.progress?.summary || a.synopsis?.text || '';
|
|
189
|
+
const whatEl = t.el.querySelector('.watch-what');
|
|
190
|
+
if (whatEl.textContent !== what) {
|
|
191
|
+
whatEl.textContent = what;
|
|
192
|
+
whatEl.title = what;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
layout();
|
|
196
|
+
$('#watch-empty').hidden = shown.length > 0;
|
|
197
|
+
$('#watch-empty').textContent = all.length
|
|
198
|
+
? 'No running agent matches. Pick another filter above.'
|
|
199
|
+
: 'No agents are running. Their sessions show up here, side by side, as soon as they start.';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function show(on) {
|
|
203
|
+
open = on;
|
|
204
|
+
view.hidden = !on;
|
|
205
|
+
document.body.classList.toggle('watching', on);
|
|
206
|
+
$('#watch-btn')?.classList.toggle('active', on);
|
|
207
|
+
if (on) {
|
|
208
|
+
history.replaceState(null, '', '#watch');
|
|
209
|
+
render();
|
|
210
|
+
} else {
|
|
211
|
+
for (const id of [...tiles.keys()]) dropTile(id);
|
|
212
|
+
if (location.hash === '#watch') history.replaceState(null, '', '#');
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
view.addEventListener('click', (e) => {
|
|
217
|
+
const btn = e.target.closest('[data-watch]');
|
|
218
|
+
if (!btn) return;
|
|
219
|
+
const id = btn.closest('.watch-tile')?.dataset.agent;
|
|
220
|
+
const what = btn.dataset.watch;
|
|
221
|
+
if (what === 'close') show(false);
|
|
222
|
+
else if (what === 'open' && id) {
|
|
223
|
+
show(false);
|
|
224
|
+
openAgent(id);
|
|
225
|
+
} else if (what === 'hide' && id) {
|
|
226
|
+
prefs.hidden = [...new Set([...prefs.hidden, id])];
|
|
227
|
+
save();
|
|
228
|
+
render();
|
|
229
|
+
} else if (what === 'unhide') {
|
|
230
|
+
prefs.hidden = [];
|
|
231
|
+
save();
|
|
232
|
+
render();
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
view.addEventListener('change', (e) => {
|
|
236
|
+
const key = e.target.dataset.watchSet;
|
|
237
|
+
if (!key) return;
|
|
238
|
+
prefs[key] = key === 'cols' ? Number(e.target.value) : e.target.value;
|
|
239
|
+
save();
|
|
240
|
+
render();
|
|
241
|
+
requestAnimationFrame(layout);
|
|
242
|
+
});
|
|
243
|
+
document.addEventListener('keydown', (e) => {
|
|
244
|
+
// Esc closes the page, unless you're typing into a session (Esc belongs to it then).
|
|
245
|
+
if (open && e.key === 'Escape' && !e.target.closest?.('.watch-term')) show(false);
|
|
246
|
+
});
|
|
247
|
+
let fitTimer = null;
|
|
248
|
+
new ResizeObserver(() => {
|
|
249
|
+
clearTimeout(fitTimer);
|
|
250
|
+
fitTimer = setTimeout(layout, 60);
|
|
251
|
+
}).observe(view);
|
|
252
|
+
|
|
253
|
+
return { show, render, isOpen: () => open };
|
|
254
|
+
}
|
package/src/backlog.js
CHANGED
|
@@ -104,7 +104,7 @@ export class Backlog extends EventEmitter {
|
|
|
104
104
|
// ------------------------------------------------------------ editing
|
|
105
105
|
|
|
106
106
|
/** Queue one item per title. Options are what an agent would take (repo, dir, base, project, ...). */
|
|
107
|
-
add(titles, { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, designDoc, engine, attachments, isolation, priority = 2 } = {}) {
|
|
107
|
+
add(titles, { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, designDoc, demoPage, benchmarks, engine, attachments, isolation, priority = 2 } = {}) {
|
|
108
108
|
const list = titles.map((t) => String(t ?? '').trim()).filter(Boolean);
|
|
109
109
|
if (!list.length) throw err(400, 'At least one item is required');
|
|
110
110
|
const pr = parsePriority(priority);
|
|
@@ -142,6 +142,8 @@ export class Backlog extends EventEmitter {
|
|
|
142
142
|
plan: Boolean(plan),
|
|
143
143
|
planReview: planReview ?? null,
|
|
144
144
|
designDoc: designDoc ?? null,
|
|
145
|
+
demoPage: demoPage ?? null,
|
|
146
|
+
benchmarks: benchmarks ?? null,
|
|
145
147
|
priority: pr,
|
|
146
148
|
order: order + i,
|
|
147
149
|
status: 'queued',
|
|
@@ -253,6 +255,8 @@ export class Backlog extends EventEmitter {
|
|
|
253
255
|
plan: it.plan,
|
|
254
256
|
planReview: it.planReview ?? undefined,
|
|
255
257
|
designDoc: it.designDoc ?? undefined,
|
|
258
|
+
demoPage: it.demoPage ?? undefined,
|
|
259
|
+
benchmarks: it.benchmarks ?? undefined,
|
|
256
260
|
priority: it.priority,
|
|
257
261
|
name: undefined,
|
|
258
262
|
});
|
|
@@ -399,8 +403,8 @@ export class Backlog extends EventEmitter {
|
|
|
399
403
|
if (it.status !== 'queued') throw err(409, 'Only queued items can be split');
|
|
400
404
|
const titles = (Array.isArray(parts) ? parts : it.aiSplit?.parts ?? []).map((t) => String(t).trim()).filter(Boolean);
|
|
401
405
|
if (titles.length < 2) throw err(400, 'Give at least two parts');
|
|
402
|
-
const { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, designDoc, engine, priority } = it;
|
|
403
|
-
const added = this.add(titles, { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, designDoc, engine, priority });
|
|
406
|
+
const { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, designDoc, demoPage, benchmarks, engine, priority } = it;
|
|
407
|
+
const added = this.add(titles, { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, designDoc, demoPage, benchmarks, engine, priority });
|
|
404
408
|
this.manager.judge?.feedback('dispatch', { summary: `split "${it.title}"`, verdict: it.aiSplit ? 'split suggested' : 'not suggested', outcome: 'split it' });
|
|
405
409
|
delete this.data.items[id];
|
|
406
410
|
this.changed();
|
package/src/brief.js
CHANGED
|
@@ -670,7 +670,11 @@ export const intentPath = (agentId) => path.join(briefDir(agentId), INTENT_FILE)
|
|
|
670
670
|
export const specPath = (agentId) => path.join(briefDir(agentId), SPEC_FILE);
|
|
671
671
|
export const DESIGN_FILE = 'DESIGN.md';
|
|
672
672
|
export const designPath = (agentId) => path.join(briefDir(agentId), DESIGN_FILE);
|
|
673
|
-
export const
|
|
673
|
+
export const DEMO_FILE = 'DEMO.html';
|
|
674
|
+
export const demoPath = (agentId) => path.join(briefDir(agentId), DEMO_FILE);
|
|
675
|
+
export const BENCH_FILE = 'BENCHMARK.md';
|
|
676
|
+
export const benchPath = (agentId) => path.join(briefDir(agentId), BENCH_FILE);
|
|
677
|
+
export const SPEC_DOCS = { intent: intentPath, spec: specPath, plan: planPath, designdoc: designPath, benchmark: benchPath, demo: demoPath };
|
|
674
678
|
|
|
675
679
|
/** INTENT.md: the request as given, and where it came from. */
|
|
676
680
|
export function intentMarkdown(agent) {
|
|
@@ -724,6 +728,30 @@ export const designDocPrompt = (file, { afterApproval = false } = {}) =>
|
|
|
724
728
|
'("- **Design page**: not published: <why>"; only for a missing or failing tool, never because the change is small) and carry on; never hold up the task for it. ' +
|
|
725
729
|
'The file is outside the repository: never copy it into the repo or commit it.';
|
|
726
730
|
|
|
731
|
+
export const demoPagePrompt = (file) =>
|
|
732
|
+
`When the change works (tests pass), make a sample demo page of it at ${file}: one self-contained HTML file ` +
|
|
733
|
+
'(CSS and JavaScript inline; no requests to other sites; under about 300 KB) that shows what this work does with realistic sample data. ' +
|
|
734
|
+
'Open with one line on what changed, then show it: for a library, API or CLI, runnable examples with sample inputs and the output you actually got ' +
|
|
735
|
+
'by running them (a small try-it form where the logic can run in the page); for a UI change, the changed screen rebuilt with sample data, ' +
|
|
736
|
+
'or screenshots you took embedded as data: URLs; for a fix, before and after. Never invent output or numbers. No filler, no repeat of the spec. ' +
|
|
737
|
+
'Publish it without asking, as a claude.ai Artifact with your Artifact tool, and add its link to the References section of your brief: ' +
|
|
738
|
+
'"- **Demo page**: [Artifact](<url>)". If you change the work later, update the file and republish to the same URL. ' +
|
|
739
|
+
'If the Artifact tool is missing or fails, write "- **Demo page**: not published: <why>" instead and carry on; never hold up the task for it. ' +
|
|
740
|
+
'The file is outside the repository: never copy it into the repo or commit it.';
|
|
741
|
+
|
|
742
|
+
export const benchmarksPrompt = (file, dir) =>
|
|
743
|
+
'Measure the speed of the code this task changes with micro benchmarks, once the change works (tests pass). ' +
|
|
744
|
+
'If the repository already has a benchmark setup (a bench or benchmarks folder, go test -bench, pytest-benchmark, JMH, criterion, ' +
|
|
745
|
+
`vitest bench, Benchmark.js, hyperfine and the like), add yours there in its style; otherwise put the scripts in ${dir}, outside the repository, never committed. ` +
|
|
746
|
+
'Benchmark the changed functions directly with realistic sample inputs at two or three sizes; warm up, run enough iterations for stable numbers, ' +
|
|
747
|
+
'and take the median and the spread (p95 or ±%). Run the same benchmark on the base commit (check it out in a temporary git worktree) ' +
|
|
748
|
+
`and on your change, back to back on this machine. Write the results to ${file} (Markdown), short:\n` +
|
|
749
|
+
'# Benchmark: <short name>\n## What was measured\nThe functions, inputs and sizes, and the command to run it again.\n' +
|
|
750
|
+
'## Results\nA table: case | before | after | change.\n## Environment\nCPU, OS, runtime and version.\n' +
|
|
751
|
+
'## Notes\nAnything noisy or surprising. A slowdown over 5% gets a line on why, or a fix.\n' +
|
|
752
|
+
'Run them again if you change the code afterwards. Only real measurements: never estimate a number. ' +
|
|
753
|
+
'The file is outside the repository: never copy it into the repo or commit it.';
|
|
754
|
+
|
|
727
755
|
/** One of the agent's files (intent, spec, plan, design doc): its Markdown and when it changed, or null. */
|
|
728
756
|
export function readSpecDoc(agentId, name) {
|
|
729
757
|
const file = SPEC_DOCS[name]?.(agentId);
|
|
@@ -751,11 +779,11 @@ export function specDocsInfo(agentId) {
|
|
|
751
779
|
export function prSections(agentId, read = (n) => readSpecDoc(agentId, n)?.markdown) {
|
|
752
780
|
const doc = (n) => read(n)?.trim();
|
|
753
781
|
// Demote the files' own headings under the description's.
|
|
754
|
-
const demote = (md) => md.replace(/^(#{1,4}) /gm, '#$1 ').replace(/^## (Intent|Spec|Plan|Design): .*\n+/m, '');
|
|
782
|
+
const demote = (md) => md.replace(/^(#{1,4}) /gm, '#$1 ').replace(/^## (Intent|Spec|Plan|Design|Benchmark): .*\n+/m, '');
|
|
755
783
|
const parts = [];
|
|
756
784
|
const intent = doc('intent');
|
|
757
785
|
if (intent) parts.push('## Intent', '', demote(intent), '');
|
|
758
|
-
for (const [name, label] of [['spec', 'Spec'], ['plan', 'Plan'], ['designdoc', 'Design']]) {
|
|
786
|
+
for (const [name, label] of [['spec', 'Spec'], ['plan', 'Plan'], ['designdoc', 'Design'], ['benchmark', 'Benchmark']]) {
|
|
759
787
|
const md = doc(name);
|
|
760
788
|
if (md) parts.push(`<details><summary><b>${label}</b></summary>`, '', demote(md), '', '</details>', '');
|
|
761
789
|
}
|
package/src/cli.js
CHANGED
|
@@ -347,6 +347,8 @@ export async function main(argv) {
|
|
|
347
347
|
.option('--no-container', 'run on this computer even if containers are the default')
|
|
348
348
|
.option('--plan', 'while a repo URL clones, plan the task with Claude (moves into the repo when ready)')
|
|
349
349
|
.option('--no-design-doc', 'no design doc for this agent (on by default: "designDoc" in config.json)')
|
|
350
|
+
.option('--demo-page', 'make a sample demo page of the change, published as an Artifact')
|
|
351
|
+
.option('--benchmarks', 'micro benchmarks of the changed code, before and after')
|
|
350
352
|
.option('--no-start', 'create without launching')
|
|
351
353
|
.option('-a, --attach', 'attach to the agent after launch (single intent only)')
|
|
352
354
|
.action(async (intents, opts, cmd) => {
|
|
@@ -374,6 +376,8 @@ export async function main(argv) {
|
|
|
374
376
|
start: opts.start,
|
|
375
377
|
plan: opts.plan,
|
|
376
378
|
designDoc: cmd.getOptionValueSource('designDoc') === 'cli' ? opts.designDoc : undefined,
|
|
379
|
+
demoPage: opts.demoPage || undefined,
|
|
380
|
+
benchmarks: opts.benchmarks || undefined,
|
|
377
381
|
});
|
|
378
382
|
for (const a of created) console.log(`${green('+')} ${bold(a.name)} ${dim(a.id)} session ${cyan(a.sessionId)}`);
|
|
379
383
|
console.log(dim(`Workspace setup and launch continue in the background. "agentmgr ls" shows status.`));
|
|
@@ -813,7 +817,7 @@ export async function main(argv) {
|
|
|
813
817
|
console.log(`${(color[r.land] ?? dim)(r.land.padEnd(7))} P${r.agent.priority} ${bold(r.agent.name)} #${r.pr.number ?? ''} ${r.pr.title ?? r.pr.url} ${checks}${r.pr.review ? ` ${r.pr.review.toLowerCase().replace(/_/g, ' ')}` : ''}${r.fixes ? dim(` sent back ${r.fixes}x`) : ''}`);
|
|
814
818
|
}
|
|
815
819
|
if (!rows.length) console.log(dim('No open pull requests from agents.'));
|
|
816
|
-
console.log(dim(`Failing checks ${settings.fixChecks ? 'are' : 'are not'} sent to agents, requested changes ${settings.fixReviews ? 'are' : 'are not'}, at most ${settings.maxFixes} times per PR; merges use ${settings.mergeMethod}.`));
|
|
820
|
+
console.log(dim(`Failing checks ${settings.fixChecks ? 'are' : 'are not'} sent to agents, requested changes ${settings.fixReviews ? 'are' : 'are not'}, at most ${settings.maxFixes} times per PR; new review comments ${settings.fixComments ? 'are' : 'are not'}, while it is open; merges use ${settings.mergeMethod}.`));
|
|
817
821
|
});
|
|
818
822
|
land
|
|
819
823
|
.command('update')
|
|
@@ -853,6 +857,7 @@ export async function main(argv) {
|
|
|
853
857
|
.description('Landing settings')
|
|
854
858
|
.option('--fix-checks <on|off>', 'send failing checks to the agent')
|
|
855
859
|
.option('--fix-reviews <on|off>', 'send requested changes to the agent')
|
|
860
|
+
.option('--fix-comments <on|off>', 'send new review comments to the agent while the pull request is open')
|
|
856
861
|
.option('--max-fixes <n>', 'at most this many times per pull request')
|
|
857
862
|
.option('--method <m>', 'merge method: squash, merge or rebase')
|
|
858
863
|
.option('--delete-branch <on|off>', 'delete the branch on GitHub after merging')
|
|
@@ -860,7 +865,7 @@ export async function main(argv) {
|
|
|
860
865
|
await daemon();
|
|
861
866
|
const onOff = (v) => (v === undefined ? undefined : ['on', 'true', 'yes', '1'].includes(String(v).toLowerCase()));
|
|
862
867
|
const patch = Object.fromEntries(
|
|
863
|
-
[['fixChecks', onOff(opts.fixChecks)], ['fixReviews', onOff(opts.fixReviews)], ['maxFixes', opts.maxFixes === undefined ? undefined : Number(opts.maxFixes)], ['mergeMethod', opts.method], ['deleteBranch', onOff(opts.deleteBranch)]].filter(([, v]) => v !== undefined),
|
|
868
|
+
[['fixChecks', onOff(opts.fixChecks)], ['fixReviews', onOff(opts.fixReviews)], ['fixComments', onOff(opts.fixComments)], ['maxFixes', opts.maxFixes === undefined ? undefined : Number(opts.maxFixes)], ['mergeMethod', opts.method], ['deleteBranch', onOff(opts.deleteBranch)]].filter(([, v]) => v !== undefined),
|
|
864
869
|
);
|
|
865
870
|
const { settings } = await api('PUT', '/landing', patch);
|
|
866
871
|
console.log(JSON.stringify(settings, null, 2));
|
package/src/codemap.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Codebase map: a repository's folders, sized by how many files they hold, with each agent in that
|
|
2
|
+
// repository on the folders it is changing or reading right now. Two agents that changed the same
|
|
3
|
+
// file are about to conflict; one reading a file another has changed is heading that way, which is
|
|
4
|
+
// the earlier warning. Changes come from the conflict radar's diffs, reading from the last half
|
|
5
|
+
// hour of the agent's transcript.
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
|
|
10
|
+
export const RECENT_MS = 30 * 60_000;
|
|
11
|
+
const MAX_FILES = 20_000;
|
|
12
|
+
const TAIL_BYTES = 768 * 1024;
|
|
13
|
+
const EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit']);
|
|
14
|
+
const READ_TOOLS = new Set(['Read', 'Grep', 'Glob', 'NotebookRead']);
|
|
15
|
+
|
|
16
|
+
/** The folder a file belongs to on the map: its first `depth` directories ("." for top-level files). */
|
|
17
|
+
export function moduleOf(file, depth = 2) {
|
|
18
|
+
const parts = file.split('/').slice(0, -1);
|
|
19
|
+
return parts.length ? parts.slice(0, depth).join('/') : '.';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Files the agent's tools touched since `since`, from its transcript: { file: { kind, at } }, kind 'edit' or 'read'. */
|
|
23
|
+
export function touchedFiles(transcript, workdir, since = Date.now() - RECENT_MS) {
|
|
24
|
+
const out = {};
|
|
25
|
+
let text = '';
|
|
26
|
+
try {
|
|
27
|
+
const st = fs.statSync(transcript);
|
|
28
|
+
const fd = fs.openSync(transcript, 'r');
|
|
29
|
+
try {
|
|
30
|
+
const len = Math.min(st.size, TAIL_BYTES);
|
|
31
|
+
const buf = Buffer.alloc(len);
|
|
32
|
+
fs.readSync(fd, buf, 0, len, st.size - len);
|
|
33
|
+
text = buf.toString('utf8');
|
|
34
|
+
} finally {
|
|
35
|
+
fs.closeSync(fd);
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
const root = workdir.endsWith('/') ? workdir : `${workdir}/`;
|
|
41
|
+
for (const line of text.split('\n')) {
|
|
42
|
+
if (!line.includes('"tool_use"')) continue;
|
|
43
|
+
let entry;
|
|
44
|
+
try {
|
|
45
|
+
entry = JSON.parse(line);
|
|
46
|
+
} catch {
|
|
47
|
+
continue; // the first line may be cut
|
|
48
|
+
}
|
|
49
|
+
const at = Date.parse(entry.timestamp ?? 0);
|
|
50
|
+
if (!(at >= since)) continue;
|
|
51
|
+
for (const c of entry.message?.content ?? []) {
|
|
52
|
+
if (c?.type !== 'tool_use') continue;
|
|
53
|
+
const kind = EDIT_TOOLS.has(c.name) ? 'edit' : READ_TOOLS.has(c.name) ? 'read' : null;
|
|
54
|
+
const p = c.input?.file_path ?? c.input?.notebook_path ?? c.input?.path;
|
|
55
|
+
if (!kind || typeof p !== 'string') continue;
|
|
56
|
+
const abs = path.isAbsolute(p) ? p : path.join(workdir, p);
|
|
57
|
+
if (!abs.startsWith(root)) continue;
|
|
58
|
+
const rel = abs.slice(root.length);
|
|
59
|
+
if (!rel || rel.startsWith('.git/')) continue;
|
|
60
|
+
const prev = out[rel];
|
|
61
|
+
// An edit outranks a read; otherwise the latest time wins.
|
|
62
|
+
if (!prev || (kind === 'edit' && prev.kind === 'read') || (kind === prev.kind && at > prev.at)) out[rel] = { kind, at };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The map: { modules: [{ key, files, agents: [{ id, changed, reading }] }], agents, links }.
|
|
70
|
+
* agents: [{ id, name, busy, attention, changed: { file: {added, removed} }, touched: { file: {kind, at} } }].
|
|
71
|
+
* links: [{ a, b, kind: 'collide' | 'heading' | 'near', files }], 'heading' from `a` (reading) to `b` (changed it).
|
|
72
|
+
*/
|
|
73
|
+
export function buildMap({ files = [], agents = [], depth = 2 }) {
|
|
74
|
+
const modules = new Map();
|
|
75
|
+
const mod = (key) => modules.get(key) ?? modules.set(key, { key, files: 0, agents: new Map() }).get(key);
|
|
76
|
+
for (const f of files.slice(0, MAX_FILES)) mod(moduleOf(f, depth)).files += 1;
|
|
77
|
+
const touch = (id, file, what) => {
|
|
78
|
+
const m = mod(moduleOf(file, depth));
|
|
79
|
+
const x = m.agents.get(id) ?? m.agents.set(id, { id, changed: 0, reading: 0 }).get(id);
|
|
80
|
+
x[what] += 1;
|
|
81
|
+
};
|
|
82
|
+
for (const a of agents) {
|
|
83
|
+
for (const f of Object.keys(a.changed ?? {})) touch(a.id, f, 'changed');
|
|
84
|
+
for (const [f, t] of Object.entries(a.touched ?? {})) if (!a.changed?.[f] && t.kind === 'read') touch(a.id, f, 'reading');
|
|
85
|
+
}
|
|
86
|
+
const links = [];
|
|
87
|
+
for (let i = 0; i < agents.length; i++) {
|
|
88
|
+
for (let j = i + 1; j < agents.length; j++) {
|
|
89
|
+
const x = agents[i];
|
|
90
|
+
const y = agents[j];
|
|
91
|
+
const cx = Object.keys(x.changed ?? {});
|
|
92
|
+
const cy = new Set(Object.keys(y.changed ?? {}));
|
|
93
|
+
const both = cx.filter((f) => cy.has(f));
|
|
94
|
+
if (both.length) {
|
|
95
|
+
links.push({ a: x.id, b: y.id, kind: 'collide', files: both.slice(0, 10) });
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
// Reading what the other changed: the next step is often an edit there.
|
|
99
|
+
const heading = (r, c) => Object.entries(r.touched ?? {}).filter(([f, t]) => t.kind === 'read' && !r.changed?.[f] && c.changed?.[f]).map(([f]) => f);
|
|
100
|
+
const xy = heading(x, y);
|
|
101
|
+
const yx = heading(y, x);
|
|
102
|
+
if (xy.length) links.push({ a: x.id, b: y.id, kind: 'heading', files: xy.slice(0, 10) });
|
|
103
|
+
if (yx.length) links.push({ a: y.id, b: x.id, kind: 'heading', files: yx.slice(0, 10) });
|
|
104
|
+
if (xy.length || yx.length) continue;
|
|
105
|
+
const mx = new Set([...cx, ...Object.keys(x.touched ?? {})].map((f) => moduleOf(f, depth)));
|
|
106
|
+
const near = [...new Set([...cy, ...Object.keys(y.touched ?? {})].map((f) => moduleOf(f, depth)))].filter((m) => mx.has(m));
|
|
107
|
+
if (near.length) links.push({ a: x.id, b: y.id, kind: 'near', files: near.slice(0, 5) });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
modules: [...modules.values()].map((m) => ({ key: m.key, files: m.files, agents: [...m.agents.values()] })).sort((a, b) => b.files - a.files || a.key.localeCompare(b.key)),
|
|
112
|
+
agents: agents.map(({ id, name, busy, attention, changed, touched }) => ({ id, name, busy: Boolean(busy), attention: Boolean(attention), changed: Object.keys(changed ?? {}).length, reading: Object.values(touched ?? {}).filter((t) => t.kind === 'read').length })),
|
|
113
|
+
links,
|
|
114
|
+
};
|
|
115
|
+
}
|
package/src/config.js
CHANGED
|
@@ -68,6 +68,12 @@ const DEFAULTS = {
|
|
|
68
68
|
// Task agents write a short design doc once their plan is settled and publish it as a claude.ai
|
|
69
69
|
// Artifact, updated when the work is done. Per agent: designDoc. (Publish to Google Drive is a button.)
|
|
70
70
|
designDoc: true,
|
|
71
|
+
// Off unless asked, per agent too: a sample demo page of the change (published as an Artifact)
|
|
72
|
+
// and micro benchmarks of the code it changed, before and after. Per agent: demoPage, benchmarks.
|
|
73
|
+
// Each morning (weekdays), a spoken standup of the agents' news; see standup.js.
|
|
74
|
+
standup: { enabled: true, at: '09:00', weekends: false, ai: true, notify: true },
|
|
75
|
+
demoPage: false,
|
|
76
|
+
benchmarks: false,
|
|
71
77
|
// The AI judge (stuck, idle screens, reviews); see JUDGE_DEFAULTS in judge.js for every field.
|
|
72
78
|
judge: { enabled: true },
|
|
73
79
|
// Clean up old agents: "close-delete", "close" (delete by hand), "manual" or "off"; see cleanup.js.
|