next-issue 6.6.38 → 6.6.40

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
@@ -39,6 +39,8 @@ writes the summary of the issues it handled and exits with code 1.
39
39
 
40
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
41
 
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
+
42
44
  A run handles up to `concurrency` issues at the same time, 1 by default. When an
43
45
  issue ends, the run fetches the open issues again and claims the oldest unseen
44
46
  one for the free slot. Each issue has its own worktree and branch. Step 3 below
@@ -118,29 +120,29 @@ the run handles one issue. For each issue:
118
120
  reports conflicted files, the fixer gets the list from the check budget,
119
121
  `maxCiFixes`, removes the conflict markers, and the harness commits the
120
122
  merge. A merge that the fixer commits itself counts only when the branch
121
- then holds the base and the listed files hold no conflict marker. With the
122
- budget used up, or when the fixer leaves a conflict marker or the merge
123
- unresolved, aborts the merge, or fails, the harness undoes the merge and
124
- hands the issue to a person with the reason `merge conflict`. The
125
- harness then pushes the commit to the base branch, without force. A push
126
- that the remote refuses, for example because the base moved, starts the
127
- rebase again, three times at most. When the push fails, the harness
128
- fetches the base first, and treats the push as landed when the base holds
129
- the commit, for example after a timeout. When that fetch fails too, the
130
- harness hands the issue to a person with the reason `push unknown` and
131
- halts, even when the hand-over fails. The state file holds the commit
132
- during the push, so a run stopped meanwhile, or the next run after that
133
- hand-over, checks the base on resume and waits for the checks of the
134
- commit when it landed. The harness then waits for the checks of the
135
- pushed commit on the base branch: its GitHub Actions workflow runs, its
136
- commit statuses and the check runs of every other GitHub App, so checks
137
- from another CI service count too. It leaves out the check runs of the
138
- GitHub Actions app, since it judges GitHub Actions by its workflow runs. A
139
- failed or errored commit status, or a check run that ends with
140
- `failure`, `timed_out` or `action_required`, fails the checks. When any check
141
- ends `cancelled`, for example because a later push cancelled the workflow
142
- run, that check never finished, even when another check (such as a release
143
- workflow) ends `success`: the harness
123
+ then holds the base commit that was merged and the listed files hold no
124
+ conflict marker. With the budget used up, or when the fixer leaves a
125
+ conflict marker or the merge unresolved, aborts the merge, or fails, the
126
+ harness undoes the merge and hands the issue to a person with the reason
127
+ `merge conflict`. The harness then pushes the commit to the base branch,
128
+ without force. A push that the remote refuses, for example because the
129
+ base moved, starts the rebase again, three times at most. When the push
130
+ fails, the harness fetches the base first, and treats the push as landed
131
+ when the base holds the commit, for example after a timeout. When that
132
+ fetch fails too, the harness hands the issue to a person with the reason
133
+ `push unknown` and halts, even when the hand-over fails. The state file
134
+ holds the commit during the push, so a run stopped meanwhile, or the
135
+ next run after that hand-over, checks the base on resume and waits for
136
+ 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
144
146
  hands the issue to a person with the reason `main checks cancelled` and
145
147
  halts, and the issue stays open. A repository
146
148
  that reports no check keeps asking for `checkGraceSeconds`. A pending state
@@ -369,7 +371,7 @@ To write the file with the defaults, run the `init` command in the repository:
369
371
  npx -y next-issue@latest init
