import type { AgentRegistry } from '../../registry/agent/definitions.js';
import { type CapacityValidator, DelegationCapacityExceeded } from '../../session/handoff/capacity.js';
import type { SessionSummaryMaterializer } from '../../session/summary/materialize.js';
import type { WorkspaceBackendRegistry } from '../../session/workspace/registry.js';
import type { AgentLifecycleListener } from '../../types/agent/lifecycle-event.js';
import type { AgentManagerConfig, AgentTask, AgentTaskContext, AgentTaskState, SendMessageOptions } from '../../types/agent/task.js';
import type { RunId, SessionId, TaskId, TenantId } from '../../types/ids/index.js';
import type { Message } from '../../types/message/index.js';
import type { RunEventListener } from '../../types/run/events.js';
import type { SubSessionId } from '../../types/session/ids.js';
import type { SessionStore } from '../../types/session/store.js';
import type { WorkspaceRef } from '../../types/workspace/ref.js';
import type { ThreadManager } from '../thread/lifecycle.js';
/**
 * Dependencies threaded into {@link AgentManager}. Phase 6 promoted the
 * SubSession + Session + WorkspaceRef triple to mandatory spawn primitives —
 * these collaborators replace the old `Object.assign({sourceAgentId,
 * parentTaskId})` loose-cast cadence with a typed {@link Lineage} +
 * {@link SessionSummaryMaterializer} closure of the parent→child message gap.
 *
 * Phase 9 Known Delta #5: fields are now unconditional required. The legacy
 * "run without deps" compat branch was removed; every `AgentManager` consumer
 * (SDK internals, `@namzu/agents`, `@namzu/api`, `@namzu/cli`) MUST wire the
 * full set before instantiating. Convention #0 (no workarounds): the
 * partially-wired mode was a migration-window bridge; 0.2.0 closes it.
 *
 * `workspaceRegistry` is required but may be empty — spawns without a
 * registered workspace backend still succeed with `workspaceRef: undefined`
 * (the runtime uses `.has(backend)` to gate provisioning). This keeps the
 * registry deny-by-default while matching pattern doc §7.1 (lazy workspace
 * provisioning).
 */
export interface AgentManagerDeps {
    readonly sessionStore: SessionStore;
    readonly workspaceRegistry: WorkspaceBackendRegistry;
    readonly summaryMaterializer: SessionSummaryMaterializer;
    readonly capacity: CapacityValidator;
    /**
     * Gate session creation on the parent Thread being `'open'` via
     * {@link ThreadManager.requireOpen}. Added in Phase 2.6 to close the
     * archive-gate gap flagged by the Phase 2.5 commit: without this,
     * `ThreadManager.archive` was best-effort because spawn could still
     * attach a live session under an archived Thread.
     */
    readonly threadManager: ThreadManager;
}
interface ChildSpawnRecord {
    subSessionId: SubSessionId;
    childSessionId: SessionId;
    tenantId: TenantId;
    parentSessionId: SessionId;
    rootSessionId: SessionId;
    childDepth: number;
    workspaceRef?: WorkspaceRef;
}
export declare class AgentManager {
    private registry;
    private instances;
    private spawnRecords;
    private completionCallbacks;
    private listeners;
    private log;
    private config;
    private evictionTimers;
    private deps;
    constructor(registry: AgentRegistry, config: Partial<AgentManagerConfig> | undefined, deps: AgentManagerDeps);
    sendMessage(options: SendMessageOptions, context: AgentTaskContext, listener?: RunEventListener): Promise<AgentTask>;
    cancel(taskId: TaskId): void;
    cancelAll(parentRunId: RunId): void;
    continueTask(taskId: TaskId, message: string): Promise<void>;
    queueMessage(taskId: TaskId, message: Message): void;
    drainMessages(taskId: TaskId): Message[];
    waitForCompletion(taskId: TaskId): Promise<void>;
    getInstance(taskId: TaskId): AgentTask | undefined;
    getSpawnRecord(taskId: TaskId): ChildSpawnRecord | undefined;
    listByParent(parentRunId: RunId): AgentTask[];
    listActive(): AgentTask[];
    getState(taskId: TaskId): AgentTaskState | undefined;
    getRegistry(): AgentRegistry;
    on(listener: AgentLifecycleListener): void;
    off(listener: AgentLifecycleListener): void;
    cleanup(): void;
    dispose(): void;
    private provisionSpawn;
    private runChild;
    /**
     * Wraps the parent listener so every event emitted from the child's run
     * carries the session-hierarchy `lineage` + `schemaVersion: 2` stamp.
     * Replaces the old `Object.assign({sourceAgentId, parentTaskId}, event)`
     * loose-cast pattern entirely — the types now encode the linkage.
     */
    private wrapChildListener;
    private finalizeChild;
    private markCompleted;
    private markFailed;
    private failSubSession;
    private markCanceled;
    private updateState;
    private requireInstance;
    private scheduleEviction;
    private resolveCompletionCallbacks;
    private clearEvictionTimer;
    private emit;
    private emitRunEvent;
}
export { DelegationCapacityExceeded };
//# sourceMappingURL=lifecycle.d.ts.map