Skip to content

Comments

Presets#402

Merged
elie222 merged 12 commits intomainfrom
preset-checks
Apr 14, 2025
Merged

Presets#402
elie222 merged 12 commits intomainfrom
preset-checks

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Apr 13, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a new badge display in the RuleForm based on the system type of the rule.
    • Enhanced rule creation and updates to include a new system type for better categorization.
    • Improved rule matching by incorporating checks for calendar events and refining filtering based on sender reply history.
    • Added functionality to check sender reply history via the Gmail API for better context in rule matching.
    • Implemented new logic for handling calendar events based on .ics file attachments.
    • Introduced a new type for handling preset matches in the rule logic.
    • Streamlined user preferences to focus on system types instead of rule names.
    • Enhanced the reply tracker enabling logic to directly utilize system types for improved clarity and efficiency.
    • Added a new optional field for system type in the Rule model for enhanced categorization.
    • Updated the database schema to standardize system type values for rules.

@vercel
Copy link

vercel bot commented Apr 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
inbox-zero ✅ Ready (Inspect) Visit Preview Apr 14, 2025 10:58am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 13, 2025

Walkthrough

The changes introduce functionality for handling system types in rules, enhancing the integration of Gmail context into rule matching. The UI components are updated to conditionally display badges based on the systemType. The Prisma schema is modified to include a new optional field and an enum for system types. Business logic in actions, validation, and rule-matching functions is updated to accommodate these system types, including calendar event detection and filtering of TO_REPLY rules based on sender reply history. Type definitions are refined with new entities such as CoreConditionType and PresetMatch, and a new module for checking sender reply history using the Gmail API is introduced.

Changes

File(s) Change Summary
apps/web/app/(app)/automation/RuleForm.tsx Introduces showSystemTypeBadge function to conditionally display badges based on systemType and updates unusedCondition type to CoreConditionType.
apps/web/app/(app)/automation/rule/create/page.tsx Updates type imports and definitions to use CoreConditionType instead of ConditionType.
apps/web/prisma/schema.prisma Adds an optional systemType field to the Rule model and introduces the SystemType enum (TO_REPLY, NEWSLETTER, MARKETING, CALENDAR, RECEIPT, NOTIFICATION).
apps/web/utils/actions/rule.ts Incorporates systemType into createRuleAction and updateRuleAction functions for rule creation and updates.
apps/web/utils/actions/rule.validation.ts Adds systemType field to createRuleBody schema, allowing specification of system types during rule creation.
apps/web/utils/ai/choose-rule/match-rules.ts Enhances rule matching by adding logic for calendar event detection and filtering TO_REPLY presets based on sender reply history.
apps/web/utils/ai/choose-rule/types.ts Introduces new PresetMatch type to the MatchReason union type.
apps/web/utils/condition.ts
apps/web/utils/config.ts
Updates condition handling by adding PRESET support and defining CoreConditionType (excluding "GROUP" and "PRESET").
apps/web/utils/reply-tracker/check-sender-reply-history.ts Introduces new helper functions to check sender reply history using the Gmail API.
apps/web/utils/parse/calender-event.ts Modifies calendar event detection logic to use attachment checks instead of parsing email body.
apps/web/app/api/user/rules/route.ts Simplifies the getRules function's parameter destructuring for accessing userId.
apps/web/utils/reply-tracker/enable.ts Modifies logic for enabling reply tracking to filter based on systemType.
apps/web/utils/rule/rule.ts Adds systemType as an optional parameter in safeCreateRule and createRule functions.
apps/web/utils/ai/choose-rule/match-rules.test.ts
apps/web/utils/ai/choose-rule/run-rules.ts
Updates function signatures to include gmail parameter for rule matching functions.
apps/web/utils/ai/reply/check-reply-tracking.ts Removes the aiFindReplyTrackingRule function.

Sequence Diagram(s)

sequenceDiagram
    participant Msg as Incoming Message
    participant RM as Rule Matcher
    participant GAPI as Gmail API
    participant CRH as Reply History Checker

    Msg->>RM: Process message for matching
    RM->>RM: Check for calendar event preset
    alt Calendar Event Detected
        RM->>RM: Select CALENDAR rule preset
    else Non-calendar Event
        RM->>GAPI: Invoke Gmail API with sender info
        GAPI->>CRH: Execute reply history check
        CRH-->>GAPI: Return reply status and count
        GAPI-->>RM: Provide reply data
        RM->>RM: Filter out TO_REPLY preset if criteria met
    end
    RM-->>Msg: Return matched rule result
Loading
sequenceDiagram
    participant U as User
    participant RF as RuleForm Component
    participant GD as getSystemTypeDisplay
    participant UI as UI Badge/Tooltip

    U->>RF: Load rule form
    RF->>GD: Get display info for system type
    GD-->>RF: Return system type name and description
    RF->>UI: Render system type badge with tooltip
    UI-->>U: Display system type information
Loading

Possibly related PRs

Poem

I'm a rabbit with a coder's delight,
Hopping through code in the soft moonlight.
System types bloom like carrots fresh and sweet,
Gmail clues guiding every beat.
My little paws tap keys in joyful play,
Celebrating changes on this bright new day.
🥕🐇 Happy coding all the way!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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

