+
    lHàjjr  ã                  ó  € 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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( ]PR                  ! 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t0RR/R R llt1RRRR /t2R! R" lt3R=R# R$ llt4R% R& lt5R' R( lt6R)R*R+R,R-R.R/R0/t7R1 R2 lt8R3 R4 lt9R5 R6 lt:R7 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ÚfieldÚ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 7      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_home)Údefault_factoryÚrefusedc               ó   € V ^8„  d   QhRR/# )é   Úreturnr    © )Úformats   "ÚA/home/ubuntu/.hermes/hermes-agent/tools/delegate_tool_dispatch.pyÚ__annotate__Ú_Batch.__annotate__9   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_kwargs9   s8   € ð  × 9Ñ 9× AÐ A¸TÐCTÐVZ×VqÑVqØ" D×$DÑ$Dð
ð 	
rA   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r:   Úir&   Útaskr    Úchildr   r;   r<   )r=   s   "r>   r?   r@   @   s.   € ÷ Fñ F˜3ð F nð F¸Sð FÀ^ñ FrA   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ÚgoalrL   r   r<   )Útools.delegate_toolrO   r   rG   )rF   rJ   rK   rL   rO   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rA   r<   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r4   r5   r6   r   r)   r8   rG   rS   Ú__static_attributes__r<   rA   r>   r   r      s©   ‡ ñ]ð $Ó#ØÓØÓØÓØÓØƒMØÓØ Ó ØÓØÓØÓØÓØÓØ!$Ó$Ø%)Ó)ØÓà€Eˆ=ÓØ!€Gˆ]Ó!Ø€IˆsÓñ ¨$Ô/€GˆTÓ/õ
÷Fñ FrA   r   c               ó$   € V ^8„  d   QhRRRRRR/# )r:   Ún_tasksr&   r(   r"   r;   ÚNoner<   )r=   s   "r>   r?   r?   E   s'   € ÷ xñ x¨3ð x¸}ð xÐQUñ xrA   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   r]   r(   Ú_hdrs   &&& r>   Ú_announce_batchrd   E   sH   € à�„{—}ØÔ*¨=ÓGÐHÈÐV]ÐU^Ð^dÐeˆÜ˜|¬W°\ÐCVÐX\Ó-]Ð_c×wñ %�{rA   c               ó   € V ^8„  d   QhRR/# )r:   r;   ztuple[str, str, Any, Any, bool]r<   )r=   s   "r>   r?   r?   K   s   € ÷ Qñ QÐ8ñ QrA   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_delegationrg   r   Úgateway.session_contextri   rj   r   )rg   Ú_origin_wake_sidÚ_origin_ui_session_idÚ _origin_session_history_deliveryri   rj   s         r>   Ú_capture_originrq   K   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/# )r:   r;   r^   r<   )r=   s   "r>   r?   r?   \   s   € ÷ Hñ HÐbfñ HrA   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".rP   zTask ÚstatusÚ?u    Â· Ú/Úschema_validFÚ	completedu   âš u   âœ“u   âœ—z [z] z  (Úduration_secondszs)Úfailure_reasonÚerror)Ú	max_charsrh   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_labelsr]   Ú	remainingÚidxÚlabelrt   Ú_slotÚschema_invalidÚiconÚcompletion_lineÚ	_err_lines   &&&&&&&        r>   Ú_report_child_donerŽ   \   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/# )	r:   Úbatchr   rƒ   r   Úhonor_parent_interruptr0   r;   r^   r<   )r=   s   "r>   r?   r?   r   s)   € ÷ 0ñ 0 &ð 0°ð 0Èdð 0ÐW[ñ 0rA   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)r5   Ú
isinstanceÚdictr   )r�   rƒ   r‘   s   &&&r>   Ú_record_finished_childr•   r   s4   € ÷
 " e§m§m m¼
