Skip to content
Closed
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
8 changes: 4 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
- 读取本地 Codex rollout JSONL
- 增量解析与分片合并
- 统计请求、轮次、缓存、速度和上下文
- 通过本机 CDP 推送签名 schema v4 / auth v2 负载
- 通过本机 CDP 推送签名 schema v5 / auth v2 负载
- 写入健康快照、简略快照和日志

会话身份约束:
Expand All @@ -65,7 +65,7 @@
### 协议

- `protocol.mjs`
- `schemas/payload-v4.schema.json`
- `schemas/payload-v5.schema.json`
- `docs/auth-v2.md`
- 页面事件:`tokens-ui-for-codex`
- 页面全局:`window.__tuiForCodex`
Expand Down Expand Up @@ -112,7 +112,7 @@ Codex rollout JSONL

## 4. 协议约束

schema v4 / auth v2 是严格签名-only:
schema v5 / auth v2 是严格签名-only:

- 必须 `authRequired: true`
- 必须有 `auth.v=2`
Expand All @@ -132,7 +132,7 @@ schema v4 / auth v2 是严格签名-only:
- nonce 重放
- seq 倒退
- `authRequired !== true`
- 旧 schema v3 / auth v1
- 旧 schema v4/v3 或 auth v1

## 5. 统计口径

Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
## 未发布源码

- 版本号暂保持 1.0.2;本轮生成本地发布候选包,不自动推送 GitHub Release。
- 页面协议升级为 schema v4 / auth v2。
- 页面协议升级为 schema v5 / auth v2(认证算法保持不变)。
- 新增 8 个指定 GPT 型号的请求、轮次、会话和历史时间范围分类记录、公开价费用参考及模型详情。
- 公开价格匿名获取并本机缓存;未知模型、usage 或价格不猜测,已归档请求费用不随新价重算。
- HMAC 输入覆盖业务正文、认证版本、keyId、时间戳、nonce 与 seq。
- 密钥改为 32 字节原始值,nonce 改为 16 字节随机值。
- 临时密钥只在一次同步事件派发期间存在,页面捕获后立即删除。
Expand Down
2 changes: 1 addition & 1 deletion DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ node plugins\tokens-ui-for-codex\scripts\check-page-state.mjs
node plugins\tokens-ui-for-codex\scripts\verify-live.mjs
```

页面应只有一个 `#tui-native` 面板,协议为 schema v4 / auth v2。
页面应只有一个 `#tui-native` 面板,协议为 schema v5 / auth v2。新旧面板与监控必须成套替换。

## 更新

