import { type RuntimeDriverName, type RuntimeEvent, type RuntimeSessionId, type RuntimeStatus, type TranscriptChunk } from "@pi-claude-code-agent/runtime"; import type { AskResult, AttachPeerInput, BridgeOptions, BridgePeer, BridgeState, BridgeTransport, BridgeTransportIncomingMessage, BridgeTransportStatus, IntercomInboundMessage, InterruptPeerResult, LaunchPeerInput, WaitForCompletionOptions } from "./types.js"; /** * Driver-aware default for `WaitForCompletionOptions.staleThresholdMs`. * * Different drivers emit driver events at very different rates. Claude * (sdk/cli) streams thinking blocks and tool deltas continuously, so a * 2-minute gap is already strongly indicative of a wedged peer. Codex and * `pi-coding-agent` batch much more aggressively — a 5-minute gap is closer * to the "alive but quiet" floor. The numbers are deliberately coarse; * callers wanting tighter bounds should pass `staleThresholdMs` explicitly. */ export declare function defaultStaleThresholdMsForDriver(driver: RuntimeDriverName): number; export declare const BRIDGE_SYSTEM_PROMPT: string; export declare class ClaudeRuntimeIntercomBridge { private readonly runtime; private readonly storageDir; private transport?; private readonly pollIntervalMs; private readonly askTimeoutMs; private readonly peers; /** * Names of peers that were launched with `waitForIdle: false` and have not * yet been observed in a terminal state. While in this set, a concurrent * `send`/`ask` must wait through the launch run's `busy` window rather * than reject with `PEER_BUSY` — the only work the peer is doing is its * own bootstrap. Cleared as soon as `deliver` (or any sync path) sees * idle/interrupted/failed/stopped, or on stop/disconnect. */ private readonly bootstrappingPeers; constructor(options?: BridgeOptions); launchPeer(input: LaunchPeerInput): Promise; attachPeer(input: AttachPeerInput): Promise; listPeers(): Promise; status(name: string): Promise; /** * Look up a peer by its runtime sessionId rather than its registry name. * Useful for callers that received the sessionId from `launchPeer` or from * a runtime event and don't want to keep a name→sessionId map of their own. */ statusBySessionId(sessionId: RuntimeSessionId): Promise; /** * Fetch the transcript chunk for a sessionId. Thin Bridge-routed wrapper * over the embedded runtime so any future Bridge-side accounting (rate * limiting, telemetry, replay buffers) applies uniformly. */ events(sessionId: RuntimeSessionId, cursor?: number): Promise; /** * Subscribe to raw runtime events, optionally filtered to a single * sessionId. Returns an unsubscribe function. This is a passthrough — the * caller sees the underlying `RuntimeEvent` stream, not the Bridge's own * lifecycle envelope. */ subscribe(listener: (event: RuntimeEvent) => void, sessionId?: RuntimeSessionId): () => void; /** * Wait until `sessionId` reaches a terminal state (`idle`, `interrupted`, * `failed`, `stopped`), or reject if the peer goes silent past * `staleThresholdMs`, exceeds `hardCeilingMs`, or the caller aborts. * * Event-driven: subscribes to the runtime's event stream and resets the * staleness window on every event for this session. The pattern is * listen-then-look — we subscribe BEFORE snapshotting status, so a peer * that lands terminal between snapshot and subscribe cannot be missed. * * Resolves with the terminal `RuntimeStatus`. `failed` is a resolution, * not a rejection: inspect `.state` and `.lastError` to distinguish. */ waitForCompletion(sessionId: RuntimeSessionId, opts?: WaitForCompletionOptions): Promise; reconcilePeers(): Promise; send(name: string, message: Omit, options?: { waitForIdle?: boolean; }): Promise; ask(name: string, message: Omit): Promise; reply(name: string, message: Omit): Promise; interrupt(name: string): Promise; interruptWithResult(name: string): Promise; stop(name: string): Promise; disconnect(name: string): Promise; setTransport(transport?: BridgeTransport): Promise; restorePeers(): Promise; transportStatus(): Promise; hasTransport(): boolean; close(): Promise; private deliver; private waitForTerminalStateOrCurrent; private waitForTerminalState; private syncPeerFromRuntime; private peerFromStatus; private registerTransportPeer; private unregisterTransportPeer; private handleTransportMessage; private rememberPeer; private forgetPeer; private listPeersWithoutRestore; private mergePersistedPeerRecord; private recordFromPeer; private requirePeer; private assertLaunchPeerNameAvailable; private assertAttachPeerNameAvailable; } declare function formatInboundMessage(message: IntercomInboundMessage): string; declare function extractReplyText(events: RuntimeEvent[]): string; declare function extractLatestReplyText(events: RuntimeEvent[]): string; declare function mapRuntimeState(state: RuntimeStatus["state"], registered: boolean): BridgeState; declare function formatTransportInboundText(message: BridgeTransportIncomingMessage): string; export { extractLatestReplyText, extractReplyText, formatInboundMessage, formatTransportInboundText, mapRuntimeState };