perf(bundle): keep zod out of the documents and Coach client routes

Both routes reached the schema library through a constant: the list of
document kinds, the list and bulk limits, the attachment cap, the Coach
data clusters and preference defaults, the conversation title length,
the scope source list and the report leaf order. Each sat in a schema
module, so importing the number shipped the library. The constants now
live in zod-free modules (lib/documents/inbound-constants,
lib/ai/coach/prefs-constants, lib/ai/coach/scope-sources,
lib/report-selection/catalogue) and the schema modules re-export them
for server code; the Coach page checks its scope parameter against the
closed list instead of parsing it. A guard walks each route's static
client graph with the TypeScript parser and fails on a zod import.

Two guards follow earlier commits in this branch: the fetch-limit
allowlist names the shared document picker sheet, and the card density
test states a floor on the cards it finds.
This commit is contained in:
Marc-André Bombeck committed 2026-10-20 14:04:06 +02:00
1 parent 3bae93256d
commit d0677adac9
26 files changed
+421 -190

No files matched your search

+9 -7
View File
@@ -14,7 +14,8 @@ import { useAuth } from "@/hooks/use-auth";
import { useRecordCapabilities } from "@/hooks/use-record-capabilities";
import { queryKeys } from "@/lib/query-keys";
import { apiGet } from "@/lib/api/api-fetch";
import { coachScopeSourceSchema } from "@/lib/ai/coach/types";
import { COACH_SCOPE_SOURCES } from "@/lib/ai/coach/scope-sources";
import type { CoachScopeSource } from "@/lib/ai/coach/types";
/**
* v1.12.0 (Coach v2 #6) — full-page Coach conversation.
@@ -117,12 +118,13 @@ function CoachPageBody() {
// chat (`?doc=`) keeps its own established scope.
const freshChat = deepLinkedId === null && seedDocumentId === null;
const rawScope = freshChat ? searchParams.get("scope") : null;
const scopeResult = rawScope
? coachScopeSourceSchema.safeParse(rawScope)
: null;
const launchScope: CoachLaunchScope | null = scopeResult?.success
? { metric: scopeResult.data }
: null;
// A closed-set check, not a schema parse: the route stays free of the
// schema library for one string comparison.
const launchScope: CoachLaunchScope | null =
rawScope !== null &&
(COACH_SCOPE_SOURCES as readonly string[]).includes(rawScope)
? { metric: rawScope as CoachScopeSource }
: null;
const seedPrefill = freshChat ? searchParams.get("ask") : null;
// Read once: the panel consumes it on mount, then the URL loses it.