next-issue 2.21.2 → 4.0.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/README.md +90 -125
- package/dist/agent-reply.mjs +13 -0
- package/dist/agent-session.mjs +56 -0
- package/dist/agents.mjs +47 -88
- package/dist/args.mjs +26 -31
- package/dist/base-checks.mjs +37 -0
- package/dist/budget.mjs +16 -0
- package/dist/check-poll.mjs +73 -0
- package/dist/checks.mjs +67 -0
- package/dist/children.mjs +52 -0
- package/dist/cli.mjs +25 -15
- package/dist/command-records.mjs +15 -0
- package/dist/config-fields.mjs +32 -0
- package/dist/config.mjs +36 -71
- package/dist/conflict.mjs +43 -42
- package/dist/durations.mjs +37 -0
- package/dist/enter-review.mjs +13 -0
- package/dist/errors.mjs +20 -0
- package/dist/exec.mjs +71 -107
- package/dist/files.mjs +28 -0
- package/dist/fix.mjs +61 -50
- package/dist/gate.mjs +31 -43
- package/dist/gh.mjs +55 -0
- package/dist/git-commit.mjs +36 -0
- package/dist/git-land.mjs +30 -0
- package/dist/git-merge.mjs +42 -0
- package/dist/git.mjs +42 -166
- package/dist/github.mjs +31 -388
- package/dist/gitignore.mjs +13 -0
- package/dist/hand-over-comments.mjs +78 -0
- package/dist/handover.mjs +60 -107
- package/dist/implement.mjs +32 -0
- package/dist/interrupt.mjs +6 -19
- package/dist/job.mjs +28 -17
- package/dist/labels.mjs +65 -0
- package/dist/land.mjs +66 -0
- package/dist/lock.mjs +54 -0
- package/dist/logs.mjs +84 -62
- package/dist/loop.mjs +12 -37
- package/dist/observe.mjs +24 -98
- package/dist/open-job.mjs +39 -0
- package/dist/pending.mjs +46 -0
- package/dist/pipeline.mjs +34 -217
- package/dist/poll.mjs +20 -0
- package/dist/ports.mjs +18 -4
- package/dist/progress.mjs +36 -23
- package/dist/prompts.mjs +31 -36
- package/dist/protocol.mjs +17 -11
- package/dist/prune-runs.mjs +33 -0
- package/dist/pull-requests.mjs +60 -0
- package/dist/questions.mjs +45 -0
- package/dist/records.mjs +3 -0
- package/dist/render.mjs +19 -0
- package/dist/revert.mjs +27 -0
- package/dist/review.mjs +63 -83
- package/dist/run-logs.mjs +23 -0
- package/dist/run.mjs +59 -58
- package/dist/serve.mjs +46 -214
- package/dist/setup.mjs +2 -5
- package/dist/skip.mjs +54 -0
- package/dist/state.mjs +27 -39
- package/dist/summary.mjs +11 -7
- package/dist/text.mjs +15 -0
- package/dist/usage.mjs +45 -0
- package/dist/verdict.mjs +20 -13
- package/dist/watch.mjs +38 -0
- package/dist/worker-paths.mjs +16 -0
- package/dist/worker-run.mjs +56 -0
- package/dist/worker-server.mjs +56 -0
- package/dist/worktree-setup.mjs +25 -0
- package/dist/worktree.mjs +58 -0
- package/package.json +1 -1
- package/dist/merge.mjs +0 -75
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { optionalFlag } from './exec.mjs';
|
|
2
|
+
import { gh, ghJson, ghOnce, ghSucceeds, viewJson } from './gh.mjs';
|
|
3
|
+
import { pollUntil, REAL_CLOCK } from './poll.mjs';
|
|
4
|
+
export async function findPr(repo, branch) {
|
|
5
|
+
const parsed = await ghJson(repo, [
|
|
6
|
+
'pr',
|
|
7
|
+
'list',
|
|
8
|
+
'--head',
|
|
9
|
+
branch,
|
|
10
|
+
'--state',
|
|
11
|
+
'open',
|
|
12
|
+
'--json',
|
|
13
|
+
'number',
|
|
14
|
+
]);
|
|
15
|
+
return parsed[0]?.number;
|
|
16
|
+
}
|
|
17
|
+
export async function createPr(repo, branch, base, title, body, draft) {
|
|
18
|
+
const created = await ghOnce(repo, [
|
|
19
|
+
'pr',
|
|
20
|
+
'create',
|
|
21
|
+
'--head',
|
|
22
|
+
branch,
|
|
23
|
+
'--base',
|
|
24
|
+
base,
|
|
25
|
+
'--title',
|
|
26
|
+
title,
|
|
27
|
+
'--body',
|
|
28
|
+
body,
|
|
29
|
+
...optionalFlag(draft, '--draft'),
|
|
30
|
+
]);
|
|
31
|
+
const number = prNumber(created) ?? (await findPr(repo, branch));
|
|
32
|
+
if (number === undefined) {
|
|
33
|
+
throw new Error(`The pull request for ${branch} was not found after creation.`);
|
|
34
|
+
}
|
|
35
|
+
return number;
|
|
36
|
+
}
|
|
37
|
+
export function prNumber(output) {
|
|
38
|
+
const match = /\/pull\/(\d+)\b/.exec(output);
|
|
39
|
+
return match === null ? undefined : Number(match[1]);
|
|
40
|
+
}
|
|
41
|
+
export async function prField(repo, pr, field) {
|
|
42
|
+
return gh(repo, ['pr', 'view', String(pr), '--json', field, '--jq', `.${field}`]);
|
|
43
|
+
}
|
|
44
|
+
export async function markPrReady(repo, pr) {
|
|
45
|
+
return ghSucceeds(repo, ['pr', 'ready', String(pr)]);
|
|
46
|
+
}
|
|
47
|
+
export async function mergePr(repo, pr) {
|
|
48
|
+
return ghSucceeds(repo, ['pr', 'merge', String(pr), '--squash', '--delete-branch']);
|
|
49
|
+
}
|
|
50
|
+
export async function prConflicts(repo, pr, options, clock = REAL_CLOCK) {
|
|
51
|
+
const mergeable = await pollUntil(options, clock, () => prField(repo, pr, 'mergeable'), (value) => value !== 'UNKNOWN');
|
|
52
|
+
return mergeable === 'CONFLICTING';
|
|
53
|
+
}
|
|
54
|
+
export async function prMerged(repo, pr) {
|
|
55
|
+
return (await prField(repo, pr, 'state')) === 'MERGED';
|
|
56
|
+
}
|
|
57
|
+
export async function mergeCommit(repo, pr, options, clock = REAL_CLOCK) {
|
|
58
|
+
const view = await pollUntil(options, clock, () => viewJson(repo, 'pr', pr, 'state,mergeCommit'), (value) => (value.state === 'MERGED' && !!value.mergeCommit?.oid) || value.state === 'CLOSED');
|
|
59
|
+
return (view.state === 'MERGED' && view.mergeCommit?.oid) || undefined;
|
|
60
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { loadConfig } from './config.mjs';
|
|
2
|
+
import { message } from './errors.mjs';
|
|
3
|
+
import { detectRepo } from './git.mjs';
|
|
4
|
+
import { waitingQuestions } from './hand-over-comments.mjs';
|
|
5
|
+
import { PORTS } from './ports.mjs';
|
|
6
|
+
export async function listQuestions(root) {
|
|
7
|
+
const config = await loadConfig(root);
|
|
8
|
+
return waitingQuestions(await detectRepo(root, config.remote), config, PORTS);
|
|
9
|
+
}
|
|
10
|
+
async function readQuestions(list, root) {
|
|
11
|
+
try {
|
|
12
|
+
return { type: 'questions', root, questions: await list(root) };
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
return { type: 'questions-error', root, message: message(error) };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function questionsReply(delivered, socket, root, delivery, id) {
|
|
19
|
+
const seen = delivered.get(socket) ?? new Map();
|
|
20
|
+
const last = seen.get(root);
|
|
21
|
+
if (last === undefined || last.read < delivery.read) {
|
|
22
|
+
seen.set(root, delivery);
|
|
23
|
+
delivered.set(socket, seen);
|
|
24
|
+
return id === undefined ? delivery.value : { ...delivery.value, id };
|
|
25
|
+
}
|
|
26
|
+
return id === undefined ? undefined : { ...last.value, id };
|
|
27
|
+
}
|
|
28
|
+
export function questionSender(list) {
|
|
29
|
+
const reads = new Map();
|
|
30
|
+
const delivered = new WeakMap();
|
|
31
|
+
return async (root, targets, id) => {
|
|
32
|
+
const read = (reads.get(root) ?? 0) + 1;
|
|
33
|
+
reads.set(root, read);
|
|
34
|
+
const value = await readQuestions(list, root);
|
|
35
|
+
for (const socket of targets()) {
|
|
36
|
+
const reply = questionsReply(delivered, socket, root, { read, value }, id);
|
|
37
|
+
if (reply !== undefined) {
|
|
38
|
+
send(socket, reply);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function send(socket, value) {
|
|
44
|
+
socket.send(JSON.stringify(value));
|
|
45
|
+
}
|
package/dist/records.mjs
ADDED
package/dist/render.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { truncate } from './text.mjs';
|
|
2
|
+
export function render(record) {
|
|
3
|
+
const time = new Date(String(record.ts)).toTimeString().slice(0, 8);
|
|
4
|
+
const issue = record.issue === undefined ? '' : ` #${record.issue}`;
|
|
5
|
+
const extras = Object.entries(record)
|
|
6
|
+
.filter(([key]) => !['ts', 'runId', 'kind', 'issue'].includes(key))
|
|
7
|
+
.map(([key, value]) => `${key}=${short(value)}`)
|
|
8
|
+
.join(' ');
|
|
9
|
+
return `${time}${issue} ${String(record.kind)}${extras.length > 0 ? ` ${extras}` : ''}\n`;
|
|
10
|
+
}
|
|
11
|
+
function short(value) {
|
|
12
|
+
if (value === undefined || value === null) {
|
|
13
|
+
return '-';
|
|
14
|
+
}
|
|
15
|
+
if (typeof value === 'number') {
|
|
16
|
+
return Number.isInteger(value) ? String(value) : String(Number(value.toFixed(6)));
|
|
17
|
+
}
|
|
18
|
+
return truncate(String(value).replace(/\s+/g, ' '), 120, '...');
|
|
19
|
+
}
|
package/dist/revert.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { writeState } from './state.mjs';
|
|
2
|
+
export async function revertFailedFix(job) {
|
|
3
|
+
if (!job.repairing || (job.state.landed ?? []).length === 0) {
|
|
4
|
+
return '';
|
|
5
|
+
}
|
|
6
|
+
job.repairing = false;
|
|
7
|
+
return revert(job);
|
|
8
|
+
}
|
|
9
|
+
export async function revert(job) {
|
|
10
|
+
const { context, issue, log, state, branch, worktree } = job;
|
|
11
|
+
const { repo, config, ports, base } = context;
|
|
12
|
+
const shas = state.landed ?? [];
|
|
13
|
+
const pushed = await log.step('revert', { base, shas }, () => ports.revertOnBase(worktree, {
|
|
14
|
+
base,
|
|
15
|
+
remote: config.remote,
|
|
16
|
+
branch,
|
|
17
|
+
shas,
|
|
18
|
+
message: `revert: issue #${issue.number}\n\nRefs #${issue.number}`,
|
|
19
|
+
reapply: `${state.title ?? `fix: resolve issue #${issue.number}`}\n\nRefs #${issue.number}`,
|
|
20
|
+
}));
|
|
21
|
+
if (!pushed) {
|
|
22
|
+
return ` The revert of the change on ${base} failed.`;
|
|
23
|
+
}
|
|
24
|
+
state.landed = undefined;
|
|
25
|
+
await writeState(repo, state);
|
|
26
|
+
return ` The harness reverted the change on ${base}.`;
|
|
27
|
+
}
|
package/dist/review.mjs
CHANGED
|
@@ -1,104 +1,84 @@
|
|
|
1
1
|
import { REVIEWING } from './agents.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { budgetUse, spendBudget } from './budget.mjs';
|
|
3
3
|
import { fixRound } from './fix.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { capDiff, reviewPrompt } from './prompts.mjs';
|
|
4
|
+
import { escalateAndFinish } from './handover.mjs';
|
|
5
|
+
import { ROUND_CONTINUE, runRole, setStatus } from './job.mjs';
|
|
6
|
+
import { landApproved } from './land.mjs';
|
|
7
|
+
import { capDiff, history, reviewPrompt } from './prompts.mjs';
|
|
9
8
|
import { writeState } from './state.mjs';
|
|
10
9
|
import { blockingFindings, formatFindings, formatVerdict, openFindings, parseVerdict, } from './verdict.mjs';
|
|
11
10
|
export async function reviewRound(job) {
|
|
12
|
-
const { context, issue,
|
|
11
|
+
const { context, issue, state } = job;
|
|
13
12
|
const { repo, config, ports } = context;
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
return { done: true, report: await finish(job, 'needs-human', 'review budget') };
|
|
13
|
+
const exhausted = await spendBudget(job, 'reviewRounds', `The limit of ${config.maxReviewRounds} review rounds was reached.`, 'review budget');
|
|
14
|
+
if (exhausted) {
|
|
15
|
+
return exhausted;
|
|
18
16
|
}
|
|
19
|
-
state.
|
|
20
|
-
|
|
21
|
-
await
|
|
17
|
+
await setStatus(context, issue.number, state.pr, config.labels.inReview);
|
|
18
|
+
const earlier = history(state.reviewLog);
|
|
19
|
+
const verdict = parseVerdict(await runReviewer(job, earlier));
|
|
20
|
+
if (verdict === undefined) {
|
|
21
|
+
return escalateAndFinish(job, 'The reviewer gave no verdict.', 'no verdict');
|
|
22
|
+
}
|
|
23
|
+
const { round, limit } = budgetUse(job, 'reviewRounds');
|
|
24
|
+
const open = openFindings(verdict, round >= limit);
|
|
25
|
+
recordVerdict(job, verdict, open);
|
|
26
|
+
await ports.commentOnIssue(repo, issue.number, formatVerdict(verdict, open));
|
|
27
|
+
if (open.length === 0) {
|
|
28
|
+
return landApproved(job);
|
|
29
|
+
}
|
|
30
|
+
return changesRequestedRound(job, open, earlier);
|
|
31
|
+
}
|
|
32
|
+
async function changesRequestedRound(job, open, earlier) {
|
|
33
|
+
const { state } = job;
|
|
34
|
+
const findings = formatFindings(open);
|
|
35
|
+
state.reviewLog.push({ round: state.reviewRounds, findings });
|
|
36
|
+
await writeState(job.context.repo, state);
|
|
37
|
+
const fix = await fixRound(job, 'The reviewer requested changes.', findings, earlier, 'review');
|
|
38
|
+
if (!fix.committed) {
|
|
39
|
+
return unfixedRound(job, fix);
|
|
40
|
+
}
|
|
41
|
+
return ROUND_CONTINUE;
|
|
42
|
+
}
|
|
43
|
+
function recordVerdict(job, verdict, open) {
|
|
44
|
+
const blocking = blockingFindings(verdict);
|
|
45
|
+
job.log.event('verdict', {
|
|
46
|
+
round: job.state.reviewRounds,
|
|
47
|
+
blocking: blocking.length,
|
|
48
|
+
minor: verdict.findings.length - blocking.length,
|
|
49
|
+
open: open.length,
|
|
50
|
+
summary: verdict.summary,
|
|
51
|
+
}, 'quiet');
|
|
52
|
+
}
|
|
53
|
+
async function runReviewer(job, earlier) {
|
|
54
|
+
const { context, issue, log, state, worktree, comments } = job;
|
|
55
|
+
const { config, ports } = context;
|
|
22
56
|
const full = await ports.diff(worktree, context.base, config.remote);
|
|
23
57
|
const patch = capDiff(full, config.diffMaxChars);
|
|
24
58
|
const fields = {
|
|
25
|
-
|
|
26
|
-
limit: config.maxReviewRounds,
|
|
59
|
+
...budgetUse(job, 'reviewRounds'),
|
|
27
60
|
diffChars: full.length,
|
|
28
61
|
cut: full.length > config.diffMaxChars,
|
|
29
62
|
};
|
|
30
63
|
const before = await ports.revision(worktree);
|
|
31
|
-
const review = await log.step('review', fields, () =>
|
|
32
|
-
name: 'reviewer',
|
|
33
|
-
cwd: worktree,
|
|
34
|
-
prompt: reviewPrompt(issue, comments, patch, history(state.reviewLog)),
|
|
35
|
-
profile: REVIEWING,
|
|
36
|
-
model: config.models.reviewer,
|
|
37
|
-
timeoutMs: config.agentTimeoutMinutes * 60_000,
|
|
38
|
-
}));
|
|
64
|
+
const review = await log.step('review', fields, () => runRole(job, 'reviewer', reviewPrompt(issue, comments, patch, earlier), REVIEWING));
|
|
39
65
|
if (await ports.discardChanges(worktree, before)) {
|
|
40
66
|
log.event('review.discard', { round: state.reviewRounds }, 'quiet');
|
|
41
67
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
68
|
+
return review.text;
|
|
69
|
+
}
|
|
70
|
+
async function unfixedRound(job, fix) {
|
|
71
|
+
const { context, issue, state } = job;
|
|
72
|
+
const { repo, ports } = context;
|
|
73
|
+
const note = fix.unrelated;
|
|
74
|
+
if (note === undefined) {
|
|
75
|
+
return escalateAndFinish(job, 'The fixer added no commit for the review findings.', 'no fix commit');
|
|
46
76
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
log.event('verdict', {
|
|
50
|
-
round: state.reviewRounds,
|
|
51
|
-
blocking: blocking.length,
|
|
52
|
-
minor: verdict.findings.length - blocking.length,
|
|
53
|
-
open: open.length,
|
|
54
|
-
summary: verdict.summary,
|
|
55
|
-
}, 'quiet');
|
|
56
|
-
await ports.commentOnPr(repo, pr, formatVerdict(verdict, open));
|
|
57
|
-
if (open.length === 0) {
|
|
58
|
-
const gate = await checkGate(job);
|
|
59
|
-
if (gate.done) {
|
|
60
|
-
return { done: true, report: gate.report };
|
|
61
|
-
}
|
|
62
|
-
if (gate.fixed) {
|
|
63
|
-
return { done: false };
|
|
64
|
-
}
|
|
65
|
-
if (config.draftPullRequest && !(await ports.markPrReady(repo, pr))) {
|
|
66
|
-
log.event('pull-request.undraft.fail', { pr }, 'quiet');
|
|
67
|
-
}
|
|
68
|
-
if (context.merge) {
|
|
69
|
-
if (await conflicts(job)) {
|
|
70
|
-
const resolved = await resolveConflict(job);
|
|
71
|
-
return resolved.done ? { done: true, report: resolved.report } : { done: false };
|
|
72
|
-
}
|
|
73
|
-
if (!(await ports.mergePr(repo, pr))) {
|
|
74
|
-
await escalate(job, 'The merge of the pull request failed.');
|
|
75
|
-
return { done: true, report: await finish(job, 'needs-human', 'merge failed') };
|
|
76
|
-
}
|
|
77
|
-
return afterMerge(job);
|
|
78
|
-
}
|
|
79
|
-
await setStatus(context, issue.number, pr, config.labels.done);
|
|
80
|
-
return { done: true, report: await finish(job, 'done') };
|
|
77
|
+
if (fix.stray === true) {
|
|
78
|
+
return escalateAndFinish(job, `The fixer disputed the findings and left a change behind: ${note}`, 'dispute with changes');
|
|
81
79
|
}
|
|
82
|
-
|
|
83
|
-
state.reviewLog.push({
|
|
84
|
-
round: state.reviewRounds,
|
|
85
|
-
findings: formatFindings(open),
|
|
86
|
-
});
|
|
80
|
+
state.reviewLog.at(-1).dispute = note;
|
|
87
81
|
await writeState(repo, state);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const note = fix.unrelated;
|
|
91
|
-
if (note === undefined) {
|
|
92
|
-
await escalate(job, 'The fixer added no commit for the review findings.');
|
|
93
|
-
return { done: true, report: await finish(job, 'needs-human', 'no fix commit') };
|
|
94
|
-
}
|
|
95
|
-
if (fix.stray === true) {
|
|
96
|
-
await escalate(job, `The fixer disputed the findings and left a change behind: ${note}`);
|
|
97
|
-
return { done: true, report: await finish(job, 'needs-human', 'dispute with changes') };
|
|
98
|
-
}
|
|
99
|
-
state.reviewLog.at(-1).dispute = note;
|
|
100
|
-
await writeState(repo, state);
|
|
101
|
-
await ports.commentOnPr(repo, pr, `### Fixer: no change\n\n${note}`);
|
|
102
|
-
}
|
|
103
|
-
return { done: false };
|
|
82
|
+
await ports.commentOnIssue(repo, issue.number, `### Fixer: no change\n\n${note}`);
|
|
83
|
+
return ROUND_CONTINUE;
|
|
104
84
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { succeeded } from './exec.mjs';
|
|
2
|
+
import { ghRun } from './gh.mjs';
|
|
3
|
+
import { joinFilled } from './text.mjs';
|
|
4
|
+
export async function runLogs(repo, failed, maxChars) {
|
|
5
|
+
const share = Math.max(1, Math.floor(maxChars / Math.max(1, failed.length)));
|
|
6
|
+
const parts = [];
|
|
7
|
+
for (const { heading, runId } of failed) {
|
|
8
|
+
parts.push(heading);
|
|
9
|
+
if (runId === undefined) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
parts.push(await runLog(repo, runId, share));
|
|
13
|
+
}
|
|
14
|
+
return parts.join('\n\n');
|
|
15
|
+
}
|
|
16
|
+
async function runLog(repo, runId, share) {
|
|
17
|
+
const logs = await ghRun(repo, ['run', 'view', runId, '--log-failed'], { tailChars: share });
|
|
18
|
+
if (succeeded(logs)) {
|
|
19
|
+
return logs.stdout;
|
|
20
|
+
}
|
|
21
|
+
const reason = joinFilled([`The log read failed with code ${logs.code}.`, logs.stderr.trim()], ' ');
|
|
22
|
+
return joinFilled([logs.stdout.trim(), reason], '\n');
|
|
23
|
+
}
|
package/dist/run.mjs
CHANGED
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { writeFile } from 'node:fs/promises';
|
|
3
|
-
import { join } from 'node:path';
|
|
1
|
+
import { recordCommands } from './command-records.mjs';
|
|
4
2
|
import { loadConfig } from './config.mjs';
|
|
5
|
-
import {
|
|
3
|
+
import { minutesToMs } from './durations.mjs';
|
|
4
|
+
import { message } from './errors.mjs';
|
|
5
|
+
import { withDefaultTimeout } from './exec.mjs';
|
|
6
|
+
import { writeJson } from './files.mjs';
|
|
7
|
+
import { slug } from './gh.mjs';
|
|
6
8
|
import { detectRepo } from './git.mjs';
|
|
7
9
|
import { defaultBranch } from './github.mjs';
|
|
8
|
-
import { exitCode, runIssues
|
|
9
|
-
import {
|
|
10
|
-
import { pendingIssues
|
|
11
|
-
import {
|
|
10
|
+
import { exitCode, runIssues } from './loop.mjs';
|
|
11
|
+
import { Recorder } from './observe.mjs';
|
|
12
|
+
import { pendingIssues } from './pending.mjs';
|
|
13
|
+
import { processIssue } from './pipeline.mjs';
|
|
14
|
+
import { PORTS } from './ports.mjs';
|
|
15
|
+
import { pruneRuns } from './prune-runs.mjs';
|
|
16
|
+
import { count } from './summary.mjs';
|
|
12
17
|
import { packageVersion } from './version.mjs';
|
|
13
|
-
|
|
14
|
-
setCommandObserver((record) => {
|
|
15
|
-
commandRecorder.getStore()?.event(record.code === 0 ? 'command' : 'command.fail', {
|
|
16
|
-
cmd: `${record.command} ${record.args.join(' ')}`,
|
|
17
|
-
code: record.code,
|
|
18
|
-
ms: record.ms,
|
|
19
|
-
stderr: record.stderr.length > 0 ? record.stderr : undefined,
|
|
20
|
-
timedOut: record.timedOut ? true : undefined,
|
|
21
|
-
}, record.code === 0 ? 'verbose' : 'quiet');
|
|
22
|
-
});
|
|
23
|
-
export function recordCommands(recorder, work) {
|
|
24
|
-
return commandRecorder.run(recorder, work);
|
|
25
|
-
}
|
|
18
|
+
import { watchIssues } from './watch.mjs';
|
|
26
19
|
export async function runRepo(root, args, controls) {
|
|
27
20
|
const config = await loadConfig(root);
|
|
28
|
-
return withDefaultTimeout(config.commandTimeoutMinutes
|
|
21
|
+
return withDefaultTimeout(minutesToMs(config.commandTimeoutMinutes), () => runWithConfig(root, args, controls, config));
|
|
29
22
|
}
|
|
30
23
|
async function runWithConfig(root, args, controls, config) {
|
|
31
24
|
const repo = await detectRepo(root, config.remote);
|
|
@@ -43,23 +36,7 @@ async function runWithConfig(root, args, controls, config) {
|
|
|
43
36
|
}
|
|
44
37
|
async function handle(args, config, repo, recorder, controls) {
|
|
45
38
|
const { interrupts } = controls;
|
|
46
|
-
const
|
|
47
|
-
const context = {
|
|
48
|
-
repo,
|
|
49
|
-
config,
|
|
50
|
-
base,
|
|
51
|
-
reset: args.reset,
|
|
52
|
-
merge: args.merge,
|
|
53
|
-
stopAfterRound: interrupts.afterRound,
|
|
54
|
-
recorder,
|
|
55
|
-
ports: PORTS,
|
|
56
|
-
};
|
|
57
|
-
recorder.event('run.start', {
|
|
58
|
-
version: await packageVersion(),
|
|
59
|
-
repo: `${repo.owner}/${repo.name}`,
|
|
60
|
-
base,
|
|
61
|
-
log: recorder.logFile,
|
|
62
|
-
}, 'quiet');
|
|
39
|
+
const context = await startRun(args, config, repo, recorder, interrupts);
|
|
63
40
|
const loop = {
|
|
64
41
|
issues: () => pendingIssues(context),
|
|
65
42
|
process: (issue) => processIssue(context, issue),
|
|
@@ -67,24 +44,55 @@ async function handle(args, config, repo, recorder, controls) {
|
|
|
67
44
|
concurrency: config.concurrency,
|
|
68
45
|
};
|
|
69
46
|
const print = controls.print ?? (async () => undefined);
|
|
70
|
-
let passStart = recorder.summary();
|
|
71
47
|
const { reports, stoppedAt, error } = args.watch
|
|
72
|
-
? await
|
|
73
|
-
...loop,
|
|
74
|
-
wait: (minutes) => {
|
|
75
|
-
recorder.event('watch.wait', { minutes }, 'quiet');
|
|
76
|
-
passStart = recorder.summary();
|
|
77
|
-
return interrupts.sleep(minutes * 60_000);
|
|
78
|
-
},
|
|
79
|
-
passEnd: (issues) => print({ ...recorder.summary(passStart), issues }),
|
|
80
|
-
})
|
|
48
|
+
? await watchRun(args, loop, recorder, interrupts, print)
|
|
81
49
|
: await runIssues(args, loop);
|
|
50
|
+
recordLoopEnd(recorder, stoppedAt, error);
|
|
51
|
+
const summary = await endRun(recorder, reports);
|
|
52
|
+
if (!args.watch) {
|
|
53
|
+
await print(summary);
|
|
54
|
+
}
|
|
55
|
+
return error === undefined ? exitCode(reports) : 1;
|
|
56
|
+
}
|
|
57
|
+
function watchRun(args, loop, recorder, interrupts, print) {
|
|
58
|
+
let passStart = recorder.summary();
|
|
59
|
+
return watchIssues(args, {
|
|
60
|
+
...loop,
|
|
61
|
+
wait: (minutes) => {
|
|
62
|
+
recorder.event('watch.wait', { minutes }, 'quiet');
|
|
63
|
+
passStart = recorder.summary();
|
|
64
|
+
return interrupts.sleep(minutesToMs(minutes));
|
|
65
|
+
},
|
|
66
|
+
passEnd: (issues) => print({ ...recorder.summary(passStart), issues }),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function recordLoopEnd(recorder, stoppedAt, error) {
|
|
82
70
|
if (stoppedAt !== undefined) {
|
|
83
71
|
recorder.event('run.stop', { issue: stoppedAt }, 'quiet');
|
|
84
72
|
}
|
|
85
73
|
if (error !== undefined) {
|
|
86
74
|
recorder.event('issues.fail', { error: message(error) }, 'quiet');
|
|
87
75
|
}
|
|
76
|
+
}
|
|
77
|
+
async function startRun(args, config, repo, recorder, interrupts) {
|
|
78
|
+
const base = await defaultBranch(repo);
|
|
79
|
+
recorder.event('run.start', {
|
|
80
|
+
version: await packageVersion(),
|
|
81
|
+
repo: slug(repo),
|
|
82
|
+
base,
|
|
83
|
+
log: recorder.logFile,
|
|
84
|
+
}, 'quiet');
|
|
85
|
+
return {
|
|
86
|
+
repo,
|
|
87
|
+
config,
|
|
88
|
+
base,
|
|
89
|
+
reset: args.reset,
|
|
90
|
+
stopAfterRound: interrupts.afterRound,
|
|
91
|
+
recorder,
|
|
92
|
+
ports: PORTS,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async function endRun(recorder, reports) {
|
|
88
96
|
recorder.event('run.end', {
|
|
89
97
|
done: count(reports, 'done'),
|
|
90
98
|
needsHuman: count(reports, 'needs-human'),
|
|
@@ -93,13 +101,6 @@ async function handle(args, config, repo, recorder, controls) {
|
|
|
93
101
|
tokens: recorder.summary().total.total,
|
|
94
102
|
}, 'quiet');
|
|
95
103
|
const summary = { ...recorder.summary(), issues: reports };
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (!args.watch) {
|
|
99
|
-
await print(summary);
|
|
100
|
-
}
|
|
101
|
-
return error === undefined ? exitCode(reports) : 1;
|
|
102
|
-
}
|
|
103
|
-
function count(reports, outcome) {
|
|
104
|
-
return reports.filter((report) => report.outcome === outcome).length;
|
|
104
|
+
await writeJson(recorder.summaryFile, summary);
|
|
105
|
+
return summary;
|
|
105
106
|
}
|