Skip to content

fix(plugin): resolve the live key from opencode's credential store - #6

Merged
JeffreyJYZ merged 2 commits into
mainfrom
fix/plugin-key-candidates
Nov 6, 2026
Merged

JeffreyJYZ merged 2 commits into
mainfrom
fix/plugin-key-candidates

Conversation

@jyzbot

@jyzbot jyzbot commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

What

The provider now finds the account's live API key instead of the one ~/.commandcode/auth.json keeps.

Why

Every request answered Invalid 'Authorization' header or token while inference on the same account worked. A re-connect through /connect writes the current key into opencode.db's credential table and leaves both auth.json files on the key it replaced:

source status
opencode.db credential, commandcode, active row works
opencode.db credential, commandcode, inactive row 401
~/.commandcode/auth.json 401

Changes

  • src/key.ts — candidateKeys() offers every key this machine can find, best first: CMD_API_KEY, store rows for commandcode/command-code (active, then newest; read with node:sqlite), opencode's legacy auth.json, the CLI's auth.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 passes keys: () => candidateKeys().
  • README.md — states the real order and the retry.
  • Version 0.5.22 → 0.5.23.

The store read is guarded: no store, a v1 store without the table, or a runtime without node:sqlite all fall through to the files.

Verification

  • bun test 246 pass / 0 fail, including new tests for store ordering, legacy-file order, CMD_API_KEY first, a refused key retried with the next candidate, and every candidate refused keeping the 401 and its message.
  • bun check no type errors, bun fmt --check clean, bunx biome lint clean (two pre-existing warnings in test/tui.test.ts), bun run build emits index.js.
  • Live: candidateKeys() on this machine returns the active store key first, then the two superseded ones.

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.
@vercel

vercel Bot commented Nov 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cmdcode-tools-site Ready Ready Preview Nov 6, 2026 3:09am UTC

@JeffreyJYZ
JeffreyJYZ merged commit 2443158 into main Nov 6, 2026
10 checks passed
@JeffreyJYZ
JeffreyJYZ deleted the fix/plugin-key-candidates branch November 6, 2026 03:10

This branch was successfully deployed

1 active deployment
Preview — 54d49658 Deployed Nov 6, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants