claude-scope 0.8.35 → 0.8.38
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.
- package/dist/claude-scope.cjs +43 -6
- package/package.json +1 -1
package/dist/claude-scope.cjs
CHANGED
|
@@ -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
|
-
*
|
|
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,14 +2507,40 @@ var init_usage_parser = __esm({
|
|
|
2504
2507
|
}
|
|
2505
2508
|
try {
|
|
2506
2509
|
const lines = await this.readAllLines(transcriptPath);
|
|
2507
|
-
|
|
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
|
-
|
|
2513
|
-
|
|
2514
|
+
const timestamp = this.parseTimestamp(line);
|
|
2515
|
+
cacheEntries.push({
|
|
2516
|
+
cacheRead: entry.cacheRead,
|
|
2517
|
+
cacheCreation: entry.cacheCreation,
|
|
2518
|
+
timestamp: timestamp?.toISOString() || ""
|
|
2519
|
+
});
|
|
2520
|
+
}
|
|
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
|
+
}
|
|
2514
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);
|
|
2515
2544
|
}
|
|
2516
2545
|
if (cumulativeCacheRead === 0 && cumulativeCacheCreation === 0) {
|
|
2517
2546
|
return null;
|
|
@@ -2551,6 +2580,8 @@ var init_usage_parser = __esm({
|
|
|
2551
2580
|
/**
|
|
2552
2581
|
* Parse a single transcript line for usage data
|
|
2553
2582
|
* Returns null if line is not an assistant message with usage
|
|
2583
|
+
*
|
|
2584
|
+
* Follows ccstatusline approach: skip sidechain and API error messages
|
|
2554
2585
|
*/
|
|
2555
2586
|
parseLineForUsage(line) {
|
|
2556
2587
|
try {
|
|
@@ -2558,6 +2589,12 @@ var init_usage_parser = __esm({
|
|
|
2558
2589
|
if (entry.type !== "assistant") {
|
|
2559
2590
|
return null;
|
|
2560
2591
|
}
|
|
2592
|
+
if (entry.isSidechain === true) {
|
|
2593
|
+
return null;
|
|
2594
|
+
}
|
|
2595
|
+
if (entry.isApiErrorMessage === true) {
|
|
2596
|
+
return null;
|
|
2597
|
+
}
|
|
2561
2598
|
const usage = entry.message?.usage;
|
|
2562
2599
|
if (!usage) {
|
|
2563
2600
|
return null;
|
|
@@ -3536,7 +3573,7 @@ var init_context_widget = __esm({
|
|
|
3536
3573
|
};
|
|
3537
3574
|
return this.styleFn(renderData2, this.colors.context);
|
|
3538
3575
|
}
|
|
3539
|
-
const used = usage.input_tokens + usage.cache_creation_input_tokens + usage.cache_read_input_tokens
|
|
3576
|
+
const used = usage.input_tokens + usage.cache_creation_input_tokens + usage.cache_read_input_tokens;
|
|
3540
3577
|
const percent = Math.round(used / context_window_size * 100);
|
|
3541
3578
|
const renderData = {
|
|
3542
3579
|
used,
|