The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): hermes update puts back an installed Hermes.app that went missing
kshitijk4poorb52c73c3e4cf
diff --git a/hermes_cli/gui_uninstall.py b/hermes_cli/gui_uninstall.pyindex a6b75932a9f..f958f96b493 100644--- a/hermes_cli/gui_uninstall.py+++ b/hermes_cli/gui_uninstall.py@@ -44,6 +44,14 @@ def source_built_gui_artifacts(hermes_home: Path) -> "list[Path]":agent_root / "node_modules", hermes_home / "desktop-build-stamp.json"]+def desktop_install_record() -> Path:+ """Where ``hermes update`` records the installed ``Hermes.app`` copies it keeps current. The apps+ are machine-wide, so the record sits under the default root whichever profile runs; deleting it+ is what stops an uninstalled app from being put back by the next update."""+ from hermes_constants import get_default_hermes_root # noqa: PLC0415+ return get_default_hermes_root() / "desktop-installed-apps.json"++def packaged_gui_app_paths() -> "list[Path]":"""Standard install locations of the packaged desktop distributable for the current OS. Every candidateis returned; the caller filters to those that exist. Never globs system-wide — only the well-known@@ -137,7 +145,7 @@ def uninstall_gui(hermes_home: "Path | None" = None, *, remove_userdata: bool =removed.append(path)return foundlog_info("Removing built GUI artifacts (renderer, release, node_modules)...")- _remove_existing(source_built_gui_artifacts(home))+ _remove_existing([*source_built_gui_artifacts(home), desktop_install_record()])log_info("Removing installed desktop app...")if not _remove_existing(packaged_gui_app_paths()):log_info("No packaged desktop app found in standard locations")diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.pyindex 0a76d222816..586c206eb29 100644--- a/hermes_cli/main_desktop.py+++ b/hermes_cli/main_desktop.py@@ -954,8 +954,9 @@ def _stage_macos_bundle_copy(src: Path, dst: Path) -> None:subprocess.run(["/usr/bin/ditto", str(src), str(dst)], check=True, capture_output=True)-def _install_rebuilt_desktop_app(desktop_dir: Path) -> tuple[list[Path], list[str]]:- """Copy the rebuilt macOS bundle over every stale installed ``Hermes.app`` (#52339).+def _install_rebuilt_desktop_app(desktop_dir: Path, candidates: list[Path]) -> tuple[list[Path], list[str]]:+ """Copy the rebuilt macOS bundle into every stale or missing installed ``Hermes.app`` in+ *candidates* (``_installed_desktop_apps()``) (#52339).``hermes desktop --build-only`` (what ``hermes update`` runs) packages into``apps/desktop/release/`` only. Finder, the Dock and Spotlight launch the copy in@@ -964,7 +965,7 @@ def _install_rebuilt_desktop_app(desktop_dir: Path) -> tuple[list[Path], list[stonly the bundle it was launched from, so an app running from ``release/`` never refreshedthe installed copy either.- Returns ``(installed, problems)``: bundles that were replaced, and one user-facing line per+ Returns ``(installed, problems)``: bundles that were (re)installed, and one user-facing line perbundle that could not be (running, copy or swap failure). Both empty means every installedcopy was already current."""@@ -975,16 +976,32 @@ def _install_rebuilt_desktop_app(desktop_dir: Path) -> tuple[list[Path], list[streturn [], []# .../Hermes.app/Contents/MacOS/Hermes -> .../Hermes.appreturn _install_rebuilt_macos_bundles(- rebuilt_exe.parents[2], _installed_desktop_apps(), running=_running_macos_app_bundles())+ rebuilt_exe.parents[2], candidates, running=_running_macos_app_bundles())def _refresh_installed_desktop_apps(desktop_dir: Path) -> None:- """Install the rebuilt bundle over stale installed copies and report each outcome."""- installed, problems = _install_rebuilt_desktop_app(desktop_dir)+ """Install the rebuilt bundle over stale or missing installed copies, report each outcome, and+ record which copies this update keeps current."""+ owned = _installed_desktop_apps()+ missing = {app for app in owned if not app.exists()}+ installed, problems = _install_rebuilt_desktop_app(desktop_dir, owned)for app in installed:- print(f" ✓ Installed the rebuilt Desktop app at {app}")+ if app in missing:+ print(f" ✓ Reinstalled the Desktop app at {app}: it had been removed, so Finder, "+ "the Dock and Spotlight could not find Hermes")+ else:+ print(f" ✓ Installed the rebuilt Desktop app at {app}")for problem in problems:print(f" ⚠ {problem}")+ if not _owns_installed_desktop_apps():+ return+ from hermes_cli.gui_uninstall import desktop_install_record # noqa: PLC0415+ from utils import atomic_json_write # noqa: PLC0415+ try:+ # A copy that failed to reinstall stays recorded, so the next update retries it.+ atomic_json_write(desktop_install_record(), {"apps": [str(app) for app in owned]})+ except OSError as exc:+ print(f" ⚠ Could not record the installed Desktop app ({exc})")def _update_owned_macos_bundles(candidates: list[Path]) -> list[Path]:@@ -1006,20 +1023,34 @@ def _update_owned_macos_bundles(candidates: list[Path]) -> list[Path]:return owned-def _installed_desktop_apps() -> list[Path]:- """Installed macOS ``Hermes.app`` bundles this checkout's update owns (none off macOS).-- A packaged app runs the checkout under the default Hermes home, so only that checkout may- build for it: a bundle from any other tree (a dev worktree) would split shell from backend.- """+def _owns_installed_desktop_apps() -> bool:+ """A packaged app runs the checkout under the default Hermes home, so only that checkout (on+ macOS) may build for it: a bundle from any other tree (a dev worktree) would split shell from+ backend."""if sys.platform != "darwin":- return []- from hermes_cli.gui_uninstall import packaged_gui_app_paths # noqa: PLC0415+ return Falsefrom hermes_cli.main import PROJECT_ROOT # noqa: PLC0415from hermes_constants import get_default_hermes_root # noqa: PLC0415- if Path(PROJECT_ROOT).resolve() != (get_default_hermes_root() / "hermes-agent").resolve():+ return Path(PROJECT_ROOT).resolve() == (get_default_hermes_root() / "hermes-agent").resolve()+++def _installed_desktop_apps() -> list[Path]:+ """Installed macOS ``Hermes.app`` bundles this checkout's update owns.++ When no owned copy is left, a recorded one that has gone missing still counts: its ownership+ stamp left with the bundle, and without the record nothing would ever put it back (Finder, the+ Dock and Spotlight lose Hermes for good). A copy moved to the other Applications folder keeps+ its stamp, so it is found instead of doubled. Hermes' GUI uninstall deletes the record.+ """+ if not _owns_installed_desktop_apps():return []- return _update_owned_macos_bundles(packaged_gui_app_paths())+ from hermes_cli.gui_uninstall import desktop_install_record, packaged_gui_app_paths # noqa: PLC0415+ from utils import read_json_or_empty # noqa: PLC0415+ candidates = packaged_gui_app_paths()+ if owned := _update_owned_macos_bundles(candidates):+ return owned+ recorded = read_json_or_empty(desktop_install_record()).get("apps", [])+ return [app for app in candidates if str(app) in recorded and not app.exists()]def _installed_desktop_launch_target(desktop_dir: Path, packaged_executable: Path) -> Path:@@ -1043,8 +1074,8 @@ def _installed_desktop_launch_target(desktop_dir: Path, packaged_executable: Patdef _install_rebuilt_macos_bundles(rebuilt_app: Path, candidates: list[Path], *, running: set[Path]) -> tuple[list[Path], list[str]]:- """Stage-and-swap ``rebuilt_app`` over each existing bundle in ``candidates`` whose ``app.asar``- differs. The rebuilt bundle already carries the stable local signing identity and no+ """Stage-and-swap ``rebuilt_app`` into each bundle path in ``candidates`` that is missing or+ whose ``app.asar`` differs. The rebuilt bundle already carries the stable local signing identity and noquarantine xattr (``_desktop_macos_relaunchable_fixup``); ``ditto`` preserves both, so nothingis re-signed here and TCC grants survive."""rebuilt_hash = _app_asar_hash(rebuilt_app)@@ -1053,7 +1084,7 @@ def _install_rebuilt_macos_bundles(installed: list[Path] = []problems: list[str] = []for app in candidates:- if not app.is_dir() or _app_asar_hash(app) == rebuilt_hash:+ if app.is_dir() and _app_asar_hash(app) == rebuilt_hash:continueif app.resolve() in running:problems.append(@@ -1069,7 +1100,8 @@ def _install_rebuilt_macos_bundles(_swap_in_new_macos_bundle(tmp, app, old)except (OSError, subprocess.CalledProcessError) as exc:shutil.rmtree(tmp, ignore_errors=True)- problems.append(f"{app} could not be replaced ({exc}); the previous app was kept")+ kept = "; the previous app was kept" if app.exists() else ""+ problems.append(f"{app} could not be installed ({exc}){kept}")continueinstalled.append(app)return installed, problemsdiff --git a/tests/hermes_cli/test_desktop_install_after_update.py b/tests/hermes_cli/test_desktop_install_after_update.pyindex 2e9b671ed7f..4f289596999 100644--- a/tests/hermes_cli/test_desktop_install_after_update.py+++ b/tests/hermes_cli/test_desktop_install_after_update.py@@ -2,8 +2,10 @@``hermes desktop --build-only`` only packages into ``apps/desktop/release/``; Finder launches thecopy in ``/Applications``. These pin the contract of ``_install_rebuilt_macos_bundles``: a stale-installed copy is replaced, a current one and a running one are never touched, and a failed swap-leaves the previous bundle launchable.+or missing installed copy is (re)installed, a current one and a running one are never touched, and+a failed swap leaves the previous bundle launchable. Which paths count as installed is decided by+``_installed_desktop_apps``: a recorded copy that went missing comes back until Hermes' own GUI+uninstall drops the record."""import shutil@@ -35,22 +37,22 @@ def rebuilt(tmp_path, monkeypatch):return _bundle(tmp_path / "apps" / "desktop" / "release" / "mac-arm64", b"rebuilt")-def test_stale_bundle_is_replaced_current_and_running_are_left_alone(rebuilt, tmp_path):+def test_stale_and_missing_bundles_are_installed_current_and_running_are_left_alone(rebuilt, tmp_path):stale = _bundle(tmp_path / "Applications", b"stale")current = _bundle(tmp_path / "home" / "Applications", b"rebuilt")running = _bundle(tmp_path / "Volumes" / "Applications", b"older")current_marker = current / "Contents" / "marker"- current_marker.write_text("untouched")+ current_marker.write_text("untouched", encoding="utf-8")+ missing = tmp_path / "missing" / "Hermes.app"installed, problems = main_desktop._install_rebuilt_macos_bundles(- rebuilt, [stale, current, running, tmp_path / "missing" / "Hermes.app"],- running={running.resolve()})+ rebuilt, [stale, current, running, missing], running={running.resolve()})- assert installed == [stale]- assert _asar(stale) == b"rebuilt"+ assert installed == [stale, missing]+ assert _asar(stale) == b"rebuilt" and _asar(missing) == b"rebuilt"assert not (stale.parent / "Hermes.app.hermes-update-old").exists()assert not (stale.parent / "Hermes.app.hermes-update-new").exists()- assert current_marker.read_text() == "untouched"+ assert current_marker.read_text(encoding="utf-8") == "untouched"# A live app is reported, never swapped under.assert _asar(running) == b"older"assert len(problems) == 1 and str(running) in problems[0]@@ -72,3 +74,40 @@ def test_failed_swap_keeps_the_previous_bundle_launchable(rebuilt, tmp_path, monassert len(problems) == 1assert stale.is_dir() and _asar(stale) == b"stale"assert not (stale.parent / "Hermes.app.hermes-update-new").exists()++[email protected]("macos")+def test_recorded_app_that_went_missing_comes_back_until_gui_uninstall(rebuilt, tmp_path, monkeypatch):+ from hermes_cli import gui_uninstall+ from hermes_cli import main as hermes_main++ home = tmp_path / "hermes-home"+ (home / "hermes-agent").mkdir(parents=True)+ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setattr(hermes_main, "PROJECT_ROOT", home / "hermes-agent")+ (rebuilt / "Contents" / "Resources" / "install-stamp.json").write_text('{"updateMechanism": "self"}', encoding="utf-8")+ app = tmp_path / "Applications" / "Hermes.app"+ shutil.copytree(rebuilt, app)+ user_app = tmp_path / "user" / "Applications" / "Hermes.app"+ user_app.parent.mkdir(parents=True)+ monkeypatch.setattr(gui_uninstall, "packaged_gui_app_paths", lambda: [app, user_app])+ monkeypatch.setattr(gui_uninstall, "desktop_userdata_dir", lambda: tmp_path / "userdata")+ monkeypatch.setattr(main_desktop, "_desktop_packaged_executable",+ lambda _d: rebuilt / "Contents" / "MacOS" / "Hermes")+ monkeypatch.setattr(main_desktop, "_running_macos_app_bundles", set)++ main_desktop._refresh_installed_desktop_apps(tmp_path) # current copy: recorded, untouched+ app.rename(user_app) # moved by the user: found by its stamp, never doubled+ main_desktop._refresh_installed_desktop_apps(tmp_path)+ assert not app.exists()+ shutil.rmtree(user_app)+ main_desktop._refresh_installed_desktop_apps(tmp_path)+ assert _asar(user_app) == b"rebuilt" and not app.exists()+ assert main_desktop._update_owned_macos_bundles([user_app]) == [user_app]+ shutil.rmtree(user_app) # the reinstalled copy is owned again, so it comes back every time+ main_desktop._refresh_installed_desktop_apps(tmp_path)+ assert _asar(user_app) == b"rebuilt"++ gui_uninstall.uninstall_gui(tmp_path / "profile-home") # the record is machine-wide+ main_desktop._refresh_installed_desktop_apps(tmp_path)+ assert not user_app.exists()diff --git a/website/docs/getting-started/updating.md b/website/docs/getting-started/updating.mdindex 1d37d0e3d3c..06e559bdde2 100644--- a/website/docs/getting-started/updating.md+++ b/website/docs/getting-started/updating.md@@ -138,7 +138,7 @@ For an admitted source checkout, `hermes update` runs these phases:3. **Post-pull syntax validation + auto-rollback** — after the pull, Hermes compiles the nine critical files every `hermes` invocation imports at startup. If any fails to parse (e.g. an orphan merge-conflict marker, an accidentally truncated file), Hermes rolls the install back so your shell stays bootable: it resets the checkout to the commit it ran before the pull (`git reset --hard <pre-pull-sha>`), or, when the update switched away from a detached checkout or a parked feature branch, returns there with `git checkout --detach <sha>` / `git checkout <branch>` (a branch it cannot check out again is restored detached at the same commit). Re-run `hermes update` once the upstream fix lands.4. **Dependency preparation** — PM provisions required tools and prepares a complete Python environment from the new lock, existing extras, and enabled plugin requirements. It validates that environment before publishing its selection. A plugin never fails the update. A plugin that no longer fits the new core is added to `plugins.disabled` in every profile that enables it (a memory provider has `memory.provider` cleared). That covers a `requires-python` that excludes Hermes's Python, a `manifest_version` newer than this Hermes supports, and dependencies that the resolver proves can't resolve alongside core and earlier plugins in config order, or that fail their own build. A download or network failure gets one retry and is disabled if it fails again. The update prints `⚠ Disabled plugin '<name>' in <home>: <reason>`, records it in the receipt's warnings, and continues. Re-enable it with `hermes plugins enable <name>` once the plugin ships a compatible release, or once the network is back. A `requires_hermes` range the running version misses never disables a plugin, because a source checkout without release tags can read as an older release. That plugin sits out instead (`⚠ Left plugin '<name>' … out of this update`), stays enabled, and rejoins once Hermes reports a version it accepts. A secondary profile whose config cannot be read sits out the same way until the config is fixed. Only a core that cannot build on its own fails this step.5. **Config migration** — detects new config options added since your version and prompts you to set them-6. **Desktop rebuild (stage-and-swap)** — if the Hermes Desktop app was built from this checkout, it is rebuilt so the GUI matches the new code. The rebuild packs into a temporary staging directory next to `apps/desktop/release/`, verifies the staged app, and only then renames it over the previous build (on Windows a real-time scanner briefly holding `release/win-unpacked` is ridden out with a few short retries). A rebuild that fails at any point — corrupt Electron download, missing dependency, disk full — leaves the previous app untouched and launchable; the update fails at that step, and `hermes desktop --build-only --force-build` or the next `hermes update` retries the rebuild. On macOS the rebuilt bundle is then copied (with `ditto`, signature intact) over a stale `/Applications/Hermes.app` or `~/Applications/Hermes.app`, so the copy Finder and the Dock launch matches the backend; an installed copy that is currently running is left alone and the update tells you to quit it and run `hermes update` again. On Windows, when the update finishes from inside the Desktop app it would rebuild (the app completing an interrupted update at launch), the rebuild is skipped with a notice instead: Windows locks a running app's files, and stopping the app would end the update with it. The rest of the update completes; quit Hermes Desktop and run `hermes desktop` from a terminal, or use **Update now** in **Settings → About**, to rebuild and reopen it.+6. **Desktop rebuild (stage-and-swap)** — if the Hermes Desktop app was built from this checkout, it is rebuilt so the GUI matches the new code. The rebuild packs into a temporary staging directory next to `apps/desktop/release/`, verifies the staged app, and only then renames it over the previous build (on Windows a real-time scanner briefly holding `release/win-unpacked` is ridden out with a few short retries). A rebuild that fails at any point — corrupt Electron download, missing dependency, disk full — leaves the previous app untouched and launchable; the update fails at that step, and `hermes desktop --build-only --force-build` or the next `hermes update` retries the rebuild. On macOS the rebuilt bundle is then copied (with `ditto`, signature intact) over a stale `/Applications/Hermes.app` or `~/Applications/Hermes.app`, so the copy Finder and the Dock launch matches the backend; an installed copy that is currently running is left alone and the update tells you to quit it and run `hermes update` again. If a copy an earlier update installed has since been removed (including dragged to the Trash), the update rebuilds it if needed, puts it back and says so, so Finder, the Dock and Spotlight find Hermes again; `hermes uninstall` removes the app for good. On Windows, when the update finishes from inside the Desktop app it would rebuild (the app completing an interrupted update at launch), the rebuild is skipped with a notice instead: Windows locks a running app's files, and stopping the app would end the update with it. The rest of the update completes; quit Hermes Desktop and run `hermes desktop` from a terminal, or use **Update now** in **Settings → About**, to rebuild and reopen it.7. **Gateway auto-restart**: running gateways are refreshed after the update completes. Service-managed gateways (systemd on Linux, launchd on macOS) restart through the service manager. Manual gateways are relaunched when Hermes can map their PID to a profile. Manually launched `hermes serve` / `hermes dashboard` backends are different: the updater leaves them running and asks their owner to restart them. See [Manual backend restart reminders](#manual-backend-restart-reminders). Backends owned by a running Desktop app remain the app's responsibility.8. **Multiplex migration (multi-profile installs)** — once the fleet is verified on the new code, an install with two or more profiles that still run **one gateway per profile** is folded into a single multiplexed default gateway when nothing blocks it (same as `hermes gateway migrate --multiplex --yes`); if a blocker exists (a bot token shared by two profiles, a secondary profile binding a port with no `/p/<profile>/` ingress) the update prints the blockers with their fixes and changes nothing. Single-profile installs are never touched. See [Migrating from per-profile gateways](../user-guide/multi-profile-gateways.md#migrating-from-per-profile-gateways).