Skip to content

The agent that grows with you

fix(config): v52 keeps what agent-browser settings resolved to on main

Teknium05dcf42cc58d
diff --git a/hermes_cli/config_migrations.py b/hermes_cli/config_migrations.py
index 9415b6cd6b4..89e0bad8a27 100644
--- a/hermes_cli/config_migrations.py
+++ b/hermes_cli/config_migrations.py
@@ -10,6 +10,7 @@ from __future__ import annotations
import copy
import functools
import logging
+import os
import re
from typing import Any, Callable, Dict, List, Optional, Tuple
from urllib.parse import urlparse
@@ -755,15 +756,30 @@ def _browser_value_from_env(key: str, value: str) -> Any:
return value.lower() if value.lower() in ("auto", "lightpanda", "chrome") else None
if key == "executable_path" and _inside_pm_store(value):
return None
+ if key == "user_data_dir" and not os.path.isabs(os.path.expanduser(value)):
+ # agent-browser inherited Hermes's cwd and resolved a relative profile there; browser.user_data_dir
+ # anchors relative paths at HERMES_HOME, so pin the directory the logins are in now.
+ return os.path.abspath(os.path.expanduser(value))
return value
+def _config_decided(key: str, current: Any) -> bool:
+ """``browser.<key>`` already won over its AGENT_BROWSER_* var, as core resolved them: ``engine: auto``
+ deferred to AGENT_BROWSER_ENGINE and ``headed`` was config OR env, so those defaults (core's `hermes
+ tools` Local Browser row wrote ``engine: auto``; old saves materialised both) do not block the move."""
+ if key == "engine":
+ return str(current or "").strip().lower() not in ("", "auto")
+ if key == "headed":
+ return current is not None and str(current).strip().lower() in ("true", "1", "yes")
+ return current not in (None, "", [])
+
+
def _migrate_to_52(results: dict[str, Any], quiet: bool) -> None:
# 51 -> 52: agent-browser and the built-in browser_* tools left Hermes; browser_exec is the only
# browser. `browser.backend` chose between the two, so it is dropped (an `off`, the opt-out of
# browser_exec, gets a notice saying how to turn browsing off now). The AGENT_BROWSER_* settings
# this home's .env gave agent-browser move to the browser.* keys the launcher reads, never over
- # a value already set. .env itself is left alone. Camofox left core in the same release: a home
+ # a value that already won over them (:func:`_config_decided`). .env itself is left alone. Camofox left core in the same release: a home
# running it is recorded now, from its pre-v52 files, so its left-core row converts it later
# while a newer home that installs the camofox plugin itself keeps browser_exec.
from pathlib import Path
@@ -776,7 +792,8 @@ def _migrate_to_52(results: dict[str, Any], quiet: bool) -> None:
added, messages = [], []
if "backend" in browser:
backend = browser.pop("backend")
- if isinstance(backend, str) and backend.strip().lower() == "off":
+ # YAML 1.1 reads an unquoted `off` as False; core treated that as off too.
+ if backend is False or (isinstance(backend, str) and backend.strip().lower() == "off"):
# config_added is what `hermes update` re-surfaces on its quiet path, so the notice rides in it.
note = ("removed browser.backend: off — the built-in browser tools are gone and browser_exec is the "
"browser now; to turn browsing off, disable the `browser` toolset in `hermes tools`")
@@ -787,7 +804,7 @@ def _migrate_to_52(results: dict[str, Any], quiet: bool) -> None:
moved = []
for name, value in _agent_browser_env(Path(get_hermes_home())).items():
key = dict(_AGENT_BROWSER_ENV_KEYS)[name]
- if browser.get(key) not in (None, "", []):
+ if _config_decided(key, browser.get(key)):
continue
new = _browser_value_from_env(key, value)
if new is not None:
diff --git a/tests/hermes_cli/test_config_migration_52_browser.py b/tests/hermes_cli/test_config_migration_52_browser.py
index 9232d3defc0..4dae49a327b 100644
--- a/tests/hermes_cli/test_config_migration_52_browser.py
+++ b/tests/hermes_cli/test_config_migration_52_browser.py
@@ -1,7 +1,8 @@
"""Config v52: agent-browser and the built-in browser tools left Hermes.
browser.backend is dropped (``off`` gets a one-time notice); AGENT_BROWSER_* from a profile's own
-.env (plus the process env for the launch home only) moves to browser.* keys that are still unset.
+.env (plus the process env for the launch home only) moves to browser.* keys that are unset or hold the
+default core let the env override.
"""
import hermes_yaml as yaml
@@ -102,6 +103,44 @@ def test_dotenv_settings_move_to_unset_keys_only(tmp_path, monkeypatch):
assert (home / ".env").read_text(encoding="utf-8") == env
+def test_env_wins_over_the_defaults_core_wrote(tmp_path, monkeypatch):
+ """Core resolved ``engine: auto`` to AGENT_BROWSER_ENGINE and ``headed`` as config OR env, and its
+ `hermes tools` Local Browser row wrote ``engine: auto``: those values do not block the move. A
+ non-default engine won on core and stays."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "launch"))
+ env = "AGENT_BROWSER_ENGINE=lightpanda\nAGENT_BROWSER_HEADED=true\n"
+ defaults = _home(tmp_path / "a", {"_config_version": 51, "browser": {"engine": "auto", "headed": False}}, env)
+ chosen = _home(tmp_path / "b", {"_config_version": 51, "browser": {"engine": "chrome", "headed": "false"}}, env)
+ _migrate(defaults, quiet=True)
+ _migrate(chosen, quiet=True)
+ assert _raw(defaults)["browser"] == {"engine": "lightpanda", "headed": True}
+ assert _raw(chosen)["browser"] == {"engine": "chrome", "headed": True}
+
+
+def test_unquoted_backend_off_gets_the_notice(tmp_path, monkeypatch, capsys):
+ """YAML 1.1 reads an unquoted ``backend: off`` as False; core treated it as off."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "launch"))
+ home = tmp_path / "a"
+ home.mkdir()
+ (home / "config.yaml").write_text("_config_version: 51\nbrowser:\n backend: off\n", encoding="utf-8")
+ results = _migrate(home)
+ assert "backend" not in (_raw(home).get("browser") or {})
+ assert "browser_exec is the browser now" in capsys.readouterr().out
+ assert any("browser.backend: off" in note for note in results["config_added"])
+
+
+def test_relative_profile_keeps_the_directory_core_used(tmp_path, monkeypatch):
+ """agent-browser resolved a relative AGENT_BROWSER_PROFILE against Hermes's cwd; browser.user_data_dir
+ anchors relative paths at HERMES_HOME, so the migration pins the absolute directory."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "launch"))
+ cwd = tmp_path / "work"
+ cwd.mkdir()
+ monkeypatch.chdir(cwd)
+ home = _home(tmp_path / "a", {"_config_version": 51}, "AGENT_BROWSER_PROFILE=prof/rel\n")
+ _migrate(home, quiet=True)
+ assert _raw(home)["browser"]["user_data_dir"] == str(cwd / "prof" / "rel")
+
+
def test_falsy_headed_and_unknown_engine_carry_nothing(tmp_path, monkeypatch):
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "launch"))
home = _home(tmp_path / "a", {"_config_version": 51},