feat: zero-config provider auto-detection + hosted LiteLLM gateway#42
Merged
Merged
Conversation
…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
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.
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.jsonalways overrides auto-detection.Key changes:
autoDetectProvider()+listDetectedProviders()in providers.js — pure, synchronous, read-onlyactiveProvider()falls back to env-based auto-detection when no config file existsLITELLM_BASE_URL+LITELLM_API_KEYenv vars, uses standard claude-* model names (no admin access needed)ANTHROPIC_BASE_URLproxy detection (non-default URL treated as proxy)emitGatewayConfig()skips file emit for hosted gatewaysforge initreports detected providerforge config show/setupdisplay auto-detection state and env var scanforge_provider_statusMCP tool (feat(substrate): bidirectional verified reconcile + docs/YAML polish #15) for AI agent discoverycheckProvideradded toforge doctorhealth checksChecklist
npm testpasses (Node 18/20/22)npm run checkpasses (Biome lint + format)feat:/fix:/docs:…)CHANGELOG.mdupdated under## [Unreleased]forge substrate,forge impact, router/gate, or MCP substrate toolsRisk & rollback
.forge/providers.jsonexists)Extra checks (tick if applicable)
Generated by Claude Code