# PlaysmithAI installer for Windows (Windows PowerShell 5.1 or PowerShell 7). # # irm https:///install.ps1 | iex # # With options (the scriptblock form passes them through): # & ([scriptblock]::Create((irm https:///install.ps1))) -Update # or set $env:PLAYSMITHAI_ARGS = '--update' before the one-liner. # # It checks for Node.js 24+, Git and pnpm and offers to install what is missing with winget, then downloads # installer.mjs from the site and runs it. installer.mjs asks for your license key and installs the Studio into # %USERPROFILE%\PlaysmithAI\studio. The install docs on the website list every option. param( [string]$Key = '', [string]$Dir = '', [string]$Api = '', [string]$Site = '', [string]$Local = '', [string]$LocalBundle = '', [switch]$Update, [switch]$Yes, [switch]$Force, [switch]$Release, [switch]$NoOpen, [switch]$NoLauncher, [switch]$SkipInstall, [switch]$SkipBootstrap ) # The website this script downloads installer.mjs from, set before release. PLAYSMITHAI_SITE or # -Site overrides it. While it still holds the __PLAYSMITHAI_ token, the script downloads nothing. $PlaysmithAIDefaultSite = 'https://playsmithai.com' # Everything runs inside this function so nothing leaks into the session that ran the one-liner. The exit code # goes back through $State, never through the output stream: a function whose output is captured also captures the # output of the programs it runs (node's prompts would vanish). function Invoke-PlaysmithAIInstall { param($Opt, $State) $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' function Say([string]$Text) { Write-Host $Text } function Step([string]$Text) { Write-Host ''; Write-Host "==> $Text" } function Ask-Yes([string]$Question) { if ($Opt.Yes) { Say "$Question yes (-Yes)"; return $true } try { $a = Read-Host "$Question [y/N]" } catch { return $false } return ($a -match '^\s*(y|yes)\s*$') } # After an install, the folders it put in the registry PATH are added to this session's PATH: appended, never a # rebuild, so entries that live only in this session (nvm, fnm and Volta shims, a portable node) stay in front. function Update-SessionPath { $have = @($env:Path -split ';' | Where-Object { $_ }) $seen = @{} foreach ($h in $have) { $seen[$h.TrimEnd('\').ToLowerInvariant()] = $true } $add = @() foreach ($scope in @('Machine', 'User')) { $p = [Environment]::GetEnvironmentVariable('Path', $scope) if ($p) { $add += ($p -split ';' | Where-Object { $_ }) } } foreach ($e in @("$env:ProgramFiles\nodejs", "$env:ProgramFiles\Git\cmd", "$env:APPDATA\npm")) { if (Test-Path $e) { $add += $e } } foreach ($e in $add) { $k = $e.TrimEnd('\').ToLowerInvariant() if (-not $seen.ContainsKey($k)) { $have += $e; $seen[$k] = $true } } $env:Path = ($have -join ';') } # The proxy Windows uses for https (Settings > Proxy, a setup script, or WinHTTP), as http://host:port, or '' when # the connection is direct or nothing can be read. function Get-SystemProxy([string]$ForUrl) { $probe = 'https://www.example.com/' if ($ForUrl -match '^https://') { $probe = $ForUrl } try { $uri = [Uri]$probe $sys = [System.Net.WebRequest]::GetSystemWebProxy() if ($sys -and -not $sys.IsBypassed($uri)) { $p = $sys.GetProxy($uri) if ($p -and $p.AbsoluteUri -ne $uri.AbsoluteUri) { return $p.AbsoluteUri.TrimEnd('/') } } } catch { } try { $reg = Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -ErrorAction Stop if ($reg.ProxyEnable -eq 1 -and $reg.ProxyServer) { $s = [string]$reg.ProxyServer if ($s -match '(?:^|;)https=([^;]+)') { $s = $Matches[1] } elseif ($s -match '(?:^|;)http=([^;]+)') { $s = $Matches[1] } elseif ($s -match '=') { return '' } if ($s -notmatch '^[a-z]+://') { $s = "http://$s" } return $s } } catch { } return '' } function Get-NodeMajor { if (-not (Get-Command node.exe -ErrorAction SilentlyContinue)) { return 0 } $v = '' try { $v = (& node.exe -v) | Select-Object -First 1 } catch { return 0 } if ($v -match '^v(\d+)\.') { return [int]$Matches[1] } return 0 } function Test-Cmd([string]$Name) { return [bool](Get-Command $Name -ErrorAction SilentlyContinue) } # Call as a statement (not inside an expression), so winget's output reaches the screen. function Install-WithWinget([string]$Id, [string]$What) { if (-not (Test-Cmd 'winget.exe')) { Say "winget (App Installer) is not available on this PC, so $What cannot be installed automatically." return } Say "Running: winget install -e --id $Id" & winget.exe install -e --id $Id --accept-package-agreements --accept-source-agreements Update-SessionPath } # Downloads need TLS 1.2 on older Windows PowerShell setups. try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { } $site = $Opt.Site if (-not $site) { $site = $env:PLAYSMITHAI_SITE } if (-not $site) { $site = $PlaysmithAIDefaultSite } $site = $site.TrimEnd('/') $siteSet = -not ($site -like '__PLAYSMITHAI_*') Say 'PlaysmithAI installer for Windows' Say 'PlaysmithAI runs on your own Claude Code sign-in (Claude Pro or Max, or an Anthropic API key).' $tar = Join-Path $env:SystemRoot 'System32\tar.exe' if (-not (Test-Path $tar)) { Say "tar.exe was not found in $env:SystemRoot\System32. It ships with Windows 10 (version 1803) and later; update Windows, then run this again." return } Step 'Node.js 24 or later' $major = Get-NodeMajor if ($major -ge 24) { Say "found Node.js $((& node.exe -v) | Select-Object -First 1)" } else { if ($major -gt 0) { Say "found Node.js $major, which is too old" } else { Say 'not found' } if (-not (Ask-Yes 'Install Node.js LTS (24 or later) with winget now?')) { Say 'Install Node.js 24 LTS from https://nodejs.org, then run this again.' return } Install-WithWinget 'OpenJS.NodeJS.LTS' 'Node.js' $major = Get-NodeMajor if ($major -lt 24) { Say 'Node.js 24 or later is still not found. Install it from https://nodejs.org, open a new PowerShell window and run this again.' return } Say "installed Node.js $((& node.exe -v) | Select-Object -First 1)" } Step 'Git' if (Test-Cmd 'git.exe') { Say "found $((& git.exe --version) | Select-Object -First 1)" } else { Say 'not found' if (-not (Ask-Yes 'Install Git with winget now?')) { Say 'Install Git from https://git-scm.com/download/win, then run this again.' return } Install-WithWinget 'Git.Git' 'Git' if (-not (Test-Cmd 'git.exe')) { Say 'Git is still not found. Install it from https://git-scm.com/download/win, open a new PowerShell window and run this again.' return } } Step 'pnpm' # A standalone pnpm.exe, or npm's pnpm.cmd (never the .ps1 shim, which the execution policy may block). function Find-Pnpm { foreach ($n in @('pnpm.exe', 'pnpm.cmd')) { if (Test-Cmd $n) { return $n } } return '' } $pnpm = Find-Pnpm if ($pnpm) { Say "found pnpm $((& $pnpm --version) | Select-Object -First 1)" } else { Say 'not found' if (-not (Ask-Yes 'Install pnpm now (npm install -g pnpm)?')) { Say 'Install pnpm with "npm install -g pnpm", then run this again.' return } & npm.cmd install -g pnpm Update-SessionPath if (-not (Find-Pnpm)) { Say 'pnpm is still not found. Open a new PowerShell window and run this again.' return } } Step 'PlaysmithAI installer' $tmp = Join-Path ([IO.Path]::GetTempPath()) ('playsmithai-' + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $tmp | Out-Null try { if ($Opt.Local) { $mjs = (Resolve-Path $Opt.Local).Path Say "using $mjs (-Local)" } else { if (-not $siteSet) { Say 'This copy of install.ps1 has no website address in it, so it cannot download the installer.' Say 'Copy the install command from the PlaysmithAI website again, or pass -Site https://.' return } $siteUri = $null if (-not [Uri]::TryCreate($site, [UriKind]::Absolute, [ref]$siteUri) -or ($site -notmatch '^https://' -and -not ($siteUri.Scheme -eq 'http' -and $siteUri.Host -in @('localhost', '127.0.0.1', '[::1]')))) { Say 'The website must use https (plain http is allowed only on localhost).' return } $mjs = Join-Path $tmp 'installer.mjs' Say "downloading $site/installer.mjs" try { Invoke-WebRequest -UseBasicParsing -Uri "$site/installer.mjs" -OutFile $mjs -MaximumRedirection 0 } catch { Say "The download failed: $($_.Exception.Message)" Say 'Check your internet connection and try again.' return } } $nodeArgs = @($mjs) if ($siteSet) { $nodeArgs += @('--site', $site) } $childKey = $env:PLAYSMITHAI_KEY if ($Opt.Key) { $childKey = $Opt.Key } if ($Opt.Dir) { $nodeArgs += @('--dir', $Opt.Dir) } if ($Opt.Api) { $nodeArgs += @('--api', $Opt.Api) } if ($Opt.LocalBundle) { $nodeArgs += @('--local-bundle', $Opt.LocalBundle) } if ($Opt.Update) { $nodeArgs += '--update' } if ($Opt.Yes) { $nodeArgs += '--yes' } if ($Opt.Force) { $nodeArgs += '--force' } if ($Opt.Release) { $nodeArgs += '--release' } if ($Opt.NoOpen) { $nodeArgs += '--no-open' } if ($Opt.NoLauncher) { $nodeArgs += '--no-launcher' } if ($Opt.SkipInstall) { $nodeArgs += '--skip-install' } if ($Opt.SkipBootstrap) { $nodeArgs += '--skip-bootstrap' } if ($env:PLAYSMITHAI_ARGS) { foreach ($a in ($env:PLAYSMITHAI_ARGS -split '\s+')) { if ($a) { $nodeArgs += $a } } } $filtered = @() for ($i = 0; $i -lt $nodeArgs.Count; $i++) { if ($nodeArgs[$i] -eq '--key') { $i++ if ($i -ge $nodeArgs.Count -or $nodeArgs[$i] -like '--*') { Say '--key needs a value'; $State.Exit = 2; return } $childKey = $nodeArgs[$i] } elseif ($nodeArgs[$i] -like '--key=*') { $childKey = $nodeArgs[$i].Substring(6) } else { $filtered += $nodeArgs[$i] } } $nodeArgs = $filtered # For the node child only (the session's values are put back after): Node's fetch goes through the proxy in # HTTPS_PROXY only when told to (NODE_USE_ENV_PROXY, Node 24+), and a PC behind a proxy has it in Windows' # settings, not in HTTPS_PROXY, so it is exported when HTTPS_PROXY is not set. NoDefaultCurrentDirectoryInExePath # keeps cmd.exe from running a same-named file in the current folder in place of git or pnpm. $envBefore = @{} foreach ($k in @('NODE_USE_ENV_PROXY', 'HTTPS_PROXY', 'NoDefaultCurrentDirectoryInExePath', 'PLAYSMITHAI_KEY')) { $envBefore[$k] = [Environment]::GetEnvironmentVariable($k, 'Process') } $env:PLAYSMITHAI_KEY = $childKey $env:NODE_USE_ENV_PROXY = '1' $env:NoDefaultCurrentDirectoryInExePath = '1' if (-not $env:HTTPS_PROXY) { $proxy = Get-SystemProxy $site if ($proxy) { $env:HTTPS_PROXY = $proxy; Say "using the system proxy $proxy" } } try { & node.exe @nodeArgs $State.Exit = $LASTEXITCODE } finally { foreach ($k in $envBefore.Keys) { [Environment]::SetEnvironmentVariable($k, $envBefore[$k], 'Process') } } } finally { Remove-Item -Recurse -Force -Path $tmp -ErrorAction SilentlyContinue } } $PlaysmithAIOptions = @{ Key = $Key; Dir = $Dir; Api = $Api; Site = $Site; Local = $Local; LocalBundle = $LocalBundle Update = [bool]$Update; Yes = [bool]$Yes; Force = [bool]$Force; Release = [bool]$Release; NoOpen = [bool]$NoOpen NoLauncher = [bool]$NoLauncher; SkipInstall = [bool]$SkipInstall; SkipBootstrap = [bool]$SkipBootstrap } $PlaysmithAIState = @{ Exit = 1 } try { Invoke-PlaysmithAIInstall -Opt $PlaysmithAIOptions -State $PlaysmithAIState } catch { Write-Host "Stopped: $($_.Exception.Message)" $PlaysmithAIState.Exit = 1 } $PlaysmithAIExit = $PlaysmithAIState.Exit $global:LASTEXITCODE = $PlaysmithAIExit Remove-Item -Path Function:Invoke-PlaysmithAIInstall -ErrorAction SilentlyContinue Remove-Variable -Name PlaysmithAIOptions, PlaysmithAIState, PlaysmithAIDefaultSite -ErrorAction SilentlyContinue # Run as a file (powershell -File install.ps1), pass the exit code on. Through iex, never exit: that would close # the window the customer typed the one-liner in. if ($MyInvocation.MyCommand.Path -and ((Split-Path -Leaf $MyInvocation.MyCommand.Path) -eq 'install.ps1')) { exit $PlaysmithAIExit }