+
    jHàjB!  ã            	      óú   € R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHt R]	! 0 Rm4      R]	! 0 Rm4      R]	! 0 Rm4      /t
]	! 0 Rm4      t]	! 0 Rm4      t]]]3tR R	 ltR
 tR tR tR t]! 4       tR R ltR tR tR# )a	  ``session.automation``: the classic CLI's /goal, /subgoal, /loop and /heartbeat managers, run here.

Main's HermesCLI held a ``GoalManager`` / ``LoopManager`` / ``HeartbeatManager`` in its own process:
they wrote ``state_meta`` through a read-write SessionDB and called the goal judge (an auxiliary
model). Over the session authority the gateway is the single writer and runs every model call, so
the viewer's managers are thin proxies (``hermes_cli/gateway_automation.py``) and each mutation or
judgement is one call of this verb, executed against the session's physical row under the owning
profile's runtime scope and the session's own workspace (quality gates run in its cwd).

The viewer keeps main's timing: it calls ``evaluate_after_turn`` / ``complete_tick`` after its turn
returns and queues the continuation itself. A session whose viewer drives its automation this way is
recorded in ``authority.viewer_automation``; the gateway's own post-turn goal/loop hooks skip it, so
a turn is never judged twice or continued twice.
)ÚannotationsN)ÚPath)ÚRuntimeStoreErrorÚgoalÚloopÚ	heartbeatc               ó   € V ^8„  d   QhRR/# )é   ÚreturnÚbool© )Úformats   "ÚF/home/ubuntu/.hermes/hermes-agent/gateway/session_viewer_automation.pyÚ__annotate__r   $   s   € ÷ Uñ U¨Dñ Uó    c                ó¦   € V e   \        V R/ 4      P                  V4      MRp\        VRJ;'       d    VP                  P                  V4      4      # )zïWhether a local viewer drives this session's goal/loop judging (see the module doc): only while
that viewer's connection still holds its subscription, so a TUI or Desktop attached after it left
gets the gateway's own post-turn hooks again.NÚviewer_automation)ÚgetattrÚgetr   Úsubscriptions)Ú	authorityÚ
session_idÚ
connections   && r   Úviewer_drivenr   $   sQ   € ð QZÒPe”˜Ð$7¸Ó<×@Ñ@ÀÔLÐko€JÜ�
 $Ð&×SÐS¨:×+CÑ+C×+GÑ+GÈ
