"""Stop hook wrapper for Sonnet 4.6 agent verifier.
The actual agent prompt + decision logic is in settings.json (type: agent).
This script exists as fallback test harness + to satisfy self-check
infrastructure expectations."""
import json
import os
import sys
import tempfile

try:
    sys.stdin.reconfigure(encoding="utf-8", errors="replace")
except Exception:
    pass


def main() -> None:
    try:
        data = json.load(sys.stdin)
    except Exception:
        return

    sid = data.get("session_id")
    if not sid:
        return
    state_path = os.path.join(tempfile.gettempdir(), f"claude-economy-{sid}.json")
    if not os.path.exists(state_path):
        return
    try:
        with open(state_path, encoding="utf-8") as f:
            state = json.load(f)
    except Exception:
        return
    level = state.get("level")
    if level is None or level == 100:
        return

    # Agent-type hook is configured in settings.json. This wrapper emits
    # a marker indicating verifier should fire for this level.
    out = {
        "hookSpecificOutput": {
            "hookEventName": "Stop",
            "additionalContext": f"Verifier marker: economy level {state.get('label', level)} active",
        }
    }
    sys.stdout.write(json.dumps(out, ensure_ascii=True))


if __name__ == "__main__":
    main()
