#!/usr/bin/env bash # apricot-batch-status.sh — One-line check on all currently-running autoplay # batches on apricot, plus wall-clock summaries for any recently-completed ones. # # Usage: # tools/apricot-batch-status.sh # latest 3 batches + live procs # tools/apricot-batch-status.sh --latest # just the newest batch dir # tools/apricot-batch-status.sh # a specific stamp # # Intended replacement for the ad-hoc `ssh apricot "for d in ...; do ..."` # one-liners the coordinator keeps re-deriving. set -euo pipefail MODE="${1:-tail}" case "$MODE" in --latest) DEPTH=1 ;; tail) DEPTH=3 ;; *) DEPTH=0; STAMP="$MODE" ;; esac read -r -d '' QUERY <<'EOF' || true set -e : "${DEPTH:=3}" : "${STAMP:=}" ROOT="$HOME/.cache/mc-batches" [ -d "$ROOT" ] || { echo "no $ROOT"; exit 0; } echo "=== apricot $(date +'%Y-%m-%d %H:%M:%S') ===" echo "--- live processes ---" echo " godot: $(pgrep -f 'godot-bin' 2>/dev/null | wc -l)" echo " autoplay-batch: $(pgrep -f 'autoplay-batch' 2>/dev/null | wc -l)" echo " cargo: $(pgrep -f 'cargo build' 2>/dev/null | wc -l)" echo if [ -n "$STAMP" ]; then targets="$ROOT/$STAMP" else targets=$(ls -1dt "$ROOT"/*/ 2>/dev/null | head -"$DEPTH") fi for stamp_dir in $targets; do [ -d "$stamp_dir" ] || continue echo "--- $(basename "$stamp_dir") ---" # For each mode subdir (smoke | gpu-* | clan-*) or the stamp dir itself: for batch in "$stamp_dir" "$stamp_dir"/smoke "$stamp_dir"/gpu-* "$stamp_dir"/clan-*; do [ -d "$batch" ] || continue compgen -G "$batch/game_*" > /dev/null || continue n=$(ls -d "$batch"/game_* 2>/dev/null | wc -l) done_n=0 progress_n=0 victory_n=0 for g in "$batch"/game_*; do s="$g/turn_stats.jsonl" [ -s "$s" ] || continue last=$(tail -1 "$s" 2>/dev/null) outcome=$(echo "$last" | grep -oE '"outcome":"[^"]+"' | head -1) if echo "$outcome" | grep -q 'victory'; then victory_n=$((victory_n + 1)) done_n=$((done_n + 1)) elif echo "$outcome" | grep -qE '(max_turns|in_progress)'; then progress_n=$((progress_n + 1)) else done_n=$((done_n + 1)) fi done label=$([ "$batch" = "$stamp_dir" ] && echo "(root)" || echo "$(basename "$batch")") echo " $label: $n games | victories=$victory_n, in_progress=$progress_n, other=$((n - victory_n - progress_n))" done echo done EOF ssh apricot "DEPTH=${DEPTH} STAMP='${STAMP:-}' bash -s" <<< "$QUERY"