getaimeter 0.6.1 → 0.6.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/watcher.js +29 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getaimeter",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Track AI coding costs across Claude, Cursor, Codex, and Gemini. Optimization recommendations that cut costs by 30%.",
5
5
  "bin": {
6
6
  "aimeter": "cli.js"
package/watcher.js CHANGED
@@ -372,10 +372,18 @@ function extractCursorUsage(dbPath) {
372
372
  if (!findSqlite3()) return [];
373
373
  if (!fs.existsSync(dbPath)) return [];
374
374
 
375
- // Check if the DB file has been modified since our last check
376
- let stat;
377
- try { stat = fs.statSync(dbPath); } catch { return []; }
378
- const currentMtime = stat.mtimeMs;
375
+ // Check if the DB has been modified since our last check.
376
+ // SQLite WAL mode: writes go to dbPath-wal, not the main file.
377
+ // We check the WAL file's mtime (if it exists) since that's what changes.
378
+ const walPath = dbPath + '-wal';
379
+ let currentMtime;
380
+ try {
381
+ if (fs.existsSync(walPath)) {
382
+ currentMtime = fs.statSync(walPath).mtimeMs;
383
+ } else {
384
+ currentMtime = fs.statSync(dbPath).mtimeMs;
385
+ }
386
+ } catch { return []; }
379
387
  const lastMtime = getOffset(dbPath + ':mtime');
380
388
  if (currentMtime <= lastMtime) return [];
381
389
 
@@ -646,17 +654,26 @@ function startWatching() {
646
654
  const cursorDbs = findCursorDbs(watchPaths);
647
655
  if (cursorDbs.length > 0) {
648
656
  log('Cursor databases found:', cursorDbs.join(', '));
649
- // Mark existing Cursor data as seen on first run
650
- if (isFirstRun) {
651
- for (const dbPath of cursorDbs) {
652
- try {
657
+ // Always pre-populate _cursorSeenKeys on startup so we don't re-report
658
+ // historical conversations. On first run, also set the mtime offset.
659
+ for (const dbPath of cursorDbs) {
660
+ try {
661
+ if (isFirstRun) {
653
662
  const mtime = fs.statSync(dbPath).mtimeMs;
654
663
  setOffset(dbPath + ':mtime', mtime);
655
- // Pre-populate seen keys so we don't report historical data
656
- extractCursorUsage(dbPath); // populates _cursorSeenKeys but we discard results
657
- } catch {}
664
+ }
665
+ // Dry-run extraction to populate _cursorSeenKeys (discard results)
666
+ const existing = extractCursorUsage(dbPath);
667
+ if (isFirstRun && existing.length > 0) {
668
+ log(`Cursor: marked ${existing.length} existing conversations as read`);
669
+ } else if (existing.length > 0) {
670
+ // Not first run but has new data since last mtime — report it
671
+ reportEvents(existing);
672
+ log(`Cursor: catch-up reported ${existing.length} events`);
673
+ }
674
+ } catch (err) {
675
+ logError('Cursor startup scan:', err.message);
658
676
  }
659
- log('Cursor: marked existing conversations as read');
660
677
  }
661
678
  }
662
679