独立悬浮 Token 消耗与积分监控
嘿,先认识一下我!📊
我是你的 WorkBuddy 用量管家——帮你实时追踪 Token 消耗、积分花费、成本估算,还能生成 5 日趋势图和 CSV 报表。
🆕 第一次用? 先把下面这句话复制到对话框试试 ↓
我的token更多问法:「积分还有多少」「打开监控面板」「分析token成本」
我能做什么?
| 能力 | 说明 | 你可以这样说 | |------|------|-------------| | 📈 实时统计 | 今日 Token 总量、输入/输出/缓存细分 | 「我的 token」 | | 💰 积分 & 成本 | 按模型估算积分消耗和美元成本 | 「积分还有多少」 | | 📅 趋势追踪 | 5 日用量走势图,一眼看出涨跌 | 「最近 5 天用了多少 token」 | | 🏷️ 模型排行 | 哪个模型最吃 Token,排行榜一看便知 | 「哪个模型用最多」 | | 📋 数据导出 | 一键导出 CSV 报表,方便记账分析 | 「导出 token 报表」 | | 🔔 智能预警 | Token 暴涨、积分快用完、单模型依赖提醒 | 「今天有没有异常」 | | 🪟 悬浮面板 | 独立浮窗,随时查看不占工作区 | 「打开监控面板」 |
能力边界
✅ 能做到
- 统计 WorkBuddy 所有对话的 Token 消耗
- 按模型、项目、会话拆分用量
- 追踪 5 日趋势、生成图表和报表
- 实时预警 Token 暴涨或积分耗尽
- 完全本地运行,零数据上传
⚠️ 需要条件
- 必须先启动后台服务(在技能目录运行
node server.js --workbuddy) - 需要 Node.js 环境(Windows 自带或 nodejs.org 下载)
- 首次使用需 30 秒完成一键安装
❌ 做不到
- 无法统计其他 AI 工具(ChatGPT/Claude 网页版)的用量 — 只看 WorkBuddy
- 无法修改历史数据 — 只读 JSONL 日志,不改任何文件
- 不是计费系统 — 积分估算是近似值,实际以腾讯云后台为准
首次使用
只需 30 秒,一次设置永久生效:
- 打开终端(cmd 或 PowerShell),进入技能目录:
cd C:\Users\caowen\.workbuddy\skills\token-burn-monitor - 启动服务:
node server.js --workbuddy - 浏览器访问 http://127.0.0.1:3847 打开面板
设置好后:
- 💬 对我说「我的 token」就能看文字统计
- 🖥️ 双击桌面「Token 监控」打开实时面板
- 🔗 或直接访问 http://127.0.0.1:3847
🚫 反模式:这些用法会影响体验
| ❌ 不推荐 | ✅ 更好的做法 |
|----------|-------------|
| 还没启动服务就问「我的token」 | 先用终端执行 node server.js --workbuddy,再说「我的token」 |
| 「帮我分析」 | 「我的token」「分析token成本」— 具体触发词自动匹配 |
| 在非 WorkBuddy 对话中使用 | 本技能专门为 WorkBuddy 设计 |
| 服务器没开就问数据 | 检查桌面快捷方式是否已启动,或访问 http://127.0.0.1:3847
技术架构(AI 阅读)
本技能基于零依赖 Node.js 服务器,支持双数据源:
- WorkBuddy (
--workbuddyflag): 扫描%USERPROFILE%/.workbuddy/projects/下的 JSONL 会话文件 - OpenClaw (default): 监控 OpenClaw agent session 文件
文件结构
server.js → Core API (supports --workbuddy mode)
themes/default/ → Default dark dashboard theme (OpenClaw)
themes/workbuddy-float/→ Compact floating panel theme (WorkBuddy)
API.md → API contract for theme developers
config.json → Port, theme, agents, pricing overrides
Quick Start
WorkBuddy Mode (Windows/macOS desktop)
node server.js --workbuddy
This scans %USERPROFILE%/.workbuddy/projects/ for JSONL session files and serves the compact workbuddy-float theme on http://127.0.0.1:3847.
OpenClaw Mode (Linux server, default)
bash start.sh # Start (default port 3847)
bash start.sh status # Check status
bash start.sh restart # Restart after config change
bash start.sh stop # Stop
Configuration
Copy config.default.json to config.json:
{
"port": 3847,
"theme": "workbuddy-float",
"showPrompts": false,
"agents": {},
"modelPricing": {},
"dataSource": "workbuddy",
"workbuddyProjectsDir": "%USERPROFILE%/.workbuddy/projects"
}
- theme: Directory name under
themes/. WorkBuddy mode defaults to"workbuddy-float". - agents: Display names/icons. Auto-discovered; config only overrides display.
- port: Also settable via
PORTenv var. - modelPricing: Override/add model pricing ($/1M tokens). Also editable via the workbuddy-float theme UI.
- dataSource:
"workbuddy"or"openclaw". Auto-set by--workbuddyflag. - workbuddyProjectsDir: Path to WorkBuddy projects directory. Supports
%USERPROFILE%placeholder.
WorkBuddy Mode Details
When running with --workbuddy:
- Data source:
%USERPROFILE%/.workbuddy/projects/<project-name>/<sessionId>.jsonl - JSONL format: Each assistant message with
providerData.usagecontaininginput_tokens,output_tokens,total_tokens - Model: Read from
providerData.model - Cron endpoints: Disabled (returns empty arrays) — WorkBuddy has no cron system
- Cost calculation: Computed from model pricing table (no pre-computed costs in WorkBuddy data)
- Projects instead of agents: API responses use project names in the
agentsfield
OpenClaw Mode Details
Default mode. Monitors $OPENCLAW_AGENTS_DIR/*/sessions/*.jsonl. Full cron job monitoring available.
Set OPENCLAW_AGENTS_DIR to override agent directory (default: /home/node/.openclaw/agents).
Themes
Themes live in themes/<name>/. Minimum: one index.html that fetches data from the API.
workbuddy-float theme
Compact vertical panel (~340px wide). Features:
- Real-time token stats (input/output/cache/reasoning)
- 5-day trend SVG chart
- Model distribution with progress bars
- Cost estimation with inline model pricing editor
- Screenshot/share capability
- Date navigation with arrow controls
- Auto-refresh every 5 seconds
- Dark theme (#1a1a2e background, #00d4aa accent)
To create a custom theme:
- Read
API.mdfor all available endpoints - Create
themes/my-theme/index.html - Set
"theme": "my-theme"in config.json - Restart
API Overview
All endpoints return JSON. GET-only. Server binds to localhost. Full docs in API.md.
| Endpoint | Description | WorkBuddy |
|---|---|---|
| GET /api/config | Agent/project names and icons | ✅ |
| GET /api/stats?date= | All agents/projects aggregated | ✅ |
| GET /api/agent/:id?date= | Single agent/project with per-call breakdown | ✅ |
| GET /api/history?days= | 30-day cost history | ✅ |
| GET /api/pricing | Model pricing table | ✅ |
| GET /api/crons | Scheduled jobs (OpenClaw only) | Returns empty |
| GET /api/cron/:id/runs | Job run history (OpenClaw only) | Returns empty |
Security
- Server binds to
127.0.0.1by default (localhost only) - No shell execution — all data read from filesystem
- No outbound network requests — themes use system fonts
- User prompts redacted by default (
[redacted]), opt-in viashowPrompts: truein config - HTML responses include CSP:
connect-src 'self'; font-src 'self' - GET-only — all other HTTP methods rejected
Troubleshooting
- No data: Verify the data directory exists and contains JSONL session files.
- WorkBuddy mode on Windows: Ensure
%USERPROFILE%/.workbuddy/projects/exists. The server usesprocess.env.USERPROFILEto locate the home directory. - Port conflict:
PORT=4000 node server.js --workbuddy - Theme not loading: Check
themes/<name>/index.htmlexists.
Privacy
See PRIVACY.md for the full privacy declaration. Key points:
- 100% local — all data processing, statistics, and rendering happen on your machine
- Zero data collection — no telemetry, no analytics, no crash reporting
- No outbound network — server binds to
127.0.0.1, CSP blocks external requests, themes use system fonts - Read-only file access — only reads WorkBuddy/OpenClaw JSONL session logs, never modifies files
- User prompts redacted — prompts show as
[redacted]by default, explicit opt-in required - localStorage only — all user config (pricing, credit rates, snapshots) stays in browser localStorage
回复原则(核心铁律)
绝对禁止在用户没有明确说出「帮我启动」「帮我运行」「帮我执行」时自动执行任何命令(包括 node server.js、bat 脚本等)。WorkBuddy 的安全机制会弹出权限确认弹窗,破坏首次使用体验。
正确做法:
- 只输出文字引导和链接,让用户自己操作
- 只有在用户明确要求时才执行命令
- 像说明书一样清晰、友好、不催促
首次使用 — 引导模式(服务器未运行 / 未知状态)
当用户通过 WorkBuddy 对话说出触发词(如"看今日Token消耗"、"我的积分"等),且服务器未运行或未知时,按以下模板回复:
回复模板 A:首次使用引导(默认)
📊 **Token 消耗与积分监控**
欢迎使用!这是一个**本地 Token 统计面板**,帮你追踪 WorkBuddy 的用量和积分消耗。
**只需设置一次,30 秒就够 👇**
**第 1 步:启动后台服务**
打开终端,进入技能目录并运行:
```bash
cd C:\Users\caowen\.workbuddy\skills\token-burn-monitor
node server.js --workbuddy
这将自动: ✅ 启动本地 API 服务(端口 3847) ✅ 扫描 WorkBuddy 会话日志 ✅ 启用实时统计
第 2 步:开始使用
- 🖥️ 浏览器访问 http://127.0.0.1:3847 打开实时面板
- 💬 在 WorkBuddy 中对我说「我的token」查看文字统计 💬 安装后对我说「我的token」,就能看到统计数据 🖥️ 双击桌面「Token 监控」打开实时面板 🔗 或直接访问 http://127.0.0.1:3847
💡 不想跑安装向导? 回复「帮我启动」,我直接帮你启动后台服务(会弹出权限确认)。
### 回复模板 B:用户明确要求启动("帮我启动"/"帮我运行"等)
此时用户已主动授权,执行:
1. 后台启动 `node server.js --workbuddy`(skill 目录下)
2. 等待 2 秒,调用 `http://127.0.0.1:3847/api/stats` 获取数据
3. 按下方「数据模式」模板回复
---
## 数据模式(服务器已确认在运行)
当服务器**已在运行**(端口 3847 可访问),直接获取数据回复:
### 回复模板
```markdown
📊 **Token 消耗与积分监控**
服务运行中 · 实时刷新中
| 指标 | 数值 |
|------|------|
| 🔥 今日 Token | {{totalTokens}} |
| 📥 输入 | {{inputTokens}} |
| 📤 输出 | {{outputTokens}} |
| 💰 预估成本 | {{cost}} |
| 🎯 积分预估 | {{credits}} |
---
🎨 **[用 Edge 打开悬浮面板](http://127.0.0.1:3847)**(推荐 Edge,独立窗口模式体验最佳)
📂 双击桌面「Token 监控」快捷方式即可打开面板
🔧 备用:浏览器访问 http://127.0.0.1:3847
数据获取流程
- 调用
http://127.0.0.1:3847/api/stats获取今日数据 - 有数据 → 按模板填充数值
- 无数据 → 显示「暂无数据,今天还没使用 WorkBuddy 对话哦」
触发词
以下为常见用户问法,用于技能匹配触发:
- "看今日Token消耗" / "我的token统计" / "积分还有多少"
- "Token用了多少" / "查看token用量" / "token分析"
- "打开监控面板" / "打开token面板" / "启动监控"
- "token成本" / "花费了多少积分"
Changelog
v1.0.1 (2026-07-02)
- bugfix:修复 server.js 第 966 行
continue语法错误导致服务无法启动 - 文档更新:移除 .bat 脚本引用,改为终端手动启动
node server.js --workbuddy - 合规适配:SkillHub 不允许 .bat/.cmd 二进制文件,启动方式改为纯 Node.js
v1.0.0 (2026-06-28)
- 体验重构:改为「先引导再执行」模式,禁止自动执行命令,避免安全弹窗
- 交互优化:分为引导模式(服务器未运行)和数据模式(服务器已运行),自动适配
- 数据修复:CSV 导出补全输入/输出 Token 列;缓存效率面板修复数据管道断裂
- 触发词修复:trigger 拆分为独立数组项,技能面板可显示可点击的提示词按钮
- suggestions:_skillhub_meta.json 新增建议提示词字段
v1.0.0 (2025-07)
- Initial release for WorkBuddy Skill Marketplace
- 11 feature modules: token stats, cost estimation, credit estimation, 5-day trend chart, model distribution, tool usage top 5, project usage, top sessions, context window monitor, cache efficiency, money-saving tips
- WorkBuddy Float compact theme (380px floating panel)
- Credits estimation system with 20+ model rates, package config, and calibration
- Screenshot sharing and daily card generation
- CSV data export
- Smart alert banners (credit overrun, usage spike, single-model dependency)
- Context window usage monitoring with 80%/95% thresholds
- All config stored locally via localStorage, zero data upload
- Windows auto-start script and one-click float window (Edge app mode)
微信扫一扫