+
    .pÐj•- ã                  ó^  € R t ^ RIHt ^ RIt^ RIHt ^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHt ^ RIHtHtHtHtHtH t  ]'       d   ^ RI!H"t" ^ RI#H$t$ R R lt%]PL                  ! R4      t'R R lt(R R lt)R R lt* ! R R4      t+R# )a"  Busy-session queueing, slot claims, slash dispatch tables and destructive-slash confirmation
for GatewayRunner (mixin bound via the MRO).

``gateway.run`` internals are imported lazily inside method bodies (import cycle), so
``patch("gateway.run.X")`` keeps intercepting them at call time.
)ÚannotationsN)ÚTYPE_CHECKING)ÚDEFAULT_LANGUAGEÚt)Úformat_iteration_progress)ÚPlatform)ÚEphemeralReply)ÚMessageEventÚMessageType)ÚSessionSource)Úcanonical_whatsapp_identifier)ÚAnyÚDictÚListÚOptionalÚTupleÚUnion)ÚGatewayRunner)Ú
TurnRunnerc               ó    € V ^8„  d   QhRRRR/# )é   Ú	input_keyÚstrÚreturnztuple[str, ...]© )Úformats   "Ú/opt/hermes/gateway/run_busy.pyÚ__annotate__r      s   € ÷ ñ  Cð ¨Oñ ó    c                ó   € / pRV  2p\        V\        R7      \        V4      3 F]  pW28X  d   K  VP                  R4       F=  pVP                  4       P	                  4       pV'       g   K+  VP                  VR4       K?  	  K_  	  \        V4      # )zúTyped-reply synonyms for ``approval.inputs.<input_key>`` (comma-lists): the English words
ALWAYS match, plus the active language's list, so a Polish pack can add "tak" without losing
"yes". Lower-cased, de-duplicated, order preserved (English first).zapproval.inputs.)ÚlangÚ,N)r   r   ÚsplitÚstripÚlowerÚ
setdefaultÚtuple)r   ÚseenÚkeyÚrawÚwords   &    r   Úapproval_input_wordsr+      s}   € ð €DØ˜Y˜KÐ
(€CÜ�#Ô,Ô-¬q°«vÓ6ˆØŒ:ÙØ—I‘I˜c–NˆDØ—:‘:“<×%Ñ%Ó'ˆDß‰tØ—‘  dÖ+ó #ñ 7ô �‹;Ðr   zgateway.runc               ó$   € V ^8„  d   QhRRRRRR/# )r   Útextr   Úslotr   úOptional[str]r   )r   s   "r   r   r   3   s!   € ÷ 
ñ 
�cð 
 ð 
¨ñ 
r   c                ó|   € W8X  d   R# V P                  VR,           4      '       d   V \        V4      ^,           R # R# )a(  Remainder after ``slot`` when ``text`` starts with it as a WHOLE slot, else None.

The ``:``-delimited slot layout is ``build_session_key``'s: an id that merely starts with another
must never match, so a whole-slot comparison is what every caller here uses. A text that IS the
slot yields ``""``.Ú Ú:N)Ú
startswithÚlen)r-   r.   s   &&r   Ú_strip_slotr5   3   s7   € ð „|ÙØ‡��t˜c•z×"Ò"Ø”C˜“I •M�NÐ#Ð#Ùr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Útailr   r.   r   Úboolr   )r   s   "r   r   r   @   s!   € ÷ /ñ /˜ð / Cð /¨Dñ /r   c                ó   € \        W4      RJ# )zbTrue when ``tail``'s FIRST slot is ``slot`` (``tail`` is ``""`` when the key ends at the
chat id).N)r5   )r7   r.   s   &&r   Ú_tail_has_slotr:   @   s   € ô �tÓ"¨$Ð.Ð.r   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r(   r   ÚprefixÚchat_idÚscope_idr/   r   zOptional[tuple[str, str]]r   )r   s   "r   r   r   F   s4   € ÷ ñ Ø	ðØðØ'*ðØ6Cðàñr   c               óÚ   € V P                  V4      '       g   R# V \        V4      R P                  R4      w  rEpV'       d
   V RV 2V3MV3pV F  p\        Wh4      p	V	f   K  WI3u # 	  R# )u  ``(chat_type, tail)`` when ``key`` names the SAME chat as ``prefix`` + ``chat_id``, else None.

``prefix`` is the key's fixed-shape head, ``agent:<profile>:<platform>:``. Everything after it is
matched as TEXT, because ids may themselves contain ``:`` (Matrix ``!room:example.org``).
``scope_id`` is Slack's workspace slot â€” ``build_session_key`` emits it there alone â€” and a key
without it still names the same chat; a key carrying a DIFFERENT known scope is another
workspace's chat. ``tail`` is ``""`` when the key ends at the chat id.
Nr2   )r3   r4   Ú	partitionr5   )
r(   r<   r=   r>   Ú	chat_typeÚ_ÚremÚ
candidatesÚ	candidater7   s
   &$$$      r   Ú_same_chat_key_slotsrF   F   sx   € ð �>‰>˜&×!Ò!ÙØœC ›K˜LÐ)×3Ñ3°CÓ8Ñ€I�#ß7?�X�J˜a ˜yÐ)¨7Ñ3ÀgÀZ€JÛˆ	Ü˜3Ó*ˆØÔØ�?Ò"ñ  ñ r   c                  óê  € ] tR t^\t$ RtR�R R lltR R ltR R ltR	 R
 ltRR/R R llt	R R lt
]R R l4       tR R ltR R ltR R ltR R ltR R lt]R R l4       t]R R l4       tR  R! ltR" R# lt]R$ R% l4       tR‘tR& R' ltR( R) ltR* R+ lt]R, R- l4       tR.R//R0 R1 lltR2 R3 ltR4R’R5R“/tR6]R7&   R”t R8]R9&   R: R; lt!R< R= lt"R> R? lt#]R@ RA l4       t$RBR/RC RD llt%RE RF lt&RG RH lt'RI RJ lt(RK RL lt)]*RM RN l4       t+RO RP lt,RQ RR lt-RS RT lt.RURVRWRX/t/R•t0R–t1RY RZ lt2R[ t3R\ R] lt4R^ t5R— U u/ uF	  q R_V  R`2bK  	  up t6Ra]Rb&   Rc Rd lt7Re Rf lt8Rg Rh lt9Ri Rj lt:Rk Rl lt;Rm Rn lt<Ro Rp lt=Rq Rr lt>Rs Rt lt?Ru Rv lt@Rw Rx ltARy Rz ltBR{ R| ltCR} R~ ltDR R€ ltER� R‚ ltFRƒ R„ ltGR… R† ltH]R‡ Rˆ l4       tI]R‰ RŠ l4       tJR‹ RŒ ltKR� RŽ ltLR�tMR# u up i )˜ÚGatewayBusySessionMixinzZBusy-session queueing, slot claims, slash dispatch tables, destructive-slash confirmation.Nc               ó    € V ^8„  d   QhRRRR/# )r   Úbusy_input_moder/   r   r8   r   )r   s   "r   r   Ú$GatewayBusySessionMixin.__annotate___   s   € ÷ Fñ F¸=ð FÐTXñ Fr   c                	ó`   € T;'       g    V P                   pV P                  ;'       d    VR9   # )Úqueue>   rM   Ústeer)Ú_busy_input_modeÚ_restart_requested)ÚselfrJ   Úmodes   && r   Ú_queue_during_drain_enabledÚ3GatewayBusySessionMixin._queue_during_drain_enabled_   s/   € à×7Ð7 $×"7Ñ"7ˆØ×&Ñ&×EÐE¨4Ð3EÑ+EÐEr   c               ó   € V ^8„  d   QhRR/# ©r   Úsession_keyr   r   )r   s   "r   r   rK   d   s   € ÷ Cñ C¨3ñ Cr   c                ód   € V P                  V4      pV'       d   VP                  P                  # R# )zKThe session's FIFO overflow list, or None when no session state exists yet.N)Ú_peek_session_stateÚconversationÚqueued_events)rQ   rW   Ústates   && r   Ú_overflow_queueÚ'GatewayBusySessionMixin._overflow_queued   s+   € à×(Ñ(¨Ó5ˆß38ˆu×!Ñ!×/Ñ/ÐB¸dÐBr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   rW   r   Úqueued_eventr	   Úadapterr   r   ÚNoner   )r   s   "r   r   rK   i   s*   € ÷ 	.ñ 	.¨ð 	.¸Lð 	.ÐSVð 	.Ð[_ñ 	.r   c                óÄ   € Ve   \        VRR4      MRpVf   R# W9   d6   V P                  V4      P                  P                  P	                  V4       MW$V&   RVn        R# )z6Append a /queue event to the FIFO chain for a session.NÚ_pending_messagesT)ÚgetattrÚ_session_staterZ   r[   ÚappendÚ_gateway_accepted)rQ   rW   r`   ra   Úpending_slots   &&&& r   Ú_enqueue_fifoÚ%GatewayBusySessionMixin._enqueue_fifoi   s]   € àFMÒFY”w˜wÐ(;¸TÔBÐ_cˆØÒÙØÔ&Ø×Ñ Ó,×9Ñ9×GÑG×NÑNÈ|Õ\à(4˜Ñ%Ø)-ˆÖ&r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   rW   r   ra   r   Úpending_eventúOptional[MessageEvent]r   r   )r   s   "r   r   rK   t   s,   € ÷ ñ ØðØ),ðØ=Sðà	ñr   c                óÎ   € V P                  V4      pV'       g   V# Vf   VP                  ^ 4      # Ve1   \        VR4      '       d   VP                  ^ 4      VP                  V&   V# )uñ   Promote the next overflow item after the slot drained.

``pending_event`` None â†’ the overflow head becomes the pending event; otherwise the head is
staged into the slot for the NEXT recursion. Returns the (possibly updated) pending_event.
rd   )r]   ÚpopÚhasattrrd   )rQ   rW   ra   rm   Úoverflows   &&&& r   Ú_promote_queued_eventÚ-GatewayBusySessionMixin._promote_queued_eventt   sb   € ð ×'Ñ'¨Ó4ˆßØ Ð ØÒ Ø—<‘< “?Ð"ØÒ¤7¨7Ð4G×#HÒ#HØ5=·\±\À!³_ˆG×%Ñ% kÑ2àÐr   ra   c               ó$   € V ^8„  d   QhRRRRRR/# ©r   rW   r   ra   r   r   Úintr   )r   s   "r   r   rK   †   s!   € ÷ ñ ¨ð ¸ð Èñ r   c               óŒ   € \        V P                  V4      ;'       g    R4      pVe   V\        VR/ 4      9   d
   V^,          pV# )u=   Total pending /queue items for a session â€” slot + overflow.rd   r   )r4   r]   re   )rQ   rW   ra   Údepths   &&$ r   Ú_queue_depthÚ$GatewayBusySessionMixin._queue_depth†   sE   € ä�D×(Ñ(¨Ó5×;Ð;¸Ó<ˆØÒ ;´'¸'ÐCVÐXZÓ2[Ô#[Ø�Q�JˆEØˆr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rW   r   ra   r   r   rn   r   )r   s   "r   r   rK   �   s"   € ÷ $ñ $°Sð $À3ð $ÐKañ $r   c                óÞ  €  V P                  V4      pV'       g   R# \        VRR4      p\        V\        4      '       d   VP	                  V4      '       d   R# VP                  ^ 4      pV'       d   VP                  ^ 4      WA&   \        P                  RV4       V'       d!   \        P                  R\        V4      V4       V#   \         d    \        P                  RTRR7        R# i ; i)a+  Pop the oldest orphaned FIFO overflow event for an idle session (None if nothing to rescue).

``queued_events`` drains only at the post-turn promotion site; a busy window ending without
it (early exit, exception/interrupt/generation-bump) orphans the overflow. On a NEW event for
a NON-busy session the oldest orphan runs as THIS turn, the next is staged into the slot so
arrival order holds, and the caller enqueues the incoming event behind it. The returned
event is REMOVED from both stores, else the post-turn dequeue would run it twice.

See #28503.
Nrd   u’   Rescued orphaned FIFO overflow event for idle session %s â€” it was queued during a busy window but the post-turn drain never promoted it (#99882)zg%d overflow event(s) still queued for session %s after rescue staging (will drain via normal promotion)z"FIFO overflow rescue failed for %sT©Úexc_info)r]   re   Ú
isinstanceÚdictÚgetrp   ÚloggerÚwarningr4   Ú	ExceptionÚdebug)rQ   rW   ra   rr   ri   Úheads   &&&   r   Ú_rescue_orphaned_overflowÚ1GatewayBusySessionMixin._rescue_orphaned_overflow�   sÐ   € ð	Ø×+Ñ+¨KÓ8ˆHßÙÜ" 7Ð,?ÀÓFˆLÜ˜l¬D×1Ò1°\×5EÑ5EÀk×5RÒ5RÙØ—<‘< “?ˆD÷ Ø,4¯L©L¸«O�Ñ)Ü�N‰Nð3à4?ô÷
 Ü—‘ðGÜHKÈHËÐWbôð ˆKøÜô 	Ü�L‰LÐ=¸{ÐUYˆLÔZÚð	ús(   ‚C �9C ÁC Á20C Â#!C Ã#C,Ã+C,c               ó    € V ^8„  d   QhRRRR/# )r   Úevent_or_textr   r   r8   r   )r   s   "r   r   rK   ´   s   € ÷ Uñ U°3ð U¸4ñ Ur   c                ód   € \        V RV 4      ;'       g    Rp\        V4      P                  R4      # )zYTrue for synthetic /goal continuation turns (so pause/clear can spare real /queue items).r-   r1   z,[Continuing toward your standing goal]
Goal:)re   r   r3   )r‹   r-   s   & r   Ú_is_goal_continuation_eventÚ3GatewayBusySessionMixin._is_goal_continuation_event³   s0   € ô �} f¨mÓ<×BÐBÀˆÜ�4‹y×#Ñ#Ð$SÓTÐTr   c               ó$   € V ^8„  d   QhRRRRRR/# rv   r   )r   s   "r   r   rK   ¹   s"   € ÷ ñ ¸Sð È3ð ÐSVñ r   c                óò  € ^ pVe   \        VRR4      MRp\        V\        4      '       dD   VP                  V4      pV P	                  V4      '       d   VP                  VR4       V^,          pV P                  V4      pV'       dk   V Uu. uF  qpP	                  V4      '       d   K  VNK  	  ppV\        V4      \        V4      ,
          ,          pW€P                  V4      P                  n
        V# u upi )zXRemove queued synthetic /goal continuations for one session; real /queue items are kept.Nrd   )re   r€   r�   r‚   r�   rp   r]   r4   rY   rZ   r[   )	rQ   rW   ra   Úremovedri   rm   rr   ÚeÚkepts	   &&&      r   Ú!_clear_goal_pending_continuationsÚ9GatewayBusySessionMixin._clear_goal_pending_continuations¹   sÓ   € àˆØFMÒFY”w˜wÐ(;¸TÔBÐ_cˆÜ�l¤D×)Ò)Ø(×,Ñ,¨[Ó9ˆMØ×/Ñ/°×>Ò>Ø× Ñ  ¨dÔ3Ø˜1•�à×'Ñ'¨Ó4ˆßÙ'ÓS™x˜!×/OÑ/OÐPQ×/R—A�A™xˆDÐSØ”s˜8“}¤s¨4£yÕ0Õ0ˆGØOS×$Ñ$ [Ó1×>Ñ>ÔLØˆùò Ts   ÂC4Â)C4c               ó    € V ^8„  d   QhRRRR/# )r   Ú
