import { spawn } from 'node:child_process'; export type PiAcceptance = { acceptedAt: string; sessionId: string; runSequence: number; }; export type PiSessionStatus = { running: boolean; health: 'healthy' | 'degraded'; sessionId: string | null; activity: 'active' | 'idle'; runSequence: number; lastError: string | null; desiredModel: string | null; desiredThinking: string | null; effectiveModel: string | null; effectiveThinking: string | null; pending: boolean; }; type DesiredSessionSettings = { model: string | null; thinking: string | null; }; export type PiModel = { provider: string; id: string; ref: string; }; export type PiApplyResult = { application: 'applied' | 'pending' | 'failed'; }; /** Shared with daemon lifecycle so gateway finalizers cannot outrun escalation. */ export declare const PI_STOP_GRACE_MS = 5000; export declare const PI_STOP_TERMINATE_MS = 2000; export declare const PI_STOP_MAX_MS: number; /** Includes scheduler/event-loop margin beyond PiRpcSession's internal bound. */ export declare const PI_STOP_LIFECYCLE_TIMEOUT_MS: number; export declare const SETUP_PI_VERSION_TIMEOUT_MS = 10000; /** Run the configured executable's version command before opening an RPC session. */ export declare function piEnvironment(extraPath?: string | undefined): NodeJS.ProcessEnv; export declare function piVersion(binary: string, timeoutMs?: number, environment?: NodeJS.ProcessEnv): Promise; export declare function requireSupportedPiVersion(output: string): void; /** A single persistent, strictly-LF-framed pi RPC child. */ export declare class PiRpcSession { private readonly options; private child; private buffer; private readonly pending; private streaming; private activityEpoch; private sessionId; private sequence; private lastError; private effectiveModel; private effectiveThinking; private safeBoundaryHandler; constructor(options: { binary: string; sessionDir: string; cwd: string; desired?: () => DesiredSessionSettings; spawn?: typeof spawn; version?: (binary: string) => Promise; /** Environment inherited by Pi; EXTRA_PATH is prepended to PATH. */ environment?: NodeJS.ProcessEnv; /** Injectable only to make restart supervision deterministic in tests. */ restartBaseMs?: number; restartMaxMs?: number; restartFailureThreshold?: number; setTimeout?: typeof setTimeout; clearTimeout?: typeof clearTimeout; /** Transport bounds are configurable so failure paths can be tested cheaply. */ commandTimeoutMs?: number; maxFrameBytes?: number; maxIncompleteBytes?: number; stderrLogMaxBytes?: number; stderrLogMaxEvents?: number; onStderrActivity?: (activity: { bytes: number; suppressed: boolean; }) => void; /** Bounded graceful shutdown seams for daemon lifecycle tests. */ stopGraceMs?: number; stopTerminateMs?: number; onRuntimeFailure?: () => void; /** Called once when this session loses ownership of a running child. */ onUnexpectedExit?: () => void; }); private startPromise; private restartTimer; private consecutiveFailures; private stopping; private restartAfterStart; private stopPromise; start(): Promise; private startChild; /** Run desired configuration only after pi reports a settled safe boundary. */ setSafeBoundaryHandler(handler: () => void): void; availableModels(): Promise; availableThinkingLevels(): Promise; /** Applies the persisted desired values only while no agent turn is active. */ applyDesired(): Promise; notify(message: string): Promise; stop(): Promise; private stopBounded; private waitForExit; /** Monotonic token used to detect settle/restart transitions during reset flush. */ currentActivityEpoch(): number; /** Returns a read-only, runtime-validated view of the child session. */ status(): Promise; private getState; private setStreaming; private applyState; private command; private receive; private processFrame; private validateCorrelatedResponse; private takePending; private failTransport; private drainStderr; private failStart; private handleUnexpectedExit; private isExhausted; private scheduleRestart; private cancelRestart; private recordFailure; private rejectPending; } export {};