
    ij                     (   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ZddlmZmZ ddl	m
Z
 ddlmZ ddlmZmZ ddlmZ ej        dk    rddlZnddlZd	Zd
ZdZej        dk    Z e            ZdZdadZde
fdZdUdee
         de
fdZde
fdZ de
fdZ!de"fdZ#ddde$de%ddfdZ&de"de"fdZ'de"de"de
fdZ(de$dee$         fdZ)de$dee$         fdZ*de$dee"         fd Z+de$de%fd!Z,d"e-e"ef         de%fd#Z.de-fd$Z/de-e"ef         fd%Z0d&e
dee-e"ef                  fd'Z1d&e
d(e-e"ef         ddfd)Z2dUdee
         dee-         fd*Z3dUd+ee
         dee-e"ef                  fd,Z4d"ee-e"ef                  dee$         fd-Z5de
d.e%ddfd/Z6dVd0Z7de%fd1Z8dVd2Z9de%fd3Z:dVd4Z;dUd+ee
         de%fd5Z<dVd6Z=eeeeeeeed7d8ed9ed:ed;ed<ed=ed>ed?eddfd@Z>dee-e"ef                  fdAZ?dVdBZ@dUde"de"dCee-e"ef                  deAe%ee-e"ef                  f         fdDZBde"de"ddfdEZCdddFdGee$         dHee$         de$fdIZDdJZEdKZFde
fdLZGdMe$de%fdNZHde%fdOZIdVdPZJ	 dUdQdRdee
         d.e%dee$         fdSZK	 dUdQdRdee
         d.e%de%fdTZLdS )Wu  
Gateway runtime status helpers.

Provides PID-file based detection of whether the gateway daemon is running,
used by send_message's check_fn to gate availability in the CLI.

The PID file lives at ``{HERMES_HOME}/gateway.pid``.  HERMES_HOME defaults to
``~/.hermes`` but can be overridden via the environment variable.  This means
separate HERMES_HOME directories naturally get separate PID files — a property
that will be useful when we add named profiles (multiple agents running
concurrently under distinct configurations).
    N)datetimetimezone)Pathget_hermes_home)AnyOptionalatomic_json_writewin32hermes-gatewayzgateway_state.jsonzgateway-lockszgateway.locki   returnc                  (    t                      } | dz  S )z@Return the path to the gateway PID file, respecting HERMES_HOME.zgateway.pidr   homes    3/home/ubuntu/.hermes/hermes-agent/gateway/status.py_get_pid_pathr   ,   s    D-    pid_pathc                 j    | |                      t                    S t                      }|t          z  S )z1Return the path to the runtime gateway lock file.)	with_name_GATEWAY_LOCK_FILENAMEr   )r   r   s     r   _get_gateway_lock_pathr   2   s4    !!"8999D(((r   c                  N    t                                          t                    S )z5Return the persisted runtime health/status file path.)r   r   _RUNTIME_STATUS_FILE r   r   _get_runtime_status_pathr   :   s    ??$$%9:::r   c                      t          j        d          } | rt          |           S t          t          j        dt          j                    dz  dz                      }|dz  t          z  S )zBReturn the machine-local directory for token-scoped gateway locks.HERMES_GATEWAY_LOCK_DIRXDG_STATE_HOMEz.localstatehermes)osgetenvr   r   _LOCKS_DIRNAME)override
