The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): prefer pinned backend over mutable install
ethernetdd189aad1a8b
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex ce5656aae68..97ad5f60d05 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -2467,7 +2467,7 @@ function backendSupportsServe(backend) {timeout: PROBE_TIMEOUT_MS,stdio: 'ignore',// `.cmd`/`.bat` shim backends carry shell: true in their descriptor- // (see resolveHermesBackend step 4); execFileSync of a .cmd without+ // (see resolveHermesBackend's command override); execFileSync of a .cmd without// shell throws EINVAL on modern Node, which the catch below would// mis-cache as "serve unsupported" for the process lifetime.shell: Boolean(backend.shell),@@ -4427,39 +4427,15 @@ function resolveHermesBackend(backendArgs: string[]): ResolvedHermesBackend {}}- // 3. ACTIVE_HERMES_ROOT — the canonical install at- // %LOCALAPPDATA%\\hermes\\hermes-agent (Windows) or ~/.hermes/hermes-agent.- // A valid bootstrap marker proves Desktop finished the first-run install- // flow, but marker provenance is NOT the same thing as runtime usability:- // the CLI can publish the same installation launcher, and older desktop- // builds could leave a healthy install behind without the marker. If the- // active runtime is usable, launch it directly; only fall through to- // bootstrap when the runtime itself is unusable.- const activeBackend: SourceBackend | null = resolveSourceInstallationBackend(ACTIVE_HERMES_ROOT, backendArgs, { hermesHome: HERMES_HOME })- const activeRuntime: ActiveRuntimeState = activeRuntimeState(activeBackend)-- if (activeBackend && !bootstrapRepairRequested) {- if (!activeRuntime.hasValidMarker) {- rememberLog(- `[bootstrap] Active Hermes runtime at ${ACTIVE_HERMES_ROOT} is usable but the bootstrap marker is missing or stale; skipping first-run bootstrap.`- )- }-- return activeBackend- }-- if (bootstrapRepairRequested) {- rememberLog('[bootstrap] repair requested; bypassing the usable active runtime to re-run the installer')- }-- // 4. HERMES_DESKTOP_HERMES — an explicit deployment override (used by the+ // 3. HERMES_DESKTOP_HERMES — an explicit deployment override (used by the// Nix wrapper), not a discovered PATH candidate. The pinned backend is- // the only valid runtime there; never fall through to bootstrap for it.- const hermesOverride = process.env.HERMES_DESKTOP_HERMES- let hermesCommand = null+ // the only valid runtime there. Resolve it before any mutable install,+ // which may belong to an older release or a different Python environment.+ const hermesOverride: string | undefined = process.env.HERMES_DESKTOP_HERMES+ let hermesCommand: string | null = nullif (hermesOverride) {- const resolvedOverride = findOnPath(hermesOverride)+ const resolvedOverride: string | null = findOnPath(hermesOverride)if (resolvedOverride) {hermesCommand = resolvedOverride@@ -4474,13 +4450,13 @@ function resolveHermesBackend(backendArgs: string[]): ResolvedHermesBackend {rememberLog(`Ignoring desktop app executable on PATH while resolving Hermes CLI: ${hermesCommand}`)hermesCommand = null} else {- const unwrapped = unwrapWindowsVenvHermesCommand(hermesCommand, backendArgs)+ const unwrapped: ReturnType<typeof unwrapWindowsVenvHermesCommand> = unwrapWindowsVenvHermesCommand(hermesCommand, backendArgs)if (unwrapped) {return unwrapped}- const shellForProbe = isCommandScript(hermesCommand)+ const shellForProbe: boolean = isCommandScript(hermesCommand)if (shouldTrustHermesOverride(hermesOverride) || verifyHermesCli(hermesCommand, { shell: shellForProbe })) {return {@@ -4502,6 +4478,31 @@ function resolveHermesBackend(backendArgs: string[]): ResolvedHermesBackend {}}+ // 4. ACTIVE_HERMES_ROOT — the canonical install at+ // %LOCALAPPDATA%\\hermes\\hermes-agent (Windows) or ~/.hermes/hermes-agent.+ // A valid bootstrap marker proves Desktop finished the first-run install+ // flow, but marker provenance is NOT the same thing as runtime usability:+ // the CLI can publish the same installation launcher, and older desktop+ // builds could leave a healthy install behind without the marker. If the+ // active runtime is usable, launch it directly; only fall through to+ // bootstrap when the runtime itself is unusable.+ const activeBackend: SourceBackend | null = resolveSourceInstallationBackend(ACTIVE_HERMES_ROOT, backendArgs, { hermesHome: HERMES_HOME })+ const activeRuntime: ActiveRuntimeState = activeRuntimeState(activeBackend)++ if (activeBackend && !bootstrapRepairRequested) {+ if (!activeRuntime.hasValidMarker) {+ rememberLog(+ `[bootstrap] Active Hermes runtime at ${ACTIVE_HERMES_ROOT} is usable but the bootstrap marker is missing or stale; skipping first-run bootstrap.`+ )+ }++ return activeBackend+ }++ if (bootstrapRepairRequested) {+ rememberLog('[bootstrap] repair requested; bypassing the usable active runtime to re-run the installer')+ }+// 5. Nothing usable yet -- signal the bootstrap runner that we need to// clone+install. Phase 1D's bootstrap-runner consumes this sentinel// and drives install.ps1 stages with a progress UI. Until 1D lands,diff --git a/nix/checks.nix b/nix/checks.nixindex 4478f912e3a..e59200fa8f1 100644--- a/nix/checks.nix+++ b/nix/checks.nix@@ -999,6 +999,15 @@ json.dump(sorted(leaf_paths(DEFAULT_CONFIG)), sys.stdout, indent=2)mkdir -p $out'';+ # A pre-existing CLI install must not override the package's backend.+ desktop-backend = pkgs.runCommand "hermes-desktop-backend" {+ nativeBuildInputs = [ hermes-agent.python pkgs.cage ];+ } ''+ python3 ${./tests/desktop-backend.py} \+ ${self'.packages.desktop}/bin/hermes-desktop ${hermes-agent}/bin/hermes+ mkdir -p $out+ '';+# Verify CLI subcommands are accessiblecli-commands = pkgs.runCommand "hermes-cli-commands" { } ''set -ediff --git a/nix/desktop.nix b/nix/desktop.nixindex f650d1a34a5..0f435e09648 100644--- a/nix/desktop.nix+++ b/nix/desktop.nix@@ -4,7 +4,7 @@# `hermes` binary with the venv, runtime PATH, bundled skills/plugins, etc.# already wired up. We point the desktop at it via the existing# `HERMES_DESKTOP_HERMES` override env var, so the desktop's resolver-# uses our fully wrapped binary at step 4 ("existing Hermes CLI").+# uses our fully wrapped binary before the mutable managed install.# No reimplementation of the agent resolution in this wrapper.{pkgs,@@ -171,8 +171,8 @@ stdenv.mkDerivation {# Wrap the nixpkgs electron binary to launch our app. Set# HERMES_DESKTOP_HERMES to the absolute path of the nix-built `hermes`- # binary so the desktop's resolver step 4 ("existing Hermes CLI on- # PATH") uses our fully wrapped binary — venv with all deps,+ # binary so the deployment override selects our fully wrapped binary+ # before any mutable managed install — venv with all deps,# bundled skills/plugins, runtime PATH (ripgrep/git/ffmpeg/etc).# No reimplementation of the agent resolver in the wrapper.makeWrapper ${lib.getExe electron} $out/bin/hermes-desktop \diff --git a/nix/hermes-agent.nix b/nix/hermes-agent.nixindex 898e11fc064..b027517a56e 100644--- a/nix/hermes-agent.nix+++ b/nix/hermes-agent.nix@@ -330,8 +330,8 @@ stdenv.mkDerivation (finalAttrs: {# `hermesDesktop` references `finalAttrs.finalPackage` (this whole# derivation, after all overrides are applied) so the desktop wrapper- # can prepend its `/bin` to PATH. The desktop's resolver step 4- # ("existing hermes on PATH") then picks up the fully wrapped+ # can pin its `hermes` command via HERMES_DESKTOP_HERMES. The+ # deployment override then picks up the fully wrapped# `hermes` binary — venv with all deps, bundled skills/plugins,# runtime PATH (ripgrep/git/ffmpeg/etc). No re-implementation# of the agent resolution in the desktop wrapper.diff --git a/nix/tests/desktop-backend.py b/nix/tests/desktop-backend.pynew file mode 100644index 00000000000..ec9b19e5bf0--- /dev/null+++ b/nix/tests/desktop-backend.py@@ -0,0 +1,77 @@+"""Launch the packaged desktop with a competing mutable install."""+import os+from pathlib import Path+import signal+import subprocess+import sys+import tempfile+import time+++desktop, expected = sys.argv[1:]+with tempfile.TemporaryDirectory(prefix="hermes-desktop-backend-") as temporary:+ home = Path(temporary)+ hermes_home = home / ".hermes"+ legacy = hermes_home / "hermes-agent"+ (legacy / "hermes_cli").mkdir(parents=True)+ (legacy / "hermes_cli" / "main.py").touch()+ launcher = legacy / "venv" / "bin" / "hermes"+ launcher.parent.mkdir(parents=True)+ # The old runtime passes discovery but cannot initialize a session. It+ # must not win merely because it was installed before the Nix desktop.+ launcher.write_text(+ f"#!{sys.executable}\n"+ "import sys\n"+ "if '--version' in sys.argv:\n"+ " print('Hermes legacy fixture')\n"+ " sys.exit(0)\n"+ "print('WRONG_BACKEND_SELECTED', flush=True)\n"+ "sys.exit(73)\n"+ )+ launcher.chmod(0o755)+ runtime = home / "runtime"+ runtime.mkdir(mode=0o700)+ env = {+ "PATH": os.environ["PATH"],+ "HOME": str(home),+ "HERMES_HOME": str(hermes_home),+ "HERMES_DESKTOP_USER_DATA_DIR": str(home / "electron"),+ "XDG_RUNTIME_DIR": str(runtime),+ "XDG_CONFIG_HOME": str(home / ".config"),+ "XDG_CACHE_HOME": str(home / ".cache"),+ "WLR_BACKENDS": "headless",+ "WLR_RENDERER": "pixman",+ "WLR_NO_HARDWARE_CURSORS": "1",+ "LANG": "C.UTF-8",+ "TZ": "UTC",+ }+ log_path = home / "desktop-output.log"+ with log_path.open("w") as log:+ child = subprocess.Popen(+ ["cage", "--", desktop, "--no-sandbox", "--disable-gpu", "--ozone-platform=wayland"],+ cwd=home, env=env, stdout=log, stderr=subprocess.STDOUT,+ start_new_session=True,+ )+ try:+ deadline = time.monotonic() + 90+ while time.monotonic() < deadline:+ output = log_path.read_text()+ desktop_log = hermes_home / "logs" / "desktop.log"+ if desktop_log.exists():+ output += desktop_log.read_text()+ assert "WRONG_BACKEND_SELECTED" not in output, output+ assert child.poll() is None, output+ if "HERMES_BACKEND_READY port=" in output:+ assert f"existing Hermes CLI at {expected}" in output, output+ print("PASS: packaged desktop selected its pinned backend over the mutable install")+ break+ time.sleep(0.1)+ else:+ raise AssertionError(f"Desktop did not start its backend:\n{log_path.read_text()}")+ finally:+ os.killpg(child.pid, signal.SIGTERM)+ try:+ child.wait(timeout=15)+ except subprocess.TimeoutExpired:+ os.killpg(child.pid, signal.SIGKILL)+ child.wait(timeout=5)diff --git a/website/docs/reference/environment-variables.md b/website/docs/reference/environment-variables.mdindex c45dbeb280b..266f3a92d01 100644--- a/website/docs/reference/environment-variables.md+++ b/website/docs/reference/environment-variables.md@@ -570,7 +570,7 @@ Three dashboard-auth providers ship in the box. For a remote Hermes Desktop conn| `HERMES_DASHBOARD_OIDC_CLIENT_ID` | Public OIDC client id (authorization-code + PKCE) for the self-hosted OIDC provider. Required to activate it. Overrides `dashboard.oauth.self_hosted.client_id`. || `HERMES_DASHBOARD_OIDC_SCOPES` | Requested OIDC scopes for the self-hosted OIDC provider (default `openid profile email`). Overrides `dashboard.oauth.self_hosted.scopes`. || `HERMES_DESKTOP_REMOTE_URL` | (Desktop side) Base URL of the remote backend, e.g. `http://host:9119`. When set, overrides the in-app Gateway URL; you still sign in from the Gateway settings panel (OAuth redirect or username/password, whichever the backend advertises). |-| `HERMES_DESKTOP_HERMES` | Desktop backend command override. Used by packagers/Nix or troubleshooting to point Electron at a specific `hermes` executable after backend probing. |+| `HERMES_DESKTOP_HERMES` | Desktop backend command override. Used by packagers/Nix or troubleshooting to point Electron at a specific `hermes` executable before checking the mutable managed install. || `HERMES_DESKTOP_HERMES_ROOT` | Desktop source-checkout override used by `hermes desktop --hermes-root`; checked before the packaged first-launch install or an existing `hermes` on `PATH`. || `HERMES_DESKTOP_IGNORE_EXISTING` | Set to `1` to make Desktop ignore an existing `hermes` on `PATH` during backend resolution. Equivalent to `hermes desktop --ignore-existing`. || `HERMES_DESKTOP_CWD` | Initial project directory for Desktop chat sessions. Set by `hermes desktop --cwd`. |diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.mdindex e7e83726be1..ab8cf3341ed 100644--- a/website/docs/user-guide/desktop.md+++ b/website/docs/user-guide/desktop.md@@ -341,7 +341,7 @@ A missing entry is still created; the flag only stops `hermes desktop` from rewr## How it works-The packaged app ships the Electron shell and a native React chat surface. On first launch it can install the Hermes Agent runtime into `HERMES_HOME` (`~/.hermes`, or `%LOCALAPPDATA%\hermes` on Windows) — **the same layout a CLI install uses**, which is why the two are interchangeable. Backend resolution first honours `HERMES_DESKTOP_HERMES_ROOT`, then a completed managed install, then a probed `hermes` on `PATH` (unless `--ignore-existing` / `HERMES_DESKTOP_IGNORE_EXISTING=1` is set), and finally an explicit `HERMES_DESKTOP_HERMES` command override for packagers such as Nix. The React renderer talks to a headless backend the app launches for you — a `hermes serve` process that serves the `tui_gateway` JSON-RPC/WebSocket API — and reuses the agent runtime rather than embedding `hermes --tui`. The desktop app is **self-contained**: it runs its own `hermes serve` backend and never opens or requires the [web dashboard](./features/web-dashboard.md). (Runtimes older than the `serve` command fall back to a headless `dashboard --no-open` automatically, so an app update never outruns its backend.) Install, backend-resolution, and self-update logic live in the Electron main process.+The packaged app ships the Electron shell and a native React chat surface. On first launch it can install the Hermes Agent runtime into `HERMES_HOME` (`~/.hermes`, or `%LOCALAPPDATA%\hermes` on Windows) — **the same layout a CLI install uses**, which is why the two are interchangeable. Bundled apps use their included backend. Without a bundled backend, resolution honours `HERMES_DESKTOP_HERMES_ROOT`, then the development checkout, then an explicit `HERMES_DESKTOP_HERMES` command override for packagers such as Nix, and finally a usable managed install. The command override takes precedence over the managed install so a Nix desktop cannot silently launch an older mutable runtime. The React renderer talks to a headless backend the app launches for you — a `hermes serve` process that serves the `tui_gateway` JSON-RPC/WebSocket API — and reuses the agent runtime rather than embedding `hermes --tui`. The desktop app is **self-contained**: it runs its own `hermes serve` backend and never opens or requires the [web dashboard](./features/web-dashboard.md). (Runtimes older than the `serve` command fall back to a headless `dashboard --no-open` automatically, so an app update never outruns its backend.) Install, backend-resolution, and self-update logic live in the Electron main process.## Connecting to a remote backend