import type { DaemonComponents } from '../boot/daemon-lifecycle.js';
export type WorkerDelegateRejectionReason = 'not_cli' | 'no_workspace' | 'no_worker_envelope' | 'coordinator_not_dispatch_target' | 'mesh_unresolved';
export interface WorkerDelegateRouting {
    /** True when the source session is a mesh worker whose events must route to a coordinator. */
    isDelegate: boolean;
    /** Resolved mesh id (runtime stamp, direct-dispatch recovery, or workspace lookup). */
    meshId: string;
    /** Resolved node id within the mesh, or '' when it cannot be determined. */
    nodeId: string;
    /** Human-readable node label for the coordinator system message. */
    nodeLabel: string;
    /** Coordinator daemon anchor (prefixed id) when the worker carries one; '' otherwise. */
    coordinatorDaemonId: string;
    /** Source session workspace (best-effort; '' when the session/workspace is missing). */
    workspace: string;
    /** Source session id echoed back, so diagnostics can name the dropped event's origin. */
    sessionId: string;
    /** Why routing was rejected (isDelegate=false), for fail-loud diagnostics (R4). */
    rejectionReason?: WorkerDelegateRejectionReason;
}
interface ResolveDeps {
    /** Resolve a mesh by id (local config + inline cache). */
    getMeshById: (meshId: string) => any | undefined;
    /** Resolve a mesh by workspace path (cached repo lookup). */
    getMeshByWorkspace: (workspace: string) => any | undefined;
}
/**
 * Resolve how a source CLI session's mesh events should route to a coordinator.
 *
 * This is the single authoritative interpretation of the worker envelope. It folds
 * together every signal that previously lived in inline branches:
 *  - runtime stamps (meshNodeFor / meshNodeId)
 *  - the coordinator anchor (meshCoordinatorDaemonId) and launch marker (launchedByCoordinator,
 *    meshCoordinatorNodeId) — any one proves delegation even if the node/mesh stamp was dropped
 *  - direct-dispatch recovery: a coordinator session that is itself a dispatch target
 *  - workspace→mesh fallback when no runtime mesh id survived
 *
 * Returns isDelegate=false (with a rejectionReason) instead of throwing, so the caller
 * can either ignore non-delegate events or surface a diagnostic.
 */
export declare function resolveWorkerDelegateRouting(components: DaemonComponents, instanceId: string, deps: ResolveDeps): WorkerDelegateRouting;
/** Ledger stream that collects delivery_unroutable diagnostics (no real mesh id exists for them). */
export declare const UNROUTABLE_DIAGNOSTIC_STREAM = "__unroutable__";
export declare function __resetUnroutableDiagnosticsForTests(): void;
/** True only for rejections that represent a silently-dropped delegate event worth a diagnostic. */
export declare function isUnroutableDelegateRejection(routing: WorkerDelegateRouting): boolean;
/**
 * R4: record that a worker event with a valid envelope could not be routed to a coordinator.
 * Writes a `delivery_unroutable` ledger entry (deduped within a short window) so operators see
 * WHY a completion never arrived instead of it vanishing. No-op for non-diagnostic rejections.
 */
export declare function recordUnroutableDelegateEvent(routing: WorkerDelegateRouting, eventName: string): boolean;
export interface UnroutableDeliveryDiagnostic {
    timestamp: string;
    event: string;
    sessionId?: string;
    workspace?: string;
    coordinatorDaemonId?: string;
}
/**
 * R4 visibility: recent delivery_unroutable diagnostics, newest first. Surfaced in mesh_status
 * so an operator/coordinator can see that completions were dropped (envelope present, mesh
 * unresolved) rather than the drops being invisible in a ledger nobody reads. The diagnostics
 * live in a single shared stream because an unroutable event has no resolvable mesh.
 */
export declare function getRecentUnroutableDeliveries(opts?: {
    sinceMs?: number;
    limit?: number;
}): UnroutableDeliveryDiagnostic[];
export {};