state_homes     r   _get_lock_dirr(   ?   s`    y233H H~~bi 0$)++2H72RSSTTJ >11r   c                  b    t          j        t          j                                                  S N)r   nowr   utc	isoformatr   r   r   _utc_now_isor.   H   s     <%%//111r   F)forcepidr/   c                   |rt           r	 t          j        ddt          |           ddgddd          }n0# t          $ r# t          j        | t          j                   Y dS w xY w|j	        d	k    r6|j
        p|j        pd
                                }t          |pd|            dS |st          j        nt          t          dt          j                  }t          j        | |           dS )zTerminate a PID with platform-appropriate force semantics.

    POSIX uses SIGTERM/SIGKILL. Windows uses taskkill /T /F for true force-kill
    because os.kill(..., SIGTERM) is not equivalent to a tree-killing hard stop.
    taskkillz/PIDz/Tz/FT
   )capture_outputtexttimeoutNr    ztaskkill failed for PID SIGKILL)_IS_WINDOWS
subprocessrunstrFileNotFoundErrorr#   killsignalSIGTERM
returncodestderrstdoutstripOSErrorgetattr)r0   r/   resultdetailssigs        r   terminate_pidrJ   L   s      		^VSXXtT:#	  FF ! 	 	 	GC(((FF	 !!};;BBDDG'E%E%E%EFFF %
U&..769fn+U+UCGCs   *6 )A#"A#identityc                     t          j        |                     d                                                    d d         S )Nutf-8   )hashlibsha256encode	hexdigest)rK   s    r   _scope_hashrS   g   s3    >(//'2233==??DDr   scopec                 J    t                      |  dt          |           dz  S )N-z.lock)r(   rS   )rT   rK   s     r   _get_scope_lock_pathrW   k   s*    ??DDH(=(=DDDDDr   c                     t          d|  d          }	 t          |                                                                d                   S # t          t
          t          t          t          f$ r Y dS w xY w)z:Return the kernel start time for a process when available./proc/z/stat   N)	r   int	read_textsplitr=   
IndexErrorPermissionError
ValueErrorrE   )r0   	stat_paths     r   _get_process_start_timerb   o   sx    (c((())I9&&((..004555z?JP   tts   8A #A54A5c                      t          |           S )zBPublic wrapper for retrieving a process start time when available.)rb   )r0   s    r   get_process_start_timerd   y   s    "3'''r   c                    t          d|  d          }	 |                                }n# t          t          t          f$ r Y dS w xY w|sdS |                    dd                              dd                                          S )	z<Return the process command line as a space-separated string.rY   z/cmdlineN        rM   ignore)errors)r   
read_bytesr=   r_   rE   replacedecoderD   )r0   cmdline_pathraws      r   _read_process_cmdlinero   ~   s    ....//L%%''8   tt  t;;w%%,,WX,FFLLNNNs   * AAc                 d    t          |           sdS d}t          fd|D                       S )zBReturn True when the live PID still looks like the Hermes gateway.F)hermes_cli.main gatewayhermes_cli/main.py gatewayhermes gatewayr   gateway/run.pyc              3       K   | ]}|v V  	d S r*   r   .0patterncmdlines     r   	<genexpr>z._looks_like_gateway_process.<locals>.<genexpr>   (      ::gw'!::::::r   )ro   any)r0   patternsry   s     @r   _looks_like_gateway_processr~      sI    #C((G uH ::::::::::r   recordc                    |                      d          t          k    rdS |                      d          }t          |t                    r|sdS d                    d |D                       d}t          fd|D                       S )zMValidate gateway identity from PID-file metadata when cmdline is unavailable.kindFargv c              3   4   K   | ]}t          |          V  d S r*   )r<   )rw   parts     r   rz   z-_record_looks_like_gateway.<locals>.<genexpr>   s(      22Ts4yy222222r   )rq   rr   rs   rt   c              3       K   | ]}|v V  	d S r*   r   rv   s     r   rz   z-_record_looks_like_gateway.<locals>.<genexpr>   r{   r   )get_GATEWAY_KIND
isinstancelistjoinr|   )r   r   r}   ry   s      @r   _record_looks_like_gatewayr      s    zz&]**u::fDdD!!  uhh22T22222GH ::::::::::r   c                      t          j                    t          t          t          j                  t          t          j                              dS )N)r0   r   r   
start_time)r#   getpidr   r   sysr   rb   r   r   r   _build_pid_recordr      s9    y{{SX-bikk::	  r   c            	      r    t                      } |                     dd ddi t                      d           | S )NstartingFr   )gateway_stateexit_reasonrestart_requestedactive_agents	platforms
updated_at)r   updater.   )payloads    r   _build_runtime_status_recordr      sJ    !!GNN#""nn     Nr   pathc                 2   |                                  sd S 	 |                                                                 }n# t          $ r Y d S w xY w|sd S 	 t	          j        |          }n# t          j        $ r Y d S w xY wt          |t                    r|nd S r*   )	existsr\   rD   rE   jsonloadsJSONDecodeErrorr   dict)r   rn   r   s      r   _read_json_filer      s    ;;== tnn$$&&   tt t*S//   tt $//977T9s!   &? 
AAA* *A=<A=r   c                 ,    t          | |d d           d S )N),:)indent
separatorsr
   )r   r   s     r   _write_json_filer      s    dGDZHHHHHHr   c                    | pt                      } |                                 sd S |                                                                 }|sd S 	 t	          j        |          }n9# t          j        $ r' 	 dt          |          icY S # t          $ r Y Y d S w xY ww xY wt          |t                    rd|iS t          |t                    r|S d S Nr0   )r   r   r\   rD   r   r   r   r[   r`   r   r   )r   rn   r   s      r   _read_pid_recordr      s    *=??H?? t





