Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(install.ps1): keep the user PATH's %VAR% entries and registry type

Vinícius DS Andrade053d43c1d552
diff --git a/install.ps1 b/install.ps1
index ea7e2c55..557048f2 100644
--- a/install.ps1
+++ b/install.ps1
@@ -140,11 +140,27 @@ function Install-AiMemory {
Say "next: & `"$exe`" setup"
return
}
- $userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
- $entries = if ($userPath) { $userPath -split ';' | Where-Object { $_ } } else { @() }
- if ($entries -notcontains $dest) {
- [Environment]::SetEnvironmentVariable('Path', (@($entries) + $dest) -join ';', 'User')
- Say "added $dest to your user PATH"
+ # Read and write the registry value itself (#1509):
+ # [Environment]::GetEnvironmentVariable expands every %VAR% entry, and
+ # SetEnvironmentVariable stores the result as a plain REG_SZ string, so an
+ # entry such as %JAVA_HOME%\bin would stop following its variable. Entries
+ # are still compared expanded, so one naming $dest through a variable counts.
+ $environment = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Environment')
+ try {
+ $userPath = $environment.GetValue('Path', '', 'DoNotExpandEnvironmentNames')
+ $entries = if ($userPath) { $userPath -split ';' | Where-Object { $_ } } else { @() }
+ $expanded = $entries | ForEach-Object { [Environment]::ExpandEnvironmentVariables($_) }
+ if ($expanded -notcontains $dest) {
+ $environment.SetValue('Path', (@($entries) + $dest) -join ';', 'ExpandString')
+ # Removing a variable that does not exist changes nothing, but .NET
+ # still broadcasts WM_SETTINGCHANGE after it, so Explorer and the
+ # terminals it starts pick up the new PATH.
+ $notify = 'ai-memory-install-' + [Guid]::NewGuid().ToString('N')
+ [Environment]::SetEnvironmentVariable($notify, [NullString]::Value, 'User')
+ Say "added $dest to your user PATH"
+ }
+ } finally {
+ $environment.Dispose()
}
if (($env:Path -split ';') -notcontains $dest) { $env:Path = "$env:Path;$dest" }
Say 'next: ai-memory setup'