| 356 | |
| 357 | |
| 358 | def _probe_version(argv: list[str]) -> dict[str, Any]: |
| 359 | binary = argv[0] |
| 360 | path = shutil.which(binary) |
| 361 | if path is None: |
| 362 | return {"available": False, "path": None, "version": None, "error": "not on PATH"} |
| 363 | try: |
| 364 | proc = subprocess.run( |
| 365 | argv, capture_output=True, text=True, timeout=10, check=False, |
| 366 | ) |
| 367 | except (OSError, subprocess.TimeoutExpired) as exc: |
| 368 | return {"available": True, "path": path, "version": None, "error": str(exc)} |
| 369 | combined = (proc.stdout + "\n" + proc.stderr).strip() |
| 370 | if proc.returncode != 0 and not combined: |
| 371 | return { |
| 372 | "available": True, "path": path, "version": None, |
| 373 | "error": f"{binary} --version exited {proc.returncode}", |
| 374 | } |
| 375 | # Grab the first line; CLIs like to print banners. "codex-cli 0.122.0" |
| 376 | # or "1.4.0" — caller can eyeball either. |
| 377 | first_line = combined.splitlines()[0].strip() if combined else "" |
| 378 | return {"available": True, "path": path, "version": first_line, "error": None} |
| 379 | |
| 380 | |
| 381 | # ---------- per-project buckets ----------------------------------------- |