À5Ì$×8OÒ8OÜ˜%Ÿ-™-¨Ö/ñ 9P¡mÑ!rA   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r:   r�   r   Úresultsr)   r‘   r0   r;   r^   r<   )r=   s   "r>   r?   r?   z   s*   € ÷ =0ñ =0 &ð =0°4ð =0ÐTXð =0Ð]añ =0rA   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).)ÚDaemonThreadPoolExecutorrQ   :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 timer{   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©Nr<   )Ú.0Úfr£   Úfuturess   & €€r>   Ú	<genexpr>Ú)_run_children_parallel.<locals>.<genexpr>Ÿ   s   øé € ÐIÁ¸A™y¨¨G°A­J×7Ð7Ãùs   ƒ g      à?)ÚtimeoutÚreturn_whenrt   ztask failure notice failed©Úexc_info)Úpush_task_failure_noticerP   Úlive_transcript)r]   )r   Úcancel_futuresc                ó   € V R ,          # ©rP   r<   ©Úrs   &r>   Ú<lambda>Ú(_run_children_parallel.<locals>.<lambda>·   s   € ˜q žrA   ©Úkeyéÿÿÿÿ)!Útools.daemon_poolr™   r   r   r   rb   r   r(   r   r'   ÚsubmitÚcontextvarsÚcopy_contextÚrunrS   ÚsetÚextendÚ_cf_waitr   Úappendr•   rŽ   r5   r€   r   r   rl   r²   r“   r&   r+   ÚshutdownÚsort)r�   r—   r‘   r™   r   r]   Útr…   r‚   Ú_tagrJ   Ú_rL   Ún_hereÚexecutorrœ   Úpendingr�   r    rƒ   r²   Ú_iÚ_liver¢   r£   r«   s   &&$                    @@@r>   Ú_run_children_parallelrÑ   z   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/# )r:   r�   r   r‘   r0   r;   r”   r<   )r=   s   "r>   r?   r?   ¹   s"   € ÷ )ñ ) &ð )ÀTð )ÐUYñ )rA   c               óú  € ^ 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 P,                  '       d/   VP/                  V P,                  4       VP1                  R	 R
7       T! V P2                  W0P4                  R7       \7        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 P<                  e   V P<                  VR&   V#   + '       g   i     ELq; 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‘   rP   NzLive transcript finalize failedTr°   r³   c                ó   € V R ,          # r¶   r<   r·   s   &r>   r¹   Ú(_execute_and_aggregate.<locals>.<lambda>Ó   s   €  1 \¦?rA   r»   )Úhome)Ú
backgroundr—   Útotal_duration_seconds)Ú_process_accounting_linesÚprocess_notesÚlive_transcriptsr4   r½   )Útools.delegation_live_logrÔ   r   r   rÆ   rS   r•   rÑ   r   r   r   ÚroundÚtimeÚ	monotonicr3   r€   r“   r&   r*   r   Úfinalizer+   r8   rÄ   rÈ   r(   r6   r   Ú$tools.process_registry_notificationsrÛ   r4   )r�   r‘   rÔ   r—   Útotal_durationrƒ   Ú_idxÚcombinedrÛ   ÚlinerÜ   rJ   rË   Ú
unit_pathss   &$            r>   Ú_execute_and_aggregateré   ¹   sI  € õ
 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—}‘}Ô%Ø�‰Ñ2ˆÔ3Ù˜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   Å#KÈ>K1É4K7ÊK7ËK.Ú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/# )r:   r�   r   Úreasonr$   r;   r<   )r=   s   "r>   r?   r?   ò   s!   € ÷ 2ñ 2˜vð 2¨sð 2°sñ 2rA   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Ð1rA   c               ó$   € V ^8„  d   QhRRRRRR/# )r:   r,   r$   r1   r0   r;   r"   r<   )r=   s   "r>   r?   r?   ù   s#   € ÷ #ñ #¨Sð #ÐSWð #Ðdqñ #rA   c                ó<  € ^ RI Hp ^ RIHp V! 4       pVRJ g   Vf   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.©ri   )Úfinite_turn_requiredTNÚHERMES_SINGLE_QUERY_SESSIONÚ1)Úasync_delivery_supportedrh   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.)rm   ri   Úgateway.session_finiterù   rü   rŸ   ÚloggerÚinfo)r,   r1   ri   rù   Úfiniterü   s   &&    r>   Ú_resolve_async_wake_sidr  ù   s¡   € õ
 8õ <Ù!Ó#€FØ�ƒ~˜&š.©_Ð=ZÓ-[Ð_bÔ-bÙð	õ
 	EÙ#×%Ò%Ùð &÷ ×:Ü�‰ð8Ø9Hô	
ð ÐßÜ�‰ð@ØAPô	
ñ øô ô Úðús   ®B ÂBÂBc               ó$   € V ^8„  d   QhRRRRRR/# )r:   r   r   r-   r$   r;   ztuple[str, str]r<   )r=   s   "r>   r?   r?     s'   € ÷ Añ A¨Sð AÈð AÐP_ñ ArA   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_keyrh   )ÚdefaultÚ
session_idNrø   ÚHERMES_SESSION_SOURCErk   Útui)Útools.approval_contextr  r$   rb   r   rm   ri   )r   r-   r  Úsession_keyÚagent_session_idri   Ú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/# )r:   Úchild_agentsz	list[Any]r;   Útupler<   )r=   s   "r>   r?   r?   4  s   € ÷ !ñ !¨	ð !°eñ !rA   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Æ   r0   rŸ   r  )r  ÚpartsÚin_toolÚcÚsummaryÚtools   &     r>   Ú_batch_progress_tokenr  4  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/# )r:   r�   r   Úunitszlist[tuple[_Batch, str]]r;   r”   r<   )r=   s   "r>   r?   r?   b  s"   € ÷ ñ ˜vð Ð.Fð È4ñ rA   c                óÖ  € V P                    Uu. uF  q"R,          NK  	  pp\        V P                  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                  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.rQ   rt   Ú
dispatchedÚmoderÙ   ÚcountÚdelegation_idÚgoalsrï   r  r  )ÚnÚkr4   Ú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>q  s"   é € Ð
2©T¨Œ:�aœÓ×#Ð# !Ô#«Tùs   ‚)ž)TFÚsubagent_idsr  r8   rÝ   r  )r   r   r   r(   Ú_BACKGROUND_NOTESr=   r4   rb   Úanyr8   r+   r)   )r�   r!  rÉ   r'  r(  ÚpayloadÚunitÚuidrJ   rË   r  Úsidss   &&          r>   Ú_dispatched_payloadr5  b  s»  € à %§¢Ó0¡˜1ˆv�YˆY¡€EÐ0ÜˆE�N‰NÓ€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#   �GÂ7%G
ÃGÃ*	G
ÄG%ÇG
c               ó    € V ^8„  d   QhRRRR/# )r:   r�   r   r;   zlist[_Batch]r<   )r=   s   "r>   r?   r?   {  s   € ÷ sñ s�Vð s ñ srA   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_completionsr4   NÚgrJ   )r   r4   )Nrh   )	Útools.delegate_tool_configr8  r   r€   r$   Ú
setdefaultrÆ   Úitemsr   )	r�   r8  ÚmembersrJ   rÉ   r  r9  r¼   Úchs	   &        r>   Ú	_units_ofr?  {  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/# )	r:   r2  r   r5   r"   Úslot_keyÚroutingr”   r;   r<   )r=   s   "r>   r?   r?   Œ  s1   € ÷ ñ ˜ð ¨-ð À=ð Ð[_ð Ðdhñ rA   c           !     ó~  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	,          ;'       g    \        R
 S
 4       R4      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Ð">Ö?ó rA   r'  rQ   r#   ÚtoolsetsNÚroleÚmodelc              3  óf   "  € T F'  p\        VR R4      '       g   K  \        VR R4      x € K)  	  R# 5i)rJ  N)rb   )r©   r  s   & r>   r¬   Ú!_dispatch_unit.<locals>.<genexpr>›  s+   é € ÐZ±¨1ÄÈÈ7ÐTX×@YÔ&ŒW�Q˜ ×&Ð&³ùs   ‚1œ1Úrunnerc                 ó   <€ \        S R R7      # )FrÕ   )ré   )r2  s   €r>   r¹   Ú _dispatch_unit.<locals>.<lambda>œ  s   ø€ Ô-¨dÈ5ÕQrA   Úinterrupt_fnr&  rA  r*  Útask_transcriptsÚprogress_fnc                 ó   <€ \        S 4      # r¨   )r  )r  s   €r>   r¹   rO  £  s   ø€ Ô1°,Ô?rA   r<   )rl   rD  r   r   r#   r%   r!   Únextr   r*   Úpathr$   )r2  r5   rA  rB  rD  rË   r  rF  rÉ   rJ   r  s   f&&&      @r>   Ú_dispatch_unitrV  Œ  sÛ  ù€ åFØ'+§}¢}Ô5¡}™)˜1˜a“A¡}Ò5€Lõ@ñ +ñ à"&§.¢.Ó1¡.˜Q��yˆy¡.Ñ1ðà;?¿<¹<ðð ðð
 �]‰]ðð
 #'§*¡*¨WÕ"5÷ #bð #b¼ÙZ±ÓZÐ\`ó:bðô 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.Ã&F32Ä	 F96Ä.F96ÅF96Å&4F96c               ó    € V ^8„  d   QhRRRR/# )r:   r2  r   r;   r^   r<   )r=   s   "r>   r?   r?   ¦  s   € ÷ 0ñ 0 vð 0°$ñ 0rA   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   )r2  rË   rL   s   &  r>   Ú_restore_parent_cancellationrY  ¦  s&   € ð —}”}‰ˆˆ1Ü�d×'Ñ'¨Ö/ó %rA   c               ó    € V ^8„  d   QhRRRR/# )r:   r�   r   r;   r$   r<   )r=   s   "r>   r?   r?   ¬  s   € ÷ 23ñ 23 ð 23¨3ñ 23rA   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       Uu. uF  p\        V. R7      NK  	  p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	P1                  VVR,          34       KÛ  \3        V4       V	'       g5   \
        P                  RVP/                  RR4      4       \        V R4      u # \
        P5                  RV^,           \!        V4      VP/                  R4      4       V
