Repository navigation
Add calendar awareness to Pulse summaries - #483
Conversation
Pulse now includes calendar event data when generating AI summaries, enabling time-sensitive observations like upcoming meetings, events in progress, and pending RSVP invitations. Changes: - Query calendarEvents and eventAttendees in both on-demand and cron generation routes to fetch events happening now, upcoming today, and tomorrow - Include pending RSVP invitations as context for gentle nudges - Add calendar section to AI context data with categorized events - Update system prompt with calendar awareness message type examples - Add calendar stats (upcomingToday, pendingInvites) to GET /api/pulse response for real-time stat display - Update PulseResponse type to include calendar stats https://claude.ai/code/session_01X2zYjFPfB2Ha2k6HRYb2FT
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughAdds calendar awareness to Pulse: new calendar-context module, system prompt extraction, calendar queries and counts, and integration of categorized calendar events into cron, on-demand generation, response payloads, and the pulse summary schema. Changes
Sequence Diagram(s)sequenceDiagram
participant Cron as Cron Job
participant Generate as Generate API
participant Calendar as fetchCalendarContext
participant DB as Database
participant AI as AI Model
participant Store as Pulse Store
Cron->>DB: load users / drives
Cron->>Calendar: fetchCalendarContext(userId, driveIds, now, endOfTomorrow)
Calendar->>DB: query calendar_events & event_attendees
DB-->>Calendar: return categorized events & invites
Cron->>AI: send context + PULSE_SYSTEM_PROMPT + calendar section
AI-->>Cron: generated pulse summary
Cron->>Store: persist pulse summary (contextData includes calendar)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In `@apps/web/src/app/api/pulse/cron/route.ts`:
- Around line 660-768: The calendar logic (calendarVisibility,
upcomingCalendarEvents, attendeeEventRows, pendingRsvps, merge/dedup, sorting,
and categorization) is duplicated and also ignores per-drive visibility
(PRIVATE) for non-creators; extract these into a shared helper (e.g.,
fetchCalendarContext(userId, driveIds, now, endOfToday, endOfTomorrow)) that
returns merged, deduped, sorted events plus pending RSVPs, then replace the
duplicated blocks in both cron/route.ts and generate/route.ts with calls to that
helper; while extracting, update the calendarVisibility construction used by
upcomingCalendarEvents and attendeeEventRows to explicitly exclude
calendarEvents with visibility = 'PRIVATE' unless eq(calendarEvents.createdById,
userId) or the driveId is in driveIds (i.e., only include drive events with
non-PRIVATE visibility or creator access), and ensure the helper accepts the
same parameters and enforces the same time bounds and limits used by
pendingRsvps.
- Line 32: The import symbol `lte` is unused in this module; remove `lte` from
the import list where it's declared (so the import statement no longer includes
`lte`) to eliminate the dead import and keep the file lint-clean—verify no other
references to `lte` (e.g., in functions or exports) exist before removing.
In `@apps/web/src/app/api/pulse/generate/route.ts`:
- Line 33: The import symbol `lte` is unused in the pulse generate route; remove
`lte` from the import list (the line that currently includes `lte`) so there are
no unused imports in the module and the linter stops flagging it.
In `@apps/web/src/app/api/pulse/route.ts`:
- Around line 172-203: The calendarVisibility logic currently uses driveIds to
include any event in those drives but ignores calendarEvents.visibility, leaking
PRIVATE/ATTENDEES_ONLY events; update the calendarVisibility construction so
that for the driveIds branch you only include drive-scoped events with
visibility = 'DRIVE' (or drive events the creator owns) and always exclude
calendarEvents with visibility = 'PRIVATE' unless eq(calendarEvents.createdById,
userId); additionally ensure ATTENDEES_ONLY events are not exposed via this
visibility filter (they should be returned only via attendeeEventRows or
eventAttendees joins) — update the calendarVisibility variable and the analogous
logic in the cron/generate handlers to combine checks on
calendarEvents.visibility, calendarEvents.createdById, driveIds, and membership
(via eventAttendees) so PRIVATE is creator-only and ATTENDEES_ONLY is limited to
creator and attendees.
🧹 Nitpick comments (1)
apps/web/src/app/api/pulse/generate/route.ts (1)
97-100: System prompt is duplicated across cron and generate routes.Both
PULSE_SYSTEM_PROMPTconstants are identical (including the new calendar awareness section). This is a pre-existing concern amplified by the calendar additions — any future prompt tweak must be applied in two places. Consider extracting the prompt to a shared module (e.g.,@/lib/ai/pulse-prompt.ts).
…lication - Remove unused `lte` imports from cron and generate routes (fixes lint/CI) - Add `calendar` property to contextData schema type (fixes TS2769 build error) - Extract shared `fetchCalendarContext` helper with visibility fix that excludes PRIVATE/ATTENDEES_ONLY events from other users in shared drives - Apply same visibility fix to stats route (pulse/route.ts) - Extract shared `PULSE_SYSTEM_PROMPT` to eliminate duplication across routes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pulse now includes calendar event data when generating AI summaries,
enabling time-sensitive observations like upcoming meetings, events
in progress, and pending RSVP invitations.
Changes:
generation routes to fetch events happening now, upcoming today,
and tomorrow
response for real-time stat display
https://claude.ai/code/session_01X2zYjFPfB2Ha2k6HRYb2FT
Summary by CodeRabbit