+
    jHàjz  ã                  óò   € R t ^ RIHt ^ RIt^ RIt^ RIHtHtHt ]P                  ! ]
4      tRtRtRt]! 0 Rm4      tR R ltR R	 ltR
 R ltR R ltR R ltRR R lltR R ltR R ltRR R lltR# )uà  Shared configâ†’env bridge for media-delivery policy.

``validate_media_delivery_path`` reads ``HERMES_MEDIA_DELIVERY_STRICT`` (gateway.strict),
``HERMES_MEDIA_ALLOW_DIRS`` (gateway.media_delivery_allow_dirs) and
``HERMES_MEDIA_TRUST_RECENT_FILES`` (gateway.trust_recent_files).  Every delivery
entrypoint (gateway startup, ``hermes cron run``, ``hermes send``) calls
:func:`apply_media_policy_env` first so standalone paths filter under the gateway's
policy instead of silently dropping attachments in strict/allowlisted deployments.
An explicitly-set env var WINS over config.yaml, so shell overrides survive. Under a HERMES_HOME
override (a served profile's turn or cron fire) nothing is bridged: readers load that profile's config.
)ÚannotationsN)ÚAnyÚDictÚOptionalÚHERMES_MEDIA_ALLOW_DIRSÚ!HERMES_MEDIA_TRUST_RECENT_SECONDSc               ó   € V ^8„  d   QhRR/# )é   ÚreturnúOptional[dict[str, Any]]© )Úformats   "Ú9/home/ubuntu/.hermes/hermes-agent/gateway/media_policy.pyÚ__annotate__r      s   € ÷ @ñ @Ð5ñ @ó    c                 óÀ   € ^ RI Hp  V ! 4       '       g   R#  ^ RIHp V! 4       P	                  R4      p\        T\        4      '       d   T# / #   \
         d    / u # i ; i)a  ``gateway`` section of the ROUTED profile's config when a HERMES_HOME override is active
(multiplexed turn), else None. The env bridge is one process-wide copy of the launch profile's
policy, so a secondary's deliveries must read their own config instead of ``os.environ``.©Úget_hermes_home_overrideN)Úload_config_readonlyÚgateway)Úhermes_constantsr   Úhermes_cli.configr   ÚgetÚ	ExceptionÚ
isinstanceÚdict)r   r   Úgateway_cfgs      r   Ú_routed_gateway_cfgr      s]   € õ :Ù#×%Ò%ÙðÝ:Ù*Ó,×0Ñ0°Ó;ˆô % [´$×7Ò7ˆ;Ð?¸RÐ?øô ô ØŠ	ðús   —A ÁAÁAc               ó   € V ^8„  d   QhRR/# ©r	   r
   Úboolr   )r   s   "r   r   r   *   s   € ÷ Lñ L˜tñ Lr   c                 óþ   € \        4       p V e   \        V P                  RR4      4      # \        P                  P                  \
        ^ ,          ^,          R4      P                  4       P                  4       \        9   # )NÚstrictFÚ0)	r   r    r   ÚosÚenvironÚ
_FLAG_ENVSÚstripÚlowerÚ_TRUTHY©Úcfgs    r   Úmedia_delivery_strictr,   *   sZ   € Ü
Ó
€CØ
‚Ü�C—G‘G˜H eÓ,Ó-Ð-Ü�:‰:�>‰>œ* Q�-¨Õ*¨CÓ0×6Ñ6Ó8×>Ñ>Ó@ÄGÑKÐKr   c               ó   € V ^8„  d   QhRR/# ©r	   r
   Ústrr   )r   s   "r   r   r   1   s   € ÷ /ñ / 3ñ /r   c                 óš   € \        4       p V e   \        V P                  R4      4      # \        P                  P                  \
        R4      # )zLOperator allowlist as the ``os.pathsep``-joined string the validator splits.Úmedia_delivery_allow_dirsÚ )r   Ú_allow_dirs_strr   r$   r%   Ú_ALLOW_DIRS_ENVr*   s    r   r1   r1   1   s9   € ä
