+
    lHàj�  ã                   ón   € R t ^ RIt^ RIHtHt ^ RIHt RtR R lt	R R lt
RR R	 lltR
^ /R R lltR# )u  Snapshot post-processing for the browser tools: truncate-and-store of oversized
accessibility trees, model-boundary secret redaction, screenshot-path recovery.

Facade-owned state is read through ``_bt`` (``tools.browser_tool``, resolved per call) â€” no import cycle.
N)ÚAnyÚOptional)Úoriginc                óF   € V ^8„  d   QhR\         R\        \         ,          /# )é   ÚtextÚreturn©Ústrr   )Úformats   "Ú@/home/ubuntu/.hermes/hermes-agent/tools/browser_tool_snapshot.pyÚ__annotate__r      s   € ÷ ñ ¬Sð ´X¼cµ]ñ ó    c                óè   € V '       g   R# \          F]  p\        P                  ! W4      pV'       g   K#  VP                  R4      P	                  4       P	                  R4      pV'       g   K[  Vu # 	  R# )zHExtract a screenshot file path from agent-browser human-readable output.NÚpathz'")Ú_SCREENSHOT_PATH_PATTERNSÚreÚsearchÚgroupÚstrip)r   ÚpatternÚmatchr   s   &   r   Ú"_extract_screenshot_path_from_textr      sV   € çÙç,ˆÜ—	’	˜'Ó(ˆß‰5Ø—;‘;˜vÓ&×,Ñ,Ó.×4Ñ4°UÓ;ˆDß‰tØ’ñ -ñ r   c                óF   € V ^8„  d   QhR\         R\        \         ,          /# )r   Úsnapshot_textr   r	   )r   s   "r   r   r   !   s   € ÷ !ñ !¬ð !´¼µñ !r   c                ó@  €  ^ RI p^ RIHp ^ RIHp V! V RR7      p\        V4      \        P                  8”  d;   VR\        P                   R\        P                  R R\        V4      R R	2,           p^ R
IH	pH
p V! RR4      pV! VRR7       VP                  VP                  R4      4      P                  4       R,          pVRV R2,          p	V! W”RRR7       \        V	4      #   \         d,   p
\        P                   P#                  RT
4        Rp
?
R# Rp
?
ii ; i)u†  Write a full snapshot to cache/web and return its path (None on failure â€” best-effort).

Mirrors ``web_tools._store_full_text``: cache/web is mounted read-only into
remote backends, so read_file can page through the complete tree on any
backend. The stored copy is force-redacted (page-rendered secrets must not
hit disk unmasked) and named by content hash so identical snapshots dedupe.
N)Úget_hermes_dir)Úredact_sensitive_textT©Úforcez 

[... stored copy truncated at Ú,z
 chars of z ...])Úensure_spill_dirÚwrite_text_exclusivez	cache/webÚ	web_cacheF)Úprivatezutf-8:Né
   Nzbrowser-snapshot-z.txt)r$   Ú	overwritez)Failed to store full browser snapshot: %s)ÚhashlibÚhermes_constantsr   Úagent.redactr   ÚlenÚ_btÚMAX_STORED_SNAPSHOT_CHARSÚtools.spill_safetyr!   r"   Úsha256ÚencodeÚ	hexdigestr
   Ú	ExceptionÚloggerÚdebug)r   r'   r   r   Úcontentr!   r"   Ú	cache_dirÚdigestr   Úexcs   &          r   Ú_store_full_snapshotr8   !   s  € ðÛÝ3Ý6á'¨¸TÔBˆÜˆw‹<œ#×7Ñ7Ô7àÐ6œ×6Ñ6Ð7Ø6´s×7TÑ7TÐUVÐ6Wð XÜ˜'“l 1Ð% Uð,õ,ð ÷
 	Ná" ;°Ó<ˆ	Ù˜¨EÕ2Ø—‘ §¡¨wÓ 7Ó8×BÑBÓDÀSÕIˆØÐ.¨v¨h°dÐ;Õ;ˆñ 	˜T°EÀTÕJÜ�4‹yÐøÜô Ü�
‰
×ÑÐDÀcÔJÝûðús   ‚C$C' Ã'DÃ2 DÄDc                óR   € V ^8„  d   QhR\         R\        \        ,          R\         /# )r   r   Ú	max_charsr   )r
   r   Úint)r   s   "r   r   r   E   s%   € ÷ 'ñ '¤cð '´h¼sµmð 'Ìsñ 'r   c           	     óÌ  € Vf   \         P                  ! 4       p\        V 4      V8:  d   V # \        V 4      pV'       d   ^ RIHp V! V4      pV P                  R4      p. p^ p\        ^n\        T;'       g    R4      ,           V^,          4      pV FS  pV\        V4      ,           ^,           W,
          8”  d    M.VP                  V4       V\        V4      ^,           ,          pKU  	  \        V4      \        V4      ,
          p	V	^ 8”  dL   V'       d/   \        V4      ^,           p
