+
    .pÐjÖ  ã                   óf   € 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 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   "Ú*/opt/hermes/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_snapshotr9   !   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+   r9   Útools.credential_filesr>   ÚsplitÚminÚappendÚjoin)r   r;   Ústored_pathr>   ÚlinesÚresultÚcharsÚreserveÚlineÚ	remainingÚ	next_lines   &&         r   Ú_truncate_snapshotrO   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   c                ó0   € V ^8„  d   QhR\         R\         /# )r   Úvaluer   )r   )r   s   "r   r   r   o   s   € ÷ ñ ¤#ð ¬#ñ r   c                óè  € ^ RI Hp \        V \        4      '       d   V! V RR7      # \        V \        4      '       d   V  Uu. uF  p\        V4      NK  	  up# \        V \        4      '       d-   \        ;QJ d    . R V  4       F  NK  	  5# ! R V  4       4      # \        V \        4      '       d8   V P                  4        UUu/ uF  w  r2\        V4      \        V4      bK  	  upp# V # u upi u uppi )zÜ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.r   Tr   c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5i©N)Ú_redact_browser_output)Ú.0Úitems   & r   Ú	<genexpr>Ú)_redact_browser_output.<locals>.<genexpr>z   s   é € ÐD¹e°dÔ+¨D×1Ð1»eùs   ‚)	r*   r   Ú
isinstancer
   ÚlistrU   ÚtupleÚdictÚitems)rQ   r   rW   Úkeys   &   r   rU   rU   o   sÉ   € õ 3ä�%œ×ÒÙ$ U°$Ô7Ð7Ü�%œ×ÒÙ9>Ó?¹°Ô& tÖ,¹Ñ?Ð?Ü�%œ×ÒßŒuÑD¹eÓD�uÐDˆuÑD¹eÓDÓDÐDÜ�%œ×ÒØ[`×[fÑ[fÔ[hÔiÑ[hÉiÈcÔ& sÓ+Ô-CÀDÓ-IÒIÑ[hÒiÐiØ€Lùò @ùó js   ÁC)Ã C.)z6Screenshot saved to ['\"](?P<path>/[^'\"]+?\.png)['\"]z0Screenshot saved to (?P<path>/\S+?\.png)(?:\s|$)z(?P<path>/\S+?\.png)(?:\s|$)rT   )Ú__doc__r   Útypingr   r   Útools.browser_tool_originr   r,   r   r   r9   rO   rU   © r   r   Ú<module>rd      s3   ðñó 
ß  Ý 3ðÐ õõ!÷H'÷Tr   