Oops! Something went wrong! :(

ESLint: 9.23.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

apps/web/utils/reply-tracker/check-sender-reply-history.ts

Oops! Something went wrong! :(

ESLint: 9.23.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bcfd5c7 and 105393a.

📒 Files selected for processing (2)
  • apps/web/utils/actions/rule.validation.ts (2 hunks)
  • apps/web/utils/reply-tracker/check-sender-reply-history.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/reply-tracker/check-sender-reply-history.ts

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 1

🧹 Nitpick comments (2)
apps/web/utils/ai/choose-rule/match-rules.ts (2)

51-69: Potential for multi-rule handling.
The current logic immediately returns after finding a matching calendar rule. If future requirements involve applying multiple calendar rules, consider continuing evaluation rather than returning early.


308-352: Make threshold and user context configurable.
At present, the threshold of 10 messages is hard-coded. If you expect dynamic requirements or user-specific variations, consider an approach that parametrizes the threshold and integrates user context for more flexible filtering.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6355e0 and a4b4231.

📒 Files selected for processing (10)
  • apps/web/app/(app)/automation/RuleForm.tsx (5 hunks)
  • apps/web/app/(app)/automation/rule/create/page.tsx (1 hunks)
  • apps/web/prisma/schema.prisma (2 hunks)
  • apps/web/utils/actions/rule.ts (2 hunks)
  • apps/web/utils/actions/rule.validation.ts (2 hunks)
  • apps/web/utils/ai/choose-rule/match-rules.ts (5 hunks)
  • apps/web/utils/ai/choose-rule/types.ts (2 hunks)
  • apps/web/utils/condition.ts (3 hunks)
  • apps/web/utils/config.ts (1 hunks)
  • apps/web/utils/reply-tracker/query.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
apps/web/app/(app)/automation/RuleForm.tsx (2)
apps/web/utils/config.ts (1)
  • CoreConditionType (14-14)
apps/web/components/ui/badge.tsx (1)
  • Badge (39-39)
apps/web/utils/ai/choose-rule/types.ts (1)
apps/web/utils/config.ts (2)
  • ConditionType (5-11)
  • ConditionType (13-13)
apps/web/app/(app)/automation/rule/create/page.tsx (1)
apps/web/utils/config.ts (1)
  • CoreConditionType (14-14)
apps/web/utils/condition.ts (1)
apps/web/utils/config.ts (3)
  • CoreConditionType (14-14)
  • ConditionType (5-11)
  • ConditionType (13-13)
🔇 Additional comments (27)
apps/web/utils/config.ts (2)

10-10: LGTM: New condition type added

The PRESET value is added to ConditionType enum, allowing preset-based conditions throughout the application.


14-14: Well-defined type utility

The CoreConditionType utility type properly excludes "GROUP" and "PRESET" from the ConditionType, focusing on the core condition types that can be directly configured. This is a good practice for type safety.

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

6-6: New import added correctly

The PresetType enum is properly imported from @prisma/client.


124-124: Validation properly implemented for new field

The presetType field is correctly defined in the schema with appropriate validation, allowing only the specific preset types defined in the enum and marking it as optional with .nullish().

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

209-211: Good documentation and field structure

The comment explaining the purpose of the field is helpful, and the field definition is correctly structured as a nullable PresetType.


608-611: Well-defined enum for preset types

The PresetType enum is defined with clear values that reflect their intended purpose: CALENDAR for calendar-related rules and TO_REPLY for reply-related rules.

apps/web/utils/ai/choose-rule/types.ts (3)

1-7: Required import added for type safety

The PresetType import is correctly added to support the new preset functionality in the type system.


30-33: Well-structured type definition

The PresetMatch type is correctly defined, following the same pattern as other match types with a type field that extracts the specific condition type and includes the necessary presetType property.


35-40: Union type properly updated

The MatchReason union type has been correctly updated to include the new PresetMatch type, ensuring type safety throughout the application when working with rule matches.

apps/web/app/(app)/automation/RuleForm.tsx (6)

34-34: Added PresetType import for new preset feature.

The import of PresetType from @prisma/client is correctly added to support the new preset type functionality in the form.


36-36: Updated import to use CoreConditionType.

Import was properly updated to include the CoreConditionType type, which excludes "GROUP" and "PRESET" condition types as defined in the config file.


122-126: Added preset type display information.

This code nicely handles the conditional display of preset information in the form, checking if the rule has a preset type before attempting to get its display information.


204-204: Updated type definition for unusedCondition.

The type has been correctly changed from Exclude<ConditionType, "GROUP"> to CoreConditionType to maintain consistency with the updated type system.


272-277: Added UI components to display preset information.

The implementation correctly uses a Badge component to display the preset name along with a tooltip explaining its purpose. This helps users understand the special behavior of preset rules.


979-996: Well-implemented preset type display function.

The getPresetTypeDisplay function is well-structured with a clear switch statement to handle different preset types, providing appropriate name and description for each type. The default case handles any future preset types that might be added.

apps/web/app/(app)/automation/rule/create/page.tsx (2)

5-5: Updated import to use CoreConditionType.

The import statement has been correctly updated to use CoreConditionType instead of ConditionType, ensuring consistency with the type system changes.


11-11: Updated type definition in searchParams.

The type for the type property in searchParams has been updated to use CoreConditionType instead of Exclude<ConditionType, "GROUP">, maintaining consistency with the updated type system throughout the application.

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

88-88: Added presetType to rule creation data.

This line correctly adds the presetType property to the data object when creating a rule, with appropriate fallback to undefined if not provided.


163-163: Added presetType to rule update data.

This line correctly adds the presetType property to the data object when updating a rule, with appropriate fallback to undefined if not provided.

apps/web/utils/condition.ts (3)

7-7: Updated import to include CoreConditionType.

Import statement has been correctly updated to include CoreConditionType alongside ConditionType, supporting the type system changes in the application.


94-94: Updated parameter type for getEmptyCondition.

The parameter type for getEmptyCondition has been correctly updated from Exclude<ConditionType, "GROUP"> to CoreConditionType, maintaining consistency with the type system changes.


182-183: Added PRESET case to conditionTypeToString.

This addition properly handles the new PRESET condition type in the conditionTypeToString function, ensuring it returns the correct string representation.

apps/web/utils/reply-tracker/query.ts (2)

22-26: Re-examine the fallback to hasReplied: true.
When extractEmailAddress fails, this function defaults to { hasReplied: true }. This may inadvertently skip a needed reply for invalid emails, so verify this aligns with your intended logic.


28-29: Default logic is sound.
Returning { hasReplied: false, receivedCount: 0 } is straightforward and paves the way for future Gmail API integration.

apps/web/utils/ai/choose-rule/match-rules.ts (3)

11-16: No concerns with the new imports.
These imported types and enums appear necessary for the new calendar and reply preset features.


29-30: Effective use of newly introduced utilities.
Both analyzeCalendarEvent and checkSenderReplyHistory are integrated below, enhancing the rule evaluation logic.


173-179: Placement of the TO_REPLY filter is appropriate.
Applying the filter before final AI-based matching makes logical sense. This ensures that invalid reply scenarios are excluded before further processing.

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: 0

🧹 Nitpick comments (2)
apps/web/utils/ai/choose-rule/match-rules.ts (1)

35-35: Consider making the threshold configurable

The threshold for determining when to filter out TO_REPLY rules is hardcoded. Consider making this configurable per user or exposing it as a system setting.

-const TO_REPLY_RECEIVED_THRESHOLD = 10;
+// Make configurable via environment or user settings
+const TO_REPLY_RECEIVED_THRESHOLD = process.env.TO_REPLY_THRESHOLD 
+  ? parseInt(process.env.TO_REPLY_THRESHOLD, 10) 
+  : 10;
apps/web/utils/reply-tracker/check-sender-reply-history.ts (1)

62-107: Export function with clear documentation and parallel processing.

The checkSenderReplyHistory function:

  • Has excellent JSDoc comments explaining its purpose and parameters
  • Properly extracts and validates the sender email
  • Efficiently runs checks in parallel using Promise.all
  • Includes comprehensive error handling and logging
  • Returns sensible default values in error cases

One minor suggestion:

Consider adding a timeout to the Promise.all call to prevent long-running queries:

    // Run checks in parallel for efficiency
    const [hasReplied, receivedCount] = await Promise.all([
      checkIfReplySent(gmail, cleanSenderEmail),
      countReceivedMessages(gmail, cleanSenderEmail, receivedThreshold),
-   ]);
+   ]).catch(error => {
+     logger.error("Timeout or error in parallel operations", { 
+       error, 
+       cleanSenderEmail 
+     });
+     return [true, 0]; // Safe defaults
+   });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4b4231 and f56a4c2.

