The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: a removed Home Assistant plugin stays removed after update and restart
teknium1e641b719130f
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.pyindex 4f51738f808..bda2cb2812a 100644--- a/hermes_cli/left_core_migration.py+++ b/hermes_cli/left_core_migration.py@@ -9,6 +9,8 @@ reuses; memory is not a row because its plugin name comes from ``memory.provider* ``hermes update`` installs the plugin for every profile home sharing the venv that uses the feature.* Agent start and gateway start retry once per process for the active home (Desktop users updatethrough the app and never run ``hermes update``), honouring ``security.allow_lazy_installs``.+* A home gets the plugin automatically at most once (``_left_core_installed`` in its config.yaml):+ ``hermes plugins remove`` afterwards is the user's choice and sticks.Installs go through the normal catalog install path at the reviewed pin (kill list, dependencyconstraints, enable). Unattended dependency consent covers only these rows: the feature shipped in@@ -105,7 +107,7 @@ class LeftCoreFeature:private_env: tuple[str, ...] = ()# Toolsets the plugin registers. Core resolved them like any built-in toolset (on only where the# platform's saved list or default composite carried them); a plugin toolset is on for every- # platform whose known_plugin_toolsets does not name it, so :func:`_keep_toolset_scope` records+ # platform whose known_plugin_toolsets does not name it, so :func:`_record_migration` records# them there wherever core had them off.toolsets: tuple[str, ...] = ()# Platforms whose core default composite (``hermes-<platform>``) never carried those toolsets.@@ -150,65 +152,82 @@ def _core_carried(feature: LeftCoreFeature, selection: list) -> bool:_SCOPED_KEY = "_left_core_scoped" # config.yaml: rows whose toolset scope this home already converted+# config.yaml: rows this home has had installed (by the migration, or by the user before it ran).+# Never written before the plugin dir exists, so a home whose install never succeeded keeps retrying.+_INSTALLED_KEY = "_left_core_installed"+++def _marked(config: dict, key: str, feature: LeftCoreFeature) -> bool:+ done = config.get(key)+ return isinstance(done, list) and feature.plugin in map(str, done)def _scope_kept(config: dict, feature: LeftCoreFeature) -> bool:- done = config.get(_SCOPED_KEY)- return not feature.toolsets or (isinstance(done, list) and feature.plugin in map(str, done))+ return not feature.toolsets or _marked(config, _SCOPED_KEY, feature)-def _keep_toolset_scope(home: Path, feature: LeftCoreFeature) -> None:- """Record *feature*'s toolsets in ``known_plugin_toolsets[platform]`` (= off) for every platform- where 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.+def _mark(config: dict, key: str, feature: LeftCoreFeature) -> None:+ done = config.get(key)+ config[key] = sorted({*(map(str, done) if isinstance(done, list) else ()), feature.plugin})+++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.- A one-time conversion 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- marked under ``_left_core_scoped`` in the same config write, so a later run never undoes a choice- the user made since (``hermes tools``). Raises when config.yaml cannot be read or written."""+ Scope: record the toolsets in ``known_plugin_toolsets[platform]`` (= off) for every platform+ where 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+ conversion 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 marked+ under ``_left_core_scoped`` so a later run never undoes a choice the user made since+ (``hermes tools``). Raises when config.yaml cannot be read or written."""from hermes_cli.config import atomic_config_write, read_user_config_rawfrom hermes_cli.toolset_validation import parse_platform_toolsets_valuepath = home / "config.yaml"config = read_user_config_raw(path)- if _scope_kept(config, feature):+ installed = plugin_present(feature.plugin, home) and not _marked(config, _INSTALLED_KEY, feature)+ if _scope_kept(config, feature) and not installed:return- saved = config.get("platform_toolsets")- saved = saved if isinstance(saved, dict) else {}- selections = {str(p): parse_platform_toolsets_value(v) for p, v in saved.items()}- for platform in feature.off_platforms:- selections.setdefault(platform, None)- known = config.get("known_plugin_toolsets")- known = known if isinstance(known, dict) else {}- for platform, selection in selections.items():- if selection is None and platform not in feature.off_platforms:- continue # no (valid) saved list: core's default composite carried the toolsets- if selection is not None and _core_carried(feature, selection):- continue- current = known.get(platform) if isinstance(known.get(platform), list) else []- if missing := [ts for ts in feature.toolsets if ts not in current]:- known[platform] = sorted({*map(str, current), *missing})- if known:- config["known_plugin_toolsets"] = known- done = config.get(_SCOPED_KEY)- config[_SCOPED_KEY] = sorted({*(map(str, done) if isinstance(done, list) else ()), feature.plugin})+ if installed:+ _mark(config, _INSTALLED_KEY, feature)+ if not _scope_kept(config, feature):+ saved = config.get("platform_toolsets")+ saved = saved if isinstance(saved, dict) else {}+ selections = {str(p): parse_platform_toolsets_value(v) for p, v in saved.items()}+ for platform in feature.off_platforms:+ selections.setdefault(platform, None)+ known = config.get("known_plugin_toolsets")+ known = known if isinstance(known, dict) else {}+ for platform, selection in selections.items():+ if selection is None and platform not in feature.off_platforms:+ continue # no (valid) saved list: core's default composite carried the toolsets+ if selection is not None and _core_carried(feature, selection):+ continue+ current = known.get(platform) if isinstance(known.get(platform), list) else []+ if missing := [ts for ts in feature.toolsets if ts not in current]:+ known[platform] = sorted({*map(str, current), *missing})+ if known:+ config["known_plugin_toolsets"] = known+ _mark(config, _SCOPED_KEY, feature)atomic_config_write(path, config)def _pending(home: Path, *, say: Callable[[str], None], process_env: bool = False) -> list[LeftCoreFeature]:- """Rows *home* uses whose plugin is not installed and that the catalog ships (a catalog miss is+ """Rows *home* uses whose plugin it never had and that the catalog ships (a catalog miss isreported through *say*). Converts the toolset scope of every row *home* uses once- (:func:`_keep_toolset_scope`), installed or not; a row whose scope cannot be recorded is- reported and skipped, never installed unscoped."""+ (:func:`_record_migration`), installed or not; a row whose scope cannot be recorded is+ reported and skipped, never installed unscoped. A row marked installed is done for good."""from hermes_cli.memory_provider_migration import catalog_sourceout = []for feature in LEFT_CORE:- present = plugin_present(feature.plugin, home)- if present and _scope_kept(_read_config(home), feature):+ if _marked(_read_config(home), _INSTALLED_KEY, feature):continueif not feature.in_use(home, process_env=process_env):continue+ present = plugin_present(feature.plugin, home)try:- _keep_toolset_scope(home, feature)+ _record_migration(home, feature)except Exception as exc:say(f" ⚠ {feature.label} moved out of core into the '{feature.plugin}' plugin: its per-platform "f"toolset selection could not be kept ({exc}). Check `hermes tools`"@@ -245,6 +264,10 @@ def _install_one(home: Path, feature: LeftCoreFeature, *, install: Callable[[strexcept Exception as exc: # network, uv, kill list — report, do not raiseresult = {"ok": False, "error": str(exc)}if result.get("ok"):+ try:+ _record_migration(home, feature)+ except Exception as exc: # the next run sees the plugin dir and records it then+ logger.debug("left-core install marker not written for %s: %s", home, exc)say(f" ✓ {feature.label} moved out of core — installed the '{feature.plugin}' plugin from the "f"catalog ({feature.unchanged}).")return Truediff --git a/plugins/AGENTS.md b/plugins/AGENTS.mdindex 5e0bfb1302a..97e7437812a 100644--- a/plugins/AGENTS.md+++ b/plugins/AGENTS.md@@ -31,6 +31,8 @@ command. A hook with no concrete consumer is speculative infrastructure and is rpredicate); `hermes update` and agent/gateway start install the plugin for homes that used it.Installing and converting core-era state are separate steps: the toolset-scope conversion runsonce per home and row (`_left_core_scoped` in config.yaml) even when the plugin is already there.+ The automatic install also happens once per home and row (`_left_core_installed`, written only+ once the plugin dir exists): a later `hermes plugins remove` sticks, a failed install retries.Core special cases become `PlatformEntry` seams the plugin sets (`trusted_inbound`,`display_tier`, `shared_env_prefixes`), never a name check.- **No new third-party-product plugins (June 2026).** Observability/metrics backends, vendor SaaSdiff --git a/tests/hermes_cli/test_left_core_migration.py b/tests/hermes_cli/test_left_core_migration.pyindex e6552912b58..c7f865c8961 100644--- a/tests/hermes_cli/test_left_core_migration.py+++ b/tests/hermes_cli/test_left_core_migration.py@@ -220,3 +220,34 @@ def test_gateway_start_outcome_waits_for_the_first_agent(tmp_path, monkeypatch):assert len(said) == 1 and said[0].startswith("✓ Home Assistant moved out of core")assert lcm.recover_at_startup(say=said.append) == [] and len(said) == 1+++def test_the_migration_installs_once_so_a_removal_sticks(tmp_path, monkeypatch):+ """At most one automatic install per home: after `hermes plugins remove`, neither `hermes update`+ nor startup reinstalls it. Until an install succeeds (catalog miss, failed install) it retries."""+ import hermes_cli.memory_provider_migration as mpm+ import pm.install+ home = _home(tmp_path, env="HASS_TOKEN=abc\n")+ plugin = home / "plugins" / "homeassistant"+ calls = []++ def install(name):+ calls.append(name)+ plugin.mkdir(parents=True)+ return {"ok": True}++ quiet = lambda message: None # noqa: E731+ monkeypatch.setattr(mpm, "catalog_source", lambda name: None)+ assert lcm.migrate_home(home, install=install, say=quiet) == []+ monkeypatch.setattr(mpm, "catalog_source", lambda name: name)+ assert lcm.migrate_home(home, install=lambda n: {"ok": False, "error": "network down"}, say=quiet) == []+ assert lcm.migrate_home(home, install=install, say=quiet) == ["homeassistant"]++ import shutil+ shutil.rmtree(plugin) # `hermes plugins remove homeassistant`+ assert lcm.migrate_home(home, install=install, say=quiet) == []+ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setattr(pm.install, "lazy_installs_allowed", lambda: True)+ monkeypatch.setattr(lcm, "_install_into", lambda h: install)+ assert lcm.recover_at_startup(say=quiet) == []+ assert calls == ["homeassistant"] and not plugin.exists()diff --git a/website/docs/user-guide/messaging/homeassistant.md b/website/docs/user-guide/messaging/homeassistant.mdindex 6eda6f8d770..eb3f68ab165 100644--- a/website/docs/user-guide/messaging/homeassistant.md+++ b/website/docs/user-guide/messaging/homeassistant.md@@ -27,7 +27,7 @@ hermes -p <profile> plugins install homeassistantThe plugin declares its own Python dependency (`aiohttp`), so there is no pip extra to install. The old `hermes-agent[homeassistant]` extra has been removed.:::info Upgrading from a release that bundled Home Assistant-Nothing to do. Every profile that was already using Home Assistant — `HASS_TOKEN` in its `.env`, `platforms.homeassistant` enabled (or given a `token`) in `config.yaml`, or the `homeassistant` toolset listed in `platform_toolsets` — gets the plugin installed automatically from the catalog by `hermes update` (for all profiles sharing the install). If that step could not run, Hermes installs it the first time the profile starts (agent or gateway start; this honours `security.allow_lazy_installs`). The outcome is reported in the terminal, the Desktop app and chat.+Nothing to do. Every profile that was already using Home Assistant — `HASS_TOKEN` in its `.env`, `platforms.homeassistant` enabled (or given a `token`) in `config.yaml`, or the `homeassistant` toolset listed in `platform_toolsets` — gets the plugin installed automatically from the catalog by `hermes update` (for all profiles sharing the install). If that step could not run, Hermes installs it the first time the profile starts (agent or gateway start; this honours `security.allow_lazy_installs`). The outcome is reported in the terminal, the Desktop app and chat. This happens once per profile: if you later remove the plugin (`hermes plugins remove homeassistant`), it stays removed.Your configuration carries over unchanged: the same `HASS_TOKEN` / `HASS_URL` variables, the same `homeassistant` platform name and `platforms.homeassistant` keys, the same `homeassistant` toolset and tool names, and the same cron `deliver: homeassistant:<notify target>` syntax. One difference: like every plugin tool, the `ha_*` tools sit behind [Tool Search](../features/tools.md) (`tool_search` / `tool_call`) when it is on, instead of being listed directly.:::diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/messaging/homeassistant.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/messaging/homeassistant.mdindex 44c22d94668..cce9db4a91f 100644--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/messaging/homeassistant.md+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/messaging/homeassistant.md@@ -27,7 +27,7 @@ hermes -p <profile> plugins install homeassistant插件自行声明其 Python 依赖(`aiohttp`),因此无需安装 pip extra。旧的 `hermes-agent[homeassistant]` extra 已被移除。:::info 从内置 Home Assistant 的版本升级-无需任何操作。每个已在使用 Home Assistant 的 profile(`.env` 中有 `HASS_TOKEN`、`config.yaml` 中启用了 `platforms.homeassistant`(或为其设置了 `token`),或 `platform_toolsets` 中列出了 `homeassistant` 工具集)都会在 `hermes update` 时自动从插件目录安装该插件(覆盖共享同一安装的所有 profile)。若该步骤未能执行,Hermes 会在该 profile 首次启动时(agent 启动或 gateway 启动)安装插件,此行为遵循 `security.allow_lazy_installs`。安装结果会显示在终端、Desktop 应用和聊天中。+无需任何操作。每个已在使用 Home Assistant 的 profile(`.env` 中有 `HASS_TOKEN`、`config.yaml` 中启用了 `platforms.homeassistant`(或为其设置了 `token`),或 `platform_toolsets` 中列出了 `homeassistant` 工具集)都会在 `hermes update` 时自动从插件目录安装该插件(覆盖共享同一安装的所有 profile)。若该步骤未能执行,Hermes 会在该 profile 首次启动时(agent 启动或 gateway 启动)安装插件,此行为遵循 `security.allow_lazy_installs`。安装结果会显示在终端、Desktop 应用和聊天中。每个 profile 只会自动安装一次:之后若你移除插件(`hermes plugins remove homeassistant`),它将保持移除状态。您的配置保持不变:相同的 `HASS_TOKEN` / `HASS_URL` 变量、相同的 `homeassistant` 平台名称和 `platforms.homeassistant` 配置键、相同的 `homeassistant` 工具集和工具名称,以及相同的 cron `deliver: homeassistant:<notify target>` 语法。唯一的区别:与所有插件工具一样,启用 [Tool Search](../features/tools.md) 时,`ha_*` 工具通过 `tool_search` / `tool_call` 调用,而不是直接列出。:::