Skip to content

fix(briefing): greet for the actual time of day, not the period#135

Merged
abdulsaheel merged 2 commits into
OpenStrap:mainfrom
dannymcc:fix/briefing-time-of-day
Jul 23, 2026
Merged

fix(briefing): greet for the actual time of day, not the period#135
abdulsaheel merged 2 commits into
OpenStrap:mainfrom
dannymcc:fix/briefing-time-of-day

Conversation

@dannymcc

@dannymcc dannymcc commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #134 (reported by @davidfleischmann).

Problem

The AI briefing greeted with "morning" in the afternoon. The morning briefing period (last night's sleep + recovery) is shown right up until 17:00 by design, and the prompt hard-coded that framing — briefingSystemPrompt said "you write the morning health briefing … this morning's recovery" and the user prompt opened "Morning briefing for …". So a reader opening it at 3pm was handed "morning" and the model dutifully greeted with it.

Fix

Separate the greeting (which should follow the clock) from the period (a data-scope concept). generate() already has the current time, so:

  • New partOfDay(now)morning/afternoon/evening/night.
  • The prompt is told the reader's real local time of day and to greet for that, never assuming another time; the morning/evening scope wording is now time-neutral (no "this morning").
  • No "morning" leaks into a morning-period prompt viewed in the afternoon.

The morning/evening period still drives which data the briefing summarises — only the greeting now tracks the clock.

Tests

test/ai_briefing_test.dart: partOfDay boundaries, and that a morning-period prompt built for an afternoon reader says "currently afternoon" and never "morning".

Verified by inspection + unit tests (no SDK here to run flutter test); worth a quick on-device look that an afternoon briefing now reads right.

Closes #134

Summary by CodeRabbit

  • New Features

    • Briefings now derive greeting and contextual header details from the reader’s local time of day.
    • Greeting guidance is generated for the current time-of-day bucket (morning/afternoon/evening/night) and stays consistent throughout the prompt.
  • Bug Fixes

    • Prevented incorrect time-of-day greetings when the briefing period and local clock don’t match.
    • Briefings now use a single “effective now” timestamp for input collection and generation time.
  • Tests

    • Updated prompt-building tests to cover explicit greeting inputs and clock-based behavior (including negative assertions).

The morning briefing (last night's sleep + recovery) is shown until 17:00, so
the prompt telling the model it's the 'morning' briefing made the AI greet with
'morning' in the afternoon (OpenStrap#134). Pass the reader's real local time of day into
the prompt and greet for that; keep the morning/evening period only as the data
scope.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5ed932e2-cc70-41b4-8c9c-1ea48fc31c14

📥 Commits

Reviewing files that changed from the base of the PR and between b2a2e91 and 7df3981.

📒 Files selected for processing (1)
  • lib/ai/briefing_engine.dart

📝 Walkthrough

Walkthrough

Briefing prompt generation now derives the reader’s local time of day and passes it through system and user prompts, keeping greeting text independent from the briefing period. Tests cover the new arguments, time-based greeting behavior, and metric rendering.

Changes

Briefing time awareness

Layer / File(s) Summary
Time-of-day prompt contract
lib/ai/briefing_engine.dart, test/ai_briefing_test.dart
Adds partOfDay, extends both prompt builders with timeOfDay, updates greeting and header text, and tests mismatched period and greeting values.
Generation time wiring
lib/ai/briefing_engine.dart
BriefingEngine.generate derives one effective timestamp, passes its local time-of-day label to both prompt builders, and uses it for generatedAtMs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: abdulsaheel

🚥 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 PR’s main change: using the reader’s actual time of day for briefing greetings.
Linked Issues check ✅ Passed The change addresses issue #134 by deriving time of day from the reader’s clock and using it in briefing prompts.
Out of Scope Changes check ✅ Passed The diff stays focused on briefing prompt/time handling and related tests, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

🧹 Nitpick comments (1)
test/ai_briefing_test.dart (1)

124-138: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the generation wiring, not only the pure builders.

This test passes 'afternoon' directly to both prompt builders, so it would still pass if BriefingEngine.generate stopped deriving or forwarding tod. Extend the generation test with a fixed afternoon now and assert the captured system and user prompts contain the local-time label.

🤖 Prompt for 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.

In `@test/ai_briefing_test.dart` around lines 124 - 138, Extend the
BriefingEngine.generate test to use a fixed afternoon now value and capture its
generated system and user prompts. Assert both prompts contain the corresponding
local-time label, verifying generate derives and forwards tod rather than
testing only briefingSystemPrompt and buildBriefingUserPrompt directly.
🤖 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 `@lib/ai/briefing_engine.dart`:
- Around line 251-258: Capture a single effective timestamp at the start of the
briefing generation flow, using the provided now value or one DateTime.now()
fallback. Reuse it for todayLabel, partOfDay, collectBriefingInputs, and
generatedAtMs so all generated content shares the same time snapshot.

---

Nitpick comments:
In `@test/ai_briefing_test.dart`:
- Around line 124-138: Extend the BriefingEngine.generate test to use a fixed
afternoon now value and capture its generated system and user prompts. Assert
both prompts contain the corresponding local-time label, verifying generate
derives and forwards tod rather than testing only briefingSystemPrompt and
buildBriefingUserPrompt directly.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d8df6a2-8c5d-4db0-b2e8-e07ef7aa8a87

📥 Commits

Reviewing files that changed from the base of the PR and between bae8f23 and b2a2e91.

📒 Files selected for processing (2)
  • lib/ai/briefing_engine.dart
  • test/ai_briefing_test.dart

Comment thread lib/ai/briefing_engine.dart Outdated
Reuse a single now for the day label, greeting and generatedAt so a null-now
generation can't straddle midnight or a greeting boundary. Addresses CodeRabbit
review on OpenStrap#135.
@abdulsaheel
abdulsaheel merged commit 9707e08 into OpenStrap:main Jul 23, 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.

the AI Briefing says morning when it is afternoon

2 participants