Add session duration computation to discovery pipeline

Extend SessionEntry with an optional duration field (milliseconds)
computed from the delta between created and modified timestamps.
The computeDuration helper handles missing or invalid dates gracefully,
returning 0 for any edge case. This enables downstream UI to show
how long each session lasted without additional API calls.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-30 09:25:44 -05:00
parent afd228eab7
commit 4b13e7eeb9
2 changed files with 11 additions and 0 deletions

View File

@@ -80,6 +80,7 @@ export async function discoverSessions(
modified: entry.modified || "",
messageCount: entry.messageCount || 0,
path: resolved,
duration: computeDuration(entry.created, entry.modified),
});
}
} catch {
@@ -102,3 +103,12 @@ export async function discoverSessions(
return sessions;
}
function computeDuration(created?: string, modified?: string): number {
if (!created || !modified) return 0;
const createdMs = new Date(created).getTime();
const modifiedMs = new Date(modified).getTime();
if (isNaN(createdMs) || isNaN(modifiedMs)) return 0;
const diff = modifiedMs - createdMs;
return diff > 0 ? diff : 0;
}