+
    lHàjp  ã            
      óŠ  € R t ^ RIHt ^ RIt^ RIt^RIHtHt ]! 4       tR5t	R R lt
R R ltRR	/R
 R lltR R lt]P                  RR	/R R ll4       tR R ltR R ltR R ltR R ltR R ltR R ltR R ltR6R R lltR  R! ltR"tR#R$R%R	R&RR'RR(R	/R) R* lltR+ R, ltR- R. ltR/ R0 ltR6R1 R2 lltR3 R4 ltR# )7zþModel switching for a live session: persist, snapshot/restore runtime, /model apply with
guards, bot-capability + config sync. Bodies are rebound onto server.py's globals at install
time (method_ctx.bind_module), so they reference server.py globals bare.)ÚannotationsN)ÚHandlerRegistryÚbind_modulec               ó   € V ^8„  d   QhRR/# )é   ÚreturnÚdict© )Úformats   "Ú=/home/ubuntu/.hermes/hermes-agent/tui_gateway/model_switch.pyÚ__annotate__r      s   € ÷ Xñ X¨Dñ Xó    c                óØ   € / \          Uu/ uF  q\        WR4      bK  	  upCR\        P                  ! \        V RR4      4      R\        P                  ! \        V RR4      4      /C# u upi )z?Capture the current agent model runtime for a one-turn restore.Ú Úreasoning_configNÚprimary_runtimeÚ_primary_runtime)Ú_RUNTIME_KEYSÚgetattrÚcopyÚdeepcopy)ÚagentÚks   & r   Ú_snapshot_agent_model_runtimer      sj   € ðXµÓ?±¨A”'˜% BÓ'Ò'±Ñ?ð XØ¤§¢¬g°eÐ=OÐQUÓ.VÓ WØœtŸ}š}¬W°UÐ<NÐPTÓ-UÓVñXð XùÒ?s   ŠA'c               ó    € V ^8„  d   QhRRRR/# )r   Úsnapshotúdict | Noner   ÚNoner	   )r
   s   "r   r   r      s   € ÷ Bñ B°+ð BÀ$ñ Br   c           
     ój  a€ S'       d   V f   R# RS9   d   SR,          V n         SP                  R4      pV'       dk   \        V R4      '       dY    \        P                  ! V4      V n        RV n        ^ V n        V P                  4       '       d   RS9   d   SR,          V n         R#  \        V R4      '       dR   V3R	 l\         4       w  r4rVpV P                  W4WVVSP                  R
4      R7       RS9   d   SR,          V n         R# R# R#   \         d    \        P                  RRR7        L‰i ; i)zCRestore an agent model runtime captured before a one-turn override.Nr   r   Ú_restore_primary_runtimeTz5TUI one-turn model restore via primary runtime failed)Úexc_infoÚswitch_modelc              3  óH   <"  € T F  pSP                  VR 4      x € K  	  R# 5i©r   N)Úget)Ú.0r   r   s   & €r   Ú	<genexpr>Ú/_restore_agent_model_runtime.<locals>.<genexpr>.   s"   øé € Ð7cÑUbÐPQ¸¿¹ÀQÈ×8KÐ8KÓUbùs   ƒ"Úcapabilities©Ú	new_modelÚnew_providerÚapi_keyÚbase_urlÚapi_moder(   )r   r$   Úhasattrr   r   r   Ú_fallback_activatedÚ_rate_limited_untilr   Ú	ExceptionÚloggerÚdebugr   r!   )r   r   ÚprimaryÚmodelÚproviderr,   r-   r.   s   &f      r   Ú_restore_agent_model_runtimer8      s'  ø€ ç�u’}Ùð ˜XÔ%Ø!)Ð*<Õ!=ˆÔØ�l‰lÐ,Ó-€Gß”7˜5Ð"<×=Ò=ð		aÜ%)§]¢]°7Ó%;ˆEÔ"Ø(,ˆEÔ%Ø()ˆEÔ%Ø×-Ñ-×/Ò/Ø%¨Ô1Ø-5Ð6HÕ-I�EÔ*Ùð 0ô ˆu�n×%Ò%Ü7cÕUbÓ7cÑ4ˆ˜¨HØ×ÑØ¸GØ¨H¯L©L¸Ó,Hð 	ô 	Jð  Ô)Ø%-Ð.@Õ%AˆEÖ"ñ *ñ &øô ô 	aÜ�L‰LÐPÐ[_ˆLÖ`ð	aús   Á>D ÂD Ä"D2Ä1D2Úhydrate_secretsTc               ó    € V ^8„  d   QhRRRR/# )r   r9   Úboolr   Ú_TurnScopesr	   )r
   s   "r   r   r   6   s   € ÷ 7ñ 7ÀDð 7ÐT_ñ 7r   c               ó<  € ^ RI Hp \        4       p V '       dI   \        V 4      pV'       d   ^ RIHp V! V4       \        V4      pRp\        \        V4      4      Vn	        MY^ RI
HpHp	 \        4       pV! V4      p\        V4      Vn        V! 4       '       g   V# \        \        V4      4      Vn	        V	! 4       pVP                  f%   \        Y`'       d   \        V4      MRR7      Vn        ^ RIHp
 V
! WGR7      Vn        V#   \&         d    \)        T4       h i ; i)u  Bind HERMES_HOME + secret + terminal scope for ``profile_home`` (None = launch profile) and
return the reset tokens. The launch profile's SECRET scope is always bound â€” its ``.env`` over
the launch env (live while single-profile, frozen at activation afterwards; never live
``os.environ`` once a secondary context may have written to it, #107422) â€” so the credential
source is fixed at entry and an in-flight launch body survives a concurrent first-secondary
activation instead of hitting ``UnscopedSecretError`` mid-request. Its terminal policy is bound
only once multiplexing is active: single-profile terminal execution keeps the standalone
``os.environ`` bridge.

``hydrate_secrets=False`` skips resolving the profile's EXTERNAL secret sources (``op run``,
``bws``, ``sh -c`` â€” a subprocess with a 30s CLI budget holding a process-global lock). Pass it
from any body that persists state rather than calls a provider: the exit-flush worker has a 5s
TOTAL budget, and one slow source there costs the transcript the flush exists to save.
)Úis_multiplex_active)Úhydrate_profile_secret_sourcesN)Úlaunch_secret_scopeÚlaunch_terminal_env)Úprofile_home)Úinstall_profile_terminal_scope)Úenv_overlay)Úagent.secret_scoper>   r<   ÚPathÚhermes_cli.env_loaderr?   Úbuild_profile_secret_scopeÚset_hermes_home_overrideÚstrÚhomeÚ!tui_gateway.launch_profile_policyr@   rA   Ú_launch_homeÚset_secret_scopeÚsecretÚtools.terminal_scoperC   Úterminalr2   Ú%_release_profile_runtime_scope_tokens)rB   r9   r>   ÚscopesrK   r?   ÚsecretsÚoverlayr@   rA   rC   s   &$         r   Ú_profile_runtime_scope_tokensrV   6   sí   € õ 7Ü‹]€Fð&ßÜ˜Ó%ˆDçÝPÙ.¨tÔ4Ü0°Ó6ˆGØˆGÜ2´3°t³9Ó=ˆF�K÷ cÜ“>ˆDÙ)¨$Ó/ˆGô -¨WÓ5ˆFŒMÙ&×(Ò(Ø�Ü2´3°t³9Ó=ˆFŒKÙ)Ó+ˆGØ�=‰=Ò Ü,¨WÖP\Ä3ÀtÄ9ÐbfÔgˆFŒMõ 	HÙ8¸ÔSˆŒØˆøÜô ô 	.¨fÔ5Øð	ús   ’BD ÂA'D ÄDc               ó    € V ^8„  d   QhRRRR/# )r   rS   z_TurnScopes | Noner   r   r	   )r
   s   "r   r   r   p   s   € ÷ ñ Ð2Dð Èñ r   c                ó
  € V f   R# ^ RI Hp RpV P                  V3V P                  \        3V P
                  \        33 F  w  r4Vf   K   V! V4       K  	  Ve   VhR#   \         d   pT;'       g    Tp Rp?K=  Rp?ii ; i)u4  Release terminal â†’ secret â†’ home. Each reset is independent: a failing terminal reset must
not leave the previous profile's secrets / HERMES_HOME installed for the next body in this
context (a fail-open scope leak on the teardown path). The first failure is re-raised after
every scope has been released.N)Úreset_terminal_scope)rP   rY   rQ   rO   Úreset_secret_scoperK   Úreset_hermes_home_overrider2   )rS   rY   Úfirst_errorÚtokenÚresetÚexcs   &     r   rR   rR   p   s�   € ð
 ‚~ÙÝ9Ø(,€KØ Ÿ/™/Ð+?Ð@À6Ç=Á=ÔRdÐBeØ Ÿ+™+Ô'AÐBóD‰ˆàŠ=Ùð	-Ù�%ŽLñDð ÒØÐñ øô ô 	-Ø%×,Ð,¨ŽKûð	-ús   ÁA Á BÁ+A=Á=Bc               ó    € V ^8„  d   QhRRRR/# )r   Úsessionr   r9   r;   r	   )r
   s   "r   r   r   †   s   € ÷ 6ñ 6¨Dð 6Àdñ 6r   c             #  ó†   "  € \        V P                  R4      VR7      p Rx € \        V4       R#   \        T4       i ; i5i)z Bind model resolution to the session's profile config and secrets (launch profile included
once the process multiplexes; see ``_profile_runtime_scope_tokens``).rB   ©r9   N)rV   r$   rR   )ra   r9   rS   s   &$ r   Ú_session_profile_runtime_scoperd   …   s6   é € ô +¨7¯;©;°~Ó+FÐXgÔh€Fð6Ûä-¨fÖ5øÔ-¨fÕ5üs   ‚A 1 ¤A±>¾Ac               ó    € V ^8„  d   QhRRRR/# )r   ra   r   r   ztuple[str, str]r	   )r
   s   "r   r   r   �   s   € ÷ $ñ $ Dð $¨_ñ $r   c                ó,  € ^ RI HpHp \        RV P	                  R4      ;'       g    R/RR7      ;_uu_ 4        \        4       ^,          '       g   V! 4       '       d   VR3uuRRR4       # \        4       R3uuRRR4       #   + '       g   i     R# ; i)aÍ  ``(model, provider)`` a not-yet-built session of its OWN profile will run on. Bare
