python-yama 0.5.0__tar.gz → 0.7.0__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 (60) hide show
  1. {python_yama-0.5.0 → python_yama-0.7.0}/PKG-INFO +3 -4
  2. {python_yama-0.5.0 → python_yama-0.7.0}/README.md +2 -3
  3. {python_yama-0.5.0 → python_yama-0.7.0}/README.zh-CN.md +2 -3
  4. {python_yama-0.5.0 → python_yama-0.7.0}/docs/agent-skill-test-framework-design.md +160 -47
  5. python_yama-0.7.0/docs/case-schema-reference.md +986 -0
  6. python_yama-0.7.0/skills/eval-plugin-with-yama/SKILL.md +289 -0
  7. {python_yama-0.5.0 → python_yama-0.7.0}/skills/eval-plugin-with-yama/references/case-schema.md +56 -10
  8. {python_yama-0.5.0 → python_yama-0.7.0}/skills/eval-plugin-with-yama/references/debugging.md +60 -18
  9. python_yama-0.7.0/skills/eval-plugin-with-yama/references/install-upgrade.md +84 -0
  10. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_assertions.py +68 -0
  11. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_cli.py +354 -0
  12. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_framework.py +1 -1
  13. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_preview.py +1 -1
  14. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_report.py +335 -2
  15. python_yama-0.7.0/tests/test_runner.py +618 -0
  16. python_yama-0.7.0/tests/test_thread_case.py +807 -0
  17. {python_yama-0.5.0 → python_yama-0.7.0}/yama/assertions.py +32 -3
  18. {python_yama-0.5.0 → python_yama-0.7.0}/yama/cli.py +236 -21
  19. {python_yama-0.5.0 → python_yama-0.7.0}/yama/models.py +2 -0
  20. {python_yama-0.5.0 → python_yama-0.7.0}/yama/report.py +234 -35
  21. {python_yama-0.5.0 → python_yama-0.7.0}/yama/runner.py +265 -14
  22. python_yama-0.7.0/yama/thread_case.py +403 -0
  23. python_yama-0.5.0/skills/eval-plugin-with-yama/SKILL.md +0 -206
  24. {python_yama-0.5.0 → python_yama-0.7.0}/.github/workflows/publish.yml +0 -0
  25. {python_yama-0.5.0 → python_yama-0.7.0}/.gitignore +0 -0
  26. {python_yama-0.5.0 → python_yama-0.7.0}/CLAUDE.md +0 -0
  27. {python_yama-0.5.0 → python_yama-0.7.0}/LICENSE +0 -0
  28. {python_yama-0.5.0 → python_yama-0.7.0}/docs/yama-intro.html +0 -0
  29. {python_yama-0.5.0 → python_yama-0.7.0}/pyproject.toml +0 -0
  30. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_cli_shim.py +0 -0
  31. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_dashboard.py +0 -0
  32. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_llm.py +0 -0
  33. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_main_entrypoint.py +0 -0
  34. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_mocks.py +0 -0
  35. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_public_api.py +0 -0
  36. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_run_plan.py +0 -0
  37. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_skill_tool.py +0 -0
  38. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_tool_loader.py +0 -0
  39. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_usage.py +0 -0
  40. {python_yama-0.5.0 → python_yama-0.7.0}/tests/test_workspace.py +0 -0
  41. {python_yama-0.5.0 → python_yama-0.7.0}/uv.lock +0 -0
  42. {python_yama-0.5.0 → python_yama-0.7.0}/yama/__init__.py +0 -0
  43. {python_yama-0.5.0 → python_yama-0.7.0}/yama/__main__.py +0 -0
  44. {python_yama-0.5.0 → python_yama-0.7.0}/yama/dashboard.py +0 -0
  45. {python_yama-0.5.0 → python_yama-0.7.0}/yama/llm.py +0 -0
  46. {python_yama-0.5.0 → python_yama-0.7.0}/yama/loaders/__init__.py +0 -0
  47. {python_yama-0.5.0 → python_yama-0.7.0}/yama/loaders/case.py +0 -0
  48. {python_yama-0.5.0 → python_yama-0.7.0}/yama/loaders/common.py +0 -0
  49. {python_yama-0.5.0 → python_yama-0.7.0}/yama/loaders/tool_loader.py +0 -0
  50. {python_yama-0.5.0 → python_yama-0.7.0}/yama/mocks.py +0 -0
  51. {python_yama-0.5.0 → python_yama-0.7.0}/yama/preview.py +0 -0
  52. {python_yama-0.5.0 → python_yama-0.7.0}/yama/tools/__init__.py +0 -0
  53. {python_yama-0.5.0 → python_yama-0.7.0}/yama/tools/base.py +0 -0
  54. {python_yama-0.5.0 → python_yama-0.7.0}/yama/tools/bash/__init__.py +0 -0
  55. {python_yama-0.5.0 → python_yama-0.7.0}/yama/tools/bash/_cli_shim.py +0 -0
  56. {python_yama-0.5.0 → python_yama-0.7.0}/yama/tools/bash/bash.py +0 -0
  57. {python_yama-0.5.0 → python_yama-0.7.0}/yama/tools/bash/fs.py +0 -0
  58. {python_yama-0.5.0 → python_yama-0.7.0}/yama/tools/skill/__init__.py +0 -0
  59. {python_yama-0.5.0 → python_yama-0.7.0}/yama/tools/skill/skill.py +0 -0
  60. {python_yama-0.5.0 → python_yama-0.7.0}/yama/workspace.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-yama
3
- Version: 0.5.0
3
+ Version: 0.7.0
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
@@ -72,15 +72,14 @@ steps:
72
72
  - assistant_contains: creative direction
73
73
 
74
74
  outcome:
