feat: add review effort accounting and budget governor
This commit is contained in:
@@ -25,6 +25,11 @@ CONFIG_MAX_INSTRUCTIONS_CHARS = 4000
|
||||
CONFIG_MAX_PATTERNS_ITEMS = 16 # allow + deny separately, total 32 entries
|
||||
CONFIG_MAX_FINDINGS = 30
|
||||
CONFIG_MAX_STATIC_MESSAGE_CHARS = 400 # free-text banner, mirror of instructions
|
||||
MAX_BUDGET_STEPS = 100
|
||||
MAX_BUDGET_TOKENS = 2_000_000
|
||||
MAX_BUDGET_SECONDS = 3_600
|
||||
MAX_BUDGET_LENSES = 8
|
||||
MAX_BUDGET_COST_USD = 100.0
|
||||
|
||||
STYLES = frozenset(STYLE_DEFAULTS)
|
||||
SEVERITY_VALUES = frozenset(SEVERITIES)
|
||||
@@ -49,6 +54,8 @@ def parse_repo_config(raw: str) -> dict:
|
||||
patterns {allow:[…], deny:[…]} — post-filter globs
|
||||
model <key of cost_model.PRICES> — per-repo override
|
||||
cost_target <key of cost_model.PRICES> — see equivalent_cost
|
||||
budget {max_steps, max_total_tokens, max_output_tokens,
|
||||
max_duration_seconds, max_lenses, max_equivalent_cost_usd}
|
||||
additional_context_urls list[str] (≤ 8) — see fetch_additional_context
|
||||
"""
|
||||
if not raw:
|
||||
@@ -193,6 +200,45 @@ def parse_repo_config(raw: str) -> dict:
|
||||
if cleaned:
|
||||
out["compare_against"] = cleaned[:12]
|
||||
|
||||
budget = _parse_budget(data.get("budget"))
|
||||
if budget:
|
||||
out["budget"] = budget
|
||||
|
||||
return out
|
||||
|
||||
|
||||
def _parse_budget(raw) -> dict:
|
||||
"""Sanitize optional per-review resource limits from trusted config."""
|
||||
if not isinstance(raw, dict):
|
||||
return {}
|
||||
out: dict = {}
|
||||
integer_limits = {
|
||||
"max_steps": (1, MAX_BUDGET_STEPS),
|
||||
"max_total_tokens": (1, MAX_BUDGET_TOKENS),
|
||||
"max_output_tokens": (1, MAX_BUDGET_TOKENS),
|
||||
"max_duration_seconds": (1, MAX_BUDGET_SECONDS),
|
||||
"max_lenses": (1, MAX_BUDGET_LENSES),
|
||||
}
|
||||
for key, (lo, hi) in integer_limits.items():
|
||||
value = raw.get(key)
|
||||
if isinstance(value, int) and not isinstance(value, bool):
|
||||
if lo <= value <= hi:
|
||||
out[key] = value
|
||||
elif isinstance(value, str) and value.strip().isdigit():
|
||||
number = int(value.strip())
|
||||
if lo <= number <= hi:
|
||||
out[key] = number
|
||||
cost = raw.get("max_equivalent_cost_usd")
|
||||
if isinstance(cost, (int, float)) and not isinstance(cost, bool):
|
||||
if 0 < float(cost) <= MAX_BUDGET_COST_USD:
|
||||
out["max_equivalent_cost_usd"] = float(cost)
|
||||
elif isinstance(cost, str):
|
||||
try:
|
||||
number = float(cost.strip())
|
||||
except ValueError:
|
||||
number = 0
|
||||
if 0 < number <= MAX_BUDGET_COST_USD:
|
||||
out["max_equivalent_cost_usd"] = number
|
||||
return out
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user