session_idr   r   r8   r   )r   s   "r   r   rK   Ê   s   € ÷ 	ñ 	¸ð 	Àñ 	r   c                ó°   € V'       g   R#  ^ RI Hp V! VR7      P                  4       #   \         d"   p\        P                  RT4        Rp?R# Rp?ii ; i)z@Best-effort fresh DB check before running a queued continuation.F)ÚGoalManager)r—   z2goal continuation: active-state recheck failed: %sN)Úhermes_cli.goalsr™   Ú	is_activer…   rƒ   r†   )rQ   r—   r™   Úexcs   &&  r   Ú_goal_still_active_for_sessionÚ6GatewayBusySessionMixin._goal_still_active_for_sessionÊ   sF   € çÙð	Ý4Ù¨*Ô5×?Ñ?ÓAÐAøÜô 	Ü�L‰LÐMÈsÔSÝûð	ús   Œ) ©A´AÁAc               ó   € V ^8„  d   QhRR/# )r   r   zOptional[int]r   )r   s   "r   r   rK   Õ   s   € ÷ ñ ¨mñ r   c                óZ   €  ^ RI Hp V! \        V RR4      4      #   \         d     R# i ; i)z:Return the configured active chat session cap, if enabled.)Úresolve_max_concurrent_sessionsÚconfigN)Úhermes_cli.active_sessionsr¡   re   r…   )rQ   r¡   s   & r   Ú_get_max_concurrent_sessionsÚ4GatewayBusySessionMixin._get_max_concurrent_sessionsÕ   s0   € ð	ÝRÙ2´7¸4ÀÈ4Ó3PÓQÐQøÜô 	Úð	ús   ‚ ›*©*c               ó    € V ^8„  d   QhRRRR/# )r   rW   r   r   r/   r   )r   s   "r   r   rK   Ý   s   € ÷ 	Hñ 	H¸ð 	HÀñ 	Hr   c                ó¨   € V P                  4       pVe   V P                  V4      '       d   R# V P                  4       pW28  d   R# ^ RIHp V! W24      # )zKReturn a user-facing rejection when starting a new session exceeds the cap.N)Úactive_session_limit_message)r¤   Ú_is_session_runningÚ_running_agent_countr£   r¨   )rQ   rW   Úmax_sessionsÚactive_countr¨   s   &&   r   Ú_active_session_limit_messageÚ5GatewayBusySessionMixin._active_session_limit_messageÝ   sN   € à×8Ñ8Ó:ˆØÒ 4×#;Ñ#;¸K×#HÒ#HÙØ×0Ñ0Ó2ˆØÔ&ÙÝKÙ+¨LÓGÐGr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rW   r   Úsourcer   r   ztuple[Any, Optional[str]]r   )r   s   "r   r   rK   è   s$   € ÷ ñ ØðØ(5ðà	"ñr   c                óâ  € V P                  V4      '       d   R# V P                  V4      pVe   RV3#  ^ RIHp V'       d)   VP                  '       d   VP                  P
                  MRpT! TRV 2\        V RR4      RTR\        VRR4      ;'       g    RR	\        VR	R4      ;'       g    RR
\        V4      /R7      #   \         d#   p\        P                  RT4       Ru Rp?# Rp?ii ; i)zAClaim a cross-process active-session slot for a new gateway turn.N)Útry_acquire_active_sessionÚgatewayzgateway:r¢   Úplatformr=   r1   Úuser_idÚlive_session_id)r—   Úsurfacer¢   Úmetadataz'Failed to claim active session slot: %s)NN)r©   r­   r£   r²   r´   Úvaluere   r   r…   rƒ   r„   )rQ   rW   r°   Úlimit_messager²   r´   rœ   s   &&&    r   Ú_claim_active_session_slotÚ2GatewayBusySessionMixin._claim_active_session_slotè   sï   € ð ×#Ñ# K×0Ò0ØÐØ×:Ñ:¸;ÓGˆØÒ$Ø˜Ð&Ð&ð	ÝMß06¸6¿?¿?¸?�v—‘×,Ò,ÐPYˆHÙ-Ø&Ø" 8 *Ð-Ü˜t X¨tÓ4à Øœw v¨y¸"Ó=×CÐCÀØœw v¨y¸"Ó=×CÐCÀð &¤s¨;Ó'7ðô	ð øô" ô 	Ü�N‰NÐDÀcÔJØÕûð	ús6   ´C ÁC ÁAC ÂC Â-C ÃC.ÃC)Ã#C.Ã)C.c               ó    € V ^8„  d   QhRRRR/# )r   Úrunning_agentr   r   r8   r   )r   s   "r   r   rK   
  s   € ÷ ñ °3ð ¸4ñ r   c                ón  € ^ RI Hp V e   WJ d   R# \        V RR4      p\        V\        \
        \        34      '       d	   V'       g   R# \        V RR4      p Ve   TM\        P                  ! 4       ;_uu_ 4        \        V4      uuRRR4       #   + '       g   i     R# ; i  \         d     R# i ; i)u®   True when *running_agent* is driving subagents (callers demote interrupt â†’ queue;
``interrupt()`` would cascade through ``_active_children``). Fail-safe False on any error.©Ú_AGENT_PENDING_SENTINELNFÚ_active_childrenÚ_active_children_lock)Úgateway.runrÁ   re   r€   Úlistr&   ÚsetÚ
contextlibÚnullcontextr8   r…   )r¾   rÁ   ÚchildrenÚlocks   &   r   Ú_agent_has_active_subagentsÚ3GatewayBusySessionMixin._agent_has_active_subagents	  s’   € õ 	8ØÒ  MÓ$LÙÜ˜=Ð*<¸dÓCˆä˜(¤T¬5´#Ð$6×7Ò7¿xÙÜ�}Ð&=¸tÓDˆð	ØÒ)‘¬z×/EÒ/EÓ/G×GÑGÜ˜H“~÷ H×G×GÓGûäô 	Úð	ús0   Á#B% Á;BÂ
B% ÂB"	ÂB% Â"B% Â%B4Â3B4c               ó$   € V ^8„  d   QhRRRRRR/# )r   r¾   r   r-   r   r   rw   r   )r   s   "r   r   rK     s!   € ÷ ñ ¨sð ¸#ð À#ñ r   c           
     óH  € \        V RR4      p\        V\        \        \        34      '       d	   V'       g   ^ # \        V RR4      p Ve   TM\
        P                  ! 4       ;_uu_ 4        \        V4      pRRR4       ^ pX F<  p\        TRR4      p\        T4      '       g   K#   T\        T! T4      4      ,          pK>  	  T#   + '       g   i     LV; i  \         d     ^ # i ; i  \         d.   p\        P                  R\        TRT4      T4        Rp?Kš  Rp?ii ; i)u­  Queue *text* into every live child of *running_agent*; returns how many accepted it.

A parent blocked inside ``delegate_task`` only drains its own steer queue after the tool
returns, i.e. after the child finishes â€” so a steer aimed at a looping child would sit
unread for the whole delegation (#112095, Telegram). Children are the parent's own
``_active_children`` (identity-scoped, same snapshot ``interrupt()`` fans out to).rÂ   NrÃ   rN   z!Steer into subagent %r failed: %sÚ_delegate_id)re   r€   rÅ   r&   rÆ   rÇ   rÈ   r…   Úcallabler8   rƒ   r„   )	r¾   r-   rÉ   rÊ   ÚsnapshotÚacceptedÚchildrN   rœ   s	   &&       r   Ú_steer_active_subagentsÚ/GatewayBusySessionMixin._steer_active_subagents  s  € ô ˜=Ð*<¸dÓCˆÜ˜(¤T¬5´#Ð$6×7Ò7¿xÙÜ�}Ð&=¸tÓDˆð	ØÒ)‘¬z×/EÒ/EÓ/G×GÑGÜ ›>�÷ Hð ˆÛˆEÜ˜E 7¨DÓ1ˆEÜ˜E—?’?ÙðpØœD¡ t£Ó-Õ-’ñ ð ˆ÷ H×Gûäô 	Úð	ûô ô pÜ—‘ÐBÄGÈEÐSaÐchÓDiÐkn×oÒoûðpúsH   Á#C Á*CÁ6C Â&C)ÃC	ÃC ÃC ÃC&Ã%C&Ã)D!Ã4"DÄD!c               ó$   € V ^8„  d   QhRRRRRR/# )r   r¾   r   r-   r   r   r8   r   )r   s   "r   r   rK   7  s&   € ÷ Sñ S°#ð S¸Sð SÀTñ Sr   c                ó~   € \        VP                  V4      4      p\        V P                  W4      4      ;'       g    T# )z–``running_agent.steer(text)`` plus fan-out to its active subagents (see
:meth:`_steer_active_subagents`); True when the parent or any child queued it.)r8   rN   rÔ   )rQ   r¾   r-   rÒ   s   &&& r   Ú_steer_running_agentÚ,GatewayBusySessionMixin._steer_running_agent7  s7   € ô ˜×+Ñ+¨DÓ1Ó2ˆÜ�D×0Ñ0°ÓEÓF×RÐRÈ(ÐRr   c               ó    € V ^8„  d   QhRRRR/# )r   rW   r   r   r8   r   )r   s   "r   r   rK   =  s   € ÷ (Iñ (IÀCð (IÈDñ (Ir   c              ƒ  óX  "  € \        V RR4      pV'       d   Vf   R# R R lp \        P                  ! V P                  W!4      G Rj  x€L
 p\        T RR4      pT'       d   Tf   R# \        TRT4      p \        P                  ! TP                  \        T4      4      G Rj  x€L
 p\        T\        4      ;'       d    \        T4      #  L‚  \        \
        3 d     R# \         d    T! RT4      u # i ; i LV  \        \
        3 d     R# \         d    T! R	T4      u # i ; i5i)
uú  True when a compression lock is held for this session's id (callers demote interrupt â†’
queue, else a follow-up against the pre-rotation parent orphans compression siblings).
Both blocking reads run in a worker thread so a large state.db never freezes the loop.

