+
    iHàj£%  ã                  óV  a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIHt ^ RIH	t	 ^ RI
Ht R(tR)tR*tR+tRtRtRtR,t]	! R	RR
7      tR]R&   R R ltR-R R lltRR/R R lltR R ltR.R R lltR R ltRR/R R lltR R lt]RRRR/R  l4       tR! tR/R" R# llt R$ R% lt!R-R& R' llt"R# )0aå  A local session's client environment: the allowlisted values a shell-launched client (classic CLI,
Ink TUI) sends as ``session.create``'s ``client_env``. Main's ``hermes`` process read them from its own
shell; the one gateway now runs every session, so they are frozen with the session's policy and bound
for its turns only, never written to the gateway's ``os.environ``. Desktop sends none: its sessions
keep the gateway's environment, and so does a session created before ``client_env`` existed.

Plain names and string values only. Behaviour names are read through :func:`session_env`; the
toolchain names (``PATH``, an activated venv, nvm/pyenv/conda) reach that session's tool subprocesses
through :func:`toolchain_environ`. Values naming this host (toolchain paths, the prefill file, the
project-plugins check of the client's folder) apply only when the gateway proved the client is on its
host (``local``); otherwise the session keeps the gateway's and is told so. Values are never logged.
)ÚannotationsN)Úcontextmanager)Ú
ContextVar)Úis_secret_env_nameÚclient_env_passthroughzªthis session uses the gateway's own PATH, toolchain and prefill file: the client's environment was not applied because the client is not attached to this gateway locally.é   Úsession_client_env)Údefaultr   Ú_BOUNDc               ó   € V ^8„  d   QhRR/# )é   ÚreturnÚ	frozenset© )Úformats   "Ú=/home/ubuntu/.hermes/hermes-agent/agent/session_client_env.pyÚ__annotate__r   )   s   € ÷ Gñ G 	ñ Gó    c                ó  € \        V \        4      '       d   V P                  R4      MRp\        V\        4      '       d   VP                  \        4      MRp\        V\        4      '       d   \        R V 4       4      # \        4       # )zEThe profile's extra tool names (``terminal.client_env_passthrough``).ÚterminalNc              3  ó¢   "  € T FE  p\        V\        4      '       g   K  VP                  4       '       g   K3  VP                  4       x € KG  	  R # 5i©N)Ú
isinstanceÚstrÚstrip)Ú.0Únames   & r   Ú	<genexpr>Ú#configured_names.<locals>.<genexpr>-   s-   é € Ð\©c d´ZÀÄc×5J”\ÈtÏzÉzÏ|”\�T—Z‘Z—\�\«cùs   ‚AŸA·A)r   ÚdictÚgetÚ
CONFIG_KEYÚlistr   )Úconfigr   Úraws   &  r   Úconfigured_namesr%   )   sp   € ä)3°F¼D×)AÒ)Aˆv�z‰z˜*Ô%Àt€HÜ&0°¼4×&@Ò&@ˆ(�,‰,”zÔ
"Àd€CÜ`jÐknÔpt×`uÒ`uŒ9Ñ\©cÓ\Ó\ð  Gô  |Eó  |Gð  Gr   c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   Úboolr   )r   s   "r   r   r   0   s   € ÷ 9ñ 9�3ð 9¨ñ 9r   c                óà   a € Vf   \        S 4      M9\        ;QJ d    V 3R lV 4       F  '       g   K   RM	  RM! V 3R lV 4       4      pV'       * ;'       d    S P                  R4      '       * # )aO  A toolchain name may travel unless it is a credential by execute_code's secret policy (even when
listed: ``NODE_AUTH_TOKEN`` matches ``NODE_``; secrets reach tools through ``terminal.env_passthrough``)
or a Hermes control name (a delegated child's markers, Kanban pins). ``secret``: a session's frozen
copy of that policy's substrings.c              3  óH   <"  € T F  qSP                  4       9   x € K  	  R # 5ir   )Úupper)r   Úsr   s   & €r   r   Ú_travels.<locals>.<genexpr>5   s   øé € Ð@cÑ\bÐWXÀdÇjÁjÃlÖARÓ\bùs   ƒ"TFÚHERMES_)r   ÚanyÚ
startswith)r   ÚsecretÚhiddens   f& r   Ú_travelsr2   0   sO   ø€ ð
 *0ªÔ Ô%¿S»SÔ@cÑ\bÓ@c¿S¿SºSÔ@cÑ\bÓ@cÓ=c€FØŒ:×8Ð8˜dŸo™o¨iÓ8Ô8Ð8r   ÚlocalTc               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r   9   s   € ÷ fñ f¨tñ fr   c          
     ó  € ^ RI Hp R\         Uu. uF  q1'       g   V\        9  g   K  VNK  	  upRV'       d)   \	        \        \        4      \        V 4      ,          4      M. RV'       d   \        \        4      M. R\        V4      /# u upi )a/  The normalisation rules (plain data) a session's map is filtered by, frozen with it: an exact retry
