feat: incorporation of Llmfit tool in to cli
What is this MR?
This merge request introduces a comprehensive integration of the LLMFit tool into corpus-client-cli. It expands the CLI with capabilities for model recommendation, download, and execution, while maintaining a modular and self-contained design.
What does it do?
- Enables system-aware LLM model recommendations
- Supports model download and lifecycle management
- Allows users to run downloaded LLMs locally
- Adds self-healing dependency handling for missing binaries
- Extends CLI functionality with new commands
- Introduces persistent state for model selection
- Provides full test coverage and documentation
Changes Included
1. New Core Logic Module (src/corpus_client_cli/llmfit.py)
-
Command Bridge
- Implemented
run_llmfit_commandto executellmfitvia system binary or fallback touv tool run
- Implemented
-
System Analysis
- Added
get_system_infoto detect CPU, GPU, and RAM for model filtering
- Added
-
Model Discovery
- Implemented
get_recommended_modelsto fetch and parse model metadata from backend
- Implemented
-
Download & Lifecycle
- Added
download_modelwith GGUF resolution and storage handling
- Added
-
LLM Execution
- Added
llmfit_run_commandto manage symlinks and run models
- Added
-
Dependency Self-Healing
- Automatically downloads required
llama-clibinaries if missing
- Automatically downloads required
2. State & Storage Updates (src/corpus_client_cli/state.py)
- Defined
MODELS_DIR(~/.corpus-cli/models) for centralized model storage - Extended
Stateclass to persist:llmfit_choicellmfit_resolved_id
3. CLI Command Registration (src/corpus_client_cli/cli.py)
- Added new commands:
-
corpus-client llm manage→ Analyze system and list compatible models -
corpus-client llm run→ Execute a selected model
-
- Enhanced
clearcommand:- Recursively deletes the
models/directory to reset local cache
- Recursively deletes the
4. Testing Infrastructure (tests/test_llmfit.py)
- Built comprehensive test suite using
unittest.mock - Simulated:
- Hardware environments
- LLMFit backend JSON responses
- Added fixtures:
mock_binariesmock_llmfit_recommend
- Covered:
- Model recommendation flow
- Download and resolution logic
- Execution and symlink behavior
5. Documentation
- Added usage documentation under
docs/ - Includes:
- System analysis instructions
- Model selection guidance
- Running LLMs locally
Acceptance Criteria
-
Users can run corpus-client llmfitto see recommended models -
Users can download models with proper GGUF resolution -
Users can execute models via corpus-client llm-run -
CLI handles missing dependencies automatically -
No regressions in existing CLI functionality -
All tests pass successfully -
Documentation is clear and complete
Test Coverage
- Unit tests cover:
- System detection logic
- Model recommendation parsing
- Download and file resolution
- Execution flow and symlink handling
- Uses mocks to isolate:
- Filesystem interactions
- External binary dependencies
- Backend API responses
- Ensures deterministic and environment-independent test execution
Design Notes
This integration is intentionally modular:
- All LLM-specific logic is isolated within
llmfit.py - Core CLI remains clean and maintainable
- External dependencies are abstracted and handled gracefully
Closes: #42 (closed)
Edited by Bhaskar Battula