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

View File

@@ -1,4 +1,4 @@
"""Seed the 6 canonical topics from canon/projects/."""
"""Seed the 6 canonical domains and topics from canon/projects/."""
import asyncio
import sys
from pathlib import Path
@@ -10,7 +10,17 @@ from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from api.database import async_session_factory, engine
from api.models.topic import Domain, Topic, TopicStatus
from api.models.domain import Domain
from api.models.topic import Topic, TopicStatus
DOMAINS = [
{"slug": "custodian", "name": "The Custodian"},
{"slug": "railiance", "name": "Railiance"},
{"slug": "markitect", "name": "Markitect"},
{"slug": "coulomb_social", "name": "Coulomb.social"},
{"slug": "personhood", "name": "Personhood"},
{"slug": "foerster_capabilities", "name": "Foerster Capabilities"},
]
TOPICS = [
{
@@ -20,7 +30,7 @@ TOPICS = [
"Master agent system: transgenerational cognitive infrastructure for "
"co-creating and stewarding knowledge across all domains."
),
"domain": Domain.custodian,
"domain_slug": "custodian",
},
{
"slug": "railiance",
@@ -29,7 +39,7 @@ TOPICS = [
"DevOps & infrastructure reliability. Dependency for all other projects; "
"provides the deployment and operational backbone."
),
"domain": Domain.railiance,
"domain_slug": "railiance",
},
{
"slug": "markitect",
@@ -38,7 +48,7 @@ TOPICS = [
"Knowledge artifact management: structured authoring, versioning, and "
"retrieval of canonical documents."
),
"domain": Domain.markitect,
"domain_slug": "markitect",
},
{
"slug": "coulomb-social",
@@ -47,7 +57,7 @@ TOPICS = [
"Co-creation marketplace experiment: connecting people around shared "
"projects and complementary capabilities."
),
"domain": Domain.coulomb_social,
"domain_slug": "coulomb_social",
},
{
"slug": "personhood",
@@ -56,7 +66,7 @@ TOPICS = [
"Rights and obligations framework: defining digital personhood, consent "
"models, and data sovereignty."
),
"domain": Domain.personhood,
"domain_slug": "personhood",
},
{
"slug": "foerster-capabilities",
@@ -65,29 +75,48 @@ TOPICS = [
"Agency capability taxonomy inspired by Heinz von Foerster: mapping the "
"space of possible cognitive and social actions."
),
"domain": Domain.foerster_capabilities,
"domain_slug": "foerster_capabilities",
},
]
async def seed() -> None:
async with async_session_factory() as session:
# ── Insert domains (idempotent) ───────────────────────────────────────
domain_by_slug: dict[str, Domain] = {}
for data in DOMAINS:
existing = await session.execute(
select(Domain).where(Domain.slug == data["slug"])
)
domain = existing.scalar_one_or_none()
if domain is not None:
print(f" skip domain (exists): {data['slug']}")
else:
domain = Domain(slug=data["slug"], name=data["name"])
session.add(domain)
await session.flush() # get the id
print(f" insert domain: {data['slug']}")
domain_by_slug[data["slug"]] = domain
# ── Insert topics (idempotent) ─────────────────────────────────────────
for data in TOPICS:
existing = await session.execute(
select(Topic).where(Topic.slug == data["slug"])
)
if existing.scalar_one_or_none() is not None:
print(f" skip (already exists): {data['slug']}")
print(f" skip topic (exists): {data['slug']}")
continue
domain = domain_by_slug[data["domain_slug"]]
topic = Topic(
slug=data["slug"],
title=data["title"],
description=data["description"],
domain=data["domain"],
domain_id=domain.id,
status=TopicStatus.active,
)
session.add(topic)
print(f" insert: {data['slug']}")
print(f" insert topic: {data['slug']}")
await session.commit()
await engine.dispose()
print("Seed complete.")