+
    jHàj)5  ã                  óh  € R t ^ RIHt ^ RIt^ RIt^ RIHt ]P                  ! ]4      t	. R/O]P                  O5tRtRRRRR	/R
RRRR/RRRRRRR/R/ /tR R lt]! RR04      tR R ltR R ltR R ltR0R R lltR R  ltR! R" ltR# R$ ltR% R& ltR1R' R( lltR2R) R* lltR+ R, ltR- R. ltR# )3a  Turn events a local viewer (the classic CLI, TUI, Desktop) reads from the canonical stream.

The classic CLI rendered every agent callback in process: the tool-generating line, the
kawaii thinking text, reasoning, MoA references, hearts, and every status line the agent printed
through ``_print_fn``. On the session authority the agent runs in the gateway, so each of those
callbacks is projected as an execution event (generation-fenced through
``TurnRunner._publish_execution``) and only for a local viewer's turn: a messaging route never
installs them, so its agent behaves exactly as before.

The cached agent is shared across turns. ``wire`` installs the sinks for one turn and returns the
previous values; ``restore`` puts them back when the turn's ``run_conversation`` returns.
)ÚannotationsN)Úlocal_desktop_uiÚ__desktop_ui_token__úmoa.referenceÚ	moa_indexÚindexÚ	moa_countÚcountúmoa.progressÚmoa_refs_doneÚ	refs_doneÚmoa_refs_totalÚ
refs_totalú	moa.phaseÚ	moa_phaseÚphaseúmoa.aggregatingc               ó   € V ^8„  d   QhRR/# ©é   ÚreturnÚdict© )Úformats   "Ú@/home/ubuntu/.hermes/hermes-agent/gateway/local_viewer_events.pyÚ__annotate__r   "   s   € ÷ ñ ˜ñ ó    c           	     óè  a a€ \          Uu/ uF  q"\        WR4      bK  	  ppS P                  oV3R lVn        V3R lpWAn        V3R lVn        V3R lVn        \        S RR4      pVe7   ^ RIHp V! V^ ,          P                  P                  V^,          4      V4       \        S 4      '       g   \        4       '       d   VV 3R lVn        \        P                  ! S V4      V\         &   V# u upi )	zTInstall this turn's local-viewer sinks on ``agent``; returns what ``restore`` needs.Nc                ó@   <€ S! R R\        T ;'       g    R4      /4      # )ztool.generatingÚnameÚ ©Ústr)r   Úpublishs   &€r   Ú<lambda>Úwire.<locals>.<lambda>&   s    ø€ ©7Ð3DÀvÌsÐSW×S]ÐS]Ð[]ËÐF_Ô+`r   c            
     ó|   <€ S! R R\        VP                  RR4      4      P                  R V  4       4      /4       R# )zagent.printÚtextÚsepÚ c              3  ó8   "  € T F  p\        V4      x € K  	  R # 5i©Nr!   )Ú.0Úas   & r   Ú	<genexpr>Ú)wire.<locals>.print_fn.<locals>.<genexpr>)   s   é € ÐH^ÑY]ÐTUÌÈQÏÈÓY]ùs   ‚N)r"   ÚgetÚjoin)ÚargsÚkwargsr#   s   *,€r   Úprint_fnÚwire.<locals>.print_fn(   s4   ø€ Ù� ¬¨F¯J©J°u¸cÓ,BÓ(C×(HÑ(HÑH^ÑY]ÓH^Ó(^Ð_Ö`r   c                ó@   <€ S! R R\        T ;'       g    R4      /4      # )zthinking.deltar'   r    r!   )r'   r#   s   &€r   r$   r%   ,   s    ø€ ©7Ð3CÀfÌcÐRV×R\ÐR\ÐZ\ËoÐE^Ô+_r   c                ó@   <€ S! R R\        T ;'       g    R4      /4      # )ÚreactionÚkindr    r!   )r9   r#   s   &€r   r$   r%   -   s   ø€ ©7°:ÀÌÈDÏJÈJÐTVËÐ?XÔ+Yr   Ú_approval_owner)Úseed_compression_countc                óf   <€ \        S4      '       d   S! R R\        T ;'       g    R4      /4      # R# )zreasoning.deltar'   r    N)Úshow_reasoningr"   )r'   r#   Úturns   &€€r   r$   r%   5   s1   ø€ ÜESÐTX×EYÒEY‰GÐ%¨´°D·J°J¸B³Ð'@ÓAÐcÐ_cÐcr   )Ú_TURN_ATTRSÚgetattrÚ_publish_executionÚtool_gen_callbackÚ	_print_fnÚthinking_callbackÚreaction_callbackÚgateway.session_usager;   Úsessionsr0   r=   Ú_config_default_launchÚreasoning_callbackr   ÚwireÚ_DESKTOP_UI_TOKEN)r>   Úagentr   Úpreviousr4   Úownerr;   r#   s   f&     @r   rJ   rJ   "   sÎ   ù€ å=HÓI¹[°T”g˜e¨4Ó0Ò0¹[€HÐIØ×%Ñ%€GÜ`€EÔõaà„Oä_€EÔÜY€EÔÜ�DÐ+¨TÓ2€EØÒÝ@Ù˜u Q�x×0Ñ0×4Ñ4°U¸1µXÓ>ÀÔFÜ�d×ÒÔ5×7Ò7õ$eˆÔ ô #3×"7Ò"7¸¸eÓ"D€HÔÑØ€Oùò+ Js   ‹C/ÚtuiÚguic               ó   € V ^8„  d   QhRR/# ©r   r   Úboolr   )r   s   "r   r   r   @   s   € ÷ 	=ñ 	=˜Dñ 	=r   c                óè   € \        V RR4      pVe*   V^ ,          P                  P                  V^,          4      MRp\        VRR4      pVf   Vf   VRJ # ^ RIHp \        V! 4       V^ ,          4      # )zÌThe session's ``show_reasoning`` display flag (``config.set``, ``/reasoning show|hide``); unset on an