Ó+SÓTÐTr   c                óB   € \        V R R4      pVe   V! 4       # ^ RIHp V# )Ú_goal_max_turns_from_configN)ÚDEFAULT_MAX_TURNS)r   Úhermes_cli.goalsr   )ÚrunnerÚ
configuredr   s   &  r   Ú
_max_turnsr    ,   s(   € Ü˜Ð!>ÀÓE€JØÒÙ‹|ÐÝ2ØÐr   c                óŒ   € VR 8X  d   ^ RI Hp V! V\        V 4      R7      # VR8X  d   ^ RIHp V! VR7      # ^ RIHp V! VR7      # )r   )ÚGoalManager)r   Údefault_max_turnsr   )ÚLoopManager)r   )ÚHeartbeatManager)r   r"   r    Úhermes_cli.loopsr$   Úhermes_cli.heartbeatr%   )r   ÚkindÚtargetr"   r$   r%   s   &&&   r   Ú_managerr*   4   sA   € Øˆv„~Ý0Ù fÄ
È6Ó@RÔSÐSØˆv„~Ý0Ù fÔ-Ð-Ý5Ù vÔ.Ð.r   c                ó®  € V e'   \        V \        \        \        \        34      '       d   V # \        V R4      '       d   RV P                  4       /# \        V R4      '       d   RV P                  4       /# \        P                  ! V 4      '       d-   \        V \        4      '       g   \        P                  ! V 4      # \        V \        4      '       d8   V P                  4        UUu/ uF  w  r\        V4      \        V4      bK  	  upp# \        V \        \         34      '       d   V  Uu. uF  p\        V4      NK  	  up# \        V 4      # u uppi u upi )zNA manager return value as JSON: states and gates keep their own serialisation.Úto_jsonÚ	__state__Úto_dictÚ__gate__)Ú
isinstanceÚstrÚintÚfloatr   Úhasattrr,   r.   ÚdataclassesÚis_dataclassÚtypeÚasdictÚdictÚitemsÚ_wireÚlistÚtuple)ÚvalueÚkÚvs   &  r   r;   r;   ?   sþ   € à‚}œ
 5¬3´´U¼DÐ*A×BÒBØˆÜˆu�i× Ò Ø˜UŸ]™]›_Ð-Ð-Üˆu�i× Ò Ø˜EŸM™M›OÐ,Ð,Ü×Ò ×&Ò&¬z¸%Ä×/FÒ/FÜ×!Ò! %Ó(Ð(Ü�%œ×ÒØ-2¯[©[¬]Ô;©]¡T Q”�A“œ˜a›Ò ©]Ò;Ð;Ü�%œ$¤˜×'Ò'Ù"'Ó(¡%˜Q”�a–¡%Ñ(Ð(Üˆu‹:Ðùó <ùâ(s   Ã& EÄ*Ec                ó¶  € VR8X  dK   VR8X  dD   ^ RI Hp \        V4      RR.,           R,          w  rxT! T \        T;'       g    R4      R VR7      # VR8X  d[   VR	8X  dT   ^ R
IHp	Hp
  V
! VR7      pV	! V4      pT P                  \        T;'       g    R.^ ,          ;'       g    R4      RW¼R7      # VR8X  dc   VR8X  d\   \        VP                  R4      \        4      '       d7   ^ RIHp / VCRVP                  VR,          4      /CpV P                  ! V/ VB # VR8X  d   VR8X  d   ^ RIHp V! V4      # VR8X  d   R# \"        #   \         d    R^ rË LÝi ; i)zVCalls that are more than one manager method; ``None`` when ``call`` is a plain method.r   Úcommand)Údispatch_goal_commandÚ N:Nr	   Nc                 ó   € R # )Nr   r   r   r   Ú<lambda>Ú_special.<locals>.<lambda>W   s   € ÑQUr   )Úauthorize_gateÚlast_user_messageÚevaluate_after_turn)Úcount_active_delegationsÚgather_background_processes)Úowner_task_idT)Úuser_initiatedÚbackground_processesÚactive_delegationsÚsetÚcontract)ÚGoalContractr   Úgoal_blocks_tick)Úgoal_blocks_loop_tickÚstate)Úhermes_cli.goal_commandrC   r<   r1   r   rK   rL   Ú	ExceptionrJ   r0   r   r9   rS   Ú	from_dictrQ   r&   rU   Ú_NOT_SPECIAL)Úmgrr(   r)   ÚcallÚargsÚkwargsrC   ÚargÚ	last_userrK   rL   Ú	processesÚdelegationsrS   rU   s   &&&&&&         r   Ú_specialrc   P   sS  € àˆv„~˜$ )Ô+õ 	BÜ˜t›*¨¨D zÕ1°2Õ6‰ˆÙ$ S¬#¨c¯i¨i°R«.ÉÐirÔsÐsØˆv„~˜$Ð"7Ô7çZð	-Ù3À&ÔIˆIÙ2°6Ó:ˆKð ×&Ñ&¤s¨D¯L¨L°R°D¸!Õ+<×+BÐ+BÀÓ'CÐTXØ<Eð 'ó gð 	gàˆv„~˜$ %œ-¬J°v·z±zÀ*Ó7MÌt×,TÒ,TÝ1ØS�FÐS˜J¨×(>Ñ(>¸vÀjÕ?QÓ(RÑSˆØ�wŠw˜Ð' Ñ'Ð'Øˆv„~˜$Ð"4Ô4Ý:Ù$ VÓ,Ð,Øˆw„ÙÜÐøô ô 	-Ø%)¨1’{ð	-ús   Á)E ÅEÅEc               ó   € V ^8„  d   QhRR/# )r	   r
   r9   r   )r   s   "r   r   r   q   s   € ÷ ñ ¸ñ r   c                óL  € \        WV4      p \        WaW#WE4      pV\        J d   \        Wc4      ! V/ VB pR\	        V4      /pVP                  p
