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
|
|
|
|
|
from datetime import date, datetime
|
2026-03-04 19:44:14 +01:00
|
|
|
from typing import Self
|
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-26 01:32:50 +02:00
|
|
|
from pydantic import BaseModel, ConfigDict, field_validator, model_validator
|
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 api.models.task import TaskPriority, TaskStatus
|
2026-06-22 13:52:13 +02:00
|
|
|
from api.schemas.compat import WorkplanIdCompatMixin, WorkplanIdCreateMixin
|
2026-05-26 01:32:50 +02:00
|
|
|
from api.task_status import normalize_task_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
|
|
|
|
|
|
|
|
|
2026-05-26 01:32:50 +02:00
|
|
|
class TaskStatusMixin(BaseModel):
|
|
|
|
|
@field_validator("status", mode="before", check_fields=False)
|
|
|
|
|
@classmethod
|
|
|
|
|
def _normalize_status(cls, value):
|
|
|
|
|
if value is None:
|
|
|
|
|
return value
|
|
|
|
|
return normalize_task_status(value)
|
|
|
|
|
|
|
|
|
|
|
2026-06-22 13:52:13 +02:00
|
|
|
class TaskCreate(TaskStatusMixin, WorkplanIdCreateMixin):
|
2026-08-22 09:43:55 +02:00
|
|
|
id: uuid.UUID | None = None
|
2026-08-30 22:38:54 +02:00
|
|
|
record_id: 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
|
|
|
title: str
|
|
|
|
|
description: str | None = None
|
|
|
|
|
status: TaskStatus = TaskStatus.todo
|
|
|
|
|
priority: TaskPriority = TaskPriority.medium
|
|
|
|
|
assignee: str | None = None
|
|
|
|
|
due_date: date | None = None
|
|
|
|
|
blocking_reason: str | None = None
|
2026-03-04 19:44:14 +01:00
|
|
|
needs_human: bool = False
|
|
|
|
|
intervention_note: 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
|
|
|
parent_task_id: uuid.UUID | None = None
|
|
|
|
|
|
2026-03-04 19:44:14 +01:00
|
|
|
@model_validator(mode="after")
|
|
|
|
|
def intervention_note_required_when_flagged(self) -> Self:
|
|
|
|
|
if self.needs_human and not self.intervention_note:
|
|
|
|
|
raise ValueError("intervention_note is required when needs_human is True")
|
|
|
|
|
return self
|
|
|
|
|
|
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-26 01:32:50 +02:00
|
|
|
class TaskUpdate(TaskStatusMixin):
|
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
|
|
|
title: str | None = None
|
|
|
|
|
description: str | None = None
|
|
|
|
|
status: TaskStatus | None = None
|
|
|
|
|
priority: TaskPriority | None = None
|
|
|
|
|
assignee: str | None = None
|
|
|
|
|
due_date: date | None = None
|
|
|
|
|
blocking_reason: str | None = None
|
2026-03-04 19:44:14 +01:00
|
|
|
needs_human: bool | None = None
|
|
|
|
|
intervention_note: 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
|
|
|
parent_task_id: uuid.UUID | None = None
|
2026-03-29 18:28:18 +02:00
|
|
|
# Token passthrough — three tiers (highest precision wins):
|
2026-03-29 18:47:40 +02:00
|
|
|
# 1. tokens_in + tokens_out → exact counts; note defaults to "measured"
|
2026-03-29 18:28:18 +02:00
|
|
|
# 2. workplan_tokens_in + workplan_tokens_out → prorated across task count (note="workplan")
|
|
|
|
|
# 3. neither provided, status=done → heuristic 1000/500 (note="heuristic")
|
2026-03-29 18:47:40 +02:00
|
|
|
# token_note overrides the auto-assigned note for Tier 1 only (e.g. "userbased")
|
2026-05-23 13:59:05 +02:00
|
|
|
# suppress_token_event lets file/cache sync update status without recording usage.
|
feat(token-tracking): record AI token consumption per task (CUST-WP-0029)
Introduces end-to-end token consumption tracking so agent work is
visible as a cost/effort metric alongside tasks and workplans.
- Migration o2j3k4l5m6n7: token_events table with FK indexes on
task_id, workstream_id, repo_id, created_at
- ORM model, Pydantic schemas (TokenEventCreate, TokenEventRead with
computed tokens_total, TokenSummary)
- Router: POST /token-events/, GET /token-events/ (7 filters),
GET /token-events/summary/ (task|workstream|repo|commit|release scope)
- MCP tools: record_token_event, get_token_summary (formatted table)
- update_task_status enriched with optional tokens_in/tokens_out
passthrough — one call creates status update + token event
- Dashboard token-cost.md page: by-repo bar, by-workplan table,
by-model bar, top-10 tasks by tokens
- ralph-workplan skill updated with token reporting guidance and
per-task heuristics for estimating counts
- Tests: test_token_events.py + test_token_passthrough.py (182 pass)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-29 17:46:46 +02:00
|
|
|
tokens_in: int | None = None
|
|
|
|
|
tokens_out: int | None = None
|
2026-03-29 18:28:18 +02:00
|
|
|
workplan_tokens_in: int | None = None
|
|
|
|
|
workplan_tokens_out: int | None = None
|
2026-03-29 18:47:40 +02:00
|
|
|
token_note: str | None = None
|
feat(token-tracking): record AI token consumption per task (CUST-WP-0029)
Introduces end-to-end token consumption tracking so agent work is
visible as a cost/effort metric alongside tasks and workplans.
- Migration o2j3k4l5m6n7: token_events table with FK indexes on
task_id, workstream_id, repo_id, created_at
- ORM model, Pydantic schemas (TokenEventCreate, TokenEventRead with
computed tokens_total, TokenSummary)
- Router: POST /token-events/, GET /token-events/ (7 filters),
GET /token-events/summary/ (task|workstream|repo|commit|release scope)
- MCP tools: record_token_event, get_token_summary (formatted table)
- update_task_status enriched with optional tokens_in/tokens_out
passthrough — one call creates status update + token event
- Dashboard token-cost.md page: by-repo bar, by-workplan table,
by-model bar, top-10 tasks by tokens
- ralph-workplan skill updated with token reporting guidance and
per-task heuristics for estimating counts
- Tests: test_token_events.py + test_token_passthrough.py (182 pass)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-29 17:46:46 +02:00
|
|
|
model: str | None = None
|
|
|
|
|
agent: str | None = None
|
|
|
|
|
session_id: str | None = None
|
2026-05-23 13:59:05 +02:00
|
|
|
suppress_token_event: bool | 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
|
|
|
|
|
|
|
|
@model_validator(mode="after")
|
2026-05-26 01:32:50 +02:00
|
|
|
def blocking_reason_required_when_human_waiting(self) -> Self:
|
|
|
|
|
if self.status == TaskStatus.wait and self.needs_human and not self.blocking_reason:
|
|
|
|
|
raise ValueError("blocking_reason is required when a human-blocked task is waiting")
|
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
|
|
|
return self
|
|
|
|
|
|
2026-03-04 19:44:14 +01:00
|
|
|
@model_validator(mode="after")
|
|
|
|
|
def intervention_note_required_when_flagged(self) -> Self:
|
|
|
|
|
if self.needs_human and not self.intervention_note:
|
|
|
|
|
raise ValueError("intervention_note is required when needs_human is True")
|
|
|
|
|
return self
|
|
|
|
|
|
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-06-07 20:11:07 +02:00
|
|
|
class TaskStatusBulkUpdate(TaskStatusMixin):
|
|
|
|
|
task_id: uuid.UUID
|
|
|
|
|
status: TaskStatus
|
|
|
|
|
blocking_reason: str | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TaskStatusBulkSync(BaseModel):
|
|
|
|
|
updates: list[TaskStatusBulkUpdate]
|
|
|
|
|
author: str | None = "custodian"
|
|
|
|
|
session_id: str | None = None
|
|
|
|
|
|
|
|
|
|
@field_validator("updates")
|
|
|
|
|
@classmethod
|
|
|
|
|
def updates_required(cls, value: list[TaskStatusBulkUpdate]):
|
|
|
|
|
if not value:
|
|
|
|
|
raise ValueError("at least one task status update is required")
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
2026-06-22 13:52:13 +02:00
|
|
|
class TaskRead(TaskStatusMixin, WorkplanIdCompatMixin):
|
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
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
id: uuid.UUID
|
2026-08-30 22:38:54 +02:00
|
|
|
record_id: 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
|
|
|
title: str
|
|
|
|
|
description: str | None = None
|
|
|
|
|
status: TaskStatus
|
|
|
|
|
priority: TaskPriority
|
|
|
|
|
assignee: str | None = None
|
|
|
|
|
due_date: date | None = None
|
|
|
|
|
blocking_reason: str | None = None
|
2026-03-04 19:44:14 +01:00
|
|
|
needs_human: bool
|
|
|
|
|
intervention_note: 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
|
|
|
parent_task_id: uuid.UUID | None = None
|
|
|
|
|
created_at: datetime
|
|
|
|
|
updated_at: datetime
|
2026-06-06 00:42:00 +02:00
|
|
|
|
|
|
|
|
|
2026-06-22 13:52:13 +02:00
|
|
|
class TaskCountRead(TaskStatusMixin, WorkplanIdCompatMixin):
|
2026-06-06 00:42:00 +02:00
|
|
|
status: TaskStatus
|
|
|
|
|
count: int
|
2026-06-07 20:11:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TaskStatusBulkSyncRead(BaseModel):
|
|
|
|
|
updated: list[TaskRead]
|
|
|
|
|
progress_event_ids: list[uuid.UUID]
|