import re # Pre-compiled ANSI Escape regex for reuse across Rag, Registry, and Architects # This prevents O(N * tokens) compilation overhead during intensive streaming ANSI_ESCAPE = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')