+
    iHàjú
  ã                  óº   a € 0 t $ R t^ RIHt ^ RIt^ RIHtHt ^ RIH	t	 ^ RI
HtHtHt ^ RIHt ]	! RRR7      tR	]R
&   Rt ! R R4      t]R R l4       tR R ltR# )aU  Host-owned cancellation for agents created deep inside synchronous work.

A host that runs a blocking command on a worker thread (Hermes Console) never sees
the ``AIAgent`` a CLI subcommand forks inside it, so it cannot call ``interrupt()``
when the user cancels. The host binds an :class:`InterruptScope` around the work;
every ``run_conversation()`` under that scope registers its agent, and
``scope.cancel()`` hard-interrupts them from any thread. Agents registering after
the cancel are interrupted immediately, so a cancel never loses the race with a
turn that has not started yet (#106179).
)ÚannotationsN)ÚcontextmanagerÚnullcontext)Ú
ContextVar)ÚAnyÚIteratorÚOptional)Úrequest_hard_interruptÚhermes_interrupt_scope)Údefaultz$ContextVar[Optional[InterruptScope]]Ú_ACTIVE_SCOPEzhost cancelled the commandc                  óL   € ] tR t^tR R ltR]/R R llt]R R l4       tRt	R	# )
ÚInterruptScopec               ó   € V ^8„  d   QhRR/# )é   ÚreturnÚNone© )Úformats   "Ú:/home/ubuntu/.hermes/hermes-agent/agent/interrupt_scope.pyÚ__annotate__ÚInterruptScope.__annotate__   s   € ÷ Gñ G˜$ñ Gó    c                	ól   € \         P                  ! 4       V n        . V n        R V n        \
        V n        R # )N)Ú	threadingÚLockÚ_lockÚ_agentsÚreasonÚ_TOOL_REASON_HOST_CANCELLEDÚ_tool_reason)Úselfs   &r   Ú__init__ÚInterruptScope.__init__   s&   € Ü—^’^Ó%ˆŒ
Ø"$ˆŒØ%)ˆŒÜ+FˆÖr   Útool_reasonc               ó$   € V ^8„  d   QhRRRRRR/# )r   r   Ústrr$   zOptional[str]r   r   r   )r   s   "r   r   r   "   s'   € ÷ 
Kñ 
K˜Sð 
K°-ð 
KÐbfñ 
Kr   c               óÔ   € V P                   ;_uu_ 4        Wn        W n        \        V P                  4      pRRR4       X F  p\        WAVR7       K  	  R#   + '       g   i     L(; i)zÛLatch ``reason`` and hard-interrupt every agent running under this scope.

``tool_reason`` names the system issuer; pass ``None`` for a human stop so the turn is
attributed to the user rather than to the host (#112647).N©r$   )r   r   r    Úlistr   r	   )r!   r   r$   ÚagentsÚagents   &&$  r   ÚcancelÚInterruptScope.cancel"   sI   € ð
 �Z�Z‹ZØ ŒKØ +ÔÜ˜$Ÿ,™,Ó'ˆF÷ ó ˆEÜ" 5¸k×Jó ÷	 �Zús   •"AÁA'	c               ó    € V ^8„  d   QhRRRR/# )r   r+   r   r   úIterator[None]r   )r   s   "r   r   r   /   s   € ÷ 
+ñ 
+˜3ð 
+ >ñ 
+r   c           	   #  	ó6  "  € V P                   ;_uu_ 4        V P                  P                  V4       V P                  V P                  r2R R R 4       Xe   \        WXR7        R x € V P                   ;_uu_ 4        V P                  P                  V4       R R R 4       R #   + '       g   i     L`; i  + '       g   i     R # ; i  T P                   ;_uu_ 4        T P                  P                  T4       R R R 4       i   + '       g   i     i ; i; i5i)Nr(   )r   r   Úappendr   r    r	   Úremove)r!   r+   r   r$   s   &&  r   ÚtrackÚInterruptScope.track.   s©   é € à�Z�Z‹ZØ�L‰L×Ñ Ô&Ø"&§+¡+¨t×/@Ñ/@�K÷ ð ÒÜ" 5¸kÕJð	+Ûà——“Ø—‘×#Ñ# EÔ*÷ ‘÷ �Zú÷ —�û�——“Ø—‘×#Ñ# EÔ*÷ ——�ÿsd   ‚D—3B"Á
DÁ$C	 Á(DÁ<B5Â
DÂ"B2	Â-DÂ5C	Ã 	DÃ	DÃD	Ã:	DÄDÄDÄD)r   r   r    r   N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r"   r   r,   r   r3   Ú__static_attributes__r   r   r   r   r      s+   † õGð
KÐB]÷ 
Kð ô
+ó ô
+r   r   c               ó    € V ^8„  d   QhRRRR/# )r   ÚscopezOptional[InterruptScope]r   r/   r   )r   s   "r   r   r   =   s   € ÷ #ñ #Ð 8ð #¸^ñ #r   c              #  ó    "  € \         P                  V 4      p Rx € \         P                  V4       R#   \         P                  T4       i ; i5i)zEMake ``scope`` the owner of every agent turn started in this context.N)r   ÚsetÚreset)r;   Útokens   & r   Úbind_interrupt_scoper@   <   s;   é € ô ×Ñ˜eÓ$€Eð#Ûä×Ñ˜EÖ"øŒ×Ñ˜EÕ"üs   ‚A™4 �A´AÁAc               ó   € V ^8„  d   QhRR/# )r   r+   r   r   )r   s   "r   r   r   F   s   € ÷ Bñ B Cñ Br   c                óh   € \         P                  4       pVf   \        4       # VP                  V 4      # )zYRegister ``agent`` with the bound scope for the duration of its turn (no-op without one).)r   Úgetr   r3   )r+   r;   s   & r   Útrack_in_interrupt_scoperD   F   s*   € ä×ÑÓ€EØ!šMŒ;‹=ÐA¨u¯{©{¸5Ó/AÐAr   )Ú__conditional_annotations__Ú__doc__Ú
__future__r   r   Ú
contextlibr   r   Úcontextvarsr   Útypingr   r   r   Úagent.interrupt_compatr	   r   Ú__annotations__r   r   r@   rD   )rE   s   @r   Ú<module>rM      sc   øðô	õ #ã ß 2Ý "ß *Ñ *å 9á6@ÐAYÐcgÔ6h€Ð3Ó hð ;Ð ÷+ñ +ðB ô#ó ð#÷Br   