+
    lHàjñ  ã                   ó.  € R t ^ RIt^ RIt^ RIt^ RIHtHt ^ RIH	t
 ^ RIHt ^ RIHt ^ RIHt ]P$                  ! ^R7      R R	 l4       tR
 R ltR"R R lltR R ltR R ltRR/R R lltR#R R lltR R ltR R ltR R ltR R ltR  R! ltR# )$uÜ   PM-owned agent-browser / Chromium discovery, acquisition and readiness.

Split out of ``tools/browser_tool.py``. Facade-owned state is read through ``_bt`` (``tools.browser_tool``, resolved per call) â€” no import cycle.N)Úagent_browser_runnableÚ	is_termux)Úorigin_module)Úbrowser_tool_cdp)Úbrowser_tool_cloud)Ú browser_tool_lightpanda_fallback)Úmaxsizec                ó>   € V ^8„  d   QhR\         \        R3,          /# )é   Úreturn.)ÚtupleÚstr)Úformats   "Ú?/home/ubuntu/.hermes/hermes-agent/tools/browser_tool_install.pyÚ__annotate__r      s   € ÷ ñ ¤e¬C°¨H¥oñ ó    c                 ó  aa€ Ro \         P                  P                  S4      '       d   \         P                  ! S4      M. p \
        ;QJ d    . VV3R lV  4       F  NK  	  5# ! VV3R lV  4       4      #   \         d    . p  LCi ; i)zbHomebrew versioned Node bin dirs (node@20, ...) that ``brew`` may not link into /opt/homebrew/bin.z/opt/homebrew/optc              3   óü   <"  € T Fq  pVP                  R 4      '       g   K  VR 8w  g   K%  \        P                  P                  \        P                  P	                  SVR4      ;o4      '       g   Km  Sx € Ks  	  R# 5i)ÚnodeÚbinN)Ú
startswithÚosÚpathÚisdirÚjoin)Ú.0ÚentryÚbin_dirÚhomebrew_opts   & €€r   Ú	<genexpr>Ú/_discover_homebrew_node_dirs.<locals>.<genexpr>   sa   øé € ð áˆEØ×Ñ˜F×#ô 	à(-°©ô 	ô �7‰7�=‰=¤B§G¡G§L¡L°¸uÀeÓ$LÐL˜×M÷ 	ŠÛùs   ƒA<¡A<ªAA<Á2
A<)r   r   r   ÚlistdirÚOSErrorr   )Úentriesr   r   s    @@r   Ú_discover_homebrew_node_dirsr$      s{   ù€ ð '€LðÜ.0¯g©g¯m©m¸L×.IÒ.I”"—*’*˜\Ô*Èrˆ÷ Œ5õ áó�5ð ˆ5õ áóó ð øô ô ØŠðús   †$A7 «A7 Á7BÂBc                ó:   € V ^8„  d   QhR\         \        ,          /# ©r
   r   )Úlistr   )r   s   "r   r   r       s   € ÷ Cñ C¤d¬3¥iñ Cr   c                 óF   € \        4       p . \        4       OV P                  O# )z;System PATH fallbacks for externally owned browser helpers.)Ú_originr$   Ú_SANE_PATH_DIRS)Ú_bts    r   Ú_browser_candidate_path_dirsr,       s#   € ä
‹)€CØBÔ)Ó+ÐB¨c×.AÑ.AÐBÐBr   c                ó0   € V ^8„  d   QhR\         R\         /# )r
   Úexisting_pathr   ©r   )r   s   "r   r   r   &   s   € ÷ 6ñ 6¤sð 6´Cñ 6r   c                ó¢  € T ;'       g    RP                  \        P                  4       Uu. uF  q'       g   K  VNK  	  pp. p\        4        FU  pV'       g   K  WB9  g   K  WC9  g   K  \        P                  P                  V4      '       g   KD  VP                  V4       KW  	  \        P                  P                  W2,           4      # u upi )zLPrepend browser-specific PATH fallbacks without reordering existing entries.Ú )Úsplitr   Úpathsepr,   r   r   Úappendr   )r.   ÚpÚ
