param( [string]$Token = "TQExdmXUMwhPlV58YfgueAscatHrZBKnI1W63Dq7", [string]$InstallRoot = "$env:USERPROFILE\Desktop\Vigthoria Code\vigthoria-desktop-bridge-mvp-20260520-v013-live", [string]$ZipUrl = "https://extension.vigthoria.io/downloads/vigthoria-desktop-bridge-mvp-20260520.zip" ) $ErrorActionPreference = "Stop" function Stop-BridgePort { Write-Host "Stopping any process listening on 127.0.0.1:49160..." for ($i = 0; $i -lt 5; $i++) { $listeners = @(Get-NetTCPConnection -LocalPort 49160 -State Listen -ErrorAction SilentlyContinue) if ($listeners.Count -eq 0) { return } foreach ($listener in $listeners) { if ($listener.OwningProcess) { Write-Host "Stopping PID $($listener.OwningProcess)" Stop-Process -Id $listener.OwningProcess -Force -ErrorAction SilentlyContinue } } Start-Sleep -Milliseconds 600 } } function Ensure-Install { if ((Test-Path (Join-Path $InstallRoot "src\local-desktop-bridge.js")) -and (Test-Path (Join-Path $InstallRoot "node_modules\ws"))) { return } Write-Host "Install root missing or incomplete. Downloading package..." $zipPath = Join-Path $env:TEMP "vigthoria-desktop-bridge-mvp-20260520.zip" $extractRoot = Join-Path $env:TEMP "vigthoria-desktop-bridge-live-start" Set-Location $env:TEMP Invoke-WebRequest -Uri $ZipUrl -OutFile $zipPath -UseBasicParsing if (Test-Path $extractRoot) { Remove-Item $extractRoot -Recurse -Force } New-Item -ItemType Directory -Path $extractRoot -Force | Out-Null Expand-Archive -Path $zipPath -DestinationPath $extractRoot -Force if (Test-Path $InstallRoot) { Remove-Item $InstallRoot -Recurse -Force -ErrorAction SilentlyContinue } New-Item -ItemType Directory -Path (Split-Path $InstallRoot -Parent) -Force | Out-Null Move-Item -Path (Join-Path $extractRoot "vigthoria-desktop-bridge-mvp") -Destination $InstallRoot Push-Location $InstallRoot $previousPreference = $ErrorActionPreference $ErrorActionPreference = "Continue" & npm.cmd install $npmExitCode = $LASTEXITCODE $ErrorActionPreference = $previousPreference if ($npmExitCode -ne 0) { throw "npm install failed with exit code $npmExitCode" } Pop-Location } Ensure-Install Stop-BridgePort $env:VIGTHORIA_DESKTOP_TOKEN = $Token $env:VIGTHORIA_DESKTOP_ALLOW_CONTROL = "1" $env:VIGTHORIA_DESKTOP_HEALTH_SCREEN = "1" Set-Location $InstallRoot Write-Host "Starting CDP-enabled Vigthoria Desktop Bridge from: $InstallRoot" Write-Host "Using node directly to avoid npm.ps1 NativeCommandError formatting." & node.exe .\src\local-desktop-bridge.js