Skip to content

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

TypeScript

perf(desktop): summarize activity from chat metadata

Josué0754cc0ba9ed
diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.json
index 57ec4a5b7..d6e5dcb7b 100644
--- a/desktop-app/package-lock.json
+++ b/desktop-app/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "evenfire",
- "version": "0.1.313",
+ "version": "0.1.314",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "evenfire",
- "version": "0.1.313",
+ "version": "0.1.314",
"license": "MPL-2.0",
"dependencies": {
"@tanstack/react-query": "5.100.10",
diff --git a/desktop-app/package.json b/desktop-app/package.json
index fdf6979eb..429bbcc3c 100644
--- a/desktop-app/package.json
+++ b/desktop-app/package.json
@@ -1,7 +1,7 @@
{
"name": "evenfire",
"productName": "Evenfire",
- "version": "0.1.313",
+ "version": "0.1.314",
"private": true,
"license": "MPL-2.0",
"description": "Evenfire desktop client for secure agent and workflow access",
diff --git a/desktop-app/src/__tests__/chatStore.test.ts b/desktop-app/src/__tests__/chatStore.test.ts
index 714ef0125..32de92eae 100644
--- a/desktop-app/src/__tests__/chatStore.test.ts
+++ b/desktop-app/src/__tests__/chatStore.test.ts
@@ -143,6 +143,31 @@ describe('messages', () => {
expect(chat!.messageCount).toBe(2)
})
+ it('persists activity aggregates in the chat index', async () => {
+ await store.createChat('agent-1', 'activity-1')
+ await store.saveMessages('agent-1', 'activity-1', [
+ { id: 'm1', role: 'user', content: 'a', timestamp: 1 },
+ {
+ id: 'm2',
+ role: 'assistant',
+ content: 'failed',
+ timestamp: 2,
+ isError: true,
+ toolSteps: [
+ { toolName: 'search', displayName: 'Search', state: 'completed' },
+ { toolName: 'write', displayName: 'Write', state: 'error' },
+ ],
+ },
+ ])
+
+ const chat = (await store.listChats('agent-1')).find(item => item.id === 'activity-1')
+ expect(chat).toMatchObject({
+ messageCount: 2,
+ errorCount: 1,
+ toolCallCount: 2,
+ })
+ })
+
it('persists task_id and writes the v2 chat file (D.3)', async () => {
await store.createChat('agent-1', 'v2-1')
await store.saveMessages('agent-1', 'v2-1', [
diff --git a/desktop-app/src/chatStore.ts b/desktop-app/src/chatStore.ts
index 1a5db8347..00599fc65 100644
--- a/desktop-app/src/chatStore.ts
+++ b/desktop-app/src/chatStore.ts
@@ -204,6 +204,11 @@ export class ChatStore {
const chat = index.chats.find(c => c.id === chatId)
if (chat) {
chat.messageCount = messages.length
+ chat.errorCount = messages.reduce((total, message) => total + (message.isError ? 1 : 0), 0)
+ chat.toolCallCount = messages.reduce(
+ (total, message) => total + (message.toolSteps?.length ?? 0),
+ 0
+ )
chat.updatedAt = new Date().toISOString()
await this.saveIndex(agentRef, index)
}
diff --git a/desktop-app/src/types.ts b/desktop-app/src/types.ts
index 92c1a3a19..228eff520 100644
--- a/desktop-app/src/types.ts
+++ b/desktop-app/src/types.ts
@@ -789,6 +789,9 @@ export interface ChatMetadata {
createdAt: string // ISO 8601
updatedAt: string // ISO 8601
messageCount: number
+ /** Persisted activity aggregates keep dashboards from opening complete chat files. */
+ errorCount?: number
+ toolCallCount?: number
/** D.5: a task terminated while this chat was NOT the active view. Drives the
* sidebar "completed_unread" badge; persisted so it survives an app restart. */
unreadTerminal?: boolean
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useActivityController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useActivityController.test.tsx
new file mode 100644
index 000000000..7a8c122a5
--- /dev/null
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useActivityController.test.tsx
@@ -0,0 +1,68 @@
+// @vitest-environment jsdom
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { renderHook } from '@testing-library/react'
+import { useActivityController } from '../useActivityController'
+
+const AGENT_A = ['agent-a']
+const EMPTY_PROGRESS = {}
+
+function installChatIndexMock() {
+ const getIndex = vi.fn(async (agentRef: string) => ({
+ version: 2,
+ lastActiveChatId: null,
+ onboardingDismissed: false,
+ chats: [
+ {
+ id: `${agentRef}-chat`,
+ title: 'Chat',
+ createdAt: '2026-07-20T00:00:00.000Z',
+ updatedAt: '2026-07-22T00:00:00.000Z',
+ messageCount: 3,
+ },
+ ],
+ }))
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ chat: { getIndex },
+ },
+ })
+ return getIndex
+}
+
+describe('useActivityController', () => {
+ afterEach(() => {
+ vi.restoreAllMocks()
+ delete (window as { clerum?: unknown }).clerum
+ })
+
+ it('computes activity from index metadata without reading conversation histories', () => {
+ installChatIndexMock()
+ const { result } = renderHook(() =>
+ useActivityController({
+ selectedAgent: 'agent-a',
+ isAuthenticated: true,
+ chatList: [
+ {
+ id: 'chat-1',
+ title: 'One',
+ createdAt: '2026-07-22T00:00:00.000Z',
+ updatedAt: '2026-07-22T00:00:00.000Z',
+ messageCount: 12,
+ errorCount: 2,
+ toolCallCount: 4,
+ },
+ ],
+ progressByAgentMessage: EMPTY_PROGRESS,
+ agentNames: AGENT_A,
+ })
+ )
+
+ expect(result.current.selectedAgentActivitySummary).toMatchObject({
+ conversations: 1,
+ messages: 12,
+ errors: 2,
+ toolCalls: 4,
+ })
+ })
+})
diff --git a/desktop-app/ui/src/hooks/domain/useActivityController.ts b/desktop-app/ui/src/hooks/domain/useActivityController.ts
index 09e9db677..8cb7702b6 100644
--- a/desktop-app/ui/src/hooks/domain/useActivityController.ts
+++ b/desktop-app/ui/src/hooks/domain/useActivityController.ts
@@ -1,15 +1,8 @@
-import { useEffect, useState } from 'react'
+import { useEffect, useMemo, useState } from 'react'
import type { TaskProgress } from '../../uiTypes'
import { useChatStore } from '../useChatStore'
import type { SidebarChatEntry } from './useAgentChatController'
-const ACTIVITY_SUMMARY_CHAT_SCAN_LIMIT = 20
-
-function getChatUpdatedTimestamp(chat: { updatedAt: string }): number {
- const timestamp = Date.parse(chat.updatedAt)
- return Number.isNaN(timestamp) ? 0 : timestamp
-}
-
interface UseActivityControllerParams {
selectedAgent: string | null
isAuthenticated: boolean
@@ -30,13 +23,60 @@ export function useActivityController({
const [agentLastActiveByAgent, setAgentLastActiveByAgent] = useState<
Record<string, string | null>
>({})
- const [selectedAgentActivitySummary, setSelectedAgentActivitySummary] = useState({
- conversations: 0,
- messages: 0,
- toolCalls: 0,
- errors: 0,
- conversationsPerDay: [] as Array<{ dayLabel: string; count: number }>,
- })
+ const selectedAgentActivitySummary = useMemo(() => {
+ if (!selectedAgent) {
+ return {
+ conversations: 0,
+ messages: 0,
+ toolCalls: 0,
+ errors: 0,
+ conversationsPerDay: [] as Array<{ dayLabel: string; count: number }>,
+ }
+ }
+
+ const dateCursor = new Date()
+ const dayKeys: string[] = []
+ for (let index = 6; index >= 0; index -= 1) {
+ const day = new Date(dateCursor)
+ day.setDate(day.getDate() - index)
+ dayKeys.push(day.toISOString().slice(0, 10))
+ }
+
+ const conversationsPerDayMap = new Map<string, number>(dayKeys.map(key => [key, 0]))
+ let totalMessages = 0
+ let totalErrors = 0
+ let persistedToolCalls = 0
+
+ for (const chat of chatList) {
+ totalMessages += chat.messageCount || 0
+ totalErrors += chat.errorCount || 0
+ persistedToolCalls += chat.toolCallCount || 0
+
+ const chatTimestamp = Date.parse(chat.updatedAt)
+ if (Number.isNaN(chatTimestamp)) continue
+ const chatDateKey = new Date(chatTimestamp).toISOString().slice(0, 10)
+ if (conversationsPerDayMap.has(chatDateKey)) {
+ conversationsPerDayMap.set(chatDateKey, (conversationsPerDayMap.get(chatDateKey) || 0) + 1)
+ }
+ }
+
+ const liveToolCalls = Object.values(progressByAgentMessage[selectedAgent] || {}).reduce(
+ (total, progress) => total + progress.steps.length,
+ 0
+ )
+ const formatter = new Intl.DateTimeFormat(undefined, { month: 'short', day: 'numeric' })
+
+ return {
+ conversations: chatList.length,
+ messages: totalMessages,
+ toolCalls: Math.max(persistedToolCalls, liveToolCalls),
+ errors: totalErrors,
+ conversationsPerDay: [...conversationsPerDayMap.entries()].map(([dayKey, count]) => ({
+ dayLabel: formatter.format(new Date(dayKey)),
+ count,
+ })),
+ }
+ }, [chatList, progressByAgentMessage, selectedAgent])
// Compute agentLastActiveByAgent for all agents
useEffect(() => {
@@ -73,84 +113,6 @@ export function useActivityController({
}
}, [agentNames, chatStore.getIndex, isAuthenticated])
- // Compute selectedAgentActivitySummary
- useEffect(() => {
- if (!selectedAgent) {
- setSelectedAgentActivitySummary({
- conversations: 0,
- messages: 0,
- toolCalls: 0,
- errors: 0,
- conversationsPerDay: [],
- })
- return
- }
-
- let cancelled = false
- ;(async () => {
- const dateCursor = new Date()
- const dayKeys: string[] = []
- for (let index = 6; index >= 0; index -= 1) {
- const day = new Date(dateCursor)
- day.setDate(day.getDate() - index)
- dayKeys.push(day.toISOString().slice(0, 10))
- }
- const conversationsPerDayMap = new Map<string, number>(dayKeys.map(key => [key, 0]))
- for (const chat of chatList) {
- const chatTimestamp = Date.parse(chat.updatedAt)
- if (Number.isNaN(chatTimestamp)) continue
- const chatDateKey = new Date(chatTimestamp).toISOString().slice(0, 10)
- if (conversationsPerDayMap.has(chatDateKey)) {
- conversationsPerDayMap.set(
- chatDateKey,
- (conversationsPerDayMap.get(chatDateKey) || 0) + 1
- )
- }
- }
-
- let totalMessages = 0
- let totalErrors = 0
- if (chatList.length > 0) {
- const chatsToScan = [...chatList]
- .sort((left, right) => getChatUpdatedTimestamp(right) - getChatUpdatedTimestamp(left))
- .slice(0, ACTIVITY_SUMMARY_CHAT_SCAN_LIMIT)
- const messageLists = await Promise.all(
- chatsToScan.map(chat => chatStore.loadMessages(selectedAgent, chat.id).catch(() => []))
- )
- for (const messages of messageLists) {
- totalMessages += messages.length
- totalErrors += messages.filter((message: any) => message.isError).length
- }
- }
-
- const progressByMessage = progressByAgentMessage[selectedAgent] || {}
- let totalToolCalls = 0
- for (const progress of Object.values(progressByMessage)) {
- totalToolCalls += progress.steps.length
- }
-
- const formatter = new Intl.DateTimeFormat(undefined, { month: 'short', day: 'numeric' })
- const conversationsPerDay = [...conversationsPerDayMap.entries()].map(([dayKey, count]) => ({
- dayLabel: formatter.format(new Date(dayKey)),
- count,
- }))
-
- if (!cancelled) {
- setSelectedAgentActivitySummary({
- conversations: chatList.length,
- messages: totalMessages,
- toolCalls: totalToolCalls,
- errors: totalErrors,
- conversationsPerDay,
- })
- }
- })()
-
- return () => {
- cancelled = true
- }
- }, [chatList, chatStore.loadMessages, progressByAgentMessage, selectedAgent])
-
return {
agentLastActiveByAgent,
selectedAgentActivitySummary,