* Calculate deterministic port from workspace path hash. * Same workspace always gets the same port for consistency. * * @param workspacePath - Absolute path to workspace root * @param basePort - Base port for calculation (default: 5200, avoids common 5173-5180) * @returns Hash-based port (base
(workspacePath: string, basePort: number = 5200)
| 71 | * @returns Hash-based port (basePort to basePort + 999) |
| 72 | */ |
| 73 | function calculateHashPort(workspacePath: string, basePort: number = 5200): number { |
| 74 | // Simple hash function - same input always produces same output |
| 75 | let hash = 0; |
| 76 | for (let i = 0; i < workspacePath.length; i++) { |
| 77 | hash = (hash << 5) - hash + workspacePath.charCodeAt(i); |
| 78 | hash = hash & hash; // Convert to 32bit integer |
| 79 | } |
| 80 | |
| 81 | // Map to port range (basePort to basePort + 999) |
| 82 | const offset = Math.abs(hash) % 1000; |
| 83 | return basePort + offset; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Get available port using hash-based selection strategy. |