+
    .pÐj,o  ã                  ó  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHtH	t
 ^ RIHtHt ^ RIHtHtHtHt ^ RIHtHt ^ RIHtHt ^ RIHtHtHtHt ^ R	IHtH t H!t!H"t"H#t# ^ R
I$H%t% ^ RI&H't' ]PP                  ! R4      t)] ! R R4      4       t*R R lt+R R lt,R R lt-R R lt.R R lt/RR/R R llt0RRRR /t1R! R" lt2R=R# R$ llt3R% R& lt4R' R( lt5R)R*R+R,R-R.R/R0/t6R1 R2 lt7R3 R4 lt8R5 R6 lt9R7 R8 lt:R9 R: lt;R; R< lt<R# )>uL  Batch execution + background dispatch for delegate_task: ``delegate_task`` builds a ``_Batch``
(children + origin identity) and hands it to ``_run_batch``, which runs it synchronously or as
detached async units â€” one per task ``group`` (ungrouped tasks are a unit each), so a finished
review does not wait for the slowest sibling.)ÚannotationsN)ÚFIRST_COMPLETEDÚwait)Ú	dataclassÚreplace)ÚAnyÚDictÚListÚOptional)Úbegin_delegation_runÚfinish_delegation_unit)Ú_new_delegation_idÚrecord_unit_child)Ú_attach_childÚ_detach_childÚ_fabricated_entryÚ_signal_child_stop)ÚSUBAGENT_FAILURE_STATUSESÚ_print_completion_lineÚ_quietÚdescribe_subagent_failureÚformat_batch_tag)Ú _capture_gateway_steer_authority)Ú_finalize_child_resultsztools.delegate_toolc                  óþ   € ] tR t^t$ RtR]R&   R]R&   R]R&   R]R	&   R
]R&   R]R&   R]R&   R
]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   RtR
]R&   RtR
]R&   RtR]R&   R  R! lt	R" R# lt
R$tR# )%Ú_Batchz One delegate_task call's built children plus everything needed to run them
and assemble the combined result (shared by the sync path and the background runner).zlist[dict[str, Any]]Ú	task_listzlist[tuple]Úchildrenr   Úparent_agentúdict[str, Any]ÚcredsúOptional[str]ÚcontextÚstrÚtop_roleÚintÚmax_childrenÚlive_deleg_idÚlistÚlive_writersÚ
live_pathsÚorigin_wake_sidÚorigin_ui_session_idÚorigin_owner_transportÚorigin_owner_session_recordÚboolÚorigin_session_history_deliveryÚfloatÚoverall_startNÚgroupÚunit_idÚ	live_homec               ó   € V ^8„  d   QhRR/# )é   Úreturnr   © )Úformats   "Ú+/opt/hermes/tools/delegate_tool_dispatch.pyÚ__annotate__Ú_Batch.__annotate__6   s   € ÷ 
ñ 
˜nñ 
ó    c                ób   € RV P                   ;'       g    RRV P                  RV P                  /# )zKSteer/stop authority of the originating session, passed to every child run.Úowner_session_idNÚowner_transportÚowner_session_record)r,   r-   r.   )Úselfs   &r;   Úowner_kwargsÚ_Batch.owner_kwargs6   s8   € ð  × 9Ñ 9× AÐ A¸TÐCTÐVZ×VqÑVqØ" D×$DÑ$Dð
ð 	
r>   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r7   Úir%   Útaskr   Úchildr   r8   r9   )r:   s   "r;   r<   r=   =   s.   € ÷ Fñ F˜3ð F nð F¸Sð FÀ^ñ Fr>   c                	ól   € ^ RI Hp V! RRVRVR,          RVRV P                  /V P                  4       B # )é    )Ú_run_single_childÚ
task_indexÚgoalrI   r   r9   )Útools.delegate_toolrL   r   rD   )rC   rG   rH   rI   rL   s   &&&& r;   Ú	run_childÚ_Batch.run_child=   s]   € Ý9Ù ñ  F¨Að  F°D¸µLð  FÈð  FÐ\`×\mÑ\mð  FÐqu÷  rCñ  rCó  rEñ  Fð  	Fr>   r9   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r3   r4   r5   rD   rP   Ú__static_attributes__r9   r>   r;   r   r      s˜   ‡ ñ]ð $Ó#ØÓØÓØÓØÓØƒMØÓØ Ó ØÓØÓØÓØÓØÓØ!$Ó$Ø%)Ó)ØÓà€Eˆ=ÓØ!€Gˆ]Ó!Ø€IˆsÓõ
÷Fñ Fr>   r   c               ó$   € V ^8„  d   QhRRRRRR/# )r7   Ún_tasksr%   r'   r!   r8   ÚNoner9   )r:   s   "r;   r<   r<   B   s'   € ÷ xñ x¨3ð x¸}ð xÐQUñ xr>   c                ó‚   € V^8”  d8   V'       d.   R\        W 4       RV R2p\        V \        V RR4      W3R7       R# R# R# )zPAnnounce the batch tag once so interleaved ``[tag n/N]`` lines are attributable.u     ðŸ”€ [z] delegating z tasksÚ_delegate_spinnerN)Úconsole_line)r   r   Úgetattr)r   rZ   r'   Ú_hdrs   &&& r;   Ú_announce_batchra   B   sH   € à�„{—}ØÔ*¨=ÓGÐHÈÐV]ÐU^Ð^dÐeˆÜ˜|¬W°\ÐCVÐX\Ó-]Ð_c×wñ %�{r>   c               ó   € V ^8„  d   QhRR/# )r7   r8   ztuple[str, str, Any, Any, bool]r9   )r:   s   "r;   r<   r<   H   s   € ÷ Qñ QÐ8ñ Qr>   c                 óÔ   € ^ RI Hp  V ! 4       pRpRp\        R4      ;_uu_ 4        ^ RIHpHp V! RR4      pV! 4       pRRR4       W.\        V4      OVN5#   + '       g   i     L!; i)uì  ``(wake_sid, ui_session_id, owner_transport, owner_session_record, session_history_delivery)`` of the
ORIGINATING session, captured BEFORE building any child: AIAgent construction
clobbers the HERMES_SESSION_ID ContextVar/os.environ with the subagent's id.  The wake-
capability flag rides the same request-scoped binding and is captured here for the same
reason â€” and fails closed: a binding that never declared it (or a read error) leaves the
session treated as non-wake-capable (#98619).)Ú_current_origin_session_idÚ FN)Úget_session_envÚ"session_history_delivery_supportedÚHERMES_UI_SESSION_ID)Útools.async_delegationrd   r   Úgateway.session_contextrf   rg   r   )rd   Ú_origin_wake_sidÚ_origin_ui_session_idÚ _origin_session_history_deliveryrf   rg   s         r;   Ú_capture_originrn   H   sz   € õ BÙ1Ó3ÐØÐØ',Ð$Ü	���ß_Ù /Ð0FÈÓ KÐÙ+MÓ+OÐ(÷ 
ð ð  QÔ6VÐWlÓ6mð  Qð  pPñ  Qð  Q÷	 
�ús   ¥AÁA'	c               ó   € V ^8„  d   QhRR/# )r7   r8   r[   r9   )r:   s   "r;   r<   r<   Y   s   € ÷ Hñ HÐbfñ Hr>   c           
     ó,  € VR,          pV\        V4      8  d	   WG,          MRV 2pVP                  RR4      p	V'       d   V RV^,            RV 2MV^,            RV 2p
VP                  R4      RJ ;'       d    V	R	8H  pV'       d   R
M
V	R	8X  d   RMRpV RV
 RV RVP                  R^ 4       R2pV	\        9   d-   \        VP                  R4      VP                  R4      ^xR7      MRpV'       d   RpV'       d   VRV 2,          p\	        WV4       V'       dc   V^ 8”  dZ   \        R4      ;_uu_ 4        TP                  RV'       d   RV,           R,           MR T RV^8w  d   RMR R24       RRR4       R# R# R#   + '       g   i     R# ; i)u³   Print one completion line for a finished child and refresh the spinner text. Failed/errored/timed-out children
say WHY on the same line â€” a bare âœ— reads as "silently dropped".rM   zTask ÚstatusÚ?u    Â· Ú/Úschema_validFÚ	completedu   âš u   âœ“u   âœ—z [z] z  (Úduration_secondszs)Úfailure_reasonÚerror)Ú	max_charsre   uF   output_schema not satisfied â€” raw text returned (schema_valid=false)u    â€” zSpinner update_text failed: %su   ðŸ”€ Ú[z taskÚsz
 remainingN)ÚlenÚgetr   r   r   r   Úupdate_text)r   Úspinner_refÚentryÚtagÚtask_labelsrZ   Ú	remainingÚidxÚlabelrq   Ú_slotÚschema_invalidÚiconÚcompletion_lineÚ	_err_lines   &&&&&&&        r;   Ú_report_child_doner‹   Y   sš  € ð �Õ
€CØ #¤c¨+Ó&6Ô 6ˆKÖ¸eÀCÀ5¸M€EØ�Y‰Y�x Ó%€Fß-0ˆsˆe�4˜˜A��w˜a ˜yÑ)¸¸Q½¸¸qÀÀ	Ð6J€EØ—Y‘Y˜~Ó.°%Ð7×QÐQ¸FÀkÑ<Q€Nß"‰5°&¸KÔ2G©ÈU€DØ˜˜b   r¨%¨°°E·I±IÐ>PÐRSÓ4TÐ3UÐUWÐX€Oð Ô.Ô.ô 	" %§)¡)Ð,<Ó"=¸u¿y¹yÈÓ?QÐ]`ÕaØ46ð ÷ Ø\ˆ	ßØ˜U 9 +Ð.Õ.ˆÜ˜<°oÔFß�y 1”}ÜÐ4×5Õ5Ø×#Ñ# eÇ¨C°#­I¸Ö,<ÈÐ+LÈYÈKÐW\ÐdmÐqrÔdrÑ]`ÐxzÐ\{ð  |Fð  %Gô  H÷ 6Ñ5ñ %�{ß5×5Ð5ús   Ä8<FÆF	c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r7   Úbatchr   r€   r   Úhonor_parent_interruptr/   r8   r[   r9   )r:   s   "r;   r<   r<   o   s)   € ÷ 0ñ 0 &ð 0°ð 0Èdð 0ÐW[ñ 0r>   c                óž   € V'       gE   V P                   '       d1   \        V\        4      '       d   \        V P                   V4       R# R# R# R# )uƒ  Detached (background) unit: durably record a child on the unit's own row the moment it finishes, so an owner
death before the unit's join â€” or anywhere before its durable completion write, the whole remaining window for a
one-child unit â€” loses only children still running, never finished work (#116000). Best-effort by construction:
``record_unit_child`` never raises into the join.N)r4   Ú
isinstanceÚdictr   )r�   r€   rŽ   s   &&&r;   Ú_record_finished_childr’   o   s4   € ÷
 " e§m§m m¼
