+
    i                         R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	H
t
 ^ RIHt ]P                  ! ]4      t ! R R4      tR# )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)Path)AnyDict)get_hermes_homec                      a  ] tR t^%t o RtV 3R lR lt]V 3R lR l4       tV 3R lR ltV 3R lR	 lt	V 3R
 lR lt
RtV tR# )DebugSessionzPer-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.
c                *   < V ^8  d   QhRS[ RS[ RR/# )   	tool_nameenv_varreturnN)str)format__classdict__s   "0/home/ubuntu/hermes-agent/tools/debug_helpers.py__annotate__DebugSession.__annotate__,   s"     5 5# 53 54 5    c               @   Wn         \        P                  ! VR 4      P                  4       R8H  V n        V P                  '       d   \        \        P                  ! 4       4      MRV n        \        4       R,          V n
        . V n        V P                  '       d-   \        P                  P                  4       P                  4       MRV n        V P                  '       d@   V P                  P!                  RRR7       \"        P%                  RWP                  4       R# R# )falsetrue logsT)parentsexist_okz&%s debug mode enabled - Session ID: %sN)r
   osgetenvlowerenabledr   uuiduuid4
session_idr   log_dir_callsdatetimenow	isoformat_start_timemkdirloggerdebug)selfr
   r   s   &&$r   __init__DebugSession.__init__,   s    "yy'288:fD/3|||#djjl+&(61,.BF,,,8,,002<<>TV<<<LLtd;LLA"OO5 r   c                    < V ^8  d   QhRS[ /# r	   r   )bool)r   r   s   "r   r   r   :   s       r   c                    V P                   # )N)r   r+   s   &r   activeDebugSession.active9   s    ||r   c                @   < V ^8  d   QhRS[ RS[S[ S[3,          RR/# )r	   	call_name	call_datar   N)r   r   r   )r   r   s   "r   r   r   =   s*      # $sCx. T r   c                    V P                   '       g   R# V P                  P                  R\        P                  P	                  4       P                  4       RV/VC4       R# )z.Append a tool-call entry to the in-memory log.N	timestampr
   )r   r#   appendr$   r%   r&   )r+   r6   r7   s   &&&r   log_callDebugSession.log_call=   sQ    |||**..0::<
 
 	r   c                   < V ^8  d   QhRR/# )r	   r   N )r   r   s   "r   r   r   G   s     M Md Mr   c                   V P                   '       g   R#  V P                   RV P                   R2pV P                  V,          pRV P                  RV P                  R\
        P
                  P                  4       P                  4       RRR	\        V P                  4      R
V P                  /p\        VRRR7      ;_uu_ 4       p\        P                  ! W4^RR7       RRR4       \        P                  RV P                  V4       R#   + '       g   i     L3; i  \         d-   p\        P!                  RT P                  T4        Rp?R# Rp?ii ; i)z=Flush the in-memory log to a JSON file in the logs directory.N_debug_.jsonr!   
start_timeend_timedebug_enabledTtotal_calls
tool_callswzutf-8)encodingF)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   saveDebugSession.saveG   s   |||	M..)0AGH||h.Hdood..H--113==?s4;;/dkkG hg66!		'QUC 7LL14>>8L 76  	MLL8$..!LL	Ms0   B.D D	)D 	D	D E'!EEc                6   < V ^8  d   QhRS[ S[S[3,          /# r/   )r   r   r   )r   r   s   "r   r   r   \   s     
 
$sCx. 
r   c                    V P                   '       g   RRRRRRR^ /# RRRV P                  R\        V P                  V P                   RV P                   R	2,          4      R\        V P                  4      /# )
zKReturn a summary dict suitable for returning from get_debug_session_info().r   Fr!   Nlog_pathrE   Tr@   rA   )r   r!   r   r"   r
   rK   r#   r2   s   &r   get_session_infoDebugSession.get_session_info\   s|    |||5dDq	  t$//DLLdnn-=WT__DUUZ+[[\3t{{+	
 	
r   )r#   r'   r   r"   r!   r
   N)__name__
__module____qualname____firstlineno____doc__r,   propertyr3   r;   rV   r[   __static_attributes____classdictcell__)r   s   @r   r   r   %   sH     5 5   M M*
 
r   r   )ra   r$   rM   loggingr   r   pathlibr   typingr   r   hermes_constantsr   	getLoggerr]   r)   r   r>   r   r   <module>rj      s@   .    	    ,			8	$E
 E
r   