create-ailk 0.46.6 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/README.md +180 -43
  2. package/component-catalog.json +223 -285
  3. package/component-catalog.md +1 -1
  4. package/dist/apply-design.d.ts +26 -68
  5. package/dist/apply-design.js +150 -322
  6. package/dist/cli.js +152 -17
  7. package/dist/compare-chrome.d.ts +108 -0
  8. package/dist/compare-chrome.js +481 -0
  9. package/dist/compare-look.d.ts +94 -0
  10. package/dist/compare-look.js +378 -0
  11. package/dist/copy.js +1 -1
  12. package/dist/design-compile.d.ts +17 -21
  13. package/dist/design-compile.js +32 -56
  14. package/dist/design-files.d.ts +93 -0
  15. package/dist/design-files.js +312 -0
  16. package/dist/design-home.d.ts +4 -2
  17. package/dist/design-home.js +88 -6
  18. package/dist/design-names.d.ts +13 -0
  19. package/dist/design-names.js +76 -0
  20. package/dist/design-package.d.ts +46 -56
  21. package/dist/design-package.js +285 -288
  22. package/dist/design-presets.d.ts +41 -0
  23. package/dist/design-presets.js +83 -4
  24. package/dist/design-scaffold.d.ts +12 -2
  25. package/dist/design-scaffold.js +72 -34
  26. package/dist/generated/design-settings.d.ts +56 -0
  27. package/dist/generated/design-settings.js +237 -0
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +2 -2
  30. package/dist/inventory.d.ts +3 -2
  31. package/dist/inventory.js +10 -4
  32. package/dist/lib/design-checks.d.ts +46 -0
  33. package/dist/lib/design-checks.js +79 -1
  34. package/dist/lib/env-catalog.js +5 -1
  35. package/dist/lib/module-license-gate.d.ts +1 -1
  36. package/dist/lib/module-license-gate.js +1 -1
  37. package/dist/lib/render-verdict.d.ts +13 -1
  38. package/dist/lib/render-verdict.js +41 -1
  39. package/dist/look-hub.d.ts +44 -0
  40. package/dist/look-hub.js +130 -0
  41. package/dist/look-record.d.ts +35 -0
  42. package/dist/look-record.js +85 -0
  43. package/dist/look-samples.d.ts +66 -0
  44. package/dist/look-samples.js +456 -0
  45. package/dist/look-settings.d.ts +53 -0
  46. package/dist/look-settings.js +363 -0
  47. package/dist/module-architecture.js +12 -0
  48. package/dist/parse-args.d.ts +10 -6
  49. package/dist/parse-args.js +26 -13
  50. package/dist/programmatic.d.ts +1 -19
  51. package/dist/programmatic.js +65 -103
  52. package/dist/retired-design-bodies.d.ts +29 -0
  53. package/dist/retired-design-bodies.js +51 -0
  54. package/dist/seed-flows.d.ts +1 -1
  55. package/dist/seed-flows.js +12 -14
  56. package/dist/seed-workspace.d.ts +4 -1
  57. package/dist/seed-workspace.js +139 -17
  58. package/dist/site-chrome.d.ts +41 -41
  59. package/dist/site-chrome.js +50 -70
  60. package/dist/site-fonts.d.ts +10 -14
  61. package/dist/site-fonts.js +5 -1
  62. package/dist/starter-grid.d.ts +2 -2
  63. package/dist/strip-look-copies.d.ts +67 -0
  64. package/dist/strip-look-copies.js +591 -0
  65. package/dist/template-manifest.d.ts +6 -14
  66. package/dist/template-manifest.js +0 -9
  67. package/dist/template-record.d.ts +3 -1
  68. package/dist/template-record.js +3 -1
  69. package/dist/topology.d.ts +15 -0
  70. package/dist/topology.js +60 -0
  71. package/dist/update.d.ts +57 -1
  72. package/dist/update.js +742 -13
  73. package/package.json +3 -4
  74. package/site-templates/aliases/hub.TEMPLATE-MANIFEST.json +2 -31
  75. package/site-templates/designs/minimalism/DESIGN.md +163 -297
  76. package/site-templates/designs/minimalism/LOOK.md +42 -0
  77. package/site-templates/designs/minimalism/design.yaml +167 -0
  78. package/site-templates/designs/standard/DESIGN.md +145 -149
  79. package/site-templates/designs/standard/LOOK.md +42 -0
  80. package/site-templates/designs/standard/design.yaml +72 -0
  81. package/site-templates/marketing-site/TEMPLATE-MANIFEST.json +2 -31
  82. package/site-templates/marketing-site/TEMPLATE-MANIFEST.md +1 -25
  83. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.json +2 -31
  84. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.md +1 -25
  85. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.json +2 -31
  86. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.md +1 -25
  87. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.json +2 -31
  88. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.md +1 -25
  89. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.json +2 -31
  90. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.md +1 -25
  91. package/site-templates/shapes/person-service/content/_site.mdx +0 -26
  92. package/templates/.claude/rules/extending.md +3 -2
  93. package/templates/.env.example +11 -4
  94. package/templates/CLAUDE.md +1 -1
  95. package/templates/DESIGN.md +145 -149
  96. package/templates/README.md +15 -16
  97. package/templates/apps/api/.env.example +29 -4
  98. package/templates/apps/api/CLAUDE.md +7 -4
  99. package/templates/apps/api/src/__tests__/vercel-handler.test.ts +176 -2
  100. package/templates/apps/api/src/lib/__mocks__/prisma.ts +30 -4
  101. package/templates/apps/api/src/vercel-handler.ts +32 -2
  102. package/templates/apps/mcp/.env.example +8 -0
  103. package/templates/apps/mcp/CLAUDE.md +5 -3
  104. package/templates/apps/web/.env.example +10 -3
  105. package/templates/apps/web/CLAUDE.md +31 -4
  106. package/templates/apps/web/app/[locale]/layout.tsx +141 -77
  107. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +13 -3
  108. package/templates/apps/web/app/not-found.tsx +11 -11
  109. package/templates/apps/web/auth.ts +48 -35
  110. package/templates/apps/web/jest.config.cjs +5 -0
  111. package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +542 -10
  112. package/templates/apps/web/lib/__tests__/library-fonts.test.ts +35 -0
  113. package/templates/apps/web/lib/__tests__/page-chrome-navigation.test.ts +233 -0
  114. package/templates/apps/web/lib/__tests__/page-chrome.test.ts +123 -26
  115. package/templates/apps/web/lib/__tests__/section-look.test.ts +150 -0
  116. package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +19 -1
  117. package/templates/apps/web/lib/__tests__/site-navigation.test.ts +288 -0
  118. package/templates/apps/web/lib/__tests__/site-theme.test.ts +81 -289
  119. package/templates/apps/web/lib/deck-page.ts +3 -10
  120. package/templates/apps/web/lib/deploy-fonts.ts +12 -0
  121. package/templates/apps/web/lib/hub-site-config.ts +237 -29
  122. package/templates/apps/web/lib/library-fonts.ts +41 -0
  123. package/templates/apps/web/lib/mcp-oauth.ts +11 -4
  124. package/templates/apps/web/lib/page-chrome.ts +105 -20
  125. package/templates/apps/web/lib/section-look.ts +28 -0
  126. package/templates/apps/web/lib/site-design.ts +205 -0
  127. package/templates/apps/web/lib/site-navigation.ts +208 -0
  128. package/templates/apps/web/lib/site-theme-head.ts +98 -13
  129. package/templates/apps/web/lib/site-theme.ts +40 -62
  130. package/templates/apps/web/messages/en.json +0 -6
  131. package/templates/apps/web/next.config.mjs +213 -11
  132. package/templates/apps/web/package.json +2 -0
  133. package/templates/apps/web/site-pages.config.tsx +4 -2
  134. package/templates/content/_site.mdx +0 -26
  135. package/templates/design.yaml +75 -0
  136. package/templates/project.yaml +14 -0
  137. package/versions.json +52 -51
  138. package/site-templates/marketing-site/DESIGN.md +0 -259
  139. package/site-templates/marketing-site-free/DESIGN.md +0 -259
  140. package/site-templates/saas-product/DESIGN.md +0 -259
  141. package/templates/apps/web/lib/__tests__/deck-page.test.ts +0 -288
  142. package/templates/apps/web/lib/__tests__/site-theme-head.test.ts +0 -70
  143. package/templates/apps/web/lib/site-chrome.ts +0 -46
  144. package/templates/apps/web/lib/site-fonts.ts +0 -15
