feat(coach): warm, localized proactive nudge with opt-in AI enrichment

Rework the proactive Coach nudge so it reads like one human checking in on
another instead of a terse English alert.

Copy: the title is a name-led greeting that rotates day to day ("Guten
Morgen, …" / "Hey …"; the 05:15 frame makes a morning opener safe) and the
body is one calm observation plus a gentle invite — never an imperative.
Drop the verbatim quoting of the user's decrypted self-context sentence:
the focus is referenced only by presence, abstractly, and is no longer
decrypted at all. Remove the 80-char mid-word clamp; each channel composes
to a length budget instead.

Cadence: suppress the nudge when the user already talked to the Coach in
the last ~24 h. With the existing rolling frequency cap (never two in a
window) and the no-trigger-no-nudge rule, the surface stays anti-nag.

AI enrichment (opt-in via the coach prefs blob, default off): when a
provider is healthy the body is composed through the model under hard
guards — a per-user budget gate, a tight per-call timeout, a per-tick
ceiling so the sequential tick can't stall across the user base, and the
outbound safety screen on the output. Any error, timeout, budget refusal
or unsafe reply falls silently back to the deterministic template, which is
always the default and the fail-closed fallback.

Localized greetings, per-trigger bodies and the focus note across all six
locales; the prefs opt-in is surfaced in the notification settings.
This commit is contained in:
Marc-André Bombeck committed 2026-06-28 16:50:49 +02:00
1 parent 54c9b4206f
commit e216a9d678
16 files changed
+818 -237

No files matched your search

@@ -110,6 +110,7 @@ describe("parseNotificationPrefs", () => {
nudgeRoutine: true,
nudgeFrequency: "weekly",
ambientSuggestions: true,
nudgeAiComposed: false,
},
measurementReminder: {
clientManaged: false,
@@ -134,6 +135,7 @@ describe("parseNotificationPrefs", () => {
nudgeRoutine: true,
nudgeFrequency: "weekly",
ambientSuggestions: true,
nudgeAiComposed: false,
},
measurementReminder: {
clientManaged: false,
@@ -160,6 +162,7 @@ describe("parseNotificationPrefs", () => {
nudgeRoutine: true,
nudgeFrequency: "weekly",
ambientSuggestions: true,
nudgeAiComposed: false,
},
measurementReminder: {
clientManaged: false,
@@ -202,6 +205,7 @@ describe("resolveNotificationPrefs (deep-merge)", () => {
nudgeRoutine: true,
nudgeFrequency: "weekly",
ambientSuggestions: true,
nudgeAiComposed: false,
},
measurementReminder: {
clientManaged: false,
@@ -232,6 +236,7 @@ describe("resolveNotificationPrefs (deep-merge)", () => {
nudgeRoutine: true,
nudgeFrequency: "weekly",
ambientSuggestions: true,
nudgeAiComposed: false,
},
measurementReminder: {
clientManaged: false,
@@ -259,6 +264,7 @@ describe("resolveNotificationPrefs (deep-merge)", () => {
nudgeRoutine: true,
nudgeFrequency: "weekly",
ambientSuggestions: true,
nudgeAiComposed: false,
},
measurementReminder: {
clientManaged: false,
@@ -286,6 +292,7 @@ describe("resolveNotificationPrefs (deep-merge)", () => {
nudgeRoutine: true,
nudgeFrequency: "weekly",
ambientSuggestions: true,
nudgeAiComposed: false,
},
measurementReminder: {
clientManaged: false,
@@ -314,6 +321,7 @@ describe("resolveNotificationPrefs (deep-merge)", () => {
nudgeRoutine: true,
nudgeFrequency: "weekly",
ambientSuggestions: true,
nudgeAiComposed: false,
},
measurementReminder: {
clientManaged: false,
@@ -504,6 +512,7 @@ describe("resolveCoachNudgePrefs — v1.16.5 nudge cron gate", () => {
enabled: true,
groups: { medication: true, vitals: true, routine: true },
minIntervalDays: 7,
aiComposed: false,
});
});
+23
View File
@@ -133,6 +133,17 @@ const coachPrefsSchema = z
* prompts, or vice versa.
*/
ambientSuggestions: z.boolean(),
/**
* v1.25.0 — opt-IN for AI-composed nudge copy. Default OFF: the proactive
* nudge ships a deterministic warm localized template, and that template is
* always the fail-closed fallback. When this is on AND a provider is
* healthy the 05:15 tick composes the nudge through the model instead —
* under a per-user budget gate, a tight per-call timeout and a per-tick
* ceiling, with any error/timeout/budget falling silently back to the
* template. Off by default so provider saturation is opt-in, never the
* baseline.
*/
nudgeAiComposed: z.boolean(),
})
.partial();
@@ -213,6 +224,11 @@ export interface NotificationPrefs {
* opener + suggested-prompt chips). Default `true`.
*/
ambientSuggestions: boolean;
/**
* v1.25.0 — opt-in for AI-composed nudge copy. Default `false`; the
* deterministic template stays the default + fail-closed fallback.
*/
nudgeAiComposed: boolean;
};
measurementReminder: {
/**
@@ -270,6 +286,7 @@ export const DEFAULT_NOTIFICATION_PREFS: NotificationPrefs = {
nudgeRoutine: true,
nudgeFrequency: "weekly",
ambientSuggestions: true,
nudgeAiComposed: false,
},
measurementReminder: {
clientManaged: false,
@@ -459,6 +476,11 @@ export interface CoachNudgePrefs {
};
/** 7 for "weekly", 14 for "biweekly". */
minIntervalDays: number;
/**
* v1.25.0 — when true the nudge tick composes the copy through the model
* (under hard guards) instead of the deterministic template. Default false.
*/
aiComposed: boolean;
}
/**
@@ -481,6 +503,7 @@ export function resolveCoachNudgePrefs(raw: unknown): CoachNudgePrefs {
routine: coach.nudgeRoutine,
},
minIntervalDays: coach.nudgeFrequency === "biweekly" ? 14 : 7,
aiComposed: coach.nudgeAiComposed,
};
}