Skip to content

The agent that grows with you

fix(desktop): expand a literal ~ in HERMES_HOME before resolving the backend home

teknium1235622a98dac
diff --git a/apps/desktop/electron/backend-env.test.ts b/apps/desktop/electron/backend-env.test.ts
index 986f164f9e1..74571692f22 100644
--- a/apps/desktop/electron/backend-env.test.ts
+++ b/apps/desktop/electron/backend-env.test.ts
@@ -147,6 +147,22 @@ test('buildDesktopBackendEnv forces PYTHONUTF8 unless the user set it explicitly
assert.equal(optedOut.PYTHONUTF8, '0')
})
+test('normalizeHermesHomeRoot expands a literal leading ~ against the home directory, not cwd', () => {
+ assert.equal(
+ normalizeHermesHomeRoot('~/.hermes', { pathModule: path.posix, homedir: '/Users/test' }),
+ '/Users/test/.hermes'
+ )
+ assert.equal(
+ normalizeHermesHomeRoot('~/.hermes/profiles/oracle', { pathModule: path.posix, homedir: '/Users/test' }),
+ '/Users/test/.hermes'
+ )
+ assert.equal(
+ normalizeHermesHomeRoot('~\\.hermes', { pathModule: path.win32, homedir: 'C:\\Users\\test' }),
+ 'C:\\Users\\test\\.hermes'
+ )
+ assert.equal(normalizeHermesHomeRoot('~', { pathModule: path.posix, homedir: '/Users/test' }), '/Users/test')
+})
+
test('normalizeHermesHomeRoot maps profile homes back to the global Hermes root', () => {
assert.equal(
normalizeHermesHomeRoot('/Users/test/.hermes/profiles/oracle', { pathModule: path.posix }),
diff --git a/apps/desktop/electron/backend-env.ts b/apps/desktop/electron/backend-env.ts
index 24d6928bad0..f3fd8c81975 100644
--- a/apps/desktop/electron/backend-env.ts
+++ b/apps/desktop/electron/backend-env.ts
@@ -1,3 +1,4 @@
+import os from 'node:os'
import path from 'node:path'
// Match the POSIX fallback surface used by the Python terminal environment.
@@ -103,12 +104,23 @@ function buildDesktopBackendPath({
return appendUniquePathEntries([hermesNodeDirs, venvBin, currentPath, saneEntries], { delimiter })
}
-function normalizeHermesHomeRoot(hermesHome, { pathModule = pathModuleForPlatform(process.platform) }: any = {}) {
+function normalizeHermesHomeRoot(
+ hermesHome,
+ { pathModule = pathModuleForPlatform(process.platform), homedir = os.homedir() }: any = {}
+) {
if (!hermesHome) {
return hermesHome
}
- const resolved = pathModule.resolve(String(hermesHome))
+ // fish (and any shell when the value is quoted) hands a literal `~` through; path.resolve()
+ // would pin it under cwd and the Python backend inherits that absolute path via HERMES_HOME.
+ let raw = String(hermesHome)
+
+ if (raw === '~' || raw.startsWith('~/') || (pathModule === path.win32 && raw.startsWith('~\\'))) {
+ raw = pathModule.join(homedir, raw.slice(1))
+ }
+
+ const resolved = pathModule.resolve(raw)
const parent = pathModule.dirname(resolved)
if (pathModule.basename(parent).toLowerCase() === 'profiles') {
diff --git a/tests/gateway/test_process_hermes_home_expansion.py b/tests/gateway/test_process_hermes_home_expansion.py
new file mode 100644
index 00000000000..02ad50ada23
--- /dev/null
+++ b/tests/gateway/test_process_hermes_home_expansion.py
@@ -0,0 +1,28 @@
+"""Gateway identity-file readers expand a literal ``~`` in HERMES_HOME.
+
+``python -m gateway.run`` never passes through the CLI's ``normalize_hermes_home_env()``, so the
+process-level home readers (PID/lock/status, lifecycle ledger, heartbeat) must expand on their own
+or a fish-style ``HERMES_HOME='~/.hermes'`` lands the identity files under ``<cwd>/~/.hermes``.
+"""
+
+from pathlib import Path
+
+import pytest
+
+from gateway import lifecycle_ledger, shutdown_watchdog, status
+
+
+ "reader",
+ [status._get_process_hermes_home, lifecycle_ledger._process_hermes_home,
+ shutdown_watchdog._process_hermes_home],
+ ids=["status", "lifecycle_ledger", "shutdown_watchdog"],
+)
+def test_process_home_readers_expand_literal_tilde(reader, tmp_path, monkeypatch):
+ monkeypatch.setenv("HOME", str(tmp_path))
+ monkeypatch.setenv("USERPROFILE", str(tmp_path))
+ monkeypatch.setenv("HERMES_HOME", "~/.x")
+ assert reader() == tmp_path / ".x"
+ assert reader().is_absolute()
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".abs"))
+ assert reader() == Path(tmp_path / ".abs")