getaimeter 0.2.0 → 0.2.1

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 +28 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getaimeter",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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
@@ -31,19 +31,37 @@ function logError(...args) {
31
31
  // Source detection from file path
32
32
  // ---------------------------------------------------------------------------
33
33
 
34
+ // Cache detected sources per file to avoid re-reading headers
35
+ const _sourceCache = new Map();
36
+
34
37
  function detectSource(filePath) {
38
+ if (_sourceCache.has(filePath)) return _sourceCache.get(filePath);
39
+
35
40
  const normalized = filePath.replace(/\\/g, '/');
36
- if (normalized.includes('local-agent-mode-sessions')) return 'desktop_agent_mode';
37
- // VS Code uses lowercase 'c' in the sanitized project dir name on Windows
38
- const projectsMatch = normalized.match(/\.claude\/projects\/([^/])/);
39
- if (projectsMatch) {
40
- const firstChar = projectsMatch[1];
41
- // On Windows: CLI produces uppercase (C--Users), VS Code produces lowercase (c--Users)
42
- if (firstChar === firstChar.toLowerCase() && firstChar !== firstChar.toUpperCase()) {
43
- return 'claude_code_vscode';
44
- }
41
+ if (normalized.includes('local-agent-mode-sessions')) {
42
+ _sourceCache.set(filePath, 'desktop_app');
43
+ return 'desktop_app';
45
44
  }
46
- return 'claude_code_cli';
45
+
46
+ // Read first 10KB of the file to find entrypoint or IDE markers
47
+ let source = 'cli'; // default
48
+ try {
49
+ const fd = fs.openSync(filePath, 'r');
50
+ const buf = Buffer.alloc(Math.min(10240, fs.fstatSync(fd).size));
51
+ fs.readSync(fd, buf, 0, buf.length, 0);
52
+ fs.closeSync(fd);
53
+ const header = buf.toString('utf8');
54
+
55
+ if (header.includes('"entrypoint":"claude-desktop"')) {
56
+ source = 'desktop_app';
57
+ } else if (header.includes('ide_opened_file') || header.includes('"entrypoint":"vscode"')) {
58
+ source = 'vscode';
59
+ }
60
+ // else remains 'cli'
61
+ } catch {}
62
+
63
+ _sourceCache.set(filePath, source);
64
+ return source;
47
65
  }
48
66
 
49
67
  // ---------------------------------------------------------------------------