À5Ì$×8OÒ8OÜ˜%Ÿ-™-¨Ö/ñ 9P¡mÑ!r>   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r7   r�   r   Úresultsr(   rŽ   r/   r8   r[   r9   )r:   s   "r;   r<   r<   w   s*   € ÷ =0ñ =0 &ð =0°4ð =0ÐTXð =0Ð]añ =0r>   c               ó”  aaa€ ^ RI Hp V P                  \        V P                  4      rTV P                   Uu. uF  qfR,          R,          NK  	  pp\        VRR4      p\        V P                  V4      p	V P                   U
UUu/ uF  w  r«qÊVbK
  	  uppp
o\        V P                  4      pV3R loV! V P                  R7      pRp V P                   U
UUu/ uFA  w  r¦qÎP                  \        P                  ! 4       P                  V P                  W¦V4      V
bKC  	  uppp
o\        S4      pV'       Ed    V'       d2   \        VR	R4      R
J d!   VP!                  VV3R lV 4       4       R
pEMf\#        VR\$        R7      w  ppV EFG  pS! VSV,          4      pVP'                  V4       \)        V VV4       \+        WHVW—W]\        V4      ,
          4       V'       d   KZ  V P,                  '       g   Kn  VP/                  R4      \0        9   g   KŠ  \        V4      V8  g   Kœ  \3        RR
R7      ;_uu_ 4        ^ RIHp VP/                  RR4      p\9        V\:        4      '       d9   ^ Tu;8:  d   \        V P<                  4      8  d   M MV P<                  V,          MRpT! V P,                  / VCV'       d   RV/M/ CVR7       RRR4       EKJ  	  EK¨  VP?                  V'       * VR7       VPA                  R R7       R# u upi u uppp
i u uppp
i   + '       g   i     EK¡  ; i  TP?                  T'       * TR7       i ; i)a¤  Run the batch's children in parallel, appending entries to ``results`` (sorted by task_index on return, one
completion line printed per child). Polls futures with a short ``wait()`` timeout instead of ``as_completed()``
so a wedged child cannot block the parent forever after an interrupt; on parent interrupt the still-pending
children are reported ``interrupted`` and abandoned (they already got the interrupt signal).)ÚDaemonThreadPoolExecutorrN   :Né(   Nr]   Nc           	     ó  <€ V P                  4       '       g   \        VR RSP                  V4      4      #  V P                  4       #   \         d1   p\        TR\        T4      SP                  T4      4      u Rp?# Rp?ii ; i)Úinterruptedu9   Parent agent interrupted â€” child did not finish in timerx   N)Údoner   r}   ÚresultÚ	Exceptionr#   )Úfuturer„   ÚexcÚ_child_by_indexs   && €r;   Ú	_entry_ofÚ)_run_children_parallel.<locals>._entry_of‡   sw   ø€ Ø�{‰{�}Š}Ü$Ø�]Ð$_Ðap×atÑatÐuxÓayóð ð	WØ—=‘=“?Ð"øÜô 	WÜ$ S¨'´3°s³8¸_×=PÑ=PÐQTÓ=UÓVÕVûð	Wús   ¶A ÁBÁ%A<Á6BÁ<B)Úmax_workersFÚ_interrupt_requestedTc              3  óD   <"  € T F  pS! VSV,          4      x € K  	  R # 5i©Nr9   )Ú.0Úfr    Úfuturess   & €€r;   Ú	<genexpr>Ú)_run_children_parallel.<locals>.<genexpr>œ   s   øé € ÐIÁ¸A™y¨¨G°A­J×7Ð7Ãùs   ƒ g      à?)ÚtimeoutÚreturn_whenrq   ztask failure notice failed©Úexc_info)Úpush_task_failure_noticerM   Úlive_transcript)rZ   )r   Úcancel_futuresc                ó   € V R ,          # )rM   r9   )Úrs   &r;   Ú<lambda>Ú(_run_children_parallel.<locals>.<lambda>´   s   € ˜q žr>   )Úkeyéÿÿÿÿ)!Útools.daemon_poolr–   r   r|   r   r_   r   r'   r   r&   ÚsubmitÚcontextvarsÚcopy_contextÚrunrP   ÚsetÚextendÚ_cf_waitr   Úappendr’   r‹   r4   r}   r   r   ri   r¯   r�   r%   r*   ÚshutdownÚsort)r�   r”   rŽ   r–   r   rZ   Útr‚   r   Ú_tagrG   Ú_rI   Ún_hereÚexecutorr™   Úpendingrš   r�   r€   r¯   Ú_iÚ_liverŸ   r    r¨   s   &&$                    @@@r;   Ú_run_children_parallelrË   w   sÉ  ú€ õ ;Ø!×.Ñ.´°E·O±OÓ0D�'Ø+0¯?ª?Ó;©? a�V•9˜S—>�>©?€KÐ;Ü˜,Ð(;¸TÓB€KÜ˜E×/Ñ/°Ó>€Dà5:·^²^ÕD±^¡M Q¨5˜%’x±^ÓD€OÜ�—‘Ó €FõWñ (°E×4FÑ4FÔG€Hð
 €KðLØw|÷  xFò  xFõ  Gñ  xFÑhsÐhiÐns—?‘?¤;×#;Ò#;Ó#=×#AÑ#AÀ5Ç?Á?ÐTUÐZ_Ó`ÐbcÒcñ  xFó  GˆÜ�g“,ˆßˆgß%¬'°,Ð@VÐX]Ó*^ÐbfÓ*fØ—‘ÕIÁÓIÔIØ"�ÙÜ$ W°cÄÔW‰MˆD�'Ü�Ù! &¨'°&­/Ó:�Ø—‘˜uÔ%ä& u¨eÐ5KÔLÜ" <¸eÀTÐX_ÔjmÐnuÓjvÕavÔwß.Ñ.°5·=·=²=ÀUÇYÁYÈxÓEXÔ\uÖEuÜ ›L¨6Ö1ô  Ð <Àt×LÖLÝSØ"ŸY™Y |°RÓ8˜Ü8BÀ2Äs×8KÒ8KÐPQÐUWÖPoÔZ]Ð^c×^nÑ^nÓZo×Po × 0Ñ 0°Ö 4Ðuy˜Ù0Ø!ŸM™MÐ+e¨eÐ+e×V[Ð9JÈEÑ8RÐacÐ+eÐovõx÷	 MÒLô ð& 	×Ñ ;œ¸{ÐÔKØ‡L�LÑ.€LÖ/ùòi <ùô Eùô( G÷$ M×LÑLûð 	×Ñ ;œ¸{ÐÕKúsn   ¸LÂL
