opencode-tokenwatch 0.3.2 → 0.5.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 +79 -107
- package/README.md +79 -107
- package/dist/server.js +11 -0
- package/dist/sidebar.d.ts +1 -1
- package/dist/tui.js +3611 -0
- package/package.json +72 -63
- package/dist/commands.jsx +0 -381
- package/dist/formatter.js +0 -289
- package/dist/generate-usage-html.js +0 -886
- package/dist/i18n.js +0 -173
- package/dist/index.js +0 -7
- package/dist/perf-tracker.js +0 -299
- package/dist/queries.js +0 -393
- package/dist/sidebar.jsx +0 -604
- package/dist/stats-store.js +0 -258
- package/dist/tui.jsx +0 -178
- /package/dist/{index.d.ts → server.d.ts} +0 -0
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
CHANGED
|
@@ -1,107 +1,79 @@
|
|
|
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, cost)
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
| File | Path | Description |
|
|
82
|
-
|------|------|-------------|
|
|
83
|
-
| JSONL log | `~/.opencode/tokenwatch.jsonl` | Raw per-request log, auto-rotated at 5 MB |
|
|
84
|
-
| Aggregated stats | `~/.opencode/tokenwatch-stats.json` | Persistent performance stats, accumulates forever |
|
|
85
|
-
| Report output | `~/.opencode/reports/` | HTML / JSON / Markdown reports |
|
|
86
|
-
|
|
87
|
-
## Requirements
|
|
88
|
-
|
|
89
|
-
- OpenCode CLI (with `opencode db` command)
|
|
90
|
-
- Node.js 18+
|
|
91
|
-
|
|
92
|
-
## Build
|
|
93
|
-
|
|
94
|
-
```sh
|
|
95
|
-
npm install
|
|
96
|
-
npm run build
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Related
|
|
100
|
-
|
|
101
|
-
- [opencode-throughput](https://github.com/Howardzhangdqs/opencode-throughput) — Real-time LLM performance monitoring (TTFT/TPS/latency/cost)
|
|
102
|
-
- [opencode-visual-cache](https://github.com/Hotakus/opencode-visual-cache) — TUI sidebar cache hit rate visualization, token distribution analysis
|
|
103
|
-
- [magic-context](https://github.com/cortexkit/magic-context/) — Cache-aware infinite context + cross-session memory system
|
|
104
|
-
|
|
105
|
-
## License
|
|
106
|
-
|
|
107
|
-
MIT
|
|
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, cost)
|
|
12
|
+
- **Cache hit rate** — Per-model tracking with trend indicators (↑/↓) and global weighted total
|
|
13
|
+
- **Performance metrics** — TTFT / TPS / End-to-end latency + P50/P95/P99 latency percentiles
|
|
14
|
+
- **Token distribution** — Per-role breakdown (system / user / tool / output)
|
|
15
|
+
- **Cost tracking** — Per-model cost display (requires provider billing data)
|
|
16
|
+
- **Error rate tracking** — Detects failed requests and computes real-time error rate
|
|
17
|
+
- **`/usage` command** — HTML Report → JSON Export → Text Report → Settings
|
|
18
|
+
- **HTML report** — Interactive ECharts dashboard: token trends, performance comparison, TPS ranking, error rate analysis — auto-opened in browser
|
|
19
|
+
- **Persistent stats** — Performance metrics accumulate forever in a dedicated file, unaffected by session resets
|
|
20
|
+
- **Multi-level collapse** — Panel, models, and sub-blocks collapsible with persisted state
|
|
21
|
+
- **Language switching** — Auto-detect or manually switch between Chinese and English
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm install opencode-tokenwatch
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Add to `opencode.json` or `opencode.jsonc`:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"$schema": "https://opencode.ai/config.json",
|
|
34
|
+
"plugin": ["opencode-tokenwatch"]
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
In OpenCode TUI, run `/usage` → **Settings** to interactively toggle display items and switch language. Settings are persisted automatically — no need to edit config files manually.
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
In OpenCode TUI, run `/usage`:
|
|
45
|
+
|
|
46
|
+
- **HTML Report** — Pick a date range, generates a dashboard and opens it in browser
|
|
47
|
+
- **JSON Export** — Exports full usage data to `~/.opencode/reports/`
|
|
48
|
+
- **Text Report** — Exports Markdown report to `~/.opencode/reports/`
|
|
49
|
+
- **Settings** — Toggle sidebar blocks, switch language
|
|
50
|
+
|
|
51
|
+
## Data Files
|
|
52
|
+
|
|
53
|
+
| File | Path | Description |
|
|
54
|
+
|------|------|-------------|
|
|
55
|
+
| JSONL log | `~/.opencode/tokenwatch.jsonl` | Raw per-request log |
|
|
56
|
+
| Aggregated stats | `~/.opencode/tokenwatch-stats.json` | Persistent performance stats |
|
|
57
|
+
| Report output | `~/.opencode/reports/` | HTML / JSON / Markdown reports |
|
|
58
|
+
|
|
59
|
+
## Requirements
|
|
60
|
+
|
|
61
|
+
- OpenCode CLI (with `opencode db` command)
|
|
62
|
+
- Node.js 18+
|
|
63
|
+
|
|
64
|
+
## Build
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
npm install
|
|
68
|
+
npm run build
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Related
|
|
72
|
+
|
|
73
|
+
- [opencode-throughput](https://github.com/Howardzhangdqs/opencode-throughput) — Real-time LLM performance monitoring (TTFT/TPS/latency/cost)
|
|
74
|
+
- [opencode-visual-cache](https://github.com/Hotakus/opencode-visual-cache) — TUI sidebar cache hit rate visualization, token distribution analysis
|
|
75
|
+
- [magic-context](https://github.com/cortexkit/magic-context/) — Cache-aware infinite context + cross-session memory system
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,107 +1,79 @@
|
|
|
1
|
-
# opencode-tokenwatch
|
|
2
|
-
|
|
3
|
-
[English](./README.en.md) · **简体中文**
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
OpenCode CLI 的实时 Token 用量统计、缓存分析与性能指标插件。
|
|
8
|
-
|
|
9
|
-
## 功能
|
|
10
|
-
|
|
11
|
-
- **侧边栏面板** — 会话级与按模型的实时统计(请求数、Token、缓存、成本)
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
| 文件 | 路径 | 说明 |
|
|
82
|
-
|------|------|------|
|
|
83
|
-
| JSONL 日志 | `~/.opencode/tokenwatch.jsonl` | 原始请求日志,超 5MB 自动轮转 |
|
|
84
|
-
| 聚合统计 | `~/.opencode/tokenwatch-stats.json` | 持久化性能统计,永久累积 |
|
|
85
|
-
| 报告输出 | `~/.opencode/reports/` | HTML / JSON / Markdown 报告 |
|
|
86
|
-
|
|
87
|
-
## 系统要求
|
|
88
|
-
|
|
89
|
-
- OpenCode CLI(支持 `opencode db` 命令)
|
|
90
|
-
- Node.js 18+
|
|
91
|
-
|
|
92
|
-
## 构建
|
|
93
|
-
|
|
94
|
-
```sh
|
|
95
|
-
npm install
|
|
96
|
-
npm run build
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## 相关项目
|
|
100
|
-
|
|
101
|
-
- [opencode-throughput](https://github.com/Howardzhangdqs/opencode-throughput) — 实时 LLM 性能监控,采集 TTFT/TPS/延迟和成本
|
|
102
|
-
- [opencode-visual-cache](https://github.com/Hotakus/opencode-visual-cache) — TUI 侧边栏缓存命中率可视化,Token 分布分析
|
|
103
|
-
- [magic-context](https://github.com/cortexkit/magic-context/) — 缓存感知的无限上下文 + 跨会话记忆系统
|
|
104
|
-
|
|
105
|
-
## 许可
|
|
106
|
-
|
|
107
|
-
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 分布** — 按角色(system / user / tool / output)分解用量占比
|
|
15
|
+
- **成本追踪** — 按模型实时显示请求成本(需 provider 返回计费数据)
|
|
16
|
+
- **错误率统计** — 识别并统计失败请求,实时计算错误率
|
|
17
|
+
- **`/usage` 命令** — HTML 报告 → JSON 导出 → 文本报告 → 设置
|
|
18
|
+
- **HTML 报告** — 交互式 ECharts 仪表盘:Token 趋势、性能对比、TPS 排名、错误率分析,自动在浏览器打开
|
|
19
|
+
- **持久化统计** — 性能指标永久累积写入独立文件,历史数据不受会话重置影响
|
|
20
|
+
- **多级折叠** — 面板、模型、子区块均可折叠,状态持久化
|
|
21
|
+
- **语言切换** — 中英双语,跟随系统或手动切换
|
|
22
|
+
|
|
23
|
+
## 安装
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm install opencode-tokenwatch
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
在 `opencode.json` 或 `opencode.jsonc` 中添加:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"$schema": "https://opencode.ai/config.json",
|
|
34
|
+
"plugin": ["opencode-tokenwatch"]
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 配置
|
|
39
|
+
|
|
40
|
+
在 OpenCode TUI 中输入 `/usage` → **设置**,可交互式开关各显示项和切换界面语言,配置自动持久化,无需手动编辑配置文件。
|
|
41
|
+
|
|
42
|
+
## 用法
|
|
43
|
+
|
|
44
|
+
在 OpenCode TUI 中输入 `/usage`,选择:
|
|
45
|
+
|
|
46
|
+
- **HTML 报告** — 选择日期范围,生成仪表盘并在浏览器打开
|
|
47
|
+
- **JSON 导出** — 导出完整用量数据至 `~/.opencode/reports/`
|
|
48
|
+
- **文本报告** — 导出 Markdown 格式至 `~/.opencode/reports/`
|
|
49
|
+
- **设置** — 开关侧边栏显示项、切换语言
|
|
50
|
+
|
|
51
|
+
## 数据文件
|
|
52
|
+
|
|
53
|
+
| 文件 | 路径 | 说明 |
|
|
54
|
+
|------|------|------|
|
|
55
|
+
| JSONL 日志 | `~/.opencode/tokenwatch.jsonl` | 原始请求日志 |
|
|
56
|
+
| 聚合统计 | `~/.opencode/tokenwatch-stats.json` | 持久化性能统计 |
|
|
57
|
+
| 报告输出 | `~/.opencode/reports/` | HTML / JSON / Markdown 报告 |
|
|
58
|
+
|
|
59
|
+
## 系统要求
|
|
60
|
+
|
|
61
|
+
- OpenCode CLI(支持 `opencode db` 命令)
|
|
62
|
+
- Node.js 18+
|
|
63
|
+
|
|
64
|
+
## 构建
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
npm install
|
|
68
|
+
npm run build
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 相关项目
|
|
72
|
+
|
|
73
|
+
- [opencode-throughput](https://github.com/Howardzhangdqs/opencode-throughput) — 实时 LLM 性能监控,采集 TTFT/TPS/延迟和成本
|
|
74
|
+
- [opencode-visual-cache](https://github.com/Hotakus/opencode-visual-cache) — TUI 侧边栏缓存命中率可视化,Token 分布分析
|
|
75
|
+
- [magic-context](https://github.com/cortexkit/magic-context/) — 缓存感知的无限上下文 + 跨会话记忆系统
|
|
76
|
+
|
|
77
|
+
## 许可
|
|
78
|
+
|
|
79
|
+
MIT
|
package/dist/server.js
ADDED
package/dist/sidebar.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TuiPluginApi, TuiTheme } from "@opencode-ai/plugin/tui";
|
|
2
2
|
import type { PerfTracker } from "./perf-tracker.js";
|
|
3
|
-
import type { TokenMessage } from "./tui.
|
|
3
|
+
import type { TokenMessage } from "./tui.js";
|
|
4
4
|
export interface SidebarConfig {
|
|
5
5
|
sidebar: {
|
|
6
6
|
showPerformance: boolean;
|