@chenlongapps/opencode-token-usage 0.4.0 → 0.4.1

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/README.md CHANGED
@@ -36,7 +36,7 @@ Alternatively, add the package to your project's `opencode.json` or `opencode.js
36
36
  > [!NOTE]
37
37
  > Requires Node.js 22+. OpenCode 2.0.9, 2.0.10, and 2.0.11 have been verified across project releases. The current SDK 2.0.11 build has been reverified on OpenCode 2.0.11.
38
38
 
39
- Restart OpenCode after installation. The panel appears in the native sidebar when `session.sidebar` is set to `auto` and the terminal is wide enough. OpenCode hides the sidebar in subagent views, so the plugin renders the same panel above the composer instead.
39
+ Restart OpenCode after installation. The panel appears in the native sidebar when `session.sidebar` is set to `auto` and the terminal is wide enough. OpenCode hides the sidebar in subagent views, so the plugin keeps one live summary line above the composer with Context, Total, Cost, and TPS. Click the line to open the full statistics in a centered dialog. Press Escape or click **esc** to close it; closing the dialog does not interrupt the subagent.
40
40
 
41
41
  For remote sessions, add the package name to `plugins` in your local `~/.config/opencode/cli.json` to load only the terminal entry point. The configuration path follows `XDG_CONFIG_HOME`.
42
42
 
