/** * Agent tool dispatcher. * Spec: §5.10 Tool Schema — actions: spawn / list / stop / recover / status / attach * * This module is a pure dispatcher: it takes a structured params object plus a * context bag and routes to the appropriate engine function. It does NOT depend * on `pi` directly — that wiring lives in `index.ts`. Keeping the dispatcher * pure lets us unit-test every action by injecting fakes via the context. */ import type { OrcaSession } from "@pi-orca/core"; import { spawnAgent } from "./spawn.js"; import { sendPromptToSdkAgent, stopSdkAgent } from "./spawners/sdk.js"; import { sendPromptToRpcAgent, stopRpcAgent } from "./spawners/rpc.js"; import { sendPromptToTmuxAgent, stopTmuxAgent } from "./spawners/tmux.js"; import { listAgentStatuses, readAgentStatus } from "./status.js"; import type { AgentLifecycle } from "@pi-orca/core"; import { recoverAgents } from "./recovery.js"; import type { ResolvedAgentTemplate } from "./template.js"; import type { AgentStatusFile } from "@pi-orca/core"; export type AgentToolAction = "spawn" | "list" | "stop" | "recover" | "status" | "attach" | "prompt"; export interface AgentToolParams { action: AgentToolAction; template?: string; agentId?: string; task?: string; labels?: Record; isolation?: "sdk" | "process" | "tmux"; tmuxTarget?: "pane" | "window"; tmuxSplit?: "horizontal" | "vertical"; lifecycle?: AgentLifecycle; } export interface AgentToolContext { /** Active session, from bindSession(ctx). */ session: OrcaSession; /** Parent session entries (for fork-bloat check during SDK spawn). */ parentEntries?: any[]; /** Currently-active parent tool list (for inheritance). */ parentTools?: string[]; /** Parent resolved template (when current agent is itself a child). */ parentTemplate?: ResolvedAgentTemplate; /** User-visible notification hook (typically `ctx.ui.notify`). */ notify?: (message: string, type?: "info" | "warning" | "error") => void; /** Parent's notify socket path (best-effort latency hint). */ parentNotifySockPath?: string; /** Spawn boot deadline (seconds); forwarded to spawnAgent. */ spawnBootDeadlineSeconds?: number; /** * Heartbeat write interval (ms); forwarded to spawnAgent. * Sourced from `polling.heartbeatIntervalSeconds` × 1000. */ heartbeatIntervalMs?: number; /** * Fork-bloat warning threshold in bytes; forwarded to spawnAgent. * Sourced from `agents.forkSizeWarnBytes` config. 0 disables. */ forkSizeWarnBytes?: number; /** * When true, terminal-status worktree cleanup bypasses the W9 safeguard. * Sourced from `agents.worktreeForceCleanupOnTerminal` config. Default false. */ worktreeForceCleanupOnTerminal?: boolean; spawnAgentFn?: typeof spawnAgent; stopSdkFn?: typeof stopSdkAgent; stopRpcFn?: typeof stopRpcAgent; stopTmuxFn?: typeof stopTmuxAgent; recoverFn?: typeof recoverAgents; listStatusesFn?: typeof listAgentStatuses; readStatusFn?: typeof readAgentStatus; /** Persistent-prompt test hooks (spec §5.13). */ sendPromptSdkFn?: typeof sendPromptToSdkAgent; sendPromptRpcFn?: typeof sendPromptToRpcAgent; sendPromptTmuxFn?: typeof sendPromptToTmuxAgent; /** Override for `tmux select-window` (attach action). */ execTmuxSelectWindow?: (windowId: string) => Promise; /** Override for `tmux select-pane` (attach action, pane target). */ execTmuxSelectPane?: (paneId: string) => Promise; } export interface AgentToolResult { success: boolean; action: AgentToolAction; message?: string; error?: string; [key: string]: unknown; } /** * Dispatch an agent tool action. * * @param params - Tool parameters (action + optional fields) * @param ctx - Context (session, hooks, test overrides) * @returns Result envelope with success flag, message/error, and payload */ export declare function executeAgentTool(params: AgentToolParams, ctx: AgentToolContext): Promise; /** * Stop every spawner-managed agent across all three isolation modes. * Used by the shutdown guard (§5.1.1) and by the test suite for cleanup. */ export declare function stopAllAgentsAcrossModes(parentSessionPath: string): Promise; export type { AgentStatusFile }; //# sourceMappingURL=tool.d.ts.map