generated from coulomb/repo-seed
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:
@@ -1,33 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
# register_project.sh — register a new project with the Custodian State Hub
|
||||
# register_project.sh — register a project/repo with the Custodian State Hub
|
||||
#
|
||||
# Usage: scripts/register_project.sh <domain> <project_path>
|
||||
# domain: one of custodian|railiance|markitect|coulomb_social|personhood|foerster_capabilities
|
||||
# Usage: scripts/register_project.sh <domain> <project_path> [--additional]
|
||||
# domain: slug of an active domain (e.g. custodian, railiance)
|
||||
# project_path: absolute path to the project directory
|
||||
# --additional: add a second repo to an existing domain; skip CLAUDE.md
|
||||
#
|
||||
# Example:
|
||||
# scripts/register_project.sh railiance /home/worsch/railiance
|
||||
# scripts/register_project.sh railiance /home/worsch/railiance-infra --additional
|
||||
#
|
||||
# What it does:
|
||||
# 1. Verify the API is reachable
|
||||
# 2. Look up the topic ID for the domain
|
||||
# 3. Check that state-hub is in ~/.claude.json; warn if missing
|
||||
# 4. Write $project_path/CLAUDE.md from the template (skip if exists)
|
||||
# 5. POST a progress event recording the registration
|
||||
# 2. Verify the domain exists via GET /domains/{slug}/
|
||||
# 3. Look up the topic ID for the domain (first active topic)
|
||||
# 4. Check that state-hub is in ~/.claude.json; warn if missing
|
||||
# 5. Write $project_path/CLAUDE.md from the template (skip if exists or --additional)
|
||||
# 6. POST to /repos/ to register the repo
|
||||
# 7. POST a progress event recording the registration
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DOMAIN="${1:-}"
|
||||
PROJECT_PATH="${2:-}"
|
||||
ADDITIONAL="${3:-}"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
STATE_HUB_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
API_BASE="${API_BASE:-http://127.0.0.1:8000}"
|
||||
|
||||
# ── Validate args ──────────────────────────────────────────────────────────────
|
||||
if [[ -z "$DOMAIN" || -z "$PROJECT_PATH" ]]; then
|
||||
echo "Usage: $0 <domain> <project_path>"
|
||||
echo " domain: custodian|railiance|markitect|coulomb_social|personhood|foerster_capabilities"
|
||||
echo "Usage: $0 <domain> <project_path> [--additional]"
|
||||
echo " domain: slug of an active domain in the State Hub"
|
||||
echo " project_path: absolute path to project directory"
|
||||
echo " --additional: register a second repo; skip CLAUDE.md generation"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -37,6 +43,7 @@ if [[ ! -d "$PROJECT_PATH" ]]; then
|
||||
fi
|
||||
|
||||
PROJECT_NAME="$(basename "$PROJECT_PATH")"
|
||||
REPO_SLUG="$(echo "$PROJECT_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-\|-$//g')"
|
||||
|
||||
# ── Step 1: API health check ───────────────────────────────────────────────────
|
||||
echo "==> Checking API at $API_BASE ..."
|
||||
@@ -48,14 +55,27 @@ if ! curl -sf "$API_BASE/state/health" > /dev/null; then
|
||||
fi
|
||||
echo " API OK"
|
||||
|
||||
# ── Step 2: Look up topic ID ───────────────────────────────────────────────────
|
||||
# ── Step 2: Verify domain exists ───────────────────────────────────────────────
|
||||
echo "==> Verifying domain '$DOMAIN' ..."
|
||||
DOMAIN_JSON="$(curl -sf "$API_BASE/domains/$DOMAIN/" 2>/dev/null || echo 'NOT_FOUND')"
|
||||
if [[ "$DOMAIN_JSON" == "NOT_FOUND" ]] || echo "$DOMAIN_JSON" | python3 -c "import json,sys; d=json.load(sys.stdin); sys.exit(0 if d.get('slug') else 1)" 2>/dev/null; then
|
||||
if [[ "$DOMAIN_JSON" == "NOT_FOUND" ]] || ! echo "$DOMAIN_JSON" | python3 -c "import json,sys; d=json.load(sys.stdin); sys.exit(0 if d.get('slug') else 1)" 2>/dev/null; then
|
||||
echo "ERROR: Domain '$DOMAIN' not found in the State Hub."
|
||||
echo " To create: make add-domain DOMAIN=$DOMAIN NAME=\"<display name>\""
|
||||
echo " To list available: curl -s $API_BASE/domains/ | python3 -m json.tool"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
echo " Domain OK"
|
||||
|
||||
# ── Step 3: Look up topic ID ───────────────────────────────────────────────────
|
||||
echo "==> Looking up topic for domain '$DOMAIN' ..."
|
||||
TOPICS_JSON="$(curl -sf "$API_BASE/topics/?status=active")"
|
||||
|
||||
TOPIC_ID="$(echo "$TOPICS_JSON" | python3 -c "
|
||||
import json, sys
|
||||
topics = json.load(sys.stdin)
|
||||
match = next((t for t in topics if t.get('domain') == sys.argv[1]), None)
|
||||
match = next((t for t in topics if t.get('domain_slug') == sys.argv[1]), None)
|
||||
if not match:
|
||||
print('NOT_FOUND')
|
||||
else:
|
||||
@@ -63,13 +83,13 @@ else:
|
||||
" "$DOMAIN")"
|
||||
|
||||
if [[ "$TOPIC_ID" == "NOT_FOUND" ]]; then
|
||||
echo "ERROR: No active topic found for domain '$DOMAIN'."
|
||||
echo " Known domains: custodian railiance markitect coulomb_social personhood foerster_capabilities"
|
||||
exit 1
|
||||
echo "WARNING: No active topic found for domain '$DOMAIN'. CLAUDE.md will omit topic_id."
|
||||
TOPIC_ID=""
|
||||
else
|
||||
echo " topic_id: $TOPIC_ID"
|
||||
fi
|
||||
echo " topic_id: $TOPIC_ID"
|
||||
|
||||
# ── Step 3: Check MCP registration ────────────────────────────────────────────
|
||||
# ── Step 4: Check MCP registration ────────────────────────────────────────────
|
||||
echo "==> Checking MCP server registration ..."
|
||||
MCP_OK="$(python3 -c "
|
||||
import json
|
||||
@@ -85,10 +105,6 @@ else:
|
||||
|
||||
if [[ "$MCP_OK" == "MISSING_FILE" ]]; then
|
||||
echo "WARNING: ~/.claude.json not found. MCP server is not registered."
|
||||
echo " To register:"
|
||||
echo " MСPCFG=\$(cat $STATE_HUB_DIR/../.mcp.json | python3 -c \"import json,sys; print(json.dumps(json.load(sys.stdin)['mcpServers']['state-hub']))\")"
|
||||
echo " claude mcp add-json -s user state-hub \"\$MCPCFG\""
|
||||
echo " python3 $SCRIPT_DIR/patch_mcp_cwd.py"
|
||||
elif [[ "$MCP_OK" == "NOT_REGISTERED" ]]; then
|
||||
echo "WARNING: 'state-hub' not found in ~/.claude.json."
|
||||
echo " To register, see CLAUDE.md MCP Server Registration section."
|
||||
@@ -96,11 +112,13 @@ else
|
||||
echo " MCP OK"
|
||||
fi
|
||||
|
||||
# ── Step 4: Write CLAUDE.md ────────────────────────────────────────────────────
|
||||
# ── Step 5: Write CLAUDE.md ────────────────────────────────────────────────────
|
||||
CLAUDE_MD="$PROJECT_PATH/CLAUDE.md"
|
||||
TEMPLATE="$SCRIPT_DIR/project_claude_md.template"
|
||||
|
||||
if [[ -f "$CLAUDE_MD" ]]; then
|
||||
if [[ "$ADDITIONAL" == "--additional" ]]; then
|
||||
echo "==> --additional flag: skipping CLAUDE.md (already exists for this domain)."
|
||||
elif [[ -f "$CLAUDE_MD" ]]; then
|
||||
echo "==> CLAUDE.md already exists at $CLAUDE_MD — skipping."
|
||||
else
|
||||
echo "==> Writing CLAUDE.md to $CLAUDE_MD ..."
|
||||
@@ -112,12 +130,35 @@ else
|
||||
echo " Written."
|
||||
fi
|
||||
|
||||
# ── Step 5: Record progress event ─────────────────────────────────────────────
|
||||
# ── Step 6: Register repo in State Hub ────────────────────────────────────────
|
||||
echo "==> Registering repo '$PROJECT_NAME' under domain '$DOMAIN' ..."
|
||||
REPO_PAYLOAD="$(python3 -c "
|
||||
import json
|
||||
payload = {
|
||||
'domain_slug': '$DOMAIN',
|
||||
'slug': '$REPO_SLUG',
|
||||
'name': '$PROJECT_NAME',
|
||||
'local_path': '$PROJECT_PATH',
|
||||
}
|
||||
print(json.dumps(payload))
|
||||
")"
|
||||
|
||||
REPO_RESULT="$(curl -sf -X POST "$API_BASE/repos/" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$REPO_PAYLOAD" 2>/dev/null || echo 'REPO_EXISTS')"
|
||||
|
||||
if [[ "$REPO_RESULT" == "REPO_EXISTS" ]]; then
|
||||
echo " Repo '$REPO_SLUG' already registered (or slug conflict) — skipping."
|
||||
else
|
||||
echo " Repo registered: $REPO_SLUG"
|
||||
fi
|
||||
|
||||
# ── Step 7: Record progress event ─────────────────────────────────────────────
|
||||
echo "==> Recording registration event ..."
|
||||
EVENT_JSON="$(python3 -c "
|
||||
import json
|
||||
payload = {
|
||||
'topic_id': '$TOPIC_ID',
|
||||
$([ -n '$TOPIC_ID' ] && echo "'topic_id': '$TOPIC_ID',")
|
||||
'event_type': 'milestone',
|
||||
'summary': 'Project registered with State Hub: $PROJECT_NAME ($DOMAIN)',
|
||||
'author': 'custodian',
|
||||
@@ -125,6 +166,7 @@ payload = {
|
||||
'project_path': '$PROJECT_PATH',
|
||||
'claude_md': '$CLAUDE_MD',
|
||||
'domain': '$DOMAIN',
|
||||
'repo_slug': '$REPO_SLUG',
|
||||
},
|
||||
}
|
||||
print(json.dumps(payload))
|
||||
@@ -139,7 +181,8 @@ echo ""
|
||||
echo "Registration complete!"
|
||||
echo " Project: $PROJECT_NAME"
|
||||
echo " Domain: $DOMAIN"
|
||||
echo " Topic ID: $TOPIC_ID"
|
||||
echo " Repo slug: $REPO_SLUG"
|
||||
[[ -n "$TOPIC_ID" ]] && echo " Topic ID: $TOPIC_ID"
|
||||
echo " CLAUDE.md: $CLAUDE_MD"
|
||||
echo ""
|
||||
echo "Next: restart Claude Code for the MCP server to be available in this project."
|
||||
|
||||
@@ -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.")
|
||||
|
||||
Reference in New Issue
Block a user