/**
 * Forked Agent — CC forkedAgent.ts parity.
 *
 * Runs an isolated agent query loop with:
 *   - Independent AbortController (parent abort propagates)
 *   - Independent message history (no mutation of parent conversation)
 *   - Shared LLM config for prompt cache sharing
 *   - Tool restriction via canUseTool function
 *   - Usage tracking across all API calls
 *   - Optional transcript recording
 *
 * This is the execution engine for all sub-agent types:
 *   - Dream consolidation
 *   - Background memory extraction
 *   - Skill/command forking
 *   - AgentTool async agents
 *
 * Reference: claude-code src/utils/forkedAgent.ts
 */
import type { AgentLogger, ChatMessage, ToolDefinition, ToolInvoker, TokenUsage, TurnEvent, HookRegistry, ForkedAgentRunnerFactory } from "../ports/agent-execution-contracts.js";
import type { LLMTransport } from "../ports/index.js";
import type { AgentProgress } from "./progress-tracker.js";
/**
 * Tool permission check function — CC canUseTool parity.
 *
 * Returns allow/deny for each tool invocation.
 * Used by dream agent (read-only bash + memory writes only),
 * session memory (full read, no write), etc.
 */
export type CanUseToolFn = (toolName: string, input: Record<string, unknown>) => {
    allowed: true;
} | {
    allowed: false;
    reason: string;
};
/**
 * Parameters for running a forked agent.
 */
export interface ForkedAgentParams {
    /** Initial messages for the forked query loop */
    promptMessages: ChatMessage[];
    /** System prompt for the forked agent */
    systemPrompt?: string;
    /** Available tools */
    tools: ToolDefinition[];
    /** Tool permission check (restricts tool access) */
    canUseTool?: CanUseToolFn;
    /** LLM transport for API calls */
    transport: LLMTransport;
    /** Tool invoker for tool execution */
    toolInvoker: ToolInvoker;
    /** Factory for the concrete agent runner. Injected to keep runtime independent from agent/. */
    createAgentRunner: ForkedAgentRunnerFactory;
    /** API key */
    apiKey: string;
    /** Model name */
    model: string;
    /** Logger */
    log: AgentLogger;
    /** Hook registry (optional) */
    hooks?: HookRegistry;
    /** Label for analytics/debugging */
    forkLabel: string;
    /** Source identifier for tracking */
    querySource?: string;
    /** Optional cap on number of turns */
    maxTurns?: number;
    /** Optional cap on output tokens */
    maxOutputTokens?: number;
    /** Temperature override */
    temperature?: number;
    /** Parent AbortController (child will be created) */
    parentSignal?: AbortSignal;
    /** Callback invoked for each event as it arrives */
    onEvent?: (event: TurnEvent) => void;
    /** Callback for progress updates */
    onProgress?: (progress: AgentProgress) => void;
    /** Skip transcript recording */
    skipTranscript?: boolean;
    /** Token budget for this sub-agent. 0 or undefined = no limit. */
    budgetTokens?: number;
    /** Parent fork depth (propagated to child tool loop) */
    parentDepth?: number;
}
/**
 * Result of a forked agent run.
 */
export interface ForkedAgentResult {
    /** All events yielded during the query loop */
    events: TurnEvent[];
    /** Accumulated token usage across all API calls */
    totalUsage: TokenUsage;
    /** Progress tracker final state */
    progress: AgentProgress;
    /** Duration of the fork in ms */
    durationMs: number;
    /** Whether it completed successfully */
    ok: boolean;
    /** Error message if failed */
    error?: string;
}
/**
 * Run a forked agent query loop with full isolation.
 *
 * This function:
 *   1. Creates an isolated context (own AbortController, message history)
 *   2. Runs the agent loop with tool restrictions
 *   3. Tracks usage across all API calls
 *   4. Returns accumulated results
 */
export declare function runForkedAgent(params: ForkedAgentParams): Promise<ForkedAgentResult>;
