feat(budget): model-aware startup context budget for profiles#75
Merged
Conversation
Add a model-aware "startup budget" check so a profile's always-on footprint (skill frontmatter + MCP tool schemas) is warned about when it exceeds 50% of the model's context window — a ~128K ceiling on a 256K model, leaving the other half free for the conversation. - lib/token-budget.ts: pure, tested math — MODEL_CONTEXT_WINDOWS map, resolveContextWindow (profile contextWindow/model → CUE_CONTEXT_WINDOW /CUE_MODEL env → 256K default), estimateMcpTokens, computeContextBudget, formatContextBudgetWarning (silent <80% budget, 🟡 near, 🔴 over). - profiles: optional `model` / `contextWindow` fields (schema.json + _types.ts), resolved leaf-wins through inheritance in profile-loader. core declares contextWindow: 256000 as the fan-out baseline. - cue launch: budget warning in the startup banner (real resolved skill + MCP token data). - cue profile suggest: new "Context budget" section auditing every profile; --model / --context / --load-factor / --no-budget flags. - docs/agent-context-budget.md: documents the budget + flags. - token-budget.test.ts: 20 new tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwQNpDsSR466euk2d1McHV
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.
What
Adds a model-aware startup context budget to cue profiles. A profile's always-on footprint — skill frontmatter (loaded into the skill router on every message) + MCP tool schemas (one set per connected server) — is paid before the user types anything. This change warns when that load exceeds 50% of the model's context window, leaving the other half as working headroom.
For a 256K model that's a ~128K startup ceiling.
Why
The existing token budget (
lib/token-budget.ts+ the launch banner) only counted skill frontmatter with flat 🟢🟡🟠🔴 thresholds (5K/10K/15K) — it ignored MCP cost and had no model/context-window awareness. There was no signal that a profile's skills + MCPs were eating into the half of the window you want free for the actual task.How
cue can't auto-detect the main-session model (it's a per-launch
/modelchoice), so the window is resolved from a declared/configured source:resolveContextWindowprecedence: profilecontextWindow→ profilemodel(viaMODEL_CONTEXT_WINDOWS) → envCUE_CONTEXT_WINDOW→ envCUE_MODEL→DEFAULT_CONTEXT_WINDOW(256K).src/lib/token-budget.ts— pure, unit-tested math:MODEL_CONTEXT_WINDOWS,resolveContextWindow,estimateMcpTokens(MCP_TOKENS_PER_SERVERdefault 1500, overrideCUE_MCP_TOKENS_PER_SERVER),computeContextBudget,formatContextBudgetWarning(silent <80% of budget, 🟡 near, 🔴 over).model/contextWindowfields (schema.json+_types.ts), resolved leaf-wins through inheritance and composites inprofile-loader.ts.coredeclarescontextWindow: 256000as the fan-out baseline.cue launch— budget warning in the startup banner, using real resolved skill + MCP token data.cue profile suggest— new Context budget section auditing every profile; new flags--model <id>,--context <tokens>,--load-factor <0..1>,--no-budget.docs/agent-context-budget.md— documents the budget + flags.Example
Tests
src/lib/token-budget.test.ts— 20 new tests (window resolution precedence, MCP estimate, budget math at 256K→128K, warning bands).tscclean on touched files (one pre-existing unrelated error inpair-suggestions.ts); biome lint clean;cue validate coreschema-valid with the new field.Notes
resources/skillssubmodule isn't checked out, so skill-token measurement reads 0 and the audit counts MCPs only — it degrades gracefully (missing skills count as 0). On a real install with skills present, both are measured.🤖 Generated with Claude Code
https://claude.ai/code/session_01TwQNpDsSR466euk2d1McHV
Generated by Claude Code