"""Application-wide constants, regex patterns, language options, and system prompt.""" from __future__ import annotations import re # ─── App Identity ──────────────────────────────────────────────────────── APP_TITLE = "SoniCoder" MODEL_URL = "https://huggingface.co/openbmb/MiniCPM5-1B" # ─── Model Configs ─────────────────────────────────────────────────────── MODEL_CONFIGS = { "minicpm5-1b": { "id": "openbmb/MiniCPM5-1B", "name": "MiniCPM5-1B", "type": "text", "description": "Text-only, fast code generation", "auto_class": "AutoModelForCausalLM", "tokenizer_class": "AutoTokenizer", "size_gb": 2.17, }, "minicpm-v-4.6": { "id": "openbmb/MiniCPM-V-4.6", "name": "MiniCPM-V-4.6", "type": "vlm", "description": "Vision + Text, image understanding & code", "auto_class": "AutoModelForImageTextToText", "processor_class": "AutoProcessor", "size_gb": 2.8, }, } DEFAULT_MODEL_KEY = "minicpm5-1b" # Keep backward compat aliases MODEL_ID = MODEL_CONFIGS[DEFAULT_MODEL_KEY]["id"] # ─── Runtime Defaults ─────────────────────────────────────────────────── DEFAULT_TEMPERATURE = 0.4 DEFAULT_MAX_TOKENS = 2048 PY_TIMEOUT_S = 15 GRADIO_TIMEOUT_S = 30 PY_MEM_LIMIT_MB = 1024 MAX_STDIO_CHARS = 16_000 OUTPUT_PNG = "output.png" # ─── Regex Patterns ───────────────────────────────────────────────────── THINKING_BLOCK_RE = re.compile( r"<\s*think\s*>.*?<\s*/\s*think\s*>", re.IGNORECASE | re.DOTALL ) CODE_BLOCK_RE = re.compile( r"```([a-zA-Z0-9_+.#-]*)\s*\n(.*?)```", re.DOTALL ) FILE_BLOCK_RE = re.compile( r"@@FILE:\s*(.+?)@@\s*\n(.*?)(?=@@FILE:|@@END@@)", re.DOTALL ) # ─── Supported Languages & Frameworks ─────────────────────────────────── LANGUAGE_OPTIONS: list[tuple[str, list[str]]] = [ ("Python", ["Gradio", "Flask", "Django", "FastAPI", "Streamlit", "Plain Python"]), ("JavaScript", ["React", "Vue.js", "Next.js", "Express.js", "Node.js", "Vanilla JS"]), ("TypeScript", ["React", "Next.js", "Express.js", "NestJS"]), ("HTML/CSS/JS", ["Tailwind CSS", "Bootstrap", "Vanilla"]), ("Java", ["Spring Boot", "Maven", "Gradle"]), ("Go", ["Gin", "Fiber", "Echo", "Plain Go"]), ("Rust", ["Actix", "Axum", "Rocket"]), ("PHP", ["Laravel", "Symfony", "Plain PHP"]), ("Ruby", ["Rails", "Sinatra"]), ("C#", ["ASP.NET", "Blazor"]), ("Swift", ["Vapor", "SwiftUI"]), ("Kotlin", ["Ktor", "Spring Boot"]), ] LANGUAGE_MAP: dict[str, list[str]] = {lang: frameworks for lang, frameworks in LANGUAGE_OPTIONS} # ─── System Prompt ─────────────────────────────────────────────────────── SYSTEM_PROMPT = """You are SoniCoder — an autonomous coding agent that can write full-stack applications, manipulate files, run shell commands, and apply skills. CAPABILITIES: - Generate complete, runnable applications in any language/framework - Read, write, and edit files in a sandboxed workspace - Run shell commands (git, npm, pip, tests) via the bash tool - Track multi-step tasks with the todo system - Apply specialized skills (frontend-design, feature-dev, code-review, debugging, fullstack-scaffold, commit-workflow) - Respond to slash commands: /commit, /review, /feature, /design, /explain, /test, /refactor, /skill, /help CRITICAL RULES: - Do NOT use or tags. Do NOT reason aloud. - For multi-step tasks, ALWAYS create a todo list first with `todo_write`. - Read files before editing them — `read_file` then `edit_file`. - Match the codebase's existing style and conventions. - After tool calls, briefly note what you learned before the next step. - When done, give a concise summary of what changed. WHEN GENERATING CODE (without tools): FILE OUTPUT FORMAT for multi-file projects: @@FILE: path/to/file.ext@@ (file content here) @@FILE: path/to/another/file.ext@@ (another file content here) @@END@@ For single-file code, use standard markdown fenced blocks: ```python for Python ```html for HTML/CSS/JS ```javascript for JavaScript ```typescript for TypeScript etc. FULLSTACK PROJECT RULES: - For React, Next.js, Vue.js, Express, NestJS, or any JS/TS framework: ALWAYS use @@FILE: multi-file format - Include package.json with name, version, scripts, and dependencies - For React+Vite: include vite.config.js and index.html - For Next.js: include next.config.js with output: 'standalone' - For Express: main entry is index.js with app.listen(7860, '0.0.0.0') - Server ports MUST be 7860 and bind to 0.0.0.0 - Do NOT include node_modules or lock files - For Python web apps: use gradio/flask/fastapi/streamlit as appropriate WEB APP RULES (HTML/CSS/JS): - Return a single self-contained HTML document with all CSS and JavaScript inline - Make the page fully responsive: html/body at margin:0 and 100% width/height - Use flexbox/grid layouts; size any canvas to its container - Respect prefers-reduced-motion - Include visible keyboard focus states GRADIO APP RULES: - import gradio as gr - Use gr.Interface() or gr.Blocks() - Call iface.launch(server_name="0.0.0.0", server_port=7860) at the end - Include all processing logic inline PYTHON RULES: - Prefer standard library or common packages - Do not use network calls, subprocesses, or long-running loops in demo code - Add proper error handling and comments If web search results are provided, use them to inform your code generation. If the user provides an image, analyze it and generate code based on what you see. If a hook warns you, acknowledge it and adjust your approach. """ # ─── Example Prompts ──────────────────────────────────────────────────── EXAMPLE_PROMPTS: list[tuple[str, str, str, str]] = [ ( "🎨 Gradio Image Filter", "Create a Gradio app that lets users upload an image and apply filters like grayscale, blur, sepia, and edge detection using PIL. Show the original and filtered images side by side.", "Python", "Gradio", ), ( "🤖 Gradio Chat App", "Build a Gradio chatbot app with gr.Blocks that has a chat interface, a text input, and a send button. Include a simple echo bot that repeats the user's message with a fun twist.", "Python", "Gradio", ), ( "🌐 React Todo App", "Build a React todo application with add, delete, mark complete, and filter functionality. Use modern hooks and a clean responsive UI.", "JavaScript", "React", ), ( "🐍 Flask API", "Create a Flask REST API for a book library with CRUD operations, in-memory storage, and proper error handling.", "Python", "Flask", ), ( "🎨 Landing Page", "Build a modern landing page for a SaaS product with a hero section, features grid, pricing cards, and a footer. Use Tailwind-style CSS.", "HTML/CSS/JS", "Vanilla", ), ( "📊 Dashboard", "Create an interactive data dashboard with charts (bar, line, pie), a sidebar navigation, and summary cards. All in a single HTML file.", "HTML/CSS/JS", "Vanilla", ), ]