#!/usr/bin/env bash # UserPromptSubmit hook — injects unread coord messages and (in dev mode) active locks. SESSION="$(hostname)/claude-main" API="http://172.16.3.30:8001" SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" MODE_FILE="${SCRIPT_DIR}/current-mode" # --- Unread messages --------------------------------------------------------- result=$(curl -s --connect-timeout 3 "${API}/api/coord/messages?to_session=${SESSION}&unread_only=true" 2>/dev/null) if [ -n "$result" ]; then count=$(echo "$result" | jq '.total' 2>/dev/null) if [ -n "$count" ] && [ "$count" -gt 0 ]; then echo "" echo "============================================================" echo "UNREAD COORD MESSAGES ($count)" echo "============================================================" echo "$result" | jq -r '.messages[] | "FROM: \(.from_session)\nDATE: \(.created_at)\nSUBJECT: \(.subject)\n\nMESSAGE:\n\(.body)\n---"' echo "============================================================" echo "" # Mark all fetched messages as read immediately echo "$result" | jq -r '.messages[].id' | tr -d '\r' | while read -r id; do curl -s -X PUT "${API}/api/coord/messages/${id}/read" >/dev/null 2>&1 done fi fi # --- Active locks (dev mode only) ------------------------------------------- current_mode="" [ -f "$MODE_FILE" ] && current_mode=$(cat "$MODE_FILE" | tr -d '[:space:]') if [ "$current_mode" = "dev" ]; then locks=$(curl -s --connect-timeout 3 "${API}/api/coord/locks" 2>/dev/null) if [ -n "$locks" ]; then lock_count=$(echo "$locks" | jq '.total' 2>/dev/null) if [ -n "$lock_count" ] && [ "$lock_count" -gt 0 ]; then echo "" echo "============================================================" echo "[WARNING] ACTIVE LOCKS ($lock_count) — check before editing" echo "============================================================" echo "$locks" | jq -r '.locks[] | "[DEV MODE] LOCK: \(.project_key) / \(.resource)\n Held by: \(.session_id)\n Reason: \(.description // "none")\n Expires: \(.expires_at // "unknown")\n---"' echo "============================================================" echo "" fi fi fi exit 0