feat(model): per-model context limits and pricing for the usage display - #89
Open
justin-carper wants to merge 4 commits into
Open
feat(model): per-model context limits and pricing for the usage display#89justin-carper wants to merge 4 commits into
justin-carper wants to merge 4 commits 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.
What
Populate Cursor models with per-model context window limits, per-token pricing, and output limits so opencode's TUI session header shows accurate tokens / context window % / cost.
Why
All Cursor models previously reported
limit.context: 200_000andcost: 0. The TUI session header rendered no context-window percentage and no dollar cost. Verified live (opencode 1.18.11):/config/providersreturned"limit":{"context":0,"output":0}for all 33 models — the config channel (provider.<id>.models, built bytoOpencodeModels()) emitted nolimit/costat all, andprovider.models()hook output is discarded for providers absent from models.dev.Changes
src/model-limits.ts(new): shared per-model maps + longest-prefix resolvers for context limits (Cursor docs default windows, not Max Mode 1M), pricing (cursor.com/docs/models-and-pricing, USD per million tokens), and output limits. Imports nothing — avoids a circular import withmodel-discovery.ts.src/model-discovery.ts:OpencodeModelConfigEntrynow carrieslimitandcost;toOpencodeModels()emits them on the config channel opencode actually reads. Cost uses the flat snake_casecache_read/cache_writekeys the config schema requires (not theModelV2nestedcacheshape). Compile-time guards (_costKeyGuard/_limitKeyGuard) fail typecheck if the emitted keys drift from the accepted schema.src/plugin/model-v2.ts:buildModelV2Map()now imports the resolvers instead of duplicating them; stale doc comment fixed.not.toHaveProperty("cache")shape trap guard), 7 new model-v2 tests. 405/405 passing, typecheck + build clean.Verified end-to-end
Isolated opencode 1.18.11 server (published plugin excluded via
XDG_CONFIG_HOMEredirect) —/config/providers:Baseline before this branch:
context: 0for all 33.Notes
provider.cursor.models.<id>override in config still wins over these defaults atplugin/index.ts:211and would keepcontext: 0for that model.