#!/usr/bin/env bash # Pre-commit check: detect duplicate decision IDs across decisions/*.md files. # Fails if the same D-NNN, Q-NNN, or R-NNN appears in more than one file. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" REPO_ROOT="$(dirname "$SCRIPT_DIR")" # Use the decisions_sync.py check-dupes command RESULT=$(python3 "$REPO_ROOT/tooling/db/decisions_sync.py" check-dupes 2>&1) # Parse the JSON result DUPES=$(echo "$RESULT" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('duplicates',0))" 2>/dev/null || echo "0") TOTAL=$(echo "$RESULT" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('total_ids',0))" 2>/dev/null || echo "0") if [ "$DUPES" -gt 0 ]; then echo "check-decision-ids: FAILED — $DUPES duplicate ID(s) found" echo "$RESULT" | python3 -c " import sys, json d = json.load(sys.stdin) for detail in d.get('details', []): print(f' {detail}') " 2>/dev/null exit 1 fi echo "check-decision-ids: OK — $TOTAL unique IDs, no duplicates" exit 0