+
    jHàjÇ!  ã                  ó¢  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
Ht ^ RIHt ^ RIHt ^ RIHtHtHt RtRt^Nt]P,                  ! R	4      tR
tR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R lt R&R R llt!R&R R llt"R R  lt#R! R" lt$R&R# R$ llt%]&R%8X  d   ]PN                  ! ]%! 4       4       R# R# )'zQRun a child process while prefixing each stdout and stderr line with a timestamp.)ÚannotationsN)ÚMapping)Údatetime)ÚPath)ÚBinaryIOÚSequenceÚTextIOz--external-supervisorÚHERMES_LAUNCHD_LABELz2^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}(?:\s|$)g      @c               ó   € V ^8„  d   QhRR/# )é   ÚreturnÚstr© )Úformats   "Ú@/home/ubuntu/.hermes/hermes-agent/hermes_cli/stderr_timestamp.pyÚ__annotate__r      s   € ÷ @ñ @�3ñ @ó    c                 óX   € \         P                  ! 4       P                  R4      R,          # )zfLocal time in logging.Formatter's default ``%(asctime)s`` shape, which ``hermes logs --since`` parses.z%Y-%m-%d %H:%M:%S,%f:Né   N)r   ÚnowÚstrftimer   r   r   Ú	timestampr      s   € ä�<Š<‹>×"Ñ"Ð#9Ó:¸3Õ?Ð?r   c               ó    € V ^8„  d   QhRRRR/# )r   Úliner   r   r   )r   s   "r   r   r   "   s   € ÷ #ñ #�Sð #˜Sñ #r   c                ó†   € V P                  R4      p\        P                  V4      '       d   RM\        4        R2pV V R2# )zZ*line* with a leading :func:`timestamp` (kept as-is if it already has one) and one ``\n``.z
Ú Ú Ú
)ÚrstripÚ_TIMESTAMP_PREFIXÚmatchr   )r   ÚrenderedÚprefixs   &  r   Ú
stamp_liner#   "   sA   € à�{‰{˜6Ó"€HÜ$×*Ñ*¨8×4Ò4‰R¼Y»[¸MÈÐ:K€FØˆX�h�Z˜rÐ"Ð"r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úlog_filer   r   r   r   ÚNoner   )r   s   "r   r   r   )   s!   € ÷ ñ  fð °Cð ¸Dñ r   c                óZ   € V P                  \        V4      4       V P                  4        R # ©N)Úwriter#   Úflush)r%   r   s   &&r   Ú_write_timestamped_liner+   )   s   € Ø‡N�N”:˜dÓ#Ô$Ø‡N�NÖr   c               ó    € V ^8„  d   QhRRRR/# )r   Úlog_pathr   r   r   r   )r   s   "r   r   r   .   s   € ÷ =ñ =˜ð = ñ =r   c                ód   € V P                   P                  R R R7       V P                  RR^R7      # )T)ÚparentsÚexist_okÚaúutf-8)ÚencodingÚ	buffering)ÚparentÚmkdirÚopen)r-   s   &r   Ú	_open_logr8   .   s.   € Ø‡O�O×Ñ $°ÐÔ6Ø�=‰=˜ w¸!ˆ=Ó<Ð<r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Ústderrr   r-   r   r   r&   r   )r   s   "r   r   r   3   s&   € ÷ Zñ Z¨ð Z¸Tð ZÀdñ Zr   c                óØ   € \        V4      ;_uu_ 4       p\        V P                  R 4       F  p\        W#P	                  RRR7      4       K!  	  RRR4       R#   + '       g   i     R# ; i)r   r2   Úreplace©ÚerrorsN)r8   ÚiterÚreadliner+   Údecode)r:   r-   r%   Úraw_lines   &&  r   Ú_copy_stderr_with_timestampsrC   3   sH   € Ü	�8×	Ô	 Ü˜VŸ_™_¨cÖ2ˆHÜ# H¯o©o¸gÈi¨oÓ.XÖYñ 3÷ 
×	×	Ò	ús   ”:AÁA)	c               ó    € V ^8„  d   QhRRRR/# )r   Ústdoutr   r   r&   r   )r   s   "r   r   r   9   s   € ÷ Uñ U¨ð U°dñ Ur   c                óâ   € \        ^RR^RR7      ;_uu_ 4       p\        V P                  R4       F  p\        WP	                  RRR7      4       K!  	  RRR4       R#   + '       g   i     R# ; i)	é   Úwr2   F)r3   r4   Úclosefdr   r<   r=   N)r7   r?   r@   r+   rA   )rE   ÚoutrB   s   &  r   Ú_copy_stdout_with_timestampsrK   9   sS   € ô 
ˆa�˜w°!¸U×	CÕ	CÀsÜ˜VŸ_™_¨cÖ2ˆHÜ# C¯©¸È¨Ó)SÖTñ 3÷ 
D×	C×	CÒ	Cús   ™:AÁA.	c               ó    € V ^8„  d   QhRRRR/# )r   Úproczsubprocess.Popen[bytes]r   zdict[int, object]r   )r   s   "r   r   r   A   s   € ÷ ñ Ð%<ð ÐARñ r   c           	     ó˜  a € R  V 3R llp/ p\         P                  \         P                  \        \         RR4      \        \         RR4      \        \         RR4      3pV F8  pVf   K	   \         P                  ! V4      W$&   \         P                   ! WA4       K:  	  V#   \
        \        \        3 d    TP                  TR4        Ki  i ; i)c               ó$   € V ^8„  d   QhRRRRRR/# )r   ÚsignumÚintÚ_frameÚobjectr   r&   r   )r   s   "r   r   Ú0_install_signal_forwarders.<locals>.__annotate__B   s!   € ÷ ñ ˜ð  fð °ñ r   c                óP   <€  SP                  V 4       R #   \         d     R # i ; ir(   )Úsend_signalÚProcessLookupError)rP   rR   rM   s   &&€r   Ú_forwardÚ,_install_signal_forwarders.<locals>._forwardB   s(   ø€ ð	Ø×Ñ˜VÖ$øÜ!ô 	Úð	ús   ƒ –%¤%ÚSIGHUPNÚSIGUSR1ÚSIGUSR2)	ÚsignalÚSIGTERMÚSIGINTÚgetattrÚ	getsignalÚOSErrorÚRuntimeErrorÚ
