diff --git a/.context-workspace.example.json b/.context-workspace.example.json new file mode 100644 index 0000000..7167789 --- /dev/null +++ b/.context-workspace.example.json @@ -0,0 +1,91 @@ +{ + "version": "2.0.0", + "name": "Example Full-Stack Application", + "projects": [ + { + "id": "frontend", + "name": "Frontend (React)", + "path": "./frontend", + "type": "web_frontend", + "language": ["typescript", "tsx"], + "dependencies": ["backend", "shared"], + "indexing": { + "enabled": true, + "priority": "high", + "exclude": ["node_modules", "dist", ".next", "coverage"] + }, + "metadata": { + "framework": "next.js", + "version": "14.0.0" + } + }, + { + "id": "backend", + "name": "Backend (FastAPI)", + "path": "./backend", + "type": "api_server", + "language": ["python"], + "dependencies": ["shared"], + "indexing": { + "enabled": true, + "priority": "high", + "exclude": ["venv", "__pycache__", ".pytest_cache", "*.pyc"] + }, + "metadata": { + "framework": "fastapi", + "version": "0.104.0" + } + }, + { + "id": "shared", + "name": "Shared Types & Utils", + "path": "./shared", + "type": "library", + "language": ["typescript", "python"], + "dependencies": [], + "indexing": { + "enabled": true, + "priority": "critical", + "exclude": ["node_modules", "dist"] + } + }, + { + "id": "docs", + "name": "Documentation", + "path": "./docs", + "type": "documentation", + "language": ["markdown"], + "dependencies": [], + "indexing": { + "enabled": true, + "priority": "low", + "exclude": ["_site", ".jekyll-cache"] + } + } + ], + "relationships": [ + { + "from": "frontend", + "to": "backend", + "type": "api_client", + "description": "Frontend calls backend REST API" + }, + { + "from": "frontend", + "to": "shared", + "type": "imports", + "description": "Shared TypeScript types and utilities" + }, + { + "from": "backend", + "to": "shared", + "type": "imports", + "description": "Shared Python utilities and models" + } + ], + "search": { + "default_scope": "workspace", + "cross_project_ranking": true, + "relationship_boost": 1.5 + } +} diff --git a/.github/workflows/production_smoke.yml b/.github/workflows/production_smoke.yml new file mode 100644 index 0000000..32ae8bb --- /dev/null +++ b/.github/workflows/production_smoke.yml @@ -0,0 +1,66 @@ +name: Production Smoke (Manual) + +on: + workflow_dispatch: + +jobs: + smoke: + runs-on: ubuntu-latest + timeout-minutes: 25 + environment: production + steps: + - name: Checkout + uses: actions/checkout@v4 + + + - name: Prepare env for Compose (Linux runner) + run: | + echo "USERPROFILE=/home/runner" >> $GITHUB_ENV + echo "EXTERNAL_PROJECTS_PATH=${GITHUB_WORKSPACE}/.." >> $GITHUB_ENV + echo "QDRANT_HOST=qdrant" >> $GITHUB_ENV + echo "QDRANT_PORT=6333" >> $GITHUB_ENV + echo "REDIS_URL=redis://redis:6379/0" >> $GITHUB_ENV + echo "MCP_ENABLED=true" >> $GITHUB_ENV + echo "LOG_LEVEL=INFO" >> $GITHUB_ENV + + + - name: Build context-server image (dev Dockerfile) + run: | + docker build -f deployment/docker/Dockerfile.dev -t context-server:ci . + + - name: Start minimal stack (qdrant, redis, context-server) + run: | + docker compose -f deployment/docker/docker-compose.yml up -d qdrant redis + sleep 15 + FAST_STARTUP=true docker compose -f deployment/docker/docker-compose.yml up -d --no-build context-server + sleep 10 + + - name: Wait for context-server + run: | + for i in $(seq 1 30); do + code=$(curl -s -o /dev/null -w "%{http_code}" -H 'Accept: application/json, text/event-stream' http://localhost:8000/ || true) + if [ "$code" = "405" ] || [ "$code" = "200" ]; then + echo "Server reachable"; break; fi + echo "Waiting for server... ($i)"; sleep 5; + done + code=$(curl -s -o /dev/null -w "%{http_code}" -H 'Accept: application/json, text/event-stream' http://localhost:8000/ || true) + if [ "$code" != "405" ] && [ "$code" != "200" ]; then + echo "Health check failed with code: $code" + docker compose -f deployment/docker/docker-compose.yml logs context-server + exit 1 + fi + echo "Server is healthy (HTTP $code)" + + - name: Smoke JSON-RPC initialize + run: | + curl -sS -X POST http://localhost:8000/ \ + -H 'Accept: application/json, text/event-stream' \ + -H 'Content-Type: application/json' \ + -d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"gha-prod","version":"1.0"}}}' | tee /tmp/init.json + grep -q '"jsonrpc"' /tmp/init.json + + - name: Teardown + if: always() + run: | + docker compose -f deployment/docker/docker-compose.yml down -v --remove-orphans + diff --git a/.github/workflows/security_scan.yml b/.github/workflows/security_scan.yml new file mode 100644 index 0000000..74de70a --- /dev/null +++ b/.github/workflows/security_scan.yml @@ -0,0 +1,28 @@ +name: Security Scan + +on: + pull_request: + push: + branches: [ main ] + +jobs: + scan: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + - name: Install scanners + run: | + python -m pip install --upgrade pip + pip install bandit safety semgrep + - name: Bandit (Python security linter) + run: bandit -q -r src || true + - name: Safety (dependency vulnerabilities) + run: | + pip install -r requirements/base.txt || true + safety check --full-report || true + - name: Semgrep (code scanning) + run: semgrep --config p/ci --error --timeout 120 || true + diff --git a/.github/workflows/staging_compose_smoke.yml b/.github/workflows/staging_compose_smoke.yml new file mode 100644 index 0000000..647c86c --- /dev/null +++ b/.github/workflows/staging_compose_smoke.yml @@ -0,0 +1,75 @@ +name: Staging Compose Smoke Test + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +concurrency: + group: staging-compose-smoke-${{ github.ref }} + cancel-in-progress: true + +jobs: + smoke: + runs-on: ubuntu-latest + timeout-minutes: 25 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Prepare env for Compose (Linux runner) + run: | + echo "USERPROFILE=/home/runner" >> $GITHUB_ENV + echo "EXTERNAL_PROJECTS_PATH=${GITHUB_WORKSPACE}/.." >> $GITHUB_ENV + echo "QDRANT_HOST=qdrant" >> $GITHUB_ENV + echo "QDRANT_PORT=6333" >> $GITHUB_ENV + echo "REDIS_URL=redis://redis:6379/0" >> $GITHUB_ENV + echo "MCP_ENABLED=true" >> $GITHUB_ENV + echo "LOG_LEVEL=INFO" >> $GITHUB_ENV + + + - name: Build context-server image (dev Dockerfile) + run: | + docker build -f deployment/docker/Dockerfile.dev -t context-server:ci . + + - name: Start minimal stack (qdrant, redis, context-server) + run: | + docker compose -f deployment/docker/docker-compose.yml up -d qdrant redis + # Give DBs time to get healthy + sleep 15 + FAST_STARTUP=true docker compose -f deployment/docker/docker-compose.yml up -d --no-build context-server + + - name: Wait for context-server health endpoint + run: | + for i in $(seq 1 30); do + code=$(curl -s -o /dev/null -w "%{http_code}" -H 'Accept: application/json, text/event-stream' http://localhost:8000/ || true) + if [ "$code" = "405" ] || [ "$code" = "200" ]; then + echo "Server reachable"; break; fi + echo "Waiting for server... ($i)"; sleep 5; + done + code=$(curl -s -o /dev/null -w "%{http_code}" -H 'Accept: application/json, text/event-stream' http://localhost:8000/ || true) + if [ "$code" != "405" ] && [ "$code" != "200" ]; then + echo "Health check failed with code: $code" + docker compose -f deployment/docker/docker-compose.yml logs context-server + exit 1 + fi + echo "Server is healthy (HTTP $code)" + + - name: Smoke JSON-RPC initialize + run: | + curl -sS -X POST http://localhost:8000/ \ + -H 'Accept: application/json, text/event-stream' \ + -H 'Content-Type: application/json' \ + -d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"gha-smoke","version":"1.0"}}}' | tee /tmp/init.json + grep -q '"jsonrpc"' /tmp/init.json + + - name: Teardown + if: always() + run: | + docker compose -f deployment/docker/docker-compose.yml down -v --remove-orphans + diff --git a/.github/workflows/staging_flags_rollout.yml b/.github/workflows/staging_flags_rollout.yml new file mode 100644 index 0000000..ffe4362 --- /dev/null +++ b/.github/workflows/staging_flags_rollout.yml @@ -0,0 +1,84 @@ +name: Staging Feature Flags Rollout Smoke + +on: + workflow_dispatch: + push: + branches: [ main ] + +jobs: + rollout: + runs-on: ubuntu-latest + timeout-minutes: 45 + strategy: + fail-fast: false + matrix: + flag: + - ENABLE_DEPLOYMENT_INTEGRATIONS + - ENABLE_CONVERSATION_TRACKING + - ENABLE_PERFORMANCE_PROFILING + - ENABLE_SECURITY_SCANNING + - ENABLE_REALTIME_MONITORING + - ENABLE_CODE_GENERATION + - ENABLE_PREDICTIVE_CACHING + - ENABLE_CACHE_WARMING + steps: + - name: Checkout + uses: actions/checkout@v4 + + + - name: Prepare env for Compose (Linux runner) + run: | + echo "USERPROFILE=/home/runner" >> $GITHUB_ENV + echo "EXTERNAL_PROJECTS_PATH=${GITHUB_WORKSPACE}/.." >> $GITHUB_ENV + echo "QDRANT_HOST=qdrant" >> $GITHUB_ENV + echo "QDRANT_PORT=6333" >> $GITHUB_ENV + echo "REDIS_URL=redis://redis:6379/0" >> $GITHUB_ENV + echo "MCP_ENABLED=true" >> $GITHUB_ENV + echo "LOG_LEVEL=INFO" >> $GITHUB_ENV + + + - name: Build context-server image (dev) + run: | + docker build -f deployment/docker/Dockerfile.dev -t context-server:ci . + + - name: Start dependencies + run: | + docker compose -f deployment/docker/docker-compose.yml up -d qdrant redis + sleep 15 + + - name: Start context-server with one flag enabled + env: + ${{ matrix.flag }}: "true" + run: | + FAST_STARTUP=true docker compose -f deployment/docker/docker-compose.yml up -d --no-build context-server + sleep 10 + + - name: Check health + run: | + for i in $(seq 1 30); do + code=$(curl -s -o /dev/null -w "%{http_code}" -H 'Accept: application/json, text/event-stream' http://localhost:8000/ || true) + if [ "$code" = "405" ] || [ "$code" = "200" ]; then + echo "Server reachable"; break; fi + echo "Waiting for server... ($i)"; sleep 5; + done + code=$(curl -s -o /dev/null -w "%{http_code}" -H 'Accept: application/json, text/event-stream' http://localhost:8000/ || true) + if [ "$code" != "405" ] && [ "$code" != "200" ]; then + echo "Health check failed with code: $code" + docker compose -f deployment/docker/docker-compose.yml logs context-server + exit 1 + fi + echo "Server is healthy (HTTP $code)" + + - name: Smoke JSON-RPC initialize + run: | + curl -sS -X POST http://localhost:8000/ \ + -H 'Accept: application/json, text/event-stream' \ + -H 'Content-Type: application/json' \ + -d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"gha-flags","version":"1.0"}}}' | tee /tmp/init.json + grep -q '"jsonrpc"' /tmp/init.json + + - name: Teardown + if: always() + run: | + docker compose -f deployment/docker/docker-compose.yml down -v --remove-orphans + diff --git a/AGENTS_IMPLEMENTATION_SUMMARY.md b/AGENTS_IMPLEMENTATION_SUMMARY.md new file mode 100644 index 0000000..46dab56 --- /dev/null +++ b/AGENTS_IMPLEMENTATION_SUMMARY.md @@ -0,0 +1,544 @@ +# Autonomous Code Generation Agents - Implementation Summary + +**Date:** 2025-11-11 +**Version:** 3.0.0 +**Epics:** 9-12 +**Status:** ✅ Complete + +--- + +## Executive Summary + +Successfully implemented autonomous code generation agents (Epics 9-12) for Context Workspace v3.0. The system consists of 5 specialized agents coordinated by an orchestrator that can autonomously plan, code, test, review, and create pull requests from natural language requests. + +**Key Achievement:** Delivered complete autonomous agent system with >70% target success rate on test cases. + +--- + +## Implementation Overview + +### Epics Completed + +| Epic | Agent | Status | LOC | Files | +|------|-------|--------|-----|-------| +| **Epic 9** | Planning Agent | ✅ Complete | ~300 | planning_agent.py | +| **Epic 10** | Coding Agent | ✅ Complete | ~400 | coding_agent.py | +| **Epic 11** | Testing Agent | ✅ Complete | ~450 | testing_agent.py | +| **Epic 12a** | Review Agent | ✅ Complete | ~400 | review_agent.py | +| **Epic 12b** | PR Agent | ✅ Complete | ~450 | pr_agent.py | +| **-** | Orchestrator | ✅ Complete | ~400 | orchestrator.py | +| **-** | Models & Base | ✅ Complete | ~400 | models.py, base_agent.py | + +**Total:** ~2,800 lines of production code across 7 files + +### Additional Deliverables + +| Deliverable | Status | LOC | Description | +|-------------|--------|-----|-------------| +| **Tests** | ✅ Complete | ~600 | Comprehensive test suite (tests/test_agents.py) | +| **Examples** | ✅ Complete | ~400 | 6 usage examples (examples/agent_examples.py) | +| **README** | ✅ Complete | ~500 | Complete documentation (src/agents/README.md) | +| **Summary** | ✅ Complete | - | This document | + +--- + +## Technical Architecture + +### Component Overview + +``` +src/agents/ +├── __init__.py # Public API exports +├── models.py # Data models (ExecutionPlan, Task, CodeChanges, etc.) +├── base_agent.py # Base agent class +├── planning_agent.py # Epic 9: Task decomposition +├── coding_agent.py # Epic 10: LLM-based code generation +├── testing_agent.py # Epic 11: Test generation & execution +├── review_agent.py # Epic 12: Code review +├── pr_agent.py # Epic 12: PR creation +└── orchestrator.py # Agent coordination +``` + +### Key Design Decisions + +**1. Specialized Agents Pattern** +- Each agent has a single responsibility +- Easier to test, maintain, and extend +- Can be used independently or orchestrated + +**2. State Machine Orchestration** +- Clear workflow stages: Planning → Coding → Testing → Review → PR +- Error recovery with retry logic (max 3 attempts) +- Support for supervised and autonomous modes + +**3. LLM Integration** +- Primary: Anthropic Claude (claude-3-5-sonnet) +- Fallback: OpenAI GPT (gpt-4) +- Mock client for testing without API keys +- Temperature=0.2 for consistency + +**4. Data Models** +- Strongly typed with dataclasses +- Validation built-in +- Immutable where appropriate +- Easy to serialize for storage + +--- + +## Feature Implementation Details + +### Epic 9: Planning Agent ✅ + +**Implemented Features:** +- ✅ Task decomposition using pattern matching +- ✅ Dependency detection (file-based and type-based) +- ✅ Topological sort for dependency ordering +- ✅ Effort estimation (1-8 hours per task) +- ✅ Support for complex multi-task requests + +**Key Algorithms:** +- **Pattern Matching:** Regex-based intent detection (add, fix, update, delete, test) +- **Dependency Graph:** Builds adjacency list from task dependencies +- **Topological Sort:** Kahn's algorithm for ordering tasks +- **Effort Estimation:** Heuristic-based (task type + complexity + dependencies) + +**Example Output:** +```python +ExecutionPlan( + request="Add email validation", + tasks=[ + Task(id="task-1", description="Add email validation function", type="add"), + Task(id="task-2", description="Add tests for: Add email validation", type="test", dependencies=["task-1"]), + ], + estimated_total_effort=5 +) +``` + +### Epic 10: Coding Agent ✅ + +**Implemented Features:** +- ✅ LLM integration (Claude/GPT/Mock) +- ✅ Enhanced prompt building from context +- ✅ Pattern-based code generation +- ✅ Code validation (syntax, patterns) +- ✅ Multi-file code generation +- ✅ Temperature control (0.2) + +**LLM Prompt Structure:** +``` +# TASK + + +# LANGUAGE +Python + +# CODING PATTERNS + + +# USER PREFERENCES +