From 3010addb70c8746597fbeeda423e4ee7d7916ae7 Mon Sep 17 00:00:00 2001 From: Alexander Buyanov Date: Fri, 19 Sep 2025 03:25:53 +0200 Subject: [PATCH] Fix #84: Block timer should reset after idle gap (#85) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Block windows were staying “active” after multiple hours with no token usage, so the block timer kept counting even though ccusage reported the session closed. Aligning the activity detection with actual token usage prevents those phantom sessions and keeps the timer in sync with the upstream report. Co-authored-by: alexander.buyanov --- src/utils/jsonl.ts | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/utils/jsonl.ts b/src/utils/jsonl.ts index 0d7e08e..a0043c9 100644 --- a/src/utils/jsonl.ts +++ b/src/utils/jsonl.ts @@ -320,13 +320,32 @@ function getAllTimestampsFromFile(filePath: string): Date[] { for (const line of lines) { try { - const json = JSON.parse(line) as { timestamp?: string }; - if (json.timestamp && typeof json.timestamp === 'string') { - const date = new Date(json.timestamp); - if (!Number.isNaN(date.getTime())) { - timestamps.push(date); - } - } + const json = JSON.parse(line) as { + timestamp?: string; + isSidechain?: boolean; + message?: { usage?: { input_tokens?: number; output_tokens?: number } }; + }; + + // Only treat entries with real token usage as block activity + const usage = json.message?.usage; + if (!usage) + continue; + + const hasInputTokens = typeof usage.input_tokens === 'number'; + const hasOutputTokens = typeof usage.output_tokens === 'number'; + if (!hasInputTokens || !hasOutputTokens) + continue; + + if (json.isSidechain === true) + continue; + + const timestamp = json.timestamp; + if (typeof timestamp !== 'string') + continue; + + const date = new Date(timestamp); + if (!Number.isNaN(date.getTime())) + timestamps.push(date); } catch { // Skip invalid JSON lines continue;