``_resolve_startup_runtime()`` reads the LAUNCH profile's config, so a secondary session's reply or
first state.db row carried the launch profile's model id. On the Nous free tier the agent build pins
``nous/welcome`` (``pin_model_for_route``), so the configured default (often the silent default,
with no provider) is not what the session runs; report the pinned route instead.)ÚGUEST_MODELÚfree_tier_routerB   NFrc   Únousr   )Úhermes_cli.anon_authrg   rh   rd   r$   Ú_resolve_startup_runtimeÚ_resolve_model)ra   rg   rh   s   &  r   Ú_session_default_routerm   �   s{   € ÷ BÜ	'¨¸¿¹À^Ó9T×9\Ð9\ÐX\Ð(]Ø8=÷
?ö 
?ä'Ó)¨!×,Ô,±×1BÒ1BØ Ð&÷
?ò 
?ô
 Ó Ð#÷
?÷ 
?÷ 
?ó 
?ús   ¹$BÁBÁ,BÂB	c               ó$   € V ^8„  d   QhRRRRRR/# )r   ra   r   Úoverrider   r	   )r
   s   "r   r   r   Ÿ   s&   € ÷ Lñ L˜dð L¨dð L°tñ Lr   c                ó–   € V'       d#   VP                  R4      VP                  R4      3M
\        V 4      w  r#RV/V'       d   RV/C# / C# )z³``session.info``'s model and provider for a not-yet-built session: the client's sticky pick when it
sent one (so the client does not clobber it), else the profile's default route.r6   r7   )r$   rm   )ra   ro   r6   r7   s   &&  r   Ú_lazy_info_routerq   Ÿ   sN   € ÷ LT�x—|‘| GÓ,¨h¯l©l¸:Ó.FÑGÔYoÐpwÓYx�O€EØ�UÐK¿ 
¨HÐ5ÐKÐKÀrÐKÐKr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   ÚsidrJ   ra   r   Úfailed_readyzthreading.Event | Noner   r;   r	   )r
   s   "r   r   r   ¦   s*   € ÷ ñ ¨sð ¸Tð ÐQgð Ðlpñ r   c                ó  € Vf   R# VP                  R\        P                  4       4      ;_uu_ 4        VP                  R4      f?   VP                  R4      e,   VP                  R4      VJg   VP	                  4       '       g    RRR4       R# VP                  R4      pVP                  R4      p\        V\        4      '       dS   \        V\        4      '       d=   / VCRV/CpVP                  R	4      ;p'       d   WTR
&   MVP                  R
R4       WAR&   RVR&   \        P                  4       VR&   VP                  RR4       VP                  RR4       RRR4       \        W4       R#   + '       g   i     L; i)zBReplace one completed failed build generation and start its retry.NFÚagent_build_lockr   Úagent_errorÚagent_readyÚmodel_overrideÚresume_runtime_overridesr7   Úprovider_overrideÚagent_build_startedÚ_agent_build_threadT)
Ú
setdefaultÚ	threadingÚLockr$   Úis_setÚ
isinstancer   ÚpopÚEventÚ_start_agent_build)rs   ra   rt   ry   Úresume_overridesr7   s   &&&   r   Ú%_restart_completed_failed_agent_buildr‡   ¦   sL  € àÒÙØ	×	Ñ	Ð.´	·±Ó0@×	AÕ	AØ�K‰K˜Ó Ò,°·±¸MÓ0JÒ0RØ—;‘;˜}Ó-°\ÓAÈ×I\ÑI\×I^ÒI^Ø÷ 
BÑ	Að !Ÿ™Ð%5Ó6ˆØ"Ÿ;™;Ð'AÓBÐÜ�n¤d×+Ò+´
Ð;KÌT×0RÒ0RØUÐ"2ÐUÐ4DÀnÑUÐØ)×-Ñ-¨jÓ9Ð9ˆxÖ9Ø8@Ð!4Ò5à ×$Ñ$Ð%8¸$Ô?Ø2BÐ.Ñ/Ø!%ˆ�ÑÜ!*§¡Ó!2ˆ�ÑØ�‰Ð)¨4Ô0Ø�‰Ð)¨4Ô0÷! 
Bô" �sÔ$Ù÷% 
B×	Aús    ³AE/ÂE/ÂA.E/Ã?AE/Å/E?	c               ó    € V ^8„  d   QhRRRR/# )r   Ú	raw_inputrJ   r   z tuple[str, str, bool, bool, str]r	   )r
   s   "r   r   r   ¿   s   € ÷ pñ p˜sð pÐGgñ pr   c           	     ó®  € ^ RI HpHpHpHp Vf	   V! V 4      MTpVP
                  VP                  VP                  VP                  VP                  3w  r‰r«p\        VRR4       F  p\        WM,          4      h	  V
