next-issue 6.6.88 → 6.6.90

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
@@ -590,7 +590,10 @@ the mark and keeps the branch and the step that the last run reached, so the
590
590
  work carries on where it stopped. After a revert, the branch holds the change
591
591
  again on top of the revert, so the change goes back to the review. An issue
592
592
  that still has the label is not claimed, unless it has an answer to the
593
- hand-over: then the run claims it and takes the label off.
593
+ hand-over: then the run claims it and takes the label off. When the label of a
594
+ hand-over reaches GitHub but its comment does not, an answer to an earlier
595
+ hand-over does not count: the issue waits, and the worker lists it, until a
596
+ person takes the label off or a writer comments after that hand-over.
594
597
 
595
598
  To give guidance, answer the hand-over with a comment on the issue. When the run
596
599
  resumes the issue, it reads the comments posted after its last
package/dist/github.mjs CHANGED
@@ -42,12 +42,17 @@ export async function issueComments(repo, issue) {
42
42
  return parsed.comments.map((comment) => ({ author: comment.author.login, body: comment.body }));
43
43
  }
44
44
  export async function threadComments(repo, number) {
45
- const raw = await ghApi(repo, `issues/${number}/comments`, '.[] | [.user.login, .body, .html_url] | @json', { paginate: true });
45
+ const raw = await ghApi(repo, `issues/${number}/comments`, '.[] | [.user.login, .body, .html_url, .created_at] | @json', { paginate: true });
46
46
  return lines(raw).map((line) => parseComment(line, number));
47
47
  }
48
48
  function parseComment(line, number) {
49
- const [author, body, url] = parseJson(line, () => `gh gave a comment of #${number} that is not valid JSON: ${line}`);
50
- return url === undefined ? { author, body: body ?? '' } : { author, body: body ?? '', url };
49
+ const [author, body, url, createdAt] = parseJson(line, () => `gh gave a comment of #${number} that is not valid JSON: ${line}`);
50
+ return {
51
+ author,
52
+ body: body ?? '',
53
+ ...(url === undefined ? {} : { url }),
54
+ ...(createdAt === undefined ? {} : { createdAt }),
55
+ };
51
56
  }
