feat(state-hub): implement v0.5 — dynamic domains & multi-repo

Replaces the hardcoded 6-domain PostgreSQL ENUM with a first-class
`domains` DB table, and adds a `managed_repos` table for multi-repo
support per domain.

P1 — Domain as a DB entity:
- Migration b1c2d3e4f5a6: creates `domains` table, migrates topics.domain
  ENUM column to domain_id FK, drops the domain ENUM type
- Domain ORM model (api/models/domain.py) + Pydantic schemas
- Domain API router: GET/POST /domains/, GET/PATCH /domains/{slug}/,
  rename and archive endpoints with EP/TD cascade on rename
- Topic model updated: domain_id FK + @property domain_slug for
  backwards-compatible JSON serialization (field renamed domain → domain_slug)
- TopicCreate/TopicRead updated; seed.py rewritten to use FK lookup

P2 — Multi-repo support:
- ManagedRepo ORM model (api/models/managed_repo.py) + schemas
- Repo API router: GET/POST /repos/, GET/PATCH /repos/{slug}/, archive
- Makefile: add-domain, rename-domain, add-repo, list-repos targets
- register_project.sh: verify domain via /domains/ API + POST /repos/

P3 — MCP tools & live validation:
- 6 new MCP tools: list_domains, create_domain, rename_domain,
  archive_domain, list_domain_repos, register_repo
- EP/TD routers: replace hardcoded VALID_DOMAINS set with per-request
  DB lookup — returns 422 with list of valid slugs on unknown domain
- State summary: adds domains: list[DomainSummary] (slug, name,
  repo_count, active_workstream_count, ep_count, td_count)
- TOOLS.md updated with domain management section

P4 — Dashboard:
- New domains.md page with KPI row + domain cards + repo lists
- domains.json.py + repos.json.py data loaders
- Domains page added to observablehq.config.js nav
- workstreams.md, extensions.md, techdept.md: domain_slug fix +
  dynamic domain list loaded from /domains/ API (no longer hardcoded)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 15:20:15 +01:00
parent c3efb099f1
commit fcd0f06536
29 changed files with 1192 additions and 73 deletions

61
api/schemas/domain.py Normal file
View File

@@ -0,0 +1,61 @@
import uuid
from datetime import datetime
from pydantic import BaseModel, ConfigDict
class DomainCreate(BaseModel):
slug: str
name: str
description: str | None = None
class DomainUpdate(BaseModel):
name: str | None = None
description: str | None = None
status: str | None = None
class DomainRename(BaseModel):
new_slug: str
new_name: str
class RepoStub(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: uuid.UUID
slug: str
name: str
local_path: str | None = None
remote_url: str | None = None
status: str
class DomainRead(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: uuid.UUID
slug: str
name: str
description: str | None = None
status: str
created_at: datetime
updated_at: datetime
class DomainDetail(DomainRead):
"""Domain with entity counts and repo list."""
topic_count: int = 0
workstream_count: int = 0
ep_count: int = 0
td_count: int = 0
repos: list[RepoStub] = []
class DomainSummary(BaseModel):
"""Lightweight domain stats for the state summary."""
slug: str
name: str
repo_count: int = 0
active_workstream_count: int = 0
ep_count: int = 0
td_count: int = 0

View File

@@ -5,10 +5,6 @@ from pydantic import BaseModel, ConfigDict
from api.models.extension_point import EPStatus
VALID_DOMAINS = {
"custodian", "railiance", "markitect",
"coulomb_social", "personhood", "foerster_capabilities",
}
VALID_PRIORITIES = {"low", "medium", "high", "critical"}

View File

@@ -0,0 +1,37 @@
import uuid
from datetime import datetime
from pydantic import BaseModel, ConfigDict
class RepoCreate(BaseModel):
domain_slug: str
slug: str
name: str
local_path: str | None = None
remote_url: str | None = None
description: str | None = None
topic_id: uuid.UUID | None = None
class RepoUpdate(BaseModel):
name: str | None = None
local_path: str | None = None
remote_url: str | None = None
description: str | None = None
topic_id: uuid.UUID | None = None
class RepoRead(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: uuid.UUID
domain_id: uuid.UUID
slug: str
name: str
local_path: str | None = None
remote_url: str | None = None
description: str | None = None
status: str
topic_id: uuid.UUID | None = None
created_at: datetime
updated_at: datetime

View File

@@ -4,6 +4,7 @@ from datetime import datetime
from pydantic import BaseModel
from api.schemas.decision import DecisionRead
from api.schemas.domain import DomainSummary
from api.schemas.progress_event import ProgressEventRead
from api.schemas.task import TaskRead
from api.schemas.topic import TopicWithWorkstreams
@@ -75,3 +76,4 @@ class StateSummary(BaseModel):
recent_progress: list[ProgressEventRead]
open_workstreams: list[WorkstreamWithDeps]
next_steps: list[NextStep] = []
domains: list[DomainSummary] = []

View File

@@ -3,22 +3,22 @@ from datetime import datetime
from pydantic import BaseModel, ConfigDict
from api.models.topic import Domain, TopicStatus
from api.models.topic import TopicStatus
class TopicCreate(BaseModel):
slug: str
title: str
description: str | None = None
domain: Domain
domain: str # domain slug — resolved to domain_id in the router
status: TopicStatus = TopicStatus.active
class TopicUpdate(BaseModel):
title: str | None = None
description: str | None = None
domain: Domain | None = None
status: TopicStatus | None = None
domain: str | None = None # domain slug — resolved to domain_id in the router
class WorkstreamStub(BaseModel):
@@ -37,7 +37,7 @@ class TopicRead(BaseModel):
slug: str
title: str
description: str | None = None
domain: Domain
domain_slug: str | None = None # resolved from FK relationship via @property
status: TopicStatus
created_at: datetime
updated_at: datetime