Skip to content

Conversation

@tnm
Copy link
Contributor

@tnm tnm commented Jan 5, 2026

Summary

  • OllamaClient consolidation: Extract duplicated OllamaClient from 6 locations into single src/kit/ollama_client.py with context manager support and session injection
  • LLM client factory: New src/kit/llm_client_factory.py with centralized factory functions for all LLM providers (OpenAI, Anthropic, Google, Ollama)
  • BaseReviewer extraction: New src/kit/pr_review/base_reviewer.py base class with shared GitHub API and caching functionality; PRReviewer and AgenticPRReviewer now inherit from it

Total reduction: ~450 lines of duplicate code. All external APIs remain unchanged.

Changes

File Change
src/kit/ollama_client.py NEW - Unified OllamaClient
src/kit/llm_client_factory.py NEW - Factory functions for LLM clients
src/kit/pr_review/base_reviewer.py NEW - Base class for reviewers
src/kit/pr_review/reviewer.py Inherits from BaseReviewer
src/kit/pr_review/agentic_reviewer.py Inherits from BaseReviewer
src/kit/pr_review/local_reviewer.py Uses llm_client_factory
src/kit/pr_review/summarizer.py Uses llm_client_factory
src/kit/pr_review/commit_generator.py Uses llm_client_factory
src/kit/summaries.py Uses llm_client_factory
tests/test_ollama_client.py NEW - 8 tests
tests/test_llm_client_factory.py NEW - 15 tests
tests/test_base_reviewer.py NEW - 14 tests

Test plan

  • All existing tests pass (1156 tests)
  • 37 new unit tests for new modules
  • Manual testing of imports and instantiation
  • Verified CLI commands work (kit review --help, etc.)

tnm added 6 commits January 5, 2026 15:34
Addresses critical and high-priority code duplication:

1. **OllamaClient consolidation** (Critical)
   - Extract duplicated OllamaClient from 6 locations into `src/kit/ollama_client.py`
   - Single implementation with context manager support and session injection
   - Eliminates ~150 lines of duplicate code

2. **LLM client factory** (High)
   - New `src/kit/llm_client_factory.py` with centralized factory functions
   - `create_openai_client`, `create_anthropic_client`, `create_google_client`, `create_ollama_client`
   - `create_client_from_config` for summaries module
   - `create_client_from_review_config` for PR review modules
   - Eliminates duplicated initialization logic across 6 files

3. **BaseReviewer extraction** (High)
   - New `src/kit/pr_review/base_reviewer.py` with shared functionality
   - PRReviewer and AgenticPRReviewer now inherit from BaseReviewer
   - Shared methods: `parse_pr_url`, `get_pr_details`, `get_pr_files`, `get_pr_diff`, `get_repo_for_analysis`
   - Eliminates ~200 lines of duplicate code between reviewers

All external APIs remain unchanged. Total reduction: ~450 lines of duplicate code.

Tests: 37 new unit tests added across 3 new test files.
- Remove model validation checks from commit, review, and summarize commands
  (models change frequently, let the API return errors for invalid ones)
- Fix provider switch: update llm.provider and llm_provider when switching
- Fix model override: update llm_model convenience accessor
@tnm tnm merged commit 816eaf7 into main Jan 6, 2026
2 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