+
    lHàj=  ã                  óÆ   € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHtHt ^ RI	H
t
 ^ RIHtHt R R ltR]3R R	 lltR
 R ltR R ltRRRR/R R lltRR R lltR R ltR# )zLHelpers shared by the non-local terminal backends (docker, ssh, cloud SDKs).)ÚannotationsN)ÚCallableÚIterable)Ú_SHELL_ENV_NAME_RE)Ú_is_hermes_internal_secretÚ_is_provider_env_blocklistedc               ó   € V ^8„  d   QhRR/# )é   Úreturnúdict[str, str]© )Úformats   "ÚE/home/ubuntu/.hermes/hermes-agent/tools/environments/remote_common.pyÚ__annotate__r      s   € ÷ ñ ˜nñ ó    c                 óX   €  ^ RI Hp  V ! 4       ;'       g    / #   \         d    / u # i ; i)uW   ``~/.hermes/.env`` values, or ``{}`` â€” a broken .env must not fail command execution.©Úload_env)Úhermes_cli.configr   Ú	Exceptionr   s    r   Úload_hermes_env_varsr      s.   € ðÝ.Ù‹z×Ð˜RÐøÜô ØŠ	ðús   ‚ – ™)¨)c               ó$   € V ^8„  d   QhRRRRRR/# )r	   Úexplicit_forwardúIterable[str]Úhermes_env_loaderzCallable[[], dict[str, str]]r
   ztuple[dict[str, str], set[str]]r   )r   s   "r   r   r      s#   € ÷ %!ñ %!¨mð %!Ø/Kð%!à!@ñ%!r   c                óÞ  € \        4       pRpRpR p ^ RIHpHp ^ RIHpHp V! 4       p\        V! 4       4      pV Uu0 uF  p\        V4      '       d   K  VkK  	  p	p\        V 4      V	 Uu0 uF  p\        V4      '       d   K  VkK  	  up,          p
V
'       d   V! 4       M/ p/ p\        4       p\        V
4       F‘  p\        P                  ! V4      ;'       g    VP                  V4      pVe	   V! Wï4      pVe   WüV&   KH  V'       g   KR  V! V4      '       d   Kb  \        P                  ! V4      '       g   K€  VP!                  V4       K“  	  WÍ3#   \         d     EL'i ; iu upi u upi )a/  Values to forward into a remote shell plus the scoped names that must be unset there.

Implicit passthrough (skill ``required_environment_variables`` + ``terminal.env_passthrough``)
is filtered through the Hermes provider-credential blocklist and the dynamic internal-secret
check; ``explicit_forward`` entries (docker_forward_env) are an operator opt-in that bypasses
both. Each value is the routed profile's secret when multiplex is active; a name the active
scope lacks is returned in the unset set so a shared sandbox cannot leak another profile's
value.
NFc                ó   € R # ©Fr   )Ú_names   &r   Ú<lambda>Ú)resolve_passthrough_env.<locals>.<lambda>&   s   € ¡%r   )Úget_all_passthroughÚresolve_passthrough_value)Ú_is_global_envÚis_multiplex_active)ÚsetÚtools.env_passthroughr!   r"   Úagent.secret_scoper#   r$   r   r   r   ÚsortedÚosÚgetenvÚgetr   Ú	fullmatchÚadd)r   r   Úpassthrough_keysr"   Úmultiplex_activeÚis_global_envr!   r$   ÚkÚimplicit_forwardÚforward_keysÚ
hermes_envÚexec_envÚunset_namesÚkeyÚvalues   &&              r   Úresolve_passthrough_envr9      sQ  € ô "%£ÐØ $ÐØÐÙ'€MðßXß[Ù.Ó0ÐÜÑ2Ó4Ó5Ðñ $4ÓYÑ#3˜aÔ;UÐVW×;XŸ˜Ñ#3ÐÐYÜÐ'Ó(Ù#ó,LÙ#ˆaÔ+GÈ×+J�ˆÑ#ñ,Lõ L€Lç(4Ñ"Ô$¸"€JØ!€HÜ›E€KÜ�lÖ#ˆÜ—	’	˜#“×5Ð5 *§.¡.°Ó"5ˆØ$Ò0Ù-¨cÓ9ˆEØÒØ!�S‹MßÑ¡m°C×&8Ô&8Ô=O×=YÒ=YÐZ]×=^Ô=^Ø�O‰O˜CÖ ñ $ð Ð Ð øô! ô ÚðüâYùò,Ls(   “'E ¾E%ÁE%Á,E*ÂE*ÅE"Å!E"c               ó$   € V ^8„  d   QhRRRRRR/# )r	   Ú
cmd_stringÚstrÚnamesr   r
   r   )r   s   "r   r   r   ?   s&   € ÷ `ñ `˜cð `¨-ð `¸Cñ `r   c                óh   € \        V4      pV'       g   V # RRP                  R V 4       4       RV  2# )z_Prefix ``cmd_string`` with ``unset`` of the profile-scoped names the remote shell must not see.zunset Ú c              3  óN   "  € T F  p\         P                  ! V4      x € K  	  R # 5i)N)ÚshlexÚquote)Ú.0Úns   & r   Ú	<genexpr>Ú prepend_unset.<locals>.<genexpr>D   s   é € Ð;±U°œUŸ[š[¨Ÿ^˜^³Uùs   ‚#%z 2>/dev/null || true
)r(   Újoin)r;   r=   s   &&r   Úprepend_unsetrH   ?   s:   € ä�5‹M€EßØÐØ�C—H‘HÑ;±UÓ;Ó;Ð<Ð<RÐS]ÐR^Ð_Ð_r   c               ó    € V ^8„  d   QhRRRR/# )r	   Úvaluesr   r
   zdict[str, str] | Noner   )r   s   "r   r   r   G   s   € ÷ 8ñ 8˜Nð 8Ð/Dñ 8r   c                ó>   € V '       d   / \         P                  CV C# R# )z²Env for the docker/ssh CLIENT subprocess: forwarded values travel here (owner-readable