is judged by these, never by the profile's allowlist or the secret policy as they are later. A client
not proven ``local`` keeps only the values that name nothing on this host (prompt, provider request).)Ú_SECRET_SUBSTRINGSÚ	behaviourÚnamesÚprefixesr0   )
Útools.code_execution_envr6   ÚBEHAVIOUR_ENVÚHOST_BEHAVIOURÚsortedÚsetÚTOOL_ENVr%   r"   ÚTOOL_ENV_PREFIXES)r#   r3   r6   Úns   &$  r   Úclient_env_rulesrB   9   sl   € õ <Ø¥]ÓW¡] ¶e¸qÌÑ?VŸ!˜!¡]ÑWØÏ”VœC¤›MÔ,<¸VÓ,DÕDÔEÐTVØ·5œÔ.Ô/¸bÀ(ÌDÐQcÓLdðfð fùÒWs
   �B	©B	c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   Úrulesr   r   r'   r   )r   s   "r   r   r   C   s&   € ÷ Nñ N�ð N˜Dð N Tñ Nr   c                óÄ   € WR ,          9   ;'       gO    \        WR,          4      ;'       d5    WR,          9   ;'       g"    V P                  \        VR,          4      4      # )r7   r0   r8   r9   )r2   r/   Útuple)r   rD   s   &&r   Ú_keptrG   C   s[   € Ø˜Õ%Ñ%÷ Nð N¬(°4¸x½Ó*I÷ +Mð +MØ�g•Ñ×KÐK $§/¡/´%¸¸jÕ8IÓ2JÓ"KðNr   c               ó   € V ^8„  d   QhRR/# ©r   r   zdict[str, str]r   )r   s   "r   r   r   H   s   € ÷ mñ m°^ñ mr   c                óî   € V f   \         P                  MT p \        V4      pV P                  4        UUu/ uF2  w  r4\	        V\
        4      '       g   K  \        W24      '       g   K0  W4bK4  	  upp# u uppi )zRClient side: this shell's allowlisted values (the profile's extra names included).)ÚosÚenvironrB   Úitemsr   r   rG   )rL   r#   rD   r   Úvalues   &&   r   Úcollect_client_envrO   H   sT   € à#šOŒb�jŠj°€GÜ˜VÓ$€EØ+2¯=©=¬?Ôl©?™K˜D¼jÈÔPS×>TŒKÔY^Ð_c×YkŒKˆDŠK©?ÒlÐlùÓls   µA1ÁA1Á'A1c               ó   € V ^8„  d   QhRR/# rI   r   )r   s   "r   r   r   O   s   € ÷ `ñ `¨.ñ `r   c                óä  € \        V \        4      '       d”   \        V 4      \        8”  g€   \        ;QJ d*    R V P                  4        4       F  '       g   K   RM	  RM! R V P                  4        4       4      '       g*   \        R V P                  4        4       4      \        8”  d   \        R4      h\        V 4       Uu/ uF"  q!e   \        W!4      '       g   K  W V,          bK$  	  up# u upi )z¯The validated map filtered by ``rules`` (``None``: unfiltered, for a map frozen before rules were).
Raises ``ValueError`` for anything but a bounded flat string-to-string map.c              3  óŠ   "  € T F9  w  r\        V\        4      '       * ;'       g    \        V\        4      '       * x € K;  	  R # 5ir   )r   r   ©r   ÚkÚvs   &  r   r   Ú'normalise_client_env.<locals>.<genexpr>S   s3   é € Ð^ÑP]ÉÈ”z !¤SÓ)Ô)×CÐC´¸A¼sÓ1CÔ-CÔCÓP]ùs
   ‚"A¥ATFc              3  ó\   "  € T F"  w  r\        V4      \        V4      ,           x € K$  	  R # 5ir   )ÚlenrS   s   &  r   r   rV   T   s    é € Ð=©}¡t q”3�q“6œC ›F—?’?«}ùs   ‚*,z;client_env must be a map of variable names to string values)r   r   rX   Ú
