# GYXX 智能工作台一键启动(Windows PowerShell) # 用法: # powershell -File workbench\bin\start-workbench.ps1 # powershell -File workbench\bin\start-workbench.ps1 -ConsoleEnvFile D:\product-collector-analyze-flow\.env # # 行为: # 1. 渲染 workbench/cordis.local.yml(插件绝对路径) # 2. 若 8765 控制台未运行,则以 --env-file 注入云端凭据启动 gyxx console # 3. 启动 dsh Web UI 并应用工作台补丁(优先 $env:DSH_HOME 源码目录,其次 npx @deepseek-ai/dsh) [CmdletBinding()] param( [string]$ConsoleEnvFile = 'D:\product-collector-analyze-flow\.env', [int]$ConsolePort = 8765, [int]$BridgePort = 8790, [switch]$SkipConsole ) $ErrorActionPreference = 'Stop' $RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path $WorkbenchDir = Join-Path $RepoRoot 'workbench' $LocalYml = Join-Path $WorkbenchDir 'cordis.local.yml' # 1) 渲染 cordis.local.yml $template = Get-Content (Join-Path $WorkbenchDir 'cordis.template.yml') -Raw -Encoding UTF8 $workbenchDirPosix = ($WorkbenchDir -replace '\\', '/') $projectRootPosix = ($RepoRoot -replace '\\', '/') # Windows 上 dsh 的 ESM 加载器要求 file:// URL $workbenchModuleUrl = 'file:///' + $workbenchDirPosix $rendered = $template.Replace('__WORKBENCH_DIR__', $workbenchModuleUrl).Replace('__PROJECT_ROOT__', $projectRootPosix) $rendered = $rendered -replace 'bridgePort: 8790', "bridgePort: $BridgePort" $rendered = $rendered -replace "consoleBaseUrl: 'http://127.0.0.1:8765'", "consoleBaseUrl: 'http://127.0.0.1:$ConsolePort'" [System.IO.File]::WriteAllText($LocalYml, $rendered, (New-Object System.Text.UTF8Encoding($false))) Write-Host "[workbench] 已生成 $LocalYml" # 2) 确保 gyxx console 在运行 if (-not $SkipConsole) { $consoleUp = $false try { $null = Invoke-WebRequest -UseBasicParsing -Uri "http://127.0.0.1:$ConsolePort/api/overview" -TimeoutSec 3 $consoleUp = $true } catch { $consoleUp = $false } if ($consoleUp) { Write-Host "[workbench] gyxx console 已在 http://127.0.0.1:$ConsolePort 运行" } else { if (-not (Test-Path $ConsoleEnvFile)) { Write-Warning "缺少 $ConsoleEnvFile —— 正式执行将无法注入云端凭据(AGENTS.md 约定)。" } $consoleArgs = @('run', 'gyxx', 'console', '--port', "$ConsolePort", '--env-file', $ConsoleEnvFile) Write-Host "[workbench] 启动 gyxx console: uv $($consoleArgs -join ' ')" Start-Process -FilePath 'uv' -ArgumentList $consoleArgs -WorkingDirectory $RepoRoot -WindowStyle Minimized $deadline = (Get-Date).AddSeconds(30) do { Start-Sleep -Milliseconds 800 try { $null = Invoke-WebRequest -UseBasicParsing -Uri "http://127.0.0.1:$ConsolePort/api/overview" -TimeoutSec 2 $consoleUp = $true } catch { $consoleUp = $false } } until ($consoleUp -or (Get-Date) -gt $deadline) if (-not $consoleUp) { Write-Warning 'gyxx console 启动超时,工作台仍可启动但工具会提示控制台离线。' } } } # 3) 启动 dsh Web UI if ($env:DSH_HOME -and (Test-Path (Join-Path $env:DSH_HOME 'package.json'))) { Write-Host "[workbench] 使用源码版 dsh: $($env:DSH_HOME)" Push-Location $env:DSH_HOME try { & pnpm dsh web --patch $LocalYml } finally { Pop-Location } } else { Write-Host '[workbench] 使用 npm 版 dsh(npx @deepseek-ai/dsh)' & npx -y '@deepseek-ai/dsh' web --patch $LocalYml }