The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(left-core): Camofox homes get the camofox catalog plugin; their browser toolset becomes camofox
Teknium15efeaec9044
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.pyindex 6c5254707fc..a0d61a3b07e 100644--- a/hermes_cli/left_core_migration.py+++ b/hermes_cli/left_core_migration.py@@ -190,6 +190,52 @@ def agent_imports_in_use(home: Path, *, process_env: bool = False) -> bool:return (home / "import-sync.json").is_file()++# 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."""+ from hermes_cli.env_loader import resolve_home_dotenv+ value = resolve_home_dotenv(home).get(name, "").strip()+ if not value and process_env:+ from hermes_constants import get_routing_process_hermes_home, hermes_home_key+ if hermes_home_key(home) == hermes_home_key(get_routing_process_hermes_home()):+ value = os.environ.get(name, "").strip()+ return value+++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 = 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"):+ 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())+@dataclass(frozen=True)class LeftCoreFeature:plugin: str # catalog entry name == installed plugin name@@ -209,6 +255,12 @@ class LeftCoreFeature:toolsets: tuple[str, ...] = ()# Platforms whose core default composite (``hermes-<platform>``) never carried those toolsets.off_platforms: tuple[str, ...] = ()+ # Core-era toolsets the plugin's toolsets replace while core keeps the name for something else+ # (core's ``browser`` is browser_exec now; Camofox's tools live in the plugin's ``camofox``). The+ # one-time scope conversion treats them as the plugin's toolsets for "did core carry it" and turns+ # them off in the home: a saved platform list naming one names the plugin's toolsets instead, and+ # ``agent.disabled_toolsets`` takes them for platforms on a default composite.+ replaces_toolsets: tuple[str, ...] = ()# Gateway platform the plugin ships: a running gateway serves it only after a restart.platform: str = ""# Channel ownership core declared for that platform, kept while the plugin is absent (migration@@ -265,6 +317,17 @@ LEFT_CORE: tuple[LeftCoreFeature, ...] = (unchanged="the conversation tools keep their names; MCP clients change their args to [\"mcp-serve\"]",command="mcp-serve", old_command="hermes mcp serve",),+ LeftCoreFeature(+ # CAMOFOX_URL is an address, not a credential: core kept it out of children only through its+ # `category: tool` OPTIONAL_ENV_VARS entry (the Tier 2 provider blocklist), as HASS_URL. The+ # bearer token is a credential.+ plugin="camofox", label="Camofox browser backend", in_use=camofox_in_use,+ unchanged="CAMOFOX_URL, the browser.camofox settings and the browser_navigate/browser_click/... tool "+ "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",),+ ),LeftCoreFeature(plugin="singularity", label="Singularity/Apptainer terminal backend", in_use=singularity_in_use,unchanged="terminal.backend: singularity, terminal.singularity_image (TERMINAL_SINGULARITY_IMAGE) "@@ -364,7 +427,7 @@ def _core_carried(feature: LeftCoreFeature, selection: list) -> bool:"""Whether core resolved *feature*'s toolsets on for a platform selecting *selection*: nameddirectly, or through a ``hermes`` / ``hermes-<platform>`` composite that included them."""def carries(name: str) -> bool:- if name in feature.toolsets or name == "hermes":+ if name in feature.toolsets or name in feature.replaces_toolsets or name == "hermes":return Truereturn name.startswith("hermes-") and name[len("hermes-"):].replace("-", "_") not in feature.off_platformsreturn any(carries(str(name)) for name in selection)@@ -390,13 +453,33 @@ def _mark(config: dict, key: str, feature: LeftCoreFeature) -> None:config[key] = sorted({*(map(str, done) if isinstance(done, list) else ()), feature.plugin})+def _turn_off_replaced(config: dict, feature: LeftCoreFeature) -> None:+ """Turn *feature*'s ``replaces_toolsets`` off in *config*: every saved platform list naming one names+ the plugin's toolsets instead (so turning core's toolset back on later stays that platform's choice),+ and ``agent.disabled_toolsets`` takes them, which also covers platforms on a default composite."""+ from agent.skill_utils import parse_config_string_list+ from hermes_cli.toolset_validation import parse_platform_toolsets_value+ replaced = set(feature.replaces_toolsets)+ saved = config.get("platform_toolsets")+ for platform, value in (saved.items() if isinstance(saved, dict) else ()):+ selection = parse_platform_toolsets_value(value)+ if selection is not None and replaced & set(map(str, selection)):+ kept = [item for item in selection if str(item) not in replaced]+ saved[platform] = kept + [ts for ts in feature.toolsets if ts not in map(str, kept)]+ agent = config.get("agent") if isinstance(config.get("agent"), dict) else {}+ disabled = parse_config_string_list(agent.get("disabled_toolsets")) if agent.get("disabled_toolsets") else []+ agent["disabled_toolsets"] = [*disabled, *sorted(replaced - set(disabled))]+ config["agent"] = agent++def _record_migration(home: Path, feature: LeftCoreFeature) -> None:"""Keep *feature*'s core-era toolset scope, and mark it installed once its plugin is in *home*,in one config write.Scope: record the toolsets in ``known_plugin_toolsets[platform]`` (= off) for every platformwhere core had them off: a saved ``platform_toolsets`` list that does not carry them, or no list- on an ``off_platforms`` platform. Platforms core resolved them on for are left alone. A one-time+ on an ``off_platforms`` platform. Platforms core resolved them on for are left alone, except that+ a row's ``replaces_toolsets`` go off everywhere (:func:`_turn_off_replaced`). A one-timeconversion per home and row, independent of installation: a plugin installed before the update(it stays inert on a core that still ships the feature) still needs it. Completion is markedunder ``_left_core_scoped`` so a later run never undoes a choice the user made since@@ -428,6 +511,8 @@ def _record_migration(home: Path, feature: LeftCoreFeature) -> None:known[platform] = sorted({*map(str, current), *missing})if known:config["known_plugin_toolsets"] = known+ if feature.replaces_toolsets:+ _turn_off_replaced(config, feature)_mark(config, _SCOPED_KEY, feature)atomic_config_write(path, config)diff --git a/tests/hermes_cli/test_left_core_camofox.py b/tests/hermes_cli/test_left_core_camofox.pynew file mode 100644index 00000000000..f5efa04ffdd--- /dev/null+++ b/tests/hermes_cli/test_left_core_camofox.py@@ -0,0 +1,206 @@+"""Camofox left core for the ``camofox`` catalog plugin: a home that ran core's Camofox backend gets the+plugin once, and its core-era ``browser`` toolset (Camofox's browser_* tools then; browser_exec now) becomes+the plugin's ``camofox`` toolset, a one-time conversion a later run never undoes.++Real config/.env files under temp homes, a fixture catalog dir; the network install is a stand-in.+"""++from __future__ import annotations++from pathlib import Path++import pytest++import hermes_cli.left_core_migration as lcm+import hermes_yaml as yaml++_CATALOG_ENTRY = """\+name: camofox+repo: https://github.com/NousResearch/hermes-official-plugins+sha: 0123456789abcdef0123456789abcdef01234567+subdir: camofox+description: Camofox anti-detection browser backend (fixture).+maintainer: NousResearch+tier: official+category: tools+capabilities:+ provides_tools: [browser_navigate]+ provides_hooks: []+ provides_middleware: []+ requires_env: []+"""++[email protected](autouse=True)+def _fresh(monkeypatch, tmp_path):+ monkeypatch.setattr(lcm, "_attempted", set())+ monkeypatch.setattr(lcm, "_undelivered", {})+ for name in ("CAMOFOX_URL", "BROWSER_CDP_URL"):+ monkeypatch.delenv(name, raising=False)+ managed = tmp_path / "managed"+ managed.mkdir()+ monkeypatch.setenv("HERMES_MANAGED_DIR", str(managed))+ from hermes_cli import plugin_catalog+ catalog = tmp_path / "catalog"+ catalog.mkdir()+ (catalog / "camofox.yaml").write_text(_CATALOG_ENTRY, encoding="utf-8")+ monkeypatch.setattr(plugin_catalog, "get_catalog_dir", lambda: catalog)+ monkeypatch.setattr(plugin_catalog, "fetch_live_catalog", lambda **_: None)+ return catalog+++def _home(tmp_path: Path, name: str = "home", *, env: str = "", config: dict | None = None) -> Path:+ home = tmp_path / name+ home.mkdir(parents=True)+ if env:+ (home / ".env").write_text(env, encoding="utf-8")+ if config is not None:+ (home / "config.yaml").write_text(yaml.safe_dump(config), encoding="utf-8")+ return home+++def _config(home: Path) -> dict:+ return yaml.safe_load((home / "config.yaml").read_text(encoding="utf-8")) or {}+++def _installer(home: Path, calls: list):+ def install(name):+ calls.append(name)+ (home / "plugins" / name).mkdir(parents=True)+ return {"ok": True}+ return install++[email protected](("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),+ # 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),+ ("CAMOFOX_URL=http://localhost:9377\n", {"browser": {"cdp_url": "ws://127.0.0.1:9222"}}, False),+ ("CAMOFOX_URL=http://localhost:9377\nBROWSER_CDP_URL=ws://127.0.0.1:9222\n", None, False),+])+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_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+++def test_process_env_url_counts_only_for_the_launch_home(tmp_path, monkeypatch):+ launch = _home(tmp_path, "launch")+ secondary = _home(tmp_path, "profiles/work")+ monkeypatch.setenv("HERMES_HOME", str(launch))+ monkeypatch.setenv("CAMOFOX_URL", "http://localhost:9377")+ assert lcm.camofox_in_use(launch) is False+ assert lcm.camofox_in_use(launch, process_env=True) is True+ assert lcm.camofox_in_use(secondary, process_env=True) is False+++def _resolved(home: Path, platform: str, monkeypatch) -> set[str]:+ from hermes_cli import tools_config+ monkeypatch.setattr(tools_config, "_get_plugin_toolset_keys", lambda: {"camofox"})+ return tools_config._get_platform_tools(_config(home), platform, include_default_mcp_servers=False)+++def test_browser_becomes_camofox_where_core_carried_it(tmp_path, monkeypatch):+ home = _home(tmp_path, env="CAMOFOX_URL=http://localhost:9377\n", config={+ "platform_toolsets": {+ "cli": ["terminal", "browser", "file"], # browser named directly+ "telegram": ["hermes-telegram"], # through the composite+ "discord": ["terminal", "file"], # core had browser off here+ },+ "agent": {"disabled_toolsets": ["memory"]},+ })+ calls, said = [], []+ install = _installer(home, calls)+ assert lcm.migrate_home(home, install=install, say=said.append) == ["camofox"]+ assert calls == ["camofox"]+ assert "Camofox browser backend moved out of core" in said[0]++ config = _config(home)+ assert config["platform_toolsets"]["cli"] == ["terminal", "file", "camofox"]+ assert config["agent"]["disabled_toolsets"] == ["memory", "browser"]+ known = config["known_plugin_toolsets"]+ assert "camofox" in known["discord"] and "camofox" in known["webhook"]+ assert "cli" not in known and "telegram" not in known+ # The end state per platform: the camofox surface where core had browser on, never browser_exec.+ for platform in ("cli", "telegram", "slack"): # slack: no saved list, default composite+ enabled = _resolved(home, platform, monkeypatch)+ assert "camofox" in enabled and "browser" not in enabled, platform+ for platform in ("discord", "webhook"):+ enabled = _resolved(home, platform, monkeypatch)+ assert "camofox" not in enabled and "browser" not in enabled, platform+++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"]}})+ 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"]+ # The user turns core's browser (browser_exec) back on for the CLI afterwards.+ config["platform_toolsets"]["cli"] = ["terminal", "camofox", "browser"]+ config["agent"]["disabled_toolsets"] = []+ (home / "config.yaml").write_text(yaml.safe_dump(config), encoding="utf-8")+ before = (home / "config.yaml").read_bytes()+ calls = []+ install = _installer(home, calls)+ lcm.migrate_home(home, install=install, say=lambda _m: None)+ after = _config(home)+ assert after["platform_toolsets"]["cli"] == ["terminal", "camofox", "browser"]+ assert after["agent"]["disabled_toolsets"] == []+ assert calls == ["camofox"]+ lcm.migrate_home(home, install=install, say=lambda _m: None)+ assert calls == ["camofox"]+ assert {k: v for k, v in _config(home).items() if k != "_left_core_installed"} == yaml.safe_load(before)+++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 = _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}}})+ b_before = (b / "config.yaml").read_bytes()+ calls: list[tuple[str, str]] = []++ def run(home):+ def install(name):+ calls.append((home.name, name))+ (home / "plugins" / name).mkdir(parents=True)+ return {"ok": True}+ return lcm.migrate_home(home, install=install, say=lambda _m: None)++ assert run(a) == ["camofox"]+ assert run(b) == []+ assert run(c) == ["camofox"]+ assert run(a) == []+ assert calls == [("a", "camofox"), ("c", "camofox")]+ assert (b / "config.yaml").read_bytes() == b_before+ assert not (b / "plugins").exists()+ assert _config(a)["platform_toolsets"]["cli"] == ["camofox"]+ assert _config(c)["agent"]["disabled_toolsets"] == ["browser"]+++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")+ 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]+ assert "hermes plugins install camofox" in said[0]+++def test_camofox_env_stays_out_of_children():+ """With the plugin absent no manifest declares CAMOFOX_*: core keeps stripping them."""+ from tools.environments import local_env_policy as policy+ assert "CAMOFOX_URL" in policy._build_provider_env_blocklist()+ assert "CAMOFOX_API_KEY" in policy._ALWAYS_STRIP_KEYS