fix(providers): read opencode config file during credential discovery#1290
Open
ericcurtin wants to merge 1 commit intoNVIDIA:mainfrom
Open
fix(providers): read opencode config file during credential discovery#1290ericcurtin wants to merge 1 commit intoNVIDIA:mainfrom
ericcurtin wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
The opencode provider only checked three environment variables (OPENCODE_API_KEY, OPENROUTER_API_KEY, OPENAI_API_KEY) when discovering existing credentials. opencode stores its API keys natively in $XDG_CONFIG_HOME/opencode/opencode.json under provider.<name>.options.apiKey, so users with a normal opencode installation but no env vars set always received the 'no credentials found' warning and the sandbox was created without any provider, causing the watch loop to hang. Extract per-provider API keys from the config file and inject them as <PROVIDER_UPPERCASE>_API_KEY credentials so the sandbox environment receives working credentials. Env vars continue to take priority. Adds five unit tests covering extraction, edge cases (keyless providers, empty keys, malformed JSON, missing provider section).
Author
|
I have read the DCO document and I hereby sign the DCO. |
Author
|
recheck |
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
openshell sandbox create -- opencodefalsely reported "No existing local credentials/config found for 'opencode'" even when the user had a working opencode installation, then hung waiting for a sandbox that was created without any provider credentials.Related Issue
N/A (reported via direct session)
Changes
OpencodeProvider::discover_existingnow reads$XDG_CONFIG_HOME/opencode/opencode.json(defaulting to~/.config/opencode/opencode.json) in addition to env varsprovider.<name>.options.apiKeyand surfaces them as<NAME_UPPERCASE>_API_KEYcredentials so they are injected into the sandbox environmentextract_credentials_from_opencode_configas a testable pure functionTesting
mise run pre-commitpassescargo test -p openshell-providers— 29 passed)Checklist