§
    ‰eîiu  ã                   óˆ   — d Z ddlZddlZddlZddlZddlZddlmZmZ ddl	m
Z
  ej        e¦  «        Z G d„ d¦  «        ZdS )aÐ  Shared debug session infrastructure for Hermes tools.

Replaces the identical DEBUG_MODE / _log_debug_call / _save_debug_log /
get_debug_session_info boilerplate previously duplicated across web_tools,
vision_tools, mixture_of_agents_tool, and image_generation_tool.

Usage in a tool module:

    from tools.debug_helpers import DebugSession

    _debug = DebugSession("web_tools", env_var="WEB_TOOLS_DEBUG")

    # Log a call (no-op when debug mode is off)
    _debug.log_call("web_search", {"query": q, "results": len(r)})

    # Save the debug log (no-op when debug mode is off)
    _debug.save()

    # Expose debug info to external callers
    def get_debug_session_info():
        return _debug.get_session_info()
é    N)ÚAnyÚDict)Úget_hermes_homec                   óŠ   — e Zd ZdZdededdfd„Zedefd„¦   «         Zded	e	ee
f         ddfd
„Zdd„Zde	ee
f         fd„ZdS )ÚDebugSessionzÌPer-tool debug session that records tool calls to a JSON log file.

    Activated by a tool-specific environment variable (e.g. WEB_TOOLS_DEBUG=true).
    When disabled, all methods are cheap no-ops.
    Ú	tool_nameÚenv_varÚreturnNc                ó  — || _         t          j        |d¦  «                             ¦   «         dk    | _        | j        r t          t          j        ¦   «         ¦  «        nd| _        t          ¦   «         dz  | _
        g | _        | j        r0t          j                             ¦   «                              ¦   «         nd| _        | j        r?| j
                             dd¬¦  «         t"                               d|| j        ¦  «         d S d S )NÚfalseÚtrueÚ ÚlogsT)ÚparentsÚexist_okz&%s debug mode enabled - Session ID: %s)r   ÚosÚgetenvÚlowerÚenabledÚstrÚuuidÚuuid4Ú
session_idr   Úlog_dirÚ_callsÚdatetimeÚnowÚ	isoformatÚ_start_timeÚmkdirÚloggerÚdebug)Úselfr   r	   s      ú5/home/div/.hermes/hermes-agent/tools/debug_helpers.pyÚ__init__zDebugSession.__init__+   sð   € Ø"ˆŒÝ”y ¨'Ñ2Ô2×8Ò8Ñ:Ô:¸fÒDˆŒØ/3¬|ÐC�#�dœj™lœlÑ+Ô+Ð+ÀˆŒÝ&Ñ(Ô(¨6Ñ1ˆŒØ,.ˆŒØBFÄ,ÐV�8Ô,×0Ò0Ñ2Ô2×<Ò<Ñ>Ô>Ð>ÐTVˆÔàŒ<ð 	5ØŒL×Ò t°dÐÑ;Ô;Ð;Ý�LŠLÐAØ" D¤Oñ5ô 5ð 5ð 5ð 5ð	5ð 	5ó    c                 ó   — | j         S )N)r   ©r#   s    r$   ÚactivezDebugSession.active8   s
   € àŒ|Ðr&   Ú	call_nameÚ	call_datac                 ó²   — | j         sdS | j                             t          j                             ¦   «                              ¦   «         |dœ|¥¦  «         dS )z.Append a tool-call entry to the in-memory log.N)Ú	timestampr   )r   r   Úappendr   r   r   )r#   r*   r+   s      r$   Úlog_callzDebugSession.log_call<   sj   € àŒ|ð 	ØˆFØŒ×ÒÝ!Ô*×.Ò.Ñ0Ô0×:Ò:Ñ<Ô<Ø"ð
