#!/bin/bash # CKB Pre-commit Hook # Blocks commits with critical risk changes # # Installation: # cp examples/hooks/pre-commit .git/hooks/pre-commit # chmod +x .git/hooks/pre-commit set -e # Check if CKB is installed if ! command -v ckb &> /dev/null; then echo "CKB not installed, skipping impact analysis" exit 0 fi # Check if we have staged changes if git diff --cached --quiet; then exit 0 fi echo "Running CKB impact analysis..." # Run impact analysis on staged changes RESULT=$(ckb impact diff --staged --format=json 2>/dev/null || echo '{"summary":{}}') RISK=$(echo "$RESULT" | jq -r '.summary.estimatedRisk // "unknown"') SYMBOLS=$(echo "$RESULT" | jq '.summary.symbolsChanged // 0') AFFECTED=$(echo "$RESULT" | jq '.summary.transitivelyAffected // 0') MODULES=$(echo "$RESULT" | jq '.blastRadius.moduleCount // 0') # Critical risk: block commit if [ "$RISK" = "critical" ]; then echo "" echo "⛔ CRITICAL RISK DETECTED" echo "" echo " Symbols changed: $SYMBOLS" echo " Transitively affected: $AFFECTED" echo " Modules in blast radius: $MODULES" echo "" echo " Review the impact before committing:" echo " $ ckb impact diff --staged" echo "" echo " To bypass this check:" echo " $ git commit --no-verify" echo "" exit 1 fi # High risk: warn but allow if [ "$RISK" = "high" ]; then echo "" echo "⚠️ HIGH RISK CHANGE" echo "" echo " Symbols changed: $SYMBOLS" echo " Transitively affected: $AFFECTED" echo " Modules in blast radius: $MODULES" echo "" echo " Consider running full test suite before pushing." echo "" fi # Medium risk: info only if [ "$RISK" = "medium" ]; then echo "ℹ️ Medium risk: $SYMBOLS symbols changed, $AFFECTED affected" fi exit 0