Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop): keep main preload self-contained

Josuée109e12a55ba
diff --git a/desktop-app/src/__tests__/desktopCommands.test.ts b/desktop-app/src/__tests__/desktopCommands.test.ts
index 39cd0d6ef..fba1430c7 100644
--- a/desktop-app/src/__tests__/desktopCommands.test.ts
+++ b/desktop-app/src/__tests__/desktopCommands.test.ts
@@ -1,4 +1,7 @@
import { describe, expect, it } from 'vitest'
+import { promises as fs } from 'node:fs'
+import path from 'node:path'
+import ts from 'typescript'
import {
DESKTOP_COMMANDS,
type DesktopShortcutInput,
@@ -24,6 +27,24 @@ function input(overrides: Partial<DesktopShortcutInput> = {}): DesktopShortcutIn
}
describe('Desktop command registry', () => {
+ it('keeps the sandboxed main preload self-contained and synchronized with command IDs', async () => {
+ const source = await fs.readFile(path.join(process.cwd(), 'src', 'preload.ts'), 'utf8')
+ const syntax = ts.createSourceFile('preload.ts', source, ts.ScriptTarget.Latest, false)
+ const relativeValueImports = syntax.statements
+ .filter(ts.isImportDeclaration)
+ .filter(statement => {
+ const specifier = ts.isStringLiteral(statement.moduleSpecifier)
+ ? statement.moduleSpecifier.text
+ : ''
+ return specifier.startsWith('.') && !statement.importClause?.isTypeOnly
+ })
+ .map(statement => statement.getText(syntax))
+ expect(relativeValueImports).toEqual([])
+ for (const command of DESKTOP_COMMANDS) {
+ expect(source, `preload is missing ${command.id}`).toContain(`'${command.id}'`)
+ }
+ })
+
it('has unique stable IDs and no binding collisions within a source', () => {
expect(new Set(DESKTOP_COMMANDS.map(command => command.id)).size).toBe(DESKTOP_COMMANDS.length)
for (const platform of ['darwin', 'win32'] as const) {
diff --git a/desktop-app/src/preload.ts b/desktop-app/src/preload.ts
index fa14b14d4..0738f32ba 100644
--- a/desktop-app/src/preload.ts
+++ b/desktop-app/src/preload.ts
@@ -1,9 +1,5 @@
import { contextBridge, ipcRenderer } from 'electron'
-import {
- type DesktopCommandId,
- type DesktopCommandSource,
- isDesktopCommandId,
-} from './desktopCommands.js'
+import type { DesktopCommandId, DesktopCommandSource } from './desktopCommands.js'
import type { PluginConsentRequest } from './pluginSdkProtocol.js'
import type {
HostMessageRequest,
@@ -11,6 +7,34 @@ import type {
SandboxUiDeepLinkEnvelope,
} from './types.js'
+// Sandboxed Electron preloads cannot load relative runtime modules. Keep this
+// allowlist self-contained and pin it to the authoritative registry in
+// desktopCommands.test.ts, matching the existing sandbox embed-preload pattern.
+const DESKTOP_COMMAND_IDS = new Set<DesktopCommandId>([
+ 'chat.newTab',
+ 'chat.closeTab',
+ 'tabs.select1',
+ 'tabs.select2',
+ 'tabs.select3',
+ 'tabs.select4',
+ 'tabs.select5',
+ 'tabs.select6',
+ 'tabs.select7',
+ 'tabs.select8',
+ 'tabs.selectLast',
+ 'tabs.next',
+ 'tabs.previous',
+ 'search.open',
+ 'search.current',
+ 'composer.focus',
+ 'commands.open',
+ 'settings.shortcuts',
+])
+
+function isDesktopCommandId(value: unknown): value is DesktopCommandId {
+ return typeof value === 'string' && DESKTOP_COMMAND_IDS.has(value as DesktopCommandId)
+}
+
const clerum = Object.freeze({
shortcuts: {
onCommand: (callback: (commandId: DesktopCommandId, source: DesktopCommandSource) => void) => {