big-spender 0.14.0 → 0.14.2

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
@@ -369,7 +369,7 @@ about 15 to 20 percent less.
369
369
  | Source | Files | Notes |
370
370
  | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
371
371
  | Claude Code | `~/.claude/projects/**/*.jsonl`, `~/.config/claude/projects`, `$CLAUDE_CONFIG_DIR/projects` | `assistant` lines; de-duplicated by `message.id` + `requestId` (one API response is logged once per content block, and resumed sessions copy history). `<synthetic>` skipped; subagent logs included. Some Claude Code versions (2.1.293 to 2.1.310) log a partial output count on a message's first line and the final count on a later line; a later line that reports more output adds the difference. |
372
- | Codex | `~/.codex/sessions/**/rollout-*.jsonl`, `$CODEX_HOME/sessions` | `event_msg` / `token_count` with `info.last_token_usage`; skipped when `total_token_usage` did not change. Model from the latest `turn_context`. `cached_input_tokens` is part of `input_tokens`; reasoning is part of `output_tokens`. |
372
+ | Codex | `~/.codex/sessions/**/rollout-*.jsonl`, `~/.codex/archived_sessions`, `$CODEX_HOME/sessions`, `$CODEX_HOME/archived_sessions` | `event_msg` / `token_count` with `info.last_token_usage`; skipped when `total_token_usage` did not change. Model from the latest `turn_context`. `cached_input_tokens` is part of `input_tokens`; reasoning is part of `output_tokens`. |
373
373
  | Cursor | Cursor's API, `DashboardService/GetFilteredUsageEvents`, with `BIG_SPENDER_CURSOR_API_KEY` | Events with token counts only. Cost is Cursor's `totalCents`. Events have no unique id and pages can overlap, so a time window with more than 1,000 events is split in half instead of paged. `cacheWriteTokens` count as 5-minute cache writes. Sessions are hashed `conversationId`s. Model names are lowercased, and anything outside `a-z 0-9 . _ : @ -` becomes `-`. |
374
374
  | pi | `~/.pi/agent/sessions/**/*.jsonl`, `$PI_CODING_AGENT_DIR/sessions`, `$PI_CODING_AGENT_SESSION_DIR`, `$PI_AGENT_DIR` (comma-separated, as in ccusage) | Assistant `message` entries with `usage`; `input` excludes cached tokens, reasoning is part of `output`, and `cacheWrite` counts as 5-minute writes except its `cacheWrite1h` part. Calls with no tokens (aborted, failed before a retry) are skipped, and a call with only `totalTokens` counts it as output. A fork's file starts with a copy of its parent's calls up to the fork; those leading calls are skipped when the parent file has them. ccusage looks only at the parent's current branch, so it counts the copy again once the parent moves to another branch. A model id that is a file path (absolute, a `file://` or `host:/` URL, or ending in `.gguf` and similar) is reduced to its file name. `subagent-artifacts/` transcripts are skipped. Cost is LiteLLM's, not the cost pi stores. |
