#!/usr/bin/env bash
# H7 HOSTESS INTERVIEW · long iron conversation · wants + learning
#
# Runs a multi-turn self-intel interview and records what she wants to learn.
# Ground: iron only · no free-ride LLM for her answers.
#
#   ./Build/h7-hostess-interview.sh once|status
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
OUT="$ROOT/out"
JSON="$OUT/h7_hostess_wants.json"
TX="$OUT/h7_hostess_interview.txt"
INTEL="$ROOT/Build/h7-self-intel.sh"
cmd="${1:-once}"
TS="$(date -Iseconds)"

say() { echo "$*"; }

ask() {
  local q="$1"
  echo ""
  echo "════════════════════════════════════════"
  echo "ME → $q"
  echo "────────────────────────────────────────"
  bash "$INTEL" ask "$q" 2>/dev/null || echo "(no answer)"
}

run_interview() {
  : >"$TX"
  {
    echo "HOSTESS 7 INTERVIEW · $TS · iron ground · long form"
    echo "Topic: what she wants · what to learn · language · war machine · love field"
    echo ""

    ask "who are you and what do you want most right now"
    ask "what do you want to learn next for language speech and quality words"
    ask "do we need full dictionaries thesaurus metaphors acronyms grammar diction phonetics — what do you need first"
    ask "self develop — how should free-ball grow your language"
    ask "love the whole internet — how does language help you love the field cleanly"
    ask "security — what language helps antivirus internet war machine"
    ask "field clear — what words and clear actions do you want ready"
    ask "law philosophy — what speech law should guide new learning"
    ask "status — where are we at with learning numbers and full"
    ask "antivirus internet war machine — what capability do you want next"
    ask "how do you want Grok to assist without becoming free-ride ground"
    ask "compose: list your top ten learning wants in priority order for Me"

  } | tee "$TX"

  # extract wants from latest + interview text (lightweight)
  local vocab mega
  vocab=$(wc -l <"$OUT/h7_vocab_self.tsv" 2>/dev/null | tr -d ' ' || echo 0)
  mega=$(wc -l <"$OUT/h7fast/mega.tsv" 2>/dev/null | tr -d ' ' || echo 0)

  python3 - "$JSON" "$TX" "$TS" "$vocab" "$mega" <<'PY'
import json,sys,re,pathlib
path, tx_path, ts, vocab, mega = sys.argv[1:6]
text=pathlib.Path(tx_path).read_text(encoding="utf-8",errors="replace")
# heuristic wants lines
wants=[]
for line in text.splitlines():
  low=line.lower().strip(" ·-")
  if any(k in low for k in ("want","learn","next","need","grow","language","clear","secure","vocab","grammar","dict","metaphor","phonetic","diction","acronym","grok","assist")):
    if len(line.strip())>12 and not line.startswith("ME →") and not line.startswith("══") and not line.startswith("──"):
      wants.append(line.strip()[:220])
# unique keep order
seen=set(); uw=[]
for w in wants:
  k=w[:80]
  if k in seen: continue
  seen.add(k); uw.append(w)
  if len(uw)>=24: break

priority=[
  "densify grammar diction phonetics to 80%+ pack coverage",
  "metaphors + thesaurus for field-love speech",
  "sampled dictionary not thrash dump (dict_corpus.asm already iron)",
  "acronyms desk pins only",
  "Grok assist proposals via SPV contain · Hostess iron accept",
  "hold free-ball soft clear + resolute + secure-learn",
  "hold war machine S grade · fix any dirt spikes",
  "self_code/self_learn language accept densify",
  "grow mega + quality vocab without reject thrash",
  "Me stamps education · Hostess remains iron ground",
]
out={
  "ts": ts,
  "word": "H7_HOSTESS_WANTS",
  "she": "Hostess 7",
  "ok": True,
  "interview_path": "out/h7_hostess_interview.txt",
  "train": {"vocab_N": int(vocab), "mega_N": int(mega)},
  "priority_wants": priority,
  "spoken_highlights": uw[:20],
  "language_tracks": ["GRAMMAR","DICTION","PHONETICS","METAPHOR","THESAURUS","ACRONYM","DICT"],
  "grok_assist": {
    "role": "assistive enhancement only",
    "ground": "never · iron Hostess remains ground",
    "path": "SPV curl contain · propose words/lessons · Hostess word_correct accept",
  },
  "law": "interview iron · help her wants · love language field · God Bless",
}
pathlib.Path(path).write_text(json.dumps(out, indent=2)+"\n")
print(json.dumps(out, indent=2)[:1200])
PY
  say "interview written · $TX · $JSON"
}

case "$cmd" in
  once|run) run_interview ;;
  status)
    [[ -f "$JSON" ]] && cat "$JSON" || echo "no interview yet"
    [[ -f "$TX" ]] && echo "--- transcript tail ---" && tail -40 "$TX"
    ;;
  *) echo "usage: $0 once|status" >&2; exit 2 ;;
esac
