cost-guard
Compare observed app-level run-rate to per-app and per-model budgets, emit INBOX warnings on breach
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 5
- Forks
- 1
01 前言 Front Matter
- name
- cost-guard
- phase
- on-demand
- description
- Compare observed app-level run-rate to per-app and per-model budgets, emit INBOX warnings on breach
- file_patterns
- []
- trigger_keywords
- [ "cost alert", "budget guard", "cost guard", "check budget", "budget breach" ]
- applicable_agents
- [ "all" ]
02 资源文件 17
- 脚本cost_guard.py14.3 KB
- 参考文档tests/fixtures/breach/cost_budgets.json171 B
- 参考文档tests/fixtures/breach/costs.json186 B
- 参考文档tests/fixtures/breach/quota_state.json210 B
- 参考文档tests/fixtures/nominal/cost_budgets.json380 B
- 参考文档tests/fixtures/nominal/costs.json185 B
- 参考文档tests/fixtures/nominal/quota_state.json314 B
- 参考文档tests/fixtures/stale/cost_budgets.json171 B
- 参考文档tests/fixtures/stale/costs.json186 B
- 参考文档tests/fixtures/stale/quota_state.json210 B
- 参考文档tests/fixtures/warn/cost_budgets.json126 B
- 参考文档tests/fixtures/warn/costs.json184 B
- 参考文档tests/fixtures/warn/quota_state.json208 B
- 参考文档tests/fixtures/zero_budget/cost_budgets.json205 B
- 参考文档tests/fixtures/zero_budget/costs.json126 B
- 参考文档tests/fixtures/zero_budget/quota_state.json210 B
- 脚本tests/test_cost_guard.py7.2 KB
03 SKILL.md 正文
cost-guard
Purpose
Watch app-level financial state and warn an operator when GCP burn or LLM token consumption is on track to breach a configured budget. cost-guard is the alarm complement to F001 cost-model: cost-model tells you what the trajectory is, cost-guard tells you whether the trajectory matters. Writes findings into the existing F008 INBOX.md surface so cost alerts share an inbox with quota_warn and breaker_tripped rather than introducing a new operator channel.
This skill is app-level, distinct from F006 budget_ceiling which guards orchestration-agent quotas inside autonomous dispatches. Different lane, different consumer.
Arguments
| Argument | Required | Description |
|---|---|---|
--costs |
no | Path to costs.json (default: dashboard/state/costs.json) |
--quota |
no | Path to quota_state.json (default: ~/.jarvis/quota_state.json) |
--budgets |
no | Path to cost_budgets.json (default: config/cost_budgets.json) |
--inbox-dir |
no | Directory containing INBOX.md (default: dashboard/state/cost-guard/) |
--seen-state |
no | Path to dedupe state file (default: dashboard/state/cost-guard/cost_guard_seen.json) |
--as-of |
no | Override "now" with an ISO-8601 timestamp for deterministic tests |
--fixtures |
no | Directory containing costs.json, quota_state.json, cost_budgets.json — convenient for testing |
If no arguments: reads defaults and writes to dashboard/state/cost-guard/INBOX.md.
Prerequisites
config/cost_budgets.jsonexists. Ships with sentinel zeros — cost-guard short-circuits withno_budgets_configuredif the operator hasn't filled in numbers.scripts/quota_check.pyandscripts/maintainer/refresh-costs.shhave been run. cost-guard treats state files >24h old as stale and emitsdata_staleinstead of false-positive breach entries.
Steps
- Load — read costs.json + quota_state.json + cost_budgets.json. Missing budget config → exit 0 with a single
no_budgets_configuredfinding. - Stale-data check — if either input has
generated>24h old, emit onedata_stalefinding and short-circuit. - Project — compute MTD daily rate for each app (mirrors F001 cost-model). Compute week-to-date burn for each LLM model.
- Compare — for each app where
gcp_monthly_budget_usd > 0, ratio =projected_month_end / budget. For each LLM model whereweekly_token_budget(orweekly_call_budget) > 0, ratio =projected_week_end / budget. - Emit —
cost_breach(ratio >= 1.0) orcost_warn(ratio >= 0.8) entries via the F008 INBOX writer (scripts/dontpanic_orchestrate/inbox.py). Always honor the resolved threshold values; the--budgetsJSON may override defaults viathresholds.warnandthresholds.breach. - Idempotency — dedupe key =
sha256(scope|kind|week_start). Re-runs within the same calendar week with the same condition append zero new INBOX entries.
Output
- INBOX.md entries appended (one per breached scope|kind tuple, deduplicated within a week).
- Updated
cost_guard_seen.jsonrecording dedupe keys. - Stdout summary: counts of entries appended + skipped + already-seen.
Exit code is 0 in all expected cases (including all-zero budgets and stale data — both are explicit findings, not errors). Exit 2 on malformed CLI flags.
Examples
python -m claude.skills.cost_guard.cost_guard \
--fixtures claude/skills/cost-guard/tests/fixtures/breach/ \
--as-of 2026-04-28T12:00:00Z \
--inbox-dir /tmp/cg-test/ \
--seen-state /tmp/cg-test/seen.json
Expected: appends one cost_breach entry per breached app to /tmp/cg-test/INBOX.md. Re-running with identical args appends nothing.
04 同仓库更多 Skills
skill-creator
Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.
worktree-isolation
Creates an isolated git worktree.
test-runner
Runs the targeted test suite.
subagent-driven-dev
Meta toolkit for dispatching subagents.
security-review
Read-only security review of pending changes.
revenue-check
Reads production revenue dashboards.