Skip to content

The agent that grows with you

fix: setup's import runs in the profile it set up, and a refused enable no longer ends setup

Teknium42df6688206a
diff --git a/hermes_cli/setup_agent_import.py b/hermes_cli/setup_agent_import.py
index 2da8f2273d2..8b22be11335 100644
--- a/hermes_cli/setup_agent_import.py
+++ b/hermes_cli/setup_agent_import.py
@@ -88,6 +88,7 @@ def _ensure_plugin(hermes_home: Path) -> bool:
"""The plugin installed and enabled in *hermes_home*: the catalog install (reviewed pin, the
usual install checks) when it is missing, else just an enable."""
from hermes_cli.left_core_migration import plugin_present
+ from hermes_cli.plugins_admission import AdmissionRefused
from hermes_cli.plugins_cmd import cmd_enable
from hermes_cli.plugins_cmd_install import cmd_install
from hermes_cli.setup import _info, print_warning
@@ -100,12 +101,16 @@ def _ensure_plugin(hermes_home: Path) -> bool:
cmd_enable(PLUGIN)
else:
cmd_install(PLUGIN, enable=True)
- except SystemExit: # both print their own error, then exit
+ # Both print their own error first: a refusal exits, an enable whose dependencies PM cannot
+ # admit raises. Either way the import is skipped and the rest of setup goes on.
+ except (SystemExit, AdmissionRefused):
pass
- if plugin_present(PLUGIN, hermes_home):
- return True
- print_warning(f"The '{PLUGIN}' plugin could not be installed, so nothing was imported. "
- f"Try again later with: hermes plugins install {PLUGIN}")
+ else:
+ if plugin_present(PLUGIN, hermes_home):
+ return True
+ verb = "enabled" if present else "installed"
+ print_warning(f"The '{PLUGIN}' plugin could not be {verb}, so nothing was imported. "
+ f"Try again later with: hermes plugins {'enable' if present else 'install'} {PLUGIN}")
return False
@@ -122,7 +127,10 @@ def _run_import(source: ImportSource, hermes_home: Path) -> bool:
from tools.environments.local import served_profile_child_env
print_header(f"Importing from {source.label}", gap=True)
before = _snapshot(hermes_home)
- argv = [sys.executable, "-m", "hermes_cli.main", "import-agent", source.name, *source.extra_args]
+ # A home that is not <root>/profiles/<name> is the root: without a selector the child's
+ # _apply_profile_override would follow the sticky active_profile into another profile.
+ selector = [] if hermes_home.resolve().parent.name == "profiles" else ["--profile", "default"]
+ argv = [sys.executable, "-m", "hermes_cli.main", *selector, "import-agent", source.name, *source.extra_args]
env = served_profile_child_env(target_home=hermes_home)
if os.environ.get("PYTHONPATH"): # this same interpreter running Hermes: keep the source tree
env["PYTHONPATH"] = os.environ["PYTHONPATH"] # a checkout launched by path, which it strips
diff --git a/tests/hermes_cli/test_setup_agent_import.py b/tests/hermes_cli/test_setup_agent_import.py
index 51b8b6cde3f..32ba3ce4f48 100644
--- a/tests/hermes_cli/test_setup_agent_import.py
+++ b/tests/hermes_cli/test_setup_agent_import.py
@@ -39,8 +39,9 @@ def homes(tmp_path, monkeypatch):
(hermes_home / "plugins" / name).mkdir(parents=True)
def run(argv, env, check=False):
- calls.append(("import", argv[3:], env["HERMES_HOME"]))
- (hermes_home / "config.yaml").write_text(f"imported: {argv[4]}\n", encoding="utf-8")
+ hermes_args = argv[argv.index("hermes_cli.main") + 1:]
+ calls.append(("import", hermes_args, env["HERMES_HOME"]))
+ (hermes_home / "config.yaml").write_text(f"imported: {hermes_args[-1]}\n", encoding="utf-8")
return subprocess.CompletedProcess(argv, 0)
monkeypatch.setattr("hermes_cli.setup.prompt_yes_no", ask)
@@ -59,8 +60,9 @@ def test_found_agent_is_offered_then_installed_from_the_catalog_and_imported(hom
assert calls == [
("ask", "Import your setup from OpenClaw?", True),
("install", "agent-importers", True),
- # core's setup migrated OpenClaw's allowlisted secrets after the preview; so does this step
- ("import", ["import-agent", "openclaw", "--migrate-secrets"], str(hermes_home)),
+ # core's setup migrated OpenClaw's allowlisted secrets after the preview; so does this step.
+ # The root home is named explicitly, so a sticky active_profile cannot redirect the child.
+ ("import", ["--profile", "default", "import-agent", "openclaw", "--migrate-secrets"], str(hermes_home)),
]
@@ -74,7 +76,7 @@ def test_several_found_are_offered_as_a_checklist_and_only_the_picks_import(home
assert calls[1] == ("pick", ["Claude Code", "Cursor"], [0, 1]) # never an agent that is absent
assert calls[2:] == [("install", "agent-importers", True),
- ("import", ["import-agent", "claude-code"], str(hermes_home))]
+ ("import", ["--profile", "default", "import-agent", "claude-code"], str(hermes_home))]
def test_declining_installs_nothing(homes):
@@ -99,3 +101,21 @@ def test_headless_or_nothing_found_asks_nothing(headless, homes, monkeypatch):
assert calls == []
assert not (hermes_home / "plugins").exists()
+
+
+def test_a_refused_enable_skips_the_import_and_setup_goes_on(homes, monkeypatch):
+ """Installed but disabled, and PM cannot admit the enable: the error is printed, nothing is
+ imported, and the step returns so the rest of setup still runs."""
+ from hermes_cli.plugins_admission import AdmissionRefused
+ user_home, hermes_home, calls, _answers = homes
+ (user_home / ".cursor").mkdir()
+ (hermes_home / "plugins" / "agent-importers").mkdir(parents=True)
+
+ def refuse(name, **_):
+ calls.append(("enable", name))
+ raise AdmissionRefused("dependency conflict")
+ monkeypatch.setattr("hermes_cli.plugins_cmd.cmd_enable", refuse)
+
+ assert step.offer_agent_import(hermes_home) == ""
+
+ assert calls == [("ask", "Import your setup from Cursor?", True), ("enable", "agent-importers")]