+
    jHàjÍ1  ã                  óB  € 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HtHt ^tRtR R ltRt]P$                  3R R	 lltR
RRR/R R lltR R ltRtR]RRRR/R R llt]P0                  R R l4       tR R ltR R ltRRR]RR/R  R! lltR# )"a  Quiet ``hermes chat -Q`` helpers: bind this session's key and resume nested notifies.

Bot Mode delivers a local DM as ``hermes -p <bot> chat -Q --query-file``. Interactive
chat binds ``set_current_session_key(self.session_id)`` around the turn; the quiet
path did not, so a nested ``message_agent`` notify inherited the dispatcher's
``HERMES_SESSION_KEY`` and never woke the recipient. Quiet also printed and exited
after one turn, so a nested teammate reply that finished during the one-shot linger
was never injected as a follow-up.
)ÚannotationsN)ÚAnyÚCallableÚMutableMappingz[kanban-worker-exit] rc=c               ó    € V ^8„  d   QhRRRR/# )é   ÚcodeÚintÚreturnÚNone© )Úformats   "ÚB/home/ubuntu/.hermes/hermes-agent/hermes_cli/quiet_single_query.pyÚ__annotate__r   !   s   € ÷ ñ ˜Cð  Dñ ó    c           	     óT  € \         P                  P                  R4      '       dZ   \        P                  ! \
        4      ;_uu_ 4        \        R\         \        V 4       2\        P                  RR7       RRR4       \        P                  ! V 4       R#   + '       g   i     L(; i)za``sys.exit(code)`` for a one-shot turn; a Kanban worker first writes the exit trailer to its log.ÚHERMES_KANBAN_TASKÚ
T)ÚfileÚflushN)ÚosÚenvironÚgetÚ
contextlibÚsuppressÚ	ExceptionÚprintÚKANBAN_WORKER_EXIT_TRAILERr	   ÚsysÚstderrÚexit)r   s   &r   Úexit_single_queryr!   !   sf   € ä	‡z�z‡~�~Ð*×+Ò+Ü× Ò ¤×+Õ+ô �BÔ1Ð2´3°t³9°+Ð>ÄSÇZÁZÐW[Õ\÷ ,ô ‡H‚HˆT†N÷	 ,×+ús   Á/BÂB'	ÚHERMES_QUIET_TURN_REPORT_FILEc               ó    € V ^8„  d   QhRRRR/# )r   r   úMutableMapping[str, str]r
   ú
str | Noner   )r   s   "r   r   r   4   s   € ÷ ;ñ ;Ð#;ð ;ÈZñ ;r   c                óB   € V P                  \        R4      ;'       g    R# )ziRead and remove the spawner's turn-report path so subprocesses started during the turn do not inherit it.N)ÚpopÚTURN_REPORT_FILE_ENV)r   s   &r   Útake_turn_report_pathr)   4   s   € à�;‰;Ô+¨TÓ2×:Ð:°dÐ:r   ÚerrorÚ Úreplyc          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   Úpathr%   Ú	exit_coder	   r*   Ústrr,   r
   r   r   )r   s   "r   r   r   9   s8   € ÷ Añ A˜Jð A°cð AÀ#ð AÐSVð AÐ`dñ Ar   c               óR  € V '       g   R# ^ RI Hp R\        P                  ! 4       R\	        V4      R\        T;'       g    R4      R\        T;'       g    R4      /p\        P                  ! \        4      ;_uu_ 4        V! WRRR	7       RRR4       R#   + '       g   i     R# ; i)
u  Atomically record ``{pid, exit_code, error, reply}`` at *path*; a no-op without a path. Never
raises: the report is the spawner's convenience, the turn itself is already persisted. ``reply``
is what the run will print â€” a spawner booking a lingering child from its report relays it.N)Úatomic_json_writeÚpidr/   r*   r+   r,   i€  )ÚindentÚmode)	Úutilsr2   r   Úgetpidr	   r0   r   r   r   )r.   r/   r*   r,   r2   Úrecords   &$$$  r   Úwrite_turn_reportr9   9   sv   € ÷ ÙÝ'à”R—Y’Y“[ +¬s°9«~¸wÌÈEÏKÈKÐUWÓHXÐZaÔcfÐgl×grÐgrÐprÓcsÐt€Fä	×	Ò	œY×	'Õ	'Ù˜$¨t¸%Õ@÷ 
(×	'×	'Ò	'ús   Á?BÂB&	c               ó$   € V ^8„  d   QhRRRRRR/# )r   r.   r0   r3   r	   r
   zdict | Noner   )r   s   "r   r   r   G   s!   € ÷ 	ñ 	˜3ð 	 Sð 	¨[ñ 	r   c                ó"  €  \        V RR7      ;_uu_ 4       p\        P                  ! V4      pRRR4       \        X\        4      '       d   TP                  R4      T8w  d   R# T#   + '       g   i     L@; i  \        \        3 d     R# i ; i)zYThe child's turn report, or None while absent, unreadable, or written by another process.z	utf-8-sig)ÚencodingNr3   )ÚopenÚjsonÚloadÚOSErrorÚ
