Make the Coach lookback a limit on every read

The saved Coach window only seeded the snapshot and each tool's default.
A tool could still read back to all time, the availability probe reported
counts and means for history outside the window, and several blocks read
fixed windows of their own (labs 12 months, correlations 180 days, the
coarse tail, the all-time extremes) whatever the setting said.

coachPrefs.defaultWindow is now enforced as a limit through one module,
history-reach.ts: the turn context clamps the client window, the snapshot
clamps its window and gives every fixed-window block either the shorter
window or, when the block's own window cannot fit, leaves it out. Every
retrieval tool clamps its window, an earlier period or a stored table that
reaches past the limit answers outside_reach, and the probe reads only
inside the limit and names older history as outside_reach without any
figure. Follow-up chips that would read past the limit are not offered.
The default (allTime) is no limit and reads as before. MCP clients pass no
limit and keep their own window arguments.

Adds the twelve-month option, rewrites the picker text to state what is
read with the numbers the readers use, shows the same options in the
managed-profile settings, counts cluster members with a singular, and
drops the opacity on switched-off rows that put their text below WCAG AA.
This commit is contained in:
Marc-André Bombeck committed 2026-10-04 20:45:21 +02:00
1 parent 3be83eee22
commit 393ac955f6
60 files changed
+2539 -304

No files matched your search

+16 -18
View File
@@ -8,11 +8,9 @@
* `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.
* v1.4.25 W5 — extended with `defaultWindow`, since then made the
* Coach's lookback limit: a per-conversation window can narrow it, never
* widen it (`src/lib/ai/coach/history-reach.ts`).
*/
import { z } from "zod/v4";
@@ -67,20 +65,20 @@ 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.
* How far back the Coach may look. This is a LIMIT, enforced
* by every Coach read (`src/lib/ai/coach/history-reach.ts`): the snapshot,
* every retrieval tool, the availability probe and the fixed-window blocks.
* Before, it only seeded the snapshot window and each tool's default, and a
* tool could read further back on its own. Values mirror `CoachScopeWindow`
* (`src/lib/ai/coach/types.ts`) so the chat route folds it into the scope
* without a translation layer. `lastYear` came with the limit. The default
* stays `allTime`, which is no limit, so a legacy row keeps its behaviour.
*/
export const coachDefaultWindowEnum = z.enum([
"last7days",
"last30days",
"last90days",
"allTime",
]);
export const coachDefaultWindowEnum = z
.enum(["last7days", "last30days", "last90days", "lastYear", "allTime"])
.describe(
"How far back the Coach may read, in every answer: snapshot, retrieval tools and summaries alike. `allTime` (the default) is no limit. Formerly only the starting window; `lastYear` came with the limit.",
);
export type CoachDefaultWindow = z.infer<typeof coachDefaultWindowEnum>;
/**