Contributing to AI Shell
Thank you for your interest in contributing to AI Shell! This document provides comprehensive guidelines for contributing to the project.
๐ Getting Started
Prerequisites
- Python 3.9 or higher
- Git
- Basic understanding of command-line tools
- Familiarity with Python and AsyncIO (for advanced contributions)
Development Setup
-
Fork and Clone
git clone https://github.com/your-username/Ai_shell.git cd Ai_shell -
Create Virtual Environment
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install Dependencies
pip install -r requirements.txt pip install pytest black flake8 pytest-cov -
Install in Development Mode
pip install -e . -
Verify Installation
python -m pytest ai-shell --help
๐๏ธ Project Architecture
Core Components
ai_shell/
โโโ main.py # Application entry point and CLI interface
โโโ config.py # Configuration management with YAML support
โโโ llm.py # LLM provider abstractions (Gemini, Ollama)
โโโ executor.py # Command execution with security validation
โโโ ui.py # User interface utilities and formatting
Key Design Patterns
- Provider Pattern: LLM providers implement a common interface
- Configuration Management: Centralized config with environment variable support
- Security Layer: Command validation and user confirmation system
- Async Architecture: Non-blocking operations for better UX
๐ง Development Workflow
Before Making Changes
-
Create a Feature Branch
git checkout -b feature/your-feature-name -
Run Tests
python -m pytest -v -
Check Code Style
black --check ai_shell/ tests/ flake8 ai_shell/ tests/
Making Changes
- Follow Code Style
- Use Black for formatting
- Follow PEP 8 guidelines
- Add type hints where appropriate
-
Write descriptive docstrings
-
Write Tests
- Add unit tests for new functionality
- Maintain high test coverage
- Use descriptive test names
-
Include both positive and negative test cases
-
Update Documentation
- Update README.md if needed
- Add docstrings to new functions/classes
- Update configuration examples
Testing Guidelines
# Run all tests
python -m pytest
# Run specific test file
python -m pytest tests/test_config.py
# Run with coverage
python -m pytest --cov=ai_shell --cov-report=html
# Run tests in verbose mode
python -m pytest -v -s
Code Quality
# Format code
black ai_shell/ tests/
# Check code style
flake8 ai_shell/ tests/
# Type checking (optional)
mypy ai_shell/
๐ Contribution Types
๐ Bug Fixes
- Report the Bug
- Use GitHub Issues
- Provide clear reproduction steps
- Include system information
-
Add relevant logs or screenshots
-
Fix the Bug
- Write a failing test first
- Implement the minimal fix
- Ensure all tests pass
- Update documentation if needed
โจ New Features
- Propose the Feature
- Open a GitHub Issue for discussion
- Explain the use case and benefits
-
Consider the scope and complexity
-
Implement the Feature
- Follow the existing architecture patterns
- Add comprehensive tests
- Update documentation
- Consider backward compatibility
Common Contribution Areas
Adding New LLM Providers
-
Create a new provider class in
llm.py:class NewLLMProvider(LLMProvider): def __init__(self, config): self.config = config async def generate_response(self, prompt, system_prompt=""): # Implementation here pass -
Register the provider in
get_llm_provider() - Add configuration options
- Write comprehensive tests
Enhancing Security Features
- Add new validation rules in
executor.py - Update the dangerous commands list
- Add configuration options for new security features
- Test edge cases thoroughly
Improving User Interface
- Add new UI components in
ui.py - Ensure consistent styling with existing components
- Test across different terminal environments
- Consider accessibility
๐งช Testing Strategy
Test Categories
- Unit Tests: Individual component testing
- Integration Tests: Component interaction testing
- End-to-End Tests: Full workflow testing
- Security Tests: Validation and safety testing
Writing Good Tests
def test_config_load_from_file():
"""Test that configuration loads correctly from YAML file."""
# Arrange
config_data = {"llm": {"provider": "gemini"}}
# Act
config = Config(config_data)
# Assert
assert config.get("llm.provider") == "gemini"
Test Coverage
- Aim for >90% test coverage
- Focus on critical paths and edge cases
- Mock external dependencies (APIs, file system)
- Test error conditions and recovery
๐ Documentation
Code Documentation
- Docstrings: All public functions and classes
- Type Hints: Use for better IDE support
- Comments: Explain complex logic, not obvious code
User Documentation
- README.md: Keep updated with new features
- Configuration: Document all config options
- Examples: Provide practical usage examples
๐ฏ Commit Guidelines
Commit Message Format
type(scope): brief description
Detailed explanation of the change, including:
- Why the change was made
- What was changed
- Any breaking changes or migration notes
Fixes #123
Commit Types
feat: New featuresfix: Bug fixesdocs: Documentation changesstyle: Code style changes (formatting, etc.)refactor: Code refactoring without feature changestest: Adding or updating testschore: Build process or auxiliary tool changes
Examples
feat(llm): add support for Claude API
- Implement ClaudeProvider class
- Add configuration options for Claude
- Update provider selection logic
- Add comprehensive tests
Fixes #456
fix(security): prevent command injection in user input
- Sanitize user input before processing
- Add validation for special characters
- Update security tests
- Document security considerations
Closes #789
๐ข Release Process
Pull Request Guidelines
- Before Submitting
- Ensure all tests pass
- Update documentation
- Add changelog entry
-
Squash commits if needed
-
PR Description
- Clear title and description
- Link to related issues
- Include screenshots for UI changes
-
List breaking changes
-
Review Process
- Address reviewer feedback
- Keep discussions focused
- Be open to suggestions
Versioning
We follow Semantic Versioning:
- MAJOR.MINOR.PATCH
- Major: Breaking changes
- Minor: New features, backward compatible
- Patch: Bug fixes, backward compatible
๐ค Community Guidelines
Code of Conduct
- Be respectful and inclusive
- Provide constructive feedback
- Help others learn and grow
- Follow the project's coding standards
- Focus on the problem, not the person
Getting Help
- GitHub Issues: Bug reports and feature requests
- GitHub Discussions: General questions and ideas
- Code Review: Learn from feedback and review others' code
๐ Recognition
Contributors are recognized in: - GitHub contributor graphs - Release notes for significant contributions - Special mentions for outstanding contributions
Thank you for contributing to AI Shell! ๐