#!/usr/bin/env bash
# Real-app stand-in for `agy acp` (PR #37119): writes an executable named `agy` into <outdir> that runs
# the checkout's own scripts/acp-mock-agent.ts in Antigravity mode. On each prompt the mock sends the
# two-question ask_question form below (the shape agy acp 1.5.x sends, copied from #37119's own test)
# and logs the answer it receives to <outdir>/responses.jsonl. Put <outdir> first on the dev server's PATH.
set -euo pipefail
checkout=$(cd "$1" && pwd)
outdir=$(mkdir -p "$2" && cd "$2" && pwd)
research="Should competitive research run before implementation?"
roles="Which workspace roles may read conversations over MCP?"
schema=$(python3 - "$research" "$roles" <<'PY'
import json, sys
research, roles = sys.argv[1:3]
ask = lambda q, opts: {"type": "string", "title": q, "oneOf": [{"const": str(i + 1), "title": t} for i, t in enumerate(opts)]}
other = lambda q: {"type": "string", "title": "Other", "description": f"Optional free-form answer to: {q}"}
print(json.dumps({"type": "object", "properties": {
    "q1": ask(research, ["(Recommended) Skip research", "Run research first"]), "q1_other": other(research),
    "q2": ask(roles, ["(Recommended) Owner and admin only", "Include support agents"]), "q2_other": other(roles)}}))
PY
)
cat > "$outdir/agy" <<SH
#!/bin/sh
export T3_ACP_ANTIGRAVITY=1 T3_ACP_AGENT_VERSION=1.5.13 T3_ACP_EMIT_ELICITATION=1
export T3_ACP_ELICITATION_RESPONSE_LOG_PATH='$outdir/responses.jsonl'
export T3_ACP_ELICITATION_SCHEMA='$schema'
exec node '$checkout/apps/server/scripts/acp-mock-agent.ts' "\$@"
SH
chmod +x "$outdir/agy"
