""" Validation utilities for the Edison application. """ import re import logging logger = logging.getLogger(__name__) def is_dangerous_command(command): """ Check if a command contains potentially dangerous operations. Args: command (str): The command to check. Returns: bool: True if the command is potentially dangerous, False otherwise. """ dangerous_patterns = [ r"rm\s+-rf\s+/", # Remove recursively from root r"sudo\s+rm", # Sudo remove r"chmod\s+777", # Chmod 777 (too permissive) r">\s+/dev/", # Redirect to device r">\s+/etc/", # Redirect to system config r"mkfs", # Format filesystem r"dd\s+if=", # Disk destroyer r":(){:\|:};:", # Fork bomb ] for pattern in dangerous_patterns: if re.search(pattern, command, re.IGNORECASE): logger.warning(f"Potentially dangerous command detected: {command}") return True return False def check_for_issue(response): """ Checks the given response for any issues. Args: response (str): The response to check. Returns: bool: True if there's an issue, False otherwise. """ prefixes = ("sorry", "i'm sorry", "the question is not clear", "i'm", "i am") return response.lower().startswith(prefixes) def check_for_markdown(response): """ Checks for the presence of markdown formatting in the response. Args: response (str): The response to check. Returns: bool: True if markdown is detected, False otherwise. """ return response.count("```", 2)