'       d   V'       d   \        WC,          4      hVf   V! W«WÉR7      pV'       g   \        R4      hY‰YÂ\        VRR4      ;'       g    R3# )uh   Normalize /model flags â†’ (model_input, explicit_provider, one_turn, persist_global, reasoning_effort).)Ú!MODEL_SWITCH_ERR_ONCE_WITH_GLOBALÚMODEL_SWITCH_ERROR_TEXTÚparse_model_switch_argsÚresolve_persist_behaviorÚerrors)Úis_onceÚexplicit_providerzmodel value requiredÚreasoning_effortr   r	   )Úhermes_cli.model_switchr‹   rŒ   r�   rŽ   Úmodel_inputr‘   Ú	is_globalÚ
is_sessionr�   r   Ú
ValueError)r‰   Úparsed_flagsÚpersist_overrider‹   rŒ   r�   rŽ   Úfr”   r‘   Úis_global_flagr–   Úone_turnÚcodes   &&&           r   Ú_switch_requestrž   ¿   sÐ   € ÷"ó "ð /;Ò.BÑ 	Ô*È€Aà	�‰�q×*Ñ*¨A¯K©K¸¿¹ÀqÇyÁyðLRÑH€K NÀô ˜˜8 RÖ(ˆÜÐ0Õ6Ó7Ð7ñ )çŸ(ÜÐ0ÕSÓTÐTØÒÙ3Ø°ô_ÐçÜÐ/Ó0Ð0Ø¨8ÄwÈqÐRdÐfhÓGi×GoÐGoÐmoÐoÐor   c               ó    € V ^8„  d   QhRRRR/# )r   r‘   rJ   r   Útupler	   )r
   s   "r   r   r   Õ   s   € ÷ Pñ P°Sð P¸Uñ Pr   c                ó.  a € S '       d3   \         ;QJ d    . V 3R lR	 4       F  NK  	  5# ! V 3R lR	 4       4      # \        4       pV'       d   VP                  4       VRR3# ^ RIHp T! RT;'       g    RR7      pVP                  RR4      p\        V4      '       d   \        V\        4      '       d   \        T;'       g    R4      p\        VP                  RR4      ;'       g    R4      pYb\        VP                  RR4      ;'       g    R4      V3# )
zY(provider, model, base_url, api_key) to switch from: live agent, else configured runtime.c              3  óR   <"  € T F  p\        SVR 4      ;'       g    R x € K  	  R# 5ir#   )r   )r%   r   r   s   & €r   r&   Ú)_current_model_runtime.<locals>.<genexpr>Ø   s*   øé € ð _Ù1]¨AŒG�E˜1˜bÓ!×'Ð' RÔ'Ó1]ùs   ƒ'œ'r7   r-   r,   r   )Úresolve_runtime_providerN)Ú	requestedÚtarget_model)r7   r6   r-   r,   )	r    rl   ÚstripÚhermes_cli.runtime_providerr¤   r$   Úcallabler‚   rJ   )r   r‘   Úcurrent_modelr¤   ÚruntimeÚkeyr7   s   f&     r   Ú_current_model_runtimer­   Õ   sò   ø€ çßŒuô _Ù1]ó_�uð 	_ˆuô _Ù1]ó_ó _ð 	_ä"Ó$€MßØ ×&Ñ&Ó(¨-¸¸RÐ?Ð?ÝDÙ&°ÀM×DYÐDYÐUYÔZ€Gð �+‰+�i Ó
$€CÜ�S�MŠM¤*¨S´#×"6Ò"6Ü�#—)�)˜‹nˆÜ�7—;‘;˜z¨2Ó.×4Ð4°"Ó5€HØ¤C¨¯©°JÀÓ(C×(IÐ(IÀrÓ$JÈCÐOÐOr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r‘   rJ   Úcurrent_providerr   ú
str | Noner	   )r
   s   "r   r   r   è   s"   € ÷ -ñ -°Cð -È3ð -ÐS]ñ -r   c                óð   € V '       g	   V'       g   V# \         P                  P                  RR4      P                  4       ;p'       d   V# \	        4       '       d   R# \        4       ^,          ;'       g    R# )a,  The provider of the model the user leaves. Agent-less with ``--provider``, ``current_provider``
is the TARGET (what switch_model wants), so the launch route names it instead; None when only a
credential resolve could tell, which the metric reads as ``unknown`` and so reports the model as
``custom``.ÚHERMES_TUI_PROVIDERr   N)ÚosÚenvironr$   r§   Ú_env_model_seedÚ_config_model_target)r   r‘   r¯   Úenv_providers   &&& r   Ú_switch_away_providerr¸   è   s\   € ÷
 ×%ØÐÜ—z‘z—~‘~Ð&;¸RÓ@×FÑFÓHÐH€|ÖHØÐÜ×ÒÙÜÓ! !Õ$×,Ð,¨Ð,r   c               ó    € V ^8„  d   QhRRRR/# )r   ra   r   r   r   r	   )r
   s   "r   r   r   ö   s   € ÷ Mñ M°Tð MÐQUñ Mr   c           
     óˆ  €  ^ RI Hp Rp\        V\        4      '       d   VP	                  R/ 4      MRp\        V\        4      '       d&   VP	                  R4      e   \        VR,          4      pV! W\        VP	                  R. 4      4      WFR7       R#   \         d"   p\        P                  RT4        Rp?R# Rp?ii ; i)zMFold the context-compression preflight warning into ``result`` (best-effort).)Ú#merge_preflight_compression_warningNr6   Úcontext_lengthÚhistory)r   ÚmessagesÚcustom_providersÚconfig_context_lengthz/preflight-compression switch warning failed: %s)
