fix(setup): detect providers from auth.json instead of broken HTTP probe#3
Merged
JohnnyVicious merged 1 commit intomainfrom Apr 12, 2026
Merged
Conversation
4 tasks
cac4de7 to
6abe793
Compare
handleSetup tried to enumerate configured providers via the OpenCode HTTP server, but neither endpoint actually returns what we want: * GET /provider returns a TypeScript schema dump (literally type signatures, not JSON data) — `JSON.parse` fails silently inside the `try`/`catch` and providers ends up as []. This is the bug observed by /opencode:setup always reporting `providers: []` even when `opencode providers list` shows credentials. * GET /provider/auth returns the *available* auth methods per provider (oauth/api/etc with prompts), not the user's *configured* credentials. The actual source of truth is OpenCode's auth.json — the same file `opencode providers list` reads — at: - $XDG_DATA_HOME/opencode/auth.json - ~/Library/Application Support/opencode/auth.json (macOS) - %APPDATA%/opencode/auth.json (Windows) - ~/.local/share/opencode/auth.json (Linux/BSD fallback) This change adds `findOpencodeAuthFile` and `getConfiguredProviders` to lib/process.mjs and rewires `handleSetup` to call them. Provider detection no longer requires the OpenCode server to be running. Verified end-to-end: `node opencode-companion.mjs setup --json` now reports `"providers": ["openrouter"]` for a workstation with OpenRouter configured via `opencode providers login`. Apache 2.0 §4(b) modification notices added to both modified files.
6abe793 to
71b4f2e
Compare
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.
Summary
handleSetupenumerated providers via the OpenCode HTTP server, but neither endpoint returns the user's configured credentials:GET /providerreturns a TypeScript schema dump (literal type signatures, not JSON).JSON.parsefails silently inside thetry/catch, soprovidersalways ends up as[]. This is the bug behind/opencode:setupreporting"providers": []even whenopencode providers listshows credentials.GET /provider/authreturns the available auth methods per provider (oauth / api / prompts), not the user's configured credentials.The actual source of truth is OpenCode's
auth.json— the same fileopencode providers listreads.Changes
lib/process.mjshelpers:findOpencodeAuthFile()(tries$XDG_DATA_HOME, the macOS / Windows defaults, then~/.local/share/opencode/auth.json) andgetConfiguredProviders()(parses the JSON object and returns its top-level keys).handleSetupcallsgetConfiguredProviders()instead of the broken HTTP probe. Provider detection no longer requires the OpenCode server to be running.Test plan
node --checkpasses foropencode-companion.mjsandlib/process.mjsopencode providers login:~/Library/Application Support/opencode/auth.jsonis found whenXDG_DATA_HOMEis unset%APPDATA%/opencode/auth.jsonis foundauth.jsondeleted,setup --jsonreports"providers": [](regression check, no crash)Out of scope
handleCancel(line 487) also hardcodeshttp://127.0.0.1:4096. Same bug class but affects a different code path — should be a separate PR.