/** * Port Allocator * Issue #136: Phase 1 - Foundation * * Provides automatic port allocation for worktree servers. * SF-SEC-002: Implements MAX_WORKTREES limit to prevent port exhaustion attacks. * * @module port-allocator */ /** * Default port range for worktree servers * Main server uses 3000, worktrees use 3001-3100 */ export declare const DEFAULT_PORT_RANGE: { readonly min: 3001; readonly max: 3100; }; /** * Maximum number of concurrent worktree servers * SF-SEC-002: Prevents port exhaustion attacks */ export declare const MAX_WORKTREES = 10; /** * Port range configuration */ export interface PortRange { min: number; max: number; } /** * Port allocator for managing worktree server ports * * @example * ```typescript * const allocator = new PortAllocator(); * const port = await allocator.findAvailablePort(); * allocator.markAllocated(port); * // ... start server on port ... * allocator.release(port); * ``` */ export declare class PortAllocator { private static instance; private readonly range; private readonly allocatedPorts; private readonly issuePortMap; constructor(range?: PortRange); /** * Get singleton instance * Issue #136: Singleton pattern for CLI commands */ static getInstance(): PortAllocator; /** * Allocate a port for a specific issue (synchronous, deterministic) * Issue #136: Simple port allocation based on issue number * * @param issueNo - Issue number * @returns Allocated port number */ allocate(issueNo: number): number; /** * Find an available port in the configured range * * @returns Available port number * @throws AppError with code PORT_EXHAUSTED if no ports available * @throws AppError with code MAX_WORKTREES_EXCEEDED if limit reached */ findAvailablePort(): Promise; /** * Check if a specific port is available * * @param port - Port number to check * @returns true if port is available */ isPortAvailable(port: number): Promise; /** * Mark a port as allocated * * @param port - Port number to mark as allocated */ markAllocated(port: number): void; /** * Release an allocated port * * @param port - Port number to release */ release(port: number): void; /** * Get the count of allocated ports */ getAllocatedCount(): number; /** * Check if a port is currently allocated (in-memory tracking) * * @param port - Port number to check * @returns true if port is allocated */ isAllocated(port: number): boolean; /** * Get all allocated ports */ getAllocatedPorts(): number[]; } /** * Create a port allocator with default settings */ export declare function createPortAllocator(range?: PortRange): PortAllocator; //# sourceMappingURL=port-allocator.d.ts.map