CoderLib
CoderLib is a comprehensive Rust library for LLM-powered code generation, analysis, and editing.
🚀 Key Features
🤖 Multi-Provider LLM Support
- OpenAI (GPT-3/4 family) with function calling
- Anthropic (Claude Sonnet/Haiku/Opus family)
- Google (Gemini Flash/Pro family)
- Azure OpenAI with enterprise-grade security
- Local Models (Ollama, LM Studio, OpenAI-compatible APIs)
- Custom Providers with extensible provider system
🔧 Advanced Tool System
- File Operations - Read, write, search, and modify files safely
- Code Analysis - Tree-sitter based parsing for 8+ languages
- Git Integration - Repository operations and version control
- Shell Commands - Secure command execution with validation
- Project Analysis - Understand project structure and dependencies
- Custom Tools - Extensible plugin architecture
🛡️ Enterprise-Ready Security
- Permission System - Fine-grained access control
- Path Validation - Prevents directory traversal attacks
- Command Filtering - Blocks dangerous operations
- Rate Limiting - Configurable request throttling
- Audit Logging - Complete operation tracking
📊 Session & Context Management
- Persistent Sessions - SQLite-backed conversation history
- Context Awareness - Intelligent context gathering and management
- Auto-Summarization - Automatic conversation summarization
- Token Management - Usage tracking and optimization
- Memory Efficiency - Smart context window management
🔌 LSP Integration
- Language Server Protocol - Full LSP client and server support
- Real-time Diagnostics - Error detection and reporting
- Code Completion - IntelliSense and auto-completion
- Symbol Navigation - Go-to-definition and references
- Refactoring Support - Code transformations and improvements
🌐 MCP Bridge
- Model Context Protocol - Seamless MCP server integration
- Tool Interoperability - Connect with external MCP tools
- Protocol Compliance - Full MCP specification support
- Transport Flexibility - HTTP, WebSocket, and Stdio transports
📦 Installation
Add CoderLib to your Cargo.toml
:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
Feature Flags
Enable specific functionality based on your needs:
[]
= { = "0.1.0", = ["full"] }
Available features:
tools
- File operations and code analysis tools (default)lsp
- Language Server Protocol support (default)mcp
- Model Context Protocol integration (default)full
- All features enabled
🚀 Quick Start
Basic LLM Integration
use ;
async
Tool Usage Example
use ;
async
LSP Client Example
use ;
async
⚙️ Configuration
CoderLib supports flexible configuration through TOML files or programmatic setup:
Configuration File (coderlib.toml
)
= false
= "info"
# OpenAI Provider
[]
= true
= "your-api-key"
= "gpt-4"
= 4000
= 30
[]
= "https://api.openai.com/v1"
# Anthropic Provider
[]
= true
= "your-anthropic-key"
= "claude-3-5-sonnet-20241022"
= 4000
# Local Model Provider
[]
= true
= "http://localhost:11434" # Ollama default
= "llama3.1:8b"
# Storage Configuration
[]
= "sqlite"
= "coderlib.db"
# Tool Configuration
[]
= true
= true
= 10485760
= [".rs", ".py", ".js", ".ts", ".md"]
# Permission System
[]
= true
= true
= ["/home/user/projects", "/tmp"]
# LSP Configuration
[]
= "rust-analyzer"
= "typescript-language-server"
= "pylsp"
Programmatic Configuration
use ;
let config = CoderLibConfig ;
🏗️ Architecture
CoderLib follows a modular, plugin-based architecture designed for flexibility and extensibility:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Host Editor │◄──►│ CoderLib │◄──►│ LLM Provider │
│ (Edit/IDE) │ │ Core │ │ (OpenAI, etc.) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Integration │ │ Tool System │ │ Storage │
│ Layer │ │ (File, Git, │ │ (SQLite, │
│ (LSP, MCP) │ │ Code, Shell) │ │ Memory) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Permission │ │ Session │ │ Event │
│ System │ │ Management │ │ System │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Core Components
- 🧠 Agent System - Intelligent request processing with tool orchestration
- 🔌 Provider Layer - Unified interface for multiple LLM providers
- 🛠️ Tool Registry - Extensible tool system for code operations
- 💾 Session Manager - Persistent conversation history and context
- 🔐 Permission System - Fine-grained security and access control
- 📡 Event System - Real-time communication and state management
- 🗄️ Storage Layer - Pluggable persistence backends
Integration Patterns
Editor Plugin Integration
use ;
MCP Server Integration
use ;
async
📚 Examples
The examples/
directory contains comprehensive usage examples:
Basic Examples
basic_usage.rs
- Simple interactive AI assistantprovider_test.rs
- Testing different LLM providersopenai_test.rs
- OpenAI-specific integrationgemini_provider.rs
- Google Gemini integration
Advanced Examples
comprehensive_tools_demo.rs
- Full tool system showcasepermission_system_demo.rs
- Security and permissionsauto_summarization_demo.rs
- Context managementcustom_commands_demo.rs
- Custom command templates
Integration Examples
edit_integration.rs
- Editor plugin integrationmcp_bridge_test.rs
- MCP server integrationlsp_integration_test.rs
- Language server integration
Running Examples
# Basic usage
# Tool system demo
# Permission system
# MCP bridge
🚀 Production Ready
CoderLib is production-ready with comprehensive features:
✅ Completed Features
- Core Architecture - Stable, modular design
- Multi-Provider LLM Support - OpenAI, Anthropic, Google, Local models
- Advanced Tool System - File ops, Git, code analysis, shell commands
- Permission System - Enterprise-grade security
- Session Management - Persistent conversations with auto-summarization
- LSP Integration - Full Language Server Protocol support
- MCP Bridge - Model Context Protocol compatibility
- Configuration System - Flexible TOML and programmatic config
- Storage Backends - SQLite with extensible architecture
- Event System - Real-time communication and state management
🔄 Continuous Improvements
- Performance Optimization - Ongoing performance enhancements
- Additional Providers - New LLM provider integrations
- Enhanced Tools - More sophisticated code analysis tools
- Documentation - Expanding guides and tutorials
- Community Features - Plugin marketplace and extensions
🤝 Contributing
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes with tests
- Run the test suite:
cargo test
- Submit a pull request
Development Setup
See CONTRIBUTING.md for detailed guidelines.
📄 License
Licensed under:
- MIT License (LICENSE or http://opensource.org/licenses/MIT)
at your option.
🙏 Acknowledgments
- Designed with safety, performance, and extensibility in mind
- Community-driven development model
📞 Support
- Documentation: docs.rs/coderlib
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Crate: crates.io/crates/coderlib
CoderLib - A library for coder in the AI world. 🚀