@vibe-cafe/vibe-usage 0.1.9 → 0.1.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-cafe/vibe-usage",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Track your AI coding tool token usage and sync to vibecafe.ai",
5
5
  "type": "module",
6
6
  "bin": {
package/src/init.js CHANGED
@@ -62,7 +62,7 @@ export async function runInit() {
62
62
  const config = {
63
63
  apiKey,
64
64
  apiUrl,
65
- lastSync: null,
65
+ lastSync: existing?.lastSync || null,
66
66
  };
67
67
  saveConfig(config);
68
68
 
@@ -20,7 +20,7 @@ export async function parse(lastSync) {
20
20
  entries.push({
21
21
  source: 'claude-code',
22
22
  model: breakdown.modelName,
23
- project: session.projectPath || 'unknown',
23
+ project: stripSessionId(session.projectPath),
24
24
  timestamp: new Date(session.lastActivity),
25
25
  inputTokens: breakdown.inputTokens,
26
26
  outputTokens: breakdown.outputTokens,
@@ -32,3 +32,15 @@ export async function parse(lastSync) {
32
32
 
33
33
  return aggregateToBuckets(entries);
34
34
  }
35
+
36
+ /**
37
+ * Strip session UUID suffix from ccusage project path.
38
+ * ccusage returns paths like '-Users-foo-project/77e854f9-...' for subagent sessions.
39
+ * We only keep the directory name part before the first '/'.
40
+ */
41
+ function stripSessionId(raw) {
42
+ if (!raw || raw === 'unknown' || raw === 'Unknown Project') return 'unknown';
43
+ const slashIdx = raw.indexOf('/');
44
+ if (slashIdx !== -1) return raw.slice(0, slashIdx);
45
+ return raw;
46
+ }
package/src/sync.js CHANGED
@@ -1,10 +1,14 @@
1
1
  import { loadConfig, saveConfig } from './config.js';
2
2
  import { ingest } from './api.js';
3
3
  import { parsers } from './parsers/index.js';
4
+ import { TOOLS } from './hooks.js';
4
5
 
5
6
  const BATCH_SIZE = 500;
6
7
 
7
8
  export async function runSync() {
9
+ // Self-heal: re-inject any missing hooks before syncing
10
+ ensureHooks();
11
+
8
12
  const config = loadConfig();
9
13
  if (!config?.apiKey) {
10
14
  console.error('Not configured. Run `npx @vibe-cafe/vibe-usage init` first.');
@@ -73,3 +77,21 @@ export async function runSync() {
73
77
  process.exit(1);
74
78
  }
75
79
  }
80
+
81
+ /**
82
+ * Re-inject hooks for any installed tool whose hook is missing.
83
+ * Runs silently — meant as a self-healing side effect of sync.
84
+ */
85
+ function ensureHooks() {
86
+ for (const tool of TOOLS) {
87
+ if (!tool.inject) continue;
88
+ try {
89
+ const result = tool.inject();
90
+ if (result.injected) {
91
+ process.stderr.write(`hook: re-installed ${tool.name} hook\n`);
92
+ }
93
+ } catch {
94
+ // ignore — best effort
95
+ }
96
+ }
97
+ }