#!/usr/bin/env bash # pmo-heartbeat.sh — wake the PMO session while the overnight chain runs. # Self-terminates when inbox-work has no TASKs AND no semaphore slots are held. INBOX=/home/reachableceo/.coordinate/inbox-work SLOTS=/home/_crossfeed/metrics/active LOG=/home/reachableceo/.coordinate/logs/heartbeat.log INTERVAL=3600 while true; do pending=$(ls -1 "$INBOX"/TASK-*.md 2>/dev/null | wc -l) active=$(ls -1 "$SLOTS"/*.pid 2>/dev/null | wc -l) if [ "$pending" -eq 0 ] && [ "$active" -eq 0 ]; then echo "$(date -Is) chain drained — heartbeat exiting" >> "$LOG" exit 0 fi screen -S RCEO-PMO -X stuff "hb: chain check — verify reports, archive, mirror redmine, redispatch flakes, dispatch next$(printf '\r')" echo "$(date -Is) wake sent (pending=$pending active=$active)" >> "$LOG" sleep "$INTERVAL" done