Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(hooks): keep allowlist plugins from fetching a handoff in unmarked repos
Renato Regis275b06b4d494
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c6a02aca..d39e610f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,6 +13,15 @@ version in [`docs/changelog/`](docs/changelog/):### Fixed+- The OpenCode, OpenCode 2, OpenClaw, Pi and OMP integrations installed with+ `--capture-mode allowlist` no longer send the handoff (or OpenCode's recap)+ request from a repository without a `.ai-memory.toml` marker. They already+ dropped its capture, but the server answers that request by resolving the+ directory into a project, so opening one of these agents in an unmarked+ directory left an empty project named after it. The native hook already+ returned before the request; these integrations call the server directly+ (#PRNUM).+- `ai-memory user list` and `ai-memory api-key list` now size their columnsby terminal display width rather than bytes, as `list-projects` and thegrants tables already do. An accented username, display name or key labeldiff --git a/crates/ai-memory-cli/src/commands/install_hooks.rs b/crates/ai-memory-cli/src/commands/install_hooks.rsindex 024b0141..6fad9be0 100644--- a/crates/ai-memory-cli/src/commands/install_hooks.rs+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs@@ -5216,6 +5216,11 @@ async function fetchHandoff(cwd: string, id: string | undefined): Promise<string// so another repository's baton could be consumed. Leave it open instead.if (!cwd) return undefined;if (captureServerRouted(cwd)) return undefined;+ // An allowlist build captures only marked repositories, and the native hook+ // returns before its handoff GET for any other (`hook.rs`). Do the same: the+ // server resolves the directory into a project to look the baton up, so a+ // request from an unmarked one leaves an empty project behind.+ if (CAPTURE_MODE === "allowlist" && !findMarker(cwd)) return undefined;const url = new URL(`${{SERVER}}/handoff`);url.searchParams.set("agent", AGENT);url.searchParams.set("cwd", cwd);@@ -5237,6 +5242,9 @@ async function fetchHandoff(cwd: string, id: string | undefined): Promise<stringasync function fetchRecap(cwd: string, id: string): Promise<string | undefined> {{if (captureServerRouted(cwd)) return undefined;+ // Same rule as the handoff fetch: no request for a repository an allowlist+ // build does not capture.+ if (CAPTURE_MODE === "allowlist" && !findMarker(cwd)) return undefined;const url = new URL(`${{SERVER}}/recap`);url.searchParams.set("agent", AGENT);url.searchParams.set("session_id", id);@@ -6010,6 +6018,11 @@ async function fetchHandoff(cwd: string, id: string | undefined): Promise<string// so another repository's baton could be consumed. Leave it open instead.if (!cwd) return undefined;if (captureServerRouted(cwd)) return undefined;+ // An allowlist build captures only marked repositories, and the native hook+ // returns before its handoff GET for any other (`hook.rs`). Do the same: the+ // server resolves the directory into a project to look the baton up, so a+ // request from an unmarked one leaves an empty project behind.+ if (CAPTURE_MODE === "allowlist" && !findMarker(cwd)) return undefined;const url = new URL(`${{SERVER}}/handoff`);url.searchParams.set("agent", AGENT);url.searchParams.set("cwd", cwd);@@ -14153,6 +14166,56 @@ model = "gpt-5"}}+ /// An allowlist build sends nothing for an unmarked repository: not the+ /// capture (#661), and not the handoff or recap GET either, which the+ /// server answers by resolving the directory into a project, creating it.+ /// The native hook returns before those requests for the same reason.+ #[test]+ fn allowlist_integrations_fetch_no_handoff_or_recap_outside_a_marked_repository() {+ const GATE: &str =+ "if (CAPTURE_MODE === \"allowlist\" && !findMarker(cwd)) return undefined;";+ let plugins = [+ (+ "opencode",+ build_opencode_plugin("http://127.0.0.1:49374", None, None, "allowlist"),+ ),+ (+ "opencode2",+ build_opencode2_plugin("http://127.0.0.1:49374", None, None, "allowlist", false)+ .unwrap(),+ ),+ (+ "omp",+ build_omp_extension("http://127.0.0.1:49374", None, None, "allowlist"),+ ),+ (+ "pi",+ build_pi_extension("http://127.0.0.1:49374", None, None, "allowlist"),+ ),+ ];+ for (agent, plugin) in plugins {+ assert!(+ plugin+ .contains("const CAPTURE_MODE: \"allowlist\" | \"denylist\" = \"allowlist\";"),+ "{agent}: the mode must be baked in"+ );+ for (fetch, path) in [("fetchHandoff", "/handoff`"), ("fetchRecap", "/recap`")] {+ let Some((_, body)) = plugin.split_once(&format!("async function {fetch}(")) else {+ assert_eq!(fetch, "fetchRecap", "{agent}: no {fetch}");+ continue;+ };+ let gate = body+ .find(GATE)+ .unwrap_or_else(|| panic!("{agent}: {fetch} must honour the allowlist"));+ let request = body.find(path).unwrap();+ assert!(+ gate < request,+ "{agent}: {fetch} gate must precede the request"+ );+ }+ }+ }+/// Slow tier: spawns Node to run the generated OMP extension.mod slow_generated_handoff_runtime {use super::*;diff --git a/crates/ai-memory-cli/src/commands/openclaw_plugin.rs b/crates/ai-memory-cli/src/commands/openclaw_plugin.rsindex 76a0fff9..bdddbef4 100644--- a/crates/ai-memory-cli/src/commands/openclaw_plugin.rs+++ b/crates/ai-memory-cli/src/commands/openclaw_plugin.rs@@ -406,6 +406,11 @@ async function fetchHandoff(event: any, ctx: any): Promise<string | undefined> {const currentCwd = cwd(event, ctx);if (!currentCwd) return undefined;if (captureServerRouted(currentCwd)) return undefined;+ // An allowlist build captures only marked repositories, and the native hook+ // returns before its handoff GET for any other (`hook.rs`). Do the same: the+ // server resolves the directory into a project to look the baton up, so a+ // request from an unmarked one leaves an empty project behind.+ if (CAPTURE_MODE === "allowlist" && !findMarker(currentCwd)) return undefined;const url = new URL(`${{SERVER}}/handoff`);url.searchParams.set("agent", AGENT);if (!applyMarkerParams(url, currentCwd)) return undefined;@@ -1039,6 +1044,21 @@ mod tests {assert!(guard < handoff.find("/handoff`").unwrap());}+ /// The handoff GET makes the server resolve the directory into a project,+ /// creating it, so an allowlist build must not send it for an unmarked+ /// repository either: the native hook returns before that request too.+ #[test]+ fn openclaw_allowlist_build_fetches_no_handoff_outside_a_marked_repository() {+ let plugin = build_plugin("http://127.0.0.1:49374", Some("tok"), None, "allowlist");+ let handoff = plugin.split_once("async function fetchHandoff(").unwrap().1;+ let gate = handoff+ .find(+ "if (CAPTURE_MODE === \"allowlist\" && !findMarker(currentCwd)) return undefined;",+ )+ .expect("handoff fetch must honour the allowlist");+ assert!(gate < handoff.find("/handoff`").unwrap());+ }+#[test]fn openclaw_plugin_denylist_bakes_inert_gate() {let plugin = build_plugin("http://127.0.0.1:49374", Some("tok"), None, "denylist");