From d260ea86f089cd9e5481f18430c89da84482edc9 Mon Sep 17 00:00:00 2001 From: weishu Date: Mon, 12 Jan 2026 21:10:49 +0800 Subject: [PATCH] fix: parse codex bash output format in web app display Parse the "Exit code: X\nWall time: Y\nOutput:\n..." format from bash tool results and display metadata (exit code and wall time) separately from the output content as a code block. --- .../components/ToolCard/views/_results.tsx | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/web/src/components/ToolCard/views/_results.tsx b/web/src/components/ToolCard/views/_results.tsx index 5620ae97..c2e552a6 100644 --- a/web/src/components/ToolCard/views/_results.tsx +++ b/web/src/components/ToolCard/views/_results.tsx @@ -95,6 +95,26 @@ function extractTextFromResult(result: unknown, depth: number = 0): string | nul return null } +interface CodexBashOutput { + exitCode: number | null + wallTime: string | null + output: string +} + +function parseCodexBashOutput(text: string): CodexBashOutput | null { + const exitMatch = text.match(/^Exit code:\s*(\d+)/m) + const wallMatch = text.match(/^Wall time:\s*(.+)$/m) + const outputMatch = text.match(/^Output:\n([\s\S]*)$/m) + + if (!exitMatch && !wallMatch && !outputMatch) return null + + return { + exitCode: exitMatch ? parseInt(exitMatch[1], 10) : null, + wallTime: wallMatch ? wallMatch[1].trim() : null, + output: outputMatch ? outputMatch[1] : text + } +} + function looksLikeHtml(text: string): boolean { const trimmed = text.trimStart() return trimmed.startsWith(' { return
{placeholderForState(props.block.tool.state)}
} + // Detect codex bash output format and render accordingly + if (typeof result === 'string') { + const parsed = parseCodexBashOutput(result) + if (parsed) { + return ( + <> +
+ {parsed.exitCode !== null && `Exit code: ${parsed.exitCode}`} + {parsed.exitCode !== null && parsed.wallTime && ' ยท '} + {parsed.wallTime && `Wall time: ${parsed.wallTime}`} +
+ {renderText(parsed.output.trim(), { mode: 'code' })} + + + ) + } + } + const text = extractTextFromResult(result) if (text) { return ( @@ -569,7 +607,6 @@ const GenericResultView: ToolViewComponent = (props: ToolViewProps) => { export const toolResultViewRegistry: Record = { Task: MarkdownResultView, Bash: BashResultView, - CodexBash: BashResultView, Glob: LineListResultView, Grep: LineListResultView, LS: LineListResultView,