acp-extension-claude 0.13.10 → 0.13.11
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/usage.d.ts +0 -1
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +0 -68
- package/package.json +1 -1
package/dist/usage.d.ts
CHANGED
|
@@ -27,6 +27,5 @@ export type UsageApiDeps = {
|
|
|
27
27
|
* Cache TTL: 60s for success, 15s for failures.
|
|
28
28
|
*/
|
|
29
29
|
export declare function getUsage(overrides?: Partial<UsageApiDeps>): Promise<UsageData | null>;
|
|
30
|
-
export declare function clearCache(homeDir?: string): void;
|
|
31
30
|
export {};
|
|
32
31
|
//# sourceMappingURL=usage.d.ts.map
|
package/dist/usage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAa9C,UAAU,gBAAgB;IACtB,SAAS,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,SAAS,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACL;
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAa9C,UAAU,gBAAgB;IACtB,SAAS,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,SAAS,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACL;AAYD,MAAM,MAAM,YAAY,GAAG;IACvB,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IACpE,GAAG,EAAE,MAAM,MAAM,CAAC;IAClB,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CAC5G,CAAC;AASF;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAAC,SAAS,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAuD/F"}
|
package/dist/usage.js
CHANGED
|
@@ -4,54 +4,8 @@ import * as path from 'path';
|
|
|
4
4
|
import * as os from 'os';
|
|
5
5
|
import * as https from 'https';
|
|
6
6
|
import { execFileSync } from 'child_process';
|
|
7
|
-
// File-based cache (HUD runs as new process each render, so in-memory cache won't persist)
|
|
8
|
-
const CACHE_TTL_MS = 60000; // 60 seconds
|
|
9
|
-
const CACHE_FAILURE_TTL_MS = 15000; // 15 seconds for failed requests
|
|
10
7
|
const KEYCHAIN_TIMEOUT_MS = 5000;
|
|
11
8
|
const KEYCHAIN_BACKOFF_MS = 60000; // Backoff on keychain failures to avoid re-prompting
|
|
12
|
-
function getCachePath(homeDir) {
|
|
13
|
-
return path.join(homeDir, '.claude', 'plugins', 'claude-hud', '.usage-cache.json');
|
|
14
|
-
}
|
|
15
|
-
function readCache(homeDir, now) {
|
|
16
|
-
try {
|
|
17
|
-
const cachePath = getCachePath(homeDir);
|
|
18
|
-
if (!fs.existsSync(cachePath))
|
|
19
|
-
return null;
|
|
20
|
-
const content = fs.readFileSync(cachePath, 'utf8');
|
|
21
|
-
const cache = JSON.parse(content);
|
|
22
|
-
// Check TTL - use shorter TTL for failure results
|
|
23
|
-
const ttl = cache.data.apiUnavailable ? CACHE_FAILURE_TTL_MS : CACHE_TTL_MS;
|
|
24
|
-
if (now - cache.timestamp >= ttl)
|
|
25
|
-
return null;
|
|
26
|
-
// JSON.stringify converts Date to ISO string, so we need to reconvert on read.
|
|
27
|
-
// new Date() handles both Date objects and ISO strings safely.
|
|
28
|
-
const data = cache.data;
|
|
29
|
-
if (data.fiveHourResetAt) {
|
|
30
|
-
data.fiveHourResetAt = data.fiveHourResetAt;
|
|
31
|
-
}
|
|
32
|
-
if (data.sevenDayResetAt) {
|
|
33
|
-
data.sevenDayResetAt = data.sevenDayResetAt;
|
|
34
|
-
}
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function writeCache(homeDir, data, timestamp) {
|
|
42
|
-
try {
|
|
43
|
-
const cachePath = getCachePath(homeDir);
|
|
44
|
-
const cacheDir = path.dirname(cachePath);
|
|
45
|
-
if (!fs.existsSync(cacheDir)) {
|
|
46
|
-
fs.mkdirSync(cacheDir, { recursive: true });
|
|
47
|
-
}
|
|
48
|
-
const cache = { data, timestamp };
|
|
49
|
-
fs.writeFileSync(cachePath, JSON.stringify(cache), 'utf8');
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
// Ignore cache write failures
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
9
|
const defaultDeps = {
|
|
56
10
|
homeDir: () => os.homedir(),
|
|
57
11
|
fetchApi: fetchUsageApi,
|
|
@@ -70,11 +24,6 @@ export async function getUsage(overrides = {}) {
|
|
|
70
24
|
const deps = { ...defaultDeps, ...overrides };
|
|
71
25
|
const now = deps.now();
|
|
72
26
|
const homeDir = deps.homeDir();
|
|
73
|
-
// Check file-based cache first
|
|
74
|
-
const cached = readCache(homeDir, now);
|
|
75
|
-
if (cached) {
|
|
76
|
-
return cached;
|
|
77
|
-
}
|
|
78
27
|
try {
|
|
79
28
|
const credentials = readCredentials(homeDir, now, deps.readKeychain);
|
|
80
29
|
if (!credentials) {
|
|
@@ -99,7 +48,6 @@ export async function getUsage(overrides = {}) {
|
|
|
99
48
|
sevenDayResetAt: null,
|
|
100
49
|
apiUnavailable: true,
|
|
101
50
|
};
|
|
102
|
-
writeCache(homeDir, failureResult, now);
|
|
103
51
|
return failureResult;
|
|
104
52
|
}
|
|
105
53
|
// Parse response - API returns 0-100 percentage directly
|
|
@@ -115,8 +63,6 @@ export async function getUsage(overrides = {}) {
|
|
|
115
63
|
fiveHourResetAt,
|
|
116
64
|
sevenDayResetAt,
|
|
117
65
|
};
|
|
118
|
-
// Write to file cache
|
|
119
|
-
writeCache(homeDir, result, now);
|
|
120
66
|
return result;
|
|
121
67
|
}
|
|
122
68
|
catch (error) {
|
|
@@ -338,17 +284,3 @@ function fetchUsageApi(accessToken) {
|
|
|
338
284
|
req.end();
|
|
339
285
|
});
|
|
340
286
|
}
|
|
341
|
-
// Export for testing
|
|
342
|
-
export function clearCache(homeDir) {
|
|
343
|
-
if (homeDir) {
|
|
344
|
-
try {
|
|
345
|
-
const cachePath = getCachePath(homeDir);
|
|
346
|
-
if (fs.existsSync(cachePath)) {
|
|
347
|
-
fs.unlinkSync(cachePath);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
catch {
|
|
351
|
-
// Ignore
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|