claude-scope 0.8.35 → 0.8.36

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.
@@ -2493,7 +2493,10 @@ var init_usage_parser = __esm({
2493
2493
  }
2494
2494
  /**
2495
2495
  * Parse cumulative cache tokens from all assistant messages in transcript
2496
- * Sums ALL cache_read and cache_creation tokens across the entire session
2496
+ *
2497
+ * Handles two transcript formats:
2498
+ * 1. Per-message format: cache_read varies per message (e.g., 2048, 4096) → sum all
2499
+ * 2. Cumulative format: cache_read is already cumulative (e.g., 165376) → use last
2497
2500
  *
2498
2501
  * @param transcriptPath - Path to the JSONL transcript file
2499
2502
  * @returns Object with cumulative cacheRead and cacheCreation, or null if not found
@@ -2504,15 +2507,41 @@ var init_usage_parser = __esm({
2504
2507
  }
2505
2508
  try {
2506
2509
  const lines = await this.readAllLines(transcriptPath);
2507
- let cumulativeCacheRead = 0;
2508
- let cumulativeCacheCreation = 0;
2510
+ const cacheEntries = [];
2509
2511
  for (const line of lines) {
2510
2512
  const entry = this.parseLineForCache(line);
2511
2513
  if (entry) {
2512
- cumulativeCacheRead += entry.cacheRead;
2513
- cumulativeCacheCreation += entry.cacheCreation;
2514
+ const timestamp = this.parseTimestamp(line);
2515
+ cacheEntries.push({
2516
+ cacheRead: entry.cacheRead,
2517
+ cacheCreation: entry.cacheCreation,
2518
+ timestamp: timestamp?.toISOString() || ""
2519
+ });
2514
2520
  }
2515
2521
  }
2522
+ if (cacheEntries.length === 0) {
2523
+ return null;
2524
+ }
2525
+ let isCumulativeFormat = false;
2526
+ if (cacheEntries.length > 1) {
2527
+ let nonDecreasingCount = 0;
2528
+ for (let i = 1; i < cacheEntries.length; i++) {
2529
+ if (cacheEntries[i].cacheRead >= cacheEntries[i - 1].cacheRead) {
2530
+ nonDecreasingCount++;
2531
+ }
2532
+ }
2533
+ isCumulativeFormat = nonDecreasingCount / (cacheEntries.length - 1) >= 0.8;
2534
+ }
2535
+ let cumulativeCacheRead;
2536
+ let cumulativeCacheCreation;
2537
+ if (isCumulativeFormat) {
2538
+ const lastEntry = cacheEntries[cacheEntries.length - 1];
2539
+ cumulativeCacheRead = lastEntry.cacheRead;
2540
+ cumulativeCacheCreation = lastEntry.cacheCreation;
2541
+ } else {
2542
+ cumulativeCacheRead = cacheEntries.reduce((sum, e) => sum + e.cacheRead, 0);
2543
+ cumulativeCacheCreation = cacheEntries.reduce((sum, e) => sum + e.cacheCreation, 0);
2544
+ }
2516
2545
  if (cumulativeCacheRead === 0 && cumulativeCacheCreation === 0) {
2517
2546
  return null;
2518
2547
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-scope",
3
- "version": "0.8.35",
3
+ "version": "0.8.36",
4
4
  "description": "Claude Code plugin for session status and analytics",
5
5
  "license": "MIT",
6
6
  "type": "module",