@deathbeam/pi-usage 0.0.10 → 0.0.11

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 CHANGED
@@ -27,7 +27,7 @@ Day rows include days without usage. Δ compares cost with the previous day. The
27
27
 
28
28
  The summary compares the daily spend so far this week and month with last week and month. Weeks start on Monday in local time. `▲new` means the previous period had no spend.
29
29
 
30
- Compaction and branch summaries are counted under `pi / summaries`.
30
+ Compaction and branch summaries are counted under `(summaries)`.
31
31
 
32
32
  ## Development
33
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deathbeam/pi-usage",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Minimal extension for token usage and cost per provider, model and project.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/usage.ts CHANGED
@@ -58,7 +58,7 @@ export type DailyCost = { label: string; cost: number };
58
58
 
59
59
  type Tally = { stats: Stats; requests: number; models?: Map<string, Tally>; providers?: Set<string> };
60
60
 
61
- const CACHE_VERSION = 2;
61
+ const CACHE_VERSION = 3;
62
62
 
63
63
  function emptyStats(): Stats {
64
64
  return { cost: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
@@ -199,20 +199,26 @@ async function parseFile(file: string): Promise<UsageRecord[]> {
199
199
  model = String(entry.model);
200
200
  } else {
201
201
  // Compaction and branch-summary calls carry no model, so their cost gets its own row.
202
- provider = "pi";
203
- model = "summaries";
202
+ provider = "(summaries)";
203
+ model = entry.type;
204
204
  }
205
205
  const cost = typeof usage.cost === "number" ? usage.cost : num(usage.cost?.total);
206
+ const input = num(usage.input);
207
+ const output = num(usage.output);
208
+ const cacheRead = num(usage.cacheRead);
209
+ const cacheWrite = num(usage.cacheWrite);
210
+ // An aborted request (delegate children report one) carries no usage; counting it adds a phantom row.
211
+ if (cost === 0 && input === 0 && output === 0 && cacheRead === 0 && cacheWrite === 0) continue;
206
212
  const stamp = entry.type === "message" ? message.timestamp : entry.timestamp;
207
213
  records.push({
208
214
  provider,
209
215
  model,
210
216
  ts: typeof stamp === "string" ? num(Date.parse(stamp)) : num(stamp),
211
217
  cost,
212
- input: num(usage.input),
213
- output: num(usage.output),
214
- cacheRead: num(usage.cacheRead),
215
- cacheWrite: num(usage.cacheWrite),
218
+ input,
219
+ output,
220
+ cacheRead,
221
+ cacheWrite,
216
222
  requests: 1,
217
223
  cwd,
218
224
  sessionId,