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
package/dist/conflict.mjs
CHANGED
|
@@ -1,52 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
export async function
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
1
|
+
import { parseCommitSubject } from './agent-reply.mjs';
|
|
2
|
+
import { spendBudget } from './budget.mjs';
|
|
3
|
+
import { commitWork, runFixer } from './fix.mjs';
|
|
4
|
+
import { escalateAndFinish } from './handover.mjs';
|
|
5
|
+
import { fallbackTitle } from './job.mjs';
|
|
6
|
+
export async function rebase(job) {
|
|
7
|
+
const { context, issue, log, state, worktree } = job;
|
|
8
|
+
const { config, ports, base } = context;
|
|
9
|
+
const title = state.title ?? fallbackTitle(issue);
|
|
10
|
+
const before = await ports.revision(worktree);
|
|
11
|
+
const files = await log.step('rebase', { base }, () => ports.startMerge(worktree, base, config.remote));
|
|
12
|
+
if (files !== undefined) {
|
|
13
|
+
log.event('rebase.conflicts', { files }, 'quiet');
|
|
14
|
+
const merged = await mergeBase(job, before, files);
|
|
15
|
+
if (merged !== undefined) {
|
|
16
|
+
return merged;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const merged = await ports.revision(worktree);
|
|
20
|
+
const squashed = await commitWork(job, merged, title, 'fixer', (cwd, message) => ports.squashOnto(cwd, base, config.remote, message));
|
|
21
|
+
if (!squashed) {
|
|
22
|
+
return escalateAndFinish(job, `The change holds nothing that ${config.remote}/${base} does not already hold.`, 'empty change');
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
12
25
|
}
|
|
13
|
-
|
|
14
|
-
const { context,
|
|
15
|
-
const {
|
|
16
|
-
if (
|
|
17
|
-
await
|
|
18
|
-
|
|
26
|
+
async function mergeBase(job, before, files) {
|
|
27
|
+
const { context, worktree } = job;
|
|
28
|
+
const { config, ports, base } = context;
|
|
29
|
+
if (files.length > 0) {
|
|
30
|
+
const exhausted = await spendBudget(job, 'ciFixes', `The change conflicts with ${base}, and the limit of ${config.maxCiFixes} check fixes was reached.`, 'merge conflict');
|
|
31
|
+
if (exhausted) {
|
|
32
|
+
await ports.abortMerge(worktree, before);
|
|
33
|
+
return exhausted;
|
|
34
|
+
}
|
|
19
35
|
}
|
|
20
|
-
|
|
21
|
-
await writeState(repo, state);
|
|
22
|
-
const before = await ports.revision(worktree);
|
|
23
|
-
const files = await log.step('merge-base', { base: context.base }, () => ports.startMerge(worktree, context.base, config.remote));
|
|
24
|
-
log.event('merge-base.conflicts', { files }, 'quiet');
|
|
25
|
-
if (files !== undefined && !(await mergeBase(job, before, files))) {
|
|
36
|
+
if (!(await resolve(job, before, files))) {
|
|
26
37
|
await ports.abortMerge(worktree, before);
|
|
27
|
-
|
|
28
|
-
return { done: true, report: await finish(job, 'needs-human', 'merge conflict') };
|
|
38
|
+
return escalateAndFinish(job, `The fixer left the conflict with ${base} unresolved.`, 'merge conflict');
|
|
29
39
|
}
|
|
30
|
-
|
|
31
|
-
return { done: false, fixed: true };
|
|
40
|
+
return undefined;
|
|
32
41
|
}
|
|
33
|
-
|
|
34
|
-
const
|
|
42
|
+
function fixConflict(job, files) {
|
|
43
|
+
const reason = `The change conflicts with ${job.context.base}.`;
|
|
44
|
+
return runFixer(job, reason, files.join('\n'), [], 'conflict');
|
|
45
|
+
}
|
|
46
|
+
async function resolve(job, before, files) {
|
|
47
|
+
const { context, worktree } = job;
|
|
35
48
|
const { config, ports } = context;
|
|
36
49
|
try {
|
|
37
|
-
|
|
38
|
-
if (files.length > 0) {
|
|
39
|
-
const reason = 'The pull request conflicts with its base.';
|
|
40
|
-
const result = await log.step('fix', { reason, cause: 'conflict', round: state.ciFixes, limit: config.maxCiFixes }, () => ports.runAgent(log, {
|
|
41
|
-
name: 'fixer',
|
|
42
|
-
cwd: worktree,
|
|
43
|
-
prompt: fixPrompt(issue, reason, files.join('\n'), [], 'conflict', job.reply),
|
|
44
|
-
profile: CODING,
|
|
45
|
-
model: config.models.fixer,
|
|
46
|
-
timeoutMs: config.agentTimeoutMinutes * 60_000,
|
|
47
|
-
}));
|
|
48
|
-
text = result.text;
|
|
49
|
-
}
|
|
50
|
+
const text = files.length > 0 ? await fixConflict(job, files) : '';
|
|
50
51
|
const subject = parseCommitSubject(text, `chore: merge ${config.remote}/${context.base}`);
|
|
51
52
|
return await commitWork(job, before, subject, 'fixer', (cwd, message) => ports.commitMerge(cwd, files, message));
|
|
52
53
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function minutesToMs(minutes) {
|
|
2
|
+
return minutes * 60_000;
|
|
3
|
+
}
|
|
4
|
+
export function daysToMs(days) {
|
|
5
|
+
return minutesToMs(days * 24 * 60);
|
|
6
|
+
}
|
|
7
|
+
export function secondsToMs(seconds) {
|
|
8
|
+
return seconds * 1000;
|
|
9
|
+
}
|
|
10
|
+
export function deadline(ms, onExpire) {
|
|
11
|
+
let timedOut = false;
|
|
12
|
+
const timer = ms === undefined
|
|
13
|
+
? undefined
|
|
14
|
+
: setTimeout(() => {
|
|
15
|
+
timedOut = true;
|
|
16
|
+
onExpire();
|
|
17
|
+
}, ms);
|
|
18
|
+
return { timedOut: () => timedOut, clear: () => clearTimeout(timer) };
|
|
19
|
+
}
|
|
20
|
+
export function elapsedMs(started) {
|
|
21
|
+
return Date.now() - started;
|
|
22
|
+
}
|
|
23
|
+
export function wakeableSleep(sleeper, ms, stopped) {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
if (stopped) {
|
|
26
|
+
resolve(false);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const settle = (slept) => {
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
sleeper.wake = undefined;
|
|
32
|
+
resolve(slept);
|
|
33
|
+
};
|
|
34
|
+
const timer = setTimeout(() => settle(true), ms);
|
|
35
|
+
sleeper.wake = () => settle(false);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ROUND_CONTINUE } from './job.mjs';
|
|
2
|
+
import { resumeLanding } from './land.mjs';
|
|
3
|
+
import { writeState } from './state.mjs';
|
|
4
|
+
export async function enterReview(job) {
|
|
5
|
+
const { context, state } = job;
|
|
6
|
+
const landed = state.landed?.at(-1);
|
|
7
|
+
if (landed !== undefined) {
|
|
8
|
+
return resumeLanding(job, landed);
|
|
9
|
+
}
|
|
10
|
+
state.phase = 'review';
|
|
11
|
+
await writeState(context.repo, state);
|
|
12
|
+
return ROUND_CONTINUE;
|
|
13
|
+
}
|
package/dist/errors.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function message(error) {
|
|
2
|
+
return error instanceof Error ? error.message : String(error);
|
|
3
|
+
}
|
|
4
|
+
export function asError(error) {
|
|
5
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
6
|
+
}
|
|
7
|
+
export function hasCode(error, code) {
|
|
8
|
+
return error.code === code;
|
|
9
|
+
}
|
|
10
|
+
export function errorMatches(error, pattern) {
|
|
11
|
+
return error instanceof Error && pattern.test(error.message);
|
|
12
|
+
}
|
|
13
|
+
export function parseJson(text, failure) {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(text);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw new Error(failure(error));
|
|
19
|
+
}
|
|
20
|
+
}
|
package/dist/exec.mjs
CHANGED
|
@@ -1,135 +1,92 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
|
+
import { killTree, unwatch, watch } from './children.mjs';
|
|
4
|
+
import { deadline, elapsedMs, minutesToMs } from './durations.mjs';
|
|
5
|
+
import { keepTail } from './text.mjs';
|
|
3
6
|
let observer;
|
|
4
|
-
const DEFAULT_TIMEOUT_MS = 10
|
|
7
|
+
const DEFAULT_TIMEOUT_MS = minutesToMs(10);
|
|
5
8
|
const defaultTimeout = new AsyncLocalStorage();
|
|
6
9
|
const STDERR_TAIL = 200_000;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export function onStop(stopper) {
|
|
10
|
-
stoppers.add(stopper);
|
|
11
|
-
return () => stoppers.delete(stopper);
|
|
10
|
+
export function setCommandObserver(next) {
|
|
11
|
+
observer = next;
|
|
12
12
|
}
|
|
13
|
-
export function
|
|
14
|
-
|
|
15
|
-
stopper();
|
|
16
|
-
}
|
|
17
|
-
stoppers.clear();
|
|
18
|
-
for (const pid of groups) {
|
|
19
|
-
try {
|
|
20
|
-
process.kill(-pid, signal);
|
|
21
|
-
}
|
|
22
|
-
catch { }
|
|
23
|
-
}
|
|
24
|
-
groups.clear();
|
|
25
|
-
process.off('SIGTERM', onTerminate);
|
|
26
|
-
process.kill(process.pid, signal);
|
|
13
|
+
export function withDefaultTimeout(ms, body) {
|
|
14
|
+
return defaultTimeout.run(ms, body);
|
|
27
15
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
function spawnChild(command, args, options) {
|
|
17
|
+
return spawn(command, args, {
|
|
18
|
+
cwd: options.cwd,
|
|
19
|
+
detached: true,
|
|
20
|
+
stdio: [
|
|
21
|
+
options.input === undefined ? 'ignore' : 'pipe',
|
|
22
|
+
options.show === true ? 2 : 'pipe',
|
|
23
|
+
'pipe',
|
|
24
|
+
],
|
|
25
|
+
});
|
|
37
26
|
}
|
|
38
|
-
function
|
|
39
|
-
if (
|
|
27
|
+
function sendInput(child, input) {
|
|
28
|
+
if (input === undefined) {
|
|
40
29
|
return;
|
|
41
30
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
process.off('SIGTERM', onTerminate);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export function track(child) {
|
|
48
|
-
watch(child.pid);
|
|
49
|
-
child.on('close', () => unwatch(child.pid));
|
|
50
|
-
child.on('error', () => unwatch(child.pid));
|
|
31
|
+
child.stdin?.on('error', () => undefined);
|
|
32
|
+
child.stdin?.end(input);
|
|
51
33
|
}
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
function collect(child, options) {
|
|
35
|
+
const output = { stdout: '', stderr: '' };
|
|
36
|
+
child.stdout?.setEncoding('utf8');
|
|
37
|
+
child.stderr?.setEncoding('utf8');
|
|
38
|
+
child.stdout?.on('data', (chunk) => {
|
|
39
|
+
options.onStdout?.(chunk);
|
|
40
|
+
output.stdout = keepTail(output.stdout + chunk, options.tailChars);
|
|
41
|
+
});
|
|
42
|
+
const stderrLimit = options.tailChars ?? STDERR_TAIL;
|
|
43
|
+
child.stderr?.on('data', (chunk) => {
|
|
44
|
+
output.stderr = keepTail(output.stderr + chunk, stderrLimit);
|
|
45
|
+
});
|
|
46
|
+
return output;
|
|
54
47
|
}
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
function notify(command, args, options, started, result) {
|
|
49
|
+
observer?.({
|
|
50
|
+
command,
|
|
51
|
+
args,
|
|
52
|
+
cwd: options.cwd,
|
|
53
|
+
code: result.code,
|
|
54
|
+
ms: elapsedMs(started),
|
|
55
|
+
stderr: succeeded(result) ? '' : result.stderr.trim(),
|
|
56
|
+
timedOut: result.timedOut,
|
|
57
|
+
});
|
|
57
58
|
}
|
|
58
59
|
export function run(command, args, options = {}) {
|
|
59
60
|
const started = Date.now();
|
|
60
61
|
const limit = options.timeoutMs ?? defaultTimeout.getStore() ?? DEFAULT_TIMEOUT_MS;
|
|
61
62
|
return new Promise((resolve, reject) => {
|
|
62
|
-
const child =
|
|
63
|
-
cwd: options.cwd,
|
|
64
|
-
detached: true,
|
|
65
|
-
stdio: [
|
|
66
|
-
options.input === undefined ? 'ignore' : 'pipe',
|
|
67
|
-
options.show === true ? 2 : 'pipe',
|
|
68
|
-
'pipe',
|
|
69
|
-
],
|
|
70
|
-
});
|
|
63
|
+
const child = spawnChild(command, args, options);
|
|
71
64
|
const pid = child.pid;
|
|
72
65
|
watch(pid);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let timedOut = false;
|
|
76
|
-
child.stdout?.setEncoding('utf8');
|
|
77
|
-
child.stderr?.setEncoding('utf8');
|
|
78
|
-
child.stdout?.on('data', (chunk) => {
|
|
79
|
-
options.onStdout?.(chunk);
|
|
80
|
-
stdout += chunk;
|
|
81
|
-
if (options.tailChars !== undefined && stdout.length > options.tailChars) {
|
|
82
|
-
stdout = stdout.slice(-options.tailChars);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
const stderrLimit = options.tailChars ?? STDERR_TAIL;
|
|
86
|
-
child.stderr?.on('data', (chunk) => {
|
|
87
|
-
stderr += chunk;
|
|
88
|
-
if (stderr.length > stderrLimit) {
|
|
89
|
-
stderr = stderr.slice(-stderrLimit);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
const timer = setTimeout(() => {
|
|
93
|
-
timedOut = true;
|
|
94
|
-
if (pid === undefined) {
|
|
95
|
-
child.kill('SIGKILL');
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
try {
|
|
99
|
-
process.kill(-pid, 'SIGKILL');
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
child.kill('SIGKILL');
|
|
103
|
-
}
|
|
104
|
-
}, limit);
|
|
66
|
+
const output = collect(child, options);
|
|
67
|
+
const timer = deadline(limit, () => killTree(child));
|
|
105
68
|
let done = false;
|
|
106
|
-
const
|
|
107
|
-
|
|
69
|
+
const release = () => {
|
|
70
|
+
timer.clear();
|
|
108
71
|
unwatch(pid);
|
|
72
|
+
};
|
|
73
|
+
const settle = (code) => {
|
|
74
|
+
release();
|
|
109
75
|
if (done) {
|
|
110
76
|
return;
|
|
111
77
|
}
|
|
112
78
|
done = true;
|
|
113
|
-
const result = { code: code ?? 1,
|
|
114
|
-
|
|
115
|
-
command,
|
|
116
|
-
args,
|
|
117
|
-
cwd: options.cwd,
|
|
118
|
-
code: result.code,
|
|
119
|
-
ms: Date.now() - started,
|
|
120
|
-
stderr: result.code === 0 ? '' : stderr.trim(),
|
|
121
|
-
timedOut,
|
|
122
|
-
});
|
|
79
|
+
const result = { code: code ?? 1, ...output, timedOut: timer.timedOut() };
|
|
80
|
+
notify(command, args, options, started, result);
|
|
123
81
|
resolve(result);
|
|
124
82
|
};
|
|
125
83
|
child.on('error', (error) => {
|
|
126
|
-
|
|
127
|
-
unwatch(pid);
|
|
84
|
+
release();
|
|
128
85
|
done = true;
|
|
129
86
|
reject(error);
|
|
130
87
|
});
|
|
131
88
|
child.on('exit', (code) => {
|
|
132
|
-
if (!timedOut) {
|
|
89
|
+
if (!timer.timedOut()) {
|
|
133
90
|
return;
|
|
134
91
|
}
|
|
135
92
|
child.stdout?.destroy();
|
|
@@ -137,19 +94,26 @@ export function run(command, args, options = {}) {
|
|
|
137
94
|
settle(code);
|
|
138
95
|
});
|
|
139
96
|
child.on('close', settle);
|
|
140
|
-
|
|
141
|
-
child.stdin?.on('error', () => undefined);
|
|
142
|
-
child.stdin?.end(options.input);
|
|
143
|
-
}
|
|
97
|
+
sendInput(child, options.input);
|
|
144
98
|
});
|
|
145
99
|
}
|
|
100
|
+
export function succeeded(result) {
|
|
101
|
+
return result.code === 0;
|
|
102
|
+
}
|
|
103
|
+
export function optionalFlag(enabled, flag) {
|
|
104
|
+
return enabled ? [flag] : [];
|
|
105
|
+
}
|
|
106
|
+
export function failedWith(commandLine, result) {
|
|
107
|
+
return `${commandLine} failed with code ${result.code}: ${result.stderr.trim()}`;
|
|
108
|
+
}
|
|
146
109
|
export async function must(command, args, options = {}) {
|
|
147
110
|
const result = await run(command, args, options);
|
|
111
|
+
const commandLine = `${command} ${args.join(' ')}`;
|
|
148
112
|
if (result.timedOut) {
|
|
149
|
-
throw new Error(`${
|
|
113
|
+
throw new Error(`${commandLine} did not finish in time.`);
|
|
150
114
|
}
|
|
151
|
-
if (result
|
|
152
|
-
throw new Error(
|
|
115
|
+
if (!succeeded(result)) {
|
|
116
|
+
throw new Error(failedWith(commandLine, result));
|
|
153
117
|
}
|
|
154
118
|
return result.stdout.trim();
|
|
155
119
|
}
|
package/dist/files.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { hasCode } from './errors.mjs';
|
|
3
|
+
export function readTextOrEmpty(path) {
|
|
4
|
+
return readFile(path, 'utf8').catch(() => '');
|
|
5
|
+
}
|
|
6
|
+
export function listOrEmpty(dir) {
|
|
7
|
+
return readdir(dir).catch(() => []);
|
|
8
|
+
}
|
|
9
|
+
export function prettyJson(value) {
|
|
10
|
+
return `${JSON.stringify(value, null, 2)}\n`;
|
|
11
|
+
}
|
|
12
|
+
export function writeJson(path, value, options) {
|
|
13
|
+
return writeFile(path, prettyJson(value), options);
|
|
14
|
+
}
|
|
15
|
+
export async function unlessMissing(read) {
|
|
16
|
+
try {
|
|
17
|
+
return await read();
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (hasCode(error, 'ENOENT')) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function readTextIfPresent(path) {
|
|
27
|
+
return unlessMissing(() => readFile(path, 'utf8'));
|
|
28
|
+
}
|
package/dist/fix.mjs
CHANGED
|
@@ -1,47 +1,60 @@
|
|
|
1
|
+
import { parseCommitSubject, parseUnrelated } from './agent-reply.mjs';
|
|
1
2
|
import { CODING } from './agents.mjs';
|
|
2
|
-
import {
|
|
3
|
-
import { message } from './
|
|
4
|
-
import {
|
|
3
|
+
import { budgetUse } from './budget.mjs';
|
|
4
|
+
import { message } from './errors.mjs';
|
|
5
|
+
import { HookError } from './git-commit.mjs';
|
|
6
|
+
import { escalateAndFinish } from './handover.mjs';
|
|
7
|
+
import { runRole } from './job.mjs';
|
|
8
|
+
import { fixPrompt, hookPrompt } from './prompts.mjs';
|
|
5
9
|
import { writeState } from './state.mjs';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
timeoutMs: config.agentTimeoutMinutes * 60_000,
|
|
20
|
-
}));
|
|
21
|
-
const unrelated = parseUnrelated(result.text);
|
|
10
|
+
import { keepTail } from './text.mjs';
|
|
11
|
+
export function escalateCheckFix(job, unrelated, checks, after = '') {
|
|
12
|
+
if (unrelated === undefined) {
|
|
13
|
+
return escalateAndFinish(job, `The fixer added no commit for the failed ${checks}.${after}`, 'no fix commit');
|
|
14
|
+
}
|
|
15
|
+
return escalateAndFinish(job, `The ${checks} fail for a reason this change did not cause: ${unrelated}${after}`, 'unrelated failure');
|
|
16
|
+
}
|
|
17
|
+
export async function fixRound(job, reason, detail, earlier, kind) {
|
|
18
|
+
const { context, issue, log, worktree } = job;
|
|
19
|
+
const { ports } = context;
|
|
20
|
+
const before = await ports.revision(worktree);
|
|
21
|
+
const text = await runFixer(job, reason, detail, earlier, kind);
|
|
22
|
+
const unrelated = parseUnrelated(text);
|
|
22
23
|
if (unrelated !== undefined) {
|
|
23
|
-
|
|
24
|
-
const moved = disputed !== before;
|
|
25
|
-
if (moved) {
|
|
26
|
-
const aside = `${branch}-dispute-${disputed.slice(0, 7)}`;
|
|
27
|
-
await ports.setAside(worktree, before, aside);
|
|
28
|
-
log.event('fix.aside', { branch: aside }, 'quiet');
|
|
29
|
-
}
|
|
30
|
-
const stray = moved || (await ports.isDirty(worktree));
|
|
31
|
-
log.event('fix.unrelated', { reason, note: unrelated, stray }, 'quiet');
|
|
32
|
-
return { committed: false, unrelated, stray };
|
|
24
|
+
return disputedFix(job, before, reason, unrelated);
|
|
33
25
|
}
|
|
34
|
-
const subject = parseCommitSubject(
|
|
26
|
+
const subject = parseCommitSubject(text, `fix: address feedback on issue #${issue.number}`);
|
|
35
27
|
if (!(await commitWork(job, before, subject, 'fixer'))) {
|
|
36
28
|
log.event('commit.empty', { reason }, 'quiet');
|
|
37
29
|
return { committed: false };
|
|
38
30
|
}
|
|
39
|
-
await ports.push(worktree, config.remote, branch, force);
|
|
40
31
|
return { committed: true };
|
|
41
32
|
}
|
|
33
|
+
export async function runFixer(job, reason, detail, earlier, kind) {
|
|
34
|
+
const { issue, log } = job;
|
|
35
|
+
const result = await log.step('fix', { reason, cause: kind, ...fixBudget(job, kind) }, () => runRole(job, 'fixer', fixPrompt(issue, reason, detail, earlier, kind, job.reply), CODING));
|
|
36
|
+
return result.text;
|
|
37
|
+
}
|
|
38
|
+
function fixBudget(job, kind) {
|
|
39
|
+
return budgetUse(job, kind === 'review' ? 'reviewRounds' : 'ciFixes');
|
|
40
|
+
}
|
|
41
|
+
async function disputedFix(job, before, reason, unrelated) {
|
|
42
|
+
const { context, log, worktree, branch } = job;
|
|
43
|
+
const { ports } = context;
|
|
44
|
+
const disputed = await ports.revision(worktree);
|
|
45
|
+
const moved = disputed !== before;
|
|
46
|
+
if (moved) {
|
|
47
|
+
const aside = `${branch}-dispute-${disputed.slice(0, 7)}`;
|
|
48
|
+
await ports.setAside(worktree, before, aside);
|
|
49
|
+
log.event('fix.aside', { branch: aside }, 'quiet');
|
|
50
|
+
}
|
|
51
|
+
const stray = moved || (await ports.isDirty(worktree));
|
|
52
|
+
log.event('fix.unrelated', { reason, note: unrelated, stray }, 'quiet');
|
|
53
|
+
return { committed: false, unrelated, stray };
|
|
54
|
+
}
|
|
42
55
|
export async function commitWork(job, before, subject, role, commit) {
|
|
43
|
-
const { context, issue, log, state, worktree
|
|
44
|
-
const {
|
|
56
|
+
const { context, issue, log, state, worktree } = job;
|
|
57
|
+
const { ports } = context;
|
|
45
58
|
const commitChanges = commit ?? ports.commitAll;
|
|
46
59
|
for (;;) {
|
|
47
60
|
try {
|
|
@@ -55,23 +68,21 @@ export async function commitWork(job, before, subject, role, commit) {
|
|
|
55
68
|
return true;
|
|
56
69
|
}
|
|
57
70
|
catch (error) {
|
|
58
|
-
|
|
59
|
-
if (!(error instanceof HookError) || used >= config.maxCommitFixes) {
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
state.commitFixes = used + 1;
|
|
63
|
-
await writeState(repo, state);
|
|
64
|
-
const output = message(error).slice(-config.logMaxChars);
|
|
65
|
-
log.event('commit.fail', { role, output }, 'quiet');
|
|
66
|
-
const fix = await log.step('commit-fix', { role, round: state.commitFixes, limit: config.maxCommitFixes }, () => ports.runAgent(log, {
|
|
67
|
-
name: role,
|
|
68
|
-
cwd: worktree,
|
|
69
|
-
prompt: hookPrompt(issue, comments, role, output),
|
|
70
|
-
profile: CODING,
|
|
71
|
-
model: config.models[role],
|
|
72
|
-
timeoutMs: config.agentTimeoutMinutes * 60_000,
|
|
73
|
-
}));
|
|
74
|
-
subject = parseCommitSubject(fix.text, subject);
|
|
71
|
+
subject = await hookFix(job, error, subject, role);
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
}
|
|
75
|
+
async function hookFix(job, error, subject, role) {
|
|
76
|
+
const { context, issue, log, state, comments } = job;
|
|
77
|
+
const { repo, config } = context;
|
|
78
|
+
const used = state.commitFixes ?? 0;
|
|
79
|
+
if (!(error instanceof HookError) || used >= config.maxCommitFixes) {
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
state.commitFixes = used + 1;
|
|
83
|
+
await writeState(repo, state);
|
|
84
|
+
const output = keepTail(message(error), config.logMaxChars);
|
|
85
|
+
log.event('commit.fail', { role, output }, 'quiet');
|
|
86
|
+
const fix = await log.step('commit-fix', { role, round: state.commitFixes, limit: config.maxCommitFixes }, () => runRole(job, role, hookPrompt(issue, comments, role, output), CODING));
|
|
87
|
+
return parseCommitSubject(fix.text, subject);
|
|
88
|
+
}
|
package/dist/gate.mjs
CHANGED
|
@@ -1,53 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { budgetUse } from './budget.mjs';
|
|
2
|
+
import { checkWaiting } from './check-poll.mjs';
|
|
3
|
+
import { escalateCheckFix, fixRound } from './fix.mjs';
|
|
4
|
+
import { escalateAndFinish } from './handover.mjs';
|
|
5
|
+
import { GATE_FIXED, GATE_PASSED } from './job.mjs';
|
|
6
|
+
import { revert } from './revert.mjs';
|
|
5
7
|
import { writeState } from './state.mjs';
|
|
6
|
-
export async function checkGate(job) {
|
|
7
|
-
const { context, log
|
|
8
|
-
const { repo, config, ports } = context;
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
graceMs: job.noChecks ? 0 : config.checkGraceSeconds * 1000,
|
|
14
|
-
timeoutMs: config.checkTimeoutMinutes * 60_000,
|
|
15
|
-
show: log.level === 'verbose',
|
|
16
|
-
}));
|
|
17
|
-
log.event('checks.state', { state: checks });
|
|
18
|
-
job.noChecks ||= checks === 'none';
|
|
19
|
-
if (checks === 'timeout') {
|
|
20
|
-
await escalate(job, 'The checks did not finish in time.');
|
|
21
|
-
return { done: true, report: await finish(job, 'needs-human', 'checks timeout') };
|
|
22
|
-
}
|
|
23
|
-
if (checks === 'none' && (await conflicts(job))) {
|
|
24
|
-
return resolveConflict(job);
|
|
25
|
-
}
|
|
26
|
-
if (checks === 'moved') {
|
|
27
|
-
await escalate(job, 'Someone pushed to the pull request while the harness waited for the checks.');
|
|
28
|
-
return { done: true, report: await finish(job, 'needs-human', 'pull request moved') };
|
|
8
|
+
export async function checkGate(job, sha) {
|
|
9
|
+
const { context, log } = job;
|
|
10
|
+
const { repo, config, ports, base } = context;
|
|
11
|
+
const checks = await log.step('main-checks', { sha }, () => ports.waitForBaseChecks(repo, sha, checkWaiting(config, true)));
|
|
12
|
+
log.event('main-checks.state', { state: checks });
|
|
13
|
+
if (checks === 'pass' || checks === 'none') {
|
|
14
|
+
return GATE_PASSED;
|
|
29
15
|
}
|
|
16
|
+
job.mainBroken = true;
|
|
30
17
|
if (checks !== 'fail') {
|
|
31
|
-
return {
|
|
18
|
+
return escalateAndFinish(job, `The checks on ${base} did not finish in time.`, 'main checks timeout');
|
|
32
19
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
return failedChecksFix(job, sha);
|
|
21
|
+
}
|
|
22
|
+
async function failedChecksFix(job, sha) {
|
|
23
|
+
const { context, log, state } = job;
|
|
24
|
+
const { repo, config, ports, base } = context;
|
|
25
|
+
const { round, limit } = budgetUse(job, 'ciFixes');
|
|
26
|
+
if (round >= limit) {
|
|
27
|
+
const reverted = await revert(job);
|
|
28
|
+
return escalateAndFinish(job, `The checks on ${base} failed and the limit of ${limit} check fixes was reached.${reverted}`, 'check budget');
|
|
36
29
|
}
|
|
37
30
|
state.ciFixes += 1;
|
|
38
31
|
await writeState(repo, state);
|
|
39
|
-
const logs = await ports.
|
|
40
|
-
log.event('checks.logs', { chars: logs.length });
|
|
41
|
-
const fix = await fixRound(job,
|
|
32
|
+
const logs = await ports.failedBaseLogs(repo, sha, config.logMaxChars);
|
|
33
|
+
log.event('main-checks.logs', { chars: logs.length });
|
|
34
|
+
const fix = await fixRound(job, `The checks on ${base} failed after the change landed there.`, logs, [], 'checks');
|
|
42
35
|
if (!fix.committed) {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
? 'The fixer added no commit for the failed checks.'
|
|
46
|
-
: `The checks fail for a reason this change did not cause: ${note}`);
|
|
47
|
-
return {
|
|
48
|
-
done: true,
|
|
49
|
-
report: await finish(job, 'needs-human', note === undefined ? 'no fix commit' : 'unrelated failure'),
|
|
50
|
-
};
|
|
36
|
+
const reverted = await revert(job);
|
|
37
|
+
return escalateCheckFix(job, fix.unrelated, `checks on ${base}`, reverted);
|
|
51
38
|
}
|
|
52
|
-
|
|
39
|
+
job.repairing = true;
|
|
40
|
+
return GATE_FIXED;
|
|
53
41
|
}
|