import type { ToolDefinition } from "@sheason/pi-coding-agent";
import { HubAgentAdapter } from "../agent/hub-agent-adapter.js";
import type { CreateHubAgentAdapterOptions } from "../agent/types.js";
import { AgentRegistry } from "../agents/agent-registry.js";
import type { ChildAgentToolHost, CreateChildToolInput, CreateGuestAgentToolInput, CreateTemporaryChildToolInput, ForkChildToolInput, ListMemoryToolInput, RemoveChildToolInput, RenameChildToolInput, SearchMemoryToolInput, SpawnChildToolInput, StartChildToolInput, StopChildToolInput, UpdateChildToolInput } from "../agents/child-agent-tools.js";
import type { GroupToolHost, UpdateAgentDescriptionToolInput, UpdateAgentSummaryToolInput } from "../agents/group-tools.js";
import { HubAgentRuntime } from "../agents/hub-agent-runtime.js";
import type { ResourceStatusToolHost } from "../agents/resource-status-tool.js";
import type { AgentRecord } from "../agents/types.js";
import { HubAuthTokenStore } from "../auth/token-store.js";
import type { AgentTokenToolHost, CreateAgentTokenToolInput, RevokeAgentTokenToolInput } from "../auth/token-tools.js";
import { type SpawnProcess } from "../executors/container-executor.js";
import type { McpClientHandle } from "../mcp/mcp-client.js";
import { McpHost } from "../mcp/mcp-host.js";
import type { McpServerConfig } from "../mcp/types.js";
import { PeerRegistry } from "../peers/peer-registry.js";
import { HubSessionService } from "../session/hub-session-service.js";
import type { HubSessionEvent } from "../session/session-events.js";
import { SourceHost } from "../sources/source-host.js";
import type { PeerToolBridge } from "../tools/peer-tool-bridge.js";
import { type PublicOrgSnapshot } from "../transport/protocol.js";
import { type SocketHubServerAddress } from "../transport/socket-hub-server.js";
import type { HubLogSink } from "../tui/hub-log.js";
export interface StartHubRuntimeOptions {
    host?: string;
    port?: number;
}
/**
 * Test-only and advanced wiring for hub bootstrap.
 * Production `HubRuntime.open(cwd)` leaves `mcp` unset; tests may inject
 * a fake `createClient` to avoid real MCP processes.
 */
