Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(capture): import unrecognized tools without their arguments or output
AkitaOnRails8d3fb0b04f0f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 587907a5..bce04ff4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -54,7 +54,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0its own record names, and a call or event the live hook would deliver toanother checkout is imported only when that checkout would capture it andsends to the same server. The output of a Claude Code `!` shell command,- which live capture never receives, is no longer imported.+ which live capture never receives, is no longer imported. A tool ai-memory+ does not recognize, such as an MCP tool, is imported as a record that it ran+ without its arguments or output, which is all live capture stores for it.(GHSA-gcpc-88hm-3xqr)- Fixed a web page open in the operator's browser being able to act on anunauthenticated server (the loopback default, no token), such as claiming adiff --git a/crates/ai-memory-cli/src/commands/backfill.rs b/crates/ai-memory-cli/src/commands/backfill.rsindex 3b3ef097..34b6ab64 100644--- a/crates/ai-memory-cli/src/commands/backfill.rs+++ b/crates/ai-memory-cli/src/commands/backfill.rs@@ -659,6 +659,8 @@ struct MappedEvent {/// the native tool payload the server's re-inspection reads, so a claim would/// be judged against the wrong schema and stripped; the server never receives/// the ignore patterns, so the client's decision is the only one possible.+/// An unrecognized tool's event carries only its family, as the live server+/// stores for an unknown-family tool, never its arguments or output.fn map_event(session_id: &str,event: &NewWorkstreamEvent,@@ -672,7 +674,7 @@ fn map_event(let decision = match capture {EventCapture::Drop => return None,EventCapture::MetadataOnly(decision) => Some(decision),- EventCapture::Keep => None,+ EventCapture::Keep | EventCapture::Unrecognized => None,};let role = event.role.as_deref().unwrap_or("");let ingest_key = format!("{session_id}:{}", event.event_id);@@ -704,6 +706,19 @@ fn map_event(}body}+ None if matches!(capture, EventCapture::Unrecognized) => {+ let outcome = if event.kind == WorkstreamEventKind::ToolResult {+ "\noutcome: unknown"+ } else {+ ""+ };+ serde_json::json!({+ "session_id": session_id,+ "title": "tool unknown",+ "message": format!("tool_family: unknown{outcome}"),+ "occurred_at": occurred_at,+ })+ }None => serde_json::json!({"session_id": session_id,"title": first_line(content),@@ -1699,6 +1714,68 @@ mod tests {assert!(posted.contains("read the notes"), "prompt kept: {posted}");}+ /// The live server stores only the family of an unknown-family tool, with+ /// no policy at all. A backfilled Codex MCP call and its output therefore+ /// post only `tool_family: unknown`, never their arguments or output, while+ /// a recognized shell call's output is posted as before.+ #[cfg(unix)]+ #[tokio::test]+ async fn backfill_posts_no_content_for_unrecognized_tools() {+ let home = tempfile::tempdir().unwrap();+ let repo = tempfile::tempdir().unwrap();+ let sid = "019a0000-0000-7000-8000-000000000002";+ let item = |payload: serde_json::Value| {+ serde_json::json!({+ "type": "response_item", "timestamp": "2026-09-01T10:00:00Z", "payload": payload,+ })+ };+ let call = |id: &str, name: &str, arguments: serde_json::Value| {+ item(serde_json::json!({+ "type": "function_call", "name": name, "call_id": id,+ "arguments": arguments.to_string(),+ }))+ };+ let output = |id: &str, text: &str| {+ item(serde_json::json!({"type": "function_call_output", "call_id": id, "output": text}))+ };+ let lines = [+ serde_json::json!({"type": "session_meta", "payload": {"id": sid, "cwd": repo.path()}}),+ call(+ "call_mcp",+ "mcp__vault__fetch",+ serde_json::json!({"query": "ARGSENTINEL"}),+ ),+ output("call_mcp", "MCPSENTINEL private record"),+ call(+ "call_pub",+ "exec_command",+ serde_json::json!({"cmd": "cargo test"}),+ ),+ output("call_pub", "PUBLICCONTROL test result"),+ ];+ let posted = backfill_posted(+ ManagedHarness::Codex,+ home.path(),+ home.path(),+ repo.path(),+ sid,+ &lines,+ )+ .await;+ for sentinel in ["ARGSENTINEL", "MCPSENTINEL", "mcp__vault"] {+ assert!(+ !posted.contains(sentinel),+ "{sentinel} was posted: {posted}"+ );+ }+ assert_eq!(+ posted.matches("\"title\":\"tool unknown\"").count(),+ 2,+ "the call and its output are still recorded: {posted}"+ );+ assert!(posted.contains("PUBLICCONTROL"), "control: {posted}");+ }+fn spawned_args(server_url: Option<&str>,server_profile: Option<&str>,diff --git a/crates/ai-memory-cli/src/commands/transcript_capture.rs b/crates/ai-memory-cli/src/commands/transcript_capture.rsindex 212a3360..c905ff77 100644--- a/crates/ai-memory-cli/src/commands/transcript_capture.rs+++ b/crates/ai-memory-cli/src/commands/transcript_capture.rs@@ -33,6 +33,11 @@ pub(crate) enum EventCapture {Keep,/// Import nothing for this event.Drop,+ /// A tool the capture policy does not recognize: record that it ran,+ /// never its arguments or output. The live server stores only the family+ /// for an unknown-family tool, whatever the policy, so an import must not+ /// store more.+ Unrecognized,/// Record that the tool ran, never its arguments or output.MetadataOnly(CaptureDecision),}@@ -41,8 +46,9 @@ impl EventCapture {const fn rank(&self) -> u8 {match self {Self::Keep => 0,- Self::MetadataOnly(_) => 1,- Self::Drop => 2,+ Self::Unrecognized => 1,+ Self::MetadataOnly(_) => 2,+ Self::Drop => 3,}}@@ -178,7 +184,10 @@ impl TranscriptCapture {.filter_map(|(event, capture)| match capture {EventCapture::Keep => Some(event),EventCapture::Drop => None,- EventCapture::MetadataOnly(decision) => Some(withheld(event, &decision)),+ EventCapture::Unrecognized => Some(withheld(event, ToolFamily::Unknown)),+ EventCapture::MetadataOnly(decision) => {+ Some(withheld(event, decision.protocol().tool_family()))+ }}).map(|mut event| {// The record's cwd only steers the decision above.@@ -190,9 +199,11 @@ impl TranscriptCapture {.collect()}+ /// A result with no call to inherit from. Nothing proves its tool was+ /// recognized, so even without a policy it keeps no output.fn orphan_result(&self) -> EventCapture {if self.policy.state() == PolicyState::Inactive {- EventCapture::Keep+ EventCapture::Unrecognized} else {EventCapture::Drop}@@ -220,6 +231,12 @@ impl TranscriptCapture {let (name, args) = recorded_call(event);let unreadable = args.is_none();let raw = tool_call_payload(event.agent, name, args.as_ref(), call_id(event));+ let recognized = self+ .policy+ .inspect(event.agent, &raw, &self.inspection_cwd)+ .protocol()+ .tool_family()+ != ToolFamily::Unknown;let inspect = |policy: &CapturePolicy, cwd: &str| {inspect_call(policy,@@ -250,7 +267,11 @@ impl TranscriptCapture {}capture = capture.stricter(inspect(&capture_policy(&destination), &destination));}- capture+ if recognized {+ capture+ } else {+ capture.stricter(EventCapture::Unrecognized)+ }}}@@ -353,8 +374,8 @@ fn recorded_call(event: &NewWorkstreamEvent) -> (&str, Option<Value>) {/// A ledger event with its content replaced by the tool family, keeping only/// the labels that pair it with the other half of the call.-fn withheld(mut event: NewWorkstreamEvent, decision: &CaptureDecision) -> NewWorkstreamEvent {- let family = serde_json::to_value(decision.protocol().tool_family())+fn withheld(mut event: NewWorkstreamEvent, family: ToolFamily) -> NewWorkstreamEvent {+ let family = serde_json::to_value(family).ok().and_then(|value| value.as_str().map(str::to_owned)).unwrap_or_else(|| "unknown".to_owned());@@ -434,6 +455,7 @@ mod tests {.map(|capture| match capture {EventCapture::Keep => "keep",EventCapture::Drop => "drop",+ EventCapture::Unrecognized => "unrecognized",EventCapture::MetadataOnly(_) => "metadata",}).collect()@@ -675,6 +697,50 @@ mod tests {);}+ /// Live capture stores no arguments or output for a tool the policy does+ /// not recognize, with or without a policy, so neither does an import: a+ /// call and its result keep only the family, as does a result with no+ /// call to inherit from. A recognized public read is kept.+ #[test]+ fn unrecognized_tools_keep_no_content_with_or_without_a_policy() {+ let unknown = |id: &str| {+ event(+ WorkstreamEventKind::ToolCall,+ "assistant",+ "mcp__vault__fetch: {\"query\":\"ARGSENTINEL\"}",+ json!({"tool": "mcp__vault__fetch", "tool_use_id": id}),+ )+ };+ for marker in [None, Some("docs/adr/**")] {+ let repo = checkout(marker);+ let capture = TranscriptCapture::for_checkout(repo.path(), repo.path());+ let events = vec![+ unknown("u"),+ result("OUTSENTINEL", Some("u")),+ read_call(&repo.path().join("src/lib.rs"), Some("p")),+ result("public code", Some("p")),+ ];+ assert_eq!(+ kinds(&capture.decide(&events)),+ ["unrecognized", "unrecognized", "keep", "keep"],+ "{marker:?}"+ );+ let uploaded = serde_json::to_string(&capture.filter_ledger_events(events)).unwrap();+ assert!(!uploaded.contains("SENTINEL"), "{uploaded}");+ assert!(uploaded.contains("public code"), "{uploaded}");+ assert!(+ uploaded.contains("[unknown tool output withheld by the capture policy]"),+ "{uploaded}"+ );+ }+ let repo = checkout(None);+ let capture = TranscriptCapture::for_checkout(repo.path(), repo.path());+ assert_eq!(+ kinds(&capture.decide(&[result("orphan output", Some("gone"))])),+ ["unrecognized"]+ );+ }+#[test]fn ledger_events_are_dropped_or_stripped_before_upload() {let repo = checkout(Some("docs/adr/**"));diff --git a/docs/design-boot-backfill.md b/docs/design-boot-backfill.mdindex 806f5317..0688a657 100644--- a/docs/design-boot-backfill.md+++ b/docs/design-boot-backfill.md@@ -196,7 +196,9 @@ Retroactive text is exactly as untrusted as live hook text, since it is old mode(`delivers_to_same_server`), or it is dropped; a rerouted call also answers to thedestination's policy. A Claude Code `!` command's output, recorded as user messagesmade only of `<bash-stdout>`/`<bash-stderr>` or `<local-command-stdout>` blocks, is- dropped, since live capture never receives it. A Drop removes both the call and its result before anything is posted; a+ dropped, since live capture never receives it. A tool the matcher does not recognize+ (unknown family) keeps only its family with or without a policy, as the live server+ stores for it, and so does a result with no call to inherit from. A Drop removes both the call and its result before anything is posted; ametadata-only decision posts the hook's metadata-only body with its`_ai_memory_capture` protocol, which the server validates and rebuilds from itsallowlist. A result is paired with its call by native id; without one it takes the