/** * Resource Allocator - Port, CPU, and memory allocation for explorations * * Manages resource allocation to prevent conflicts between parallel explorations */ import type { AllocatedResources } from '../types/exploration.types.js'; export interface AllocationRequest { cpu_limit: string; exploration_id: string; memory_limit: string; worktree_index: number; } export interface ResourcePool { allocated_containers: Map; allocated_ports: Set; port_range_end: number; port_range_start: number; } export declare class ResourceAllocator { private pool; constructor(portRangeStart?: number, portRangeEnd?: number); /** * Allocate resources for a worktree */ allocate(request: AllocationRequest): AllocatedResources; /** * Allocate multiple resources for parallel worktrees */ allocateMultiple(requests: AllocationRequest[]): AllocatedResources[]; /** * Release resources for a worktree */ release(explorationId: string, worktreeIndex: number): void; /** * Release all resources for an exploration */ releaseAll(explorationId: string): void; /** * Get allocated resources for a worktree */ getAllocated(explorationId: string, worktreeIndex: number): AllocatedResources | null; /** * Get all allocated resources for an exploration */ getAllAllocated(explorationId: string): AllocatedResources[]; /** * Check if resources are available for N branches */ canAllocate(branches: number): boolean; /** * Get number of available ports */ getAvailablePortCount(): number; /** * Get allocation statistics */ getStats(): { active_containers: number; allocated_ports: number; available_ports: number; total_ports: number; }; /** * Get the set of host ports currently mapped by Docker containers */ private getDockerAllocatedPorts; /** * Allocate a port from the pool */ private allocatePort; /** * Validate CPU limit format */ static validateCpuLimit(cpuLimit: string): boolean; /** * Validate memory limit format */ static validateMemoryLimit(memoryLimit: string): boolean; /** * Convert memory limit to bytes */ static memoryLimitToBytes(memoryLimit: string): number; /** * Convert memory limit to megabytes */ static memoryLimitToMB(memoryLimit: string): number; /** * Format bytes to human-readable memory limit */ static formatMemoryLimit(bytes: number): string; /** * Reset the allocator (useful for testing) */ reset(): void; /** * Reserve a specific port (for manual allocation) */ reservePort(port: number): boolean; /** * Check if a port is available */ isPortAvailable(port: number): boolean; /** * Get list of allocated ports */ getAllocatedPorts(): number[]; /** * Get list of available ports */ getAvailablePorts(): number[]; } //# sourceMappingURL=resource-allocator.d.ts.map