import type * as http from 'http';
import type { Adapter } from '../core/types.js';
import type { ClientRegistry } from '../engines/client-registry.js';
import type { NexusEvent, NexusEventType } from '../engines/event-bus.js';
import type { MemoryEngine } from '../engines/memory.js';
import type { GovernorState, PressureLevel } from '../engines/machine-efficiency/index.js';
import type { OrchestratorEngine } from '../engines/orchestrator.js';
import type { RuntimeHealthEnvelope } from '../engines/runtime-health.js';
import type { RuntimeRegistry } from '../engines/runtime-registry.js';
import type { WorkspaceContext } from '../engines/workspace-resolver.js';
import type { SubAgentRuntime } from '../phantom/runtime.js';
import type { ArchitectsRuntime } from '../architects/index.js';
import type { SynapseRuntime } from '../synapse/index.js';
export interface DashboardServerOptions {
    runtimeProvider?: () => SubAgentRuntime | undefined;
    orchestratorProvider?: () => OrchestratorEngine | undefined;
    memoryProvider?: () => MemoryEngine | undefined;
    adaptersProvider?: () => Adapter[];
    clientRegistryProvider?: () => ClientRegistry | undefined;
    synapseProvider?: () => SynapseRuntime | undefined;
    architectsProvider?: () => ArchitectsRuntime | undefined;
    runtimeHealthProvider?: () => RuntimeHealthEnvelope;
    workspaceContextProvider?: () => WorkspaceContext;
    synapseInitErrorProvider?: () => {
        message: string;
        stack: string | null;
        at: number;
    } | null;
    reinitSynapseProvider?: () => void;
    repoRoot?: string;
}
export interface DashboardEventCard {
    id: string;
    type: NexusEventType;
    title: string;
    source: string;
    time: number;
    severity: 'good' | 'info' | 'warn' | 'bad';
    category: 'memory' | 'tokens' | 'runtime' | 'pod' | 'skills' | 'workflows' | 'clients' | 'system' | 'hooks' | 'automations' | 'shield' | 'federation' | 'mcp' | 'byzantine' | 'darwin';
    summary: string;
    payload: unknown;
}
export interface DashboardCompatibilityProbe {
    status: 'free' | 'compatible' | 'incompatible' | 'indeterminate';
    url: string;
    health?: DashboardHealthResponse;
    reason?: string;
    attempts?: number;
}
export interface DashboardProbeResponse {
    statusCode: number;
    body: string;
}
export interface DashboardHealthResponse {
    dashboardApiVersion: string;
    projectName?: string;
    currentRepoId?: string | null;
    repoIdentity?: {
        repoName: string;
        repoRoot: string;
        workspaceRoot: string;
        workspaceSource: string;
        workspaceStateKey: string;
        remoteUrl?: string | null;
        currentRepoId: string | null;
    };
    scanContext?: {
        repoRoot: string;
        workspaceRoot: string;
        workspaceSource: string;
        workspaceStateKey: string;
        notes: string[];
    };
    capabilities: Record<string, boolean>;
    compatibility: {
        schemaVersion: number;
        requiredCapabilities: string[];
        missingCapabilities: string[];
        status: 'compatible' | 'incompatible';
    };
    dashboardUrl: string | null;
    dashboardMode: 'idle' | 'bound' | 'reused';
    connection: unknown;
    runtimeEnvelope: RuntimeHealthEnvelope;
    runtime: unknown;
    memory: unknown;
    pod: unknown;
    clients: unknown;
    release: unknown;
    docs: unknown;
    ci: unknown;
    skillDistribution: {
        serverGoverned: boolean;
        eligibleClients: number;
        distributableSkills: number;
    };
}
export interface DashboardCompatibilityStatus {
    schemaVersion: number;
    requiredCapabilities: string[];
    missingCapabilities: string[];
    status: 'compatible' | 'incompatible';
}
export interface DashboardSkillDistributionSkill {
    skillId: string;
    name: string;
    scope: string;
    rolloutStatus: string;
    riskClass: string;
    distributableClientIds: string[];
}
export interface DashboardSkillDistributionManifest {
    generatedAt: number;
    serverGoverned: boolean;
    policy: {
        allowedScopes: string[];
        excludedClientIds: string[];
        eligibleStates: string[];
    };
    clients: Array<{
        clientId: string;
        displayName: string;
        state: string;
        source: string;
        eligibleForDistribution: boolean;
        distributableSkillIds: string[];
        distributableSkillNames: string[];
    }>;
    skills: DashboardSkillDistributionSkill[];
    summary: {
        totalClients: number;
        eligibleClients: number;
        totalSkills: number;
        distributableSkills: number;
    };
}
export interface CachedResponse<T> {
    expiresAt: number;
    value?: T;
    refresh?: Promise<T>;
}
export type DashboardSurfaceMode = 'operate' | 'memory' | 'runs' | 'assets' | 'trust';
export interface DashboardSummaryDTO {
    generatedAt: number;
    selectedRuntimeId: string | null;
    repoIdentity: unknown;
    health: DashboardHealthResponse;
    runtimes: unknown[];
    usage: unknown;
    latestRun: unknown;
    orchestrationSession: unknown;
    memoryHealth: unknown;
    memoryShared: unknown[];
    memoryContainers: unknown;
    gateSummary: unknown;
    tokenOptimization: unknown;
    interpretationIssues: unknown[];
    preCompactionBackup: unknown;
    backends: unknown;
    clients: unknown[];
    primaryClient: unknown;
    nexusLayer: unknown;
    ragCollections: unknown[];
    ragAttachedCount: number;
    patterns: unknown[];
    alerts: Array<{
        id: string;
        tone: 'info' | 'warn' | 'bad';
        title: string;
        summary: string;
    }>;
}
export interface OperateSurfaceDTO {
    repoIdentity: unknown;
    runs: unknown[];
    usage: unknown;
    tokenOptimization: unknown;
    sourceAwareTokenBudget: unknown;
    modelRoute?: unknown;
    agentFlow: unknown;
    gateSummary: unknown;
    memoryContainers: unknown;
    interpretationIssues: unknown[];
    orchestration?: unknown;
    orchestrationSession: unknown;
    orchestrationLedger: unknown;
    instructionPacket: unknown;
    tokensSummary: unknown;
    tokensTimeline: unknown[];
    tokensBySource: unknown;
    memory: unknown;
    memorySummary?: unknown;
    memoryHealth: unknown;
    memoryShared: unknown[];
    clients: unknown[];
    primaryClient: unknown;
}
export interface MemorySurfaceDTO {
    repoIdentity: unknown;
    usage: unknown;
    memory: unknown[];
    workspace: unknown[];
    profile: unknown[];
    shared: unknown[];
    inbox: unknown[];
    memoryHealth: unknown;
    memoryContainers: unknown;
    qualitySummary: unknown;
    memoryAudit: unknown;
    memoryQuarantine: unknown[];
    memoryShared: unknown[];
    knowledgeFabricSession: unknown;
    knowledgeProvenance: unknown;
    ragCollections: unknown[];
    patterns: unknown[];
    modelTiers: unknown;
    nexusLayer: unknown;
}
export interface RunsSurfaceDTO {
    repoIdentity: unknown;
    runs: unknown[];
    usage: unknown;
    gateSummary: unknown;
    selectionAudit: unknown;
    gateTimeline: unknown[];
    parallelism: unknown;
    tokenOptimization: unknown;
    sourceAwareTokenBudget: unknown;
    agentFlow: unknown;
    orchestrationSession: unknown;
    orchestrationLedger: unknown;
    workerPlan: unknown;
    artifactOutcomes: unknown;
    instructionPacket: unknown;
    tokensSummary: unknown;
    tokensTimeline: unknown[];
    tokensBySource: unknown;
    worktreeHealth: unknown;
}
export interface AssetsSurfaceDTO {
    repoIdentity: unknown;
    usage: unknown;
    selectionAudit: unknown;
    featureRegistry: unknown;
    patternPacks: unknown[];
    skills: unknown[];
    specialists: unknown[];
    crews: unknown[];
    workflows: unknown[];
    hooks: unknown[];
    automations: unknown[];
    backends: unknown;
}
export interface TrustSurfaceDTO {
    repoIdentity: unknown;
    usage: unknown;
    interpretationIssues: unknown[];
    preCompactionBackup: unknown;
    memoryContainers: unknown;
    health: DashboardHealthResponse;
    worktreeHealth: unknown;
    federation: unknown;
    memoryAudit: unknown;
    memoryQuarantine: unknown[];
    synapseTeams: unknown[];
    synapseHealth: unknown[];
    synapseApprovals: unknown[];
    architectsDispatch: unknown;
    architectsEscalations: unknown[];
    architectsWorklist: unknown;
    clients: unknown[];
    primaryClient: unknown;
    nexusLayer: unknown;
    nexusProof: unknown;
    machinePressure: PressureLevel;
    activeWorktrees: number;
    governor: GovernorState;
}
export type DashboardSurfaceDTO = OperateSurfaceDTO | MemorySurfaceDTO | RunsSurfaceDTO | AssetsSurfaceDTO | TrustSurfaceDTO | {
    error: string;
    surface: string;
};
export interface DashboardSelectorContext {
    repoRoot: string;
    runtimeRegistry: RuntimeRegistry;
    workspaceContextProvider?: () => WorkspaceContext;
    repoTreeGenerator: {
        generate(): any;
    };
    getRuntime(): SubAgentRuntime | undefined;
    getOrchestrator(): OrchestratorEngine | undefined;
    getMemory(): MemoryEngine | undefined;
    getAdapters(): Adapter[];
    getClientRegistry(): ClientRegistry | undefined;
    getSynapse(): SynapseRuntime | undefined;
    getArchitects(): ArchitectsRuntime | undefined;
    getSelectedRepoIdentity(url: URL): unknown;
    getPreferredArchitectsWorklist(url: URL, worklistId?: string | null, strikeTeamId?: string | null): unknown;
    getSkillDistributionManifest(): DashboardSkillDistributionManifest;
    buildFeatureRegistry(): any;
    resolveRuntimeSnapshot(url: URL): any;
    collectUsageSnapshot(url: URL): any;
    collectTokenOptimization(snapshot: any, usage: any): any;
    collectGateSummary(run: any): any;
    collectInterpretationIssues(input: {
        usage: any;
        latestRun: any;
        memoryHealth: any;
    }): any[];
    collectMemoryQualitySummary(memoryHealth: any, containers: any): any;
    buildDashboardAlerts(payload: {
        health: DashboardHealthResponse;
        usage: any;
        memoryHealth: any;
    }): Array<{
        id: string;
        tone: 'info' | 'warn' | 'bad';
        title: string;
        summary: string;
    }>;
    listDashboardMemories(options?: any): any[];
    listCrossProjectMemories(options: any): any;
    listCrossProjectProjects(limit: number): any;
    getCachedValue<T>(key: string, ttlMs: number, producer: () => Promise<T>): Promise<T>;
    collectHealth(): Promise<DashboardHealthResponse>;
    collectCompatibilityHealth(): DashboardHealthResponse;
    resolveDashboardEntity(kind: string, id: string, url: URL): unknown;
}
export interface DashboardRouteContext extends DashboardSelectorContext {
    getAddress(): string | null;
    getCorsOrigin(): string;
    respondJson(res: http.ServerResponse, data: unknown, statusCode?: number): void;
    respondCachedJson<T>(res: http.ServerResponse, key: string, ttlMs: number, producer: () => Promise<T>, statusCode?: number): Promise<void>;
    readJsonBody(req: http.IncomingMessage): Promise<Record<string, any>>;
    serveSse(req: http.IncomingMessage, res: http.ServerResponse): void;
    getSynapseInitError(): {
        message: string;
        stack: string | null;
        at: number;
    } | null;
    getReinitSynapse?(): (() => void) | null;
}
export interface DashboardRouteHandler {
    (ctx: DashboardRouteContext, req: http.IncomingMessage, res: http.ServerResponse, url: URL): Promise<boolean>;
}
export interface DashboardEventNormalizer {
    normalize(event: NexusEvent): DashboardEventCard;
}