Context compression is interrupt-protected (#23975) but gateway ``interrupt`` busy-input mode can
still start a follow-up turn against the pre-rotation parent while compression is mid-flight,
producing orphaned compression siblings (#56391).
Úsession_storeNFc               ó    € V ^8„  d   QhRRRR/# )r   Úwhatr   r   r8   r   )r   s   "r   r   ÚPGatewayBusySessionMixin._session_has_compression_in_flight.<locals>.__annotate__I  s   € ÷ 	ñ 	 ð 	°ñ 	r   c                ó6   € \         P                  R WRR7       R# )z�Compression in-flight check failed while reading %s %s; treating compression as active to avoid interrupting a possible parent-session rotationTr~   )rƒ   r„   )rÞ   Úidents   &&r   Ú_assume_activeÚRGatewayBusySessionMixin._session_has_compression_in_flight.<locals>._assume_activeI  s$   € Ü�N‰NðRØSWÐimð ô ñ r   ÚsessionÚ_session_dbÚ_dbzlock holder for session)re   ÚasyncioÚ	to_threadÚ#_lookup_session_id_under_store_lockÚAttributeErrorÚ	TypeErrorr…   Úget_compression_lock_holderr   r€   r8   )rQ   rW   rÜ   râ   r—   Ú
session_dbÚraw_dbÚholders   &&      r   Ú"_session_has_compression_in_flightÚ:GatewayBusySessionMixin._session_has_compression_in_flight=  s  é € ô    o°tÓ<ˆß˜mÒ3Ùõ	ð	:Ü&×0Ò0Ø×8Ñ8¸-ó ÷ ˆJô ˜T =°$Ó7ˆ
ß˜ZÒ/ÙÜ˜ U¨JÓ7ˆð		IÜ"×,Ò,¨V×-OÑ-OÔQTÐU_ÓQ`Óa×aˆFô ˜f¤cÓ*×;Ð;¬t°F«|Ð;ñ!øô ¤	Ð*ô 	ÚÜô 	:Ù! )¨[Ó9Ò9ð	:úñ bøô
 ¤	Ð*ô 	ÚÜô 	IÙ!Ð";¸ZÓHÒHð	Iüsš   ‚"D*¥$C Á	CÁ
C Á(D*Á7-C= Â$C;Â%C= Ã C= ÃD*ÃC ÃC8ÃD*Ã"C8Ã+
C8Ã5D*Ã7C8Ã8D*Ã;C= Ã=D'ÄD*ÄD'Ä
D'Ä$D*Ä&D'Ä'D*c               ó   € V ^8„  d   QhRR/# rV   r   )r   s   "r   r   rK   h  s   € ÷ Qñ QÈñ Qr   c                óÞ   € V P                   ;_uu_ 4        V P                  4        V P                  P                  V4      pRRR4       Xe   \	        VRR4      # R#   + '       g   i     L#; i)zISync helper run in the thread pool: read session_id under the store lock.Nr—   )Ú_lockÚ_ensure_loaded_lockedÚ_entriesr‚   re   )rÜ   rW   Úentrys   && r   ré   Ú;GatewayBusySessionMixin._lookup_session_id_under_store_lockg  s[   € ð × × Ó Ø×/Ñ/Ô1Ø!×*Ñ*×.Ñ.¨{Ó;ˆE÷ !ð 6;Ò5FŒw�u˜l¨DÓ1ÐPÈDÐP÷ !× ús   •,AÁA,	c               ó$   € V ^8„  d   QhRRRRRR/# )r   rW   r   Úeventr	   r   rb   r   )r   s   "r   r   rK   w  s"   € ÷ 28ñ 28¸3ð 28À|ð 28ÐX\ñ 28r   c                	óè  aa€ ^ RI Hp V P                  SP                  4      pV'       g   R# \	        VRR4      p\        V\        4      '       d   VP                  V4      MRoSRJ;'       d—    \	        SRR4      \	        SRR4      8H  ;'       dt    \	        SRR4      \	        SRR4      8H  ;'       dQ    \        ;QJ d*    VV3R lV P                   4       F  '       d   K   RM	  RM! VV3R lV P                   4       4      p\	        SR	R4      \	        SR	R4      0pV'       du   \        P                  V9   d`   V\        P                  \        P                  08:  d;   V! VP                  VSSP                  \        P                  8H  R
7       RSn        R# V P!                  WR7      V P"                  8¼  d#   \$        P'                  RWP"                  4       R# V P)                  VSV4       R# )é    )Úmerge_pending_message_eventNrd   ÚinternalFÚallow_gateway_controlTc              3  ó¾   <"  € T FR  p\        SR R4      ;'       g    / P                  V4      \        SR R4      ;'       g    / P                  V4      8H  x € KT  	  R# 5i)r¸   N)re   r‚   )Ú.0r(   rú   Úexistings   & €€r   Ú	<genexpr>ÚJGatewayBusySessionMixin._queue_or_replace_pending_event.<locals>.<genexpr>‡  s[   øé € ð ñ 8�Cô ˜ :¨tÓ4×:Ð:¸×?Ñ?ÀÓDÜ˜E :¨tÓ4×:Ð:¸×?Ñ?ÀÓDöEã7ùs   ƒAœ$AÁAÚmessage_type)Ú
merge_text©ra   uJ   Dropping busy-mode follow-up for session %s â€” pending queue at cap (%d).)Úgateway.platforms.baserý   Ú_delivery_adapter_forr°   re   r€   r�   r‚   ÚallÚ_SECURITY_METADATA_KEYSr
   ÚPHOTOÚTEXTrd   r  rh   rz   Ú_BUSY_QUEUE_MAX_PENDINGrƒ   r„   rj   )	rQ   rW   rú   rý   ra   ri   Úsame_security_contextÚmerge_typesr  s	   &&f     @r   Ú_queue_or_replace_pending_eventÚ7GatewayBusySessionMixin._queue_or_replace_pending_eventw  sÀ  ù€ ÝFØ×,Ñ,¨U¯\©\Ó:ˆßÙô ˜wÐ(;¸TÓBˆô 5?¸|ÌT×4RÒ4R�<×#Ñ# KÔ0ÐX\ˆØ (°Ð 4÷ 	!
ð 	!
Ü�H˜j¨%Ó0´G¸EÀ:ÈuÓ4UÑU÷ ð Ü˜Ð"9¸4Ó@Ü�uÐ5°tÓ<ñ=÷ð ÷ “õ ð  ×7Ò7ó——’õ ð  ×7Ò7óó ð	 	ô  �H˜n¨dÓ3Ü�E˜>¨4Ó0ð
ˆ÷
 "Ü×!Ñ! [Ô0Ø¤× 0Ñ 0´+×2CÑ2CÐDÔDá'Ø×)Ñ)¨;¸Ø ×-Ñ-´×1AÑ1AÑAõð '+ˆEÔ#Ùà×Ñ˜[ÐÓ:¸d×>ZÑ>ZÔZÜ�N‰NØ\Ø×9Ñ9ôñ à×Ñ˜;¨¨wÖ7r   c               ó    € V ^8„  d   QhRRRR/# ©r   rú   r	   r   r   r   )r   s   "r   r   rK   «  s   € ÷ Sñ S°Lð SÀSñ Sr   c              ƒ  óT  "  € VP                   ;'       g    RP                  4       pV P                  V4      '       g   V# V P                  WP	                  VP
                  4      VP
                  VRR7      G Rj  x€L
 w  r4V'       d   T;'       g    TP                  4       # T#  L*5i)a@  Steerable text for a busy follow-up, transcribing voice-message media first.

Steer bypasses the inbound STT queue, so a media-only voice follow-up would otherwise
silently degrade to queue mode. Uses the single out-of-band STT choke point, so STT runs at
most once per message; on failure the caption (if any) is kept.
r1   z
Busy-steer©Úlog_contextN)r-   r#   Ú_pending_event_audio_pathsÚ"_transcribe_and_echo_pending_voicer	  r°   )rQ   rú   r-   Úenriched_textÚsuccessful_transcriptss   &&   r   Ú_prepare_busy_steer_textÚ0GatewayBusySessionMixin._prepare_busy_steer_text«  s˜   é € ð —
‘
× Ð ˜b×'Ñ'Ó)ˆØ×.Ñ.¨u×5Ò5ØˆKØ6:×6]Ñ6]Ø×-Ñ-¨e¯l©lÓ;¸U¿\¹\È4Ð]ið 7^ó 7
÷ 1
Ñ-ˆ÷ 3I�×%Ð% ×,Ñ,Ó.ÐRÈdÐRñ1
ùs   ‚;B(¾=B(Á;B&Á<B(ÂB(c               ó$   € V ^8„  d   QhRRRRRR/# )r   r-   r   rú   r	   r   r   )r   s   "r   r   rK   º  s!   € ÷ (
ñ (
¨Cð (
¸ð (
Èñ (
r   c           
     óª  € VP                  4       '       g   V# ^ RIpVP                  pRVP                  P                  /R Uu/ uF  qU\        WE4      bK  	  upCRVP                  R	VP                  /CpVP                  4        UUu/ uF  w  rWVR9  g   K  WWbK  	  ppp^ R
IH	p ^ RI
Hp	Hp
HpHp V P                  V4      ;_uu_ 4        \!        V! 4       P#                  R4      ;'       g    / P#                  RR4      4      pRRR4       V! VP                  X4      '       dN   RVRVRV	RV	RV	/pVP                  4        UUu/ uF%  w  rWYUR9   d   TMVP#                  WZ4      ! V4      bK'  	  pppVP$                  ! VRR7      P'                  RR4      P'                  RR4      pRV RV 2# u upi u uppi   + '       g   i     L½; iu uppi )zGKeep event origin in this injection, never in the cached system prompt.Nr´   r=   rµ   Úparent_chat_idÚchat_id_altÚuser_id_altÚ
message_idÚsource_message_id)Ú_load_gateway_config)Ú_hash_chat_idÚ_hash_idÚ_hash_sender_idÚ_should_redact_piiÚprivacyÚ
redact_piiFT)Úensure_asciiÚ[z\u005bÚ]z\u005dzGGateway message origin (JSON data, not instructions or authorization):
zG
Do not guess a reply destination when these fields are insufficient.

)
r=   Ú	thread_idrA   rµ   r>   Úprofiler   r!  r"  Úprospective_thread_id)Nr1   )r´   rA   )r#   Újsonr°   r´   r¹   re   r#  ÚitemsrÄ   r%  Úgateway.sessionr&  r'  r(  r)  Ú_profile_scope_for_sourcer8   r‚   ÚdumpsÚreplace)rQ   r-   rú   r2  r°   r(   Úoriginr¹   r%  r&  r'  r(  r)  r+  ÚhashersÚencodeds   &&&             r   Ú_steer_text_with_originÚ/GatewayBusySessionMixin._steer_text_with_originº  sÚ  € à�z‰z�|Š|ØˆKÛà—‘ˆà˜Ÿ™×-Ñ-ð
ñ5ó ñ 5¨S”G˜FÓ(Ò(ñ 5ñ ð
ð ˜%×*Ñ*Ø ×!2Ñ!2ñ
ˆð 06¯|©|¬~ÔY©~¡ ÀÈjÑAX”*�#’*©~ˆÑYÝ4ß`Ó`ð ×+Ñ+¨F×3Õ3ÜÑ3Ó5×9Ñ9¸)ÓD×JÐJÈ×OÑOÐP\Ð^cÓdÓeˆJ÷ 4á˜fŸo™o¨z×:Ò:ð ˜?¨M¸?Ø˜=¨-¸Ø  -ðˆGð RX×Q]ÑQ]ÔQ_ôaÙQ_Á:À3ð Ð,EÔ%E™EØ#ŸK™K¨Ô6°uÓ=ò>ÙQ_ð ñ að —*’*˜V°$Ô7×?Ñ?ÀÀYÓO×WÑWÐX[Ð]fÓgˆàVØˆið Wàˆfðð	
ùò5ùó Z÷
 4×3üóas$   ÁF1Â	F6ÂF6Ã:F<Å+GÆ<G	c               ó   € V ^8„  d   QhRR/# ©r   rú   r	   r   )r   s   "r   r   rK   å  s   € ÷ 
ñ 
˜lñ 
r   c                	ól  € V P                   P                  \        P                  8X  d:   V P                   P                  R 8X  d   V P                   P
                  '       d   V# V P                   P                  \        P                  8X  d   V P                   P
                  '       d   R# V P                  # )ÚdmN)r°   r´   r   ÚTELEGRAMrA   r/  r#  )rú   Úreply_anchors   &&r   Ú_busy_reply_toÚ&GatewayBusySessionMixin._busy_reply_toä  sŠ   € ð
 �|‰|×$Ñ$¬×(9Ñ(9Ô9Ø—‘×&Ñ&¨$Ô.Ø—‘×&×&Ð&ð ð	
ð
  Ÿ,™,×/Ñ/´8×3DÑ3DÔDÈÏÉ×I_×I_ÐI_�$ð	
ð
 fk×euÑeuð	
r   Úplain_anchorFc               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   rú   r	   Úcontentr   rE  r8   r   rb   r   )r   s   "r   r   rK   ï  s*   € ÷ 
ñ 
¨Lð 
ÈCð 
Ðbfð 
Ðswñ 
r   c          	   ƒ  óü   "  € V P                  V4      pTP                  VP                  P                  TV'       d   TMV P	                  W4      V P                  VP                  V4      R7      G Rj  x€L
  R#  L5i)zHSend a busy-path reply anchored to the event (thread metadata included).)r=   rG  Úreply_tor¸   N)Ú_reply_anchor_for_eventÚ_send_with_retryr°   r=   rC  Ú_thread_metadata_for_source)rQ   rú   ra   rG  rE  rB  s   &&&&$ r   Ú_send_busy_replyÚ(GatewayBusySessionMixin._send_busy_replyï  sg   é € à×3Ñ3°EÓ:ˆØ×&Ñ&Ø—L‘L×(Ñ(°'ß%1‘\°t×7JÑ7JÈ5Ó7_Ø×5Ñ5°e·l±lÀLÓQð 'ó 
÷ 	
ô 	
ùs   ‚A1A<Á3A:Á4A<c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   rú   r	   rW   r   Úeffective_moder   rb   r   )r   s   "r   r   rK   ø  s*   € ÷ 
=ñ 
=°<ð 
=Ècð 
=Ðcfð 
=Ðkoñ 
=r   c              ƒ  óN  "  € V P                  VP                  4      pV'       g   R# V P                  V4      '       d.   V P                  W!4       \	        RV P                  4       R7      pM\	        RV P                  4       R7      pV P                  WV4      G Rj  x€L
  R#  L5i)zYBusy path while the gateway is restarting/stopping: queue (if allowed) and tell the user.Nzgateway.busy.drain_queued)Úactionzgateway.busy.drain_rejected)r	  r°   rS   r  r   Ú_status_action_gerundrM  )rQ   rú   rW   rP  ra   Úmessages   &&&&  r   Ú_send_busy_drain_noticeÚ/GatewayBusySessionMixin._send_busy_drain_noticeø  s€   é € à×,Ñ,¨U¯\©\Ó:ˆßÙØ×+Ñ+¨N×;Ò;Ø×0Ñ0°ÔDÜÐ3¸D×<VÑ<VÓ<XÔY‰GäÐ5¸d×>XÑ>XÓ>ZÔ[ˆGØ×#Ñ# E°GÓ<×<Ô<ùs   ‚<B%¿AB%ÂB#ÂB%u   ðŸ‘�u   ðŸ‘Žúdict[str, tuple]Ú_PLAINTEXT_APPROVAL_EXTRA_WORDSztuple[tuple[str, tuple], ...]Ú_PLAINTEXT_APPROVAL_INPUT_KEYSc               ó   € V ^8„  d   QhRR/# )r   r   rW  r   )r   s   "r   r   rK     s   € ÷ ñ Ð+;ñ r   c                ó    € \        V P                  4      pV P                   F(  w  r#\        V4       F  pVP	                  WC4       K  	  K*  	  V# )ua   Word â†’ (verb, args) for the active language: the English list âˆª ``t("approval.inputs.<k>")``.)r�   rX  rY  r+   r%   )rQ   Úwordsr   Ú	verb_argsr*   s   &    r   Ú_plaintext_approval_wordsÚ1GatewayBusySessionMixin._plaintext_approval_words  sJ   € ä"& t×'KÑ'KÓ"LˆØ$(×$GÔ$GÑ ˆIÜ,¨YÖ7�Ø× Ñ  Ö1ó 8ñ %Hð ˆr   c               ó$   € V ^8„  d   QhRRRRRR/# ©r   rú   r	   rW   r   r   r8   r   )r   s   "r   r   rK     s#   € ÷ 2ñ 2Àð 2Ð[^ð 2Ðcgñ 2r   c              ƒ  óø  "  €  ^ RI Hp VP                  '       Ed.   V! V4      '       Ed   VP                  ;'       g    RP	                  4       P                  4       pV P                  4       P                  V4      pVeÊ   Vw  rgVR8X  d   V P                  MV P                  pRV RV 2P                  4       Vn        V! V4      G Rj  x€L
 p	\        P                  RW&V4       V P                  VP                  4      p
V
'       d@   V	'       d8   V
P                  V	4      w  r¼V'       d   V P!                  WVRR	7      G Rj  x€L
  R# R#  L� L
  \"         d    \        P%                  R
TRR7        R# i ; i5i)z¡Route a bare "yes"/"no" to the approval handlers while a dangerous-command approval blocks.

Returns True when the message was consumed as an approval response.
)Úhas_blocking_approvalr1   NÚapproveÚ/Ú z<Approval response via plain text: session=%s verb=%s args=%rT)rE  zSPlain-text approval routing failed for session %s; falling through to busy handlingr~   F)Útools.approvalrc  rÿ   r-   r#   r$   r^  r‚   Ú_handle_approve_commandÚ_handle_deny_commandÚrstriprƒ   Úinfor	  r°   Ú_unwrap_ephemeralrM  r…   r„   )rQ   rú   rW   rc  Ú	_raw_textÚ_matchÚ_verbÚ_normalized_argsÚ_approval_handlerÚ_replyÚ_adapterÚ_textÚ_eph_ttls   &&&          r   Ú$_route_plaintext_approval_while_busyÚ<GatewayBusySessionMixin._route_plaintext_approval_while_busy  s^  é € ð)	Ý<ð ×*×*Ñ*Ñ/DÀ[×/QÓ/QØ"ŸZ™Z×-Ð-¨2×4Ñ4Ó6×<Ñ<Ó>�	Ø×7Ñ7Ó9×=Ñ=¸iÓH�ØÒ%Ø.4Ñ+�Eà8=ÀÔ8J˜×4Ò4ÐPT×PiÑPið &ð $% U G¨1Ð-=Ð,>Ð!?×!FÑ!FÓ!H�E”JÙ#4°UÓ#;×;�FÜ—K‘KØVØ#Ð,<ôð  $×9Ñ9¸%¿,¹,ÓG�Hß§FØ*2×*DÑ*DÀVÓ*L™˜ß Ø"&×"7Ñ"7¸ÈÐ]aÐ"7Ó"b×bÐbÙñ ñ! <ñ cøäô 	Ü�N‰Nð3Ø4?È$ð õ ñ ð	üs^   ‚E:„'E ¬E ¿BE Ã
EÃAE Ä2E ÅEÅE ÅE:ÅE ÅE Å#E7Å3E:Å6E7Å7E:c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   rú   r	   rW   r   rP  r¾   r   r   zGatewayRunner._BusySteerOutcomer   )r   s   "r   r   rK   G  s4   € ÷ 4
ñ 4
Ø!ð4
Ø03ð4
ØEHð4
ØY\ð4
à	(ñ4
r   c              ƒ  ó‚  "  € ^ RI Hp VR8H  ;'       d    V P                  V4      pV'       d   V P                  VR4      pVR8H  ;'       d    V P	                  V4      G Rj  x€L
 pV'       d   V P                  VR4      pR;r‰VRJ;'       d    WEJp
VP
                  \        P                  8H  ;'       d+    VP                  '       * ;'       d    VP                  '       * pVR8X  dÏ   V P                  V4      G Rj  x€L
 p\        VRR4      ;'       g    . p\        V4      ;'       d'    \        V P                  V4      4      \        V4      8H  pV'       d@   V'       g	   V'       d0   V
'       d(   \        VR4      '       d   V P!                  VRWÂVR	7      pV'       d   V P#                  WBV4       MqR
pMnVR8X  dh   V'       d`   V
'       dX   \        VRR4      RJ dG   \        VR4      '       d5   T P%                  YAP&                  ;'       g    RP)                  4       W!4      p	V P+                  W6WxV	R7      #  EL× EL?5i)z_Apply interrupt->queue demotions, then attempt steer (steer mode) or redirect (interrupt mode).rÀ   Ú	interruptz/the running agent has active subagents (#30170)Nz)context compression is in flight (#56391)FrN   Ú
media_urls©rú   rM   Ú_supports_active_turn_redirectTÚredirectr1   )rP  Údemoted_for_subagentsÚdemoted_for_compressionÚsteeredÚ
redirected)rÄ   rÁ   rË   Ú_demote_interruptrð   r  r
   r  r{  Úmedia_typesr  re   r8   r4   r  rq   Ú_try_agent_verbÚ_fold_into_running_turnÚ_redirect_active_turnr-   r#   Ú_BusySteerOutcome)rQ   rú   rW   rP  r¾   rÁ   r  r€  r�  r‚  Ú
agent_liveÚ
plain_textÚ
steer_textÚ_steer_media_urlsÚ_steer_all_voices   &&&&&          r   Ú_resolve_busy_steer_or_redirectÚ7GatewayBusySessionMixin._resolve_busy_steer_or_redirectG  s  é € õ 	8ð
 ˜kÑ)×]Ð]¨d×.NÑ.NÈ}Ó.]ð 	÷ !Ø!×3Ñ3°KÐArÓsˆNà˜kÑ)×hÐh°D×4[Ñ4[Ð\gÓ4h×.hð 	 ÷ #Ø!×3Ñ3°KÐAlÓmˆNØ$Ð$ˆØ"¨$Ð.×_Ð_°=Ð3_ˆ
à×Ñ¤+×"2Ñ"2Ñ2×eÐe¸5×;KÑ;KÔ7K×eÐeÐTY×TeÑTeÔPeð 	ð ˜WÔ$Ø#×<Ñ<¸UÓC×CˆJô
 !(¨¨|¸TÓ B× HÐ HÀbÐÜ#Ð$5Ó6÷  ð  Ü�D×3Ñ3°EÓ:Ó;¼sÐCTÓ?UÑUð ÷ Ÿz×-=Ç:ÔRYÐZgÐip×RqÒRqØ×.Ñ.Ø! 7¨JÈ5ð /ó �÷ Ø×,Ñ,¨]ÈÕOà!(‘à˜kÔ)¯j¿ZÜ˜Ð'GÈÓOÐSWÓWÜ˜ z×2Ò2à×3Ñ3Ø§
¡
× 0Ð 0¨b×7Ñ7Ó9¸;óˆJð ×%Ñ%Ø)Ø$;ÐYcð &ó 
ð 	
òG /iò Dùsƒ   ‚,H?¯H?ÁH?Á"H9Á#H?Á/H?Â'H?Â7H?Ã-H?Ã=H<Ã>H?ÄH?Ä+.H?ÅH?Å"H?Å*H?Å2.H?Æ!$H?ÇH?ÇA H?È+H?È<H?c               ó$   € V ^8„  d   QhRRRRRR/# )r   rW   r   Úwhyr   r   )r   s   "r   r   rK   ~  s!   € ÷ ñ  sð °ð ¸ñ r   c                	ó2   € \         P                  R W4       R# )zIDemoting busy_input_mode 'interrupt' to 'queue' for session %s because %srM   ©rƒ   rk  )rW   r‘  s   &&r   rƒ  Ú)GatewayBusySessionMixin._demote_interrupt}  s   € ä�‰Ð_ÐalÔrÙr   rú   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   Úverbr   r-   rW   rú   rn   r   r8   r   )r   s   "r   r   rK   ‚  s4   € ÷ ñ Ø#&ðØ.1ðØ@CðØOeðà	ñr   c               óþ   €  V'       d   V P                  W54      MTpVR8X  d   V P                  W4      # \        \        W4      ! V4      4      #   \         d#   p\
        P                  RY$T4        Rp?R# Rp?ii ; i)zQCall ``running_agent.<verb>(text)`` (steer/redirect); False + warning on failure.rN   z$Gateway %s failed for session %s: %sNF)r;  rØ   r8   re   r…   rƒ   r„   )rQ   r¾   r–  r-   rW   rú   Ú	call_textrœ   s   &&&&&$  r   r…  Ú'GatewayBusySessionMixin._try_agent_verb‚  sn   € ð	ßEJ˜×4Ñ4°TÔAÐPTˆIØ�wŒØ×0Ñ0°ÓJÐJÜœ Ô4°YÓ?Ó@Ð@øÜô 	Ü�N‰NÐAÀ4ÐVYÔZÝûð	ús!   ‚A Š*A µA ÁA<ÁA7Á7A<c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r-   r   rW   rú   r	   r   r8   r   )r   s   "r   r   rK   �  s*   € ÷ ñ ¸ð È3ð ÐWcð Ðhlñ r   c                ó¼  € V P                  VRW#VR7      '       g   R# V P                  WV4      pVf   R# V P                  V4      pVP                  '       d   \	        VP                  4      MRpVP
                  e1   VP
                  VJd!   WeP
                  n        WuP
                  n        VP                  e!   WeP                  n	        WuP                  n
        R# )a˜  ``redirect()`` the running turn onto *event* and re-anchor its delivery to that message.

The turn's reply anchor and ledger identity were bound to the message that OPENED it, and
the final send is bracketed against that event; after a successful redirect the answer is
to *event*, so the reply must quote it (#115001). Both redirect entry points (busy
interrupt mode and the priority path) go through here.
r~  r|  FNT)r…  r†  rJ  r#  r   rú   Úreply_anchor_overrideÚledger_message_idÚctxÚevent_message_idÚinbound_message_id)rQ   r¾   r-   rW   rú   ÚturnÚanchorÚ
inbound_ids   &&&&&   r   r‡  Ú-GatewayBusySessionMixin._redirect_active_turn�  s³   € ð ×#Ñ# M°:¸tÐX]Ð#×^Ò^ÙØ×+Ñ+¨MÈÓNˆØŠ<ÙØ×-Ñ-¨eÓ4ˆØ.3×.>×.>Ð.>”S˜×)Ñ)Ô*ÀDˆ
Ø�:‰:Ò! d§j¡j¸Ó&=Ø/5�J‰JÔ,Ø+5�J‰JÔ(Ø�8‰8ÒØ(.�H‰HÔ%Ø*4�H‰HÔ'Ùr   c               ó    € V ^8„  d   QhRRRR/# )r   rW   r   rú   r	   r   )r   s   "r   r   rK   ¦  s   € ÷ ñ À#ð Èlñ r   c                ó8  € V P                  V4      P                  pVP                  VJd   R# VP                  e_   VP                  VJdO   VP                  P	                  V4       VP
                  e&   VP                  P                  VP
                  n        V# )zÐThe running turn now answers *event* too (steer, redirect): if *event* was addressed to
the bot, a bare silence marker must not end the turn. Returns the turn, or None when a newer
turn already owns the slot.N)rf   r¡  Úagentrú   Úabsorb_reply_expectedrž  Úreply_expected)rQ   r¾   rW   rú   r¡  s   &&&& r   r†  Ú/GatewayBusySessionMixin._fold_into_running_turn¦  su   € ð ×"Ñ" ;Ó/×4Ñ4ˆØ�:‰:˜]Ó*ÙØ�:‰:Ò! d§j¡j¸Ó&=Ø�J‰J×,Ñ,¨UÔ3Ø�x‰xÒ#Ø*.¯*©*×*CÑ*C�—‘Ô'Øˆr   c               ó    € V ^8„  d   QhRRRR/# )r   rú   r	   r   rb   r   )r   s   "r   r   rK   ³  s   € ÷ ñ À<ð Ðlpñ r   c              ƒ  ó†  "  € ^ RI Hp  VP                  p\        VRR4      ;'       g    . pV P	                  V4      '       d?   T P                  YVP                  VP                  ;'       g    RRR7      G Rj  x€L
 w  rWMV'       g   V'       d	   V! V4      pVP                  V4       R#  L2  \         d     R# i ; i5i)zYInterrupt mode: abort in-flight tool calls; the agent loop exits at its next check point.)Ú_build_media_placeholderr{  Nr1   zVoice-busy-interruptr  )	rÄ   r­  r-   re   r  r  r°   rz  r…   )rQ   rú   ra   r¾   r­  Ú_interrupt_textÚ_media_urlsrB   s   &&&&    r   Ú'_interrupt_running_agent_for_busy_eventÚ?GatewayBusySessionMixin._interrupt_running_agent_for_busy_event³  s®   é € å8ð	Ø#Ÿj™jˆOÜ! %¨°tÓ<×BÐBÀˆKØ×.Ñ.¨u×5Ò5Ø+/×+RÑ+RØ E§L¡L°%·*±*×2BÐ2BÀÐPfð ,Só ,÷ &Ñ"� ÷ %¯Ù":¸5Ó"A�Ø×#Ñ# OÖ4ñ&øô ô 	Úð	üsR   ‚CŠ9B/ Á)B/ Á.B/ Á:B-Á;B/ Â
