Skip to content

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

Rust

fix(core): deliver kimi handoffs on user-prompt, not session-start

Lucas Oliveira526f4bd8a0c6
diff --git a/crates/ai-memory-core/src/ids.rs b/crates/ai-memory-core/src/ids.rs
index cbde6213..cb8dbff7 100644
--- a/crates/ai-memory-core/src/ids.rs
+++ b/crates/ai-memory-core/src/ids.rs
@@ -300,9 +300,32 @@ impl AgentKind {
/// tool. Unknown future agents return `false` until we know their
/// SessionStart stdout semantics; accepting a handoff is single-use and
/// should fail safe.
+ ///
+ /// Kimi Code fires `SessionStart` but discards the hook's stdout/result
+ /// entirely (`packages/agent-core/src/session/index.ts` ignores the
+ /// dispatch return, verified in the v0.28.1 source), so the handoff is
+ /// delivered on `UserPromptSubmit` instead — see
+ /// [`Self::user_prompt_injects_handoff`].
#[must_use]
pub fn session_start_injects_handoff(self) -> bool {
- !matches!(self, Self::Crush | Self::Grok | Self::Zero | Self::Other)
+ !matches!(
+ self,
+ Self::Crush | Self::Grok | Self::Zero | Self::KimiCode | Self::Other
+ )
+ }
+
+ /// Whether this agent injects the native `user-prompt` (UserPromptSubmit)
+ /// hook's stdout into the upcoming turn as context. Only Kimi Code does:
+ /// its `SessionStart` stdout is discarded (see
+ /// [`Self::session_start_injects_handoff`]), while `UserPromptSubmit`
+ /// stdout is prepended to the turn as a user message with
+ /// `origin: {kind: 'hook_result'}` (`agent/turn/index.ts`,
+ /// `session/hooks/user-prompt.ts`, verified in the v0.28.1 source).
+ /// Empty stdout injects nothing, so the hook prints the raw handoff body
+ /// or nothing at all — never a JSON envelope.
+ #[must_use]
+ pub fn user_prompt_injects_handoff(self) -> bool {
+ matches!(self, Self::KimiCode)
}
}
@@ -387,8 +410,22 @@ mod tests {
);
// Unknown tags still degrade to Other.
assert_eq!(AgentKind::from_wire("kimi-2"), AgentKind::Other);
- // Kimi Code can inject the session-start handoff (consumes additionalContext).
- assert!(AgentKind::KimiCode.session_start_injects_handoff());
+ // Kimi Code discards SessionStart stdout (verified in the v0.28.1
+ // source), so the handoff is delivered on UserPromptSubmit instead.
+ assert!(!AgentKind::KimiCode.session_start_injects_handoff());
+ assert!(AgentKind::KimiCode.user_prompt_injects_handoff());
+ }
+
+ #[test]
+ fn user_prompt_handoff_injection_is_kimi_only() {
+ for agent in AgentKind::ALL {
+ assert_eq!(
+ agent.user_prompt_injects_handoff(),
+ agent == AgentKind::KimiCode,
+ "{}",
+ agent.as_str()
+ );
+ }
}
#[test]