From c98abb4c2839ca7e2eb4f074254d111892fcff6e Mon Sep 17 00:00:00 2001 From: bourgois Date: Wed, 10 Jun 2026 13:43:00 +0200 Subject: [PATCH] fix(chat): make task-notification parsing tolerant of field order and whitespace The task-notification regex required an exact field sequence (task-id, output-file, status, summary) with no leading/trailing content, and ran with the /g flag against the raw string. Notifications whose fields arrive in a different order, omit optional fields, or carry surrounding whitespace failed to match and rendered as raw XML in the chat instead of a formatted notification. Anchor the match to the trimmed content and use non-greedy [\s\S]*? between the status and summary captures so field order and incidental whitespace no longer break parsing. --- src/components/chat/hooks/useChatMessages.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/chat/hooks/useChatMessages.ts b/src/components/chat/hooks/useChatMessages.ts index 82e7d9e1ef..fd0128b35d 100644 --- a/src/components/chat/hooks/useChatMessages.ts +++ b/src/components/chat/hooks/useChatMessages.ts @@ -55,8 +55,8 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes if (msg.role === 'user') { // Parse task notifications - const taskNotifRegex = /\s*[^<]*<\/task-id>\s*[^<]*<\/output-file>\s*([^<]*)<\/status>\s*([^<]*)<\/summary>\s*<\/task-notification>/g; - const taskNotifMatch = taskNotifRegex.exec(content); + const taskNotifRegex = /^[\s\S]*?([^<]*)<\/status>[\s\S]*?([^<]*)<\/summary>[\s\S]*?<\/task-notification>$/; + const taskNotifMatch = taskNotifRegex.exec(content.trim()); if (taskNotifMatch) { converted.push({ type: 'assistant',