@vibe-cafe/vibe-usage 0.7.3 → 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 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 10 parsers: active time (AI generation time, excluding queue/TTFT wait), total duration, message counts
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-cafe/vibe-usage",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Track your AI coding tool token usage and sync to vibecafe.ai",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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
+ }
@@ -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/tools.js CHANGED
@@ -82,6 +82,11 @@ export const TOOLS = [
82
82
  id: 'droid',
83
83
  dataDir: join(homedir(), '.factory', 'sessions'),
84
84
  },
85
+ {
86
+ name: 'Hermes',
87
+ id: 'hermes',
88
+ dataDir: join(homedir(), '.hermes', 'state.db'),
89
+ },
85
90
  ];
86
91
 
87
92
  export function detectInstalledTools() {