From a0ba65944fd1f940c161e7bb2aa7f01f62ae1c15 Mon Sep 17 00:00:00 2001 From: Olcan Date: Fri, 30 May 2025 12:43:59 -0700 Subject: [PATCH] disable markdown rendering of shell tool output (#625) --- .../components/messages/ToolGroupMessage.tsx | 1 + .../ui/components/messages/ToolMessage.tsx | 27 ++++++++++++------- packages/cli/src/ui/hooks/useToolScheduler.ts | 23 ++++++++++++++-- packages/cli/src/ui/types.ts | 1 + 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/packages/cli/src/ui/components/messages/ToolGroupMessage.tsx b/packages/cli/src/ui/components/messages/ToolGroupMessage.tsx index 8bcde3bb..280b4321 100644 --- a/packages/cli/src/ui/components/messages/ToolGroupMessage.tsx +++ b/packages/cli/src/ui/components/messages/ToolGroupMessage.tsx @@ -72,6 +72,7 @@ export const ToolGroupMessage: React.FC = ({ ? 'low' : 'medium' } + renderOutputAsMarkdown={tool.renderOutputAsMarkdown} /> {tool.status === ToolCallStatus.Confirming && diff --git a/packages/cli/src/ui/components/messages/ToolMessage.tsx b/packages/cli/src/ui/components/messages/ToolMessage.tsx index 51d3dffb..0cb5a101 100644 --- a/packages/cli/src/ui/components/messages/ToolMessage.tsx +++ b/packages/cli/src/ui/components/messages/ToolMessage.tsx @@ -21,6 +21,7 @@ export type TextEmphasis = 'high' | 'medium' | 'low'; export interface ToolMessageProps extends IndividualToolCallDisplay { availableTerminalHeight: number; emphasis?: TextEmphasis; + renderOutputAsMarkdown?: boolean; } export const ToolMessage: React.FC = ({ @@ -30,6 +31,7 @@ export const ToolMessage: React.FC = ({ status, availableTerminalHeight, emphasis = 'medium', + renderOutputAsMarkdown = true, }) => { const contentHeightEstimate = availableTerminalHeight - STATIC_HEIGHT - RESERVED_LINE_COUNT; @@ -76,15 +78,22 @@ export const ToolMessage: React.FC = ({ )} - {typeof displayableResult === 'string' && ( - - - - )} + {typeof displayableResult === 'string' && + renderOutputAsMarkdown && ( + + + + )} + {typeof displayableResult === 'string' && + !renderOutputAsMarkdown && ( + + {displayableResult} + + )} {typeof displayableResult !== 'string' && ( { + // Determine if markdown rendering should be skipped for this tool + let renderOutputAsMarkdown = true; // Default to true + if (t.status === 'error') { + // For errors, the tool object might not be available, so check t.request.name + if (t.request.name === 'execute_bash_command') { + renderOutputAsMarkdown = false; + } + } else if ('tool' in t && t.tool?.name === 'execute_bash_command') { + // For other statuses, check t.tool.name if tool exists + renderOutputAsMarkdown = false; + } + switch (t.status) { case 'success': return { @@ -550,15 +562,17 @@ export function mapToDisplay( resultDisplay: t.response.resultDisplay, status: mapStatus(t.status), confirmationDetails: undefined, + renderOutputAsMarkdown, }; case 'error': return { callId: t.request.callId, - name: t.request.name, - description: '', + name: t.request.name, // Use request.name as tool might be undefined + description: '', // No description available if tool is undefined resultDisplay: t.response.resultDisplay, status: mapStatus(t.status), confirmationDetails: undefined, + renderOutputAsMarkdown, }; case 'cancelled': return { @@ -568,6 +582,7 @@ export function mapToDisplay( resultDisplay: t.response.resultDisplay, status: mapStatus(t.status), confirmationDetails: undefined, + renderOutputAsMarkdown, }; case 'awaiting_approval': return { @@ -577,6 +592,7 @@ export function mapToDisplay( resultDisplay: undefined, status: mapStatus(t.status), confirmationDetails: t.confirmationDetails, + renderOutputAsMarkdown, }; case 'executing': return { @@ -586,6 +602,7 @@ export function mapToDisplay( resultDisplay: t.liveOutput ?? undefined, status: mapStatus(t.status), confirmationDetails: undefined, + renderOutputAsMarkdown, }; case 'validating': // Add this case return { @@ -595,6 +612,7 @@ export function mapToDisplay( resultDisplay: undefined, status: mapStatus(t.status), confirmationDetails: undefined, + renderOutputAsMarkdown, }; case 'scheduled': return { @@ -604,6 +622,7 @@ export function mapToDisplay( resultDisplay: undefined, status: mapStatus(t.status), confirmationDetails: undefined, + renderOutputAsMarkdown, }; default: { // ensures every case is checked for above diff --git a/packages/cli/src/ui/types.ts b/packages/cli/src/ui/types.ts index 2826bb1e..3a8c55bb 100644 --- a/packages/cli/src/ui/types.ts +++ b/packages/cli/src/ui/types.ts @@ -49,6 +49,7 @@ export interface IndividualToolCallDisplay { resultDisplay: ToolResultDisplay | undefined; status: ToolCallStatus; confirmationDetails: ToolCallConfirmationDetails | undefined; + renderOutputAsMarkdown?: boolean; } export interface HistoryItemBase {