Spaces:
Running
Running
A newer version of the Gradio SDK is available: 6.20.0
metadata
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
# 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)
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:
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:
# 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:
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
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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 and Claude Code
- Powered by Hugging Face Transformers
- Models: Qwen2.5-Coder, MiniCPM5, MiniCPM-V, DeepSeek-Coder
Built with โค๏ธ by the SoniCoder team