big-spender 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -8
- package/dist/collector.mjs +36 -30
- package/package.json +1 -1
- package/templates/env.example +0 -3
package/README.md
CHANGED
|
@@ -374,8 +374,8 @@ about 15 to 20 percent less.
|
|
|
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. |
|
|
376
376
|
| GitHub Copilot CLI (experimental) | `~/.copilot/session-state/*/events.jsonl`, `$COPILOT_HOME/session-state` | Experimental: so far compared with ccusage only on a few sessions from one machine and on ccusage's test fixtures, not on regular use. `session.usage_record` events (one per model call). Older versions log only `session.shutdown`; its cumulative `modelMetrics` count as the growth since the previous shutdown, and only when no per-call record came in that interval. `inputTokens` includes cache reads and writes, so input counts uncached tokens only. Reasoning is part of `outputTokens`. A `-1m` or `-1m-internal` model suffix is dropped. Only the top-level `events.jsonl` of each session is read, not the OpenTelemetry export or `session-store.db`. |
|
|
377
|
-
| Antigravity (experimental) | `~/.gemini/antigravity*/conversations/**/*.db`, `~/.config/antigravity/conversations
|
|
378
|
-
| Gemini CLI (experimental) | `~/.gemini/tmp/**/*.json` and `*.jsonl`, `$GEMINI_DATA_DIR` (comma-separated) | **Experimental:**
|
|
377
|
+
| Antigravity (experimental) | `~/.gemini/antigravity*/conversations/**/*.db`, `~/.config/antigravity/conversations`, T3 Code profiles | **Experimental:** matches ccusage on test fixtures and one day of real CLI and T3 Code data. Every T3 Code profile, `~/.t3/{userdata,dev}/providers/antigravity/*/antigravity-acp`, is read, also under `$T3CODE_HOME`. `antigravity*` is `antigravity` and its `-cli`, `-ide`, `-backup` and `-acp` variants; `$ANTIGRAVITY_DATA_DIR` (comma-separated) is read too. Read with `node:sqlite` (Node 22.13+, else skipped with a warning). Usage messages in `gen_metadata` and `steps`, retries included; copies sharing a response, provider or message id merge and keep the largest counts. A later copy can move a response to another day or model; the day and model it left are sent as a zero row, which takes them back on the server. A model name with a slash (possibly a path) becomes `gemini-internal-model`. Reasoning is part of output. |
|
|
378
|
+
| Gemini CLI (experimental) | `~/.gemini/tmp/**/*.json` and `*.jsonl`, `$GEMINI_DATA_DIR` (comma-separated) | **Experimental:** checked against ccusage on test fixtures, not yet against real Gemini CLI data. `gemini` chat messages with `tokens`, and saved headless `stats` (per model, or with the last model named, else `unknown`). A changed file is read whole and its counts replace what it counted before, as ccusage counts each file as it is; in JSONL the last copy of a message id counts. `input` excludes `cached` when the total shows it was inside (always in stats), and `tool` tokens count as input. Reasoning (`thoughts`) and any total beyond the parts count as output, as ccusage bills them, though its per-model output leaves reasoning out. A model id that is a file path is reduced to its file name. `$GEMINI_DATA_DIR` adds dirs to the default rather than replacing it. |
|
|
379
379
|
|
|
380
380
|
**Pricing.** Claude Code, Codex, pi, Grok Build, GitHub Copilot CLI, Antigravity, Gemini CLI and OpenCode use LiteLLM
|
|
381
381
|
| OpenCode | `~/.local/share/opencode` (or `$XDG_DATA_HOME/opencode`), or `$OPENCODE_DATA_DIR` (comma-separated, replaces the default): `opencode.db` and pre-SQLite `storage/message/**/*.json` | Assistant messages, and `completed` compaction rows, from the 1.x `message` table, the 2.x `session_message` table and the JSON files. The first copy of a message id wins, because 2.x copies the 1.x rows; A 2.x fork's copies of its parent's rows keep the parent rows' times, so rows older than the fork are skipped, as OpenCode's own stats do; this holds after the parent is deleted, and a parent deleted before big-spender read it is not counted. Needs `node:sqlite` (Node 22.13+). OpenCode rewrites a running message, so each run reads the window again and adds what changed; an hour and model a message left are sent as a zero row, which takes them back on the server. Cache reads and writes are outside `input`. 1.x counts reasoning in `output`; 2.x does not, so it is added. `claude-agent` rows are skipped, because the Claude Code source counts them. A model id that is a file path, a URL, or ends in a model-file extension (`.gguf`, `.safetensors`, ...) is cut to its file name, without query or login; an address with no file name is sent as `local`. OpenCode's own `cost` is not used; a model is priced under the first upstream it was seen on. |
|
|
@@ -400,12 +400,6 @@ input price, also above a tier, as ccusage does. 1-hour cache writes use
|
|
|
400
400
|
minus cache-read price). Copilot also tries `github_copilot/<model>`, and swaps a dot between digits
|
|
401
401
|
for a dash in Claude model names (`claude-opus-4.6` is priced as `claude-opus-4-6`).
|
|
402
402
|
|
|
403
|
-
**Experimental sources.** A source whose counts match ccusage on test data but have not been checked
|
|
404
|
-
against real usage yet is marked `experimental` in `SOURCES`. The collector reads and sends it only
|
|
405
|
-
when `BIG_SPENDER_EXPERIMENTAL` (comma-separated provider ids, in the environment or the env file)
|
|
406
|
-
names it. Antigravity and Gemini CLI are gated this way. Removing it from the list stops sending its rows on the
|
|
407
|
-
next run; adding it back recounts them without counting anything twice.
|
|
408
|
-
|
|
409
403
|
**Adding a provider.** Add an entry to `SOURCES` in `src/collector.mjs`, the provider id to
|
|
410
404
|
`PROVIDERS` in `src/schema.ts`, a row to the table above, and a test with a fixture log. The entry
|
|
411
405
|
says where the data lives, how it is read, and which LiteLLM keys price its models. Append-only JSONL
|
package/dist/collector.mjs
CHANGED
|
@@ -18,12 +18,11 @@
|
|
|
18
18
|
// node collector.mjs --reset # forget local state and rescan everything
|
|
19
19
|
//
|
|
20
20
|
// Env: BIG_SPENDER_DEVICE_ID, BIG_SPENDER_INGEST_URL, BIG_SPENDER_INGEST_TOKEN and optionally
|
|
21
|
-
// BIG_SPENDER_CURSOR_API_KEY
|
|
22
|
-
// templates/env.example).
|
|
21
|
+
// BIG_SPENDER_CURSOR_API_KEY and BIG_SPENDER_POLL_LIMITS=off (see templates/env.example).
|
|
23
22
|
// The older USAGE_* names are still read when the new one is unset.
|
|
24
23
|
|
|
25
24
|
import { createHash } from 'node:crypto';
|
|
26
|
-
import { createReadStream, existsSync, readFileSync, statSync } from 'node:fs';
|
|
25
|
+
import { createReadStream, existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
27
26
|
import {
|
|
28
27
|
mkdir,
|
|
29
28
|
open,
|
|
@@ -1360,10 +1359,9 @@ function geminiEvents(path, text, mtimeMs) {
|
|
|
1360
1359
|
/**
|
|
1361
1360
|
* Gemini rewrites its files, so a changed file is read whole and what it counts now replaces
|
|
1362
1361
|
* what it counted before, as ccusage counts each file as it is. `state.seen` keeps each file's
|
|
1363
|
-
* counts per hour, model, tier and session so they can be taken back
|
|
1364
|
-
*
|
|
1365
|
-
*
|
|
1366
|
-
* zero row.
|
|
1362
|
+
* counts per hour, model, tier and session so they can be taken back. A message updated,
|
|
1363
|
+
* corrected or removed in the file changes the count with it, and an hour or model it leaves is
|
|
1364
|
+
* sent as a zero row.
|
|
1367
1365
|
* @type {Source['read']}
|
|
1368
1366
|
*/
|
|
1369
1367
|
async function readGemini(paths, ctx, provider) {
|
|
@@ -1530,6 +1528,23 @@ const ANTIGRAVITY_ROOTS = [
|
|
|
1530
1528
|
];
|
|
1531
1529
|
const ANTIGRAVITY_DEFAULT_MODEL = 'gemini-internal-model';
|
|
1532
1530
|
|
|
1531
|
+
/**
|
|
1532
|
+
* T3 Code runs Antigravity with a profile per provider instance, named by the instance id's
|
|
1533
|
+
* SHA-256, under the state dir of its home: `userdata`, or `dev` for a development build.
|
|
1534
|
+
*/
|
|
1535
|
+
function t3AntigravityDirs(t3Home) {
|
|
1536
|
+
return ['userdata', 'dev'].flatMap((stateDir) => {
|
|
1537
|
+
const profiles = join(t3Home, stateDir, 'providers', 'antigravity');
|
|
1538
|
+
let names;
|
|
1539
|
+
try {
|
|
1540
|
+
names = readdirSync(profiles);
|
|
1541
|
+
} catch {
|
|
1542
|
+
return [];
|
|
1543
|
+
}
|
|
1544
|
+
return names.map((name) => join(profiles, name, 'antigravity-acp', 'conversations'));
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1533
1548
|
const isDir = (path) => {
|
|
1534
1549
|
try {
|
|
1535
1550
|
return statSync(path).isDirectory();
|
|
@@ -1538,12 +1553,14 @@ const isDir = (path) => {
|
|
|
1538
1553
|
}
|
|
1539
1554
|
};
|
|
1540
1555
|
|
|
1541
|
-
const antigravityEnvDirs = () =>
|
|
1542
|
-
(process.env.ANTIGRAVITY_DATA_DIR ?? '')
|
|
1556
|
+
const antigravityEnvDirs = () => [
|
|
1557
|
+
...(process.env.ANTIGRAVITY_DATA_DIR ?? '')
|
|
1543
1558
|
.split(',')
|
|
1544
1559
|
.map((root) => root.trim())
|
|
1545
1560
|
.filter(Boolean)
|
|
1546
|
-
.map((root) => (isDir(join(root, 'conversations')) ? join(root, 'conversations') : root))
|
|
1561
|
+
.map((root) => (isDir(join(root, 'conversations')) ? join(root, 'conversations') : root)),
|
|
1562
|
+
...(process.env.T3CODE_HOME?.trim() ? t3AntigravityDirs(process.env.T3CODE_HOME.trim()) : [])
|
|
1563
|
+
];
|
|
1547
1564
|
|
|
1548
1565
|
function byPathComponents(a, b) {
|
|
1549
1566
|
const x = a.split(sep);
|
|
@@ -2433,8 +2450,7 @@ async function readOpenCode(paths, ctx, provider) {
|
|
|
2433
2450
|
* paths: string[],
|
|
2434
2451
|
* envPaths: () => string[],
|
|
2435
2452
|
* read: (paths: string[], ctx: ReadContext, provider: string) => Promise<void>,
|
|
2436
|
-
* priceKeys: (model: string) => string[]
|
|
2437
|
-
* experimental?: boolean
|
|
2453
|
+
* priceKeys: (model: string) => string[]
|
|
2438
2454
|
* }} Source
|
|
2439
2455
|
*/
|
|
2440
2456
|
|
|
@@ -2451,7 +2467,6 @@ async function readOpenCode(paths, ctx, provider) {
|
|
|
2451
2467
|
* data whole on every run and skips what it counted before through `state.seen`, keyed with a
|
|
2452
2468
|
* provider prefix and valued with the record's timestamp so pruneState can drop it.
|
|
2453
2469
|
* - `priceKeys`: the LiteLLM keys to try for a model, in order.
|
|
2454
|
-
* - `experimental`: read only when BIG_SPENDER_EXPERIMENTAL names it; see enabledSources.
|
|
2455
2470
|
*
|
|
2456
2471
|
* @type {Record<string, Source>}
|
|
2457
2472
|
*/
|
|
@@ -2529,14 +2544,15 @@ const SOURCES = {
|
|
|
2529
2544
|
}
|
|
2530
2545
|
},
|
|
2531
2546
|
antigravity: {
|
|
2532
|
-
|
|
2533
|
-
|
|
2547
|
+
paths: [
|
|
2548
|
+
...ANTIGRAVITY_ROOTS.map((root) => join(HOME, root, 'conversations')),
|
|
2549
|
+
...t3AntigravityDirs(join(HOME, '.t3'))
|
|
2550
|
+
],
|
|
2534
2551
|
envPaths: antigravityEnvDirs,
|
|
2535
2552
|
read: readAntigravity,
|
|
2536
2553
|
priceKeys: antigravityPriceKeys
|
|
2537
2554
|
},
|
|
2538
2555
|
gemini: {
|
|
2539
|
-
experimental: true,
|
|
2540
2556
|
paths: [join(HOME, '.gemini', 'tmp')],
|
|
2541
2557
|
envPaths: () =>
|
|
2542
2558
|
(process.env.GEMINI_DATA_DIR ?? '')
|
|
@@ -2564,16 +2580,6 @@ const SOURCES = {
|
|
|
2564
2580
|
}
|
|
2565
2581
|
};
|
|
2566
2582
|
|
|
2567
|
-
// An experimental source has not been checked against real usage yet, so it is read and sent only
|
|
2568
|
-
// when BIG_SPENDER_EXPERIMENTAL (comma-separated provider ids) names it. Turned off, its counted rows
|
|
2569
|
-
// stay in the state, so turning it on again replaces them instead of counting them twice.
|
|
2570
|
-
function enabledSources() {
|
|
2571
|
-
const optIn = new Set(
|
|
2572
|
-
(process.env.BIG_SPENDER_EXPERIMENTAL ?? '').split(',').map((id) => id.trim())
|
|
2573
|
-
);
|
|
2574
|
-
return Object.entries(SOURCES).filter(([id, source]) => !source.experimental || optIn.has(id));
|
|
2575
|
-
}
|
|
2576
|
-
|
|
2577
2583
|
/** @param {[string, Source][]} sources */
|
|
2578
2584
|
async function scan(state, resolvePrice, cutoffMs, sources, polled) {
|
|
2579
2585
|
/** @type {ReadContext} */
|
|
@@ -3077,14 +3083,14 @@ async function main() {
|
|
|
3077
3083
|
const resolvePrice = makePriceResolver(pricing.models);
|
|
3078
3084
|
const state = await loadState();
|
|
3079
3085
|
pruneState(state, coverageStartMs);
|
|
3080
|
-
const sources =
|
|
3081
|
-
const
|
|
3086
|
+
const sources = Object.entries(SOURCES);
|
|
3087
|
+
const known = new Set(Object.keys(SOURCES));
|
|
3082
3088
|
const polled = await pollLimits(state, nowMs);
|
|
3083
3089
|
await scan(state, resolvePrice, coverageStartMs, sources, polled);
|
|
3084
3090
|
await saveState(state);
|
|
3085
3091
|
|
|
3086
3092
|
const buckets = Object.fromEntries(
|
|
3087
|
-
Object.entries(state.buckets).filter(([key]) =>
|
|
3093
|
+
Object.entries(state.buckets).filter(([key]) => known.has(key.split('|')[1]))
|
|
3088
3094
|
);
|
|
3089
3095
|
const used = new Set(Object.keys(buckets).map((k) => k.split('|')[1]));
|
|
3090
3096
|
const device = buildSnapshot(
|
|
@@ -3095,7 +3101,7 @@ async function main() {
|
|
|
3095
3101
|
pricingSource: `litellm@${new Date(pricing.fetchedAt).toISOString().slice(0, 10)}`,
|
|
3096
3102
|
// Older servers require the claude and codex counts and reject any other key, so another
|
|
3097
3103
|
// provider's count is sent only once this device has used it.
|
|
3098
|
-
providers: [...
|
|
3104
|
+
providers: [...known].filter((p) => p === 'claude' || p === 'codex' || used.has(p)),
|
|
3099
3105
|
nowMs,
|
|
3100
3106
|
coverageStartMs,
|
|
3101
3107
|
limits: state.limits
|
package/package.json
CHANGED
package/templates/env.example
CHANGED
|
@@ -10,9 +10,6 @@ BIG_SPENDER_INGEST_TOKEN=
|
|
|
10
10
|
# Optional, on one machine only: a Cursor user API key. The collector then reads the account's
|
|
11
11
|
# usage from Cursor's API and sends it as the device "cursor". Set by `big-spender install --cursor`.
|
|
12
12
|
# BIG_SPENDER_CURSOR_API_KEY=
|
|
13
|
-
# Optional: experimental sources to read too, comma-separated. Their counts match ccusage on test
|
|
14
|
-
# data but have not been checked against real usage yet. Available: antigravity, gemini.
|
|
15
|
-
# BIG_SPENDER_EXPERIMENTAL=antigravity
|
|
16
13
|
# Optional: set to off to stop the collector asking Anthropic and OpenAI how full your Claude and
|
|
17
14
|
# Codex limit windows are. It reads the agents' own login files read-only and only sends the token to
|
|
18
15
|
# that provider.
|