#!/usr/bin/env bash
set -euo pipefail

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
control_root="$(cd "${script_dir}/.." && pwd)"
runtime_repo="${control_root}/../zhct/zhctproject/aliyun_ops_agent"
agent_bin="${runtime_repo}/.venv/bin/aliyun-ops-agent"
state_db="${runtime_repo}/state/zhctprompt-control.db"
profile="${ZHCT_ALIYUN_OPS_PROFILE:-ai-nutrition-audit}"
region="${ZHCT_ALIYUN_OPS_REGION:-cn-beijing}"

if [[ ! -x "$agent_bin" ]]; then
  echo "Aliyun Ops Agent is not installed at: $agent_bin" >&2
  echo "See: ${runtime_repo}/README.md" >&2
  exit 1
fi

exec "$agent_bin" \
  --backend cli \
  --profile "$profile" \
  --region "$region" \
  --state-db "$state_db" \
  "$@"
