next-issue 6.6.44 → 6.6.46

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 CHANGED
@@ -37,7 +37,7 @@ 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.
40
+ Only one worker or command-line run goes at a time in a repository. Both hold one lock, `.next-issue/worker.lock`, with the process id and the start time of that process: the worker for its whole life, and a command-line run from its start to its end. A run that the worker starts takes no lock of its own, since the worker runs at most one run at a time. A command-line run that starts while any worker is alive, busy or idle, or while another command-line run is going, claims no issue and exits with code 1 and the error `another next-issue worker or run (process id <n>) is going in this repository`. Run `next-issue stop` first to stop the worker. A lock whose process is gone, or started at another time, is stale and taken over.
41
41
 
42
42
  Every command uses the main worktree of the repository as its root, the first one that `git worktree list` shows, even when it runs in a linked worktree. So `.next-issue/`, with the config, the locks, the worker socket, the saved state and the notes, and `.worktrees/` are always in the main worktree, and a run or worker started from a linked worktree gets the same refusal as one started from the main worktree.
43
43
 
@@ -115,12 +115,16 @@ the run handles one issue. For each issue:
115
115
  Approved changes land one at a time, so the next one waits until the
116
116
  checks of the last one end, and other issues go on meanwhile. The
117
117
  harness fetches the remote base, merges it into the branch and makes the
118
- change one commit on top of it, with the subject of the newest commit of
119
- the change. When git merges the base cleanly, no agent runs. When git
120
- reports conflicted files, the fixer gets the list from the check budget,
121
- `maxCiFixes`, removes the conflict markers, and the harness commits the
122
- merge. A merge that the fixer commits itself counts only when the branch
123
- then holds the base commit that was merged and the listed files hold no
118
+ change one commit on top of it, with the subject of the implementer's
119
+ commit. A review fix keeps that subject, but a commit fix for the
120
+ implementer's commit replaces it, and a fix for failed checks after the
121
+ landing lands under the fixer's own subject. The reapply commit after a
122
+ revert uses the subject of the change. When git merges the base cleanly,
123
+ no agent runs. When git reports conflicted files, the fixer gets the
124
+ list from the check budget, `maxCiFixes`, removes the conflict markers,
125
+ and the harness commits the merge. A merge that the fixer commits itself
126
+ counts only when the branch then holds the base commit that was merged
127
+ and the listed files hold no
124
128
  conflict marker. With the budget used up, or when the fixer leaves a
125
129
  conflict marker or the merge unresolved, aborts the merge, or fails, the
126
130
  harness undoes the merge and hands the issue to a person with the reason
@@ -134,17 +138,20 @@ the run handles one issue. For each issue:
134
138
  holds the commit during the push, so a run stopped meanwhile, or the
135
139
  next run after that hand-over, checks the base on resume and waits for
136
140
  the checks of the commit when it landed. The harness then waits for the
137
- checks of the pushed commit on the base branch: its GitHub Actions
138
- workflow runs, its commit statuses and the check runs of every other
139
- GitHub App, so checks from another CI service count too. It leaves out
140
- the check runs of the GitHub Actions app, since it judges GitHub Actions
141
- by its workflow runs. A failed or errored commit status, or a check run
142
- that ends with `failure`, `timed_out` or `action_required`, fails the
143
- checks. When any check ends `cancelled`, for example because a later
144
- push cancelled the workflow run, that check never finished, even when
145
- another check (such as a release workflow) ends `success`: the harness
146
- hands the issue to a person with the reason `main checks cancelled` and
147
- halts, and the issue stays open. A repository
141
+ checks of the pushed commit on the base branch: the GitHub Actions
142
+ workflow runs that a `push` event started on it, its commit statuses
143
+ and the check runs of every other GitHub App, so checks from another CI
144
+ service count too. It leaves out the check runs of the GitHub Actions
145
+ app, since it judges GitHub Actions by its workflow runs. It leaves out
146
+ workflow runs that any other event (such as `issues`, `issue_comment` or
147
+ `schedule`) started, since GitHub gives such a run the tip of the
148
+ default branch as its commit. A failed or errored commit status, or a
149
+ check run that ends with `failure`, `timed_out` or `action_required`,
150
+ fails the checks. When any check ends `cancelled`, for example because
151
+ a later push cancelled the workflow run, that check never finished,
152
+ even when another check (such as a release workflow) ends `success`:
153
+ the harness hands the issue to a person with the reason
154
+ `main checks cancelled` and halts, and the issue stays open. A repository
148
155
  that reports no check keeps asking for `checkGraceSeconds`. A pending state
