You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything.
Technical Analysis
This PR adds graceful fallback support for Brave Search and Tavily API keys through multiple sources:
search-keys.json - New config file for search API keys
Direct environment variables - BRAVE_API_KEY and TAVILY_API_KEY
JSON comment stripping - Handles // and /* */ comments in configs
Code Quality Highlights
TokenManager.swift: The stripJSONComments() function correctly handles escape sequences inside strings (line 780-814), avoiding the classic bug of stripping comments that appear inside string literals. Thread safety is maintained via queue.sync wrapper.
Fallback chain is sensible: opencode.json → search-keys.json → environment variables gives users flexibility without breaking existing setups.
Shell scripts match Swift: The bash implementations in query-brave-search.sh and query-tavily-search.sh correctly mirror the Swift logic, including the same XDG path priority order.
Proper error handling: Uses isReadableFile(atPath:) check before reading (line 711) - a nice touch that prevents crashes on permission-denied scenarios.
Credential source tracking: The UI now shows exactly where the API key came from (opencode.json, search-keys.json, or Environment variable XXX) - much better for debugging auth issues than the previous hardcoded fallback.
Minor style fix: AntigravityProvider removes unnecessary parentheses in condition (line 466) - not a bug, just cleaner.
Incremental Changes (since last review)
Shell script temp file cleanup fix: Variables now initialized before trap registration, consolidated cleanup function prevents orphaned temp files
SearchAPIKeyLookupSource refactoring: Clean struct-based pattern for unified key lookup across config sources
Operator precedence verified: Swift's & has higher precedence than ==, so byte & 0x80 == 0 is semantically identical to (byte & 0x80) == 0
📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are.
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
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
opencode.jsonsearch config parsing even when it contains//or/* */commentssearch-keys.jsonand directBRAVE_API_KEY/TAVILY_API_KEYenvironment variables