Files
VianoBugAnalysis/src/viano_bug_analysis/analysis/investigation_config.py
T

58 lines
2.1 KiB
Python

import tomllib
from dataclasses import asdict, dataclass
from pathlib import Path
class InvestigationError(Exception):
def __init__(self, code, *, feedback=None):
self.code = code
self.feedback = feedback
super().__init__(code)
@dataclass(frozen=True)
class InvestigationConfig:
max_iterations_per_hypothesis: int = 50
max_invalid_responses: int = 3
max_questions_per_hypothesis: int = 30
test_deadline_seconds: int = 21600
max_steps_per_dispatch: int = 8
max_early_reviews: int = 3
prompt_target_characters: int = 13125
recent_evidence_count: int = 1
lean_loop: bool = False
lean_checkpoint_steps: int = 4
lean_protocol: int = 1
bootstrap_json_framing: bool = False
def __post_init__(self):
if any(type(value) is not int or value <= 0 for name,value in asdict(self).items() if name not in {'lean_loop','lean_checkpoint_steps','bootstrap_json_framing'}):
raise InvestigationError("INVESTIGATION_CONFIG")
if type(self.lean_checkpoint_steps) is not int or self.lean_checkpoint_steps<0 or self.lean_protocol not in {1,2}:
raise InvestigationError('INVESTIGATION_CONFIG')
if type(self.lean_loop) is not bool or type(self.bootstrap_json_framing) is not bool:
raise InvestigationError('INVESTIGATION_CONFIG')
@classmethod
def load(cls, path):
try:
with Path(path).open("rb") as stream:
document=tomllib.load(stream)
if set(document)!={"investigation"}:
raise InvestigationError("INVESTIGATION_CONFIG")
return cls(**document["investigation"])
except (OSError,ValueError,TypeError,KeyError):
raise InvestigationError("INVESTIGATION_CONFIG") from None
@dataclass(frozen=True)
class InvestigationLimits:
max_json_bytes: int = 4*1024*1024
max_context_bytes: int = 1024*1024
max_state_checkpoints: int = 10000
def __post_init__(self):
if any(type(value) is not int or value<=0 for value in asdict(self).values()):
raise InvestigationError("INVESTIGATION_LIMIT_CONFIG")