# Growing a software factory

The four diagrams and dotFactory definitions follow the article in order. Each definition is a standalone snapshot. Use the highlighted part of the diagram and the matching code excerpt in the article.

| Stage | Diagram | Full definition | Code to show in the article |
| --- | --- | --- | --- |
| Open a pull request | [SVG](images/01.svg) | [01.fct](code/01.fct) | The issue trigger and the two steps that implement the ticket and open the PR. |
| Run tests before opening the PR | [SVG](images/02.svg) | [02.fct](code/02.fct) | The `tested_patch` loop. The `prev test_feedback` binding returns failed test output to the coding agent for up to three total attempts. |
| Feed merge-candidate CI back | [SVG](images/03.svg) | [03.fct](code/03.fct) | The `ci_failed` trigger and `repair` step. The run uses the failed revision, updated base, and CI output. It reuses the existing test loop before updating the PR. |
| Split work before coding | [SVG](images/04.svg) | [04.fct](code/04.fct) | The `Scope` choice, `triage`, and the two guarded branches. A split produces a proposal for review. Approved child tickets can enter through the existing issue trigger. |

## Host adapters

The definitions pass the repository's parser, resolver, and validator. Running them requires a host that implements the article-specific kinds below.

- `article_issue_opened` normalizes a ticket-opened event and deduplicates deliveries. A coding run should keep its edits on a working branch.
- `article_coding_agent` prepares a checkout, applies changes, and returns the branch and commit. It starts retries from the last tested candidate and applies the supplied CI base on repairs. Its scope-inspection action reads the ticket and checkout and returns either a single change or proposed child tickets with acceptance criteria and dependencies.
- `article_tests` runs the test command against the exact candidate and returns the same revision, a pass/fail result, and test output. A failing test is a result that the loop can consume.
- `article_merge_ci_failed` admits failed checks for the current merge candidate, only for PRs this factory owns. CI must schedule a fresh check when the base moves. The adapter deduplicates events, drops stale results, and enforces a per-PR repair budget across runs.
- `article_repository` opens or finds a PR for the ticket, reports exhausted attempts, or presents a split for human review. On CI repair, it publishes the candidate only if the PR head still matches the failed revision. It does not merge PRs or turn proposals into issues automatically.
