+
    „WÝjØ  ã                  ó²   € R t ^ RIHt ^ RIt^ RIHt ^ RIHtHt R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/R R lltRR]	R]/R R llltR# )uD  Name what a draining gateway is waiting on while ``hermes update`` blocks on it.

The gateway's in-band restart (SIGUSR1 â†’ ``request_restart``) defers ``stop()`` until in-flight
work finishes, capped by ``agent.restart_after_turn_timeout`` (30 min by default). From the
updater's side that was a bare "draining (up to 1875s)..." followed by silence, which reads as a
hung update. The gateway publishes each unit it is holding for in ``gateway_state.json``
(``active_work``, written by ``GatewayShutdownMixin._describe_active_work``); this module turns
that into progress lines.
)ÚannotationsN)ÚPath)ÚCallableÚOptionalg      >@c               ó    € V ^8„  d   QhRRRR/# )é   ÚsecondsÚobjectÚreturnÚstr© )Úformats   "ÚVC:\Users\johnn\AppData\Local\hermes\hermes-agent\hermes_cli\update_cmd_drain_report.pyÚ__annotate__r      s   € ÷ Nñ N˜&ð N Sñ Nó    c                ó¢   €  \        \        V 4      4      pT^<8¼  d   T^<,           RT^<,          R R2# T R2#   \        \        3 d     R # i ; i)Ú?ÚmÚ02dÚs)ÚintÚfloatÚ	TypeErrorÚ
ValueError)r   Útotals   & r   Ú_fmt_elapsedr      s_   € ðÜ”E˜'“NÓ#ˆð 27¸"´ˆe�r�kˆ]˜!˜E B�J sÐ+¨1Ð-ÐMÀUÀGÈ1À+ÐMøô ”zÐ"ô Úðús   ‚9 ¹AÁAc               ó$   € V ^8„  d   QhRRRRRR/# )r   Újob_idr   ÚhomeúOptional[Path]r
   zOptional[str]r   )r   s   "r   r   r      s!   € ÷ ñ ˜3ð  nð ¸ñ r   c                ó~  €  ^ RI HpHp ^ RIHp V'       d	   V! V4      MRp V! 4        F_  p\        VP                  R4      4      V 8X  g   K$  \        VP                  R4      ;'       g    R4      ;'       g    Ru Ve
   V! V4       # # 	  Ve	   V! V4       R#   Te
   T! T4       i i ; i  \         d     R# i ; i)uf   ``name`` from the profile's ``jobs.json`` (None when unreadable â€” the id alone still identifies it).)Úreset_hermes_home_overrideÚset_hermes_home_override)Ú	load_jobsNÚidÚnameÚ )Úhermes_constantsr!   r"   Ú	cron.jobsr#   r   ÚgetÚ	Exception)r   r   r!   r"   r#   ÚtokenÚjobs   &&     r   Ú_cron_job_namer-      sµ   € ðßYÝ'ç26Ñ(¨Ô.¸Dˆð	2Ù –{�Ü�s—w‘w˜t“}Ó%¨Ö/Ü˜sŸw™w v›×4Ð4°"Ó5×=Ð=¸Ñ=àÒ Ù*¨5Õ1ð !ñ	 #ð Ò Ù*¨5Ô1ñ øð	 Ò Ù*¨5Õ1ð !ûäô ÚðúsK   ‚B- ˜
B- £&B ÁB Á+B Á9B Á=B- ÂB ÂB- ÂB*Â*B- Â-B<Â;B<c               ó$   € V ^8„  d   QhRRRRRR/# )r   ÚunitÚdictr   r   r
   r   r   )r   s   "r   r   r   0   s!   € ÷ 1ñ 1 Dð 1°ð 1È#ñ 1r   c                ó  € \        V P                  R4      ;'       g    R4      pV P                  R4      pV'       d   RV 2MRpV P                  R4      pVe   R\        V4       2MRpVR8X  ds   \        V P                  R	4      ;'       g    R
4      p\        Wq4      pRV 2V'       d   RV R2MR,           p	V P                  R4      '       d   RV 2MRV 2p
V	 V
 V 2# VR8X  dŸ   \        V P                  R4      ;'       g    R
4      pV P                  R4      pV P                  R4      pRP	                  R V'       d   RV 2MRV'       d   RV 2MR3 4       4      pRV V V 2V'       d   RV R2,           # R,           # VR8X  dp   \        V P                  R4      ;'       g    R4      P                  4       pRV P                  R4      ;'       g    R
 V V 2V'       d   RV R2,           # R,           # V R V V 2# )!zWOne human line for one ``active_work`` entry; unknown shapes degrade to their ``kind``.ÚkindÚworkÚpidz pid r&   Ú	elapsed_sz
