@tokscale/cli 1.4.2 → 2.0.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 (188) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +128 -0
  4. package/dist/index.js.map +1 -0
  5. package/package.json +19 -26
  6. package/dist/auth.d.ts +0 -17
  7. package/dist/auth.d.ts.map +0 -1
  8. package/dist/auth.js +0 -162
  9. package/dist/auth.js.map +0 -1
  10. package/dist/cli.d.ts +0 -9
  11. package/dist/cli.d.ts.map +0 -1
  12. package/dist/cli.js +0 -1523
  13. package/dist/cli.js.map +0 -1
  14. package/dist/credentials.d.ts +0 -50
  15. package/dist/credentials.d.ts.map +0 -1
  16. package/dist/credentials.js +0 -151
  17. package/dist/credentials.js.map +0 -1
  18. package/dist/cursor.d.ts +0 -167
  19. package/dist/cursor.d.ts.map +0 -1
  20. package/dist/cursor.js +0 -906
  21. package/dist/cursor.js.map +0 -1
  22. package/dist/date-utils.d.ts +0 -10
  23. package/dist/date-utils.d.ts.map +0 -1
  24. package/dist/date-utils.js +0 -47
  25. package/dist/date-utils.js.map +0 -1
  26. package/dist/graph-types.d.ts +0 -142
  27. package/dist/graph-types.d.ts.map +0 -1
  28. package/dist/graph-types.js +0 -6
  29. package/dist/graph-types.js.map +0 -1
  30. package/dist/native-runner.d.ts +0 -11
  31. package/dist/native-runner.d.ts.map +0 -1
  32. package/dist/native-runner.js +0 -77
  33. package/dist/native-runner.js.map +0 -1
  34. package/dist/native.d.ts +0 -105
  35. package/dist/native.d.ts.map +0 -1
  36. package/dist/native.js +0 -302
  37. package/dist/native.js.map +0 -1
  38. package/dist/sessions/types.d.ts +0 -28
  39. package/dist/sessions/types.d.ts.map +0 -1
  40. package/dist/sessions/types.js +0 -27
  41. package/dist/sessions/types.js.map +0 -1
  42. package/dist/spinner.d.ts +0 -75
  43. package/dist/spinner.d.ts.map +0 -1
  44. package/dist/spinner.js +0 -203
  45. package/dist/spinner.js.map +0 -1
  46. package/dist/submit.d.ts +0 -22
  47. package/dist/submit.d.ts.map +0 -1
  48. package/dist/submit.js +0 -292
  49. package/dist/submit.js.map +0 -1
  50. package/dist/table.d.ts +0 -42
  51. package/dist/table.d.ts.map +0 -1
  52. package/dist/table.js +0 -181
  53. package/dist/table.js.map +0 -1
  54. package/dist/tui/App.d.ts +0 -4
  55. package/dist/tui/App.d.ts.map +0 -1
  56. package/dist/tui/App.js +0 -350
  57. package/dist/tui/App.js.map +0 -1
  58. package/dist/tui/components/BarChart.d.ts +0 -17
  59. package/dist/tui/components/BarChart.d.ts.map +0 -1
  60. package/dist/tui/components/BarChart.js +0 -146
  61. package/dist/tui/components/BarChart.js.map +0 -1
  62. package/dist/tui/components/DailyView.d.ts +0 -13
  63. package/dist/tui/components/DailyView.d.ts.map +0 -1
  64. package/dist/tui/components/DailyView.js +0 -86
  65. package/dist/tui/components/DailyView.js.map +0 -1
  66. package/dist/tui/components/DateBreakdownPanel.d.ts +0 -7
  67. package/dist/tui/components/DateBreakdownPanel.d.ts.map +0 -1
  68. package/dist/tui/components/DateBreakdownPanel.js +0 -36
  69. package/dist/tui/components/DateBreakdownPanel.js.map +0 -1
  70. package/dist/tui/components/Footer.d.ts +0 -28
  71. package/dist/tui/components/Footer.d.ts.map +0 -1
  72. package/dist/tui/components/Footer.js +0 -130
  73. package/dist/tui/components/Footer.js.map +0 -1
  74. package/dist/tui/components/Header.d.ts +0 -9
  75. package/dist/tui/components/Header.d.ts.map +0 -1
  76. package/dist/tui/components/Header.js +0 -20
  77. package/dist/tui/components/Header.js.map +0 -1
  78. package/dist/tui/components/Legend.d.ts +0 -7
  79. package/dist/tui/components/Legend.d.ts.map +0 -1
  80. package/dist/tui/components/Legend.js +0 -16
  81. package/dist/tui/components/Legend.js.map +0 -1
  82. package/dist/tui/components/LoadingSpinner.d.ts +0 -8
  83. package/dist/tui/components/LoadingSpinner.d.ts.map +0 -1
  84. package/dist/tui/components/LoadingSpinner.js +0 -55
  85. package/dist/tui/components/LoadingSpinner.js.map +0 -1
  86. package/dist/tui/components/ModelRow.d.ts +0 -13
  87. package/dist/tui/components/ModelRow.d.ts.map +0 -1
  88. package/dist/tui/components/ModelRow.js +0 -15
  89. package/dist/tui/components/ModelRow.js.map +0 -1
  90. package/dist/tui/components/ModelView.d.ts +0 -13
  91. package/dist/tui/components/ModelView.d.ts.map +0 -1
  92. package/dist/tui/components/ModelView.js +0 -96
  93. package/dist/tui/components/ModelView.js.map +0 -1
  94. package/dist/tui/components/OverviewView.d.ts +0 -14
  95. package/dist/tui/components/OverviewView.d.ts.map +0 -1
  96. package/dist/tui/components/OverviewView.js +0 -65
  97. package/dist/tui/components/OverviewView.js.map +0 -1
  98. package/dist/tui/components/StatsView.d.ts +0 -14
  99. package/dist/tui/components/StatsView.d.ts.map +0 -1
  100. package/dist/tui/components/StatsView.js +0 -102
  101. package/dist/tui/components/StatsView.js.map +0 -1
  102. package/dist/tui/components/TokenBreakdown.d.ts +0 -14
  103. package/dist/tui/components/TokenBreakdown.d.ts.map +0 -1
  104. package/dist/tui/components/TokenBreakdown.js +0 -10
  105. package/dist/tui/components/TokenBreakdown.js.map +0 -1
  106. package/dist/tui/components/index.d.ts +0 -16
  107. package/dist/tui/components/index.d.ts.map +0 -1
  108. package/dist/tui/components/index.js +0 -13
  109. package/dist/tui/components/index.js.map +0 -1
  110. package/dist/tui/config/settings.d.ts +0 -15
  111. package/dist/tui/config/settings.d.ts.map +0 -1
  112. package/dist/tui/config/settings.js +0 -147
  113. package/dist/tui/config/settings.js.map +0 -1
  114. package/dist/tui/config/themes.d.ts +0 -15
  115. package/dist/tui/config/themes.d.ts.map +0 -1
  116. package/dist/tui/config/themes.js +0 -82
  117. package/dist/tui/config/themes.js.map +0 -1
  118. package/dist/tui/hooks/useData.d.ts +0 -19
  119. package/dist/tui/hooks/useData.d.ts.map +0 -1
  120. package/dist/tui/hooks/useData.js +0 -467
  121. package/dist/tui/hooks/useData.js.map +0 -1
  122. package/dist/tui/index.d.ts +0 -4
  123. package/dist/tui/index.d.ts.map +0 -1
  124. package/dist/tui/index.js +0 -36
  125. package/dist/tui/index.js.map +0 -1
  126. package/dist/tui/types/index.d.ts +0 -137
  127. package/dist/tui/types/index.d.ts.map +0 -1
  128. package/dist/tui/types/index.js +0 -25
  129. package/dist/tui/types/index.js.map +0 -1
  130. package/dist/tui/utils/cleanup.d.ts +0 -22
  131. package/dist/tui/utils/cleanup.d.ts.map +0 -1
  132. package/dist/tui/utils/cleanup.js +0 -59
  133. package/dist/tui/utils/cleanup.js.map +0 -1
  134. package/dist/tui/utils/colors.d.ts +0 -19
  135. package/dist/tui/utils/colors.d.ts.map +0 -1
  136. package/dist/tui/utils/colors.js +0 -68
  137. package/dist/tui/utils/colors.js.map +0 -1
  138. package/dist/tui/utils/format.d.ts +0 -7
  139. package/dist/tui/utils/format.d.ts.map +0 -1
  140. package/dist/tui/utils/format.js +0 -45
  141. package/dist/tui/utils/format.js.map +0 -1
  142. package/dist/tui/utils/responsive.d.ts +0 -5
  143. package/dist/tui/utils/responsive.d.ts.map +0 -1
  144. package/dist/tui/utils/responsive.js +0 -5
  145. package/dist/tui/utils/responsive.js.map +0 -1
  146. package/dist/wrapped.d.ts +0 -43
  147. package/dist/wrapped.d.ts.map +0 -1
  148. package/dist/wrapped.js +0 -716
  149. package/dist/wrapped.js.map +0 -1
  150. package/src/auth.ts +0 -211
  151. package/src/cli.ts +0 -1865
  152. package/src/credentials.ts +0 -176
  153. package/src/cursor.ts +0 -1044
  154. package/src/date-utils.ts +0 -51
  155. package/src/graph-types.ts +0 -175
  156. package/src/native-runner.js +0 -4
  157. package/src/native-runner.ts +0 -91
  158. package/src/native.ts +0 -631
  159. package/src/sessions/types.ts +0 -59
  160. package/src/spinner.ts +0 -283
  161. package/src/submit.ts +0 -358
  162. package/src/table.ts +0 -233
  163. package/src/tui/App.tsx +0 -443
  164. package/src/tui/components/BarChart.tsx +0 -205
  165. package/src/tui/components/DailyView.tsx +0 -132
  166. package/src/tui/components/DateBreakdownPanel.tsx +0 -79
  167. package/src/tui/components/Footer.tsx +0 -368
  168. package/src/tui/components/Header.tsx +0 -68
  169. package/src/tui/components/Legend.tsx +0 -39
  170. package/src/tui/components/LoadingSpinner.tsx +0 -81
  171. package/src/tui/components/ModelRow.tsx +0 -47
  172. package/src/tui/components/ModelView.tsx +0 -147
  173. package/src/tui/components/OverviewView.tsx +0 -121
  174. package/src/tui/components/StatsView.tsx +0 -249
  175. package/src/tui/components/TokenBreakdown.tsx +0 -46
  176. package/src/tui/components/index.ts +0 -15
  177. package/src/tui/config/settings.ts +0 -183
  178. package/src/tui/config/themes.ts +0 -115
  179. package/src/tui/hooks/useData.ts +0 -557
  180. package/src/tui/index.tsx +0 -44
  181. package/src/tui/opentui.d.ts +0 -166
  182. package/src/tui/types/index.ts +0 -172
  183. package/src/tui/utils/cleanup.ts +0 -65
  184. package/src/tui/utils/colors.ts +0 -76
  185. package/src/tui/utils/format.ts +0 -36
  186. package/src/tui/utils/responsive.ts +0 -8
  187. package/src/types.d.ts +0 -28
  188. package/src/wrapped.ts +0 -845
