Something went wrong. Try again.
Open source agent hosting on the AT Protocol
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192# Installs the languid CLI on Windows, or updates it: irm https://languid.ai/install.ps1 | iex## Needs Node 22.18 or newer, and Git for Windows for the bash your agents run commands in. The code# goes in ~\.languid\app and a `languid` command in ~\.local\bin, which joins your PATH. Running it# again updates both and restarts the Languid tray. Then, on a first install, it signs you in# (LANGUID_NO_LOGIN=1 skips that).## The service fills in @SERVICE@ and @TARBALL@ when it serves this file.$ErrorActionPreference = 'Stop'$ProgressPreference = 'SilentlyContinue'
function Fail($msg) { Write-Host "languid install: $msg" -ForegroundColor Red; throw "languid install: $msg" }
$Service = if ($env:LANGUID_SERVER) { $env:LANGUID_SERVER } else { '@SERVICE@' }$Tarball = if ($env:LANGUID_TARBALL) { $env:LANGUID_TARBALL } else { '@TARBALL@' }$App = if ($env:LANGUID_APP_DIR) { $env:LANGUID_APP_DIR } else { Join-Path $HOME '.languid\app' }$Bin = if ($env:LANGUID_BIN_DIR) { $env:LANGUID_BIN_DIR } else { Join-Path $HOME '.local\bin' }
if (-not (Get-Command node -ErrorAction SilentlyContinue)) { Fail 'needs Node 22.18 or newer: https://nodejs.org' }if (-not (Get-Command npx -ErrorAction SilentlyContinue)) { Fail 'needs npx, which comes with Node: https://nodejs.org' }if (-not (Get-Command tar -ErrorAction SilentlyContinue)) { Fail 'needs tar, which comes with Windows 10 and later' }& node -e 'const [a, b] = process.versions.node.split(".").map(Number); process.exit(a > 22 || (a === 22 && b >= 18) ? 0 : 1)'if ($LASTEXITCODE -ne 0) { Fail "needs Node 22.18 or newer (this is $(node --version)): https://nodejs.org" }$gitBash = @("$env:ProgramFiles\Git\bin\bash.exe", "${env:ProgramFiles(x86)}\Git\bin\bash.exe") | Where-Object { $_ -and (Test-Path $_) } | Select-Object -First 1if (-not $gitBash) { Write-Host 'Your agents run commands in bash, which comes with Git for Windows: https://git-scm.com/download/win' -ForegroundColor Yellow }
New-Item -ItemType Directory -Force -Path (Split-Path $App), $Bin | Out-Null$New = "$App.new.$PID"$Old = "$App.old.$PID"$Tgz = "$New.tgz"try { Write-Host 'downloading languid…' try { Invoke-WebRequest -Uri $Tarball -OutFile $Tgz -UseBasicParsing } catch { Fail "could not download $Tarball" } New-Item -ItemType Directory -Force -Path $New | Out-Null & tar -xzf $Tgz -C $New --strip-components=1 if ($LASTEXITCODE -ne 0) { Fail "could not unpack $Tarball" } if (-not (Test-Path (Join-Path $New 'src\cli.ts'))) { Fail "$Tarball doesn't look like languid" }
# The tray holds files in the old copy open; stop it before the swap, and start it again after. $tray = Get-CimInstance Win32_Process -Filter "Name = 'powershell.exe'" | Where-Object { $_.CommandLine -like "*$App\windows\Languid.ps1*" } $tray | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }
# Swap it in before installing: pnpm writes absolute paths into node_modules\.bin. $first = -not (Test-Path $App) if (-not $first) { Move-Item $App $Old } Move-Item $New $App Write-Host 'installing its dependencies…' $pnpm = (& node -p "require('$($App.Replace('\','/'))/package.json').packageManager.split('@')[1]") Push-Location $App $env:NPM_CONFIG_UPDATE_NOTIFIER = 'false' & npx --yes "pnpm@$pnpm" install --frozen-lockfile --reporter=silent $ok = $LASTEXITCODE -eq 0 Pop-Location if (-not $ok) { Remove-Item -Recurse -Force $App -ErrorAction SilentlyContinue if (Test-Path $Old) { Move-Item $Old $App } Fail 'installing dependencies failed; nothing changed' } if (Test-Path $Old) { Remove-Item -Recurse -Force $Old -ErrorAction SilentlyContinue }} finally { Remove-Item -Force $Tgz -ErrorAction SilentlyContinue if (Test-Path $New) { Remove-Item -Recurse -Force $New -ErrorAction SilentlyContinue }}
Set-Content -Path (Join-Path $Bin 'languid.cmd') -Encoding ASCII -Value "@echo off`r`nnode `"$App\src\cli.ts`" %*"Write-Host "installed: $Bin\languid.cmd"
# A computer set up from this install keeps running the old code until the tray restarts it.if ($tray) { Start-Process -WindowStyle Hidden -FilePath powershell.exe -ArgumentList @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden', '-File', "`"$App\windows\Languid.ps1`"") Write-Host 'restarted the Languid tray'}
# Put ~\.local\bin on the user's PATH, once.$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')if (-not (($userPath -split ';') -contains $Bin)) { [Environment]::SetEnvironmentVariable('Path', ($(if ($userPath) { "$userPath;" } else { '' }) + $Bin), 'User') Write-Host "added $Bin to your PATH"}if (-not (($env:Path -split ';') -contains $Bin)) { $env:Path = "$env:Path;$Bin" }
if (-not $first) { Write-Host 'updated'} elseif (-not $env:LANGUID_NO_LOGIN -and [Environment]::UserInteractive) { Write-Host '' & "$Bin\languid.cmd" login --url $Service if ($LASTEXITCODE -eq 0) { Write-Host ''; Write-Host 'run: languid' } else { Write-Host ''; Write-Host 'sign in with: languid login' }} else { Write-Host '' Write-Host 'sign in with: languid login'}