python-yama 0.10.6__tar.gz → 0.10.8__tar.gz

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.
Files changed (76) hide show
  1. {python_yama-0.10.6 → python_yama-0.10.8}/PKG-INFO +1 -1
  2. {python_yama-0.10.6 → python_yama-0.10.8}/docs/agent-skill-test-framework-design.md +27 -14
  3. {python_yama-0.10.6 → python_yama-0.10.8}/skills/eval-plugin-with-yama/SKILL.md +15 -9
  4. {python_yama-0.10.6 → python_yama-0.10.8}/skills/eval-plugin-with-yama/references/debugging.md +5 -3
  5. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_cli.py +67 -4
  6. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_report.py +98 -0
  7. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_usage.py +135 -6
  8. {python_yama-0.10.6 → python_yama-0.10.8}/yama/cli.py +20 -9
  9. {python_yama-0.10.6 → python_yama-0.10.8}/yama/llm.py +26 -4
  10. {python_yama-0.10.6 → python_yama-0.10.8}/yama/report.py +45 -6
  11. {python_yama-0.10.6 → python_yama-0.10.8}/yama/runner.py +15 -1
  12. {python_yama-0.10.6 → python_yama-0.10.8}/.github/workflows/publish.yml +0 -0
  13. {python_yama-0.10.6 → python_yama-0.10.8}/.gitignore +0 -0
  14. {python_yama-0.10.6 → python_yama-0.10.8}/CLAUDE.md +0 -0
  15. {python_yama-0.10.6 → python_yama-0.10.8}/LICENSE +0 -0
  16. {python_yama-0.10.6 → python_yama-0.10.8}/README.md +0 -0
  17. {python_yama-0.10.6 → python_yama-0.10.8}/README.zh-CN.md +0 -0
  18. {python_yama-0.10.6 → python_yama-0.10.8}/docs/case-schema-reference.md +0 -0
  19. {python_yama-0.10.6 → python_yama-0.10.8}/docs/superpowers/plans/2026-08-17-concurrency-defaults.md +0 -0
  20. {python_yama-0.10.6 → python_yama-0.10.8}/docs/superpowers/plans/2026-08-17-step-timeout-failure.md +0 -0
  21. {python_yama-0.10.6 → python_yama-0.10.8}/docs/superpowers/specs/2026-08-17-concurrency-defaults-design.md +0 -0
  22. {python_yama-0.10.6 → python_yama-0.10.8}/docs/superpowers/specs/2026-08-17-step-timeout-failure-design.md +0 -0
  23. {python_yama-0.10.6 → python_yama-0.10.8}/docs/yama-intro.html +0 -0
  24. {python_yama-0.10.6 → python_yama-0.10.8}/pyproject.toml +0 -0
  25. {python_yama-0.10.6 → python_yama-0.10.8}/skills/eval-plugin-with-yama/references/case-schema.md +0 -0
  26. {python_yama-0.10.6 → python_yama-0.10.8}/skills/eval-plugin-with-yama/references/install-upgrade.md +0 -0
  27. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_assertions.py +0 -0
  28. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_cli_shim.py +0 -0
  29. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_dashboard.py +0 -0
  30. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_framework.py +0 -0
  31. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_judge_llm.py +0 -0
  32. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_llm.py +0 -0
  33. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_main_entrypoint.py +0 -0
  34. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_mocks.py +0 -0
  35. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_openai_llm.py +0 -0
  36. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_pr.py +0 -0
  37. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_preview.py +0 -0
  38. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_public_api.py +0 -0
  39. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_report_bundle.py +0 -0
  40. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_report_upload.py +0 -0
  41. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_run_plan.py +0 -0
  42. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_runner.py +0 -0
  43. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_skill_loader.py +0 -0
  44. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_skill_tool.py +0 -0
  45. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_thread_case.py +0 -0
  46. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_tool_loader.py +0 -0
  47. {python_yama-0.10.6 → python_yama-0.10.8}/tests/test_workspace.py +0 -0
  48. {python_yama-0.10.6 → python_yama-0.10.8}/uv.lock +0 -0
  49. {python_yama-0.10.6 → python_yama-0.10.8}/yama/__init__.py +0 -0
  50. {python_yama-0.10.6 → python_yama-0.10.8}/yama/__main__.py +0 -0
  51. {python_yama-0.10.6 → python_yama-0.10.8}/yama/assertions.py +0 -0
  52. {python_yama-0.10.6 → python_yama-0.10.8}/yama/dashboard.py +0 -0
  53. {python_yama-0.10.6 → python_yama-0.10.8}/yama/judge_llm.py +0 -0
  54. {python_yama-0.10.6 → python_yama-0.10.8}/yama/judge_routing.py +0 -0
  55. {python_yama-0.10.6 → python_yama-0.10.8}/yama/loaders/__init__.py +0 -0
  56. {python_yama-0.10.6 → python_yama-0.10.8}/yama/loaders/case.py +0 -0
  57. {python_yama-0.10.6 → python_yama-0.10.8}/yama/loaders/common.py +0 -0
  58. {python_yama-0.10.6 → python_yama-0.10.8}/yama/loaders/skill_loader.py +0 -0
  59. {python_yama-0.10.6 → python_yama-0.10.8}/yama/loaders/tool_loader.py +0 -0
  60. {python_yama-0.10.6 → python_yama-0.10.8}/yama/mocks.py +0 -0
  61. {python_yama-0.10.6 → python_yama-0.10.8}/yama/models.py +0 -0
  62. {python_yama-0.10.6 → python_yama-0.10.8}/yama/openai_llm.py +0 -0
  63. {python_yama-0.10.6 → python_yama-0.10.8}/yama/pr.py +0 -0
  64. {python_yama-0.10.6 → python_yama-0.10.8}/yama/preview.py +0 -0
  65. {python_yama-0.10.6 → python_yama-0.10.8}/yama/report_bundle.py +0 -0
  66. {python_yama-0.10.6 → python_yama-0.10.8}/yama/report_upload.py +0 -0
  67. {python_yama-0.10.6 → python_yama-0.10.8}/yama/thread_case.py +0 -0
  68. {python_yama-0.10.6 → python_yama-0.10.8}/yama/tools/__init__.py +0 -0
  69. {python_yama-0.10.6 → python_yama-0.10.8}/yama/tools/base.py +0 -0
  70. {python_yama-0.10.6 → python_yama-0.10.8}/yama/tools/bash/__init__.py +0 -0
  71. {python_yama-0.10.6 → python_yama-0.10.8}/yama/tools/bash/_cli_shim.py +0 -0
  72. {python_yama-0.10.6 → python_yama-0.10.8}/yama/tools/bash/bash.py +0 -0
  73. {python_yama-0.10.6 → python_yama-0.10.8}/yama/tools/bash/fs.py +0 -0
  74. {python_yama-0.10.6 → python_yama-0.10.8}/yama/tools/skill/__init__.py +0 -0
  75. {python_yama-0.10.6 → python_yama-0.10.8}/yama/tools/skill/skill.py +0 -0
  76. {python_yama-0.10.6 → python_yama-0.10.8}/yama/workspace.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: python-yama