, running Úcronr   r   z	cron job z (Ú)Úexternalz in external workerz in-processÚchatÚsessionÚmodelÚcurrent_toolz, c              3  ó8   "  € T F  q'       g   K  Vx € K  	  R # 5i©Nr   )Ú.0Úps   & r   Ú	<genexpr>Ú,describe_active_work_unit.<locals>.<genexpr>A   s   é € ÐoÑ&i ÓmnŸ1š1Ó&iùs   ‚	�
zmodel ztool z
chat turn z [Ú]Ú
delegationÚgoalzbackground delegation Údelegation_idz run)r   r)   r   r-   ÚjoinÚstrip)r/   r   r2   r4   Úpid_partÚelapsedÚelapsed_partr   r%   ÚlabelÚwherer:   r;   ÚtoolÚdetailrE   s   &&              r   Údescribe_active_work_unitrP   0   s  € äˆt�x‰x˜Ó×)Ð) 6Ó*€DØ
�(‰(�5‹/€Cß #��s�e‰}¨€HØ�h‰h�{Ó#€GØ;BÒ;N�Z¤¨WÓ 5Ð6Ñ7ÐTV€LØˆv„~Ü�T—X‘X˜hÓ'×.Ð.¨3Ó/ˆÜ˜fÓ+ˆØ˜F˜8Ð$¿¨"¨T¨F°!©À"ÕEˆØ48·H±H¸Z×4HÒ4HÐ% h ZÑ0ÐP[Ð\dÐ[eÐNfˆØ�˜˜ ˜~Ð.Ð.Øˆv„~Ü�d—h‘h˜yÓ)×0Ð0¨SÓ1ˆØ—‘˜Ó!ˆØ�x‰x˜Ó'ˆØ—‘Ño¿5¨°¨wÑ'7Àb×\`ÈEÐRVÐQWÉ.ÐfhÑ&iÓoÓoˆØ˜G˜9 X J¨|¨nÐ=×SYÀ2ÀfÀXÈQÀÕbÐbÐ_aÕbÐbØˆ|ÔÜ�4—8‘8˜FÓ#×)Ð) rÓ*×0Ñ0Ó2ˆØ(¨¯©°/Ó)B×)IÐ)IÀcÐ(JÈ8È*ÐUaÐTbÐcß#'�R˜�v˜Q�<õ1ð 	2Ø-/õ1ð 	2àˆV�4˜�z , Ð0Ð0r   c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r
   úOptional[list]r   )r   s   "r   r   r   J   s   € ÷ 	ñ 	˜>ð 	°^ñ 	r   c                óâ   €  ^ RI Hp T! V '       d
   V R,          MR4      ;'       g    / pVP                  R4      p\        V\        4      '       d   \	        V4      # R#   \
         d     R# i ; i)zd``active_work`` as the gateway last published it, or None (old gateway / not draining / unreadable).)Úread_runtime_statuszgateway_state.jsonNÚactive_work)Úgateway.statusrT   r)   Ú
isinstanceÚlistr*   )r   rT   Úrecordr3   s   &   r   Úread_active_workrZ   J   sb   € ðÝ6á$ÇD TÐ,@Ö%@ÈdÓS×YÐYÐWYˆØ�z‰z˜-Ó(ˆÜ'¨¬d×3Ò3Œt�D‹zÐ=¸Ð=øÜô Úðús!   ‚A ’A ¨4A ÁA ÁA.Á-A.c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r
   r   r   )r   s   "r   r   r   V   s   € ÷ Wñ W�~ð W¨#ñ Wr   c                óL   € ^ RI Hp V! V 4      pV'       d   VR8w  d   RV R2# R# )zUThe TUI command that opens *home*'s profile: a bare ``hermes`` opens the default one.)Úprofile_name_for_homeÚdefaultz
hermes -p z --tuizhermes --tui)r'   r]   )r   r]   r%   s   &  r   Ú_tui_commandr_   V   s,   € å6á  Ó&€Dß(,°¸Ô1BˆZ˜�v˜VÐ$ÐVÈÐVr   r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r3   rR   Úremaining_sr   r   r   r
   r   r   )r   s   "r   r   r   ^   s)   € ÷ ñ ˜nð ¸eð È>ð Ðehñ r   c               óî  a€ R\        V^ 4      R R2.pV f   VP                  R4       M¼V '       g   VP                  R4       M¢VP                  R\        V 4       R24       VP                  V3R lV  4       4       \        ;QJ d    R	 V  4       F  '       g   K   R
