@tokenboard/cli 0.1.5 → 0.1.6
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/cli.js +48 -15
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -587,13 +587,13 @@ function _getBuiltinFlags(long, short, userNames, userAliases) {
|
|
|
587
587
|
|
|
588
588
|
// src/commands/preview.ts
|
|
589
589
|
init_esm_shims();
|
|
590
|
-
import { homedir as
|
|
590
|
+
import { homedir as homedir3 } from "os";
|
|
591
591
|
|
|
592
592
|
// src/config/home.ts
|
|
593
593
|
init_esm_shims();
|
|
594
594
|
import { join } from "path";
|
|
595
|
-
function resolveProjectsRoot(
|
|
596
|
-
return join(
|
|
595
|
+
function resolveProjectsRoot(homedir4) {
|
|
596
|
+
return join(homedir4, ".claude", "projects");
|
|
597
597
|
}
|
|
598
598
|
|
|
599
599
|
// src/collectors/claude-code-source.ts
|
|
@@ -794,6 +794,9 @@ function parsedLineToRecord(line, timeZone) {
|
|
|
794
794
|
// src/collectors/ccusage-source.ts
|
|
795
795
|
init_esm_shims();
|
|
796
796
|
import { spawn, spawnSync } from "child_process";
|
|
797
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync3 } from "fs";
|
|
798
|
+
import { homedir } from "os";
|
|
799
|
+
import { join as join4 } from "path";
|
|
797
800
|
|
|
798
801
|
// src/collectors/ccusage-sources.ts
|
|
799
802
|
init_esm_shims();
|
|
@@ -847,7 +850,30 @@ function ccusageDailyToRecords(source, daily) {
|
|
|
847
850
|
|
|
848
851
|
// src/collectors/ccusage-source.ts
|
|
849
852
|
var SPAWN_TIMEOUT_MS = 3e4;
|
|
853
|
+
var CCUSAGE_MAJOR = 20;
|
|
850
854
|
var CLAUDE_AGENT = "claude";
|
|
855
|
+
function resolveCachedCcusageV20(npxCache = join4(homedir(), ".npm", "_npx")) {
|
|
856
|
+
try {
|
|
857
|
+
for (const hash of readdirSync2(npxCache)) {
|
|
858
|
+
const pkgDir = join4(npxCache, hash, "node_modules", "ccusage");
|
|
859
|
+
let pkg;
|
|
860
|
+
try {
|
|
861
|
+
pkg = JSON.parse(readFileSync3(join4(pkgDir, "package.json"), "utf8"));
|
|
862
|
+
} catch {
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
if (typeof pkg.version !== "string") continue;
|
|
866
|
+
const major = Number.parseInt(pkg.version.split(".")[0] ?? "", 10);
|
|
867
|
+
if (major !== CCUSAGE_MAJOR) continue;
|
|
868
|
+
const binField = pkg.bin;
|
|
869
|
+
const binRel = typeof binField === "string" ? binField : typeof binField === "object" && binField !== null ? binField["ccusage"] : void 0;
|
|
870
|
+
if (typeof binRel !== "string") continue;
|
|
871
|
+
return join4(pkgDir, binRel);
|
|
872
|
+
}
|
|
873
|
+
} catch {
|
|
874
|
+
}
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
851
877
|
function hasNpx() {
|
|
852
878
|
try {
|
|
853
879
|
const r = spawnSync("npx", ["--version"], { stdio: "ignore" });
|
|
@@ -856,9 +882,16 @@ function hasNpx() {
|
|
|
856
882
|
return false;
|
|
857
883
|
}
|
|
858
884
|
}
|
|
885
|
+
var cachedBinPath;
|
|
886
|
+
function ccusageV20Bin() {
|
|
887
|
+
if (cachedBinPath === void 0) cachedBinPath = resolveCachedCcusageV20();
|
|
888
|
+
return cachedBinPath;
|
|
889
|
+
}
|
|
859
890
|
function runCcusage(args) {
|
|
891
|
+
const bin = ccusageV20Bin();
|
|
892
|
+
const [cmd, cmdArgs] = bin ? [process.execPath, [bin, ...args]] : ["npx", ["-y", "ccusage@20", ...args]];
|
|
860
893
|
return new Promise((resolve, reject) => {
|
|
861
|
-
const child = spawn(
|
|
894
|
+
const child = spawn(cmd, cmdArgs, { stdio: ["ignore", "pipe", "ignore"] });
|
|
862
895
|
let stdout = "";
|
|
863
896
|
const killer = setTimeout(() => child.kill("SIGKILL"), SPAWN_TIMEOUT_MS);
|
|
864
897
|
child.stdout.on("data", (chunk2) => {
|
|
@@ -909,7 +942,7 @@ function canSkipFanOut(agents) {
|
|
|
909
942
|
return [...agents].every((a) => a === CLAUDE_AGENT);
|
|
910
943
|
}
|
|
911
944
|
async function collectCcusage() {
|
|
912
|
-
if (!hasNpx()) {
|
|
945
|
+
if (ccusageV20Bin() === null && !hasNpx()) {
|
|
913
946
|
return { records: [], skipped: [], npxAvailable: false };
|
|
914
947
|
}
|
|
915
948
|
const agents = await detectAgentsWithData();
|
|
@@ -1880,27 +1913,27 @@ var CLAIM_HINT = "\u2192 Claim your spot anytime \u2192 tokenboard claim";
|
|
|
1880
1913
|
|
|
1881
1914
|
// src/config/auth-store.ts
|
|
1882
1915
|
init_esm_shims();
|
|
1883
|
-
import { homedir, platform } from "os";
|
|
1884
|
-
import { join as
|
|
1916
|
+
import { homedir as homedir2, platform } from "os";
|
|
1917
|
+
import { join as join5, isAbsolute } from "path";
|
|
1885
1918
|
import { mkdir, writeFile, chmod, rename, unlink, readFile } from "fs/promises";
|
|
1886
1919
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
1887
1920
|
function resolveConfigDir(env = process.env) {
|
|
1888
1921
|
if (platform() === "win32") {
|
|
1889
|
-
const appData = env.APPDATA && env.APPDATA.trim() !== "" ? env.APPDATA :
|
|
1890
|
-
return
|
|
1922
|
+
const appData = env.APPDATA && env.APPDATA.trim() !== "" ? env.APPDATA : join5(homedir2(), "AppData", "Roaming");
|
|
1923
|
+
return join5(appData, "tokenboard");
|
|
1891
1924
|
}
|
|
1892
1925
|
const xdg = env.XDG_CONFIG_HOME;
|
|
1893
|
-
const base = xdg && isAbsolute(xdg) ? xdg :
|
|
1894
|
-
return
|
|
1926
|
+
const base = xdg && isAbsolute(xdg) ? xdg : join5(homedir2(), ".config");
|
|
1927
|
+
return join5(base, "tokenboard");
|
|
1895
1928
|
}
|
|
1896
1929
|
function resolveAuthPath(env = process.env) {
|
|
1897
|
-
return
|
|
1930
|
+
return join5(resolveConfigDir(env), "auth.json");
|
|
1898
1931
|
}
|
|
1899
1932
|
async function writeAuthFile(auth, env = process.env) {
|
|
1900
1933
|
const dir = resolveConfigDir(env);
|
|
1901
|
-
const finalPath =
|
|
1934
|
+
const finalPath = join5(dir, "auth.json");
|
|
1902
1935
|
await mkdir(dir, { recursive: true, mode: 448 });
|
|
1903
|
-
const tmpPath =
|
|
1936
|
+
const tmpPath = join5(dir, `.auth.json.${randomBytes2(6).toString("hex")}.tmp`);
|
|
1904
1937
|
const body = `${JSON.stringify(auth, null, 2)}
|
|
1905
1938
|
`;
|
|
1906
1939
|
try {
|
|
@@ -2487,7 +2520,7 @@ async function runClaim() {
|
|
|
2487
2520
|
// src/commands/preview.ts
|
|
2488
2521
|
async function collectLocalRecords() {
|
|
2489
2522
|
const tz = resolveTimeZone();
|
|
2490
|
-
const files = findJsonlFiles(resolveProjectsRoot(
|
|
2523
|
+
const files = findJsonlFiles(resolveProjectsRoot(homedir3()));
|
|
2491
2524
|
const [claudeLines, ccusage] = await Promise.all([
|
|
2492
2525
|
Promise.resolve().then(() => dedupeByMessageId(collectClaudeCodeLinesCached(files, resolveConfigDir()))),
|
|
2493
2526
|
collectCcusage()
|