#!/usr/bin/env bash
# usage: start-rows.sh <before|after> <builddir> <projdir> <basedir> <row...>
set -u
build=$1; dir=$2; proj=$3; base=$4; shift 4
cd "$dir"
for row in "$@"; do
  case $row in
    R1) at="14:18"; extra="" ;;
    R3) at="14:20"; extra="" ;;
    R6) at=""; extra="" ;;
  esac
  if [ "$row" = R6 ]; then
    msg="Do not use any tools at all. Reply with exactly one line: OK-R6-$build"
  else
    msg="Use only the CronCreate tool. Do not use any other tool, do not read or edit any file. Schedule a one-shot (non-recurring) cron for $at UTC today (the machine's local time zone is UTC) whose prompt is: 'Append the line FIRED-$row-$build followed by the current UTC time to $proj/cron.log using a single shell append, and do nothing else.' Then reply DONE."
  fi
  node apps/server/src/bin.ts thread start "$proj" "$msg" --base-dir "$base" --title "$row-$build" --provider claudeAgent --model claude-sonnet-5-5 --wait --json > /tmp/ev-23636/out/$row-$build.start.json 2>&1 &
done
wait
