Skip to content

feat(enterprise) send and manage org recommendations email#4219

Open
St0rmz1 wants to merge 5 commits into
mainfrom
feat/org-email-preferences-adoption-digest
Open

feat(enterprise) send and manage org recommendations email#4219
St0rmz1 wants to merge 5 commits into
mainfrom
feat/org-email-preferences-adoption-digest

Conversation

@St0rmz1

@St0rmz1 St0rmz1 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a weekly recommendations email for Enterprise organizations and the controls to manage it. Organization owners can turn the email on or off from a new Email preferences section on the organization page. When it is on, a weekly cron emails the organization's owners a short summary of how many features are set up and the top open recommendations, linking back to the Feature adoption view.

  • New recommendations_digest_enabled flag in the organization settings JSONB (schema-types.ts). No new table is added.
  • New owner-only, Enterprise-gated updateRecommendationsDigest tRPC mutation that toggles the flag, plus the useUpdateRecommendationsDigest hook. The toggle writes a single JSONB key with jsonb_set (or removes it) instead of rewriting the whole settings object.
  • New Email preferences card on the organization dashboard (owner-only) with two rows: the existing low balance alerts (which still opens its configuration modal) and the new weekly recommendations email (an on/off toggle).
  • Send path: a recommendationsDigest.html template and a sendRecommendationsDigestEmail helper in email.ts, a recommendations-digest.ts library that builds each org's payload from getOrganizationRecommendations, resolves the owner recipients, and sends, and an enterprise-recommendations-digest cron registered in vercel.json to run Mondays at 09:00 UTC.
  • Orgs with no open recommendations are skipped (no "all good" email). Before each send, a per recipient, per week marker is claimed in transactional_email_log so cron overlap or retries do not produce duplicates. The claim is released if the send fails so a later run can retry.
  • The dispatch query filters opted-in orgs in SQL (settings ->> 'recommendations_digest_enabled' = 'true') rather than loading every Enterprise org.
  • Admin preview: a fixture for the new template in email-testing-router.ts so it renders on the admin email testing page, plus a row in emails/AGENTS.md.
  • Tests for the toggle mutation, the digest builder, owner recipient resolution, and the duplicate-claim and retry behavior.

Verification

  • As an owner of an Enterprise org, toggle the weekly recommendations email on and off and confirm the setting persists.
  • Preview the "Kilo: Your weekly recommendations" template on the admin email testing page (/admin/email-testing).

Visual Changes

Two surfaces changed: the new Email preferences card on the organization page (owner-only), and the new recommendations email template. Screenshots to add:

Before After

Reviewer Notes

  • Recipients are the organization's owners, resolved at send time. There is no stored recipient list and no per recipient unsubscribe; owners turn the email off with the toggle.
  • Access: reads and the toggle are Enterprise only, and the toggle is owner only.
  • Idempotency reuses the existing transactional_email_log (no new table). The key is organizationId:userId:weekMonday, so it does not contain recipient email addresses. It is best effort: a send that succeeds at the provider but fails to record the marker would not be retried that week.

Comment thread apps/web/src/lib/organizations/recommendations-digest.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • apps/web/src/emails/AGENTS.md
  • apps/web/src/lib/organizations/organizations.ts
  • apps/web/src/lib/organizations/recommendations-digest.test.ts
  • apps/web/src/lib/organizations/recommendations-digest.ts
  • apps/web/src/routers/admin/email-testing-router.ts
  • apps/web/src/routers/organizations/organization-settings-router.ts
Previous Review Summary (commit d2f3879)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit d2f3879)

Status: 1 Issues Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/lib/organizations/recommendations-digest.ts 185 Opt-out gating reads from the replica, so a recent disable can still send one more digest.
Files Reviewed (15 files)
  • apps/web/src/app/api/cron/enterprise-recommendations-digest/route.ts - 0 issues
  • apps/web/src/app/api/organizations/hooks.ts - 0 issues
  • apps/web/src/components/organizations/OrganizationDashboard.tsx - 0 issues
  • apps/web/src/components/organizations/OrganizationEmailPreferencesCard.tsx - 0 issues
  • apps/web/src/emails/AGENTS.md - 0 issues
  • apps/web/src/emails/recommendationsDigest.html - 0 issues
  • apps/web/src/lib/email.ts - 0 issues
  • apps/web/src/lib/organizations/organizations.ts - 0 issues
  • apps/web/src/lib/organizations/recommendations-digest.test.ts - 0 issues
  • apps/web/src/lib/organizations/recommendations-digest.ts - 1 issue
  • apps/web/src/routers/admin/email-testing-router.ts - 0 issues
  • apps/web/src/routers/organizations/organization-settings-router.test.ts - 0 issues
  • apps/web/src/routers/organizations/organization-settings-router.ts - 0 issues
  • apps/web/vercel.json - 0 issues
  • packages/db/src/schema-types.ts - 0 issues

Reviewed by gpt-5.4-2026-03-05 · Input: 63.7K · Output: 9.7K · Cached: 343.8K

Review guidance: REVIEW.md from base branch main

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