#!/bin/sh
# Public-repo hygiene pre-commit hook.
#
# build-loop is open source. This hook blocks a commit that stages a
# private app slug (see scripts/check_private_slugs.py for the editable
# denylist) or runtime memory/state files. Unlike post-commit, this hook
# MUST be able to fail the commit, so it is NOT fire-and-forget — a
# non-zero exit aborts the commit by design.
#
# Idempotent installer chains this after any pre-existing pre-commit;
# this body is the private-slug-guard segment only.

# --- BEGIN private-slug-guard pre-commit ---
RALLY_POINT_TOPLEVEL="$(git rev-parse --show-toplevel 2>/dev/null)"
if [ -z "$RALLY_POINT_TOPLEVEL" ]; then
  echo "private-slug-guard: cannot resolve repo toplevel — refusing to skip the guard" >&2
  exit 2
fi
PRIVATE_SLUG_GUARD="$RALLY_POINT_TOPLEVEL/.git/hooks/.private-slug-check.py"
if [ -f "$PRIVATE_SLUG_GUARD" ]; then
  python3 "$PRIVATE_SLUG_GUARD" || exit 1
fi
RUNTIME_MEMORY_GUARD="$RALLY_POINT_TOPLEVEL/.git/hooks/.runtime-memory-tracking-check.py"
if [ -f "$RUNTIME_MEMORY_GUARD" ]; then
  python3 "$RUNTIME_MEMORY_GUARD" || exit 1
fi
# --- END private-slug-guard pre-commit ---

exit 0
