from __future__ import annotations
import json
import sys
from pathlib import Path
def main() -> int:
report_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("precision-regression-report.json")
if not report_path.exists():
print(f"precision report not found: {report_path}", file=sys.stderr)
return 1
report = json.loads(report_path.read_text())
totals = report.get("totals", {})
print("### Totals")
print(f"- FN: {totals.get('fn', 'n/a')} (threshold={report.get('fnThreshold', 'n/a')})")
print(f"- FP: {totals.get('fp', 'n/a')} (threshold={report.get('fpThreshold', 'n/a')})")
diff_summary = report.get("diffSummary", {})
if diff_summary:
fn = diff_summary.get("fn", {})
fp = diff_summary.get("fp", {})
print("\n### Diff summary")
print(f"- FN changed: {fn.get('changed', 'n/a')}")
print(f"- FN impacted: {fn.get('impacted', 'n/a')}")
print(f"- FP changed: {fp.get('changed', 'n/a')}")
print(f"- FP impacted: {fp.get('impacted', 'n/a')}")
confidence = report.get("confidenceDistribution", {})
if confidence:
print("\n### Confidence distribution")
for certainty in sorted(confidence):
print(f"- {certainty}: {confidence[certainty]}")
by_language = report.get("byLanguage", {})
if by_language:
print("\n### By language FN/FP diffs")
for lang in sorted(by_language):
row = by_language[lang] or {}
th = row.get("threshold", {})
diff = row.get("thresholdDiff", {})
ds = row.get("diffSummary", {})
fn_ds = ds.get("fn", {})
fp_ds = ds.get("fp", {})
print(
f"- {lang}: "
f"FN={row.get('fn', 'n/a')} (th={th.get('fn', 'n/a')}, delta={diff.get('fn', 'n/a')}, "
f"changed={fn_ds.get('changed', 'n/a')}, impacted={fn_ds.get('impacted', 'n/a')}) | "
f"FP={row.get('fp', 'n/a')} (th={th.get('fp', 'n/a')}, delta={diff.get('fp', 'n/a')}, "
f"changed={fp_ds.get('changed', 'n/a')}, impacted={fp_ds.get('impacted', 'n/a')})"
)
if report.get("gateStatus") == "failed":
failed_langs = report.get("failedLanguages", [])
if failed_langs:
print("\n### Gate failures")
for row in failed_langs:
th = row.get("threshold", {})
delta = row.get("delta", {})
print(
f"- {row.get('lang')}: "
f"FN={row.get('fn')} (th={th.get('fn')}, delta={delta.get('fn')}), "
f"FP={row.get('fp')} (th={th.get('fp')}, delta={delta.get('fp')})"
)
repro = report.get("reproductionCommand")
if repro:
print("\n### Reproduce gate failure")
print("```bash")
print(repro)
print("```")
cases = report.get("cases", [])
hotspots = [
c
for c in cases
if c.get("fn", {}).get("total", 0) > 0 or c.get("fp", {}).get("total", 0) > 0
]
if hotspots:
print("\n### Diff hotspots (FN/FP > 0)")
for c in hotspots:
print(
f"- {c.get('name')} ({c.get('lang')}): "
f"fn={c.get('fn', {}).get('total', 0)} "
f"fp={c.get('fp', {}).get('total', 0)}"
)
return 0
if __name__ == "__main__":
raise SystemExit(main())