P7                  \9        V4      R,          4       EK}  	  \;        W	4      pV
'       d   V
VR&   \<        P>                  ! VRR7      # u upi )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)r8   Ú-rt   r#  r&  zZdelegate_task: async pool at capacity (%s); running the whole batch synchronously instead.r{   Úrejectedrë   z?delegate_task: unit %d/%d not accepted (%s); running it inline.r—   Úinline_resultsFrð   ) rR   r\  r  r,   r1   rþ   rÿ   rõ   r   r  r-   r”   rb   r?  r   Ú	enumerater   r(   r   r5   r   r   rV  r€   rÆ   rY  ÚwarningrÄ   ré   r5  ró   rô   )r�   r\  Úwake_sidr   r
  r-   rB  r2  r!  r#  rb  rA  r)  r5   rË   rL   Údispatchr1  s   &                 r>   Ú_dispatch_backgroundrg  ¬  sK  € õ
 <Ü& u×'<Ñ'<¸e×>cÑ>cÓd€HØÒÜ�‰ð  Bô  	CÜ" 5¨*Ó5Ð5à×%Ñ%€LÜ(BÀ<×QkÑQkÓ(lÑ%€KÜØÐ^fÜ! ,°¸dÓCÑXoÓXqô€Gô
 4=¸UÔ3CÓDÑ3C¨4ŒW�T 2×&Ñ3C€EÐDØ+-€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Ð2ùòA Es   ÂI3c               ó$   € V ^8„  d   QhRRRRRR/# )r:   r�   r   rÙ   r0   r;   r$   r<   )r=   s   "r>   r?   r?   à  s&   € ÷ Iñ I�fð I¨$ð I°3ñ IrA   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   rb   r   rg  ró   rô   ré   )r�   rÙ   s   &&r>   Ú
_run_batchrm  à  s^   € ô Ø�‰¤3 u§~¡~Ó#6¼gÀe×FXÑFXÐZkÐmnÓ>oÐrsÕ>sõ÷ Ü# EÓ*Ð*Ü�:Š:Ô,¨UÓ3À%ÔHÐHrA   )F)>rY   Ú
__future__r   rÀ   ró   Úloggingrà   Úconcurrent.futuresr   r   rÅ   Údataclassesr   r   r   Útypingr   r	   r
   r   Ú,hermes_cli.observability.shared_metrics_loopr   r   rl   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   rd   rq   rŽ   r•   rÑ   ré   rò   rõ   r  r  r  r/  r5  r?  rV  rY  rg  rm  r<   rA   r>   Ú<module>ry     s(  ðñ1õ
 #ã Û Û Û ß @ß 1Ñ 1ß ,Ó ,ç eß Hß mÓ m÷õ õ JÝ ?à	×	Ò	Ð0Ó	1€ð ÷%Fð %Fó ð%FõPxõQõ"Hõ,0õ=0ð~)ÈD÷ )ðX ð	uð
 ð	mðÐ õ2÷#õJAõ,!ð0 
ð	_ð ð	:ð
 ð	ð ð	hð%Ð õ.õ2sõ"õ40õ23÷hIrA   