#!/bin/bash
# AutoWorkflow Post-Bash Router Hook
# Runs on: PostToolUse for Bash
# Purpose: Route bash commands to appropriate post-action hooks
#
# Routes:
# - git commit → post-commit.sh (BLUEPRINT update reminder)

# Project directory (use env var if set, otherwise current directory)
PROJECT_DIR="${CLAUDE_PROJECT_DIR:-.}"

# Read JSON input from stdin (Claude Code hooks pass data via stdin)
INPUT_JSON=$(cat)

# Extract command from JSON
if echo "$INPUT_JSON" | grep -q '"command"'; then
    TOOL_INPUT=$(echo "$INPUT_JSON" | grep -o '"command"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/"command"[[:space:]]*:[[:space:]]*"//' | sed 's/"$//')
else
    TOOL_INPUT="$INPUT_JSON"
fi

# Check if this was a git commit command
if echo "$TOOL_INPUT" | grep -qE "git\s+commit"; then
    # Route to post-commit hook
    "$PROJECT_DIR/.claude/hooks/post-commit.sh"
    exit $?
fi

# No routing needed for other commands
exit 0