@@ -1,38 +1,88 @@
1
1
  /**
2
2
  * The hub read of the site's identity and seo (#11456, spec
3
- * docs/specs/11456-a-hub-connected-site-reads-spec.md D3).
3
+ * docs/specs/11456-a-hub-connected-site-reads-spec.md D3; #12390, spec
4
+ * docs/specs/12390-a-single-tenant-site-shows-what-its-admin-saves-spec.md
5
+ * D2, D3).
4
6
  *
5
- * A HUB-CONNECTED site — one with a spoke key that would go on the wire
6
- * (`sendsSpokeKey()`), whatever its content adapter (#11515) — reads its
7
- * identity and seo from `GET /v1/content/site-config`, which answers its own
8
- * workspace's rows; a site serving file content with a key reads them too. A
9
- * site with no key makes no call and keeps reading `content/_site.mdx`:
10
- * without a key the route can only answer 401.
7
+ * A HUB-CONNECTED site reads its identity and seo from
8
+ * `GET /v1/content/site-config`, whatever its content adapter (#11515). It is
9
+ * one of two kinds:
10
+ * - a spoke: a spoke key that would go on the wire (`sendsSpokeKey()`); the
11
+ * route answers the key's own workspace;
12
+ * - a single-tenant site: no key, but an API address it names
13
+ * (`apiBaseConfigured()`) over `https:` or loopback (`isSafeTransport`,
14
+ * the key's own transport rule); the route answers the deployment's one
15
+ * workspace, and 401 on a hub, or on a deployment with zero or several
16
+ * workspaces or a sole one that is not the seeded default.
17
+ * A site with neither makes no call and keeps reading `content/_site.mdx`;
18
+ * `getApiBase()`'s `localhost:3001` default is not an address it names.
11
19
  *
12
20
  * Cached with Next's `unstable_cache` under `siteConfigTag()` for at most
13
21
  * `HUB_SITE_REVALIDATE_SECONDS`. The `site-config` revalidate event an Admin
14
22
  * save fires purges the tag (`app/api/revalidate/route.ts`); the expiry is the
15
- * safety net for a spoke with no `revalidateUrl`. The key parts carry a
23
+ * safety net for a site with no revalidate target. The key parts carry a
16
24
  * digest of the spoke key — never the key — so two deployments with different
17
- * keys sharing one data cache never share an entry (SEC-11456-2).
25
+ * keys sharing one data cache never share an entry (SEC-11456-2); a keyless
26
+ * read's part is `keyless:` plus a digest of the API address, so it never
27
+ * shares an entry with a keyed read or a site with another API
28
+ * (SEC-12390-3).
18
29
  *
19
30
  * Inside the cached callback a non-2xx, a throw, a read slower than
20
31
  * `HUB_SITE_TIMEOUT_MS` or a body without the two keys THROWS, so nothing is
21
32
  * written and Next keeps serving the last entry (`page-renderer`'s
22
- * `api-source.ts` failure rule). Outside, a failure answers this instance's
23
- * last good value, else `undefined` — so a hub outage never reaches a page.
24
- * The timeout does not abort the request (`http.ts`'s `get` takes no signal).
33
+ * `api-source.ts` failure rule). One exception: a keyless read the API
34
+ * refuses (401) resolves no rows, so the refusal is cached like a workspace
35
+ * with none and the site renders from its file, with one warn per held
36
+ * answer (SEC-12390-4); a keyed 401 still throws, so a spoke whose key was
37
+ * revoked keeps its last good value. Outside, a failure answers this
38
+ * instance's last good value, else `undefined` — so a hub outage never
39
+ * reaches a page — and a failed keyless read makes this instance wait
40
+ * `HUB_SITE_RETRY_SECONDS` before asking again (SEC-12390-5). The timeout
41
+ * does not abort the request (`http.ts`'s `get` takes no signal).
25
42
  *
26
43
  * One read per request: `readHubSite` is wrapped in React's `cache()`, so
27
44
  * the layout's metadata, its render and every page's JSON-LD share it.
28
45
  *
46
+ * The workspace's site navigation rides the same read (#12401, spec
47
+ * docs/specs/12401-a-site-renders-its-header-spec.md D1): `navigation` is
48
+ * `{ version, record }` when the body carries one `siteNavigationSchema`
49
+ * accepts, else `null` — an absent key (a hub older than #12400), `null`, a
50
+ * version that is not a positive integer or a record the schema refuses, the
51
+ * last two with one warning per distinct refused field path, naming the path
52
+ * and never a value. The schema check is the only barrier between a hub value
53
+ * and a link (`localeHref` passes any scheme through), so only its parsed
54
+ * output is kept. `identity` and `seo` are parsed as before in every case.
55
+ *
56
+ * Words and links only (#12470 D7): before the parse, the three style keys
57
+ * the record held before — `header.style`, `footer.style`, `families` — are
58
+ * removed (`withoutLegacyNavigationStyles`), so a site ahead of its hub
59
+ * still renders that hub's links.
60
+ *
61
+ * The workspace's design record rides the same read too (#12470 D7, D8):
62
+ * `design` is `{ version, record, settings, look }` when the body carries one
63
+ * that parses, else `null`, with the navigation's warning rule. `record` is
64
+ * checked with `siteDesignSchema` — the one schema the route and the tools
65
+ * use — after every top-level member the site does not render is removed (so
66
+ * a hub that adds one, as #12503 will, does not blank an older site's
67
+ * design); `settings` with `designSettingsSchema` and `look` with
68
+ * `siteDesignLookSchema`, each nullable; every level stays strict. Its
69
+ * grammars are what hold a hub value inside its CSS declaration where #12473
70
+ * writes one (SEC-12470-15). Today the site reads only `record.chrome`
71
+ * (`page-chrome.ts`'s `withDesignChrome`).
72
+ *
29
73
  * `site-brand.tsx`, `site-identity.ts`, `site-contact-email.ts` and
30
74
  * `site-contact-lines.ts` import this module; it imports none of them.
31
75
  */
