opencode-tokenwatch 0.1.0 → 0.3.0
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 -21
- package/README.en.md +97 -0
- package/README.md +97 -103
- package/dist/commands.d.ts +2 -0
- package/dist/commands.jsx +369 -0
- package/dist/formatter.d.ts +103 -0
- package/dist/formatter.js +14 -3
- package/dist/generate-usage-html.d.ts +2 -0
- package/dist/generate-usage-html.js +866 -0
- package/dist/i18n.d.ts +5 -0
- package/dist/i18n.js +171 -0
- package/dist/perf-tracker.d.ts +60 -0
- package/dist/perf-tracker.js +257 -0
- package/dist/queries.d.ts +3 -1
- package/dist/queries.js +156 -97
- package/dist/sidebar.d.ts +22 -0
- package/dist/sidebar.jsx +395 -0
- package/dist/tui.d.ts +15 -1
- package/dist/tui.jsx +123 -0
- package/package.json +63 -63
- package/dist/tui.js +0 -406
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 TTWK
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TTWK
|
|
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.en.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# opencode-tokenwatch
|
|
2
|
+
|
|
3
|
+
**English** · [简体中文](./README.md)
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Real-time token usage, cache analytics & performance dashboard plugin for OpenCode CLI.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Sidebar panel** — Session-level and per-model real-time stats (requests, tokens, cache, latency, cost)
|
|
12
|
+
- **Cache hit rate** — Inline progress bars with color thresholds, trend indicators (↑/↓), and global weighted cache hit rate in the summary row
|
|
13
|
+
- **Performance metrics** — TTFT / TPS / End-to-end latency + P50/P95/P99 latency percentiles
|
|
14
|
+
- **Token distribution** — 5-bucket role breakdown (system, user, Agent, Tool and other with fallback and adaptive scaling)
|
|
15
|
+
- **Error rate statistics** — Detects and tracks failed requests (empty token response) and real-time error rate
|
|
16
|
+
- **Model pricing** — Input/cache/output unit prices
|
|
17
|
+
- **`/usage` command** — HTML Report → JSON Export → Text Report → Settings
|
|
18
|
+
- **HTML report** — Interactive ECharts dashboard: Token distribution, performance percentiles, error rate analysis, model speed rankings (redesigned from overlapping scatter plots to horizontal bar charts), auto-opened in browser
|
|
19
|
+
- **Multi-level collapse** — Panel, models, and sub-blocks collapsible with persisted state
|
|
20
|
+
- **Language switching** — Auto-detect or manually switch between Chinese and English
|
|
21
|
+
- **Per-request tracking** — TTFT/TPS/latency logged to JSONL for report analysis
|
|
22
|
+
- **Adaptive coloring** — Colors auto-derived from theme
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npm install opencode-tokenwatch
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Add to `opencode.json` or `opencode.jsonc`:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"$schema": "https://opencode.ai/config.json",
|
|
35
|
+
"plugin": ["opencode-tokenwatch"]
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
```jsonc
|
|
42
|
+
{
|
|
43
|
+
"plugin": ["opencode-tokenwatch"],
|
|
44
|
+
"pluginConfig": {
|
|
45
|
+
"opencode-tokenwatch": {
|
|
46
|
+
"sidebar": {
|
|
47
|
+
"showPerformance": true,
|
|
48
|
+
"showPricing": false,
|
|
49
|
+
"showTokenDistribution": false,
|
|
50
|
+
"showTrend": true
|
|
51
|
+
},
|
|
52
|
+
"language": "auto"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
| Option | Type | Default | Description |
|
|
59
|
+
|--------|------|---------|-------------|
|
|
60
|
+
| `sidebar.showPerformance` | boolean | `true` | Show TTFT/TPS/latency |
|
|
61
|
+
| `sidebar.showPricing` | boolean | `true` | Show model pricing |
|
|
62
|
+
| `sidebar.showTokenDistribution` | boolean | `true` | Show token distribution |
|
|
63
|
+
| `sidebar.showTrend` | boolean | `true` | Show trend indicator |
|
|
64
|
+
| `language` | `"auto"` / `"zh"` / `"en"` | `"auto"` | UI language |
|
|
65
|
+
|
|
66
|
+
Settings can also be toggled via `/usage` → Settings, taking precedence over `pluginConfig`.
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
In OpenCode TUI, run `/usage`:
|
|
71
|
+
|
|
72
|
+
- **HTML Report** — Pick a date range, generates a dashboard and opens it in browser
|
|
73
|
+
- **JSON Export** — Exports full usage data to `~/.opencode/reports/`
|
|
74
|
+
- **Text Report** — Exports Markdown report to `~/.opencode/reports/`
|
|
75
|
+
- **Settings** — Toggle sidebar blocks, switch language
|
|
76
|
+
|
|
77
|
+
## Requirements
|
|
78
|
+
|
|
79
|
+
- OpenCode CLI (with `opencode db` command)
|
|
80
|
+
- Node.js 18+
|
|
81
|
+
|
|
82
|
+
## Build
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
npm install
|
|
86
|
+
npm run build
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Related
|
|
90
|
+
|
|
91
|
+
- [opencode-throughput](https://github.com/Howardzhangdqs/opencode-throughput) — Real-time LLM performance monitoring (TTFT/TPS/latency/cost)
|
|
92
|
+
- [opencode-visual-cache](https://github.com/Hotakus/opencode-visual-cache) — TUI sidebar cache hit rate visualization, token distribution analysis
|
|
93
|
+
- [magic-context](https://github.com/cortexkit/magic-context/) — Cache-aware infinite context + cross-session memory system
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,103 +1,97 @@
|
|
|
1
|
-
# opencode-tokenwatch
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
|
|
77
|
-
##
|
|
78
|
-
|
|
79
|
-
- OpenCode CLI
|
|
80
|
-
- Node.js 18+
|
|
81
|
-
|
|
82
|
-
##
|
|
83
|
-
|
|
84
|
-
```sh
|
|
85
|
-
npm install
|
|
86
|
-
npm run build
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
##
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
cache, which is especially helpful on Windows when the default cache directory is
|
|
99
|
-
locked by another process.
|
|
100
|
-
|
|
101
|
-
## License
|
|
102
|
-
|
|
103
|
-
MIT
|
|
1
|
+
# opencode-tokenwatch
|
|
2
|
+
|
|
3
|
+
[English](./README.en.md) · **简体中文**
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
OpenCode CLI 的实时 Token 用量统计、缓存分析与性能指标插件。
|
|
8
|
+
|
|
9
|
+
## 功能
|
|
10
|
+
|
|
11
|
+
- **侧边栏面板** — 会话级与按模型的实时统计(请求数、Token、缓存、耗时、成本)
|
|
12
|
+
- **缓存命中率** — 模型行内彩色进度条,带趋势指示器(↑/↓),全局总计行显示**全局加权命中率**
|
|
13
|
+
- **性能指标** — TTFT / TPS / 端到端延迟 + P50/P95/P99 延迟分位数
|
|
14
|
+
- **Token 分布** — 5 桶角色分解(系统、用户、Agent、Tool 以及 other 兜底,支持自适应缩放)
|
|
15
|
+
- **错误率统计** — 识别并统计失败请求(空 Token 响应),实时计算错误率
|
|
16
|
+
- **模型定价** — 输入/缓存/输出单价
|
|
17
|
+
- **`/usage` 命令** — HTML 报告 → JSON 导出 → 文本报告 → 设置
|
|
18
|
+
- **HTML 报告** — 交互式 ECharts 仪表盘:Token 分布、性能分位数、错误率分析、模型效率水平排名(已重构重叠散点图为水平条形对比图),自动在浏览器打开
|
|
19
|
+
- **多级折叠** — 面板、模型、子区块均可折叠,状态持久化
|
|
20
|
+
- **语言切换** — 中英双语,可跟随系统或手动切换
|
|
21
|
+
- **性能追踪** — 每次请求的 TTFT/TPS/延迟写入 JSONL,用于报告分析
|
|
22
|
+
- **自适应配色** — 从主题色自动衍生
|
|
23
|
+
|
|
24
|
+
## 安装
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npm install opencode-tokenwatch
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
在 `opencode.json` 或 `opencode.jsonc` 中添加:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"$schema": "https://opencode.ai/config.json",
|
|
35
|
+
"plugin": ["opencode-tokenwatch"]
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 配置
|
|
40
|
+
|
|
41
|
+
```jsonc
|
|
42
|
+
{
|
|
43
|
+
"plugin": ["opencode-tokenwatch"],
|
|
44
|
+
"pluginConfig": {
|
|
45
|
+
"opencode-tokenwatch": {
|
|
46
|
+
"sidebar": {
|
|
47
|
+
"showPerformance": true,
|
|
48
|
+
"showPricing": false,
|
|
49
|
+
"showTokenDistribution": false,
|
|
50
|
+
"showTrend": true
|
|
51
|
+
},
|
|
52
|
+
"language": "auto"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
| 配置项 | 类型 | 默认值 | 说明 |
|
|
59
|
+
|--------|------|--------|------|
|
|
60
|
+
| `sidebar.showPerformance` | boolean | `true` | 显示 TTFT/TPS/延迟 |
|
|
61
|
+
| `sidebar.showPricing` | boolean | `true` | 显示模型定价 |
|
|
62
|
+
| `sidebar.showTokenDistribution` | boolean | `true` | 显示 Token 分布 |
|
|
63
|
+
| `sidebar.showTrend` | boolean | `true` | 显示趋势指示器 |
|
|
64
|
+
| `language` | `"auto"` / `"zh"` / `"en"` | `"auto"` | 界面语言 |
|
|
65
|
+
|
|
66
|
+
运行时也可通过 `/usage` → 设置 调整,优先级高于 `pluginConfig`。
|
|
67
|
+
|
|
68
|
+
## 用法
|
|
69
|
+
|
|
70
|
+
在 OpenCode TUI 中输入 `/usage`,选择:
|
|
71
|
+
|
|
72
|
+
- **HTML 报告** — 选择日期范围,生成仪表盘并在浏览器打开
|
|
73
|
+
- **JSON 导出** — 导出完整用量数据至 `~/.opencode/reports/`
|
|
74
|
+
- **文本报告** — 导出 Markdown 格式至 `~/.opencode/reports/`
|
|
75
|
+
- **设置** — 开关侧边栏显示项、切换语言
|
|
76
|
+
|
|
77
|
+
## 系统要求
|
|
78
|
+
|
|
79
|
+
- OpenCode CLI(支持 `opencode db` 命令)
|
|
80
|
+
- Node.js 18+
|
|
81
|
+
|
|
82
|
+
## 构建
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
npm install
|
|
86
|
+
npm run build
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## 相关项目
|
|
90
|
+
|
|
91
|
+
- [opencode-throughput](https://github.com/Howardzhangdqs/opencode-throughput) — 实时 LLM 性能监控,采集 TTFT/TPS/延迟和成本
|
|
92
|
+
- [opencode-visual-cache](https://github.com/Hotakus/opencode-visual-cache) — TUI 侧边栏缓存命中率可视化,Token 分布分析
|
|
93
|
+
- [magic-context](https://github.com/cortexkit/magic-context/) — 缓存感知的无限上下文 + 跨会话记忆系统
|
|
94
|
+
|
|
95
|
+
## 许可
|
|
96
|
+
|
|
97
|
+
MIT
|