Úhermes_cli.context_switch_guardr»   r‚   r   r$   ÚintÚlistr2   r3   r4   )	Úresultr   ra   ÚcfgÚcustom_provsr»   Úcfg_ctxÚmcr_   s	   &&&&&    r   Ú_merge_preflight_warningrÉ   ö   s¡   € ð
MÝWØˆÜ%/°´T×%:Ò%:ˆS�W‰W�W˜bÔ!ÀˆÜ�bœ$×Ò B§F¡FÐ+;Ó$<Ò$HÜ˜"Ð-Õ.Ó/ˆGÙ+Ø¬$¨w¯{©{¸9ÀbÓ/IÓ*JØ)÷	Jøô ô MÜ�‰ÐFÈ×LÒLûðMús   ‚BB ÂCÂ B<Â<Cc               ó    € V ^8„  d   QhRRRR/# )r   Úcurrent_base_urlrJ   r   r   r	   )r
   s   "r   r   r     s   € ÷ iñ i°sð iÐ\gñ ir   c           
     ó”  €  ^ RI HpHp T! V P                  V P                  V P
                  ;'       g    TV P                  ;'       g    TV P                  V! V4      R7      pVf   R# V P                  '       d   VP                   RV P                   2MVP                  pRV P                  RVRRR	V/#   \         d    Rp Lbi ; i)
u�   Deferred-confirm response when the selection guards flag the target model (or, with a live
``agent``, the switch itself â€” large cached context), else None.©Úcombined_selection_warningÚselection_context_for_agent)r7   r-   r,   Ú
model_infoÚselection_contextNz

ÚvalueÚwarningÚconfirm_requiredTÚconfirm_message)Ú!hermes_cli.model_selection_guardsrÎ   rÏ   r*   Útarget_providerr-   r,   rÐ   r2   Úwarning_messageÚmessage)rÄ   rË   Úcurrent_api_keyr   rÎ   rÏ   rÓ   Úmsgs   &&&&    r   Ú_expensive_model_confirmrÜ     sÇ   € ð÷	Eá,Ø×Ñ v×'=Ñ'=ÈÏÉ×HkÐHkÐ[kØ—N‘N×5Ð5 oÀ&×BSÑBSÙ9¸%Ó@ôBˆð ‚ÙØ>D×>T×>TÐ>TˆW�_‰_Ð˜T &×"8Ñ"8Ð!9Ñ
:ÐZa×ZiÑZi€Cà�V×%Ñ% y°#Ð7IÈ4ÐQbÐdgÐhÐhøô ô ØŠðús   ‚2B7 µB7 Á
B7 Â7CÃCc               ó$   € V ^8„  d   QhRRRRRR/# )r   rs   rJ   ra   r   rª   r	   )r
   s   "r   r   r     s"   € ÷ 4ñ 4˜cð 4¨Dð 4ÐPSñ 4r   c                ó*  €  VP                  VP                  VP                  VP                  VP                  VP
                  \        VRR4      R7       \        Y4       \        T4       \        T4       \        YP                  TP                  R
7       \        Y4       Te   YQR&   R# TP!                  RR4       R#   \         dG   p\        P                  RT4       \        RTP                   RT R\        TRT4       R	24      ThRp?ii ; i)zWSwap the live agent in place, then restart/persist/mark/announce; a failed swap aborts.Úruntime_capabilitiesNr)   z.In-place model switch failed for TUI agent: %szModel switch to z	 failed (z); staying on r6   Ú.)r6   r7   Úone_turn_model_restore)r!   r*   r×   r,   r-   r.   r   r2   r3   rÓ   r—   Ú_restart_slash_workerÚ_persist_live_session_runtimeÚ#_persist_live_session_system_promptÚ_append_model_switch_markerÚ_emit_session_inforƒ   )rs   ra   r   rÄ   rª   r   r_   s   &&&&&& r   Ú_commit_agent_switchrç     s  € ð[Ø×ÑØ×&Ñ&°V×5KÑ5KÐU[×UcÑUcØ—_‘_¨v¯©Ü  Ð)?ÀÓFð 	ô 	Hô ˜#Ô'Ü! 'Ô*Ü'¨Ô0Ü ×/?Ñ/?È&×J`ÑJ`ÕaÜ�sÔ$ØÒØ,4Ð(Ó)à�‰Ð,¨dÖ3øô% ô 	[ô 	�‰ÐGÈÔMÜÐ+¨F×,<Ñ,<Ð+=¸YÀsÀeð L'Ü'.¨u°g¸}Ó'MÐ&NÈaðQó RØWZð	[ûð	[ús   ‚AC ÃDÃADÄDzmodel.large_noticeÚconfirm_expensive_modelFÚpin_session_overrider˜   r™   Úcount_switchc               ó<   € V ^8„  d   QhRRRRRRRRRRR	R
RRRRRR/	# )r   rs   rJ   ra   r   r‰   rè   r;   ré   r˜   z
Any | Noner™   zbool | Nonerê   r   r	   )r
   s   "r   r   r   7  sr   € ÷ TVñ TVØ	ðTVØðTVØ(+ðTVØIMðTVàðTVà5?ðTVð "ðTVð 9=ðTVð IMñTVr   c               óô  € ^ RI Hp \        W%V4      w  ršr¼pVP                  R4      pV'       d   V'       g   \	        R4      h\        Wê4      w  ppppR;p;pp\        P                  ! \        4      ;_uu_ 4        ^ RI	H
