claude-roi 0.8.8 → 0.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/metrics.js +23 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-roi",
3
- "version": "0.8.8",
3
+ "version": "0.8.9",
4
4
  "description": "Correlate AI coding agent token usage with git output to measure ROI",
5
5
  "type": "module",
6
6
  "bin": {
package/src/metrics.js CHANGED
@@ -581,8 +581,10 @@ export function computeMetrics(correlatedSessions, organicCommits, commitsByRepo
581
581
  day.totalTokens += dayData.inputTokens + dayData.outputTokens + dayData.cacheReadTokens + (dayData.cacheCreationTokens || 0);
582
582
  }
583
583
 
584
- // Session count attributed to start date
585
- ensureDay(startDate).sessions++;
584
+ // Session count attributed to each day it had activity
585
+ for (const date of Object.keys(usage)) {
586
+ ensureDay(date).sessions++;
587
+ }
586
588
 
587
589
  // Commits attributed to their own timestamps
588
590
  for (const commit of session.commits) {
@@ -740,12 +742,25 @@ export function computeMetrics(correlatedSessions, organicCommits, commitsByRepo
740
742
  if (dateStr === todayStr) { costByPeriod.today.cost += dayData.cost; costByPeriod.today.tokens += dTok; }
741
743
  }
742
744
 
743
- // Sessions count once (on start date), commits count on their own dates
744
- costByPeriod.allTime.sessions++; costByPeriod.allTime.commits += session.commitCount;
745
- const sDate = new Date(session.startTime);
746
- if (sDate >= startOfMonth) { costByPeriod.month.sessions++; costByPeriod.month.commits += session.commitCount; }
747
- if (sDate >= startOfWeek) { costByPeriod.week.sessions++; costByPeriod.week.commits += session.commitCount; }
748
- if (startDateStr === todayStr) { costByPeriod.today.sessions++; costByPeriod.today.commits += session.commitCount; }
745
+ // Sessions count if they had any activity in the period (via dailyUsage dates)
746
+ const usageDates = Object.keys(usage);
747
+ const hasActivityToday = usageDates.includes(todayStr);
748
+ const hasActivityThisWeek = usageDates.some(d => new Date(d + 'T12:00:00') >= startOfWeek);
749
+ const hasActivityThisMonth = usageDates.some(d => new Date(d + 'T12:00:00') >= startOfMonth);
750
+ costByPeriod.allTime.sessions++;
751
+ if (hasActivityThisMonth) costByPeriod.month.sessions++;
752
+ if (hasActivityThisWeek) costByPeriod.week.sessions++;
753
+ if (hasActivityToday) costByPeriod.today.sessions++;
754
+
755
+ // Commits count by their actual commit date, not session start date
756
+ for (const commit of (session.commits || [])) {
757
+ const commitDateStr = toDateStr(commit.timestamp);
758
+ const commitDate = new Date(commitDateStr + 'T12:00:00');
759
+ costByPeriod.allTime.commits++;
760
+ if (commitDate >= startOfMonth) costByPeriod.month.commits++;
761
+ if (commitDate >= startOfWeek) costByPeriod.week.commits++;
762
+ if (commitDateStr === todayStr) costByPeriod.today.commits++;
763
+ }
749
764
  }
750
765
 
751
766
  const summary = {