B/ ÂB/ Â+CÂ-B/ Â/B>Â:CÂ=B>Â>Cc               ó$   € V ^8„  d   QhRRRRRR/# ra  r   )r   s   "r   r   rK   Ã  s"   € ÷ !ñ !¨\ð !Èð !ÐPTñ !r   c                	óN  € ^ RI HpHp ^ RIHp \
        P                  P                  R4      pVe#   VP                  4       P                  4       R9   pM3\        V! V! 4       V! VP                  P                  4      RR4      4      pV'       g   \        P                  RV4       V# )rü   )r%  Ú_platform_config_key©Úresolve_display_settingÚ%HERMES_GATEWAY_BUSY_STEER_ACK_ENABLEDÚbusy_steer_ack_enabledTz(Busy steer ack suppressed for session %s>   Ú1ÚonÚyesÚtrue)rÄ   r%  r´  Úgateway.display_configr¶  ÚosÚenvironr‚   r#   r$   r8   r°   r´   rƒ   r†   )rQ   rú   rW   r%  r´  r¶  Ústeer_ack_envÚsteer_ack_enableds   &&&     r   Ú_busy_steer_ack_enabledÚ/GatewayBusySessionMixin._busy_steer_ack_enabledÃ  s‰   € çJÝBÜŸ
