Skip to content

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

Rust

fix(cli): match the installed user-prompt-submit event stem for kimi

Lucas Oliveira07366605b7a5
diff --git a/crates/ai-memory-cli/src/commands/hook.rs b/crates/ai-memory-cli/src/commands/hook.rs
index a62f4339..ba487f6b 100644
--- a/crates/ai-memory-cli/src/commands/hook.rs
+++ b/crates/ai-memory-cli/src/commands/hook.rs
@@ -18,7 +18,7 @@ use std::time::Duration;
use ai_memory_core::{AgentKind, ManagedRunId, SessionId};
use ai_memory_hooks::capture_policy::metadata_only_body;
-use ai_memory_hooks::{CaptureDisposition, PolicyState};
+use ai_memory_hooks::{CaptureDisposition, HookEvent, PolicyState};
use ai_memory_llm::OidcToken;
use crate::cli::HookArgs;
@@ -497,7 +497,10 @@ where
// into the turn verbatim as a `hook_result` user message. The payload
// carries the native `sessionId`, so the destructive GET can also link
// the managed run to the native session, same as session-start does.
- if args.event == "user-prompt"
+ // The installed kimi hook passes the script stem (`user-prompt-submit`)
+ // while the legacy shell path posts `user-prompt`; HookEvent::parse
+ // canonicalizes both (and the snake/native spellings) to UserPrompt.
+ if HookEvent::parse(&args.event) == HookEvent::UserPrompt
&& AgentKind::from_wire(&args.agent).user_prompt_injects_handoff()
{
let client = build_client();
@@ -1514,6 +1517,47 @@ mod tests {
assert!(request.contains("session_id=session_abc"), "{request}");
}
+ #[tokio::test]
+ async fn kimi_user_prompt_submit_stem_also_delivers_the_handoff() {
+ // The default PosixNative/WindowsNative installs pass the script stem
+ // (`--event user-prompt-submit`), not the legacy `user-prompt` token;
+ // both must trigger delivery or the production path would print `{}`
+ // and kimi would inject it as literal context.
+ let tmp = tempfile::tempdir().unwrap();
+ let (base, mut requests) = serve_requests("200 OK", "AMWS-HANDOFF-DELTA").await;
+ let mut stdout = Vec::new();
+ run_with_payload(
+ Some(tmp.path().to_path_buf()),
+ kimi_hook_args("user-prompt-submit", &base),
+ serde_json::json!({"sessionId": "session_abc", "cwd": tmp.path(), "prompt": "hi"})
+ .to_string(),
+ &mut stdout,
+ |_| Ok(()),
+ )
+ .await
+ .unwrap();
+ assert_eq!(stdout, b"AMWS-HANDOFF-DELTA\n");
+ let request = first_request(&mut requests).await.unwrap();
+ assert!(request.starts_with("GET /handoff?"), "{request}");
+
+ let tmp = tempfile::tempdir().unwrap();
+ let (base, mut requests) = serve_requests("404 Not Found", "").await;
+ let mut stdout = Vec::new();
+ run_with_payload(
+ Some(tmp.path().to_path_buf()),
+ kimi_hook_args("user-prompt-submit", &base),
+ serde_json::json!({"sessionId": "session_abc", "cwd": tmp.path(), "prompt": "hi"})
+ .to_string(),
+ &mut stdout,
+ |_| Ok(()),
+ )
+ .await
+ .unwrap();
+ let request = first_request(&mut requests).await.unwrap();
+ assert!(request.starts_with("GET /handoff?"), "{request}");
+ assert_eq!(stdout, b"");
+ }
+
#[tokio::test]
async fn kimi_user_prompt_prints_nothing_when_no_handoff_is_pending() {
let tmp = tempfile::tempdir().unwrap();
diff --git a/scripts/managed-workstream-acceptance.sh b/scripts/managed-workstream-acceptance.sh
index b39e07f9..5184c2e8 100755
--- a/scripts/managed-workstream-acceptance.sh
+++ b/scripts/managed-workstream-acceptance.sh
@@ -359,11 +359,14 @@ mkdir -p "$KIMI_FAKE_HOME"
"$BIN" --data-dir "$DATA" run --new edge-kimi --executable "$FAKE" \
kimi >"$LOGS/edge-kimi-first.log" 2>&1
)
-[ ! -s "$TMP/kimi-first-argv.log" ] || {
+# The fake echoes one line per argv element, so a zero-argument fresh launch
+# leaves a single empty line in the log; assert no real argument arrived
+# rather than asserting the file is byte-empty.
+if grep -q . "$TMP/kimi-first-argv.log"; then
printf 'fresh kimi launch unexpectedly received a session selector\n' >&2
cat "$TMP/kimi-first-argv.log" >&2
exit 1
-}
+fi
kimi_session_dir=$(find "$KIMI_FAKE_HOME/sessions" -mindepth 2 -maxdepth 2 -type d -print -quit)
[ -n "$kimi_session_dir" ] || {
printf 'fake kimi did not create a native session store\n' >&2