class SafetyManager: def __init__(self): self.banned_phrases = ["delete all", "shutdown", "format", "upload private"] self.allowed_actions = set() self.audit_log = [] def is_safe_command(self, command: str) -> bool: for phrase in self.banned_phrases: if phrase in command.lower(): self.log_event(f"Blocked unsafe command: '{command}'") return False return True def authorize_action(self, action_name: str): self.allowed_actions.add(action_name) def revoke_action(self, action_name: str): self.allowed_actions.discard(action_name) def is_action_allowed(self, action_name: str) -> bool: allowed = action_name in self.allowed_actions if not allowed: self.log_event(f"Unauthorized action attempt: '{action_name}'") return allowed def log_event(self, entry: str): self.audit_log.append(entry) def get_audit_log(self): return self.audit_log