Fix #84: Block timer should reset after idle gap (#85)

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 <alexander.buyanov@konux.de>
This commit is contained in:
Alexander Buyanov
2025-09-18 21:25:53 -04:00
committed by GitHub
co-authored by alexander.buyanov
parent 2842f856e9
commit 3010addb70
+26 -7
View File
@@ -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;