Ink or Desktop launch, its ``display.show_reasoning`` (default on), as main's TUI gateway resolved it.r:   Nr=   T©Úactive_policy)r@   rG   r0   Úgateway.session_policyrV   Úlaunch_shows_reasoning)r>   rN   ÚliveÚflagrV   s   &    r   r=   r=   @   sq   € ô �DÐ+¨TÓ2€EØ.3Ò.?ˆ5��8×Ñ× Ñ   q¥Ô*ÀT€DÜ�4Ð)¨4Ó0€DØÒ˜4š<Ø�tˆ|ÐÝ4Ü!¡-£/°5¸µ8Ó<Ð<r   c               ó   € V ^8„  d   QhRR/# rR   r   )r   s   "r   r   r   L   s   € ÷ Oñ O ñ Or   c                 ó@   € ^ RI Hp  \        V ! 4       RR4      \        9   # )é    rU   ÚsourceN)rW   rV   r@   Ú_CONFIG_DEFAULT_SOURCESrU   s    r   rH   rH   L   s   € Ý4Ü‘=“? H¨dÓ3Ô7NÑNÐNr   c               ó   € V ^8„  d   QhRR/# rR   r   )r   s   "r   r   r   Q   s   € ÷ 5ñ 5°ñ 5r   c                óÄ   € \        V RR4      \        9  d   R# ^ RIHp V! V P	                  VRR7      P                  R4      4      p\        VP                  RR4      4      # )	zYAn unset session flag: ``display.show_reasoning`` for an Ink or Desktop launch, else off.r^   NF)Úlocal_display_config)ÚsecretsÚdisplayr=   T)r@   r_   Úgateway.display_configrb   Úconfigr0   rS   )ÚpolicyÚ	authorityrb   rd   s   &&  r   rX   rX   Q   sS   € äˆv�x Ó&Ô.EÔEÙÝ;Ù" 6§=¡=°ÀE =Ó#J×#NÑ#NÈyÓ#YÓZ€GÜ�—‘Ð,¨dÓ3Ó4Ð4r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úpayloadr   Ú
event_typer"   r   rS   r   )r   s   "r   r   r   Z   s&   € ÷ bñ b¨tð bÀð bÈdñ br   c                óÈ  € VP                  R 4      p\        V\        4      '       d	   V'       g   R# ^ RIpVP                  P                  R4      p\        \        V RR4      RR4      p\        V\        4      '       d   V'       d
   V^ ,          MRpVe   Vf   R# VP                  R4      pVP                  ;_uu_ 4        VP                  P                  V4      p	V	f9   VR8X  d2   \        V\        4      '       d   VP                  P                  V4      p	V	RJ;'       d"    VP                  V	P                  R4      V4      uuRRR4       #   + '       g   i     R# ; i)	Úsubagent_idFNztools.delegate_tool_registryÚ_ctxÚagent_holderÚ	parent_idzsubagent.spawn_requestedrL   )
