#!/bin/bash
set -uo pipefail
# Run codex 3 times on the saved prompt, capture each stdout, check parseability with the actual parser
PROMPT=/tmp/last-prompt-codex-stdin-shim_sh.txt
for n in 1 2 3; do
  SBX=$(mktemp -d /tmp/pr-review-XXXX)
  ( cd "$SBX" && PWD="$SBX" OLDPWD="$SBX" /home/claude/repos/codex-pr-reviewer/codex-stdin-shim.sh < "$PROMPT" > /tmp/cj/raw$n.txt 2>/tmp/cj/raw$n.err )
  echo "=== run $n exit=$? stdout_bytes=$(wc -c < /tmp/cj/raw$n.txt) ==="
  echo "--- first 3 lines ---"
  head -3 /tmp/cj/raw$n.txt
  echo "--- last 3 lines ---"
  tail -3 /tmp/cj/raw$n.txt
  rm -rf "$SBX"
done
echo "ALLDONE"
