Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
chore(run): move the Kiro v3 resume auto-wire to its own change
Éverton Toffanettoa4e72075b3d1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4b9bbf32..c06607f8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -227,9 +227,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0They now find the store as Crush does: `options.data_directory` from Crush'sJSON configs, else the closest `.crush` up to the git worktree root (not onedirectly in the home), else `<cwd>/.crush`. (#820)-- A Kiro v3 resume that falls back to the default session store drops- `KIRO_HOME` from the child, but auto-wire still installed hooks and MCP- under `KIRO_HOME`; it now wires the default home that resume reads. (#820)- Native `ai-memory upgrade` no longer refuses every Linux install by probingthe running executable for write (Linux `ETXTBSY`); it only requires theparent directory to be writable for rename-based replace. (#802)diff --git a/crates/ai-memory-cli/src/commands/run.rs b/crates/ai-memory-cli/src/commands/run.rsindex eafd7193..9098a977 100644--- a/crates/ai-memory-cli/src/commands/run.rs+++ b/crates/ai-memory-cli/src/commands/run.rs@@ -399,13 +399,7 @@ pub(super) async fn run_from_with_wiring(.or_else(|| std::env::var_os(name))};if config.run_autowire && !no_autowire {- let wire_env = autowire_env(- harness,- &run_env,- &plan.args,- remove_kiro_home.then(|| home.join(".kiro")).as_deref(),- &launch_env,- );+ let wire_env = autowire_env(harness, &run_env, &plan.args, &launch_env);super::run_autowire::ensure_wired_with(config, harness, wire_overrides, &wire_env);}if plan.mode == LaunchMode::Session@@ -947,14 +941,11 @@ fn upsert_env(entries: &mut Vec<(String, String)>, key: String, value: String) {/// `--env` entries, adjusted where the child runs with something else. OMP/// ranks `--profile` above `OMP_PROFILE`, so the flag is passed on through the/// profile variables (see [`omp_profile_flag_env`], which reads the launch-/// environment `launch_env`); a Kiro v3 resume from the default store drops-/// `KIRO_HOME` from the child, so its hooks and MCP belong under-/// `default_kiro_home`.+/// environment `launch_env`).fn autowire_env(harness: ManagedHarness,run_env: &[(String, String)],native_args: &[OsString],- default_kiro_home: Option<&Path>,launch_env: &dyn Fn(&str) -> Option<OsString>,) -> Vec<(String, String)> {let mut env = run_env.to_vec();@@ -969,9 +960,6 @@ fn autowire_env(set(&name, value);}}- if let Some(kiro_home) = default_kiro_home {- set("KIRO_HOME", kiro_home.display().to_string());- }env}@@ -3262,89 +3250,6 @@ mod tests {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 no- /// hooks and no MCP.- #[cfg(unix)]- #[tokio::test]- async fn kiro_v3_default_store_resume_autowires_the_home_the_child_reads() {- use crate::commands::run_autowire::WireOverrides;-- const SESSION: &str = "sess_c3774f9d-269e-40d1-aa02-2bb0c0817b4e";- let (address, server) = mock_workstream_server(Some(SESSION)).await;- let home = tempfile::tempdir().unwrap();- let data = tempfile::tempdir().unwrap();- let repo = tempfile::tempdir().unwrap();- let (script, captured) = capture_env_script(repo.path(), "KIRO_HOME");-- let session_dir = home- .path()- .join(".kiro/sessions/checkout-fixture")- .join(SESSION);- std::fs::create_dir_all(&session_dir).unwrap();- std::fs::write(- session_dir.join("session.json"),- serde_json::json!({- "schemaVersion": "1.0.0",- "dataModelVersion": 1,- "id": SESSION,- "workspacePaths": [repo.path()],- "createdAt": "2026-08-06T10:00:00Z",- "lastModifiedAt": "2026-08-06T10:05:00Z",- "agentMode": "vibe",- "status": "idle"- })- .to_string(),- )- .unwrap();- std::fs::write(session_dir.join("messages.jsonl"), "{}\n").unwrap();- let custom = home.path().join("custom-kiro");- std::fs::create_dir_all(custom.join("sessions")).unwrap();-- let config = launch_config(home.path(), data.path(), address);- let overrides = WireOverrides {- hooks_dir: Some(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../hooks")),- confine_to: Some(home.path().to_path_buf()),- ..WireOverrides::default()- };- let env = vec![("KIRO_HOME".to_string(), custom.display().to_string())];- let exit = run_from_with_wiring(- &config,- run_args(RunHarnessChoice::Kiro, script, env, &["--v3"]),- repo.path(),- &overrides,- )- .await- .expect("managed Kiro v3 resume completes");- assert_eq!(exit, 0);- assert_eq!(- std::fs::read_to_string(&captured).unwrap(),- "unset",- "the default-store resume must drop KIRO_HOME from the child"- );-- let kiro_default = home.path().join(".kiro");- let hooks = kiro_default.join("hooks").join("ai-memory.json");- assert!(- std::fs::read_to_string(&hooks).is_ok_and(|s| s.contains("ai-memory")),- "hooks missing in {}",- hooks.display()- );- let mcp = kiro_default.join("settings").join("mcp.json");- assert!(- std::fs::read_to_string(&mcp).is_ok_and(|s| s.contains("ai-memory")),- "MCP missing in {}",- mcp.display()- );- assert!(- !custom.join("hooks").exists() && !custom.join("settings").exists(),- "the KIRO_HOME the child no longer reads must stay untouched"- );-- server.abort();- }-#[test]fn blank_home_overrides_names_only_blank_home_variables() {let env = |pairs: &'static [(&'static str, &'static str)]| {@@ -3618,9 +3523,9 @@ mod tests {server.abort();}- /// OMP ranks `--profile` above `OMP_PROFILE`, and a Kiro v3 default-store- /// resume drops `KIRO_HOME`, so auto-wire sees what the child will run- /// with; everything else in `--env` passes through untouched.+ /// OMP ranks `--profile` above `OMP_PROFILE`, so auto-wire sees what the+ /// child will run with; everything else in `--env` passes through+ /// untouched.#[test]fn autowire_env_follows_what_the_child_runs_with() {let run_env = vec![@@ -3647,17 +3552,17 @@ mod tests {let launch = only(run_env.clone());let args = [OsString::from("--profile"), OsString::from("work")];- let omp = autowire_env(ManagedHarness::Omp, &run_env, &args, None, &launch);+ let omp = autowire_env(ManagedHarness::Omp, &run_env, &args, &launch);assert_eq!(lookup(&omp, "OMP_PROFILE"), ["work"]);assert_eq!(lookup(&omp, "KIRO_HOME"), ["/custom"]);assert_eq!(lookup(&omp, "FOO"), ["x"]);assert_eq!(- autowire_env(ManagedHarness::Pi, &run_env, &args, None, &launch),+ autowire_env(ManagedHarness::Pi, &run_env, &args, &launch),run_env,"only OMP reads --profile");assert_eq!(- autowire_env(ManagedHarness::Omp, &run_env, &[], None, &launch),+ autowire_env(ManagedHarness::Omp, &run_env, &[], &launch),run_env);@@ -3677,22 +3582,11 @@ mod tests {ManagedHarness::Omp,&inherited,&default_args,- None,&only(inherited.clone()),);assert_eq!(ai_memory_workstream::omp_agent_dir(home, None, only(wired)).unwrap(),home.join(".omp").join("agent"));-- let kiro = autowire_env(- ManagedHarness::KiroV3,- &run_env,- &[],- Some(Path::new("/home/me/.kiro")),- &launch,- );- assert_eq!(lookup(&kiro, "KIRO_HOME"), ["/home/me/.kiro"]);- assert_eq!(lookup(&kiro, "OMP_PROFILE"), ["other"]);}}diff --git a/docs/managed-workstreams.md b/docs/managed-workstreams.mdindex 8f694724..629fd28d 100644--- a/docs/managed-workstreams.md+++ b/docs/managed-workstreams.md@@ -553,8 +553,7 @@ transparently. Kiro CLI 2.16.2 wrote v3 sessions below the defaultchecks the configured v3 root first and that default root as a compatibilityfallback. If a linked session exists only in the fallback, ai-memory removes`KIRO_HOME` for that one resume so Kiro can find the session; Kiro consequently-uses its default-home v3 settings/hooks for that process, and first-launch-auto-wire wires that default home rather than `KIRO_HOME`. Fresh launches and+uses its default-home v3 settings/hooks for that process. Fresh launches andversions that store the session below the configured root keep `KIRO_HOME`unchanged. Every candidate still needs exact id, schema, and checkout metadata.The v2 `--yolo` translation is `--trust-all-tools`; an explicit narrower