/**
 * `spectral serve` — relay orchestration entry point.
 *
 * Architecture (post-Batch 2 cutover):
 *  1. Pre-flight: `requireLogin()` — same UX as the main spawn path.
 *  2. Pre-flight: `preflightSqlite()` — fail fast on a broken native module.
 *  3. Open the SQLite store and construct a `SessionStreamManager`.
 *  4. Register this machine with the backend (`ensureMachineRegistered`),
 *     which either reuses a fresh `machine.json` or POSTs to
 *     `/api/machines/register` and persists the issued JWT.
 *  5. Open a single long-lived `RelayClient` to `/agent-connection` carrying
 *     the machine JWT. Reconnects forever with backoff.
 *  6. Until Batch 3 ships, every inbound non-pong frame is acked back as
 *     `{kind:"ack", echo:<frame>}`. This proves the WS is bidirectional
 *     end-to-end and gives operators a smoke check before envelope routing.
 *  7. SIGINT/SIGTERM trigger graceful shutdown: dispose the relay (close 1000),
 *     dispose the manager (tear down agent streams), close the store.
 *
 * What this module is NOT (yet):
 *  - It does NOT translate relay envelopes into REST handler calls or WS
 *    event broadcasts. That dispatcher is Batch 3.
 *  - It does NOT bind any local port. The local HTTP server is gone.
 *
 * Flag surface:
 *  - `--machine-name <name>` — display name used at registration time.
 *  - `--port <n>` / `-p <n>` / `SPECTRAL_PORT` — accepted but warned-and-ignored
 *    so users updating from the pre-relay version don't get a hard error.
 *
 * The exported `runServe()` returns a handle so tests can drive the relay
 * loop in-process without spawning a subprocess. Tests inject
 * `relayUrlOverride` + `fetchImpl` + `webSocketImpl` to point at an
 * in-process fake backend.
 */
import { RelayClient } from "../relay/client.js";
import type { BridgeFactory } from "../server/session-stream.js";
import { SessionStreamManager } from "../server/session-stream.js";
import { SessionStore } from "../server/storage.js";
/**
 * Translate a backend HTTP(S) base URL to the relay WS(S) URL.
 * `http://x:y` → `ws://x:y/agent-connection`
 * `https://x` → `wss://x/agent-connection`
 */
export declare function deriveRelayUrl(backendUrl: string): string;
export interface ParsedServeArgs {
    /** Optional machine display name override. */
    machineName?: string;
    /**
     * Whether the user passed a deprecated `--port`/`SPECTRAL_PORT`. Surfaced
     * so the CLI driver can emit a single, consistent warning.
     */
    deprecatedPort: boolean;
}
/**
 * Parse the `serve` subcommand's flag surface. Manual parser, same style as
 * `login`/`logout` (no CLI framework).
 *
 * Accepted:
 *   --machine-name <name>
 *   --machine-name=<name>
 * Deprecated (warn, don't error):
 *   --port <n>  /  -p <n>  /  --port=<n>
 *
 * Anything else throws so users notice typos.
 */
export declare function parseServeArgs(args: string[]): ParsedServeArgs;
export interface RunServeOptions {
    /** Working directory spectral runs in. Defaults to homedir(). */
    cwd?: string;
    /** Skip SIGINT/SIGTERM handlers (tests). */
    installSignalHandlers?: boolean;
    /** Suppress startup banner (tests). */
    silent?: boolean;
    /** Override the SQLite path (tests). */
    dbPath?: string;
    /** Bridge factory for `SessionStreamManager` (tests). */
    bridgeFactory?: BridgeFactory;
    /** Display-name override (passed by `runServeCli` from `--machine-name`). */
    machineName?: string;
    /**
     * Override the backend base URL. Honors `SPECTRAL_BACKEND_URL` env var
     * when not set explicitly. Tests pass this to point at an in-process fake.
     */
    backendUrlOverride?: string;
    /**
     * Override the derived relay URL. Honors `SPECTRAL_RELAY_URL` env var when
     * not set explicitly. Tests use this to point at an in-process WS server.
     */
    relayUrlOverride?: string;
    /** Override fetch (tests, registration). */
    fetchImpl?: typeof fetch;
    /** Override the WebSocket constructor (tests, RelayClient). */
    webSocketImpl?: ConstructorParameters<typeof RelayClient>[0]["webSocketImpl"];
}
export interface RunServeHandle {
    /** Open store. Exposed for tests. */
    store: SessionStore;
    /** Manager driving agent streams. Exposed for tests. */
    manager: SessionStreamManager;
    /** Live relay client. Exposed for tests. */
    relay: RelayClient;
    /** Resolved machine id (from registration). */
    machineId: string;
    /** Close everything cleanly. Idempotent. */
    close(): Promise<void>;
}
export declare function runServe(opts?: RunServeOptions): Promise<RunServeHandle>;
/**
 * CLI entry point used by `cli.ts`. Surfaces the deprecation warning for
 * `--port`/`SPECTRAL_PORT` once, then defers to `runServe`.
 */
export declare function runServeCli(rawArgs: string[]): Promise<RunServeHandle>;
//# sourceMappingURL=serve.d.ts.map