# Skill Evaluation 原生、本地的 Skill evaluation 与 OpenCode tracing,使用 SQLite、OTLP collector 和内置 UI。 项目目录与 Python 包名统一为 `agent_evaluation`。 从零添加 Skill、case、instrumentation 和 evaluator,见 [Quick Extension Guide](docs/quick-extension-guide.md)。 环境安装、联网边界和环境变量索引见 [Quick Extension Guide 的环境章节](docs/quick-extension-guide.md#0-环境安装与变量索引)。 ## Quickstart 从仓库根目录运行。首次安装环境: ```bash agent_evaluation/environment/sync-python-env.sh cp agent_evaluation/.env.example agent_evaluation/.env ``` 第一条命令是可重复的一键同步入口,但需要本机已有 `uv` 和 `git`;首次通常联网下载 Python/依赖及固定 tracing checkout。它不安装 OpenCode executable 或云端凭证;离线复用要求 这些内容已经在本机 cache/checkout 中准备好。 在 `.env` 填写 `OPENAI_API_KEY`、`SKILL_EVAL_LLM_MODEL`;兼容服务可填写 `OPENAI_BASE_URL`。文件不提交。环境安装会 checkout 固定 revision 的 fork `coding-harness-tracing`,其中包含原生 OTLP 出口、OpenCode plugin、reconciler、脱敏和事件协议。 已有 plugin 的 HOME 应继续指向该 tracing 安装;详见 [tracing 前置条件](backend/README.md#tracing-前置条件)。 使用 CLI 运行前,先启动 native collector/UI。Collector 接收 trace;evaluation 进程保存实验和 评分,两者共享同一个 SQLite 数据库: ```bash # 终端 A:原生 SQLite collector + UI,Ctrl-C 停止 agent_evaluation/scripts/start-evaluation-server ``` ## 选择运行方式 三种方式都使用同一个 `EvaluationLoop`、canonical dataset、profile、SQLite 和 artifact。 区别只在任务从哪里来、是否由本项目启动 OpenCode,以及每次处理多少 case。 | 要做什么 | 选择 | 推荐入口 | 适用情形 | | --- | --- | --- | --- | | 无人值守地运行一个或多个 case | 默认 headless | `scripts/eval-cli` | 批量实验、CI 或可重复的真实 OpenCode 运行 | | 人工在真实 TTY 中操作一个 OpenCode 会话 | `interactive` | `scripts/run-interactive-example` | 需要观察或干预 TUI;退出后评估该 case | | 评估已结束、已导出的 OpenCode 会话 | `evaluate-export` | `scripts/run-export-example` | 不再次启动 OpenCode;复用原 session 的原生 trace | `scripts/run-interactive-example` 与 `scripts/run-export-example` 是可直接编辑或用环境变量覆盖的 单 case 示例,预填仓库的 Skill、dataset、profile 和常用路径。`scripts/eval-cli` 是薄 wrapper: 它设置 Python/PYTHONPATH 和 localhost proxy bypass,其他参数原样交给 CLI,因此既是无头批量 入口,也是 `interactive`、`evaluate-export` 的通用入口。`scripts/start-evaluation-server` 只负责 collector/UI,不执行 case。脚本都必须直接执行,不能 `source` 或 `. script`。 interactive 示例要求真实 TTY,先检查脚本顶部的本机路径: ```bash # 终端 B agent_evaluation/scripts/run-interactive-example ``` 要评估保留的 session,先执行 `opencode export `,再在 另一个终端运行: ```bash EXPORT_JSON=/absolute/path/export.json CASE_ID=V_PosSharpDet \ TRACE_PROJECT=subject-opencode \ agent_evaluation/scripts/run-export-example ``` export 只恢复任务记录;trace evaluator 读取原生 DB 的 project/session spans,不从 export 或 JSONL 生成替代 trace。其他 backend 的历史数据库不会自动迁移。 默认 UI 为 `http://127.0.0.1:6006`,仅本机可访问;需要局域网浏览时,按 [Native backend 网络监听配置](backend/README.md#启动与配置) 启动服务。CLI 的实验记录仍 直接写运行 CLI 所在机器的 SQLite;跨机器运行需要共享同一个数据库文件。正式数据库为 `workspace/native/evaluation.sqlite`。 Experiments 显示实验与统一报告,Traces 显示 session、span 时序、正文、显式事件与关联 evaluation。本地报告仍为 `workspace/artifacts//report/index.html`,可离线打开。 ## 无头批量运行示例 以仓库父目录作为 fixtures 的 provenance root;按本机位置修改 `REPO_ROOT`: ```bash REPO_ROOT=/absolute/path/to/agent_eval agent_evaluation/scripts/eval-cli \ --skill "$REPO_ROOT/data/veritas-ut-testplan-gen" \ --dataset agent_evaluation/dataset_bundles/veritas-ut-testplan-gen/v1 \ --evaluation-profile agent_evaluation/evaluation_profiles/veritas-ut-testplan-gen.yaml \ --case-id V_PosSharpDet \ --opencode-command "$REPO_ROOT/package/opencode/opencode" \ --opencode-home "$REPO_ROOT/package/real-opencode-home" \ --opencode-model opencode/mimo-v2.5-free \ --agent-workdir "$REPO_ROOT" \ --artifacts agent_evaluation/workspace/artifacts \ --backend-endpoint http://127.0.0.1:6006 \ --no-evolve ``` `--database` 可指定独立数据库,两端必须指向同一文件,启动检查会核对 database ID。 自定义端口使用 server `--port` 和 CLI `--backend-endpoint`;backend endpoint 不隐含具体厂商。 `SKILL_EVAL_PYTHON` 选择 wrapper 的 Python。凭证文件优先级为 `--env-file` > `SKILL_EVAL_ENV_FILE` > 本项目 `.env`;已有 shell 变量优先于文件。 默认 `.env` 可以不存在,此时直接使用 shell 环境变量;显式指定的环境文件必须存在。 Worktree 之间不会自动查找或共享 `.env`,请显式设置 `SKILL_EVAL_ENV_FILE`。 两个 example 脚本把额外参数原样传给 CLI,例如: ```bash agent_evaluation/scripts/run-interactive-example --interactive-timeout 1800 --opencode-model opencode/big-pickle EXPORT_JSON=/path/export.json agent_evaluation/scripts/run-export-example --case-id V_AXIR_ALIGN --llm-timeout 180 ``` 普通单值参数以最后一次传入为准;无头模式的 `--case-id` 可重复选择多个 case, 只有无头模式支持 `--limit`。Interactive 不提供无效的 auto-approve 开关。 无头模式默认使用真实 OpenCode;`--adapter simulator` 只用于 fake/编排验证,不能作为真实 OpenCode 验收。省略 `--case-id` 时运行 dataset 中所有 case;显式重复 `--case-id` 或使用 `--limit` 可控制批量范围。要直接使用通用入口运行另两种模式: ```bash # 真实 TTY;一次一个 case agent_evaluation/scripts/eval-cli interactive --help # 一次一个已导出的 session;trace profile 需要 --trace-project agent_evaluation/scripts/eval-cli evaluate-export --help ``` ## 架构 ```text Skill + evaluation profile + canonical dataset -> EvaluationLoop -> NativeExperimentBackend.run() -> AgentAdapter.run() 每 case 一次 -> BoundEvaluator.evaluate() 每 evaluator/case 一次 -> SQLite: experiment / run / ScoreRecord -> 可选 annotation: score 与 span 的关联 -> feedback / candidate / artifact / HTML OpenCode plugin -> reconciler -> OTLP/HTTP JSON -> native collector -> SQLite spans -> NativeTraceStore -> TraceEvidence -> evaluator ``` 五个接口仍在 `ports.py`:AgentAdapter、DatasetLoader、ExperimentBackend、TraceStore、 LLMCompletionBackend。评分没有 vendor carrier 或 metadata 补写。UI 与本地报告共享 evaluation renderer,只有原生 UI 负责数据库和 trace 浏览。 ## 文档与源码地图 | 任务 | 入口 | | --- | --- | | 快速扩展一个完整 evaluation | [Quick Extension Guide](docs/quick-extension-guide.md) | | 输入、生命周期、artifact、失败诊断 | [Runtime README](docs/runtime.md) | | 新增 evaluator、LLM contract、annotate | [Evaluator README](evaluators/README.md) | | 替换 case 或构建 dataset | [Dataset README](datasets/README.md) | | 扩展事件协议或 carrier | [Instrumentation](docs/runtime.md#instrumentation-protocol) | | DB、OTLP、UI、tracing integration | [Native integration](backend/README.md) | | 新增外部 adapter | [Integrations](integrations/README.md) | | 按任务查找规范 | [Docs map](docs/README.md) | `loop.py` 组装实验,`evaluators/` 定义规则与 LLM,`trace_evidence.py` 做通用投影, `instrumentation.py` 保存协议,`backend/` 实现存储/collector/backend, `artifacts.py` 归档,`reporting/` 生成共用报告。四类输入继续保持分离。 ### 目录职责 | 位置 | 职责 | | --- | --- | | 顶层 Python 模块 | CLI、配置、领域模型、五个 Protocol、Loop、事件协议、trace evidence、artifact | | `datasets/` | canonical loader、builder、manifest 校验及 source converters | | `dataset_bundles/` | 构建后的 canonical 配置与数据,不存运行代码 | | `evaluators/` | 规则、typed params、judge contract、绑定与 LLM 执行 | | `integrations/` | OpenCode、OpenAI 和测试 Simulator 等外部适配 | | `backend/` | SQLite、OTLP、实验调度、TraceStore、HTTP 路由和浏览页 | | `reporting/` | 统一 ReportData 与纯 HTML 渲染;输入转换/写盘归调用方,统计归领域模型 | | `tests/datasets/` | dataset 测试;其余测试直接位于 `tests/` | | `evaluation_profiles/`、`scripts/`、`environment/` | 评分配置、四个用户入口、可复现环境 | | `docs/`、`workspace/` | 长期文档、ignored 运行数据 | Python 入口为 `python -m agent_evaluation.cli`。此次目录迁移不保留旧 import 或 CLI module 别名;历史实验里的路径原样保留,不重写历史 artifact。 ## 测试与保留 ```bash python -m pytest -q agent_evaluation/tests python -m compileall -q agent_evaluation git diff --check ``` 真实验收用真实 OpenCode;Simulator 仅用于单元/fake 测试或明确要求的检查。实验完成不等于 质量全通过:CLI 仅在所有 assessment 成功且 score=1 时退出 0。Measurement、diagnostic、 可选 annotation 错误不改变质量门槛。 `workspace/` 不提交。SQLite 是正式事实来源,停掉 collector/运行进程后再复制或清理。 Agent 输出不能仅靠 trace 恢复,artifact 与必要 raw evidence 应一起保留。其他 backend 的历史 workspace 不迁移、不删除;原生运行使用新数据库和新 experiment ID。