getaimeter 0.2.0 → 0.2.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/cli.js +12 -0
- package/package.json +1 -1
- package/watcher.js +46 -10
package/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ const { getApiKey, saveApiKey, getWatchPaths, AIMETER_DIR } = require('./config'
|
|
|
5
5
|
const { startWatching } = require('./watcher');
|
|
6
6
|
const { install, uninstall, isInstalled, startNow, stopNow } = require('./service');
|
|
7
7
|
const { checkForUpdate, getCurrentVersion } = require('./update-check');
|
|
8
|
+
const { startTray, stopTray } = require('./tray');
|
|
8
9
|
|
|
9
10
|
const command = process.argv[2] || 'help';
|
|
10
11
|
|
|
@@ -187,8 +188,18 @@ function runWatch() {
|
|
|
187
188
|
|
|
188
189
|
const cleanup = startWatching();
|
|
189
190
|
|
|
191
|
+
// Launch system tray icon (non-blocking, fails silently if systray2 not available)
|
|
192
|
+
const showTray = !process.argv.includes('--no-tray');
|
|
193
|
+
if (showTray) {
|
|
194
|
+
startTray(() => {
|
|
195
|
+
cleanup();
|
|
196
|
+
try { fs.unlinkSync(lockFile); } catch {}
|
|
197
|
+
}).catch(() => {}); // ignore tray errors
|
|
198
|
+
}
|
|
199
|
+
|
|
190
200
|
const cleanupAll = () => {
|
|
191
201
|
cleanup();
|
|
202
|
+
stopTray();
|
|
192
203
|
try { fs.unlinkSync(lockFile); } catch {}
|
|
193
204
|
process.exit(0);
|
|
194
205
|
};
|
|
@@ -196,6 +207,7 @@ function runWatch() {
|
|
|
196
207
|
process.on('SIGINT', cleanupAll);
|
|
197
208
|
process.on('SIGTERM', cleanupAll);
|
|
198
209
|
process.on('exit', () => {
|
|
210
|
+
stopTray();
|
|
199
211
|
try { fs.unlinkSync(lockFile); } catch {}
|
|
200
212
|
});
|
|
201
213
|
|
package/package.json
CHANGED
package/watcher.js
CHANGED
|
@@ -31,19 +31,55 @@ 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
|
+
// For subagent files, inherit the parent session's source
|
|
47
|
+
if (normalized.includes('/subagents/')) {
|
|
48
|
+
const parentDir = normalized.replace(/\/[^/]+\/subagents\/.*$/, '');
|
|
49
|
+
// Find the parent JSONL (same dir, .jsonl file)
|
|
50
|
+
try {
|
|
51
|
+
const parentDirNative = parentDir.replace(/\//g, path.sep);
|
|
52
|
+
const entries = fs.readdirSync(parentDirNative);
|
|
53
|
+
for (const entry of entries) {
|
|
54
|
+
if (entry.endsWith('.jsonl')) {
|
|
55
|
+
const parentFile = path.join(parentDirNative, entry);
|
|
56
|
+
const parentSource = detectSource(parentFile); // recursive, will cache
|
|
57
|
+
_sourceCache.set(filePath, parentSource);
|
|
58
|
+
return parentSource;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} catch {}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Read first 10KB of the file to find entrypoint or IDE markers
|
|
65
|
+
let source = 'cli'; // default
|
|
66
|
+
try {
|
|
67
|
+
const fd = fs.openSync(filePath, 'r');
|
|
68
|
+
const buf = Buffer.alloc(Math.min(10240, fs.fstatSync(fd).size));
|
|
69
|
+
fs.readSync(fd, buf, 0, buf.length, 0);
|
|
70
|
+
fs.closeSync(fd);
|
|
71
|
+
const header = buf.toString('utf8');
|
|
72
|
+
|
|
73
|
+
if (header.includes('"entrypoint":"claude-desktop"')) {
|
|
74
|
+
source = 'desktop_app';
|
|
75
|
+
} else if (header.includes('ide_opened_file') || header.includes('"entrypoint":"vscode"')) {
|
|
76
|
+
source = 'vscode';
|
|
77
|
+
}
|
|
78
|
+
// else remains 'cli'
|
|
79
|
+
} catch {}
|
|
80
|
+
|
|
81
|
+
_sourceCache.set(filePath, source);
|
|
82
|
+
return source;
|
|
47
83
|
}
|
|
48
84
|
|
|
49
85
|
// ---------------------------------------------------------------------------
|