pHp V! 4       pVP                  R4      pV! V4      pRRR4       V! WŸVVVVV
VVR7	      pVP                  '       g    \	        VP                  ;'       g    R4      hV'       d   V'       d   \        V4      MRpV'       d   \        VWáVV4       V'       g   \!        VVVV4      pVe   V# T;'       dH    \#        V\$        4      ;'       d0    V'       * ;'       d!    V'       * ;'       d    VP                  R	4      pR
V9   pVP                  R
4      pV'       d   \'        4       w  ppRVRV/VR
&    V'       d   \)        WVVVV4       T'       d`   \#        T\$        4      '       dJ   T'       gB   RTP,                  RTP.                  RTP0                  RTP2                  RTP4                  /TR&   T'       d   ^ RI Hp  T ! T4       T'       d   \9        YYíYËR7       T'       d<   ^ RIHp! T!! \?        YêT4      TP.                  \A        T4      T\C        TRR4      R7       \C        TRR4      ;p"'       d-   T '       d%   \E        RT RRT" 2RRRRRR R!\F        R"\F        /4       R#TP,                  R$TPH                  ;'       g    RR%R&R'T'       d   R(/# T'       d   R)/# R*/#   + '       g   i     EL“; i  \         d+    T'       d!   T'       d   TTR
&   h TP+                  R
R4       h i ; i)+z§``count_switch=False``: an internal swap (config adoption, MoA one-shot and its restore), not a
user's /model pick, so it stays out of the shared-metrics switch count.)r!   r   z%/model --once requires a live sessionN)Úget_compatible_custom_providersÚload_configÚ	providers)	r‰   r¯   rª   rË   rÚ   r•   r‘   Úuser_providersr¿   zmodel switch failedÚfollow_profile_configÚcomposer_override_profiler6   r7   r-   r,   r.   ry   )Úpersist_model_selection)Úpersist_globalrœ   )Úrecord_model_switchÚ
session_id)Úfrom_providerÚto_providerÚsurfaceÚ
from_modelrö   Úusage_noticer   znotification.showÚtextu   âš  ÚlevelÚwarnÚkindÚttlÚttl_msi@  r¬   ÚidrÒ   rÓ   rÔ   FÚscopeÚonceÚglobalra   )%r“   r!   rž   r$   r—   r­   Ú
contextlibÚsuppressr2   Úhermes_cli.configrí   rî   ÚsuccessÚerror_messager   rÉ   rÜ   r‚   r   r¶   rç   rƒ   r*   r×   r-   r,   r.   ró   Ú_apply_switch_reasoningÚ.hermes_cli.observability.shared_metrics_eventsrõ   r¸   Ú_session_sourcer   Ú_emitÚLARGE_MODEL_NOTICE_KEYrØ   )#rs   ra   r‰   rè   ré   r˜   r™   rê   r!   r”   r‘   rœ   rô   r’   r   r¯   rª   rË   rÚ   Ú
user_provsrÆ   rÅ   rí   rî   rÄ   Úrestore_snapshotÚconfirmÚrecords_composer_overrideÚhad_composer_profileÚprevious_composer_profileÚprofile_modelÚprofile_providerró   rõ   Únotices#   &&&$$$$$                           r   Ú_apply_model_switchr  7  sƒ  € õ 5ÜQ`ØÐ!1óR3ÑN€K HÐ>Nà�K‰K˜Ó €EßŸÜÐ@ÓAÐAÜI_ØóJ"ÑFÐ�mÐ%5°ð '+Ð*€JÐ*� Ü	×	Ò	œY×	'Õ	'ßRÙ‹mˆØ—W‘W˜[Ó)ˆ
Ù6°sÓ;ˆ÷	 
(ñ
 ØÐP]Ø)¸?ÐVdØ+¸JØ%ô	'€Fð
 �>�>ˆ>Ü˜×-Ñ-×FÐFÐ1FÓGÐGß@HÏUÔ4°UÔ;ÐY]ÐßÜ  ¨¸¸lÔKß"Ü*¨6Ð3CÀ_ÐV[Ó\ˆØÒØˆNà÷ 	Hð 	H¤¨G´TÓ!:÷ 	Hð 	HÀ8¼|÷ 	Hð 	HØÔ÷	Hð 	HØ#*§;¡;Ð/FÓ#Gð ð 7¸'ÑAÐØ '§¡Ð,GÓ HÐß Ü*>Ó*@Ñ'ˆÐ'à�] JÐ0@ð0BˆÐ+Ñ,ð
