#!/usr/bin/env bash
# Non-blocking PostToolUse hook: after an .py file is written/edited, surface ONLY
# FAIL-level cost leaks (e.g. an unbounded agent loop the moment you write it).
# Always exits 0 — never blocks the edit. Safe no-op if no valid .py path is passed.
f="${1:-}"
case "$f" in
  *.py) [ -f "$f" ] || exit 0 ;;
  *) exit 0 ;;
esac
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(dirname "$HERE")"
out="$(env PYTHONPATH="${ROOT}${PYTHONPATH:+:${PYTHONPATH}}" python3 -m tokenlint.cli "$f" --fail-on never 2>/dev/null || true)"
if printf '%s' "$out" | grep -q 'FAIL'; then
  printf '\n[TokenLint] cost risk in %s:\n%s\n' "$f" "$out"
fi
exit 0
