Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(setup): keep the Windows logon entry off reg.exe and scope uninstall to its data dir
Gabriel Scharbd4c895249cca
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7b0e6982..91e7f059 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -47,10 +47,16 @@ version in [`docs/changelog/`](docs/changelog/):with no administrator rights. `ai-memory setup` now has a service step onWindows: it writes an `ai-memory` value under the per-user `Run` key thatstarts a hidden `ai-memory service-host` at logon, and starts it right away.+ The value is written and read through the registry API, not by running+ `reg.exe`: an unsigned binary running `reg.exe add` on the `Run` key is a+ common persistence signal, and Bitdefender's behavioral engine quarantined+ `ai-memory.exe` for it (#1280).The host runs the server with no console window and restarts it after afailure, giving up after five failures within ten seconds of starting.`ai-memory uninstall --apply` stops the host and removes the value when it- still has the shape `setup` writes. (#1271)+ still has the shape `setup` writes and names this install's data dir, so an+ uninstall against another data dir (a second install, a test's temporary+ one) leaves the entry alone. (#1271, #1280)- Added `ai-memory setup --web`, which shows the setup plan as a page inyour browser and applies the agents you tick there by running `ai-memorysetup --yes --agent ...` and streaming its output to the page. The page isdiff --git a/Cargo.lock b/Cargo.lockindex b71a4a02..236eabc8 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -82,6 +82,7 @@ dependencies = ["tracing-appender","tracing-subscriber","uuid",+ "windows-registry","zip",]@@ -805,7 +806,7 @@ dependencies = ["iana-time-zone","num-traits","serde",- "windows-link",+ "windows-link 0.2.1",][[package]]@@ -2233,7 +2234,7 @@ dependencies = ["simd_cesu8","thiserror 2.0.18","walkdir",- "windows-link",+ "windows-link 0.2.1",][[package]]@@ -2721,7 +2722,7 @@ dependencies = ["libc","redox_syscall","smallvec",- "windows-link",+ "windows-link 0.2.1",][[package]]@@ -4796,7 +4797,7 @@ checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d"dependencies = ["windows-implement","windows-interface",- "windows-result",+ "windows-result 0.1.2","windows-targets 0.52.6",]@@ -4828,6 +4829,23 @@ version = "0.2.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"+[[package]]+name = "windows-link"+version = "0.100.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9b39de7c7fe78858b0144c50c3fc000bab3be17d5e9b85b1053871693c7f7415"++[[package]]+name = "windows-registry"+version = "0.100.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a14b75dbbc0f2bb1ebbf6dcb6dc0035ae17f10ec280045d10fa27ad8874903b2"+dependencies = [+ "windows-link 0.100.0",+ "windows-result 0.100.0",+ "windows-strings",+]+[[package]]name = "windows-result"version = "0.1.2"@@ -4837,6 +4855,24 @@ dependencies = ["windows-targets 0.52.6",]+[[package]]+name = "windows-result"+version = "0.100.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "44873a1ef61c85d5e2991db91fe656cfcf0731097e00dff1ac860f1cb3b752a0"+dependencies = [+ "windows-link 0.100.0",+]++[[package]]+name = "windows-strings"+version = "0.100.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6a70b590c684f1d2854f74999896f7c0558f1bdde62f599088599e20ea1d2f60"+dependencies = [+ "windows-link 0.100.0",+]+[[package]]name = "windows-sys"version = "0.48.0"@@ -4870,7 +4906,7 @@ version = "0.61.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"dependencies = [- "windows-link",+ "windows-link 0.2.1",][[package]]@@ -4910,7 +4946,7 @@ version = "0.53.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"dependencies = [- "windows-link",+ "windows-link 0.2.1","windows_aarch64_gnullvm 0.53.1","windows_aarch64_msvc 0.53.1","windows_i686_gnu 0.53.1",diff --git a/crates/ai-memory-cli/Cargo.toml b/crates/ai-memory-cli/Cargo.tomlindex 7fca90da..bd874a05 100644--- a/crates/ai-memory-cli/Cargo.toml+++ b/crates/ai-memory-cli/Cargo.toml@@ -104,3 +104,6 @@ tokio = { workspace = true, features = ["test-util"] }[lints]workspace = true++[target."cfg(windows)".dependencies]+windows-registry = "0.100.0"diff --git a/crates/ai-memory-cli/src/commands/uninstall.rs b/crates/ai-memory-cli/src/commands/uninstall.rsindex 54edc483..d1d052cd 100644--- a/crates/ai-memory-cli/src/commands/uninstall.rs+++ b/crates/ai-memory-cli/src/commands/uninstall.rs@@ -913,7 +913,12 @@ fn setup_service(config: &Config) -> Option<(ServiceManager, user_service::Removlet path = user_service::unit_path(manager, &home, xdg_config_home.as_deref());Some((manager,- user_service::planned_removal_for(manager, &path, &user_service::SystemRunner),+ user_service::planned_removal_for(+ manager,+ &path,+ &config.data_dir,+ &user_service::SystemRunner,+ ),))}diff --git a/crates/ai-memory-cli/src/commands/user_service.rs b/crates/ai-memory-cli/src/commands/user_service.rsindex 0d424e10..a9758330 100644--- a/crates/ai-memory-cli/src/commands/user_service.rs+++ b/crates/ai-memory-cli/src/commands/user_service.rs@@ -401,14 +401,41 @@ pub(crate) fn is_setup_run_entry(data: &str) -> bool {&& !args.contains('|')}-/// The data of the `ai-memory` value under the `Run` key, read with-/// `reg query`; `None` when it is absent or cannot be read.+/// The `--data-dir` a `setup` logon entry names, unquoted the way+/// [`windows_arg`] quoted it; `None` when the entry names none.+fn run_entry_data_dir(data: &str) -> Option<String> {+ let rest = data.split_once(" --data-dir ")?.1.trim_start();+ let quoted = rest.strip_prefix('"')?;+ let (dir, _) = quoted.split_once('"')?;+ // `windows_arg` doubled the backslashes that end the path.+ let trailing = dir.len() - dir.trim_end_matches('\\').len();+ Some(dir[..dir.len() - trailing / 2].to_owned())+}++/// Whether two Windows paths name the same directory: the `\\?\` prefix,+/// trailing separators and letter case do not count.+fn same_windows_dir(left: &str, right: &str) -> bool {+ let plain = |path: &str| {+ let path = path.strip_prefix(r"\\?\").unwrap_or(path);+ path.trim_end_matches(['\\', '/']).replace('/', "\\")+ };+ plain(left).eq_ignore_ascii_case(&plain(right))+}++/// Whether the logon entry `data` is the one `setup` wrote for `data_dir`.+/// Another install's entry (a second data dir, a test's temporary one) has+/// the same shape and the same value name, and is not this uninstall's to+/// remove.+fn is_setup_run_entry_for(data: &str, data_dir: &Path) -> bool {+ is_setup_run_entry(data)+ && run_entry_data_dir(data)+ .is_some_and(|dir| same_windows_dir(&dir, &data_dir.to_string_lossy()))+}++/// The data of the `ai-memory` value under the `Run` key; `None` when it is+/// absent or cannot be read.pub(crate) fn run_value(runner: &dyn CommandRunner) -> Option<String> {- let outcome = runner- .run("reg", &["query", RUN_KEY, "/v", RUN_VALUE])- .ok()- .filter(|outcome| outcome.success)?;- parse_reg_query(&outcome.stdout, RUN_VALUE)+ runner.run_key_value()}/// Pick the data out of `reg query <key> /v <name>`, which prints the key,@@ -447,12 +474,90 @@ pub(crate) trait CommandRunner {fn run_launcher(&self, program: &str, args: &[&str]) -> Result<CommandOutcome> {self.run(program, args)}++ /// The `ai-memory` value under the `Run` key. The default asks+ /// `reg query`, which test doubles script; [`SystemRunner`] reads the+ /// registry directly on Windows.+ fn run_key_value(&self) -> Option<String> {+ let outcome = self+ .run("reg", &["query", RUN_KEY, "/v", RUN_VALUE])+ .ok()+ .filter(|outcome| outcome.success)?;+ parse_reg_query(&outcome.stdout, RUN_VALUE)+ }++ /// Write `data` as the `ai-memory` value under the `Run` key.+ fn set_run_key_value(&self, data: &str) -> Result<()> {+ require(+ self,+ "reg",+ &[+ "add", RUN_KEY, "/v", RUN_VALUE, "/t", "REG_SZ", "/d", data, "/f",+ ],+ )+ .map(drop)+ }++ /// Delete the `ai-memory` value under the `Run` key.+ fn delete_run_key_value(&self) -> Result<()> {+ require(self, "reg", &["delete", RUN_KEY, "/v", RUN_VALUE, "/f"]).map(drop)+ }}/// Runs commands for real, resolved through `PATH`.pub(crate) struct SystemRunner;+/// The `Run` key below `HKEY_CURRENT_USER`, as the registry API names it.+#[cfg(windows)]+const RUN_SUBKEY: &str = r"Software\Microsoft\Windows\CurrentVersion\Run";++/// String values under `HKEY_CURRENT_USER`, through the registry API.+#[cfg(windows)]+mod user_registry {+ use anyhow::{Context as _, Result};++ pub(super) fn get(subkey: &str, name: &str) -> Option<String> {+ windows_registry::CURRENT_USER+ .open(subkey)+ .and_then(|key| key.get_string(name))+ .ok()+ }++ pub(super) fn set(subkey: &str, name: &str, data: &str) -> Result<()> {+ windows_registry::CURRENT_USER+ .create(subkey)+ .and_then(|key| key.set_string(name, data))+ .with_context(|| format!(r"writing HKCU\{subkey}\{name}"))+ }++ pub(super) fn delete(subkey: &str, name: &str) -> Result<()> {+ windows_registry::CURRENT_USER+ .create(subkey)+ .and_then(|key| key.remove_value(name))+ .with_context(|| format!(r"deleting HKCU\{subkey}\{name}"))+ }+}+impl CommandRunner for SystemRunner {+ // Through the registry API, not `reg.exe`: an unsigned binary spawning+ // `reg.exe add …\CurrentVersion\Run` is a textbook persistence signal,+ // and Bitdefender's behavioral engine quarantined `ai-memory.exe` for it+ // (#1280).+ #[cfg(windows)]+ fn run_key_value(&self) -> Option<String> {+ user_registry::get(RUN_SUBKEY, RUN_VALUE)+ }++ #[cfg(windows)]+ fn set_run_key_value(&self, data: &str) -> Result<()> {+ user_registry::set(RUN_SUBKEY, RUN_VALUE, data)+ }++ #[cfg(windows)]+ fn delete_run_key_value(&self) -> Result<()> {+ user_registry::delete(RUN_SUBKEY, RUN_VALUE)+ }+fn run(&self, program: &str, args: &[&str]) -> Result<CommandOutcome> {let output = std::process::Command::new(program).args(args)@@ -545,21 +650,7 @@ fn install_windows(unit: &ServiceUnit, runner: &dyn CommandRunner) -> Result<Serreturn Ok(ServiceChange::Unchanged);}if !current {- require(- runner,- "reg",- &[- "add",- RUN_KEY,- "/v",- RUN_VALUE,- "/t",- "REG_SZ",- "/d",- &unit.contents,- "/f",- ],- )?;+ runner.set_run_key_value(&unit.contents)?;}super::service_host::stop(&host.state_file, runner)?;let exe = host.exe.to_string_lossy();@@ -597,7 +688,11 @@ fn write_unit(unit: &ServiceUnit) -> Result<()> {Ok(())}-fn require(runner: &dyn CommandRunner, program: &str, args: &[&str]) -> Result<CommandOutcome> {+fn require<R: CommandRunner + ?Sized>(+ runner: &R,+ program: &str,+ args: &[&str],+) -> Result<CommandOutcome> {let outcome = runner.run(program, args)?;if !outcome.success {bail!(@@ -698,6 +793,7 @@ pub(crate) enum Removal {pub(crate) fn planned_removal_for(manager: ServiceManager,path: &Path,+ data_dir: &Path,runner: &dyn CommandRunner,) -> Removal {if manager != ServiceManager::WindowsRun {@@ -705,7 +801,9 @@ pub(crate) fn planned_removal_for(}match run_value(runner) {None => Removal::Absent,- Some(data) if is_setup_run_entry(&data) => Removal::Removed(path.to_path_buf()),+ Some(data) if is_setup_run_entry_for(&data, data_dir) => {+ Removal::Removed(path.to_path_buf())+ }Some(_) => Removal::NotOurs(path.to_path_buf()),}}@@ -731,7 +829,7 @@ pub(crate) fn remove(data_dir: &Path,runner: &dyn CommandRunner,) -> Result<Removal> {- let planned = planned_removal_for(manager, path, runner);+ let planned = planned_removal_for(manager, path, data_dir, runner);if !matches!(planned, Removal::Removed(_)) {return Ok(planned);}@@ -758,7 +856,7 @@ pub(crate) fn remove(}ServiceManager::WindowsRun => {super::service_host::stop(&super::service_host::state_file(data_dir), runner)?;- require(runner, "reg", &["delete", RUN_KEY, "/v", RUN_VALUE, "/f"])?;+ runner.delete_run_key_value()?;}}Ok(planned)@@ -1251,24 +1349,45 @@ mod tests {assert_eq!(runner.calls.borrow().len(), 2);}- /// Uninstall removes only an entry `setup` wrote; someone else's value- /// under the same name is left, and an absent one is nothing to do.+ /// Uninstall removes only the entry `setup` wrote for this data dir;+ /// another install's entry, someone else's value under the same name, and+ /// an absent one are all left alone.#[test]fn uninstall_removes_only_setups_logon_entry() {let root = tempfile::tempdir().unwrap();let path = unit_path(ServiceManager::WindowsRun, root.path(), None);+ let data_dir = Path::new(r"C:\d");+ let entry = " ai-memory REG_SZ \"C:\\x\\ai-memory.exe\" --data-dir \"C:\\d\" \+ --config \"C:\\d\\config.toml\" service-host\r\n";let ours = FakeRunner {- stdout: vec![(- "reg query",- " ai-memory REG_SZ \"C:\\x\\ai-memory.exe\" --data-dir \"C:\\d\" \- --config \"C:\\d\\config.toml\" service-host\r\n",- )],+ stdout: vec![("reg query", entry)],..FakeRunner::default()};assert_eq!(- remove(ServiceManager::WindowsRun, &path, root.path(), &ours).unwrap(),+ remove(ServiceManager::WindowsRun, &path, data_dir, &ours).unwrap(),Removal::Removed(path.clone()));++ let other_install = FakeRunner {+ stdout: vec![("reg query", entry)],+ ..FakeRunner::default()+ };+ assert_eq!(+ remove(+ ServiceManager::WindowsRun,+ &path,+ root.path(),+ &other_install+ )+ .unwrap(),+ Removal::NotOurs(path.clone())+ );+ assert_eq!(+ other_install.calls.borrow().len(),+ 1,+ "only the query ran: {:?}",+ other_install.calls.borrow()+ );assert!(ours.calls.borrow()@@ -1323,6 +1442,59 @@ mod windows_entry_tests {assert!(windows_arg("data dir", r#"C:\a"b"#).is_err());}+ /// The data dir comes back out of an entry exactly as `windows_arg` put+ /// it in, trailing backslashes included.+ #[test]+ fn the_entry_names_its_data_dir() {+ for dir in [+ r"C:\Users\me\AppData\Local\ai-memory",+ r"D:\",+ r"C:\with space\d",+ ] {+ let entry = format!(+ "{} --data-dir {} --config {} {SERVICE_HOST}",+ windows_arg("binary", r"C:\bin\ai-memory.exe").unwrap(),+ windows_arg("data dir", dir).unwrap(),+ windows_arg("config", r"C:\c.toml").unwrap(),+ );+ assert_eq!(run_entry_data_dir(&entry).as_deref(), Some(dir), "{entry}");+ }+ assert_eq!(+ run_entry_data_dir(r#""C:\bin\ai-memory.exe" service-host"#),+ None+ );+ }++ #[test]+ fn data_dirs_compare_without_prefix_case_or_trailing_separator() {+ assert!(same_windows_dir(+ r"\\?\C:\Users\Me\AppData\Local\ai-memory",+ r"c:\users\me\appdata\local\ai-memory\"+ ));+ assert!(!same_windows_dir(r"C:\a\ai-memory", r"C:\b\ai-memory"));+ assert!(!same_windows_dir(r"C:\ai-memory", r"C:\ai-memory-test"));+ }++ /// The test that found this: an `uninstall` run against a temporary data+ /// dir removed the developer's own logon entry, because every entry with+ /// `setup`'s shape counted as ours.+ #[test]+ fn only_the_entry_for_this_data_dir_is_ours() {+ let entry = r#""C:\bin\ai-memory.exe" --data-dir "\\?\C:\Users\me\AppData\Local\ai-memory" --config "C:\c.toml" service-host"#;+ assert!(is_setup_run_entry_for(+ entry,+ Path::new(r"C:\Users\me\AppData\Local\ai-memory")+ ));+ assert!(!is_setup_run_entry_for(+ entry,+ Path::new(r"C:\Users\me\AppData\Local\Temp\.tmpAbC123\data")+ ));+ assert!(!is_setup_run_entry_for(+ r#""C:\bin\ai-memory.exe" service-host"#,+ Path::new(r"C:\Users\me\AppData\Local\ai-memory")+ ));+ }+#[test]fn reg_query_output_yields_the_value_data() {let out = "\r\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\r\n \@@ -1388,3 +1560,27 @@ mod windows_entry_tests {);}}++/// The registry calls the logon entry goes through, against a throwaway key:+/// the real `Run` key is never touched.+#[cfg(all(test, windows))]+mod user_registry_tests {+ use super::user_registry;++ #[test]+ fn a_value_round_trips_and_deleting_it_leaves_nothing() {+ let subkey = format!(r"Software\ai-memory-tests\{}", uuid::Uuid::new_v4());+ let data = r#""C:\Program Files\ai memory\ai-memory.exe" --data-dir "C:\d\\" service-host"#;+ assert_eq!(user_registry::get(&subkey, "ai-memory"), None);++ user_registry::set(&subkey, "ai-memory", data).unwrap();+ assert_eq!(+ user_registry::get(&subkey, "ai-memory").as_deref(),+ Some(data)+ );++ user_registry::delete(&subkey, "ai-memory").unwrap();+ assert_eq!(user_registry::get(&subkey, "ai-memory"), None);+ windows_registry::CURRENT_USER.remove_tree(&subkey).unwrap();+ }+}diff --git a/docs/security-boundaries.md b/docs/security-boundaries.mdindex e8b77bf3..cd3770f1 100644--- a/docs/security-boundaries.md+++ b/docs/security-boundaries.md@@ -110,7 +110,7 @@ means the boundary is not built yet.| 15 | Agent-archive restore path confinement, resource bounds, and consistency | `ai-memory-cli/src/commands/restore_agents.rs` stages only bounded regular UTF-8 entries; requires a one-to-one manifest/body/checksum/target mapping; allowlists destinations by scope; rejects symlinked descendants; writes each file atomically and rolls back earlier writes after a later failure. `backup_agents.rs` skips direct and directory-root source symlinks, bounds individual assets, and atomically replaces a private archive only after gzip completion | `backup_agents.rs` `restore_agents_rejects_path_traversal`, `restore_agents_rejects_unauthorized_destination_path`, `restore_agents_verifies_sha256_integrity`, `restore_agents_requires_a_complete_one_to_one_manifest`, `restore_agents_rejects_oversized_entries_from_the_header`, `restore_agents_rejects_a_symlinked_destination_parent`, `backup_agents_does_not_follow_config_or_asset_root_symlinks`, and `failed_backup_leaves_the_previous_archive_intact`; `backup_and_restore_agents_round_trip` is the valid-path control; `restore_agents::tests::rollback_removes_new_files_and_restores_overwrites` covers recovery | STRONG || 16 | Relay queue identity, migration, and private filesystem state | `companions/ai-memory-relay/src/queue.rs` `Queue::open_inner` performs read-only identity preflight, rechecks under `IMMEDIATE`, commits schema and metadata together; `configure` checks the presence of user objects and rechecks `identity`/`schema_version` metadata on the same connection before every bounded BUSY/LOCKED retry; `fsguard.rs` checks existing paths and creates owner-only files before SQLite opens them | `tests/relay.rs` `a_foreign_database_is_refused_byte_for_byte`, `unknown_schemas_refuse_without_mutation`, `a_foreign_database_with_a_writer_is_refused_before_write_coordination`, `a_foreign_identity_after_preflight_is_refused_without_mutation`, `a_foreign_identity_during_journal_retry_is_refused_without_mutation`, `journal_retry_refuses_a_changed_version_or_empty_database_without_mutation`; controls: `journal_transition_retries_sqlite_lock_without_losing_v1_values`, `fresh_queue_init_and_v1_reopens_work_across_processes`; recovery: `interrupted_and_failed_migrations_roll_back_and_recover`, `journal_reclassification_busy_preserves_committed_migration_and_retries_same_queue`; diagnostics: `classification_read_failures_display_the_sqlite_cause_once_and_preserve_foreign_bytes`; Unix privacy: `the_queue_database_and_its_sidecars_are_owner_only` and the contended migration control | Guard-removal proof covers preflight, locked recheck, and journal retry identity/version checks; full table structure is outside this classification. Windows path rejection is preserved; Windows ACL hardening remains operator-owned || 17 | `ai-memory setup --web` local wizard: only the page this process printed can read the plan or apply a setup | `ai-memory-cli/src/commands/setup_web.rs` `guard` (binds `127.0.0.1` on an OS-picked port; every request needs a `Host` of exactly `127.0.0.1:<port>` or `localhost:<port>` and the one-time 256-bit path secret, compared with `subtle`; a POST also needs this page's `Origin` and the CSRF token the page reads from its own JSON; no CORS grant; `no-store`, `no-referrer`, `DENY` framing, and a CSP with a per-run nonce and no outside sources on the page) and `apply` (agent names must be `--agent` values, de-duplicated, at least one; the child is always `ai-memory setup --yes --agent ...` with the wizard's own flags, never a caller-chosen argument) | `setup_web.rs` `the_page_is_served_only_to_our_host_and_secret` (a rebinding `Host`, a bare `127.0.0.1`, another port, a wrong secret and a missing one refused; controls: `127.0.0.1` and `localhost` with the secret), `apply_refuses_cross_site_and_unknown_input_and_starts_nothing` (no `Origin`, a foreign `Origin`, no CSRF token and a wrong one each refused; `--force`, a shell-like name and an empty choice refused; no child starts), `apply_runs_setup_with_the_picked_agents_and_streams_its_output` (legitimate control: exact argument list); `tests/suite/setup_e2e.rs` `setup_web_serves_the_plan_and_applies_the_picked_agent` (the same through the binary); bite-checked by removing the `Host` check, the `Origin` check, the CSRF check and the agent allowlist one at a time | STRONG |-| 18 | `uninstall` removes only a service `setup` wrote, including the Windows logon entry | `ai-memory-cli/src/commands/user_service.rs` `planned_removal` / `is_rendered_by_setup` (a unit file whose identity digest still matches) and `planned_removal_for` / `is_setup_run_entry` (a `HKCU\...\Run\ai-memory` value that is a quoted `ai-memory.exe` ending in `service-host`, with no `&` or `|` chaining) before `remove` stops anything or deletes it | `user_service.rs` `uninstall_removes_only_setups_logon_entry` (another program's value under the same name is left with only the query run; absent value is nothing to do; control: setup's value is deleted with `reg delete`), `only_setups_entry_shape_counts_as_ours` (unquoted, other program, `serve`, `&`/`|` chaining all refused), and the unit-file identity tests in the same module | STRONG |+| 18 | `uninstall` removes only a service `setup` wrote, including the Windows logon entry | `ai-memory-cli/src/commands/user_service.rs` `planned_removal` / `is_rendered_by_setup` (a unit file whose identity digest still matches) and `planned_removal_for` / `is_setup_run_entry_for` (a `HKCU\...\Run\ai-memory` value that is a quoted `ai-memory.exe` ending in `service-host`, with no `&` or `|` chaining, whose `--data-dir` is the data dir being uninstalled) before `remove` stops anything or deletes it | `user_service.rs` `uninstall_removes_only_setups_logon_entry` (another install's entry, naming a different `--data-dir`, is left with only the query run; another program's value under the same name is left; absent value is nothing to do; control: this data dir's entry is deleted), `only_the_entry_for_this_data_dir_is_ours` (a temporary data dir does not claim the operator's entry, #1280), `only_setups_entry_shape_counts_as_ours` (unquoted, other program, `serve`, `&`/`|` chaining all refused), and the unit-file identity tests in the same module | STRONG |## Keeping this current (the standing protocol)diff --git a/docs/windows.md b/docs/windows.mdindex d4592f5f..cae2d513 100644--- a/docs/windows.md+++ b/docs/windows.md@@ -367,8 +367,15 @@ The host records its own process id and the server's inrunning host alone; a changed entry is rewritten and the host restarted.`ai-memory uninstall --apply` stops the host and deletes the value, but onlywhen the value still has the shape `setup` writes (a quoted `ai-memory.exe`-ending in `service-host`); a value someone else put under the same name is-left in place.+ending in `service-host`) and its `--data-dir` is the data dir being+uninstalled; a value someone else put under the same name, or the entry of+another install, is left in place.++`setup` and `uninstall` read and write the value through the registry API+rather than running `reg.exe`. Endpoint protection that watches for+persistence (Bitdefender's Advanced Threat Control, for one) treats an+unsigned program running `reg.exe add` on the `Run` key as malicious and+quarantines it (#1280).The logon entry runs only while you are signed in, which matches a systemduser unit without lingering and a macOS LaunchAgent. For a server that runs