Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
import uuid
|
2026-05-02 12:01:45 +02:00
|
|
|
import socket
|
perf(api): CUST-WP-0041 — DB indexes, TTL caches, noload on list endpoints
- Migration t7o8p9q0r1s2: indexes on tasks.status, tasks(workstream_id,status),
workstreams.status, sbom_snapshots(repo_id,snapshot_at)
- workplan-index: 30 s TTL cache + ?refresh param (4171 ms → 16 ms on hit)
- /state/summary: 15 s TTL cache, bypassed on Cache-Control: no-cache
- /topics/: noload(workstreams, decisions, progress_events) (2382 ms → 115 ms)
- /domains/: noload(topics, repos, goals) (2252 ms → 39 ms)
- /repos/: noload(goals) (2222 ms → 599 ms first / fast on repeat)
- conftest: reset TTL caches between tests to prevent bleed-through
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:12:17 +02:00
|
|
|
import time
|
2026-05-02 12:01:45 +02:00
|
|
|
from pathlib import Path
|
|
|
|
|
from typing import Any
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
|
perf(api): CUST-WP-0041 — DB indexes, TTL caches, noload on list endpoints
- Migration t7o8p9q0r1s2: indexes on tasks.status, tasks(workstream_id,status),
workstreams.status, sbom_snapshots(repo_id,snapshot_at)
- workplan-index: 30 s TTL cache + ?refresh param (4171 ms → 16 ms on hit)
- /state/summary: 15 s TTL cache, bypassed on Cache-Control: no-cache
- /topics/: noload(workstreams, decisions, progress_events) (2382 ms → 115 ms)
- /domains/: noload(topics, repos, goals) (2252 ms → 39 ms)
- /repos/: noload(goals) (2222 ms → 599 ms first / fast on repeat)
- conftest: reset TTL caches between tests to prevent bleed-through
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:12:17 +02:00
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
from sqlalchemy import select
|
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
|
|
|
|
|
from api.database import get_session
|
2026-05-02 12:01:45 +02:00
|
|
|
from api.models.managed_repo import ManagedRepo
|
2026-05-02 00:21:14 +02:00
|
|
|
from api.models.workstream import Workstream
|
|
|
|
|
from api.schemas.workstream import (
|
|
|
|
|
WorkstreamCreate,
|
|
|
|
|
WorkstreamRead,
|
|
|
|
|
WorkstreamStatus,
|
|
|
|
|
WorkstreamUpdate,
|
|
|
|
|
)
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/workstreams", tags=["workstreams"])
|
|
|
|
|
|
perf(api): CUST-WP-0041 — DB indexes, TTL caches, noload on list endpoints
- Migration t7o8p9q0r1s2: indexes on tasks.status, tasks(workstream_id,status),
workstreams.status, sbom_snapshots(repo_id,snapshot_at)
- workplan-index: 30 s TTL cache + ?refresh param (4171 ms → 16 ms on hit)
- /state/summary: 15 s TTL cache, bypassed on Cache-Control: no-cache
- /topics/: noload(workstreams, decisions, progress_events) (2382 ms → 115 ms)
- /domains/: noload(topics, repos, goals) (2252 ms → 39 ms)
- /repos/: noload(goals) (2222 ms → 599 ms first / fast on repeat)
- conftest: reset TTL caches between tests to prevent bleed-through
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:12:17 +02:00
|
|
|
_INDEX_CACHE: dict[str, Any] | None = None
|
|
|
|
|
_INDEX_CACHE_AT: float = 0.0
|
|
|
|
|
_INDEX_TTL = 30.0
|
|
|
|
|
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
|
2026-05-02 12:01:45 +02:00
|
|
|
def _repo_path(repo: ManagedRepo) -> Path | None:
|
|
|
|
|
hostname = socket.gethostname()
|
|
|
|
|
candidates = []
|
|
|
|
|
host_paths = repo.host_paths or {}
|
|
|
|
|
if host_paths.get(hostname):
|
|
|
|
|
candidates.append(host_paths[hostname])
|
|
|
|
|
if repo.local_path:
|
|
|
|
|
candidates.append(repo.local_path)
|
|
|
|
|
for raw in candidates:
|
|
|
|
|
path = Path(raw).expanduser()
|
|
|
|
|
if path.is_dir():
|
|
|
|
|
return path
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _frontmatter(path: Path) -> dict[str, Any]:
|
|
|
|
|
try:
|
|
|
|
|
text = path.read_text(encoding="utf-8")
|
|
|
|
|
except OSError:
|
|
|
|
|
return {}
|
|
|
|
|
if not text.startswith("---\n"):
|
|
|
|
|
return {}
|
|
|
|
|
end = text.find("\n---", 4)
|
|
|
|
|
if end == -1:
|
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
data: dict[str, Any] = {}
|
|
|
|
|
for raw_line in text[4:end].splitlines():
|
|
|
|
|
line = raw_line.strip()
|
|
|
|
|
if not line or line.startswith("#") or ":" not in line:
|
|
|
|
|
continue
|
|
|
|
|
key, value = line.split(":", 1)
|
|
|
|
|
value = value.strip()
|
|
|
|
|
if len(value) >= 2 and value[0] == value[-1] and value[0] in {"'", '"'}:
|
|
|
|
|
value = value[1:-1]
|
|
|
|
|
data[key.strip()] = value
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
@router.get("/", response_model=list[WorkstreamRead])
|
|
|
|
|
async def list_workstreams(
|
|
|
|
|
topic_id: uuid.UUID | None = None,
|
2026-03-02 23:39:17 +01:00
|
|
|
repo_id: uuid.UUID | None = None,
|
feat(goals): add domain/repo goal tracking and update_workstream MCP tool
- Migration c5d6e7f8a9b0: domain_goals and repo_goals tables, repo_goal_id FK on workstreams
- DomainGoal: one active per domain (partial unique index), status active/archived/superseded
- RepoGoal: integer priority, status active/paused/completed/archived, optional domain_goal_id link
- WorkstreamUpdate schema and router extended with repo_goal_id and repo_goal_id filter
- 6 new MCP goal tools: create_domain_goal, get_domain_goals, activate_domain_goal, create_repo_goal, get_repo_goals, update_repo_goal
- update_workstream MCP tool: patch any subset of workstream fields (title, description, owner, due_date, repo_goal_id, status)
- get_domain_summary extended with goal_guidance (needs_workplan, alignment_warnings) signals
- Dashboard goals.md page and docs/goals.md reference page
- CLAUDE.md template updated to act on goal_guidance signals at session start
- CUST-WP-0010 workplan for this feature
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 00:15:29 +01:00
|
|
|
repo_goal_id: uuid.UUID | None = None,
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
status: WorkstreamStatus | None = None,
|
2026-03-18 02:17:04 +01:00
|
|
|
owner: str | None = None,
|
|
|
|
|
slug: str | None = None,
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
session: AsyncSession = Depends(get_session),
|
|
|
|
|
) -> list[Workstream]:
|
|
|
|
|
q = select(Workstream)
|
|
|
|
|
if topic_id:
|
|
|
|
|
q = q.where(Workstream.topic_id == topic_id)
|
2026-03-02 23:39:17 +01:00
|
|
|
if repo_id:
|
|
|
|
|
q = q.where(Workstream.repo_id == repo_id)
|
feat(goals): add domain/repo goal tracking and update_workstream MCP tool
- Migration c5d6e7f8a9b0: domain_goals and repo_goals tables, repo_goal_id FK on workstreams
- DomainGoal: one active per domain (partial unique index), status active/archived/superseded
- RepoGoal: integer priority, status active/paused/completed/archived, optional domain_goal_id link
- WorkstreamUpdate schema and router extended with repo_goal_id and repo_goal_id filter
- 6 new MCP goal tools: create_domain_goal, get_domain_goals, activate_domain_goal, create_repo_goal, get_repo_goals, update_repo_goal
- update_workstream MCP tool: patch any subset of workstream fields (title, description, owner, due_date, repo_goal_id, status)
- get_domain_summary extended with goal_guidance (needs_workplan, alignment_warnings) signals
- Dashboard goals.md page and docs/goals.md reference page
- CLAUDE.md template updated to act on goal_guidance signals at session start
- CUST-WP-0010 workplan for this feature
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 00:15:29 +01:00
|
|
|
if repo_goal_id:
|
|
|
|
|
q = q.where(Workstream.repo_goal_id == repo_goal_id)
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
if status:
|
|
|
|
|
q = q.where(Workstream.status == status)
|
2026-03-18 02:17:04 +01:00
|
|
|
if owner:
|
|
|
|
|
q = q.where(Workstream.owner == owner)
|
|
|
|
|
if slug:
|
|
|
|
|
q = q.where(Workstream.slug == slug)
|
2026-05-04 11:45:24 +02:00
|
|
|
q = q.order_by(
|
|
|
|
|
Workstream.planning_priority.asc().nullslast(),
|
|
|
|
|
Workstream.planning_order.asc().nullslast(),
|
|
|
|
|
Workstream.updated_at.desc(),
|
|
|
|
|
)
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
result = await session.execute(q)
|
|
|
|
|
return list(result.scalars().all())
|
|
|
|
|
|
|
|
|
|
|
2026-05-02 12:01:45 +02:00
|
|
|
@router.get("/workplan-index")
|
perf(api): CUST-WP-0041 — DB indexes, TTL caches, noload on list endpoints
- Migration t7o8p9q0r1s2: indexes on tasks.status, tasks(workstream_id,status),
workstreams.status, sbom_snapshots(repo_id,snapshot_at)
- workplan-index: 30 s TTL cache + ?refresh param (4171 ms → 16 ms on hit)
- /state/summary: 15 s TTL cache, bypassed on Cache-Control: no-cache
- /topics/: noload(workstreams, decisions, progress_events) (2382 ms → 115 ms)
- /domains/: noload(topics, repos, goals) (2252 ms → 39 ms)
- /repos/: noload(goals) (2222 ms → 599 ms first / fast on repeat)
- conftest: reset TTL caches between tests to prevent bleed-through
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:12:17 +02:00
|
|
|
async def workplan_index(
|
|
|
|
|
refresh: bool = Query(False, description="Force cache invalidation"),
|
|
|
|
|
session: AsyncSession = Depends(get_session),
|
|
|
|
|
) -> dict[str, Any]:
|
2026-05-02 12:01:45 +02:00
|
|
|
"""Map file-backed workstream ids to their local workplan filenames."""
|
perf(api): CUST-WP-0041 — DB indexes, TTL caches, noload on list endpoints
- Migration t7o8p9q0r1s2: indexes on tasks.status, tasks(workstream_id,status),
workstreams.status, sbom_snapshots(repo_id,snapshot_at)
- workplan-index: 30 s TTL cache + ?refresh param (4171 ms → 16 ms on hit)
- /state/summary: 15 s TTL cache, bypassed on Cache-Control: no-cache
- /topics/: noload(workstreams, decisions, progress_events) (2382 ms → 115 ms)
- /domains/: noload(topics, repos, goals) (2252 ms → 39 ms)
- /repos/: noload(goals) (2222 ms → 599 ms first / fast on repeat)
- conftest: reset TTL caches between tests to prevent bleed-through
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:12:17 +02:00
|
|
|
global _INDEX_CACHE, _INDEX_CACHE_AT
|
|
|
|
|
if not refresh and _INDEX_CACHE is not None and (time.monotonic() - _INDEX_CACHE_AT) < _INDEX_TTL:
|
|
|
|
|
return _INDEX_CACHE
|
|
|
|
|
|
2026-05-02 12:01:45 +02:00
|
|
|
result = await session.execute(
|
|
|
|
|
select(ManagedRepo).where(ManagedRepo.status == "active").order_by(ManagedRepo.slug)
|
|
|
|
|
)
|
|
|
|
|
index: dict[str, Any] = {}
|
|
|
|
|
for repo in result.scalars().all():
|
|
|
|
|
root = _repo_path(repo)
|
|
|
|
|
if root is None:
|
|
|
|
|
continue
|
|
|
|
|
for directory, archived in (
|
|
|
|
|
(root / "workplans", False),
|
|
|
|
|
(root / "workplans" / "archived", True),
|
|
|
|
|
):
|
|
|
|
|
if not directory.is_dir():
|
|
|
|
|
continue
|
|
|
|
|
for path in sorted(directory.glob("*.md")):
|
|
|
|
|
data = _frontmatter(path)
|
|
|
|
|
workstream_id = data.get("state_hub_workstream_id")
|
|
|
|
|
if not workstream_id:
|
|
|
|
|
continue
|
|
|
|
|
index[str(workstream_id)] = {
|
|
|
|
|
"filename": path.name,
|
|
|
|
|
"relative_path": str(path.relative_to(root)),
|
|
|
|
|
"repo_slug": repo.slug,
|
|
|
|
|
"archived": archived,
|
|
|
|
|
}
|
perf(api): CUST-WP-0041 — DB indexes, TTL caches, noload on list endpoints
- Migration t7o8p9q0r1s2: indexes on tasks.status, tasks(workstream_id,status),
workstreams.status, sbom_snapshots(repo_id,snapshot_at)
- workplan-index: 30 s TTL cache + ?refresh param (4171 ms → 16 ms on hit)
- /state/summary: 15 s TTL cache, bypassed on Cache-Control: no-cache
- /topics/: noload(workstreams, decisions, progress_events) (2382 ms → 115 ms)
- /domains/: noload(topics, repos, goals) (2252 ms → 39 ms)
- /repos/: noload(goals) (2222 ms → 599 ms first / fast on repeat)
- conftest: reset TTL caches between tests to prevent bleed-through
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:12:17 +02:00
|
|
|
_INDEX_CACHE = {"workstreams": index}
|
|
|
|
|
_INDEX_CACHE_AT = time.monotonic()
|
|
|
|
|
return _INDEX_CACHE
|
2026-05-02 12:01:45 +02:00
|
|
|
|
|
|
|
|
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
@router.post("/", response_model=WorkstreamRead, status_code=status.HTTP_201_CREATED)
|
|
|
|
|
async def create_workstream(
|
|
|
|
|
body: WorkstreamCreate,
|
|
|
|
|
session: AsyncSession = Depends(get_session),
|
|
|
|
|
) -> Workstream:
|
|
|
|
|
ws = Workstream(**body.model_dump())
|
|
|
|
|
session.add(ws)
|
|
|
|
|
await session.commit()
|
|
|
|
|
await session.refresh(ws)
|
|
|
|
|
return ws
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/{workstream_id}", response_model=WorkstreamRead)
|
|
|
|
|
async def get_workstream(
|
|
|
|
|
workstream_id: uuid.UUID,
|
|
|
|
|
session: AsyncSession = Depends(get_session),
|
|
|
|
|
) -> Workstream:
|
|
|
|
|
ws = await session.get(Workstream, workstream_id)
|
|
|
|
|
if ws is None:
|
|
|
|
|
raise HTTPException(status_code=404, detail="Workstream not found")
|
|
|
|
|
return ws
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.patch("/{workstream_id}", response_model=WorkstreamRead)
|
|
|
|
|
async def update_workstream(
|
|
|
|
|
workstream_id: uuid.UUID,
|
|
|
|
|
body: WorkstreamUpdate,
|
|
|
|
|
session: AsyncSession = Depends(get_session),
|
|
|
|
|
) -> Workstream:
|
|
|
|
|
ws = await session.get(Workstream, workstream_id)
|
|
|
|
|
if ws is None:
|
|
|
|
|
raise HTTPException(status_code=404, detail="Workstream not found")
|
|
|
|
|
for field, value in body.model_dump(exclude_unset=True).items():
|
|
|
|
|
setattr(ws, field, value)
|
|
|
|
|
await session.commit()
|
|
|
|
|
await session.refresh(ws)
|
|
|
|
|
return ws
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.delete("/{workstream_id}", response_model=WorkstreamRead)
|
|
|
|
|
async def archive_workstream(
|
|
|
|
|
workstream_id: uuid.UUID,
|
|
|
|
|
session: AsyncSession = Depends(get_session),
|
|
|
|
|
) -> Workstream:
|
|
|
|
|
ws = await session.get(Workstream, workstream_id)
|
|
|
|
|
if ws is None:
|
|
|
|
|
raise HTTPException(status_code=404, detail="Workstream not found")
|
2026-05-02 00:21:14 +02:00
|
|
|
ws.status = "archived"
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
await session.commit()
|
|
|
|
|
await session.refresh(ws)
|
|
|
|
|
return ws
|