# Agent Behavioral Rules โ™ป๏ธ _This markdown file can be re-used anytime you wanna build a new app_ ## 1. ๐Ÿง  Cognitive Protocol (Mandatory MCP Usage) **Rule: Think Before You Code.** For any task involving **logic implementation, refactoring, debugging, or architectural changes**, you **MUST** use the `sequentialthinking` tool (MCP) as your FIRST step. **Trigger Conditions:** - When the user asks for a feature implementation (e.g., "Implement Prompt Batching"). - When analyzing a bug or a complex error log. - When planning a refactoring strategy. **Execution Steps:** 1. **Initiate `sequentialthinking`:** Do not output any code or text explanation until you have invoked this tool. 2. **Analyze & Plan:** Use the tool to: - Break down the user's request into atomic steps. - Identify potential risks (e.g., "Will this break the `dev` branch?"). - Formulate a hypothesis or a step-by-step implementation plan. 3. **Review:** Only after the sequential thinking process is complete and you have a clear path, proceed to write code or answer. **Rule: Terminal Command Notification.** If a task requires terminal commands (e.g., `mkdir`, `mv`, `rm`, `pnpm install`), you **MUST NOT** execute them directly. Instead, **notify the user** of the exact commands needed so they can run them manually. This is to ensure efficiency and avoid delays in command processing. **Exception:** - Simple content generation (e.g., "Write a README") or trivial fixes (e.g., typos) do not require this tool. ## 2. Documentation Lookup When I need code generation, setup or configuration steps, or library/API documentation: 1. **Primary:** Always use context7 when I need code generation, setup or configuration steps, or library/API documentation. This means you should automatically use the Context7 MCP tools to resolve library id and get library docs without me having to explicitly ask. 2. **Fallback:** If Context7 is unavailable, use web search to find the official documentation from: - GitHub repositories (README, docs folder) - Official documentation sites (e.g., svelte.dev, kit.svelte.dev) - Package registry pages (npm) Always prioritize official sources over blog posts or Stack Overflow answers. ## 3. Commit Message Convention We follow a convention combining Gitmoji and Conventional Commits. **Format:** `[Gitmoji] [Type]: [Title]` **Gitmoji & Types:** - โœจ `:sparkles:` `feat`: New features - ๐Ÿ› `:bug:` `fix`: Bug fixes - ๐Ÿ“š `:books:` `docs`: Documentation changes - ๐Ÿ’„ `:lipstick:` `ui`: UI changes - โ™ป๏ธ `:recycle:` `refactor`: Code refactoring - ๐Ÿš€ `:rocket:` `deploy`: Deployment tasks - โš™๏ธ `:gear:` `chore`: Build/config changes - โœ… `:white_check_mark:` `test`: Adding/fixing tests - ๐Ÿš‘ `:ambulance:` `hotfix`: Critical hotfixes **Rule:** After completing a significant task or a series of related changes, **ALWAYS** provide a **single-line** git commit message in the format above with adding adequate gitmoji at the start of the commit message. Focus on the most significant change. ## 4. Testing Strategy We prioritize automated testing to ensure high quality and reliability. 1. **Framework:** Use **Vitest** and **Svelte Testing Library** for frontend and API route testing. 2. **Execution:** Before finalizing complex logic, ensure tests are written and passing. ## 5. Coding Standards & Design Principles ### 5.1 SOLID Principles (Strict Enforcement) - **SRP (Single Responsibility Principle):** - Each component or utility must have **one and only one reason to change**. - Do NOT create "God Components". If a Svelte component exceeds 300 lines or handles mixed concerns, split it. - **OCP (Open/Closed Principle):** - Design for extension. Use slots and snippets for components that might change content. - **DIP (Dependency Inversion):** - Always depend on abstractions. Use Svelte context or stores/runes for dependency injection where appropriate. ### 6. SvelteKit & Svelte 5 Best Practices - **Runes ($state):** Convert `let var = val;` to `let var = $state(val);`. - **Props ($props):** Replace `export let prop;` with `let { prop } = $props();`. - **Derived ($derived):** Convert `$: double = count * 2;` to `let double = $derived(count * 2);`. - **Effects ($effect):** Convert `$: { sideEffect(); }` to `$effect(() => { sideEffect(); });`. - **Events:** Prefer callback props over `createEventDispatcher`. - **Icons:** Use `@lucide/svelte` for icon imports. **Rule:** Always use individual sub-path imports (e.g., `import Menu from "@lucide/svelte/icons/menu"`) instead of barrel imports to avoid deprecation warnings and improve tree-shaking. - **Cleanup:** Remove unused imports and ensure `lang="ts"`. ### 7. API Routes (SvelteKit Backend) - **Validation:** Use Zod or similar for validating incoming request data in `+server.ts`. - **Error Handling:** Use `error()` from `@sveltejs/kit` to return proper HTTP status codes. - **Security:** Ensure sensitive operations are protected by authentication checks (e.g., Supabase session). ### 8. Frontend & Backend Logging & Environment Checks - **Logging:** All `console.log`, `console.error`, and other debug logs MUST be wrapped in an environment check to prevent leaking information in production. - **Frontend Environment Check:** Use `IS_DEV_MODE` from `$lib/utils/env` to check if the app is running in development mode (Local OR Staging/Preview). - **Backend Environment Check:** Use `dev || isDevHostname(url.hostname)` since `IS_DEV_MODE` (which relies on `window`) is not available on the server. - **Example (Frontend):** ```typescript import { IS_DEV_MODE } from "$lib/utils/env"; if (IS_DEV_MODE) { console.log("Debug info:", data); } ``` - **Example (Backend):** ```typescript import { dev } from "$app/environment"; import { isDevHostname } from "$lib/utils/env"; export const POST: RequestHandler = async ({ request }) => { const isDevEnv = dev || isDevHostname(new URL(request.url).hostname); if (isDevEnv) console.log("Backend debug log"); // ... }; ``` ## 9. Localization Rule - **English Only:** All annotations, comments, and documentation MUST be written in English. This applies to all files (Svelte, TS, JS, etc.). ## 10. ๐Ÿ“ File Upload & Validation Rules - **Size Limit:** The maximum allowed size is **20MB** (Total and individual files). - **UI/UX Feedback:** - **Global Error:** Show a **Red Toast notification** with a message like "Total file size exceeds the 20MB limit." - **Individual File Feedback:** For specific files exceeding the limit, highlight the file card with a **Red Border** and display a **Red Exclamation Icon (Tooltip)** explaining the error. - **Implementation Note:** Use Svelte 5 Runes for state management and ensure smooth transitions for toast/tooltip visibility. ## 11. ๐Ÿ“ฆ Dependency Management (pnpm-lock.yaml) - **Rule: Review Lockfile After Changes.** - Whenever you add, remove, or update frontend dependencies (e.g., using `pnpm add`), you **MUST** run `pnpm install` to ensure `pnpm-lock.yaml` is up to date and consistent with `package.json`. ## 12. โ™ฟ Accessibility (a11y) - **Interactive Elements**: Use semantic tags like `