Skip to content

The agent that grows with you

fix(desktop): keep the legacy Linux desktop entry as a hidden alias

Brooklyn Nicholsonf97d0c51b957
diff --git a/hermes_cli/gui_uninstall.py b/hermes_cli/gui_uninstall.py
index 824e74f02b5..a6b75932a9f 100644
--- a/hermes_cli/gui_uninstall.py
+++ b/hermes_cli/gui_uninstall.py
@@ -59,11 +59,14 @@ def packaged_gui_app_paths() -> "list[Path]":
[Path(program_files) / "Hermes"] if program_files else [])
# Linux: an AppImage lives wherever the user put it and deb/rpm files belong to the package manager
# (see the hint in ``uninstall_gui``), so only the desktop entry + hicolor icons are cleaned here.
- from hermes_cli.linux_desktop_entry import desktop_entry_path
+ from hermes_cli.linux_desktop_entry import LEGACY_DESKTOP_ENTRY_NAME, desktop_entry_path
data_base = _env_dir("XDG_DATA_HOME", home / ".local" / "share")
icons = data_base / "icons" / "hicolor"
# "scalable" plus every fixed-size dir the installer may have written (panel sizes + older native copies).
- return [desktop_entry_path(), data_base / "applications" / "Hermes.desktop"] + [
+ # The legacy entry is a hidden alias of the app-id entry since #124492 — remove it with the real one.
+ return [desktop_entry_path(),
+ data_base / "applications" / LEGACY_DESKTOP_ENTRY_NAME,
+ data_base / "applications" / "Hermes.desktop"] + [
icons / size / "apps" / "hermes.png"
for size in ("scalable", "24x24", "32x32", "48x48", "256x256", "512x512", "1024x1024")]
diff --git a/hermes_cli/linux_desktop_entry.py b/hermes_cli/linux_desktop_entry.py
index e8cbf630643..fe022c1abc2 100644
--- a/hermes_cli/linux_desktop_entry.py
+++ b/hermes_cli/linux_desktop_entry.py
@@ -29,8 +29,8 @@ from typing import Callable, Mapping, Optional
APP_ID = "com.nousresearch.hermes"
DESKTOP_ENTRY_NAME = f"{APP_ID}.desktop"
-# Entry name written before the app-id rename; a successful install retires it so the menu does
-# not list Hermes twice (see _remove_legacy_desktop_entry).
+# Entry name written before the app-id rename; a successful install converts it into a hidden
+# alias (NoDisplay=true) so pre-rename taskbar pins keep resolving (see _alias_legacy_desktop_entry).
LEGACY_DESKTOP_ENTRY_NAME = "hermes.desktop"
# XDG startup notification: set by an app-grid / menu launch, absent for terminal and detached
@@ -423,6 +423,7 @@ def _quote_exec_arg(arg: str) -> str:
def render_desktop_entry(exec_command: str, icon: str) -> str:
+ """The app-id entry: identity lives in the file name and ``StartupWMClass``."""
return (
"[Desktop Entry]\n"
"Type=Application\n"
@@ -438,6 +439,11 @@ def render_desktop_entry(exec_command: str, icon: str) -> str:
)
+def _render_legacy_alias_entry(exec_command: str, icon: str) -> str:
+ """The app-id entry, hidden from the app grid; ``StartupWMClass`` still groups old pins."""
+ return render_desktop_entry(exec_command, icon) + "NoDisplay=true\n"
+
+
def refresh_desktop_databases(applications_dir: Path) -> "list[str]":
"""Reindex the menu caches. Run each tool only when it exists."""
ran: list[str] = []
@@ -606,32 +612,43 @@ def _launcher_entry_management_enabled() -> bool:
return True
-def _remove_legacy_desktop_entry(applications_dir: Path) -> None:
- """Delete the pre-rename ``hermes.desktop`` left beside the app-id entry.
+def _alias_legacy_desktop_entry(applications_dir: Path, exec_command: str, icon: str) -> bool:
+ """Keep the pre-rename ``hermes.desktop`` as a hidden alias of the app-id entry.
- Without it the menu lists Hermes twice, and an old taskbar pin keeps resolving to an entry
- that no longer matches the window. Only a file that still names this app is removed —
- anything else at that path (a hand-written launcher, another vendor's file) is left alone.
+ Shells resolve a taskbar pin by the entry file name it was pinned against: deleting the
+ file makes GNOME drop the favourite and Plasma leave an inert item, and nothing can
+ re-pin for the user. The alias stays launchable for old pins without listing Hermes
+ twice. Only a file that still names this app is converted; anything else at that path
+ is left alone. True when the legacy file was (re)written.
"""
legacy = applications_dir / LEGACY_DESKTOP_ENTRY_NAME
try:
text = legacy.read_text(encoding="utf-8-sig")
except OSError:
- return
+ return False
if not any(line.strip() == "Name=Hermes" for line in text.splitlines()):
- return
+ return False
+ alias_contents = _render_legacy_alias_entry(exec_command, icon)
+ if text == alias_contents:
+ return False
try:
- legacy.unlink()
+ from utils import atomic_write_text
+
+ atomic_write_text(legacy, alias_contents, create_mode=0o755)
+ legacy.chmod(0o755)
except OSError:
- pass
+ return False
+ return True
def install_desktop_entry(project_root: Path) -> Optional[Path]:
"""Create or refresh the app-id entry, respecting the opt-out for existing entries.
- Only the app-id entry is written; a pre-rename ``hermes.desktop`` beside it is retired once
- the new entry exists, and only while launcher management is enabled. ``None`` on non-Linux
- platforms or when the write fails — a convenience, never a reason to fail a launch.
+ Only the app-id entry is written; a pre-rename ``hermes.desktop`` beside it is converted
+ into a hidden alias once the new entry exists, and only while launcher management is
+ enabled — deleting it instead would silently kill existing taskbar pins (#124492).
+ ``None`` on non-Linux platforms or when the write fails — a convenience, never a reason
+ to fail a launch.
"""
if not is_supported():
return None
@@ -651,32 +668,33 @@ def install_desktop_entry(project_root: Path) -> Optional[Path]:
icon_value = str(icon) if icon.is_file() else "hermes"
if icon.is_file() and _install_icon_to_hicolor(icon):
icon_value = "hermes"
- contents = render_desktop_entry(resolve_exec_command(project_root), icon_value)
+ exec_command = resolve_exec_command(project_root)
+ contents = render_desktop_entry(exec_command, icon_value)
try:
entry_path.parent.mkdir(parents=True, exist_ok=True)
# When nothing changed, skip the rewrite. Then a launch does not
# churn the menu caches.
- if entry_path.is_file() and entry_path.read_text(encoding="utf-8-sig") == contents:
- return entry_path
- # Atomic replace: an interrupted plain write leaves a zero-byte entry, which permanently
- # breaks the taskbar pin (nothing later rewrites a file that exists at the right path).
- # The temp+rename dance in utils.atomic_write_text is the codebase's shared implementation — ported
- # from #80547, which closed unmerged with this piece unlanded.
- from utils import atomic_write_text
-
- atomic_write_text(entry_path, contents, create_mode=0o755)
- # Some launchers (and older Plasma) offer the entry only when it is executable.
- entry_path.chmod(0o755)
+ unchanged = entry_path.is_file() and entry_path.read_text(encoding="utf-8-sig") == contents
+ if not unchanged:
+ # Atomic replace: an interrupted plain write leaves a zero-byte entry, which permanently
+ # breaks the taskbar pin (nothing later rewrites a file that exists at the right path).
+ # The temp+rename dance in utils.atomic_write_text is the codebase's shared implementation — ported
+ # from #80547, which closed unmerged with this piece unlanded.
+ from utils import atomic_write_text
+
+ atomic_write_text(entry_path, contents, create_mode=0o755)
+ # Some launchers (and older Plasma) offer the entry only when it is executable.
+ entry_path.chmod(0o755)
except OSError:
return None
- # Retiring the old entry is management too: with the opt-out set, an existing
- # launcher stays even here, in the missing-entry path where the new entry is
- # still created.
- if manage_enabled:
- _remove_legacy_desktop_entry(entry_path.parent)
- refresh_desktop_databases(entry_path.parent)
+ # Converting the old entry is management too: with the opt-out set, an existing
+ # launcher stays untouched even here, in the missing-entry path where the new
+ # entry is still created.
+ aliased = manage_enabled and _alias_legacy_desktop_entry(entry_path.parent, exec_command, icon_value)
+ if aliased or not unchanged:
+ refresh_desktop_databases(entry_path.parent)
return entry_path
diff --git a/tests/hermes_cli/test_gui_uninstall.py b/tests/hermes_cli/test_gui_uninstall.py
index ab9eb914b2d..93488bcd60c 100644
--- a/tests/hermes_cli/test_gui_uninstall.py
+++ b/tests/hermes_cli/test_gui_uninstall.py
@@ -60,6 +60,10 @@ def test_uninstall_removes_launcher_entry_and_refreshes_cache(tmp_path, monkeypa
entry = lde.desktop_entry_path()
entry.parent.mkdir(parents=True, exist_ok=True)
entry.write_text("x", encoding="utf-8")
+ # The pre-rename entry lives on as a hidden alias of the app-id entry (#124492);
+ # a GUI uninstall must take it with the real one.
+ legacy_alias = entry.with_name(lde.LEGACY_DESKTOP_ENTRY_NAME)
+ legacy_alias.write_text("x", encoding="utf-8")
refreshed: list[Path] = []
monkeypatch.setattr(
@@ -76,6 +80,7 @@ def test_uninstall_removes_launcher_entry_and_refreshes_cache(tmp_path, monkeypa
removed = gu.uninstall_gui(hermes_home)
assert entry in removed and not entry.exists()
+ assert legacy_alias in removed and not legacy_alias.exists()
assert refreshed == [entry.parent]
# The icon lives in the checkout. A GUI uninstall must not delete it.
assert lde.icon_path(hermes_home / "hermes-agent").exists()
diff --git a/tests/hermes_cli/test_linux_desktop_entry.py b/tests/hermes_cli/test_linux_desktop_entry.py
index fbff1958e98..e0cfa57074d 100644
--- a/tests/hermes_cli/test_linux_desktop_entry.py
+++ b/tests/hermes_cli/test_linux_desktop_entry.py
@@ -653,8 +653,16 @@ def test_installed_entry_carries_the_window_app_id(tmp_path, xdg_home, monkeypat
assert values["Name"] == "Hermes" # the menu label is not part of the identity
-def test_install_retires_the_legacy_entry_name(tmp_path, xdg_home, monkeypatch):
- """A leftover hermes.desktop would surface as a second Hermes in the app grid."""
+def test_install_keeps_the_legacy_entry_as_a_hidden_alias(tmp_path, xdg_home, monkeypatch):
+ """A pin resolves by the entry file name it was pinned against (#124492).
+
+ Deleting ``hermes.desktop`` silently kills existing taskbar pins (GNOME drops
+ the favourite, Plasma leaves an inert item) and the shell has no mechanism to
+ re-point the association for the user. The pre-rename entry must survive as a
+ ``NoDisplay=true`` alias of the app-id entry: out of the app grid, still
+ launchable, and window-matched through the same ``StartupWMClass`` and
+ ``Exec`` as the app-id entry.
+ """
_stub_install(tmp_path, monkeypatch)
root = _make_project(tmp_path)
legacy = xdg_home / "applications" / lde.LEGACY_DESKTOP_ENTRY_NAME
@@ -667,11 +675,30 @@ def test_install_retires_the_legacy_entry_name(tmp_path, xdg_home, monkeypatch):
entry = lde.install_desktop_entry(root)
assert entry is not None and entry.is_file()
- assert not legacy.exists()
+ assert legacy.is_file(), "an existing pin resolves through this file — it must survive"
+ alias = _parse(legacy.read_text(encoding="utf-8"))
+ assert alias["NoDisplay"] == "true" # no second Hermes in the app grid
+ assert alias["StartupWMClass"] == lde.APP_ID # still groups with the window
+ entry_values = _parse(entry.read_text(encoding="utf-8"))
+ assert alias["Exec"] == entry_values["Exec"] # launches the same command
+ assert alias["Icon"] == entry_values["Icon"]
+
+
+def test_unchanged_entry_still_aliases_a_legacy_entry(tmp_path, xdg_home, monkeypatch):
+ """An up-to-date app-id entry must not skip converting a legacy file found beside it."""
+ _stub_install(tmp_path, monkeypatch)
+ root = _make_project(tmp_path)
+ assert lde.install_desktop_entry(root) is not None
+ legacy = xdg_home / "applications" / lde.LEGACY_DESKTOP_ENTRY_NAME
+ legacy.write_text("[Desktop Entry]\nType=Application\nName=Hermes\nExec=hermes desktop\n", encoding="utf-8")
+
+ lde.install_desktop_entry(root)
+
+ assert _parse(legacy.read_text(encoding="utf-8"))["NoDisplay"] == "true"
def test_install_keeps_foreign_files_at_the_legacy_path(tmp_path, xdg_home, monkeypatch):
- """Only our own entry retires; another app's file at that name is not ours to delete."""
+ """Only our own entry is converted to an alias; another app's file is not ours to rewrite."""
_stub_install(tmp_path, monkeypatch)
root = _make_project(tmp_path)
foreign = xdg_home / "applications" / lde.LEGACY_DESKTOP_ENTRY_NAME
@@ -688,9 +715,9 @@ def test_install_keeps_foreign_files_at_the_legacy_path(tmp_path, xdg_home, monk
def test_install_opt_out_preserves_the_legacy_entry(tmp_path, xdg_home, monkeypatch):
- """The opt-out protects user edits, so it also stops the legacy retirement.
+ """The opt-out protects user edits, so it also stops the legacy alias conversion.
- The missing-entry path still creates the app-id entry; the deletion is
+ The missing-entry path still creates the app-id entry; the rewrite is
management too and must not run when the user asked to be left alone.
"""
hermes_home = tmp_path / "hermes-home"
@@ -711,7 +738,9 @@ def test_install_opt_out_preserves_the_legacy_entry(tmp_path, xdg_home, monkeypa
entry = lde.install_desktop_entry(root)
assert entry == xdg_home / "applications" / lde.DESKTOP_ENTRY_NAME
- assert legacy.is_file(), "the opt-out must keep the legacy entry in place"
+ assert legacy.read_text(encoding="utf-8") == (
+ "[Desktop Entry]\nType=Application\nName=Hermes\nExec=hermes desktop\n"
+ ), "the opt-out must leave the legacy entry byte-for-byte untouched"
def test_app_id_matches_the_desktop_build_identity():