370
372
  ```
371
373
 
372
- The command writes `.next-issue/config.json` in the repository and adds
374
+ The command writes `.next-issue/config.json` in the main worktree and adds
373
375
  `.next-issue/` and `.worktrees/` to `info/exclude` in the git directory, which
374
376
  linked worktrees share. It removes those two lines from `.gitignore`, and
375
377
  deletes `.gitignore` when nothing else is left in it. It moves a
@@ -576,10 +578,10 @@ With `--hunt`, which turns on `--watch`, the harness runs a hunter agent at the
576
578
 
577
579
  - 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;
578
580
  - follows `next-issue.hunt.md` in the repository root, or a short built-in prompt when the file is missing;
579
- - 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;
581
+ - 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. It files and searches with `gh --repo <owner>/<name>` of the configured `remote`, so another GitHub remote, such as `upstream` in a fork, never gets its issues. 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;
580
582
  - runs no test suite and changes no file. It gets the tools of the reviewer.
581
583
 
582
- 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.
584
+ 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; a url that is not an issue of the repository of `remote` does not count as filed, 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.
583
585
 
584
586
  ## Worker
585
587
 
package/dist/conflict.mjs CHANGED
@@ -11,7 +11,7 @@ export async function rebase(job) {
11
11
  const { target, files } = await log.step('rebase', { base }, () => ports.startMerge(worktree, base, config.remote));
12
12
  if (files !== undefined) {
13
13
  log.event('rebase.conflicts', { files }, 'quiet');
14
- const merged = await mergeBase(job, before, files);
14
+ const merged = await mergeBase(job, { before, target, files });
15
15
  if (merged !== undefined) {
16
16
  return merged;
17
17
  }
@@ -24,7 +24,8 @@ export async function rebase(job) {
24
24
  }
25
25
  return undefined;
26
26
  }
27
- async function mergeBase(job, before, files) {
27
+ async function mergeBase(job, merge) {
28
+ const { before, files } = merge;
28
29
  const { context, worktree } = job;
29
30
  const { config, ports, base } = context;
30
31
  if (files.length > 0) {
@@ -33,7 +34,7 @@ async function mergeBase(job, before, files) {
33
34
  return exhausted;
34
35
  }
35
36
  }
36
- if (!(await resolve(job, before, files))) {
37
+ if (!(await resolve(job, merge))) {
37
38
  await ports.abortMerge(worktree, before);
38
39
  return escalateAndFinish(job, `The fixer left the conflict with ${base} unresolved.`, 'merge conflict');
39
40
  }
@@ -43,13 +44,14 @@ function fixConflict(job, files) {
43
44
  const reason = `The change conflicts with ${job.context.base}.`;
44
45
  return runFixer(job, reason, files.join('\n'), [], 'conflict');
45
46
  }
46
- async function resolve(job, before, files) {
47
+ async function resolve(job, merge) {
47
48
  const { context, worktree } = job;
49
+ const { before, files } = merge;
48
50
  const { config, ports } = context;
49
51
  try {
50
52
  const text = files.length > 0 ? await fixConflict(job, files) : '';
51
53
  const subject = parseCommitSubject(text, `chore: merge ${config.remote}/${context.base}`);
52
- return await commitWork(job, before, subject, 'fixer', (cwd, message) => ports.commitMerge(cwd, { before, base: context.base, remote: config.remote, files }, message));
54
+ return await commitWork(job, before, subject, 'fixer', (cwd, message) => ports.commitMerge(cwd, merge, message));
53
55
  }
54
56
  catch (error) {
55
57
  await ports.abortMerge(worktree, before);
@@ -2,7 +2,7 @@ import { join } from 'node:path';
2
2
  import { run, succeeded } from './exec.mjs';
3
3
  import { readTextOrEmpty } from './files.mjs';
4
4
  import { commitEverything } from './git-commit.mjs';
5
- import { fetchBase, git, isAncestor, remoteRef, resetHard, succeeds } from './git.mjs';
5
+ import { fetchBase, git, isAncestor, resetHard, succeeds } from './git.mjs';
6
6
  import { lines } from './text.mjs';
7
7
  export async function startMerge(cwd, base, remote) {
8
8
  const target = await git(cwd, ['rev-parse', await fetchBase(cwd, base, remote)]);
@@ -33,7 +33,7 @@ export async function commitMerge(cwd, merge, message) {
33
33
  return true;
34
34
  }
35
35
  async function refuseUnmerged(cwd, merge) {
36
- const holdsBase = await isAncestor(cwd, remoteRef(merge.remote, merge.base), 'HEAD');
36
+ const holdsBase = await isAncestor(cwd, merge.target, 'HEAD');
37
37
  if (!holdsBase || (await hasConflictMarkers(cwd, merge.files))) {
38
38
  await resetHard(cwd, merge.before);
39
39
  }
package/dist/git.mjs CHANGED
@@ -16,7 +16,10 @@ export function parseRemote(url) {
16
16
  throw new Error(`Cannot parse the git remote URL: ${url}`);
17
17
  }
18
18
  export async function repoRoot(cwd) {
19
- return git(cwd, ['rev-parse', '--show-toplevel']);
19
+ const top = await git(cwd, ['rev-parse', '--show-toplevel']);
20
+ const list = await git(cwd, ['worktree', 'list', '--porcelain']);
21
+ const [first = '', second = ''] = list.split('\n');
22
+ return first.startsWith('worktree ') && second !== 'bare' ? first.slice('worktree '.length) : top;
20
23
  }
21
24
  export async function detectRepo(cwd, remote) {
22
25
  const root = await repoRoot(cwd);
package/dist/github.mjs CHANGED
@@ -61,10 +61,18 @@ export async function canWrite(repo, login) {
61
61
  throw error;
62
62
  }
63
63
  }
64
+ const REPOSITORY_SLUG = '(.repository_url | split("/") | .[-2:] | join("/"))';
64
65
  export async function openBlockers(repo, issue) {
65
- const repoSlug = slug(repo);
66
- const raw = await ghApi(repo, `issues/${issue}/dependencies/blocked_by`, '.[] | select(.state == "open") | (.repository_url | split("/") | .[-2:] | join("/")) + "#" + (.number | tostring)', { paginate: true });
67
- return lines(raw).map((ref) => ref.startsWith(`${repoSlug}#`) ? ref.slice(repoSlug.length) : ref);
66
+ const raw = await ghApi(repo, `issues/${issue}/dependencies/blocked_by`, `.[] | select(.state == "open") | ${REPOSITORY_SLUG} + "#" + (.number | tostring)`, { paginate: true });
67
+ const refs = lines(raw);
68
+ const prefixes = [`${slug(repo)}#`.toLowerCase()];
69
+ if (refs.some((ref) => !ref.toLowerCase().startsWith(prefixes[0]))) {
70
+ prefixes.push(`${await ghApi(repo, `issues/${issue}`, REPOSITORY_SLUG)}#`.toLowerCase());
71
+ }
72
+ return refs.map((ref) => {
73
+ const prefix = prefixes.find((candidate) => ref.toLowerCase().startsWith(candidate));
74
+ return prefix === undefined ? ref : ref.slice(prefix.length - 1);
75
+ });
68
76
  }
