-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.ps1
More file actions
278 lines (242 loc) · 10.4 KB
/
setup.ps1
File metadata and controls
278 lines (242 loc) · 10.4 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
# --- setup.ps1 ---
param(
[switch]$Check,
[switch]$Docker,
[switch]$Local,
[switch]$Help
)
$ErrorActionPreference = "Stop"
$CoreTexMinPython = $env:CORETEX_MIN_PYTHON
if ([string]::IsNullOrEmpty($CoreTexMinPython)) { $CoreTexMinPython = "3.12" }
function Show-Usage {
Write-Host "CoreTex OS Setup Utility"
Write-Host "Usage: .\setup.ps1 [OPTIONS]"
Write-Host ""
Write-Host "Options:"
Write-Host " -Help Show this help message and exit"
Write-Host " -Check Verify dependencies without installing or mutating state"
Write-Host " -Docker Build/use the isolated Docker runtime without prompting"
Write-Host " -Local Use the local uv/Deno runtime without prompting"
Write-Host ""
Write-Host "Examples:"
Write-Host " .\setup.ps1 -Check"
Write-Host " .\setup.ps1 -Docker"
Write-Host " .\setup.ps1 -Local"
}
function Test-DockerComposeAvailable {
if ($null -eq (Get-Command docker -ErrorAction SilentlyContinue)) { return $false }
docker compose version >$null 2>&1
return $LASTEXITCODE -eq 0
}
function Test-CommandAvailable {
param([Parameter(Mandatory = $true)][string]$Name)
return $null -ne (Get-Command $Name -ErrorAction SilentlyContinue)
}
function Test-PythonVersionAvailable {
$PythonCmd = Get-Command python -ErrorAction SilentlyContinue
if ($null -eq $PythonCmd) { $PythonCmd = Get-Command py -ErrorAction SilentlyContinue }
if ($null -eq $PythonCmd) { return $false }
$Script = "import sys; need=tuple(map(int, '$CoreTexMinPython'.split('.'))); raise SystemExit(0 if sys.version_info[:2] >= need else 1)"
if ($PythonCmd.Name -eq "py.exe" -or $PythonCmd.Name -eq "py") {
& py -3 -c $Script >$null 2>&1
} else {
& $PythonCmd.Source -c $Script >$null 2>&1
}
return $LASTEXITCODE -eq 0
}
function Show-NextSteps {
Write-Host ""
Write-Host "Next steps:"
Write-Host " 1. Run: .\ctx.bat status"
Write-Host " 2. Try: .\ctx.bat task \"Summarize this repository in five bullets\""
Write-Host " 3. Re-run diagnostics anytime with: .\setup.ps1 -Check"
}
function Confirm-DefaultYes {
param([Parameter(Mandatory = $true)][string]$Prompt)
if ($env:CORETEX_HEADLESS -eq "1") { return $true }
$Reply = Read-Host "$Prompt (y/n) [y]"
if ([string]::IsNullOrEmpty($Reply)) { $Reply = "y" }
return $Reply -match "^[Yy]$"
}
function Refresh-EnvPath {
$MachinePath = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
$UserPath = [System.Environment]::GetEnvironmentVariable("Path", "User")
$LocalUv = Join-Path $env:USERPROFILE ".local\bin"
$CargoBin = Join-Path $env:USERPROFILE ".cargo\bin"
$DenoBin = Join-Path $env:USERPROFILE ".deno\bin"
$env:Path = "$LocalUv;$CargoBin;$DenoBin;$MachinePath;$UserPath"
}
function Resolve-InstalledUv {
$UvCmd = Get-Command uv -ErrorAction SilentlyContinue
if ($null -ne $UvCmd) { return $UvCmd.Source }
foreach ($Candidate in @(
(Join-Path $env:USERPROFILE ".local\bin\uv.exe"),
(Join-Path $env:USERPROFILE ".cargo\bin\uv.exe")
)) {
if (Test-Path $Candidate) { return $Candidate }
}
return $null
}
function Install-UvRuntime {
$Existing = Resolve-InstalledUv
if ($null -ne $Existing) { return $Existing }
if (-not (Confirm-DefaultYes "The uv package manager is missing. Install it now?")) {
Write-Error -Message "Aborting. uv is required for local installation."
exit 1
}
Write-Host "[*] Downloading uv package manager (this may take a moment)..." -ForegroundColor Cyan
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
irm https://astral.sh/uv/install.ps1 | iex
Refresh-EnvPath
$Installed = Resolve-InstalledUv
if ($null -eq $Installed) {
Write-Error "uv installation failed or could not be found in PATH. Restart your terminal or add .local\bin to PATH."
exit 1
}
return $Installed
}
function Install-DenoRuntime {
if (Test-CommandAvailable "deno") { return }
if (-not (Confirm-DefaultYes "The Deno WASM sandbox runtime is missing. Install it now?")) {
Write-Error -Message "Aborting. deno is required for local installation."
exit 1
}
Write-Host "`n[*] Downloading Deno WASM Sandbox locally (this may take a moment)..." -ForegroundColor Cyan
irm https://deno.land/install.ps1 | iex
Refresh-EnvPath
if (Test-CommandAvailable "deno") { return }
$DefaultDeno = Join-Path $env:USERPROFILE ".deno\bin\deno.exe"
if (-not (Test-Path $DefaultDeno)) {
Write-Error "deno installation failed or could not be found in PATH. Restart your terminal or add .deno\bin to PATH."
exit 1
}
}
function Invoke-DockerCompose {
param([Parameter(ValueFromRemainingArguments = $true)][string[]]$ComposeArgs)
& docker compose @ComposeArgs
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
if ($Help) {
Show-Usage
exit 0
}
if ($Docker -and $Local) {
Write-Error "Choose either -Docker or -Local, not both."
exit 2
}
Clear-Host
Write-Host "====================================================" -ForegroundColor Cyan
Write-Host " ______ ______ ______ ______ ______ ______ _ _ " -ForegroundColor Cyan
Write-Host " / _____ / __ \ / __ \ / ____ /__ __ / ____ / / / / " -ForegroundColor Cyan
Write-Host " / / / / / / / /__/ / / ___ / / / ___ \ / / " -ForegroundColor Cyan
Write-Host " / /____ / /__/ / / __ / /____ / / / /____ / / \ \ " -ForegroundColor Cyan
Write-Host " \______ \______/ /_/ \_ \_____/ /_/ \_____/_/ \_\" -ForegroundColor Cyan
Write-Host "====================================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Biomimetic Agentic OS // Initialization Probe" -ForegroundColor DarkGray
Write-Host ""
# 1. Probe for Air-Gapped AI (Ollama)
$OllamaFound = $false
try {
$OllamaCheck = Invoke-WebRequest -Uri "http://127.0.0.1:11434/api/tags" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
if ($OllamaCheck.StatusCode -eq 200) { $OllamaFound = $true }
} catch { }
if (-not $OllamaFound) {
try {
$OllamaCheck2 = Invoke-WebRequest -Uri "http://localhost:11434/api/tags" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
if ($OllamaCheck2.StatusCode -eq 200) { $OllamaFound = $true }
} catch { }
}
if ($OllamaFound) {
Write-Host "[+] Local Ollama Engine Detected. Air-gapped execution is available." -ForegroundColor Green
} else {
Write-Host "[-] No local Ollama detected. Cloud LLM keys will be required." -ForegroundColor Yellow
}
Write-Host ""
$DockerAvailable = $false
if ($null -ne (Get-Command docker -ErrorAction SilentlyContinue)) {
docker info >$null 2>&1
if ($?) {
$DockerAvailable = $true
}
}
$DockerComposeAvailable = $DockerAvailable -and (Test-DockerComposeAvailable)
if ($Check) {
$CheckFailed = $false
Write-Host "Prerequisite check:"
Write-Host " python_${CoreTexMinPython}_plus: $(Test-PythonVersionAvailable)"
Write-Host " uv: $($null -ne (Get-Command uv -ErrorAction SilentlyContinue))"
Write-Host " deno: $($null -ne (Get-Command deno -ErrorAction SilentlyContinue))"
Write-Host " docker_engine: $DockerAvailable"
Write-Host " docker_compose: $DockerComposeAvailable"
if ($Docker) {
if (-not ($DockerAvailable -and $DockerComposeAvailable)) { $CheckFailed = $true }
} elseif ($Local) {
if ((-not (Test-PythonVersionAvailable)) -or ($null -eq (Get-Command uv -ErrorAction SilentlyContinue)) -or ($null -eq (Get-Command deno -ErrorAction SilentlyContinue))) { $CheckFailed = $true }
} elseif ((-not (Test-PythonVersionAvailable)) -or ($null -eq (Get-Command uv -ErrorAction SilentlyContinue)) -or ($null -eq (Get-Command deno -ErrorAction SilentlyContinue))) {
$CheckFailed = $true
}
if ($CheckFailed) {
Write-Host "Result: missing required prerequisites for the selected setup path."
exit 1
}
Write-Host "Result: ready."
exit 0
}
Write-Host "Select your preferred deployment architecture:" -ForegroundColor White
Write-Host " [1] Pure Local (Requires uv and Python 3.12+)"
if ($DockerAvailable -and $DockerComposeAvailable) {
Write-Host " [2] Isolated Container (Requires Docker - ZERO host dependencies)"
} else {
Write-Host " [2] Isolated Container (UNAVAILABLE - Docker engine not running)" -ForegroundColor Gray
}
$AutoInstall = $false
if ($Docker) {
$DeployChoice = "2"
} elseif ($Local) {
$DeployChoice = "1"
} elseif ($env:CORETEX_HEADLESS -eq "1") {
$AutoInstall = $true
$DeployChoice = "1"
} else {
$DeployChoice = Read-Host "Enter choice [1]"
if ([string]::IsNullOrEmpty($DeployChoice)) { $DeployChoice = "1" }
}
if ($DeployChoice -eq "2") {
if (-not $DockerAvailable) {
Write-Error "Docker is installed but the engine is not reachable. Start Docker and retry, or run .\setup.ps1 -Local."
exit 1
}
if (-not $DockerComposeAvailable) {
Write-Error "Docker Compose is unavailable. Install Docker Desktop with Compose support, then retry."
exit 1
}
Write-Host "`n[*] Building Isolated Docker Sandbox..." -ForegroundColor Cyan
if (-not (Test-Path .env)) { New-Item -Path . -Name ".env" -ItemType "file" > $null }
foreach ($dir in "logs", "System\config", "Meta", "Workspace") {
if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir > $null }
}
Invoke-DockerCompose build
Write-Host "`n[+] Build complete." -ForegroundColor Green
Show-NextSteps
Write-Host "[*] Booting Synaptic Genesis inside container context...`n" -ForegroundColor Cyan
# Force docker fallback execution to prevent missing venv crash
.\ctx.bat --docker setup
exit
}
Write-Host "`n[*] Initializing Pure Local Environment..." -ForegroundColor Cyan
if (-not (Test-PythonVersionAvailable)) {
Write-Error "Python ${CoreTexMinPython}+ is required for local setup. Install Python ${CoreTexMinPython}+ or run .\setup.ps1 -Docker."
exit 1
}
$UvBin = Install-UvRuntime
Install-DenoRuntime
foreach ($dir in "logs", "System\config", "Meta") {
if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force > $null }
}
Write-Host "`n[*] Synchronizing CoreTex dependencies (this may take a moment)..." -ForegroundColor Cyan
& $UvBin sync --all-extras
Write-Host "`n[+] Local environment synchronized." -ForegroundColor Green
Show-NextSteps
Write-Host "[*] Booting Synaptic Genesis...`n" -ForegroundColor Cyan
& $UvBin run python -m System.cli setup