3
- Version: 0.10.6
3
+ Version: 0.10.8
4
4
  Summary: A reproducible evaluation runner for tool-using Agent skills
5
5
  Project-URL: Repository, https://github.com/world-sim-dev/yama
6
6
  Project-URL: Issues, https://github.com/world-sim-dev/yama/issues
@@ -2442,23 +2442,34 @@ class CaseResult:
2442
2442
  def request_duration_ms(self) -> float | None: ... # 各 run request_duration_ms() 之和
2443
2443
  ```
2444
2444
 
2445
- **Token 用量统计**没有独立的 `Usage` 类,而是一条贯穿各层的普通字典字段
2446
- (`{"prompt_tokens", "completion_tokens", "total_tokens"}`,值均为 int):
2445
+ **Token 用量统计**没有独立的 `Usage` 类,而是一条贯穿各层的普通字典字段。
2446
+ `prompt_tokens`、`completion_tokens`、`total_tokens` 是始终参与聚合的三个核心 int
2447
+ 计数器;Provider 返回缓存读取数据时,字典另带可选的 `cache_read_tokens` int:
2447
2448
 
2448
2449
  - **采集**:`llm.py:_normalized_usage` 把 Provider 返回的 usage 负载规范化成上述
2449
- 三个计数器(丢弃 `prompt_tokens_details` 等 Provider 特有的明细块;缺
2450
- `total_tokens` 时用 prompt+completion 补齐;三个计数器都缺时得到 `None`),挂在
2451
- `LLMResponse.usage`。`ScriptedLLMClient` 的脚本响应可带可选的 `usage` 键,走同一
2452
- 个规范化(用于测试与回放)。
2450
+ 三个核心计数器(缺 `total_tokens` 时仍用 prompt+completion 补齐;三个核心计数器
2451
+ 都缺时得到 `None`),挂在 `LLMResponse.usage`。输入、输出、总量完全沿用 Provider
2452
+ 的 `prompt_tokens` / `completion_tokens` / `total_tokens` 语义,不反推输入、不额外
2453
+ 累加 reasoning token。Cache Read 按 `prompt_tokens_details.cached_tokens`、
2454
+ `cache_read_input_tokens`、`cached_content_token_count`、`cache_tokens`、
2455
+ `prompt_cache_hit_tokens` 的顺序取第一个有效非负值;多个别名不相加,也不把 Cache
2456
+ Read 加入 prompt/total。`ScriptedLLMClient` 的脚本响应可带可选的 `usage` 键,走
2457
+ 同一个规范化(用于测试与回放)。
2453
2458
  - **记录**:tool-loop 的每次请求把非空 usage 写进对应请求记录
2454
2459
  (`requests[].usage`,见 `runner.py:_run_step`);Judge 调用不经过 `requests`
2455
2460
  记录,`assertions.py:run_judge` 把它的 usage 补在返回的 `judge_result["usage"]`
2456
2461
  上(Provider 未报用量时两处都没有该键)。
2457
- - **聚合**:`runner.py:combine_usage` 对多个 usage 字典逐键求和,全部无数据时返回
2462
+ - **聚合**:`runner.py:combine_usage` 对三个核心计数器逐键求和,全部无数据时返回
2458
2463
  `None`(「没有数据」与「0 token」必须可区分——脚本回放或中途死掉的 run 不应显示
2459
- 成 0)。`RunResult.usage()` = 该 run 全部 `requests[].usage` + 各 Step
2460
- `judge_result["usage"]` 之和;`CaseResult.usage()` = 各 run 之和。两者的
2461
- `to_dict()` 都带 `usage` 字段,因此 `result.json` 与 `--json` 输出天然携带。
2464
+ 成 0)。可选 `cache_read_tokens` 只累加实际返回的有效值:所有调用都缺失时聚合结果
2465
+ 继续缺失该键,明确返回 0 时则保留 0。`RunResult.usage()` = 该 run 全部
2466
+ `requests[].usage` + 各 Step `judge_result["usage"]` 之和;`CaseResult.usage()` = 各
2467
+ run 之和。两者的 `to_dict()` 都带 `usage` 字段,因此 `result.json` 与 `--json`
2468
+ 输出天然携带。HTML Run 标题、comparison 表和 Case 顶部 metadata 在
2469
+ `prompt_tokens > 0` 且 `0 <= cache_read_tokens <= prompt_tokens` 时展示两位小数的
2470
+ `cache_read_tokens / prompt_tokens`;Case 级比例直接使用 `CaseResult.usage()`,即
2471
+ `所有 Run 的 cache_read_tokens 之和 / 所有 Run 的 prompt_tokens 之和`,不是逐 Run
2472
+ 百分比的平均值。缺失或异常时显示 `–`。
2462
2473
  - **耗时**:tool-loop 的每次请求都会在 `requests[].duration_ms` 记录本轮
2463
2474
  `llm.complete()` 耗时。`runner.py:combine_duration_ms` 对这些毫秒数求和,
2464
2475
  全部无数据时返回 `None`。`RunResult.request_duration_ms()` =
@@ -3145,10 +3156,12 @@ Case;`--preview` 在收集/解析之后、执行之前返回(LLM client 根
3145
3156
 
3146
3157
  `yama from-thread` 是 `cli.py:main` 里的独立子命令分支(和 `dashboard` 一样在主 parser
3147
3158
  之前按 `argv[:1]` 分发),用于把后台某条模型调用记录转换为 Case YAML 起点。它从选中
3148
- record 的 request 生成 `context.skills`/`context.tools`/`context.messages`;传入
3149
- `--commit-id` 时通过 SSH `git show <commit>:dsl.json` 取得 DSL 并写入
3150
- `mocks.state.dsl`。当 DSL workflow 和 request history 足够完整时,还会自动生成一条
3151
- `steps[]`:
3159
+ record 的 request 生成 `context.skills`/`context.tools`/`context.messages`。默认通过
3160
+ SSH `git show HEAD:dsl.json` 尝试读取目标 Thread 远端 workspace 当前检出提交的 DSL;
3161
+ 这里的 `HEAD` 不会触发 `git fetch`。读取成功时 DSL 写入 `mocks.state.dsl`;读取失败时
3162
+ stderr 打印 warning,并继续生成不含 DSL 的 Case 骨架。显式传入 `--commit-id <ref>`
3163
+ 则改为读取 `<ref>:dsl.json`,且读取失败保持 `ThreadCaseError`(退出码 2),不会降级。
3164
+ 当 DSL workflow 和 request history 足够完整时,还会自动生成一条 `steps[]`:
3152
3165
 
3153
3166
  模型记录的 HTTP transport 由 `YAMA_THREAD_HTTP_TRANSPORT` 控制,值会去除首尾空白并
3154
3167
  按大小写不敏感方式解析:
@@ -159,7 +159,8 @@ outcome:
159
159
 
160
160
  当用户说“把这次线上对话做成 eval”“复现这个 thread”“从 record 生成 case”时,先尝试从
161
161
  用户给出的 thread URL、record id、message id 或日志里提取 `--record-id` 所需的
162
- `thread_id, message_id`。缺 Bearer token、目标环境、具体 record 下标或是否抓 DSL 时再问。
162
+ `thread_id, message_id`。缺 Bearer token、目标环境、具体 record 下标,或需要历史 DSL
163
+ 但缺少对应 commit ref 时再问。
163
164
 
164
165
  不想手工誊抄某次真实对话的 System Prompt / Tool Schema / History 时,先把用户给出的
165
166
  thread URL、record id、message id、环境、record 下标、commit id 等信息转成对应的
@@ -178,20 +179,21 @@ yama from-thread \
178
179
  `<thread_id>-<message_id>.yaml`,便于从文件名反查来源对话。
179
180
  - `--token`(必填):调用 Admin API 的 Bearer Token。
180
181
  - `--env {dev,staging,prod}`(默认 `dev`;dev 和 staging 共用同一套 Base URL/SSH
181
- 配置):选择 Admin API Base URL;同时传了 `--commit-id` 时还决定 DSL 所在的
182
- SSH Host 与远端目录。
182
+ 配置):选择 Admin API Base URL,并决定 DSL 所在的 SSH Host 与远端目录。
183
183
  - `--thread-type {one_shot,interactive,streaming,adventurer,gamer,atelier}`:
184
184
  查询参数,不传就让服务端按 Thread 自身存的类型回退。
185
185
  - `--record-index`(默认 `-1`,即最后一条):一条 Message 可能挂了多条 Model
186
186
  Record,用它选具体第几条。
187
- - `--commit-id`:额外通过 SSH 执行 `git show <commit>:dsl.json` 抓取该 Thread
188
- 在某次提交时的 DSL,合并进生成的 `mocks.state.dsl`;不传就完全跳过 DSL 抓取。
187
+ - `--commit-id`:指定通过 SSH 执行 `git show <ref>:dsl.json` 所读取的 Git ref。
188
+ 不传时默认尝试 `HEAD:dsl.json`;这里的 `HEAD` 是远端 workspace 当前检出的提交,
189
+ 命令不会执行 `git fetch`。隐式 `HEAD` 读取失败时会在 stderr 警告并继续生成无 DSL
190
+ 骨架;显式 ref 读取失败则报 `ThreadCaseError` 并退出。
189
191
 
190
192
  stdout 只输出 Case YAML(可直接重定向进文件);stderr 打印选中 record 的定位信息
191
193
  (`provider_file`/`line_no`/`model`/`datetime`)和 response 预览,用来确认抓到的是不是
192
194
  想要的那次调用。生成的骨架里 `context.tools` 是把该次请求的 tools 逐个转成
193
195
  `inline` Schema,`context.skills` 是从 System Prompt 的 `<available_skills>` 块解出来的
194
- Skill 名列表;传了 `--commit-id` 时会把 DSL 放进 `mocks.state.dsl`。
196
+ Skill 名列表;DSL 获取成功时会把它放进 `mocks.state.dsl`。
195
197
 
196
198
  对 `from-thread` 生成的 Case,**除 `mocks.tools` 外,其它内容一律以 bash 命令输出为准**:
197
199
  不要用大模型改写 `context`、`steps`、`description`、`outcome`、自动生成的 hard checks 或
@@ -224,8 +226,9 @@ config/alias/版本路径和来源 record/commit 告诉用户。
224
226
  这类情况下先回到用户确认是否需要手写 Step,而不是直接用大模型猜写完整 Case。
225
227
 
226
228
  失败会在 stderr 打印 `Thread case error: ...`,退出码 2(Admin API 请求失败、
227
- `--record-id` 格式不对、record index 越界、SSH/`git show` 失败等都算这一类,和
228
- Collection error / LLM error 分属不同层级)。
229
+ `--record-id` 格式不对、record index 越界、显式 commit 的 SSH/`git show` 失败等都算
230
+ 这一类,和 Collection error / LLM error 分属不同层级)。默认隐式读取 `HEAD` 的
231
+ SSH/`git show` 失败是例外:它只打印 warning,然后返回无 DSL 骨架和退出码 0。
229
232
 
230
233
  ## 安装与升级
231
234
 
@@ -296,7 +299,10 @@ macOS 在 exFAT 等卷上生成的 AppleDouble `._*.yaml` 会在解析前被忽
296
299
  `LLM error` / `Framework error` 文本在对应 Case header 里看。每轮 LLM Request
297
300
  详情会展示 Method、Duration、Arguments、Response,Response 是完整 assistant
298
301
  message(含 tool_calls);Case/Run/Step 层级仍展示 tool-loop LLM Request
299
- 耗时总和。
302
+ 耗时总和。Provider 返回 Cache Read 时,Run 标题与 comparison 表还会展示输入、输出、
303
+ 总 Token 和 `Cache Read / prompt_tokens` 的缓存读取占比;Case 顶部 metadata 会按所有
304
+ Run 的 Token 总量计算同一口径的加权占比,而不是对各 Run 的百分比取平均。未返回或
305
+ 比例异常时显示 `–`。
300
306
 
301
307
  当仓库 CI 使用 `yama pr-run --report --upload-report --commit-id <sha>` 时,yama 会上传当前
302
308
  commit 报告、每个运行到的 Case 详情报告,并更新受影响 Plugin 的远端 latest 报告。
@@ -32,11 +32,11 @@
32
32
 
33
33
  | 文件 | 内容 | 什么时候看 |
34
34
  | --- | --- | --- |
35
- | `result.json` | run 是否通过、`status`(`pass`/`fail`/`error`)、`error`/`traceback`、全量数据汇总(含 run 级 `usage` token 汇总、`request_duration_ms` LLM Request 耗时汇总、`runs[].tag_summary` 与每个 Step 的 `tag_summary`,Provider 未报用量时 usage 为 null) | **永远先看**:status/error 决定排查层级 |
35
+ | `result.json` | run 是否通过、`status`(`pass`/`fail`/`error`)、`error`/`traceback`、全量数据汇总(含 run 级 `usage` token 汇总、`request_duration_ms` LLM Request 耗时汇总、`runs[].tag_summary` 与每个 Step 的 `tag_summary`,Provider 未报用量时 usage 为 null;Provider 返回缓存读取时 usage 另带可选 `cache_read_tokens`) | **永远先看**:status/error 决定排查层级 |
36
36
  | `hard-checks.json` | `{step_id: [每条断言的 type/passed/label/expected/actual/reason/detail]}` | Step 断言失败时 |
37
37
  | `mock-events.json` | 每次 Tool 调用:`tool/arguments/result/is_error/match_failed/state_diff/duration_ms`。`is_error` 是语义判定:结果带**非 null** `error`,或 bash 信封 `exit_code != 0`;成功结果里的 `error: null` 不算错误 | 怀疑 Mock 匹配 / Tool 行为时 |
38
38
  | `mock-state.json` | run 结束时的最终共享 state | 有状态 Handler / Python Checker 断言失败时 |
39
- | `requests/request-00N.json` | 每次真实 LLM 调用的完整入参(messages/tools)、完整 assistant response 与 `duration_ms`;请求失败时带 `error` 字段,Provider 报了用量时带 `usage`(prompt/completion/total tokens) | 怀疑「模型到底看到了什么」或哪一轮慢时 |
39
+ | `requests/request-00N.json` | 每次真实 LLM 调用的完整入参(messages/tools)、完整 assistant response 与 `duration_ms`;请求失败时带 `error` 字段,Provider 报了用量时带 `usage`(prompt/completion/total tokens,以及可选的 Cache Read) | 怀疑「模型到底看到了什么」或哪一轮慢时 |
40
40
  | `transcript.json` | 每个 Step 结束后的完整对话快照(含注入消息、Tool Result) | 复盘模型行为时 |
41
41
  | `rendered-system-prompt.txt` | 实际发送的 System Prompt(含 `<available_skills>`) | 怀疑 Skill 没暴露 / 渲染不对时 |
42
42
  | `case.resolved.yaml` | Case 展开后的编译产物 | 怀疑路径 / 默认值解析不符合预期时 |
@@ -45,7 +45,9 @@
45
45
 
46
46
  `--report` 生成自包含 HTML,逐 Case/Run/Step 展示 transcript、Tool Call、断言、
47
47
  LLM token 用量与 LLM Request 耗时(顶部 `CASES PASSED` / `CASES ERRORS` /
48
- `LLM TOKENS` 汇总卡片 + 各层级耗时明细)。每轮 LLM Request
48
+ `LLM TOKENS` 汇总卡片 + 各层级耗时明细;每个 Run 还会展示输入、输出、总 Token,
49
+ Provider 返回 Cache Read 时展示 `Cache Read / prompt_tokens` 的缓存读取占比;Case 顶部
50
+ metadata 按所有 Run 的 Cache Read 与 prompt token 总和计算加权占比)。每轮 LLM Request
49
51
  详情会同时展示 Method、Duration、Arguments、Response,Response 是完整 assistant
50
52
  message(含 tool_calls),适合人工浏览;省略路径时默认写带
51
53
  时间戳的 `.yama/reports/report-<ts>.html`(历史累积,`latest.html` 是指向最新
@@ -1618,6 +1618,8 @@ class FromThreadCommandTests(unittest.TestCase):
1618
1618
  stderr = io.StringIO()
1619
1619
  with patch(
1620
1620
  "yama.cli.fetch_model_records", return_value=self._fake_payload()
1621
+ ), patch(
1622
+ "yama.cli.fetch_dsl_at_commit", return_value={}
1621
1623
  ), contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr):
1622
1624
  code = main(
1623
1625
  [
@@ -1659,6 +1661,8 @@ class FromThreadCommandTests(unittest.TestCase):
1659
1661
  def test_passes_record_id_to_case_builder(self) -> None:
1660
1662
  with patch(
1661
1663
  "yama.cli.fetch_model_records", return_value=self._fake_payload()
1664
+ ), patch(
1665
+ "yama.cli.fetch_dsl_at_commit", return_value={}
1662
1666
  ), patch(
1663
1667
  "yama.cli.build_case_dict", return_value={"context": {}, "steps": []}
1664
1668
  ) as build:
@@ -1758,13 +1762,46 @@ class FromThreadCommandTests(unittest.TestCase):
1758
1762
  self.assertEqual(code, 2)
1759
1763
  self.assertIn("Thread case error", stderr.getvalue())
1760
1764
 
1761
- def test_omitting_commit_id_never_calls_fetch_dsl_at_commit(self) -> None:
1765
+ def test_omitting_commit_id_fetches_dsl_from_head(self) -> None:
1766
+ stdout = io.StringIO()
1767
+ stderr = io.StringIO()
1768
+ dsl = {"workflow": {"steps": []}}
1769
+ with patch(
1770
+ "yama.cli.fetch_model_records", return_value=self._fake_payload()
1771
+ ), patch(
1772
+ "yama.cli.fetch_dsl_at_commit", return_value=dsl
1773
+ ) as fetch_dsl, contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(
1774
+ stderr
1775
+ ):
1776
+ code = main(
1777
+ [
1778
+ "from-thread",
1779
+ "--record-id", "th_1, msg_1",
1780
+ "--token", "tok",
1781
+ ]
1782
+ )
1783
+
1784
+ self.assertEqual(code, 0)
1785
+ fetch_dsl.assert_called_once_with(
1786
+ "th_1", "HEAD", "root@8.219.55.193", "/work/aion-runtime-v2-dev"
1787
+ )
1788
+ self.assertEqual(
1789
+ yaml.safe_load(stdout.getvalue())["mocks"],
1790
+ {"state": {"dsl": dsl}},
1791
+ )
1792
+ self.assertIn("at commit HEAD", stderr.getvalue())
1793
+
1794
+ def test_implicit_head_failure_warns_and_generates_case_without_dsl(
1795
+ self,
1796
+ ) -> None:
1797
+ stdout = io.StringIO()
1798
+ stderr = io.StringIO()
1762
1799
  with patch(
1763
1800
  "yama.cli.fetch_model_records", return_value=self._fake_payload()
1764
1801
  ), patch(
1765
1802
  "yama.cli.fetch_dsl_at_commit",
1766
- side_effect=AssertionError("fetch_dsl_at_commit should not be called"),
1767
- ) as fetch_dsl:
1803
+ side_effect=ThreadCaseError("git show failed"),
1804
+ ), contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr):
1768
1805
  code = main(
1769
1806
  [
1770
1807
  "from-thread",
@@ -1772,8 +1809,34 @@ class FromThreadCommandTests(unittest.TestCase):
1772
1809
  "--token", "tok",
1773
1810
  ]
1774
1811
  )
1812
+
1775
1813
  self.assertEqual(code, 0)
1776
- fetch_dsl.assert_not_called()
1814
+ parsed = yaml.safe_load(stdout.getvalue())
1815
+ self.assertNotIn("mocks", parsed)
1816
+ self.assertEqual(parsed["steps"], [])
1817
+ self.assertIn("failed to fetch DSL at HEAD", stderr.getvalue())
1818
+ self.assertIn("continuing without DSL", stderr.getvalue())
1819
+
1820
+ def test_explicit_commit_dsl_failure_remains_fatal(self) -> None:
1821
+ stderr = io.StringIO()
1822
+ with patch(
1823
+ "yama.cli.fetch_model_records", return_value=self._fake_payload()
1824
+ ), patch(
1825
+ "yama.cli.fetch_dsl_at_commit",
1826
+ side_effect=ThreadCaseError("git show failed"),
1827
+ ), contextlib.redirect_stderr(stderr):
1828
+ code = main(
1829
+ [
1830
+ "from-thread",
1831
+ "--record-id", "th_1, msg_1",
1832
+ "--token", "tok",
1833
+ "--commit-id", "abc123",
1834
+ ]
1835
+ )
1836
+
1837
+ self.assertEqual(code, 2)
1838
+ self.assertIn("Thread case error", stderr.getvalue())
1839
+ self.assertIn("git show failed", stderr.getvalue())
1777
1840
 
1778
1841
 
1779
1842
  class PrPlanCliTests(unittest.TestCase):
@@ -537,6 +537,7 @@ class TokenUsageReportTests(unittest.TestCase):
537
537
  "prompt_tokens": 50,
538
538
  "completion_tokens": 10,
539
539
  "total_tokens": 60,
540
+ "cache_read_tokens": 40,
540
541
  },
541
542
  },
542
543
  )
@@ -553,6 +554,7 @@ class TokenUsageReportTests(unittest.TestCase):
553
554
  "prompt_tokens": 1000,
554
555
  "completion_tokens": 200,
555
556
  "total_tokens": 1200,
557
+ "cache_read_tokens": 800,
556
558
  },
557
559
  }
558
560
  ],
@@ -575,6 +577,101 @@ class TokenUsageReportTests(unittest.TestCase):
575
577
  # Judge section shows its own call's consumption.
576
578
  self.assertIn("60 tokens (50 in / 10 out)", html)
577
579
 
580
+ def test_run_summary_shows_aggregate_cache_read_share(self) -> None:
581
+ case = _make_case("")
582
+ html = render_html_report([case], [self.make_result(case)])
583
+ self.assertIn(
584
+ "1,260 tokens (1,050 in / 210 out) · cache read 80.00%",
585
+ html,
586
+ )
587
+
588
+ def test_case_metadata_uses_weighted_cache_read_share_across_runs(self) -> None:
589
+ case = _make_case("")
590
+ result = self.make_result(case)
591
+ result.runs.append(
592
+ RunResult(
593
+ run_index=2,
594
+ passed=True,
595
+ requests=[
596
+ {
597
+ "step_id": "greet",
598
+ "request_index": 0,
599
+ "usage": {
600
+ "prompt_tokens": 150,
601
+ "completion_tokens": 10,
602
+ "total_tokens": 160,
603
+ "cache_read_tokens": 30,
604
+ },
605
+ }
606
+ ],
607
+ )
608
+ )
609
+
610
+ html = render_html_report([case], [result])
611
+
612
+ # Weighted case share: (840 + 30) / (1,050 + 150), not (80% + 20%) / 2.
613
+ self.assertIn(
614
+ "<div><span>Cache read</span><strong>72.50%</strong></div>",
615
+ html,
616
+ )
617
+
618
+ def test_run_comparison_separates_total_input_output_and_cache_read(self) -> None:
619
+ case = _make_case("")
620
+ result = self.make_result(case)
621
+ result.runs.append(replace(result.runs[0], run_index=2))
622
+
623
+ html = render_html_report([case], [result])
624
+
625
+ self.assertIn(
626
+ "<th>Total tokens</th><th>Input tokens</th>"
627
+ "<th>Output tokens</th><th>Cache read</th>",
628
+ html,
629
+ )
630
+ self.assertIn(
631
+ "<td>1,260</td><td>1,050</td><td>210</td><td>80.00%</td>",
632
+ html,
633
+ )
634
+
635
+ def test_run_cache_read_share_preserves_zero(self) -> None:
636
+ case = _make_case("")
637
+ result = self.make_result(case)
638
+ result.runs[0].requests[0]["usage"]["cache_read_tokens"] = 0
639
+ result.runs[0].steps[0].judge_result["usage"]["cache_read_tokens"] = 0
640
+
641
+ html = render_html_report([case], [result])
642
+
643
+ self.assertIn("cache read 0.00%", html)
644
+
645
+ def test_run_cache_read_share_is_unavailable_when_not_reported(self) -> None:
646
+ case = _make_case("")
647
+ result = self.make_result(case)
648
+ result.runs[0].requests[0]["usage"].pop("cache_read_tokens")
649
+ result.runs[0].steps[0].judge_result["usage"].pop("cache_read_tokens")
650
+ result.runs.append(replace(result.runs[0], run_index=2))
651
+
652
+ html = render_html_report([case], [result])
653
+
654
+ self.assertNotIn("cache read ", html)
655
+ self.assertIn(
656
+ "<td>1,260</td><td>1,050</td><td>210</td><td>–</td>",
657
+ html,
658
+ )
659
+
660
+ def test_run_cache_read_share_rejects_values_above_input(self) -> None:
661
+ case = _make_case("")
662
+ result = self.make_result(case)
663
+ result.runs[0].requests[0]["usage"]["cache_read_tokens"] = 1001
664
+ result.runs[0].steps[0].judge_result["usage"]["cache_read_tokens"] = 50
665
+ result.runs.append(replace(result.runs[0], run_index=2))
666
+
667
+ html = render_html_report([case], [result])
668
+
669
+ self.assertNotIn("cache read ", html)
670
+ self.assertIn(
671
+ "<td>1,260</td><td>1,050</td><td>210</td><td>–</td>",
672
+ html,
673
+ )
674
+
578
675
  def test_step_summaries_carry_a_step_number_prefix_and_id_chip(self) -> None:
579
676
  case = _make_case("")
580
677
  html = render_html_report([case], [self.make_result(case)])
@@ -607,6 +704,7 @@ class TokenUsageReportTests(unittest.TestCase):
607
704
  )
608
705
  html = render_html_report([case], [result])
609
706
  self.assertIn("<div><span>LLM tokens</span><strong>–</strong></div>", html)
707
+ self.assertIn("<div><span>Cache read</span><strong>–</strong></div>", html)
610
708
  self.assertIn('<div class="summary-card"><span>LLM TOKENS</span><strong>–</strong></div>', html)
611
709
 
612
710
 
@@ -29,7 +29,7 @@ class NormalizedUsageTests(unittest.TestCase):
29
29
  self.assertIsNone(_normalized_usage({"prompt_tokens_details": {"cached": 3}}))
30
30
  self.assertIsNone(_normalized_usage({"prompt_tokens": "12"}))
31
31
 
32
- def test_keeps_only_the_three_counters_as_ints(self) -> None:
32
+ def test_keeps_nested_cache_read_without_changing_core_counters(self) -> None:
33
33
  usage = _normalized_usage(
34
34
  {
35
35
  "prompt_tokens": 10,
@@ -40,16 +40,79 @@ class NormalizedUsageTests(unittest.TestCase):
40
40
  )
41
41
  self.assertEqual(
42
42
  usage,
43
- {"prompt_tokens": 10, "completion_tokens": 2, "total_tokens": 12},
43
+ {
44
+ "prompt_tokens": 10,
45
+ "completion_tokens": 2,
46
+ "total_tokens": 12,
47
+ "cache_read_tokens": 4,
48
+ },
44
49
  )
45
50
 
46
- def test_reads_attribute_style_payloads(self) -> None:
51
+ def test_cache_read_aliases_are_supported(self) -> None:
52
+ for field in (
53
+ "cache_read_input_tokens",
54
+ "cached_content_token_count",
55
+ "cache_tokens",
56
+ "prompt_cache_hit_tokens",
57
+ ):
58
+ with self.subTest(field=field):
59
+ usage = _normalized_usage(
60
+ {
61
+ "prompt_tokens": 10,
62
+ "completion_tokens": 2,
63
+ field: 4,
64
+ }
65
+ )
66
+ self.assertEqual(usage["cache_read_tokens"], 4)
67
+
68
+ def test_first_valid_cache_read_alias_wins_and_zero_is_preserved(self) -> None:
47
69
  usage = _normalized_usage(
48
- SimpleNamespace(prompt_tokens=7, completion_tokens=3, total_tokens=10)
70
+ {
71
+ "prompt_tokens": 10,
72
+ "completion_tokens": 2,
73
+ "prompt_tokens_details": {"cached_tokens": 0},
74
+ "cache_read_input_tokens": 7,
75
+ "cache_tokens": 9,
76
+ }
77
+ )
78
+ self.assertEqual(usage["cache_read_tokens"], 0)
79
+
80
+ def test_invalid_cache_read_aliases_are_skipped(self) -> None:
81
+ usage = _normalized_usage(
82
+ {
83
+ "prompt_tokens": 10,
84
+ "completion_tokens": 2,
85
+ "prompt_tokens_details": {"cached_tokens": -1},
86
+ "cache_read_input_tokens": True,
87
+ "cached_content_token_count": "8",
88
+ "cache_tokens": 3.0,
89
+ }
90
+ )
91
+ self.assertEqual(usage["cache_read_tokens"], 3)
92
+
93
+ def test_missing_cache_read_remains_absent(self) -> None:
94
+ usage = _normalized_usage(
95
+ {"prompt_tokens": 10, "completion_tokens": 2}
96
+ )
97
+ self.assertNotIn("cache_read_tokens", usage)
98
+
99
+ def test_reads_attribute_style_payloads_and_nested_cache_details(self) -> None:
100
+ usage = _normalized_usage(
101
+ SimpleNamespace(
102
+ prompt_tokens=7,
103
+ completion_tokens=3,
104
+ total_tokens=10,
105
+ prompt_tokens_details=SimpleNamespace(cached_tokens=2),
106
+ )
49
107
  )
50
108
  self.assertEqual(
51
109
  usage,
52
- {"prompt_tokens": 7, "completion_tokens": 3, "total_tokens": 10},
110
+ {
111
+ "prompt_tokens": 7,
112
+ "completion_tokens": 3,
113
+ "total_tokens": 10,
114
+ "cache_read_tokens": 2,
115
+ },
53
116
  )
54
117
 
55
118
  def test_missing_total_is_summed_from_the_parts(self) -> None:
@@ -82,6 +145,63 @@ class CombineUsageTests(unittest.TestCase):
82
145
  {"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 5},
83
146
  )
84
147
 
148
+ def test_sums_only_reported_valid_cache_read_tokens(self) -> None:
149
+ combined = combine_usage(
150
+ [
151
+ {
152
+ "prompt_tokens": 10,
153
+ "completion_tokens": 2,
154
+ "total_tokens": 12,
155
+ "cache_read_tokens": 4,
156
+ },
157
+ {
158
+ "prompt_tokens": 5,
159
+ "completion_tokens": 1,
160
+ "total_tokens": 6,
161
+ },
162
+ {
163
+ "prompt_tokens": 3,
164
+ "completion_tokens": 1,
165
+ "total_tokens": 4,
166
+ "cache_read_tokens": -2,
167
+ },
168
+ {
169
+ "prompt_tokens": 2,
170
+ "completion_tokens": 1,
171
+ "total_tokens": 3,
172
+ "cache_read_tokens": True,
173
+ },
174
+ ]
175
+ )
176
+ self.assertEqual(
177
+ combined,
178
+ {
179
+ "prompt_tokens": 20,
180
+ "completion_tokens": 5,
181
+ "total_tokens": 25,
182
+ "cache_read_tokens": 4,
183
+ },
184
+ )
185
+
186
+ def test_cache_read_stays_absent_when_no_call_reports_it(self) -> None:
187
+ combined = combine_usage(
188
+ [{"prompt_tokens": 5, "completion_tokens": 1, "total_tokens": 6}]
189
+ )
190
+ self.assertNotIn("cache_read_tokens", combined)
191
+
192
+ def test_reported_zero_cache_read_is_preserved(self) -> None:
193
+ combined = combine_usage(
194
+ [
195
+ {
196
+ "prompt_tokens": 5,
197
+ "completion_tokens": 1,
198
+ "total_tokens": 6,
199
+ "cache_read_tokens": 0,
200
+ }
201
+ ]
202
+ )
203
+ self.assertEqual(combined["cache_read_tokens"], 0)
204
+
85
205
 
86
206
  class ResultUsageAggregationTests(unittest.TestCase):
87
207
  """Run usage sums the tool-loop requests plus judge calls; case usage
@@ -97,6 +217,7 @@ class ResultUsageAggregationTests(unittest.TestCase):
97
217
  "prompt_tokens": 50,
98
218
  "completion_tokens": 10,
99
219
  "total_tokens": 60,
220
+ "cache_read_tokens": 40,
100
221
  }
101
222
  )
102
223
  ],
@@ -108,6 +229,7 @@ class ResultUsageAggregationTests(unittest.TestCase):
108
229
  "prompt_tokens": 1000,
109
230
  "completion_tokens": 200,
110
231
  "total_tokens": 1200,
232
+ "cache_read_tokens": 800,
111
233
  },
112
234
  },
113
235
  {"step_id": "greet", "request_index": 1},
@@ -120,6 +242,7 @@ class ResultUsageAggregationTests(unittest.TestCase):
120
242
  "prompt_tokens": 1050,
121
243
  "completion_tokens": 210,
122
244
  "total_tokens": 1260,
245
+ "cache_read_tokens": 840,
123
246
  }
124
247
  self.assertEqual(run.usage(), expected)
125
248
  self.assertEqual(run.to_dict()["usage"], expected)
@@ -140,6 +263,7 @@ class ResultUsageAggregationTests(unittest.TestCase):
140
263
  "prompt_tokens": 2100,
141
264
  "completion_tokens": 420,
142
265
  "total_tokens": 2520,
266
+ "cache_read_tokens": 1680,
143
267
  }
144
268
  self.assertEqual(result.usage(), expected)
145
269
  self.assertEqual(result.to_dict()["usage"], expected)
@@ -171,7 +295,12 @@ class ClientUsageCaptureTests(unittest.IsolatedAsyncioTestCase):
171
295
  )
172
296
  self.assertEqual(
173
297
  response.usage,
174
- {"prompt_tokens": 11, "completion_tokens": 4, "total_tokens": 15},
298
+ {
299
+ "prompt_tokens": 11,
300
+ "completion_tokens": 4,
301
+ "total_tokens": 15,
302
+ "cache_read_tokens": 2,
303
+ },
175
304
  )
176
305
 
177
306
  async def test_litellm_response_without_usage_yields_none(self) -> None:
@@ -1312,8 +1312,7 @@ def _thread_case_parser() -> argparse.ArgumentParser:
1312
1312
  default="dev",
1313
1313
  help=(
1314
1314
  "Target environment: dev, staging, or prod (default: dev)."
1315
- " Selects the admin API base URL and, when --commit-id is set,"
1316
- " the DSL SSH host and remote base dir"
1315
+ " Selects the admin API base URL, DSL SSH host, and remote base dir"
1317
1316
  ),
1318
1317
  )
1319
1318
  parser.add_argument(
@@ -1336,8 +1335,8 @@ def _thread_case_parser() -> argparse.ArgumentParser:
1336
1335
  "--commit-id",
1337
1336
  default=None,
1338
1337
  help=(
1339
- "Git commit to read dsl.json from via SSH (git show <commit>:dsl.json);"
1340
- " omit to skip fetching dsl entirely"
1338
+ "Git ref to read dsl.json from via SSH (git show <ref>:dsl.json);"
1339
+ " omit to try HEAD and continue without DSL if that lookup fails"
1341
1340
  ),
1342
1341
  )
1343
1342
  return parser
@@ -1362,13 +1361,25 @@ def _run_thread_case(args: argparse.Namespace) -> int:
1362
1361
  Text(f"response: {build_response_preview(record.get('response'))}", style="dim")
1363
1362
  )
1364
1363
  dsl: dict[str, Any] | None = None
1365
- if args.commit_id is not None:
1366
- ssh_host = resolve_dsl_ssh_host(args.env)
1367
- remote_base_dir = resolve_dsl_remote_base_dir(args.env)
1368
- dsl = fetch_dsl_at_commit(thread_id, args.commit_id, ssh_host, remote_base_dir)
1364
+ commit_id = args.commit_id if args.commit_id is not None else "HEAD"
1365
+ ssh_host = resolve_dsl_ssh_host(args.env)
1366
+ remote_base_dir = resolve_dsl_remote_base_dir(args.env)
1367
+ try:
1368
+ dsl = fetch_dsl_at_commit(thread_id, commit_id, ssh_host, remote_base_dir)
1369
+ except ThreadCaseError as exc:
1370
+ if args.commit_id is not None:
1371
+ raise
1372
+ stderr.print(
1373
+ Text(
1374
+ "dsl: warning: failed to fetch DSL at HEAD;"
1375
+ f" continuing without DSL: {exc}",
1376
+ style="yellow",
1377
+ )
1378
+ )
1379
+ else:
1369
1380
  stderr.print(
1370
1381
  Text(
1371
- f"dsl: fetched {len(dsl)} top-level key(s) at commit {args.commit_id}",
1382
+ f"dsl: fetched {len(dsl)} top-level key(s) at commit {commit_id}",
1372
1383
  style="dim",
1373
1384
  )
1374
1385
  )
@@ -239,13 +239,32 @@ def _value(item: Any, key: str, default: Any = None) -> Any:
239
239
  return getattr(item, key, default)
240
240
 
241
241
 
242
+ def _cache_read_tokens(value: Any) -> int | None:
243
+ prompt_details = _value(value, "prompt_tokens_details")
244
+ candidates = [
245
+ _value(prompt_details, "cached_tokens"),
246
+ _value(value, "cache_read_input_tokens"),
247
+ _value(value, "cached_content_token_count"),
248
+ _value(value, "cache_tokens"),
249
+ _value(value, "prompt_cache_hit_tokens"),
250
+ ]
251
+ for candidate in candidates:
252
+ if (
253
+ isinstance(candidate, (int, float))
254
+ and not isinstance(candidate, bool)
255
+ and candidate >= 0
256
+ ):
257
+ return int(candidate)
258
+ return None
259
+
260
+
242
261
  def _normalized_usage(value: Any) -> dict[str, int] | None:
243
262
  """Reduce a provider usage payload to plain int token counters.
244
263
 
245
- Providers attach extra detail blocks (`prompt_tokens_details`, cache
246
- counters, ...) with shapes that vary per provider; only the three
247
- OpenAI-style counters are kept so downstream aggregation can sum
248
- them blindly. Returns None when the payload carries none of them.
264
+ The three OpenAI-style counters keep their existing semantics. A
265
+ provider-reported cache-read counter is retained under the optional
266
+ `cache_read_tokens` key; it is never added to prompt or total tokens.
267
+ Returns None when the payload carries none of the core counters.
249
268
  """
250
269
  if value is None:
251
270
  return None
@@ -260,6 +279,9 @@ def _normalized_usage(value: Any) -> dict[str, int] | None:
260
279
  "total_tokens",
261
280
  usage.get("prompt_tokens", 0) + usage.get("completion_tokens", 0),
262
281
  )
282
+ cache_read_tokens = _cache_read_tokens(value)
283
+ if cache_read_tokens is not None:
284
+ usage["cache_read_tokens"] = cache_read_tokens
263
285
  return usage
264
286
 
265
287
 
@@ -46,6 +46,24 @@ def _usage_inline(usage: Any) -> str:
46
46
  )
47
47
 
48
48
 
49
+ def _cache_read_percentage(usage: Any) -> str:
50
+ if not isinstance(usage, dict):
51
+ return ""
52
+ prompt_tokens = usage.get("prompt_tokens")
53
+ cache_read_tokens = usage.get("cache_read_tokens")
54
+ if (
55
+ isinstance(prompt_tokens, bool)
56
+ or not isinstance(prompt_tokens, (int, float))
57
+ or prompt_tokens <= 0
58
+ or isinstance(cache_read_tokens, bool)
59
+ or not isinstance(cache_read_tokens, (int, float))
60
+ or cache_read_tokens < 0
61
+ or cache_read_tokens > prompt_tokens
62
+ ):
63
+ return ""
64
+ return f"{cache_read_tokens / prompt_tokens:.2%}"
65
+
66
+
49
67
  def _duration_inline(duration_ms: Any) -> str:
50
68
  if isinstance(duration_ms, bool) or not isinstance(duration_ms, (int, float)):
51
69
  return ""
@@ -884,19 +902,35 @@ def _run_detail_cells(run: RunResult) -> str:
884
902
  overall = _run_judge_overall(run)
885
903
  judge_cell = f"{overall:.0%}" if overall is not None else "–"
886
904
  usage = run.usage()
887
- tokens_cell = f"{usage['total_tokens']:,}" if usage else "–"
888
905
  error_note = ' <span class="muted">(run error)</span>' if run.error else ""
889
906
  return (
890
907
  f"<td>{steps_passed}/{len(run.steps)}{error_note}</td>"
891
908
  f"<td>{checks_passed}/{len(checks)}</td>"
892
909
  f"<td>{_text(judge_cell)}</td>"
893
- f"<td>{_text(tokens_cell)}</td>"
910
+ f"{_usage_detail_cells(usage)}"
911
+ )
912
+
913
+
914
+ def _usage_detail_cells(usage: dict[str, int] | None) -> str:
915
+ if usage:
916
+ total_cell = f"{usage.get('total_tokens', 0):,}"
917
+ input_cell = f"{usage.get('prompt_tokens', 0):,}"
918
+ output_cell = f"{usage.get('completion_tokens', 0):,}"
919
+ cache_read_cell = _cache_read_percentage(usage) or "–"
920
+ else:
921
+ total_cell = input_cell = output_cell = cache_read_cell = "–"
922
+ return (
923
+ f"<td>{_text(total_cell)}</td>"
924
+ f"<td>{_text(input_cell)}</td>"
925
+ f"<td>{_text(output_cell)}</td>"
926
+ f"<td>{_text(cache_read_cell)}</td>"
894
927
  )
895
928
 
896
929
 
897
930
  _RUN_DETAIL_HEADERS = (
898
931
  "<th>Steps passed</th><th>Hard checks</th><th>Judge overall</th>"
899
- "<th>Tokens</th>"
932
+ "<th>Total tokens</th><th>Input tokens</th>"
933
+ "<th>Output tokens</th><th>Cache read</th>"
900
934
  )
901
935
 
902
936
 
@@ -950,7 +984,6 @@ def _render_variant_comparison(groups: dict[str, list[RunResult]]) -> str:
950
984
  ]
951
985
  judge_cell = f"{sum(overalls) / len(overalls):.0%}" if overalls else "–"
952
986
  usage = combine_usage(run.usage() for run in runs)
953
- tokens_cell = f"{usage['total_tokens']:,}" if usage else "–"
954
987
  error_note = f' <span class="muted">(+{errors} error)</span>' if errors else ""
955
988
  pass_rate_cell = f"{passed / len(evaluated):.0%}" if evaluated else "–"
956
989
  rows.append(
@@ -960,14 +993,15 @@ def _render_variant_comparison(groups: dict[str, list[RunResult]]) -> str:
960
993
  f"<td>{passed}/{len(evaluated)}{error_note}</td>"
961
994
  f"<td>{_text(pass_rate_cell)}</td>"
962
995
  f"<td>{_text(judge_cell)}</td>"
963
- f"<td>{_text(tokens_cell)}</td>"
996
+ f"{_usage_detail_cells(usage)}"
964
997
  "</tr>"
965
998
  )
966
999
  return (
967
1000
  '<div class="table-wrap"><table class="variant-compare">'
968
1001
  "<thead><tr><th>Status</th><th>Variant</th>"
969
1002
  "<th>Runs passed</th><th>Pass rate</th><th>Judge overall</th>"
970
- "<th>Tokens</th></tr></thead>"
1003
+ "<th>Total tokens</th><th>Input tokens</th>"
1004
+ "<th>Output tokens</th><th>Cache read</th></tr></thead>"
971
1005
  f'<tbody>{"".join(rows)}</tbody></table></div>'
972
1006
  )
973
1007
 
@@ -1089,6 +1123,9 @@ def _render_run(run: RunResult) -> str:
1089
1123
  meta_parts.append(f"LLM request time {_duration_inline(run_duration)}")
1090
1124
  if run_usage:
1091
1125
  meta_parts.append(_usage_inline(run_usage))
1126
+ cache_read_percentage = _cache_read_percentage(run_usage)
1127
+ if cache_read_percentage:
1128
+ meta_parts.append(f"cache read {cache_read_percentage}")
1092
1129
  if run.artifact_dir:
1093
1130
  meta_parts.append(f"Artifacts: {run.artifact_dir}")
1094
1131
  meta = (
@@ -1355,6 +1392,7 @@ def _render_case(
1355
1392
  if case_usage
1356
1393
  else "–"
1357
1394
  )
1395
+ cache_read_cell = _cache_read_percentage(case_usage) or "–"
1358
1396
  case_duration = result.request_duration_ms()
1359
1397
  duration_cell = _duration_inline(case_duration) if case_duration is not None else "–"
1360
1398
  # The description is the human-meaningful headline; the case_key only
@@ -1379,6 +1417,7 @@ def _render_case(
1379
1417
  f'<div><span>Tools</span><strong>{_text(tools)}</strong></div>'
1380
1418
  f'<div><span>Skills</span><strong>{_text(skills)}</strong></div>'
1381
1419
  f'<div><span>LLM tokens</span><strong>{_text(usage_cell)}</strong></div>'
1420
+ f'<div><span>Cache read</span><strong>{_text(cache_read_cell)}</strong></div>'
1382
1421
  f'<div><span>LLM request time</span><strong>{_text(duration_cell)}</strong></div>'
1383
1422
  f'<div><span>Updated at (Beijing time)</span><strong>{_text(updated_at_beijing or "-")}</strong></div>'
1384
1423
  "</div>"
@@ -126,9 +126,13 @@ def combine_usage(items: Iterable[Any]) -> dict[str, int] | None:
126
126
  Non-dict items (None from runs whose provider reported no usage) are
127
127
  skipped, and the sum is None when nothing carried usage at all --
128
128
  "no data" must stay distinguishable from "0 tokens" so scripted or
129
- errored runs don't render as a misleading all-zero consumption.
129
+ errored runs don't render as a misleading all-zero consumption. The
130
+ optional cache-read counter is summed only when providers reported it;
131
+ its absence stays distinguishable from a reported zero.
130
132
  """
131
133
  total: dict[str, int] | None = None
134
+ cache_read_total = 0
135
+ cache_read_seen = False
132
136
  for item in items:
133
137
  if not isinstance(item, dict):
134
138
  continue
@@ -138,6 +142,16 @@ def combine_usage(items: Iterable[Any]) -> dict[str, int] | None:
138
142
  value = item.get(key)
139
143
  if isinstance(value, (int, float)) and not isinstance(value, bool):
140
144
  total[key] += int(value)
145
+ cache_read = item.get("cache_read_tokens")
146
+ if (
147
+ isinstance(cache_read, (int, float))
148
+ and not isinstance(cache_read, bool)
149
+ and cache_read >= 0
150
+ ):
151
+ cache_read_seen = True
152
+ cache_read_total += int(cache_read)
153
+ if total is not None and cache_read_seen:
154
+ total["cache_read_tokens"] = cache_read_total
141
155
  return total
142
156
 
143
157
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes