#!/bin/sh
# PMAT Work Enforcement Hook (master-plan-pmat-work-system.md W-001)
# This hook blocks commits without an active work ticket.

# Check for active work ticket
if ! pmat work status --active >/dev/null 2>&1; then
    echo "COMPLIANCE VIOLATION"
    echo ""
    echo "Action blocked: git commit"
    echo "Reason: No active work ticket"
    echo ""
    echo "To fix:"
    echo "  1. Start work: pmat work start <ticket-id>"
    echo "  2. Or create ticket: pmat work start \"description\" --spec <spec-file>"
    echo ""
    echo "Bypass (NOT RECOMMENDED):"
    echo "  git commit --no-verify"
    exit 1
fi

# Ensure commit message references ticket
TICKET_ID=$(pmat work status --active --quiet 2>/dev/null)
if [ -n "$TICKET_ID" ]; then
    # Check commit message for ticket reference
    if ! grep -qi "$TICKET_ID\|#[0-9]" "$1" 2>/dev/null; then
        echo "Commit message should reference ticket: $TICKET_ID"
    fi
fi

exit 0
