Repository navigation
fix(plugin): resolve the live key from opencode's credential store - #6
Merged
Merged
Conversation
A re-connect through /connect writes the current key into opencode.db's `credential` table and leaves `~/.commandcode/auth.json` on the one it replaced, so the provider answered "Invalid 'Authorization' header or token" on an account whose inference was fine. `candidateKeys` now offers every key this machine can find — CMD_API_KEY, store rows for `commandcode`/`command-code` (active first, then newest), opencode's legacy auth.json, the CLI's auth.json, then the host's auth hook — and `resolveKey` takes the first. The transport walks the rest: a 401 moves to the next candidate and remembers the key that worked, so a stale host setting costs one request instead of the whole turn. The store is read with `node:sqlite`, guarded: no store, a v1 store without the table, or a runtime lacking it all fall through to the files.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
JeffreyJYZ
approved these changes
Nov 6, 2026
This branch was successfully deployed
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
The provider now finds the account's live API key instead of the one
~/.commandcode/auth.jsonkeeps.Why
Every request answered
Invalid 'Authorization' header or tokenwhile inference on the same account worked. A re-connect through/connectwrites the current key intoopencode.db'scredentialtable and leaves bothauth.jsonfiles on the key it replaced:opencode.dbcredential,commandcode, active rowopencode.dbcredential,commandcode, inactive row~/.commandcode/auth.jsonChanges
src/key.ts—candidateKeys()offers every key this machine can find, best first:CMD_API_KEY, store rows forcommandcode/command-code(active, then newest; read withnode:sqlite), opencode's legacyauth.json, the CLI'sauth.json, then the host's auth hook.resolveKey()takes the first, and keeps its signature.src/provider/index.ts— the transport walks the remaining candidates: a 401 moves to the next key and the key that worked is remembered, so a stale host setting costs one request instead of the turn. Only 401 rotates; 429/5xx stay the same rejection for every key.src/v2.ts— the aisdk hook passeskeys: () => candidateKeys().README.md— states the real order and the retry.The store read is guarded: no store, a v1 store without the table, or a runtime without
node:sqliteall fall through to the files.Verification
bun test246 pass / 0 fail, including new tests for store ordering, legacy-file order,CMD_API_KEYfirst, a refused key retried with the next candidate, and every candidate refused keeping the 401 and its message.bun checkno type errors,bun fmt --checkclean,bunx biome lintclean (two pre-existing warnings intest/tui.test.ts),bun run buildemitsindex.js.candidateKeys()on this machine returns the active store key first, then the two superseded ones.