™
Ÿ™Ð'NÓOˆØÒ$Ø -× 3Ñ 3Ó 5× ;Ñ ;Ó =ÐA[Ñ [Ñä $Ù'Ù(Ó*Ñ,@ÀÇÁ×AVÑAVÓ,WØ,¨dóó!Ð÷ !Ü�L‰LÐCÀ[ÔQØ Ð r   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   rK   Ö  s   € ÷ .ñ . Cñ .r   c                	ó   € \        R 4      # )zgateway.busy.demoted_tail©r   ©rQ   s   &r   Ú_BUSY_DEMOTED_TAILÚ*GatewayBusySessionMixin._BUSY_DEMOTED_TAILÕ  s   € äÐ,Ó-Ð-r   c               ó<   € V ^8„  d   QhRRRRRRRRR	RR
RRRRRRR/	# )r   rú   r	   ÚnowÚfloatr¾   r   Úis_steer_moder8   Úis_queue_modeÚis_redirect_moder  r€  r   r   r   )r   s   "r   r   rK   Ù  sf   € ÷ Fñ FØ!ðFØ(-ðFØKNðFàðFà,0ðFàDHðFð  $ðFð ?CðFð 
ñ	Fr   c          	     	ó¦  € ^ RI Hp
HpHpHp ^ RIHp . p\        V! V! 4       V! VP                  P                  4      RR4      4      pV'       Ed+   V'       Ed"   WJJEd    VP                  4       p^ pV'       dI   VP                  P                  '       d-   \        W#P                  P                  ,
          ^<,          4      pV^ 8”  d   VP                  \        RVR7      4       VP!                  R^ 4      '       d<   VP                  \#        VP!                  R^ 4      VP!                  R^ 4      4      4       VP!                  R	4      '       d,   VP                  \        R
VP!                  R	4      R7      4       V'       d&   \        R\        R4      P'                  V4      R7      MRpV'       d/   V P)                  V4      '       d   \        R4      p\        R4      pMÃV'       d   \        R4      \        R4      ppM¤V'       d   \        R4      \        R4      ppM…V'       d!   V'       d   \        R4      V P*                  ppM]V'       d!   V	'       d   \        R4      V P*                  ppM5V'       d   \        R4      \        R4      ppM\        R4      \        R4      pp\        RVVVR7      p ^ RIHpHpHpHp V! V! 4       V4      '       g>   V'       d   RMV'       d   R MV'       d   R!MR"pV R#V! V4       2pV! VR$,          V4       V#   \$         d     EL¥i ; i  \$         d"   p\6        P9                  R%T4        R&p?T# R&p?ii ; i)'rü   )rÁ   Ú_hermes_homer%  r´  rµ  Úbusy_ack_detailTzgateway.busy.elapsed_min)ÚminutesÚmax_iterationsÚapi_call_countÚcurrent_toolzgateway.busy.running_tool)Útoolzgateway.busy.ack_detail_wrapzgateway.busy.ack_detail_joiner)Údetailr1   z#gateway.busy.steered_subagents_headz#gateway.busy.steered_subagents_tailzgateway.busy.steered_headzgateway.busy.steered_tailzgateway.busy.redirected_headzgateway.busy.redirected_tailz"gateway.busy.subagent_working_headzgateway.busy.compressing_headzgateway.busy.queued_headzgateway.busy.queued_tailzgateway.busy.interrupting_headzgateway.busy.interrupting_tailzgateway.busy.ack)r‡   rØ  r7   )ÚBUSY_INPUT_FLAGÚbusy_input_hint_gatewayÚis_seenÚ	mark_seenrN   rM   r~  rz  z

zconfig.yamlz.Failed to apply busy-input onboarding hint: %sN)rÄ   rÁ   rÑ  r%  r´  r½  r¶  r8   r°   r´   Úget_activity_summaryr¡  Ú
started_tsrw   rg   r   r‚   r   r…   ÚjoinrË   rÈ  Úagent.onboardingrÙ  rÚ  rÛ  rÜ  rƒ   r†   )rQ   rú   rË  Ú_busy_stater¾   rÍ  rÎ  rÏ  r  r€  rÁ   rÑ  r%  r´  r¶  Ústatus_partsÚbusy_ack_detail_enabledÚsummaryÚelapsed_minÚstatus_detailr‡   r7   rT  rÙ  rÚ  rÛ  rÜ  Ú
_hint_modeÚ_onb_errs   &&&&&$$$$$                   r   Ú_compose_busy_ack_messageÚ1GatewayBusySessionMixin._compose_busy_ack_messageÙ  sÞ  € ÷
	
ó 	
õ 	Cð ˆÜ"&Ù#Ù$Ó&Ñ(<¸U¿\¹\×=RÑ=RÓ(SØ! 4óó#
Ð÷ #Ð"§} }¸Ô9eðØ'×<Ñ<Ó>�Ø�ß ;×#3Ñ#3×#>×#>Ð#>Ü"% s×-=Ñ-=×-HÑ-HÕ'HÈBÕ&NÓ"O�KØ ”?Ø ×'Ñ'¬Ð*DÈkÔ(ZÔ[Ø—;‘;Ð/°×3Ò3Ø ×'Ñ'Ü1Ø#ŸK™KÐ(8¸!Ó<¸g¿k¹kÐJZÐ\]Ó>^óôð
 —;‘;˜~×.Ò.Ø ×'Ñ'¬Ð*EÈGÏKÉKÐXfÓLgÔ(hÔi÷ )ô Ð9Ä!ÐDdÓBe×BjÑBjÐkwÓBxÕyØ.0ð 	ç˜T×=Ñ=¸m×LÒLÜÐ:Ó;ˆDÜÐ:Ó;‰DßÜÐ6Ó7¼Ð;VÓ9W�$ˆD�$ßÜÐ9Ó:¼AÐ>\Ó<]�$ˆD�$ß×4äÐ?Ó@À$×BYÑBY�$ˆD�$ß×6ÜÐ:Ó;¸T×=TÑ=T�$ˆD�$ßÜÐ5Ó6¼Ð:TÓ8U�$ˆD�$äÐ;Ó<¼aÐ@`Ó>a�$ˆDÜÐ&¨T¸-ÈdÔSˆð	UßgÓgÙÑ/Ó1°?×CÒCç,‘Gß$1™ß'7™Ø$ð	 ð %˜I TÑ*AÀ*Ó*MÐ)NÐO�Ù˜,¨Õ6¸ÔHð ˆøôI ô ÚðûôD ô 	UÜ�L‰LÐIÈ8×TÐTØˆûð	UúsV   Á!L Á;L ÂA&L Ã>AL Å+L Ê3'L$ Ë	L$ Ë%	L$ Ë/!L$ ÌL!Ì L!Ì$MÌ/MÍMc               ó$   € V ^8„  d   QhRRRRRR/# )r   rú   r	   rT  r   r   rb   r   )r   s   "r   r   rK   !  s#   € ÷ ;ñ ;°ð ;ÐPSð ;ÐX\ñ ;r   c              ƒ  	ó¦   "  €  V P                  WV4      G R j  x€L
  R #  L  \         d"   p\        P                  RT4        R p?R # R p?ii ; i5i)NzFailed to send busy-ack: %s)rM  r…   rƒ   r†   )rQ   rú   ra   rT  r’   s   &&&& r   Ú_send_busy_ack_replyÚ,GatewayBusySessionMixin._send_busy_ack_reply!  sA   é € ð	;Ø×'Ñ'¨¸Ó@×@Ô@øÜô 	;Ü�L‰LÐ6¸×:Ò:ûð	;üs6   ‚A„" ™ š" žA " ¢A­A	ÁAÁ	AÁAc               ó$   € V ^8„  d   QhRRRRRR/# ra  r   )r   s   "r   r   rK   '  s(   € ÷ bñ b¸|ð bÐZ]ð bÐbfñ br   c              ƒ  	ó|  "  € VP                   '       d]   VP                  '       dK   V P                  VP                  4      pV'       d&   V\	        VR / 4      9   d   V P                  W!4       R# R# ^ RIHp V P                  VP                  4      '       g€   \        P                  RVP                  P                  VP                  P                  VP                  P                  '       d!   VP                  P                  P                  MRV4       R# V P                  VP                  4      '       g   R# RVn        V P#                  VP                  4      pV P$                  '       d   V P'                  WV4      G Rj  x€L
  R# V P)                  W4      G Rj  x€L
 '       d   R# V P                  VP                  4      pV'       g   R# \	        VRR4      '       d   V P                  W!4       R# VP*                  \,        P.                  8X  d*   V P1                  VP                  4      R8X  d
   VR	8w  d   R# V P3                  V4      pV'       d   VP4                  P6                  MRpV P9                  WWW4      G Rj  x€L
 pVP:                  VP<                  r•VP>                  '       g   V	'       g   V P                  W!4       VR8H  p
VR	8H  pVR
8H  ;'       d    T	pVR
8X  d0   V	'       g(   V'       d    WtJd   V PA                  WV4      G Rj  x€L
  \B        PD                  PG                  RR4      PI                  4       R8w  d   \        PK                  RV4       R# \L        PL                  ! 4       pYÖ'       d   VP4                  PN                  M^ ,
          ^8  d   R# V'       d   V PQ                  W4      '       g   R# WÐPS                  V4      P4                  n'        V PU                  WWgVW¬VPV                  VPX                  R7	      pV P[                  WV4      G Rj  x€L
  R#  EL« EL“ EL° EL" L5i)rd   TFrÀ   z`Dropping message from unauthorized user in active session: user=%s (%s), platform=%s, session=%sÚunknownNrþ   rM   rN   rz  ÚHERMES_GATEWAY_BUSY_ACK_ENABLEDr¼  z"Busy ack suppressed for session %s)rÍ  rÎ  rÏ  r  r€  ).rþ   rÿ   r	  r°   re   r  rÄ   rÁ   Ú_is_user_authorized_for_sourcerƒ   r„   rµ   Ú	user_namer´   r¹   Ú_admit_bot_message_for_sourceÚ_bot_loop_admittedÚ_effective_busy_input_modeÚ	_drainingrU  rv  r  r
   r  Ú_effective_busy_text_moderY   r¡  r§  rŽ  rP  r‚  r�  r°  r¾  r¿  r‚   r$   r†   ÚtimeÚbusy_ack_tsrÂ  rf   ré  r  r€  rí  )rQ   rú   rW   ra   rÁ   rP  rá  r¾   Ú_steerr‚  rÎ  rÍ  rÏ  rË  rT  s   &&&            r   Ú#_handle_active_session_busy_messageÚ;GatewayBusySessionMixin._handle_active_session_busy_message'  s[  é € ð �>�>ˆ>˜e×9×9Ð9Ø×0Ñ0°·±Ó>ˆGß˜;¬'°'Ð;NÐPRÓ*SÔSØ×4Ñ4°[ÔHÙÙõ 	8ð ×2Ñ2°5·<±<×@Ò@Ü�N‰Nð8Ø9>¿¹×9MÑ9MÈuÏ|É|×OeÑOeØ/4¯|©|×/D×/DÐ/D�—‘×%Ñ%×+Ò+È)ÐU`ôñ
 à×1Ñ1°%·,±,×?Ò?ÙØ#'ˆÔ à×8Ñ8¸¿¹ÓFˆØ�>�>ˆ>Ø×.Ñ.¨uÀ>ÓR×RÐRÙØ×:Ñ:¸5ÓN×NÖNÙØ×,Ñ,¨U¯\©\Ó:ˆßÙô �5˜* e×,Ò,Ø×0Ñ0°ÔDÙà×Ñ¤+×"2Ñ"2Ô2Ø×.Ñ.¨u¯|©|Ó<ÀÔGØ 'Ô)áà×.Ñ.¨{Ó;ˆß2=˜×(Ñ(×.Ò.À4ˆØ×;Ñ;¸EÐP^Ón×nˆØ%+×%:Ñ%:¸F×<MÑ<M˜
ð �~�~ˆ~§jØ×0Ñ0°ÔDð '¨'Ñ1ˆØ&¨'Ñ1ˆØ)¨[Ñ8×GÐG¸ZÐà˜kÔ)·*ß -Ó"Nà×>Ñ>¸uÈ}Ó]×]Ð]ô �:‰:�>‰>Ð;¸VÓD×JÑJÓLÐPVÔVÜ�L‰LÐ=¸{ÔKÙô �iŠi‹kˆØ¶+�+×"Ñ"×.Ò.À1ÕEÈÔJÙç ×!=Ñ!=¸e×!QÒ!QÙà<?×Ñ˜KÓ(×-Ñ-Ô9à×0Ñ0Ø˜À-Ø'Ø"(×">Ñ">Ø$*×$BÑ$Bð	 1ó 
ˆð ×'Ñ'¨¸Ó@×@Ð@ÙòK SâNò( oò, ^ñ0 	Aùs²   ‚$P<§"P<Á
AP<ÂAP<Ã.A	P<Ä85P<Å.P<ÆP.ÆP<ÆP1Æ	P<Æ)$P<ÇBP<É-P<ÊP4Ê4P<Ê:&P<Ë!P<Ë3P<Ë;P<ÌP7ÌBP<Î/A8P<Ð'P:Ð(P<Ð1P<Ð4P<Ð7P<Ð:P<ÚbgÚ_handle_background_commandÚsethomeÚ_handle_set_home_commandc               ó   € V ^8„  d   QhRR/# ©r   r   zdict[str, Any]r   )r   s   "r   r   rK   œ  s   € ÷ 
ñ 
¨~ñ 
r   c                	ó    € V Uu/ uF=  pV\        W P                  P                  VR VP                  RR4       R24      4      bK?  	  up# u upi )Ú_handle_Ú-rB   Ú_command)re   Ú_COMMAND_HANDLER_ALIASESr‚   r7  )rQ   ÚnamesÚnames   && r   Ú_command_handler_tableÚ.GatewayBusySessionMixin._command_handler_tableœ  sg   € ñ
 ó	
ñ �ð ”'Ø×3Ñ3×7Ñ7¸ÀÈÏÉÐVYÐ[^ÓI_ÐH`Ð`hÐ>iÓjóò ñ ñ	
ð 	
ùò 
s   …AAc                ó8   € V P                  V P                  4      # )z@Return ordinary slash handlers shared by idle and busy dispatch.)r  Ú_PLAIN_COMMANDSrÇ  s   &r   Ú_gateway_plain_command_handlersÚ7GatewayBusySessionMixin._gateway_plain_command_handlers¤  s   € à×*Ñ*¨4×+?Ñ+?Ó@Ð@r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r-   r   Úlabelr   rb   r   )r   s   "r   r   rK   ¨  s&   € ÷ 	Eñ 	E°Cð 	EÀð 	EÈñ 	Er   c              ƒ  ó  "  €  V P                  V4      pV'       d@   VP                  \        VP                  4      W P	                  V4      R7      G Rj  x€L
  R# R#  L  \
         d    \        P                  RTRR7        R# i ; i5i)zVBest-effort acknowledgment for a slash command that falls through to agent processing.)r¸   Nz%s ack send failedTr~   )r	  Úsendr   r=   rL  r…   rƒ   r†   )rQ   r°   r-   r  ra   s   &&&& r   Ú_send_command_ackÚ)GatewayBusySessionMixin._send_command_ack¨  s‚   é € ð	EØ×0Ñ0°Ó8ˆGßØ—l‘lÜ˜Ÿ™Ó'¨×8XÑ8XÐY_Ó8`ð #ó ÷ ò ñ ñøô ô 	EÜ�L‰LÐ-¨u¸tˆL×Dð	Eüs;   ‚B