52
57
  export async function canWrite(repo, login) {
53
58
  try {
@@ -1,4 +1,5 @@
1
1
  import { repoArg } from './gh.mjs';
2
+ import { readState } from './state.mjs';
2
3
  export const HAND_OVER = 'next-issue needs help:';
3
4
  const HARNESS_HEADINGS = [HAND_OVER, '### Review:', '### Fixer:'];
4
5
  function fromHarness(comment) {
@@ -53,22 +54,41 @@ export async function waitingQuestions(repo, config, ports) {
53
54
  }
54
55
  return questions;
55
56
  }
56
- async function replyAfter(comments, last, writer) {
57
- if (last === -1) {
58
- return [];
57
+ function postedAfter(comment, since) {
58
+ return since !== undefined && comment.createdAt !== undefined && comment.createdAt > since;
59
+ }
60
+ /** With a pending hand-over, only comments after it answer; without its time, none do. */
61
+ function answerCandidates(comments, last, pending) {
62
+ if (pending !== undefined) {
63
+ return comments.filter((comment) => postedAfter(comment, pending.since));
64
+ }
65
+ return last === -1 ? [] : comments.slice(last + 1);
66
+ }
67
+ async function replyAfter(comments, last, writer, pending) {
68
+ return writerQuotes(answerCandidates(comments, last, pending).filter((comment) => !fromHarness(comment)), writer);
69
+ }
70
+ async function pendingHandOver(repo, issue) {
71
+ try {
72
+ return (await readState(repo, issue))?.pendingHandOver;
73
+ }
74
+ catch {
75
+ return undefined;
59
76
  }
60
- return writerQuotes(comments.slice(last + 1).filter((comment) => !fromHarness(comment)), writer);
61
77
  }
62
78
  async function waitingQuestion(repo, config, ports, writer, issue) {
63
79
  const { comments, last } = await handOverThread(repo, ports, writer, issue.number);
64
- if ((await replyAfter(comments, last, writer)).length > 0) {
80
+ const pending = await pendingHandOver(repo, issue.number);
81
+ if ((await replyAfter(comments, last, writer, pending)).length > 0) {
65
82
  return undefined;
66
83
  }
67
- const comment = comments[last];
84
+ const latest = comments[last];
85
+ const comment = pending === undefined || (latest !== undefined && postedAfter(latest, pending.since))
86
+ ? latest
87
+ : undefined;
68
88
  return {
69
89
  issue: issue.number,
70
90
  title: issue.title,
71
- reason: comment?.body.slice(HAND_OVER.length).trim() ?? '',
91
+ reason: comment?.body.slice(HAND_OVER.length).trim() ?? pending?.reason ?? '',
72
92
  url: comment?.url ?? '',
73
93
  repo: repoArg(repo),
74
94
  labels: { needsHuman: config.labels.needsHuman, skip: config.labels.skip },
@@ -79,9 +99,22 @@ export async function writerComments(context, log, issue) {
79
99
  const comments = (await ports.issueComments(repo, issue)).filter((comment) => !fromHarness(comment));
80
100
  return writerQuotes(comments, writers(repo, ports), (comment) => log.event('comment.skip', { author: comment.author }, 'quiet'));
81
101
  }
82
- export async function handOverReply(context, issue) {
102
+ export async function handOverReply(context, issue, pending) {
83
103
  const { repo, ports } = context;
84
104
  const writer = writers(repo, ports);
85
105
  const { comments, last } = await handOverThread(repo, ports, writer, issue);
86
- return replyAfter(comments, last, writer);
106
+ return replyAfter(comments, last, writer, pending);
107
+ }
108
+ /** The time of the newest thread comment, `''` for an empty thread, `undefined` when the thread cannot be read. */
109
+ export async function threadEnd(context, issue) {
110
+ try {
111
+ const comments = await context.ports.threadComments(context.repo, issue);
112
+ return comments.reduce((end, comment) => {
113
+ const at = comment.createdAt ?? '';
114
+ return at > end ? at : end;
115
+ }, '');
116
+ }
117
+ catch {
118
+ return undefined;
119
+ }
87
120
  }
package/dist/handover.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { runStopped } from './children.mjs';
2
2
  import { elapsedMs } from './durations.mjs';
3
3
  import { message } from './errors.mjs';
4
- import { HAND_OVER } from './hand-over-comments.mjs';
4
+ import { HAND_OVER, threadEnd } from './hand-over-comments.mjs';
5
5
  import { setStatus, } from './job.mjs';
6
6
  import { oneAtATime } from './lock.mjs';
7
7
  import { revertFailedFix } from './revert.mjs';
@@ -142,14 +142,20 @@ async function cleanUp(context, log, branch) {
142
142
  async function handOver(context, log, issue, state, reason) {
143
143
  const { repo, ports, config } = context;
144
144
  log.event('hand-over', { reason }, 'quiet');
145
+ const { pendingHandOver: _pending, ...rest } = state;
145
146
  try {
147
+ const since = await threadEnd(context, issue);
148
+ await writeState(repo, {
149
+ ...rest,
150
+ pendingHandOver: { reason, ...(since === undefined ? {} : { since }) },
151
+ });
146
152
  await setStatus(context, issue, config.labels.needsHuman);
147
153
  await ports.commentOnIssue(repo, issue, handOverComment(reason));
148
154
  }
149
155
  catch (error) {
150
156
  throw new HandOverFailed(reason, error);
151
157
  }
152
- await writeState(repo, { ...state, handedOver: true });
158
+ await writeState(repo, { ...rest, handedOver: true });
153
159
  }
154
160
  class HandOverFailed extends Error {
155
161
  reason;
package/dist/open-job.mjs CHANGED
@@ -2,7 +2,7 @@ import { handOverReply, writerComments } from './hand-over-comments.mjs';
2
2
  import { setStatus } from './job.mjs';
3
3
  import { oneAtATime } from './lock.mjs';
4
4
  import { writeState } from './state.mjs';
5
- export async function openJob(context, issue, log, state, start, handedOver) {
5
+ export async function openJob(context, issue, log, state, start, handedOver, pending) {
6
6
  const started = Date.now();
7
7
  const { repo, config } = context;
8
8
  const branch = state.branch;
@@ -12,7 +12,7 @@ export async function openJob(context, issue, log, state, start, handedOver) {
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))
15
+ ? await log.step('reply', {}, () => handOverReply(context, issue.number, pending))
16
16
  : [];
17
17
  const worktree = await openWorktree(context, issue, log, branch, start);
18
18
  return {
package/dist/pipeline.mjs CHANGED
@@ -6,7 +6,8 @@ import { implement } from './implement.mjs';
6
6
  import { openJob } from './open-job.mjs';
7
7
  import { reviewRound } from './review.mjs';
8
8
  import { skipReport, unclaimedError } from './skip.mjs';
9
- import { newState, readState, resetState } from './state.mjs';
9
+ import { hasLabel } from './labels.mjs';
10
+ import { newState, readState, resetState, } from './state.mjs';
10
11
  import { setUp } from './worktree-setup.mjs';
11
12
  export async function processIssue(context, issue, claimed = () => undefined) {
12
13
  const { repo } = context;
@@ -29,12 +30,13 @@ export async function processIssue(context, issue, claimed = () => undefined) {
29
30
  }
30
31
  claimed();
31
32
  log.event('issue.start', { title: issue.title, createdAt: issue.createdAt }, 'quiet');
32
- const state = startState(context, issue, saved);
33
+ const handedOver = wasHandedOver(context, issue, saved);
34
+ const state = startState(context, issue, saved, handedOver);
33
35
  let report;
34
36
  try {
35
37
  report = closing
36
38
  ? await finishClosing(context, issue, log, state, started)
37
- : await work(context, issue, log, state, saved === undefined, saved?.handedOver === true);
39
+ : await work(context, issue, log, state, saved === undefined, handedOver, saved?.pendingHandOver);
38
40
  }
39
41
  catch (error) {
40
42
  if (!runStopped()) {
@@ -45,14 +47,22 @@ export async function processIssue(context, issue, claimed = () => undefined) {
45
47
  log.event('issue.end', { outcome: report.outcome, reason: report.reason, ms: report.ms }, 'quiet');
46
48
  return report;
47
49
  }
48
- function startState(context, issue, saved) {
50
+ /** A hand-over whose comment failed counts once the issue is claimed with its label still on, that is with an answer. */
51
+ function wasHandedOver(context, issue, saved) {
52
+ if (saved?.handedOver === true) {
53
+ return true;
54
+ }
55
+ return (saved?.pendingHandOver !== undefined && hasLabel(issue.labels, context.config.labels.needsHuman));
56
+ }
57
+ function startState(context, issue, saved, handedOver) {
49
58
  if (saved === undefined) {
50
59
  return newState(issue.number, branchName(issue.number));
51
60
  }
52
- return context.reset || saved.handedOver === true ? resetState(saved) : saved;
61
+ const { pendingHandOver: _pending, ...rest } = saved;
62
+ return context.reset || handedOver ? resetState(saved) : rest;
53
63
  }
54
- async function work(context, issue, log, state, start, handedOver) {
55
- const job = await openJob(context, issue, log, state, start, handedOver);
64
+ async function work(context, issue, log, state, start, handedOver, pending) {
65
+ const job = await openJob(context, issue, log, state, start, handedOver, pending);
56
66
  const setup = await setUp(job);
57
67
  if (setup.done) {
58
68
  return setup.report;
package/dist/serve.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
1
2
  import { mkdir, rename, rm } from 'node:fs/promises';
2
3
  import { createServer } from 'node:http';
3
4
  import { basename, dirname, join } from 'node:path';
@@ -35,6 +36,9 @@ export async function startWorker(options) {
35
36
  const server = createServer();
36
37
  const sockets = new WebSocketServer({ server });
37
38
  const sendQuestions = questionSender(options.questions);
39
+ // Taken outside any run, so a question read that an issue end starts does not take on
40
+ // the run's stop, command log, children or default timeout.
41
+ const outsideRuns = AsyncLocalStorage.snapshot();
38
42
  const busy = () => [...runs.values()].some(active);
39
43
  let idleTimer;
40
44
  const { closed, close } = closer(async () => {
@@ -67,7 +71,7 @@ export async function startWorker(options) {
67
71
  broadcast(sockets, runs);
68
72
  };
69
73
  broadcast(sockets, runs);
70
- withRunChildren(run.children, () => options.runRepo(root, args, runControls(run, update, () => void sendQuestions(root, () => sockets.clients))))
74
+ withRunChildren(run.children, () => options.runRepo(root, args, runControls(run, update, () => outsideRuns(() => void sendQuestions(root, () => sockets.clients)))))
71
75
  .then(() => update({ ...run.progress, status: endStatus(run) }), (error) => update({ ...run.progress, status: 'failed', error: message(error) }))
72
76
  .finally(closeWhenIdle);
73
77
  };
package/dist/skip.mjs CHANGED
@@ -25,7 +25,7 @@ export function skipReason(issue, config, resuming, answered = false) {
25
25
  export async function skipReport(context, log, issue, saved, started) {
26
26
  let answered;
27
27
  try {
28
- answered = await hasAnswer(context, issue);
28
+ answered = await hasAnswer(context, issue, saved);
29
29
  }
30
30
  catch (error) {
31
31
  return readError(log, issue, saved, error, started);
@@ -51,11 +51,11 @@ export async function skipReport(context, log, issue, saved, started) {
51
51
  }
52
52
  return undefined;
53
53
  }
54
- async function hasAnswer(context, issue) {
54
+ async function hasAnswer(context, issue, saved) {
55
55
  if (!hasLabel(issue.labels, context.config.labels.needsHuman)) {
56
56
  return false;
57
57
  }
58
- return (await handOverReply(context, issue.number)).length > 0;
58
+ return (await handOverReply(context, issue.number, saved?.pendingHandOver)).length > 0;
59
59
  }
60
60
  function readError(log, issue, saved, error, started) {
61
61
  if (!runStopped()) {
package/dist/state.mjs CHANGED
@@ -45,6 +45,9 @@ function isReviewRound(value) {
45
45
  isOptional(value.dispute, 'string') &&
46
46
  isOptional(value.settled, 'string'));
47
47
  }
48
+ function isPending(value) {
49
+ return isRecord(value) && typeof value.reason === 'string' && isOptional(value.since, 'string');
50
+ }
48
51
  function isState(value) {
49
52
  return (isRecord(value) &&
50
53
  typeof value.issue === 'number' &&
@@ -66,6 +69,7 @@ function isState(value) {
66
69
  Array.isArray(value.reviewLog) &&
67
70
  value.reviewLog.every(isReviewRound) &&
68
71
  isOptional(value.handedOver, 'boolean') &&
72
+ (value.pendingHandOver === undefined || isPending(value.pendingHandOver)) &&
69
73
  isOptional(value.closing, 'boolean'));
70
74
  }
71
75
  export async function savedIssues(repo) {
@@ -79,7 +83,7 @@ export function newState(issue, branch) {
79
83
  return { issue, phase: 'claimed', branch, ciFixes: 0, reviewRounds: 0, reviewLog: [] };
80
84
  }
81
85
  export function resetState(state) {
82
- const { handedOver: _handedOver, ...rest } = state;
86
+ const { handedOver: _handedOver, pendingHandOver: _pending, ...rest } = state;
83
87
  const phase = rest.phase === 'approved' ? 'review' : rest.phase;
84
88
  return { ...rest, phase, ciFixes: 0, commitFixes: 0, reviewRounds: 0, reviewLog: [] };
85
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.88",
3
+ "version": "6.6.90",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",