zstack
A stack for coding agents that works the same under any harness. One thread owns a task and writes all its code. Three delegates help it and never edit source: an explorer reads, two competing **designer**s plan deep or new work, and a verifier owns verification. The role-to-model map is the machine file's [models].
Derived from pstack by Lauren Tan. PROVENANCE.md records what changed and why.
how it fits together
- The stack is what every coding thread loads:
skills/, agents/, the invariants, and the guard that enforces them. It names no repo. It reads the config only through queue.py.
- The invariants are the few things that always hold: nothing merges unverified, nothing held is started or merged, a turn does not end with unverified work, one item has one thread, a thread is started once, a thread cannot change its own controls, and nothing is published that breaks the repo's own invariants. The stack's are
config/invariants.toml; each repo adds its own beside its policy.toml. Every one names where it is enforced and what proves it: the five about the queue's state are properties of model/Queue.tla, each with a mutant that breaks it, and the rest are tests. What nothing can check is judgment, and goes in each item's brief, not in every session.
- The queue is one program per machine,
queue.py. It keeps almost nothing: which threads are running, which finished threads wait on an open PR, the tasks the orchestrator added by hand, the verifier's verdict per PR, and the ids already handled. Everything else it reads from the repo when it matters: what is assigned to us, what is held, whether a PR is open, a draft or green. Each machine takes the labels its config names, and queue.py check refuses two machines whose labels overlap. The highest priority goes first. Its steps are model-checked in model/Queue.tla.
- The pass is
queue.py pass, run on a schedule on each machine. It clears what has finished, frees the slot of a thread that died, and starts a thread for each ready item up to the cap. No model takes part: it starts and reads threads through the T3 Code command run.t3 names. It records an item as running before it starts the thread, so a start whose answer was lost is never started twice: a later pass finds that thread by its title, and launches the item again only when T3 Code has listed none for run.lost_min minutes. It launches nothing while the filesystem of the clone, or of a worktree it holds, has less free space than run.disk_floor_gb, and still settles and merges what it holds.
- Merging is the thread's, through a gate. The verifier passes a head as
auto or review and records that with queue.py verified. The thread then runs gh pr merge <pr> --squash --match-head-commit <head>, and the guard asks queue.py gate before it lets that run. A review head waits for the owner, and a new push shuts the gate until the verifier passes the new head. A waiting PR whose head passed as auto, or a preapproved item's waiting PR on either pass, is merged by the pass, through the same gates and a fresh read of every check. When the PR's base branch has a merge queue, the pass puts that head in the queue instead (GraphQL enqueuePullRequest with the head as expectedHeadOid) and keeps the item waiting until GitHub reports it merged. A hold or review label on the PR or its issue that a later pass sees takes it out of the queue again. If GitHub drops a preapproved head, the pass queues it again once, since a flake earns one fresh run. A second drop of that head, or a drop of a head that is not preapproved, is reported blocked with GitHub's reason, and that head is not queued again.