Skip to content

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

TypeScript

fix(desktop): preserve fenced code search (R1-M7)

Josuéb01509c9fd0d
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.tsx
index 9beaaf7d2..e275c70a7 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
@@ -107,6 +107,27 @@ function setThreadState(
}
describe('ChatThread local-search highlighting', () => {
+ it('keeps calculated and rendered matches aligned inside longer Markdown fences', () => {
+ const assistant: AgentChatMessage = {
+ id: 'turn-1-assistant',
+ role: 'assistant',
+ content: ['````typescript', '```needle', 'visible needle', '````'].join('\n'),
+ timestamp: 2,
+ }
+ setThreadState([{ role: 'assistant', items: [assistant] }])
+ threadStateValue.localSearchQuery = 'needle'
+ threadStateValue.localSearchCurrentMatch = {
+ messageId: assistant.id,
+ occurrence: 0,
+ }
+
+ render(<ChatThread />)
+
+ const renderedMatches = document.querySelectorAll('.chat-search-match')
+ expect(renderedMatches).toHaveLength(2)
+ expect(findLoadedChatMessageMatches([assistant], 'needle')).toHaveLength(renderedMatches.length)
+ })
+
it('renders every plain and Markdown match and distinguishes the selected occurrence', () => {
const messages: AgentChatMessage[] = [
{ ...userMsg, content: 'Needle then needle' },
diff --git a/desktop-app/ui/src/lib/__tests__/chatLocalSearch.test.ts b/desktop-app/ui/src/lib/__tests__/chatLocalSearch.test.ts
index 24bbc0684..3dd95df1f 100644
--- a/desktop-app/ui/src/lib/__tests__/chatLocalSearch.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/chatLocalSearch.test.ts
@@ -53,6 +53,14 @@ describe('loaded chat local search', () => {
])
})
+ it('keeps code lines that are not valid closers for a longer fence', () => {
+ const content = ['````typescript', '```needle', 'visible needle', '````'].join('\n')
+ expect(findLoadedChatMessageMatches([message('assistant', content)], 'needle')).toEqual([
+ { messageId: 'assistant', occurrence: 0 },
+ { messageId: 'assistant', occurrence: 1 },
+ ])
+ })
+
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.ts
index 550328302..8198dec18 100644
--- a/desktop-app/ui/src/lib/chatLocalSearch.ts
+++ b/desktop-app/ui/src/lib/chatLocalSearch.ts
@@ -18,19 +18,26 @@ export function chatMessageDomId(messageId: string): string {
* and fenced-code language identifiers).
*/
export function markdownSearchableText(source: string): string {
- let fence: '`' | '~' | null = null
+ let fence: { marker: '`' | '~'; length: number } | 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
+ const fenceMatch = part.match(/^\s{0,3}(`{3,}|~{3,})(.*)$/)
+ if (fence === null && fenceMatch) {
+ const run = fenceMatch[1]!
+ fence = { marker: run[0] as '`' | '~', length: run.length }
return ' '.repeat(part.length)
}
- if (fence !== null) return part
+ if (fence !== null) {
+ const run = fenceMatch?.[1] ?? ''
+ const trailing = fenceMatch?.[2] ?? ''
+ if (run[0] === fence.marker && run.length >= fence.length && trailing.trim().length === 0) {
+ fence = null
+ return ' '.repeat(part.length)
+ }
+ return part
+ }
if (/^\s{0,3}\[[^\]]+\]:\s*/.test(part)) return ' '.repeat(part.length)
return part
.replace(/\]\((?:\\.|[^)])*\)/g, match => `]${' '.repeat(match.length - 1)}`)