getaimeter 0.1.2 → 0.1.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 +22 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getaimeter",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Track your Claude AI usage across CLI, VS Code, and Desktop App. One command to start.",
5
5
  "bin": {
6
6
  "aimeter": "cli.js"
package/watcher.js CHANGED
@@ -240,7 +240,7 @@ function startWatching() {
240
240
  }
241
241
  saveState();
242
242
 
243
- // Set up fs.watch on each path
243
+ // Set up fs.watch on each path (works well on macOS/Linux)
244
244
  const watchers = [];
245
245
  for (const watchPath of watchPaths) {
246
246
  try {
@@ -255,18 +255,38 @@ function startWatching() {
255
255
  });
256
256
 
257
257
  watchers.push(w);
258
- log('Watching:', watchPath);
258
+ log('Watching (fs.watch):', watchPath);
259
259
  } catch (err) {
260
260
  logError(`Could not watch ${watchPath}:`, err.message);
261
261
  }
262
262
  }
263
263
 
264
+ // Polling fallback — fs.watch is unreliable on Windows for deeply nested dirs.
265
+ // Every 5 seconds, scan all known JSONL files for size changes.
266
+ const POLL_INTERVAL = 5_000;
267
+ const pollInterval = setInterval(() => {
268
+ for (const watchPath of watchPaths) {
269
+ const files = findJsonlFiles(watchPath);
270
+ for (const file of files) {
271
+ try {
272
+ const currentSize = fs.statSync(file).size;
273
+ const lastOffset = getOffset(file);
274
+ if (currentSize > lastOffset) {
275
+ handleFileChange(file);
276
+ }
277
+ } catch {}
278
+ }
279
+ }
280
+ }, POLL_INTERVAL);
281
+ log(`Polling every ${POLL_INTERVAL / 1000}s as fallback`);
282
+
264
283
  // Periodic state save
265
284
  const saveInterval = setInterval(() => saveState(), 30_000);
266
285
 
267
286
  // Return cleanup
268
287
  return () => {
269
288
  clearInterval(saveInterval);
289
+ clearInterval(pollInterval);
270
290
  for (const w of watchers) w.close();
271
291
  for (const t of _debounceTimers.values()) clearTimeout(t);
272
292
  saveState();