path_partsÚprefix_partsÚparts   &    r   Ú_merge_browser_pathr9   &   s“   € à+×1Ð1¨r×8Ñ8¼¿¹ÔDÓJÑD˜Ë—!�!ÑD€JÐJØ €LÜ,Ö.ˆß‰4�DÖ*¨tÖ/GÌBÏGÉGÏMÉMÐZ^×L_ÔL_Ø×Ñ Ö%ñ /ô �:‰:�?‰?˜<Õ4Ó5Ð5ùò Ks
   ¬	CºCc                ó$   € V ^8„  d   QhR\         /# r&   r/   )r   s   "r   r   r   0   s   € ÷ fñ fœsñ fr   c                  ó*   € \        4       '       d   R # R# )z5npm install -g agent-browser && agent-browser installzXhermes pm install agent-browser (system libraries: npx playwright install-deps chromium))Ú_is_termux_environment© r   r   Ú_browser_install_hintr>   0   s   € Ü×ÒÙFÙer   c                ó>   € V ^8„  d   QhR\         R,          R\        /# )r
   r   Nr   )r   Úbool)r   s   "r   r   r   6   s"   € ÷ Rñ R¬3°­:ð R¼$ñ Rr   c                 óä   € V '       g   R # \         P                  P                  V 4      ;'       dA    \         P                  R8H  ;'       g&    \         P                  ! V \         P
                  4      # )FÚnt)r   r   ÚisfileÚnameÚaccessÚX_OK©r   s   &r   Ú _agent_browser_candidate_presentrH   6   sB   € ßÙÜ�7‰7�>‰>˜$Ó×QÐQ¤R§W¡W°¡_×%PÐ%P¼¿	º	À$ÌÏÉÓ8PÐQr   ÚvalidateTc                ó0   € V ^8„  d   QhR\         R\        /# )r
   rI   r   )r@   r   )r   s   "r   r   r   <   s   € ÷ "ñ "¤Tð "´Sñ "r   c                ó¼  € ^ RI p\        4       pV'       g=   VP                  R4      pV'       d$   VP                  e   \	        VP                  4      # V '       d   \
        M\        pR\        R4      3 F@  pVR8X  d   K  \        P                  ! RVR7      pV'       g   K.  V! V4      '       g   K>  Vu # 	  R\        4        2pV '       dW   V'       gO    VP                  R4       TP                  R4      pT'       d$   TP                  e   \	        TP                  4      # \        V4      h  TP                  \        3 d   p\        T RT 24      ThRp?ii ; i)ad  Select PM's exact binary, then an external PATH/Homebrew installation.

Termux owns its browser installation. Elsewhere PM may acquire a missing
CLI at execution time, subject to its lazy-install policy. Readiness checks
(``validate=False``) never execute or install anything. Selection is not
cached: a new PM fact or profile must be visible immediately.
Nzagent-browserr1   rG   z.agent-browser CLI not found. Install it with: Ú
)Úpmr<   Úinstalled_packageÚbinaryr   r   rH   r9   ÚshutilÚwhichr>   ÚensureÚInstallErrorr"   ÚFileNotFoundError)	rI   rM   ÚtermuxÚ	installedÚusableÚsearch_pathÚ	candidateÚhintÚexcs	   $        r   Ú_find_agent_browserr\   <   s)  € ó ä#Ó%€FßØ×(Ñ(¨Ó9ˆ	ß˜×)Ñ)Ò5Ü�y×'Ñ'Ó(Ð(ß'/Õ#Ô5U€FØÔ1°"Ó5Ó6ˆØ˜"ÔÙÜ—L’L °{ÔCˆ	ß‰9™ 	×*Ô*ØÒñ 7ð <Ô<QÓ<SÐ;TÐU€DßŸð	?Ø�I‰I�oÔ&ð ×(Ñ(¨Ó9ˆ	ß˜×)Ñ)Ò5Ü�y×'Ñ'Ó(Ð(Ü
˜DÓ
!Ð!øð —‘¤Ð)ô 	?Ü# t f¨B¨s¨eÐ$4Ó5¸3Ð>ûð	?ús   ÃD. Ä.EÅEÅEc                ó0   € V ^8„  d   QhR\         R\        /# )r
   Útimeoutr   )Úfloatr@   )r   s   "r   r   r   ^   s   € ÷ ñ ¬%ð ¼4ñ r   c                ó   € R# )z¬Frozen old-updater surface names this module too (the extraction-era home); tools.browser_tool
carries the permanent definition. No npx work is performed; relaunch instead.Fr=   )r^   s   &r   Úwarm_agent_browser_npx_cachera   ^   s   € ñ r   c                ó$   € V ^8„  d   QhR\         /# r&   ©r@   )r   s   "r   r   r   d   s   € ÷ Pñ PœTñ Pr   c                 ó¼   € ^ RI Hp  V ! 4       p\        T;'       d>    \        P                  P                  V4      ;'       g    \        P                  ! V4      4      # )zEAn explicit browser executable or PM's selected full Chromium exists.)Úchromium_executable)Úhermes_cli.browser_runtimere   r@   r   r   rC   rP   rQ   )re   Úab_paths     r   Ú_chromium_installedrh   d   s>   € å>á!Ó#€GÜ�×NÐNœRŸW™WŸ^™^¨GÓ4×MÐM¼¿ºÀWÓ8MÓOÐOr   c                ó$   € V ^8„  d   QhR\         /# r&   rc   )r   s   "r   r   r   l   s   € ÷ !ñ !¤Tñ !r   c                 óæ  € \        4       p V P                  '       d   \        4       # RV n        \        4       '       g6   \	        4       '       g&   \
        P                  P                  R4      '       d   R# ^ RIH	pH
pHp V! 4       '       g   R# V P                  P                  R4        V! R4       \        4       #   T\        3 d(   pT P                  P                  RT4        Rp?R# Rp?ii ; i)	z“Install only PM's pinned full Chromium, never the upstream browser pair.