69
77
  export async function reopenIssue(repo, issue) {
70
78
  await gh(repo, ['issue', 'reopen', String(issue)]);
package/dist/hunt.mjs CHANGED
@@ -4,6 +4,7 @@ import { setTimeout as delay } from 'node:timers/promises';
4
4
  import { REVIEWING } from './agents.mjs';
5
5
  import { minutesToMs } from './durations.mjs';
6
6
  import { readTextIfPresent } from './files.mjs';
7
+ import { slug } from './gh.mjs';
7
8
  import { git, gitFetch, remoteRef } from './git.mjs';
8
9
  import { oneAtATime } from './lock.mjs';
9
10
  import { huntPrompt } from './prompts.mjs';
@@ -25,6 +26,10 @@ export async function huntWorktree(repo, base, remote) {
25
26
  }
26
27
  return path;
27
28
  }
29
+ function isIssueOf(repo, url) {
30
+ const issue = /^https:\/\/github\.com\/([^/]+\/[^/]+)\/issues\/\d+\/?$/i.exec(url);
31
+ return issue?.[1]?.toLowerCase() === slug(repo).toLowerCase();
32
+ }
28
33
  export async function hunt(context, count) {
29
34
  const { repo, config, base, recorder, ports } = context;
30
35
  return recorder.step('hunt', {}, async () => {
@@ -38,13 +43,13 @@ export async function hunt(context, count) {
38
43
  const result = await ports.runAgent(recorder, {
39
44
  name: 'hunter',
40
45
  cwd,
41
- prompt: huntPrompt(instructions, config.labels.ready, config.labels.hunt, count),
46
+ prompt: huntPrompt(instructions, config.labels.ready, config.labels.hunt, count, slug(repo)),
42
47
  profile: REVIEWING,
43
48
  timeoutMs: minutesToMs(config.agentTimeoutMinutes),
44
49
  });
45
50
  const urls = [...result.text.matchAll(FILED)]
46
51
  .map((match) => match[1])
47
- .filter((url) => /^https?:\/\//.test(url));
52
+ .filter((url) => isIssueOf(repo, url));
48
53
  for (const url of urls.length === 0 ? ['none'] : urls) {
49
54
  recorder.event('hunt.issue', { url }, 'quiet');
50
55
  }
package/dist/pending.mjs CHANGED
@@ -38,7 +38,7 @@ async function savedIssue(context, number) {
38
38
  catch (error) {
39
39
  context.recorder
40
40
  .scope({ issue: number })
41
- .event('issue.error', { error: message(error) }, 'quiet');
41
+ .event('issue.unreadable', { error: message(error) }, 'quiet');
42
42
  return { open: false };
43
43
  }
44
44
  }
package/dist/prompts.mjs CHANGED
@@ -164,7 +164,7 @@ const HUNT_DEFAULT = [
164
164
  'Read the whole repository and look for bugs: wrong results, unhandled errors, races, security holes and documentation that contradicts the code.',
165
165
  'Prove each finding from the code. A guess is not a finding.',
166
166
  ].join('\n');
167
- export function huntPrompt(instructions, ready, source, count) {
167
+ export function huntPrompt(instructions, ready, source, count, repository) {
168
168
  const issues = count === 1 ? '1 issue' : `${count} issues`;
169
169
  const kept = instructions?.trim() ?? '';
170
170
  const label = [ready, source]
@@ -178,8 +178,8 @@ export function huntPrompt(instructions, ready, source, count) {
178
178
  [
179
179
  'Run no test suite and no build. Change no file. Do not commit or push.',
180
180
  `File up to ${issues}, your most serious findings first. File nothing when you find no real problem.`,
181
- 'Before you file an issue, search the open and closed issues for a duplicate, for example with `gh issue list --state all --search "<words>"`. Do not file a finding when a duplicate exists.',
182
- `File each issue with \`gh issue create${label} --title "<conventional commit subject>" --body-file -\`.`,
181
+ `Before you file an issue, search the open and closed issues for a duplicate, for example with \`gh issue list --repo ${repository} --state all --search "<words>"\`. Do not file a finding when a duplicate exists.`,
182
+ `File each issue with \`gh issue create --repo ${repository}${label} --title "<conventional commit subject>" --body-file -\`.`,
183
183
  `The body holds these sections as \`##\` headings, in this order: ${ISSUE_SECTIONS.map((section) => `\`## ${section}\``).join(', ')}.`,
184
184
  'Give the file and line of each piece of evidence. Leave the Open questions section empty.',
185
185
  'End your final message with one line in the form `issue: <url>` for each issue you filed, or one `issue: none` line when you filed nothing.',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.38",
3
+ "version": "6.6.40",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",