$
$
&
&C t*S//   	3s88$$$$ 	 	 	444	 '3  w'4   4s0   A' 'B7B
B

BBBB	lock_pathc                 <    t          | pt                                S r*   )r   r   )r   s    r   _read_gateway_lock_recordr      s    IA)?)A)ABBBr   c                 r    | sd S 	 t          | d                   S # t          t          t          f$ r Y d S w xY wr   )r[   KeyError	TypeErrorr`   )r   s    r   _pid_from_recordr      sO     t6%=!!!i,   tts    66cleanup_stalec                    |sdS 	 |                      d           n# t          $ r Y nw xY w	 t          |                                d           dS # t          $ r Y dS w xY w)a  Delete a stale gateway PID file (and its sibling lock metadata).

    Called from ``get_running_pid()`` after the runtime lock has already been
    confirmed inactive, so the on-disk metadata is known to belong to a dead
    process.  Unlike ``remove_pid_file()`` (which defensively refuses to delete
    a PID file whose ``pid`` field differs from ``os.getpid()`` to protect
    ``--replace`` handoffs), this path force-unlinks both files so the next
    startup sees a clean slate.
    NT
missing_ok)unlink	Exceptionr   r   r   s     r   _cleanup_invalid_pid_pathr      s      4((((   x((//4/@@@@@   s    
**#A 
A! A!c                 2   |                      d           |                                  t          j        t	                      |            |                                  	 t          j        |                                            d S # t          $ r Y d S w xY w)Nr   )
seektruncater   dumpr   flushr#   fsyncfilenorE   handles    r   _write_gateway_lock_recordr     s    
KKNNN
OOI!!6***
LLNNN
!!!!!   s    &B 
BBc                    	 t           r|                     dt          j                   |                                 dk    r)|                     d           |                                  |                     t                     t          j	        | 
                                t          j        d           n>t          j        | 
                                t          j        t          j        z             dS # t           t"          f$ r Y dS w xY w)Nr   
   TF)r9   r   r#   SEEK_ENDtellwriter   _WINDOWS_LOCK_OFFSETmsvcrtlockingr   LK_NBLCKfcntlflockLOCK_EXLOCK_NBBlockingIOErrorrE   r   s    r   _try_acquire_file_lockr     s     	HKK2;'''{{}}!!T"""KK,---N6==??FOQ????K)FGGGtW%   uus   C3C7 7DDc                 6   	 t           rN|                     t                     t          j        |                                 t          j        d           d S t          j        |                                 t          j	                   d S # t          $ r Y d S w xY w)Nr   )r9   r   r   r   r   r   LK_UNLCKr   r   LOCK_UNrE   r   s    r   _release_file_lockr   .  s     	8KK,---N6==??FOQ?????K77777   s   AB
 1B
 

BBc                      t           dS t                      } | j                            dd           t	          | dd          }t          |          s|                                 dS t          |           |a dS )zClaim the cross-process runtime lock for the gateway.

    Unlike the PID file, the lock is owned by the live process itself. If the
    process dies abruptly, the OS releases the lock automatically.
    NTparentsexist_oka+rM   encodingF)_gateway_lock_handler   parentmkdiropenr   closer   )r   r   s     r   acquire_gateway_runtime_lockr   9  s     't!##DKdT222$w///F!&)) uv&&&!4r   c                      t           } | dS da t          |            	 |                                  dS # t          $ r Y dS w xY w)z<Release the gateway runtime lock when owned by this process.N)r   r   r   rE   r   s    r   release_gateway_runtime_lockr   N  s_     "F~v   s   4 
