Skip to content

Fix staging conflict v1#586

Merged
elie222 merged 35 commits intoelie222:stagingfrom
edulelis:fix-staging-conflict-v1
Jul 23, 2025
Merged

Fix staging conflict v1#586
elie222 merged 35 commits intoelie222:stagingfrom
edulelis:fix-staging-conflict-v1

Conversation

@edulelis
Copy link
Collaborator

@edulelis edulelis commented Jul 21, 2025

Summary by CodeRabbit

  • New Features

    • Introduced delayed actions for email processing rules, allowing users to schedule actions (e.g., archive, label, reply) to occur after a configurable delay (1 minute to 90 days).
    • Added UI controls in rule creation/editing to specify and manage action delays, including user-friendly input for delay duration.
    • Enabled new onboarding options such as "Label + archive after a week" when the delayed actions feature is enabled.
    • Added monitoring and management capabilities for scheduled actions.
  • Bug Fixes

    • Improved validation and error handling for delayed action scheduling and execution.
  • Documentation

    • Added comprehensive documentation for delayed actions, including usage examples and API endpoint details.
  • Refactor

    • Updated tooltip components for improved UI consistency and customization.
    • Refined form and onboarding flows to integrate delayed actions seamlessly.
  • Tests

    • Added unit tests for delayed action scheduling, execution, and cancellation to ensure reliability.
  • Chores

    • Updated version to v1.10.0.

edulelis added 30 commits June 18, 2025 10:12
@vercel
Copy link

vercel bot commented Jul 21, 2025

@edulelis is attempting to deploy a commit to the Inbox Zero Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

This change introduces a comprehensive delayed actions feature for email processing rules, enabling actions (such as labeling, archiving, replying) to be scheduled for execution after a configurable delay. The implementation spans the database schema, backend logic, API endpoints, scheduling and cancellation utilities, UI components, test coverage, and documentation. Integration with QStash provides event-driven, reliable scheduling and execution of delayed actions.

Changes

File(s) / Group Change Summary
.cursor/rules/features/delayed-actions.mdc Added detailed documentation for the delayed actions feature, including architecture, API, scheduling, execution, error handling, and usage examples.
apps/web/prisma/schema.prisma, apps/web/prisma/migrations/.../migration.sql Extended schema: added ScheduledAction model, enums for status, and delayInMinutes to Action. Created migration for these changes.
apps/web/utils/scheduled-actions/scheduler.ts New module: implements scheduling, cancellation, and status management for delayed actions using QStash and Prisma.
apps/web/utils/scheduled-actions/executor.ts New module: handles execution of scheduled actions, updating statuses, error handling, and integration with Gmail and AI logic.
apps/web/utils/scheduled-actions/executor.test.ts, apps/web/utils/scheduled-actions/scheduler.test.ts Added comprehensive unit tests for the scheduler and executor utilities, covering success, failure, and edge cases.
apps/web/app/api/scheduled-actions/execute/route.ts New secured API endpoint for executing scheduled actions triggered by QStash, with signature verification and robust error handling.
apps/web/utils/ai/choose-rule/run-rules.ts Updated rule execution to split immediate and delayed actions, schedule/cancel delayed actions, and persist immediate actions only.
apps/web/utils/actions/rule.ts, apps/web/utils/actions/rule.validation.ts Added support for delayInMinutes, new category value for delayed archive, and corresponding validation.
apps/web/utils/ai/rule/create-rule-schema.ts, apps/web/utils/ai/assistant/chat.ts, apps/web/utils/ai/types.ts Extended schemas and types to include delayInMinutes for actions.
apps/web/utils/delayed-actions.ts New utility: defines which action types can be delayed.
apps/web/utils/rule/rule.ts, apps/web/utils/action-item.ts Updated mapping and sanitization to include delayInMinutes.
apps/web/utils/date.ts Added exported constants for common minute-based durations.
apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx Major UI update: supports configuring delayed actions in the rule form, with input controls, validation, and optimistic updates.
apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx Passes mutate function to RuleForm for revalidation after edits.
apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx, apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx Adds delayInMinutes property to action objects for consistency.
apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx, apps/web/utils/actions/rule.ts Supports new onboarding option for delayed archive (label + archive after a week) if feature flag enabled.
apps/web/hooks/useFeatureFlags.ts Adds useDelayedActionsEnabled hook for feature flag checks.
apps/web/components/TooltipExplanation.tsx, apps/web/components/ui/tooltip.tsx Refactors tooltip components for improved UI and side placement, used in new/updated forms.
apps/web/app/api/ai/digest/route.ts Removes cron secret check (unrelated to delayed actions).
apps/web/__tests__/ai-choose-rule.test.ts Updates test data to include delayInMinutes for actions.
version.txt Bumps version from v1.9.21 to v1.10.0.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI (RuleForm)
    participant API
    participant Scheduler (QStash)
    participant DB
    participant Executor
    participant Gmail/External

    User->>UI (RuleForm): Configure rule with delayed action (e.g., ARCHIVE after 1 week)
    UI (RuleForm)->>API: Submit rule with delayInMinutes
    API->>DB: Persist rule and actions (with delay)
    API->>Scheduler: scheduleDelayedActions()
    Scheduler->>DB: Create ScheduledAction record(s)
    Scheduler->>QStash: Schedule message for execution (with delay)
    QStash->>API: POST /scheduled-actions/execute (after delay)
    API->>Executor: executeScheduledAction(scheduledActionId)
    Executor->>DB: Fetch scheduled action, mark as executing
    Executor->>Gmail/External: Perform action (e.g., archive email)
    Executor->>DB: Update scheduled action status (completed/failed)
Loading

Estimated code review effort

5 (~2–3 hours)

Possibly related PRs

Poem

🐇✨
A rule delayed, a plan in place,
Actions wait with patient grace.
QStash whispers, "Now's your time!"
Archive, label, send—sublime!
With minutes, hours, days to spare,
The rabbit's magic fills the air.
Hopping forward—change is near!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 13

🧹 Nitpick comments (9)
apps/web/utils/actions/rule.ts (2)

556-606: Refactor duplicated delayed action logic

The logic for creating actions based on categoryAction is duplicated between the create and update sections. Consider extracting this into a helper function to improve maintainability.

