import { S as Scope, a as ResultBlobStore, B as Budget, A as Agent, b as SupervisedResult } from './types-CogNCaw7.js';
import { M as MakeWorkerAgent, A as AnalystRegistry, E as ExecutorConfig } from './coordination-o0TzS7Ms.js';
import { R as RouterConfig, T as ToolLoopChat, a as ToolLoopCompactionOptions } from './sanitize-Dcbjp0tU.js';
import { D as DeliverableSpec } from './completion-gate-tzwyyD-E.js';

/** The supervisor's profile — the subset of an `AgentProfile` that selects + shapes its brain.
 *  `harness` is the backend-as-data discriminant; `systemPrompt` is the standing instruction. */
interface SupervisorProfile {
    readonly name?: string;
    /** null/undefined → router brain (in-process tool-loop); a coding-CLI harness → sandboxed brain. */
    readonly harness?: string | null;
    /** The router model when the brain is router-driven (falls back to the deps router config). */
    readonly model?: string;
    /** The standing instructions ("you delegate, you do not solve"). */
    readonly systemPrompt?: string;
}
/** How to run a sandboxed harness as the DRIVER, with the coordination verbs mounted — the substrate
 *  seam the caller supplies (mirrors `makeWorkerAgent` for spawned children). It runs `profile` on
 *  `task` in its backend (sandbox / cli-bridge) with `coordinationMcpUrl` mounted as an MCP server,
 *  so the harness calls spawn_agent / await_event / stop as native tools over the live scope. */
type DriveHarness = (args: {
    readonly profile: SupervisorProfile;
    readonly task: unknown;
    readonly scope: Scope<unknown>;
    readonly coordinationMcpUrl: string;
}) => Promise<void>;
interface SupervisorAgentDeps {
    readonly blobs: ResultBlobStore;
    /** Resolve a spawned worker `profile` to a leaf agent — the recursion seam (same for both arms). */
    readonly makeWorkerAgent: MakeWorkerAgent;
    /** Per-child budget reserved from the conserved pool on each spawn. */
    readonly perWorker: Budget;
    /** Hard cap on simultaneously-LIVE workers across both arms — `spawn_agent` fails closed once
     *  this many are in flight (a concurrency fence on top of the conserved-pool fence; bounds live
     *  boxes/sandboxes, not total work). Omit/`<= 0` = no cap. */
    readonly maxLiveWorkers?: number;
    /** Router substrate for a router-brained supervisor (`harness` null). The profile's model wins. */
    readonly router?: RouterConfig;
    /** Inject the brain directly (tests / advanced) instead of resolving `routerBrain` from the profile. */
    readonly brain?: ToolLoopChat;
    /** Required for a sandboxed-harness supervisor (`harness` set): runs the harness as the driver. */
    readonly driveHarness?: DriveHarness;
    /** WORK tools the supervisor may call DIRECTLY (router arm) — so it can do simple work ITSELF and
     *  only delegate when it needs parallelism. Pair with `executeExtraTool`. */
    readonly extraTools?: ReadonlyArray<{
        readonly name: string;
        readonly description?: string;
        readonly parameters: Record<string, unknown>;
    }>;
    /** Runs an `extraTools` call; null/undefined falls through to the coordination dispatch. */
    readonly executeExtraTool?: (name: string, args: Record<string, unknown>) => Promise<string | null | undefined>;
    /** Analyst lenses available to the driver (both arms). Required for `analyzeOnSettle`. */
    readonly analysts?: AnalystRegistry;
    /** Analyst kinds run on each worker-settle → a `finding` the driver composes its next steer from
     *  (the self-improving UP-leg). Unset/empty = status quo (no analyst feed). Requires `analysts`. */
    readonly analyzeOnSettle?: ReadonlyArray<string>;
    readonly maxTurns?: number;
    /** Give the supervisor brain a chapter-lifecycle on its OWN context window (router arm only) — it
     *  distills its coordination transcript to a compact progress note once it exceeds the threshold,
     *  instead of re-billing the whole thing every turn. See `DriverAgentOptions.compaction`. */
    readonly compaction?: ToolLoopCompactionOptions;
}
/** Build a supervisor `Agent` from its profile: the brain resolves from `profile.harness` (backend-as-data), the same resolution rule as every worker. */
declare function supervisorAgent(profile: SupervisorProfile, deps: SupervisorAgentDeps): Agent<unknown, unknown>;

/** Build the worker seam from a backend (WHERE workers run) + an optional completion oracle (the
 *  deliverable check that makes "settled ⟺ delivered" true — the guard against "ran but didn't
 *  deliver"). The ONE place a backend becomes a spawnable worker. */
