Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "zcode-token-usage-statusbar",
"version": "1.5.3",
"description": "ZCode token usage query via the token_usage MCP tool, /usage command, and skill (reads the local usage DB). By default auto-installs the desktop floating usage status bar (modifies app.asar; fully quit and reopen ZCode to take effect; opt-out respected). Appends a per-answer rate line at the end of each reply (rendered deterministically via the renderer bridge; tok/s, TTFT, output tokens).",
"author": {
"name": "xhwxt/ByteRax"
},
"homepage": "https://github.com/ByteRax/zcode-token-usage-statusbar",
"repository": "https://github.com/ByteRax/zcode-token-usage-statusbar",
"license": "MIT",
"keywords": [
"token",
"usage",
"statusbar",
"monitor",
"zusage"
],
"commands": "commands",
"skills": "skills",
"packageLayout": {
"schemaVersion": 1,
"files": [
"LICENSE",
"marketplace.json",
"plugins/zcode-token-usage-statusbar/.claude-plugin/plugin.json",
"plugins/zcode-token-usage-statusbar/.mcp.json",
"plugins/zcode-token-usage-statusbar/.zcode-plugin/plugin.json",
"plugins/zcode-token-usage-statusbar/README.md",
"plugins/zcode-token-usage-statusbar/commands/install-overlay.md",
"plugins/zcode-token-usage-statusbar/commands/uninstall-overlay.md",
"plugins/zcode-token-usage-statusbar/commands/usage.md",
"plugins/zcode-token-usage-statusbar/hooks/hooks.json",
"plugins/zcode-token-usage-statusbar/hooks/prompt-submit.py",
"plugins/zcode-token-usage-statusbar/hooks/session-start.py",
"plugins/zcode-token-usage-statusbar/inject-main.cjs",
"plugins/zcode-token-usage-statusbar/install_monitor.py",
"plugins/zcode-token-usage-statusbar/overlay.js",
"plugins/zcode-token-usage-statusbar/overlay_install.py",
"plugins/zcode-token-usage-statusbar/patch_install.py",
"plugins/zcode-token-usage-statusbar/plugin-release.cjs",
"plugins/zcode-token-usage-statusbar/plugin-storage.cjs",
"plugins/zcode-token-usage-statusbar/plugin-updater.cjs",
"plugins/zcode-token-usage-statusbar/plugin_auto_update.py",
"plugins/zcode-token-usage-statusbar/quota-client.cjs",
"plugins/zcode-token-usage-statusbar/release_unpack.py",
"plugins/zcode-token-usage-statusbar/renderer_bridge.py",
"plugins/zcode-token-usage-statusbar/restart_notice.py",
"plugins/zcode-token-usage-statusbar/runtime_lock.py",
"plugins/zcode-token-usage-statusbar/skills/zcode-token-usage/SKILL.md",
"plugins/zcode-token-usage-statusbar/token_rate.py",
"plugins/zcode-token-usage-statusbar/turn-stats.js",
"plugins/zcode-token-usage-statusbar/usage_mcp.py",
"plugins/zcode-token-usage-statusbar/usage_stats.py",
"plugins/zcode-token-usage-statusbar/zusage.py"
]
},
"description_i18n": {
"en": "ZCode token usage query via the token_usage MCP tool, /usage command, and skill (reads the local usage DB). By default auto-installs the desktop floating usage status bar (modifies app.asar; fully quit and reopen ZCode to take effect; opt-out respected). Appends a per-answer rate line at the end of each reply (rendered deterministically via the renderer bridge; tok/s, TTFT, output tokens).",
"zh-CN": "ZCode token 用量查询(token_usage MCP 工具 + /usage 命令 + 技能,读本地 usage 数据库);缺配置文件或缺字段时默认为桌面客户端自动安装/修复悬浮用量状态条(修改 app.asar,成功后需完全退出并重开;显式 false 保留,环境变量优先,卸载豁免阻止重注入,无环境变量覆盖时损坏/非布尔配置不开启);每次回答末尾自动追加逐问速率行(由前端确定性渲染,依赖 renderer 桥;即时 tok/s 含思考、首字延迟、输出 token、生成耗时、段数/峰值与会话累计,--current 守卫防旧数据充数)。"
}
}
12 changes: 12 additions & 0 deletions external_plugins/zcode-token-usage-statusbar/.mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"mcpServers": {
"zusage": {
"type": "stdio",
"command": "python3",
"args": [
"${ZCODE_PLUGIN_ROOT}/usage_mcp.py"
],
"enabled": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "zcode-token-usage-statusbar",
"version": "1.5.3",
"description": "ZCode token usage query via the token_usage MCP tool, /usage command, and skill (reads the local usage DB). By default auto-installs the desktop floating usage status bar (modifies app.asar; fully quit and reopen ZCode to take effect; opt-out respected). Appends a per-answer rate line at the end of each reply (rendered deterministically via the renderer bridge; tok/s, TTFT, output tokens).",
"author": {
"name": "xhwxt/ByteRax"
},
"homepage": "https://github.com/ByteRax/zcode-token-usage-statusbar",
"repository": "https://github.com/ByteRax/zcode-token-usage-statusbar",
"license": "MIT",
"keywords": [
"token",
"usage",
"statusbar",
"monitor",
"zusage"
],
"commands": "commands",
"skills": "skills",
"packageLayout": {
"schemaVersion": 1,
"files": [
"LICENSE",
"marketplace.json",
"plugins/zcode-token-usage-statusbar/.claude-plugin/plugin.json",
"plugins/zcode-token-usage-statusbar/.mcp.json",
"plugins/zcode-token-usage-statusbar/.zcode-plugin/plugin.json",
"plugins/zcode-token-usage-statusbar/README.md",
"plugins/zcode-token-usage-statusbar/commands/install-overlay.md",
"plugins/zcode-token-usage-statusbar/commands/uninstall-overlay.md",
"plugins/zcode-token-usage-statusbar/commands/usage.md",
"plugins/zcode-token-usage-statusbar/hooks/hooks.json",
"plugins/zcode-token-usage-statusbar/hooks/prompt-submit.py",
"plugins/zcode-token-usage-statusbar/hooks/session-start.py",
"plugins/zcode-token-usage-statusbar/inject-main.cjs",
"plugins/zcode-token-usage-statusbar/install_monitor.py",
"plugins/zcode-token-usage-statusbar/overlay.js",
"plugins/zcode-token-usage-statusbar/overlay_install.py",
"plugins/zcode-token-usage-statusbar/patch_install.py",
"plugins/zcode-token-usage-statusbar/plugin-release.cjs",
"plugins/zcode-token-usage-statusbar/plugin-storage.cjs",
"plugins/zcode-token-usage-statusbar/plugin-updater.cjs",
"plugins/zcode-token-usage-statusbar/plugin_auto_update.py",
"plugins/zcode-token-usage-statusbar/quota-client.cjs",
"plugins/zcode-token-usage-statusbar/release_unpack.py",
"plugins/zcode-token-usage-statusbar/renderer_bridge.py",
"plugins/zcode-token-usage-statusbar/restart_notice.py",
"plugins/zcode-token-usage-statusbar/runtime_lock.py",
"plugins/zcode-token-usage-statusbar/skills/zcode-token-usage/SKILL.md",
"plugins/zcode-token-usage-statusbar/token_rate.py",
"plugins/zcode-token-usage-statusbar/turn-stats.js",
"plugins/zcode-token-usage-statusbar/usage_mcp.py",
"plugins/zcode-token-usage-statusbar/usage_stats.py",
"plugins/zcode-token-usage-statusbar/zusage.py"
]
},
"description_i18n": {
"en": "ZCode token usage query via the token_usage MCP tool, /usage command, and skill (reads the local usage DB). By default auto-installs the desktop floating usage status bar (modifies app.asar; fully quit and reopen ZCode to take effect; opt-out respected). Appends a per-answer rate line at the end of each reply (rendered deterministically via the renderer bridge; tok/s, TTFT, output tokens).",
"zh-CN": "ZCode token 用量查询(token_usage MCP 工具 + /usage 命令 + 技能,读本地 usage 数据库);缺配置文件或缺字段时默认为桌面客户端自动安装/修复悬浮用量状态条(修改 app.asar,成功后需完全退出并重开;显式 false 保留,环境变量优先,卸载豁免阻止重注入,无环境变量覆盖时损坏/非布尔配置不开启);每次回答末尾自动追加逐问速率行(由前端确定性渲染,依赖 renderer 桥;即时 tok/s 含思考、首字延迟、输出 token、生成耗时、段数/峰值与会话累计,--current 守卫防旧数据充数)。"
}
}
53 changes: 53 additions & 0 deletions external_plugins/zcode-token-usage-statusbar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# ZCode Token Usage Statusbar

See model speed, token usage, context size, plan quota, and Git status while you work in ZCode.

> **Important:** installing the status bar **modifies the ZCode desktop client's `app.asar`** (injects a loader and an overlay; the patch is removable and keeps a backup). After install you must **fully quit and reopen ZCode** — closing the window is not enough. Usage statistics are read from the local database and never uploaded. If you only want the query tools, skip the status bar (see [Turn off or remove](#turn-off-or-remove)).

## What you get

- Floating status bar (desktop): generation speed (tok/s), per-turn / session / today token usage, cache hit rate, sub-agent breakdown, context usage, plan-quota chip, Git status chip. Tooltips show details; the ⚙ panel toggles what is shown.
- Per-answer rate line appended under each reply: tok/s, time to first token, output tokens, duration, session totals.
- `/usage` command (today / week / models / current), the `token_usage` MCP tool, and a skill that teaches the agent how to query usage.

## Requirements

- Python **3.8+** with the standard library only — no pip packages.
- Hook commands fall back `python3` → `python` → `py -3` (Windows friendly). The stdio MCP server is fixed to `python3`; if your machine has no `python3` on PATH, edit `command` in the installed copy's `.mcp.json` to your interpreter (the MCP tool is optional; commands and hooks work without it).

## Install & first run

1. Install this plugin from the marketplace and keep it enabled.
2. Open (or reopen) a session. The plugin then installs / repairs the status bar automatically. **This modifies `app.asar` — only proceed if you trust this project.**
3. **Fully quit and reopen ZCode.**

Automatic install is on by default (missing config file or missing field = enabled). An explicit `"plugin_auto_install_overlay": false` in `~/.zcode/zcode-token-usage-statusbar/config.json` is preserved; `ZUSAGE_PLUGIN_AUTO_INSTALL=1/0` overrides the config; `/uninstall-overlay` leaves an opt-out marker that blocks re-injection. With no environment override, a corrupted or non-boolean config does **not** enable auto-install. If automatic install fails, run `/install-overlay` and follow its output; a full restart is still required.

## How it works & side effects

| Area | Behavior |
|---|---|
| Hooks | `SessionStart` syncs runtime files, checks for updates, and may show a restart notice; `PromptSubmit` records the prompt timestamp and appends the per-answer rate line. |
| MCP server | `.mcp.json` starts `usage_mcp.py` as a stdio JSON-RPC server exposing `token_usage(scope)`. It reads the local usage database only. |
| Files written | `~/.zcode/zcode-token-usage-statusbar/` (runtime files, config, per-session state; secrets file is `0600`); a patch + backup inside the ZCode client directory (`app.asar`); overlay settings in `~/.zcode/zusage3`. Uninstalling the plugin does not delete personal config. |
| Network | Local statistics never leave your machine (read-only SQLite). The plan-quota chip decrypts the host's stored OAuth credentials **in memory only** and calls BigModel / Z.ai usage endpoints directly to show your plan quota; credentials are never written to config, logs, or diagnostics. Plugin updates download code from the configured source. Optional SSH/WSL remote queries go through the connection channel you configured; the plugin never decrypts or reuses host passwords or key passphrases and never auto-deploys. The Git chip runs local read-only `git` queries (no fetch, no network). |
| Executed commands | Python scripts shipped with the plugin; `git` (read-only status queries); `ssh`/`wsl.exe` only for remote usage you configured. |
| Third-party code | None bundled — plain Python 3.8 stdlib, plain JavaScript (Electron main-process CommonJS). MIT licensed; source at [ByteRax/zcode-token-usage-statusbar](https://github.com/ByteRax/zcode-token-usage-statusbar). |

Remote sessions (SSH/WSL) need a matching `zusage.py` deployed manually on each remote host; see the [user guide](https://github.com/ByteRax/zcode-token-usage-statusbar/blob/main/docs/user-guide.md) for the full remote, quota-source, and multi-window details.

## Turn off or remove

- `/uninstall-overlay` — removes the status bar, keeps the opt-out marker, keeps personal config.
- `"plugin_auto_install_overlay": false` — keep the query tools only.
- `"answer_rate_line": false` — drop the per-answer rate line (takes effect on the next prompt).
- `"plugin_auto_update": false` — disable update checks.
- Full removal: turn off auto-update, run `/uninstall-overlay`, then uninstall the plugin from ZCode settings and fully restart. **Uninstalling the plugin alone does not remove the status bar.**

## Configuration

Default runtime config lives in `~/.zcode/zcode-token-usage-statusbar/config.json` — merge only the fields you change. Beyond the switches above it also covers remote targets, quota sources, and display options; see [`config.example.json`](https://github.com/ByteRax/zcode-token-usage-statusbar/blob/main/config.example.json) and the [user guide](https://github.com/ByteRax/zcode-token-usage-statusbar/blob/main/docs/user-guide.md).

## Source & license

MIT — [ByteRax/zcode-token-usage-statusbar](https://github.com/ByteRax/zcode-token-usage-statusbar). Bug reports and PRs welcome (Chinese or English).
53 changes: 53 additions & 0 deletions external_plugins/zcode-token-usage-statusbar/README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# ZCode Token Usage Statusbar(Token 用量状态栏)

在 ZCode 里实时查看模型速度、token 用量、上下文容量、套餐额度与 Git 状态。

> **重要提示:** 安装悬浮状态条会**修改 ZCode 桌面客户端的 `app.asar`**(注入加载器与浮层;补丁可移除且保留备份)。安装成功后必须**完全退出并重开 ZCode**,只关闭窗口不算退出。用量统计只读取本地数据库,绝不上传。如果只要查询工具、不要状态条,见[关闭或移除](#关闭或移除)。

## 你能得到什么

- 桌面悬浮状态条:生成速度(tok/s)、本轮 / 会话 / 今日 token 用量、缓存命中率、子代理明细、上下文容量、套餐额度 chip、Git 状态 chip。悬停看明细,⚙ 面板可调整显示项。
- 每条回答末尾自动追加逐问速率行:tok/s、首字延迟、输出 token、生成耗时、会话累计。
- `/usage` 命令(today / week / models / current)、`token_usage` MCP 工具,以及一个教会智能体查询用量的技能。

## 环境要求

- Python **3.8+**,仅标准库,无需安装任何 pip 包。
- Hook 命令按 `python3` → `python` → `py -3` 自动回退(兼容 Windows)。stdio MCP 服务固定使用 `python3`;若机器 PATH 里没有 `python3`,可把安装副本 `.mcp.json` 的 `command` 改成可用解释器(MCP 工具是可选的,命令与 Hook 不依赖它)。

## 安装与首次运行

1. 从插件市场安装本插件并保持启用。
2. 新建或重新打开会话,插件会自动安装 / 修复状态条。**这一步会修改 `app.asar`,请确认信任此项目。**
3. **完全退出并重开 ZCode。**

自动安装默认开启(配置文件不存在或缺字段视为开启)。`~/.zcode/zcode-token-usage-statusbar/config.json` 中已有的显式 `"plugin_auto_install_overlay": false` 会保留;环境变量 `ZUSAGE_PLUGIN_AUTO_INSTALL=1/0` 优先于配置;`/uninstall-overlay` 会留下卸载豁免标记阻止自动重注入。未设置环境变量时,损坏配置或非布尔字段**不会**触发自动安装。自动安装失败时执行 `/install-overlay` 按输出排查,成功后仍需完全重启。

## 工作原理与副作用

| 方面 | 行为 |
|---|---|
| Hook | `SessionStart` 同步运行文件、检查更新、必要时给出重启提醒;`PromptSubmit` 记录提问时间戳并追加逐问速率行。 |
| MCP 服务 | `.mcp.json` 以 stdio JSON-RPC 启动 `usage_mcp.py`,提供 `token_usage(scope)` 工具,只读本地用量数据库。 |
| 文件写入 | `~/.zcode/zcode-token-usage-statusbar/`(运行文件、配置、会话状态;凭据文件权限 `0600`);ZCode 客户端目录内的补丁与备份(`app.asar`);`~/.zcode/zusage3` 中的浮层设置。卸载插件不删除个人配置。 |
| 网络 | 本地统计绝不出本机(只读 SQLite)。套餐额度 chip 在**内存中**解密宿主持有的 OAuth 凭据,直连 BigModel / Z.ai 用量端点展示套餐额度;凭据绝不写入配置、日志或诊断。插件更新会从已配置来源下载代码。可选的 SSH/WSL 远端查询走你自行配置的连接通道;插件不解密复用宿主密码或私钥口令,也不自动部署。Git chip 只在本机只读执行 `git` 查询(不 fetch、不联网)。 |
| 执行的命令 | 随插件分发的 Python 脚本;`git`(只读状态查询);仅对你配置过的远端查询使用 `ssh`/`wsl.exe`。 |
| 第三方代码 | 不捆绑任何第三方代码——纯 Python 3.8 标准库 + 原生 JavaScript(Electron 主进程 CommonJS)。MIT 许可证;源码在 [ByteRax/zcode-token-usage-statusbar](https://github.com/ByteRax/zcode-token-usage-statusbar)。 |

SSH/WSL 远端会话需要在每台远端手工部署同版本 `zusage.py`;远端、额度源与多窗口的完整说明见[用户指南](https://github.com/ByteRax/zcode-token-usage-statusbar/blob/main/docs/user-guide.md)。

## 关闭或移除

- `/uninstall-overlay`——移除状态条,保留卸载豁免标记,保留个人配置。
- `"plugin_auto_install_overlay": false`——只保留查询工具。
- `"answer_rate_line": false`——关闭逐问速率行(下一问生效)。
- `"plugin_auto_update": false`——关闭更新检查。
- 彻底移除:先关自动更新,执行 `/uninstall-overlay`,再在 ZCode 设置里卸载插件并完全重启。**只卸载插件不会移除状态条。**

## 配置

默认运行配置在 `~/.zcode/zcode-token-usage-statusbar/config.json`——只合并需要修改的字段。除上述开关外还覆盖远端目标、额度源与显示选项;见 [`config.example.json`](https://github.com/ByteRax/zcode-token-usage-statusbar/blob/main/config.example.json) 与[用户指南](https://github.com/ByteRax/zcode-token-usage-statusbar/blob/main/docs/user-guide.md)。

## 源码与许可证

MIT — [ByteRax/zcode-token-usage-statusbar](https://github.com/ByteRax/zcode-token-usage-statusbar)。欢迎中英文 issue 与 PR。
Loading