Skip to content

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

Rust

Merge audited PR #1492

AkitaOnRails7f5907465a87
diff --cc CHANGELOG.md
index 46e233d9,69ca4849..c82ecdb8
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -11,48 -11,17 +11,58 @@@ version in [`docs/changelog/`](docs/cha
## [Unreleased]
+### Security
+- Updated `rustls-webpki` 0.103.15 → 0.103.16 for
+ [RUSTSEC-2026-0382](https://rustsec.org/advisories/RUSTSEC-2026-0382), in
+ which certificate verification may accept distrusted intermediates, and
+ `webpki-root-certs` 1.0.9 → 1.0.10 for
+ [RUSTSEC-2026-0383](https://rustsec.org/advisories/RUSTSEC-2026-0383), whose
+ bundled roots still trusted distrusted emSign intermediates. The importer,
+ relay and wiki sync companions take the same `rustls-webpki` bump.
+
### Fixed
+- Held `ai-memory run` heartbeat notices while the harness owns the terminal
+ and printed them after it exits, so a server outage no longer writes into the
+ harness TUI. Only the first and latest notices are replayed, with a count of
+ the rest.
+ ([#1500](https://github.com/akitaonrails/ai-memory/issues/1500))
+
+- Dropped stopwords from the quoted bag of words a search falls back to when
+ its text looks like FTS5 syntax but does not parse, such as a question
+ ending in `(prod)`. The fallback OR-joined `what`, `is`, `the` and `of`
+ with the content words; it now filters through the configured
+ `[search.fts] stopwords` list like a bare query, keeps the words the user
+ quoted, and keeps every word when all of them are stopwords.
+
+- Corrected `docs/lifecycle-ops.md` on two points. The `move-project` merge
+ drops everything the source project owns, the same set `purge-project`
+ deletes. This includes managed workstreams, cross-project messages,
+ auto-improvement and profile-harvest state, consolidation jobs, ingest keys,
+ entities, page feedback, purge tombstones and project grants as well as
+ sessions, observations and handoffs. The `400` for sending both a project
+ name and an id, or neither, applies to the admin endpoints; the CLI resolves
+ a missing project from the marker, the git remote, then the directory name.
+ ([#1493](https://github.com/akitaonrails/ai-memory/issues/1493))
+
+- Named the install's data dir in the `mcp-bridge` entries `install-mcp`
+ writes for Claude Code and the session-less stdio bridge when the install
+ was given one (`--data-dir`, `AI_MEMORY_DATA_DIR` or `data_dir` in the
+ config), as Muse's entry and the install's hooks already did. The bridge
+ read the default data dir's config and token instead, so on a host whose
+ server uses the default data dir it authenticated with the server's root
+ bearer.
+ ([#1489](https://github.com/akitaonrails/ai-memory/issues/1489))
+
+ - Let `ai-memory mcp-bridge` send the key `install-hooks --apply --auth-token`
+ stored in `<data_dir>/auth-token` when no bearer is configured, ahead of the
+ loopback root token discovery, so a remote
+ client whose hooks hold a native API key wires the MCP bridge without
+ copying the key. `install-mcp --apply --auth-token` now stores the key there
+ for the Claude Code (`--session-aware`) and Muse bridge entries and leaves
+ it out of the harness config, where it outlived a key rotation; existing
+ entries keep working. `uninstall --only hooks` keeps the stored key while
+ such a bridge entry remains. ([#1490](https://github.com/akitaonrails/ai-memory/issues/1490))
+
## [3.1.2] - 2026-10-20
### Fixed
diff --cc crates/ai-memory-cli/src/commands/install_mcp.rs
index 4f9c2cda,5f6b3b3b..4d5385a1
--- a/crates/ai-memory-cli/src/commands/install_mcp.rs
+++ b/crates/ai-memory-cli/src/commands/install_mcp.rs
@@@ -128,21 -138,31 +130,46 @@@ pub(crate) fn run_with_opencode_dialect
{
route_file_token(&mut args, token_file)?;
}
+ // The bridge loads its config and token from a data dir the way any CLI
+ // call does. Muse starts stdio servers with a cleared environment (`HOME`,
+ // `PATH` and its own `MUSE_SESSION_ID`), so its bridge finds this install
+ // only through an explicit `--data-dir`, as the Muse hooks do. Any other
+ // bridge needs it when this install was given a data dir: the hooks name
+ // that dir, and a bridge without it would read the default one, with its
+ // own config and bearer. Not from inside the Docker helper, whose data dir
+ // is a container path the host-side bridge cannot open.
+ let runs_bridge =
+ (args.client == McpClient::ClaudeCode && args.session_aware) || args.stdio_bridge;
+ if config.runtime_env.host_cwd().is_none()
+ && (args.client == McpClient::Muse || (runs_bridge && config.data_dir_explicit))
+ {
+ args.bridge_data_dir = Some(config.data_dir.clone());
+ }
+ // An explicit `--auth-token` for an entry that runs `mcp-bridge` goes where
+ // the hooks keep theirs, `<data_dir>/auth-token`, and the bridge reads it
+ // from there when nothing else is configured. Inline in the harness config
+ // it would sit outside the data dir's protection and outlive a rotation,
+ // the reasons #552 moved the hooks' copy. The entry then names that data
+ // dir, so the bridge reads the file the key went into. Only `--apply`
+ // stores, as with `install-hooks`: a printed snippet is the operator's to
+ // place. The key stays inline, as before, whenever the bridge would not
+ // reach it: a bearer this config is configured with would win over it, a
+ // different key already stored belongs to the hooks, the store failed, or
+ // this is the Docker helper, whose data dir the host-side bridge cannot
+ // open.
+ let bridge_carries_token = matches!(args.client, McpClient::Muse)
+ || (args.client == McpClient::ClaudeCode && args.session_aware);
+ if args.apply
+ && token_given
+ && bridge_carries_token
+ && config.auth.configured_bearer_token().is_none()
+ && config.runtime_env.host_cwd().is_none()
+ && let Some(token) = args.auth_token.as_deref()
+ && store_bridge_key(&config.data_dir, token)
+ {
+ args.auth_token = None;
+ args.bridge_data_dir = Some(config.data_dir.clone());
+ }
validate_args(&args)?;
if args.apply {
return apply_to_config_file(&args);
@@@ -4318,62 -4387,102 +4407,158 @@@ mod tests
assert!(!text.contains(FILE_TOKEN), "{text}");
}
+ /// Every bridge entry names a data dir the install was given, as the
+ /// install's hooks do, so the bridge reads that install's config and
+ /// bearer rather than the default data dir's. Controls: a default install
+ /// keeps its entries unchanged (only Muse, which clears the environment,
+ /// names the dir regardless), and the Docker helper, whose data dir is a
+ /// container path, names it for no client.
+ #[test]
+ fn bridge_entries_name_a_data_dir_the_install_was_given() {
+ let tmp = tempfile::tempdir().unwrap();
+ let data_dir = tmp.path().join("client-data");
+ let marker = data_dir.to_string_lossy().into_owned();
+ let installed = |config: &Config, label: &str| {
+ let mut bridges = 0;
+ for &client in <McpClient as clap::ValueEnum>::value_variants() {
+ if matches!(client, McpClient::Pi | McpClient::Dsh | McpClient::Zcode) {
+ continue; // no config file, print-only, and HTTP-only
+ }
+ let ext = if matches!(client, McpClient::Codex | McpClient::Grok) {
+ "toml"
+ } else {
+ "json"
+ };
+ let file = tmp.path().join(format!("{label}-{client:?}.{ext}"));
+ apply_with(config, client, &file).unwrap_or_else(|e| panic!("{client:?}: {e:#}"));
+ let text = std::fs::read_to_string(&file).unwrap();
+ if text.contains("mcp-bridge") {
+ bridges += 1;
+ }
+ let names_dir = text.contains("--data-dir") && text.contains(marker.as_str());
+ let expected = match label {
+ "explicit" => text.contains("mcp-bridge"),
+ "default" => client == McpClient::Muse,
+ _ => false,
+ };
+ assert_eq!(names_dir, expected, "{label} {client:?}: {text}");
+ }
+ assert!(
+ bridges > 2,
+ "{label}: too few bridge entries to prove anything"
+ );
+ };
+
+ let mut explicit = file_token_config(&data_dir);
+ explicit.data_dir = data_dir.clone();
+ explicit.data_dir_explicit = true;
+ installed(&explicit, "explicit");
+
+ let mut default = explicit.clone();
+ default.data_dir_explicit = false;
+ installed(&default, "default");
+
+ let mut docker = explicit.clone();
+ docker.runtime_env = crate::config::RuntimeEnv::with_host_cwd_for_tests("/host/repo");
+ installed(&docker, "docker");
+ }
+
+ /// An explicit `--auth-token` for an entry that runs the bridge is stored
+ /// in `<data_dir>/auth-token`, where the bridge reads it, and the entry
+ /// names that data dir instead of carrying the key. Controls, each of
+ /// which keeps the key inline as before and stores nothing new: the print
+ /// path, a bearer the config already resolves (it would win over the
+ /// stored key), a different key already stored for the hooks, hooks that
+ /// sign in with OIDC, the Docker helper, and an HTTP entry, whose literal
+ /// header is documented.
+ #[test]
+ fn an_explicit_key_for_a_bridge_is_stored_instead_of_written_inline() {
+ const KEY: &str = "aim_explicit_key";
+ let tmp = tempfile::tempdir().unwrap();
+ let config_in = |name: &str| Config {
+ data_dir: tmp.path().join(name),
+ ..Config::default()
+ };
+ let install = |config: &Config, client: McpClient, apply: bool| -> String {
+ let file = config.data_dir.with_extension(format!("{client:?}.json"));
+ let mut args = args_for(client);
+ args.apply = apply;
+ args.config_file = Some(file.clone());
+ args.session_aware = client == McpClient::ClaudeCode;
+ args.auth_token = Some(KEY.into());
+ run_with_opencode_dialect(config, args, None).unwrap();
+ std::fs::read_to_string(&file).unwrap_or_default()
+ };
+ let stored = |config: &Config| crate::config::read_hook_auth_token(&config.data_dir);
+
+ for client in [McpClient::ClaudeCode, McpClient::Muse] {
+ let config = config_in(&format!("stored-{client:?}"));
+ let text = install(&config, client, true);
+ assert!(
+ !text.contains(KEY),
+ "{client:?} entry still carries the key: {text}"
+ );
+ assert!(!text.contains("AI_MEMORY_AUTH_TOKEN"), "{client:?}: {text}");
+ assert!(text.contains("--data-dir"), "{client:?}: {text}");
+ assert!(
+ text.contains(config.data_dir.to_string_lossy().as_ref()),
+ "{client:?} entry must name the dir the key went into: {text}"
+ );
+ assert_eq!(stored(&config).as_deref(), Some(KEY), "{client:?}");
+ // The shell hooks read the header file of the same pair.
+ assert_eq!(
+ std::fs::read_to_string(crate::config::hook_auth_header_path_in(&config.data_dir))
+ .unwrap(),
+ format!("Authorization: Bearer {KEY}\n")
+ );
+ }
+
+ let printed = config_in("printed");
+ install(&printed, McpClient::ClaudeCode, false);
+ assert_eq!(
+ stored(&printed),
+ None,
+ "a printed snippet must store nothing"
+ );
+
+ let mut configured = config_in("configured");
+ configured.auth.bearer_token = Some("configured-bearer".into());
+ assert!(install(&configured, McpClient::ClaudeCode, true).contains(KEY));
+ assert_eq!(stored(&configured), None);
+
+ let other = config_in("other");
+ crate::config::store_hook_auth_token(&other.data_dir, "aim_hooks_key").unwrap();
+ assert!(install(&other, McpClient::ClaudeCode, true).contains(KEY));
+ assert_eq!(stored(&other).as_deref(), Some("aim_hooks_key"));
+
+ let oidc = config_in("oidc");
+ let response = ai_memory_llm::OidcTokenResponse {
+ access_token: "oidc-access".into(),
+ refresh_token: Some("oidc-refresh".into()),
+ expires_in: None,
+ };
+ std::fs::create_dir_all(&oidc.data_dir).unwrap();
+ ai_memory_llm::OidcToken::from_token_response(&response, "iss", "cid", "ep", None)
+ .unwrap()
+ .save(&oidc.data_dir.join("auth.json"))
+ .unwrap();
+ assert!(install(&oidc, McpClient::ClaudeCode, true).contains(KEY));
+ assert_eq!(
+ stored(&oidc),
+ None,
+ "OIDC hooks must not be switched to the key"
+ );
+
+ let mut docker = config_in("docker");
+ docker.runtime_env = crate::config::RuntimeEnv::with_host_cwd_for_tests("/host/repo");
+ assert!(install(&docker, McpClient::ClaudeCode, true).contains(KEY));
+ assert_eq!(stored(&docker), None);
+
+ let http = config_in("http");
+ assert!(install(&http, McpClient::Cursor, true).contains(&format!("Bearer {KEY}")));
+ assert_eq!(stored(&http), None);
+ }
+
#[test]
fn mcp_server_url_defaults_to_configured_server_url() {
let config = Config {
diff --cc docs/mcp-install.md
index d659e295,9189fbf6..f92ef74f
--- a/docs/mcp-install.md
+++ b/docs/mcp-install.md
@@@ -25,13 -25,20 +25,24 @@@ Warp, Cline, Kilo Code, Goose, Qwen Cod
> the token file at launch and forwards no session id, so the client passes
> `workspace` and `project` like any static client. Stdio entries name the
> `ai-memory` binary by its absolute path, so the client does not need it on
-> its `PATH`; the Docker wrapper keeps the bare `ai-memory`. ZCode keeps
+> its `PATH`; the Docker wrapper keeps the bare `ai-memory`. When the install
+> was given a data dir (`--data-dir`, `AI_MEMORY_DATA_DIR` or `data_dir` in
+> the config), every bridge entry names it with `--data-dir`, as that
+> install's hooks do, so the bridge reads that install's config and token
+> rather than the default data dir's. ZCode keeps
> HTTP entries only and is refused. Passing `--auth-token` explicitly (or
> `AI_MEMORY_AUTH_TOKEN`) keeps the HTTP snippets below, header included.
+ > The two entries that run the bridge with an explicit key are the
+ > exception: `install-mcp --apply --auth-token <key>` for Claude Code with
+ > `--session-aware`, and for Muse, stores the key in `<data_dir>/auth-token`,
+ > the file `install-hooks --apply --auth-token` writes, and writes the entry
+ > with `--data-dir` and no key. The bridge reads that file whenever no
+ > bearer is configured, ahead of the root token it discovers on a loopback
+ > install, so a client whose hooks already hold a key needs no
+ > `--auth-token` here at all, and rotating the key with `install-hooks` also
+ > rotates the bridge's. The key stays in the entry, as before, when the
+ > config already resolves a bearer, a different key is stored, the hooks
+ > sign in with OIDC, or the snippet is only printed.
> **Transport is stateless by default.** Since v0.1.2 the HTTP transport
> answers each request independently (plain JSON, no `Mcp-Session-Id`