next-issue 3.0.0 → 5.0.0

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
@@ -51,8 +51,7 @@ the run handles one issue. For each issue:
51
51
  resume too. An issue that GitHub lists as blocked by an open issue waits,
52
52
  because its blocker closes only when the change of the blocker lands.
53
53
  An issue with saved state under `.next-issue/` resumes instead, whatever its
54
- other labels and blockers. Such an issue joins the list also when it is
55
- closed, if its pull request is merged.
54
+ other labels and blockers.
56
55
  2. Add `status:in-progress` to the issue.
57
56
  3. Fetch the remote, fast-forward the local copy of the default branch when
58
57
  that is safe, then add a git worktree at `.worktrees/<n>` in the
@@ -169,7 +168,7 @@ and comments the reason on the issue, when:
169
168
  - the setup command fails, or does not finish in `setupTimeoutMinutes`;
170
169
  - a step of the run fails with an error. A `gh` call that is safe to repeat,
171
170
  such as a read or a label edit, is tried up to three times first when the
172
- network fails. A `gh pr create`, `gh pr comment` or `gh issue comment` is
171
+ network fails. A `gh issue comment` is
173
172
  tried once, so a lost reply never makes a duplicate.
174
173
 
175
174
  The fixer sees the findings of all earlier rounds, not only the last one, with
@@ -237,8 +236,7 @@ Every run has an id, `<timestamp>`, and writes these under `.next-issue/runs/`:
237
236
  - `<id>.jsonl` — one JSON object per event, with `ts`, `runId`, `kind`, and the
238
237
  `issue`, `role` or `round` in scope;
239
238
  - `<id>.summary.json` — token totals per agent role, event counts, and
240
- one report per issue with the outcome, the reason, the pull request number
241
- and the budgets used;
239
+ one report per issue with the outcome, the reason and the budgets used;
242
240
  - `<id>/sessions/` — the full pi session of each agent call, with every
243
241
  message, tool call and tool result. The session id in a `usage` event is
244
242
  part of the file name.
@@ -251,7 +249,7 @@ get the full summary object there instead, so the harness fits in a pipe. All
251
249
  progress goes to standard error.
252
250
 
253
251
  Recorded for each step: `claim`, `comments`, `reply`, `worktree`, `setup`,
254
- `implement`, `push`, `pull-request`, `checks`, `review` and `fix`, each with a
252
+ `implement`, `review`, `fix`, `commit-fix`, `rebase`, `land`, `main-checks` and `revert`, each with a
255
253
  `.start`, `.end` or `.error` event and a duration in `ms`. Every `git` and `gh`
256
254
  command is recorded with its exit code and duration. A `tool` event holds the
257
255
  tool name, and for a `bash` tool the command too. Each agent call adds a `usage`
@@ -308,7 +306,9 @@ project.
308
306
  With no file, every field keeps its default. A field that is not in the file
309
307
  keeps its default. A file that cannot be read, a file that is not valid
310
308
  JSON, a field with a value of the wrong type and a field name that the harness
311
- does not know all stop the run, so a typo cannot pass without a word.
309
+ does not know all stop the run, so a typo cannot pass without a word. An old
310
+ `draftPullRequest` field stops the run with an error that says to remove it,
311
+ because no pull request is opened.
312
312
 
