feat: add free model resolution#21907
Open
caretak3r wants to merge 1 commit intoanomalyco:devfrom
Open
Conversation
887c095 to
cd5548b
Compare
95d635f to
2bb71d0
Compare
Author
|
@rekram1-node @adamdotdevin Anything for me to do here, looks like other changes were pushed here? Thank you! |
bc990dd to
0e22efe
Compare
Resolves --model free to a random free opencode model before prompting. Supports --variant any for random variant selection. Closes anomalyco#21863
7a6e936 to
ae63741
Compare
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #21863
Type of change
What does this PR do?
Adds
Provider.resolveSelection()which resolves--model freeto a random free opencode-provider model. With--variant any, a random variant is chosen from that model's available variants (and falls through cleanly when the model has none).Selection logic (
packages/opencode/src/provider/provider.ts:1742-1780):The
providerID === opencodegate excludes OpenRouter:freemodels. TheisListedgate excludes any opencode-provider model that happens to have zero declared cost but isn't actually meant to be in the free pool (e.g.gpt-5-nano).Integration points:
cli/cmd/run.ts— resolves before prompting / sending commandcli/cmd/tui/thread.ts— resolves before launching the TUIcli/cmd/tui/app.tsx+context/args.tsx— store the resolved variant in local stateHow did you verify your code works?
Workspace gates (run locally on this branch, all green):
bun turbo typecheckbun test(the 3 affected files)Named tests covering this feature —
In
packages/opencode/test/provider/provider.test.ts:resolveModel picks only valid opencode free listings— proves the filter admits only(providerID = opencode) ∩ (cost = 0) ∩ (id = big-pickle | endsWith("-free")), and explicitly rejectsgpt-5-nanoand OpenRouterfree-router.resolveSelection picks a variant from the chosen free model—Math.randomis mocked to land on a model with variants; the picked variant comes from that model's own variant set.resolveSelection keeps explicit variants unchanged—--variant max(literal) is preserved verbatim, not re-randomized.resolveSelection falls back to no variant when the chosen free model has none— graceful degrade for models that have no variants.In
packages/opencode/test/cli/cmd/run.test.ts:resolves free before promptingpasses the resolved model to command sessionspasses the resolved any variant to sessionsIn
packages/opencode/test/cli/tui/thread.test.ts:resolves the free model alias before launching the tuipasses the resolved any variant before launching the tuiNegative cases verified —
--model freeexcludes::free/-freealiases (different providerID)opencode/gpt-5-nano(zero cost but not inisListedwhitelist)cost.input,cost.output,cost.cache.read,cost.cache.write, orexperimentalOver200KManual sanity — Explicit model passthrough (
--model opencode/big-pickle) is unchanged becauseresolveSelectionshort-circuits when the model is not literally"free".--variant anywithout--model freeis also short-circuited.Checklist