sonicoder / README.md
Z User
๐Ÿš€ SoniCoder v2.1.0 - Major Enhancement Release
5249791
|
Raw
History Blame Contribute Delete
8.44 kB
---
title: SoniCoder v2.1
emoji: ๐Ÿš€
colorFrom: purple
colorTo: blue
sdk: gradio
sdk_version: 6.19.0
app_file: app.py
pinned: false
license: apache-2.0
---
# SoniCoder v2.1 โ€” Enhanced AI Code Agent
> **Optimized AI code writer agent with architecture inspired by Gemini CLI and Claude Code.**
**No external APIs needed** โ€” runs entirely on local inference with smart 1B models.
## โœจ What's New in v2.1
### ๐ŸŽฏ Major Enhancements
- **๐Ÿค– New Model Support**: Added DeepSeek-Coder-1.3B for advanced code reasoning
- **๐Ÿ’พ Session Management**: Persistent conversations with export to JSON/Markdown/HTML
- **๐Ÿ“ Code Templates**: Quick-start templates for common project types (Flask, React, Express, Gradio)
- **โšก Performance Optimizations**: Response caching, model optimization, better memory management
- **๐Ÿ”’ Security Hardening**: Enhanced input validation, command blocking patterns, environment scrubbing
- **๐Ÿ“Š Metrics & Monitoring**: Inference metrics tracking, token counting, performance statistics
- **๐ŸŽจ Improved UI**: Better error messages, loading states, progress indicators
### ๐Ÿ”ง Technical Improvements
- **Model Loading Progress**: Real-time progress callbacks during model initialization
- **Response Caching**: Cache similar prompts for faster responses (configurable TTL)
- **Better Error Recovery**: Graceful fallbacks when streaming fails
- **Command Audit Trail**: Track executed commands with timestamps and results
- **Conversation Summarization**: Auto-summarize long contexts to stay within token limits
- **Token Usage Estimation**: Estimate token counts for cost/performance planning
## ๐Ÿš€ Quick Start
### Installation
```bash
# Clone the repository
git clone https://huggingface.co/spaces/sonic-coder/sonicoder
cd sonicoder
# Install dependencies
pip install -r requirements.txt
# Run the application
python app.py
```
### Docker (Alternative)
```dockerfile
FROM python:3.11-slim
WORKSPACE /app
COPY . .
RUN pip install -r requirements.txt
EXPOSE 7860
CMD ["python", "app.py"]
```
## ๐Ÿ–ฅ๏ธ Features
### Core Capabilities
| Feature | Description |
|---------|-------------|
| **Code Generation** | Generate complete applications in any language/framework |
| **File Operations** | Read, write, edit files in a sandboxed workspace |
| **Shell Execution** | Run commands (git, npm, pip, tests) with safety controls |
| **Multi-model Support** | Switch between Qwen2.5-Coder, MiniCPM5, MiniCPM-V, DeepSeek-Coder |
| **Vision Support** | Upload images for VLM-powered code generation |
| **Slash Commands** | `/commit`, `/review`, `/feature`, `/design`, etc. |
| **Custom Agents** | Create AI-generated personas with specialized behaviors |
### Built-in Skills
| Skill | Description |
|-------|-------------|
| `frontend-design` | Distinctive visual design guidance |
| `feature-dev` | Guided feature implementation workflow |
| `code-review` | High-signal code review |
| `debugging` | Systematic debugging workflow |
| `fullstack-scaffold` | Project structure scaffolding rules |
| `commit-workflow` | Git commit best practices |
### Code Templates
Quick-start templates available:
| Template | Language | Framework |
|----------|----------|-----------|
| `python-flask-api` | Python | Flask |
| `react-todo-app` | JavaScript | React |
| `gradio-image-app` | Python | Gradio |
| `express-js-server` | JavaScript | Express.js |
## ๐Ÿ“ Project Structure
```
sonicoder/
โ”œโ”€โ”€ app.py # Entry point: launches Gradio Server
โ”œโ”€โ”€ requirements.txt # Python dependencies
โ”œโ”€โ”€ README.md # This file
โ”œโ”€โ”€ CLAUDE.md # Project memory & conventions
โ”œโ”€โ”€ index.html # Frontend (single-file SPA)
โ”‚
โ””โ”€โ”€ code/
โ”œโ”€โ”€ config/
โ”‚ โ””โ”€โ”€ constants.py # App config, system prompt, templates
โ”œโ”€โ”€ model/
โ”‚ โ”œโ”€โ”€ loader.py # Model loading with progress tracking
โ”‚ โ””โ”€โ”€ inference.py # Streaming inference with caching
โ”œโ”€โ”€ agent/
โ”‚ โ””โ”€โ”€ __init__.py # Agent loop (model โ†” tools)
โ”œโ”€โ”€ tools/
โ”‚ โ”œโ”€โ”€ fs.py # File operations
โ”‚ โ”œโ”€โ”€ bash.py # Sandboxed shell execution (enhanced)
โ”‚ โ”œโ”€โ”€ todos.py # Todo list management
โ”‚ โ””โ”€โ”€ github.py # GitHub integration
โ”œโ”€โ”€ skills/ # Built-in skills (markdown)
โ”œโ”€โ”€ agents/ # Custom agent system
โ”œโ”€โ”€ commands/ # Slash command definitions
โ”œโ”€โ”€ hooks/ # Safety hook rules
โ”œโ”€โ”€ execution/ # Code execution sandbox
โ”œโ”€โ”€ server/
โ”‚ โ”œโ”€โ”€ routes.py # All HTTP + API endpoints
โ”‚ โ”œโ”€โ”€ chat_helpers.py # Prompt building (enhanced)
โ”‚ โ”œโ”€โ”€ session_manager.py # Session persistence & export (NEW)
โ”‚ โ””โ”€โ”€ __init__.py # Server utilities
โ”œโ”€โ”€ huggingface/ # HF Spaces deployment
โ”œโ”€โ”€ websearch/ # Web search scraping
โ””โ”€โ”€ config.py # Workspace & config paths
```
## ๐ŸŽฎ Usage Examples
### Basic Code Generation
```
User: Create a Python Flask API with CRUD operations for a todo list
SoniCoder: [Generates complete Flask application with proper structure]
```
### Using Templates
```
User: Use the react-todo-app template as a starting point
SoniCoder: [Loads template and customizes based on requirements]
```
### Iterative Development
```
User: Build me a REST API
SoniCoder: [Creates initial API]
User: Add authentication to it
SoniCoder: [Reads existing file, adds auth middleware]
User: Write tests for the auth endpoint
SoniCoder: [Creates test file with pytest]
```
## โš™๏ธ Configuration
### Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| `SONICODER_WORKSPACE` | Workspace root directory | `./workspace` |
| `MODEL_CACHE_DIR` | Model cache location | Default HF cache |
### Model Selection
Models can be switched via the UI or API:
```python
from code.model.loader import switch_model
# Switch to DeepSeek Coder
result = switch_model("deepseek-coder-1.3b")
print(result) # {"success": True, "message": "Switching to DeepSeek-Coder-1.3B..."}
```
### Performance Tuning
In `code/config/constants.py`:
```python
# Enable response caching
CACHE_ENABLED = True
CACHE_TTL_SECONDS = 300 # 5 minutes
# Concurrency limits
MAX_CONCURRENT_REQUESTS = 5
```
## ๐Ÿ”’ Security
### Command Safety
Blocked patterns include:
- Destructive commands (`rm -rf /`, `mkfs`, `dd`)
- System control (`shutdown`, `reboot`)
- Fork bombs (`:(){:|:&};:`)
- Pipe-to-shell attacks (`curl ... | bash`)
- Root filesystem modifications
### Input Validation
- Maximum prompt length: 10,000 characters
- Maximum file size: 10 MB
- Rate limiting: 30 requests/minute
- Regex-based pattern blocking
## ๐Ÿ“Š Export & Sessions
### Export Formats
Sessions can be exported in multiple formats:
```python
from code.server.session_manager import export_session, get_session_manager
manager = get_session_manager()
session = manager.get_session("session_id")
# Export as JSON
export_session(session, format="json", output_dir="./exports")
# Export as Markdown
export_session(session, format="markdown", output_dir="./exports")
# Export as styled HTML
export_session(session, format="html", output_dir="./exports")
```
### Session Persistence
Sessions are automatically saved to `CONFIG_DIR/sessions/` and restored on restart.
## ๐Ÿค Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## ๐Ÿ“„ License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
## ๐Ÿ™ Acknowledgments
- Inspired by [Gemini CLI](https://github.com/google-gemini/gemini-cli) and [Claude Code](https://docs.anthropic.com/en/docs/claude-code)
- Powered by Hugging Face Transformers
- Models: Qwen2.5-Coder, MiniCPM5, MiniCPM-V, DeepSeek-Coder
---
**Built with โค๏ธ by the SoniCoder team**