Ã	L- ÃALÄ L- Ä9L- ÅBL- Ç#L- Ç7L- ÈL- È%L- È:B LÊ;LËL- ÌL- ÌL*Ì#
L- Ì-MrŽ   Tc               ó$   € V ^8„  d   QhRRRRRR/# )r7   r�   r   rŽ   r/   r8   r‘   r9   )r:   s   "r;   r<   r<   ¶   s"   € ÷ &ñ & &ð &ÀTð &ÐUYñ &r>   c               óz  € ^ RI Hp . p\        V P                  4      ^8X  dE   VP	                  V P
                  ! V P                  ^ ,          !  4       \        WR,          V4       M\        WVR7       \        W0P                  V P                  V P                  4       \        \        P                  ! 4       V P                  ,
          ^4      pV FÞ  pVP                  RR4      p\!        V\"        4      '       g   K-  ^ Tu;8:  d   \        V P$                  4      8  g   KQ  M KU  V P$                  V,          f   Kl  \'        RRR7      ;_uu_ 4        V P$                  V,          P)                  V4       RRR4       V\        V P*                  4      8  g   KÈ  V P*                  V,          VR&   Kà  	  V! V P,                  W0P.                  R	7       \1        V P                  W1'       * R
7       RVRV/p^ RIHp V UU	u. uF  qX! V4       F  q™NK  	  K  	  p
pp	V
'       d   W§R&   V P                   UUu. uF5  w  p qË\        V P*                  4      8  g   K"  V P*                  V,          NK7  	  pppV'       d   W×R&   V P6                  e   V P6                  VR&   V#   + '       g   i     EL1; iu up	pi u uppi )a€  Run the batch's built children, join, finalize (hooks + cost rollup), return the combined dict. Shared by the
sync path and the background runner; a background runner receives a per-group unit (a subset of the call's
children) so each group JOINS only on itself. Live transcripts are finalized but retained as the full-fidelity
record (retention pruning happens on future dispatches).)Úupdate_manifest_statuses©rŽ   rM   NzLive transcript finalize failedTr­   r°   )Úhome)Ú
backgroundr”   Útotal_duration_seconds)Ú_process_accounting_linesÚprocess_notesÚlive_transcriptsr3   r·   )Útools.delegation_live_logrÎ   r|   r   rÀ   rP   r’   rË   r   r   r   ÚroundÚtimeÚ	monotonicr2   r}   r�   r%   r)   r   Úfinalizer*   r'   r5   r   Ú$tools.process_registry_notificationsrÓ   r3   )r�   rŽ   rÎ   r”   Útotal_durationr€   Ú_idxÚcombinedrÓ   ÚlinerÔ   rG   rÅ   Ú
unit_pathss   &$            r;   Ú_execute_and_aggregaterá   ¶   s!  € õ
 CØ€GÜ
