Development
Extend the factory
Step-by-step recipes to add CLI verbs, UI actions, project settings, prompts, role skills, review rules, catalogues, and diagrams.
How-to guide
Follow these code-anchored recipes to add commands, settings, prompts, rule packs, catalogues, and diagrams to factory/. Run the matching unit test package after each change.
Pick your recipe
| What you want to add | Primary files touched | Verification test |
|---|---|---|
| CLI verb & UI action | internal/cli/, internal/ui/, internal/ui/web/ | go -C factory test -short ./tests/unit/cli/... ./tests/unit/ui/... |
| Project preference | internal/project/{project,schema}.go, internal/ui/prefs.go | go -C factory test ./tests/unit/project/... |
| Prompt or role skill | prompts/*.md, skills/*/SKILL.md, skills/map.json | go -C factory test ./tests/unit/skillmap/... |
| Deslop or Code review rule | deslop/*/rules.json, codereview/packs/*.json | go -C factory test ./tests/unit/{deslop,codereview}/... |
| Project catalogue | catalogue/<type>.json, catalogue/templates/, project.go | go -C factory test ./tests/unit/project/... |
| Architecture diagram | docs-site/components/mdx/diagrams/specs/ | bun run verify:diagrams && bun run check:llms |
Add a CLI verb and UI action
CLI-backed UI actions shell out to t12 with --by <email>, while t12-ui writes host control files (access/, approvals/, observer/) directly. Implement and test the CLI verb first.
Implement and register the CLI verb
- Add the verb under
factory/internal/cli/usingflag.FlagSetandparse(set, args, ...)(cli.go), accepting--homeand--by. - Keep
net/httpout ofinternal/cli/soTestTheCoreAndTheCageProgramsLinkNoNetworkCodekeeps passing; place direct HTTP calls underfactory/cmd/t12-adapter/orfactory/cmd/t12-<name>/(v2t12invokes local harnesses and subprocess adapters). - Register the verb in
commandsincli.goor viainit(), matchingask.go(ask),confirm.go(confirm),factory.go(run), andrequests.go(conversation,request).
Add the UI handler and control
- Add a
POSTroute toServer.Handler()infactory/internal/ui/server.gowrapped withs.signedIn(...)(pluss.operator(...)if Operator-only). - In
factory/internal/ui/, resolves.requestOfors.projectOf, checka.Editor/a.Acceptor/a.Run, and calls.command(...)ors.start(...)with--byset tov.User.Email. - Update types in
factory/internal/ui/web/src/api/types.tsand add a<Button>or<Confirm>insrc/pages/callingrun(path, form, success)fromuseActions(lib/use-actions.ts).
Rebuild and test
factory/scripts/build-ui.sh
go -C factory build -o bin/ ./cmd/...
go -C factory test -short ./tests/unit/cli/... ./tests/unit/ui/...Add a project preference
- Add struct field: Add the exported field and
jsontag toPreferencesinfactory/internal/project/project.goand set any non-zero default inDefaultPreferences(). - Register schema rule: Add a
settingentry topreferenceSettingsinfactory/internal/project/schema.go(key,kindinkString/kSlug/kInt/kEnum/kArgv/kStrings/kGlobs/kBool, bounds/enum,help). - Mark safety keys: Set
safety: truewhenever relaxing the key could hide defects (non-Operator edits write<home>/proposals/until approved). - Expose in UI (optional): Add the key to
plainKeysinfactory/internal/ui/prefs.goto show it on the plain Preferences tab. - Test:
go -C factory test ./tests/unit/project/...Add or edit a prompt or role skill
factory/factory.go embeds prompts/ and skills/ into factory.Files. Keep phrasing neutral so wording_test.go passes.
- Start
factory/prompts/<name>.mdwith# <Title>on line 1, a blank line on line 2, andVersion: <N>on line 3 (promptinfo.go). - Increment
<N>on every edit; if editing a prompt inlockedPrompts, update its version and 12-char SHA-256 prefix infactory/tests/unit/contextcreator/prompts_test.go. - Test:
go -C factory test ./tests/unit/contextcreator/... ./tests/unit/skillmap/...Add a Deslop or Code review rule
- Add a rule to
"rules"infactory/deslop/typescript/rules.json(orfactory/deslop/<stack>/rules.jsonmatchingproject.Stack) with"fixtures": { "must_catch": [...], "must_not_catch": [...] }:
| Field | Allowed values |
|---|---|
id | ^DS-[A-F]\d+-[a-z][a-z-]*$ |
manifesto | Non-empty array from #2, #5, #6, #8, #14, #15, #17, #18, #19, #21 |
tool | diff-regex, test-literal, vi-mock, clone, dead-weight, prose |
action / severity | action: finding | autofix; severity: blocking | should-fix |
- Set
"status": "advisory"soRule.FindingSeverity()emitsshould-fixwhile<home>/deslop/stats.jsontracks precision (proposes promotion at>= 20hits with80%kept, demotion at> 25%dismissed across>= 10hits, andguardrail-*.jsonafter>= 3recurring runs). - Test:
go -C factory test ./tests/unit/deslop/...Add a project catalogue
- Create
factory/catalogue/<type>.json(^[a-z0-9][a-z0-9-]*$) withtype,version(1or higher),title,template,project,defaults, andmust_haves. - List
must_havesin exact order (goal,users,pages,core-journey,look,out-of-scope), each withquestionandwhy_askplusrecommendedonpagesandlook. Populatedefaultswithid,topic,question,default,alternatives,reason, andevidence(keeping strings compliant withwording_test.go). - For buildable types, add
factory/catalogue/templates/<template-name>/(package.json, nonode_modules/); leavetemplateempty for plan-only types likedesktop.json. Register<type>inProjectTypes(factory/internal/project/project.go). - Test:
go -C factory test ./tests/unit/project/...Add or update an architecture diagram
Architecture diagrams render as theme-matched animated SVGs defined under factory/docs-site/components/mdx/diagrams/ and embed via <FactoryDiagram />.
- Create
factory/docs-site/components/mdx/diagrams/specs/<name>.ts(or edit an existing spec) and register it infactory/docs-site/components/mdx/diagrams/index.ts. - Keep zones, nodes, edges, and playback scenarios inside
viewBoxwith zero overlaps and validcodeReftargets. - Embed
<FactoryDiagram name="<name>" />(optionally withcaption="...") in an MDX page, then runbun run verify:diagramsandbun run check:llmsfromfactory/docs-site/.