„AA  ÁAÁA  ÁB
ÁA  Á #BÂB
ÂBÂB
c                ó8   € V P                  V P                  4      # )zVSlash handlers dispatched only on the idle path (busy dispatch has its own allowlist).)r  Ú_IDLE_COMMANDSrÇ  s   &r   Ú_gateway_idle_command_handlersÚ6GatewayBusySessionMixin._gateway_idle_command_handlers³  s   € à×*Ñ*¨4×+>Ñ+>Ó?Ð?r   Ú_busy_r  zdict[str, str]Ú_BUSY_SPECIAL_HANDLERSc               ó    € V ^8„  d   QhRRRR/# ©r   rú   r	   Ú	quick_keyr   r   )r   s   "r   r   rK   ¼  s   € ÷ ">ñ ">¸ð ">ÐZ]ñ ">r   c              ƒ  ó–  "  € VP                   p\        VRR4      p\        VRR4      pV'       dd   V P                  P                  V4      pVe   \        W4      ! WV4      G Rj  x€L
 # V P                  P                  V4      p	V	e   \        V	4      # VR9   d~   V P                  4       P                  V4      p
V
eE   V P                  V4      ;_uu_4       GRj  x€L
  V
! V4      G Rj  x€L
 uuRRR4      GRj  x€L
  # \        P                  RWe4       \        RVR7      #  L¿ LK L= L.  + GRj  x€L 
 '       g   i     LD; i5i)	uï  Dispatch a recognized slash command while an agent is running.

Order: ``busy_handler`` (mid-run variant) â†’ ``busy_policy == "dispatch"`` (normal handler)
â†’ catch-all reject text. Rejecting is required rather than falling through to
interrupt + discard: commands like /model, /reasoning, /voice, /insights, /title,
/resume, /retry, /undo, /compress, /usage, /reload-mcp, /sethome, /reset (all
registered as Discord slash commands) would interrupt the agent AND get silently
discarded by the slash-command safety net, producing a zero-char response.
See #5057, #6252, #10370.

1. ``busy_handler`` â€” special mid-run variant (e.g. /goal's control-verb whitelist, /queue's FIFO
enqueue, /model's custom reject text). 2. 3. See #5057, #6252, #10370.
Úbusy_policyÚrejectÚbusy_handlerNuM   busy_policy=%s for /%s has no mid-run handler â€” falling back to busy-rejectzgateway.busy.slash_rejected©Úcommand)ÚdispatchÚinterrupt_then_dispatch)
r  re   r  r‚   Ú_BUSY_REJECT_TEXTr   r  Ú_async_profile_scope_for_sourcerƒ   r„   )rQ   rú   Úcmd_defr   r°   r  ÚpolicyÚhandler_keyÚspecialÚ
reject_keyÚplains   &&&&&      r   Ú_dispatch_busy_slash_commandÚ4GatewayBusySessionMixin._dispatch_busy_slash_command¼  s  é € ð �|‰|ˆÜ˜ -°Ó:ˆÜ˜g ~°tÓ<ˆßØ×1Ñ1×5Ñ5°kÓBˆGØÒ"Ü$ TÔ3°EÀfÓM×MÐMØ×/Ñ/×3Ñ3°KÓ@ˆJØÒ%Ü˜“}Ð$ØÐ<Ô<Ø×8Ñ8Ó:×>Ñ>¸tÓDˆEØÒ Ø×?Ñ?À×G×GÕGÙ!& u£×-÷ H×GÒGä�N‰Nð.Ø/5ôô
 Ð.¸Ô=Ð=ñ Nñ HÙ-÷ H×G×GÒGüss   ‚A#E	Á%D%Á&A5E	ÃD'ÃE	ÃD-Ã+D)Ã,D-Ã/E	Ã<D+Ã=)E	Ä'E	Ä)D-Ä+E	Ä-E	Ä3D6Ä4
E	Ä?E	ÅE	c               ó   € V ^8„  d   QhRR/# r>  r   )r   s   "r   r   rK   à  s   € ÷ 8ñ 8°ñ 8r   c              ƒ  ó$  "  € ^ RI Hp VP                  4       ;'       g    RP                  4       pVP	                  4       R9   d-   VP                  4       '       d   \        R4      # \        R4      # VP                  4       pVeK   V'       gC   VP                  R4      '       d   \        RVP                  R4      R7      MRp\        R	VR
7      # TP                  T;'       g    RR7       V'       d   \        RVR7      MRp\        RVR
7      # 5i)z¶`/pause [reason]` engages the global emergency stop; `/pause off` lifts it (the estop gate
lets slash commands through while paused so messaging-only operators are never locked out).)Úestopr1   zgateway.pause.resumedzgateway.pause.not_pausedNÚreasonzgateway.pause.reason_suffix)r6  zgateway.pause.already_paused)Úsuffixzgateway.pause.paused>   ÚoffÚstopÚresumeÚ	disengage)
r§  r5  Úget_command_argsr#   r$   r;  r   Ú	get_stater‚   Úengage)rQ   rú   r5  Úargsr\   r7  s   &&    r   Ú_handle_pause_commandÚ-GatewayBusySessionMixin._handle_pause_commandà  sÜ   é € õ 	 Ø×&Ñ&Ó(×.Ð.¨B×5Ñ5Ó7ˆØ�:‰:‹<ÐAÔAØ�‰× Ò ÜÐ0Ó1Ð1ÜÐ/Ó0Ð0Ø—‘Ó!ˆØÒ§TØUZ×U^ÑU^Ð_g×UhÒUh”QÐ4¸U¿Y¹YÀxÓ=PÕQÐnpˆFÜÐ3¸FÔCÐCØ�‰˜DŸL˜L DˆÔ)ßBF”Ð0¸Õ>ÈBˆÜÐ'°Ô7Ð7ùs$   ‚ADÁ1DÂDÂ%>DÃ$DÃ4Dc               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rK   ñ  s   € ÷ ñ ¨|ð Èñ r   c              ƒ  	ó:   "  € \         P                  R V4       R# 5i)z3Ignoring /start platform ping for active session %sr1   r“  )rQ   rú   r   r°   s   &&&&r   Ú_busy_start_commandÚ+GatewayBusySessionMixin._busy_start_commandñ  s   é € ä�‰ÐIÈ9ÔUÙùs   ‚c               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rK   ö  s   € ÷ $ñ $°ð $Èñ $r   c              ƒ  	ó$   "  € ^ RI Hp V! 4       # 5i)rü   )Úformat_status_text)Úhermes_cli.proxy_clirH  )rQ   rú   r   r°   rH  s   &&&& r   Ú_busy_egress_commandÚ,GatewayBusySessionMixin._busy_egress_commandö  s   é € Ý;Ù!Ó#Ð#ùs   ‚c               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rK   ú  s   € ÷ 9ñ 9¨lð 9Àsñ 9r   c              ƒ  	ó¦   "  € ^ RI Hp V P                  W#VRR7      G Rj  x€L
  \        P	                  RV4       \        \        R4      4      #  L.5i)rü   )Ú_INTERRUPT_REASON_STOPÚstop_command©Úinterrupt_reasonÚinvalidation_reasonNu@   STOP for session %s â€” agent interrupted, session lock releasedzgateway.stop.stopped)rÄ   rN  Ú_interrupt_and_clear_sessionrƒ   rk  r   r   )rQ   rú   r   r°   rN  s   &&&& r   Ú_busy_stop_commandÚ*GatewayBusySessionMixin._busy_stop_commandú  sV   é € å6Ø×/Ñ/ØÐ0FÐ\jð 0ó 
÷ 	
ð 	
ô 	�‰ÐVÐXaÔbÜœaÐ 6Ó7Ó8Ð8ñ		
ùs   ‚A A¡/Ac               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rK     s   € ÷ 	7ñ 	7¨\ð 	7Àcñ 	7r   c              ƒ  	óˆ   "  € ^ RI Hp V P                  W#VRR7      G Rj  x€L
  V P                  V4      G Rj  x€L
 #  L L5i)rü   )Ú_INTERRUPT_REASON_RESETÚnew_commandrP  N)rÄ   rX  rS  Ú_handle_reset_command)rQ   rú   r   r°   rX  s   &&&& r   Ú_busy_new_commandÚ)GatewayBusySessionMixin._busy_new_command  sR   é € õ 	8ð ×/Ñ/ØÐ0GÐ]jð 0ó 
÷ 	
ð 	
ð ×/Ñ/°Ó6×6Ð6ñ	
ñ 7ùs   ‚A >¡A¹A ºAÁ Ac               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rK     s   € ÷ oñ o¨|ð oÈñ or   c              ƒ  	óô  "  € VP                  4       P                  4       p\        \        VR R4      4      pV'       g   V'       g   \	        R4      # V P                  V4      pV'       EdO   T P                  T\        R/ RVbRV'       d   VP                  M\        P                  bRVP                  bRVP                  bRVP                  bR \        \        VR . 4      ;'       g    . 4      bR\        \        VR. 4      ;'       g    . 4      bR	\        \        VR	. 4      ;'       g    . 4      bR
VP                  bRVP                   bRVP"                  bRVP$                  bRVP&                  bRVP(                  bRVP*                  bRVP,                  bRVP.                  bRVP0                  b V4       V P3                  W&R7      p\	        R4      V^8”  d   \	        RVR7      ,           # R,           # 5i)r{  Nzgateway.queue.usager-   r  r°   Úraw_messager#  r„  Úmedia_text_inlinedÚreply_to_message_idÚreply_to_textÚreply_to_author_idÚreply_to_author_nameÚreply_to_is_own_messageÚ
auto_skillÚchannel_promptÚchannel_contextrþ   Ú	timestampr  zgateway.queue.queuedzgateway.queue.queued_depth)ry   r1   r   )r<  r#   r8   re   r   r	  rj   r	   r  r
   r  r°   r_  r#  rÅ   ra  rb  rc  rd  re  rf  rg  rh  rþ   ri  rz   )rQ   rú   r   r°   Úqueued_textÚ	has_mediara   ry   s   &&&&    r   Ú_busy_queue_commandÚ+GatewayBusySessionMixin._busy_queue_command  s   é € à×,Ñ,Ó.×4Ñ4Ó6ˆäœ ¨°dÓ;Ó<ˆ	ß§9ÜÐ*Ó+Ð+Ø×,Ñ,¨VÓ4ˆßˆ7Ø×Ñ˜y¬,ò +Ù ð+ßEN¨u×/AÒ/AÔT_×TdÑTdøð+à—|’|ð+à16×1BÒ1Bð+àOT×O_ÒO_ð+ô  ¤¨¨|¸RÓ @× FÐ FÀBÔGð+ô !¤¨°¸rÓ!B×!HÐ!HÀbÔIð	+ô
 $(¬°Ð7KÈRÓ(P×(VÐ(VÐTVÔ#Wð+ð %*×$=Ò$=ð+ð NS×M`ÒM`ð+ð $)×#;Ò#;ð+ð &+×%?Ò%?ð+ð ).×(EÒ(Eð+ð SX×RbÒRbð+ð  %×3Ò3ð+ð FK×EZÒEZð+ð Ÿšð+ð 49·?²?ð+ð ôð ×!Ñ! )Ð!Ó=ˆÜÐ'Ó(Ð\aÐdeÔ\e¬AÐ.JÐRWÔ,XÕnÐnÐkmÕnÐnùs&   ‚AG8Á$G8Á,A;G8Ã( G8Ä	 G8Ä*CG8c               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rK   '  s   € ÷ $Iñ $I¨|ð $IÈñ $Ir   c              ƒ  	óB  a aaaa"  € ^ RI Hp SP                  4       P                  4       oS'       g   \	        R4      # S P                  S4      pV'       d   VP                  P                  MRpR VVV VV3R llpWdJ d   V! \	        R4      4      # V'       d   \        VR4      '       g   V! \	        R4      4      #  S P                  VS P                  SS4      4      pT'       g   \	        R4      # S P                  TSS4       SR,          \        S4      ^<8”  d   RMR,           p
S P!                  T4      '       d   \	        R4      M
\	        R4      p\	        RYºR7      #   \         d/   p	\        P                  R	ST	4       \	        R
T	R7      u Rp	?	# Rp	?	ii ; i5i)rü   rÀ   zgateway.steer.usageNc               ó    € V ^8„  d   QhRRRR/# )r   Úreplyr   r   r   )r   s   "r   r   ÚAGatewayBusySessionMixin._busy_steer_command.<locals>.__annotate__1  s   € ÷ 		ñ 		 3ð 		¨3ñ 		r   c                óê   <€ SP                  S4      pV'       dY   SP                  S\        S\        P                  SP
                  SP                  SP                  SP                  R 7      V4       V # ))r-   r  r°   r#  rg  rh  )	r	  rj   r	   r
   r  r°   r#  rg  rh  )rq  ra   rú   r   rQ   r°   r‹  s   & €€€€€r   Ú_queue_fallbackÚDGatewayBusySessionMixin._busy_steer_command.<locals>._queue_fallback1  sd   ø€ à×0Ñ0°Ó8ˆGßØ×"Ñ" 9¬lØ#´+×2BÑ2BÈ5Ï<É<Ø$×/Ñ/À×@TÑ@TØ$)×$9Ñ$9ô/ð ô	ð
 ˆLr   zgateway.steer.queued_startingrN   zgateway.steer.queued_no_agentzSteer failed for session %s: %szgateway.steer.failed©Úerrorzgateway.steer.rejected_empty:Né<   Nz...r1   zgateway.steer.target_subagentszgateway.steer.target_runzgateway.steer.queued)ÚtargetÚpreview)rÄ   rÁ   r<  r#   r   rY   r¡  r§  rq   rØ   r;  r…   rƒ   r„   r†  r4   rË   )rQ   rú   r   r°   rÁ   Ú_steer_stater¾   rt  rÒ   rœ   rz  ry  r‹  s   ffff        @r   Ú_busy_steer_commandÚ+GatewayBusySessionMixin._busy_steer_command'  sc  üé € õ 	8Ø×+Ñ+Ó-×3Ñ3Ó5ˆ
ßÜÐ*Ó+Ð+Ø×/Ñ/°	Ó:ˆß3?˜×)Ñ)×/Ò/ÀTˆ÷		ô 		ð Ó3Ù"¤1Ð%DÓ#EÓFÐFß¤G¨M¸7×$CÒ$CÙ"¤1Ð%DÓ#EÓFÐFð	8Ø×0Ñ0°À×@\Ñ@\Ð]gÐinÓ@oÓpˆH÷ ÜÐ3Ó4Ð4Ø×$Ñ$ ]°I¸uÔEØ˜S•/¬c°*«oÀÔ.B¡UÈÕKˆØ9=×9YÑ9YÐZg×9hÒ9h”!Ð4Ô5ÜÐ3Ó4ð 	äÐ'°ÔHÐHøô ô 	8Ü�N‰NÐ<¸iÈÔMÜÐ+°3Ô7Õ7ûð	8üsP   ‡AFÁAFÂ#FÂ?"E# Ã!FÃ)AFÅ #FÅ#FÅ.#FÆFÆFÆFÆFc               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rK   M  s   € ÷ -ñ -¨lð -Àsñ -r   c              ƒ  	ó®   "  € ^ RI Hp T! VP                  4       ;'       g    R4      '       d   V P                  V4      G Rj  x€L
 # \	        R4      #  L5i)rü   )Úis_goal_controlr1   Nzgateway.busy.reject_goal)Úhermes_cli.goal_commandr€  r<  Ú_handle_goal_commandr   )rQ   rú   r   r°   r€  s   &&&& r   Ú_busy_goal_commandÚ*GatewayBusySessionMixin._busy_goal_commandM  sK   é € õ 	<á˜5×1Ñ1Ó3×9Ð9°r×:Ò:Ø×2Ñ2°5Ó9×9Ð9ÜÐ+Ó,Ð,ñ :ùs   ‚,A¯AÁAÁAc               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rK   V  s   € ÷ -ñ -¨lð -Àsñ -r   c              ƒ  	óà   "  € VP                  4       ;'       g    R P                  4       P                  4       pV'       d   VR9   d   V P                  V4      G Rj  x€L
 # \	        R4      #  L5i)r1   Nzgateway.busy.reject_loop>	   Úhelpr9  ÚclearÚpauseÚcancelr:  Ústatusú-hú--help)r<  r#   r$   Ú_handle_loop_commandr   )rQ   rú   r   r°   Ú	_loop_args   &&&& r   Ú_busy_loop_commandÚ*GatewayBusySessionMixin._busy_loop_commandV  s]   é € à×+Ñ+Ó-×3Ð3°×:Ñ:Ó<×BÑBÓDˆ	ß˜IÐ)yÔyØ×2Ñ2°5Ó9×9Ð9ÜÐ+Ó,Ð,ñ :ùs   ‚>A.ÁA.ÁA,ÁA.c               ó$   € V ^8„  d   QhRRRRRR/# )r   r°   r   Úcanonical_cmdr   r   r/   r   )r   s   "r   r   rK   ]  s'   € ÷ Zñ Z¨-ð ZÈð ZÐP]ñ Zr   c                óL  € ^ RI Hp V'       g   R# V! W4      pVP                  '       d#   VP                  VP                  V4      '       d   R# \
        P                  RY!P                  '       d   VP                  P                  MRVP                  4       \        VP                  4      pV'       dZ   \        R4      RP                  R VR,           4       4      ,           \        V4      ^8”  d   R	MR