ˆ5�>‰>Ó˜aÔØ�‰�u—’¨¯©°qÕ(9Ñ:Ô;ô 	˜u¨b¥kÐ3IÕJä˜uÐF\Õ]ä˜G§_¡_°e·n±nÀe×FXÑFXÔYÜœ4Ÿ>š>Ó+¨e×.AÑ.AÕAÀ1ÓE€NÛˆØ�y‰y˜ rÓ*ˆÜ�dœC× Ô  Q¨$Ö%H´°U×5GÑ5GÓ1H×%HÒ%HÈU×M_ÑM_Ð`dÕMeÔMqÜÐ9ÀD×IÖIØ×"Ñ" 4Õ(×1Ñ1°%Ô8÷ Jà”c˜%×*Ñ*Ó+Ö+Ø+0×+;Ñ+;¸DÕ+A�Ð'Ó(ñ ñ ˜U×0Ñ0°'ÇÁÕPÜ˜5Ÿ?™?¨GÔ@ZÕ[à )¨7Ð4LÈnÐ]€HåNÙ'.Ô\¡w˜eÐ;TÐUZÖ;[°4’TÑ;[‘T¡w€MÑ\ßØ$1�Ñ!Ø7<·~²~Ôc±~©)¨1¨a°ÌSÐQV×QaÑQaÓMbÑIbÔ%�%×"Ñ" 1×%Ð%±~€JÑcßØ'1Ð#Ñ$Ø‡{�{ÒØ!ŸK™Kˆ�ÑØ€O÷% J×IÐIüó ]ùó ds   Å#JÇ>J1È4J7ÉJ7ÊJ.Úno_asyncu8  background=true is not available in this session â€” it cannot receive a detached subagent result after the turn ends (a finite chat using -Q, --oneshot, or non-TTY stdio, `hermes -z`, a cron job, a Kanban worker, or a stateless HTTP endpoint). The subagent(s) ran SYNCHRONOUSLY and the result is included above.Úat_capacitya  The background delegation pool was at capacity (delegation.max_concurrent_children), so the subagent(s) ran SYNCHRONOUSLY and the result is included above. Raise delegation.max_concurrent_children in config.yaml to allow more concurrent background delegations.c               ó$   € V ^8„  d   QhRRRRRR/# )r7   r�   r   Úreasonr#   r8   r9   )r:   s   "r;   r<   r<   ì   s!   € ÷ 2ñ 2˜vð 2¨sð 2°sñ 2r>   c                ó”   € \        V 4      p\        V\        4      '       d   \        V,          VR&   \        P
                  ! VRR7      # )zGInline fallback: run the batch now and explain why it was not detached.ÚnoteF©Úensure_ascii)rá   r�   r‘   Ú_SYNC_FALLBACK_NOTESÚjsonÚdumps)r�   rå   r›   s   && r;   Ú_run_sync_with_noterí   ì   s8   € ä# EÓ*€FÜ�&œ$×ÒÜ-¨fÕ5ˆˆv‰Ü�:Š:�f¨5Ô1Ð1r>   c               ó$   € V ^8„  d   QhRRRRRR/# )r7   r+   r#   r0   r/   r8   r!   r9   )r:   s   "r;   r<   r<   ó   s#   € ÷ "ñ "¨Sð "ÐSWð "Ðdqñ "r>   c                ó  € ^ RI Hp V! R4      R8X  d   R#  ^ RI Hp V! 4       '       d   R#  T '       d!   T'       d   \        P                  RT 4       T # T '       d   \        P                  RT 4       R#   \         d     R# i ; i)	zëDetached result target: empty for push, a resumable API id, or None for inline.

API completion only persists a row; this does not authorize a model wake. The
continuation must read that row, not an authoritative caller-owned snapshot.©rf   ÚHERMES_SINGLE_QUERY_SESSIONÚ1N)Úasync_delivery_supportedre   u€   delegate_task: session %s resumes server history â€” detached result will be persisted for the next client turn (no model wake).u‰   delegate_task: session %s has no declared server-history consumer â€” running the batch synchronously so the result returns in this turn.)rj   rf   ró   rœ   ÚloggerÚinfo)r+   r0   rf   ró   s   &&  r;   Ú_resolve_async_wake_sidrö   ó   s‹   € õ
 8ñ
 Ð4Ó5¸Ô<Ùð	õ
 	EÙ#×%Ò%Ùð &÷ ×:Ü�‰ð8Ø9Hô	
ð ÐßÜ�‰ð@ØAPô	
ñ øô ô Úðús   —A5 Á5BÂBc               ó$   € V ^8„  d   QhRRRRRR/# )r7   r   r   r,   r#   r8   ztuple[str, str]r9   )r:   s   "r;   r<   r<     s'   € ÷ Añ A¨Sð AÈð AÐP_ñ Ar>   c                ó@  € ^ RI Hp V! RR7      p\        \        V RR4      ;'       g    R4      p\	        R4      ;_uu_ 4        ^ RIHp V! RR4      pV! RR4      ;'       g    TpVR	8X  d   V'       d   TpRRR4       T;'       g    TV3#   + '       g   i     L; i)
uC  ``(session_key, origin_ui_session_id)`` the async registry routes completions by.

Desktop/TUI: the routable key is the durable AIAgent.session_id â€” compression can rotate it mid-turn before the
TUI-side dict is re-anchored, and a stale approval-context key would orphan the completion. Gateway chats keep the
platform conversation key (agent:main:...). The CLI has no bound approval contextvar and no HERMES_SESSION_KEY, so
the key resolves empty; its drain is a positive-ownership filter on the durable session_id (empty would fail
closed), so stamp the parent's durable id.
)Úget_current_session_keyre   )ÚdefaultÚ
session_idNrð   ÚHERMES_SESSION_SOURCErh   Útui)Útools.approval_contextrù   r#   r_   r   rj   rf   )r   r,   rù   Úsession_keyÚagent_session_idrf   Úsources   &&     r;   Ú_resolve_async_session_keyr    s’   € õ ?Ù)°"Ô5€KÜœ7 <°¸rÓB×HÐHÀbÓIÐÜ	���Ý;Ù Ð!8¸"Ó=ˆñ  /Ð/EÀrÓJ×bÐbÐNbÐØ�UŒ?×/Ø*ˆK÷ 
ð ×*Ð*Ð*Ð,@Ð@Ð@÷ 
�ús   Á1BÁ5BÂB	c               ó    € V ^8„  d   QhRRRR/# )r7   Úchild_agentsz	list[Any]r8   Útupler9   )r:   s   "r;   r<   r<   -  s   € ÷ !ñ !¨	ð !°eñ !r>   c                óN  € . pRpV  Fl  p VP                  4       pVP                  R4      pVP                  VP                  R^ 4      WTP                  R4      34       T;'       g    \        V4      pKn  	  \        V4      V3#   \         d    TP                  R4        Kœ  i ; i)aÂ  Progress token for the async registry's stale monitor: every child's (api_call_count, current_tool,
last_activity_ts). last_activity_ts ticks on streamed chunks, tool transitions and API-call start/completion,
so a child streaming a long response counts as alive; a fully frozen token past the threshold means the batch
is wedged. ``in_tool`` is True while ANY child is inside a tool so slow tools get the higher ceiling (mirrors
the sync heartbeat).FÚcurrent_toolÚapi_call_countÚlast_activity_tsN)Úget_activity_summaryr}   rÀ   r/   rœ   r  )r  ÚpartsÚin_toolÚcÚsummaryÚtools   &     r;   Ú_batch_progress_tokenr  -  sŸ   € ð €EØ€GÛˆð	Ø×,Ñ,Ó.ˆGØ—;‘;˜~Ó.ˆDØ�L‰L˜'Ÿ+™+Ð&6¸Ó:¸DÇ+Á+ÐN`ÓBaÐbÔcØ×+Ð+¤ d£ŠGñ ô �‹<˜Ð Ð øô ô 	Ø�L‰L˜×ð	ús   ‹ABÁ'BÂB$Â#B$Úonea*  Subagent is running in the background; its full result re-enters the conversation as a new message when it finishes. Results are delivered only after you END YOUR TURN: do anything that does not depend on it, then stop with a one-line status. Do not poll its transcript or artifacts to wait for it.Úmanyai  {n} subagents are running in parallel in the background as {k} completion unit(s); each unit's results re-enter the conversation as their own new message when THAT unit finishes. Results are delivered only after you END YOUR TURN: do anything that does not depend on them, then stop with a one-line status. Do not poll transcripts or artifacts to wait for them.Úcontrol_hintzâWhile a child runs you can orchestrate it live with this same tool: delegate_task(action='list') to see live children, action='steer' with subagent_id + message to redirect one, action='stop' with subagent_id to end one early.Úlive_transcripts_hintzÈEach subagent streams a human-readable transcript of its operations to the file listed above (append-only, one per task). Read or `tail -f` these paths at any time to watch a child work while it runs.c               ó$   € V ^8„  d   QhRRRRRR/# )r7   r�   r   Úunitszlist[tuple[_Batch, str]]r8   r‘   r9   )r:   s   "r;   r<   r<   [  s"   € ÷ ñ ˜vð Ð.Fð È4ñ r>   c                ó€  € V P                    Uu. uF  q"R,          NK  	  pp\        V4      pRRRRRTRV P                  ;'       g    V^ ,          ^,          RTR	V^8X  d   \        R
,          M&\        R,          P	                  V\        V4      R7      /p\        V4      ^8”  dM   V UUUU	u. uF6  w  rgRTRVP
                  RVP                   UU	u. uF  w  p q˜NK
  	  up	p/NK8  	  up	pppVR&   V P                   U	U
