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.
- package/package.json +1 -1
- package/watcher.js +29 -12
package/package.json
CHANGED
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
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
const
|
|
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
|
-
//
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
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
|
-
|
|
656
|
-
|
|
657
|
-
|
|
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
|
|