"""MATE, written and run AFTER the sealed screen's data (2026-09-11, session 37).

The sealed AI_SELF pattern matched 8 of 178 reachable hosts, which looked
narrow. This re-fetches only the hosts the sealed screen flagged for a price and
applies a broader self-description pattern, to estimate how many storefronts the
sealed screen could have missed. Nothing found here enters the verdict; any
storefront it finds is scored in a separate table beside it.
"""
import csv, re
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).resolve().parent))
from screen import get, text_of, AI_SELF, PRICE  # noqa: E402

BROAD = re.compile(r"\b(ai|autonomous)[- ]agent\b|\bagent[- ]run\b|\bi am an agent\b|\bi'm an agent\b"
                   r"|\ban? (llm|claude|gpt|gemini)[- ]?(based|powered)?\s+agent\b|\bno human\b", re.I)
HERE = Path(__file__).resolve().parent
rows = [r for r in csv.DictReader(open(HERE / "screen.csv")) if r["price"] == "1" and r["candidate"] != "1"]

def one(r):
    s1, home = get(f"https://{r['host']}/")
    s2, llms = get(f"https://{r['host']}/llms.txt")
    if s2 != 200 or "<html" in (llms or "")[:400].lower():
        llms = ""
    text = text_of(home if s1 == 200 else "") + " " + llms
    m = BROAD.search(text)
    return r["host"], bool(m), (text[max(0, m.start()-80): m.end()+80] if m else "")

with ThreadPoolExecutor(max_workers=8) as pool:
    out = list(pool.map(one, rows))
hits = [o for o in out if o[1]]
print(f"price-flagged non-candidates re-screened: {len(out)}; broad AI-agent hits: {len(hits)}")
for h, _, ev in hits:
    print(h, "|", re.sub(r"\s+", " ", ev)[:200])
