Files
claudetools/api/routers/coord_work_items.py
Mike Swanson 63975284f4 feat: agent coordination system (workflows, locks, components, messages)
Adds /api/coord/* endpoints for real-time cross-session coordination:
- coord_workflows: named units of work per project
- coord_work_items: tasks within workflows with dependency chains
- coord_session_locks: exclusive resource locks with auto-expiry (TTL)
- coord_component_states: live component state per project (upsert)
- coord_messages: cross-session messaging and broadcasts
- /api/coord/status: cross-project snapshot endpoint

Replaces PROJECT_STATE.md as the coordination layer for Claude sessions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 08:25:33 -07:00

87 lines
2.8 KiB
Python

"""Coordination work items router."""
from uuid import UUID
from fastapi import APIRouter, Depends, Query, status
from sqlalchemy.orm import Session
from api.database import get_db
from api.middleware.auth import get_current_user
from api.schemas.coord_work_item import CoordWorkItemCreate, CoordWorkItemResponse, CoordWorkItemUpdate
from api.services import coord_work_item_service
router = APIRouter()
@router.get("", response_model=dict, status_code=status.HTTP_200_OK)
def list_work_items(
workflow_id: str | None = Query(default=None),
project_key: str | None = Query(default=None),
status_filter: str | None = Query(default=None),
assigned_session: str | None = Query(default=None),
skip: int = Query(default=0, ge=0),
limit: int = Query(default=100, ge=1, le=1000),
db: Session = Depends(get_db),
current_user: dict = Depends(get_current_user),
):
"""List work items with optional filters."""
items, total = coord_work_item_service.get_work_items(
db,
workflow_id=workflow_id,
project_key=project_key,
status_filter=status_filter,
assigned_session=assigned_session,
skip=skip,
limit=limit,
)
return {
"total": total,
"skip": skip,
"limit": limit,
"work_items": [CoordWorkItemResponse.model_validate(i) for i in items],
}
@router.post("", response_model=CoordWorkItemResponse, status_code=status.HTTP_201_CREATED)
def create_work_item(
data: CoordWorkItemCreate,
db: Session = Depends(get_db),
current_user: dict = Depends(get_current_user),
):
"""Create a new work item within a workflow."""
item = coord_work_item_service.create_work_item(db, data)
return CoordWorkItemResponse.model_validate(item)
@router.get("/{item_id}", response_model=CoordWorkItemResponse, status_code=status.HTTP_200_OK)
def get_work_item(
item_id: UUID,
db: Session = Depends(get_db),
current_user: dict = Depends(get_current_user),
):
"""Get a work item by ID."""
item = coord_work_item_service.get_work_item_by_id(db, item_id)
return CoordWorkItemResponse.model_validate(item)
@router.put("/{item_id}", response_model=CoordWorkItemResponse, status_code=status.HTTP_200_OK)
def update_work_item(
item_id: UUID,
data: CoordWorkItemUpdate,
db: Session = Depends(get_db),
current_user: dict = Depends(get_current_user),
):
"""Update a work item."""
item = coord_work_item_service.update_work_item(db, item_id, data)
return CoordWorkItemResponse.model_validate(item)
@router.delete("/{item_id}", response_model=dict, status_code=status.HTTP_200_OK)
def delete_work_item(
item_id: UUID,
db: Session = Depends(get_db),
current_user: dict = Depends(get_current_user),
):
"""Delete a work item."""
return coord_work_item_service.delete_work_item(db, item_id)