@versot/vaguspi 0.1.1 → 0.1.3

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/dist/bin.js CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env node
2
+
1
3
  // apps/cli/src/bin.ts
2
4
  import { readFileSync as readFileSync7 } from "node:fs";
3
5
  import { parseArgs } from "node:util";
@@ -446,6 +448,10 @@ function messageToText(message) {
446
448
 
447
449
  // packages/host/engine/dist/usage-stats.js
448
450
  import { SessionManager } from "@earendil-works/pi-coding-agent";
451
+ function dayAt(ts) {
452
+ const d = new Date(ts);
453
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
454
+ }
449
455
  async function aggregateUsageStats() {
450
456
  const infos = await SessionManager.listAll();
451
457
  let totalTokens = 0;
@@ -459,11 +465,10 @@ async function aggregateUsageStats() {
459
465
  const activeDates = /* @__PURE__ */ new Set();
460
466
  const DAY = 864e5;
461
467
  const dayMap = /* @__PURE__ */ new Map();
462
- const dayAt = (ts) => Math.floor(ts / DAY);
463
468
  const ensureDay = (day) => {
464
469
  let p = dayMap.get(day);
465
470
  if (!p) {
466
- p = { tokens: 0, messages: 0, sessions: 0, byModel: /* @__PURE__ */ new Map() };
471
+ p = { tokens: 0, messages: 0, sessions: 0, cost: 0, byModel: /* @__PURE__ */ new Map() };
467
472
  dayMap.set(day, p);
468
473
  }
469
474
  return p;
@@ -487,12 +492,13 @@ async function aggregateUsageStats() {
487
492
  if (m.role !== "assistant" || m.usage === void 0)
488
493
  continue;
489
494
  const u = m.usage;
490
- const tokens = typeof u.totalTokens === "number" ? u.totalTokens : Number(u.input ?? 0) + Number(u.output ?? 0) + Number(u.cacheRead ?? 0) + Number(u.cacheWrite ?? 0);
495
+ const tokens = Number(u.input ?? 0) + Number(u.output ?? 0);
491
496
  const cost = typeof u.cost?.total === "number" ? u.cost.total : 0;
492
497
  totalTokens += tokens;
493
498
  totalCost += cost;
494
499
  sessionTokens += tokens;
495
500
  dayPoint.tokens += tokens;
501
+ dayPoint.cost += cost;
496
502
  const key = `${String(m.provider ?? "unknown")}/${String(m.model ?? "unknown")}`;
497
503
  const cur = byModel.get(key) ?? { tokens: 0, cost: 0 };
498
504
  byModel.set(key, { tokens: cur.tokens + tokens, cost: cur.cost + cost });
@@ -511,8 +517,9 @@ async function aggregateUsageStats() {
511
517
  }
512
518
  }
513
519
  const daily = [...dayMap.entries()].toSorted((a, b) => a[0] - b[0]).map(([day, p]) => ({
514
- ts: day * DAY,
520
+ ts: day,
515
521
  tokens: p.tokens,
522
+ cost: p.cost,
516
523
  messages: p.messages,
517
524
  sessions: p.sessions,
518
525
  byModel: Object.fromEntries(p.byModel)
@@ -522,14 +529,14 @@ async function aggregateUsageStats() {
522
529
  let longestStreak = 0;
523
530
  let run = 0;
524
531
  for (let i = 0; i < dates.length; i++) {
525
- run = i === 0 || dates[i] === (dates[i - 1] ?? 0) + 1 ? run + 1 : 1;
532
+ run = i === 0 || dates[i] === (dates[i - 1] ?? 0) + DAY ? run + 1 : 1;
526
533
  if (run > longestStreak)
527
534
  longestStreak = run;
528
535
  }
529
- const today = Math.floor(Date.now() / DAY);
536
+ const today = new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth(), (/* @__PURE__ */ new Date()).getDate()).getTime();
530
537
  let currentStreak = 0;
531
538
  for (let i = dates.length - 1; i >= 0; i--) {
532
- if (dates[i] === today - currentStreak) {
539
+ if (dates[i] === today - currentStreak * DAY) {
533
540
  currentStreak++;
534
541
  } else {
535
542
  break;