krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

docs/superpowers/plans/2026-10-16-part5-today-routine.md

062549ad26607ce9e973ed2a9a7ef6f853885f83
daybyday/docs/superpowers/plans/2026-10-16-part5-today-routine.md rendered · source · history · blame · raw

99 lines · 10119 bytes

10 symbols in this file
 1# Part 5: Today Routine Implementation Plan
 2
 3> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
 4
 5**Goal:** A short spoken morning routine (greeting, birthday line, today/yesterday/tomorrow, day picture, month, season, pick today's weather) that ends with a weather sticker on a browsable month calendar, per child, plus parent-set day pictures shown on day cards and in the routine.
 6
 7**Architecture:** Two new SwiftData models, `Sticker` and `DayPicture`, reference a child by `profileID` instead of a relationship, so the existing `Profile` entity is unchanged and earlier stores open with a purely additive schema change; `ProfileStore` deletes them with the profile. The routine's lines come from a pure `RoutineScript`; the calendar layout from a pure `MonthGrid`. Views: `TodayRoutineView` (step cards, weather pick, sticker award) reached from the home banner, `StickerCalendarView`, and a day-pictures section in the profile editor.
 8
 9**Tech Stack:** SwiftUI, SwiftData, Swift Testing, Xcode 27.
10
11**Spec:** `docs/superpowers/specs/2026-10-16-learning-games-design.md` (part 5). Builds on the part 1–4 plans in this folder.
12
13## Global Constraints
14
15- iOS 17.5 target; SF Symbols must be in SF Symbols 5; each new symbol gets a `UIImage(systemName:)` test.
16- `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor`; pure logic `nonisolated`.
17- No change to the `Profile` or `AnswerRecord` entities. New entities only. A store written by the current main build must open with the new container and keep its profiles (test in Task 1).
18- One sticker per child per calendar day; finishing the routine again that day replaces the sticker's weather.
19- Weeks start on Sunday. Seasons as in `MonthOfYear.season`. The weather pick is not a quiz: any choice is accepted.
20- Every prompt spoken; the child never needs to read. Flat fills; every new fill with white content ≥ 3:1 in `ContrastTests`.
21- Lifecycle: `generation` guard on every `asyncAfter`; `ZStack` for screen states; advance on speech completion with a step-scoped backstop.
22- Day pictures are set behind the parent gate (profile editor), per child.
23- Branch `feat/today-routine`. Every commit `Ref #N` (last `Closes #N`). No AI attribution.
24- Test command: `xcodebuild test -project DayByDay.xcodeproj -scheme DayByDay -destination 'platform=iOS Simulator,name=iPhone 18 Pro'` (full suite ~10 min; run in background).
25
26## Review Focus
27
281. Day boundaries: yesterday/tomorrow wrap at the week's ends and across month and year ends (Friday Jan 1, 2027 → "Yesterday was Thursday.", "It's January."). Test in Task 2.
292. Birthday lines: Feb 29 birthdays in non-leap years get the month line all February and no "today" line; birthday today beats birthday month. Test in Task 2.
303. Stickers: finishing twice the same day keeps one sticker; deleting a child removes their stickers and day pictures and no one else's. Test in Task 1.
314. A store from the previous build (profiles and answers only) opens with the new schema and keeps its data. Test in Task 1.
325. Calendar browsing never goes past the current month, and a month with no stickers still renders its grid. Test in Task 2 (`MonthGrid`) and Task 5.
33
34---
35
36### Task 0: Branch and issue
37
38- [ ] `git checkout -b feat/today-routine main`; `gitbay issue create --title "Part 5: Today routine and sticker calendar" --json --file -`; commit this plan with `Ref #N`.
39
40### Task 1: Stickers and day pictures in the store
41
42**Files:** Create `DayByDay/Profiles/Sticker.swift`, `DayByDay/Profiles/DayPicture.swift`. Modify `ProfileStore.swift` (container types, methods, delete). Test `DayByDayTests/StickerStoreTests.swift`.
43
44**Interfaces:**
45- `@Model final class Sticker { var profileID: UUID; var year: Int; var month: Int; var day: Int; var weatherRaw: Int; var createdAt: Date }`.
46- `nonisolated enum DayPictureKind: String, CaseIterable { swim, school, grandma, park, music, soccer, library, dance }` with `name` ("swim day", "school day", "grandma day", "park day", "music day", "soccer day", "library day", "dance day") and `symbol` (`figure.pool.swim`, `backpack.fill`, `heart.fill`, `tree.fill`, `music.note`, `soccerball`, `books.vertical.fill`, `figure.dance`).
47- `@Model final class DayPicture { var profileID: UUID; var weekdayRaw: Int; var kindRaw: String }`.
48- `ProfileStore.makeContainer` includes `Sticker` and `DayPicture`. New methods: `addSticker(for: Profile, on: DateComponents (year, month, day), weather: LearnWeather)` (upsert), `stickers(for: Profile, year: Int, month: Int) -> [Sticker]`, `sticker(for: Profile, on:) -> Sticker?`, `setPicture(_ kind: DayPictureKind?, on: DayOfWeek, for: Profile)` (nil removes), `picture(on: DayOfWeek, for: Profile) -> DayPictureKind?`. `delete(_:)` also deletes the profile's stickers and pictures.
49
50- [ ] Tests: `stickerUpsertsPerDay`, `stickersByMonth`, `picturesSetReplaceRemove`, `deleteRemovesOnlyThatChildsData`, `pictureSymbolsExist`, `oldStoreOpens` (create an on-disk store at a temp URL with a container of `Profile` and `AnswerRecord` only, insert a profile and an answer, drop it, open the same URL with `makeContainer`'s full type list, expect the profile and answer). RED, implement, GREEN, commit `feat: stickers and day pictures`.
51
52### Task 2: Routine script and month grid
53
54**Files:** Create `DayByDay/Today/RoutineScript.swift`, `DayByDay/Today/MonthGrid.swift`. Test `DayByDayTests/RoutineScriptTests.swift`, `DayByDayTests/MonthGridTests.swift`.
55
56**Interfaces:**
57- `nonisolated struct RoutineScript { struct Line: Equatable { let text: String; let symbol: String } ; init(date: Date, calendar: Calendar, name: String?, birthday: (month: Int, day: Int)?, picture: DayPictureKind?); let lines: [Line] }`. Order:
58  1. `"Hi, \(name)!"` (or `"Hi!"`), symbol `sun.max.fill`.
59  2. Birthday today: `"Today is your birthday! Happy birthday!"` (`birthday.cake.fill`); else birthday month: `"Your birthday is in \(Month)!"` (`gift.fill`). Feb 29 birthdays count as "today" only on Feb 29.
60  3. `"Today is \(Day)."` (that day's `DayOfWeek.symbol`); then, if a picture is set for today, `"Today is \(picture.name)!"` (picture symbol).
61  4. `"Yesterday was \(Day)."`, 5. `"Tomorrow is \(Day)."` (day symbols).
62  6. `"It's \(Month)."` (month symbol), 7. `"It's \(Season)."` (season symbol).
63- `nonisolated struct MonthGrid { init(year: Int, month: Int, calendar: Calendar); let leadingBlanks: Int (Sunday-first); let days: Int; var cells: [Int?] (blanks then 1…days); func shifted(by months: Int) -> MonthGrid }`.
64
65- [ ] Tests with a Gregorian calendar fixed to UTC: `fridayScript` (2026-10-16, "Maya", no birthday, no picture → the 7 lines exactly), `birthdayMonthLine`, `birthdayTodayBeatsMonth`, `leapBirthday` (Feb 29 birthday on 2027-02-28 → month line only; on 2028-02-29 → today line), `pictureLine`, `weekWraps` (2026-10-18 Sunday → yesterday Saturday; 2026-10-17 Saturday → tomorrow Sunday), `yearEnd` (2027-01-01 → "It's January.", yesterday Thursday), `octoberGrid` (2026-10: 4 blanks, 31 days), `februaryGrids` (2027: 28, 2028: 29), `shiftAcrossYear` (2026-12 shifted by 1 → 2027-01). RED, implement, GREEN, commit `feat: routine script and month grid`.
66
67### Task 3: Day pictures for parents and on day cards
68
69**Files:** Modify `DayByDay/Profiles/ProfileEditorView.swift` (section), `DayByDay/DayCard.swift` (flat fill + badge), `DayByDay/DaysOfWeekView.swift`. Test `ContrastTests`.
70
71**Interfaces:**
72- Profile editor (existing profiles only): section "Day pictures" with a picker per weekday (None + each kind, symbol and name), saving through `setPicture`.
73- `DayCard(day:isHighlighted:picture:)`: flat fill; `DayOfWeek.color` changed to values ≥ 3:1 against white; when `picture` is set, a white badge circle with the picture symbol in the day color sits in the top-trailing corner, and tapping says `"\(Day). It's \(picture.name)!"` instead of the day name.
74- `DaysOfWeekView` reads the current profile's pictures from the session.
75
76- [ ] Test `dayColorAgainstWhite` over all days. RED, implement, GREEN, render, commit `feat: day pictures`.
77
78### Task 4: Today routine screen
79
80**Files:** Create `DayByDay/Today/TodayRoutineView.swift`. Modify `DayByDay/Home/HomeView.swift`, `DayByDay/Home/TodayBanner.swift`.
81
82**Interfaces:**
83- `TodayRoutineView`: one large step card at a time (symbol 120 pt, the line in large text on the today color), spoken on appear; a big "next" arrow button advances (and "Hear it again"). After the last line: `"What's the weather like today?"` with `ChoiceTile`s for sunny, cloudy, rainy, snowy, windy. Any tap: `.success`, `"It's \(weather) today! Here's your sticker!"`, `addSticker(today, weather)`, then `StickerCalendarView` for the current month with today's sticker, plus "Play again" style "Done" back navigation. Without a current profile (cannot happen past the picker) the routine still runs and skips the sticker.
84- Home banner links to `TodayRoutineView`; its subtitle line shows "Tap for your sticker!" until today's sticker exists, then a small sticker in today's weather.
85
86- [ ] Build, render (steps and weather pick), commit `feat: today routine`.
87
88### Task 5: Sticker calendar
89
90**Files:** Create `DayByDay/Today/StickerCalendarView.swift`.
91
92**Interfaces:**
93- `StickerCalendarView(profile:, year:, month:)`: month name and year header with back/forward arrows (forward disabled at the current month); weekday initials row; 7-column grid from `MonthGrid`; each day cell shows its number, today outlined, and a sticker (weather symbol, white, in a circle of `Category.weather.color`) when present. Tapping a stickered day says `"On October 3, it was sunny."`.
94
95- [ ] Build, render a month with stickers and an empty month, commit `feat: sticker calendar`.
96
97### Task 6: Reviews, MR, merge
98
99- [ ] Extend `ReviewExport`. Fresh art/sound reviewer (two rounds max). Fresh whole-branch code reviewer with this Review Focus. One fix pass, RED→GREEN. Full suite green. Push, MR `Closes #N`, squash-merge, delete branch.