#!/usr/bin/env bash
# GRIN learn (Claws personal mail) → TRUE equate hits · then asm
# English folder tree · surface swap · ATOM_SURFACE only · not constellation
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
IMPORT="${1:-$ROOT/out/grin_learn_import.json}"
EXPORT_HINT="$ROOT/out/grin_learn_export_hint.txt"

mkdir -p "$ROOT/out"

if [[ ! -f "$IMPORT" ]]; then
  cat >"$EXPORT_HINT" <<'EOF'
GRIN learn → TRUE equates
-------------------------
1. On mail desk · open messages so learn chips grow
2. Browser console (or future Export button):
     copy(JSON.stringify(GrokGrin.learn || GrokKnow.learn))
3. Save as Projects/x/out/grin_learn_import.json
4. Run:  ./Build/grin-learn-to-true.sh
5. Cook: ./Build/true-equates-to-asm.py

Law: English folders · surface swap · ATOM_SURFACE · not constellation
EOF
  echo "no import yet · wrote $EXPORT_HINT"
  echo "pass path: ./Build/grin-learn-to-true.sh /path/to/learn.json"
fi

# if import provided as arg and not in place, copy
if [[ -f "$IMPORT" && "$IMPORT" != "$ROOT/out/grin_learn_import.json" ]]; then
  cp -f "$IMPORT" "$ROOT/out/grin_learn_import.json"
fi

python3 "$ROOT/Build/true-equates-to-asm.py"
echo "done · TRUE equates asm + optional learn hits"