,           \        R4      ,           pM\        R4      p\        RW&R7      # )u´   Denial message if ``source`` cannot run ``canonical_cmd``, else None (both dispatch paths
use it so an in-flight agent can't bypass admin gating; no ``allow_admin_from`` â†’ None).)Úpolicy_for_runner_sourceNzLSlash command /%s denied for %s:%s (not admin, not in user_allowed_commands)Ú?z'gateway.unauthorized.admin_only_can_runz, c              3  ó,   "  € T F
  pR V 2x € K  	  R# 5i)re  Nr   )r  Úcs   & r   r  Ú>GatewayBusySessionMixin._check_slash_access.<locals>.<genexpr>m  s   é € ÐHoÑZnÐUVÈ1ÈQÈCÍÓZnùs   ‚:Né   Nu   â€¦r1   z+gateway.unauthorized.admin_only_whoami_hintz$gateway.unauthorized.admin_only_nonezgateway.unauthorized.admin_only)r&  r7  )Úgateway.slash_accessr•  ÚenabledÚcan_runrµ   rƒ   rk  r´   r¹   ÚsortedÚuser_allowed_commandsr   rß  r4   )rQ   r°   r“  r•  r,  Úallowed_previewr7  s   &&&    r   Ú_check_slash_accessÚ+GatewayBusySessionMixin._check_slash_access]  sâ   € õ 	BßÙÙ)¨$Ó7ˆØ�~�~ˆ~ §¡°·±À×!NÒ!NÙÜ�‰ØZØ·O·O°O˜6Ÿ?™?×0Ò0ÈÈfÏnÉnô	
ô ! ×!=Ñ!=Ó>ˆßäÐ;Ó<¸t¿y¹yÑHoÐZiÐjmÖZnÓHoÓ?oÕoÜ Ó0°2Ô5‘5¸2õ?ÜABÐCpÓAqõrñ ô
 Ð=Ó>ˆFÜÐ2¸MÔYÐYr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r°   r   Úown_keyr   r   úlist[tuple[str, str, str]]r   )r   s   "r   r   rK   t  s"   € ÷ ñ  mð ¸cð ÐF`ñ r   c                ój  € \        \        VRR4      ;'       g    R4      pV'       g   . # VP                  R8X  d5   VP                  \        P
                  8X  d   \        V4      ;'       g    TpRP                  VP                  R^4      R,          4      pV RVP                  P                   R2p\        \        VRR4      ;'       g    R4      ;'       g    Rp. pV P                  4        F?  pW‚8X  d   K  \        W…W6R7      p	V	f   K  VP                  W‰^ ,          V	^,          34       KA  	  V# )	uî  ``(key, chat_type, tail)`` for every OTHER running turn in the caller's chat (``tail`` is
the key text after the chat id, ``""`` when the key ends there).

The namespace comes from ``own_key`` â€” the session store's own answer, so a named-profile
stop matches that profile's runs and never a literal. ``_snapshot_running_agents`` already
drops the pending sentinel (a session still being set up has no agent). Callers gate on
authorization; ``own_key`` is excluded. Both tiers share one call.
r=   Nr1   r@  r2   :Nr   Nr>   )r<   r=   r>   )r   re   rA   r´   r   ÚWHATSAPPr   rß  r"   r¹   Ú_snapshot_running_agentsrF   rg   )
rQ   r°   r¤  r=   Ú	namespacer<   r>   Úrunsr(   Úparseds
   &&&       r   Ú_same_chat_runsÚ'GatewayBusySessionMixin._same_chat_runst  s
  € ô ”g˜f i°Ó6×<Ð<¸"Ó=ˆßØˆIØ×Ñ˜tÔ#¨¯©¼8×;LÑ;LÔ(Lô 4°GÓ<×GÐGÀˆGØ—H‘H˜WŸ]™]¨3°Ó2°2Õ6Ó7ˆ	Ø�;˜a §¡× 5Ñ 5Ð6°aÐ8ˆÜ”w˜v z°4Ó8×>Ð>¸BÓ?×GÐGÀ4ˆØˆØ×0Ñ0Ö2ˆCØŒ~ÙÜ)¨#ÀgÔaˆFØÔ!Ø—‘˜S¨¥)¨V°A­YÐ7Ö8ñ 3ð ˆr   c               ó$   € V ^8„  d   QhRRRRRR/# ©r   r°   r   rª  r¥  r   z	list[str]r   )r   s   "r   r   rK   �  s$   € ÷ 
ñ 
Ø#ð
Ø+Eð
à	ñ
r   c           	     ó
  € \        \        VRR4      ;'       g    R4      p\        VRR4      ;'       g    RpV'       d	   V'       g   . # V UUUu. uF#  w  rVpWd8X  g   K  \        Ws4      '       g   K!  VNK%  	  uppp# u upppi )zëKeys from ``runs`` belonging to OTHER participants in the caller's own thread (per-user
thread mode keys are ``...:{thread_id}:{user_id}``, so another user's run is invisible to the
caller's own ``/stop``). Callers still gate on authz.r/  Nr1   rA   ©r   re   r:   )rQ   r°   rª  r/  rA   r(   Úkey_chat_typer7   s   &&&     r   Ú_sibling_thread_run_keysÚ0GatewayBusySessionMixin._sibling_thread_run_keys�  s€   € ô œ ¨°TÓ:×@Ð@¸bÓAˆ	Ü˜F K°Ó6×<Ð<¸"ˆ	ß§	ØˆIñ -1õ
á,0Ñ(� DØÑ)ô ä.<¸T×.M÷ ˆCÙ,0ó
ð 	
ùô 
s   ÁA>Á A>Á3A>c               ó$   € V ^8„  d   QhRRRRRR/# r¯  r   )r   s   "r   r   rK      s$   € ÷ 
ñ 
Ø#ð
Ø+Eð
à	ñ
r   c           	     óÈ   € \        \        VRR4      ;'       g    R4      pV UUUu. uF+  w  rEpV'       d   V'       d   \        Wc4      '       g   K)  VNK-  	  uppp# u upppi )u3  Keys from ``runs`` for ANY session of the same chat, whatever the chat_type/thread/
participant slots. Two supported shapes make a /stop key miss a run in the same chat (found
via Slack's native stop button, gateway-gateway#286): a top-level channel turn keys
``channel`` while an in-thread /stop normalizes to ``thread``, and rolling-DM configs key
without the thread slot the stop carries. "/stop" means "stop what's running in THIS chat",
which is also what lets a human stop a peer's per-sender group run (see ``_same_chat_runs``).

A stop sent from INSIDE a thread only reaches runs whose own thread slot is that thread (or
that carry no thread slot at all â€” the rolling-DM shape). Anything else in the channel is a
different conversation: another reply thread, or a peer's top-level run. Callers gate on
authz.
r/  Nr1   r±  )rQ   r°   rª  r/  r(   Ú_key_chat_typer7   s   &&&    r   Ú_chat_scoped_run_keysÚ-GatewayBusySessionMixin._chat_scoped_run_keys   sY   € ô œ ¨°TÓ:×@Ð@¸bÓAˆ	ñ .2õ
á-1Ñ)� Tß§D¬N¸4×,K÷ ˆCÙ-1ó
ð 	
ùô 
s   §A¿AÁAc               ó    € V ^8„  d   QhRRRR/# )r   rú   r	   r   r8   r   )r   s   "r   r   rK   ¶  s   € ÷ 5añ 5a°,ð 5aÀ4ñ 5ar   c                óŠ  € ^ RI Hp Ve   VP                  e   VP                  f   R#  VP                  P                  P
                  R8w  d   R#   TR,          pTP                  4       '       gK   \        T RR4      '       d6   \        P                  ! 4       \        T RR4      ,
          ^<8  d
   RT n
        R# R# \        P                  ! TP                  R	R
7      4      pTP                  R4      pTP                  R4      R8w  g(   \        T\         4      '       d   TP                  T8”  d   R# \        T RR4      '       d
   RT n
        R# TP                  R4      p\        T\         \"        34      ;'       d     \        P                  ! 4       T,
          R8„  '       * #   \         d     R# i ; i  \         d     R# i ; i)aM  True if this /restart is a Telegram re-delivery we already handled.

The previous gateway wrote ``.restart_last_processed.json`` (platform + update_id). A
/restart with update_id <= that value is a redelivery when this process booted from that
restart; otherwise the marker must be < 5 minutes old. Telegram only (numeric ordering).
)rÑ  FÚtelegramz.restart_last_processed.jsonÚ_booted_from_restartÚ_startup_timeg        Tz	utf-8-sig)ÚencodingÚ	update_idr´   Úrequested_ati,  )rÄ   rÑ  r°   Úplatform_update_idr´   r¹   r…   Úexistsre   rú  r½  r2  ÚloadsÚ	read_textr‚   r€   rw   rÌ  )rQ   rú   rÑ  Úmarker_pathÚdataÚrecorded_uidrÁ  s   &&     r   Ú_is_stale_restart_redeliveryÚ4GatewayBusySessionMixin._is_stale_restart_redelivery¶  s€  € õ 	-ØŠ=˜EŸL™LÒ0°E×4LÑ4LÒ4TÙð	Ø�|‰|×$Ñ$×*Ñ*¨jÔ8Ùð 9ð
	Ø&Ð)GÕGˆKØ×%Ñ%×'Ò'ô ˜DÐ"8¸%×@Ò@ÜŸ	š	›¤g¨d°OÀSÓ&IÕIÈBÔNà05�DÔ-ÙÙÜ—:’:˜k×3Ñ3¸[Ð3ÓIÓJˆDð —x‘x Ó,ˆà�H‰H�ZÓ  JÔ.Ü˜l¬C×0Ò0Ø×'Ñ'¨,Ô6áô �4Ð/°×7Ò7Ø(-ˆDÔ%Ùð —x‘x Ó/ˆÜ˜|¬c´5¨\Ó:×_Ð_¼t¿yºy»{È\Õ?YÐ\_Ñ?_Ô`Ð`øôQ ô 	Úð	ûô* ô 	Úð	ús0   ª%F! ÁF3 Á2AF3 Â<&F3 Æ!F0Æ/F0Æ3GÇGc               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rK   í  s   € ÷ <ñ <°|ð <Èñ <r   c              ƒ  ó  "  € ^ RI Hp  ^ RIHp T! VP	                  4       ;'       g    RP                  4       V! VP                  4      RR7      #   \         d.   p\        P                  RT4       \        RTR7      u R	p?# R	p?ii ; i5i)
zV/suggestions via the shared handler (origin = event source so jobs deliver back here).©Ú_command_origin_for_source)Úhandle_suggestions_commandr1   r³   ©r8  r·   zsuggestions command failed: %szgateway.suggestions.failedrv  N)rÄ   rÎ  Úhermes_cli.suggestions_cmdrÏ  r<  r#   r°   r…   rƒ   r†   r   )rQ   rú   rÎ  rÏ  r’   s   &&   r   Ú_handle_suggestions_commandÚ3GatewayBusySessionMixin._handle_suggestions_commandí  sv   é € å:ð	<ÝMÙ-Ø×'Ñ'Ó)×/Ð/¨R×6Ñ6Ó8Ù1°%·,±,Ó?Èôð øô ô 	<Ü�L‰LÐ9¸1Ô=ÜÐ1¸Ô;Õ;ûð	<üs5   ‚BŠAA ÁBÁB	Á"BÁ>B	Á?BÂB	Â	Bc               ó   € V ^8„  d   QhRR/# r>  r   )r   s   "r   r   rK   ú  s   € ÷ Rñ R°\ñ Rr   c              ƒ  ó4  "  € ^ RI Hp  ^ RIHp T! VP	                  4       ;'       g    RP                  4       V! VP                  4      RR7      #   \         d:   p\        P                  RT4       ^ RIH
p T! \        RTR	7      4      u R
p?# R
p?ii ; i5i)zT/blueprint via the shared handler (origin = event source so jobs deliver back here).rÍ  )Úhandle_blueprint_commandr1   r³   rÐ  zblueprint command failed: %s)ÚBlueprintCommandResultzgateway.blueprint.failedrv  N)rÄ   rÎ  Úhermes_cli.blueprint_cmdrÖ  r<  r#   r°   r…   rƒ   r†   r×  r   )rQ   rú   rÎ  rÖ  r’   r×  s   &&    r   Ú_handle_blueprint_commandÚ1GatewayBusySessionMixin._handle_blueprint_commandú  s�   é € å:ð		RÝIÙ+Ø×'Ñ'Ó)×/Ð/¨R×6Ñ6Ó8Ù1°%·,±,Ó?Èôð øô ô 	RÜ�L‰LÐ7¸Ô;ÝGÙ)¬!Ð,FÈaÔ*PÓQÕQûð	Rüs5   ‚BŠAA ÁBÁBÁ.BÂ
BÂBÂBÂBc          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   rú   r	   r&  r   ÚtitlerØ  r   zstr | EphemeralReply | Noner   )r   s   "r   r   rK     s4   € ÷ 
ñ 
Ø$ð
Ø/2ð
Ø;>ð
ØHKð
à	$ñ
r   c             ƒ  óú  aaa"  € Rp V P                  4       P                  R4      p\        V\        4      '       d   \	        VP                  RR4      4      pT'       g   S! 4       G Rj  x€L
 # T P                  TP                  4      oR TTT3R llpT P                  TP                  P                  4      p	\        RSYIR7      p
T P                  TSY:TR	7      G Rj  x€L
 #   \
         d     Lši ; i L‹ L5i)
u5  Gate a destructive session slash command (/new, /reset, /undo).

``execute()`` (async â†’ str | EphemeralReply) runs immediately when
``approvals.destructive_slash_confirm`` is off; otherwise via ``_request_slash_confirm``:
``once`` runs it, ``always`` persists the opt-out then runs it, ``cancel`` skips it.
TÚ	approvalsÚdestructive_slash_confirmNc               ó   € V ^8„  d   QhRR/# )r   Úchoicer   r   )r   s   "r   r   ÚNGatewayBusySessionMixin._maybe_confirm_destructive_slash.<locals>.__annotate__  s   € ÷ 	ñ 	 cñ 	r   c              “  óP   <"  € \         P                  V SSS4      G R j  x€L
 #  L5i©N)rH   Ú _run_confirmed_destructive_slash)rá  r&  ÚexecuterW   s   &€€€r   Ú_on_confirmÚMGatewayBusySessionMixin._maybe_confirm_destructive_slash.<locals>._on_confirm  s,   øé € ä0×QÑQØ˜ ¨+ó÷ ð ñ ùs   ƒ&Ÿ$ &z"gateway.confirm.destructive_prompt)r&  rØ  r<   )rú   r&  rÜ  rT  Úhandler)Ú_read_user_configr‚   r€   r�   r8   r…   Ú_session_key_for_sourcer°   Ú_typed_command_prefix_forr´   r   Ú_request_slash_confirm)rQ   rú   r&  rÜ  rØ  ræ  Úconfirm_requiredrÞ  rç  Ú_pÚprompt_messagerW   s   &$d$$d     @r   Ú _maybe_confirm_destructive_slashÚ8GatewayBusySessionMixin._maybe_confirm_destructive_slash  sï   úé € ð  Ðð	Ø×.Ñ.Ó0×4Ñ4°[ÓAˆIÜ˜)¤T×*Ò*Ü#'¨	¯©Ð6QÐSWÓ(XÓ#YÐ ÷  Ù ›—?Ð"à×2Ñ2°5·<±<Ó@ˆ÷	ò 	ð ×+Ñ+¨E¯L©L×,AÑ,AÓBˆÜÐ?ÈÐY_ÔkˆØ×0Ñ0Ø °ÐWbð 1ó 
÷ 
ð 	
øô ô 	Ùð	úñ #ñ
ùsN   …C;‰AC& ÁC;Á!
C;Á+C7Á,A5C;Ã!C9Ã"C;Ã&C4Ã1C;Ã3C4Ã4C;Ã9C;c               ó    € V ^8„  d   QhRRRR/# )r   Ú	persistedr8   r   r   r   )r   s   "r   r   rK   *  s   € ÷ zñ z¨Dð z°Sñ zr   c                ó4   € \        V '       d   R4      # R4      # )u  Note appended after an "always" confirm. ``persisted=False``: the user did approve this
run, so the action still goes ahead, but the preference did not stick and the prompt will be
back next time â€” say so rather than promising an opt-out that was never written.z"gateway.confirm.destructive_optoutz.gateway.confirm.destructive_optout_save_failedrÆ  )rô  s   &r   Ú_destructive_optout_noteÚ0GatewayBusySessionMixin._destructive_optout_note)  s   € ô
 ¿Ð5ÓyÐyÐHxÓyÐyr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rá  r   r&  rW   r   )r   s   "r   r   rK   1  s"   € ÷ ñ °sð ÀSð Ð`cñ r   c              ƒ  óÖ  "  € V R8X  d   \        RVR7      # RpV R8X  dP    ^ RIHp \        V! RR4      4      pV'       d   \        P                  RV4       M\        P                  R	V4        V! 4       G Rj  x€L
 pV R8X  d3   \        V\        4      '       d   V\        P                  V4      ,           # V#   \         d!   p\        P                  R
