diff --git a/packages/stats/src/parser.ts b/packages/stats/src/parser.ts index e09faa559..236e81d29 100644 --- a/packages/stats/src/parser.ts +++ b/packages/stats/src/parser.ts @@ -72,12 +72,16 @@ export async function parseSessionFile( for (const line of lines) { const lineLength = line.length + 1; // +1 for newline if (line.trim()) { - const entry = JSON.parse(line) as SessionEntry; - if (currentOffset >= fromOffset && entry && isAssistantMessage(entry)) { - const msgStats = extractStats(sessionPath, folder, entry); - if (msgStats) { - stats.push(msgStats); + try { + const entry = JSON.parse(line) as SessionEntry; + if (currentOffset >= fromOffset && entry && isAssistantMessage(entry)) { + const msgStats = extractStats(sessionPath, folder, entry); + if (msgStats) { + stats.push(msgStats); + } } + } catch { + // Skip malformed JSONL lines } } currentOffset += lineLength;