Expand Down
10 changes: 5 additions & 5 deletions README.agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
| --- | --- |
| 插件标识 | `tokens-ui-for-codex@tokens-ui-for-codex-local` |
| 插件版本 | 1.0.2 本地发布候选;包含未提交到 Git 的 auth v2/context/range 更新 |
| 页面协议 | 签名 schema v4 / auth v2 |
| 页面协议 | 签名 schema v5 / auth v2 |
| 页面事件 | `tokens-ui-for-codex` |
| 页面全局 | `window.__tuiForCodex` |
| 用户脚本 | `%APPDATA%\Codex++\user_scripts\tokens-ui-for-codex-panel.js` |
Expand Down Expand Up @@ -98,8 +98,8 @@ powershell.exe -NoProfile -ExecutionPolicy Bypass -File "<包根>\install.ps1"
3. 用户脚本存在,并与部署文件 SHA-256 一致
4. `codex plugin list` 显示插件为 installed/enabled
5. 页面 `panelCount=1`
6. `window.__tuiForCodexProtocol.supportedSchemaVersions` 包含 `4`
7. `window.__tuiForCodex.schemaVersion === 4`
6. `window.__tuiForCodexProtocol.supportedSchemaVersions` 包含 `5`
7. `window.__tuiForCodex.schemaVersion === 5`
8. `window.__tuiForCodex.auth.v === 2`,`keyId`/`nonce` 各 32 位十六进制
9. `window.__tuiForCodex.auth.mac` 为 64 位十六进制字符串
10. `__tuiForCodexAuthBootstrap` 与历史 `__tuiForCodexAuthKey` 均不存在
Expand Down Expand Up @@ -210,7 +210,7 @@ Get-ChildItem ((Get-Content -Raw -Encoding UTF8 .\runtime-paths.json | ConvertFr
| 两条统计条 | 用户脚本目录是否有旧 `.js` | 保留新脚本,把其他面板脚本改为 `.bak` |
| 等待数据 | 健康文件、日志、当前对话 | 切到有内容的会话,或重启监控 |
| 数字停止 | 分片、定位预警、文件 mtime | 合并分片逻辑;必要时重载页面 |
| 详情不更新 | 对话 ID、schema v4 / auth v2 | 检查控制台安全计数和监控日志 |
| 详情不更新 | 对话 ID、schema v5 / auth v2 | 检查控制台安全计数和监控日志 |
| 主题不跟随 | `<html data-theme>` | 检查页面主题观察器与宿主属性 |
| 中文路径失败 | PS1 BOM、VBS 编码 | PS1= UTF-8 BOM;VBS= UTF-16LE |
| 速度不动 | 数据源节奏 | 心跳不产生新数据,等待新的 usage record |
Expand Down Expand Up @@ -283,7 +283,7 @@ Get-ChildItem ((Get-Content -Raw -Encoding UTF8 .\runtime-paths.json | ConvertFr
1. 校验清单缺失和哈希错误均为 0
2. 重新运行安装器
3. 重载页面
4. 验证 schema v4 / auth v2 与单实例
4. 验证 schema v5 / auth v2 与单实例

## 11. 卸载

Expand Down
4 changes: 2 additions & 2 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ fallback command. The PowerShell confirmation window still requires `Y`.
Codex rollout JSONL
→ incremental parser and statistics
→ local CDP with dynamic port discovery
→ signed schema v4 / auth v2 payload
→ signed schema v5 / auth v2 payload
→ HMAC verification in the Codex++ script
→ incremental bar/dialog rendering
```
Expand Down Expand Up @@ -242,7 +242,7 @@ view does not depend on a heartbeat.

## Security and privacy

- Signed-only schema v4 / auth v2
- Signed-only schema v5 / auth v2
- HMAC authenticates integrity and origin; it does not encrypt data
- Random 256-bit per-monitor session key
- HMAC-SHA256 over the payload, auth version, key ID, timestamp, nonce and sequence
Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
- 速度使用 `≈XXXT/s`,明确表示估算值
- 指针停留在统计条上时冻结刷新,移出后立即追上最新值

详情弹层包含六个分区:
详情弹层包含以下分区:

| 分区 | 内容 |
| --- | --- |
Expand All @@ -51,6 +51,7 @@
| 监控操作 | 手动启动和安全告警;顶部健康灯可悬浮查看错误码、原因和恢复状态 |
| 当前提问请求明细 | 默认最近 10 条,加载更多每次 +20,最多 500 条 |
| 各轮摘要 | 默认最近 10 轮,加载更多每次 +50,最多 500 轮 |
| GPT 模型记录与参考费用 | 按模型查看会话、当前轮、请求及所选历史范围的用量、计价覆盖率与单模型详情 |

两个列表均为最新在前。未显示的条目不会进入页面负载,只有点击“加载更多”才按窗口拉取。
页面、监控协议和接收端都严格限制最多 **500** 条;更早的结构化请求与轮次摘要写入本地历史文件,
Expand Down Expand Up @@ -80,6 +81,23 @@
[docs/context-estimation.md](docs/context-estimation.md)。
如果未归类内容超过 60%,页面会隐藏不可靠的分类,仅保留精确已用量和上限。

## GPT 模型记录与参考费用(未发布源码)

仅支持 GPT-6.1 Sol、GPT-6 Astra、GPT-6.1 Terra、GPT-6 Sol、GPT-6 Luna、
GPT-5.6 Sol、GPT-5.6 Terra、GPT-5.6 Luna。按精确模型 ID 归属,不根据当前模型
倒填旧请求;无法归属的记录保留未知。各模型分别记录 input、cached、output、total 和请求数。

费用为 **按 OpenRouter 公开价折算的 USD 参考值**,不是 Codex 实际账单、账号余额或订阅剩余额度。
监控只匿名 GET 公开模型目录,价目快照保存到 `stateDir/pricing/openrouter-catalog.json`,
24 小时内复用,失败时标记缓存陈旧;不会向价格服务发送本机用量、消息或凭据。
缺模型、价目或必要 usage 分类时显示未知;部分结果只显示已知小计和覆盖率。
未核实的 Fast、Batch、缓存 TTL 档位不猜价,不把 reasoning 再计入 output。
请求首次归档的费用保留,不用今天的价格回填旧档案。

详情提供模型列表及单模型详情,不改变紧凑条布局;原有 auth v2 签名保留,业务 schema 升级为 v5。
账号管理、额度估值、连接器、密钥管理和外汇换算均不在此功能范围。
具体口径与已核实价格源见 [docs/model-costs.md](docs/model-costs.md)。

## 上下文能力

- 已用量取最后一次请求的 `usage.total_tokens`,并受模型上下文上限约束;
Expand Down Expand Up @@ -224,7 +242,7 @@ PowerShell 确认窗口,只有输入 `Y` 才启动。页面不会静默启动
本地 Codex 会话 JSONL
→ token-stats.mjs 增量解析与统计
→ 本机 CDP(动态端口)
→ 签名 schema v4 / auth v2 负载
→ 签名 schema v5 / auth v2 负载
→ Codex++ 用户脚本验签
→ 原生风格统计条与详情增量渲染
```
Expand Down Expand Up @@ -275,7 +293,7 @@ PowerShell 确认窗口,只有输入 `Y` 才启动。页面不会静默启动

## 安全与隐私

- 页面协议为**签名-only schema v4 / auth v2**
- 页面协议为**签名-only schema v5 / auth v2**
- HMAC 只做完整性和来源校验,不提供加密
- 每次监控启动生成随机 256-bit 会话密钥
- HMAC-SHA256 签名覆盖完整负载、认证版本、keyId、时间戳、nonce 与 seq
Expand Down
11 changes: 6 additions & 5 deletions docs/auth-v2.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# HMAC auth v2

本文描述当前工作树的本地推送认证协议。已发布的 1.0.2 标签仍使用
schema v3 / auth v1;当前未发布源码升级为 schema v4 / auth v2。
schema v3 / auth v1;当前未发布源码升级为 schema v5 / auth v2。

## 目标

Expand All @@ -14,7 +14,7 @@ schema v3 / auth v1;当前未发布源码升级为 schema v4 / auth v2。

```json
{
"schemaVersion": 4,
"schemaVersion": 5,
"authRequired": true,
"auth": {
"v": 2,
Expand Down Expand Up @@ -47,7 +47,7 @@ tokens-ui-for-codex/auth-v2

页面必须同时满足:

- `schemaVersion=4`
- `schemaVersion=5`(v4 及更早版本不接受;v5 新增模型与费用结构,认证算法不变)
- `auth.v=2`
- `keyId` 与 `nonce` 为 32 位小写十六进制
- `mac` 为 64 位小写十六进制
Expand Down Expand Up @@ -91,11 +91,12 @@ WebCrypto `CryptoKey`。

## 兼容性

schema v4 与 schema v3 不兼容:
schema v5 与 schema v4/v3 不兼容。即使同为 auth v2,业务 schema 不匹配也拒绝:

| 面板 | 监控 | 结果 |
| --- | --- | --- |
| auth v2 | auth v2 | 正常 |
| schema v5 / auth v2 | schema v5 / auth v2 | 正常 |
| schema v5 / auth v2 | schema v4 / auth v2 | `protocol-mismatch` |
| auth v1 | auth v2 | `protocol-mismatch` |
| auth v2 | auth v1 | `protocol-mismatch` |

Expand Down
67 changes: 67 additions & 0 deletions docs/model-costs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# GPT 模型记录与参考费用

状态:未发布工作树功能,版本号仍为 `1.0.2+codex.20261020131145`;等待人工验收。
业务协议为 schema v5,HMAC auth v2 的签名、时窗、nonce、seq 规则不变。

## 模型与价格核验

2026-11-03(Asia/Shanghai)匿名读取 [OpenRouter 模型目录](https://openrouter.ai/api/v1/models)
返回 HTTP 200,以下 8 个精确 ID 均存在。仅接受表中的 `openai/…` 与无前缀 ID,
不根据子串、相似名称或当前选中模型猜测历史归属。

下表为本次核验的 USD / 百万 token 快照,**不是运行时常量,也不是实际账单**:

| 模型 ID(省略 openai/) | 普通输入 | 缓存读取 | 输出 | 目录缓存写入 |
| --- | ---: | ---: | ---: | ---: |
| gpt-6.1-sol | 2 | 0.1 | 10 | 2.5 |
| gpt-6-astra | 10 | 1 | 50 | 12.5 |
| gpt-6.1-terra | 1 | 0.05 | 5 | 1.25 |
| gpt-6-sol | 2 | 0.2 | 10 | 2.5 |
| gpt-6-luna | 0.1 | 0.01 | 0.5 | 0.125 |
| gpt-5.6-sol | 4 | 0.4 | 20 | 5 |
| gpt-5.6-terra | 2 | 0.2 | 12 | 2.5 |
| gpt-5.6-luna | 0.2 | 0.02 | 1.2 | 0.25 |

目录单位是 USD / token,运算直接使用该单位。目录同时返回 `min_prompt_tokens=272000`
的上下文档位;只有可验证的完整档位才可选用。参考资料:
[OpenRouter 目录接口](https://openrouter.ai/docs/api/api-reference/models/list-all-models-and-their-properties)、
[OpenAI 官方定价](https://developers.openai.com/api/docs/pricing)。

目录文档的认证示例包含 Bearer token,匿名读取只是当前可用的 best-effort 行为,不承诺永久可用。
实现不会索取或读取 key;401/403/429、超时、坏 JSON 都使用最后有效缓存或返回不可用。

## 计价与未知值

每个模型单独记录 input、cached、output、total、请求数、参考费用以及已计价/未计价请求数。
费用与原有 token 统计独立;不改 F1 合并、速度、计时与原有累计数字。

```text
普通输入 = input − cached − 已确认的缓存写入
参考费用 = 普通输入 × prompt 价格
+ cached × input_cache_read 价格
+ 缓存写入 × input_cache_write 价格
+ output × completion 价格
```

- output 已含 reasoning,不再加一次 reasoning。
- 缓存分类缺失、非有限/负值或分类合计大于 input 时不可计价,不夹断成貌似准确的金额。
- 没有可靠模型、价格或 usage 时金额为 null,页面显示 `--` 或未知;未知不是免费。
- 有部分可计价请求时只列已知小计及覆盖率,不能当成完整费用。
- Standard 公共价参考不是实际调用渠道的账单。未核实的 Fast/Batch/12h/API profile 不套通用倍率;
API profile 解析支持精确 model/tier/TTL/上下文区间与官方来源及有效期,未提供证据的组合保持未知。
- 不计算账号余额、订阅剩余额度、真实扣款或外汇换算;不恢复历史账号实验。

## 获取、历史与隐私

- 唯一外部请求为匿名 GET 公开目录,10 秒超时;不发送本机模型用量、消息、路径或凭据。
- 缓存位于 `runtimePaths.stateDir/pricing/openrouter-catalog.json`,24 小时复用,临时文件加 rename 原子写入。
- 失败不会清空最后有效快照;stale 状态和快照时间随签名负载展示。不在每秒心跳中重新联网。
- 请求首次归档的价格结果保留;新价不重估旧请求,旧档案缺模型/费用时仍未知,不回填猜价。
- 时间范围沿用 today / 3d / 7d / 30d / all,只读取脱敏的结构化轮次档案;详情关闭时停止范围计算。
- schema、监控和面板成套使用 v5;新字段经过 auth v2 完整签名并按白名单校验,列表上限仍为 500。

## 查看方式

在详情中查看模型列表,再点击单个模型查看 token 分类、请求数、费用覆盖率。
会话、当前轮、请求明细和已有历史范围保留各自统计口径,不将它们再次相加。
紧凑条布局、宿主模型选择菜单和 Codex 配置保持原样。
Loading