#!/bin/bash
# check-commands.sh FILE : runs every `backticked` command listed under "## Commands"
# in a CLAUDE.md / AGENTS.md, from the file's folder. PASS/FAIL per command.
f="$1"; dir=$(dirname "$f"); fails=0
cmds=$(awk '/^## /{on=($0=="## Commands")} on' "$f" | grep -o '`[^`]*`' | tr -d '`')
while IFS= read -r c; do
  [ -z "$c" ] && continue
  if (cd "$dir" && bash -c "$c" >/tmp/cc.out 2>&1); then echo "PASS  $c"
  else echo "FAIL  $c"; grep -m1 -i "missing script\|error" /tmp/cc.out | sed "s/^/      /"; fails=$((fails+1)); fi
done <<< "$cmds"
echo "$fails failed"; [ "$fails" -eq 0 ]
