The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): uninstall never removes an AppImage it inherited APPIMAGE from
Teknium3b5c6eaf4f2c
diff --git a/apps/desktop/electron/desktop-uninstall.test.ts b/apps/desktop/electron/desktop-uninstall.test.tsindex f58bf402290..22e3224dad1 100644--- a/apps/desktop/electron/desktop-uninstall.test.ts+++ b/apps/desktop/electron/desktop-uninstall.test.ts@@ -155,6 +155,15 @@ test('resolveRemovableAppPath uses APPIMAGE on Linux when set', () => {)})+// AppImage apps (terminals, IDEs) export APPIMAGE to everything they start;+// uninstalling an unpacked Hermes launched from one must never rm -rf that app.+test('resolveRemovableAppPath ignores an APPIMAGE inherited from another AppImage', () => {+ assert.equal(+ resolveRemovableAppPath('/opt/hermes/linux-unpacked/hermes', 'linux', { APPIMAGE: '/home/x/Apps/Other.AppImage' }),+ '/opt/hermes/linux-unpacked'+ )+})+test('resolveRemovableAppPath finds the unpacked dir on Linux', () => {assert.equal(resolveRemovableAppPath('/opt/hermes/linux-unpacked/hermes', 'linux', {}), '/opt/hermes/linux-unpacked')// A system-package install (/usr/bin) → null, left to apt/dnf.diff --git a/apps/desktop/electron/desktop-uninstall.ts b/apps/desktop/electron/desktop-uninstall.tsindex 9fb9051a5e7..f06e0be08e3 100644--- a/apps/desktop/electron/desktop-uninstall.ts+++ b/apps/desktop/electron/desktop-uninstall.ts@@ -28,6 +28,7 @@import path from 'node:path'import type { InstallStamp } from './install-stamp'+import { ownAppImage } from './relaunch-target'export interface UninstallSummaryDetails {hermes_home: string@@ -263,7 +264,7 @@ function modeRemovesUserData(mode: string) {** macOS: …/Hermes.app/Contents/MacOS/Hermes → …/Hermes.app* Windows: …\Hermes\Hermes.exe → …\Hermes (install dir)- * Linux: AppImage → the APPIMAGE env path; unpacked → the *-unpacked dir+ * Linux: AppImage → APPIMAGE when we run from it; unpacked → the *-unpacked dir** Returns null when we can't confidently identify a removable bundle (e.g.* running from a dev checkout, or a system-package install we must not rmtree).@@ -304,9 +305,12 @@ function resolveRemovableAppPath(execPath, platform, env: any = {}) {return null}- // Linux: an AppImage exposes its own path via the APPIMAGE env var.- if (env.APPIMAGE) {- return env.APPIMAGE+ // Linux: an AppImage exposes its own path via APPIMAGE, but only trust it+ // when this executable runs from that image (it leaks from AppImage parents).+ const appImage = ownAppImage(exe, env)++ if (appImage) {+ return appImage}// Unpacked electron-builder tree: …/linux-unpacked/hermesdiff --git a/apps/desktop/electron/linux-sandbox-relaunch.test.ts b/apps/desktop/electron/linux-sandbox-relaunch.test.tsindex 04fd3f0f628..2cadea7a7df 100644--- a/apps/desktop/electron/linux-sandbox-relaunch.test.ts+++ b/apps/desktop/electron/linux-sandbox-relaunch.test.ts@@ -108,6 +108,21 @@ describe('Linux runtime --no-sandbox relaunch', () => {expect(relaunch).toEqual({ args: ['--no-sandbox'], execPath: '/home/u/Apps/Hermes.AppImage' })})+ // The type-2 runtime mounts under $TMPDIR/.mount_<name><random>; a launch that+ // lost APPDIR still runs from that mount, so APPIMAGE is still ours.+ it('relaunches the AppImage when only APPIMAGE survives but this runs from its mount', () => {+ const relaunch = linuxNoSandboxRelaunch({+ platform: 'linux',+ runtimeNoSandbox: true,+ argv: ['/run/user/1000/.mount_HermesQ7x2Lp/hermes'],+ execPath: '/run/user/1000/.mount_HermesQ7x2Lp/hermes',+ env: { APPIMAGE: '/home/u/Apps/Hermes.AppImage' },+ launchedWithoutSandbox: false+ })++ expect(relaunch).toEqual({ args: ['--no-sandbox'], execPath: '/home/u/Apps/Hermes.AppImage' })+ })+// AppImage apps (terminals, IDEs) export APPIMAGE/APPDIR to everything they// start; Hermes launched from one must relaunch itself, not that app.it('relaunches this executable when APPIMAGE was inherited from another AppImage', () => {diff --git a/apps/desktop/electron/relaunch-target.ts b/apps/desktop/electron/relaunch-target.tsindex 446e84e6321..d429ce5501b 100644--- a/apps/desktop/electron/relaunch-target.ts+++ b/apps/desktop/electron/relaunch-target.ts@@ -1,27 +1,47 @@import path from 'node:path'+// AppImage is Linux-only; POSIX semantics keep the answer identical on every test host.+const posix = path.posix+/**- * The executable that starts this app again, or undefined for Electron's- * default (process.execPath).+ * The AppImage file this executable runs from, or undefined when it is not one.*- * A real AppImage runs from a FUSE mount (APPDIR) that disappears when this- * process exits, so it relaunches the image file ($APPIMAGE) instead. The- * AppImage runtime exports APPIMAGE/APPDIR to every descendant, though: Hermes- * started from a terminal or IDE AppImage inherits that app's pair, and- * relaunching it would start the other app while Hermes never comes back. The- * pair is ours only when this executable lives inside APPDIR.+ * The AppImage runtime exports APPIMAGE/APPDIR to every descendant: Hermes+ * started from a terminal or IDE AppImage inherits that app's values, and+ * acting on them would relaunch, or rm -rf on uninstall, the other app.+ * APPIMAGE is ours only when this executable runs from that image's mount:+ * - inside APPDIR when it is set (the FUSE mount, or the+ * `appimage_extracted_<hash>` dir of --appimage-extract-and-run);+ * - otherwise inside a type-2 runtime mount, `$TMPDIR/.mount_<name><random>`+ * (AppImage/type2-runtime src/runtime/runtime.c build_mount_point():+ * "%s/.mount_%.*sXXXXXX", then mkdtemp).*/-export function relaunchExecPath(- execPath: string = process.execPath,- env: NodeJS.ProcessEnv = process.env-): string | undefined {+export function ownAppImage(execPath: string, env: NodeJS.ProcessEnv): string | undefined {const { APPDIR: appDir, APPIMAGE: appImage } = env- if (!appImage || !appDir) {+ if (!appImage || !execPath) {return undefined}- const inside = path.relative(path.resolve(appDir), path.resolve(execPath))+ const exe = posix.resolve(execPath)++ if (!appDir) {+ return posix.dirname(exe).split('/').some(segment => segment.startsWith('.mount_')) ? appImage : undefined+ }++ const inside = posix.relative(posix.resolve(appDir), exe)- return inside && !inside.startsWith('..') && !path.isAbsolute(inside) ? appImage : undefined+ return inside && !inside.startsWith('..') && !posix.isAbsolute(inside) ? appImage : undefined+}++/**+ * The executable that starts this app again, or undefined for Electron's+ * default (process.execPath). A real AppImage runs from a mount that+ * disappears when this process exits, so it relaunches the image file instead.+ */+export function relaunchExecPath(+ execPath: string = process.execPath,+ env: NodeJS.ProcessEnv = process.env+): string | undefined {+ return ownAppImage(execPath, env)}