The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): PluginOs gains native save/open file pickers
Brooklyn Nicholsonc57f8ad4e151
diff --git a/apps/desktop/src/contrib/plugin.test.ts b/apps/desktop/src/contrib/plugin.test.tsindex 9f522fe7038..8210f212d1a 100644--- a/apps/desktop/src/contrib/plugin.test.ts+++ b/apps/desktop/src/contrib/plugin.test.ts@@ -38,6 +38,48 @@ describe('createPluginContext.os', () => {await expect(ctx.os.openExternal('https://example.com')).resolves.toBe(false)await expect(ctx.os.revealPath('/tmp')).resolves.toBe(false)await expect(ctx.os.writeClipboard('hi')).resolves.toBe(false)+ // The pickers answer with a path, so their "unavailable" is null.+ await expect(ctx.os.pickSavePath()).resolves.toBeNull()+ await expect(ctx.os.pickOpenPath()).resolves.toBeNull()+ })++ it('file pickers return the chosen path, and null on cancel', async () => {+ const bridge = {+ selectPaths: vi.fn().mockResolvedValue(['/tmp/board.tar.gz']),+ selectSavePath: vi.fn().mockResolvedValue('/tmp/out.tar.gz')+ }++ ;(window as unknown as { hermesDesktop: unknown }).hermesDesktop = bridge++ try {+ const ctx = createPluginContext('demo')++ await expect(ctx.os.pickSavePath({ title: 'Save' })).resolves.toBe('/tmp/out.tar.gz')+ expect(bridge.selectSavePath).toHaveBeenCalledWith({ title: 'Save' })++ await expect(ctx.os.pickOpenPath({ title: 'Open' })).resolves.toBe('/tmp/board.tar.gz')+ expect(bridge.selectPaths).toHaveBeenCalledWith({ multiple: false, title: 'Open' })++ // Cancel: the save dialog resolves null, the open dialog an empty list.+ bridge.selectSavePath.mockResolvedValue(null)+ bridge.selectPaths.mockResolvedValue([])+ await expect(ctx.os.pickSavePath()).resolves.toBeNull()+ await expect(ctx.os.pickOpenPath()).resolves.toBeNull()+ } finally {+ delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop+ }+ })++ it('file pickers degrade to null on an older shell that lacks them', async () => {+ ;(window as unknown as { hermesDesktop: unknown }).hermesDesktop = {}++ try {+ const ctx = createPluginContext('demo')+ await expect(ctx.os.pickSavePath()).resolves.toBeNull()+ await expect(ctx.os.pickOpenPath()).resolves.toBeNull()+ } finally {+ delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop+ }})it('routes through the bridge and turns a bridge throw into false', async () => {diff --git a/apps/desktop/src/contrib/plugin.ts b/apps/desktop/src/contrib/plugin.tsindex dc2a9bbf8a8..6e7c793e772 100644--- a/apps/desktop/src/contrib/plugin.ts+++ b/apps/desktop/src/contrib/plugin.ts@@ -55,10 +55,23 @@ export interface PluginOs {/** Reveal a path in the OS file manager (Finder / Explorer). Resolves* false when unavailable. */revealPath: (path: string) => Promise<boolean>+ /** Native save dialog. Resolves the chosen path, or null on cancel /+ * when unavailable. The path is on the BACKEND's filesystem, so hand it+ * to a `rest` call rather than trying to write it from the renderer. */+ pickSavePath: (options?: PluginFileDialogOptions) => Promise<null | string>+ /** Native open dialog, single file. Resolves the chosen path, or null on+ * cancel / when unavailable. */+ pickOpenPath: (options?: PluginFileDialogOptions) => Promise<null | string>/** Write text to the system clipboard. Resolves false when unavailable. */writeClipboard: (text: string) => Promise<boolean>}+export interface PluginFileDialogOptions {+ defaultPath?: string+ filters?: Array<{ extensions: string[]; name: string }>+ title?: string+}+export interface PluginContext {/** The resolved plugin source tag, e.g. `'plugin:cost-meter'`. */readonly source: string@@ -146,6 +159,21 @@ function createPluginOs(pluginId: string): PluginOs {}}+ // Same shape as `attempt`, for the pickers that answer with a path.+ const attemptPath = async (run: (bridge: NonNullable<typeof window.hermesDesktop>) => Promise<null | string>) => {+ const bridge = typeof window === 'undefined' ? undefined : window.hermesDesktop++ if (!bridge) {+ return null+ }++ try {+ return await run(bridge)+ } catch {+ return null+ }+ }+return {notify: input => dispatchPluginNativeNotification(pluginId, input),openExternal: url =>@@ -154,6 +182,13 @@ function createPluginOs(pluginId: string): PluginOs {return true}),+ pickOpenPath: options =>+ attemptPath(async bridge => {+ const picked = await bridge.selectPaths?.({ ...options, multiple: false })++ return picked?.[0] ?? null+ }),+ pickSavePath: options => attemptPath(async bridge => (await bridge.selectSavePath?.(options)) ?? null),revealPath: path => attempt(async bridge => (bridge.revealPath ? bridge.revealPath(path) : false)),writeClipboard: text => attempt(bridge => bridge.writeClipboard(text))}