+
    lHàjÙ  ã                   óú   € R t ^ RIt^ RIHt ^ RIt^ RIt^ RIHt ^ RIt^ RI	H
t
 ^ RIHt ^ RIHt ]P                  ! R4      tR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4      tR# )ak  File-backed output for background processes a registered worker starts.

A managed worker is a per-turn interpreter. A stdout pipe whose read end that worker's reader
thread owns closes when the worker exits, so the child's next write raises SIGPIPE
(``broken_pipe``) and everything it printed is gone. Under a worker the child writes to a
profile-scoped log instead and its shell records the exit status beside it (the contract the
env-backend wrapper already uses), so whichever interpreter adopts the checkpoint entry next
(the session's next worker, the owner at startup) tails the same file and collects the exit.
N)Úsuppress©ÚPath)ÚOptional)Úmake_user_dir©Úget_hermes_homeztools.process_registrygš™™™™™É?c                ó$   € V ^8„  d   QhR\         /# ©é   Úreturnr   )Úformats   "ÚF/home/ubuntu/.hermes/hermes-agent/tools/process_registry_output_log.pyÚ__annotate__r      s   € ÷ 9ñ 9”Dñ 9ó    c                  ó2   € \        4       R ,          R,          # )Úlogszprocess-outputr   © r   r   Ú
output_dirr      s   € ÜÓ˜vÕ%Ð(8Õ8Ð8r   c                óF   € V ^8„  d   QhR\         R\        \        ,          /# )r   Ú
session_idr   )Ústrr   r   )r   s   "r   r   r       s   € ÷ +ñ +¤#ð +¬(´4­.ñ +r   c                óð  € ^ RI Hp V! 4       '       g   R# \        4       p\        VRRRR7       ^ RIHp \        P                  ! 4       V,
          pVP                  R4       Fs  p\        \        4      ;_uu_ 4        VP                  4       P                  V8  d2   VP                  R4      P                  RR	7       VP                  4        RRR4       Ku  	  W  R2,          #   + '       g   i     K“  ; i)
