/**
 * `GET /api/events` — the viewer's live channel (server-sent events).
 *
 * Two questions the open browser cannot answer for itself, and one stream that
 * answers both:
 *
 * - **"has the file I'm looking at changed on disk?"** — the drift banner. The
 *   verdict itself comes from `/api/source` (it hashes the bytes); this stream
 *   only says *when to ask again*, so the banner appears about a third of a
 *   second after a save instead of on the next navigation.
 * - **"has the index moved?"** — the live refresh. Something else (an agent's
 *   MCP daemon, `codegraph sync`, a git hook) writes the graph; when it does,
 *   every screen the viewer is showing is one round-trip out of date.
 *
 * ## This server watches. It never syncs.
 *
 * `codegraph ui` is read-only in every sense — the banner it prints says so —
 * so the obvious implementation (run the engine's watcher, let it sync) is out.
 * What is left is *observation*, from two independent directions:
 *
 * - the project tree, through the engine's own {@link FileWatcher} with a
 *   notify-only `syncFn`. It never writes: the callback that would have run a
 *   sync fans the changed paths out to the browser instead. Everything else
 *   about it — the per-platform watch strategy, the indexer's ignore scope, the
 *   adaptive debounce, the degrade latch — is behaviour we would otherwise have
 *   had to write again, worse.
 * - the index itself, through one non-recursive `fs.watch` on the data
 *   directory. That is the only cross-process signal there is: the writer is a
 *   different process, and the thing it changes is a file. A settled write is
 *   followed by ONE cheap query (`getIndexRevision`), and only a revision that
 *   actually moved becomes an event.
 *
 * **Nothing polls.** Both watchers are edge-triggered, and both start on the
 * first subscriber and stop with the last one — a viewer nobody has open costs
 * no watch descriptors, which matters on Linux where the strategy is
 * per-directory.
 *
 * ## Boundary
 *
 * A long-lived response sits inside the loopback boundary exactly like every
 * other route: `Host`, `Origin` and the GET-only rule are already enforced by
 * `startUiServer` before this module is reached, and nothing here reads the
 * repository — the paths it names came from the watcher and the index, and the
 * viewer has to go back through `/api/source` (and therefore through
 * `resolveProjectFile`) to see a byte of any of them.
 */
import type { IncomingMessage, ServerResponse } from 'http';
import type { GraphSession } from './session';
/**
 * Paths carried in one event. `total` is always the real number — a burst of
 * two thousand files still says two thousand, it just does not list them.
 */
export declare const MAX_EVENT_FILES = 200;
/** Comment frame keeping the connection (and the client's idea of it) alive. */
export declare const HEARTBEAT_MS = 25000;
export interface WireIndexRevision {
    lastIndexedAt: number | null;
    files: number;
}
/** Sent once, immediately, so a client knows what it is synchronised against. */
export interface WireEventHello {
    type: 'hello';
    index: WireIndexRevision | null;
    /** Which of the two observers actually came up. */
    watching: {
        source: boolean;
        index: boolean;
    };
    /** Non-null when live watching has given up; the client must NOT start polling. */
    degraded: string | null;
    heartbeatMs: number;
    at: number;
}
/** Source files changed on disk. The index has NOT caught up yet. */
export interface WireEventChanged {
    type: 'changed';
    files: string[];
    total: number;
    truncated: boolean;
    /**
     * True when the change could not be described file by file (a directory
     * removal, or a burst past the watcher's scoped ceiling). Treat any open file
     * as possibly affected.
     */
    scan: boolean;
    at: number;
}
/** The index moved: some other process finished writing the graph. */
export interface WireEventIndex {
    type: 'index';
    index: WireIndexRevision;
    /** Files this sync re-indexed, newest first. Empty when it only deleted. */
    files: string[];
    total: number;
    truncated: boolean;
    at: number;
}
/** Live watching has stopped for good. Sent once; the stream stays open. */
export interface WireEventDegraded {
    type: 'degraded';
    reason: string;
    at: number;
}
export type WireEvent = WireEventHello | WireEventChanged | WireEventIndex | WireEventDegraded;
/**
 * Fans filesystem and index changes out to every open viewer.
 *
 * One hub per server. It owns the watchers, and owns them lazily: they exist
 * only while somebody is listening.
 */
export declare class EventHub {
    private readonly projectRoot;
    private readonly session;
    private readonly clients;
    private sourceWatcher;
    private indexWatcher;
    private indexTimer;
    /** When the current settle window started, for the {@link INDEX_SETTLE_MAX_MS} cap. */
    private indexPendingSince;
    private revision;
    private sourceUp;
    private indexUp;
    private degraded;
    private closed;
    constructor(projectRoot: string, session: GraphSession);
    /**
     * Attach one browser to the stream.
     *
     * Returns `true` in every case — the response is answered here, streaming or
     * not — so it slots into the API's `switch` like any other endpoint.
     */
    subscribe(req: IncomingMessage, res: ServerResponse, method: string): true;
    /** Number of attached clients — for tests and for the watchers' lifetime. */
    get size(): number;
    /** Stop watching and end every open stream. Idempotent. */
    close(): void;
    private drop;
    private send;
    private broadcast;
    private ensureWatching;
    private stopWatching;
    /**
     * The project tree, through the engine's watcher with the sync taken out.
     *
     * The `syncFn` is the whole trick: the watcher calls it with exactly the
     * paths it would have handed to a scoped sync (or `undefined` when the events
     * could not describe the change), we announce them and report zero files
     * changed. It succeeds every time, so the watcher's failure ladder — lock
     * retries, backoff, the degrade latch — is only ever reached by the watch
     * layer itself, which is precisely the part we do want.
     */
    private startSourceWatcher;
    private announceChanged;
    /**
     * The index, through one watch on the data directory.
     *
     * Non-recursive and on the directory rather than the database file: SQLite
     * writes land in `codegraph.db-wal`, and a full re-index REPLACES
     * `codegraph.db` outright (a watch on the file itself would follow the
     * unlinked inode and never fire again).
     */
    private startIndexWatcher;
    /**
     * Wait for the writing to stop, then look once.
     *
     * Re-armed by every write, so a sync that takes four seconds produces one
     * probe at its end — except that {@link INDEX_SETTLE_MAX_MS} caps how long
     * the first probe can be deferred, so a continuously-writing full index still
     * refreshes the viewer while it runs.
     */
    private scheduleProbe;
    /** One query. An unmoved revision is not an event. */
    private checkIndex;
    /**
     * The current revision, or null when there is no readable index.
     *
     * A missing index is not an error here: `codegraph ui` refuses to start
     * without one, but a user can delete `.codegraph/` with the viewer open, and
     * every endpoint already says so in its own words when asked.
     */
    private probe;
}
//# sourceMappingURL=events.d.ts.map