import { type ChildProcessWithoutNullStreams } from "node:child_process"; import type { PtyManager } from "../../features/background-command/pty/pty-manager.js"; import type { CommandDelegationParams, Delegation, DelegationResult, DelegationTerminalKind } from "../../shared/types.js"; export type HeadlessCommandState = { process: ChildProcessWithoutNullStreams; output: string; truncated: boolean; }; type CommandDelegationCallbacks = { getDelegation: (id: string) => Delegation | undefined; registerDelegation: (delegation: Delegation, scheduleSafety: boolean) => void; persistAllDelegations: () => void; buildResult: (delegation: Delegation) => DelegationResult; cleanupTracking: (delegationId: string, childSessionId: string) => void; onTerminal: (delegationId: string, newState: "completed" | "error" | "timeout", error?: string, terminalDetail?: { terminalKind?: DelegationTerminalKind; terminationSignal?: string; explicitCancellation?: boolean; }) => void; }; /** * Manages PTY and headless command delegation lifecycle. * * Owned state: command poll timers, headless process tracking. * Delegates registration, persistence, and cleanup to DelegationManager via callbacks. */ export declare class CommandDelegationHandler { private readonly callbacks; private readonly commandPollTimers; private readonly headlessCommands; private readonly ptyManager; constructor(ptyManager: PtyManager | null, callbacks: CommandDelegationCallbacks); /** Dispatch a command via PTY (preferred) or headless fallback. Caller handles concurrency. */ dispatchCommand(params: CommandDelegationParams, queueKey: string, nestingDepth: number): Promise; /** * Recover a PTY delegation that was running before restart. * * PTY OS processes cannot survive a harness restart — the underlying * `bun-pty` process tree dies with the parent. When recovery cannot * find the prior session (because the runtime has no PTY manager, or * the manager has no record of this `ptySessionId`), surface a truthful * `terminalKind: "non-resumable-after-restart"` rather than the * historical "session not found" string. Observers can then distinguish * "we crashed" from "this kind of process is just not resumable". * * @see Phase 16.2.1 — R-PTY-03-AMENDED */ recoverPtyDelegation(delegation: Delegation): void; /** Clear poll timers for a given delegation. */ clearTimers(delegationId: string): void; private dispatchHeadlessCommand; private schedulePtyExitPoll; private finalizeCommandDelegation; private resolvePtyManager; private readPtyOutput; private buildMinimalEnv; } export {}; //# sourceMappingURL=handler.d.ts.map