/** * Shared delegation (subagent) detection. * * A "delegation" is a tool call where one agent spawns or polls another agent * (Claude Code `Agent`/`Task`, Copilot `task`/`read_agent`). Both the server * (which materializes a linked child session — #1075) and the web * `AgentToolCard` (which renders the call) need to recognize delegations and * extract the same normalized fields, so the parser lives here as the single * source of truth rather than being duplicated per consumer. * * Detection is **arg-shape first, tool-name second**: tool names drift across * SDK versions, so the presence of a `prompt` plus a delegation-id field * (`subagent_type`/`agent_type`/`name`/`agent_id`) is what identifies a * delegation; the tool name is only a hint. * * @module */ /** Normalized info extracted from agent/subagent tool args across runtimes. */ export interface DelegationInfo { /** Agent type: "Explore", "Plan", "general-purpose", "worker", etc. */ agentType?: string; /** Short description of the subagent task. */ description?: string; /** Full prompt sent to the subagent. */ prompt?: string; /** Whether the subagent runs in the background. */ isBackground?: boolean; /** Model override (e.g. "sonnet", "opus"). */ model?: string; /** Copilot: human-readable agent name (e.g. "find-tests"). */ agentName?: string; /** Copilot read_agent: the agent_id being polled. */ agentId?: string; /** Whether this is a resume of a prior subagent. */ isResume?: boolean; /** Whether this is a read_agent poll (a correlation, not a fresh spawn). */ isPoll?: boolean; } /** * Parse agent/subagent tool args from all supported runtimes into a normalized * shape. Returns an empty object for non-object args. * * Handles: * - Claude Code `Agent` / `Task`: `{ subagent_type, description, prompt, run_in_background, model, resume }` * - Copilot `task`: `{ agent_type, description, prompt, mode, name }` * - Copilot `read_agent`: `{ agent_id }` * * @param tool - Tool name as reported by the runtime. * @param args - Parsed tool args object. * @returns Normalized delegation info (empty object if args is not an object). */ export declare function parseDelegationArgs(tool: string, args: unknown): DelegationInfo; /** * Decide whether a tool call is a delegation (spawning or polling a subagent). * * Arg-shape predicate (tool name is only a secondary hint): * - a `read_agent` poll is always a delegation reference (`isPoll`), or * - a spawn must carry a `prompt` **and** a delegation-id field * (`agentType` from subagent_type/agent_type, or Copilot `agentName`). * * Ordinary tools that merely have a `prompt` (e.g. a search tool) but no * delegation-id field are rejected, as are empty-prompt calls. * * @param tool - Tool name as reported by the runtime. * @param args - Parsed tool args object. * @returns Normalized {@link DelegationInfo} if this is a delegation, else `undefined`. */ export declare function detectDelegation(tool: string, args: unknown): DelegationInfo | undefined; /** * Stable identity key for a delegated subagent, used to deduplicate repeated * references to the same child (e.g. Copilot `read_agent` polls that follow the * original `task` spawn) onto one child session. * * Preference order: explicit `agentId` (Copilot) → `agentName` (Copilot) → * the originating tool-call id (Claude Code, which has no agent identity in its * args). The caller supplies `toolCallId` as the fallback. * * @param info - Parsed delegation info. * @param toolCallId - The originating tool_use call id (fallback identity). * @returns A non-empty identity key. */ export declare function delegationIdentityKey(info: DelegationInfo, toolCallId: string): string; /** Lifecycle status reported by a Copilot `read_agent` poll result. */ export type ReadAgentStatus = "completed" | "running" | "failed" | "error" | "cancelled"; /** * Extract the lifecycle status from a Copilot `read_agent` poll result, if it * carries the structured `"Agent . agent_id: …"` prefix. Shared so the * server (deciding when to close a polled child) and the web card render the * same status. * * @param result - The raw `read_agent` tool result text. * @returns The parsed status, or `undefined` if the prefix is absent. */ export declare function readAgentResultStatus(result: string): ReadAgentStatus | undefined; /** Prefix for materialized subagent child session ids. */ export declare const SUBAGENT_SESSION_PREFIX: string; /** * Runtime marker for materialized subagent child sessions (#1075). These are * not real PowerLine sessions — they are virtual activity logs attached to a * parent session — so env- and lifecycle-scoped queries (active/latest session, * reanimate, recovery) must exclude them by this runtime. */ export declare const SUBAGENT_RUNTIME: string; /** * Derive the deterministic child session id for a delegation. The server uses * this to create/resolve the child session; the web uses the *same* function to * compute the navigation target — so both always agree without a wire field. * * The id is a pure function of the parent session id and the delegation's * identity key, so repeated references to the same subagent (e.g. `read_agent` * polls) map to one id. The identity key is sanitized to keep the id URL- and * key-safe. * * @param parentSessionId - The delegating session id. * @param identityKey - From {@link delegationIdentityKey}. * @returns A deterministic, URL-safe child session id. */ export declare function deriveChildSessionId(parentSessionId: string, identityKey: string): string; //# sourceMappingURL=subagent.d.ts.map