The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): load a desktop half from unified agent-plugin packages
Brooklyn Nicholson4c1365b6c405
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 583c102e3ab..9cd3a13a179 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -11699,13 +11699,13 @@ ipcMain.handle('hermes:fs:openDir', async (_event, dirPath) => {// it yields `undefined/desktop-plugins` (or a non-existent remote path) and the// on-disk plugin door silently breaks (#66899). Electron owns this resolution// so it stays valid in every connection mode. Created on demand, like openDir.-ipcMain.handle('hermes:fs:desktopPluginsRoot', async () => {+async function localPluginsRoot(dirName: string): Promise<string> {// Profile-aware: a named Desktop profile gets its own plugin root under// profiles/<name>/, matching the profile-scoped hermes_home the backend// reported before this resolver existed. 'default'/unset pins the global root.const profile = readActiveDesktopProfile()const base = profile && profile !== 'default' ? path.join(HERMES_HOME, 'profiles', profile) : HERMES_HOME- const dir = path.join(base, 'desktop-plugins')+ const dir = path.join(base, dirName)try {await fs.promises.mkdir(dir, { recursive: true })@@ -11715,7 +11715,16 @@ ipcMain.handle('hermes:fs:desktopPluginsRoot', async () => {}return dir-})+}++ipcMain.handle('hermes:fs:desktopPluginsRoot', async () => localPluginsRoot('desktop-plugins'))++// The LOCAL agent-plugin root (`<HERMES_HOME>/plugins`), same Electron-local+// resolution as above. This is the desktop half of a UNIFIED plugin package:+// an agent plugin may ship `desktop/plugin.js` alongside its Python code (the+// same shape as `dashboard/manifest.json`), and the renderer's disk door scans+// this root for it — one installable folder serving both SDKs.+ipcMain.handle('hermes:fs:agentPluginsRoot', async () => localPluginsRoot('plugins'))// 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 candiff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.tsindex 0231ecf33e6..ffa8ffa7e00 100644--- a/apps/desktop/electron/preload.ts+++ b/apps/desktop/electron/preload.ts@@ -207,6 +207,7 @@ contextBridge.exposeInMainWorld('hermesDesktop', {revealPath: targetPath => ipcRenderer.invoke('hermes:fs:reveal', targetPath),openDir: dirPath => ipcRenderer.invoke('hermes:fs:openDir', dirPath),desktopPluginsRoot: () => ipcRenderer.invoke('hermes:fs:desktopPluginsRoot'),+ agentPluginsRoot: () => ipcRenderer.invoke('hermes:fs:agentPluginsRoot'),renamePath: (targetPath, newName) => ipcRenderer.invoke('hermes:fs:rename', targetPath, newName),writeTextFile: (filePath, content) => ipcRenderer.invoke('hermes:fs:writeText', filePath, content),trashPath: targetPath => ipcRenderer.invoke('hermes:fs:trash', targetPath),diff --git a/apps/desktop/src/contrib/plugins.ts b/apps/desktop/src/contrib/plugins.tsindex 6349880e3ed..adeb06c2aae 100644--- a/apps/desktop/src/contrib/plugins.ts+++ b/apps/desktop/src/contrib/plugins.ts@@ -5,8 +5,9 @@* `HermesPlugin` registers automatically (vite glob — drop a folder in).* None ship in-tree today; reference/demo plugins live in the companion* `hermes-example-plugins` repo.- * - RUNTIME: the on-disk door (`<hermes home>/desktop-plugins/<name>/plugin.js`)- * — the agent's/user's door, watched + hot-reloaded by the runtime loader.+ * - RUNTIME: the on-disk doors (`<hermes home>/desktop-plugins/<name>/plugin.js`+ * and the unified-package half `<hermes home>/plugins/<name>/desktop/plugin.js`)+ * — the agent's/user's doors, watched + hot-reloaded by the runtime loader.*/import { createPluginContext, type HermesPlugin } from './plugin'diff --git a/apps/desktop/src/contrib/runtime-loader.test.ts b/apps/desktop/src/contrib/runtime-loader.test.tsindex cc1d4336c2d..7c89a52640b 100644--- a/apps/desktop/src/contrib/runtime-loader.test.ts+++ b/apps/desktop/src/contrib/runtime-loader.test.ts@@ -15,21 +15,30 @@ vi.mock('@/hermes', async importActual => ({}))const desktopPluginsRoot = vi.fn<() => Promise<string>>()+const agentPluginsRoot = vi.fn<() => Promise<string>>()const readDir = vi.fn<(path: string) => Promise<HermesReadDirResult>>()+const readFileText = vi.fn<(path: string) => Promise<{ text: string }>>()const watchDirectory = vi.fn<(path: string) => Promise<{ id: string }>>()+const watchPreviewFile = vi.fn<(path: string) => Promise<{ id: string }>>()const onPreviewFileChanged = vi.fn()beforeEach(() => {desktopPluginsRoot.mockReset()+ agentPluginsRoot.mockReset()readDir.mockReset()+ readFileText.mockReset()watchDirectory.mockReset()+ watchPreviewFile.mockReset()onPreviewFileChanged.mockReset()getStatus.mockClear();(window as unknown as { hermesDesktop: unknown }).hermesDesktop = {+ agentPluginsRoot,desktopPluginsRoot,onPreviewFileChanged,readDir,- watchDirectory+ readFileText,+ watchDirectory,+ watchPreviewFile}})@@ -38,39 +47,73 @@ afterEach(() => {})describe('scanDiskPlugins (#66899)', () => {- it('scans the Electron-resolved local root, never the backend hermes_home', async () => {+ it('scans the Electron-resolved local roots, never the backend hermes_home', async () => {desktopPluginsRoot.mockResolvedValue('/local/.hermes/desktop-plugins')+ agentPluginsRoot.mockResolvedValue('/local/.hermes/plugins')readDir.mockResolvedValue({ entries: [] })await discoverRuntimePlugins()expect(desktopPluginsRoot).toHaveBeenCalled()expect(readDir).toHaveBeenCalledWith('/local/.hermes/desktop-plugins')+ expect(readDir).toHaveBeenCalledWith('/local/.hermes/plugins')// The remote backend's hermes_home must never feed the local plugin scan.expect(getStatus).not.toHaveBeenCalled()expect(readDir).not.toHaveBeenCalledWith('/remote/box/.hermes/desktop-plugins')})- it('no-ops when the resolver yields no local root', async () => {+ it('no-ops when the resolvers yield no local root', async () => {desktopPluginsRoot.mockResolvedValue('')+ agentPluginsRoot.mockResolvedValue('')await discoverRuntimePlugins()expect(readDir).not.toHaveBeenCalled()})++ it('probes desktop/plugin.js inside agent-plugin packages (unified packaging)', async () => {+ desktopPluginsRoot.mockResolvedValue('/local/.hermes/desktop-plugins')+ agentPluginsRoot.mockResolvedValue('/local/.hermes/plugins')+ readDir.mockImplementation(async dir =>+ dir === '/local/.hermes/plugins'+ ? { entries: [{ isDirectory: true, name: 'my-feature', path: '/local/.hermes/plugins/my-feature' }] }+ : { entries: [] }+ )+ // No desktop half in this package — probe must target desktop/plugin.js.+ readFileText.mockRejectedValue(new Error('ENOENT'))++ await discoverRuntimePlugins()++ expect(readFileText).toHaveBeenCalledWith('/local/.hermes/plugins/my-feature/desktop/plugin.js')+ // The Python half's files must never be probed as a desktop entry.+ expect(readFileText).not.toHaveBeenCalledWith('/local/.hermes/plugins/my-feature/plugin.js')+ })++ it('still scans the standalone root when agentPluginsRoot is absent (older shell)', async () => {+ delete (window.hermesDesktop as unknown as { agentPluginsRoot?: unknown }).agentPluginsRoot+ desktopPluginsRoot.mockResolvedValue('/local/.hermes/desktop-plugins')+ readDir.mockResolvedValue({ entries: [] })++ await discoverRuntimePlugins()++ expect(readDir).toHaveBeenCalledWith('/local/.hermes/desktop-plugins')+ expect(readDir).toHaveBeenCalledTimes(1)+ })})describe('watchRuntimePlugins dir watch (#66899)', () => {- it('watches the Electron-resolved local root, never the backend hermes_home', async () => {+ it('watches both Electron-resolved local roots, never the backend hermes_home', async () => {desktopPluginsRoot.mockResolvedValue('/local/.hermes/desktop-plugins')+ agentPluginsRoot.mockResolvedValue('/local/.hermes/plugins')readDir.mockResolvedValue({ entries: [] })watchDirectory.mockResolvedValue({ id: 'watch-1' })watchRuntimePlugins()- // Drain the async scan + startDirWatch chains.- await vi.waitFor(() => expect(watchDirectory).toHaveBeenCalled())+ // Drain the async scan + startDirWatches chains.+ await vi.waitFor(() => expect(watchDirectory).toHaveBeenCalledTimes(2))expect(watchDirectory).toHaveBeenCalledWith('/local/.hermes/desktop-plugins')+ expect(watchDirectory).toHaveBeenCalledWith('/local/.hermes/plugins')expect(watchDirectory).not.toHaveBeenCalledWith('/remote/box/.hermes/desktop-plugins')expect(getStatus).not.toHaveBeenCalled()})diff --git a/apps/desktop/src/contrib/runtime-loader.ts b/apps/desktop/src/contrib/runtime-loader.tsindex 1fc5458a3a5..4680148a2ec 100644--- a/apps/desktop/src/contrib/runtime-loader.ts+++ b/apps/desktop/src/contrib/runtime-loader.ts@@ -11,8 +11,9 @@* broken plugin can never take the app down.** Sources today: the in-repo runtime example (`?raw`, proves the pipeline)- * and `<hermes home>/desktop-plugins/<name>/plugin.js` on disk — the door the- * agent writes through.+ * and the two on-disk doors — `<hermes home>/desktop-plugins/<name>/plugin.js`+ * and the unified agent-plugin half `<hermes home>/plugins/<name>/desktop/+ * plugin.js` — the doors the agent writes through.** SECURITY — this is NOT a capability boundary. A loaded plugin is evaluated* as ESM in the renderer realm with FULL app authority: the React singleton,@@ -179,13 +180,19 @@ export async function loadRuntimePlugin(}// ----------------------------------------------------------------------------// The on-disk plugin door: `<hermes home>/desktop-plugins/<name>/plugin.js`-// (agent- or user-written). SELF-MAINTAINING — no reload ceremony:+// The on-disk plugin door — TWO roots, one pipeline:+// - `<hermes home>/desktop-plugins/<name>/plugin.js` — the standalone door+// (agent- or user-written desktop-only plugins);+// - `<hermes home>/plugins/<name>/desktop/plugin.js` — the desktop HALF of a+// unified agent-plugin package: the same installed folder that carries the+// Python plugin (plugin.yaml / plugin.json) ships its desktop UI beside it,+// so one feature is ONE install instead of two co-dependent plugins.+// SELF-MAINTAINING — no reload ceremony:// - each plugin.js is fs-watched (the preview watcher IPC, debounced in// main): saving the file hot-reloads the plugin in place;-// - the directory itself is fs-watched too (watchDirectory IPC), so new-// folders load + removed ones unload on the change tick; older Electron-// shells without watchDirectory fall back to the slow visible-tab poll.+// - each root is fs-watched too (watchDirectory IPC), so new folders load ++// removed ones unload on the change tick; older Electron shells without+// watchDirectory fall back to the slow visible-tab poll.// Panes land via placement adoption and STAY where the user drags them —// the tree treats not-yet-loaded pane ids as hidden, so boot and reload are// collapse -> appear, never a placeholder flash.@@ -193,25 +200,60 @@ export async function loadRuntimePlugin(const DISK_POLL_MS = 5_000+interface DiskRoot {+ dir: string+ /** Resolve a scanned folder to its candidate plugin entry file. */+ entry: (folderPath: string) => string+}++/** Both scan roots, resolved fresh each pass (Electron-local, never the+ * backend's hermes_home — #66899). `agentPluginsRoot` is optional: older+ * shells predate it and the unified-package half simply doesn't scan. */+async function diskRoots(): Promise<DiskRoot[]> {+ const desktop = window.hermesDesktop++ if (!desktop) {+ return []+ }++ const roots: DiskRoot[] = []+ const standalone = await desktop.desktopPluginsRoot?.()++ if (standalone) {+ roots.push({ dir: standalone, entry: folder => `${folder}/plugin.js` })+ }++ const unified = await desktop.agentPluginsRoot?.()++ if (unified) {+ roots.push({ dir: unified, entry: folder => `${folder}/desktop/plugin.js` })+ }++ return roots+}+interface DiskPlugin {file: string/** Loaded plugin id (null while broken — kept so a fixing save reloads). */id: null | string+ /** Origin label (folder name) — the toast/inventory name for load errors. */+ origin: stringwatchId: null | string}+/** Live disk plugins keyed by ENTRY FILE path — unique across both roots+ * (folder names alone can collide between them). */const disk = new Map<string, DiskPlugin>()let watching = falselet scanning = false-async function loadDiskPlugin(name: string, file: string): Promise<void> {+async function loadDiskPlugin(entry: DiskPlugin): Promise<void> {const desktop = window.hermesDesktop!- const entry = disk.get(name)- const prevId = entry?.id+ const prevId = entry.idtry {- const { text } = await desktop.readFileText(file)- const id = await loadRuntimePlugin(text, name, { file })+ const { text } = await desktop.readFileText(entry.file)+ const id = await loadRuntimePlugin(text, entry.origin, { file: entry.file })// A hot-edit that changes `plugin.id`: loadRuntimePlugin only disposes the// NEW id, so unload the previous incarnation here or its contributions +@@ -221,14 +263,12 @@ async function loadDiskPlugin(name: string, file: string): Promise<void> {dropPlugin(prevId)}- if (entry) {- entry.id = id ?? entry.id- }+ entry.id = id ?? entry.id// A fixing save under a different plugin id — drop the folder-named// error record so the inventory shows one row, not a ghost.- if (id && id !== name) {- dropPlugin(name)+ if (id && id !== entry.origin) {+ dropPlugin(entry.origin)}} catch {// File vanished mid-read — the next scan reconciles.@@ -247,48 +287,53 @@ async function scanDiskPlugins(): Promise<void> {scanning = truetry {- // The plugin root is a LOCAL Electron path, resolved independently of the- // connected backend — a remote backend's hermes_home is a remote path and- // yields `undefined/desktop-plugins` here (#66899).- const root = await desktop.desktopPluginsRoot?.()+ const roots = await diskRoots()- if (!root) {+ if (roots.length === 0) {return}- const { entries } = await desktop.readDir(root)const seen = new Set<string>()- for (const dir of entries.filter(e => e.isDirectory)) {- seen.add(dir.name)-- if (disk.has(dir.name)) {- continue- }-- const file = `${dir.path}/plugin.js`+ for (const root of roots) {+ let entriestry {- await desktop.readFileText(file)+ ;({ entries } = await desktop.readDir(root.dir))} catch {- continue // No plugin.js (yet) — not a plugin folder.+ continue // Root missing (no plugins yet) — the poll/watch reconciles.}- const record: DiskPlugin = { file, id: null, watchId: null }- disk.set(dir.name, record)- await loadDiskPlugin(dir.name, file)-- try {- record.watchId = (await desktop.watchPreviewFile(file)).id- } catch {- // Unwatchable — the poll still reconciles new folders; edits need a- // manual "Reload desktop plugins".+ for (const dir of entries.filter(e => e.isDirectory)) {+ const file = root.entry(dir.path)+ seen.add(file)++ if (disk.has(file)) {+ continue+ }++ try {+ await desktop.readFileText(file)+ } catch {+ continue // No entry file (yet) — not a plugin folder for this root.+ }++ const record: DiskPlugin = { file, id: null, origin: dir.name, watchId: null }+ disk.set(file, record)+ await loadDiskPlugin(record)++ try {+ record.watchId = (await desktop.watchPreviewFile(file)).id+ } catch {+ // Unwatchable — the poll still reconciles new folders; edits need a+ // manual "Reload desktop plugins".+ }}}// Folder deleted -> plugin gone, cleanly (inventory row included).- for (const [name, record] of disk) {- if (seen.has(name)) {+ for (const [file, record] of disk) {+ if (seen.has(file)) {continue}@@ -297,16 +342,16 @@ async function scanDiskPlugins(): Promise<void> {dropPlugin(record.id)}- dropPlugin(name)+ dropPlugin(record.origin)if (record.watchId) {void desktop.stopPreviewFileWatch(record.watchId)}- disk.delete(name)+ disk.delete(file)}} catch {- // No desktop-plugins dir (or no gateway yet) — nothing to reconcile.+ // No plugin roots (or no gateway yet) — nothing to reconcile.} finally {scanning = false}@@ -326,51 +371,60 @@ export function watchRuntimePlugins(): void {watching = true- let dirWatchId: null | string = null+ const dirWatchIds = new Set<string>()+ const watchedDirs = new Set<string>()desktop.onPreviewFileChanged(({ id }) => {// Directory tick: a plugin folder appeared or vanished — reconcile.- if (dirWatchId && id === dirWatchId) {+ if (dirWatchIds.has(id)) {void scanDiskPlugins()return}- for (const [name, record] of disk) {+ for (const record of disk.values()) {if (record.watchId === id) {- void loadDiskPlugin(name, record.file)+ void loadDiskPlugin(record)return}}})- const startDirWatch = async (): Promise<boolean> => {+ // True only when EVERY root is fs-watched — a partially watched set keeps+ // the poll alive so unwatched roots still reconcile new/removed folders.+ const startDirWatches = async (): Promise<boolean> => {if (!desktop.watchDirectory) {return false}- try {- // Same Electron-local root as the scanner — never the backend's- // hermes_home, which is a remote path in remote mode (#66899).- const root = await desktop.desktopPluginsRoot?.()+ const roots = await diskRoots()- if (!root) {- return false- }+ if (roots.length === 0) {+ return false+ }- dirWatchId = (await desktop.watchDirectory(root)).id+ let all = true- return true- } catch {- // Dir missing (no plugins yet) or unwatchable — fall back to the poll,- // which also handles the dir being created later.- return false+ for (const root of roots) {+ if (watchedDirs.has(root.dir)) {+ continue+ }++ try {+ dirWatchIds.add((await desktop.watchDirectory(root.dir)).id)+ watchedDirs.add(root.dir)+ } catch {+ // Dir missing or unwatchable — the poll covers it and retries here.+ all = false+ }}++ return all}void scanDiskPlugins()- void startDirWatch().then(watched => {+ void startDirWatches().then(watched => {if (watched) {return}@@ -382,15 +436,13 @@ export function watchRuntimePlugins(): void {void scanDiskPlugins()- // The dir may have been created since — upgrade to the watch and retire- // this poll once it lands.- if (dirWatchId === null) {- void startDirWatch().then(upgraded => {- if (upgraded) {- window.clearInterval(timer)- }- })- }+ // A root may have appeared since — upgrade to the watches and retire+ // this poll once every root is covered.+ void startDirWatches().then(upgraded => {+ if (upgraded) {+ window.clearInterval(timer)+ }+ })}, DISK_POLL_MS)})}diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.tsindex f2470634c2f..13e2b8dba5a 100644--- a/apps/desktop/src/global.d.ts+++ b/apps/desktop/src/global.d.ts@@ -215,6 +215,11 @@ declare global {// resolved by Electron independently of the connected backend (#66899).// Created on demand; returns the normalized absolute path.desktopPluginsRoot?: () => Promise<string>+ // Local AGENT-plugin root (<HERMES_HOME>/plugins), same Electron-local+ // resolution. The disk door also scans it for `<name>/desktop/plugin.js`+ // so one agent-plugin package can ship a desktop UI half. Optional:+ // older Electron shells predate it — the scanner then skips this root.+ agentPluginsRoot?: () => Promise<string>// Rename a file/folder in place (new base name, same parent dir).renamePath?: (path: string, newName: string) => Promise<{ path: string }>// Write a small UTF-8 text file (hardened path, parent must exist).