V
e   V
P                  4       MRVR&   V#   \
         d/   p	RR\        T	4      P                  R\        T	4      //p Rp	?	L[Rp	?	ii ; i)z\Run one call against ``target``'s persisted state: ``{state, value}`` or ``{state, error}``.r>   Úerrorr7   ÚmessageNrV   )r*   rc   rZ   r   r;   Ú_ERRORSr7   Ú__name__r1   rV   r,   )r   r(   r)   r\   r]   r^   r[   r>   ÚoutÚexcrV   s   &&&&&&     r   Úinvokerl   q   s§   € ä
�6 Ó
(€CðKÜ˜ F°$Ó?ˆØ”LÓ Ü˜CÔ&¨Ð7°Ñ7ˆEØœ˜e›Ð%ˆð �I‰I€EØ&+Ò&7�5—=‘=”?¸T€Cˆ�LØ€Jøô	 ô KØ˜¤ c£×!3Ñ!3°YÄÀCÃÐIÐJ�ûðKús   Ž5A* Á*B#Á5$BÂB#c                ó   € \        V 4      \        ,
          '       d   \        R 4      hV P                  R4      V P                  R4      r!V P                  R4      ;'       g    . V P                  R4      ;'       g    / rCV\        9  gy   V\        V,          9  gg   \        V\        4      '       dQ   \        V\        4      '       d;   \        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \        R 4      hWW43# )Úinvalid_paramsr(   r\   r]   r^   c              3  ó~   "  € T F3  p\        V\        4      ;'       d    VP                  R 4      '       * x € K5  	  R# 5i)Ú_N)r0   r1   Ú
startswith)Ú.0r?   s   & r   Ú	<genexpr>Ú_parse.<locals>.<genexpr>‡   s5   é € Ð6tÑmsÐhi´zÀ!ÄSÓ7I×7cÐ7cÐRS×R^ÑR^Ð_bÓRcÔNcÔ7cÓmsùs   ‚=ž=FT)	rQ   Ú_FIELDSr   r   Ú_CALLSr0   r<   r9   Úall)Úparamsr(   r\   r]   r^   s   &    r   Ú_parsery   �   sÄ   € Ü
ˆ6ƒ{”W×ÔÜÐ 0Ó1Ð1Ø—‘˜FÓ# V§Z¡Z°Ó%7ˆ$Ø—:‘:˜fÓ%×+Ð+¨¨V¯Z©Z¸Ó-A×-GÐ-GÀRˆ&Ø”FÔ˜d¬&°­,Ô6¼jÈÌt×>TÒ>TÜ˜f¤d×+Ò+·3³3Ñ6tÑmsÓ6t·3·3²3Ñ6tÑmsÓ6t×3tÒ3tÜÐ 0Ó1Ð1Ø�tÐ#Ð#r   c              ƒ  óÒ  a
aaaaaaaa"  € \        V4      w  ooo
o\        VP                  \        4      '       d   VP                  '       g   \	        R 4      h^ RIHp V! WVR4       V P                  oSP                  VP                  ,          o^ RI	H
p V! SV4      o\        SR4      '       g   / Sn        V SP                  VP                  &   SP                  o\        SP                  4      oV
VVVVVVV3R lpVV3R lpS\         9   d   V! 4       MRp\"        P$                  ! V4      G Rj  x€L
 pVe   V! 4       V8w  d   ^ RIHp	 V	! SVP                  4       V#  L/5i)	rn   )Ú	authorizezsession:control)Úphysical_targetr   c                 ó   <€ ^ RI Hp  ^ RIHp V ! S4      ;_uu_ 4        V! SSP                  4      ;_uu_ 4        \        SSS	SSS4      uuRRR4       uuRRR4       #   + '       g   i     M; iRRR4       R#   + '       g   i     R# ; i)é    )Ú_profile_runtime_scope)Ú_session_workspaceN)Úgateway.runr   Úgateway.session_commandsr€   Úsourcerl   )
r   r€   r]   r\   Úhomer(   r^   Úliver   r)   s
     €€€€€€€€r   ÚrunÚautomation.<locals>.runœ   sZ   ø€ Ý6Ý?Ù# D×)Õ)Ñ+=¸fÀdÇkÁk×+RÕ+RÜ˜& $¨°°d¸FÓC÷ ,SÑ+R×)Ò)×+R×+Rú×)×)×)Ò)ús"   žA<ºA	Á