package/src/date-utils.ts DELETED
@@ -1,51 +0,0 @@
1
- export function formatDateLocal(date: Date): string {
2
- const y = date.getFullYear();
3
- const m = String(date.getMonth() + 1).padStart(2, "0");
4
- const d = String(date.getDate()).padStart(2, "0");
5
- return `${y}-${m}-${d}`;
6
- }
7
-
8
- export function parseDateStringToLocal(dateStr: string): Date | null {
9
- const match = dateStr.match(/^(\d{4})-(\d{2})-(\d{2})$/);
10
- if (!match) return null;
11
- const [, yearStr, monthStr, dayStr] = match;
12
- const year = parseInt(yearStr);
13
- const month = parseInt(monthStr) - 1;
14
- const day = parseInt(dayStr);
15
- const date = new Date(year, month, day);
16
- if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) {
17
- return null;
18
- }
19
- return date;
20
- }
21
-
22
- export function getStartOfDayTimestamp(date: Date): number {
23
- const start = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
24
- return start.getTime();
25
- }
26
-
27
- export function getEndOfDayTimestamp(date: Date): number {
28
- // Returns start of NEXT day (exclusive upper bound for half-open interval [since, until))
29
- const nextDay = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1, 0, 0, 0, 0);
30
- return nextDay.getTime();
31
- }
32
-
33
- export function getContributionLocalDate(contrib: { date: string; timestampMs?: number }): string {
34
- if (contrib.timestampMs != null) {
35
- return formatDateLocal(new Date(contrib.timestampMs));
36
- }
37
- return contrib.date;
38
- }
39
-
40
- const MIN_VALID_TIMESTAMP_MS = 1_000_000_000_000;
41
- const MAX_VALID_TIMESTAMP_MS = 4_102_444_800_000;
42
-
43
- export function validateTimestampMs(ts: number, label: string): number {
44
- if (!Number.isFinite(ts) || !Number.isSafeInteger(ts)) {
45
- throw new Error(`${label} must be a finite safe integer, got ${ts}`);
46
- }
47
- if (ts < MIN_VALID_TIMESTAMP_MS || ts > MAX_VALID_TIMESTAMP_MS) {
48
- throw new Error(`${label} out of valid range (${MIN_VALID_TIMESTAMP_MS}..${MAX_VALID_TIMESTAMP_MS}), got ${ts}`);
49
- }
50
- return ts;
51
- }
@@ -1,175 +0,0 @@
1
- /**
2
- * Type definitions for contribution graph data
3
- * Note: intensity is calculated based on COST ($), not tokens
4
- */
5
-
6
- /**
7
- * Valid source identifiers
8
- */
9
- export type SourceType = "opencode" | "claude" | "codex" | "gemini" | "cursor" | "amp" | "droid" | "openclaw" | "pi";
10
-
11
- /**
12
- * Token breakdown by category
13
- */
14
- export interface TokenBreakdown {
15
- input: number;
16
- output: number;
17
- cacheRead: number;
18
- cacheWrite: number;
19
- reasoning: number;
20
- }
21
-
22
- /**
23
- * Per-source contribution for a single day
24
- */
25
- export interface SourceContribution {
26
- /** Source identifier */
27
- source: SourceType;
28
-
29
- /** Exact model ID as reported by the source */
30
- modelId: string;
31
-
32
- /** Provider ID if available */
33
- providerId?: string;
34
-
35
- /** Token counts */
36
- tokens: TokenBreakdown;
37
-
38
- /** Calculated cost for this source/model combination */
39
- cost: number;
40
-
41
- /** Number of messages/requests */
42
- messages: number;
43
- }
44
-
45
- /**
46
- * Daily contribution entry with full granularity
47
- */
48
- export interface DailyContribution {
49
- /** ISO date string (YYYY-MM-DD) in UTC - note: this is the UTC day bucket, not local date */
50
- date: string;
51
-
52
- /** Unix timestampMs (ms) of earliest message in this UTC day bucket.
53
- * Undefined for days with no valid timestamps. */
54
- timestampMs?: number;
55
-
56
- /** Aggregated totals for the day */
57
- totals: {
58
- /** Total tokens (input + output + cache) */
59
- tokens: number;
60
- /** Total cost in USD */
61
- cost: number;
62
- /** Number of messages/requests */
63
- messages: number;
64
- };
65
-
66
- /**
67
- * Calculated intensity grade (0-4)
68
- * Based on COST, not tokens
69
- * 0 = no activity, 4 = highest cost relative to max
70
- */
71
- intensity: 0 | 1 | 2 | 3 | 4;
72
-
73
- /** Token breakdown by category (aggregated across all sources) */
74
- tokenBreakdown: TokenBreakdown;
75
-
76
- /** Per-source breakdown with model information */
77
- sources: SourceContribution[];
78
- }
79
-
80
- /**
81
- * Year-level summary
82
- */
83
- export interface YearSummary {
84
- /** Year as string (e.g., "2024") */
85
- year: string;
86
-
87
- /** Total tokens for the year */
88
- totalTokens: number;
89
-
90
- /** Total cost for the year */
91
- totalCost: number;
92
-
93
- /** Date range for this year's data */
94
- range: {
95
- start: string;
96
- end: string;
97
- };
98
- }
99
-
100
- /**
101
- * Summary statistics
102
- */
103
- export interface DataSummary {
104
- /** Total tokens across all time */
105
- totalTokens: number;
106
-
107
- /** Total cost across all time */
108
- totalCost: number;
109
-
110
- /** Total number of days in date range */
111
- totalDays: number;
112
-
113
- /** Number of days with activity */
114
- activeDays: number;
115
-
116
- /** Average cost per day (based on active days) */
117
- averagePerDay: number;
118
-
119
- /** Maximum cost in a single day (used for intensity calculation) */
120
- maxCostInSingleDay: number;
121
-
122
- /** All sources present in the data */
123
- sources: SourceType[];
124
-
125
- /** All unique model IDs across all sources */
126
- models: string[];
127
- }
128
-
129
- /**
130
- * Metadata about the export
131
- */
132
- export interface ExportMeta {
133
- /** ISO timestamp of when the data was generated */
134
- generatedAt: string;
135
-
136
- /** CLI version that generated this data */
137
- version: string;
138
-
139
- /** Date range of the data */
140
- dateRange: {
141
- start: string;
142
- end: string;
143
- };
144
- }
145
-
146
- /**
147
- * Root data structure exported by CLI
148
- * This is the complete JSON schema for contribution graph data
149
- */
150
- export interface TokenContributionData {
151
- /** Metadata about the export */
152
- meta: ExportMeta;
153
-
154
- /** Summary statistics */
155
- summary: DataSummary;
156
-
157
- /** Year-by-year breakdown for multi-year views */
158
- years: YearSummary[];
159
-
160
- /** Daily contribution data - the core dataset */
161
- contributions: DailyContribution[];
162
- }
163
-
164
- /**
165
- * Unified message format for aggregation
166
- * Used internally to normalize data from different sources
167
- */
168
- export interface UnifiedMessage {
169
- source: SourceType;
170
- modelId: string;
171
- providerId?: string;
172
- timestampMs: number; // Unix milliseconds
173
- tokens: TokenBreakdown;
174
- cost: number;
175
- }
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env bun
2
- // Shim for bunx: when Bun loads src/ directly instead of dist/,
3
- // this file redirects to the TypeScript source.
4
- await import("./native-runner.ts");
@@ -1,91 +0,0 @@
1
- #!/usr/bin/env bun
2
- /**
3
- * Native Runner - Subprocess for non-blocking native Rust calls
4
- *
5
- * This script runs in a separate process to keep the main event loop free
6
- * for UI rendering (e.g., spinner animation).
7
- *
8
- * Communication: tmpfile (JSON input) -> tmpfile (JSON output)
9
- */
10
-
11
- import { readFileSync, writeFileSync } from "node:fs";
12
-
13
- interface NativeRunnerRequest {
14
- method: string;
15
- args: unknown[];
16
- }
17
-
18
- async function main() {
19
- const inputFile = process.argv[2];
20
- const outputFile = process.argv[3];
21
-
22
- if (!inputFile || !outputFile) {
23
- process.stderr.write(JSON.stringify({ error: "Usage: native-runner <inputFile> <outputFile>" }));
24
- process.exit(1);
25
- }
26
-
27
- // Dynamic import so that load failures are caught and reported as JSON to stderr
28
- // rather than causing an unhandled crash with no diagnostic output (e.g. on NixOS
29
- // where the .node binary's dynamic linker path differs from standard Linux paths).
30
- let nativeCore: typeof import("@tokscale/core");
31
- try {
32
- const mod = await import("@tokscale/core");
33
- // CJS modules wrapped by Bun expose exports as .default; fall back to the namespace.
34
- nativeCore = ((mod as unknown as { default: typeof mod }).default ?? mod) as typeof import("@tokscale/core");
35
- } catch (e) {
36
- const err = e as Error;
37
- process.stderr.write(JSON.stringify({
38
- error: `Failed to load native module (@tokscale/core): ${err.message}`,
39
- stack: err.stack,
40
- }));
41
- process.exit(1);
42
- }
43
-
44
- const input = readFileSync(inputFile, "utf-8");
45
-
46
- let request: NativeRunnerRequest;
47
- try {
48
- request = JSON.parse(input) as NativeRunnerRequest;
49
- } catch (e) {
50
- throw new Error(`Malformed JSON input: ${(e as Error).message}`);
51
- }
52
-
53
- const { method, args } = request;
54
-
55
- if (!Array.isArray(args) || args.length === 0) {
56
- throw new Error(`Invalid args for method '${method}': expected at least 1 argument`);
57
- }
58
-
59
- let result: unknown;
60
-
61
- switch (method) {
62
- case "parseLocalSources":
63
- result = nativeCore.parseLocalSources(args[0] as Parameters<typeof nativeCore.parseLocalSources>[0]);
64
- break;
65
- case "finalizeReport":
66
- result = await nativeCore.finalizeReport(args[0] as Parameters<typeof nativeCore.finalizeReport>[0]);
67
- break;
68
- case "finalizeMonthlyReport":
69
- result = await nativeCore.finalizeMonthlyReport(args[0] as Parameters<typeof nativeCore.finalizeMonthlyReport>[0]);
70
- break;
71
- case "finalizeGraph":
72
- result = await nativeCore.finalizeGraph(args[0] as Parameters<typeof nativeCore.finalizeGraph>[0]);
73
- break;
74
- case "finalizeReportAndGraph":
75
- result = await nativeCore.finalizeReportAndGraph(args[0] as Parameters<typeof nativeCore.finalizeReportAndGraph>[0]);
76
- break;
77
- default:
78
- throw new Error(`Unknown method: ${method}`);
79
- }
80
-
81
- writeFileSync(outputFile, JSON.stringify(result), "utf-8");
82
- }
83
-
84
- main().catch((e) => {
85
- const error = e as Error;
86
- process.stderr.write(JSON.stringify({
87
- error: error.message,
88
- stack: error.stack,
89
- }));
90
- process.exit(1);
91
- });