tokmon 0.15.0 → 0.15.1

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.
@@ -2,6 +2,7 @@
2
2
  import {
3
3
  PROVIDERS,
4
4
  buildAccounts,
5
+ cacheDir,
5
6
  detectProviders,
6
7
  resolveTimezone
7
8
  } from "./chunk-ZPH4754N.js";
@@ -274,9 +275,13 @@ code{color:#e6b450}</style></head><body>
274
275
  </body></html>`;
275
276
 
276
277
  // src/web/data-engine.ts
278
+ import { readFileSync as readFileSync2, writeFileSync, mkdirSync } from "fs";
279
+ import { join as join3 } from "path";
277
280
  var TABLE_INTERVAL_MS = 3e5;
278
281
  var SSE_HEARTBEAT_MS = 25e3;
279
282
  var IDLE_PAUSE_MS = 6e4;
283
+ var SNAPSHOT_CACHE_THROTTLE_MS = 2e4;
284
+ var snapshotCacheFile = () => join3(cacheDir(), "web-snapshot.json");
280
285
  function createDataEngine(opts) {
281
286
  const { version, tz, summaryIntervalMs, billingIntervalMs, resolved } = opts;
282
287
  const usage = /* @__PURE__ */ new Map();
@@ -288,6 +293,7 @@ function createDataEngine(opts) {
288
293
  let summaryTimer;
289
294
  let tableTimer;
290
295
  let billingTimer;
296
+ let lastPersist = 0;
291
297
  const idle = () => sseClients.size === 0 && Date.now() - lastActivity > IDLE_PAUSE_MS;
292
298
  const usageEntry = (id) => {
293
299
  let u = usage.get(id);
@@ -297,9 +303,33 @@ function createDataEngine(opts) {
297
303
  }
298
304
  return u;
299
305
  };
306
+ const hydrateFromCache = () => {
307
+ try {
308
+ const cached = JSON.parse(readFileSync2(snapshotCacheFile(), "utf-8"));
309
+ if (!cached || !Array.isArray(cached.accounts)) return;
310
+ for (const a of cached.accounts) {
311
+ if (a.dashboard || a.table) usage.set(a.id, { dashboard: a.dashboard, table: a.table });
312
+ if (a.billing) billing.set(a.id, a.billing);
313
+ }
314
+ current = assembleSnapshot({ version, tz, intervalMs: summaryIntervalMs, resolved, usage, billing });
315
+ } catch {
316
+ }
317
+ };
318
+ const persist = () => {
319
+ if (!current) return;
320
+ if (!current.accounts.some((a) => a.hasUsage && a.table != null)) return;
321
+ if (Date.now() - lastPersist < SNAPSHOT_CACHE_THROTTLE_MS) return;
322
+ lastPersist = Date.now();
323
+ try {
324
+ mkdirSync(cacheDir(), { recursive: true });
325
+ writeFileSync(snapshotCacheFile(), JSON.stringify(current));
326
+ } catch {
327
+ }
328
+ };
300
329
  const rebuild = () => {
301
330
  if (stopped) return;
302
331
  current = assembleSnapshot({ version, tz, intervalMs: summaryIntervalMs, resolved, usage, billing });
332
+ persist();
303
333
  if (sseClients.size === 0) return;
304
334
  const payload = `event: snapshot
305
335
  data: ${JSON.stringify(current)}
@@ -356,6 +386,7 @@ data: ${JSON.stringify(current)}
356
386
  billingBusy = false;
357
387
  }
358
388
  };
389
+ hydrateFromCache();
359
390
  return {
360
391
  snapshot: () => current,
361
392
  start() {
package/dist/cli.js CHANGED
@@ -1996,7 +1996,7 @@ function App({ interval: cliInterval, initialConfig }) {
1996
1996
  setWebStatus("off");
1997
1997
  } else {
1998
1998
  setWebStatus("starting");
1999
- const { startWebServer } = await import("./server-JV3U3PIF.js");
1999
+ const { startWebServer } = await import("./server-NO7JYH7U.js");
2000
2000
  const ctrl = await startWebServer({ config: cfg, log: false });
2001
2001
  webRef.current = ctrl;
2002
2002
  setWebUrl(ctrl.url);
@@ -2674,7 +2674,7 @@ process.emitWarning = ((warning, ...rest) => {
2674
2674
  var args = process.argv.slice(2);
2675
2675
  var subcommand = args[0]?.toLowerCase();
2676
2676
  if (subcommand === "serve" || subcommand === "web") {
2677
- const { startWeb } = await import("./web-6MDSVWLV.js");
2677
+ const { startWeb } = await import("./web-KQUELAT7.js");
2678
2678
  await startWeb(args.slice(1));
2679
2679
  process.exit(typeof process.exitCode === "number" ? process.exitCode : 0);
2680
2680
  }
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  startWebServer
4
- } from "./chunk-6QVIIZWX.js";
4
+ } from "./chunk-Z7JLP2Y2.js";
5
5
  import "./chunk-ZPH4754N.js";
6
6
  export {
7
7
  startWebServer
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  startWebServer
4
- } from "./chunk-6QVIIZWX.js";
4
+ } from "./chunk-Z7JLP2Y2.js";
5
5
  import {
6
6
  flushDisk,
7
7
  loadConfig
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokmon",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "Terminal dashboard for Claude Code, Codex, and Cursor usage, limits, and costs",
5
5
  "type": "module",
6
6
  "bin": {