import { DebuggerDriver, type ModuleFunctions } from "../driver.js"; import type { Channel } from "./channel.js"; import { type ClientKind, type Hello } from "./protocol.js"; import { type AttachRecord } from "./registry.js"; import { type SessionChannelOptions } from "./sessionChannel.js"; /** How long a connection has to say what it is. A client built before * `client` existed sends nothing first and would wait on `hello` for * ever; it is told why instead. */ export declare const HANDSHAKE_MS = 5000; export type AttachOptions = { functions: ModuleFunctions; hello: Hello; rewindSize?: number; session?: SessionChannelOptions; }; export type AttachedSession = { driver: DebuggerDriver; /** A connection that sent `client` with this kind. */ admit(channel: Channel, kind: ClientKind): void; /** Run `listener` once, when the session ends for any reason. */ onEnd(listener: () => void): void; /** End the session: the driver is removed and every party is closed. */ detach(): void; }; /** Open a session on the program behind `functions`, with no party on * it yet. The driver is installed at once, so the program stops at its * next step and waits for the first party to join. */ export declare function openSession(options: AttachOptions): AttachedSession; /** Attach a debugger that speaks over `channel`, a terminal whose * connection is its session: closing it, from either side, detaches. */ export declare function attachOverChannel(channel: Channel, options: AttachOptions): AttachedSession; export type AttachServer = { socketPath: string; /** The session on the connection in progress, or null. */ current(): AttachedSession | null; stop(): Promise; }; export type ServerUnavailable = { unavailable: string; }; export type AttachServerOptions = { dir: string; record: AttachRecord; /** The functions of the context a debugger attaches to, read when a * debugger connects: the context running then is the one meant, and * a TypeScript program can have started another node since the * signal arrived. */ functions: () => ModuleFunctions; rewindSize?: number; log?: (line: string) => void; }; /** Listen on `.sock` in the sessions directory. A connection's * first message says what it is; the first to join opens the session, * and the rules in `sessionRules.ts` say who else may. The server and * every accepted socket are `unref`ed, so an open session never keeps a * finished program alive, and the server is `ref`ed only while the * driver waits on an answer. Node cannot read the peer's pid from a * Unix socket, so a refusal says since when. Every way this can fail * comes back as `unavailable`: * the signal listener that calls it must never throw into the program. * The directory is checked here, right before `listen`, not only at * registration hours earlier: the check is what keeps the socket's * short window at the umask's mode private. */ export declare function startAttachServer(options: AttachServerOptions): Promise;