-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
111 lines (91 loc) · 3.49 KB
/
install.ps1
File metadata and controls
111 lines (91 loc) · 3.49 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
# OpenAnalyst CLI Installer - Windows PowerShell
# Usage: irm https://raw.githubusercontent.com/OpenAnalystInc/cli/main/install.ps1 | iex
$ErrorActionPreference = "Continue"
try { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 } catch {}
$PackageName = "@openanalystinc/openanalyst-cli"
$LegacyPackageName = "@openanalyst/cli"
function Test-OpenAnalystShim {
param([string]$Path)
if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
return $false
}
try {
$Content = Get-Content -LiteralPath $Path -Raw -ErrorAction Stop
} catch {
return $false
}
return $Content -match '@openanalyst[\\/]+cli' `
-or $Content -match '@openanalystinc[\\/]+openanalyst-cli' `
-or $Content -match 'node_modules[\\/]+@openanalyst'
}
function Repair-OpenAnalystGlobalBin {
$Prefix = $null
try { $Prefix = (npm prefix -g 2>$null).Trim() } catch {}
if (-not $Prefix) { return }
try {
$ResolvedPrefix = [System.IO.Path]::GetFullPath($Prefix)
$PrefixRoot = $ResolvedPrefix.TrimEnd('\', '/') + [System.IO.Path]::DirectorySeparatorChar
} catch {
return
}
foreach ($Name in @("openanalyst", "openanalyst.cmd", "openanalyst.ps1")) {
$Candidate = Join-Path $ResolvedPrefix $Name
try { $FullPath = [System.IO.Path]::GetFullPath($Candidate) } catch { continue }
if (-not $FullPath.StartsWith($PrefixRoot, [System.StringComparison]::OrdinalIgnoreCase)) {
continue
}
if (Test-OpenAnalystShim $FullPath) {
try {
Remove-Item -LiteralPath $FullPath -Force -ErrorAction Stop
} catch {
Write-Host " Could not remove stale shim: $FullPath" -ForegroundColor Yellow
}
}
}
}
Write-Host ""
Write-Host " OpenAnalyst CLI" -ForegroundColor DarkCyan
Write-Host " The Universal AI Agent for Your Terminal" -ForegroundColor DarkGray
Write-Host ""
# Check for Node.js
$NodeVersion = $null
try { $NodeVersion = (node --version 2>$null) } catch {}
if (-not $NodeVersion) {
Write-Host " Node.js is required but not found." -ForegroundColor Red
Write-Host " Install from: https://nodejs.org/" -ForegroundColor DarkGray
Write-Host ""
exit 1
}
Write-Host " Node.js $NodeVersion detected" -ForegroundColor DarkGray
# Repair legacy global installs before npm links the new binary.
Repair-OpenAnalystGlobalBin
try { npm uninstall -g $LegacyPackageName $PackageName --silent 2>&1 | Out-Null } catch {}
Repair-OpenAnalystGlobalBin
# Install via npm
Write-Host ""
Write-Host " Installing..." -ForegroundColor White -NoNewline
try {
npm install -g "$PackageName@latest" 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "npm install failed" }
Write-Host " done" -ForegroundColor Green
} catch {
Write-Host " failed" -ForegroundColor Red
Write-Host " Try manually:" -ForegroundColor DarkGray
Write-Host " npm uninstall -g $LegacyPackageName $PackageName" -ForegroundColor DarkGray
Write-Host " npm install -g $PackageName@latest" -ForegroundColor DarkGray
exit 1
}
# Verify
$Version = $null
try { $Version = (openanalyst --version 2>$null) } catch {}
Write-Host ""
if ($Version) {
Write-Host " $([char]0x2713) $Version" -ForegroundColor Green
} else {
Write-Host " $([char]0x2713) Installed" -ForegroundColor Green
}
Write-Host ""
Write-Host " To get started:" -ForegroundColor White
Write-Host ""
Write-Host " openanalyst" -ForegroundColor Cyan
Write-Host ""