5.7 KiB
5.7 KiB
Clover CLI Implementation Plan
Overview
This document outlines the implementation plan for the Clover CLI tool, a terminal-based assistant that works with various AI models to help build and manage projects. The tool will support multiple models, provide a set of core tools, and have several key features for project management.
Project Structure
clover/
├── main.py # Main entry point
├── cli/ # CLI module
│ ├── __init__.py
│ ├── commands.py # Command implementations
│ └── parser.py # CLI argument parsing
├── tools/ # Core tool implementations
│ ├── __init__.py
│ ├── file_tools.py # File operations (read, create, update, delete)
│ ├── project_tools.py # Project operations (summarize, structure)
│ └── commandline_tool.py # Command line execution tool
├── models/ # Model interaction modules
│ ├── __init__.py
│ ├── model_manager.py # Manage available models
│ └── api_client.py # API client for different LLM providers
├── config/ # Configuration management
│ ├── __init__.py
│ └── settings.py # Settings and configuration handling
├── utils/ # Utility functions
│ ├── __init__.py
│ └── helpers.py # Helper functions and utilities
├── .agent # Agent summary file (to be maintained)
├── .structure # Project structure diagram (to be maintained)
├── summary.md # Summary of actions taken so far (to be maintained)
└── requirements.txt # Dependencies
Core Tools Implementation
1. File Operations Tools
- read_file: Read content from a file and return its contents
- create_file: Create a new file with specified content
- update_file: Modify an existing file's content at specific lines or patterns
- delete_file: Remove a file from the project
2. Project Summary Tools
- summarize_file: Use another LLM to generate a summary of a specific file
- get_project_structure: Look for structure.md or generate it using LLM
- aggregate_summaries: Collect summaries from all files and create a combined project summary
3. Command Line Tool
- commandline: Execute system commands with user permission
- safe_execute: Handle command execution safely with error handling and permissions
Key Features Implementation
1. /list - List Available Models
- Query the OpenAI-compatible server for available models
- Display model information in a readable format
2. /init - Initialize Project Summary
- Create a "clover.md" file in project root
- Generate initial project summary using LLM
- Update this file as the project progresses
3. /timeout - Set Timeout Duration
- Configure maximum time allowed for agent to work on a problem
- Store timeout value in configuration
4. /threads - Set Thread Limit
- Configure maximum threads used for concurrent LLM operations
- Manage thread pool for sub-processes like file summaries and command line calls
Implementation Details
Model Integration
- Abstract model interface that supports multiple providers (OpenAI, Anthropic, etc.)
- Model manager to handle switching between different models
- API client that handles authentication and requests
Configuration Management
- Environment variables for configuration
- Settings file for persistent configuration storage
- Default fallback values for all settings
Thread Management
- Semaphore-based system for controlling concurrent LLM operations
- Thread pool implementation for managing sub-processes
- Safety limits to prevent resource exhaustion
Security Considerations
- Permission prompts for command line execution
- Input validation for all user inputs
- Safe file paths to prevent directory traversal attacks
Dependencies to Install in Virtual Environment
- openai (for OpenAI API integration)
- requests (for HTTP requests)
- python-dotenv (for environment variable management)
- tqdm (for progress bars)
Development Approach
- Start with basic CLI structure and command parsing
- Implement core tools step by step
- Add model integration capabilities
- Implement configuration management
- Add threading and timeout features
- Implement permission prompts for command execution
- Test all components thoroughly
- Document functionality and usage
Testing Strategy
- Unit tests for individual tools and functions
- Integration tests for end-to-end CLI operations
- Security tests for file system access and command execution
- Configuration management tests
Version Control Considerations
- Maintain .agent, .structure, and summary.md files during development
- Follow Git workflow for tracking changes
- Keep requirements.txt updated with dependencies
## Virtual Environment Setup Plan
1. Create a new virtual environment in the project directory:
```bash
python -m venv clover_env
-
Activate the virtual environment:
source clover_env/bin/activate # On macOS/Linux # or clover_env\Scripts\activate # On Windows -
Install required packages:
pip install openai requests python-dotenv tqdm -
Initialize the project structure
Command Line Interface Design
The CLI should support commands like:
clover /list- List available modelsclover /init- Initialize projectclover /timeout 300- Set timeout to 300 secondsclover /threads 5- Set thread limit to 5- Direct prompts for AI assistance
Each command will be implemented in the commands.py file with proper error handling and validation.