diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..2707605 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,55 @@ +# Dependabot configuration for automated dependency updates +# Documentation: https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + # Python dependencies via pip/uv + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "weekly" + day: "monday" + time: "03:00" + open-pull-requests-limit: 5 + reviewers: + - "niksacdev" + labels: + - "dependencies" + - "python" + commit-message: + prefix: "chore" + prefix-development: "chore" + include: "scope" + groups: + development: + patterns: + - "pytest*" + - "mypy*" + - "ruff*" + - "black*" + - "pre-commit*" + openai: + patterns: + - "openai*" + - "agents*" + documentation: + patterns: + - "mkdocs*" + - "sphinx*" + + # GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + day: "monday" + time: "03:00" + open-pull-requests-limit: 3 + reviewers: + - "niksacdev" + labels: + - "dependencies" + - "github-actions" + commit-message: + prefix: "ci" + include: "scope" \ No newline at end of file diff --git a/.gitignore b/.gitignore index b491021..69a54db 100644 --- a/.gitignore +++ b/.gitignore @@ -209,6 +209,49 @@ __marimo__/ # SpecStory (AI code documentation) .specstory/ -# Application results and logs +# ============================================================================ +# Project-Specific Ignores +# ============================================================================ + +# Results and output files results/ console_app/results/ +loan_processing/results/ +*.result.json +*.decision.json + +# Temporary files +*.tmp +*.temp +*.bak +*.swp +*.swo +*~ + +# Local development +.env.local +.env.*.local +local_notes.md +scratch/ + +# MCP Server data +mcp_server_data/ +*.db +*.sqlite + +# Generated documentation +docs/_build/ +docs/generated/ + +# Performance profiling +*.prof +*.pstats +profile_output/ + +# Test coverage reports (duplicates removed as they're already above) + +# IDE specific files +.idea/ +.vscode/ +*.sublime-* +.DS_Store diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..750bdcb --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,73 @@ +# Pre-commit hooks for security and code quality +# Install: pip install pre-commit && pre-commit install + +repos: + # Security - Detect secrets + - repo: https://github.com/Yelp/detect-secrets + rev: v1.4.0 + hooks: + - id: detect-secrets + args: ['--baseline', '.secrets.baseline'] + exclude: .*\.lock|package-lock\.json + + # Python code quality + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.4 + hooks: + - id: ruff + args: [--fix] + - id: ruff-format + + # Python type checking + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.10.0 + hooks: + - id: mypy + additional_dependencies: [types-all] + args: [--ignore-missing-imports] + + # Check for common issues + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + args: ['--maxkb=1000'] + - id: check-case-conflict + - id: check-merge-conflict + - id: check-json + - id: check-toml + - id: detect-private-key + - id: no-commit-to-branch + args: ['--branch', 'main'] + + # Markdown formatting + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.39.0 + hooks: + - id: markdownlint + args: ['--fix'] + + # Security - Safety check + - repo: https://github.com/Lucas-C/pre-commit-hooks-safety + rev: v1.3.3 + hooks: + - id: python-safety-dependencies-check + +# Additional local hooks +- repo: local + hooks: + - id: no-env-files + name: Block .env files + entry: .env files must not be committed + language: fail + files: '^\.env$' + + - id: no-api-keys + name: Check for API keys + entry: 'sk-[a-zA-Z0-9]{48}|AKIA[0-9A-Z]{16}' + language: pygrep + types: [text] + exclude: \.env\.example|SECURITY\.md \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..18aaa53 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,297 @@ +# Contributing to Multi-Agent Loan Processing System + +Thank you for your interest in contributing! This document provides guidelines and instructions for contributing to the project. + +## ๐Ÿš€ Getting Started + +### Prerequisites + +- Python 3.10 or higher +- `uv` package manager (`pip install uv`) +- OpenAI API key (or Azure OpenAI credentials) + +### Development Setup + +1. **Fork and clone the repository** + ```bash + git clone https://github.com/your-username/multi-agent-system.git + cd multi-agent-system + ``` + +2. **Install dependencies with uv** + ```bash + uv sync + ``` + +3. **Set up environment variables** + ```bash + cp .env.example .env + # Edit .env with your API keys + ``` + +4. **Install pre-commit hooks** + ```bash + uv pip install pre-commit + pre-commit install + ``` + +5. **Run tests to verify setup** + ```bash + uv run pytest tests/test_agent_registry.py -v + ``` + +## ๐Ÿ“ Development Workflow + +### 1. Create a Feature Branch + +```bash +git checkout -b feature/your-feature-name +``` + +### 2. Make Your Changes + +Follow these guidelines: +- Write clean, readable code following PEP 8 +- Add type hints to all functions +- Include docstrings for modules, classes, and functions +- Keep functions focused and small +- Follow existing patterns in the codebase + +### 3. Write Tests + +- Add tests for new functionality +- Ensure existing tests pass +- Maintain >80% code coverage + +```bash +# Run specific tests +uv run pytest tests/test_your_feature.py -v + +# Run with coverage +uv run pytest tests/ --cov=loan_processing --cov-report=term-missing +``` + +### 4. Run Quality Checks + +Before committing, run all quality checks: + +```bash +# Linting +uv run ruff check . --fix +uv run ruff format . + +# Type checking +uv run mypy loan_processing/ + +# Tests +uv run pytest tests/test_agent_registry.py tests/test_safe_evaluator.py -v +``` + +### 5. Commit Your Changes + +Write clear, descriptive commit messages: + +```bash +git commit -m "feat: add income trend analysis to income agent" +``` + +Commit message format: +- `feat:` New feature +- `fix:` Bug fix +- `docs:` Documentation changes +- `test:` Test additions or changes +- `refactor:` Code refactoring +- `chore:` Maintenance tasks + +### 6. Push and Create PR + +```bash +git push origin feature/your-feature-name +``` + +Then create a Pull Request on GitHub with: +- Clear description of changes +- Link to related issues +- Screenshots/examples if applicable +- Test results + +## ๐Ÿ—๏ธ Architecture Guidelines + +### Agent Development + +When adding new agents: + +1. **Create persona file**: `loan_processing/agents/agent-persona/your-agent-persona.md` +2. **Update configuration**: Add to `loan_processing/config/agents.yaml` +3. **Define output format**: Specify structured output requirements +4. **Add tests**: Create `tests/test_your_agent.py` + +### MCP Server Development + +When adding MCP servers: + +1. **Create server module**: `loan_processing/tools/mcp_servers/your_server/` +2. **Implement server.py**: Follow existing server patterns +3. **Add to configuration**: Update `agents.yaml` with server details +4. **Document tools**: List all tools the server provides + +## ๐Ÿ“‹ Code Style + +### Python Style Guide + +- Use `ruff` for linting and formatting +- Follow PEP 8 with 120 character line limit +- Use descriptive variable names +- Add type hints for all functions +- Write comprehensive docstrings + +### Example Function: + +```python +def calculate_debt_to_income_ratio( + monthly_debt: Decimal, + monthly_income: Decimal, + include_proposed_payment: bool = True +) -> float: + """ + Calculate the debt-to-income ratio for loan qualification. + + Args: + monthly_debt: Total monthly debt payments + monthly_income: Gross monthly income + include_proposed_payment: Whether to include proposed loan payment + + Returns: + DTI ratio as a percentage (0-100) + + Raises: + ValueError: If monthly_income is zero or negative + """ + if monthly_income <= 0: + raise ValueError("Monthly income must be positive") + + return float((monthly_debt / monthly_income) * 100) +``` + +## ๐Ÿงช Testing Guidelines + +### Test Structure + +- Unit tests: `tests/test_*.py` +- Integration tests: `tests/test_integration_*.py` +- Use pytest fixtures for common test data +- Mock external dependencies +- Test both success and failure cases + +### Example Test: + +```python +def test_agent_creation(): + """Test that agents are created with correct configuration.""" + agent = AgentRegistry.create_agent("intake", model="gpt-4") + + assert agent.name == "Intake Agent" + assert agent.model == "gpt-4" + assert len(agent.mcp_servers) == 0 # Optimized for speed +``` + +## ๐Ÿ“š Documentation + +### Documentation Requirements + +- Update README.md for user-facing changes +- Update CLAUDE.md for AI development instructions +- Add docstrings to all new code +- Create ADRs for architectural decisions +- Update configuration examples + +### ADR Format + +Create `docs/decisions/adr-XXX-title.md`: + +```markdown +# ADR-XXX: Title + +## Status +Accepted/Proposed/Deprecated + +## Context +Why this decision is needed + +## Decision +What we're doing + +## Consequences +What happens as a result +``` + +## ๐Ÿ› Reporting Issues + +### Bug Reports + +Include: +- Python version +- Steps to reproduce +- Expected behavior +- Actual behavior +- Error messages/logs +- Environment details + +### Feature Requests + +Include: +- Use case description +- Proposed solution +- Alternative approaches considered +- Impact on existing functionality + +## ๐Ÿ”’ Security + +- Never commit secrets or API keys +- Report security issues privately (see SECURITY.md) +- Use secure coding practices +- Validate all inputs +- Follow principle of least privilege + +## ๐Ÿ“Š Performance + +- Profile code for bottlenecks +- Optimize database queries +- Use async operations where appropriate +- Cache expensive computations +- Monitor memory usage + +## ๐ŸŽฏ Pull Request Checklist + +Before submitting a PR, ensure: + +- [ ] Code follows style guidelines +- [ ] Tests pass locally +- [ ] Coverage maintained >80% +- [ ] Documentation updated +- [ ] Pre-commit hooks pass +- [ ] No hardcoded values +- [ ] No sensitive data exposed +- [ ] Commit messages follow format +- [ ] PR description is complete + +## ๐Ÿ’ฌ Getting Help + +- Open an issue for bugs/features +- Check existing issues first +- Join discussions in issues/PRs +- Review documentation thoroughly +- Ask questions - we're here to help! + +## ๐Ÿ† Recognition + +Contributors will be recognized in: +- README.md contributors section +- Release notes +- Project documentation + +Thank you for contributing to make loan processing more efficient and accessible! + +--- + +*By contributing, you agree that your contributions will be licensed under the MIT License.* \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..2bf5ed8 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,123 @@ +# Security Policy + +## ๐Ÿ”’ Security Best Practices + +This repository demonstrates secure coding practices for AI-powered loan processing systems. + +### API Key Security + +**NEVER commit API keys or secrets to version control!** + +1. Copy `.env.example` to `.env` +2. Add your API keys to `.env` +3. Ensure `.env` is in `.gitignore` (already configured) +4. Use environment variables for all sensitive configuration + +### Data Privacy + +This system implements privacy-by-design principles: + +- **No Real SSNs**: The system uses UUID-based `applicant_id` instead of SSNs +- **No PII in Logs**: Sensitive data is never logged +- **Secure Parameters**: All MCP server calls use secure identifiers +- **Data Minimization**: Only necessary data is collected and processed + +### Secure Development + +- All dependencies are managed through `uv` with lock files +- Regular security audits with `uv pip audit` +- Comprehensive test coverage (>83%) +- Type checking with mypy +- Linting with ruff + +## ๐Ÿ› Reporting Security Vulnerabilities + +We take security seriously. If you discover a security vulnerability, please follow responsible disclosure: + +1. **DO NOT** create a public GitHub issue +2. Email security concerns to: [your-email@example.com] +3. Include: + - Description of the vulnerability + - Steps to reproduce + - Potential impact + - Suggested fix (if any) + +We will acknowledge receipt within 48 hours and provide a detailed response within 5 business days. + +## ๐Ÿ›ก๏ธ Security Features + +### Authentication & Authorization +- API key-based authentication for AI services +- Secure MCP server communication +- Role-based agent permissions + +### Data Protection +- Applicant IDs (UUIDs) instead of SSNs +- Encrypted sensitive data in transit +- Audit logging for compliance + +### Input Validation +- Pydantic models for data validation +- Regex patterns for format verification +- Boundary checking for numerical inputs + +## ๐Ÿ“‹ Security Checklist for Contributors + +Before submitting a PR: + +- [ ] No hardcoded credentials +- [ ] No real PII in test data +- [ ] All inputs validated +- [ ] Error messages don't leak sensitive info +- [ ] Dependencies updated and audited +- [ ] Tests pass with >80% coverage + +## ๐Ÿ”„ Dependency Management + +Regular dependency updates: +```bash +# Update dependencies +uv sync + +# Audit for vulnerabilities +uv pip audit + +# Update to latest secure versions +uv update +``` + +## ๐Ÿ“œ Compliance + +This system is designed with compliance in mind: + +- **FCRA**: Fair Credit Reporting Act compliance +- **ECOA**: Equal Credit Opportunity Act adherence +- **GDPR**: Privacy-by-design principles +- **SOC2**: Audit trail and access controls + +## ๐Ÿšจ Known Security Considerations + +1. **MCP Servers**: Currently run on localhost without authentication. In production: + - Add authentication to MCP servers + - Use TLS for MCP communications + - Implement rate limiting + +2. **API Keys**: Currently single API key for all agents. In production: + - Use separate keys per agent + - Implement key rotation + - Add usage monitoring + +3. **Audit Logging**: Basic logging implemented. In production: + - Send logs to SIEM + - Implement tamper-proof audit trail + - Add compliance reporting + +## ๐Ÿ“ž Contact + +Security Team: [your-email@example.com] +Project Maintainer: [your-github-username] + +--- + +*Last Updated: August 2025* +*Security Policy Version: 1.0* \ No newline at end of file