Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/daemon/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ export interface UsageQueryResult {
};
totals: UsageTotals;
byDay: UsageMetricBucket[];
/** Local-time hourly buckets keyed `YYYY-MM-DD HH`; absent from older daemons. */
byHour?: UsageMetricBucket[];
byRepository: UsageMetricBucket[];
byModel: UsageMetricBucket[];
byAgent: UsageMetricBucket[];
Expand Down
5 changes: 5 additions & 0 deletions src/store/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ export class SessionStore {
};

const byDayMap = new Map<string, UsageMetricBucket>();
const byHourMap = new Map<string, UsageMetricBucket>();
const byRepoMap = new Map<string, UsageMetricBucket>();
const byModelMap = new Map<string, UsageMetricBucket>();
const byAgentMap = new Map<string, UsageMetricBucket>();
Expand Down Expand Up @@ -480,6 +481,7 @@ export class SessionStore {
const d = new Date(row.created_at);
const dayKey = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
accumulate(byDayMap, dayKey, inputTokens, outputTokens, cachedTokens, totalTokens, cost);
accumulate(byHourMap, `${dayKey} ${String(d.getHours()).padStart(2, "0")}`, inputTokens, outputTokens, cachedTokens, totalTokens, cost);

// Repo (normalized project name across worktrees)
const repoKey = normalizeProjectName(row);
Expand Down Expand Up @@ -546,6 +548,7 @@ export class SessionStore {
const d = new Date(row.ended_at);
const dayKey = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
accumulate(byDayMap, dayKey, inputTokens, outputTokens, cachedTokens, totalTokens, cost);
accumulate(byHourMap, `${dayKey} ${String(d.getHours()).padStart(2, "0")}`, inputTokens, outputTokens, cachedTokens, totalTokens, cost);
accumulate(
byRepoMap,
normalizeProjectName({ repository: row.repository, cwd: row.cwd }),
Expand All @@ -566,6 +569,7 @@ export class SessionStore {
};

const byDay = [...byDayMap.values()].sort((a, b) => a.key.localeCompare(b.key));
const byHour = [...byHourMap.values()].sort((a, b) => a.key.localeCompare(b.key));
const byRepository = [...byRepoMap.values()].sort(sortDescending);
const byModel = [...byModelMap.values()].sort(sortDescending);
const byAgent = [...byAgentMap.values()].sort(sortDescending);
Expand All @@ -580,6 +584,7 @@ export class SessionStore {
},
totals,
byDay,
byHour,
byRepository,
byModel,
byAgent,
Expand Down
Loading
Loading