Skip to content

Comments

Fix ai diff and upgrade openrouter#661

Merged
elie222 merged 1 commit intomainfrom
feat/fix-ai-diff
Aug 7, 2025
Merged

Fix ai diff and upgrade openrouter#661
elie222 merged 1 commit intomainfrom
feat/fix-ai-diff

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Aug 7, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced AI rule difference detection to provide stricter JSON output and clearer rule formatting.
  • Bug Fixes
    • Improved test coverage for AI rule diffing, including added and removed rules with consistent formatting.
  • Chores
    • Updated dependency for AI SDK provider to a newer version.
    • Introduced a linter warning for console statements, with exceptions for specific files.
    • Standardized log length handling in AI-related utilities for consistency.

@vercel
Copy link

vercel bot commented Aug 7, 2025

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

Name Status Preview Updated (UTC)
inbox-zero 🔄 Building (Inspect) Visit Preview Aug 7, 2025 10:55am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

Walkthrough

This set of changes updates the AI-driven rule diff logic to use a schema-driven object generation approach, enhances prompt instructions, and modifies related tests to match new output formatting. It also bumps an AI SDK dependency, introduces a logging constant, and adds a linter rule to warn on console usage, with exceptions for specific files.

Changes

Cohort / File(s) Change Summary
AI Rule Diff Refactor
apps/web/utils/ai/rule/diff-rules.ts
Switched from tool-based text generation to schema-driven object generation for AI rule diffing, inlined schema, enforced strict JSON output, updated prompt, and changed result extraction logic.
Test Update for Rule Diff
apps/web/__tests__/ai-diff-rules.test.ts
Updated test expectations to include leading asterisks in rule strings, added assertions for removed rules, and updated test command instructions.
AI SDK Dependency Bump
apps/web/package.json
Upgraded @openrouter/ai-sdk-provider from version 1.0.0-beta.6 to 1.1.0.
Logging Constant Introduction
apps/web/utils/llms/index.ts
Replaced hardcoded log string slice length with a named constant MAX_LOG_LENGTH (value: 200).
Linter Rule Addition
biome.json
Added a global warning rule for console usage, with overrides to disable it for specified test and script files.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant aiDiffRules
    participant AI_Model

    User->>aiDiffRules: Call with emailAccount, oldPromptFile, newPromptFile
    aiDiffRules->>AI_Model: Send prompt with inline schema and strict JSON instructions
    AI_Model-->>aiDiffRules: Return structured JSON diff object
    aiDiffRules-->>User: Return parsed diff object (addedRules, editedRules, removedRules)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

  • AI fixes for AI SDK v5 #656: Refactored the aiDiffRules function to use schema-driven object generation with inline schema definitions and stricter JSON output, directly related to the changes here.

Poem

A schema here, a schema there,
JSON rules floating in the air!
Linter warns of console logs,
While tests now check for leading frogs—
(Asterisks, I mean, with flair).
Version bumped, the code feels neat,
This rabbit’s work is now complete! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 52657f0 and c3a8dd8.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • apps/web/__tests__/ai-diff-rules.test.ts (2 hunks)
  • apps/web/package.json (1 hunks)
  • apps/web/utils/ai/rule/diff-rules.ts (3 hunks)
  • apps/web/utils/llms/index.ts (3 hunks)
  • biome.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (17)
