tokenusage-cli 0.2.6 → 0.4.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +52 -11
  3. package/bin/tokenusage.js +14 -2
  4. package/package.json +1 -2
  5. package/src/cli.js +325 -78
  6. package/src/commands/device-login.js +3 -3
  7. package/src/commands/init.js +343 -153
  8. package/src/commands/pause.js +11 -23
  9. package/src/commands/reconcile.js +485 -0
  10. package/src/commands/sessions.js +57 -14
  11. package/src/commands/status.js +5 -2
  12. package/src/commands/sync.js +77 -18
  13. package/src/commands/uninstall.js +6 -9
  14. package/src/commands/upload.js +147 -0
  15. package/src/lib/cli-errors.js +33 -0
  16. package/src/lib/cli-ui.js +93 -0
  17. package/src/lib/ingest-sanitize.js +9 -0
  18. package/src/lib/queue-row-normalize.js +55 -0
  19. package/src/lib/rollout.js +39 -2
  20. package/src/lib/scheduled-task.js +597 -75
  21. package/src/lib/session-analytics.js +171 -3
  22. package/src/lib/session-upload.js +6 -0
  23. package/src/lib/sync-report.js +8 -2
  24. package/src/lib/trae-db.js +6 -1
  25. package/src/lib/antigravity-paths.js +0 -48
  26. package/src/lib/async-queue-reader.js +0 -138
  27. package/src/lib/atomic-json.js +0 -27
  28. package/src/lib/bearer-token.js +0 -11
  29. package/src/lib/cloud-account.js +0 -541
  30. package/src/lib/codex-context-breakdown.js +0 -806
  31. package/src/lib/context-health.js +0 -124
  32. package/src/lib/grok-context-breakdown.js +0 -890
  33. package/src/lib/heatmap-compact.js +0 -114
  34. package/src/lib/local-api.js +0 -3574
  35. package/src/lib/outcomes-engine.js +0 -253
  36. package/src/lib/pet-packages.js +0 -722
  37. package/src/lib/skill-usage.js +0 -267
  38. package/src/lib/skills-manager.js +0 -1591
  39. package/src/lib/source-metadata.js +0 -48
  40. package/src/lib/subscription-manager.js +0 -293
  41. package/src/lib/wrapped-aggregator.js +0 -236
  42. package/test/audit-fixes.test.js +0 -249
  43. package/test/branding.test.js +0 -24
  44. package/test/cli-options.test.js +0 -43
  45. package/test/cli-smoke.test.js +0 -53
  46. package/test/cli-ui.test.js +0 -47
  47. package/test/collection-controls.test.js +0 -255
  48. package/test/ingest-sanitize.test.js +0 -162
  49. package/test/packaging.test.js +0 -107
  50. package/test/quiet-warnings.test.js +0 -53
  51. package/test/runtime-copy.test.js +0 -111
  52. package/test/session-upload.test.js +0 -427
  53. package/test/zstd-native.test.js +0 -36
@@ -3684,6 +3684,7 @@ async function enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets })
3684
3684
  total_cost_usd: totals.total_cost_usd || 0,
3685
3685
  usage_precision: usagePrecision || undefined,
3686
3686
  ...prioritySubsetOf(totals),
3687
+ ...creditsSubsetOf(totals),
3687
3688
  conversation_count: totals.conversation_count,
3688
3689
  }),
3689
3690
  );
@@ -3765,6 +3766,7 @@ async function enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets })
3765
3766
  total_cost_usd: unknownBucket.totals.total_cost_usd || 0,
3766
3767
  usage_precision: usagePrecision || undefined,
3767
3768
  ...prioritySubsetOf(unknownBucket.totals),
3769
+ ...creditsSubsetOf(unknownBucket.totals),
3768
3770
  conversation_count: unknownBucket.totals.conversation_count,
3769
3771
  }),
3770
3772
  );
@@ -3814,6 +3816,7 @@ async function enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets })
3814
3816
  billable_total_tokens: group.totals.billable_total_tokens ?? group.totals.total_tokens,
3815
3817
  total_cost_usd: group.totals.total_cost_usd || 0,
3816
3818
  ...prioritySubsetOf(group.totals),
3819
+ ...creditsSubsetOf(group.totals),
3817
3820
  conversation_count: group.totals.conversation_count,
3818
3821
  }),
3819
3822
  );
@@ -4405,6 +4408,7 @@ function initTotals() {
4405
4408
  billable_total_tokens: 0,
4406
4409
  total_cost_usd: 0,
4407
4410
  conversation_count: 0,
4411
+ credits: 0,
4408
4412
  };
4409
4413
  }
4410
4414
 
@@ -4440,6 +4444,14 @@ function prioritySubsetOf(totals) {
4440
4444
  return subset;
4441
4445
  }
4442
4446
 