+      function getActionsData(
+        categoryAction: "label" | "label_archive" | "label_archive_delayed",
+        label: string,
+        hasDigest: boolean,
+      ) {
+        return [
+          { type: ActionType.LABEL, label },
+          ...(categoryAction === "label_archive"
+            ? [{ type: ActionType.ARCHIVE }]
+            : categoryAction === "label_archive_delayed"
+              ? [
+                  {
+                    type: ActionType.ARCHIVE,
+                    delayInMinutes: ONE_WEEK_MINUTES,
+                  },
+                ]
+              : []),
+          ...(hasDigest ? [{ type: ActionType.DIGEST }] : []),
+        ];
+      }

       if (existingRule) {
         const promise = prisma.rule
           .update({
             where: { id: existingRule.id },
             data: {
               instructions,
               actions: {
                 deleteMany: {},
                 createMany: {
-                  data: [
-                    { type: ActionType.LABEL, label },
-                    ...(categoryAction === "label_archive"
-                      ? [{ type: ActionType.ARCHIVE }]
-                      : categoryAction === "label_archive_delayed"
-                        ? [
-                            {
-                              type: ActionType.ARCHIVE,
-                              delayInMinutes: ONE_WEEK_MINUTES,
-                            },
-                          ]
-                        : []),
-                    ...(hasDigest ? [{ type: ActionType.DIGEST }] : []),
-                  ],
+                  data: getActionsData(categoryAction, label, hasDigest),
                 },
               },
             },
           })

Apply the same refactoring to the create section and the prompt generation logic.


622-627: Simplify nested ternary operators for better readability

The nested ternary operators make the prompt generation logic hard to follow. Consider using a more readable approach.

-          rules.push(
-            `${promptFileInstructions}${
-              categoryAction === "label_archive"
-                ? " and archive them"
-                : categoryAction === "label_archive_delayed"
-                  ? " and archive them after a week"
-                  : ""
-            }.`,
-          );
+          let actionSuffix = "";
+          if (categoryAction === "label_archive") {
+            actionSuffix = " and archive them";
+          } else if (categoryAction === "label_archive_delayed") {
+            actionSuffix = " and archive them after a week";
+          }
+          rules.push(`${promptFileInstructions}${actionSuffix}.`);
apps/web/utils/scheduled-actions/executor.test.ts (1)

29-279: Consider adding additional test cases for comprehensive coverage.

The test suite is missing coverage for several important scenarios:

  • Email no longer exists (should mark as completed with reason)
  • Concurrent execution protection
  • ExecutedRule completion when all scheduled actions finish
  • QStash scheduling/cancellation failures

Would you like me to generate additional test cases to improve the coverage?

apps/web/components/ui/tooltip.tsx (1)

21-29: Consider the implications of automatic provider wrapping.

Wrapping each Tooltip in its own TooltipProvider could lead to nested providers and unexpected behavior when multiple tooltips are used together. Consider requiring a single TooltipProvider at a higher level in the component tree.

 function Tooltip({
   ...props
 }: React.ComponentProps<typeof TooltipPrimitive.Root>) {
   return (
-    <TooltipProvider>
-      <TooltipPrimitive.Root data-slot="tooltip" {...props} />
-    </TooltipProvider>
+    <TooltipPrimitive.Root data-slot="tooltip" {...props} />
   );
 }
apps/web/utils/scheduled-actions/executor.ts (1)

200-213: Consider refactoring to avoid type conversion complexity.

The conversion from EmailForAction to ParsedMessage with dummy values for unused fields indicates a potential design issue.

Consider updating runActionFunction to accept EmailForAction directly, or create a minimal interface that both types can satisfy to avoid this conversion and dummy values.

.cursor/rules/features/delayed-actions.mdc (2)

86-86: Clarify the field notation.

The text "(field: scheduledId)" appears to be informal notation. Consider rephrasing for clarity.

-4. **Message ID Storage**: QStash scheduledId stored for efficient cancellation (field: scheduledId)
+4. **Message ID Storage**: QStash's returned message ID is stored in the `scheduledId` field for efficient cancellation

1-219: Consider adding additional operational sections.

The documentation is comprehensive but could benefit from:

  1. Testing strategies - How to test delayed actions in development
  2. Performance considerations - Impact on database, QStash limits
  3. Troubleshooting guide - Common issues and solutions
  4. Rollback procedures - How to safely disable the feature if needed
apps/web/utils/scheduled-actions/scheduler.ts (2)

140-141: Remove unnecessary non-null assertion.

The non-null assertion (!) on line 141 is unnecessary since you've already filtered for item.delayInMinutes != null && item.delayInMinutes > 0 on lines 129-130.

-    const scheduledFor = addMinutes(new Date(), actionItem.delayInMinutes!);
+    const scheduledFor = addMinutes(new Date(), actionItem.delayInMinutes);

272-276: Clarify the messageId comment for better understanding.

The comment about messageId having "a different meaning" could be more specific.

-      // The messageId here has a different meaning because it is
-      // the QStash identifier and not the usual messageId of the email
+      // Note: This messageId is the QStash message identifier,
+      // not to be confused with the email messageId parameter
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e12132b and aaf6707.

📒 Files selected for processing (29)
  • .cursor/rules/features/delayed-actions.mdc (1 hunks)
  • apps/web/__tests__/ai-choose-rule.test.ts (1 hunks)
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx (1 hunks)
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx (2 hunks)
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx (19 hunks)
  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx (3 hunks)
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx (3 hunks)
  • apps/web/app/api/ai/digest/route.ts (0 hunks)
  • apps/web/app/api/scheduled-actions/execute/route.ts (1 hunks)
  • apps/web/components/TooltipExplanation.tsx (2 hunks)
  • apps/web/components/ui/tooltip.tsx (1 hunks)
  • apps/web/hooks/useFeatureFlags.ts (1 hunks)
  • apps/web/prisma/migrations/20250626043046_add_scheduled_actions/migration.sql (1 hunks)
  • apps/web/prisma/schema.prisma (6 hunks)
  • apps/web/utils/action-item.ts (2 hunks)
  • apps/web/utils/actions/rule.ts (10 hunks)
  • apps/web/utils/actions/rule.validation.ts (3 hunks)
  • apps/web/utils/ai/assistant/chat.ts (4 hunks)
  • apps/web/utils/ai/choose-rule/run-rules.ts (4 hunks)
  • apps/web/utils/ai/rule/create-rule-schema.ts (2 hunks)
  • apps/web/utils/ai/types.ts (1 hunks)
  • apps/web/utils/date.ts (1 hunks)
  • apps/web/utils/delayed-actions.ts (1 hunks)
  • apps/web/utils/rule/rule.ts (1 hunks)
  • apps/web/utils/scheduled-actions/executor.test.ts (1 hunks)
  • apps/web/utils/scheduled-actions/executor.ts (1 hunks)
  • apps/web/utils/scheduled-actions/scheduler.test.ts (1 hunks)
  • apps/web/utils/scheduled-actions/scheduler.ts (1 hunks)
  • version.txt (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/web/app/api/ai/digest/route.ts
🧰 Additional context used
📓 Path-based instructions (39)
!{.cursor/rules/*.mdc}

📄 CodeRabbit Inference Engine (.cursor/rules/cursor-rules.mdc)

Never place rule files in the project root, in subdirectories outside .cursor/rules, or in any other location

Files:

  • version.txt
  • apps/web/__tests__/ai-choose-rule.test.ts
  • apps/web/hooks/useFeatureFlags.ts
  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/utils/ai/types.ts
  • apps/web/utils/date.ts
  • apps/web/utils/ai/rule/create-rule-schema.ts
  • apps/web/utils/delayed-actions.ts
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/utils/rule/rule.ts
  • apps/web/utils/ai/choose-rule/run-rules.ts
  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/action-item.ts
  • apps/web/utils/scheduled-actions/scheduler.test.ts
  • apps/web/utils/scheduled-actions/executor.test.ts
  • apps/web/app/api/scheduled-actions/execute/route.ts
  • apps/web/utils/ai/assistant/chat.ts
  • apps/web/utils/scheduled-actions/executor.ts
  • .cursor/rules/features/delayed-actions.mdc
  • apps/web/utils/actions/rule.ts
  • apps/web/components/TooltipExplanation.tsx
  • apps/web/components/ui/tooltip.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/prisma/migrations/20250626043046_add_scheduled_actions/migration.sql
  • apps/web/prisma/schema.prisma
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
  • apps/web/utils/scheduled-actions/scheduler.ts
!pages/_document.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/ultracite.mdc)

!pages/_document.{js,jsx,ts,tsx}: Don't import next/document outside of pages/_document.jsx in Next.js projects.
Don't import next/document outside of pages/_document.jsx in Next.js projects.

Files:

  • version.txt
  • apps/web/__tests__/ai-choose-rule.test.ts
  • apps/web/hooks/useFeatureFlags.ts
  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/utils/ai/types.ts
  • apps/web/utils/date.ts
  • apps/web/utils/ai/rule/create-rule-schema.ts
  • apps/web/utils/delayed-actions.ts
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/utils/rule/rule.ts
  • apps/web/utils/ai/choose-rule/run-rules.ts
  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/action-item.ts
  • apps/web/utils/scheduled-actions/scheduler.test.ts
  • apps/web/utils/scheduled-actions/executor.test.ts
  • apps/web/app/api/scheduled-actions/execute/route.ts
  • apps/web/utils/ai/assistant/chat.ts
  • apps/web/utils/scheduled-actions/executor.ts
  • .cursor/rules/features/delayed-actions.mdc
  • apps/web/utils/actions/rule.ts
  • apps/web/components/TooltipExplanation.tsx
  • apps/web/components/ui/tooltip.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/prisma/migrations/20250626043046_add_scheduled_actions/migration.sql
  • apps/web/prisma/schema.prisma
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
  • apps/web/utils/scheduled-actions/scheduler.ts
apps/web/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (apps/web/CLAUDE.md)

apps/web/**/*.{ts,tsx}: Use TypeScript with strict null checks
Path aliases: Use @/ for imports from project root
Use proper error handling with try/catch blocks
Format code with Prettier
Leverage TypeScript inference for better DX

Files:

  • apps/web/__tests__/ai-choose-rule.test.ts
  • apps/web/hooks/useFeatureFlags.ts
  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/utils/ai/types.ts
  • apps/web/utils/date.ts
  • apps/web/utils/ai/rule/create-rule-schema.ts
  • apps/web/utils/delayed-actions.ts
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/utils/rule/rule.ts
  • apps/web/utils/ai/choose-rule/run-rules.ts
  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/action-item.ts
  • apps/web/utils/scheduled-actions/scheduler.test.ts
  • apps/web/utils/scheduled-actions/executor.test.ts
  • apps/web/app/api/scheduled-actions/execute/route.ts
  • apps/web/utils/ai/assistant/chat.ts
  • apps/web/utils/scheduled-actions/executor.ts
  • apps/web/utils/actions/rule.ts
  • apps/web/components/TooltipExplanation.tsx
  • apps/web/components/ui/tooltip.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
  • apps/web/utils/scheduled-actions/scheduler.ts
**/*.ts

📄 CodeRabbit Inference Engine (.cursor/rules/form-handling.mdc)

**/*.ts: The same validation should be done in the server action too
Define validation schemas using Zod

Files:

  • apps/web/__tests__/ai-choose-rule.test.ts
  • apps/web/hooks/useFeatureFlags.ts
  • apps/web/utils/ai/types.ts
  • apps/web/utils/date.ts
  • apps/web/utils/ai/rule/create-rule-schema.ts
  • apps/web/utils/delayed-actions.ts
  • apps/web/utils/rule/rule.ts
  • apps/web/utils/ai/choose-rule/run-rules.ts
  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/action-item.ts
  • apps/web/utils/scheduled-actions/scheduler.test.ts
  • apps/web/utils/scheduled-actions/executor.test.ts
  • apps/web/app/api/scheduled-actions/execute/route.ts
  • apps/web/utils/ai/assistant/chat.ts
  • apps/web/utils/scheduled-actions/executor.ts
  • apps/web/utils/actions/rule.ts
  • apps/web/utils/scheduled-actions/scheduler.ts
apps/web/__tests__/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/llm-test.mdc)

Place all LLM-related tests in apps/web/tests/

LLM-specific tests should be placed in apps/web/tests/

Files:

  • apps/web/__tests__/ai-choose-rule.test.ts
apps/web/__tests__/**/*.test.ts

📄 CodeRabbit Inference Engine (.cursor/rules/llm-test.mdc)

apps/web/__tests__/**/*.test.ts: Always create helper functions for common test data in LLM-related tests
Include standard test cases: happy path, error handling, edge cases (empty input, null values), different user configurations, and various input formats in LLM-related tests
Set appropriate timeouts for LLM calls in tests (e.g., 15,000ms for long-running operations)
Use descriptive console.debug statements for generated content in LLM-related tests
Do not mock the LLM call in LLM-related tests; call the actual LLM
Test both AI and non-AI paths in LLM-related tests

Files:

  • apps/web/__tests__/ai-choose-rule.test.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/logging.mdc)

**/*.{ts,tsx}: Use createScopedLogger for logging in backend TypeScript files
Typically add the logger initialization at the top of the file when using createScopedLogger
Only use .with() on a logger instance within a specific function, not for a global logger

Import Prisma in the project using import prisma from "@/utils/prisma";

**/*.{ts,tsx}: Don't use TypeScript enums.
Don't use TypeScript const enum.
Don't use the TypeScript directive @ts-ignore.
Don't use primitive type aliases or misleading types.
Don't use empty type parameters in type aliases and interfaces.
Don't use any or unknown as type constraints.
Don't use implicit any type on variable declarations.
Don't let variables evolve into any type through reassignments.
Don't use non-null assertions with the ! postfix operator.
Don't misuse the non-null assertion operator (!) in TypeScript files.
Don't use user-defined types.
Use as const instead of literal types and type annotations.
Use export type for types.
Use import type for types.
Don't declare empty interfaces.
Don't merge interfaces and classes unsafely.
Don't use overload signatures that aren't next to each other.
Use the namespace keyword instead of the module keyword to declare TypeScript namespaces.
Don't use TypeScript namespaces.
Don't export imported variables.
Don't add type annotations to variables, parameters, and class properties that are initialized with literal expressions.
Don't use parameter properties in class constructors.
Use either T[] or Array consistently.
Initialize each enum member value explicitly.
Make sure all enum members are literal values.

Files:

  • apps/web/__tests__/ai-choose-rule.test.ts
  • apps/web/hooks/useFeatureFlags.ts
  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/utils/ai/types.ts
  • apps/web/utils/date.ts
  • apps/web/utils/ai/rule/create-rule-schema.ts
  • apps/web/utils/delayed-actions.ts
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/utils/rule/rule.ts
  • apps/web/utils/ai/choose-rule/run-rules.ts
  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/action-item.ts
  • apps/web/utils/scheduled-actions/scheduler.test.ts
  • apps/web/utils/scheduled-actions/executor.test.ts
  • apps/web/app/api/scheduled-actions/execute/route.ts
  • apps/web/utils/ai/assistant/chat.ts
  • apps/web/utils/scheduled-actions/executor.ts
  • apps/web/utils/actions/rule.ts
  • apps/web/components/TooltipExplanation.tsx
  • apps/web/components/ui/tooltip.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
  • apps/web/utils/scheduled-actions/scheduler.ts
**/*.test.{ts,js}

📄 CodeRabbit Inference Engine (.cursor/rules/security.mdc)

Include security tests in your test suites to verify authentication, authorization, and error handling.

Files:

  • apps/web/__tests__/ai-choose-rule.test.ts
  • apps/web/utils/scheduled-actions/scheduler.test.ts
  • apps/web/utils/scheduled-actions/executor.test.ts
**/*.test.{ts,js,tsx,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/testing.mdc)

**/*.test.{ts,js,tsx,jsx}: Tests are colocated next to the tested file (e.g., dir/format.ts and dir/format.test.ts)
Use vi.mock("server-only", () => ({})); to mock the server-only module in tests
Mock @/utils/prisma in tests using vi.mock("@/utils/prisma") and use the provided prisma mock
Mock external dependencies in tests
Clean up mocks between tests
Do not mock the Logger

Files:

  • apps/web/__tests__/ai-choose-rule.test.ts
  • apps/web/utils/scheduled-actions/scheduler.test.ts
  • apps/web/utils/scheduled-actions/executor.test.ts
**/__tests__/**/*.{ts,js,tsx,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/testing.mdc)

AI tests are placed in the __tests__ directory and are not run by default (they use a real LLM)

Files:

  • apps/web/__tests__/ai-choose-rule.test.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/ultracite.mdc)

**/*.{js,jsx,ts,tsx}: Don't use elements in Next.js projects.
Don't use elements in Next.js projects.
Don't use namespace imports.
Don't access namespace imports dynamically.
Don't use global eval().
Don't use console.
Don't use debugger.
Don't use var.
Don't use with statements in non-strict contexts.
Don't use the arguments object.
Don't use consecutive spaces in regular expression literals.
Don't use the comma operator.
Don't use unnecessary boolean casts.
Don't use unnecessary callbacks with flatMap.
Use for...of statements instead of Array.forEach.
Don't create classes that only have static members (like a static namespace).
Don't use this and super in static contexts.
Don't use unnecessary catch clauses.
Don't use unnecessary constructors.
Don't use unnecessary continue statements.
Don't export empty modules that don't change anything.
Don't use unnecessary escape sequences in regular expression literals.
Don't use unnecessary labels.
Don't use unnecessary nested block statements.
Don't rename imports, exports, and destructured assignments to the same name.
Don't use unnecessary string or template literal concatenation.
Don't use String.raw in template literals when there are no escape sequences.
Don't use useless case statements in switch statements.
Don't use ternary operators when simpler alternatives exist.
Don't use useless this aliasing.
Don't initialize variables to undefined.
Don't use the void operators (they're not familiar).
Use arrow functions instead of function expressions.
Use Date.now() to get milliseconds since the Unix Epoch.
Use .flatMap() instead of map().flat() when possible.
Use literal property access instead of computed property access.
Don't use parseInt() or Number.parseInt() when binary, octal, or hexadecimal literals work.
Use concise optional chaining instead of chained logical expressions.
Use regular expression literals instead of the RegExp constructor when possible.
Don't use number literal object member names th...

Files:

  • apps/web/__tests__/ai-choose-rule.test.ts
  • apps/web/hooks/useFeatureFlags.ts
  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/utils/ai/types.ts
  • apps/web/utils/date.ts
  • apps/web/utils/ai/rule/create-rule-schema.ts
  • apps/web/utils/delayed-actions.ts
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/utils/rule/rule.ts
  • apps/web/utils/ai/choose-rule/run-rules.ts
  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/action-item.ts
  • apps/web/utils/scheduled-actions/scheduler.test.ts
  • apps/web/utils/scheduled-actions/executor.test.ts
  • apps/web/app/api/scheduled-actions/execute/route.ts
  • apps/web/utils/ai/assistant/chat.ts
  • apps/web/utils/scheduled-actions/executor.ts
  • apps/web/utils/actions/rule.ts
  • apps/web/components/TooltipExplanation.tsx
  • apps/web/components/ui/tooltip.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
  • apps/web/utils/scheduled-actions/scheduler.ts
**/*.{test,spec}.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/ultracite.mdc)

**/*.{test,spec}.{js,jsx,ts,tsx}: Don't use export or module.exports in test files.
Don't use focused tests.
Don't use disabled tests.
Make sure the assertion function, like expect, is placed inside an it() function call.
Don't nest describe() blocks too deeply in test files.
Don't use focused tests.
Don't use disabled tests.
Don't use export or module.exports in test files.

Files:

  • apps/web/__tests__/ai-choose-rule.test.ts
  • apps/web/utils/scheduled-actions/scheduler.test.ts
  • apps/web/utils/scheduled-actions/executor.test.ts
apps/web/hooks/**/*.ts

📄 CodeRabbit Inference Engine (apps/web/CLAUDE.md)

Use SWR for efficient data fetching and caching

apps/web/hooks/**/*.ts: Use SWR for client-side data fetching and caching.
Call mutate() after successful mutations to refresh SWR data on the client.

Files:

  • apps/web/hooks/useFeatureFlags.ts
apps/web/hooks/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (apps/web/CLAUDE.md)

Call mutate() after successful mutations to refresh data

Files:

  • apps/web/hooks/useFeatureFlags.ts