ßä  ¨u°f¸mÐM]Ô^÷ ¤
¨7´D× 9Ò 9Ç(à�V×%Ñ% z°6×3IÑ3IØ˜Ÿ™¨°F·N±NÀJÐPV×P_ÑP_ð%aˆÐ Ñ!÷ ÝCÙ Ô'ßÜ ¨eÐVdÕxßÝVáÜ/°ÐJZÓ[Ø×.Ñ.¼ÈÓ8PÐ]jÜ˜u l°DÓ9õ	;ô ˜& .°"Ó5Ð5ˆÖ5¿3ô 	Ð! 3Ø�d˜6˜(�O W¨f°f¸eÀXÈtØÔ)¨4Ô1Gð)Iô 	Jð 	�×!Ñ! 9¨f×.DÑ.D×.JÐ.JÈØ˜EØŸ8�ðVð V÷ 7E¨(ðVð Vð KTðVð V÷A 
(×	'Ð	'ûô@ ô ß$ß#Ø7P�Ð3Ñ4ð 	ð —‘Ð7¸Ô>Øðús*   Á;)L.ÇM Ç
M Ì.L?	ÍM7ÍM7ÍM7c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   rs   rJ   Úeffortrô   r;   rœ   r   r   r	   )r
   s   "r   r   r   Ž  s2   € ÷ )ñ ) ð )¸cð )ÐVZð )Ðfjð )Ðosñ )r   c               ó  € ^ RI Hp V! V4      pVf   R# Ve   Wrn        V'       g   \        V\        4      '       g   R# V'       d    \        RV4       VP                  RR4       MWqR&   Ve   \        V4       \        W4       R# R# )uf  ``/model X --reasoning <level>``: the effort rides with the pick and shares its scope. Runs
AFTER ``agent.switch_model`` (which re-resolves ``reasoning_config`` from config.yaml, so an
earlier write would be clobbered). ``--once`` restores through ``one_turn_model_restore`` â€”
the snapshot's ``primary_runtime`` carries the pre-switch ``reasoning_config``.)Úparse_reasoning_effortNzagent.reasoning_effortÚcreate_reasoning_override)	Úhermes_constantsr  r   r‚   r   Ú_write_config_keyrƒ   rã   ræ   )rs   ra   r   r  rô   rœ   r  Úparseds   &&&&$$  r   r  r  Ž  sx   € õ
 8Ù# FÓ+€FØ‚~ÙØÒØ!'Ôß”z '¬4×0Ò0ÙßÜÐ2°FÔ;Ø�‰Ð/°Õ6à/5Ð+Ñ,ØÒÜ% gÔ.Ü˜3Ö(ñ r   c               ó$   € V ^8„  d   QhRRRRRR/# ©r   rs   rJ   ra   r   r   r   r	   )r
   s   "r   r   r   ¥  s&   € ÷ #Hñ #H ð #H¨dð #H°tñ #Hr   c                ó~  € VP                  R4      pVf   R#  \        \        VRR4      ;'       g    R4      P                  4       pV'       gl   \        VRR4      VP                  R4      ;'       g    RrT\        V'       d   V'       d   VP	                  V4      MR;'       g    R4      P                  4       pVR8w  d   R# ^ RIHp T! VP                  R	4      ;'       g    R4      pVR
8X  d   R# VP                  R4      pWqR&   Ve   W‡8X  d   R#   \        T \        T4      R7      p	 \        YTR,          \        T4      R7      p
\        T	4       RT
n        \        RT RR/4       R#   \         d     R# i ; i  \        T	4       i ; i  \         d"   p\        P!                  RY4        Rp?R# Rp?ii ; i)a1  Rebuild a Bot Chat session's agent when its capability surface changed. Bot Chats are
eternal sessions with toolsets/MCP baked in at construction, so a capability edit would
otherwise wait for /new: fingerprint at turn start and on change swap in a fresh agent for
the SAME session (history is DB-backed).r   NÚ_session_title_hintr   Ú_session_dbÚsession_keyzBot Chat)Úcapability_fingerprintrB   ÚunavailableÚbot_caps_seen)Úcwd)rö   Úplatform_overrider  rÙ   uD   Capabilities updated â€” this bot's tools and prompt were refreshed.z%Bot capability sync failed for %s: %s)r$   rJ   r   r§   Úget_session_titleÚtools.bot_mode_prober(  r2   Ú_set_session_contextÚ_session_cwdÚ_rebuild_session_agentr  Ú_clear_session_contextr%  r  r3   rÓ   )rs   ra   r   ÚtitleÚdbr¬   r(  ÚcurrentÚseenÚtokensÚ	new_agentÚes   &&          r   Ú_sync_bot_capabilitiesr:  ¥  s“  € ð
 �K‰K˜Ó €EØ‚}ÙðÜ”G˜EÐ#8¸"Ó=×CÐCÀÓD×JÑJÓLˆßÜ˜e ]°DÓ9¸7¿;¹;À}Ó;U×;[Ð;[ÐY[�Ü·r¿c˜×-Ñ-¨cÔ2È×SÐSÐQSÓT×ZÑZÓ\ˆEØ�JÔÙÝ?Ù(¨¯©°^Ó)D×)LÐ)LÈÓMˆØ�mÔ#ÙØ�{‰{˜?Ó+ˆØ#*�Ñ ØŠ<˜4œ?Ùð +ð