u. uF  w   rš\        V
RR4      NK  	  pp	p
\        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   WµR&   \        R,          VR&   V P                  '       d)   \        V P                  4      VR&   \        R,          VR&   V# u upi u up	pi u up	pppi u up
p	i )zNModel-facing handle for an accepted background call: one entry per async unit.rN   rq   Ú
dispatchedÚmoderÑ   ÚcountÚdelegation_idÚgoalsrç   r  r  )ÚnÚkr3   Útask_indexesr  Ú_subagent_idNc              3  óV   "  € T F  p\        V\        4      ;'       d    Tx € K!  	  R # 5ir¥   )r�   r#   )r¦   r{   s   & r;   r©   Ú&_dispatched_payload.<locals>.<genexpr>j  s"   é € Ð
2©T¨Œ:�aœÓ×#Ð# !Ô#«Tùs   ‚)ž)TFÚsubagent_idsr  rÕ   r  )r   r|   r'   Ú_BACKGROUND_NOTESr:   r3   r   r_   Úanyr*   r(   )r�   r  rÃ   r  r  ÚpayloadÚunitÚuidrG   rÅ   r  Úsidss   &&          r;   Ú_dispatched_payloadr*  [  sŸ  € à %§¢Ó0¡˜1ˆv�YˆY¡€EÐ0ÜˆE‹
€Aà�, ¨°g¸qØ˜×,Ñ,×;Ð;°°aµ¸µ¸WÀeØ¨A°¬FÔ! %Ö(Ô8IÈ&Õ8Q×8XÑ8XÐ[\Ô`cÐdiÓ`jÐ8XÓ8kð€Gô
 ˆ5ƒz�A„~ñ #ö
á"‘	�ð ˜c 7¨D¯J©J¸Ð\`×\iÒ\iÔHjÑ\iÉyÐPQÐSTÐVWÊÑ\iÒHjÓkÙ"ô
ˆ�Ñð ?D¿nºnÔM¹n±°!°QŒG�A�~ tÖ,¹n€DÑMß
ƒsÑ
2©TÓ
2‡s‡s‚sÑ
2©TÓ
2×2Ò2Ø"&�ÑÜ"3°NÕ"Cˆ�ÑØ××ÐÜ&*¨5×+;Ñ+;Ó&<ˆÐ"Ñ#Ü+<Ð=TÕ+UˆÐ'Ñ(Ø€Nùò' 1ùó Ikùõ
ùó Ns#   �F'Â-%F2
ÃF,Ã 	F2
ÄF:Æ,F2
c               ó    € V ^8„  d   QhRRRR/# )r7   r�   r   r8   zlist[_Batch]r9   )r:   s   "r;   r<   r<   r  s   € ÷ sñ s�Vð s ñ sr>   c           
     óŽ  € ^ RI Hp V! 4       '       g   V .# / pV P                   FR  w  r4pVP                  R4      pVR9  d   R\	        V4      3MRV3pVP                  V. 4      P                  W4V34       KT  	  VP                  4        UUu. uF)  w  rx\        YV^ ,          R8X  d
   V^,          MRR7      NK+  	  upp# u uppi )a  Partition the call's children into async units: one per distinct task ``group`` (first-appearance order) and
one per ungrouped task. Each unit is a ``_Batch`` sharing the call's task_list/transcripts but owning a subset of
``children``, so a unit joins only on itself and its completion re-enters the conversation on its own.

Off by default (``delegation.independent_completions``): the whole call is ONE unit and returns as one message.
A per-task flurry of completions (one new turn each) fragmented orchestrators that had no plan for it.)Ú_get_independent_completionsr3   NÚgrG   )r   r3   )Nre   )	Útools.delegate_tool_configr-  r   r}   r#   Ú
setdefaultrÀ   Úitemsr   )	r�   r-  ÚmembersrG   rÃ   r  r.  r¶   Úchs	   &        r;   Ú	_units_ofr4  r  s·   € õ HÙ'×)Ò)ØˆwˆØ&(€GØ—>”>‰ˆˆaØ�E‰E�'‹NˆØ ¨
Ô2ˆs”C˜“F‰m¸¸a¸ˆØ×Ñ˜3 Ó#×*Ñ*¨A°!¨9Ö5ñ "ð cj×boÑboÔbqÔrÑbqÑW^ÐWZŒG�E¸¸Q½À3¼¨s°1®vÈD×RÑbqÒrÐrùÓrs   Â/Cc          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r7   r'  r   r4   r!   Úslot_keyÚroutingr‘   r8   r9   )r:   s   "r;   r<   r<   ƒ  s1   € ÷ ñ ˜ð ¨-ð À=ð Ð[_ð Ðdhñ r>   c           !     óH  a a
€ ^ RI Hp S P                   UUu. uF  w   rVVNK
  	  uppo
