next-issue 5.6.2 → 6.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
@@ -222,8 +222,8 @@ agents run inside the harness, and their commands and the harness commands run
222
222
  in a process group of their own, so a press reaches only the harness.
223
223
 
224
224
  The harness runs all git and `gh` commands itself. The commit holds all the
225
- changes in the worktree, so a setup command that writes a file outside
226
- `.gitignore` puts that file in the commit. The reviewer is the one agent whose
225
+ changes in the worktree, so a setup command that writes a file that git does
226
+ not ignore puts that file in the commit. The reviewer is the one agent whose
227
227
  changes never get that far: the harness discards them, and undoes any commit
228
228
  that the reviewer made, before it reads the verdict.
229
229
 
@@ -314,9 +314,13 @@ To write the file with the defaults, run the `init` command in the repository:
314
314
  npx -y next-issue@latest init
315
315
  ```
316
316
 
317
- The command writes `next-issue.config.json` in the root of the repository and
318
- adds `.next-issue/` and `.worktrees/` to `.gitignore`. It stops when the
319
- config file is there already; `--force` replaces it. The file holds no
317
+ The command writes `.next-issue/config.json` in the repository and adds
318
+ `.next-issue/` and `.worktrees/` to `info/exclude` in the git directory, which
319
+ linked worktrees share. It removes those two lines from `.gitignore`, and
320
+ deletes `.gitignore` when nothing else is left in it. It moves a
321
+ `next-issue.config.json` in the root to `.next-issue/config.json`; every other
322
+ command stops while that old file is there. It stops when the config file is
323
+ there already; `--force` replaces it. The file holds no
320
324
  `setupCommand`, because the harness deduces one from the lock file of the
321
325
  project.
322
326
 
@@ -529,8 +533,12 @@ of one repository never affect another. The worker:
529
533
  - holds `.next-issue/worker.lock` in the repository, with its process id, so
530
534
  only one worker runs per repository. A lock whose process is no longer alive
531
535
  is taken over;
532
- - runs at most one run at a time. Each run is like `next-issue` without
533
- `--watch`;
536
+ - runs at most one run at a time. A client starts it with
537
+ `{ "type": "start", "root": "<path>", "args": [...] }`. Each run is like
538
+ `next-issue` with those args, or with none when `args` is left out. It takes
539
+ `--once`, `--max <n>`, `--watch`, `--hunt`, `--reset`, `--verbose` and
540
+ `--quiet`, and refuses a command, `--json`, `--force`, `--help` or an
541
+ unknown argument with an `error` message;
534
542
  - sends every client the progress of every run when it connects and on every
535
543
  change: for each running issue the issue, the step, the tool count and the
536
544
  last tool, and the handled issues;
package/dist/args.mjs CHANGED
@@ -14,7 +14,7 @@ const LEVELS = new Map([
14
14
  ]);
15
15
  export const USAGE = `next-issue [command] [options]
16
16
 
17
- init write ${CONFIG_FILE} with the defaults
17
+ init write ${CONFIG_FILE} with the defaults and add .next-issue/ and .worktrees/ to info/exclude
18
18
  serve run the worker of this repository that pi extensions talk to
19
19
  stop stop the worker of this repository
20
20
  logs show the latest run log and follow it
@@ -76,3 +76,15 @@ function whole(value, option) {
76
76
  }
77
77
  return parsed;
78
78
  }
79
+ const OUTPUT_ONLY = ['json', 'force', 'help'];
80
+ export function parseStartArgs(argv) {
81
+ const args = parseArgs(argv);
82
+ if (args.command !== 'run') {
83
+ throw new Error(`start does not take ${args.command}`);
84
+ }
85
+ const refused = OUTPUT_ONLY.find((name) => args[name]);
86
+ if (refused !== undefined) {
87
+ throw new Error(`start does not take --${refused}`);
88
+ }
89
+ return args;
90
+ }
package/dist/cli.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { parseArgs, USAGE } from './args.mjs';
3
- import { writeDefaultConfig } from './config.mjs';
3
+ import { moveOldConfig, rejectOldConfig, writeDefaultConfig } from './config.mjs';
4
+ import { OLD_CONFIG_FILE } from './config-fields.mjs';
4
5
  import { message } from './errors.mjs';
5
6
  import { prettyJson } from './files.mjs';
6
7
  import { repoRoot } from './git.mjs';
7
- import { ensureIgnored } from './gitignore.mjs';
8
+ import { ensureExcluded, excludeFile, removeIgnored } from './ignore.mjs';
8
9
  import { listenForInterrupts } from './interrupt.mjs';
9
10
  import { stopWorker } from './lock.mjs';
10
11
  import { followLog, newestRunLog } from './logs.mjs';
@@ -26,15 +27,16 @@ async function main() {
26
27
  return 0;
27
28
  }
28
29
  const root = await repoRoot(process.cwd());
