#!/usr/bin/env bash
# The Steward interactive TUI launcher — finds a python with textual (the `ir` uv-tool venv ships it).
set -u
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# pipx is the current `ir` install; uv-tool is the older one; then `ir`'s own interpreter; then python3.
IR_PY=""; command -v ir >/dev/null 2>&1 && IR_PY="$(dirname "$(readlink -f "$(command -v ir)")")/python"
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
  "$PY" -c "import textual" 2>/dev/null && exec "$PY" "$HERE/tui.py" "$@"
done
echo "st-tui: no python with textual found (install: pipx install 'inferroute>=0.3.28', or pip install textual)" >&2
exit 1
