Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(hooks): narrow Antigravity capture fallback (#294)

AkitaOnRails6451bebedfe7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0b70de24..f185d723 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,25 +8,11 @@ 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. (#294)
-- 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. (#294)
+- Recognized Antigravity CLI's native file/edit and search tools, applied path
+ exclusions to its `TargetFile` operations, and captured bounded successful
+ edit content from `toolCall.args` when the hook omits an output field. Generic
+ MCP/resource tools remain fail-closed until their path schemas are proven,
+ while failed edits retain their error instead of attempted content. (#294)
## [1.19.2] - 2026-07-28
diff --git a/crates/ai-memory-hooks/src/capture_policy.rs b/crates/ai-memory-hooks/src/capture_policy.rs
index f4f9b346..47c4ce9e 100644
--- a/crates/ai-memory-hooks/src/capture_policy.rs
+++ b/crates/ai-memory-hooks/src/capture_policy.rs
@@ -576,8 +576,7 @@ fn family(name: &str) -> ToolFamily {
| "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,
+ "bash" | "shell" | "execute" | "run_command" | "web_search" => ToolFamily::NonFile,
_ => ToolFamily::Unknown,
}
}
@@ -638,8 +637,6 @@ fn direct_paths(object: &Map<String, Value>) -> Option<Vec<String>> {
"AbsolutePath",
"notebook_path",
"TargetFile",
- "SearchPath",
- "DirectoryPath",
] {
if let Some(value) = object.get(key) {
if paths.len() == MAX_CAPTURE_CANDIDATES {
@@ -996,33 +993,20 @@ mod tests {
("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() {
+ fn antigravity_target_file_is_a_proven_path() {
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() {
+ fn antigravity_file_tools_honor_capture_exclusions() {
let policy = CapturePolicy::resolve(
CaptureSource::Parsed(&CaptureConfig {
ignore_paths: vec!["secret/**".into()],
@@ -1030,11 +1014,26 @@ mod tests {
"/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);
+ for tool in [
+ "view_file",
+ "write_to_file",
+ "replace_file_content",
+ "multi_replace_file_content",
+ ] {
+ let ignored = json!({
+ "toolCall": {
+ "name": tool,
+ "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,
+ "tool: {tool}"
+ );
+ }
let kept =
json!({"toolCall": {"name": "view_file", "args": {"TargetFile": "src/main.rs"}}});
diff --git a/crates/ai-memory-hooks/src/payload.rs b/crates/ai-memory-hooks/src/payload.rs
index 96a663c7..48b1670f 100644
--- a/crates/ai-memory-hooks/src/payload.rs
+++ b/crates/ai-memory-hooks/src/payload.rs
@@ -549,20 +549,11 @@ 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",
- "ReplacementContent",
- "CodeContent",
- "ReplacementChunks",
- ],
- )
- .or_else(|| extract_content(raw, &["error"]))
- .unwrap_or_else(|| "(no output captured)".into());
+ let result =
+ extract_content(raw, &["tool_response", "tool_output", "output", "result"])
+ .or_else(|| extract_content(raw, &["error"]))
+ .or_else(|| antigravity_edit_content(agent, raw))
+ .unwrap_or_else(|| "(no output captured)".into());
summary.push_str("\n---\n");
summary.push_str(&result);
Some(truncate_excerpt(&summary))
@@ -571,6 +562,25 @@ fn safe_tool_body(
}
}
+fn antigravity_edit_content(agent: AgentKind, raw: &serde_json::Value) -> Option<String> {
+ if agent != AgentKind::AntigravityCli {
+ return None;
+ }
+ let tool_call = raw.get("toolCall")?;
+ let tool = tool_call.get("name")?.as_str()?;
+ if !matches!(
+ tool.to_ascii_lowercase().as_str(),
+ "write_to_file" | "replace_file_content" | "multi_replace_file_content"
+ ) {
+ return None;
+ }
+ let args = tool_call.get("args")?;
+ extract_content(
+ args,
+ &["ReplacementContent", "CodeContent", "ReplacementChunks"],
+ )
+}
+
fn extract_string(value: &serde_json::Value, keys: &[&str]) -> Option<String> {
for key in keys {
for candidate in extraction_candidates(value) {
@@ -652,9 +662,6 @@ 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
}
@@ -1969,10 +1976,8 @@ mod tests {
#[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.
+ // Fixture shapes captured from a live antigravity-cli session. The hook
+ // never sends a top-level result; the written content lives in args.
let write_to_file = HookEnvelope::from_query_and_body(
HookQuery {
event: "post-tool-use".into(),
@@ -2055,6 +2060,69 @@ mod tests {
assert!(body.contains("Line 4: fourth line edited"));
}
+ #[test]
+ fn antigravity_failed_edit_prefers_error_over_attempted_content() {
+ let env = HookEnvelope::from_query_and_body(
+ HookQuery {
+ event: "post-tool-use".into(),
+ agent: Some("antigravity-cli".into()),
+ ..Default::default()
+ },
+ serde_json::json!({
+ "error": "EDIT_FAILED_SENTINEL",
+ "toolCall": {
+ "name": "replace_file_content",
+ "args": {
+ "TargetFile": "/repo/src/main.rs",
+ "ReplacementContent": "CONTENT_WAS_NOT_WRITTEN"
+ }
+ }
+ }),
+ );
+ let body = env.body_excerpt.unwrap();
+ assert!(body.contains("outcome: error"));
+ assert!(body.contains("EDIT_FAILED_SENTINEL"));
+ assert!(!body.contains("CONTENT_WAS_NOT_WRITTEN"));
+ }
+
+ #[test]
+ fn antigravity_generic_tools_and_unrelated_events_fail_closed() {
+ for tool in ["read_url_content", "read_resource", "call_mcp_tool"] {
+ 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": {"message": "NESTED_ARGUMENT_SENTINEL"}
+ },
+ "tool_response": "UNPROVEN_OUTPUT_SENTINEL"
+ }),
+ );
+ assert_eq!(
+ env.body_excerpt.as_deref(),
+ Some("tool_family: unknown\noutcome: unknown")
+ );
+ }
+
+ let notification = HookEnvelope::from_query_and_body(
+ HookQuery {
+ event: "notification".into(),
+ agent: Some("antigravity-cli".into()),
+ ..Default::default()
+ },
+ serde_json::json!({
+ "toolCall": {
+ "args": {"message": "NESTED_ARGUMENT_SENTINEL"}
+ }
+ }),
+ );
+ assert!(notification.body_excerpt.is_none());
+ }
+
#[test]
fn pi_post_outcomes_and_stable_id_are_rendered() {
for (is_error, outcome) in [
diff --git a/docs/marker-file.md b/docs/marker-file.md
index c037fac4..174480a7 100644
--- a/docs/marker-file.md
+++ b/docs/marker-file.md
@@ -206,7 +206,12 @@ an agent-provided validated call ID when their documented schema proves one,
and a PostToolUse outcome class. `PreToolUse` never retains commands,
arguments, paths, input bodies, or arbitrary tool names. `PostToolUse` appends
its existing tool-response/error excerpt and caps the complete rendered body at
-2,000 UTF-8-safe bytes. Unsupported tool envelopes do not gain a PreToolUse
+2,000 UTF-8-safe bytes. Antigravity's successful file-edit events fall back to
+the bounded replacement or written-content field in `toolCall.args` because its
+hook payload does not include an output field; failed edits retain the error
+instead. The fallback is Antigravity-only and is discarded with any event
+rejected by capture exclusions.
+Unsupported tool envelopes do not gain a PreToolUse
body, and association is only by matching agent-provided call IDs. User-prompt stores its prompt
text, notification stores its message/text, and post-compaction stores its
summary; other event bodies are currently empty unless explicitly supported.