The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(browser): camofox_in_use reads only what core selected Camofox by
Teknium6f459e3d9c32
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.pyindex a0d61a3b07e..8b3b2f9ea8d 100644--- a/hermes_cli/left_core_migration.py+++ b/hermes_cli/left_core_migration.py@@ -191,14 +191,6 @@ def agent_imports_in_use(home: Path, *, process_env: bool = False) -> bool:-# The values core's DEFAULT_CONFIG carried under browser.camofox. save_config materialised schema-# defaults into config.yaml before it learned to strip them, so a mapping holding only these is a-# copied template, not a Camofox setup.-_CAMOFOX_CORE_DEFAULTS = {"managed_persistence": False, "user_id": "", "session_key": "",- "adopt_existing_tab": False, "rewrite_loopback_urls": False,- "loopback_host_alias": "host.docker.internal"}--def _home_env(home: Path, name: str, *, process_env: bool) -> str:"""*name* as *home*'s dotenv layers resolve it (:func:`~hermes_cli.env_loader.resolve_home_dotenv`),else, with *process_env* and for the launch home only, the process environment."""@@ -214,27 +206,24 @@ def _home_env(home: Path, name: str, *, process_env: bool) -> str:def camofox_in_use(home: Path, *, process_env: bool = False) -> bool:"""What made core run its Camofox backend for *home*, read the way core selected it(``tools/browser_camofox.is_camofox_mode``): a CDP endpoint (``browser.cdp_url`` or- ``BROWSER_CDP_URL``) won over Camofox; a stored ``browser.cloud_provider`` decided alone (Camofox- only when it names ``camofox``); with none stored, ``CAMOFOX_URL`` in its dotenv layers (the process- env too for the launch home with *process_env*), or Camofox settings of its own under- ``browser.camofox``. Config is read with the managed overlay applied; read-only."""- from gateway import config_loader- try:- browser = config_loader.read_yaml_layers(home).get("browser")- except Exception: # malformed config.yaml: core read no selection from it either- logger.debug("left-core: unreadable config for %s", home, exc_info=True)- browser = None+ ``BROWSER_CDP_URL``) won over Camofox; a stored selection (``browser.cloud_provider``, or+ ``use_gateway`` = the managed row) decided alone, Camofox only when it names ``camofox``; with+ none stored, ``CAMOFOX_URL`` in its dotenv layers (the process env too for the launch home with+ *process_env*). ``browser.camofox`` settings never selected it: a leftover block without an+ address ran browser_exec. Config is the raw config.yaml, as core read it; read-only."""+ from utils import is_truthy_value+ browser = _read_config(home).get("browser")browser = browser if isinstance(browser, dict) else {}if str(browser.get("cdp_url") or "").strip() or _home_env(home, "BROWSER_CDP_URL", process_env=process_env):return False- selected = str(browser.get("cloud_provider") or "").strip().lower()- if selected or str(browser.get("use_gateway") or "").strip().lower() in ("1", "true", "yes", "on"):+ if is_truthy_value(browser.get("use_gateway")):+ return False+ provider = browser.get("cloud_provider")+ selected = str(provider).strip().lower() if provider is not None else ""+ if selected:return selected == "camofox"- if _home_env(home, "CAMOFOX_URL", process_env=process_env):- return True- settings = browser.get("camofox")- return isinstance(settings, dict) and any(- key not in _CAMOFOX_CORE_DEFAULTS or value != _CAMOFOX_CORE_DEFAULTS[key] for key, value in settings.items())+ return bool(_home_env(home, "CAMOFOX_URL", process_env=process_env))+@dataclass(frozen=True)class LeftCoreFeature:diff --git a/tests/hermes_cli/test_left_core_camofox.py b/tests/hermes_cli/test_left_core_camofox.pyindex f5efa04ffdd..5d53a15256b 100644--- a/tests/hermes_cli/test_left_core_camofox.py+++ b/tests/hermes_cli/test_left_core_camofox.py@@ -74,11 +74,10 @@ def _installer(home: Path, calls: list):@pytest.mark.parametrize(("env", "config", "in_use"), [("CAMOFOX_URL=http://localhost:9377\n", None, True), # A: the address alone selected it("", None, False), # B- ("", {"browser": {"camofox": {"managed_persistence": True}}}, True), # C: Camofox settings of its own("", {"browser": {"cloud_provider": "camofox"}}, True),- # A config core's save_config materialised: the old schema defaults are not a Camofox setup.- ("", {"browser": {"camofox": {"managed_persistence": False, "user_id": "",- "loopback_host_alias": "host.docker.internal"}}}, False),+ # browser.camofox settings never selected Camofox: without an address core ran browser_exec.+ ("", {"browser": {"camofox": {"managed_persistence": True, "user_id": "me"}}}, False),+ ("CAMOFOX_URL=http://localhost:9377\n", {"browser": {"camofox": {"managed_persistence": True}}}, True),# A stored selection decides alone; a CDP endpoint won over Camofox.("CAMOFOX_URL=http://localhost:9377\n", {"browser": {"cloud_provider": "browserbase"}}, False),("CAMOFOX_URL=http://localhost:9377\n", {"browser": {"use_gateway": True}}, False),@@ -89,6 +88,18 @@ def test_camofox_in_use_reads_core_selection(tmp_path, env, config, in_use):assert lcm.camofox_in_use(_home(tmp_path, env=env, config=config)) is in_use+def test_leftover_camofox_settings_keep_browser_exec(tmp_path):+ """A browser.camofox block with no address is not a Camofox home: nothing is installed and core's+ browser toolset stays on (converting it would leave the home with no browser at all)."""+ home = _home(tmp_path, config={+ "browser": {"camofox": {"managed_persistence": True}},+ "platform_toolsets": {"cli": ["terminal", "browser", "file"]},+ })+ before = (home / "config.yaml").read_bytes()+ assert lcm.migrate_home(home, install=lambda name: pytest.fail("not a Camofox home"), say=print) == []+ assert (home / "config.yaml").read_bytes() == before++def test_managed_env_url_counts(tmp_path):(tmp_path / "managed" / ".env").write_text("CAMOFOX_URL=http://camofox:9377\n", encoding="utf-8")assert lcm.camofox_in_use(_home(tmp_path)) is True@@ -164,11 +175,11 @@ def test_conversion_is_never_undone(tmp_path):def test_homes_are_islands_a_b_c_a(tmp_path):- """A (CAMOFOX_URL in .env) and C (browser.camofox only) are migrated; B is never touched."""+ """A (CAMOFOX_URL in .env) and C (cloud_provider: camofox) are migrated; B is never touched."""a = _home(tmp_path, "a", env="CAMOFOX_URL=http://localhost:9377\n",config={"platform_toolsets": {"cli": ["browser"]}})b = _home(tmp_path, "b", config={"platform_toolsets": {"cli": ["browser", "terminal"]}})- c = _home(tmp_path, "c", config={"browser": {"camofox": {"managed_persistence": True}}})+ c = _home(tmp_path, "c", config={"browser": {"cloud_provider": "camofox"}})b_before = (b / "config.yaml").read_bytes()calls: list[tuple[str, str]] = []