This guide covers development practices, contributing guidelines, and technical details for working on the Cognitive Engine codebase. ## Development Environment Setup ### Prerequisites - Python 3.9 or higher - Git - pip ### Setup Steps 1. **Clone the repository** ```bash git clone cd cognitive_engine ``` 2. **Create virtual environment** ```bash python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate ``` 3. **Install development dependencies** ```bash pip install -r requirements.txt pip install pytest pytest-asyncio black flake8 mypy ``` 4. **Configure environment** ```bash cp .env.example .env # Edit .env with your development configuration ``` 5. **Run tests** ```bash python run.py test ``` ## Project Structure ``` cognitive_engine/ ├── core/ # Core engine orchestration │ ├── engine.py # Main orchestration loop │ ├── config.py # Configuration management │ ├── memory.py # Three-layer memory system │ ├── meta_cognition.py # Meta-cognitive oversight │ ├── reasoning_trace.py # Reasoning process tracking │ ├── inner_knowing.py # Self-awareness system │ ├── self_doubt.py # Uncertainty handling │ ├── ethical_alignment.py # Ethical reasoning │ ├── emotional_simulation.py # Emotional modeling │ ├── decision_control.py # Decision management │ ├── temporal_identity.py # Identity continuity │ ├── peaceful_resolution.py # Conflict resolution │ └── obedience_understanding.py # Authority analysis ├── models/ # Data models │ ├── thought.py # Thought object │ └── state.py # Problem state ├── layers/ # Cognitive layers │ ├── interpreter.py # Input interpretation │ ├── generator.py # Thought generation │ ├── deliberator.py # Thought deliberation │ ├── committer.py # Output commitment │ └── meta.py # Meta-cognition ├── utils/ # Utilities │ ├── scoring.py # Thought scoring │ ├── memory.py # Memory utilities │ └── logger.py # Logging ├── llm/ # LLM integration │ ├── client.py # LLM client │ ├── prompts.py # Prompt templates │ └── knowledge_base.py # Context management ├── agent/ # Autonomous agent │ ├── agent.py # Main agent │ ├── planner.py # Goal planning │ ├── executor.py # Action execution │ ├── observer.py # Result observation │ └── goals.py # Goal definitions ├── tools/ # Tool system │ ├── registry.py # Tool registry │ ├── web_search.py # Web search tool │ └── code_exec.py # Code execution tool ├── learning/ # Learning system │ ├── extractor.py # Pattern extraction │ ├── patterns.py # Pattern model │ ├── synthesizer.py # Rule synthesis │ └── updater.py # Knowledge update ├── prompt_evolution/ # Prompt evolution │ ├── prompt_store.py # Prompt versioning │ ├── proposer.py # Improvement suggestions │ ├── tester.py # A/B testing │ ├── evaluator.py # Performance evaluation │ └── controller.py # Change control ├── dashboard/ # Cognitive telemetry │ ├── server.py # WebSocket server │ ├── stream.py # Event streaming │ └── events.py # Event schemas ├── ui/ # Dashboard UI │ ├── index.html # Main dashboard │ ├── app.js # Frontend logic │ └── styles.css # Styling ├── tests/ # Test suite ├── docs/ # Documentation ├── website/ # Website and wiki │ └── wiki/ # Project wiki ├── run.py # Entry point ├── requirements.txt # Dependencies └── .env.example # Environment template ``` ## Code Style Guidelines ### Python Style - Use **Black** for code formatting (120 character line length) - Use **flake8** for linting - Include **type hints** for all functions - Write **Google-style docstrings** - Follow **PEP 8** naming conventions: - PascalCase for classes - snake_case for functions and variables - UPPER_CASE for constants ### Example Code Style ```python from typing import Optional, List, Dict, Any from datetime import datetime class ExampleClass: """ A brief description of the class. Longer description if needed. Attributes: attribute1: Description of attribute1 attribute2: Description of attribute2 """ def __init__(self, attribute1: str, attribute2: Optional[int] = None): """ Initialize the ExampleClass. Args: attribute1: Description of attribute1 attribute2: Description of attribute2 (optional) """ self.attribute1 = attribute1 self.attribute2 = attribute2 def example_method(self, param: str) -> Dict[str, Any]: """ A brief description of the method. Args: param: Description of param Returns: A dictionary containing the result Raises: ValueError: If param is invalid """ if not param: raise ValueError("param cannot be empty") return { "result": param, "timestamp": datetime.now() } ``` ### Formatting Commands ```bash # Format code with Black black cognitive_engine/ # Check linting with flake8 flake8 cognitive_engine/ # Type checking with mypy mypy cognitive_engine/ ``` ## Testing ### Running Tests ```bash # Run all tests python run.py test # Run specific test file pytest tests/test_engine.py # Run with coverage pytest --cov=cognitive_engine tests/ # Run specific test pytest tests/test_engine.py::test_process ``` ### Writing Tests Create test files in the `tests/` directory following the naming convention `test_.py`. ```python import pytest from core.engine import CognitiveEngine class TestCognitiveEngine: """Test suite for CognitiveEngine.""" def setup_method(self): """Set up test fixtures.""" self.engine = CognitiveEngine() def test_initialization(self): """Test engine initialization.""" assert self.engine is not None assert self.engine.thought_graph is not None def test_process_basic_query(self): """Test processing a basic query.""" result = self.engine.process("What is AI?") assert result is not None assert result.final_output is not None assert result.iteration_count > 0 ``` ### Test Coverage Maintain test coverage above 80%. Check coverage with: ```bash pytest --cov=cognitive_engine --cov-report=html ``` ## Documentation ### Code Documentation - All public classes and methods must have docstrings - Use Google-style docstring format - Include type hints in function signatures - Document complex algorithms with inline comments ### Wiki Documentation - Update the wiki in `website/wiki/` when adding features - Keep API documentation in sync with code changes - Update architecture documentation for structural changes - Add examples for new features ### README Updates - Update README.md for user-facing changes - Update installation instructions for dependency changes - Update configuration guide for new configuration options ## Contributing Workflow ### 1. Create a Branch ```bash git checkout -b feature/your-feature-name # or git checkout -b fix/your-bug-fix ``` ### 2. Make Changes - Follow code style guidelines - Write tests for new functionality - Update documentation - Ensure all tests pass ### 3. Commit Changes Follow conventional commits format: ``` ():