import { type TaskObservedToolCall, type TaskSubagentResult, type TaskUsageStats } from './types.js';
export type TaskStatus = 'running' | 'completed' | 'failed' | 'killed';
export interface RegisteredTask {
    scopeId: string;
    agentId: string;
    name: string;
    subagentType: string;
    prompt: string;
    status: TaskStatus;
    isBackgrounded: boolean;
    runId: number;
    startedAt: number;
    completedAt?: number;
    transcriptFile?: string;
    outputFile: string;
    abortController: AbortController;
    sendMessage?: (message: string) => boolean;
    resumeMessage?: (message: string) => void;
    pendingMessages: string[];
    toolUses: number;
    activeToolUses: number;
    recentToolCalls: TaskObservedToolCall[];
    outputLines: string[];
    outputFileChars?: number;
    outputFileLines?: number;
    usage?: TaskUsageStats;
    resultText?: string;
    errorMessage?: string;
    notified: boolean;
}
export interface TaskSessionScope {
    getSessionFile?: () => string | undefined;
    getSessionId?: () => string | undefined;
    getHeader?: () => unknown;
}
/** Resolve the scope id used to key tasks — falls through subagent sessions to the top-level parent. */
export declare function getTaskScopeId(session: TaskSessionScope | undefined): string | undefined;
export declare class TaskManager {
    private readonly tasks;
    private readonly names;
    private readonly listeners;
    /** Register a new running task and return the populated record. */
    register(input: Omit<RegisteredTask, 'status' | 'isBackgrounded' | 'runId' | 'startedAt' | 'toolUses' | 'activeToolUses' | 'recentToolCalls' | 'outputLines' | 'pendingMessages' | 'notified'> & {
        isBackgrounded?: boolean;
    }): RegisteredTask;
    /** Return all tasks registered under a scope, ordered by start time. */
    list(scopeId: string): RegisteredTask[];
    /** Count tasks in the running state for a scope. */
    countRunning(scopeId: string): number;
    /** Subscribe to registry mutations; returns an unsubscribe function. */
    subscribe(listener: () => void): () => void;
    /** Look up a task by agent id or by task name; returns 'ambiguous' if a name resolves to multiple tasks. */
    get(scopeId: string, agentIdOrName: string): RegisteredTask | undefined | 'ambiguous';
    /** Apply a progress snapshot to a running task and notify subscribers. */
    updateProgress(scopeId: string, agentId: string, progress: number | {
        toolUses: number;
        transcriptFile?: string;
        toolCalls?: TaskObservedToolCall[];
        outputLines?: string[];
        activeToolUses?: number;
        usage?: TaskUsageStats;
        resultText?: string;
    }, transcriptFile?: string): void;
    /** Mark a task terminal, persist its output file, and return the updated record. */
    finish(scopeId: string, agentId: string, result: TaskSubagentResult, runId?: number): RegisteredTask | undefined;
    /** Atomically mark a task as having delivered its parent notification (returns false on duplicates). */
    markNotified(scopeId: string, agentId: string): boolean;
    /** Wire the runner's send-message callback to a registered task and flush queued messages. */
    attachSender(scopeId: string, agentId: string, sendMessage: (message: string) => boolean): void;
    /** Promote a foreground task to backgrounded so it survives the parent tool call. */
    background(scopeId: string, agentId: string): boolean;
    /** Abort a running task via its AbortController. */
    abort(scopeId: string, agentId: string): boolean;
    /** Remove a foreground task from the registry once the parent tool call resolves. */
    unregisterIfForeground(scopeId: string, agentId: string): void;
    /** Reset a terminal task to running state for a transcript-resume run. */
    restart(scopeId: string, agentId: string, abortController: AbortController): RegisteredTask | undefined;
    /** Clear all registered tasks (used by tests and session resets). */
    reset(): void;
    /** Deliver a follow-up message to a running task, queue if not yet wired, or restart from transcript. */
    routeMessage(scopeId: string, agentIdOrName: string, message: string): {
        ok: true;
        agentId: string;
    } | {
        ok: false;
        reason: string;
    };
    /** Try to deliver any messages that arrived before the runner attached its sender. */
    private flushPendingMessages;
    /** After a terminal finish, replay queued messages by triggering a transcript resume. */
    private resumePendingMessagesAfterTerminalFinish;
    /** Notify all subscribed listeners that the registry mutated. */
    private emitChange;
    /** Lazily create the task map for a scope. */
    private tasksForScope;
    /** Lazily create the name-to-id index for a scope. */
    private namesForScope;
}
export declare const taskManager: TaskManager;
export declare const TASK_NOTIFICATION_CUSTOM_TYPE = "taskNotification";
/** Render the XML notification block consumed by the parent agent loop. */
export declare function formatTaskNotification(task: RegisteredTask): string;
/** Render a compact two-line task summary suitable for the TUI display. */
export declare function formatTaskNotificationDisplay(task: RegisteredTask): string;
//# sourceMappingURL=manager.d.ts.map