#!/usr/bin/env bash
# UserPromptSubmit hook: nudge toward verification when a prompt asserts a limit.
#
# Inert unless SOTA_ANCHOR_PROMPT_HOOK=1. This runs on every message the user
# sends, so the default install pays nothing for it beyond one env-var test.
#
# It only ever adds context. It never emits a block decision and never exits
# non-zero, because a non-zero exit on this event erases what the user typed --
# far too destructive for a heuristic nudge.
set -uo pipefail

[ "${SOTA_ANCHOR_PROMPT_HOOK:-0}" = "1" ] || exit 0

payload="$(cat 2>/dev/null)" || exit 0
lowered="$(printf '%s' "$payload" | tr '[:upper:]' '[:lower:]')"

NUDGE="sota-anchor plugin: this request assumes something is unavailable, or proposes building around it. That assumption may be out of date - an existing library, reader, tool or model capability may already cover it. Before building the workaround, or advising that no such tool exists, the check-what-exists skill (or /sota-check) can check it against recent sources. If the limitation turns out to be real, carry on - this is a prompt to check, not an objection."

# Epistemic-stance terms: they describe the SHAPE of a claimed limitation, or of
# building around one, not any subject matter. Nothing here knows what CAD or
# genomics are, so the no-topic-dictionary rule the engine follows still holds.
#
# "cant" is how the prompt a live session declined to check spelled it. Matched
# as whole words only, because it also sits inside "significant".
STANCE="cannot|can't|cant|can not|unable to|impossible|not possible|unsupported"
STANCE+="|doesn't support|does not support|isn't supported|not supported|no native"
STANCE+="|no way to|workaround|work around|fall back|fallback|limitation"
STANCE+="|manually parse|by hand|from scratch|write my own|write our own"
STANCE+="|roll my own|roll our own|hand-roll|hand roll|reimplement|re-implement"
STANCE+="|reverse engineer|reverse-engineer|custom parser|custom converter"
STANCE+="|custom reader|proprietary"
pattern="(^|[^a-z'])(${STANCE})([^a-z]|$)"

if [[ "$lowered" =~ $pattern ]]; then
    printf '{\n  "hookSpecificOutput": {\n    "hookEventName": "UserPromptSubmit",\n    "additionalContext": "%s"\n  }\n}\n' "$NUDGE"
fi

exit 0
