/** * Subagent Delegation Extension for Spectral * * Registers a `subagent` tool that allows the coding agent to delegate tasks * to specialized sub-agents running in-process via `agentLoop()`. * * Each subagent invocation runs with its own fresh AgentContext (isolated * context window), keeping the main conversation lean and focused. * * Three execution modes: * - Single: { agent: "name", task: "..." } * - Parallel: { tasks: [{ agent, task }, ...] } (max 8, 4 concurrent) * - Chain: { chain: [{ agent, task: "... {previous} ..." }, ...] } * * Agent definitions live as markdown files with YAML frontmatter: * - ~/.spectral/agent/agents/*.md (user-level, always loaded) * - .spectral/agents/*.md (project-level, opt-in via agentScope) * * Subagents use an in-process `agentLoop()` for: * - Clean context isolation (fresh messages array) * - Combined system prompt (shared/base prompt + subagent-specific instructions) * - Tool filtering (only the tools specified in agent config) * - Model selection (session model preferred, agent-configured as fallback) * - Signal propagation (abort passthrough) * - Access to observational memory via the `recall` and * `write_project_observation` tools, which run against a parent-session * point-in-time snapshot (branch + session id); other observation tools * (`share_project_observation`, `receive_agent_observations`, * `compact_context`, `subagent`) remain excluded */ import type { AgentTool } from "../sdk/agent-core/index.js"; import { type ExtensionAPI, type ExtensionContext } from "../sdk/coding-agent/index.js"; import { type AgentConfig } from "./agents.js"; import type { ServerEvent } from "../server/wire.ts"; import type { ReadonlySessionManager } from "../sdk/coding-agent/core/session-manager.js"; /** * Build the system prompt for a subagent session. * * The host session's base prompt may already contain an injected primary-agent * block (`# Primary Agent: ...` followed by an optional `\n\n---\n\n` delimiter). * A subagent must not inherit the host's primary agent, so the existing block is * stripped and replaced by the subagent's own primary-agent block (appended * below the base). Any content before or after the primary block (provider * preamble, shared base prompt) is preserved. */ export declare function buildSubagentSystemPrompt(baseSystemPrompt: string | undefined, agent: Pick): string; /** * Give subagents a point-in-time branch view without exposing the live parent * SessionManager. Each getBranch call returns fresh clones of the snapshot. */ export declare function createSubagentSessionManagerSnapshot(sessionManager: ExtensionContext["sessionManager"]): Pick; export declare function resolveSubagentTools(cwd: string, ext: ExtensionAPI, ctx: ExtensionContext): AgentTool[]; /** Test hook: replace the run-level retry sleep (e.g. with an instant/collecting stub). */ export declare function setSubagentRetrySleepForTesting(fn?: (ms: number, signal?: AbortSignal) => Promise): void; /** * Resolve the max number of child-run attempts for the run-level retry loop. * An explicit tool param (clamped to 0-10) overrides everything — including a * globally disabled retry switch. Without the param, the session default * (7 retries) applies unless retry is explicitly disabled, in which case a * single attempt is made. */ export declare function resolveSubagentMaxAttempts(explicit: number | undefined, settings: { enabled?: boolean; maxRetries?: number; } | undefined): number; export default function subagentExtension(ext: ExtensionAPI, opts?: { disabledAgents?: string[]; emitSubagentEvent?: (event: ServerEvent) => void; teamId?: string; }): void; //# sourceMappingURL=index.d.ts.map