import { type ChildProcess, type SpawnOptions } from 'child_process'; import { Capability } from '../capabilities.js'; import type { AgentAdapter, AgentProcess, AgentSpawnConfig, Backend } from '../types.js'; import { buildSpawnArgs } from './spawn-args.js'; import { createLineSplitter, encodeCommand } from './framing.js'; /** Result of a switch_session RPC: ok=true when pi acked, cancelled=true when an in-flight agent was preempted. */ type SwitchResult = { ok: boolean; cancelled: boolean; }; /** * PI-specific extension of AgentProcess that exposes sendExtensionUiResponse. * Callers that need to respond to ask_user_question events (plan approval, interactive questions) * can use this method to send extension_ui_response back to the PI subprocess. * Payload fields depend on the dialog method (rpc.md §extension_ui): * select/input/editor: { value: string } or { cancelled: true } * confirm: { confirmed: boolean } or { cancelled: true } */ export interface PIAgentProcess extends AgentProcess { sendExtensionUiResponse(id: string, payload: Record): void; } type SpawnFn = (command: string, args: string[], options: SpawnOptions) => ChildProcess; export declare class PIAdapter implements AgentAdapter { readonly backend: Backend; readonly capabilities: Set; private readonly sessions; private readonly spawner; private readonly sessionPathRegistry; /** sessionDir for the .jsonl path convention. Exposed for tests. */ readonly sessionDir: string; constructor(spawner?: SpawnFn, sessionDir?: string); spawn(config: AgentSpawnConfig): PIAgentProcess; /** * Resolve the JSONL file path for a given PI session ID. * Returns null if the session has not been registered yet (not spawned or bootstrap pending). */ resolveSessionPath(sessionId: string): string | null; /** * Switch an existing subprocess (identified by onSessionKey) to serve a different PI session. * Returns {ok:false, cancelled:false} if the session key or target session ID is unknown. * NTH-1: onSessionKey routes the switch to the correct subprocess (spec done-when #1 omits it, * but it is architecturally required for multi-session adapters). */ switchSession(sessionId: string, onSessionKey: string): Promise; close(sessionKey: string): Promise; kill(sessionKey: string): boolean; listSessions(): string[]; } export declare const _test: { buildSpawnArgs: typeof buildSpawnArgs; encodeCommand: typeof encodeCommand; createLineSplitter: typeof createLineSplitter; DEFAULT_SESSION_DIR: string; MCP_BRIDGE_PATH: string; TOOL_SHIMS_PATH: string; HOOK_BRIDGE_PATH: string; CLOSE_EXIT_WAIT_MS: number; SWITCH_SESSION_TIMEOUT_MS: number; }; export {};