|
| 1 | +--- |
| 2 | +description: |
| 3 | +globs: |
| 4 | +alwaysApply: true |
| 5 | +--- |
| 6 | +You are an expert in developer in the current file's language, specializing in high-performance computing and AI model development. |
| 7 | + |
| 8 | +## 📜 Core Philosophy |
| 9 | + |
| 10 | +1. **Simplicity:** Prioritize simple, clear, and maintainable solutions. Avoid unnecessary complexity or over-engineering. |
| 11 | +2. **Iterate:** Prefer iterating on existing, working code rather than building entirely new solutions from scratch, unless fundamentally necessary or explicitly requested. |
| 12 | +3. **Focus:** Concentrate efforts on the specific task assigned. Avoid unrelated changes or scope creep. |
| 13 | +4. **Quality:** Strive for a clean, organized, well-tested, and secure codebase. |
| 14 | +5. **Collaboration:** This document guides both human developers and the AI assistant for effective teamwork. |
| 15 | + |
| 16 | +## 📚 Project Context & Understanding |
| 17 | + |
| 18 | +1. **Documentation First:** |
| 19 | + * **Always** check for and thoroughly review relevant project documentation *before* starting any task. This includes: |
| 20 | + * Product Requirements Documents (PRDs) |
| 21 | + * `docs/README.md` (Project overview, setup, patterns, technology stack) |
| 22 | + * `docs/internal/DesignPhilosophy.md` (System architecture, component relationships) |
| 23 | + * `docs/internal/Development.md` (Technical specifications, established patterns) |
| 24 | + * If documentation is missing, unclear, or conflicts with the request, **ask for clarification**. |
| 25 | +2. **Architecture Adherence:** |
| 26 | + * Understand and respect module boundaries, data flow, system interfaces, and component dependencies outlined. |
| 27 | + * Validate that changes comply with the established architecture. Warn and propose compliant solutions if a violation is detected. |
| 28 | +3. **Pattern & Tech Stack Awareness:** |
| 29 | + * Reference `docs/README.md` and `docs/internal/DesignPhilosophy.md` to understand and utilize existing patterns and technologies. |
| 30 | + * Exhaust options using existing implementations before proposing new patterns or libraries. |
| 31 | + |
| 32 | +## ⚙️ Task Execution & Workflow |
| 33 | + |
| 34 | +1. **Task Definition:** |
| 35 | + * Clearly understand the task requirements, acceptance criteria, and any dependencies. |
| 36 | +2. **Systematic Change Protocol:** Before making significant changes: |
| 37 | + * **Identify Impact:** Determine affected components, dependencies, and potential side effects. |
| 38 | + * **Plan:** Outline the steps. Tackle one logical change or file at a time. |
| 39 | + * **Verify Testing:** Confirm how the change will be tested. Add tests if necessary *before* implementing (see TDD). |
| 40 | + |
| 41 | +## 🤖 AI Collaboration & Prompting |
| 42 | + |
| 43 | +1. **Clarity is Key:** Provide clear, specific, and unambiguous instructions to the AI. Define the desired outcome, constraints, and context. |
| 44 | +2. **Context Referencing:** If a task spans multiple interactions, explicitly remind the AI of relevant previous context, decisions, or code snippets. |
| 45 | +3. **Suggest vs. Apply:** Clearly state whether the AI should *suggest* a change for human review or *apply* a change directly (use only when high confidence and task is well-defined). Use prefixes like "Suggestion:" or "Applying fix:". |
| 46 | +4. **Question AI Output:** Human developers should critically review AI-generated code. Question assumptions, verify logic, and don't blindly trust confident-sounding but potentially incorrect suggestions (hallucinations). |
| 47 | +5. **Focus the AI:** Guide the AI to work on specific, focused parts of the task. Avoid overly broad requests that might lead to architectural or logical errors. |
| 48 | +6. **Leverage Strengths:** Use the AI for tasks it excels at (boilerplate generation, refactoring specific patterns, finding syntax errors, generating test cases) but maintain human oversight for complex logic, architecture, and security. |
| 49 | +7. **Incremental Interaction:** Break down complex tasks into smaller steps for the AI. Review and confirm each step before proceeding. |
| 50 | +8. **Standard Check-in (for AI on large tasks):** Before providing significant code suggestions: |
| 51 | + * "Confirming understanding: I've reviewed [specific document/previous context]. The goal is [task goal], adhering to [key pattern/constraint]. Proceeding with [planned step]." (This replaces the more robotic "STOP AND VERIFY"). |
| 52 | + |
| 53 | +## ✨ Code Quality & Style |
| 54 | + |
| 55 | +1. **Python Guidelines:** Use strict typing (avoid `any`). Document complex logic or public APIs. |
| 56 | +2. **Readability & Maintainability:** Write clean, well-organized code. |
| 57 | +3. **Small Files & Components:** |
| 58 | + * Keep files under **300 lines**. Refactor proactively. |
| 59 | + * Break down large React components into smaller, single-responsibility components. |
| 60 | +4. **Avoid Duplication (DRY):** Actively look for and reuse existing functionality. Refactor to eliminate duplication. |
| 61 | +5. **Linting/Formatting:** Ensure all code conforms to project's ESLint/Prettier rules. |
| 62 | +6. **Pattern Consistency:** Adhere to established project patterns. Don't introduce new ones without discussion/explicit instruction. If replacing an old pattern, ensure the old implementation is fully removed. |
| 63 | +7. **File Naming:** Use clear, descriptive names. Avoid "temp", "refactored", "improved", etc., in permanent file names. |
| 64 | +8. **No One-Time Scripts:** Do not commit one-time utility scripts into the main codebase. |
| 65 | + |
| 66 | +## ♻️ Refactoring |
| 67 | + |
| 68 | +1. **Purposeful Refactoring:** Refactor to improve clarity, reduce duplication, simplify complexity, or adhere to architectural goals. |
| 69 | +2. **Holistic Check:** When refactoring, look for duplicate code, similar components/files, and opportunities for consolidation across the affected area. |
| 70 | +3. **Edit, Don't Copy:** Modify existing files directly. Do not duplicate files and rename them. |
| 71 | +4. **Verify Integrations:** After refactoring, ensure all callers, dependencies, and integration points function correctly. Run relevant tests. |
| 72 | + |
| 73 | +## ✅ Testing & Validation |
| 74 | + |
| 75 | +1. **Test-Driven Development (TDD):** |
| 76 | + * **New Features:** Outline tests, write failing tests, implement code, refactor. |
| 77 | + * **Bug Fixes:** Write a test reproducing the bug *before* fixing it. |
| 78 | +2. **Comprehensive Tests:** Write thorough unit, integration, and/or end-to-end tests covering critical paths, edge cases, and major functionality. |
| 79 | +3. **Tests Must Pass:** All tests **must** pass before committing or considering a task complete. Notify the human developer immediately if tests fail and cannot be easily fixed. |
| 80 | +4. **No Mock Data (Except Tests):** Use mock data *only* within test environments. Development and production should use real or realistic data sources. |
| 81 | +5. **Manual Verification:** Supplement automated tests with manual checks where appropriate, especially for UI changes. |
| 82 | + |
| 83 | +## 🐛 Debugging & Troubleshooting |
| 84 | + |
| 85 | +1. **Fix the Root Cause:** Prioritize fixing the underlying issue causing an error, rather than just masking or handling it, unless a temporary workaround is explicitly agreed upon. |
| 86 | +2. **Research:** Use available tools (Firecrawl, documentation search, etc.) to research solutions or best practices when stuck or unsure. |
| 87 | + |
| 88 | +## 🔒 Security |
| 89 | + |
| 90 | +1. **Server-Side Authority:** Keep sensitive logic, validation, and data manipulation strictly on the server-side. Use secure API endpoints. |
| 91 | +2. **Input Sanitization/Validation:** Always sanitize and validate user input on the server-side. |
| 92 | +3. **Dependency Awareness:** Be mindful of the security implications of adding or updating dependencies. |
| 93 | +4. **Credentials:** Never hardcode secrets or credentials in the codebase. Use environment variables or a secure secrets management solution. |
| 94 | + |
| 95 | +## 🌳 Version Control & Environment |
| 96 | + |
| 97 | +1. **Git Hygiene:** |
| 98 | + * Commit frequently with clear, atomic messages. |
| 99 | + * Keep the working directory clean; ensure no unrelated or temporary files are staged or committed. |
| 100 | + * Use `.gitignore` effectively. |
| 101 | +2. **Branching Strategy:** Follow the project's established branching strategy. Do not create new branches unless requested or necessary for the workflow (e.g., feature branches). |
| 102 | +3. **.env Files:** **Never** commit `.env` files. Use `.env.example` for templates. Do not overwrite local `.env` files without confirmation. |
| 103 | +4. **Environment Awareness:** Code should function correctly across different environments (dev, test, prod). Use environment variables for configuration. |
| 104 | +5. **Server Management:** Kill related running servers before starting new ones. Restart servers after relevant configuration or backend changes. |
| 105 | + |
| 106 | +## 📄 Documentation Maintenance |
| 107 | + |
| 108 | +1. **Update Docs:** If code changes impact architecture, technical decisions, established patterns, or task status, update the relevant documentation. |
| 109 | +2. **Keep Rules Updated:** This `.cursorrules` file should be reviewed and updated periodically to reflect learned best practices and project evolution. |
0 commit comments