Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(windows): recognize upgrade after global options
agammann57ef7cbdd592
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c6a02aca..4725146c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,6 +13,11 @@ version in [`docs/changelog/`](docs/changelog/):### Fixed+- The native Windows Docker wrapper now recognizes `upgrade` after valid+ `--config` or `--data-dir` global options and pulls the image instead of+ forwarding `upgrade` into the helper container. Unknown and malformed+ options still reach the CLI parser (#1667).+- `ai-memory user list` and `ai-memory api-key list` now size their columnsby terminal display width rather than bytes, as `list-projects` and thegrants tables already do. An accented username, display name or key labeldiff --git a/bin/ai-memory.ps1 b/bin/ai-memory.ps1index 7250b977..d631be55 100644--- a/bin/ai-memory.ps1+++ b/bin/ai-memory.ps1@@ -40,10 +40,22 @@ function Get-WrapperSubcommand {$Index = 0while ($Index -lt $WrapperArgs.Count) {$Arg = $WrapperArgs[$Index]- if ($Arg -eq "--config" -or $Arg -eq "--data-dir") {+ if ($Arg -ceq "--config" -or $Arg -ceq "--data-dir") {+ if ($Index + 1 -ge $WrapperArgs.Count -or+ [string]::IsNullOrEmpty($WrapperArgs[$Index + 1]) -or+ ($WrapperArgs[$Index + 1].Length -gt 1 -and+ $WrapperArgs[$Index + 1].StartsWith("-"))) {+ return ""+ }$Index += 2- } elseif ($Arg -like "--*") {+ } elseif ($Arg -clike "--config=*" -or $Arg -clike "--data-dir=*") {+ if ($Arg.EndsWith("=")) {+ return ""+ }$Index += 1+ } elseif ($Arg.StartsWith("-")) {+ # Leave unknown and malformed options to the CLI parser.+ return ""} else {return $Arg}@@ -198,7 +210,7 @@ if (-not (Get-Command $Docker -ErrorAction SilentlyContinue)) {exit 127}-if ($CommandArgs.Count -gt 0 -and $CommandArgs[0] -eq "upgrade") {+if ((Get-WrapperSubcommand $CommandArgs) -ceq "upgrade") {& $Docker pull $Imageif ($LASTEXITCODE -ne 0) {exit $LASTEXITCODEdiff --git a/crates/ai-memory-cli/tests/suite/packaging.rs b/crates/ai-memory-cli/tests/suite/packaging.rsindex 98c6eafa..cf9ada14 100644--- a/crates/ai-memory-cli/tests/suite/packaging.rs+++ b/crates/ai-memory-cli/tests/suite/packaging.rs@@ -1416,7 +1416,7 @@ fn run_powershell_wrapper_with_server_url(args: &[&str], server_url: Option<&strlet output = command.output().unwrap();assert!(output.status.success(),- "PowerShell wrapper failed: stdout={} stderr={}",+ "PowerShell wrapper failed for {args:?}: stdout={} stderr={}",String::from_utf8_lossy(&output.stdout),String::from_utf8_lossy(&output.stderr));@@ -3579,6 +3579,68 @@ mod slow {);}+ #[cfg(windows)]+ #[test]+ fn windows_wrapper_upgrades_after_valid_global_options_only() {+ for args in [+ &["upgrade"][..],+ &["--config", "C:\\tmp\\config with spaces.toml", "upgrade"],+ &["--config=C:\\tmp\\config.toml", "upgrade"],+ &["--data-dir", "C:\\tmp\\data", "upgrade"],+ &["--data-dir=C:\\tmp\\data", "upgrade"],+ ] {+ let docker = run_powershell_wrapper(args);+ assert!(+ docker.starts_with("pull "),+ "valid global options must not hide the wrapper-only upgrade; args={args:?}, docker={docker}"+ );+ }++ for args in [+ &["--unknown", "upgrade"][..],+ &["--help", "upgrade"],+ &["--config", "--help", "upgrade"],+ &["--data-dir=", "upgrade"],+ &["--CONFIG", "C:\\tmp\\config.toml", "upgrade"],+ &["--DATA-DIR=C:\\tmp\\data", "upgrade"],+ &["--config", "C:\\tmp\\config.toml", "UPGRADE"],+ ] {+ let docker = run_powershell_wrapper(args);+ assert!(+ docker.starts_with("run "),+ "invalid or help options must not trigger an image pull; args={args:?}, docker={docker}"+ );+ }++ // `powershell.exe -File` consumes a bare `-` before the script sees it,+ // so exercise this valid config value through a PowerShell command.+ let script = repo_root()+ .join("bin/ai-memory.ps1")+ .display()+ .to_string()+ .replace('\'', "''");+ let output = Command::new(ai_memory_test_support::powershell_exe())+ .args([+ "-NoLogo",+ "-NoProfile",+ "-NonInteractive",+ "-ExecutionPolicy",+ "Bypass",+ "-Command",+ ])+ .arg(format!("& '{script}' --config '-' upgrade"))+ .env("AI_MEMORY_DOCKER", "Write-Output")+ .output()+ .unwrap();+ assert!(+ output.status.success() && String::from_utf8_lossy(&output.stdout).starts_with("pull"),+ "a single dash is a valid config value: status={:?}, stdout={}, stderr={}",+ output.status.code(),+ String::from_utf8_lossy(&output.stdout),+ String::from_utf8_lossy(&output.stderr)+ );+ }+// #1545: the helper container has no host harnesses, so the managed// launch/discovery commands must run through the native Windows client —// never the container engine — with the child's exit code preserved.diff --git a/docs/windows.md b/docs/windows.mdindex c5314509..d525f386 100644--- a/docs/windows.md+++ b/docs/windows.md@@ -200,8 +200,9 @@ container, which has no host CLIs.sets `AI_MEMORY_RUN_AUTOWIRE=false` for the intercepted commands unless youset the variable yourself). Export `AI_MEMORY_RUN_AUTOWIRE=true` to let`run` rewire a harness around the native client instead.-- Upgrading in this scenario: `ai-memory upgrade` pulls the image only. It- does not refresh the wrapper or install a native client. Refresh the+- Upgrading in this scenario: `ai-memory upgrade` pulls the image only,+ including when `--config` or `--data-dir` precedes `upgrade`. It does not+ refresh the wrapper or install a native client. Refresh thewrapper scripts by re-running the install block at the top of thisscenario, and the native client with its own `ai-memory.exe upgrade`([Scenario C](#scenario-c-prebuilt-release-binary-no-toolchain)). Then