declare function workerFromBackend(backend: ExecutorConfig, deliverable?: DeliverableSpec<unknown>): MakeWorkerAgent;
interface SuperviseOptions {
    /** The conserved compute pool for the whole run. */
    readonly budget: Budget;
    /** WHERE workers run — derives the worker seam. Provide this OR an explicit `makeWorkerAgent`. */
    readonly backend?: ExecutorConfig;
    /** The completion oracle for backend-derived workers (settled ⟺ delivered). Strongly recommended:
     *  without it the supervisor trusts a worker's self-report — exactly the "ran but didn't deliver"
     *  failure mode of a static orchestrator. */
    readonly deliverable?: DeliverableSpec<unknown>;
    /** Override the worker seam directly (tests / advanced) instead of deriving it from `backend`. */
    readonly makeWorkerAgent?: MakeWorkerAgent;
    /** The supervisor's router substrate (`harness` null). The profile's model wins. */
    readonly router?: RouterConfig;
    /** Inject the supervisor brain directly (tests / advanced). */
    readonly brain?: ToolLoopChat;
    /** Run a sandboxed-harness supervisor (`harness` set). */
    readonly driveHarness?: DriveHarness;
    /** WORK tools the supervisor may call DIRECTLY — so a recursive atom can ACT (do simple work
     *  itself) OR SPAWN (delegate when it needs parallelism), not be a pure manager. Pair with
     *  `executeExtraTool`. Router arm only (`harness` null). */
    readonly extraTools?: ReadonlyArray<{
        readonly name: string;
        readonly description?: string;
        readonly parameters: Record<string, unknown>;
    }>;
    /** Runs an `extraTools` call; null/undefined falls through to the coordination dispatch. */
    readonly executeExtraTool?: (name: string, args: Record<string, unknown>) => Promise<string | null | undefined>;
    /** Per-child budget reserved on each spawn. Defaults to a quarter of the pool's tokens. */
    readonly perWorker?: Budget;
    /** Hard cap on simultaneously-LIVE workers — `spawn_agent` fails closed once this many are in
     *  flight. The conserved pool bounds TOTAL work; this bounds SIMULTANEOUS work (live boxes/
     *  sandboxes a real fleet runs at once). Omit/`<= 0` = no cap (the pool stays the only fence). */
    readonly maxLiveWorkers?: number;
    /** Analyst lenses available to the driver. Required for `analyzeOnSettle`. Unset → status quo
     *  (the driver receives settled worker outputs, no analyst findings). */
    readonly analysts?: AnalystRegistry;
    /** Analyst kind ids run AUTOMATICALLY when a worker settles `done` — each re-enters as a `finding`
     *  the driver pulls (`await_event`) and composes its next steer from. The self-improving UP-leg,
     *  threaded to the driver at this level (propagate to sub-drivers via a recursive `makeWorkerAgent`).
     *  Omit/empty = status quo (no analyst feed). Requires `analysts`. */
    readonly analyzeOnSettle?: ReadonlyArray<string>;
    /** Worker output store. Defaults to in-memory. */
    readonly blobs?: ResultBlobStore;
    readonly maxDepth?: number;
    readonly maxTurns?: number;
    /** Give the supervisor brain a chapter-lifecycle on its OWN context window (router arm only): once
     *  its coordination transcript exceeds `thresholdTokens` it distills to a compact progress note and
     *  continues, instead of re-billing the whole transcript every turn (the cost that makes the LLM-brain
     *  front door lose to a dumb-Ralph respawn). The live `Scope` roster is the durable state across
     *  chapters. Default off. `distill` defaults to a brain self-summary + the settled-worker roster. */
    readonly compaction?: ToolLoopCompactionOptions;
    readonly runId?: string;
    readonly now?: () => number;
    /** Restrict the run to this subset of models. When set, every configured model — the
     *  supervisor router model, the profile's model, and the backend's model — must be a member,
     *  or `supervise()` throws a `ConfigError` before any compute is spent. Unset = unrestricted. */
    readonly allowedModels?: readonly string[];
}
/** One-call supervisor: build + run a supervisor from its profile with sensible defaults; the raw `supervisorAgent` + `createSupervisor().run` seams stay available for power use. */
declare function supervise(profile: SupervisorProfile, task: unknown, opts: SuperviseOptions): Promise<SupervisedResult<unknown>>;

export { type DriveHarness as D, type SupervisorProfile as S, type SuperviseOptions as a, type SupervisorAgentDeps as b, supervisorAgent as c, supervise as s, workerFromBackend as w };
