Skip to content

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

Rust

fix(hooks): extract user-prompt title from Kimi Code content blocks

Lucas Oliveira6b86e505805a
diff --git a/crates/ai-memory-hooks/src/payload.rs b/crates/ai-memory-hooks/src/payload.rs
index 20f296a2..4f1e4a98 100644
--- a/crates/ai-memory-hooks/src/payload.rs
+++ b/crates/ai-memory-hooks/src/payload.rs
@@ -571,7 +571,12 @@ fn best_title_hint(event: HookEvent, raw: &serde_json::Value) -> Option<String>
match event {
HookEvent::SessionStart => extract_string(raw, &["model", "title"]),
HookEvent::UserPrompt => {
- extract_string(raw, &["prompt", "message", "text"]).map(|s| truncate_for_title(&s))
+ // `extract_content` (not `extract_string`): Kimi Code sends
+ // `prompt` as content blocks (`[{"type":"text","text":...}]`),
+ // which only `value_to_text` flattens — plain-string agents
+ // (Claude Code et al.) get the identical value back, so this
+ // widens coverage without changing their behaviour.
+ extract_content(raw, &["prompt", "message", "text"]).map(|s| truncate_for_title(&s))
}
HookEvent::PreToolUse | HookEvent::PostToolUse => {
extract_string(raw, &["tool", "tool_name", "name"])
@@ -1288,6 +1293,30 @@ mod tests {
assert!(title.ends_with('…'));
}
+ /// Kimi Code sends `prompt` as Anthropic-style content blocks, not a
+ /// plain string. The title hint must flatten them exactly like the
+ /// body excerpt does, or the observation title degrades to the bare
+ /// event kind while the body holds the actual prompt.
+ #[test]
+ fn user_prompt_title_flattens_kimi_code_content_blocks() {
+ let q = HookQuery {
+ event: "user-prompt".into(),
+ agent: Some("kimi-code".into()),
+ ..Default::default()
+ };
+ let env = HookEnvelope::from_query_and_body(
+ q,
+ serde_json::json!({
+ "hook_event_name": "UserPromptSubmit",
+ "session_id": "session_kimi-1",
+ "cwd": "/tmp/proj",
+ "prompt": [ { "type": "text", "text": "hello" } ]
+ }),
+ );
+ assert_eq!(env.title_hint.as_deref(), Some("hello"));
+ assert_eq!(env.body_excerpt.as_deref(), Some("hello"));
+ }
+
#[test]
fn post_tool_excerpt_truncates_without_splitting_utf8() {
let q = HookQuery {