ai-agentmanager 1.29.0 → 1.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/public/app.js +1 -1
- package/public/bughunt.js +38 -10
- package/public/today.js +6 -2
- package/src/bughunt.js +247 -11
- package/src/manager.js +11 -2
- package/src/server.js +41 -3
- package/src/today.js +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.30.0 (2026-11-07)
|
|
4
|
+
|
|
5
|
+
- **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.
|
|
6
|
+
|
|
3
7
|
## 1.29.0 (2026-11-07)
|
|
4
8
|
|
|
5
9
|
- **Questions for you, with answers ready.** The assistant now also finds questions put to you in Slack (and email and meeting notes, with those on), including ones you're only copied or mentioned on, and prepares an answer for each: it reads the thread and checks the code of your projects, Jira and docs. They show in Today (*Asked you* is pressing, *CC'd* can wait) and under Actions → Questions, with the draft to *Copy*, *Edit*, or *Draft again*, and *Thread* to open where it was asked. A question without a draft has *Draft an answer*, which starts a session that researches it. Nothing is ever sent for you. (`agentmgr actions add --question … [--cc]`, `agentmgr actions answer <id> "<text>"`.)
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -265,7 +265,7 @@ const todayUi = initToday({
|
|
|
265
265
|
openActions: () => actionsUi.open(),
|
|
266
266
|
openIssues: () => issuesUi.open(),
|
|
267
267
|
openReviews: () => reviewsUi.open(),
|
|
268
|
-
openBugs: () => bugsUi.open({ show
|
|
268
|
+
openBugs: (show = 'open') => bugsUi.open({ show }),
|
|
269
269
|
openChanges: (id) => (showTab('agents'), select(id), reviewUi.open(id)),
|
|
270
270
|
});
|
|
271
271
|
$('#today-btn').onclick = () => todayUi.open();
|
package/public/bughunt.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Bugs: what background bug hunts found, checked, worst first; and the hunts themselves (a project
|
|
2
2
|
// or a folder of it, recent changes or the whole module, by hand or every night, with a cost
|
|
3
3
|
// limit per run). Each finding opens to its evidence; Fix starts an agent on it, File it opens a
|
|
4
|
-
// filled-in issue, Not a bug keeps it from coming back, Snooze hides it until later.
|
|
4
|
+
// filled-in issue, Not a bug keeps it from coming back, Snooze hides it until later. A hunt can
|
|
5
|
+
// fix the serious ones itself: those come as draft pull requests, under Draft PRs.
|
|
5
6
|
|
|
6
7
|
import { holdWhilePicking, rowKeys } from './rowkeys.js';
|
|
7
8
|
import { expandButton, expandable } from './expand.js';
|
|
@@ -10,9 +11,11 @@ const SAVED = 'agentmgr.bugsFilter';
|
|
|
10
11
|
const FILTERS = [
|
|
11
12
|
['open', 'Open'],
|
|
12
13
|
['fixing', 'Fixing'],
|
|
14
|
+
['pr', 'Draft PRs'],
|
|
13
15
|
['snoozed', 'Snoozed'],
|
|
14
16
|
['filed', 'Filed'],
|
|
15
17
|
['notbug', 'Not a bug'],
|
|
18
|
+
['done', 'Done'],
|
|
16
19
|
['dropped', 'Not kept'],
|
|
17
20
|
['hunts', 'Hunts'],
|
|
18
21
|
];
|
|
@@ -70,9 +73,21 @@ export function initBugHunt({ api, $, esc, ago, toast, openAgent }) {
|
|
|
70
73
|
<button class="small" data-bug="file" title="A filled-in issue to submit (i)">File it</button>
|
|
71
74
|
<button class="small" data-bug="notbug" title="Not a bug: it won't be reported again (x)">Not a bug</button>
|
|
72
75
|
<select class="small" data-bug-snooze title="Hide it until then (s: tomorrow)"><option value="">Snooze…</option><option value="day">Until tomorrow 9am</option><option value="week">Until Monday 9am</option></select>`
|
|
73
|
-
: f.status === '
|
|
74
|
-
? `<
|
|
75
|
-
|
|
76
|
+
: f.status === 'pr'
|
|
77
|
+
? `${f.prUrl ? `<a class="small-link primary-link" href="${esc(f.prUrl)}" target="_blank" rel="noopener" title="The draft pull request: look it over, then mark it ready">Open PR ↗</a>` : ''}
|
|
78
|
+
<button class="small" data-bug="done" title="You looked at it: off the list (d)">Done</button>
|
|
79
|
+
${f.fixAgentId ? '<button class="small" data-bug="open-fix" title="The session that fixed it">Session</button>' : ''}`
|
|
80
|
+
: f.status === 'fixing' && f.fixAgentId
|
|
81
|
+
? `<button class="small" data-bug="open-fix" title="Open the agent fixing it">Open fix</button> <button class="small" data-bug="back" title="Back to open (o)">Bring back</button>`
|
|
82
|
+
: `<button class="small" data-bug="back" title="Back to open (o)">Bring back</button>`;
|
|
83
|
+
const auto =
|
|
84
|
+
f.auto?.state === 'fixing'
|
|
85
|
+
? ' · fixing automatically'
|
|
86
|
+
: f.auto?.state === 'failed'
|
|
87
|
+
? ` · the automatic fix didn't hold up: ${f.auto.reason}`
|
|
88
|
+
: f.status === 'pr'
|
|
89
|
+
? ' · fixed automatically: a draft pull request'
|
|
90
|
+
: '';
|
|
76
91
|
const full =
|
|
77
92
|
opened === f.id
|
|
78
93
|
? `<tr class="bug-detail"><td colspan="3">
|
|
@@ -80,18 +95,20 @@ export function initBugHunt({ api, $, esc, ago, toast, openAgent }) {
|
|
|
80
95
|
<p><b>Evidence: ${f.evidence.type === 'test' ? 'a failing test' : 'the path through the code'}.</b></p><pre>${esc(f.evidence.detail)}</pre>
|
|
81
96
|
${f.evidence.test ? `<p><b>Test.</b></p><pre>${esc(f.evidence.test)}</pre>` : ''}
|
|
82
97
|
${f.fix ? `<p><b>Suggested fix.</b> ${esc(f.fix)}</p>` : ''}
|
|
98
|
+
${f.auto?.check ? `<p class="hint">The fix was reviewed by the AI judge: ${esc(f.auto.check.reason ?? '')} (${Math.round(f.auto.check.confidence * 100)}%).</p>` : ''}
|
|
99
|
+
${f.issueUrl ? `<p class="hint">Filed: <a href="${esc(f.issueUrl)}" target="_blank" rel="noopener">${esc(f.issueUrl)}</a></p>` : ''}
|
|
83
100
|
<p class="hint">${f.check ? `Second check: ${f.check.real ? 'holds up' : 'does not hold up'} (${Math.round(f.check.confidence * 100)}%). ${esc(f.check.reason ?? '')}` : 'Second check: not asked (the AI judge is off); kept because a test fails.'} Found ${esc(ago(f.at))} by the ${esc(f.hunt ?? '')} hunt${f.foundBy ? ` · <button class="link" data-bug-agent="${esc(f.foundBy)}">its session</button>` : ''}.</p>
|
|
84
101
|
</td></tr>`
|
|
85
102
|
: '';
|
|
86
103
|
return `<tr data-row-id="${esc(f.id)}" class="bug-${esc(f.severity)}">
|
|
87
104
|
<td class="nowrap"><span class="bug-sev ${esc(f.severity)}">${esc(SEV[f.severity] ?? f.severity)}</span></td>
|
|
88
|
-
<td><div class="today-title">${esc(f.title)}</div><div class="hint">${esc(where(f))}${f.evidence?.type === 'test' ? ' · a test fails' : ''}${f.snoozeUntil ? ` · until ${esc(new Date(f.snoozeUntil).toLocaleString())}` : ''}</div></td>
|
|
105
|
+
<td><div class="today-title">${esc(f.title)}</div><div class="hint">${esc(where(f))}${f.evidence?.type === 'test' ? ' · a test fails' : ''}${esc(auto)}${f.snoozeUntil ? ` · until ${esc(new Date(f.snoozeUntil).toLocaleString())}` : ''}</div></td>
|
|
89
106
|
<td class="nowrap today-acts">${acts}</td>
|
|
90
107
|
</tr>${full}`;
|
|
91
108
|
}
|
|
92
109
|
|
|
93
110
|
function huntForm(h) {
|
|
94
|
-
const p = h ?? { focus: 'changes', schedule: 'manual', maxUsd: 5, kinds: [], path: '', project: projects[0]?.shortcut ?? '' };
|
|
111
|
+
const p = h ?? { focus: 'changes', schedule: 'manual', maxUsd: 5, kinds: [], path: '', project: projects[0]?.shortcut ?? '', autoFix: false, fixAt: 'high', fileIssues: false, testCommand: '' };
|
|
95
112
|
return `<form class="hunt-form alerts-body" data-hunt-form="${esc(h?.id ?? 'new')}">
|
|
96
113
|
<h3>${h ? `Edit ${esc(h.name)}` : 'New hunt'}</h3>
|
|
97
114
|
<div class="row three">
|
|
@@ -106,6 +123,14 @@ export function initBugHunt({ api, $, esc, ago, toast, openAgent }) {
|
|
|
106
123
|
<label>Cost limit per run ($) <input name="maxUsd" type="number" min="0.5" max="500" step="0.5" value="${esc(p.maxUsd)}" /></label>
|
|
107
124
|
</div>
|
|
108
125
|
<p class="hint">The hunter reads the code and runs the tests on its own copy; it never commits or pushes. One hunt runs at a time, and it stops at the cost limit.</p>
|
|
126
|
+
<fieldset><legend>Fix automatically</legend>
|
|
127
|
+
<label class="check"><input type="checkbox" name="autoFix" ${p.autoFix ? 'checked' : ''} /> Fix the bugs it finds, from
|
|
128
|
+
<select name="fixAt" class="small">${Object.entries(SEV).map(([k, label]) => `<option value="${k}" ${(p.fixAt ?? 'high') === k ? 'selected' : ''}>${esc(label)}${k === 'critical' ? ' only' : ' and up'}</option>`).join('')}</select>,
|
|
129
|
+
as draft pull requests</label>
|
|
130
|
+
<label>Test command <span class="hint">(optional: run on each fix before its pull request, like npm test)</span><input name="testCommand" value="${esc(p.testCommand ?? '')}" placeholder="npm test" autocomplete="off" /></label>
|
|
131
|
+
<label class="check"><input type="checkbox" name="fileIssues" ${p.fileIssues ? 'checked' : ''} /> When a fix doesn't hold up, file the bug as a GitHub issue <span class="hint">(issues on a public repository are public)</span></label>
|
|
132
|
+
<p class="hint">Each fix is made by its own agent on its own branch: its test must fail before and pass after, the whole suite must pass, and the AI judge (when it's on) reviews the change. Only then is a <b>draft</b> pull request opened; nothing is merged. At most 3 a run, within the cost limit above.</p>
|
|
133
|
+
</fieldset>
|
|
109
134
|
<div class="dialog-actions"><button type="button" class="ghost" data-bug="cancel-hunt">Cancel</button><button type="submit" class="primary">${h ? 'Save' : 'Add hunt'}</button></div>
|
|
110
135
|
</form>`;
|
|
111
136
|
}
|
|
@@ -116,7 +141,7 @@ export function initBugHunt({ api, $, esc, ago, toast, openAgent }) {
|
|
|
116
141
|
.map((h) => {
|
|
117
142
|
const last = h.last ? `${h.last.status === 'running' ? 'running now' : `${h.last.kept ?? 0} kept of ${h.last.found ?? 0} new`} · ${ago(h.last.at)}` : 'not run yet';
|
|
118
143
|
return `<tr data-hunt="${esc(h.id)}">
|
|
119
|
-
<td><div class="today-title">${esc(h.name)}</div><div class="hint">${esc(h.focus === 'changes' ? 'recent changes' : `whole module${h.coveredCount ? ` (${h.coveredCount} parts covered)` : ''}`)}${h.kinds.length ? ` · ${esc(h.kinds.join(', '))}` : ''} · ${esc(h.schedule === 'nightly' ? 'nightly' : 'by hand')} · up to $${esc(h.maxUsd)}</div></td>
|
|
144
|
+
<td><div class="today-title">${esc(h.name)}</div><div class="hint">${esc(h.focus === 'changes' ? 'recent changes' : `whole module${h.coveredCount ? ` (${h.coveredCount} parts covered)` : ''}`)}${h.kinds.length ? ` · ${esc(h.kinds.join(', '))}` : ''} · ${esc(h.schedule === 'nightly' ? 'nightly' : 'by hand')} · up to $${esc(h.maxUsd)}${h.autoFix ? ` · fixes ${esc(h.fixAt === 'critical' ? 'critical ones' : `${h.fixAt} and up`)} as draft PRs` : ''}</div></td>
|
|
120
145
|
<td class="hint">${esc(last)}${h.open ? ` · ${h.open} open` : ''}</td>
|
|
121
146
|
<td class="nowrap today-acts"><button class="small primary" data-bug="run" ${data.running ? 'disabled title="A hunt is running; one at a time"' : 'title="Start a run now"'}>Hunt now</button> <button class="small" data-bug="edit">Edit</button> <button class="small ${sure === h.id ? 'danger' : ''}" data-bug="delete">${sure === h.id ? 'Delete it?' : 'Delete'}</button></td>
|
|
122
147
|
</tr>`;
|
|
@@ -136,6 +161,7 @@ export function initBugHunt({ api, $, esc, ago, toast, openAgent }) {
|
|
|
136
161
|
const empty = {
|
|
137
162
|
open: data.hunts.length ? 'No open bugs. Hunts add what they find here, worst first.' : 'No bugs yet: set up a hunt under Hunts.',
|
|
138
163
|
dropped: "Findings the second check didn't confirm. They aren't reported again.",
|
|
164
|
+
pr: 'No draft pull requests. A hunt with Fix automatically on opens one for each bug it fixes and the checks accept.',
|
|
139
165
|
};
|
|
140
166
|
body.innerHTML = `
|
|
141
167
|
<div class="issues-head">
|
|
@@ -152,7 +178,7 @@ export function initBugHunt({ api, $, esc, ago, toast, openAgent }) {
|
|
|
152
178
|
: rows.length
|
|
153
179
|
? `<div class="issues-scroll"><table class="issues today-table"><tbody>${rows.map(findingRow).join('')}</tbody></table></div>`
|
|
154
180
|
: `<p class="hint issues-empty">${esc(empty[filter] ?? 'None here.')}</p>`}
|
|
155
|
-
${filter === 'hunts' ? '' : '<p class="hint">Keys: j/k move (or click a row), Enter shows the evidence, a fix, i file it, x not a bug, s snooze until tomorrow, o bring back, r look again, [ ] filters, f bigger.</p>'}`;
|
|
181
|
+
${filter === 'hunts' ? '' : '<p class="hint">Keys: j/k move (or click a row), Enter shows the evidence, a fix, i file it, x not a bug, s snooze until tomorrow, d done (a draft PR looked at), o bring back, r look again, [ ] filters, f bigger.</p>'}`;
|
|
156
182
|
keys.redraw();
|
|
157
183
|
}
|
|
158
184
|
const render = holdWhilePicking(body, draw);
|
|
@@ -165,7 +191,7 @@ export function initBugHunt({ api, $, esc, ago, toast, openAgent }) {
|
|
|
165
191
|
const before = ids.map((id) => [id, finding(id)?.status, finding(id)?.snoozeUntil]);
|
|
166
192
|
try {
|
|
167
193
|
await api('POST', '/findings/set', { ids, status, until });
|
|
168
|
-
const label = { open: 'Back on the list', notbug: 'Not a bug: it won\'t be reported again', snoozed: 'Snoozed', filed: 'Marked filed' }[status];
|
|
194
|
+
const label = { open: 'Back on the list', notbug: 'Not a bug: it won\'t be reported again', snoozed: 'Snoozed', filed: 'Marked filed', done: 'Done' }[status];
|
|
169
195
|
const undo = undoing ? null : { label: 'Undo', run: async () => {
|
|
170
196
|
for (const [id, st, u] of before) if (st && st !== 'fixing') await decide([id], st, st === 'snoozed' ? u : null, { undoing: true });
|
|
171
197
|
} };
|
|
@@ -199,6 +225,7 @@ export function initBugHunt({ api, $, esc, ago, toast, openAgent }) {
|
|
|
199
225
|
}
|
|
200
226
|
}
|
|
201
227
|
if (what === 'notbug') return decide([id], 'notbug');
|
|
228
|
+
if (what === 'done') return decide([id], 'done');
|
|
202
229
|
if (what === 'snooze') return decide([id], 'snoozed', later(extra || 'day'));
|
|
203
230
|
if (what === 'back') return decide([id], 'open');
|
|
204
231
|
if (what === 'open-fix' && f.fixAgentId) return dialog.close(), openAgent(f.fixAgentId);
|
|
@@ -218,6 +245,7 @@ export function initBugHunt({ api, $, esc, ago, toast, openAgent }) {
|
|
|
218
245
|
x: (r) => act(r.dataset.rowId, 'notbug'),
|
|
219
246
|
s: (r) => act(r.dataset.rowId, 'snooze', 'day'),
|
|
220
247
|
o: (r) => act(r.dataset.rowId, 'back'),
|
|
248
|
+
d: (r) => act(r.dataset.rowId, 'done'),
|
|
221
249
|
r: Object.assign(() => load(), { needsRow: false }),
|
|
222
250
|
},
|
|
223
251
|
});
|
|
@@ -257,7 +285,7 @@ export function initBugHunt({ api, $, esc, ago, toast, openAgent }) {
|
|
|
257
285
|
e.preventDefault();
|
|
258
286
|
document.activeElement?.blur?.();
|
|
259
287
|
const fd = new FormData(form);
|
|
260
|
-
const input = { project: fd.get('project'), path: fd.get('path'), name: fd.get('name'), focus: fd.get('focus'), kinds: fd.getAll('kind'), schedule: fd.get('schedule'), maxUsd: Number(fd.get('maxUsd')) };
|
|
288
|
+
const input = { project: fd.get('project'), path: fd.get('path'), name: fd.get('name'), focus: fd.get('focus'), kinds: fd.getAll('kind'), schedule: fd.get('schedule'), maxUsd: Number(fd.get('maxUsd')), autoFix: fd.get('autoFix') === 'on', fixAt: fd.get('fixAt'), fileIssues: fd.get('fileIssues') === 'on', testCommand: fd.get('testCommand') };
|
|
261
289
|
try {
|
|
262
290
|
const id = form.dataset.huntForm;
|
|
263
291
|
await api(id === 'new' ? 'POST' : 'PUT', id === 'new' ? '/hunts' : `/hunts/${id}`, input);
|
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 === '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(' ');
|
|
64
65
|
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(' ');
|
|
65
66
|
return [it.agentId ? btn('open', 'Open', "Open the agent's session (Enter)", it.score < 20) : '', link(it.url, it.issueKey ? 'Jira' : 'Link')].join(' ');
|
|
66
67
|
}
|
|
@@ -212,9 +213,9 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
|
|
|
212
213
|
dialog.close();
|
|
213
214
|
return openReviews();
|
|
214
215
|
}
|
|
215
|
-
if (what === 'bugs' || (what === 'enter' && it.kind === 'bug')) {
|
|
216
|
+
if (what === 'bugs' || (what === 'enter' && (it.kind === 'bug' || it.kind === 'bug-pr'))) {
|
|
216
217
|
dialog.close();
|
|
217
|
-
return openBugs?.();
|
|
218
|
+
return openBugs?.(it.kind === 'bug-pr' ? 'pr' : undefined);
|
|
218
219
|
}
|
|
219
220
|
if (what === 'enter') {
|
|
220
221
|
if (it.kind === 'action') {
|
|
@@ -281,6 +282,9 @@ export function initToday({ api, $, esc, ago, openAgent, showInbox, openActions,
|
|
|
281
282
|
t.setHours(9, 0, 0, 0);
|
|
282
283
|
await api('POST', '/findings/set', { ids: [it.findingId], status: what === 'skip' ? 'snoozed' : 'notbug', until: what === 'skip' ? t.toISOString() : null });
|
|
283
284
|
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' }));
|
|
285
|
+
} else if (it.kind === 'bug-pr' && what === 'done') {
|
|
286
|
+
await api('POST', '/findings/set', { ids: [it.findingId], status: 'done' });
|
|
287
|
+
changedWith('Done: off the list', 'done', () => api('POST', '/findings/set', { ids: [it.findingId], status: 'pr' }));
|
|
284
288
|
} else if (it.kind === 'pr-requested' && (what === 'review' || what === 'assign')) {
|
|
285
289
|
const a = await api('POST', '/reviews', { url: it.reviewUrl });
|
|
286
290
|
toast?.(`Reviewer ${a.name ?? 'agent'} started`, 3000);
|
package/src/bughunt.js
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
// so the list stays worth reading. Bugs already reported, or that you said aren't bugs, aren't
|
|
6
6
|
// reported again. From the list: Fix (an agent starts on it, with the failing test), File it (a
|
|
7
7
|
// filled-in issue to submit), Not a bug, or Snooze.
|
|
8
|
+
//
|
|
9
|
+
// With "Fix automatically" on a hunt, the serious ones are fixed without you: an agent fixes each
|
|
10
|
+
// on its own branch (its test must go from failing to passing, and the whole suite must pass), the
|
|
11
|
+
// judge reviews the change against the finding, and what holds up is opened as a draft pull
|
|
12
|
+
// request for you to review. Nothing is merged. A fix that doesn't hold up stays in the list with
|
|
13
|
+
// the reason (and, when you asked for it, is filed as an issue so it isn't lost).
|
|
8
14
|
|
|
9
15
|
import crypto from 'node:crypto';
|
|
10
16
|
import fs from 'node:fs';
|
|
@@ -13,6 +19,8 @@ import { briefDir } from './brief.js';
|
|
|
13
19
|
|
|
14
20
|
export const FINDINGS_FILE = 'FINDINGS.json';
|
|
15
21
|
export const findingsPath = (agentId) => path.join(briefDir(agentId), FINDINGS_FILE);
|
|
22
|
+
export const FIX_FILE = 'FIX.json';
|
|
23
|
+
export const fixPath = (agentId) => path.join(briefDir(agentId), FIX_FILE);
|
|
16
24
|
|
|
17
25
|
export const FOCUS = { changes: 'What changed since the last run', module: 'The whole module, a part at a time' };
|
|
18
26
|
export const KINDS = {
|
|
@@ -26,11 +34,14 @@ export const KINDS = {
|
|
|
26
34
|
};
|
|
27
35
|
export const SEVERITIES = ['critical', 'high', 'medium', 'low'];
|
|
28
36
|
export const SCHEDULES = { manual: 'Only when you press Hunt now', nightly: 'Every night (1–5am), when no hunt is running' };
|
|
29
|
-
export const STATUSES = ['open', 'fixing', 'filed', 'notbug', 'snoozed', 'dropped'];
|
|
37
|
+
export const STATUSES = ['open', 'fixing', 'pr', 'done', 'filed', 'notbug', 'snoozed', 'dropped'];
|
|
30
38
|
|
|
31
39
|
const MAX_FINDINGS = 500;
|
|
32
40
|
const MAX_RUNS = 20;
|
|
33
41
|
const KEEP_AT = 0.6;
|
|
42
|
+
// Fix automatically: at most this many pull requests a run, and never for less than this each.
|
|
43
|
+
export const MAX_AUTO_PRS = 3;
|
|
44
|
+
const MIN_FIX_USD = 0.5;
|
|
34
45
|
const err = (status, message) => Object.assign(new Error(message), { status });
|
|
35
46
|
const clip = (s, n) => {
|
|
36
47
|
const t = String(s ?? '').trim();
|
|
@@ -189,6 +200,84 @@ export function fixIntent(f) {
|
|
|
189
200
|
.join('\n\n');
|
|
190
201
|
}
|
|
191
202
|
|
|
203
|
+
/** What an automatic fix agent is asked to do: the finding (its request). */
|
|
204
|
+
export function autoFixIntent(f) {
|
|
205
|
+
return `Bug fix: ${f.title}\n\n${fixIntent(f)}`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** An automatic fix agent's instructions: proven, unattended, and a report in `file`. */
|
|
209
|
+
export function fixerPrompt(file, fixing = {}) {
|
|
210
|
+
return [
|
|
211
|
+
`This fix runs without the user: nobody will answer questions, so decide yourself, and keep the change as small as the fix needs. ${fixing.testCommand ? `The project's tests run with: ${fixing.testCommand}` : "Find how the project's tests run (package.json, Makefile, CI config)."}`,
|
|
212
|
+
"1. Add a test for the bug to the project's tests and run it: it must fail before the fix. 2. Fix it. 3. Run that test again (it must pass) and then the whole test suite (it must pass). Don't commit, push or open a pull request: that's done for you once the fix is checked.",
|
|
213
|
+
`Write what happened to ${file} as JSON:\n` +
|
|
214
|
+
'{ "fixed": true|false, "why": "<one or two sentences: the fix, or why you could not fix it or it is not a bug>",\n' +
|
|
215
|
+
' "test": { "file": "<the test file>", "before": "fail|pass", "after": "fail|pass" },\n' +
|
|
216
|
+
' "suite": { "command": "<how you ran all the tests>", "passed": true|false, "output": "<the last lines it printed>" } }',
|
|
217
|
+
'Then set your status as done in the brief.',
|
|
218
|
+
].join('\n\n');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** FIX.json, cleaned up, or null. */
|
|
222
|
+
export function normalizeFix(raw) {
|
|
223
|
+
if (!raw || typeof raw !== 'object' || typeof raw.fixed !== 'boolean') return null;
|
|
224
|
+
const pf = (v) => (v === 'pass' || v === 'fail' ? v : null);
|
|
225
|
+
return {
|
|
226
|
+
fixed: raw.fixed,
|
|
227
|
+
why: clip(raw.why, 1000),
|
|
228
|
+
test: { file: raw.test?.file ? clip(raw.test.file, 300) : null, before: pf(raw.test?.before), after: pf(raw.test?.after) },
|
|
229
|
+
suite: { command: raw.suite?.command ? clip(raw.suite.command, 300) : null, passed: raw.suite?.passed === true, output: clip(raw.suite?.output, 2000) },
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** A fix agent's FIX.json, or null. */
|
|
234
|
+
export function readFix(agentId) {
|
|
235
|
+
try {
|
|
236
|
+
const text = fs.readFileSync(fixPath(agentId), 'utf8');
|
|
237
|
+
return normalizeFix(JSON.parse(text.slice(text.indexOf('{'), text.lastIndexOf('}') + 1)));
|
|
238
|
+
} catch {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Why a fix's own report doesn't hold up, or null when it does. */
|
|
244
|
+
export function fixProblem(report) {
|
|
245
|
+
if (!report) return 'The fix agent wrote no report';
|
|
246
|
+
if (!report.fixed) return `The fix agent didn't fix it${report.why ? `: ${report.why}` : ''}`;
|
|
247
|
+
if (report.test.before !== 'fail') return "Its test didn't fail before the fix, so it doesn't show the bug";
|
|
248
|
+
if (report.test.after !== 'pass') return "Its test still fails after the fix";
|
|
249
|
+
if (!report.suite.passed) return 'The test suite fails with the fix';
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** The judge's question: does this change fix the finding, and nothing else? */
|
|
254
|
+
export function fixCheckPrompt(f, diff) {
|
|
255
|
+
return [
|
|
256
|
+
'An agent fixed the bug below without a person watching. Review its change before it goes to the user as a pull request: does it fix the bug at its cause, with a test that shows the bug, without changing other behaviour or weakening other tests? Reject changes that only hide the symptom, skip or loosen tests, or do unrelated things.',
|
|
257
|
+
`Bug: ${f.title}\nWhere: ${f.file ?? '?'}${f.line ? `:${f.line}` : ''}\nHow it fails: ${f.why}`,
|
|
258
|
+
`The change:\n${String(diff ?? '').slice(0, 30_000)}`,
|
|
259
|
+
'Reply with JSON only: { "ok": true|false, "confidence": <0 to 1>, "reason": "<one or two sentences>" }',
|
|
260
|
+
].join('\n\n');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** The draft pull request's description: the finding, how the fix was checked. */
|
|
264
|
+
export function fixPrBody(f, report, check, testCommand = null) {
|
|
265
|
+
return [
|
|
266
|
+
`Fixes a bug found by a bug hunt.`,
|
|
267
|
+
findingMarkdown(f).replace(/\n\n_Found by a bug hunt in AI Agent Manager\._$/, ''),
|
|
268
|
+
'**How the fix was checked**',
|
|
269
|
+
[
|
|
270
|
+
`- The test${report.test.file ? ` (\`${report.test.file}\`)` : ''} failed before the fix and passes after it.`,
|
|
271
|
+
`- The whole suite passes${report.suite.command ? ` (\`${report.suite.command}\`)` : ''}.`,
|
|
272
|
+
testCommand ? `- Run again here before this pull request: \`${testCommand}\` passes.` : null,
|
|
273
|
+
check ? `- The AI judge reviewed the change: ${check.reason || 'it holds up'} (confidence ${Math.round(check.confidence * 100)}%).` : null,
|
|
274
|
+
]
|
|
275
|
+
.filter(Boolean)
|
|
276
|
+
.join('\n'),
|
|
277
|
+
'_Opened as a draft by AI Agent Manager. Nothing was merged: look it over, then mark it ready._',
|
|
278
|
+
].join('\n\n');
|
|
279
|
+
}
|
|
280
|
+
|
|
192
281
|
/** The finding as an issue, in Markdown. */
|
|
193
282
|
export function findingMarkdown(f) {
|
|
194
283
|
return [
|
|
@@ -218,9 +307,17 @@ export function issueLinkFor(repo, f) {
|
|
|
218
307
|
}
|
|
219
308
|
|
|
220
309
|
export class BugHunts {
|
|
221
|
-
/**
|
|
222
|
-
|
|
310
|
+
/**
|
|
311
|
+
* `judge` is the AI judge (ask(key, agent, prompt, validate)); `read` gives a hunter's findings
|
|
312
|
+
* and `readFix` a fix agent's report (tests). `git` does what fixing automatically needs:
|
|
313
|
+
* { diff(agentId), commit(agentId, message), pr(agentId, { title, body, draft }),
|
|
314
|
+
* test(agentId, command) → { passed, output }, fileIssue(project, { title, body }) → url }.
|
|
315
|
+
*/
|
|
316
|
+
constructor({ manager, store, judge = null, log = () => {}, read = readFindings, readFix: rf = readFix, git = null }) {
|
|
223
317
|
this.read = read;
|
|
318
|
+
this.readFix = rf;
|
|
319
|
+
this.git = git;
|
|
320
|
+
this.settling = new Set();
|
|
224
321
|
this.manager = manager;
|
|
225
322
|
this.store = store;
|
|
226
323
|
this.judge = judge;
|
|
@@ -228,6 +325,7 @@ export class BugHunts {
|
|
|
228
325
|
this.checking = new Set();
|
|
229
326
|
this.onFinished = (agent) => {
|
|
230
327
|
if (agent?.hunting) this.ingest(agent.id).catch((e) => this.log(`bughunt: ${e.message}`));
|
|
328
|
+
else if (agent && this.autoFinding(agent.id)) this.settle(agent.id).catch((e) => this.log(`bughunt: ${e.message}`));
|
|
231
329
|
};
|
|
232
330
|
manager.on('finished', this.onFinished);
|
|
233
331
|
this.timer = null;
|
|
@@ -265,7 +363,23 @@ export class BugHunts {
|
|
|
265
363
|
const raw = input.maxUsd === undefined ? prev.maxUsd ?? 5 : Number(input.maxUsd);
|
|
266
364
|
if (!(Number.isFinite(raw) && raw > 0 && raw <= 500)) throw err(400, 'The cost limit per run is a number of dollars, up to 500');
|
|
267
365
|
const p = cleanPath(input.path ?? prev.path ?? '');
|
|
268
|
-
|
|
366
|
+
const fixAt = input.fixAt ?? prev.fixAt ?? 'high';
|
|
367
|
+
if (!SEVERITIES.includes(fixAt)) throw err(400, `Fix automatically from ${SEVERITIES.join(', ')}`);
|
|
368
|
+
const flag = (k) => Boolean(input[k] ?? prev[k] ?? false);
|
|
369
|
+
const testCommand = clip(input.testCommand ?? prev.testCommand ?? '', 300) || null;
|
|
370
|
+
return {
|
|
371
|
+
project,
|
|
372
|
+
path: p,
|
|
373
|
+
focus,
|
|
374
|
+
kinds,
|
|
375
|
+
schedule,
|
|
376
|
+
maxUsd: Math.round(raw * 100) / 100,
|
|
377
|
+
name: clip(input.name ?? prev.name ?? '', 80) || `${project}${p ? `/${p}` : ''}`,
|
|
378
|
+
autoFix: flag('autoFix'),
|
|
379
|
+
fixAt,
|
|
380
|
+
fileIssues: flag('fileIssues'),
|
|
381
|
+
testCommand,
|
|
382
|
+
};
|
|
269
383
|
}
|
|
270
384
|
|
|
271
385
|
add(input) {
|
|
@@ -365,18 +479,139 @@ export class BugHunts {
|
|
|
365
479
|
this.manager.stop(agentId);
|
|
366
480
|
} catch {}
|
|
367
481
|
this.log(`bughunt: ${agent.name}: ${kept} kept of ${found} new`);
|
|
368
|
-
return { found, kept };
|
|
482
|
+
return h?.autoFix ? { found, kept, fixing: this.autoFix(h, agentId) } : { found, kept };
|
|
369
483
|
} finally {
|
|
370
484
|
this.checking.delete(agentId);
|
|
371
485
|
}
|
|
372
486
|
}
|
|
373
487
|
|
|
374
|
-
/**
|
|
488
|
+
/**
|
|
489
|
+
* Runs that ended without saying done (stopped, out of budget): their findings are taken in too.
|
|
490
|
+
* Likewise automatic fixes: one that stopped is settled as it stands.
|
|
491
|
+
*/
|
|
375
492
|
async sweep() {
|
|
376
493
|
for (const a of this.store.list()) {
|
|
377
|
-
if (!a.hunting || a.hunting.ingestedAt) continue;
|
|
378
494
|
const rt = this.manager.runtimes?.get(a.id);
|
|
379
|
-
|
|
495
|
+
const ended = a.brief?.status === 'done' || (a.desired !== 'running' && !rt?.pty);
|
|
496
|
+
if (a.hunting && !a.hunting.ingestedAt) {
|
|
497
|
+
if (ended) await this.ingest(a.id).catch(() => {});
|
|
498
|
+
} else if (ended && this.autoFinding(a.id)) await this.settle(a.id).catch(() => {});
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** The finding an automatic fix agent is working on, while it is. */
|
|
503
|
+
autoFinding(agentId) {
|
|
504
|
+
return this.findings.find((f) => f.auto?.agentId === agentId && f.auto.state === 'fixing') ?? null;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Fix automatically: the run's new findings at or above the hunt's severity, worst first, up to
|
|
509
|
+
* MAX_AUTO_PRS, each by its own agent on its own branch. What's left of the run's cost limit is
|
|
510
|
+
* shared between them. Returns the ids of the findings being fixed.
|
|
511
|
+
*/
|
|
512
|
+
autoFix(h, hunterId) {
|
|
513
|
+
const rank = (s) => SEVERITIES.indexOf(s);
|
|
514
|
+
const picked = this.findings
|
|
515
|
+
.filter((f) => f.foundBy === hunterId && f.status === 'open' && rank(f.severity) <= rank(h.fixAt ?? 'high'))
|
|
516
|
+
.sort((a, b) => rank(a.severity) - rank(b.severity))
|
|
517
|
+
.slice(0, MAX_AUTO_PRS);
|
|
518
|
+
if (!picked.length) return [];
|
|
519
|
+
const spent = Number(this.manager.get?.(hunterId)?.costUsd) || 0;
|
|
520
|
+
const each = Math.floor(((h.maxUsd - spent) / picked.length) * 100) / 100;
|
|
521
|
+
const started = [];
|
|
522
|
+
for (const f of picked) {
|
|
523
|
+
if (!this.git || each < MIN_FIX_USD) {
|
|
524
|
+
f.auto = { state: 'failed', at: now(), reason: this.git ? `The run's cost limit ($${h.maxUsd}) was used up by the hunt` : "Pull requests can't be opened from here" };
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
try {
|
|
528
|
+
const agent = this.manager.create({
|
|
529
|
+
project: f.project,
|
|
530
|
+
intent: autoFixIntent(f),
|
|
531
|
+
fixing: { findingId: f.id, testCommand: h.testCommand ?? null },
|
|
532
|
+
name: `fix-${f.title}`.toLowerCase().replace(/[^a-z0-9-]+/g, '-').slice(0, 40),
|
|
533
|
+
worktree: true,
|
|
534
|
+
planReview: false,
|
|
535
|
+
designDoc: false,
|
|
536
|
+
demoPage: false,
|
|
537
|
+
benchmarks: false,
|
|
538
|
+
});
|
|
539
|
+
this.manager.patch(agent.id, { budgetUsd: each });
|
|
540
|
+
f.fixAgentId = agent.id;
|
|
541
|
+
f.status = 'fixing';
|
|
542
|
+
f.auto = { state: 'fixing', agentId: agent.id, at: now(), budgetUsd: each };
|
|
543
|
+
started.push(f.id);
|
|
544
|
+
this.log(`bughunt: fixing "${f.title}" automatically (${agent.name}, up to $${each})`);
|
|
545
|
+
} catch (e) {
|
|
546
|
+
f.auto = { state: 'failed', at: now(), reason: `Couldn't start a fix: ${e.message}` };
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
this.store.save();
|
|
550
|
+
return started;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* An automatic fix ended: its report, the tests (when the hunt has a test command) and the judge
|
|
555
|
+
* decide. What holds up is committed and opened as a draft pull request; what doesn't stays in
|
|
556
|
+
* the list with the reason, and is filed as an issue when the hunt says so. Safe to call twice.
|
|
557
|
+
*/
|
|
558
|
+
async settle(agentId) {
|
|
559
|
+
const f = this.autoFinding(agentId);
|
|
560
|
+
if (!f || this.settling.has(agentId)) return null;
|
|
561
|
+
this.settling.add(agentId);
|
|
562
|
+
const h = this.hunts.find((x) => x.id === f.huntId) ?? null;
|
|
563
|
+
const agent = this.store.get(agentId);
|
|
564
|
+
try {
|
|
565
|
+
const report = this.readFix(agentId);
|
|
566
|
+
let problem = fixProblem(report);
|
|
567
|
+
const diff = problem ? '' : await this.git.diff(agentId).catch(() => '');
|
|
568
|
+
if (!problem && !diff.trim()) problem = 'The fix agent changed nothing';
|
|
569
|
+
if (!problem && h?.testCommand) {
|
|
570
|
+
const t = await this.git.test(agentId, h.testCommand).catch((e) => ({ passed: false, output: e.message }));
|
|
571
|
+
if (!t.passed) problem = `The tests fail with the fix (${h.testCommand})${t.output ? `: ${clip(t.output.split('\n').slice(-6).join(' '), 300)}` : ''}`;
|
|
572
|
+
}
|
|
573
|
+
let check = null;
|
|
574
|
+
// With the judge off (Settings), the tests decide alone.
|
|
575
|
+
if (!problem && this.judge && this.judge.enabled !== false) {
|
|
576
|
+
check = await this.judge.ask(`fix:${f.id}`, agent, fixCheckPrompt(f, diff), (d) => typeof d.ok === 'boolean').catch(() => null);
|
|
577
|
+
if (!check) problem = "The judge couldn't review the change";
|
|
578
|
+
else if (!(check.ok && check.confidence >= KEEP_AT)) problem = `The judge didn't accept the change: ${clip(check.reason, 400) || 'no reason given'}`;
|
|
579
|
+
}
|
|
580
|
+
if (!problem) {
|
|
581
|
+
const title = `Fix: ${f.title}`.slice(0, 100);
|
|
582
|
+
try {
|
|
583
|
+
await this.git.commit(agentId, title).catch((e) => {
|
|
584
|
+
if (!/nothing to commit/i.test(e.message)) throw e;
|
|
585
|
+
});
|
|
586
|
+
const pr = await this.git.pr(agentId, { title, body: fixPrBody(f, report, check, h?.testCommand ?? null), draft: true });
|
|
587
|
+
f.status = 'pr';
|
|
588
|
+
f.prUrl = pr.url ?? null;
|
|
589
|
+
f.auto = { ...f.auto, state: 'pr', doneAt: now(), check: check ? { confidence: check.confidence, reason: clip(check.reason, 600) } : null };
|
|
590
|
+
this.log(`bughunt: "${f.title}": draft pull request ${f.prUrl ?? '(no link)'}`);
|
|
591
|
+
} catch (e) {
|
|
592
|
+
problem = `Fixed, but the pull request couldn't be opened: ${e.message}`;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
if (problem) {
|
|
596
|
+
f.status = 'open';
|
|
597
|
+
f.auto = { ...f.auto, state: 'failed', doneAt: now(), reason: clip(problem, 600) };
|
|
598
|
+
this.log(`bughunt: "${f.title}": automatic fix didn't hold up: ${problem}`);
|
|
599
|
+
if (h?.fileIssues && !f.issueUrl) {
|
|
600
|
+
try {
|
|
601
|
+
f.issueUrl = await this.git.fileIssue(f.project, { title: f.title, body: `${findingMarkdown(f)}\n\n_An automatic fix was tried and didn't hold up: ${clip(problem, 400)}_` });
|
|
602
|
+
if (f.issueUrl) f.status = 'filed';
|
|
603
|
+
} catch (e) {
|
|
604
|
+
f.auto.issueError = clip(e.message, 300);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
this.store.save();
|
|
609
|
+
try {
|
|
610
|
+
this.manager.stop(agentId);
|
|
611
|
+
} catch {}
|
|
612
|
+
return { status: f.status, problem: problem ?? null, prUrl: f.prUrl ?? null };
|
|
613
|
+
} finally {
|
|
614
|
+
this.settling.delete(agentId);
|
|
380
615
|
}
|
|
381
616
|
}
|
|
382
617
|
|
|
@@ -400,9 +635,9 @@ export class BugHunts {
|
|
|
400
635
|
this.timer.unref?.();
|
|
401
636
|
}
|
|
402
637
|
|
|
403
|
-
/** Your decision on findings: open, notbug, snoozed (until a time), filed. */
|
|
638
|
+
/** Your decision on findings: open, notbug, snoozed (until a time), filed, done (its fix looked at). */
|
|
404
639
|
set(ids = [], status, { until = null } = {}) {
|
|
405
|
-
if (!['open', 'notbug', 'snoozed', 'filed'].includes(status)) throw err(400, 'The decision is open, notbug, snoozed or
|
|
640
|
+
if (!['open', 'notbug', 'snoozed', 'filed', 'done', 'pr'].includes(status)) throw err(400, 'The decision is open, notbug, snoozed, filed or done');
|
|
406
641
|
let snoozeUntil = null;
|
|
407
642
|
if (status === 'snoozed') {
|
|
408
643
|
const t = Date.parse(until ?? '');
|
|
@@ -412,7 +647,8 @@ export class BugHunts {
|
|
|
412
647
|
const set = [];
|
|
413
648
|
for (const id of new Set(ids)) {
|
|
414
649
|
const f = this.findings.find((x) => x.id === id);
|
|
415
|
-
|
|
650
|
+
// Back to its draft pull request (Undo) only when it has one.
|
|
651
|
+
if (!f || (status === 'pr' && !f.prUrl)) continue;
|
|
416
652
|
f.prev = f.status;
|
|
417
653
|
f.status = status;
|
|
418
654
|
f.snoozeUntil = snoozeUntil;
|
package/src/manager.js
CHANGED
|
@@ -111,7 +111,7 @@ import { assignedIssues, issueFields, issueSummary, jiraProblem, leadingIssue, l
|
|
|
111
111
|
import { issueRows } from './issues.js';
|
|
112
112
|
import { designRows } from './designs.js';
|
|
113
113
|
import { reviewPath, reviewerPrompt } from './reviews.js';
|
|
114
|
-
import { findingsPath, hunterPrompt } from './bughunt.js';
|
|
114
|
+
import { findingsPath, fixPath, fixerPrompt, hunterPrompt } from './bughunt.js';
|
|
115
115
|
import { reminderFor, reminderSettings } from './reminders.js';
|
|
116
116
|
import { combine, facts as scoreFacts, improveMessage, scorecardMarkdown, scorecardPrompt } from './scorecard.js';
|
|
117
117
|
import { CONTAINER_ENGINES, claudeToken, containerName, containerRunning, engineMounts, gitCommonDir, removeContainer, runArgs, stopContainer } from './container.js';
|
|
@@ -398,7 +398,7 @@ export class AgentManager extends EventEmitter {
|
|
|
398
398
|
};
|
|
399
399
|
// A recent agent gone quiet: follow up on it, or close its finished session (reminders.js).
|
|
400
400
|
// A bug hunt's work goes to the Bugs list, not a follow-up.
|
|
401
|
-
v.followUp = agent.hunting ? null : reminderFor(v, reminderSettings(this.config));
|
|
401
|
+
v.followUp = agent.hunting || agent.fixing ? null : reminderFor(v, reminderSettings(this.config));
|
|
402
402
|
return v;
|
|
403
403
|
}
|
|
404
404
|
|
|
@@ -627,6 +627,7 @@ export class AgentManager extends EventEmitter {
|
|
|
627
627
|
builds,
|
|
628
628
|
reviewing,
|
|
629
629
|
hunting,
|
|
630
|
+
fixing,
|
|
630
631
|
}) {
|
|
631
632
|
intent = (intent ?? '').trim();
|
|
632
633
|
const staged = stagedFiles(attachments);
|
|
@@ -685,6 +686,8 @@ export class AgentManager extends EventEmitter {
|
|
|
685
686
|
...(!general && reviewing ? { reviewing } : {}),
|
|
686
687
|
// Hunts for bugs, read-only (bughunt.js): { huntId, path, focus, kinds, since, covered }.
|
|
687
688
|
...(!general && hunting ? { hunting } : {}),
|
|
689
|
+
// Fixes a hunt's finding without you (bughunt.js): { findingId, testCommand }.
|
|
690
|
+
...(!general && fixing ? { fixing } : {}),
|
|
688
691
|
name: name?.trim() || jiraKey || slug,
|
|
689
692
|
slug,
|
|
690
693
|
intent,
|
|
@@ -1236,6 +1239,12 @@ export class AgentManager extends EventEmitter {
|
|
|
1236
1239
|
writableDir ??= path.dirname(file);
|
|
1237
1240
|
prompts.push(hunterPrompt(file, agent.hunting));
|
|
1238
1241
|
}
|
|
1242
|
+
if (agent.fixing && task) {
|
|
1243
|
+
fs.mkdirSync(briefDir(agent.id), { recursive: true });
|
|
1244
|
+
const file = path.join(fs.realpathSync(briefDir(agent.id)), path.basename(fixPath(agent.id)));
|
|
1245
|
+
writableDir ??= path.dirname(file);
|
|
1246
|
+
prompts.push(fixerPrompt(file, agent.fixing));
|
|
1247
|
+
}
|
|
1239
1248
|
if (planning) prompts.push(planningPrompt(agent));
|
|
1240
1249
|
// What earlier agents learned in this repo, and the one command to add to it.
|
|
1241
1250
|
let allowedTools = null;
|
package/src/server.js
CHANGED
|
@@ -52,8 +52,9 @@ import { Value, valueSlack } from './value.js';
|
|
|
52
52
|
import { Store } from './store.js';
|
|
53
53
|
import { about, latestRelease } from './about.js';
|
|
54
54
|
import { Support } from './support.js';
|
|
55
|
-
import { leadingJiraKey } from './tracker.js';
|
|
55
|
+
import { ghBin, leadingJiraKey } from './tracker.js';
|
|
56
56
|
import { BugHunts } from './bughunt.js';
|
|
57
|
+
import * as git from './git.js';
|
|
57
58
|
|
|
58
59
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
59
60
|
const require = createRequire(import.meta.url);
|
|
@@ -100,7 +101,44 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
|
|
|
100
101
|
const myActions = new MyActions({ store, manager });
|
|
101
102
|
const reviews = new Reviews({ manager, store, log: (m) => console.log(`[agentmgr] ${m}`) });
|
|
102
103
|
// Bug hunts: the judge checks each finding when it's on (else only failing tests are kept).
|
|
103
|
-
|
|
104
|
+
// Fixing automatically: the change, the tests, a commit and a draft pull request, or an issue.
|
|
105
|
+
const huntGit = {
|
|
106
|
+
diff: async (id) => {
|
|
107
|
+
const a = manager.mustGet(id);
|
|
108
|
+
const base = await review.base(a);
|
|
109
|
+
return base ? git.fullDiff(a.workdir, base.sha) : '';
|
|
110
|
+
},
|
|
111
|
+
commit: (id, message) => review.commit(id, { message }),
|
|
112
|
+
pr: (id, opts) => review.pr(id, opts),
|
|
113
|
+
test: (id, command) => runCommand(manager.mustGet(id), command),
|
|
114
|
+
fileIssue: async (project, { title, body }) => {
|
|
115
|
+
const p = manager.resolveProject(project);
|
|
116
|
+
const slug = /github\.com[/:]([\w.-]+\/[\w.-]+?)(?:\.git)?\/?$/.exec(p?.repo ?? '')?.[1];
|
|
117
|
+
if (!slug && !p?.dir) throw new Error('The project has no GitHub repository to file in');
|
|
118
|
+
const out = await git.run(ghBin(), ['issue', 'create', ...(slug ? ['-R', slug] : []), '--title', title, '--body', body, '--label', 'bug'], { cwd: p?.dir ?? undefined, timeout: 60_000 }).catch((e) =>
|
|
119
|
+
// A repository without a "bug" label: file it without one.
|
|
120
|
+
/label/i.test(e.message) ? git.run(ghBin(), ['issue', 'create', ...(slug ? ['-R', slug] : []), '--title', title, '--body', body], { cwd: p?.dir ?? undefined, timeout: 60_000 }) : Promise.reject(e),
|
|
121
|
+
);
|
|
122
|
+
return /https:\/\/\S+\/issues\/\d+/.exec(out)?.[0] ?? null;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
/** A shell command in an agent's folder: { passed, output } (the last lines), killed after 15 minutes. */
|
|
126
|
+
const runCommand = (agent, command) =>
|
|
127
|
+
new Promise((resolve) => {
|
|
128
|
+
const child = spawn(process.env.SHELL || '/bin/sh', ['-lc', command], { cwd: agent.workdir, env: manager.childEnv(agent), detached: true });
|
|
129
|
+
let out = '';
|
|
130
|
+
const keep = (d) => (out = (out + d).slice(-4000));
|
|
131
|
+
child.stdout.on('data', keep);
|
|
132
|
+
child.stderr.on('data', keep);
|
|
133
|
+
const timer = setTimeout(() => {
|
|
134
|
+
try {
|
|
135
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
136
|
+
} catch {}
|
|
137
|
+
}, 15 * 60_000);
|
|
138
|
+
child.on('error', (e) => (clearTimeout(timer), resolve({ passed: false, output: e.message })));
|
|
139
|
+
child.on('close', (code) => (clearTimeout(timer), resolve({ passed: code === 0, output: out })));
|
|
140
|
+
});
|
|
141
|
+
const hunts = new BugHunts({ manager, store, judge: manager.judge, git: huntGit, log: (m) => console.log(`[agentmgr] ${m}`) });
|
|
104
142
|
hunts.startTimer();
|
|
105
143
|
const races = new Races({ manager, store });
|
|
106
144
|
const review = new Review({ manager });
|
|
@@ -936,7 +974,7 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
|
|
|
936
974
|
f.slack || f.gemini ? got('actions', () => myActions.rows()) : [],
|
|
937
975
|
got('reviews', () => reviews.rows()),
|
|
938
976
|
]);
|
|
939
|
-
const findings = hunts.list().findings.filter((x) => x.status === 'open');
|
|
977
|
+
const findings = hunts.list().findings.filter((x) => x.status === 'open' || x.status === 'pr');
|
|
940
978
|
const items = todayItems({ inbox, issues, actions, reviews: prs, findings });
|
|
941
979
|
return { items, aside: todayAside({ issues, actions }), speech: todaySpeech(items), features: f, errors };
|
|
942
980
|
}));
|
package/src/today.js
CHANGED
|
@@ -111,8 +111,14 @@ export function todayItems({ inbox = [], issues = [], actions = [], reviews = []
|
|
|
111
111
|
}
|
|
112
112
|
// Bugs a hunt found and the check confirmed: the serious ones (the rest wait in the Bugs list).
|
|
113
113
|
for (const f of findings) {
|
|
114
|
+
// Fixed without you: a draft pull request to look over.
|
|
115
|
+
if (f.status === 'pr') {
|
|
116
|
+
items.push({ id: `bug:${f.id}`, kind: 'bug-pr', label: 'Fix ready', title: f.title, why: `Fixed automatically (${f.severity}): a draft pull request; its test failed before and passes now${f.auto?.check ? ', and the judge reviewed it' : ''}`, score: 34, at: f.auto?.doneAt ?? f.at ?? null, findingId: f.id, url: f.prUrl ?? null });
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
114
119
|
if (f.status !== 'open' || !['critical', 'high'].includes(f.severity)) continue;
|
|
115
|
-
|
|
120
|
+
const failed = f.auto?.state === 'failed' ? ` · the automatic fix didn't hold up: ${f.auto.reason}` : '';
|
|
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 });
|
|
116
122
|
}
|
|
117
123
|
return items.sort((x, y) => x.score - y.score || String(y.at ?? '').localeCompare(String(x.at ?? '')));
|
|
118
124
|
}
|