149
156
  waits again, up to `checkTimeoutMinutes`. A read that fails is tried three
150
157
  times. When the checks pass, the harness closes the issue and sets
@@ -266,7 +273,12 @@ Press `Ctrl-C` to stop the run step by step:
266
273
  3. The third press stops every agent, kills the command that runs and every
267
274
  child of it, so the run dies in the middle of a step. The saved state lets the next run continue the
268
275
  issue, but the issue keeps `status:in-progress` and the run writes no
269
- summary.
276
+ summary. Edits that an agent did not commit stay in the worktree. When
277
+ the issue resumes in review, the harness drops them before the reviewer
278
+ starts, so the reviewer sees only the commits of the branch. Files that
279
+ git ignores, such as build output, stay. When it
280
+ resumes before the first commit, the implementer runs again and the
281
+ commit holds them.
270
282
 
271
283
  Signals that arrive within 100 ms of the last counted one count as one press,
272
284
  because `npx` and `npm exec` pass on a press as a second signal.
@@ -493,7 +505,8 @@ silent skip.
493
505
  Every agent prompt holds `.next-issue/notes.md` when it exists, so lessons
494
506
  such as test commands, tool quirks and deliberate behaviour carry over from one
495
507
  issue to the next. The implementer and the fixer may add a short note to it, and
496
- the prompt asks them to keep only what still holds. The reviewer only reads it.
508
+ the prompt asks them to keep only what still holds. The reviewer and the hunter
509
+ only read it.
497
510
 
498
511
  ## Retry an issue that waits for a person
499
512
 
@@ -600,7 +613,9 @@ affect another. The worker:
600
613
  When the path of the socket file is too long for the system, about 103
601
614
  bytes on macOS and 107 on Linux, it exits with an error that says so;
602
615
  - holds `.next-issue/worker.lock` in the repository, with its process id and
603
- the start time of that process, so only one worker runs per repository. A
616
+ the start time of that process, so only one worker or command-line run goes
617
+ per repository. A worker that starts while a command-line run holds the lock
618
+ exits with `another worker is running`. A
604
619
  lock is stale, and is taken over, when no process has that id or the process
605
620
  with that id started at another time, for example because the system gave
606
621
  the id of a worker that was killed or lost in a reboot to another process.
@@ -658,9 +673,12 @@ affect another. The worker:
658
673
 
659
674
  Stop the worker of a repository with `next-issue stop` in that repository.
660
675
  Workers of other repositories carry on. This sends `SIGTERM` to the process in
661
- the lock file when the lock is not stale, so the worker stops at once and a
662
- run that is going resumes from its saved state next time. When no worker is
663
- running, the command says so and exits with 0.
676
+ the lock file when the lock is not stale and the worker socket file takes a
677
+ connection, so the worker stops at once and a run that is going resumes from
678
+ its saved state next time. When no worker is running, the command says so and
679
+ exits with 0. When a command-line run holds the lock, the command sends no
680
+ signal, says `no worker is running; a command-line run (process id <n>) is
681
+ going, press Ctrl-C there to stop it` and exits with 0.
664
682
 
665
683
  Versions before one worker per repository ran one worker for the machine,
666
684
  with `next-issue.sock`, `next-issue.lock` and `next-issue.roots.json` in
