Skip to content

Improve choose rule prompt#375

Merged
elie222 merged 6 commits intomainfrom
improve-choose-rule-prompt
Mar 20, 2025
Merged

Improve choose rule prompt#375
elie222 merged 6 commits intomainfrom
improve-choose-rule-prompt

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Mar 20, 2025

Summary by CodeRabbit

  • New Features

    • Email messages now include a unique identifier, improving tracking and reference.
    • AI responses are now built using a clearer, structured set of instructions for enhanced consistency.
  • Bug Fixes

    • Adjusted email object structures to ensure consistent handling of identifiers across various functions.
  • Refactor

    • Underlying logic for processing emails and applying rules has been refined for increased robustness.
    • Enhanced error handling for date properties in email messages to prevent potential runtime errors.

@vercel
Copy link

vercel bot commented Mar 20, 2025

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

Name Status Preview Updated (UTC)
inbox-zero ✅ Ready (Inspect) Visit Preview Mar 20, 2025 8:13pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request adds an id property to email objects across multiple modules. In test files and utility functions, the returned email object now includes an id field, and the corresponding type definition has been updated. Additionally, the AI response flow in the choose-rule module has been modified to integrate a new dependency, Braintrust, and to structure rule instructions within defined tags, updating the prompt construction and logging accordingly.

Changes

Files Change Summary
apps/web/__tests__/ai-choose-rule.test.ts, apps/web/utils/get-email-from-message.ts, apps/web/utils/types.ts Added an id property to email objects and updated the EmailForLLM type definition to include id for identification.
apps/web/utils/ai/choose-rule/ai-choose-rule.ts Integrated the Braintrust class, restructured the AI prompt with tagged instructions, recalculated rule numbering, and updated logging to reflect the new data structure.
apps/web/utils/actions/ai-rule.ts Added an id property to email objects in generateRulesPromptAction and reportAiMistakeAction functions for improved data structure consistency.
apps/web/utils/ai/reply/generate-nudge.ts, apps/web/utils/ai/reply/generate-reply.ts Updated parameter types in aiGenerateNudge and aiGenerateReply functions to use EmailForLLM for greater flexibility and improved error handling for the date field.
apps/web/app/api/google/webhook/process-history-item.test.ts Modified the test setup for processHistoryItem to mock a single message object instead of a thread, changing the structure of the headers property.
apps/web/app/api/google/webhook/process-history-item.ts Updated the parameter name for messageId to id: messageId in the call to runColdEmailBlocker, aligning with the new naming convention.
apps/web/utils/actions/cold-email.ts Changed the parameter passed to isColdEmail to use id instead of messageId, providing a default value of an empty string if body.messageId is falsy.
apps/web/utils/cold-email/is-cold-email.ts Updated multiple function signatures to use EmailForLLM, replacing messageId with id across various contexts for consistency.

Possibly related PRs

Poem

I'm a little rabbit, coding on the run,
Hopping through changes, adding fun under the sun.
With a brand new id in every email byte,
And Braintrust guiding rules just right.
I leap with joy as clean code takes flight.
🐰✨

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/app/api/google/webhook/process-history-item.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser '@typescript-eslint/parser' declared in 'apps/web/.eslintrc.json': Cannot find module '@typescript-eslint/parser'
Require stack:

  • /apps/web/.eslintrc.json
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)
apps/web/utils/cold-email/is-cold-email.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser '@typescript-eslint/parser' declared in 'apps/web/.eslintrc.json': Cannot find module '@typescript-eslint/parser'
Require stack:

  • /apps/web/.eslintrc.json
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)
apps/web/utils/actions/cold-email.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser '@typescript-eslint/parser' declared in 'apps/web/.eslintrc.json': Cannot find module '@typescript-eslint/parser'
Require stack:

  • /apps/web/.eslintrc.json
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)

📜 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 44069f5 and a0ae409.

📒 Files selected for processing (3)
  • apps/web/app/api/google/webhook/process-history-item.ts (1 hunks)
  • apps/web/utils/actions/cold-email.ts (1 hunks)
  • apps/web/utils/cold-email/is-cold-email.ts (9 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

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

🧹 Nitpick comments (1)
apps/web/app/api/google/webhook/process-history-item.test.ts (1)

167-179: Proper implementation of Gmail API message structure.

The changes to the mock implementation correctly represent the Gmail API message structure with headers as an array of objects containing name and value fields, which aligns with the actual Gmail API response format. This makes the test more accurate and reliable.

However, there might be a potential inconsistency with other tests in the file (like lines 153-159) that still expect headers as an object with direct properties. Ensure that all tests are updated consistently to handle the new header structure.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8d20d58 and 5893206.

📒 Files selected for processing (1)
  • apps/web/app/api/google/webhook/process-history-item.test.ts (1 hunks)

@elie222 elie222 merged commit 50bdf1a into main Mar 20, 2025
1 of 4 checks passed
@elie222 elie222 deleted the improve-choose-rule-prompt branch December 18, 2025 23:07
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

Comments