ccclub 0.2.79 → 0.2.81
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.js +30 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -452,35 +452,42 @@ async function fetchUsageLimits() {
|
|
|
452
452
|
debug("returning null: token expired at", expiresAt);
|
|
453
453
|
return null;
|
|
454
454
|
}
|
|
455
|
-
const curlCmd = `curl -
|
|
455
|
+
const curlCmd = `curl -s --max-time 8 "https://api.anthropic.com/api/oauth/usage" -H "Authorization: Bearer ${accessToken}" -H "anthropic-beta: oauth-2025-04-20" -H "User-Agent: claude-code/2.1.5"`;
|
|
456
456
|
debug("running curl...");
|
|
457
457
|
const { stdout: stdout5 } = await execAsync(curlCmd, { timeout: 9e3 });
|
|
458
458
|
debug("curl stdout length:", stdout5.length, "first 100:", stdout5.slice(0, 100));
|
|
459
|
-
if (
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
459
|
+
if (stdout5) {
|
|
460
|
+
const data = JSON.parse(stdout5);
|
|
461
|
+
if (!data.error) {
|
|
462
|
+
const fiveHourRaw = data.five_hour?.utilization;
|
|
463
|
+
const sevenDayRaw = data.seven_day?.utilization;
|
|
464
|
+
const result = {
|
|
465
|
+
fiveHour: parseUtilization(fiveHourRaw),
|
|
466
|
+
sevenDay: parseUtilization(sevenDayRaw),
|
|
467
|
+
snapshotAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
468
|
+
};
|
|
469
|
+
debug("returning snapshot:", result.fiveHour, result.sevenDay);
|
|
470
|
+
writeCache(result);
|
|
471
|
+
return result;
|
|
472
|
+
}
|
|
473
|
+
debug("API error response:", data.error);
|
|
467
474
|
}
|
|
468
|
-
const fiveHourRaw = data.five_hour?.utilization;
|
|
469
|
-
const sevenDayRaw = data.seven_day?.utilization;
|
|
470
|
-
const result = {
|
|
471
|
-
fiveHour: parseUtilization(fiveHourRaw),
|
|
472
|
-
sevenDay: parseUtilization(sevenDayRaw),
|
|
473
|
-
snapshotAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
474
|
-
};
|
|
475
|
-
debug("returning snapshot:", result.fiveHour, result.sevenDay);
|
|
476
|
-
writeCache(result);
|
|
477
|
-
return result;
|
|
478
475
|
} catch (err) {
|
|
479
476
|
debug("caught error:", err instanceof Error ? err.message : String(err));
|
|
480
|
-
const stale = readCache(true);
|
|
481
|
-
if (stale) debug("returning stale cache as fallback:", stale.fiveHour, stale.sevenDay);
|
|
482
|
-
return stale;
|
|
483
477
|
}
|
|
478
|
+
try {
|
|
479
|
+
const tmp = JSON.parse(readFileSync2("/tmp/sl-claude-usage", "utf-8"));
|
|
480
|
+
if (typeof tmp.fiveHour === "number" && typeof tmp.sevenDay === "number") {
|
|
481
|
+
const result = { fiveHour: tmp.fiveHour, sevenDay: tmp.sevenDay, snapshotAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
482
|
+
debug("returning cc-costline cache fallback:", result.fiveHour, result.sevenDay);
|
|
483
|
+
writeCache(result);
|
|
484
|
+
return result;
|
|
485
|
+
}
|
|
486
|
+
} catch {
|
|
487
|
+
}
|
|
488
|
+
const stale = readCache(true);
|
|
489
|
+
if (stale) debug("returning stale cache as fallback:", stale.fiveHour, stale.sevenDay);
|
|
490
|
+
return stale;
|
|
484
491
|
}
|
|
485
492
|
|
|
486
493
|
// src/commands/sync.ts
|
|
@@ -1387,7 +1394,7 @@ async function hookCommand() {
|
|
|
1387
1394
|
}
|
|
1388
1395
|
|
|
1389
1396
|
// src/index.ts
|
|
1390
|
-
var VERSION = "0.2.
|
|
1397
|
+
var VERSION = "0.2.81";
|
|
1391
1398
|
startUpdateCheck(VERSION);
|
|
1392
1399
|
var program = new Command();
|
|
1393
1400
|
program.name("ccclub").description("Claude Code leaderboard among friends").version(VERSION, "-v, -V, --version");
|