forked from forthfate/openorbit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbehaviors.py
More file actions
55 lines (44 loc) · 2.05 KB
/
Copy pathbehaviors.py
File metadata and controls
55 lines (44 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Clean-room policy implementations for the public behavior bundles."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Iterable
class SourceCatalogPolicy:
"""Allow browser actions only when their target is present in source catalog evidence."""
@staticmethod
def validate_actions(actions: Iterable[dict[str, str]], catalog: set[str]) -> list[dict[str, str]]:
validated = list(actions)
invalid = [action.get("target", "") for action in validated if action.get("target") not in catalog]
if invalid:
raise ValueError(f"Actions are not source-backed: {', '.join(invalid)}")
return validated
@dataclass(frozen=True)
class ImprovementDecision:
action: str
stable_runs: int
reason: str
class ImprovementPolicy:
"""Enforce isolated candidate evaluation, promotion, and rollback gates."""
REQUIRED_EVALUATIONS = 3
REQUIRED_SCORECARDS = 7
MINIMUM_SCORE = 4
@classmethod
def assess(
cls, scores: Iterable[int], stable_runs: int, fingerprint_matches: bool
) -> ImprovementDecision:
values = list(scores)
if not fingerprint_matches:
return ImprovementDecision(
"blocked", 0, "Candidate fingerprint changed outside the isolated patch."
)
if len(values) != cls.REQUIRED_SCORECARDS:
return ImprovementDecision("blocked", 0, "A complete 5+2 evaluation is required.")
sufficient = all(score >= cls.MINIMUM_SCORE for score in values)
if sufficient and stable_runs + 1 >= cls.REQUIRED_EVALUATIONS:
return ImprovementDecision("promote", stable_runs + 1, "Three complete sufficient gates passed.")
if not sufficient and stable_runs + 1 >= cls.REQUIRED_EVALUATIONS:
return ImprovementDecision(
"revert", stable_runs + 1, "Three non-sufficient gates exhausted the candidate."
)
return ImprovementDecision(
"continue", stable_runs + 1, "Candidate remains isolated for another gate."
)