Spec: Law-AI Factory — GitFactory builds and manages law-ai's AI orchestration¶
- ID: 002-law-ai-factory
- Status: shipped
- Owner: @bamr87
- Created: 2026-08-17
- Roadmap link: docs/ROADMAP.md § Fleet (GitFactory applied to any repo); user request 2026-08-16
- Golden-rules compliance: confirmed against CLAUDE.md § Golden rules
1. Problem & Motivation¶
law-ai runs an AO-SDLC whose deterministic half is automated (evolve.yml appends audit findings weekly) but whose agentic half is manual: the tracking issue literally asks a human to "run /evolve". law-ai has no .factory/, and its AI orchestration (mention handler aside) is hand-authored YAML. GitFactory exists precisely to compile governed agent lines — so it should be the tool that builds and manages law-ai's orchestration: blueprints as source of truth, compiled workflows with computed least-privilege grants, loop guards, kill switches, and telemetry/fleet visibility for free.
2. Origin & Background¶
- Backlog items claimed: BL-20260817-03
- Builds on: ADR-018 (standalone blueprints + generator-script dogfood pattern), ADR-017 (
gate.enablementdefault-OFF governance), ADR-013 (survey-mode grants), ADR-012 (OAuth-first auth — law-ai'sclaude.ymlalready uses the identical expression), ADR-023 (promptRef read grants). law-ai side is governed by its own constitution §7/§11 — aspecs/037package + BL entry land there with the artifacts.
3. Goals¶
- G1: law-ai's agentic orchestration is generated by GitFactory from committed blueprints — never hand-edited.
- G2: Every line ships default-OFF (repo-variable kill switch) with least-privilege grants and loop guards; arming is an explicit human act.
- G3: The line shapes are reusable: an
ao-sdlc-autopilottemplate joins the gallery for any AO-SDLC repo.
4. Non-Goals¶
- NG1: Replacing law-ai's deterministic workflows (
ci.yml,evolve.ymlaudit,nightly-tests.yml,claude.ymlmention handler) — the factory lines complement them. - NG2: Arming any line (setting
*_ENABLED=true) or committing/pushing in either repo — user actions. - NG3: Cross-repo lines (gitorio-hosted workflows acting on law-ai) — the lines live in law-ai with repo-local tokens.
5. User Stories¶
- As law-ai's maintainer, I want the weekly audit's "next step" executed by a governed agent line, so the backlog drains without me babysitting
/evolve. - As the fleet operator, I want law-ai's automation visible as blueprints and Fleet-tab telemetry, so managing it is the same motion as managing every other repo.
6. Functional Requirements¶
- FR-1: An
ao-sdlc-autopilottemplate in the gallery: cron + plan-first manual →gate.enablement→rate.limiter→agent.claude(promptRef) →sink.open_pr; compiles with zero error diagnostics. - FR-2: A generator
app/scripts/gen-aosdlc-factory.ts <target-repo-dir>that emits, into the target: three standalone blueprints (evolve-pilot, backlog-triage, issue-concierge) and their compiledfactory--*.ymlwith correctblueprintPathheaders; it refuses on any error-level diagnostic. - FR-3: law-ai receives the artifacts:
.factory/{evolve-pilot,backlog-triage,issue-concierge}.blueprint.json,.factory/prompts/{evolve-pilot,backlog-triage,issue-concierge}.md,.github/workflows/factory--{evolve-pilot,backlog-triage,issue-concierge}.yml. - FR-4: Kill switches per line —
EVOLVE_PILOT_ENABLED,BACKLOG_TRIAGE_ENABLED,ISSUE_CONCIERGE_ENABLED— all default-OFF (unset ⇒ idle). - FR-5: law-ai governance closed: BL entry in law-ai's BACKLOG.md,
specs/037-gitfactory-orchestration/package, law-ai'sspec_validator.py+backlog_lint.pygreen, markdown one-paragraph-per-line.
7. Non-Functional Requirements¶
- NFR-SEC-1: Least privilege per line — grants derived by the compiler from sinks only; no blanket Bash; the evolve pilot opens PRs but can never merge (no-self-merge).
- NFR-LOOP-1: The issue-concierge line (issue-triggered, comment/label-writing) carries the compiler's actor-based bot loop guard.
- NFR-AUTH-1: Auth is the house expression —
CLAUDE_CODE_OAUTH_TOKENfirst,ANTHROPIC_API_KEYfallback — matching law-ai's existingclaude.ymlsecrets.
8. Blueprint & Schema Impact¶
No new machine types; blueprints use existing 21 types and must validate against schema/blueprint.schema.json. One new gallery template (FR-1).
9. Compiler & Workflow Impact¶
No compiler changes; the generator consumes compile() with blueprintPath per line (ADR-018). Compiled workflows carry the GENERATED BY GITFACTORY header + blueprint hash, so law-ai's drift detection works from day one.
10. UI Impact¶
The new template renders in the Templates gallery (existing gallery code; no panel changes). law-ai becomes observable via the existing Fleet tab by adding it to a roster (runtime action, not code).
11. Security Impact¶
Prompts instruct agents to fetch entity content via gh (numbers-not-bodies, ADR-005); untrusted issue text never enters workflow YAML. All lines default-OFF; a compromised agent cannot re-arm its own kill switch (variable writes need admin scope). Grants: evolve-pilot and backlog-triage get file-edit + gh pr create (via sink.open_pr) but no merge verb; issue-concierge gets comment/label verbs only.
12. Acceptance Criteria¶
- AC-1:
gen-aosdlc-factory.ts /path/to/law-aiexits 0, writes exactly 3 blueprints + 3 workflows, each workflow containing the generated header, its ownblueprintPath, and its line'svars.*_ENABLEDgate. - AC-2: The issue-concierge workflow contains the bot guard (
github.event.sender.type != 'Bot'). - AC-3: The evolve-pilot and backlog-triage workflows contain no
gh pr mergegrant; both containgh pr createand the git verbs. - AC-4: A catalog invariant test compiles the
ao-sdlc-autopilottemplate with zero error diagnostics (existing catalog.test.ts covers all templates). - AC-5: In law-ai:
python3 scripts/spec_validator.pyandpython3 scripts/backlog_lint.pyexit 0 with the new spec 037 + BL entry present.
13. Risks & Open Questions¶
- R-1: An autonomous evolve pilot could pick a BL item needing human judgment — mitigated: the prompt embeds law-ai's
/evolvestop conditions (licensing/data-source/HITL questions ⇒ stop and file, never guess) and the line is draft-PR-only. - R-2: Concierge noise on every new issue — mitigated: default-OFF; single comment obligation with dedup instruction; rate limiting via
maxTurnsand the label-first contract.
14. Out of Scope / Follow-ups¶
- A
repository_dispatch/cross-repo control line from gitorio into law-ai (BL-20260816-22 territory). - Modeling law-ai's deterministic
evolve.ymlaudit as a compiled factory line (mirrors gitorio's own BL-20260816-34).