getaimeter 0.1.9 → 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.
- package/package.json +1 -1
- package/watcher.js +32 -11
package/package.json
CHANGED
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'))
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
// ---------------------------------------------------------------------------
|
|
@@ -88,6 +106,10 @@ function extractNewUsage(filePath) {
|
|
|
88
106
|
// Skip synthetic/internal messages
|
|
89
107
|
if (obj.message.model === '<synthetic>') continue;
|
|
90
108
|
|
|
109
|
+
// Skip internal Claude Code background calls (compaction, routing, etc.)
|
|
110
|
+
const model = obj.message.model || '';
|
|
111
|
+
if (model.includes('haiku')) continue;
|
|
112
|
+
|
|
91
113
|
// Check for thinking content blocks (appear in streaming progress messages)
|
|
92
114
|
const contentBlocks = obj.message.content || [];
|
|
93
115
|
for (const block of contentBlocks) {
|
|
@@ -100,7 +122,6 @@ function extractNewUsage(filePath) {
|
|
|
100
122
|
if (!obj.message.stop_reason) continue;
|
|
101
123
|
|
|
102
124
|
const u = obj.message.usage;
|
|
103
|
-
const model = obj.message.model || 'unknown';
|
|
104
125
|
|
|
105
126
|
// Estimate thinking tokens: ~4 chars per token (conservative estimate)
|
|
106
127
|
// The API doesn't separate thinking_tokens in the JSONL usage field
|