-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.ps1
More file actions
257 lines (223 loc) · 8.91 KB
/
Copy pathinstall.ps1
File metadata and controls
257 lines (223 loc) · 8.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# Coven Code installer for Windows (PowerShell).
#
# Usage (one-liner):
# irm https://github.com/OpenCoven/coven-code/releases/latest/download/install.ps1 | iex
#
# Or download and run locally:
# Invoke-WebRequest https://github.com/OpenCoven/coven-code/releases/latest/download/install.ps1 -OutFile install.ps1
# .\install.ps1
[CmdletBinding()]
param(
[string]$Version = "",
[string]$Binary = "",
[string]$InstallDir = "",
[switch]$NoModifyPath,
[switch]$Help
)
$ErrorActionPreference = 'Stop'
$App = 'coven-code'
$Repo = 'OpenCoven/coven-code'
function Write-Info($msg) { Write-Host $msg }
function Write-Success($msg) { Write-Host $msg -ForegroundColor Green }
function Write-Warn($msg) { Write-Host $msg -ForegroundColor Yellow }
function Write-Err($msg) { Write-Host $msg -ForegroundColor Red }
function Write-Muted($msg) { Write-Host $msg -ForegroundColor DarkGray }
function Show-Usage {
@"
Coven Code installer (Windows)
Usage: install.ps1 [options]
Options:
-Help Show this help
-Version <version> Install a specific version (e.g., 0.1.0)
-Binary <path> Install from a local binary instead of downloading
-InstallDir <path> Override install location (default: %USERPROFILE%\.coven-code\bin)
-NoModifyPath Don't add the install dir to user PATH
Examples:
irm https://github.com/OpenCoven/coven-code/releases/latest/download/install.ps1 | iex
.\install.ps1 -Version 0.1.0
.\install.ps1 -Binary C:\path\to\coven-code.exe
"@
}
if ($Help) { Show-Usage; exit 0 }
# ----- Detect architecture -----
function Get-Arch {
$procArch = $env:PROCESSOR_ARCHITECTURE
if ($null -eq $procArch) { $procArch = '' }
switch ($procArch.ToLower()) {
'amd64' { return 'x86_64' }
'x86' { return 'x86_64' } # rare; ship 64-bit anyway
'arm64' {
Write-Warn "ARM64 Windows is not currently supported in releases. Falling back to x86_64."
return 'x86_64'
}
default {
Write-Warn "Unknown architecture '$procArch'. Defaulting to x86_64."
return 'x86_64'
}
}
}
# ----- Resolve install directory -----
if ([string]::IsNullOrEmpty($InstallDir)) {
$InstallDir = Join-Path $env:USERPROFILE ".coven-code\bin"
}
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
# ----- Resolve version (latest if not provided) -----
function Resolve-Version {
if (-not [string]::IsNullOrEmpty($script:Version)) {
return ($script:Version -replace '^v', '')
}
try {
$resp = Invoke-RestMethod -UseBasicParsing -Uri "https://api.github.com/repos/$Repo/releases/latest" -Headers @{ 'User-Agent' = 'coven-code-installer' }
$tag = $resp.tag_name
if ([string]::IsNullOrEmpty($tag)) { throw "no tag_name in response" }
return ($tag -replace '^v', '')
} catch {
Write-Err "Failed to fetch latest version from GitHub API: $_"
exit 1
}
}
# ----- Already-installed check -----
function Check-Existing($desiredVersion) {
$existing = Get-Command coven-code -ErrorAction SilentlyContinue
if ($null -eq $existing) { return }
try {
$vline = (& coven-code --version) 2>&1 | Select-Object -First 1
$installed = ($vline -split '\s+')[-1]
} catch {
$installed = 'unknown'
}
if ($installed -eq $desiredVersion) {
Write-Muted "Version $desiredVersion already installed at $($existing.Source)"
Write-Muted "Use -Version to install a different one."
exit 0
}
Write-Muted "Found existing coven-code at $($existing.Source) (v$installed) - upgrading to v$desiredVersion"
}
# ----- Download & extract -----
function Download-And-Install($desiredVersion, $arch) {
$archive = "coven-code-windows-$arch.zip"
$url = "https://github.com/$Repo/releases/download/v$desiredVersion/$archive"
$tmpRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("coven-code-install-" + [System.Guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $tmpRoot -Force | Out-Null
$zipPath = Join-Path $tmpRoot $archive
$extractDir = Join-Path $tmpRoot "extract"
New-Item -ItemType Directory -Path $extractDir -Force | Out-Null
Write-Info "Installing coven-code v$desiredVersion (windows-$arch)"
Write-Muted "Downloading $url"
try {
# Disable progress UI for a faster, less noisy download.
$oldPref = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $zipPath
$ProgressPreference = $oldPref
} catch {
Write-Err "Download failed: $_"
Write-Info ("Check that release v$desiredVersion exists for windows-" + $arch + ":")
Write-Info " https://github.com/$Repo/releases/tag/v$desiredVersion"
Remove-Item -Recurse -Force $tmpRoot -ErrorAction SilentlyContinue
exit 1
}
Write-Muted "Extracting..."
try {
Expand-Archive -Path $zipPath -DestinationPath $extractDir -Force
} catch {
Write-Err "Extract failed: $_"
Remove-Item -Recurse -Force $tmpRoot -ErrorAction SilentlyContinue
exit 1
}
$extractedExe = Join-Path $extractDir 'coven-code.exe'
if (-not (Test-Path $extractedExe)) {
Write-Err "Archive did not contain expected binary 'coven-code.exe'"
Get-ChildItem -Recurse $extractDir | Format-Table FullName
Remove-Item -Recurse -Force $tmpRoot -ErrorAction SilentlyContinue
exit 1
}
Install-Binary $extractedExe
Remove-Item -Recurse -Force $tmpRoot -ErrorAction SilentlyContinue
}
function Install-FromBinary {
if (-not (Test-Path $script:Binary)) {
Write-Err "Binary not found at $script:Binary"
exit 1
}
Write-Info "Installing coven-code from $script:Binary"
Install-Binary $script:Binary
}
function Install-Binary($source) {
$target = Join-Path $InstallDir 'coven-code.exe'
$aliasTarget = Join-Path $InstallDir 'coven-cave.exe'
# `coven.exe` belongs to the Coven daemon CLI (@opencoven/cli); older
# installers shipped it as an alias, so clean it up on upgrade.
$staleShort = Join-Path $InstallDir 'coven.exe'
# The currently running coven-code.exe (if any) holds an exclusive file lock on
# Windows. Try to swap by renaming the old one first.
foreach ($path in @($target, $aliasTarget, $staleShort)) {
if (-not (Test-Path $path)) { continue }
$stale = "$path.old"
if (Test-Path $stale) { Remove-Item -Force $stale -ErrorAction SilentlyContinue }
try { Move-Item -Force $path $stale } catch { }
}
Copy-Item -Force $source $target
Copy-Item -Force $source $aliasTarget
Write-Success "Installed: $target"
Write-Success "Installed alias: $aliasTarget"
}
# ----- PATH modification -----
function Add-ToUserPath {
if ($NoModifyPath) { return }
$current = [Environment]::GetEnvironmentVariable('Path', 'User')
if ($null -eq $current) { $current = '' }
# Already on PATH?
$paths = $current -split ';' | Where-Object { $_ -ne '' }
foreach ($p in $paths) {
if ($p.TrimEnd('\') -ieq $InstallDir.TrimEnd('\')) {
Write-Muted "Install dir already on user PATH: $InstallDir"
return
}
}
if ([string]::IsNullOrEmpty($current)) {
$newPath = $InstallDir
} else {
$newPath = $InstallDir + ';' + $current
}
[Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
# Make it visible in this session too so coven-code --version works immediately.
$env:Path = $InstallDir + ';' + $env:Path
Write-Success ("Added " + $InstallDir + " to user PATH")
Write-Muted "Open a new terminal for the change to take effect everywhere."
}
# ----- GitHub Actions hint -----
function GithubPathHint {
if ($env:GITHUB_ACTIONS -eq 'true' -and -not [string]::IsNullOrEmpty($env:GITHUB_PATH)) {
Add-Content -Path $env:GITHUB_PATH -Value $InstallDir
Write-Info "Added $InstallDir to `$GITHUB_PATH"
}
}
# ----- Main flow -----
Write-Info "Tip: the unified Coven CLI installs and manages this engine for you -- 'npm install -g @opencoven/cli', then run 'coven'. This standalone installer still works."
if (-not [string]::IsNullOrEmpty($Binary)) {
Install-FromBinary
} else {
$arch = Get-Arch
$desiredVersion = Resolve-Version
Check-Existing $desiredVersion
Download-And-Install $desiredVersion $arch
}
Add-ToUserPath
GithubPathHint
Write-Host ""
Write-Success "coven-code is installed!"
Write-Host ""
Write-Muted "Quickstart:"
Write-Muted " # Set an API key"
Write-Host " `$env:ANTHROPIC_API_KEY = 'sk-ant-...'"
Write-Host ""
Write-Muted " # Open a new terminal, then:"
Write-Success " coven-code "
Write-Success " coven-cave "
Write-Muted " # or"
Write-Success " coven-code -p `"...`" "
Write-Host ""
Write-Muted "Docs: https://github.com/$Repo"