Implements production-ready MSP platform with cross-machine persistent memory for Claude. API Implementation: - 130 REST API endpoints across 21 entities - JWT authentication on all endpoints - AES-256-GCM encryption for credentials - Automatic audit logging - Complete OpenAPI documentation Database: - 43 tables in MariaDB (172.16.3.20:3306) - 42 SQLAlchemy models with modern 2.0 syntax - Full Alembic migration system - 99.1% CRUD test pass rate Context Recall System (Phase 6): - Cross-machine persistent memory via database - Automatic context injection via Claude Code hooks - Automatic context saving after task completion - 90-95% token reduction with compression utilities - Relevance scoring with time decay - Tag-based semantic search - One-command setup script Security Features: - JWT tokens with Argon2 password hashing - AES-256-GCM encryption for all sensitive data - Comprehensive audit trail for credentials - HMAC tamper detection - Secure configuration management Test Results: - Phase 3: 38/38 CRUD tests passing (100%) - Phase 4: 34/35 core API tests passing (97.1%) - Phase 5: 62/62 extended API tests passing (100%) - Phase 6: 10/10 compression tests passing (100%) - Overall: 144/145 tests passing (99.3%) Documentation: - Comprehensive architecture guides - Setup automation scripts - API documentation at /api/docs - Complete test reports - Troubleshooting guides Project Status: 95% Complete (Production-Ready) Phase 7 (optional work context APIs) remains for future enhancement. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
265 lines
7.1 KiB
Python
265 lines
7.1 KiB
Python
"""
|
|
DecisionLog API router for ClaudeTools.
|
|
|
|
Defines all REST API endpoints for managing decision logs,
|
|
tracking important decisions made during work.
|
|
"""
|
|
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from api.database import get_db
|
|
from api.middleware.auth import get_current_user
|
|
from api.schemas.decision_log import (
|
|
DecisionLogCreate,
|
|
DecisionLogResponse,
|
|
DecisionLogUpdate,
|
|
)
|
|
from api.services import decision_log_service
|
|
|
|
# Create router with prefix and tags
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get(
|
|
"",
|
|
response_model=dict,
|
|
summary="List all decision logs",
|
|
description="Retrieve a paginated list of all decision logs",
|
|
status_code=status.HTTP_200_OK,
|
|
)
|
|
def list_decision_logs(
|
|
skip: int = Query(
|
|
default=0,
|
|
ge=0,
|
|
description="Number of records to skip for pagination"
|
|
),
|
|
limit: int = Query(
|
|
default=100,
|
|
ge=1,
|
|
le=1000,
|
|
description="Maximum number of records to return (max 1000)"
|
|
),
|
|
db: Session = Depends(get_db),
|
|
current_user: dict = Depends(get_current_user),
|
|
):
|
|
"""
|
|
List all decision logs with pagination.
|
|
|
|
Returns decision logs ordered by most recent first.
|
|
"""
|
|
try:
|
|
logs, total = decision_log_service.get_decision_logs(db, skip, limit)
|
|
|
|
return {
|
|
"total": total,
|
|
"skip": skip,
|
|
"limit": limit,
|
|
"logs": [DecisionLogResponse.model_validate(log) for log in logs]
|
|
}
|
|
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
detail=f"Failed to retrieve decision logs: {str(e)}"
|
|
)
|
|
|
|
|
|
@router.get(
|
|
"/by-impact/{impact}",
|
|
response_model=dict,
|
|
summary="Get decision logs by impact level",
|
|
description="Retrieve decision logs filtered by impact level",
|
|
status_code=status.HTTP_200_OK,
|
|
)
|
|
def get_decision_logs_by_impact(
|
|
impact: str,
|
|
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),
|
|
):
|
|
"""
|
|
Get decision logs filtered by impact level.
|
|
|
|
Valid impact levels: low, medium, high, critical
|
|
"""
|
|
try:
|
|
logs, total = decision_log_service.get_decision_logs_by_impact(
|
|
db, impact, skip, limit
|
|
)
|
|
|
|
return {
|
|
"total": total,
|
|
"skip": skip,
|
|
"limit": limit,
|
|
"impact": impact,
|
|
"logs": [DecisionLogResponse.model_validate(log) for log in logs]
|
|
}
|
|
|
|
except HTTPException:
|
|
raise
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
detail=f"Failed to retrieve decision logs: {str(e)}"
|
|
)
|
|
|
|
|
|
@router.get(
|
|
"/by-project/{project_id}",
|
|
response_model=dict,
|
|
summary="Get decision logs by project",
|
|
description="Retrieve all decision logs for a specific project",
|
|
status_code=status.HTTP_200_OK,
|
|
)
|
|
def get_decision_logs_by_project(
|
|
project_id: UUID,
|
|
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),
|
|
):
|
|
"""
|
|
Get all decision logs for a specific project.
|
|
"""
|
|
try:
|
|
logs, total = decision_log_service.get_decision_logs_by_project(
|
|
db, project_id, skip, limit
|
|
)
|
|
|
|
return {
|
|
"total": total,
|
|
"skip": skip,
|
|
"limit": limit,
|
|
"project_id": str(project_id),
|
|
"logs": [DecisionLogResponse.model_validate(log) for log in logs]
|
|
}
|
|
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
detail=f"Failed to retrieve decision logs: {str(e)}"
|
|
)
|
|
|
|
|
|
@router.get(
|
|
"/by-session/{session_id}",
|
|
response_model=dict,
|
|
summary="Get decision logs by session",
|
|
description="Retrieve all decision logs for a specific session",
|
|
status_code=status.HTTP_200_OK,
|
|
)
|
|
def get_decision_logs_by_session(
|
|
session_id: UUID,
|
|
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),
|
|
):
|
|
"""
|
|
Get all decision logs for a specific session.
|
|
"""
|
|
try:
|
|
logs, total = decision_log_service.get_decision_logs_by_session(
|
|
db, session_id, skip, limit
|
|
)
|
|
|
|
return {
|
|
"total": total,
|
|
"skip": skip,
|
|
"limit": limit,
|
|
"session_id": str(session_id),
|
|
"logs": [DecisionLogResponse.model_validate(log) for log in logs]
|
|
}
|
|
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
detail=f"Failed to retrieve decision logs: {str(e)}"
|
|
)
|
|
|
|
|
|
@router.get(
|
|
"/{log_id}",
|
|
response_model=DecisionLogResponse,
|
|
summary="Get decision log by ID",
|
|
description="Retrieve a single decision log by its unique identifier",
|
|
status_code=status.HTTP_200_OK,
|
|
)
|
|
def get_decision_log(
|
|
log_id: UUID,
|
|
db: Session = Depends(get_db),
|
|
current_user: dict = Depends(get_current_user),
|
|
):
|
|
"""
|
|
Get a specific decision log by ID.
|
|
"""
|
|
log = decision_log_service.get_decision_log_by_id(db, log_id)
|
|
return DecisionLogResponse.model_validate(log)
|
|
|
|
|
|
@router.post(
|
|
"",
|
|
response_model=DecisionLogResponse,
|
|
summary="Create new decision log",
|
|
description="Create a new decision log with the provided details",
|
|
status_code=status.HTTP_201_CREATED,
|
|
)
|
|
def create_decision_log(
|
|
log_data: DecisionLogCreate,
|
|
db: Session = Depends(get_db),
|
|
current_user: dict = Depends(get_current_user),
|
|
):
|
|
"""
|
|
Create a new decision log.
|
|
|
|
Requires a valid JWT token with appropriate permissions.
|
|
"""
|
|
log = decision_log_service.create_decision_log(db, log_data)
|
|
return DecisionLogResponse.model_validate(log)
|
|
|
|
|
|
@router.put(
|
|
"/{log_id}",
|
|
response_model=DecisionLogResponse,
|
|
summary="Update decision log",
|
|
description="Update an existing decision log's details",
|
|
status_code=status.HTTP_200_OK,
|
|
)
|
|
def update_decision_log(
|
|
log_id: UUID,
|
|
log_data: DecisionLogUpdate,
|
|
db: Session = Depends(get_db),
|
|
current_user: dict = Depends(get_current_user),
|
|
):
|
|
"""
|
|
Update an existing decision log.
|
|
|
|
Only provided fields will be updated. All fields are optional.
|
|
"""
|
|
log = decision_log_service.update_decision_log(db, log_id, log_data)
|
|
return DecisionLogResponse.model_validate(log)
|
|
|
|
|
|
@router.delete(
|
|
"/{log_id}",
|
|
response_model=dict,
|
|
summary="Delete decision log",
|
|
description="Delete a decision log by its ID",
|
|
status_code=status.HTTP_200_OK,
|
|
)
|
|
def delete_decision_log(
|
|
log_id: UUID,
|
|
db: Session = Depends(get_db),
|
|
current_user: dict = Depends(get_current_user),
|
|
):
|
|
"""
|
|
Delete a decision log.
|
|
|
|
This is a permanent operation and cannot be undone.
|
|
"""
|
|
return decision_log_service.delete_decision_log(db, log_id)
|