Skip to content

Phase 4: Smart log, adaptive targets, coach memory, health sync, social sign-in, light theme - #7

Merged
coderback merged 8 commits into
mainfrom
phase-4
Nov 5, 2026
Merged

coderback merged 8 commits into
mainfrom
phase-4

Conversation

@coderback

@coderback coderback commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Phase 4 of the roadmap (docs/ROADMAP.md). The features come from new competitor research (docs/MARKET_RESEARCH.md): its three "build first" picks, plus the platform work that was asked for.

Stacked on #6 (Phase 3). The base is phase-3, so this diff shows only Phase 4. Merge #6 first; this PR then moves to main.

⚠️ Deploy notes

  • Migrations: 20261106120000 to 20261106150000 are already applied to Supabase. They only add tables and columns, so servers running earlier code keep working.
  • Sign-in: Google and Apple sign-in need the providers switched on in Supabase Auth. Add grit://auth-callback and the web app's /auth-callback to the allowed redirect URLs. The buttons stay hidden until a provider is on.
  • Native builds: HealthKit, Health Connect and the Smart log camera need a development build. New config: the @kingstinct/react-native-healthkit and react-native-health-connect plugins, expo-build-properties, Health Connect read permissions, camera/photo permission text, expo-apple-authentication and expo-web-browser.
  • Request size: the API now accepts JSON bodies up to 5 MB, for meal photos.

The research's three "build first" features

  • ✨ Smart log (POST /food/parse, POST /food/parse/log): type, dictate or photograph a meal.
    • The model splits it into items with portions and lists hidden oil, butter and sauces separately.
    • Nutrition comes from the user's own confirmed foods first, then Open Food Facts for branded items, then an estimate checked against its macros.
    • Each item shows its source and is reviewed before logging.
    • Confirmed foods and usual portions are saved per user (FoodMemory), and their names go to the model so it reuses them. Users see them, and can forget any, in "Foods GRIT knows".
    • Capped at 30 readings a day by an atomic counter. A failed reading isn't counted.
  • Adaptive calorie targets (GET /targets/adaptive, apply, snooze):
    • Estimated burn comes from the least-squares weight slope and intake on fully logged days, blended with the Mifflin estimate.
    • A suggested target appears on Stats and in the Sunday check-in.
    • Guardrails: at most ±200 kcal per change, a 1,200 kcal floor, changes under 50 kcal ignored, 6 days to settle after a change, and snooze for a week.
  • Coach memory and check-ins:
    • After each message, the coach saves lasting facts as notes and removes notes that go out of date. Notes are capped at 40, and notes the user writes are never dropped automatically.
    • The chat shows "🧠 Noted: …" as notes are taken, and they're managed in "What your coach knows" (/ai/memories).
    • The coach's context gains these notes, the week's averages over logged days, and the adaptive estimate.
    • A daily 1pm check-in looks at a logging gap, missed workouts, low protein, or a weight plateau while losing weight. It sends the first that applies; each kind at most once a week, never on Sundays.

Platform

  • Light theme: a light palette alongside the dark one. It follows the system setting, or the user picks under Account → Appearance. Styles read the current palette at render time, and the app remounts when the theme changes.
  • Google and Apple sign-in:
    • Supabase PKCE flow: native Apple sign-in on iOS (with a hashed nonce), and a browser sign-in with an /auth-callback code exchange everywhere else.
    • After the first sign-in, the backend user is created and any onboarding answers are saved.
  • Apple Health / Health Connect (POST /health/import, GET /health/recent):
    • Imports workouts, daily steps and sleep, and weigh-ins.
    • Re-sending is safe: workouts are matched by ActivityLog.externalId and days by HealthDay.
    • Phone steps count toward step challenges (the higher of logged and phone steps each day).
    • The coach sees steps and sleep.

