|
2 | 2 |
|
3 | 3 | The Compass Contribution Guide is available on the official doc site: |
4 | 4 | [https://docs.compasscalendar.com/docs/how-to-contribute/contribute](https://docs.compasscalendar.com/docs/how-to-contribute/contribute) |
| 5 | + |
| 6 | +## For AI Agents |
| 7 | + |
| 8 | +This section provides specific guidelines for AI coding agents working on Compass. |
| 9 | + |
| 10 | +### Getting Started |
| 11 | + |
| 12 | +1. **Read the Documentation First** |
| 13 | + - Start with [AGENTS.md](./AGENTS.md) for complete development instructions |
| 14 | + - Review [README.md](./README.md) for project overview |
| 15 | + - Check existing issues and PRs for context |
| 16 | + |
| 17 | +2. **Environment Setup** |
| 18 | + |
| 19 | + ```bash |
| 20 | + yarn install --frozen-lockfile --network-timeout 300000 |
| 21 | + cp packages/backend/.env.local.example packages/backend/.env |
| 22 | + yarn dev:web # Verify frontend works |
| 23 | + ``` |
| 24 | + |
| 25 | +3. **Understand the Codebase** |
| 26 | + - Use `yarn ai:index` to generate semantic search index |
| 27 | + - Explore `ai-tools/` directory for helpful scripts |
| 28 | + - Review architecture in [AGENTS.md](./AGENTS.md) |
| 29 | + |
| 30 | +### Coding Standards for AI Agents |
| 31 | + |
| 32 | +#### 1. Module Imports |
| 33 | + |
| 34 | +**ALWAYS** use module aliases instead of relative paths: |
| 35 | + |
| 36 | +```typescript |
| 37 | +// ✅ Correct |
| 38 | +import { foo } from '@compass/core' |
| 39 | +import { bar } from '@web/common/utils' |
| 40 | +import { baz } from '@core/types' |
| 41 | + |
| 42 | +// ❌ Wrong |
| 43 | +import { foo } from '../../../core/src' |
| 44 | +import { bar } from '../../common/utils' |
| 45 | +``` |
| 46 | + |
| 47 | +#### 2. Type Safety and Validation |
| 48 | + |
| 49 | +**ALWAYS** use Zod for validation: |
| 50 | + |
| 51 | +```typescript |
| 52 | +import { z } from "zod"; |
| 53 | + |
| 54 | +// Define schema |
| 55 | +export const UserSchema = z.object({ |
| 56 | + id: z.string(), |
| 57 | + email: z.string().email(), |
| 58 | + name: z.string().min(1), |
| 59 | +}); |
| 60 | + |
| 61 | +// Export type from schema |
| 62 | +export type User = z.infer<typeof UserSchema>; |
| 63 | + |
| 64 | +// Use for validation |
| 65 | +export const validateUser = (data: unknown): User => UserSchema.parse(data); |
| 66 | +``` |
| 67 | + |
| 68 | +#### 3. Testing Requirements |
| 69 | + |
| 70 | +Write tests following user behavior patterns: |
| 71 | + |
| 72 | +```typescript |
| 73 | +// ✅ Correct - Using semantic queries |
| 74 | +const button = screen.getByRole('button', { name: /save/i }); |
| 75 | +await user.click(button); |
| 76 | + |
| 77 | +// ❌ Wrong - Using implementation details |
| 78 | +const button = container.querySelector('.save-button'); |
| 79 | +button.click(); |
| 80 | +``` |
| 81 | + |
| 82 | +#### 4. API Route Documentation |
| 83 | + |
| 84 | +Document all backend routes with JSDoc: |
| 85 | + |
| 86 | +```typescript |
| 87 | +/** |
| 88 | + * Get user profile information |
| 89 | + * @route GET /api/user/profile |
| 90 | + * @auth Required - Supertokens session |
| 91 | + * @returns {UserProfile} User profile data |
| 92 | + * @throws {401} Unauthorized - Invalid or missing session |
| 93 | + * @throws {404} Not Found - User not found |
| 94 | + */ |
| 95 | +.get(userController.getProfile); |
| 96 | +``` |
| 97 | + |
| 98 | +#### 5. Error Handling |
| 99 | + |
| 100 | +Always include proper error handling: |
| 101 | + |
| 102 | +```typescript |
| 103 | +try { |
| 104 | + const result = await apiCall(); |
| 105 | + return { success: true, data: result }; |
| 106 | +} catch (error) { |
| 107 | + logger.error('Operation failed', { error, context }); |
| 108 | + throw new ApiError('User-friendly message', 500); |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +### Git Workflow for AI Agents |
| 113 | + |
| 114 | +#### Branch Naming |
| 115 | + |
| 116 | +Follow semantic branch naming: |
| 117 | + |
| 118 | +```bash |
| 119 | +# Format: type/action[-issue-number] |
| 120 | +feature/add-calendar-sync |
| 121 | +bug/fix-auth-timeout |
| 122 | +docs/update-api-docs |
| 123 | +refactor/simplify-event-handler |
| 124 | +``` |
| 125 | + |
| 126 | +#### Commit Messages |
| 127 | + |
| 128 | +Use conventional commit format: |
| 129 | + |
| 130 | +```bash |
| 131 | +# Format: type(scope): description |
| 132 | +feat(web): add calendar event creation modal |
| 133 | +fix(backend): resolve authentication timeout issue |
| 134 | +docs(readme): update installation instructions |
| 135 | +refactor(core): simplify date utility functions |
| 136 | +test(web): add unit tests for login component |
| 137 | +``` |
| 138 | + |
| 139 | +**Commit Types:** |
| 140 | + |
| 141 | +- `feat` - New features |
| 142 | +- `fix` - Bug fixes |
| 143 | +- `docs` - Documentation changes |
| 144 | +- `style` - Code style changes (formatting, semicolons) |
| 145 | +- `refactor` - Code refactoring |
| 146 | +- `test` - Adding or updating tests |
| 147 | +- `chore` - Maintenance tasks, dependency updates |
| 148 | + |
| 149 | +**Scope Examples:** |
| 150 | + |
| 151 | +- `web` - Frontend/React changes |
| 152 | +- `backend` - Server/API changes |
| 153 | +- `core` - Shared utilities/types |
| 154 | +- `scripts` - CLI tools and build scripts |
| 155 | +- `config` - Configuration files |
| 156 | + |
| 157 | +### Code Review Process |
| 158 | + |
| 159 | +#### Before Submitting PR |
| 160 | + |
| 161 | +1. **Run Type Checking** |
| 162 | + |
| 163 | + ```bash |
| 164 | + yarn type-check |
| 165 | + ``` |
| 166 | + |
| 167 | +2. **Run Tests** |
| 168 | + |
| 169 | + ```bash |
| 170 | + yarn test:core |
| 171 | + yarn test:web |
| 172 | + yarn test:backend |
| 173 | + ``` |
| 174 | + |
| 175 | +3. **Check Code Health** |
| 176 | + |
| 177 | + ```bash |
| 178 | + yarn audit:code-health |
| 179 | + ``` |
| 180 | + |
| 181 | +4. **Format Code** |
| 182 | + |
| 183 | + ```bash |
| 184 | + yarn prettier . --write |
| 185 | + ``` |
| 186 | + |
| 187 | +5. **Generate Documentation** (if you added/modified APIs) |
| 188 | + ```bash |
| 189 | + yarn docs:generate |
| 190 | + ``` |
| 191 | + |
| 192 | +#### PR Description Template |
| 193 | + |
| 194 | +```markdown |
| 195 | +## Description |
| 196 | + |
| 197 | +Brief description of changes |
| 198 | + |
| 199 | +## Type of Change |
| 200 | + |
| 201 | +- [ ] Bug fix (non-breaking change fixing an issue) |
| 202 | +- [ ] New feature (non-breaking change adding functionality) |
| 203 | +- [ ] Breaking change (fix or feature causing existing functionality to change) |
| 204 | +- [ ] Documentation update |
| 205 | + |
| 206 | +## Testing |
| 207 | + |
| 208 | +- [ ] Unit tests pass (`yarn test:core`, `yarn test:web`, `yarn test:backend`) |
| 209 | +- [ ] E2E tests pass (if applicable) |
| 210 | +- [ ] Manual testing completed |
| 211 | + |
| 212 | +## Checklist |
| 213 | + |
| 214 | +- [ ] Code follows project style guidelines |
| 215 | +- [ ] Self-review completed |
| 216 | +- [ ] Comments added for complex logic |
| 217 | +- [ ] Documentation updated |
| 218 | +- [ ] No new warnings introduced |
| 219 | +- [ ] Tests added/updated as needed |
| 220 | +``` |
| 221 | + |
| 222 | +### Common Pitfalls to Avoid |
| 223 | + |
| 224 | +1. **Don't use barrel files (`index.ts`)** - Use named exports directly |
| 225 | +2. **Don't use raw Tailwind colors** - Use semantic theme colors (`bg-bg-primary` not `bg-blue-300`) |
| 226 | +3. **Don't test login without backend** - Frontend tests should work standalone |
| 227 | +4. **Don't modify unrelated code** - Keep changes surgical and focused |
| 228 | +5. **Don't skip type checking** - Always run `yarn type-check` before submitting |
| 229 | +6. **Don't ignore linter warnings** - Fix all warnings in your code |
| 230 | +7. **Don't use relative imports** - Always use module aliases |
| 231 | + |
| 232 | +### AI Tools Reference |
| 233 | + |
| 234 | +The `ai-tools/` directory contains helper scripts: |
| 235 | + |
| 236 | +- **`generate-api-docs.ts`** - Extract and document all API endpoints |
| 237 | +- **`extract-types.ts`** - Generate type documentation |
| 238 | +- **`code-health-audit.ts`** - Analyze code quality metrics |
| 239 | +- **`semantic-index.ts`** - Build search index for code navigation |
| 240 | +- **`test-harness.ts`** - Template for automated testing workflows |
| 241 | + |
| 242 | +Run any tool with: |
| 243 | + |
| 244 | +```bash |
| 245 | +yarn ts-node ai-tools/<script-name>.ts |
| 246 | +``` |
| 247 | + |
| 248 | +### Resources for AI Agents |
| 249 | + |
| 250 | +- **OpenAI Harness Engineering**: [https://openai.com/index/harness-engineering/](https://openai.com/index/harness-engineering/) |
| 251 | +- **Loop Methodology**: [https://ghuntley.com/loop/](https://ghuntley.com/loop/) |
| 252 | +- **Testing Library**: Best practices for user-centric testing |
| 253 | +- **Zod Documentation**: Type-safe validation patterns |
| 254 | + |
| 255 | +### Questions? |
| 256 | + |
| 257 | +For issues or questions: |
| 258 | + |
| 259 | +1. Check existing GitHub issues |
| 260 | +2. Review [AGENTS.md](./AGENTS.md) and docs |
| 261 | +3. Join GitHub Discussions |
| 262 | +4. Create a new issue with detailed context |
0 commit comments