ccusage 16.1.2 → 16.2.1
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 +1 -0
- package/config-schema.json +12 -0
- package/dist/{_types-BXB_jFi9.js → _types-DIdtMJ6V.js} +23 -2
- package/dist/calculate-cost.d.ts +2 -2
- package/dist/calculate-cost.js +1 -1
- package/dist/{data-loader--Ga8BPdt.d.ts → data-loader-D1FVB4Lp.d.ts} +7 -31
- package/dist/{data-loader-DUaYLdYR.js → data-loader-DzuyD9Va.js} +149 -232
- package/dist/data-loader.d.ts +3 -3
- package/dist/data-loader.js +5 -5
- package/dist/{debug-hX9iI1FE.js → debug-CWK-ECNy.js} +3 -3
- package/dist/debug.js +5 -5
- package/dist/index.js +447 -441
- package/dist/{logger-vSpPcCiQ.js → logger-Cl0x4-O7.js} +1 -1
- package/dist/logger.js +1 -1
- package/dist/{mcp-D343KJOh.js → mcp-CzT8_3kj.js} +5 -5
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +5 -5
- package/dist/{pricing-fetcher-BgDfBZ05.d.ts → pricing-fetcher-DK8lcI1w.d.ts} +1 -1
- package/dist/{pricing-fetcher-BrJoueZ1.js → pricing-fetcher-_ZIEzYHY.js} +5 -5
- package/dist/pricing-fetcher.d.ts +1 -1
- package/dist/pricing-fetcher.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
</div>
|
|
5
5
|
|
|
6
6
|
<p align="center">
|
|
7
|
+
<a href="https://socket.dev/api/npm/package/ccusage"><img src="https://socket.dev/api/badge/npm/package/ccusage" alt="Socket Badge" /></a>
|
|
7
8
|
<a href="https://npmjs.com/package/ccusage"><img src="https://img.shields.io/npm/v/ccusage?color=yellow" alt="npm version" /></a>
|
|
8
9
|
<a href="https://tanstack.com/stats/npm?packageGroups=%5B%7B%22packages%22:%5B%7B%22name%22:%22ccusage%22%7D%5D%7D%5D&range=30-days&transform=none&binType=daily&showDataMode=all&height=400"><img src="https://img.shields.io/npm/dy/ccusage" alt="NPM Downloads" /></a>
|
|
9
10
|
<a href="https://packagephobia.com/result?p=ccusage"><img src="https://packagephobia.com/badge?p=ccusage" alt="install size" /></a>
|
package/config-schema.json
CHANGED
|
@@ -745,6 +745,18 @@
|
|
|
745
745
|
"markdownDescription": "Refresh interval in seconds for cache expiry (default: 1)",
|
|
746
746
|
"default": 1
|
|
747
747
|
},
|
|
748
|
+
"contextLowThreshold": {
|
|
749
|
+
"type": "string",
|
|
750
|
+
"description": "Context usage percentage below which status is shown in green (0-100)",
|
|
751
|
+
"markdownDescription": "Context usage percentage below which status is shown in green (0-100)",
|
|
752
|
+
"default": 50
|
|
753
|
+
},
|
|
754
|
+
"contextMediumThreshold": {
|
|
755
|
+
"type": "string",
|
|
756
|
+
"description": "Context usage percentage below which status is shown in yellow (0-100)",
|
|
757
|
+
"markdownDescription": "Context usage percentage below which status is shown in yellow (0-100)",
|
|
758
|
+
"default": 80
|
|
759
|
+
},
|
|
748
760
|
"debug": {
|
|
749
761
|
"type": "boolean",
|
|
750
762
|
"description": "Show pricing mismatch information for debugging",
|
|
@@ -3015,7 +3015,28 @@ var ZodFirstPartyTypeKind;
|
|
|
3015
3015
|
(function(ZodFirstPartyTypeKind$1) {
|
|
3016
3016
|
ZodFirstPartyTypeKind$1["ZodString"] = "ZodString", ZodFirstPartyTypeKind$1["ZodNumber"] = "ZodNumber", ZodFirstPartyTypeKind$1["ZodNaN"] = "ZodNaN", ZodFirstPartyTypeKind$1["ZodBigInt"] = "ZodBigInt", ZodFirstPartyTypeKind$1["ZodBoolean"] = "ZodBoolean", ZodFirstPartyTypeKind$1["ZodDate"] = "ZodDate", ZodFirstPartyTypeKind$1["ZodSymbol"] = "ZodSymbol", ZodFirstPartyTypeKind$1["ZodUndefined"] = "ZodUndefined", ZodFirstPartyTypeKind$1["ZodNull"] = "ZodNull", ZodFirstPartyTypeKind$1["ZodAny"] = "ZodAny", ZodFirstPartyTypeKind$1["ZodUnknown"] = "ZodUnknown", ZodFirstPartyTypeKind$1["ZodNever"] = "ZodNever", ZodFirstPartyTypeKind$1["ZodVoid"] = "ZodVoid", ZodFirstPartyTypeKind$1["ZodArray"] = "ZodArray", ZodFirstPartyTypeKind$1["ZodObject"] = "ZodObject", ZodFirstPartyTypeKind$1["ZodUnion"] = "ZodUnion", ZodFirstPartyTypeKind$1["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion", ZodFirstPartyTypeKind$1["ZodIntersection"] = "ZodIntersection", ZodFirstPartyTypeKind$1["ZodTuple"] = "ZodTuple", ZodFirstPartyTypeKind$1["ZodRecord"] = "ZodRecord", ZodFirstPartyTypeKind$1["ZodMap"] = "ZodMap", ZodFirstPartyTypeKind$1["ZodSet"] = "ZodSet", ZodFirstPartyTypeKind$1["ZodFunction"] = "ZodFunction", ZodFirstPartyTypeKind$1["ZodLazy"] = "ZodLazy", ZodFirstPartyTypeKind$1["ZodLiteral"] = "ZodLiteral", ZodFirstPartyTypeKind$1["ZodEnum"] = "ZodEnum", ZodFirstPartyTypeKind$1["ZodEffects"] = "ZodEffects", ZodFirstPartyTypeKind$1["ZodNativeEnum"] = "ZodNativeEnum", ZodFirstPartyTypeKind$1["ZodOptional"] = "ZodOptional", ZodFirstPartyTypeKind$1["ZodNullable"] = "ZodNullable", ZodFirstPartyTypeKind$1["ZodDefault"] = "ZodDefault", ZodFirstPartyTypeKind$1["ZodCatch"] = "ZodCatch", ZodFirstPartyTypeKind$1["ZodPromise"] = "ZodPromise", ZodFirstPartyTypeKind$1["ZodBranded"] = "ZodBranded", ZodFirstPartyTypeKind$1["ZodPipeline"] = "ZodPipeline", ZodFirstPartyTypeKind$1["ZodReadonly"] = "ZodReadonly";
|
|
3017
3017
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
3018
|
-
const stringType = ZodString.create, numberType = ZodNumber.create, nanType = ZodNaN.create, bigIntType = ZodBigInt.create, booleanType = ZodBoolean.create, dateType = ZodDate.create, symbolType = ZodSymbol.create, undefinedType = ZodUndefined.create, nullType = ZodNull.create, anyType = ZodAny.create, unknownType = ZodUnknown.create, neverType = ZodNever.create, voidType = ZodVoid.create, arrayType = ZodArray.create, objectType = ZodObject.create, strictObjectType = ZodObject.strictCreate, unionType = ZodUnion.create, discriminatedUnionType = ZodDiscriminatedUnion.create, intersectionType = ZodIntersection.create, tupleType = ZodTuple.create, recordType = ZodRecord.create, mapType = ZodMap.create, setType = ZodSet.create, functionType = ZodFunction.create, lazyType = ZodLazy.create, literalType = ZodLiteral.create, enumType = ZodEnum.create, nativeEnumType = ZodNativeEnum.create, promiseType = ZodPromise.create, effectsType = ZodEffects.create, optionalType = ZodOptional.create, nullableType = ZodNullable.create, preprocessType = ZodEffects.createWithPreprocess, pipelineType = ZodPipeline.create,
|
|
3018
|
+
const stringType = ZodString.create, numberType = ZodNumber.create, nanType = ZodNaN.create, bigIntType = ZodBigInt.create, booleanType = ZodBoolean.create, dateType = ZodDate.create, symbolType = ZodSymbol.create, undefinedType = ZodUndefined.create, nullType = ZodNull.create, anyType = ZodAny.create, unknownType = ZodUnknown.create, neverType = ZodNever.create, voidType = ZodVoid.create, arrayType = ZodArray.create, objectType = ZodObject.create, strictObjectType = ZodObject.strictCreate, unionType = ZodUnion.create, discriminatedUnionType = ZodDiscriminatedUnion.create, intersectionType = ZodIntersection.create, tupleType = ZodTuple.create, recordType = ZodRecord.create, mapType = ZodMap.create, setType = ZodSet.create, functionType = ZodFunction.create, lazyType = ZodLazy.create, literalType = ZodLiteral.create, enumType = ZodEnum.create, nativeEnumType = ZodNativeEnum.create, promiseType = ZodPromise.create, effectsType = ZodEffects.create, optionalType = ZodOptional.create, nullableType = ZodNullable.create, preprocessType = ZodEffects.createWithPreprocess, pipelineType = ZodPipeline.create, coerce = {
|
|
3019
|
+
string: ((arg) => ZodString.create({
|
|
3020
|
+
...arg,
|
|
3021
|
+
coerce: true
|
|
3022
|
+
})),
|
|
3023
|
+
number: ((arg) => ZodNumber.create({
|
|
3024
|
+
...arg,
|
|
3025
|
+
coerce: true
|
|
3026
|
+
})),
|
|
3027
|
+
boolean: ((arg) => ZodBoolean.create({
|
|
3028
|
+
...arg,
|
|
3029
|
+
coerce: true
|
|
3030
|
+
})),
|
|
3031
|
+
bigint: ((arg) => ZodBigInt.create({
|
|
3032
|
+
...arg,
|
|
3033
|
+
coerce: true
|
|
3034
|
+
})),
|
|
3035
|
+
date: ((arg) => ZodDate.create({
|
|
3036
|
+
...arg,
|
|
3037
|
+
coerce: true
|
|
3038
|
+
}))
|
|
3039
|
+
}, modelNameSchema = stringType().min(1, "Model name cannot be empty").brand(), sessionIdSchema = stringType().min(1, "Session ID cannot be empty").brand(), requestIdSchema = stringType().min(1, "Request ID cannot be empty").brand(), messageIdSchema = stringType().min(1, "Message ID cannot be empty").brand(), isoTimestampSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/, "Invalid ISO timestamp").brand(), dailyDateSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format").brand(), activityDateSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format").brand(), monthlyDateSchema = stringType().regex(/^\d{4}-\d{2}$/, "Date must be in YYYY-MM format").brand(), weeklyDateSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format").brand(), filterDateSchema = stringType().regex(/^\d{8}$/, "Date must be in YYYYMMDD format").brand(), projectPathSchema = stringType().min(1, "Project path cannot be empty").brand(), versionSchema = stringType().regex(/^\d+\.\d+\.\d+/, "Invalid version format").brand(), createSessionId = (value) => sessionIdSchema.parse(value), createDailyDate = (value) => dailyDateSchema.parse(value), createMonthlyDate = (value) => monthlyDateSchema.parse(value), createWeeklyDate = (value) => weeklyDateSchema.parse(value), createProjectPath = (value) => projectPathSchema.parse(value);
|
|
3019
3040
|
function createBucket(value) {
|
|
3020
3041
|
return weeklyDateSchema.safeParse(value).success ? createWeeklyDate(value) : createMonthlyDate(value);
|
|
3021
3042
|
}
|
|
@@ -3052,4 +3073,4 @@ const CostModes = [
|
|
|
3052
3073
|
total_lines_removed: numberType().optional()
|
|
3053
3074
|
}).optional()
|
|
3054
3075
|
});
|
|
3055
|
-
export { CostModes, SortOrders, ZodFirstPartyTypeKind, ZodOptional, ZodType, activityDateSchema, arrayType, booleanType, createBucket, createDailyDate, createMonthlyDate, createProjectPath, createSessionId, createWeeklyDate, dailyDateSchema, discriminatedUnionType, enumType, filterDateSchema, isoTimestampSchema, literalType, messageIdSchema, modelNameSchema, modelPricingSchema, monthlyDateSchema, numberType, objectType, optionalType, projectPathSchema, recordType, requestIdSchema, sessionIdSchema, statuslineHookJsonSchema, stringType, unionType, unknownType, versionSchema, weeklyDateSchema };
|
|
3076
|
+
export { CostModes, SortOrders, ZodFirstPartyTypeKind, ZodOptional, ZodType, activityDateSchema, arrayType, booleanType, coerce, createBucket, createDailyDate, createMonthlyDate, createProjectPath, createSessionId, createWeeklyDate, dailyDateSchema, discriminatedUnionType, enumType, filterDateSchema, isoTimestampSchema, literalType, messageIdSchema, modelNameSchema, modelPricingSchema, monthlyDateSchema, numberType, objectType, optionalType, projectPathSchema, recordType, requestIdSchema, sessionIdSchema, statuslineHookJsonSchema, stringType, unionType, unknownType, versionSchema, weeklyDateSchema };
|
package/dist/calculate-cost.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
1
|
+
import { DailyUsage, MonthlyUsage, SessionUsage, WeeklyUsage } from "./data-loader-D1FVB4Lp.js";
|
|
2
|
+
import "./pricing-fetcher-DK8lcI1w.js";
|
|
3
3
|
|
|
4
4
|
//#region src/_token-utils.d.ts
|
|
5
5
|
|
package/dist/calculate-cost.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { getTotalTokens } from "./_token-utils-WjkbrjKv.js";
|
|
2
|
-
import "./_types-
|
|
2
|
+
import "./_types-DIdtMJ6V.js";
|
|
3
3
|
import { calculateTotals, createTotalsObject } from "./calculate-cost-BDqO4yWA.js";
|
|
4
4
|
export { calculateTotals, createTotalsObject, getTotalTokens };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Bucket, CostMode, PricingFetcher, SortOrder
|
|
1
|
+
import { Bucket, CostMode, PricingFetcher, SortOrder } from "./pricing-fetcher-DK8lcI1w.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/_consts.d.ts
|
|
@@ -8,8 +8,11 @@ import { z } from "zod";
|
|
|
8
8
|
*/
|
|
9
9
|
declare const WEEK_DAYS: readonly ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
|
|
11
|
+
* Week day names type
|
|
12
|
+
*/
|
|
13
|
+
type WeekDay = typeof WEEK_DAYS[number];
|
|
14
|
+
/**
|
|
15
|
+
* Day of week as number (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
|
|
13
16
|
*/
|
|
14
17
|
//#endregion
|
|
15
18
|
//#region src/_session-blocks.d.ts
|
|
@@ -66,16 +69,6 @@ type SessionBlock = {
|
|
|
66
69
|
* @returns Array of valid Claude data directory paths
|
|
67
70
|
*/
|
|
68
71
|
declare function getClaudePaths(): string[];
|
|
69
|
-
/**
|
|
70
|
-
* Get context usage percentage thresholds for color coding
|
|
71
|
-
* Can be configured via environment variables or uses defaults
|
|
72
|
-
* Validates and clamps values to 0-100 range and enforces LOW < MEDIUM ordering
|
|
73
|
-
* @returns Context usage thresholds with LOW and MEDIUM percentages
|
|
74
|
-
*/
|
|
75
|
-
declare function getContextUsageThresholds(): {
|
|
76
|
-
readonly LOW: number;
|
|
77
|
-
readonly MEDIUM: number;
|
|
78
|
-
};
|
|
79
72
|
/**
|
|
80
73
|
* Extract project name from Claude JSONL file path
|
|
81
74
|
* @param jsonlPath - Absolute path to JSONL file
|
|
@@ -668,22 +661,6 @@ declare const bucketUsageSchema: z.ZodObject<{
|
|
|
668
661
|
* Type definition for bucket usage aggregation
|
|
669
662
|
*/
|
|
670
663
|
type BucketUsage = z.infer<typeof bucketUsageSchema>;
|
|
671
|
-
/**
|
|
672
|
-
* Formats a date string to YYYY-MM-DD format
|
|
673
|
-
* @param dateStr - Input date string
|
|
674
|
-
* @param timezone - Optional timezone to use for formatting
|
|
675
|
-
* @param locale - Optional locale to use for formatting (defaults to 'en-CA' for YYYY-MM-DD format)
|
|
676
|
-
* @returns Formatted date string in YYYY-MM-DD format
|
|
677
|
-
*/
|
|
678
|
-
declare function formatDate(dateStr: string, timezone?: string, locale?: string): string;
|
|
679
|
-
/**
|
|
680
|
-
* Formats a date string to compact format with year on first line and month-day on second
|
|
681
|
-
* @param dateStr - Input date string
|
|
682
|
-
* @param timezone - Timezone to use for formatting (pass undefined to use system timezone)
|
|
683
|
-
* @param locale - Locale to use for formatting
|
|
684
|
-
* @returns Formatted date string with newline separator (YYYY\nMM-DD)
|
|
685
|
-
*/
|
|
686
|
-
declare function formatDateCompact(dateStr: string, timezone: string | undefined, locale: string): string;
|
|
687
664
|
/**
|
|
688
665
|
* Create a unique identifier for deduplication using message ID and request ID
|
|
689
666
|
*/
|
|
@@ -732,7 +709,6 @@ type DateFilter = {
|
|
|
732
709
|
since?: string; // YYYYMMDD format
|
|
733
710
|
until?: string; // YYYYMMDD format
|
|
734
711
|
};
|
|
735
|
-
type WeekDay = TupleToUnion<typeof WEEK_DAYS>;
|
|
736
712
|
/**
|
|
737
713
|
* Configuration options for loading usage data
|
|
738
714
|
*/
|
|
@@ -806,4 +782,4 @@ declare function calculateContextTokens(transcriptPath: string, modelId?: string
|
|
|
806
782
|
*/
|
|
807
783
|
declare function loadSessionBlockData(options?: LoadOptions): Promise<SessionBlock[]>;
|
|
808
784
|
//#endregion
|
|
809
|
-
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath,
|
|
785
|
+
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME,
|
|
1
|
+
import { CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME, DEFAULT_CLAUDE_CODE_PATH, DEFAULT_CLAUDE_CONFIG_PATH, DEFAULT_LOCALE, DEFAULT_RECENT_DAYS, PricingFetcher, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR, __commonJSMin, __require, __toESM, isFailure, isPromise, isSuccess, map, pipe, require_usingCtx, try_ } from "./pricing-fetcher-_ZIEzYHY.js";
|
|
2
2
|
import { getTotalTokens } from "./_token-utils-WjkbrjKv.js";
|
|
3
|
-
import { activityDateSchema, arrayType, booleanType, createBucket, createDailyDate, createMonthlyDate, createProjectPath, createSessionId, createWeeklyDate, dailyDateSchema, isoTimestampSchema, messageIdSchema, modelNameSchema, monthlyDateSchema, numberType, objectType, projectPathSchema, requestIdSchema, sessionIdSchema, stringType, unionType, versionSchema, weeklyDateSchema } from "./_types-
|
|
4
|
-
import { logger } from "./logger-
|
|
5
|
-
import a, { readFile } from "node:fs/promises";
|
|
3
|
+
import { activityDateSchema, arrayType, booleanType, createBucket, createDailyDate, createMonthlyDate, createProjectPath, createSessionId, createWeeklyDate, dailyDateSchema, isoTimestampSchema, messageIdSchema, modelNameSchema, monthlyDateSchema, numberType, objectType, projectPathSchema, requestIdSchema, sessionIdSchema, stringType, unionType, versionSchema, weeklyDateSchema } from "./_types-DIdtMJ6V.js";
|
|
4
|
+
import { logger } from "./logger-Cl0x4-O7.js";
|
|
5
|
+
import a, { readFile, stat } from "node:fs/promises";
|
|
6
6
|
import path, { posix } from "node:path";
|
|
7
7
|
import process$1 from "node:process";
|
|
8
8
|
import b from "node:fs";
|
|
@@ -10,83 +10,7 @@ import F from "node:os";
|
|
|
10
10
|
function toArray(array) {
|
|
11
11
|
return array = array ?? [], Array.isArray(array) ? array : [array];
|
|
12
12
|
}
|
|
13
|
-
const VOID = Symbol("p-void")
|
|
14
|
-
function isString(x) {
|
|
15
|
-
return typeof x === "string";
|
|
16
|
-
}
|
|
17
|
-
function isRecord(x) {
|
|
18
|
-
return x != null && !Array.isArray(x) && typeof x === "object";
|
|
19
|
-
}
|
|
20
|
-
const defaultThreshold = 20;
|
|
21
|
-
function inspect(value, options = {}) {
|
|
22
|
-
if (value === null) return "null";
|
|
23
|
-
if (Array.isArray(value)) return inspectArray(value, options);
|
|
24
|
-
switch (typeof value) {
|
|
25
|
-
case "string": return JSON.stringify(value);
|
|
26
|
-
case "bigint": return `${value}n`;
|
|
27
|
-
case "object": return value.constructor?.name === "Object" ? inspectRecord(value, options) : value.constructor?.name;
|
|
28
|
-
case "function": return value.name || "(anonymous)";
|
|
29
|
-
}
|
|
30
|
-
return value?.toString() ?? "undefined";
|
|
31
|
-
}
|
|
32
|
-
function inspectArray(value, options) {
|
|
33
|
-
const { threshold = defaultThreshold } = options, vs = value.map((v$1) => inspect(v$1, options)), s = vs.join(", ");
|
|
34
|
-
if (s.length <= threshold) return `[${s}]`;
|
|
35
|
-
const m$1 = vs.join(",\n");
|
|
36
|
-
return `[\n${indent(2, m$1)}\n]`;
|
|
37
|
-
}
|
|
38
|
-
function inspectRecord(value, options) {
|
|
39
|
-
const { threshold = defaultThreshold } = options, vs = [...Object.keys(value), ...Object.getOwnPropertySymbols(value)].map((k$1) => `${k$1.toString()}: ${inspect(value[k$1], options)}`), s = vs.join(", ");
|
|
40
|
-
if (s.length <= threshold) return `{${s}}`;
|
|
41
|
-
const m$1 = vs.join(",\n");
|
|
42
|
-
return `{\n${indent(2, m$1)}\n}`;
|
|
43
|
-
}
|
|
44
|
-
function indent(level, text) {
|
|
45
|
-
const prefix = " ".repeat(level);
|
|
46
|
-
return text.split("\n").map((line) => `${prefix}${line}`).join("\n");
|
|
47
|
-
}
|
|
48
|
-
function rewriteName(fn, name, ...args) {
|
|
49
|
-
let cachedName;
|
|
50
|
-
return Object.defineProperties(fn, { name: { get: () => {
|
|
51
|
-
return cachedName || (cachedName = `${name}(${args.map((v$1) => inspect(v$1)).join(", ")})`, cachedName);
|
|
52
|
-
} } });
|
|
53
|
-
}
|
|
54
|
-
function annotate(fn, name, value) {
|
|
55
|
-
return Object.defineProperties(fn, { [name]: { value } });
|
|
56
|
-
}
|
|
57
|
-
function hasAnnotation(fn, name) {
|
|
58
|
-
return !!fn[name];
|
|
59
|
-
}
|
|
60
|
-
function isObjectOf(predObj) {
|
|
61
|
-
const preds = [...Object.keys(predObj), ...Object.getOwnPropertySymbols(predObj)].map((k$1) => [k$1, predObj[k$1]]), pred = rewriteName((x) => {
|
|
62
|
-
return isObject$1(x) ? preds.every(([k$1, pred$1]) => pred$1(x[k$1])) : false;
|
|
63
|
-
}, "isObjectOf", predObj);
|
|
64
|
-
return annotate(pred, "predObj", predObj);
|
|
65
|
-
}
|
|
66
|
-
function isObject$1(x) {
|
|
67
|
-
return !(x == null || typeof x !== "object" && typeof x !== "function" || Array.isArray(x));
|
|
68
|
-
}
|
|
69
|
-
function asOptional(pred) {
|
|
70
|
-
return hasAnnotation(pred, "optional") ? pred : rewriteName(annotate((x) => x === void 0 || pred(x), "optional", pred), "asOptional", pred);
|
|
71
|
-
}
|
|
72
|
-
const isErrorObject = isObjectOf({
|
|
73
|
-
proto: isString,
|
|
74
|
-
name: isString,
|
|
75
|
-
message: isString,
|
|
76
|
-
stack: asOptional(isString),
|
|
77
|
-
attributes: isRecord
|
|
78
|
-
});
|
|
79
|
-
var UnreachableError = class UnreachableError extends Error {
|
|
80
|
-
args;
|
|
81
|
-
constructor(args) {
|
|
82
|
-
if (super(`unreachable: ${args}`), Error.captureStackTrace) Error.captureStackTrace(this, UnreachableError);
|
|
83
|
-
this.name = this.constructor.name, this.args = args;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
function unreachable(...args) {
|
|
87
|
-
throw new UnreachableError(args);
|
|
88
|
-
}
|
|
89
|
-
const isResult = (result) => "object" == typeof result && null !== result && "type" in result && ("Success" === result.type && "value" in result || "Failure" === result.type && "error" in result), unwrap = (...args) => {
|
|
13
|
+
const VOID = Symbol("p-void"), isResult = (result) => "object" == typeof result && null !== result && "type" in result && ("Success" === result.type && "value" in result || "Failure" === result.type && "error" in result), unwrap = (...args) => {
|
|
90
14
|
const firstArgument = args[0];
|
|
91
15
|
if (isResult(firstArgument) || isPromise(firstArgument)) {
|
|
92
16
|
const result = firstArgument, hasDefault$1 = 2 === args.length, defaultValue$1 = hasDefault$1 ? args[1] : void 0, apply = (r) => {
|
|
@@ -122,82 +46,7 @@ function groupBy(arr, getKeyFromItem) {
|
|
|
122
46
|
function uniq(arr) {
|
|
123
47
|
return Array.from(new Set(arr));
|
|
124
48
|
}
|
|
125
|
-
var
|
|
126
|
-
return function(a$1, b$1, order) {
|
|
127
|
-
return comparer(a$1, b$1, order) * order;
|
|
128
|
-
};
|
|
129
|
-
}, throwInvalidConfigErrorIfTrue = function(condition, context) {
|
|
130
|
-
if (condition) throw Error("Invalid sort config: " + context);
|
|
131
|
-
}, unpackObjectSorter = function(sortByObj) {
|
|
132
|
-
var _a = sortByObj || {}, asc = _a.asc, desc = _a.desc, order = asc ? 1 : -1, sortBy = asc || desc;
|
|
133
|
-
throwInvalidConfigErrorIfTrue(!sortBy, "Expected `asc` or `desc` property"), throwInvalidConfigErrorIfTrue(asc && desc, "Ambiguous object with `asc` and `desc` config properties");
|
|
134
|
-
var comparer = sortByObj.comparer && castComparer(sortByObj.comparer);
|
|
135
|
-
return {
|
|
136
|
-
order,
|
|
137
|
-
sortBy,
|
|
138
|
-
comparer
|
|
139
|
-
};
|
|
140
|
-
}, multiPropertySorterProvider = function(defaultComparer$1) {
|
|
141
|
-
return function multiPropertySorter(sortBy, sortByArr, depth$1, order, comparer, a$1, b$1) {
|
|
142
|
-
var valA, valB;
|
|
143
|
-
if (typeof sortBy === "string") valA = a$1[sortBy], valB = b$1[sortBy];
|
|
144
|
-
else if (typeof sortBy === "function") valA = sortBy(a$1), valB = sortBy(b$1);
|
|
145
|
-
else {
|
|
146
|
-
var objectSorterConfig = unpackObjectSorter(sortBy);
|
|
147
|
-
return multiPropertySorter(objectSorterConfig.sortBy, sortByArr, depth$1, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer$1, a$1, b$1);
|
|
148
|
-
}
|
|
149
|
-
var equality = comparer(valA, valB, order);
|
|
150
|
-
return (equality === 0 || valA == null && valB == null) && sortByArr.length > depth$1 ? multiPropertySorter(sortByArr[depth$1], sortByArr, depth$1 + 1, order, comparer, a$1, b$1) : equality;
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
function getSortStrategy(sortBy, comparer, order) {
|
|
154
|
-
if (sortBy === void 0 || sortBy === true) return function(a$1, b$1) {
|
|
155
|
-
return comparer(a$1, b$1, order);
|
|
156
|
-
};
|
|
157
|
-
if (typeof sortBy === "string") return throwInvalidConfigErrorIfTrue(sortBy.includes("."), "String syntax not allowed for nested properties."), function(a$1, b$1) {
|
|
158
|
-
return comparer(a$1[sortBy], b$1[sortBy], order);
|
|
159
|
-
};
|
|
160
|
-
if (typeof sortBy === "function") return function(a$1, b$1) {
|
|
161
|
-
return comparer(sortBy(a$1), sortBy(b$1), order);
|
|
162
|
-
};
|
|
163
|
-
if (Array.isArray(sortBy)) {
|
|
164
|
-
var multiPropSorter_1 = multiPropertySorterProvider(comparer);
|
|
165
|
-
return function(a$1, b$1) {
|
|
166
|
-
return multiPropSorter_1(sortBy[0], sortBy, 1, order, comparer, a$1, b$1);
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
var objectSorterConfig = unpackObjectSorter(sortBy);
|
|
170
|
-
return getSortStrategy(objectSorterConfig.sortBy, objectSorterConfig.comparer || comparer, objectSorterConfig.order);
|
|
171
|
-
}
|
|
172
|
-
var sortArray = function(order, ctx, sortBy, comparer) {
|
|
173
|
-
var _a;
|
|
174
|
-
if (!Array.isArray(ctx)) return ctx;
|
|
175
|
-
if (Array.isArray(sortBy) && sortBy.length < 2) _a = sortBy, sortBy = _a[0];
|
|
176
|
-
return ctx.sort(getSortStrategy(sortBy, comparer, order));
|
|
177
|
-
};
|
|
178
|
-
function createNewSortInstance(opts) {
|
|
179
|
-
var comparer = castComparer(opts.comparer);
|
|
180
|
-
return function(arrayToSort) {
|
|
181
|
-
var ctx = Array.isArray(arrayToSort) && !opts.inPlaceSorting ? arrayToSort.slice() : arrayToSort;
|
|
182
|
-
return {
|
|
183
|
-
asc: function(sortBy) {
|
|
184
|
-
return sortArray(1, ctx, sortBy, comparer);
|
|
185
|
-
},
|
|
186
|
-
desc: function(sortBy) {
|
|
187
|
-
return sortArray(-1, ctx, sortBy, comparer);
|
|
188
|
-
},
|
|
189
|
-
by: function(sortBy) {
|
|
190
|
-
return sortArray(1, ctx, sortBy, comparer);
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
var defaultComparer = function(a$1, b$1, order) {
|
|
196
|
-
return a$1 == null ? order : b$1 == null ? -order : typeof a$1 === typeof b$1 ? a$1 < b$1 ? -1 : a$1 > b$1 ? 1 : 0 : typeof a$1 < typeof b$1 ? -1 : 1;
|
|
197
|
-
}, sort = createNewSortInstance({ comparer: defaultComparer }), inPlaceSort = createNewSortInstance({
|
|
198
|
-
comparer: defaultComparer,
|
|
199
|
-
inPlaceSorting: true
|
|
200
|
-
}), d = Object.defineProperty, n = (s, t) => d(s, "name", {
|
|
49
|
+
var d = Object.defineProperty, n = (s, t) => d(s, "name", {
|
|
201
50
|
value: t,
|
|
202
51
|
configurable: !0
|
|
203
52
|
});
|
|
@@ -2059,6 +1908,145 @@ async function glob(patternsOrOptions, options) {
|
|
|
2059
1908
|
} : patternsOrOptions, cwd = opts.cwd ? path.resolve(opts.cwd).replace(BACKSLASHES, "/") : process.cwd().replace(BACKSLASHES, "/");
|
|
2060
1909
|
return crawl(opts, cwd, false);
|
|
2061
1910
|
}
|
|
1911
|
+
var castComparer = function(comparer) {
|
|
1912
|
+
return function(a$1, b$1, order) {
|
|
1913
|
+
return comparer(a$1, b$1, order) * order;
|
|
1914
|
+
};
|
|
1915
|
+
}, throwInvalidConfigErrorIfTrue = function(condition, context) {
|
|
1916
|
+
if (condition) throw Error("Invalid sort config: " + context);
|
|
1917
|
+
}, unpackObjectSorter = function(sortByObj) {
|
|
1918
|
+
var _a = sortByObj || {}, asc = _a.asc, desc = _a.desc, order = asc ? 1 : -1, sortBy = asc || desc;
|
|
1919
|
+
throwInvalidConfigErrorIfTrue(!sortBy, "Expected `asc` or `desc` property"), throwInvalidConfigErrorIfTrue(asc && desc, "Ambiguous object with `asc` and `desc` config properties");
|
|
1920
|
+
var comparer = sortByObj.comparer && castComparer(sortByObj.comparer);
|
|
1921
|
+
return {
|
|
1922
|
+
order,
|
|
1923
|
+
sortBy,
|
|
1924
|
+
comparer
|
|
1925
|
+
};
|
|
1926
|
+
}, multiPropertySorterProvider = function(defaultComparer$1) {
|
|
1927
|
+
return function multiPropertySorter(sortBy, sortByArr, depth$1, order, comparer, a$1, b$1) {
|
|
1928
|
+
var valA, valB;
|
|
1929
|
+
if (typeof sortBy === "string") valA = a$1[sortBy], valB = b$1[sortBy];
|
|
1930
|
+
else if (typeof sortBy === "function") valA = sortBy(a$1), valB = sortBy(b$1);
|
|
1931
|
+
else {
|
|
1932
|
+
var objectSorterConfig = unpackObjectSorter(sortBy);
|
|
1933
|
+
return multiPropertySorter(objectSorterConfig.sortBy, sortByArr, depth$1, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer$1, a$1, b$1);
|
|
1934
|
+
}
|
|
1935
|
+
var equality = comparer(valA, valB, order);
|
|
1936
|
+
return (equality === 0 || valA == null && valB == null) && sortByArr.length > depth$1 ? multiPropertySorter(sortByArr[depth$1], sortByArr, depth$1 + 1, order, comparer, a$1, b$1) : equality;
|
|
1937
|
+
};
|
|
1938
|
+
};
|
|
1939
|
+
function getSortStrategy(sortBy, comparer, order) {
|
|
1940
|
+
if (sortBy === void 0 || sortBy === true) return function(a$1, b$1) {
|
|
1941
|
+
return comparer(a$1, b$1, order);
|
|
1942
|
+
};
|
|
1943
|
+
if (typeof sortBy === "string") return throwInvalidConfigErrorIfTrue(sortBy.includes("."), "String syntax not allowed for nested properties."), function(a$1, b$1) {
|
|
1944
|
+
return comparer(a$1[sortBy], b$1[sortBy], order);
|
|
1945
|
+
};
|
|
1946
|
+
if (typeof sortBy === "function") return function(a$1, b$1) {
|
|
1947
|
+
return comparer(sortBy(a$1), sortBy(b$1), order);
|
|
1948
|
+
};
|
|
1949
|
+
if (Array.isArray(sortBy)) {
|
|
1950
|
+
var multiPropSorter_1 = multiPropertySorterProvider(comparer);
|
|
1951
|
+
return function(a$1, b$1) {
|
|
1952
|
+
return multiPropSorter_1(sortBy[0], sortBy, 1, order, comparer, a$1, b$1);
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
var objectSorterConfig = unpackObjectSorter(sortBy);
|
|
1956
|
+
return getSortStrategy(objectSorterConfig.sortBy, objectSorterConfig.comparer || comparer, objectSorterConfig.order);
|
|
1957
|
+
}
|
|
1958
|
+
var sortArray = function(order, ctx, sortBy, comparer) {
|
|
1959
|
+
var _a;
|
|
1960
|
+
if (!Array.isArray(ctx)) return ctx;
|
|
1961
|
+
if (Array.isArray(sortBy) && sortBy.length < 2) _a = sortBy, sortBy = _a[0];
|
|
1962
|
+
return ctx.sort(getSortStrategy(sortBy, comparer, order));
|
|
1963
|
+
};
|
|
1964
|
+
function createNewSortInstance(opts) {
|
|
1965
|
+
var comparer = castComparer(opts.comparer);
|
|
1966
|
+
return function(arrayToSort) {
|
|
1967
|
+
var ctx = Array.isArray(arrayToSort) && !opts.inPlaceSorting ? arrayToSort.slice() : arrayToSort;
|
|
1968
|
+
return {
|
|
1969
|
+
asc: function(sortBy) {
|
|
1970
|
+
return sortArray(1, ctx, sortBy, comparer);
|
|
1971
|
+
},
|
|
1972
|
+
desc: function(sortBy) {
|
|
1973
|
+
return sortArray(-1, ctx, sortBy, comparer);
|
|
1974
|
+
},
|
|
1975
|
+
by: function(sortBy) {
|
|
1976
|
+
return sortArray(1, ctx, sortBy, comparer);
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
var defaultComparer = function(a$1, b$1, order) {
|
|
1982
|
+
return a$1 == null ? order : b$1 == null ? -order : typeof a$1 === typeof b$1 ? a$1 < b$1 ? -1 : a$1 > b$1 ? 1 : 0 : typeof a$1 < typeof b$1 ? -1 : 1;
|
|
1983
|
+
}, sort = createNewSortInstance({ comparer: defaultComparer }), inPlaceSort = createNewSortInstance({
|
|
1984
|
+
comparer: defaultComparer,
|
|
1985
|
+
inPlaceSorting: true
|
|
1986
|
+
}), import_usingCtx$1 = /* @__PURE__ */ __toESM(require_usingCtx(), 1);
|
|
1987
|
+
function unreachable(value) {
|
|
1988
|
+
throw new Error(`Unreachable code reached with value: ${value}`);
|
|
1989
|
+
}
|
|
1990
|
+
async function getFileModifiedTime(filePath) {
|
|
1991
|
+
return pipe(try_({
|
|
1992
|
+
try: stat(filePath),
|
|
1993
|
+
catch: (error) => error
|
|
1994
|
+
}), map((stats) => stats.mtime.getTime()), unwrap(0));
|
|
1995
|
+
}
|
|
1996
|
+
function createDateFormatter(timezone, locale) {
|
|
1997
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1998
|
+
year: "numeric",
|
|
1999
|
+
month: "2-digit",
|
|
2000
|
+
day: "2-digit",
|
|
2001
|
+
timeZone: timezone
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
function createDatePartsFormatter(timezone, locale) {
|
|
2005
|
+
return new Intl.DateTimeFormat(locale, {
|
|
2006
|
+
year: "numeric",
|
|
2007
|
+
month: "2-digit",
|
|
2008
|
+
day: "2-digit",
|
|
2009
|
+
timeZone: timezone
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
function formatDate(dateStr, timezone, locale) {
|
|
2013
|
+
const date = new Date(dateStr), formatter = createDateFormatter(timezone, locale ?? DEFAULT_LOCALE);
|
|
2014
|
+
return formatter.format(date);
|
|
2015
|
+
}
|
|
2016
|
+
function formatDateCompact(dateStr, timezone, locale) {
|
|
2017
|
+
const parseResult = dailyDateSchema.safeParse(dateStr), date = parseResult.success ? timezone != null ? /* @__PURE__ */ new Date(`${dateStr}T00:00:00Z`) : /* @__PURE__ */ new Date(`${dateStr}T00:00:00`) : new Date(dateStr), formatter = createDatePartsFormatter(timezone, locale), parts = formatter.formatToParts(date), year = parts.find((p) => p.type === "year")?.value ?? "", month = parts.find((p) => p.type === "month")?.value ?? "", day = parts.find((p) => p.type === "day")?.value ?? "";
|
|
2018
|
+
return `${year}\n${month}-${day}`;
|
|
2019
|
+
}
|
|
2020
|
+
function sortByDate(items, getDate, order = "desc") {
|
|
2021
|
+
const sorted = sort(items);
|
|
2022
|
+
switch (order) {
|
|
2023
|
+
case "desc": return sorted.desc((item) => new Date(getDate(item)).getTime());
|
|
2024
|
+
case "asc": return sorted.asc((item) => new Date(getDate(item)).getTime());
|
|
2025
|
+
default: unreachable(order);
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
function filterByDateRange(items, getDate, since, until) {
|
|
2029
|
+
return since == null && until == null ? items : items.filter((item) => {
|
|
2030
|
+
const dateStr = getDate(item).substring(0, 10).replace(/-/g, "");
|
|
2031
|
+
return !(since != null && dateStr < since || until != null && dateStr > until);
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
2034
|
+
function getDateWeek(date, startDay) {
|
|
2035
|
+
const d$1 = new Date(date), day = d$1.getDay(), shift = (day - startDay + 7) % 7;
|
|
2036
|
+
return d$1.setDate(d$1.getDate() - shift), createWeeklyDate(d$1.toISOString().substring(0, 10));
|
|
2037
|
+
}
|
|
2038
|
+
function getDayNumber(day) {
|
|
2039
|
+
const dayMap = {
|
|
2040
|
+
sunday: 0,
|
|
2041
|
+
monday: 1,
|
|
2042
|
+
tuesday: 2,
|
|
2043
|
+
wednesday: 3,
|
|
2044
|
+
thursday: 4,
|
|
2045
|
+
friday: 5,
|
|
2046
|
+
saturday: 6
|
|
2047
|
+
};
|
|
2048
|
+
return dayMap[day];
|
|
2049
|
+
}
|
|
2062
2050
|
const DEFAULT_SESSION_DURATION_HOURS = 5;
|
|
2063
2051
|
function floorToHour(timestamp) {
|
|
2064
2052
|
const floored = new Date(timestamp);
|
|
@@ -2201,23 +2189,6 @@ function getClaudePaths() {
|
|
|
2201
2189
|
- Or set ${CLAUDE_CONFIG_DIR_ENV} environment variable to valid directory path(s) containing a '${CLAUDE_PROJECTS_DIR_NAME}' subdirectory`.trim());
|
|
2202
2190
|
return paths;
|
|
2203
2191
|
}
|
|
2204
|
-
function getContextUsageThresholds() {
|
|
2205
|
-
const lowThresholdStr = process$1.env[CONTEXT_LOW_THRESHOLD_ENV], mediumThresholdStr = process$1.env[CONTEXT_MEDIUM_THRESHOLD_ENV];
|
|
2206
|
-
let lowThreshold = DEFAULT_CONTEXT_USAGE_THRESHOLDS.LOW, mediumThreshold = DEFAULT_CONTEXT_USAGE_THRESHOLDS.MEDIUM;
|
|
2207
|
-
if (lowThresholdStr != null) {
|
|
2208
|
-
const parsed = Number.parseInt(lowThresholdStr, 10);
|
|
2209
|
-
if (!Number.isNaN(parsed)) lowThreshold = Math.max(0, Math.min(100, parsed));
|
|
2210
|
-
}
|
|
2211
|
-
if (mediumThresholdStr != null) {
|
|
2212
|
-
const parsed = Number.parseInt(mediumThresholdStr, 10);
|
|
2213
|
-
if (!Number.isNaN(parsed)) mediumThreshold = Math.max(0, Math.min(100, parsed));
|
|
2214
|
-
}
|
|
2215
|
-
if (lowThreshold >= mediumThreshold) lowThreshold = DEFAULT_CONTEXT_USAGE_THRESHOLDS.LOW, mediumThreshold = DEFAULT_CONTEXT_USAGE_THRESHOLDS.MEDIUM;
|
|
2216
|
-
return {
|
|
2217
|
-
LOW: lowThreshold,
|
|
2218
|
-
MEDIUM: mediumThreshold
|
|
2219
|
-
};
|
|
2220
|
-
}
|
|
2221
2192
|
function extractProjectFromPath(jsonlPath) {
|
|
2222
2193
|
const normalizedPath = jsonlPath.replace(/[/\\]/g, path.sep), segments = normalizedPath.split(path.sep), projectsIndex = segments.findIndex((segment) => segment === CLAUDE_PROJECTS_DIR_NAME);
|
|
2223
2194
|
if (projectsIndex === -1 || projectsIndex + 1 >= segments.length) return "unknown";
|
|
@@ -2380,12 +2351,6 @@ function calculateTotals(entries, getUsage, getCost) {
|
|
|
2380
2351
|
totalCost: 0
|
|
2381
2352
|
});
|
|
2382
2353
|
}
|
|
2383
|
-
function filterByDateRange(items, getDate, since, until) {
|
|
2384
|
-
return since == null && until == null ? items : items.filter((item) => {
|
|
2385
|
-
const dateStr = getDate(item).substring(0, 10).replace(/-/g, "");
|
|
2386
|
-
return !(since != null && dateStr < since || until != null && dateStr > until);
|
|
2387
|
-
});
|
|
2388
|
-
}
|
|
2389
2354
|
function filterByProject(items, getProject, projectFilter) {
|
|
2390
2355
|
return projectFilter == null ? items : items.filter((item) => {
|
|
2391
2356
|
const projectName = getProject(item);
|
|
@@ -2401,38 +2366,6 @@ function markAsProcessed(uniqueHash, processedHashes) {
|
|
|
2401
2366
|
function extractUniqueModels(entries, getModel) {
|
|
2402
2367
|
return uniq(entries.map(getModel).filter((m$1) => m$1 != null && m$1 !== "<synthetic>"));
|
|
2403
2368
|
}
|
|
2404
|
-
function createDateFormatter(timezone, locale) {
|
|
2405
|
-
return new Intl.DateTimeFormat(locale, {
|
|
2406
|
-
year: "numeric",
|
|
2407
|
-
month: "2-digit",
|
|
2408
|
-
day: "2-digit",
|
|
2409
|
-
timeZone: timezone
|
|
2410
|
-
});
|
|
2411
|
-
}
|
|
2412
|
-
function createDatePartsFormatter(timezone, locale) {
|
|
2413
|
-
return new Intl.DateTimeFormat(locale, {
|
|
2414
|
-
year: "numeric",
|
|
2415
|
-
month: "2-digit",
|
|
2416
|
-
day: "2-digit",
|
|
2417
|
-
timeZone: timezone
|
|
2418
|
-
});
|
|
2419
|
-
}
|
|
2420
|
-
function formatDate(dateStr, timezone, locale) {
|
|
2421
|
-
const date = new Date(dateStr), formatter = createDateFormatter(timezone, locale ?? "en-CA");
|
|
2422
|
-
return formatter.format(date);
|
|
2423
|
-
}
|
|
2424
|
-
function formatDateCompact(dateStr, timezone, locale) {
|
|
2425
|
-
const parseResult = dailyDateSchema.safeParse(dateStr), date = parseResult.success ? timezone != null ? /* @__PURE__ */ new Date(`${dateStr}T00:00:00Z`) : /* @__PURE__ */ new Date(`${dateStr}T00:00:00`) : new Date(dateStr), formatter = createDatePartsFormatter(timezone, locale), parts = formatter.formatToParts(date), year = parts.find((p) => p.type === "year")?.value ?? "", month = parts.find((p) => p.type === "month")?.value ?? "", day = parts.find((p) => p.type === "day")?.value ?? "";
|
|
2426
|
-
return `${year}\n${month}-${day}`;
|
|
2427
|
-
}
|
|
2428
|
-
function sortByDate(items, getDate, order = "desc") {
|
|
2429
|
-
const sorted = sort(items);
|
|
2430
|
-
switch (order) {
|
|
2431
|
-
case "desc": return sorted.desc((item) => new Date(getDate(item)).getTime());
|
|
2432
|
-
case "asc": return sorted.asc((item) => new Date(getDate(item)).getTime());
|
|
2433
|
-
default: unreachable(order);
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
2369
|
function createUniqueHash(data) {
|
|
2437
2370
|
const messageId = data.message.id, requestId = data.requestId;
|
|
2438
2371
|
return messageId == null || requestId == null ? null : `${messageId}:${requestId}`;
|
|
@@ -2513,7 +2446,7 @@ async function loadDailyUsageData(options) {
|
|
|
2513
2446
|
const data = result.data, uniqueHash = createUniqueHash(data);
|
|
2514
2447
|
if (isDuplicateEntry(uniqueHash, processedHashes)) continue;
|
|
2515
2448
|
markAsProcessed(uniqueHash, processedHashes);
|
|
2516
|
-
const date = formatDate(data.timestamp, options?.timezone,
|
|
2449
|
+
const date = formatDate(data.timestamp, options?.timezone, DEFAULT_LOCALE), cost = fetcher != null ? await calculateCostForEntry(data, mode, fetcher) : data.costUSD ?? 0, project = extractProjectFromPath(file);
|
|
2517
2450
|
allEntries.push({
|
|
2518
2451
|
data,
|
|
2519
2452
|
date,
|
|
@@ -2579,7 +2512,7 @@ async function loadSessionData(options) {
|
|
|
2579
2512
|
sessionId: createSessionId(latestEntry.sessionId),
|
|
2580
2513
|
projectPath: createProjectPath(latestEntry.projectPath),
|
|
2581
2514
|
...totals,
|
|
2582
|
-
lastActivity: formatDate(latestEntry.timestamp, options?.timezone,
|
|
2515
|
+
lastActivity: formatDate(latestEntry.timestamp, options?.timezone, DEFAULT_LOCALE),
|
|
2583
2516
|
versions: uniq(versions).sort(),
|
|
2584
2517
|
modelsUsed,
|
|
2585
2518
|
modelBreakdowns
|
|
@@ -2598,22 +2531,6 @@ async function loadMonthlyUsageData(options) {
|
|
|
2598
2531
|
...rest
|
|
2599
2532
|
})));
|
|
2600
2533
|
}
|
|
2601
|
-
function getDateWeek(date, startDay) {
|
|
2602
|
-
const d$1 = new Date(date), day = d$1.getDay(), shift = (day - startDay + 7) % 7;
|
|
2603
|
-
return d$1.setDate(d$1.getDate() - shift), createWeeklyDate(d$1.toISOString().substring(0, 10));
|
|
2604
|
-
}
|
|
2605
|
-
function getDayNumber(day) {
|
|
2606
|
-
const dayMap = {
|
|
2607
|
-
sunday: 0,
|
|
2608
|
-
monday: 1,
|
|
2609
|
-
tuesday: 2,
|
|
2610
|
-
wednesday: 3,
|
|
2611
|
-
thursday: 4,
|
|
2612
|
-
friday: 5,
|
|
2613
|
-
saturday: 6
|
|
2614
|
-
};
|
|
2615
|
-
return dayMap[day];
|
|
2616
|
-
}
|
|
2617
2534
|
async function loadWeeklyUsageData(options) {
|
|
2618
2535
|
const startDay = options?.startOfWeek != null ? getDayNumber(options.startOfWeek) : getDayNumber("sunday");
|
|
2619
2536
|
return loadBucketUsageData((data) => getDateWeek(new Date(data.date), startDay), options).then((usages) => usages.map(({ bucket,...rest }) => ({
|
|
@@ -2751,7 +2668,7 @@ async function loadSessionBlockData(options) {
|
|
|
2751
2668
|
}
|
|
2752
2669
|
}
|
|
2753
2670
|
const blocks = identifySessionBlocks(allEntries, options?.sessionDurationHours), dateFiltered = options?.since != null && options.since !== "" || options?.until != null && options.until !== "" ? blocks.filter((block) => {
|
|
2754
|
-
const blockDateStr = formatDate(block.startTime.toISOString(), options?.timezone,
|
|
2671
|
+
const blockDateStr = formatDate(block.startTime.toISOString(), options?.timezone, DEFAULT_LOCALE).replace(/-/g, "");
|
|
2755
2672
|
return !(options.since != null && options.since !== "" && blockDateStr < options.since || options.until != null && options.until !== "" && blockDateStr > options.until);
|
|
2756
2673
|
}) : blocks;
|
|
2757
2674
|
return sortByDate(dateFiltered, (block) => block.startTime, options?.order);
|
|
@@ -2761,4 +2678,4 @@ async function loadSessionBlockData(options) {
|
|
|
2761
2678
|
_usingCtx6.d();
|
|
2762
2679
|
}
|
|
2763
2680
|
}
|
|
2764
|
-
export { DEFAULT_SESSION_DURATION_HOURS, bucketUsageSchema, calculateBurnRate, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, filterRecentBlocks,
|
|
2681
|
+
export { DEFAULT_SESSION_DURATION_HOURS, bucketUsageSchema, calculateBurnRate, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, filterRecentBlocks, formatDateCompact, getClaudePaths, getEarliestTimestamp, getFileModifiedTime, getUsageLimitResetTime, glob, globUsageFiles, identifySessionBlocks, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, projectBlockUsage, sessionUsageSchema, sortFilesByTimestamp, toArray, transcriptMessageSchema, transcriptUsageSchema, uniq, unreachable, unwrap, usageDataSchema, weeklyUsageSchema };
|
package/dist/data-loader.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
3
|
-
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath,
|
|
1
|
+
import { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema } from "./data-loader-D1FVB4Lp.js";
|
|
2
|
+
import "./pricing-fetcher-DK8lcI1w.js";
|
|
3
|
+
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema };
|