import importlib.util, re, sys
p="/home/kiro/.hermes/scripts/x-account-monitor-run.py"
src=open(p).read()
# extract the sets without executing the scan
ns={}
for name in ["DEAD","DORMANT","SKIP","CORE","IRRELEVANT","NON_CORE","FILM_INDUSTRY"]:
    m=re.search(rf"^{name} = (.*?)(?=\n\n)", src, re.S|re.M)
    if m:
        code=f"{name} = {m.group(1)}"
        try:
            exec(code, ns)
        except Exception as e:
            print(f"{name}: EXEC FAIL {e}")
for n in ["DEAD","DORMANT","CORE","IRRELEVANT","NON_CORE","FILM_INDUSTRY"]:
    v=ns.get(n)
    print(f"{n}: {len(v) if hasattr(v,'__len__') else v}")

txt=open("/home/kiro/trend-engine/trends/x/raw/rising-accounts.md").read()
found=re.findall(r"@(\w+)", txt)
handles=[]; seen=set()
for h in ns["CORE"]+found:
    k=h.lower()
    if k in ns["SKIP"] or h in ns["DEAD"] or h in ns["DORMANT"] or k in seen: continue
    seen.add(k); handles.append(h)
print("built handles:", len(handles))
overlaps=[]
sets={n:set(ns[n]) for n in ["DORMANT","CORE","IRRELEVANT","NON_CORE","FILM_INDUSTRY","DEAD"]}
names=list(sets)
for i in range(len(names)):
    for j in range(i+1,len(names)):
        o=sets[names[i]]&sets[names[j]]
        if o: overlaps.append((names[i],names[j],sorted(o)))
print("overlaps:", overlaps if overlaps else "none")
print("AidenChaoyangHe in IRRELEVANT:", "AidenChaoyangHe" in ns["IRRELEVANT"])
print("Soaima_Ai in DEAD:", "Soaima_Ai" in ns["DEAD"])
missing=[h for h in ns["CORE"] if h.lower() not in {x.lower() for x in handles}]
print("CORE handles dropped from build:", missing if missing else "none")
