mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
The v1.4.22 B5 audit removed the placeholder cog from the Coach
drawer header because it had no real wiring. v1.4.23 H4 returns
the cog with an actual settings surface backed by a per-user
preferences row.
Schema: nullable JSONB column `users.coach_prefs_json` (migration
0038_coach_prefs). Null = legacy v1.4.22 defaults; non-null carries
`{ tone, verbosity, excludeMetrics, showEvidenceByDefault }` validated
by the Zod schema in `src/lib/validations/coach-prefs.ts`.
Routes: GET + PUT `/api/auth/me/coach-prefs`. PUT validates the body,
persists the canonical defaulted form, and emits an
`auth.me.coach-prefs.put` annotation with the four-knob meta. OpenAPI
registry covers both verbs; the spec regenerates without drift.
Coach prompt builder: `getCoachSystemPrompt(locale, prefs)` prepends a
per-user OVERRIDE paragraph for non-default tone (neutral / concise)
and verbosity (brief / detailed). Concise tone forces brief verbosity
regardless of the explicit selection — concise == short. Default
prefs leave the prompt unchanged so the v1.4.22 train stays in place.
Snapshot builder: reads the prefs row BEFORE any measurement query
and intersects `excludeMetrics` with the resolved scope. The model
never sees data the user opted out of — that's the load-bearing
order: filter first, query second.
UI: settings cog in the drawer header opens a right-edge `<Sheet>`
with three Select pickers (tone, verbosity) and one Switch column
(per-metric exclusions + showEvidenceByDefault). Save calls the PUT
route and invalidates the `["coach-prefs"]` query so the next reply
honours the new defaults without a reload. EN + DE i18n keys for
every label and hint.
Message-thread reads the same `["coach-prefs"]` cache and toggles the
`open` attribute on the evidence `<details>` element when
`showEvidenceByDefault` is true.
Tests +24 unit (coach-prefs schema, system-prompt prefix, snapshot
mock for new prefs row). Integration round-trip seeds a session,
PUTs a non-default prefs shape, asserts the GET reflects the saved
values + the DB row carries the canonical defaulted form.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
16 lines
832 B
SQL
16 lines
832 B
SQL
-- v1.4.23 H4 — per-user Coach prompt-tuning preferences.
|
|
--
|
|
-- The Coach drawer's settings cog returned in v1.4.23 (the v1.4.22 B5
|
|
-- audit had pulled the dead placeholder cog out so it stayed empty
|
|
-- until the per-user surface was real). Persist the four controls the
|
|
-- cog exposes — tone, verbosity, excludeMetrics, showEvidenceByDefault
|
|
-- — as a single nullable Json column so adding new knobs in v1.5
|
|
-- (e.g., per-source language preference) doesn't churn the schema.
|
|
--
|
|
-- Default behaviour stays exactly v1.4.22 when the column is NULL —
|
|
-- tone="warm", verbosity="default", no metrics excluded, evidence
|
|
-- disclosure closed by default. The Coach prompt builder reads the
|
|
-- column and folds non-default knobs into the system prompt prefix.
|
|
ALTER TABLE "users"
|
|
ADD COLUMN IF NOT EXISTS "coach_prefs_json" JSONB;
|