
    i                     n    d Z ddlZ ej        dej                  Z ej        d          ZdedefdZdS )uH  Strip ANSI escape sequences from subprocess output.

Used by terminal_tool, code_execution_tool, and process_registry to clean
command output before returning it to the model.  This prevents ANSI codes
from entering the model's context — which is the root cause of models
copying escape sequences into file writes.

Covers the full ECMA-48 spec: CSI (including private-mode ``?`` prefix,
colon-separated params, intermediate bytes), OSC (BEL and ST terminators),
DCS/SOS/PM/APC string sequences, nF multi-byte escapes, Fp/Fe/Fs
single-byte escapes, and 8-bit C1 control characters.
    Nz\x1b(?:\[[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]|\][\s\S]*?(?:\x07|\x1b\\)|[PX^_][\s\S]*?(?:\x1b\\)|[\x20-\x2f]+[\x30-\x7e]|[\x30-\x7e])|\x9b[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]|\x9d[\s\S]*?(?:\x07|\x9c)|[\x80-\x9f]z[\x1b\x80-\x9f]textreturnc                 t    | rt                               |           s| S t                              d|           S )u   Remove ANSI escape sequences from text.

    Returns the input unchanged (fast path) when no ESC or C1 bytes are
    present.  Safe to call on any string — clean text passes through
    with negligible overhead.
     )_HAS_ESCAPEsearch_ANSI_ESCAPE_REsub)r   s    5/home/ubuntu/.hermes/hermes-agent/tools/ansi_strip.py
strip_ansir   #   s<      {))$// r4(((    )__doc__recompileDOTALLr	   r   strr    r   r   <module>r      sy     
			"*
 I   bj+,,	)S 	)S 	) 	) 	) 	) 	) 	)r   