/** * Shared DispatchManager factory. * * Platform-agnostic: does NOT import from @opencode-ai/plugin or * @earendil-works/pi-coding-agent. Both platform entry points * (DispatchService on OpenCode, pi-extension on Pi) use this factory * to construct a DispatchManager with identical configuration and * lineage registration logic. * * @module */ import { DispatchManager } from "./core/manager.ts"; import type { DispatchManagerConfig } from "./config.ts"; import type { ISessionClient } from "../platform/ports/session-client.ts"; import type { ResolvedRole } from "../types.ts"; /** Options for createDispatchManager. */ export interface CreateDispatchManagerOptions { /** Platform-specific session client (OpenCode SDK, Pi process spawn, etc.). */ sessionClient: ISessionClient; /** Fully resolved roles (with subagents already expanded). */ resolvedRoles: ResolvedRole[]; /** Directory used for task state persistence. */ storeDirectory: string; /** Optional primary role override (if omitted, the factory selects among the * roles with mode: primary — preferring the first that carries a dispatch * config block, falling back to the first primary in array order). */ primaryRole?: ResolvedRole; /** Optional config overrides applied with highest precedence. */ configOverrides?: Partial; } /** Return value of createDispatchManager. */ export interface CreateDispatchManagerResult { manager: DispatchManager; resolvedSubagents: Map; subagentModelKey: Map; /** Set if `recover()` failed. The manager is still usable with empty state. */ recoverError?: Error; } /** * Result of {@link buildSubagentLineage}. */ export interface SubagentLineageResult { resolvedSubagents: Map; subagentModelKey: Map; /** Maps every resolved subagent (any nesting depth) and every root role id * to the id of its OWNING root role — the role prefix of composite * concurrency keys and the key into roleConfigs. */ subagentRoleKey: Map; } /** * Builds resolvedSubagents, subagentModelKey, and subagentRoleKey maps from * resolved roles. Models cascade down: a child without an explicit model * inherits its parent's model. subagentRoleKey maps every descendant subagent * (any nesting depth) to the ROOT role id at the top-level call, so role-scoped * configs and concurrency keys resolve uniformly regardless of depth. * * Exported separately so callers that already have a cached * DispatchManager (e.g., DispatchService on hot-reload) can rebuild * lineage maps without constructing a new manager. */ export declare function buildSubagentLineage(resolvedRoles: ResolvedRole[]): SubagentLineageResult; /** * Build per-role merged dispatch configs for EVERY resolved role. * * Each role (primary and subagent modes alike) gets an entry: the merged * result of default → role dispatch config → env overrides, then * configOverrides applied with highest precedence. The manager-wide * finalConfig (governed by the effective primary role) is separate and still * built inside createDispatchManager — this map feeds role-scoped config * resolution (effectiveConfigFor) and per-role concurrency limits. */ export declare function buildRoleConfigs(resolvedRoles: ResolvedRole[], configOverrides?: Partial): Map; /** * Create a fully initialized DispatchManager. * * Handles subagent lineage registration, config merge (default → primary * role dispatch config → env overrides → configOverrides), manager * construction, setStoreDirectory, and recover(). * * If recover() fails, the error is returned as `recoverError` in the * result rather than thrown. The manager is still usable with empty state. * Platform entry points decide how to handle recovery failure (OpenCode * degrades gracefully; Pi aborts initialization). */ export declare function createDispatchManager(opts: CreateDispatchManagerOptions): Promise; //# sourceMappingURL=factory.d.ts.map