feat: auto-sync models from CommandCode API at startup - #1
Conversation
- Fetch model list from CommandCode API on plugin config hook - Merge with local models.json (API provides context_length, local provides curated cost/tier/reasoning) - Persist merged result back to models.json for offline fallback - Treat empty API response as failure to avoid wiping local models - Add idempotency to saveModels (only write when content changed) - Add new models and fix context sizes in models.json - Add unit tests for mergeModels (pure) and integration tests using existing mockFetch helpers
|
Nice 👍 |
- Switch from disk write to in-memory merge; sync updates no longer
persist between startups
- Add config-file opt-out at
~/.config/opencode/commandcode-go-opencode-provider.json
with `disableModelSync: true` to skip the API fetch entirely
- loadModels: throw actionable error on missing/corrupt bundled
models.json ("please reinstall commandcode-go-opencode-provider",
original error chained via Error.cause)
- Tests: add withFakeConfig / withMissingModels / withCorruptModels
helpers and structural assertions for bundled, opt-out, and
load-error paths
- README: document the opt-out workflow and bundled-list refresh
via `bun run sync`
|
Really like this direction — auto-syncing from the API is the right fix for the staleness. I built a small patch on top of this branch with three proposed tweaks and opened it as #5 (stacked on these commits, so it's just the one extra commit to review):
All your existing tests pass (I reworked the "missing key" one to assert the keyless fetch path, and added a name test) — 87 pass, typecheck clean. Happy to fold these into your branch directly if you'd prefer that over a stacked PR — whatever's easiest for you and @brent-weatherall. |
Auto-syncs the model list from the CommandCode API on opencode startup, so context sizes and new models are kept up to date without manual intervention. The local
models.jsonis still bundled with the plugin as an offline fallback.Motivation
The local
models.jsonwas getting stale — context sizes were wrong (e.g.xiaomi/mimo-v2.5-prowas 128K instead of 1M) and new models required a manual sync to be added.Changes
plugin.ts: config hook now fetches/provider/v1/modelson startup (5s timeout, AbortController)plugin.ts: merges API response with localmodels.json— API providescontext_length, local provides curatedcost/tier/reasoningplugin.ts: persists merged result back tomodels.jsonfor offline useplugin.ts: idempotentsaveModels(skips write when content unchanged)plugin.ts: empty API responses are treated as failure to avoid wiping local modelsmodels.json: 6 new models added, 4 context sizes correctedREADME.md: documents auto-sync behaviortests/unit/plugin.test.ts: 9 new tests (6 pure unit tests formergeModels, 3 integration tests using existingmockFetch/mockFetchTrackhelpers)Test plan
bun test— 82 pass, 0 fail (was 73)bun run typecheck— cleanCOMMANDCODE_API_KEYset, verifymodels.jsontimestamp updates and new context sizes take effectCompatibility
models.jsonscripts/sync-models.tsis kept for users who want explicit controlNotes for reviewer
mergeModelsandModelEntryare exported to enable unit testingsaveModelsis wrapped in try/catch with silent failure (per existing project pattern)dataarray)