From 8393bdd7717a3fa62ef56c108df217a38235a0d0 Mon Sep 17 00:00:00 2001 From: Thomas Brugman Date: Fri, 7 Nov 2025 16:36:13 +0100 Subject: [PATCH] fix: improve task history export in Orchestrator mode - Added flattenMessages function to handle nested tasks - Improved handling of Orchestrator completion messages - Better support for tool_use and tool_result messages --- src/integrations/misc/export-markdown.ts | 47 +++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/integrations/misc/export-markdown.ts b/src/integrations/misc/export-markdown.ts index 2d493ce50c..5932051615 100644 --- a/src/integrations/misc/export-markdown.ts +++ b/src/integrations/misc/export-markdown.ts @@ -3,6 +3,48 @@ import os from "os" import * as path from "path" import * as vscode from "vscode" +function flattenMessages(messages: Anthropic.MessageParam[]): Anthropic.MessageParam[] { + return messages.flatMap((message) => { + // Check if this is an Orchestrator message with nested tasks + if ( + message.role === "assistant" && + typeof message.content === "string" && + message.content.includes("Orchestrator: Task completed") + ) { + // This is an Orchestrator completion message, we'll include it but not its nested content + // as that will be included separately in the history + return [ + { + role: message.role, + content: message.content, + }, + ] + } + + // For tool_use and tool_result messages, ensure they're properly included + if (Array.isArray(message.content)) { + const processedContent = message.content.map((block) => { + if (block.type === "tool_result" && typeof block.content !== "string" && Array.isArray(block.content)) { + // Flatten nested tool results + return { + ...block, + content: block.content.map(formatContentBlockToMarkdown).join("\n"), + } + } + return block + }) + return [ + { + ...message, + content: processedContent, + }, + ] + } + + return [message] + }) +} + export async function downloadTask(dateTs: number, conversationHistory: Anthropic.MessageParam[]) { // File name const date = new Date(dateTs) @@ -17,8 +59,11 @@ export async function downloadTask(dateTs: number, conversationHistory: Anthropi hours = hours ? hours : 12 // the hour '0' should be '12' const fileName = `roo_task_${month}-${day}-${year}_${hours}-${minutes}-${seconds}-${ampm}.md` + // Flatten and process messages for export + const flattenedHistory = flattenMessages(conversationHistory) + // Generate markdown - const markdownContent = conversationHistory + const markdownContent = flattenedHistory .map((message) => { const role = message.role === "user" ? "**User:**" : "**Assistant:**" const content = Array.isArray(message.content)