repospend 0.1.7 → 0.1.8

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/cli.js CHANGED
@@ -12,6 +12,8 @@ function summarize(sessions) {
12
12
  const cacheCreationInputTokens = optionalSum(sessions, "cacheCreationInputTokens");
13
13
  const cacheCreationInputTokens5m = optionalSum(sessions, "cacheCreationInputTokens5m");
14
14
  const cacheCreationInputTokens1h = optionalSum(sessions, "cacheCreationInputTokens1h");
15
+ const cacheCreationInputTokens30m = optionalSum(sessions, "cacheCreationInputTokens30m");
16
+ const cacheCreationInputTokens12h = optionalSum(sessions, "cacheCreationInputTokens12h");
15
17
  return {
16
18
  estimatedCostUsd: cost.knownCount > 0 ? cost.value : void 0,
17
19
  knownCostSessions: cost.knownCount,
@@ -20,13 +22,15 @@ function summarize(sessions) {
20
22
  cacheCreationInputTokens,
21
23
  cacheCreationInputTokens5m,
22
24
  cacheCreationInputTokens1h,
25
+ cacheCreationInputTokens30m,
26
+ cacheCreationInputTokens12h,
23
27
  inputTokens,
24
28
  outputTokens: sum(sessions, "outputTokens"),
25
29
  reasoningTokens: sum(sessions, "reasoningTokens"),
26
30
  cachedInputPct: inputTokens > 0 ? cachedInputTokens / inputTokens : 0,
27
31
  sessionCount: sessions.length,
28
32
  repoCount: repos.length,
29
- modelCount: new Set(sessions.map((session) => session.model).filter(Boolean)).size,
33
+ modelCount: new Set(sessions.flatMap((session) => sessionModelSlices(session).map((slice) => slice.model)).filter(Boolean)).size,
30
34
  mostExpensiveRepo: repos.filter((repo) => repo.estimatedCostUsd !== void 0).sort((a, b) => (b.estimatedCostUsd ?? 0) - (a.estimatedCostUsd ?? 0))[0],
31
35
  unknownCostSessions: sessions.filter((session) => session.estimatedCostUsd === void 0).length,
32
36
  userPromptCount: optionalSum(sessions, "userPromptCount"),
@@ -57,12 +61,53 @@ function groupByRepo(sessions) {
57
61
  }));
58
62
  }
59
63
  function groupByModel(sessions) {
60
- const groups = groupBy(sessions, (session) => session.model ?? "unknown-model", (session) => session.model ?? "Model not recorded");
61
- const unknownModelSessions = sessions.filter((session) => !session.model);
64
+ const groups = /* @__PURE__ */ new Map();
65
+ for (const session of sessions) {
66
+ for (const slice of sessionModelSlices(session)) {
67
+ const id = slice.model ?? "unknown-model";
68
+ const group = groups.get(id) ?? emptyGroup(id, slice.model ?? "Model not recorded");
69
+ accumulateGroup(group, session, slice);
70
+ groups.set(id, group);
71
+ }
72
+ }
73
+ const grouped = sortGroups([...groups.values()]);
74
+ const unknownModelSessions = sessions.filter((session) => !session.model && !(session.modelUsage ?? []).some((entry) => entry.model));
62
75
  if (unknownModelSessions.length > 0 && unknownModelSessions.every(isClaudeSyntheticZeroUsageSession)) {
63
- return groups.map((group) => group.id === "unknown-model" ? { ...group, label: "Claude synthetic / no usage" } : group);
76
+ return grouped.map((group) => group.id === "unknown-model" ? { ...group, label: "Claude synthetic / no usage" } : group);
64
77
  }
65
- return groups;
78
+ return grouped;
79
+ }
80
+ function sessionModelSlices(session) {
81
+ if (session.modelUsage?.length) {
82
+ return session.modelUsage.map((entry) => ({
83
+ model: entry.model,
84
+ inputTokens: entry.inputTokens,
85
+ cachedInputTokens: entry.cachedInputTokens,
86
+ cacheCreationInputTokens: entry.cacheCreationInputTokens,
87
+ cacheCreationInputTokens5m: 0,
88
+ cacheCreationInputTokens1h: 0,
89
+ cacheCreationInputTokens30m: entry.cacheCreationInputTokens30m ?? 0,
90
+ cacheCreationInputTokens12h: entry.cacheCreationInputTokens12h ?? 0,
91
+ outputTokens: entry.outputTokens,
92
+ reasoningTokens: entry.reasoningTokens,
93
+ totalTokens: entry.totalTokens,
94
+ estimatedCostUsd: entry.estimatedCostUsd
95
+ }));
96
+ }
97
+ return [{
98
+ model: session.model,
99
+ inputTokens: session.inputTokens,
100
+ cachedInputTokens: session.cachedInputTokens,
101
+ cacheCreationInputTokens: session.cacheCreationInputTokens ?? 0,
102
+ cacheCreationInputTokens5m: session.cacheCreationInputTokens5m ?? 0,
103
+ cacheCreationInputTokens1h: session.cacheCreationInputTokens1h ?? 0,
104
+ cacheCreationInputTokens30m: session.cacheCreationInputTokens30m ?? 0,
105
+ cacheCreationInputTokens12h: session.cacheCreationInputTokens12h ?? 0,
106
+ outputTokens: session.outputTokens,
107
+ reasoningTokens: session.reasoningTokens,
108
+ totalTokens: session.totalTokens,
109
+ estimatedCostUsd: session.estimatedCostUsd
110
+ }];
66
111
  }