export interface HubRuntimeOpenOptions {
    mcp?: {
        createClient?: (config: McpServerConfig, opts: {
            timeoutMs: number;
        }) => Promise<McpClientHandle>;
    };
    executors?: {
        containerSpawn?: SpawnProcess;
    };
    logs?: HubLogSink;
}
type InitializeAdapterOptions = Omit<CreateHubAgentAdapterOptions, "sessionService" | "tools" | "cwd">;
type AgentHydrationStatus = "running" | "loading" | "not_hydrated" | "error";
export declare class HubRuntime implements ChildAgentToolHost, GroupToolHost, ResourceStatusToolHost, AgentTokenToolHost {
    readonly cwd: string;
    readonly agentRegistry: AgentRegistry;
    readonly authTokenStore: HubAuthTokenStore;
    readonly sourceHost: SourceHost;
    readonly mcpHost: McpHost;
    readonly rootTokenForDisplay: string | undefined;
    private readonly socketServer;
    private readonly agentRuntimes;
    private readonly configLayers;
    private readonly memoryStore;
    private readonly adapterUserOptions;
    private liveEventUnsubs;
    private readonly createMcpClient;
    private readonly logs;
    private readonly containerExecutorLauncher;
    private readonly containerExecutorHandles;
    private socketAddress;
    private readonly pendingPeerConfigChangesByAgentId;
    private readonly peerConfigApplyInFlightByAgentId;
    private readonly sessionLogUnsubs;
    private readonly memoryIndexUnsubs;
    private readonly temporaryCleanupUnsubs;
    private readonly temporaryCleanupInFlight;
    private readonly childStartInFlightByAgentId;
    private readonly childStartErrorsByAgentId;
    private readonly manuallyStoppedAgentIds;
    private backgroundChildHydrationStarted;
    private stopping;
    private sessionFanout;
    private constructor();
    private log;
    get sessionService(): HubSessionService;
    get peerRegistry(): PeerRegistry;
    get tools(): ToolDefinition[];
    get peerToolBridge(): PeerToolBridge;
    get agentAdapter(): HubAgentAdapter | undefined;
    set agentAdapter(value: HubAgentAdapter | undefined);
    getAgentRecords(): AgentRecord[];
    getRootAgentRuntime(): HubAgentRuntime;
    getAgentRuntime(agentId?: string): HubAgentRuntime;
    tryGetAgentRuntime(agentId: string): HubAgentRuntime | undefined;
    getAgentHydrationStatus(agentId: string): AgentHydrationStatus;
    getPublicOrgSnapshot(): PublicOrgSnapshot;
    isAgentInSubtree(scopeRootAgentId: string, targetAgentId: string): boolean;
    /** Ids of all known agents. Child runtimes may hydrate lazily on first use. */
    getAllMessagingAgentIds(): string[];
    deliverMessageToGuest(senderAgentId: string, targetAgentId: string, message: string, options?: {
        messageId?: string;
        responseIds?: string[];
    }): boolean;
    /**
     * Subscribes to `HubSessionService` activity for every running agent, forwarding `(agentId, event)` until unsubscribed.
     * New agents added after `SocketHubServer.start()` are wired automatically.
     */
    subscribeAllSessionServiceEvents(listener: (agentId: string, event: HubSessionEvent) => void): () => void;
    static open(cwd?: string, openOptions?: HubRuntimeOpenOptions): HubRuntime;
    getMcpHostForAgent(agentId: string): McpHost | undefined;
    getMcpServerStatusesForAgent(agentId: string): import("../mcp/types.js").McpRuntimeStatus[];
    private resolvePeerForTool;
    private getVisibleExecutorPeersForAgent;
    getSourceStatusesForAgent(agentId: string): import("../index.js").SourceRuntimeStatus[];
    private getSourceMessageTargetAgentIds;
    private buildConfigLayersForAgent;
    private refreshAgentListViews;
    private setPeerConfigSnapshot;
    private removePeerConfigSnapshot;
    private queuePeerConfigChange;
    private applyPendingPeerConfigBeforeInput;
    private applyPendingPeerConfigForAgent;
    private applyPendingPeerConfigForAgentOnce;
    /** Check if any pending peer config change requires a full adapter restart. */
    private pendingChangesRequireFullRestart;
    initializeAgentAdapter(options?: InitializeAdapterOptions): Promise<HubAgentAdapter>;
    private createChildHubAgentRuntime;
    private ensureAgentRuntimeRegistered;
    createGuestAgent(callerAgentId: string, input: CreateGuestAgentToolInput): Promise<string>;
    ensureAgentStarted(agentId: string, reason?: string): Promise<HubAgentRuntime | undefined>;
    private wireSessionFanoutForNewAgent;
    private wireSessionLogForAgent;
    private unwireSessionLogForAgent;
    private wireMemoryIndexForAgent;
    private unwireMemoryIndexForAgent;
    private indexAgentMemory;
    private wireLiveEventsForAgent;
    private unwireSessionFanoutForAgent;
    private unwireLiveEventsForAgent;
    private static materializeSessionManagerToDisk;
    /**
     * Test hook: how many `subscribeAllSessionServiceEvents` calls are still active (unsub not run).
     * @internal
     */
    getSessionFanoutEntryCountForTest(): number;
    private assertAgentInSubtree;
    /**
     * After `agentRegistry` + session file are persisted, if adapter start fails, remove the registry row and
     * session file so disk matches the in-memory runtime map.
     */
    private rollbackPersistedChildRecordIfPresent;
    private createPeerConnectCommand;
    private createGuestAcpConnectCommand;
    private static tryUnlinkFile;
    private continueChildCurrentTranscript;
    private writeChildResourceExtendsConfig;
    private refreshSourcesForChildExtends;
    private startBackgroundChildHydration;
    private hydrateChildAgentsInBackground;
    private startSourceHostAfterChildHydration;
    private addAndStartNewChildFromRegistry;
    private containerExecutorKey;
    private getHubUrlForContainerExecutors;
    private startContainerExecutorsForAgent;
    private startContainerExecutorsForRunningAgents;
    private stopContainerExecutorsForAgent;
    private stopAllContainerExecutors;
    private maybeTrackTemporaryChild;
    private cleanupTemporaryChild;
    private reportTemporaryChildResult;
    private extractLastAssistantText;
    createChildAgent(callerAgentIdOrInput: string | CreateChildToolInput, maybeInput?: CreateChildToolInput): Promise<string>;
    createTemporaryChildAgent(callerAgentId: string, input: CreateTemporaryChildToolInput): Promise<string>;
    spawnChildAgent(parentAgentId: string, input: SpawnChildToolInput & {
        temporary?: boolean;
        reportResult?: boolean;
    }): Promise<string>;
    private createContainerExecutorConfigs;
    groupText(callerAgentId: string): Promise<string>;
    resourceStatusText(callerAgentId: string): Promise<string>;
    updateAgentDescriptionText(callerAgentId: string, input: UpdateAgentDescriptionToolInput): Promise<string>;
    updateAgentSummaryText(callerAgentId: string, input: UpdateAgentSummaryToolInput): Promise<string>;
    updateChildAgent(callerAgentId: string, input: UpdateChildToolInput): Promise<string>;
    renameChildAgent(callerAgentId: string, input: RenameChildToolInput): Promise<string>;
    createAgentTokenText(callerAgentId: string, input: CreateAgentTokenToolInput): Promise<string>;
    revokeAgentTokenText(callerAgentId: string, input: RevokeAgentTokenToolInput): Promise<string>;
    forkChildAgent(parentAgentId: string, input: ForkChildToolInput): Promise<string>;
    private requireChildRecordForLifecycle;
    stopChildAgent(callerAgentId: string, input: StopChildToolInput): Promise<string>;
    startChildAgent(callerAgentId: string, input: StartChildToolInput): Promise<string>;
    removeChildAgent(callerAgentId: string, input: RemoveChildToolInput): Promise<string>;
    private removeChildAgentInternal;
    private revokeTokensScopedToAgents;
    listAgentsText(): Promise<string>;
    private static messagePlainText;
    searchMemoryText(callerAgentId: string, input: SearchMemoryToolInput): Promise<string>;
    listMemoryText(callerAgentId: string, input: ListMemoryToolInput): Promise<string>;
    private getMemoryScopeAgentIds;
    private assertMemoryIdsInScope;
    private refreshMemoryIndexForScope;
    private indexRegisteredAgentMemory;
    start(options?: StartHubRuntimeOptions): Promise<SocketHubServerAddress>;
    /**
     * Terminal shutdown for this `HubRuntime` instance: tears down live forwarding, every `HubAgentRuntime`, source and
     * MCP hosts, and the socket server, then **clears** the internal agent-runtime map. Do not reuse this instance;
     * open a new hub with `HubRuntime.open()` if you need another lifecycle.
     */
    stop(): Promise<void>;
}
export {};
//# sourceMappingURL=hub-runtime.d.ts.map