next-issue 6.6.25 → 6.6.27
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 +6 -1
- package/dist/lock.mjs +3 -3
- package/dist/run.mjs +31 -1
- package/dist/worktree.mjs +21 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,8 @@ not tried again in that run. The run ends when no unseen issue is left. When
|
|
|
37
37
|
the fetch fails, the run claims no new issue, ends once the running issues end,
|
|
38
38
|
writes the summary of the issues it handled and exits with code 1.
|
|
39
39
|
|
|
40
|
+
Only one run goes at a time in a repository. A run holds `.next-issue/run.lock`, with its process id and the start time of that process, from its start to its end, and the worker takes the same lock for each run it starts. A run that starts while another run, from the worker or from the command line, is going claims no issue and fails at once with an error that names the other run and its process id (a command-line run exits with code 1, and a run started from the worker ends with status `failed` and the error text): `the worker (process id <n>) has a run going in this repository` or `another next-issue run (process id <n>) is going in this repository`. A lock whose process is gone, or started at another time, is stale and taken over, as with the worker lock.
|
|
41
|
+
|
|
40
42
|
A run handles up to `concurrency` issues at the same time, 1 by default. When an
|
|
41
43
|
issue ends, the run fetches the open issues again and claims the oldest unseen
|
|
42
44
|
one for the free slot. Each issue has its own worktree and branch. Step 3 below
|
|
@@ -64,7 +66,10 @@ the run handles one issue. For each issue:
|
|
|
64
66
|
no commits of its own starts again from the remote base. An issue with no
|
|
65
67
|
saved state does not reuse a local `<n>` branch: it resets that branch,
|
|
66
68
|
and any worktree that holds it, to the remote branch, or to the remote
|
|
67
|
-
base when there is none.
|
|
69
|
+
base when there is none. The main worktree of the repository is never
|
|
70
|
+
used, reset or cleaned: when it has the branch of the issue checked out,
|
|
71
|
+
the issue fails and is handed over, and the reason asks you to check out
|
|
72
|
+
another branch there. A fast-forward of the base that is not safe
|
|
68
73
|
leaves the local base branch as it is and writes a `base.behind` event. A
|
|
69
74
|
new branch then starts from the remote base.
|
|
70
75
|
4. Let the implementer agent do the work, then commit it. For a behaviour
|
package/dist/lock.mjs
CHANGED
|
@@ -38,7 +38,7 @@ async function holderOf(text) {
|
|
|
38
38
|
}
|
|
39
39
|
return (await processStart(pid)) === started ? pid : undefined;
|
|
40
40
|
}
|
|
41
|
-
async function
|
|
41
|
+
export async function lockHolder(lockPath) {
|
|
42
42
|
return holderOf(await readTextOrEmpty(lockPath));
|
|
43
43
|
}
|
|
44
44
|
function idOf(found) {
|
|
@@ -144,7 +144,7 @@ async function removeDeadDrafts(path) {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
export async function stopWorker(lockPath) {
|
|
147
|
-
const pid = await
|
|
147
|
+
const pid = await lockHolder(lockPath);
|
|
148
148
|
if (pid !== undefined) {
|
|
149
149
|
process.kill(pid, 'SIGTERM');
|
|
150
150
|
}
|
|
@@ -169,7 +169,7 @@ function heldLock(path, id, text) {
|
|
|
169
169
|
export async function lock(path, waitMs, readStart = processStart) {
|
|
170
170
|
const started = await readStart(process.pid);
|
|
171
171
|
if (started === undefined) {
|
|
172
|
-
throw new Error('next-issue: cannot read the start time of
|
|
172
|
+
throw new Error('next-issue: cannot read the start time of this process');
|
|
173
173
|
}
|
|
174
174
|
const text = `${process.pid} ${started}\n`;
|
|
175
175
|
const deadline = Date.now() + waitMs;
|
package/dist/run.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { mkdir, rm } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
1
3
|
import { recordCommands } from './command-records.mjs';
|
|
2
4
|
import { loadConfig } from './config.mjs';
|
|
3
5
|
import { minutesToMs } from './durations.mjs';
|
|
@@ -8,16 +10,44 @@ import { slug } from './gh.mjs';
|
|
|
8
10
|
import { detectRepo } from './git.mjs';
|
|
9
11
|
import { defaultBranch } from './github.mjs';
|
|
10
12
|
import { hunter } from './hunt.mjs';
|
|
13
|
+
import { lock, lockHolder } from './lock.mjs';
|
|
11
14
|
import { exitCode, runIssues } from './loop.mjs';
|
|
12
15
|
import { Recorder } from './observe.mjs';
|
|
13
16
|
import { pendingIssues } from './pending.mjs';
|
|
14
17
|
import { processIssue } from './pipeline.mjs';
|
|
15
18
|
import { PORTS } from './ports.mjs';
|
|
16
19
|
import { pruneRuns } from './prune-runs.mjs';
|
|
20
|
+
import { stateDir } from './state.mjs';
|
|
17
21
|
import { count } from './summary.mjs';
|
|
18
22
|
import { packageVersion } from './version.mjs';
|
|
19
23
|
import { watchIssues } from './watch.mjs';
|
|
20
|
-
|
|
24
|
+
import { workerPaths } from './worker-paths.mjs';
|
|
25
|
+
export function runRepo(root, args, controls) {
|
|
26
|
+
return withRunLock(root, () => runLoaded(root, args, controls));
|
|
27
|
+
}
|
|
28
|
+
async function withRunLock(root, work) {
|
|
29
|
+
await mkdir(stateDir(root), { recursive: true });
|
|
30
|
+
const path = join(stateDir(root), 'run.lock');
|
|
31
|
+
const held = await lock(path, 0);
|
|
32
|
+
if (held === undefined) {
|
|
33
|
+
throw new Error(await runningMessage(root, path));
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return await work();
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
if (held.owns()) {
|
|
40
|
+
await rm(path, { force: true });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function runningMessage(root, path) {
|
|
45
|
+
const pid = await lockHolder(path);
|
|
46
|
+
return pid !== undefined && pid === (await lockHolder(workerPaths(root).lockPath))
|
|
47
|
+
? `the worker (process id ${pid}) has a run going in this repository`
|
|
48
|
+
: `another next-issue run (process id ${pid ?? 'unknown'}) is going in this repository`;
|
|
49
|
+
}
|
|
50
|
+
async function runLoaded(root, args, controls) {
|
|
21
51
|
const config = await loadConfig(root);
|
|
22
52
|
return withDefaultTimeout(minutesToMs(config.commandTimeoutMinutes), () => runWithConfig(root, args, controls, config));
|
|
23
53
|
}
|
package/dist/worktree.mjs
CHANGED
|
@@ -14,6 +14,7 @@ export async function addWorktree(repo, issue, branch, base, remote, start) {
|
|
|
14
14
|
const baseUpdated = await fastForwardBase(repo, base, remote);
|
|
15
15
|
await git(repo.root, ['worktree', 'prune']);
|
|
16
16
|
await releaseFromHunt(repo, branch);
|
|
17
|
+
await refuseMainWorktree(repo, branch);
|
|
17
18
|
const pushed = await hasBranch(repo, upstream, '--remotes');
|
|
18
19
|
const existing = await findWorktree(repo, branch);
|
|
19
20
|
const path = existing ?? worktreePath(repo, issue);
|
|
@@ -55,13 +56,22 @@ async function updateBase(repo, base, remote) {
|
|
|
55
56
|
return oneFetchAtATime(() => succeeds(repo.root, args));
|
|
56
57
|
}
|
|
57
58
|
export async function findWorktree(repo, branch) {
|
|
58
|
-
const
|
|
59
|
-
|
|
59
|
+
const found = await holder(repo, branch);
|
|
60
|
+
if (found === undefined || found.main || (await isHunt(repo, found.path))) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
return found.path;
|
|
64
|
+
}
|
|
65
|
+
async function refuseMainWorktree(repo, branch) {
|
|
66
|
+
const found = await holder(repo, branch);
|
|
67
|
+
if (found?.main) {
|
|
68
|
+
throw new Error(`the main worktree at ${found.path} has branch ${branch} checked out, so the issue cannot have its own worktree; check out another branch there and try again`);
|
|
69
|
+
}
|
|
60
70
|
}
|
|
61
71
|
async function releaseFromHunt(repo, branch) {
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
await git(path, ['checkout', '--detach']);
|
|
72
|
+
const found = await holder(repo, branch);
|
|
73
|
+
if (found !== undefined && !found.main && (await isHunt(repo, found.path))) {
|
|
74
|
+
await git(found.path, ['checkout', '--detach']);
|
|
65
75
|
}
|
|
66
76
|
}
|
|
67
77
|
async function isHunt(repo, path) {
|
|
@@ -70,11 +80,12 @@ async function isHunt(repo, path) {
|
|
|
70
80
|
}
|
|
71
81
|
async function holder(repo, branch) {
|
|
72
82
|
const list = await git(repo.root, ['worktree', 'list', '--porcelain']);
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
const blocks = list.split('\n\n').map((block) => block.split('\n'));
|
|
84
|
+
const index = blocks.findIndex((lines) => lines.includes(`branch refs/heads/${branch}`));
|
|
85
|
+
const path = blocks[index]
|
|
86
|
+
?.find((line) => line.startsWith('worktree '))
|
|
87
|
+
?.slice('worktree '.length);
|
|
88
|
+
return path === undefined ? undefined : { path, main: index === 0 };
|
|
78
89
|
}
|
|
79
90
|
export async function removeWorktree(repo, path) {
|
|
80
91
|
return succeeds(repo.root, ['worktree', 'remove', path]);
|