Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(hooks): recognize antigravity-cli native tools and capture edit content
Marcelo Mogami94e0f5c1e232
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 118a6669..44cbcb76 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Fixed+- Antigravity CLI's native tools (`view_file`, `replace_file_content`,+ `multi_replace_file_content`, `write_to_file`, `list_dir`, `grep_search`,+ `read_url_content`, `read_resource`, `call_mcp_tool`) are now recognized by+ `capture_policy::family()` instead of falling through to `ToolFamily::Unknown`.+ Previously every Antigravity file read/edit and search observation was+ reduced to a bare `tool_family: unknown` stub with no captured content,+ leaving session-end LLM consolidation with nothing to summarize.+- Antigravity's edit tools (`write_to_file`, `replace_file_content`,+ `multi_replace_file_content`) now capture the content actually written,+ read from `toolCall.args.CodeContent` / `.ReplacementContent` /+ `.ReplacementChunks`. Previously `post-tool-use` observations for these+ tools rendered `(no output captured)` even after the family fix above,+ because Antigravity's hook payload never sends a top-level+ `tool_response`/`output`/`result` field; the written content lives nested+ under `toolCall.args` instead. Antigravity's read/search tools+ (`view_file`, `list_dir`, `grep_search`, ...) still summarize to+ `tool_family` + outcome only — Antigravity's `post-tool-use` payload does+ not echo back read/search results at all, so there is nothing to capture+ for those.+## [1.19.2] - 2026-07-28### Fixeddiff --git a/crates/ai-memory-hooks/src/capture_policy.rs b/crates/ai-memory-hooks/src/capture_policy.rsindex ad09dba4..f4f9b346 100644--- a/crates/ai-memory-hooks/src/capture_policy.rs+++ b/crates/ai-memory-hooks/src/capture_policy.rs@@ -556,13 +556,28 @@ fn extract(agent: AgentKind, raw: &Value) -> Extracted {fn family(name: &str) -> ToolFamily {match name.to_ascii_lowercase().as_str() {- "read" | "write" | "edit" | "apply_patch" | "notebookedit" | "notebook_edit"- | "create_file" | "delete_file" | "rename_file" | "move_file" | "multi_edit"- | "multiedit" | "replace" | "replace_all" => ToolFamily::File,- "search" | "grep" | "glob" | "find" | "list" | "ls" | "list_files" | "read_dir" => {- ToolFamily::SearchList- }- "bash" | "shell" | "execute" | "run_command" | "web_search" => ToolFamily::NonFile,+ "read"+ | "write"+ | "edit"+ | "apply_patch"+ | "notebookedit"+ | "notebook_edit"+ | "create_file"+ | "delete_file"+ | "rename_file"+ | "move_file"+ | "multi_edit"+ | "multiedit"+ | "replace"+ | "replace_all"+ | "view_file"+ | "replace_file_content"+ | "multi_replace_file_content"+ | "write_to_file" => ToolFamily::File,+ "search" | "grep" | "glob" | "find" | "list" | "ls" | "list_files" | "read_dir"+ | "list_dir" | "grep_search" => ToolFamily::SearchList,+ "bash" | "shell" | "execute" | "run_command" | "web_search" | "read_url_content"+ | "read_resource" | "call_mcp_tool" => ToolFamily::NonFile,_ => ToolFamily::Unknown,}}@@ -622,6 +637,9 @@ fn direct_paths(object: &Map<String, Value>) -> Option<Vec<String>> {"absolute_path","AbsolutePath","notebook_path",+ "TargetFile",+ "SearchPath",+ "DirectoryPath",] {if let Some(value) = object.get(key) {if paths.len() == MAX_CAPTURE_CANDIDATES {@@ -970,6 +988,61 @@ mod tests {assert!(CaptureProtocol::parse(&bad).is_none());}#[test]+ fn antigravity_native_tools_are_no_longer_unknown() {+ for (tool, expected) in [+ ("view_file", ToolFamily::File),+ ("replace_file_content", ToolFamily::File),+ ("multi_replace_file_content", ToolFamily::File),+ ("write_to_file", ToolFamily::File),+ ("list_dir", ToolFamily::SearchList),+ ("grep_search", ToolFamily::SearchList),+ ("read_url_content", ToolFamily::NonFile),+ ("read_resource", ToolFamily::NonFile),+ ("call_mcp_tool", ToolFamily::NonFile),+ ] {+ assert_eq!(family(tool), expected, "tool: {tool}");+ }+ }+ #[test]+ fn antigravity_direct_paths_recognizes_native_arg_keys() {+ let target = json!({"TargetFile": "/repo/src/main.rs"});+ assert_eq!(+ direct_paths(target.as_object().unwrap()).unwrap(),+ vec!["/repo/src/main.rs".to_string()]+ );+ let search = json!({"SearchPath": "/repo/src"});+ assert_eq!(+ direct_paths(search.as_object().unwrap()).unwrap(),+ vec!["/repo/src".to_string()]+ );+ let dir = json!({"DirectoryPath": "/repo"});+ assert_eq!(+ direct_paths(dir.as_object().unwrap()).unwrap(),+ vec!["/repo".to_string()]+ );+ }+ #[test]+ fn antigravity_view_file_is_captured_and_matched_like_other_agents() {+ let policy = CapturePolicy::resolve(+ CaptureSource::Parsed(&CaptureConfig {+ ignore_paths: vec!["secret/**".into()],+ }),+ "/repo",+ None,+ );+ let ignored =+ json!({"toolCall": {"name": "view_file", "args": {"TargetFile": "secret/keys.txt"}}});+ let decision = policy.inspect(AgentKind::AntigravityCli, &ignored, "/repo");+ assert_eq!(decision.protocol().tool_family(), ToolFamily::File);+ assert_eq!(decision.protocol().disposition(), CaptureDisposition::Drop);++ let kept =+ json!({"toolCall": {"name": "view_file", "args": {"TargetFile": "src/main.rs"}}});+ let decision = policy.inspect(AgentKind::AntigravityCli, &kept, "/repo");+ assert_eq!(decision.protocol().tool_family(), ToolFamily::File);+ assert_eq!(decision.protocol().disposition(), CaptureDisposition::Keep);+ }+ #[test]fn normalization_and_matcher_bounds() {let policy = CapturePolicy::resolve(CaptureSource::Parsed(&CaptureConfig {diff --git a/crates/ai-memory-hooks/src/payload.rs b/crates/ai-memory-hooks/src/payload.rsindex 27eb2ebf..96a663c7 100644--- a/crates/ai-memory-hooks/src/payload.rs+++ b/crates/ai-memory-hooks/src/payload.rs@@ -549,10 +549,20 @@ fn safe_tool_body(if metadata.tool_family == crate::capture_policy::ToolFamily::Unknown {return Some(summary);}- let result =- extract_content(raw, &["tool_response", "tool_output", "output", "result"])- .or_else(|| extract_content(raw, &["error"]))- .unwrap_or_else(|| "(no output captured)".into());+ let result = extract_content(+ raw,+ &[+ "tool_response",+ "tool_output",+ "output",+ "result",+ "ReplacementContent",+ "CodeContent",+ "ReplacementChunks",+ ],+ )+ .or_else(|| extract_content(raw, &["error"]))+ .unwrap_or_else(|| "(no output captured)".into());summary.push_str("\n---\n");summary.push_str(&result);Some(truncate_excerpt(&summary))@@ -642,6 +652,9 @@ fn extraction_candidates(value: &serde_json::Value) -> Vec<&serde_json::Value> {if let Some(event) = value.get("event") {push_candidates(&mut out, event);}+ if let Some(args) = value.get("toolCall").and_then(|call| call.get("args")) {+ push_candidates(&mut out, args);+ }out}@@ -1907,6 +1920,141 @@ mod tests {assert!(!env.body_excerpt.unwrap().contains("tool_call_id"));}+ #[test]+ fn antigravity_native_file_and_search_tools_render_captured_content() {+ for (tool, args, family) in [+ (+ "view_file",+ serde_json::json!({"TargetFile": "src/main.rs"}),+ "file",+ ),+ (+ "replace_file_content",+ serde_json::json!({"TargetFile": "src/main.rs"}),+ "file",+ ),+ (+ "list_dir",+ serde_json::json!({"DirectoryPath": "src"}),+ "search-list",+ ),+ (+ "grep_search",+ serde_json::json!({"SearchPath": "src"}),+ "search-list",+ ),+ ] {+ let env = HookEnvelope::from_query_and_body(+ HookQuery {+ event: "post-tool-use".into(),+ agent: Some("antigravity-cli".into()),+ ..Default::default()+ },+ serde_json::json!({+ "toolCall": {"name": tool, "args": args},+ "tool_response": "SENTINEL_CONTENT",+ }),+ );+ let body = env.body_excerpt.unwrap();+ assert!(+ body.contains(&format!("tool_family: {family}")),+ "tool: {tool}, body: {body}"+ );+ assert!(+ body.contains("SENTINEL_CONTENT"),+ "tool: {tool}, body: {body}"+ );+ }+ }++ #[test]+ fn antigravity_edit_tools_capture_real_written_content() {+ // Fixture shapes captured verbatim from a live antigravity-cli session+ // (docs-celo/03-antigravity-tool-family-mapping/08 and 10) — the hook+ // never sends a top-level result; the written content lives nested+ // under toolCall.args.+ let write_to_file = HookEnvelope::from_query_and_body(+ HookQuery {+ event: "post-tool-use".into(),+ agent: Some("antigravity-cli".into()),+ ..Default::default()+ },+ serde_json::json!({+ "toolCall": {+ "name": "write_to_file",+ "args": {+ "CodeContent": "# Scratch Test File 09\n\nLine 1: first line\n",+ "Description": "Temporary scratch file",+ "Overwrite": true,+ "TargetFile": "/repo/scratch-test-09.md"+ }+ }+ }),+ );+ let body = write_to_file.body_excerpt.unwrap();+ assert!(body.contains("tool_family: file"));+ assert!(body.contains("Scratch Test File 09"));++ let replace_file_content = HookEnvelope::from_query_and_body(+ HookQuery {+ event: "post-tool-use".into(),+ agent: Some("antigravity-cli".into()),+ ..Default::default()+ },+ serde_json::json!({+ "toolCall": {+ "name": "replace_file_content",+ "args": {+ "TargetFile": "/repo/1-visao.md",+ "TargetContent": "old line",+ "ReplacementContent": "new line REPLACED_SENTINEL",+ "Instruction": "Add debug test comment"+ }+ }+ }),+ );+ let body = replace_file_content.body_excerpt.unwrap();+ assert!(body.contains("tool_family: file"));+ assert!(body.contains("REPLACED_SENTINEL"));++ let multi_replace = HookEnvelope::from_query_and_body(+ HookQuery {+ event: "post-tool-use".into(),+ agent: Some("antigravity-cli".into()),+ ..Default::default()+ },+ serde_json::json!({+ "toolCall": {+ "name": "multi_replace_file_content",+ "args": {+ "TargetFile": "/repo/scratch-test-09.md",+ "Instruction": "Edit Line 1 and Line 4",+ "ReplacementChunks": [+ {+ "TargetContent": "Line 1: first line",+ "ReplacementContent": "Line 1: first line edited",+ "StartLine": 3,+ "EndLine": 3,+ "AllowMultiple": false+ },+ {+ "TargetContent": "Line 4: fourth line",+ "ReplacementContent": "Line 4: fourth line edited",+ "StartLine": 6,+ "EndLine": 6,+ "AllowMultiple": false+ }+ ]+ }+ }+ }),+ );+ let body = multi_replace.body_excerpt.unwrap();+ assert!(body.contains("tool_family: file"));+ assert!(body.contains("Line 1: first line edited"));+ assert!(body.contains("Line 4: fourth line edited"));+ }+#[test]fn pi_post_outcomes_and_stable_id_are_rendered() {for (is_error, outcome) in [