#!/usr/bin/env bash
set -euo pipefail
# Run from the checkout, with its isolated development server already running.
# Supply a synthetic workspace, a private model selection, and an output directory.
: "${SYNTHETIC_WORKSPACE:?}" "${PROVIDER_INSTANCE:?}" "${PROVIDER_MODEL:?}" "${RUN_ROOT:?}"
run_dir="$RUN_ROOT/$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p "$run_dir" "$SYNTHETIC_WORKSPACE"
node apps/server/src/bin.ts project add --base-dir .t3 --title 'Command output evidence' "$SYNTHETIC_WORKSPACE" > "$run_dir/project.json"
for count in 100000 3000; do
  node apps/server/src/bin.ts thread start --base-dir .t3 \
    --provider "$PROVIDER_INSTANCE" --model "$PROVIDER_MODEL" \
    --title "Command output: $count lines" --json --wait \
    "$SYNTHETIC_WORKSPACE" \
    "Run this exact command as one Bash call, then reply finished: seq 1 $count | sed 's/^/build log line /'" \
    > "$run_dir/turn-$count.json"
done
printf '%s\n' "$run_dir"
