Skip to content

The agent that grows with you

refactor(browser_exec): resolve every browser through browser_session

Tekniuma99fa3d2491b
diff --git a/tools/browser_use_cli.py b/tools/browser_use_cli.py
index 59f900d65b8..6b1422351af 100644
--- a/tools/browser_use_cli.py
+++ b/tools/browser_use_cli.py
@@ -1,7 +1,9 @@
-"""Use the Browser Use CLI 3.0 (https://browser-use.com) for browser automation
+"""``browser_exec``: drive a real browser through the Browser Use CLI engine (browser-harness,
+https://browser-use.com), Hermes' only core browser tool.
-When browser.backend is "browser-use", the model gets ``browser_exec`` tool
-instead of default browser tools
+The harness speaks CDP to whatever ``tools.browser_session`` resolved for the call: an operator
+``BU_CDP_*`` endpoint, a ``/browser connect`` override, a cloud provider's session, or a local browser
+(real profile, Lightpanda, or the packaged Chromium started by ``tools.browser_launcher``).
"""
import contextlib
@@ -26,8 +28,9 @@ from utils import is_truthy_value
logger = logging.getLogger(__name__)
-_BACKEND_KEY = "browser-use"
-BACKEND_DISABLED = "off"
+_BROWSER_USE_PROVIDER = "browser-use"
+# The one credential the harness itself reads (BU_AUTOSPAWN of a Browser Use cloud browser).
+_HARNESS_PASSTHROUGH_KEYS: tuple[str, ...] = ("BROWSER_USE_API_KEY",)
# Cloud daemon names become the BU_NAME env var
_SESSION_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$")
@@ -90,9 +93,10 @@ _STDERR_CAP_CHARS = 4000
_TASK_ID_SAFE_RE = re.compile(r"[^A-Za-z0-9._-]+") # filesystem-safe task ids
# Screenshot paths printed by capture_screenshot(): POSIX or Windows drive-letter absolute.
_IMAGE_PATH_RE = re.compile(r"((?:[A-Za-z]:[\\/]|/)[^\s\"']+?\.(?:png|jpe?g|webp))", re.IGNORECASE)
-# http(s) URL literals in exec code checked against browser_navigate's policy
+# http(s) URL literals in exec code, checked against the browser URL policy
_URL_RE = re.compile(r"https?://[^\s'\"\\)]+", re.IGNORECASE)
-_FHS_BIN_DIRS = ("/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin")
+_FHS_BIN_DIRS = ("/opt/homebrew/bin", "/opt/homebrew/sbin", "/usr/local/sbin", "/usr/local/bin", "/usr/sbin",
+ "/usr/bin", "/sbin", "/bin")
def _quiet(fn: Callable[[], Any], default: Any, log_prefix: str = "") -> Any:
@@ -111,12 +115,8 @@ def _lazy_call(module: str, name: str, default: Any, log_prefix: str) -> Any:
return _quiet(lambda: getattr(importlib.import_module(module), name)(), default, log_prefix)
-def _camofox_active(context: str = "") -> bool:
- return _lazy_call("tools.browser_camofox", "is_camofox_mode", False, f"Camofox activity check failed{context}")
-
-
def _real_profile_consented() -> bool:
- return _lazy_call("tools.browser_tool_cloud", "_use_real_profile", False, "real-profile consent lookup failed")
+ return _lazy_call("tools.browser_session_cloud", "use_real_profile", False, "real-profile consent lookup failed")
def _set_cdp_env(env: dict, cdp: str) -> None:
@@ -153,10 +153,10 @@ def _code_url_verdict(code: str) -> _CodeUrlVerdict:
the hybrid LOCAL sidecar. Each URL's routing predicate is evaluated ONCE and feeds both answers: it
resolves DNS unmemoised, so a rebinding host evaluated twice could relax the private-address floor and
still route to the cloud provider."""
- from tools.browser_tool import _hybrid_routes_locally, evaluate_url_safety
+ from tools.browser_url_policy import evaluate_url_safety, hybrid_routes_locally
local_sidecar = False
for url in _URL_RE.findall(code or ""):
- routes_local = _hybrid_routes_locally(url)
+ routes_local = hybrid_routes_locally(url)
local_sidecar = local_sidecar or routes_local
err = evaluate_url_safety(url, auto_local=routes_local)
if err:
@@ -164,9 +164,20 @@ def _code_url_verdict(code: str) -> _CodeUrlVerdict:
return _CodeUrlVerdict(None, local_sidecar)
+def _harness_credentials() -> dict:
+ """The harness's own credential from the active profile's secret scope, never ``os.environ``: under
+ multiplex that holds the LAUNCH profile's key, and a served profile's browser runs on its own (or none)."""
+ from agent.secret_scope import current_secret_scope, get_secret, serves_routed_profile
+ routed = serves_routed_profile()
+ scope = (current_secret_scope() or {}) if routed else None
+ values = {key: (scope.get(key) if routed else get_secret(key)) for key in _HARNESS_PASSTHROUGH_KEYS}
+ return {key: value for key, value in values.items() if value is not None}
+
+
def _base_subprocess_env() -> dict:
- from tools.browser_tool import _build_browser_env
- env = _build_browser_env()
+ from tools.browser_session import build_browser_env
+ env = build_browser_env()
+ env.update(_harness_credentials())
# The harness runs on Hermes's own interpreter, but a bundled Desktop install boots that
# interpreter with its site dir on PYTHONPATH (no venv to activate), and the harness's daemon
# re-runs sys.executable. Point PYTHONPATH at the harness's site dir, replacing whatever the
@@ -191,9 +202,6 @@ def _floor_subprocess_path(path: str) -> str:
"""
if os.name == "nt":
return path
- with contextlib.suppress(Exception):
- from tools.browser_tool_install import _merge_browser_path
- return _merge_browser_path(path or "")
parts = [p for p in (path or "").split(os.pathsep) if p]
return os.pathsep.join(parts + [d for d in _FHS_BIN_DIRS if d not in set(parts) and os.path.isdir(d)])
@@ -223,32 +231,13 @@ def _use_gateway(browser_cfg: dict) -> bool:
return str(browser_cfg.get("cloud_provider") or "").strip().lower() == NOUS_MANAGED_PROVIDER
-def get_browser_backend() -> str:
- """Configured browser backend key ("" = unset → default). YAML 1.1 parses an
- unquoted ``off`` as False — that must mean BACKEND_DISABLED, not "unset"."""
- raw = _read_browser_cfg().get("backend")
- return (BACKEND_DISABLED if raw is False else "") if isinstance(raw, bool) else str(raw or "").strip().lower()
-
-
-def set_browser_use_mode(enabled: bool) -> None:
- """``/browser use [off]`` on every surface: persist ``browser.backend`` for the current profile and drop
- cached tool availability. A live agent keeps its tools (prompt cache); the next one built gets the swap."""
- from hermes_cli.config import load_config, save_config
- from tools.registry import invalidate_check_fn_cache
- config = load_config()
- config.setdefault("browser", {})["backend"] = _BACKEND_KEY if enabled else BACKEND_DISABLED
- save_config(config)
- invalidate_check_fn_cache()
-
-
def is_legacy_browser_use_cloud_config(browser_cfg: dict) -> bool:
- """True for pre-CLI direct-API Browser Use cloud configs. An explicit backend or
- a non-Browser-Use cloud_provider wins; Camofox is selected via env var, not
- cloud_provider, so a Camofox user with a stray BROWSER_USE_API_KEY keeps it."""
- if not isinstance(browser_cfg, dict) or browser_cfg.get("backend"):
+ """True for pre-CLI direct-API Browser Use cloud configs: no cloud_provider (or ``browser-use``), not the
+ Nous gateway, and BROWSER_USE_API_KEY set; the CLI then reaches Browser Use cloud natively."""
+ if not isinstance(browser_cfg, dict):
return False
provider = str(browser_cfg.get("cloud_provider") or "").strip().lower()
- if provider not in {"browser-use", ""} or _use_gateway(browser_cfg) or _camofox_active(" during migration"):
+ if provider not in {"browser-use", ""} or _use_gateway(browser_cfg):
return False
return _browser_use_api_key_set()
@@ -260,39 +249,6 @@ def _browser_use_api_key_set() -> bool:
return bool(get_secret("BROWSER_USE_API_KEY", ""))
-def is_browser_use_cli_mode() -> bool:
- """True when the Browser Use CLI replaces the built-in browser stack. Browser Use mode is the DEFAULT:
- unset ``browser.backend`` ("") enables it whenever browser-harness is importable (a core dependency);
- ``browser.backend: off`` keeps the built-in browser_* tools. Camofox always falls back to the built-in
- tools (Firefox, custom HTTP API, no CDP surface for the harness)."""
- if _camofox_active():
- return False
- backend = get_browser_backend()
- return backend == _BACKEND_KEY if backend else (is_legacy_browser_use_cloud_config(_read_browser_cfg()) or _find_cli() is not None)
-
-
-def default_downgrade_notice() -> Optional[str]:
- """One-line notice when ``browser.backend`` is unset but the CLI is not runnable, so
- the session fell back to the built-in tools. Rate-limited to once per 24h via a stamp file."""
- try:
- if get_browser_backend() or _camofox_active() or _find_cli() is not None:
- return None # explicit choice / Camofox / CLI present — nothing downgraded
- stamp = Path(get_hermes_home()) / "cache" / ".browser_use_default_notice"
- now = time.time()
- with contextlib.suppress(OSError):
- if 0 <= now - stamp.stat().st_mtime < 24 * 3600:
- return None
- with contextlib.suppress(OSError):
- stamp.parent.mkdir(parents=True, exist_ok=True)
- stamp.touch()
- os.utime(stamp, (now, now))
- return ("browser-harness is missing from Hermes's Python environment — using the built-in browser tools. "
- "Run `hermes update` to re-sync it, or set `browser.backend: off` in config.yaml to silence this.")
- except Exception as e: # pragma: no cover — a notice must never break startup
- logger.debug("browser-use downgrade notice failed: %s", e)
- return None
-
-
def _harness_site_dir() -> Optional[str]:
"""The site dir Hermes's interpreter imports ``browser_harness`` from, or None."""
spec = importlib.util.find_spec("browser_harness")
@@ -309,6 +265,11 @@ def _find_cli() -> Optional[list[str]]:
return [sys.executable, "-m", "browser_harness.run"]
+def browser_exec_available() -> bool:
+ """check_fn: browser-harness is importable (a core dependency). Never launches or opens sockets."""
+ return _find_cli() is not None
+
+
def _workspace_dir(task_id: Optional[str]) -> Optional[str]:
"""Stable per-task scratch dir that persists across browser_exec calls"""
if os.environ.get("BH_AGENT_WORKSPACE"):
@@ -385,100 +346,47 @@ def _sidecar_daemon_name(name: str) -> str:
def _export_real_profile_note(env: dict, key: str) -> None:
"""The session layer decides real profile vs fresh browser once per key; carry its note (if it fell
back) so the result reports the browser this call actually drives."""
- from tools.browser_tool_session import real_profile_note
+ from tools.browser_session import real_profile_note
note = real_profile_note(key)
if note:
env.setdefault(_REAL_PROFILE_FALLBACK_SENTINEL, note)
-def _resolve_lightpanda_cdp(env: dict, task_id: Optional[str], session_name: str = "",
- sidecar: bool = False) -> Optional[str]:
- """Point the harness at a Hermes-spawned ``lightpanda serve`` (``browser.engine: lightpanda`` and
- nothing of higher precedence claimed the session). Each cache key gets its own process via the
- legacy ``_get_session_info()`` (cache, reaper, atexit): private browser, own-tab preamble skipped."""
- try:
- from tools.browser_tool_session import _get_session_info
- from tools.browser_tool_lightpanda_fallback import _using_lightpanda_engine
- if not _using_lightpanda_engine():
- return None
- except Exception as e: # stubbed browser_tool in tests / engine lookup failure
- logger.debug("browser engine lookup failed: %s", e)
- return None
- err = _export_session_cdp(
- env, _get_session_info, _backend_cache_key(task_id, session_name, sidecar),
- lambda e: (f"Lightpanda could not be started: {e} Set browser.engine to auto "
- "to use local Chrome, or switch backends via `hermes tools` → Browser Automation."),
- "Lightpanda session returned no CDP endpoint. Set browser.engine to auto to use local Chrome.",
- )
- if err is None:
+def _mark_local_browser(env: dict, session: dict, key: str) -> None:
+ """Flags for a LOCAL session browser: it runs on the Bot Desktop display (lease fence), and unless a
+ persistent profile / the real-profile browser is shared by every key, it is exclusive to this key (no
+ own-tab preamble: nothing to share a tab with)."""
+ env[_BOT_DESKTOP_BROWSER_SENTINEL] = "1"
+ features = session.get("features") or {}
+ if not session.get("shared_profile") and not features.get("real_profile"):
env[_PRIVATE_BROWSER_SENTINEL] = "1"
- env[_BOT_DESKTOP_BROWSER_SENTINEL] = "1"
- _export_real_profile_note(env, _backend_cache_key(task_id, session_name, sidecar))
- return err
+ _export_real_profile_note(env, key)
-def _reach_sandbox_cdp(cdp: str) -> str:
- """A CDP endpoint agent-browser reported from INSIDE the terminal backend's sandbox is that sandbox's
- loopback: unreachable from this host (Docker bridge / ssh remote). The harness, the vault supervisor
- and ``browser_exec`` all connect from here, so forward the port over the sandbox's exec stream and hand
- them the local end. Chromium's DevTools accepts any loopback ``Host`` header, port included."""
- try:
- from tools.browser_tool_session import _browser_in_sandbox
- if not _browser_in_sandbox():
- return cdp
- from urllib.parse import urlsplit, urlunsplit
- from tools.bot_desktop import runtime as _bd_runtime, sandbox_host
- from tools.environments import streams
- parts = urlsplit(cdp)
- if parts.hostname not in ("127.0.0.1", "localhost") or not parts.port:
- return cdp
- sandbox = _bd_runtime._sandbox_env(create=True)
- if sandbox is None:
- return cdp
- local = streams.forward_port(sandbox, parts.port, user=sandbox_host._user_for(sandbox))
- return urlunsplit(parts._replace(netloc=f"127.0.0.1:{local}"))
- except Exception as e: # a failed forward degrades to the unreachable endpoint's own error
- logger.debug("sandbox CDP forward unavailable: %s", e)
- return cdp
-
-
-def _resolve_managed_chromium_cdp(env: dict, task_id: Optional[str], session_name: str = "",
- sidecar: bool = False) -> Optional[str]:
- """Point the harness at Hermes' packaged Chromium, launched through agent-browser for this cache key —
- the same browser the built-in tools drive. Left alone, the harness discovers the user's INSTALLED
- Chrome on its default profile, which needs the chrome://inspect toggle + an Allow popup per run and
- is blocked outright on Chrome >=136; on a headless box it just reports ``chrome-not-running``.
- ``get cdp-url`` runs through ``_run_browser_command`` (legacy cache, inactivity reaper, atexit, Chromium
- preflight/auto-install) on EVERY call: it launches the browser cold, follows a relaunch, and refreshes
- the agent-browser daemon's idle timer, which never sees the harness's direct CDP traffic."""
- try:
- from tools.browser_tool_session import _run_browser_command
- from tools.browser_tool import _get_open_command_timeout
- except Exception as e: # pragma: no cover — stubbed browser_tool in tests
- logger.debug("managed chromium resolution unavailable: %s", e)
- return None
- res = _run_browser_command(_backend_cache_key(task_id, session_name, sidecar), "get", ["cdp-url"],
- timeout=_get_open_command_timeout(first_open=True))
- cdp = str(((res or {}).get("data") or {}).get("cdpUrl") or "") if (res or {}).get("success") else ""
- if not cdp:
- return (f"The local browser could not be started: {(res or {}).get('error') or 'agent-browser returned no CDP endpoint'} "
- "Run `hermes tools` → Browser Automation to (re)install Chromium, or switch backends.")
- cdp = _reach_sandbox_cdp(cdp)
- _set_cdp_env(env, cdp)
- env[_PRIVATE_BROWSER_SENTINEL] = "1" # one Chromium per cache key: nothing to share a tab with
- env[_BOT_DESKTOP_BROWSER_SENTINEL] = "1"
- _export_real_profile_note(env, _backend_cache_key(task_id, session_name, sidecar))
- return None
+def _resolve_local_cdp(env: dict, task_id: Optional[str], session_name: str = "",
+ sidecar: bool = False) -> Optional[str]:
+ """Local browser for this cache key through the session layer: the consented real profile, Lightpanda
+ (``browser.engine: lightpanda``), or the packaged Chromium. Never the harness's own discovery of the
+ user's installed Chrome (chrome://inspect toggle + Allow popup per run, blocked on Chrome >=136)."""
+ from tools.browser_lightpanda import using_lightpanda_engine
+ from tools.browser_session import get_session_info
+ key = _backend_cache_key(task_id, session_name, sidecar)
+ session: dict = {}
+ def _session_info(cache_key: str) -> dict:
+ session.update(get_session_info(cache_key) or {})
+ return session
-def _resolve_local_engine_cdp(env: dict, task_id: Optional[str], session_name: str = "",
- sidecar: bool = False) -> Optional[str]:
- """Local engine (no provider / override, or the hybrid sidecar): ``browser.engine: lightpanda`` or the
- packaged Chromium."""
- err = _resolve_lightpanda_cdp(env, task_id, session_name, sidecar)
- if err or _has_cdp_env(env):
- return err
- return _resolve_managed_chromium_cdp(env, task_id, session_name, sidecar)
+ if _quiet(using_lightpanda_engine, False):
+ fail = lambda e: (f"Lightpanda could not be started: {e} Set browser.engine to auto "
+ "to use local Chrome, or switch backends via `hermes tools` → Browser Automation.")
+ else:
+ fail = lambda e: (f"The local browser could not be started: {e} "
+ "Run `hermes tools` → Browser Automation to (re)install Chromium, or switch backends.")
+ err = _export_session_cdp(env, _session_info, key, fail, "The local browser session returned no CDP endpoint.")
+ if err is None:
+ _mark_local_browser(env, session, key)
+ return err
def _resolve_backend_cdp(env: dict, task_id: Optional[str], session_name: str = "",
@@ -486,9 +394,9 @@ def _resolve_backend_cdp(env: dict, task_id: Optional[str], session_name: str =
"""Point the harness at the configured backend's CDP endpoint; error string on failure.
Precedence: (1) ``BU_CDP_WS``/``BU_CDP_URL`` already in env (operator override); (2) ``BROWSER_CDP_URL``
- env / ``browser.cdp_url`` (``/browser connect``); (3) a cloud provider via the legacy ``_get_session_info()``
- so browser_exec shares the SAME session machinery (per-task cache, expiry, reaper, atexit);
- (4) the local engine — ``browser.engine: lightpanda`` or Hermes' packaged Chromium via agent-browser
+ env / ``browser.cdp_url`` (``/browser connect``); (3) a cloud provider via ``browser_session.get_session_info``
+ (per-key cache, expiry, reaper, atexit; a provider failure falls back to a local browser);
+ (4) the local engine — ``browser.engine: lightpanda`` or Hermes' packaged Chromium via the launcher
(never the harness's own discovery of the user's installed Chrome); (5) BU direct-API configs WITH
``BROWSER_USE_API_KEY`` → None (checked before (3)): the CLI reaches BU cloud natively (BU_AUTOSPAWN); a
keyless ``browser-use`` provider (managed-gateway autodetect, or a selection missing its key) takes (3).
@@ -496,26 +404,22 @@ def _resolve_backend_cdp(env: dict, task_id: Optional[str], session_name: str =
sessions concurrent-safe.
``force_local_sidecar`` skips step (3): the call runs on the local engine under the ``::local`` cache
- key (hybrid routing; see ``_hybrid_routes_locally``). It sits BELOW the two operator overrides, and the
+ key (hybrid routing; see ``browser_url_policy.hybrid_routes_locally``). It sits BELOW the two operator overrides, and the
sidecar verdict never fires while a CDP override is set."""
if _has_cdp_env(env):
return None
- try:
- from tools.browser_tool_cloud import _get_cloud_provider
- from tools.browser_tool_session import _get_session_info
- from tools.browser_tool_cdp import _get_cdp_override
- except Exception as e: # pragma: no cover — stubbed browser_tool in tests
- logger.debug("browser_tool backend resolution unavailable: %s", e)
- return None
- override = _quiet(_get_cdp_override, "")
+ from tools.browser_session import get_session_info
+ from tools.browser_session_cdp import get_cdp_override
+ from tools.browser_session_cloud import get_cloud_provider
+ override = _quiet(get_cdp_override, "")
if override:
_set_cdp_env(env, override)
return None
if force_local_sidecar:
- return _resolve_local_engine_cdp(env, task_id, session_name, sidecar=True)
- provider = _quiet(_get_cloud_provider, None, "Cloud provider lookup failed")
+ return _resolve_local_cdp(env, task_id, session_name, sidecar=True)
+ provider = _quiet(get_cloud_provider, None, "Cloud provider lookup failed")
if provider is None:
- return _resolve_local_engine_cdp(env, task_id, session_name)
+ return _resolve_local_cdp(env, task_id, session_name)
# Browser Use direct-API configs: the CLI talks to BU cloud natively (BU_AUTOSPAWN) — the
# legacy provider would create a second, redundant session. Nous-gateway configs (cloud_provider: nous
@@ -525,7 +429,7 @@ def _resolve_backend_cdp(env: dict, task_id: Optional[str], session_name: str =
# a selection missing its key; both go through the session path (gateway CDP, or the session layer's
# local-Chromium fallback) instead of leaving the harness to hunt for an installed Chrome.
provider_key = str(getattr(provider, "name", "") or "").strip().lower()
- if provider_key == _BACKEND_KEY and not _use_gateway(_read_browser_cfg()) and _browser_use_api_key_set():
+ if provider_key == _BROWSER_USE_PROVIDER and not _use_gateway(_read_browser_cfg()) and _browser_use_api_key_set():
env[_PRIVATE_BROWSER_SENTINEL] = "1" # named BU cloud browsers are exclusive to their daemon
return None
@@ -533,22 +437,25 @@ def _resolve_backend_cdp(env: dict, task_id: Optional[str], session_name: str =
session: dict = {}
def _session_info(key: str) -> dict:
- session.update(_get_session_info(key) or {})
+ session.update(get_session_info(key) or {})
return session
+ key = _backend_cache_key(task_id, session_name)
err = _export_session_cdp(
- env, _session_info, _backend_cache_key(task_id, session_name),
+ env, _session_info, key,
lambda e: (f"Cloud browser provider {provider_name} failed to provide a session: {e}. "
"Fix the provider configuration or switch backends via `hermes tools` → Browser Automation."),
- f"Cloud browser provider {provider_name} returned no CDP endpoint, so Browser Use mode "
- "cannot drive it. Switch to the built-in browser tools for this provider.",
+ f"Cloud browser provider {provider_name} returned no CDP endpoint, so browser_exec "
+ "cannot drive it. Pick a CDP-capable provider via `hermes tools` → Browser Automation.",
)
- if err and session.get("fallback_from_cloud"):
- # The provider failed (rate limit, quota, outage) and the session layer fell back to local
- # Chromium, as it does for the built-in tools; that session has no CDP URL until it launches.
+ if session.get("fallback_from_cloud"):
+ # The provider failed (rate limit, quota, outage) and the session layer fell back to a LOCAL
+ # browser for this key; it already carries its CDP URL.
logger.warning("browser_exec: %s failed (%s); using local Chromium for this session",
provider_name, session.get("fallback_reason"))
- return _resolve_managed_chromium_cdp(env, task_id, session_name)
+ if err is None:
+ _mark_local_browser(env, session, key)
+ return err
# A provider browser keyed bu-named-<name> is exclusive to this session — the
# own-tab preamble would just leak a blank tab into it.
if err is None and session_name:
@@ -565,21 +472,17 @@ def _resolve_real_profile_cdp(env: dict, force_local: bool) -> Optional[str]:
``_route_backend`` then falls back to the normal backend and reports it, never silently."""
if not _real_profile_consented() or _has_cdp_env(env):
return None
- try:
- from tools.browser_tool_cdp import _get_cdp_override_raw
- from tools.browser_tool_cloud import _get_cloud_provider
- from tools.browser_tool_real_profile import _real_profile_cdp
- except Exception as e: # pragma: no cover — stubbed browser_tool in tests
- logger.debug("real-profile backend resolution unavailable: %s", e)
- return None
- if _quiet(_get_cdp_override_raw, ""):
+ from tools.browser_session_cdp import get_cdp_override_raw
+ from tools.browser_session_cloud import get_cloud_provider
+ from tools.browser_session_real_profile import real_profile_cdp
+ if _quiet(get_cdp_override_raw, ""):
return None
# Only auto-upgrade genuinely-local attaches; any cloud path (provider, provider lookup failure, or
# legacy BU cloud config) stays on its backend unless the model passes local=true.
- if not force_local and (_quiet(_get_cloud_provider, object()) is not None
+ if not force_local and (_quiet(get_cloud_provider, object()) is not None
or is_legacy_browser_use_cloud_config(_read_browser_cfg())):
return None
- cdp, err = _real_profile_cdp()
+ cdp, err = real_profile_cdp()
if cdp and not err:
_set_cdp_env(env, cdp)
env[_BOT_DESKTOP_BROWSER_SENTINEL] = "1"
@@ -594,10 +497,10 @@ def _attach_vault_supervisor(env: dict, task_id: Optional[str]) -> None:
if not cdp:
return
try:
+ from tools.browser_session_cdp import get_dialog_policy_config, resolve_cdp_override
from tools.browser_supervisor import SUPERVISOR_REGISTRY
- from tools.browser_tool_cdp import _get_dialog_policy_config, _resolve_cdp_override
- policy, timeout_s = _get_dialog_policy_config()
- SUPERVISOR_REGISTRY.get_or_start(task_id=task_id or "default", cdp_url=_resolve_cdp_override(cdp),
+ policy, timeout_s = get_dialog_policy_config()
+ SUPERVISOR_REGISTRY.get_or_start(task_id=task_id or "default", cdp_url=resolve_cdp_override(cdp),
dialog_policy=policy, dialog_timeout_s=timeout_s)
except Exception as exc:
logger.debug("browser_exec: CDP supervisor attach failed (non-fatal): %s", exc)
@@ -621,10 +524,10 @@ def _route_backend(env: dict, session: str, task_id: Optional[str], local: bool,
"(browser.use_real_profile: true) or the desktop Settings → Browser section, then retry.")
# local=True promised the user's own machine: a profile that can't load runs on a fresh LOCAL browser
# (the sidecar, which never loads the profile), never the cloud one. Without ``local`` the session
- # layer makes the one real-profile-or-fresh decision and reports it (_resolve_managed_chromium_cdp).
+ # layer makes the one real-profile-or-fresh decision and reports it (_resolve_local_cdp).
if local and not _has_cdp_env(env) and (rp_err or not real_profile):
if rp_err:
- from tools.browser_tool_real_profile import real_profile_fallback_note
+ from tools.browser_session_real_profile import real_profile_fallback_note
env[_REAL_PROFILE_FALLBACK_SENTINEL] = real_profile_fallback_note(rp_err)
env[_LOCAL_FALLBACK_SENTINEL] = "1"
force_local_sidecar = True
@@ -635,7 +538,7 @@ def _route_backend(env: dict, session: str, task_id: Optional[str], local: bool,
def _group_popen_kwargs() -> dict:
"""Popen kwargs starting the CLI in its own process group (a new session on POSIX) so a
timeout can take down every process that inherited the capture pipes, not just the CLI
- child. Windows also hides the console the .cmd shim would flash (as browser_tool does)."""
+ child. Windows also hides the console window."""
def _flags() -> dict:
from hermes_cli._subprocess_compat import windows_hide_flags
si = subprocess.STARTUPINFO()
@@ -697,7 +600,7 @@ def _run_cli_killing_process_group(cmd, code, env, timeout):
# swap (/browser connect|disconnect) leaves later calls in the old browser until these are stopped.
_driven_daemons: dict[tuple[str, ...], str] = {} # daemon identity -> home
_driven_daemons_lock = threading.Lock()
-_live_generation = functools.partial(_lazy_call, "tools.browser_tool_cdp", "live_cdp_generation", 0,
+_live_generation = functools.partial(_lazy_call, "tools.browser_session_cdp", "live_cdp_generation", 0,
"live CDP generation lookup failed") # this profile's publish count
# Route cache key -> whether its last browser_exec ran on the hybrid local sidecar.
_exec_route_is_sidecar: dict[str, bool] = {}
@@ -844,7 +747,7 @@ def browser_exec(code: str, session: str = "", timeout_s: int = _DEFAULT_TIMEOUT
return {"error_result": tool_error(f"Failed to launch browser-use CLI: {e}")}
if bot_desktop_browser:
- from tools.browser_tool_session import run_fenced
+ from tools.browser_session import run_fenced
dispatched = run_fenced({"features": {"local": True}}, dispatch)
else:
dispatched = dispatch()
@@ -937,7 +840,7 @@ _HELPERS_DIGEST = (
def _description_header() -> str:
"""Header tailored to whether the active model can see images natively"""
- if _lazy_call("tools.browser_tool_lightpanda_fallback", "lightpanda_engine_status", (False, ""),
+ if _lazy_call("tools.browser_lightpanda", "lightpanda_engine_status", (False, ""),
"lightpanda engine status unavailable")[0]: # no screenshots, whatever the model sees
return _HEADER_BASE + _HEADER_TEXT_ONLY + _HEADER_LIGHTPANDA
vision = _lazy_call("tools.vision_tools", "_should_use_native_vision_fast_path", False, "")
@@ -982,7 +885,7 @@ BROWSER_EXEC_SCHEMA = {
# browser_exec is additionally gated at tool-definition time — sessions whose toolsets
# lack ``terminal`` never see it (model_tools._compute_tool_definitions). check_fn only
-# answers "is Browser Use mode configured"; surface policy lives with the session.
+# answers "is browser-harness importable"; surface policy lives with the session.
from tools.registry import registry
registry.register(
@@ -994,7 +897,7 @@ registry.register(
timeout_s=args.get("timeout_s", _DEFAULT_TIMEOUT_S), task_id=kw.get("task_id"),
local=bool(args.get("local", False)),
),
- check_fn=is_browser_use_cli_mode,
+ check_fn=browser_exec_available,
dynamic_schema_overrides=_dynamic_schema_overrides,
emoji="🌐",
)