Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
feat(run): name defined profiles on an unknown --profile
AkitaOnRailse0f234573c70
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ce893e3d..e0b5a1d6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -19,7 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0`[run.profiles.<name>.env]` in `config.toml`. Profile values feed the samenative-session, auto-wire, and child-process environment path as `--env`;precedence is profile, then `--env-file`, then repeated `--env`. Unknown or- invalid profiles fail before a workstream lease or child process. (#922)+ invalid profiles fail before a workstream lease or child process; an unknown+ name lists the defined profiles or prints a table to paste. (#922; error+ message, tests and docs from #1031 by @geeksilva97)- Added cross-project attribution for native lifecycle file-tool events whoseharness keeps reporting the parent session's cwd. A bounded, recognizedabsolute target reroutes only when every path proves the same repository ordiff --git a/crates/ai-memory-cli/src/commands/run.rs b/crates/ai-memory-cli/src/commands/run.rsindex b68ef921..3572ed88 100644--- a/crates/ai-memory-cli/src/commands/run.rs+++ b/crates/ai-memory-cli/src/commands/run.rs@@ -340,7 +340,7 @@ async fn run_once_with_wiring(.run.profiles.get(name)- .ok_or_else(|| anyhow!("unknown run profile {name:?}"))+ .ok_or_else(|| unknown_run_profile(&config.run, name))}).transpose()?;let run_env = resolve_run_env(profile, args.env_file.as_deref(), &args.env)@@ -1844,6 +1844,26 @@ fn remove_wrapper_no_autowire(args: &mut Vec<OsString>) -> bool {args.len() != before}+/// The error for a `--profile` name `config.toml` does not define: it names+/// the profiles that do exist, or, with none defined, prints a table to paste.+fn unknown_run_profile(run: &crate::config::RunSettings, name: &str) -> anyhow::Error {+ if !run.profiles.is_empty() {+ let known = run.profiles.keys().map(String::as_str).collect::<Vec<_>>();+ return anyhow!(+ "unknown run profile {name:?}; defined profiles: {}",+ known.join(", ")+ );+ }+ // Quoted when needed: a valid profile name may contain `.`, which a bare+ // TOML key would split into nested tables.+ let key = toml_edit::Key::new(name);+ anyhow!(+ "unknown run profile {name:?}; none are defined. Add to your config.toml:\n\n \+ [run.profiles.{}.env]\n CLAUDE_CONFIG_DIR = \"/absolute/path\"",+ key.display_repr()+ )+}+/// Merge `--env-file` lines with `--env` entries into the final key/value/// list applied to the spawned harness, preserving file order but letting a/// `--env` entry override a same-key `--env-file` line. Values are taken@@ -4467,12 +4487,15 @@ mod tests {assert_eq!(wrapper.profile.as_deref(), Some("work"));assert_eq!(wrapper.native_args, ["--model", "opus"].map(OsString::from));- let native = parse_run(&["ai-memory", "run", "omp", "--profile", "omp-work"]);- assert_eq!(native.profile, None);- assert_eq!(- native.native_args,- ["--profile", "omp-work"].map(OsString::from)- );+ for (harness, native_profile) in [("omp", "omp-work"), ("codex", "codex-work")] {+ let native = parse_run(&["ai-memory", "run", harness, "--profile", native_profile]);+ assert_eq!(native.profile, None, "{harness}");+ assert_eq!(+ native.native_args,+ ["--profile", native_profile].map(OsString::from),+ "{harness}'s own --profile must reach the child"+ );+ }}#[tokio::test]@@ -4508,7 +4531,34 @@ mod tests {).await.unwrap_err();- assert_eq!(error.to_string(), "unknown run profile \"missing\"");+ assert_eq!(+ error.to_string(),+ "unknown run profile \"missing\"; none are defined. Add to your config.toml:\n\n \+ [run.profiles.missing.env]\n CLAUDE_CONFIG_DIR = \"/absolute/path\""+ );+ }++ #[test]+ fn unknown_run_profile_names_the_defined_profiles_in_sorted_order() {+ let mut run = crate::config::RunSettings::default();+ for name in ["work", "personal"] {+ run.profiles+ .insert(name.into(), crate::config::RunProfile::default());+ }+ assert_eq!(+ unknown_run_profile(&run, "wrok").to_string(),+ "unknown run profile \"wrok\"; defined profiles: personal, work"+ );+ }++ #[test]+ fn unknown_run_profile_hint_quotes_a_dotted_name_as_one_toml_key() {+ let hint =+ unknown_run_profile(&crate::config::RunSettings::default(), "work.v2").to_string();+ assert!(+ hint.contains("[run.profiles.\"work.v2\".env]"),+ "a bare dotted key would paste as nested tables: {hint}"+ );}#[test]@@ -5364,6 +5414,85 @@ mod tests {server.abort();}+ /// Two accounts of one harness on one machine: each `--profile` must reach+ /// the child and auto-wire its own config home on its own first launch.+ /// The autowire sentinel is keyed by install target, so the second+ /// profile is not skipped as "already wired" by the first.+ #[cfg(unix)]+ #[tokio::test]+ async fn each_run_profile_launches_and_autowires_its_own_config_home() {+ use crate::commands::run_autowire::WireOverrides;++ let (address, server) = mock_workstream_server(None).await;+ let home = tempfile::tempdir().unwrap();+ let data = tempfile::tempdir().unwrap();+ let repo = tempfile::tempdir().unwrap();+ let (script, captured) = capture_env_script(repo.path(), "CLAUDE_CONFIG_DIR");+ let work_home = data.path().join("claude-work");+ let personal_home = data.path().join("claude-personal");+ for dir in [&work_home, &personal_home] {+ std::fs::create_dir_all(dir).unwrap();+ }++ let mut config = launch_config(home.path(), data.path(), address);+ for (name, dir) in [("work", &work_home), ("personal", &personal_home)] {+ config.run.profiles.insert(+ name.to_string(),+ crate::config::RunProfile {+ env: [("CLAUDE_CONFIG_DIR".to_string(), dir.display().to_string())].into(),+ },+ );+ }+ let overrides = WireOverrides {+ hooks_dir: Some(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../hooks")),+ confine_to: Some(data.path().to_path_buf()),+ ..WireOverrides::default()+ };++ for (name, dir, other) in [+ ("work", &work_home, &personal_home),+ ("personal", &personal_home, &work_home),+ ] {+ let mut args = run_args(+ RunHarnessChoice::Claude,+ script.clone(),+ vec![],+ &["--version"],+ );+ args.profile = Some(name.to_string());+ let other_before = std::fs::read_dir(other).unwrap().count();+ let exit = run_from_with_wiring(&config, args, repo.path(), &overrides)+ .await+ .unwrap_or_else(|error| panic!("profile {name} run fails: {error:#}"));+ assert_eq!(exit, 0);+ assert_eq!(+ std::fs::read_to_string(&captured).unwrap(),+ dir.display().to_string(),+ "profile {name} must reach the spawned child"+ );+ let settings = dir.join("settings.json");+ assert!(+ std::fs::read_to_string(&settings)+ .is_ok_and(|s| s.contains("ai-memory") || s.contains("ai_memory")),+ "profile {name}: hooks missing in {}",+ settings.display()+ );+ let mcp = dir.join(".claude.json");+ assert!(+ std::fs::read_to_string(&mcp).is_ok_and(|s| s.contains("ai-memory")),+ "profile {name}: MCP missing in {}",+ mcp.display()+ );+ assert_eq!(+ std::fs::read_dir(other).unwrap().count(),+ other_before,+ "profile {name} must not wire the other account's config home"+ );+ }++ server.abort();+ }+/// A Kiro v3 session stored under the default home is resumed with/// `KIRO_HOME` removed from the child, so auto-wire must wire that default/// home. Wiring the `--env` home instead left the resumed session with nodiff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdindex 6d5b63dd..645ddcb8 100644--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@ -747,6 +747,15 @@ release_base_url = "" # override the GitHub releases base URL that# For hermetic tests / mirrors, not day-to-day installs.# Env: AI_MEMORY_RELEASE_BASE_URL.+[run.profiles.work.env] # env-only launch profile for `ai-memory run --profile+CLAUDE_CONFIG_DIR = "/home/me/.claude-work" # work <harness>` (#922): same reach as+ # `--env` (child, native-session lookup, auto-wire),+ # layered under `--env-file` and `--env`. Values are+ # literal (use absolute paths); names and keys are+ # validated at load, and an unknown name fails before+ # lease, auto-wire or launch. TOML only: the+ # AI_MEMORY_* overlay lowercases env-derived keys.+[maintenance] # scheduled server jobs (run outside hook latency)enabled = true # master switch for the scheduled jobs belowforget_sweep_interval_secs = 86400 # retention forget sweep; 0 disables. Cadence persistsdiff --git a/docs/cookbook.md b/docs/cookbook.mdindex bb141562..1b2bfc06 100644--- a/docs/cookbook.md+++ b/docs/cookbook.md@@ -151,6 +151,19 @@ ai-memory run --env CODEX_HOME="$HOME/.codex-work" codex # the dir must exist(provider keys, an account's config dir) can write it to a file and pass`--env-file <path>`, one `KEY=VALUE` per line. Values are taken literally, souse absolute paths in the file.+- To name an account once instead of repeating `--env`, add a profile to+ `config.toml` and select it with `--profile` (before the harness name):++ ```toml+ [run.profiles.work.env]+ CLAUDE_CONFIG_DIR = "/home/me/.claude-work"+ ```++ Then `ai-memory run --profile work claude`. Use absolute paths: profile+ values are not expanded. `--env-file` and `--env` still override a profile+ entry, and an unknown name fails before anything is wired or launched. A+ `--profile` after the harness name belongs to the harness (OMP and Codex+ have their own).- Auto-wire runs once per config home, so the second account gets its hooks +MCP on its own first launch. To wire one by hand, export the variable for theinstallers: `CLAUDE_CONFIG_DIR="$HOME/.claude-work" ai-memory install-hooks