§
    øžyj›  ã                   ó¾   — d Z ddlZ ej        dej        ¦  «        Z ej        d¦  «        Z ej        d¦  «        Z ej        d¦  «        Zdedef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]z [\x00-\x08\x0b\x0c\x0e-\x1f\x7f]z[\x00-\x08\x0b-\x1f\x7f-\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    ú6/home/ragecks/.hermes/hermes-agent/tools/ansi_strip.pyÚ
strip_ansir   .   s<   € ð ð •{×)Ò)¨$Ñ/Ô/ð ØˆÝ×Ò˜r 4Ñ(Ô(Ð(ó    c                 óî   — | rt                                | ¦  «        s| S t          | ¦  «        } d| v r*|                      dd¦  «                             dd¦  «        } t                               d| ¦  «        S )uA  Sanitize stored/untrusted text before echoing it to a terminal.

    Removes ANSI/ECMA-48 escape sequences AND bare control characters,
    preserving only newlines and tabs (carriage returns are normalized
    to newlines so ``\r``-overwrite spoofing can't hide content).

    Use this when re-rendering conversation history or other persisted
    text in a terminal UI (e.g. the ``/resume`` recap): a message that
    arrived with embedded escapes â€” pasted content, gateway-origin
    text, or model output echoing injected tool results â€” must not be
    able to clear the screen, retitle the window, move the cursor, or
    restyle adjacent UI when replayed. Rich's ``Text()`` does NOT
    neutralize raw escape bytes, so sanitization has to happen before
    display. Mirrors openai/codex#31494 (``sanitize_user_text``).
    úz
Ú
r   )Ú_HAS_CONTROLr   r   ÚreplaceÚ_CONTROL_CHARS_REr
   r   s    r   Úsanitize_display_textr   :   su   € ð  ð •|×*Ò*¨4Ñ0Ô0ð ØˆÝ�dÑÔ€DØˆt€|€|Ø�|Š|˜F DÑ)Ô)×1Ò1°$¸Ñ=Ô=ˆÝ× Ò   TÑ*Ô*Ð*r   )Ú__doc__ÚreÚcompileÚDOTALLr	   r   r   r   Ústrr   r   © r   r   ú<module>r      sÄ   ððð ð 
€	€	€	à�"”*ð
ð „Iñô €ð  ˆbŒjÐ+Ñ,Ô,€ð �B”JÐBÑCÔCÐ ð ˆrŒzÐ:Ñ;Ô;€ð	)�Sð 	)˜Sð 	)ð 	)ð 	)ð 	)ð+ ð +¨ð +ð +ð +ð +ð +ð +r   