AAc                    | pt                      }t          |t                      k    rdS |                                sdS t          |dd          }	 t	          |          r8t          |           	 	 |                                 dS # t          $ r Y dS w xY w	 	 |                                 dS # t          $ r Y dS w xY w# 	 |                                 w # t          $ r Y w w xY wxY w)zFReturn True when some process currently owns the gateway runtime lock.NTFr   rM   r   )r   r   r   r   r   r   r   rE   )r   resolved_lock_pathr   s      r   is_gateway_runtime_lock_activer   \  s4    #>&<&>&>',>BXBZBZ,Z,Zt$$&& u$dW===F	!&)) 	v&&&	LLNNNNN 	 	 	DD		 	LLNNNNN 	 	 	DD		LLNNNN 	 	 	D	sT   C 5B 
BBB4 4
CCC,CC,
C)&C,(C))C,c                  (   t                      } | j                            dd           t          j        t                                }	 t          j        | t          j        t          j	        z  t          j
        z            }n# t          $ r  w xY w	 t          j        |dd          5 }|                    |           ddd           dS # 1 swxY w Y   dS # t          $ r* 	 |                     d           n# t           $ r Y nw xY w w xY w)zWrite the current process PID and metadata to the gateway PID file.

    Uses atomic O_CREAT | O_EXCL creation so that concurrent --replace
    invocations race: exactly one process wins and the rest get
    FileExistsError.
    Tr   wrM   r   Nr   )r   r   r   r   dumpsr   r#   r   O_CREATO_EXCLO_WRONLYFileExistsErrorfdopenr   r   r   rE   )r   r   fdfs       r   write_pid_filer   s  sj    ??DKdT222Z)++,,FWT2:	1BK?@@   Yr3111 	QGGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   	KK4K(((( 	 	 	D	s`   9B BC -CC CC CC 
D(C?>D?
D	DDD)r   r   r   r   platformplatform_state
error_codeerror_messager   r   r   r   r   r   r   r   c                    t                      }t          |          pt                      }	|	                    di            |	                    dt                     t          j                    |	d<   t          t          j                              |	d<   t                      |	d<   | t          ur| |	d<   |t          ur||	d<   |t          urt          |          |	d<   |t          ur t          d	t          |                    |	d
<   |t          urb|	d                             |i           }
|t          ur||
d<   |t          ur||
d<   |t          ur||
d<   t                      |
d<   |
|	d         |<   t          ||	           dS )zBPersist gateway runtime health information for diagnostics/status.r   r   r0   r   r   r   r   r   r   r   r!   r   r   N)r   r   r   
setdefaultr   r#   r   rb   r.   _UNSETboolmaxr[   r   r   )r   r   r   r   r   r   r   r   r   r   platform_payloads              r   write_runtime_statusr    s    $%%Dd##E'C'E'EG{B'''v}---Y[[GEN3BIKK@@GL(NNGLF""#0 &  !,&&'+,='>'>#$F""#&q#m*<*<#=#= v";/33HbAA''(6W%V##-7\*&&0=_-)5&)9X&T7#####r   c                  8    t          t                                S )z=Read the persisted gateway runtime health/status information.)r   r   r   r   r   read_runtime_statusr    s    355666r   c                  6   	 t                      } t          |           }|Q	 t          |d                   }n# t          t          t
          f$ r d}Y nw xY w||t          j                    k    rdS |                     d           dS # t          $ r Y dS w xY w)ah  Remove the gateway PID file, but only if it belongs to this process.

    During --replace handoffs, the old process's atexit handler can fire AFTER
    the new process has written its own PID file.  Blindly removing the file
    would delete the new process's record, leaving the gateway running with no
    PID file (invisible to ``get_running_pid()``).
    Nr0   Tr   )
