#!/usr/bin/env python3
"""Throwaway helper: run dm_conversation.py set-icp-precheck for every project.

Usage:
  python3 _run_icp_precheck.py --dm-id 4583 --default-label icp_miss \
      --default-notes "crypto researcher, not target vertical" \
      --override 'fazm=icp_miss=engaged on agentic token cost but no claude-code-wrapper signal' \
      --override 'Agora=icp_miss=crypto researcher not a protocol governance buyer'

Any project NOT overridden gets the default label/notes.
"""
import argparse, subprocess, sys

PROJECTS = [
    "fazm", "Terminator", "macOS MCP", "Vipassana", "S4L", "AI Browser Profile",
    "WhatsApp MCP", "macOS Session Replay", "Cyrano", "Assrt", "PieLine", "Clone",
    "mk0r", "fde10x", "claude-meter", "c0nsl", "tenxats", "paperback-expert",
    "studyly", "Mediar", "NightOwl", "Runner", "Agora", "Podlog", "ccmd",
]
SCRIPT = "/Users/matthewdi/social-autoposter/scripts/dm_conversation.py"

def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--dm-id", required=True)
    ap.add_argument("--default-label", default="icp_miss")
    ap.add_argument("--default-notes", default="not target vertical")
    ap.add_argument("--override", action="append", default=[],
                    help="PROJECT=LABEL=NOTES")
    args = ap.parse_args()

    overrides = {}
    for o in args.override:
        parts = o.split("=", 2)
        if len(parts) != 3:
            print("bad override:", o); sys.exit(2)
        overrides[parts[0]] = (parts[1], parts[2])

    # validate override keys
    for k in overrides:
        if k not in PROJECTS:
            print("UNKNOWN project in override:", k); sys.exit(2)

    fails = 0
    for p in PROJECTS:
        label, notes = overrides.get(p, (args.default_label, args.default_notes))
        r = subprocess.run(
            ["python3", SCRIPT, "set-icp-precheck", "--dm-id", args.dm_id,
             "--project", p, "--label", label, "--notes", notes],
            capture_output=True, text=True)
        tag = "ok" if r.returncode == 0 else "FAIL"
        if r.returncode != 0:
            fails += 1
        print(f"{tag} {p}={label}", (r.stderr or r.stdout or "").strip()[:120])
    print(f"DONE dm={args.dm_id} fails={fails}")

if __name__ == "__main__":
    main()