32
76
 
33
77
  import { createHash } from "node:crypto";
34
78
 
35
- import { sendsSpokeKey, siteConfig } from "@working-theory/api-client";
79
+ import {
80
+ apiBaseConfigured,
81
+ getApiBase,
82
+ isSafeTransport,
83
+ sendsSpokeKey,
84
+ siteConfig,
85
+ } from "@working-theory/api-client";
36
86
  import {
37
87
  siteConfigTag,
38
88
  siteWorkspaceSegment,
@@ -43,38 +93,176 @@ import {
43
93
  type SEO,
44
94
  type SiteIdentity,
45
95
  } from "@working-theory/site-config/schema";
96
+ import {
97
+ designSettingsSchema,
98
+ siteDesignLookSchema,
99
+ siteDesignSchema,
100
+ siteDesignVersionSchema,
101
+ siteNavigationSchema,
102
+ siteNavigationVersionSchema,
103
+ withoutLegacyNavigationStyles,
104
+ type DesignSettings,
105
+ type SiteDesign,
106
+ type SiteDesignLook,
107
+ type SiteNavigation,
108
+ } from "@working-theory/validation";
46
109
  import { cache } from "react";
47
110
  import type { ZodType } from "zod";
48
111
 
49
- /** The workspace's identity and seo rows as the site reads them; each `null` when absent or unreadable. */
112
+ /** The workspace's navigation record and the version it was saved at (#12401 D1). */
113
+ export interface HubNavigation {
114
+ version: number;
115
+ record: SiteNavigation;
116
+ }
117
+
118
+ /** The workspace's design record, the version it was saved at, and the settings and look the hub worked out from it (#12470 D8). */
119
+ export interface HubDesign {
120
+ version: number;
121
+ record: SiteDesign;
122
+ settings: DesignSettings | null;
123
+ look: SiteDesignLook | null;
124
+ }
125
+
126
+ /** The workspace's identity, seo, navigation and design rows as the site reads them; each `null` when absent or unreadable. */
50
127
  export interface HubSite {
51
128
  identity: SiteIdentity | null;
52
129
  seo: SEO | null;
130
+ navigation: HubNavigation | null;
131
+ design: HubDesign | null;
53
132
  }
54
133
 
134
+ /**
135
+ * The cache key's shape part, bumped whenever the parsed `HubSite` shape or
136
+ * the schema it is checked with changes, so an entry written by older site
137
+ * code is never served as this shape (#12401 D1).
138
+ */
139
+ const HUB_SITE_SHAPE = "design1";
140
+
55
141
  /** How long one hub read is served before it is read again. */
56
142
  export const HUB_SITE_REVALIDATE_SECONDS = 300;
57
143
  /** A read slower than this is a failed read. */
58
144
  export const HUB_SITE_TIMEOUT_MS = 3_000;
145
+ /** How long an instance waits after a failed keyless read (the discovery reader's hold). */
146
+ export const HUB_SITE_RETRY_SECONDS = 15;
59
147
 
60
148
  /**
61
- * Whether this site reads its identity and seo from the hub: a spoke key on
62
- * the wire, whatever the content adapter (#11515).
149
+ * Whether this site reads its identity and seo from the hub, whatever the
150
+ * content adapter (#11515): a spoke key on the wire, or an API address it
151
+ * names over `https:` or loopback (#12390 D2).
63
152
  */
64
153
  export function hubConnected(): boolean {
65
- return sendsSpokeKey();
154
+ return (
155
+ sendsSpokeKey() || (apiBaseConfigured() && isSafeTransport(getApiBase()))
156
+ );
66
157
  }
67
158
 
68
159
  /** The last value `readHubSite` resolved on this instance. */
69
160
  let held: HubSite | undefined;
161
+ /** Until when this instance makes no keyless read (epoch ms), after one failed. */
162
+ let keylessRetryAt = 0;
70
163
 
71
164
  function parsedOrNull<T>(schema: ZodType<T>, value: unknown): T | null {
72
165
  const parsed = schema.safeParse(value);
73
166
  return parsed.success ? parsed.data : null;
74
167
  }
75
168
 
76
- /** One hub read. Throws on any failure, so the cache writes nothing. */
77
- async function fetchHubSite(): Promise<HubSite> {
169
+ /** The refused navigation and design field paths this process has warned about. */
170
+ const warnedPaths = new Set<string>();
171
+
172
+ /**
173
+ * A refused field's path, with every segment a hub value chose masked — a
174
+ * `byLocale` key, or any segment that is not an index or a plain field name —
175
+ * so it never carries a value.
176
+ */
177
+ function fieldPath(path: readonly PropertyKey[]): string {
178
+ const parts = path.map((part, i) =>
179
+ typeof part === "number" ||
180
+ (typeof part === "string" && /^[A-Za-z]{1,32}$/.test(part) && path[i - 1] !== "byLocale")
181
+ ? String(part)
182
+ : "*",
183
+ );
184
+ return parts.length > 0 ? parts.join(".") : "(record)";
185
+ }
186
+
187
+ function unreadable(member: "navigation" | "design", path: string): null {
188
+ const key = `${member}:${path}`;
189
+ if (!warnedPaths.has(key)) {
190
+ warnedPaths.add(key);
191
+ console.warn(
192
+ `[hub-site-config] ${member} unreadable at ${path}; rendering the site's own ${member === "navigation" ? "navigation" : "look"}`,
193
+ );
194
+ }
195
+ return null;
196
+ }
197
+
198
+ /** The body's `navigation`, parsed, else `null` (#12401 D1). */
199
+ function navigationOrNull(value: unknown): HubNavigation | null {
200
+ if (value === undefined || value === null) return null;
201
+ if (typeof value !== "object" || Array.isArray(value)) {
202
+ return unreadable("navigation", "navigation");
203
+ }
204
+ const { version, record } = value as { version?: unknown; record?: unknown };
205
+ const parsedVersion = siteNavigationVersionSchema.safeParse(version);
206
+ if (!parsedVersion.success) return unreadable("navigation", "version");
207
+ // #12470 D7 — an older hub's record may still carry the three style keys.
208
+ const parsedRecord = siteNavigationSchema.safeParse(withoutLegacyNavigationStyles(record));
209
+ if (!parsedRecord.success) {
210
+ return unreadable("navigation", fieldPath(parsedRecord.error.issues[0]?.path ?? []));
211
+ }
212
+ return { version: parsedVersion.data, record: parsedRecord.data };
213
+ }
214
+
215
+ /** The design record's top-level members this site renders; any other is removed before the strict parse (#12470 D7). */
216
+ const RENDERED_DESIGN_MEMBERS = ["version", "from", "changes", "settings", "chrome", "brand"] as const;
217
+
218
+ /** `record` with only the top-level members the site renders; any other value passes through to the parse. */
219
+ function renderedDesignMembers(record: unknown): unknown {
220
+ if (typeof record !== "object" || record === null || Array.isArray(record)) return record;
221
+ return Object.fromEntries(
222
+ RENDERED_DESIGN_MEMBERS.filter((key) => Object.hasOwn(record, key)).map((key) => [
223
+ key,
224
+ (record as Record<string, unknown>)[key],
225
+ ]),
226
+ );
227
+ }
228
+
229
+ /** The body's `design`, parsed, else `null` (#12470 D8). */
230
+ function designOrNull(value: unknown): HubDesign | null {
231
+ if (value === undefined || value === null) return null;
232
+ if (typeof value !== "object" || Array.isArray(value)) return unreadable("design", "design");
233
+ const { version, record, settings, look } = value as {
234
+ version?: unknown;
235
+ record?: unknown;
236
+ settings?: unknown;
237
+ look?: unknown;
238
+ };
239
+ const parsedVersion = siteDesignVersionSchema.safeParse(version);
240
+ if (!parsedVersion.success) return unreadable("design", "version");
241
+ const parsedRecord = siteDesignSchema.safeParse(renderedDesignMembers(record));
242
+ if (!parsedRecord.success) {
243
+ return unreadable("design", `record.${fieldPath(parsedRecord.error.issues[0]?.path ?? [])}`);
244
+ }
245
+ const parsedSettings = designSettingsSchema.nullable().safeParse(settings ?? null);
246
+ if (!parsedSettings.success) {
247
+ return unreadable("design", `settings.${fieldPath(parsedSettings.error.issues[0]?.path ?? [])}`);
248
+ }
249
+ const parsedLook = siteDesignLookSchema.nullable().safeParse(look ?? null);
250
+ if (!parsedLook.success) {
251
+ return unreadable("design", `look.${fieldPath(parsedLook.error.issues[0]?.path ?? [])}`);
252
+ }
253
+ return {
254
+ version: parsedVersion.data,
255
+ record: parsedRecord.data,
256
+ settings: parsedSettings.data,
257
+ look: parsedLook.data,
258
+ };
259
+ }
260
+
261
+ /**
262
+ * One hub read. Throws on any failure, so the cache writes nothing — except
263
+ * a keyless read's 401, which resolves no rows (#12390 D3).
264
+ */
265
+ async function fetchHubSite(keyed: boolean): Promise<HubSite> {
78
266
  let timer: ReturnType<typeof setTimeout> | undefined;
79
267
  const timeout = new Promise<never>((_resolve, reject) => {
80
268
  timer = setTimeout(
@@ -85,6 +273,12 @@ async function fetchHubSite(): Promise<HubSite> {
85
273
  });
86
274
  try {
87
275
  const res = await Promise.race([siteConfig.get(), timeout]);
276
+ if (!res.ok && res.status === 401 && !keyed) {
277
+ console.warn(
278
+ "[hub-site-config] the API refused a keyless read (401); rendering from content/_site.mdx",
279
+ );
280
+ return { identity: null, seo: null, navigation: null, design: null };
281
+ }
88
282
  if (!res.ok) throw new Error(`hub site-config read answered ${res.status}`);
89
283
  const body: unknown = res.body;
90
284
  if (
@@ -98,22 +292,31 @@ async function fetchHubSite(): Promise<HubSite> {
98
292
  return {
99
293
  identity: parsedOrNull(SiteIdentitySchema, body.identity),
100
294
  seo: parsedOrNull(SEOSchema, body.seo),
295
+ navigation: navigationOrNull("navigation" in body ? body.navigation : undefined),
296
+ design: designOrNull("design" in body ? body.design : undefined),
101
297
  };
102
298
  } finally {
103
299
  clearTimeout(timer);
104
300
  }
105
301
  }
106
302
 
107
- /** The first 16 hex of the spoke key's SHA-256 — a cache-key part, never the key. */
108
- function spokeKeyDigest(): string {
109
- return createHash("sha256")
110
- .update((process.env.AILK_SPOKE_KEY ?? "").trim(), "utf8")
111
- .digest("hex")
112
- .slice(0, 16);
303
+ /** The first 16 hex of a value's SHA-256 — a cache-key part, never the value. */
304
+ function digest16(value: string): string {
305
+ return createHash("sha256").update(value, "utf8").digest("hex").slice(0, 16);
306
+ }
307
+
308
+ /**
309
+ * The cache key's third part: the spoke key's digest for a keyed read, else
310
+ * `keyless:` plus the API address's digest (SEC-12390-3).
311
+ */
312
+ function callerKeyPart(keyed: boolean): string {
313
+ return keyed
314
+ ? digest16((process.env.AILK_SPOKE_KEY ?? "").trim())
315
+ : `keyless:${digest16(getApiBase())}`;
113
316
  }
114
317
 
115
318
  /**
116
- * The hub's identity and seo for this site, or `undefined` when the site is
319
+ * The hub's identity, seo and navigation for this site, or `undefined` when the site is
117
320
  * not hub-connected (no call made) or no read has ever succeeded here.
118
321
  * Never rejects. Shared within one request (React `cache()`).
119
322
  */
@@ -121,17 +324,20 @@ export const readHubSite = cache(async function readHubSite(): Promise<
121
324
  HubSite | undefined
122
325
  > {
123
326
  if (!hubConnected()) return undefined;
327
+ const keyed = sendsSpokeKey();
328
+ if (!keyed && Date.now() < keylessRetryAt) return held;
124
329
  try {
125
330
  // Loaded only on the hub-connected path, so a site that is not one loads
126
331
  // nothing it did not load before.
127
332
  const { unstable_cache } = await import("next/cache");
128
333
  const read = unstable_cache(
129
- fetchHubSite,
130
- ["ailk-hub-site-config", siteWorkspaceSegment(), spokeKeyDigest()],
334
+ () => fetchHubSite(keyed),
335
+ ["ailk-hub-site-config", siteWorkspaceSegment(), callerKeyPart(keyed), HUB_SITE_SHAPE],
131
336
  { tags: [siteConfigTag()], revalidate: HUB_SITE_REVALIDATE_SECONDS },
132
337
  );
133
338
  held = await read();
134
339
  } catch (err) {
340
+ if (!keyed) keylessRetryAt = Date.now() + HUB_SITE_RETRY_SECONDS * 1_000;
135
341
  console.warn(
136
342
  `[hub-site-config] read failed (${err instanceof Error ? err.name : typeof err}); serving the last good value`,
137
343
  );
@@ -148,7 +354,9 @@ export function heldHubSite(): HubSite | undefined {
148
354
  return hubConnected() ? held : undefined;
149
355
  }
150
356
 
151
- /** Test seam: forget the held value. */
357
+ /** Test seam: forget the held value, any keyless wait and the navigation warnings. */
152
358
  export function __resetHubSiteForTests(): void {
153
359
  held = undefined;
360
+ keylessRetryAt = 0;
361
+ warnedPaths.clear();
154
362
  }
@@ -0,0 +1,41 @@
1
+ // library-fonts.ts — the design library's faces, built into every site
2
+ // (#12473 D6, spec docs/specs/12473-a-site-renders-its-colours-spec.md).
3
+ //
4
+ // Hand-written, not generated: one `next/font/local` call per entry of
5
+ // `LIBRARY_FONTS` (@working-theory/theme), each a literal `src` into the
6
+ // face's installed `@fontsource-variable/<slug>` latin variable file, so a
7
+ // build never reaches Google. Every face's `@font-face` rule is in the built
8
+ // stylesheet; none is preloaded, so a browser downloads one only when an
9
+ // element uses its family. The hub design record chooses which face
10
+ // `--font-display` / `--font-body` name, per request, with no build.
11
+ //
12
+ // The locale layout imports this module, so every page's stylesheet carries
13
+ // the rules. A test holds `LIBRARY_FACES`' families equal to `LIBRARY_FONTS`'.
14
+
15
+ import localFont from "next/font/local";
16
+
17
+ /** A built face: the CSS variable its family is read through, and the class that declares it. */
18
+ export interface BuiltFace {
19
+ variable: string;
20
+ className: string;
21
+ }
22
+
23
+ const figtree = localFont({
24
+ src: "../node_modules/@fontsource-variable/figtree/files/figtree-latin-wght-normal.woff2",
25
+ variable: "--font-lib-figtree",
26
+ display: "swap",
27
+ preload: false,
28
+ });
29
+
30
+ const newsreader = localFont({
31
+ src: "../node_modules/@fontsource-variable/newsreader/files/newsreader-latin-wght-normal.woff2",
32
+ variable: "--font-lib-newsreader",
33
+ display: "swap",
34
+ preload: false,
35
+ });
36
+
37
+ /** The library's built faces, by family. */
38
+ export const LIBRARY_FACES: ReadonlyMap<string, BuiltFace> = new Map([
39
+ ["Figtree", { variable: "--font-lib-figtree", className: figtree.variable }],
40
+ ["Newsreader", { variable: "--font-lib-newsreader", className: newsreader.variable }],
41
+ ]);
@@ -35,12 +35,14 @@ import { createHash, timingSafeEqual } from "node:crypto";
35
35
 
36
36
  import {
37
37
  ALL_WORKSPACES_SCOPE,
38
+ DEFAULT_MCP_SCOPES,
38
39
  ISSUER_SCOPE_PREFIX,
39
40
  lowerRole,
40
41
  MCP_SCOPES,
41
42
  type McpScope,
42
43
  type MembershipRole,
43
44
  grantsForWorkspace,
45
+ offerableScopes,
44
46
  parseGrantedScopes,
45
47
  scopesForRole,
46
48
  tokenIssuedBy,
@@ -310,10 +312,14 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
310
312
  return value;
311
313
  }
312
314
 
313
- /** Each workspace with the scopes the request may approve there. */
315
+ /**
316
+ * Each workspace with the scopes the request may approve there: the scopes
317
+ * the client named, else `DEFAULT_MCP_SCOPES`, so an opt-in scope is offered
318
+ * only to a client that asks for it by name (#12470 D3, SEC-12470-1).
319
+ */
314
320
  async function offeredWorkspaces(userId: string, requested: string[]) {
315
321
  const asked = requested.filter((s): s is McpScope => (MCP_SCOPES as readonly string[]).includes(s));
316
- const pool = asked.length > 0 ? asked : [...MCP_SCOPES];
322
+ const pool = offerableScopes(asked);
317
323
  const memberships = await deps.readMemberships(userId);
318
324
  return memberships.map((m) => {
319
325
  const allowed = new Set(scopesForRole(m.role));
@@ -379,14 +385,15 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
379
385
 
380
386
  /**
381
387
  * The all-workspaces consent's union (#11607 D1a): every workspace, and the
382
- * requested scopes any of the person's roles may approve, in `MCP_SCOPES` order.
388
+ * requested scopes any of the person's roles may approve, in `MCP_SCOPES`
389
+ * order — never an opt-in one, even when named (#12470 D3).
383
390
  */
384
391
  async function offeredReach(userId: string, requested: string[]) {
385
392
  const workspaces = await offeredWorkspaces(userId, requested);
386
393
  const union = new Set(workspaces.flatMap((w) => w.offered));
387
394
  return {
388
395
  workspaces: workspaces.map(({ id, name, organizationName, role }) => ({ id, name, organizationName, role })),
389
- offered: MCP_SCOPES.filter((s) => union.has(s)),
396
+ offered: DEFAULT_MCP_SCOPES.filter((s) => union.has(s)),
390
397
  };
391
398
  }
392
399
 
@@ -5,9 +5,9 @@
5
5
  * Four levels, most specific first: the page's own frontmatter (`header:`,
6
6
  * `footer:`, `layout:`), its route family's key in `_site.mdx` (`blog:`,
7
7
  * `docs:`, …), the site defaults in `_site.mdx` (`header.style`,
8
- * `footer.style`, `layout`), and last the design's own knobs in the
9
- * generated `site-chrome.ts`. A site that sets nothing resolves to exactly
10
- * the chrome the design gave it before this file existed.
8
+ * `footer.style`, `layout`), and last the design's own knobs — the hub design
9
+ * record's layout, else `BASE_SITE_LAYOUT` (#12477 D1). A site that sets
10
+ * nothing resolves to exactly the chrome its look gives it.
11
11
  *
12
12
  * Blog posts and docs pages are served by the docs-blog slice, which this
13
13
  * base file must never import, so they take their `blog:` / `docs:` family
@@ -38,6 +38,7 @@ import {
38
38
  type SiteLayout,
39
39
  } from "@working-theory/site-config/schema";
40
40
  import { conventionPath, ROUTES } from "@working-theory/templates/routes";
41
+ import type { SiteDesignChrome, SiteNavigation } from "@working-theory/validation";
41
42
  import { readLocales } from "@working-theory/web-i18n";
42
43
  import { cache } from "react";
43
44
  import { parse as parseYaml } from "yaml";
@@ -51,8 +52,11 @@ import {
51
52
  resolveTypeAndSlug,
52
53
  } from "./deck-page";
53
54
  import { toInternalDocsPath } from "./docs-path";
55
+ import { readHubSite } from "./hub-site-config";
54
56
  import { SERVICES_ROUTE, toInternalServicesPath } from "./services-path";
55
57
  import { resolveContentRoot } from "./site-brand";
58
+ import { readSiteDesign, type SiteLayoutKnobs } from "./site-design";
59
+ import { safeNavigationChrome, type NavigationChrome } from "./site-navigation";
56
60
 
57
61
  /** The chrome settings a site sets in `_site.mdx`. */
58
62
  export interface SiteChromeSettings {
@@ -70,13 +74,13 @@ export interface PageChromeFields {
70
74
  }
71
75
 
72
76
  /**
73
- * The design knobs the template level reads — a structural slice of the
74
- * generated `SiteChrome`, so a scaffold generated before `innerPages` or
75
- * `chromeStyle` existed still compiles.
77
+ * The design knobs the template level reads — a structural slice of
78
+ * `SiteLayoutKnobs` (`lib/site-design.ts`).
76
79
  */
77
80
  export interface ChromeKnobs {
81
+ nav: HeaderStyle;
78
82
  home: SiteLayout;
79
- footer: "columns" | "centered";
83
+ footer: FooterStyle;
80
84
  innerPages?: "bare";
81
85
  chromeStyle?: "minimal";
82
86
  }
@@ -167,6 +171,61 @@ export const readSiteChromeSettings = cache(
167
171
  },
168
172
  );
169
173
 
174
+ /**
175
+ * The file settings with the hub design record's `chrome` laid over them
176
+ * (#12470 D7, after #12401 D4): the record's header and footer style, and each
177
+ * route family's `header` and `footer`, win where the record sets them; every
178
+ * other value — the layout, a family's `path` — is the file's. Returns new
179
+ * objects and never changes `site`, which `readSiteChromeSettings` shares
180
+ * across the request.
181
+ */
182
+ export function withDesignChrome(
183
+ site: SiteChromeSettings,
184
+ chrome: SiteDesignChrome | undefined,
185
+ ): SiteChromeSettings {
186
+ if (chrome === undefined) return site;
187
+ const families: SiteChromeSettings["families"] = { ...site.families };
188
+ for (const key of ROUTE_FAMILY_KEYS) {
189
+ const styles = chrome.families?.[key];
190
+ if (styles?.header === undefined && styles?.footer === undefined) continue;
191
+ families[key] = {
192
+ ...site.families[key],
193
+ ...(styles.header !== undefined ? { header: styles.header } : {}),
194
+ ...(styles.footer !== undefined ? { footer: styles.footer } : {}),
195
+ };
196
+ }
197
+ const headerStyle = chrome.header ?? site.headerStyle;
198
+ const footerStyle = chrome.footer ?? site.footerStyle;
199
+ return {
200
+ ...site,
201
+ ...(headerStyle !== undefined ? { headerStyle } : {}),
202
+ ...(footerStyle !== undefined ? { footerStyle } : {}),
203
+ families,
204
+ };
205
+ }
206
+
207
+ /** The hub navigation record a page renders, with its translation (#12401 D3). */
208
+ export interface RecordNavigation {
209
+ version: number;
210
+ record: SiteNavigation;
211
+ chrome: NavigationChrome;
212
+ }
213
+
214
+ /**
215
+ * The hub navigation record this request renders for `locale`, with its
216
+ * translation (#12401 D3, D4) — `null` when the hub read carries none or the
217
+ * translator refuses it. `resolveHomeChrome` answers it, so the record's
218
+ * styles apply exactly when its links render.
219
+ */
220
+ const readRecordNavigation = cache(async function readRecordNavigation(
221
+ locale: string,
222
+ ): Promise<RecordNavigation | null> {
223
+ const navigation = (await readHubSite())?.navigation ?? null;
224
+ if (navigation === null) return null;
225
+ const chrome = safeNavigationChrome(navigation.record, locale);
226
+ return chrome === null ? null : { version: navigation.version, record: navigation.record, chrome };
227
+ });
228
+
170
229
  /** The closing footer's site settings (#10550 D3). */
171
230
  export interface ClosingFooterSettings {
172
231
  locality?: string;
@@ -362,16 +421,19 @@ export interface PageChromeInput {
362
421
 
363
422
  export interface ResolvedChrome {
364
423
  header: HeaderStyle;
365
- /** No page, family or site value set the header — the design's own treatment applies. */
366
- headerFromTemplate: boolean;
367
424
  /** `line` is the design's one-bar footer on a bare inner page; never a site value. */
368
425
  footer: FooterStyle | "line";
369
426
  }
370
427
 
371
- /** The design's own header and footer for a page (#10049 D3's template table). */
428
+ /**
429
+ * The design's own header and footer for a page (#10049 D3's template table).
430
+ * Where the table gives the design's own bar, it is the look's `nav` (#12470
431
+ * D7), so `mark-only` means the same whether a look, a site, a page or the
432
+ * design record sets it.
433
+ */
372
434
  function templateChrome(
373
435
  input: PageChromeInput,
374
- ): Pick<ResolvedChrome, "header" | "footer"> {
436
+ ): ResolvedChrome {
375
437
  const { chrome } = input;
376
438
  if (input.isHome) {
377
439
  if (input.homeIsDeck && chrome.home === "deck") {
@@ -380,39 +442,63 @@ function templateChrome(
380
442
  footer: chrome.chromeStyle === "minimal" ? "closing" : chrome.footer,
381
443
  };
382
444
  }
383
- return { header: "full", footer: chrome.footer };
445
+ return { header: chrome.nav, footer: chrome.footer };
384
446
  }
385
447
  if (input.closingListed) {
386
448
  return {
387
- header: chrome.innerPages === "bare" ? "bare" : "full",
449
+ header: chrome.innerPages === "bare" ? "bare" : chrome.nav,
388
450
  footer: "closing",
389
451
  };
390
452
  }
391
453
  if (chrome.innerPages === "bare") return { header: "bare", footer: "line" };
392
- return { header: "full", footer: chrome.footer };
454
+ return { header: chrome.nav, footer: chrome.footer };
393
455
  }
394
456
 
395
457
  /**
396
458
  * The home's layout and chrome — the one resolution both the layout and the
397
- * home page read, so the bar and the landing can never disagree.
459
+ * home page read, so the bar and the landing can never disagree. The site
460
+ * settings are `_site.mdx`'s with the hub design record's `chrome` over them
461
+ * (#12470 D7) — whenever the hub read carries a design record, whether or not
462
+ * a navigation record renders: style no longer belongs to the navigation.
463
+ * `navigation` is the rendered navigation record, for the layout.
464
+ *
465
+ * #12473 D4 — the design knobs are the hub design record's layout when it
466
+ * carries one, else `chrome` — the callers' `BASE_SITE_LAYOUT` (#12477 D1);
467
+ * `knobs` answers the record's alone, absent with no record, for the home
468
+ * page's deck knobs.
398
469
  */
399
470
  export async function resolveHomeChrome(
400
471
  locale: string,
401
472
  chrome: ChromeKnobs,
402
- ): Promise<{ layout: SiteLayout; chrome: ResolvedChrome; site: SiteChromeSettings }> {
403
- const site = readSiteChromeSettings();
473
+ ): Promise<{
474
+ layout: SiteLayout;
475
+ chrome: ResolvedChrome;
476
+ site: SiteChromeSettings;
477
+ navigation: RecordNavigation | null;
478
+ knobs?: SiteLayoutKnobs;
479
+ }> {
480
+ const [navigation, hub, design] = await Promise.all([
481
+ readRecordNavigation(locale),
482
+ readHubSite(),
483
+ readSiteDesign(),
484
+ ]);
485
+ const knobs = design?.layout;
486
+ const designKnobs = knobs ?? chrome;
487
+ const site = withDesignChrome(readSiteChromeSettings(), hub?.design?.record.chrome);
404
488
  const page = await resolveChromePage("/", locale);
405
- const layout = resolveHomeLayout(site, page, chrome);
489
+ const layout = resolveHomeLayout(site, page, designKnobs);
406
490
  return {
407
491
  layout,
408
492
  site,
493
+ navigation,
494
+ ...(knobs !== undefined && { knobs }),
409
495
  chrome: resolvePageChrome({
410
496
  isHome: true,
411
497
  homeIsDeck: layout === "deck",
412
498
  family: null,
413
499
  page,
414
500
  site,
415
- chrome,
501
+ chrome: designKnobs,
416
502
  closingListed: false,
417
503
  }),
418
504
  };
@@ -427,7 +513,6 @@ export function resolvePageChrome(input: PageChromeInput): ResolvedChrome {
427
513
  const footer = input.page.footer ?? family?.footer ?? input.site.footerStyle;
428
514
  return {
429
515
  header: header ?? template.header,
430
- headerFromTemplate: header === undefined,
431
516
  footer: footer ?? template.footer,
432
517
  };
433
518
  }