import type { ThinkingLevel } from "@sheason/pi-agent-core";
import type { Api, Model } from "@sheason/pi-ai";
import type { AgentSessionServices, ToolDefinition } from "@sheason/pi-coding-agent";
import { HubAgentAdapter } from "../agent/hub-agent-adapter.js";
import type { CreateHubAgentAdapterOptions } from "../agent/types.js";
import { type AgentTokenToolHost } from "../auth/token-tools.js";
import type { PeerMcpIndexSnapshot } from "../config-aggregation/agent-config-services.js";
import type { ConfigLayerRegistry } from "../config-aggregation/config-layer-registry.js";
import type { PeerConfigJsonLayers } from "../config-aggregation/types.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 type { RegisteredPeer } from "../peers/peer-types.js";
import type { HubSessionService } from "../session/hub-session-service.js";
import { PeerToolBridge } from "../tools/peer-tool-bridge.js";
import type { LiveRenderEvent } from "../transport/live-events.js";
import type { SocketHubServer } from "../transport/socket-hub-server.js";
import type { HubLogSink } from "../tui/hub-log.js";
import { type AgentMessagingToolHost } from "./agent-messaging-tools.js";
import { type ChildAgentToolHost } from "./child-agent-tools.js";
import { type GroupToolHost } from "./group-tools.js";
import { type ResourceStatusToolHost } from "./resource-status-tool.js";
import type { AgentModelRef, AgentRecord } from "./types.js";
export interface HubAgentRuntimeOptions {
    cwd: string;
    record: AgentRecord;
    sessionService: HubSessionService;
    socketServer: SocketHubServer;
    /** If omitted, a new `PeerRegistry` is created. Hub orchestration can inject the main registry to match the socket. */
    peerRegistry?: PeerRegistry;
    agentDir?: string;
    getConfigLayers?: () => PeerConfigJsonLayers[];
    /** ConfigLayerRegistry for discover_peer_resources tool to read peer config at runtime. */
    configLayerRegistry?: ConfigLayerRegistry;
    /** Getter for peer MCP snapshots for discover_peer_resources tool. */
    peerMcpSnapshotsGetter?: () => PeerMcpIndexSnapshot[];
    mcp?: {
        configPath: string;
        configRoot?: () => unknown;
        createClient?: (config: McpServerConfig, opts: {
            timeoutMs: number;
        }) => Promise<McpClientHandle>;
    };
    createAgentAdapter?: (options: CreateHubAgentAdapterOptions) => Promise<HubAgentAdapter>;
    sharedTools?: ToolDefinition[];
    agentTools?: ToolDefinition[];
    refreshSources?: () => Promise<void>;
    refreshMcp?: () => Promise<void>;
    model?: Model<Api>;
    thinkingLevel?: ThinkingLevel;
    scopedModels?: Array<{
        model: Model<Api>;
        thinkingLevel?: ThinkingLevel;
    }>;
    services?: AgentSessionServices;
    prepareServices?: (services: AgentSessionServices) => Promise<void> | void;
    beforeInputQueueDrain?: CreateHubAgentAdapterOptions["beforeInputQueueDrain"];
    logs?: HubLogSink;
    /** When set on the main agent, registers main-only child management tools. */
    getChildAgentHost?: () => ChildAgentToolHost;
    /** Resolves `HubRuntime` (or test double) for agent-to-agent messaging tools; all hub agents use this. */
    getAgentMessagingHost?: () => AgentMessagingToolHost;
    /** Resolves `HubRuntime` for group identity and agent description tools; all hub agents use this. */
    getGroupHost?: () => GroupToolHost;
    /** Resolves `HubRuntime` for source/MCP/skill status inspection; all hub agents use this. */
    getResourceStatusHost?: () => ResourceStatusToolHost;
    /** Resolves `HubRuntime` for creating scoped access tokens; all hub agents use this. */
    getAgentTokenHost?: () => AgentTokenToolHost;
    /** Resolves executor peers visible to this agent's tree scope. */
    resolvePeerForTool?: (callerAgentId: string, peerId: string) => RegisteredPeer | undefined;
    /** Called when the agent's model selection changes, so the caller can persist it. */
    persistModelRef?: (agentId: string, modelRef: AgentModelRef) => void;
}
/**
 * Per-agent shell: session service wiring, peer registry/bridge, tools, and optional hub agent adapter.
 * Intended for future multi-agent `HubRuntime` orchestration; safe to use for a single main agent.
 *
 * **Lifecycle:** each instance is one-shot. After `stop()` finishes, the bridge is disposed and
 * the runtime is closed. To run an agent again, construct a new `HubAgentRuntime` (or have
 * orchestration do so) rather than reusing a stopped instance.
 */
export declare class HubAgentRuntime {
    readonly record: AgentRecord;
    readonly sessionService: HubSessionService;
    readonly peerRegistry: PeerRegistry;
    readonly peerToolBridge: PeerToolBridge;
    readonly tools: ToolDefinition[];
    readonly mcpHost: McpHost | undefined;
    agentAdapter: HubAgentAdapter | undefined;
    private readonly cwd;
    private readonly agentDir?;
    private readonly createAgentAdapterImpl;
    private readonly getConfigLayers;
    private readonly getChildAgentHost;
    private readonly refreshSources?;
    private readonly refreshMcp?;
    private readonly model?;
    private readonly thinkingLevel?;
    private readonly scopedModels?;
    private readonly services?;
    private readonly prepareServices?;
    private readonly beforeInputQueueDrain?;
    private readonly logs;
    private readonly persistModelRefCallback?;
    private readonly liveEventSubscribers;
    private readonly remoteMcpToolNames;
    private adapterLiveUnsub;
    private startInFlight;
    /** `stop()` sets this so `runStart` can avoid committing an adapter (or can dispose) after a slow `create`. */
    private abortStartRequested;
    /** `true` from the beginning of `stop()` through full teardown; not cleared until `close()`-equivalent. */
    private closed;
    private stopInFlight;
    private peerBridgeActive;
    constructor(options: HubAgentRuntimeOptions);
    subscribeLiveEvents(listener: (event: LiveRenderEvent) => void): () => void;
    start(): Promise<void>;
    private runStart;
    private refreshRemoteMcpTools;
    restartAdapter(): Promise<void>;
    stop(): Promise<void>;
    private runStop;
}
//# sourceMappingURL=hub-agent-runtime.d.ts.map