Skip to content

The agent that grows with you

fix(desktop): carry the launcher-reported root on override command backends

liuhao1024735dcd6f4600
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 74265e1edef..b5657008574 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -609,6 +609,7 @@ import {
type UpdaterStrategy
} from './updater'
import {
+ launcherInstallDirectory,
observeUpdaterHandoff,
repairMacUpdaterHelper,
resolveInstallationLauncher,
@@ -5005,6 +5006,19 @@ function writeDefaultProjectDir(dir) {
const installedRuntimeGate = createInstalledRuntimeGate(process.env, rememberLog)
+// resolveHermesBackend runs once per surface (startup, TUI resume, config
+// refresh, pool backends), and a launcher's install directory cannot move
+// while this process lives, so probe each launcher path at most once.
+const launcherInstallRoots = new Map<string, string | undefined>()
+
+function launcherInstallRoot(launcher: string): string | undefined {
+ if (!launcherInstallRoots.has(launcher)) {
+ launcherInstallRoots.set(launcher, launcherInstallDirectory(launcher) ?? undefined)
+ }
+
+ return launcherInstallRoots.get(launcher)
+}
+
async function resolveHermesBackend(backendArgs: string[]): Promise<ResolvedHermesBackend> {
const payload = bundledPayload(process.resourcesPath)
@@ -5103,7 +5117,12 @@ async function resolveHermesBackend(backendArgs: string[]): Promise<ResolvedHerm
env: {},
kind: 'command',
shell: shellForProbe,
- local: 'installed'
+ local: 'installed',
+ // ticketRuntimeFor() mints gateway tickets only from a python
+ // backend or a command backend that names its installation root
+ // (launcher probe cwd + PYTHONPATH), so pin the root the launcher
+ // itself reports (#138774).
+ root: launcherInstallRoot(hermesCommand)
}
}
diff --git a/apps/desktop/electron/updater-process.test.ts b/apps/desktop/electron/updater-process.test.ts
index 00aeaf57be3..7f6b3201a8b 100644
--- a/apps/desktop/electron/updater-process.test.ts
+++ b/apps/desktop/electron/updater-process.test.ts
@@ -1,5 +1,7 @@
import assert from 'node:assert/strict'
import type { SpawnOptions } from 'node:child_process'
+import fs from 'node:fs/promises'
+import os from 'node:os'
import path from 'node:path'
import { test } from 'vitest'
@@ -7,6 +9,7 @@ import { test } from 'vitest'
import {
collectRelaunchArgs,
describeUpdaterHandoffFailure,
+ launcherInstallDirectory,
MARKER_SELF_ADOPT_EPOCH_MS,
observeUpdaterHandoff,
resolvePosixScriptHandoff,
@@ -477,3 +480,33 @@ test('observeUpdaterHandoff settles ok for children without an event interface',
assert.equal(outcome.ok, true)
})
+
+test.skipIf(process.platform === 'win32')('launcherInstallDirectory returns the root the launcher reports', async () => {
+ const dir = await realpathMkdtemp('launcher-install-')
+ const reported = await fs.realpath(await fs.mkdir(path.join(dir, 'hermes-agent')).then(() => path.join(dir, 'hermes-agent')))
+ const launcher = await writeLauncher(dir, `printf 'Hermes Agent v0.22.1\\nInstall directory: ${reported}\\n'`)
+
+ assert.equal(launcherInstallDirectory(launcher), reported)
+})
+
+test.skipIf(process.platform === 'win32')('launcherInstallDirectory stays null when the launcher reports nothing', async () => {
+ const dir = await realpathMkdtemp('launcher-install-')
+
+ for (const body of ["printf 'Hermes Agent v0.22.1\\n'", 'exit 3']) {
+ const launcher = await writeLauncher(dir, body)
+
+ assert.equal(launcherInstallDirectory(launcher), null)
+ }
+})
+
+async function realpathMkdtemp(prefix: string): Promise<string> {
+ return fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), prefix)))
+}
+
+/** A POSIX script stands in for the installation launcher's --version boundary. */
+async function writeLauncher(dir: string, body: string): Promise<string> {
+ const file = path.join(dir, 'hermes')
+ await fs.writeFile(file, `#!/bin/sh\n${body}\n`, { mode: 0o755 })
+
+ return file
+}
diff --git a/apps/desktop/electron/updater-process.ts b/apps/desktop/electron/updater-process.ts
index f80a0406c54..7a6e11d5352 100644
--- a/apps/desktop/electron/updater-process.ts
+++ b/apps/desktop/electron/updater-process.ts
@@ -113,7 +113,7 @@ export function launcherTargetsInstallation(launcher: string, root: string): boo
}
/** The real install directory a launcher's `--version` reports, or null. */
-function launcherInstallDirectory(launcher: string, root?: string): string | null {
+export function launcherInstallDirectory(launcher: string, root?: string): string | null {
try {
// Node refuses to exec a .cmd directly (CVE-2024-27980), and `shell:true`
// would hand an interpolated path to cmd.exe wholesale. Invoke cmd.exe