ValueErrorÚpop)rM   rX   ÚpreviousÚ	forwardedrP   s   f    r   Ú_install_signal_forwardersrh   A   s²   ø€ ÷ð ð #%€Hô 	�‰Ü�‰Ü”˜ $Ó'Ü”˜	 4Ó(Ü”˜	 4Ó(ð€Ió ˆØÔð+Ü#)×#3Ò#3°FÓ#;�Ñ Ü—’˜fÖ/ñ	 ð €Oøô œ\¬:Ð6ô +Ø—‘˜V T×*ð+ús   Á).BÂ(C	ÃC	c               ó    € V ^8„  d   QhRRRR/# )r   ÚcommandúSequence[str]r   Úboolr   )r   s   "r   r   r   `   s   € ÷ 
Zñ 
Z¨ð 
Z¸4ñ 
Zr   c                ó‚   €  ^ RI Hp \        T! RP	                  R T  4       4      4      4      #   \         d     R# i ; i)zþTrue for Hermes ``gateway run`` argv this wrapper is allowed to upgrade.

The wrapper is generic. Only historical/current Hermes gateway shapes get ``--external-
supervisor``; an arbitrary launchd child must not be marked as gateway-supervised (#87005).
)Úlooks_like_gateway_command_lineFr   c              3  ó8   "  € T F  p\        V4      x € K  	  R # 5ir(   )r   )Ú.0Úparts   & r   Ú	<genexpr>Ú._is_hermes_gateway_run_argv.<locals>.<genexpr>j   s   é € Ð8WÉwÀt¼¸T¿¸Ëwùs   ‚)Úgateway.statusrn   Ú	Exceptionrl   Újoin)rj   rn   s   & r   Ú_is_hermes_gateway_run_argvrw   `   s@   € ðÝBô Ñ/°·±Ñ8WÉwÓ8WÓ0WÓXÓYÐYøô ô Úðús   ‚/ ¯>½>c               ó    € V ^8„  d   QhRRRR/# )r   ÚenvironúMapping[str, str] | Noner   zdict[str, str]r   )r   s   "r   r   r   m   s   € ÷ ñ Ð&>ð È.ñ r   c                óø   € V f   \         P                  MT pR\        3 FW  p\        VP	                  VR4      ;'       g    R4      P                  4       pVP                  R4      '       g   KO  \        V/u # 	  / # )u@  Env vars that carry this wrapper's launchd identity to the grandchild.

