Skip to content

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

TypeScript

feat(desktop): name app tabs after the embed document.title (§2)

Diego Zacarias443eede5ad89
diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.ts
index 25d25fe82..1d40884df 100644
--- a/desktop-app/src/appService.ts
+++ b/desktop-app/src/appService.ts
@@ -4827,6 +4827,7 @@ export class AppService {
onClosed?: () => void
onRefreshError?: (message: string) => void
onOauthError?: (message: string) => void
+ onTitleChanged?: (title: string) => void
}): Promise<void> {
return this.enqueueSandboxUiLifecycle(() => this.openSandboxUiNow(args))
}
@@ -4842,6 +4843,7 @@ export class AppService {
onClosed?: () => void
onRefreshError?: (message: string) => void
onOauthError?: (message: string) => void
+ onTitleChanged?: (title: string) => void
}): Promise<void> {
const recipeNs = String(args.recipeNs || '').trim()
const recipeName = String(args.recipeName || '').trim()
@@ -4875,6 +4877,9 @@ export class AppService {
if (!active || !surface) return
void active.openGfsResourceFromNavigation(surface.webContentsId, uri)
},
+ onTitleChanged: title => {
+ args.onTitleChanged?.(title)
+ },
onOauthAuthorize: (oauthClientId, background) => {
void this.requestSandboxUiOauthAuthorize(
recipeNs,
diff --git a/desktop-app/src/ipc.ts b/desktop-app/src/ipc.ts
index c066cc0ea..e6fc2e4ed 100644
--- a/desktop-app/src/ipc.ts
+++ b/desktop-app/src/ipc.ts
@@ -1744,6 +1744,10 @@ export function registerIpcHandlers(service: AppService): void {
if (parentWindow.isDestroyed()) return
parentWindow.webContents.send('sandboxUi:refreshError', { appRef, message })
},
+ onTitleChanged: title => {
+ if (parentWindow.isDestroyed()) return
+ parentWindow.webContents.send('sandboxUi:titleChanged', { appRef, title })
+ },
})
}
)
diff --git a/desktop-app/src/preload.ts b/desktop-app/src/preload.ts
index 59b2d2db7..52dccc4c7 100644
--- a/desktop-app/src/preload.ts
+++ b/desktop-app/src/preload.ts
@@ -676,6 +676,11 @@ const clerum = Object.freeze({
ipcRenderer.on('sandboxUi:refreshError', listener)
return () => ipcRenderer.off('sandboxUi:refreshError', listener)
},
+ onTitleChanged: (callback: (args: { appRef: string; title: string }) => void) => {
+ const listener = (_event: unknown, args: { appRef: string; title: string }) => callback(args)
+ ipcRenderer.on('sandboxUi:titleChanged', listener)
+ return () => ipcRenderer.off('sandboxUi:titleChanged', listener)
+ },
},
/**
* Plugin permissions, trusted-renderer half: the consent modal and the
diff --git a/desktop-app/src/renderer.d.ts b/desktop-app/src/renderer.d.ts
index 8a3b6f05f..bff458b64 100644
--- a/desktop-app/src/renderer.d.ts
+++ b/desktop-app/src/renderer.d.ts
@@ -756,6 +756,7 @@ declare global {
onRefreshError: (
callback: (args: { appRef: string; message: string }) => void
) => () => void
+ onTitleChanged: (callback: (args: { appRef: string; title: string }) => void) => () => void
}
pluginSdk: {
onConsentRequested: (callback: (request: PluginConsentRequest) => void) => () => void
diff --git a/desktop-app/src/sandboxUiDriver.ts b/desktop-app/src/sandboxUiDriver.ts
index 2b49b4836..d0ad53a9b 100644
--- a/desktop-app/src/sandboxUiDriver.ts
+++ b/desktop-app/src/sandboxUiDriver.ts
@@ -104,6 +104,13 @@ export type MountSandboxUiArgs = {
bounds: SandboxUiBounds
routePath?: string
onClosed?: () => void
+ /**
+ * Fired when the embedded document's `<title>` changes (`page-title-updated`).
+ * The driver only forwards the plugin-controlled title; the renderer decides
+ * whether to surface it (its app tab title) and trims/ignores empty values.
+ * Read-only: it never grants the embed any privilege.
+ */
+ onTitleChanged?: (title: string) => void
/**
* Spec §9.9 — recipe-author Connect button affordance. Fired when the
* embed navigates to `clerum://oauth?clientId=…`. The driver's only
@@ -344,6 +351,7 @@ export async function mountSandboxUiView(args: MountSandboxUiArgs): Promise<void
bounds,
routePath,
onClosed,
+ onTitleChanged,
} = args
if (parentWindow.isDestroyed()) {
@@ -472,11 +480,19 @@ export async function mountSandboxUiView(args: MountSandboxUiArgs): Promise<void
const onDocumentReady = (): void => {
if (active?.view === view) active.documentReady = true
}
+ // Forward the embed's live `document.title` so the renderer can name its app
+ // tab after it (mirrors the URL-report pattern). The title is plugin content,
+ // so it stays read-only — the renderer trims/ignores empty values.
+ const onPageTitleUpdated = (_event: Electron.Event, title: string): void => {
+ if (active?.view === view) onTitleChanged?.(title)
+ }
view.webContents.on('did-start-navigation', onDidStartNavigation)
view.webContents.on('did-finish-load', onDocumentReady)
+ view.webContents.on('page-title-updated', onPageTitleUpdated)
active.cleanupDocumentLifecycle = () => {
view.webContents.removeListener('did-start-navigation', onDidStartNavigation)
view.webContents.removeListener('did-finish-load', onDocumentReady)
+ view.webContents.removeListener('page-title-updated', onPageTitleUpdated)
}
active.cleanupShortcutRouting = wireDesktopShortcutRouting({
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index 3f68666ac..f483c5822 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -72,6 +72,7 @@ import {
selectWorkspaceTab,
selectWorkspaceTabAt,
setAppTabSavedRoutePath,
+ setAppTabTitle,
} from '@lib/workspaceTabs'
import type { WorkspaceTab } from '@lib/workspaceTabs.types'
import { AgentsPage } from '@pages/AgentsPage'
@@ -1288,6 +1289,24 @@ export function App() {
return unsubscribe
}, [setPendingSandboxUiDeepLinkState])
+ // Name the live app tab after the embed's `document.title` (mini-spec 06 §2).
+ // Only the tab whose embed is live (`liveSandboxUiTabIdRef`) is renamed, and
+ // only when the reported `appRef` still matches it, so a late title event from
+ // a torn-down embed can't relabel whichever app is live now. The store ignores
+ // empty titles, so the tab keeps its `app.label` until a real title arrives.
+ React.useEffect(() => {
+ const off = window.clerum.sandboxUi.onTitleChanged?.(({ appRef, title }) => {
+ const tabId = liveSandboxUiTabIdRef.current
+ if (!tabId) return
+ setWorkspaceTabs(state => {
+ const tab = state.tabs.find(candidate => candidate.id === tabId && candidate.kind === 'app')
+ if (!tab || tab.app?.appRef !== appRef) return state
+ return setAppTabTitle(state, tabId, title)
+ })
+ })
+ return () => off?.()
+ }, [setWorkspaceTabs])
+
React.useEffect(() => {
if (
!canProcessSandboxUiDeepLinks(
diff --git a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
index 56b7ff3c1..874b87492 100644
--- a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
+++ b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
@@ -959,6 +959,92 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
})
})
+// Mini-spec 06 §2 — an app tab is named after the embed's live `document.title`.
+// The main process forwards `page-title-updated` over `sandboxUi.onTitleChanged`;
+// App renames the LIVE app tab (never a background one), ignoring empty titles so
+// the tab keeps its `app.label`. Driven through the real store producer + the real
+// WorkspaceTabStrip so the assertion is on the rendered tab label (T4).
+describe('App app-tab title — live document.title (mini-spec 06 §2)', () => {
+ let currentController: AppController
+ let titleChangedCb: ((args: { appRef: string; title: string }) => void) | null
+
+ beforeEach(() => {
+ vi.clearAllMocks()
+ sidebarHarness.props = null
+ sandboxUiPageHarness.props = null
+ appHeaderHarness.props = null
+ appHeaderHarness.openNotification = null
+ titleChangedCb = null
+ currentController = makeController()
+ vi.mocked(useAppController).mockImplementation(() => useReactiveController(currentController))
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ shortcuts: { onCommand: vi.fn(() => vi.fn()) },
+ app: { rendererReady: vi.fn().mockResolvedValue(undefined) },
+ sandboxUi: {
+ listApps: vi.fn().mockResolvedValue({ apps: [] }),
+ listPendingDeepLinks: vi.fn().mockResolvedValue({ links: [] }),
+ clearPendingDeepLinks: vi.fn().mockResolvedValue(undefined),
+ onDeepLink: vi.fn(() => vi.fn()),
+ onTitleChanged: vi.fn((cb: (args: { appRef: string; title: string }) => void) => {
+ titleChangedCb = cb
+ return vi.fn()
+ }),
+ setVisible: vi.fn().mockResolvedValue(undefined),
+ setBounds: vi.fn().mockResolvedValue(undefined),
+ focusActive: vi.fn().mockResolvedValue(true),
+ close: vi.fn().mockResolvedValue(undefined),
+ },
+ } as unknown as Window['clerum'],
+ })
+ })
+
+ afterEach(() => {
+ cleanup()
+ delete (window as { clerum?: unknown }).clerum
+ })
+
+ it('renames the live app tab to the embed document.title, and an empty title keeps the label', () => {
+ render(<App />)
+
+ // Launch an app: its tab starts named after the registry label ('App').
+ act(() => {
+ sidebarHarness.props?.onOpenSandboxUiApp?.({
+ appRef: 'ns/app',
+ label: 'App',
+ defaultPath: '/',
+ })
+ })
+ expect(screen.getByRole('button', { name: 'App' })).toBeTruthy()
+
+ // The embed reports its live document.title → the tab renames to it.
+ act(() => titleChangedCb?.({ appRef: 'ns/app', title: 'Ticket 42 — Acme' }))
+ expect(screen.getByRole('button', { name: 'Ticket 42 — Acme' })).toBeTruthy()
+ expect(screen.queryByRole('button', { name: 'App' })).toBeNull()
+
+ // A subsequent EMPTY title (mid-navigation blank) must not blank the label —
+ // the tab keeps the last real title.
+ act(() => titleChangedCb?.({ appRef: 'ns/app', title: ' ' }))
+ expect(screen.getByRole('button', { name: 'Ticket 42 — Acme' })).toBeTruthy()
+ })
+
+ it('ignores a title event whose appRef does not match the live tab', () => {
+ render(<App />)
+ act(() => {
+ sidebarHarness.props?.onOpenSandboxUiApp?.({
+ appRef: 'ns/app',
+ label: 'App',
+ defaultPath: '/',
+ })
+ })
+ // A stale title from a different app must not relabel the live tab.
+ act(() => titleChangedCb?.({ appRef: 'ns/other', title: 'Wrong' }))
+ expect(screen.getByRole('button', { name: 'App' })).toBeTruthy()
+ expect(screen.queryByRole('button', { name: 'Wrong' })).toBeNull()
+ })
+})
+
// Mini-spec 05: below the minimum panel width the drawer is SUPPRESSED (hidden,
// app takes full width) without clearing the user's open intent, so it reappears
// when the window re-widens; a MANUAL close clears the intent, so it stays gone.
diff --git a/desktop-app/ui/src/lib/__tests__/workspaceTabs.test.ts b/desktop-app/ui/src/lib/__tests__/workspaceTabs.test.ts
index 998ed030c..9838e9739 100644
--- a/desktop-app/ui/src/lib/__tests__/workspaceTabs.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/workspaceTabs.test.ts
@@ -18,6 +18,7 @@ import {
selectWorkspaceTab,
selectWorkspaceTabAt,
setAppTabSavedRoutePath,
+ setAppTabTitle,
} from '../workspaceTabs'
import type { ActiveChat, SettingsSection, WorkspaceTabsState } from '../workspaceTabs.types'
@@ -166,6 +167,56 @@ describe('workspaceTabs — setAppTabSavedRoutePath (mini-spec 05 §3)', () => {
})
})
+describe('workspaceTabs — setAppTabTitle (mini-spec 06 §2)', () => {
+ it('renames the matching app tab and leaves siblings untouched', () => {
+ let state = createEmptyWorkspaceTabsState()
+ state = openAppTab(state, { id: 'app-1', appRef: 'eventasks', title: 'App' })
+ state = openAppTab(state, { id: 'app-2', appRef: 'eventasks', title: 'App' })
+
+ state = setAppTabTitle(state, 'app-1', 'Ticket 42 — Acme')
+
+ expect(state.tabs.find(t => t.id === 'app-1')?.title).toBe('Ticket 42 — Acme')
+ expect(state.tabs.find(t => t.id === 'app-2')?.title).toBe('App')
+ expect(state.activeTabId).toBe('app-2') // selection is not disturbed
+ })
+
+ it('trims the reported title before storing it', () => {
+ let state = createEmptyWorkspaceTabsState()
+ state = openAppTab(state, { id: 'app-1', appRef: 'eventasks', title: 'App' })
+ state = setAppTabTitle(state, 'app-1', ' Padded title ')
+ expect(state.tabs.find(t => t.id === 'app-1')?.title).toBe('Padded title')
+ })
+
+ it('is a no-op (same reference) when the title is unchanged', () => {
+ let state = createEmptyWorkspaceTabsState()
+ state = openAppTab(state, { id: 'app-1', appRef: 'eventasks', title: 'Doc' })
+ expect(setAppTabTitle(state, 'app-1', 'Doc')).toBe(state)
+ // A trimmed value equal to the stored one is likewise a no-op.
+ expect(setAppTabTitle(state, 'app-1', ' Doc ')).toBe(state)
+ })
+
+ it('ignores an empty / whitespace-only title, keeping the previous one', () => {
+ let state = createEmptyWorkspaceTabsState()
+ state = openAppTab(state, { id: 'app-1', appRef: 'eventasks', title: 'Doc' })
+ expect(setAppTabTitle(state, 'app-1', '')).toBe(state)
+ expect(setAppTabTitle(state, 'app-1', ' ')).toBe(state)
+ expect(state.tabs.find(t => t.id === 'app-1')?.title).toBe('Doc')
+ })
+
+ it('is a no-op when the tab is missing (persist racing a close) or not an app', () => {
+ let state = createEmptyWorkspaceTabsState()
+ state = openAppTab(state, { id: 'app-1', appRef: 'eventasks', title: 'App' })
+ state = openChatTab(state, { id: 'chat-1', agentRef: 'a', chatId: 'c1', title: 'Chat' })
+ state = openFilesTab(state, { id: 'files-1' })
+
+ expect(setAppTabTitle(state, 'gone', 'X')).toBe(state)
+ // A chat / files tab is never renamed by the app-title path.
+ expect(setAppTabTitle(state, 'chat-1', 'X')).toBe(state)
+ expect(setAppTabTitle(state, 'files-1', 'X')).toBe(state)
+ expect(state.tabs.find(t => t.id === 'chat-1')?.title).toBe('Chat')
+ })
+})
+
describe('workspaceTabs — new chat (blank) with kind guard', () => {
it('reuses the active blank chat tab (aligns the agent)', () => {
let state = createWorkspaceTabsState('boot', null)
diff --git a/desktop-app/ui/src/lib/workspaceTabs.ts b/desktop-app/ui/src/lib/workspaceTabs.ts
index 19b800383..21e164754 100644
--- a/desktop-app/ui/src/lib/workspaceTabs.ts
+++ b/desktop-app/ui/src/lib/workspaceTabs.ts
@@ -189,6 +189,31 @@ export function setAppTabSavedRoutePath(
}
}
+/**
+ * Persist the live `document.title` of an app embed on its tab (mini-spec 06
+ * §2), so the strip names the tab after what the plugin currently shows. A
+ * mirror of `setAppTabSavedRoutePath`: a no-op (same reference) when the tab is
+ * missing, is not an app tab, or already holds this title, so a `setState`
+ * bails out. An empty / whitespace-only title is IGNORED (keeps the previous
+ * title) — a mid-navigation blank must not blank the tab label; precedence
+ * `document.title → app.label → 'App'` is resolved by the caller, not here.
+ */
+export function setAppTabTitle(
+ state: WorkspaceTabsState,
+ tabId: string,
+ title: string
+): WorkspaceTabsState {
+ const trimmed = title.trim()
+ if (!trimmed) return state
+ const target = state.tabs.find(tab => tab.id === tabId && tab.kind === 'app')
+ if (!target) return state
+ if (target.title === trimmed) return state
+ return {
+ ...state,
+ tabs: state.tabs.map(tab => (tab.id === tabId ? { ...tab, title: trimmed } : tab)),
+ }
+}
+
/** Files: single instance — focus the existing tab if present (R8). */
export function openFilesTab(
state: WorkspaceTabsState,