set shell := ["pwsh", "-NoProfile", "-Command"]

# Build and deploy everything across Windows and WSL
deploy-all: deploy-win deploy-wsl
    Write-Host "Deployment complete across both OS boundaries." -ForegroundColor Green

# Gracefully shut down the running server
shutdown-server:
    Write-Host "Shutting down MCP server gracefully..." -ForegroundColor Cyan
    -Invoke-RestMethod -Uri "http://127.0.0.1:3000/shutdown" -Method Post -ErrorAction SilentlyContinue
    Start-Sleep -Seconds 1
    if (Get-Process mcp-memory-server -ErrorAction SilentlyContinue) { Stop-Process -Name mcp-memory-server -Force -ErrorAction SilentlyContinue }

# Build and deploy Windows-native binaries
deploy-win: shutdown-server
    Write-Host "Building Windows binaries..." -ForegroundColor Cyan
    cargo build --release -p mcp-memory-server -p mcp-memory-stub -p mcp-memory-win-nvim
    Write-Host "Deploying Windows binaries..." -ForegroundColor Cyan
    Copy-Item -Force target\release\mcp-memory-stub.exe "C:\Users\reazul.ashraf\.local\bin\"; Copy-Item -Force target\release\mcp-memory-win-nvim.exe "C:\Users\reazul.ashraf\.local\bin\"
    Copy-Item -Force target\release\mcp-memory-server.exe "C:\Users\reazul.ashraf\.local\bin\"

# Build and deploy WSL-native binaries
deploy-wsl:
    Write-Host "Building and deploying WSL binaries natively..." -ForegroundColor Cyan
    wsl.exe -d Ubuntu -e bash -c 'export PATH="$PATH:/home/riz/.cargo/bin" && cd /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory && cargo build --release -p mcp-memory-stub -p mcp-memory-linux-nvim && cp target/release/mcp-memory-stub /home/riz/.local/bin/ && cp target/release/mcp-memory-linux-nvim /home/riz/.local/bin/'

# Run configuration tests to ensure eagerTools parity
test-config:
    cargo test --release -p mcp-memory-server --test parity_test
