#!/usr/bin/env bash
# Repository-relative entry point for the detached Codex login watcher.
set -uo pipefail

SCRIPT_DIR=$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
ROOT=$(dirname -- "$SCRIPT_DIR")
PY="$ROOT/.venv/bin/python"
if [ ! -x "$PY" ]; then
  PY=""
  for name in python3 python3.14 python3.13 python3.12; do
    candidate=$(command -v "$name" 2>/dev/null || true)
    if [ -n "$candidate" ] && "$candidate" -c 'import sys; raise SystemExit(sys.version_info < (3, 12))' 2>/dev/null; then
      PY=$candidate
      break
    fi
  done
fi
[ -n "$PY" ] || { echo "subfleet: Python 3.12 or newer is required" >&2; exit 2; }

export PYTHONPATH="$ROOT${PYTHONPATH:+:$PYTHONPATH}"
exec "$PY" -m subfleet.login "$@"
