vibeusage 0.2.8
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/LICENSE +21 -0
- package/README.md +182 -0
- package/README.zh-CN.md +182 -0
- package/bin/tracker.js +28 -0
- package/package.json +46 -0
- package/src/cli.js +64 -0
- package/src/commands/diagnostics.js +39 -0
- package/src/commands/init.js +798 -0
- package/src/commands/status.js +155 -0
- package/src/commands/sync.js +479 -0
- package/src/commands/uninstall.js +153 -0
- package/src/lib/browser-auth.js +175 -0
- package/src/lib/claude-config.js +190 -0
- package/src/lib/cli-ui.js +179 -0
- package/src/lib/codex-config.js +224 -0
- package/src/lib/debug-flags.js +9 -0
- package/src/lib/diagnostics.js +190 -0
- package/src/lib/fs.js +62 -0
- package/src/lib/gemini-config.js +284 -0
- package/src/lib/init-flow.js +48 -0
- package/src/lib/insforge-client.js +75 -0
- package/src/lib/insforge.js +23 -0
- package/src/lib/opencode-config.js +98 -0
- package/src/lib/progress.js +77 -0
- package/src/lib/prompt.js +20 -0
- package/src/lib/rollout.js +1317 -0
- package/src/lib/tracker-paths.js +66 -0
- package/src/lib/upload-throttle.js +129 -0
- package/src/lib/uploader.js +116 -0
- package/src/lib/vibescore-api.js +222 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 victor-wu.eth
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 🟢 VIBESCORE
|
|
4
|
+
|
|
5
|
+
**QUANTIFY YOUR AI OUTPUT**
|
|
6
|
+
_Real-time AI Analytics for Codex CLI_
|
|
7
|
+
|
|
8
|
+
[**www.vibeusage.cc**](https://www.vibeusage.cc)
|
|
9
|
+
|
|
10
|
+
[](https://opensource.org/licenses/MIT)
|
|
11
|
+
[](https://nodejs.org/)
|
|
12
|
+
[](https://www.apple.com/macos/)
|
|
13
|
+
|
|
14
|
+
[**English**](README.md) • [**中文说明**](README.zh-CN.md)
|
|
15
|
+
|
|
16
|
+
[**Documentation**](docs/) • [**Dashboard**](dashboard/) • [**Backend API**](BACKEND_API.md)
|
|
17
|
+
|
|
18
|
+
<br/>
|
|
19
|
+
|
|
20
|
+
<img src="docs/screenshots/dashboard.png" width="900" alt="VibeUsage Dashboard Preview"/>
|
|
21
|
+
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 🌌 Overview
|
|
27
|
+
|
|
28
|
+
**VibeUsage** is an intelligent token usage tracking system designed specifically for macOS developers. Through the all-new **Matrix-A Design System**, it provides a high-fidelity cyberpunk-style dashboard that transforms your **AI Output** into quantifiable metrics, supported by the **Neural Divergence Map** for real-time monitoring of multi-model compute distribution.
|
|
29
|
+
|
|
30
|
+
> [!TIP] > **Core Index**: Our signature metric that reflects your flow state by analyzing token consumption rates and patterns.
|
|
31
|
+
|
|
32
|
+
## 🔒 Privacy-First Architecture (Stealth Protocol)
|
|
33
|
+
|
|
34
|
+
We believe your code and thoughts are your own. VibeUsage is built with strict privacy pillars to ensure your data never leaves your control.
|
|
35
|
+
|
|
36
|
+
- 🛡️ **No Content Upload**: We never upload prompts or responses. We only compute token counts locally and send counts plus minimal metadata (timestamps, model, device).
|
|
37
|
+
- 📡 **Local Aggregation**: All token consumption analysis happens on your machine. We only relay quantized 30-minute usage buckets to the cloud.
|
|
38
|
+
- 🔐 **Hashed Identity**: Device tokens are hashed using SHA-256 server-side. Your raw credentials never exist in our database.
|
|
39
|
+
- 🔦 **Full Transparency**: Audit the sync logic yourself in `src/lib/rollout.js`. We literally only capture numbers and timestamps.
|
|
40
|
+
|
|
41
|
+
## 🚀 Key Features
|
|
42
|
+
|
|
43
|
+
- 📡 **Auto-Sync**: Real-time interception of Codex CLI pipes with **automatic background synchronization**. Once initialized, your tokens are tracked and synced without any manual commands.
|
|
44
|
+
- 🧭 **Universal-Sync**: Native support for **Codex CLI**, **Every Code**, and the latest **Claude Code**. Whether it's GPT-4, Claude 3.5 Sonnet, or o1/Gemini, token consumption from all models is unified and counted.
|
|
45
|
+
- 📊 **Matrix Dashboard**: High-performance dashboard built with React + Vite, featuring the new **Matrix-A** design language.
|
|
46
|
+
- **Neural Divergence Map**: Visualize multi-engine load balancing and compute distribution.
|
|
47
|
+
- **Cost Intelligence**: Real-time, multi-dimensional cost breakdown and forecasting.
|
|
48
|
+
- **Smart Notifications**: Non-intrusive system-level alerts using a Golden (Gold/Amber) visual style for high-value information.
|
|
49
|
+
- ⚡ **AI Analytics**: Deep analysis of Input/Output tokens, with dedicated tracking for Cached and Reasoning components.
|
|
50
|
+
- 🔒 **Identity Core**: Robust authentication and permission management to secure your development data.
|
|
51
|
+
|
|
52
|
+
### 🌌 Visual Preview
|
|
53
|
+
|
|
54
|
+
<img src="docs/screenshots/landing.png" width="900" alt="VibeUsage Landing Preview"/>
|
|
55
|
+
|
|
56
|
+
## 🛠️ Quick Start
|
|
57
|
+
|
|
58
|
+
### Installation
|
|
59
|
+
|
|
60
|
+
Initialize your environment once and forget it. VibeUsage handles all synchronization in the background automatically.
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npx --yes vibeusage init
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Note: `init` shows a consent prompt in interactive shells. Use `--yes` to skip prompts in non-interactive environments.
|
|
67
|
+
Optional: `--dry-run` previews planned changes without writing files.
|
|
68
|
+
Note: If `~/.code/config.toml` exists (or `CODE_HOME`), `init` also configures Every Code `notify` automatically. No further user intervention is required for data sync.
|
|
69
|
+
Note: If Gemini CLI home exists, `init` installs a `SessionEnd` hook in `~/.gemini/settings.json` and sets `tools.enableHooks = true` so hooks execute. This enables all Gemini hooks; disable by setting `tools.enableHooks = false` (or disabling the `vibeusage-tracker` hook).
|
|
70
|
+
|
|
71
|
+
### Sync & Status
|
|
72
|
+
|
|
73
|
+
````bash
|
|
74
|
+
While sync happens automatically, you can manually trigger a synchronization or check status anytime:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Manually sync latest local session data (Optional)
|
|
78
|
+
npx --yes vibeusage sync
|
|
79
|
+
|
|
80
|
+
# Check current link status
|
|
81
|
+
npx --yes vibeusage status
|
|
82
|
+
````
|
|
83
|
+
|
|
84
|
+
### Sources
|
|
85
|
+
|
|
86
|
+
- Codex CLI logs: `~/.codex/sessions/**/rollout-*.jsonl` (override with `CODEX_HOME`)
|
|
87
|
+
- Every Code logs: `~/.code/sessions/**/rollout-*.jsonl` (override with `CODE_HOME`)
|
|
88
|
+
- Gemini CLI logs: `~/.gemini/tmp/**/chats/session-*.json` (override with `GEMINI_HOME`)
|
|
89
|
+
|
|
90
|
+
## 🔧 Environment Variables
|
|
91
|
+
|
|
92
|
+
- `VIBESCORE_HTTP_TIMEOUT_MS`: CLI HTTP timeout in ms (default `20000`, `0` disables, clamped to `1000..120000`).
|
|
93
|
+
- `VITE_VIBESCORE_HTTP_TIMEOUT_MS`: Dashboard request timeout in ms (default `15000`, `0` disables, clamped to `1000..30000`).
|
|
94
|
+
- `GEMINI_HOME`: Override Gemini CLI home (defaults to `~/.gemini`).
|
|
95
|
+
|
|
96
|
+
## 🧰 Troubleshooting
|
|
97
|
+
|
|
98
|
+
### Streak shows 0 days while totals look correct
|
|
99
|
+
|
|
100
|
+
- Streak is defined as consecutive days ending today. If today's total is 0, streak will be 0.
|
|
101
|
+
- If you expect a non-zero streak, clear cached auth/heatmap data and sign in again:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
localStorage.removeItem("vibeusage.dashboard.auth.v1");
|
|
105
|
+
Object.keys(localStorage)
|
|
106
|
+
.filter((k) => k.startsWith("vibeusage.heatmap."))
|
|
107
|
+
.forEach((k) => localStorage.removeItem(k));
|
|
108
|
+
location.reload();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- Complete the landing page sign-in flow again after reload.
|
|
112
|
+
- Note: `insforge-auth-token` is not used by the dashboard; use `vibeusage.dashboard.auth.v1`.
|
|
113
|
+
|
|
114
|
+
## 🏗️ Architecture
|
|
115
|
+
|
|
116
|
+
```mermaid
|
|
117
|
+
graph TD
|
|
118
|
+
A[Codex CLI] -->|Rollout Logs| B(Tracker CLI)
|
|
119
|
+
B -->|AI Tokens| C{Core Relay}
|
|
120
|
+
C --> D[VibeUsage Dashboard]
|
|
121
|
+
C --> E[AI Analytics Engine]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 💻 Developer Guide
|
|
125
|
+
|
|
126
|
+
To run locally or contribute:
|
|
127
|
+
|
|
128
|
+
### Dashboard Development
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Install dependencies
|
|
132
|
+
cd dashboard
|
|
133
|
+
npm install
|
|
134
|
+
|
|
135
|
+
# Start dev server
|
|
136
|
+
npm run dev
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Debug Payload (Usage Endpoints)
|
|
140
|
+
|
|
141
|
+
When `debug=1` is included in a usage endpoint request, the response adds a `debug` object that helps the dashboard attribute slow queries without relying on response headers.
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
const res = await fetch(
|
|
145
|
+
`${baseUrl}/functions/vibeusage-usage-summary?from=2025-12-30&to=2025-12-30&debug=1`,
|
|
146
|
+
{
|
|
147
|
+
headers: { Authorization: `Bearer ${userJwt}` }
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
const data = await res.json();
|
|
151
|
+
|
|
152
|
+
if (data.debug) {
|
|
153
|
+
console.debug('usage debug', {
|
|
154
|
+
requestId: data.debug.request_id,
|
|
155
|
+
status: data.debug.status,
|
|
156
|
+
queryMs: data.debug.query_ms,
|
|
157
|
+
slowThresholdMs: data.debug.slow_threshold_ms,
|
|
158
|
+
slowQuery: data.debug.slow_query
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Architecture Validation
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# Validate Copy Registry
|
|
167
|
+
npm run validate:copy
|
|
168
|
+
|
|
169
|
+
# Run smoke tests
|
|
170
|
+
npm run smoke
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 📜 License
|
|
174
|
+
|
|
175
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
<div align="center">
|
|
180
|
+
<b>System_Ready // 2024 VibeUsage OS</b><br/>
|
|
181
|
+
<i>"More Tokens. More Vibe."</i>
|
|
182
|
+
</div>
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 🟢 VIBESCORE
|
|
4
|
+
|
|
5
|
+
**量化你的 AI 产出**
|
|
6
|
+
_Codex CLI 实时 AI 分析工具_
|
|
7
|
+
|
|
8
|
+
[**www.vibeusage.cc**](https://www.vibeusage.cc)
|
|
9
|
+
|
|
10
|
+
[](https://opensource.org/licenses/MIT)
|
|
11
|
+
[](https://nodejs.org/)
|
|
12
|
+
[](https://www.apple.com/macos/)
|
|
13
|
+
|
|
14
|
+
[**English**](README.md) • [**中文说明**](README.zh-CN.md)
|
|
15
|
+
|
|
16
|
+
[**文档**](docs/) • [**控制台**](dashboard/) • [**后端接口**](BACKEND_API.md)
|
|
17
|
+
|
|
18
|
+
<br/>
|
|
19
|
+
|
|
20
|
+
<img src="docs/screenshots/dashboard.png" width="900" alt="VibeUsage 控制台预览"/>
|
|
21
|
+
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 🌌 项目概述
|
|
27
|
+
|
|
28
|
+
**VibeUsage** 是一个专为 macOS 开发者设计的智能令牌(Token)使用追踪系统。它通过全新的 **Matrix-A Design System**,提供高度可视化的赛博朋克风格仪表盘,将你的 **AI 产出 (AI Output)** 转化为可量化的指标,并支持通过 **Neural Divergence Map** 实时监控多模型的算力分布。
|
|
29
|
+
|
|
30
|
+
> [!TIP] > **Core Index (核心指数)**: 我们的标志性指标,通过分析 Token 消耗速率与模式,反映你的开发心流状态。
|
|
31
|
+
|
|
32
|
+
## 🔒 隐私优先架构 (隐身协议)
|
|
33
|
+
|
|
34
|
+
我们坚信你的代码和思想属于你自己。VibeUsage 建立在严格的隐私支柱之上,确保你的数据始终处于受控状态。
|
|
35
|
+
|
|
36
|
+
- 🛡️ **内容不出本地**:我们从不上传 Prompt 或响应内容。只在本地计算 Token 数量,并上传 Token 计数与最小元数据(时间、模型、设备)。
|
|
37
|
+
- 📡 **本地聚合**:所有 Token 消耗分析均在你的机器上完成。我们仅将量化的 30 分钟使用桶(Usage Buckets)中继到云端。
|
|
38
|
+
- 🔐 **身份哈希**:设备令牌在服务端使用 SHA-256 进行哈希处理。你的原始凭据绝不会存在于我们的数据库中。
|
|
39
|
+
- 🔦 **全程透明**:你可以亲自审计 `src/lib/rollout.js` 中的同步逻辑。我们真正采集的只有数字和时间戳。
|
|
40
|
+
|
|
41
|
+
## 🚀 核心功能
|
|
42
|
+
|
|
43
|
+
- 📡 **自动嗅探与同步 (Auto-Sync)**: 实时监听 Codex CLI 管道并具备**全自动后台同步**功能。初始化后,你的 Token 产出将自动追踪并同步,无需手动执行脚本。
|
|
44
|
+
- 🧭 **全能采集 (Universal-Sync)**: 原生支持 **Codex CLI**, **Every Code** 以及最新的 **Claude Code**。无论是 GPT-4, Claude 3.5 Sonnet 还是 o1/Gemini,所有模型的 Token 消耗均可被统一捕获与统计。
|
|
45
|
+
- 📊 **Matrix Dashboard (矩阵控制台)**: 基于 React + Vite 的高性能仪表盘,采用全新的 **Matrix-A** 设计语言。
|
|
46
|
+
- **Neural Divergence Map (神经发散图谱)**: 可视化多引擎负载均衡状态,直观展示算力分布。
|
|
47
|
+
- **Cost Intelligence (成本智能)**: 实时、多维度的成本分解与预测。
|
|
48
|
+
- **Smart Notifications (智能通知)**: 非侵入式的系统级通知,采用金色 (Gold/Amber) 视觉传达高价值信息。
|
|
49
|
+
- ⚡ **AI Analytics (AI 分析)**: 深度分析 Input/Output Token,支持缓存 (Cached) 与推理 (Reasoning) 部分的分离监控。
|
|
50
|
+
- 🔒 **Identity Core (身份核心)**: 完备的身份验证与权限管理,保护你的开发数据资产。
|
|
51
|
+
|
|
52
|
+
### 🌌 视觉预览
|
|
53
|
+
|
|
54
|
+
<img src="docs/screenshots/landing.png" width="900" alt="VibeUsage 落地页预览"/>
|
|
55
|
+
|
|
56
|
+
## 🛠️ 快速开始
|
|
57
|
+
|
|
58
|
+
### 安装
|
|
59
|
+
|
|
60
|
+
只需一次初始化,即可变身为“自动驾驶”模式。VibeUsage 会在后台处理所有数据同步,你只需专注开发。
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npx --yes vibeusage init
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
说明:交互式终端会显示授权菜单;非交互环境可使用 `--yes` 跳过。
|
|
67
|
+
可选:`--dry-run` 仅预览将发生的变更,不写入任何文件。
|
|
68
|
+
说明:若存在 `~/.code/config.toml`(或 `CODE_HOME`),`init` 会自动配置 Every Code 的 `notify`。配置完成后,数据同步完全自动化,无需后续人工干预。
|
|
69
|
+
说明:若检测到 Gemini CLI home,`init` 会在 `~/.gemini/settings.json` 安装 `SessionEnd` hook,并将 `tools.enableHooks = true` 以确保 hook 生效。这会启用所有 Gemini hooks;如需关闭,可将 `tools.enableHooks = false`(或禁用 `vibeusage-tracker` hook)。
|
|
70
|
+
|
|
71
|
+
### 同步与状态查看
|
|
72
|
+
|
|
73
|
+
````bash
|
|
74
|
+
虽然同步是自动完成的,但你仍可以随时手动触发同步或查看状态:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# 手动同步最新的本地会话数据 (可选)
|
|
78
|
+
npx --yes vibeusage sync
|
|
79
|
+
|
|
80
|
+
# 查看当前连接状态
|
|
81
|
+
npx --yes vibeusage status
|
|
82
|
+
````
|
|
83
|
+
|
|
84
|
+
### 日志来源
|
|
85
|
+
|
|
86
|
+
- Codex CLI 日志:`~/.codex/sessions/**/rollout-*.jsonl`(可用 `CODEX_HOME` 覆盖)
|
|
87
|
+
- Every Code 日志:`~/.code/sessions/**/rollout-*.jsonl`(可用 `CODE_HOME` 覆盖)
|
|
88
|
+
- Gemini CLI 日志:`~/.gemini/tmp/**/chats/session-*.json`(可用 `GEMINI_HOME` 覆盖)
|
|
89
|
+
|
|
90
|
+
## 🔧 环境变量
|
|
91
|
+
|
|
92
|
+
- `VIBESCORE_HTTP_TIMEOUT_MS`:CLI 请求超时(毫秒,默认 `20000`,`0` 表示关闭,范围 `1000..120000`)。
|
|
93
|
+
- `VITE_VIBESCORE_HTTP_TIMEOUT_MS`:Dashboard 请求超时(毫秒,默认 `15000`,`0` 表示关闭,范围 `1000..30000`)。
|
|
94
|
+
- `GEMINI_HOME`:覆盖 Gemini CLI 的 home(默认 `~/.gemini`)。
|
|
95
|
+
|
|
96
|
+
## 🧰 常见问题
|
|
97
|
+
|
|
98
|
+
### Streak 显示 0 天但总量正常
|
|
99
|
+
|
|
100
|
+
- Streak 的口径是“从今天开始连续使用的天数”,如果今天的 total 为 0,streak 就是 0。
|
|
101
|
+
- 如果你确认应该有 streak,请清理本地缓存并重新登录:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
localStorage.removeItem("vibeusage.dashboard.auth.v1");
|
|
105
|
+
Object.keys(localStorage)
|
|
106
|
+
.filter((k) => k.startsWith("vibeusage.heatmap."))
|
|
107
|
+
.forEach((k) => localStorage.removeItem(k));
|
|
108
|
+
location.reload();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- 刷新后重新走一遍 landing page 的登录流程。
|
|
112
|
+
- 说明:Dashboard 不使用 `insforge-auth-token`,实际存储在 `vibeusage.dashboard.auth.v1`。
|
|
113
|
+
|
|
114
|
+
## 🏗️ 系统架构
|
|
115
|
+
|
|
116
|
+
```mermaid
|
|
117
|
+
graph TD
|
|
118
|
+
A[Codex CLI] -->|Rollout Logs| B(Tracker CLI)
|
|
119
|
+
B -->|AI Tokens| C{Core Relay}
|
|
120
|
+
C --> D[VibeUsage Dashboard]
|
|
121
|
+
C --> E[AI Analytics Engine]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 💻 开发者指南
|
|
125
|
+
|
|
126
|
+
如果你想在本地运行或贡献代码:
|
|
127
|
+
|
|
128
|
+
### 仪表盘开发
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# 安装依赖
|
|
132
|
+
cd dashboard
|
|
133
|
+
npm install
|
|
134
|
+
|
|
135
|
+
# 启动开发服务器
|
|
136
|
+
npm run dev
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 调试字段(Usage 接口)
|
|
140
|
+
|
|
141
|
+
当请求包含 `debug=1` 时,usage 接口会在响应体中附带 `debug` 对象,方便前端定位慢查询而不依赖响应头。
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
const res = await fetch(
|
|
145
|
+
`${baseUrl}/functions/vibeusage-usage-summary?from=2025-12-30&to=2025-12-30&debug=1`,
|
|
146
|
+
{
|
|
147
|
+
headers: { Authorization: `Bearer ${userJwt}` }
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
const data = await res.json();
|
|
151
|
+
|
|
152
|
+
if (data.debug) {
|
|
153
|
+
console.debug('usage debug', {
|
|
154
|
+
requestId: data.debug.request_id,
|
|
155
|
+
status: data.debug.status,
|
|
156
|
+
queryMs: data.debug.query_ms,
|
|
157
|
+
slowThresholdMs: data.debug.slow_threshold_ms,
|
|
158
|
+
slowQuery: data.debug.slow_query
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 整体架构验证
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# 验证 Copy 注册表
|
|
167
|
+
npm run validate:copy
|
|
168
|
+
|
|
169
|
+
# 执行烟雾测试
|
|
170
|
+
npm run smoke
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 📜 开源协议
|
|
174
|
+
|
|
175
|
+
本项目基于 [MIT](LICENSE) 协议开源。
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
<div align="center">
|
|
180
|
+
<b>System_Ready // 2024 VibeUsage OS</b><br/>
|
|
181
|
+
<i>"More Tokens. More Vibe."</i>
|
|
182
|
+
</div>
|
package/bin/tracker.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
|
|
4
|
+
const { run } = require('../src/cli');
|
|
5
|
+
const { stripDebugFlag } = require('../src/lib/debug-flags');
|
|
6
|
+
|
|
7
|
+
const { argv, debug } = stripDebugFlag(process.argv.slice(2));
|
|
8
|
+
if (debug) process.env.VIBEUSAGE_DEBUG = '1';
|
|
9
|
+
|
|
10
|
+
run(argv).catch((err) => {
|
|
11
|
+
console.error(err?.stack || String(err));
|
|
12
|
+
if (debug) {
|
|
13
|
+
if (typeof err?.status === 'number') {
|
|
14
|
+
console.error(`Status: ${err.status}`);
|
|
15
|
+
}
|
|
16
|
+
if (typeof err?.code === 'string' && err.code.trim()) {
|
|
17
|
+
console.error(`Code: ${err.code.trim()}`);
|
|
18
|
+
}
|
|
19
|
+
const original = err?.originalMessage;
|
|
20
|
+
if (original && original !== err?.message) {
|
|
21
|
+
console.error(`Original error: ${original}`);
|
|
22
|
+
}
|
|
23
|
+
if (typeof err?.nextActions === 'string' && err.nextActions.trim()) {
|
|
24
|
+
console.error(`Next actions: ${err.nextActions.trim()}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vibeusage",
|
|
3
|
+
"version": "0.2.8",
|
|
4
|
+
"description": "Codex CLI token usage tracker (macOS-first, notify-driven).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"type": "commonjs",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "node --test test/*.test.js",
|
|
12
|
+
"smoke": "node scripts/smoke/insforge-smoke.cjs",
|
|
13
|
+
"build:insforge": "node scripts/build-insforge-functions.cjs",
|
|
14
|
+
"build:insforge:check": "node scripts/build-insforge-functions.cjs --check",
|
|
15
|
+
"dashboard:dev": "npm --prefix dashboard run dev",
|
|
16
|
+
"dashboard:build": "npm --prefix dashboard run build",
|
|
17
|
+
"dashboard:preview": "npm --prefix dashboard run preview",
|
|
18
|
+
"dev:shim": "node scripts/dev-bin-shim.cjs",
|
|
19
|
+
"validate:copy": "node scripts/validate-copy-registry.cjs",
|
|
20
|
+
"copy:pull": "node scripts/copy-sync.cjs pull",
|
|
21
|
+
"copy:push": "node scripts/copy-sync.cjs push",
|
|
22
|
+
"architecture:canvas": "node scripts/ops/architecture-canvas.cjs",
|
|
23
|
+
"validate:guardrails": "node scripts/validate-architecture-guardrails.cjs"
|
|
24
|
+
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"tracker": "bin/tracker.js",
|
|
27
|
+
"vibeusage": "bin/tracker.js",
|
|
28
|
+
"vibeusage-tracker": "bin/tracker.js",
|
|
29
|
+
"vibescore-tracker": "bin/tracker.js"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"bin/",
|
|
33
|
+
"src/",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"esbuild": "0.27.2"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@insforge/sdk": "^1.0.4"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const { cmdInit } = require('./commands/init');
|
|
2
|
+
const { cmdSync } = require('./commands/sync');
|
|
3
|
+
const { cmdStatus } = require('./commands/status');
|
|
4
|
+
const { cmdDiagnostics } = require('./commands/diagnostics');
|
|
5
|
+
const { cmdUninstall } = require('./commands/uninstall');
|
|
6
|
+
|
|
7
|
+
async function run(argv) {
|
|
8
|
+
const [command, ...rest] = argv;
|
|
9
|
+
|
|
10
|
+
if (!command || command === '-h' || command === '--help') {
|
|
11
|
+
printHelp();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
switch (command) {
|
|
16
|
+
case 'init':
|
|
17
|
+
await cmdInit(rest);
|
|
18
|
+
return;
|
|
19
|
+
case 'sync':
|
|
20
|
+
await cmdSync(rest);
|
|
21
|
+
return;
|
|
22
|
+
case 'status':
|
|
23
|
+
await cmdStatus(rest);
|
|
24
|
+
return;
|
|
25
|
+
case 'diagnostics':
|
|
26
|
+
await cmdDiagnostics(rest);
|
|
27
|
+
return;
|
|
28
|
+
case 'uninstall':
|
|
29
|
+
await cmdUninstall(rest);
|
|
30
|
+
return;
|
|
31
|
+
default:
|
|
32
|
+
throw new Error(`Unknown command: ${command}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function printHelp() {
|
|
37
|
+
// Keep this short; npx users want quick guidance.
|
|
38
|
+
process.stdout.write(
|
|
39
|
+
[
|
|
40
|
+
'vibeusage',
|
|
41
|
+
'',
|
|
42
|
+
'Usage:',
|
|
43
|
+
' npx vibeusage [--debug] init [--yes] [--dry-run] [--no-open] [--link-code <code>]',
|
|
44
|
+
' npx vibeusage [--debug] sync [--auto] [--drain]',
|
|
45
|
+
' npx vibeusage [--debug] status',
|
|
46
|
+
' npx vibeusage [--debug] diagnostics [--out diagnostics.json]',
|
|
47
|
+
' npx vibeusage [--debug] uninstall [--purge]',
|
|
48
|
+
'',
|
|
49
|
+
'Notes:',
|
|
50
|
+
' - init: consent first, local setup next, browser sign-in last.',
|
|
51
|
+
' - --yes skips the consent menu (non-interactive safe).',
|
|
52
|
+
' - --dry-run previews changes without writing files.',
|
|
53
|
+
' - optional: --link-code <code> skips browser login when provided by Dashboard.',
|
|
54
|
+
' - Every Code notify installs when ~/.code/config.toml exists.',
|
|
55
|
+
' - auto sync waits for a device token.',
|
|
56
|
+
' - optional: VIBEUSAGE_DASHBOARD_URL or --dashboard-url for hosted landing.',
|
|
57
|
+
' - sync parses ~/.codex/sessions/**/rollout-*.jsonl and ~/.code/sessions/**/rollout-*.jsonl, then uploads token deltas.',
|
|
58
|
+
' - --debug shows original backend errors.',
|
|
59
|
+
''
|
|
60
|
+
].join('\n')
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { run };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const path = require('node:path');
|
|
2
|
+
|
|
3
|
+
const { writeFileAtomic, chmod600IfPossible } = require('../lib/fs');
|
|
4
|
+
const { collectTrackerDiagnostics } = require('../lib/diagnostics');
|
|
5
|
+
|
|
6
|
+
async function cmdDiagnostics(argv = []) {
|
|
7
|
+
const opts = parseArgs(argv);
|
|
8
|
+
const diagnostics = await collectTrackerDiagnostics();
|
|
9
|
+
const json = JSON.stringify(diagnostics, null, opts.compact ? 0 : 2) + '\n';
|
|
10
|
+
|
|
11
|
+
if (opts.out) {
|
|
12
|
+
const outPath = path.resolve(process.cwd(), opts.out);
|
|
13
|
+
await writeFileAtomic(outPath, json);
|
|
14
|
+
await chmod600IfPossible(outPath);
|
|
15
|
+
process.stderr.write(`Wrote diagnostics to: ${outPath}\n`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
process.stdout.write(json);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function parseArgs(argv) {
|
|
22
|
+
const out = {
|
|
23
|
+
out: null,
|
|
24
|
+
compact: false
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < argv.length; i++) {
|
|
28
|
+
const a = argv[i];
|
|
29
|
+
if (a === '--out') out.out = argv[++i] || null;
|
|
30
|
+
else if (a === '--compact') out.compact = true;
|
|
31
|
+
else if (a === '--pretty') out.compact = false;
|
|
32
|
+
else throw new Error(`Unknown option: ${a}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = { cmdDiagnostics };
|
|
39
|
+
|