/** * fork-subagent.ts — Fork subagent logic: boilerplate builder, guards, helpers. * * The fork pattern lets the LLM omit subagent_type to create a child that * inherits the parent's full conversation context (system prompt, history, * tool pool) with byte-identical API request prefixes for prompt cache * sharing across all fork children spawned from the same parent message. * * Reference: claude-code-main/src/tools/AgentTool/forkSubagent.ts */ /** XML tag wrapping fork boilerplate rules in the child's directive message. */ export declare const FORK_BOILERPLATE_TAG = "fork-boilerplate"; /** Prefix appended before the directive text in the child's first message. */ export declare const FORK_DIRECTIVE_PREFIX = "Your directive: "; /** Placeholder text used for every tool_result block in the fork prefix. * Must be identical across ALL fork children for prompt cache sharing. */ export declare const FORK_PLACEHOLDER_RESULT = "Fork started \u2014 processing in background"; /** Synthetic agent type name used for analytics when the fork path fires. */ export declare const FORK_SUBAGENT_TYPE = "fork"; export declare function isForkSubagentEnabled(): boolean; /** * Build the forked conversation messages for the child agent. * * For prompt cache sharing, all fork children must produce byte-identical * API request prefixes. This function: * 1. Keeps the full parent assistant message (all toolCall blocks, text) * 2. Builds a single user message with tool_result blocks for every toolCall * using an identical placeholder, then appends a per-child directive text * * Result: [assistant(all_toolCalls), user(placeholder_results, directive)] * Only the final text block differs per child, maximizing cache hits. */ export declare function buildForkedMessages(directive: string, assistantMessage: { role: "assistant"; content: any[]; [key: string]: any; }): any[]; export declare function buildChildMessage(directive: string): string; /** * Guard against recursive forking. Scans user messages for the fork * boilerplate tag. Returns true if the conversation history indicates * the current agent is already a fork child. */ export declare function isInForkChild(messages: any[]): boolean; /** * Notice injected into fork children running in an isolated worktree. * Tells the child to translate paths from the inherited context, re-read * potentially stale files, and that its changes are isolated. */ export declare function buildWorktreeNotice(parentCwd: string, worktreeCwd: string): string;