关于 cost-health
cost-health 是用于 CI 的成本健康检查技能,并行运行预算、消耗速度、异常和预算耗尽预测检查。它汇总各项结果,并以最严重的退出码决定门禁状态。
主要功能
- 01并行运行四项成本检查
- 02汇总每项检查状态
- 03按最严重结果返回退出码
- 04可配置各类告警阈值
- 05支持跳过指定检查
适用场景
- 01在 CI 中设置统一成本门禁
- 02快速运行时跳过较慢的检查
- 03对预算耗尽时间设置告警
- 04检查成本异常与消耗加速
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ ruvnet/ ruflo --skill cost-health安装后在 Claude Code 中输入/cost-health确认已加载。
详细介绍
四项 CI 门禁技能(budget / burn / anomaly / projection)分别回答不同的问题。本技能将它们组合起来——并行运行全部四项,返回 max(exit_codes),并为每项检查打印一行摘要。
| 子检查 | 问题 | 默认阈值 |
|---|---|---|
budget | “我们是否已超出配置的预算?” | 达到 100% 时 HARD_STOP |
burn | “每日消耗是否正在加速?” | 较前一周均值增长 +100% |
anomaly | “是否有任何特定会话是 >3.5σ 的异常值?” | ≥1 个异常值 |
projection | “我们何时会达到预算的 100%?” | <14 天 |
算法
- 并行启动全部四个子检查脚本(通过
child_process.spawn使用Promise.all)。 - 每个子检查都会输出
--format json;解析并捕获退出代码。 - Projection 没有内置退出代码——根据
daysUntilReached[100%] < --alert-days-to-exhaust合成一个退出代码。 - 最终退出代码 =
max(subcheck exits)。任意一项检查失败都会导致门禁失败。 - 为每项检查打印一行摘要,并显示整体 HEALTHY/UNHEALTHY 徽标。
CI 集成
- name: Cost health gate
run: cost health --alert-acceleration 100 --alert-outliers 1
一个步骤即可涵盖四组警报阈值。在使用本技能之前,你需要配置四个独立的门禁,每个门禁都会重复执行 npx 和 memory-list 开销;现在只需调用一次 shell 命令(内部的四个子检查 npx 调用会并行运行)。
自定义阈值
# Quarterly review — stricter thresholds
cost health --alert-acceleration 50 --alert-outliers 1 --alert-days-to-exhaust 30
# Production drift gate — only fire on egregious changes
cost health --alert-acceleration 200 --alert-outliers 3 --alert-days-to-exhaust 7
# Skip the slow burn check during a smoke run
cost health --skip burn
冒烟测试记录(5 个健康会话,然后添加 1 个异常值)
# Healthy
Overall: ✓ HEALTHY (max exit code 0)
| Check | Status | Detail |
| budget | ✓ | unknown — no budget configured |
| burn | ✓ | delta within ±100% |
| anomaly | ✓ | 0 outliers — under threshold ≥1 |
| projection | ✓ | no budget configured — skipping |
# After adding $5 outlier (vs $0.10 baseline)
Overall: ⚠ UNHEALTHY (max exit code 1)
| burn | ⚠ | ALERT 5163.2% acceleration: latest bucket $5.00 is 5163.2% above prior mean $0.095 |
| anomaly | ⚠ | ALERT 1 outlier (|z|>3.5) |
跳过子检查
cost health --skip burn,projection # only budget + anomaly
适用于以下情况:
- 某项子检查不适用(未设置预算 → 跳过 projection)
- 某项子检查对于快速反馈场景来说太慢(冒烟测试)
- 某项子检查已在其他 CI 门禁中独立检查
退出代码语义
| 退出代码 | 含义 |
|---|---|
| 0 | 所有子检查均正常 |
| 1 | 至少一项子检查触发警报(预算 HARD_STOP、消耗偏移、异常值离群、projection 即将耗尽) |
| 2 | 某项子检查存在配置或用法错误(例如,无效 CLI 参数传递给子脚本) |
| 127 | 某项子检查启动失败(脚本缺失等) |
max() 表示以最严重的信号为准——退出代码 2(配置错误)始终高于退出代码 1(警报),因此你可以在错误配置的流水线被误认为健康之前发现问题。
评论
支持 Markdown