the runtime your coding agents live on
Rust agentagent-orchestrationaiai-agentsclaude-codeclicodexcoding-agentsdeveloper-toolsdevtoolsmultiplexerrustterminalterminal-multiplexerterminal-uitmuxtuiworkspace-manager
fix: preserve windows path variables during install
Ogulcan Celik8ed742da2683
diff --git a/scripts/windows_install_conpty_package_test.ps1 b/scripts/windows_install_conpty_package_test.ps1index 062c2cfed..232e61ac4 100644--- a/scripts/windows_install_conpty_package_test.ps1+++ b/scripts/windows_install_conpty_package_test.ps1@@ -6,6 +6,69 @@ param(Set-StrictMode -Version Latest$ErrorActionPreference = "Stop"+$installerPath = (Resolve-Path -LiteralPath "$PSScriptRoot\..\website\install.ps1").Path+$parseErrors = $null+$tokens = $null+$installerAst = [System.Management.Automation.Language.Parser]::ParseFile(+ $installerPath,+ [ref]$tokens,+ [ref]$parseErrors+)+if ($parseErrors.Count -ne 0) {+ throw ($parseErrors | Out-String)+}+foreach ($functionName in @("Prepend-PathEntry", "Update-PathRegistryEntry")) {+ $definition = $installerAst.FindAll(+ {+ param($node)+ $node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and+ $node.Name -eq $functionName+ },+ $true+ ) | Select-Object -First 1+ if ($null -eq $definition) {+ throw "installer is missing function $functionName"+ }+ Invoke-Expression $definition.Extent.Text+}++$pathTestVariable = "HERDR_INSTALLER_PATH_TEST"+$oldPathTestVariable = [Environment]::GetEnvironmentVariable($pathTestVariable, "Process")+$testRegistryPath = "Software\HerdrInstallerTests-$([Guid]::NewGuid().ToString('N'))"+$testEnvironmentKey = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey($testRegistryPath)+if ($null -eq $testEnvironmentKey) {+ throw "unable to create temporary installer test registry key"+}+try {+ [Environment]::SetEnvironmentVariable($pathTestVariable, "C:\expanded", "Process")+ $testEnvironmentKey.SetValue(+ "Path",+ "%$pathTestVariable%\bin;C:\existing",+ [Microsoft.Win32.RegistryValueKind]::ExpandString+ )+ $pathChanged = Update-PathRegistryEntry -EnvironmentKey $testEnvironmentKey -Entry "C:\Herdr\bin"+ if (-not $pathChanged) {+ throw "installer PATH update reported no change"+ }+ if (Update-PathRegistryEntry -EnvironmentKey $testEnvironmentKey -Entry "C:\Herdr\bin") {+ throw "installer PATH update was not idempotent"+ }++ $options = [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames+ $rawPath = $testEnvironmentKey.GetValue("Path", $null, $options)+ $expectedPath = "C:\Herdr\bin;%$pathTestVariable%\bin;C:\existing"+ if ($rawPath -cne $expectedPath) {+ throw "installer changed raw PATH: expected '$expectedPath', got '$rawPath'"+ }+ if ($testEnvironmentKey.GetValueKind("Path") -ne [Microsoft.Win32.RegistryValueKind]::ExpandString) {+ throw "installer changed the PATH registry value kind"+ }+} finally {+ $testEnvironmentKey.Dispose()+ [Microsoft.Win32.Registry]::CurrentUser.DeleteSubKeyTree($testRegistryPath, $false)+ [Environment]::SetEnvironmentVariable($pathTestVariable, $oldPathTestVariable, "Process")+}+$archive = (Resolve-Path -LiteralPath $ArchivePath).Path$root = Join-Path $env:RUNNER_TEMP ("herdr-installer-test-" + [Guid]::NewGuid().ToString("N"))$webRoot = Join-Path $root "web"diff --git a/website/install.ps1 b/website/install.ps1index ce510e7b3..e5842dc8f 100644--- a/website/install.ps1+++ b/website/install.ps1@@ -94,6 +94,55 @@ function Prepend-PathEntry {return ($segments -join ";")}+function Update-PathRegistryEntry {+ param(+ [Microsoft.Win32.RegistryKey]$EnvironmentKey,+ [string]$Entry+ )++ $options = [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames+ $value = $EnvironmentKey.GetValue("Path", $null, $options)+ $kind = if ($null -eq $value) {+ [Microsoft.Win32.RegistryValueKind]::String+ } else {+ $EnvironmentKey.GetValueKind("Path")+ }+ $newValue = Prepend-PathEntry -PathValue $value -Entry $Entry+ if ($newValue -ceq $value) {+ return $false+ }++ $EnvironmentKey.SetValue("Path", $newValue, $kind)+ return $true+}++function Publish-EnvironmentChange {+ if (-not ("HerdrInstaller.EnvironmentNativeMethods" -as [type])) {+ Add-Type -Namespace HerdrInstaller -Name EnvironmentNativeMethods -MemberDefinition @'+[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Unicode)]+public static extern System.IntPtr SendMessageTimeout(+ System.IntPtr hWnd,+ uint message,+ System.UIntPtr wParam,+ string lParam,+ uint flags,+ uint timeout,+ out System.UIntPtr result);+'@+ }++ $result = [UIntPtr]::Zero+ [HerdrInstaller.EnvironmentNativeMethods]::SendMessageTimeout(+ [IntPtr]0xffff,+ 0x1a,+ [UIntPtr]::Zero,+ "Environment",+ 0x0002,+ 1000,+ [ref]$result+ ) | Out-Null+}+function Get-ManifestAsset {param([object]$Manifest,@@ -608,10 +657,17 @@ try {Remove-Item -LiteralPath $tempDir -Recurse -Force -ErrorAction SilentlyContinue}-$userPath = [Environment]::GetEnvironmentVariable("Path", "User")-$newUserPath = Prepend-PathEntry -PathValue $userPath -Entry $visibleBinDir-if ($newUserPath -cne $userPath) {- [Environment]::SetEnvironmentVariable("Path", $newUserPath, "User")+$userEnvironmentKey = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey("Environment")+if ($null -eq $userEnvironmentKey) {+ throw "Unable to open the current user's environment registry key."+}+try {+ $userPathChanged = Update-PathRegistryEntry -EnvironmentKey $userEnvironmentKey -Entry $visibleBinDir+} finally {+ $userEnvironmentKey.Dispose()+}+if ($userPathChanged) {+ Publish-EnvironmentChangeWrite-Step "PATH updated for future PowerShell sessions."} else {Write-Step "$visibleBinDir is already first on PATH."