"""Per-attempt read budget for sources already covered by a discovery checkpoint.""" from __future__ import annotations class CheckpointReadBudget: """Permit one direct read of each checkpoint input during implementation. A checkpoint injects the durable conclusions from its declared, source-hashed inputs into the worker context. An implementation may still need one precise source read to apply those conclusions, but repeated full-file reads are a known non-progress loop. This guard is intentionally narrow: it applies only to exact ``read_file`` calls for declared checkpoint inputs. Searches, globs, and unrelated project files remain available. """ def __init__(self, input_paths: list[str] | None = None) -> None: self._input_paths = frozenset(input_paths or []) self._read_paths: set[str] = set() def reject_reason(self, tool_name: str, args: dict) -> str: """Record an allowed checkpoint input read or return its rejection text.""" if tool_name != "read_file": return "" path = args.get("path", "") if not isinstance(path, str) or path not in self._input_paths: return "" if path not in self._read_paths: self._read_paths.add(path) return "" return ( "CHECKPOINT_READ_BUDGET_REJECTED: This attempt already read declared checkpoint " f"input {path!r}. Use the verified discovery checkpoint context and prior tool result " "to implement or verify; do not repeat this source read." )