| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- """Cross-tool Agent Team harness helpers.
- Provides deterministic helpers shared by Devin, Cursor, and Codex adapters.
- All functions are offline, do not access hardware, and do not start model APIs.
- """
- from __future__ import annotations
- import hashlib
- import json
- import subprocess
- from pathlib import Path
- from typing import Any
- def repo_root(cwd: Path | None = None) -> Path:
- cmd = ["git", "rev-parse", "--show-toplevel"]
- result = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True, check=True)
- return Path(result.stdout.strip()).resolve()
- def current_commit_full(cwd: Path | None = None) -> str:
- result = subprocess.run(
- ["git", "rev-parse", "HEAD"],
- cwd=cwd,
- capture_output=True,
- text=True,
- check=True,
- )
- return result.stdout.strip().lower()
- def sha256_file(path: Path) -> str:
- digest = hashlib.sha256()
- with path.open("rb") as stream:
- for chunk in iter(lambda: stream.read(1024 * 1024), b""):
- digest.update(chunk)
- return digest.hexdigest().lower()
- def load_team_contract(repo: Path | None = None) -> dict[str, Any]:
- repo = repo or repo_root()
- path = repo / "agent-team" / "contract.json"
- return json.loads(path.read_text(encoding="utf-8-sig"))
- def is_protected_root(target: Path, protected: list[str]) -> bool:
- resolved = target.resolve()
- for root_str in protected:
- root = Path(root_str).resolve()
- try:
- resolved.relative_to(root)
- return True
- except ValueError:
- pass
- return False
|