Docker supplies the binary. Other installs require lazy-install consent.
TÚAGENT_BROWSER_EXECUTABLE_PATHF)rS   rR   Úlazy_installs_allowedz(browser: installing PM's pinned ChromiumÚchromiumz)browser: Chromium auto-install failed: %sN)r)   Ú_chromium_autoinstall_attemptedrh   Ú_running_in_dockerr<   r   ÚenvironÚgetrM   rS   rR   rl   ÚloggerÚinfor"   Úwarning)r+   rS   rR   rl   r[   s        r   Ú_maybe_autoinstall_chromiumru   l   sº   € ô
 ‹)€CØ
×*×*Ð*Ü"Ó$Ð$Ø*.€CÔ'Ü×ÒÔ5×7Ò7¼2¿:¹:¿>¹>ÐJi×;jÒ;jÙß>Ñ>Ù ×"Ò"ÙØ‡J�J‡O�OÐ>Ô?ðÙˆzÔô Ó Ð øð œ'Ð"ô Ø�
‰
×ÑÐFÈÔLÝûðús   Â*B< Â<C0Ã	C+Ã+C0c                ó$   € V ^8„  d   QhR\         /# r&   rc   )r   s   "r   r   r   ƒ   s   € ÷ ñ œDñ r   c                 ó  € \         P                  P                  R4      '       d   R#  \        RRRR7      ;_uu_ 4       p RV P	                  4       9   uuRRR4       #   + '       g   i     R# ; i  \
         d     R	# i ; i)
zABest-effort detection of whether we're inside a Docker container.z/.dockerenvTz/proc/1/cgroupÚrtzutf-8)ÚencodingÚdockerNF)r   r   ÚexistsÚopenÚreadr"   )Úfps    r   ro   ro   ƒ   s]   € ä	‡w�w‡~�~�m×$Ò$ÙðÜÐ" D°7×;Õ;¸rØ˜rŸw™w›yÑ(÷ <×;×;Ó;ûäô Úðús.   ©A1 ¿AÁ
A1 ÁA.	Á(A1 Á.A1 Á1B Á?B c                ó$   € V ^8„  d   QhR\         /# r&   rc   )r   s   "r   r   r   Ž   s   € ÷ !ñ !¤Dñ !r   c                 óŽ  € \        4       p V P                  4       '       d   R# V P                  4       '       d   R# \        P                  ! 4       '       d   R#  \        RR7       \        P                  ! 4       pTe   TP                  4       # \        P                  ! 4       '       d   R# \        4       #   \         d     R# i ; i)zõWhether the browser tools should be advertised.

Local mode needs the ``agent-browser`` CLI plus a Chromium build (except Lightpanda-only text workflows);
cloud mode needs the CLI plus provider credentials (the provider hosts its own Chromium).
FT)rI   )r)   Ú_is_browser_use_cli_modeÚ_is_camofox_modeÚ_cdpÚ_get_cdp_override_rawr\   rT   Ú_cloudÚ_get_cloud_providerÚis_availableÚ_lpÚ_using_lightpanda_enginerh   )r+   Úproviders     r   Úcheck_browser_requirementsr‹   Ž   s¢   € ô ‹)€Cà
×#Ñ#×%Ò%Ùà
×Ñ×ÒÙä×!Ò!×#Ò#ÙðÜ UÕ+ô
 ×)Ò)Ó+€HØÒØ×$Ñ$Ó&Ð&ä
×#Ò#×%Ò%ÙäÓ Ð øô ô Úðús   ÁB5 Â5CÃCc                ó$   € V ^8„  d   QhR\         /# r&   rc   )r   s   "r   r   r   ¯   s   € ÷ 
'ñ 
'¬4ñ 
'r   c                 ó@   € \        4       '       g   R# ^ RIHp  V ! 4       # )aD  Advertise ``browser_vision`` only with BOTH a working browser AND a vision backend.

Without the vision check, the tool stays in the model's tool list even when no vision provider is
configured, then fails at call time with a cryptic provider-side error like ``unknown variant
`image_url`, expected `text``` (issue #31179).
F©Úcheck_vision_requirements)r‹   Útools.vision_toolsr�   rŽ   s    r   Ú!check_browser_vision_requirementsr‘   ¯   s   € ô &×'Ò'ÙÝ<Ù$Ó&Ð&r   )r1   )g      N@)Ú__doc__Ú	functoolsr   rP   Úhermes_constantsr   r   r<   Útools.browser_tool_originr   r)   Útoolsr   rƒ   r   r…   r   rˆ   Ú	lru_cacher$   r,   r9   r>   rH   r\   ra   rh   ru   ro   r‹   r‘   r=   r   r   Ú<module>r˜      sˆ   ðñWó Û 	Û ç XÝ >Ý *Ý .Ý 9ð ×Ò˜QÔôó  ðõC÷6õfõRð"¨D÷ "÷DõPõ!õ.õ!÷B
'r   