V
3R lpT! RRS P                   Uu. uF  qˆR,          NK  	  upRS P                  RRRS P
                  R	S P                  R	,          R
V 3R lRTRTRTR\        S P                  4      \        S P                  4      8  d"   S P                   U	Uu. uF  w  p	 qYNK
  	  upp	MRRS P                   U	Uu/ uF‹  w  p	 pV	\        S P                  4      8  g   K#  S P                  V	,          f   K:  S P                  V	,          P                  f   K[  \        V	4      \        S P                  V	,          P                  4      bK�  	  upp	RV
3R l/VB # u uppi u upi u upp	i u upp	i )zSHand ONE unit to the async registry; the runner joins on that unit's children only.)Údispatch_async_delegation_batchc                 ó2   <€ S F  p \        V R 4       K  	  R# )zAsync delegation cancelledN)r   )r  r  s    €r;   Ú
_interruptÚ"_dispatch_unit.<locals>._interruptˆ  s   ø€ ÛˆAÜ˜qÐ">Ö?ó r>   r  rN   r"   ÚtoolsetsNÚroleÚmodelÚrunnerc                 ó   <€ \        S R R7      # )FrÏ   )rá   )r'  s   €r;   r´   Ú _dispatch_unit.<locals>.<lambda>‘  s   ø€ Ô-¨dÈ5ÕQr>   Úinterrupt_fnr  r6  r  Útask_transcriptsÚprogress_fnc                 ó   <€ \        S 4      # r¥   )r  )r  s   €r;   r´   rB  ˜  s   ø€ Ô1°,Ô?r>   r9   )ri   r9  r   r   r"   r$   r    r|   r)   Úpathr#   )r'  r4   r6  r7  r9  rÅ   r  r;  rÃ   rG   r  s   f&&&      @r;   Ú_dispatch_unitrH  ƒ  s¼  ù€ åFØ'+§}¢}Ô5¡}™)˜1˜a“A¡}Ò5€Lõ@ñ +ñ à"&§.¢.Ó1¡.˜Q��yˆy¡.Ñ1ðà;?¿<¹<ðð ðð �]‰]ð	ð #'§*¡*¨WÕ"5ð	ô
 Rðð  ðð 07ðð BJðô <?¸t¿}¹}Ó;MÔPSÐTX×TbÑTbÓPcÔ;c¨¯ªÔ7©™I˜Q  1’a©Ó7Ðimðð QU×P]ÒP]ô EÑP]ÁWÀQÈÈ1Ø¤ T×%6Ñ%6Ó!7Ñ7ô AØ<@×<MÑ<MÈaÕ<Pô Aà"×/Ñ/°Õ2×7Ñ7ô Aœ#˜a›&¤# d×&7Ñ&7¸Õ&:×&?Ñ&?Ó"@Ò@ÑP]ò Eðô @ðð DKñð ùó 6ùò 2ùó
 8ùóEs)   ˜FÁFÃF2Ã. F6ÄF6Ä*F6Å4F6c               ó    € V ^8„  d   QhRRRR/# )r7   r'  r   r8   r[   r9   )r:   s   "r;   r<   r<   ›  s   € ÷ 0ñ 0 vð 0°$ñ 0r>   c                ó^   € V P                    F  w   r\        V P                  V4       K  	  R# )z“Rejected children stay owned by the parent: re-attach them (``_attach_child`` replays a stop that
