import { type ChildProcess, type SpawnOptions } from "node:child_process"; import type { AdapterLogger } from "./logger.js"; /** Abstraction over child-process spawning used by {@link ProcessTunnel}. */ export interface TunnelProcessFactory { /** Spawn a child process. */ spawn(command: string, args: string[], options: SpawnOptions): ChildProcess; } /** Abstraction over port readiness probing used by {@link ProcessTunnel}. */ export interface TunnelPortProbe { /** Wait for a TCP port to accept connections on localhost. */ waitForPort(port: number): Promise; } /** Abstraction for a long-lived port-forwarding tunnel. */ export interface RemoteTunnel { /** The local port the tunnel is bound to. */ localPort: number; /** Open the tunnel (spawns a background process). */ open(): Promise; /** Close the tunnel (kills the background process). */ close(): Promise; /** Return true if the tunnel process is still running. */ isAlive(): boolean; } /** * Base class for tunnels backed by a long-lived child process. * Subclasses provide the command and arguments to spawn. */ export declare abstract class ProcessTunnel implements RemoteTunnel { localPort: number; protected process: ChildProcess | undefined; protected logger: AdapterLogger; protected readonly processFactory: TunnelProcessFactory; protected readonly portProbe: TunnelPortProbe; /** * Optional environment variable overrides for the spawned tunnel process. * Merged on top of `process.env` when the tunnel is opened. */ protected spawnEnv: NodeJS.ProcessEnv | undefined; constructor(localPort: number, logger?: AdapterLogger, processFactory?: TunnelProcessFactory, portProbe?: TunnelPortProbe); /** Return the command and arguments to spawn the tunnel process. */ protected abstract spawnArgs(): { command: string; args: string[]; }; /** * Wait for the tunnel to become ready after spawning. * Override in subclasses that can't probe a local port (e.g. reverse tunnels). */ protected waitForReady(): Promise; /** Open the tunnel by spawning the background process. */ open(): Promise; /** Close the tunnel by killing the background process. */ close(): Promise; /** Return true if the tunnel process is still running. */ isAlive(): boolean; } /** * Base class for reverse tunnels that bind a remote port to a local port. * * Reverse tunnels bind on the remote side, so local port probing doesn't work. * Readiness is determined by a fixed delay followed by an exit-code check. * Subclasses override `spawnArgs()` for the specific transport (SSH, gh CLI). */ export declare abstract class ProcessReverseTunnel extends ProcessTunnel { protected readonly remotePort: number; protected readonly sleepFn: (ms: number) => Promise; constructor(localPort: number, remotePort: number, sleepFn: (ms: number) => Promise, processFactory?: TunnelProcessFactory, portProbe?: TunnelPortProbe); /** Wait for the reverse tunnel to establish by sleeping, then check for early exit. */ protected waitForReady(): Promise; } //# sourceMappingURL=tunnel.d.ts.map