getaimeter 0.1.0 → 0.1.2
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/service.js +4 -4
- package/update-check.js +1 -1
- package/watcher.js +11 -6
package/package.json
CHANGED
package/service.js
CHANGED
|
@@ -35,7 +35,7 @@ function getWatcherScript() {
|
|
|
35
35
|
const { execSync } = require('child_process');
|
|
36
36
|
try {
|
|
37
37
|
const globalBin = execSync('npm root -g', { encoding: 'utf8' }).trim();
|
|
38
|
-
const globalCli = path.join(globalBin, '
|
|
38
|
+
const globalCli = path.join(globalBin, 'getaimeter', 'cli.js');
|
|
39
39
|
if (fs.existsSync(globalCli)) return globalCli;
|
|
40
40
|
} catch {}
|
|
41
41
|
|
|
@@ -45,13 +45,13 @@ function getWatcherScript() {
|
|
|
45
45
|
console.log('');
|
|
46
46
|
try {
|
|
47
47
|
const { execSync: ex } = require('child_process');
|
|
48
|
-
ex('npm install -g
|
|
48
|
+
ex('npm install -g getaimeter', { stdio: 'inherit' });
|
|
49
49
|
const globalBin = ex('npm root -g', { encoding: 'utf8' }).trim();
|
|
50
|
-
const globalCli = path.join(globalBin, '
|
|
50
|
+
const globalCli = path.join(globalBin, 'getaimeter', 'cli.js');
|
|
51
51
|
if (fs.existsSync(globalCli)) return globalCli;
|
|
52
52
|
} catch {
|
|
53
53
|
console.log(' Could not install globally. Install manually:');
|
|
54
|
-
console.log(' npm install -g
|
|
54
|
+
console.log(' npm install -g getaimeter');
|
|
55
55
|
console.log(' Then run: aimeter install');
|
|
56
56
|
}
|
|
57
57
|
}
|
package/update-check.js
CHANGED
|
@@ -68,7 +68,7 @@ function showUpdateMessage(latest) {
|
|
|
68
68
|
const current = getCurrentVersion();
|
|
69
69
|
console.log('');
|
|
70
70
|
console.log(` Update available: ${current} → ${latest}`);
|
|
71
|
-
console.log(` Run: npm update -g
|
|
71
|
+
console.log(` Run: npm update -g getaimeter`);
|
|
72
72
|
console.log('');
|
|
73
73
|
}
|
|
74
74
|
|
package/watcher.js
CHANGED
|
@@ -72,9 +72,11 @@ function extractNewUsage(filePath) {
|
|
|
72
72
|
if (lastOffset > 0 && lines.length > 0) lines.shift();
|
|
73
73
|
|
|
74
74
|
const usageEvents = [];
|
|
75
|
+
let lineOffset = lastOffset;
|
|
75
76
|
|
|
76
77
|
for (const line of lines) {
|
|
77
78
|
const trimmed = line.trim();
|
|
79
|
+
lineOffset += Buffer.byteLength(line + '\n', 'utf8');
|
|
78
80
|
if (!trimmed) continue;
|
|
79
81
|
|
|
80
82
|
let obj;
|
|
@@ -85,9 +87,9 @@ function extractNewUsage(filePath) {
|
|
|
85
87
|
const u = obj.message.usage;
|
|
86
88
|
const model = obj.message.model || 'unknown';
|
|
87
89
|
|
|
88
|
-
// Build dedup hash
|
|
90
|
+
// Build dedup hash — include line offset for uniqueness
|
|
89
91
|
const hash = crypto.createHash('md5')
|
|
90
|
-
.update(`${filePath}:${model}:${u.input_tokens || 0}:${u.output_tokens || 0}
|
|
92
|
+
.update(`${filePath}:${lineOffset}:${model}:${u.input_tokens || 0}:${u.output_tokens || 0}`)
|
|
91
93
|
.digest('hex');
|
|
92
94
|
|
|
93
95
|
if (isDuplicate(hash)) continue;
|
|
@@ -141,12 +143,15 @@ function handleFileChange(filePath) {
|
|
|
141
143
|
// Only care about .jsonl files
|
|
142
144
|
if (!filePath.endsWith('.jsonl')) return;
|
|
143
145
|
|
|
144
|
-
//
|
|
145
|
-
const
|
|
146
|
+
// Normalize path for consistent debounce key (Windows fires with mixed separators/casing)
|
|
147
|
+
const normalizedKey = path.resolve(filePath).toLowerCase();
|
|
148
|
+
|
|
149
|
+
// Debounce: wait 1000ms after last change before processing
|
|
150
|
+
const existing = _debounceTimers.get(normalizedKey);
|
|
146
151
|
if (existing) clearTimeout(existing);
|
|
147
152
|
|
|
148
|
-
_debounceTimers.set(
|
|
149
|
-
_debounceTimers.delete(
|
|
153
|
+
_debounceTimers.set(normalizedKey, setTimeout(async () => {
|
|
154
|
+
_debounceTimers.delete(normalizedKey);
|
|
150
155
|
try {
|
|
151
156
|
const events = extractNewUsage(filePath);
|
|
152
157
|
if (events.length > 0) {
|