/** * Dev-mode port resolution utilities. * * Provides a `listen` wrapper that automatically retries the next port when * the requested one is already in use, and writes the resolved port to a * well-known temp file so the CLI / frontend can discover it. * * Port affinity: when a port file already exists (e.g. after a tsx watch * restart), the saved port is tried FIRST so the backend stays on the same * port the frontend was configured with. * * This module is dev-only and should never run in production. */ import type { Server } from "http"; /** Filename written next to the project `.env` so the CLI can read it. */ export declare const DEV_PORT_FILENAME = ".rebase-dev-port"; /** * Try to `listen` on `startPort`. If the port is busy (`EADDRINUSE`), increment * and retry up to `maxAttempts` times. * * When a port file already exists (written by a previous run), the saved port * is tried first to maintain port affinity across tsx watch restarts. * * Resolves with the port that was actually bound. * * @internal Not part of the stable public API. Exported only because the * official app template (`packages/cli/templates/template/backend/src/index.ts` * and `app/backend/src/index.ts`) calls it directly in dev mode. Its dev-only * port-affinity behavior is an implementation detail and may change without * a major version bump. */ export declare function listenWithPortRetry(server: Server, startPort: number, options?: { host?: string; maxAttempts?: number; /** Absolute path to write the resolved port file into. Defaults to `process.cwd()`. */ portFileDir?: string; /** Service key to include in the state file for MCP server auto-discovery. */ serviceKey?: string; }): Promise; /** * Clean up the dev port file and state file (call on graceful shutdown). * * @internal Not part of the stable public API. See {@link listenWithPortRetry}. */ export declare function cleanupDevPortFile(dir: string): void;