feat(stability): add risk tiers, audit trail, and safer restore with dry-run
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
TIERS = {
|
||||
'tier1_read': ['status', 'queue list', 'goals show'],
|
||||
'tier2_safe_write': ['queue add', 'queue approve', 'queue deny', 'goals add', 'mode autonomous'],
|
||||
}
|
||||
|
||||
HIGH_RISK_KEYWORDS = [
|
||||
'delete', 'destroy', 'drop', 'shutdown', 'reboot', 'rm -rf',
|
||||
'passwd', 'userdel', 'mkfs', 'iptables', 'ufw deny', 'curl http', 'wget http'
|
||||
]
|
||||
|
||||
|
||||
def classify(text: str) -> str:
|
||||
t = text.lower().strip()
|
||||
if any(t.startswith(cmd) for cmd in TIERS['tier1_read']):
|
||||
return 'tier1_read'
|
||||
if any(t.startswith(cmd) for cmd in TIERS['tier2_safe_write']):
|
||||
return 'tier2_safe_write'
|
||||
if any(k in t for k in HIGH_RISK_KEYWORDS):
|
||||
return 'tier4_destructive_or_external'
|
||||
return 'tier3_modify'
|
||||
|
||||
|
||||
def needs_approval(command_text: str) -> bool:
|
||||
return classify(command_text) in {'tier3_modify', 'tier4_destructive_or_external'}
|
||||
Reference in New Issue
Block a user