#!/bin/bash # Post-commit hook: Send dev-alerts for feature specs and significant changes # Get commit info COMMIT_HASH=$(git rev-parse --short HEAD) COMMIT_MSG=$(git log -1 --pretty=%B) BRANCH=$(git rev-parse --abbrev-ref HEAD) AUTHOR=$(git log -1 --pretty=%an) # Determine project from submodule path if git rev-parse --show-toplevel | grep -q "guru-connect"; then PROJECT="guruconnect" PROJECT_NAME="GuruConnect" elif git rev-parse --show-toplevel | grep -q "guru-rmm"; then PROJECT="gururmm" PROJECT_NAME="GuruRMM" else PROJECT="claudetools" PROJECT_NAME="ClaudeTools" fi # Check if this is a spec commit (new SPEC-NNN file or updated roadmap) SPEC_FILES=$(git diff-tree --no-commit-id --name-only -r HEAD | grep -E 'docs/specs/SPEC-[0-9]+-.*\.md$') ROADMAP_UPDATED=$(git diff-tree --no-commit-id --name-only -r HEAD | grep -E 'FEATURE_ROADMAP\.md$') if [[ -n "$SPEC_FILES" ]]; then # Extract SPEC number and name from first spec file SPEC_FILE=$(echo "$SPEC_FILES" | head -1) SPEC_NUM=$(echo "$SPEC_FILE" | grep -oE 'SPEC-[0-9]+') SPEC_NAME=$(echo "$SPEC_FILE" | sed -E 's/.*SPEC-[0-9]+-(.*)\.md$/\1/' | tr '-' ' ' | sed 's/.*/\u&/') # Read spec file to extract key info SPEC_PATH=$(git rev-parse --show-toplevel)/"$SPEC_FILE" PRIORITY=$(grep -m1 "^\*\*Priority:\*\*" "$SPEC_PATH" | sed 's/.*Priority:\*\* //' | tr -d '\n') EFFORT=$(grep -m1 "^\*\*Estimated Effort:\*\*" "$SPEC_PATH" | sed 's/.*Estimated Effort:\*\* //' | tr -d '\n') OVERVIEW=$(sed -n '/^## Overview/,/^##/p' "$SPEC_PATH" | grep -v "^##" | head -5 | tr '\n' ' ') # Send dev-alerts message SESSION_ID=$(hostname)/claude-main # Build JSON payload with proper escaping JSON_PAYLOAD=$(python3 -c "import json; print(json.dumps({ 'from_session': '$SESSION_ID', 'to_session': 'dev-alerts', 'project_key': '$PROJECT', 'subject': '$PROJECT_NAME Feature Spec: $SPEC_NUM $SPEC_NAME', 'body': '''New $PROJECT_NAME feature specification created. $SPEC_NUM: $SPEC_NAME Priority: $PRIORITY | Effort: $EFFORT OVERVIEW: $OVERVIEW Commit: $COMMIT_HASH on $BRANCH Author: $AUTHOR 🤖 Auto-generated via post-commit hook''' }))") curl -s -X POST http://172.16.3.30:8001/api/coord/messages \ -H "Content-Type: application/json" \ -d "$JSON_PAYLOAD" > /dev/null 2>&1 fi # Detect build/push events (commit message contains 'spec:', 'feat:', 'fix:', etc.) if echo "$COMMIT_MSG" | grep -qE '^(spec|feat|fix|chore|docs|build):'; then COMMIT_TYPE=$(echo "$COMMIT_MSG" | grep -oE '^[a-z]+:' | tr -d ':') # Only send build alerts for significant commits on main branch if [[ "$BRANCH" == "main" ]] && [[ "$COMMIT_TYPE" =~ ^(spec|feat|fix|build)$ ]]; then FILES_CHANGED=$(git diff-tree --no-commit-id --name-only -r HEAD | wc -l | tr -d ' ') SESSION_ID=$(hostname)/claude-main # Build JSON payload with proper escaping JSON_PAYLOAD=$(python3 -c "import json; print(json.dumps({ 'from_session': '$SESSION_ID', 'to_session': 'dev-alerts', 'project_key': '$PROJECT', 'subject': '$PROJECT_NAME Build: $COMMIT_TYPE on main', 'body': '''$PROJECT_NAME main branch updated. COMMIT: $COMMIT_HASH TYPE: $COMMIT_TYPE FILES CHANGED: $FILES_CHANGED BRANCH: $BRANCH AUTHOR: $AUTHOR MESSAGE: $COMMIT_MSG 🔨 Auto-generated via post-commit hook''' }))") curl -s -X POST http://172.16.3.30:8001/api/coord/messages \ -H "Content-Type: application/json" \ -d "$JSON_PAYLOAD" > /dev/null 2>&1 fi fi exit 0