next-issue 14.4.9 → 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/README.md +1 -1
- package/dist/cli/switch-run.mjs +21 -0
- package/dist/cli.mjs +3 -13
- package/dist/shared/args.mjs +1 -1
- package/dist/shared/hand-over-comments.mjs +0 -46
- package/dist/shared/handover.mjs +0 -1
- package/dist/shared/lock.mjs +0 -21
- package/dist/worker/progress.mjs +2 -84
- package/dist/worker/serve.mjs +11 -73
- package/dist/worker/worker-run.mjs +2 -10
- package/dist/worker/worker-server.mjs +3 -21
- package/package.json +1 -1
- package/dist/worker/questions.mjs +0 -45
- package/dist/worker/upcoming.mjs +0 -39
package/README.md
CHANGED
|
@@ -93,7 +93,7 @@ A field that is not in the file keeps its default. See [Configuration](https://g
|
|
|
93
93
|
| `refresh` | Ask the going run to check for new issues now |
|
|
94
94
|
| `init` | Write the config file with the defaults |
|
|
95
95
|
| `serve` | Run the worker of this repository that the clients talk to |
|
|
96
|
-
| `stop` | Stop the
|
|
96
|
+
| `stop` | Stop the going run after its current issues |
|
|
97
97
|
| `logs` | Show the latest run log and follow it |
|
|
98
98
|
| `update` | Install the `create-issue` and `answer-hand-over` skills for Claude Code |
|
|
99
99
|
| `--force` | With `init`: replace an existing config file |
|
package/dist/cli/switch-run.mjs
CHANGED
|
@@ -73,3 +73,24 @@ function switched(connection, root, name, on) {
|
|
|
73
73
|
sent = true;
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
+
export async function stopInWorker(root) {
|
|
77
|
+
const connection = await findWorker(root);
|
|
78
|
+
if (connection === undefined) {
|
|
79
|
+
return NO_RUN;
|
|
80
|
+
}
|
|
81
|
+
const progress = connection.runs[root];
|
|
82
|
+
if (!going(progress)) {
|
|
83
|
+
connection.close();
|
|
84
|
+
return NO_RUN;
|
|
85
|
+
}
|
|
86
|
+
if (progress.status === 'stopping' && progress.upgrade === undefined) {
|
|
87
|
+
connection.close();
|
|
88
|
+
return 'next-issue: the run is stopping already\n';
|
|
89
|
+
}
|
|
90
|
+
connection.send({ type: 'stop', root, after: 'issue' });
|
|
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
|
+
}
|
|
95
|
+
return 'next-issue: the run will stop after its current issues\n';
|
|
96
|
+
}
|
package/dist/cli.mjs
CHANGED
|
@@ -5,14 +5,12 @@ import { OLD_CONFIG_FILE } from './shared/config-fields.mjs';
|
|
|
5
5
|
import { message } from './shared/errors.mjs';
|
|
6
6
|
import { repoRoot } from './shared/git.mjs';
|
|
7
7
|
import { ensureExcluded, excludeFile, removeIgnored } from './cli/ignore.mjs';
|
|
8
|
-
import { stopWorker } from './shared/lock.mjs';
|
|
9
8
|
import { followLog, newestRunLog } from './cli/logs.mjs';
|
|
10
9
|
import { serve } from './worker/serve.mjs';
|
|
11
10
|
import { startInWorker } from './cli/start.mjs';
|
|
12
11
|
import { STATE_DIR } from './shared/state.mjs';
|
|
13
|
-
import { refreshInWorker, switchInWorker } from './cli/switch-run.mjs';
|
|
12
|
+
import { refreshInWorker, stopInWorker, switchInWorker } from './cli/switch-run.mjs';
|
|
14
13
|
import { chooseScope, installSkills } from './cli/update.mjs';
|
|
15
|
-
import { workerPaths } from './shared/worker-paths.mjs';
|
|
16
14
|
import { WORKTREE_DIR } from './shared/worktree.mjs';
|
|
17
15
|
function write(stream, text) {
|
|
18
16
|
return new Promise((resolve, reject) => {
|
|
@@ -39,7 +37,8 @@ async function main() {
|
|
|
39
37
|
}
|
|
40
38
|
await rejectOldConfig(root);
|
|
41
39
|
if (args.command === 'stop') {
|
|
42
|
-
|
|
40
|
+
await write(process.stdout, await stopInWorker(root));
|
|
41
|
+
return 0;
|
|
43
42
|
}
|
|
44
43
|
if (args.command === 'watch' || args.command === 'hunt') {
|
|
45
44
|
await write(process.stdout, await switchInWorker(root, args.command, args.on));
|
|
@@ -62,15 +61,6 @@ function run(root, args, argv) {
|
|
|
62
61
|
process.stderr.on('error', () => { });
|
|
63
62
|
return startInWorker(root, args, argv.slice(1));
|
|
64
63
|
}
|
|
65
|
-
const STOPPED = {
|
|
66
|
-
none: () => 'next-issue: no worker is running\n',
|
|
67
|
-
worker: (pid) => `next-issue: stopped the worker with process id ${pid}\n`,
|
|
68
|
-
};
|
|
69
|
-
async function stop(root) {
|
|
70
|
-
const { stopped, pid } = await stopWorker(workerPaths(root));
|
|
71
|
-
await write(process.stdout, STOPPED[stopped](pid));
|
|
72
|
-
return 0;
|
|
73
|
-
}
|
|
74
64
|
async function logs(root) {
|
|
75
65
|
const file = await newestRunLog(root);
|
|
76
66
|
if (file === undefined) {
|
package/dist/shared/args.mjs
CHANGED
|
@@ -28,7 +28,7 @@ export const USAGE = `next-issue <command> [options]
|
|
|
28
28
|
refresh ask the going run to check for new issues now
|
|
29
29
|
init write ${CONFIG_FILE} with the defaults and add .next-issue/ and .worktrees/ to info/exclude
|
|
30
30
|
serve run the worker of this repository that the clients talk to
|
|
31
|
-
stop stop the
|
|
31
|
+
stop stop the going run after its current issues
|
|
32
32
|
logs show the latest run log and follow it
|
|
33
33
|
update install the create-issue and answer-hand-over skills for Claude Code
|
|
34
34
|
--scope user|project
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { repoArg } from './gh.mjs';
|
|
2
|
-
import { heldByPerson, readState } from './state.mjs';
|
|
3
1
|
import { AGENT_PREFIX, agentHeading } from './text.mjs';
|
|
4
2
|
export const HAND_OVER = agentHeading('Hand-over', 'needs help');
|
|
5
3
|
const OLD_HAND_OVER = 'next-issue needs help:';
|
|
@@ -54,18 +52,6 @@ async function handOverThread(repo, ports, writer, issue) {
|
|
|
54
52
|
const comments = await ports.threadComments(repo, issue);
|
|
55
53
|
return { comments, last: await lastHandOver(comments, writer) };
|
|
56
54
|
}
|
|
57
|
-
export async function waitingQuestions(repo, config, ports) {
|
|
58
|
-
const writer = writers(repo, ports);
|
|
59
|
-
const issues = await ports.openIssues(repo, config.issueLimit, [config.labels.needsHuman]);
|
|
60
|
-
const questions = [];
|
|
61
|
-
for (const issue of issues) {
|
|
62
|
-
const question = await waitingQuestion(repo, config, ports, writer, issue);
|
|
63
|
-
if (question) {
|
|
64
|
-
questions.push(question);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return questions;
|
|
68
|
-
}
|
|
69
55
|
function postedAfter(comment, since) {
|
|
70
56
|
return since !== undefined && comment.createdAt !== undefined && comment.createdAt > since;
|
|
71
57
|
}
|
|
@@ -79,38 +65,6 @@ function answerCandidates(comments, last, pending) {
|
|
|
79
65
|
async function replyAfter(comments, last, writer, pending) {
|
|
80
66
|
return writerQuotes(answerCandidates(comments, last, pending).filter((comment) => !fromHarness(comment)), writer);
|
|
81
67
|
}
|
|
82
|
-
async function savedState(repo, issue) {
|
|
83
|
-
try {
|
|
84
|
-
return await readState(repo, issue);
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async function waitingQuestion(repo, config, ports, writer, issue) {
|
|
91
|
-
const { comments, last } = await handOverThread(repo, ports, writer, issue.number);
|
|
92
|
-
const saved = await savedState(repo, issue.number);
|
|
93
|
-
const pending = saved?.pendingHandOver;
|
|
94
|
-
if (!heldByPerson(saved) && (await replyAfter(comments, last, writer, pending)).length > 0) {
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
const latest = comments[last];
|
|
98
|
-
const comment = pending === undefined || (latest !== undefined && postedAfter(latest, pending.since))
|
|
99
|
-
? latest
|
|
100
|
-
: undefined;
|
|
101
|
-
return {
|
|
102
|
-
issue: issue.number,
|
|
103
|
-
title: issue.title,
|
|
104
|
-
reason: (comment && handOverReason(comment)) ?? pending?.reason ?? '',
|
|
105
|
-
url: comment?.url ?? '',
|
|
106
|
-
repo: repoArg(repo),
|
|
107
|
-
labels: {
|
|
108
|
-
needsHuman: config.labels.needsHuman,
|
|
109
|
-
skip: config.labels.skip,
|
|
110
|
-
ready: config.labels.ready,
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
68
|
export async function writerComments(context, log, issue) {
|
|
115
69
|
const { repo, ports } = context;
|
|
116
70
|
const comments = (await ports.issueComments(repo, issue)).filter((comment) => !fromHarness(comment));
|
package/dist/shared/handover.mjs
CHANGED
|
@@ -206,7 +206,6 @@ export async function claimedError(context, log, issue, state, error, started) {
|
|
|
206
206
|
catch (failure) {
|
|
207
207
|
log.event('hand-over.error', { error: message(failure) });
|
|
208
208
|
}
|
|
209
|
-
// The issue ends (and the waiting questions go out) only once the hand-over is done.
|
|
210
209
|
logIssueError(log, error, started);
|
|
211
210
|
await cleanUp(context, log, state.branch);
|
|
212
211
|
const report = {
|
package/dist/shared/lock.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { execFile } from 'node:child_process';
|
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { readFileSync, statSync } from 'node:fs';
|
|
4
4
|
import { link, open, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
5
|
-
import { createConnection } from 'node:net';
|
|
6
5
|
import { basename, dirname, join } from 'node:path';
|
|
7
6
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
8
7
|
import { promisify } from 'node:util';
|
|
@@ -151,26 +150,6 @@ async function removeDeadDrafts(path) {
|
|
|
151
150
|
}
|
|
152
151
|
}
|
|
153
152
|
}
|
|
154
|
-
function takesConnection(socketPath) {
|
|
155
|
-
return new Promise((resolve) => {
|
|
156
|
-
const socket = createConnection(socketPath);
|
|
157
|
-
socket.once('connect', () => {
|
|
158
|
-
socket.destroy();
|
|
159
|
-
resolve(true);
|
|
160
|
-
});
|
|
161
|
-
socket.once('error', () => resolve(false));
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
export async function stopWorker(paths) {
|
|
165
|
-
const text = await readTextOrEmpty(paths.lockPath);
|
|
166
|
-
const pid = await holderOf(text);
|
|
167
|
-
const unverified = text.trim().split(' ').length === 1;
|
|
168
|
-
if (pid === undefined || (unverified && !(await takesConnection(paths.socketPath)))) {
|
|
169
|
-
return { stopped: 'none' };
|
|
170
|
-
}
|
|
171
|
-
process.kill(pid, 'SIGTERM');
|
|
172
|
-
return { stopped: 'worker', pid };
|
|
173
|
-
}
|
|
174
153
|
function textOf(path) {
|
|
175
154
|
try {
|
|
176
155
|
return readFileSync(path, 'utf8');
|
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,6 +1,5 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
1
|
import { mkdir, rename, rm } from 'node:fs/promises';
|
|
3
|
-
import { createServer } from 'node:http';
|
|
2
|
+
import { createServer, STATUS_CODES } from 'node:http';
|
|
4
3
|
import { basename, dirname, join } from 'node:path';
|
|
5
4
|
import { WebSocketServer } from 'ws';
|
|
6
5
|
import { parseStartArgs } from '../shared/args.mjs';
|
|
@@ -8,16 +7,14 @@ import { stopChildren, withRunChildren } from '../shared/children.mjs';
|
|
|
8
7
|
import { message } from '../shared/errors.mjs';
|
|
9
8
|
import { lock } from '../shared/lock.mjs';
|
|
10
9
|
import { startProgress } from './progress.mjs';
|
|
11
|
-
import { isNewer
|
|
12
|
-
import { listQuestions, questionSender, send, } from './questions.mjs';
|
|
10
|
+
import { isNewer } from '../shared/protocol.mjs';
|
|
13
11
|
import { runRepo } from './run.mjs';
|
|
14
|
-
import { listUpcoming, sendUpcoming } from './upcoming.mjs';
|
|
15
12
|
import { packageVersion } from '../shared/version.mjs';
|
|
16
13
|
import { resumeOnSuccessor } from '../shared/worker-client.mjs';
|
|
17
14
|
import { keepLogTrimmed, LOG_CHECK_MS } from './worker-log.mjs';
|
|
18
15
|
import { checkSocketPath, workerPaths } from '../shared/worker-paths.mjs';
|
|
19
16
|
import { active, dropUpgrade, endStatus, newRun, requestRefresh, requestStop, requestUpgrade, runControls, runsMessage, setHunting, setWatching, startRefusal, stoppingMessage, stopPoint, switchRefusal, } from './worker-run.mjs';
|
|
20
|
-
import { broadcast, closer, fileId, isLaunch, listen, parseMessage,
|
|
17
|
+
import { broadcast, closer, fileId, isLaunch, listen, parseMessage, removeOwned, send, sendAll, shutdown, stopListening, } from './worker-server.mjs';
|
|
21
18
|
const LOCK_WAIT_MS = 5_000;
|
|
22
19
|
const IDLE_MS = 30_000;
|
|
23
20
|
export async function startWorker(options) {
|
|
@@ -38,15 +35,9 @@ export async function startWorker(options) {
|
|
|
38
35
|
let successor;
|
|
39
36
|
const server = createServer();
|
|
40
37
|
const sockets = new WebSocketServer({ server });
|
|
41
|
-
const sendQuestions = questionSender(options.questions);
|
|
42
|
-
// Taken outside any run, so a question read that an issue end starts does not take on
|
|
43
|
-
// the run's stop, command log, children or default timeout.
|
|
44
|
-
const outsideRuns = AsyncLocalStorage.snapshot();
|
|
45
38
|
const busy = () => [...runs.values()].some(active);
|
|
46
39
|
let idleTimer;
|
|
47
40
|
const idleMs = options.idleMs ?? IDLE_MS;
|
|
48
|
-
let polledAt = Number.NEGATIVE_INFINITY;
|
|
49
|
-
const polled = () => Date.now() - polledAt < idleMs;
|
|
50
41
|
const handOver = async (how, run) => {
|
|
51
42
|
const listening = stopListening(server);
|
|
52
43
|
removeOwned(owned);
|
|
@@ -72,16 +63,10 @@ export async function startWorker(options) {
|
|
|
72
63
|
}
|
|
73
64
|
});
|
|
74
65
|
const closeWhenIdle = () => {
|
|
75
|
-
if ((restart !== undefined ||
|
|
66
|
+
if ((restart !== undefined || sockets.clients.size === 0) && !busy()) {
|
|
76
67
|
void close();
|
|
77
68
|
}
|
|
78
69
|
};
|
|
79
|
-
const idleTimeUp = () => {
|
|
80
|
-
if (polled()) {
|
|
81
|
-
idleTimer = setTimeout(idleTimeUp, idleMs - (Date.now() - polledAt));
|
|
82
|
-
}
|
|
83
|
-
closeWhenIdle();
|
|
84
|
-
};
|
|
85
70
|
const upgradeBetweenIssues = (run) => {
|
|
86
71
|
if (restart === undefined) {
|
|
87
72
|
return;
|
|
@@ -120,7 +105,7 @@ export async function startWorker(options) {
|
|
|
120
105
|
broadcast(sockets, runs);
|
|
121
106
|
let summary;
|
|
122
107
|
withRunChildren(run.children, () => options.runRepo(root, args, {
|
|
123
|
-
...runControls(run, update
|
|
108
|
+
...runControls(run, update),
|
|
124
109
|
print: args.watch
|
|
125
110
|
? async (pass) => sendAll(sockets, { type: 'pass', root, summary: pass })
|
|
126
111
|
: undefined,
|
|
@@ -208,18 +193,10 @@ export async function startWorker(options) {
|
|
|
208
193
|
else if (value.type === 'refresh') {
|
|
209
194
|
requestRefresh(runs.get(value.root));
|
|
210
195
|
}
|
|
211
|
-
else if (value.type === 'questions') {
|
|
212
|
-
return sendQuestions(value.root, () => [socket], value.id);
|
|
213
|
-
}
|
|
214
|
-
else if (value.type === 'upcoming') {
|
|
215
|
-
return sendUpcoming(options.upcoming ?? listUpcoming, socket, value.root);
|
|
216
|
-
}
|
|
217
|
-
return undefined;
|
|
218
196
|
};
|
|
219
197
|
sockets.on('connection', (socket) => {
|
|
220
198
|
send(socket, { type: 'hello', version: options.version });
|
|
221
199
|
send(socket, runsMessage(runs));
|
|
222
|
-
void sendQuestions(options.root, () => [socket]);
|
|
223
200
|
socket.on('close', closeWhenIdle);
|
|
224
201
|
socket.on('error', () => socket.terminate());
|
|
225
202
|
socket.on('message', (data) => {
|
|
@@ -229,61 +206,23 @@ export async function startWorker(options) {
|
|
|
229
206
|
}
|
|
230
207
|
const refuse = refuser(socket, value, options.root);
|
|
231
208
|
try {
|
|
232
|
-
|
|
209
|
+
receive(socket, value, refuse);
|
|
233
210
|
}
|
|
234
211
|
catch (error) {
|
|
235
212
|
refuse(message(error));
|
|
236
213
|
}
|
|
237
214
|
});
|
|
238
215
|
});
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const refusal = (text) => [
|
|
244
|
-
{ type: 'error', root: options.root, message: text },
|
|
245
|
-
];
|
|
246
|
-
if (request.url !== '/') {
|
|
247
|
-
reply(response, 404, refusal('the worker answers on / only'));
|
|
248
|
-
}
|
|
249
|
-
else if (request.method === 'GET') {
|
|
250
|
-
reply(response, 200, [{ type: 'hello', version: options.version }, runsMessage(runs)]);
|
|
251
|
-
}
|
|
252
|
-
else if (request.method !== 'POST') {
|
|
253
|
-
reply(response, 405, refusal('the worker answers GET and POST only'));
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
let body;
|
|
257
|
-
try {
|
|
258
|
-
body = await readBody(request);
|
|
259
|
-
}
|
|
260
|
-
catch {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
const value = parseMessage(body);
|
|
264
|
-
if (value === undefined) {
|
|
265
|
-
reply(response, 400, refusal('the request is not a next-issue message'));
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
const replies = [];
|
|
269
|
-
const peer = { send: (data) => replies.push(JSON.parse(data)) };
|
|
270
|
-
const refuse = refuser(peer, value, options.root);
|
|
271
|
-
try {
|
|
272
|
-
await receive(peer, value, refuse);
|
|
273
|
-
}
|
|
274
|
-
catch (error) {
|
|
275
|
-
refuse(message(error));
|
|
276
|
-
}
|
|
277
|
-
reply(response, 200, [...replies, runsMessage(runs)]);
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
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
|
+
});
|
|
281
220
|
const draft = join(dirname(options.socketPath), `~${basename(options.socketPath).slice(1)}`);
|
|
282
221
|
await rm(draft, { force: true });
|
|
283
222
|
await listen(server, draft);
|
|
284
223
|
await rename(draft, options.socketPath);
|
|
285
224
|
owned.socket = fileId(options.socketPath);
|
|
286
|
-
idleTimer = setTimeout(
|
|
225
|
+
idleTimer = setTimeout(closeWhenIdle, idleMs);
|
|
287
226
|
return { closed, close, release: () => removeOwned(owned) };
|
|
288
227
|
}
|
|
289
228
|
function upgradedRun(run) {
|
|
@@ -305,7 +244,6 @@ export async function serve(root, logCheckMs = LOG_CHECK_MS) {
|
|
|
305
244
|
...paths,
|
|
306
245
|
version: await packageVersion(),
|
|
307
246
|
runRepo,
|
|
308
|
-
questions: listQuestions,
|
|
309
247
|
});
|
|
310
248
|
if (worker === undefined) {
|
|
311
249
|
stopTrimming();
|
|
@@ -37,9 +37,6 @@ export function runsMessage(runs) {
|
|
|
37
37
|
runs: Object.fromEntries([...runs].map(([root, run]) => [root, run.progress])),
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
function endsIssue(record) {
|
|
41
|
-
return record['kind'] === 'issue.end' || record['kind'] === 'issue.error';
|
|
42
|
-
}
|
|
43
40
|
export function stopPoint(after) {
|
|
44
41
|
return STOP_POINTS.find((point) => point === (after ?? 'issue'));
|
|
45
42
|
}
|
|
@@ -128,17 +125,12 @@ function runInterrupts(run) {
|
|
|
128
125
|
},
|
|
129
126
|
};
|
|
130
127
|
}
|
|
131
|
-
export function runControls(run, update
|
|
128
|
+
export function runControls(run, update) {
|
|
132
129
|
return {
|
|
133
130
|
interrupts: runInterrupts(run),
|
|
134
131
|
hunting: run.hunting,
|
|
135
132
|
watching: run.watching,
|
|
136
133
|
refreshed: run.refresher.refreshed,
|
|
137
|
-
onEvent: (record) =>
|
|
138
|
-
update(applyEvent(run.progress, record));
|
|
139
|
-
if (endsIssue(record)) {
|
|
140
|
-
issueEnded();
|
|
141
|
-
}
|
|
142
|
-
},
|
|
134
|
+
onEvent: (record) => update(applyEvent(run.progress, record)),
|
|
143
135
|
};
|
|
144
136
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { rmSync, statSync } from 'node:fs';
|
|
2
|
-
import { send } from './questions.mjs';
|
|
3
2
|
import { runsMessage } from './worker-run.mjs';
|
|
4
3
|
function isRecord(value) {
|
|
5
4
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
@@ -38,6 +37,9 @@ export function parseMessage(text) {
|
|
|
38
37
|
}
|
|
39
38
|
return isClientMessage(value) ? value : undefined;
|
|
40
39
|
}
|
|
40
|
+
export function send(socket, value) {
|
|
41
|
+
socket.send(JSON.stringify(value));
|
|
42
|
+
}
|
|
41
43
|
export function broadcast(sockets, runs) {
|
|
42
44
|
sendAll(sockets, runsMessage(runs));
|
|
43
45
|
}
|
|
@@ -46,26 +48,6 @@ export function sendAll(sockets, value) {
|
|
|
46
48
|
send(socket, value);
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
|
-
const BODY_LIMIT = 1024 * 1024;
|
|
50
|
-
export function readBody(request) {
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
let body = '';
|
|
53
|
-
request.setEncoding('utf8');
|
|
54
|
-
request.on('data', (chunk) => {
|
|
55
|
-
body += chunk;
|
|
56
|
-
if (body.length > BODY_LIMIT) {
|
|
57
|
-
resolve('');
|
|
58
|
-
request.destroy();
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
request.on('end', () => resolve(body));
|
|
62
|
-
request.on('error', reject);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
export function reply(response, status, messages) {
|
|
66
|
-
response.writeHead(status, { 'content-type': 'application/json', connection: 'close' });
|
|
67
|
-
response.end(JSON.stringify(messages));
|
|
68
|
-
}
|
|
69
51
|
export function listen(server, path) {
|
|
70
52
|
return new Promise((resolve, reject) => {
|
|
71
53
|
server.once('error', reject);
|
package/package.json
CHANGED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from '../shared/config.mjs';
|
|
2
|
-
import { message } from '../shared/errors.mjs';
|
|
3
|
-
import { detectRepo } from '../shared/git.mjs';
|
|
4
|
-
import { waitingQuestions } from '../shared/hand-over-comments.mjs';
|
|
5
|
-
import { PORTS } from '../shared/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/worker/upcoming.mjs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from '../shared/config.mjs';
|
|
2
|
-
import { message } from '../shared/errors.mjs';
|
|
3
|
-
import { detectRepo } from '../shared/git.mjs';
|
|
4
|
-
import { PORTS } from '../shared/ports.mjs';
|
|
5
|
-
import { send } from './questions.mjs';
|
|
6
|
-
import { listedIssues, skipReason } from '../shared/skip.mjs';
|
|
7
|
-
import { savedIssues } from '../shared/state.mjs';
|
|
8
|
-
/** The fresh issues the worker would claim, oldest first as it claims them; issues with saved state resume instead. */
|
|
9
|
-
export async function upcomingIssues(repo, config, ports) {
|
|
10
|
-
const issues = await listedIssues(ports, repo, config, []);
|
|
11
|
-
const saved = new Set(await savedIssues(repo));
|
|
12
|
-
const upcoming = { claimable: [], blocked: [] };
|
|
13
|
-
for (const issue of issues) {
|
|
14
|
-
if (saved.has(issue.number) || skipReason(issue, config, false) !== undefined) {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
const blockers = await ports.openBlockers(repo, issue.number);
|
|
18
|
-
const item = { issue: issue.number, title: issue.title };
|
|
19
|
-
if (blockers.length > 0) {
|
|
20
|
-
upcoming.blocked.push({ ...item, blockers });
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
upcoming.claimable.push(item);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return upcoming;
|
|
27
|
-
}
|
|
28
|
-
export async function listUpcoming(root) {
|
|
29
|
-
const config = await loadConfig(root);
|
|
30
|
-
return upcomingIssues(await detectRepo(root, config.remote), config, PORTS);
|
|
31
|
-
}
|
|
32
|
-
export async function sendUpcoming(list, socket, root) {
|
|
33
|
-
try {
|
|
34
|
-
send(socket, { type: 'upcoming', root, ...(await list(root)) });
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
send(socket, { type: 'upcoming-error', root, message: message(error) });
|
|
38
|
-
}
|
|
39
|
-
}
|