The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: a scheduled hermes import-agent --sync installs the plugin on a home nothing migrated
Teknium0736f4e98ef2
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.pyindex 9ab1147b618..5b31ffdbafe 100644--- a/hermes_cli/left_core_migration.py+++ b/hermes_cli/left_core_migration.py@@ -28,6 +28,7 @@ from __future__ import annotationsimport loggingimport os+import sysfrom dataclasses import dataclassfrom pathlib import Pathfrom typing import Callable, Optional@@ -636,3 +637,16 @@ def recover_at_startup(*, say: Optional[Callable[[str], None]] = None) -> list[sexcept Exception as exc: # never take agent/gateway start downlogger.warning("left-core plugin migration failed: %s", exc, exc_info=True)return []+++def recover_for_command(name: Optional[str]) -> None:+ """``hermes <name>`` names a command a left-core plugin registers, and the active home uses that+ feature but lacks the plugin: run :func:`recover_at_startup` now, before plugin commands are+ discovered, so the command it installs runs in this same invocation. A home nothing migrated yet+ (a Docker image swap runs no ``hermes update``) whose only Hermes process is a scheduled+ ``hermes import-agent --sync`` never starts an agent or a gateway to do it."""+ from hermes_constants import get_hermes_home+ home = Path(get_hermes_home())+ if any(name and name in (f.cli, f.command, *f.old_cli) and not plugin_present(f.plugin, home)+ and f.in_use(home) for f in LEFT_CORE):+ recover_at_startup(say=lambda message: print(message, file=sys.stderr))diff --git a/hermes_cli/main.py b/hermes_cli/main.pyindex baaea1738b7..f682f57e94b 100644--- a/hermes_cli/main.py+++ b/hermes_cli/main.py@@ -3259,7 +3259,9 @@ def _register_plugin_cli_commands(subparsers) -> None:try:from plugins.memory import discover_plugin_cli_commandsfrom hermes_cli.plugins import discover_plugins, get_plugin_manager+ from hermes_cli.left_core_migration import recover_for_command+ recover_for_command(_first_positional_argv())seen_plugin_commands = set()for cmd_info in discover_plugin_cli_commands():_attach_plugin_cli_command(subparsers, cmd_info)diff --git a/tests/hermes_cli/test_agent_import_left_core.py b/tests/hermes_cli/test_agent_import_left_core.pyindex a9bef2701a1..27a8789bb21 100644--- a/tests/hermes_cli/test_agent_import_left_core.py+++ b/tests/hermes_cli/test_agent_import_left_core.py@@ -59,3 +59,41 @@ def test_only_a_home_with_registered_imports_gets_the_plugin(tmp_path):assert lcm.migrate_home(synced, install=install, say=said.append) == ["agent-importers"]assert calls == ["agent-importers"]assert "✓ `hermes import-agent` moved out of core" in said[0]+++def test_a_scheduled_sync_on_a_home_nothing_migrated_installs_the_plugin_and_runs(tmp_path, monkeypatch, capsys):+ """An upgrade that ran no `hermes update` (a Docker image swap) leaves a home with sync sources and+ no plugin; when the scheduled `hermes import-agent --sync` is its only Hermes process, that run+ installs the plugin and parses as the plugin's own command."""+ home = tmp_path / ".hermes"+ home.mkdir()+ (home / "config.yaml").write_text("model: test\n", encoding="utf-8")+ (home / "import-sync.json").write_text('{"version": 1, "agents": {}}', encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.delenv("HERMES_DISABLE_LAZY_INSTALLS", raising=False)+ monkeypatch.setattr(sys, "argv", ["hermes", "import-agent", "--sync"])+ installs = []++ def install_into(target, consent=None):+ def install(name): # what the catalog install leaves behind: the plugin, enabled+ installs.append((target, name))+ plugin = target / "plugins" / name+ plugin.mkdir(parents=True)+ (plugin / "plugin.yaml").write_text(f"name: {name}\nversion: 1.0.0\n", encoding="utf-8")+ (plugin / "__init__.py").write_text(+ "def register(ctx):\n"+ " ctx.register_cli_command('import-agent', 'import', "+ "lambda p: p.add_argument('--sync', action='store_true'), lambda args: 'synced')\n",+ encoding="utf-8")+ (target / "config.yaml").write_text(f"model: test\nplugins:\n enabled: [{name}]\n", encoding="utf-8")+ return {"ok": True}+ return install+ monkeypatch.setattr(lcm, "_install_into", install_into)+ from hermes_cli.main import _build_cli_parser++ parser, _subparsers = _build_cli_parser()+ args = parser.parse_args(sys.argv[1:])++ assert installs == [(home, "agent-importers")]+ assert args.sync is True and args.func(args) == "synced"+ assert "installed the 'agent-importers' plugin" in capsys.readouterr().err