Testing

  • Backend: 116 unit tests and 44 database tests. Prettier, ESLint, tsc and the schema drift check are clean.
  • Mobile: 23 unit tests, tsc clean, no lint errors (5 warnings, all in files this PR doesn't touch).
  • Live checks against the real model and a real sign-in:
    • Smart log: 13/13, including a photo reading and a learned food coming back as "your usual" with its portion.
    • Coach memory: 9/9. The coach remembered an ACL injury in a later answer, and replaced a schedule note when the schedule changed.
  • Web end-to-end:
    • Light theme 16/16, sign-in 12/12, health settings 5/5, Smart log 18/18, coach memory and check-ins 12/12.
    • Adaptive targets passed 8/8 when first built. I didn't re-run that suite at the end because it needs four weeks of seeded data; its database tests still pass.

Not testable here: real-device HealthKit and Health Connect sync, the camera, and native Apple sign-in.

- Colors now answers from the current palette (dark or a new light one
  tuned for contrast on white), so screens pick up the theme as they
  render. Styles that were computed once at load (sheet inputs, profile
  cards, buttons, settings rows, trend tabs, the scanner) are read at
  render instead.
- Settings → Account → Appearance: System (follows the phone, live),
  Light or Dark, saved on the device. Changing it redraws the app and
  returns to the same screen. The status bar and screen backgrounds
  follow, and app.json now reports the phone's setting.
Competitive landscape, category gaps and ranked moat candidates, with
sources. It sets the Phase 4 priorities: AI meal logging grounded in a
food database and the user's history, adaptive calorie targets, and a
coach with memory that acts across nutrition, training, habits and
friends.
- iOS: Apple's native sheet (expo-apple-authentication) with a hashed
  nonce, exchanged with Supabase via signInWithIdToken; the name Apple
  shares on first sign-in is saved to the account.
- Android and web, and Google everywhere: Supabase's sign-in page in a
  browser session (expo-web-browser), returning to /auth-callback with a
  one-time code. The Supabase client now uses the PKCE flow; the
  password reset screen already handled codes.
- "Continue with Apple / Google" on the login screen and the onboarding
  sign-up step, shown only for providers switched on in Supabase (read
  from its public settings), so nothing appears until they're set up.
  The old "coming soon" buttons are gone.
- Every sign-in method now finishes the same way (afterSignIn): create
  the backend user, named from the provider's profile, and save any
  onboarding answers.
- iOS reads Apple Health through @kingstinct/react-native-healthkit;
  Android reads Health Connect through react-native-health-connect
  (both read-only). Workouts, daily step totals, sleep and weigh-ins
  from the last two weeks, then incrementally, when the app opens or
  comes to the foreground (at most every 15 minutes).
- POST /health/import stores them idempotently: workouts by the health
  app's ID (new activity_logs.externalId), days and weigh-ins by date.
  New health_days table for steps and sleep.
- Step challenges count, per day, the larger of the phone's total and
  the steps on logged workouts, so nothing is counted twice. The coach
  sees today's steps and last night's sleep.
- Settings → Apple Health / Health Connect: connect, sync now, what's
  come in. Web explains it syncs from the phone apps. Overlapping sleep
  from a watch and a phone counts once; awake time is removed.
- App config: the HealthKit entitlement and read-permission text, the
  Health Connect read permissions and SDK 36.
- Works out what someone actually burns from what they logged and how
  their weight moved: a least-squares fit through the weigh-ins (no lag,
  steady against water swings) against average intake on days logged
  fully enough to trust, blended toward the profile's formula estimate
  while data is thin. Needs 14 days, 10 logged days and 4 weigh-ins.
- Suggests a target for the goal and pace, moving at most 200 kcal per
  check-in, never below 1,200, and only when the change is at least 50.
  After a change it waits a week; "Not now" snoozes for a week.
- GET /targets/adaptive, POST /targets/adaptive/apply and /snooze. The
  Sunday check-in alert includes the suggestion.
- Stats: a "Your metabolism" card with the estimate, confidence, the
  inputs behind it and the suggestion; before there's enough data, it
  shows what's still needed.
Smart log reads a typed, dictated or photographed meal into separate
items with portions, including the oil, butter and sauces trackers
usually miss. Each item's nutrition comes from the user's own past
confirmations first, then the food database for branded items, then
a sanity-checked estimate, and every item is shown with its source
for review before anything is logged.

Confirmed items are remembered per user (nutrition and usual
portion), so the next reading of the same food starts from their
numbers. Settings lists what has been learned and can forget it.
Readings are capped at 30 a day; a failed reading doesn't count.
The coach now takes short notes when a message holds something that
matters for future coaching (an injury, foods avoided, when they can
train) and replaces notes that go out of date. Notes are used in every
chat, shown in the chat as they're taken, and can be seen, added to
and deleted under What your coach knows. The coach's context also
gains the week's averages over logged days and the adaptive estimate.

A daily 1pm check-in looks for a logging gap, a run of missed
workouts, low protein against target, or a weight plateau while
cutting, and sends the first that applies. Each kind goes at most once
a week, never on Sundays, and only with progress alerts on.
@vercel

vercel Bot commented Nov 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
grit-demo Ready Ready Preview Nov 4, 2026 11:58pm UTC

@coderback
coderback changed the base branch from phase-3 to main November 5, 2026 00:01
@coderback
coderback merged commit c793f0f into main Nov 5, 2026
4 checks 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