Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(windows): launch the service host with plain paths
Gabriel Scharb0b2daed08f24
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 59954396..354f8cc4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,13 @@ version in [`docs/changelog/`](docs/changelog/):## [Unreleased]+### Fixed+- On Windows, `setup` now starts the logon host with a plain executable path,+ and the host passes plain drive/UNC data-directory and config arguments to the+ supervisor and server it launches, instead of the `\\?\` verbatim prefix a+ canonical path carries. The `Run` value was already plain (3.1.0); this covers+ the command lines built from `current_exe()` and the canonical data dir. (#1280)+## [3.1.0] - 2026-10-16### Addeddiff --git a/crates/ai-memory-cli/src/commands/service_host.rs b/crates/ai-memory-cli/src/commands/service_host.rsindex 8cdb0cbb..c85c09b9 100644--- a/crates/ai-memory-cli/src/commands/service_host.rs+++ b/crates/ai-memory-cli/src/commands/service_host.rs@@ -279,19 +279,30 @@ fn sleep_unless_stopped(delay: Duration, stop_requested: &dyn Fn() -> bool) {}}-/// The global arguments that point a child at this install.+/// The global arguments that point a child at this install. Paths are passed+/// in their plain spelling, the one the logon entry uses: the data dir is+/// canonical, and its `\\?\` prefix otherwise reaches the command lines of+/// the supervisor and the server, where an EDR trace showed it (#1280).pub(crate) fn install_args(config: &Config, config_path: Option<&Path>) -> Vec<std::ffi::OsString> {- let mut args = vec![- "--data-dir".into(),- config.data_dir.clone().into_os_string(),- ];+ let mut args = vec!["--data-dir".into(), plain_arg(&config.data_dir)];if let Some(path) = config_path {args.push("--config".into());- args.push(path.as_os_str().to_owned());+ args.push(plain_arg(path));}args}+/// `path` without a `\\?\` verbatim prefix. A path that is not UTF-8 is+/// passed as it is.+fn plain_arg(path: &Path) -> std::ffi::OsString {+ match path.to_str() {+ Some(text) => super::path_util::strip_windows_verbatim_prefix(text)+ .into_owned()+ .into(),+ None => path.as_os_str().to_owned(),+ }+}+/// Run `service-host`.////// # Errors@@ -304,7 +315,10 @@ pub async fn run(config: &Config, args: ServiceHostArgs, config_path: Option<&Pasetup` installs a systemd user unit or a LaunchAgent instead");}+ // `current_exe()` can return a `\\?\` verbatim path; the host launches+ // itself and the server with it, so strip the prefix there too (#1280).let exe = std::env::current_exe().context("locating the running ai-memory binary")?;+ let exe = std::path::PathBuf::from(plain_arg(&exe));let install = install_args(config, config_path);if !args.supervise {let mut host_args = install.clone();@@ -802,6 +816,40 @@ mod tests {);}+ /// The data dir is canonical, so on Windows it carries a `\\?\` prefix;+ /// the supervisor and the server get the plain spelling (#1280).+ #[test]+ fn children_get_plain_paths() {+ let config = Config {+ data_dir: PathBuf::from(r"\\?\C:\Users\me\AppData\Local\ai-memory"),+ ..Config::default()+ };+ let config_path = Path::new(r"\\?\C:\Users\me\AppData\Local\ai-memory\config.toml");+ assert_eq!(+ install_args(&config, Some(config_path)),+ [+ "--data-dir",+ r"C:\Users\me\AppData\Local\ai-memory",+ "--config",+ r"C:\Users\me\AppData\Local\ai-memory\config.toml",+ ]+ .map(std::ffi::OsString::from)+ .to_vec()+ );++ // A data dir on a share keeps its UNC spelling, and spaces survive.+ let config = Config {+ data_dir: PathBuf::from(r"\\?\UNC\server\share\ai memory"),+ ..Config::default()+ };+ assert_eq!(+ install_args(&config, None),+ ["--data-dir", r"\\server\share\ai memory"]+ .map(std::ffi::OsString::from)+ .to_vec()+ );+ }+#[test]fn service_host_refuses_off_windows() {if cfg!(windows) {diff --git a/crates/ai-memory-cli/src/commands/user_service.rs b/crates/ai-memory-cli/src/commands/user_service.rsindex a4b02d50..065b0e42 100644--- a/crates/ai-memory-cli/src/commands/user_service.rs+++ b/crates/ai-memory-cli/src/commands/user_service.rs@@ -382,7 +382,7 @@ fn render_windows(spec: &ServiceSpec) -> Result<ServiceUnit> {path: unit_path(ServiceManager::WindowsRun, &spec.home, None),contents,host: Some(HostLaunch {- exe: spec.exe.clone(),+ exe: PathBuf::from(exe),args: ["--data-dir", data_dir, "--config", config, SERVICE_HOST].map(str::to_owned).to_vec(),@@ -1865,6 +1865,15 @@ mod windows_entry_tests {"{}",unit.contents);+ // `setup` starts the host with this command line too, and the+ // verbatim program path showed up in an EDR's process tree there.+ let host = unit.host.unwrap();+ assert_eq!(host.exe, PathBuf::from(r"C:\Users\me\ai\ai-memory.exe"));+ assert!(+ host.args.iter().all(|arg| !arg.contains(r"\\?\")),+ "{:?}",+ host.args+ );}/// The rendered entry is one setup recognises as its own, names the