cc-dev-template 0.1.102 → 0.1.103
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/package.json +1 -1
- package/src/scripts/statusline.js +18 -14
package/package.json
CHANGED
|
@@ -13,14 +13,16 @@
|
|
|
13
13
|
* Output: Formatted status to stdout
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
const { readFileSync, writeFileSync, readdirSync, statSync } = require('fs');
|
|
16
|
+
const { readFileSync, writeFileSync, readdirSync, statSync, unlinkSync } = require('fs');
|
|
17
17
|
const { join, basename } = require('path');
|
|
18
18
|
const { execSync, spawnSync, spawn } = require('child_process');
|
|
19
19
|
const { homedir } = require('os');
|
|
20
20
|
|
|
21
21
|
// Usage API cache
|
|
22
22
|
const USAGE_CACHE_PATH = join(homedir(), '.claude', '.usage-cache.json');
|
|
23
|
+
const USAGE_LOCK_PATH = join(homedir(), '.claude', '.usage-cache.lock');
|
|
23
24
|
const USAGE_CACHE_TTL = 120000; // 2 minutes
|
|
25
|
+
const USAGE_LOCK_TTL = 30000; // 30s lock to prevent concurrent refresh spawns
|
|
24
26
|
const USAGE_HISTORY_MAX = 20; // ~40 min of readings at 2min intervals
|
|
25
27
|
|
|
26
28
|
// Background refresh mode: fetch usage data and write cache, then exit
|
|
@@ -348,6 +350,7 @@ function refreshUsageCache() {
|
|
|
348
350
|
data,
|
|
349
351
|
history,
|
|
350
352
|
}));
|
|
353
|
+
try { unlinkSync(USAGE_LOCK_PATH); } catch {}
|
|
351
354
|
}
|
|
352
355
|
}
|
|
353
356
|
} catch {
|
|
@@ -371,22 +374,23 @@ function getUsageData() {
|
|
|
371
374
|
cacheAge = Date.now() - cache.timestamp;
|
|
372
375
|
} catch {}
|
|
373
376
|
|
|
374
|
-
// Trigger background refresh if cache is stale
|
|
377
|
+
// Trigger background refresh if cache is stale and no other refresh is running
|
|
375
378
|
if (cacheAge > USAGE_CACHE_TTL) {
|
|
376
|
-
|
|
379
|
+
let lockHeld = false;
|
|
377
380
|
try {
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
cache.timestamp = Date.now();
|
|
381
|
-
writeFileSync(USAGE_CACHE_PATH, JSON.stringify(cache));
|
|
382
|
-
} catch {}
|
|
383
|
-
try {
|
|
384
|
-
const child = spawn(process.execPath, [__filename, '--refresh'], {
|
|
385
|
-
detached: true,
|
|
386
|
-
stdio: 'ignore',
|
|
387
|
-
});
|
|
388
|
-
child.unref();
|
|
381
|
+
const lockTime = parseInt(readFileSync(USAGE_LOCK_PATH, 'utf-8'), 10);
|
|
382
|
+
lockHeld = (Date.now() - lockTime) < USAGE_LOCK_TTL;
|
|
389
383
|
} catch {}
|
|
384
|
+
if (!lockHeld) {
|
|
385
|
+
try { writeFileSync(USAGE_LOCK_PATH, String(Date.now())); } catch {}
|
|
386
|
+
try {
|
|
387
|
+
const child = spawn(process.execPath, [__filename, '--refresh'], {
|
|
388
|
+
detached: true,
|
|
389
|
+
stdio: 'ignore',
|
|
390
|
+
});
|
|
391
|
+
child.unref();
|
|
392
|
+
} catch {}
|
|
393
|
+
}
|
|
390
394
|
}
|
|
391
395
|
|
|
392
396
|
return { data: cacheData, history: cacheHistory };
|