+
    „WÝjp  ã                  óT  € R t ^ RIHt ^ RIHt ^ RIHtHtHt ^ RI	H
t
 ]! RR7       ! R R4      4       t]! RR7       ! R	 R
4      4       tR R ltR R ltR%R R lltR%R R lltRtR R ltR%R R llt]]]3tRRRRRRRRRRRR/R R  lltR! R" ltRRRRRRRRRR/R# R$ lltR# )&u÷   Unified selection-time guard registry for model switching surfaces.

Guard modules (``model_cost_guard``, ``model_data_policy_guard``) keep their public APIs â€” existing
tests and mock patch points remain valid; this module only aggregates them.
)Úannotations)Ú	dataclass)ÚIterableÚListÚOptional)Ú	ModelInfoT)Úfrozenc                  óN   € ] tR t^t$ RtR]R&   R]R&   R]R&   R]R&   R]R&   RtR	# )
ÚSelectionWarningz@A selection-time warning a surface must confirm before applying.ÚstrÚkindÚtitleÚmodelÚproviderÚmessage© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r   ó    ÚUC:\Users\johnn\AppData\Local\hermes\hermes-agent\hermes_cli\model_selection_guards.pyr
   r
      s   ‡ áJà
ƒIØƒJØƒJØƒMØ‡Lr   r
   c                  ó8   € ] tR t^t$ RtRtR]R&   RtR]R&   RtR# )ÚSelectionContexta*  Live-session facts a surface threads into the registry. Model-only guards (cost, data-policy)
ignore it; guards about the *switch itself* (context-cache) need the size of the conversation at
stake and the model it is currently on. Surfaces without a live agent omit it and those guards
stay silent.NzOptional[int]Úcontext_tokensúOptional[str]Úcurrent_modelr   )	r   r   r   r   r   r   r   r   r   r   r   r   r   r      s   ‡ ñð
 %)€N�MÓ(Ø#'€M�=×'r   r   c               ó    € V ^8„  d   QhRRRR/# )é   ÚagentÚobjectÚreturnúOptional[SelectionContext]r   )Úformats   "r   Ú__annotate__r'   %   s   € ÷ fñ f vð fÐ2Lñ fr   c                óú   € V f   R#  \        V RR4      pV'       d!   \        \        VR^ 4      ;'       g    ^ 4      M^ pV^ 8:  d   R# \        T\        V RR4      ;'       g    RR7      #   \         d    ^ p L:i ; i)u]  :class:`SelectionContext` from a live ``AIAgent``.

Uses the compressor's measured ``last_prompt_tokens`` (what the provider billed
on the latest turn). ``session_prompt_tokens`` is a lifetime sum and is not live
occupancy, so it is not a fallback (#126343). ``None`` when no positive
measurement exists â€” the guard stays silent rather than guess.NÚcontext_compressorÚlast_prompt_tokensr   Ú )r   r   )ÚgetattrÚintÚ	Exceptionr   )r"   ÚccÚtokenss   &  r   Úselection_context_for_agentr1   %   sƒ   € ð ‚}ÙðÜ�UÐ0°$Ó7ˆßCE””W˜RÐ!5°qÓ9×>Ð>¸QÔ?È1ˆð �„{ÙÜ¨6ÄÈÐPWÐY[ÓA\×AdÐAdÐ`dÔeÐeøô	 ô ØŠðús   ˆ-A* ¶	A* Á*A:Á9A:c               ó(   € V ^8„  d   QhRRRRRRRR/# )r!   r   r   r   Ú
model_namer   r   r   )r&   s   "r   r'   r'   8   s.   € ÷ Xñ X�ð X˜Cð X°cð XÀ]ñ Xr   c                ó€   € Vf   R# \        Y\        VRV4      \        TRT;'       g    R4      VP                  R7      # )z‚Lift a raw guard payload into a :class:`SelectionWarning` (None passes through). Duck-typed:
payloads may carry only ``.message``.Nr   r   r+   ©r   r   r   r   r   )r
   r,   r   )r   r   Úwarningr3   r   s   &&&&&r   Ú_wrapr7   8   sA   € ð ‚ÙÜØ¤g¨g°wÀ
