next-issue 6.6.41 → 6.6.43

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
@@ -483,7 +483,10 @@ A `setupCommand` that fails, or that does not finish in `setupTimeoutMinutes`,
483
483
  hands the issue to a person. The wait for the checks has its own limit, so
484
484
  `commandTimeoutMinutes` holds for every other `git` and `gh` command. State per
485
485
  issue goes to `.next-issue/<issue>.json`, so a new run continues where the last
486
- run stopped. A state file that is not valid JSON, or that does not hold a valid
486
+ run stopped. The harness writes a state file to a temporary file in the same
487
+ folder and renames it over the old one, so a state file is replaced in one
488
+ step: a run killed or a disk that fills up during a write leaves the earlier
489
+ state. A state file that is not valid JSON, or that does not hold a valid
487
490
  state, gives the issue an `error` outcome that names the file, rather than a
488
491
  silent skip.
489
492
 
package/dist/files.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { readdir, readFile, writeFile } from 'node:fs/promises';
1
+ import { randomUUID } from 'node:crypto';
2
+ import { readdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
2
3
  import { hasCode } from './errors.mjs';
3
4
  export function readTextOrEmpty(path) {
4
5
  return readFile(path, 'utf8').catch(() => '');
@@ -12,6 +13,17 @@ export function prettyJson(value) {
12
13
  export function writeJson(path, value, options) {
13
14
  return writeFile(path, prettyJson(value), options);
14
15
  }
16
+ export async function replaceJson(path, value) {
17
+ const draft = `${path}.${process.pid}.${randomUUID()}.tmp`;
18
+ try {
19
+ await writeFile(draft, prettyJson(value));
20
+ await rename(draft, path);
21
+ }
22
+ catch (error) {
23
+ await rm(draft, { force: true });
24
+ throw error;
25
+ }
26
+ }
15
27
  export async function unlessMissing(read) {
16
28
  try {
17
29
  return await read();
package/dist/loop.mjs CHANGED
@@ -11,7 +11,7 @@ export async function runIssues(args, loop, seen = new Set()) {
11
11
  for (;;) {
12
12
  if (claiming && room()) {
13
13
  try {
14
- await claimIssues(loop, seen, running, room);
14
+ claiming = await claimIssues(loop, seen, running, room);
15
15
  }
16
16
  catch (failure) {
17
17
  error = failure;
@@ -47,7 +47,13 @@ function loopResult(reports, stoppedAt, error) {
47
47
  };
48
48
  }
49
49
  async function claimIssues(loop, seen, running, room) {
50
+ if (loop.stop()) {
51
+ return false;
52
+ }
50
53
  const issues = await loop.issues();
54
+ if (loop.stop()) {
55
+ return false;
56
+ }
51
57
  for (const issue of issues.filter((candidate) => !seen.has(candidate.number))) {
52
58
  if (!room()) {
53
59
  break;
@@ -55,6 +61,7 @@ async function claimIssues(loop, seen, running, room) {
55
61
  seen.add(issue.number);
56
62
  running.set(issue.number, loop.process(issue).then((report) => ({ issue: issue.number, report }), (failure) => ({ issue: issue.number, failure })));
57
63
  }
64
+ return true;
58
65
  }
59
66
  export function exitCode(reports) {
60
67
  return reports.some((report) => report.outcome === 'needs-human' || report.outcome === 'error')
package/dist/state.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { mkdir, readdir, rm } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import { parseJson } from './errors.mjs';
4
- import { readTextIfPresent, unlessMissing, writeJson } from './files.mjs';
4
+ import { readTextIfPresent, replaceJson, unlessMissing } from './files.mjs';
5
5
  import { isRecord } from './records.mjs';
6
6
  export const STATE_DIR = '.next-issue';
7
7
  export function stateDir(root) {
@@ -80,7 +80,7 @@ export function resetState(state) {
80
80
  }
81
81
  export async function writeState(repo, state) {
82
82
  await mkdir(stateDir(repo.root), { recursive: true });
83
- await writeJson(file(repo, state.issue), state);
83
+ await replaceJson(file(repo, state.issue), state);
84
84
  }
85
85
  export async function dropState(repo, issue) {
86
86
  await rm(file(repo, issue), { force: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.41",
3
+ "version": "6.6.43",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",