75
- require:
76
- hard_checks: all_pass
75
+ require: {}
77
76
  ```
78
77
 
79
78
  - `description` (optional) is a one-line summary of what the Case tests; it is shown in the CLI output and the HTML report.
80
79
  - `context.tools` is the tool schema sent to the model; `mocks.tools` is how the runner responds when a tool call arrives. The two sets of tool names must match exactly.
81
80
  - To use a Skill, declare it by name under `context.skills` and also declare `{builtin: skill}` under `context.tools`; the model reads the Skill body via `skill(name, file?, call_reason?)`.
82
81
  - To simulate command-line tools, declare `{builtin: bash}` and configure per-command output under `mocks.cli`.
83
- - `steps[].assert.hard` are deterministic checks (nine types, including `tool_called`, `tool_arguments`, and `assistant_contains`); add `assert.judge` for LLM scoring.
82
+ - `steps[].assert.hard` are deterministic checks (nine types, including `tool_called`, `tool_arguments`, and `assistant_contains`); untagged hard checks must all pass by default. Add `assert.judge` for LLM scoring.
84
83
 
85
84
  For the full schema (every Skill/tool/mock form, the `bash` sandbox, message injection, judge configuration, and more), see the [design doc](https://github.com/world-sim-dev/yama/blob/main/docs/agent-skill-test-framework-design.md) (Chinese).
86
85
 
@@ -46,15 +46,14 @@ steps:
46
46
  - assistant_contains: creative direction
47
47
 
48
48
  outcome:
49
- require:
50
- hard_checks: all_pass
49
+ require: {}
51
50
  ```
52
51
 
53
52
  - `description` (optional) is a one-line summary of what the Case tests; it is shown in the CLI output and the HTML report.
54
53
  - `context.tools` is the tool schema sent to the model; `mocks.tools` is how the runner responds when a tool call arrives. The two sets of tool names must match exactly.
55
54
  - To use a Skill, declare it by name under `context.skills` and also declare `{builtin: skill}` under `context.tools`; the model reads the Skill body via `skill(name, file?, call_reason?)`.
56
55
  - To simulate command-line tools, declare `{builtin: bash}` and configure per-command output under `mocks.cli`.
57
- - `steps[].assert.hard` are deterministic checks (nine types, including `tool_called`, `tool_arguments`, and `assistant_contains`); add `assert.judge` for LLM scoring.
56
+ - `steps[].assert.hard` are deterministic checks (nine types, including `tool_called`, `tool_arguments`, and `assistant_contains`); untagged hard checks must all pass by default. Add `assert.judge` for LLM scoring.
58
57
 