Ó&KÜ˜ *¨h¯n¨n¸"Ó=ÀwÇÁôXð Xr   Nc               ó4   € V ^8„  d   QhRRRRRRRRRRR	R
RR/# ©r!   r3   r   r   r   Úbase_urlÚapi_keyÚ
model_infoúOptional[ModelInfo]Úctxr%   r$   úOptional[SelectionWarning]r   )r&   s   "r   r'   r'   B   sM   € ÷ Sñ SØðSØ,ðSØ8EðSØP]ðSà#ðSà*DðSàPjñSr   c                ó@   € ^ RI Hp V! WW#VR7      p\        RRWpV4      # )é    )Úexpensive_model_warning)r   r:   r;   r<   ÚcostzExpensive Model Warning)Úhermes_cli.model_cost_guardrB   r7   )r3   r   r:   r;   r<   r>   rB   r6   s   &&&&&&  r   Ú_cost_guardrE   B   s-   € õ Dá%Ø°ÐV`ôb€Gä�Ð2°GÈÓRÐRr   c               ó4   € V ^8„  d   QhRRRRRRRRRRR	R
RR/# r9   r   )r&   s   "r   r'   r'   L   sM   € ÷ ]ñ ]Øð]Ø,ð]Ø8Eð]ØP]ð]à#ð]à*Dð]àPjñ]r   c                ó>   € ^ RI Hp V! WVR7      p\        RRWpV4      # )rA   )Údata_training_warning)r   r:   Údata_policyzData-Training Tier Warning)Ú"hermes_cli.model_data_policy_guardrH   r7   )r3   r   r:   r;   r<   r>   rH   r6   s   &&&&&&  r   Ú_data_policy_guardrK   L   s'   € õ Iá# JÈHÔU€GÜ�Ð <¸gÐS[Ó\Ð\r   i † c               ó   € V ^8„  d   QhRR/# )r!   r$   r-   r   )r&   s   "r   r'   r'   Z   s   € ÷ 2ñ 2 #ñ 2r   c                 ó  €  ^ RI Hp  V ! 4       ;'       g    / P                  R/ 4      p\        V\        4      '       d   VP                  R4      MRpVe   \        ^ \        V4      4      #  \        #   \         d	     \        # i ; i)zX``model.switch_context_confirm_tokens`` from config.yaml (0 disables), else the default.)Úload_configr   Úswitch_context_confirm_tokensN)	Úhermes_cli.configrN   ÚgetÚ
isinstanceÚdictÚmaxr-   r.   Ú&DEFAULT_CONTEXT_CACHE_SWITCH_THRESHOLD)rN   Ú	model_cfgÚraws      r   Ú_context_cache_thresholdrX   Z   s‚   € ðÝ1á “]×(Ð( b×-Ñ-¨g°rÓ:ˆ	Ü@JÈ9ÔVZ×@[Ò@[ˆi�m‰mÐ;Ô<ÐaeˆØŠ?Ü�qœ#˜c›(Ó#Ð#ð ô 2Ð1øô ô ØÜ1Ð1ðús   ‚A2 –AA2 Á2BÂBc               ó4   € V ^8„  d   QhRRRRRRRRRRR	R
RR/# r9   r   )r&   s   "r   r'   r'   h   sD   € ÷ <ñ <Øð<Ø,ð<Ø8Eð<ØP]ð<à#ð<à*Dð<àPjñ<r   c           
     óÖ  € Ve   VP                   '       g   R# T ;'       g    RP                  4       pVP                  ;'       g    RP                  4       pV'       d   V'       d	   Wg8X  d   R# \        4       p\	        VP                   4      p	V^ 8:  g   W˜8  d   R# RP                  RRRV	R R2RV R	2RR
VR R2R.4      p
\        RRTT;'       g    RP                  4       V
R7      # )a  Confirm a mid-session switch that abandons a large cached context. Fires only when the surface
supplied live facts showing the active context at/above the threshold; smaller sessions, sessions
with no measured size and same-model re-selects (cache stays warm) are silent.Nr+   Ú
z"!!! LARGE CONTEXT MODEL SWITCH !!!zThis session holds ~Ú,z tokens of context.zSwitching to u~    makes the next reply re-read all of it uncached (providers key prompt caches per model) â€” a one-time full-price input cost.z:Threshold: model.switch_context_confirm_tokens (currently z; 0 disables this check).z)Confirm only if you intend to switch now.Úcontext_cachezLarge Context Switch Warningr5   )r   Ústripr   rX   r-   Újoinr
   )r3   r   r:   r;   r<   r>   ÚtargetÚcurrentÚ	thresholdr0   r   s   &&&&&&     r   Ú_context_cache_guardrc   h   sø   € ð ‚{˜#×,×,Ð,ÙØ×Ð˜B×%Ñ%Ó'€FØ× Ñ ×&Ð& B×-Ñ-Ó/€Gß—g &Ô"3ÙÜ(Ó*€IÜ�×#Ñ#Ó$€FØ�A„~˜Ô+ÙØ�i‰iØ,Ø
Ø
˜v a˜jÐ(;Ð<Ø
˜�xð  Ið 	Ià
Ø
DÀYÈqÀMÐQjÐkØ3ð5ó 6€Gô ØÐ$BÈ&Ø—.�.˜b×'Ñ'Ó)°7ô<ð <r   r   r:   r;   r<   Úinclude_kindsÚselection_contextc               ó8   € V ^8„  d   QhRRRRRRRRRRR	R
RRRR/# )r!   r3   r   r   r   r:   r;   r<   r=   rd   zOptional[Iterable[str]]re   r%   r$   úlist[SelectionWarning]r   )r&   s   "r   r'   r'   ‹   sS   € ÷ ñ ØðØ"/ðØBOðàðà/Bðð +ðð 2ð	ð >Tñ	r   c          	     óÜ   € Ve   \        V4      MRp. p\         F<  p	 V	! WW#WF4      p
T
f   K  Te   T
P                  T9   g   K+  TP	                  T
4       K>  	  V#   \         d     KP  i ; i)u   Warnings from every registered guard (empty in the common case). ``include_kinds`` restricts
which kinds are returned; ``selection_context`` carries live-session facts for switch-aware guards.
Guard exceptions are swallowed â€” never break model selection.N)ÚsetÚ_GUARDSr.   r   Úappend)r3   r   r:   r;   r<   rd   re   ÚwantedÚresultsÚguardr6   s   &$$$$$$    r   Úselection_warningsro   ‹   su   € ð $1Ò#<ŒS�ÔÀ$€FØ&(€Gßˆð	Ù˜J°(ÀZÓcˆGð Ô F¢N°g·l±lÀfÖ6LØ�N‰N˜7Ö#ñ ð €Nøô	 ô 	Úð	ús   ž
AÁA+Á*A+c               ó    € V ^8„  d   QhRRRR/# )r!   Úwarningsrg   r$   r   r   )r&   s   "r   r'   r'   Ÿ   s   € ÷ 4ñ 4Ð5ð 4¸#ñ 4r   c                ó2   € RP                  R V  4       4      # )zTOne confirm-prompt body for several warnings (one prompt beats two sequential ones).z

c              3  ó8   "  € T F  qP                   x € K  	  R # 5i©N)r   )Ú.0Úws   & r   Ú	<genexpr>Ú#combined_message.<locals>.<genexpr>¡   s   é € Ð3©( Q—y–y«(ùs   ‚)r_   )rq   s   &r   Úcombined_messagery   Ÿ   s   € à�;‰;Ñ3©(Ó3Ó3Ð3r   c               ó4   € V ^8„  d   QhRRRRRRRRRRR	R
RR/# )r!   r3   r   r   r   r:   r;   r<   r=   re   r%   r$   r?   r   )r&   s   "r   r'   r'   ¤   sQ   € ÷ Kñ KØðKØ"/ðKØBOðKàðKà/BðKð 2ðKð  ñ	Kr   c          	     óÜ   € \        WW#VVR7      pV'       g   R# \        V4      ^8X  d
   V^ ,          # \        RRV^ ,          P                  V^ ,          P                  \        V4      R7      # )z‘Drop-in for ``expensive_model_warning`` call sites: ``None``, the single warning, or a merged
``kind="multiple"`` warning stacking every message.)r   r:   r;   r<   re   NÚmultiplezModel Selection Warningr5   )ro   Úlenr
   r   r   ry   )r3   r   r:   r;   r<   re   rq   s   &$$$$$ r   Úcombined_selection_warningr~   ¤   sm   € ô "Ø°ÐV`Ø+ô-€H÷ ÙÜ
ˆ8ƒ}˜ÔØ˜�{ÐÜØÐ8ÀÈÅ×@QÑ@QØ˜!•×%Ñ%Ô/?ÀÓ/IôKð Kr   rt   )r   Ú
__future__r   Údataclassesr   Útypingr   r   r   Úagent.models_devr   r
   r   r1   r7   rE   rK   rU   rX   rc   rj   ro   ry   r~   r   r   r   Ú<module>rƒ      s  ðñõ #å !ß +Ñ +å &ñ �$Ô÷ð ó ðñ �$Ô÷(ð (ó ð(õfõ&X÷S÷]ð *1Ð &õ2÷<ð@ Ð*Ð,@Ð
A€ðØ26ðØRVðà!ðàEIðð .2ðð 59÷	õ(4ð
KØ26ðKØRVðKà!ðKàEIðKð 59÷Kñ Kr   