apps/web/hooks/**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/hooks.mdc)

Place custom hooks in the apps/web/hooks/ directory.

Files:

  • apps/web/hooks/useFeatureFlags.ts
apps/web/hooks/use*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/hooks.mdc)

apps/web/hooks/use*.{js,jsx,ts,tsx}: Name custom hooks with the use prefix (e.g., useAccounts.ts).
For fetching data from API endpoints in custom hooks, prefer using useSWR.
Create dedicated hooks for specific data types (e.g., useAccounts, useLabels).
Custom hooks should encapsulate reusable stateful logic, especially for data fetching or complex UI interactions.
Keep custom hooks focused on a single responsibility.

Files:

  • apps/web/hooks/useFeatureFlags.ts
apps/web/hooks/useFeatureFlags.ts

📄 CodeRabbit Inference Engine (.cursor/rules/posthog-feature-flags.mdc)

apps/web/hooks/useFeatureFlags.ts: All feature flag hooks should be defined in apps/web/hooks/useFeatureFlags.ts
Use kebab-case for feature flag keys (e.g., 'inbox-cleaner', 'pricing-options-2')
Use 'use[FeatureName]Enabled' for boolean flag hook names and 'use[FeatureName]Variant' for variant flag hook names
Always define types for variant flags
Always provide a default/control fallback for variant flags
Keep all feature flag hooks centralized in useFeatureFlags.ts

Files:

  • apps/web/hooks/useFeatureFlags.ts
apps/web/app/**

📄 CodeRabbit Inference Engine (apps/web/CLAUDE.md)

NextJS app router structure with (app) directory

Files:

  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/app/api/scheduled-actions/execute/route.ts
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
apps/web/**/*.tsx

📄 CodeRabbit Inference Engine (apps/web/CLAUDE.md)

apps/web/**/*.tsx: Follow tailwindcss patterns with prettier-plugin-tailwindcss
Prefer functional components with hooks
Use shadcn/ui components when available
Ensure responsive design with mobile-first approach
Follow consistent naming conventions (PascalCase for components)
Use LoadingContent component for async data
Use result?.serverError with toastError and toastSuccess
Use LoadingContent component to handle loading and error states consistently
Pass loading, error, and children props to LoadingContent

Files:

  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/components/TooltipExplanation.tsx
  • apps/web/components/ui/tooltip.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
**/*.tsx

📄 CodeRabbit Inference Engine (.cursor/rules/form-handling.mdc)

**/*.tsx: Use React Hook Form with Zod for validation
Validate form inputs before submission
Show validation errors inline next to form fields

Files:

  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/components/TooltipExplanation.tsx
  • apps/web/components/ui/tooltip.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
apps/web/app/(app)/*/**

📄 CodeRabbit Inference Engine (.cursor/rules/page-structure.mdc)

Components for the page are either put in page.tsx, or in the apps/web/app/(app)/PAGE_NAME folder

Files:

  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
apps/web/app/(app)/*/**/*.tsx

📄 CodeRabbit Inference Engine (.cursor/rules/page-structure.mdc)

If you need to use onClick in a component, that component is a client component and file must start with 'use client'

Files:

  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
apps/web/app/(app)/*/**/**/*.tsx

📄 CodeRabbit Inference Engine (.cursor/rules/page-structure.mdc)

If we're in a deeply nested component we will use swr to fetch via API

Files:

  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
apps/web/app/**/*.tsx

📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)

Components with onClick must be client components with use client directive

Files:

  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
**/*.{jsx,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/ultracite.mdc)

**/*.{jsx,tsx}: Don't destructure props inside JSX components in Solid projects.
Don't use both children and dangerouslySetInnerHTML props on the same element.
Don't use Array index in keys.
Don't assign to React component props.
Don't define React components inside other components.
Don't use event handlers on non-interactive elements.
Don't assign JSX properties multiple times.
Don't add extra closing tags for components without children.
Use <>...</> instead of ....
Don't insert comments as text nodes.
Don't use the return value of React.render.
Make sure all dependencies are correctly specified in React hooks.
Make sure all React hooks are called from the top level of component functions.
Don't use unnecessary fragments.
Don't pass children as props.
Use semantic elements instead of role attributes in JSX.

Files:

  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/components/TooltipExplanation.tsx
  • apps/web/components/ui/tooltip.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
**/*.{html,jsx,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/ultracite.mdc)

**/*.{html,jsx,tsx}: Don't use or elements.
Don't use accessKey attribute on any HTML element.
Don't set aria-hidden="true" on focusable elements.
Don't add ARIA roles, states, and properties to elements that don't support them.
Only use the scope prop on elements.
Don't assign non-interactive ARIA roles to interactive HTML elements.
Make sure label elements have text content and are associated with an input.
Don't assign interactive ARIA roles to non-interactive HTML elements.
Don't assign tabIndex to non-interactive HTML elements.
Don't use positive integers for tabIndex property.
Don't include "image", "picture", or "photo" in img alt prop.
Don't use explicit role property that's the same as the implicit/default role.
Make static elements with click handlers use a valid role attribute.
Always include a title element for SVG elements.
Give all elements requiring alt text meaningful information for screen readers.
Make sure anchors have content that's accessible to screen readers.
Assign tabIndex to non-interactive HTML elements with aria-activedescendant.
Include all required ARIA attributes for elements with ARIA roles.
Make sure ARIA properties are valid for the element's supported roles.
Always include a type attribute for button elements.
Make elements with interactive roles and handlers focusable.
Give heading elements content that's accessible to screen readers (not hidden with aria-hidden).
Always include a lang attribute on the html element.
Always include a title attribute for iframe elements.
Accompany onClick with at least one of: onKeyUp, onKeyDown, or onKeyPress.
Accompany onMouseOver/onMouseOut with onFocus/onBlur.
Include caption tracks for audio and video elements.
Make sure all anchors are valid and navigable.
Ensure all ARIA properties (aria-*) are valid.
Use valid, non-abstract ARIA roles for elements with ARIA roles.
Use valid ARIA state and property values.
Use valid values for the autocomplete attribute on input eleme...

Files:

  • apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx
  • apps/web/components/TooltipExplanation.tsx
  • apps/web/components/ui/tooltip.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
apps/web/utils/{ai,llms}/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/llm.mdc)

apps/web/utils/{ai,llms}/**/*: LLM-related code must be organized in the directories: apps/web/utils/ai/, apps/web/utils/llms/, and apps/web/tests/ for LLM-specific tests.
Keep related AI functions in the same file or directory.

Files:

  • apps/web/utils/ai/types.ts
  • apps/web/utils/ai/rule/create-rule-schema.ts
  • apps/web/utils/ai/choose-rule/run-rules.ts
  • apps/web/utils/ai/assistant/chat.ts
apps/web/utils/{ai,llms}/**/*.ts

📄 CodeRabbit Inference Engine (.cursor/rules/llm.mdc)

apps/web/utils/{ai,llms}/**/*.ts: Follow the standard structure for LLM-related functions: use a scoped logger, define a Zod schema for output, validate inputs early, separate system and user prompts, log inputs and outputs, call chatCompletionObject with proper configuration, and return validated results.
Keep system prompts and user prompts separate in LLM-related code.
System prompt should define the LLM's role and task specifications.
User prompt should contain the actual data and context.
Always define a Zod schema for response validation in LLM-related functions.
Make Zod schemas as specific as possible to guide the LLM output.
Use descriptive scoped loggers for each LLM feature.
Log inputs and outputs with appropriate log levels in LLM-related functions.
Include relevant context in log messages for LLM-related code.
Implement early returns for invalid inputs in LLM-related functions.
Use proper error types and logging in LLM-related code.
Implement fallbacks for AI failures in LLM-related functions.
Add retry logic for transient failures using withRetry in LLM-related code.
Use XML-like tags to structure data in LLM prompts.
Remove excessive whitespace and truncate long inputs in LLM prompts.
Format data consistently across similar LLM-related functions.
Use TypeScript types for all parameters and return values in LLM-related code.
Define clear interfaces for complex input/output structures in LLM-related code.
Extract common patterns into utility functions in LLM-related code.
Document complex AI logic with clear comments in LLM-related code.

Files:

  • apps/web/utils/ai/types.ts
  • apps/web/utils/ai/rule/create-rule-schema.ts
  • apps/web/utils/ai/choose-rule/run-rules.ts
  • apps/web/utils/ai/assistant/chat.ts
apps/web/utils/**

📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)

Create utility functions in utils/ folder for reusable logic

Files:

  • apps/web/utils/ai/types.ts
  • apps/web/utils/date.ts
  • apps/web/utils/ai/rule/create-rule-schema.ts
  • apps/web/utils/delayed-actions.ts
  • apps/web/utils/rule/rule.ts
  • apps/web/utils/ai/choose-rule/run-rules.ts
  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/action-item.ts
  • apps/web/utils/scheduled-actions/scheduler.test.ts
  • apps/web/utils/scheduled-actions/executor.test.ts
  • apps/web/utils/ai/assistant/chat.ts
  • apps/web/utils/scheduled-actions/executor.ts
  • apps/web/utils/actions/rule.ts
  • apps/web/utils/scheduled-actions/scheduler.ts
apps/web/utils/**/*.ts

📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)

apps/web/utils/**/*.ts: Use lodash utilities for common operations (arrays, objects, strings)
Import specific lodash functions to minimize bundle size

Files:

  • apps/web/utils/ai/types.ts
  • apps/web/utils/date.ts
  • apps/web/utils/ai/rule/create-rule-schema.ts
  • apps/web/utils/delayed-actions.ts
  • apps/web/utils/rule/rule.ts
  • apps/web/utils/ai/choose-rule/run-rules.ts
  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/action-item.ts
  • apps/web/utils/scheduled-actions/scheduler.test.ts
  • apps/web/utils/scheduled-actions/executor.test.ts
  • apps/web/utils/ai/assistant/chat.ts
  • apps/web/utils/scheduled-actions/executor.ts
  • apps/web/utils/actions/rule.ts
  • apps/web/utils/scheduled-actions/scheduler.ts
apps/web/utils/actions/**/*.ts

📄 CodeRabbit Inference Engine (apps/web/CLAUDE.md)

apps/web/utils/actions/**/*.ts: Use server actions for all mutations (create/update/delete operations)
next-safe-action provides centralized error handling
Use Zod schemas for validation on both client and server
Use revalidatePath in server actions for cache invalidation

apps/web/utils/actions/**/*.ts: Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.
Use revalidatePath in server actions to invalidate cache after mutations.

Files:

  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/actions/rule.ts
apps/web/utils/actions/*.validation.ts

📄 CodeRabbit Inference Engine (.cursor/rules/fullstack-workflow.mdc)

Define Zod schemas for validation in dedicated files and use them for both client and server validation.

Define input validation schemas using Zod in the corresponding .validation.ts file. These schemas are used by next-safe-action (.schema()) and can also be reused on the client for form validation.

Files:

  • apps/web/utils/actions/rule.validation.ts
apps/web/utils/actions/*.ts

📄 CodeRabbit Inference Engine (.cursor/rules/server-actions.mdc)

apps/web/utils/actions/*.ts: Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).
Use actionClientUser when only authenticated user context (userId) is needed.
Use actionClient when both authenticated user context and a specific emailAccountId are needed. The emailAccountId must be bound when calling the action from the client.
Use adminActionClient for actions restricted to admin users.
Access necessary context (like userId, emailAccountId, etc.) provided by the safe action client via the ctx object in the .action() handler.
Server Actions are strictly for mutations (operations that change data, e.g., creating, updating, deleting). Do NOT use Server Actions for data fetching (GET operations). For data fetching, use dedicated GET API Routes combined with SWR Hooks.
Use SafeError for expected/handled errors within actions if needed. next-safe-action provides centralized error handling.
Use the .metadata({ name: "actionName" }) method to provide a meaningful name for monitoring. Sentry instrumentation is automatically applied via withServerActionInstrumentation within the safe action clients.
If an action modifies data displayed elsewhere, use revalidatePath or revalidateTag from next/cache within the action handler as needed.

Server action files must start with use server

Files:

  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/actions/rule.ts
apps/web/app/api/**/route.ts

📄 CodeRabbit Inference Engine (apps/web/CLAUDE.md)

apps/web/app/api/**/route.ts: Use withAuth for user-level operations
Use withEmailAccount for email-account-level operations
Do NOT use POST API routes for mutations - use server actions instead
No need for try/catch in GET routes when using middleware
Export response types from GET routes

apps/web/app/api/**/route.ts: Wrap all GET API route handlers with withAuth or withEmailAccount middleware for authentication and authorization.
Export response types from GET API routes for type-safe client usage.
Do not use try/catch in GET API routes when using authentication middleware; rely on centralized error handling.

Files:

  • apps/web/app/api/scheduled-actions/execute/route.ts
**/api/**/route.ts

📄 CodeRabbit Inference Engine (.cursor/rules/security.mdc)

**/api/**/route.ts: ALL API routes that handle user data MUST use appropriate authentication and authorization middleware (withAuth or withEmailAccount).
ALL database queries in API routes MUST be scoped to the authenticated user/account (e.g., include userId or emailAccountId in query filters).
Always validate that resources belong to the authenticated user before performing operations (resource ownership validation).
Use withEmailAccount middleware for API routes that operate on a specific email account (i.e., use or require emailAccountId).
Use withAuth middleware for API routes that operate at the user level (i.e., use or require only userId).
Use withError middleware (with proper validation) for public endpoints, custom authentication, or cron endpoints.
Cron endpoints MUST use withError middleware and validate the cron secret using hasCronSecret(request) or hasPostCronSecret(request).
Cron endpoints MUST capture unauthorized attempts with captureException and return a 401 status for unauthorized requests.
All parameters in API routes MUST be validated for type, format, and length before use.
Request bodies in API routes MUST be validated using Zod schemas before use.
All Prisma queries in API routes MUST only return necessary fields and never expose sensitive data.
Error messages in API routes MUST not leak internal information or sensitive data; use generic error messages and SafeError where appropriate.
API routes MUST use a consistent error response format, returning JSON with an error message and status code.
All findUnique and findFirst Prisma calls in API routes MUST include ownership filters (e.g., userId or emailAccountId).
All findMany Prisma calls in API routes MUST be scoped to the authenticated user's data.
Never use direct object references in API routes without ownership checks (prevent IDOR vulnerabilities).
Prevent mass assignment vulnerabilities by only allowing explicitly whitelisted fields in update operations in AP...