Ó
€CØ
‚Ü˜sŸw™wÐ'BÓCÓDÐDÜ�:‰:�>‰>œ/¨2Ó.Ð.r   c               ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   r   9   s   € ÷ hñ h Tñ hr   c                 óö   € \        4       p V e   \        V P                  RR4      4      # \        P                  P                  \
        ^,          ^,          R4      P                  4       P                  4       R9  # )NÚtrust_recent_filesTÚ1)r#   ÚfalseÚnoÚoffr2   )r   r    r   r$   r%   r&   r'   r(   r*   s    r   Úmedia_delivery_trust_recentr<   9   s\   € Ü
Ó
€CØ
‚Ü�C—G‘GÐ0°$Ó7Ó8Ð8Ü�:‰:�>‰>œ* Q�-¨Õ*¨CÓ0×6Ñ6Ó8×>Ñ>Ó@ÐHgÑgÐgr   c               ó   € V ^8„  d   QhRR/# r.   r   )r   s   "r   r   r   @   s   € ÷ 9ñ 9¨Sñ 9r   c                 óª   € \        4       p V e#   V P                  R4      pVf   R# \        V4      # \        P                  P                  \
        R4      # )zMRaw recency window (``""`` = validator default); the caller parses/floors it.Útrust_recent_files_secondsr2   )r   r   r/   r$   r%   Ú_TRUST_RECENT_SECONDS_ENV)r+   Úraws     r   Ú#media_delivery_trust_recent_secondsrB   @   sG   € ä
Ó
€CØ
‚Ø�g‰gÐ2Ó3ˆØ’[ˆrÐ.¤c¨#£hÐ.Ü�:‰:�>‰>Ô3°RÓ8Ð8r   c               ó    € V ^8„  d   QhRRRR/# )r	   Úconfigr   r
   zdict[str, Any]r   )r   s   "r   r   r   J   s   € ÷ 	@ñ 	@Ð6ð 	@À.ñ 	@r   c                ó¸   € V f    ^ RI Hp V! 4       ;'       g    / p V P                  R/ 4      p\	        V\
        4      '       d   V# / #   \         d    / u # i ; i)N)Úload_configr   )r   rF   r   r   r   r   )rD   rF   r   s   &  r   Ú_load_gateway_cfgrG   J   s]   € Ø‚~ð	Ý5á “]×(Ð( bˆFð —*‘*˜Y¨Ó+€KÜ$ [´$×7Ò7ˆ;Ð?¸RÐ?øô ô 	ØŠIð	ús   †A	 šA	 Á	AÁAc               ó$   € V ^8„  d   QhRRRRRR/# )r	   Úenvr/   Úvaluer
   ÚNoner   )r   s   "r   r   r   V   s!   € ÷  ñ  ˜#ð   cð  ¨dñ  r   c                óŽ   € V'       d=   \         P                  P                  V 4      '       g   V\         P                  V &   R# R# R# )zHSet ``env`` only when unset/empty and ``value`` is non-empty (env wins).N)r$   r%   r   )rI   rJ   s   &&r   Ú_set_env_defaultrM   V   s+   € ç”R—Z‘Z—^‘^ C×(Ò(ØŒ�
‰
�3‹ñ )�ur   c               ó    € V ^8„  d   QhRRRR/# )r	   Ú
allow_dirsr   r
   r/   r   )r   s   "r   r   r   \   s   € ÷ =ñ = ð =¨ñ =r   c                óº   € \        V \        \        34      '       d'   \        P                  P                  R  V  4       4      # \        V \        4      '       d   V # R# )c              3  óJ   "  € T F  q'       g   K  \        V4      x € K  	  R # 5i©N)r/   )Ú.0Úps   & r   Ú	<genexpr>Ú"_allow_dirs_str.<locals>.<genexpr>^   s   é € Ð?©z¨!»Qœvœs 1Ÿv˜v«zùs   ‚	#�#r2   )r   ÚlistÚtupler$   ÚpathsepÚjoinr/   )rO   s   &r   r3   r3   \   sC   € Ü�*œt¤U˜m×,Ò,Ü�z‰z�‰Ñ?©zÓ?Ó?Ð?Ü# J´×4Ò4ˆ:Ð<¸"Ð<r   c               ó    € V ^8„  d   QhRRRR/# )r	   rD   r   r
   rK   r   )r   s   "r   r   r   b   s   € ÷ Eñ EÐ#;ð EÀtñ Er   c                óŒ  €  ^ RI Hp V! 4       '       d   R# \        V 4      pV'       g   R# \         F1  w  r4VP	                  V4      pVf   K  \        YE'       d   RMR4       K3  	  VP	                  R4      pV'       d   \        \        \        V4      4       R# R#   \         d    \        P                  RRR7        R# i ; i)	u¼  Bridge gateway media-policy settings from config.yaml into the env.  Idempotent,
env-wins, never raises â€” a bridge failure must not break delivery (validator defaults apply).

No-op under a HERMES_HOME override, the same gate the readers use: there they take the
profile's own config (``_routed_gateway_cfg``), and ``os.environ`` is shared â€” a routed cron
fire would hand its allowlist and strictness to the launch profile and its children.r   Nr8   r#   r1   zapply_media_policy_env failedT)Úexc_info)r   r   rG   r&   r   rM   r4   r3   r   ÚloggerÚdebug)rD   r   r   ÚkeyrI   ÚflagrO   s   &      r   Úapply_media_policy_envrb   b   sŸ   € ðEÝ=Ù#×%Ò%ÙÜ'¨Ó/ˆßÙß"‰HˆCØ—?‘? 3Ó'ˆDØÔÜ  ®T¡c°sÖ;ñ #ð !—_‘_Ð%@ÓAˆ
ßÜœ_¬o¸jÓ.IÖJñ øäô EÜ�‰Ð4¸tˆ×DðEús'   ‚B —B ¬B Á1B Â B Â"CÃC))r"   ÚHERMES_MEDIA_DELIVERY_STRICT)r7   ÚHERMES_MEDIA_TRUST_RECENT_FILES>   r8   ÚonÚyesÚtruerR   )Ú__doc__Ú
__future__r   Úloggingr$   Útypingr   r   r   Ú	getLoggerÚ__name__r^   r&   r4   r@   Ú	frozensetr)   r   r,   r1   r<   rB   rG   rM   r3   rb   r   r   r   Ú<module>ro      s~   ðñ
õ #ã Û 	ß &Ñ &à	×	Ò	˜8Ó	$€àt€
Ø+€Ø?Ð Ù
Ò.Ó
/€õ@õLõ/õhõ9÷	@õ õ=÷Eñ Er   