launchd stamps ``XPC_SERVICE_NAME=<job label>`` only on this wrapper (its direct child; an
interactive shell has none, the grandchild sees ``XPC_SERVICE_NAME=0``). Re-exporting the
label lets the gateway resolve its job without it (the stop-drain cap reading the live
``ExitTimeOut``, the exit-75 restart route, the control-socket supervisor declaration â€” all
via ``gateway.restart.launchd_job_label``). Only ``ai.hermes.*`` labels are exported;
app-coalition labels are meaningless as a job identity.
ÚXPC_SERVICE_NAMEr   z	ai.hermes)Úosry   Ú_LAUNCHD_LABEL_ENVr   ÚgetÚstripÚ
startswith)ry   ÚenvÚvariableÚlabels   &   r   Ú_child_launchd_label_envr…   m   sl   € ð  šŒ"�*Š*¨W€CØ'Ô);Ó<ˆÜ�C—G‘G˜H bÓ)×/Ð/¨RÓ0×6Ñ6Ó8ˆØ×Ñ˜K×(Ô(Ü&¨Ð.Ò.ñ =ð €Ir   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rj   rk   ry   rz   r   z	list[str]r   )r   s   "r   r   r      s#   € ÷ ñ  Mð Ð<Tð Ð`iñ r   c                óB  € V  Uu. uF  p\        V4      NK  	  ppVf   \        P                  MTp\        VP                  RR4      4      P	                  4       p\
        V9  d6   V'       d.   VR8w  d'   \        V4      '       d   VP                  \
        4       V# u upi )a‚  Return the argv to exec, upgrading stale launchd-wrapped gateway commands.

launchd stamps ``XPC_SERVICE_NAME=<job label>`` only on this wrapper (its direct child; an
interactive shell has none, the grandchild sees ``XPC_SERVICE_NAME=0``). Newly generated
plists put ``--external-supervisor`` on the inner ``gateway run`` so ``hermes update`` can see
the flag on the live process argv.
r|   r   Ú0)r   r}   ry   r   r€   ÚEXTERNAL_SUPERVISOR_FLAGrw   Úappend)rj   ry   rq   Úargvr‚   Úxpc_services   &&    r   Ú_prepare_child_commandr�      s~   € ñ #*Ó*¡'˜$ŒC�ŽI¡'€DÐ*ØšŒ"�*Š*¨W€CÜ�c—g‘gÐ0°"Ó5Ó6×<Ñ<Ó>€KÜ tÔ+·ÀÈsÔ@RÔWrÐsw×WxÒWxØ�‰Ô,Ô-Ø€Kùò +s   …Bc               ó$   € V ^8„  d   QhRRRRRR/# )r   rj   rk   Ú
returncoderQ   r   r   )r   s   "r   r   r   �   s"   € ÷ ñ ¨mð Èð ÐQTñ r   c                ót   € V^ 8  d   ^€\        V4      ,           # V\        8X  d   \        V 4      '       d   ^ # V# )a  Exit status the launchd wrapper reports for *returncode* from *command*.

