type RuntimeInvalidationReason = 'account-health' | 'publish-task-lease' type RuntimeInvalidationListener = (event: { reason: RuntimeInvalidationReason at: number accountId?: string taskId?: string }) => void const listeners = new Set() export function emitRuntimeInvalidated( reason: RuntimeInvalidationReason, details: { accountId?: string; taskId?: string } = {}, ): void { const event = { reason, at: Date.now(), ...details, } as const for (const listener of listeners) { try { listener(event) } catch (error) { console.warn('[desktop-runtime] invalidation listener failed', { reason, message: error instanceof Error ? error.message : String(error), }) } } } export function onRuntimeInvalidated(listener: RuntimeInvalidationListener): () => void { listeners.add(listener) return () => { listeners.delete(listener) } }