/** * spawn-cleanup — bounded, idempotent cleanup with ownership confirmation. * * G-026 M3 (ADR-0004 #6/#19/#20): cleanup follows a bounded 5-phase sequence * with a total deadline budget (default 15s): * graceful terminate (≤1s) → bounded wait (≤5s) → force kill/terminate (≤5s) * → backend verify re-query (≤4s) → confirmed / unknown. * On timeout/unknown the slot is NOT released and the batch freezes; leftover * resources are recorded with operator guidance. Cleanup is idempotent. */ export type CleanupVerdict = "confirmed" | "unknown" | "already-gone"; export interface CleanupHooks { /** Graceful terminate (e.g. tmux send-keys C-c / child.kill(SIGTERM)). */ gracefulTerminate: () => Promise | void; /** Wait for the worker resources to exit naturally (no arg; sleep internally). */ wait: () => Promise | void; /** Force kill/terminate (e.g. kill-pane -t %N / child.kill(9) / kill-session). */ forceTerminate: () => Promise | void; /** Re-query backend to confirm the resource is gone. Returns true when gone. */ verify: () => Promise | boolean; /** Whether the resource was already absent before cleanup began. */ probeGone: () => Promise | boolean; } export interface BoundedCleanupOptions { /** Per-phase budget ms (defaults: graceful 1000, wait 5000, force 5000, verify 4000). */ gracefulMs?: number; waitMs?: number; forceMs?: number; verifyMs?: number; /** Total deadline ms (default 15_000). Overrides sum of phases when smaller. */ totalDeadlineMs?: number; } export interface CleanupResult { verdict: CleanupVerdict; /** Human-readable trace of the sequence executed. */ trace: string[]; /** True when the total deadline expired before verification completed. */ timedOut: boolean; } /** * Run the bounded cleanup sequence. Always resolves (never throws); on any * phase error it falls through to the next phase. Returns confirmed only when * the backend verify query confirms the resource is gone. */ export declare function runBoundedCleanup(hooks: CleanupHooks, opts?: BoundedCleanupOptions): Promise;