30
+ if (args.command === 'init') {
31
+ return init(root, args.force);
32
+ }
33
+ await rejectOldConfig(root);
29
34
  if (args.command === 'serve') {
30
35
  return serve(root);
31
36
  }
32
37
  if (args.command === 'stop') {
33
38
  return stop(root);
34
39
  }
35
- if (args.command === 'init') {
36
- return init(root, args.force);
37
- }
38
40
  if (args.command === 'logs') {
39
41
  return logs(root, args.json);
40
42
  }
@@ -64,13 +66,23 @@ async function logs(root, json) {
64
66
  return followLog(file, { json, tail }, (text) => write(process.stdout, text));
65
67
  }
66
68
  async function init(root, force) {
67
- const path = await writeDefaultConfig(root, force);
68
- await write(process.stdout, `wrote ${path}\n`);
69
- for (const directory of [STATE_DIR, WORKTREE_DIR]) {
70
- if (await ensureIgnored(root, `${directory}/`)) {
71
- await write(process.stdout, `added ${directory}/ to .gitignore\n`);
69
+ const exclude = await excludeFile(root);
70
+ const moved = await moveOldConfig(root, force);
71
+ if (moved === undefined) {
72
+ await write(process.stdout, `wrote ${await writeDefaultConfig(root, force)}\n`);
73
+ }
74
+ else {
75
+ await write(process.stdout, `moved ${OLD_CONFIG_FILE} to ${moved}\n`);
76
+ }
77
+ const entries = [STATE_DIR, WORKTREE_DIR].map((directory) => `${directory}/`);
78
+ for (const entry of entries) {
79
+ if (await ensureExcluded(exclude, entry)) {
80
+ await write(process.stdout, `added ${entry} to ${exclude}\n`);
72
81
  }
73
82
  }
83
+ for (const entry of await removeIgnored(root, entries)) {
84
+ await write(process.stdout, `removed ${entry} from .gitignore\n`);
85
+ }
74
86
  return 0;
75
87
  }
76
88
  main().then((code) => process.exit(code), async (error) => {
@@ -1,4 +1,5 @@
1
- export const CONFIG_FILE = 'next-issue.config.json';
1
+ export const CONFIG_FILE = '.next-issue/config.json';
2
+ export const OLD_CONFIG_FILE = 'next-issue.config.json';
2
3
  export function record(value, what) {
3
4
  if (typeof value !== 'object' || value === null || Array.isArray(value)) {
4
5
  throw new Error(`${CONFIG_FILE}: ${what} must be an object.`);
package/dist/config.mjs CHANGED
@@ -1,7 +1,8 @@
1
- import { join } from 'node:path';
2
- import { CONFIG_FILE, record, rejectUnknown, text, whole } from './config-fields.mjs';
1
+ import { mkdir, readFile, rename } from 'node:fs/promises';
2
+ import { dirname, join } from 'node:path';
3
+ import { CONFIG_FILE, OLD_CONFIG_FILE, record, rejectUnknown, text, whole, } from './config-fields.mjs';
3
4
  import { hasCode, message, parseJson } from './errors.mjs';
4
- import { readTextIfPresent, writeJson } from './files.mjs';
5
+ import { readTextIfPresent, unlessMissing, writeJson } from './files.mjs';
5
6
  const DEFAULTS = {
6
7
  remote: 'origin',
7
8
  issueLimit: 100,
@@ -68,19 +69,41 @@ const FILE_DEFAULTS = {
68
69
  function configFile(root) {
69
70
  return join(root, CONFIG_FILE);
70
71
  }
72
+ function existsAlready() {
73
+ return new Error(`${CONFIG_FILE} exists already. Use --force to replace it.`);
74
+ }
71
75
  export async function writeDefaultConfig(root, force) {
72
76
  const path = configFile(root);
77
+ await mkdir(dirname(path), { recursive: true });
73
78
  try {
74
79
  await writeJson(path, FILE_DEFAULTS, { flag: force ? 'w' : 'wx' });
75
80
  }
76
81
  catch (error) {
77
82
  if (hasCode(error, 'EEXIST')) {
78
- throw new Error(`${CONFIG_FILE} exists already. Use --force to replace it.`);
83
+ throw existsAlready();
79
84
  }
80
85
  throw error;
81
86
  }
82
87
  return path;
83
88
  }
89
+ export async function moveOldConfig(root, force) {
90
+ const old = join(root, OLD_CONFIG_FILE);
91
+ if ((await readTextIfPresent(old)) === undefined) {
92
+ return undefined;
93
+ }
94
+ const path = configFile(root);
95
+ if (!force && (await unlessMissing(() => readFile(path))) !== undefined) {
96
+ throw existsAlready();
97
+ }
98
+ await mkdir(dirname(path), { recursive: true });
99
+ await rename(old, path);
100
+ return path;
101
+ }
102
+ export async function rejectOldConfig(root) {
103
+ if ((await readTextIfPresent(join(root, OLD_CONFIG_FILE))) !== undefined) {
104
+ throw new Error(`${OLD_CONFIG_FILE} moved to ${CONFIG_FILE}. Run next-issue init to move it.`);
105
+ }
106
+ }
84
107
  export async function loadConfig(root) {
85
108
  let raw;
86
109
  try {
@@ -0,0 +1,32 @@
1
+ import { appendFile, mkdir, rm, writeFile } from 'node:fs/promises';
2
+ import { join, resolve } from 'node:path';
3
+ import { readTextIfPresent, readTextOrEmpty } from './files.mjs';
4
+ import { git } from './git.mjs';
5
+ export async function excludeFile(root) {
6
+ return join(resolve(root, await git(root, ['rev-parse', '--git-common-dir'])), 'info', 'exclude');
7
+ }
8
+ export async function ensureExcluded(path, entry) {
9
+ const current = await readTextOrEmpty(path);
10
+ if (current.split('\n').some((line) => line.trim() === entry)) {
11
+ return false;
12
+ }
13
+ const gap = current.length === 0 || current.endsWith('\n') ? '' : '\n';
14
+ await mkdir(join(path, '..'), { recursive: true });
15
+ await appendFile(path, `${gap}${entry}\n`);
16
+ return true;
17
+ }
18
+ export async function removeIgnored(root, entries) {
19
+ const path = join(root, '.gitignore');
20
+ const current = await readTextIfPresent(path);
21
+ if (current === undefined) {
22
+ return [];
23
+ }
24
+ const lines = current.split('\n');
25
+ const removed = entries.filter((entry) => lines.some((line) => line.trim() === entry));
26
+ if (removed.length === 0) {
27
+ return [];
28
+ }
29
+ const kept = lines.filter((line) => !removed.includes(line.trim())).join('\n');
30
+ await (kept.trim() === '' ? rm(path) : writeFile(path, kept));
31
+ return removed;
32
+ }
package/dist/serve.mjs CHANGED
@@ -3,7 +3,7 @@ import { mkdir, rm } from 'node:fs/promises';
3
3
  import { createServer } from 'node:http';
4
4
  import { dirname } from 'node:path';
5
5
  import { WebSocketServer } from 'ws';
6
- import { parseArgs } from './args.mjs';
6
+ import { parseStartArgs } from './args.mjs';
7
7
  import { stopChildren } from './children.mjs';
8
8
  import { message } from './errors.mjs';
9
9
  import { lock } from './lock.mjs';
@@ -40,12 +40,20 @@ export async function startWorker(options) {
40
40
  void close();
41
41
  }
42
42
  };
43
- const start = (socket, root) => {
43
+ const start = (socket, root, argv) => {
44
44
  const refusal = startRefusal(runs.get(root), restart);
45
45
  if (refusal !== undefined) {
46
46
  send(socket, { type: 'error', root, message: refusal });
47
47
  return;
48
48
  }
49
+ let args;
50
+ try {
51
+ args = parseStartArgs(argv);
52
+ }
53
+ catch (error) {
54
+ send(socket, { type: 'error', root, message: message(error) });
55
+ return;
56
+ }
49
57
  const run = { progress: startProgress(), stop: false };
50
58
  runs.set(root, run);
51
59
  const update = (next) => {
@@ -54,7 +62,7 @@ export async function startWorker(options) {
54
62
  };
55
63
  broadcast(sockets, runs);
56
64
  options
57
- .runRepo(root, parseArgs([]), runControls(run, update, () => void sendQuestions(root, () => sockets.clients)))
65
+ .runRepo(root, args, runControls(run, update, () => void sendQuestions(root, () => sockets.clients)))
58
66
  .then(() => update({ ...run.progress, status: endStatus(run) }), (error) => update({ ...run.progress, status: 'failed', error: message(error) }))
59
67
  .finally(closeWhenIdle);
60
68
  };
@@ -66,7 +74,7 @@ export async function startWorker(options) {
66
74
  }
67
75
  }
68
76
  else if (value.type === 'start') {
69
- start(socket, value.root);
77
+ start(socket, value.root, value.args ?? []);
70
78
  }
71
79
  else if (value.type === 'stop') {
72
80
  if (requestStop(runs.get(value.root))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "5.6.2",
3
+ "version": "6.0.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",
@@ -1,13 +0,0 @@
1
- import { appendFile } from 'node:fs/promises';
2
- import { join } from 'node:path';
3
- import { readTextOrEmpty } from './files.mjs';
4
- export async function ensureIgnored(root, entry) {
5
- const path = join(root, '.gitignore');
6
- const current = await readTextOrEmpty(path);
7
- if (current.split('\n').some((line) => line.trim() === entry)) {
8
- return false;
9
- }
10
- const gap = current.length === 0 || current.endsWith('\n') ? '' : '\n';
11
- await appendFile(path, `${gap}${entry}\n`);
12
- return true;
13
- }