67
112
  function groupBySourceApp(sessions) {
68
113
  return groupBy(sessions, (session) => session.sourceApp, (session) => session.sourceApp);
@@ -77,45 +122,57 @@ function groupBy(sessions, keyFn, labelFn) {
77
122
  const groups = /* @__PURE__ */ new Map();
78
123
  for (const session of sessions) {
79
124
  const id = keyFn(session);
80
- const existing = groups.get(id);
81
- const group = existing ?? {
82
- id,
83
- label: labelFn(session),
84
- estimatedCostUsd: void 0,
85
- knownCostSessions: 0,
86
- unknownCostSessions: 0,
87
- inputTokens: 0,
88
- cachedInputTokens: 0,
89
- cacheCreationInputTokens: 0,
90
- cacheCreationInputTokens5m: 0,
91
- cacheCreationInputTokens1h: 0,
92
- outputTokens: 0,
93
- reasoningTokens: 0,
94
- totalTokens: 0,
95
- sessionCount: 0,
96
- messageCount: 0,
97
- warnings: []
98
- };
99
- group.inputTokens += session.inputTokens;
100
- group.cachedInputTokens += session.cachedInputTokens;
101
- group.cacheCreationInputTokens = (group.cacheCreationInputTokens ?? 0) + (session.cacheCreationInputTokens ?? 0);
102
- group.cacheCreationInputTokens5m = (group.cacheCreationInputTokens5m ?? 0) + (session.cacheCreationInputTokens5m ?? 0);
103
- group.cacheCreationInputTokens1h = (group.cacheCreationInputTokens1h ?? 0) + (session.cacheCreationInputTokens1h ?? 0);
104
- group.outputTokens += session.outputTokens;
105
- group.reasoningTokens += session.reasoningTokens;
106
- group.totalTokens += session.totalTokens;
107
- group.sessionCount += 1;
108
- group.messageCount += session.messageCount;
109
- group.warnings = unique([...group.warnings, ...session.warnings]);
110
- if (session.estimatedCostUsd !== void 0) {
111
- group.estimatedCostUsd = roundCurrency((group.estimatedCostUsd ?? 0) + session.estimatedCostUsd);
112
- group.knownCostSessions += 1;
113
- } else {
114
- group.unknownCostSessions += 1;
115
- }
125
+ const group = groups.get(id) ?? emptyGroup(id, labelFn(session));
126
+ accumulateGroup(group, session, session);
116
127
  groups.set(id, group);
117
128
  }
118
- return [...groups.values()].sort((a, b) => (b.estimatedCostUsd ?? 0) - (a.estimatedCostUsd ?? 0) || b.totalTokens - a.totalTokens);
129
+ return sortGroups([...groups.values()]);
130
+ }
131
+ function emptyGroup(id, label) {
132
+ return {
133
+ id,
134
+ label,
135
+ estimatedCostUsd: void 0,
136
+ knownCostSessions: 0,
137
+ unknownCostSessions: 0,
138
+ inputTokens: 0,
139
+ cachedInputTokens: 0,
140
+ cacheCreationInputTokens: 0,
141
+ cacheCreationInputTokens5m: 0,
142
+ cacheCreationInputTokens1h: 0,
143
+ cacheCreationInputTokens30m: 0,
144
+ cacheCreationInputTokens12h: 0,
145
+ outputTokens: 0,
146
+ reasoningTokens: 0,
147
+ totalTokens: 0,
148
+ sessionCount: 0,
149
+ messageCount: 0,
150
+ warnings: []
151
+ };
152
+ }
153
+ function accumulateGroup(group, session, slice) {
154
+ group.inputTokens += slice.inputTokens;
155
+ group.cachedInputTokens += slice.cachedInputTokens;
156
+ group.cacheCreationInputTokens = (group.cacheCreationInputTokens ?? 0) + (slice.cacheCreationInputTokens ?? 0);
157
+ group.cacheCreationInputTokens5m = (group.cacheCreationInputTokens5m ?? 0) + (slice.cacheCreationInputTokens5m ?? 0);
158
+ group.cacheCreationInputTokens1h = (group.cacheCreationInputTokens1h ?? 0) + (slice.cacheCreationInputTokens1h ?? 0);
159
+ group.cacheCreationInputTokens30m = (group.cacheCreationInputTokens30m ?? 0) + (slice.cacheCreationInputTokens30m ?? 0);
160
+ group.cacheCreationInputTokens12h = (group.cacheCreationInputTokens12h ?? 0) + (slice.cacheCreationInputTokens12h ?? 0);
161
+ group.outputTokens += slice.outputTokens;
162
+ group.reasoningTokens += slice.reasoningTokens;
163
+ group.totalTokens += slice.totalTokens;
164
+ group.sessionCount += 1;
165
+ group.messageCount += session.messageCount;
166
+ group.warnings = unique([...group.warnings, ...session.warnings]);
167
+ if (slice.estimatedCostUsd !== void 0) {
168
+ group.estimatedCostUsd = roundCurrency((group.estimatedCostUsd ?? 0) + slice.estimatedCostUsd);
169
+ group.knownCostSessions += 1;
170
+ } else {
171
+ group.unknownCostSessions += 1;
172
+ }
173
+ }
174
+ function sortGroups(groups) {
175
+ return groups.sort((a, b) => (b.estimatedCostUsd ?? 0) - (a.estimatedCostUsd ?? 0) || b.totalTokens - a.totalTokens);
119
176
  }
120
177
  function isClaudeSyntheticZeroUsageSession(session) {
121
178
  return session.warnings.includes("claude_synthetic_zero_usage");
@@ -142,6 +199,8 @@ function toCsv(sessions) {
142
199
  "cacheCreationInputTokens",
143
200
  "cacheCreationInputTokens5m",
144
201
  "cacheCreationInputTokens1h",
202
+ "cacheCreationInputTokens30m",
203
+ "cacheCreationInputTokens12h",
145
204
  "outputTokens",
146
205
  "reasoningTokens",
147
206
  "reasoningOutputTokens",
@@ -360,6 +419,8 @@ var pricingInfo = {
360
419
  { label: "OpenAI pricing reference", url: "https://developers.openai.com/api/docs/pricing" },
361
420
  { label: "OpenAI GPT-6 model reference", url: "https://developers.openai.com/api/docs/models" },
362
421
  { label: "OpenAI GPT-6.1 Sol reference", url: "https://developers.openai.com/api/docs/models/gpt-6.1-sol" },
422
+ { label: "OpenAI GPT-6.1 Terra reference", url: "https://developers.openai.com/api/docs/models/gpt-6.1-terra" },
423
+ { label: "OpenAI prompt caching guide", url: "https://developers.openai.com/api/docs/guides/prompt-caching" },
363
424
  { label: "OpenAI GPT-5.6 preview pricing", url: "https://openai.com/index/previewing-gpt-5-6-sol/" },
364
425
  { label: "OpenAI GPT-5.6 price update", url: "https://openai.com/index/advancing-the-price-performance-frontier-with-gpt-5-6/" },
365
426
  { label: "Claude pricing reference", url: "https://platform.claude.com/docs/en/about-claude/pricing" },
@@ -368,24 +429,37 @@ var pricingInfo = {
368
429
  { label: "GitHub Copilot model pricing reference", url: "https://docs.github.com/en/copilot/reference/copilot-billing/models-and-pricing" }
369
430
  ],
370
431
  unit: "USD per 1M tokens",
371
- updatedAt: "2026-10-17",
372
- note: "RepoSpend estimates API-equivalent cost from local token counts and public Standard pricing. GPT-6 defaults use short-context rates. Claude transcript fast-mode speeds use explicit published cards. Long-context, other processing modes, regional, and account-specific pricing can differ. This is not your actual bill."
432
+ updatedAt: "2026-10-27",
433
+ note: "RepoSpend estimates API-equivalent cost from local token counts and public Standard pricing. Requests over each model's long-context threshold reprice per request when request sizes are recorded; aggregate-only usage assumes short-context rates and is flagged. Claude transcript fast-mode speeds use explicit published cards. Other processing modes, regional, and account-specific pricing can differ. This is not your actual bill."
373
434
  };
374
435
  var defaultPricing = {
375
- "gpt-6-astra": { inputPerMillion: 10, cachedInputPerMillion: 1, cacheCreationInputPerMillion: 12.5, outputPerMillion: 50, reasoningOutputPerMillion: 50 },
376
- "gpt-6-sol": { inputPerMillion: 2, cachedInputPerMillion: 0.2, cacheCreationInputPerMillion: 2.5, outputPerMillion: 10, reasoningOutputPerMillion: 10 },
377
- "gpt-6.1-sol": { inputPerMillion: 2, cachedInputPerMillion: 0.1, cacheCreationInputPerMillion: 2.5, outputPerMillion: 10, reasoningOutputPerMillion: 10 },
378
- "gpt-6-luna": { inputPerMillion: 0.1, cachedInputPerMillion: 0.01, cacheCreationInputPerMillion: 0.125, outputPerMillion: 0.5, reasoningOutputPerMillion: 0.5 },
379
- "gpt-5.6": { inputPerMillion: 4, cachedInputPerMillion: 0.4, cacheCreationInputPerMillion: 5, outputPerMillion: 20, reasoningOutputPerMillion: 20, note: "GPT-5.6 aliases Sol. Promotional Standard short-context rates are available at least through November 21, 2026: $4 input / $20 output, $0.40 cache reads, and $5 cache writes per 1M tokens." },
380
- "gpt-5.6-sol": { inputPerMillion: 4, cachedInputPerMillion: 0.4, cacheCreationInputPerMillion: 5, outputPerMillion: 20, reasoningOutputPerMillion: 20, note: "Promotional Standard short-context rates available at least through November 21, 2026." },
381
- "gpt-5.6-terra": { inputPerMillion: 2, cachedInputPerMillion: 0.2, cacheCreationInputPerMillion: 2.5, outputPerMillion: 12, reasoningOutputPerMillion: 12, note: "GPT-5.6 Terra reduced API pricing effective July 30, 2026. Cache reads are 90% below input and cache writes are 1.25x input." },
382
- "gpt-5.6-luna": { inputPerMillion: 0.2, cachedInputPerMillion: 0.02, cacheCreationInputPerMillion: 0.25, outputPerMillion: 1.2, reasoningOutputPerMillion: 1.2, note: "GPT-5.6 Luna reduced API pricing effective July 30, 2026. Cache reads are 90% below input and cache writes are 1.25x input." },
436
+ "gpt-6-astra": { inputPerMillion: 10, cachedInputPerMillion: 1, cacheCreationInputPerMillion: 12.5, cacheCreationInput30mPerMillion: 12.5, cacheCreationInput12hPerMillion: 25, outputPerMillion: 50, reasoningOutputPerMillion: 50 },
437
+ "gpt-6-astra-long-context": { inputPerMillion: 20, cachedInputPerMillion: 2, cacheCreationInputPerMillion: 25, cacheCreationInput30mPerMillion: 25, cacheCreationInput12hPerMillion: 50, outputPerMillion: 75, reasoningOutputPerMillion: 75, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole request when a single API call exceeds 272K input tokens: input and cache rates 2x, output 1.5x." },
438
+ "gpt-6-sol": { inputPerMillion: 2, cachedInputPerMillion: 0.2, cacheCreationInputPerMillion: 2.5, cacheCreationInput30mPerMillion: 2.5, cacheCreationInput12hPerMillion: 5, outputPerMillion: 10, reasoningOutputPerMillion: 10 },
439
+ "gpt-6-sol-long-context": { inputPerMillion: 4, cachedInputPerMillion: 0.4, cacheCreationInputPerMillion: 5, cacheCreationInput30mPerMillion: 5, cacheCreationInput12hPerMillion: 10, outputPerMillion: 15, reasoningOutputPerMillion: 15, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole request when a single API call exceeds 272K input tokens: input and cache rates 2x, output 1.5x." },
440
+ "gpt-6-luna": { inputPerMillion: 0.1, cachedInputPerMillion: 0.01, cacheCreationInputPerMillion: 0.125, cacheCreationInput30mPerMillion: 0.125, cacheCreationInput12hPerMillion: 0.25, outputPerMillion: 0.5, reasoningOutputPerMillion: 0.5 },
441
+ "gpt-6-luna-long-context": { inputPerMillion: 0.2, cachedInputPerMillion: 0.02, cacheCreationInputPerMillion: 0.25, cacheCreationInput30mPerMillion: 0.25, cacheCreationInput12hPerMillion: 0.5, outputPerMillion: 0.75, reasoningOutputPerMillion: 0.75, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole request when a single API call exceeds 272K input tokens: input and cache rates 2x, output 1.5x." },
442
+ "gpt-6.1-sol": { inputPerMillion: 2, cachedInputPerMillion: 0.1, cacheCreationInputPerMillion: 2.5, cacheCreationInput30mPerMillion: 2.5, cacheCreationInput12hPerMillion: 5, outputPerMillion: 10, reasoningOutputPerMillion: 10 },
443
+ "gpt-6.1-sol-long-context": { inputPerMillion: 4, cachedInputPerMillion: 0.2, cacheCreationInputPerMillion: 5, cacheCreationInput30mPerMillion: 5, cacheCreationInput12hPerMillion: 10, outputPerMillion: 15, reasoningOutputPerMillion: 15, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole request when a single API call exceeds 272K input tokens: input and cache rates 2x, output 1.5x." },
444
+ "gpt-6.1-terra": { inputPerMillion: 1, cachedInputPerMillion: 0.05, cacheCreationInputPerMillion: 1.25, cacheCreationInput30mPerMillion: 1.25, cacheCreationInput12hPerMillion: 2.5, outputPerMillion: 5, reasoningOutputPerMillion: 5, note: "GPT-6.1 Terra Standard short-context rates, released October 26, 2026. Cache writes are 1.25x input for 30-minute TTL and 2.5x for 12-hour TTL." },
445
+ "gpt-6.1-terra-long-context": { inputPerMillion: 2, cachedInputPerMillion: 0.1, cacheCreationInputPerMillion: 2.5, cacheCreationInput30mPerMillion: 2.5, cacheCreationInput12hPerMillion: 5, outputPerMillion: 7.5, reasoningOutputPerMillion: 7.5, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole request when a single API call exceeds 272K input tokens: input and cache rates 2x, output 1.5x." },
446
+ "gpt-5.6": { inputPerMillion: 4, cachedInputPerMillion: 0.4, cacheCreationInputPerMillion: 5, cacheCreationInput30mPerMillion: 5, cacheCreationInput12hPerMillion: 10, outputPerMillion: 20, reasoningOutputPerMillion: 20, note: "GPT-5.6 aliases Sol. Promotional Standard short-context rates are available at least through November 21, 2026: $4 input / $20 output, $0.40 cache reads, and $5 cache writes per 1M tokens." },
447
+ "gpt-5.6-sol": { inputPerMillion: 4, cachedInputPerMillion: 0.4, cacheCreationInputPerMillion: 5, cacheCreationInput30mPerMillion: 5, cacheCreationInput12hPerMillion: 10, outputPerMillion: 20, reasoningOutputPerMillion: 20, note: "Promotional Standard short-context rates available at least through November 21, 2026." },
448
+ "gpt-5.6-terra": { inputPerMillion: 2, cachedInputPerMillion: 0.2, cacheCreationInputPerMillion: 2.5, cacheCreationInput30mPerMillion: 2.5, cacheCreationInput12hPerMillion: 5, outputPerMillion: 12, reasoningOutputPerMillion: 12, note: "GPT-5.6 Terra reduced API pricing effective July 30, 2026. Cache reads are 90% below input and cache writes are 1.25x input." },
449
+ "gpt-5.6-luna": { inputPerMillion: 0.2, cachedInputPerMillion: 0.02, cacheCreationInputPerMillion: 0.25, cacheCreationInput30mPerMillion: 0.25, cacheCreationInput12hPerMillion: 0.5, outputPerMillion: 1.2, reasoningOutputPerMillion: 1.2, note: "GPT-5.6 Luna reduced API pricing effective July 30, 2026. Cache reads are 90% below input and cache writes are 1.25x input." },
383
450
  "gpt-5.5": { inputPerMillion: 5, cachedInputPerMillion: 0.5, outputPerMillion: 30, reasoningOutputPerMillion: 30 },
384
451
  "gpt-5.5-pro": { inputPerMillion: 30, outputPerMillion: 180, reasoningOutputPerMillion: 180 },
385
452
  "gpt-5.4": { inputPerMillion: 2.5, cachedInputPerMillion: 0.25, outputPerMillion: 15, reasoningOutputPerMillion: 15 },
386
453
  "gpt-5.4-mini": { inputPerMillion: 0.75, cachedInputPerMillion: 0.075, outputPerMillion: 4.5, reasoningOutputPerMillion: 4.5 },
387
454
  "gpt-5.4-nano": { inputPerMillion: 0.2, cachedInputPerMillion: 0.02, outputPerMillion: 1.25, reasoningOutputPerMillion: 1.25 },
388
455
  "gpt-5.4-pro": { inputPerMillion: 30, outputPerMillion: 180, reasoningOutputPerMillion: 180 },
456
+ "gpt-5.6-sol-long-context": { inputPerMillion: 8, cachedInputPerMillion: 0.8, cacheCreationInputPerMillion: 10, cacheCreationInput30mPerMillion: 10, cacheCreationInput12hPerMillion: 20, outputPerMillion: 30, reasoningOutputPerMillion: 30, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole GPT-5.6 request when a single API call exceeds 272K input tokens: input and cache rates 2x, output 1.5x." },
457
+ "gpt-5.6-terra-long-context": { inputPerMillion: 4, cachedInputPerMillion: 0.4, cacheCreationInputPerMillion: 5, cacheCreationInput30mPerMillion: 5, cacheCreationInput12hPerMillion: 10, outputPerMillion: 18, reasoningOutputPerMillion: 18, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole GPT-5.6 Terra request when a single API call exceeds 272K input tokens: input and cache rates 2x, output 1.5x." },
458
+ "gpt-5.6-luna-long-context": { inputPerMillion: 0.4, cachedInputPerMillion: 0.04, cacheCreationInputPerMillion: 0.5, cacheCreationInput30mPerMillion: 0.5, cacheCreationInput12hPerMillion: 1, outputPerMillion: 1.8, reasoningOutputPerMillion: 1.8, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole GPT-5.6 Luna request when a single API call exceeds 272K input tokens: input and cache rates 2x, output 1.5x." },
459
+ "gpt-5.5-long-context": { inputPerMillion: 10, cachedInputPerMillion: 1, outputPerMillion: 45, reasoningOutputPerMillion: 45, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole GPT-5.5 request when a single API call exceeds 272K input tokens. No published cache-write rates." },
460
+ "gpt-5.5-pro-long-context": { inputPerMillion: 60, outputPerMillion: 270, reasoningOutputPerMillion: 270, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole GPT-5.5 Pro request when a single API call exceeds 272K input tokens. No published cache rates." },
461
+ "gpt-5.4-long-context": { inputPerMillion: 5, cachedInputPerMillion: 0.5, outputPerMillion: 22.5, reasoningOutputPerMillion: 22.5, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole GPT-5.4 request when a single API call exceeds 272K input tokens. No published cache-write rates." },
462
+ "gpt-5.4-pro-long-context": { inputPerMillion: 60, outputPerMillion: 270, reasoningOutputPerMillion: 270, note: "RepoSpend pricing card, not a provider model ID. Applied to the whole GPT-5.4 Pro request when a single API call exceeds 272K input tokens. No published cache rates." },
389
463
  "gpt-5.3-codex": { inputPerMillion: 1.75, cachedInputPerMillion: 0.175, outputPerMillion: 14, reasoningOutputPerMillion: 14 },
390
464
  "gpt-5.3-codex-spark": { inputPerMillion: 1.75, cachedInputPerMillion: 0.175, outputPerMillion: 14, reasoningOutputPerMillion: 14, note: "Research preview pricing is not final in the OpenAI Codex rate card; this API-equivalent rate matches the practical ccusage/LiteLLM-style estimate." },
391
465
  "gpt-5.2": { inputPerMillion: 1.75, cachedInputPerMillion: 0.175, outputPerMillion: 14, reasoningOutputPerMillion: 14 },
@@ -563,41 +637,87 @@ function calculateCostUsd(usage, pricing, requestInputTokens) {
563
637
  function calculateRequestCosts(requests, pricing) {
564
638
  const resolutions = /* @__PURE__ */ new Map();
565
639
  const warnings = /* @__PURE__ */ new Set();
640
+ const assumptions = /* @__PURE__ */ new Set();
566
641
  let total = 0;
567
- for (const request of requests) {
642
+ const requestCosts = requests.map((request) => {
568
643
  let resolution = request.model ? resolutions.get(request.model) : void 0;
569
644
  if (request.model && !resolution) {
570
645
  resolution = resolvePricingForModel(request.model, pricing);
571
646
  resolutions.set(request.model, resolution);
572
647
  }
573
- const cost = unroundedCostUsd(request, pricing, request.requestInputTokens, resolution);
648
+ const context = requestContextPricing(request, pricing, resolution);
649
+ if (context.assumption) assumptions.add(context.assumption);
650
+ const cost = context.pricing === void 0 ? void 0 : costFromModelPricing(request, context.pricing);
574
651
  if (cost !== void 0) total += cost;
575
652
  else if (request.model && resolution) {
576
- const missingContext = needsHaikuContext(request.model, resolution) && (request.requestInputTokens === void 0 || !Number.isFinite(request.requestInputTokens) || request.requestInputTokens < 0);
577
- warnings.add(missingContext ? "unknown_request_context" : `unknown_pricing_model:${normalizePricingModelId(request.model)}`);
653
+ warnings.add(context.unknownContext ? "unknown_request_context" : `unknown_pricing_model:${normalizePricingModelId(request.model)}`);
578
654
  } else warnings.add("unknown_pricing");
579
- }
580
- return { costUsd: requests.length && !warnings.size ? Number((total + Number.EPSILON).toFixed(6)) : void 0, warnings: [...warnings] };
581
- }
582
- function needsHaikuContext(model, resolution) {
583
- return resolution.sourceModel === "claude-haiku-5-5" || resolution.inherited && /^claude-haiku-5-5(?:$|[-.@[])/.test(normalizePricingModelId(model));
655
+ return cost;
656
+ });
657
+ return {
658
+ costUsd: requests.length && !warnings.size ? Number((total + Number.EPSILON).toFixed(6)) : void 0,
659
+ requestCosts,
660
+ warnings: [...warnings],
661
+ assumptions: [...assumptions]
662
+ };
584
663
  }
585
- function unroundedCostUsd(usage, pricing, requestInputTokens, cachedResolution) {
664
+ var REQUEST_CONTEXT_RULES = [
665
+ { baseModel: "claude-haiku-5-5", thresholdInputTokens: 1e5, longContextModel: "claude-haiku-5-5-long-context", unknownRequestSize: "unpriced", missingLongContextCard: "unpriced", inheritedModelPattern: /^claude-haiku-5-5(?:$|[-.@[])/ },
666
+ { baseModel: "gpt-6-astra", thresholdInputTokens: 272e3, longContextModel: "gpt-6-astra-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
667
+ { baseModel: "gpt-6-sol", thresholdInputTokens: 272e3, longContextModel: "gpt-6-sol-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
668
+ { baseModel: "gpt-6-luna", thresholdInputTokens: 272e3, longContextModel: "gpt-6-luna-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
669
+ { baseModel: "gpt-6.1-sol", thresholdInputTokens: 272e3, longContextModel: "gpt-6.1-sol-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
670
+ { baseModel: "gpt-6.1-terra", thresholdInputTokens: 272e3, longContextModel: "gpt-6.1-terra-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
671
+ // GPT-5.x Standard cards carry the same >272K tiers; mini/nano have no published tier.
672
+ { baseModel: "gpt-5.6", thresholdInputTokens: 272e3, longContextModel: "gpt-5.6-sol-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
673
+ { baseModel: "gpt-5.6-sol", thresholdInputTokens: 272e3, longContextModel: "gpt-5.6-sol-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
674
+ { baseModel: "gpt-5.6-terra", thresholdInputTokens: 272e3, longContextModel: "gpt-5.6-terra-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
675
+ { baseModel: "gpt-5.6-luna", thresholdInputTokens: 272e3, longContextModel: "gpt-5.6-luna-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
676
+ { baseModel: "gpt-5.5", thresholdInputTokens: 272e3, longContextModel: "gpt-5.5-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
677
+ { baseModel: "gpt-5.5-pro", thresholdInputTokens: 272e3, longContextModel: "gpt-5.5-pro-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
678
+ { baseModel: "gpt-5.4", thresholdInputTokens: 272e3, longContextModel: "gpt-5.4-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true },
679
+ { baseModel: "gpt-5.4-pro", thresholdInputTokens: 272e3, longContextModel: "gpt-5.4-pro-long-context", unknownRequestSize: "short-context", missingLongContextCard: "base", canonicalFlatOverride: true }
680
+ ];
681
+ function pricingContextRules() {
682
+ return REQUEST_CONTEXT_RULES.map(({ baseModel, longContextModel, thresholdInputTokens }) => ({ baseModel, longContextModel, thresholdInputTokens }));
683
+ }
684
+ function requestContextPricing(request, pricing, resolution) {
685
+ if (!request.model || !resolution) return { pricing: void 0, unknownContext: false };
686
+ const normalizedModel = normalizePricingModelId(request.model);
687
+ const rule = REQUEST_CONTEXT_RULES.find((candidate) => candidate.baseModel === resolution.sourceModel || resolution.inherited && candidate.inheritedModelPattern?.test(normalizedModel));
688
+ if (!rule) return { pricing: resolution.pricing, unknownContext: false };
689
+ const baseRow = pricing[rule.baseModel];
690
+ const basePricing = resolution.sourceModel === rule.baseModel ? resolution.pricing : isUsableModelPricing(baseRow) ? baseRow : void 0;
691
+ const requestInputTokens = request.requestInputTokens;
692
+ if (requestInputTokens === void 0 || !Number.isFinite(requestInputTokens) || requestInputTokens < 0) {
693
+ return rule.unknownRequestSize === "unpriced" ? { pricing: void 0, unknownContext: true } : { pricing: basePricing, unknownContext: false, assumption: `assumed_short_context_rates:${rule.baseModel}` };
694
+ }
695
+ if (requestInputTokens <= rule.thresholdInputTokens) return { pricing: basePricing, unknownContext: false };
696
+ const bundledBase = defaultPricing[rule.baseModel];
697
+ if (rule.canonicalFlatOverride && resolution.sourceModel === rule.baseModel && bundledBase && basePricing && !pricingEntriesEqual(basePricing, bundledBase) && pricingEntriesEqual(pricing[rule.longContextModel], defaultPricing[rule.longContextModel])) {
698
+ return { pricing: basePricing, unknownContext: false };
699
+ }
700
+ const longContext = resolvePricingForModel(rule.longContextModel, pricing);
701
+ if (isUsableModelPricing(longContext.pricing)) return { pricing: longContext.pricing, unknownContext: false };
702
+ return rule.missingLongContextCard === "unpriced" ? { pricing: void 0, unknownContext: false } : { pricing: basePricing, unknownContext: false, assumption: `missing_long_context_pricing:${rule.baseModel}` };
703
+ }
704
+ function unroundedCostUsd(usage, pricing, requestInputTokens) {
586
705
  if (!usage.model) {
587
706
  return void 0;
588
707
  }
589
- const resolution = cachedResolution ?? resolvePricingForModel(usage.model, pricing);
590
- let modelPricing = resolution.pricing;
591
- if (needsHaikuContext(usage.model, resolution)) {
592
- if (requestInputTokens === void 0 || !Number.isFinite(requestInputTokens) || requestInputTokens < 0) return void 0;
593
- modelPricing = pricing[requestInputTokens > 1e5 ? "claude-haiku-5-5-long-context" : "claude-haiku-5-5"];
594
- }
595
- if (!isUsableModelPricing(modelPricing)) {
708
+ const resolution = resolvePricingForModel(usage.model, pricing);
709
+ const modelPricing = requestContextPricing({ ...usage, requestInputTokens }, pricing, resolution).pricing;
710
+ return costFromModelPricing(usage, modelPricing);
711
+ }
712
+ function costFromModelPricing(usage, modelPricing) {
713
+ if (!usage.model || !isUsableModelPricing(modelPricing)) {
596
714
  return void 0;
597
715
  }
598
716
  const cacheCreationInput5m = usage.cacheCreationInputTokens5m ?? 0;
599
717
  const cacheCreationInput1h = usage.cacheCreationInputTokens1h ?? 0;
600
- const splitCacheCreationInput = cacheCreationInput5m + cacheCreationInput1h;
718
+ const cacheCreationInput30m = usage.cacheCreationInputTokens30m ?? 0;
719
+ const cacheCreationInput12h = usage.cacheCreationInputTokens12h ?? 0;
720
+ const splitCacheCreationInput = cacheCreationInput5m + cacheCreationInput1h + cacheCreationInput30m + cacheCreationInput12h;
601
721
  const cacheCreationInput = usage.cacheCreationInputTokens ?? splitCacheCreationInput;
602
722
  const unclassifiedCacheCreationInput = Math.max(cacheCreationInput - splitCacheCreationInput, 0);
603
723
  const billableInput = Math.max(usage.inputTokens - usage.cachedInputTokens - cacheCreationInput, 0);
@@ -605,8 +725,10 @@ function unroundedCostUsd(usage, pricing, requestInputTokens, cachedResolution)
605
725
  const cacheCreationRate = firstPositiveRate(modelPricing.cacheCreationInputPerMillion, modelPricing.cacheCreationInput1hPerMillion, modelPricing.cacheCreationInput5mPerMillion, modelPricing.inputPerMillion);
606
726
  const cacheCreation5mRate = firstPositiveRate(modelPricing.cacheCreationInput5mPerMillion, modelPricing.cacheCreationInputPerMillion, modelPricing.inputPerMillion);
607
727
  const cacheCreation1hRate = firstPositiveRate(modelPricing.cacheCreationInput1hPerMillion, modelPricing.cacheCreationInputPerMillion, modelPricing.inputPerMillion);
728
+ const cacheCreation30mRate = firstPositiveRate(modelPricing.cacheCreationInput30mPerMillion, modelPricing.cacheCreationInputPerMillion, modelPricing.inputPerMillion);
729
+ const cacheCreation12hRate = firstPositiveRate(modelPricing.cacheCreationInput12hPerMillion, modelPricing.cacheCreationInputPerMillion, modelPricing.inputPerMillion);
608
730
  const reasoningRate = modelPricing.reasoningOutputPerMillion ?? modelPricing.outputPerMillion;
609
- const cost = billableInput / 1e6 * modelPricing.inputPerMillion + usage.cachedInputTokens / 1e6 * cachedRate + cacheCreationInput5m / 1e6 * cacheCreation5mRate + cacheCreationInput1h / 1e6 * cacheCreation1hRate + unclassifiedCacheCreationInput / 1e6 * cacheCreationRate + usage.outputTokens / 1e6 * modelPricing.outputPerMillion + usage.reasoningTokens / 1e6 * reasoningRate;
731
+ const cost = billableInput / 1e6 * modelPricing.inputPerMillion + usage.cachedInputTokens / 1e6 * cachedRate + cacheCreationInput5m / 1e6 * cacheCreation5mRate + cacheCreationInput1h / 1e6 * cacheCreation1hRate + cacheCreationInput30m / 1e6 * cacheCreation30mRate + cacheCreationInput12h / 1e6 * cacheCreation12hRate + unclassifiedCacheCreationInput / 1e6 * cacheCreationRate + usage.outputTokens / 1e6 * modelPricing.outputPerMillion + usage.reasoningTokens / 1e6 * reasoningRate;
610
732
  return cost;
611
733
  }
612
734
  function firstPositiveRate(...rates) {
@@ -614,7 +736,7 @@ function firstPositiveRate(...rates) {
614
736
  }
615
737
 
616
738
  // packages/core/src/cache.ts
617
- var activeCacheVersion = "parse-v1";
739
+ var activeCacheVersion = "parse-v2";
618
740
  var preparedCacheRoot;
619
741
  function parseCacheRoot() {
620
742
  return path2.join(repospendHome(), "cache", activeCacheVersion);
@@ -878,7 +1000,7 @@ function filterUsage(sessions, filters) {
878
1000
  if (!matchesAny(session.sourceClient, filters.source)) return false;
879
1001
  if (!matchesAny(session.sourceApp, filters.sourceApp)) return false;
880
1002
  if (!matchesRepo(session, filters.repo)) return false;
881
- if (!matchesModel(session.model, filters.model)) return false;
1003
+ if (!matchesModel(session, filters.model)) return false;
882
1004
  const startedAt = timestamp(session.startedAt);
883
1005
  const hasDateFilter = Boolean(filters.from || filters.to);
884
1006
  if (hasDateFilter && startedAt === void 0) return false;
@@ -887,7 +1009,38 @@ function filterUsage(sessions, filters) {
887
1009
  if (from !== void 0 && startedAt !== void 0 && startedAt < from) return false;
888
1010
  if (to !== void 0 && startedAt !== void 0 && startedAt > to) return false;
889
1011
  return true;
890
- });
1012
+ }).map((session) => projectModelFilter(session, filters.model));
1013
+ }
1014
+ function projectModelFilter(session, filter) {
1015
+ const values = filterValues(filter);
1016
+ if (!values.length || !session.modelUsage?.length) return session;
1017
+ const slices = session.modelUsage.filter((entry) => modelValueMatches(entry.model, values));
1018
+ const reasoningTokens = sumSlices(slices, "reasoningTokens");
1019
+ return {
1020
+ ...session,
1021
+ // The representative model must belong to the selected usage: keep the original
1022
+ // model when it is selected, otherwise use the first matching slice's model.
1023
+ model: session.model !== void 0 && slices.some((entry) => entry.model === session.model) ? session.model : slices[0]?.model,
1024
+ modelUsage: slices,
1025
+ inputTokens: sumSlices(slices, "inputTokens"),
1026
+ cachedInputTokens: sumSlices(slices, "cachedInputTokens"),
1027
+ cacheCreationInputTokens: sumSlices(slices, "cacheCreationInputTokens"),
1028
+ cacheCreationInputTokens5m: sumSlices(slices, "cacheCreationInputTokens5m"),
1029
+ cacheCreationInputTokens1h: sumSlices(slices, "cacheCreationInputTokens1h"),
1030
+ cacheCreationInputTokens30m: sumSlices(slices, "cacheCreationInputTokens30m"),
1031
+ cacheCreationInputTokens12h: sumSlices(slices, "cacheCreationInputTokens12h"),
1032
+ outputTokens: sumSlices(slices, "outputTokens"),
1033
+ reasoningTokens,
1034
+ reasoningOutputTokens: reasoningTokens,
1035
+ totalTokens: sumSlices(slices, "totalTokens"),
1036
+ estimatedCostUsd: slices.every((entry) => entry.estimatedCostUsd !== void 0) ? slices.reduce((total, entry) => total + (entry.estimatedCostUsd ?? 0), 0) : void 0
1037
+ };
1038
+ }
1039
+ function modelValueMatches(model, values) {
1040
+ return values.includes(model ?? "unknown-model");
1041
+ }
1042
+ function sumSlices(slices, key) {
1043
+ return slices.reduce((total, entry) => total + (entry[key] ?? 0), 0);
891
1044
  }
892
1045
  function matchesAny(value, filter) {
893
1046
  const values = filterValues(filter);
@@ -899,10 +1052,11 @@ function matchesRepo(session, filter) {
899
1052
  if (!values.length) return true;
900
1053
  return values.includes(session.repoName) || values.includes(session.repoRoot);
901
1054
  }
902
- function matchesModel(value, filter) {
1055
+ function matchesModel(session, filter) {
903
1056
  const values = filterValues(filter);
904
1057
  if (!values.length) return true;
905
- return value !== void 0 ? values.includes(value) : values.includes("unknown-model");
1058
+ const models = session.modelUsage?.length ? session.modelUsage.map((entry) => entry.model) : [session.model];
1059
+ return models.some((model) => model !== void 0 ? values.includes(model) : values.includes("unknown-model"));
906
1060
  }
907
1061
  function filterValues(filter) {
908
1062
  if (!filter) return [];
@@ -1899,28 +2053,35 @@ function dateValue(value) {
1899
2053
  }
1900
2054
 
1901
2055
  // packages/core/src/sources/codex-token.ts
1902
- function aggregateTokens(records) {
2056
+ function aggregateTokens(records, modelForRecord) {
1903
2057
  const accumulator = emptyTokenAccumulator();
1904
2058
  for (const record of records) {
1905
- collectRecordTokens(accumulator, record);
2059
+ collectRecordTokens(accumulator, record, modelForRecord?.(record));
1906
2060
  }
1907
2061
  finalizeTokenAccumulator(accumulator);
1908
2062
  return {
1909
2063
  inputTokens: accumulator.inputTokens,
1910
2064
  cachedInputTokens: accumulator.cachedInputTokens,
2065
+ cacheCreationInputTokens: accumulator.cacheCreationInputTokens || void 0,
2066
+ cacheCreationInputTokens30m: accumulator.cacheCreationInputTokens30m || void 0,
2067
+ cacheCreationInputTokens12h: accumulator.cacheCreationInputTokens12h || void 0,
1911
2068
  outputTokens: accumulator.outputTokens,
1912
2069
  reasoningTokens: accumulator.reasoningTokens,
1913
2070
  totalTokens: accumulator.totalTokens,
1914
2071
  tokenAggregationMethod: accumulator.tokenAggregationMethod,
1915
2072
  tokenConfidence: accumulator.tokenConfidence,
1916
2073
  tokenSnapshotCount: accumulator.tokenSnapshotCount,
1917
- warnings: accumulator.warnings
2074
+ warnings: accumulator.warnings,
2075
+ requestUsages: accumulator.requestUsages
1918
2076
  };
1919
2077
  }
1920
2078
  function emptyTokenAccumulator() {
1921
2079
  return {
1922
2080
  inputTokens: 0,
1923
2081
  cachedInputTokens: 0,
2082
+ cacheCreationInputTokens: 0,
2083
+ cacheCreationInputTokens30m: 0,
2084
+ cacheCreationInputTokens12h: 0,
1924
2085
  outputTokens: 0,
1925
2086
  reasoningTokens: 0,
1926
2087
  totalTokens: 0,
@@ -1929,12 +2090,14 @@ function emptyTokenAccumulator() {
1929
2090
  tokenSnapshotCount: 0,
1930
2091
  warnings: [],
1931
2092
  cumulativeTokenSnapshots: [],
1932
- directTokenUsages: []
2093
+ directTokenUsages: [],
2094
+ requestUsages: []
1933
2095
  };
1934
2096
  }
1935
- function collectRecordTokens(accumulator, record) {
2097
+ function collectRecordTokens(accumulator, record, model) {
1936
2098
  const usage = extractRecordTokens(record);
1937
2099
  if (!usage) return;
2100
+ usage.model = model;
1938
2101
  accumulator.tokenSnapshotCount += 1;
1939
2102
  if (usage.cumulative) {
1940
2103
  accumulator.cumulativeTokenSnapshots.push(usage);
@@ -1951,6 +2114,7 @@ function finalizeTokenAccumulator(accumulator) {
1951
2114
  applyFinalUsage(accumulator, finalSnapshot);
1952
2115
  accumulator.tokenAggregationMethod = "final_snapshot";
1953
2116
  accumulator.tokenConfidence = "high";
2117
+ accumulator.requestUsages = [{ ...requestUsageFrom(finalSnapshot, void 0), model: void 0 }];
1954
2118
  if (accumulator.directTokenUsages.length > 0) accumulator.warnings.push("token_direct_usage_ignored_after_cumulative_snapshot");
1955
2119
  return;
1956
2120
  }
@@ -1961,15 +2125,19 @@ function finalizeTokenAccumulator(accumulator) {
1961
2125
  (sum2, usage) => ({
1962
2126
  inputTokens: sum2.inputTokens + usage.inputTokens,
1963
2127
  cachedInputTokens: sum2.cachedInputTokens + usage.cachedInputTokens,
2128
+ cacheCreationInputTokens: sum2.cacheCreationInputTokens + usage.cacheCreationInputTokens,
2129
+ cacheCreationInputTokens30m: sum2.cacheCreationInputTokens30m + usage.cacheCreationInputTokens30m,
2130
+ cacheCreationInputTokens12h: sum2.cacheCreationInputTokens12h + usage.cacheCreationInputTokens12h,
1964
2131
  outputTokens: sum2.outputTokens + usage.outputTokens,
1965
2132
  reasoningTokens: sum2.reasoningTokens + usage.reasoningTokens,
1966
2133
  totalTokens: sum2.totalTokens + usage.totalTokens
1967
2134
  }),
1968
- { inputTokens: 0, cachedInputTokens: 0, outputTokens: 0, reasoningTokens: 0, totalTokens: 0 }
2135
+ { inputTokens: 0, cachedInputTokens: 0, cacheCreationInputTokens: 0, cacheCreationInputTokens30m: 0, cacheCreationInputTokens12h: 0, outputTokens: 0, reasoningTokens: 0, totalTokens: 0 }
1969
2136
  );
1970
2137
  applyFinalUsage(accumulator, total);
1971
2138
  accumulator.tokenAggregationMethod = "delta_sum";
1972
2139
  accumulator.tokenConfidence = "high";
2140
+ accumulator.requestUsages = filteredDirect.map((usage) => requestUsageFrom(usage, usage.inputTokens));
1973
2141
  const skipped = direct.length - filteredDirect.length;
1974
2142
  if (skipped > 0) accumulator.warnings.push("duplicate_or_stale_token_snapshots_skipped");
1975
2143
  return;
@@ -1977,6 +2145,20 @@ function finalizeTokenAccumulator(accumulator) {
1977
2145
  accumulator.tokenAggregationMethod = "unknown";
1978
2146
  accumulator.tokenConfidence = "low";
1979
2147
  }
2148
+ function requestUsageFrom(usage, requestInputTokens) {
2149
+ return {
2150
+ model: "model" in usage ? usage.model : void 0,
2151
+ requestInputTokens,
2152
+ inputTokens: usage.inputTokens,
2153
+ cachedInputTokens: usage.cachedInputTokens,
2154
+ cacheCreationInputTokens: usage.cacheCreationInputTokens,
2155
+ cacheCreationInputTokens30m: usage.cacheCreationInputTokens30m,
2156
+ cacheCreationInputTokens12h: usage.cacheCreationInputTokens12h,
2157
+ outputTokens: usage.outputTokens,
2158
+ reasoningTokens: usage.reasoningTokens,
2159
+ totalTokens: usage.totalTokens
2160
+ };
2161
+ }
1980
2162
  function extractRecordTokens(record) {
1981
2163
  if (!record || typeof record !== "object") return void 0;
1982
2164
  const object = record;
@@ -2012,10 +2194,10 @@ function filterDuplicateDirectUsages(usages) {
2012
2194
  return filtered;
2013
2195
  }
2014
2196
  function sameTokenUsage(a, b) {
2015
- return a.inputTokens === b.inputTokens && a.cachedInputTokens === b.cachedInputTokens && a.outputTokens === b.outputTokens && a.reasoningTokens === b.reasoningTokens && a.totalTokens === b.totalTokens;
2197
+ return a.inputTokens === b.inputTokens && a.cachedInputTokens === b.cachedInputTokens && a.cacheCreationInputTokens === b.cacheCreationInputTokens && a.cacheCreationInputTokens30m === b.cacheCreationInputTokens30m && a.cacheCreationInputTokens12h === b.cacheCreationInputTokens12h && a.outputTokens === b.outputTokens && a.reasoningTokens === b.reasoningTokens && a.totalTokens === b.totalTokens;
2016
2198
  }
2017
2199
  function isMonotonicFrom(current, previous) {
2018
- return current.inputTokens >= previous.inputTokens && current.cachedInputTokens >= previous.cachedInputTokens && current.outputTokens >= previous.outputTokens && current.reasoningTokens >= previous.reasoningTokens;
2200
+ return current.inputTokens >= previous.inputTokens && current.cachedInputTokens >= previous.cachedInputTokens && current.cacheCreationInputTokens >= previous.cacheCreationInputTokens && current.outputTokens >= previous.outputTokens && current.reasoningTokens >= previous.reasoningTokens;
2019
2201
  }
2020
2202
  function looksLikeStaleRegression(current, previous, last) {
2021
2203
  const previousTotal = tokenBucketTotal(previous);
@@ -2031,22 +2213,34 @@ function stripSnapshot(usage) {
2031
2213
  return {
2032
2214
  inputTokens: usage.inputTokens,
2033
2215
  cachedInputTokens: usage.cachedInputTokens,
2216
+ cacheCreationInputTokens: usage.cacheCreationInputTokens,
2217
+ cacheCreationInputTokens30m: usage.cacheCreationInputTokens30m,
2218
+ cacheCreationInputTokens12h: usage.cacheCreationInputTokens12h,
2034
2219
  outputTokens: usage.outputTokens,
2035
2220
  reasoningTokens: usage.reasoningTokens,
2036
2221
  totalTokens: usage.totalTokens
2037
2222
  };
2038
2223
  }
2039
2224
  function tokenUsageFromObject(target, cumulative) {
2225
+ const inputDetails = firstObject2(target.input_tokens_details, target.inputTokensDetails, target.prompt_tokens_details, target.promptTokensDetails);
2226
+ const ttlDetails = firstObject2(target.cache_write_tokens_details, target.cacheWriteTokensDetails, inputDetails?.cache_write_tokens_details, inputDetails?.cacheWriteTokensDetails);
2040
2227
  const input = numberFromKeys(target, ["input_tokens", "inputTokens", "prompt_tokens", "promptTokens"]);
2041
- const cached = numberFromKeys(target, ["cached_input_tokens", "cachedInputTokens", "cached_tokens", "cachedTokens", "cache_read_input_tokens"]);
2228
+ const cached = numberFromKeys(target, ["cached_input_tokens", "cachedInputTokens", "cached_tokens", "cachedTokens", "cache_read_input_tokens"]) || (inputDetails ? numberFromKeys(inputDetails, ["cached_tokens", "cachedTokens"]) : 0);
2042
2229
  const outputWithReasoning = numberFromKeys(target, ["output_tokens", "outputTokens", "completion_tokens", "completionTokens"]);
2043
- const reasoning = numberFromKeys(target, ["reasoning_tokens", "reasoningTokens", "reasoning_output_tokens", "reasoningOutputTokens"]);
2230
+ const reasoning = numberFromKeys(target, ["reasoning_tokens", "reasoningTokens", "reasoning_output_tokens", "reasoningOutputTokens"]) || (firstObject2(target.output_tokens_details, target.outputTokensDetails) ? numberFromKeys(firstObject2(target.output_tokens_details, target.outputTokensDetails), ["reasoning_tokens", "reasoningTokens"]) : 0);
2044
2231
  const output = Math.max(outputWithReasoning - reasoning, 0);
2045
2232
  const total = numberFromKeys(target, ["total_tokens", "totalTokens", "tokens_used", "tokensUsed"]);
2046
- if (input + cached + output + reasoning + total === 0) return void 0;
2233
+ const cacheWrite30m = ttlDetails ? numberFromKeys(ttlDetails, ["ttl_30m_tokens", "ttl30mTokens", "ttl_30m"]) : 0;
2234
+ const cacheWrite12h = ttlDetails ? numberFromKeys(ttlDetails, ["ttl_12h_tokens", "ttl12hTokens", "ttl_12h"]) : 0;
2235
+ const cacheWriteDeclared = numberFromKeys(target, ["cache_creation_input_tokens", "cacheCreationInputTokens", "cache_write_input_tokens", "cacheWriteInputTokens", "cache_write_tokens", "cacheWriteTokens"]) || (inputDetails ? numberFromKeys(inputDetails, ["cache_write_tokens", "cacheWriteTokens", "cache_creation_input_tokens", "cacheCreationInputTokens"]) : 0);
2236
+ const cacheCreation = Math.max(cacheWriteDeclared, cacheWrite30m + cacheWrite12h);
2237
+ if (input + cached + output + reasoning + total + cacheCreation === 0) return void 0;
2047
2238
  return {
2048
2239
  inputTokens: input,
2049
2240
  cachedInputTokens: cached,
2241
+ cacheCreationInputTokens: cacheCreation,
2242
+ cacheCreationInputTokens30m: cacheWrite30m,
2243
+ cacheCreationInputTokens12h: cacheWrite12h,
2050
2244
  outputTokens: output,
2051
2245
  reasoningTokens: reasoning,
2052
2246
  totalTokens: total || input + output + reasoning,
@@ -2056,6 +2250,9 @@ function tokenUsageFromObject(target, cumulative) {
2056
2250
  function applyFinalUsage(accumulator, usage) {
2057
2251
  accumulator.inputTokens = usage.inputTokens;
2058
2252
  accumulator.cachedInputTokens = usage.cachedInputTokens;
2253
+ accumulator.cacheCreationInputTokens = usage.cacheCreationInputTokens;
2254
+ accumulator.cacheCreationInputTokens30m = usage.cacheCreationInputTokens30m;
2255
+ accumulator.cacheCreationInputTokens12h = usage.cacheCreationInputTokens12h;
2059
2256
  accumulator.outputTokens = usage.outputTokens;
2060
2257
  accumulator.reasoningTokens = usage.reasoningTokens;
2061
2258
  accumulator.totalTokens = usage.totalTokens || usage.inputTokens + usage.outputTokens + usage.reasoningTokens;
@@ -2076,7 +2273,7 @@ function numberFromKeys(object, keys) {
2076
2273
  }
2077
2274
 
2078
2275
  // packages/core/src/sources/codex.ts
2079
- var codexSessionCacheVersion = "codex-session-v1";
2276
+ var codexSessionCacheVersion = "codex-session-v2";
2080
2277
  var nativeSqliteRebuildAttempted = false;
2081
2278
  function scanCodex(options) {
2082
2279
  const codexHome = options.codexHome ?? path5.join(os3.homedir(), ".codex");
@@ -2307,6 +2504,9 @@ function threadToUsage(row, index, sessionFiles, options, importedModels = /* @_
2307
2504
  provider,
2308
2505
  inputTokens,
2309
2506
  cachedInputTokens,
2507
+ cacheCreationInputTokens: sessionBreakdown.cacheCreationInputTokens,
2508
+ cacheCreationInputTokens30m: sessionBreakdown.cacheCreationInputTokens30m,
2509
+ cacheCreationInputTokens12h: sessionBreakdown.cacheCreationInputTokens12h,
2310
2510
  outputTokens,
2311
2511
  reasoningTokens,
2312
2512
  reasoningOutputTokens: reasoningTokens,
@@ -2346,13 +2546,14 @@ function threadToUsage(row, index, sessionFiles, options, importedModels = /* @_
2346
2546
  sessionOutcome: inferOutcome(sessionBreakdown),
2347
2547
  compaction: sessionBreakdown.compaction
2348
2548
  };
2349
- const estimate = hasPricedBreakdown ? calculateRequestCosts([usage], options.pricing) : void 0;
2350
- const cost = estimate?.costUsd;
2351
- const costWarnings = hasPricedBreakdown ? warnings : [...warnings, "missing_token_breakdown"];
2549
+ const estimate = hasPricedBreakdown ? sessionEstimate(sessionBreakdown.requestUsages, model, options.pricing) : void 0;
2550
+ const cost = estimate?.result.costUsd;
2551
+ const costWarnings = [...warnings, ...estimate?.result.assumptions ?? []];
2352
2552
  return {
2353
2553
  ...usage,
2354
2554
  estimatedCostUsd: cost,
2355
- warnings: cost === void 0 ? [.../* @__PURE__ */ new Set([...costWarnings, "unknown_pricing", ...estimate?.warnings ?? []])] : warnings
2555
+ modelUsage: estimate?.modelUsage,
2556
+ warnings: cost === void 0 ? [.../* @__PURE__ */ new Set([...hasPricedBreakdown ? costWarnings : [...costWarnings, "missing_token_breakdown"], "unknown_pricing", ...estimate?.result.warnings ?? []])] : [...new Set(costWarnings)]
2356
2557
  };
2357
2558
  }
2358
2559
  function readStandaloneSessions(sessionFiles, options) {
@@ -2382,6 +2583,9 @@ function readStandaloneSessions(sessionFiles, options) {
2382
2583
  provider,
2383
2584
  inputTokens: breakdown.inputTokens,
2384
2585
  cachedInputTokens: breakdown.cachedInputTokens,
2586
+ cacheCreationInputTokens: breakdown.cacheCreationInputTokens,
2587
+ cacheCreationInputTokens30m: breakdown.cacheCreationInputTokens30m,
2588
+ cacheCreationInputTokens12h: breakdown.cacheCreationInputTokens12h,
2385
2589
  outputTokens: breakdown.outputTokens,
2386
2590
  reasoningTokens: breakdown.reasoningTokens,
2387
2591
  reasoningOutputTokens: breakdown.reasoningTokens,
@@ -2422,14 +2626,52 @@ function readStandaloneSessions(sessionFiles, options) {
2422
2626
  compaction: breakdown.compaction
2423
2627
  };
2424
2628
  const hasPricedBreakdown = breakdown.inputTokens + breakdown.cachedInputTokens + breakdown.outputTokens + breakdown.reasoningTokens > 0;
2425
- const estimate = hasPricedBreakdown ? calculateRequestCosts([usage], options.pricing) : void 0;
2426
- const cost = estimate?.costUsd;
2629
+ const estimate = hasPricedBreakdown ? sessionEstimate(breakdown.requestUsages, model, options.pricing) : void 0;
2630
+ const cost = estimate?.result.costUsd;
2427
2631
  return {
2428
2632
  ...usage,
2429
2633
  estimatedCostUsd: cost,
2430
- warnings: cost === void 0 ? [.../* @__PURE__ */ new Set([...usage.warnings, hasPricedBreakdown ? "unknown_pricing" : "missing_token_breakdown", ...estimate?.warnings ?? []])] : usage.warnings
2634
+ modelUsage: estimate?.modelUsage,
2635
+ warnings: cost === void 0 ? [.../* @__PURE__ */ new Set([...usage.warnings, hasPricedBreakdown ? "unknown_pricing" : "missing_token_breakdown", ...estimate?.result.warnings ?? [], ...estimate?.result.assumptions ?? []])] : [.../* @__PURE__ */ new Set([...usage.warnings, ...estimate?.result.assumptions ?? []])]
2636
+ };
2637
+ });
2638
+ }
2639
+ function sessionEstimate(requestUsages, fallbackModel, pricing) {
2640
+ const requests = requestUsages.map((request) => ({ ...request, model: request.model ?? fallbackModel }));
2641
+ const result = calculateRequestCosts(requests, pricing);
2642
+ return { result, modelUsage: buildSessionModelUsage(requests, result.requestCosts) };
2643
+ }
2644
+ function buildSessionModelUsage(requests, requestCosts) {
2645
+ if (!requests.length) return void 0;
2646
+ const groups = /* @__PURE__ */ new Map();
2647
+ requests.forEach((request, index) => {
2648
+ const entry = groups.get(request.model) ?? {
2649
+ model: request.model,
2650
+ requestCount: 0,
2651
+ inputTokens: 0,
2652
+ cachedInputTokens: 0,
2653
+ cacheCreationInputTokens: 0,
2654
+ cacheCreationInputTokens30m: 0,
2655
+ cacheCreationInputTokens12h: 0,
2656
+ outputTokens: 0,
2657
+ reasoningTokens: 0,
2658
+ totalTokens: 0,
2659
+ estimatedCostUsd: 0
2431
2660
  };
2661
+ entry.requestCount += 1;
2662
+ entry.inputTokens += request.inputTokens;
2663
+ entry.cachedInputTokens += request.cachedInputTokens;
2664
+ entry.cacheCreationInputTokens += request.cacheCreationInputTokens;
2665
+ entry.cacheCreationInputTokens30m = (entry.cacheCreationInputTokens30m ?? 0) + request.cacheCreationInputTokens30m;
2666
+ entry.cacheCreationInputTokens12h = (entry.cacheCreationInputTokens12h ?? 0) + request.cacheCreationInputTokens12h;
2667
+ entry.outputTokens += request.outputTokens;
2668
+ entry.reasoningTokens += request.reasoningTokens;
2669
+ entry.totalTokens += request.totalTokens;
2670
+ const requestCost = requestCosts[index];
2671
+ entry.estimatedCostUsd = requestCost === void 0 || entry.estimatedCostUsd === void 0 ? void 0 : Number((entry.estimatedCostUsd + requestCost).toFixed(6));
2672
+ groups.set(request.model, entry);
2432
2673
  });
2674
+ return [...groups.values()];
2433
2675
  }
2434
2676
  function hasImportedSession(sessions, candidate) {
2435
2677
  const candidatePath = comparableSourcePath(candidate.sourcePath);
@@ -2575,7 +2817,8 @@ function readSessionBreakdown(filePath) {
2575
2817
  applyCompactionEvent(breakdown, record, lastUserMessageText);
2576
2818
  }
2577
2819
  breakdown.messageCount = eventMessageCount || responseMessageCount;
2578
- const tokenAggregation = aggregateTokens(records);
2820
+ const modelByRecord = recordModels(records);
2821
+ const tokenAggregation = aggregateTokens(records, (record) => modelByRecord.get(record));
2579
2822
  Object.assign(breakdown, {
2580
2823
  ...tokenAggregation,
2581
2824
  warnings: [...breakdown.warnings, ...tokenAggregation.warnings]
@@ -2590,6 +2833,22 @@ function readSessionBreakdown(filePath) {
2590
2833
  if (cacheKey) writeJsonCache("codex-session", cacheKey, breakdown);
2591
2834
  return breakdown;
2592
2835
  }
2836
+ function recordModels(records) {
2837
+ const models = /* @__PURE__ */ new Map();
2838
+ let current;
2839
+ for (const record of records) {
2840
+ const declared = declaredRecordModel(record);
2841
+ if (declared) current = declared;
2842
+ models.set(record, current);
2843
+ }
2844
+ return models;
2845
+ }
2846
+ function declaredRecordModel(record) {
2847
+ const object = asRecord(record);
2848
+ const payload = firstObject3(object?.payload) ?? object;
2849
+ const collaborationSettings = firstObject3(firstObject3(payload?.collaboration_mode)?.settings);
2850
+ return stringValue2(payload?.model) ?? stringValue2(collaborationSettings?.model);
2851
+ }
2593
2852
  function sessionBreakdownCacheKey(filePath) {
2594
2853
  try {
2595
2854
  const stat = fs5.statSync(filePath);
@@ -2674,6 +2933,7 @@ function emptyBreakdown() {
2674
2933
  outputTokens: 0,
2675
2934
  reasoningTokens: 0,
2676
2935
  totalTokens: 0,
2936
+ requestUsages: [],
2677
2937
  tokenAggregationMethod: "unknown",
2678
2938
  tokenConfidence: "low",
2679
2939
  tokenSnapshotCount: 0,
@@ -3136,7 +3396,7 @@ function claudeBreakdownToUsage(file, index, options, breakdown, idSuffix = "")
3136
3396
  return {
3137
3397
  ...usage,
3138
3398
  estimatedCostUsd: cost,
3139
- warnings: cost === void 0 ? [.../* @__PURE__ */ new Set([...usage.warnings, "unknown_pricing", ...estimate?.warnings ?? [], ...estimate?.warnings.some((warning) => warning.startsWith("unknown_pricing_model:") && warning.includes("fast-mode")) ? ["unknown_fast_mode_pricing"] : []])] : usage.warnings
3399
+ warnings: cost === void 0 ? [.../* @__PURE__ */ new Set([...usage.warnings, "unknown_pricing", ...estimate?.warnings ?? [], ...estimate?.assumptions ?? [], ...estimate?.warnings.some((warning) => warning.startsWith("unknown_pricing_model:") && warning.includes("fast-mode")) ? ["unknown_fast_mode_pricing"] : []])] : [.../* @__PURE__ */ new Set([...usage.warnings, ...estimate?.assumptions ?? []])]
3140
3400
  };
3141
3401
  }
3142
3402
  function inferClaudeEntrypointFromPath(filePath) {
@@ -4049,7 +4309,7 @@ function breakdownToUsage(breakdown, index, options) {
4049
4309
  };
4050
4310
  const estimate = hasPricedBreakdown ? calculateRequestCosts(breakdown.tokenEvents.map((event) => ({ ...event, model: normalizeCopilotModel(hasKnownModel(event.model) ? event.model : breakdown.model) })), options.pricing) : void 0;
4051
4311
  const cost = estimate?.costUsd;
4052
- return { ...usage, estimatedCostUsd: cost, warnings: hasPricedBreakdown && cost === void 0 ? [.../* @__PURE__ */ new Set([...usage.warnings, "unknown_pricing", ...estimate?.warnings ?? []])] : usage.warnings };
4312
+ return { ...usage, estimatedCostUsd: cost, warnings: hasPricedBreakdown && cost === void 0 ? [.../* @__PURE__ */ new Set([...usage.warnings, "unknown_pricing", ...estimate?.warnings ?? [], ...estimate?.assumptions ?? []])] : [.../* @__PURE__ */ new Set([...usage.warnings, ...estimate?.assumptions ?? []])] };
4053
4313
  }
4054
4314
  function unknownCopilotRepoInfo() {
4055
4315
  return {
@@ -4755,9 +5015,12 @@ function applyCursorRecord(breakdown, record) {
4755
5015
  }
4756
5016
  }
4757
5017
  const usage = extractUsage(objects);
4758
- if (usage.inputTokens + usage.cachedInputTokens + usage.outputTokens + usage.reasoningTokens + usage.totalTokens > 0) {
5018
+ if (usage.inputTokens + usage.cachedInputTokens + usage.outputTokens + usage.reasoningTokens + usage.totalTokens + usage.cacheCreationInputTokens > 0) {
4759
5019
  breakdown.inputTokens += usage.inputTokens;
4760
5020
  breakdown.cachedInputTokens += usage.cachedInputTokens;
5021
+ breakdown.cacheCreationInputTokens += usage.cacheCreationInputTokens;
5022
+ breakdown.cacheCreationInputTokens30m += usage.cacheCreationInputTokens30m;
5023
+ breakdown.cacheCreationInputTokens12h += usage.cacheCreationInputTokens12h;
4761
5024
  breakdown.outputTokens += usage.outputTokens;
4762
5025
  breakdown.reasoningTokens += usage.reasoningTokens;
4763
5026
  breakdown.totalTokens += usage.totalTokens;
@@ -4850,9 +5113,16 @@ function textFromUnknown(value) {
4850
5113
  function extractUsage(objects) {
4851
5114
  const usageObjects = objects.filter((object) => Object.keys(object).some((key) => key.toLowerCase().includes("token") || key.toLowerCase() === "usage"));
4852
5115
  const candidates = usageObjects.length ? usageObjects : objects;
5116
+ const detailObjects = candidates.flatMap((candidate) => [firstObject6(candidate.input_tokens_details), firstObject6(candidate.inputTokensDetails), firstObject6(candidate.cache_write_tokens_details)].filter((item) => Boolean(item)));
5117
+ const cacheCreation30m = firstNumberByKeys(detailObjects, ["ttl_30m_tokens", "ttl30mTokens"]) ?? 0;
5118
+ const cacheCreation12h = firstNumberByKeys(detailObjects, ["ttl_12h_tokens", "ttl12hTokens"]) ?? 0;
5119
+ const cacheCreationDeclared = firstNumberByKeys(candidates, ["cacheCreationInputTokens", "cache_creation_input_tokens", "cacheWriteInputTokens", "cache_write_input_tokens", "cache_write_tokens"]) ?? firstNumberByKeys(detailObjects, ["cache_write_tokens", "cacheWriteTokens"]) ?? 0;
4853
5120
  return {
4854
5121
  inputTokens: firstNumberByKeys(candidates, ["inputTokens", "input_tokens", "promptTokens", "prompt_tokens", "totalUsedTokens"]) ?? 0,
4855
- cachedInputTokens: firstNumberByKeys(candidates, ["cachedInputTokens", "cached_input_tokens", "cacheReadInputTokens", "cache_read_input_tokens"]) ?? 0,
5122
+ cachedInputTokens: firstNumberByKeys(candidates, ["cachedInputTokens", "cached_input_tokens", "cached_tokens", "cacheReadInputTokens", "cache_read_input_tokens"]) ?? firstNumberByKeys(detailObjects, ["cached_tokens", "cachedTokens"]) ?? 0,
5123
+ cacheCreationInputTokens: Math.max(cacheCreationDeclared, cacheCreation30m + cacheCreation12h),
5124
+ cacheCreationInputTokens30m: cacheCreation30m,
5125
+ cacheCreationInputTokens12h: cacheCreation12h,
4856
5126
  outputTokens: firstNumberByKeys(candidates, ["outputTokens", "output_tokens", "completionTokens", "completion_tokens"]) ?? 0,
4857
5127
  reasoningTokens: firstNumberByKeys(candidates, ["reasoningTokens", "reasoning_tokens", "reasoningOutputTokens", "reasoning_output_tokens"]) ?? 0,
4858
5128
  totalTokens: firstNumberByKeys(candidates, ["totalTokens", "total_tokens", "tokens", "tokenCount", "token_count"]) ?? 0,
@@ -4908,6 +5178,9 @@ function candidateToUsage(candidate, index, options) {
4908
5178
  provider: providerForModel2(breakdown.model ?? ""),
4909
5179
  inputTokens: breakdown.inputTokens,
4910
5180
  cachedInputTokens: breakdown.cachedInputTokens,
5181
+ cacheCreationInputTokens: breakdown.cacheCreationInputTokens || void 0,
5182
+ cacheCreationInputTokens30m: breakdown.cacheCreationInputTokens30m || void 0,
5183
+ cacheCreationInputTokens12h: breakdown.cacheCreationInputTokens12h || void 0,
4911
5184
  outputTokens: breakdown.outputTokens,
4912
5185
  reasoningTokens: breakdown.reasoningTokens,
4913
5186
  reasoningOutputTokens: breakdown.reasoningTokens,
@@ -4960,7 +5233,7 @@ function candidateToUsage(candidate, index, options) {
4960
5233
  return {
4961
5234
  ...usage,
4962
5235
  estimatedCostUsd,
4963
- warnings: estimatedCostUsd === void 0 ? [.../* @__PURE__ */ new Set([...usage.warnings, breakdown.hasEstimatedPromptTokens ? "cursor_cost_not_estimated_from_prompt_tokens" : hasTokenBreakdown ? "unknown_pricing" : "unknown_cost", ...estimate?.warnings ?? []])] : usage.warnings
5236
+ warnings: estimatedCostUsd === void 0 ? [.../* @__PURE__ */ new Set([...usage.warnings, breakdown.hasEstimatedPromptTokens ? "cursor_cost_not_estimated_from_prompt_tokens" : hasTokenBreakdown ? "unknown_pricing" : "unknown_cost", ...estimate?.warnings ?? [], ...estimate?.assumptions ?? []])] : [.../* @__PURE__ */ new Set([...usage.warnings, ...estimate?.assumptions ?? []])]
4964
5237
  };
4965
5238
  }
4966
5239
  function inferProjectPathFromCursorPath(filePath, cursorHome) {
@@ -5074,6 +5347,9 @@ function emptyBreakdown4() {
5074
5347
  model: void 0,
5075
5348
  inputTokens: 0,
5076
5349
  cachedInputTokens: 0,
5350
+ cacheCreationInputTokens: 0,
5351
+ cacheCreationInputTokens30m: 0,
5352
+ cacheCreationInputTokens12h: 0,
5077
5353
  outputTokens: 0,
5078
5354
  reasoningTokens: 0,
5079
5355
  totalTokens: 0,
@@ -5351,7 +5627,9 @@ function readPricingData() {
5351
5627
  const pricingPath = resolvePricingPath(config);
5352
5628
  return {
5353
5629
  path: pricingPath,
5354
- models: loadPricingTable(pricingPath)
5630
+ models: loadPricingTable(pricingPath),
5631
+ defaults: defaultPricing,
5632
+ contextRules: pricingContextRules()
5355
5633
  };
5356
5634
  }
5357
5635
  function readConfigData() {
@@ -5375,7 +5653,9 @@ function writePricingData(models) {
5375
5653
  clearScanCache();
5376
5654
  return {
5377
5655
  path: pricingPath,
5378
- models: loadPricingTable(pricingPath)
5656
+ models: loadPricingTable(pricingPath),
5657
+ defaults: defaultPricing,
5658
+ contextRules: pricingContextRules()
5379
5659
  };
5380
5660
  }
5381
5661
  function clearRepoSpendLocalData() {
@@ -6446,12 +6726,18 @@ function recentCommandLines(lines) {
6446
6726
  function createServer(options = {}) {
6447
6727
  const app = Fastify({ logger: false });
6448
6728
  app.addHook("onRequest", async (request, reply) => {
6449
- if (!isProtectedLocalMutation(request.method, request.url)) return;
6450
- if (!isAllowedLocalHost(request.headers.host)) {
6451
- return reply.code(403).send({ error: "Mutating RepoSpend local settings requires a localhost Host header." });
6729
+ const path11 = guardRequestPath(request);
6730
+ if (isProtectedLocalMutation(request.method, path11)) {
6731
+ if (!isAllowedLocalHost(request.headers.host)) {
6732
+ return reply.code(403).send({ error: "Mutating RepoSpend local settings requires a localhost Host header." });
6733
+ }
6734
+ if (!isAllowedLocalOrigin(request.headers.origin)) {
6735
+ return reply.code(403).send({ error: "Mutating RepoSpend local settings requires a localhost Origin." });
6736
+ }
6737
+ return;
6452
6738
  }
6453
- if (!isAllowedLocalOrigin(request.headers.origin)) {
6454
- return reply.code(403).send({ error: "Mutating RepoSpend local settings requires a localhost Origin." });
6739
+ if (isSensitiveLocalRead(request.method, path11) && request.headers.host && !isAllowedLocalHost(request.headers.host)) {
6740
+ return reply.code(403).send({ error: "Reading RepoSpend local data requires a localhost Host header." });
6455
6741
  }
6456
6742
  });
6457
6743
  app.get("/api/health", async () => ({ ok: true, app: "RepoSpend", version: readPackageVersion() }));
@@ -6566,7 +6852,26 @@ function isAddressInUse(error) {
6566
6852
  }
6567
6853
  function isProtectedLocalMutation(method, url) {
6568
6854
  if (method !== "PUT" && method !== "POST" && method !== "DELETE") return false;
6569
- return url.startsWith("/api/settings/") || url.startsWith("/api/cache/");
6855
+ const pathname = routerNormalizedPath(url);
6856
+ return pathname.startsWith("/api/settings/") || pathname.startsWith("/api/cache/");
6857
+ }
6858
+ var SENSITIVE_LOCAL_READS = /* @__PURE__ */ new Set(["/api/dashboard", "/api/export.json", "/api/export.csv"]);
6859
+ function isSensitiveLocalRead(method, url) {
6860
+ if (method !== "GET" && method !== "HEAD") return false;
6861
+ return SENSITIVE_LOCAL_READS.has(routerNormalizedPath(url));
6862
+ }
6863
+ function guardRequestPath(request) {
6864
+ const matched = request.routeOptions?.url;
6865
+ return typeof matched === "string" ? matched : routerNormalizedPath(request.url);
6866
+ }
6867
+ function routerNormalizedPath(url) {
6868
+ const absoluteStripped = url.replace(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^/?#]*/, "");
6869
+ const raw = absoluteStripped.split("?")[0] ?? "";
6870
+ try {
6871
+ return decodeURIComponent(raw);
6872
+ } catch {
6873
+ return raw;
6874
+ }
6570
6875
  }
6571
6876
  function isAllowedLocalHost(hostHeader) {
6572
6877
  if (!hostHeader) return false;
@@ -6613,11 +6918,15 @@ function validatePricingBody(body) {
6613
6918
  const cachedInputPerMillion = finiteNumber(row.cachedInputPerMillion);
6614
6919
  const cacheCreationInput5mPerMillion = finiteNumber(row.cacheCreationInput5mPerMillion);
6615
6920
  const cacheCreationInput1hPerMillion = finiteNumber(row.cacheCreationInput1hPerMillion);
6921
+ const cacheCreationInput30mPerMillion = finiteNumber(row.cacheCreationInput30mPerMillion);
6922
+ const cacheCreationInput12hPerMillion = finiteNumber(row.cacheCreationInput12hPerMillion);
6616
6923
  const cacheCreationInputPerMillion = finiteNumber(row.cacheCreationInputPerMillion);
6617
6924
  const reasoningOutputPerMillion = finiteNumber(row.reasoningOutputPerMillion);
6618
6925
  if (cachedInputPerMillion !== void 0) modelPricing.cachedInputPerMillion = cachedInputPerMillion;
6619
6926
  if (cacheCreationInput5mPerMillion !== void 0) modelPricing.cacheCreationInput5mPerMillion = cacheCreationInput5mPerMillion;
6620
6927
  if (cacheCreationInput1hPerMillion !== void 0) modelPricing.cacheCreationInput1hPerMillion = cacheCreationInput1hPerMillion;
6928
+ if (cacheCreationInput30mPerMillion !== void 0) modelPricing.cacheCreationInput30mPerMillion = cacheCreationInput30mPerMillion;
6929
+ if (cacheCreationInput12hPerMillion !== void 0) modelPricing.cacheCreationInput12hPerMillion = cacheCreationInput12hPerMillion;
6621
6930
  if (cacheCreationInputPerMillion !== void 0) modelPricing.cacheCreationInputPerMillion = cacheCreationInputPerMillion;
6622
6931
  if (reasoningOutputPerMillion !== void 0) modelPricing.reasoningOutputPerMillion = reasoningOutputPerMillion;
6623
6932
  if (typeof row.note === "string") modelPricing.note = row.note;