@vibe-cafe/vibe-usage 0.7.2 → 0.7.4
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/README.md +15 -2
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/init.js +2 -1
- package/src/parsers/hermes.js +100 -0
- package/src/parsers/index.js +2 -0
- package/src/sync.js +6 -1
- package/src/tools.js +5 -0
package/README.md
CHANGED
|
@@ -47,12 +47,13 @@ npx @vibe-cafe/vibe-usage status # Show config & detected tools
|
|
|
47
47
|
| Kimi Code | `~/.kimi/sessions/` |
|
|
48
48
|
| Amp | `~/.local/share/amp/threads/` |
|
|
49
49
|
| Droid | `~/.factory/sessions/` |
|
|
50
|
+
| Hermes | `~/.hermes/state.db` (SQLite) |
|
|
50
51
|
|
|
51
52
|
## How It Works
|
|
52
53
|
|
|
53
54
|
- Parses local session logs from each AI coding tool
|
|
54
55
|
- Aggregates token usage into 30-minute buckets
|
|
55
|
-
- Extracts session metadata from all
|
|
56
|
+
- Extracts session metadata from all parsers: active time (AI generation time, excluding queue/TTFT wait), total duration, message counts
|
|
56
57
|
- Uploads buckets + sessions to your vibecafe.ai dashboard
|
|
57
58
|
- Stateless: computes full totals from local logs each sync (idempotent, no state files)
|
|
58
59
|
- For continuous syncing, use `npx @vibe-cafe/vibe-usage daemon` or the [Vibe Usage Mac app](https://github.com/vibe-cafe/vibe-usage-app)
|
|
@@ -90,7 +91,19 @@ VIBE_USAGE_DEV=1 npx @vibe-cafe/vibe-usage sync
|
|
|
90
91
|
|
|
91
92
|
## Config
|
|
92
93
|
|
|
93
|
-
Config stored at `~/.vibe-usage/config.json` (dev: `config.dev.json`).
|
|
94
|
+
Config stored at `~/.vibe-usage/config.json` (dev: `config.dev.json`).
|
|
95
|
+
|
|
96
|
+
| Key | Description |
|
|
97
|
+
|-----|-------------|
|
|
98
|
+
| `apiKey` | Your API key (starts with `vbu_`) |
|
|
99
|
+
| `apiUrl` | Server URL (default: `https://vibecafe.ai`) |
|
|
100
|
+
| `hostname` | Stable device name for usage tracking (set at init, reused across syncs) |
|
|
101
|
+
|
|
102
|
+
The `hostname` is captured once during `init` and reused for all future syncs. This prevents macOS mDNS hostname changes (e.g., `MacBook-Pro` → `MacBook-Pro-2`) from creating duplicate device entries. To change it manually:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npx @vibe-cafe/vibe-usage config set hostname my-device-name
|
|
106
|
+
```
|
|
94
107
|
|
|
95
108
|
## Daemon Mode
|
|
96
109
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/init.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createInterface } from 'node:readline';
|
|
2
2
|
import { execFile } from 'node:child_process';
|
|
3
|
-
import { platform } from 'node:os';
|
|
3
|
+
import { hostname as osHostname, platform } from 'node:os';
|
|
4
4
|
import { loadConfig, saveConfig } from './config.js';
|
|
5
5
|
import { ingest } from './api.js';
|
|
6
6
|
import { runSync } from './sync.js';
|
|
@@ -61,6 +61,7 @@ export async function runInit() {
|
|
|
61
61
|
const config = {
|
|
62
62
|
apiKey,
|
|
63
63
|
apiUrl,
|
|
64
|
+
hostname: existing?.hostname || osHostname().replace(/\.local$/, ''),
|
|
64
65
|
};
|
|
65
66
|
saveConfig(config);
|
|
66
67
|
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { aggregateToBuckets, extractSessions } from './index.js';
|
|
6
|
+
|
|
7
|
+
const HERMES_HOME = process.env.HERMES_HOME || join(homedir(), '.hermes');
|
|
8
|
+
const DB_PATH = join(HERMES_HOME, 'state.db');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parse Hermes Agent usage data from its SQLite database (~/.hermes/state.db).
|
|
12
|
+
*
|
|
13
|
+
* Token buckets come from the sessions table (cumulative per-session totals).
|
|
14
|
+
* Session timing comes from the messages table (per-message role + timestamp).
|
|
15
|
+
*/
|
|
16
|
+
export async function parse() {
|
|
17
|
+
if (!existsSync(DB_PATH)) return { buckets: [], sessions: [] };
|
|
18
|
+
|
|
19
|
+
let sessionRows;
|
|
20
|
+
try {
|
|
21
|
+
sessionRows = queryDb(`SELECT
|
|
22
|
+
id,
|
|
23
|
+
model,
|
|
24
|
+
started_at as startedAt,
|
|
25
|
+
input_tokens as inputTokens,
|
|
26
|
+
output_tokens as outputTokens,
|
|
27
|
+
cache_read_tokens as cacheReadTokens,
|
|
28
|
+
reasoning_tokens as reasoningTokens
|
|
29
|
+
FROM sessions
|
|
30
|
+
WHERE input_tokens > 0 OR output_tokens > 0`);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (err.message && err.message.includes('ENOENT')) {
|
|
33
|
+
throw new Error('sqlite3 CLI not found. Install sqlite3 to sync Hermes data.');
|
|
34
|
+
}
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const entries = [];
|
|
39
|
+
for (const row of sessionRows) {
|
|
40
|
+
// started_at is a Unix timestamp (float)
|
|
41
|
+
const timestamp = new Date(row.startedAt * 1000);
|
|
42
|
+
if (isNaN(timestamp.getTime())) continue;
|
|
43
|
+
|
|
44
|
+
// Hermes stores input_tokens exclusive of cache (Anthropic-style semantics)
|
|
45
|
+
entries.push({
|
|
46
|
+
source: 'hermes',
|
|
47
|
+
model: row.model || 'unknown',
|
|
48
|
+
project: 'unknown',
|
|
49
|
+
timestamp,
|
|
50
|
+
inputTokens: row.inputTokens || 0,
|
|
51
|
+
outputTokens: row.outputTokens || 0,
|
|
52
|
+
cachedInputTokens: row.cacheReadTokens || 0,
|
|
53
|
+
reasoningOutputTokens: row.reasoningTokens || 0,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Session events from messages table for active time calculation
|
|
58
|
+
let messageRows;
|
|
59
|
+
try {
|
|
60
|
+
messageRows = queryDb(`SELECT
|
|
61
|
+
session_id as sessionId,
|
|
62
|
+
role,
|
|
63
|
+
timestamp
|
|
64
|
+
FROM messages
|
|
65
|
+
WHERE role IN ('user', 'assistant')
|
|
66
|
+
ORDER BY timestamp`);
|
|
67
|
+
} catch {
|
|
68
|
+
// Messages query failed — return buckets only
|
|
69
|
+
return { buckets: aggregateToBuckets(entries), sessions: [] };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const sessionEvents = [];
|
|
73
|
+
for (const row of messageRows) {
|
|
74
|
+
const timestamp = new Date(row.timestamp * 1000);
|
|
75
|
+
if (isNaN(timestamp.getTime())) continue;
|
|
76
|
+
|
|
77
|
+
sessionEvents.push({
|
|
78
|
+
sessionId: row.sessionId,
|
|
79
|
+
source: 'hermes',
|
|
80
|
+
project: 'unknown',
|
|
81
|
+
timestamp,
|
|
82
|
+
role: row.role === 'user' ? 'user' : 'assistant',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return { buckets: aggregateToBuckets(entries), sessions: extractSessions(sessionEvents) };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function queryDb(sql) {
|
|
90
|
+
const output = execFileSync('sqlite3', [
|
|
91
|
+
'-json',
|
|
92
|
+
DB_PATH,
|
|
93
|
+
sql,
|
|
94
|
+
], { encoding: 'utf-8', maxBuffer: 100 * 1024 * 1024, timeout: 30000 });
|
|
95
|
+
|
|
96
|
+
const trimmed = output.trim();
|
|
97
|
+
if (!trimmed || trimmed === '[]') return [];
|
|
98
|
+
|
|
99
|
+
return JSON.parse(trimmed);
|
|
100
|
+
}
|
package/src/parsers/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { parse as parseKimiCode } from './kimi-code.js';
|
|
|
10
10
|
import { parse as parseAmp } from './amp.js';
|
|
11
11
|
import { parse as parseDroid } from './droid.js';
|
|
12
12
|
import { parse as parseAntigravity } from './antigravity.js';
|
|
13
|
+
import { parse as parseHermes } from './hermes.js';
|
|
13
14
|
import { parse as parsePiCodingAgent } from './pi-coding-agent.js';
|
|
14
15
|
|
|
15
16
|
export const parsers = {
|
|
@@ -24,6 +25,7 @@ export const parsers = {
|
|
|
24
25
|
'amp': parseAmp,
|
|
25
26
|
'droid': parseDroid,
|
|
26
27
|
'antigravity': parseAntigravity,
|
|
28
|
+
'hermes': parseHermes,
|
|
27
29
|
'pi-coding-agent': parsePiCodingAgent,
|
|
28
30
|
};
|
|
29
31
|
|
package/src/sync.js
CHANGED
|
@@ -59,7 +59,12 @@ export async function runSync({ throws = false, quiet = false } = {}) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
let host = config.hostname;
|
|
63
|
+
if (!host) {
|
|
64
|
+
host = osHostname().replace(/\.local$/, '');
|
|
65
|
+
config.hostname = host;
|
|
66
|
+
saveConfig(config);
|
|
67
|
+
}
|
|
63
68
|
for (const b of allBuckets) {
|
|
64
69
|
b.hostname = host;
|
|
65
70
|
}
|
package/src/tools.js
CHANGED