#!/usr/bin/env bash
# Wrapper so cron has a sane PATH and the secrets from .env.
# Usage: run.sh <script.mjs> [args...]
#   run.sh research.mjs
#   run.sh write-daily.mjs
#   run.sh approve.mjs <slug>
set -euo pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Tools (claude is under /root/.local/bin; node/npx under /usr/bin).
export PATH="/root/.local/bin:/usr/bin:/usr/local/bin:$PATH"

# Secrets (REPLICATE_API_TOKEN, etc.)
if [ -f "$DIR/.env" ]; then
  set -a
  . "$DIR/.env"
  set +a
fi

exec node "$DIR/scripts/$1" "${@:2}"