Files:

  • apps/web/app/api/scheduled-actions/execute/route.ts
apps/web/app/api/**/*.{ts,js}

📄 CodeRabbit Inference Engine (.cursor/rules/security-audit.mdc)

apps/web/app/api/**/*.{ts,js}: All API route handlers in 'apps/web/app/api/' must use authentication middleware: withAuth, withEmailAccount, or withError (with custom authentication logic).
All Prisma queries in API routes must include user/account filtering (e.g., emailAccountId or userId in WHERE clauses) to prevent unauthorized data access.
All parameters used in API routes must be validated before use; do not use parameters from 'params' or request bodies directly in queries without validation.
Request bodies in API routes should use Zod schemas for validation.
API routes should only return necessary fields using Prisma's 'select' and must not include sensitive data in error messages.
Error messages in API routes must not reveal internal details; use generic errors and SafeError for user-facing errors.
All QStash endpoints (API routes called via publishToQstash or publishToQstashQueue) must use verifySignatureAppRouter to verify request authenticity.
All cron endpoints in API routes must use hasCronSecret or hasPostCronSecret for authentication.
Do not hardcode weak or plaintext secrets in API route files; secrets must not be directly assigned as string literals.
Review all new withError usage in API routes to ensure custom authentication is implemented where required.

Files:

  • apps/web/app/api/scheduled-actions/execute/route.ts
apps/web/components/**/*.tsx

📄 CodeRabbit Inference Engine (apps/web/CLAUDE.md)

Use React Hook Form with Zod validation for form handling

Use the LoadingContent component to handle loading and error states consistently in data-fetching components.

Use PascalCase for components (e.g. components/Button.tsx)

Files:

  • apps/web/components/TooltipExplanation.tsx
  • apps/web/components/ui/tooltip.tsx
apps/web/components/ui/**

📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)

Shadcn components are in components/ui

Files:

  • apps/web/components/ui/tooltip.tsx
apps/web/prisma/schema.prisma

📄 CodeRabbit Inference Engine (.cursor/rules/prisma.mdc)

The Prisma schema file must be located at apps/web/prisma/schema.prisma

Files:

  • apps/web/prisma/schema.prisma
🧠 Learnings (25)
apps/web/__tests__/ai-choose-rule.test.ts (10)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Test both AI and non-AI paths in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Document complex AI logic with clear comments in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Implement fallbacks for AI failures in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Include standard test cases: happy path, error handling, edge cases (empty input, null values), different user configurations, and various input formats in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Use descriptive console.debug statements for generated content in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Format data consistently across similar LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Set appropriate timeouts for LLM calls in tests (e.g., 15,000ms for long-running operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Make Zod schemas as specific as possible to guide the LLM output.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use TypeScript types for all parameters and return values in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Always create helper functions for common test data in LLM-related tests

apps/web/hooks/useFeatureFlags.ts (10)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Keep all feature flag hooks centralized in useFeatureFlags.ts

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : All feature flag hooks should be defined in apps/web/hooks/useFeatureFlags.ts

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Use 'use[FeatureName]Enabled' for boolean flag hook names and 'use[FeatureName]Variant' for variant flag hook names

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Always define types for variant flags

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/hooks.mdc:0-0
Timestamp: 2025-07-18T15:05:41.696Z
Learning: Applies to apps/web/hooks/use*.{js,jsx,ts,tsx} : Create dedicated hooks for specific data types (e.g., useAccounts, useLabels).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Use kebab-case for feature flag keys (e.g., 'inbox-cleaner', 'pricing-options-2')

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/hooks.mdc:0-0
Timestamp: 2025-07-18T15:05:41.696Z
Learning: Applies to apps/web/hooks/use*.{js,jsx,ts,tsx} : Name custom hooks with the use prefix (e.g., useAccounts.ts).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Always provide a default/control fallback for variant flags

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/hooks.mdc:0-0
Timestamp: 2025-07-18T15:05:41.696Z
Learning: Applies to apps/web/hooks/use*.{js,jsx,ts,tsx} : Keep custom hooks focused on a single responsibility.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/**/*.tsx : Prefer functional components with hooks

apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx (1)

Learnt from: edulelis
PR: #576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses [key: string]: DigestItem[] | undefined | string | Date | undefined instead of intersection types like & Record<string, DigestItem[] | undefined> due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.

apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx (17)

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/hooks/**/*.{ts,tsx} : Call mutate() after successful mutations to refresh data

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/hooks/**/*.ts : Call mutate() after successful mutations to refresh SWR data on the client.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions for all mutations (create/update/delete operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/data-fetching.mdc:0-0
Timestamp: 2025-07-18T15:04:44.809Z
Learning: Applies to app/**/*.{ts,tsx} : For mutating data, use Next.js server actions

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{jsx,tsx} : Use semantic elements instead of role attributes in JSX.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't use duplicate function parameter names.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{html,jsx,tsx} : Don't use explicit role property that's the same as the implicit/default role.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{jsx,tsx} : Don't destructure props inside JSX components in Solid projects.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use revalidatePath in server actions to invalidate cache after mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-07-19T17:50:22.043Z
Learning: Applies to components/**/*.tsx : Use the LoadingContent component to handle loading states

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/**/*.tsx : Use LoadingContent component for async data

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/**/*.tsx : Pass loading, error, and children props to LoadingContent

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/**/*.tsx : Use LoadingContent component to handle loading and error states consistently

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/components/**/*.tsx : Use the LoadingContent component to handle loading and error states consistently in data-fetching components.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/index.mdc:0-0
Timestamp: 2025-07-18T15:05:56.618Z
Learning: Form handling using React Hook Form and Zod

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/components/**/*.tsx : Use React Hook Form with Zod validation for form handling

apps/web/utils/ai/types.ts (10)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use TypeScript types for all parameters and return values in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Document complex AI logic with clear comments in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Implement fallbacks for AI failures in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use proper error types and logging in LLM-related code.

Learnt from: edulelis
PR: #576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses [key: string]: DigestItem[] | undefined | string | Date | undefined instead of intersection types like & Record<string, DigestItem[] | undefined> due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use adminActionClient for actions restricted to admin users.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Format data consistently across similar LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Define clear interfaces for complex input/output structures in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Test both AI and non-AI paths in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

apps/web/utils/date.ts (8)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Format data consistently across similar LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Use Date.now() to get milliseconds since the Unix Epoch.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use TypeScript types for all parameters and return values in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Set appropriate timeouts for LLM calls in tests (e.g., 15,000ms for long-running operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Document complex AI logic with clear comments in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use proper error types and logging in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Make Zod schemas as specific as possible to guide the LLM output.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Extract common patterns into utility functions in LLM-related code.

apps/web/utils/ai/rule/create-rule-schema.ts (13)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Make Zod schemas as specific as possible to guide the LLM output.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/*.validation.ts : Define Zod schemas for validation in dedicated files and use them for both client and server validation.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Always define a Zod schema for response validation in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.validation.ts : Define input validation schemas using Zod in the corresponding .validation.ts file. These schemas are used by next-safe-action (.schema()) and can also be reused on the client for form validation.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use Zod schemas for validation on both client and server

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Document complex AI logic with clear comments in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Follow the standard structure for LLM-related functions: use a scoped logger, define a Zod schema for output, validate inputs early, separate system and user prompts, log inputs and outputs, call chatCompletionObject with proper configuration, and return validated results.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Implement fallbacks for AI failures in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use TypeScript types for all parameters and return values in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-18T15:04:57.098Z
Learning: Applies to **/*.ts : Define validation schemas using Zod

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/prisma.mdc:0-0
Timestamp: 2025-06-23T12:26:53.882Z
Learning: In this project, Prisma should be imported using 'import prisma from "@/utils/prisma";' in TypeScript files.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security-audit.mdc:0-0
Timestamp: 2025-07-20T09:00:41.952Z
Learning: Applies to apps/web/app/api/**/*.{ts,js} : Request bodies in API routes should use Zod schemas for validation.

apps/web/utils/delayed-actions.ts (10)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use adminActionClient for actions restricted to admin users.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions for all mutations (create/update/delete operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : next-safe-action provides centralized error handling

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-07-18T15:05:34.890Z
Learning: Applies to apps/web/utils/gmail/**/*.ts : Keep provider-specific implementation details isolated in the appropriate utils subfolder (e.g., 'apps/web/utils/gmail/')

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Implement fallbacks for AI failures in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use SafeError for expected/handled errors within actions if needed. next-safe-action provides centralized error handling.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use the .metadata({ name: "actionName" }) method to provide a meaningful name for monitoring. Sentry instrumentation is automatically applied via withServerActionInstrumentation within the safe action clients.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/project-structure.mdc:0-0
Timestamp: 2025-07-20T09:00:16.480Z
Learning: Applies to apps/web/utils/actions/*.ts : Server action files must start with use server

apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx (1)

Learnt from: edulelis
PR: #576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses [key: string]: DigestItem[] | undefined | string | Date | undefined instead of intersection types like & Record<string, DigestItem[] | undefined> due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.

apps/web/utils/rule/rule.ts (7)

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions for all mutations (create/update/delete operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Format data consistently across similar LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : If an action modifies data displayed elsewhere, use revalidatePath or revalidateTag from next/cache within the action handler as needed.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use the .metadata({ name: "actionName" }) method to provide a meaningful name for monitoring. Sentry instrumentation is automatically applied via withServerActionInstrumentation within the safe action clients.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use adminActionClient for actions restricted to admin users.

apps/web/utils/ai/choose-rule/run-rules.ts (18)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Implement fallbacks for AI failures in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Document complex AI logic with clear comments in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Follow the standard structure for LLM-related functions: use a scoped logger, define a Zod schema for output, validate inputs early, separate system and user prompts, log inputs and outputs, call chatCompletionObject with proper configuration, and return validated results.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Format data consistently across similar LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions for all mutations (create/update/delete operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Implement early returns for invalid inputs in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Make Zod schemas as specific as possible to guide the LLM output.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Extract common patterns into utility functions in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Access necessary context (like userId, emailAccountId, etc.) provided by the safe action client via the ctx object in the .action() handler.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use actionClient when both authenticated user context and a specific emailAccountId are needed. The emailAccountId must be bound when calling the action from the client.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/utilities.mdc:0-0
Timestamp: 2025-07-19T17:50:28.259Z
Learning: The utils folder also contains core app logic such as Next.js Server Actions and Gmail API requests.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use adminActionClient for actions restricted to admin users.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-07-18T15:05:34.890Z
Learning: Applies to apps/web/utils/gmail/**/*.ts : Keep provider-specific implementation details isolated in the appropriate utils subfolder (e.g., 'apps/web/utils/gmail/')

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use SafeError for expected/handled errors within actions if needed. next-safe-action provides centralized error handling.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : next-safe-action provides centralized error handling

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/index.mdc:0-0
Timestamp: 2025-07-18T15:05:56.618Z
Learning: Guidelines for implementing Next.js server actions

apps/web/utils/actions/rule.validation.ts (11)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/*.validation.ts : Define Zod schemas for validation in dedicated files and use them for both client and server validation.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.validation.ts : Define input validation schemas using Zod in the corresponding .validation.ts file. These schemas are used by next-safe-action (.schema()) and can also be reused on the client for form validation.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use Zod schemas for validation on both client and server

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Make Zod schemas as specific as possible to guide the LLM output.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Always define a Zod schema for response validation in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-18T15:04:57.098Z
Learning: Applies to **/*.ts : Define validation schemas using Zod

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security-audit.mdc:0-0
Timestamp: 2025-07-20T09:00:41.952Z
Learning: Applies to apps/web/app/api/**/*.{ts,js} : Request bodies in API routes should use Zod schemas for validation.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Follow the standard structure for LLM-related functions: use a scoped logger, define a Zod schema for output, validate inputs early, separate system and user prompts, log inputs and outputs, call chatCompletionObject with proper configuration, and return validated results.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security.mdc:0-0
Timestamp: 2025-07-18T17:27:46.378Z
Learning: Applies to /api//route.ts : Request bodies in API routes MUST be validated using Zod schemas before use.

Learnt from: edulelis
PR: #576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses [key: string]: DigestItem[] | undefined | string | Date | undefined instead of intersection types like & Record<string, DigestItem[] | undefined> due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.

apps/web/utils/action-item.ts (11)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions for all mutations (create/update/delete operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use adminActionClient for actions restricted to admin users.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use the .metadata({ name: "actionName" }) method to provide a meaningful name for monitoring. Sentry instrumentation is automatically applied via withServerActionInstrumentation within the safe action clients.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : If an action modifies data displayed elsewhere, use revalidatePath or revalidateTag from next/cache within the action handler as needed.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security-audit.mdc:0-0
Timestamp: 2025-07-20T09:00:41.952Z
Learning: Applies to apps/web/app/api/**/*.{ts,js} : API routes should only return necessary fields using Prisma's 'select' and must not include sensitive data in error messages.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Access necessary context (like userId, emailAccountId, etc.) provided by the safe action client via the ctx object in the .action() handler.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Format data consistently across similar LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use revalidatePath in server actions to invalidate cache after mutations.

Learnt from: edulelis
PR: #576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses [key: string]: DigestItem[] | undefined | string | Date | undefined instead of intersection types like & Record<string, DigestItem[] | undefined> due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.

apps/web/utils/scheduled-actions/scheduler.test.ts (12)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Test both AI and non-AI paths in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Set appropriate timeouts for LLM calls in tests (e.g., 15,000ms for long-running operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Include standard test cases: happy path, error handling, edge cases (empty input, null values), different user configurations, and various input formats in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Use descriptive console.debug statements for generated content in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Always create helper functions for common test data in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions for all mutations (create/update/delete operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Implement fallbacks for AI failures in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use proper error types and logging in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-23T12:27:30.570Z
Learning: When mocking Prisma in Vitest, import the Prisma mock from '@/utils/mocks/prisma', mock '@/utils/prisma', and clear all mocks in a beforeEach hook to ensure test isolation.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-23T12:27:30.570Z
Learning: When using Vitest for testing, each test should be independent, use descriptive test names, mock external dependencies, and clean up mocks between tests.

apps/web/utils/scheduled-actions/executor.test.ts (13)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Test both AI and non-AI paths in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Include standard test cases: happy path, error handling, edge cases (empty input, null values), different user configurations, and various input formats in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Set appropriate timeouts for LLM calls in tests (e.g., 15,000ms for long-running operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Use descriptive console.debug statements for generated content in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Always create helper functions for common test data in LLM-related tests

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Implement fallbacks for AI failures in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use proper error types and logging in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/tests/**/*.test.ts : Do not mock the LLM call in LLM-related tests; call the actual LLM

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-23T12:27:30.570Z
Learning: When mocking Prisma in Vitest, import the Prisma mock from '@/utils/mocks/prisma', mock '@/utils/prisma', and clear all mocks in a beforeEach hook to ensure test isolation.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{test,spec}.{js,jsx,ts,tsx} : Make sure the assertion function, like expect, is placed inside an it() function call.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-23T12:27:30.570Z
Learning: When using Vitest for testing, each test should be independent, use descriptive test names, mock external dependencies, and clean up mocks between tests.

apps/web/app/api/scheduled-actions/execute/route.ts (14)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security-audit.mdc:0-0
Timestamp: 2025-07-20T09:00:41.952Z
Learning: Applies to apps/web/app/api/**/*.{ts,js} : All QStash endpoints (API routes called via publishToQstash or publishToQstashQueue) must use verifySignatureAppRouter to verify request authenticity.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security.mdc:0-0
Timestamp: 2025-07-18T17:27:46.378Z
Learning: Applies to /api//route.ts : Cron endpoints MUST use withError middleware and validate the cron secret using hasCronSecret(request) or hasPostCronSecret(request).

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/app/api/**/route.ts : Do NOT use POST API routes for mutations - use server actions instead

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security-audit.mdc:0-0
Timestamp: 2025-07-20T09:00:41.952Z
Learning: Applies to apps/web/app/api/**/*.{ts,js} : All cron endpoints in API routes must use hasCronSecret or hasPostCronSecret for authentication.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/get-api-route.mdc:0-0
Timestamp: 2025-07-18T15:05:26.685Z
Learning: Applies to app/api/**/route.ts : Always wrap the handler with withAuth or withEmailAccount for consistent error handling and authentication in GET API routes.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security.mdc:0-0
Timestamp: 2025-07-18T17:27:46.378Z
Learning: Applies to /api//route.ts : Cron endpoints MUST capture unauthorized attempts with captureException and return a 401 status for unauthorized requests.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/app/api/**/route.ts : Wrap all GET API route handlers with withAuth or withEmailAccount middleware for authentication and authorization.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : next-safe-action provides centralized error handling

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/index.mdc:0-0
Timestamp: 2025-07-18T15:05:56.618Z
Learning: Guidelines for implementing Next.js server actions

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/index.mdc:0-0
Timestamp: 2025-07-18T15:05:56.618Z
Learning: Guidelines for implementing GET API routes in Next.js

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Server Actions are strictly for mutations (operations that change data, e.g., creating, updating, deleting). Do NOT use Server Actions for data fetching (GET operations). For data fetching, use dedicated GET API Routes combined with SWR Hooks.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/utilities.mdc:0-0
Timestamp: 2025-07-19T17:50:28.259Z
Learning: The utils folder also contains core app logic such as Next.js Server Actions and Gmail API requests.

apps/web/utils/ai/assistant/chat.ts (11)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Document complex AI logic with clear comments in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Make Zod schemas as specific as possible to guide the LLM output.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Implement fallbacks for AI failures in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Follow the standard structure for LLM-related functions: use a scoped logger, define a Zod schema for output, validate inputs early, separate system and user prompts, log inputs and outputs, call chatCompletionObject with proper configuration, and return validated results.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use TypeScript types for all parameters and return values in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Always define a Zod schema for response validation in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Format data consistently across similar LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use descriptive scoped loggers for each LLM feature.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Include relevant context in log messages for LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use proper error types and logging in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Log inputs and outputs with appropriate log levels in LLM-related functions.

apps/web/utils/scheduled-actions/executor.ts (12)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use actionClient when both authenticated user context and a specific emailAccountId are needed. The emailAccountId must be bound when calling the action from the client.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : next-safe-action provides centralized error handling

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use SafeError for expected/handled errors within actions if needed. next-safe-action provides centralized error handling.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-07-18T15:05:34.890Z
Learning: Applies to apps/web/utils/gmail/**/*.ts : Keep provider-specific implementation details isolated in the appropriate utils subfolder (e.g., 'apps/web/utils/gmail/')

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Implement fallbacks for AI failures in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use proper error types and logging in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use adminActionClient for actions restricted to admin users.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions for all mutations (create/update/delete operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/utilities.mdc:0-0
Timestamp: 2025-07-19T17:50:28.259Z
Learning: The utils folder also contains core app logic such as Next.js Server Actions and Gmail API requests.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/index.mdc:0-0
Timestamp: 2025-07-18T15:05:56.618Z
Learning: Guidelines for implementing Next.js server actions

apps/web/utils/actions/rule.ts (10)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use actionClient when both authenticated user context and a specific emailAccountId are needed. The emailAccountId must be bound when calling the action from the client.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/utilities.mdc:0-0
Timestamp: 2025-07-19T17:50:28.259Z
Learning: The utils folder also contains core app logic such as Next.js Server Actions and Gmail API requests.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/app/api/**/route.ts : Use withEmailAccount for email-account-level operations

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Access necessary context (like userId, emailAccountId, etc.) provided by the safe action client via the ctx object in the .action() handler.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security.mdc:0-0
Timestamp: 2025-07-18T17:27:46.378Z
Learning: Applies to /api//route.ts : Use withEmailAccount middleware for API routes that operate on a specific email account (i.e., use or require emailAccountId).

Learnt from: edulelis
PR: #576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses [key: string]: DigestItem[] | undefined | string | Date | undefined instead of intersection types like & Record<string, DigestItem[] | undefined> due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't use unnecessary labels.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : User prompt should contain the actual data and context.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Keep system prompts and user prompts separate in LLM-related code.

apps/web/components/TooltipExplanation.tsx (11)

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/**/*.tsx : Prefer functional components with hooks

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/**/*.tsx : Use shadcn/ui components when available

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/project-structure.mdc:0-0
Timestamp: 2025-07-20T09:00:16.480Z
Learning: Applies to apps/web/app/**/*.tsx : Components with onClick must be client components with use client directive

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-07-19T17:50:22.043Z
Learning: Applies to components/**/*.tsx : Use Shadcn UI and Tailwind for components and styling

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/page-structure.mdc:0-0
Timestamp: 2025-07-18T15:07:00.226Z
Learning: Applies to apps/web/app/(app)//**/.tsx : If you need to use onClick in a component, that component is a client component and file must start with 'use client'

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{jsx,tsx} : Use semantic elements instead of role attributes in JSX.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Document complex AI logic with clear comments in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-07-19T17:50:22.043Z
Learning: Applies to components/**/*.tsx : Use the Input component with autosizeTextarea and appropriate props for text areas

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/data-fetching.mdc:0-0
Timestamp: 2025-07-18T15:04:44.809Z
Learning: Applies to {app,components}/**/*.{ts,tsx} : Use result?.serverError with toastError and toastSuccess for error handling; success toast is optional

Learnt from: aryanprince
PR: #210
File: apps/web/app/(app)/stats/NewsletterModal.tsx:2-4
Timestamp: 2024-08-23T11:37:26.779Z
Learning: MoreDropdown is a React component and useUnsubscribeButton is a custom React hook, and they should not be imported using import type.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{html,jsx,tsx} : Accompany onMouseOver/onMouseOut with onFocus/onBlur.

apps/web/components/ui/tooltip.tsx (15)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{jsx,tsx} : Use semantic elements instead of role attributes in JSX.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/**/*.tsx : Prefer functional components with hooks

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-07-19T17:50:22.043Z
Learning: Applies to components/**/*.tsx : Use Shadcn UI and Tailwind for components and styling

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/**/*.tsx : Use shadcn/ui components when available

Learnt from: aryanprince
PR: #210
File: apps/web/app/(app)/stats/NewsletterModal.tsx:2-4
Timestamp: 2024-08-23T11:37:26.779Z
Learning: MoreDropdown is a React component and useUnsubscribeButton is a custom React hook, and they should not be imported using import type.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{jsx,tsx} : Use <>...</> instead of ....

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-07-19T17:50:22.043Z
Learning: Applies to components/**/*.tsx : Implement responsive design with Tailwind CSS using a mobile-first approach

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{html,jsx,tsx} : Accompany onMouseOver/onMouseOut with onFocus/onBlur.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{jsx,tsx} : Don't define React components inside other components.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{html,jsx,tsx} : Don't use explicit role property that's the same as the implicit/default role.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/project-structure.mdc:0-0
Timestamp: 2025-07-20T09:00:16.480Z
Learning: Applies to apps/web/app/**/*.tsx : Components with onClick must be client components with use client directive

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/page-structure.mdc:0-0
Timestamp: 2025-07-18T15:07:00.226Z
Learning: Applies to apps/web/app/(app)//**/.tsx : If you need to use onClick in a component, that component is a client component and file must start with 'use client'

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{jsx,tsx} : Don't assign to React component props.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{jsx,tsx} : Make sure all React hooks are called from the top level of component functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{jsx,tsx} : Make sure all dependencies are correctly specified in React hooks.

apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx (21)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Keep all feature flag hooks centralized in useFeatureFlags.ts

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Use kebab-case for feature flag keys (e.g., 'inbox-cleaner', 'pricing-options-2')

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Use 'use[FeatureName]Enabled' for boolean flag hook names and 'use[FeatureName]Variant' for variant flag hook names

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : All feature flag hooks should be defined in apps/web/hooks/useFeatureFlags.ts

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Always define types for variant flags

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Always provide a default/control fallback for variant flags

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/hooks.mdc:0-0
Timestamp: 2025-07-18T15:05:41.696Z
Learning: Applies to apps/web/hooks/use*.{js,jsx,ts,tsx} : Create dedicated hooks for specific data types (e.g., useAccounts, useLabels).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Implement fallbacks for AI failures in LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use XML-like tags to structure data in LLM prompts.

Learnt from: edulelis
PR: #576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses [key: string]: DigestItem[] | undefined | string | Date | undefined instead of intersection types like & Record<string, DigestItem[] | undefined> due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.

Learnt from: elie222
PR: #537
File: apps/web/app/(app)/[emailAccountId]/clean/onboarding/page.tsx:30-34
Timestamp: 2025-07-08T13:14:07.449Z
Learning: The clean onboarding page in apps/web/app/(app)/[emailAccountId]/clean/onboarding/page.tsx is intentionally Gmail-specific and should show an error for non-Google email accounts rather than attempting to support multiple providers.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use actionClient when both authenticated user context and a specific emailAccountId are needed. The emailAccountId must be bound when calling the action from the client.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/components/**/*.tsx : Use React Hook Form with Zod validation for form handling

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-18T15:04:57.098Z
Learning: Applies to **/*.tsx : Validate form inputs before submission

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/index.mdc:0-0
Timestamp: 2025-07-18T15:05:56.618Z
Learning: Form handling using React Hook Form and Zod

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-18T15:04:57.098Z
Learning: Applies to **/*.tsx : Use React Hook Form with Zod for validation

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/components/**/*Form.tsx : Use result?.serverError with toastError and toastSuccess for error and success notifications in form submission handlers.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/components/**/*Form.tsx : Use React Hook Form with Zod resolver for form handling and validation.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-07-19T17:50:22.043Z
Learning: Applies to components/**/*.tsx : Use the Input component for text inputs, passing registerProps and error props for form handling

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-18T15:04:57.098Z
Learning: Applies to **/*.tsx : Show validation errors inline next to form fields

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/index.mdc:0-0
Timestamp: 2025-07-18T15:05:56.618Z
Learning: Guidelines for creating custom React hooks

apps/web/prisma/schema.prisma (2)

Learnt from: edulelis
PR: #576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses [key: string]: DigestItem[] | undefined | string | Date | undefined instead of intersection types like & Record<string, DigestItem[] | undefined> due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use actionClient when both authenticated user context and a specific emailAccountId are needed. The emailAccountId must be bound when calling the action from the client.

apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx (39)

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/hooks/**/*.{ts,tsx} : Call mutate() after successful mutations to refresh data

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions for all mutations (create/update/delete operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-18T15:04:57.098Z
Learning: Applies to **/*.tsx : Validate form inputs before submission

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/components/**/*Form.tsx : Use React Hook Form with Zod resolver for form handling and validation.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Format data consistently across similar LLM-related functions.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/components/**/*.tsx : Use React Hook Form with Zod validation for form handling

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : If an action modifies data displayed elsewhere, use revalidatePath or revalidateTag from next/cache within the action handler as needed.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Document complex AI logic with clear comments in LLM-related code.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use XML-like tags to structure data in LLM prompts.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-18T15:04:57.098Z
Learning: Applies to **/*.tsx : Use React Hook Form with Zod for validation

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/index.mdc:0-0
Timestamp: 2025-07-18T15:05:56.618Z
Learning: Form handling using React Hook Form and Zod

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/index.mdc:0-0
Timestamp: 2025-07-18T15:05:56.618Z
Learning: Guidelines for creating custom React hooks

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Always define types for variant flags

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/**/*.tsx : Use shadcn/ui components when available

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Always provide a default/control fallback for variant flags

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Use 'use[FeatureName]Enabled' for boolean flag hook names and 'use[FeatureName]Variant' for variant flag hook names

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/hooks/**/*.ts : Call mutate() after successful mutations to refresh SWR data on the client.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/components/**/*.tsx : Use the LoadingContent component to handle loading and error states consistently in data-fetching components.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/data-fetching.mdc:0-0
Timestamp: 2025-07-18T15:04:44.809Z
Learning: Applies to app/**/*.{ts,tsx} : For mutating data, use Next.js server actions

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/**/*.tsx : Use LoadingContent component to handle loading and error states consistently

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/hooks.mdc:0-0
Timestamp: 2025-07-18T15:05:41.696Z
Learning: Applies to apps/web/hooks/use*.{js,jsx,ts,tsx} : Create dedicated hooks for specific data types (e.g., useAccounts, useLabels).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/hooks.mdc:0-0
Timestamp: 2025-07-18T15:05:41.696Z
Learning: Applies to apps/web/hooks/use*.{js,jsx,ts,tsx} : Name custom hooks with the use prefix (e.g., useAccounts.ts).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't use unnecessary labels.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use revalidatePath in server actions to invalidate cache after mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Server Actions are strictly for mutations (operations that change data, e.g., creating, updating, deleting). Do NOT use Server Actions for data fetching (GET operations). For data fetching, use dedicated GET API Routes combined with SWR Hooks.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/app/api/**/route.ts : Do NOT use POST API routes for mutations - use server actions instead

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/**/*.tsx : Use result?.serverError with toastError and toastSuccess

Learnt from: edulelis
PR: #576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses [key: string]: DigestItem[] | undefined | string | Date | undefined instead of intersection types like & Record<string, DigestItem[] | undefined> due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/posthog-feature-flags.mdc:0-0
Timestamp: 2025-07-18T15:07:12.388Z
Learning: Applies to apps/web/hooks/useFeatureFlags.ts : Use kebab-case for feature flag keys (e.g., 'inbox-cleaner', 'pricing-options-2')

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Access necessary context (like userId, emailAccountId, etc.) provided by the safe action client via the ctx object in the .action() handler.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{html,jsx,tsx} : Make sure label elements have text content and are associated with an input.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-18T15:04:57.098Z
Learning: Applies to **/*.tsx : Show validation errors inline next to form fields

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : User prompt should contain the actual data and context.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-07-19T17:50:22.043Z
Learning: Applies to components/**/*.tsx : Use the Input component for text inputs, passing registerProps and error props for form handling

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use actionClient when both authenticated user context and a specific emailAccountId are needed. The emailAccountId must be bound when calling the action from the client.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-07-19T17:50:22.043Z
Learning: Applies to components/**/*.tsx : Use the Input component with autosizeTextarea and appropriate props for text areas

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{html,jsx,tsx} : Use valid values for the autocomplete attribute on input elements.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{jsx,tsx} : Don't use event handlers on non-interactive elements.

apps/web/utils/scheduled-actions/scheduler.ts (8)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the next-safe-action library for type safety, input validation, context management, and error handling. Refer to apps/web/utils/actions/safe-action.ts for client definitions (actionClient, actionClientUser, adminActionClient).

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/fullstack-workflow.mdc:0-0
Timestamp: 2025-07-18T15:05:16.118Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions (with next-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : next-safe-action provides centralized error handling

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use SafeError for expected/handled errors within actions if needed. next-safe-action provides centralized error handling.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-07-18T17:27:58.220Z
Learning: Applies to apps/web/utils/actions/*.ts : Use adminActionClient for actions restricted to admin users.

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.243Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Follow the standard structure for LLM-related functions: use a scoped logger, define a Zod schema for output, validate inputs early, separate system and user prompts, log inputs and outputs, call chatCompletionObject with proper configuration, and return validated results.

Learnt from: CR
PR: elie222/inbox-zero#0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.448Z
Learning: Applies to apps/web/utils/actions/**/*.ts : Use server actions for all mutations (create/update/delete operations)

Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/index.mdc:0-0
Timestamp: 2025-07-18T15:05:56.618Z
Learning: Guidelines for implementing Next.js server actions

🧬 Code Graph Analysis (10)
apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx (1)
apps/web/hooks/useRule.tsx (1)
  • useRule (4-8)
apps/web/utils/ai/rule/create-rule-schema.ts (1)
apps/web/utils/actions/rule.validation.ts (1)
  • delayInMinutesSchema (11-15)
apps/web/utils/actions/rule.validation.ts (1)
apps/web/utils/date.ts (1)
  • NINETY_DAYS_MINUTES (13-13)
apps/web/utils/scheduled-actions/scheduler.test.ts (2)
apps/web/utils/delayed-actions.ts (1)
  • canActionBeDelayed (15-17)
apps/web/utils/scheduled-actions/scheduler.ts (1)
  • cancelScheduledActions (165-245)
apps/web/utils/scheduled-actions/executor.test.ts (5)
apps/web/utils/ai/actions.ts (1)
  • runActionFunction (23-71)
apps/web/utils/mail.ts (1)
  • parseMessage (14-23)
apps/web/utils/user/get.ts (1)
  • getEmailAccountWithAiAndTokens (57-92)
apps/web/utils/gmail/client.ts (1)
  • getGmailClientWithRefresh (49-99)
apps/web/utils/scheduled-actions/executor.ts (1)
  • executeScheduledAction (23-105)
apps/web/utils/ai/assistant/chat.ts (1)
apps/web/utils/actions/rule.validation.ts (1)
  • delayInMinutesSchema (11-15)
apps/web/utils/actions/rule.ts (1)
apps/web/utils/date.ts (1)
  • ONE_WEEK_MINUTES (12-12)
apps/web/components/TooltipExplanation.tsx (2)
apps/web/components/ui/tooltip.tsx (3)
  • TooltipProvider (61-61)
  • TooltipTrigger (61-61)
  • TooltipContent (61-61)
apps/web/utils/index.ts (1)
  • cn (4-6)
apps/web/components/ui/tooltip.tsx (1)
apps/web/utils/index.ts (1)
  • cn (4-6)
apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx (1)
apps/web/hooks/useFeatureFlags.ts (1)
  • useDelayedActionsEnabled (45-47)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Static Code Analysis Js
  • GitHub Check: Jit Security
🔇 Additional comments (50)
apps/web/utils/delayed-actions.ts (1)

1-17: LGTM! Clean utility module for delayed actions feature.

The implementation is well-structured and follows best practices:

  • Centralizes the definition of delayable actions in a reusable utility
  • Uses clear naming conventions and proper TypeScript types
  • Provides a simple, efficient function to check action eligibility
  • The selected action types logically support delayed execution
version.txt (1)

1-1: Appropriate version bump for the new delayed actions feature.

The minor version increment from v1.9.21 to v1.10.0 correctly reflects the addition of substantial new functionality.

apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx (1)

136-136: Correct integration of delayInMinutes property for cold email blocker actions.

The addition of delayInMinutes: null to all cold email blocker action objects maintains consistency with the new delayed actions schema while appropriately setting immediate execution for these system-generated actions.

Also applies to: 152-152, 169-169

apps/web/hooks/useFeatureFlags.ts (1)

45-47: Perfect implementation of the delayed actions feature flag.

The hook follows all established patterns:

  • Correct naming convention (use[FeatureName]Enabled)
  • Proper kebab-case feature flag key
  • Consistent with other boolean flag hooks in the file
  • Properly centralized in useFeatureFlags.ts
apps/web/__tests__/ai-choose-rule.test.ts (1)

79-79: Necessary test data update for delayed actions compatibility.

Adding delayInMinutes: null to the action object ensures the test data matches the updated schema while maintaining test validity.

apps/web/utils/ai/types.ts (1)

25-25: LGTM! Type definition correctly extended for delayed actions.

The addition of delayInMinutes?: number | null to the ActionItem type is properly typed and aligns with the delayed actions feature implementation across the codebase.

apps/web/app/(app)/[emailAccountId]/assistant/DraftReplies.tsx (1)

95-95: LGTM! Optimistic update correctly includes new field.

Adding delayInMinutes: null to the optimistic update ensures consistency between the client-side representation and server response structure for the delayed actions feature.

apps/web/app/(app)/[emailAccountId]/assistant/RuleDialog.tsx (2)

31-31: LGTM! Properly destructures mutate for cache management.

Extracting mutate from the useRule hook enables proper SWR cache management for rule updates.


55-55: LGTM! Correctly passes mutate to RuleForm for existing rules.

Passing the mutate function to RuleForm when editing existing rules enables proper cache revalidation and optimistic updates, following SWR best practices.

apps/web/utils/ai/rule/create-rule-schema.ts (2)

7-7: LGTM! Correctly imports delay validation schema.

Importing delayInMinutesSchema from the rule validation module ensures consistent validation rules across the application.


80-80: LGTM! Properly integrates delay field into action schema.

Adding delayInMinutes: delayInMinutesSchema to the action schema enables proper validation of delay values for the delayed actions feature, following Zod validation best practices.

apps/web/utils/date.ts (1)

10-13: LGTM! Well-defined minute-based duration constants.

The new minute-based constants are correctly calculated and follow consistent naming patterns. They provide useful standardized values for the delayed actions feature while complementing the existing millisecond-based constants.

apps/web/utils/rule/rule.ts (1)

350-350: LGTM: Properly integrates delayInMinutes field.

The addition of delayInMinutes: a.delayInMinutes correctly maps the delay field from the action schema to the Prisma input, enabling the delayed actions feature.

apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx (4)

37-37: LGTM: Proper feature flag import.

Correctly imports the useDelayedActionsEnabled hook from the centralized feature flags module.


166-166: LGTM: Proper feature flag usage.

Correctly uses the feature flag hook to conditionally enable delayed actions UI.


211-211: LGTM: Text consistency improvement.

Good change to standardize the text casing from "Label + Skip Inbox" to "Label + skip inbox" for consistency.


213-217: LGTM: Well-implemented conditional delayed action option.

The implementation correctly:

  • Uses feature flag gating to conditionally render the new option
  • Provides clear user-facing text "Label + archive after a week"
  • Maps to the correct value "label_archive_delayed" that aligns with the validation schema
apps/web/utils/action-item.ts (2)

165-174: LGTM: Type definition properly extended.

The ActionFieldsSelection type correctly includes "delayInMinutes" from Prisma.ActionCreateInput, maintaining type safety for the delayed actions feature.


188-188: LGTM: Proper field initialization with fallback.

The delayInMinutes field is correctly initialized with action.delayInMinutes || null, providing a safe fallback that aligns with the nullable schema definition.

apps/web/utils/actions/rule.validation.ts (4)

9-9: LGTM: Proper import for validation bounds.

Correctly imports the NINETY_DAYS_MINUTES constant from the date utilities, maintaining consistency across the codebase for time-based validations.


11-15: LGTM: Well-defined validation schema.

The delayInMinutesSchema is properly implemented with:

  • Reasonable bounds (1 minute to 90 days)
  • Clear, user-friendly error messages
  • Support for nullish values for optional delays
  • Type safety with Zod validation

83-83: LGTM: Proper integration into action schema.

The delayInMinutes field is correctly added to the zodAction schema, enabling validation for delayed actions throughout the system.


174-179: LGTM: Category action enum properly extended.

The categoryAction enum correctly includes the new "label_archive_delayed" option, which aligns with the UI changes in the onboarding flow and maintains consistency across the validation layer.

apps/web/utils/ai/assistant/chat.ts (4)

18-18: LGTM: Proper schema import for validation.

Correctly imports the delayInMinutesSchema from the rule validation module, ensuring consistent validation across the AI assistant functionality.


95-95: LGTM: Schema properly integrated into AI tool.

The delayInMinutes field is correctly added to the updateRuleActionsSchema, enabling the AI assistant to validate and process delayed action requests.


119-119: LGTM: Type definition properly extended.

The UpdateRuleActionsResult type correctly includes the optional delayInMinutes field, maintaining type safety for AI assistant responses.


760-760: LGTM: Proper value extraction with fallback.

The tool execution correctly extracts action.delayInMinutes ?? null, providing a safe fallback that aligns with the nullable schema definition and ensures consistent data handling.

apps/web/utils/scheduled-actions/scheduler.test.ts (1)

22-39: Well-structured tests for action delay support

The test coverage for canActionBeDelayed is comprehensive, testing both supported and unsupported action types clearly.

apps/web/utils/ai/choose-rule/run-rules.ts (1)

220-225: Proper handling of delayInMinutes field

Good implementation - correctly removes the delayInMinutes field before persisting executed actions, as this field is only relevant for scheduling.

apps/web/app/api/scheduled-actions/execute/route.ts (2)

1-18: Proper security implementation for QStash endpoint

Correctly implements QStash signature verification as required for endpoints called via QStash, with appropriate error handling middleware and request validation schema.


46-109: Well-structured execution flow with proper status handling

The implementation correctly:

  • Validates the scheduled action exists and is in the correct state
  • Prevents duplicate processing by marking as executing
  • Handles all edge cases (cancelled, already processed)
  • Returns appropriate HTTP status codes
apps/web/utils/actions/rule.ts (1)

232-232: Consistent handling of delayInMinutes across operations

The implementation properly handles the delayInMinutes field in both update and create operations within the rule update flow, maintaining data consistency.

Also applies to: 251-251

apps/web/utils/scheduled-actions/executor.test.ts (2)

1-28: LGTM! Proper test setup with correct mocking patterns.

The test file correctly mocks all dependencies including the server-only module and Prisma client as per the project guidelines.


269-277: Add missing await keyword.

The test is not awaiting the executeScheduledAction promise, which could cause the test to pass incorrectly.

-      await executeScheduledAction(mockScheduledAction);
+      const result = await executeScheduledAction(mockScheduledAction);
+      
+      expect(result.success).toBe(false);
+      expect(result.error).toBeDefined();
⛔ Skipped due to learnings
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Make sure async functions actually use await.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Include standard test cases: happy path, error handling, edge cases (empty input, null values), different user configurations, and various input formats in LLM-related tests
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{test,spec}.{js,jsx,ts,tsx} : Make sure the assertion function, like expect, is placed inside an it() function call.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Set appropriate timeouts for LLM calls in tests (e.g., 15,000ms for long-running operations)
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Test both AI and non-AI paths in LLM-related tests
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security-audit.mdc:0-0
Timestamp: 2025-07-20T09:00:41.952Z
Learning: Applies to apps/web/app/api/**/*.{ts,js} : Review all new withError usage in API routes to ensure custom authentication is implemented where required.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{test,spec}.{js,jsx,ts,tsx} : Don't use disabled tests.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.287Z
Learning: Applies to **/*.{test,spec}.{js,jsx,ts,tsx} : Don't use disabled tests.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security.mdc:0-0
Timestamp: 2025-07-18T17:27:46.378Z
Learning: Applies to **/*.test.{ts,js} : Include security tests in your test suites to verify authentication, authorization, and error handling.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.554Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Do not mock the LLM call in LLM-related tests; call the actual LLM
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-23T12:27:30.570Z
Learning: When mocking Prisma in Vitest, import the Prisma mock from '@/utils/__mocks__/prisma', mock '@/utils/prisma', and clear all mocks in a beforeEach hook to ensure test isolation.
apps/web/components/ui/tooltip.tsx (2)

8-19: LGTM! Clean implementation of TooltipProvider.

The component correctly extends the Radix primitive with sensible defaults and follows React best practices.


31-35: LGTM! Simple and effective wrapper.

The TooltipTrigger component correctly wraps the Radix primitive.

apps/web/utils/scheduled-actions/executor.ts (1)

240-306: LGTM! Well-structured helper functions.

The helper functions are focused, properly handle their responsibilities, and include appropriate logging.

apps/web/prisma/schema.prisma (3)

423-428: Note: These fields appear unrelated to the delayed actions feature.

The draftId, wasDraftSent, and draftSendLog fields seem to be for a different feature (draft tracking) and are not mentioned in the PR summary for delayed actions.

Likely an incorrect or invalid review comment.


430-462: LGTM! Well-designed ScheduledAction model.

The model has appropriate fields, relationships, and indexes for efficient querying. The separation of status (action execution) and schedulingStatus (QStash scheduling) provides good observability.


893-905: LGTM! Comprehensive status enums.

The enums properly model all states in the scheduled action lifecycle, with clear separation between execution status and scheduling status.

.cursor/rules/features/delayed-actions.mdc (2)

183-218: LGTM! Comprehensive usage documentation.

The examples, API endpoints, error handling, and monitoring sections provide clear guidance for using and operating the delayed actions feature.


16-16: Verified: Delay limits match documentation

The delayInMinutes schema enforces a minimum of 1 minute and a maximum of NINETY_DAYS_MINUTES (60 min × 24 hr × 90 days = 90 days), so the docs’ “1 minute to 90 days” range is accurate. No changes needed.

apps/web/prisma/migrations/20250626043046_add_scheduled_actions/migration.sql (1)

1-55: Well-structured migration with proper idempotency and indexing.

The migration correctly uses IF NOT EXISTS clauses for safe re-runs, establishes appropriate foreign key relationships with cascade behaviors, and includes optimized indexes for common query patterns. The schema design effectively supports the delayed actions feature.

apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx (5)

91-92: Proper implementation of feature flag and mutate pattern.

Good use of the feature flag hook and SWR's mutate function for optimistic UI updates.

Also applies to: 102-112


207-240: Well-implemented optimistic updates with proper error handling.

The optimistic update pattern correctly updates the UI immediately, revalidates on success, and resets on error. This provides excellent user experience while maintaining data consistency.


991-1005: Excellent implementation of delayed action UI with proper feature gating.

The delayed action controls are well-integrated with:

  • Feature flag gating for safe rollout
  • Memoized computation for performance
  • Clear user experience with toggle and tooltip
  • Proper validation and error handling

Also applies to: 1251-1291


1462-1527: Well-designed delay input controls with good UX.

The component provides excellent user experience with:

  • Intuitive value and unit selection
  • Proper input sanitization (numbers only)
  • Clean separation of display and storage logic
  • Consistent use of shadcn UI components

1529-1559: Clean and efficient time conversion utilities.

The helper functions handle edge cases well and provide intuitive unit selection based on divisibility. Good defensive programming with null/undefined checks.

apps/web/utils/scheduled-actions/scheduler.ts (2)

1-20: Well-structured module setup with proper error handling.

Good use of scoped logger and defensive programming with null client handling when QSTASH_TOKEN is not configured.


165-245: Robust cancellation logic with good error resilience.

Excellent implementation that:

  • Efficiently cancels QStash messages before database updates
  • Continues processing even if individual cancellations fail
  • Properly logs warnings without failing the entire operation
  • Returns useful count for caller feedback

Comment on lines +22 to +26
logger.info("QStash request received", {
url: request.url,
method: request.method,
headers: Object.fromEntries(request.headers.entries()),
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid logging sensitive request headers

Logging all request headers could potentially expose sensitive information like authentication tokens. Consider filtering sensitive headers or removing header logging in production.

       logger.info("QStash request received", {
         url: request.url,
         method: request.method,
-        headers: Object.fromEntries(request.headers.entries()),
+        // Only log non-sensitive headers
+        headers: {
+          'content-type': request.headers.get('content-type'),
+          'content-length': request.headers.get('content-length'),
+        },
       });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
logger.info("QStash request received", {
url: request.url,
method: request.method,
headers: Object.fromEntries(request.headers.entries()),
});
logger.info("QStash request received", {
url: request.url,
method: request.method,
// Only log non-sensitive headers
headers: {
'content-type': request.headers.get('content-type'),
'content-length': request.headers.get('content-length'),
},
});
🤖 Prompt for AI Agents
In apps/web/app/api/scheduled-actions/execute/route.ts around lines 22 to 26,
the code logs all request headers, which may expose sensitive information such
as authentication tokens. Modify the logging to either filter out sensitive
headers like Authorization and Cookie before logging or remove the headers from
the log entirely in production environments to protect sensitive data.

Comment on lines +39 to +52
const [isOpen, setIsOpen] = useState(false);

const handleClick = useCallback(() => {
setIsOpen((prev) => !prev);
}, []);

return (
<Tooltip content={text}>
<HelpCircleIcon
className={cn(tooltipIconVariants({ size }), className)}
/>
</Tooltip>
<TooltipProvider delayDuration={200}>
<Tooltip open={isOpen} onOpenChange={setIsOpen}>
<TooltipTrigger asChild>
<HelpCircleIcon
className={cn(tooltipIconVariants({ size }), className)}
onClick={handleClick}
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider standard tooltip behavior and improve accessibility

The current implementation uses onClick to toggle tooltip visibility, which deviates from standard tooltip UX patterns. Additionally, there are accessibility concerns:

  1. Tooltips typically appear on hover/focus, not click
  2. Missing keyboard support (Enter/Space keys)
  3. Missing ARIA attributes for screen readers
  4. No focus/blur handlers accompanying mouse events

Consider this more accessible implementation:

-  const [isOpen, setIsOpen] = useState(false);
-
-  const handleClick = useCallback(() => {
-    setIsOpen((prev) => !prev);
-  }, []);

   return (
     <TooltipProvider delayDuration={200}>
-      <Tooltip open={isOpen} onOpenChange={setIsOpen}>
+      <Tooltip>
         <TooltipTrigger asChild>
           <HelpCircleIcon
             className={cn(tooltipIconVariants({ size }), className)}
-            onClick={handleClick}
+            role="img"
+            aria-label="More information"
+            tabIndex={0}
           />
         </TooltipTrigger>

If click-to-toggle behavior is specifically required for this use case, add keyboard support:

   const handleClick = useCallback(() => {
     setIsOpen((prev) => !prev);
   }, []);
+
+  const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
+    if (e.key === 'Enter' || e.key === ' ') {
+      e.preventDefault();
+      setIsOpen((prev) => !prev);
+    }
+  }, []);

   return (
     <TooltipProvider delayDuration={200}>
       <Tooltip open={isOpen} onOpenChange={setIsOpen}>
         <TooltipTrigger asChild>
           <HelpCircleIcon
             className={cn(tooltipIconVariants({ size }), className)}
             onClick={handleClick}
+            onKeyDown={handleKeyDown}
+            role="button"
+            aria-label="Show tooltip"
+            aria-expanded={isOpen}
+            tabIndex={0}
           />
🤖 Prompt for AI Agents
In apps/web/components/TooltipExplanation.tsx around lines 39 to 52, the tooltip
currently toggles visibility only on click, which is not standard and lacks
accessibility features. To fix this, change the tooltip to open on hover and
focus events instead of click, add keyboard event handlers to support Enter and
Space keys if click-to-toggle is necessary, include appropriate ARIA attributes
for screen readers, and add focus and blur handlers to complement mouse events
for better accessibility compliance.

Comment on lines +104 to +105
if (!isTest) {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove empty if block

This empty if block appears to be incomplete or leftover code that should be removed.

-  if (!isTest) {
-  }
-
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!isTest) {
}
🤖 Prompt for AI Agents
In apps/web/utils/ai/choose-rule/run-rules.ts around lines 104 to 105, there is
an empty if block checking if !isTest. Remove this empty if block entirely as it
serves no purpose and may be leftover or incomplete code.

Comment on lines +107 to +111
const { immediateActions, delayedActions } = groupBy(actionItems, (item) =>
item.delayInMinutes != null && item.delayInMinutes > 0
? "delayedActions"
: "immediateActions",
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Handle potential undefined values from groupBy

The groupBy function returns an object that may not have both properties defined. Destructuring with defaults would be safer.

-  const { immediateActions, delayedActions } = groupBy(actionItems, (item) =>
+  const groupedActions = groupBy(actionItems, (item) =>
     item.delayInMinutes != null && item.delayInMinutes > 0
       ? "delayedActions"
       : "immediateActions",
   );
+  const immediateActions = groupedActions.immediateActions || [];
+  const delayedActions = groupedActions.delayedActions || [];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { immediateActions, delayedActions } = groupBy(actionItems, (item) =>
item.delayInMinutes != null && item.delayInMinutes > 0
? "delayedActions"
: "immediateActions",
);
const groupedActions = groupBy(actionItems, (item) =>
item.delayInMinutes != null && item.delayInMinutes > 0
? "delayedActions"
: "immediateActions",
);
const immediateActions = groupedActions.immediateActions || [];
const delayedActions = groupedActions.delayedActions || [];
🤖 Prompt for AI Agents
In apps/web/utils/ai/choose-rule/run-rules.ts around lines 107 to 111, the
destructuring of the groupBy result assumes both immediateActions and
delayedActions always exist, but groupBy may return an object missing one or
both keys. To fix this, provide default empty arrays when destructuring, such as
setting immediateActions = [] and delayedActions = [] to avoid undefined values
and potential runtime errors.


// Create ActionItem from scheduled action data
const actionItem: ActionItem = {
id: scheduledAction.id, // Use scheduled action ID temporarily
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Consider the implications of reusing the scheduled action ID.

Using the scheduled action ID as the temporary action item ID could cause conflicts if the ID is used elsewhere expecting a real action item ID.

Consider generating a temporary unique ID or documenting this behavior clearly:

-      id: scheduledAction.id, // Use scheduled action ID temporarily
+      id: `temp-${scheduledAction.id}`, // Use prefixed ID to indicate temporary nature
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
id: scheduledAction.id, // Use scheduled action ID temporarily
id: `temp-${scheduledAction.id}`, // Use prefixed ID to indicate temporary nature
🤖 Prompt for AI Agents
In apps/web/utils/scheduled-actions/executor.ts at line 61, avoid using the
scheduled action ID as the temporary action item ID to prevent potential ID
conflicts. Instead, generate a unique temporary ID (e.g., using a UUID or a
unique prefix) for the action item or add clear documentation explaining why the
scheduled action ID is reused and the implications of this choice.

Comment on lines +142 to +145
if (
error instanceof Error &&
error.message === "Requested entity was not found."
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make error detection more robust.

Checking for exact error message text is brittle and could break with API changes.

Consider checking error codes or status instead:

if (error instanceof Error) {
  // Check for 404 status if available
  const isNotFound = 
    error.message.includes("not found") ||
    error.message.includes("404") ||
    (error as any).code === 404;
  
  if (isNotFound) {
    // Handle not found case
  }
}
🤖 Prompt for AI Agents
In apps/web/utils/scheduled-actions/executor.ts around lines 142 to 145, the
current error check relies on an exact error message string which is fragile.
Update the condition to detect "not found" errors more robustly by checking if
the error message includes "not found" or "404", or if the error object has a
code property equal to 404. This will make the error handling resilient to minor
API message changes.

Comment on lines +41 to +133
describe("cancelScheduledActions", () => {
it("should cancel scheduled actions for a message", async () => {
// Mock finding actions to cancel
prisma.scheduledAction.findMany.mockResolvedValue([
{ id: "action-1", scheduledId: "qstash-msg-1" },
{ id: "action-2", scheduledId: "qstash-msg-2" },
] as any);

// Mock updating actions as cancelled
prisma.scheduledAction.updateMany.mockResolvedValue({ count: 2 });

const result = await cancelScheduledActions({
messageId: "msg-123",
emailAccountId: "account-123",
});

expect(prisma.scheduledAction.findMany).toHaveBeenCalledWith({
where: {
emailAccountId: "account-123",
messageId: "msg-123",
status: ScheduledActionStatus.PENDING,
},
select: {
id: true,
scheduledId: true,
},
});

expect(prisma.scheduledAction.updateMany).toHaveBeenCalledWith({
where: {
emailAccountId: "account-123",
messageId: "msg-123",
status: ScheduledActionStatus.PENDING,
},
data: {
status: ScheduledActionStatus.CANCELLED,
},
});

expect(result).toBe(2);
});

it("should return zero when no actions to cancel", async () => {
prisma.scheduledAction.findMany.mockResolvedValue([]);
prisma.scheduledAction.updateMany.mockResolvedValue({ count: 0 });

const result = await cancelScheduledActions({
messageId: "msg-456",
emailAccountId: "account-123",
});

expect(result).toBe(0);
});

it("should include threadId when provided", async () => {
prisma.scheduledAction.findMany.mockResolvedValue([
{ id: "action-1", scheduledId: "qstash-msg-1" },
] as any);
prisma.scheduledAction.updateMany.mockResolvedValue({ count: 1 });

await cancelScheduledActions({
messageId: "msg-123",
emailAccountId: "account-123",
threadId: "thread-123",
reason: "Custom reason",
});

expect(prisma.scheduledAction.findMany).toHaveBeenCalledWith({
where: {
emailAccountId: "account-123",
messageId: "msg-123",
threadId: "thread-123",
status: ScheduledActionStatus.PENDING,
},
select: {
id: true,
scheduledId: true,
},
});

expect(prisma.scheduledAction.updateMany).toHaveBeenCalledWith({
where: {
emailAccountId: "account-123",
messageId: "msg-123",
threadId: "thread-123",
status: ScheduledActionStatus.PENDING,
},
data: {
status: ScheduledActionStatus.CANCELLED,
},
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add test coverage for error scenarios and edge cases

The test suite is missing coverage for important scenarios:

  1. QStash deletion failures (should log but not fail the entire operation)
  2. Error handling when database operations fail
  3. Usage of the optional reason parameter

Add these test cases:

it("should continue cancellation even if QStash deletion fails", async () => {
  prisma.scheduledAction.findMany.mockResolvedValue([
    { id: "action-1", scheduledId: "qstash-msg-1" },
  ] as any);
  prisma.scheduledAction.updateMany.mockResolvedValue({ count: 1 });
  
  // Mock QStash deletion failure
  vi.mocked(qstash.messages.delete).mockRejectedValueOnce(
    new Error("QStash error")
  );

  const result = await cancelScheduledActions({
    messageId: "msg-123",
    emailAccountId: "account-123",
  });

  // Should still update the database despite QStash error
  expect(prisma.scheduledAction.updateMany).toHaveBeenCalled();
  expect(result).toBe(1);
});

it("should handle database errors", async () => {
  prisma.scheduledAction.findMany.mockRejectedValue(
    new Error("Database error")
  );

  await expect(
    cancelScheduledActions({
      messageId: "msg-123",
      emailAccountId: "account-123",
    })
  ).rejects.toThrow("Database error");
});

it("should use custom reason when provided", async () => {
  prisma.scheduledAction.findMany.mockResolvedValue([
    { id: "action-1", scheduledId: "qstash-msg-1" },
  ] as any);
  prisma.scheduledAction.updateMany.mockResolvedValue({ count: 1 });

  await cancelScheduledActions({
    messageId: "msg-123",
    emailAccountId: "account-123",
    reason: "Custom cancellation reason",
  });

  // Verify the reason is logged (would need to spy on logger)
});
🤖 Prompt for AI Agents
In apps/web/utils/scheduled-actions/scheduler.test.ts between lines 41 and 133,
add test cases to cover error scenarios and edge cases missing from the current
suite. Specifically, add a test to verify that cancellation continues even if
QStash message deletion fails by mocking qstash.messages.delete to reject and
asserting the updateMany call still happens and returns the expected count. Add
a test to handle database errors by mocking findMany to reject and asserting
that cancelScheduledActions throws the error. Finally, add a test to confirm the
optional reason parameter is used by passing a custom reason and verifying it is
logged, which may require spying on the logger. These additions ensure robust
error handling and full coverage of optional parameters.

Comment on lines +41 to +81
describe("cancelScheduledActions", () => {
it("should cancel scheduled actions for a message", async () => {
// Mock finding actions to cancel
prisma.scheduledAction.findMany.mockResolvedValue([
{ id: "action-1", scheduledId: "qstash-msg-1" },
{ id: "action-2", scheduledId: "qstash-msg-2" },
] as any);

// Mock updating actions as cancelled
prisma.scheduledAction.updateMany.mockResolvedValue({ count: 2 });

const result = await cancelScheduledActions({
messageId: "msg-123",
emailAccountId: "account-123",
});

expect(prisma.scheduledAction.findMany).toHaveBeenCalledWith({
where: {
emailAccountId: "account-123",
messageId: "msg-123",
status: ScheduledActionStatus.PENDING,
},
select: {
id: true,
scheduledId: true,
},
});

expect(prisma.scheduledAction.updateMany).toHaveBeenCalledWith({
where: {
emailAccountId: "account-123",
messageId: "msg-123",
status: ScheduledActionStatus.PENDING,
},
data: {
status: ScheduledActionStatus.CANCELLED,
},
});

expect(result).toBe(2);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add assertions for QStash message deletion calls

The test verifies Prisma operations but doesn't assert that QStash messages were actually deleted. Consider adding these assertions to ensure complete coverage of the cancellation flow.

+import { qstash } from "@/utils/upstash";
+
 describe("cancelScheduledActions", () => {
   it("should cancel scheduled actions for a message", async () => {
     // Mock finding actions to cancel
     prisma.scheduledAction.findMany.mockResolvedValue([
       { id: "action-1", scheduledId: "qstash-msg-1" },
       { id: "action-2", scheduledId: "qstash-msg-2" },
     ] as any);

     // Mock updating actions as cancelled
     prisma.scheduledAction.updateMany.mockResolvedValue({ count: 2 });

     const result = await cancelScheduledActions({
       messageId: "msg-123",
       emailAccountId: "account-123",
     });

     expect(prisma.scheduledAction.findMany).toHaveBeenCalledWith({
       where: {
         emailAccountId: "account-123",
         messageId: "msg-123",
         status: ScheduledActionStatus.PENDING,
       },
       select: {
         id: true,
         scheduledId: true,
       },
     });

     expect(prisma.scheduledAction.updateMany).toHaveBeenCalledWith({
       where: {
         emailAccountId: "account-123",
         messageId: "msg-123",
         status: ScheduledActionStatus.PENDING,
       },
       data: {
         status: ScheduledActionStatus.CANCELLED,
       },
     });

+    // Verify QStash messages were deleted
+    expect(qstash.messages.delete).toHaveBeenCalledTimes(2);
+    expect(qstash.messages.delete).toHaveBeenCalledWith("qstash-msg-1");
+    expect(qstash.messages.delete).toHaveBeenCalledWith("qstash-msg-2");

     expect(result).toBe(2);
   });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe("cancelScheduledActions", () => {
it("should cancel scheduled actions for a message", async () => {
// Mock finding actions to cancel
prisma.scheduledAction.findMany.mockResolvedValue([
{ id: "action-1", scheduledId: "qstash-msg-1" },
{ id: "action-2", scheduledId: "qstash-msg-2" },
] as any);
// Mock updating actions as cancelled
prisma.scheduledAction.updateMany.mockResolvedValue({ count: 2 });
const result = await cancelScheduledActions({
messageId: "msg-123",
emailAccountId: "account-123",
});
expect(prisma.scheduledAction.findMany).toHaveBeenCalledWith({
where: {
emailAccountId: "account-123",
messageId: "msg-123",
status: ScheduledActionStatus.PENDING,
},
select: {
id: true,
scheduledId: true,
},
});
expect(prisma.scheduledAction.updateMany).toHaveBeenCalledWith({
where: {
emailAccountId: "account-123",
messageId: "msg-123",
status: ScheduledActionStatus.PENDING,
},
data: {
status: ScheduledActionStatus.CANCELLED,
},
});
expect(result).toBe(2);
});
import { qstash } from "@/utils/upstash";
describe("cancelScheduledActions", () => {
it("should cancel scheduled actions for a message", async () => {
// Mock finding actions to cancel
prisma.scheduledAction.findMany.mockResolvedValue([
{ id: "action-1", scheduledId: "qstash-msg-1" },
{ id: "action-2", scheduledId: "qstash-msg-2" },
] as any);
// Mock updating actions as cancelled
prisma.scheduledAction.updateMany.mockResolvedValue({ count: 2 });
const result = await cancelScheduledActions({
messageId: "msg-123",
emailAccountId: "account-123",
});
expect(prisma.scheduledAction.findMany).toHaveBeenCalledWith({
where: {
emailAccountId: "account-123",
messageId: "msg-123",
status: ScheduledActionStatus.PENDING,
},
select: {
id: true,
scheduledId: true,
},
});
expect(prisma.scheduledAction.updateMany).toHaveBeenCalledWith({
where: {
emailAccountId: "account-123",
messageId: "msg-123",
status: ScheduledActionStatus.PENDING,
},
data: {
status: ScheduledActionStatus.CANCELLED,
},
});
// Verify QStash messages were deleted
expect(qstash.messages.delete).toHaveBeenCalledTimes(2);
expect(qstash.messages.delete).toHaveBeenCalledWith("qstash-msg-1");
expect(qstash.messages.delete).toHaveBeenCalledWith("qstash-msg-2");
expect(result).toBe(2);
});
});
🤖 Prompt for AI Agents
In apps/web/utils/scheduled-actions/scheduler.test.ts between lines 41 and 81,
the test for cancelScheduledActions mocks and asserts Prisma database calls but
lacks assertions verifying that QStash messages were deleted. To fix this, add
assertions that confirm the QStash message deletion function was called with the
expected scheduledIds, ensuring the test fully covers the cancellation flow
including external message deletions.

Comment on lines +22 to +112
export async function createScheduledAction({
executedRuleId,
actionItem,
messageId,
threadId,
emailAccountId,
scheduledFor,
}: {
executedRuleId: string;
actionItem: ActionItem;
messageId: string;
threadId: string;
emailAccountId: string;
scheduledFor: Date;
}) {
if (!canActionBeDelayed(actionItem.type)) {
throw new Error(
`Action type ${actionItem.type} is not supported for delayed execution`,
);
}

if (actionItem.delayInMinutes == null || actionItem.delayInMinutes <= 0) {
throw new Error(
`Invalid delayInMinutes: ${actionItem.delayInMinutes}. Must be a positive number.`,
);
}

try {
const scheduledAction = await prisma.scheduledAction.create({
data: {
executedRuleId,
actionType: actionItem.type,
messageId,
threadId,
emailAccountId,
scheduledFor,
status: ScheduledActionStatus.PENDING,
// Store ActionItem data for later execution
label: actionItem.label,
subject: actionItem.subject,
content: actionItem.content,
to: actionItem.to,
cc: actionItem.cc,
bcc: actionItem.bcc,
url: actionItem.url,
},
});

const payload: ScheduledActionPayload = {
scheduledActionId: scheduledAction.id,
};

const deduplicationId = `scheduled-action-${scheduledAction.id}`;

const scheduledId = await scheduleMessage({
payload,
delayInMinutes: actionItem.delayInMinutes,
deduplicationId,
});

if (scheduledId) {
await prisma.scheduledAction.update({
where: { id: scheduledAction.id },
data: {
scheduledId,
schedulingStatus: "SCHEDULED" as const,
},
});
}

logger.info("Created and scheduled action with QStash", {
scheduledActionId: scheduledAction.id,
actionType: actionItem.type,
scheduledFor,
messageId,
threadId,
deduplicationId,
});

return scheduledAction;
} catch (error) {
logger.error("Failed to create QStash scheduled action", {
error,
executedRuleId,
actionType: actionItem.type,
messageId,
threadId,
});
throw error;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Consider handling potential inconsistency between QStash and database.

The implementation is solid with good validation and error handling. However, there's a potential issue: if QStash scheduling succeeds (line 76-80) but the database update fails (line 83-90), you could have an orphaned scheduled message in QStash without a corresponding scheduledId in the database.

Consider wrapping the QStash scheduling and database update in a transaction-like pattern or implementing compensating logic to cancel the QStash message if the database update fails.

🤖 Prompt for AI Agents
In apps/web/utils/scheduled-actions/scheduler.ts between lines 70 and 95, there
is a risk of inconsistency if scheduling the message with QStash succeeds but
updating the database with the scheduledId fails, leaving orphaned scheduled
messages. To fix this, implement a transaction-like flow by first scheduling the
message with QStash, then updating the database inside a try-catch block. If the
database update fails, add compensating logic to cancel or delete the scheduled
message from QStash to maintain consistency. Ensure error handling covers both
operations to avoid orphaned entries.

@elie222
Copy link
Owner

elie222 commented Jul 22, 2025

@claude review this

@claude
Copy link

claude bot commented Jul 22, 2025

Claude encountered an error —— View job

Failed with exit code 128

I'll analyze this and get back to you.

@elie222 elie222 merged commit 6c836ee into elie222:staging Jul 23, 2025
21 of 23 checks passed
@edulelis edulelis deleted the fix-staging-conflict-v1 branch July 24, 2025 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments