$ErrorActionPreference = "Stop" $root = Split-Path -Parent $PSScriptRoot $runtimeDir = Join-Path $root "smqjh-agent-runtime" $logsDir = Join-Path $root "logs" if (-not (Test-Path $runtimeDir)) { throw "Runtime directory not found: $runtimeDir" } New-Item -ItemType Directory -Force -Path $logsDir | Out-Null if (-not $env:SMQJH_MCP_URL) { $env:SMQJH_MCP_URL = "http://127.0.0.1:8765/mcp" } if (-not $env:WEB_AGENT_PORT) { $env:WEB_AGENT_PORT = "5188" } if (-not (Test-Path (Join-Path $runtimeDir "node_modules"))) { Push-Location $runtimeDir try { npm install } finally { Pop-Location } } $stamp = Get-Date -Format "yyyyMMdd-HHmmss" $stdout = Join-Path $logsDir "web-agent-$stamp.out.log" $stderr = Join-Path $logsDir "web-agent-$stamp.err.log" Start-Process ` -FilePath "powershell" ` -ArgumentList @("-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", "npm run dev") ` -WorkingDirectory $runtimeDir ` -WindowStyle Hidden ` -RedirectStandardOutput $stdout ` -RedirectStandardError $stderr Write-Host "Web Agent start requested." Write-Host "URL: http://127.0.0.1:$env:WEB_AGENT_PORT" Write-Host "MCP: $env:SMQJH_MCP_URL" Write-Host "stdout: $stdout" Write-Host "stderr: $stderr"