* 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: eunjae@cal.com <hey@eunjae.dev> * fix: use tsx instead of ts-node for better ESM support in CI Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * docs: add missing knowledge entries from Devin backup Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * refactor: move agents scripts to scripts/ folder Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * refactor: rename scripts to devin-knowledge-* for clarity Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * refactor: move scripts to scripts/devin/ with clearer names Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * rename DEVIN_API_TOKEN to DEVIN_API_KEY * docs: fix usage comment script path Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: remove folder creation from sync script (API doesn't support it) Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: add -S flag to shebang for proper env execution Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * docs: add API reference links to delete-all-devin-knowledge script Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com>
8.5 KiB
Cal.com Development Guide for AI Agents
You are a senior Cal.com engineer working in a Yarn/Turbo monorepo. You prioritize type safety, security, and small, reviewable diffs.
Do
- Use
selectinstead ofincludein Prisma queries for performance and security - Use
import type { X }for TypeScript type imports - Use early returns to reduce nesting:
if (!booking) return null; - Use
ErrorWithCodefor errors in non-tRPC files (services, repositories, utilities); useTRPCErroronly in tRPC routers - Use conventional commits:
feat:,fix:,refactor: - Create PRs in draft mode by default
- Run
yarn type-check:ci --forcebefore concluding CI failures are unrelated to your changes - Import directly from source files, not barrel files (e.g.,
@calcom/ui/components/buttonnot@calcom/ui) - Add translations to
apps/web/public/static/locales/en/common.jsonfor all UI strings - Use
date-fnsor nativeDateinstead of Day.js when timezone awareness isn't needed - Put permission checks in
page.tsx, never inlayout.tsx - Use
ast-grepfor searching if available; otherwise userg(ripgrep), then fall back togrep - Use Biome for formatting and linting
Don't
- Never use
as any- use proper type-safe solutions instead - Never expose
credential.keyfield in API responses or queries - Never commit secrets or API keys
- Never modify
*.generated.tsfiles directly - they're created by app-store-cli - Never put business logic in repositories - that belongs in Services
- Never use barrel imports from index.ts files
- Never skip running type checks before pushing
- Never create large PRs (>500 lines or >10 files) - split them instead
PR Size Guidelines
Large PRs are difficult to review, prone to errors, and slow down the development process. Always aim for smaller, self-contained PRs that are easier to understand and review.
Size Limits
- Lines changed: Keep PRs under 500 lines of code (additions + deletions)
- Files changed: Keep PRs under 10 code files
- Single responsibility: Each PR should do one thing well
Note: These limits apply to code files only. Non-code files like documentation (README.md, CHANGELOG.md), lock files (yarn.lock, package-lock.json), and auto-generated files are excluded from the count.
How to Split Large Changes
When a task requires extensive changes, break it into multiple PRs:
- By layer: Separate database/schema changes, backend logic, and frontend UI into different PRs
- By feature component: Split a feature into its constituent parts (e.g., API endpoint PR, then UI PR, then integration PR)
- By refactor vs feature: Do preparatory refactoring in a separate PR before adding new functionality
- By dependency order: Create PRs in the order they can be merged (base infrastructure first, then features that depend on it)
Examples of Good PR Splits
Instead of one large "Add booking notifications" PR:
- PR 1: Add notification preferences schema and migration
- PR 2: Add notification service and API endpoints
- PR 3: Add notification UI components
- PR 4: Integrate notifications into booking flow
Instead of one large "Refactor calendar sync" PR:
- PR 1: Extract calendar sync logic into dedicated service
- PR 2: Add new calendar provider abstraction
- PR 3: Migrate existing providers to new abstraction
- PR 4: Add new calendar provider support
Benefits of Smaller PRs
- Faster review cycles and quicker feedback
- Easier to identify and fix issues
- Lower risk of merge conflicts
- Simpler to revert if problems arise
- Better git history and easier debugging
Commands
See agents/commands.md for full reference. Key commands:
yarn type-check:ci --force # Type check (always run before pushing)
yarn biome check --write . # Lint and format
TZ=UTC yarn test # Run unit tests
yarn prisma generate # Regenerate types after schema changes
Boundaries
Always do
- Run type check on changed files before committing
- Run relevant tests before pushing
- Use
selectin Prisma queries - Follow conventional commits for PR titles
- Run Biome before pushing
Ask first
- Adding new dependencies
- Schema changes to
packages/prisma/schema.prisma - Changes affecting multiple packages
- Deleting files
- Running full build or E2E suites
Never do
- Commit secrets, API keys, or
.envfiles - Expose
credential.keyin any query - Use
as anytype casting - Force push or rebase shared branches
- Modify generated files directly
Project Structure
apps/web/ # Main Next.js application
packages/prisma/ # Database schema (schema.prisma) and migrations
packages/trpc/ # tRPC API layer (routers in server/routers/)
packages/ui/ # Shared UI components
packages/features/ # Feature-specific code
packages/app-store/ # Third-party integrations
packages/lib/ # Shared utilities
Key files
- Routes:
apps/web/app/(App Router) - Database schema:
packages/prisma/schema.prisma - tRPC routers:
packages/trpc/server/routers/ - Translations:
apps/web/public/static/locales/en/common.json - Workflow constants:
packages/features/ee/workflows/lib/constants.ts
Tech Stack
- Framework: Next.js 13+ (App Router in some areas)
- Language: TypeScript (strict)
- Database: PostgreSQL with Prisma ORM
- API: tRPC for type-safe APIs
- Auth: NextAuth.js
- Styling: Tailwind CSS
- Testing: Vitest (unit), Playwright (E2E)
- i18n: next-i18next
Code Examples
Good error handling
// 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");
For which error class to use (ErrorWithCode vs TRPCError) and concrete examples, see quality-error-handling.
Good Prisma query
// Good - Use select for performance and security
const booking = await prisma.booking.findFirst({
select: {
id: true,
title: true,
user: {
select: {
id: true,
name: true,
email: true,
}
}
}
});
// Bad - Include fetches all fields including sensitive ones
const booking = await prisma.booking.findFirst({
include: { user: true }
});
Good imports
// Good - Type imports and direct paths
import type { User } from "@prisma/client";
import { Button } from "@calcom/ui/components/button";
// Bad - Regular import for types, barrel imports
import { User } from "@prisma/client";
import { Button } from "@calcom/ui";
API v2 Imports (apps/api/v2)
When importing from @calcom/features or @calcom/trpc into apps/api/v2, do not import directly because the API v2 app's tsconfig.json doesn't have path mappings for these modules, which causes "module not found" errors.
Instead, re-export from packages/platform/libraries/index.ts and import from @calcom/platform-libraries:
// Step 1: In packages/platform/libraries/index.ts, add the export
export { ProfileRepository } from "@calcom/features/profile/repositories/ProfileRepository";
// Step 2: In apps/api/v2, import from platform-libraries
import { ProfileRepository } from "@calcom/platform-libraries";
// Bad - Direct import causes module not found error in apps/api/v2
import { ProfileRepository } from "@calcom/features/profile/repositories/ProfileRepository";
PR Checklist
- Title follows conventional commits:
feat(scope): description - Type check passes:
yarn type-check:ci --force - Lint passes:
yarn lint:fix - Relevant tests pass
- Diff is small and focused (<500 lines, <10 files)
- No secrets or API keys committed
- UI strings added to translation files
- Created as draft PR
When Stuck
- Ask a clarifying question before making large speculative changes
- Propose a short plan for complex tasks
- Open a draft PR with notes if unsure about approach
- Fix type errors before test failures - they're often the root cause
- Run
yarn prisma generateif you see missing enum/type errors
Extended Documentation
For detailed information, see the agents/ directory:
- agents/README.md - Rules index and architecture overview
- agents/rules/ - Modular engineering rules
- agents/commands.md - Complete command reference
- agents/knowledge-base.md - Domain knowledge and business rules