"""Local operator commands; no public HTTP replay or arbitrary object paths.""" import argparse import json from .domain import Failure from .jobs import Jobs, fault from .postgres import PostgresStore from .storage import ObjectStorage from .worker import cleanup_ready def cleanup(store, storage, failed_hours=168, intent_seconds=3600): if failed_hours < 0 or intent_seconds < 0: raise ValueError("Retention must be nonnegative") counts = {"ready_staging": 0, "failed_sources": 0, "orphan_intents": 0} with store.connection() as conn: ready = conn.execute( "SELECT id FROM attachments WHERE status='ready' AND stage_key IS NOT NULL" ).fetchall() for row in ready: cleanup_ready(store, storage, row["id"]) counts["ready_staging"] += 1 with store.connection() as conn: candidates = conn.execute( "SELECT id FROM attachments WHERE status='failed' AND updated_at