@echo off
setlocal
cd /d "%~dp0"

call "%~dp0tools\resolve_h3_runtime.cmd"
if errorlevel 1 (pause & exit /b 1)
set "H3_ENGINE_PYTHON=%H3_RUNTIME_PYTHON%"

if not exist "ComfyUI\main.py" (
  echo [ERROR] ComfyUI not found: ComfyUI\main.py
  pause
  exit /b 1
)

if not exist ".triton_cache" mkdir ".triton_cache"
set "TRITON_CACHE_DIR=%~dp0.triton_cache"

echo Starting MiniMax H3 with adaptive acceleration at http://127.0.0.1:8189 ...
"%H3_RUNTIME_PYTHON%" "tools\launch_comfy.py" --port 8189 --open-browser
set "H3_EXIT=%ERRORLEVEL%"

echo.
echo ComfyUI has stopped.
pause
exit /b %H3_EXIT%
