# Install lvcs on Windows from a release on releases.lvcs.sh # (docs/production-readiness.md, R3; decisions 252 and 421), in Windows PowerShell # 5.1 or PowerShell 7: # # irm https://ps.lvcs.sh | iex # curl.exe -fsSL https://ps.lvcs.sh | powershell -c - # # It downloads lvcs--.zip, SHA256SUMS, and the release's # Ed25519-signed manifest.json (decisions 293, 315, and 380), and installs # only when the archive passes a check independent of the download. # SHA256SUMS comes from the same place as the archive, so it only catches # corruption. The independent check is: the manifest's SHA-256 pinned in # this script for the version ($releasePins below, written when the release # is published; this script is served from ps.lvcs.sh, not from the # release), then the archive's hash that manifest lists; else the # manifest's signature checked by the lvcs.exe already installed (Windows # PowerShell has no Ed25519). With neither it refuses and says how to go # on; it never asks the downloaded lvcs.exe to vouch for itself. When cosign # is on PATH and the release has a Sigstore bundle, SHA256SUMS's bundle is # verified too; a release published by hand has none, which it says in one # line. It installs without elevation and adds the directory to the user # PATH. # # Environment: # LVCS_VERSION the release to install, as 0.1.0 or v0.1.0 (default: # the newest release pinned below, else the latest) # LVCS_INSTALL_DIR where lvcs.exe goes (default: # %LOCALAPPDATA%\Programs\lvcs\bin) # LVCS_BASE_URL a URL serving one release's files in place of GitHub (a # mirror, or an install test); needs a version # (LVCS_VERSION or a pin) # LVCS_NO_SERVICE when 1, skip the last step, `lvcs install`, which runs # the per-user daemon as a Scheduled Task at logon # (decision 272) # # No Windows build is published until the Windows port lands (W1 to W9), so # until then this stops at the download and says so. # # Everything runs inside one script block, so `iex` leaves no variables in # the caller's session and a failure throws instead of closing the shell. & { Set-StrictMode -Version 2 $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # Windows PowerShell 5.1 may default to TLS 1.0, which the releases host refuses. [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 # The releases host (lvcs_vocab::ids::RELEASES_URL, decision 421): each # release's archives, SHA256SUMS, and signed manifest under v/, # and the newest release's manifest under latest/. A Sigstore bundle, # when a release has one, is signed by the source repository's release # workflow. $releases = 'https://releases.lvcs.sh' $signer = "^https://github\.com/gabewillen/lvcs/\.github/workflows/release\.yml@refs/tags/v" $issuer = 'https://token.actions.githubusercontent.com' # One ' ' per published release, # newest last, written by scripts/release-pin.sh when the release is # published (decision 380). # release-pins:begin $releasePins = @( '0.1.0 cbe4b24ef91c21cbe4b8b09ef4ae6b16cf6897895fdabf6adef0256ed27c315a' '0.1.2 3905c8c6c09d38625bf376a98a732c30ded8c1e8c717a4609e080e06b5ba5706' '0.1.3 d100472a0cb795f7f1e880f0c3473e7494da487a102b8d5210e7aea5941b267c' '0.2.0 5891d7c5c4f3123dc96b7eef437901f6b33c05feeee2850cf391b93b2fafd94f' '0.2.1 4742f31001927c2aa660c6d4265078e505fae481c0a3273ff6b004adef552b0b' '0.2.2 26931d5f1c9232d1f655bb2483138a09d514e1c807f6818ea903f56ecd8fc104' '0.2.3 70bbd01f0a6a63ee35e00cc1d63fd356f4d2a81460d56918b321df5a6eede242' '0.2.4 1b0fbd11bc6e767666a727da12c3a58df7b67cc7c8022960b441ad174172585c' '0.2.5 a520befa408630ef422e48ffe8ca6eda98accf45290a571780c2e960851bca0f' '0.2.6 e376d55e9ea9872f65e94957737e8c8b2cabc79a7ec1f274c57da40ec5413a81' '0.2.7 cdf60029187d40b0385b4ba4044b108e7a1e56810b7a63469f711120db1825e6' '0.2.8 3ec55e0a76802c9cd0f5dacb70ab8812e0492f0d86dd2e17e29bac72e41b9757' '0.2.9 503e3e096bd6b12ef153813878eed43e7a75be056ba741f8d65f8f5d8e54ebb8' '0.2.10 ff761b5d7e577a80b0a9a1f0a6a2152b3e25b93a4b05fdf5814519e0941d7358' '0.2.11 941b8d3c03f0a16dfa9bff28c40b3ca4fac787131e2f350fb494b6d32c1099bc' '0.2.12 772036cfd20085b07e6952fc11154ba913b64b465b0ffdf08c7b2a0e633e289c' '0.2.13 d430a8b858de1041d1f5f4e1e1a6856247eb3a11a496c18a456dcc9f71dbeb60' '0.2.14 3d4af9c217128166aa8c46323a5282a6f80434fe553448e6a94de8beaf4e0b00' '0.3.0 9e35d80a057db617c0aca6788735562e2a04a2cf7db26d8c0c030f238eb9d70a' '0.3.1 bb075cde64dbbb1cbbce14def5276dbadc7f71ce3381bf56f05ccc968ed5f30e' ) # release-pins:end $pins = [ordered]@{} foreach ($entry in $releasePins) { $fields = "$entry".Trim() -split '\s+' if ($fields.Count -eq 2) { $pins[$fields[0]] = $fields[1] } } function Say([string]$message) { [Console]::Error.WriteLine("agentflare-install: $message") } # A 32-bit PowerShell on 64-bit Windows reports the real CPU here. $cpu = $env:PROCESSOR_ARCHITEW6432 if (-not $cpu) { $cpu = $env:PROCESSOR_ARCHITECTURE } switch ($cpu) { 'AMD64' { $arch = 'x86_64' } 'ARM64' { $arch = 'aarch64' } default { throw "agentflare-install: no release for architecture '$cpu': releases cover x86_64 (AMD64) and aarch64 (ARM64)" } } $target = "$arch-pc-windows-msvc" $version = "$env:LVCS_VERSION" -replace '^v', '' if (-not $version -and $pins.Count -gt 0) { $version = @($pins.Keys)[$pins.Count - 1] } if ($env:LVCS_BASE_URL) { if (-not $version) { throw 'agentflare-install: LVCS_BASE_URL needs LVCS_VERSION (this installer pins no release)' } $base = "$env:LVCS_BASE_URL".TrimEnd('/') } else { if (-not $version) { # Only the version is read here; the release itself is checked below. $latest = "$releases/latest/manifest.json" try { $text = (Invoke-WebRequest -UseBasicParsing -Uri $latest).Content } catch { throw "agentflare-install: could not reach $latest ($($_.Exception.Message)); set LVCS_VERSION to pick a release" } if ("$text" -notmatch '"version":\s*"([0-9A-Za-z.+-]+)"') { throw "agentflare-install: found no version in $latest; set LVCS_VERSION to pick one" } $version = $Matches[1] } $base = "$releases/v$version" } if ($env:LVCS_INSTALL_DIR) { $dir = $env:LVCS_INSTALL_DIR } elseif ($env:LOCALAPPDATA) { $dir = Join-Path $env:LOCALAPPDATA 'Programs\lvcs\bin' } else { throw 'agentflare-install: LOCALAPPDATA is unset; set LVCS_INSTALL_DIR' } $tmp = Join-Path ([IO.Path]::GetTempPath()) ("agentflare-install-" + [guid]::NewGuid()) New-Item -ItemType Directory -Path $tmp | Out-Null try { Say "downloading agentflare $version for $target" foreach ($file in @('manifest.json', 'manifest.json.sig')) { try { Invoke-WebRequest -UseBasicParsing -Uri "$base/$file" -OutFile (Join-Path $tmp $file) } catch { throw "agentflare-install: could not download $base/$file ($($_.Exception.Message))" } } $manifest = Join-Path $tmp 'manifest.json' $sig = Join-Path $tmp 'manifest.json.sig' $parsed = Get-Content -Raw $manifest | ConvertFrom-Json $targetEntry = $parsed.targets.PSObject.Properties[$target] if (-not $targetEntry -or -not $targetEntry.Value.file) { throw "agentflare-install: manifest.json lists no archive for $target" } $archive = "$($targetEntry.Value.file)" if ($archive -match '[/\\]' -or $archive -match '\.\.') { throw "agentflare-install: manifest.json lists an invalid archive name '$archive'" } # The release's hash for the archive, checked independently of the # download: through the manifest hash pinned here, else the # manifest's signature checked by the installed agentflare.exe or # lvcs.exe. Nothing from the download is unpacked or run before this passes. $installedAf = Join-Path $dir 'agentflare.exe' $installedLegacy = Join-Path $dir 'lvcs.exe' $verifier = $null if (Test-Path -PathType Leaf $installedAf) { $verifier = $installedAf } elseif (Test-Path -PathType Leaf $installedLegacy) { $verifier = $installedLegacy } $listedHash = $null if ($pins.Contains($version)) { $pin = $pins[$version] $have = (Get-FileHash -Algorithm SHA256 -Path $manifest).Hash if ($have -ne $pin) { throw "agentflare-install: refusing to install: manifest.json has SHA-256 $have, but this installer pins $pin for agentflare $version, so the release is not the one published" } $listedHash = "$($targetEntry.Value.sha256)" if (-not $listedHash) { throw "agentflare-install: refusing to install: the release manifest lists no $archive" } Say "verified the release manifest against the hash this installer pins for agentflare $version" } elseif ($verifier) { $listed = & $verifier release-verify $manifest $sig $archive if ($LASTEXITCODE -ne 0) { throw "agentflare-install: refusing to install: the release manifest's signature did not verify" } $listedHash = ("$listed".Trim() -split '\s+')[0] Say "verified the release manifest's signature with the installed $(Split-Path -Leaf $verifier)" } else { $pinned = if ($pins.Count -gt 0) { @($pins.Keys) -join ', ' } else { 'none' } Say "refusing to install: nothing here can check agentflare $version independently of the download:" Say " this installer pins no manifest hash for $version (it pins $pinned), and there is no agentflare.exe or lvcs.exe in $dir." Say "next: install a pinned version (unset LVCS_VERSION), then run agentflare update, which checks the" Say " signature itself; or verify manifest.json.sig on a machine with OpenSSL 3 and install by hand." throw "agentflare-install: refusing to install: no independent check for agentflare $version" } foreach ($file in @($archive, 'SHA256SUMS')) { try { Invoke-WebRequest -UseBasicParsing -Uri "$base/$file" -OutFile (Join-Path $tmp $file) } catch { throw "agentflare-install: could not download $base/$file ($($_.Exception.Message))" } } $sums = Join-Path $tmp 'SHA256SUMS' $bundle = Join-Path $tmp 'SHA256SUMS.sigstore.json' if (-not (Get-Command cosign -ErrorAction SilentlyContinue)) { Say 'cosign is not on PATH, so no Sigstore signature is checked (the release manifest still is)' } elseif (-not (& { try { Invoke-WebRequest -UseBasicParsing -Uri "$base/SHA256SUMS.sigstore.json" -OutFile $bundle; $true } catch { $false } })) { Say 'this release has no Sigstore bundle (it was published outside GitHub Actions), so cosign is skipped; the signed manifest is checked' } else { & cosign verify-blob --bundle $bundle --certificate-identity-regexp $signer --certificate-oidc-issuer $issuer $sums | Out-Null if ($LASTEXITCODE -ne 0) { throw 'agentflare-install: refusing to install: the Sigstore signature on SHA256SUMS did not verify' } Say 'verified the Sigstore signature on SHA256SUMS' } $want = $null foreach ($line in Get-Content $sums) { $fields = "$line".Trim() -split '\s+' if ($fields.Count -eq 2 -and $fields[1].TrimStart('*') -eq $archive) { $want = $fields[0]; break } } if (-not $want) { throw "agentflare-install: SHA256SUMS lists no $archive" } $got = (Get-FileHash -Algorithm SHA256 -Path (Join-Path $tmp $archive)).Hash # -ne is case-insensitive; Get-FileHash prints upper case, sha256sum lower. if ($got -ne $want) { throw "agentflare-install: refusing to install: $archive has SHA-256 $got, but SHA256SUMS says $want" } if ($got -ne $listedHash) { throw "agentflare-install: refusing to install: $archive has SHA-256 $got, but the release manifest says $listedHash" } $unpacked = Join-Path $tmp 'x' Expand-Archive -Path (Join-Path $tmp $archive) -DestinationPath $unpacked if (Test-Path -PathType Leaf (Join-Path $unpacked 'agentflare.exe')) { $binName = 'agentflare' $exeName = 'agentflare.exe' $markerName = 'agentflare.install' } elseif (Test-Path -PathType Leaf (Join-Path $unpacked 'lvcs.exe')) { $binName = 'lvcs' $exeName = 'lvcs.exe' $markerName = 'lvcs.install' } else { throw "agentflare-install: $archive holds neither agentflare.exe nor lvcs.exe" } $new = Join-Path $unpacked $exeName New-Item -ItemType Directory -Force -Path $dir | Out-Null $exe = Join-Path $dir $exeName # Windows cannot overwrite a running .exe but can rename it. $old = "$exe.old" if (Test-Path $old) { Remove-Item -Force $old -ErrorAction SilentlyContinue } if (Test-Path $exe) { Move-Item -Force $exe $old } Copy-Item $new $exe New-Item -ItemType File -Force -Path (Join-Path $dir $markerName) | Out-Null Say "installed $(& $exe --version) to $exe" # The Claude Code plugin's hook helper ships in the same signed # archive (decision 513); its hooks find it here. $helper = Join-Path $unpacked 'lvcs-claude-code.exe' if (Test-Path -PathType Leaf $helper) { $helperExe = Join-Path $dir 'lvcs-claude-code.exe' if (Test-Path "$helperExe.old") { Remove-Item -Force "$helperExe.old" -ErrorAction SilentlyContinue } if (Test-Path $helperExe) { Move-Item -Force $helperExe "$helperExe.old" } Copy-Item $helper $helperExe } # The plugins the release ships (decision 514), each a directory # under plugins\ beside the binary, where `init` finds the # bundled ones; swapped in whole, so an installed plugin keeps its # path. Windows archives ship none yet. $plugins = Join-Path $unpacked 'plugins' if (Test-Path -PathType Container $plugins) { $installed = Join-Path $dir 'plugins' $pluginsOld = Join-Path $dir 'plugins.old' if (Test-Path $pluginsOld) { Remove-Item -Recurse -Force $pluginsOld -ErrorAction SilentlyContinue } if (Test-Path $installed) { Move-Item -Force $installed $pluginsOld } Copy-Item -Recurse $plugins $installed if (Test-Path $pluginsOld) { Remove-Item -Recurse -Force $pluginsOld -ErrorAction SilentlyContinue } } $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') if (-not $userPath) { $userPath = '' } $entries = $userPath -split ';' | Where-Object { $_ } | ForEach-Object { $_.TrimEnd('\') } if ($entries -notcontains $dir.TrimEnd('\')) { $joined = (@($userPath.TrimEnd(';'), $dir) | Where-Object { $_ }) -join ';' [Environment]::SetEnvironmentVariable('Path', $joined, 'User') Say "added $dir to your user PATH; open a new terminal to use it there" } if ((($env:Path -split ';') | ForEach-Object { $_.TrimEnd('\') }) -notcontains $dir.TrimEnd('\')) { $env:Path = "$env:Path;$dir" } # The per-user daemon, as a Scheduled Task at logon (decision 272). if ($env:LVCS_NO_SERVICE -eq '1') { Say "LVCS_NO_SERVICE=1: not installing the daemon's service; run $binName install, or $binName daemon in the foreground" } else { & $exe install if ($LASTEXITCODE -ne 0) { throw "agentflare-install: $binName install failed; run it again, or set LVCS_NO_SERVICE=1 and run $binName daemon yourself" } } } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } }