用途
AI CLI Benchmark 用于设计、运行和审查跨 GitHub Copilot CLI、Codex CLI 以及直接模型 API 的公平性能、token 与费用对比。它适用于需要比较不同 AI CLI 或 API 调用方式在速度、token 消耗和成本上差异的场景。该技能负责比较条件的设计、执行与证据化;如果只是对过去 session 做事后分析,则不在其范围内。
主要能力
- 冻结任务:固定 dataset、expected labels、prompt、schema、input order、model、reasoning,并生成 hash。当同时比较 accuracy 与性能时,对全部 provider 应用相同的合格条件。
- 定义测量边界:区分 one request、serial total、fresh-process end to end;不把 API 直调与包含 CLI 启动时间的结果并列为 model speed。
- 隔离每个 CLI:使用 repo 外的自有临时目录、fresh process、临时 COPILOT_HOME / 仅认证的 CODEX_HOME;禁用 custom instructions、tools、MCP、session reuse,且不将 secret 传入子进程或日志。
- 观察缓存而非假设可控:必要时在 prompt 开头加入唯一 nonce,只保存 nonce 的 hash 而非本体;zero-cache-read gate 仅用于诊断,失败应作为 provider cache 的观测结果记录,而非隐藏为 benchmark 失败。
- 记录原始 token 分类:将 normal input、cache read、cache write、output、reasoning 分别保存为独立字段;在确认 provider schema 的包含与排他关系前,不合并 token 分类。
- 重复运行后再声称性能差异:不将单次差异归因于 cache 的因果效果;报告 median / p95 / range 与 accuracy。
- 校验产物:使用
python scripts/helper.py result.json --require-cache-metadata --report validation.json校验结果 JSON。
使用方式
结果 JSON 需满足以下结构:test_design.prompt_sha256、可选的 test_design.cache_observation(包含 nonce_added_at_prompt_start、nonce_sha256),以及 providers[],其中每个 provider 包含 provider、elapsed_ms、passed、cases、usage(input_tokens、cached_input_tokens、cache_write_tokens、output_tokens、可选的 reasoning_tokens)。仅在步骤 4 的诊断 gate 中使用 --require-zero-cache-read。
缓存边界
Copilot CLI / Codex CLI 没有公开选项可禁用 provider 侧 model prompt cache。fresh process、临时 home、ephemeral、nonce 都不应被称为 cache off。COPILOT_CACHE_HOME 用于 Marketplace、自动更新 package 等本地临时数据;COPILOT_MCP_TOOL_CACHE 用于本地 MCP server 的 tool-list snapshot,二者都不是 model prompt cache。OpenAI prompt cache 无法手动清除;只有从 Responses API 直接调用 GPT-5.6 及以后版本时,才可在 explicit-only mode 下不放置 breakpoint,从而避免该 request 的 cache write,不应将此推测应用到 CLI。nonce 用于避免 user prompt 整体匹配,但无法阻止其之前的 hidden system / agent prefix 的 cache read。
报告规则
cache write 不是 cache hit,应与 read 分开,并按对应 model 的计费类别计算费用。应写为“观测到的 cache read 0 run”或“cache-observed run”,而非“uncached run”。需记录 CLI version、model、reasoning、prompt hash、nonce hash、fresh-process 条件、测量边界、usage schema。即使 cache read 为 0,也不保证未来 write 或 hidden prefix 的控制。
完成标准
- dataset / prompt / schema / model / reasoning 已固定并有 hash。
- 所有 provider 使用 fresh process 与临时 home。
- cache read / write 分别保存为独立字段。
- 测量边界与 accuracy 一并报告。
- 无多次运行时不将速度差异归因于因果。
- benchmark JSON validator 通过。
参考
- OpenAI Prompt caching: https://developers.openai.com/api/docs/guides/prompt-caching
- GitHub Copilot CLI command reference: https://docs.github.com/en/copilot/reference/copilot-cli-reference/cli-command-reference