forked from Symbo-gif/Perplexity-Enigma-CLI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
281 lines (240 loc) · 7.78 KB
/
Copy pathsetup.ps1
File metadata and controls
281 lines (240 loc) · 7.78 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
276
277
278
279
280
281
<#
.SYNOPSIS
Setup script for Perplexity - Enigma CLI
.DESCRIPTION
Installs dependencies, builds the project, and configures your system
so you can run 'enigma' from anywhere in PowerShell.
.EXAMPLE
.\setup.ps1
# Run the full setup
.EXAMPLE
.\setup.ps1 -SkipBuild
# Skip the build step (if already built)
#>
[CmdletBinding()]
param(
[switch]$SkipBuild,
[switch]$Uninstall
)
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
function Write-Step {
param([string]$Message)
Write-Host "[*] $Message" -ForegroundColor Cyan
}
function Write-Success {
param([string]$Message)
Write-Host "[+] $Message" -ForegroundColor Green
}
function Write-Err {
param([string]$Message)
Write-Host "[!] $Message" -ForegroundColor Red
}
function Write-Warn {
param([string]$Message)
Write-Host "[!] $Message" -ForegroundColor Yellow
}
function Show-Banner {
Write-Host ""
Write-Host "=================================================================" -ForegroundColor Cyan
Write-Host ""
Write-Host " Perplexity - Enigma Setup" -ForegroundColor Magenta
Write-Host " Enterprise AI-Powered Coding Assistant" -ForegroundColor DarkGray
Write-Host ""
Write-Host "=================================================================" -ForegroundColor Cyan
Write-Host ""
}
function Test-NodeInstalled {
try {
$nodeVersion = & node --version 2>$null
if ($nodeVersion -match "v(\d+)") {
$majorVersion = [int]$Matches[1]
if ($majorVersion -ge 18) {
return $true
}
Write-Err "Node.js 18+ is required. Found: $nodeVersion"
return $false
}
}
catch {
Write-Err "Node.js is not installed or not in PATH"
Write-Host "Please install Node.js 18+ from https://nodejs.org"
return $false
}
return $false
}
function Install-Dependencies {
Write-Step "Installing npm dependencies..."
Push-Location $ScriptDir
try {
$output = & npm install 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host $output
throw "npm install failed"
}
Write-Success "Dependencies installed"
}
finally {
Pop-Location
}
}
function Build-Project {
Write-Step "Building TypeScript project..."
Push-Location $ScriptDir
try {
$output = & npm run build 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host $output
throw "Build failed"
}
Write-Success "Build completed"
}
finally {
Pop-Location
}
}
function Get-ProfilePath {
return $PROFILE.CurrentUserAllHosts
}
function Add-EnigmaToProfile {
$profilePath = Get-ProfilePath
$profileDir = Split-Path -Parent $profilePath
# Ensure profile directory exists
if (-not (Test-Path $profileDir)) {
New-Item -ItemType Directory -Path $profileDir -Force | Out-Null
}
# Create profile if it doesn't exist
if (-not (Test-Path $profilePath)) {
New-Item -ItemType File -Path $profilePath -Force | Out-Null
Write-Step "Created PowerShell profile at $profilePath"
}
$enigmaPath = Join-Path $ScriptDir "bin" "enigma.ps1"
# Check if already added
if (Test-Path $profilePath) {
$profileContent = Get-Content $profilePath -Raw -ErrorAction SilentlyContinue
}
else {
$profileContent = ""
}
if ($profileContent -and ($profileContent -match "function\s+enigma")) {
Write-Warn "Enigma function already exists in your PowerShell profile. Skipping duplicate entry."
return
}
# Add to profile
$functionDef = @"
# Perplexity - Enigma CLI
function enigma {
& "$enigmaPath" @args
}
"@
Add-Content -Path $profilePath -Value $functionDef
Write-Success "Added 'enigma' command to PowerShell profile"
Write-Host " Profile: $profilePath"
}
function Remove-EnigmaFromProfile {
$profilePath = Get-ProfilePath
if (-not (Test-Path $profilePath)) {
Write-Warn "No PowerShell profile found"
return
}
$profileContent = Get-Content $profilePath -Raw
if (-not $profileContent.Contains("Perplexity - Enigma CLI")) {
Write-Warn "Enigma is not in your PowerShell profile"
return
}
# Remove the enigma function block
$pattern = "(?s)\r?\n# Perplexity - Enigma CLI\r?\nfunction enigma \{[^}]+\}\r?\n"
$newContent = $profileContent -replace $pattern, ""
Set-Content -Path $profilePath -Value $newContent
Write-Success "Removed 'enigma' command from PowerShell profile"
}
function Test-ApiKey {
if ($env:PPLX_API_KEY) {
Write-Success "PPLX_API_KEY environment variable is set"
return $true
}
$envPath = Join-Path $ScriptDir ".env"
if (Test-Path $envPath) {
$content = Get-Content $envPath -Raw
if ($content -match "PPLX_API_KEY=pplx-") {
Write-Success "API key found in .env file"
return $true
}
}
$configPath = Join-Path $ScriptDir ".pplxrc"
if (Test-Path $configPath) {
$content = Get-Content $configPath -Raw
if ($content -match "key:\s*[`"']?pplx-") {
Write-Success "API key found in .pplxrc"
return $true
}
}
Write-Warn "No API key configured"
Write-Host ""
Write-Host " To set your API key, run enigma and enter it when prompted,"
Write-Host " or manually create a .env file with:"
Write-Host ' PPLX_API_KEY=pplx-your-key-here' -ForegroundColor Cyan
Write-Host ""
Write-Host " Get your API key at: https://www.perplexity.ai/settings/api"
Write-Host ""
return $false
}
function Main {
Show-Banner
if ($Uninstall) {
Write-Step "Uninstalling Perplexity - Enigma..."
Remove-EnigmaFromProfile
Write-Success "Uninstall complete. Restart PowerShell to apply changes."
return
}
# Check Node.js
Write-Step "Checking prerequisites..."
if (-not (Test-NodeInstalled)) {
exit 1
}
Write-Success "Node.js is installed"
# Install dependencies
if (-not (Test-Path (Join-Path $ScriptDir "node_modules"))) {
Install-Dependencies
}
else {
Write-Success "Dependencies already installed"
}
# Build project
if (-not $SkipBuild) {
if (-not (Test-Path (Join-Path $ScriptDir "dist" "index.js"))) {
Build-Project
}
else {
Write-Success "Project already built"
}
}
# Add to PowerShell profile
Write-Step "Configuring PowerShell..."
Add-EnigmaToProfile
# Check for API key
Write-Step "Checking API key..."
Test-ApiKey | Out-Null
Write-Host ""
Write-Host "=================================================================" -ForegroundColor Green
Write-Host ""
Write-Host "✓ Enigma CLI installed successfully!" -ForegroundColor Green
Write-Host ""
Write-Host "To start using Enigma:"
Write-Host ""
Write-Host " 1. Restart PowerShell (or run: . `$PROFILE)" -ForegroundColor Yellow
Write-Host ""
Write-Host " 2. Run 'enigma' to get started" -ForegroundColor Cyan
Write-Host ""
Write-Host "Quick commands:"
Write-Host " enigma - Interactive mode" -ForegroundColor Cyan
Write-Host ' enigma "question" - Quick question' -ForegroundColor Cyan
Write-Host ' enigma ask "question" - Ask a question' -ForegroundColor Cyan
Write-Host " enigma config - View configuration" -ForegroundColor Cyan
Write-Host " enigma --help - Show all commands" -ForegroundColor Cyan
Write-Host ""
Write-Host "=================================================================" -ForegroundColor Green
Write-Host ""
}
# Run main
Main