Skip to Content
turbo-12f
Development

Extend the factory

Step-by-step recipes to add CLI verbs, UI actions, database stores, project settings, flow steps, prompts, role skills, review rules, catalogues, and diagrams.

How-to guide

Follow these code-anchored recipes to add commands, stores, settings, prompts, rule packs, catalogues, and diagrams to the factory. Paths are relative to the repository root. Run the matching test package after each change.

Pick your recipe

What you want to addPrimary files touchedVerification test
CLI verb & UI actioninternal/cli/, internal/ui/, internal/ui/web/go test -short ./tests/unit/cli/... ./tests/unit/ui/...
Database storeinternal/db/schema/migrations/, your package, an internal/db/importer hookgo test ./internal/<pkg>/... with T12_TEST_DATABASE_URL set
Project preferenceinternal/project/{project,schema}.go, internal/ui/prefs.gogo test ./tests/unit/project/...
Flow stepinternal/orchestrator/, internal/cli/run_steps.go, assets/strategist/rules.json, internal/ui/web/src/lib/steps.tsgo test ./internal/cli/ -run TestEveryFlowStepIsWiredAndOwned
Prompt or role skillassets/prompts/*.md, assets/skills/*/SKILL.md, assets/skills/map.jsongo test ./tests/unit/skillmap/...
Deslop or Code review ruleassets/deslop/*/rules.json, assets/codereview/packs/*.jsongo test ./tests/unit/{deslop,codereview}/...
Project cataloguecatalogue/<type>.json, catalogue/templates/, internal/project/project.gogo test ./tests/unit/project/...
Architecture diagramdocs-site/components/mdx/diagrams/specs/bun run verify:diagrams && bun run check:llms

Add a CLI verb and UI action

State lives in Postgres, so a UI action never writes files. It either shells out to t12 with --by <email> or, in cloud mode (s.Cloud != nil), dispatches the same verb to the GitHub Actions worker. Implement and test the CLI verb first.

Implement and register the CLI verb

  1. Add the verb under internal/cli/ using flag.FlagSet and parse(set, args, ...) (cli.go), accepting --home and, where the action is attributed to a person, --by.
  2. Open the home with e.openHome(*home). Main already opened the database for every verb not listed in noDatabase, so the verb gets it through e.DB.
  3. Keep net/http out of internal/cli/ so TestTheCoreAndTheCageProgramsLinkNoNetworkCodeButTheDatabaseClient keeps passing; place direct HTTP calls under cmd/t12-adapter/ or cmd/t12-<name>/.
  4. Register the verb with commands["<verb>"] = command{usage, run} in an init(), matching ask.go, confirm.go and run in factory.go, requests.go (conversation, request) and db.go (db).

Add the UI route and guards

  1. Add the route to Server.Handler() in internal/ui/server.go. Conversation routes go in registerConversationRoutes, which serves both /api/c/{id} and /api/r/{id}.
  2. Wrap the handler in s.signedIn(...), which answers 401 without a session and 403 for a POST without the matching X-CSRF-Token. Add s.operator(...) for Operator-only routes, or s.teamOnly(...) for project pages a client must not see.
  3. Resolve access in the handler: s.requestOf returns a reqAccess with Editor, Acceptor and Run; s.projectOf returns the project name and repository and answers 404 unless the person has access.
  4. Refuse with forbid(...) and return errors through s.writeActionResult. Call s.requireAI(email) or s.requireGitHub(email) first when the action starts a conversation or project: they answer 409 when the person has no connected AI or GitHub.
  5. Start the work with s.command(v.User.Email, a.ID, "<verb>", "--home", s.Home.Dir, ..., "--by", v.User.Email) or s.start(...). Branch on s.Cloud != nil and call s.Cloud.Dispatch(...) the way startBuild in build.go does.

Add the web control

Update types in internal/ui/web/src/api/types.ts and add a button or <Confirm> in src/pages/ or src/components/ that calls run(path, form, success) from useActions (src/lib/use-actions.ts). run shows the server's error text, and a 409 refetches the page.

Rebuild and test

scripts/build-ui.sh
go build -o bin/ ./cmd/...
go test -short ./tests/unit/cli/... ./tests/unit/ui/...

Where each guard lives

signedIn, operator and Handler() are in internal/ui/server.go; teamOnly is in internal/ui/team_only.go; reqAccess, requestOf and accessTo are in internal/ui/requests.go; requireAI and requireGitHub are in internal/ui/capabilities.go.

Add a store

Every durable record lives in Neon Postgres (ADR 0005); the state home holds scratch only. A new store follows the ADR's store contract.

Take a client and add a migration

  1. Accept a *db.Client in the constructor, never a path. schema.Open(ctx) runs once in main, reads DATABASE_URL, migrates, and returns db.ErrNoDatabaseURL when it is unset; pass the client down.
  2. Add a new file internal/db/schema/migrations/NNNN_name.sql numbered after the last one (names match ^\d{4}_[a-z0-9_]+\.sql$, without gaps). A merged migration is never edited: its checksum is recorded and an edited file is refused.
  3. Pick the right shape: a few KB of mutable JSON is a documents row, an unbounded list is a table or log_entries stream, and anything hashed or binary is a blob.

Replace locks with database primitives

NeedUse
Read-modify-write one small recordUpdateDoc, or an UPDATE ... WHERE rev = $n compare-and-swap
Append to a hash chainAppendChained(ctx, stream, genesis, build) with a pure build(seq, prev)
Several rows that change togetherBatch, one transaction; put guards in SQL
Exclusion over long workWithLease(ctx, name, ttl, wait, fn)

Mark a write Idem only if repeating it leaves the same state; Exec is never retried. Map errors.Is(err, db.ErrUnique | ErrNotFound | ErrLeaseHeld ...) to your package's errors at the boundary.

Import old files and test

  1. If the store replaces files in an old home, register an import step in init() with importer.Register("<name>", importer.Order<Band>, hook) and write only through e.Exec with db.Idem statements, so t12 db import --home DIR --dry-run stays side-effect free.
  2. Delete the file store in the same change: no dual write and no if file exists.
  3. Test with dbtest.New(t) or recordtest.New(t), which skip when T12_TEST_DATABASE_URL is unset:
scripts/test-db.sh start
eval "$(scripts/test-db.sh env)"
go test ./internal/<pkg>/...

Add a project preference

  1. Add struct field: Add the exported field and json tag to Preferences in internal/project/project.go and set any non-zero default in DefaultPreferences().
  2. Register schema rule: Add a setting entry to preferenceSettings in internal/project/schema.go (key, kind in kString/kSlug/kRepo/kInt/kEnum/kArgv/kStrings/kGlobs/kBool, bounds/enum, help).
  3. Mark safety keys: Set safety: true whenever relaxing the key could hide defects. t12 config set then stores the change as a proposal document (config-<key>-<timestamp>.json) until an Operator approves it with t12 config approve.
  4. Expose in UI (optional): Add the key to plainKeys in internal/ui/prefs.go to show it on the plain Preferences page.
  5. Test:
go test ./tests/unit/project/...

Change a flow

A flow is the ordered steps every lane of a conversation runs. team (the default) has six, classic has eleven; both end with the merge policy, the merge and the deploy dry run (ADR 0006). To add a step to a flow:

  1. Step constant: Add the step name as a constant in internal/orchestrator (next to Analyze, Engineer, QA).
  2. StepFunc: Add its StepFunc to the map returned by cli.runSession.steps in internal/cli/run_steps.go.
  3. Flow and owner: Add the step to the flow's Steps in internal/orchestrator/flow.go, in run order, with the step right before Policy as the lane's last check. For the team flow also add an entry to Owners, naming the team member who does it.
  4. Routing rule: Add a found_by rule for the step to assets/strategist/rules.json, so a blocking finding has a route (for example qa goes to engineer with "tokens": 0, a fix attempt). The team flow routes failures by these rules alone and never asks the Strategist agent.
  5. Web label: Add a label, icon and description for the step to internal/ui/web/src/lib/steps.ts; the lane grid shows it, with the team member under it for a team conversation.

TestEveryFlowStepIsWiredAndOwned fails until the step is wired, owned and routed:

go test ./internal/cli/ -run TestEveryFlowStepIsWiredAndOwned

A conversation records its flow in a flow-chosen event before its first part starts, and everything that reads a conversation takes its steps from that event. Changing a flow therefore never moves a conversation that already started.

Add or edit a prompt or role skill

assets/embed.go embeds prompts/, skills/, strategist/, codereview/, deslop/ and the harness guard hooks into assets.Files. Keep phrasing neutral so tests/unit/skillmap/wording_test.go passes.

  1. Add or edit assets/prompts/<name>.md. Start it with # <Title>, a blank line, then Version: <N> on line 3 (internal/contextcreator/promptinfo.go); the eight Context creator prompts require it, and several role prompts carry it too.
  2. Increment <N> on every edit of a Context creator prompt, then update its version and 12-character SHA-256 prefix in lockedPrompts in tests/unit/contextcreator/prompts_test.go; the failing test prints the new values.
  3. Test:
go test ./tests/unit/contextcreator/... ./tests/unit/skillmap/...

Add a Deslop or Code review rule

  1. Add a rule to "rules" in assets/deslop/typescript/rules.json (or assets/deslop/<stack>/rules.json for go, python, rust, matching ResolveStack) with "fixtures": { "must_catch": [...], "must_not_catch": [...] }:
FieldAllowed values
id^DS-[A-F]\d+-[a-z][a-z-]*$, unique in the pack
manifestoNon-empty array from #2, #5, #6, #8, #14, #15, #17, #18, #19, #21
tooldiff-regex, test-literal, vi-mock, clone, dead-weight, prose
statusadvisory or blocking; at least one must_catch fixture is required
  1. Set "status": "advisory" so Rule.FindingSeverity() emits should-fix while the deslop-stats document tracks precision. It proposes promotion at 20 or more hits with 80% kept, and demotion when more than 25% of at least 10 judged hits are dismissed. Runs recurring across 3 requests (RecurringRunsMin) raise guardrail-slop proposals.
  2. Test:
go test ./tests/unit/deslop/...

Add a project catalogue

  1. Create catalogue/<type>.json (^[a-z0-9][a-z0-9-]*$) with type, version (1 or higher), title, template, project, defaults, and must_haves.
  2. List must_haves in exact order (goal, users, pages, core-journey, look, out-of-scope), each with question and why_ask plus recommended on pages and look. Give each defaults entry an id slug, topic, question, default, reason and at least one alternatives value other than the default (keeping strings compliant with wording_test.go).
  3. For buildable types, add catalogue/templates/<template-name>/ with a package.json and set template to templates/<template-name>. Leave template empty for plan-only types like desktop.json. A new project's t12 ask --type reads catalogue/<type>.json directly; add <type> to ProjectTypes (internal/project/project.go) so a project's type setting and t12 ask --repo --type accept it.
  4. Test:
go test ./tests/unit/project/...

Add or update an architecture diagram

Architecture diagrams render as theme-matched animated SVGs defined under docs-site/components/mdx/diagrams/ and embed via <FactoryDiagram />.

  1. Create docs-site/components/mdx/diagrams/specs/<name>.ts (or edit an existing spec) and register it in docs-site/components/mdx/diagrams/index.ts.
  2. Keep zones, nodes, edges, and playback scenarios inside viewBox with zero overlaps and valid codeRef targets.
  3. Embed <FactoryDiagram name="<name>" /> (optionally with caption="...") in an MDX page, then run bun run verify:diagrams and bun run check:llms from docs-site/.

Next steps

On this page