Sitelet https://github.com/Flissel/coding-engine/tree/master/infra
Skip to content

Latest commit

 

History

History

README.md

🚀 Coding Engine Container

Autonome Code-Generierung im Docker-Container mit Live-Preview und Web-Widget.

Features

  • 🐳 Docker containerized - Ubuntu 22.04 + Python 3.11 + Node.js 20
  • 🖥️ Live VNC preview - Watch code execute in real-time via browser
  • 🎛️ REST API - Full control via FastAPI endpoints
  • 📡 WebSocket streaming - Real-time events and logs
  • 🔌 Embeddable widget - Drop into any website
  • ⏹️ User-controlled stop - No automatic timeouts
  • 🔍 Auto project detection - Electron, Web Apps, CLI tools
  • 📦 Git Integration - Automatic GitHub repository creation and push

Quick Start

# Navigate to infra directory
cd infra

# Start the container
docker-compose up --build

# Access the services:
# - Control API: http://localhost:8000
# - Widget:      http://localhost:8000/widget/widget.html
# - VNC:         http://localhost:6080/vnc.html

Git Integration

The container supports automatic GitHub repository creation and code pushing when generation completes.

Setup

  1. Create a GitHub Personal Access Token (PAT)

    • Go to GitHub → Settings → Developer Settings → Personal Access Tokens → Tokens (classic)
    • Generate new token with repo scope
    • Copy the token
  2. Set the environment variable

    Option A: Environment variable (recommended)

    # Linux/macOS
    export GITHUB_TOKEN=ghp_your_token_here
    cd infra && docker-compose up
    
    # Windows PowerShell
    $env:GITHUB_TOKEN="ghp_your_token_here"
    cd infra; docker-compose up
    
    # Windows CMD
    set GITHUB_TOKEN=ghp_your_token_here
    cd infra && docker-compose up

    Option B: .env file

    # Create infra/.env file
    echo "GITHUB_TOKEN=ghp_your_token_here" > infra/.env

Usage via API

Check Git status:

curl http://localhost:8000/api/git/status

Response:

{
  "configured": true,
  "username": "your-username",
  "message": "GitHub configured for user: your-username"
}

Start engine with Git enabled:

curl -X POST http://localhost:8000/api/start \
  -H "Content-Type: application/json" \
  -d '{
    "requirements_file": "my-project.json",
    "output_dir": "my-output",
    "git_config": {
      "repo_name": "my-generated-app",
      "description": "Auto-generated by Coding Engine",
      "private": true,
      "create_repo": true,
      "push_on_complete": true
    }
  }'

Manual push (after generation):

curl -X POST "http://localhost:8000/api/git/push?output_dir=my-output" \
  -H "Content-Type: application/json" \
  -d '{
    "repo_name": "my-repo",
    "private": true
  }'

Usage via Widget

  1. Open the widget: http://localhost:8000/widget/widget.html
  2. Go to the Config tab
  3. Enable "Push to GitHub on completion"
  4. Optionally set repository name (defaults to output directory name)
  5. Choose private/public
  6. Click Start
  7. When complete, a banner shows the repository URL

Git Events (WebSocket)

The WebSocket stream includes these Git-related events:

Event Description
git_repo_created Repository created on GitHub
git_push_started Push operation started
git_push_complete Code successfully pushed (includes repo_url)
git_error Git operation failed

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                    Docker Container                              │
│  ┌──────────────────────────────────────────────────────────┐   │
│  │                    supervisord                            │   │
│  │                                                           │   │
│  │  ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────────┐  │   │
│  │  │  Xvfb   │  │ x11vnc  │  │  noVNC  │  │ FastAPI     │  │   │
│  │  │ :99     │──│ :5900   │──│ :6080   │  │ Control     │  │   │
│  │  └─────────┘  └─────────┘  └─────────┘  │ Server :8000│  │   │
│  │                                         │             │  │   │
│  │  ┌───────────────────────────────────┐  │ ┌─────────┐ │  │   │
│  │  │        Coding Engine              │◄─┼─│ Git     │ │  │   │
│  │  │   (src/mind/orchestrator.py)      │  │ │ Service │ │  │   │
│  │  └───────────────────────────────────┘  │ └─────────┘ │  │   │
│  │                                         └─────────────┘  │   │
│  └──────────────────────────────────────────────────────────┘   │
│                                                                  │
│  Ports: 8000 (API), 6080 (VNC), 3000-3001/5000/8080 (Preview)   │
└─────────────────────────────────────────────────────────────────┘