!{.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:

  • apps/web/package.json
  • apps/web/utils/llms/index.ts
  • biome.json
  • apps/web/__tests__/ai-diff-rules.test.ts
  • apps/web/utils/ai/rule/diff-rules.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:

  • apps/web/package.json
  • apps/web/utils/llms/index.ts
  • biome.json
  • apps/web/__tests__/ai-diff-rules.test.ts
  • apps/web/utils/ai/rule/diff-rules.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/utils/llms/index.ts
  • apps/web/__tests__/ai-diff-rules.test.ts
  • apps/web/utils/ai/rule/diff-rules.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/utils/llms/index.ts
  • apps/web/__tests__/ai-diff-rules.test.ts
  • apps/web/utils/ai/rule/diff-rules.ts
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/llms/index.ts
  • apps/web/utils/ai/rule/diff-rules.ts
apps/web/utils/llms/index.ts

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

The core LLM functionality must be implemented in utils/llms/index.ts.

Files:

  • apps/web/utils/llms/index.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/llms/index.ts
  • apps/web/utils/ai/rule/diff-rules.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/utils/llms/index.ts
  • apps/web/__tests__/ai-diff-rules.test.ts
  • apps/web/utils/ai/rule/diff-rules.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/llms/index.ts
  • apps/web/utils/ai/rule/diff-rules.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/llms/index.ts
  • apps/web/utils/ai/rule/diff-rules.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/utils/llms/index.ts
  • apps/web/__tests__/ai-diff-rules.test.ts
  • apps/web/utils/ai/rule/diff-rules.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-diff-rules.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-diff-rules.test.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-diff-rules.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-diff-rules.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-diff-rules.test.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-diff-rules.test.ts
🧠 Learnings (45)
📓 Common learnings
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.272Z
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.272Z
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.272Z
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.272Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Keep system prompts and user prompts separate 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.272Z
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.272Z
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-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.570Z
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.272Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : System prompt should define the LLM's role and task specifications.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.272Z
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.272Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Include relevant context in log messages for LLM-related code.
📚 Learning: applies to **/*.{jsx,tsx} : make sure all dependencies are correctly specified in react hooks....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{jsx,tsx} : Make sure all dependencies are correctly specified in React hooks.

Applied to files:

  • apps/web/package.json
📚 Learning: in this project, prisma should be imported using 'import prisma from "@/utils/prisma";' in typescrip...
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.

Applied to files:

  • apps/web/package.json
📚 Learning: applies to components/**/*.tsx : use `next/image` package for images...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-07-19T17:50:22.078Z
Learning: Applies to components/**/*.tsx : Use `next/image` package for images

Applied to files:

  • apps/web/package.json
📚 Learning: applies to {components,app}/**/*.tsx : for api get requests to server use the `swr` package...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ui-components.mdc:0-0
Timestamp: 2025-07-19T17:50:22.078Z
Learning: Applies to {components,app}/**/*.tsx : For API get requests to server use the `swr` package

Applied to files:

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

Applied to files:

  • apps/web/utils/llms/index.ts
📚 Learning: applies to apps/web/utils/{ai,llms}/**/*.ts : remove excessive whitespace and truncate long inputs i...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.272Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Remove excessive whitespace and truncate long inputs in LLM prompts.

Applied to files:

  • apps/web/utils/llms/index.ts
📚 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.272Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use proper error types and logging in LLM-related code.

Applied to files:

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

Applied to files:

  • apps/web/utils/llms/index.ts
📚 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.272Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use descriptive scoped loggers for each LLM feature.

Applied to files:

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

Applied to files:

  • apps/web/utils/llms/index.ts
  • apps/web/utils/ai/rule/diff-rules.ts
📚 Learning: applies to apps/web/utils/{ai,llms}/**/*.ts : follow the standard structure for llm-related function...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.272Z
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.

Applied to files:

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

Applied to files:

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

Applied to files:

  • apps/web/utils/llms/index.ts
  • apps/web/__tests__/ai-diff-rules.test.ts
  • apps/web/utils/ai/rule/diff-rules.ts
📚 Learning: applies to apps/web/utils/{ai,llms}/**/*.ts : use typescript types for all parameters and return val...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.272Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use TypeScript types for all parameters and return values in LLM-related code.

Applied to files:

  • apps/web/utils/llms/index.ts
  • apps/web/__tests__/ai-diff-rules.test.ts
📚 Learning: applies to **/*.{ts,tsx} : typically add the logger initialization at the top of the file when using...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/logging.mdc:0-0
Timestamp: 2025-07-18T15:06:47.625Z
Learning: Applies to **/*.{ts,tsx} : Typically add the logger initialization at the top of the file when using `createScopedLogger`

Applied to files:

  • apps/web/utils/llms/index.ts
📚 Learning: applies to **/*.{ts,tsx} : use `createscopedlogger` for logging in backend typescript files...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/logging.mdc:0-0
Timestamp: 2025-07-18T15:06:47.625Z
Learning: Applies to **/*.{ts,tsx} : Use `createScopedLogger` for logging in backend TypeScript files

Applied to files:

  • apps/web/utils/llms/index.ts
📚 Learning: applies to **/*.{ts,tsx} : only use `.with()` on a logger instance within a specific function, not f...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/logging.mdc:0-0
Timestamp: 2025-07-18T15:06:47.625Z
Learning: Applies to **/*.{ts,tsx} : Only use `.with()` on a logger instance within a specific function, not for a global logger

Applied to files:

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

Applied to files:

  • apps/web/utils/llms/index.ts
📚 Learning: applies to apps/web/utils/{ai,llms}/**/*.ts : system prompt should define the llm's role and task sp...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.272Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : System prompt should define the LLM's role and task specifications.

Applied to files:

  • apps/web/utils/llms/index.ts
  • apps/web/utils/ai/rule/diff-rules.ts
📚 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.272Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : User prompt should contain the actual data and context.

Applied to files:

  • apps/web/utils/llms/index.ts
  • apps/web/utils/ai/rule/diff-rules.ts
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : don't use console....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't use console.

Applied to files:

  • biome.json
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : don't rename imports, exports, and destructured assignments to the...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't rename imports, exports, and destructured assignments to the same name.

Applied to files:

  • biome.json
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : don't reassign const variables....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't reassign const variables.

Applied to files:

  • biome.json
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : don't export empty modules that don't change anything....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't export empty modules that don't change anything.

Applied to files:

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

Applied to files:

  • biome.json
  • apps/web/__tests__/ai-diff-rules.test.ts
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : don't use unsafe negation....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't use unsafe negation.

Applied to files:

  • biome.json
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : don't have redundant "use strict"....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't have redundant "use strict".

Applied to files:

  • biome.json
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : don't use constant expressions in conditions....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't use constant expressions in conditions.

Applied to files:

  • biome.json
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : don't use unnecessary nested block statements....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't use unnecessary nested block statements.

Applied to files:

  • biome.json
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : don't use empty block statements and static blocks....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't use empty block statements and static blocks.

Applied to files:

  • biome.json
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : make sure to use the "use strict" directive in script files....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Make sure to use the "use strict" directive in script files.

Applied to files:

  • biome.json
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : don't use debugger....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't use debugger.

Applied to files:

  • biome.json
📚 Learning: applies to **/*.{js,jsx,ts,tsx} : don't use with statements in non-strict contexts....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Don't use with statements in non-strict contexts.

Applied to files:

  • biome.json
📚 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.570Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Test both AI and non-AI paths in LLM-related tests

Applied to files:

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

Applied to files:

  • apps/web/__tests__/ai-diff-rules.test.ts
  • apps/web/utils/ai/rule/diff-rules.ts
📚 Learning: run ai tests with: pnpm test-ai your-feature...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.570Z
Learning: Run AI tests with: pnpm test-ai your-feature

Applied to files:

  • apps/web/__tests__/ai-diff-rules.test.ts
📚 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.318Z
Learning: Applies to **/*.{test,spec}.{js,jsx,ts,tsx} : Don't use disabled tests.

Applied to files:

  • apps/web/__tests__/ai-diff-rules.test.ts
📚 Learning: applies to apps/web/__tests__/**/*.test.ts : include standard test cases: happy path, error handling...
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-07-18T15:06:10.570Z
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

Applied to files:

  • apps/web/__tests__/ai-diff-rules.test.ts
📚 Learning: applies to **/*.{test,spec}.{js,jsx,ts,tsx} : don't use export or module.exports in test files....
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/ultracite.mdc:0-0
Timestamp: 2025-07-20T09:03:06.318Z
Learning: Applies to **/*.{test,spec}.{js,jsx,ts,tsx} : Don't use export or module.exports in test files.

Applied to files:

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

Applied to files:

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

Applied to files:

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

Applied to files:

  • apps/web/utils/ai/rule/diff-rules.ts
📚 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/llm.mdc:0-0
Timestamp: 2025-07-18T15:06:40.272Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.ts : Use XML-like tags to structure data in LLM prompts.

Applied to files:

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

Applied to files:

  • apps/web/utils/ai/rule/diff-rules.ts
⏰ 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). (3)
  • GitHub Check: Secret Detection
  • GitHub Check: Jit Security
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (12)
apps/web/package.json (1)

