#!/usr/bin/env bash
# Launcher de Theus CLI (paquete de release).
# Ejecuta el bundle self-contained cli.js con Bun.
set -euo pipefail

SOURCE="${BASH_SOURCE[0]}"
while [[ -L "$SOURCE" ]]; do
  DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
  SOURCE="$(readlink "$SOURCE")"
  [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE"
done
APP="$(cd -P "$(dirname "$SOURCE")/.." && pwd)"

if ! command -v bun >/dev/null 2>&1; then
  echo "theus: Bun no esta instalado. Instalalo desde https://bun.sh y reintenta." >&2
  exit 1
fi

if [[ ! -f "$APP/cli.js" ]]; then
  echo "theus: no encuentro el bundle en $APP/cli.js. Reinstala con: curl -fsSL https://theus.pe/install.sh | bash" >&2
  exit 1
fi

exec bun "$APP/cli.js" "$@"
