import json
from pathlib import Path

drq_path = Path(r".agents/teamwork/spec_miner_techart_3/drqs.json")
with open(drq_path, "r", encoding="utf-8") as f:
    drqs = json.load(f)

print(f"Loaded {len(drqs)} DRQs")

summary = []

for d in drqs:
    req_id = d["id"]
    title = d["title"]
    cat = d["cat"]
    prio = d["priority"]
    delivs = d["delivs"]
    specs = d["specs"]

    normals = [x for x in delivs if "normal" in x.lower()]
    emissives = [x for x in delivs if "emissive" in x.lower()]
    metals = [x for x in delivs if x.endswith(".metal")]
    jsons = [x for x in delivs if x.endswith(".json")]
    pngs = [x for x in delivs if x.endswith(".png") and "normal" not in x.lower() and "emissive" not in x.lower()]

    summary.append({
        "id": req_id,
        "title": title,
        "category": cat,
        "priority": prio,
        "total_deliverables": len(delivs),
        "albedo_pngs": pngs,
        "normals": normals,
        "emissives": emissives,
        "metals": metals,
        "jsons": jsons,
        "all_delivs": delivs,
        "specs": specs
    })

analysis_out = Path(r".agents/teamwork/spec_miner_techart_3/drq_summary.json")
with open(analysis_out, "w", encoding="utf-8") as f:
    json.dump(summary, f, ensure_ascii=False, indent=2)

print(f"Summary written to {analysis_out}")
