/** * Recovery — Layer 3 of the parent liveness protocol. * Spec: §5.3 — `/agents recover` * * Scans the parent's .orca/agents/ for non-terminal status YAMLs left behind * from a previous parent process (crash, kill, etc.). For each, performs a * liveness check based on isolation mode and decides: respawn, mark abandoned, * or skip. */ import { type GitExec, type SweepResult } from "./worktree.js"; import type { AgentStatusFile } from "@pi-orca/core"; export type RecoveryAction = { kind: "skip"; reason: string; } | { kind: "abandon"; reason: string; } | { kind: "respawn"; respawnIdle: boolean; }; export interface RecoveryItem { agentId: string; status: AgentStatusFile; action: RecoveryAction; } export interface RecoverAgentsParams { /** Parent session path (for status enumeration) */ parentSessionPath: string; /** Project directory (for template re-loading) */ projectDir?: string; /** User directory (for template re-loading) */ userDir?: string; /** * Optional liveness probe override (for testing). * Defaults to `isPidAlive` from @pi-orca/core. */ isAliveOverride?: (pid: number) => boolean; /** * Action to take when an agent needs respawn. Implementer wires this to * the appropriate spawner (with --session pinned to the saved session). * Return value indicates success or a structured error. */ onRespawn?: (item: RecoveryItem) => Promise; /** * Notification hook for user-visible messages (e.g., "template missing", * "agent recovered idle"). */ notify?: (message: string, type?: "info" | "warning" | "error") => void; /** * Cwd to probe for a git repository. When the parent session lives in a * git repo, the recovery pass also sweeps `/.pi/active-*.lock` * for orphan worktrees (§4.1.2). Defaults to `process.cwd()`. */ cwd?: string; /** * Bypass the W9 uncommitted-work safeguard when sweeping orphan worktrees. * Sourced from `agents.worktreeForceCleanupOnTerminal` config. */ worktreeForceCleanupOnTerminal?: boolean; /** Test-only git exec injection. */ execGit?: GitExec; } export interface RecoverAgentsResult { scanned: number; abandoned: string[]; respawned: string[]; skipped: string[]; /** Worktree sweep result (§4.1.2). Absent when cwd is not inside a git repo. */ worktreeSweep?: SweepResult; } /** * Plan recovery actions for every non-terminal agent in the parent's sibling * folder. Does NOT execute respawns — that's left to the caller via * `executeRecovery`. Separation lets the tool dispatcher show a preview * before performing destructive operations. * * @param params - Recovery parameters * @returns Per-agent recovery plans (kind, reason) */ export declare function planRecovery(params: RecoverAgentsParams): Promise; /** * Execute the planned recovery actions. * Spec: §5.3.1 * * @param plans - Recovery items from planRecovery * @param params - Original recovery parameters (for onRespawn + notify) * @returns Result summary */ export declare function executeRecovery(plans: RecoveryItem[], params: RecoverAgentsParams): Promise; /** * Convenience: plan + execute in one pass. * * @param params - Recovery parameters * @returns Result summary */ export declare function recoverAgents(params: RecoverAgentsParams): Promise; /** * De-duplicate `originalTask` re-emission (round-3 finding C12). * Spec §5.3.1 — before respawning, scan saved session entries for an existing * user_message matching `originalTask`. If found, the agent already consumed * the prompt pre-crash; the caller should skip the sendUserMessage call. * * @param entries - Session entries from SessionManager.open().getEntries() * @param task - Original task string * @returns True if the task is already present (skip re-emit) */ export declare function alreadyHasOriginalTask(entries: any[], task: string): boolean; //# sourceMappingURL=recovery.d.ts.map