#!/usr/bin/env bash
set -u
SHA="${1:?sha}"; LABEL="${2:?label}"
W="/c/Users/decid/Documents/projects/spt-core/.worktrees/gate-293c"
OUT="/c/Users/decid/AppData/Local/Temp/claude/C--Users-decid-Documents-projects-spt-core/95a5ade8-823c-4bff-a8fe-e0a9e9db5054/scratchpad/head-gate-win/$SHA"; mkdir -p "$OUT"
cd "$W" || exit 90
[ -z "$(git status --short)" ] || { echo TREE_DIRTY; git status --short; exit 91; }
git checkout -q --detach "$SHA" || exit 92
echo "HEAD=$(git rev-parse HEAD) tree=$(git rev-parse HEAD^{tree})" | tee "$OUT/head.txt"
cargo run -q -p xtask -- pool-claim --pool target --label "$LABEL" > "$OUT/claim.raw" 2>&1; echo $? > "$OUT/claim.exit"; echo "claim exit $(cat "$OUT/claim.exit")"; cat "$OUT/claim.raw"
run() { n="$1"; shift; echo "=== $n start $(date -u +%T)"; "$@" > "$OUT/$n.raw" 2>&1; echo $? > "$OUT/$n.exit"; echo "=== $n exit $(cat "$OUT/$n.exit") end $(date -u +%T)"; }
run clippy cargo clippy --workspace --all-targets -- -D warnings
run brainread cargo run -q -p xtask -- brain-read-check
run xcheck cargo run -q -p xtask -- check
run nextest-xtask cargo nextest run -p xtask
run treqs traceable-reqs check
echo "=== SUMMARY $SHA"; for f in "$OUT"/*.exit; do printf '%s=%s\n' "$(basename "$f" .exit)" "$(cat "$f")"; done
