cost-diff
它能做什么
这项技能比较两份已保存的成本摘要,并列出增减的部分。适合想查看某项改动是否增加了 AI 支出的团队。
适用场景
- ✓当代码改动可能提高了 AI 支出,你想加以检查时。
- ✓当你想比较某次发布前后的成本时。
- ✓当支出超过设定上限时,你希望它自动使检查失败时。
技能链接
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-diff/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请比较我改动前后的成本摘要,并告诉我哪些项目增加了。”
每周 5 个新技能,1 分钟读完。
工作原理
这项技能加载两个摘要文件,比较总额和各模型的金额,并按变化幅度排序。当增幅超过你设定的上限时,它可以返回错误代码。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
PR-level cost regression detection. Where cost-counterfactual compares to HYPOTHETICAL baselines (always-haiku/sonnet/opus) and cost-burn compares latest bucket to PRIOR MEAN, cost-diff compares two SPECIFIC known-good snapshots.
| Question | Skill |
|---|---|
| "What would we have spent at always-X?" | cost-counterfactual |
| "Is daily burn accelerating vs prior mean?" | cost-burn |
| "Did THIS PR add spend vs main?" | cost-diff ← this |
Algorithm
Implementation: scripts/diff.mjs. Consumes the
stable JSON contract from cost summary --format json.
- Load
--baselineand--currentJSON snapshots. - Sanity check: both must have
total_cost_usd+sessionCount(cost-summary shape). - Per-key delta:
byTier(haiku/sonnet/opus) andbyModel(each model). - Each entry tagged
added/removed/changedbased on baseline / current zero-ness. - Sort table by
|delta|descending so the biggest movers are at the top. --alert-on-pct N: exit 1 whentotal_pct > N.--alert-on-usd N: exit 1 whentotal_delta_usd > N. Both can be set; first to trigger wins.
PR-gate workflow
# Capture baseline (e.g. on main, via the cost-tracker-smoke CI workflow)
cost summary --format json > baseline.json
# On the PR branch, capture current state
cost summary --format json > current.json
# Compare; fail the PR if total spend grew >10% OR >$5
cost diff --baseline baseline.json --current current.json \
--alert-on-pct 10 --alert-on-usd 5.00
The combination of both flags catches:
- Percent-only fires: a small absolute change but a meaningful shift (e.g. doubling from $0.10 to $0.20 hits +100% but only +$0.10).
- USD-only fires: a large absolute change with a small percent (e.g. growing from $100 to $110 is only +10% but +$10).
Either signal can fail the PR independently — they're OR'd.
--alert-on-class-pct (iter 86)
The two USD-level thresholds above miss a regression class: when ONE
token type grows disproportionately even though total spend grows
modestly. Example: a PR introduces a verbose context-cache pattern,
total spend grows only 10% (under --alert-on-pct 50), but cache_write
tokens grow 900%. The iter-82 driver hides inside the USD signal.
--alert-on-class-pct cache_write:50 exits 1 when cache_write tokens
grow more than 50% baseline → current. Multiple classes can be checked
in one flag (comma-separated):
cost diff --baseline baseline.json --current current.json \
--alert-on-class-pct cache_write:50,output:25
First class to breach wins. Valid classes: input | output | cache_write | cache_read.
Recommended PR-gate triad:
cost diff --baseline ... --current ... \
--alert-on-pct 25 \
--alert-on-usd 5.00 \
--alert-on-class-pct cache_write:100
Three orthogonal signals — pct (total grew), usd (large absolute
jump), class-pct (composition shifted). Each catches what the others
miss; AND-of-OR semantics means any one firing fails the PR.
Smoke transcript (synthetic baseline + current)
| Total spend | $1.000000 | $1.500000 | +$0.500000 | 50.00% |
| Sessions | 10 | 13 | +3 | 30.00% |
## By tier
| opus | $0 | $0.60 | +$0.600000 | new | added |
| sonnet | $0.70 | $0.50 | -$0.200000 | -28.57% | changed |
| haiku | $0.30 | $0.40 | +$0.100000 | 33.33% | changed |
Notice the table is sorted by absolute delta, not alphabetically — the biggest mover (opus newly added) bubbles to the top. Operators reading top-down see "what mattered" first.
Exit codes
| Exit | Meaning |
|---|---|
| 0 | No alert, OR no thresholds set |
| 1 | --alert-on-pct or --alert-on-usd threshold exceeded |
| 2 | Config error (missing files, invalid JSON, malformed snapshot) |
Status column
| Status | Meaning |
|---|---|
added |
This tier/model was $0 in baseline, >$0 in current |
removed |
This tier/model was >$0 in baseline, $0 in current |
changed |
Both baseline and current >$0; delta is the difference |
Entries with baseline === 0 && current === 0 are dropped (nothing to
report).
Composition with cost-summary
cost-diff is the SECOND HALF of a contract that cost-summary started:
the stable JSON shape from cost summary --format json. Both pieces
have been frozen — adding fields to summary is fine; renaming or
removing isn't.
If you're consuming snapshots elsewhere (
常见问题
它需要哪些文件?
它需要两个 JSON 格式的成本摘要文件,一个作为基准,一个代表当前状态。
它会标记新出现的模型吗?
会。每一项都会标注为新增、移除或已变更,因此新模型会很醒目。
它能自动阻止某项改动吗?
可以。你可以设置百分比或金额上限,任一超过时检查即失败。
详情
作者的原始描述
Snapshot delta between two cost-summary JSON outputs. PR-level cost regression detection — answers "what changed between these two specific snapshots?". Pairs with cost-summary's stable JSON contract.
repo: ruvnet/ruflo
热度
- GitHub 星标
- 81k
- 排名
- #1599
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
agent-adaptive-coordinator
81k帮你的智能体在工作量变化时拆分和重新平衡一组 AI 智能体,并选择适合任务的分工方式。
agent-agent
81k教你的智能体把一个大目标拆成有顺序的行动计划,并在情况变化时重新规划。
agent-agentic-payments
81k帮你的智能体管理 AI 购物的消费授权,包括消费上限、时间窗口、商户规则和签名审批。
agent-analyze-code-quality
81k帮你的智能体检查代码质量,找出代码异味、技术债务和重构建议,且不改动文件。