# Project Utah Windows installer. Runs per user; no administrator or system Python needed. [CmdletBinding()] param( [string]$InstallDir = $(if ($env:UTAH_INSTALL_DIR) { $env:UTAH_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'Utah' }), [switch]$NoPath, [switch]$Uninstall ) $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $version = '2026.11.18-terminal.builder.9-win1' $agentHash = '9bbd44593288e13b7940380b019bd5184c1c44c038380702d75d1905fbd52b65' $pythonVersion = '3.13.17' $pythonHashes = @{ amd64 = '9e35319bffedab8b36ad44d8f377cb4f1733bcec257a0b6d04d94f01486ddb38' arm64 = '7b58787a047b400edbfcb539aa3cdb4e2ed77bf0f22cae42b7c01cedd7dd6614' win32 = '4afd37bc88ed1391209a4c58deb902cd0741a476692412b23d340aff6e9285e7' } function Assert-Hash([string]$Path, [string]$Expected) { if ((Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash -ine $Expected) { throw "Download verification failed for $([IO.Path]::GetFileName($Path)). Run the installer again." } } function Write-Atomic([string]$Path, [string]$Text) { $temporary = "$Path.$([Guid]::NewGuid().ToString('N')).tmp" $backup = "$temporary.bak" try { [IO.File]::WriteAllText($temporary, $Text, (New-Object Text.UTF8Encoding($false))) if (Test-Path -LiteralPath $Path) { [IO.File]::Replace($temporary, $Path, $backup) } else { [IO.File]::Move($temporary, $Path) } } finally { if (Test-Path -LiteralPath $temporary) { Remove-Item -LiteralPath $temporary -Force } if (Test-Path -LiteralPath $backup) { Remove-Item -LiteralPath $backup -Force } } } function Set-UtahPath([string]$Directory, [bool]$Remove) { $savedPath = [Environment]::GetEnvironmentVariable('Path', 'User') $parts = @($savedPath -split ';' | Where-Object { $_ -and $_.TrimEnd('\') -ine $Directory.TrimEnd('\') }) if (-not $Remove) { $parts = @($Directory) + $parts } [Environment]::SetEnvironmentVariable('Path', ($parts -join ';'), 'User') $sessionParts = @($env:Path -split ';' | Where-Object { $_ -and $_.TrimEnd('\') -ine $Directory.TrimEnd('\') }) if (-not $Remove) { $sessionParts = @($Directory) + $sessionParts } $env:Path = $sessionParts -join ';' # Inform Explorer so newly opened terminals inherit the new user PATH. try { if (-not ('Utah.EnvironmentBroadcast' -as [type])) { Add-Type -Namespace Utah -Name EnvironmentBroadcast -MemberDefinition @' [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true)] public static extern System.IntPtr SendMessageTimeout(System.IntPtr hWnd, uint Msg, System.UIntPtr wParam, string lParam, uint flags, uint timeout, out System.UIntPtr result); '@ } $broadcastResult = [UIntPtr]::Zero [void][Utah.EnvironmentBroadcast]::SendMessageTimeout([IntPtr]0xffff, 0x1a, [UIntPtr]::Zero, 'Environment', 2, 1000, [ref]$broadcastResult) } catch { Write-Verbose 'Open a new terminal if the existing parent process has cached PATH.' } } $installRoot = [IO.Path]::GetFullPath([Environment]::ExpandEnvironmentVariables($InstallDir)).TrimEnd('\') if ($installRoot -eq [IO.Path]::GetPathRoot($installRoot).TrimEnd('\') -or $installRoot -ieq $env:USERPROFILE -or $installRoot -match '[%"!\r\n]') { throw 'Choose a dedicated Utah install folder without command expansion characters.' } $binDir = Join-Path $installRoot 'bin' $launcher = Join-Path $binDir 'utah.cmd' $operatorHandoff = Join-Path $binDir 'utah-operator-handoff.cmd' $manifestPath = Join-Path $installRoot 'install.json' foreach ($directory in @($installRoot, $binDir)) { if ((Test-Path -LiteralPath $directory) -and ((Get-Item -LiteralPath $directory -Force).Attributes -band [IO.FileAttributes]::ReparsePoint)) { throw 'The install folder must not be a symbolic link or junction.' } } $oldManifest = $null if (Test-Path -LiteralPath $manifestPath) { $oldManifest = Get-Content -LiteralPath $manifestPath -Raw -Encoding UTF8 | ConvertFrom-Json if ($oldManifest.product -ne 'Project Utah terminal' -or $oldManifest.root -ine $installRoot) { throw 'This folder has an unrelated install manifest. Choose a different -InstallDir.' } } if ($Uninstall) { if (-not $oldManifest) { throw 'No Utah installation was found in this folder.' } foreach ($owned in $oldManifest.files) { $target = [IO.Path]::GetFullPath((Join-Path $installRoot $owned.path)) if (-not $target.StartsWith($installRoot + '\', [StringComparison]::OrdinalIgnoreCase)) { throw 'Invalid install manifest path.' } if (Test-Path -LiteralPath $target) { if ((Get-FileHash -LiteralPath $target -Algorithm SHA256).Hash -ieq $owned.sha256) { Remove-Item -LiteralPath $target -Force } else { Write-Host "Preserved modified file: $target" } } } if (-not $NoPath) { Set-UtahPath $binDir $true } Remove-Item -LiteralPath $manifestPath -Force Write-Host 'Utah uninstalled. Saved sign-in and workspace investigations were preserved.' Write-Host 'Use utah --logout before uninstalling to revoke the saved connection.' return } if (Test-Path -LiteralPath $launcher) { if ((Get-Content -LiteralPath $launcher -Raw) -notmatch 'REM Project Utah terminal launcher') { throw 'An unrelated utah.cmd exists. Choose a different -InstallDir.' } } $other = Get-Command utah -ErrorAction SilentlyContinue if ($other -and $other.Source -ine $launcher) { Write-Warning "Another utah command exists at $($other.Source). Utah will also be available at $launcher." } New-Item -ItemType Directory -Path $installRoot, $binDir -Force | Out-Null $stage = Join-Path $installRoot ('.install-' + [Guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $stage | Out-Null try { $architecture = $env:PROCESSOR_ARCHITEW6432 if (-not $architecture) { $architecture = $env:PROCESSOR_ARCHITECTURE } $arch = switch ($architecture.ToUpperInvariant()) { 'ARM64' { 'arm64' } 'AMD64' { 'amd64' } 'X86' { 'win32' } default { throw "Unsupported Windows architecture: $architecture" } } $runtimeName = 'python-' + $pythonVersion + '-' + $arch $runtimeDir = Join-Path $installRoot $runtimeName $python = Join-Path $runtimeDir 'python.exe' # Named by its content hash, like install.sh: a new release never collides with an older file of the same version. $agentName = 'terminal-' + $agentHash.Substring(0, 16).ToLowerInvariant() + '.py' $agent = Join-Path $installRoot $agentName Write-Host "Installing Utah $version for Windows ($arch)..." $source = Join-Path $stage 'terminal.py' if ($PSScriptRoot -and (Test-Path -LiteralPath (Join-Path $PSScriptRoot 'terminal-windows.py'))) { Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'terminal-windows.py') -Destination $source } else { Invoke-WebRequest -UseBasicParsing -Uri ('https://aithatsee.com/utah/terminal-windows.py?version=' + $version) -OutFile $source -TimeoutSec 60 } Assert-Hash $source $agentHash if (-not (Test-Path -LiteralPath $python)) { $archive = Join-Path $stage 'python.zip' $archiveName = 'python-' + $pythonVersion + '-embed-' + $arch + '.zip' if ($PSScriptRoot -and (Test-Path -LiteralPath (Join-Path $PSScriptRoot $archiveName))) { Copy-Item -LiteralPath (Join-Path $PSScriptRoot $archiveName) -Destination $archive } else { Write-Host 'Downloading the private Python runtime from python.org...' Invoke-WebRequest -UseBasicParsing -Uri ('https://www.python.org/ftp/python/' + $pythonVersion + '/' + $archiveName) -OutFile $archive -TimeoutSec 120 } Assert-Hash $archive $pythonHashes[$arch] $expanded = Join-Path $stage 'runtime' Expand-Archive -LiteralPath $archive -DestinationPath $expanded $signature = Get-AuthenticodeSignature -LiteralPath (Join-Path $expanded 'python.exe') if ($signature.Status -ne 'Valid' -or $signature.SignerCertificate.Subject -notmatch 'Python Software Foundation') { throw 'The Python runtime signature could not be verified.' } # Restore ordinary script-directory imports for configured local test adapters. # Utah itself launches with -E -S to ignore Python environment/site customization. Get-ChildItem -LiteralPath $expanded -Filter 'python*._pth' -File | ForEach-Object { Remove-Item -LiteralPath $_.FullName -Force } if (Test-Path -LiteralPath $runtimeDir) { throw 'An incomplete private runtime exists. Choose a new install folder or repair this runtime.' } Move-Item -LiteralPath $expanded -Destination $runtimeDir } $syntaxCheck = & $python -E -S -X utf8 -c 'import ast,pathlib,sys; ast.parse(pathlib.Path(sys.argv[1]).read_bytes()); assert sys.version_info >= (3,9)' $source 2>&1 if ($LASTEXITCODE -ne 0) { throw "The agent or private runtime did not validate: $syntaxCheck" } $candidateVersion = & $python -E -S -X utf8 -u $source --version 2>&1 if ($LASTEXITCODE -ne 0 -or "$candidateVersion" -ne "Utah $version") { throw "The candidate did not start: $candidateVersion. Your launcher was preserved." } if ((Test-Path -LiteralPath $agent) -and (Get-FileHash -LiteralPath $agent -Algorithm SHA256).Hash -ieq $agentHash) { Remove-Item -LiteralPath $source -Force } else { Move-Item -LiteralPath $source -Destination $agent -Force } $launcherText = "@echo off`r`nREM Project Utah terminal launcher`r`nsetlocal DisableDelayedExpansion`r`n`"%~dp0..\$runtimeName\python.exe`" -E -S -X utf8 -u `"%~dp0..\$agentName`" %*`r`nexit /b %errorlevel%`r`n" Write-Atomic $launcher $launcherText $check = & $launcher --version 2>&1 if ($LASTEXITCODE -ne 0 -or "$check" -ne "Utah $version") { throw "Launch verification failed: $check" } $operatorHandoffText = @' @echo off setlocal DisableDelayedExpansion call "%~dp0utah.cmd" --operator-handoff exit /b %errorlevel% '@ Write-Atomic $operatorHandoff $operatorHandoffText $ownedFiles = @($agent, $launcher, $operatorHandoff) + @(Get-ChildItem -LiteralPath $runtimeDir -File -Recurse | ForEach-Object { $_.FullName }) $files = @($ownedFiles | ForEach-Object { @{ path = $_.Substring($installRoot.Length + 1); sha256 = (Get-FileHash -LiteralPath $_ -Algorithm SHA256).Hash.ToLowerInvariant() } }) if ($oldManifest) { $current = @($files | ForEach-Object { $_.path }) $files += @($oldManifest.files | Where-Object { $_.path -notin $current }) } Write-Atomic $manifestPath (@{ product = 'Project Utah terminal'; root = $installRoot; version = $version; files = $files } | ConvertTo-Json -Depth 5) if (-not $NoPath) { Set-UtahPath $binDir $false } Write-Host "Installed and verified: $check" Write-Host "`nIn a new terminal, connect your account: utah --setup" Write-Host 'In your project folder, start with: utah' Write-Host "Or run setup now: & '$($launcher.Replace("'", "''"))' --setup" Write-Host 'Rerun this installer to update. Run utah --doctor to check tools without signing in.' } finally { $resolvedStage = [IO.Path]::GetFullPath($stage) if ($resolvedStage.StartsWith($installRoot + '\.install-', [StringComparison]::OrdinalIgnoreCase) -and (Test-Path -LiteralPath $resolvedStage)) { Remove-Item -LiteralPath $resolvedStage -Recurse -Force } }