"""Typed reuse gate. Gemini describes pixels; jev supplies probabilities, not parsed judge prose."""
import hashlib,json,sys
from pathlib import Path
sys.path.insert(0,str(Path.home()/'forge-hub/agent'))
from typesafe_client import JevClient,noul

def classify(description):
    r=JevClient().ask(description,{
        'person':noul('The described ASSET ITSELF shows a person or human character. Do not count a separate scale-reference mannequin beside the asset. Human outfits or hair alone without a person do not count.'),
        'artwork':noul('The described ASSET ITSELF contains a photographed third-party painting, poster or photograph. Original generated 3D geometry and ordinary material textures do not count.')})
    ps={k:r.noul(k) for k in ['person','artwork']}
    return {'model':'jev','probabilities':ps,'blocked':any(p>=.35 for p in ps.values()),'threshold':.35,'source':'authored'}

def cached(description,root):
    path=Path(root)/'safety'/ (hashlib.sha256(description.encode()).hexdigest()+'.json');path.parent.mkdir(exist_ok=True)
    if path.exists():return json.loads(path.read_text())
    result=classify(description);path.write_text(json.dumps(result,separators=(',',':')));return result
