vibeusage 0.2.10 → 0.2.12

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.12",
4
4
  "description": "Codex CLI token usage tracker (macOS-first, notify-driven).",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -51,6 +51,7 @@ const ASCII_LOGO = [
51
51
  ].join('\n');
52
52
 
53
53
  const DIVIDER = '----------------------------------------------';
54
+ const DEFAULT_DASHBOARD_URL = 'https://www.vibeusage.cc';
54
55
 
55
56
  async function cmdInit(argv) {
56
57
  const opts = parseArgs(argv);
@@ -69,7 +70,7 @@ async function cmdInit(argv) {
69
70
  let dashboardUrl = opts.dashboardUrl ||
70
71
  process.env.VIBEUSAGE_DASHBOARD_URL ||
71
72
  process.env.VIBESCORE_DASHBOARD_URL ||
72
- null;
73
+ DEFAULT_DASHBOARD_URL;
73
74
  const notifyPath = path.join(binDir, 'notify.cjs');
74
75
  const appDir = path.join(trackerDir, 'app');
75
76
  const trackerBinPath = path.join(appDir, 'bin', 'tracker.js');
@@ -140,7 +141,6 @@ async function cmdInit(argv) {
140
141
 
141
142
  if (setup.pendingBrowserAuth) {
142
143
  const deviceName = opts.deviceName || os.hostname();
143
- if (!dashboardUrl) dashboardUrl = await detectLocalDashboardUrl();
144
144
  const flow = await beginBrowserAuth({ baseUrl, dashboardUrl, timeoutMs: 10 * 60_000, open: false });
145
145
  const canAutoOpen = !opts.noOpen;
146
146
  renderAuthTransition({ authUrl: flow.authUrl, canAutoOpen });
@@ -157,7 +157,6 @@ async function cmdInit(argv) {
157
157
  const resolvedDashboardUrl = dashboardUrl || null;
158
158
  renderSuccessBox({ configPath, dashboardUrl: resolvedDashboardUrl });
159
159
  } else if (deviceToken) {
160
- if (!dashboardUrl) dashboardUrl = await detectLocalDashboardUrl();
161
160
  const resolvedDashboardUrl = dashboardUrl || null;
162
161
  renderSuccessBox({ configPath, dashboardUrl: resolvedDashboardUrl });
163
162
  } else {
@@ -686,35 +685,6 @@ function isSelfNotify(cmd) {
686
685
 
687
686
  module.exports = { cmdInit };
688
687
 
689
- async function detectLocalDashboardUrl() {
690
- // Dev-only convenience: prefer a local dashboard (if running) so the user sees our own UI first.
691
- // Vite defaults to 5173, but may auto-increment if the port is taken.
692
- const hosts = ['127.0.0.1', 'localhost'];
693
- const ports = [5173, 5174, 5175, 5176, 5177];
694
-
695
- for (const port of ports) {
696
- for (const host of hosts) {
697
- const base = `http://${host}:${port}`;
698
- const ok = await checkUrlReachable(base);
699
- if (ok) return base;
700
- }
701
- }
702
- return null;
703
- }
704
-
705
- async function checkUrlReachable(url) {
706
- const timeoutMs = 250;
707
- try {
708
- const controller = new AbortController();
709
- const t = setTimeout(() => controller.abort(), timeoutMs);
710
- const res = await fetch(url, { method: 'GET', signal: controller.signal });
711
- clearTimeout(t);
712
- return Boolean(res && res.ok);
713
- } catch (_e) {
714
- return false;
715
- }
716
- }
717
-
718
688
  async function probeFile(p) {
719
689
  try {
720
690
  const st = await fs.stat(p);
@@ -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;