43-43: LGTM! Appropriate upgrade from beta to stable.

The upgrade from 1.0.0-beta.6 to 1.1.0 moves from beta to a stable release, which aligns well with the refactoring to use createGenerateObject in the AI utilities.

apps/web/utils/llms/index.ts (3)

35-35: LGTM! Good practice introducing a named constant.

Replacing the magic number 200 with MAX_LOG_LENGTH improves code maintainability and readability.


58-60: LGTM! Consistent use of the new constant.

The logging calls now use MAX_LOG_LENGTH consistently, making the truncation behavior configurable and eliminating magic numbers.


133-135: LGTM! Consistent application across functions.

Both createGenerateText and createGenerateObject now use the same MAX_LOG_LENGTH constant for consistent logging behavior.

biome.json (1)

24-24: LGTM! Good enforcement of console usage guidelines.

Adding "noConsole": "warn" enforces the coding guideline against console usage while allowing it in appropriate contexts (tests, scripts) through the overrides section.

apps/web/__tests__/ai-diff-rules.test.ts (2)

5-5: LGTM! Helpful clarification for running AI tests.

The updated comment clearly shows that RUN_AI_TESTS=true is required to run these tests, which is helpful for developers.


36-44: LGTM! Test expectations updated to match new output format.

The test expectations correctly reflect the new output format with:

  • Leading asterisks in rule strings
  • Updated addedRules, editedRules, and removedRules arrays
  • Proper structure matching the schema-driven approach
