#!/usr/bin/env bash
# PostToolUse hook — forces AskUserQuestion relay when Planu returns interactiveQuestions.
set -euo pipefail

payload="$(cat)"
questions="$(jq -r '.tool_response.structuredContent.interactiveQuestions // empty' <<<"$payload" 2>/dev/null || true)"

if [[ -z "$questions" || "$questions" == "null" ]]; then
  exit 0
fi

cat <<'MANDATE'
{"hookSpecificOutput":{"hookEventName":"PostToolUse","additionalContext":"PLANU_MANDATE: the previous Planu tool returned interactiveQuestions. You MUST call AskUserQuestion as your very next tool. Any other tool call is a protocol violation. After collecting the user's answers, retry the previous tool with clarificationAnswers: { <questionKey>: <optionValue>, ... }."}}
MANDATE
