✨ feat(review-thread): review-thread --batch answers many threads from one run (#590)
niyam review-thread --batch <file> now answers many review threads in one run. The token is checked once, and the threads are answered in the file's order. One thread per run works as before.
Why. Until now each run took one thread (src/review-thread.ts:27-31 on main), and each run started a process and checked the token's login (/user). So 20 threads cost 20 process starts and 20 login checks. Source: athya-rules docs/lessons/review-and-merge.md#sync-many-threads-from-one-process, read 2026-11-24 at 1d3ffa1. Spec v1's D3 on https://github.com/veda-hq/niyam/issues/394 says to build it, and Alok approved the spec and the slice there ("Decision: approve spec v1 #583 … #590").
What it does
- The file is a JSON list of
{ "thread", "reply" | "bodyFile", "resolve", "reaction", "comment" }, the options one run takes.- Each entry becomes the arguments for one run and goes through
threadArgs, so the batch adds no rules of its own. - A
bodyFilereply resolves the thread unless"resolve": false. An inlinereplyresolves it only with"resolve": true. - These are refused, naming the entry: an unknown key, a value of the wrong type, an empty list, and text that is not JSON.
- Each entry becomes the arguments for one run and goes through
- The order of checks.
- Before any request, every entry's ids and reply file are checked. A malformed file posts nothing.
- Then the token is checked once (
/user). - Then each thread is answered in order.
- Stops at the first refusal. It prints
review-thread: stopped at <thread> (i of n); done: …; not done: ….- A refusal from GitHub still ends the run with GitHub's error, as it does for one thread.
- Rerunning the same file is safe: a reply already on a thread is not posted again, and a resolved thread is left alone.
- The list must be inside the repository, as
--body-filemust, since the allow rule runs the command without a prompt. Both are read only afterSys.confinefollows their links and finds them inside the git toplevel, so a link in the repository cannot post a file from outside it. This is a fix from Cubic's review, and it holds--body-filetoo. - Unchanged: one thread per run, on a machine and in a Claude cloud session.
The README, docs/decisions.md and the usage text describe it. The README also says a thread goes in the list only once its fix is on the remote. lint/eslint-suppressions.json drops one no-raw-error-string from src/review-thread.ts because that occurrence is gone; no suppression was added.
Evidence: pnpm check exits 0 on head 541913f, which merges in main at bc0f9b4. It runs provenance, typecheck, lint, test, test:scripts, pins, pariksha, hooks:check, build and smoke.
pnpm test: tests 2238, pass 2238, fail 0
review-thread.ts 100.00 lines / 97.69 branches / 100.00 functions
pnpm test:scripts: tests 138, pass 138, fail 0
New tests in src/review-thread.test.ts:
- A batch on a machine: a reply from a file, an inline reply, and a reaction with resolve, all in file order with one
/usercheck. - A batch in a Claude cloud session, over the proxy's REST routes, with one
/usercheck. - A batch stopped by a refusal:
- GitHub's 403 on the second thread: the first thread is done, the second and third are not, and no request names the third.
- A pull request the agent did not open: refused before anything is posted.
- A rerun after a stop: a batch stopped by GitHub's 502 is run again against a fake that keeps what was posted. The rerun posts only the missing resolve.
- A link out of the repository: a reply file whose link leads outside is refused before any request, in a batch and for one thread.
- A malformed file:
- text that is not JSON, an empty list, an unknown key, a wrong type, a missing thread, and each
threadArgsrefusal, with the entry's number; - a cloud id on this machine, and a reply file that is missing, empty or outside the repository;
- a batch file that is missing or outside the repository.
- Each is refused before any request.
- text that is not JSON, an empty list, an unknown key, a wrong type, a missing thread, and each
reviewArgs:--batchwith no path, or with more arguments, is refused, andsrc/run.test.tsexits 2 with the usage text.
Guards: none.
Slice: #590
🤖 Generated with Claude Code