()
| 389 | |
| 390 | |
| 391 | def plugin_metadata() -> dict[str, Any]: |
| 392 | root = _find_plugin_root() |
| 393 | metadata: dict[str, Any] = { |
| 394 | "name": None, |
| 395 | "version": None, |
| 396 | "repository": None, |
| 397 | "source_root": str(root) if root else None, |
| 398 | "git_commit": None, |
| 399 | } |
| 400 | if root is None: |
| 401 | return metadata |
| 402 | plugin_json = root / ".codex-plugin" / "plugin.json" |
| 403 | try: |
| 404 | payload = json.loads(plugin_json.read_text(encoding="utf-8")) |
| 405 | metadata["name"] = payload.get("name") |
| 406 | metadata["version"] = payload.get("version") |
| 407 | metadata["repository"] = payload.get("repository") |
| 408 | except (OSError, json.JSONDecodeError): |
| 409 | pass |
| 410 | git_root = next( |
| 411 | (candidate for candidate in [root, *root.parents] if (candidate / ".git").exists()), None |
| 412 | ) |
| 413 | if git_root is not None: |
| 414 | revision = run_cmd(["git", "rev-parse", "HEAD"], git_root, timeout=15) |
| 415 | if revision.get("ok") and revision.get("stdout_tail"): |
| 416 | metadata["git_commit"] = str(revision["stdout_tail"]).splitlines()[0].strip() |
| 417 | return metadata |
| 418 | |
| 419 | |
| 420 | def environment_snapshot() -> dict[str, Any]: |
no test coverage detected