diff --git a/scripts/lib/llm-summary.js b/scripts/lib/llm-summary.js index 83eebd05f..758387565 100644 --- a/scripts/lib/llm-summary.js +++ b/scripts/lib/llm-summary.js @@ -54,11 +54,11 @@ function extractConversationText(transcriptPath) { } const lines = content.split('\n').filter(Boolean); - const turns = []; + let turns = []; // Older records cannot change a summary once its most recent turns are full. for (let index = lines.length - 1; index >= 0 && turns.length < MAX_TURNS; index--) { - const entryTurns = []; + let entryTurns = []; try { const entry = JSON.parse(lines[index]); const isUser = entry.type === 'user' || entry.message?.role === 'user'; @@ -77,7 +77,7 @@ function extractConversationText(transcriptPath) { : ''; const cleaned = text.replace(/\n+/g, ' ').trim(); if (cleaned && !isClassifierNotice(cleaned)) { - entryTurns.push({ role: 'User', text: cleaned.slice(0, 400) }); + entryTurns = [...entryTurns, { role: 'User', text: cleaned.slice(0, 400) }]; } } @@ -89,13 +89,13 @@ function extractConversationText(transcriptPath) { .replace(/\n+/g, ' ') .trim(); if (textParts) { - entryTurns.push({ role: 'Claude', text: textParts.slice(0, 600) }); + entryTurns = [...entryTurns, { role: 'Claude', text: textParts.slice(0, 600) }]; } } } catch { // Skip unparseable lines } - turns.unshift(...entryTurns); + turns = [...entryTurns, ...turns]; } if (turns.length === 0) return null;