${highlightJson(shown)}` : `${escapeHtml(shown)}`
}
// ─── sections ────────────────────────────────────────────────────────────────
/** KPI card row: the numbers that describe the session. */
function renderKpiGrid(input: RenderInput, lang: ReportLang): string {
const stats = input.stats
const cards: Array<{ readonly label: LabelKey; readonly value: string; readonly note?: string; readonly tip: LabelKey }> = [
{ label: 'messages', value: String(input.totals.messages), tip: 'tipMessages' },
{
label: 'toolCalls',
value: String(input.totals.toolCalls),
note: stats !== undefined && stats.failedToolCalls > 0 ? tf('failedNote', lang, { n: stats.failedToolCalls }) : undefined,
tip: 'tipToolCalls',
},
{ label: 'tokensIn', value: fmtTokens(input.totals.inputTokens), tip: 'tipTokens' },
{ label: 'tokensOut', value: fmtTokens(input.totals.outputTokens), tip: 'tipTokens' },
{
label: 'duration',
value: stats?.durationMs !== undefined && stats.durationMs !== null ? formatDuration(stats.durationMs) : '—',
tip: 'tipDuration',
},
{ label: 'turns', value: stats !== undefined ? String(stats.turns) : '—', tip: 'tipTurns' },
]
const cost = stats?.cost
if (cost !== undefined) {
cards.push({
label: 'cost',
value: `${cost.currency}${cost.total >= 0.01 ? cost.total.toFixed(2) : cost.total.toFixed(4)}`,
tip: 'tipCost',
})
}
const spark = stats !== undefined ? renderSparklineSvg(stats.perAssistantTokens, lang) : ''
return [
'${escapeHtml(block.text.trim())}${escapeHtml(truncate(diff, options.resultCharLimit))}${renderCode(block.arguments, options.argCharLimit)}${renderCode(inner, options.resultCharLimit)}${escapeHtml(id8(String(toolResult.source.callId)))}${isError ? ' ⚠ ERROR' : ''}