param ( [switch]$VerboseOutput ) $ErrorActionPreference = "Stop" Write-Host "========================================================" -ForegroundColor Cyan Write-Host " Tala Cognitive Engine Room - Native Windows Installer" -ForegroundColor Cyan Write-Host "========================================================" -ForegroundColor Cyan Write-Host "" $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition $Root = $ScriptDir # 1. Preflight & "$Root\scripts\doctor.ps1" if ($LASTEXITCODE -eq 2) { Write-Host "Doctor found critical issues (e.g., port conflicts). Please resolve them before running the installer." -ForegroundColor Red exit 1 } elseif ($LASTEXITCODE -eq 1) { Write-Host "Doctor found missing dependencies. Attempting to install them..." -ForegroundColor Yellow } # 2. Dependencies via Winget Write-Host "[2/6] Checking Dependencies via Winget..." function Install-IfMissing { param([string]$Command, [string]$WingetId, [string]$FriendlyName) try { $null = Get-Command $Command -ErrorAction Stop Write-Host " - $FriendlyName is already installed." -ForegroundColor Green } catch { Write-Host " - Installing $FriendlyName via winget..." -ForegroundColor Yellow winget install --id $WingetId --accept-package-agreements --accept-source-agreements --silent Write-Host " - $FriendlyName installed! (You may need to restart your terminal later)." -ForegroundColor Green } } Install-IfMissing -Command "node" -WingetId "OpenJS.NodeJS.LTS" -FriendlyName "Node.js" Install-IfMissing -Command "uv" -WingetId "astral-sh.uv" -FriendlyName "Python (uv)" Install-IfMissing -Command "psql" -WingetId "PostgreSQL.PostgreSQL" -FriendlyName "PostgreSQL" # Update PATH dynamically for the current session in case winget just installed them $env:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") if (-not (Get-Command "python" -ErrorAction SilentlyContinue) -and -not (Get-Command "py" -ErrorAction SilentlyContinue)) { Write-Host " - Python runtime not found. Installing Python 3.11 via uv..." -ForegroundColor Yellow uv python install 3.11 Write-Host " - Python runtime is available through uv." -ForegroundColor Green } else { Write-Host " - Python runtime is already available." -ForegroundColor Green } # 3. Bootstrap Database Write-Host "[3/6] Bootstrapping Database..." & "$Root\scripts\bootstrap-db.ps1" -DbUser "tala" -DbPass "tala" -DbName "tala" # 4. Generate .env safely Write-Host "[4/6] Checking Configuration..." $EnvPath = Join-Path $Root ".env" if (Test-Path $EnvPath) { Write-Host " - .env file already exists. Skipping generation to prevent silent overwrite." -ForegroundColor Yellow } else { Write-Host " - .env will be generated by first-run setup." -ForegroundColor Yellow } # 5. First-run setup Write-Host "[5/6] Running First-Run Setup..." Push-Location $Root uv run python scripts/first_run.py --self-test Pop-Location Write-Host "[6/6] Execution Policy Checks..." $CurrentPolicy = Get-ExecutionPolicy if ($CurrentPolicy -eq "Restricted") { Write-Host " - PowerShell Execution Policy is 'Restricted'." -ForegroundColor Yellow Write-Host " - To run Tala scripts without issues, consider running:" Write-Host " Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser" -ForegroundColor Cyan } else { Write-Host " - Execution policy is $CurrentPolicy. Looks good." -ForegroundColor Green } Write-Host "========================================================" -ForegroundColor Green Write-Host " Installation Complete!" -ForegroundColor Green Write-Host " Run Tala by executing: .\scripts\start-tala.ps1" -ForegroundColor Green Write-Host "========================================================" -ForegroundColor Green