-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot_delegate.py
More file actions
executable file
·39 lines (33 loc) · 1.06 KB
/
Copy pathroot_delegate.py
File metadata and controls
executable file
·39 lines (33 loc) · 1.06 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
#!/usr/bin/env python3
import json
from pathlib import Path
from datetime import datetime
ALERTS_DIR = Path("/opt/selfix_companion/root_alerts")
JOURNAL = Path("/opt/SELFIX/data/root_journal.json")
def load_alerts():
return list(ALERTS_DIR.glob("*.json"))
def handle_alert(alert_file: Path):
data = json.loads(alert_file.read_text())
decision = "accept" if data.get("reason") != "karma_too_low" else "quarantine"
log_entry = {
"timestamp": datetime.now().isoformat(),
"alert": data,
"decision": decision
}
print(f"👑 Root AI decision: {decision} for module: {data.get('module')}")
append_to_journal(log_entry)
alert_file.unlink()
def append_to_journal(entry):
if JOURNAL.exists():
log = json.loads(JOURNAL.read_text())
else:
log = []
log.append(entry)
JOURNAL.write_text(json.dumps(log, indent=2))
def main():
if not ALERTS_DIR.exists():
ALERTS_DIR.mkdir(parents=True)
for alert_file in load_alerts():
handle_alert(alert_file)
if __name__ == "__main__":
main()