feat: lay down the day view and timeline contract

Land every file the day view, the timeline and life events share before
any of them is built, so the server, the day view and the timeline can be
built side by side without editing the same file (#613).

Schema and migration 0387: LifeEvent with a short category list, calendar
start and end dates, a day/month/year precision, encrypted title and note,
a soft-delete tombstone and an index for the per-user live list. Every new
column is annotated for the column-reader sweep. Life events travel in both
backup purposes with their two ends in one file, are wiped with the
account, and are registered for key rotation.

src/lib/day/contract.ts carries the constants and wire types for
GET /api/day/{date}, /api/day/index, /api/timeline, /api/timeline/readiness
and the life-event routes, free of Zod so the navigation chrome can import
it; the schemas beside it feed the routes and the published contract. The
Coach and MCP tool name get_day is reserved there, and life events are
listed as the one section no model ever sees.

The opt-in timeline module, its navigation entry, the day-section and
timeline-lane surfaces, the day and timeline query keys (evicted by every
record data bundle), and stub routes that answer 501 behind their
admissions. The four cross-section reads declare the whole record for now;
the life-event list is a profile read, and life events join the profile
sharing domain and its consent copy in all seven locales. The day,
timeline and lifeEvents message namespaces carry their base copy as
release-pending keys.

The aggregate bundle cap moves to 4400: the branch already measured 4365
against 4335, and the new copy adds 10 KB.
This commit is contained in:
Marc-André Bombeck committed 2026-10-08 13:03:37 +02:00
1 parent 861ba21086
commit c79fc6cc7b
57 files changed
+4290 -21

No files matched your search

+5 -1
View File
@@ -374,7 +374,11 @@ describe("registry — opt-in marker", () => {
// default-on disabled-allowlist now; their egress channels (the weather
// fetch, the document AI-read, the AI Coach exposure) are separately gated
// and stay off until explicitly configured.
const OPT_IN_KEYS = new Set(["mcp", "nutrients"]);
//
// v1.42 — `timeline` joins them for a different reason: it opens no channel,
// but it is a new way of reading the whole record, and the readiness
// inventory shown when it is switched on is meant to be the first contact.
const OPT_IN_KEYS = new Set(["mcp", "nutrients", "timeline"]);
it("marks only the egress-surface modules opt-in (every other is default-on)", () => {
for (const key of MODULE_KEYS) {
@@ -67,6 +67,7 @@ import {
} from "@/lib/insights/sub-page-metric";
import { TREND_CHART_CONFIG } from "@/lib/insights/trend-chart-select";
import { SYMPTOM_CHANNEL_PREFIX } from "@/lib/symptoms/shared";
import { DAY_SECTION_KEYS, TIMELINE_LANE_KEYS } from "@/lib/day/contract";
import {
SURFACE_KINDS,
SURFACE_MODULE,
@@ -156,6 +157,20 @@ describe("every surface id names a surface that exists", () => {
}
});
it("day-section: a section the day view renders", () => {
const keys = new Set<string>(DAY_SECTION_KEYS);
for (const id of localIds("day-section")) {
expect(keys.has(id), id).toBe(true);
}
});
it("timeline-lane: a lane the timeline renders", () => {
const keys = new Set<string>(TIMELINE_LANE_KEYS);
for (const id of localIds("timeline-lane")) {
expect(keys.has(id), id).toBe(true);
}
});
it("correlation: a discovery channel, a weather field or the lab pass", () => {
const channels = new Set<string>([
...DISCOVERY_BEHAVIOURS,
@@ -269,6 +284,10 @@ describe("every surface that shows a module's data is owned by it", () => {
["correlation:MEDICATION_COMPLIANCE", "medications"],
["correlation:SYMPTOM_SEVERITY", "illness"],
["correlation:LAB_DRAWS", "labs"],
["nav:/timeline", "timeline"],
["day-section:lifeEvents", "timeline"],
["day-section:symptoms", "illness"],
["timeline-lane:documents", "inboundDocuments"],
])("%s is owned by %s", (id, owner) => {
expect(surfaceModule(id)).toBe(owner);
});
+10
View File
@@ -44,6 +44,7 @@ type DomainDataClient = Pick<
| "mentalHealthAssessment"
| "nutrientIntakeDay"
| "vaccinationRecord"
| "lifeEvent"
>;
type DomainProbe = (
@@ -201,6 +202,15 @@ const MODULE_DOMAIN_PROBES: Record<OwnedModuleKey, DomainProbe> = {
select: { id: true },
}),
),
// The timeline's own content is the life events; everything else on it
// belongs to other modules and says nothing about whether this one is used.
timeline: (client, recordId) =>
anyRow(
client.lifeEvent.findFirst({
where: { userId: recordId, deletedAt: null },
select: { id: true },
}),
),
};
/**
+21
View File
@@ -173,6 +173,19 @@ export const MODULE_KEYS = [
// surfaces the person made content for; it does not silently retract a
// commitment the app made to them.
"vaccinations",
// v1.42 (#613) — the life timeline (`/timeline`): years at a glance, the
// record's conditions, medications, visits and documents in lanes beside the
// value series, plus the person's own life events. OPT-IN (off by default):
// not because it egresses (it does not), but because it is a new way of
// looking at the whole record, and the readiness inventory that greets the
// switch is the right first contact with it. The day view is NOT this
// module: it is core and opens for every account.
//
// Life events belong to this module. They are only created from the
// timeline and the day's capture sheet while it is on, and they disappear
// from the day with it; the `/api/life-events` row store stays reachable so
// a restore keeps working and re-enabling finds the events intact.
"timeline",
] as const;
export type ModuleKey = (typeof MODULE_KEYS)[number];
@@ -369,6 +382,14 @@ export const MODULE_REGISTRY: Readonly<Record<ModuleKey, ModuleDefinition>> =
// No `optIn`: default-on. Nothing leaves the instance and the surfaces
// are inert until the person logs a dose.
},
timeline: {
key: "timeline",
labelKey: "modules.timeline.label",
descriptionKey: "modules.timeline.description",
category: "tracking",
// Off by default; see the key's comment in `MODULE_KEYS`.
optIn: true,
},
});
const MODULE_KEY_SET: ReadonlySet<string> = new Set(MODULE_KEYS);
+40
View File
@@ -48,6 +48,10 @@ import type { ModuleKey } from "@/lib/modules/registry";
* - `settings-layout`: a Settings, Layout group, by its id.
* - `correlation`: a correlation-discovery channel, by its channel key.
* - `score-ring`: a dashboard hero score ring, by its `ScoreRingId`.
* - `day-section`: a section of the day view, by its `DaySectionKey`. The
* day loader blanks a section whose owner is off, and the views drop it.
* - `timeline-lane`: a lane of the timeline, by its `TimelineLaneKey`; the
* readiness inventory leaves it out the same way.
*/
export const SURFACE_KINDS = [
"nav",
@@ -62,6 +66,8 @@ export const SURFACE_KINDS = [
"settings-layout",
"correlation",
"score-ring",
"day-section",
"timeline-lane",
] as const;
export type SurfaceKind = (typeof SURFACE_KINDS)[number];
@@ -79,6 +85,7 @@ const STATIC_SURFACE_MODULE = {
"nav:/documents": "inboundDocuments",
"nav:/coach": "coach",
"nav:/achievements": "achievements",
"nav:/timeline": "timeline",
// ── Insights sub-pages ──
"insights-page:mood": "mood",
@@ -205,6 +212,39 @@ const STATIC_SURFACE_MODULE = {
"correlation:SYMPTOM_SEVERITY": "illness",
// The labs ↔ outcome pass over lab draws.
"correlation:LAB_DRAWS": "labs",
// ── Day view sections (v1.42) ──
// The readings carry no owner here: each value follows its own type's
// module (`moduleForMeasurementType`), so a section-level owner would hide
// the core vitals with it. Allergies, visits, check-ups and the anamnesis
// facts are core record surfaces and stay unowned.
"day-section:sleep": "sleep",
"day-section:mood": "mood",
"day-section:assessments": "mentalHealth",
"day-section:medications": "medications",
"day-section:illness": "illness",
// Person-defined symptoms ride the illness module, as everywhere else.
"day-section:symptoms": "illness",
"day-section:labs": "labs",
"day-section:vaccinations": "vaccinations",
"day-section:documents": "inboundDocuments",
"day-section:workouts": "workouts",
"day-section:cycle": "cycle",
"day-section:environment": "environment",
// Life events are the timeline module's own content: off, they leave the
// day as well.
"day-section:lifeEvents": "timeline",
// ── Timeline lanes (v1.42) ──
// The `life` lane mixes life events (this module) with travel periods (the
// environment module) and is filtered item by item; allergies and visits are
// core.
"timeline-lane:illness": "illness",
"timeline-lane:medications": "medications",
"timeline-lane:vaccinations": "vaccinations",
"timeline-lane:labs": "labs",
"timeline-lane:documents": "inboundDocuments",
"timeline-lane:cycle": "cycle",
} as const satisfies Record<string, ModuleKey>;
/** A surface id the map declares literally. */