r0   Ú
isinstancer"   ÚsysÚmodulesr@   ÚlistÚ_active_subagents_lockÚ_active_subagentsÚ_is_descendant_of)
r>   rj   rk   rm   rr   ÚregistryÚholderÚ
turn_agentrp   Úrecords
   &&&       r   Ú_is_active_session_subagentr|   Z   s  € Ø—+‘+˜mÓ,€KÜ�k¤3×'Ò'¯{ÙÛØ�{‰{�‰Ð=Ó>€HÜ”W˜T 6¨4Ó0°.À$ÓG€FÜ(¨´×6Ò6¿6�˜–Àt€JØÒ˜:Ò-ÙØ—‘˜KÓ(€IØ	×	(×	(Ó	(Ø×+Ñ+×/Ñ/°Ó<ˆØŠ>˜jÐ,FÔFÌ:ÐV_Ôad×KeÒKeà×/Ñ/×3Ñ3°IÓ>ˆFØ˜TÐ!×aÐa h×&@Ñ&@ÀÇÁÈGÓATÐV`Ó&a÷ 
)×	(×	(Ó	(ús   ÃA"EÄ$!EÅE!	c               ó   € V ^8„  d   QhRR/# ©r   r   ÚNoner   )r   s   "r   r   r   m   s   € ÷ Qñ Q°Dñ Qr   c                ó\  € \        V R R4      pVe   \        V^ ,          RR4      MRpVe   \        V\        4      '       g   V P                  W4       R# Vw  rVp\        VP                  P                  V4      RR4      p\        VRR4      p	^ RIp
V	e   T	MV
P                  4       ;_uu_ 4        VP                  V4      V8X  d   V P                  W4        RRR4       R#  RRR4       Ve+   \        WV4      '       d   VP                  WbV/ R7       R# R# R#   + '       g   i     L@; i)r:   NÚ	executingÚevent_streamÚlock)rk   Ú	execution)
r@   rq   r   rA   rG   r0   Ú
contextlibÚnullcontextr|   r#   )r>   rk   rj   rN   r�   rh   Ú
session_idÚ
generationÚstreamrƒ   r…   s   &&&        r   Ú_publish_subagentrŠ   m   s  € Ü�DÐ+¨TÓ2€EØ8=Ò8I”˜˜a� +¨tÔ4Èt€IØ‚}œJ y´$×7Ò7Ø×Ñ 
Ô4ÙØ(-Ñ%€I˜:Ü�Y×'Ñ'×+Ñ+¨JÓ7¸ÈÓN€FÜ�6˜6 4Ó(€DÛàÒ!‰ z×'=Ñ'=Ó'?×	?Ñ	?Ø�=‰=˜Ó$¨
Ô2Ø×#Ñ# JÔ8Ø÷ 
@Ñ	?Ø2÷ 
@ð ÒÔ9¸$È×TÒTà�‰�z°zÈRˆÖPñ UÑ÷	 
@×	?ús   Â/)DÄD+	c               ó   € V ^8„  d   QhRR/# r~   r   )r   s   "r   r   r   �   s   € ÷  1ñ  1Àñ  1r   c                ó.  € \        V\        4      '       dG   VP                  R4      '       d0   VR8X  d   R# ^ RIHp \        WV! WW4\        V 4      R7      4       R# VR8X  d!   ^ RIHp V P                  W! W#V4      4       R# VR8w  d   V\        9  d   R# ^ R	IHp \        V 4      '       g   VR8w  d   V! V 4      '       g   R# VR8X  d   R
\        T;'       g    R4      /pM{VR8X  d.   R\        T;'       g    R4      R
\        T;'       g    R4      /pMGVR9   d*   V'       g   VR8X  d   R\        T;'       g    R4      /M/ pMR\        T;'       g    R4      /pTP                  \        P                  V/ 4      P                  4        U	U
u/ uF#  w  ršVP                  V	4      f   K  W¤V	,          bK%  	  up
p	4       VR8X  d   RR0\!        V4      8:  g   R# VR8X  d   VP                  R4      '       g   R# V P                  W4       R# u up
p	i )a  ``subagent.*``, ``reasoning.available`` and the MoA facade events from the agent's progress callback; a classic CLI renders MoA references whatever its reasoning display (main's ``_on_tool_progress``), while other viewers get them only with reasoning shown.z	subagent.zsubagent.textN)Ú_subagent_payload)r=   ztool.progress)Útool_progress_payloadzreasoning.available)Úclassic_cli_turnr'   r    r   Úlabelr   r   Ú
aggregatorr
   r   r   r   )r   r   )rq   r"   Ú
startswithÚtui_gateway.tool_progressr�   rŠ   r=   Úagent.tool_progress_relayrŽ   rA   Ú	_MOA_KEYSÚgateway.session_cli_turnr�   Úupdater0   ÚitemsÚset)r>   rk   r   Úpreviewr3   r�   rŽ   r�   rj   ÚkeyÚouts   &&&&&      r   Úpublish_progressr�   �   sÍ  € ä�*œc×"Ò" z×'<Ñ'<¸[×'IÒ'IØ˜Ô(ÙÝ?Ü˜$Ñ,=Ø˜g¼nÈTÓ>Rô-Tô 	UáØ�_Ô$ÝCØ×Ñ 
Ð,AÀ$ÐQWÓ,XÔYÙØÐ*Ô*¨zÄÔ/JÙÝ9Ü˜4× Ò  ZÐ3HÔ%HÑM]Ð^b×McÒMcÙØÐ*Ô*Øœ3˜wŸ}˜}¨"Ó-Ð.‰Ø	�Ô	&ØœC §
 
¨›O¨V´S¸¿¸ÀBÓ5GÐH‰Ø	Ð7Ô	7ß59¸ZÐK\Ô=\�<¤ T§Z Z¨R£Ñ1Ðbd‰àœC §
 
¨›OÐ,ˆØ‡N�N´Y·]±]À:ÈrÓ5R×5XÑ5XÔ5Zô 4Ñ5Z©¨Ø—z‘z #“ô %�C �Ò$Ñ5Zò 4ô 5à�^Ô#¨[¸,Ð,GÌ3ÈwË<Ô,WÙØ�[Ô ¨¯©°W×)=Ò)=ÙØ×Ñ˜JÖ0ùó4s   ÆH
Æ.H
c               ó    € V ^8„  d   QhRRRR/# )r   rM   údict | Noner   r   r   )r   s   "r   r   r   ¤   s   € ÷ $ñ $˜[ð $¨Tñ $r   c                óÄ   € V'       g   R # VP                  \        R 4      pVe   \        P                  ! V4       VP	                  4        F  w  r4\        WV4       K  	  R # r+   )ÚpoprK   r   Úreleaser˜   Úsetattr)rL   rM   Útokenr   Úvalues   &&   r   Úrestorer¦   ¤   sJ   € ßÙØ�L‰LÔ*¨DÓ1€EØÒÜ× Ò  Ô'Ø—~‘~Ö'‰ˆÜ�˜UÖ#ó (r   c               ó   € V ^8„  d   QhRR/# r~   r   )r   s   "r   r   r   ®   s   € ÷ 
Gñ 
G¨ñ 
Gr   c                óv   aaa€ ^ RI Ho V P                  w  oopVVV3R lpV P                  V! 4       R4       R# )a„  Agent thread, after each tool: a tool (a plugin adding goal criteria, parking the goal) can move
automation state mid-turn, so viewers' cards repaint now instead of at turn end. The snapshot is read,
compared and published on the gateway loop, in order with the slash commands' publishes (a snapshot
read here could land after a newer one); revision-gated, so other tools publish nothing.)r#   c               “  ó&   <"  € S! S SR R7       R# 5i)T)Úonly_if_changedNr   )rh   Úcanonical_idr#   s   €€€r   Ú	republishÚ-publish_control_if_changed.<locals>.republish¶   s   øé € Ù�	˜<¸×>ùs   ƒz#session.control.update after a toolN)Úgateway.session_control_actionsr#   r:   Ú	_schedule)r>   Ú_generationr¬   rh   r«   r#   s   &  @@@r   Úpublish_control_if_changedr±   ®   s0   ú€ õ
 8Ø+/×+?Ñ+?Ñ(€Iˆ|˜[÷?à‡N�N‘9“;Ð EÖFr   c               ó   € V ^8„  d   QhRR/# r~   r   )r   s   "r   r   r   »   s   € ÷ Nñ NÀñ Nr   c                óº  € \        T;'       g    R4      p\        P                  ! 4       V P                  P	                  R/ 4      V&   Vf   R#  ^ RIHp T! T\        V\        4      '       d   TM/ V P                  P                  R7      pVe!   W`P                  P	                  R	/ 4      V&   R# R#   \         d    \        P                  RTRR7       Rp LMi ; i)
a  Monotonic start time of one call (``tool.complete.duration_s``) and, for a write-capable
tool, the before-state of its local files: the agent fires the start callback BEFORE the tool
writes, so the gateway owns the snapshot the classic CLI used to take in process.r    Ú_local_tool_startsN)Úcapture_local_edit_snapshot)Útask_idz#Edit snapshot capture failed for %sT©Úexc_infoÚ_local_edit_snapshots)r"   ÚtimeÚ	monotonicÚ__dict__Ú
setdefaultÚagent.displayrµ   rq   r   rn   r‡   Ú	ExceptionÚloggerÚdebug)r>   Úcall_idÚ	tool_namer2   r›   rµ   Úsnapshots   &&&&   r   Únote_tool_startrÅ   »   sÅ   € ô ˆg�mˆm˜Ó
€CÜ>B¿nºnÓ>N€D‡M�M×ÑÐ1°2Ó6°sÑ;ØÒÙðÝ=Ù.¨yÄ*ÈTÔSW×BXÒBX¹$Ð^`Ø7;·y±y×7KÑ7KôMˆð
 ÒØEM�‰× Ñ Ð!8¸"Ó=¸cÓBñ øô ô Ü�‰Ð:¸IÐPTˆÔUØŠðús   Á=B2 Â2%CÃCc               ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   r   Î   s   € ÷ ñ Èdñ r   c                ór  € \        T;'       g    R4      pV P                  P                  R/ 4      P                  VR4      pRVe   \        P
                  ! 4       V,
          MR/pVf   V# T P                  P                  R/ 4      P                  VR4      p. p	 ^ RIHp
 T
! Y$\        V\        4      '       d   TM/ W‰P                  R7       V	'       d   RP                  V	4      MRVR&   \        W$4      pVe   VP!                  V4       V#   \         d    \        P                  RTR	R
7       . p	 Lgi ; i)z«``duration_s``, ``inline_diff`` (the rendered edit diff main's CLI printed after a write,
``None`` when there is none) and, for the todo tool, the full ``todos`` snapshot.r    r´   NÚ
duration_sr¹   )Úrender_edit_diff_with_delta)Úfunction_argsrÄ   r4   zEdit diff preview failed for %sTr·   Ú
Úinline_diff)r"   r¼   r½   r¡   rº   r»   r¾   rÉ   rq   r   Úappendr¿   rÀ   rÁ   r1   Ú
todo_stater—   )r>   rÂ   rÃ   r2   Úresultr›   ÚstartedÚfieldsrÄ   ÚrenderedrÉ   Útodos   &&&&&       r   Úcomplete_fieldsrÔ   Î   s  € ô ˆg�mˆm˜Ó
€CØ�m‰m×&Ñ&Ð';¸RÓ@×DÑDÀSÈ$ÓO€GØ¸GÒ<OœTŸ^š^Ó-°Ö7ÐUYÐZ€FØÒØˆØ�}‰}×'Ñ'Ð(?ÀÓD×HÑHÈÈdÓS€HØ€HðÝ=Ù# IÌZÐX\Ô^b×McÒMcÁTÐikØ-5ÇÁõ	Q÷
 4<˜DŸI™I hÔ/À€Fˆ=ÑÜ�iÓ(€DØÒØ�‰�dÔØ€Møô ô Ü�‰Ð6¸	ÈDˆÔQØŠðús   Â3D Ä%D6Ä5D6c               ó   € V ^8„  d   QhRR/# )r   r   rŸ   r   )r   s   "r   r   r   æ   s   € ÷ 
ñ 
 [ñ 
r   c                óÚ   € ^ RI Hp V! V 4      '       g   R# ^ RIp^ RIHp  T! \        V\        4      '       d   VP                  V4      4      # T4      #   \        \        3 d     R# i ; i)zWThe client-safe ``{todos, revision}`` snapshot a todo tool's result carries, else None.)Úis_todo_tool_nameN)Ú_normalize_todo_state)
Útools.todo_toolr×   Újsonr“   rØ   rq   r"   ÚloadsÚ	TypeErrorÚ
ValueError)rÃ   rÏ   r×   rÚ   rØ   s   &&   r   rÎ   rÎ   æ   s^   € å1Ù˜Y×'Ò'ÙÛÝ?ðÙ$¼:ÀfÌc×;RÒ;R T§Z¡Z°Ó%7Ó_Ð_ÐX^Ó_Ð_øÜ”zÐ"ô Úðús   ¢,A ÁA ÁA*Á)A*c               ó   € V ^8„  d   QhRR/# )r   r   z
int | Noner   )r   s   "r   r   r   ó   s   € ÷ ,ñ , Jñ ,r   c                ó¬   € ^ RI Hp V! V 4      '       g   R# VR8X  d   ^ RIHp \	        V! 4       4      pM^ RIHp \	        V! 4       4      pV^ 8”  d   V# R# )a@  ``timeout_s`` of a local viewer's approval / clarify prompt: the window the gateway's own wait
enforces (``approvals.timeout`` / the clarify timeout), so the classic CLI's modal shows the
same countdown and gives up when the gateway does. ``None`` on a messaging turn (frame
unchanged) and for an unlimited clarify wait.)Úlocal_viewer_turnNÚapproval)Ú_get_approval_timeout)Úget_clarify_timeout)Úgateway.run_turn_progressrà   Útools.approval_contextrâ   ÚintÚtools.clarify_gatewayrã   )r>   r9   rà   râ   Úsecondsrã   s   &&    r   Úprompt_timeout_sré   ó   sP   € õ
 <Ù˜T×"Ò"ÙàˆzÔÝ@ÜÑ+Ó-Ó.‰å=ÜÑ)Ó+Ó,ˆØ ”kˆ7Ð+ tÐ+r   )rB   rC   rD   rE   rI   )r    )NN)NNN)Ú__doc__Ú
__future__r   Úloggingrº   Úgatewayr   Ú	getLoggerÚ__name__rÀ   ÚCALLBACK_ATTRSr?   rK   r•   rJ   Ú	frozensetr_   r=   rH   rX   r|   rŠ   r�   r¦   r±   rÅ   rÔ   rÎ   ré   r   r   r   Ú<module>rò      sÚ   ðñõ #ã Û å $à	×	Ò	˜8Ó	$€ò1Ø ×/Ñ/ñ1€ð +Ð à˜{¨G°[À'ÐJØ˜o¨{Ð<LÈlÐ[Ø˜;¨°À+ÐO_ÐamÐnØ ð$€	õñ6 $ U¨E NÓ3Ð õ	=õOõ
5÷bõ&Qõ( 1õF$õ
G÷N÷&õ0
÷,r   