-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.ps1
More file actions
275 lines (237 loc) · 8.9 KB
/
Copy pathinstall.ps1
File metadata and controls
275 lines (237 loc) · 8.9 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# Open Agent Kit (OAK) installer for Windows
# Usage: irm https://raw.githubusercontent.com/goondocks-co/open-agent-kit/main/install.ps1 | iex
#
# Detects available Python package managers and installs oak-ci from PyPI.
# Prefers: pipx > uv > pip (--user)
# Requires: Python >= 3.12
#
# Environment variables:
# OAK_INSTALL_METHOD - Force a specific method: pipx, uv, or pip
# OAK_VERSION - Install a specific version (e.g., "0.2.0")
$ErrorActionPreference = "Stop"
$Package = "oak-ci"
$MinPythonMajor = 3
$MinPythonMinor = 12
$MaxPythonMinor = 13
function Write-Info { param($Msg) Write-Host "==> $Msg" -ForegroundColor Blue }
function Write-Ok { param($Msg) Write-Host "==> $Msg" -ForegroundColor Green }
function Write-Warn { param($Msg) Write-Host "warning: $Msg" -ForegroundColor Yellow }
function Write-Err { param($Msg) Write-Host "error: $Msg" -ForegroundColor Red }
function Find-Python {
foreach ($cmd in @("python3", "python", "py")) {
$found = Get-Command $cmd -ErrorAction SilentlyContinue
if ($found) { return $found.Source }
}
return $null
}
function Test-PythonVersion {
param($PythonCmd)
try {
$version = & $PythonCmd -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>$null
$parts = $version.Split(".")
$major = [int]$parts[0]
$minor = [int]$parts[1]
if ($major -lt $MinPythonMajor -or ($major -eq $MinPythonMajor -and $minor -lt $MinPythonMinor)) {
return $null
}
if ($major -gt $MinPythonMajor -or ($major -eq $MinPythonMajor -and $minor -gt $MaxPythonMinor)) {
return $null
}
return $version
} catch {
return $null
}
}
function Install-WithPipx {
param($VersionSpec)
Write-Info "Installing with pipx..."
# Uninstall first — pipx ignores --python when --force is passed (pipx >=1.8)
pipx uninstall $Package 2>$null | Out-Null
if ($VersionSpec) {
pipx install "${Package}==${VersionSpec}"
} else {
pipx install $Package
}
}
function Install-WithUv {
param($VersionSpec)
Write-Info "Installing with uv..."
# Uninstall first to ensure clean install (mirrors pipx workaround)
uv tool uninstall $Package 2>$null | Out-Null
if ($VersionSpec) {
uv tool install "${Package}==${VersionSpec}"
} else {
uv tool install $Package
}
}
function Install-WithPip {
param($PythonCmd, $VersionSpec)
Write-Info "Installing with pip (--user)..."
if ($VersionSpec) {
& $PythonCmd -m pip install --user --upgrade "${Package}==${VersionSpec}"
} else {
& $PythonCmd -m pip install --user --upgrade $Package
}
}
function Test-VersionMatch {
param([string]$Actual, [string]$Expected)
if ([string]::IsNullOrWhiteSpace($Expected)) {
return $true
}
return $Actual -match [regex]::Escape($Expected)
}
function Test-PipxPackageInstalled {
param($VersionSpec)
$line = pipx list --short 2>$null | Where-Object { $_ -match "^$Package\s" } | Select-Object -First 1
if (-not $line) {
return $false
}
return (Test-VersionMatch -Actual $line -Expected $VersionSpec)
}
function Test-UvPackageInstalled {
param($VersionSpec)
$line = uv tool list 2>$null | Where-Object { $_ -match "^$Package\s" } | Select-Object -First 1
if (-not $line) {
return $false
}
return (Test-VersionMatch -Actual $line -Expected $VersionSpec)
}
function Test-PipPackageInstalled {
param($PythonCmd, $VersionSpec)
$show = & $PythonCmd -m pip show $Package 2>$null
if (-not $show) {
return $false
}
$versionLine = $show | Where-Object { $_ -match "^Version:\s" } | Select-Object -First 1
if (-not $versionLine) {
return $false
}
$installedVersion = $versionLine -replace "^Version:\s*", ""
if ([string]::IsNullOrWhiteSpace($VersionSpec)) {
return $true
}
return $installedVersion -eq $VersionSpec
}
function Test-InstallVerification {
param($Method, $PythonCmd, $VersionSpec)
switch ($Method) {
"pipx" { return Test-PipxPackageInstalled -VersionSpec $VersionSpec }
"uv" { return Test-UvPackageInstalled -VersionSpec $VersionSpec }
"pip" { return Test-PipPackageInstalled -PythonCmd $PythonCmd -VersionSpec $VersionSpec }
default { return $false }
}
}
function Main {
Write-Host ""
Write-Host " Open Agent Kit (OAK) Installer" -ForegroundColor White
Write-Host " The Intelligence Layer for AI Agents"
Write-Host ""
Write-Info "Detected OS: Windows"
# Find Python
$pythonCmd = Find-Python
if (-not $pythonCmd) {
Write-Err "Python ${MinPythonMajor}.${MinPythonMinor}-${MinPythonMajor}.${MaxPythonMinor} not found."
Write-Host ""
Write-Info "Install from: https://www.python.org/downloads/"
exit 1
}
# Check Python version
$pythonVersion = Test-PythonVersion $pythonCmd
if (-not $pythonVersion) {
$actual = & $pythonCmd --version 2>&1
Write-Err "Python ${MinPythonMajor}.${MinPythonMinor}+ required, found: $actual"
exit 1
}
Write-Info "Found Python $pythonVersion ($pythonCmd)"
# Determine version spec
$versionSpec = $env:OAK_VERSION
if ($versionSpec) {
Write-Info "Installing version: $versionSpec"
}
# Choose install method
$method = $env:OAK_INSTALL_METHOD
$actualMethod = $null
if ($method) {
Write-Info "Using requested method: $method"
switch ($method) {
"pipx" {
if (-not (Get-Command pipx -ErrorAction SilentlyContinue)) { Write-Err "pipx not found"; exit 1 }
Install-WithPipx $versionSpec
$actualMethod = "pipx"
}
"uv" {
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) { Write-Err "uv not found"; exit 1 }
Install-WithUv $versionSpec
$actualMethod = "uv"
}
"pip" {
Install-WithPip $pythonCmd $versionSpec
$actualMethod = "pip"
}
default {
Write-Err "Unknown method: $method (use: pipx, uv, or pip)"
exit 1
}
}
} elseif (Get-Command pipx -ErrorAction SilentlyContinue) {
Install-WithPipx $versionSpec
$actualMethod = "pipx"
} elseif (Get-Command uv -ErrorAction SilentlyContinue) {
Install-WithUv $versionSpec
$actualMethod = "uv"
} else {
Write-Warn "Neither pipx nor uv found, falling back to pip"
Install-WithPip $pythonCmd $versionSpec
$actualMethod = "pip"
}
if (-not (Test-InstallVerification -Method $actualMethod -PythonCmd $pythonCmd -VersionSpec $versionSpec)) {
Write-Err "Installation verification failed for method: $actualMethod"
Write-Info "Try setting OAK_INSTALL_METHOD=pipx|uv|pip and rerun installer"
exit 1
}
$oakBin = "oak"
# Verify installation
Write-Host ""
$oakCmd = Get-Command $oakBin -ErrorAction SilentlyContinue
if ($oakCmd) {
$installedVersion = & $oakBin --version 2>$null
if (-not $installedVersion) { $installedVersion = "unknown" }
if (-not (Test-VersionMatch -Actual $installedVersion -Expected $versionSpec)) {
Write-Err "Detected $oakBin command does not match requested version ($versionSpec)"
Write-Info "Restart your terminal and verify with: $oakBin --version"
exit 1
}
Write-Ok "OAK installed successfully! ($installedVersion)"
Write-Host ""
Write-Info "Get started:"
Write-Host " cd \path\to\your\project"
Write-Host " $oakBin init"
Write-Host " $oakBin ci start"
Write-Host ""
} else {
Write-Warn "$oakBin command not found in PATH"
# Detect the scripts directory where oak was installed
$scriptsDir = $null
if ($actualMethod -eq "pip") {
try {
$scriptsDir = & $pythonCmd -c "import sysconfig; print(sysconfig.get_path('scripts', 'nt_user'))" 2>$null
} catch {}
}
if ($scriptsDir -and (Test-Path $scriptsDir)) {
Write-Host ""
Write-Info "$oakBin was installed to: $scriptsDir"
Write-Host ""
Write-Info "Add it to your PATH (this session):"
Write-Host " `$env:PATH += `";$scriptsDir`"" -ForegroundColor Cyan
Write-Host ""
Write-Info "Add it permanently (run once):"
Write-Host " [Environment]::SetEnvironmentVariable(`"PATH`", [Environment]::GetEnvironmentVariable(`"PATH`", `"User`") + `";$scriptsDir`", `"User`")" -ForegroundColor Cyan
} else {
Write-Host ""
Write-Info "Restart your terminal or add the Python Scripts directory to PATH"
}
Write-Host ""
Write-Info "Then verify with: $oakBin --version"
}
}
Main