#!/usr/bin/env python3 """ Session startup recovery check. Call this at the start of any new session to handle Gateway crash recovery. """ import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent)) from state_manager import OperationState def check_for_recovery(): """Check if this session is recovering from a Gateway outage.""" interrupted = OperationState.list_interrupted() if not interrupted: return None # Find most recent interrupted operation most_recent = max(interrupted, key=lambda x: x.get('last_checkpoint', '')) state = OperationState.load(most_recent['operation_id']) return state if __name__ == "__main__": state = check_for_recovery() if state: print(f"RECOVERY_MODE: {state.operation_id}") print(f"AGENT: {state.agent_name}") print(f"RESUME_PROMPT: {state.resume_prompt}") print(f"PROGRESS: {state.progress}") else: print("NO_RECOVERY")