Skip to content

Conversation

@denkhaus
Copy link

Summary

This PR introduces support for custom Anthropic API endpoints by adding a centralized client creation utility that respects the ANTHROPIC_BASE_URL environment variable. This enables VC to work with Anthropic-compatible APIs, custom deployments, or alternative endpoints while maintaining backward compatibility.

Key Changes

New Utility Function

  • Added NewAnthropicClient() in internal/ai/utils.go that:
    • Creates an Anthropic client with standard API key authentication
    • Optionally uses ANTHROPIC_BASE_URL environment variable for custom endpoints
    • Provides a single point of configuration for all Anthropic client creation

Refactored Client Instantiation

Replaced direct anthropic.NewClient() calls with the new utility in:

  • internal/ai/supervisor.go - AI supervision functionality
  • internal/discovery/sdk/ai.go - AI discovery SDK
  • internal/executor/agent.go - Agent loop detection
  • internal/executor/executor.go - Auto-commit message generation
  • internal/repl/conversation_state.go - REPL conversation handling
  • internal/health/model_*_test.go - Test files for model cost/quality

Benefits

  1. Flexibility: Enables use with alternative Anthropic-compatible endpoints
  2. Maintainability: Single point of client configuration reduces code duplication
  3. Backward Compatibility: No breaking changes - works with default Anthropic API
  4. Testability: Easier to mock or override for testing

Usage

To use with a custom endpoint:

export ANTHROPIC_API_KEY=your-api-key
export ANTHROPIC_BASE_URL=https://your-custom-endpoint.com
./vc

If ANTHROPIC_BASE_URL is not set, the client will use the default Anthropic API endpoint.

Testing

  • All existing tests continue to pass without modification
  • Test files updated to use the new centralized client creation
  • No functional changes to existing behavior

This enhancement makes VC more adaptable to different deployment scenarios and enables integration with custom AI infrastructure while maintaining simplicity for standard use cases.

- Add NewAnthropicClient utility function in internal/ai/utils.go
- Support ANTHROPIC_BASE_URL environment variable for custom endpoints
- Replace direct client instantiation across all AI packages
- Reduce code duplication and improve maintainability

This enables VC to work with alternative Anthropic-compatible endpoints
by setting the ANTHROPIC_BASE_URL environment variable.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
reifying pushed a commit to reifying/vc that referenced this pull request Dec 22, 2025
- Added comprehensive tests for buildIterationContext() (both refiners)
- Added tests for serialization edge cases
- Added tests for deserializeAnalysis() error path
- Added tests for prompt construction (convergence and refinement)
- Added tests for truncateForPrompt() utility
- Added nil artifact error path tests for Refine() methods
- All tests are fixture-based and run without ANTHROPIC_API_KEY

Coverage improvements:
- analysis_refiner.go: 85.3% (buildIterationContext 0%->100%, truncateForPrompt 66.7%->100%, serializeAnalysis 72.5%->95%, deserializeAnalysis 0%->100%)
- assessment_refiner.go: 73.1% (buildConvergencePrompt 0%->100%, buildRefinementPrompt 0%->100%)
- Overall refiner coverage: 79.96% (exceeds 60% target)

Addresses vc-ckef acceptance criteria #1, steveyegge#4, steveyegge#5, steveyegge#6
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