zMThe log a worker-spawned process writes to; None outside a registered worker.)Úis_worker_processNiÀ  T)ÚmodeÚparentsÚexist_ok)ÚRESULT_RETENTION_SECONDSzproc_*.exitú.log)Ú
missing_ok)Úagent.runtime_session_storer   r   r   Útools.process_registry_resultsr   ÚtimeÚglobr   ÚFileNotFoundErrorÚstatÚst_mtimeÚwith_suffixÚunlink)r   r   Ú	directoryr   ÚcutoffÚexiteds   &     r   Úworker_output_logr,       s¸   € å=Ù×ÒÙÜ“€IÜ�) %°ÀÕEÝGä�YŠY‹[Ð3Õ3€FØ—.‘. Ö/ˆÜÔ'×(Õ(Ø�{‰{‹}×%Ñ%¨Ô.Ø×"Ñ" 6Ó*×1Ñ1¸TÐ1ÔBØ—‘”÷ )Ñ(ñ 0ð
 ˜ TÐ*Õ*Ð*÷	 )×(Ð(ús   Á<AC$Ã$C5c                ó$   € V ^8„  d   QhR\         /# r
   ©r   )r   s   "r   r   r   2   s   € ÷ \ñ \œ3ñ \r   c                ó¼   € \        \        T ;'       g    R4      4      pV '       d6   VP                  \        4       8X  d   VP                  R8X  d   \        V4      # R# )zLA checkpointed log path, only when it names this profile's output directory.Ú r   )r   r   Úparentr   Úsuffix)ÚpathÚlogs   & r   Úadoptable_logr5   2   s@   € ä
Œs�4—:�:˜2‹Ó
€Cß §
¡
¬j«lÔ :¸s¿z¹zÈVÔ?SŒ3ˆs‹8Ð[ÐY[Ð[r   c                ó0   € V ^8„  d   QhR\         R\        /# )r   r4   r   )r   Úint)r   s   "r   r   r   8   s   € ÷ dñ dœð d¤#ñ dr   c           	     óÎ   € \         P                  ! V \         P                  \         P                  ,          \         P                  ,          \        \         R^ 4      ,          R4      # )zXOwner-only append descriptor for the child's stdout+stderr (the parent closes its copy).ÚO_BINARYi€  )ÚosÚopenÚO_WRONLYÚO_CREATÚO_APPENDÚgetattr©r4   s   &r   Úopen_output_logrA   8   s;   € ä�7Š7�3œŸ™¤b§j¡jÕ0´2·;±;Õ>ÄÌÈZÐYZÓA[Õ[Ð]bÓcÐcr   c                ó$   € V ^8„  d   QhR\         /# r
   r   )r   s   "r   r   r   =   s   € ÷ *ñ *”tñ *r   c                 ó6   € \        V 4      P                  R 4      # )z.exit)r   r'   r@   s   &r   Ú
_exit_pathrD   =   s   € Ü�‹9× Ñ  Ó)Ð)r   c                ó<   € V ^8„  d   QhR\         R\        R\        /# )r   r4   Úcommandr   )r   r   )r   s   "r   r   r   A   s&   € ÷ tñ tœTð t¬Cð t´Cñ tr   c                ój   € ^ RI pVP                  \        V 4      P                  4       4      pRV RV 2# )zŸPrefix ``command`` so the shell writes its exit status beside the log: an interpreter
that adopts the process after the spawner exited has no Popen to wait on.Nz__hermes_exit_file=z9; trap 'printf "%s\n" "$?" > "$__hermes_exit_file"' EXIT
)ÚshlexÚquoterD   Úas_posix)r4   rF   rH   Útargets   &&  r   Úrecord_exit_commandrL   A   s8   € ó Ø�[‰[œ C›×1Ñ1Ó3Ó4€FØ   Ð(iÐjqÐirÐsÐsr   c                ó:   € V ^8„  d   QhR\         \        ,          /# r
   )r   r7   )r   s   "r   r   r   I   s   € ÷ ñ œx¬�}ñ r   c                 ó˜   €  \        \        V 4      P                  R R7      P                  4       4      #   \        \
        3 d     R# i ; i)z	utf-8-sig)ÚencodingN)r7   rD   Ú	read_textÚstripÚOSErrorÚ
ValueErrorr@   s   &r   Úrecorded_exit_coderT   I   sD   € ðÜ”:˜c“?×,Ñ,°kÐ,ÓB×HÑHÓJÓKÐKøÜ”ZÐ ô Úðús   ‚14 ´A	ÁA	c                   ó6   a € ] tR t^Pt o RtV 3R lR ltRtV tR# )ÚProcessOutputLogMixinzšThe subclass supplies ``_ingest_output``, ``_clean_shell_noise``, ``_finish_reader``,
``_finish_exited`` and ``_detached_host_fate``. See ProcessRegistry.c                ó   <€ V ^8„  d   QhRR/# )r   r   Nr   )r   Ú__classdict__s   "€r   r   Ú"ProcessOutputLogMixin.__annotate__T   s   ø€ ÷ 3/ñ 3/¨4ñ 3/r   c           	     óÄ  a aaa€ \         P                  ! R4      ! RR7      pSP                  oRSn        RoR VV V3R llpR VV V3R llp \	        SP
                  R	4      ;_uu_ 4       p^ p V! 4       pVP                  R
4      pV'       dJ   VP                  V4      ;p	'       d	   V! V	4       Yg'       d   ^ M
\        V4      ,          pV\        8  d   Kj  V'       g   M\        P                  ! \        4       K�  RRR4       Se&   S P!                  SY#RSP"                  T3R l4       R# TP                  RRR7      ;p'       d	   T! T4       \%        SP
                  4      pTf   S P'                  SRRRR7       R# S P'                  ST4       R#   + '       g   i     L ; i  \         d,   p
\        P                  RSP
                  T