4447
+ // Vendor credits (docs/sources-capture-audit.md §2) serialize only when
4448
+ // positive, so buckets that never see a credit-based provider keep their
4449
+ // previously persisted queuedKey and queue rows unchanged.
4450
+ function creditsSubsetOf(totals) {
4451
+ const value = Number(totals?.credits) || 0;
4452
+ return value > 0 ? { credits: value } : {};
4453
+ }
4454
+
4443
4455
  function addTotals(target, delta) {
4444
4456
  for (const [field] of PRIORITY_SUBSET_FIELDS) {
4445
4457
  const value = Number(delta?.[field]) || 0;
@@ -4456,6 +4468,9 @@ function addTotals(target, delta) {
4456
4468
  ((target.total_cost_usd || 0) + (delta.total_cost_usd || 0)) * USD_TICKS_PER_USD,
4457
4469
  ) / USD_TICKS_PER_USD;
4458
4470
  target.conversation_count += delta.conversation_count || 0;
4471
+ // Credits are a display-only dimension: summed like cost but never part of
4472
+ // any token column or sum check (docs/sources-capture-audit.md §2).
4473
+ target.credits = Math.round(((target.credits || 0) + (delta.credits || 0)) * 1e6) / 1e6;
4459
4474
  }
4460
4475
 
4461
4476
  // Signed-delta defense (audit fix): OpenCode corrections subtract a prior
@@ -4473,6 +4488,7 @@ function clampTotalsNonNegative(totals) {
4473
4488
  "total_tokens",
4474
4489
  "billable_total_tokens",
4475
4490
  "conversation_count",
4491
+ "credits",
4476
4492
  ]) {
4477
4493
  if (totals[key] != null) totals[key] = Math.max(0, totals[key]);
4478
4494
  }
@@ -4516,6 +4532,10 @@ function subtractTotals(target, totals) {
4516
4532
  0,
4517
4533
  target.conversation_count - (totals.conversation_count || 0),
4518
4534
  );
4535
+ target.credits = Math.max(
4536
+ 0,
4537
+ Math.round(((target.credits || 0) - (totals.credits || 0)) * 1e6) / 1e6,
4538
+ );
4519
4539
  }
4520
4540
 
4521
4541
  function totalsKey(totals) {
@@ -4533,7 +4553,9 @@ function totalsKey(totals) {
4533
4553
  // Appended only when a priority subset exists, so buckets that never see the
4534
4554
  // tier keep their previously persisted queuedKey and are not re-enqueued.
4535
4555
  const priority = PRIORITY_SUBSET_FIELDS.map(([field]) => Number(totals[field]) || 0);
4536
- return priority.some((value) => value > 0) ? `${base}|p:${priority.join(",")}` : base;
4556
+ const key = priority.some((value) => value > 0) ? `${base}|p:${priority.join(",")}` : base;
4557
+ const credits = Number(totals.credits) || 0;
4558
+ return credits > 0 ? `${key}|c:${credits}` : key;
4537
4559
  }
4538
4560
 
4539
4561
  function toUtcHalfHourStart(ts) {
@@ -6889,9 +6911,18 @@ function qoderNewTimestampMs(record) {
6889
6911
  || 0;
6890
6912
  }
6891
6913
 
6914
+ // Vendor credits (Qoder) ride along on token rows and are the only counter on
6915
+ // credits-only rows. They are a display-only dimension
6916
+ // (docs/sources-capture-audit.md §2): summed for visibility, never converted
6917
+ // to tokens and never merged into any token column.
6918
+ function qoderUsageCredits(usage) {
6919
+ const credits = Number(usage?.credits ?? usage?.original_credits ?? 0);
6920
+ return Number.isFinite(credits) && credits > 0 ? Math.round(credits * 1e6) / 1e6 : 0;
6921
+ }
6922
+
6892
6923
  function normalizeQoderNewTokens(usage) {
6893
6924
  if (!usage || typeof usage !== "object") return null;
6894
- const credits = Number(usage.credits ?? usage.original_credits ?? 0);
6925
+ const credits = qoderUsageCredits(usage);
6895
6926
  let input = Number(usage.input_tokens ?? 0);
6896
6927
  let cached = Number(usage.cache_read_input_tokens ?? usage.cached_tokens ?? 0);
6897
6928
  let cacheCreation = Number(usage.cache_creation_input_tokens ?? 0);
@@ -7024,9 +7055,14 @@ async function parseQoderNewIncremental({
7024
7055
  total_tokens: base.total_tokens,
7025
7056
  billable_total_tokens: base.billable_total_tokens,
7026
7057
  total_cost_usd: 0,
7058
+ credits: base.credits || 0,
7027
7059
  usage_precision: base.usage_precision || undefined,
7028
7060
  conversation_count: 1,
7029
7061
  } : {
7062
+ // Credit-only usage: the token delta stays zero (no first-party
7063
+ // credit→token rate), but the vendor credits are now recorded for
7064
+ // display instead of being dropped (2026-10-31 P1,
7065
+ // docs/sources-capture-plan.md §3).
7030
7066
  input_tokens: 0,
7031
7067
  cached_input_tokens: 0,
7032
7068
  cache_creation_input_tokens: 0,
@@ -7035,6 +7071,7 @@ async function parseQoderNewIncremental({
7035
7071
  total_tokens: 0,
7036
7072
  billable_total_tokens: 0,
7037
7073
  total_cost_usd: 0,
7074
+ credits: qoderUsageCredits(usage),
7038
7075
  conversation_count: 1,
7039
7076
  };
7040
7077
  let projectKey = null;