cc-costline 0.4.0 → 0.4.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/dist/statusline.d.ts +2 -0
- package/dist/statusline.js +18 -3
- package/package.json +1 -1
package/dist/statusline.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { CacheData } from "./cache.js";
|
|
1
2
|
export declare function formatTokens(t: number): string;
|
|
2
3
|
export declare function formatCost(n: number): string;
|
|
3
4
|
export declare function ctxColor(pct: number): string;
|
|
4
5
|
export declare function formatCountdown(resetsAtMs: number): string;
|
|
6
|
+
export declare function shouldRefreshLocalCostCache(cache: CacheData | null, transcriptPath?: string, now?: number): boolean;
|
|
5
7
|
export declare function rankColor(rank: number): string;
|
|
6
8
|
export declare function render(input: string): string;
|
package/dist/statusline.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync, existsSync, writeFileSync, unlinkSync } from "node:fs";
|
|
1
|
+
import { readFileSync, existsSync, statSync, writeFileSync, unlinkSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { execSync } from "node:child_process";
|
|
@@ -49,6 +49,22 @@ export function formatCountdown(resetsAtMs) {
|
|
|
49
49
|
const minutes = totalMinutes % 60;
|
|
50
50
|
return `-${hours}:${String(minutes).padStart(2, "0")}`;
|
|
51
51
|
}
|
|
52
|
+
export function shouldRefreshLocalCostCache(cache, transcriptPath = "", now = Date.now()) {
|
|
53
|
+
if (!cache)
|
|
54
|
+
return true;
|
|
55
|
+
const cacheUpdatedAt = new Date(cache.updatedAt).getTime();
|
|
56
|
+
if (isNaN(cacheUpdatedAt))
|
|
57
|
+
return true;
|
|
58
|
+
if (transcriptPath) {
|
|
59
|
+
try {
|
|
60
|
+
const transcriptMtime = statSync(transcriptPath).mtimeMs;
|
|
61
|
+
if (transcriptMtime > cacheUpdatedAt)
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
catch { }
|
|
65
|
+
}
|
|
66
|
+
return now - cacheUpdatedAt >= CACHE_TTL_MS;
|
|
67
|
+
}
|
|
52
68
|
// ccclub rank fetcher — TTL-based cache (stale fallback on failure)
|
|
53
69
|
function getCcclubRank() {
|
|
54
70
|
const configPath = join(homedir(), ".ccclub", "config.json");
|
|
@@ -231,8 +247,7 @@ export function render(input) {
|
|
|
231
247
|
}
|
|
232
248
|
// Refresh local cost cache if stale
|
|
233
249
|
let cache = readCache();
|
|
234
|
-
|
|
235
|
-
if (cacheAge >= CACHE_TTL_MS) {
|
|
250
|
+
if (shouldRefreshLocalCostCache(cache, transcriptPath)) {
|
|
236
251
|
try {
|
|
237
252
|
const result = collectCosts();
|
|
238
253
|
// Don't overwrite valid cache with zeros (directory read failure)
|