4        Rp
?
LÔRp
?
ii ; i)z¤Tail ``session.output_log`` until its process ends. The spawner decides the exit from
its Popen; an adopter (no Popen) from the recorded status, else ``lost`` (-1).zutf-8Úreplace)ÚerrorsTc                ó(   € V ^8„  d   QhR\         RR/# )r   Útextr   Nr.   )r   s   "r   r   Ú<ProcessOutputLogMixin._log_reader_loop.<locals>.__annotate__^   s   € ÷ 	/ñ 	/œð 	/ ñ 	/r   c                 óˆ   <€ S'       d'   SP                  V 4      p V P                  4       '       * oSP                  SV 4       R # ©N)Ú_clean_shell_noiserQ   Ú_ingest_output)r^   Ú
head_noiseÚselfÚsessions   &€€€r   ÚingestÚ6ProcessOutputLogMixin._log_reader_loop.<locals>.ingest^   s4   ø€ çØ×.Ñ.¨tÓ4�Ø!%§¡£Ô-�
Ø×Ñ ¨Ö.r   c                ó$   € V ^8„  d   QhR\         /# r
   )Úbool)r   s   "r   r   r_   e   s   € ÷ 	_ñ 	_œñ 	_r   c                  óÆ   <€ SP                   P                  4       '       d   R # S e   S P                  4       RJ # SP                  SP                  SP
                  4      R8H  # )FNÚrunning)Ú_reader_finish_requestedÚis_setÚpollÚ_detached_host_fateÚpidÚhost_start_time)Úprocre   rf   s   €€€r   rl   Ú7ProcessOutputLogMixin._log_reader_loop.<locals>.runninge   sU   ø€ Ø×/Ñ/×6Ñ6×8Ò8ÙØÒØ—y‘y“{ dÐ*Ð*Ø×+Ñ+¨G¯K©K¸×9PÑ9PÓQÐU^Ñ^Ð^r   Úrbi   Nz$Process output log %s unreadable: %sÚLogc                  ó   <€ S P                   # ra   )Ú
returncode)rs   s   €r   Ú<lambda>Ú8ProcessOutputLogMixin._log_reader_loop.<locals>.<lambda>~   s   ø€ ÐTX×TcÒTcr   r   )ÚfinalÚlostÚbackend_lost)ÚreasonÚsourceéÿÿÿÿ)ÚcodecsÚgetincrementaldecoderÚprocessÚ_reader_selectabler;   Ú
output_logÚreadÚdecodeÚlenÚ_FINAL_DRAIN_MAX_BYTESr"   ÚsleepÚ_TAIL_SECONDSrR   ÚloggerÚwarningÚ_finish_readerÚwaitrT   Ú_finish_exited)re   rf   Údecoderrg   rl   ÚstreamÚdrainedÚaliveÚchunkr^   ÚexcÚtailÚcoderd   rs   s   ff           @@r   Ú_log_reader_loopÚ&ProcessOutputLogMixin._log_reader_loopT   s‰  û€ ô ×.Ò.¨wÔ7¸yÔIˆØ�‰ˆà%)ˆÔ"àˆ
÷	/ò 	/÷	_ò 	_ð	\Ü�g×(Ñ(¨$×/Ô/°6Ø�Øá#›I�EØ"ŸK™K¨Ó.�EßØ#*§>¡>°%Ó#8Ð8˜4Ö8Ù" 4œLØ®¡1´3°u³:Õ=˜Ø"Ô%;Ô;Ù$ß ØÜ—J’Jœ}Ö-÷ 0ð" ÒØ×Ñ ¨¸%ÀÇÁÔLcÔdÙØ—>‘> #¨T�>Ó2Ð2ˆ4Ö2Ù�4ŒLÜ! '×"4Ñ"4Ó5ˆØŠ<à×Ñ ¨°FÀ>ÐÖRà×Ñ ¨Ö.÷7 0×/ûô ô 	\Ü�N‰NÐAÀ7×CUÑCUÐWZ×[Ñ[ûð	\úsH   ÁF) Á,#FÂFÂ)7FÃ!FÃ>F) ÆF&	Æ!F) Æ&F) Æ)GÆ4!GÇGr   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r™   Ú__static_attributes__Ú__classdictcell__)rX   s   @r   rV   rV   P   s   ø‡ € ñL÷3/ö 3/r   rV   i   )rŸ   r�   Ú
contextlibr   Úloggingr:   Úpathlibr   r"   Útypingr   Úhermes_dir_aclr   Úhermes_constantsr   Ú	getLoggerrŒ   r‹   r‰   r   r,   r5   rA   rD   rL   rT   rV   r   r   r   Ú<module>r©      ss   ðñó Ý Û Û 	Ý Û Ý Ý (å ,à	×	Ò	Ð3Ó	4€à€à Ð õ9õ+õ$\õdõ
*õtõ÷7/ó 7/r   