cost-budget-check
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCost Budget Check
成本预算检查
Reads for the project's budget limit, sums across records produced by , computes utilization, and emits the measured 4-tier alert ladder (50% INFO / 75% WARNING / 90% CRITICAL / 100% HARD_STOP).
cost-tracking:budget-configtotal_cost_usdsession-*cost-trackUntil P2 (this skill) landed, the README documented the alert ladder but no code checked it. Now this skill is the gate.
读取项目的配置获取预算限额,汇总生成的记录中的总额,计算利用率,并触发实测的四级阶梯警报(50% INFO / 75% WARNING / 90% CRITICAL / 100% HARD_STOP)。
cost-tracking:budget-configcost-tracksession-*total_cost_usd在P2(该skill)落地之前,README中仅记录了警报阶梯,但没有代码实现检查逻辑。现在这个skill是管控的核心。
When to use
使用场景
- After every cost-track run, to surface the alert level.
- Before spawning a swarm — if utilization ≥ 90%, escalate to first.
/cost-optimize - Cron-friendly via for continuous monitoring.
/loop 30m
- 每次cost-track运行后,用于显示警报等级。
- 在启动swarm之前——如果利用率≥90%,需先调用进行优化。
/cost-optimize - 通过实现定时任务,支持持续监控。
/loop 30m
Steps
操作步骤
-
Run the check:bash
node plugins/ruflo-cost-tracker/scripts/budget.mjs checkFilter by period:(defaultBUDGET_PERIOD=today). Useallfor machine-readable JSON.BUDGET_QUIET=1 -
Inspect the markdown summary — budget, spent, remaining, utilization percentage, alert level (🟢 OK · 🟡 INFO · 🟠 WARNING · 🔴 CRITICAL · 🛑 HARD_STOP), and the recommended action.
-
Set / inspect the budget:bash
node plugins/ruflo-cost-tracker/scripts/budget.mjs set 50.00 node plugins/ruflo-cost-tracker/scripts/budget.mjs get -
HARD_STOP path —exits with code
budget.mjs checkwhen utilization ≥ 100%. Wrap critical agent spawns in a1guard to fail closed.budget.mjs check && spawn …
-
执行检查:bash
node plugins/ruflo-cost-tracker/scripts/budget.mjs check按时间段筛选:(默认值为BUDGET_PERIOD=today)。使用all可输出机器可读的JSON格式。BUDGET_QUIET=1 -
查看Markdown摘要——包含预算金额、已支出金额、剩余金额、利用率百分比、警报等级(🟢 正常 · 🟡 INFO · 🟠 WARNING · 🔴 CRITICAL · 🛑 HARD_STOP),以及推荐操作。
-
设置/查看预算:bash
node plugins/ruflo-cost-tracker/scripts/budget.mjs set 50.00 node plugins/ruflo-cost-tracker/scripts/budget.mjs get -
HARD_STOP流程——当利用率≥100%时,将以退出码
budget.mjs check终止。可将关键agent的启动逻辑包装为1,确保在超预算时停止执行。budget.mjs check && spawn …
Storage shape (cost-tracking:budget-config
)
cost-tracking:budget-config存储结构(cost-tracking:budget-config
)
cost-tracking:budget-configjson
{
"budget_usd": 50.00,
"setAt": "2026-05-05T...",
"thresholds": { "info": 0.50, "warning": 0.75, "critical": 0.90, "hard_stop": 1.00 }
}json
{
"budget_usd": 50.00,
"setAt": "2026-05-05T...",
"thresholds": { "info": 0.50, "warning": 0.75, "critical": 0.90, "hard_stop": 1.00 }
}Alert ladder (from REFERENCE.md, now enforced)
警报阶梯(来自REFERENCE.md,现已强制执行)
| Threshold | Level | Action |
|---|---|---|
| 50% | INFO 🟡 | log notification, no UX disruption |
| 75% | WARNING 🟠 | display warning, suggest |
| 90% | CRITICAL 🔴 | urgent alert, recommend model downgrades |
| 100% | HARD_STOP 🛑 | halt non-essential spawns; exit code 1 |
| 阈值 | 等级 | 操作 |
|---|---|---|
| 50% | INFO 🟡 | 记录通知,不影响用户体验 |
| 75% | WARNING 🟠 | 显示警告,建议调用 |
| 90% | CRITICAL 🔴 | 紧急警报,推荐降级模型 |
| 100% | HARD_STOP 🛑 | 暂停非必要的agent启动;退出码1 |
Cross-references
交叉引用
- (producer) — populates
cost-trackcost-tracking:session-* - — same data source, narrative format
cost-report - — recommended action when WARNING/CRITICAL
cost-optimize - REFERENCE.md "Budget alert thresholds" — the documented ladder this enforces
- (数据生成方)——填充
cost-track数据cost-tracking:session-* - ——使用同一数据源,生成叙事格式报告
cost-report - ——当触发WARNING/CRITICAL时的推荐操作
cost-optimize - REFERENCE.md中的“预算警报阈值”——本工具强制执行的文档化阶梯规则