375
375
  | Grok Build (experimental) | `~/.grok/sessions/**/updates.jsonl`, `$GROK_HOME/sessions` | **Experimental:** checked against ccusage on test fixtures built from its Grok parser tests, not yet against real Grok Build logs. `turn_completed` lines, one row per model in `usage.modelUsage` (the top-level usage under `summary.json`'s `current_model_id` when that map is missing). De-duplicated by `eventId` + model, also across sessions, since one event can be exported into several; a row without `eventId` by its full content within its file. `cachedReadTokens` and `cacheCreationTokens` are part of `inputTokens`; reasoning is part of `outputTokens`. Always the base rate: a turn sums several API requests, so its total cannot pick the long-context tier; a request of its own above 200K tokens is under-priced. A model id that is a file path is reduced to its file name. A turn cut off before it completes is never logged, so it is not counted. |
@@ -9,13 +9,7 @@
9
9
  // and POSTs it as a second snapshot under the device id "cursor".
10
10
  //
11
11
  // Zero dependencies, Node >= 20 (or Bun). `big-spender install` copies this single file to
12
- // ~/.local/share/big-spender/collector.mjs and schedules it. See the package README.
13
- //
14
- // Usage:
15
- // node collector.mjs # parse new log bytes, POST the snapshot
16
- // node collector.mjs --dry-run # print the snapshot + a 24h summary, no POST
17
- // node collector.mjs --summary # print only the 24h summary
18
- // node collector.mjs --reset # forget local state and rescan everything
12
+ // ~/.local/share/big-spender/collector.mjs and schedules it. See the package README and USAGE below.
19
13
  //
20
14
  // Env: BIG_SPENDER_DEVICE_ID, BIG_SPENDER_INGEST_URL, BIG_SPENDER_INGEST_TOKEN and optionally
21
15
  // BIG_SPENDER_CURSOR_API_KEY and BIG_SPENDER_POLL_LIMITS=off (see templates/env.example).
@@ -54,10 +48,28 @@ const CURSOR_PAGE_SIZE = 1000;
54
48
  // The server's date floor (EARLIEST_DATE in schema.ts); the backfill reads from here.
55
49
  const CURSOR_EARLIEST_MS = Date.parse('2020-01-01T00:00:00Z');
56
50
 
57
- const args = new Set(process.argv.slice(2));
58
- const DRY_RUN = args.has('--dry-run');
59
- const SUMMARY_ONLY = args.has('--summary');
60
- const RESET = args.has('--reset');
51
+ const USAGE = `Usage: node collector.mjs [--dry-run | --summary] [--reset]
52
+
53
+ (no flag) read new log data and POST the snapshot
54
+ --dry-run print the snapshot and a 24h summary; sends nothing
55
+ --summary print only the 24h summary; sends nothing
56
+ --reset forget local state and rescan everything
57
+ -h, --help print this help`;
58
+
59
+ // Checked before anything else runs: an ignored typo such as --dryrun would post a real snapshot.
60
+ const args = process.argv.slice(2);
61
+ if (args.includes('--help') || args.includes('-h')) {
62
+ console.log(USAGE);
63
+ process.exit(0);
64
+ }
65
+ const unknown = args.find((a) => !['--dry-run', '--summary', '--reset'].includes(a));
66
+ if (unknown !== undefined) {
67
+ console.error(`[big-spender] unknown argument: ${unknown}\n\n${USAGE}`);
68
+ process.exit(2);
69
+ }
70
+ const DRY_RUN = args.includes('--dry-run');
71
+ const SUMMARY_ONLY = args.includes('--summary');
72
+ const RESET = args.includes('--reset');
61
73
 
62
74
  const HOME = homedir();
63
75
  const CACHE_DIR = join(process.env.XDG_CACHE_HOME || join(HOME, '.cache'), 'big-spender');
@@ -2478,8 +2490,11 @@ const SOURCES = {
2478
2490
  priceKeys: litellmKeys('anthropic')
2479
2491
  },
2480
2492
  codex: {
2481
- paths: [join(HOME, '.codex', 'sessions')],
2482
- envPaths: () => fromEnv('CODEX_HOME', 'sessions'),
2493
+ paths: [join(HOME, '.codex', 'sessions'), join(HOME, '.codex', 'archived_sessions')],
2494
+ envPaths: () => [
2495
+ ...fromEnv('CODEX_HOME', 'sessions'),
2496
+ ...fromEnv('CODEX_HOME', 'archived_sessions')
2497
+ ],
2483
2498
  read: jsonlReader((ctx, file, path) =>
2484
2499
  codexLineHandler(
2485
2500
  ctx.state,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "big-spender",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "Track what your AI coding agents would cost at API prices, across all your machines.",
5
5
  "keywords": [
6
6
  "ai",