#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PYTHON_BIN="${PYTHON_BIN:-python3}"

export PIXVERSE_AGENT_PLUGIN_ROOT="$ROOT"
export PIXVERSE_AGENT_RUNTIME_EXECUTABLE="$ROOT/scripts/pixverse-runtime"
if [[ -f "$ROOT/.codex-plugin/plugin.json" ]]; then
  export PIXVERSE_CLI_SOURCE="codex-plugin"
else
  export PIXVERSE_CLI_SOURCE="agent-plugin"
fi
RUNTIME_ROOT="$ROOT"
if [[ -d "$ROOT/packages/runtime/pixverse_runtime" ]]; then
  RUNTIME_ROOT="$ROOT/packages/runtime"
fi
export PYTHONPATH="$RUNTIME_ROOT${PYTHONPATH:+:$PYTHONPATH}"

exec "$PYTHON_BIN" -m pixverse_runtime.cli "$@"