T4        Rp?LpRp?ii ; i Lm5i)uZ   Confirm-callback body: ``cancel`` â†’ message; ``always`` persists the opt-out, then runs.rŠ  zgateway.confirm.cancelledr%  FÚalways)Úsave_config_valuez#approvals.destructive_slash_confirmz8User opted out of destructive slash confirm (session=%s)z[Could not persist destructive_slash_confirm=false (session=%s); config.yaml is not writablez5Failed to persist destructive_slash_confirm=false: %sN)r   Úclirû  r8   rƒ   rk  r„   r…   r€   r   rH   rö  )rá  r&  ræ  rW   rô  rû  rœ   Úresults   &&&&    r   rå  Ú8GatewayBusySessionMixin._run_confirmed_destructive_slash0  sÖ   é € ð �XÔÜÐ0¸'ÔBÐBØˆ	Ø�XÔð]Ý1ô !Ñ!2Ð3XÐZ_Ó!`Óa�	ßÜ—K‘KÐ ZÐ\gÕhä—N‘NðDØEPõñ “y—ˆà�XÔ¤*¨V´S×"9Ò"9ØÔ3×LÑLÈYÓWÕWÐWØˆøô ô ]Ü—‘ÐVÐX[×\Ñ\ûð]úá ùsF   ‚C)¡6B9 ÁC)ÁB9 Á.C)Á9C'Á:?C)Â9C$ÃCÃC)ÃC$Ã$C)c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   rú   r	   r&  r   rÜ  rT  r   r/   r   )r   s   "r   r   rK   K  s4   € ÷ 8ñ 8Ø$ð8Ø/2ð8Ø;>ð8ØILð8à	ñ8r   c          	   ƒ  ó  "  € ^ RI Hp VP                  pV P                  V4      p\	        V RR4      p	V	f   ^ RIp
V
P                  ^4      ;q�n        \        V	4       pVP                  W‹W%4       V P                  V4      pV P                  WpP                  V4      4      pVež    VP                  VP                  W4VW½R7      G Rj  x€L
 pV'       d   \	        VRR4      '       d   R# ^ RIHp \	        VRR4      pV! V4      '       d5   \"        P%                  R	W'P&                  V4       VP)                  V4       R#  V# V#  L{  \*         d-   p\"        P-                  R
Y'P&                  T4        Rp?T# Rp?ii ; i5i)zØAsk the user to confirm a slash command; ``handler(choice)`` runs on "once"/"always"/
"cancel" and its return is sent as a message. Returns None if buttons rendered, else the
text-fallback message (which IS the ack).)Úslash_confirmÚ_slash_confirm_counterN)r=   rÜ  rT  rW   Ú
confirm_idr¸   ÚsuccessF)Údeclined_sendrw  ui   slash-confirm DECLINED by the connector's egress guard for %s on %s â€” suppressing the text fallback: %sz*send_slash_confirm failed for %s on %s: %s)Útoolsr  r°   rë  re   Ú	itertoolsÚcountr  ÚnextÚregisterr	  rL  rJ  Úsend_slash_confirmr=   Úgateway.relay.egressr  rƒ   r„   r´   rˆ  r…   r†   )rQ   rú   r&  rÜ  rT  ré  Ú_slash_confirm_modr°   rW   ÚcounterÚ
_itertoolsr  ra   r¸   Úbutton_resultr  Ú_confirm_errrœ   s   &$$$$$            r   rí  Ú.GatewayBusySessionMixin._request_slash_confirmK  sz  é € õ 	>Ø—‘ˆØ×2Ñ2°6Ó:ˆä˜$Ð 8¸$Ó?ˆØŠ?Û*Ø4>×4DÑ4DÀQÓ4GÐGˆGÔ1Ü˜W›�ˆ
ð 	×#Ñ# K¸WÔNà×,Ñ,¨VÓ4ˆØ×3Ñ3°F×<XÑ<XÐY^Ó<_Ó`ˆàÒðjØ&-×&@Ñ&@Ø"ŸN™N°%ÐVaØ)ð 'Aó '÷ !�÷ !¤W¨]¸IÀu×%MÒ%MÙõ ?ä& }°g¸tÓD�Ù  ×/Ò/Ü—N‘NðSà§¡°,ôð
 '×,Ñ,¨[Ô9Ùð 0ð ˆˆwˆñA!øô: ô jÜ—‘ÐIÈ7×TcÑTcÐeh×iÐiàˆûðjüsU   ‚B#F Â&"E ÃEÃ	E ÃE Ã(F Ã*AE Ä=F ÅE ÅE=Å!E8Å2F Å8E=Å=F c               ó   € V ^8„  d   QhRR/# r  r   )r   s   "r   r   rK   …  s   € ÷ 4ñ 4 >ñ 4r   c                óx   €  ^ RI Hp V! 4       p\        T\        4      '       d   T# / #   \         d    / u # i ; i)zQRaw config.yaml for gate lookups that must see on-disk changes without a restart.)Úload_config)Úhermes_cli.configr  r…   r€   r�   )rQ   r  Úcfgs   &  r   rê  Ú)GatewayBusySessionMixin._read_user_config…  s@   € ð	Ý5Ù“-ˆCô ! ¤d×+Ò+ˆsÐ3°Ð3øô ô 	ØŠIð	ús   ‚) ©9¸9)r½  r  rä  )Úhermes_plugin_idÚhermes_plugin_injectionÚgateway_session_keyÚgateway_session_idÚgateway_session_strictÚgateway_proven_session_idÚnotification_category©rd  r1   ©Údenyr1   ))rd  r   )r"  r!  )rú  )rd  rú  )rä   )rd  rä   )r‹  ÚcontextÚrestartrd  r"  r‰  Úagentsrÿ  ÚbtwÚkanbanÚsubgoalÚ	heartbeatÚbusyÚyoloÚverboseÚfooterr‡  Úcommandsr0  ÚloginÚupdateÚversion)#ÚtopicÚwhoamir´   r9  Ú	reasoningÚmemoryÚskillsÚfastrÞ  Úmodelzcodex-runtimeÚpersonalityÚsuggestionsÚsaveÚretryr  ÚcompressÚusageÚtopupÚinsightsz
reload-mcpzreload-skillsÚbundlesr†   rÜ  r:  ÚsessionsÚbranchÚrollbackÚdiffÚgoalÚloopÚrefineÚreviewÚvoice)Ústartr9  ÚnewrM   rN   ÚegressrF  rG  )NÚ__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rS   r]   rj   rs   rz   rˆ   Ústaticmethodr�   r”   r�   r¤   r­   r»   rË   rÔ   rØ   rð   ré   r  r  r  r;  rC  rM  rU  rX  Ú__annotations__rY  r^  rv  rŽ  rƒ  r…  r‡  r†  r°  rÂ  ÚpropertyrÈ  ré  rí  rý  r	  r  r  r  r  r  r  r  r1  r@  rD  rJ  rT  r[  rl  r|  rƒ  r�  r¡  r¬  r³  r¸  rÉ  rÒ  rÙ  rñ  rö  rå  rí  rê  Ú__static_attributes__)Úks   0r   rH   rH   \   s�  ‡ Ùd÷Fõ
Cõ
	.õð$¸t÷ õ$ðL ôUó ðUõ
õ"	õõ	HõðB ôó ðð" ôó ðõ6Sõ(IðT ôQó ðQðÐõ28õhSõ(
ðT ô
ó ð
ð
Ðin÷ 
õ
=ð :@ÀÐRXÐZfÐ8gÐ#Ð%5ÓgðEPÐ"Ð$Aó Põõ2õh4
ðl ôó ððØhl÷õõ.õõ !ð$ ô.ó ð.õFõP;õbðJ !%Ð&BÀIÐOiÐjÐð€Oð€Nõ
òAõ	Eò@ñ *nó.Ù)m AˆV�A�3�hÐÒÑ)mñ.Ð˜Nó õ">õH8õ"õ
$õ9õ	7õoõ2$IõL-õ-õZõ.õ8
õ 
õ,5aõn<õRõ
ðB ôzó ðzð ôó ðõ48÷t4ñ 4ùò[.s   ÅG0rH   ),rR  Ú
__future__r   ÚloggingÚtypingr   rç   rÇ   r2  r¾  rú  Ú
agent.i18nr   r   Úagent.session_activityr   Úgateway.configr   r  r   Úgateway.platforms.eventr	   r
   r4  r   Úgateway.whatsapp_identityr   r   r   r   r   r   r   rÄ   r   Úgateway.run_turn_runnerr   r+   Ú	getLoggerrƒ   r5   r:   rF   rH   r   r   r   Ú<module>rb     sz   ðñõ #ã Ý  Û Û Û Û 	Û ß *Ý <Ý #Ý 1ß =Ý )Ý Cß :× :çÝ)Ý2õð" 
×	Ò	˜=Ó	)€õ
õ/õ÷,p4ó p4r   