/** * `spectral serve` — relay orchestration entry point. * * Architecture: * 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. When the JWT is * rejected (HTTP 401/403 on WS upgrade), the relay emits `auth-failed` * and `serve.ts` triggers a re-registration attempt. If re-registration * succeeds, a fresh relay is spawned with the new JWT. If it fails (e.g. * team API key rotated), the process exits with a clear message. * 6. SIGINT/SIGTERM trigger graceful shutdown: dispose the relay (close 1000), * dispose the manager (tear down agent streams), close the store. * * Flag surface: * - `--machine-name ` — display name used at registration time. * - `SPECTRAL_MACHINE_NAME` — fallback display name used when the flag is * not supplied. The flag takes precedence over the environment variable. * - `--port ` / `-p ` / `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 * --machine-name= * Deprecated (warn, don't error): * --port / -p / --port= * * 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[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; } export declare function runServe(opts?: RunServeOptions): Promise; /** * 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; //# sourceMappingURL=serve.d.ts.map