feat: adapt review budget to diff size
This commit is contained in:
@@ -15,6 +15,13 @@ DEFAULTS = {
|
||||
"max_duration_seconds": 480,
|
||||
}
|
||||
|
||||
PROFILES = (
|
||||
# (changed lines threshold, steps, total tokens, output tokens, seconds)
|
||||
(2_000, 80, 1_200_000, 80_000, 1_800),
|
||||
(800, 60, 800_000, 60_000, 1_200),
|
||||
(200, 40, 400_000, 40_000, 900),
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Budget:
|
||||
@@ -63,6 +70,34 @@ class Budget:
|
||||
price_target=price_target,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def for_review(cls, config: dict | None, diff: str) -> "Budget":
|
||||
"""Choose safe headroom from diff size, unless config is explicit."""
|
||||
if isinstance((config or {}).get("budget"), dict):
|
||||
return cls.from_config(config)
|
||||
changed_lines = _changed_line_count(diff)
|
||||
for threshold, steps, tokens, output, seconds in PROFILES:
|
||||
if changed_lines >= threshold:
|
||||
return cls.from_config({
|
||||
**(config or {}),
|
||||
"budget": {
|
||||
"max_steps": steps,
|
||||
"max_total_tokens": tokens,
|
||||
"max_output_tokens": output,
|
||||
"max_duration_seconds": seconds,
|
||||
},
|
||||
})
|
||||
return cls.from_config(config)
|
||||
|
||||
|
||||
def _changed_line_count(diff: str) -> int:
|
||||
"""Count changed lines without treating hunk headers as additions."""
|
||||
return sum(
|
||||
1 for line in diff.splitlines()
|
||||
if (line.startswith("+") and not line.startswith("+++"))
|
||||
or (line.startswith("-") and not line.startswith("---"))
|
||||
)
|
||||
|
||||
|
||||
def _env_int(name: str, default: int) -> int:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user