ValueErrorÚ
isinstanceÚdictr   )r.   r3   Úfhr8   s   &&  r   Úread_turn_reportrE   G   sn   € ðÜ�$ ×-Õ-°Ü—Y’Y˜r“]ˆF÷ .ô �fœd×#Ò# v§z¡z°%Ó'8¸CÔ'?ÙØ€M÷ .×-ûä”ZÐ ô Úðús-   ‚A9 —A&®A9 Á&A6	Á1A9 Á6A9 Á9BÂBg       @Ú
exit_graceÚcwdr<   c               ó8   € V ^8„  d   QhRRRRRRRRR	R
RRRRRR/# )r   ÚargvÚlistÚenvr$   Úreport_pathr0   ÚtimeoutÚfloatrF   úfloat | NonerG   r%   r<   r
   zsubprocess.CompletedProcessr   )r   s   "r   r   r   Y   s_   € ÷ B^ñ B^˜Dð B^Ð*Bð B^ÐQTð B^Ð_dð B^Ø".ðB^ØXbðB^à *ðB^à6QñB^r   c               ó”  aa€ ^ RI Hp Vf   \        P                  R8X  d   Rp\        P
                  ! V \        P                  \        P                  \        P                  RVR/ VC\        V/CWW! 4       R7
      o/ oR VV3R	 llp\        P                  ! VR
SP                   2RR7      p	V	P                  4        \        P                  ! 4       V,           p
Rp T	P                  Ve   Ve   TMRR7       V	P!                  4       '       gD   \        P"                  ! V SP$                  SP'                  RR4      SP'                  RR4      4      # Ve   Ve   M”\)        VSP                  4      ;'       g    Tp\        P                  ! 4       V
8¼  g   K»  Ve   MSSP+                  4        V	P                  RR7       \)        VSP                  4      pVe   M\        P,                  ! W4      h\        P"                  ! T \/        VR,          4      VP'                  R4      ;'       g    RVP'                  R4      ;'       g    R4      # )uå  Run one ``hermes chat -Q`` delivery child; *timeout* bounds the TURN, not the process.