arrived while async admission had them detached).N)r   r   r   )r'  rÅ   rI   s   &  r;   Ú_restore_parent_cancellationrK  ›  s&   € ð —}”}‰ˆˆ1Ü�d×'Ñ'¨Ö/ó %r>   c               ó    € V ^8„  d   QhRRRR/# )r7   r�   r   r8   r#   r9   )r:   s   "r;   r<   r<   ¡  s   € ÷ 23ñ 23 ð 23¨3ñ 23r>   c           
     ó²  € ^ RI Hp \        V P                  V P                  4      pVf"   \
        P                  R4       \        V R4      # V P                  p\        W0P                  4      w  rE\        WEV\        VRR4      V! 4       R7      p\        V 4      p. p. p	Rp
\        V4       EFz  w  r¼\        V4      ^8X  d   V P                   M+V P                   '       d   V P                    RV^,            2MRpT;'       g    \#        4       ;Vn        pVP&                   F  w   rï\)        W?4       K  	  \+        WÍW¦4      pVP-                  R4      R	8X  d0   T
;'       g
    VR
,          p
VP/                  VVR
,          34       KÛ  \1        V4       V'       g5   \
        P                  RVP-                  RR4      4       \        V R4      u # \
        P3                  RV^,           \        V4      VP-                  R4      4       V	P5                  \7        V4      R,          4       EK}  	  \9        W4      pV	'       d   V	VR&   \:        P<                  ! VRR7      # )af  Dispatch the call as independent async units (see ``_units_of``) and return the tool result JSON. Every unit