_MAX_NAMESr.   rM   ÚsumÚ
_MAX_BYTESÚ
ValueErrorr=   rG   )rN   rD   r   s   && r   Únormalise_client_envr]   O   s¦   € ô �uœd×#Ò#¤s¨5£z´JÔ'>ß‹sÑ^ÐPU×P[ÑP[ÔP]Ó^�s�sŠsÑ^ÐPU×P[ÑP[ÔP]Ó^×^Ò^ÜÑ=¨u¯{©{¬}Ó=Ó=Ä
ÔJÜÐVÓWÐWÜ*0°¬-Ó_©- $º=ÌEÐRV×L^ÔˆD˜•+Ò©-Ñ_Ð_ùÒ_s   ÃC-ÃC-c               ó   € V ^8„  d   QhRR/# rI   r   )r   s   "r   r   r   Y   s   € ÷ Nñ N°~ñ Nr   c               ó.   € \        V \        WR7      4      # )zJGateway side: the map filtered by the session profile's own current rules.)r3   )r]   rB   )rN   r#   r3   s   &&$r   Úaccept_client_envr`   Y   s   € ä Ô'7¸Ô'LÓMÐMr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Ú	committedr   Úrequestr   r'   r   )r   s   "r   r   r   ^   s!   € ÷ &ñ &˜Tð &¨Dð &°Tñ &r   c                ó0  € V P                  R4      pVe   RV9  d   VRJ ;'       d    RV9  # V P                  R4      p \        VR,          Vf   RM\        P                  ! V4      4      pT\        P                  ! T4      8H  #   \         d     R# i ; i)a,  Whether a retried ``session.create`` (``request``: its params) carries the client environment the
committed session (``committed``: its stored policy) froze. The complete retried map, normalised by
the rules frozen with the session, must equal the stored one: an added name those rules keep, a
missing stored name or a changed value is a different request; one they drop never counts. Staging
and the transactional commit both judge by this. A session committed without a map (Desktop, one
from before the field) still matches only a retry that sends none.Úclient_env_jsonNÚ
client_envÚclient_env_rules_jsonF)r    r]   ÚjsonÚloadsr\   )rb   rc   ÚstoredrD   Úsents   &&   r   Úretry_matchesrl   ^   s˜   € ð �]‰]Ð,Ó-€FØ‚~˜¨WÔ4Ø˜ˆ~×=Ð= ,°gÑ"=Ð=Ø�M‰MÐ1Ó2€EðÜ# G¨LÕ$9À5Â=¹4ÔVZ×V`ÒV`ÐafÓVgÓhˆð ”4—:’:˜fÓ%Ñ%Ð%øô ô Úðús   Á -B ÂBÂBrD   c             #  óÄ   "  € \         P                  V f   RMV \        V4      V34      p Rx € \         P                  V4       R#   \         P                  T4       i ; i5i)a   Bind one session's client environment (``None``: the gateway's own) for this context; ``local``
is the gateway's own proof, frozen in the session's policy, that the client runs on this host;
``rules`` the normalisation rules frozen with it (``client_env_rules``; ``None``: the built-ins).N)r
   r>   r'   Úreset)Úenvr3   rD   Útokens   &$$ r   Úclient_env_scoperq   p   sF   é € ô
 �J‰J˜sš{‘t°´d¸5³kÀ5Ð0IÓJ€EðÛä�‰�UÖøŒ�‰�UÕüs   ‚(A «A ¯A ÁAÁA c                 óH   € \         P                  4       p V f   R # V ^ ,          # r   )r
   r    )Úbounds    r   Úbound_client_envrt   |   s    € Ü�J‰J‹L€EØ’=ˆ4Ð. e¨A¥hÐ.r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   r	   r   r   )r   s   "r   r   r   �   s!   € ÷ 'ñ '�cð ' Cð '°ñ 'r   c                óÂ   € \         P                  4       pVe   V \        9   d&   V^,          '       g   \        P                  ! W4      # V^ ,          P                  W4      # )zòA behaviour value for the session executing here: its client's (an unexported name is unset,