HÜ% c¬|¸GÓ/DÔEˆð	+Ü.¨sÈÐP]ÕH^ÜAPÐQXÓAYô[ˆIô # 6Ô*Ø(2ˆ	Ô%Üˆh˜˜iÐ)oÐpÖqøô ô Úðûô # 6Õ*ûô ô HÜ�‰Ð>À×GÒGûðHúsp   ™E. ²E. Á#E. Á3E. ÂE. Â%E. ÃE. Ã#E. Ã3E. ÄF Ä-F  Å!F Å.E=Å<E=Æ FÆF ÆF<ÆF7Æ7F<c               ó$   € V ^8„  d   QhRRRRRR/# r#  r	   )r
   s   "r   r   r   Ë  s&   € ÷ .eñ .e sð .e°Tð .e¸dñ .er   c           
     óÌ  a aa€ VP                  R4      pVf   R# \        4       pV^ ,          '       g   R# VP                  R4      pW48X  d   R# RpVP                  R4      '       d²   VP                  R4      p\        V\        4      '       de   \	        VP                  R4      ;'       g    R4      P                  4       \	        VP                  R4      ;'       g    R4      P                  4       3MRpVe   Ws8X  d   R# VP                  R4      V3pRVR&   W1R&   Vw  opS\        VRR4      8X  d,   V'       d   V\        VRR4      8X  d   Ve   \        V4       R# V'       d   S R	V 2MSp	 \        S WR
RRRR7       R#   \         dU   o\        P                  RSS S4       ^ RIHp
 T
! TTT 3R lR\        TP                  R4      RR4      R7        Ro>R# Ro>ii ; i)z¦Adopt a config.yaml model change at turn start (like gateways do per message). Sessions
pinned with /model keep their choice; a failed switch keeps the current model.r   NÚconfig_model_seenry   rò   r6   r   r7   z --provider TF)rè   ré   r™   rê   z;Configured model %s could not be adopted for session %s: %s)Úrender_notificationc            	     ó.   <€ \        R SRRS RS  2/4      # )ÚerrorrÙ   z%Could not switch to configured model z: )r  )r9  r6   rs   s   €€€r   Ú<lambda>Ú/_sync_agent_model_with_config.<locals>.<lambda>ø  s&   ø€ ”E˜' 3¨Ð6[Ð\aÐ[bÐbdÐefÐdgÐ4hÐ(iÔjr   ÚtuiÚ_notification_config)ÚplatformÚuser_config)r$   r¶   r‚   r   rJ   r§   rƒ   r   rã   r  r2   r3   rÓ   Úgateway.warning_notificationsr>  )rs   ra   r   Útargetr6  Úsuperseded_pinÚcomposer_profileÚpinned_profiler7   Úrawr>  r9  r6   s   f&         @@r   Ú_sync_agent_model_with_configrM  Ë  sÞ  ú€ ð �K‰K˜Ó €EØ‚}ÙÜ!Ó#€FØ�!�9Œ9ÙØ�;‰;Ð*Ó+€DØ„~ÙØ€NØ‡{�{Ð#×$Ò$Ø"Ÿ;™;Ð'BÓCÐô Ð(¬$×/Ò/ô Ð ×$Ñ$ WÓ-×3Ð3°Ó4×:Ñ:Ó<ÜÐ ×$Ñ$ ZÓ0×6Ð6°BÓ7×=Ñ=Ó?ñ
ð 6:ð 	ð Ò! ^Ô%=Ùð !Ÿ™Ð%5Ó6Ð8HÐHˆØ/3ˆÐ+Ñ,à#)ÐÑ Ø�O€Eˆ8ð ”˜˜w¨Ó+Ô+·XÀÌWÐUZÐ\fÐhjÓMkÔAkØÒ%Ü)¨'Ô2Ùß.6ˆUˆG�< ˜zÑ
*¸E€Cðeô 	Ø�°tÐRWØ"°÷	8øô ô eÜ�‰ÐTÐV[Ð]`ÐbcÔdÝEÙÞjØ¬°·±¸GÓ0DÐF\Ð^bÓ(c÷	eó 	eûðeús   Å1F ÆG#ÆA	GÇG#c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r6   rJ   r7   r   ÚAnyr   r°   r	   )r
   s   "r   r   r   ü  s)   € ÷ <ñ <¨Sð <¸Cð <Èð <ÐWañ <r   c                ó¤   € V '       g   R#  ^ RI HpHp T! Y;'       g    RV! V4      R7      pTe   TP                  # R#   \         d     R# i ; i)u´  Selection-guard message for a model queued mid-turn, or ``None``. Runs BEFORE the pick is
stashed (the client can still turn the response into a confirm prompt); only pre-resolution
inputs exist for the model guards, so they can only under-fire â€” ``_apply_model_switch`` is the
backstop. The live ``agent`` supplies the context-cache guard's session size here, since at turn
start that guard can no longer ask and would drop the pick.NrÍ   )r7   rÑ   )rÖ   rÎ   rÏ   r2   rÙ   )r6   r7   r   rÎ   rÏ   rÓ   s   &&&   r   Ú!_pending_switch_selection_warningrQ  ü  s^   € ÷ Ùð÷	Eá,Ø×,Ð,¨Ñ@[Ð\aÓ@bôdˆð &Ò1ˆ7�?‰?Ð;°tÐ;øô ô Úðús   ŒA  ŸA  Á AÁAc               ó   € V ^8„  d   QhRR/# )r   r   r   r	   )r
   s   "r   r   r     s   € ÷ 0ñ 0˜ñ 0r   c                ó2   € \        \        4       V RR7       R# )zQPublish this module's helpers + handlers onto ``server``, rebound to its globals.)ÚskipN)Ú_)r   Úglobals)Úservers   &r   ÚregisterrX    s   € ä”“	˜6¨×/r   )r6   r7   r,   r-   r.   )N) Ú__doc__Ú
__future__r   r  r   Ú
method_ctxr   r   Ú	_registryr   r   r8   rV   rR   Úcontextmanagerrd   rm   rq   r‡   rž   r­   r¸   rÉ   rÜ   rç   r  r  r  r:  rM  rQ  rX  r	   r   r   Ú<module>r^     sÿ   ðñLõ #ã Û ç 4áÓ€	ð I€õXõBð:7È4÷ 7õtð* ×Ñð6ÈTö 6ó ð6õ$õLõõ2põ,Põ&-õM÷iõ&4ð8 .Ð ðTVØPUðTVà!%ðTVàBFðTVð %)ðTVð @D÷TVõn)õ.#HõL.e÷b<÷$0r   