📒 Files selected for processing (4)
  • apps/web/utils/ai/choose-rule/match-rules.test.ts (16 hunks)
  • apps/web/utils/ai/choose-rule/match-rules.ts (9 hunks)
  • apps/web/utils/ai/choose-rule/run-rules.ts (1 hunks)
  • apps/web/utils/reply-tracker/check-sender-reply-history.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/web/utils/ai/choose-rule/run-rules.ts (1)
apps/web/utils/ai/choose-rule/match-rules.ts (1)
  • findMatchingRule (205-216)
apps/web/utils/ai/choose-rule/match-rules.test.ts (1)
apps/web/utils/ai/choose-rule/match-rules.ts (1)
  • findMatchingRule (205-216)
🔇 Additional comments (12)
apps/web/utils/ai/choose-rule/match-rules.ts (5)

1-1: Added necessary imports for preset functionality

The new imports correctly support the calendar event detection and reply history tracking features.

Also applies to: 16-17, 30-31


56-74: Well-implemented calendar event detection

The calendar event detection and matching logic is clear and straightforward, with proper logging and early returns for improved performance.


179-185: Appropriately filtering potential matches

The updated return value correctly applies the TO_REPLY preset filtering logic to potential matches before returning them.


209-209: Consistently updated function signatures

Function signatures are consistently updated throughout the file to include the Gmail parameter.

Also applies to: 222-222


318-365: Robust implementation of reply history filtering

The TO_REPLY preset filtering logic is well-implemented with:

  1. Early returns for efficiency
  2. Clear error handling that doesn't block rule processing on failure
  3. Informative logging
  4. Careful consideration of edge cases

This effectively prevents showing TO_REPLY prompts for senders who have sent many messages without receiving replies.

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

48-48: Update to include Gmail context in rule matching logic.

The parameter gmail is now passed to findMatchingRule which aligns with the new function signature in match-rules.ts. This enables the rule matching logic to utilize Gmail-specific functionalities like checking sender reply history for preset rules.

apps/web/utils/ai/choose-rule/match-rules.test.ts (3)

2-2: Import of Gmail type added correctly.

The gmail_v1 type from @googleapis/gmail is correctly imported to support the updated function signature.


24-24: Gmail mock object added appropriately.

An empty Gmail mock object is created to pass to findMatchingRule calls throughout the test file. This allows tests to remain valid without requiring actual Gmail API interactions.


110-110: Test cases updated to include Gmail parameter.

All test cases have been properly updated to include the gmail parameter in their calls to findMatchingRule, maintaining consistency with the updated function signature.

Also applies to: 124-124, 138-138, 163-163, 182-182, 201-201, 237-237, 267-267, 298-298, 320-320, 341-341, 383-383, 423-423, 464-464

apps/web/utils/reply-tracker/check-sender-reply-history.ts (3)

1-7: Well-structured imports and logger setup.

The file correctly imports necessary dependencies and establishes a scoped logger for tracking reply-related queries.


8-26: Helper function implemented with proper error handling.

