$ErrorActionPreference = 'Stop' $Version = '0.2.0' $Base = if ($env:AGENTSOCKET_RELEASE_URL) { $env:AGENTSOCKET_RELEASE_URL } else { "https://agentsocket.xyz/releases/$Version" } $Architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant() if ($Architecture -notin @('x64','arm64')) { throw 'This release supports Windows x64 and arm64.' } $Name = "agentsocket-windows-$Architecture.exe" $Temp = Join-Path ([IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString()) New-Item -ItemType Directory $Temp | Out-Null try { Invoke-WebRequest "$Base/$Name" -OutFile (Join-Path $Temp $Name) $Sums = (Invoke-WebRequest "$Base/SHA256SUMS").Content $Expected = ($Sums -split "`n" | Where-Object { $_ -match "^[a-f0-9]{64}\s+$([regex]::Escape($Name))\s*$" }) -replace '\s+.*$', '' $Actual = (Get-FileHash (Join-Path $Temp $Name) -Algorithm SHA256).Hash.ToLowerInvariant() if (!$Expected -or $Actual -ne $Expected.Trim()) { throw 'Release checksum verification failed.' } $Bin = if ($env:AGENTSOCKET_INSTALL_DIR) { $env:AGENTSOCKET_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'AgentSocket\bin' } New-Item -ItemType Directory -Force $Bin | Out-Null Move-Item -Force (Join-Path $Temp $Name) (Join-Path $Bin 'agentsocket.exe') $Path = [Environment]::GetEnvironmentVariable('Path','User') if (($Path -split ';') -notcontains $Bin) { [Environment]::SetEnvironmentVariable('Path',"$Bin;$Path",'User') } $env:Path = "$Bin;$env:Path" & (Join-Path $Bin 'agentsocket.exe') --help | Out-Null Write-Host "AgentSocket $Version installed. Run agentsocket login, then agentsocket connect." } finally { Remove-Item -Recurse -Force $Temp }