jackailocal / windows /Start-JackAILocal.ps1
jackboy70's picture
Claude Opus 4.8 (1M context)
Deploy: clean professional lite builder (no false integrity failure)
dbc891c
Raw History Blame Contribute Delete
7.23 kB
[CmdletBinding()]
param(
[switch]$NoBrowser,
[switch]$AppMode
)
$ErrorActionPreference = "Stop"
$Root = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$DiagDir = Join-Path $Root "diagnostics"
$LogDir = Join-Path $Root ".jackailocal\logs"
$CacheDir = Join-Path $Root ".jackailocal\cache"
$RunDir = Join-Path $Root ".jackailocal\run"
New-Item -ItemType Directory -Force -Path $DiagDir,$LogDir,$CacheDir,$RunDir | Out-Null
# Lite / inspection bundle exported from the hosted Hugging Face Space: it ships
# the builder scripts, WebUI, config and the AI-reviewed manifest, but NOT the
# native runtime binaries (Ollama, whisper.cpp, Piper) or the models, which a
# hosted Space cannot ship. Detect it and exit cleanly with guidance instead of
# failing the integrity check meant for the full package.
$buildManifest = Join-Path $Root "manifest\build-manifest.json"
$isLite = $false
if (Test-Path $buildManifest) {
try {
$bm = Get-Content -Raw $buildManifest | ConvertFrom-Json
if ($bm.hosted_lite_build -eq $true) { $isLite = $true }
} catch {}
}
if (-not (Test-Path (Join-Path $Root "bin\jackailocald.exe"))) { $isLite = $true }
if ($isLite) {
Write-Host ""
Write-Host "JackAILocal - lite inspection bundle" -ForegroundColor Cyan
Write-Host "-----------------------------------------------------------------"
Write-Host "This package was exported from the hosted Hugging Face Space."
Write-Host "It contains the builder scripts, WebUI, configuration and the"
Write-Host "AI-reviewed build manifest - but NOT the native runtime binaries"
Write-Host "(Ollama, whisper.cpp, Piper) or the models, which a hosted Space"
Write-Host "cannot ship. This bundle is for inspecting the build plan."
Write-Host ""
Write-Host "To actually run JackAILocal:"
Write-Host " 1. Get the full package (with binaries) from the project repo."
Write-Host " 2. From that full package, run BUILD-LOCAL.cmd or BUILD-USB.cmd."
Write-Host ""
Write-Host "See README-FIRST.txt and manifest\build-manifest.json for details."
Write-Host "-----------------------------------------------------------------"
exit 0
}
& (Join-Path $PSScriptRoot "hwscan-windows.ps1") -OutputPath (Join-Path $DiagDir "hardware.json") | Out-Null
& (Join-Path $PSScriptRoot "Integrity-Check.ps1") -Root $Root -Mode Fail | Out-Null
$env:JACKAILOCAL_ROOT = $Root
$env:JACKAILOCAL_CACHE = $CacheDir
$OllamaExe = Join-Path $Root "backends\ollama\windows\ollama.exe"
$DaemonExe = Join-Path $Root "bin\jackailocald.exe"
if (!(Test-Path $DaemonExe)) { throw "Missing $DaemonExe. Run factory build first." }
$ollamaPidFile = Join-Path $RunDir "ollama.pid"
$daemonPidFile = Join-Path $RunDir "jackailocald.pid"
$OllamaPort = "11434"
$OllamaHost = "127.0.0.1:11434"
$OllamaUrl = "http://127.0.0.1:11434"
$ollamaRunning = Get-NetTCPConnection -LocalAddress 127.0.0.1 -LocalPort 11434 -State Listen -ErrorAction SilentlyContinue
$reuseOllama = $false
if ($ollamaRunning) {
# Query the running instance to check if it has the models from the USB
try {
$response = Invoke-RestMethod -Uri "$OllamaUrl/api/tags" -TimeoutSec 2
$manifestPath = Join-Path $Root "manifest\build-manifest.json"
$defaultModelRef = "qwen3.5:4b" # fallback default
if (Test-Path $manifestPath) {
$manifest = Get-Content -Raw $manifestPath | ConvertFrom-Json
if ($manifest.default_model.model_ref) {
$defaultModelRef = $manifest.default_model.model_ref
}
}
$found = $false
foreach ($m in $response.models) {
if ($m.name -eq $defaultModelRef -or $m.name.StartsWith($defaultModelRef + ":") -or $m.name -eq $defaultModelRef.Replace(":", "-")) {
$found = $true
break
}
}
if ($found) {
Write-Host "Ollama is already running on port 11434 and contains our preloaded models. Reusing instance."
$reuseOllama = $true
}
} catch {}
}
if (-not $reuseOllama) {
if ($ollamaRunning) {
Write-Host "Host Ollama is running but does not have our preloaded models. Launching isolated instance on port 11435."
$OllamaPort = "11435"
$OllamaHost = "127.0.0.1:11435"
$OllamaUrl = "http://127.0.0.1:11435"
}
if (!(Test-Path $OllamaExe)) { throw "Missing $OllamaExe. Run backend installer first." }
# Isolate Ollama environment completely to the USB/local folder root
$env:OLLAMA_HOST = $OllamaHost
$env:OLLAMA_MODELS = Join-Path $Root "models\ollama"
$env:OLLAMA_NO_CLOUD = "true"
$env:OLLAMA_TMPDIR = $CacheDir
$env:HOME = $Root
$env:USERPROFILE = $Root
# Also set for the Gradio agent decision engine
$env:OLLAMA_AGENT_ENDPOINT = "http://127.0.0.1:$($OllamaPort)/v1"
$ollamaProcess = Start-Process -FilePath $OllamaExe `
-ArgumentList "serve" `
-WindowStyle Hidden `
-WorkingDirectory (Split-Path $OllamaExe) `
-PassThru `
-RedirectStandardOutput (Join-Path $LogDir "ollama.out.log") `
-RedirectStandardError (Join-Path $LogDir "ollama.err.log")
$ollamaProcess.Id | Set-Content -Encoding ASCII $ollamaPidFile
for ($i = 0; $i -lt 30; $i++) {
Start-Sleep -Milliseconds 500
try {
Invoke-RestMethod -Uri "$OllamaUrl/api/tags" -TimeoutSec 2 | Out-Null
break
} catch {
if ($i -eq 29) { throw "Ollama did not become ready on port $OllamaPort. See $LogDir." }
}
}
} else {
# Reusing running host instance on 11434
$env:OLLAMA_HOST = $OllamaHost
$env:OLLAMA_AGENT_ENDPOINT = "http://127.0.0.1:$($OllamaPort)/v1"
}
$daemonRunning = Get-NetTCPConnection -LocalAddress 127.0.0.1 -LocalPort 4891 -State Listen -ErrorAction SilentlyContinue
if ($daemonRunning -and !(Test-Path $daemonPidFile)) {
throw "Port 4891 is already in use by another process. Stop that process before launching JackAILocal."
}
if (-not $daemonRunning) {
$daemonProcess = Start-Process -FilePath $DaemonExe `
-ArgumentList "serve --config config\jackailocal.windows.toml" `
-WindowStyle Hidden `
-WorkingDirectory $Root `
-PassThru `
-RedirectStandardOutput (Join-Path $LogDir "jackailocald.out.log") `
-RedirectStandardError (Join-Path $LogDir "jackailocald.err.log")
$daemonProcess.Id | Set-Content -Encoding ASCII $daemonPidFile
for ($i = 0; $i -lt 30; $i++) {
Start-Sleep -Milliseconds 500
try {
Invoke-RestMethod -Uri "http://127.0.0.1:4891/health" -TimeoutSec 2 | Out-Null
break
} catch {
if ($i -eq 29) { throw "JackAILocal runtime did not become ready. See $LogDir." }
}
}
}
$Url = "http://127.0.0.1:4891"
if ($NoBrowser) { return }
if ($AppMode) {
$browserCandidates = @(
(Join-Path ${env:ProgramFiles(x86)} "Microsoft\Edge\Application\msedge.exe"),
(Join-Path $env:ProgramFiles "Microsoft\Edge\Application\msedge.exe"),
(Join-Path $env:LOCALAPPDATA "Microsoft\Edge\Application\msedge.exe"),
(Join-Path $env:ProgramFiles "Google\Chrome\Application\chrome.exe"),
(Join-Path ${env:ProgramFiles(x86)} "Google\Chrome\Application\chrome.exe")
)
$appBrowser = $browserCandidates | Where-Object { $_ -and (Test-Path $_) } | Select-Object -First 1
if ($appBrowser) {
Start-Process -FilePath $appBrowser -ArgumentList "--app=$Url", "--start-maximized"
return
}
}
Start-Process $Url