/**
 * Fork Sub-Agent — CC-aligned fork mechanism for spawning child agents.
 *
 * Core design principles (aligned with Claude Code):
 * 1. Child agent shares parent's message prefix (prompt cache hit)
 * 2. Fork uses placeholder results to ensure byte-identical prefix across children
 * 3. Child has independent tool context (doesn't pollute parent state)
 * 4. Results flow back via AsyncGenerator (streaming backflow)
 * 5. Depth control via in-memory counter (not DB-based)
 */
import type { AgentDefinition } from "./agent-registry.js";
import { MAX_FORK_DEPTH } from "../../runtime/config/tunable-defaults.js";
/** Sentinel tag injected into fork children to prevent recursive forking. */
export declare const FORK_SENTINEL_TAG = "<fork-child-context>";
/** Placeholder text used for all tool_results in shared prefix (ensures byte-identical prefix). */
export declare const FORK_PLACEHOLDER_RESULT = "Fork started \u2014 processing in background";
export { MAX_FORK_DEPTH };
export interface ForkContext {
    /** Parent's full message history (becomes shared prefix for cache). */
    parentMessages: unknown[];
    /** Parent's rendered system prompt (byte-exact for cache hit). */
    systemPrompt: string;
    /** Parent's full tool pool (useExactTools=true pattern). */
    parentTools: string[];
    /** Current fork depth (0 = root). */
    depth: number;
    /** Abort signal from parent. */
    abortSignal?: AbortSignal;
    /** Parent's agent ID for lineage tracking. */
    parentAgentId: string;
    /** Isolated worktree path for this fork child (CC team worktree parity). */
    worktreePath?: string;
}
export interface ForkChildConfig {
    /** The agent definition to run. */
    agent: AgentDefinition;
    /** Task-specific prompt for this child (the unique part after shared prefix). */
    taskPrompt: string;
    /** Optional override for max turns. */
    maxTurns?: number;
    /** Whether to run in background (async). */
    isAsync?: boolean;
}
export interface ForkChildMessage {
    role: "assistant" | "user" | "system";
    content: unknown;
    toolCalls?: unknown[];
}
export interface ForkResult {
    /** Whether the fork completed successfully. */
    ok: boolean;
    /** Child's final output text (summary). */
    output: string;
    /** Messages produced by the child (for result backflow). */
    messages: ForkChildMessage[];
    /** Total tokens consumed by the child. */
    tokensUsed: number;
    /** Whether the child hit its turn limit. */
    maxTurnsReached: boolean;
    /** Child's agent ID. */
    childAgentId: string;
}
/**
 * Check if current context is inside a fork child (prevents recursive forking).
 */
export declare function isInForkChild(messages: unknown[]): boolean;
/**
 * Check if fork depth allows spawning another child.
 */
export declare function canForkAtDepth(currentDepth: number): boolean;
/**
 * Build forked messages that ensure byte-identical prefix across all fork children.
 *
 * Strategy (aligned with CC's buildForkedMessages):
 * 1. Keep full parent message history (all tool_use blocks, thinking, text)
 * 2. Replace all pending tool_results with FORK_PLACEHOLDER_RESULT
 * 3. Append a single user message with the child-specific directive
 * → All children share the same prefix up to the directive → maximum cache hits.
 */
export declare function buildForkedMessages(context: ForkContext, childConfig: ForkChildConfig): unknown[];
/**
 * Build placeholder tool results for the shared prefix.
 * When parent has pending tool_calls, replace them all with identical placeholder text
 * so all fork children produce byte-identical API request prefix.
 */
export declare function buildForkPlaceholderResults(pendingToolCallIds: string[]): Array<{
    role: "tool";
    tool_call_id: string;
    content: string;
}>;
/**
 * Resolve the effective tool set for a fork child.
 * CC pattern: useExactTools=true → child gets parent's full tool pool,
 * then filtered by agent definition.
 */
export declare function resolveForkChildTools(parentTools: string[], agent: AgentDefinition): string[];
/**
 * Generate a unique agent ID for a fork child.
 */
export declare function generateForkChildAgentId(parentAgentId: string, agentName: string, depth: number): string;