59
58
  For the full schema (every Skill/tool/mock form, the `bash` sandbox, message injection, judge configuration, and more), see the [design doc](https://github.com/world-sim-dev/yama/blob/main/docs/agent-skill-test-framework-design.md) (Chinese).
60
59
 
@@ -46,15 +46,14 @@ steps:
46
46
  - assistant_contains: 创意方向
47
47
 
48
48
  outcome:
49
- require:
50
- hard_checks: all_pass
49
+ require: {}
51
50
  ```
52
51
 
53
52
  - `description`(可选)是一句话说明当前 Case 测试什么;会展示在 CLI 输出和 HTML 报告中。
54
53
  - `context.tools` 是发给模型的 Tool Schema,`mocks.tools` 是 Runner 收到 Tool Call 后如何返回结果;两者的 Tool 名字集合必须完全一致。
55
54
  - 需要 Skill 时在 `context.skills` 中按名字声明,并在 `context.tools` 中同时声明 `{builtin: skill}`;模型通过 `skill(name, file?, call_reason?)` 读取正文。
56
55
  - 需要模拟命令行工具时声明 `{builtin: bash}`,在 `mocks.cli` 中按命令配置输出。
57
- - `steps[].assert.hard` 是确定性检查(`tool_called`、`tool_arguments`、`assistant_contains` 等九种类型);还可以加 `assert.judge` 做 LLM 打分。
56
+ - `steps[].assert.hard` 是确定性检查(`tool_called`、`tool_arguments`、`assistant_contains` 等九种类型);未打 tag 的 hard check 默认必须全部通过。还可以加 `assert.judge` 做 LLM 打分。
58
57
 
59
58
  完整 Schema(Skill/Tool/Mock 的全部写法、`bash` 沙箱、Message Injection、Judge 配置等)见[设计文档](docs/agent-skill-test-framework-design.md)。
60
59
 
@@ -1155,11 +1155,12 @@ Provider 凭据由 LiteLLM 从其标准环境变量或运行环境读取,不
1155
1155
  }
1156
1156
  },
1157
1157
  "resolved_provider": { "name": "openrouter", "model": "openrouter/anthropic/claude-sonnet-4.6" },
1158
- "response": { "role": "assistant", "content": "..." }
1158
+ "response": { "role": "assistant", "content": "..." },
1159
+ "duration_ms": 842.317
1159
1160
  }
1160
1161
  ```
1161
1162
 
1162
- `resolved_provider` 是原设计未提及的额外字段(来自 `LLMClient.last_provider`);请求失败时该记录会多一个 `"error": "<ExceptionType>: <message>"` 字段,而不是 `response`。报告中的 `LLM Request` 只渲染 `invocation.method` 和 `invocation.arguments`;`step_id`、`request_index`、`resolved_provider`、响应和错误均不伪装成模型调用参数。
1163
+ `resolved_provider` 是原设计未提及的额外字段(来自 `LLMClient.last_provider`);请求失败时该记录会多一个 `"error": "<ExceptionType>: <message>"` 字段,而不是 `response`。`duration_ms` 由 `runner.py:_run_step` 用 `time.perf_counter()` 环绕 `self.llm.complete` 调用测得(四舍五入到 3 位小数),记录这一轮从发起调用到拿到返回(或抛出异常)的耗时,成功、失败都会写入。执行时间线里每次 assistant 响应的摘要行、以及 run 底部 `LLM requests (N)` 里每条 Request 的摘要行,都会展示这个耗时(`N ms`,`report.py:_duration_inline`)。每个 `LLM request` 折叠卡统一渲染 `invocation.method`、单轮 `duration_ms`、`invocation.arguments` 和 `response`;成功时 `response` 是这一轮模型返回的完整 assistant message(含 `tool_calls`),请求失败时该记录改由 `error` 字段说明失败。Run/Case/报告顶部会把全部 tool-loop 请求的 `duration_ms` 相加,作为 LLM Request 总耗时展示;`step_id`、`request_index`、`resolved_provider` 均不伪装成模型调用参数。
1163
1164
 
1164
1165
  Judge 使用的模型写在 `steps[].assert.judge.model` 或全局 Judge 配置中(省略时回退到当前 Case 的 `model`,见 12.2 节)。
1165
1166
 
@@ -1594,8 +1595,11 @@ execution:
1594
1595
  - `timeout_seconds_per_step`:单个 Step 的总时限,默认 **120**。通过
1595
1596
  `asyncio.wait_for` 真实生效(`runner.py:_run_once`),但需要注意:超时触发的是
1596
1597
  `asyncio.TimeoutError`,**没有**被单独捕获转换成"仅本 Step 失败、run 继续"——它
1597
- 会被 `_run_once` 外层的 `except Exception` 当成整条 run 异常失败处理(`RunResult.passed
1598
- = False`,`RunResult.error` 记录异常信息),run 直接终止,不会再跑后续 Step。
1598
+ 会被 `_run_once` 外层的 `except Exception` 当成整条 run 的基础设施异常处理
1599
+ (`RunResult.status = "error"`,`RunResult.passed = False`,`RunResult.error`
1600
+ 记录异常信息),run 直接终止,不会再跑后续 Step。`LLMError`(Provider
1601
+ 请求失败、接口异常、脚本回放耗尽等)同样归为 run/case 的 `error` 状态,而不是
1602
+ hard check/Judge 失败。
1599
1603
  这与下面 `max_tool_rounds_per_step` 超限的处理方式(仅本 Step 记为失败、run 继续
1600
1604
  跑完剩余 Step)不同。
1601
1605
  - `max_tool_rounds_per_step`:一个 Step 内允许的最大 Tool Call 循环轮数,默认 **10**。
@@ -1612,9 +1616,11 @@ execution:
1612
1616
  原样继承,跨供应商切换时如需避免继承需在条目里显式覆盖。
1613
1617
  - `label` 缺省取合并后的模型名;label 是报告/CLI 的分组维度,条目之间必须
1614
1618
  唯一(两个条目共用同一模型名时必须显式给 `label`),否则报错。
1615
- - 总 run 数 = Σ times,`run_index` 跨条目连续递增;`passed`/`pass_rate`
1616
- 语义不变(所有 run 都通过 Case 才算过)。每个 `RunResult` 记录本 run 的
1617
- `label` 与生效 `model`(进 `result.json` 与 `--json` 输出)。
1619
+ - 总 run 数 = Σ times,`run_index` 跨条目连续递增。`status="error"` 的 run
1620
+ 不进入 pass/fail 分母;只要存在非 error 的失败 run,Case 为 `fail`;没有失败
1621
+ 但存在 error run 时,Case 为 `error`;只有所有非 error run 都通过且没有 error
1622
+ 时,Case 才为 `pass`。`pass_rate` 只按非 error run 计算。每个 `RunResult`
1623
+ 记录本 run 的 `label` 与生效 `model`(进 `result.json` 与 `--json` 输出)。
1618
1624
  - 变体模型只作用于被测 Agent 的 Tool Loop;**Judge 的 `default_model`
1619
1625
  固定为 Case 级 `model`**(`judge.model` 仍可显式覆盖),保证不同变体的
1620
1626
  评分口径一致、可对比。
@@ -1702,23 +1708,36 @@ assert:
1702
1708
 
1703
1709
  断言默认只作用于当前 Step;需要检查最终跨 Step 状态时,使用 Python Checker 或 `outcome` 中的 Case 级要求。`assistant_semantic_count` 的实际语义见 12.1 节——它并非真正的语义理解,而是大小写不敏感的字面子串计数,命名有历史包袱。
1704
1710
 
1711
+ `assert.hard` 每条断言还可以带一个可选的 `tag` 平级字段(断言类型 key 之外的
1712
+ 另一个 key,同一条断言最多一个 tag),用于在 8.8 节的
1713
+ `outcome.require.hard_checks.tags` 里按 tag 设置不同的通过率容忍度;不打 tag 的断言
1714
+ 默认归入 `must_pass`。tag 只属于 `assert.hard`,不属于 `assert.judge` 或 Judge 维度。
1715
+ 允许的 tag 固定为 `must_pass` / `high_confidence` / `tolerant` / `informational`
1716
+ 四种,写其它值会在运行时报 `AssertionConfigurationError`。
1717
+
1705
1718
  ### 8.8 `outcome`:整个 Case 的最终门槛
1706
1719
 
1707
1720
  ```yaml
1708
1721
  outcome:
1709
1722
  require:
1710
- hard_checks: all_pass
1723
+ hard_checks:
1724
+ tags:
1725
+ high_confidence: 0.9
1726
+ tolerant: 0.8
1727
+ informational: 0.0
1711
1728
  judge:
1712
1729
  overall_gte: 0.8
1713
1730
  each_dimension_gte: 0.6
1714
1731
  ```
1715
1732
 
1716
- "所有 Step 必须 `hard_pass`"这条门槛在 `runner.py:_case_passed` 中是**硬编码行为**
1717
- (`if not all(step.hard_pass for step in steps): return False`),代码里**没有**
1718
- 一个真正读取 `hard_checks: all_pass` 这个具体配置键的地方——写不写它、写成什么值都
1719
- 不影响实际判定,这条门槛始终生效且不可关闭。`judge.overall_gte`/
1720
- `judge.each_dimension_gte` 则是真实读取的配置键(见 12.3 节)。Judge 门槛只决定
1721
- 质量是否达标,不会把协议错误变成通过。
1733
+ 判定逻辑由 `runner.py` 里的共享函数 `tag_pass_summary(steps, outcome)` 计算:按每条
1734
+ hard check 的固定 tag 分组(未打 tag 的默认归入 `must_pass`),每组算
1735
+ `rate = passed / total`,阈值取 `outcome.require.hard_checks.tags` 里对应 tag 的
1736
+ 配置值或固定默认值(旧版 `outcome.require.tags` 仍兼容读取,但新 Case 不再推荐)。
1737
+ 默认阈值为:`must_pass: 1.0`(固定,不可降低)、`high_confidence: 0.9`、
1738
+ `tolerant: 0.8`、`informational: 0.0`。这就是"所有未标注断言都必须通过"这条旧规则
1739
+ 的等价表述(详见 12.3 节)。`judge.overall_gte`/`judge.each_dimension_gte` 仍是真实
1740
+ 读取的配置键。Judge 门槛只决定质量是否达标,不会把协议错误变成通过。
1722
1741
 
1723
1742
  ### 8.9 完整示例:用人物图片与歌曲规划 MV 风格
1724
1743
 
@@ -1791,7 +1810,6 @@ steps:
1791
1810
 
1792
1811
  outcome:
1793
1812
  require:
1794
- hard_checks: all_pass
1795
1813
  judge: { overall_gte: 0.8 }
1796
1814
  ```
1797
1815
 
@@ -1935,7 +1953,8 @@ class MockToolRegistry:
1935
1953
 
1936
1954
  1. 未声明的工具名(不在构造期传入的 `mocks.tools` 里)直接抛出
1937
1955
  `MockInvocationError("tool has no mock handler: <name>")`——这是一个**未捕获**
1938
- 异常,会让整条 run 立刻失败终止(`RunResult.passed=False`),而不是仅让当前
1956
+ 异常,会让整条 run 立刻终止并标为 Framework ERROR(`RunResult.status="error"`,
1957
+ `RunResult.error_kind="framework"`,`RunResult.passed=False`),而不是仅让当前
1939
1958
  Step 记一条硬失败、run 继续跑完剩余 Step。
1940
1959
  2. 校验 `match.arguments`(若声明了的话);不匹配时 `match_failed=True`,但**不会**
1941
1960
  抛异常中断执行——继续走到第 4 步,返回一个统一的 Tool Error。
@@ -1986,8 +2005,9 @@ respond:
1986
2005
  `sequence` 必须是非空列表,按调用次数从第一条开始依次消费(`sequence_indexes`
1987
2006
  按 tool 名字独立计数)。**序列被消费完之后如果还有下一次调用,是一次硬失败**:
1988
2007
  `MockInvocationError("mock response sequence exhausted: <name>")`,未捕获,导致
1989
- 整条 run 立即失败——不是"重复最后一条",也不是给模型返回一个可见的错误结果,这是
1990
- 原设计未明确的一处行为空白。
2008
+ 整条 run 立即变成 Framework ERROR(`status="error"`,`error_kind="framework"`)
2009
+ ——不是"重复最后一条",也不是给模型返回一个可见的错误结果,这是原设计未明确的一处
2010
+ 行为空白。
1991
2011
 
1992
2012
  ### 9.4 Python Handler 契约
1993
2013
 
@@ -2084,8 +2104,8 @@ Python Handler 有三类结果,不能混为一谈:
2084
2104
  - `MockImplementationError`:Handler 自身抛出的未预期异常、或返回值/state 不可 JSON 序列化时的包装异常。
2085
2105
 
2086
2106
  只有显式 `raise ToolMockError(...)` 才会变成模型可见的结构化 Tool Error;以上三种
2087
- 框架内部异常都属于"Mock 实现或配置有问题",视为测试基础设施故障而非被测 Agent
2088
- 应该看到的业务错误。
2107
+ 框架内部异常都属于"Mock 实现或配置有问题",视为 Framework ERROR(`status="error"`,
2108
+ `error_kind="framework"`)而非被测 Agent 应该看到的业务错误。
2089
2109
 
2090
2110
  示例:
2091
2111
 
@@ -2132,8 +2152,8 @@ Checker 从同一个最终 state 读取业务结果。Handler 源码本身不复
2132
2152
 
2133
2153
  未声明工具与参数不匹配的处理策略固定如下(无配置开关):
2134
2154
 
2135
- - Agent 调用未声明工具时,整条 run 立即硬失败(`MockInvocationError`,未捕获异常
2136
- 终止 run,而不是仅让当前 Step 记一条失败、run 继续)。
2155
+ - Agent 调用未声明工具时,整条 run 立即变成 Framework ERROR(`MockInvocationError`,
2156
+ 未捕获异常终止 run,而不是仅让当前 Step 记一条失败、run 继续)。
2137
2157
  - Tool arguments 无法匹配 `match.arguments` 时不中断执行:Runner 向模型返回统一的
2138
2158
  Tool Error `{"error": {"code": "UNKNOWN_ERROR", "message": "unknown error",
2139
2159
  "details": null, "retryable": false}}`,同时在 Mock Event 中以 `match_failed: true`
@@ -2221,7 +2241,7 @@ async def run_step(case, step, messages, registry, run_index, requests):
2221
2241
  终止**:`_run_once` 会捕获这个异常,把 Transcript 回滚到该 Step 开始前的快照,
2222
2242
  生成一条人工构造的失败 `StepResult`(`hard_checks` 里有一条
2223
2243
  `type: max_tool_rounds_exceeded` 的失败记录),然后**继续执行后续 Step**——这与
2224
- `execution.timeout_seconds_per_step` 超时(会让整条 run 直接失败终止,见 8.5 节)
2244
+ `execution.timeout_seconds_per_step` 超时(会让整条 run 标为 `status="error"` 并终止,见 8.5 节)
2225
2245
  的处理方式不同,容易混淆,需要分别记住。
2226
2246
  - `context.builders`(case scope,第 7.3 节)与 `steps[].message_inject`(Step
2227
2247
  scope,第 7.6 节)是两套独立的插入机制:前者只在第一个 Step 开始前跑一次,后者
@@ -2250,6 +2270,8 @@ execution:
2250
2270
  class RunResult:
2251
2271
  run_index: int
2252
2272
  passed: bool
2273
+ status: Literal["pass", "fail", "error"] # 旧调用未传时由 passed 推导
2274
+ error_kind: Literal["llm", "framework"] | None = None
2253
2275
  steps: list[StepResult] = field(default_factory=list)
2254
2276
  error: str | None = None
2255
2277
  traceback: str | None = None
@@ -2259,6 +2281,7 @@ class RunResult:
2259
2281
  artifact_dir: Path | None = None
2260
2282
 
2261
2283
  def usage(self) -> dict[str, int] | None: ... # 见下方 token 用量说明
2284
+ def request_duration_ms(self) -> float | None: ... # 全部 tool-loop LLM Request 耗时之和
2262
2285
 
2263
2286
  @dataclass
2264
2287
  class CaseResult:
@@ -2267,8 +2290,10 @@ class CaseResult:
2267
2290
  runs: list[RunResult]
2268
2291
  pass_rate: float
2269
2292
  description: str = "" # Case 顶层 description 的透传,供 CLI/JSON 输出展示
2293
+ status: Literal["pass", "fail", "error"] # 旧调用未传时由 passed 推导
2270
2294
 
2271
2295
  def usage(self) -> dict[str, int] | None: ... # 各 run usage() 之和
2296
+ def request_duration_ms(self) -> float | None: ... # 各 run request_duration_ms() 之和
2272
2297
  ```
2273
2298
 
2274
2299
  **Token 用量统计**没有独立的 `Usage` 类,而是一条贯穿各层的普通字典字段
@@ -2288,6 +2313,11 @@ class CaseResult:
2288
2313
  成 0)。`RunResult.usage()` = 该 run 全部 `requests[].usage` + 各 Step