The checkIfReplySent function correctly queries the Gmail API to check if the user has sent a reply to the specified sender. The error handling is appropriate, defaulting to true on error which is a safer approach for TO_REPLY filtering.


28-60: Message counting function appropriately limited by threshold.

The countReceivedMessages function efficiently counts messages from a sender up to the provided threshold. The query and error handling are well-implemented.

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: 0

🧹 Nitpick comments (2)
apps/web/utils/reply-tracker/check-sender-reply-history.ts (2)

75-107: Consider adding pagination for more accurate message counting

The current implementation only counts messages up to the threshold in a single request. If there's a need to accurately count all messages (even if capped at the threshold), consider implementing pagination to retrieve all relevant messages.

Example implementation with pagination:

async function countReceivedMessages(
  gmail: gmail_v1.Gmail,
  cleanSenderEmail: string,
  threshold: number,
): Promise<number> {
  try {
    const query = `from:${cleanSenderEmail}`;
    logger.info(`Checking received message count (up to ${threshold})`, {
      cleanSenderEmail,
      threshold,
    });

-    // Fetch up to the threshold number of message IDs.
-    const response = await getMessages(gmail, {
-      query,
-      maxResults: threshold,
-    });
-    const count = response.messages?.length ?? 0;
+    // Implement pagination to get accurate count up to threshold
+    let count = 0;
+    let pageToken: string | undefined;
+    
+    do {
+      const response = await getMessages(gmail, {
+        query,
+        maxResults: Math.min(100, threshold - count), // Gmail API usually limits to 100 per page
+        pageToken,
+      });
+      
+      count += response.messages?.length ?? 0;
+      pageToken = response.nextPageToken;
+      
+      // Stop if we've reached the threshold or there are no more pages
+    } while (pageToken && count < threshold);

    logger.info("Received message count check result", {
      cleanSenderEmail,
      count,
    });
    return count;
  } catch (error) {
    logger.error("Error counting received messages", {
      error,
      cleanSenderEmail,
    });
    return 0; // Default to 0 on error
  }
}

16-53: Consider validating the receivedThreshold parameter

The receivedThreshold parameter is not validated. Consider adding validation to ensure it's a positive number to prevent unexpected behavior.

