@echo off
REM Start the Entropyk UI API server on :3030 without stale-process issues.
REM Kills any leftover ui-server.exe (they survive dead shells on Windows and
REM lock the port AND cargo build outputs), then starts the freshest binary.
setlocal
for /f "tokens=2" %%P in ('tasklist /FI "IMAGENAME eq ui-server.exe" /NH 2^>nul ^| findstr ui-server') do (
  echo Killing stale ui-server.exe PID %%P
  taskkill /PID %%P /F >nul 2>&1
)
if exist "%~dp0..\target\release\ui-server.exe" (
  echo Starting RELEASE ui-server on http://localhost:3030
  "%~dp0..\target\release\ui-server.exe"
) else (
  echo Starting debug ui-server on http://localhost:3030 ^(build release for speed: cargo build --release -p entropyk-demo --bin ui-server^)
  "%~dp0..\target\debug\ui-server.exe"
)
