| 501 | |
| 502 | |
| 503 | def _server_env( |
| 504 | *, |
| 505 | swebench_repo: Path, |
| 506 | clawcodex_repo: Path, |
| 507 | openclaude_repo: Path, |
| 508 | agent: str, |
| 509 | ) -> dict[str, str]: |
| 510 | env = os.environ.copy() |
| 511 | # Make `scripts.*` imports resolve from inside the SWE-bench repo. |
| 512 | pythonpath = [str(swebench_repo)] |
| 513 | if env.get("PYTHONPATH"): |
| 514 | pythonpath.append(env["PYTHONPATH"]) |
| 515 | env["PYTHONPATH"] = os.pathsep.join(pythonpath) |
| 516 | |
| 517 | # Repo locations the wrappers themselves consult. |
| 518 | if clawcodex_repo.is_dir(): |
| 519 | env.setdefault("CLAWCODEX_REPO", str(clawcodex_repo)) |
| 520 | # Only point at a source checkout when it is actually built; otherwise the |
| 521 | # API server should fall through to global `openclaude` on PATH (npm -g). |
| 522 | if openclaude_repo.is_dir() and (openclaude_repo / "dist" / "cli.mjs").is_file(): |
| 523 | env.setdefault("OPENCLAUDE_REPO", str(openclaude_repo)) |
| 524 | return env |
| 525 | |
| 526 | |
| 527 | def _run_predictions( |