codeburn icon indicating copy to clipboard operation
codeburn copied to clipboard

feat(cli): add burn guardrails

Open ozymandiashh opened this issue 6 months ago • 1 comments

Summary

CodeBurn already gives strong post-hoc cost visibility, but there was no small command for catching runaway spend while it is happening. This adds codeburn guard, a one-shot local guardrail check that flags sessions or local-hour windows once they reach configurable USD thresholds.

What changed

  • add codeburn guard with default thresholds of $3 per session and $10 per local hour
  • support existing report-style filters: --period, --from, --to, --provider, --project, and --exclude
  • add --json for scripts and --fail-on-alert for cron/CI workflows
  • aggregate hourly spend from parsed assistant calls using local timezone bucketing
  • sort alerts by threshold severity so the most urgent guardrail breach appears first
  • document the command and add an Unreleased changelog entry

Why one-shot first

A daemon/watch mode could come later, but a one-shot command keeps this first version small and composable. Users can run it manually, from cron, or inside shell scripts without introducing background process state or notification preferences in this PR.

Example

codeburn guard
codeburn guard -p week --max-session-usd 5 --max-hourly-usd 20
codeburn guard --json --fail-on-alert

Validation

  • npx vitest run tests/guard.test.ts
  • npx vitest run
  • npm run build
  • node dist/cli.js guard --help
  • node dist/cli.js guard --from 2999-01-01 --to 2999-01-02 --json

Note: full npx tsc --noEmit is currently blocked on origin/main by existing src/providers/copilot.ts type errors; this branch does not touch that provider.

ozymandiashh avatar May 05 '26 22:05 ozymandiashh

Validation run on macOS arm64 with private details omitted. This is behavior proof, not just build proof.

What was checked:

  • guard was run with deliberately low thresholds so real local usage produced alert output.
  • The JSON alert list contained both session and hour alert types, proving both guardrail paths can fire.
  • A future empty date range (2999-01-01 to 2999-01-02) returned zero projects/sessions/calls and an empty alerts array, proving the no-data path does not fabricate alerts.

Commands:

  • npx vitest run tests/guard.test.ts - 7/7 tests passed.
  • npx tsx src/cli.ts guard -p today --provider claude --max-session-usd 1 --max-hourly-usd 1 --json - JSON parsed and contained both alert classes.
  • npx tsx src/cli.ts guard --from 2999-01-01 --to 2999-01-02 --json - JSON parsed with empty totals/alerts.

No project names, prompts, paths, session IDs, raw costs, usage totals, or private product details are included here.

ozymandiashh avatar May 17 '26 13:05 ozymandiashh

Closing this — it's an unsolicited feature PR that's gone stale, and per CONTRIBUTING these should start from an issue with maintainer buy-in. Cleaning up my open-PR queue; happy to revisit via an issue if there's interest.

ozymandiashh avatar Jun 21 '26 13:06 ozymandiashh