Skip to content

[+] New feature: Added dynamic time-aware daily AI reflection prompts.#51

Merged
aryansoni-dev merged 1 commit into
mainfrom
dev
Jul 6, 2026
Merged

[+] New feature: Added dynamic time-aware daily AI reflection prompts.#51
aryansoni-dev merged 1 commit into
mainfrom
dev

Conversation

@aryansoni-dev

@aryansoni-dev aryansoni-dev commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added dynamic daily reflection prompts that change by time of day and local date.
    • Home now shows the reflection card only when a prompt is available and takes you directly to a new journal entry with that prompt.
    • Reflection prompts are now saved and restored more reliably across app sessions.
  • Bug Fixes

    • Improved layout consistency in AI responses and insight cards.
    • Better handling when prompts can’t be generated or refreshed, with safer fallback behavior.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds an end-to-end dynamic daily reflection prompt system: new types, domain validation/fallback logic, a Supabase edge function calling an AI provider, a client service with request deduplication, a persisted Zustand store, useReflectionClock/useDailyReflectionPrompt hooks, and Home screen wiring. It also includes unrelated layout tweaks to the AI response renderer and insights card, plus tests and docs.

Changes

Dynamic Daily Reflection Prompts

Layer / File(s) Summary
Types and domain logic
types/dailyReflectionPrompt.ts, lib/reflection-prompts/dailyReflectionPrompts.ts, data/daily-reflection-prompts.ts, tests/daily-reflection-prompts.test.ts, package.json
Defines prompt/bundle types and implements period detection, date-key generation, validation (length, duplicate, unsafe-content checks), and deterministic fallback bundle creation, backed by a prompt pool and a dedicated test script/suite.
Supabase edge function
supabase/functions/generate-daily-reflection-prompts/*, supabase/config.toml
Adds a Deno edge function that authenticates requests, validates payloads, calls an AI chat-completions endpoint, caches/deduplicates in-flight requests, validates returned prompts, and returns structured JSON responses.
Client service and persisted store
lib/ai/dailyReflectionPromptService.ts, store/useDailyReflectionPromptStore.ts, lib/account/clearLocalUserData.ts
Adds a service calling the edge function with in-flight request dedup and error mapping, and a Zustand store persisting sanitized prompt bundles per user, wired into account cleanup.
Reflection hooks
hooks/useReflectionClock.ts, hooks/useDailyReflectionPrompt.ts
Adds a clock hook that schedules updates at period boundaries and a hook that resolves/generates/caches the current prompt bundle with offline fallback and stale-response protection.
Home screen wiring and docs
components/home/home-screen.tsx, docs/dynamic-home-reflection-prompts-test.md
Wires the Home screen reflection card and CTA to the new hooks, conditionally rendering the card and routing to the journal editor with the generated prompt; adds a manual test matrix.

Layout tweaks

Layer / File(s) Summary
AI renderer full-width text
components/ai/ai-response-renderer.tsx
Adds explicit w-full classes across headings, blockquotes, paragraphs, list items, and error fallback text.
Insights card title layout
components/insights/insights-screen.tsx
Updates InsightMessageCard emoji/title layout with a new flex wrapper and typography classes.

Estimated code review effort: 4 (Complex) | ~75 minutes

Sequence Diagram(s)

sequenceDiagram
  participant HomeScreen
  participant useDailyReflectionPrompt
  participant PromptStore as useDailyReflectionPromptStore
  participant PromptService as dailyReflectionPromptService
  participant EdgeFunction as generate-daily-reflection-prompts
  participant AIProvider

  HomeScreen->>useDailyReflectionPrompt: currentTime (from useReflectionClock)
  useDailyReflectionPrompt->>PromptStore: read cached bundle / hydration status
  alt bundle missing and online
    useDailyReflectionPrompt->>PromptService: generateDailyReflectionPromptBundle
    PromptService->>EdgeFunction: POST dateKey, timezone
    EdgeFunction->>AIProvider: chat completion request
    AIProvider-->>EdgeFunction: prompt JSON
    EdgeFunction-->>PromptService: validated prompts
    PromptService-->>useDailyReflectionPrompt: bundle or error
    useDailyReflectionPrompt->>PromptStore: setBundle (generated or fallback)
  else offline
    useDailyReflectionPrompt->>PromptStore: setBundle (fallback)
  end
  useDailyReflectionPrompt-->>HomeScreen: isLoading, period, prompt
  HomeScreen->>HomeScreen: openDailyReflection navigates to /journal/new
Loading

Possibly related PRs

  • aryansoni-dev/dear-diary#39: Introduces/uses clearLocalUserData for account deletion, which this PR extends to also clear daily reflection prompt bundles.
  • aryansoni-dev/dear-diary#46: Modifies the same components/ai/ai-response-renderer.tsx introduced there, with this PR adjusting its layout classes.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: dynamic, time-aware daily AI reflection prompts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/home/home-screen.tsx`:
- Around line 198-211: The empty-state CTA is currently disabled in
openDailyReflection when reflectionPrompt is null, which blocks users while the
prompt is still loading. Update openDailyReflection in home-screen.tsx to always
navigate to a usable journal entry path, either by falling back to the plain
/journal/new flow without prompt params or by preserving the previous non-prompt
editor route, while keeping the reflection prompt behavior only when
reflectionPrompt is available.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 571aa6c4-9238-4d9f-9228-ec29f577adc0

📥 Commits

Reviewing files that changed from the base of the PR and between 72028f9 and d848178.

⛔ Files ignored due to path filters (1)
  • assets/images/insights-tab-mockup.png is excluded by !**/*.png
📒 Files selected for processing (17)
  • components/ai/ai-response-renderer.tsx
  • components/home/home-screen.tsx
  • components/insights/insights-screen.tsx
  • data/daily-reflection-prompts.ts
  • docs/dynamic-home-reflection-prompts-test.md
  • hooks/useDailyReflectionPrompt.ts
  • hooks/useReflectionClock.ts
  • lib/account/clearLocalUserData.ts
  • lib/ai/dailyReflectionPromptService.ts
  • lib/reflection-prompts/dailyReflectionPrompts.ts
  • package.json
  • store/useDailyReflectionPromptStore.ts
  • supabase/config.toml
  • supabase/functions/generate-daily-reflection-prompts/deno.json
  • supabase/functions/generate-daily-reflection-prompts/index.ts
  • tests/daily-reflection-prompts.test.ts
  • types/dailyReflectionPrompt.ts

Comment thread components/home/home-screen.tsx
@aryansoni-dev
aryansoni-dev merged commit e95e396 into main Jul 6, 2026
1 check passed
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