Skip to content

feat: proxy auto-discovery for OpenCode + init proxy-route injection#13

Merged
alderpath merged 1 commit into
masterfrom
proxy-auto-discover
Jun 16, 2026
Merged

feat: proxy auto-discovery for OpenCode + init proxy-route injection#13
alderpath merged 1 commit into
masterfrom
proxy-auto-discover

Conversation

@alderpath

Copy link
Copy Markdown
Contributor

Problem

Setting up the Reliary proxy for all OpenCode providers required manually changing baseURL per provider and maintaining proxy-routes.json. Adding a new provider meant more manual editing. High friction.

Solution

Auto-discovery in routes.rs: The proxy now scans 5 agent configs on unknown API key:

  1. proxy-routes.json (explicit user override, highest priority)
  2. OpenCode opencode.json providers
  3. Claude Code ~/.claude.json
  4. Cline config
  5. Pi ~/.pi/agent/models.json
  6. Environment variables (fallback)

When a provider sends a request through the proxy with its API key, the proxy auto-discovers the real upstream URL by scanning these configs. New provider = zero config.

Init proxy-route injection: reliary-agent init now asks:

Route all OpenCode providers through Reliary proxy? [Y/n]

If yes: mutates all provider baseURLs to http://127.0.0.1:9090/v1, generates proxy-routes.json mapping apiKey → original upstream URL.

Clean uninstall: reliary-agent uninstall restores original baseURLs from the backup in proxy-routes.json.

Key design decisions

  • init asks Y/N before mutating -- no silent config changes
  • Backup metadata stored in proxy-routes.json as __backups key -- single file, no separate backup
  • normalize_url() handles both OpenAI (/chat/completions) and Anthropic (/v1/messages) URL patterns

Tests

  • All 85 existing tests pass (0 regression)
  • Routes module compiles with zero warnings

routes.rs:
- Added scan_opencode_configs() — discovers upstream by scanning opencode.json providers
- Added scan_claude_config() — discovers upstream from ~/.claude.json
- Added scan_cline_config() — discovers upstream from Cline config
- Added normalize_url() — ensures proper /chat/completions or /v1/messages suffix
- Auto-discovery cascade: proxy-routes.json > OpenCode > Claude > Cline > Pi > env vars

init.rs:
- inject_opencode_proxy_routes() — reads opencode.json, mutates provider baseURLs
  to http://127.0.0.1:9090/v1, generates proxy-routes.json
- restore_opencode_proxy_routes() — restores original baseURLs on uninstall
- Prompt asks user Y/N before mutating config
@alderpath alderpath merged commit d5b2357 into master Jun 16, 2026
4 checks passed
@alderpath alderpath deleted the proxy-auto-discover branch June 16, 2026 21:05
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.

1 participant