33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
TIERS = {
|
|
'tier1_read': ['status', 'help', '/help', 'start', '/start', 'blocked', 'guardrails show', 'allowlist show', 'queue list', 'goals show'],
|
|
'tier2_safe_write': ['queue add', 'queue approve', 'queue deny', 'goals add', 'mode autonomous'],
|
|
}
|
|
|
|
LOW_RISK_INTENT_KEYWORDS = [
|
|
'look into', 'investigate', 'research', 'come up with', 'figure out', 'plan', 'analyze', 'summarize'
|
|
]
|
|
|
|
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().lstrip('/').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 LOW_RISK_INTENT_KEYWORDS):
|
|
return 'tier1_read'
|
|
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'}
|