All writing

Writing

TDD by Construction: How the Vimbus Loop Validates Its Own Code at Scale

By Aggelos Konstantilieris·May 22, 2026·7 min read·Updated October 28, 2026

I run an autonomous loop that writes production code one task at a time, with a fresh agent per task. At that pace a green test suite is not enough. pnpm check can pass while nobody opened the frontend and the backend drifted off its architecture.

So the loop has checks at three levels: the task before an agent runs, the code before a checkbox flips, and the whole codebase before anything ships.

A task is a typed contract

Every unit of work lives in loop-state/tasks.md as a checkbox item with typed fields. The driver parses the file, picks the first unchecked item and builds a five-phase prompt from its fields. Here is a real backend task, lightly trimmed:

- [ ] A1 — Verify the demand-events schema, dedup recipe, and dayBucket
  - Id: class-demand-tracking-a-1-schema-and-dedup-verify
  - TaskType: backend
  - Complexity: high
  - Epic: A
  - Design: design/02-event-model.md
  - State: state/locked-decisions.md
  - Skill: database-design-mongodb
  - Files:
    - apps/api/src/demand/infrastructure/persistence/mongoose/demand-event.schema.ts
    - apps/api/src/demand/application/demand-dedup.ts
    - apps/api/src/demand/application/demand-dedup.spec.ts
  - TestCmd: pnpm test -- --testPathPattern=demand-dedup
  - Acceptance: pnpm test -- --testPathPattern=demand exits 0 with at least one
    test per branch of the dedup recipe (customerId-present, customerPhone-only,
    both-null skip, same-day collapse, next-day produces second row).

Skill: names the one capability the agent loads before coding. TestCmd: makes the task test-driven, because it is a real command that must exit zero.

A planner pipeline writes these files. Research, Interview, Design Writer and Task Writer steps produce the tasks. A Review Agent audits the whole graph, for up to three rounds, before it returns PASS.

The verification-hook rule (E3)

The conventions doc has a rule called E3. Any task with TaskType set to backend, frontend or fullstack must declare at least one verification hook. Six are accepted:

  • TestCmd: A shell command, usually pnpm test -- --testPathPattern=<file>.
  • Route: A URL to exercise through the Playwright MCP.
  • Playwright: A description of a browser interaction.
  • VisualCheck: A screenshot or visual-diff anchor.
  • A11y: An accessibility check.
  • Evidence: Proof outside the browser, such as a log excerpt, a request body or a DB row.

Acceptance: alone does not count. It says what should be true, while a hook says how a machine confirms it.

Static validation before any agent runs

tools/loop/lib/Validate-Module.ps1 makes no model call. It reads the task file, so a malformed task never costs an agent run. The E3 check is blunt:

# E3:missing-verification — implementation TaskType without any
# verification hook.
if ($f.TaskType -and ($f.TaskType.ToLower() -in @('backend', 'frontend', 'fullstack'))) {
    $hasHook = [bool]$f.TestCmd -or ($f.Route.Count -gt 0) -or `
               $f.Playwright -or $f.VisualCheck -or $f.A11y -or $f.Evidence
    if (-not $hasHook) {
        $errors.Add((_NewFinding -Rule 'E3:missing-verification' `
            -Message ("TaskType `{0}` must declare at least one of " +
                      "TestCmd/Route/Playwright/VisualCheck/A11y/Evidence" -f $f.TaskType)))
    }
}

An E3 error stops the loop before it starts. The same file rejects vague criteria such as looks good, duplicate ids and remote git operations.

Where a green suite misleads

Across a 131-task module, two problems appear that unit tests do not catch.

The first is a frontend nobody opened. A frontend task can pass a Jest test that mounts its component alone, while no browser ever loaded the route. You can end up with a green module and a blank screen.

The second is a backend that drifts. Each task runs in a fresh context, so an agent that cannot see the existing ports may inject a Mongoose model into a use case. The test passes, but the boundary is broken.

Two agents on the frontend

When a task declares browser acceptance through Route:, Playwright:, VisualCheck: or A11y:, the loop splits it into two runs with different tools.

The implementation run has no browser tools. It writes the code, runs the unit checks and must leave the checkbox alone:

3. Browser verification is deferred to a second Claude invocation with strict Playwright-only MCP.
   - Do not call browser MCP tools in this implementation pass.
   - Complete the implementation and non-browser checks only.
   - Do not flip the checkbox in this pass; the browser verification pass will flip it if the UI checks pass.

A second agent, with only the Playwright MCP, opens the real Route:, performs the interaction, runs axe and reads the console. Only this agent may change - [ ] to - [x]. The agent that writes the code never decides that it works.

If it cannot make the UI pass, it writes BLOCKED.md with a reason such as not-mounted or auth-gate and halts the loop. The input check requires a matching hook per task type:

TaskTypeVerification the loop requires
backendTestCmd: — a Jest run, usually against mongodb-memory-server
frontendRoute: + Playwright: + Evidence: — driven through the Playwright MCP
fullstackboth of the above
migrationTestCmd: or Evidence: with expected pre/post row counts

Keeping the backend on its architecture

Before any code is written, the Review Agent reads the whole task graph and fails it on any blocking architectural issue:

  • Every port in domain/ has a matching adapter task in infrastructure/.
  • No application/ task imports from infrastructure/ directly. It goes through a port.
  • Tasks are ordered domain, application, infrastructure, interface/http.
  • Injection tokens are Symbol()s in SCREAMING_SNAKE_CASE, defined before use.
  • businessId is never read from a request body, query param or URL. This is the same header-only rule the API enforces at runtime.

While the loop runs, Build-Prompt.ps1 restates the rules in every backend and fullstack prompt:

Hexagonal rules (non-negotiable):
- `domain/`          — pure TS (ports, value objects, enums; no NestJS imports)
- `application/`     — `@Injectable()` services depending on ports via `@Inject(TOKEN)`
- `infrastructure/`  — adapters (Mongo, Redis, Meta, etc.)
- `interface/http/`  — controllers + DTOs
Never remove or bypass a port.

A PROGRESS.md and a history.md beside tasks.md record every PASS, FAIL and SKIP, so a long run survives a crash without redoing work.

The verification chain

After the task's own hooks, every task runs pnpm check:

"check": "pnpm lint && pnpm typecheck && pnpm test"

Any lint failure, type error, red test or failed browser run leaves the checkbox unset.

Auditing the whole codebase

Above the per-task checks, a product-owner agent sends a backend and a frontend auditor out in parallel. Their rule for marking something done:

A checkbox is [x] only if the audit traced HTTP entry → controller → service → DB schema → response, AND a test exists exercising the full path.

Code with no test, or only mocks in the critical layers, stays open. The frontend auditor applies the same rule with a Playwright or MSW test.

What it costs

Every task needs a proof decided up front. The browser run is a second agent call, and the restated rules add weight to every prompt. For exploratory work that is not worth it.

In return, the checks hold during unattended overnight runs with nobody reviewing a diff. Kent Beck's TDD asks you to write the test first, and here the loop will not start a task until it has one.

The Matcha case study shows the product this loop builds.