← back to AgentAbrams

snippets/precommit.sh

39 lines

#!/usr/bin/env bash
set -euo pipefail

# precommit.sh — run minimal safety checks before committing.
# Usage: bash snippets/precommit.sh

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

echo "=== AgentAbrams Pre-Commit Checks ==="
echo ""

echo "[1/3] Lint posts for obvious sensitive patterns"
shopt -s nullglob
posts=("$REPO_ROOT"/posts/*.md)
if [ ${#posts[@]} -eq 0 ]; then
    echo "  No posts found; skipping."
else
    for f in "${posts[@]}"; do
        python3 "$REPO_ROOT/snippets/redact_lint.py" "$f"
    done
fi
echo ""

echo "[2/3] Validate skills metadata"
cd "$REPO_ROOT"
python3 "$REPO_ROOT/snippets/validate_skills.py"
echo ""

echo "[3/3] Ensure no .env accidentally staged"
if git diff --cached --name-only 2>/dev/null | grep -E '(^|/)\.env($|[^a-zA-Z0-9_])' >/dev/null 2>&1; then
    echo "ERROR: .env appears staged. Unstage it and keep secrets out of git."
    exit 1
fi
echo "  No .env staged."
echo ""

echo "=== All pre-commit checks passed ==="