#!/bin/bash
# Thin wrapper that delegates to @quantiya/codevibe-codex-plugin

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

DELEGATE="$SCRIPT_DIR/../node_modules/@quantiya/codevibe-codex-plugin/bin/codevibe-codex"

if [ ! -f "$DELEGATE" ]; then
  echo "Error: @quantiya/codevibe-codex-plugin not found. Try reinstalling: npm install -g @quantiya/codevibe" >&2
  exit 1
fi

case "${1:-}" in
  login|logout|help|--help|-h|version|--version|-v)
    ;;
  *)
    if ! command -v codex >/dev/null 2>&1; then
      cat >&2 <<'EOF'

Codex CLI is not installed on this system.

CodeVibe attaches to the Codex CLI — you need it installed first.

  Install Codex CLI:
    npm install -g @openai/codex

Then run codevibe-codex again.

Learn more: https://quantiya.ai/codevibe
EOF
      exit 1
    fi
    ;;
esac

exec "$DELEGATE" "$@"
