#!/bin/sh
# Rally Point post-commit capture (cross-tool).
#
# git fires this regardless of which tool (Claude / Codex / plain git)
# made the commit, so it is the durable cross-tool capture boundary.
# Fire-and-forget: all real work is backgrounded and the hook returns 0
# immediately so it can NEVER slow down or fail a commit.
#
# Identity comes from the environment when present:
#   RALLY_POINT_TOOL   (default: unknown; APP_PULSE_TOOL fallback supported)
#   RALLY_POINT_RUN_ID (default: unknown; APP_PULSE_RUN_ID fallback supported)
#   RALLY_POINT_MODEL  (default: unknown; APP_PULSE_MODEL fallback supported)
#
# Idempotent installer chains this after any pre-existing post-commit;
# this body is the Rally Point segment only.

# --- BEGIN rally-point post-commit ---
RALLY_POINT_TOPLEVEL="$(git rev-parse --show-toplevel 2>/dev/null)"
if [ -z "$RALLY_POINT_TOPLEVEL" ]; then
  echo "rally-point post-commit: cannot resolve repo toplevel" >&2
  exit 2
fi
RALLY_POINT_CAPTURE="$RALLY_POINT_TOPLEVEL/.git/hooks/.rally-point-capture.py"
if [ -f "$RALLY_POINT_CAPTURE" ]; then
  (
    python3 "$RALLY_POINT_CAPTURE" >/dev/null 2>&1
  ) </dev/null >/dev/null 2>&1 &
fi
# --- END rally-point post-commit ---
exit 0