/proc/*/environ) while the argv carries names only; ``None`` = inherit when nothing to add.N)r)   Úenviron)rJ   s   &r   Úclient_env_withrM   G   s    € ÷ (.Ð#Œb�j‰jÐ#˜FÐ#Ð7°4Ð7r   ÚcheckFÚenvc          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r	   Úcmdú	list[str]ÚtimeoutÚfloatrN   ÚboolrO   zdict | Noner
   zsubprocess.CompletedProcessr   )r   s   "r   r   r   M   s7   € ÷ Iñ I�Yð I¨Eð I¸$ð IÈ[ð IØ0ñIr   c               óZ   € \         P                  ! V RRRRW\         P                  VR7	      # )z¹``subprocess.run`` with the backend-standard capture settings: text mode with utf-8/replace
decoding and stdin closed (DEVNULL) so a CLI that unexpectedly prompts cannot hang the agent.Tzutf-8Úreplace)Úcapture_outputÚtextÚencodingÚerrorsrS   rN   ÚstdinrO   )Ú
subprocessÚrunÚDEVNULL)rQ   rS   rN   rO   s   &$$$r   Úrun_capturer`   M   s/   € ô �>Š>Ø˜D t°gÀiØ¬J×,>Ñ,>ÀCôIð Ir   c               ó$   € V ^8„  d   QhRRRRRR/# )r	   r;   r<   ÚloginrU   r
   rR   r   )r   s   "r   r   r   V   s&   € ÷ Uñ U˜#ð U dð U°yñ Ur   c                ó(   € V'       d   RRRV .# RRV .# )zF``bash [-l] -c <cmd>`` argv tail used by every spawn-per-call backend.Úbashz-lz-cr   )r;   rb   s   &&r   Ú	bash_argvre   V   s   € ç/4ˆF�D˜$ 
Ð+ÐT¸6À4ÈÐ:TÐTr   c               ó    € V ^8„  d   QhRRRR/# )r	   Úextrar<   r
   ÚNoner   )r   s   "r   r   r   [   s   € ÷ "ñ "˜3ð " 4ñ "r   c                ó€   € ^ RI p VP                  V 4       R#   \         d   p\        \	        T4      4      hRp?ii ; i)zbLazy-install an optional SDK's pm extra (idempotent). Install failures
surface as ``ImportError``.N)ÚpmÚensure_importr   ÚImportErrorr<   )rg   rj   Úes   &  r   Úensure_lazy_deprn   [   s9   € ó ð"Ø
×Ñ˜ÖøÜô "Üœ#˜a›&Ó!Ð!ûð"ús   † ™=¤8¸=r   r   )Ú__doc__Ú
__future__r   r)   rA   r]   Útypingr   r   Ú#tools.environments.base_session_envr   Ú#tools.environments.local_env_policyr   r   r   r9   rH   rM   r`   re   rn   r   r   r   Ú<module>rt      s^   ðÙ Rå "ã 	Û Û ß %å Bß hõð ?AØNb÷%!õP`õ8ðIÀð IÐ[_÷ I÷U÷
"r   