Signal deaths stay 128+N. Gateway EX_CONFIG (78) becomes 0 so
``KeepAlive.SuccessfulExit=false`` parks the job instead of crash-looping;
a non-gateway child that happens to exit 78 is left alone.
)ÚabsÚ_GATEWAY_FATAL_CONFIG_EXIT_CODErw   )rj   r�   s   &&r   Ú _child_returncode_for_supervisorr“   �   s8   € ð �A„~Ø”S˜“_Õ$Ð$ØÔ4Ô4Ô9TÐU\×9]Ò9]ÙØÐr   c               ó    € V ^8„  d   QhRRRR/# )r   r‹   úSequence[str] | Noner   zargparse.Namespacer   )r   s   "r   r   r   �   s   € ÷ ñ Ð*ð Ð/Añ r   c                ó’  € \         P                  ! R R7      pVP                  RR\        R7       VP                  R\         P                  R7       VP                  V 4      pVP                  '       d1   VP                  ^ ,          R8X  d   VP                  R,          Vn        VP                  '       g   VP                  R	4       V# )
zYRun a command, timestamp each stderr line into a log file and each stdout line to stdout.)Údescriptionz--error-logT)ÚrequiredÚtyperj   )Únargsz--:rG   NNzmissing command after --)ÚargparseÚArgumentParserÚadd_argumentr   Ú	REMAINDERÚ
parse_argsrj   Úerror)r‹   ÚparserÚargss   &  r   Ú_parse_argsr£   �   s˜   € Ü×$Ò$Øoô€Fð ×Ñ˜°¼4ÐÔ@Ø
×Ñ˜	¬×);Ñ);ÐÔ<Ø×Ñ˜TÓ"€DØ‡|‡|€|˜Ÿ™ Q�¨4Ô/Ø—|‘| BÕ'ˆŒØ�<�<ˆ<Ø�‰Ð/Ô0Ø€Kr   c               ó    € V ^8„  d   QhRRRR/# )r   r‹   r•   r   rQ   r   )r   s   "r   r   r   «   s   € ÷ Fñ FÐ#ð F¨sñ Fr   c                ó<  € \        V 4      pVP                  p \        P                  ! \	        VP
                  4      \        P                  \        P                  / \        P                  C\        4       CR 7      pTP                  e   TP                  f   Q h\        P                   ! \"        TP                  3RR7      pTP%                  4        \'        T4      p \)        TP                  T4       TP+                  4       pTP-                  \.        4       TP                  P1                  4        TP3                  4        F  w  rš\4        P4                  ! Yš4       K  	  \7        TP
                  T4      #   \         dK   p\        T4      ;_uu_ 4       p\        TRT 24       RRR4       M  + '       g   i     M; i Rp?^# Rp?ii ; i  TP                  P1                  4        TP3                  4        F  w  rš\4        P4                  ! Yš4       K  	  i ; i))rE   r:   r‚   z,failed to start stderr-timestamped command: NT)Útargetr¢   Údaemon)r£   Ú	error_logÚ
subprocessÚPopenr�   rj   ÚPIPEr}   ry   r…   rb   r8   r+   rE   r:   Ú	threadingÚThreadrK   Ústartrh   rC   Úwaitrv   Ú_STDOUT_DRAIN_TIMEOUT_SÚcloseÚitemsr]   r“   )r‹   r¢   r-   rM   Úexcr%   Ústdout_pumpÚprevious_handlersr�   rP   Úhandlers   &          r   Úmainr·   «   s‘  € Ü�tÓ€DØ—^‘^€Hð
Ü×ÒÜ" 4§<¡<Ó0Ü—?‘?Ü—?‘?Ø<”2—:‘:Ð<Ô!9Ó!;Ð<ô	
ˆð �;‰;Ò" t§{¡{Ò'>Ð>Ð>Ü×"Ò"Ô*FÈdÏkÉkÈ^ÐdhÔi€KØ×ÑÔÜ2°4Ó8Ðð	+Ü$ T§[¡[°(Ô;ð —Y‘Y“[ˆ
Ø×ÑÔ0Ô1à�‰×ÑÔØ0×6Ñ6Ö8‰OˆFÜ�MŠM˜&Ö*ñ  9ä+¨D¯L©L¸*ÓEÐEøô' ô Ü�x× Ô  HÜ# HÐ0\Ð]`Ð\aÐ.bÔc÷ !× × Ð úåûðûð  	�‰×ÑÔØ0×6Ñ6Ö8‰OˆFÜ�MŠM˜&Ö*ò  9ús=   ™A#E8 Ã;G Å8GÆGÆF/Æ&	GÆ/F?Æ:GÇGÇAHÚ__main__r(   )(Ú__doc__Ú
__future__r   r›   r}   Úrer]   r©   Úsysr¬   Úcollections.abcr   r   Úpathlibr   Útypingr   r   r   r‰   r~   r’   Úcompiler   r°   r   r#   r+   r8   rC   rK   rh   rw   r…   r�   r“   r£   r·   Ú__name__Úexitr   r   r   Ú<module>rÃ      s¿   ðÙ Wå "ã Û 	Û 	Û Û Û 
Û Ý #Ý Ý ß -Ñ -à2Ð Ø+Ð ð #%Ð à—J’JÐTÓUÐ ð Ð õ@õ
#õõ
=õ
ZõUõõ>
Z÷÷$õ õ÷FðB ˆzÔØ‡H‚H‰T‹VÖñ r   