param([switch]$Check, [switch]$InstallOnly, [switch]$Desktop, [switch]$Authorize) $ErrorActionPreference = 'Stop' # PowerShell 7 can pass its module search path to Windows PowerShell 5.1. # Restore this host's built-in modules before checksum and ZIP commands run. $env:PSModulePath = (Join-Path $PSHOME 'Modules') + [IO.Path]::PathSeparator + $env:PSModulePath if ($InstallOnly -and ($Desktop -or $Authorize)) { throw 'Use -InstallOnly separately from account or desktop authorization options.' } if ($Check) { Write-Output 'BoxBridge guided installer: Windows x64, per-user Node runtime, CLI, Orca and cloud setup.'; exit 0 } if (-not [Environment]::Is64BitOperatingSystem -or $env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { throw 'The guided Windows installer supports x64.' } $bridgeRoot = Join-Path $env:LOCALAPPDATA 'BoxBridgeCLI' $runtimeRoot = Join-Path $bridgeRoot 'runtime' $node = Join-Path $runtimeRoot 'node.exe' New-Item -ItemType Directory -Force $runtimeRoot | Out-Null $stage = Join-Path $runtimeRoot ('.first-install-' + [Guid]::NewGuid().ToString('N')) New-Item -ItemType Directory $stage | Out-Null try { $valid = $false if (Test-Path $node) { & $node -e 'const [a,b]=process.versions.node.split(".").map(Number);process.exit(a>22||a===22&&b>=16?0:1)'; $valid = $LASTEXITCODE -eq 0 } if (-not $valid) { Write-Host 'Preparing private Node.js runtime…' $zip = Join-Path $stage 'node.zip' Invoke-WebRequest -UseBasicParsing 'https://nodejs.org/dist/v22.23.4/node-v22.23.4-win-x64.zip' -OutFile $zip -TimeoutSec 900 if ((Get-FileHash $zip -Algorithm SHA256).Hash.ToLowerInvariant() -ne 'cbc74b5e0982c9dbb41525fd8fb5dcd32fbee237863f7829072f4639a1ce5f20') { throw 'Node checksum mismatch; installation stopped.' } Expand-Archive $zip -DestinationPath $stage Copy-Item (Join-Path $stage 'node-v22.23.4-win-x64/node.exe') $node } $bootstrap = Join-Path $stage 'bootstrap.mjs' Invoke-WebRequest -UseBasicParsing 'https://lanshuagent.com/boxbridge/bootstrap-cli.mjs' -OutFile $bootstrap -TimeoutSec 180 if ((Get-FileHash $bootstrap -Algorithm SHA256).Hash.ToLowerInvariant() -ne '3db6733a135d15fe06f958e48cfa1217a00333fcb222ed09a848eeb32dec980f') { throw 'Installer checksum mismatch; installation stopped.' } $options = @() if ($InstallOnly) { $options += '--install-only' } if ($Desktop) { $options += '--desktop' } if ($Authorize) { $options += '--authorize' } & $node $bootstrap @options if ($LASTEXITCODE -ne 0) { throw 'BoxBridge setup paused. Read the step above, resolve it and run the installer again.' } } finally { Remove-Item $stage -Recurse -Force }