import type { OpencodeClient as OpenCodeClient } from "@opencode-ai/sdk"; import type { CompletionDetector } from "../completion/detector.js"; import { type Delegation } from "../../shared/types.js"; type SdkDelegationCallbacks = { getDelegation: (id: string) => Delegation | undefined; persistAllDelegations: () => void; cleanupTracking: (delegationId: string, childSessionId: string) => void; scheduleSafetyCeiling: (delegation: Delegation) => void; onSessionIdle: (sessionId: string) => void; onTerminal: (delegationId: string, newState: "completed" | "error" | "timeout", error?: string) => void; /** * Optional accessor for the lifecycle-manager-owned `CompletionDetector`. * When provided, the SDK polling loop (Phase 36.1 re-wiring) feeds message * counts into the detector and consumes any cached terminal signals from * `session.error` / `session.deleted` events that arrived through the * lifecycle event handler. When absent, the handler falls back to legacy * adaptive polling alone — keeping unit tests and callers that don't wire * a detector backwards-compatible. */ getCompletionDetector?: () => CompletionDetector | undefined; }; /** * Manages SDK delegation lifecycle: stability polling, result extraction, and recovery. * * Owned state: stability poll timers. * Delegates registration, persistence, and cleanup to DelegationManager via callbacks. */ export declare class SdkDelegationHandler { private readonly client; private readonly callbacks; private readonly stabilityTimers; constructor(client: OpenCodeClient, callbacks: SdkDelegationCallbacks); /** Compute adaptive poll interval based on time since last message count change. */ private calculateAdaptiveInterval; /** Schedule a stability poll for an SDK delegation. */ scheduleStabilityPoll(delegationId: string, justChanged?: boolean): void; /** Recover an SDK delegation that was running before restart. */ recoverSdkDelegation(delegation: Delegation): Promise; /** * Clears only the recovery retry marker after the SDK proves the child session still exists. * * @param delegation - Persisted delegation being reconciled during startup recovery. */ private clearStaleRecoveryError; /** Check whether a stability poll timer is active for the given delegation. */ isPolling(delegationId: string): boolean; /** Expose stability timers for test compatibility. */ getTimerMap(): Map; /** Clear stability timers for a given delegation. */ clearTimers(delegationId: string): void; private performStabilityPoll; /** * Check if a child session is still actively processing (not idle). * * Queries the session status map via the SDK. Returns `true` if the session * is in a non-idle state (e.g., "busy" / "running"), meaning the agent is * still actively working. Returns `false` if the session is idle or if the * status cannot be determined (defensive: treat unknown as not-busy to avoid * blocking finalization indefinitely). */ private isSessionBusy; private finalizeSdkDelegation; } export {}; //# sourceMappingURL=handler.d.ts.map