@@ -44,6 +44,8 @@ For remote sessions, add the package name to `plugins` in your local `~/.config/
44
44
 
45
45
  Enter `/usage` in a session to open a native dialog with the session tree's token totals and estimated cost by recorded model. Scroll with ↑/↓, Page Up/Down, Home/End, press `d` to switch between compact and detailed numbers, and close with Escape. The command does not send a prompt to the model.
46
46
 
47
+ The subagent picker keeps the summary in the form `Token Usage · Context … · Total … · Cost … · TPS …`. Missing values remain unavailable rather than becoming zero, and the line does not advertise a keyboard shortcut. Clicking it opens a smaller dialog with the sidebar's exact rows (including Steps, TPS and TTFT) without reserving space for the full panel while closed.
48
+
47
49
  The dialog is split into five sections with separate statistics:
48
50
 
49
51
  | Section | Contents |
@@ -71,7 +73,7 @@ Costs follow the sidebar's pricing and `partial`/unavailable/free conventions. C
71
73
  | `Total` | Sum of all five token categories |
72
74
  | `Context` | Latest context usage after the most recent completed compaction in the viewed session; not aggregated across the subtree |
73
75
  | `Steps` | Assistant message count across the session tree, including subagents; follows OpenCode's own stats definition, so compaction and user messages are not steps |
74
- | `Cost` | Estimated cost across the tree, pricing each assistant and compaction call with its actual model |
76
+ | `Est. Cost` | Estimated cost across the tree, pricing each assistant and compaction call with its actual model |
75
77
  | `TPS` | Generation throughput for `Output + Reasoning` across the tree; live estimates are marked with `~` |
76
78
  | `TTFT` | Average time to first token across measurable assistant steps in the tree |
77
79
 
@@ -81,8 +83,8 @@ Costs follow the sidebar's pricing and `partial`/unavailable/free conventions. C
81
83
  - A fork is a separate session tree. Inherited message copies are attributed only to their original source to prevent double counting.
82
84
  - `Context` only searches messages after the most recent compaction with `status === "completed"` and is hidden when reliable usage or a model context limit is unavailable.
83
85
  - `Steps` counts every assistant message in the tree, whether or not it reported usage, and reuses the fork-copy de-duplication so inherited history is never counted twice.
84
- - `Cost` prices every message with its recorded model. A complete non-zero price resolved by OpenCode takes precedence. If OpenCode reports a complete zero price, a complete official snapshot price overrides it; incomplete prices fall back for the whole message without mixing rates.
85
- - Gateway models can use fallback prices through exact model IDs, documented aliases, and known wrappers. A terminal `-free` or `:free` is removed only for an exact base ID lookup; other suffixes are not stripped. The fallback excludes gateway markups, regional premiums, unlisted discounts, tool fees, and taxes, so Cost is an estimate rather than a provider bill.
86
+ - `Est. Cost` prices every message with its recorded model. A complete non-zero price resolved by OpenCode takes precedence. If OpenCode reports a complete zero price, a complete official snapshot price overrides it; incomplete prices fall back for the whole message without mixing rates.
87
+ - Gateway models can use fallback prices through exact model IDs, documented aliases, and known wrappers. A terminal `-free` or `:free` is removed only for an exact base ID lookup; other suffixes are not stripped. The fallback excludes gateway markups, regional premiums, unlisted discounts, tool fees, and taxes, so Est. Cost is an estimate rather than a provider bill.
86
88
  - Confirmed free usage displays `$0.00`; unavailable prices display `—`; known subtotals with unpriced messages are marked `partial`. See the [built-in price snapshot](docs/pricing.md) for coverage, sources, and limitations.
87
89
  - Initial read failures display `Unavailable`. Later failures retain the last complete snapshot, display `Not updated`, and retry automatically.
88
90
 
package/README.zh-CN.md CHANGED
@@ -36,7 +36,7 @@ opencode plugin add @chenlongapps/opencode-token-usage
36
36
  > [!NOTE]
37
37
  > 需要 Node.js 22+。项目历次发布已验证 OpenCode 2.0.9、2.0.10 和 2.0.11;当前 SDK 2.0.11 构建已在 OpenCode 2.0.11 上重新验证。
38
38
 
39
- 安装后重启 OpenCode。终端足够宽且 `session.sidebar` 设为 `auto` 时,面板会显示在原生侧边栏中。OpenCode 在子代理视图中隐藏侧边栏,因此插件会在输入区上方显示同一面板。
39
+ 安装后重启 OpenCode。终端足够宽且 `session.sidebar` 设为 `auto` 时,面板会显示在原生侧边栏中。OpenCode 在子代理视图中隐藏侧边栏,因此插件会在输入区上方保留一行实时摘要,显示 Context、Total、Cost 和 TPS。点击摘要可在居中弹窗中查看完整统计;按 Escape 或点击 **esc** 即可关闭,关闭弹窗不会中断子代理。
40
40
 
41
41
  连接远程服务器时,可将包名加入本机 `~/.config/opencode/cli.json` 的 `plugins`,仅加载终端入口;配置路径遵循 `XDG_CONFIG_HOME`。
42
42
 
@@ -44,6 +44,8 @@ opencode plugin add @chenlongapps/opencode-token-usage
44
44
 
45
45
  在会话中输入 `/usage`,可打开原生弹窗查看当前会话树的 token 总量,以及按消息实际模型汇总的估算费用。使用 ↑/↓、Page Up/Down、Home/End 滚动,按 `d` 切换紧凑/详细数字,Escape 关闭。该命令不会向模型发送消息。
46
46
 
47
+ 子代理视图中的摘要格式为 `Token Usage · Context … · Total … · Cost … · TPS …`。缺失数据仍显示不可用,不会被当作零,摘要也不提示快捷键。点击后打开较小的弹窗,按侧边栏原有行序展示精确数值(包括 Steps、TPS 和 TTFT);关闭时不会为完整面板预留高度。
48
+
47
49
  弹窗分为五个区域,统计口径互相独立:
48
50
 
49
51
  | 区域 | 内容 |
@@ -71,7 +73,7 @@ opencode plugin add @chenlongapps/opencode-token-usage
71
73
  | `Total` | 五类 token 之和 |
72
74
  | `Context` | 当前会话最后一次已完成压缩后的最新上下文用量,不随子树累计 |
73
75
  | `Steps` | 全树(含子代理)的 assistant 消息数,口径与 OpenCode 自带统计一致,compaction 与用户消息不计为 step |
74
- | `Cost` | 按每条 assistant 与 compaction 消息实际模型估算的全树费用 |
76
+ | `Est. Cost` | 按每条 assistant 与 compaction 消息实际模型估算的全树费用 |
75
77
  | `TPS` | 全树 `Output + Reasoning` 的生成速度;生成中的估算值带 `~` 标记 |
76
78
  | `TTFT` | 全树中可测 assistant step 的平均首 token 时间 |
77
79
 
@@ -81,8 +83,8 @@ opencode plugin add @chenlongapps/opencode-token-usage
81
83
  - 分叉会话是独立会话树。继承消息副本只归原始来源,避免重复计费。
82
84
  - `Context` 仅搜索最后一次 `status === "completed"` 的 compaction 之后;没有可靠用量或模型上限时隐藏。
83
85
  - `Steps` 统计树中全部 assistant 消息,无论是否已上报用量;复用分叉副本去重,继承历史不会重复计数。
84
- - `Cost` 按每条消息记录的实际模型分别计算。OpenCode 当前解析出的完整非零价格优先;若 OpenCode 给出完整零价,且内置价格快照可以完整计价,则采用快照价格。价格不完整时整条消息回退,不混用两套费率。
85
- - 网关模型通过精确模型 ID、明确别名和已知包装格式匹配;也会尝试移除终尾 `-free` 或 `:free` 后精确查找基础 ID,其他后缀不会剥离。快照不包含网关加价、区域溢价、未列明的折扣、工具费和税费,因此 Cost 是估算而非提供商账单。
86
+ - `Est. Cost` 按每条消息记录的实际模型分别计算。OpenCode 当前解析出的完整非零价格优先;若 OpenCode 给出完整零价,且内置价格快照可以完整计价,则采用快照价格。价格不完整时整条消息回退,不混用两套费率。
87
+ - 网关模型通过精确模型 ID、明确别名和已知包装格式匹配;也会尝试移除终尾 `-free` 或 `:free` 后精确查找基础 ID,其他后缀不会剥离。快照不包含网关加价、区域溢价、未列明的折扣、工具费和税费,因此 Est. Cost 是估算而非提供商账单。
86
88
  - 确认免费时显示 `$0.00`;价格不可用时显示 `—`;只有部分消息可计算时在已知小计后标注 `partial`。覆盖范围、来源和限制见[内置官方价格快照](docs/pricing.md)。
87
89
  - 首次读取失败显示 `Unavailable`;后续失败保留上次完整快照、标注 `Not updated` 并自动重试。
88
90
 
package/ROADMAP.md CHANGED
@@ -8,18 +8,18 @@
8
8
 
9
9
  * [x] OpenCode 2.0.9 主插件与 `./tui` 入口集成
10
10
  * [x] 向原生 `sidebar.content` 追加基础面板,保留宿主内容
11
- * [x] 子代理视图使用 `session.composer.top` 显示完整面板,适配宿主隐藏侧边栏的行为
11
+ * [x] 子代理视图通过 `session.composer.top` 提供使用量入口,适配宿主隐藏侧边栏的行为(初版显示完整面板,后改为按需弹窗)
12
12
  * [x] 检测当前会话,沿 `parentID` 汇总根会话及所有后代
13
13
  * [x] 分页读取完整消息,包括压缩前历史和未打开的子代理
14
14
  * [x] 快照替换与继承历史去重,防止重复累计
15
15
  * [x] 显示 Input、Output、Reasoning、Cache Read、Cache Write
16
16
  * [x] 显示缓存命中率 Cache Rate
17
17
  * [x] 显示五类 token 的总量 Total
18
- * [x] 按当前查看会话的活动模型估算 Cost,支持模型切换
18
+ * [x] 按当前查看会话的活动模型估算 Est. Cost,支持模型切换
19
19
  * [x] 未选模型时使用所在位置的默认模型;缺失适用价格按 0 并标注
20
20
  * [x] 按每条消息的传入 token 数选择价格阶梯
21
21
  * [x] 数字使用千位逗号分组:`1200 → 1,200`、`125000 → 125,000`、`1500000 → 1,500,000`
22
- * [x] 空会话保留基础统计行并显示零;零值 Cache Write 与 Cost 隐藏
22
+ * [x] 空会话保留基础统计行并显示零;零值 Cache Write 与 Est. Cost 隐藏
23
23
  * [x] 消息用量上报后合并刷新,切换会话时隔离旧请求
24
24
  * [x] 加载、不可用、未更新与失败恢复状态
25
25
  * [x] 实际打包产物在 OpenCode 2.0.9 和 2.0.10 中验证加载、显示、刷新与子代理累计
@@ -99,6 +99,7 @@ Steps 1,234
99
99
  * [x] 显示各个模型费用
100
100
  * [x] 拆分为 Context Window / Last Request / Context Breakdown / Session / By Model,口径互不混用
101
101
  * [x] 紧凑数字(K/M)、来源条形图、Session 单行汇总、`d` 详细模式切换
102
+ * [x] 子代理视图保留 Context、Total、Cost、TPS 单行摘要,点击打开可关闭的原生居中统计弹窗
102
103
 
103
104
  ## 后续评估
104
105