API Reference

Control Endpoints

Method Endpoint Description
GET / API info and available endpoints
GET /api/health Health check with service status
GET /api/status Current engine state and metrics
POST /api/start Start code generation
POST /api/stop Stop running engine
GET /api/logs Get log history

Git Endpoints

Method Endpoint Description
GET /api/git/status Check GitHub configuration
POST /api/git/create Create GitHub repository
POST /api/git/push Push code to GitHub

WebSocket

Endpoint Description
/ws Real-time event stream

Directory Structure

infra/
├── Dockerfile              # Container image definition
├── docker-compose.yml      # Service configuration
├── supervisord.conf        # Multi-process management
├── README.md               # This file
│
├── control_server/         # FastAPI Control Server
│   ├── __init__.py
│   ├── server.py           # Main API server
│   ├── models.py           # Pydantic models
│   └── git_service.py      # GitHub integration
│
├── widget/                 # Embeddable widget
│   ├── widget.html         # Widget markup
│   ├── widget.css          # Widget styles
│   └── widget.js           # Widget logic
│
├── scripts/                # Container scripts
│   ├── entrypoint.sh       # Container startup
│   ├── start-preview.sh    # Preview launcher
│   └── process-monitor.sh  # Process monitor
│
└── data/                   # Mounted volumes
    ├── requirements/       # Input requirements (read-only)
    └── output/             # Generated code output

Configuration

Environment Variables

Variable Description Default
GITHUB_TOKEN GitHub PAT for repository operations (none)
OPENAI_API_KEY OpenAI API key for code generation (none)
ANTHROPIC_API_KEY Anthropic API key (alternative) (none)
DISPLAY X11 display for GUI apps :99
NODE_ENV Node.js environment development

Port Mapping

Container Port Host Port Service
8000 8000 FastAPI Control Server
6080 6080 noVNC Web Interface
3000 3000 Preview (React/Next.js)
3001 3001 Preview (alternate)
5000 5000 Preview (Flask/Python)
8080 8080 Preview (general)

Embedding the Widget

<!-- Option 1: Direct embed -->
<iframe 
  src="http://localhost:8000/widget/widget.html"
  width="900" 
  height="600"
  frameborder="0">
</iframe>

<!-- Option 2: Custom integration -->
<div id="coding-engine-container"></div>
<link rel="stylesheet" href="http://localhost:8000/widget/widget.css">
<script src="http://localhost:8000/widget/widget.js"></script>
<script>
  const widget = new CodingEngineWidget({
    apiUrl: 'http://localhost:8000',
    vncPath: '/vnc/vnc.html'
  });
</script>

Development

Live Editing

The docker-compose.yml mounts control_server/ and widget/ directories, allowing live editing without rebuild:

# Edit files locally - changes reflect immediately
vim infra/widget/widget.js

# Only need to rebuild for Dockerfile changes
docker-compose up --build

Adding New Features

  1. New API endpoint: Edit control_server/server.py
  2. New data models: Edit control_server/models.py
  3. Widget UI: Edit widget/widget.html and widget.css
  4. Widget logic: Edit widget/widget.js

Troubleshooting

Container won't start

# Check Docker is running
docker info

# Remove old containers and rebuild
docker-compose down
docker-compose up --build

VNC not connecting

# Check Xvfb is running in container
docker-compose exec coding-engine ps aux | grep Xvfb

# Check x11vnc
docker-compose exec coding-engine ps aux | grep x11vnc

Git push failing

# Check token is set
curl http://localhost:8000/api/git/status

# Verify token permissions
# Token needs 'repo' scope for private repos
# Token needs 'public_repo' scope for public repos only

API not responding

# Check container health
docker-compose ps

# View logs
docker-compose logs -f coding-engine

License

MIT License - See LICENSE file in root directory.