← back to Small Business Builder

scripts/overnight-loop.sh

27 lines

#!/bin/bash
# Overnight pipeline — fully local, zero Claude tokens.
# Cycles: re-audit live URLs (regression detection) → top up roasts → idle.
# Designed to run from a launchd plist.

set -u
cd "$(dirname "$0")/.."
LOG="/tmp/overnight-loop.log"

echo "=== $(date) — overnight cycle start ===" >> "$LOG"

# 1) Re-run live HTML audits with regression alerting (cheerio, no LLM).
echo "--- live audits ---" >> "$LOG"
node scripts/audit-public-sites.mjs --rebuild >> "$LOG" 2>&1

# 2) Top up roasts on any rows that lost theirs / new rows added (qwen3 local).
echo "--- roast top-up ---" >> "$LOG"
node scripts/generate-roasts.mjs >> "$LOG" 2>&1

# 3) Trim old log to last 4MB.
LOG_SIZE=$(stat -f%z "$LOG" 2>/dev/null || echo 0)
if [ "$LOG_SIZE" -gt 4194304 ]; then
  tail -c 2097152 "$LOG" > "${LOG}.tmp" && mv "${LOG}.tmp" "$LOG"
fi

echo "=== $(date) — overnight cycle done ===" >> "$LOG"