#!/usr/bin/env bash
#
# test-kilo-bench — regression gate for the Kilo Code CLI (kilo) integration.
#
# Builds Zentty in Debug (or reuses a derived build, see --no-build) and runs
# the agent-bench harness against every scenario the kilo profile defines.
# Strict mode rejects auth-skip / binary-skip outcomes so a missing binary or
# auth blocker fails the gate rather than silently passing.
#
# Kilo is a manifest agent (ZenttyResources/agents/kilo.json) on the
# opencode-plugin family: the bench materializes its wrapper into the run
# dir and drives it through the shared zentty-opencode-zentty.js plugin.
#
# Re-run this after:
#   * any kilo CLI bump (it is the upstream side of the contract)
#   * changes to AgentLaunchBootstrap.openCodeFamilyPlan / kilo.json
#   * changes to the shared zentty-opencode-zentty.js plugin
#   * changes to scripts/agent-bench/profiles/kilo.json
#
# Usage:
#   scripts/test-kilo-bench                 # full sweep, builds first
#   scripts/test-kilo-bench --no-build      # skip xcodebuild, reuse last build
#   scripts/test-kilo-bench --scenarios smoke,restore_launch
#

set -euo pipefail

cd "$(dirname "$0")/.."

NO_BUILD=0
SCENARIOS="smoke,session_capture,approval,restore_launch,manual_compact"
while [[ $# -gt 0 ]]; do
  case "$1" in
    --no-build) NO_BUILD=1; shift ;;
    --scenarios) SCENARIOS="$2"; shift 2 ;;
    --scenarios=*) SCENARIOS="${1#--scenarios=}"; shift ;;
    -h|--help)
      sed -n '2,26p' "$0"
      exit 0
      ;;
    *)
      echo "Unknown argument: $1" >&2
      exit 2
      ;;
  esac
done

BENCH_ARGS=(run --agents kilo --scenarios "$SCENARIOS" --strict)
if [[ $NO_BUILD -eq 1 ]]; then
  BENCH_ARGS+=(--no-build)
fi

echo "==> Running agent-bench against scenarios: $SCENARIOS"
python3 scripts/agent-bench/agent_bench.py "${BENCH_ARGS[@]}"