The child records its turn at *report_path* (``write_turn_report``) the moment the turn ends,
then runs the one-shot exit linger for nested ``notify_on_complete`` replies â€” bounded by
``terminal.oneshot_completion_wait_seconds``, whose default equals the delivery caps, so
waiting for process exit booked every delivered turn that left a reply pending as a timeout
and killed the linger (#113608, #114980). A child that exits is booked from its real exit
code and streams. A child still lingering once its report exists is booked from the report
and left running (a daemon thread drains and reaps it): after *exit_grace* seconds for a
spawner that needs only the outcome, or at the cap when *exit_grace* is None, for a spawner
that relays the printed answer â€” a teammate's reply during the linger may still become it.
Only a turn that never ends is killed, as ``subprocess.TimeoutExpired``.

*cwd* pins the child's directory (a spawner sitting in a reaped scratch workspace must not
hand its dead cwd on â€” the child dies at CLI startup, #102941). The pipes decode lossily
everywhere: a stray non-UTF-8 byte (a grandchild sharing the pipe interleaving a partial
multi-byte write) must not raise in the drain thread and take the reply and the failure tail
with it (#105582). Without an explicit *encoding* they decode as UTF-8 only on win32, where
the child is guaranteed UTF-8 (hermes_bootstrap reconfigures its streams even under
PYTHONIOENCODING=cp1252) while the gateway parent is not started in UTF-8 mode, so the
locale default mangled or lost accented replies (#115894); on POSIX the child keeps the
locale codec, so the locale default stays correct there (#66566).
)Úwindows_hide_flagsNÚwin32zutf-8TÚreplace)	ÚstdinÚstdoutr   Útextr<   ÚerrorsrK   rG   Úcreationflagsc               ó   € V ^8„  d   QhRR/# )r   r
   r   r   )r   s   "r   r   Ú'run_reported_turn.<locals>.__annotate__}   s   € ÷ <ñ <�Dñ <r   c                 ó:   <€ S P                  4       w  SR &   SR&   R# )ÚoutÚerrN)Úcommunicate)ÚprocÚstreamss   €€r   Ú_drainÚ!run_reported_turn.<locals>._drain}   s   ø€ Ø)-×)9Ñ)9Ó);Ñ&ˆ�‰˜ ›r   zquiet-turn-drain-)ÚtargetÚnameÚdaemong      Ð?©rM   r\   r+   r]   g      @r/   r,   r*   )Úhermes_cli._subprocess_compatrQ   r   ÚplatformÚ
subprocessÚPopenÚDEVNULLÚPIPEr(   Ú	threadingÚThreadr3   ÚstartÚtimeÚ	monotonicÚjoinÚis_aliveÚCompletedProcessÚ
returncoder   rE   ÚkillÚTimeoutExpiredr	   )rI   rK   rL   rM   rF   rG   r<   rQ   ra   ÚdrainÚdeadlineÚreportr_   r`   s   &$$$$$$     @@r   Úrun_reported_turnr{   Y   sé  ù€ õ4 AàÒœCŸL™L¨GÔ3ØˆÜ×ÒØ”J×&Ñ&¬z¯©ÄzÇÁÐ]aØ )Ð1[°CÐ1[Ô9MÈ{Ñ1[ØÐ1Ó3ô5€Dð €G÷<ñ <ô ×Ò FÐ3DÀTÇXÁXÀJÐ1OÐX\Ô]€EØ	‡K�K„MÜ�~Š~Ó 'Õ)€HØ€FØ
Ø�
‰
¨Ò);À
Ò@V™:Ð\`ˆ
ÔaØ�~‰~×ÒÜ×.Ò.¨t°T·_±_ÀgÇkÁkÐRWÐY[ÓF\Ð^e×^iÑ^iÐjoÐqsÓ^tÓuÐuØÒ *Ò"8Øä! +¨t¯x©xÓ8×BÐB¸FˆÜ�>Š>Ó˜xÖ'ØÒ!ØØ�I‰IŒKØ�J‰J˜sˆJÔ#ô
 & k°4·8±8Ó<ˆFØÒ!ØÜ×+Ò+¨DÓ:Ð:ä×&Ò&ØŒc�&˜Õ%Ó&¨¯
©
°7Ó(;×(AÐ(A¸rÀ6Ç:Á:ÈgÓCV×C\ÐC\ÐZ\ó^ð ^r   c               ó   € V ^8„  d   QhRR/# )r   Ú
session_idr0   r   )r   s   "r   r   r   Ÿ   s   € ÷ )ñ ) sñ )r   c              #  óv   "  € ^ RI HpHp T! T ;'       g    R4      p Rx € V! V4       R#   T! T4       i ; i5i)zWBind the approval/session key to *this* quiet session for the enclosing ``with`` block.)Úreset_current_session_keyÚset_current_session_keyÚdefaultN)Útools.approval_contextr   r€   )r}   r   r€   Útokens   &   r   Úbind_quiet_session_keyr„   ž   s6   é € ÷ Zá# J×$;Ð$;°)Ó<€Eð)Ûá! %Ö(øÑ! %Õ(üs   ‚9ž, ¢
9¬
6¶9c               ó   € V ^8„  d   QhRR/# )r   r
   Úboolr   )r   s   "r   r   r   ª   s   € ÷ 4ñ 4¨4ñ 4r   c                óÊ   a€ ^ RI Ho ^ RIHp V '       dA   \        ;QJ d    V3R lV  4       F  '       d   K   RM	  RM! V3R lV  4       4      '       g   R# V! R4      '       * # )z\True when every drained event is an automatic diagnostic AND the CLI policy suppresses them.)Údiagnostic_process_event)Úwarning_notifications_enabledc              3  ód   <"  € T F%  p\        V\        4      '       g   K  S! V4      x € K'  	  R # 5i)N)rB   rC   )Ú.0Úerˆ   s   & €r   Ú	<genexpr>Ú._diagnostic_only_wake_muted.<locals>.<genexpr>¯   s(   øé € Ð`Á&¸QÌJÐWXÔZ^×L_Ô8Ñ5°a×8Ð8Ã&ùs   ƒ0 0FTÚcli)Úagent.notification_presentationrˆ   Úgateway.warning_notificationsr‰   Úall)Úeventsr‰   rˆ   s   & @r   Ú_diagnostic_only_wake_mutedr”   ª   s=   ø€ åHÝKçŸ›Ô`Á&Ó`ŸŸšÔ`Á&Ó`×`Ò`ÙÙ,¨UÓ3Ô3Ð3r   c               ó   € V ^8„  d   QhRR/# )r   r
   rN   r   )r   s   "r   r   r   ´   s   € ÷ 	>ñ 	> Uñ 	>r   c                 ó.   € ^ RI Hp  V P                  4       # )ab  Total linger budget for one quiet run: the shared ``terminal.oneshot_completion_wait_seconds``.