@@ -14,8 +14,8 @@ function jsonLines(raw) {
14
14
  .map((line) => JSON.parse(line));
15
15
  }
16
16
  async function baseRuns(repo, sha) {
17
- const runs = await ghApi(repo, `actions/runs?head_sha=${sha}&per_page=100`, '.workflow_runs[] | {databaseId: .id, name, status, conclusion: (.conclusion // ""), attempt: .run_attempt} | @json', { paginate: true });
18
- return jsonLines(runs);
17
+ const runs = await ghApi(repo, `actions/runs?head_sha=${sha}&per_page=100`, '.workflow_runs[] | {databaseId: .id, name, status, conclusion: (.conclusion // ""), attempt: .run_attempt, event} | @json', { paginate: true });
18
+ return jsonLines(runs).filter((entry) => entry.event === 'push');
19
19
  }
20
20
  async function externalChecks(repo, sha) {
21
21
  const [runs, statuses] = await Promise.all([
package/dist/cli.mjs CHANGED
@@ -9,7 +9,7 @@ import { ensureExcluded, excludeFile, removeIgnored } from './ignore.mjs';
9
9
  import { listenForInterrupts } from './interrupt.mjs';
10
10
  import { stopWorker } from './lock.mjs';
11
11
  import { followLog, newestRunLog } from './logs.mjs';
12
- import { runRepo } from './run.mjs';
12
+ import { runLocked } from './run.mjs';
13
13
  import { serve } from './serve.mjs';
14
14
  import { STATE_DIR } from './state.mjs';
15
15
  import { formatSummary } from './summary.mjs';
@@ -44,16 +44,19 @@ async function main() {
44
44
  }
45
45
  function run(root, args) {
46
46
  const interrupts = listenForInterrupts((text) => void write(process.stderr, `${text}\n`));
47
- return runRepo(root, args, {
47
+ return runLocked(root, args, {
48
48
  interrupts,
49
49
  print: (summary) => write(process.stdout, args.json ? prettyJson(summary) : formatSummary(summary)),
50
50
  });
51
51
  }
52
+ const STOPPED = {
53
+ none: () => 'next-issue: no worker is running\n',
54
+ run: (pid) => `next-issue: no worker is running; a command-line run (process id ${pid}) is going, press Ctrl-C there to stop it\n`,
55
+ worker: (pid) => `next-issue: stopped the worker with process id ${pid}\n`,
56
+ };
52
57
  async function stop(root) {
53
- const pid = await stopWorker(workerPaths(root).lockPath);
54
- await write(process.stdout, pid === undefined
55
- ? 'next-issue: no worker is running\n'
56
- : `next-issue: stopped the worker with process id ${pid}\n`);
58
+ const { stopped, pid } = await stopWorker(workerPaths(root));
59
+ await write(process.stdout, STOPPED[stopped](pid));
57
60
  return 0;
58
61
  }
59
62
  async function logs(root, json) {
package/dist/fix.mjs CHANGED
@@ -32,7 +32,15 @@ export async function fixRound(job, reason, detail, earlier, kind) {
32
32
  return disputedFix(job, before, reason, { resolved });
33
33
  }
34
34
  const subject = parseCommitSubject(text, `fix: address feedback on issue #${issue.number}`);
35
- if (!(await commitWork(job, before, subject, 'fixer'))) {
35
+ const title = job.state.title;
36
+ if (kind === 'checks') {
37
+ job.state.changeTitle ??= title;
38
+ }
39
+ const committed = await commitWork(job, before, subject, 'fixer');
40
+ if (kind === 'review') {
41
+ job.state.title = title;
42
+ }
43
+ if (!committed) {
36
44
  log.event('commit.empty', { reason }, 'quiet');
37
45
  return { committed: false };
38
46
  }
package/dist/hunt.mjs CHANGED
@@ -6,6 +6,7 @@ import { minutesToMs } from './durations.mjs';
6
6
  import { readTextIfPresent } from './files.mjs';
7
7
  import { slug } from './gh.mjs';
8
8
  import { git, gitFetch, remoteRef } from './git.mjs';
9
+ import { withNotes } from './job.mjs';
9
10
  import { oneAtATime } from './lock.mjs';
10
11
  import { huntPrompt } from './prompts.mjs';
11
12
  import { skipReason } from './skip.mjs';
@@ -43,7 +44,7 @@ export async function hunt(context, count) {
43
44
  const result = await ports.runAgent(recorder, {
44
45
  name: 'hunter',
45
46
  cwd,
46
- prompt: huntPrompt(instructions, config.labels.ready, config.labels.hunt, count, slug(repo)),
47
+ prompt: await withNotes(repo.root, huntPrompt(instructions, config.labels.ready, config.labels.hunt, count, slug(repo)), false),
47
48
  profile: REVIEWING,
48
49
  timeoutMs: minutesToMs(config.agentTimeoutMinutes),
49
50
  });
package/dist/job.mjs CHANGED
@@ -13,15 +13,18 @@ export function gateRound(gate) {
13
13
  }
14
14
  return gate.fixed ? ROUND_CONTINUE : undefined;
15
15
  }
16
+ export async function withNotes(root, prompt, writable) {
17
+ const path = notesPath(root);
18
+ const notes = await readTextIfPresent(path);
19
+ return paragraphs([notesBlock(path, notes, writable), prompt]);
20
+ }
16
21
  export async function runRole(job, role, prompt, profile) {
17
22
  const { config, ports, repo } = job.context;
18
- const path = notesPath(repo.root);
19
- const notes = await readTextIfPresent(path);
20
23
  const writable = role === 'implementer' || role === 'fixer';
21
24
  return ports.runAgent(job.log, {
22
25
  name: role,
23
26
  cwd: job.worktree,
24
- prompt: paragraphs([notesBlock(path, notes, writable), prompt]),
27
+ prompt: await withNotes(repo.root, prompt, writable),
25
28
  profile,
26
29
  model: config.models[role],
27
30
  timeoutMs: minutesToMs(config.agentTimeoutMinutes),
package/dist/lock.mjs CHANGED
@@ -2,6 +2,7 @@ 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';
5
6
  import { basename, dirname, join } from 'node:path';
6
7
  import { setTimeout as delay } from 'node:timers/promises';
7
8
  import { promisify } from 'node:util';
@@ -143,12 +144,26 @@ async function removeDeadDrafts(path) {
143
144
  }
144
145
  }
145
146
  }
146
- export async function stopWorker(lockPath) {
147
- const pid = await lockHolder(lockPath);
148
- if (pid !== undefined) {
149
- process.kill(pid, 'SIGTERM');
147
+ function listening(socketPath) {
148
+ return new Promise((resolve) => {
149
+ const socket = createConnection(socketPath);
150
+ socket.once('connect', () => {
151
+ socket.destroy();
152
+ resolve(true);
153
+ });
154
+ socket.once('error', () => resolve(false));
155
+ });
156
+ }
157
+ export async function stopWorker(paths) {
158
+ const pid = await lockHolder(paths.lockPath);
159
+ if (pid === undefined) {
160
+ return { stopped: 'none' };
161
+ }
162
+ if (!(await listening(paths.socketPath))) {
163
+ return { stopped: 'run', pid };
150
164
  }
151
- return pid;
165
+ process.kill(pid, 'SIGTERM');
166
+ return { stopped: 'worker', pid };
152
167
  }
153
168
  function textOf(path) {
154
169
  try {
package/dist/revert.mjs CHANGED
@@ -25,7 +25,7 @@ export function sentence(text) {
25
25
  }
26
26
  export function reapplyMessage(job) {
27
27
  const { number } = job.issue;
28
- return `${job.state.title ?? `fix: resolve issue #${number}`}\n\nRefs #${number}`;
28
+ return `${job.state.changeTitle ?? job.state.title ?? `fix: resolve issue #${number}`}\n\nRefs #${number}`;
29
29
  }
30
30
  export async function revert(job) {
31
31
  const { context, issue, log, state, branch, worktree } = job;
package/dist/review.mjs CHANGED
@@ -61,6 +61,9 @@ async function runReviewer(job, earlier) {
61
61
  cut: full.length > config.diffMaxChars,
62
62
  };
63
63
  const before = await ports.revision(worktree);
64
+ if (await ports.discardChanges(worktree, before, job.branch)) {
65
+ log.event('review.clean', { round: state.reviewRounds }, 'quiet');
66
+ }
64
67
  const review = await log.step('review', fields, () => runRole(job, 'reviewer', reviewPrompt(issue, comments, patch, earlier, earlier.length === 0 ? state.implementerReply : state.fixerReply), REVIEWING));
65
68
  if (await ports.discardChanges(worktree, before, job.branch)) {
66
69
  log.event('review.discard', { round: state.reviewRounds }, 'quiet');
package/dist/run.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { mkdir, rm } from 'node:fs/promises';
2
- import { join } from 'node:path';
2
+ import { dirname } from 'node:path';
3
3
  import { recordCommands } from './command-records.mjs';
4
4
  import { loadConfig } from './config.mjs';
5
5
  import { minutesToMs } from './durations.mjs';
@@ -17,23 +17,20 @@ import { pendingIssues } from './pending.mjs';
17
17
  import { processIssue } from './pipeline.mjs';
18
18
  import { PORTS } from './ports.mjs';
19
19
  import { pruneRuns } from './prune-runs.mjs';
20
- import { stateDir } from './state.mjs';
21
20
  import { count } from './summary.mjs';
22
21
  import { packageVersion } from './version.mjs';
23
22
  import { watchIssues } from './watch.mjs';
24
23
  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');
24
+ export async function runLocked(root, args, controls) {
25
+ const path = workerPaths(root).lockPath;
26
+ await mkdir(dirname(path), { recursive: true });
31
27
  const held = await lock(path, 0);
32
28
  if (held === undefined) {
33
- throw new Error(await runningMessage(root, path));
29
+ const pid = await lockHolder(path);
30
+ throw new Error(`another next-issue worker or run (process id ${pid ?? 'unknown'}) is going in this repository`);
34
31
  }
35
32
  try {
36
- return await work();
33
+ return await runRepo(root, args, controls);
37
34
  }
38
35
  finally {
39
36
  if (held.owns()) {
@@ -41,13 +38,7 @@ async function withRunLock(root, work) {
41
38
  }
42
39
  }
43
40
  }
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) {
41
+ export async function runRepo(root, args, controls) {
51
42
  const config = await loadConfig(root);
52
43
  return withDefaultTimeout(minutesToMs(config.commandTimeoutMinutes), () => runWithConfig(root, args, controls, config));
53
44
  }
package/dist/state.mjs CHANGED
@@ -51,6 +51,7 @@ function isState(value) {
51
51
  PHASES.includes(value.phase) &&
52
52
  typeof value.branch === 'string' &&
53
53
  isOptional(value.title, 'string') &&
54
+ isOptional(value.changeTitle, 'string') &&
54
55
  isOptional(value.implementerReply, 'string') &&
55
56
  isOptional(value.fixerReply, 'string') &&
56
57
  typeof value.ciFixes === 'number' &&
package/dist/watch.mjs CHANGED
@@ -50,6 +50,9 @@ async function huntIssues(hunter, running, failed, claims, stopped, signal) {
50
50
  let step = 0;
51
51
  while (!stopped()) {
52
52
  const ready = await hunter.ready(running, failed).catch(() => undefined);
53
+ if (stopped()) {
54
+ return;
55
+ }
53
56
  claims.take();
54
57
  const waiting = ready?.filter((issue) => !running.has(issue.number)).length;
55
58
  if (waiting !== undefined && waiting < hunter.cap) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.44",
3
+ "version": "6.6.46",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",