/** * agent-runner.ts — Core execution engine: creates sessions, runs agents, collects results. */ import type { Api, Model } from "@earendil-works/pi-ai"; import type { ExtensionContext } from "@earendil-works/pi-coding-agent"; import { type AgentSession, type ExtensionAPI, type ToolDefinition } from "@earendil-works/pi-coding-agent"; import type { SubagentType, ThinkingLevel } from "./types.js"; /** Normalize max turns. undefined or 0 = unlimited, otherwise minimum 1. */ export declare function normalizeMaxTurns(n: number | undefined): number | undefined; /** Get the default max turns value. undefined = unlimited. */ export declare function getDefaultMaxTurns(): number | undefined; /** Set the default max turns value. undefined or 0 = unlimited, otherwise minimum 1. */ export declare function setDefaultMaxTurns(n: number | undefined): void; /** Get the grace turns value. */ export declare function getGraceTurns(): number; /** Set the grace turns value (minimum 1). */ export declare function setGraceTurns(n: number): void; /** Info about a tool event in the subagent. */ export interface ToolActivity { type: "start" | "end"; toolName: string; } export interface RunOptions { /** ExtensionAPI instance — used for pi.exec() instead of execSync. */ pi: ExtensionAPI; /** Stable runtime ID for parent bridge routing. */ agentId?: string; /** Parent session affinity for bridge delivery. */ parentSessionId?: string; /** Whether the subagent may block on ask_parent. */ allowAskParent?: boolean; /** Extra tools available only for this run. */ customTools?: ToolDefinition[]; model?: Model; maxTurns?: number; signal?: AbortSignal; isolated?: boolean; inheritContext?: boolean; thinkingLevel?: ThinkingLevel; /** Override working directory (e.g. for worktree isolation). */ cwd?: string; /** Called on tool start/end with activity info. */ onToolActivity?: (activity: ToolActivity) => void; /** Called on streaming text deltas from the assistant response. */ onTextDelta?: (delta: string, fullText: string) => void; onSessionCreated?: (session: AgentSession) => void; /** Called at the end of each agentic turn with the cumulative count. */ onTurnEnd?: (turnCount: number) => void; /** Called when a notable run tag is resolved. */ onRunTag?: (tag: string) => void; /** Called when non-fatal warnings are collected. */ onWarning?: (warnings: string[]) => void; /** Whether warnings should surface as transient UI notifications. */ notifyWarnings?: boolean; } export interface RunResult { responseText: string; session: AgentSession; /** True if the agent was hard-aborted (max_turns + grace exceeded). */ aborted: boolean; /** True if the agent was steered to wrap up (hit soft turn limit) but finished in time. */ steered: boolean; /** Non-fatal warnings produced while preparing or running the agent. */ warnings: string[]; } export declare function runAgent(ctx: ExtensionContext, type: SubagentType, prompt: string, options: RunOptions): Promise; /** * Send a new prompt to an existing session (resume). */ export declare function resumeAgent(session: AgentSession, prompt: string, options?: { onToolActivity?: (activity: ToolActivity) => void; signal?: AbortSignal; }): Promise; /** * Send a steering message to a running subagent. * The message will interrupt the agent after its current tool execution. */ export declare function steerAgent(session: AgentSession, message: string): Promise; /** * Get the subagent's conversation messages as formatted text. */ export declare function getAgentConversation(session: AgentSession): string;