π€ Production-Ready AI-Powered Code Analysis, Test Generation, and Optimization SDK
The CI Code Companion SDK is a comprehensive, production-ready Python SDK that brings advanced AI capabilities to your development workflow. Built with modern async architecture and intelligent agent routing, it provides seamless code analysis, automated test generation, performance optimization, and interactive AI assistance.
- π§ Multi-Agent AI System - Specialized agents for React, Python, Node.js, Database, DevOps, and Mobile
- β‘ Async Performance - Modern async/await architecture with parallel processing
- π― Intelligent Routing - Automatic agent selection based on file content and technology stack
- π§ͺ Smart Test Generation - Automated unit test creation with coverage analysis
- π Advanced Code Analysis - Security scanning, performance optimization, and style checking
- π¬ Interactive Chat - Context-aware AI assistance for development questions
- π Production Ready - Comprehensive error handling, logging, and monitoring
- π Easy Integration - GitLab CI/CD, Cloud Run components, and standalone usage
CI Code Companion SDK
βββ π§ Core Engine # Orchestration, config, utilities
βββ π€ Agent System # Specialized AI agents with intelligent routing
βββ π Data Models # Structured analysis results and metrics
βββ π§ Services # File operations and external integrations
βββ π Web Dashboard # Interactive web interface
βββ π¦ Cloud Components # GitLab CI/CD and Cloud Run deployments
# Install from source
git clone https://github.com/your-org/CI-Code-Companion.git
cd CI-Code-Companion
pip install -e .
# Or install from PyPI (when published)
pip install ci-code-companion-sdk
import asyncio
from ci_code_companion_sdk import CICodeCompanionSDK, SDKConfig
async def main():
# Initialize SDK
config = SDKConfig(
ai_provider='vertex_ai',
project_id='your-gcp-project'
)
sdk = CICodeCompanionSDK(config=config)
# Analyze code
with open('example.py', 'r') as f:
code = f.read()
# Get comprehensive analysis
analysis = await sdk.analyze_file('example.py', code)
print(f"Issues found: {len(analysis.issues)}")
print(f"Confidence: {analysis.confidence_score:.2f}")
# Generate tests
tests = await sdk.generate_tests('example.py', code)
print(f"Generated test framework: {tests.get('framework')}")
# Get optimization suggestions
optimizations = await sdk.optimize_code('example.py', code)
print(f"Optimizations: {len(optimizations.get('optimizations', []))}")
# Interactive AI chat
response = await sdk.chat("How can I improve this code?", 'example.py', code)
print(f"AI Suggestion: {response[:100]}...")
if __name__ == "__main__":
asyncio.run(main())
# Start the web dashboard
python run_dashboard.py
# Visit http://localhost:5001
# - Upload files for analysis
# - Generate tests interactively
# - Chat with specialized AI agents
# - View detailed reports and metrics
Agent | File Types | Specializations |
---|---|---|
React Agent | .jsx , .tsx |
Hooks validation, performance, component analysis |
Python Agent | .py |
PEP8, security, Django/Flask/FastAPI frameworks |
Node Agent | .js , .ts |
Express/NestJS, async patterns, performance |
Database Agent | .sql |
Query optimization, security, performance tuning |
DevOps Agent | .yml , .tf |
Docker, Kubernetes, Terraform best practices |
Mobile Agent | .dart , .kt |
React Native, Flutter, platform-specific optimizations |
The SDK automatically routes files to the most appropriate agent based on:
- File Extensions - Direct mapping for common file types
- Content Analysis - Framework and library detection within files
- Project Context - Understanding project structure and dependencies
- Agent Capabilities - Matching required analysis types with agent strengths
# Required
export GCP_PROJECT_ID="your-gcp-project"
# Optional
export CI_SDK_LOG_LEVEL="INFO"
export CI_SDK_MAX_FILE_SIZE="10485760" # 10MB
export CI_SDK_MAX_CONCURRENT="5"
export CI_SDK_CACHE_ENABLED="true"
ai_provider: "vertex_ai"
project_id: "your-gcp-project"
region: "us-central1"
# Agent configuration
agents:
react_agent:
enabled: true
max_file_size: 1048576 # 1MB
python_agent:
enabled: true
frameworks: ["django", "flask", "fastapi"]
# File handling
allowed_file_types:
- ".py"
- ".js"
- ".jsx"
- ".ts"
- ".tsx"
- ".sql"
# Performance
max_concurrent_operations: 5
enable_metrics: true
cache_enabled: true
The SDK provides production-ready GitLab CI/CD components:
# .gitlab-ci.yml
include:
- component: $CI_SERVER_FQDN/your-group/ci-code-companion/ai-code-reviewer@main
inputs:
gcp_project_id: $GCP_PROJECT_ID
review_type: "comprehensive"
severity_threshold: "medium"
post_comment: true
- component: $CI_SERVER_FQDN/your-group/ci-code-companion/ai-test-generator@main
inputs:
gcp_project_id: $GCP_PROJECT_ID
test_framework: "pytest"
create_mr: true
ai-analysis:
stage: test
image: python:3.11
before_script:
- pip install ci-code-companion-sdk
script:
- python -c "
import asyncio;
from ci_code_companion_sdk import CICodeCompanionSDK, SDKConfig;
async def analyze():
sdk = CICodeCompanionSDK(SDKConfig());
# Your analysis logic here
asyncio.run(analyze())
"
# Build development image
docker build --target development -t ci-companion-dev .
# Run with hot reload
docker run -p 5000:5000 -v $(pwd):/app ci-companion-dev
# Build production image
docker build --target production -t ci-companion-prod .
# Run production server
docker run -p 8080:8080 -e PORT=8080 ci-companion-prod
# Deploy to Google Cloud Run
gcloud run deploy ci-code-companion \
--image gcr.io/your-project/ci-companion-prod \
--platform managed \
--region us-central1 \
--allow-unauthenticated
Performs comprehensive code analysis including:
- Issue detection with severity levels
- Code suggestions and improvements
- Security vulnerability scanning
- Performance optimization opportunities
- Style and convention adherence
Generates comprehensive test suites:
- Unit tests with high coverage
- Integration test templates
- Mock and fixture generation
- Framework-specific best practices
Provides optimization recommendations:
- Performance improvements
- Memory usage optimization
- Algorithm efficiency suggestions
- Best practice implementations
Interactive AI assistance:
- Context-aware responses
- Code-specific guidance
- Architecture recommendations
- Debugging assistance
from ci_code_companion_sdk.models import AnalysisResult, CodeIssue, CodeSuggestion
# Analysis result structure
class AnalysisResult:
issues: List[CodeIssue] # Detected issues
suggestions: List[CodeSuggestion] # Improvement suggestions
confidence_score: float # AI confidence (0-1)
metadata: Dict[str, Any] # Additional context
class CodeIssue:
title: str # Issue title
description: str # Detailed description
severity: str # critical, high, medium, low, info
line_number: Optional[int] # Location in file
suggestion: Optional[str] # How to fix
# Install test dependencies
pip install -e ".[test]"
# Run unit tests
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=ci_code_companion_sdk --cov-report=html
# Run integration tests
pytest tests/integration/ -v --slow
# Generate tests for SDK components
python examples/sdk_basic_usage.py
# Run generated tests
pytest generated_tests/ -v
# Get SDK statistics
stats = await sdk.get_stats()
print(f"Active agents: {stats['active_agents']}")
print(f"Success rate: {stats['success_rate']:.1%}")
print(f"Avg response time: {stats['avg_response_time']:.2f}s")
# Verify SDK health
health = await sdk.health_check()
if health['status'] == 'healthy':
print("β
SDK is operational")
CI-Code-Companion/
βββ ci_code_companion_sdk/ # Main SDK package
β βββ core/ # Engine, config, exceptions
β βββ agents/ # Specialized AI agents
β βββ models/ # Data models
β βββ services/ # File and external services
βββ web_dashboard/ # Web interface
βββ components/ # GitLab CI/CD components
βββ examples/ # Usage examples
βββ tests/ # Test suite
βββ docs/ # Documentation
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Test your changes:
pytest tests/
- Commit changes:
git commit -m 'Add amazing feature'
- Push to branch:
git push origin feature/amazing-feature
- Open a Pull Request
# Format code
black ci_code_companion_sdk/ tests/
# Lint code
flake8 ci_code_companion_sdk/ tests/
# Type checking
mypy ci_code_companion_sdk/
- Migration Guide - Upgrading from legacy versions
- Project Structure - Detailed architecture overview
- Examples - Comprehensive usage examples
- API Documentation - Detailed API reference
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π§ Email: support@cicompanion.ai
- Input Validation - All inputs are sanitized and validated
- File Size Limits - Configurable limits prevent resource exhaustion
- Secure AI Prompts - Prompt injection protection and sanitization
- Access Controls - Token-based authentication for production deployments
Please report security vulnerabilities to security@cicompanion.ai
This project is licensed under the MIT License - see the LICENSE file for details.
- Google Cloud Vertex AI - Powering our AI capabilities
- GitLab - CI/CD platform integration
- Python Community - Amazing ecosystem and tools
- Contributors - Thank you for making this project better
CI Code Companion SDK - Bringing AI-powered intelligence to every line of code π