/** * Durable background-command lane (GH-535). * * Long-running side-effecting work the chat agent launches inside a turn * (metadata `retrieve`/`deploy`, builds) is a child of that turn's `claude` * process, so it dies when the turn closes, the user hits Stop, the idle reaper * fires, or the session respawns on the next message. This lane lets the agent * delegate such work to the long-lived bridge SERVER, which spawns it as a * DETACHED process in its own process group. Because the server outlives the * turn, the work survives all four teardown paths above. * * Lifecycle is surfaced through the SAME event bus the phase-spawn lane uses, so * the web-console renders it via its existing `backgroundSpawns` UI with no * client changes. */ export type BackgroundCommandStatus = 'running' | 'completed' | 'failed'; export type BackgroundCommandSession = { id: string; command: string; args: string[]; label: string; status: BackgroundCommandStatus; startedAt: string; completedAt?: string; exitCode?: number | null; pid?: number; logFile: string; parentChatSessionId?: string; }; export type LaunchBackgroundInput = { command: string; args: string[]; label?: string; cwd: string; parentChatSessionId?: string; }; export type LaunchBackgroundResult = { ok: true; session: BackgroundCommandSession; } | { ok: false; error: string; }; /** Test seam: register an additional allow-listed command prefix. */ export declare function addAllowedPrefixForTest(prefix: string[]): void; /** Test seam: clear test-only allow-list entries. */ export declare function resetAllowedPrefixesForTest(): void; export declare function validateBackgroundCommand(command: string, args: string[]): { ok: true; } | { ok: false; error: string; }; export declare function getBackgroundSession(id: string): BackgroundCommandSession | undefined; export declare function listBackgroundSessions(filter?: { status?: BackgroundCommandStatus; parentChatSessionId?: string; }): BackgroundCommandSession[]; /** Test seam: clear the registry between cases. */ export declare function resetBackgroundSessionsForTest(): void; /** * Validate and launch a background command as a DETACHED process in its own * process group (`detached: true` + `setsid` semantics). The child is * `unref()`ed so the bridge can exit independently, and its stdio is redirected * to a per-session log file (no pipe kept open). Returns immediately with the * tracked session; completion is reported asynchronously via the spawn event bus. */ export declare function launchBackgroundCommand(input: LaunchBackgroundInput, now: number): LaunchBackgroundResult;