Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(upgrade): refresh generated integrations (#1869)
AkitaOnRails688f79339c66
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c520ce4a..41a8d50f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,6 +13,9 @@ version in [`docs/changelog/`](docs/changelog/):### Fixed+- Refreshed existing ai-memory-owned OpenCode, OpenCode 2, OMP, Pi, and+ OpenClaw generated TypeScript integrations during `ai-memory upgrade`, while+ leaving absent and user-owned installs untouched (#1869).- Excluded Codex's generated approval-review transcripts and backgroundsuggestion prompts from transcript backfill and profile harvesting, andkept a hand-reworded profile page attached to its ledger topic even when adiff --git a/crates/ai-memory-cli/src/commands/install_hooks.rs b/crates/ai-memory-cli/src/commands/install_hooks.rsindex 04a710d5..7db8f1ad 100644--- a/crates/ai-memory-cli/src/commands/install_hooks.rs+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs@@ -1459,6 +1459,22 @@ fn existing_agent_config(args: &InstallHooksArgs) -> Option<String> {std::fs::read_to_string(path).ok()}+/// Whether a generated TypeScript integration carries the ownership banner and+/// agent constant used by the installer and uninstaller.+pub(crate) fn generated_integration_content_is_owned(agent: AgentChoice, existing: &str) -> bool {+ let (name, agent_constant) = match agent {+ AgentChoice::OpenCode => ("opencode", "open-code"),+ AgentChoice::OpenCode2 => ("opencode2", "opencode2"),+ AgentChoice::Pi => ("pi", "pi"),+ AgentChoice::Omp => ("omp", "omp"),+ AgentChoice::Openclaw => ("openclaw", "openclaw"),+ _ => return false,+ };+ let banner = format!("// Auto-generated by `ai-memory install-hooks --agent {name} --apply`.");+ existing.lines().next() == Some(banner.as_str())+ && existing.contains(&format!("const AGENT = \"{agent_constant}\";"))+}+/// Recover a strategy only from configuration entries ai-memory owns. Shared/// JSON/TOML config files may contain unrelated hooks, while generated/// TypeScript files carry an explicit ownership header.diff --git a/crates/ai-memory-cli/src/commands/upgrade.rs b/crates/ai-memory-cli/src/commands/upgrade.rsindex b3edc1b4..562667a5 100644--- a/crates/ai-memory-cli/src/commands/upgrade.rs+++ b/crates/ai-memory-cli/src/commands/upgrade.rs@@ -6,7 +6,7 @@//! `docs/macos.md`, Windows zip in `docs/windows.md` Scenario C): download the//! matching archive + `.sha256`, verify, replace the on-disk binary (and sibling//! `hooks/` when present), then re-run `install-hooks --apply` for every staged-//! agent.+//! agent and every existing ai-memory-owned generated TypeScript integration.//!//! Client-only: never claims to upgrade a remote/homelab server.//!@@ -81,6 +81,7 @@ pub async fn run(config: &Config, args: UpgradeArgs) -> Result<()> {// Sync FS after await is intentional for this CLI one-shot path.refresh_staged_hooks(config)?;+ refresh_generated_integrations(config);refresh_plugins(config, &super::user_service::SystemRunner);warn_remote_server(config);println!("✓ upgraded to {tag}");@@ -807,6 +808,66 @@ fn refresh_staged_hooks(config: &Config) -> Result<()> {Ok(())}+const GENERATED_INTEGRATIONS: &[(&str, AgentChoice)] = &[+ ("opencode", AgentChoice::OpenCode),+ ("opencode2", AgentChoice::OpenCode2),+ ("omp", AgentChoice::Omp),+ ("pi", AgentChoice::Pi),+ ("openclaw", AgentChoice::Openclaw),+];++fn refresh_generated_integrations(config: &Config) {+ for &(name, agent) in GENERATED_INTEGRATIONS {+ let path = match default_generated_integration_path(agent) {+ Ok(path) => path,+ Err(err) => {+ println!(" (skipping generated {name} integration — {err:#})");+ continue;+ }+ };+ let owned = fs::read_to_string(&path).is_ok_and(|content| {+ install_hooks::generated_integration_content_is_owned(agent, &content)+ });+ if !owned {+ continue;+ }++ println!("→ refreshing generated {name} integration");+ let mut args = apply_hooks_args(agent);+ args.config_file = if agent == AgentChoice::Openclaw {+ path.parent().map(Path::to_path_buf)+ } else {+ Some(path.clone())+ };+ let result = if agent == AgentChoice::OpenCode {+ install_hooks::run_with_opencode_dialect(+ config,+ args,+ Some(ai_memory_workstream::OpenCodeDialect::V1),+ )+ } else {+ install_hooks::run(config, args)+ };+ if let Err(err) = result {+ println!(+ " (skipped — {err:#}; re-run `ai-memory install-hooks --agent {name} --apply`)"+ );+ }+ }+}++fn default_generated_integration_path(agent: AgentChoice) -> Result<PathBuf> {+ match agent {+ AgentChoice::OpenCode => install_hooks::opencode_plugin_path(),+ AgentChoice::OpenCode2 => install_hooks::opencode2_plugin_path(),+ AgentChoice::Omp => install_hooks::omp_extension_path(None),+ AgentChoice::Pi => install_hooks::pi_extension_path(),+ AgentChoice::Openclaw => Ok(crate::commands::openclaw_plugin::default_plugin_dir()?+ .join(crate::commands::openclaw_plugin::ENTRYPOINT_TS)),+ _ => bail!("not a generated TypeScript integration: {agent:?}"),+ }+}+/// Keep the marketplace plugins in step with the binary (#1166). Claude Code/// does not auto-update a third-party marketplace unless the user turned that/// on, so the Claude Code plugin is updated here. Codex is only told what todiff --git a/crates/ai-memory-cli/tests/suite/upgrade_e2e.rs b/crates/ai-memory-cli/tests/suite/upgrade_e2e.rsindex 74282b87..e7b4d92a 100644--- a/crates/ai-memory-cli/tests/suite/upgrade_e2e.rs+++ b/crates/ai-memory-cli/tests/suite/upgrade_e2e.rs@@ -393,4 +393,167 @@ mod slow {);server.abort();}++ #[tokio::test]+ async fn native_upgrade_refreshes_only_owned_generated_integrations() {+ fn generated_path(home: &Path, agent: &str) -> PathBuf {+ match agent {+ "opencode" => home.join(".config/opencode/plugins/ai-memory.ts"),+ "opencode2" => home.join(".config/opencode/plugins/ai-memory-opencode2.ts"),+ "pi" => home.join(".pi/agent/extensions/ai-memory-pi.ts"),+ "omp" => home.join(".omp/agent/extensions/ai-memory-omp.ts"),+ "openclaw" => {+ let data = if cfg!(windows) {+ home.join("AppData/Local")+ } else if cfg!(target_os = "macos") {+ home.join("Library/Application Support")+ } else {+ home.join(".local/share")+ };+ data.join("ai-memory/openclaw-plugin/index.ts")+ }+ other => panic!("unknown generated agent {other}"),+ }+ }++ fn agent_constant(agent: &str) -> &str {+ match agent {+ "opencode" => "open-code",+ other => other,+ }+ }++ fn write_old_owned(home: &Path, agent: &str) {+ let path = generated_path(home, agent);+ fs::create_dir_all(path.parent().expect("generated parent")).expect("mkdir generated");+ let assistant = if agent == "opencode2" {+ "const CAPTURE_ASSISTANT = true;\n"+ } else {+ ""+ };+ fs::write(+ path,+ format!(+ "// Auto-generated by `ai-memory install-hooks --agent {agent} --apply`.\n\+ const AGENT = \"{}\";\n\+ const DEFAULT_PROJECT_STRATEGY = \"repo-root\";\n\+ {assistant}old-render\n",+ agent_constant(agent)+ ),+ )+ .expect("plant old generated render");+ }++ async fn run_upgrade(+ base: &str,+ plant: impl FnOnce(&Path),+ ) -> (tempfile::TempDir, std::process::Output) {+ let prefix = tempfile::tempdir().expect("install prefix");+ let data_dir = tempfile::tempdir().expect("data dir");+ let home = tempfile::tempdir().expect("home");+ let exe = install_writable_prefix(prefix.path());+ fs::write(data_dir.path().join("capture-mode"), "allowlist\n")+ .expect("persist capture mode");+ plant(home.path());+ let empty_path = prefix.path().join("empty-path");+ fs::create_dir(&empty_path).expect("empty PATH");++ let mut cmd = hermetic(exe.to_str().expect("utf-8 exe path"));+ cmd.args(["upgrade", "--version", TAG, "--force"])+ .env("AI_MEMORY_RELEASE_BASE_URL", base)+ .env("AI_MEMORY_DATA_DIR", data_dir.path())+ .env("AI_MEMORY_HOME", home.path())+ .env("HOME", home.path())+ .env("USERPROFILE", home.path())+ .env("XDG_DATA_HOME", home.path().join(".local/share"))+ .env("APPDATA", home.path().join("AppData/Roaming"))+ .env("LOCALAPPDATA", home.path().join("AppData/Local"))+ .env("PATH", empty_path)+ .env_remove("OMP_PROFILE")+ .env_remove("PI_PROFILE")+ .env_remove("PI_CONFIG_DIR");+ let output = tokio::process::Command::from(cmd)+ .output()+ .await+ .expect("spawn upgrade");+ assert!(+ output.status.success(),+ "upgrade failed: stdout={}\nstderr={}",+ String::from_utf8_lossy(&output.stdout),+ String::from_utf8_lossy(&output.stderr)+ );+ (home, output)+ }++ let asset = host_asset_name().to_string();+ let archive = Arc::new(build_release_archive());+ let hash = format!("{:x}", Sha256::digest(archive.as_ref()));+ let fixture = ReleaseFixture {+ checksum_body: format!("{hash} {asset}\n"),+ asset,+ archive,+ };+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0")+ .await+ .expect("bind release fixture");+ let addr = listener.local_addr().expect("fixture addr");+ let app = Router::new()+ .route("/releases/latest/tag", get(latest_tag))+ .route("/releases/download/{tag}/{name}", get(download))+ .with_state(fixture);+ let server = tokio::spawn(async move {+ axum::serve(listener, app).await.expect("fixture serve");+ });+ let base = format!("http://{addr}/releases");++ let unowned = "// User-owned OpenCode plugin; do not overwrite.\n";+ let (home, _) = run_upgrade(&base, |home| {+ fs::create_dir_all(home.join(".config/opencode/plugins"))+ .expect("mkdir unowned plugin");+ fs::write(generated_path(home, "opencode"), unowned).expect("plant unowned plugin");+ for agent in ["opencode2", "pi", "omp", "openclaw"] {+ write_old_owned(home, agent);+ }+ })+ .await;+ for agent in ["opencode2", "pi", "omp", "openclaw"] {+ let content = fs::read_to_string(generated_path(home.path(), agent))+ .unwrap_or_else(|error| panic!("read refreshed {agent}: {error}"));+ assert!(+ content.contains("windowsHide: true"),+ "{agent} stayed stale"+ );+ assert!(+ content.contains("const DEFAULT_PROJECT_STRATEGY = \"repo-root\";"),+ "{agent} lost project strategy"+ );+ assert!(+ content+ .contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"allowlist\";"),+ "{agent} lost capture mode"+ );+ }+ let opencode2 =+ fs::read_to_string(generated_path(home.path(), "opencode2")).expect("read OpenCode 2");+ assert!(opencode2.contains("const CAPTURE_ASSISTANT = true;"));+ assert_eq!(+ fs::read_to_string(generated_path(home.path(), "opencode"))+ .expect("read unowned plugin"),+ unowned+ );++ let (home, _) = run_upgrade(&base, |home| write_old_owned(home, "opencode")).await;+ let opencode = fs::read_to_string(generated_path(home.path(), "opencode"))+ .expect("read refreshed OpenCode");+ assert!(opencode.contains("windowsHide: true"));+ assert!(opencode.contains("const DEFAULT_PROJECT_STRATEGY = \"repo-root\";"));+ for agent in ["opencode2", "pi", "omp", "openclaw"] {+ assert!(+ !generated_path(home.path(), agent).exists(),+ "upgrade created absent {agent} integration"+ );+ }++ server.abort();+ }}diff --git a/docs/windows.md b/docs/windows.mdindex d525f386..035ac0c8 100644--- a/docs/windows.md+++ b/docs/windows.md@@ -297,9 +297,12 @@ ai-memory upgrade --forceThat downloads `ai-memory-windows-x86_64.zip` + `.sha256`, verifies thechecksum, replaces `ai-memory.exe` via rename-aside (Windows cannot overwritea running image), refreshes a sibling `hooks/` tree when present, then-re-stages hooks for agents already under the data-dir hooks tree. Keep the-manual zip download above as a fallback if the install directory is not-writable (for example under Program Files).+re-stages hooks for agents already under the data-dir hooks tree. It also+re-renders existing ai-memory-owned OpenCode, OpenCode 2, OMP, Pi, and OpenClaw+TypeScript integrations at their default or active-profile paths; absent and+user-owned files are left untouched. Keep the manual zip download above as a+fallback if the install directory is not writable (for example under Program+Files).The zip mirrors the Linux release tarball, minus the Linux-only serviceassets: it contains `ai-memory.exe`, the full `hooks/` bundle (`.ps1` +