@tokscale/cli 1.4.3 → 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.
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/package.json +19 -26
- package/dist/auth.d.ts +0 -17
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js +0 -162
- package/dist/auth.js.map +0 -1
- package/dist/cli.d.ts +0 -9
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -1550
- package/dist/cli.js.map +0 -1
- package/dist/credentials.d.ts +0 -50
- package/dist/credentials.d.ts.map +0 -1
- package/dist/credentials.js +0 -151
- package/dist/credentials.js.map +0 -1
- package/dist/cursor.d.ts +0 -167
- package/dist/cursor.d.ts.map +0 -1
- package/dist/cursor.js +0 -906
- package/dist/cursor.js.map +0 -1
- package/dist/date-utils.d.ts +0 -10
- package/dist/date-utils.d.ts.map +0 -1
- package/dist/date-utils.js +0 -47
- package/dist/date-utils.js.map +0 -1
- package/dist/graph-types.d.ts +0 -142
- package/dist/graph-types.d.ts.map +0 -1
- package/dist/graph-types.js +0 -6
- package/dist/graph-types.js.map +0 -1
- package/dist/native-runner.d.ts +0 -11
- package/dist/native-runner.d.ts.map +0 -1
- package/dist/native-runner.js +0 -77
- package/dist/native-runner.js.map +0 -1
- package/dist/native.d.ts +0 -106
- package/dist/native.d.ts.map +0 -1
- package/dist/native.js +0 -302
- package/dist/native.js.map +0 -1
- package/dist/sessions/types.d.ts +0 -28
- package/dist/sessions/types.d.ts.map +0 -1
- package/dist/sessions/types.js +0 -27
- package/dist/sessions/types.js.map +0 -1
- package/dist/spinner.d.ts +0 -75
- package/dist/spinner.d.ts.map +0 -1
- package/dist/spinner.js +0 -203
- package/dist/spinner.js.map +0 -1
- package/dist/submit.d.ts +0 -23
- package/dist/submit.d.ts.map +0 -1
- package/dist/submit.js +0 -294
- package/dist/submit.js.map +0 -1
- package/dist/table.d.ts +0 -42
- package/dist/table.d.ts.map +0 -1
- package/dist/table.js +0 -181
- package/dist/table.js.map +0 -1
- package/dist/tui/App.d.ts +0 -4
- package/dist/tui/App.d.ts.map +0 -1
- package/dist/tui/App.js +0 -333
- package/dist/tui/App.js.map +0 -1
- package/dist/tui/components/BarChart.d.ts +0 -17
- package/dist/tui/components/BarChart.d.ts.map +0 -1
- package/dist/tui/components/BarChart.js +0 -146
- package/dist/tui/components/BarChart.js.map +0 -1
- package/dist/tui/components/DailyView.d.ts +0 -13
- package/dist/tui/components/DailyView.d.ts.map +0 -1
- package/dist/tui/components/DailyView.js +0 -86
- package/dist/tui/components/DailyView.js.map +0 -1
- package/dist/tui/components/DateBreakdownPanel.d.ts +0 -7
- package/dist/tui/components/DateBreakdownPanel.d.ts.map +0 -1
- package/dist/tui/components/DateBreakdownPanel.js +0 -36
- package/dist/tui/components/DateBreakdownPanel.js.map +0 -1
- package/dist/tui/components/Footer.d.ts +0 -28
- package/dist/tui/components/Footer.d.ts.map +0 -1
- package/dist/tui/components/Footer.js +0 -130
- package/dist/tui/components/Footer.js.map +0 -1
- package/dist/tui/components/Header.d.ts +0 -9
- package/dist/tui/components/Header.d.ts.map +0 -1
- package/dist/tui/components/Header.js +0 -20
- package/dist/tui/components/Header.js.map +0 -1
- package/dist/tui/components/Legend.d.ts +0 -7
- package/dist/tui/components/Legend.d.ts.map +0 -1
- package/dist/tui/components/Legend.js +0 -16
- package/dist/tui/components/Legend.js.map +0 -1
- package/dist/tui/components/LoadingSpinner.d.ts +0 -8
- package/dist/tui/components/LoadingSpinner.d.ts.map +0 -1
- package/dist/tui/components/LoadingSpinner.js +0 -55
- package/dist/tui/components/LoadingSpinner.js.map +0 -1
- package/dist/tui/components/ModelRow.d.ts +0 -13
- package/dist/tui/components/ModelRow.d.ts.map +0 -1
- package/dist/tui/components/ModelRow.js +0 -15
- package/dist/tui/components/ModelRow.js.map +0 -1
- package/dist/tui/components/ModelView.d.ts +0 -13
- package/dist/tui/components/ModelView.d.ts.map +0 -1
- package/dist/tui/components/ModelView.js +0 -96
- package/dist/tui/components/ModelView.js.map +0 -1
- package/dist/tui/components/OverviewView.d.ts +0 -14
- package/dist/tui/components/OverviewView.d.ts.map +0 -1
- package/dist/tui/components/OverviewView.js +0 -65
- package/dist/tui/components/OverviewView.js.map +0 -1
- package/dist/tui/components/StatsView.d.ts +0 -14
- package/dist/tui/components/StatsView.d.ts.map +0 -1
- package/dist/tui/components/StatsView.js +0 -102
- package/dist/tui/components/StatsView.js.map +0 -1
- package/dist/tui/components/TokenBreakdown.d.ts +0 -14
- package/dist/tui/components/TokenBreakdown.d.ts.map +0 -1
- package/dist/tui/components/TokenBreakdown.js +0 -10
- package/dist/tui/components/TokenBreakdown.js.map +0 -1
- package/dist/tui/components/index.d.ts +0 -16
- package/dist/tui/components/index.d.ts.map +0 -1
- package/dist/tui/components/index.js +0 -13
- package/dist/tui/components/index.js.map +0 -1
- package/dist/tui/config/settings.d.ts +0 -15
- package/dist/tui/config/settings.d.ts.map +0 -1
- package/dist/tui/config/settings.js +0 -147
- package/dist/tui/config/settings.js.map +0 -1
- package/dist/tui/config/themes.d.ts +0 -15
- package/dist/tui/config/themes.d.ts.map +0 -1
- package/dist/tui/config/themes.js +0 -82
- package/dist/tui/config/themes.js.map +0 -1
- package/dist/tui/hooks/useData.d.ts +0 -19
- package/dist/tui/hooks/useData.d.ts.map +0 -1
- package/dist/tui/hooks/useData.js +0 -468
- package/dist/tui/hooks/useData.js.map +0 -1
- package/dist/tui/index.d.ts +0 -4
- package/dist/tui/index.d.ts.map +0 -1
- package/dist/tui/index.js +0 -36
- package/dist/tui/index.js.map +0 -1
- package/dist/tui/types/index.d.ts +0 -137
- package/dist/tui/types/index.d.ts.map +0 -1
- package/dist/tui/types/index.js +0 -26
- package/dist/tui/types/index.js.map +0 -1
- package/dist/tui/utils/cleanup.d.ts +0 -22
- package/dist/tui/utils/cleanup.d.ts.map +0 -1
- package/dist/tui/utils/cleanup.js +0 -59
- package/dist/tui/utils/cleanup.js.map +0 -1
- package/dist/tui/utils/colors.d.ts +0 -19
- package/dist/tui/utils/colors.d.ts.map +0 -1
- package/dist/tui/utils/colors.js +0 -71
- package/dist/tui/utils/colors.js.map +0 -1
- package/dist/tui/utils/format.d.ts +0 -7
- package/dist/tui/utils/format.d.ts.map +0 -1
- package/dist/tui/utils/format.js +0 -45
- package/dist/tui/utils/format.js.map +0 -1
- package/dist/tui/utils/responsive.d.ts +0 -5
- package/dist/tui/utils/responsive.d.ts.map +0 -1
- package/dist/tui/utils/responsive.js +0 -5
- package/dist/tui/utils/responsive.js.map +0 -1
- package/dist/wrapped.d.ts +0 -43
- package/dist/wrapped.d.ts.map +0 -1
- package/dist/wrapped.js +0 -719
- package/dist/wrapped.js.map +0 -1
- package/src/auth.ts +0 -211
- package/src/cli.ts +0 -1892
- package/src/credentials.ts +0 -176
- package/src/cursor.ts +0 -1044
- package/src/date-utils.ts +0 -51
- package/src/graph-types.ts +0 -175
- package/src/native-runner.js +0 -4
- package/src/native-runner.ts +0 -91
- package/src/native.ts +0 -633
- package/src/sessions/types.ts +0 -59
- package/src/spinner.ts +0 -283
- package/src/submit.ts +0 -360
- package/src/table.ts +0 -233
- package/src/tui/App.tsx +0 -453
- package/src/tui/components/BarChart.tsx +0 -205
- package/src/tui/components/DailyView.tsx +0 -132
- package/src/tui/components/DateBreakdownPanel.tsx +0 -79
- package/src/tui/components/Footer.tsx +0 -380
- package/src/tui/components/Header.tsx +0 -68
- package/src/tui/components/Legend.tsx +0 -39
- package/src/tui/components/LoadingSpinner.tsx +0 -81
- package/src/tui/components/ModelRow.tsx +0 -47
- package/src/tui/components/ModelView.tsx +0 -147
- package/src/tui/components/OverviewView.tsx +0 -121
- package/src/tui/components/StatsView.tsx +0 -249
- package/src/tui/components/TokenBreakdown.tsx +0 -46
- package/src/tui/components/index.ts +0 -15
- package/src/tui/config/settings.ts +0 -183
- package/src/tui/config/themes.ts +0 -115
- package/src/tui/hooks/useData.ts +0 -558
- package/src/tui/index.tsx +0 -44
- package/src/tui/opentui.d.ts +0 -166
- package/src/tui/types/index.ts +0 -173
- package/src/tui/utils/cleanup.ts +0 -65
- package/src/tui/utils/colors.ts +0 -78
- package/src/tui/utils/format.ts +0 -36
- package/src/tui/utils/responsive.ts +0 -8
- package/src/types.d.ts +0 -28
- package/src/wrapped.ts +0 -848
package/src/credentials.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tokscale CLI Credentials Manager
|
|
3
|
-
* Stores and retrieves API tokens for authenticated CLI operations
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import * as fs from "node:fs";
|
|
7
|
-
import * as path from "node:path";
|
|
8
|
-
import * as os from "node:os";
|
|
9
|
-
|
|
10
|
-
export interface Credentials {
|
|
11
|
-
token: string;
|
|
12
|
-
username: string;
|
|
13
|
-
avatarUrl?: string;
|
|
14
|
-
createdAt: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface StarCache {
|
|
18
|
-
username: string;
|
|
19
|
-
hasStarred: boolean;
|
|
20
|
-
checkedAt: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const OLD_CONFIG_DIR = path.join(os.homedir(), ".tokscale");
|
|
24
|
-
const CONFIG_DIR = path.join(os.homedir(), ".config", "tokscale");
|
|
25
|
-
const OLD_CREDENTIALS_FILE = path.join(OLD_CONFIG_DIR, "credentials.json");
|
|
26
|
-
const CREDENTIALS_FILE = path.join(CONFIG_DIR, "credentials.json");
|
|
27
|
-
const STAR_CACHE_FILE = path.join(CONFIG_DIR, "star-cache.json");
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Ensure the config directory exists
|
|
31
|
-
*/
|
|
32
|
-
function ensureConfigDir(): void {
|
|
33
|
-
if (!fs.existsSync(CONFIG_DIR)) {
|
|
34
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Migrate credentials from old path (~/.token-tracker) to new XDG path (~/.config/token-tracker)
|
|
40
|
-
*/
|
|
41
|
-
function migrateFromOldPath(): void {
|
|
42
|
-
try {
|
|
43
|
-
if (!fs.existsSync(CREDENTIALS_FILE) && fs.existsSync(OLD_CREDENTIALS_FILE)) {
|
|
44
|
-
ensureConfigDir();
|
|
45
|
-
fs.copyFileSync(OLD_CREDENTIALS_FILE, CREDENTIALS_FILE);
|
|
46
|
-
fs.chmodSync(CREDENTIALS_FILE, 0o600);
|
|
47
|
-
// Delete old file after successful migration
|
|
48
|
-
fs.unlinkSync(OLD_CREDENTIALS_FILE);
|
|
49
|
-
// Try to remove old directory if empty
|
|
50
|
-
try {
|
|
51
|
-
fs.rmdirSync(OLD_CONFIG_DIR);
|
|
52
|
-
} catch {
|
|
53
|
-
// Directory not empty (cursor files may exist) - ignore
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
} catch {
|
|
57
|
-
// Migration failed - continue with normal operation (old path may still work)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Save credentials to disk
|
|
63
|
-
*/
|
|
64
|
-
export function saveCredentials(credentials: Credentials): void {
|
|
65
|
-
ensureConfigDir();
|
|
66
|
-
fs.writeFileSync(CREDENTIALS_FILE, JSON.stringify(credentials, null, 2), {
|
|
67
|
-
encoding: "utf-8",
|
|
68
|
-
mode: 0o600, // Read/write for owner only
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Load credentials from disk
|
|
74
|
-
* Returns null if no credentials are stored or file is invalid
|
|
75
|
-
*/
|
|
76
|
-
export function loadCredentials(): Credentials | null {
|
|
77
|
-
migrateFromOldPath();
|
|
78
|
-
try {
|
|
79
|
-
if (!fs.existsSync(CREDENTIALS_FILE)) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
const data = fs.readFileSync(CREDENTIALS_FILE, "utf-8");
|
|
83
|
-
const parsed = JSON.parse(data);
|
|
84
|
-
|
|
85
|
-
// Validate structure
|
|
86
|
-
if (!parsed.token || !parsed.username) {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return parsed as Credentials;
|
|
91
|
-
} catch {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Clear stored credentials
|
|
98
|
-
*/
|
|
99
|
-
export function clearCredentials(): boolean {
|
|
100
|
-
try {
|
|
101
|
-
if (fs.existsSync(CREDENTIALS_FILE)) {
|
|
102
|
-
fs.unlinkSync(CREDENTIALS_FILE);
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
return false;
|
|
106
|
-
} catch {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Check if user is logged in
|
|
113
|
-
*/
|
|
114
|
-
export function isLoggedIn(): boolean {
|
|
115
|
-
return loadCredentials() !== null;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Get the API base URL
|
|
120
|
-
*/
|
|
121
|
-
export function getApiBaseUrl(): string {
|
|
122
|
-
return process.env.TOKSCALE_API_URL || "https://tokscale.ai";
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Get the credentials file path (for debugging)
|
|
127
|
-
*/
|
|
128
|
-
export function getCredentialsPath(): string {
|
|
129
|
-
return CREDENTIALS_FILE;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Load star cache for a specific username
|
|
134
|
-
* Returns null if no cache exists or file is invalid
|
|
135
|
-
*/
|
|
136
|
-
export function loadStarCache(username: string): StarCache | null {
|
|
137
|
-
try {
|
|
138
|
-
if (!fs.existsSync(STAR_CACHE_FILE)) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
const data = fs.readFileSync(STAR_CACHE_FILE, "utf-8");
|
|
142
|
-
const parsed = JSON.parse(data);
|
|
143
|
-
|
|
144
|
-
if (!parsed.username || typeof parsed.hasStarred !== "boolean" || !parsed.checkedAt) {
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (parsed.username !== username) {
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (!parsed.hasStarred) {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return parsed as StarCache;
|
|
157
|
-
} catch {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Save star cache to disk
|
|
164
|
-
*/
|
|
165
|
-
export function saveStarCache(cache: StarCache): void {
|
|
166
|
-
try {
|
|
167
|
-
ensureConfigDir();
|
|
168
|
-
fs.writeFileSync(STAR_CACHE_FILE, JSON.stringify(cache, null, 2), {
|
|
169
|
-
encoding: "utf-8",
|
|
170
|
-
mode: 0o600,
|
|
171
|
-
});
|
|
172
|
-
} catch {
|
|
173
|
-
// Silent fail - cache is optional, don't block submission
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|