#!/usr/bin/env bash
# nightly_hermes.sh — fire Hermes a bounded OVERNIGHT autonomous directive (~2am ET),
# using his free 5-hour compute window while Jun sleeps. Reviewed by the 9am kickoff.
# Fires via launchd com.feral.calypso.nightly-hermes.
set -uo pipefail
ENV="/Users/feral/dev/feral-cc-bots/calypso/.env"
LOG="/Users/feral/dev/feral-cc-bots/calypso/specs/malin-harness/nightly_hermes.log"
[ -f "$ENV" ] && { set -a; source "$ENV"; set +a; }

BODY="$(mktemp)"
cat > "$BODY" << 'EOF'
Hermes — OVERNIGHT autonomous queue. Jun's asleep and Cal reviews at 9am, so: NO approval-gated changes to the live system, NO decisions that need conferring. If something genuinely needs a call, leave it noted for the 9am review instead of guessing.

PRIORITY 1 -- render CANDIDATE expression videos (neutral -> emotion -> neutral) for these 15 new emotions, in order. RENDER ONLY: do NOT add anything to the live FC library (Jun batch-approves in the morning). Use the muscle-onset guide so each initiates from the right muscle (anger = brow-furrow first; fear = brows+eyes-wide first; disgust = nose-wrinkle first; etc.). Render as many as your compute window allows; carry the rest to the next night.
  Anger, Fear, Disgust, Horror, Excitement, Awe, Anxiety, Confusion, Satisfaction, Relief, Adoration, Romance, Sexual Desire, Calmness, Awkwardness.

PRIORITY 2 -- generate VARIATIONS of the approved POSITIVE emotions (happy, amused_flirty, + any positive keepers): slightly different takes of each reaction, saved as variants (e.g. happy_2, happy_3, amused_flirty_2 ...) and added to the library. This gives the FC night-time VARIETY so it isn't replaying the same clip. Malin's persona is eager + warm, so positive variety matters most -- lean here. (Cal handles the player rotating among variants; you just render + add them.)

PRIORITY 3 -- if those are caught up: build MILs (Mood Idle Loops) for the already-APPROVED emotions -- short, seamless sustained-mood resting loops, registered to the neutral anchor.

Keep everything bounded + reversible, on disk. Leave a short status (what you rendered + what carries over) for the 9am review. -- Cal (nightly)
EOF

gog gmail send --account jkhybridmotion@gmail.com --to groundgeneralhermes@gmail.com \
  --subject "Overnight autonomous queue: MILs (priority) + candidate renders (review at 9am)" \
  --body-file "$BODY" >> "$LOG" 2>&1
echo "[$(date +%Y-%m-%dT%H:%M:%S%z)] nightly hermes directive sent" >> "$LOG"
rm -f "$BODY"
