diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..449db4c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,61 @@ +# Git +.git +.gitignore + +# Python +__pycache__ +*.py[cod] +*$py.class +*.so +.Python +.venv +venv/ +ENV/ +env/ +.eggs +*.egg-info/ +.mypy_cache/ +.pytest_cache/ +.ruff_cache/ +htmlcov/ +.coverage +coverage.xml + +# IDE +.idea/ +.vscode/ +*.swp +*.swo + +# Build artifacts +build/ +dist/ +*.egg + +# Documentation +docs/ +*.md +!README.md + +# Tests (not needed in production image) +tests/ +pytest.ini + +# Development files +.pre-commit-config.yaml +Makefile +docker-compose*.yml + +# Templates (not needed in production) +templates/ + +# Tools (not needed in production) +tools/ + +# Node modules (if any) +node_modules/ + +# Misc +.DS_Store +*.log +*.tmp diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..2016d51 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,75 @@ +# CodeFlow Engine Docker Image +# Multi-stage build for optimized production image + +# Stage 1: Build stage +FROM python:3.12-slim as builder + +WORKDIR /app + +# Install build dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + curl \ + git \ + libpq-dev \ + && rm -rf /var/lib/apt/lists/* + +# Install poetry +RUN pip install --no-cache-dir poetry==1.8.3 + +# Copy dependency files +COPY pyproject.toml poetry.lock ./ + +# Configure poetry to not create virtual environment (we're in a container) +RUN poetry config virtualenvs.create false + +# Install dependencies (without dev dependencies by default) +ARG RUN_TESTS=false +RUN if [ "$RUN_TESTS" = "true" ]; then \ + poetry install --no-interaction --no-ansi; \ + else \ + poetry install --no-interaction --no-ansi --only main,server,database,resilience; \ + fi + +# Stage 2: Production stage +FROM python:3.12-slim as production + +WORKDIR /app + +# Install runtime dependencies only +RUN apt-get update && apt-get install -y --no-install-recommends \ + libpq5 \ + curl \ + && rm -rf /var/lib/apt/lists/* \ + && useradd --create-home --shell /bin/bash codeflow + +# Copy installed packages from builder +COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages +COPY --from=builder /usr/local/bin /usr/local/bin + +# Copy application code +COPY codeflow_engine/ ./codeflow_engine/ +COPY pyproject.toml ./ +COPY alembic/ ./alembic/ + +# Set ownership to non-root user +RUN chown -R codeflow:codeflow /app + +# Switch to non-root user +USER codeflow + +# Environment variables +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + HOST=0.0.0.0 \ + PORT=8080 + +# Expose the application port +EXPOSE 8080 + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:8080/health || exit 1 + +# Default command: run the server +CMD ["python", "-m", "codeflow_engine.server"] diff --git a/docs/development/CODE_QUALITY.md b/docs/development/CODE_QUALITY.md index 6bae9f9..7dd11de 100644 --- a/docs/development/CODE_QUALITY.md +++ b/docs/development/CODE_QUALITY.md @@ -56,53 +56,53 @@ Pre-commit hooks are automatically installed and will run on every commit. The h ### Using the Python Script -The `scripts/code_quality.py` script provides convenient commands: +The `tools/scripts/code_quality.py` script provides convenient commands: ```bash # Format code -python scripts/code_quality.py format +python tools/scripts/code_quality.py format # Run linting tools -python scripts/code_quality.py lint +python tools/scripts/code_quality.py lint # Run tests -python scripts/code_quality.py test +python tools/scripts/code_quality.py test # Check dependencies for vulnerabilities -python scripts/code_quality.py security +python tools/scripts/code_quality.py security # Install pre-commit hooks -python scripts/code_quality.py pre-commit install +python tools/scripts/code_quality.py pre-commit install # Run pre-commit hooks manually -python scripts/code_quality.py pre-commit run +python tools/scripts/code_quality.py pre-commit run # Run all quality checks -python scripts/code_quality.py check +python tools/scripts/code_quality.py check ``` ### Using the Windows Batch Script -For Windows users, `scripts/code_quality.bat` provides the same functionality: +For Windows users, `tools/scripts/code_quality.bat` provides the same functionality: ```cmd # Format code -scripts\code_quality.bat format +tools\scripts\code_quality.bat format # Run linting tools -scripts\code_quality.bat lint +tools\scripts\code_quality.bat lint # Run tests -scripts\code_quality.bat test +tools\scripts\code_quality.bat test # Check dependencies for vulnerabilities -scripts\code_quality.bat security +tools\scripts\code_quality.bat security # Install pre-commit hooks -scripts\code_quality.bat install +tools\scripts\code_quality.bat install # Run all quality checks -scripts\code_quality.bat check +tools\scripts\code_quality.bat check ``` ### Direct Tool Usage @@ -181,13 +181,13 @@ python -m pre_commit install python -m pre_commit run --all-files # Or use the comprehensive check -python scripts/code_quality.py check +python tools/scripts/code_quality.py check ``` ## Development Workflow 1. **Before committing**: Pre-commit hooks run automatically -2. **Manual checks**: Use `scripts/code_quality.py check` for comprehensive validation +2. **Manual checks**: Use `tools/scripts/code_quality.py check` for comprehensive validation 3. **Fix issues**: Address any linting or formatting issues 4. **Commit**: Use conventional commit messages (enforced by commitizen) diff --git a/docs/development/MIGRATION_GUIDE.md b/docs/development/MIGRATION_GUIDE.md index ed5d199..947fb37 100644 --- a/docs/development/MIGRATION_GUIDE.md +++ b/docs/development/MIGRATION_GUIDE.md @@ -162,7 +162,7 @@ New validation scripts have been created to maintain repository health: ### 1. Import Validation ```bash -python scripts/validate_imports.py +python tools/scripts/validate_imports.py ``` - Scans all Python files for broken imports @@ -172,7 +172,7 @@ python scripts/validate_imports.py ### 2. Link Validation ```bash -python scripts/validate_links.py +python tools/scripts/validate_links.py ``` - Validates all Markdown links in documentation @@ -182,7 +182,7 @@ python scripts/validate_links.py ### 3. Configuration Validation ```bash -python scripts/validate_configs.py +python tools/scripts/validate_configs.py ``` - Validates all configuration files (YAML, JSON, INI) @@ -192,7 +192,7 @@ python scripts/validate_configs.py ### 4. Template Validation ```bash -python scripts/validate_templates.py +python tools/scripts/validate_templates.py ``` - Validates all template files @@ -202,7 +202,7 @@ python scripts/validate_templates.py ### 5. Build System Validation ```bash -python scripts/validate_build_system.py +python tools/scripts/validate_build_system.py ``` - Validates pyproject.toml configuration @@ -268,11 +268,11 @@ The pre-commit configuration has been updated to include: ```bash # Run all validation scripts -python scripts/validate_imports.py -python scripts/validate_links.py -python scripts/validate_configs.py -python scripts/validate_templates.py -python scripts/validate_build_system.py +python tools/scripts/validate_imports.py +python tools/scripts/validate_links.py +python tools/scripts/validate_configs.py +python tools/scripts/validate_templates.py +python tools/scripts/validate_build_system.py ``` ### Expected Results @@ -288,7 +288,7 @@ python scripts/validate_build_system.py 1. **Import Errors After Reorganization:** ```bash - python scripts/validate_imports.py + python tools/scripts/validate_imports.py ``` - Check the generated report for specific import issues @@ -297,7 +297,7 @@ python scripts/validate_build_system.py 2. **Broken Documentation Links:** ```bash - python scripts/validate_links.py + python tools/scripts/validate_links.py ``` - Review the link validation report @@ -306,7 +306,7 @@ python scripts/validate_build_system.py 3. **Configuration Issues:** ```bash - python scripts/validate_configs.py + python tools/scripts/validate_configs.py ``` - Check for configuration validation errors @@ -329,9 +329,9 @@ Run validation scripts regularly to maintain repository health: ```bash # Weekly validation -python scripts/validate_imports.py -python scripts/validate_links.py -python scripts/validate_configs.py +python tools/scripts/validate_imports.py +python tools/scripts/validate_links.py +python tools/scripts/validate_configs.py ``` ### Adding New Files @@ -341,14 +341,14 @@ When adding new files, ensure they follow the established organization: - **Documentation**: Place in appropriate `docs/` subdirectory - **Templates**: Use existing template categories or create new ones - **Configuration**: Add to `configs/` with proper validation -- **Scripts**: Add to `scripts/` with validation capabilities +- **Scripts**: Add to `tools/scripts/` with validation capabilities ### Updating Dependencies When updating dependencies: 1. Update `pyproject.toml` only -2. Run `python scripts/validate_build_system.py` +2. Run `python tools/scripts/validate_build_system.py` 3. Test installation with new dependencies ## Conclusion diff --git a/docs/development/WINDOWS_DEVELOPMENT.md b/docs/development/WINDOWS_DEVELOPMENT.md index 721eb4e..2fed707 100644 --- a/docs/development/WINDOWS_DEVELOPMENT.md +++ b/docs/development/WINDOWS_DEVELOPMENT.md @@ -24,12 +24,12 @@ Instead of relying on pre-commit hooks, use our provided scripts for code qualit ```cmd # Run all code quality checks before committing -scripts\code_quality.bat check +python -m codeflow_engine.actions.quality_engine --mode comprehensive -# Or run individual tools -scripts\code_quality.bat format -scripts\code_quality.bat lint -scripts\code_quality.bat test +# Or run with different modes +python -m codeflow_engine.actions.quality_engine --mode fast +python -m codeflow_engine.actions.quality_engine --mode smart +python -m codeflow_engine.actions.quality_engine --mode ai_enhanced ``` #### Option 2: Install Standard Python 3.13.5 (Highly Recommended) @@ -55,7 +55,7 @@ If you want to keep Windows Store Python, you can create manual git hooks: ```bash #!/bin/sh echo "Running code quality checks..." -python scripts/code_quality.py check +python -m codeflow_engine.actions.quality_engine --mode fast if [ $? -ne 0 ]; then echo "Code quality checks failed. Please fix issues before committing." exit 1 @@ -79,8 +79,8 @@ python -m isort . --profile black python -m flake8 . --max-line-length 100 python -m mypy . --config-file pyproject.toml -# Or use our convenience script -scripts\code_quality.bat check +# Or use our convenience module +python -m codeflow_engine.actions.quality_engine --mode comprehensive ``` ### Commit Message Format diff --git a/docs/testing/COVERAGE_GUIDE.md b/docs/testing/COVERAGE_GUIDE.md index c8d9a42..aedcd21 100644 --- a/docs/testing/COVERAGE_GUIDE.md +++ b/docs/testing/COVERAGE_GUIDE.md @@ -57,13 +57,13 @@ open htmlcov/index.html **Bash:** ```bash -./scripts/check-coverage.sh [threshold] +./tools/coverage/check-coverage.sh [threshold] # Default threshold: 70% ``` **PowerShell:** ```powershell -.\scripts\check-coverage.ps1 -CoverageThreshold 70 +.\tools\coverage\check-coverage.ps1 -CoverageThreshold 70 ``` ### Coverage by Module diff --git a/docs/testing/COVERAGE_IMPROVEMENT_PLAN.md b/docs/testing/COVERAGE_IMPROVEMENT_PLAN.md index 4d38487..26788f2 100644 --- a/docs/testing/COVERAGE_IMPROVEMENT_PLAN.md +++ b/docs/testing/COVERAGE_IMPROVEMENT_PLAN.md @@ -359,7 +359,7 @@ poetry run pytest --cov=codeflow_engine --cov-report=html --cov-report=term poetry run coverage report --show-missing # Coverage check script -./scripts/check-coverage.sh 70 +./tools/coverage/check-coverage.sh 70 ``` ### Coverage Analysis diff --git a/docs/testing/QUICK_START_TESTING.md b/docs/testing/QUICK_START_TESTING.md index f601a5c..bf63241 100644 --- a/docs/testing/QUICK_START_TESTING.md +++ b/docs/testing/QUICK_START_TESTING.md @@ -38,7 +38,7 @@ poetry run pytest --cov=codeflow_engine --cov-report=html open htmlcov/index.html # Or use the measurement script -./scripts/measure-coverage.sh +./tools/coverage/measure-coverage.sh ``` ### 3. Run by Category @@ -140,10 +140,10 @@ def test_with_sample_data(): ```bash # Check if coverage meets threshold -./scripts/check-coverage.sh 70 +./tools/coverage/check-coverage.sh 70 # Or PowerShell -.\scripts\check-coverage.ps1 -CoverageThreshold 70 +.\tools\coverage\check-coverage.ps1 -CoverageThreshold 70 ``` --- diff --git a/pyproject.toml b/pyproject.toml index ff64e58..84abcd5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -349,11 +349,8 @@ line-ending = "auto" docstring-code-format = true [tool.ruff.lint.per-file-ignores] -# Allow print statements in scripts -"scripts/**/*.py" = ["T201"] - -# Allow all issues in volume control scripts -"scripts/volume-control/volume_knob.py" = ["ALL"] +# Allow print statements in coverage tools +"tools/coverage/**/*.py" = ["T201"] # Allow various issues in test files "tests/**/*.py" = [ @@ -367,26 +364,6 @@ docstring-code-format = true "DTZ005", # datetime.now() without tz ] -# Allow specific issues in volume-control scripts -"scripts/volume-control/**/*.py" = [ - "T201", # print statements - "PTH110", "PTH123", "PTH103", "PTH107", "PTH118", # pathlib issues - "PLR0911", "PLR0912", "PLR2004", # complexity issues - "TRY003", "TRY300", "TRY301", "TRY302", # try-except issues - "EM101", "EM102", # exception message issues - "F811", "F821", "F841", # pyflakes issues - "ARG002", # unused arguments - "SIM102", "SIM105", "SIM117", # simplify issues - "S603", "S607", "S110", "S112", # security issues - "N814", "N999", # naming issues - "RUF012", # mutable class attributes - "FBT001", "FBT002", # boolean issues - "A002", # argument shadowing - "B904", # exception chaining - "G004", # logging f-strings - "PGH003", # pygrep-hooks -] - # Allow specific issues in template discovery "templates/discovery/**/*.py" = [ "PTH123", # pathlib issues diff --git a/templates/README.md b/templates/README.md index 6707119..aecaa8c 100644 --- a/templates/README.md +++ b/templates/README.md @@ -126,7 +126,7 @@ All templates can be customized by: ### Template Validation -Templates are validated using `scripts/validate_templates.py` to ensure: +Templates are validated using `tools/scripts/validate_templates.py` to ensure: - Proper syntax and structure - Required parameters are defined diff --git a/scripts/coverage/__init__.py b/tools/coverage/__init__.py similarity index 61% rename from scripts/coverage/__init__.py rename to tools/coverage/__init__.py index bf1053f..3bf05e5 100644 --- a/scripts/coverage/__init__.py +++ b/tools/coverage/__init__.py @@ -1,5 +1,5 @@ """Coverage utilities for test quality gates.""" -from scripts.coverage.runner import CoverageRunner +from tools.coverage.runner import CoverageRunner __all__ = ["CoverageRunner"] diff --git a/scripts/check-coverage.ps1 b/tools/coverage/check-coverage.ps1 similarity index 76% rename from scripts/check-coverage.ps1 rename to tools/coverage/check-coverage.ps1 index 7c7e295..2bfe542 100644 --- a/scripts/check-coverage.ps1 +++ b/tools/coverage/check-coverage.ps1 @@ -8,5 +8,4 @@ param( $ErrorActionPreference = 'Stop' # Use the unified Python coverage utility -python -m scripts.coverage.runner check --threshold $CoverageThreshold - +python -m tools.coverage.runner check --threshold $CoverageThreshold diff --git a/scripts/check-coverage.sh b/tools/coverage/check-coverage.sh old mode 100644 new mode 100755 similarity index 73% rename from scripts/check-coverage.sh rename to tools/coverage/check-coverage.sh index c16139a..823a326 --- a/scripts/check-coverage.sh +++ b/tools/coverage/check-coverage.sh @@ -7,5 +7,4 @@ set -e COVERAGE_THRESHOLD=${1:-70} # Use the unified Python coverage utility -python -m scripts.coverage.runner check --threshold "$COVERAGE_THRESHOLD" - +python -m tools.coverage.runner check --threshold "$COVERAGE_THRESHOLD" diff --git a/scripts/measure-coverage.ps1 b/tools/coverage/measure-coverage.ps1 similarity index 82% rename from scripts/measure-coverage.ps1 rename to tools/coverage/measure-coverage.ps1 index fa0f764..66cf4c0 100644 --- a/scripts/measure-coverage.ps1 +++ b/tools/coverage/measure-coverage.ps1 @@ -4,5 +4,4 @@ $ErrorActionPreference = 'Stop' # Use the unified Python coverage utility -python -m scripts.coverage.runner measure - +python -m tools.coverage.runner measure diff --git a/scripts/measure-coverage.sh b/tools/coverage/measure-coverage.sh old mode 100644 new mode 100755 similarity index 81% rename from scripts/measure-coverage.sh rename to tools/coverage/measure-coverage.sh index 5ba464c..ead21b1 --- a/scripts/measure-coverage.sh +++ b/tools/coverage/measure-coverage.sh @@ -5,5 +5,4 @@ set -e # Use the unified Python coverage utility -python -m scripts.coverage.runner measure - +python -m tools.coverage.runner measure diff --git a/scripts/coverage/runner.py b/tools/coverage/runner.py similarity index 100% rename from scripts/coverage/runner.py rename to tools/coverage/runner.py