Skip to content

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

TypeScript

fix: address desktop deep-link review findings

Josué9b76bf2eb27f
diff --git a/.github/workflows/ci-public.yml b/.github/workflows/ci-public.yml
index ef2f6821e..4a8a8d9bf 100644
--- a/.github/workflows/ci-public.yml
+++ b/.github/workflows/ci-public.yml
@@ -60,6 +60,7 @@ jobs:
- workflow-approval-request-reader
- stdio-bridge
- external-rest-api
+ - profile-ui
- desktop-app
- mcp-servers
- packages/workflow-runtime-core
diff --git a/Makefile b/Makefile
index 664e38ecc..1f69fb365 100644
--- a/Makefile
+++ b/Makefile
@@ -41,6 +41,7 @@ SERVICES := \
webhook-proxy \
webhook-gateway \
stdio-bridge \
+ profile-ui \
desktop-app \
mcp-servers \
packages/workflow-runtime-core \
@@ -59,6 +60,7 @@ TEST_SERVICES := \
webhook-proxy \
webhook-gateway \
stdio-bridge \
+ profile-ui \
desktop-app \
mcp-servers \
packages/workflow-runtime-core \
diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.json
index 5021ed01a..b7363122b 100644
--- a/desktop-app/package-lock.json
+++ b/desktop-app/package-lock.json
@@ -1,14 +1,15 @@
{
"name": "evenfire",
- "version": "0.1.324",
+ "version": "0.1.325",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "evenfire",
- "version": "0.1.324",
+ "version": "0.1.325",
"license": "MPL-2.0",
"dependencies": {
+ "@clerum/desktop-app-links": "file:../packages/desktop-app-links",
"@tanstack/react-query": "5.100.10",
"js-yaml": "^4.1.1",
"keytar": "^7.9.0",
@@ -46,6 +47,10 @@
"wait-on": "^8.0.5"
}
},
+ "../packages/desktop-app-links": {
+ "name": "@clerum/desktop-app-links",
+ "version": "0.1.0"
+ },
"node_modules/@adobe/css-tools": {
"version": "4.4.4",
"resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.4.tgz",
@@ -397,6 +402,10 @@
"specificity": "bin/cli.js"
}
},
+ "node_modules/@clerum/desktop-app-links": {
+ "resolved": "../packages/desktop-app-links",
+ "link": true
+ },
"node_modules/@csstools/color-helpers": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-6.0.2.tgz",
diff --git a/desktop-app/package.json b/desktop-app/package.json
index 4e86e78c8..0b4731114 100644
--- a/desktop-app/package.json
+++ b/desktop-app/package.json
@@ -1,7 +1,7 @@
{
"name": "evenfire",
"productName": "Evenfire",
- "version": "0.1.324",
+ "version": "0.1.325",
"private": true,
"license": "MPL-2.0",
"description": "Evenfire desktop client for secure agent and workflow access",
@@ -42,6 +42,7 @@
"make:linux:arm64": "electron-forge make --platform=linux --arch=arm64"
},
"dependencies": {
+ "@clerum/desktop-app-links": "file:../packages/desktop-app-links",
"@tanstack/react-query": "5.100.10",
"js-yaml": "^4.1.1",
"keytar": "^7.9.0",
diff --git a/desktop-app/src/__tests__/appService.sandboxUiApps.test.ts b/desktop-app/src/__tests__/appService.sandboxUiApps.test.ts
index a2a100d7a..5db21e9d9 100644
--- a/desktop-app/src/__tests__/appService.sandboxUiApps.test.ts
+++ b/desktop-app/src/__tests__/appService.sandboxUiApps.test.ts
@@ -183,3 +183,26 @@ describe('AppService.openForgotPassword', () => {
})
})
})
+
+describe('AppService profile UI link authority', () => {
+ it('uses the authenticated invitation profile instead of guessing a tenant hostname', async () => {
+ const service = makeService() as unknown as {
+ me: { id: string; email: string }
+ memberRegistrationServiceClient: { getInvitationProfile: ReturnType<typeof vi.fn> }
+ resolveProfileUiBaseUrl: () => Promise<string>
+ }
+ service.me = { id: 'user-1', email: '[email protected]' }
+ service.memberRegistrationServiceClient = {
+ getInvitationProfile: vi.fn().mockResolvedValue({
+ profileUiBaseUrl: 'https://accounts.tenant.example/profile',
+ }),
+ }
+
+ await expect(service.resolveProfileUiBaseUrl()).resolves.toBe(
+ 'https://accounts.tenant.example/profile'
+ )
+ expect(service.memberRegistrationServiceClient.getInvitationProfile).toHaveBeenCalledWith(
+ )
+ })
+})
diff --git a/desktop-app/src/__tests__/protocolLaunchArgs.test.ts b/desktop-app/src/__tests__/protocolLaunchArgs.test.ts
index 5c4011f16..830b447b6 100644
--- a/desktop-app/src/__tests__/protocolLaunchArgs.test.ts
+++ b/desktop-app/src/__tests__/protocolLaunchArgs.test.ts
@@ -16,12 +16,17 @@ describe('collectInitialProtocolUrls', () => {
'Evenfire',
'evenfire://app/sandbox-recipes/task-board?path=%2Ftasks',
'clerum://oauth-completed?clientId=github&provider=github',
+ 'clerum://oauth-completed?clientId=slack&provider=slack',
+ 'clerum://oauth-completed?clientId=github&provider=github',
'--unrelated',
])
expect(result).toEqual({
evenfireUrls: ['evenfire://app/sandbox-recipes/task-board?path=%2Ftasks'],
- clerumUrl: 'clerum://oauth-completed?clientId=github&provider=github',
+ clerumUrls: [
+ 'clerum://oauth-completed?clientId=github&provider=github',
+ 'clerum://oauth-completed?clientId=slack&provider=slack',
+ ],
})
})
})
diff --git a/desktop-app/src/__tests__/sandboxUiDeepLinkQueue.test.ts b/desktop-app/src/__tests__/sandboxUiDeepLinkQueue.test.ts
new file mode 100644
index 000000000..3f0401b7c
--- /dev/null
+++ b/desktop-app/src/__tests__/sandboxUiDeepLinkQueue.test.ts
@@ -0,0 +1,29 @@
+import { describe, expect, it } from 'vitest'
+import { SandboxUiDeepLinkQueue } from '../sandboxUiDeepLinkQueue.js'
+
+describe('SandboxUiDeepLinkQueue', () => {
+ it('deduplicates semantic targets and acknowledges the matching envelope', () => {
+ const queue = new SandboxUiDeepLinkQueue()
+ const first = queue.enqueue({ appRef: 'ns/app', path: '/inbox', teamId: 'team-1' })
+ expect(first?.id).toBe(1)
+ expect(queue.enqueue({ appRef: 'ns/app', path: '/inbox', teamId: 'team-1' })).toBeNull()
+ queue.acknowledge(first!.id)
+ expect(queue.list()).toEqual([])
+ })
+
+ it('clears pending links when the authenticated identity changes', () => {
+ const queue = new SandboxUiDeepLinkQueue()
+ queue.enqueue({ appRef: 'ns/app' })
+ queue.clear()
+ expect(queue.list()).toEqual([])
+ expect(queue.enqueue({ appRef: 'ns/app' })?.id).toBe(2)
+ })
+
+ it('keeps the newest bounded set of links', () => {
+ const queue = new SandboxUiDeepLinkQueue(2)
+ queue.enqueue({ appRef: 'ns/one' })
+ queue.enqueue({ appRef: 'ns/two' })
+ queue.enqueue({ appRef: 'ns/three' })
+ expect(queue.list().map(item => item.appRef)).toEqual(['ns/two', 'ns/three'])
+ })
+})
diff --git a/desktop-app/src/__tests__/sandboxUiDeepLinks.test.ts b/desktop-app/src/__tests__/sandboxUiDeepLinks.test.ts
index 1e1e391fa..0a5cad45c 100644
--- a/desktop-app/src/__tests__/sandboxUiDeepLinks.test.ts
+++ b/desktop-app/src/__tests__/sandboxUiDeepLinks.test.ts
@@ -37,6 +37,26 @@ describe('sandbox UI deep links', () => {
)
})
+ it('preserves a profile UI base-path prefix', () => {
+ expect(
+ buildSandboxUiWebLink('https://tenant.example.com/profile/', {
+ recipeNs: 'sandbox-recipes',
+ recipeName: 'agentic-task-board',
+ })
+ ).toBe('https://tenant.example.com/profile/open/apps/sandbox-recipes/agentic-task-board')
+ })
+
+ it('keeps an omitted path optional so the recipe default route wins', () => {
+ const url = buildSandboxUiDeepLink({
+ recipeNs: 'sandbox-recipes',
+ recipeName: 'agentic-task-board',
+ })
+ expect(url).not.toContain('path=')
+ expect(parseSandboxUiDeepLink(url)).toEqual({
+ appRef: 'sandbox-recipes/agentic-task-board',
+ })
+ })
+
it('rejects a non-web handoff origin', () => {
expect(() =>
buildSandboxUiWebLink('javascript:alert(1)', {
@@ -63,6 +83,16 @@ describe('sandbox UI deep links', () => {
parseSandboxUiDeepLink('evenfire://app/sandbox-recipes/agentic-task-board?team=team%2Fother')
).toBeNull()
expect(parseSandboxUiDeepLink('https://example.com/app')).toBeNull()
+ expect(
+ parseSandboxUiDeepLink(
+ 'evenfire://app/sandbox-recipes/agentic-task-board?path=%2Fsafe%2F..%2Fadmin'
+ )
+ ).toBeNull()
+ expect(
+ parseSandboxUiDeepLink(
+ 'evenfire://app/sandbox-recipes/agentic-task-board?path=%2Fsafe%2F%252e%252e%2Fadmin'
+ )
+ ).toBeNull()
})
it('extracts the current route from the active embedded app URL', () => {
diff --git a/desktop-app/src/__tests__/sandboxUiDriver.test.ts b/desktop-app/src/__tests__/sandboxUiDriver.test.ts
index 37c3a22cc..0a1af9fd8 100644
--- a/desktop-app/src/__tests__/sandboxUiDriver.test.ts
+++ b/desktop-app/src/__tests__/sandboxUiDriver.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it, vi } from 'vitest'
import {
SANDBOX_UI_COOKIE_NAME,
applySandboxUiClientRoute,
+ canApplySandboxUiClientRoute,
extractSandboxUiCookie,
extractSandboxUiPath,
partitionFor,
@@ -36,6 +37,40 @@ describe('applySandboxUiClientRoute', () => {
})
})
+describe('canApplySandboxUiClientRoute', () => {
+ const expectedUrl = 'https://rpc.example/api/v1/sandbox-ui/ns/app/view/'
+
+ it('waits through a 503 interstitial before handing off the client route', () => {
+ expect(
+ canApplySandboxUiClientRoute({
+ expectedUrl,
+ currentUrl: expectedUrl,
+ navigatedUrl: expectedUrl,
+ httpResponseCode: 503,
+ })
+ ).toBe(false)
+ })
+
+ it('accepts only a successful load of the expected server route', () => {
+ expect(
+ canApplySandboxUiClientRoute({
+ expectedUrl,
+ currentUrl: expectedUrl,
+ navigatedUrl: expectedUrl,
+ httpResponseCode: 200,
+ })
+ ).toBe(true)
+ expect(
+ canApplySandboxUiClientRoute({
+ expectedUrl,
+ currentUrl: `${expectedUrl}unexpected`,
+ navigatedUrl: expectedUrl,
+ httpResponseCode: 200,
+ })
+ ).toBe(false)
+ })
+})
+
describe('partitionFor', () => {
it('produces a stable persist:sandbox-ui partition name per (env, recipe)', () => {
expect(partitionFor('env1', 'sandbox-recipes', 'r1')).toBe(
diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.ts
index f5cd42c3d..792f47097 100644
--- a/desktop-app/src/appService.ts
+++ b/desktop-app/src/appService.ts
@@ -693,16 +693,7 @@ export class AppService {
options: ProfileSettingsOpenOptions = {}
): Promise<{ profileUiUrl: string }> {
const normalizedEmail = email.trim().toLowerCase()
- let profileUiBaseUrl = config.desktopProfileUiBaseUrl
- if (normalizedEmail) {
- try {
- const activation =
- await this.memberRegistrationServiceClient.getInvitationProfile(normalizedEmail)
- profileUiBaseUrl = activation.profileUiBaseUrl
- } catch {
- profileUiBaseUrl = config.desktopProfileUiBaseUrl
- }
- }
+ const profileUiBaseUrl = await this.resolveProfileUiBaseUrl(normalizedEmail)
const network = String(options.network || '')
.trim()
@@ -718,6 +709,20 @@ export class AppService {
return { profileUiUrl: profileUiUrl.toString() }
}
+ private async resolveProfileUiBaseUrl(email?: string): Promise<string> {
+ const normalizedEmail = String(email || this.me?.email || '')
+ .trim()
+ .toLowerCase()
+ if (!normalizedEmail) return config.desktopProfileUiBaseUrl
+ try {
+ const activation =
+ await this.memberRegistrationServiceClient.getInvitationProfile(normalizedEmail)
+ return activation.profileUiBaseUrl
+ } catch {
+ return config.desktopProfileUiBaseUrl
+ }
+ }
+
async completeDesktopSetup(email: string, authorizationToken: string) {
const normalizedEmail = email.trim().toLowerCase()
if (!normalizedEmail || !authorizationToken.trim()) {
@@ -2921,8 +2926,9 @@ export class AppService {
const { buildSandboxUiWebLink } = await import('./sandboxUiDeepLinks.js')
const location = driver.getActiveSandboxUiLocation()
if (!location) throw new Error('No app is currently open')
+ const profileUiBaseUrl = await this.resolveProfileUiBaseUrl()
return {
- url: buildSandboxUiWebLink(config.desktopProfileUiBaseUrl, {
+ url: buildSandboxUiWebLink(profileUiBaseUrl, {
...location,
teamId: String(teamId || '').trim() || undefined,
}),
diff --git a/desktop-app/src/main.ts b/desktop-app/src/main.ts
index 83b534a44..1e3955a66 100644
--- a/desktop-app/src/main.ts
+++ b/desktop-app/src/main.ts
@@ -5,11 +5,8 @@ import { config } from './config.js'
import { assertTrustedSender, registerIpcHandlers } from './ipc.js'
import { createMainWindowCoordinator } from './mainWindowCoordinator.js'
import { collectInitialProtocolUrls } from './protocolLaunchArgs.js'
-import {
- type SandboxUiDeepLinkEnvelope,
- parseSandboxUiDeepLink,
- sandboxUiDeepLinkTargetsEqual,
-} from './sandboxUiDeepLinks.js'
+import { SandboxUiDeepLinkQueue } from './sandboxUiDeepLinkQueue.js'
+import { parseSandboxUiDeepLink } from './sandboxUiDeepLinks.js'
import { installAdaptiveSystemIcon, resolveSystemIconPath } from './systemIcon.js'
const EVENFIRE_APP_NAME = 'Evenfire'
@@ -26,8 +23,7 @@ process.stderr?.on?.('error', () => {})
let mainWindow: BrowserWindow | null = null
const appService = new AppService()
const pendingEvenfireUrls: string[] = []
-const pendingSandboxUiDeepLinks: SandboxUiDeepLinkEnvelope[] = []
-let sandboxUiDeepLinkSequence = 0
+const sandboxUiDeepLinkQueue = new SandboxUiDeepLinkQueue()
let mainWindowLifecycleReady = false
function systemIconAssetsDirectory(): string {
@@ -98,15 +94,19 @@ ipcMain.handle('window:getVisibility', event => {
ipcMain.handle('sandboxUi:listPendingDeepLinks', event => {
assertTrustedSender(event)
- return { links: [...pendingSandboxUiDeepLinks] }
+ return { links: sandboxUiDeepLinkQueue.list() }
+})
+
+ipcMain.handle('sandboxUi:clearPendingDeepLinks', event => {
+ assertTrustedSender(event)
+ sandboxUiDeepLinkQueue.clear()
})
ipcMain.handle('sandboxUi:acknowledgeDeepLink', (event, payload: { id?: unknown }) => {
assertTrustedSender(event)
const id = Number(payload?.id)
if (!Number.isInteger(id) || id <= 0) throw new Error('Invalid app deep-link id')
- const index = pendingSandboxUiDeepLinks.findIndex(link => link.id === id)
- if (index >= 0) pendingSandboxUiDeepLinks.splice(index, 1)
+ sandboxUiDeepLinkQueue.acknowledge(id)
})
const DESKTOP_SETUP_PROTOCOL = 'evenfire'
const CLERUM_PROTOCOL = 'clerum'
@@ -138,17 +138,11 @@ function handleSandboxUiDeepLink(rawUrl: string): boolean {
// Coalesce only while the same semantic target is awaiting renderer
// acknowledgement. Query-parameter order cannot bypass this check, and once
// acknowledged, an immediate user re-click creates a fresh envelope.
- if (pendingSandboxUiDeepLinks.some(pending => sandboxUiDeepLinkTargetsEqual(pending, target))) {
+ const envelope = sandboxUiDeepLinkQueue.enqueue(target)
+ if (!envelope) {
requestMainWindow()
return true
}
-
- const envelope: SandboxUiDeepLinkEnvelope = {
- id: (sandboxUiDeepLinkSequence += 1),
- ...target,
- }
- pendingSandboxUiDeepLinks.push(envelope)
- if (pendingSandboxUiDeepLinks.length > 20) pendingSandboxUiDeepLinks.shift()
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send('sandboxUi:deepLink', envelope)
}
@@ -182,7 +176,7 @@ function handleEvenfireUrl(rawUrl: string): void {
}
if (parsed.hostname === 'app') {
- handleSandboxUiDeepLink(rawUrl)
+ if (!handleSandboxUiDeepLink(rawUrl)) requestMainWindow()
return
}
@@ -205,8 +199,7 @@ function handleEvenfireUrl(rawUrl: string): void {
if (!externalRestApiBaseUrl) return
if (mainWindow && !mainWindow.isDestroyed()) {
- mainWindow.show()
- mainWindow.focus()
+ focusMainWindow()
mainWindow.webContents.send('auth:desktopEnvironmentSetup', {
externalRestApiBaseUrl,
appName,
@@ -225,8 +218,7 @@ function handleEvenfireUrl(rawUrl: string): void {
if (!email || !authorizationToken) return
if (mainWindow && !mainWindow.isDestroyed()) {
- mainWindow.show()
- mainWindow.focus()
+ focusMainWindow()
mainWindow.webContents.send('auth:desktopSetupToken', { email, authorizationToken })
} else {
pendingEvenfireUrls.push(rawUrl)
@@ -262,11 +254,7 @@ function handleClerumUrl(rawUrl: string): void {
driver.dispatchSandboxUiOauthCompleted({ oauthClientId, provider })
})()
- if (mainWindow && !mainWindow.isDestroyed()) {
- if (mainWindow.isMinimized()) mainWindow.restore()
- mainWindow.show()
- mainWindow.focus()
- }
+ focusMainWindow()
}
registerCustomProtocols()
@@ -276,10 +264,9 @@ if (!gotSingleInstanceLock) {
app.quit()
} else {
app.on('second-instance', (_event, argv) => {
- const desktopSetupLink = argv.find(arg => arg.startsWith(`${DESKTOP_SETUP_PROTOCOL}://`))
- if (desktopSetupLink) handleEvenfireUrl(desktopSetupLink)
- const clerumLink = argv.find(arg => arg.startsWith(`${CLERUM_PROTOCOL}://`))
- if (clerumLink) handleClerumUrl(clerumLink)
+ const protocolUrls = collectInitialProtocolUrls(argv)
+ protocolUrls.evenfireUrls.forEach(handleEvenfireUrl)
+ protocolUrls.clerumUrls.forEach(handleClerumUrl)
requestMainWindow()
})
}
@@ -363,8 +350,8 @@ if (gotSingleInstanceLock) {
const initialProtocolUrls = collectInitialProtocolUrls(process.argv)
pendingEvenfireUrls.push(...initialProtocolUrls.evenfireUrls)
await mainWindowCoordinator.ensureWindow()
- if (process.platform !== 'darwin' && initialProtocolUrls.clerumUrl) {
- handleClerumUrl(initialProtocolUrls.clerumUrl)
+ if (process.platform !== 'darwin') {
+ initialProtocolUrls.clerumUrls.forEach(handleClerumUrl)
}
wirePowerMonitor()
diff --git a/desktop-app/src/preload.ts b/desktop-app/src/preload.ts
index e9851e07d..5bc2c0880 100644
--- a/desktop-app/src/preload.ts
+++ b/desktop-app/src/preload.ts
@@ -1,4 +1,5 @@
import { contextBridge, ipcRenderer } from 'electron'
+import type { SandboxUiDeepLinkEnvelope } from './sandboxUiDeepLinks.js'
import type { HostMessageRequest, ProfileSettingsOpenOptions } from './types.js'
const clerum = Object.freeze({
@@ -424,19 +425,15 @@ const clerum = Object.freeze({
reload: () => ipcRenderer.invoke('sandboxUi:reload'),
copyDeepLink: (teamId?: string) => ipcRenderer.invoke('sandboxUi:copyDeepLink', { teamId }),
listPendingDeepLinks: () => ipcRenderer.invoke('sandboxUi:listPendingDeepLinks'),
+ clearPendingDeepLinks: () => ipcRenderer.invoke('sandboxUi:clearPendingDeepLinks'),
acknowledgeDeepLink: (id: number) =>
ipcRenderer.invoke('sandboxUi:acknowledgeDeepLink', { id }),
setBounds: (bounds: { x: number; y: number; width: number; height: number; dpr?: number }) =>
ipcRenderer.invoke('sandboxUi:setBounds', { bounds }),
setVisible: (visible: boolean) => ipcRenderer.invoke('sandboxUi:setVisible', { visible }),
capturePreview: () => ipcRenderer.invoke('sandboxUi:capturePreview'),
- onDeepLink: (
- callback: (args: { id: number; appRef: string; path: string; teamId?: string }) => void
- ) => {
- const listener = (
- _event: unknown,
- args: { id: number; appRef: string; path: string; teamId?: string }
- ) => callback(args)
+ onDeepLink: (callback: (args: SandboxUiDeepLinkEnvelope) => void) => {
+ const listener = (_event: unknown, args: SandboxUiDeepLinkEnvelope) => callback(args)
ipcRenderer.on('sandboxUi:deepLink', listener)
return () => ipcRenderer.off('sandboxUi:deepLink', listener)
},
diff --git a/desktop-app/src/protocolLaunchArgs.ts b/desktop-app/src/protocolLaunchArgs.ts
index a8f7d6942..3914abea3 100644
--- a/desktop-app/src/protocolLaunchArgs.ts
+++ b/desktop-app/src/protocolLaunchArgs.ts
@@ -1,11 +1,11 @@
export type InitialProtocolUrls = {
evenfireUrls: string[]
- clerumUrl?: string
+ clerumUrls: string[]
}
export function collectInitialProtocolUrls(argv: string[]): InitialProtocolUrls {
return {
- evenfireUrls: [...new Set(argv.filter(argument => argument.startsWith('evenfire://')))],
- clerumUrl: argv.find(argument => argument.startsWith('clerum://')),
+ evenfireUrls: [...new Set(argv.filter(argument => argument.startsWith('evenfire:')))],
+ clerumUrls: [...new Set(argv.filter(argument => argument.startsWith('clerum:')))],
}
}
diff --git a/desktop-app/src/renderer.d.ts b/desktop-app/src/renderer.d.ts
index f6a7f7a97..26d2547f4 100644
--- a/desktop-app/src/renderer.d.ts
+++ b/desktop-app/src/renderer.d.ts
@@ -556,6 +556,7 @@ declare global {
reload: () => Promise<void>
copyDeepLink: (teamId?: string) => Promise<{ url: string }>
listPendingDeepLinks: () => Promise<{ links: SandboxUiDeepLinkEnvelope[] }>
+ clearPendingDeepLinks?: () => Promise<void>
acknowledgeDeepLink: (id: number) => Promise<void>
setBounds: (bounds: {
x: number
diff --git a/desktop-app/src/sandboxUiDeepLinkQueue.ts b/desktop-app/src/sandboxUiDeepLinkQueue.ts
new file mode 100644
index 000000000..cbe1d8d68
--- /dev/null
+++ b/desktop-app/src/sandboxUiDeepLinkQueue.ts
@@ -0,0 +1,30 @@
+import type { SandboxUiDeepLinkEnvelope, SandboxUiDeepLinkTarget } from './sandboxUiDeepLinks.js'
+import { sandboxUiDeepLinkTargetsEqual } from './sandboxUiDeepLinks.js'
+
+export class SandboxUiDeepLinkQueue {
+ private readonly pending: SandboxUiDeepLinkEnvelope[] = []
+ private sequence = 0
+
+ constructor(private readonly maxSize = 20) {}
+
+ list(): SandboxUiDeepLinkEnvelope[] {
+ return [...this.pending]
+ }
+
+ enqueue(target: SandboxUiDeepLinkTarget): SandboxUiDeepLinkEnvelope | null {
+ if (this.pending.some(item => sandboxUiDeepLinkTargetsEqual(item, target))) return null
+ const envelope = { id: (this.sequence += 1), ...target }
+ this.pending.push(envelope)
+ if (this.pending.length > this.maxSize) this.pending.shift()
+ return envelope
+ }
+
+ acknowledge(id: number): void {
+ const index = this.pending.findIndex(item => item.id === id)
+ if (index >= 0) this.pending.splice(index, 1)
+ }
+
+ clear(): void {
+ this.pending.splice(0)
+ }
+}
diff --git a/desktop-app/src/sandboxUiDeepLinks.ts b/desktop-app/src/sandboxUiDeepLinks.ts
index 1761c80d7..62ef6f5b3 100644
--- a/desktop-app/src/sandboxUiDeepLinks.ts
+++ b/desktop-app/src/sandboxUiDeepLinks.ts
@@ -1,29 +1,20 @@
-export const SANDBOX_UI_DEEP_LINK_HOST = 'app'
-export const SANDBOX_UI_DEEP_LINK_PROTOCOL = 'evenfire:'
-export const SANDBOX_UI_WEB_LINK_PATH = '/open/apps'
-
-const MAX_APP_SEGMENT_LENGTH = 253
-const MAX_APP_ROUTE_LENGTH = 4096
-const MAX_TEAM_ID_LENGTH = 255
-const APP_SEGMENT_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/
-const TEAM_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/
-
-export type SandboxUiDeepLinkTarget = {
- appRef: string
- path: string
- teamId?: string
-}
-
-export type SandboxUiDeepLinkEnvelope = SandboxUiDeepLinkTarget & {
- id: number
-}
-
-type SandboxUiDeepLinkParts = {
- recipeNs: string
- recipeName: string
- path: string
- teamId?: string
-}
+import { normalizeSandboxUiRoute } from '@clerum/desktop-app-links'
+
+export {
+ SANDBOX_UI_DEEP_LINK_HOST,
+ SANDBOX_UI_DEEP_LINK_PROTOCOL,
+ SANDBOX_UI_WEB_LINK_PATH,
+ buildSandboxUiDeepLink,
+ buildSandboxUiWebLink,
+ normalizeSandboxUiRoute,
+ parseSandboxUiDeepLink,
+ sandboxUiDeepLinkTargetsEqual,
+} from '@clerum/desktop-app-links'
+export type {
+ SandboxUiDeepLinkEnvelope,
+ SandboxUiDeepLinkParts,
+ SandboxUiDeepLinkTarget,
+} from '@clerum/desktop-app-links'
type SandboxUiViewRouteInput = {
currentUrl: string
@@ -32,125 +23,6 @@ type SandboxUiViewRouteInput = {
recipeName: string
}
-function isValidAppSegment(value: string): boolean {
- return (
- value.length > 0 && value.length <= MAX_APP_SEGMENT_LENGTH && APP_SEGMENT_PATTERN.test(value)
- )
-}
-
-function normalizeTeamId(rawTeamId: string | undefined): string | null {
- const teamId = String(rawTeamId || '').trim()
- if (!teamId) return ''
- if (teamId.length > MAX_TEAM_ID_LENGTH || !TEAM_ID_PATTERN.test(teamId)) return null
- return teamId
-}
-
-export function normalizeSandboxUiRoute(rawPath: string): string | null {
- const path = String(rawPath || '').trim()
- if (
- !path ||
- path.length > MAX_APP_ROUTE_LENGTH ||
- !path.startsWith('/') ||
- path.startsWith('//') ||
- path.includes('\\')
- ) {
- return null
- }
- if (/[\u0000-\u001f\u007f]/.test(path)) return null
- return path
-}
-
-export function buildSandboxUiDeepLink(parts: SandboxUiDeepLinkParts): string {
- const recipeNs = String(parts.recipeNs || '').trim()
- const recipeName = String(parts.recipeName || '').trim()
- const path = normalizeSandboxUiRoute(parts.path)
- const teamId = normalizeTeamId(parts.teamId)
- if (!isValidAppSegment(recipeNs) || !isValidAppSegment(recipeName) || !path || teamId === null) {
- throw new Error('Cannot create a deep link for this app route')
- }
-
- const url = new URL(
- `${SANDBOX_UI_DEEP_LINK_PROTOCOL}//${SANDBOX_UI_DEEP_LINK_HOST}/` +
- `${encodeURIComponent(recipeNs)}/${encodeURIComponent(recipeName)}`
- )
- url.searchParams.set('path', path)
- if (teamId) url.searchParams.set('team', teamId)
- return url.toString()
-}
-
-export function buildSandboxUiWebLink(
- profileUiBaseUrl: string,
- parts: SandboxUiDeepLinkParts
-): string {
- const recipeNs = String(parts.recipeNs || '').trim()
- const recipeName = String(parts.recipeName || '').trim()
- const deepLink = new URL(buildSandboxUiDeepLink({ ...parts, recipeNs, recipeName }))
- let baseUrl: URL
- try {
- baseUrl = new URL(profileUiBaseUrl)
- } catch {
- throw new Error('Cannot create a shareable link for this desktop environment')
- }
- if (!['http:', 'https:'].includes(baseUrl.protocol) || baseUrl.username || baseUrl.password) {
- throw new Error('Cannot create a shareable link for this desktop environment')
- }
-
- const url = new URL(
- `${SANDBOX_UI_WEB_LINK_PATH}/${encodeURIComponent(recipeNs)}/` + encodeURIComponent(recipeName),
- baseUrl
- )
- url.search = deepLink.search
- return url.toString()
-}
-
-export function parseSandboxUiDeepLink(rawUrl: string): SandboxUiDeepLinkTarget | null {
- let parsed: URL
- try {
- parsed = new URL(rawUrl)
- } catch {
- return null
- }
- if (
- parsed.protocol !== SANDBOX_UI_DEEP_LINK_PROTOCOL ||
- parsed.hostname !== SANDBOX_UI_DEEP_LINK_HOST
- ) {
- return null
- }
-
- const segments = parsed.pathname.split('/').filter(Boolean)
- if (segments.length !== 2) return null
- let recipeNs: string
- let recipeName: string
- try {
- recipeNs = decodeURIComponent(segments[0] || '')
- recipeName = decodeURIComponent(segments[1] || '')
- } catch {
- return null
- }
- if (!isValidAppSegment(recipeNs) || !isValidAppSegment(recipeName)) return null
-
- const path = normalizeSandboxUiRoute(parsed.searchParams.get('path') || '/')
- if (!path) return null
- const teamId = normalizeTeamId(parsed.searchParams.get('team') || undefined)
- if (teamId === null) return null
- return {
- appRef: `${recipeNs}/${recipeName}`,
- path,
- ...(teamId ? { teamId } : {}),
- }
-}
-
-export function sandboxUiDeepLinkTargetsEqual(
- left: SandboxUiDeepLinkTarget,
- right: SandboxUiDeepLinkTarget
-): boolean {
- return (
- left.appRef === right.appRef &&
- left.path === right.path &&
- (left.teamId || '') === (right.teamId || '')
- )
-}
-
export function extractSandboxUiViewRoute(input: SandboxUiViewRouteInput): string | null {
let current: URL
let proxy: URL
@@ -168,5 +40,5 @@ export function extractSandboxUiViewRoute(input: SandboxUiViewRouteInput): strin
if (current.pathname !== prefix && !current.pathname.startsWith(`${prefix}/`)) return null
const pathname = current.pathname.slice(prefix.length) || '/'
- return normalizeSandboxUiRoute(`${pathname}${current.search}${current.hash}`)
+ return normalizeSandboxUiRoute(`${pathname}${current.search}${current.hash}`) ?? null
}
diff --git a/desktop-app/src/sandboxUiDriver.ts b/desktop-app/src/sandboxUiDriver.ts
index 3408aea37..19189ad80 100644
--- a/desktop-app/src/sandboxUiDriver.ts
+++ b/desktop-app/src/sandboxUiDriver.ts
@@ -122,6 +122,7 @@ export function getActiveSandboxUiLocation(): {
path: string
} | null {
if (!active) return null
+ if (active.view.webContents.isDestroyed()) return null
const currentPath = extractSandboxUiViewRoute({
currentUrl: active.view.webContents.getURL(),
rpcProxyOrigin: active.rpcProxyOrigin,
@@ -380,12 +381,43 @@ export async function mountSandboxUiView(args: MountSandboxUiArgs): Promise<void
const clientRouteUrl =
`${proxyOriginUrl}/api/v1/sandbox-ui/` +
`${encodeURIComponent(recipeNs)}/${encodeURIComponent(recipeName)}/view${clientRoutePath}`
- view.webContents.once('did-finish-load', () => {
- if (!active || active.view !== view || view.webContents.isDestroyed()) return
- void applySandboxUiClientRoute(view.webContents, clientRouteUrl).catch(err => {
- console.warn('[SandboxUI] client route handoff failed:', err)
- })
- })
+ let lastNavigation = { url: '', status: 0 }
+ const cleanupClientRouteHandoff = () => {
+ view.webContents.removeListener('did-navigate', onDidNavigate)
+ view.webContents.removeListener('did-finish-load', onDidFinishLoad)
+ }
+ const onDidNavigate = (
+ _event: Electron.Event,
+ navigatedUrl: string,
+ httpResponseCode: number
+ ) => {
+ lastNavigation = { url: navigatedUrl, status: httpResponseCode }
+ }
+ const onDidFinishLoad = () => {
+ if (!active || active.view !== view || view.webContents.isDestroyed()) {
+ cleanupClientRouteHandoff()
+ return
+ }
+ if (
+ !canApplySandboxUiClientRoute({
+ expectedUrl: url,
+ currentUrl: view.webContents.getURL(),
+ navigatedUrl: lastNavigation.url,
+ httpResponseCode: lastNavigation.status,
+ })
+ ) {
+ return
+ }
+ void applySandboxUiClientRoute(view.webContents, clientRouteUrl)
+ .then(applied => {
+ if (applied) cleanupClientRouteHandoff()
+ })
+ .catch(err => {
+ console.warn('[SandboxUI] client route handoff failed:', err)
+ })
+ }
+ view.webContents.on('did-navigate', onDidNavigate)
+ view.webContents.on('did-finish-load', onDidFinishLoad)
}
// Drop the HTTP cache on every open so a stale entry from a prior
// broken pod can't keep painting after the recipe is healthy. The
@@ -430,6 +462,20 @@ export async function applySandboxUiClientRoute(
)
}
+export function canApplySandboxUiClientRoute(input: {
+ expectedUrl: string
+ currentUrl: string
+ navigatedUrl: string
+ httpResponseCode: number
+}): boolean {
+ return (
+ input.currentUrl === input.expectedUrl &&
+ input.navigatedUrl === input.expectedUrl &&
+ input.httpResponseCode >= 200 &&
+ input.httpResponseCode < 400
+ )
+}
+
/**
* Unmount the active view (no-op if nothing is mounted). Called on user
* "Close" / navigate-away. Leaves the per-recipe partition intact so a
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index 08bd650ae..be880405e 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -27,6 +27,7 @@ import {
getConversationOriginForAppLaunch,
getConversationOriginForNavigation,
} from '@lib/sandboxUiConversationOrigin'
+import { shouldPurgeSandboxUiDeepLinks } from '@lib/sandboxUiDeepLinkState'
import { AgentsPage } from '@pages/AgentsPage'
import { AuthPage } from '@pages/AuthPage'
import { ChatPage } from '@pages/ChatPage'
@@ -149,6 +150,8 @@ export function App() {
const contentPanelRef = React.useRef<HTMLElement | null>(null)
const activeConversationOriginRef = React.useRef<SandboxUiConversationOrigin | null>(null)
const processingSandboxUiDeepLinkIdRef = React.useRef<number | null>(null)
+ const sandboxUiDeepLinkIdentityRef = React.useRef<string | null | undefined>(undefined)
+ const sandboxUiDeepLinkGenerationRef = React.useRef(0)
const isAgentChatView =
(vm.navItem === DESKTOP_ROUTES.agents && Boolean(vm.selectedAgent)) ||
(vm.navItem === DESKTOP_ROUTES.chat && Boolean(vm.selectedAgent))
@@ -201,11 +204,6 @@ export function App() {
setAvailableSandboxUiApps([])
setActiveSandboxUiApp(null)
setSandboxUiConversationOrigin(null)
- setPendingSandboxUiDeepLinks(current =>
- current.map(item =>
- item.conversationOrigin ? { ...item, conversationOrigin: null } : item
- )
- )
return
}
@@ -232,6 +230,22 @@ export function App() {
}
}, [vm.currentTeamId, vm.isAuthenticated])
+ React.useEffect(() => {
+ const identity =
+ vm.isAuthenticated && vm.me ? `${vm.me.id}:${String(vm.me.email || '').toLowerCase()}` : null
+ const previousIdentity = sandboxUiDeepLinkIdentityRef.current
+ sandboxUiDeepLinkIdentityRef.current = identity
+ if (!shouldPurgeSandboxUiDeepLinks(previousIdentity, identity)) return
+
+ setPendingSandboxUiDeepLinks([])
+ processingSandboxUiDeepLinkIdRef.current = null
+ sandboxUiDeepLinkGenerationRef.current += 1
+ const clearPendingDeepLinks = window.clerum.sandboxUi.clearPendingDeepLinks
+ if (typeof clearPendingDeepLinks === 'function') {
+ void clearPendingDeepLinks().catch(() => undefined)
+ }
+ }, [vm.isAuthenticated, vm.me])
+
const handleSandboxUiOpening = React.useCallback((app: ActiveSandboxUiApp) => {
setActiveSandboxUiApp(app)
}, [])
@@ -299,11 +313,15 @@ export function App() {
const handleSidebarNavSelect = React.useCallback(
(item: NavItem) => {
setSandboxUiConversationOrigin(
- getConversationOriginForNavigation(item, activeConversationOrigin)
+ getConversationOriginForNavigation(
+ item,
+ activeConversationOrigin,
+ sandboxUiConversationOrigin
+ )
)
vm.handleNavSelect(item)
},
- [activeConversationOrigin, vm.handleNavSelect]
+ [activeConversationOrigin, sandboxUiConversationOrigin, vm.handleNavSelect]
)
const handleOpenSandboxUiApp = React.useCallback(
@@ -352,13 +370,16 @@ export function App() {
const pending = pendingSandboxUiDeepLinks[0]
if (!pending || processingSandboxUiDeepLinkIdRef.current !== null) return
processingSandboxUiDeepLinkIdRef.current = pending.link.id
+ const processingGeneration = sandboxUiDeepLinkGenerationRef.current
void (async () => {
try {
if (pending.link.teamId && pending.link.teamId !== vm.currentTeamId) {
await vm.handleEnsureTeamContext({ teamId: pending.link.teamId })
}
+ if (processingGeneration !== sandboxUiDeepLinkGenerationRef.current) return
const result = await window.clerum.sandboxUi.listApps()
+ if (processingGeneration !== sandboxUiDeepLinkGenerationRef.current) return
const availableApps = toActiveSandboxUiApps(result.apps)
setAvailableSandboxUiApps(availableApps)
const resolution = resolveSandboxUiDeepLinkApp(result.apps, pending.link.appRef)
@@ -373,19 +394,28 @@ export function App() {
launchSandboxUiApp(
{
...resolution.app,
- routePath: pending.link.path,
+ ...(pending.link.path ? { routePath: pending.link.path } : {}),
},
- pending.conversationOrigin
+ pending.conversationOrigin ?? sandboxUiConversationOrigin
)
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
vm.pushToast(`Could not open app link: ${message}`, 'error')
} finally {
- await window.clerum.sandboxUi.acknowledgeDeepLink(pending.link.id).catch(() => undefined)
+ if (
+ processingGeneration !== sandboxUiDeepLinkGenerationRef.current ||
+ processingSandboxUiDeepLinkIdRef.current !== pending.link.id
+ ) {
+ return
+ }
setPendingSandboxUiDeepLinks(current =>
current.filter(item => item.link.id !== pending.link.id)
)
processingSandboxUiDeepLinkIdRef.current = null
+ const acknowledgeDeepLink = window.clerum.sandboxUi.acknowledgeDeepLink
+ if (typeof acknowledgeDeepLink === 'function') {
+ await acknowledgeDeepLink(pending.link.id).catch(() => undefined)
+ }
}
})()
}, [
@@ -396,6 +426,7 @@ export function App() {
vm.handleEnsureTeamContext,
vm.isAuthenticated,
vm.pushToast,
+ sandboxUiConversationOrigin,
])
React.useEffect(() => {
diff --git a/desktop-app/ui/src/App.types.ts b/desktop-app/ui/src/App.types.ts
index 80bbf63de..ac2fc3b0a 100644
--- a/desktop-app/ui/src/App.types.ts
+++ b/desktop-app/ui/src/App.types.ts
@@ -1,11 +1,7 @@
+import type { SandboxUiDeepLinkEnvelope } from '@clerum/desktop-app-links'
import type { SandboxUiConversationOrigin } from '@pages/SandboxUiPage.types'
-export type SandboxUiDeepLinkEnvelope = {
- id: number
- appRef: string
- path: string
- teamId?: string
-}
+export type { SandboxUiDeepLinkEnvelope } from '@clerum/desktop-app-links'
export type PendingSandboxUiDeepLink = {
link: SandboxUiDeepLinkEnvelope
diff --git a/desktop-app/ui/src/lib/__tests__/sandboxUiConversationOrigin.test.ts b/desktop-app/ui/src/lib/__tests__/sandboxUiConversationOrigin.test.ts
index 29cadbb89..37e0e99c6 100644
--- a/desktop-app/ui/src/lib/__tests__/sandboxUiConversationOrigin.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/sandboxUiConversationOrigin.test.ts
@@ -13,15 +13,21 @@ const conversationOrigin = {
describe('sandbox UI conversation origin', () => {
it('preserves an active conversation while navigating to the Apps picker', () => {
- expect(getConversationOriginForNavigation(DESKTOP_ROUTES.apps, conversationOrigin)).toEqual(
- conversationOrigin
- )
+ expect(
+ getConversationOriginForNavigation(DESKTOP_ROUTES.apps, conversationOrigin, null)
+ ).toEqual(conversationOrigin)
})
it('clears the preserved conversation when navigating elsewhere', () => {
- expect(getConversationOriginForNavigation(DESKTOP_ROUTES.settings, conversationOrigin)).toBe(
- null
- )
+ expect(
+ getConversationOriginForNavigation(DESKTOP_ROUTES.settings, conversationOrigin, null)
+ ).toBe(null)
+ })
+
+ it('keeps the preserved origin when Apps is selected again', () => {
+ expect(
+ getConversationOriginForNavigation(DESKTOP_ROUTES.apps, null, conversationOrigin)
+ ).toEqual(conversationOrigin)
})
it('uses the preserved conversation when launching from the Apps picker', () => {
diff --git a/desktop-app/ui/src/lib/__tests__/sandboxUiDeepLinkState.test.ts b/desktop-app/ui/src/lib/__tests__/sandboxUiDeepLinkState.test.ts
new file mode 100644
index 000000000..d130111b6
--- /dev/null
+++ b/desktop-app/ui/src/lib/__tests__/sandboxUiDeepLinkState.test.ts
@@ -0,0 +1,18 @@
+import { describe, expect, it } from 'vitest'
+import { shouldPurgeSandboxUiDeepLinks } from '../sandboxUiDeepLinkState'
+
+describe('shouldPurgeSandboxUiDeepLinks', () => {
+ it('keeps a cold-start link while the first user authenticates', () => {
+ expect(shouldPurgeSandboxUiDeepLinks(undefined, null)).toBe(false)
+ expect(shouldPurgeSandboxUiDeepLinks(null, 'user-a')).toBe(false)
+ })
+
+ it('purges links on logout or an authenticated identity change', () => {
+ expect(shouldPurgeSandboxUiDeepLinks('user-a', null)).toBe(true)
+ expect(shouldPurgeSandboxUiDeepLinks('user-a', 'user-b')).toBe(true)
+ })
+
+ it('keeps links while the same identity changes teams', () => {
+ expect(shouldPurgeSandboxUiDeepLinks('user-a', 'user-a')).toBe(false)
+ })
+})
diff --git a/desktop-app/ui/src/lib/sandboxUiConversationOrigin.ts b/desktop-app/ui/src/lib/sandboxUiConversationOrigin.ts
index bf6f32005..8be969649 100644
--- a/desktop-app/ui/src/lib/sandboxUiConversationOrigin.ts
+++ b/desktop-app/ui/src/lib/sandboxUiConversationOrigin.ts
@@ -2,11 +2,23 @@ import { DESKTOP_ROUTES } from '@constants/navigation'
import type { SandboxUiConversationOrigin } from '@pages/SandboxUiPage.types'
import type { NavItem } from '@/uiTypes'
+function resolveConversationOrigin(
+ item: NavItem,
+ activeConversationOrigin: SandboxUiConversationOrigin | null,
+ preservedConversationOrigin: SandboxUiConversationOrigin | null
+): SandboxUiConversationOrigin | null {
+ return (
+ activeConversationOrigin ?? (item === DESKTOP_ROUTES.apps ? preservedConversationOrigin : null)
+ )
+}
+
export function getConversationOriginForNavigation(
item: NavItem,
- activeConversationOrigin: SandboxUiConversationOrigin | null
+ activeConversationOrigin: SandboxUiConversationOrigin | null,
+ preservedConversationOrigin: SandboxUiConversationOrigin | null
): SandboxUiConversationOrigin | null {
- return item === DESKTOP_ROUTES.apps ? activeConversationOrigin : null
+ if (item !== DESKTOP_ROUTES.apps) return null
+ return resolveConversationOrigin(item, activeConversationOrigin, preservedConversationOrigin)
}
export function getConversationOriginForAppLaunch(
@@ -14,8 +26,9 @@ export function getConversationOriginForAppLaunch(
activeConversationOrigin: SandboxUiConversationOrigin | null,
preservedConversationOrigin: SandboxUiConversationOrigin | null
): SandboxUiConversationOrigin | null {
- return (
- activeConversationOrigin ??
- (currentItem === DESKTOP_ROUTES.apps ? preservedConversationOrigin : null)
+ return resolveConversationOrigin(
+ currentItem,
+ activeConversationOrigin,
+ preservedConversationOrigin
)
}
diff --git a/desktop-app/ui/src/lib/sandboxUiDeepLinkState.ts b/desktop-app/ui/src/lib/sandboxUiDeepLinkState.ts
new file mode 100644
index 000000000..119c87875
--- /dev/null
+++ b/desktop-app/ui/src/lib/sandboxUiDeepLinkState.ts
@@ -0,0 +1,10 @@
+export function shouldPurgeSandboxUiDeepLinks(
+ previousIdentity: string | null | undefined,
+ currentIdentity: string | null
+): boolean {
+ return (
+ previousIdentity !== undefined &&
+ previousIdentity !== null &&
+ previousIdentity !== currentIdentity
+ )
+}
diff --git a/desktop-app/ui/src/pages/SandboxUiPage.tsx b/desktop-app/ui/src/pages/SandboxUiPage.tsx
index dd8b73046..6153ac92b 100644
--- a/desktop-app/ui/src/pages/SandboxUiPage.tsx
+++ b/desktop-app/ui/src/pages/SandboxUiPage.tsx
@@ -149,6 +149,7 @@ function useEmbedBounds(
}
const APP_PAGE_SIZE = 6
+let pendingSandboxUiUnmountCleanup: number | null = null
export function SandboxUiPage({
boundsRefreshKey = 0,
@@ -174,7 +175,6 @@ export function SandboxUiPage({
const [embedPreviewDataUrl, setEmbedPreviewDataUrl] = useState<string | null>(null)
const embedSlotRef = useRef<HTMLDivElement>(null)
const lastShortcutOpenRequestIdRef = useRef(0)
- const pendingUnmountCleanupRef = useRef<number | null>(null)
const shellOverlayOpen =
headerShellOverlayOpen || sidebarShellOverlayOpen || toastShellOverlayOpen
@@ -219,14 +219,14 @@ export function SandboxUiPage({
}, [])
// Tear down the embed when this page unmounts (user navigates away).
- useEffect(() => {
- if (pendingUnmountCleanupRef.current !== null) {
- window.clearTimeout(pendingUnmountCleanupRef.current)
- pendingUnmountCleanupRef.current = null
+ useLayoutEffect(() => {
+ if (pendingSandboxUiUnmountCleanup !== null) {
+ window.clearTimeout(pendingSandboxUiUnmountCleanup)
+ pendingSandboxUiUnmountCleanup = null
}
return () => {
- pendingUnmountCleanupRef.current = window.setTimeout(() => {
- pendingUnmountCleanupRef.current = null
+ pendingSandboxUiUnmountCleanup = window.setTimeout(() => {
+ pendingSandboxUiUnmountCleanup = null
void window.clerum.sandboxUi.close()
onEmbeddedAppBack?.()
}, 0)
@@ -256,6 +256,7 @@ export function SandboxUiPage({
label: app.label,
icon: app.icon,
defaultPath: app.defaultPath,
+ ...(app.routePath ? { routePath: app.routePath } : {}),
})
try {
const rect = await waitForEmbedSlotRect(embedSlotRef)
diff --git a/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx b/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
index 5dfa52d49..8e3aebfcd 100644
--- a/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
@@ -90,6 +90,18 @@ describe('SandboxUiPage', () => {
expect(screen.getAllByRole('button', { name: /^Open / })).toHaveLength(2)
})
+ it('does not let an old unmount timer close an immediate replacement page', async () => {
+ sandboxUi.listApps.mockResolvedValue({ apps: [] })
+ sandboxUi.close.mockResolvedValue(undefined)
+ const first = render(<SandboxUiPage />)
+
+ first.unmount()
+ render(<SandboxUiPage />)
+ await new Promise(resolve => window.setTimeout(resolve, 0))
+
+ expect(sandboxUi.close).not.toHaveBeenCalled()
+ })
+
it('renders the empty apps page with calm centered guidance', async () => {
sandboxUi.listApps.mockResolvedValueOnce({ apps: [] })
@@ -155,6 +167,7 @@ describe('SandboxUiPage', () => {
it('opens a deep-linked app at its stable entry point before handing off the client route', async () => {
sandboxUi.listApps.mockResolvedValueOnce({ apps: [] })
sandboxUi.open.mockResolvedValueOnce(undefined)
+ const onEmbeddedAppOpening = vi.fn()
render(
<SandboxUiPage
@@ -165,6 +178,7 @@ describe('SandboxUiPage', () => {
routePath: '/tasks/task-42?panel=details',
}}
shortcutOpenRequestId={1}
+ onEmbeddedAppOpening={onEmbeddedAppOpening}
/>
)
@@ -183,6 +197,12 @@ describe('SandboxUiPage', () => {
},
})
})
+ expect(onEmbeddedAppOpening).toHaveBeenCalledWith({
+ appRef: 'sandbox-recipes/task-board',
+ label: 'Agentic Task Board',
+ defaultPath: '/',
+ routePath: '/tasks/task-42?panel=details',
+ })
})
it('returns to the originating conversation from an app', async () => {
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 2e04d1e84..e5333af94 100644
--- a/host-context-controller/package-lock.json
+++ b/host-context-controller/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.158",
+ "version": "0.1.159",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.158",
+ "version": "0.1.159",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/host-context-controller/package.json b/host-context-controller/package.json
index 32eca539e..221dc92d7 100644
--- a/host-context-controller/package.json
+++ b/host-context-controller/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.158",
+ "version": "0.1.159",
"description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API",
"main": "dist/main.js",
"engines": {
diff --git a/host-context-controller/test/statelessDeployment.workspaceLayout.test.ts b/host-context-controller/test/statelessDeployment.workspaceLayout.test.ts
index 7b75c2327..6a74125c4 100644
--- a/host-context-controller/test/statelessDeployment.workspaceLayout.test.ts
+++ b/host-context-controller/test/statelessDeployment.workspaceLayout.test.ts
@@ -57,6 +57,9 @@ afterEach(() => {
})
describe('stateless workspace layout migration', () => {
+ // This is the only case that launches the migration shell twice. Keep its
+ // runner budget above the generic 5s limit so CI process contention cannot
+ // turn a completed idempotency check into a harness timeout.
it('moves legacy workspace and SQLite files once and is idempotent', () => {
const root = makeRoot()
writeFileSync(join(root, 'notes.md'), 'workspace-data')
@@ -67,9 +70,7 @@ describe('stateless workspace layout migration', () => {
expect(readFileSync(join(root, 'workspace', 'notes.md'), 'utf8')).toBe('workspace-data')
expect(readFileSync(join(root, 'state', 'state.db'), 'utf8')).toBe('durable-db')
- }, // runner budget above the generic 5s limit so CI process contention cannot // This is the only case that launches the migration shell twice. Keep its
- // turn a completed idempotency check into a harness timeout.
- 15_000)
+ }, 15_000)
it('finishes a partial migration whose SQLite source is already under workspace', () => {
const root = makeRoot()
diff --git a/packages/desktop-app-links/index.cjs b/packages/desktop-app-links/index.cjs
new file mode 100644
index 000000000..68db314ee
--- /dev/null
+++ b/packages/desktop-app-links/index.cjs
@@ -0,0 +1,154 @@
+'use strict'
+
+const SANDBOX_UI_DEEP_LINK_HOST = 'app'
+const SANDBOX_UI_DEEP_LINK_PROTOCOL = 'evenfire:'
+const SANDBOX_UI_WEB_LINK_PATH = '/open/apps'
+const MAX_APP_SEGMENT_LENGTH = 253
+const MAX_APP_ROUTE_LENGTH = 4096
+const MAX_TEAM_ID_LENGTH = 255
+const APP_SEGMENT_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/
+const TEAM_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/
+const DOT_SEGMENT_PATTERN = /^(?:\.|%2e){1,2}$/i
+
+function isValidAppSegment(value) {
+ return (
+ value.length > 0 &&
+ value.length <= MAX_APP_SEGMENT_LENGTH &&
+ APP_SEGMENT_PATTERN.test(value) &&
+ value !== '.' &&
+ value !== '..'
+ )
+}
+
+function normalizeTeamId(rawTeamId) {
+ const teamId = String(rawTeamId || '').trim()
+ if (!teamId) return ''
+ if (teamId.length > MAX_TEAM_ID_LENGTH || !TEAM_ID_PATTERN.test(teamId)) return null
+ return teamId
+}
+
+function normalizeSandboxUiRoute(rawPath) {
+ const routePath = String(rawPath || '').trim()
+ if (!routePath) return undefined
+ if (
+ routePath.length > MAX_APP_ROUTE_LENGTH ||
+ !routePath.startsWith('/') ||
+ routePath.startsWith('//') ||
+ routePath.includes('\\') ||
+ /[\u0000-\u001f\u007f]/.test(routePath)
+ ) {
+ return null
+ }
+ const pathname = routePath.split(/[?#]/, 1)[0]
+ if (pathname.split('/').some(segment => DOT_SEGMENT_PATTERN.test(segment))) return null
+ return routePath
+}
+
+function validateParts(parts) {
+ const recipeNs = String(parts.recipeNs || '').trim()
+ const recipeName = String(parts.recipeName || '').trim()
+ const routePath = normalizeSandboxUiRoute(parts.path)
+ const teamId = normalizeTeamId(parts.teamId)
+ if (
+ !isValidAppSegment(recipeNs) ||
+ !isValidAppSegment(recipeName) ||
+ routePath === null ||
+ teamId === null
+ ) {
+ return null
+ }
+ return { recipeNs, recipeName, path: routePath, teamId: teamId || undefined }
+}
+
+function buildSandboxUiDeepLink(parts) {
+ const valid = validateParts(parts)
+ if (!valid) throw new Error('Cannot create a deep link for this app route')
+ const url = new URL(
+ `${SANDBOX_UI_DEEP_LINK_PROTOCOL}//${SANDBOX_UI_DEEP_LINK_HOST}/` +
+ `${encodeURIComponent(valid.recipeNs)}/${encodeURIComponent(valid.recipeName)}`
+ )
+ if (valid.path) url.searchParams.set('path', valid.path)
+ if (valid.teamId) url.searchParams.set('team', valid.teamId)
+ return url.toString()
+}
+
+function buildSandboxUiWebLink(profileUiBaseUrl, parts) {
+ const valid = validateParts(parts)
+ if (!valid) throw new Error('Cannot create a deep link for this app route')
+ const deepLink = new URL(buildSandboxUiDeepLink(valid))
+ let baseUrl
+ try {
+ baseUrl = new URL(profileUiBaseUrl)
+ } catch {
+ throw new Error('Cannot create a shareable link for this desktop environment')
+ }
+ if (!['http:', 'https:'].includes(baseUrl.protocol) || baseUrl.username || baseUrl.password) {
+ throw new Error('Cannot create a shareable link for this desktop environment')
+ }
+
+ baseUrl.search = ''
+ baseUrl.hash = ''
+ const basePath = baseUrl.pathname.replace(/\/+$/, '')
+ baseUrl.pathname =
+ `${basePath}${SANDBOX_UI_WEB_LINK_PATH}/${encodeURIComponent(valid.recipeNs)}/` +
+ encodeURIComponent(valid.recipeName)
+ baseUrl.search = deepLink.search
+ return baseUrl.toString()
+}
+
+function parseSandboxUiDeepLink(rawUrl) {
+ let parsed
+ try {
+ parsed = new URL(rawUrl)
+ } catch {
+ return null
+ }
+ if (
+ parsed.protocol !== SANDBOX_UI_DEEP_LINK_PROTOCOL ||
+ parsed.hostname !== SANDBOX_UI_DEEP_LINK_HOST
+ ) {
+ return null
+ }
+
+ const segments = parsed.pathname.split('/').filter(Boolean)
+ if (segments.length !== 2) return null
+ let recipeNs
+ let recipeName
+ try {
+ recipeNs = decodeURIComponent(segments[0] || '')
+ recipeName = decodeURIComponent(segments[1] || '')
+ } catch {
+ return null
+ }
+ const valid = validateParts({
+ recipeNs,
+ recipeName,
+ path: parsed.searchParams.get('path') || undefined,
+ teamId: parsed.searchParams.get('team') || undefined,
+ })
+ if (!valid) return null
+ return {
+ appRef: `${valid.recipeNs}/${valid.recipeName}`,
+ ...(valid.path ? { path: valid.path } : {}),
+ ...(valid.teamId ? { teamId: valid.teamId } : {}),
+ }
+}
+
+function sandboxUiDeepLinkTargetsEqual(left, right) {
+ return (
+ left.appRef === right.appRef &&
+ (left.path || '') === (right.path || '') &&
+ (left.teamId || '') === (right.teamId || '')
+ )
+}
+
+module.exports = {
+ SANDBOX_UI_DEEP_LINK_HOST,
+ SANDBOX_UI_DEEP_LINK_PROTOCOL,
+ SANDBOX_UI_WEB_LINK_PATH,
+ buildSandboxUiDeepLink,
+ buildSandboxUiWebLink,
+ normalizeSandboxUiRoute,
+ parseSandboxUiDeepLink,
+ sandboxUiDeepLinkTargetsEqual,
+}
diff --git a/packages/desktop-app-links/index.d.ts b/packages/desktop-app-links/index.d.ts
new file mode 100644
index 000000000..308af40bf
--- /dev/null
+++ b/packages/desktop-app-links/index.d.ts
@@ -0,0 +1,32 @@
+export declare const SANDBOX_UI_DEEP_LINK_HOST: 'app'
+export declare const SANDBOX_UI_DEEP_LINK_PROTOCOL: 'evenfire:'
+export declare const SANDBOX_UI_WEB_LINK_PATH: '/open/apps'
+
+export type SandboxUiDeepLinkTarget = {
+ appRef: string
+ path?: string
+ teamId?: string
+}
+
+export type SandboxUiDeepLinkEnvelope = SandboxUiDeepLinkTarget & {
+ id: number
+}
+
+export type SandboxUiDeepLinkParts = {
+ recipeNs: string
+ recipeName: string
+ path?: string
+ teamId?: string
+}
+
+export function normalizeSandboxUiRoute(rawPath?: string): string | undefined | null
+export function buildSandboxUiDeepLink(parts: SandboxUiDeepLinkParts): string
+export function buildSandboxUiWebLink(
+ profileUiBaseUrl: string,
+ parts: SandboxUiDeepLinkParts
+): string
+export function parseSandboxUiDeepLink(rawUrl: string): SandboxUiDeepLinkTarget | null
+export function sandboxUiDeepLinkTargetsEqual(
+ left: SandboxUiDeepLinkTarget,
+ right: SandboxUiDeepLinkTarget
+): boolean
diff --git a/packages/desktop-app-links/package.json b/packages/desktop-app-links/package.json
new file mode 100644
index 000000000..d56920d8f
--- /dev/null
+++ b/packages/desktop-app-links/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "@clerum/desktop-app-links",
+ "version": "0.1.0",
+ "private": true,
+ "type": "commonjs",
+ "main": "index.cjs",
+ "types": "index.d.ts"
+}
diff --git a/profile-ui/app/open/apps/[recipeNs]/[recipeName]/route.ts b/profile-ui/app/open/apps/[recipeNs]/[recipeName]/route.ts
index ea50b84da..88556cfa5 100644
--- a/profile-ui/app/open/apps/[recipeNs]/[recipeName]/route.ts
+++ b/profile-ui/app/open/apps/[recipeNs]/[recipeName]/route.ts
@@ -3,7 +3,7 @@ import {
buildEvenfireDesktopAppContentSecurityPolicy,
buildEvenfireDesktopAppLink,
buildEvenfireDesktopAppRedirectDocument,
-} from '@lib/desktopAppLinks'
+} from '../../../../../lib/desktopAppLinks'
export const dynamic = 'force-dynamic'
@@ -16,7 +16,7 @@ export async function GET(
const deepLink = buildEvenfireDesktopAppLink({
recipeNs: params.recipeNs,
recipeName: params.recipeName,
- path: requestUrl.searchParams.get('path') || '/',
+ path: requestUrl.searchParams.get('path') || undefined,
teamId: requestUrl.searchParams.get('team') || undefined,
})
@@ -26,6 +26,8 @@ export async function GET(
headers: {
'Cache-Control': 'no-store',
'Content-Type': 'text/plain; charset=utf-8',
+ 'Referrer-Policy': 'no-referrer',
+ 'X-Content-Type-Options': 'nosniff',
},
})
}
diff --git a/profile-ui/lib/desktopAppLinks.ts b/profile-ui/lib/desktopAppLinks.ts
index 1247f6ef8..7e4820f4b 100644
--- a/profile-ui/lib/desktopAppLinks.ts
+++ b/profile-ui/lib/desktopAppLinks.ts
@@ -1,43 +1,18 @@
-const APP_SEGMENT_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/
-const TEAM_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/
-const MAX_APP_SEGMENT_LENGTH = 253
-const MAX_APP_ROUTE_LENGTH = 4096
-const MAX_TEAM_ID_LENGTH = 255
+import { buildSandboxUiDeepLink } from '@clerum/desktop-app-links'
+
const SCRIPT_NONCE_PATTERN = /^[A-Za-z0-9+/_-]+={0,2}$/
export function buildEvenfireDesktopAppLink(parts: {
recipeNs: string
recipeName: string
- path: string
+ path?: string
teamId?: string
}): string | null {
- const recipeNs = String(parts.recipeNs || '').trim()
- const recipeName = String(parts.recipeName || '').trim()
- const path = String(parts.path || '').trim()
- const teamId = String(parts.teamId || '').trim()
- const validSegment = (value: string) =>
- value.length > 0 && value.length <= MAX_APP_SEGMENT_LENGTH && APP_SEGMENT_PATTERN.test(value)
-
- if (
- !validSegment(recipeNs) ||
- !validSegment(recipeName) ||
- !path ||
- path.length > MAX_APP_ROUTE_LENGTH ||
- !path.startsWith('/') ||
- path.startsWith('//') ||
- path.includes('\\') ||
- /[\u0000-\u001f\u007f]/.test(path) ||
- (teamId && (teamId.length > MAX_TEAM_ID_LENGTH || !TEAM_ID_PATTERN.test(teamId)))
- ) {
+ try {
+ return buildSandboxUiDeepLink(parts)
+ } catch {
return null
}
-
- const url = new URL(
- `evenfire://app/${encodeURIComponent(recipeNs)}/${encodeURIComponent(recipeName)}`
- )
- url.searchParams.set('path', path)
- if (teamId) url.searchParams.set('team', teamId)
- return url.toString()
}
function escapeHtml(value: string): string {
@@ -49,20 +24,6 @@ function escapeHtml(value: string): string {
.replaceAll("'", '&#39;')
}
-function desktopAppDisplayName(parsed: URL): string {
- const encodedRecipeName = parsed.pathname.split('/').filter(Boolean)[1]
- if (!encodedRecipeName) return 'this app'
-
- try {
- const recipeName = decodeURIComponent(encodedRecipeName)
- return recipeName.length <= MAX_APP_SEGMENT_LENGTH && APP_SEGMENT_PATTERN.test(recipeName)
- ? recipeName
- : 'this app'
- } catch {
- return 'this app'
- }
-}
-
function normalizeScriptNonce(scriptNonce: string): string {
const nonce = String(scriptNonce || '').trim()
if (!nonce || nonce.length > 128 || !SCRIPT_NONCE_PATTERN.test(nonce)) {
@@ -74,7 +35,7 @@ function normalizeScriptNonce(scriptNonce: string): string {
export function buildEvenfireDesktopAppContentSecurityPolicy(scriptNonce: string): string {
const nonce = normalizeScriptNonce(scriptNonce)
return (
- `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'unsafe-inline'; ` +
+ `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'nonce-${nonce}'; ` +
"base-uri 'none'; form-action 'none'; frame-ancestors 'none'"
)
}
@@ -90,7 +51,6 @@ export function buildEvenfireDesktopAppRedirectDocument(
const nonce = normalizeScriptNonce(scriptNonce)
const escapedLink = escapeHtml(deepLink)
- const escapedAppName = escapeHtml(desktopAppDisplayName(parsed))
const scriptLink = JSON.stringify(deepLink).replaceAll('<', '\\u003c')
return `<!doctype html>
<html lang="en">
@@ -98,8 +58,8 @@ export function buildEvenfireDesktopAppRedirectDocument(
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="refresh" content="0;url=${escapedLink}">
- <title>Open ${escapedAppName} in Evenfire</title>
- <style>
+ <title>Open app in Evenfire</title>
+ <style nonce="${escapeHtml(nonce)}">
:root {
color-scheme: dark;
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
@@ -188,7 +148,7 @@ export function buildEvenfireDesktopAppRedirectDocument(
<section class="page-card">
<div class="stack-tight">
<p class="eyebrow">Evenfire Desktop</p>
- <h1>Open ${escapedAppName}</h1>
+ <h1>Open app in Evenfire</h1>
<p class="body-copy">
Evenfire should open this app automatically. Use the button if your browser asks for
confirmation.
@@ -196,7 +156,7 @@ export function buildEvenfireDesktopAppRedirectDocument(
</div>
<a class="open-button" href="${escapedLink}">Open in Evenfire</a>
<p class="body-copy">
- If nothing happens, make sure the Evenfire desktop app is installed and try again.
+ If nothing happens, install or update to the latest Evenfire Desktop, then try again.
</p>
</section>
</main>
diff --git a/profile-ui/package-lock.json b/profile-ui/package-lock.json
index 7059f52ef..23c5a7c7c 100644
--- a/profile-ui/package-lock.json
+++ b/profile-ui/package-lock.json
@@ -1,13 +1,14 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.107",
+ "version": "0.1.108",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-profile-ui",
- "version": "0.1.107",
+ "version": "0.1.108",
"dependencies": {
+ "@clerum/desktop-app-links": "file:../packages/desktop-app-links",
"next": "16.2.11",
"react": "^18.3.1",
"react-dom": "^18.3.1"
@@ -19,6 +20,14 @@
"typescript": "^5.9.2"
}
},
+ "../packages/desktop-app-links": {
+ "name": "@clerum/desktop-app-links",
+ "version": "0.1.0"
+ },
+ "node_modules/@clerum/desktop-app-links": {
+ "resolved": "../packages/desktop-app-links",
+ "link": true
+ },
"node_modules/@emnapi/runtime": {
"version": "1.11.2",
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.2.tgz",
diff --git a/profile-ui/package.json b/profile-ui/package.json
index c848cf6bc..7a82baada 100644
--- a/profile-ui/package.json
+++ b/profile-ui/package.json
@@ -1,14 +1,15 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.107",
+ "version": "0.1.108",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p 3001",
- "test": "rm -rf .test-dist && tsc -p tsconfig.test.json && node --test .test-dist/test/invitations.test.js"
+ "test": "rm -rf .test-dist && tsc -p tsconfig.test.json && node --test .test-dist/test/*.test.js"
},
"dependencies": {
+ "@clerum/desktop-app-links": "file:../packages/desktop-app-links",
"next": "16.2.11",
"react": "^18.3.1",
"react-dom": "^18.3.1"
diff --git a/profile-ui/test/desktopAppLinks.test.ts b/profile-ui/test/desktopAppLinks.test.ts
index 17267016b..bf9bc8a21 100644
--- a/profile-ui/test/desktopAppLinks.test.ts
+++ b/profile-ui/test/desktopAppLinks.test.ts
@@ -28,6 +28,24 @@ test('buildEvenfireDesktopAppLink rejects unsafe routes', () => {
}),
null
)
+ assert.equal(
+ buildEvenfireDesktopAppLink({
+ recipeNs: 'sandbox-recipes',
+ recipeName: 'agentic-task-board',
+ path: '/safe/%2e%2e/admin',
+ }),
+ null
+ )
+})
+
+test('buildEvenfireDesktopAppLink leaves an omitted route to the recipe default', () => {
+ assert.equal(
+ buildEvenfireDesktopAppLink({
+ recipeNs: 'sandbox-recipes',
+ recipeName: 'agentic-task-board',
+ }),
+ 'evenfire://app/sandbox-recipes/agentic-task-board'
+ )
})
test('buildEvenfireDesktopAppRedirectDocument creates an unauthenticated protocol handoff', () => {
@@ -40,9 +58,11 @@ test('buildEvenfireDesktopAppRedirectDocument creates an unauthenticated protoco
assert.match(document, /window\.location\.replace/)
assert.match(document, new RegExp(`<script nonce="${scriptNonce}">`))
assert.match(document, /evenfire:\/\/app\/sandbox-recipes\/agentic-task-board/)
- assert.match(document, /<style>/)
+ assert.match(document, new RegExp(`<style nonce="${scriptNonce}">`))
assert.match(document, /class="page-card"/)
- assert.match(document, /<h1>Open agentic-task-board<\/h1>/)
+ assert.match(document, /<h1>Open app in Evenfire<\/h1>/)
+ assert.doesNotMatch(document, /agentic-task-board<\/h1>/)
+ assert.match(document, /install or update to the latest Evenfire Desktop/)
assert.match(document, /class="open-button"/)
assert.doesNotMatch(document, /login|authenticate|authorization/i)
})
@@ -52,7 +72,9 @@ test('buildEvenfireDesktopAppContentSecurityPolicy authorizes only the nonce-bea
const policy = buildEvenfireDesktopAppContentSecurityPolicy(scriptNonce)
assert.match(policy, new RegExp(`script-src 'nonce-${scriptNonce}'`))
+ assert.match(policy, new RegExp(`style-src 'nonce-${scriptNonce}'`))
assert.doesNotMatch(policy, /script-src 'unsafe-inline'/)
+ assert.doesNotMatch(policy, /style-src 'unsafe-inline'/)
})
test('buildEvenfireDesktopAppRedirectDocument rejects unrelated protocols', () => {
diff --git a/profile-ui/test/desktopAppRoute.test.ts b/profile-ui/test/desktopAppRoute.test.ts
new file mode 100644
index 000000000..f0d5d0bd4
--- /dev/null
+++ b/profile-ui/test/desktopAppRoute.test.ts
@@ -0,0 +1,31 @@
+import assert from 'node:assert/strict'
+import test from 'node:test'
+import { GET } from '../app/open/apps/[recipeNs]/[recipeName]/route'
+
+const routeContext = {
+ params: Promise.resolve({
+ recipeNs: 'sandbox-recipes',
+ recipeName: 'agentic-task-board',
+ }),
+}
+
+test('desktop app handoff leaves an omitted path to the recipe default', async () => {
+ const response = await GET(new Request('https://profile.example/open/apps/ns/app'), routeContext)
+ const body = await response.text()
+
+ assert.equal(response.status, 200)
+ assert.match(body, /evenfire:\/\/app\/sandbox-recipes\/agentic-task-board/)
+ assert.doesNotMatch(body, /[?&]path=/)
+ assert.match(body, /Open app in Evenfire/)
+})
+
+test('desktop app handoff rejects dot-segment routes with hardened error headers', async () => {
+ const request = new Request(
+ 'https://profile.example/open/apps/ns/app?path=%2Fsafe%2F%252e%252e%2Fadmin'
+ )
+ const response = await GET(request, routeContext)
+
+ assert.equal(response.status, 400)
+ assert.equal(response.headers.get('referrer-policy'), 'no-referrer')
+ assert.equal(response.headers.get('x-content-type-options'), 'nosniff')
+})
diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.json
index fae2c8dd2..69bb9f161 100644
--- a/rpc-proxy/package-lock.json
+++ b/rpc-proxy/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.51",
+ "version": "0.1.50",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-rpc-proxy",
- "version": "0.1.51",
+ "version": "0.1.50",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/rpc-proxy/package.json b/rpc-proxy/package.json
index 93641a581..8d54ca64b 100644
--- a/rpc-proxy/package.json
+++ b/rpc-proxy/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.51",
+ "version": "0.1.50",
"description": "External-facing RPC proxy for tenant-scoped MCP access",
"main": "dist/main.js",
"engines": {