as it was for main's process), else the gateway's own environment, which a client not attached
locally also keeps for the values that name this host.)r
   r    r<   rK   Úgetenv)r   r	   rs   s   && r   Úsession_envrx   �   sE   € ô �J‰J‹L€EØ‚}˜¤Ô/¸¸a¿¼Ü�yŠy˜Ó'Ð'Ø��8�<‰<˜Ó&Ð&r   c               ó   € V ^8„  d   QhRR/# rI   r   )r   s   "r   r   r   ‹   s   € ÷ mñ m�.ñ mr   c                 óö   € \         P                  4       p V e   V ^,          '       g   / # V ^ ,          P                  4        UUu/ uF'  w  rV\        9  g   K  \	        V4      '       g   K%  WbK)  	  upp# u uppi )z`The toolchain values this session's tool subprocesses start with (empty when unbound or remote).)r
   r    rM   r;   r2   )rs   r   rN   s      r   Útool_envr{   ‹   s\   € ä�J‰J‹L€EØ‚}˜E !ŸHœHØˆ	Ø+0°­8¯>©>Ô+;ÔlÑ+;™K˜D¸tÌ=Ñ?XŒKÔ]eÐfj×]kŒKˆDŠKÑ+;ÒlÐlùÓls   ÁA5ÁA5Á+A5c               ó   € V ^8„  d   QhRR/# rI   r   )r   s   "r   r   r   “   s   € ÷ ñ  Nñ r   c                ó¤  € \        V f   \        P                  MT 4      p\        P	                  4       pVf   V# \
         F1  pV^,          '       g   V\        9  g   K  VP                  VR4       K3  	  V^,          '       g   V# V^,          ;'       g    R\        R\        RR/pVR,           Uu0 uF  p\        W4R,          4      '       g   K  VkK!  	  pp\        VR,          4      pVP                  4        UUu/ uF/  w  rxVR8X  g"   Wu9   d   K  VP                  V4      '       d   K-  WxbK1  	  p	ppV	\        4       ,          # u upi u uppi )aF  The environment this session's tool subprocesses start from (``base``: the gateway's). Unbound
(messaging, cron, Desktop): unchanged. Every client's session drops the gateway's own behaviour
values it reads from its client (:func:`session_env`), so tools never see the daemon's ephemeral
prompt or provider request in place of the session's. A client not attached locally keeps the
host values (``HOST_BEHAVIOUR``) and the rest of the gateway's environment. A local shell client's
session: its toolchain replaces the gateway's, and every toolchain name it did not export (built-in,
or configured for its profile when the session was created) is unset, as in main's process: one
client's venv or GEM_HOME never reaches another's session through the daemon it started. PATH is
the exception: a client that sent none runs with the gateway's.Nr8   r9   r0   ÚPATH)r   rK   rL   r
   r    r;   r<   Úpopr?   r@   r2   rF   rM   r/   r{   )
Úbasero   rs   r   rD   r8   r9   rT   rU   Úkepts
   &         r   Útoolchain_environr‚   “   s  € ô ˜Tš\Œr�zŠz¨tÓ
4€CÜ�J‰J‹L€EØ‚}Øˆ
ßˆØ��8Œ8�t¤>Ö1Ø�G‰G�D˜$Öñ ð ��8Œ8Øˆ
Ø�!�H×ZÐZ˜¤(¨JÔ8IÈ8ÐUYÐZ€EØ# GžnÓP™n�d´¸ÀX½×0O�TˆT™n€EÐPÜ�U˜:Õ&Ó'€HØ ŸY™Yœ[Ôf™[‘T�Q¨A°¬KÀÁ
ŒDÈaÏlÉlÐ[c×NdŒDˆAŠD™[€DÑfØ”(“*ÕÐùò Qùãfs   Â2EÃEÃ>EÄEÄ-E)ÚHERMES_EPHEMERAL_SYSTEM_PROMPTÚHERMES_PREFILL_MESSAGES_FILEÚHERMES_INFERENCE_PROVIDERÚHERMES_ENABLE_PROJECT_PLUGINS)r„   r†   )r~   ÚVIRTUAL_ENVÚGOPATHÚGOROOTÚ
CARGO_HOMEÚRUSTUP_HOMEÚ	JAVA_HOME)ÚCONDA_ÚNODE_ÚNVM_ÚPYENV_i   r   )NN)Ú )#Ú__conditional_annotations__Ú__doc__Ú
__future__r   rh   rK   Ú
contextlibr   Úcontextvarsr   r:   r   r;   r<   r?   r@   r!   ÚNOT_LOCAL_WARNINGrY   r[   r
   Ú__annotations__r%   r2   rB   rG   rO   r]   r`   rl   rq   rt   rx   r{   r‚   )r’   s   @r   Ú<module>r™      sß   øðôõ #ã Û 	Ý %Ý "å 7ð2€ð S€Ø`€Ø9Ð à%€
ðcÐ à€
Ø€
ñ  Ð 4¸dÔC€ˆ
Ó CõG÷9ðf d÷ fõN÷
mõ`ðN¨d÷ Nõ
&ð$ ð 4ð ¨tó ó ðò/÷
'õm÷ñ r   