Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): align Markdown search matches (R1-M6)
Josué6c3136c3ffdf
diff --git a/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsx b/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsxindex e01d14dac..9beaaf7d2 100644--- a/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsx+++ b/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsx@@ -12,6 +12,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'import { cleanup, fireEvent, render, screen } from '@testing-library/react'import userEvent from '@testing-library/user-event'import type { MessageToolStep } from '../../../../../src/types'+import { findLoadedChatMessageMatches } from '../../../lib/chatLocalSearch'import type { AgentChatMessage, TaskProgress } from '../../../uiTypes'// vi.mock calls are hoisted above this import, so ChatThread binds the mocks.import { ChatThread } from '../ChatThread'@@ -107,21 +108,23 @@ function setThreadState(describe('ChatThread local-search highlighting', () => {it('renders every plain and Markdown match and distinguishes the selected occurrence', () => {+ const messages: AgentChatMessage[] = [+ { ...userMsg, content: 'Needle then needle' },+ {+ id: 'turn-1-assistant',+ role: 'assistant',+ content: 'A **needle** in a [needle link](https://needle.example/needle).',+ timestamp: 2,+ },+ ]setThreadState([{role: 'user',- items: [{ ...userMsg, content: 'Needle then needle' }],+ items: [messages[0]!],},{role: 'assistant',- items: [- {- id: 'turn-1-assistant',- role: 'assistant',- content: 'A **needle** in a [needle link](https://example.com).',- timestamp: 2,- },- ],+ items: [messages[1]!],},])threadStateValue.localSearchQuery = 'needle'@@ -132,10 +135,12 @@ describe('ChatThread local-search highlighting', () => {const { rerender } = render(<ChatThread />)- expect(document.querySelectorAll('.chat-search-match')).toHaveLength(4)+ const renderedMatches = document.querySelectorAll('.chat-search-match')+ expect(renderedMatches).toHaveLength(4)+ expect(findLoadedChatMessageMatches(messages, 'needle')).toHaveLength(renderedMatches.length)const active = screen.getByTestId('chat-search-current-match')expect(active.textContent).toBe('needle')- expect(active.closest('a')?.getAttribute('href')).toBe('https://example.com')+ expect(active.closest('a')?.getAttribute('href')).toBe('https://needle.example/needle')threadStateValue.localSearchCurrentMatch = { messageId: 'turn-1-user', occurrence: 1 }rerender(<ChatThread />)diff --git a/desktop-app/ui/src/lib/__tests__/chatLocalSearch.test.ts b/desktop-app/ui/src/lib/__tests__/chatLocalSearch.test.tsindex ef437a8c4..24bbc0684 100644--- a/desktop-app/ui/src/lib/__tests__/chatLocalSearch.test.ts+++ b/desktop-app/ui/src/lib/__tests__/chatLocalSearch.test.ts@@ -1,6 +1,10 @@import { describe, expect, it } from 'vitest'import type { AgentChatMessage } from '../../uiTypes'-import { findLoadedChatMessageMatches, wrapMatchIndex } from '../chatLocalSearch'+import {+ findLoadedChatMessageMatches,+ markdownSearchableText,+ wrapMatchIndex,+} from '../chatLocalSearch'function message(id: string, content: string, role: AgentChatMessage['role'] = 'assistant') {return { id, content, role, timestamp: 1 } satisfies AgentChatMessage@@ -31,6 +35,24 @@ describe('loaded chat local search', () => {).toEqual([])})+ it('counts visible Markdown text without hidden destinations or syntax metadata', () => {+ const content = [+ '# Needle heading',+ '[needle link](https://needle.example/path "needle title")',+ '```needle-language',+ 'needle in code',+ '```',+ '[hidden-ref]: https://example.test/needle "needle title"',+ ].join('\n')++ expect(markdownSearchableText(content)).not.toContain('needle.example')+ expect(findLoadedChatMessageMatches([message('assistant', content)], 'needle')).toEqual([+ { messageId: 'assistant', occurrence: 0 },+ { messageId: 'assistant', occurrence: 1 },+ { messageId: 'assistant', occurrence: 2 },+ ])+ })+it('wraps forward and backward through loaded matches', () => {expect(wrapMatchIndex(2, 3, 1)).toBe(0)expect(wrapMatchIndex(0, 3, -1)).toBe(2)diff --git a/desktop-app/ui/src/lib/chatLocalSearch.ts b/desktop-app/ui/src/lib/chatLocalSearch.tsindex 02be16fee..550328302 100644--- a/desktop-app/ui/src/lib/chatLocalSearch.ts+++ b/desktop-app/ui/src/lib/chatLocalSearch.ts@@ -11,6 +11,35 @@ export function chatMessageDomId(messageId: string): string {return `chat-message-${encodeURIComponent(messageId)}`}+/**+ * Project Markdown source to the text ReactMarkdown makes searchable. This+ * intentionally keeps labels and code contents while masking metadata that is+ * not rendered as message text (destinations, reference definitions, tags,+ * and fenced-code language identifiers).+ */+export function markdownSearchableText(source: string): string {+ let fence: '`' | '~' | null = null+ return source+ .split(/(\r?\n)/)+ .map(part => {+ if (part === '\n' || part === '\r\n') return part+ const fenceMatch = part.match(/^\s{0,3}(`{3,}|~{3,})/)+ if (fenceMatch) {+ const marker = fenceMatch[1]?.[0] as '`' | '~'+ if (fence === null) fence = marker+ else if (fence === marker) fence = null+ return ' '.repeat(part.length)+ }+ if (fence !== null) return part+ if (/^\s{0,3}\[[^\]]+\]:\s*/.test(part)) return ' '.repeat(part.length)+ return part+ .replace(/\]\((?:\\.|[^)])*\)/g, match => `]${' '.repeat(match.length - 1)}`)+ .replace(/\]\[[^\]]+\]/g, match => `]${' '.repeat(match.length - 1)}`)+ .replace(/<\/?[A-Za-z][A-Za-z0-9-]*(?:\s[^>]*)?\/?>/g, match => ' '.repeat(match.length))+ })+ .join('')+}+export function findLoadedChatMessageMatches(messages: AgentChatMessage[],query: string@@ -22,7 +51,7 @@ export function findLoadedChatMessageMatches(const displayed =message.role === 'user'? (parseChatMessageDisplay(message.content)?.content ?? message.content)- : message.content+ : markdownSearchableText(message.content)const haystack = displayed.toLocaleLowerCase()let offset = 0let occurrence = 0diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.cssindex 852cec55c..0a2bfadc3 100644--- a/desktop-app/ui/src/styles.css+++ b/desktop-app/ui/src/styles.css@@ -14971,7 +14971,6 @@ pre {background: rgba(var(--warning-rgb), 0.3);border-radius: 2px;color: inherit;- padding: 0 1px;}.chat-search-match--active {