tokentracker-cli 0.8.1 → 0.10.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.
@@ -28,6 +28,11 @@ const {
28
28
  ensurePricingLoaded,
29
29
  } = require("./pricing");
30
30
 
31
+ const {
32
+ computeClaudeCategoryBreakdown,
33
+ unsupportedSourcePayload: unsupportedCategoryPayload,
34
+ } = require("./claude-categorizer");
35
+
31
36
  // ---------------------------------------------------------------------------
32
37
  // Queue data helpers
33
38
  // ---------------------------------------------------------------------------
@@ -997,6 +1002,30 @@ function createLocalApiHandler({ queuePath }) {
997
1002
  return true;
998
1003
  }
999
1004
 
1005
+ // --- usage-category-breakdown (Claude Code only) ---
1006
+ // Splits historical Claude usage into seven semantic categories that
1007
+ // mirror the Claude Code /context view: system_prefix /
1008
+ // conversation_history / user_input / tool_calls / subagents /
1009
+ // reasoning / assistant_response. Other sources don't carry the
1010
+ // per-message role data this requires, so they return scope:unsupported.
1011
+ if (p === "/functions/tokentracker-usage-category-breakdown") {
1012
+ const from = url.searchParams.get("from") || "";
1013
+ const to = url.searchParams.get("to") || "";
1014
+ const requestedSource = (url.searchParams.get("source") || "claude").trim().toLowerCase();
1015
+ if (requestedSource !== "claude") {
1016
+ json(res, { from, to, ...unsupportedCategoryPayload(requestedSource) });
1017
+ return true;
1018
+ }
1019
+ try {
1020
+ const result = await computeClaudeCategoryBreakdown({ from, to, projectDir: process.cwd() });
1021
+ json(res, { from, to, ...result });
1022
+ } catch (e) {
1023
+ console.error("[LocalAPI] usage-category-breakdown:", e?.message || e);
1024
+ json(res, { from, to, ...unsupportedCategoryPayload("claude"), error: "compute_failed" }, 500);
1025
+ }
1026
+ return true;
1027
+ }
1028
+
1000
1029
  // --- project-usage-summary ---
1001
1030
  if (p === "/functions/tokentracker-project-usage-summary") {
1002
1031
  // Use the per-project bucket log that rollout.js emits — it already