One budget covers the drain loop here AND the later ``_wait_for_oneshot_background_completions``
pass, so a stuck ``notify_on_complete`` child cannot stack round-after-round waits on top of the
finalize re-wait (pre-fix worst case: 8 rounds x 600s + 600s).
©ÚProcessRegistry)Útools.process_registryr˜   Ú _oneshot_completion_wait_secondsr—   s    r   Úquiet_notify_linger_secondsr›   ´   s   € õ 7à×;Ñ;Ó=Ð=r   Ú
owns_eventÚ
max_roundsÚlinger_budgetc          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   r}   r0   Úrun_turnzCallable[[str], Any]r�   r	   rž   rO   r
   r   r   )r   s   "r   r   r   À   s:   € ÷ 5ñ 5Øð5à"ð5ð
 ð5ð  ð5ð 	ñ5r   c          	     ó  € ^ RI Hp ^ RIHpHp RpT ;'       g    Rp	Vf   \        4       p\        P                  ! 4       \        \        V4      R4      ,           p
\        V4       EF  pVP                  R\        V
\        P                  ! 4       ,
          R4      R7      p. pVP                  W’R7       F/  w  rïV! VR4      pVf   K  V! VV4       VP                  Wï34       K1  	  V UUu. uF  w  pqÿ'       g   K  VNK  	  pppV'       dI   V! R	P                  V4      4      p\        V UUu. uF  w  rïV'       g   K  VNK  	  upp4      '       g   TpVP!                  R
4      '       d    V# V'       d   EK  Vu # 	  V# u uppi u uppi )uÝ  Linger for ``notify_on_complete`` work, then run owned completion texts as follow-up turns.

Returns the last ``run_turn`` result, or ``None`` when nothing owned completed. The whole
loop shares ONE linger budget (default: ``terminal.oneshot_completion_wait_seconds``) â€” a
process that times out is waited on no further this run: after the current round's drained
texts run, the loop stops (the finalize linger still covers it once, bounded, via the
budget handshake below).
)Úprocess_registry)Úclaim_event_deliveryÚcomplete_event_deliveryNr+   g        rf   )Úsession_keyrœ   z	cli-quietz

Ú	timed_out)r™   r¢   Útools.async_delegationr£   r¤   r›   rp   rq   ÚmaxrN   ÚrangeÚwait_for_pending_completionsÚdrain_notificationsÚappendrr   r”   r   )r}   r    rœ   r�   rž   r¢   r£   r¤   ÚlastÚkeyry   Ú_ÚwaitÚdrainedÚeventrV   ÚclaimÚ_eventÚtextsÚfollows   &&$$$               r   Ú!continue_quiet_notify_completionsr·   À   sc  € õ  8ßTà€DØ
×
Ð
˜€CØÒÜ3Ó5ˆÜ�~Š~Ó¤#¤e¨MÓ&:¸CÓ"@Õ@€HÜ�:×ˆØ×<Ñ<¸TÌ3ÈxÔZ^×ZhÒZhÓZjÕOjÐloÓKpÐ<ÓqˆØˆØ+×?Ñ?ÈCÐ?Ög‰KˆEñ
 )¨°Ó<ˆEØŠ}ÙÙ# E¨5Ô1Ø�N‰N˜E˜=Ö)ñ hñ +2Ô:©'™,˜& $³T—�©'ˆÑ:ßÙ˜fŸk™k¨%Ó0Ó1ˆFô /ÉÔ/YÉ¹+¸%ÔTX·°ÉÒ/Y×ZÒZØ�Ø�8‰8�K× Ò Øð €K÷ ŠuØŠKñ9 ð: €Kùó ;ùó 0Zs   Ã,FÃ=FÄ/F	Å F	)Ú__doc__Ú
__future__r   r   r>   r   ri   r   rm   rp   Útypingr   r   r   Ú_MAX_QUIET_NOTIFY_ROUNDSr   r!   r(   r   r)   r9   rE   Ú REPORTED_TURN_EXIT_GRACE_SECONDSr{   Úcontextmanagerr„   r”   r›   r·   r   r   r   Ú<module>r¾      sì   ðñõ #ã Û Û 	Û Û 
Û Û ß 0Ñ 0ð Ð ð 8Ð õð  7Ð ð ?A¿j¹j÷ ;ð
AÈð AÐY[÷ Aõ	ð $'Ð  ðB^Ø1QðB^ØeiðB^à-1÷B^ðJ ×Ñô)ó ð)õ4õ	>ð5ð ð	5ð
 /ð5ð #'÷5ñ 5r   