( repoRoot: string, sessionName: string, wranglerRegistryPath: string, serviceNames: string[] )
| 495 | // hash/persisted offset's ports are held by a foreign occupant (another |
| 496 | // worktree's stack, macOS AirPlay on 5000/7000), probe +100 candidate |
| 497 | // offsets and take the first whose full computed port set is free. Never |
| 498 | // silently share. The chosen offset is persisted before startup so later |
| 499 | // port-computing commands agree even if startup is interrupted. |
| 500 | const offsetIsExplicit = |
| 501 | process.env.KILO_PORT_OFFSET !== undefined && process.env.KILO_PORT_OFFSET !== 'auto'; |
| 502 | let reusedHostServices = new Set<string>(); |
| 503 | if (!sessionAlreadyRunning) { |
| 504 | const originalOffset = portOffset; |
| 505 | // Read before the lease writes over it: it names the offset whose compose |
| 506 | // project holds this worktree's containers right now. |
| 507 | const previousOffset = readPersistedPortOffset(repoRoot); |
| 508 | reusedHostServices = await acquirePortOffsetLease( |
| 509 | serviceNames, |
| 510 | offsetIsExplicit, |
| 511 | repoRoot, |
| 512 | sessionName, |
| 513 | undefined, |
| 514 | undefined, |
| 515 | previousOffset |
| 516 | ); |
| 517 | if (portOffset !== originalOffset) |
| 518 | console.log(`${DIM}Auto-selected port offset ${portOffset}${RESET}`); |
no test coverage detected