/** * child-process-agent.ts — Spawn child Pi agents as separate OS processes. * * Based on nicobailon/pi-subagents's child-process approach. * Unlike in-process createAgentSession(), this spawns a fresh `pi` CLI * subprocess for each child. Benefits: * - Process isolation: no shared state with the parent * - Full tool access: child starts with fresh tool registration * - Model independence: child can use a different model/thinking level * - No context contamination: parent conversation doesn't leak into child * - No EXCLUDED_TOOL_NAMES leaks: orchestration tools not registered at all */ import type { SubagentType, ThinkingLevel } from "./types.js"; export interface ChildAgentOptions { /** Agent type name (used for tool selection / system prompt). */ agentType: SubagentType; /** User task prompt. */ task: string; /** Working directory for the child. Default: parent cwd. */ cwd?: string; /** Model override (provider/modelId). Default: parent's active model. */ model?: string; /** Thinking level. */ thinkingLevel?: ThinkingLevel; /** Max turns before steering to wrap up. */ maxTurns?: number; /** Tool names to pass via --tools. When omitted, defaults are used. */ tools?: string[]; /** System prompt for --system-prompt (replace mode) or --append-system-prompt. */ systemPrompt?: string; /** System prompt mode. Default: "replace". */ systemPromptMode?: "replace" | "append"; /** AbortSignal to cancel the child process. */ signal?: AbortSignal; /** Callback for streaming stdout lines as they arrive. */ onStdout?: (line: string) => void; /** Callback for streaming stderr lines as they arrive. */ onStderr?: (line: string) => void; } export interface ChildAgentResult { /** Full stdout content. */ stdout: string; /** Full stderr content. */ stderr: string; /** Exit code of the child process. */ exitCode: number | null; /** Whether the process was aborted via signal. */ aborted: boolean; /** Duration in milliseconds. */ durationMs: number; } /** Default built-in tool names (used when tools option is omitted). */ export declare const DEFAULT_CHILD_TOOLS: string[]; /** * Spawn a child Pi agent as a separate OS process. * * Uses `pi --print` mode which streams completion as stdout text. * The child runs independently with its own tool registration, * model configuration, and system prompt. * * @returns Result object with stdout, stderr, exit code, etc. */ export declare function spawnChildAgent(options: ChildAgentOptions): Promise;