ccusage 0.4.2 → 0.6.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 +106 -1
- package/dist/arktype-C-GObzDh-Dj1DVoqC.js +5 -0
- package/dist/calculate-cost.d.ts +5 -5
- package/dist/calculate-cost.js +1 -1
- package/dist/core-BgFXUe_h.js +693 -0
- package/dist/{data-loader-B8mdiY5r.js → data-loader-CDv0IYZx.js} +59 -22
- package/dist/{data-loader-DtCt7sNl.d.ts → data-loader-aUOjeZ06.d.ts} +17 -6
- package/dist/data-loader.d.ts +5 -5
- package/dist/data-loader.js +5 -5
- package/dist/{debug-Oce2b5bO.js → debug-Dk36WQTw.js} +4 -4
- package/dist/debug.js +5 -5
- package/dist/dist-C_i5I27w.js +469 -0
- package/dist/{dist-D6rk8Ra5.js → dist-FwNhpFrW.js} +30 -1
- package/dist/effect-WSjEuzC9-BsxP11fz.js +10 -0
- package/dist/esm-vjyZjnpZ.js +1090 -0
- package/dist/index-CISmcbXk-BotItq1T.js +23 -0
- package/dist/index.js +171 -23
- package/dist/{logger-nCODI08N.js → logger-DhDyJEC5.js} +2 -2
- package/dist/logger.js +1 -1
- package/dist/mcp-G-TIOcuj.js +37580 -0
- package/dist/mcp.d.ts +15 -0
- package/dist/mcp.js +10 -0
- package/dist/{pricing-fetcher-bvi4lbXl.js → pricing-fetcher-BCv1Vods.js} +2 -2
- package/dist/{pricing-fetcher-BqlslEH3.d.ts → pricing-fetcher-DygIroMj.d.ts} +1 -1
- package/dist/pricing-fetcher.d.ts +2 -2
- package/dist/pricing-fetcher.js +3 -3
- package/dist/{shared-args-DWaGio0e.js → shared-args-BtMSktLn.js} +10 -3
- package/dist/shared-args.d.ts +14 -0
- package/dist/shared-args.js +6 -6
- package/dist/sury-DmrZ3_Oj-DhGOjCNc.js +10 -0
- package/dist/{types-DjlBTM5P.js → types-BcXIBMQk.js} +3 -2
- package/dist/types-CFnCBr2I.js +3586 -0
- package/dist/{types-BfZ5dOy7.d.ts → types-y1JQzaKZ.d.ts} +4 -2
- package/dist/types.d.ts +3 -3
- package/dist/types.js +3 -3
- package/dist/utils.js +1 -1
- package/dist/valibot-CQk-M5rL-Cq5E7F3g.js +10 -0
- package/dist/zod-Db63SLXj-BWdcigdx.js +30 -0
- package/package.json +2 -1
- /package/dist/{calculate-cost-BnufbprY.js → calculate-cost-2IwHSzmi.js} +0 -0
- /package/dist/{index-Bazt8Nfd.d.ts → index-BurjgCfW.d.ts} +0 -0
- /package/dist/{prompt-BwcIpzWm.js → prompt-IToGuko2.js} +0 -0
- /package/dist/{utils-BeihwpHn.js → utils-C7kg8MXN.js} +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region node_modules/xsschema/dist/index-CISmcbXk.js
|
|
2
|
+
const missingDependenciesUrl = "https://xsai.js.org/docs/packages-top/xsschema#missing-dependencies";
|
|
3
|
+
const tryImport = async (result, name) => {
|
|
4
|
+
try {
|
|
5
|
+
return await result;
|
|
6
|
+
} catch {
|
|
7
|
+
throw new Error(`xsschema: Missing dependencies "${name}". see ${missingDependenciesUrl}`);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const getToJsonSchemaFn = async (vendor) => {
|
|
11
|
+
switch (vendor) {
|
|
12
|
+
case "arktype": return import("./arktype-C-GObzDh-Dj1DVoqC.js").then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
13
|
+
case "effect": return import("./effect-WSjEuzC9-BsxP11fz.js").then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
14
|
+
case "sury": return import("./sury-DmrZ3_Oj-DhGOjCNc.js").then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
15
|
+
case "valibot": return import("./valibot-CQk-M5rL-Cq5E7F3g.js").then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
16
|
+
case "zod": return import("./zod-Db63SLXj-BWdcigdx.js").then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
17
|
+
default: throw new Error(`xsschema: Unsupported schema vendor "${vendor}". see https://xsai.js.org/docs/packages-top/xsschema#unsupported-schema-vendor`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const toJsonSchema = async (schema) => getToJsonSchemaFn(schema["~standard"].vendor).then(async (toJsonSchema2) => toJsonSchema2(schema));
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { missingDependenciesUrl, toJsonSchema, tryImport };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { __commonJS, __require, __toESM,
|
|
3
|
-
import {
|
|
4
|
-
import "./dist-
|
|
5
|
-
import { description, log, logger, name, version } from "./logger-
|
|
6
|
-
import "./pricing-fetcher-
|
|
7
|
-
import "./
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
2
|
+
import { __commonJS, __require, __toESM, loadDailyUsageData, loadMonthlyUsageData, loadSessionData } from "./data-loader-CDv0IYZx.js";
|
|
3
|
+
import { calculateTotals, createTotalsObject, getTotalTokens } from "./calculate-cost-2IwHSzmi.js";
|
|
4
|
+
import "./dist-FwNhpFrW.js";
|
|
5
|
+
import { description, log, logger, name, version } from "./logger-DhDyJEC5.js";
|
|
6
|
+
import "./pricing-fetcher-BCv1Vods.js";
|
|
7
|
+
import { detectMismatches, printMismatchReport } from "./debug-Dk36WQTw.js";
|
|
8
|
+
import "./types-BcXIBMQk.js";
|
|
9
|
+
import { sharedArgs, sharedCommandConfig } from "./shared-args-BtMSktLn.js";
|
|
10
|
+
import { formatCurrency, formatNumber } from "./utils-C7kg8MXN.js";
|
|
11
|
+
import "./types-CFnCBr2I.js";
|
|
12
|
+
import { createMcpServer } from "./mcp-G-TIOcuj.js";
|
|
13
|
+
import "./index-CISmcbXk-BotItq1T.js";
|
|
11
14
|
import process$1 from "node:process";
|
|
12
15
|
|
|
13
16
|
//#region node_modules/gunshi/lib/utils-B_QNzw5q.js
|
|
@@ -2726,7 +2729,7 @@ var require_table = __commonJS({ "node_modules/cli-table3/src/table.js"(exports,
|
|
|
2726
2729
|
const debug = require_debug$1();
|
|
2727
2730
|
const utils = require_utils$1();
|
|
2728
2731
|
const tableLayout = require_layout_manager();
|
|
2729
|
-
var Table$
|
|
2732
|
+
var Table$3 = class extends Array {
|
|
2730
2733
|
constructor(opts) {
|
|
2731
2734
|
super();
|
|
2732
2735
|
const options = utils.mergeOptions(opts);
|
|
@@ -2789,7 +2792,7 @@ var require_table = __commonJS({ "node_modules/cli-table3/src/table.js"(exports,
|
|
|
2789
2792
|
return str[0].length;
|
|
2790
2793
|
}
|
|
2791
2794
|
};
|
|
2792
|
-
Table$
|
|
2795
|
+
Table$3.reset = () => debug.reset();
|
|
2793
2796
|
function doDraw(row, lineNum, result) {
|
|
2794
2797
|
let line = [];
|
|
2795
2798
|
row.forEach(function(cell) {
|
|
@@ -2798,7 +2801,7 @@ var require_table = __commonJS({ "node_modules/cli-table3/src/table.js"(exports,
|
|
|
2798
2801
|
let str = line.join("");
|
|
2799
2802
|
if (str.length) result.push(str);
|
|
2800
2803
|
}
|
|
2801
|
-
module.exports = Table$
|
|
2804
|
+
module.exports = Table$3;
|
|
2802
2805
|
} });
|
|
2803
2806
|
|
|
2804
2807
|
//#endregion
|
|
@@ -2878,21 +2881,21 @@ var require_picocolors = __commonJS({ "node_modules/picocolors/picocolors.js"(ex
|
|
|
2878
2881
|
|
|
2879
2882
|
//#endregion
|
|
2880
2883
|
//#region src/commands/daily.ts
|
|
2881
|
-
var import_cli_table3$
|
|
2882
|
-
var import_picocolors$
|
|
2884
|
+
var import_cli_table3$2 = __toESM(require_cli_table3(), 1);
|
|
2885
|
+
var import_picocolors$2 = __toESM(require_picocolors(), 1);
|
|
2883
2886
|
const dailyCommand = define({
|
|
2884
2887
|
name: "daily",
|
|
2885
2888
|
description: "Show usage report grouped by date",
|
|
2886
2889
|
...sharedCommandConfig,
|
|
2887
2890
|
async run(ctx) {
|
|
2888
2891
|
if (ctx.values.json) logger.level = 0;
|
|
2889
|
-
const
|
|
2892
|
+
const dailyData = await loadDailyUsageData({
|
|
2890
2893
|
since: ctx.values.since,
|
|
2891
2894
|
until: ctx.values.until,
|
|
2892
2895
|
claudePath: ctx.values.path,
|
|
2893
|
-
mode: ctx.values.mode
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
+
mode: ctx.values.mode,
|
|
2897
|
+
order: ctx.values.order
|
|
2898
|
+
});
|
|
2896
2899
|
if (dailyData.length === 0) {
|
|
2897
2900
|
if (ctx.values.json) log(JSON.stringify([]));
|
|
2898
2901
|
else logger.warn("No Claude usage data found.");
|
|
@@ -2919,7 +2922,7 @@ const dailyCommand = define({
|
|
|
2919
2922
|
log(JSON.stringify(jsonOutput, null, 2));
|
|
2920
2923
|
} else {
|
|
2921
2924
|
logger.box("Claude Code Token Usage Report - Daily");
|
|
2922
|
-
const table = new import_cli_table3$
|
|
2925
|
+
const table = new import_cli_table3$2.default({
|
|
2923
2926
|
head: [
|
|
2924
2927
|
"Date",
|
|
2925
2928
|
"Input",
|
|
@@ -2958,6 +2961,149 @@ const dailyCommand = define({
|
|
|
2958
2961
|
"─".repeat(12),
|
|
2959
2962
|
"─".repeat(10)
|
|
2960
2963
|
]);
|
|
2964
|
+
table.push([
|
|
2965
|
+
import_picocolors$2.default.yellow("Total"),
|
|
2966
|
+
import_picocolors$2.default.yellow(formatNumber(totals.inputTokens)),
|
|
2967
|
+
import_picocolors$2.default.yellow(formatNumber(totals.outputTokens)),
|
|
2968
|
+
import_picocolors$2.default.yellow(formatNumber(totals.cacheCreationTokens)),
|
|
2969
|
+
import_picocolors$2.default.yellow(formatNumber(totals.cacheReadTokens)),
|
|
2970
|
+
import_picocolors$2.default.yellow(formatNumber(getTotalTokens(totals))),
|
|
2971
|
+
import_picocolors$2.default.yellow(formatCurrency(totals.totalCost))
|
|
2972
|
+
]);
|
|
2973
|
+
log(table.toString());
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2976
|
+
});
|
|
2977
|
+
|
|
2978
|
+
//#endregion
|
|
2979
|
+
//#region src/commands/mcp.ts
|
|
2980
|
+
const mcpCommand = define({
|
|
2981
|
+
name: "mcp",
|
|
2982
|
+
description: "Show usage report for MCP",
|
|
2983
|
+
args: {
|
|
2984
|
+
path: sharedArgs.path,
|
|
2985
|
+
mode: sharedArgs.mode,
|
|
2986
|
+
type: {
|
|
2987
|
+
type: "enum",
|
|
2988
|
+
short: "t",
|
|
2989
|
+
description: "Transport type for MCP server",
|
|
2990
|
+
choices: ["stdio", "http"],
|
|
2991
|
+
default: "stdio"
|
|
2992
|
+
},
|
|
2993
|
+
port: {
|
|
2994
|
+
type: "number",
|
|
2995
|
+
description: "Port for HTTP transport (default: 8080)",
|
|
2996
|
+
default: 8080
|
|
2997
|
+
}
|
|
2998
|
+
},
|
|
2999
|
+
async run(ctx) {
|
|
3000
|
+
const { type, mode, path, port } = ctx.values;
|
|
3001
|
+
if (type === "stdio") logger.level = 0;
|
|
3002
|
+
const server = createMcpServer({
|
|
3003
|
+
claudePath: path,
|
|
3004
|
+
mode
|
|
3005
|
+
});
|
|
3006
|
+
server.start(ctx.values.type === "http" ? {
|
|
3007
|
+
transportType: "httpStream",
|
|
3008
|
+
httpStream: { port }
|
|
3009
|
+
} : { transportType: "stdio" });
|
|
3010
|
+
}
|
|
3011
|
+
});
|
|
3012
|
+
|
|
3013
|
+
//#endregion
|
|
3014
|
+
//#region src/commands/monthly.ts
|
|
3015
|
+
var import_cli_table3$1 = __toESM(require_cli_table3(), 1);
|
|
3016
|
+
var import_picocolors$1 = __toESM(require_picocolors(), 1);
|
|
3017
|
+
const monthlyCommand = define({
|
|
3018
|
+
name: "monthly",
|
|
3019
|
+
description: "Show usage report grouped by month",
|
|
3020
|
+
...sharedCommandConfig,
|
|
3021
|
+
async run(ctx) {
|
|
3022
|
+
if (ctx.values.json) logger.level = 0;
|
|
3023
|
+
const monthlyData = await loadMonthlyUsageData({
|
|
3024
|
+
since: ctx.values.since,
|
|
3025
|
+
until: ctx.values.until,
|
|
3026
|
+
claudePath: ctx.values.path,
|
|
3027
|
+
mode: ctx.values.mode,
|
|
3028
|
+
order: ctx.values.order
|
|
3029
|
+
});
|
|
3030
|
+
if (monthlyData.length === 0) {
|
|
3031
|
+
if (ctx.values.json) {
|
|
3032
|
+
const emptyOutput = {
|
|
3033
|
+
monthly: [],
|
|
3034
|
+
totals: {
|
|
3035
|
+
inputTokens: 0,
|
|
3036
|
+
outputTokens: 0,
|
|
3037
|
+
cacheCreationTokens: 0,
|
|
3038
|
+
cacheReadTokens: 0,
|
|
3039
|
+
totalTokens: 0,
|
|
3040
|
+
totalCost: 0
|
|
3041
|
+
}
|
|
3042
|
+
};
|
|
3043
|
+
log(JSON.stringify(emptyOutput, null, 2));
|
|
3044
|
+
} else logger.warn("No Claude usage data found.");
|
|
3045
|
+
process$1.exit(0);
|
|
3046
|
+
}
|
|
3047
|
+
const totals = calculateTotals(monthlyData);
|
|
3048
|
+
if (ctx.values.debug && !ctx.values.json) {
|
|
3049
|
+
const mismatchStats = await detectMismatches(ctx.values.path);
|
|
3050
|
+
printMismatchReport(mismatchStats, ctx.values.debugSamples);
|
|
3051
|
+
}
|
|
3052
|
+
if (ctx.values.json) {
|
|
3053
|
+
const jsonOutput = {
|
|
3054
|
+
monthly: monthlyData.map((data) => ({
|
|
3055
|
+
month: data.month,
|
|
3056
|
+
inputTokens: data.inputTokens,
|
|
3057
|
+
outputTokens: data.outputTokens,
|
|
3058
|
+
cacheCreationTokens: data.cacheCreationTokens,
|
|
3059
|
+
cacheReadTokens: data.cacheReadTokens,
|
|
3060
|
+
totalTokens: getTotalTokens(data),
|
|
3061
|
+
totalCost: data.totalCost
|
|
3062
|
+
})),
|
|
3063
|
+
totals: createTotalsObject(totals)
|
|
3064
|
+
};
|
|
3065
|
+
log(JSON.stringify(jsonOutput, null, 2));
|
|
3066
|
+
} else {
|
|
3067
|
+
logger.box("Claude Code Token Usage Report - Monthly");
|
|
3068
|
+
const table = new import_cli_table3$1.default({
|
|
3069
|
+
head: [
|
|
3070
|
+
"Month",
|
|
3071
|
+
"Input",
|
|
3072
|
+
"Output",
|
|
3073
|
+
"Cache Create",
|
|
3074
|
+
"Cache Read",
|
|
3075
|
+
"Total Tokens",
|
|
3076
|
+
"Cost (USD)"
|
|
3077
|
+
],
|
|
3078
|
+
style: { head: ["cyan"] },
|
|
3079
|
+
colAligns: [
|
|
3080
|
+
"left",
|
|
3081
|
+
"right",
|
|
3082
|
+
"right",
|
|
3083
|
+
"right",
|
|
3084
|
+
"right",
|
|
3085
|
+
"right",
|
|
3086
|
+
"right"
|
|
3087
|
+
]
|
|
3088
|
+
});
|
|
3089
|
+
for (const data of monthlyData) table.push([
|
|
3090
|
+
data.month,
|
|
3091
|
+
formatNumber(data.inputTokens),
|
|
3092
|
+
formatNumber(data.outputTokens),
|
|
3093
|
+
formatNumber(data.cacheCreationTokens),
|
|
3094
|
+
formatNumber(data.cacheReadTokens),
|
|
3095
|
+
formatNumber(getTotalTokens(data)),
|
|
3096
|
+
formatCurrency(data.totalCost)
|
|
3097
|
+
]);
|
|
3098
|
+
table.push([
|
|
3099
|
+
"─".repeat(12),
|
|
3100
|
+
"─".repeat(12),
|
|
3101
|
+
"─".repeat(12),
|
|
3102
|
+
"─".repeat(12),
|
|
3103
|
+
"─".repeat(12),
|
|
3104
|
+
"─".repeat(12),
|
|
3105
|
+
"─".repeat(10)
|
|
3106
|
+
]);
|
|
2961
3107
|
table.push([
|
|
2962
3108
|
import_picocolors$1.default.yellow("Total"),
|
|
2963
3109
|
import_picocolors$1.default.yellow(formatNumber(totals.inputTokens)),
|
|
@@ -2982,13 +3128,13 @@ const sessionCommand = define({
|
|
|
2982
3128
|
...sharedCommandConfig,
|
|
2983
3129
|
async run(ctx) {
|
|
2984
3130
|
if (ctx.values.json) logger.level = 0;
|
|
2985
|
-
const
|
|
3131
|
+
const sessionData = await loadSessionData({
|
|
2986
3132
|
since: ctx.values.since,
|
|
2987
3133
|
until: ctx.values.until,
|
|
2988
3134
|
claudePath: ctx.values.path,
|
|
2989
|
-
mode: ctx.values.mode
|
|
2990
|
-
|
|
2991
|
-
|
|
3135
|
+
mode: ctx.values.mode,
|
|
3136
|
+
order: ctx.values.order
|
|
3137
|
+
});
|
|
2992
3138
|
if (sessionData.length === 0) {
|
|
2993
3139
|
if (ctx.values.json) log(JSON.stringify([]));
|
|
2994
3140
|
else logger.warn("No Claude usage data found.");
|
|
@@ -3092,7 +3238,9 @@ const sessionCommand = define({
|
|
|
3092
3238
|
//#region src/commands/index.ts
|
|
3093
3239
|
const subCommands = new Map();
|
|
3094
3240
|
subCommands.set("daily", dailyCommand);
|
|
3241
|
+
subCommands.set("monthly", monthlyCommand);
|
|
3095
3242
|
subCommands.set("session", sessionCommand);
|
|
3243
|
+
subCommands.set("mcp", mcpCommand);
|
|
3096
3244
|
const mainCommand = dailyCommand;
|
|
3097
3245
|
await cli(process$1.argv.slice(2), mainCommand, {
|
|
3098
3246
|
name,
|
|
@@ -949,7 +949,7 @@ function createConsola(options = {}) {
|
|
|
949
949
|
defaults: { level },
|
|
950
950
|
stdout: process.stdout,
|
|
951
951
|
stderr: process.stderr,
|
|
952
|
-
prompt: (...args) => import("./prompt-
|
|
952
|
+
prompt: (...args) => import("./prompt-IToGuko2.js").then((m) => m.prompt(...args)),
|
|
953
953
|
reporters: options.reporters || [options.fancy ?? !(T || R) ? new FancyReporter() : new BasicReporter()],
|
|
954
954
|
...options
|
|
955
955
|
});
|
|
@@ -965,7 +965,7 @@ const consola = createConsola();
|
|
|
965
965
|
//#endregion
|
|
966
966
|
//#region package.json
|
|
967
967
|
var name = "ccusage";
|
|
968
|
-
var version = "0.
|
|
968
|
+
var version = "0.6.0";
|
|
969
969
|
var description = "Usage analysis tool for Claude Code";
|
|
970
970
|
|
|
971
971
|
//#endregion
|
package/dist/logger.js
CHANGED