next-issue 10.5.1 → 10.6.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
@@ -356,6 +356,8 @@ In a run of the `serve` worker, a client can switch hunting and watching on or o
356
356
  - sends each `error` as `{ "type": "error", "root": "<path>", "message": "<text>" }`. When a `start`, `stop`, `watch`, `hunt` or `refresh` message carries an `"id"`, the `error` that refuses it carries the same `id`;
357
357
  - runs at most one run at a time. A client starts it with `{ "type": "start", "root": "<path>", "args": [...] }`. Each run is like `next-issue start` with those args, or with none when `args` is left out (the pi extension sends none). It takes `--max <n>`, `--watch`, `--hunt`, `--reset`, `--verbose` and `--quiet`, and refuses a command (`start` too), `--json`, `--force`, `--help` or an unknown argument with an `error` message;
358
358
  - sends every client the progress of every run when it connects and on every change: for each running issue the issue, the step, the tool count and the last tool, and the handled issues (an issue handled in more than one pass appears once for each);
359
+ - sends every client `{ "type": "output", "root": "<path>", "text": "<lines>" }` for each line of a run that `next-issue start` prints on standard error, as the run prints it and at the level of the run (`--verbose`, `--quiet` or the default). The same lines still go to `.next-issue/worker.log`;
360
+ - sends every client one `{ "type": "end", "root": "<path>", "code": <n>, "summary": {...} }` message when a run ends. `code` is the exit code that `next-issue start` would return for the run, and `summary` is the summary of the whole run that `next-issue start --json` prints (in a watch run, all passes). A run that fails has `code` 1, no `summary`, and the text that `next-issue start` prints after `next-issue failed: ` in `error`;
359
361
  - sends every client a `questions` message for each repository: the open issues with the `needsHuman` label, each with its number, title, the reason of the hand-over, the url of the comment that holds it, the `owner/name` repository, and the `needsHuman`, `skip` and `ready` labels. It reads them from GitHub, so the list is the same after a restart. It sends them when a client connects, for its repository, after each issue of a run ends, and when a client sends `{ "type": "questions", "root": "<path>" }`. An issue that no longer has the label leaves the list, and so does an issue whose hand-over has an answer from a writer, the same answer that lets a run claim it. An issue that a person holds with the label stays in the list, even when an earlier hand-over has an answer. An issue with the label but no hand-over comment is in the list with an empty reason and url. The issues are read one at a time. A client never gets an older list after a newer one. When the client adds an `"id"` to its message, the list that answers it carries the same `id` and is read after the message arrived. When the list cannot be read, the client gets `{ "type": "questions-error", "root": "<path>", "message": "<text>" }`;
360
362
  - answers `{ "type": "upcoming", "root": "<path>" }` with `{ "type": "upcoming", "root": "<path>", "claimable": [...], "blocked": [...] }`: the open issues with the `ready` label that a run would claim, oldest first, each with its `issue` number and `title`, without issues that have saved state or a label that stops a claim. An issue blocked by open issues is in `blocked` with their references in `blockers`. When the list cannot be read, the client gets `{ "type": "upcoming-error", "root": "<path>", "message": "<text>" }`;
361
363
  - stops a run when a client sends `{ "type": "stop", "root": "<path>", "after": "issue" | "round" | "now" }`. With no `after`, it stops after `issue`. `issue` works like a first `Ctrl-C`: no new claim or hunt, and the held issues and a going hunt finish. `round` works like a second `Ctrl-C`: each running issue stops after its current round, with the state kept, and a going hunt ends first. `now` stops every agent, command and hunt of the run at once, and each running issue ends as `stopped` with its state and labels kept; the worker keeps running. A later point than one already asked for changes nothing, and an earlier one replaces it. An unknown `after` gets an `error` message;
package/dist/agents.mjs CHANGED
@@ -137,7 +137,7 @@ function observe(log, event, cwd) {
137
137
  else if (event.type === 'message_update' &&
138
138
  event.assistantMessageEvent.type === 'text_delta' &&
139
139
  log.level === 'verbose') {
140
- process.stderr.write(event.assistantMessageEvent.delta);
140
+ log.print(event.assistantMessageEvent.delta);
141
141
  }
142
142
  }
143
143
  const PATH_TOOLS = new Set(['read', 'write', 'edit', 'grep', 'find', 'ls']);
