← back to Abrams
scripts/email-hourly.sh
86 lines
#!/usr/bin/env bash
# email-hourly.sh — send hourly digest of panel activity to steve via George MCP.
# Business hours only (Mon-Fri 9am-6pm PT). After-hours = quiet exit.
set -euo pipefail
cd "$(dirname "$0")/.."
HOUR=$(date +%H)
DOW=$(date +%u) # 1=Mon, 7=Sun
# Business hours gate: Mon-Fri (1-5), 09:00-17:59
if [ "$DOW" -gt 5 ] || [ "$HOUR" -lt 9 ] || [ "$HOUR" -gt 17 ]; then
echo "{\"ts\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\",\"type\":\"email-skip\",\"reason\":\"after-hours\",\"hour\":\"$HOUR\",\"dow\":\"$DOW\"}" >> data/build-log.jsonl
exit 0
fi
STAMP="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
SINCE_FILE="data/.last-email-ts"
SINCE=$(cat "$SINCE_FILE" 2>/dev/null || echo "1970-01-01T00:00:00Z")
# Count events since last email
NEW_EVENTS=$(awk -v since="$SINCE" -F'"' '$4 > since' data/build-log.jsonl 2>/dev/null | wc -l | tr -d ' ')
PROJ_COUNT=$(node -e "try{console.log(JSON.parse(require('fs').readFileSync('data/projects.json','utf8')).count||0)}catch{console.log(0)}")
IDEA_COUNT=$(node -e "try{console.log((JSON.parse(require('fs').readFileSync('data/ideas.json','utf8')).ideas||[]).length)}catch{console.log(0)}")
LIVE_COUNT=$(node -e "try{const p=JSON.parse(require('fs').readFileSync('data/projects.json','utf8')).projects||[];console.log(p.filter(x=>x.status==='live').length)}catch{console.log(0)}")
LEAD_COUNT=$(wc -l < data/leads.jsonl 2>/dev/null | tr -d ' ' || echo 0)
# Compose markdown body
BODY=$(cat <<EOF
# Abrams Panel — Hourly Digest
**As of $STAMP**
- Projects tracked: **$PROJ_COUNT** ($LIVE_COUNT live)
- SWOT analyses: **$IDEA_COUNT**
- Leads captured (total): **$LEAD_COUNT**
- Build events since last email: **$NEW_EVENTS**
## Recent build log
\`\`\`
$(tail -15 data/build-log.jsonl | python3 -c "
import sys, json
for line in sys.stdin:
try:
d = json.loads(line)
ts = d.pop('ts','')[:19].replace('T',' ')
typ = d.pop('type','evt')
print(f'{ts} {typ:18} {json.dumps(d)}')
except: pass
")
\`\`\`
## Live panel
→ http://127.0.0.1:9898/
→ /trademark · /ideas · /wall · /chat
---
YOLO loop tick fires every 15 min - email next at top of next business hour.
---
**Designer Wallcoverings, Inc. · 1234 Ventura Blvd, Sherman Oaks, CA 91423 · info@designerwallcoverings.com**
Internal operations digest, sent to Steven Abrams only. To stop these emails, disable the launchd plist com.abrams.panel-email or reply STOP.
EOF
)
# Send via George Gmail MCP — wrapper script writes a draft JSON; cron-claude reads + sends.
# For now: append to mailbox queue file; a separate watcher posts to George.
mkdir -p data/email-queue
QUEUE="data/email-queue/$(date +%Y%m%d-%H%M%S).json"
cat > "$QUEUE" <<EOF
{
"to": "steve@designerwallcoverings.com",
"subject": "Abrams Panel - hourly @ $(date +%H:%M)",
"body_markdown": $(printf '%s' "$BODY" | python3 -c 'import sys,json;print(json.dumps(sys.stdin.read()))'),
"generated_at": "$STAMP"
}
EOF
echo "$STAMP" > "$SINCE_FILE"
echo "{\"ts\":\"$STAMP\",\"type\":\"email-queued\",\"projects\":$PROJ_COUNT,\"ideas\":$IDEA_COUNT,\"leads\":$LEAD_COUNT,\"events\":$NEW_EVENTS,\"queue_file\":\"$QUEUE\"}" >> data/build-log.jsonl
echo "queued: $QUEUE"