Files
Felipe Neves RicardoandClaude Opus 5.5 2c0fab6155 fix(hooks): send the [briefing] keys on the session-start handoff GET (#998)
docs/marker-file.md says the hook scripts forward `briefing` and
`briefing_budget` on the handoff lookup when the marker opts in. Only the
Kiro CLI and Kimi Code scripts did; the session-start scripts of Claude
Code, Codex, Cursor, Gemini CLI, OpenCode, Command Code, Devin and
Antigravity CLI built the GET from ai_memory_marker_qs alone, and the
PowerShell library added the briefing query only for Kimi and Grok. A
script install with `inject_on_session_start = true` therefore got the
handoff without the brief, while the native `ai-memory hook` command
sent both.

Each of those scripts now appends ai_memory_briefing_qs to its handoff
GET, and Invoke-AiMemoryHook adds Get-AiMemoryBriefingQuery to every
session-start fetch outside Kiro's once-per-session gate. No gate is
added: the native session-start path sends the keys on every start.

tests/hooks/test_lib.sh discovers every bundle whose session-start.sh
fetches the handoff and asserts the keys are present when the marker
opts in and absent when it opts out, plus a static check on the
PowerShell library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019KhB86k7H61CePGZdxtwyz
2026-09-30 17:51:53 -03:00

27 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# codex SessionStart hook.
# 1. Forwards the event JSON to the ai-memory server (fire-and-forget).
# 2. Synchronously fetches any pending cross-agent handoff and prints
# it to stdout — agent CLIs prepend session-start hook stdout to
# the next session, so the resuming agent sees prior context with
# no human in the loop.
#
_lib_dir="$(dirname "$0")"
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
. "$_lib_dir/_lib.sh"
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
PAYLOAD=$(cat)
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
QS=$(ai_memory_marker_qs "$CWD")
# The `[briefing]` opt-in rides the handoff GET, as in the native hook.
BRIEF_QS=$(ai_memory_briefing_qs "$CWD")
SESSION_ID=$(ai_memory_extract_session_id "$PAYLOAD")
SESSION_QS=""
[ -n "$SESSION_ID" ] && SESSION_QS="&session_id=$(ai_memory_url_encode "$SESSION_ID")"
printf '%s' "$PAYLOAD" \
| ai_memory_post_hook "$SERVER/hook?event=session-start&agent=codex${QS}" >/dev/null 2>&1 || true
ai_memory_get_handoff "$SERVER/handoff?agent=codex${QS}${SESSION_QS}${BRIEF_QS}" 2>/dev/null || true
exit 0