Spec, Build, Sensors: a harness for AI-written code
How I organize a TypeScript monorepo so AI agents ship changes that are predictable, easy to review and ready to merge.
An agent can write a feature in minutes. The hard part is trusting what comes back. I stopped trying to fix that by reading every diff harder and started building the project around three stages: Spec decides what to build, Build produces it in isolation, and Sensors prove it is safe to merge. This article walks through that structure using a small side project of mine, FutMeet. It is still being built and has not launched, so the repository keeps changing while I write this.
Spec
Explore the idea, write it down, plan it. No code yet.
Build
Isolated branch, written conventions, tests with the code.
Sensors
Automated checks that read green or red. Red means fix and rerun.
- 1. Introduction
- What is a harness
- The three stages
- 2. Development
- The monorepo
- Spec
- Build
- Sensors
- Other harnesses
- 3. Conclusion
- References
1. Introduction
AI in real life
In my day-to-day, an AI agent already writes most of the code. In FutMeet, the README says it plainly: agents write most changes. That is not a promise about the future, it is how the repository is used today.
The speed is real. What bites is everything around it. The agent forgets a convention you told it yesterday. It adds a dependency nobody asked for. It declares the task done while a test is red. None of this is new for a human team either, but an agent produces it faster and never gets tired of doing it.
Reading every diff more carefully does not scale. It also turns you into the slowest part of the system. I would rather spend that effort once, on the structure around the agent.
What is a harness
The word comes from the agent world. Birgitta Böckeler, writing on martinfowler.com, puts it as everything in an AI agent except the model itself
, and then focuses on the part you build for your own project: the outer harness (Harness engineering for coding agent users, April 2026). OpenAI used the same word in its write-up of building a product with Codex.
Böckeler splits the harness into two kinds of controls:
Guides (feedforward)
They steer the agent before it acts, so the first attempt is more likely to be right. Examples: AGENTS.md-style rules, skills, code mods.
Sensors (feedback)
They observe after the agent acts and let it self-correct. Examples: tests, linters, type checkers, an AI reviewer.
She also separates computational controls (deterministic and fast, like a type checker) from inferential ones (semantic judgment, like an AI code review, slower and less predictable). And the human's job becomes iterating on the harness: when the same mistake shows up twice, you improve a guide or a sensor, not your supervision.
The three stages
My three stages are not Böckeler's terms. They are how I lay the same idea out in time, in a repository:
- Spec is a guide. The agent clarifies intent, compares approaches and writes a spec and a plan before touching code.
- Build is also a guide. Work happens in an isolated worktree, and written conventions (skills) tell the agent how this project does things.
- Sensors are the feedback. Automated checks decide whether the result is allowed to become a pull request.
Splitting guides into Spec and Build is my choice. It helps because they happen at different moments and fail in different ways: a bad spec builds the wrong thing correctly, a bad build implements the right thing wrongly.
Here is the whole loop. Click through the steps or press Play.
Why structure it like this
- Rules live in the repository. A new agent session, a new teammate or a different tool reads the same files. Nothing depends on someone remembering to say it again.
- Failures are cheap and early. A wrong spec costs a paragraph. A wrong branch costs a worktree you delete. A red sensor costs one rerun. A bug in production costs much more.
- Review gets smaller. By the time a pull request exists, the mechanical questions are already answered. You review intent and design, which is the part only you can judge.
2. Development
The monorepo
FutMeet helps casual football players organize pickup games: someone opens a room and shares the link, players join, and the app sorts everyone into balanced teams. It is a TypeScript monorepo on npm workspaces, orchestrated by Turborepo:
apps/web: React 19 and Vite, a single-page app.apps/api: the BFF, a Fastify 5 REST API on PostgreSQL.packages/shared: domain types and utils both apps import.packages/sensors: the code behindnpm run verify.packages/tsconfigandpackages/oxlint-config: one TypeScript and one lint configuration for everyone.
Turbo sets the order of the tasks: shared builds first, then the apps.
// turbo.json
{
"tasks": {
"build": { "dependsOn": ["^build"], "outputs": ["dist/**"] },
"typecheck": { "dependsOn": ["^build"] },
"dev": { "cache": false, "persistent": true },
"lint": {},
"test": {}
}
}^build means "build my dependencies first" (Turborepo docs). Because @futmeet/shared exports its compiled dist/ files, typecheck in the web and the API runs against the shared package as it really is.
The shared package is the contract between front and back. A single definition, imported by alias and never by a relative path across packages:
// packages/shared/src/types/index.ts
// 'sorting' is frontend-only transient state; backend only stores 'setup' | 'complete'
export type GameStatus = 'setup' | 'sorting' | 'complete';
export type ServerGameStatus = 'setup' | 'complete';
// apps/web and apps/api
import type { Game } from '@futmeet/shared/types';If the API changes what a Game looks like, the web's typecheck should fail on the same run. I have not measured how often that saves me. I just notice it is the kind of mistake I stopped seeing in review.
Now pick a stage to see which files in the repository belong to it:
- CLAUDE.mdRequired workflow, skill index and conventions
- Issue or ticketSpec and plan for each change. Not in the repo
- adr/Decisions that are hard to reverse
- .claude/skills/One folder per skill, details in
references/ - .githooks/No commits to
mainor from the primary checkout - apps/web, apps/apiThe code the agent changes
- packages/sharedContract between front and back
- packages/tsconfig, oxlint-configOne configuration, applied everywhere
- turbo.jsonTask order and caching
- packages/sensors/verify, skills lint, test presence, bundle budget
- .claude/settings.jsonHook that blocks
gh pr createwhile red - .github/workflows/ci.ymlThe same sensors, as a backstop
Spec: decide before you type
The first stage has one rule: no code before the idea is written down. First the agent asks what you want and compares the options. What comes out is a short spec and plan, with the main goal and the steps, and they live in the ticket: a GitHub issue, a Jira ticket or any other management tool. If the decision is hard to reverse, it also becomes an ADR, and that one stays in the repository.
An example from FutMeet, trimmed. This spec for adding Docker support starts with a goal and the files it will touch:
# Docker Configuration Design: FutMeet API
**Scope:** `apps/api`
## Goal
Add Docker support to the API with two modes:
- `dev` profile: starts only the PostgreSQL database.
- `deploy` profile: starts the database, runs migrations,
then starts the compiled API.
## Files
apps/api/
Dockerfile (new: multi-stage build)
docker-compose.yml (updated: profiles, migrate service, api service)
.env.example (updated)Two things make this a guide and not just documentation. It states the scope, so the agent has a boundary. And it is short enough to be read by a person in a minute, so you can disagree before forty files change.
The format and the habit come from Superpowers, a methodology of composable skills: it asks what you want to build, shows the spec in short pieces for you to approve, and only then writes the plan, before any code (README). By default it writes them as files, so FutMeet keeps them under docs/superpowers/.
I'd rather not commit specs and plans. The team already talks about the work in the ticket, and it doesn't sit in the repo after the merge.
The spec is also where you catch the expensive mistakes. Correcting a paragraph is the cheapest edit you will make all week.
Build: isolate it and write the rules down
The second stage answers two questions: where does the work happen, and how does the agent know how this project does things?
Where. Always in its own worktree, never on main. It's in the project rules, and if anyone tries to commit on main, a hook stops it:
git worktree add .worktrees/feat-room-link -b feat/room-link
# .githooks/pre-commit
Direct commits to 'main' are blocked. Create a worktree: git worktree add ...
Commits from the primary checkout are blocked. Work in a worktree ...How. Conventions live in .claude/skills/. Each skill is a short SKILL.md of 100 lines or fewer that points to a references/ folder for detail. CLAUDE.md only holds the index, so the agent loads the one skill that matches the task and nothing else:
| Working on | Skill the agent loads |
|---|---|
| Any change, branch, cleanup | worktree-workflow |
| New API module, routes | api-fastify-module |
| Components and CSS Modules | component-architecture-css-modules |
| Forms | forms-react-hook-form-zod |
| Tests | testing-vitest |
| Before opening a PR | pr-gate |
A few rules do not fit in config, so they are written as prose. The API runs Route → Controller → Service → Repository → Query and services contain no try/catch. The web uses CSS Modules and no inline styles. Shared code is imported by alias. An agent that reads this before touching apps/api stops reinventing the layering on every task.
Keeping each skill under 100 lines is a constraint I chose on purpose. A long instruction file is read less carefully, by agents and by people. The limit also becomes a sensor, as you will see next.
Tests are part of Build, not an afterthought: every file the agent creates or modifies ships with its tests in the same commit.
Sensors: let the checks decide
A sensor is an automated check that reads green or red, nothing in between. npm run verify runs all of them and a pull request opens only when every one is green:
| Sensor | Catches |
|---|---|
lint, typecheck | oxlint warnings, type errors |
format:check | Changed files that do not match Prettier |
knip | Unused files, dependencies and binaries |
skills:lint | Skills over 100 lines, broken references/ links, skills missing from the index |
test:presence | A changed source file with no test, a changed web component with no a11y test |
secrets, audit:prod | Committed credentials, high or critical vulnerabilities |
test | Failing tests, coverage under the floor |
build, bundle | Compile errors, web bundle over its gzip budget |
db:check | Migrations that fail to apply or roll back (always in CI) |
All of these are computational in Böckeler's sense: deterministic, fast enough to run on every change. FutMeet also has an inferential one, the security-pr-review skill, but that is a reviewer, not a gate. Notice that a few sensors check the harness itself: skills:lint keeps the Build guides honest, and test:presence turns "every file ships with tests" from a wish into a rule. That is the loop Böckeler describes: when a mistake repeats, you turn the guide into a sensor.
The runner is a small script. It runs each sensor, prints a summary and exits non-zero when any is red:
// packages/sensors/src/verify.mjs
export const SENSORS = ['lint', 'typecheck', 'format:check', 'knip', 'skills:lint',
'test:presence', 'secrets', 'audit:prod', 'test', 'build', 'bundle'];
// verify failed: test:presence red. Fix the cause, then rerun npm run verify.
// verify passed: all sensors green.Try it yourself. The agent changed a file and forgot the test, so the first run fails. Write the missing test and run it again, or try skipping the test and see what happens.
- lint
- typecheck
- format:check
- knip
- skills:lint
- test:presence
- secrets
- audit:prod
- test
- build
- bundle
The rule behind that last button matters most. pr-gate says a fix must change code, tests or config so the sensor passes for the right reason. Skipping tests, lowering a coverage floor, raising the bundle limit, adding lint-disable comments or @ts-ignore do not count. Without that rule, an agent will reach green the easy way.
Enforcement has three layers, from closest to the agent to furthest:
- A Claude Code hook in
.claude/settings.jsonruns before everygh pr createand blocks it while any sensor is red. - Git hooks in
.githooks/block commits tomainand from the primary checkout. - CI runs the same sensors on every pull request, so nothing depends on the local machine.
A sensor only catches the mistakes someone remembered to check for. My sensors say nothing about whether a feature is a good idea or whether the code is easy to read. That stays with the spec and the review. So I say the code is ready to merge, not that it's safe.
Other harnesses worth reading
FutMeet is one small project. These two are better known and show different choices:
Superpowers
A full methodology shipped as skills: ask first, write a spec, then a plan, then execute task by task with subagents and review. It starts working from the first message, because the skills trigger on their own (README). I use it for FutMeet's Spec stage.
Matt Pocock's skills
Small, composable skills for "real engineering, not vibe coding". Unlike frameworks that own the whole process, they let you adapt only what you need (README).
The pattern I take from both: skills are the cheapest way to turn a convention into a guide. What they do not give you is the red/green feedback. That is the part I added in packages/sensors.
3. Conclusion
An agent is fast but forgetful. A harness is how the project remembers for it. Put together, the three stages look like this:
| Stage | Kind of control | Question it answers | In FutMeet |
|---|---|---|---|
| Spec | Guide (feedforward) | What are we building, and why this way? | Spec and plan before the code, ADRs in the repository |
| Build | Guide (feedforward) | Where does the work happen, and how does this project do things? | Worktrees, git hooks, skills, tests with code |
| Sensors | Feedback | Is this safe to merge? | npm run verify, the PR hook, CI |
The monorepo helps in a quiet way. One place for the web, the API and the shared contract means one set of skills, one verify, one task graph that Turbo keeps in order. Splitting the same rules across several repositories would have meant keeping several harnesses in sync.
If you want to try this without rebuilding anything, start small and in this order:
- One sensor. Make a single command that runs your lint, types, tests and build, and returns non-zero on any failure.
- One rule the agent breaks. Write it as a short skill or a section of your instructions file. When it breaks it again, turn it into a check.
- One habit before code. Ask for a short spec and read it before the agent starts.
The harness is never finished. Each time the agent surprises you, ask which guide would have prevented it or which sensor would have caught it, and add that one. Over time you review less code and more intent.