VP                  RV	 RV RV
 R24       MVP                  RV	 R24       RP                  V4      # )	u*  Truncate a snapshot at line boundaries (never mid-element) to ``max_chars``.

Defaults to ``browser.snapshot_threshold``. The full snapshot is stored to
cache/web and the appended note tells the agent how to page through it
with read_file â€” element refs beyond the cut are in the file, not lost.
)Úto_agent_visible_cache_pathÚ
Ú z
[... u9    more lines truncated â€” full snapshot: read_file path="z	" offset=z limit=200]z= more lines truncated, use browser_snapshot for full content])
r+   Úget_browser_snapshot_thresholdr*   r8   Útools.credential_filesr=   ÚsplitÚminÚappendÚjoin)r   r:   Ústored_pathr=   ÚlinesÚresultÚcharsÚreserveÚlineÚ	remainingÚ	next_lines   &&         r   Ú_truncate_snapshotrN   E   sD  € ð ÒÜ×6Ò6Ó8ˆ	Ü
ˆ=Ó˜YÔ&ØÐä& }Ó5€KßåFÙ1°+Ó>ˆà×Ñ Ó%€EØ€FØ€Eô �#œ˜K×-Ð-¨2Ó.Õ.°	¸QµÓ?€GÛˆØ”3�t“9Õ˜qÕ  9Õ#6Ô6ÙØ�‰�dÔØ”�T“˜Q•ÕŠñ	 ô
 �E“
œS ›[Õ(€IØ�1„}ßÜ˜F› a�ˆIØ�M‰MØ˜)˜ð %#Ø#. -¨y¸¸À;ðPõð
 �M‰M˜G I ;Ð.kÐlÔmØ�9‰9�VÓÐr   Ú_depthc                ó<   € V ^8„  d   QhR\         R\        R\         /# )r   ÚvaluerO   r   )r   r;   )r   s   "r   r   r   o   s!   € ÷ ñ ¤#ð ´#ð ¼cñ r   c          
     óF  a€ ^ RI HpHpHp SV8¼  d   V# \	        V \
        4      '       d   V! V RR7      # \	        V \        4      '       d%   V  Uu. uF  p\        VS^,           R7      NK  	  up# \	        V \        4      '       d3   \        ;QJ d    . V3R lV  4       F  NK  	  5# ! V3R lV  4       4      # \	        V \        4      '       dJ   V P                  4        UUu/ uF,  w  re\        VS^,           R7      \        VS^,           R7      bK.  	  upp# V # u upi u uppi )aW  Force-redact secrets in browser-originated data (snapshots, console, eval
results can carry page-rendered keys/cookies/tokens). Tool output is a model
boundary, so this applies even when global log redaction is disabled.

``_depth`` stops a page-controlled tree from raising RecursionError. The
unread remainder is replaced, not returned raw.
)ÚREDACT_WALK_DEPTH_MARKERÚREDACT_WALK_MAX_DEPTHr   Tr   ©rO   c              3   óL   <"  € T F  p\        VS^,           R7      x € K  	  R# 5i)é   rU   N)Ú_redact_browser_output)Ú.0ÚitemrO   s   & €r   Ú	<genexpr>Ú)_redact_browser_output.<locals>.<genexpr>„   s"   øé € ÐWÑQVÈÔ+¨D¸À!½×DÑDÓQVùs   ƒ!$)r)   rS   rT   r   Ú
isinstancer
   ÚlistrX   ÚtupleÚdictÚitems)rQ   rO   rS   rT   r   rZ   Úkeys   &d     r   rX   rX   o   s   ø€ ÷ñ ð Ð&Ô&Ø'Ð'Ü�%œ×ÒÙ$ U°$Ô7Ð7Ü�%œ×ÒÙLQÓRÉEÀDÔ& t°F¸QµJ×?ÉEÑRÐRÜ�%œ×ÒßŒuÔWÑQVÓW�uÐWˆuÔWÑQVÓWÓWÐWÜ�%œ×Òð #Ÿ[™[œ]ô
á*‘	�ô # 3¨v¸­zÔ:Ô<RÐSWÐ`fÐijÕ`jÔ<kÒkÙ*ò
ð 	
ð €Lùò Sùó
s   ÁDÃ 2D)z6Screenshot saved to ['\"](?P<path>/[^'\"]+?\.png)['\"]z0Screenshot saved to (?P<path>/\S+?\.png)(?:\s|$)z(?P<path>/\S+?\.png)(?:\s|$))N)Ú__doc__r   Útypingr   r   Útools.browser_tool_originr   r+   r   r   r8   rN   rX   © r   r   Ú<module>rg      s?   ðñó 
ß  Ý 3ðÐ õõ!÷H'ðT¸÷ ñ r   