An architecture write-up for swarm-review.
The control plane
In a swarm-review run the models do the reading and the judging. Everything else is decided by code that behaves the same way every time: which stages run and in what order, who is dispatched with which inputs, which file each agent must leave, what happens when a file is missing, and whether the synthesis may run at all. That code is one workflow script and three small command-line scripts. This document describes them, and it ends with a table of which decisions a model makes and which it does not. The review pipeline describes the stages themselves and what each agent is asked to do.
Components
| Component | Where | What it is |
|---|---|---|
| Launcher | skills/swarm-review/SKILL.md |
The entry point Claude Code loads for /swarm-review. It runs prepare.mjs, says what is about to run, starts the workflow and reports the result. Its rules are narrow: it passes the run config to the workflow complete and unmodified, it does not repair a config by guessing, and it never edits the sources or the run directory while the workflow runs. |
| Config resolver | skills/swarm-review/bin/prepare.mjs |
Turns a JSON config, or bare source paths with flags, into the full run config, and lays out the run directory. resolve writes nothing, and materialize creates the directory. |
| Workflow script | skills/swarm-review/workflow.js |
The orchestration, run by Claude Code's Workflow tool. It holds the stage logic and the text of every stage prompt. A workflow script has no file system access, so every file is read and written by an agent it starts. |
| Plan validator | skills/swarm-review/bin/plan.mjs |
Checks the designer's plan.json against run.json and renders RUNBOOK.md from the two. It exits with the full list of problems when the plan does not fit. |
| Clerk | skills/swarm-review/bin/clerk.mjs |
Checks which of a stage's expected files exist on disk and appends one line to STATUS.md. |
One run, from a command to a verdict
The config becomes a run config
A run is described by one JSON file, or by nothing more than the path of a spec. prepare.mjs resolves either
into the run config, the only input the workflow takes.
- Unknown keys are rejected. Every level of the config is checked against its list of allowed keys, so a typo fails before a run starts. Every problem is collected and reported in one message.
- Values are bounded. Each source path must exist. Source ids and role names are kebab-case and unique. The
panel is 2 to 15 reviewers with the challenger extra, the scenario count is 1 to 30, the gate is
strictorlenient, and a pinned role's materials must name sources the config has. A prompt file the config pins must exist, and the challenger's name cannot also be a panel role. - Defaults fill the rest. Eight reviewers and a challenger named
red-team, five confidence tags, the two verdict lists, every stage on, 13 scenarios, the model onautoin Python, the strict gate, and the web allowed. The subject defaults to the first heading of the primary source, and the mandate is built from the subject, the tags and the verdicts. - The run directory is new.
materializerefuses a directory that is not empty. It createsagents/,reviews/,scenarios/andmodels/, copies any pinned prompts intoagents/, writesrun.json, and startsSTATUS.mdwith a RUN STARTED line that states the sources, the panel, the stages and the number of agents the config will start. - A dry run writes nothing.
--dry-runprints the resolved config and creates no directory.
The workflow script takes nothing else. If its arguments are not a resolved run config, it stops before starting any agent.
The plan is validated before anyone is dispatched
The panel designer is the one place where a model shapes the run: it chooses the roles, the challenger's lenses, the scenarios, whether a model is worth building and the outline of the report. Its output passes two checks.
The first is the schema on the designer's structured return. The second is plan.mjs, which the designer must
run against the plan it wrote to disk, correcting the plan until the script passes.
| Part of the plan | What plan.mjs requires |
|---|---|
| Roles | Exactly the number the config asks for. Each has a unique kebab-case name, a title, a description and at least two focus areas. |
| Finding prefixes | 1 to 4 capital letters, unique across the panel and the challenger. |
| Materials | Each role lists at least one source, every source id is one the config has, each is marked primary or reference, and at least one is primary. |
| Pinned roles | Each role the config pins is present under exactly its name, with its materials and its extra task unchanged. |
| Challenger | The name the config gives, with 1 to 5 lenses that each have a name and a stance. A config that pins lenses fixes their number. |
| Scenarios | Exactly the count the config asks for, pinned titles unchanged and in order, and at least two parties for the traces to follow. |
| Model | A yes or no with a reason. A config that forces the model on requires yes, and a yes requires a brief. |
| Report sections | 2 to 8 titled sections, unless the config fixes the outline. |
Once the plan passes, plan.mjs renders RUNBOOK.md from run.json and plan.json: the execution rules, the
sources, the dispatch table with each reviewer's materials, extra task and finding ids, the challenger's lenses,
the scenarios, the model brief and the report outline. The runbook is rendered from the two files by a script. No
model writes it.
The script applies its own checks to what the designer returns. A plan with fewer than two roles, no challenger or no model decision is not usable, and the designer is run once more. A second failure is logged as STAGE 0 FAILED and the run stops, because nothing else can run without a panel. The script also drops a role whose name repeats or collides with the challenger's, and it uses the challenger name from the config whatever the plan says.
Waves, the clerk and the one-retry rule
The designer and the question writer are each run once more if they return nothing. Every other dispatch goes
through one function, wave. It takes a list of tasks, each naming the agent to start and the file that agent
must leave.
- Start every task in parallel.
- Run the clerk on the files the tasks should have left.
- Start again, once, each task whose file is missing. The retry prompt says that the first attempt did not leave a complete file and that the whole task is to be done again.
- Run the clerk on the retried files and log the result as a RETRY line.
- Record anything still missing as an anomaly and return. The run continues to the next stage.
The clerk reports the disk, not the agents. clerk.mjs counts a file as present when it is a regular file of
at least 200 bytes, so an empty or stub file counts as missing. It appends one line to STATUS.md with the time,
the stage and COMPLETE or INCOMPLETE, a one-line detail, the count of outputs on disk and the names of any that
are missing. The detail is built by the script from the agents' structured returns, for example each reviewer's
verdict, or the number of disputes and direct conflicts in cross-examination.
Why an agent runs the clerk. A workflow script cannot touch the file system, so the script starts a clerk
agent at low effort whose whole task is to run one command exactly as written and return the present and
missing arrays it prints. The return is held to a schema, and the script keeps only the paths it asked about.
The log line itself is written by clerk.mjs, so STATUS.md reflects the disk whatever the clerk agent returns.
When the clerk fails. If the clerk agent returns nothing usable, the script records an anomaly and falls back to the stage agents' own returns for that stage: a task whose agent returned nothing is treated as missing and retried.
An agent that cannot run is an anomaly, not a crash. Starting an agent can fail, for example when the session's token budget is exhausted. The script catches the failure, records it and carries on, and the gate decides what the gap means.
| Log event | Files the clerk expects |
|---|---|
| RUN STARTED | None. Written by prepare.mjs. |
| STAGE 0 | plan.json, RUNBOOK.md, QUESTIONS.md when that stage is on, and agents/<role>.md for every reviewer. |
| STAGE 1 WAVE 1 | reviews/<role>.md for every panel reviewer. |
| STAGE 1 | reviews/<challenger>.md. |
| STAGE 2 | reviews/crossexam-<role>.md for every reviewer with a Stage 1 report. |
| STAGE 3 | scenarios/SCENARIOS.md. |
| STAGE 4 | models/RESULTS.md and models/ASSUMPTIONS.md. |
| STAGE 5 | ANALYSIS.md, or no files and the word BLOCKED when the gate stops the run. |
What a later stage does about an earlier gap
A missing file does not stop the run. Each later stage is dispatched with the inputs that exist.
- The challenger is given only the panel reports that reached disk. With none, it is not run.
- Cross-examination includes only reviewers that have a Stage 1 report, and each reads only the reports that exist. With fewer than two reports the stage is skipped.
- Scenarios and the model start together after cross-examination. Each is skipped when no report is on disk.
The model runs when the config forces it on, or when the config says
autoand the designer judged the sources' quantitative claims worth modelling. - The synthesis prompt names only the inputs that exist. When no model results exist it is told so, with the reason, and it must say so in the quantitative section.
Every skip is recorded as an anomaly, and the run returns the anomalies beside the list of gaps.
The gate before synthesis
Before Stage 5 the script lists the gaps: a Stage 1 report missing for any reviewer, a cross-examination missing for any reviewer that has a report, and the scenario traces, each counted only when its stage is on. The model is not part of the gate.
| Gate | With no gaps | With gaps |
|---|---|---|
strict, the default |
The synthesis runs. | The synthesis does not run. The clerk logs STAGE 5 BLOCKED with the list of what is missing, and the run returns the status blocked. |
lenient |
The synthesis runs. | The synthesis runs, and it is told to put PARTIAL in the title of ANALYSIS.md and to list the missing inputs directly under it. The run returns partial. |
With no Stage 1 report at all the run is blocked under either gate. A run whose synthesis starts and still leaves
no ANALYSIS.md after the retry returns failed. Otherwise it returns complete.
What comes back, and resuming
The workflow returns a small object and the launcher reports from it: the status, the executive verdict and its
headline, the counts of dealbreakers, fix items and open conflicts, each reviewer's Stage 1 and Stage 2 verdict,
how many reports and cross-examinations reached disk, the gaps and the anomalies. If the status is blocked,
partial or failed, the launcher leads with that. It does not restate the analysis, because the files are the
deliverable.
A run that was interrupted, or that stopped at the gate, can be resumed in the same session. prepare.mjs --resume prints the saved run.json unchanged, and the launcher starts the same script with that config and the
earlier workflow run's id. Agents that completed return from the Workflow tool's cache, and only the missing work
runs.
What a model decides and what it does not
| Decision | Made by |
|---|---|
| Which stages run, and in what order | The config and the script |
| The panel size, the challenger's name, the tags and the verdicts, the gate | The config |
Which roles sit on the panel, the challenger's lenses, the scenarios, whether to build a model on auto |
The designer agent, inside the shape plan.mjs enforces |
| What each reviewer is asked | A prompt writer agent, in a fixed outline, instructed to carry the mandate word for word |
| Who reads which files at each stage | The script, from the plan and from what is on disk |
| Whether a stage's output exists | clerk.mjs, from the file system |
| Whether to retry, and how many times | The script: once |
| Whether the synthesis runs | The script: the gate |
| The findings, the disputes, the ranking and the verdict | The agents |
Tests
tests/workflow.test.mjs runs workflow.js outside the Workflow tool, with a fake agent that writes to an
in-memory disk, so no model is called. Its cases are a full nine-reviewer run in runbook order, the inputs each
dispatch prompt carries, a missing report retried once, the strict gate blocking synthesis after a second miss
while the other reviewers still cross-examine, the lenient gate marking the analysis PARTIAL, disabled stages,
the model following the designer on auto, pinned prompts used as supplied, a dead clerk, a wrong argument
object, and a designer that fails twice. tests/bin.test.mjs covers the three scripts: resolution and its
overrides, rejection of bad configs with every problem listed, the run directory layout and the refusal to reuse
one, the clerk's line, plan validation, and the rendered runbook.
The outline of the final report exists twice, in plan.mjs for the runbook and in workflow.js for the
synthesis prompt, because a workflow script cannot import a module. A test holds the two together.
What is not there
- The clerk checks existence and size, not content. A report can be on disk and still be poor.
- Instructions are not enforcement. That a reviewer works alone, leaves the sources untouched and keeps the mandate word for word are instructions in a prompt. Nothing verifies them mechanically.
- The returned plan is trusted to match the file. The script dispatches from the plan the designer returns,
and the designer is told to return it identical to
plan.json. Nothing compares the two. - Resume is tied to the session. The cache that makes it cheap belongs to the Claude Code session, so a new session needs a fresh run.
- There is no budget. A cost ledger, a per-run budget and a record of every model request and tool call are designed and not built. The cost controls are the panel size, the stage switches, the effort setting and whatever token budget the session enforces.
- There is no replay or scoring. Replaying a run from its record, comparing two runs, and scoring a run against a set of known findings are designed and not built.
Where to read next
- The review pipeline: the stages, what each agent is told, the vocabulary and what a run costs.
docs/CONFIG.mdin the swarm-review repository: every config key and its default.