export async function checkSenderReplyHistory(
  gmail: gmail_v1.Gmail,
  senderEmail: string,
  receivedThreshold: number,
): Promise<{ hasReplied: boolean; receivedCount: number }> {
+  // Validate threshold is a positive number
+  if (!Number.isInteger(receivedThreshold) || receivedThreshold <= 0) {
+    logger.warn("Invalid receivedThreshold parameter", { receivedThreshold });
+    receivedThreshold = 5; // Default to a reasonable value
+  }
+
  const cleanSenderEmail = extractEmailAddress(senderEmail);
  if (!cleanSenderEmail) {
    logger.warn("Could not extract email from sender", { senderEmail });
    // Default to assuming a reply might be needed if email is invalid
    return { hasReplied: true, receivedCount: 0 };
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f56a4c2 and 76c68a9.

📒 Files selected for processing (1)
  • apps/web/utils/reply-tracker/check-sender-reply-history.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/utils/reply-tracker/check-sender-reply-history.ts (3)
apps/web/utils/logger.ts (1)
  • createScopedLogger (17-65)
apps/web/utils/email.ts (1)
  • extractEmailAddress (16-36)
apps/web/utils/gmail/message.ts (1)
  • getMessages (191-209)
🔇 Additional comments (5)
apps/web/utils/reply-tracker/check-sender-reply-history.ts (5)

1-7: Good job with imports and logger setup

The imports are well-organized and the scoped logger is appropriately named for the module's context.


8-26: Default return value may lead to confusing behavior

The function returns { hasReplied: true, receivedCount: 0 } when it cannot extract an email. While the comment explains this is to assume "a reply might be needed," this behavior might be counterintuitive. Consider if returning this default value aligns with your application's expected behavior.

Also, note that extractEmailAddress can return an empty string for invalid inputs, which your function correctly handles.


28-53: Well-structured async processing with proper error handling

Excellent job using Promise.all to run the checks in parallel for efficiency. The error handling is comprehensive with appropriate logging that includes relevant context.


71-72: Verify default error behavior aligns with business logic

Defaulting to return true on error might mask actual issues. While the comment explains it's "safer for TO_REPLY filtering," ensure this aligns with the expected application behavior.


55-73:

Details

❓ Verification inconclusive

Consider query parameter sanitization

While you're using the cleaned email address, Gmail queries might benefit from additional sanitization to prevent potential query injection issues.


🏁 Script executed:

#!/bin/bash
# Check if the cleanSenderEmail variable is properly sanitized for Gmail query

# Look for other instances of Gmail query construction to see if sanitization is applied
rg -A 2 -B 2 "query = " --glob "*.ts"

# Check if there's any existing sanitization function for Gmail queries
rg "sanitize.*query|clean.*query" --glob "*.ts"

Length of output: 10307


Review: Ensure Robust Sanitization of Gmail Query Parameters

While the code uses the cleanSenderEmail variable when constructing the Gmail query, our search indicates that there isn’t a dedicated sanitization function (e.g., one named like sanitizeQuery) applied across similar query constructions in the codebase. Although the variable name suggests prior cleaning, it isn’t clear if that step fully escapes or validates the input to prevent query injection.

  • Please verify that cleanSenderEmail is rigorously sanitized (or consider adding an explicit sanitization/escaping mechanism) before it's interpolated into the query string.
  • Review upstream cleaning routines to ensure they account for all potential query injection vectors.

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: 1

🧹 Nitpick comments (2)
apps/web/utils/ai/choose-rule/match-rules.ts (2)

35-35: Document the threshold value selection.

The TO_REPLY_RECEIVED_THRESHOLD constant value of 10 appears to be an important business rule threshold. Consider adding a comment explaining why this specific value was chosen and the reasoning behind it.

-const TO_REPLY_RECEIVED_THRESHOLD = 10;
+/**
+ * Threshold for the number of emails received from a sender without reply
+ * before we stop suggesting TO_REPLY preset. This ensures we don't keep 
+ * suggesting replies to senders the user consistently ignores.
+ */
+const TO_REPLY_RECEIVED_THRESHOLD = 10;

319-365: Enhance documentation for TO_REPLY filtering logic.

The filterToReplyPreset function implements sophisticated filtering logic for TO_REPLY preset rules, but the business logic could be better documented. Additionally, the function assumes the sender's email is in a specific format in message.headers.from.

Consider adding more detailed comments explaining:

  1. Why we filter out TO_REPLY preset for senders with no reply history but high received count
  2. How to extract and validate the sender email more robustly
 // Helper function to filter out TO_REPLY preset if conditions met
 async function filterToReplyPreset(
   potentialMatches: (RuleWithActionsAndCategories & { instructions: string })[],
   message: ParsedMessage,
   gmail: gmail_v1.Gmail,
 ): Promise<(RuleWithActionsAndCategories & { instructions: string })[]> {
+  // We filter out TO_REPLY preset rules when the user has received many emails
+  // from a sender but never replied. This indicates the user doesn't want
+  // to engage with this sender, so we shouldn't keep suggesting to reply.
+
   const toReplyRuleIndex = potentialMatches.findIndex(
     (r) => r.presetType === PresetType.TO_REPLY,
   );

   if (toReplyRuleIndex === -1) {
     return potentialMatches; // No TO_REPLY rule found
   }

+  // Extract sender email - in the future, consider using a more robust
+  // email extraction function that handles different formats
   const senderEmail = message.headers.from;
   if (!senderEmail) {
     return potentialMatches; // Cannot check history without sender email
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76c68a9 and 2227105.

📒 Files selected for processing (2)
  • apps/web/utils/ai/choose-rule/match-rules.ts (9 hunks)
  • apps/web/utils/parse/calender-event.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/utils/parse/calender-event.ts (1)
apps/web/utils/types.ts (1)
  • ParsedMessage (47-58)
🔇 Additional comments (4)
apps/web/utils/parse/calender-event.ts (1)

236-250: Great implementation of the ICS attachment detection.

The hasIcsAttachment function is well-implemented with good defensive coding. It properly checks if attachments exist before attempting to iterate through them, and uses optional chaining (?.) with toLowerCase() to handle potential undefined values safely.

apps/web/utils/ai/choose-rule/match-rules.ts (3)

57-74: Good implementation of calendar event preset matching.

The calendar event detection logic is well-implemented and gives priority to calendar event matching over other rules, which makes sense for this use case. The code properly logs matches for easier debugging.


179-185: Clean implementation of TO_REPLY preset filtering.

The updated return statement properly filters potential matches based on the sender's reply history before returning them. This is a clean implementation that maintains the existing structure while adding new functionality.


41-51:

Details

✅ Verification successful

Verify all callers of the updated functions.

The gmail parameter has been added to multiple function signatures. Ensure that all callers of these functions throughout the codebase have been updated to include this parameter.

Also applies to: 205-210, 218-223


🏁 Script executed:

#!/bin/bash
# Check for possible callers of these functions that might need updates

# Check for findMatchingRule usage
echo "Checking for findMatchingRule usage:"
rg -A 2 "findMatchingRule\(" --type=ts --type=js

# Check for findMatchingRuleWithReasons usage
echo "Checking for findMatchingRuleWithReasons usage:"
rg -A 2 "findMatchingRuleWithReasons\(" --type=ts --type=js

# Check for findPotentialMatchingRules usage
echo "Checking for findPotentialMatchingRules usage:"
rg -A 2 "findPotentialMatchingRules\(" --type=ts --type=js

Length of output: 5631


Call sites correctly include the new gmail parameter.
Verification confirms that all callers of the functions—namely findMatchingRule, findMatchingRuleWithReasons, and findPotentialMatchingRules—have been updated to pass the gmail parameter. Specifically, the updates in the following files have been verified:

  • apps/web/utils/ai/choose-rule/run-rules.ts
  • apps/web/utils/ai/choose-rule/match-rules.test.ts
  • apps/web/utils/ai/choose-rule/match-rules.ts

No additional changes are required.

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: 1

🔭 Outside diff range comments (3)
apps/web/utils/rule/rule.ts (3)

52-56: ⚠️ Potential issue

Missing systemType parameter in error recovery flow.

When recreating a rule due to a duplicate name error, the systemType parameter is not passed to createRule, which will cause the system type to be lost.

Apply this fix to ensure system type is preserved:

      const rule = await createRule({
        result: { ...result, name: `${result.name} - ${Date.now()}` },
        userId,
        categoryIds,
+       systemType,
      });

153-158: ⚠️ Potential issue

systemType parameter missing from updateRule function.

The updateRule function doesn't have a systemType parameter, and the function doesn't update the systemType field in the database. This means system types cannot be updated once set.

Consider adding systemType support to the updateRule function:

async function updateRule(
  ruleId: string,
  result: CreateOrUpdateRuleSchemaWithCategories,
  userId: string,
  categoryIds?: string[] | null,
+ systemType?: SystemType | null,
) {
  return prisma.rule.update({
    where: { id: ruleId },
    data: {
      name: result.name,
      userId,
+     systemType,
      // NOTE: this is safe for now as `Action` doesn't have relations
      // ...rest of the function

84-88: ⚠️ Potential issue

systemType not passed when creating a rule in safeUpdateRule error flow.

When handling a duplicate name error in safeUpdateRule, the systemType is not passed to createRule, which will result in the system type being lost.

This should be fixed by passing systemType to createRule:

      const rule = await createRule({
        result: { ...result, name: `${result.name} - ${Date.now()}` },
        userId,
        categoryIds,
+       systemType, // Need to pass systemType from parent function
      });

Note: This requires adding the systemType parameter to the safeUpdateRule function as well.

🧹 Nitpick comments (8)
apps/web/utils/ai/choose-rule/match-rules.ts (3)

35-36: Consider making TO_REPLY_RECEIVED_THRESHOLD configurable

While defining this as a constant is good practice, consider making this value configurable via environment variables or user settings to allow flexibility without code changes.

-const TO_REPLY_RECEIVED_THRESHOLD = 10;
+// Number of emails required before filtering out TO_REPLY preset rules
+const TO_REPLY_RECEIVED_THRESHOLD = Number(
+  process.env.TO_REPLY_RECEIVED_THRESHOLD || "10"
+);

319-365: Robust implementation with proper error handling

The filterToReplyPreset function is well-implemented with:

  1. Clear logic for identifying TO_REPLY rules
  2. Proper null checks for sender email
  3. Robust error handling that logs issues without breaking the main flow
  4. Informative logging of filtering decisions

One suggestion:

Consider adding a unit test specifically for this function to ensure the filtering logic works as expected with different combinations of reply history data.


344-355: Consider enhancing logging with more context

The logging is good, but consider adding additional context like the messageId to make troubleshooting easier.

      logger.info(
        "Filtering out TO_REPLY rule due to no prior reply and high received count",
        {
          ruleId: potentialMatches[toReplyRuleIndex].id,
          senderEmail,
          receivedCount,
+         messageId: message.id,
        },
      );
apps/web/app/(app)/automation/RuleForm.tsx (1)

978-982: Consider a more extensible approach for determining badge visibility.

The current implementation hardcodes specific system types that should show a badge. This may require frequent updates as more system types are added.

Consider using a more maintainable approach, such as:

-function showSystemTypeBadge(systemType?: SystemType | null): boolean {
-  if (systemType === SystemType.TO_REPLY) return true;
-  if (systemType === SystemType.CALENDAR) return true;
-  return false;
-}
+const SYSTEM_TYPES_WITH_BADGES = new Set([
+  SystemType.TO_REPLY,
+  SystemType.CALENDAR,
+]);
+
+function showSystemTypeBadge(systemType?: SystemType | null): boolean {
+  return !!systemType && SYSTEM_TYPES_WITH_BADGES.has(systemType);
+}
apps/web/utils/reply-tracker/enable.ts (4)

101-102: Parameters added to safeCreateRule function

The null parameter's purpose is not clear without additional context. Consider adding a comment to explain what this parameter represents for better code maintainability.

  const newRule = await safeCreateRule(
    {
      name: RuleName.ToReply,
      condition: {
        aiInstructions: defaultReplyTrackerInstructions,
      },
      actions: [
        {
          type: ActionType.LABEL,
          fields: {
            label: NEEDS_REPLY_LABEL_NAME,
            to: null,
            subject: null,
            content: null,
            cc: null,
            bcc: null,
            webhookUrl: null,
          },
        },
      ],
    },
    userId,
-    null,
+    null, // Optional parameter for rule options/metadata
    SystemType.TO_REPLY,
  );

105-108: Consider updating error message

The error message mentions "Reply Zero" which might be a legacy term if the functionality has been renamed to "Reply Tracker".

  if ("error" in newRule) {
-    logger.error("Error enabling Reply Zero", { error: newRule.error });
-    return { error: "Error enabling Reply Zero" };
+    logger.error("Error enabling Reply Tracker", { error: newRule.error });
+    return { error: "Error enabling Reply Tracker" };
  }

113-114: Consider updating error message

Same issue with "Reply Zero" naming.

-  logger.error("Error enabling Reply Zero, no rule found");
-  return { error: "Error enabling Reply Zero" };
+  logger.error("Error enabling Reply Tracker, no rule found");
+  return { error: "Error enabling Reply Tracker" };

129-130: Consider updating error message

Same issue with "Reply Zero" naming.

-  logger.error("Error enabling Reply Zero", { error: "No rule found" });
-  return { error: "Error enabling Reply Zero" };
+  logger.error("Error enabling Reply Tracker", { error: "No rule found" });
+  return { error: "Error enabling Reply Tracker" };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d69fb6d and 37af33f.

📒 Files selected for processing (12)
  • apps/web/app/(app)/automation/RuleForm.tsx (5 hunks)
  • apps/web/app/(app)/automation/onboarding/CategoriesSetup.tsx (1 hunks)
  • apps/web/app/(app)/automation/onboarding/page.tsx (5 hunks)
  • apps/web/prisma/migrations/20250414091625_rule_system_type/migration.sql (1 hunks)
  • apps/web/prisma/schema.prisma (2 hunks)
  • apps/web/utils/actions/rule.ts (13 hunks)
  • apps/web/utils/actions/rule.validation.ts (2 hunks)
  • apps/web/utils/ai/choose-rule/match-rules.ts (9 hunks)
  • apps/web/utils/ai/choose-rule/types.ts (2 hunks)
  • apps/web/utils/ai/reply/check-reply-tracking.ts (0 hunks)
  • apps/web/utils/reply-tracker/enable.ts (4 hunks)
  • apps/web/utils/rule/rule.ts (4 hunks)
💤 Files with no reviewable changes (1)
  • apps/web/utils/ai/reply/check-reply-tracking.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/web/app/(app)/automation/onboarding/CategoriesSetup.tsx
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/web/utils/actions/rule.validation.ts
  • apps/web/utils/ai/choose-rule/types.ts
  • apps/web/prisma/schema.prisma
  • apps/web/utils/actions/rule.ts
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/web/utils/rule/rule.ts (1)
apps/web/utils/ai/rule/create-rule-schema.ts (1)
  • CreateOrUpdateRuleSchemaWithCategories (128-131)
apps/web/app/(app)/automation/onboarding/page.tsx (1)
apps/web/utils/actions/rule.validation.ts (1)
  • CategoryAction (155-155)
🔇 Additional comments (24)
apps/web/utils/ai/choose-rule/match-rules.ts (5)

1-1: The new imports properly support system type integration

The added imports for Gmail API types, SystemType enum, calendar attachment detection, and sender reply history tracking align well with the PR objectives to extend rule matching functionality with system types.

Also applies to: 16-16, 30-31


41-51: Function parameter signature appropriately updated

The addition of the Gmail API parameter is necessary to support the new functionality for checking sender reply history and is consistently applied across related functions.


57-74: Well-implemented calendar event detection

The calendar event detection logic is well structured with appropriate logging. The implementation correctly identifies calendar events using the hasIcsAttachment function and returns a matching rule with the CALENDAR system type if found.


178-185: Function composition improves maintainability

Extracting the TO_REPLY filtering logic into a separate function improves code maintainability and follows the single responsibility principle.


339-342:

Details

✅ Verification successful

Verify the parameter order for checkSenderReplyHistory

Make sure the parameters for checkSenderReplyHistory are in the correct order. Double-check that the function expects the Gmail API instance first, then the sender email, and finally the threshold.


🏁 Script executed:

#!/bin/bash
# Check the parameter order for checkSenderReplyHistory function
rg -A 5 "function checkSenderReplyHistory" --glob="*.ts"

Length of output: 658


Parameter Order Verified: No Changes Needed

After verifying, the parameter order for checkSenderReplyHistory is confirmed as follows:

  • gmail (Gmail API instance)
  • senderEmail (sender email address)
  • TO_REPLY_RECEIVED_THRESHOLD (reply received threshold)

The code in apps/web/utils/ai/choose-rule/match-rules.ts at lines 339-342 correctly aligns with the function definition in apps/web/utils/reply-tracker/check-sender-reply-history.ts.

apps/web/prisma/migrations/20250414091625_rule_system_type/migration.sql (2)

4-4: Be aware of potential migration failure due to duplicates.

This migration adds a unique constraint on [userId,systemType]. If there are existing duplicate values in your database, this migration will fail. Make sure to clean up any duplicate data before running this in production.


8-8: LGTM: Well-structured enum creation.

The SystemType enum values cover a comprehensive set of system-defined rule categories, allowing for specialized rule handling based on their type.

apps/web/app/(app)/automation/RuleForm.tsx (4)

34-34: LGTM: Proper import and type updates.

The addition of SystemType import and update to use CoreConditionType aligns with the system types feature implementation.

Also applies to: 36-36


199-200: Type update for better type safety.

Changing from Exclude<ConditionType, "GROUP"> to CoreConditionType improves type safety and consistency with type definitions across the application.


269-275: Good feature: Conditional rendering of a badge for special preset rules.

The added UI component clearly informs users when a rule has special preset logic that may impact conditions.


814-817: Improved description clarity for reply tracking.

The updated description more clearly explains the purpose of the reply tracking action and its relationship with the NEEDS_REPLY_LABEL_NAME label.

apps/web/app/(app)/automation/onboarding/page.tsx (5)

5-10: LGTM: Updated imports to include SystemType.

Proper import of the new SystemType enum from @prisma/client.


30-30: LGTM: Updated UserPreferences type to use systemType.

Changed from selecting name to systemType in the rules object, aligning with the database schema changes.


46-46: LGTM: Updated getUserPreferences to select systemType.

This change ensures that the systemType field is retrieved from the database when getting user preferences.


62-66: LGTM: Updated preference functions to use SystemType enum constants.

Using SystemType enum constants provides better type safety than string literals.


81-85: LGTM: Updated getRuleSetting to use SystemType.

Modified the function parameter from name: string to systemType: SystemType and updated the lookup logic to match rules based on systemType.

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

4-9: LGTM: Updated imports to include SystemType.

Proper import of the SystemType enum from @prisma/client.


34-34: LGTM: Added systemType parameter to safeCreateRule.

This change allows passing the system type when creating a rule.

Also applies to: 46-46


108-108: LGTM: Added systemType to createRule function and data object.

This properly adds the systemType field to the rule creation process.

Also applies to: 113-113, 121-121

apps/web/utils/reply-tracker/enable.ts (5)

3-3: Import statement updated to include SystemType

The import statement has been correctly updated to include SystemType from @prisma/client, which is necessary for the new system type filtering logic.


33-35: Query updated to filter by SystemType

The query has been updated to filter rules based on systemType which is more explicit and type-safe than the previous approach.


38-38: SystemType added to select statement

Adding systemType to the select statement ensures this field is available for processing rules.


53-53: Updated rule finding logic

The logic to find a rule has been updated to use the systemType field, which aligns with the query changes above.


11-144: Overall changes look good

The changes to use SystemType.TO_REPLY for rule identification provide a more structured and type-safe approach than the previous implementation. This aligns well with the PR objective of introducing presets functionality.

Consider verifying that all error messages consistently use the current feature name throughout the codebase for better user experience.

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: 0

🧹 Nitpick comments (1)
apps/web/app/(app)/automation/examples.ts (1)

74-74: Fix the grammatical error in this line.

There's redundant wording in "draft a reply a polite reply". Consider changing to either "draft a polite reply" or "draft a reply with a polite tone".

-* Label media inquiries as "Press" and draft a reply a polite reply.`,
+* Label media inquiries as "Press" and draft a polite reply.`,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37af33f and 7057cf1.

📒 Files selected for processing (1)
  • apps/web/app/(app)/automation/examples.ts (4 hunks)
🔇 Additional comments (4)
apps/web/app/(app)/automation/examples.ts (4)

20-24: LGTM! The removal of marketing and newsletter labels aligns with PR objectives.

I notice the common prompts array has been streamlined, with marketing, newsletter, and receipt labeling prompts removed (as mentioned in the AI summary). This aligns with the PR's introduction of system types for categorization.


53-53: LGTM! The updated founder prompt is concise and relevant.

The founder prompt now concludes with recruitment-related labeling, while the previously mentioned marketing, newsletter, and receipt labels have been removed (as per the AI summary).


91-91: LGTM! The investor persona prompt has been updated appropriately.

The marketing-related labels have been removed as mentioned in the AI summary, and the prompt now concludes with a speaking opportunity categorization.


193-193: LGTM! The student prompt has been streamlined.

As noted in the AI summary, the marketing and newsletter labeling instructions have been removed from the student persona prompt, which aligns with the PR's approach to handling these categorizations differently.

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: 0

🧹 Nitpick comments (2)
apps/web/utils/ai/choose-rule/match-rules.ts (2)

35-35: Consider configuring the threshold.

The TO_REPLY_RECEIVED_THRESHOLD = 10 might be better pulled from a configuration or environment variable to make it more flexible.

-const TO_REPLY_RECEIVED_THRESHOLD = 10;
+const TO_REPLY_RECEIVED_THRESHOLD = parseInt(process.env.TO_REPLY_RECEIVED_THRESHOLD ?? "10", 10);

320-367: Handle potential multiple TO_REPLY rules.

Currently, filterToReplyPreset only filters out the first matching rule for SystemType.TO_REPLY. If there can be multiple TO_REPLY rules, consider filtering them all:

-const toReplyRuleIndex = potentialMatches.findIndex(
-  (r) => r.systemType === SystemType.TO_REPLY,
-);
...
-if (toReplyRuleIndex === -1) {
-  return potentialMatches;
-}
...
-return potentialMatches.filter((_, index) => index !== toReplyRuleIndex);
+const filteredMatches = potentialMatches.filter(
+  (r) => r.systemType !== SystemType.TO_REPLY
+);
...
+// If no prior reply and threshold reached, remove all TO_REPLY rules:
+return filteredMatches;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7057cf1 and db0a5c6.

📒 Files selected for processing (1)
  • apps/web/utils/ai/choose-rule/match-rules.ts (10 hunks)
🔇 Additional comments (5)
apps/web/utils/ai/choose-rule/match-rules.ts (5)

1-1: New imports look correct.

The newly introduced imports, including gmail_v1, SystemType, and others from @prisma/client, seem consistent with the usage throughout the file.

Also applies to: 12-17


56-74: Verify early return logic for calendar events.

Returning immediately upon finding a CALENDAR rule prevents any other rules from being considered. Ensure that only one rule is expected to match in this flow.


178-184: Appropriate filtering approach for TO_REPLY.

Integrating the filterToReplyPreset call before returning potential matches is a solid way to handle the new logic for TO_REPLY system types without cluttering this function further.


200-201: Log message for system preset detection is aligned.

The 'Matched a system preset' return string correctly identifies the PRESET condition type.


211-213:

Details

✅ Verification successful

Method signatures updated seamlessly.

All additions of the gmail parameter appear appropriate. Confirm that all upstream calling sites pass the correct gmail object.

Also applies to: 224-225, 236-237


🏁 Script executed:

#!/bin/bash
# Verify that all invocations of `findMatchingRule` and `findMatchingRuleWithReasons` pass the `gmail` argument
rg -A 2 "findMatchingRule\(" 
rg -A 2 "findMatchingRuleWithReasons\(" 

Length of output: 4835


All invoking sites now pass the correct gmail argument

The verification confirms that every call to both findMatchingRule and findMatchingRuleWithReasons—including those in apps/web/utils/ai/choose-rule/match-rules.test.ts and apps/web/utils/ai/choose-rule/run-rules.ts—consistently supplies the gmail parameter. The method signature updates are hence seamlessly integrated.

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: 0

🧹 Nitpick comments (1)
apps/web/prisma/migrations/20250414103126_migrate_system_rule_types/migration.sql (1)

1-6: Ensure Atomicity and Enum Consistency.

All six update statements correctly update the "systemType" field with standardized uppercase enum values corresponding to the rule names. This adheres to the new enum definitions you have in your Prisma schema. Please verify that these values — 'TO_REPLY', 'NEWSLETTER', 'MARKETING', 'CALENDAR', 'RECEIPT', and 'NOTIFICATION' — exactly match the enums defined in your application.

Additionally, if your migration system does not automatically wrap migration files in a transaction, consider manually wrapping these statements in a transaction (using BEGIN; and COMMIT;) to ensure atomicity during the migration process.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db0a5c6 and bcfd5c7.

📒 Files selected for processing (1)
  • apps/web/prisma/migrations/20250414103126_migrate_system_rule_types/migration.sql (1 hunks)

@elie222 elie222 merged commit 412e1a8 into main Apr 14, 2025
4 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 14, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 10, 2025
@elie222 elie222 deleted the preset-checks branch December 18, 2025 23:08
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.

1 participant