2289
2314
  `judge_result["usage"]` 之和;`CaseResult.usage()` = 各 run 之和。两者的
2290
2315
  `to_dict()` 都带 `usage` 字段,因此 `result.json` 与 `--json` 输出天然携带。
2316
+ - **耗时**:tool-loop 的每次请求都会在 `requests[].duration_ms` 记录本轮
2317
+ `llm.complete()` 耗时。`runner.py:combine_duration_ms` 对这些毫秒数求和,
2318
+ 全部无数据时返回 `None`。`RunResult.request_duration_ms()` =
2319
+ 该 run 全部 `requests[].duration_ms` 之和;`CaseResult.request_duration_ms()` =
2320
+ 各 run 之和。两者的 `to_dict()` 都带 `request_duration_ms` 字段。
2291
2321
 
2292
2322
  ```python
2293
2323
  # models.py
@@ -2326,14 +2356,14 @@ class ToolCallRecord:
2326
2356
  ├── fixtures/
2327
2357
  │ └── <sha256前12位>-<原始文件名> # 用到的 fixture 文件本身的拷贝
2328
2358
  ├── requests/
2329
- │ ├── request-001.json # run 内全局递增编号,不按 Step 分段;Provider 报了用量时带 usage
2359
+ │ ├── request-001.json # run 内全局递增编号,不按 Step 分段;带 duration_ms,Provider 报了用量时带 usage
2330
2360
  │ └── request-002.json
2331
2361
  ├── transcript.json # [StepResult.to_dict(), ...]
2332
2362
  ├── mock-events.json
2333
2363
  ├── mock-state.json
2334
2364
  ├── hard-checks.json # {step_id: hard_checks}
2335
2365
  ├── judge-result.json # {step_id: judge_result}(只含有 Judge 结果的 Step;含 Judge 调用的 usage)
2336
- └── result.json # RunResult.to_dict()(含 run 级 usage 汇总、本 run 的 label 与生效 model)+ generated_at + traceback?
2366
+ └── result.json # RunResult.to_dict()(含 run 级 usage/request_duration_ms 汇总、本 run 的 label 与生效 model)+ generated_at + traceback?
2337
2367
  ```
