mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
feat(coach): default analysis window as user preference + per-conversation override
`coachPrefs.defaultWindow` joins the existing prefs blob (tone, verbosity, excludeMetrics, showEvidenceByDefault). The picker lives in the Coach settings sheet; the drawer header carries a small pill that overrides the saved default for the current chat only. Closing the drawer drops the override so the next session starts on the saved preference. Backwards-compatible: legacy rows missing the key resolve to "allTime", matching the v1.4.24 behaviour. The chat route folds the saved window into snapshot scope when the client doesn't supply one.
This commit is contained in:
1 parent
2bd29022b1
commit
330be965ac
10 files changed
+331
-8
No files matched your search
@@ -21,11 +21,24 @@ describe("coachPrefsSchema", () => {
|
||||
verbosity: "brief" as const,
|
||||
excludeMetrics: ["bp", "weight"] as const,
|
||||
showEvidenceByDefault: true,
|
||||
defaultWindow: "last30days" as const,
|
||||
};
|
||||
const out = coachPrefsSchema.parse(input);
|
||||
expect(out).toEqual(input);
|
||||
});
|
||||
|
||||
// v1.4.25 W5 — defaultWindow added. Missing key → fallback to
|
||||
// "allTime" so the legacy persisted shape stays representative.
|
||||
it("fills in defaultWindow=allTime when the key is missing", () => {
|
||||
const out = coachPrefsSchema.parse({});
|
||||
expect(out.defaultWindow).toBe("allTime");
|
||||
});
|
||||
|
||||
it("rejects unknown defaultWindow values", () => {
|
||||
const result = coachPrefsSchema.safeParse({ defaultWindow: "lifetime" });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects unknown tone values", () => {
|
||||
const result = coachPrefsSchema.safeParse({ tone: "stoic" });
|
||||
expect(result.success).toBe(false);
|
||||
@@ -82,7 +95,21 @@ describe("parseCoachPrefs", () => {
|
||||
verbosity: "default" as const,
|
||||
excludeMetrics: ["mood" as const],
|
||||
showEvidenceByDefault: true,
|
||||
defaultWindow: "last90days" as const,
|
||||
};
|
||||
expect(parseCoachPrefs(input)).toEqual(input);
|
||||
});
|
||||
|
||||
it("fills defaultWindow=allTime when older persisted rows are missing it", () => {
|
||||
// Legacy v1.4.23/v1.4.24 persisted shape without `defaultWindow`.
|
||||
// Defaulting is backwards-compatible — the row keeps reading as
|
||||
// "all time" until the user picks a tighter default in the cog.
|
||||
const legacy = {
|
||||
tone: "warm" as const,
|
||||
verbosity: "default" as const,
|
||||
excludeMetrics: [] as const,
|
||||
showEvidenceByDefault: false,
|
||||
};
|
||||
expect(parseCoachPrefs(legacy).defaultWindow).toBe("allTime");
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,12 @@
|
||||
* snapshot builder both read this shape — the snapshot must filter on
|
||||
* `excludeMetrics` BEFORE landing in the system prompt so the model
|
||||
* never sees data the user opted out of.
|
||||
*
|
||||
* v1.4.25 W5 — extended with `defaultWindow`. The picker lives in the
|
||||
* settings sheet; the drawer header carries a per-conversation override
|
||||
* pill so a single chat can narrow the window without flipping the
|
||||
* global default. The chat route folds the saved preference into the
|
||||
* snapshot scope when the client didn't supply a window override.
|
||||
*/
|
||||
import { z } from "zod/v4";
|
||||
|
||||
@@ -52,6 +58,23 @@ export const coachExcludeMetricEnum = z.enum([
|
||||
]);
|
||||
export type CoachExcludeMetric = z.infer<typeof coachExcludeMetricEnum>;
|
||||
|
||||
/**
|
||||
* v1.4.25 W5 — default analysis window the Coach uses when the client
|
||||
* doesn't supply a per-conversation override. Mirrors
|
||||
* `CoachScopeWindow` (`src/lib/ai/coach/types.ts`) so the chat route
|
||||
* can fold the preference into `scope.window` without a translation
|
||||
* layer. The default stays `allTime` to preserve the v1.4.24 behaviour
|
||||
* — every legacy row reads as "no opinion" until the user explicitly
|
||||
* picks a tighter default.
|
||||
*/
|
||||
export const coachDefaultWindowEnum = z.enum([
|
||||
"last7days",
|
||||
"last30days",
|
||||
"last90days",
|
||||
"allTime",
|
||||
]);
|
||||
export type CoachDefaultWindow = z.infer<typeof coachDefaultWindowEnum>;
|
||||
|
||||
/**
|
||||
* Full preferences shape. Defaults are inlined into the schema so a
|
||||
* `safeParse({})` call returns the legacy v1.4.22 defaults — saves a
|
||||
@@ -62,6 +85,7 @@ export const coachPrefsSchema = z.object({
|
||||
verbosity: coachVerbosityEnum.default("default"),
|
||||
excludeMetrics: z.array(coachExcludeMetricEnum).max(9).default([]),
|
||||
showEvidenceByDefault: z.boolean().default(false),
|
||||
defaultWindow: coachDefaultWindowEnum.default("allTime"),
|
||||
});
|
||||
|
||||
export type CoachPrefs = z.infer<typeof coachPrefsSchema>;
|
||||
@@ -77,6 +101,7 @@ export const DEFAULT_COACH_PREFS: CoachPrefs = {
|
||||
verbosity: "default",
|
||||
excludeMetrics: [],
|
||||
showEvidenceByDefault: false,
|
||||
defaultWindow: "allTime",
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user