How Yokai runs a phase
Yokai runs every phase in three acts: Plan, Build and Seal. Then it checks four facts on disk before it moves on. This page follows one phase from the board to the commit.
The parts of a run
Yokai's supervisor is a loop. It picks the next phase, runs it, checks the result and decides whether to continue, halt or finish. It knows nothing about what the code should look like. That knowledge lives in the agent and in the files under .koi/run/.
Take one phase from the Daylist walkthrough: P2, "Persist tasks in localStorage". When you run yokai --once, the supervisor reads .koi/run/BOARD.json, finds P2 as the first todo card, reads its reviewed model tier, and picks an agent and model for each turn from your settings.
The supervisor never edits product code. It sends a prompt to the agent, one turn at a time, through Tori. Tori speaks the Agent Client Protocol (ACP). For Claude Code and Codex it starts a Node adapter: claude-agent-acp or codex-acp if that command is on PATH, else npx -y @agentclientprotocol/claude-agent-acp or npx -y @agentclientprotocol/codex-acp. Cursor and OpenCode serve ACP themselves through cursor-agent acp and opencode acp. Messages travel over the adapter process's standard input and output.
One turn over ACP
A turn is one prompt and the agent's work until it stops. Each turn follows the same exchange:
initialize: Tori and the agent agree on a protocol version and capabilities.session/new: Tori opens a session in the repository directory. An interrupted turn can reattach withsession/resumeorsession/load.session/prompt: Tori sends the turn prompt. While the agent works,session/updatemessages stream its text, thoughts, tool calls and file edits back to the cockpit.
When the agent asks permission to use a tool, Tori answers session/request_permission from the run's permission mode. The default is approve-all, because the safety net is the gate and Git, not prompts. Cost and token counts come from the agent; if it does not report usage, the cockpit shows a dash.
By default every turn gets a fresh session, so the agent starts from what is on disk. Token savings reuses two sessions per phase instead.
Plan, Build, Seal
A phase is divided into three acts. The supervisor writes the card's status before each act, so a relaunch knows where to resume.
- Plan (
planning). One agent turn writes.koi/run/phases/phase-02-<slug>.md: goal, an "Explicitly out" list, and a numbered approach. Then the agent stops without touching code. If a phase file for P2 already exists, Yokai skips this act. - Build (
building). A loop of coder turns, sensor runs and judge turns until the change converges or the iteration budget runs out. The Build loop explains it. - Seal (
sealing). One agent turn records the verified outcome on the card, marks itdone, updatesNOTES.mdand the phase file's Outcome, setsnextAction, and makes one conventional commit with everything the phase produced.
The contract
The agent's message at the end of Seal does not count. After Seal the supervisor checks four facts, in this order:
- The card advanced: P2's status is
done. - A new commit exists:
HEADmoved since the phase started. - The gate is green: every script in
.koi/sensors/exits 0. If Seal left the product files exactly as Build verified them, Yokai reuses the green Build result instead of running the sensors again. - The tree is clean: nothing the phase touched is left uncommitted. Files that the gate run itself rewrote do not count.
If all four hold, the phase is done and the supervisor moves on. If the card did not advance, the supervisor retries the phase once in a fresh run; a second miss in a row is a stall. Any other miss goes to recovery, or halts the run when recovery is off.
Seal's done is provisional. If the gate is red after Seal, the supervisor reopens the card as todo and restores nextAction to /junji next, so a relaunch runs the phase again instead of skipping it. Seal's commit stays in history. Verification on disk covers the gate in detail.
Example: what P2 leaves behind
After a clean run of P2:
git log -1shows a commit likefeat(storage): persist tasks and recover from invalid data.- P2's card has
"status": "done"and a one-line outcome.nextActionis still/junji nextbecause P3 istodo. .koi/run/phases/phase-02-persistence.mdhas an Outcome section..koi/run/ledger.jsonlhas a new row. It looks like this, with the hashes shortened and some fields left out:
{"phase":"P2","agent":"claude","model":"sonnet","tokens":131526,"cost_usd":0.41,"gate_passed":true,"advanced":true,"commit_made":true,"head_before":"07fe780…","head_after":"7e534a0…"}
.koi/run/FEEDBACK.mdis gone. Yokai deletes it before Seal when Build converges, so it is never committed.
If the run stops
Open the same checkout and run yokai. The supervisor reads the card's status. If P2 was building, it resumes Build; if sealing, it resumes Seal. An interrupted turn can reattach to its agent session through .koi/run/live-session.json.
What can go wrong
phase P2 marked done but produced no commit. The agent marked the card but did not commit. With recovery on, Repair commits the work if the gate is green.gate red after phase P2 (sensor 30-test, ...). Seal changed product code or a test is flaky. The card is back totodo; fix the cause and relaunch.phase P2 left uncommitted changes. A build output or dependency folder ended up in the tree. Repair adds it to.gitignorewhen it is plainly regenerable.phase P2 made no progress in 2 runs. The phase is a stall. Recovery's Diagnose turn reads the failure; if it cannot fix it, use/junji refineto split the phase.