vibeusage 0.2.16 → 0.2.17
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 +136 -20
- package/README.zh-CN.md +135 -19
- package/package.json +1 -1
- package/src/cli.js +3 -2
- package/src/commands/status.js +52 -1
- package/src/commands/sync.js +76 -11
- package/src/lib/codex-config.js +132 -10
- package/src/lib/diagnostics.js +3 -0
- package/src/lib/rollout.js +155 -1
- package/src/lib/subscriptions.js +317 -0
- package/src/lib/uploader.js +7 -1
- package/src/lib/vibeusage-api.js +7 -2
package/README.md
CHANGED
|
@@ -42,13 +42,23 @@ We believe your code and thoughts are your own. VibeUsage is built with strict p
|
|
|
42
42
|
|
|
43
43
|
## 🚀 Key Features
|
|
44
44
|
|
|
45
|
-
- 📡 **Auto-Sync**: Real-time interception of
|
|
46
|
-
- 🧭 **Universal-Sync**: Native support for
|
|
45
|
+
- 📡 **Auto-Sync**: Real-time interception of AI CLI pipes with **automatic background synchronization**. Once initialized, your tokens are tracked and synced without any manual commands.
|
|
46
|
+
- 🧭 **Universal-Sync**: Native support for multiple AI CLI tools:
|
|
47
|
+
- **Codex CLI** - OpenAI's official CLI
|
|
48
|
+
- **Every Code** - Community Codex alternative
|
|
49
|
+
- **Gemini CLI** - Google's AI CLI
|
|
50
|
+
- **Opencode** - AI coding assistant
|
|
51
|
+
- **Claude Code** - Anthropic's official CLI
|
|
52
|
+
- Whether it's GPT-4, Claude 3.5 Sonnet, or o1/Gemini, token consumption from all models is unified and counted.
|
|
47
53
|
- 📊 **Matrix Dashboard**: High-performance dashboard built with React + Vite, featuring the new **Matrix-A** design language.
|
|
48
54
|
- **Neural Divergence Map**: Visualize multi-engine load balancing and compute distribution.
|
|
49
55
|
- **Cost Intelligence**: Real-time, multi-dimensional cost breakdown and forecasting.
|
|
56
|
+
- **Activity Heatmap**: GitHub-style contribution graph with streak tracking.
|
|
50
57
|
- **Smart Notifications**: Non-intrusive system-level alerts using a Golden (Gold/Amber) visual style for high-value information.
|
|
51
58
|
- ⚡ **AI Analytics**: Deep analysis of Input/Output tokens, with dedicated tracking for Cached and Reasoning components.
|
|
59
|
+
- 📈 **Leaderboard**: Daily, weekly, monthly, and all-time rankings with privacy-safe display names.
|
|
60
|
+
- 🌐 **Public View**: Share your AI usage journey with a privacy-safe public profile.
|
|
61
|
+
- 📁 **Project Stats**: Track token usage by project/repository across all time.
|
|
52
62
|
- 🔒 **Identity Core**: Robust authentication and permission management to secure your development data.
|
|
53
63
|
|
|
54
64
|
### 🌌 Visual Preview
|
|
@@ -65,14 +75,33 @@ Initialize your environment once and forget it. VibeUsage handles all synchroniz
|
|
|
65
75
|
npx --yes vibeusage init
|
|
66
76
|
```
|
|
67
77
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
**Authentication Methods:**
|
|
79
|
+
|
|
80
|
+
1. **Browser Auth** (default) - Opens browser for secure authentication
|
|
81
|
+
2. **Link Code** - Use `--link-code` to authenticate via dashboard-generated code
|
|
82
|
+
3. **Password** - Direct password authentication (fallback)
|
|
83
|
+
4. **Access Token** - For CI/automated environments
|
|
84
|
+
|
|
85
|
+
**CLI Options:**
|
|
86
|
+
- `--yes` - Skip consent prompts in non-interactive environments
|
|
87
|
+
- `--dry-run` - Preview changes without writing files
|
|
88
|
+
- `--link-code <code>` - Authenticate using a link code from dashboard
|
|
89
|
+
- `--base-url <url>` - Override the default API endpoint
|
|
90
|
+
|
|
91
|
+
**Supported CLI Tools Auto-Configuration:**
|
|
92
|
+
|
|
93
|
+
| Tool | Config Location | Method |
|
|
94
|
+
|------|----------------|--------|
|
|
95
|
+
| Codex CLI | `~/.codex/config.toml` | `notify` hook |
|
|
96
|
+
| Every Code | `~/.code/config.toml` (or `CODE_HOME`) | `notify` hook |
|
|
97
|
+
| Gemini CLI | `~/.gemini/settings.json` (or `GEMINI_HOME`) | `SessionEnd` hook |
|
|
98
|
+
| Opencode | Global plugins | Message parser plugin |
|
|
99
|
+
| Claude Code | `~/.claude/hooks/` | Hook configuration |
|
|
100
|
+
|
|
101
|
+
Once `init` completes, all supported CLI tools are automatically configured for data sync. No further intervention required.
|
|
72
102
|
|
|
73
103
|
### Sync & Status
|
|
74
104
|
|
|
75
|
-
````bash
|
|
76
105
|
While sync happens automatically, you can manually trigger a synchronization or check status anytime:
|
|
77
106
|
|
|
78
107
|
```bash
|
|
@@ -81,7 +110,7 @@ npx --yes vibeusage sync
|
|
|
81
110
|
|
|
82
111
|
# Check current link status
|
|
83
112
|
npx --yes vibeusage status
|
|
84
|
-
|
|
113
|
+
```
|
|
85
114
|
|
|
86
115
|
### Doctor
|
|
87
116
|
|
|
@@ -96,21 +125,78 @@ npx --yes vibeusage doctor --json --out doctor.json
|
|
|
96
125
|
npx --yes vibeusage doctor --base-url https://example.invalid
|
|
97
126
|
```
|
|
98
127
|
|
|
99
|
-
###
|
|
128
|
+
### Uninstall
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Standard uninstall (keeps data)
|
|
132
|
+
npx --yes vibeusage uninstall
|
|
133
|
+
|
|
134
|
+
# Full purge - removes all data including config and cached sessions
|
|
135
|
+
npx --yes vibeusage uninstall --purge
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Log Sources
|
|
100
139
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
140
|
+
| Tool | Log Location | Override Env |
|
|
141
|
+
|------|-------------|--------------|
|
|
142
|
+
| Codex CLI | `~/.codex/sessions/**/rollout-*.jsonl` | `CODEX_HOME` |
|
|
143
|
+
| Every Code | `~/.code/sessions/**/rollout-*.jsonl` | `CODE_HOME` |
|
|
144
|
+
| Gemini CLI | `~/.gemini/tmp/**/chats/session-*.json` | `GEMINI_HOME` |
|
|
145
|
+
| Opencode | `~/.opencode/messages/*.json` | - |
|
|
146
|
+
| Claude Code | Parsed from hook output | - |
|
|
104
147
|
|
|
105
148
|
## 🔧 Environment Variables
|
|
106
149
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
150
|
+
### Core Settings
|
|
151
|
+
|
|
152
|
+
| Variable | Description | Default |
|
|
153
|
+
|----------|-------------|---------|
|
|
154
|
+
| `VIBEUSAGE_HTTP_TIMEOUT_MS` | CLI HTTP timeout in ms (`0` disables, clamped `1000..120000`) | `20000` |
|
|
155
|
+
| `VITE_VIBEUSAGE_HTTP_TIMEOUT_MS` | Dashboard request timeout in ms (`0` disables, clamped `1000..30000`) | `15000` |
|
|
156
|
+
| `VIBEUSAGE_DEBUG` | Enable debug output (`1` or `true` to enable) | - |
|
|
157
|
+
| `VIBEUSAGE_DASHBOARD_URL` | Custom dashboard URL | `https://www.vibeusage.cc` |
|
|
158
|
+
| `VIBEUSAGE_INSFORGE_BASE_URL` | Custom API base URL | `https://5tmappuk.us-east.insforge.app` |
|
|
159
|
+
| `VIBEUSAGE_DEVICE_TOKEN` | Pre-configured device token (for CI) | - |
|
|
160
|
+
|
|
161
|
+
### CLI Tool Overrides
|
|
162
|
+
|
|
163
|
+
| Variable | Description | Default |
|
|
164
|
+
|----------|-------------|---------|
|
|
165
|
+
| `CODEX_HOME` | Codex CLI directory override | `~/.codex` |
|
|
166
|
+
| `CODE_HOME` | Every Code directory override | `~/.code` |
|
|
167
|
+
| `GEMINI_HOME` | Gemini CLI directory override | `~/.gemini` |
|
|
168
|
+
|
|
169
|
+
### Deprecated
|
|
170
|
+
|
|
171
|
+
- `VIBEUSAGE_ROLLUP_ENABLED`: Currently ignored; rollup aggregation is disabled pending table deployment.
|
|
111
172
|
|
|
112
173
|
## 🧰 Troubleshooting
|
|
113
174
|
|
|
175
|
+
### Debug Mode
|
|
176
|
+
|
|
177
|
+
Enable debug output to see detailed request/response information:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
VIBEUSAGE_DEBUG=1 npx --yes vibeusage sync
|
|
181
|
+
# or
|
|
182
|
+
npx --yes vibeusage sync --debug
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Health Check
|
|
186
|
+
|
|
187
|
+
Run the built-in doctor command to diagnose issues:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
# Basic health check
|
|
191
|
+
npx --yes vibeusage doctor
|
|
192
|
+
|
|
193
|
+
# JSON output for debugging
|
|
194
|
+
npx --yes vibeusage doctor --json --out doctor.json
|
|
195
|
+
|
|
196
|
+
# Test against a different endpoint
|
|
197
|
+
npx --yes vibeusage doctor --base-url https://your-instance.insforge.app
|
|
198
|
+
```
|
|
199
|
+
|
|
114
200
|
### Streak shows 0 days while totals look correct
|
|
115
201
|
|
|
116
202
|
- Streak is defined as consecutive days ending today. If today's total is 0, streak will be 0.
|
|
@@ -127,16 +213,46 @@ location.reload();
|
|
|
127
213
|
- Complete the landing page sign-in flow again after reload.
|
|
128
214
|
- Note: `insforge-auth-token` is not used by the dashboard; use `vibeusage.dashboard.auth.v1`.
|
|
129
215
|
|
|
216
|
+
### Sync Issues
|
|
217
|
+
|
|
218
|
+
If data isn't appearing in the dashboard:
|
|
219
|
+
|
|
220
|
+
1. Check status: `npx --yes vibeusage status`
|
|
221
|
+
2. Force manual sync: `npx --yes vibeusage sync`
|
|
222
|
+
3. Verify CLI tool hooks are configured (re-run `init` if needed)
|
|
223
|
+
4. Check debug output: `VIBEUSAGE_DEBUG=1 npx vibeusage sync`
|
|
224
|
+
|
|
225
|
+
### Timeout Errors
|
|
226
|
+
|
|
227
|
+
Increase HTTP timeout for slow connections:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
VIBEUSAGE_HTTP_TIMEOUT_MS=60000 npx --yes vibeusage sync
|
|
231
|
+
```
|
|
232
|
+
|
|
130
233
|
## 🏗️ Architecture
|
|
131
234
|
|
|
132
235
|
```mermaid
|
|
133
236
|
graph TD
|
|
134
|
-
A[Codex CLI] -->|Rollout Logs|
|
|
135
|
-
B -->|
|
|
136
|
-
C
|
|
137
|
-
|
|
237
|
+
A[Codex CLI] -->|Rollout Logs| F(Tracker CLI)
|
|
238
|
+
B[Every Code] -->|Rollout Logs| F
|
|
239
|
+
C[Gemini CLI] -->|Session Logs| F
|
|
240
|
+
D[Opencode] -->|Message Logs| F
|
|
241
|
+
E[Claude Code] -->|Hook Output| F
|
|
242
|
+
F -->|AI Tokens| G{Core Relay}
|
|
243
|
+
G --> H[VibeUsage Dashboard]
|
|
244
|
+
G --> I[AI Analytics Engine]
|
|
245
|
+
G --> J[Leaderboard Service]
|
|
246
|
+
G --> K[Public View API]
|
|
138
247
|
```
|
|
139
248
|
|
|
249
|
+
### Components
|
|
250
|
+
|
|
251
|
+
- **Tracker CLI** (`src/`): Node.js CLI that parses logs from multiple AI tools and syncs token data
|
|
252
|
+
- **Core Relay** (InsForge Edge Functions): Serverless backend handling ingestion, aggregation, and API
|
|
253
|
+
- **Dashboard** (`dashboard/`): React + Vite frontend for visualization
|
|
254
|
+
- **AI Analytics Engine**: Cost calculation, model breakdown, and usage forecasting
|
|
255
|
+
|
|
140
256
|
## 💻 Developer Guide
|
|
141
257
|
|
|
142
258
|
To run locally or contribute:
|
package/README.zh-CN.md
CHANGED
|
@@ -42,13 +42,23 @@ _Codex CLI 实时 AI 分析工具_
|
|
|
42
42
|
|
|
43
43
|
## 🚀 核心功能
|
|
44
44
|
|
|
45
|
-
- 📡 **自动嗅探与同步 (Auto-Sync)**: 实时监听
|
|
46
|
-
- 🧭 **全能采集 (Universal-Sync)**:
|
|
45
|
+
- 📡 **自动嗅探与同步 (Auto-Sync)**: 实时监听 AI CLI 管道并具备**全自动后台同步**功能。初始化后,你的 Token 产出将自动追踪并同步,无需手动执行脚本。
|
|
46
|
+
- 🧭 **全能采集 (Universal-Sync)**: 原生支持多种 AI CLI 工具:
|
|
47
|
+
- **Codex CLI** - OpenAI 官方 CLI
|
|
48
|
+
- **Every Code** - 社区版 Codex 替代品
|
|
49
|
+
- **Gemini CLI** - Google AI CLI
|
|
50
|
+
- **Opencode** - AI 编程助手
|
|
51
|
+
- **Claude Code** - Anthropic 官方 CLI
|
|
52
|
+
- 无论是 GPT-4、Claude 3.5 Sonnet 还是 o1/Gemini,所有模型的 Token 消耗均可被统一捕获与统计。
|
|
47
53
|
- 📊 **Matrix Dashboard (矩阵控制台)**: 基于 React + Vite 的高性能仪表盘,采用全新的 **Matrix-A** 设计语言。
|
|
48
54
|
- **Neural Divergence Map (神经发散图谱)**: 可视化多引擎负载均衡状态,直观展示算力分布。
|
|
49
55
|
- **Cost Intelligence (成本智能)**: 实时、多维度的成本分解与预测。
|
|
56
|
+
- **Activity Heatmap (活跃热力图)**: GitHub 风格的贡献图,支持连续天数统计。
|
|
50
57
|
- **Smart Notifications (智能通知)**: 非侵入式的系统级通知,采用金色 (Gold/Amber) 视觉传达高价值信息。
|
|
51
58
|
- ⚡ **AI Analytics (AI 分析)**: 深度分析 Input/Output Token,支持缓存 (Cached) 与推理 (Reasoning) 部分的分离监控。
|
|
59
|
+
- 📈 **排行榜 (Leaderboard)**: 日、周、月、总排行榜,使用隐私安全的显示名称。
|
|
60
|
+
- 🌐 **公开视图 (Public View)**: 分享你的 AI 使用历程,隐私安全的公开档案。
|
|
61
|
+
- 📁 **项目统计 (Project Stats)**: 按项目/仓库追踪 Token 使用,支持全时间范围。
|
|
52
62
|
- 🔒 **Identity Core (身份核心)**: 完备的身份验证与权限管理,保护你的开发数据资产。
|
|
53
63
|
|
|
54
64
|
### 🌌 视觉预览
|
|
@@ -65,14 +75,33 @@ _Codex CLI 实时 AI 分析工具_
|
|
|
65
75
|
npx --yes vibeusage init
|
|
66
76
|
```
|
|
67
77
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
**认证方式:**
|
|
79
|
+
|
|
80
|
+
1. **浏览器认证**(默认)- 打开浏览器进行安全认证
|
|
81
|
+
2. **链接码** - 使用 `--link-code` 通过控制台生成的代码认证
|
|
82
|
+
3. **密码** - 直接密码认证(后备方案)
|
|
83
|
+
4. **访问令牌** - 用于 CI/自动化环境
|
|
84
|
+
|
|
85
|
+
**CLI 选项:**
|
|
86
|
+
- `--yes` - 非交互环境跳过确认提示
|
|
87
|
+
- `--dry-run` - 仅预览变更,不写入文件
|
|
88
|
+
- `--link-code <code>` - 使用控制台的链接码认证
|
|
89
|
+
- `--base-url <url>` - 覆盖默认 API 端点
|
|
90
|
+
|
|
91
|
+
**支持的 CLI 工具自动配置:**
|
|
92
|
+
|
|
93
|
+
| 工具 | 配置位置 | 方式 |
|
|
94
|
+
|------|---------|------|
|
|
95
|
+
| Codex CLI | `~/.codex/config.toml` | `notify` hook |
|
|
96
|
+
| Every Code | `~/.code/config.toml`(或 `CODE_HOME`) | `notify` hook |
|
|
97
|
+
| Gemini CLI | `~/.gemini/settings.json`(或 `GEMINI_HOME`) | `SessionEnd` hook |
|
|
98
|
+
| Opencode | 全局插件 | 消息解析插件 |
|
|
99
|
+
| Claude Code | `~/.claude/hooks/` | Hook 配置 |
|
|
100
|
+
|
|
101
|
+
`init` 完成后,所有支持的 CLI 工具将自动配置数据同步,无需额外操作。
|
|
72
102
|
|
|
73
103
|
### 同步与状态查看
|
|
74
104
|
|
|
75
|
-
````bash
|
|
76
105
|
虽然同步是自动完成的,但你仍可以随时手动触发同步或查看状态:
|
|
77
106
|
|
|
78
107
|
```bash
|
|
@@ -81,7 +110,7 @@ npx --yes vibeusage sync
|
|
|
81
110
|
|
|
82
111
|
# 查看当前连接状态
|
|
83
112
|
npx --yes vibeusage status
|
|
84
|
-
|
|
113
|
+
```
|
|
85
114
|
|
|
86
115
|
### Doctor
|
|
87
116
|
|
|
@@ -96,21 +125,78 @@ npx --yes vibeusage doctor --json --out doctor.json
|
|
|
96
125
|
npx --yes vibeusage doctor --base-url https://example.invalid
|
|
97
126
|
```
|
|
98
127
|
|
|
128
|
+
### 卸载
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# 标准卸载(保留数据)
|
|
132
|
+
npx --yes vibeusage uninstall
|
|
133
|
+
|
|
134
|
+
# 完全清理 - 删除所有数据,包括配置和缓存会话
|
|
135
|
+
npx --yes vibeusage uninstall --purge
|
|
136
|
+
```
|
|
137
|
+
|
|
99
138
|
### 日志来源
|
|
100
139
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
140
|
+
| 工具 | 日志位置 | 覆盖环境变量 |
|
|
141
|
+
|------|---------|-------------|
|
|
142
|
+
| Codex CLI | `~/.codex/sessions/**/rollout-*.jsonl` | `CODEX_HOME` |
|
|
143
|
+
| Every Code | `~/.code/sessions/**/rollout-*.jsonl` | `CODE_HOME` |
|
|
144
|
+
| Gemini CLI | `~/.gemini/tmp/**/chats/session-*.json` | `GEMINI_HOME` |
|
|
145
|
+
| Opencode | `~/.opencode/messages/*.json` | - |
|
|
146
|
+
| Claude Code | 从 hook 输出解析 | - |
|
|
104
147
|
|
|
105
148
|
## 🔧 环境变量
|
|
106
149
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
150
|
+
### 核心设置
|
|
151
|
+
|
|
152
|
+
| 变量 | 说明 | 默认值 |
|
|
153
|
+
|------|------|--------|
|
|
154
|
+
| `VIBEUSAGE_HTTP_TIMEOUT_MS` | CLI HTTP 超时(毫秒,`0` 表示关闭,范围 `1000..120000`) | `20000` |
|
|
155
|
+
| `VITE_VIBEUSAGE_HTTP_TIMEOUT_MS` | Dashboard 请求超时(毫秒,`0` 表示关闭,范围 `1000..30000`) | `15000` |
|
|
156
|
+
| `VIBEUSAGE_DEBUG` | 启用调试输出(`1` 或 `true` 开启) | - |
|
|
157
|
+
| `VIBEUSAGE_DASHBOARD_URL` | 自定义 Dashboard URL | `https://www.vibeusage.cc` |
|
|
158
|
+
| `VIBEUSAGE_INSFORGE_BASE_URL` | 自定义 API 基础 URL | `https://5tmappuk.us-east.insforge.app` |
|
|
159
|
+
| `VIBEUSAGE_DEVICE_TOKEN` | 预配置设备令牌(用于 CI) | - |
|
|
160
|
+
|
|
161
|
+
### CLI 工具覆盖
|
|
162
|
+
|
|
163
|
+
| 变量 | 说明 | 默认值 |
|
|
164
|
+
|------|------|--------|
|
|
165
|
+
| `CODEX_HOME` | Codex CLI 目录覆盖 | `~/.codex` |
|
|
166
|
+
| `CODE_HOME` | Every Code 目录覆盖 | `~/.code` |
|
|
167
|
+
| `GEMINI_HOME` | Gemini CLI 目录覆盖 | `~/.gemini` |
|
|
168
|
+
|
|
169
|
+
### 已废弃
|
|
170
|
+
|
|
171
|
+
- `VIBEUSAGE_ROLLUP_ENABLED`:当前被忽略;rollup 聚合在代码层禁用,等待 rollup 表部署完成后再恢复。
|
|
111
172
|
|
|
112
173
|
## 🧰 常见问题
|
|
113
174
|
|
|
175
|
+
### 调试模式
|
|
176
|
+
|
|
177
|
+
启用调试输出以查看详细的请求/响应信息:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
VIBEUSAGE_DEBUG=1 npx --yes vibeusage sync
|
|
181
|
+
# 或
|
|
182
|
+
npx --yes vibeusage sync --debug
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### 健康检查
|
|
186
|
+
|
|
187
|
+
运行内置的 doctor 命令诊断问题:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
# 基础健康检查
|
|
191
|
+
npx --yes vibeusage doctor
|
|
192
|
+
|
|
193
|
+
# JSON 输出用于调试
|
|
194
|
+
npx --yes vibeusage doctor --json --out doctor.json
|
|
195
|
+
|
|
196
|
+
# 测试不同端点
|
|
197
|
+
npx --yes vibeusage doctor --base-url https://your-instance.insforge.app
|
|
198
|
+
```
|
|
199
|
+
|
|
114
200
|
### Streak 显示 0 天但总量正常
|
|
115
201
|
|
|
116
202
|
- Streak 的口径是“从今天开始连续使用的天数”,如果今天的 total 为 0,streak 就是 0。
|
|
@@ -127,16 +213,46 @@ location.reload();
|
|
|
127
213
|
- 刷新后重新走一遍 landing page 的登录流程。
|
|
128
214
|
- 说明:Dashboard 不使用 `insforge-auth-token`,实际存储在 `vibeusage.dashboard.auth.v1`。
|
|
129
215
|
|
|
216
|
+
### 同步问题
|
|
217
|
+
|
|
218
|
+
如果数据未出现在控制台:
|
|
219
|
+
|
|
220
|
+
1. 检查状态:`npx --yes vibeusage status`
|
|
221
|
+
2. 强制手动同步:`npx --yes vibeusage sync`
|
|
222
|
+
3. 验证 CLI 工具 hooks 是否已配置(需要时重新运行 `init`)
|
|
223
|
+
4. 检查调试输出:`VIBEUSAGE_DEBUG=1 npx vibeusage sync`
|
|
224
|
+
|
|
225
|
+
### 超时错误
|
|
226
|
+
|
|
227
|
+
为慢速连接增加 HTTP 超时:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
VIBEUSAGE_HTTP_TIMEOUT_MS=60000 npx --yes vibeusage sync
|
|
231
|
+
```
|
|
232
|
+
|
|
130
233
|
## 🏗️ 系统架构
|
|
131
234
|
|
|
132
235
|
```mermaid
|
|
133
236
|
graph TD
|
|
134
|
-
A[Codex CLI] -->|Rollout Logs|
|
|
135
|
-
B -->|
|
|
136
|
-
C
|
|
137
|
-
|
|
237
|
+
A[Codex CLI] -->|Rollout Logs| F(Tracker CLI)
|
|
238
|
+
B[Every Code] -->|Rollout Logs| F
|
|
239
|
+
C[Gemini CLI] -->|Session Logs| F
|
|
240
|
+
D[Opencode] -->|Message Logs| F
|
|
241
|
+
E[Claude Code] -->|Hook Output| F
|
|
242
|
+
F -->|AI Tokens| G{Core Relay}
|
|
243
|
+
G --> H[VibeUsage Dashboard]
|
|
244
|
+
G --> I[AI Analytics Engine]
|
|
245
|
+
G --> J[Leaderboard Service]
|
|
246
|
+
G --> K[Public View API]
|
|
138
247
|
```
|
|
139
248
|
|
|
249
|
+
### 组件说明
|
|
250
|
+
|
|
251
|
+
- **Tracker CLI** (`src/`): Node.js CLI,解析多个 AI 工具的日志并同步 Token 数据
|
|
252
|
+
- **Core Relay** (InsForge Edge Functions): 无服务器后端,处理摄取、聚合和 API
|
|
253
|
+
- **Dashboard** (`dashboard/`): React + Vite 前端可视化
|
|
254
|
+
- **AI Analytics Engine**: 成本计算、模型分解和使用预测
|
|
255
|
+
|
|
140
256
|
## 💻 开发者指南
|
|
141
257
|
|
|
142
258
|
如果你想在本地运行或贡献代码:
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -45,8 +45,8 @@ function printHelp() {
|
|
|
45
45
|
'',
|
|
46
46
|
'Usage:',
|
|
47
47
|
' npx vibeusage [--debug] init [--yes] [--dry-run] [--no-open] [--link-code <code>]',
|
|
48
|
-
' npx vibeusage [--debug] sync [--auto] [--drain]',
|
|
49
|
-
' npx vibeusage [--debug] status',
|
|
48
|
+
' npx vibeusage [--debug] sync [--auto] [--drain] [--from-openclaw]',
|
|
49
|
+
' npx vibeusage [--debug] status [--probe-keychain] [--probe-keychain-details]',
|
|
50
50
|
' npx vibeusage [--debug] diagnostics [--out diagnostics.json]',
|
|
51
51
|
' npx vibeusage [--debug] doctor [--json] [--out doctor.json] [--base-url <url>]',
|
|
52
52
|
' npx vibeusage [--debug] uninstall [--purge]',
|
|
@@ -60,6 +60,7 @@ function printHelp() {
|
|
|
60
60
|
' - auto sync waits for a device token.',
|
|
61
61
|
' - optional: VIBEUSAGE_DASHBOARD_URL or --dashboard-url for hosted landing.',
|
|
62
62
|
' - sync parses ~/.codex/sessions/**/rollout-*.jsonl and ~/.code/sessions/**/rollout-*.jsonl, then uploads token deltas.',
|
|
63
|
+
' - --from-openclaw marks sync runs triggered by OpenClaw hooks.',
|
|
63
64
|
' - --debug shows original backend errors.',
|
|
64
65
|
''
|
|
65
66
|
].join('\n')
|
package/src/commands/status.js
CHANGED
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
buildGeminiHookCommand
|
|
13
13
|
} = require('../lib/gemini-config');
|
|
14
14
|
const { resolveOpencodeConfigDir, isOpencodePluginInstalled } = require('../lib/opencode-config');
|
|
15
|
+
const { collectLocalSubscriptions } = require('../lib/subscriptions');
|
|
15
16
|
const { normalizeState: normalizeUploadState } = require('../lib/upload-throttle');
|
|
16
17
|
const { collectTrackerDiagnostics } = require('../lib/diagnostics');
|
|
17
18
|
const { resolveTrackerPaths } = require('../lib/tracker-paths');
|
|
@@ -31,6 +32,7 @@ async function cmdStatus(argv = []) {
|
|
|
31
32
|
const queueStatePath = path.join(trackerDir, 'queue.state.json');
|
|
32
33
|
const cursorsPath = path.join(trackerDir, 'cursors.json');
|
|
33
34
|
const notifySignalPath = path.join(trackerDir, 'notify.signal');
|
|
35
|
+
const openclawSignalPath = path.join(trackerDir, 'openclaw.signal');
|
|
34
36
|
const throttlePath = path.join(trackerDir, 'sync.throttle');
|
|
35
37
|
const uploadThrottlePath = path.join(trackerDir, 'upload.throttle.json');
|
|
36
38
|
const autoRetryPath = path.join(trackerDir, 'auto.retry.json');
|
|
@@ -56,6 +58,7 @@ async function cmdStatus(argv = []) {
|
|
|
56
58
|
const pendingBytes = Math.max(0, queueSize - (queueState.offset || 0));
|
|
57
59
|
|
|
58
60
|
const lastNotify = (await safeReadText(notifySignalPath))?.trim() || null;
|
|
61
|
+
const lastOpenclawSync = (await safeReadText(openclawSignalPath))?.trim() || null;
|
|
59
62
|
const lastNotifySpawn = parseEpochMsToIso((await safeReadText(throttlePath))?.trim() || null);
|
|
60
63
|
|
|
61
64
|
const codexNotify = await readCodexNotify(codexConfigPath);
|
|
@@ -89,6 +92,17 @@ async function cmdStatus(argv = []) {
|
|
|
89
92
|
)} bytes)`
|
|
90
93
|
: null;
|
|
91
94
|
|
|
95
|
+
const subscriptions = await collectLocalSubscriptions({
|
|
96
|
+
home,
|
|
97
|
+
env: process.env,
|
|
98
|
+
probeKeychain: opts.probeKeychain,
|
|
99
|
+
probeKeychainDetails: opts.probeKeychainDetails
|
|
100
|
+
});
|
|
101
|
+
const subscriptionLines =
|
|
102
|
+
subscriptions.length > 0
|
|
103
|
+
? subscriptions.map(formatSubscriptionLine)
|
|
104
|
+
: [];
|
|
105
|
+
|
|
92
106
|
process.stdout.write(
|
|
93
107
|
[
|
|
94
108
|
'Status:',
|
|
@@ -97,6 +111,7 @@ async function cmdStatus(argv = []) {
|
|
|
97
111
|
`- Queue: ${pendingBytes} bytes pending`,
|
|
98
112
|
`- Last parse: ${cursors?.updatedAt || 'never'}`,
|
|
99
113
|
`- Last notify: ${lastNotify || 'never'}`,
|
|
114
|
+
`- Last OpenClaw-triggered sync: ${lastOpenclawSync || 'never'}`,
|
|
100
115
|
`- Last notify-triggered sync: ${lastNotifySpawn || 'never'}`,
|
|
101
116
|
`- Last upload: ${lastUpload || 'never'}`,
|
|
102
117
|
`- Next upload after: ${nextUpload || 'never'}`,
|
|
@@ -108,6 +123,7 @@ async function cmdStatus(argv = []) {
|
|
|
108
123
|
`- Claude hooks: ${claudeHookConfigured ? 'set' : 'unset'}`,
|
|
109
124
|
`- Gemini hooks: ${geminiHookConfigured ? 'set' : 'unset'}`,
|
|
110
125
|
`- Opencode plugin: ${opencodePluginConfigured ? 'set' : 'unset'}`,
|
|
126
|
+
...subscriptionLines,
|
|
111
127
|
''
|
|
112
128
|
]
|
|
113
129
|
.filter(Boolean)
|
|
@@ -115,12 +131,47 @@ async function cmdStatus(argv = []) {
|
|
|
115
131
|
);
|
|
116
132
|
}
|
|
117
133
|
|
|
134
|
+
function formatSubscriptionLine(entry = {}) {
|
|
135
|
+
const tool = String(entry.tool || '');
|
|
136
|
+
const provider = String(entry.provider || '');
|
|
137
|
+
const product = String(entry.product || '');
|
|
138
|
+
const planType = String(entry.planType || '');
|
|
139
|
+
const rateLimitTier = String(entry.rateLimitTier || '');
|
|
140
|
+
const toolLabel =
|
|
141
|
+
tool === 'codex'
|
|
142
|
+
? 'Codex'
|
|
143
|
+
: tool === 'opencode'
|
|
144
|
+
? 'OpenCode'
|
|
145
|
+
: tool === 'claude'
|
|
146
|
+
? 'Claude Code'
|
|
147
|
+
: tool;
|
|
148
|
+
|
|
149
|
+
if (!planType) return null;
|
|
150
|
+
|
|
151
|
+
if (tool === 'claude' && provider === 'anthropic' && product === 'subscription') {
|
|
152
|
+
const suffix = rateLimitTier ? ` (rate limit tier: ${rateLimitTier})` : '';
|
|
153
|
+
return `- ${toolLabel} subscription: ${planType}${suffix}`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (provider === 'openai' && product === 'chatgpt') {
|
|
157
|
+
return `- ${toolLabel} ChatGPT plan: ${planType}`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const productLabel = product ? product.replace(/_/g, ' ') : 'subscription';
|
|
161
|
+
return `- ${toolLabel} ${productLabel}: ${planType}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
118
164
|
function parseArgs(argv) {
|
|
119
|
-
const out = { diagnostics: false };
|
|
165
|
+
const out = { diagnostics: false, probeKeychain: false, probeKeychainDetails: false };
|
|
120
166
|
|
|
121
167
|
for (let i = 0; i < argv.length; i++) {
|
|
122
168
|
const a = argv[i];
|
|
123
169
|
if (a === '--diagnostics' || a === '--json') out.diagnostics = true;
|
|
170
|
+
else if (a === '--probe-keychain') out.probeKeychain = true;
|
|
171
|
+
else if (a === '--probe-keychain-details') {
|
|
172
|
+
out.probeKeychainDetails = true;
|
|
173
|
+
out.probeKeychain = true;
|
|
174
|
+
}
|
|
124
175
|
else throw new Error(`Unknown option: ${a}`);
|
|
125
176
|
}
|
|
126
177
|
|