Fix #86 Adjust block metrics gap threshold for short breaks (#87)

Detect block boundaries after 60 minutes of inactivity instead of requiring a 5-hour gap.
This prevents block start times from carrying over into short midday breaks and ensures elapsed time matches ccusage.

Co-authored-by: alexander.buyanov <alexander.buyanov@konux.de>
This commit is contained in:
Alexander Buyanov
2025-09-19 12:18:48 -04:00
committed by GitHub
co-authored by alexander.buyanov
parent d9ee110fc7
commit 798b637c58
+2 -1
View File
@@ -183,6 +183,7 @@ function findMostRecentBlockStartTime(
sessionDurationHours = 5
): BlockMetrics | null {
const sessionDurationMs = sessionDurationHours * 60 * 60 * 1000;
const sessionGapThresholdMs = Math.min(sessionDurationMs, 60 * 60 * 1000); // treat >=1h inactivity as boundary
const now = new Date();
// Step 1: Find all JSONL files with their modification times
@@ -256,7 +257,7 @@ function findMostRecentBlockStartTime(
const gap = previousTimestamp.getTime() - currentTimestamp.getTime();
if (gap >= sessionDurationMs) {
if (gap >= sessionGapThresholdMs) {
// Found a true session boundary
foundSessionGap = true;
break;