#!/bin/bash
# orient.sh <phase> <prev_phase|-> <focus files comma-separated> > orientation.md   (runs ssh to the build host)
PHASE=$1; PREV=$2; FOCUS=$3; R=${HARNESS_REMOTE:-spark}; W=${HARNESS_CWD:-/home/zerc/wbbench/pi_work}; PO=${HARNESS_PREV_OUT:-/home/zerc/wbbench/out}
echo "ORIENTATION PACKET for phase $PHASE (already in your context — do not re-read these files)."
echo; echo "## File tree"; ssh $R "cd $W && find . -type f -not -path './target/*' -not -path '*/dist/*' -not -path './.git/*' -printf '%P %s\n' | sort"
if [ "$PREV" != "-" ]; then
  for f in summary.md verify.txt; do t=$(ssh $R "head -c 6000 $PO/$PREV/$f 2>/dev/null"); [ -n "$t" ] && { echo; echo "## previous phase ($PREV) $f"; echo "$t"; }; done
fi
IFS=, ; for f in $FOCUS; do f=$(echo $f | xargs); echo; if ssh $R "test -f $W/$f"; then n=$(ssh $R "wc -l < $W/$f"); echo "## focus file: $f ($n lines)"; ssh $R "head -c 60000 $W/$f"; else echo "## focus file: $f — does not exist yet (you create it)"; fi; done; unset IFS
echo; echo "## Current verify"; ssh $R "export PATH=\$HOME/.cargo/bin:\$PATH DATABASE_URL=postgres://postgres:wb@localhost:5433/wb; timeout 1200 python3 ${HARNESS_VERIFY:-/home/zerc/wbbench/v5/verify_ws.py} $W --quick 2>&1 | grep -v '^JSON '" | head -c 6000
