Skip to content

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

Rust

Merge remote-tracking branch 'origin/main' into feat/1645-lossless-project-merge

AkitaOnRails3452ff8fdd02
diff --cc tests/hooks/test_lib.sh
index efaab92e,57748926..42df7b80
--- a/tests/hooks/test_lib.sh
+++ b/tests/hooks/test_lib.sh
@@@ -1255,60 -1204,8 +1255,59 @@@ for script in "$(dirname "$0")"/../../h
done
# Guards the discovery itself: an empty glob or a renamed helper would
# otherwise pass with nothing checked.
- assert_eq "session-start bundles that fetch the handoff were found" "yes" \
- "$([ "$BRIEF_BUNDLES" -ge 9 ] && printf 'yes' || printf 'no (%s)' "$BRIEF_BUNDLES")"
+ assert_eq "all handoff-fetching scripts were checked for briefing" "13" "$BRIEF_SCRIPTS"
+# --- the subagent-start bundle hands the subagent its brief --------------
+# `[briefing] inject_on_subagent_start` gives each subagent the
+# project brief from the read-only `/brief` route, as the native hook does,
+# and never asks `/handoff`, whose fetch claims the parent session's baton.
+# Without that opt-in (the session-start one alone included) the bundle
+# replies `{}` as it always did.
+SUB_CURL_BIN="$TMP/fake-brief-curl-bin"
+mkdir -p "$SUB_CURL_BIN"
+cat >"$SUB_CURL_BIN/curl" <<'EOF'
+#!/bin/sh
+printf '%s\n' "$*" >>"$AI_MEMORY_CURL_LOG"
+case "$*" in
+ *'/brief?'*) printf 'subagent-brief-context' ;;
+ *'/handoff?'*) printf 'parent-handoff' ;;
+esac
+EOF
+chmod +x "$SUB_CURL_BIN/curl"
+SUB_REPO="$TMP/subagent-brief-on"
+mkdir -p "$SUB_REPO"
+printf '[briefing]\ninject_on_subagent_start = true\nmax_chars = 6000\n' >"$SUB_REPO/.ai-memory.toml"
+
+# Runs the subagent-start.sh bundle from repository "$1" and prints its stdout.
+subagent_start_output() {
+ rm -rf "$TMP/subagent-data" "$FAKE_CURL_LOG"
+ printf '{"cwd":"%s","session_id":"parent-s","hook_event_name":"SubagentStart","agent_id":"agent-1","agent_type":"Explore"}' "$1" \
+ | PATH="$SUB_CURL_BIN:$PATH" AI_MEMORY_CURL_LOG="$FAKE_CURL_LOG" \
+ AI_MEMORY_DATA_DIR="$TMP/subagent-data" AI_MEMORY_HOOK_URL='http://memory.test' \
+ sh "$(dirname "$0")/../../hooks/claude-code/subagent-start.sh" 2>/dev/null
+}
+
+assert_eq "the subagent-start bundle injects the opted-in brief" \
+ '{"hookSpecificOutput":{"hookEventName":"SubagentStart","additionalContext":"subagent-brief-context"}}' \
+ "$(subagent_start_output "$SUB_REPO")"
+assert_eq "the subagent brief GET carries the opt-in and the budget" "yes" \
+ "$(grep -q '/brief?agent=claude-code&cwd=.*&briefing=true&briefing_budget=6000' "$FAKE_CURL_LOG" && printf 'yes' || printf 'no')"
+assert_eq "a subagent start never fetches the handoff" "no" \
+ "$(grep -q '/handoff?' "$FAKE_CURL_LOG" && printf 'yes' || printf 'no')"
+assert_eq "a subagent start without the subagent opt-in replies {}" "{}" \
+ "$(subagent_start_output "$BRIEF_REPO")"
+assert_eq "a subagent start without the subagent opt-in asks for no brief" "no" \
+ "$(grep -q '/brief?' "$FAKE_CURL_LOG" 2>/dev/null && printf 'yes' || printf 'no')"
+# Hook scripts run without `set -e`; this suite's would end the substitution at
+# the auth-header lookup's non-zero status.
+rm -f "$FAKE_CURL_LOG"
+assert_eq "get_brief refuses a URL without cwd" "" \
+ "$(set +e; export PATH="$SUB_CURL_BIN:$PATH" AI_MEMORY_CURL_LOG="$FAKE_CURL_LOG"
+ ai_memory_get_brief 'http://memory.test/brief?agent=claude-code&briefing=true')"
+assert_eq "get_brief fetches a URL with cwd" "subagent-brief-context" \
+ "$(set +e; export PATH="$SUB_CURL_BIN:$PATH" AI_MEMORY_CURL_LOG="$FAKE_CURL_LOG"
+ ai_memory_get_brief 'http://memory.test/brief?agent=claude-code&cwd=%2Frepo&briefing=true')"
+
# --- a handoff is never claimed without a project directory -------------
# `GET /handoff` claims the newest open handoff in whatever project the server
# resolves. A payload that names no directory sent no `cwd`, so the server fell