feat: add GitHub workflows to sync agents/ to Devin Knowledge (#26994)
* feat: add GitHub workflows to sync agents/ to Devin Knowledge - Add parse-to-devin-knowledge.ts to convert agents/ markdown to Devin Knowledge JSON - Add validate-format.ts to validate rules have frontmatter and knowledge-base sections start with 'When...' - Add sync-to-devin.ts to sync knowledge entries to Devin API - Add export-devin-knowledge.sh to backup existing Devin knowledge - Add validate-agents-format.yml workflow to validate format on PRs - Add sync-agents-to-devin.yml workflow to sync on merge to main - Add devin-knowledge.json to .gitignore (generated file) Co-Authored-By: [email protected] <[email protected]> * fix: use tsx instead of ts-node for better ESM support in CI Co-Authored-By: [email protected] <[email protected]> * docs: add missing knowledge entries from Devin backup Co-Authored-By: [email protected] <[email protected]> * refactor: move agents scripts to scripts/ folder Co-Authored-By: [email protected] <[email protected]> * refactor: rename scripts to devin-knowledge-* for clarity Co-Authored-By: [email protected] <[email protected]> * refactor: move scripts to scripts/devin/ with clearer names Co-Authored-By: [email protected] <[email protected]> * rename DEVIN_API_TOKEN to DEVIN_API_KEY * docs: fix usage comment script path Co-Authored-By: [email protected] <[email protected]> * fix: remove folder creation from sync script (API doesn't support it) Co-Authored-By: [email protected] <[email protected]> * fix: add -S flag to shebang for proper env execution Co-Authored-By: [email protected] <[email protected]> * use pull_request_target * fix: add -S flag to shebang in sync-knowledge-to-devin.ts for proper env execution Co-Authored-By: unknown <> * restructure workflows * refactor: consolidate agent docs and split knowledge-base into modular rules - Delete knowledge-base.md, migrate content to 17 new rule files - Delete coding-standards.md (content duplicated in AGENTS.md and rules) - Add ci- and reference- prefixes to rules/_sections.md - Update AGENTS.md to reference new rule files - Update agents/README.md as rules index - Clean up parse-local-knowledge.ts (remove deleted file references) New rule files: - testing-playwright, testing-mocking, testing-timezone - ci-check-failures, ci-type-check-first, ci-git-workflow - data-prisma-migrations, data-prisma-feature-flags - quality-error-handling, quality-imports, quality-pr-creation, quality-code-comments - architecture-features-modules - patterns-workflow-triggers, patterns-app-store - reference-file-locations, reference-local-dev Co-Authored-By: Claude Opus 4.5 <[email protected]> * Revert "refactor: consolidate agent docs and split knowledge-base into modular rules" This reverts commit 8251b6b214c7c01a3bfe2137c6aa9292dd72427e. * refactor: reorganize agent docs - extract coding rules, keep domain knowledge - Slim down knowledge-base.md (356 → 96 lines) to domain knowledge only - Add Business rules section (managed events, orgs/teams, OAuth clients) - Delete coding-standards.md (content moved to rules) - Create 19 new rule files for coding guidelines: - quality-*: PR creation, error handling, imports, comments, code review - testing-*: playwright, mocking, timezone, incremental - ci-*: check failures, type-check-first, git workflow - data-prisma-*: migrations, feature flags - patterns-*: workflow triggers, app store - architecture-features-modules, reference-file-locations, reference-local-dev - Update agents/README.md as rules index (43 total rules) - Update _sections.md with CI/CD and Reference sections - Clean up parse-local-knowledge.ts Co-Authored-By: Claude Opus 4.5 <[email protected]> * fix: rename knowledge-base sections to start with "When..." Update section headers to pass validation rules: - "Business Rules" → "When working with managed events, organizations, or OAuth clients" - "Product & Codebase Knowledge" → "When you need product or codebase context" Co-Authored-By: Claude Opus 4.5 <[email protected]> * refactor: split knowledge-base business rules into separate sections Split the combined "When working with managed events, organizations, or OAuth clients" section into three distinct ## sections for better Devin triggering: - When working with managed event types - When working with organizations and teams - When working with OAuth clients Co-Authored-By: Claude Opus 4.5 <[email protected]> * refactor: simplify trigger description logic in parse-local-knowledge.ts Since validate-local-knowledge.ts enforces that all section titles must start with "When...", we can remove the manual fallback logic and just use the title directly as the trigger description. Co-Authored-By: Claude Opus 4.5 <[email protected]> * refactor: simplify knowledge-base section validation Simplify the validation to only check that section titles start with "When..." since we've standardized on that pattern. Remove the special cases for error, file naming, PR, and repo note sections. Co-Authored-By: Claude Opus 4.5 <[email protected]> * feat: add script to delete all Devin knowledge entries Add delete-all-devin-knowledge.ts script that: - Lists all knowledge entries before deletion - Requires interactive confirmation (Y) to proceed - Blocks execution in non-TTY environments (CI, piped input) - Shows progress while deleting entries Co-Authored-By: Claude Opus 4.5 <[email protected]> * docs: add API reference links to delete-all-devin-knowledge script Co-Authored-By: Claude Opus 4.5 <[email protected]> * fix: replace NOW() with CURRENT_TIMESTAMP in feature flag migration example Co-Authored-By: unknown <> * add -S * docs: consolidate agent documentation and add AI setup guide - Remove duplicated Project Structure & Tech Stack from agents/README.md - Condense Commands section in AGENTS.md, link to agents/commands.md - Add AI-Assisted Development section to root README.md explaining the agents/ folder structure and symlink configuration Co-Authored-By: Claude Opus 4.5 <[email protected]> * docs: remove incorrect CLAUDE.md symlink claim from README Co-Authored-By: unknown <> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <[email protected]>
This commit is contained in:
34 files changed
+1823
-485
No files matched your search
@@ -44,3 +44,13 @@ The section ID (in parentheses) is the filename prefix used to group rules.
|
||||
|
||||
**Impact:** MEDIUM
|
||||
**Description:** Engineering culture, accountability, and collaboration standards.
|
||||
|
||||
## 9. CI/CD (ci)
|
||||
|
||||
**Impact:** HIGH
|
||||
**Description:** Continuous integration practices, type checking priorities, and git workflow standards.
|
||||
|
||||
## 10. Reference (reference)
|
||||
|
||||
**Impact:** LOW
|
||||
**Description:** Informational lookups, file locations, and local development setup guides.
|
||||
@@ -0,0 +1,54 @@
|
||||
---
|
||||
title: packages/features vs apps/web/modules
|
||||
impact: HIGH
|
||||
impactDescription: Wrong placement causes tight coupling and import issues
|
||||
tags: architecture, features, modules, trpc
|
||||
---
|
||||
|
||||
# packages/features vs apps/web/modules
|
||||
|
||||
## packages/features
|
||||
|
||||
The `packages/features` package should contain only framework-agnostic code:
|
||||
- Repositories (data access layer)
|
||||
- Services (business logic)
|
||||
- Core utilities and helpers
|
||||
- Types and interfaces
|
||||
|
||||
**Files in `packages/features/**` should NOT import from `@calcom/trpc`.**
|
||||
|
||||
## apps/web/modules
|
||||
|
||||
Web-specific code, particularly anything that uses tRPC, should live in `apps/web/modules/...`:
|
||||
- React hooks that use tRPC queries/mutations
|
||||
- tRPC-specific utilities
|
||||
- Web-only UI components that depend on tRPC
|
||||
|
||||
## Example Structure
|
||||
|
||||
```
|
||||
packages/features/feature-opt-in/
|
||||
├── repository/
|
||||
│ └── FeatureOptInRepository.ts # Data access - OK here
|
||||
├── service/
|
||||
│ └── FeatureOptInService.ts # Business logic - OK here
|
||||
└── types.ts # Types - OK here
|
||||
|
||||
apps/web/modules/feature-opt-in/
|
||||
└── hooks/
|
||||
└── useFeatureOptIn.ts # tRPC hook - MUST be here
|
||||
```
|
||||
|
||||
## Why This Matters
|
||||
|
||||
```typescript
|
||||
// ❌ Bad - tRPC hook in packages/features
|
||||
// packages/features/feature-opt-in/hooks/useFeatureOptIn.ts
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
// ✅ Good - tRPC hook in apps/web/modules
|
||||
// apps/web/modules/feature-opt-in/hooks/useFeatureOptIn.ts
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
```
|
||||
|
||||
This separation ensures that `packages/features` remains portable and can be used by other apps (like `apps/api/v2`) without pulling in web-specific dependencies.
|
||||
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: CI Check Failure Handling
|
||||
impact: HIGH
|
||||
impactDescription: Misinterpreting CI failures wastes debugging time
|
||||
tags: ci, debugging, workflow
|
||||
---
|
||||
|
||||
# CI Check Failure Handling
|
||||
|
||||
## What to Focus On
|
||||
|
||||
When reviewing CI check failures in Cal.com:
|
||||
|
||||
1. **E2E tests can be flaky** and may fail intermittently
|
||||
2. **Focus only on CI failures that are directly related to your code changes**
|
||||
3. Infrastructure-related failures (like dependency installation issues) can be disregarded if all code-specific checks pass
|
||||
|
||||
## Known CI Issues to Ignore
|
||||
|
||||
These errors are related to SAML database misconfiguration on CI and should be ignored:
|
||||
- "password authentication failed for user postgres"
|
||||
- "Invalid URL"
|
||||
|
||||
## E2E Tests Skipping
|
||||
|
||||
**E2E tests skipping is expected behavior:**
|
||||
- When E2E tests are skipped, it's because the `ready-for-e2e` label has not been added to the PR
|
||||
- The "required" check intentionally fails when E2E tests are skipped to prevent merging without E2E
|
||||
- Do not try to fix anything related to skipped E2E tests - this is completely expected and normal
|
||||
|
||||
## Before Blaming CI
|
||||
|
||||
Always run type checks locally using `yarn type-check:ci --force` before concluding that CI failures are unrelated to your changes. Even if errors appear in files you haven't directly modified, your changes might still be causing type issues through dependencies or type inference.
|
||||
@@ -0,0 +1,37 @@
|
||||
---
|
||||
title: Git and CI Workflow
|
||||
impact: HIGH
|
||||
impactDescription: Incorrect workflow causes wasted CI cycles and confusion
|
||||
tags: git, ci, workflow
|
||||
---
|
||||
|
||||
# Git and CI Workflow
|
||||
|
||||
## Push Before Checking CI
|
||||
|
||||
Always push committed changes to the remote repository before waiting for or checking CI status.
|
||||
|
||||
Waiting for CI checks on unpushed local commits is backwards - the CI runs on the remote repository state, not local commits.
|
||||
|
||||
**Proper sequence:**
|
||||
1. Commit locally
|
||||
2. Run local checks (`yarn type-check:ci --force`, `yarn biome check --write .`)
|
||||
3. Push to remote
|
||||
4. Monitor CI status
|
||||
|
||||
## Branch Operations
|
||||
|
||||
When asked to move changes to a different branch, use git commands to commit existing changes to the specified branch rather than redoing the work. This is more efficient and prevents duplication of effort.
|
||||
|
||||
## Never Force Push
|
||||
|
||||
**Never force push to main or production branches** - under any circumstances.
|
||||
|
||||
## Working with tRPC Changes
|
||||
|
||||
When making changes that affect tRPC components or after pulling updates that modify tRPC-related files:
|
||||
|
||||
1. First run `yarn prisma generate` to ensure all database types are up-to-date
|
||||
2. Then run `cd packages/trpc && yarn build` to rebuild the tRPC package
|
||||
|
||||
This sequence ensures that type definitions are properly generated before building.
|
||||
@@ -0,0 +1,43 @@
|
||||
---
|
||||
title: Type Check Before Tests
|
||||
impact: HIGH
|
||||
impactDescription: Type errors are often the root cause of test failures
|
||||
tags: ci, typescript, type-check, workflow
|
||||
---
|
||||
|
||||
# Type Check Before Tests
|
||||
|
||||
## Priority Order
|
||||
|
||||
When working on the Cal.com repository, prioritize fixing type issues before addressing failing tests.
|
||||
|
||||
1. Run `yarn type-check:ci --force` first
|
||||
2. Fix all TypeScript errors
|
||||
3. Then run tests with `TZ=UTC yarn test`
|
||||
|
||||
## Why Type Check First
|
||||
|
||||
Type errors are often the root cause of test failures. Fixing types first:
|
||||
- Eliminates cascading failures
|
||||
- Ensures code compiles correctly
|
||||
- Catches issues that tests might miss
|
||||
|
||||
## Comparing Branches
|
||||
|
||||
Compare type check results between the main branch and your feature branch to confirm whether you've introduced new type errors:
|
||||
|
||||
```bash
|
||||
# On your branch
|
||||
yarn type-check:ci --force 2>&1 | tee /tmp/feature-types.log
|
||||
|
||||
# On main
|
||||
git checkout main
|
||||
yarn type-check:ci --force 2>&1 | tee /tmp/main-types.log
|
||||
|
||||
# Compare
|
||||
diff /tmp/main-types.log /tmp/feature-types.log
|
||||
```
|
||||
|
||||
## Missing Enum Errors
|
||||
|
||||
If you encounter errors related to missing enum values (like `CreationSource.WEBAPP`), running `yarn prisma generate` will typically resolve these issues by regenerating the TypeScript types from the schema.
|
||||
@@ -0,0 +1,40 @@
|
||||
---
|
||||
title: Feature Flag Seeding
|
||||
impact: MEDIUM
|
||||
impactDescription: Proper feature flag setup enables controlled rollouts
|
||||
tags: prisma, feature-flags, migrations
|
||||
---
|
||||
|
||||
# Feature Flag Seeding
|
||||
|
||||
## Creating Feature Flag Migrations
|
||||
|
||||
To seed new feature flags in Cal.com, create a Prisma migration:
|
||||
|
||||
```bash
|
||||
yarn prisma migrate dev --create-only --name seed_[feature_name]_feature
|
||||
```
|
||||
|
||||
## Migration File Location
|
||||
|
||||
The migration file should be placed in `packages/prisma/migrations/` with a timestamp prefix format:
|
||||
|
||||
```
|
||||
20250724210733_seed_calendar_cache_sql_features/migration.sql
|
||||
```
|
||||
|
||||
## SQL Structure
|
||||
|
||||
Follow the pattern from existing feature seeding migrations like:
|
||||
`packages/prisma/migrations/20241216000000_add_calendar_cache_serve/migration.sql`
|
||||
|
||||
```sql
|
||||
INSERT INTO "Feature" ("slug", "enabled", "type", "description", "createdAt", "updatedAt")
|
||||
VALUES
|
||||
('your-feature-slug', false, 'OPERATIONAL', 'Description of feature', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT ("slug") DO NOTHING;
|
||||
```
|
||||
|
||||
The migration should INSERT the new features into the `Feature` table with:
|
||||
- Appropriate type (like `OPERATIONAL`)
|
||||
- Default `enabled` status for manual team enablement
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
title: Prisma Schema and Migrations
|
||||
impact: HIGH
|
||||
impactDescription: Schema changes affect all downstream code and deployments
|
||||
tags: prisma, database, migrations, schema
|
||||
---
|
||||
|
||||
# Prisma Schema and Migrations
|
||||
|
||||
## After Schema Changes
|
||||
|
||||
After making changes to the Prisma schema in Cal.com and creating migrations, you need to run:
|
||||
|
||||
```bash
|
||||
yarn prisma generate
|
||||
```
|
||||
|
||||
This updates the TypeScript types. This is especially important:
|
||||
- When switching Node.js versions
|
||||
- After adding new fields to models
|
||||
- After pulling changes that include Prisma schema updates
|
||||
|
||||
## Creating Migrations
|
||||
|
||||
```bash
|
||||
# Development migration
|
||||
npx prisma migrate dev --name migration_name
|
||||
|
||||
# Production deployment
|
||||
yarn workspace @calcom/prisma db-deploy
|
||||
```
|
||||
|
||||
## Timestamp Fields
|
||||
|
||||
When adding timestamp fields like `createdAt` and `updatedAt`:
|
||||
- Do not set default values if you want existing records to have null values
|
||||
- Only new records should get timestamps automatically
|
||||
- For `updatedAt` fields, ensure they're updated when records are modified
|
||||
|
||||
## Squash Migrations
|
||||
|
||||
Whenever you change the schema.prisma file, remember to always consolidate migrations by squashing them as declared in the [Prisma docs](https://www.prisma.io/docs/orm/prisma-migrate/workflows/squashing-migrations).
|
||||
|
||||
This helps maintain a clean migration history and prevents accumulation of multiple migration files.
|
||||
|
||||
## Enum Generator Errors
|
||||
|
||||
If you encounter enum generator errors during the Prisma generate step (like "Cannot find module './enum-generator.ts'"), run `yarn install` first before trying to generate.
|
||||
|
||||
## Cache-Related Features
|
||||
|
||||
When implementing cache-related features that require timestamp tracking, always update the database schema first before modifying application code that references those fields.
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
title: App Store Integration Patterns
|
||||
impact: MEDIUM
|
||||
impactDescription: App store integrations require specific patterns for generated files
|
||||
tags: app-store, integrations, generated-files
|
||||
---
|
||||
|
||||
# App Store Integration Patterns
|
||||
|
||||
## Generated Files
|
||||
|
||||
The Cal.com repository uses generated files (`*.generated.ts`) for app-store integrations. These files are created by the app-store-cli tool.
|
||||
|
||||
**Do not manually modify** `*.generated.ts` files. If you need structural changes to how integrations are imported or used, update the CLI code that generates these files.
|
||||
|
||||
## Import Patterns
|
||||
|
||||
Recent changes have moved from dynamic imports to static map-based imports for better performance. When working with browser components in the app-store, static imports should be used rather than dynamic imports.
|
||||
|
||||
### Generated File Types
|
||||
|
||||
When modifying the app-store-cli `build.ts` file, ensure it correctly handles all types:
|
||||
|
||||
1. **Regular service files** (`calendar.services.generated.ts`, `crm.services.generated.ts`, etc.) - need default imports
|
||||
2. **Browser component files** (`apps.browser-addon.generated.tsx`, etc.) - may require dynamic imports with Next.js
|
||||
|
||||
The `lazyImport` parameter in `getExportedObject()` determines whether to use dynamic imports (for browser components) or static imports (for server-side services).
|
||||
|
||||
## Calendar Cache Features
|
||||
|
||||
The calendar cache system follows specific patterns in `packages/features/calendar-cache-sql`. When implementing provider-specific calendar cache services (like for Outlook/Office365), the provider-specific code should be placed in the corresponding provider directory (e.g., `packages/app-store/office365calendar`).
|
||||
@@ -0,0 +1,39 @@
|
||||
---
|
||||
title: Workflow Trigger Implementation
|
||||
impact: MEDIUM
|
||||
impactDescription: Consistent workflow patterns ensure reliable automation
|
||||
tags: workflows, triggers, automation
|
||||
---
|
||||
|
||||
# Workflow Trigger Implementation
|
||||
|
||||
## Using scheduleWorkflowReminders
|
||||
|
||||
To trigger workflows in Cal.com, use the `scheduleWorkflowReminders` function. This is the standard approach used throughout the codebase.
|
||||
|
||||
Before implementing new workflow triggers, examine existing implementations in the codebase to understand the pattern. The function:
|
||||
- Filters workflows by trigger type
|
||||
- Processes each workflow step
|
||||
|
||||
Key locations where this is used:
|
||||
- Booking handlers
|
||||
- Confirmation processes
|
||||
- Other booking-related events
|
||||
|
||||
## Adding New Workflow Triggers
|
||||
|
||||
1. Check `packages/prisma/schema.prisma` for existing webhooks and workflow trigger enums as reference
|
||||
2. Add the same enums to workflows (only when asked specifically)
|
||||
3. Add enums to `packages/features/ee/workflows/lib/constants.ts` for UI display
|
||||
4. Add translations to `en/locale.json` using the format `{enum}_trigger` (all lowercase)
|
||||
|
||||
Webhook triggers serve as the reference implementation pattern for workflow triggers.
|
||||
|
||||
## Workflows vs Webhooks
|
||||
|
||||
Workflows and webhooks are two completely separate features in Cal.com with different implementations and file structures:
|
||||
|
||||
- Workflow constants: `packages/features/ee/workflows/lib/constants.ts`
|
||||
- NOT in the webhooks directory
|
||||
|
||||
When working on workflow triggers, do not reference or use webhook trigger implementations - they are distinct systems.
|
||||
@@ -0,0 +1,48 @@
|
||||
---
|
||||
title: Code Comment Guidelines
|
||||
impact: MEDIUM
|
||||
impactDescription: Excessive comments add noise; missing comments hurt maintainability
|
||||
tags: comments, documentation, readability
|
||||
---
|
||||
|
||||
# Code Comment Guidelines
|
||||
|
||||
## General Principle
|
||||
|
||||
Keep comments limited and avoid obvious ones. Comments should explain "why" not "what" - the code itself should be clear enough to explain what it does.
|
||||
|
||||
## When to Comment
|
||||
|
||||
- Complex business logic that isn't obvious from the code
|
||||
- Workarounds or hacks with explanation of why they're needed
|
||||
- Non-obvious performance optimizations
|
||||
- Important security considerations
|
||||
|
||||
## When NOT to Comment
|
||||
|
||||
```typescript
|
||||
// ❌ Bad - Obvious comment
|
||||
// Get the user
|
||||
const user = await getUser(userId);
|
||||
|
||||
// ❌ Bad - Restating the code
|
||||
// Loop through bookings
|
||||
for (const booking of bookings) {
|
||||
// Process booking
|
||||
processBooking(booking);
|
||||
}
|
||||
```
|
||||
|
||||
## Good Examples
|
||||
|
||||
```typescript
|
||||
// ✅ Good - Explains why, not what
|
||||
// We need to fetch availability before slots because the timezone
|
||||
// conversion depends on the user's configured availability rules
|
||||
const availability = await getAvailability(userId);
|
||||
const slots = convertToSlots(availability, timezone);
|
||||
|
||||
// ✅ Good - Documents a non-obvious constraint
|
||||
// Google Calendar API has a 2500 event limit per sync request
|
||||
const BATCH_SIZE = 2500;
|
||||
```
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: Code Review Focus
|
||||
impact: MEDIUM
|
||||
impactDescription: Focused reviews are more useful than scattered feedback
|
||||
tags: code-review, workflow
|
||||
---
|
||||
|
||||
# Code Review Focus
|
||||
|
||||
## When Asked to Review a PR
|
||||
|
||||
Focus on providing a clear summary of what the PR is doing and its core functionality.
|
||||
|
||||
**Avoid getting sidetracked by:**
|
||||
- CI failures
|
||||
- Testing issues
|
||||
- Technical implementation details (unless specifically requested)
|
||||
|
||||
## Good Review Structure
|
||||
|
||||
1. **Summary**: What does this PR do?
|
||||
2. **Core changes**: What are the main code changes?
|
||||
3. **Impact**: What parts of the system does this affect?
|
||||
|
||||
## What to Look For
|
||||
|
||||
- Does the code do what it claims to do?
|
||||
- Are there any obvious bugs or edge cases?
|
||||
- Does it follow Cal.com coding standards?
|
||||
- Is the change appropriately scoped?
|
||||
|
||||
## What to Skip (Unless Asked)
|
||||
|
||||
- Nitpicks about style (Biome handles this)
|
||||
- Suggestions for refactoring unrelated code
|
||||
- Deep dives into implementation details
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
title: Error Handling Patterns
|
||||
impact: HIGH
|
||||
impactDescription: Proper error handling ensures debuggable and secure code
|
||||
tags: errors, trpc, services, repositories
|
||||
---
|
||||
|
||||
# Error Handling Patterns
|
||||
|
||||
## Descriptive Errors
|
||||
|
||||
```typescript
|
||||
// ✅ Good - Descriptive error with context
|
||||
throw new Error(`Unable to create booking: User ${userId} has no available time slots for ${date}`);
|
||||
|
||||
// ❌ Bad - Generic error
|
||||
throw new Error("Booking failed");
|
||||
```
|
||||
|
||||
## ErrorWithCode vs TRPCError
|
||||
|
||||
Use `ErrorWithCode` for files that are not directly coupled to tRPC. The tRPC package has a middleware called `errorConversionMiddleware` that automatically converts `ErrorWithCode` instances into `TRPCError` instances.
|
||||
|
||||
### In Non-tRPC Files (services, repositories, utilities)
|
||||
|
||||
```typescript
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { ErrorWithCode } from "@calcom/lib/errors";
|
||||
|
||||
// Option 1: Using constructor with ErrorCode enum
|
||||
throw new ErrorWithCode(ErrorCode.BookingNotFound, "Booking not found");
|
||||
|
||||
// Option 2: Using the Factory pattern for common HTTP errors
|
||||
throw ErrorWithCode.Factory.Forbidden("You don't have permission to view this");
|
||||
throw ErrorWithCode.Factory.NotFound("Resource not found");
|
||||
throw ErrorWithCode.Factory.BadRequest("Invalid input");
|
||||
```
|
||||
|
||||
### In tRPC Routers Only
|
||||
|
||||
```typescript
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Invalid booking time slot",
|
||||
});
|
||||
```
|
||||
|
||||
## packages/features Import Restrictions
|
||||
|
||||
Files in `packages/features/**` should NOT import from `@calcom/trpc`. This keeps the features package decoupled from the tRPC layer, making the code more reusable and testable. Use `ErrorWithCode` for error handling in these files.
|
||||
@@ -0,0 +1,49 @@
|
||||
---
|
||||
title: Import and Export Patterns
|
||||
impact: MEDIUM
|
||||
impactDescription: Incorrect imports cause build failures and bundle bloat
|
||||
tags: imports, exports, modules, app-store
|
||||
---
|
||||
|
||||
# Import and Export Patterns
|
||||
|
||||
## Named vs Default Exports
|
||||
|
||||
When working with imports in the Cal.com codebase, particularly in app-store integrations, pay attention to whether modules use named exports or default exports.
|
||||
|
||||
Many services like VideoApiAdapter, CalendarService, and PaymentService are exported as named exports, but the actual export name may differ from the generic service type.
|
||||
|
||||
```typescript
|
||||
// ✅ Good - Verify actual export name and use named import
|
||||
import { AppleCalendarService } from "./applecalendar/lib/CalendarService";
|
||||
|
||||
// With renaming if needed
|
||||
import { AppleCalendarService as ApplecalendarCalendarService } from "./applecalendar/lib/CalendarService";
|
||||
|
||||
// ❌ Bad - Assuming default export without checking
|
||||
import CalendarService from "./applecalendar/lib/CalendarService";
|
||||
```
|
||||
|
||||
## Generated Files
|
||||
|
||||
When fixing imports in Cal.com's generated files (like `packages/app-store/apps.browser-*.generated.tsx`), always check the actual exports in the source files first.
|
||||
|
||||
For EventTypeAppCardInterface components, they likely use named exports rather than default exports, requiring:
|
||||
|
||||
```typescript
|
||||
import * as ComponentName from "./path";
|
||||
// instead of
|
||||
import ComponentName from "./path";
|
||||
```
|
||||
|
||||
## Factory Function Naming
|
||||
|
||||
When creating factory functions that replace class exports, use the naming convention `Build[ServiceName]` instead of just `[ServiceName]`:
|
||||
|
||||
```typescript
|
||||
// ✅ Good - Clear factory function naming
|
||||
export function BuildPaymentService() { ... }
|
||||
|
||||
// ❌ Bad - Confusing with class export
|
||||
export function PaymentService() { ... }
|
||||
```
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: PR Creation Best Practices
|
||||
impact: HIGH
|
||||
impactDescription: PRs that don't follow guidelines slow down review cycles
|
||||
tags: pull-request, code-review, workflow
|
||||
---
|
||||
|
||||
# PR Creation Best Practices
|
||||
|
||||
## Draft Mode
|
||||
|
||||
Create pull requests in draft mode by default, so that a human reviewer can mark it as ready for review only when it is.
|
||||
|
||||
## PR Title
|
||||
|
||||
- Use conventional commits: `feat:`, `fix:`, `refactor:`
|
||||
- Be specific: `fix: handle timezone edge case in booking creation`
|
||||
- Not generic: `fix: booking bug`
|
||||
|
||||
## Size Limits
|
||||
|
||||
- **Large PRs** (>500 lines or >10 files) are not recommended
|
||||
- Split large changes by layer (database, backend, frontend)
|
||||
- Split by feature component (API, UI, integration)
|
||||
|
||||
## PR Requirements
|
||||
|
||||
- PR title must follow Conventional Commits specification
|
||||
- For most PRs, you only need to run linting and type checking
|
||||
- E2E tests will only run if PR has "ready-for-e2e" label
|
||||
|
||||
## Before Pushing
|
||||
|
||||
1. Run `yarn type-check:ci --force` to check types
|
||||
2. Run `yarn biome check --write .` to lint and format
|
||||
3. Run relevant tests locally
|
||||
@@ -0,0 +1,50 @@
|
||||
---
|
||||
title: Key File Locations
|
||||
impact: LOW
|
||||
impactDescription: Quick reference for finding important files
|
||||
tags: reference, navigation, file-locations
|
||||
---
|
||||
|
||||
# Key File Locations
|
||||
|
||||
## UI Components
|
||||
|
||||
- Event types page: `apps/web/modules/event-types/views/event-types-listing-view.tsx`
|
||||
- Bookings page: `apps/web/modules/bookings/views/bookings-view.tsx`
|
||||
- Shared UI patterns (tabs, search bars, filter buttons) should maintain consistent alignment across views
|
||||
|
||||
## Database
|
||||
|
||||
- Schema: `packages/prisma/schema.prisma`
|
||||
- Migrations: `packages/prisma/migrations/`
|
||||
|
||||
## API
|
||||
|
||||
- tRPC routers: `packages/trpc/server/routers/`
|
||||
- API v2 controllers: `apps/api/v2/src/modules/*/controllers/*.controller.ts`
|
||||
- OpenAPI spec: `docs/api-reference/v2/openapi.json` (auto-generated, don't edit manually)
|
||||
|
||||
## Features
|
||||
|
||||
- Workflow constants: `packages/features/ee/workflows/lib/constants.ts`
|
||||
- Round-robin/host prioritization: `packages/features/bookings/lib/getLuckyUser.ts`
|
||||
- Calendar cache: `packages/features/calendar-cache-sql`
|
||||
- DataTable guide: `packages/features/data-table/GUIDE.md`
|
||||
|
||||
## Translations
|
||||
|
||||
- English: `apps/web/public/static/locales/en/common.json`
|
||||
|
||||
## App Store
|
||||
|
||||
- Generated files: `packages/app-store/*.generated.ts`
|
||||
- CLI tool: `packages/app-store-cli/`
|
||||
|
||||
## File Naming Conventions
|
||||
|
||||
- **Repository files**: `PrismaBookingRepository.ts` (PascalCase with Repository suffix)
|
||||
- **Service files**: `MembershipService.ts` (PascalCase with Service suffix)
|
||||
- **Components**: `BookingForm.tsx` (PascalCase)
|
||||
- **Utilities**: `date-utils.ts` (kebab-case)
|
||||
- **Types**: `Booking.types.ts` (PascalCase with .types.ts suffix)
|
||||
- **Tests**: Same as source file + `.test.ts` or `.spec.ts`
|
||||
@@ -0,0 +1,73 @@
|
||||
---
|
||||
title: Local Development Setup
|
||||
impact: LOW
|
||||
impactDescription: Reference guide for local development environment
|
||||
tags: reference, development, setup
|
||||
---
|
||||
|
||||
# Local Development Setup
|
||||
|
||||
## Initial Setup
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
yarn
|
||||
|
||||
# Set up environment
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
|
||||
Generate required secrets:
|
||||
|
||||
```bash
|
||||
# NEXTAUTH_SECRET
|
||||
openssl rand -base64 32
|
||||
|
||||
# CALENDSO_ENCRYPTION_KEY (must be 32 characters for AES256)
|
||||
openssl rand -base64 24
|
||||
```
|
||||
|
||||
Configure in `.env`:
|
||||
- `DATABASE_URL` - PostgreSQL connection string
|
||||
- `DATABASE_DIRECT_URL` - Same as DATABASE_URL
|
||||
|
||||
## Database Setup
|
||||
|
||||
```bash
|
||||
# Development
|
||||
yarn workspace @calcom/prisma db-migrate
|
||||
|
||||
# Production
|
||||
yarn workspace @calcom/prisma db-deploy
|
||||
```
|
||||
|
||||
## Test Users
|
||||
|
||||
When setting up local development database, it creates test users. The passwords are the same as the username:
|
||||
- `free:free`
|
||||
- `pro:pro`
|
||||
|
||||
## Logging
|
||||
|
||||
Control logging verbosity by setting `NEXT_PUBLIC_LOGGER_LEVEL` in .env:
|
||||
- 0: silly
|
||||
- 1: trace
|
||||
- 2: debug
|
||||
- 3: info
|
||||
- 4: warn
|
||||
- 5: error
|
||||
- 6: fatal
|
||||
|
||||
## API v2 Imports
|
||||
|
||||
If you need to import from `@calcom/features` or `@calcom/trpc` into `apps/api/v2`, use the platform-libraries package instead:
|
||||
|
||||
```typescript
|
||||
// ✅ Good
|
||||
import { SomeService } from "@calcom/platform-libraries";
|
||||
|
||||
// ❌ Bad - Will cause module resolution errors
|
||||
import { SomeService } from "@calcom/features/...";
|
||||
```
|
||||
@@ -0,0 +1,27 @@
|
||||
---
|
||||
title: Incremental Test Fixing
|
||||
impact: MEDIUM
|
||||
impactDescription: Methodical approach prevents getting overwhelmed by test failures
|
||||
tags: testing, debugging, workflow
|
||||
---
|
||||
|
||||
# Incremental Test Fixing
|
||||
|
||||
## One File at a Time
|
||||
|
||||
When fixing failing tests in the Cal.com repository, take an incremental approach by addressing one file at a time rather than attempting to fix all issues simultaneously.
|
||||
|
||||
This methodical approach makes it easier to identify and resolve specific issues without getting overwhelmed by the complexity of multiple failing tests across different files.
|
||||
|
||||
## Recommended Order
|
||||
|
||||
1. Run `yarn type-check:ci --force` to identify TypeScript type errors
|
||||
2. Run `yarn test` to identify failing unit tests
|
||||
3. Address both type errors and failing tests before considering the task complete
|
||||
4. Type errors often need to be fixed first as they may be causing the test failures
|
||||
|
||||
## Focus Strategy
|
||||
|
||||
- Focus on getting each file's tests passing completely before moving on to the next file
|
||||
- Fix type errors before test failures - they're often the root cause
|
||||
- Run `yarn prisma generate` if you see missing enum/type errors
|
||||
@@ -0,0 +1,26 @@
|
||||
---
|
||||
title: Mock Implementation Patterns
|
||||
impact: MEDIUM
|
||||
impactDescription: Poor mocks cause flaky tests and false positives
|
||||
tags: testing, mocking, calendar, app-store
|
||||
---
|
||||
|
||||
# Mock Implementation Patterns
|
||||
|
||||
## Calendar Service Mocks
|
||||
|
||||
When mocking calendar services in Cal.com test files, implement the `Calendar` interface rather than adding individual properties from each specific calendar service type (like `FeishuCalendarService`).
|
||||
|
||||
Since all calendar services implement the `Calendar` interface and are stored in a map, the mock service should also implement this interface to ensure type compatibility.
|
||||
|
||||
## App-Store Integration Mocks
|
||||
|
||||
When mocking app-store resources in Cal.com tests, prefer implementing simpler mock designs that directly implement the required interfaces rather than trying to match complex deep mock structures created with `mockDeep`.
|
||||
|
||||
This approach is more maintainable and helps resolve type compatibility issues.
|
||||
|
||||
## General Guidance
|
||||
|
||||
- For complex mocks that cause type compatibility issues with deep mocks, consider using simpler fake implementations
|
||||
- When needed, you can modify other mock files to support your implementation
|
||||
- Creative solutions and refactoring to better designs are encouraged when standard mocking causes persistent type errors
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
title: Playwright E2E Testing
|
||||
impact: HIGH
|
||||
impactDescription: E2E tests catch integration issues before production
|
||||
tags: testing, playwright, e2e
|
||||
---
|
||||
|
||||
# Playwright E2E Testing
|
||||
|
||||
## Running Tests
|
||||
|
||||
Use the command format:
|
||||
|
||||
```bash
|
||||
PLAYWRIGHT_HEADLESS=1 yarn e2e [test-file.e2e.ts]
|
||||
```
|
||||
|
||||
This format includes the proper timezone setting, virtual display server, and uses the repository's e2e runner.
|
||||
|
||||
**Do not use** the standard `yarn playwright test` command.
|
||||
|
||||
## Local Testing First
|
||||
|
||||
Always ensure Playwright tests pass locally before pushing code. The user requires fast local e2e feedback loops instead of relying on CI, which is too slow for development iteration.
|
||||
|
||||
**Never push test code until those tests are passing locally first.**
|
||||
|
||||
## CI Behavior
|
||||
|
||||
- E2E tests will only run if PR has "ready-for-e2e" label
|
||||
- When E2E tests are skipped, the "required" check intentionally fails to prevent merging without E2E
|
||||
- Do not try to fix anything related to skipped E2E tests - this is expected behavior
|
||||
@@ -0,0 +1,37 @@
|
||||
---
|
||||
title: Timezone Handling in Tests
|
||||
impact: HIGH
|
||||
impactDescription: Timezone bugs are hard to reproduce without consistent test environments
|
||||
tags: testing, timezone, consistency
|
||||
---
|
||||
|
||||
# Timezone Handling in Tests
|
||||
|
||||
## Always Use TZ=UTC
|
||||
|
||||
When running tests in the Cal.com repository, use the `TZ=UTC` environment variable:
|
||||
|
||||
```bash
|
||||
TZ=UTC yarn test
|
||||
```
|
||||
|
||||
This ensures consistent timezone handling and prevents timezone-related test failures that might occur when tests are run in different environments or by different developers with varying local timezone settings.
|
||||
|
||||
## Why This Matters
|
||||
|
||||
- Tests may pass locally but fail in CI (or vice versa)
|
||||
- Date/time assertions become unpredictable
|
||||
- Debugging timezone issues is time-consuming
|
||||
|
||||
## Test Commands
|
||||
|
||||
```bash
|
||||
# Unit tests
|
||||
TZ=UTC yarn test
|
||||
|
||||
# Specific test file
|
||||
TZ=UTC yarn vitest run path/to/file.test.ts
|
||||
|
||||
# E2E tests (already configured in yarn e2e)
|
||||
PLAYWRIGHT_HEADLESS=1 yarn e2e
|
||||
```
|
||||
Reference in new issue
Block a user