r   r   r[   r   r   r`   r#   r   r   r   )r   r   file_pids      r   remove_pid_filer    s     && ve}--i4       #BIKK(?(?t$$$$$   s7   B
 8 B
 AB
 AB
 2B
 

BBmetadatac                    t          | |          }|j                            dd           i t                      | t	          |          |pi t                      d}t          |          }|<|                                r(	 |                    d           n# t          $ r Y nw xY w|r	 t          |d                   }n# t          t          t          f$ r d}Y nw xY w|t          j                    k    r@|                    d          |                    d          k    rt#          ||           d|fS |du }|s	 t          j        |d           t'          |          }|                    d          |||                    d          k    rd}|s	 t)          d	| d
          }	|	                                r`|	                                                                D ]9}
|
                    d          r"|
                                d         }|dv rd} n:n7# t          t2          f$ r Y n$w xY wn# t4          t2          t          f$ r d}Y nw xY w|r(	 |                    d           n# t          $ r Y nw xY wd|fS 	 t          j        |t          j        t          j        z  t          j        z            }n!# t>          $ r dt          |          fcY S w xY w	 t          j         |dd          5 }tC          j"        ||           ddd           n# 1 swxY w Y   n7# tF          $ r* 	 |                    d           n# t          $ r Y nw xY w w xY wdS )zAcquire a machine-local lock keyed by scope + identity.

    Used to prevent multiple local gateways from using the same external identity
    at once (e.g. the same Telegram bot token across different HERMES_HOME dirs).
    Tr   )rT   identity_hashr  r   Nr   r0   r   r   rY   z/statuszState:r   )TtFr   rM   r   )TN)$rW   r   r   r   rS   r.   r   r   r   rE   r[   r   r   r`   r#   r   r   r   r>   rb   r   r\   
splitlines
startswithr]   r_   ProcessLookupErrorr   r   r   r   r   r   r   r   r   )rT   rK   r  r   r   existingexisting_pidstalecurrent_start_proc_status_line_stater   r   s                 r   acquire_scoped_lockr    sp    %UH55I4$777


$X..N"nn  F y))HI,,..
	---- 	 	 	D	 .#	 x//LL)Z0 	  	  	 LLL	  29;;&&8<<+E+ET`IaIa+a+aY///>!$ 	a(((
 !8 E ELL..:%1%l)C)CCC E  
'+,J\,J,J,J'K'K'..00 *)5)?)?)A)A)L)L)N)N * *#(#3#3H#=#= !*-2[[]]1-=F'-';';04$)E	!*
 $_5    'A   4  	#  D 1111    (?"1WY
