/** * Pi Coding Agent Harness Adapter — cleo-os implementation. * * Layering (ADR-069 D002): this adapter is in the Workflow layer. Workflow * MAY use Conduit (Messaging) to publish inter-agent DMs; Conduit MUST NOT * know about the harness (ADR-069 D002). All DB reads/writes MUST go * through the Storage chokepoint (umbrella DataAccessor / `openCleoDb()`, * T9050). * * @see ADR-069 (CLEO Coordination Layers) * * Implements the {@link HarnessAdapter} interface for the Pi coding agent CLI * (`@mariozechner/pi-coding-agent`). Provides process spawn, status, kill, * and output streaming for Pi processes launched by cleo-os. * * @remarks * This adapter is the cleo-os counterpart to the CAAMP * `PiSpawnProvider` in `packages/adapters/src/providers/pi/spawn.ts`. * Where the CAAMP spawn provider is a detached fire-and-forget launcher, * this adapter owns the full process lifecycle — attached stdin/stdout/stderr, * bounded output buffering, and structured exit promises — so it can be * used in orchestrated sandbox runs. * * Two launch modes are supported: * - **Host-native** (default): Pi is invoked directly from PATH (or via * `CLEO_PI_BINARY`). This is the standard mode for local development. * - **Docker sandbox** (opt-in): Pi is launched inside the * `cleo-sandbox/pi:local` Docker container when `CLEO_PI_SANDBOXED=1` is * set or `sandboxed: true` is passed to {@link PiCodingAgentAdapter.spawn}. * Falls back to host-native with a warning when Docker is unavailable. * * Instance IDs have the format `pi--` to make * correlation with task records straightforward. * * @see packages/adapters/src/providers/pi/spawn.ts — CAAMP spawn provider * @see packages/cleo-os/src/harnesses/pi-coding-agent/pi-wrapper.ts — process management * @see packages/cleo-os/src/harnesses/pi-coding-agent/docker-mode.ts — sandbox mode * @task T922 * @epic T911 * @packageDocumentation */ import type { HarnessAdapter, HarnessOutputLine, HarnessProcessStatus, HarnessSpawnOptions, HarnessSpawnResult } from './types.js'; /** * Harness adapter for the Pi coding agent CLI in the cleo-os sandbox. * * Manages a pool of Pi processes, each identified by a stable instance ID. * Supports host-native and Docker sandbox launch modes. * * @example * ```typescript * const adapter = new PiCodingAgentAdapter(); * const { instanceId, exitPromise } = await adapter.spawn('T123', 'Write a hello-world script'); * const status = await exitPromise; * console.log('exit code:', status.exitCode); * ``` * * @public */ export declare class PiCodingAgentAdapter implements HarnessAdapter { /** Short adapter identifier. */ readonly id = "pi-coding-agent"; /** Active process tracking entries keyed by instance ID. */ private readonly processes; /** Low-level Pi process launcher. */ private readonly wrapper; /** Docker sandbox mode adapter. */ private readonly docker; /** * Generate a stable instance ID for a spawned process. * * @param taskId - CLEO task ID. * @returns Instance ID string in the format `pi--`. */ private makeInstanceId; /** * Spawn a Pi coding agent process with the given task prompt. * * When `opts.sandboxed` is `true` (or `CLEO_PI_SANDBOXED=1` is set), the * adapter first verifies Docker readiness and delegates to * {@link DockerModeAdapter.spawnInDocker}. On Docker failure it falls back * to host-native mode with a warning to stderr. * * The returned {@link HarnessSpawnResult.exitPromise} resolves once the * process exits or is killed. It NEVER rejects — failures are encoded in * the resolved {@link HarnessProcessStatus}. * * @param taskId - Stable CLEO task identifier associated with this run. * @param prompt - Prompt text to pass to the Pi agent. * @param opts - Optional spawn configuration. * @returns Spawn result containing the instance ID, PID, and exit promise. * * @public */ spawn(taskId: string, prompt: string, opts?: HarnessSpawnOptions): Promise; /** * Query the current status of a spawned process. * * @param instanceId - Instance ID returned from {@link spawn}. * @returns Current status snapshot, or `null` when the ID is not tracked. * * @public */ status(instanceId: string): HarnessProcessStatus | null; /** * Terminate a running Pi process via SIGTERM-then-SIGKILL. * * Idempotent — subsequent calls after the first are no-ops. * * @param instanceId - Instance ID returned from {@link spawn}. * * @public */ kill(instanceId: string): Promise; /** * Return recently captured output lines for a process. * * Returns a snapshot of the bounded ring buffer maintained by the wrapper. * The buffer is limited to `CLEO_HARNESS_OUTPUT_BUFFER` lines (default 500). * * @param instanceId - Instance ID returned from {@link spawn}. * @returns Array of recent output lines, oldest first; empty when not found. * * @public */ output(instanceId: string): HarnessOutputLine[]; /** * Spawn Pi inside a Docker sandbox container. * * Checks Docker readiness first. On failure, falls back to host-native * mode with a stderr warning. Prompt delivery and output buffering follow * the same pattern as the host-native path in {@link PiWrapper.start}. * * @param entry - Process tracking entry (mutated in place). * @param prompt - Prompt text to deliver to Pi. * @param cwd - Host working directory (bind-mounted into container). * @param env - Extra environment variable overrides. */ private spawnInSandbox; } //# sourceMappingURL=adapter.d.ts.map