2338
2368
 
2339
2369
  写产物前,`YamaRunner.run_case` 会先整体删除该 Case 的产物目录
@@ -2468,7 +2498,7 @@ Judge 只评价无法可靠写成确定性规则的质量维度。执行逻辑
2468
2498
  `evidence` 是**单个字符串**(不是证据数组),且**不存在 `confidence` 字段**——
2469
2499
  系统提示词只要求这四个 key,代码里也不解析/输出 `confidence`。
2470
2500
  5. 每个维度先规范化为 `(score - 1) / 4`,再按 `weight` 计算加权平均,得到 `overall`(`0..1`)。未写 `weight` 时按代码里的默认值 `1.0` 处理(等价于等权);显式权重按各自权重值直接加权平均(不需要额外归一化步骤,`weighted / total_weight` 已经等价于归一化)。
2471
- 6. 维度低于自身 `min_score`(未写时默认 `1`,即事实上不设下限)时 Judge 该 Step 失败;Case 级 `outcome.require.judge` 还可以增加 overall 和所有维度的统一门槛。
2501
+ 6. 维度低于自身 `min_score`(未写时默认 `1`,即事实上不设下限)时 Judge 该 Step 失败;Case 级 `outcome.require.judge.overall_gte` 还会并入该 Step 的 Judge 总状态:只有维度门槛和 Step `overall >= overall_gte` 同时满足,报告里的 Judge 才显示通过。
2472
2502
  7. Judge 分数不能抵消任何 Hard Assert 失败——`_case_passed` 会在检查 Judge 结果之前先判断所有 Step 的 `hard_pass`,一旦有失败就直接返回 `False`,Judge 逻辑根本不会被求值。
2473
2503
 
2474
2504
  ```yaml
@@ -2505,9 +2535,10 @@ judge:
2505
2535
  | `dimensions[].min_score` | 否 | 该维度 `1..5` 的最低原始分;省略时默认 `1`(不设下限)。 |
2506
2536
 
2507
2537
  Judge 实际返回的结构化结果(`run_judge` 在 Judge LLM 的原始输出上原地补充
2508
- `overall`/`passed` 两个字段后整体返回;Judge Provider 报了 token 用量时再补一个
2509
- `usage`——Judge 调用不进 run 的 `requests` 记录,其用量靠这个字段进入 run 级
2510
- 聚合,见第 11 节):
2538
+ `overall`/`passed` 两个字段;如果 Case 配了 `outcome.require.judge.overall_gte`,
2539
+ Runner 再把 `dimensions_passed`、`overall_required`、`overall_passed` 合入结果并
2540
+ 用二者的 AND 更新 `passed`;Judge Provider 报了 token 用量时再补一个 `usage`——
2541
+ Judge 调用不进 run 的 `requests` 记录,其用量靠这个字段进入 run 级聚合,见第 11 节):
2511
2542
 
2512
2543
  ```json