313
313
  ```json
314
314
  {
@@ -327,7 +327,6 @@ does not know all stop the run, so a typo cannot pass without a word.
327
327
  "logMaxChars": 20000,
328
328
  "diffMaxChars": 60000,
329
329
  "keepRunDays": 7,
330
- "draftPullRequest": true,
331
330
  "models": {
332
331
  "implementer": null,
333
332
  "reviewer": null,
@@ -361,7 +360,6 @@ does not know all stop the run, so a typo cannot pass without a word.
361
360
  | `logMaxChars` | `20000` | The maximum length of the failed job logs, shared between the failed jobs |
362
361
  | `diffMaxChars` | `60000` | The maximum length of the diff that the reviewer reads |
363
362
  | `keepRunDays` | `7` | The number of days to keep the run files; `0` keeps them all |
364
- | `draftPullRequest` | `true` | Open the pull request as a draft, until the review approves |
365
363
  | `setupCommand` | from the lock file | A shell command to run in a new worktree, before the implementer |
366
364
  | `models` | `null` per role | The pi model per agent role, as `provider/model`: `implementer`, `reviewer`, `fixer` |
367
365
  | `labels` | see above | The names of the labels that the harness reads and sets |
@@ -436,7 +434,6 @@ state of an issue that a label still holds back stays as it was.
436
434
  | `--force` | Replace an existing config file, with `init` |
437
435
  | `--once` | Stop after the first handled issue |
438
436
  | `--max <n>` | Handle at most n issues |
439
- | `--merge` | No effect: an approved change always lands on the base branch |
440
437
  | `--watch` | Keep running, and read the open issues again after each pass |
441
438
  | `--reset` | Drop the saved budgets and findings, and keep the rest of the state |
442
439
  | `--json` | Print the machine summary instead of the text one, or the raw JSON lines with `logs` |
@@ -452,7 +449,7 @@ not, so a cron job or a CI step can read the result of the run.
452
449
  A run without `--watch` ends when no unseen issue is left. With `--watch`, the
453
450
  harness then waits, reads the open issues again and runs another pass, so it
454
451
  picks up an issue that someone opens during the run, or one whose blocker
455
- merges. Each pass tries every open issue again, also one that an earlier pass
452
+ closes. Each pass tries every open issue again, also one that an earlier pass
456
453
  skipped. An issue that failed in an earlier pass is not tried again until the
457
454
  next run.
458
455
 
@@ -490,14 +487,14 @@ of one repository never affect another. The worker:
490
487
  only one worker runs per repository. A lock whose process is no longer alive
491
488
  is taken over;
492
489
  - runs at most one run at a time. Each run is like `next-issue` without
493
- `--watch`, and the client says whether it merges;
490
+ `--watch`;
494
491
  - sends every client the progress of every run when it connects and on every
495
492
  change: for each running issue the issue, the step, the tool count and the
496
493
  last tool, and the handled issues;
497
494
  - sends every client a `questions` message for each repository: the open
498
495
  issues with the `needsHuman` label, each with its number, title, the reason
499
496
  of the hand-over, the url of the comment that holds it, the `owner/name`
500
- repository, the pull request when there is one, and the `needsHuman` and
497
+ repository, and the `needsHuman` and
501
498
  `skip` labels. It reads them
502
499
  from GitHub, so the list is the same after a restart. It sends them when a
503
500
  client connects, for its repository, after each issue of a run
package/dist/args.mjs CHANGED
@@ -3,7 +3,6 @@ const SWITCHES = new Map([
3
3
  ['--force', 'force'],
4
4
  ['--json', 'json'],
5
5
  ['--help', 'help'],
6
- ['--merge', 'merge'],
7
6
  ['--watch', 'watch'],
8
7
  ['--reset', 'reset'],
9
8
  ['--once', 'once'],
@@ -21,7 +20,6 @@ export const USAGE = `next-issue [command] [options]
21
20
 
22
21
  --once stop after the first handled issue
23
22
  --max <n> handle at most n issues
24
- --merge no effect: an approved change always lands on the base branch
25
23
  --watch keep running and read the issues again after each pass
26
24
  --reset drop the saved budgets and findings first
27
25
  --json print the machine summary instead of the text one, or raw lines with logs
@@ -38,7 +36,6 @@ export function parseArgs(argv) {
38
36
  json: false,
39
37
  reset: false,
40
38
  force: false,
41
- merge: false,
42
39
  watch: false,
43
40
  level: 'normal',
44
41
  };
@@ -18,12 +18,6 @@ export function whole(value, field, least) {
18
18
  }
19
19
  return value;
20
20
  }
