big-spender 0.10.0 → 0.11.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 +3 -2
- package/dist/collector.mjs +260 -2
- package/dist/history.js +10 -0
- package/dist/schema.d.ts +9 -1
- package/dist/schema.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -338,7 +338,8 @@ about 15 to 20 percent less.
|
|
|
338
338
|
| Antigravity (experimental) | `~/.gemini/antigravity*/conversations/**/*.db`, `~/.config/antigravity/conversations` | **Experimental:** read only with `BIG_SPENDER_EXPERIMENTAL=antigravity`; checked against ccusage on test fixtures, not yet against real Antigravity data. `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. |
|
|
339
339
|
| Gemini CLI (experimental) | `~/.gemini/tmp/**/*.json` and `*.jsonl`, `$GEMINI_DATA_DIR` (comma-separated) | **Experimental:** read only with `BIG_SPENDER_EXPERIMENTAL=gemini`; 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. |
|
|
340
340
|
|
|
341
|
-
**Pricing.** Claude Code, Codex, pi, Grok Build, GitHub Copilot CLI, Antigravity
|
|
341
|
+
**Pricing.** Claude Code, Codex, pi, Grok Build, GitHub Copilot CLI, Antigravity, Gemini CLI and OpenCode use LiteLLM
|
|
342
|
+
| 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. |
|
|
342
343
|
`model_prices_and_context_window.json`, cached for 24 hours in `~/.cache/big-spender/`. Each source lists the LiteLLM keys to try for a model. Claude
|
|
343
344
|
Code and Codex try the exact model, then the `anthropic/` or `openai/` prefix, then without a date
|
|
344
345
|
suffix. pi tries the LiteLLM prefixes of the providers pi supports too (`openrouter/`, `fireworks_ai/`,
|
|
@@ -352,7 +353,7 @@ Gemini CLI tries `gemini/`, `vertex_ai/` and `openrouter/google/`, then the bare
|
|
|
352
353
|
Gemini from models.dev's `google/` entries first, and for `gemini-2.5-flash` that entry is $0.15
|
|
353
354
|
input and $1.25 output per million tokens, half of LiteLLM's (and models.dev's own `gemini/` entry)
|
|
354
355
|
$0.30 and $2.50. So ccusage shows about half the collector's cost for that model.
|
|
355
|
-
Unknown models count with cost 0 and log a warning.
|
|
356
|
+
OpenCode tries the model, then under the upstream provider it ran on. Unknown models count with cost 0 and log a warning.
|
|
356
357
|
Long-context tiers
|
|
357
358
|
(`*_above_<N>k_tokens`) are applied per request; a missing cache price is derived from the base
|
|
358
359
|
input price, also above a tier, as ccusage does. 1-hour cache writes use
|
package/dist/collector.mjs
CHANGED
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
writeFile
|
|
36
36
|
} from 'node:fs/promises';
|
|
37
37
|
import { homedir } from 'node:os';
|
|
38
|
-
import { basename, dirname, extname, join, resolve, sep } from 'node:path';
|
|
38
|
+
import { basename, dirname, extname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
39
39
|
import { gzipSync } from 'node:zlib';
|
|
40
40
|
|
|
41
41
|
const SCHEMA_VERSION = 1;
|
|
@@ -136,7 +136,9 @@ async function acquireLock() {
|
|
|
136
136
|
* A bare number on a Claude key means the counted output is unknown (state from an older version).
|
|
137
137
|
* Antigravity keeps a merged response under each of its ids: see agStoreGroup.
|
|
138
138
|
* Gemini keeps a file's counts under `gm:` and its path: [latest hour, counts]; see readGemini.
|
|
139
|
-
*
|
|
139
|
+
* For OpenCode it is [timestamp, tier, input, output, cache read, cache write, model, upstream,
|
|
140
|
+
* session].
|
|
141
|
+
* @typedef {number | [number, number] | [number, string] | [number, number, string, ...(number | string)[]] | [number, Record<string, any>] | (number | string)[]} Seen
|
|
140
142
|
* One subscription usage window instance; see limitWindowSchema in src/schema.ts.
|
|
141
143
|
* @typedef {{ provider: string, window: string, resetsAt: string, peakPercent: number, hitAt?: string }} Limit
|
|
142
144
|
* @typedef {{ version: number, files: Record<string, FileState>, seen: Record<string, Seen>, buckets: Record<string, Bucket>, limits?: Record<string, Limit>, fixes?: string[], rescan?: string[], cursorBackfills?: string[] }} State
|
|
@@ -1898,6 +1900,249 @@ function antigravityPriceKeys(model) {
|
|
|
1898
1900
|
return [...names].flatMap((name) => prefixes.map((prefix) => prefix + name));
|
|
1899
1901
|
}
|
|
1900
1902
|
|
|
1903
|
+
// OpenCode keeps one record per assistant message and rewrites it while the message runs: in
|
|
1904
|
+
// SQLite (`message` in 1.x; `session_message` from 2.0, which copies the 1.x rows under the same
|
|
1905
|
+
// ids) and, before SQLite, in `storage/message/<session>/<message>.json`. A message id counts
|
|
1906
|
+
// from the first store that has it, 1.x rows first, so every `session_message` row left was
|
|
1907
|
+
// written by 2.x.
|
|
1908
|
+
|
|
1909
|
+
/**
|
|
1910
|
+
* @typedef {{ id: string, session: string, ts: number, model: string, upstream: string, tokens: any, separateReasoning: boolean }} OpenCodeMessage
|
|
1911
|
+
*/
|
|
1912
|
+
|
|
1913
|
+
/** @type {Map<string, string>} */
|
|
1914
|
+
const opencodeUpstreams = new Map();
|
|
1915
|
+
|
|
1916
|
+
const OPENCODE_ALIASES = new Map([
|
|
1917
|
+
['gemini-3-pro-high', 'gemini-3-pro-preview'],
|
|
1918
|
+
['k2p6', 'kimi-k2.6']
|
|
1919
|
+
]);
|
|
1920
|
+
const CLAUDE_DOTTED = /^(claude-(?:haiku|opus|sonnet)-)(\d+)\.(\d)/;
|
|
1921
|
+
|
|
1922
|
+
function opencodePriceKeys(model) {
|
|
1923
|
+
const resolved = OPENCODE_ALIASES.get(model) ?? model;
|
|
1924
|
+
// LiteLLM spells claude-opus-4.5 and claude-opus-45 as claude-opus-4-5.
|
|
1925
|
+
const normalized = CLAUDE_DOTTED.test(resolved)
|
|
1926
|
+
? resolved.replace(CLAUDE_DOTTED, '$1$2-$3')
|
|
1927
|
+
: resolved.replace(/^(claude-(?:haiku|opus|sonnet)-\d)(\d)/, '$1-$2');
|
|
1928
|
+
const bases = [...new Set([resolved, normalized])];
|
|
1929
|
+
const upstream = opencodeUpstreams.get(model);
|
|
1930
|
+
// The upstream as ccusage spells it (zai_coding_plan), then its first word (zai).
|
|
1931
|
+
const prefixes = upstream
|
|
1932
|
+
? [...new Set([upstream.replaceAll('-', '_'), upstream.split('-')[0]])]
|
|
1933
|
+
: [];
|
|
1934
|
+
return [...bases, ...prefixes.flatMap((p) => bases.map((b) => `${p}/${b}`))];
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
/**
|
|
1938
|
+
* Cache reads and writes are outside `input`. OpenCode 1.x counts reasoning inside `output` and
|
|
1939
|
+
* records `total`. 2.x stores the visible output only (`output` minus reasoning) and no `total`,
|
|
1940
|
+
* so its reasoning is added back.
|
|
1941
|
+
*/
|
|
1942
|
+
function opencodeTokens(t, separateReasoning) {
|
|
1943
|
+
const input = num(t?.input);
|
|
1944
|
+
const cacheRead = num(t?.cache?.read);
|
|
1945
|
+
const cacheWrite = num(t?.cache?.write);
|
|
1946
|
+
let output = num(t?.output);
|
|
1947
|
+
const total = num(t?.total);
|
|
1948
|
+
if (total) output = Math.max(output, total - input - cacheRead - cacheWrite);
|
|
1949
|
+
else if (separateReasoning) output += num(t?.reasoning);
|
|
1950
|
+
return { input, output, cacheRead, cacheWrite };
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
async function opencodeDbPath(dir) {
|
|
1954
|
+
if (existsSync(join(dir, 'opencode.db'))) return join(dir, 'opencode.db');
|
|
1955
|
+
const names = await readdir(dir).catch(() => []);
|
|
1956
|
+
const channel = names.filter((n) => /^opencode-[A-Za-z0-9_-]+\.db$/.test(n)).sort()[0];
|
|
1957
|
+
return channel ? join(dir, channel) : null;
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
function readOpenCodeDb(db, sinceMs, out) {
|
|
1961
|
+
const columns = (table) =>
|
|
1962
|
+
new Set(
|
|
1963
|
+
db
|
|
1964
|
+
.prepare('SELECT name FROM pragma_table_info(?)')
|
|
1965
|
+
.all(table)
|
|
1966
|
+
.map((r) => r.name)
|
|
1967
|
+
);
|
|
1968
|
+
const add = (r, separateReasoning) => {
|
|
1969
|
+
if (out.has(r.id)) return;
|
|
1970
|
+
out.set(r.id, { ...r, tokens: parseJson(r.tokens ?? 'null'), separateReasoning });
|
|
1971
|
+
};
|
|
1972
|
+
const v1 = columns('message');
|
|
1973
|
+
if (v1.has('data')) {
|
|
1974
|
+
const since = v1.has('time_created') ? 'time_created >= ? AND' : '';
|
|
1975
|
+
const rows = db
|
|
1976
|
+
.prepare(
|
|
1977
|
+
`SELECT id, session_id AS session, json_extract(data, '$.time.created') AS ts,
|
|
1978
|
+
json_extract(data, '$.modelID') AS model, json_extract(data, '$.providerID') AS upstream,
|
|
1979
|
+
json_extract(data, '$.tokens') AS tokens
|
|
1980
|
+
FROM message WHERE ${since} json_valid(data)`
|
|
1981
|
+
)
|
|
1982
|
+
.all(...(since ? [sinceMs] : []));
|
|
1983
|
+
for (const r of rows) add(r, false);
|
|
1984
|
+
}
|
|
1985
|
+
const v2 = columns('session_message');
|
|
1986
|
+
if (!v2.has('data') || !v2.has('type')) return;
|
|
1987
|
+
const sessions = columns('session_v2');
|
|
1988
|
+
// A 2.x fork starts with copies of its parent's rows, made when the fork is, that keep the
|
|
1989
|
+
// parent rows' time_created. OpenCode's own usage stats skip them the same way, and this needs
|
|
1990
|
+
// no parent row, so it holds after the parent is deleted.
|
|
1991
|
+
const forks =
|
|
1992
|
+
v2.has('time_created') && sessions.has('fork_session_id') && sessions.has('time_created');
|
|
1993
|
+
const since = v2.has('time_created') ? 'm.time_created >= ? AND' : '';
|
|
1994
|
+
const rows = db
|
|
1995
|
+
.prepare(
|
|
1996
|
+
`SELECT m.id, m.session_id AS session,
|
|
1997
|
+
coalesce(json_extract(m.data, '$.time.created'), ${v2.has('time_created') ? 'm.time_created' : 'NULL'}) AS ts,
|
|
1998
|
+
coalesce(json_extract(m.data, '$.model.id'), json_extract(m.data, '$.model.modelID'),
|
|
1999
|
+
json_extract(m.data, '$.modelID')) AS model,
|
|
2000
|
+
coalesce(json_extract(m.data, '$.model.providerID'), json_extract(m.data, '$.providerID')) AS upstream,
|
|
2001
|
+
json_extract(m.data, '$.tokens') AS tokens
|
|
2002
|
+
FROM session_message m
|
|
2003
|
+
${forks ? 'LEFT JOIN session_v2 s ON s.id = m.session_id' : ''}
|
|
2004
|
+
WHERE ${since} json_valid(m.data) AND (m.type = 'assistant'
|
|
2005
|
+
OR (m.type = 'compaction' AND json_extract(m.data, '$.status') = 'completed'))
|
|
2006
|
+
${forks ? 'AND (s.fork_session_id IS NULL OR m.time_created >= s.time_created)' : ''}`
|
|
2007
|
+
)
|
|
2008
|
+
.all(...(since ? [sinceMs] : []));
|
|
2009
|
+
for (const r of rows) add(r, true);
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
async function readOpenCodeFiles(dir, sinceMs, out) {
|
|
2013
|
+
for await (const path of walk(join(dir, 'storage', 'message'), (name) =>
|
|
2014
|
+
name.endsWith('.json')
|
|
2015
|
+
)) {
|
|
2016
|
+
if (out.has(basename(path, '.json'))) continue;
|
|
2017
|
+
const st = await stat(path).catch(() => null);
|
|
2018
|
+
if (!st || st.mtimeMs < sinceMs) continue;
|
|
2019
|
+
const o = parseJson(await readFile(path, 'utf8').catch(() => ''));
|
|
2020
|
+
const id = typeof o?.id === 'string' ? o.id : basename(path, '.json');
|
|
2021
|
+
if (!o || out.has(id)) continue;
|
|
2022
|
+
out.set(id, {
|
|
2023
|
+
id,
|
|
2024
|
+
session: o.sessionID,
|
|
2025
|
+
ts: o.time?.created,
|
|
2026
|
+
model: o.modelID,
|
|
2027
|
+
upstream: o.providerID,
|
|
2028
|
+
tokens: o.tokens,
|
|
2029
|
+
separateReasoning: false
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
const MODEL_FILE = /\.(?:gguf|ggml|bin|safetensors|onnx|pt|pth|ckpt|llamafile)$/i;
|
|
2035
|
+
|
|
2036
|
+
/**
|
|
2037
|
+
* A local model can be named by its path or a URL, which can carry a login, a query or a folder
|
|
2038
|
+
* name. Only a file name leaves the machine; an address without one becomes `local`.
|
|
2039
|
+
*/
|
|
2040
|
+
function opencodeModelName(id) {
|
|
2041
|
+
const scheme = /^[A-Za-z][A-Za-z0-9+.-]*:/.exec(id)?.[0] ?? '';
|
|
2042
|
+
const rest = id.slice(scheme.length);
|
|
2043
|
+
// `scheme:/...`, `//host/...`, or anything with a query, fragment or login after a scheme.
|
|
2044
|
+
const address = /^[/\\]{2}/.test(rest) || (scheme !== '' && /^[/\\]|[?#@]/.test(rest));
|
|
2045
|
+
const path = address || /^[/~.\\]|\\/.test(rest) || (rest.includes('/') && MODEL_FILE.test(rest));
|
|
2046
|
+
const clean = (name) => name.replace(/[^A-Za-z0-9._:/@-]/g, '-').slice(0, 100);
|
|
2047
|
+
if (!path) return clean(id.replace(/[?#].*$/s, ''));
|
|
2048
|
+
const local = address ? rest.replace(/[?#].*$/s, '').replace(/^[/\\]{2}[^/\\]*/, '') : rest;
|
|
2049
|
+
const name = local
|
|
2050
|
+
.split(/[/\\]/)
|
|
2051
|
+
.pop()
|
|
2052
|
+
.replace(/[?#].*$/s, '');
|
|
2053
|
+
return clean(!name || name.includes('@') ? 'local' : name);
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
function countOpenCode(ctx, provider, m) {
|
|
2057
|
+
if (typeof m.model !== 'string' || !m.model || typeof m.upstream !== 'string') return;
|
|
2058
|
+
// Claude Code writes its own transcript of these turns, and the claude source reads it.
|
|
2059
|
+
if (m.upstream === 'claude-agent') return;
|
|
2060
|
+
const ts = Number(m.ts);
|
|
2061
|
+
if (!Number.isFinite(ts) || ts < ctx.cutoffMs) return;
|
|
2062
|
+
|
|
2063
|
+
const model = opencodeModelName(m.model);
|
|
2064
|
+
if (!opencodeUpstreams.has(model)) opencodeUpstreams.set(model, m.upstream);
|
|
2065
|
+
const t = opencodeTokens(m.tokens, m.separateReasoning);
|
|
2066
|
+
const session = shortHash(`opencode:${m.session ?? 'unknown'}`);
|
|
2067
|
+
const counted =
|
|
2068
|
+
t.input || t.output || t.cacheRead || t.cacheWrite
|
|
2069
|
+
? [
|
|
2070
|
+
ts,
|
|
2071
|
+
tierFor(ctx.resolvePrice(provider, model), t.input + t.cacheRead + t.cacheWrite),
|
|
2072
|
+
t.input,
|
|
2073
|
+
t.output,
|
|
2074
|
+
t.cacheRead,
|
|
2075
|
+
t.cacheWrite,
|
|
2076
|
+
model,
|
|
2077
|
+
m.upstream,
|
|
2078
|
+
session
|
|
2079
|
+
]
|
|
2080
|
+
: null;
|
|
2081
|
+
const key = `o:${shortHash(m.id)}`;
|
|
2082
|
+
const prev = Array.isArray(ctx.state.seen[key]) ? ctx.state.seen[key] : null;
|
|
2083
|
+
if (!prev ? !counted : counted?.every((v, i) => v === prev[i])) return;
|
|
2084
|
+
|
|
2085
|
+
const add = ([at, tier, input, output, cacheRead, cacheWrite, modelAt = model], sign) => {
|
|
2086
|
+
addRecord(ctx.state, {
|
|
2087
|
+
ts: at,
|
|
2088
|
+
provider,
|
|
2089
|
+
model: modelAt,
|
|
2090
|
+
tier,
|
|
2091
|
+
session,
|
|
2092
|
+
input: sign * input,
|
|
2093
|
+
cacheRead: sign * cacheRead,
|
|
2094
|
+
cacheWrite5m: sign * cacheWrite,
|
|
2095
|
+
cacheWrite1h: 0,
|
|
2096
|
+
output: sign * output
|
|
2097
|
+
});
|
|
2098
|
+
};
|
|
2099
|
+
if (prev) add(prev, -1);
|
|
2100
|
+
if (counted) {
|
|
2101
|
+
add(counted, 1);
|
|
2102
|
+
ctx.state.seen[key] = counted;
|
|
2103
|
+
} else delete ctx.state.seen[key];
|
|
2104
|
+
// The session leaves the bucket the message left, unless another of its messages is there.
|
|
2105
|
+
const bucketOf = (c) => bucketKey(Math.floor(c[0] / HOUR_MS) * HOUR_MS, provider, c[6], c[1]);
|
|
2106
|
+
const left = prev && bucketOf(prev);
|
|
2107
|
+
if (left && (!counted || bucketOf(counted) !== left) && ctx.state.buckets[left]) {
|
|
2108
|
+
const stays = Object.entries(ctx.state.seen).some(
|
|
2109
|
+
([k, v]) => k.startsWith('o:') && Array.isArray(v) && v[8] === session && bucketOf(v) === left
|
|
2110
|
+
);
|
|
2111
|
+
if (!stays) {
|
|
2112
|
+
const b = ctx.state.buckets[left];
|
|
2113
|
+
b.sessions = b.sessions.filter((s) => s !== session);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
async function readOpenCode(paths, ctx, provider) {
|
|
2119
|
+
// Usage kept from messages no longer on disk still needs its upstream to be priced.
|
|
2120
|
+
for (const [key, v] of Object.entries(ctx.state.seen)) {
|
|
2121
|
+
if (key.startsWith('o:') && Array.isArray(v) && !opencodeUpstreams.has(v[6])) {
|
|
2122
|
+
if (typeof v[7] === 'string') opencodeUpstreams.set(v[6], v[7]);
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
if (!paths.length) return;
|
|
2126
|
+
/** @type {Map<string, OpenCodeMessage>} */
|
|
2127
|
+
const messages = new Map();
|
|
2128
|
+
for (const dir of new Set(paths.map((p) => resolve(p)))) {
|
|
2129
|
+
const file = await opencodeDbPath(dir);
|
|
2130
|
+
if (file) {
|
|
2131
|
+
let db;
|
|
2132
|
+
try {
|
|
2133
|
+
db = await openSqlite(file);
|
|
2134
|
+
if (db) readOpenCodeDb(db, ctx.cutoffMs, messages);
|
|
2135
|
+
} catch (err) {
|
|
2136
|
+
log(`skipping unreadable OpenCode database: ${err.message}`);
|
|
2137
|
+
} finally {
|
|
2138
|
+
db?.close();
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
await readOpenCodeFiles(dir, ctx.cutoffMs, messages);
|
|
2142
|
+
}
|
|
2143
|
+
for (const m of messages.values()) countOpenCode(ctx, provider, m);
|
|
2144
|
+
}
|
|
2145
|
+
|
|
1901
2146
|
/**
|
|
1902
2147
|
* @typedef {{ state: State, resolvePrice: (provider: string, model: string) => any, cutoffMs: number, seenPaths: Set<string>, filesRead: number, parsedBytes: number }} ReadContext
|
|
1903
2148
|
* @typedef {{
|
|
@@ -2018,6 +2263,19 @@ const SOURCES = {
|
|
|
2018
2263
|
...['gemini', 'vertex_ai', 'openrouter/google'].map((p) => `${p}/${model}`),
|
|
2019
2264
|
model
|
|
2020
2265
|
]
|
|
2266
|
+
},
|
|
2267
|
+
opencode: {
|
|
2268
|
+
// Its default dir depends on XDG_DATA_HOME and, as in ccusage, OPENCODE_DATA_DIR
|
|
2269
|
+
// (comma-separated) replaces it, so both come from envPaths. No other source reads these files.
|
|
2270
|
+
paths: [],
|
|
2271
|
+
envPaths: () => {
|
|
2272
|
+
const dirs = process.env.OPENCODE_DATA_DIR?.split(',').map((p) => p.trim());
|
|
2273
|
+
if (dirs) return dirs.filter(Boolean);
|
|
2274
|
+
const xdg = process.env.XDG_DATA_HOME;
|
|
2275
|
+
return [join(xdg && isAbsolute(xdg) ? xdg : join(HOME, '.local', 'share'), 'opencode')];
|
|
2276
|
+
},
|
|
2277
|
+
read: readOpenCode,
|
|
2278
|
+
priceKeys: opencodePriceKeys
|
|
2021
2279
|
}
|
|
2022
2280
|
};
|
|
2023
2281
|
|
package/dist/history.js
CHANGED
|
@@ -65,6 +65,16 @@ function dropOldestDays(rows, excess) {
|
|
|
65
65
|
}
|
|
66
66
|
return { rows: rows.slice(cut), days };
|
|
67
67
|
}
|
|
68
|
+
const isEmpty = (r) => !r.sessions &&
|
|
69
|
+
!r.inputTokens &&
|
|
70
|
+
!r.cacheReadTokens &&
|
|
71
|
+
!r.cacheWrite5mTokens &&
|
|
72
|
+
!r.cacheWrite1hTokens &&
|
|
73
|
+
!r.outputTokens &&
|
|
74
|
+
!r.costUsd.input &&
|
|
75
|
+
!r.costUsd.cacheRead &&
|
|
76
|
+
!r.costUsd.cacheWrite &&
|
|
77
|
+
!r.costUsd.output;
|
|
68
78
|
export function mergeSnapshots(stored, next) {
|
|
69
79
|
const sorted = [...next.hourly].sort(compareRows);
|
|
70
80
|
const fresh = sorted.filter(hasTokens);
|
package/dist/schema.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const EARLIEST_DATE = "2020-01-01T00:00:00Z";
|
|
|
3
3
|
export declare const MAX_ROWS = 50000;
|
|
4
4
|
export declare const DEVICE_ID: RegExp;
|
|
5
5
|
export declare const CURSOR_DEVICE_ID = "cursor";
|
|
6
|
-
export declare const PROVIDERS: readonly ['claude', 'codex', 'cursor', 'pi', 'grok', 'copilot', 'antigravity', 'gemini'];
|
|
6
|
+
export declare const PROVIDERS: readonly ['claude', 'codex', 'cursor', 'pi', 'grok', 'copilot', 'antigravity', 'gemini', 'opencode'];
|
|
7
7
|
export declare const RANGES: readonly ['7d', '30d', '90d', 'all'];
|
|
8
8
|
export declare const usageRowSchema: z.ZodObject<{
|
|
9
9
|
hour: z.ZodISODateTime;
|
|
@@ -19,6 +19,7 @@ export declare const usageRowSchema: z.ZodObject<{
|
|
|
19
19
|
cursor: "cursor";
|
|
20
20
|
gemini: "gemini";
|
|
21
21
|
grok: "grok";
|
|
22
|
+
opencode: "opencode";
|
|
22
23
|
pi: "pi";
|
|
23
24
|
}>;
|
|
24
25
|
model: z.ZodString;
|
|
@@ -46,6 +47,7 @@ export declare const limitWindowSchema: z.ZodObject<{
|
|
|
46
47
|
cursor: "cursor";
|
|
47
48
|
gemini: "gemini";
|
|
48
49
|
grok: "grok";
|
|
50
|
+
opencode: "opencode";
|
|
49
51
|
pi: "pi";
|
|
50
52
|
}>;
|
|
51
53
|
window: z.ZodString;
|
|
@@ -73,6 +75,7 @@ export declare const usageSnapshotSchema: z.ZodObject<{
|
|
|
73
75
|
cursor: "cursor";
|
|
74
76
|
gemini: "gemini";
|
|
75
77
|
grok: "grok";
|
|
78
|
+
opencode: "opencode";
|
|
76
79
|
pi: "pi";
|
|
77
80
|
}>;
|
|
78
81
|
model: z.ZodString;
|
|
@@ -101,6 +104,7 @@ export declare const usageSnapshotSchema: z.ZodObject<{
|
|
|
101
104
|
cursor: z.ZodOptional<z.ZodNumber>;
|
|
102
105
|
gemini: z.ZodOptional<z.ZodNumber>;
|
|
103
106
|
grok: z.ZodOptional<z.ZodNumber>;
|
|
107
|
+
opencode: z.ZodOptional<z.ZodNumber>;
|
|
104
108
|
pi: z.ZodOptional<z.ZodNumber>;
|
|
105
109
|
}, z.core.$strict>>;
|
|
106
110
|
'7d': z.ZodObject<{
|
|
@@ -112,6 +116,7 @@ export declare const usageSnapshotSchema: z.ZodObject<{
|
|
|
112
116
|
cursor: z.ZodOptional<z.ZodNumber>;
|
|
113
117
|
gemini: z.ZodOptional<z.ZodNumber>;
|
|
114
118
|
grok: z.ZodOptional<z.ZodNumber>;
|
|
119
|
+
opencode: z.ZodOptional<z.ZodNumber>;
|
|
115
120
|
pi: z.ZodOptional<z.ZodNumber>;
|
|
116
121
|
}, z.core.$strict>;
|
|
117
122
|
'30d': z.ZodObject<{
|
|
@@ -123,6 +128,7 @@ export declare const usageSnapshotSchema: z.ZodObject<{
|
|
|
123
128
|
cursor: z.ZodOptional<z.ZodNumber>;
|
|
124
129
|
gemini: z.ZodOptional<z.ZodNumber>;
|
|
125
130
|
grok: z.ZodOptional<z.ZodNumber>;
|
|
131
|
+
opencode: z.ZodOptional<z.ZodNumber>;
|
|
126
132
|
pi: z.ZodOptional<z.ZodNumber>;
|
|
127
133
|
}, z.core.$strict>;
|
|
128
134
|
'90d': z.ZodObject<{
|
|
@@ -134,6 +140,7 @@ export declare const usageSnapshotSchema: z.ZodObject<{
|
|
|
134
140
|
cursor: z.ZodOptional<z.ZodNumber>;
|
|
135
141
|
gemini: z.ZodOptional<z.ZodNumber>;
|
|
136
142
|
grok: z.ZodOptional<z.ZodNumber>;
|
|
143
|
+
opencode: z.ZodOptional<z.ZodNumber>;
|
|
137
144
|
pi: z.ZodOptional<z.ZodNumber>;
|
|
138
145
|
}, z.core.$strict>;
|
|
139
146
|
}, z.core.$strict>>;
|
|
@@ -146,6 +153,7 @@ export declare const usageSnapshotSchema: z.ZodObject<{
|
|
|
146
153
|
cursor: "cursor";
|
|
147
154
|
gemini: "gemini";
|
|
148
155
|
grok: "grok";
|
|
156
|
+
opencode: "opencode";
|
|
149
157
|
pi: "pi";
|
|
150
158
|
}>;
|
|
151
159
|
window: z.ZodString;
|
package/dist/schema.js
CHANGED
|
@@ -22,7 +22,8 @@ export const PROVIDERS = [
|
|
|
22
22
|
'grok',
|
|
23
23
|
'copilot',
|
|
24
24
|
'antigravity',
|
|
25
|
-
'gemini'
|
|
25
|
+
'gemini',
|
|
26
|
+
'opencode'
|
|
26
27
|
];
|
|
27
28
|
// Public ranges. 7d, 30d and 90d are bucketed by UTC day, `all` by ISO week. Nothing is finer
|
|
28
29
|
// than a day: an hourly view would show when each machine is in use.
|