feat(desktop): attest and manage the owned Windows host lifecycle

This commit is contained in:
Agent Workbench Dev
2026-10-31 09:03:01 +08:00
parent e634a252dd
commit 249f191ebc
32 changed files with 1765 additions and 70 deletions
+10 -10
View File
@@ -1,14 +1,14 @@
[CmdletBinding()]
param([int]$Port = 0)
param([int]$Port = 0, [string]$DataRoot = '', [string]$NodePath = '')
$ErrorActionPreference = 'Stop'
[Console]::OutputEncoding = [Text.UTF8Encoding]::new($false)
$appRoot = [IO.Path]::GetFullPath((Split-Path -Parent $PSScriptRoot))
if ($Port -eq 0) { $Port = if ($env:AGENT_WORKBENCH_PORT) { [int]$env:AGENT_WORKBENCH_PORT } else { 4318 } }
if ($Port -lt 1 -or $Port -gt 65535) { throw 'Please use a port between 1 and 65535.' }
$workbenchUrl = "http://127.0.0.1:$Port"
try { $health = Invoke-RestMethod -Uri "$workbenchUrl/api/health" -TimeoutSec 2 }
catch { Write-Output "Agent Workbench is not running on port $Port."; exit 0 }
if ($health.app -ne 'agent-workbench' -or -not $health.ready) { throw "This port is occupied by another service: $Port" }
$bootstrap = Invoke-RestMethod -Uri "$workbenchUrl/api/bootstrap" -TimeoutSec 3
Invoke-RestMethod -Uri "$workbenchUrl/api/shutdown" -Method Post -ContentType 'application/json' -Body '{}' -Headers @{ 'X-Workbench-Token' = $bootstrap.token } -TimeoutSec 15 | Out-Null
Write-Output "Agent Workbench is stopping: $workbenchUrl"
if (-not $DataRoot) { $DataRoot = if ($env:AGENT_WORKBENCH_DATA_DIR) { $env:AGENT_WORKBENCH_DATA_DIR } else { Join-Path $env:LOCALAPPDATA 'AgentWorkbench' } }
$DataRoot = [IO.Path]::GetFullPath($DataRoot)
if (-not $NodePath) { $NodePath = Join-Path $appRoot 'runtime\node.exe' }
if (-not (Test-Path -LiteralPath $NodePath)) { $NodePath = (Get-Command node.exe -ErrorAction Stop).Source }
$output = & $NodePath (Join-Path $appRoot 'dist-server\host-launcher.mjs') stop --app-root $appRoot --data-root $DataRoot --node $NodePath --port ([string]$Port)
if ($LASTEXITCODE -ne 0) { throw 'The original host stop remains unverified. See the diagnostic above.' }
$result = $output | ConvertFrom-Json
Write-Output ('Agent Workbench host: ' + $result.state)