ai-agentmanager 1.33.0 → 1.35.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/land.js +34 -6
- package/public/sure.js +21 -0
- package/src/eval.js +6 -2
- package/src/landing.js +120 -9
- package/src/server.js +5 -0
- package/src/tracker.js +13 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.35.0 (2026-11-09)
|
|
4
|
+
|
|
5
|
+
- **Flaky CI is caught before it reaches the agent.** When GitHub Actions checks fail on an agent's pull request, the failed jobs are run once more on the same commit (`gh run rerun --failed`) before the agent is told. If they pass, the checks are marked **Flaky** on the pull request's row in the Land tab and nothing is sent; if they fail again, the agent is told, and that it failed twice. Checks from other CI systems, and a re-run GitHub refuses, go to the agent straight away as before. Once per commit; turn it off in the Land tab's settings.
|
|
6
|
+
|
|
7
|
+
## 1.34.0 (2026-11-08)
|
|
8
|
+
|
|
9
|
+
- **Merge on the Eval.** A pull request is *sure to merge* when its agent's Eval is 100%, the app's own test run passed on the very commit the pull request is at with nothing left uncommitted, a reviewer approved it, and GitHub has it ready. The Land tab lists these first, marked **Sure to merge** with the Eval's percentage; a ready pull request that isn't sure says why (for example "The tests ran on a different commit than the pull request is at"). Turn on **Merge on the Eval** in the Land tab's settings and these merge on their own: each commit is tried once, your policies and branch protection still apply, and a merge that fails says why on the pull request's row. Off by default; the approval requirement can be turned off.
|
|
10
|
+
|
|
3
11
|
## 1.33.0 (2026-11-08)
|
|
4
12
|
|
|
5
13
|
- **Eval for each Jira change, with a confidence.** When an agent on a Jira issue says it's done, the app runs the project's tests again itself, on the change as it is (the test command is found in the project's files, or set once per project), and works out an *Eval* from evidence, not from the agent's word. It covers:
|
package/package.json
CHANGED
package/public/land.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// Land tab: every agent's open pull request, grouped by what it needs to get merged, with
|
|
2
|
-
// Review, Update, Ask to fix and Merge.
|
|
2
|
+
// Review, Update, Ask to fix and Merge. Ones whose Eval is 100% on their latest commit come first.
|
|
3
|
+
// Settings for sending failures back to agents, and for merging on the Eval, at the bottom.
|
|
3
4
|
|
|
4
5
|
import { listenHtml } from './speak.js';
|
|
6
|
+
import { evalChip } from './eval.js';
|
|
7
|
+
import { sureToMerge } from './sure.js';
|
|
5
8
|
const SHORT = { ready: 'ready', fix: 'to fix', behind: 'behind', waiting: 'waiting', draft: 'draft' };
|
|
6
9
|
const GROUPS = [
|
|
7
10
|
['ready', 'Ready to merge'],
|
|
@@ -35,10 +38,10 @@ export function initLand({ api, esc, toast, agents, $, scoreBadge = () => '', se
|
|
|
35
38
|
for (const a of agents.values()) {
|
|
36
39
|
for (const pr of a.prs ?? []) {
|
|
37
40
|
if (pr.state !== 'OPEN' || pr.source === 'mentioned') continue;
|
|
38
|
-
out.push({ a, pr, land: pr.land ?? 'waiting' });
|
|
41
|
+
out.push({ a, pr, land: pr.land ?? 'waiting', sure: sureToMerge(a, pr, { needApproval: settings?.sureNeedsApproval ?? true }) });
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
|
-
return out.sort((x, y) => (x.a.priority ?? 2) - (y.a.priority ?? 2));
|
|
44
|
+
return out.sort((x, y) => Number(y.sure.sure) - Number(x.sure.sure) || (x.a.priority ?? 2) - (y.a.priority ?? 2));
|
|
42
45
|
};
|
|
43
46
|
|
|
44
47
|
// Review comments sent to the agent so far, and when last.
|
|
@@ -47,13 +50,32 @@ export function initLand({ api, esc, toast, agents, $, scoreBadge = () => '', se
|
|
|
47
50
|
return ` <span class="hint" title="Last sent ${esc(new Date(c.lastAt).toLocaleString())}">${c.count} review comment${c.count === 1 ? '' : 's'} sent</span>`;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
// Failed checks being run again before the agent hears of them, and checks that passed on a re-run.
|
|
54
|
+
function rerunHint(a, pr) {
|
|
55
|
+
const recs = Object.entries(a.landing?.reruns ?? {}).filter(([k]) => k.startsWith(`${pr.url}@`)).map(([, v]) => v);
|
|
56
|
+
const now = a.landing?.reruns?.[`${pr.url}@${pr.head}`];
|
|
57
|
+
const flaky = [...new Set(recs.filter((r) => r.result === 'passed').flatMap((r) => r.flaky ?? []))];
|
|
58
|
+
let out = '';
|
|
59
|
+
if (now && !now.result && !now.error) out += ` <span class="hint" title="The failed GitHub Actions jobs run once more before the agent is told">Re-running ${esc((now.checks ?? []).join(', ') || 'failed checks')}</span>`;
|
|
60
|
+
if (flaky.length) out += ` <span class="hint" title="Failed, then passed when run again on the same commit">Flaky: ${esc(flaky.join(', '))}</span>`;
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Why a ready pull request isn't sure, or why merging it on its own didn't work.
|
|
65
|
+
function sureHint(a, pr, land, sure) {
|
|
66
|
+
const tried = a.landing?.sure?.[`${pr.url}@${pr.head}`];
|
|
67
|
+
if (tried?.error) return ` <span class="hint fail" title="${esc(tried.error)}">Couldn't merge on its own</span>`;
|
|
68
|
+
if (land === 'ready' && !sure.sure && a.eval?.items) return ` <span class="hint" title="Why it isn't merged on its Eval">${esc(sure.why)}</span>`;
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function rowHtml({ a, pr, land, sure }) {
|
|
51
73
|
const canFix = land === 'fix' || land === 'behind';
|
|
52
74
|
return `<li class="agent land-row" data-agent="${a.id}" data-url="${esc(pr.url)}">
|
|
53
75
|
<div class="line1"><span class="prio p${a.priority ?? 2}">P${a.priority ?? 2}</span>
|
|
54
76
|
<a class="name" href="${esc(pr.url)}" target="_blank" rel="noopener" title="${esc(pr.title ?? pr.url)}">#${esc(pr.number ?? '')} ${esc(pr.title ?? pr.url)}</a></div>
|
|
55
|
-
<div class="line2"><button class="link" data-land="goto">${esc(a.name)}</button>${a.runtime?.busy ? ' <span class="hint">working</span>' : ''}${commentsHint(a.landing?.comments?.[pr.url])}</div>
|
|
56
|
-
<div class="land-chips">${scoreBadge(a.docs?.scorecard, esc)} ${prChips(pr, esc)}</div>
|
|
77
|
+
<div class="line2"><button class="link" data-land="goto">${esc(a.name)}</button>${a.runtime?.busy ? ' <span class="hint">working</span>' : ''}${commentsHint(a.landing?.comments?.[pr.url])}${sureHint(a, pr, land, sure)}${rerunHint(a, pr)}</div>
|
|
78
|
+
<div class="land-chips">${scoreBadge(a.docs?.scorecard, esc)} ${evalChip(a.eval, esc)} ${sure.sure ? `<span class="tag open" title="${esc(sure.why)}">Sure to merge</span>` : ''} ${prChips(pr, esc)}</div>
|
|
57
79
|
<div class="bl-actions">
|
|
58
80
|
<button class="small" data-land="review" title="Its diff, line comments for the agent, commit and push">Review</button>
|
|
59
81
|
${listenHtml(`prvoice:${a.id}`, { title: 'Explain the review aloud: the PR, its checks, the AI review, the riskiest changes and what is left', label: 'Explain' })}
|
|
@@ -86,11 +108,17 @@ export function initLand({ api, esc, toast, agents, $, scoreBadge = () => '', se
|
|
|
86
108
|
: '<p class="hint land-empty">No open pull requests from agents. Open one from <b>Review changes</b> on an agent, or let the agent open it.</p>'}
|
|
87
109
|
${s ? `<details class="land-settings"><summary>When checks fail or reviewers comment</summary>
|
|
88
110
|
<label class="check"><input type="checkbox" data-set="fixChecks" ${s.fixChecks ? 'checked' : ''}> Send failing checks to the agent</label>
|
|
111
|
+
<label class="check"><input type="checkbox" data-set="rerunFailed" ${s.rerunFailed ? 'checked' : ''}> First run failed GitHub Actions jobs once more on the same commit: one that passes then is marked flaky and not sent</label>
|
|
89
112
|
<label class="check"><input type="checkbox" data-set="fixReviews" ${s.fixReviews ? 'checked' : ''}> Send requested changes to the agent</label>
|
|
90
113
|
<label class="check"><input type="checkbox" data-set="fixComments" ${s.fixComments ? 'checked' : ''}> Send new review comments to the agent while the pull request is open (from the repo's members and review bots)</label>
|
|
91
114
|
<label>At most <input type="number" min="0" max="20" data-set="maxFixes" value="${s.maxFixes}"> times per pull request</label>
|
|
92
115
|
<label>Merge with <select data-set="mergeMethod">${['squash', 'merge', 'rebase'].map((m) => `<option ${m === s.mergeMethod ? 'selected' : ''}>${m}</option>`).join('')}</select></label>
|
|
93
116
|
<label class="check"><input type="checkbox" data-set="deleteBranch" ${s.deleteBranch ? 'checked' : ''}> Delete the branch on GitHub after merging</label>
|
|
117
|
+
</details>
|
|
118
|
+
<details class="land-settings"><summary>Merge on the Eval</summary>
|
|
119
|
+
<label class="check"><input type="checkbox" data-set="mergeWhenSure" ${s.mergeWhenSure ? 'checked' : ''}> Merge a pull request on its own when its Eval is 100%, the app's own test run passed on the commit the pull request is at, and GitHub has it ready</label>
|
|
120
|
+
<label class="check"><input type="checkbox" data-set="sureNeedsApproval" ${s.sureNeedsApproval ? 'checked' : ''}> Only once a reviewer has approved it</label>
|
|
121
|
+
<p class="hint">Each commit is tried once, and your policies and branch protection still apply. When this is off, these pull requests are only listed first, marked <b>Sure to merge</b>.</p>
|
|
94
122
|
</details>` : ''}`;
|
|
95
123
|
}
|
|
96
124
|
|
package/public/sure.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Sure to merge: a pull request whose agent's Eval backs it all the way. The daemon merges on it
|
|
2
|
+
// (when that is turned on) and the Land tab lists these first, so both use this one rule.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Whether a pull request can be merged on the strength of its agent's Eval: { sure, why }. Sure
|
|
6
|
+
* means 100%, with the tests run by the app on the very commit the PR is at and nothing left
|
|
7
|
+
* uncommitted, a reviewer's approval (unless that's turned off), and GitHub ready to merge it.
|
|
8
|
+
*/
|
|
9
|
+
export function sureToMerge(agent, pr, { needApproval = true, land = pr?.land } = {}) {
|
|
10
|
+
const ev = agent?.eval;
|
|
11
|
+
const no = (why) => ({ sure: false, why });
|
|
12
|
+
if (!ev?.items) return no('No Eval yet');
|
|
13
|
+
if (ev.rerun?.running) return no('Its tests are running');
|
|
14
|
+
if (ev.confidence !== 100) return no(`The Eval is ${ev.confidence}%`);
|
|
15
|
+
if (!ev.rerun?.passed) return no("The app's own test run didn't pass");
|
|
16
|
+
if (!pr?.head || ev.rerun.head !== pr.head) return no('The tests ran on a different commit than the pull request is at');
|
|
17
|
+
if (ev.rerun.clean === false) return no('There were uncommitted changes when the tests ran');
|
|
18
|
+
if (needApproval && pr.review !== 'APPROVED') return no('No reviewer has approved it');
|
|
19
|
+
if (land !== 'ready') return no(`GitHub doesn't have it ready to merge (${land ?? 'unknown'})`);
|
|
20
|
+
return { sure: true, why: needApproval ? '100% on its latest commit, approved and ready' : '100% on its latest commit and ready' };
|
|
21
|
+
}
|
package/src/eval.js
CHANGED
|
@@ -264,11 +264,13 @@ export class Evals {
|
|
|
264
264
|
* `state(agent)` → a hash of its code as it is; `changes(agent)` → { files: [{ path }] };
|
|
265
265
|
* `transcript(agent)` → its session's text (Claude Code), or null when it can't be read.
|
|
266
266
|
*/
|
|
267
|
-
constructor({ manager, store, run, state, changes = async () => ({ files: [] }), transcript, benches = null, log = () => {} }) {
|
|
267
|
+
constructor({ manager, store, run, state, commit = async () => null, changes = async () => ({ files: [] }), transcript, benches = null, log = () => {} }) {
|
|
268
268
|
this.manager = manager;
|
|
269
269
|
this.store = store;
|
|
270
270
|
this.run = run;
|
|
271
271
|
this.state = state;
|
|
272
|
+
// The commit the tests ran on, and whether nothing was left uncommitted: merging relies on it.
|
|
273
|
+
this.commit = commit;
|
|
272
274
|
this.changes = changes;
|
|
273
275
|
this.transcript = transcript;
|
|
274
276
|
this.benches = benches;
|
|
@@ -334,8 +336,9 @@ export class Evals {
|
|
|
334
336
|
try {
|
|
335
337
|
const started = Date.now();
|
|
336
338
|
const st = await this.state(agent).catch(() => null);
|
|
339
|
+
const at = await this.commit(agent).catch(() => null);
|
|
337
340
|
const res = await this.run(agent, command);
|
|
338
|
-
rerun = { command, passed: Boolean(res.passed), counts: countsOf(res.output), tail: clip(String(res.output ?? '').split('\n').slice(-15).join('\n'), 2000), timedOut: Boolean(res.timedOut), state: st, at: now(), ms: Date.now() - started };
|
|
341
|
+
rerun = { command, passed: Boolean(res.passed), counts: countsOf(res.output), tail: clip(String(res.output ?? '').split('\n').slice(-15).join('\n'), 2000), timedOut: Boolean(res.timedOut), state: st, head: at?.head ?? null, clean: at?.clean ?? null, at: now(), ms: Date.now() - started };
|
|
339
342
|
} catch (e) {
|
|
340
343
|
rerun = { command, passed: false, counts: null, tail: clip(String(e?.message ?? e), 2000), timedOut: false, state: null, at: now(), ms: 0 };
|
|
341
344
|
} finally {
|
|
@@ -389,6 +392,7 @@ export class Evals {
|
|
|
389
392
|
// A test run ended while this was worked out: the one it ended with has the newer answer.
|
|
390
393
|
if (!rerun && (cur.eval?.rerun?.at ?? null) !== (agent.eval?.rerun?.at ?? null)) return this.view(id);
|
|
391
394
|
this.manager.patch(id, { eval: { ...ev, rerun: rerun ?? cur.eval?.rerun ?? null, postedTo: cur.eval?.postedTo ?? null } });
|
|
395
|
+
this.manager.emit?.('evaluated', this.store.get(id));
|
|
392
396
|
return this.view(id);
|
|
393
397
|
}
|
|
394
398
|
|
package/src/landing.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
// Landing: getting agents' pull requests merged. Failing checks and requested changes are sent
|
|
2
2
|
// back to the agent that owns the PR (a few times per PR at most), new review comments are sent
|
|
3
3
|
// to it for as long as the PR is open, a branch that fell behind is brought up to date with the
|
|
4
|
-
// branch it targets, and ready PRs are merged with one click.
|
|
4
|
+
// branch it targets, and ready PRs are merged with one click. A PR whose Eval is 100% on its latest
|
|
5
|
+
// commit is "sure": listed first, and merged on its own when that is turned on. Failed GitHub Actions
|
|
6
|
+
// checks are re-run once per commit before the agent hears of them: a check that passes then is flaky.
|
|
5
7
|
import os from 'node:os';
|
|
6
8
|
import * as git from './git.js';
|
|
7
9
|
import { NO_REPO } from './manager.js';
|
|
8
|
-
import { AGENT_MARK, ghBin, newFeedback, prFeedback } from './tracker.js';
|
|
10
|
+
import { AGENT_MARK, ghBin, landState, newFeedback, prFeedback } from './tracker.js';
|
|
9
11
|
import { triggerSettings } from './triggers.js';
|
|
10
12
|
import { parseBaseRef } from './review.js';
|
|
13
|
+
import { sureToMerge as sureOf } from '../public/sure.js';
|
|
11
14
|
|
|
12
15
|
export const MERGE_METHODS = ['squash', 'merge', 'rebase'];
|
|
13
|
-
export const LANDING_DEFAULTS = { fixChecks: true, fixReviews: true, fixComments: true, maxFixes: 3, mergeMethod: 'squash', deleteBranch: true };
|
|
16
|
+
export const LANDING_DEFAULTS = { fixChecks: true, fixReviews: true, fixComments: true, maxFixes: 3, mergeMethod: 'squash', deleteBranch: true, mergeWhenSure: false, sureNeedsApproval: true, rerunFailed: true };
|
|
14
17
|
// Rounds of review comments sent per PR: a stop in case an agent's own replies keep coming back.
|
|
15
18
|
const COMMENT_ROUNDS = 30;
|
|
16
19
|
const QUOTE_MAX = 1500;
|
|
17
20
|
const MESSAGE_MAX = 9000;
|
|
18
21
|
const LAND_ORDER = ['ready', 'fix', 'behind', 'waiting', 'draft'];
|
|
22
|
+
// A re-run that GitHub hasn't been seen starting by then: take the failure as it stands.
|
|
23
|
+
const RERUN_WAIT_MS = 15 * 60_000;
|
|
19
24
|
|
|
20
25
|
const err = (status, message) => Object.assign(new Error(message), { status });
|
|
21
26
|
|
|
@@ -30,13 +35,16 @@ export function landingSettings(config = {}) {
|
|
|
30
35
|
maxFixes: Number.isFinite(n) && n >= 0 ? Math.min(20, Math.floor(n)) : LANDING_DEFAULTS.maxFixes,
|
|
31
36
|
mergeMethod: MERGE_METHODS.includes(c.mergeMethod) ? c.mergeMethod : LANDING_DEFAULTS.mergeMethod,
|
|
32
37
|
deleteBranch: c.deleteBranch !== false,
|
|
38
|
+
mergeWhenSure: c.mergeWhenSure === true,
|
|
39
|
+
sureNeedsApproval: c.sureNeedsApproval !== false,
|
|
40
|
+
rerunFailed: c.rerunFailed !== false,
|
|
33
41
|
};
|
|
34
42
|
}
|
|
35
43
|
|
|
36
|
-
export function checksMessage(pr) {
|
|
44
|
+
export function checksMessage(pr, { again = false } = {}) {
|
|
37
45
|
const names = pr.checks?.failed?.length ? pr.checks.failed.join(', ') : 'some checks';
|
|
38
46
|
return [
|
|
39
|
-
`CI is failing on your pull request ${pr.url} (${names})
|
|
47
|
+
`CI is failing on your pull request ${pr.url} (${names}).${again ? ' They were run again and failed again, so this is unlikely to be a flaky test.' : ''}`,
|
|
40
48
|
`Look at the failures (\`gh pr checks ${pr.number ?? pr.url}\`, and \`gh run view <run id> --log-failed\` for the logs), fix the cause, run the relevant tests locally, then commit and push.`,
|
|
41
49
|
'If a failure is unrelated to your change (a flaky test or a broken main), say so instead of changing unrelated code.',
|
|
42
50
|
].join('\n');
|
|
@@ -84,6 +92,16 @@ export function updateMessage(base) {
|
|
|
84
92
|
return `Your branch is behind ${base}. Merge ${base} into it (git fetch, then git merge ${base}), resolve any conflicts keeping both sides' intent, run the tests, then commit and push.`;
|
|
85
93
|
}
|
|
86
94
|
|
|
95
|
+
/** gh's --repo for a pull request's URL: owner/repo, with the host when it isn't github.com. */
|
|
96
|
+
export function repoOf(url) {
|
|
97
|
+
const m = /^https?:\/\/([^/]+)\/([^/]+)\/([^/]+)\/pull\/\d+/.exec(url ?? '');
|
|
98
|
+
if (!m) return null;
|
|
99
|
+
return m[1] === 'github.com' ? `${m[2]}/${m[3]}` : `${m[1]}/${m[2]}/${m[3]}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** sureToMerge with where the pull request stands worked out here. */
|
|
103
|
+
export const sureToMerge = (agent, pr, opts = {}) => sureOf(agent, pr, { ...opts, land: landState(pr) });
|
|
104
|
+
|
|
87
105
|
export class Landing {
|
|
88
106
|
constructor({ manager, store, config = {}, log = (m) => console.log(`[agentmgr] ${m}`) }) {
|
|
89
107
|
this.manager = manager;
|
|
@@ -92,6 +110,8 @@ export class Landing {
|
|
|
92
110
|
this.log = log;
|
|
93
111
|
this.onPrs = (agent) => this.react(agent).catch((e) => this.log(`landing: ${e.message}`));
|
|
94
112
|
manager.on('prs', this.onPrs);
|
|
113
|
+
this.onEvaluated = (agent) => agent && this.mergeIfSure(agent).catch((e) => this.log(`landing: ${e.message}`));
|
|
114
|
+
manager.on('evaluated', this.onEvaluated);
|
|
95
115
|
// Running agents' PRs are refreshed by the manager; closed agents with an open PR every few minutes.
|
|
96
116
|
this.timer = setInterval(() => this.refreshClosed().catch(() => {}), (config.landingRefreshMin ?? 6) * 60_000);
|
|
97
117
|
this.timer.unref?.();
|
|
@@ -100,6 +120,7 @@ export class Landing {
|
|
|
100
120
|
close() {
|
|
101
121
|
clearInterval(this.timer);
|
|
102
122
|
this.manager.off('prs', this.onPrs);
|
|
123
|
+
this.manager.off('evaluated', this.onEvaluated);
|
|
103
124
|
}
|
|
104
125
|
|
|
105
126
|
get settings() {
|
|
@@ -109,8 +130,11 @@ export class Landing {
|
|
|
109
130
|
update(patch = {}) {
|
|
110
131
|
if (patch.mergeMethod !== undefined && !MERGE_METHODS.includes(patch.mergeMethod)) throw err(400, `mergeMethod must be one of ${MERGE_METHODS.join(', ')}`);
|
|
111
132
|
if (patch.maxFixes !== undefined && !(Number(patch.maxFixes) >= 0)) throw err(400, 'maxFixes must be 0 or more');
|
|
133
|
+
const was = this.settings.mergeWhenSure;
|
|
112
134
|
const next = landingSettings({ landing: { ...this.config.landing, ...patch } });
|
|
113
135
|
this.config.landing = next;
|
|
136
|
+
// Just turned on: what is already sure merges now, not on its next change.
|
|
137
|
+
if (next.mergeWhenSure && !was) for (const a of this.store.list()) this.mergeIfSure(a).catch((e) => this.log(`landing: ${e.message}`));
|
|
114
138
|
return next;
|
|
115
139
|
}
|
|
116
140
|
|
|
@@ -131,6 +155,7 @@ export class Landing {
|
|
|
131
155
|
for (const pr of this.openPrs(agent)) {
|
|
132
156
|
const watched = s.fixComments ? await this.sendFeedback(agent, pr) : null;
|
|
133
157
|
if (watched?.sent) sent = true;
|
|
158
|
+
if (this.trackRerun(agent, pr)) sent = true;
|
|
134
159
|
if (!pr.head || !s.maxFixes) continue;
|
|
135
160
|
const count = Object.keys(agent.landing.sent).filter((k) => k.startsWith(`${pr.url}#`)).length;
|
|
136
161
|
if (count >= s.maxFixes) continue;
|
|
@@ -142,11 +167,95 @@ export class Landing {
|
|
|
142
167
|
this.log(`landing: told ${agent.name} about ${kind} on ${pr.url}`);
|
|
143
168
|
sent = true;
|
|
144
169
|
};
|
|
145
|
-
if (s.fixChecks && pr.checks?.state === 'failed')
|
|
170
|
+
if (s.fixChecks && pr.checks?.state === 'failed') {
|
|
171
|
+
const rerun = s.rerunFailed ? await this.rerunOnce(agent, pr) : null;
|
|
172
|
+
if (rerun?.started) sent = true;
|
|
173
|
+
if (!rerun?.waiting) send('checks', checksMessage(pr, { again: Boolean(rerun?.again) }));
|
|
174
|
+
}
|
|
146
175
|
// A review requesting changes that comments are watched for was sent with them.
|
|
147
176
|
else if (s.fixReviews && pr.review === 'CHANGES_REQUESTED' && !watched?.changesRequested) send('review', reviewMessage(pr));
|
|
148
177
|
}
|
|
149
|
-
if (sent
|
|
178
|
+
if (sent && this.store.get(agent.id)) this.manager.patch(agent.id, { landing: agent.landing });
|
|
179
|
+
await this.mergeIfSure(agent);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Failed checks on this commit: re-run the failed GitHub Actions jobs once, and hold the message
|
|
184
|
+
* until they finish. { waiting } while they run, { again } when they failed again, null to tell
|
|
185
|
+
* the agent now (nothing to re-run, or the re-run couldn't start).
|
|
186
|
+
*/
|
|
187
|
+
async rerunOnce(agent, pr) {
|
|
188
|
+
const key = `${pr.url}@${pr.head}`;
|
|
189
|
+
const reruns = (agent.landing.reruns ??= {});
|
|
190
|
+
const rec = reruns[key];
|
|
191
|
+
if (!rec) {
|
|
192
|
+
const runs = pr.checks?.runs ?? [];
|
|
193
|
+
const repo = repoOf(pr.url);
|
|
194
|
+
if (!runs.length || !repo) return null;
|
|
195
|
+
reruns[key] = { at: new Date().toISOString(), runs, checks: pr.checks.failed ?? [] };
|
|
196
|
+
try {
|
|
197
|
+
for (const id of runs) await git.run(ghBin(), ['run', 'rerun', id, '--failed', '--repo', repo], { cwd: os.tmpdir(), timeout: 60_000 });
|
|
198
|
+
} catch (e) {
|
|
199
|
+
reruns[key].error = e.message.replace(/^\S+ run rerun .*? failed: /, '');
|
|
200
|
+
this.log(`landing: couldn't re-run the failed checks on ${pr.url}: ${reruns[key].error}`);
|
|
201
|
+
return { started: true };
|
|
202
|
+
}
|
|
203
|
+
this.log(`landing: re-running the failed checks on ${pr.url} once before telling ${agent.name}`);
|
|
204
|
+
return { waiting: true, started: true };
|
|
205
|
+
}
|
|
206
|
+
if (rec.error) return null;
|
|
207
|
+
if (rec.result === 'failed') return { again: true };
|
|
208
|
+
// Still the failure from before the re-run: GitHub hasn't shown it starting yet.
|
|
209
|
+
if (!rec.restarted && Date.now() - Date.parse(rec.at) < RERUN_WAIT_MS) return { waiting: true };
|
|
210
|
+
rec.result = 'failed';
|
|
211
|
+
rec.doneAt = new Date().toISOString();
|
|
212
|
+
return { again: true };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** A re-run under way: note when it starts, and a pass as flaky checks. True when something changed. */
|
|
216
|
+
trackRerun(agent, pr) {
|
|
217
|
+
const rec = agent.landing.reruns?.[`${pr.url}@${pr.head}`];
|
|
218
|
+
if (!rec || rec.result || rec.error) return false;
|
|
219
|
+
const state = pr.checks?.state;
|
|
220
|
+
if (state === 'running' && !rec.restarted) {
|
|
221
|
+
rec.restarted = true;
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
if (state === 'passed') {
|
|
225
|
+
Object.assign(rec, { result: 'passed', flaky: rec.checks, doneAt: new Date().toISOString() });
|
|
226
|
+
this.log(`landing: ${rec.checks.join(', ') || 'checks'} on ${pr.url} passed on a re-run: flaky`);
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Merge the agent's pull requests that are sure to merge, when that is turned on. Tried once per
|
|
234
|
+
* commit: a failure (a policy, branch protection) is kept and shown, not retried until it changes.
|
|
235
|
+
*/
|
|
236
|
+
async mergeIfSure(agent) {
|
|
237
|
+
const s = this.settings;
|
|
238
|
+
if (!s.mergeWhenSure || NO_REPO.has(agent.kind)) return;
|
|
239
|
+
for (const pr of this.openPrs(agent)) {
|
|
240
|
+
if (!sureToMerge(agent, pr, { needApproval: s.sureNeedsApproval }).sure) continue;
|
|
241
|
+
const cur = this.store.get(agent.id);
|
|
242
|
+
if (!cur) return;
|
|
243
|
+
const tried = ((cur.landing ??= { sent: {} }).sure ??= {});
|
|
244
|
+
const key = `${pr.url}@${pr.head}`;
|
|
245
|
+
if (tried[key]) continue;
|
|
246
|
+
tried[key] = { at: new Date().toISOString() };
|
|
247
|
+
this.store.save();
|
|
248
|
+
try {
|
|
249
|
+
await this.merge(agent.id, { url: pr.url });
|
|
250
|
+
tried[key].merged = true;
|
|
251
|
+
this.log(`landing: merged ${pr.url}: its Eval is 100% on its latest commit`);
|
|
252
|
+
} catch (e) {
|
|
253
|
+
tried[key].error = e.message;
|
|
254
|
+
this.log(`landing: couldn't merge ${pr.url} on its Eval: ${e.message}`);
|
|
255
|
+
}
|
|
256
|
+
// Through patch, so open screens show the merge or why it didn't happen.
|
|
257
|
+
if (this.store.get(agent.id)) this.manager.patch(agent.id, { landing: this.store.get(agent.id).landing });
|
|
258
|
+
}
|
|
150
259
|
}
|
|
151
260
|
|
|
152
261
|
/**
|
|
@@ -198,11 +307,13 @@ export class Landing {
|
|
|
198
307
|
for (const pr of view.prs.filter((p) => p.state === 'OPEN' && p.source !== 'mentioned')) {
|
|
199
308
|
const fixes = Object.keys(agent.landing?.sent ?? {}).filter((k) => k.startsWith(`${pr.url}#`)).length;
|
|
200
309
|
const comments = agent.landing?.comments?.[pr.url]?.count ?? 0;
|
|
201
|
-
|
|
310
|
+
const sure = sureToMerge(agent, pr, { needApproval: this.settings.sureNeedsApproval });
|
|
311
|
+
const tried = agent.landing?.sure?.[`${pr.url}@${pr.head}`] ?? null;
|
|
312
|
+
rows.push({ agent: { id: agent.id, name: agent.name, priority: view.priority, busy: view.runtime.busy, running: view.runtime.running }, pr, land: pr.land ?? 'waiting', fixes, comments, confidence: agent.eval?.confidence ?? null, sure, tried });
|
|
202
313
|
}
|
|
203
314
|
}
|
|
204
315
|
const rank = (r) => (LAND_ORDER.includes(r.land) ? LAND_ORDER.indexOf(r.land) : LAND_ORDER.length);
|
|
205
|
-
return { settings: this.settings, rows: rows.sort((a, b) => rank(a) - rank(b) || a.agent.priority - b.agent.priority) };
|
|
316
|
+
return { settings: this.settings, rows: rows.sort((a, b) => rank(a) - rank(b) || Number(b.sure.sure) - Number(a.sure.sure) || a.agent.priority - b.agent.priority) };
|
|
206
317
|
}
|
|
207
318
|
|
|
208
319
|
agentPr(ref, url) {
|
package/src/server.js
CHANGED
|
@@ -166,6 +166,11 @@ export async function startServer({ port = PORT, host = HOST } = {}) {
|
|
|
166
166
|
const [head, status, diff] = await Promise.all([git.run('git', ['rev-parse', 'HEAD'], opts), git.run('git', ['status', '--porcelain'], opts), git.run('git', ['diff', 'HEAD'], opts)]);
|
|
167
167
|
return stateHash(head.trim(), status, diff);
|
|
168
168
|
},
|
|
169
|
+
commit: async (a) => {
|
|
170
|
+
const opts = { cwd: a.workdir, timeout: 30_000 };
|
|
171
|
+
const [head, status] = await Promise.all([git.run('git', ['rev-parse', 'HEAD'], opts), git.run('git', ['status', '--porcelain'], opts)]);
|
|
172
|
+
return { head: head.trim(), clean: !status.trim() };
|
|
173
|
+
},
|
|
169
174
|
changes: (a) => review.get(a.id),
|
|
170
175
|
// Claude Code's session: the test runs in it. Other engines keep theirs differently.
|
|
171
176
|
transcript: (a) => (engineOf(a).id === 'claude' && a.workdir ? readTail(engineOf(a).sessionFile(a.workdir, a.sessionId)) : null),
|
package/src/tracker.js
CHANGED
|
@@ -226,19 +226,28 @@ const PR_FIELDS = 'number,title,url,state,isDraft,headRefOid,reviewDecision,merg
|
|
|
226
226
|
const FAILED = new Set(['FAILURE', 'ERROR', 'TIMED_OUT', 'CANCELLED', 'ACTION_REQUIRED', 'STARTUP_FAILURE']);
|
|
227
227
|
const PASSED = new Set(['SUCCESS', 'NEUTRAL', 'SKIPPED']);
|
|
228
228
|
|
|
229
|
-
/**
|
|
229
|
+
/**
|
|
230
|
+
* gh's statusCheckRollup -> { state: passed|failed|running|none, failed: [names], running, total },
|
|
231
|
+
* plus runs: the GitHub Actions run ids of the failed checks (when there are any), to re-run them.
|
|
232
|
+
*/
|
|
230
233
|
export function checkSummary(rollup) {
|
|
231
234
|
const list = Array.isArray(rollup) ? rollup : [];
|
|
232
235
|
const failed = [];
|
|
236
|
+
const runs = new Set();
|
|
233
237
|
let running = 0;
|
|
234
238
|
for (const c of list) {
|
|
235
239
|
// Check runs have status/conclusion; commit statuses have state.
|
|
236
240
|
const result = c.conclusion || (c.status && c.status !== 'COMPLETED' ? 'PENDING' : null) || c.state || 'PENDING';
|
|
237
|
-
if (FAILED.has(result))
|
|
238
|
-
|
|
241
|
+
if (FAILED.has(result)) {
|
|
242
|
+
failed.push(c.name || c.context || 'check');
|
|
243
|
+
const run = /\/actions\/runs\/(\d+)/.exec(c.detailsUrl ?? '')?.[1];
|
|
244
|
+
if (run) runs.add(run);
|
|
245
|
+
} else if (!PASSED.has(result)) running += 1;
|
|
239
246
|
}
|
|
240
247
|
const state = !list.length ? 'none' : failed.length ? 'failed' : running ? 'running' : 'passed';
|
|
241
|
-
|
|
248
|
+
const out = { state, failed: failed.slice(0, 10), running, total: list.length };
|
|
249
|
+
if (runs.size) out.runs = [...runs].slice(0, 5);
|
|
250
|
+
return out;
|
|
242
251
|
}
|
|
243
252
|
|
|
244
253
|
/** Where a pull request stands on its way in: merged, closed, draft, fix, behind, ready or waiting. */
|