apps/web/utils/ai/rule/diff-rules.ts (5)

5-5: LGTM! Appropriate import change for the refactoring.

Switching from createGenerateText to createGenerateObject aligns with the schema-driven approach implemented in this function.


44-58: LGTM! Excellent enhancement with explicit JSON formatting.

The added instructions with a concrete JSON example help guide the LLM to produce consistent, structured output. This follows the best practice of making schemas as specific as possible to guide LLM output.


62-66: LGTM! Proper use of createGenerateObject with descriptive labeling.

The function follows the standard LLM structure with proper scoped labeling ("Diff rules") for tracking and debugging purposes.


72-87: LGTM! Excellent schema-driven approach with detailed descriptions.

The inline schema definition is well-structured with:

  • Descriptive schemaName and schemaDescription
  • Specific field descriptions for each property
  • Proper Zod typing for arrays and objects
  • Clear separation of concerns (added, edited, removed rules)

This follows the retrieved learning about making Zod schemas as specific as possible to guide LLM output.


89-89: LGTM! Clean return of structured object.

Returning result.object directly is the correct approach for the createGenerateObject pattern, replacing the previous tool-based extraction.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/fix-ai-diff

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests 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.

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.

@claude
Copy link

claude bot commented Aug 7, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

@socket-security
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedhusky@​9.1.71001005979100
Addedencoding@​0.1.131001007876100
Addedfast-deep-equal@​3.1.31001009976100
Addedclsx@​2.1.11001009576100
Addedhe@​1.2.010010010079100
Addedjson5@​2.2.310010010079100
Addeddate-fns@​4.1.01001009180100
Addedlodash@​4.17.211001008680100
Addedpostcss@​8.5.4991008188100
Addedtypescript@​5.8.310010089100100
Addedjiti@​2.4.29810010090100
Updated@​openrouter/​ai-sdk-provider@​1.0.0-beta.6 ⏵ 1.1.0100 +1100100 +198 +1100

View full report

@elie222 elie222 merged commit 4194483 into main Aug 7, 2025
11 of 14 checks passed
@elie222 elie222 deleted the feat/fix-ai-diff branch August 7, 2025 10:58
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