Skip to content

feat: user-controllable token/cost budgets with tight enforcement + a…#142

Merged
chauncygu merged 1 commit into
mainfrom
v3.05.82
Jun 5, 2026
Merged

feat: user-controllable token/cost budgets with tight enforcement + a…#142
chauncygu merged 1 commit into
mainfrom
v3.05.82

Conversation

@chauncygu
Copy link
Copy Markdown
Contributor

…uto-save

Adds a friendly UX layer on top of the existing quota.py engine so users can cap spend per session or per day, in tokens or USD, and never lose work when a cap is hit.

  • /budget command (commands/core.py): view usage vs each cap as colored bars + %, or set one — /budget $5 (cost), /budget 200k (tokens, parses 200k/1.5m), /budget daily $20, /budget clear. --budget $5 / --budget 200k startup flag.
  • One budget per scope: a new cap REPLACES the other unit for that scope, so switching tokens<->USD just works and no stale cap silently keeps blocking.
  • Tight enforcement (no surprise overshoot): check_quota projects the next request's input and stops BEFORE the call if it would cross the cap; quota.output_room clamps that call's max_tokens to the remaining headroom — a tool-heavy turn can't blow 40k->49k past the budget anymore.
  • Proximity warnings at >=80% (yellow) / >=95% (red) end-of-turn.
  • On hit: agent yields QuotaPause (carrying which cap broke: key/scope/unit/ limit); the REPL auto-saves the session (session_latest.json + daily backup, the path /resume reads) and prints next steps. The "raise it" hint matches the breached unit (token cap -> /budget 40k, daily cost -> /budget daily $40).

quota.py: parse_budget / fmt_amount / usage_vs_limits / warnings / output_room, projected check_quota, QuotaExceeded carries the breached cap. agent.py: QuotaPause + projection + output clamp. cheetahclaws.py: /budget registration, QuotaPause handling, --budget, near-limit warnings. 42-case tests/test_budget.py (isolated quota dir). Docs: README, features.md, reference.md, news.md. Defaults stay unlimited (interactive); daemon serve-mode guardrails unchanged.

…uto-save

Adds a friendly UX layer on top of the existing quota.py engine so users can
cap spend per session or per day, in tokens or USD, and never lose work when a
cap is hit.

- /budget command (commands/core.py): view usage vs each cap as colored bars +
  %, or set one — /budget $5 (cost), /budget 200k (tokens, parses 200k/1.5m),
  /budget daily $20, /budget clear. --budget $5 / --budget 200k startup flag.
- One budget per scope: a new cap REPLACES the other unit for that scope, so
  switching tokens<->USD just works and no stale cap silently keeps blocking.
- Tight enforcement (no surprise overshoot): check_quota projects the next
  request's input and stops BEFORE the call if it would cross the cap;
  quota.output_room clamps that call's max_tokens to the remaining headroom — a
  tool-heavy turn can't blow 40k->49k past the budget anymore.
- Proximity warnings at >=80% (yellow) / >=95% (red) end-of-turn.
- On hit: agent yields QuotaPause (carrying which cap broke: key/scope/unit/
  limit); the REPL auto-saves the session (session_latest.json + daily backup,
  the path /resume reads) and prints next steps. The "raise it" hint matches the
  breached unit (token cap -> /budget 40k, daily cost -> /budget daily $40).

quota.py: parse_budget / fmt_amount / usage_vs_limits / warnings / output_room,
projected check_quota, QuotaExceeded carries the breached cap. agent.py:
QuotaPause + projection + output clamp. cheetahclaws.py: /budget registration,
QuotaPause handling, --budget, near-limit warnings. 42-case tests/test_budget.py
(isolated quota dir). Docs: README, features.md, reference.md, news.md.
Defaults stay unlimited (interactive); daemon serve-mode guardrails unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chauncygu chauncygu merged commit 99a3b4a into main Jun 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant