Files
claudetools/.claude/scripts/check-messages.sh
Howard Enos 07decf9376 sync: auto-sync from HOWARD-HOME at 2026-05-14 19:07:17
Author: Howard Enos
Machine: HOWARD-HOME
Timestamp: 2026-05-14 19:07:17
2026-05-14 19:07:17 -07:00

59 lines
2.7 KiB
Bash

#!/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 ""
# Fire a Windows toast so the user sees it even if not watching the terminal
toast_body=$(echo "$result" | jq -r '[.messages[] | .from_session + ": " + .subject] | join(", ")' | tr -d '\r')
notify_ps1=$(cygpath -w "${SCRIPT_DIR}/scripts/notify.ps1" 2>/dev/null || echo "${SCRIPT_DIR}/scripts/notify.ps1" | sed 's|^/\([a-zA-Z]\)/|\1:/|')
powershell.exe -NonInteractive -NoProfile -Command \
"& '$notify_ps1' -Title 'ClaudeTools: $count new message(s)' -Message '$toast_body'" \
>/dev/null 2>&1 &
# 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