Seeded repo with intent and initial content.
This commit is contained in:
parent
86b9063721
commit
12d0c31cff
27 changed files with 2683 additions and 1 deletions
33
src/emergent_security/memory.py
Normal file
33
src/emergent_security/memory.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"""Security memory (canon B5). Memory informs; negative memory blocks until cleared (C10)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Mapping
|
||||
|
||||
from emergent_security.model import Request, frozen_mapping
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class MemoryEntry:
|
||||
decision_class: str
|
||||
scope: Mapping[str, Any]
|
||||
polarity: str
|
||||
cleared: bool = False
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: Mapping[str, Any]) -> MemoryEntry:
|
||||
return cls(
|
||||
decision_class=str(data["decision_class"]),
|
||||
scope=frozen_mapping(data.get("scope")),
|
||||
polarity=str(data.get("polarity", "positive")),
|
||||
cleared=bool(data.get("cleared", False)),
|
||||
)
|
||||
|
||||
def blocks(self, request: Request) -> bool:
|
||||
return (
|
||||
self.polarity == "negative"
|
||||
and not self.cleared
|
||||
and self.decision_class == request.decision_class
|
||||
and all(request.scope.get(key) == value for key, value in self.scope.items())
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue