Core API
Core module.
- contextbench.core.merge(intervals: List[Tuple[int, int]]) List[Tuple[int, int]][source]
Merge overlapping or adjacent intervals.
- contextbench.core.length(intervals: List[Tuple[int, int]]) int[source]
Total bytes covered by intervals.
- contextbench.core.intersect(a: List[Tuple[int, int]], b: List[Tuple[int, int]]) List[Tuple[int, int]][source]
Intersection of two interval lists.
- contextbench.core.intersect_size(a: List[Tuple[int, int]], b: List[Tuple[int, int]]) int[source]
Bytes in intersection.
- contextbench.core.line_to_byte(file_path: str, start_line: int, end_line: int) Tuple[int, int] | None[source]
Convert line span to byte offsets. Returns (start_byte, end_byte) inclusive.
- contextbench.core.checkout(repo_url: str, commit: str, cache_dir: str, verbose: bool = True, sparse_paths: List[str] | None = None) str | None[source]
Checkout repo at specific commit.
Concurrency-safe strategy: - Keep one shared “base” clone per repo under cache_dir (never switch its HEAD). - Create a dedicated detached worktree per commit under /tmp (or a configurable tmp root).
This prevents multiple commits from fighting over the same working directory.