ð 
ð ð
ñ 	ô 	ð 	ð 	ð 	r&   c                 ó:  — | j         sdS 	 | j        › d| j        › d�}| j        |z  }| j        | j        t
          j                             ¦   «                              ¦   «         dt          | j	        ¦  «        | j	        dœ}t          |dd¬¦  «        5 }t          j        ||d	d
¬¦  «         ddd¦  «         n# 1 swxY w Y   t                               d| j        |¦  «         dS # t          $ r,}t                               d| j        |¦  «         Y d}~dS d}~ww xY w)z=Flush the in-memory log to a JSON file in the logs directory.NÚ_debug_ú.jsonT)r   Ú
start_timeÚend_timeÚdebug_enabledÚtotal_callsÚ
tool_callsÚwzutf-8)Úencodingé   F)ÚindentÚensure_asciiz%s debug log saved: %szError saving %s debug log: %s)r   r   r   r   r   r   r   r   Úlenr   ÚopenÚjsonÚdumpr!   r"   Ú	ExceptionÚerror)r#   ÚfilenameÚfilepathÚpayloadÚfÚes         r$   ÚsavezDebugSession.saveF   s†  € àŒ|ð 	ØˆFð	MØœ.ÐGÐG°´ÐGÐGÐGˆHØ”| hÑ.ˆHà"œoØ"Ô.Ý$Ô-×1Ò1Ñ3Ô3×=Ò=Ñ?Ô?Ø!%Ý" 4¤;Ñ/Ô/Ø"œkðð ˆGõ �h ¨gÐ6Ñ6Ô6ð D¸!Ý”	˜' 1¨Q¸UÐCÑCÔCÐCðDð Dð Dñ Dô Dð Dð Dð Dð Dð Dð Døøøð Dð Dð Dð Då�LŠLÐ1°4´>À8ÑLÔLÐLÐLÐLøÝð 	Mð 	Mð 	MÝ�LŠLÐ8¸$¼.È!ÑLÔLÐLÐLÐLÐLÐLÐLÐLøøøøð	Møøøs<   ‹BC$ ÂB6Â*C$ Â6B:Â:C$ Â=B:Â>$C$ Ã$
DÃ.!DÄDc           	      ó¤   — | j         sdddddœS d| j        t          | j        | j        › d| j        › d�z  ¦  «        t          | j        ¦  «        dœS )zKReturn a summary dict suitable for returning from get_debug_session_info().FNr   )r   r   Úlog_pathr6   Tr1   r2   )r   r   r   r   r   r=   r   r(   s    r$   Úget_session_infozDebugSession.get_session_info[   st   € àŒ|ð 	à Ø"Ø Ø ð	ð ð ð Øœ/Ý˜DœL¨d¬nÐ+[Ð+[ÀTÄ_Ð+[Ð+[Ð+[Ñ[Ñ\Ô\Ý˜tœ{Ñ+Ô+ð	
ð 
ð 	
r&   )r
   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r%   ÚpropertyÚboolr)   r   r   r/   rH   rK   © r&   r$   r   r   $   sÚ   € € € € € ðð ð5 #ð 5°3ð 5¸4ð 5ð 5ð 5ð 5ð ð˜ð ð ð ñ „Xðð #ð °$°s¸C°x´.ð ÀTð ð ð ð ðMð Mð Mð Mð*
 $ s¨C x¤.ð 
ð 
ð 
ð 
ð 
ð 
r&   r   )rO   r   r?   Úloggingr   r   Útypingr   r   Úhermes_constantsr   Ú	getLoggerrL   r!   r   rR   r&   r$   ú<module>rW      s¶   ððð ð. €€€Ø €€€Ø €€€Ø 	€	€	€	Ø €€€Ø Ð Ð Ð Ð Ð Ð Ð à ,Ð ,Ð ,Ð ,Ð ,Ð ,à	ˆÔ	˜8Ñ	$Ô	$€ðE
ð E
ð E
ð E
ð E
ñ E
ô E
ð E
ð E
ð E
r&   