feat(desktop): Uninstall for standalone desktop plugins via Electron IPC

Rows whose only half is a folder in <HERMES_HOME>/desktop-plugins (no agent
package behind it) get the same trash button + destructive confirm as the
agent rows. The renderer names the FOLDER, never a path; Electron
(`hermes:plugin:removeDesktop` -> desktop-plugin-remove.ts) resolves it under
the app-level root, refuses anything that is not a single contained segment,
refuses unified-package halves (the reconcile would re-copy them; the agent
uninstall prunes them), removes a symlinked folder as the link, and deletes
the tree. The loader then retires the entry (unload, drop rows, stop watch)
so the pane/commands vanish without waiting for the next scan.

Why an IPC: these plugins have no agent half, so `plugins.manage remove` on
the gateway cannot reach them — they live on this computer, in every
connection mode.
This commit is contained in:
teknium1 authored and Teknium committed 2026-09-21 00:09:50 -07:00
1 parent 43fe9c1773
commit dec236b214
13 files changed
+403 -18

No files matched your search

@@ -0,0 +1,81 @@
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { removeDesktopPlugin } from './desktop-plugin-remove'
import { PACKAGE_MARKER } from './desktop-plugins-root'
const homes: string[] = []
function makeRoot(): { home: string; root: string } {
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-dp-remove-'))
homes.push(home)
const root = path.join(home, 'desktop-plugins')
fs.mkdirSync(root, { recursive: true })
return { home, root }
}
function write(file: string, text: string) {
fs.mkdirSync(path.dirname(file), { recursive: true })
fs.writeFileSync(file, text)
}
afterEach(() => {
for (const home of homes.splice(0)) {
fs.rmSync(home, { force: true, recursive: true })
}
})
describe('removeDesktopPlugin', () => {
it('deletes exactly the named standalone folder under the root and leaves its neighbours', async () => {
const { root } = makeRoot()
write(path.join(root, 'hello', 'plugin.js'), 'export default {}')
write(path.join(root, 'hello', 'assets', 'icon.svg'), '<svg/>')
write(path.join(root, 'other', 'plugin.js'), 'export default {}')
const result = await removeDesktopPlugin(root, 'hello')
expect(result).toEqual({ ok: true, path: path.join(root, 'hello') })
expect(fs.existsSync(path.join(root, 'hello'))).toBe(false)
expect(fs.existsSync(path.join(root, 'other', 'plugin.js'))).toBe(true)
})
it('refuses anything that is not a single folder name inside the root, deleting nothing', async () => {
const { home, root } = makeRoot()
write(path.join(home, 'config.yaml'), 'model: x')
write(path.join(root, 'hello', 'plugin.js'), 'export default {}')
for (const name of ['../config.yaml', '..', '.', '', 'hello/plugin.js', `..${path.sep}config.yaml`, path.join(root, 'hello')]) {
const result = await removeDesktopPlugin(root, name)
expect(result.ok, name).toBe(false)
}
expect(fs.existsSync(path.join(home, 'config.yaml'))).toBe(true)
expect(fs.existsSync(path.join(root, 'hello', 'plugin.js'))).toBe(true)
})
it('refuses a unified package half (marker present) and a missing folder', async () => {
const { root } = makeRoot()
write(path.join(root, 'uni', 'plugin.js'), 'export default {}')
write(path.join(root, 'uni', PACKAGE_MARKER), JSON.stringify({ package: 'uni', source: '/x' }))
expect((await removeDesktopPlugin(root, 'uni')).ok).toBe(false)
expect(fs.existsSync(path.join(root, 'uni', 'plugin.js'))).toBe(true)
expect((await removeDesktopPlugin(root, 'ghost')).ok).toBe(false)
})
it('removes a symlinked plugin folder as the link, never following it', async () => {
const { home, root } = makeRoot()
const real = path.join(home, 'elsewhere')
write(path.join(real, 'plugin.js'), 'export default {}')
fs.symlinkSync(real, path.join(root, 'linked'), 'dir')
expect((await removeDesktopPlugin(root, 'linked')).ok).toBe(true)
expect(fs.existsSync(path.join(root, 'linked'))).toBe(false)
expect(fs.existsSync(path.join(real, 'plugin.js'))).toBe(true)
})
})
@@ -0,0 +1,60 @@
// Uninstall of a STANDALONE desktop plugin: delete one folder directly under
// the app-level `<HERMES_HOME>/desktop-plugins` root. The renderer names the
// folder, never a path — containment is by construction (single segment) and
// re-checked after resolution so nothing outside the root can be addressed.
//
// A unified package's desktop half (folder carrying `.hermes-package.json`) is
// refused here: the reconcile re-copies it from `plugins/<name>/desktop` on
// the next pass while the agent package exists, so deleting the copy would
// only make it flicker. That half goes away with `plugins.manage remove`.
import fs from 'node:fs'
import path from 'node:path'
import { PACKAGE_MARKER } from './desktop-plugins-root'
export interface RemoveDesktopPluginResult {
ok: boolean
error?: string
/** The folder that was deleted (on success). */
path?: string
}
export async function removeDesktopPlugin(appRoot: string, rawName: unknown): Promise<RemoveDesktopPluginResult> {
const name = String(rawName ?? '').trim()
if (!name || name === '.' || name === '..' || /[\\/]/.test(name)) {
return { ok: false, error: 'invalid plugin folder name' }
}
const root = path.resolve(appRoot)
const target = path.resolve(root, name)
if (path.relative(root, target) !== name) {
return { ok: false, error: `${name} is not inside the desktop-plugins folder` }
}
let stat: fs.Stats
try {
// lstat: a symlinked folder is removed as the LINK, never by following it.
stat = await fs.promises.lstat(target)
} catch {
return { ok: false, error: `${name} is not installed` }
}
if (!stat.isDirectory() && !stat.isSymbolicLink()) {
return { ok: false, error: `${name} is not a plugin folder` }
}
if (stat.isDirectory() && fs.existsSync(path.join(target, PACKAGE_MARKER))) {
return { ok: false, error: `${name} is the desktop half of an agent plugin — uninstall that plugin instead` }
}
try {
await fs.promises.rm(target, { force: true, recursive: true })
} catch (error) {
return { ok: false, error: error instanceof Error ? error.message : String(error) }
}
return { ok: true, path: target }
}
+7
View File
@@ -8,6 +8,7 @@ import path from 'node:path'
import { ipcMain, shell } from 'electron'
import { installDesktopPluginFromGit, probePluginRepo } from './desktop-plugin-install'
import { removeDesktopPlugin } from './desktop-plugin-remove'
import {
DESKTOP_PLUGINS_DIR,
ensureDir,
@@ -160,6 +161,12 @@ export function registerFsIpc({
)
})
// Uninstall a standalone desktop plugin by FOLDER NAME under the app-level
// root. The renderer never passes a path; containment is re-checked inside.
ipcMain.handle('hermes:plugin:removeDesktop', async (_event, payload) =>
removeDesktopPlugin(path.join(hermesHome, DESKTOP_PLUGINS_DIR), payload?.name)
)
// Rename a file/folder in place. The renderer passes the existing path + a new
// base name; the destination is resolved in the SAME parent dir so a rename can
// never move the item elsewhere or traverse out. Rejects on a name collision.
+1
View File
@@ -487,6 +487,7 @@ contextBridge.exposeInMainWorld('hermesDesktop', {
signalDeepLinkReady: () => ipcRenderer.invoke('hermes:deep-link-ready'),
probePluginRepo: payload => ipcRenderer.invoke('hermes:plugin:probe', payload),
installDesktopPlugin: payload => ipcRenderer.invoke('hermes:plugin:installDesktop', payload),
removeDesktopPlugin: payload => ipcRenderer.invoke('hermes:plugin:removeDesktop', payload),
onWindowStateChanged: callback => {
const listener = (_event, payload) => callback(payload)
ipcRenderer.on('hermes:window-state-changed', listener)
@@ -26,6 +26,13 @@ vi.mock('@/app/gateway/hooks/use-gateway-request', () => ({
useGatewayRequest: () => ({ requestGateway })
}))
const uninstallDiskPlugin = vi.fn(async (_id: string) => ({ ok: true }))
vi.mock('@/contrib/runtime-loader', async importOriginal => ({
...(await importOriginal<Record<string, unknown>>()),
uninstallDiskPlugin: (id: string) => uninstallDiskPlugin(id)
}))
describe('PluginsTab', () => {
beforeEach(() => {
$pluginRecords.set({})
@@ -423,6 +430,39 @@ describe('PluginsTab catalog UX', () => {
await waitFor(() => expect(screen.queryByText('demo-weather')).toBeNull())
})
it('uninstalls a standalone desktop plugin through Electron only after the confirm dialog is accepted', async () => {
$pluginRecords.set({
clock: { id: 'clock', name: 'Clock', kind: 'disk', status: 'loaded', file: '/h/desktop-plugins/clock/plugin.js' }
})
uninstallDiskPlugin.mockClear()
render(<PluginsTab profile={null} />)
screen.getByRole('button', { name: 'Uninstall: Clock' }).click()
await waitFor(() => expect($confirmRequest.get()?.title).toBe('Uninstall Clock?'))
expect(uninstallDiskPlugin).not.toHaveBeenCalled()
settleConfirm(true)
await waitFor(() => expect(uninstallDiskPlugin).toHaveBeenCalledWith('clock'))
// Nothing goes over the gateway: this half lives in this app, not the profile.
expect(requestGateway).not.toHaveBeenCalledWith('plugins.manage', expect.objectContaining({ action: 'remove' }))
})
it('offers no desktop Uninstall for a bundled plugin or a unified package half', () => {
$pluginRecords.set({
bots: { id: 'bots', name: 'Bot Mode', kind: 'bundled', status: 'loaded' },
media: { id: 'media', name: 'Media Studio', kind: 'disk', status: 'loaded', packageName: 'hermes-media-studio' }
})
render(<PluginsTab profile={null} />)
expect(screen.getByText('Bot Mode')).toBeTruthy()
expect(screen.getByText('Media Studio')).toBeTruthy()
expect(screen.queryByRole('button', { name: /^Uninstall:/ })).toBeNull()
})
it('offers no Uninstall for a pip-installed (entrypoint) agent plugin', () => {
$agentPlugins.set([
{ description: '', key: 'demo-tool', name: 'demo-tool', source: 'entrypoint', status: 'enabled', version: '' }
@@ -15,7 +15,7 @@ import { Codicon } from '@/components/ui/codicon'
import { Switch } from '@/components/ui/switch'
import { Tip } from '@/components/ui/tooltip'
import { $pluginRecords, type PluginRecord, setPluginEnabled } from '@/contrib/plugins-store'
import { discoverRuntimePlugins } from '@/contrib/runtime-loader'
import { discoverRuntimePlugins, uninstallDiskPlugin } from '@/contrib/runtime-loader'
import type { ProfileScope } from '@/hermes'
import { useI18n } from '@/i18n'
import { triggerHaptic } from '@/lib/haptics'
@@ -225,7 +225,8 @@ function PackageRow({
busy,
onAgentToggle,
onAgentUpdate,
onAgentRemove
onAgentRemove,
onDesktopRemove
}: {
pkg: PluginPackage
scope: null | string
@@ -234,6 +235,7 @@ function PackageRow({
onAgentToggle: (row: AgentPluginRow, enable: boolean) => void
onAgentUpdate: (row: AgentPluginRow) => void
onAgentRemove: (row: AgentPluginRow) => void
onDesktopRemove: (record: PluginRecord) => void
}) {
const { t } = useI18n()
const p = t.skills.plugins
@@ -247,6 +249,10 @@ function PackageRow({
// was cloned there) can be uninstalled here: bundled plugins are refused by
// the backend and entrypoint (pip-installed) ones go with their package.
const agentRemovable = agent?.source === 'user' || agent?.source === 'git'
// A STANDALONE desktop plugin (a folder in <HERMES_HOME>/desktop-plugins with
// no agent package behind it) is deleted by Electron. A unified package's
// desktop half is not offered here: uninstalling the agent half prunes it.
const desktopRemovable = desktop?.kind === 'disk' && !desktop.packageName && !agent
// Electron's desktop-half reconcile only walks THIS machine's homes, so a
// package installed on a remote backend can never materialize here (#114079).
const remoteBackend = useStore($connection)?.mode === 'remote'
@@ -291,9 +297,10 @@ function PackageRow({
)}
</span>
{/* Same fixed-slot treatment for Uninstall: present on every row so the
halves line up, populated only when the agent half is a user install. */}
halves line up, populated when the agent half is a user install or
the row is a standalone desktop plugin. */}
<span className="flex size-7 shrink-0 items-center justify-center">
{agent && agentRemovable && (
{agent && agentRemovable ? (
<Tip label={p.uninstallTip(pkg.name, scopeLabel)}>
<Button
aria-label={`${p.uninstall}: ${pkg.name}`}
@@ -306,7 +313,19 @@ function PackageRow({
<Trash2 className="size-3.5" />
</Button>
</Tip>
)}
) : desktop && desktopRemovable ? (
<Tip label={p.uninstallDesktopTip(pkg.name)}>
<Button
aria-label={`${p.uninstall}: ${pkg.name}`}
className="text-(--ui-text-tertiary) hover:text-(--ui-danger,#f87171)"
onClick={() => onDesktopRemove(desktop)}
size="icon"
variant="ghost"
>
<Trash2 className="size-3.5" />
</Button>
</Tip>
) : null}
</span>
</div>
@@ -624,6 +643,26 @@ export const PluginsTab = memo(function PluginsTab({
}
})
}}
onDesktopRemove={record => {
void confirm({
confirmLabel: p.uninstall,
description: p.uninstallDesktopConfirmBody(record.name),
destructive: true,
title: p.uninstallConfirmTitle(record.name)
}).then(async ok => {
if (!ok) {
return
}
const result = await uninstallDiskPlugin(record.id)
if (result.ok) {
notify({ kind: 'success', message: p.uninstalledDesktop(record.name) })
} else {
notifyError(result.error, p.uninstallFailed(record.name))
}
})
}}
pkg={pkg}
scope={scope}
scopeLabel={label}
+104 -1
View File
@@ -5,7 +5,13 @@ import type * as HermesModule from '@/hermes'
import { emitGatewayEvent } from './events'
import { $pluginRecords, publishPlugin, setPluginEnabled } from './plugins-store'
import { discoverRuntimePlugins, loadRuntimePlugin, unloadRuntimePlugin, watchRuntimePlugins } from './runtime-loader'
import {
discoverRuntimePlugins,
loadRuntimePlugin,
uninstallDiskPlugin,
unloadRuntimePlugin,
watchRuntimePlugins
} from './runtime-loader'
// getStatus would supply the connected backend's hermes_home — a REMOTE path in
// remote mode. The disk scanner must NOT derive the plugin root from it (#66899).
@@ -385,6 +391,103 @@ describe('plugin source reads (512 KiB preview-cap bug)', () => {
})
})
describe('uninstallDiskPlugin (Plugins hub trash button)', () => {
const removeDesktopPlugin = vi.fn<(payload: { name: string }) => Promise<{ ok: boolean; error?: string }>>()
const blobToDataUrl = () => {
const createObjectURL = vi
.spyOn(URL, 'createObjectURL')
.mockImplementation(
blob =>
`data:text/javascript;base64,${Buffer.from((blob as unknown as { parts: string[] }).parts.join('')).toString('base64')}`
)
const revokeObjectURL = vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => undefined)
const RealBlob = globalThis.Blob
vi.stubGlobal(
'Blob',
class {
parts: string[]
constructor(parts: string[]) {
this.parts = parts
}
}
)
return () => {
createObjectURL.mockRestore()
revokeObjectURL.mockRestore()
vi.stubGlobal('Blob', RealBlob)
}
}
/** One standalone folder `gone-soon` at the root, loaded as plugin id `gone`. */
const seedStandalone = async () => {
const root = '/local/.hermes/desktop-plugins'
desktopPluginsRoot.mockResolvedValue(root)
readDir.mockImplementation(async dir => {
if (dir === root) {
return { entries: [{ isDirectory: true, name: 'gone-soon', path: `${root}/gone-soon` }] }
}
if (dir === `${root}/gone-soon`) {
return { entries: [{ isDirectory: false, name: 'plugin.js', path: `${root}/gone-soon/plugin.js` }] }
}
return { entries: [] }
})
readFileText.mockResolvedValue({ text: 'export default { id: "gone", register() {} }' })
watchPreviewFile.mockResolvedValue({ id: 'w-gone' })
removeDesktopPlugin.mockReset()
;(window.hermesDesktop as unknown as { removeDesktopPlugin: unknown }).removeDesktopPlugin = removeDesktopPlugin
await discoverRuntimePlugins()
expect($pluginRecords.get().gone).toMatchObject({ kind: 'disk', status: 'loaded' })
}
it('asks Electron to delete the FOLDER by name, then retires the registration and its watch', async () => {
const restore = blobToDataUrl()
try {
await seedStandalone()
removeDesktopPlugin.mockResolvedValue({ ok: true })
expect(await uninstallDiskPlugin('gone')).toEqual({ ok: true })
// The folder name, never a path — Electron resolves it under the root.
expect(removeDesktopPlugin).toHaveBeenCalledWith({ name: 'gone-soon' })
expect($pluginRecords.get().gone).toBeUndefined()
expect(stopPreviewFileWatch).toHaveBeenCalledWith('w-gone')
} finally {
restore()
unloadRuntimePlugin('gone')
}
})
it('keeps the plugin loaded and reports the reason when Electron refuses', async () => {
const restore = blobToDataUrl()
try {
await seedStandalone()
removeDesktopPlugin.mockResolvedValue({ ok: false, error: 'gone-soon is not inside the desktop-plugins folder' })
expect(await uninstallDiskPlugin('gone')).toEqual({
ok: false,
error: 'gone-soon is not inside the desktop-plugins folder'
})
expect($pluginRecords.get().gone).toMatchObject({ kind: 'disk', status: 'loaded' })
// Unknown ids never reach the bridge.
expect(await uninstallDiskPlugin('never-installed')).toMatchObject({ ok: false })
expect(removeDesktopPlugin).toHaveBeenCalledTimes(1)
} finally {
restore()
removeDesktopPlugin.mockResolvedValue({ ok: true })
await uninstallDiskPlugin('gone')
}
})
})
describe('bundled-shadowed disk copies', () => {
it('skips a disk copy of a bundled plugin but publishes a visible inventory row', async () => {
// The bundled twin is already registered (build-time glob).
+48 -12
View File
@@ -676,18 +676,7 @@ async function scanDiskPlugins(): Promise<void> {
continue
}
if (record.id) {
unloadRuntimePlugin(record.id)
dropPlugin(record.id)
}
dropOriginRecord(record.origin, record)
if (record.watchId) {
void desktop.stopPreviewFileWatch(record.watchId)
}
disk.delete(file)
retireDiskPlugin(file, record)
}
} catch {
// No plugin roots (or no gateway yet) — nothing to reconcile.
@@ -696,6 +685,53 @@ async function scanDiskPlugins(): Promise<void> {
}
}
/** Forget a disk entry whose folder is gone: unload its registration, drop
* its inventory rows, stop its file watch. */
function retireDiskPlugin(file: string, record: DiskPlugin): void {
if (record.id) {
unloadRuntimePlugin(record.id)
dropPlugin(record.id)
}
dropOriginRecord(record.origin, record)
if (record.watchId) {
void window.hermesDesktop?.stopPreviewFileWatch(record.watchId)
}
disk.delete(file)
}
/** Uninstall a STANDALONE disk plugin (Capabilities → Plugins trash button):
* Electron deletes `<root>/<folder>` (containment enforced there), then the
* entry is retired here so the pane/commands vanish without waiting for the
* next scan. Unified-package halves are not addressable this way — the agent
* uninstall prunes them. Resolves with the failure reason instead of throwing. */
export async function uninstallDiskPlugin(pluginId: string): Promise<{ ok: boolean; error?: string }> {
const found = [...disk.entries()].find(([, record]) => record.id === pluginId || record.origin === pluginId)
if (!found) {
return { ok: false, error: 'not an installed desktop plugin' }
}
const [file, record] = found
const remove = window.hermesDesktop?.removeDesktopPlugin
if (!remove) {
return { ok: false, error: 'this Hermes Desktop build cannot remove desktop plugins — delete the folder by hand' }
}
const result = await remove({ name: record.origin })
if (!result?.ok) {
return { ok: false, error: result?.error ?? 'unknown error' }
}
retireDiskPlugin(file, record)
return { ok: true }
}
/** Manual rescan (the ⌘K "Reload desktop plugins" fallback). */
export const discoverRuntimePlugins = scanDiskPlugins
+3
View File
@@ -543,6 +543,9 @@ declare global {
repo?: string
force?: boolean
}) => Promise<{ ok: boolean; pluginName?: string; path?: string; error?: string }>
/** Delete a STANDALONE desktop plugin folder (`<desktop-plugins root>/<name>`);
* Electron re-checks containment and refuses unified-package halves. */
removeDesktopPlugin?: (payload: { name: string }) => Promise<{ ok: boolean; path?: string; error?: string }>
onWindowStateChanged?: (callback: (payload: HermesWindowState) => void) => () => void
onFocusSession?: (callback: (sessionId: string) => void) => () => void
onNotificationAction?: (callback: (payload: { actionId: string; sessionId?: string }) => void) => () => void
+4
View File
@@ -1856,6 +1856,10 @@ export const en: Translations = {
`This deletes the plugin's files from the ${profile} profile. Any desktop half it shipped is removed with it. Reinstall it from the catalog or from Git at any time.`,
uninstallFailed: (name: string) => `Could not uninstall ${name}`,
uninstalled: (name: string) => `${name} uninstalled. Restart the gateway to unload it.`,
uninstallDesktopTip: (name: string) => `Uninstall ${name} from this app`,
uninstallDesktopConfirmBody: (name: string) =>
`This deletes ${name} from the desktop-plugins folder on this computer and unloads it now. Reinstall it from Git or drop the folder back at any time.`,
uninstalledDesktop: (name: string) => `${name} uninstalled.`,
deepLinkErrorTitle: 'Plugin install link rejected',
deepLinkCatalogInvalidName: 'The link\u2019s catalog name is missing or invalid.',
deepLinkCatalogUnknown: (name: string) =>
+3
View File
@@ -1596,6 +1596,9 @@ export interface Translations {
uninstallConfirmBody: (name: string, profile: string) => string
uninstallFailed: (name: string) => string
uninstalled: (name: string) => string
uninstallDesktopTip: (name: string) => string
uninstallDesktopConfirmBody: (name: string) => string
uninstalledDesktop: (name: string) => string
deepLinkErrorTitle: string
deepLinkCatalogInvalidName: string
deepLinkCatalogUnknown: (name: string) => string
+4
View File
@@ -2029,6 +2029,10 @@ export const zh = defineLocale({
`这将从 ${profile} 配置中删除该插件的文件。它附带的桌面部分也会一并移除。之后可随时从目录或 Git 重新安装。`,
uninstallFailed: (name: string) => `无法卸载 ${name}`,
uninstalled: (name: string) => `${name} 已卸载。重启网关后完全卸载。`,
uninstallDesktopTip: (name: string) => `从本应用卸载 ${name}`,
uninstallDesktopConfirmBody: (name: string) =>
`这将从本机的 desktop-plugins 文件夹中删除 ${name} 并立即卸载。之后可随时从 Git 重新安装或将文件夹放回。`,
uninstalledDesktop: (name: string) => `${name} 已卸载。`,
deepLinkErrorTitle: '插件安装链接已拒绝',
deepLinkCatalogInvalidName: '链接中的目录名称缺失或无效。',
deepLinkCatalogUnknown: (name: string) => `“${name}”不在 Hermes 插件目录中。未安装任何内容。`,
+4
View File
@@ -539,6 +539,10 @@ Hermes: **one row per plugin**, with two switch columns.
package's desktop half. Restart the gateway to unload the plugin's code.
Repo-bundled and pip-installed (entrypoint) plugins have no trash button:
the first cannot be removed, the second goes with its Python package.
A standalone desktop plugin (a folder you dropped into
`~/.hermes/desktop-plugins/` with no agent package) gets the same trash
button; confirming deletes that folder on this computer and unloads the
plugin immediately, no gateway involved.
Discovery sits underneath: the live [Plugin Catalog](./features/plugin-catalog.md)
picker installs reviewed entries at their pinned commit into the selected