feat(budget): spend budgets with overview display and scriptable --check#562
Open
ozymandiashh wants to merge 1 commit into
Open
feat(budget): spend budgets with overview display and scriptable --check#562ozymandiashh wants to merge 1 commit into
ozymandiashh wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #561.
What this adds
A spend-budget feature, so codeburn does not just show where AI spend goes but lets you act on it: set a daily/weekly/monthly budget, see budget usage with a run-rate projection in
overview, and get a scriptable over-budget signal frombudget --check. There is no spend-budget feature today (context-budget.tsis the model context window, unrelated).How it surfaces
overviewshows one line under the totals when the period matches a configured cadence (today -> daily, last-7-days -> weekly, this-month -> monthly):green under 80%, amber from 80%, red at 100%+, with a linear run-rate projection for the in-progress period.
budget --checkprints each configured budget's status and exits 1 if any is over budget, so it composes into a shell prompt, pre-commit, or cron/CI step without codeburn shipping any cross-platform notification machinery:Design decisions
--checkexit code, not a notification daemon. That keeps the feature small and composable and leaves the choice of how to be notified to the user.currencysets andoverviewshows). Spend is summed in USD and converted once viaconvertCostbefore comparison, so the line reads in the same units the user typed.--provider,--project,--exclude). A global budget shown next to a filtered subset would read as falsely-green, so it is hidden rather than misleading.budget --checkuses the same date-range source asoverviewper cadence (daily ->today, weekly ->week, monthly ->month), so the spend window and the numbers agree between the two surfaces.overviewoutput and every other command are byte-for-byte identical. The feature is purely additive.Implementation
src/budget.ts(new): a purecomputeBudgetStatusreturning{ spent, budget, pct, projected, state }, whereprojected = spent * totalDays / elapsedDaysandstateisunder(<80%),warn(>=80%), orover(>=100%). No I/O, fully unit-tested.src/config.ts: a new optionalbudgetfield ({ daily?, weekly?, monthly? }, display-currency amounts).src/main.ts: thebudgetcommand (set with finite > 0 validation,--list,--remove,--checkthat aggregates current-period spend via the existing session pipeline) and the overview wiring that builds the budget status for the matching tier.src/overview.ts: the budget line inrenderOverview, colored by state, with the projection only while the period is in progress.Verification
tests/budget.test.ts): threshold boundaries, exact projection math, invalid-input guards.tests/cli-budget.test.ts, isolated HOME): set/list/remove; invalid amount exits 1;--checkexits 1 over and 0 under-or-none; the budget line is suppressed under filters;--checkandoverview -p weekreport the same weekly spend window.tests/overview.test.ts): the line appears with the right percent and projection when a budget is set, and is absent otherwise.npx vitest run tests/budget.test.ts tests/cli-budget.test.ts tests/overview.test.tspasses.npm testis green except the pre-existing locale-dependenttests/overview.test.tsseparator assertion.npx tsc --noEmitis clean. The offline build succeeds.codeburn budget --monthly 1thenoverview -p monthrendersMonthly budget: <real spend> of €1.00 (...) projected ... by month end, andbudget --checkexits 1.Files
src/budget.ts(new),src/config.ts,src/main.ts,src/overview.tstests/budget.test.ts(new),tests/cli-budget.test.ts(new),tests/overview.test.ts