next-issue 17.1.0 → 17.2.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
@@ -28,7 +28,7 @@ flowchart TD
28
28
 
29
29
  ## Install and quick start
30
30
 
31
- You need Node 24 or later, git 2.40 or later, `gh` logged in with write access to the repository, a `remote` on GitHub and Claude Code, logged in. See [Requirements](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#requirements).
31
+ You need Node 24 or later, git 2.40 or later, `gh` logged in with write access to the repository, a `remote` on GitHub and Claude Code, logged in. The repository needs a root `package.json` with the scripts `format`, `lint`, `typecheck` and `test`, each of which fails on a problem; `format` checks the formatting and does not write files. The harness runs them before each push, since no person checks the change, see [Local checks](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#local-checks). See [Requirements](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#requirements).
32
32
 
33
33
  Run the harness inside a git repository:
34
34
 
@@ -58,8 +58,7 @@ It writes `.next-issue/config.json` with the defaults, or keeps the file when it
58
58
  | `checkGraceSeconds` | `60` | The time to wait for checks to show on the base branch |
59
59
  | `checkIntervalSeconds` | `15` | The time between two reads of the checks |
60
60
  | `checkTimeoutMinutes` | `60` | The limit for one wait for the checks |
61
- | `checks` | `[]` | Shell commands that must pass before an approved change is pushed |
62
- | `checksTimeoutMinutes` | `30` | The limit for one command in `checks` |
61
+ | `checksTimeoutMinutes` | `30` | The limit for one script of the local gate |
63
62
  | `commandTimeoutMinutes` | `10` | The limit for one `git` or `gh` command |
64
63
  | `concurrency` | `1` | The most issues that an agent works on at the same time |
65
64
  | `diffMaxChars` | `60000` | The maximum length of the diff that the reviewer reads |
package/dist/cli.mjs CHANGED
@@ -4,6 +4,7 @@ import { moveOldConfig, rejectOldConfig, writeDefaultConfig } from './shared/con
4
4
  import { OLD_CONFIG_FILE } from './shared/config-fields.mjs';
5
5
  import { message } from './shared/errors.mjs';
6
6
  import { repoRoot } from './shared/git.mjs';
7
+ import { requireScripts } from './shared/setup.mjs';
7
8
  import { ensureExcluded, excludeFile, removeIgnored } from './cli/ignore.mjs';
8
9
  import { followLog, newestRunLog } from './cli/logs.mjs';
9
10
  import { serve } from './worker/serve.mjs';
@@ -48,6 +49,9 @@ async function main() {
48
49
  if (args.command === 'logs') {
49
50
  return logs(root);
50
51
  }
52
+ if (args.command === 'start') {
53
+ await requireScripts(root);
54
+ }
51
55
  await excludeStateDirectories(root, process.stderr);
52
56
  if (args.command === 'serve') {
53
57
  return serve(root);
@@ -81,6 +85,7 @@ async function init(root, args) {
81
85
  for (const folder of await installSkills(scope)) {
82
86
  await write(process.stdout, `wrote ${folder}\n`);
83
87
  }
88
+ await requireScripts(root);
84
89
  return 0;
85
90
  }
86
91
  async function excludeStateDirectories(root, stream) {
@@ -31,13 +31,6 @@ export function text(value, field, allowEmpty) {
31
31
  }
32
32
  return value;
33
33
  }
34
- export function commands(value, field) {
35
- if (!Array.isArray(value) ||
36
- !value.every((entry) => typeof entry === 'string' && entry.trim().length > 0)) {
37
- throw new Error(`${CONFIG_FILE}: ${field} must be a list of commands that are not empty.`);
38
- }
39
- return [...value];
40
- }
41
34
  export function checkNames(value, field) {
42
35
  if (!Array.isArray(value) || !value.every((entry) => typeof entry === 'string' && entry !== '')) {
43
36
  throw new Error(`${CONFIG_FILE}: ${field} must be a list of check names that are not empty.`);
@@ -1,6 +1,6 @@
1
1
  import { mkdir, readFile, rename } from 'node:fs/promises';
2
2
  import { dirname, join } from 'node:path';
3
- import { CONFIG_FILE, checkNames, commands, OLD_CONFIG_FILE, record, rejectUnknown, text, whole, } from './config-fields.mjs';
3
+ import { CONFIG_FILE, checkNames, OLD_CONFIG_FILE, record, rejectUnknown, text, whole, } from './config-fields.mjs';
4
4
  import { MAX_TIMER_MS } from './durations.mjs';
5
5
  import { hasCode, message, parseJson } from './errors.mjs';
6
6
  import { readTextIfPresent, replaceJson, sortKeys, unlessMissing, writeJson } from './files.mjs';
@@ -21,7 +21,6 @@ const DEFAULTS = {
21
21
  logMaxChars: 20000,
22
22
  diffMaxChars: 60000,
23
23
  keepRunDays: 7,
24
- checks: [],
25
24
  checksTimeoutMinutes: 30,
26
25
  ignoredChecks: [],
27
26
  models: {},
@@ -38,7 +37,6 @@ const DEFAULTS = {
38
37
  function defaults() {
39
38
  return {
40
39
  ...DEFAULTS,
41
- checks: [...DEFAULTS.checks],
42
40
  ignoredChecks: [...DEFAULTS.ignoredChecks],
43
41
  models: { ...DEFAULTS.models },
44
42
  labels: { ...DEFAULTS.labels },
@@ -162,9 +160,6 @@ function parseConfig(value) {
162
160
  if (file.setupCommand !== undefined) {
163
161
  config.setupCommand = text(file.setupCommand, 'setupCommand', false);
164
162
  }
165
- if (file.checks !== undefined) {
166
- config.checks = commands(file.checks, 'checks');
167
- }
168
163
  if (file.ignoredChecks !== undefined) {
169
164
  config.ignoredChecks = checkNames(file.ignoredChecks, 'ignoredChecks');
170
165
  }
@@ -1,5 +1,7 @@
1
1
  import { access } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
+ import { message, parseJson } from './errors.mjs';
4
+ import { readTextIfPresent } from './files.mjs';
3
5
  const MARKERS = [
4
6
  ['pnpm-lock.yaml', 'pnpm install --frozen-lockfile'],
5
7
  ['package-lock.json', 'npm ci'],
@@ -27,3 +29,41 @@ export async function detectSetupCommand(root) {
27
29
  }
28
30
  return undefined;
29
31
  }
32
+ export const SCRIPTS = ['format', 'lint', 'typecheck', 'test'];
33
+ const RUNNERS = [
34
+ ['pnpm-lock.yaml', 'pnpm run'],
35
+ ['package-lock.json', 'npm run'],
36
+ ['yarn.lock', 'yarn run'],
37
+ ['bun.lock', 'bun run'],
38
+ ['bun.lockb', 'bun run'],
39
+ ];
40
+ /** The command that runs a package script, from the lock file of the package manager. */
41
+ export async function scriptRunner(root) {
42
+ for (const [file, runner] of RUNNERS) {
43
+ if (await exists(join(root, file))) {
44
+ return runner;
45
+ }
46
+ }
47
+ return 'npm run';
48
+ }
49
+ function listed(names) {
50
+ const quoted = names.map((name) => `\`${name}\``);
51
+ return quoted.length === 1
52
+ ? quoted[0]
53
+ : `${quoted.slice(0, -1).join(', ')} and ${quoted.at(-1)}`;
54
+ }
55
+ const WHY = `next-issue runs ${listed(SCRIPTS)} before each push, since the humanless flow relies on these checks instead of a person. Each script must fail on a problem, and \`format\` must check the formatting, not write files.`;
56
+ /** Fails when the root `package.json` is missing or lacks any of the scripts of the local gate. */
57
+ export async function requireScripts(root) {
58
+ const text = await readTextIfPresent(join(root, 'package.json'));
59
+ if (text === undefined) {
60
+ throw new Error(`there is no package.json at the root of the repository, so it lacks the scripts ${listed(SCRIPTS)}. ${WHY}`);
61
+ }
62
+ const file = parseJson(text, (error) => `package.json is not valid JSON: ${message(error)}`);
63
+ const scripts = file?.scripts ?? {};
64
+ const missing = SCRIPTS.filter((name) => typeof scripts[name] !== 'string');
65
+ if (missing.length > 0) {
66
+ const noun = missing.length === 1 ? 'script' : 'scripts';
67
+ throw new Error(`the root package.json lacks the ${noun} ${listed(missing)}. ${WHY}`);
68
+ }
69
+ }
@@ -86,8 +86,14 @@ async function watchPasses(failed, watch) {
86
86
  await watch.passEnd(pass.reports);
87
87
  step = 0;
88
88
  }
89
- if (pass.error !== undefined || pass.stoppedAt !== undefined) {
90
- return { ...pass, reports };
89
+ if (pass.error !== undefined) {
90
+ if (!watching()) {
91
+ return { ...pass, reports };
92
+ }
93
+ watch.unreadable(pass.error);
94
+ }
95
+ if (pass.stoppedAt !== undefined) {
96
+ return { reports, stoppedAt: pass.stoppedAt };
91
97
  }
92
98
  if (watch.stop() || !watching()) {
93
99
  return { reports };
@@ -4,19 +4,17 @@ import { minutesToMs } from '../shared/durations.mjs';
4
4
  import { succeeded } from '../shared/exec.mjs';
5
5
  import { escalateCheckFix, fixRound } from './fix.mjs';
6
6
  import { writeState } from '../shared/state.mjs';
7
+ import { SCRIPTS, scriptRunner } from '../shared/setup.mjs';
7
8
  import { outputBlock } from '../shared/text.mjs';
8
9
  import { setUpBeforeChecks } from './worktree-setup.mjs';
9
10
  /**
10
- * Runs the configured check commands in the worktree before a push.
11
+ * Runs the `format`, `lint`, `typecheck` and `test` scripts in the worktree before a push.
11
12
  * Gives `true` when every command passed, `false` when the fixer committed a fix (merge and check again),
12
13
  * or the finished hand-over.
13
14
  */
14
15
  export async function localChecks(job) {
15
16
  const { context, state, worktree } = job;
16
- const { config, ports, repo } = context;
17
- if (config.checks.length === 0) {
18
- return true;
19
- }
17
+ const { ports, repo } = context;
20
18
  const change = await ports.revision(worktree);
21
19
  const setup = await setUpBeforeChecks(job);
22
20
  if (setup !== undefined) {
@@ -40,7 +38,8 @@ async function runChecks(job) {
40
38
  const { context, log, worktree } = job;
41
39
  const { config, ports } = context;
42
40
  const head = await ports.revision(worktree);
43
- for (const command of config.checks) {
41
+ const runner = await scriptRunner(worktree);
42
+ for (const command of SCRIPTS.map((script) => `${runner} ${script}`)) {
44
43
  const result = await log.step('check', { cmd: command }, () => ports.runCheck(command, worktree, minutesToMs(config.checksTimeoutMinutes), config.logMaxChars));
45
44
  await evenWhenStopped(() => ports.discardChanges(worktree, head));
46
45
  // A stop kills the command, so its failure is no finding: the next run checks again.
@@ -83,6 +83,7 @@ export function watchRun(args, loop, context, controls, print) {
83
83
  return slept;
84
84
  },
85
85
  passEnd: (issues) => print({ ...recorder.summary(passStart), issues }),
86
+ unreadable: (error) => recorder.event('issues.unreadable', { error: message(error) }),
86
87
  hunter: hunt,
87
88
  hunting: controls.hunting ?? onOff(args.hunt),
88
89
  watching: controls.watching,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "17.1.0",
3
+ "version": "17.2.0",
4
4
  "description": "Autonomous issue harness driven by the Claude Agent SDK",
5
5
  "keywords": [
6
6
  "github",
@@ -37,8 +37,8 @@
37
37
  "typecheck": "tsc --noEmit",
38
38
  "lint": "oxlint --deny-warnings",
39
39
  "lint:fix": "oxlint --fix",
40
- "format": "oxfmt",
41
- "format:check": "oxfmt --check",
40
+ "format": "oxfmt --check",
41
+ "format:fix": "oxfmt",
42
42
  "prepack": "npm run build"
43
43
  },
44
44
  "devDependencies": {
@@ -61,7 +61,7 @@ Run any next-issue command as `npx -y next-issue@latest <command>`. Never run it
61
61
  gh run view --repo <repo> <run> --log-failed
62
62
  ```
63
63
 
64
- For `local checks failed: <command>`, the command comes from `checks` in `.next-issue/config.json`. Ask the user before you run it in `.claude/worktrees/next-issue-<number>`.
64
+ For `local checks failed: <command>`, the command runs the failed script of the root `package.json` (`format`, `lint`, `typecheck` or `test`), such as `npm run lint`. Ask the user before you run it in `.claude/worktrees/next-issue-<number>`.
65
65
 
66
66
  7. Explain the blocker to the user in plain words: what the worker tried, what stopped it and what it needs from a person. Quote the reason and the questions of the hand-over where that helps.
67
67
  8. Ask numbered questions, with the answers of the questions of the hand-over among them. Label options with letters and recommend one. Ask again until you know whether to retry, retry with guidance or give up, and, for guidance, its text.