M	  RM! R	 V  4       4      '       d   VP                  R\        S4       R24       VP                  R4       RP                  V4      # )zSMulti-line progress block: what the gateway is waiting on plus how to stop waiting.u     â�³ still draining â€” z.0fz s left before the forced restartuc        (gateway did not report what it is waiting on â€” pre-update gateway or unreadable state file)zC     (no active work reported; the gateway should exit momentarily)z     waiting on z active work unit(s):c              3  óB   <"  € T F  pR \        VS4       2x € K  	  R# 5i)u          â€¢ N)rP   )r?   Úur   s   & €r   rA   Ú&format_drain_report.<locals>.<genexpr>g   s#   øé € ÐVÑQUÈA�{Ô#<¸QÀÓ#EÐ"FÕGÓQUùs   ƒc              3  óz   "  € T F1  p\        V\        4      ;'       d    VP                  R 4      R8H  x € K3  	  R# 5i)r2   r9   N)rW   r0   r)   )r?   rd   s   & r   rA   re   h   s/   é € ÐMÉÀ1Œz˜!œTÓ"×>Ð> q§u¡u¨V£}¸Ñ'>Ô>Ëùs   ‚;ž;TFz_     a chat turn waiting on an approval or clarify question can be answered now: open it with `z` (resume the session)z{     finish or kill the work above to release the drain now; agent.restart_after_turn_timeout in config.yaml caps this waitÚ
)ÚmaxÚappendÚlenÚextendÚanyr_   rG   )r3   ra   r   Úliness   &$d r   Úformat_drain_reportrn   ^   sÚ   ø€ à(¬¨[¸!Ó)<¸SÐ(AÐAaÐbÐc€EØ‚|Ø�‰ÐzÕ{ßØ�‰ÐZÕ[à�‰Ð'¬¨D«	 {Ð2GÐHÔIØ�‰ÔVÑQUÓVÔVß‹3ÑMÉÓM�3�3Š3ÑMÉÓM×MÒMð �L‰Lð *Ü*6°tÓ*<Ð)=Ð=SðUô Và�‰ð Vô 	Wà�9‰9�UÓÐr   Ú
interval_sÚemitc          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   r   r   Úbudget_sr   ro   rp   zCallable[[str], None]r
   zCallable[[], None]r   )r   s   "r   r   r   r   s2   € ÷ ñ  .ð Àeð Ø(-ðà"7ðàDVñr   c               ó`   a aaaaa€ \         P                  ! 4       oRS/oR VVV VVV3R llpV# )z—Return a zero-arg callback for ``_wait_for_pid_exit(on_progress=...)`` that prints the drain
report every ``interval_s`` while the wait is in progress.Úlastc               ó   € V ^8„  d   QhRR/# )r   r
   ÚNoner   )r   s   "r   r   Ú-drain_progress_reporter.<locals>.__annotate__z   s   € ÷ mñ m�4ñ mr   c                 óÀ   <€ \         P                  ! 4       p V SR ,          ,
          S8  d   R# V SR &   S! \        \        S4      SV S,
          ,
          SR7      4       R# )rt   N)ra   r   )ÚtimeÚ	monotonicrn   rZ   )Únowrr   rp   r   ro   ÚstartedÚstates    €€€€€€r   Ú_tickÚ&drain_progress_reporter.<locals>._tickz   sQ   ø€ Ü�nŠnÓˆØ��v•Õ Ô+ÙØˆˆf‰ÙÔ Ô!1°$Ó!7ÀXÐQTÐW^ÕQ^ÕE_ÐfjÔkÖlr   )ry   rz   )r   rr   ro   rp   r~   r|   r}   s   fddd @@r   Údrain_progress_reporterr€   r   s.   ý€ ô
 �nŠnÓ€GØ�WÐ€E÷mõ mð €Lr   r>   )Ú__doc__Ú
__future__r   ry   Úpathlibr   Útypingr   r   ÚDRAIN_REPORT_INTERVAL_Sr   r-   rP   rZ   r_   rn   Úprintr€   r   r   r   Ú<module>r‡      sb   ðñõ #ã Ý ß %ð Ð õNõ÷&1÷4	õWðÐ\`÷ ñ(Ø0Gðà:?÷ò r   