ccusage 16.2.5 → 17.0.0
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/README.md +20 -25
- package/config-schema.json +0 -33
- package/dist/_types-CV6z8-9_.js +583 -0
- package/dist/{calculate-cost-BDqO4yWA.js → calculate-cost-CX9KwEZt.js} +1 -1
- package/dist/calculate-cost.d.ts +1 -4
- package/dist/calculate-cost.js +2 -3
- package/dist/data-loader-DQtk3Va0.js +3733 -0
- package/dist/data-loader-D_hlygEz.d.ts +2307 -0
- package/dist/data-loader.d.ts +1 -2
- package/dist/data-loader.js +3 -5
- package/dist/debug-Bn_uiKiR.js +148 -0
- package/dist/debug.d.ts +8 -0
- package/dist/debug.js +4 -6
- package/dist/index.d.ts +0 -0
- package/dist/index.js +2838 -2065
- package/dist/{logger-wHijzbnK.js → logger-1M8m84B7.js} +179 -74
- package/dist/logger.d.ts +11 -7
- package/dist/logger.js +1 -1
- package/dist/{prompt-DsUFNEY7.js → prompt-BeRmYuGP.js} +49 -28
- package/package.json +4 -4
- package/dist/_token-utils-WjkbrjKv.js +0 -5
- package/dist/_types-DIdtMJ6V.js +0 -3076
- package/dist/data-loader-D1FVB4Lp.d.ts +0 -785
- package/dist/data-loader-abvRdQYo.js +0 -2681
- package/dist/debug-CkCfHFil.js +0 -109
- package/dist/mcp-Dz21qUWi.js +0 -6832
- package/dist/mcp.d.ts +0 -35
- package/dist/mcp.js +0 -8
- package/dist/pricing-fetcher-BtUY4dRM.js +0 -402
- package/dist/pricing-fetcher-DK8lcI1w.d.ts +0 -219
- package/dist/pricing-fetcher.d.ts +0 -2
- package/dist/pricing-fetcher.js +0 -4
package/dist/debug-CkCfHFil.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, PricingFetcher, USAGE_DATA_GLOB_PATTERN, __toESM, isFailure, require_usingCtx, try_ } from "./pricing-fetcher-BtUY4dRM.js";
|
|
2
|
-
import { getClaudePaths, glob, unwrap, usageDataSchema } from "./data-loader-abvRdQYo.js";
|
|
3
|
-
import { logger } from "./logger-wHijzbnK.js";
|
|
4
|
-
import { readFile } from "node:fs/promises";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
var import_usingCtx = /* @__PURE__ */ __toESM(require_usingCtx(), 1);
|
|
7
|
-
async function detectMismatches(claudePath) {
|
|
8
|
-
try {
|
|
9
|
-
var _usingCtx = (0, import_usingCtx.default)();
|
|
10
|
-
let claudeDir;
|
|
11
|
-
if (claudePath != null && claudePath !== "") claudeDir = claudePath;
|
|
12
|
-
else {
|
|
13
|
-
const paths = getClaudePaths();
|
|
14
|
-
if (paths.length === 0) throw new Error("No valid Claude data directory found");
|
|
15
|
-
claudeDir = path.join(paths[0], CLAUDE_PROJECTS_DIR_NAME);
|
|
16
|
-
}
|
|
17
|
-
const files = await glob([USAGE_DATA_GLOB_PATTERN], {
|
|
18
|
-
cwd: claudeDir,
|
|
19
|
-
absolute: true
|
|
20
|
-
}), fetcher = _usingCtx.u(new PricingFetcher()), stats = {
|
|
21
|
-
totalEntries: 0,
|
|
22
|
-
entriesWithBoth: 0,
|
|
23
|
-
matches: 0,
|
|
24
|
-
mismatches: 0,
|
|
25
|
-
discrepancies: [],
|
|
26
|
-
modelStats: /* @__PURE__ */ new Map(),
|
|
27
|
-
versionStats: /* @__PURE__ */ new Map()
|
|
28
|
-
};
|
|
29
|
-
for (const file of files) {
|
|
30
|
-
const content = await readFile(file, "utf-8"), lines = content.trim().split("\n").filter((line) => line.length > 0);
|
|
31
|
-
for (const line of lines) {
|
|
32
|
-
const parseParser = try_({
|
|
33
|
-
try: () => JSON.parse(line),
|
|
34
|
-
catch: () => /* @__PURE__ */ new Error("Invalid JSON")
|
|
35
|
-
}), parseResult = parseParser();
|
|
36
|
-
if (isFailure(parseResult)) continue;
|
|
37
|
-
const schemaResult = usageDataSchema.safeParse(parseResult.value);
|
|
38
|
-
if (!schemaResult.success) continue;
|
|
39
|
-
const data = schemaResult.data;
|
|
40
|
-
if (stats.totalEntries++, data.costUSD !== void 0 && data.message.model != null && data.message.model !== "<synthetic>") {
|
|
41
|
-
stats.entriesWithBoth++;
|
|
42
|
-
const model = data.message.model, calculatedCost = await unwrap(fetcher.calculateCostFromTokens(data.message.usage, model)), difference = Math.abs(data.costUSD - calculatedCost), percentDiff = data.costUSD > 0 ? difference / data.costUSD * 100 : 0, modelStat = stats.modelStats.get(model) ?? {
|
|
43
|
-
total: 0,
|
|
44
|
-
matches: 0,
|
|
45
|
-
mismatches: 0,
|
|
46
|
-
avgPercentDiff: 0
|
|
47
|
-
};
|
|
48
|
-
if (modelStat.total++, data.version != null) {
|
|
49
|
-
const versionStat = stats.versionStats.get(data.version) ?? {
|
|
50
|
-
total: 0,
|
|
51
|
-
matches: 0,
|
|
52
|
-
mismatches: 0,
|
|
53
|
-
avgPercentDiff: 0
|
|
54
|
-
};
|
|
55
|
-
if (versionStat.total++, percentDiff < DEBUG_MATCH_THRESHOLD_PERCENT) versionStat.matches++;
|
|
56
|
-
else versionStat.mismatches++;
|
|
57
|
-
versionStat.avgPercentDiff = (versionStat.avgPercentDiff * (versionStat.total - 1) + percentDiff) / versionStat.total, stats.versionStats.set(data.version, versionStat);
|
|
58
|
-
}
|
|
59
|
-
if (percentDiff < .1) stats.matches++, modelStat.matches++;
|
|
60
|
-
else stats.mismatches++, modelStat.mismatches++, stats.discrepancies.push({
|
|
61
|
-
file: path.basename(file),
|
|
62
|
-
timestamp: data.timestamp,
|
|
63
|
-
model,
|
|
64
|
-
originalCost: data.costUSD,
|
|
65
|
-
calculatedCost,
|
|
66
|
-
difference,
|
|
67
|
-
percentDiff,
|
|
68
|
-
usage: data.message.usage
|
|
69
|
-
});
|
|
70
|
-
modelStat.avgPercentDiff = (modelStat.avgPercentDiff * (modelStat.total - 1) + percentDiff) / modelStat.total, stats.modelStats.set(model, modelStat);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return stats;
|
|
75
|
-
} catch (_) {
|
|
76
|
-
_usingCtx.e = _;
|
|
77
|
-
} finally {
|
|
78
|
-
_usingCtx.d();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function printMismatchReport(stats, sampleCount = 5) {
|
|
82
|
-
if (stats.entriesWithBoth === 0) {
|
|
83
|
-
logger.info("No pricing data found to analyze.");
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const matchRate = stats.matches / stats.entriesWithBoth * 100;
|
|
87
|
-
if (logger.info("\n=== Pricing Mismatch Debug Report ==="), logger.info(`Total entries processed: ${stats.totalEntries.toLocaleString()}`), logger.info(`Entries with both costUSD and model: ${stats.entriesWithBoth.toLocaleString()}`), logger.info(`Matches (within 0.1%): ${stats.matches.toLocaleString()}`), logger.info(`Mismatches: ${stats.mismatches.toLocaleString()}`), logger.info(`Match rate: ${matchRate.toFixed(2)}%`), stats.mismatches > 0 && stats.modelStats.size > 0) {
|
|
88
|
-
logger.info("\n=== Model Statistics ===");
|
|
89
|
-
const sortedModels = Array.from(stats.modelStats.entries()).sort((a$1, b) => b[1].mismatches - a$1[1].mismatches);
|
|
90
|
-
for (const [model, modelStat] of sortedModels) if (modelStat.mismatches > 0) {
|
|
91
|
-
const modelMatchRate = modelStat.matches / modelStat.total * 100;
|
|
92
|
-
logger.info(`${model}:`), logger.info(` Total entries: ${modelStat.total.toLocaleString()}`), logger.info(` Matches: ${modelStat.matches.toLocaleString()} (${modelMatchRate.toFixed(1)}%)`), logger.info(` Mismatches: ${modelStat.mismatches.toLocaleString()}`), logger.info(` Avg % difference: ${modelStat.avgPercentDiff.toFixed(1)}%`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (stats.mismatches > 0 && stats.versionStats.size > 0) {
|
|
96
|
-
logger.info("\n=== Version Statistics ===");
|
|
97
|
-
const sortedVersions = Array.from(stats.versionStats.entries()).filter(([_, versionStat]) => versionStat.mismatches > 0).sort((a$1, b) => b[1].mismatches - a$1[1].mismatches);
|
|
98
|
-
for (const [version, versionStat] of sortedVersions) {
|
|
99
|
-
const versionMatchRate = versionStat.matches / versionStat.total * 100;
|
|
100
|
-
logger.info(`${version}:`), logger.info(` Total entries: ${versionStat.total.toLocaleString()}`), logger.info(` Matches: ${versionStat.matches.toLocaleString()} (${versionMatchRate.toFixed(1)}%)`), logger.info(` Mismatches: ${versionStat.mismatches.toLocaleString()}`), logger.info(` Avg % difference: ${versionStat.avgPercentDiff.toFixed(1)}%`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (stats.discrepancies.length > 0 && sampleCount > 0) {
|
|
104
|
-
logger.info(`\n=== Sample Discrepancies (first ${sampleCount}) ===`);
|
|
105
|
-
const samples = stats.discrepancies.slice(0, sampleCount);
|
|
106
|
-
for (const disc of samples) logger.info(`File: ${disc.file}`), logger.info(`Timestamp: ${disc.timestamp}`), logger.info(`Model: ${disc.model}`), logger.info(`Original cost: $${disc.originalCost.toFixed(6)}`), logger.info(`Calculated cost: $${disc.calculatedCost.toFixed(6)}`), logger.info(`Difference: $${disc.difference.toFixed(6)} (${disc.percentDiff.toFixed(2)}%)`), logger.info(`Tokens: ${JSON.stringify(disc.usage)}`), logger.info("---");
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
export { detectMismatches, printMismatchReport };
|