Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opencode2-plugin-model-stats

opencode2 侧边栏插件:按模型统计当前会话的 token 用量、缓存命中率和花费。

Session  $0.59
├─ z-ai/glm-5.2 (xhigh)
│  ├─ in     2.8M
│  ├─ out    3.4K
│  ├─ cache  91%
│  └─ cost   $0.59
└─ context  208K · 20%

统计口径是全量的:会翻分页拉完整条会话历史,并把 subagent 子会话一起算进来,所以树的加总和 opencode 自己显示的 spent 对得上。

in/out总输入/总输出in 含缓存读、缓存写(对 Anthropic 这类原生只报非缓存输入的 provider,缓存部分补回来),out 含思考 token;cache 是缓存读占 in 的比例;cost 按 models.dev 标准价格 × 实际用量计算。历史消息若落库时价格被清零(cost: 0),侧边栏会用 catalog 价格按 token 用量现场重算,顶部总额与树一致。

要求

  • opencode2@opencode-ai/cli,next 通道)
  • bun

安装

git clone https://github.com/xinxinsuried/opencode2-plugin-model-stats \
  ~/.config/opencode/plugins/opencode2-plugin-model-stats
cd ~/.config/opencode/plugins/opencode2-plugin-model-stats
bun install

~/.config/opencode/cli.jsonplugins 里加上 tui.tsx绝对路径

{
  "plugins": [
    "/home/you/.config/opencode/plugins/opencode2-plugin-model-stats/tui.tsx"
  ]
}

Windows 用正斜杠:"C:/Users/you/.config/opencode/plugins/opencode2-plugin-model-stats/tui.tsx"

重启 opencode2,打开任意会话,侧边栏就有了(ctrl+psidebar 可以切换显隐)。

必须指向文件,不能指向目录。目录形式宿主会去 resolve <dir>/tui,而编译版的 import.meta.resolve 不补扩展名,会报 ENOENT ... stat '.../opencode2-plugin-model-stats/tui'

卸载

cli.jsonplugins 里删掉那行,删除目录。

文件

文件 作用
tui.tsx 侧边栏插件本体,注册 sidebar.content slot
server.ts 空的 server 插件,只为满足 plugins/ 目录的 server 侧自动扫描

开发

改完 tui.tsx 直接存盘,opencode2 按 mtime 热重载,不用重启。

加载失败会在 TUI 里弹 error toast,详细原因看 ~/.local/share/opencode/log/opencode.log

社区

linux.do 是一个好社区。

License

MIT

About

opencode2 sidebar plugin: per-model token usage, cache hit rate and cost for the current session

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages