106 lines
3.9 KiB
PowerShell
106 lines
3.9 KiB
PowerShell
# Enable WorkBuddy CDP and capture UI styles.
|
|
#
|
|
# Purpose: make the real WorkBuddy expose DevTools Protocol on port 9223, then
|
|
# capture element rects + computed styles for the sidebar, conversation
|
|
# area and input area, as the basis for YCode visual alignment.
|
|
#
|
|
# NOTE: WorkBuddy has a single-instance lock, so it must be fully exited and
|
|
# restarted with the env var set. Running this script therefore CLOSES the
|
|
# current WorkBuddy window (including any conversation in progress).
|
|
#
|
|
# Usage (run in a PowerShell window OUTSIDE WorkBuddy):
|
|
# powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\Administrator\code\YCode\scripts\enable-wb-cdp.ps1
|
|
#
|
|
# This file is intentionally ASCII-only: Windows PowerShell 5.1 reads .ps1 as
|
|
# ANSI, so non-ASCII text would be corrupted and break the parser.
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$WorkBuddyExe = Join-Path $env:LOCALAPPDATA 'Programs\WorkBuddy\WorkBuddy.exe'
|
|
$ProjectRoot = 'C:\Users\Administrator\code\YCode'
|
|
$DebugPort = 9223
|
|
# Captures contain real conversation content, so they are kept in a private
|
|
# user directory instead of the repository.
|
|
$OutDir = Join-Path $env:USERPROFILE '.ycode\captures'
|
|
|
|
Write-Host '=== YCode: enable WorkBuddy CDP and capture ===' -ForegroundColor Cyan
|
|
|
|
if (-not (Test-Path $WorkBuddyExe)) {
|
|
Write-Host "[FAIL] WorkBuddy not found: $WorkBuddyExe" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# ---------- 1. stop existing instances ----------
|
|
Write-Host '[1/5] Stopping running WorkBuddy processes...'
|
|
Get-Process -Name WorkBuddy -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
|
Start-Sleep -Seconds 4
|
|
$left = Get-Process -Name WorkBuddy -ErrorAction SilentlyContinue
|
|
if ($left) {
|
|
Write-Host "[WARN] still alive: $($left.Id -join ',') ; waiting 4s more..." -ForegroundColor Yellow
|
|
Start-Sleep -Seconds 4
|
|
}
|
|
|
|
# ---------- 2. launch with debug port ----------
|
|
Write-Host '[2/5] Starting with WORKBUDDY_REMOTE_DEBUGGING_PORT...'
|
|
$previous = $env:WORKBUDDY_REMOTE_DEBUGGING_PORT
|
|
try {
|
|
$env:WORKBUDDY_REMOTE_DEBUGGING_PORT = "$DebugPort"
|
|
Start-Process -FilePath $WorkBuddyExe
|
|
} finally {
|
|
if ($null -eq $previous) {
|
|
Remove-Item Env:WORKBUDDY_REMOTE_DEBUGGING_PORT -ErrorAction SilentlyContinue
|
|
} else {
|
|
$env:WORKBUDDY_REMOTE_DEBUGGING_PORT = $previous
|
|
}
|
|
}
|
|
|
|
# ---------- 3. wait for the debug port ----------
|
|
Write-Host '[3/5] Waiting for debug port (up to 90s)...'
|
|
$ready = $false
|
|
for ($i = 1; $i -le 45; $i++) {
|
|
Start-Sleep -Seconds 2
|
|
try {
|
|
$null = Invoke-RestMethod "http://127.0.0.1:$DebugPort/json/version" -TimeoutSec 3
|
|
$ready = $true
|
|
break
|
|
} catch {
|
|
if (($i % 5) -eq 0) {
|
|
$waited = $i * 2
|
|
Write-Host " ...waited $waited s"
|
|
}
|
|
}
|
|
}
|
|
|
|
if (-not $ready) {
|
|
Write-Host '[FAIL] Debug port did not open. WorkBuddy is running normally, but without CDP.' -ForegroundColor Red
|
|
Write-Host 'Possible causes: the switch was removed in this version, or the port is taken.' -ForegroundColor Yellow
|
|
Write-Host 'Please send this window output back to the assistant.' -ForegroundColor Yellow
|
|
exit 2
|
|
}
|
|
Write-Host ' Port is ready.' -ForegroundColor Green
|
|
|
|
# ---------- 4. capture ----------
|
|
Write-Host '[4/5] Capturing UI styles...'
|
|
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
|
|
$target = Join-Path $OutDir $stamp
|
|
New-Item -ItemType Directory -Force -Path $target | Out-Null
|
|
|
|
Push-Location $ProjectRoot
|
|
try {
|
|
node scripts\wb-capture.mjs $DebugPort $target
|
|
} finally {
|
|
Pop-Location
|
|
}
|
|
|
|
# ---------- 5. summary ----------
|
|
Write-Host '[5/5] Done.'
|
|
Get-ChildItem -LiteralPath $target | Select-Object Name, Length | Format-Table -AutoSize
|
|
|
|
Write-Host ''
|
|
Write-Host 'Output directory:' -NoNewline
|
|
Write-Host " $target" -ForegroundColor Green
|
|
Write-Host ''
|
|
Write-Host 'Next steps:' -ForegroundColor Cyan
|
|
Write-Host ' 1) Go back to WorkBuddy, reopen the conversation, and send the directory path above to the assistant.'
|
|
Write-Host ' 2) To disable CDP later: exit WorkBuddy, then start it again WITHOUT the env var.'
|