Skip to content

The agent that grows with you

fix(browser): Camofox left-core row converts only homes from before the split

Teknium7de2e8b0e2f8
diff --git a/hermes_cli/config_migrations.py b/hermes_cli/config_migrations.py
index 8ed9bd382f6..9415b6cd6b4 100644
--- a/hermes_cli/config_migrations.py
+++ b/hermes_cli/config_migrations.py
@@ -763,9 +763,12 @@ def _migrate_to_52(results: dict[str, Any], quiet: bool) -> None:
# 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.
+ # a value already set. .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
+ from hermes_cli.left_core_migration import record_core_use
from hermes_constants import get_hermes_home
config = read_raw_config()
@@ -793,9 +796,11 @@ def _migrate_to_52(results: dict[str, Any], quiet: bool) -> None:
if moved:
added.append(f"browser: {', '.join(moved)}")
messages.append(f" ✓ Moved agent-browser settings from .env to config.yaml: {', '.join(moved)}")
- if not added:
+ used = record_core_use(Path(get_hermes_home()), config, 52)
+ if not added and not used:
return
- config["browser"] = browser
+ if added:
+ config["browser"] = browser
_persist_migration(config)
results["config_added"].extend(added)
if not quiet:
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.py
index 8b3b2f9ea8d..09ccdfd250a 100644
--- a/hermes_cli/left_core_migration.py
+++ b/hermes_cli/left_core_migration.py
@@ -275,6 +275,11 @@ class LeftCoreFeature:
plugin_key: str = ""
# ``terminal.backend`` value the plugin registers: unknown-backend errors name the install command.
terminal_backend: str = ""
+ # Config schema version that shipped without the feature, for a row whose conversion changes what a
+ # home runs (``replaces_toolsets``): only a home from before it ran the core feature, so the row fires
+ # only while the home's config is below it or when that version's config step found the feature in
+ # use (:func:`record_core_use`). A newer home that sets the plugin up itself keeps core's toolsets.
+ left_at: int = 0
LEFT_CORE: tuple[LeftCoreFeature, ...] = (
@@ -315,7 +320,7 @@ LEFT_CORE: tuple[LeftCoreFeature, ...] = (
"names are unchanged; they are the `camofox` toolset now, and core's `browser` toolset "
"(browser_exec) is turned off in this profile",
secret_env=("CAMOFOX_API_KEY",), private_env=("CAMOFOX_URL",),
- toolsets=("camofox",), off_platforms=("webhook",), replaces_toolsets=("browser",),
+ toolsets=("camofox",), off_platforms=("webhook",), replaces_toolsets=("browser",), left_at=52,
),
LeftCoreFeature(
plugin="singularity", label="Singularity/Apptainer terminal backend", in_use=singularity_in_use,
@@ -428,6 +433,36 @@ _SCOPED_KEY = "_left_core_scoped" # config.yaml: rows whose toolset scope this
_INSTALLED_KEY = "_left_core_installed"
+# config.yaml: rows whose ``left_at`` config step found the core feature in use in this home.
+_USED_KEY = "_left_core_used"
+
+
+def record_core_use(home: Path, config: dict, version: int) -> bool:
+ """Config step *version* hook, before it writes *config* (*home*'s raw config.yaml, still showing the
+ core-era setup): mark every row that left core at *version* and that *home* uses. Returns whether
+ *config* changed. The launch home's process env counts, as at agent start."""
+ used = [feature for feature in LEFT_CORE if feature.left_at == version
+ and not _marked(config, _USED_KEY, feature) and feature.in_use(home, process_env=True)]
+ for feature in used:
+ _mark(config, _USED_KEY, feature)
+ return bool(used)
+
+
+def _predates_split(home: Path, feature: LeftCoreFeature) -> bool:
+ """*home* ran *feature* in core: its config is still below ``left_at`` (this pass ran before the
+ config step), or that step recorded the feature in use. A missing or unstamped config.yaml is
+ neither: the config step stamps (and records) an unstamped one, a missing one is a new home."""
+ if not feature.left_at:
+ return True
+ config = _read_config(home)
+ if _marked(config, _USED_KEY, feature):
+ return True
+ try:
+ return int(config["_config_version"]) < feature.left_at
+ except (KeyError, TypeError, ValueError):
+ return False
+
+
def _marked(config: dict, key: str, feature: LeftCoreFeature) -> bool:
done = config.get(key)
return isinstance(done, list) and feature.plugin in map(str, done)
@@ -518,7 +553,7 @@ def _pending(home: Path, *, say: Callable[[str], None], process_env: bool = Fals
for feature in LEFT_CORE:
if _marked(_read_config(home), _INSTALLED_KEY, feature):
continue
- if not feature.in_use(home, process_env=process_env):
+ if not _predates_split(home, feature) or not feature.in_use(home, process_env=process_env):
continue
present = plugin_present(feature.plugin, home)
try:
diff --git a/tests/hermes_cli/test_left_core_camofox.py b/tests/hermes_cli/test_left_core_camofox.py
index 5d53a15256b..84590bd6ca5 100644
--- a/tests/hermes_cli/test_left_core_camofox.py
+++ b/tests/hermes_cli/test_left_core_camofox.py
@@ -92,6 +92,7 @@ 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={
+ "_config_version": 51,
"browser": {"camofox": {"managed_persistence": True}},
"platform_toolsets": {"cli": ["terminal", "browser", "file"]},
})
@@ -123,6 +124,7 @@ def _resolved(home: Path, platform: str, monkeypatch) -> set[str]:
def test_browser_becomes_camofox_where_core_carried_it(tmp_path, monkeypatch):
home = _home(tmp_path, env="CAMOFOX_URL=http://localhost:9377\n", config={
+ "_config_version": 51,
"platform_toolsets": {
"cli": ["terminal", "browser", "file"], # browser named directly
"telegram": ["hermes-telegram"], # through the composite
@@ -153,7 +155,7 @@ def test_browser_becomes_camofox_where_core_carried_it(tmp_path, monkeypatch):
def test_conversion_is_never_undone(tmp_path):
home = _home(tmp_path, env="CAMOFOX_URL=http://localhost:9377\n",
- config={"platform_toolsets": {"cli": ["terminal", "browser"]}})
+ config={"_config_version": 51, "platform_toolsets": {"cli": ["terminal", "browser"]}})
lcm._record_migration(home, next(f for f in lcm.LEFT_CORE if f.plugin == "camofox"))
config = _config(home)
assert config["_left_core_scoped"] == ["camofox"]
@@ -177,9 +179,9 @@ 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 (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": {"cloud_provider": "camofox"}})
+ config={"_config_version": 51, "platform_toolsets": {"cli": ["browser"]}})
+ b = _home(tmp_path, "b", config={"_config_version": 51, "platform_toolsets": {"cli": ["browser", "terminal"]}})
+ c = _home(tmp_path, "c", config={"_config_version": 51, "browser": {"cloud_provider": "camofox"}})
b_before = (b / "config.yaml").read_bytes()
calls: list[tuple[str, str]] = []
@@ -201,9 +203,51 @@ def test_homes_are_islands_a_b_c_a(tmp_path):
assert _config(c)["agent"]["disabled_toolsets"] == ["browser"]
+def _migrate_config(home: Path) -> None:
+ from hermes_cli.config import migrate_config
+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override
+ token = set_hermes_home_override(home)
+ try:
+ migrate_config(interactive=False, quiet=True)
+ finally:
+ reset_hermes_home_override(token)
+
+
+_SPLIT_ENV = "CAMOFOX_URL=http://localhost:9377\n"
+_SPLIT_TOOLSETS = {"cli": ["terminal", "browser", "file"]}
+
+
+def test_upgrade_converts_after_the_config_step(tmp_path, monkeypatch):
+ """`hermes update` / Desktop migrate config.yaml to v52 before the left-core pass: the v52 step
+ records the core-era Camofox use, so the pass still converts the home."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "launch"))
+ home = _home(tmp_path, env=_SPLIT_ENV, config={"_config_version": 51, "platform_toolsets": _SPLIT_TOOLSETS})
+ _migrate_config(home)
+ assert _config(home)["_config_version"] == 52
+ calls = []
+ assert lcm.migrate_home(home, install=_installer(home, calls), say=lambda _m: None) == ["camofox"]
+ config = _config(home)
+ assert config["platform_toolsets"]["cli"] == ["terminal", "file", "camofox"]
+ assert config["agent"]["disabled_toolsets"] == ["browser"]
+
+
[email protected]("stamp", [51, 52])
+def test_home_from_after_the_split_keeps_browser_exec(tmp_path, monkeypatch, stamp):
+ """A home that crossed v52 without Camofox (or started at v52) and sets up the camofox plugin later
+ runs both side by side: the row never turns browser_exec off for it."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "launch"))
+ home = _home(tmp_path, config={"_config_version": stamp, "platform_toolsets": _SPLIT_TOOLSETS})
+ _migrate_config(home)
+ (home / "plugins" / "camofox").mkdir(parents=True)
+ (home / ".env").write_text(_SPLIT_ENV, encoding="utf-8")
+ before = (home / "config.yaml").read_bytes()
+ assert lcm.migrate_home(home, install=lambda name: pytest.fail("installed by the user"), say=print) == []
+ assert (home / "config.yaml").read_bytes() == before
+
+
def test_catalog_miss_names_the_install_command(tmp_path, _fresh):
(_fresh / "camofox.yaml").unlink()
- home = _home(tmp_path, env="CAMOFOX_URL=http://localhost:9377\n")
+ home = _home(tmp_path, env="CAMOFOX_URL=http://localhost:9377\n", config={"_config_version": 51})
said = []
assert lcm.migrate_home(home, install=lambda name: pytest.fail("no catalog entry"), say=said.append) == []
assert "cannot find in the plugin catalog yet" in said[0]