-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Expand file tree
/
Copy pathquickstart.ps1
More file actions
1660 lines (1472 loc) · 62.2 KB
/
quickstart.ps1
File metadata and controls
1660 lines (1472 loc) · 62.2 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Requires -Version 5.1
<#
.SYNOPSIS
quickstart.ps1 - Interactive onboarding for Aden Agent Framework (Windows)
.DESCRIPTION
An interactive setup wizard that:
1. Installs Python dependencies via uv
2. Installs Playwright browser for web scraping
3. Helps configure LLM API keys
4. Verifies everything works
.NOTES
Run from the project root: .\quickstart.ps1
Requires: PowerShell 5.1+ and Python 3.11+
#>
# Use "Continue" so stderr from external tools (uv, python) does not
# terminate the script. Errors are handled via $LASTEXITCODE checks.
$ErrorActionPreference = "Continue"
# ============================================================
# Colors / helpers
# ============================================================
function Write-Color {
param(
[string]$Text,
[ConsoleColor]$Color = [ConsoleColor]::White,
[switch]$NoNewline
)
$prev = $Host.UI.RawUI.ForegroundColor
$Host.UI.RawUI.ForegroundColor = $Color
if ($NoNewline) { Write-Host $Text -NoNewline }
else { Write-Host $Text }
$Host.UI.RawUI.ForegroundColor = $prev
}
function Write-Step {
param([string]$Number, [string]$Text)
Write-Color -Text ([char]0x2B22) -Color Yellow -NoNewline
Write-Host " " -NoNewline
Write-Color -Text "$Text" -Color Cyan
Write-Host ""
}
function Write-Ok {
param([string]$Text)
Write-Color -Text " $([char]0x2713) $Text" -Color Green
}
function Write-Warn {
param([string]$Text)
Write-Color -Text " ! $Text" -Color Yellow
}
function Write-Fail {
param([string]$Text)
Write-Color -Text " X $Text" -Color Red
}
function Prompt-YesNo {
param(
[string]$Prompt,
[string]$Default = "y"
)
if ($Default -eq "y") { $hint = "[Y/n]" } else { $hint = "[y/N]" }
$response = Read-Host "$Prompt $hint"
if ([string]::IsNullOrWhiteSpace($response)) { $response = $Default }
return $response -match "^[Yy]"
}
function Prompt-Choice {
param(
[string]$Prompt,
[string[]]$Options
)
Write-Host ""
Write-Color -Text $Prompt -Color White
Write-Host ""
for ($i = 0; $i -lt $Options.Count; $i++) {
Write-Color -Text " $($i + 1)" -Color Cyan -NoNewline
Write-Host ") $($Options[$i])"
}
Write-Host ""
while ($true) {
$choice = Read-Host "Enter choice (1-$($Options.Count))"
if ($choice -match '^\d+$') {
$num = [int]$choice
if ($num -ge 1 -and $num -le $Options.Count) {
return $num - 1
}
}
Write-Color -Text "Invalid choice. Please enter 1-$($Options.Count)" -Color Red
}
}
# ============================================================
# Windows Defender Exclusion Functions
# ============================================================
function Test-IsAdmin {
<#
.SYNOPSIS
Check if current PowerShell session has admin privileges
#>
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal]$identity
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Test-DefenderExclusions {
<#
.SYNOPSIS
Check if Windows Defender is enabled and which paths need exclusions
.PARAMETER Paths
Array of paths to check
.OUTPUTS
Hashtable with DefenderEnabled, MissingPaths, and optional Error
#>
param([string[]]$Paths)
# Security: Define safe path prefixes (project + user directories only)
$safePrefixes = @(
$ScriptDir, # Project directory
$env:LOCALAPPDATA, # User local appdata
$env:APPDATA # User roaming appdata
)
# Normalize and filter null/empty values
$safePrefixes = $safePrefixes | Where-Object { $_ } | ForEach-Object {
try { [System.IO.Path]::GetFullPath($_) } catch { $null }
} | Where-Object { $_ }
try {
# Check if Defender cmdlets are available (may not exist on older Windows)
$mpModule = Get-Module -ListAvailable -Name Defender -ErrorAction SilentlyContinue
if (-not $mpModule) {
return @{
DefenderEnabled = $false
Error = "Windows Defender module not available"
}
}
# Check if Defender is running
$status = Get-MpComputerStatus -ErrorAction Stop
if (-not $status.RealTimeProtectionEnabled) {
return @{
DefenderEnabled = $false
Reason = "Real-time protection is disabled"
}
}
# Get current exclusions
$prefs = Get-MpPreference -ErrorAction Stop
$existing = $prefs.ExclusionPath
if (-not $existing) { $existing = @() }
# Normalize existing paths for comparison (some may contain wildcards
# or env vars that GetFullPath rejects — skip those gracefully)
$existing = $existing | Where-Object { $_ } | ForEach-Object {
try { [System.IO.Path]::GetFullPath($_) } catch { $_ }
}
# Normalize paths and find missing exclusions
$missing = @()
foreach ($path in $Paths) {
try {
$normalized = [System.IO.Path]::GetFullPath($path)
} catch {
continue # Skip paths with unsupported format
}
# Security: Ensure path is within safe boundaries
$isSafe = $false
foreach ($prefix in $safePrefixes) {
if ($normalized -like "$prefix*") {
$isSafe = $true
break
}
}
if (-not $isSafe) {
Write-Warn "Security: Refusing to exclude path outside safe boundaries: $normalized"
continue
}
# Info: Warn if path doesn't exist yet (but still process it)
if (-not (Test-Path $path -ErrorAction SilentlyContinue)) {
Write-Verbose "Path does not exist yet: $path (will be excluded when created)"
}
# Check if path is already excluded (or is a child of an excluded path)
$alreadyExcluded = $false
foreach ($excluded in $existing) {
if ($normalized -like "$excluded*") {
$alreadyExcluded = $true
break
}
}
if (-not $alreadyExcluded) {
$missing += $normalized
}
}
return @{
DefenderEnabled = $true
MissingPaths = $missing
ExistingPaths = $existing
}
} catch {
return @{
DefenderEnabled = $false
Error = $_.Exception.Message
}
}
}
function Test-IsDefenderEnabled {
<#
.SYNOPSIS
Quick boolean check if Defender real-time protection is enabled
.OUTPUTS
Boolean - $true if enabled, $false otherwise
#>
try {
$mpModule = Get-Module -ListAvailable -Name Defender -ErrorAction SilentlyContinue
if (-not $mpModule) {
return $false
}
$status = Get-MpComputerStatus -ErrorAction Stop
return $status.RealTimeProtectionEnabled
} catch {
# If we can't check, assume disabled (fail-safe)
return $false
}
}
function Add-DefenderExclusions {
<#
.SYNOPSIS
Add Windows Defender exclusions for specified paths
.PARAMETER Paths
Array of paths to exclude
.OUTPUTS
Hashtable with Added and Failed arrays
#>
param([string[]]$Paths)
$added = @()
$failed = @()
foreach ($path in $Paths) {
try {
try {
$normalized = [System.IO.Path]::GetFullPath($path)
} catch {
$normalized = $path # Use raw path if normalization fails
}
Add-MpPreference -ExclusionPath $normalized -ErrorAction Stop
$added += $normalized
} catch {
$failed += @{
Path = $path
Error = $_.Exception.Message
}
}
}
return @{
Added = $added
Failed = $failed
}
}
# Get the directory where this script lives
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
# ============================================================
# Banner
# ============================================================
Clear-Host
Write-Host ""
$hex = [char]0x2B22 # filled hexagon
$hexDim = [char]0x2B21 # outline hexagon
$banner = ""
for ($i = 0; $i -lt 13; $i++) {
if ($i % 2 -eq 0) { $banner += $hex } else { $banner += $hexDim }
}
Write-Color -Text $banner -Color Yellow
Write-Host ""
Write-Color -Text " A D E N H I V E" -Color White
Write-Host ""
Write-Color -Text $banner -Color Yellow
Write-Host ""
Write-Color -Text " Goal-driven AI agent framework" -Color DarkGray
Write-Host ""
Write-Host "This wizard will help you set up everything you need"
Write-Host "to build and run goal-driven AI agents."
Write-Host ""
if (-not (Prompt-YesNo "Ready to begin?")) {
Write-Host ""
Write-Host "No problem! Run this script again when you're ready."
exit 0
}
Write-Host ""
# ============================================================
# Step 1: Check Python
# ============================================================
Write-Step -Number "1" -Text "Step 1: Checking Python..."
# On Windows "python3.x" aliases don't exist; prefer "python" then "python3"
$PythonCmd = $null
foreach ($candidate in @("python", "python3", "python3.13", "python3.12", "python3.11")) {
try {
$ver = & $candidate -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>$null
if ($LASTEXITCODE -eq 0 -and $ver) {
$parts = $ver.Split(".")
$major = [int]$parts[0]
$minor = [int]$parts[1]
if ($major -eq 3 -and $minor -ge 11) {
$PythonCmd = $candidate
break
}
}
} catch {
# candidate not found, continue
}
}
if (-not $PythonCmd) {
Write-Color -Text "Python 3.11+ is not installed or not on PATH." -Color Red
Write-Host ""
Write-Host "Please install Python 3.11+ from https://python.org"
Write-Host " - Make sure to check 'Add Python to PATH' during installation"
Write-Host "Then run this script again."
exit 1
}
$PythonVersion = & $PythonCmd -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"
Write-Ok "Python $PythonVersion ($PythonCmd)"
Write-Host ""
# ============================================================
# Check / install uv
# ============================================================
$uvCmd = Get-Command uv -ErrorAction SilentlyContinue
# If uv not in PATH, check if it exists in default location
if (-not $uvCmd) {
$uvDir = Join-Path $env:USERPROFILE ".local\bin"
$uvExePath = Join-Path $uvDir "uv.exe"
if (Test-Path $uvExePath) {
Write-Host " uv found at $uvExePath, updating PATH..." -ForegroundColor Yellow
# Add to User PATH
$currentUserPath = [System.Environment]::GetEnvironmentVariable("Path", "User")
if (-not $currentUserPath.Contains($uvDir)) {
$newUserPath = $currentUserPath + ";" + $uvDir
[System.Environment]::SetEnvironmentVariable("Path", $newUserPath, "User")
}
# Refresh PATH for current session
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "Machine")
$uvCmd = Get-Command uv -ErrorAction SilentlyContinue
if ($uvCmd) {
Write-Ok "uv is now in PATH"
}
}
}
# If still not found, install it
if (-not $uvCmd) {
Write-Warn "uv not found. Installing..."
try {
# Official uv installer for Windows
Invoke-RestMethod https://astral.sh/uv/install.ps1 | Invoke-Expression
# Ensure uv directory is in User PATH for future sessions
$uvDir = Join-Path $env:USERPROFILE ".local\bin"
$currentUserPath = [System.Environment]::GetEnvironmentVariable("Path", "User")
if (-not $currentUserPath.Contains($uvDir)) {
$newUserPath = $currentUserPath + ";" + $uvDir
[System.Environment]::SetEnvironmentVariable("Path", $newUserPath, "User")
Write-Host " Added $uvDir to User PATH" -ForegroundColor Green
}
# Refresh PATH for current session
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "Machine")
$uvCmd = Get-Command uv -ErrorAction SilentlyContinue
} catch {
Write-Color -Text "Error: uv installation failed" -Color Red
Write-Host "Please install uv manually from https://astral.sh/uv/"
exit 1
}
if (-not $uvCmd) {
Write-Color -Text "Error: uv not found after installation" -Color Red
Write-Host "Please close and reopen PowerShell, then run this script again."
Write-Host "Or install uv manually from https://astral.sh/uv/"
exit 1
}
Write-Ok "uv installed successfully"
}
$uvVersion = & uv --version
Write-Ok "uv detected: $uvVersion"
Write-Host ""
# Check for Node.js (needed for frontend dashboard)
function Install-NodeViaFnm {
<#
.SYNOPSIS
Install Node.js 20 via fnm (Fast Node Manager) - mirrors nvm approach in quickstart.sh
#>
$fnmCmd = Get-Command fnm -ErrorAction SilentlyContinue
if (-not $fnmCmd) {
$fnmDir = Join-Path $env:LOCALAPPDATA "fnm"
$fnmExe = Join-Path $fnmDir "fnm.exe"
if (-not (Test-Path $fnmExe)) {
try {
Write-Host " Downloading fnm (Fast Node Manager)..." -ForegroundColor DarkGray
$zipUrl = "https://github.com/Schniz/fnm/releases/latest/download/fnm-windows.zip"
$zipPath = Join-Path $env:TEMP "fnm-install.zip"
Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath -UseBasicParsing -ErrorAction Stop
if (-not (Test-Path $fnmDir)) { New-Item -ItemType Directory -Path $fnmDir -Force | Out-Null }
Expand-Archive -Path $zipPath -DestinationPath $fnmDir -Force
Remove-Item $zipPath -Force -ErrorAction SilentlyContinue
} catch {
Write-Fail "fnm download failed"
Write-Host " Install Node.js 20+ manually from https://nodejs.org" -ForegroundColor DarkGray
return $false
}
}
if (Test-Path (Join-Path $fnmDir "fnm.exe")) {
$env:PATH = "$fnmDir;$env:PATH"
} else {
Write-Fail "fnm binary not found after download"
Write-Host " Install Node.js 20+ manually from https://nodejs.org" -ForegroundColor DarkGray
return $false
}
}
try {
$null = & fnm install 20 2>&1
if ($LASTEXITCODE -ne 0) { throw "fnm install 20 exited with code $LASTEXITCODE" }
& fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression
$null = & fnm use 20 2>&1
$testNode = Get-Command node -ErrorAction SilentlyContinue
if ($testNode) {
$ver = & node --version 2>$null
Write-Ok "Node.js $ver installed via fnm"
return $true
}
throw "node not found after fnm install"
} catch {
Write-Fail "Node.js installation failed"
Write-Host " Install manually from https://nodejs.org" -ForegroundColor DarkGray
return $false
}
}
$NodeAvailable = $false
$nodeCmd = Get-Command node -ErrorAction SilentlyContinue
if ($nodeCmd) {
$nodeVersion = & node --version 2>$null
if ($nodeVersion -match '^v(\d+)') {
$nodeMajor = [int]$Matches[1]
if ($nodeMajor -ge 20) {
Write-Ok "Node.js $nodeVersion"
$NodeAvailable = $true
} else {
Write-Warn "Node.js $nodeVersion found (20+ required for frontend dashboard)"
Write-Host " Installing Node.js 20 via fnm..." -ForegroundColor Yellow
$NodeAvailable = Install-NodeViaFnm
}
}
} else {
Write-Warn "Node.js not found. Installing via fnm..."
$NodeAvailable = Install-NodeViaFnm
}
Write-Host ""
# ============================================================
# Step 2: Install Python Packages
# ============================================================
Write-Step -Number "2" -Text "Step 2: Installing packages..."
Write-Color -Text "This may take a minute..." -Color DarkGray
Write-Host ""
Push-Location $ScriptDir
try {
if (Test-Path "pyproject.toml") {
Write-Host " Installing workspace packages... " -NoNewline
$syncOutput = & uv sync 2>&1
$syncExitCode = $LASTEXITCODE
if ($syncExitCode -eq 0) {
Write-Ok "workspace packages installed"
} else {
Write-Fail "workspace installation failed"
Write-Host $syncOutput
exit 1
}
} else {
Write-Fail "failed (no root pyproject.toml)"
exit 1
}
# Install Playwright browser
Write-Host " Installing Playwright browser... " -NoNewline
$null = & uv run python -c "import playwright" 2>&1
$importExitCode = $LASTEXITCODE
if ($importExitCode -eq 0) {
$null = & uv run python -m playwright install chromium 2>&1
$playwrightExitCode = $LASTEXITCODE
if ($playwrightExitCode -eq 0) {
Write-Ok "ok"
} else {
Write-Warn "skipped (install manually: uv run python -m playwright install chromium)"
}
} else {
Write-Warn "skipped"
}
} finally {
Pop-Location
}
Write-Host ""
Write-Ok "All packages installed"
Write-Host ""
# Build frontend (if Node.js is available)
$FrontendBuilt = $false
if ($NodeAvailable) {
Write-Step -Number "" -Text "Building frontend dashboard..."
Write-Host ""
$frontendDir = Join-Path $ScriptDir "core\frontend"
if (Test-Path (Join-Path $frontendDir "package.json")) {
Write-Host " Installing npm packages... " -NoNewline
Push-Location $frontendDir
try {
$null = & npm install --no-fund --no-audit 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Ok "ok"
# Clean stale tsbuildinfo cache — tsc -b incremental builds fail
# silently when these are out of sync with source files
Get-ChildItem -Path $frontendDir -Filter "tsconfig*.tsbuildinfo" -ErrorAction SilentlyContinue | Remove-Item -Force
Write-Host " Building frontend... " -NoNewline
$null = & npm run build 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Ok "ok"
Write-Ok "Frontend built -> core/frontend/dist/"
$FrontendBuilt = $true
} else {
Write-Warn "build failed"
Write-Host " Run 'cd core\frontend && npm run build' manually to debug." -ForegroundColor DarkGray
}
} else {
Write-Warn "npm install failed"
$NodeAvailable = $false
}
} finally {
Pop-Location
}
}
Write-Host ""
}
# ============================================================
# Step 2.5: Windows Defender Exclusions (Optional Performance Boost)
# ============================================================
Write-Step -Number "2.5" -Text "Step 2.5: Windows Defender exclusions (optional)"
Write-Color -Text "Excluding project paths from real-time scanning can improve performance:" -Color DarkGray
Write-Host " - uv sync: ~40% faster"
Write-Host " - Agent startup: ~30% faster"
Write-Host ""
# Define paths to exclude
$pathsToExclude = @(
$ScriptDir, # Project directory
(Join-Path $ScriptDir ".venv"), # Virtual environment
(Join-Path $env:LOCALAPPDATA "uv") # uv cache
)
# Check current state
$checkResult = Test-DefenderExclusions -Paths $pathsToExclude
if (-not $checkResult.DefenderEnabled) {
if ($checkResult.Error) {
Write-Warn "Cannot check Defender status: $($checkResult.Error)"
} elseif ($checkResult.Reason) {
Write-Warn "Skipping: $($checkResult.Reason)"
}
Write-Host ""
# Continue installation without failing
} elseif ($checkResult.MissingPaths.Count -eq 0) {
Write-Ok "All paths already excluded from Defender scanning"
Write-Host ""
} else {
# Show what will be excluded
Write-Host "Paths to exclude:"
foreach ($path in $checkResult.MissingPaths) {
Write-Color -Text " - $path" -Color Cyan
}
Write-Host ""
# Security notice
Write-Color -Text "⚠️ Security Trade-off:" -Color Yellow
Write-Host "Adding exclusions improves performance but reduces real-time protection."
Write-Host "Only proceed if you trust this project and its dependencies."
Write-Host ""
# Prompt for consent (default = No for security)
if (Prompt-YesNo "Add these Defender exclusions?" "n") {
Write-Host ""
# Check admin privileges
if (-not (Test-IsAdmin)) {
Write-Warn "Administrator privileges required to modify Defender settings."
Write-Host ""
Write-Color -Text "To add exclusions manually, run PowerShell as Administrator and paste:" -Color White
Write-Host ""
foreach ($path in $checkResult.MissingPaths) {
$cmd = "Add-MpPreference -ExclusionPath '$path'"
Write-Color -Text " $cmd" -Color Cyan
}
Write-Host ""
Write-Color -Text "Or copy all commands to clipboard? [y/N]" -Color White
$copyChoice = Read-Host
if ($copyChoice -match "^[Yy]") {
$commands = ($checkResult.MissingPaths | ForEach-Object {
"Add-MpPreference -ExclusionPath '$_'"
}) -join "`r`n"
try {
Set-Clipboard -Value $commands
Write-Ok "Commands copied to clipboard"
} catch {
Write-Warn "Could not copy to clipboard. Please copy manually."
}
}
} else {
# Re-check Defender status before adding (could have changed during prompt)
if (-not (Test-IsDefenderEnabled)) {
Write-Warn "Defender status changed during setup (now disabled)."
Write-Host "Skipping exclusions - they would have no effect."
Write-Host ""
} else {
# Add exclusions
Write-Host " Adding exclusions... " -NoNewline
# Re-check paths in case something changed
$freshCheck = Test-DefenderExclusions -Paths $pathsToExclude
if ($freshCheck.MissingPaths.Count -eq 0) {
Write-Ok "already added"
Write-Host " (Exclusions were added by another process)"
} else {
$result = Add-DefenderExclusions -Paths $freshCheck.MissingPaths
if ($result.Added.Count -gt 0) {
Write-Ok "done"
foreach ($path in $result.Added) {
Write-Ok "Excluded: $path"
}
}
if ($result.Failed.Count -gt 0) {
Write-Host ""
# Calculate and show success rate
$totalPaths = $result.Added.Count + $result.Failed.Count
if ($totalPaths -gt 0) {
$successRate = [math]::Round(($result.Added.Count / $totalPaths) * 100)
Write-Warn "Only $($result.Added.Count)/$totalPaths exclusions added ($successRate%)"
Write-Host "Performance benefit may be reduced."
Write-Host ""
}
Write-Warn "Failed exclusions:"
foreach ($failure in $result.Failed) {
Write-Warn " $($failure.Path): $($failure.Error)"
}
}
}
}
}
} else {
Write-Host ""
Write-Warn "Skipped. You can add exclusions later for better performance."
Write-Host " Run this script again or add them manually via Windows Security."
}
Write-Host ""
}
# ============================================================
# Step 3: Verify Python Imports
# ============================================================
Write-Step -Number "3" -Text "Step 3: Verifying Python imports..."
$importErrors = 0
$imports = @(
@{ Module = "framework"; Label = "framework"; Required = $true },
@{ Module = "aden_tools"; Label = "aden_tools"; Required = $true },
@{ Module = "litellm"; Label = "litellm"; Required = $false }
)
# Batch check all imports in single process (reduces subprocess spawning overhead)
$modulesToCheck = @("framework", "aden_tools", "litellm")
try {
$checkOutput = & uv run python scripts/check_requirements.py @modulesToCheck 2>&1 | Out-String
$resultJson = $null
# Try to parse JSON result
try {
$resultJson = $checkOutput | ConvertFrom-Json
} catch {
Write-Fail "Failed to parse import check results"
Write-Host $checkOutput
exit 1
}
# Display results for each module
foreach ($imp in $imports) {
Write-Host " $($imp.Label)... " -NoNewline
$status = $resultJson.$($imp.Module)
if ($status -eq "ok") {
Write-Ok "ok"
} elseif ($imp.Required) {
Write-Fail "failed"
if ($status) {
Write-Host " $status" -ForegroundColor Red
}
$importErrors++
} else {
Write-Warn "issues (may be OK)"
if ($status -and $status -ne "ok") {
Write-Host " $status" -ForegroundColor Yellow
}
}
}
} catch {
Write-Fail "Import check failed: $($_.Exception.Message)"
exit 1
}
if ($importErrors -gt 0) {
Write-Host ""
Write-Color -Text "Error: $importErrors import(s) failed. Please check the errors above." -Color Red
exit 1
}
Write-Host ""
# ============================================================
# Step 4: Verify Claude Code Skills
# ============================================================
Write-Step -Number "4" -Text "Step 4: Verifying Claude Code skills..."
# (skills check is informational only, shown in final verification)
# ============================================================
# Provider / model data
# ============================================================
$ProviderMap = [ordered]@{
ANTHROPIC_API_KEY = @{ Name = "Anthropic (Claude)"; Id = "anthropic" }
OPENAI_API_KEY = @{ Name = "OpenAI (GPT)"; Id = "openai" }
GEMINI_API_KEY = @{ Name = "Google Gemini"; Id = "gemini" }
GOOGLE_API_KEY = @{ Name = "Google AI"; Id = "google" }
GROQ_API_KEY = @{ Name = "Groq"; Id = "groq" }
CEREBRAS_API_KEY = @{ Name = "Cerebras"; Id = "cerebras" }
MISTRAL_API_KEY = @{ Name = "Mistral"; Id = "mistral" }
TOGETHER_API_KEY = @{ Name = "Together AI"; Id = "together" }
DEEPSEEK_API_KEY = @{ Name = "DeepSeek"; Id = "deepseek" }
}
$DefaultModels = @{
anthropic = "claude-haiku-4-5-20251001"
openai = "gpt-5-mini"
gemini = "gemini-3-flash-preview"
groq = "moonshotai/kimi-k2-instruct-0905"
cerebras = "zai-glm-4.7"
mistral = "mistral-large-latest"
together_ai = "meta-llama/Llama-3.3-70B-Instruct-Turbo"
deepseek = "deepseek-chat"
}
# Model choices: array of hashtables per provider
$ModelChoices = @{
anthropic = @(
@{ Id = "claude-haiku-4-5-20251001"; Label = "Haiku 4.5 - Fast + cheap (recommended)"; MaxTokens = 8192 },
@{ Id = "claude-sonnet-4-20250514"; Label = "Sonnet 4 - Fast + capable"; MaxTokens = 8192 },
@{ Id = "claude-sonnet-4-5-20250929"; Label = "Sonnet 4.5 - Best balance"; MaxTokens = 16384 },
@{ Id = "claude-opus-4-6"; Label = "Opus 4.6 - Most capable"; MaxTokens = 32768 }
)
openai = @(
@{ Id = "gpt-5-mini"; Label = "GPT-5 Mini - Fast + cheap (recommended)"; MaxTokens = 16384 },
@{ Id = "gpt-5.2"; Label = "GPT-5.2 - Most capable"; MaxTokens = 16384 }
)
gemini = @(
@{ Id = "gemini-3-flash-preview"; Label = "Gemini 3 Flash - Fast (recommended)"; MaxTokens = 8192 },
@{ Id = "gemini-3.1-pro-preview"; Label = "Gemini 3.1 Pro - Best quality"; MaxTokens = 8192 }
)
groq = @(
@{ Id = "moonshotai/kimi-k2-instruct-0905"; Label = "Kimi K2 - Best quality (recommended)"; MaxTokens = 8192 },
@{ Id = "openai/gpt-oss-120b"; Label = "GPT-OSS 120B - Fast reasoning"; MaxTokens = 8192 }
)
cerebras = @(
@{ Id = "zai-glm-4.7"; Label = "ZAI-GLM 4.7 - Best quality (recommended)"; MaxTokens = 8192 },
@{ Id = "qwen3-235b-a22b-instruct-2507"; Label = "Qwen3 235B - Frontier reasoning"; MaxTokens = 8192 }
)
}
function Get-ModelSelection {
param([string]$ProviderId)
$choices = $ModelChoices[$ProviderId]
if (-not $choices -or $choices.Count -eq 0) {
return @{ Model = $DefaultModels[$ProviderId]; MaxTokens = 8192 }
}
if ($choices.Count -eq 1) {
return @{ Model = $choices[0].Id; MaxTokens = $choices[0].MaxTokens }
}
# Find default index from previous model (if same provider)
$defaultIdx = "1"
if ($PrevModel -and $PrevProvider -eq $ProviderId) {
for ($j = 0; $j -lt $choices.Count; $j++) {
if ($choices[$j].Id -eq $PrevModel) {
$defaultIdx = [string]($j + 1)
break
}
}
}
Write-Host ""
Write-Color -Text "Select a model:" -Color White
Write-Host ""
for ($i = 0; $i -lt $choices.Count; $i++) {
Write-Color -Text " $($i + 1)" -Color Cyan -NoNewline
Write-Host ") $($choices[$i].Label) " -NoNewline
Write-Color -Text "($($choices[$i].Id))" -Color DarkGray
}
Write-Host ""
while ($true) {
$raw = Read-Host "Enter choice [$defaultIdx]"
if ([string]::IsNullOrWhiteSpace($raw)) { $raw = $defaultIdx }
if ($raw -match '^\d+$') {
$num = [int]$raw
if ($num -ge 1 -and $num -le $choices.Count) {
$sel = $choices[$num - 1]
Write-Host ""
Write-Ok "Model: $($sel.Id)"
return @{ Model = $sel.Id; MaxTokens = $sel.MaxTokens }
}
}
Write-Color -Text "Invalid choice. Please enter 1-$($choices.Count)" -Color Red
}
}
# ============================================================
# Configure LLM API Key
# ============================================================
Write-Step -Number "" -Text "Configuring LLM provider..."
# Hive config paths
$HiveConfigDir = Join-Path $env:USERPROFILE ".hive"
$HiveConfigFile = Join-Path $HiveConfigDir "configuration.json"
$SelectedProviderId = ""
$SelectedEnvVar = ""
$SelectedModel = ""
$SelectedMaxTokens = 8192
$SubscriptionMode = ""
# ── Credential detection (silent — just set flags) ───────────
$ClaudeCredDetected = $false
$claudeCredPath = Join-Path $env:USERPROFILE ".claude\.credentials.json"
if (Test-Path $claudeCredPath) { $ClaudeCredDetected = $true }
$CodexCredDetected = $false
$codexAuthPath = Join-Path $env:USERPROFILE ".codex\auth.json"
if (Test-Path $codexAuthPath) { $CodexCredDetected = $true }
$ZaiCredDetected = $false
$zaiKey = [System.Environment]::GetEnvironmentVariable("ZAI_API_KEY", "User")
if (-not $zaiKey) { $zaiKey = $env:ZAI_API_KEY }
if ($zaiKey) { $ZaiCredDetected = $true }
# Detect API key providers
$ProviderMenuEnvVars = @("ANTHROPIC_API_KEY", "OPENAI_API_KEY", "GEMINI_API_KEY", "GROQ_API_KEY", "CEREBRAS_API_KEY")
$ProviderMenuNames = @("Anthropic (Claude) - Recommended", "OpenAI (GPT)", "Google Gemini - Free tier available", "Groq - Fast, free tier", "Cerebras - Fast, free tier")
$ProviderMenuIds = @("anthropic", "openai", "gemini", "groq", "cerebras")
$ProviderMenuUrls = @(
"https://console.anthropic.com/settings/keys",
"https://platform.openai.com/api-keys",
"https://aistudio.google.com/apikey",
"https://console.groq.com/keys",
"https://cloud.cerebras.ai/"
)
# ── Read previous configuration (if any) ──────────────────────
$PrevProvider = ""
$PrevModel = ""
$PrevEnvVar = ""
$PrevSubMode = ""
if (Test-Path $HiveConfigFile) {
try {
$prevConfig = Get-Content -Path $HiveConfigFile -Raw | ConvertFrom-Json
$prevLlm = $prevConfig.llm
if ($prevLlm) {
$PrevProvider = if ($prevLlm.provider) { $prevLlm.provider } else { "" }
$PrevModel = if ($prevLlm.model) { $prevLlm.model } else { "" }
$PrevEnvVar = if ($prevLlm.api_key_env_var) { $prevLlm.api_key_env_var } else { "" }
if ($prevLlm.use_claude_code_subscription) { $PrevSubMode = "claude_code" }
elseif ($prevLlm.use_codex_subscription) { $PrevSubMode = "codex" }
elseif ($prevLlm.api_base -and $prevLlm.api_base -like "*api.z.ai*") { $PrevSubMode = "zai_code" }
}
} catch { }
}
# Compute default menu number (only if credential is still valid)
$DefaultChoice = ""
if ($PrevSubMode -or $PrevProvider) {
$prevCredValid = $false
switch ($PrevSubMode) {
"claude_code" { if ($ClaudeCredDetected) { $prevCredValid = $true } }
"zai_code" { if ($ZaiCredDetected) { $prevCredValid = $true } }
"codex" { if ($CodexCredDetected) { $prevCredValid = $true } }
default {
if ($PrevEnvVar) {
$envVal = [System.Environment]::GetEnvironmentVariable($PrevEnvVar, "Process")
if (-not $envVal) { $envVal = [System.Environment]::GetEnvironmentVariable($PrevEnvVar, "User") }
if ($envVal) { $prevCredValid = $true }
}
}
}
if ($prevCredValid) {
switch ($PrevSubMode) {
"claude_code" { $DefaultChoice = "1" }
"zai_code" { $DefaultChoice = "2" }
"codex" { $DefaultChoice = "3" }
}
if (-not $DefaultChoice) {
switch ($PrevProvider) {
"anthropic" { $DefaultChoice = "4" }
"openai" { $DefaultChoice = "5" }
"gemini" { $DefaultChoice = "6" }
"groq" { $DefaultChoice = "7" }
"cerebras" { $DefaultChoice = "8" }
}
}
}
}
# ── Show unified provider selection menu ─────────────────────
Write-Color -Text "Select your default LLM provider:" -Color White
Write-Host ""
Write-Color -Text " Subscription modes (no API key purchase needed):" -Color Cyan
# 1) Claude Code
Write-Host " " -NoNewline
Write-Color -Text "1" -Color Cyan -NoNewline
Write-Host ") Claude Code Subscription " -NoNewline
Write-Color -Text "(use your Claude Max/Pro plan)" -Color DarkGray -NoNewline
if ($ClaudeCredDetected) { Write-Color -Text " (credential detected)" -Color Green } else { Write-Host "" }
# 2) ZAI Code
Write-Host " " -NoNewline
Write-Color -Text "2" -Color Cyan -NoNewline
Write-Host ") ZAI Code Subscription " -NoNewline
Write-Color -Text "(use your ZAI Code plan)" -Color DarkGray -NoNewline
if ($ZaiCredDetected) { Write-Color -Text " (credential detected)" -Color Green } else { Write-Host "" }
# 3) Codex
Write-Host " " -NoNewline