2513
2544
  {
@@ -2533,48 +2564,83 @@ Judge 实际返回的结构化结果(`run_judge` 在 Judge LLM 的原始输出
2533
2564
  ```yaml
2534
2565
  outcome:
2535
2566
  require:
2536
- hard_checks: all_pass
2567
+ hard_checks:
2568
+ tags:
2569
+ high_confidence: 0.9
2570
+ tolerant: 0.8
2571
+ informational: 0.0
2537
2572
  judge:
2538
2573
  overall_gte: 0.8
2539
2574
  each_dimension_gte: 0.6
2540
2575
  ```
2541
2576
 
2542
2577
  `judge.overall_gte`/`judge.each_dimension_gte` 是真实生效的配置键(对所有跑过 Judge
2543
- 的 Step 的 `overall`/各维度分别取阈值);`hard_checks: all_pass` 描述的行为
2544
- (所有 Step 必须 `hard_pass`)是硬编码在 `runner.py:_case_passed` 里的、不可关闭的
2545
- 门槛,这个具体的配置键本身并不被代码读取(写不写、写成什么值都不影响结果)。
2578
+ 的 Step 的 `overall`/各维度分别取阈值,不对多个 Step 取平均)。`outcome.require.hard_checks.tags` 按固定
2579
+ tag 设置 hard check 的通过率阈值(`[0, 1]` 区间的数字):`runner.py:tag_pass_summary`
2580
+ 按这次 run 里每条 hard check 的 tag 分组,算出 `rate = passed / total`,与该 tag
2581
+ 的阈值比较。允许的 tag 固定为 `must_pass` / `high_confidence` / `tolerant` /
2582
+ `informational` 四种;断言未写 tag 时归入 `must_pass`。默认阈值分别是
2583
+ `1.0` / `0.9` / `0.8` / `0.0`,其中 `must_pass` 固定为 `1.0` 不可降低。旧版
2584
+ `outcome.require.tags` 仍兼容读取,但新 Case 应写在 `hard_checks.tags` 下。完全不使用
2585
+ 这个字段的 Case 行为不变:所有断言都落进 `must_pass`,等价于旧版"所有 Step 必须
2586
+ hard_pass"这条规则。未知 tag/key、阈值不是 `[0, 1]` 区间内的数字、或试图降低
2587
+ `must_pass`,都会在运行时抛 `AssertionConfigurationError`,体现为这次 run 的
2588
+ `RunResult.error` 字段且 `status="error"` / `error_kind="framework"`。`_case_passed` 的判定顺序是:先看 `tag_pass_summary` 的每个分组是否都
2589
+ `ok`,任一不 `ok` 直接判失败;再走 Judge 门槛。
2546
2590
 
2547
2591
  实际的最终结果结构是 `CaseResult`(`runner.py`),**不存在**原设计设想的
2548
2592
  `{"passed", "hard_pass", "judge_pass", "quality_score", "reason"}` 这种顶层扁平
2549
2593
  结构——`hard_pass`/`judge_result` 这类判定分散在每个 Step 上,run 级别和 Case 级别
2550
- 只各自有一个整体 `passed` 布尔:
2594
+ 各自有一个三态 `status`(`pass`/`fail`/`error`)和一个兼容旧调用的 `passed`
2595
+ 布尔:`passed` 只在 `status == "pass"` 时为 `true`。LLM 请求异常或
2596
+ `timeout_seconds_per_step` 超时会把 run/case 标成 `error`,不进入 pass/fail 分母;
2597
+ 断言/Judge 的行为性不达标是 `fail`;断言配置错误、Mock/Builder/Checker 代码异常等
2598
+ 未捕获框架异常也是 `error`,但 `error_kind="framework"`,与
2599
+ `error_kind="llm"` 的大模型异常分开统计。
2551
2600
 
2552
2601
  ```json
2553
2602
  {
2554
2603
  "case_key": "__evals__/cases/image-led-mv.yaml",
2555
2604
  "passed": true,
2605
+ "status": "pass",
2556
2606
  "pass_rate": 1.0,
2557
2607
  "usage": { "prompt_tokens": 2000, "completion_tokens": 460, "total_tokens": 2460 },
2608
+ "request_duration_ms": 842.317,
2558
2609
  "runs": [
2559
2610
  {
2560
2611
  "run_index": 1,
2561
2612
  "passed": true,
2562
- "steps": [ { "step_id": "...", "hard_pass": true, "judge_result": { "...": "..." } } ],
2613
+ "status": "pass",
2614
+ "error_kind": null,
2615
+ "steps": [
2616
+ {
2617
+ "step_id": "...",
2618
+ "hard_pass": true,
2619
+ "tag_summary": {
2620
+ "must_pass": { "passed": 4, "total": 4, "rate": 1.0, "threshold": 1.0, "ok": true }
2621
+ },
2622
+ "judge_result": { "...": "..." }
2623
+ }
2624
+ ],
2563
2625
  "error": null,
2564
2626
  "usage": { "prompt_tokens": 2000, "completion_tokens": 460, "total_tokens": 2460 },
2627
+ "request_duration_ms": 842.317,
2565
2628
  "mock_events": [ "..." ],
2566
2629
  "mock_state": { "...": "..." },
2567
2630
  "requests": [ "..." ],
2568
- "artifact_dir": ".yama/runs/.../run-001"
2631
+ "artifact_dir": ".yama/runs/.../run-001",
2632
+ "tag_summary": {
2633
+ "must_pass": { "passed": 4, "total": 4, "rate": 1.0, "threshold": 1.0, "ok": true }
2634
+ }
2569
2635
  }
2570
2636
  ]
2571
2637
  }
2572
2638
  ```
2573
2639
 
2574
- (Case/run 级的 `usage` 是第 11 节所述的聚合结果;无任何用量数据时为 `null`。)
2640
+ (Case/run 级的 `usage` 与 `request_duration_ms` 是第 11 节所述的聚合结果;无任何对应数据时为 `null`。)
2575
2641
 
2576
- 质量分不能抵消硬检查失败:`_case_passed` 先判空 `all(step.hard_pass for step in
2577
- steps)`,任一为 `False` 就直接返回 `False`,Judge 相关逻辑不会再被求值。
2642
+ 质量分不能抵消硬检查失败:`_case_passed` 先算 `tag_pass_summary`(见 12.3 节),
2643
+ 任一分组不达标就直接返回 `False`,Judge 相关逻辑不会再被求值。
2578
2644
 
2579
2645
  ## 13. 多 Plugin 隔离与报告
2580
2646
 
@@ -2611,7 +2677,21 @@ Step——不是按 Plugin 拆开的多个文件,也没有 JSON 版的 `summar
2611
2677
  用量(第 11 节的聚合链)在报告的每一层都有展示:顶部摘要多一张「LLM tokens」
2612
2678
  卡片(总量 + in/out 拆分),Case 头部 metadata 多一格逐 Case 汇总,Run/Step 的
2613
2679
  summary 行、执行时间线里的每次 assistant 响应、LLM requests 诊断列表和 Judge
2614
- 小节各自带本层级的 token 数;没有用量数据的层级显示 `–` 或不显示。
2680
+ 小节各自带本层级的 token 数;没有用量数据的层级显示 `–` 或不显示。每轮 LLM
2681
+ Request 的详情会展示 Method、Duration、Arguments、Response,Response
2682
+ 是完整 assistant message(含 tool_calls),不只是文本内容;Case metadata
2683
+ 和 Run/Step summary 会展示 tool-loop LLM Request 耗时总和。报告不展示
2684
+ **Case tag summary**;每个 Step 的 **Hard checks** 区域会展示该 Step 自己的
2685
+ **Pass rate by tag** 折叠表,run 级 JSON 里仍保留 `tag_summary` 用于最终判定诊断。
2686
+ 顶部摘要只展示三张可见卡片:**CASES PASSED**、**CASES ERRORS**、
2687
+ **LLM TOKENS**。`CASES PASSED` 是通过 Case 数 / 总 Case 数;`CASES ERRORS`
2688
+ 是 error Case 数 / 总 Case 数;错误 Case 的具体 `error_kind` 与错误文本展示在对应
2689
+ Case header 里(如 **LLM error** / **Framework error**),而不是在顶部摘要里再拆
2690
+ 全局错误分类。整体 verdict 的优先级是 fail > error > pass(有断言/Judge 失败时为
2691
+ FAIL;没有失败但有 LLM/超时错误时为 ERROR;全部非 error 项通过且无 error 时为
2692
+ PASS)。`error_kind="llm"` 对应 LLM 请求异常和 Step 超时;`error_kind="framework"`
2693
+ 对应断言配置、Mock/Builder/Checker 代码、Mock sequence、未声明 Tool 等框架/Case
2694
+ 代码异常。
2615
2695
 
2616
2696
  跑了多个 run 的 Case(`len(runs) > 1`)在 metadata 与 Planned runs 折叠卡之间
2617
2697
  多一节 **Run comparison**(`report.py:_render_run_comparison`):
@@ -2652,8 +2732,10 @@ summary 行、执行时间线里的每次 assistant 响应、LLM requests 诊断
2652
2732
 
2653
2733
  报告 `<head>` 里内嵌一段惰性的 meta JSON(`render_page` 的 `meta` 参数,
2654
2734
  `<script type="application/json" id="yama-report-meta">`),携带 `kind`/
2655
- `generated_at`/`passed`/Case-Run-check 通过数/总 tokens——dashboard 索引页靠它
2656
- 列出每份历史报告的统计,而不必解析报告正文标记。
2735
+ `generated_at`/`passed`/`status`/Case-Run-check 通过数/Case-Run error 数/
2736
+ `llm_errors`/`framework_errors`/总 tokens——dashboard 索引页靠它列出每份历史报告的
2737
+ 统计,而不必解析报告正文标记。这里保留机器可读的 run/error 细分统计;报告正文顶部
2738
+ 只保留上面三张人工浏览用汇总卡片。
2657
2739
 
2658
2740
  **用例预览页(`preview.py`,`--preview` 与 dashboard `/preview` 共用)。**
2659
2741
  `render_preview_html` 复用报告的页面外壳与版式(`report.py:render_page` +
@@ -2727,24 +2809,26 @@ static snapshot 措辞)。
2727
2809
  [1/2] <case_key>
2728
2810
  <description,若有>
2729
2811
  Run 1/2
2730
- ✓ <step_id> hard checks 3/3 judge passed 92%
2812
+ ✗ <step_id> hard checks 3/3 judge failed 55% (required >= 70%)
2731
2813
  ├── ✓ 01 <hard check label>
2732
2814
  └── ✗ 02 <hard check label>
2733
2815
  ├── Expected ...
2734
2816
  ├── Actual ...
2735
2817
  └── Reason ...
2736
2818
  ✓ <case_key> 2/2 runs passed 100% tokens 2,460
2819
+ ! <case_key> 0/0 runs passed 0% 1 error
2737
2820
 
2738
2821
  Yama Eval Results
2739
2822
  Result | Case(含 description 副行) | Runs | Pass rate | Tokens
2740
2823
  ...
2741
- <caption:m/n cases passed • j/k runs passed • tokens 2,460 (in 2,000 / out 460)>
2824
+ <caption:m/n cases passed • j/k runs passed • [x case errors] • [y run errors] • [a llm errors] • [b framework errors] • tokens 2,460 (in 2,000 / out 460)>
2742
2825
  ```
2743
2826
 
2744
2827
  `tokens ...` 片段与表格 `Tokens` 列来自 `CaseResult.usage()`/`RunResult.usage()`
2745
2828
  (case 完成行与表格 caption 里是总量,caption 另带 in/out 拆分;明细树里 Case 行
2746
2829
  带拆分、Run 行只带总量);聚合为 `None`(Provider 没报用量)时不打印该片段,
2747
- 表格单元格显示 `–`,caption 也不带 tokens 段。
2830
+ 表格单元格显示 `–`,caption 也不带 tokens 段。`✓`/`✗`/`!` 分别对应
2831
+ `status=pass`/`fail`/`error`;ERROR 行不会计入 cases/runs passed 的分母。
2748
2832
 
2749
2833
  **并发模式**(并发 >1 且收集到多个 Case,默认即是):不同 Case 的 Step 结果会
2750
2834
  乱序到达,逐 Step 流式打印会把不相关 Case 的行交错在错误的 Case 标题下,因此改为
@@ -2796,7 +2880,7 @@ CLI 侧按并发模式挑选回调实现,两者的**已完成结果**都只做
2796
2880
  只原地更新对应行的状态(首个事件时惰性启动 transient `rich Live` 面板,
2797
2881
  `get_renderable` 每个刷新帧重建全部行——事件处理只整体替换行 dict、从不原地
2798
2882
  改写,避免与 Live 的刷新线程读写竞争);`case_end` 用 `build_case_tree` 从最终
2799
- `CaseResult` 渲染整 Case 块打印到面板上方,并把该行翻成 `✓/✗`;最后一个
2883
+ `CaseResult` 渲染整 Case 块打印到面板上方,并把该行翻成 `✓/✗/!`;最后一个
2800
2884
  `case_end` 后自动停掉面板。某个 Case 在 `case_end` 之前异常退出时面板不会自行
2801
2885
  停止,由 `cli.py:_run` 在 `gather` 结束后统一调用 `progress.close()` 兜底
2802
2886
  (两个 printer 都实现了 `close()`)。两个容易回归的实现约束:
@@ -2813,12 +2897,39 @@ stderr,保证 stdout 是纯 JSON);`--list` 只打印 `case_key` 列表,
2813
2897
  Case;`--preview` 在收集/解析之后、执行之前返回(LLM client 根本不会被构造),
