import type { Message, Provider, ThinkingLevel } from "@kenkaiiii/gg-ai";
import { type AgentDefinition } from "./agents.js";
import { SubAgentStore } from "./subagent-store.js";
import { type SubAgentTokenUsage } from "../tools/subagent-shared.js";
export type SubAgentState = "starting" | "running" | "completed" | "failed" | "interrupted" | "closed" | "reaped";
export interface SubAgentSnapshot {
    agent_id: string;
    task_name: string;
    state: SubAgentState;
    started_at: number;
    updated_at: number;
    elapsed_ms: number;
    current_activity?: string;
    turn_count: number;
    tool_use_count: number;
    token_usage: SubAgentTokenUsage;
    output?: string;
    error?: string;
    agent_name?: string;
    provider?: string;
    model?: string;
    child_session_id?: string;
    child_session_path?: string;
    collected?: boolean;
    recovered?: boolean;
}
export interface SubAgentManagerOptions {
    cwd: string;
    agents: AgentDefinition[];
    getProvider: () => Provider;
    getModel: () => string;
    getThinkingLevel: () => ThinkingLevel | undefined;
    getCacheKey?: () => string | undefined;
    getBaseUrl?: () => string | undefined;
    /** Optional per-model concurrency cap (subagentMaxPerModel setting). Counted
     *  against the RESOLVED child model — read-only agents may run on the fast
     *  model, so they count under that model, not the parent's. Only ever
     *  reduces concurrency below the global ACTIVE_LIMIT. */
    getMaxPerModel?: () => number | undefined;
    onState?: (snapshot: SubAgentSnapshot) => void;
    workerEntry?: string;
    idleTimeoutMs?: number;
    store?: SubAgentStore;
    sessionRootDir?: string;
}
/** Shared pre-finalization hook used by both AgentSession and the Ink host. */
export declare function buildSubAgentCompletionFollowUp(manager: Pick<SubAgentManager, "completionGateMessage"> | undefined): Message[] | null;
export declare class SubAgentManager {
    private readonly options;
    private readonly workers;
    private readonly snapshots;
    private readonly listeners;
    private shuttingDown;
    private shutdownPromise?;
    private readonly store;
    private readonly sessionRootDir;
    private parentSessionId?;
    private persistQueue;
    private persistPending;
    private persistScheduled;
    constructor(options: SubAgentManagerOptions);
    /** Restore bounded history; dead in-flight workers become honestly interrupted. */
    hydrate(parentSessionId: string): Promise<void>;
    /** Rebind durable child history after parent compaction creates a continuation. */
    rebindParentSession(parentSessionId: string): Promise<void>;
    /** A genuinely new parent starts with no unrelated child history. */
    resetParentSession(parentSessionId: string): Promise<void>;
    waitForPersistence(): Promise<void>;
    spawn(taskName: string, task: string, agentName?: string): Promise<SubAgentSnapshot>;
    sendMessage(agentId: string, message: string): Promise<number>;
    followup(agentId: string, task: string): Promise<SubAgentSnapshot>;
    interrupt(agentId: string, collectResult?: boolean): Promise<SubAgentSnapshot>;
    subscribe(listener: (snapshot: SubAgentSnapshot) => void): () => void;
    list(): SubAgentSnapshot[];
    wait(agentIds?: string[], condition?: "any" | "all", timeoutMs?: number): Promise<{
        timed_out: boolean;
        agents: SubAgentSnapshot[];
    }>;
    completionGate(): {
        active: SubAgentSnapshot[];
        uncollected: SubAgentSnapshot[];
        unresolved: number;
    };
    completionGateMessage(): string | undefined;
    interruptAll(): Promise<void>;
    shutdownAll(): Promise<void>;
    /** Synchronous process-exit fallback: terminate detached process groups immediately. */
    shutdownAllNow(): void;
    private markCollected;
    private spawnWorkerProcess;
    private respawnRecovered;
    private attach;
    private handleFrame;
    private request;
    private waitForChange;
    private publish;
    private snapshot;
    private queuePersist;
    private elapsed;
    private activeCount;
    /** Enforce the optional per-model cap against the resolved child model. */
    private assertModelCapacity;
    private isActive;
    private isTerminal;
    private requireWorker;
    private assertAvailable;
    private assertChildSessionPath;
    private createId;
    private scheduleIdleReap;
    private reapExcessIdle;
    private fail;
    private close;
    private kill;
}
//# sourceMappingURL=subagent-manager.d.ts.map