RY 6 DEE 1 1 1oi0000001Yr3111 	&VIff%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&   	---- 	 	 	D	 :s   B 
B)(B)0C C"!C"H= BH% %H98H9=III6 6
JJ9K K#"K#'L, >L L,  L$$L, 'L$(L, ,
M 7MM 
MM MM c                 f   t          | |          }t          |          }|sdS |                    d          t          j                    k    rdS |                    d          t          t          j                              k    rdS 	 |                    d           dS # t          $ r Y dS w xY w)zDRelease a previously-acquired scope lock when owned by this process.Nr0   r   Tr   )rW   r   r   r#   r   rb   r   rE   )rT   rK   r   r  s       r   release_scoped_lockr  .  s    $UH55Iy))H ||Ebikk))||L!!%<RY[[%I%IIID)))))   s   
B" "
B0/B0)	owner_pidowner_start_timer  r  c                    t                      }d}|                                r|                    d          D ]}| t          |          }t	          |t
                    s)	 t          |                    d                    }n# t          t          f$ r Y `w xY w|| k    rk||                    d          |k    r	 |
                    d           |dz  }# t          $ r Y w xY w|S )	a&  Remove scoped lock files in the lock directory.

    Called during --replace to clean up stale locks left by stopped/killed
    gateway processes that did not release their locks gracefully. When an
    ``owner_pid`` is provided, only lock records belonging to that gateway
    process are removed. ``owner_start_time`` further narrows the match to
    protect against PID reuse.

    When no owner is provided, preserves the legacy behavior and removes every
    scoped lock file in the directory.

    Returns the number of lock files removed.
    r   z*.lockNr0   r   Tr   r   )r(   r   globr   r   r   r[   r   r   r`   r   rE   )r  r  lock_dirremoved	lock_filer   
record_pids          r   release_all_scoped_locksr"  >  s'   $ HG !x00 	 	I$(33!&$// !$VZZ%6%6!7!7JJ!:.   H**$0

<004DDD  D 1111   Ns$   $"BBBC
C+*C+z.gateway-takeover.json<   c                  2    t                      } | t          z  S )z6Return the path to the --replace takeover marker file.)r   _TAKEOVER_MARKER_FILENAMEr   s    r   _get_takeover_marker_pathr&    s    D+++r   
target_pidc                     	 t          |           }| |t          j                    t                      d}t	          t                      |           dS # t          t          f$ r Y dS w xY w)a  Record that ``target_pid`` is being replaced by the current process.

    Captures the target's ``start_time`` so that PID reuse after the
    target exits cannot later match the marker. Also records the
    replacer's PID and a UTC timestamp for TTL-based staleness checks.

    Returns True on successful write, False on any failure. The caller
    should proceed with the SIGTERM even if the write fails (the marker
    is a best-effort signal, not a correctness requirement).
    )r'  target_start_timereplacer_pid
written_atTF)rb   r#   r   r.   r   r&  rE   r_   )r'  r)  r   s      r   write_takeover_markerr,    s|    3J??$!2IKK&..	
 
 	244f===t_%   uus   AA A('A(c                  P   t                      } t          |           }|sdS 	 t          |d                   }|                    d          }|                    d          pd}nF# t          t
          t          f$ r, 	 |                     d           n# t          $ r Y nw xY wY dS w xY wd}	 t          j
        |          }t          j        t          j                  |z
                                  }|t          k    rd}n# t
          t          f$ r d}Y nw xY w|r*	 |                     d           n# t          $ r Y nw xY wdS t!          j                    }t%          |          }	||k    o|duo	|	duo||	k    }
	 |                     d           n# t          $ r Y nw xY w|
S )	a  Check & unlink the takeover marker if it names the current process.

    Returns True only when a valid (non-stale) marker names this PID +
    start_time. A returning True indicates the current SIGTERM is a
    planned --replace takeover; the caller should exit 0 instead of
    signalling ``_signal_initiated_shutdown``.

    Always unlinks the marker on match (and on detected staleness) so
    subsequent unrelated signals don't re-trigger.
    Fr'  r)  r+  r7   Tr   N)r&  r   r[   r   r   r   r`   r   rE   r   fromisoformatr+   r   r,   total_seconds_TAKEOVER_MARKER_TTL_Sr#   r   rb   )r   r   r'  r)  r+  r  
written_dtageour_pidour_start_timematchess              r    consume_takeover_marker_for_selfr6    s'    %&&DT""F u	-..
"JJ':;;ZZ--3

i,   	KK4K(((( 	 	 	D	uu E+J77
|HL))J6EEGG'''Ez"     	KK4K(((( 	 	 	D	u ikkG,W55Ng 	0T)	0$&	0 /	 t$$$$    Nsm   AA% %B(=BB(
B!B( B!!B('B(.AD DDD6 6
EE?F 
F#"F#c                  n    	 t                                          d           dS # t          $ r Y dS w xY w)zDRemove the takeover marker unconditionally. Safe to call repeatedly.Tr   N)r&  r   rE   r   r   r   clear_takeover_markerr8    sL    !##**d*;;;;;   s   "& 
44Tr   c                b   | pt                      }t          |          }t          |          }|st          ||           dS t	          |          }t          |          }||fD ]}t          |          }|	 t          j        |d           n;# t          $ r Y 7t          $ r t          |          r|cY c S Y Wt          $ r Y bw xY w|                    d          }	t          |          }
|		|
|
|	k    rt          |          st          |          r|c S t          ||           dS )zReturn the PID of a running gateway instance, or ``None``.

    Checks the PID file and verifies the process is actually alive.
    Cleans up stale PID files automatically.
    r9  Nr   r   )r   r   r   r   r   r   r   r#   r>   r  r_   r   rE   r   rb   r~   )r   r   resolved_pid_pathr   lock_activeprimary_recordfallback_recordr   r0   recorded_startr  s              r   get_running_pidr@    s    !3MOO/0ABB01CDDK !"3=QQQQt%&788N/0BCCO!?3  v&&;	GCOOOO! 	 	 	H 	 	 	 *&11 




H 	 	 	 H	
  L11/44%-*CYgHgHg&s++ 	/I&/Q/Q 	JJJ	 /}MMMM4s   ;B
C	C	=	C	C	c                (    t          | |          duS )z1Check if the gateway daemon is currently running.r9  N)r@  r   s     r   is_gateway_runningrB    s     8=AAAMMr   r*   )r   N)M__doc__rO   r   r#   r?   r:   r   r   r   pathlibr   hermes_constantsr   typingr   r	   utilsr   r   r   r   r   r   r%   r9   objectr   r   r   r   r   r   r   r(   r<   r.   r[   r   rJ   rS   rW   rb   rd   ro   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  tupler  r  r"  r%  r0  r&  r,  r6  r8  r@  rB  r   r   r   <module>rJ     s      				      



 ' ' ' ' ' ' ' '       , , , , , ,                 # # # # # #<7MMMMLLL +  lg%	'   #  t        ) )Xd^ )t ) ) ) );$ ; ; ; ;
2t 2 2 2 22c 2 2 2 2 .3   s d t    6E# E# E E E EE Es Et E E E E #    ( ( ( ( ( (

Os 
Ox} 
O 
O 
O 
O;S ;T ; ; ; ; ;tCH~ ;$ ; ; ; ;&4    
d38n 
 
 
 
:$ :8DcN#; : : : : I4 I$sCx. IT I I I I x~ $    0C C$ C8DQTVYQYNC[ C C C CXd38n5 (3-          ,   d        d    *    htn     .   6  # ($ ($ ($($ ($ 	($
 ($ ($ ($ ($ ($ 
($ ($ ($ ($V7Xd38n5 7 7 7 7
   0W Ws Wc WXd3PS8n=U Wafgkmuvz{~  AD  |D  wE  nF  hF  bG W W W Wts c d    $  $&** * *}* sm* 		* * * *@ 5  ,4 , , , ,c d    2>$ > > > >B     $2 2 2 2tn2 2 c]	2 2 2 2l  $N N N NtnN N 
	N N N N N Nr   