2814
2898
  `--list` 与 `--preview` 同时给出时 `--list` 优先。
2815
2899
 
2900
+ `yama from-thread` 是 `cli.py:main` 里的独立子命令分支(和 `dashboard` 一样在主 parser
2901
+ 之前按 `argv[:1]` 分发),用于把后台某条模型调用记录转换为 Case YAML 起点。它从选中
2902
+ record 的 request 生成 `context.skills`/`context.tools`/`context.messages`;传入
2903
+ `--commit-id` 时通过 SSH `git show <commit>:dsl.json` 取得 DSL 并写入
2904
+ `mocks.state.dsl`。当 DSL workflow 和 request history 足够完整时,还会自动生成一条
2905
+ `steps[]`:
2906
+
2907
+ - 当前 step id 来自 `dsl.workflow.steps`,优先第一条 `status == "in_progress"`,否则取
2908
+ 第一条非 `completed`/`skipped`;若全部完成/跳过、没有 DSL、或步骤缺少 id,则不填充
2909
+ step。
2910
+ - 最近一条非纯 `<system-reminder>...</system-reminder>` 的用户消息成为
2911
+ `steps[0].user`,`context.messages` 截断到这条消息之前,避免运行 Case 时重复发送同一
2912
+ 用户回合。
2913
+ - 如果该用户消息下一条就是纯 `<system-reminder>` 用户消息,则写入
2914
+ `steps[0].message_inject`,`position: after_user_message`。
2915
+ - 从该用户消息之后的 assistant tool calls 和选中 record 的 response message 中收集
2916
+ Tool 名,按首次出现顺序聚合调用次数,生成带 `times: <count>` 和 `tag: must_pass`
2917
+ 的 `tool_called` hard checks。
2918
+
2919
+ 自动 step 只表达“复现这一轮输入并期待相同 Tool 类型被调用”。它不生成 `mocks.tools`、
2920
+ 更精细的参数断言或 Judge;这些仍由 Case 作者按评测目标补齐。生成的 Case 会固定写入
2921
+ `outcome.require.hard_checks.tags.must_pass: 1.0`,让 `must_pass` 组的 100% 通过门槛在
2922
+ 骨架里显式可见。若无法推导当前 workflow step 或真实用户输入,则保留 `steps: []`,
2923
+ stdout 仍只输出 YAML,stderr 只输出 record/response/DSL 抓取诊断信息。
2924
+
2816
2925
  `cli.py:main` 的错误出口按层归类(退出码都是 2):`ConfigurationError`/
