Skip to content

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

Rust

fix(hooks): capture Grok tool observation bodies

AkitaOnRails9746eba64001
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87b31cb3..3a3b3aba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
+- Grok Build CLI tool observations are no longer stored with an empty body.
+ Grok posts Claude Code's snake_case tool fields (`tool_name` / `tool_input` /
+ `tool_use_id`), but it was missing from both `closed_tool_agent` and the
+ tool-metadata agent match, so every `PostToolUse` body extraction returned
+ nothing while the observation itself was still captured. Grok now shares the
+ Claude Code tool mapping, so tool family, outcome and output land in the
+ body. (#931)
- `ai-memory bootstrap` on a repository small enough for one chunk no longer
asks the provider for 64K output tokens. The output cap was keyed on the
number of chunks, so the only chunk of a small repo got the one-shot cap
diff --git a/crates/ai-memory-hooks/src/capture_policy.rs b/crates/ai-memory-hooks/src/capture_policy.rs
index cc4737aa..9614a200 100644
--- a/crates/ai-memory-hooks/src/capture_policy.rs
+++ b/crates/ai-memory-hooks/src/capture_policy.rs
@@ -166,7 +166,14 @@ pub(crate) fn tool_observation_metadata(
// camelCase — all captured live (engine v0.16.5, #512).
// Native Codex 0.154 uses these same top-level fields, including
// `tool_use_id` on both sides of a tool call.
- AgentKind::ClaudeCode | AgentKind::CommandCode | AgentKind::Codex | AgentKind::Zcode => (
+ // Grok Build CLI posts Claude Code's snake_case aliases
+ // (`tool_name` / `tool_input` / `tool_use_id`) on its tool hooks
+ // alongside camelCase, so it shares this mapping (#931).
+ AgentKind::ClaudeCode
+ | AgentKind::CommandCode
+ | AgentKind::Codex
+ | AgentKind::Grok
+ | AgentKind::Zcode => (
object.get("tool_name")?.as_str()?,
object.get("tool_use_id").and_then(Value::as_str),
),
@@ -211,6 +218,7 @@ pub(crate) fn tool_observation_metadata(
AgentKind::ClaudeCode
| AgentKind::CommandCode
| AgentKind::Codex
+ | AgentKind::Grok
| AgentKind::Hermes
| AgentKind::KiroCli
| AgentKind::Pool
diff --git a/crates/ai-memory-hooks/src/payload.rs b/crates/ai-memory-hooks/src/payload.rs
index 4601e4cf..e5a700e0 100644
--- a/crates/ai-memory-hooks/src/payload.rs
+++ b/crates/ai-memory-hooks/src/payload.rs
@@ -698,6 +698,7 @@ const fn closed_tool_agent(agent: AgentKind) -> bool {
| AgentKind::Pi
| AgentKind::Omp
| AgentKind::AntigravityCli
+ | AgentKind::Grok
| AgentKind::Hermes
| AgentKind::Pool
| AgentKind::Zcode
@@ -2331,6 +2332,35 @@ mod tests {
);
}
+ /// Grok Build CLI posts a `PostToolUse` with Claude Code's snake_case
+ /// aliases (`tool_name` / `tool_input` / `tool_use_id`). It was absent from
+ /// both `closed_tool_agent` and the `tool_observation_metadata` match, so
+ /// every Grok tool observation was stored with an empty body (#931).
+ #[test]
+ fn grok_post_tool_excerpt_captures_tool_response() {
+ let q = HookQuery {
+ event: "post-tool-use".into(),
+ agent: Some("grok".into()),
+ ..Default::default()
+ };
+ let env = HookEnvelope::from_query_and_body(
+ q,
+ serde_json::json!({
+ "tool_name": "Bash",
+ "tool_input": {"command": "ls"},
+ "tool_use_id": "call_grok_1",
+ "tool_response": {"stdout": "MARKER_GROK_931"},
+ }),
+ );
+ let body = env
+ .body_excerpt
+ .expect("grok post-tool body should not be empty");
+ assert!(
+ body.contains("MARKER_GROK_931"),
+ "grok tool_response should be serialized into the body: {body:?}"
+ );
+ }
+
/// End-to-end: a native-hook user prompt (`event=user-prompt-submit`,
/// string `prompt`) maps to `UserPrompt` and keeps its body text.
#[test]