#!/usr/bin/env pwsh # Hermes Portable Rescue — Windows Agent (PowerShell) # Run: powershell -ExecutionPolicy Bypass -File .\run-hermes.ps1 $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $HermesRoot = Resolve-Path (Join-Path $ScriptDir "..\hermes") $HermesConfig = Join-Path $HermesRoot "config.yaml" $PythonExe = Join-Path $ScriptDir "python\python.exe" $HermesExe = Join-Path $ScriptDir "python\Scripts\hermes.exe" $PipBootstrap = Join-Path $ScriptDir "bin\get-pip.py" $WheelsDir = Join-Path $ScriptDir "bin\wheels" $Marker = Join-Path $ScriptDir ".installed" $WinMCPWheelsDir = Join-Path $ScriptDir "bin\wheels-windows-mcp" $WinMCPScript = Join-Path $ScriptDir "start-windows-mcp.bat" $WinMCPMarker = Join-Path $ScriptDir "bin\.windows-mcp-installed" Write-Host "============================================" -ForegroundColor Cyan Write-Host " Hermes Portable Rescue - Windows Agent" -ForegroundColor Cyan Write-Host "============================================" -ForegroundColor Cyan Write-Host "" Write-Host "Python: $PythonExe" Write-Host "Config: $HermesConfig" if (-not (Test-Path $PythonExe)) { Write-Host "[ERROR] Python not found at $PythonExe" -ForegroundColor Red exit 1 } # Bootstrap Hermes on first run if (-not (Test-Path $Marker)) { Write-Host "[*] First run -- installing Hermes Agent..." & $PythonExe $PipBootstrap --quiet --no-warn-script-location 2>&1 | Out-Null if ($LASTEXITCODE -ne 0) { Write-Host "[ERROR] Failed to bootstrap pip." -ForegroundColor Red exit 1 } & $PythonExe -m pip install --no-index --find-links $WheelsDir --quiet hermes-agent zeroconf ifaddr 2>&1 if ($LASTEXITCODE -ne 0) { Write-Host "[ERROR] Failed to install Hermes Agent." -ForegroundColor Red exit 1 } Set-Content -Path $Marker -Value "" Write-Host "[OK] Hermes Agent installed." -ForegroundColor Green } # Check Hermes CLI installed if (-not (Test-Path $HermesExe)) { Write-Host "[ERROR] Hermes CLI not found at $HermesExe" -ForegroundColor Red Write-Host "Run this script again to install Hermes Agent first." exit 1 } # Auto-start Windows-MCP server $mcpHealth = "http://127.0.0.1:8000/mcp/health" try { $null = Invoke-WebRequest -Uri $mcpHealth -Method GET -TimeoutSec 2 -ErrorAction Stop Write-Host "[OK] Windows MCP Server already running." -ForegroundColor Green } catch { Write-Host "[*] Auto-starting Windows MCP Server (UI Automation)..." Start-Process -WindowStyle Minimized -FilePath $WinMCPScript $mcpReady = $false for ($i = 0; $i -lt 20; $i++) { Start-Sleep -Seconds 1 try { $null = Invoke-WebRequest -Uri $mcpHealth -Method GET -TimeoutSec 1 -ErrorAction Stop $mcpReady = $true Write-Host "[OK] Windows MCP Server is ready!" -ForegroundColor Green break } catch {} } if (-not $mcpReady) { Write-Host "[WARN] Windows MCP Server not ready after 20s - continuing..." -ForegroundColor Yellow } } # Launch Hermes Write-Host "" Write-Host "[*] Starting Hermes Agent..." & $HermesExe --config $HermesConfig Write-Host "" Write-Host "[*] Hermes exited."