#!/usr/bin/env bash
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
logs_dir="$repo_root/outputs/logs"
model_dir="$repo_root/outputs/model_outputs/latest"

latest_log="$(ls "$logs_dir"/full_run_*.log 2>/dev/null | sort | tail -n 1 || true)"
latest_run="$(ls -d "$model_dir"/run_* 2>/dev/null | sort | tail -n 1 || true)"

echo "party2d full-run progress"
echo "repo: $repo_root"
echo

if [[ -n "$latest_log" ]]; then
  echo "Latest durable log: $latest_log"
  echo "--- last 40 log lines ---"
  tail -n 40 "$latest_log"
else
  echo "No durable full_run_*.log found under $logs_dir"
fi

echo
if [[ -n "$latest_run" ]]; then
  echo "Latest model run: $latest_run"
  metrics="$latest_run/diagnostics/run_metrics.json"
  if [[ -f "$metrics" ]]; then
    echo "Metrics: $metrics"
    echo "Open the JSON metrics file above for run-summary fields."
  else
    echo "No archived metrics yet. If the run is still sampling, watch the durable log with:"
    if [[ -n "$latest_log" ]]; then
      echo "  tail -f \"$latest_log\""
    else
      echo "  tail -f outputs/logs/full_run_<timestamp>.log"
    fi
  fi
else
  echo "No completed model run found under $model_dir"
fi

echo
echo "To follow a running job live:"
if [[ -n "$latest_log" ]]; then
  echo "  tail -f \"$latest_log\""
else
  echo "  tail -f outputs/logs/full_run_<timestamp>.log"
fi
