Shaf Lab

Code factory

A software-production pipeline where coding agents, specs, checks, and review loops turn intent into shipped code, with humans steering.

A code factory, also called a software factory, is a production pipeline that turns intent into shipped code with coding agents doing most of the writing. A work item enters as a spec with acceptance criteria. An agent builds the change in an isolated branch or worktree. Deterministic checks such as tests, type checks, lint, and the build run first; review agents with a fresh context judge the diff against the spec; and the change either merges, goes back for rework, or escalates to a person. Builders use the term for the whole system, not for any single agent.

What makes it a factory rather than a chat with a capable model is durable state and gates. Each job carries its own record of spec, build log, check results, and review verdicts outside any conversation, so work survives a crashed session and can run many jobs in parallel. The rules for merging live in machine-readable policy, not in someone's head, and every claim an agent makes, such as "tests pass," has to be backed by evidence the pipeline collected itself, like an exit code, a screenshot, or a trace.

Humans move from writing code to designing and steering the factory. They decide what gets built, write or approve specs, choose which checks gate which changes, and own the escalations that a machine should not decide, such as product trade-offs, security-sensitive areas, and changes with a large blast radius. The craft shifts to building checks that are cheap, fast, and hard to fake, because a factory can only safely automate what it can verify.

The failure modes are the ones of any production line running too fast. Weak checks let plausible but wrong code through at volume. Long agent runs drift. Review becomes a bottleneck if every change needs a person, and understanding of the codebase erodes if no person reads anything. A good factory turns every escaped bug into a new test or rule, starts with narrow, well-tested parts of the code, and widens autonomy only as its evidence improves.

Light and dark factories

Code factories that keep humans reviewing the work, versus ones that let agents scope, build, and ship unattended.

A light factory keeps people in the loop: agents build and check changes, but a person reads and approves what ships. A dark factory, named after lights-out manufacturing, lets agents scope, build, verify, and merge with no one reading the details. Most real factories are a mix, with some kinds of change running dark and others staying lit.

The deciding question is whether a machine can prove the work is done. A loop can run dark when its checks are cheap, run often, and are hard to fake, such as a strong test suite, type checks, or property tests on a well-understood module. It should stay lit when a wrong answer is expensive and only a person would catch it, such as subtle production behavior, security boundaries, or decisions that shape the product for a long time. Running everything dark erodes the team's understanding of its own code; running everything lit makes review the bottleneck.

Risk-tiered merge policy

Rules that assign each change a risk tier by what it touches, and require stronger checks and review for higher tiers.

A risk-tiered merge policy classifies every change by what it touches and sets the gates it must pass to merge. Changes to documentation or isolated UI copy might need only CI. Changes to authentication, payments, database schemas, or agent tools might need extra test suites, browser evidence, an independent review agent, and a human approval.

Keeping the policy in one machine-readable file, for example path patterns mapped to required checks, lets the pipeline enforce it and keeps scripts, workflows, and documentation from drifting apart. The policy should itself be protected: an agent must not be able to lower the tier of its own change or edit the checks that gate it without escalating to a person.