2817
2926
  `CollectionError`/`ValueError` 打印 `Collection error: ...`(Case 还没跑起来,
2818
2927
  问题出在工作区配置或 Case 收集/解析);`LLMError` 单独打印 `LLM error: ...`——
2819
2928
  此时 Case 往往已经收集甚至执行过(例如脚本回放响应未被消费、Provider 配置缺失),
2820
2929
  把它标成 Collection error 会把排查引到错误的层级。run 内部的 LLM 异常仍由
2821
- `YamaRunner._run_once` 捕获进 `RunResult.error`,不走这个出口。
2930
+ `YamaRunner._run_once` 捕获进 `RunResult.error` 且标为 `status="error"`,不走这个
2931
+ 顶层出口;CLI 汇总完所有 Case 后,如果没有 `fail` 但存在 `error`,也返回退出码 2。
2932
+ 如果同时存在 `fail` 和 `error`,退出码仍为 1,报告/JSON 里会分别显示失败和错误。
2822
2933
 
2823
2934
  一个 Plugin 的 Skill、Tool、Case、产物目录不会泄漏到另一个 Plugin——这一点由
2824
2935
  "每个 Case 归属唯一 Plugin Root、产物写在该 Plugin 自己的 `.yama/` 下"这一实现
@@ -2927,6 +3038,8 @@ Case;`--preview` 在收集/解析之后、执行之前返回(LLM client 根
2927
3038
  - JSON 产物(逐 Case/逐 run)与单文件 HTML 汇总报告。
2928
3039
  - LLM token 用量统计:逐请求采集、run/Case 级聚合、CLI 与 HTML 报告展示
2929
3040
  (见第 11 节与第 13 节)。
3041
+ - LLM Request 耗时统计:逐请求采集 `duration_ms`、run/Case/报告级聚合并在
3042
+ HTML 报告展示(见第 11 节与第 13 节)。
2930
3043
 
2931
3044
  ## 17. 最终边界
2932
3045