cc-dev-template 0.1.101 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-dev-template",
3
- "version": "0.1.101",
3
+ "version": "0.1.103",
4
4
  "description": "Structured AI-assisted development framework for Claude Code",
5
5
  "bin": {
6
6
  "cc-dev-template": "./bin/install.js"
@@ -13,15 +13,17 @@
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_CACHE_TTL = 45000; // 45 seconds
24
- const USAGE_HISTORY_MAX = 20; // ~15 min of readings at 45s intervals
23
+ const USAGE_LOCK_PATH = join(homedir(), '.claude', '.usage-cache.lock');
24
+ const USAGE_CACHE_TTL = 120000; // 2 minutes
25
+ const USAGE_LOCK_TTL = 30000; // 30s lock to prevent concurrent refresh spawns
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
27
29
  if (process.argv.includes('--refresh')) {
@@ -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,15 +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) {
379
+ let lockHeld = false;
376
380
  try {
377
- const child = spawn(process.execPath, [__filename, '--refresh'], {
378
- detached: true,
379
- stdio: 'ignore',
380
- });
381
- child.unref();
381
+ const lockTime = parseInt(readFileSync(USAGE_LOCK_PATH, 'utf-8'), 10);
382
+ lockHeld = (Date.now() - lockTime) < USAGE_LOCK_TTL;
382
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
+ }
383
394
  }
384
395
 
385
396
  return { data: cacheData, history: cacheHistory };