21
- export function flag(value, field) {
22
- if (typeof value !== 'boolean') {
23
- throw new Error(`${CONFIG_FILE}: ${field} must be true or false.`);
24
- }
25
- return value;
26
- }
27
21
  export function text(value, field, allowEmpty) {
28
22
  if (typeof value !== 'string' || (!allowEmpty && value.length === 0)) {
29
23
  throw new Error(`${CONFIG_FILE}: ${field} must be ${allowEmpty ? 'text' : 'text that is not empty'}.`);
package/dist/config.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { join } from 'node:path';
2
- import { CONFIG_FILE, flag, record, rejectUnknown, text, whole } from './config-fields.mjs';
2
+ import { CONFIG_FILE, record, rejectUnknown, text, whole } from './config-fields.mjs';
3
3
  import { hasCode, message, parseJson } from './errors.mjs';
4
4
  import { readTextIfPresent, writeJson } from './files.mjs';
5
5
  const DEFAULTS = {
@@ -18,7 +18,6 @@ const DEFAULTS = {
18
18
  logMaxChars: 20000,
19
19
  diffMaxChars: 60000,
20
20
  keepRunDays: 7,
21
- draftPullRequest: true,
22
21
  models: {},
23
22
  labels: {
24
23
  ready: 'status:todo',
@@ -86,6 +85,9 @@ export async function loadConfig(root) {
86
85
  }
87
86
  function parseConfig(value) {
88
87
  const file = record(value, 'the file');
88
+ if (file.draftPullRequest !== undefined) {
89
+ throw new Error(`${CONFIG_FILE}: draftPullRequest is no longer used, because changes land on the base branch with no pull request. Remove the field.`);
90
+ }
89
91
  rejectUnknown(file, FIELDS, 'field');
90
92
  const config = defaults();
91
93
  if (file.remote !== undefined) {
@@ -96,9 +98,6 @@ function parseConfig(value) {
96
98
  config[field] = whole(file[field], field, least);
97
99
  }
98
100
  }
99
- if (file.draftPullRequest !== undefined) {
100
- config.draftPullRequest = flag(file.draftPullRequest, 'draftPullRequest');
101
- }
102
101
  if (file.setupCommand !== undefined) {
103
102
  config.setupCommand = text(file.setupCommand, 'setupCommand', false);
104
103
  }
package/dist/gh.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { setTimeout as delay } from 'node:timers/promises';
2
2
  import { secondsToMs } from './durations.mjs';
3
3
  import { errorMatches } from './errors.mjs';
4
- import { must, optionalFlag, run, succeeded } from './exec.mjs';
4
+ import { must, optionalFlag, run } from './exec.mjs';
5
5
  const NETWORK_TRIES = 3;
6
6
  const NETWORK_FAULT = /unexpected EOF|connection reset|connection refused|i\/o timeout|TLS handshake timeout|HTTP 50[234]/i;
7
7
  export function slug(repo) {
@@ -47,9 +47,6 @@ export async function ghApi(repo, path, jq, { paginate = false } = {}) {
47
47
  jq,
48
48
  ]);
49
49
  }
50
- export async function ghSucceeds(repo, args) {
51
- return succeeded(await ghRun(repo, args));
52
- }
53
50
  export function names(items) {
54
51
  return items.map((item) => item.name);
55
52
  }
package/dist/github.mjs CHANGED
@@ -78,6 +78,3 @@ async function comment(repo, kind, number, body) {
78
78
  export async function commentOnIssue(repo, issue, body) {
79
79
  await comment(repo, 'issue', issue, body);
80
80
  }
81
- export async function commentOnPr(repo, pr, body) {
82
- await comment(repo, 'pr', pr, body);
83
- }
@@ -1,5 +1,4 @@
1
1
  import { slug } from './gh.mjs';
2
- import { readState } from './state.mjs';
3
2
  export const HAND_OVER = 'next-issue needs help:';
4
3
  const HARNESS_HEADINGS = [HAND_OVER, '### Review:', '### Fixer:'];
5
4
  function fromHarness(comment) {
@@ -38,8 +37,8 @@ async function lastHandOver(comments, writer) {
38
37
  }
39
38
  return -1;
40
39
  }
41
- async function handOverThread(repo, ports, writer, thread) {
42
- const comments = await ports.threadComments(repo, thread);
40
+ async function handOverThread(repo, ports, writer, issue) {
41
+ const comments = await ports.threadComments(repo, issue);
43
42
  return { comments, last: await lastHandOver(comments, writer) };
44
43
  }
45
44
  export async function waitingQuestions(repo, config, ports) {
@@ -52,8 +51,7 @@ export async function waitingQuestions(repo, config, ports) {
52
51
  return questions;
53
52
  }
54
53
  async function waitingQuestion(repo, config, ports, writer, issue) {
55
- const pr = (await readState(repo, issue.number))?.pr;
56
- const { comments, last } = await handOverThread(repo, ports, writer, pr ?? issue.number);
54
+ const { comments, last } = await handOverThread(repo, ports, writer, issue.number);
57
55
  const comment = comments[last];
58
56
  return {
59
57
  issue: issue.number,
@@ -61,7 +59,6 @@ async function waitingQuestion(repo, config, ports, writer, issue) {
61
59
  reason: comment?.body.slice(HAND_OVER.length).trim() ?? '',
62
60
  url: comment?.url ?? '',
63
61
  repo: slug(repo),
64
- ...(pr === undefined ? {} : { pr }),
65
62
  labels: { needsHuman: config.labels.needsHuman, skip: config.labels.skip },
66
63
  };
67
64
  }
@@ -70,10 +67,10 @@ export async function writerComments(context, log, issue) {
70
67
  const comments = (await ports.issueComments(repo, issue)).filter((comment) => !fromHarness(comment));
71
68
  return writerQuotes(comments, writers(repo, ports), (comment) => log.event('comment.skip', { author: comment.author }, 'quiet'));
72
69
  }
73
- export async function handOverReply(context, issue, pr) {
70
+ export async function handOverReply(context, issue) {
74
71
  const { repo, ports } = context;
75
72
  const writer = writers(repo, ports);
76
- const { comments, last } = await handOverThread(repo, ports, writer, pr ?? issue);
73
+ const { comments, last } = await handOverThread(repo, ports, writer, issue);
77
74
  if (last === -1) {
78
75
  return [];
79
76
  }
package/dist/handover.mjs CHANGED
@@ -12,8 +12,8 @@ export async function escalateAndFinish(job, note, reason) {
12
12
  return { done: true, report: await finish(job, 'needs-human', reason) };
13
13
  }
14
14
  export async function finishDone(job) {
15
- const { context, issue, state } = job;
16
- await setStatus(context, issue.number, state.pr, context.config.labels.done);
15
+ const { context, issue } = job;
16
+ await setStatus(context, issue.number, context.config.labels.done);
17
17
  await context.ports.closeIssue(context.repo, issue.number);
18
18
  return { done: true, report: await finish(job, 'done') };
19
19
  }
@@ -29,7 +29,6 @@ function issueReport(issue, outcome, state, started, reason) {
29
29
  issue,
30
30
  outcome,
31
31
  reason,
32
- pr: state.pr,
33
32
  ciFixes: state.ciFixes,
34
33
  reviewRounds: state.reviewRounds,
35
34
  ms: elapsedMs(started),
@@ -76,14 +75,8 @@ async function handOver(context, log, issue, state, reason) {
76
75
  const { repo, ports, config } = context;
77
76
  log.event('hand-over', { reason }, 'quiet');
78
77
  await writeState(repo, { ...state, handedOver: true });
79
- await setStatus(context, issue, state.pr, config.labels.needsHuman);
80
- const body = `${HAND_OVER} ${reason}`;
81
- if (state.pr === undefined) {
82
- await ports.commentOnIssue(repo, issue, body);
83
- }
84
- else {
85
- await ports.commentOnPr(repo, state.pr, body);
86
- }
78
+ await setStatus(context, issue, config.labels.needsHuman);
79
+ await ports.commentOnIssue(repo, issue, `${HAND_OVER} ${reason}`);
87
80
  }
88
81
  export async function claimedError(context, log, issue, state, error, started) {
89
82
  const { reason } = logIssueError(log, error, started);
package/dist/job.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { managedLabels } from './config.mjs';
2
2
  import { minutesToMs } from './durations.mjs';
3
- import { writeState } from './state.mjs';
4
3
  export const ROUND_CONTINUE = { done: false };
5
4
  export const GATE_PASSED = { done: false, fixed: false };
6
5
  export const GATE_FIXED = { done: false, fixed: true };
@@ -24,23 +23,7 @@ export function runRole(job, role, prompt, profile) {
24
23
  export function fallbackTitle(issue) {
25
24
  return `fix: resolve issue #${issue.number}`;
26
25
  }
27
- export async function openPr(job) {
28
- const { context, issue, log, state, branch } = job;
26
+ export async function setStatus(context, issue, label) {
29
27
  const { repo, config, ports } = context;
30
- const pr = await log.step('pull-request', { branch }, async () => {
31
- const existing = await ports.findPr(repo, branch);
32
- return (existing ??
33
- ports.createPr(repo, branch, context.base, state.title ?? fallbackTitle(issue), `Closes #${issue.number}\n\nOpened by next-issue.`, config.draftPullRequest));
34
- });
35
- state.pr = pr;
36
- await writeState(repo, state);
37
- log.event('pull-request.ready', { pr }, 'quiet');
38
- }
39
- export async function setStatus(context, issue, pr, label) {
40
- const { repo, config, ports } = context;
41
- const managed = managedLabels(config);
42
- await ports.setLabel(repo, 'issue', issue, label, managed);
43
- if (pr !== undefined) {
44
- await ports.setLabel(repo, 'pr', pr, label, managed);
45
- }
28
+ await ports.setLabel(repo, 'issue', issue, label, managedLabels(config));
46
29
  }
package/dist/open-job.mjs CHANGED
@@ -7,12 +7,12 @@ export async function openJob(context, issue, log, state, start, handedOver) {
7
7
  const { repo, config } = context;
8
8
  const branch = state.branch;
9
9
  await log.step('claim', { label: config.labels.inProgress }, async () => {
10
- await setStatus(context, issue.number, state.pr, config.labels.inProgress);
10
+ await setStatus(context, issue.number, config.labels.inProgress);
11
11
  await writeState(repo, state);
12
12
  });
13
13
  const comments = await log.step('comments', {}, () => writerComments(context, log, issue.number));
14
14
  const reply = handedOver
15
- ? await log.step('reply', {}, () => handOverReply(context, issue.number, state.pr))
15
+ ? await log.step('reply', {}, () => handOverReply(context, issue.number))
16
16
  : [];
17
17
  const worktree = await openWorktree(context, issue, log, branch, start);
18
18
  return {
package/dist/pending.mjs CHANGED
@@ -30,9 +30,7 @@ async function savedIssue(context, number) {
30
30
  }
31
31
  try {
32
32
  const { open, ...issue } = await ports.viewIssue(repo, number);
33
- if (saved === 'broken' ||
34
- open ||
35
- (saved.pr !== undefined && (await ports.prMerged(repo, saved.pr)))) {
33
+ if (saved === 'broken' || open) {
36
34
  return { open, issue };
37
35
  }
38
36
  return { open };
package/dist/poll.mjs CHANGED
@@ -7,14 +7,3 @@ export const REAL_CLOCK = {
7
7
  export function pause(clock, options, rest) {
8
8
  return clock.sleep(Math.min(secondsToMs(options.intervalSeconds), rest));
9
9
  }
10
- export async function pollUntil(options, clock, probe, settled) {
11
- const deadline = clock.now() + options.timeoutMs;
12
- for (;;) {
13
- const value = await probe();
14
- const rest = deadline - clock.now();
15
- if (settled(value) || rest <= 0) {
16
- return value;
17
- }
18
- await pause(clock, options, rest);
19
- }
20
- }
package/dist/ports.mjs CHANGED
@@ -1,14 +1,12 @@
1
1
  import { runAgent } from './agents.mjs';
2
2
  import { failedBaseLogs, waitForBaseChecks } from './base-checks.mjs';
3
- import { failedCheckLogs, waitForChecks } from './checks.mjs';
4
3
  import { run } from './exec.mjs';
5
4
  import { commitAll } from './git-commit.mjs';
6
5
  import { pushToBase, revertOnBase, squashOnto } from './git-land.mjs';
7
6
  import { abortMerge, commitMerge, startMerge } from './git-merge.mjs';
8
7
  import { deleteBranch, diff, discardChanges, disputeBranches, isDirty, latestSubject, push, resetToBase, revision, setAside, } from './git.mjs';
9
- import { canWrite, closeIssue, commentOnIssue, commentOnPr, issueComments, openBlockers, openIssues, reopenIssue, threadComments, viewIssue, } from './github.mjs';
8
+ import { canWrite, closeIssue, commentOnIssue, issueComments, openBlockers, openIssues, reopenIssue, threadComments, viewIssue, } from './github.mjs';
10
9
  import { setLabel } from './labels.mjs';
11
- import { createPr, findPr, markPrReady, mergeCommit, mergePr, prConflicts, prMerged, } from './pull-requests.mjs';
12
10
  import { detectSetupCommand } from './setup.mjs';
13
11
  import { addWorktree, findWorktree, removeWorktree } from './worktree.mjs';
14
12
  async function runSetup(command, cwd, timeoutMs) {
@@ -20,29 +18,20 @@ export const PORTS = {
20
18
  canWrite,
21
19
  closeIssue,
22
20
  commentOnIssue,
23
- commentOnPr,
24
21
  commitAll,
25
22
  commitMerge,
26
- createPr,
27
23
  deleteBranch,
28
24
  detectSetupCommand,
29
25
  diff,
30
26
  discardChanges,
31
27
  disputeBranches,
32
28
  failedBaseLogs,
33
- failedCheckLogs,
34
- findPr,
35
29
  findWorktree,
36
30
  isDirty,
37
31
  issueComments,
38
32
  latestSubject,
39
- markPrReady,
40
- mergeCommit,
41
- mergePr,
42
33
  openBlockers,
43
34
  openIssues,
44
- prConflicts,
45
- prMerged,
46
35
  push,
47
36
  pushToBase,
48
37
  removeWorktree,
@@ -59,5 +48,4 @@ export const PORTS = {
59
48
  threadComments,
60
49
  viewIssue,
61
50
  waitForBaseChecks,
62
- waitForChecks,
63
51
  };
package/dist/review.mjs CHANGED
@@ -14,7 +14,7 @@ export async function reviewRound(job) {
14
14
  if (exhausted) {
15
15
  return exhausted;
16
16
  }
17
- await setStatus(context, issue.number, state.pr, config.labels.inReview);
17
+ await setStatus(context, issue.number, config.labels.inReview);
18
18
  const earlier = history(state.reviewLog);
19
19
  const verdict = parseVerdict(await runReviewer(job, earlier));
20
20
  if (verdict === undefined) {
package/dist/serve.mjs CHANGED
@@ -40,7 +40,7 @@ export async function startWorker(options) {
40
40
  void close();
41
41
  }
42
42
  };
43
- const start = (socket, root, merge) => {
43
+ const start = (socket, root) => {
44
44
  const refusal = startRefusal(runs.get(root), restart);
45
45
  if (refusal !== undefined) {
46
46
  send(socket, { type: 'error', root, message: refusal });
@@ -54,7 +54,7 @@ export async function startWorker(options) {
54
54
  };
55
55
  broadcast(sockets, runs);
56
56
  options
57
- .runRepo(root, { ...parseArgs([]), merge }, runControls(run, update, () => void sendQuestions(root, () => sockets.clients)))
57
+ .runRepo(root, parseArgs([]), runControls(run, update, () => void sendQuestions(root, () => sockets.clients)))
58
58
  .then(() => update({ ...run.progress, status: endStatus(run) }), (error) => update({ ...run.progress, status: 'failed', error: message(error) }))
59
59
  .finally(closeWhenIdle);
60
60
  };
@@ -66,7 +66,7 @@ export async function startWorker(options) {
66
66
  }
67
67
  }
68
68
  else if (value.type === 'start') {
69
- start(socket, value.root, value.merge === true);
69
+ start(socket, value.root);
70
70
  }
71
71
  else if (value.type === 'stop') {
72
72
  if (requestStop(runs.get(value.root))) {
package/dist/state.mjs CHANGED
@@ -46,7 +46,6 @@ function isState(value) {
46
46
  typeof value.issue === 'number' &&
47
47
  PHASES.includes(value.phase) &&
48
48
  typeof value.branch === 'string' &&
49
- isOptional(value.pr, 'number') &&
50
49
  isOptional(value.title, 'string') &&
51
50
  typeof value.ciFixes === 'number' &&
52
51
  isOptional(value.commitFixes, 'number') &&
package/dist/summary.mjs CHANGED
@@ -18,9 +18,6 @@ export function count(reports, outcome) {
18
18
  }
19
19
  function issueLine(report) {
20
20
  const parts = [`#${report.issue} ${report.outcome.padEnd(11)}`];
21
- if (report.pr !== undefined) {
22
- parts.push(`pr ${report.pr}`);
23
- }
24
21
  if (report.ciFixes > 0) {
25
22
  parts.push(`ci fixes ${report.ciFixes}`);
26
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "3.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",
package/dist/checks.mjs DELETED
@@ -1,67 +0,0 @@
1
- import { pollChecks } from './check-poll.mjs';
2
- import { failedWith, succeeded } from './exec.mjs';
3
- import { ghRun } from './gh.mjs';
4
- import { isAncestor } from './git.mjs';
5
- import { prField } from './pull-requests.mjs';
6
- import { runLogs } from './run-logs.mjs';
7
- const CHECK_PENDING_CODE = 8;
8
- const NO_CHECKS = /no checks reported/i;
9
- function failedCheck(check) {
10
- return check.bucket === 'fail';
11
- }
12
- async function readChecks(repo, pr) {
13
- const result = await ghRun(repo, [
14
- 'pr',
15
- 'checks',
16
- String(pr),
17
- '--json',
18
- 'name,bucket,link,description',
19
- ]);
20
- const output = result.stdout.trim();
21
- if (output.length === 0) {
22
- if (NO_CHECKS.test(result.stderr)) {
23
- return 'none';
24
- }
25
- throw new Error(failedWith(`gh pr checks ${pr}`, result));
26
- }
27
- const checks = JSON.parse(output);
28
- return checks.length === 0 ? 'none' : checks;
29
- }
30
- async function watchOnce(repo, pr, intervalSeconds, timeoutMs, show) {
31
- const watch = await ghRun(repo, ['pr', 'checks', String(pr), '--watch', '--fail-fast', '--interval', String(intervalSeconds)], { show, timeoutMs });
32
- if (watch.timedOut) {
33
- return 'timeout';
34
- }
35
- if (succeeded(watch)) {
36
- return 'pass';
37
- }
38
- if (watch.code === CHECK_PENDING_CODE) {
39
- return 'pending';
40
- }
41
- const checks = await readChecks(repo, pr);
42
- if (checks !== 'none' && checks.some(failedCheck)) {
43
- return 'fail';
44
- }
45
- throw new Error(`gh pr checks ${pr} --watch failed with code ${watch.code} and no check failed: ${watch.stderr.trim()}`);
46
- }
47
- export function waitForChecks(repo, pr, options) {
48
- return pollChecks({
49
- head: () => prField(repo, pr, 'headRefOid'),
50
- lags: (head) => options.head === undefined
51
- ? Promise.resolve(true)
52
- : isAncestor(repo.root, head, options.head),
53
- list: async () => ((await readChecks(repo, pr)) === 'none' ? 'none' : 'some'),
54
- watch: (timeoutMs) => watchOnce(repo, pr, options.intervalSeconds, timeoutMs, options.show),
55
- }, options);
56
- }
57
- export async function failedCheckLogs(repo, pr, maxChars) {
58
- const checks = await readChecks(repo, pr);
59
- if (checks === 'none') {
60
- return 'The checks failed, but gh reports no check for the pull request.';
61
- }
62
- const failed = checks.filter(failedCheck).map((check) => ({
63
- heading: `## ${check.name}\n${check.description}`,
64
- runId: /\/actions\/runs\/(\d+)/.exec(check.link)?.[1],
65
- }));
66
- return runLogs(repo, failed, maxChars);
67
- }
@@ -1,60 +0,0 @@
1
- import { optionalFlag } from './exec.mjs';
2
- import { gh, ghJson, ghOnce, ghSucceeds, viewJson } from './gh.mjs';
3
- import { pollUntil, REAL_CLOCK } from './poll.mjs';
4
- export async function findPr(repo, branch) {
5
- const parsed = await ghJson(repo, [
6
- 'pr',
7
- 'list',
8
- '--head',
9
- branch,
10
- '--state',
11
- 'open',
12
- '--json',
13
- 'number',
14
- ]);
15
- return parsed[0]?.number;
16
- }
17
- export async function createPr(repo, branch, base, title, body, draft) {
18
- const created = await ghOnce(repo, [
19
- 'pr',
20
- 'create',
21
- '--head',
22
- branch,
23
- '--base',
24
- base,
25
- '--title',
26
- title,
27
- '--body',
28
- body,
29
- ...optionalFlag(draft, '--draft'),
30
- ]);
31
- const number = prNumber(created) ?? (await findPr(repo, branch));
32
- if (number === undefined) {
33
- throw new Error(`The pull request for ${branch} was not found after creation.`);
34
- }
35
- return number;
36
- }
37
- export function prNumber(output) {
38
- const match = /\/pull\/(\d+)\b/.exec(output);
39
- return match === null ? undefined : Number(match[1]);
40
- }
41
- export async function prField(repo, pr, field) {
42
- return gh(repo, ['pr', 'view', String(pr), '--json', field, '--jq', `.${field}`]);
43
- }
44
- export async function markPrReady(repo, pr) {
45
- return ghSucceeds(repo, ['pr', 'ready', String(pr)]);
46
- }
47
- export async function mergePr(repo, pr) {
48
- return ghSucceeds(repo, ['pr', 'merge', String(pr), '--squash', '--delete-branch']);
49
- }
50
- export async function prConflicts(repo, pr, options, clock = REAL_CLOCK) {
51
- const mergeable = await pollUntil(options, clock, () => prField(repo, pr, 'mergeable'), (value) => value !== 'UNKNOWN');
52
- return mergeable === 'CONFLICTING';
53
- }
54
- export async function prMerged(repo, pr) {
55
- return (await prField(repo, pr, 'state')) === 'MERGED';
56
- }
57
- export async function mergeCommit(repo, pr, options, clock = REAL_CLOCK) {
58
- const view = await pollUntil(options, clock, () => viewJson(repo, 'pr', pr, 'state,mergeCommit'), (value) => (value.state === 'MERGED' && !!value.mergeCommit?.oid) || value.state === 'CLOSED');
59
- return (view.state === 'MERGED' && view.mergeCommit?.oid) || undefined;
60
- }