gusage 1.1.2 → 1.2.1
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/README.md +1 -0
- package/dist/index.js +82 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,7 @@ gusage --json --watch 5s | jq .
|
|
|
67
67
|
- `-n, --notify [threshold]`: Send a desktop notification when a model drops below the threshold percent (default: `20`). Requires `--watch`.
|
|
68
68
|
- `-j, --json`: Output raw JSON instead of a table. Can be combined with `--watch` for streaming data.
|
|
69
69
|
- `--no-color`: Disable color output (also respects `NO_COLOR` env var).
|
|
70
|
+
- `-v, --version`: Show version.
|
|
70
71
|
|
|
71
72
|
## Requirements
|
|
72
73
|
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,55 @@ import os from "os";
|
|
|
8
8
|
import crypto from "crypto";
|
|
9
9
|
import { parseArgs } from "util";
|
|
10
10
|
import { execSync, spawn } from "child_process";
|
|
11
|
+
// package.json
|
|
12
|
+
var package_default = {
|
|
13
|
+
name: "gusage",
|
|
14
|
+
version: "1.2.1",
|
|
15
|
+
description: "A standalone CLI to export Gemini CLI quota and usage statistics",
|
|
16
|
+
module: "index.ts",
|
|
17
|
+
type: "module",
|
|
18
|
+
bin: {
|
|
19
|
+
gusage: "dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
files: [
|
|
22
|
+
"dist/index.js",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
author: "Abdellah Hariti <haritiabdellah@gmail.com>",
|
|
27
|
+
license: "MIT",
|
|
28
|
+
private: false,
|
|
29
|
+
scripts: {
|
|
30
|
+
format: "prettier --write .",
|
|
31
|
+
prepare: "husky",
|
|
32
|
+
build: "bun build ./index.ts --outfile dist/index.js && chmod +x dist/index.js",
|
|
33
|
+
prepack: "bun run build"
|
|
34
|
+
},
|
|
35
|
+
"lint-staged": {
|
|
36
|
+
"*": "prettier --write --ignore-unknown",
|
|
37
|
+
"*.ts": "bash -c 'bun x tsc --noEmit'"
|
|
38
|
+
},
|
|
39
|
+
devDependencies: {
|
|
40
|
+
"@types/bun": "latest",
|
|
41
|
+
husky: "^9.1.7",
|
|
42
|
+
"lint-staged": "^16.2.7",
|
|
43
|
+
prettier: "^3.8.1"
|
|
44
|
+
},
|
|
45
|
+
peerDependencies: {
|
|
46
|
+
typescript: "^5"
|
|
47
|
+
},
|
|
48
|
+
keywords: [
|
|
49
|
+
"gemini-cli",
|
|
50
|
+
"gemini",
|
|
51
|
+
"google-gemini",
|
|
52
|
+
"quota",
|
|
53
|
+
"usage",
|
|
54
|
+
"stats",
|
|
55
|
+
"monitoring"
|
|
56
|
+
]
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// index.ts
|
|
11
60
|
var OAUTH_CLIENT_ID = "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com";
|
|
12
61
|
var OAUTH_CLIENT_SECRET = "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";
|
|
13
62
|
var CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com";
|
|
@@ -87,6 +136,27 @@ function validateNotifyRuntime(notifyThreshold, isWatching, hasNotificationSuppo
|
|
|
87
136
|
function shouldSendThresholdNotification(prevFraction, currentFraction, threshold) {
|
|
88
137
|
return prevFraction !== undefined && prevFraction > threshold && currentFraction <= threshold;
|
|
89
138
|
}
|
|
139
|
+
function parseWatchIntervalArg(raw) {
|
|
140
|
+
let totalMs = 0;
|
|
141
|
+
let found = false;
|
|
142
|
+
const normalizedParts = [];
|
|
143
|
+
const matches = raw.matchAll(/(\d+)(h|m|s)?/g);
|
|
144
|
+
for (const match of matches) {
|
|
145
|
+
found = true;
|
|
146
|
+
const val = parseInt(match[1], 10);
|
|
147
|
+
const unit = match[2] || "s";
|
|
148
|
+
normalizedParts.push(`${val}${unit}`);
|
|
149
|
+
if (unit === "s")
|
|
150
|
+
totalMs += val * 1000;
|
|
151
|
+
else if (unit === "m")
|
|
152
|
+
totalMs += val * 60000;
|
|
153
|
+
else if (unit === "h")
|
|
154
|
+
totalMs += val * 3600000;
|
|
155
|
+
}
|
|
156
|
+
if (!found)
|
|
157
|
+
return null;
|
|
158
|
+
return { intervalMs: totalMs, intervalStr: normalizedParts.join("") };
|
|
159
|
+
}
|
|
90
160
|
function parseVersion(modelId) {
|
|
91
161
|
const match = modelId.match(/gemini-(\d+)(?:\.(\d+))?-(.*)/);
|
|
92
162
|
if (match) {
|
|
@@ -140,6 +210,7 @@ function padVisual(str, width, side = "right") {
|
|
|
140
210
|
return side === "right" ? str + pad : pad + str;
|
|
141
211
|
}
|
|
142
212
|
async function main() {
|
|
213
|
+
const packageVersion = package_default.version;
|
|
143
214
|
const args = Bun.argv.slice(2);
|
|
144
215
|
const watchIdx = args.findIndex((a) => a === "--watch" || a === "-w");
|
|
145
216
|
if (watchIdx !== -1 && (watchIdx === args.length - 1 || args[watchIdx + 1].startsWith("-"))) {
|
|
@@ -153,6 +224,7 @@ async function main() {
|
|
|
153
224
|
args,
|
|
154
225
|
options: {
|
|
155
226
|
help: { type: "boolean", short: "h" },
|
|
227
|
+
version: { type: "boolean", short: "v" },
|
|
156
228
|
json: { type: "boolean", short: "j" },
|
|
157
229
|
"no-color": { type: "boolean" },
|
|
158
230
|
watch: { type: "string", short: "w" },
|
|
@@ -166,6 +238,7 @@ Usage: gusage [options]
|
|
|
166
238
|
|
|
167
239
|
Options:
|
|
168
240
|
-h, --help Show this help message
|
|
241
|
+
-v, --version Show version and exit
|
|
169
242
|
-w, --watch [interval] Update live every interval (default: 10s).
|
|
170
243
|
Supports combined units: 20s, 5m, 1m20s.
|
|
171
244
|
-n, --notify [threshold] Show a critical OS notification if any model falls below
|
|
@@ -175,28 +248,19 @@ Options:
|
|
|
175
248
|
`);
|
|
176
249
|
return;
|
|
177
250
|
}
|
|
251
|
+
if (values.version) {
|
|
252
|
+
console.log(packageVersion);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
178
255
|
const isWatching = values.watch !== undefined;
|
|
179
256
|
const isJson = values.json === true;
|
|
180
257
|
let intervalMs = 1e4;
|
|
181
258
|
let intervalStr = "10s";
|
|
182
259
|
if (values.watch) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
found = true;
|
|
188
|
-
const val = parseInt(match[1], 10);
|
|
189
|
-
const unit = match[2] || "s";
|
|
190
|
-
if (unit === "s")
|
|
191
|
-
totalMs += val * 1000;
|
|
192
|
-
else if (unit === "m")
|
|
193
|
-
totalMs += val * 60000;
|
|
194
|
-
else if (unit === "h")
|
|
195
|
-
totalMs += val * 3600000;
|
|
196
|
-
}
|
|
197
|
-
if (found) {
|
|
198
|
-
intervalMs = totalMs;
|
|
199
|
-
intervalStr = values.watch;
|
|
260
|
+
const parsedWatch = parseWatchIntervalArg(values.watch);
|
|
261
|
+
if (parsedWatch) {
|
|
262
|
+
intervalMs = parsedWatch.intervalMs;
|
|
263
|
+
intervalStr = parsedWatch.intervalStr;
|
|
200
264
|
}
|
|
201
265
|
}
|
|
202
266
|
const useColor = !values["no-color"] && !process.env.NO_COLOR && process.stdout.isTTY;
|
|
@@ -455,6 +519,7 @@ async function refreshAccessToken(refreshToken) {
|
|
|
455
519
|
export {
|
|
456
520
|
validateNotifyRuntime,
|
|
457
521
|
shouldSendThresholdNotification,
|
|
522
|
+
parseWatchIntervalArg,
|
|
458
523
|
parseNotifyThresholdArg,
|
|
459
524
|
main as default
|
|
460
525
|
};
|