#!/usr/bin/env bash
# The Steward — Projects onboarding TUI launcher. Finds a python that has `textual` (the `ir` client
# ships it) and launches orchestrator/onboard_tui.py. Searches the pipx venv (current `ir` install),
# the uv-tool venv (older `ir`), `ir`'s own interpreter, and plain python3 — first hit with textual wins.
set -u
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# resolve the python that backs the `ir` console-script (most reliable across pipx/uv installs)
IR_PY=""
if command -v ir >/dev/null 2>&1; then
  IR_PY="$(dirname "$(readlink -f "$(command -v ir)")")/python"
fi

for PY in \
    "$HOME/.local/share/pipx/venvs/inferroute/bin/python" \
    "$HOME/.local/share/uv/tools/inferroute/bin/python3" \
    "$IR_PY" \
    python3; do
  [ -n "$PY" ] || continue
  command -v "$PY" >/dev/null 2>&1 || continue
  if "$PY" -c "import textual" 2>/dev/null; then
    exec "$PY" "$HERE/onboard_tui.py" "$@"
  fi
done

echo "st-onboard: no python with textual found." >&2
echo "  install it:  pipx install 'inferroute>=0.3.28'   (ships textual), or:  pip install textual" >&2
exit 1
