Skip to content

The agent that grows with you

fix(uninstall): keep desktop userData in keep-data mode

Yuan Li0fec10a3ce0e
diff --git a/hermes_cli/uninstall.py b/hermes_cli/uninstall.py
index 48c5add2ca6..e1f4526d1c3 100644
--- a/hermes_cli/uninstall.py
+++ b/hermes_cli/uninstall.py
@@ -700,6 +700,9 @@ def run_uninstall(args):
print(f" Config: {hermes_home / 'config.yaml'}")
print(f" Secrets: {hermes_home / '.env'}")
print(f" Data: {hermes_home / 'cron/'}, {hermes_home / 'sessions/'}, {hermes_home / 'logs/'}")
+ from hermes_cli.gui_uninstall import desktop_userdata_dir
+ if desktop_userdata_dir().exists():
+ print(f" Desktop: {desktop_userdata_dir()} (app data - kept by 'Keep data', removed by 'Full uninstall')")
print()
if named_profiles:
@@ -781,6 +784,9 @@ def _print_uninstall_dry_run(*, project_root: Path, hermes_home: Path, full_unin
print(f" • Hermes config/data: {hermes_home}")
if sys.platform == "darwin":
print(" • macOS: dashboard/serve launchd jobs, Electron + setup caches")
+ from hermes_cli.gui_uninstall import desktop_userdata_dir
+ if (userdata := desktop_userdata_dir()).exists():
+ print(f" • {'Keep desktop' if not full_uninstall else 'Desktop'} app data: {userdata}")
profiles = _discover_named_profiles() if _is_default_hermes_home(hermes_home) else []
if profiles:
print(" • Named profiles (interactive uninstall asks before removing):")
@@ -940,10 +946,12 @@ def _perform_uninstall(
# 3c. Chat GUI artifacts go with the agent code. uninstall_gui() never touches config/sessions/
# .env (safe in keep-data mode); the packaged app + Electron userData live OUTSIDE HERMES_HOME.
+ # The userData dir is user configuration (connections.json, OAuth partitions, renderer
+ # state), so keep-data preserves it — only the full wipe removes it.
log_info("Removing desktop Chat GUI artifacts...")
try:
from hermes_cli.gui_uninstall import uninstall_gui
- if not uninstall_gui(hermes_home):
+ if not uninstall_gui(hermes_home, remove_userdata=full_uninstall):
log_info("No desktop GUI artifacts found")
except Exception as e:
log_warn(f"Could not remove desktop GUI artifacts: {e}")
@@ -1007,6 +1015,9 @@ def _perform_uninstall(
if not full_uninstall:
print(color("Your configuration and data have been preserved:", Colors.CYAN))
print(f" {hermes_home}/")
+ from hermes_cli.gui_uninstall import desktop_userdata_dir
+ if desktop_userdata_dir().exists():
+ print(f" {desktop_userdata_dir()} (desktop app data)")
print()
print("To reinstall later with your existing settings:")
print(color(_REINSTALL_HINT[windows], Colors.DIM))
diff --git a/tests/hermes_cli/test_uninstall_gui_userdata.py b/tests/hermes_cli/test_uninstall_gui_userdata.py
new file mode 100644
index 00000000000..4af1d29e538
--- /dev/null
+++ b/tests/hermes_cli/test_uninstall_gui_userdata.py
@@ -0,0 +1,85 @@
+"""Keep-data uninstall must not delete the desktop app's Electron userData dir.
+
+Regression for #122548: ``hermes uninstall`` option 1 (Keep data) wiped
+``desktop_userdata_dir()`` (connections.json, OAuth partitions, renderer state)
+because ``_perform_uninstall`` never forwarded ``remove_userdata``.
+"""
+from __future__ import annotations
+
+from pathlib import Path
+
+import pytest
+
+import hermes_cli.uninstall as uninstall
+from hermes_cli.gui_uninstall import uninstall_gui
+
+
+def homes(tmp_path, monkeypatch):
+ """Temp home + checkout with sentinel data; uninstall side effects are stubbed."""
+ home = tmp_path / "hermes-home"
+ home.mkdir()
+ (home / "config.yaml").write_text("{}", encoding="utf-8")
+ project_root = tmp_path / "checkout"
+ project_root.mkdir()
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ monkeypatch.setattr(uninstall, "get_project_root", lambda: project_root)
+ monkeypatch.setattr(uninstall, "get_hermes_home", lambda: home)
+ monkeypatch.setattr(uninstall, "uninstall_gateway_service", lambda: True)
+ for name in ("remove_path_from_shell_configs", "remove_wrapper_script",
+ "remove_node_symlinks", "remove_legacy_runtime_trees"):
+ monkeypatch.setattr(uninstall, name, lambda *a, **k: [])
+ return home, project_root
+
+
+def test_keep_data_uninstall_preserves_desktop_userdata(homes, monkeypatch):
+ home, _ = homes
+ calls: list[bool | None] = []
+
+ def spy(*args, **kwargs):
+ calls.append(kwargs.get("remove_userdata", "absent"))
+ return [Path("sentinel")]
+
+ monkeypatch.setattr("hermes_cli.gui_uninstall.uninstall_gui", spy)
+ uninstall._perform_uninstall(
+ project_root=homes[1], hermes_home=home, full_uninstall=False,
+ remove_profiles=False, named_profiles=[])
+ assert calls == [False], "keep-data must forward remove_userdata=False to uninstall_gui"
+ assert (home / "config.yaml").exists(), "keep-data must keep $HERMES_HOME data"
+
+
+def test_full_uninstall_still_removes_desktop_userdata(homes, monkeypatch):
+ home, _ = homes
+ calls: list[bool | None] = []
+
+ def spy(*args, **kwargs):
+ calls.append(kwargs.get("remove_userdata", "absent"))
+ return [Path("sentinel")]
+
+ monkeypatch.setattr("hermes_cli.gui_uninstall.uninstall_gui", spy)
+ uninstall._perform_uninstall(
+ project_root=homes[1], hermes_home=home, full_uninstall=True,
+ remove_profiles=False, named_profiles=[])
+ assert calls == [True], "full wipe must forward remove_userdata=True to uninstall_gui"
+ assert not home.exists(), "full wipe must remove $HERMES_HOME"
+
+
+def test_uninstall_gui_keeps_userdata_dir_when_told_to(tmp_path, monkeypatch):
+ """The gui_uninstall half of the contract: remove_userdata=False leaves the dir on disk."""
+ home = tmp_path / "home"
+ home.mkdir()
+ built = home / "hermes-agent" / "apps" / "desktop" / "node_modules"
+ built.mkdir(parents=True)
+ userdata = tmp_path / "appdata" / "Hermes"
+ (userdata / "Partitions").mkdir(parents=True)
+ (userdata / "connections.json").write_text('{"id":"local"}', encoding="utf-8")
+ monkeypatch.setattr("hermes_cli.gui_uninstall.desktop_userdata_dir", lambda: userdata)
+
+ removed = uninstall_gui(home, remove_userdata=False)
+ assert userdata.exists(), "remove_userdata=False must keep the Electron userData dir"
+ assert (userdata / "connections.json").read_text(encoding="utf-8") == '{"id":"local"}'
+ assert not built.exists(), "built GUI artifacts are still removed"
+ assert userdata not in removed
+
+ uninstall_gui(home, remove_userdata=True)
+ assert not userdata.exists(), "remove_userdata=True must remove the Electron userData dir"