Skip to content

feat: zero-config provider auto-detection + hosted LiteLLM gateway#42

Merged
CodeWithJuber merged 3 commits into
masterfrom
claude/forge-work-system-setup-p26ka5
Jul 8, 2026
Merged

feat: zero-config provider auto-detection + hosted LiteLLM gateway#42
CodeWithJuber merged 3 commits into
masterfrom
claude/forge-work-system-setup-p26ka5

Conversation

@CodeWithJuber

Copy link
Copy Markdown
Owner

What & why

Zero-config provider auto-detection from environment variables, so the forge work system activates automatically in any AI chat session without manual forge config provider <name>.

Problem: After PR #41, providers existed but required manual switching. The litellm provider was hardcoded to localhost:4000 — no support for hosted gateways where the user only has a URL + API key and no admin access.

Solution: autoDetectProvider() inspects env vars and picks the best provider automatically. Priority chain: LITELLM_BASE_URL > ANTHROPIC_BASE_URL (proxy) > OPENROUTER_API_KEY > ANTHROPIC_API_KEY. Explicit .forge/providers.json always overrides auto-detection.

Key changes:

  • autoDetectProvider() + listDetectedProviders() in providers.js — pure, synchronous, read-only
  • activeProvider() falls back to env-based auto-detection when no config file exists
  • Hosted LiteLLM support: LITELLM_BASE_URL + LITELLM_API_KEY env vars, uses standard claude-* model names (no admin access needed)
  • ANTHROPIC_BASE_URL proxy detection (non-default URL treated as proxy)
  • emitGatewayConfig() skips file emit for hosted gateways
  • forge init reports detected provider
  • forge config show/setup display auto-detection state and env var scan
  • forge_provider_status MCP tool (feat(substrate): bidirectional verified reconcile + docs/YAML polish #15) for AI agent discovery
  • checkProvider added to forge doctor health checks
  • 30 provider tests (471 total pass, 0 fail)

Checklist

  • npm test passes (Node 18/20/22)
  • npm run check passes (Biome lint + format)
  • New public functions have a test
  • Conventional commit message (feat:/fix:/docs: …)
  • CHANGELOG.md updated under ## [Unreleased]
  • No new runtime dependency (dev deps ok)
  • Substrate/docs updated if this changes forge substrate, forge impact, router/gate, or MCP substrate tools

Risk & rollback

  • Risk level: low
  • Rollback plan: Revert the commit — auto-detection is additive (existing explicit configs are unaffected, new code paths only activate when no .forge/providers.json exists)

Extra checks (tick if applicable)

  • Input validated at boundaries; errors handled (no swallowing)
  • Logs contain no secrets/PII
  • If AI-assisted: I understand it, verified the package APIs, and it has tests

Generated by Claude Code

claude added 3 commits July 8, 2026 13:40
…pport

Auto-detect the best API provider from environment variables with no manual
configuration required. Priority chain: LITELLM_BASE_URL > ANTHROPIC_BASE_URL
(proxy) > OPENROUTER_API_KEY > ANTHROPIC_API_KEY. Explicit .forge/providers.json
always overrides auto-detection.

- Add autoDetectProvider() and listDetectedProviders() to providers.js
- Modify activeProvider() to fall back to env-based auto-detection
- Support hosted LiteLLM gateways (LITELLM_BASE_URL + LITELLM_API_KEY) where
  users have no admin access — uses standard claude-* model names
- Detect ANTHROPIC_BASE_URL proxy setups automatically
- Enhanced providerStatus() with auto-detection source and env var scan
- emitGatewayConfig() skips file emit for hosted gateways (user can't modify)
- forge init reports detected provider
- forge config show/setup display auto-detection state and env scan
- Add forge_provider_status MCP tool for AI agent discovery
- Add checkProvider to forge doctor health checks
- 30 provider tests covering all cases (471 total pass, 0 fail)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019PXuKmJp92Gdo2FudNjSx2
Apply biome auto-fixes: import ordering (dash.js, cost_report.js),
catch block formatting (cost_report.js), string concatenation to
template literals (cli.js, dash.html), optional chaining (cli.js),
and import/code reorganization across modified files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019PXuKmJp92Gdo2FudNjSx2
Narrow union type in cli.js init handler with 'in' checks so TS can
verify .added/.path access. Convert remaining string concatenations
to template literals in cli.js and dash.html. Use optional chaining
for r.findings?.length.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019PXuKmJp92Gdo2FudNjSx2
@CodeWithJuber CodeWithJuber marked this pull request as ready for review July 8, 2026 14:03
@CodeWithJuber CodeWithJuber merged commit cb01420 into master Jul 8, 2026
10 checks passed
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