#!/usr/bin/env bash
#ddev-generated
## Description: Print the task prompt and wait for an operator-driven attempt; ships no agent, no skills, no rule set
## Credentials: none
set -euo pipefail

# The default adapter, and deliberately an inert one.
#
# "Vanilla by default" means the bed ships nothing tuned: no bundled agent,
# no skills, no rule set. A tuned harness is the thing this bed MEASURES, and
# a bed that shipped one would be grading its own configuration. So the
# default path hands the prompt to a human, who drives whatever agent they
# are actually evaluating, in whatever environment they actually use. Every
# graded run this bed has produced so far was driven exactly this way.
#
# It is also the honest floor for the run contract: it needs no runtime, no
# credentials and no network, so `ddev ai-eval-run` works on a freshly
# cloned bed with nothing else installed.
#
# Contract with ai-eval-run: the run request arrives by environment and file,
# never on stdin, so stdin stays connected to the operator.

RUN_DIR="${APG_RUN_DIR:?manual adapter must be invoked by ai-eval-run}"
TASK_ID="${APG_TASK_ID:-unknown}"
PROMPT_FILE="${APG_PROMPT_FILE:?missing APG_PROMPT_FILE}"

echo
echo "--------------------------------------------------------------------"
echo " Task ${TASK_ID} - give this prompt to the agent under test"
echo "--------------------------------------------------------------------"
cat "${PROMPT_FILE}"
echo "--------------------------------------------------------------------"
echo
echo "The prompt is also at ${PROMPT_FILE}"
if [ -n "${APG_DDEV_PROJECT:-}" ]; then
  echo "The agent should act on the '${APG_DDEV_PROJECT}' bed at ${APG_APPROOT:-.}"
fi
echo

# Non-interactive means nobody is there to drive the attempt. Exiting 0 would
# tell the manifest an attempt ran when none did, and a harness that records
# attempts it did not make is the exact failure this project exists to catch.
if [ ! -t 0 ]; then
  echo "manual: no terminal attached, so no attempt was made." >&2
  echo "        This adapter needs an operator. For an unattended run, select a runtime" >&2
  echo "        adapter with --agent=<name> (see 'ddev ai-eval-run --list-agents')." >&2
  exit 4
fi

read -r -p "Press Enter once the agent has finished its attempt (Ctrl-C to abandon): " _
echo "manual: attempt recorded."
