param([string]$AppRoot = (Split-Path -Parent $PSScriptRoot), [string]$DataRoot = '', [int]$Port = 4318) $ErrorActionPreference = 'Stop' $AppRoot = (Resolve-Path -LiteralPath $AppRoot).Path if (-not $DataRoot) { $DataRoot = Join-Path $env:LOCALAPPDATA 'AgentWorkbench' } $DesktopExe = Join-Path $AppRoot 'desktop\AgentWorkbench.exe' $NodeExe = Join-Path $AppRoot 'runtime\node.exe' $MainFile = Join-Path $AppRoot 'dist-desktop\main.cjs' $DesktopArgs = @('--app-root', $AppRoot, '--data-root', $DataRoot, '--port', [string]$Port) if (-not (Test-Path -LiteralPath $DesktopExe)) { $DesktopExe = Join-Path $AppRoot 'runtime\electron\electron.exe' if (-not (Test-Path -LiteralPath $DesktopExe)) { $DesktopExe = Join-Path $AppRoot 'node_modules\electron\dist\electron.exe' } if (-not (Test-Path -LiteralPath $NodeExe)) { $NodeExe = Join-Path (Split-Path -Parent $AppRoot) 'tools\node-v24.22.1-win-x64\node.exe' } $DesktopArgs = @($MainFile) + $DesktopArgs + @('--node', $NodeExe) } foreach ($Required in @($DesktopExe, $NodeExe, $MainFile)) { if (-not (Test-Path -LiteralPath $Required -PathType Leaf)) { throw "Desktop runtime file is missing: $Required" } } $QuotedArgs = ($DesktopArgs | ForEach-Object { if ($_ -match '"') { throw 'Invalid launch path.' }; '"' + $_ + '"' }) -join ' ' Start-Process -FilePath $DesktopExe -ArgumentList $QuotedArgs -WorkingDirectory $AppRoot -WindowStyle Hidden