package/dist/observe.mjs CHANGED
@@ -14,10 +14,12 @@ class Sink {
14
14
  level;
15
15
  file;
16
16
  listener;
17
+ output;
17
18
  /** Set once the run log fails: the run goes on, and its events reach only the listener. */
18
19
  failed = false;
19
- constructor(stream, level, file, listener) {
20
+ constructor(stream, level, file, listener, output) {
20
21
  this.stream = stream;
22
+ this.output = output;
21
23
  this.level = level;
22
24
  this.file = file;
23
25
  this.listener = listener;
@@ -29,7 +31,7 @@ class Sink {
29
31
  return;
30
32
  }
31
33
  this.failed = true;
32
- process.stderr.write(`next-issue: the run log ${this.file} cannot be written (${message(error)}); the run goes on without it\n`);
34
+ this.output(`next-issue: the run log ${this.file} cannot be written (${message(error)}); the run goes on without it\n`);
33
35
  }
34
36
  write(record) {
35
37
  if (!this.failed) {
@@ -68,12 +70,12 @@ export class Recorder {
68
70
  this.base = base;
69
71
  this.runId = runId;
70
72
  }
71
- static async create(root, level, listener, open = (file) => createWriteStream(file, { flags: 'a' })) {
73
+ static async create(root, level, listener, open = (file) => createWriteStream(file, { flags: 'a' }), output = (text) => process.stderr.write(text)) {
72
74
  const runId = new Date().toISOString().replace(/[:.]/g, '-');
73
75
  const dir = runsDir(root);
74
76
  await mkdir(dir, { recursive: true });
75
77
  const file = join(dir, `${runId}.jsonl`);
76
- const sink = new Sink(open(file), level, file, listener);
78
+ const sink = new Sink(open(file), level, file, listener, output);
77
79
  return new Recorder(sink, {}, runId);
78
80
  }
79
81
  get logFile() {
@@ -105,9 +107,12 @@ export class Recorder {
105
107
  };
106
108
  this.sink.write(record);
107
109
  if (VISIBILITY[this.sink.level] >= VISIBILITY[visibility]) {
108
- process.stderr.write(render(record));
110
+ this.sink.output(render(record));
109
111
  }
110
112
  }
113
+ print(text) {
114
+ this.sink.output(text);
115
+ }
111
116
  usage(role, usage, ms, fields = {}) {
112
117
  this.sink.add(role, usage, ms);
113
118
  this.event('usage', { role, ms, ...usage, ...fields });
package/dist/run.mjs CHANGED
@@ -47,7 +47,7 @@ export async function runRepo(root, args, controls) {
47
47
  async function runWithConfig(root, args, controls, config) {
48
48
  await checkGitVersion();
49
49
  const repo = await detectRepo(root, config.remote);
50
- const recorder = await Recorder.create(repo.root, args.level, controls.onEvent);
50
+ const recorder = await Recorder.create(repo.root, args.level, controls.onEvent, undefined, controls.output);
51
51
  try {
52
52
  const pruned = await pruneRuns(repo.root, config.keepRunDays);
53
53
  if (pruned > 0) {
@@ -77,6 +77,7 @@ async function handle(args, config, repo, recorder, controls) {
77
77
  if (crash !== undefined) {
78
78
  throw crash.failure;
79
79
  }
80
+ controls.ended?.(summary);
80
81
  if (!args.watch) {
81
82
  await print(summary);
82
83
  }
package/dist/serve.mjs CHANGED
@@ -16,7 +16,7 @@ import { packageVersion } from './version.mjs';
16
16
  import { keepLogTrimmed, LOG_CHECK_MS } from './worker-log.mjs';
17
17
  import { checkSocketPath, workerPaths } from './worker-paths.mjs';
18
18
  import { active, dropUpgrade, endStatus, newRun, requestRefresh, requestStop, requestUpgrade, runControls, runsMessage, setHunting, setWatching, startRefusal, stopPoint, switchRefusal, } from './worker-run.mjs';
19
- import { broadcast, closer, fileId, listen, parseMessage, removeOwned, shutdown, } from './worker-server.mjs';
19
+ import { broadcast, closer, fileId, listen, parseMessage, removeOwned, sendAll, shutdown, } from './worker-server.mjs';
20
20
  const LOCK_WAIT_MS = 5_000;
21
21
  const IDLE_MS = 30_000;
22
22
  export async function startWorker(options) {
@@ -79,8 +79,29 @@ export async function startWorker(options) {
79
79
  broadcast(sockets, runs);
80
80
  };
81
81
  broadcast(sockets, runs);
82
- withRunChildren(run.children, () => options.runRepo(root, args, runControls(run, update, () => outsideRuns(() => void sendQuestions(root, () => sockets.clients)))))
83
- .then(() => update({ ...run.progress, status: endStatus(run) }), (error) => update({ ...run.progress, status: 'failed', error: message(error) }))
82
+ let summary;
83
+ withRunChildren(run.children, () => options.runRepo(root, args, {
84
+ ...runControls(run, update, () => outsideRuns(() => void sendQuestions(root, () => sockets.clients))),
85
+ output: (text) => {
86
+ process.stderr.write(text);
87
+ sendAll(sockets, { type: 'output', root, text });
88
+ },
89
+ ended: (ended) => {
90
+ summary = ended;
91
+ },
92
+ }))
93
+ .then((code) => {
94
+ update({ ...run.progress, status: endStatus(run) });
95
+ sendAll(sockets, {
96
+ type: 'end',
97
+ root,
98
+ code,
99
+ ...(summary === undefined ? {} : { summary }),
100
+ });
101
+ }, (error) => {
102
+ update({ ...run.progress, status: 'failed', error: message(error) });
103
+ sendAll(sockets, { type: 'end', root, code: 1, error: message(error) });
104
+ })
84
105
  .finally(closeWhenIdle);
85
106
  };
86
107
  const stop = (refuse, root, after) => {
@@ -36,7 +36,9 @@ export function parseMessage(text) {
36
36
  return isClientMessage(value) ? value : undefined;
37
37
  }
38
38
  export function broadcast(sockets, runs) {
39
- const value = runsMessage(runs);
39
+ sendAll(sockets, runsMessage(runs));
40
+ }
41
+ export function sendAll(sockets, value) {
40
42
  for (const socket of sockets.clients) {
41
43
  send(socket, value);
42
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "10.5.1",
3
+ "version": "10.6.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",