next-issue 14.4.10 → 14.4.11
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/dist/cli/switch-run.mjs
CHANGED
|
@@ -83,11 +83,14 @@ export async function stopInWorker(root) {
|
|
|
83
83
|
connection.close();
|
|
84
84
|
return NO_RUN;
|
|
85
85
|
}
|
|
86
|
-
if (progress.status === 'stopping') {
|
|
86
|
+
if (progress.status === 'stopping' && progress.upgrade === undefined) {
|
|
87
87
|
connection.close();
|
|
88
88
|
return 'next-issue: the run is stopping already\n';
|
|
89
89
|
}
|
|
90
90
|
connection.send({ type: 'stop', root, after: 'issue' });
|
|
91
91
|
await connection.end();
|
|
92
|
+
if (progress.upgrade !== undefined) {
|
|
93
|
+
return 'next-issue: the run will stop after its current issues and not start again\n';
|
|
94
|
+
}
|
|
92
95
|
return 'next-issue: the run will stop after its current issues\n';
|
|
93
96
|
}
|
package/dist/worker/progress.mjs
CHANGED
|
@@ -1,91 +1,9 @@
|
|
|
1
|
-
import { truncate } from '../shared/text.mjs';
|
|
2
|
-
const TOOL_LINE_MAX = 80;
|
|
3
|
-
const NOT_STAGES = new Set(['issue.start', 'agent.start', 'run.start']);
|
|
4
1
|
export function startProgress(hunting = false) {
|
|
5
|
-
return { status: 'running', hunting
|
|
6
|
-
}
|
|
7
|
-
function toolLine(record) {
|
|
8
|
-
const tool = String(record['tool']);
|
|
9
|
-
const command = record['command'];
|
|
10
|
-
const path = record['path'];
|
|
11
|
-
const line = typeof command === 'string'
|
|
12
|
-
? `${tool} ${command.split('\n')[0]}`
|
|
13
|
-
: typeof path === 'string'
|
|
14
|
-
? `${tool} ${path}`
|
|
15
|
-
: tool;
|
|
16
|
-
return truncate(line, TOOL_LINE_MAX, '…');
|
|
17
|
-
}
|
|
18
|
-
function stageName(step, record) {
|
|
19
|
-
const cause = record['cause'];
|
|
20
|
-
if (step === 'fix' && typeof cause === 'string') {
|
|
21
|
-
return `${cause} fix`;
|
|
22
|
-
}
|
|
23
|
-
if (step === 'commit-fix') {
|
|
24
|
-
return 'commit fix';
|
|
25
|
-
}
|
|
26
|
-
return step;
|
|
27
|
-
}
|
|
28
|
-
function stageOf(step, record) {
|
|
29
|
-
const name = stageName(step, record);
|
|
30
|
-
const round = record['round'];
|
|
31
|
-
const limit = record['limit'];
|
|
32
|
-
if (typeof round !== 'number') {
|
|
33
|
-
return name;
|
|
34
|
-
}
|
|
35
|
-
return typeof limit === 'number' ? `${name} ${round}/${limit}` : `${name} ${round}`;
|
|
36
|
-
}
|
|
37
|
-
function without(issues, issue) {
|
|
38
|
-
return issues.filter((current) => current.issue !== issue);
|
|
39
|
-
}
|
|
40
|
-
function change(progress, issue, update) {
|
|
41
|
-
return {
|
|
42
|
-
...progress,
|
|
43
|
-
issues: progress.issues.map((current) => (current.issue === issue ? update(current) : current)),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function addHandled(handled, issue, outcome) {
|
|
47
|
-
return outcome === 'done' || outcome === 'needs-human' || outcome === 'error'
|
|
48
|
-
? [...handled, { issue, outcome }]
|
|
49
|
-
: handled;
|
|
50
|
-
}
|
|
51
|
-
function started(issue, record) {
|
|
52
|
-
const next = {
|
|
53
|
-
issue,
|
|
54
|
-
tools: 0,
|
|
55
|
-
startedAt: Date.parse(String(record['ts'])),
|
|
56
|
-
};
|
|
57
|
-
if (typeof record['title'] === 'string') {
|
|
58
|
-
next.title = record['title'];
|
|
59
|
-
}
|
|
60
|
-
return next;
|
|
2
|
+
return { status: 'running', hunting };
|
|
61
3
|
}
|
|
62
4
|
export function applyEvent(progress, record) {
|
|
63
|
-
|
|
64
|
-
const issue = Number(record['issue']);
|
|
65
|
-
if (kind === 'issue.start') {
|
|
66
|
-
return { ...progress, issues: [...without(progress.issues, issue), started(issue, record)] };
|
|
67
|
-
}
|
|
68
|
-
if (kind === 'tool') {
|
|
69
|
-
return change(progress, issue, (current) => ({
|
|
70
|
-
...current,
|
|
71
|
-
tools: current.tools + 1,
|
|
72
|
-
lastTool: toolLine(record),
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
if (kind === 'issue.end' || kind === 'issue.error') {
|
|
76
|
-
const outcome = kind === 'issue.error' ? 'error' : record['outcome'];
|
|
77
|
-
const handled = addHandled(progress.handled, issue, outcome);
|
|
78
|
-
return { ...progress, issues: without(progress.issues, issue), handled };
|
|
79
|
-
}
|
|
80
|
-
if (kind === 'issues') {
|
|
81
|
-
return { ...progress, open: Number(record['open']) };
|
|
82
|
-
}
|
|
83
|
-
if (kind === 'issues.fail') {
|
|
5
|
+
if (record['kind'] === 'issues.fail') {
|
|
84
6
|
return { ...progress, error: String(record['error']) };
|
|
85
7
|
}
|
|
86
|
-
if (kind.endsWith('.start') && !NOT_STAGES.has(kind)) {
|
|
87
|
-
const stage = stageOf(kind.slice(0, -'.start'.length), record);
|
|
88
|
-
return change(progress, issue, (current) => ({ ...current, stage }));
|
|
89
|
-
}
|
|
90
8
|
return progress;
|
|
91
9
|
}
|
package/dist/worker/serve.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mkdir, rename, rm } from 'node:fs/promises';
|
|
2
|
-
import { createServer } from 'node:http';
|
|
2
|
+
import { createServer, STATUS_CODES } from 'node:http';
|
|
3
3
|
import { basename, dirname, join } from 'node:path';
|
|
4
4
|
import { WebSocketServer } from 'ws';
|
|
5
5
|
import { parseStartArgs } from '../shared/args.mjs';
|
|
@@ -7,14 +7,14 @@ import { stopChildren, withRunChildren } from '../shared/children.mjs';
|
|
|
7
7
|
import { message } from '../shared/errors.mjs';
|
|
8
8
|
import { lock } from '../shared/lock.mjs';
|
|
9
9
|
import { startProgress } from './progress.mjs';
|
|
10
|
-
import { isNewer
|
|
10
|
+
import { isNewer } from '../shared/protocol.mjs';
|
|
11
11
|
import { runRepo } from './run.mjs';
|
|
12
12
|
import { packageVersion } from '../shared/version.mjs';
|
|
13
13
|
import { resumeOnSuccessor } from '../shared/worker-client.mjs';
|
|
14
14
|
import { keepLogTrimmed, LOG_CHECK_MS } from './worker-log.mjs';
|
|
15
15
|
import { checkSocketPath, workerPaths } from '../shared/worker-paths.mjs';
|
|
16
16
|
import { active, dropUpgrade, endStatus, newRun, requestRefresh, requestStop, requestUpgrade, runControls, runsMessage, setHunting, setWatching, startRefusal, stoppingMessage, stopPoint, switchRefusal, } from './worker-run.mjs';
|
|
17
|
-
import { broadcast, closer, fileId, isLaunch, listen, parseMessage,
|
|
17
|
+
import { broadcast, closer, fileId, isLaunch, listen, parseMessage, removeOwned, send, sendAll, shutdown, stopListening, } from './worker-server.mjs';
|
|
18
18
|
const LOCK_WAIT_MS = 5_000;
|
|
19
19
|
const IDLE_MS = 30_000;
|
|
20
20
|
export async function startWorker(options) {
|
|
@@ -38,8 +38,6 @@ export async function startWorker(options) {
|
|
|
38
38
|
const busy = () => [...runs.values()].some(active);
|
|
39
39
|
let idleTimer;
|
|
40
40
|
const idleMs = options.idleMs ?? IDLE_MS;
|
|
41
|
-
let polledAt = Number.NEGATIVE_INFINITY;
|
|
42
|
-
const polled = () => Date.now() - polledAt < idleMs;
|
|
43
41
|
const handOver = async (how, run) => {
|
|
44
42
|
const listening = stopListening(server);
|
|
45
43
|
removeOwned(owned);
|
|
@@ -65,16 +63,10 @@ export async function startWorker(options) {
|
|
|
65
63
|
}
|
|
66
64
|
});
|
|
67
65
|
const closeWhenIdle = () => {
|
|
68
|
-
if ((restart !== undefined ||
|
|
66
|
+
if ((restart !== undefined || sockets.clients.size === 0) && !busy()) {
|
|
69
67
|
void close();
|
|
70
68
|
}
|
|
71
69
|
};
|
|
72
|
-
const idleTimeUp = () => {
|
|
73
|
-
if (polled()) {
|
|
74
|
-
idleTimer = setTimeout(idleTimeUp, idleMs - (Date.now() - polledAt));
|
|
75
|
-
}
|
|
76
|
-
closeWhenIdle();
|
|
77
|
-
};
|
|
78
70
|
const upgradeBetweenIssues = (run) => {
|
|
79
71
|
if (restart === undefined) {
|
|
80
72
|
return;
|
|
@@ -221,54 +213,16 @@ export async function startWorker(options) {
|
|
|
221
213
|
}
|
|
222
214
|
});
|
|
223
215
|
});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const refusal = (text) => [
|
|
229
|
-
{ type: 'error', root: options.root, message: text },
|
|
230
|
-
];
|
|
231
|
-
if (request.url !== '/') {
|
|
232
|
-
reply(response, 404, refusal('the worker answers on / only'));
|
|
233
|
-
}
|
|
234
|
-
else if (request.method === 'GET') {
|
|
235
|
-
reply(response, 200, [{ type: 'hello', version: options.version }, runsMessage(runs)]);
|
|
236
|
-
}
|
|
237
|
-
else if (request.method !== 'POST') {
|
|
238
|
-
reply(response, 405, refusal('the worker answers GET and POST only'));
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
let body;
|
|
242
|
-
try {
|
|
243
|
-
body = await readBody(request);
|
|
244
|
-
}
|
|
245
|
-
catch {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
const value = parseMessage(body);
|
|
249
|
-
if (value === undefined) {
|
|
250
|
-
reply(response, 400, refusal('the request is not a next-issue message'));
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
const replies = [];
|
|
254
|
-
const peer = { send: (data) => replies.push(JSON.parse(data)) };
|
|
255
|
-
const refuse = refuser(peer, value, options.root);
|
|
256
|
-
try {
|
|
257
|
-
receive(peer, value, refuse);
|
|
258
|
-
}
|
|
259
|
-
catch (error) {
|
|
260
|
-
refuse(message(error));
|
|
261
|
-
}
|
|
262
|
-
reply(response, 200, [...replies, runsMessage(runs)]);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
server.on('request', (request, response) => void answer(request, response));
|
|
216
|
+
server.on('request', (_request, response) => {
|
|
217
|
+
response.writeHead(426, { connection: 'close' });
|
|
218
|
+
response.end(STATUS_CODES[426]);
|
|
219
|
+
});
|
|
266
220
|
const draft = join(dirname(options.socketPath), `~${basename(options.socketPath).slice(1)}`);
|
|
267
221
|
await rm(draft, { force: true });
|
|
268
222
|
await listen(server, draft);
|
|
269
223
|
await rename(draft, options.socketPath);
|
|
270
224
|
owned.socket = fileId(options.socketPath);
|
|
271
|
-
idleTimer = setTimeout(
|
|
225
|
+
idleTimer = setTimeout(closeWhenIdle, idleMs);
|
|
272
226
|
return { closed, close, release: () => removeOwned(owned) };
|
|
273
227
|
}
|
|
274
228
|
function upgradedRun(run) {
|
|
@@ -48,26 +48,6 @@ export function sendAll(sockets, value) {
|
|
|
48
48
|
send(socket, value);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
const BODY_LIMIT = 1024 * 1024;
|
|
52
|
-
export function readBody(request) {
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
let body = '';
|
|
55
|
-
request.setEncoding('utf8');
|
|
56
|
-
request.on('data', (chunk) => {
|
|
57
|
-
body += chunk;
|
|
58
|
-
if (body.length > BODY_LIMIT) {
|
|
59
|
-
resolve('');
|
|
60
|
-
request.destroy();
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
request.on('end', () => resolve(body));
|
|
64
|
-
request.on('error', reject);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
export function reply(response, status, messages) {
|
|
68
|
-
response.writeHead(status, { 'content-type': 'application/json', connection: 'close' });
|
|
69
|
-
response.end(JSON.stringify(messages));
|
|
70
|
-
}
|
|
71
51
|
export function listen(server, path) {
|
|
72
52
|
return new Promise((resolve, reject) => {
|
|
73
53
|
server.once('error', reject);
|