"""Score one LegalReasonBench matter from a finished Harbor trial. The matter reward is points-weighted across its assignments: the sum of signed points earned (penalties subtract) over the sum of available positive points, clamped to [0, 1]. Harbor's own multi_step_reward_strategy = "mean" averages the per-assignment rewards instead and is diagnostic only. Usage: python score_matter.py """ import json import sys from pathlib import Path def score(trial_dir: Path) -> dict: earned = positive = 0.0 steps = [] # Each assignment's verifier writes reward-details.json; the raw RewardKit copy # under raw/ has no aggregation block and is skipped. for details in sorted(trial_dir.rglob("reward-details.json")): correctness = json.loads(details.read_text()).get("correctness") aggregation = correctness.get("aggregation") if isinstance(correctness, dict) else None if not isinstance(aggregation, dict) or "earned" not in aggregation or "positive_total" not in aggregation: continue earned += float(aggregation["earned"]) positive += float(aggregation["positive_total"]) steps.append({ "file": str(details.relative_to(trial_dir)), "assignment_reward": correctness.get("score"), "earned": aggregation["earned"], "positive_total": aggregation["positive_total"], }) if not steps: raise SystemExit(f"no assignment reward-details.json under {trial_dir}") overall = max(0.0, min(1.0, earned / positive)) if positive > 0 else 0.0 return {"matter_reward": overall, "earned": earned, "positive_total": positive, "assignments": steps} if __name__ == "__main__": print(json.dumps(score(Path(sys.argv[1])), indent=2))