of one call shares ONE pool slot (``slot_key``), so grouping never changes capacity accounting. Falls back to
running synchronously (with an explanatory ``note``) when the session cannot receive detached completions or the
async pool is at capacity.)Ú_get_max_async_childrenNzkdelegate_task: async delivery unsupported on this session runtime; running the batch synchronously instead.râ   rû   )rÿ   r,   Úorigin_session_idÚparent_session_idÚmax_async_childrenÚ-rq   r  r  zZdelegate_task: async pool at capacity (%s); running the whole batch synchronously instead.rx   Úrejectedrã   z?delegate_task: unit %d/%d not accepted (%s); running it inline.r”   Úinline_resultsFrè   )rO   rN  rö   r+   r0   rô   rõ   rí   r   r  r,   r‘   r_   r4  Ú	enumerater|   r'   r   r4   r   r   rH  r}   rÀ   rK  Úwarningr¾   rá   r*  rë   rì   )r�   rN  Úwake_sidr   rÿ   r,   r7  r  r  rT  r6  r  r'  r4   rÅ   rI   Údispatchr&  s   &                 r;   Ú_dispatch_backgroundrY  ¡  s,  € õ
 <Ü& u×'<Ñ'<¸e×>cÑ>cÓd€HØÒÜ�‰ð  Bô  	CÜ" 5¨*Ó5Ð5à×%Ñ%€LÜ(BÀ<×QkÑQkÓ(lÑ%€KÜØÐ^fÜ! ,°¸dÓCÑXoÓXqô€Gô
 �eÓ€EØ+-€JØ!#€NØ"€HÜ˜U×#‰ˆô *-¨U«°q¬�%×%Ò%Ðch×cv×cvÐcvÀ%×BUÑBUÐAVÐVWÐXYÐ\]ÕX]ÐW^Ñ?_ð  }AˆØ!(×!@Ð!@Ô,>Ó,@Ð@ˆŒ�wð  Ÿ=œ=‰KˆAˆqÜ˜,Ö.ñ )ä! $°ÓCˆØ�<‰<˜Ó! \Ô1Ø×<Ð< 8¨OÕ#<ˆHØ×Ñ˜t X¨oÕ%>Ð?Ô@ÙÜ$ TÔ*ßÜ�K‰KØlØ—‘˜W jÓ1ôô ' u¨mÓ<Ò<ô 	�‰ÐXÐZ[Ð^_ÕZ_ÔadÐejÓakÐmu×myÑmyð  {Bó  nCô  	DØ×ÑÔ4°TÓ:¸9ÕE×Fñ1 $ô2 " %Ó4€GßØ$2ˆÐ Ñ!Ü�:Š:�g¨EÔ2Ð2r>   c               ó$   € V ^8„  d   QhRRRRRR/# )r7   r�   r   rÑ   r/   r8   r#   r9   )r:   s   "r;   r<   r<   Õ  s&   € ÷ Iñ I�fð I¨$ð I°3ñ Ir>   c           	     óø   € \        V P                  \        V P                  4      \	        V P
                  R^ 4      ^,           R7       V'       d   \        V 4      # \        P                  ! \        V 4      RR7      # )zPTool result JSON: a dispatch handle (background) or the joined combined results.Ú_delegate_depth)Ú	subagentsÚdepthFrè   )
r   r   r|   r   r_   r   rY  rë   rì   rá   )r�   rÑ   s   &&r;   Ú
_run_batchr_  Õ  s^   € ô Ø�‰¤3 u§~¡~Ó#6¼gÀe×FXÑFXÐZkÐmnÓ>oÐrsÕ>sõ÷ Ü# EÓ*Ð*Ü�:Š:Ô,¨UÓ3À%ÔHÐHr>   )F)=rV   Ú
__future__r   rº   rë   ÚloggingrØ   Úconcurrent.futuresr   r   r¿   Údataclassesr   r   Útypingr   r   r	   r
   Ú,hermes_cli.observability.shared_metrics_loopr   r   ri   r   r   Útools.delegate_tool_child_runr   r   r   r   Útools.delegate_tool_progressr   r   r   r   r   Útools.delegate_tool_registryr   Útools.delegate_tool_resultsr   Ú	getLoggerrô   r   ra   rn   r‹   r’   rË   rá   rê   rí   rö   r  r  r$  r*  r4  rH  rK  rY  r_  r9   r>   r;   Ú<module>rk     s%  ðñ1õ
 #ã Û Û Û ß @ß *ß ,Ó ,ç eß Hß mÓ m÷õ õ JÝ ?à	×	Ò	Ð0Ó	1€ð ÷"Fð "Fó ð"FõJxõQõ"Hõ,0õ=0ð~&ÈD÷ &ðR ð	uð
 ð	mðÐ õ2÷"õHAõ,!ð0 
ð	_ð ð	:ð
 ð	ð ð	hð%Ð õ.õ.sõ"õ00õ23÷hIr>   