← back to Sanderson Onboard

scripts/cadence_resume.sh

50 lines

#!/bin/zsh
# cadence_resume.sh — daily ~200/day SDG publish resume, hard cap <=500/run, same per-item gates.
# Modeled on com.steve.hollywood-create-resume. Auto-halts if a batch's compliance pass-rate drops
# below THRESHOLD. Each item: settlement-gate + 6-field gate (enforced inside create_sdg.mjs).
set -e
cd "$(dirname "$0")/.."
LOG=pilot/cadence.log
DAILY=${DAILY:-200}
THRESHOLD=${THRESHOLD:-0.85}   # min (created)/(created+held+err) to keep going next day
echo "=== $(date -u +%FT%TZ) SDG cadence run (daily=$DAILY) ===" >> $LOG

# 1) Ensure per-brand full manifests exist + are enriched (idempotent; skips already-built rows via audit)
for b in sanderson harlequin zoffany morris; do
  node scripts/build_manifest.mjs --brand=$b >> $LOG 2>&1 || true
  node scripts/settlement_gate.mjs --brand=$b >> $LOG 2>&1 || true
done

# 2) Assemble a combined, round-robin, most-ready-first queue capped at DAILY
node scripts/assemble_queue.mjs --daily=$DAILY >> $LOG 2>&1

# 2b) SETTLEMENT IMAGE-VISION gate (the legal gate the binding text requires) — local qwen2.5vl, $0.
#     Removes any design whose IMAGE shows bird/butterfly-on-directional-foliage (name gate is not enough).
node scripts/settlement_vision.mjs --file=pilot/queue-today.json >> $LOG 2>&1

# 3) Create+go-live the day's queue (idempotent resume via create-audit.jsonl; caps at 500 hard)
node scripts/create_sdg.mjs --manifest=pilot/queue-today.json --apply --limit=$DAILY >> $LOG 2>&1
RC=$?

# 4) Compliance halt-check: compute pass-rate from the audit tail; halt (unload) if below threshold
node scripts/cadence_healthcheck.mjs --threshold=$THRESHOLD >> $LOG 2>&1 || {
  echo "!! compliance below $THRESHOLD — unloading cadence to halt" >> $LOG
  launchctl unload ~/Library/LaunchAgents/com.steve.sdg-publish-cadence.plist 2>/dev/null || true
}
# 5) TK-11471 WEIGHT PROOF (read-only): assert every variant THIS run created is live with
#    weight>0, and write the fleet-health heartbeat. The SDG cadence is what put 385 zero-weight
#    variants live overnight (TK-11414); create_sdg.mjs was fixed in 8d09eed, and this is the step
#    that proves the fix actually held in a real run instead of assuming it did.
#    The verifier writes its OWN heartbeat (--heartbeat), including on its own failure, so a
#    verifier that dies reports WARN rather than leaving no row at all. Its exit code is CAPTURED
#    and logged, never propagated through `set -e` — verification must never abort the cadence.
#    NOTE `|| VRC=$?`: this script runs under `set -e`, so a bare call would ABORT the cadence the
#    first time the verifier reports FAIL(1)/UNKNOWN(2). A command in a `||` list is exempt from
#    `set -e`, which is what keeps a failing verification non-fatal while still capturing its code.
VRC=0
node scripts/verify_cadence_weights.mjs \
  --heartbeat="$HOME/.claude/skills/sdg-cadence-weight-verify/data/latest.json" >> $LOG 2>&1 || VRC=$?
echo "--- TK-11471 weight verify rc=$VRC (0=PASS 1=FAIL 2=UNKNOWN/WARN) ---" >> $LOG

echo "=== run complete rc=$RC ===" >> $LOG