from fastapi import APIRouter from analysis.failure_autopsy import FailureAutopsy router = APIRouter() # in real system this comes from your engine/session store ENGINE_REGISTRY = {} def get_engine(session_id): return ENGINE_REGISTRY.get(session_id) # ----------------------------- # RUN AUTOPSY # ----------------------------- @router.get("/autopsy/{session_id}/{action}") def run_autopsy(session_id: str, action: str): engine = get_engine(session_id) if not engine: return {"error": "session not found"} autopsy = FailureAutopsy( engine.journal, critical_path=getattr(engine, "critical_path", None) ) return autopsy.report(action)