next-issue 6.6.26 → 6.6.28
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 +3 -1
- package/dist/hunt.mjs +5 -1
- package/dist/lock.mjs +3 -3
- package/dist/run.mjs +31 -1
- 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
|
|
@@ -557,7 +559,7 @@ With `--hunt`, which turns on `--watch`, the harness runs a hunter agent at the
|
|
|
557
559
|
|
|
558
560
|
- works in its own worktree at `.worktrees/hunt`, on a detached `HEAD` at the remote base branch, which the harness fetches and checks out before each hunt. A branch that the hunter checks out keeps its commits, and an issue that resumes never uses the hunt worktree as its own;
|
|
559
561
|
- follows `next-issue.hunt.md` in the repository root, or a short built-in prompt when the file is missing;
|
|
560
|
-
- files up to `huntCap` less that count, worked out just before the hunt, its most serious findings first, each with the `labels.ready` label, the `labels.hunt` label and the sections of the [issue format](#issue-format), after a search for duplicates. The `labels.hunt` label, `source:hunt` by default, marks the issue as one the hunter filed
|
|
562
|
+
- files up to `huntCap` less that count, worked out just before the hunt, its most serious findings first, each with the `labels.ready` label, the `labels.hunt` label and the sections of the [issue format](#issue-format), after a search for duplicates. The `labels.hunt` label, `source:hunt` by default, marks the issue as one the hunter filed. The harness creates the `labels.ready` and `labels.hunt` labels before the hunt when they are missing. It files nothing when it finds no real problem or a duplicate exists;
|
|
561
563
|
- runs no test suite and changes no file. It gets the tools of the reviewer.
|
|
562
564
|
|
|
563
565
|
With `huntCap` at 1 and no ready issue, a hunt files at most one issue. The hunter ends its reply with one `issue:` line for each issue it filed, or one `issue: none` line, and the run log holds one `hunt.issue` event with the `url` for each, or one with `none`. A hunt that fails writes a `hunt.error` event and the watch goes on. The hunter then waits before the next hunt, with a `hunt.wait` event and the same back-off, so a failure, or a hunt that files nothing, that repeats waits 1, 2, 3, 5, 10, then 10 minutes, and the back-off goes back to 1 minute after a hunt that files at least one issue. The next pass claims the new issues like any other. At the first `Ctrl-C` the hunter stops after its current hunt, and the watch ends once the hunt and the running issues end. A first `Ctrl-C` during the watch wait tells you so while a hunt runs, and the third press stops the hunter at once. The hunter stops too when the watch ends for another reason.
|
package/dist/hunt.mjs
CHANGED
|
@@ -29,7 +29,11 @@ export async function hunt(context, count) {
|
|
|
29
29
|
const { repo, config, base, recorder, ports } = context;
|
|
30
30
|
return recorder.step('hunt', {}, async () => {
|
|
31
31
|
const cwd = await oneAtATime(repo.root, () => ports.huntWorktree(repo, base, config.remote));
|
|
32
|
-
|
|
32
|
+
for (const label of [config.labels.ready, config.labels.hunt]) {
|
|
33
|
+
if (label.length > 0) {
|
|
34
|
+
await ports.ensureLabel(repo, label);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
33
37
|
const instructions = await readTextIfPresent(join(repo.root, HUNT_FILE));
|
|
34
38
|
const result = await ports.runAgent(recorder, {
|
|
35
39
|
name: 'hunter',
|
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
|
}
|