vibeusage 0.2.10 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibeusage",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "Codex CLI token usage tracker (macOS-first, notify-driven).",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -1,6 +1,14 @@
1
1
  'use strict';
2
2
 
3
- const { createClient } = require('@insforge/sdk');
3
+ function loadInsforgeSdk() {
4
+ try {
5
+ return require('@insforge/sdk');
6
+ } catch (err) {
7
+ const wrapped = new Error('Missing dependency @insforge/sdk. Please reinstall vibeusage.');
8
+ wrapped.cause = err;
9
+ throw wrapped;
10
+ }
11
+ }
4
12
 
5
13
  function getAnonKey({ env = process.env } = {}) {
6
14
  return (
@@ -44,6 +52,7 @@ function createTimeoutFetch(baseFetch) {
44
52
 
45
53
  function createInsforgeClient({ baseUrl, accessToken } = {}) {
46
54
  if (!baseUrl) throw new Error('Missing baseUrl');
55
+ const { createClient } = loadInsforgeSdk();
47
56
  const anonKey = getAnonKey();
48
57
  return createClient({
49
58
  baseUrl,
@@ -606,7 +606,9 @@ async function parseOpencodeMessageFile({
606
606
 
607
607
  const messageKey = deriveOpencodeMessageKey(msg, filePath);
608
608
  const prev = messageIndex && messageKey ? messageIndex[messageKey] : null;
609
- const lastTotals = prev && typeof prev.lastTotals === 'object' ? prev.lastTotals : legacyTotals;
609
+ const indexTotals = prev && typeof prev.lastTotals === 'object' ? prev.lastTotals : null;
610
+ const fallbackMatch = !fallbackKey || fallbackKey === messageKey;
611
+ const lastTotals = indexTotals || (fallbackMatch ? fallbackLastTotals : null);
610
612
 
611
613
  const currentTotals = normalizeOpencodeTokens(msg?.tokens);
612
614
  if (!currentTotals) {
@@ -1200,10 +1202,12 @@ function normalizeOpencodeTokens(tokens) {
1200
1202
  const output = toNonNegativeInt(tokens.output);
1201
1203
  const reasoning = toNonNegativeInt(tokens.reasoning);
1202
1204
  const cached = toNonNegativeInt(tokens.cache?.read);
1203
- const total = input + output + reasoning;
1205
+ const cacheWrite = toNonNegativeInt(tokens.cache?.write);
1206
+ const inputTokens = input + cacheWrite;
1207
+ const total = inputTokens + output + reasoning;
1204
1208
 
1205
1209
  return {
1206
- input_tokens: input,
1210
+ input_tokens: inputTokens,
1207
1211
  cached_input_tokens: cached,
1208
1212
  output_tokens: output,
1209
1213
  reasoning_output_tokens: reasoning,
@@ -1303,7 +1307,7 @@ function normalizeUsage(u) {
1303
1307
  }
1304
1308
 
1305
1309
  function normalizeClaudeUsage(u) {
1306
- const inputTokens = toNonNegativeInt(u?.input_tokens);
1310
+ const inputTokens = toNonNegativeInt(u?.input_tokens) + toNonNegativeInt(u?.cache_creation_input_tokens);
1307
1311
  const outputTokens = toNonNegativeInt(u?.output_tokens);
1308
1312
  const hasTotal = u && Object.prototype.hasOwnProperty.call(u, 'total_tokens');
1309
1313
  const totalTokens = hasTotal ? toNonNegativeInt(u?.total_tokens) : inputTokens + outputTokens;