diff --git a/AGENT_INSTALL.md b/AGENT_INSTALL.md index fefb2c6..a637616 100644 --- a/AGENT_INSTALL.md +++ b/AGENT_INSTALL.md @@ -6,13 +6,22 @@ extension yourself (Step 3 is the user's job). ## 1. Install the CLI and skill -Run the install command from [`README.md`](README.md) (macOS/Linux): +Run the install command from [`README.md`](README.md): + +**macOS / Linux:** ```bash curl -fsSL https://raw.githubusercontent.com/Tencent/BrowserSkill/main/install.sh | sh bsk install-skill --yes ``` +**Windows (PowerShell):** + +```powershell +irm https://raw.githubusercontent.com/Tencent/BrowserSkill/main/install.ps1 | iex +bsk install-skill --yes +``` + ## 2. Run `bsk doctor` ```bash diff --git a/README.md b/README.md index 9bfccbc..6b91ae6 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,11 @@ Install the CLI, then install the extension from the [Chrome Web Store](https:// curl -fsSL https://raw.githubusercontent.com/Tencent/BrowserSkill/main/install.sh | sh ``` -**Windows**: download `bsk-v-x86_64-pc-windows-msvc.zip` from the -[latest CLI release](https://github.com/Tencent/BrowserSkill/releases/latest) -and add the extracted `bsk.exe` to your `PATH`. +**Windows** (PowerShell — installs to `~/.local/bin`): + +```powershell +irm https://raw.githubusercontent.com/Tencent/BrowserSkill/main/install.ps1 | iex +``` Verify the binary: diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..84a10dd --- /dev/null +++ b/install.ps1 @@ -0,0 +1,169 @@ +<# +.SYNOPSIS +install.ps1 — install the bsk CLI on Windows from GitHub Releases. + +.DESCRIPTION +Downloads the latest (or pinned) bsk release for Windows x64, +extracts bsk.exe to a user-local directory, and adds it to PATH. + +Usage: + irm https://raw.githubusercontent.com/Tencent/BrowserSkill/main/install.ps1 | iex + +Environment overrides: + $env:BSK_REPO GitHub owner/repo (default: Tencent/BrowserSkill) + $env:BSK_VERSION Pin CLI version (default: latest from version.json) + $env:BSK_INSTALL_DIR Install directory (default: $HOME\.local\bin) +#> + +#Requires -Version 5.1 + +$ErrorActionPreference = "Stop" + +$Repo = if ($env:BSK_REPO) { $env:BSK_REPO } else { "Tencent/BrowserSkill" } +$InstallDir = if ($env:BSK_INSTALL_DIR) { $env:BSK_INSTALL_DIR } else { Join-Path $HOME ".local\bin" } +$GitHub = "https://github.com/${Repo}" + +function Write-Log { + param([string]$Message) + Write-Host "==> $Message" -ForegroundColor Cyan +} + +function Write-Die { + param([string]$Message) + Write-Host "error: $Message" -ForegroundColor Red + exit 1 +} + +# ── Platform / architecture detection ───────────────────────────────────────── + +function Get-PlatformTriple { + $arch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture + + switch ($arch) { + "X64" { $archId = "x64" } + "Arm64" { $archId = "arm64" } + default { Write-Die "unsupported architecture: $arch (x64 and ARM64 only)" } + } + + $windowsArch = switch ($archId) { + "x64" { "x86_64-pc-windows-msvc" } + "arm64" { "aarch64-pc-windows-msvc" } + } + + return @{ + ArchId = $archId + TargetTriple = $windowsArch + } +} + +# ── Version resolution ──────────────────────────────────────────────────────── + +function Get-LatestVersion { + $versionJsonUrl = "${GitHub}/releases/latest/download/version.json" + Write-Log "fetching latest version from ${versionJsonUrl}" + + try { + $version = (Invoke-RestMethod -Uri $versionJsonUrl).version + if (-not $version) { Write-Die "could not parse version from version.json" } + return $version + } + catch { + Write-Die "failed to fetch version.json: $_" + } +} + +# ── PATH helpers ────────────────────────────────────────────────────────────── + +function Add-ToUserPath { + param([string]$Dir) + + $currentUserPath = [Environment]::GetEnvironmentVariable("PATH", "User") -split ";" | Where-Object { $_ } + + if ($currentUserPath -contains $Dir) { + Write-Log "$Dir is already in your user PATH" + return + } + + $newUserPath = ($currentUserPath + $Dir) -join ";" + [Environment]::SetEnvironmentVariable("PATH", $newUserPath, "User") + Write-Log "added ${Dir} to user PATH" +} + +function Add-ToSessionPath { + param([string]$Dir) + + $pathEntries = $env:PATH -split ";" | Where-Object { $_ } + if ($pathEntries -contains $Dir) { + return + } + + $env:PATH = "$Dir;$env:PATH" +} + +# ── Main ────────────────────────────────────────────────────────────────────── + +function Main { + $platform = Get-PlatformTriple + + if ($env:BSK_VERSION) { + $version = $env:BSK_VERSION -replace '^v', '' + Write-Log "using pinned version ${version}" + } + else { + $version = Get-LatestVersion + Write-Log "latest version is ${version}" + } + + $tag = "cli-v${version}" + $archiveName = "bsk-v${version}-$($platform.TargetTriple).zip" + $downloadUrl = "${GitHub}/releases/download/${tag}/${archiveName}" + + $tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName()) + New-Item -ItemType Directory -Path $tempDir -Force | Out-Null + + try { + $archivePath = Join-Path $tempDir $archiveName + + Write-Log "downloading ${downloadUrl}" + Invoke-WebRequest -Uri $downloadUrl -OutFile $archivePath -UseBasicParsing -ErrorAction Stop + + Write-Log "extracting ${archiveName}" + Expand-Archive -Path $archivePath -DestinationPath $tempDir -Force + + if (-not (Test-Path (Join-Path $tempDir "bsk.exe"))) { + Write-Die "bsk.exe not found in archive" + } + + if (-not (Test-Path $InstallDir)) { + New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null + } + + Copy-Item -Path (Join-Path $tempDir "bsk.exe") -Destination (Join-Path $InstallDir "bsk.exe") -Force + + Write-Log "installed bsk to $InstallDir\bsk.exe" + + # Add to session PATH (current shell) + Add-ToSessionPath $InstallDir + + # Add to user PATH (persistent) + Add-ToUserPath $InstallDir + + # Verify + $bskPath = Join-Path $InstallDir "bsk.exe" + if (Get-Command bsk -ErrorAction SilentlyContinue) { + & bsk --version + } + else { + Write-Log "verify install: & ""$bskPath"" --version" + } + + Write-Log "done" + Write-Host "" + Write-Host "Open a new PowerShell window for PATH changes to take full effect." + } + finally { + Remove-Item -Recurse -Force $tempDir -ErrorAction SilentlyContinue + } +} + +Main