#!/usr/bin/env bash
# Review package: the working tree against a snapshot index (untracked files included,
# the committed web bundle excluded: minified). Writes OUTFILE, prints its size.
# Usage: wt-review BASE_INDEX OUTFILE TITLE
set -euo pipefail
base=$1; out=$2; title=$3
tmp="$out.index"
cp "$base" "$tmp"
export GIT_INDEX_FILE="$tmp"
git ls-files --others --exclude-standard -z | xargs -0 -r git add -N -- 2>/dev/null || true
spec=(-- . ':(exclude)src/variancelabs_mcp/app/static' ':(exclude)src/variancelabs_mcp/viewer/static' ':(exclude)src/web-app/package-lock.json')
{
  echo "# Review package: $title"
  echo "(working tree vs snapshot; nothing is committed in this project — CLAUDE.md)"
  echo
  echo "## Files changed (bundle under src/variancelabs_mcp/*/static excluded)"
  git diff --stat=160 "${spec[@]}"
  echo
  echo "## Bundle files touched (names only)"
  git diff --name-status -- src/variancelabs_mcp/app/static src/variancelabs_mcp/viewer/static || true
  echo
  echo "## Diff"
  git diff -U10 "${spec[@]}"
} > "$out"
rm -f "$tmp"
echo "wrote $out: $(wc -c < "$out" | tr -d ' ') bytes"
