How it works
Three parts. The script owns state. The orchestrator starts the agents the script names. Each agent does one step and writes one file.
Three parts
| Part | What it is | What it decides |
|---|---|---|
The script, .factory/bin/mfactory | Python, the standard library and PyYAML | Everything about state: which step a job is in, where an outcome leads, whether a limit is reached, whether the checks pass, when to merge. |
The orchestrator, the /mfactory skill | A prompt your coding tool's main agent follows | Nothing. It asks the script what to do, starts the agents the script names, and reports back. |
| The agents | One small generated file per step, pointing at a prompt in .factory/roles/ | The content of their one step: a spec, a build, a review. |
The pipeline is data in factory/pipes/*.yaml, so no prompt describes it. Changing the pipeline changes no prompt, and the orchestrator works the same for any graph.
The loop
$ .factory/bin/mfactory next 004
start-agent mfactory-spec
prompt: Job: 004-dark-mode. Step: spec. Job folder: /repo/.factory/jobs/004-dark-mode/. ...
then: .factory/bin/mfactory done 004-dark-mode
$ .factory/bin/mfactory done 004-dark-mode
004-dark-mode #12: spec DONE -> build
next runs checks, merge, and verify steps itself and prints the result. For agent and review steps it prints which agents to start and the one-line prompt of each. done reads the first line of the file the agent wrote, checks the work (the file is new, the tree is clean, the branch is pushed), and follows the edge for that outcome.
Whether an agent's file is new is decided by comparing the file's size and modification time with what was recorded when the job entered the step, not by comparing clocks.
Where the factory lives
In a project, the factory is the .factory/ folder. In this repository that folder is built from core/, with adapters/ and web/ beside it.
.factory/bin/mfactory the CLI
.factory/lib/modfactory/ the factory's code
.factory/roles/*.md one prompt per agent step and reviewer
.factory/skill/SKILL.md the orchestrator
.factory/defaults.toml the default pipeline and settings
.factory/templates/factory.toml the factory.toml written on first install
.factory/adapters/*.toml per tool: folders, agent file format, default models
.factory/web/ the dashboard, inlined when it is served
You edit factory/factory.toml and the pipes in factory/pipes/. mfactory sync writes the agent files the tool actually loads. See where each tool writes.
A job's folder
Each job has a folder, .factory/jobs/<id>/, in the main checkout. Git ignores it. The branch is {branch_prefix}<id> (default factory/<id>), in a worktree at .worktrees/<id>. A revert branch is {branch_prefix}revert-<id>.
job.json state: step, history, counts, pull request
issue.md the issue and its comments, as quoted data
intake.md spec.md build.md decision.md verify.md
progress.md notes from a build attempt that stopped early
feedback-1.md what a person asked for
round-1/checks.md the gate's verdict, with checks.log
round-1/review-code.md one file per reviewer
round-1/debug-1.md the debugger's diagnosis
A build that stops before it rewrites build.md can leave progress.md. The next builder of that step is told to read it. done deletes the file once the build outcome is accepted.
What the script will not do
- It does not deploy.
- It does not merge a revert. A failed validation can open a draft pull request that reverts the merge, for a person to merge.
- It does not merge at all unless the merge step is on. See who merges.
- It does not let a job edit
factory/,.factory/, or a generated agent or skill file. See protected paths.