A<ÁA/Á*A<Á<B	c                 ól   <€ \         ;QJ d    . V V3R  lR 4       F  NK  	  5# ! V V3R  lR 4       4      # )c              3  ód   <"  € T F%  pSP                   P                  V R S 24      x € K'  	  R# 5i)Ú:N)ÚdbÚget_meta)rr   r?   r   r)   s   & €€r   rs   Ú/automation.<locals>.<lambda>.<locals>.<genexpr>¡   s/   øé € ÐgÑIfÀA˜Ÿ™×.Ñ.°!°°A°f°X¨×?Ð?ÓIfùs   ƒ-0)r   r   r   )r=   )r   r)   s   €€r   rF   Úautomation.<locals>.<lambda>¡   s#   ø€ —5”5ÕgÑIfÓg—5Ðg�5ÕgÑIfÓgÔgr   N)Úpublish)ry   r0   r   r1   r   Úgateway.session_busy_controlsr{   r   ÚsessionsÚgateway.session_ancillaryr|   r4   r   r   r   Ú
profile_idÚ_READSÚasyncioÚ	to_threadÚgateway.session_control_actionsr�   )r   Úrefrx   r{   r|   r†   ÚrowsÚbeforeÚresultr�   r]   r   r\   r„   r(   r^   r…   r   r)   s   &&&       @@@@@@@@@r   Ú
automationrœ   Œ   s   ÿøé € Ü% f›~Ñ€Dˆ$��fÜ�c—n‘n¤c×*Ò*°#·.·.°.ÜÐ 0Ó1Ð1Ý7Ùˆj˜vÐ'8Ô9Ø×$Ñ$€IØ×Ñ˜cŸn™nÕ-€DÝ9Ù˜Y¨Ó,€FÜ�9Ð1×2Ò2Ø&(ˆ	Ô#Ø2<€I×Ñ §¡Ñ/Ø×Ñ€FÜ�	×$Ñ$Ó%€D÷Dô Dõ
 h€Dàœv”~‰TŒV¨4€Fä×$Ò$ SÓ)×)€FØ‚~™› 6Ô)å;Ù�	˜3Ÿ>™>Ô*Ø€Mñ *ùs   ‹AE'ÁC'E'Ä5E%Ä60E'>   rQ   ÚclearÚpauserV   ÚresumerB   Úwait_onÚadd_gateÚ	mark_doneÚ
is_waitingÚadd_subgoalÚclear_gatesÚremove_gateÚstop_waitingÚclear_subgoalsÚremove_subgoalÚwait_on_sessionÚwait_for_secondsrJ   >	   rQ   r�   rž   rV   rŸ   Ú	fire_tickÚabandon_tickÚcomplete_tickrT   >   rQ   r�   rž   rV   rŸ   Ú
due_promptÚabandon_fire>   rV   r£   rT   >   r]   r\   r(   r^   Úprofiler   )Ú__doc__Ú
__future__r   r•   r5   Úpathlibr   Úhermes_state_runtimer   Ú	frozensetrv   r”   ru   ÚRuntimeErrorÚ
ValueErrorÚ
IndexErrorrh   r   r    r*   r;   rc   ÚobjectrZ   rl   ry   rœ   r   r   r   Ú<module>r»      s§   ðñõ #ã Û Ý å 2ð ‰Iò kó lð ‰Iò +ó ,à‘ÒeÓfð
€ñ 
Ò>Ó	?€Ù
ÒOÓ
P€Ø˜ ZÐ
0€õUòò/òò"ñ< ‹x€õò $ôr   