koi
Documentation / architecture

The Build loop

Build is where the code gets written. Each iteration is one coder turn, then the sensors, then one judge turn if the sensors are green. It repeats until nothing blocks or the budget runs out.

What Build is

Build is the second act of every phase. Its input is the phase plan (the spec) that Plan wrote. Its output is a verdict: converged or not-converged. Build never commits, never marks the card and never says "done". Seal and the contract check do that.

Every Build runs one coder and one judge. There is no fan-out to several workers and no strategy to choose.

One iteration

  1. Coder turn. The agent reads the phase plan, any guides, and .koi/run/FEEDBACK.md, then edits the working tree. It must not commit and must not edit FEEDBACK.md.
  2. Sensors. Yokai runs every script in .koi/sensors/ in filename order, from the repository root. The first non-zero exit stops the run and names the sensor.
  3. Judge turn, only if every sensor passed. A read-only agent turn reads git diff against the phase plan and returns findings as JSON. Each finding is blocking or nit.

If a sensor failed or the judge reported a blocking finding, Yokai appends the details to FEEDBACK.md and starts the next iteration. If the sensors are green and nothing blocks, Build returns converged.

Sensors decide, the judge can only veto
One Build iteration and its two exits The coder turn edits the tree, then the sensors run. If any sensor is red, the failure goes to FEEDBACK.md. If all sensors are green, the judge turn reviews the diff. A blocking finding also goes to FEEDBACK.md. With no blocking finding, Build has converged. FEEDBACK.md feeds the next coder turn. Coder turn Sensors all green Judge turn any red blocking finding no blocking FEEDBACK.md Converged next iteration

Who can say yes

Only the sensors can let Build converge. The judge can block, but it can never pass a change past a red sensor, and it does not even run while a sensor is red.

Signal Can let Build converge Can block it
A sensor script Yes, together with the others Yes
A blocking judge finding Never Yes
A judge nit Never No, it is recorded only

If Yokai cannot parse the judge's output, it shows the output but does not treat it as a veto.

The judge reads the judge row of CONTEXT.md › Skills and uses the listed SKILL.md files as its review rubric. The coder reads the coder row the same way. Do not confuse the judge with /junji review: the judge looks at one iteration's diff against one phase plan and writes to FEEDBACK.md; review reads a whole pull request and adds fix phases to the board.

Feedback and guides

Two things steer the coder.

  • Guides come before it acts. They are file paths or short instructions listed under build.guides in .koi/yokai.yml, such as docs/style.md. They do not change during a run.
  • FEEDBACK.md comes after a failure. It is append-only, Yokai is its only writer, and it holds the sensor output and judge findings from earlier iterations. The coder prompt tells the agent to read it first and address every unresolved item.

A guide is different from a skill. A skill is a SKILL.md in your repository that CONTEXT.md › Skills assigns to a role.

Budget

build.max_iters in .koi/yokai.yml caps the iterations per Build. Leave it out for no limit. 0 means run no iterations. yokai --max-iters 3 overrides it for one launch.

When the budget runs out without convergence, Build returns not-converged and leaves FEEDBACK.md in place. With recovery on (the default), Diagnose reads it and decides what to do next. With recovery: false, the run halts before Seal.

# .koi/yokai.yml
build:
  max_iters: 5
  judge: true
  guides: [docs/style.md]
roles:
  judge:
    tier: high   # review with a stronger model than the phase tier

build.judge: false skips the judge turn. Token savings mode turns review back on whatever this setting says.

Example: two iterations of P2

  1. Iteration 1. The coder adds saveTasks and loadTasks. The sensor 30-test.sh fails: the test for malformed stored JSON throws. Yokai appends the failing test output to FEEDBACK.md.
  2. Iteration 2. The coder reads the feedback, wraps the parse in a try/catch and falls back to an empty list. All four sensors pass. The judge returns [{"severity":"nit","file":"src/storage.ts","line":12,"message":"name the storage key as a constant"}]. A nit does not block, so Build converges.

Yokai deletes FEEDBACK.md, then starts Seal.

What can go wrong

  • The judge never runs. That is expected while any sensor is red. Fix the failure the sensors report first.
  • Iterations repeat the same failure. Read FEEDBACK.md. The plan may be missing a fact, such as a fixture the test needs. Recovery's Diagnose turn can add a steer to the next Build.
  • The judge keeps blocking on taste. Put the rule in a skill or a guide so the coder follows it from the first iteration, or adjust the phase plan.
  • Build halts with FEEDBACK.md present and recovery off. Read the file, fix the plan or the code, and relaunch.