@nifrajs/cli 5.1.0 → 5.2.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 (201) hide show
  1. package/CHANGELOG.md +3211 -0
  2. package/README.md +3 -0
  3. package/dist/agent-files.d.ts +19 -11
  4. package/dist/agent-files.d.ts.map +1 -1
  5. package/dist/agent-files.js +26 -18
  6. package/dist/agent-files.js.map +1 -1
  7. package/dist/assure-hydration.d.ts.map +1 -1
  8. package/dist/assure-hydration.js +1 -0
  9. package/dist/assure-hydration.js.map +1 -1
  10. package/dist/assure.d.ts.map +1 -1
  11. package/dist/assure.js +14 -1
  12. package/dist/assure.js.map +1 -1
  13. package/dist/capabilities-tool.d.ts.map +1 -1
  14. package/dist/capabilities-tool.js +131 -45
  15. package/dist/capabilities-tool.js.map +1 -1
  16. package/dist/check-diagnostics.d.ts +5 -0
  17. package/dist/check-diagnostics.d.ts.map +1 -1
  18. package/dist/check-diagnostics.js +3 -0
  19. package/dist/check-diagnostics.js.map +1 -1
  20. package/dist/check-scan.d.ts.map +1 -1
  21. package/dist/check-scan.js +6 -3
  22. package/dist/check-scan.js.map +1 -1
  23. package/dist/check.d.ts.map +1 -1
  24. package/dist/check.js +52 -12
  25. package/dist/check.js.map +1 -1
  26. package/dist/cli.d.ts.map +1 -1
  27. package/dist/cli.js +23 -12
  28. package/dist/cli.js.map +1 -1
  29. package/dist/command-catalog.d.ts.map +1 -1
  30. package/dist/command-catalog.js +9 -5
  31. package/dist/command-catalog.js.map +1 -1
  32. package/dist/dev-bun-config.d.ts +6 -3
  33. package/dist/dev-bun-config.d.ts.map +1 -1
  34. package/dist/dev-bun-config.js +13 -10
  35. package/dist/dev-bun-config.js.map +1 -1
  36. package/dist/dev-feed-tool.d.ts +3 -2
  37. package/dist/dev-feed-tool.d.ts.map +1 -1
  38. package/dist/dev-feed-tool.js +26 -5
  39. package/dist/dev-feed-tool.js.map +1 -1
  40. package/dist/doctor.d.ts +15 -1
  41. package/dist/doctor.d.ts.map +1 -1
  42. package/dist/doctor.js +79 -61
  43. package/dist/doctor.js.map +1 -1
  44. package/dist/i18n-check.d.ts +11 -1
  45. package/dist/i18n-check.d.ts.map +1 -1
  46. package/dist/i18n-check.js +170 -17
  47. package/dist/i18n-check.js.map +1 -1
  48. package/dist/init-agents.d.ts +46 -6
  49. package/dist/init-agents.d.ts.map +1 -1
  50. package/dist/init-agents.js +193 -31
  51. package/dist/init-agents.js.map +1 -1
  52. package/dist/internal/project-specifiers.d.ts.map +1 -1
  53. package/dist/internal/project-specifiers.js +9 -1
  54. package/dist/internal/project-specifiers.js.map +1 -1
  55. package/dist/internal/source-facts.d.ts +6 -0
  56. package/dist/internal/source-facts.d.ts.map +1 -1
  57. package/dist/internal/source-facts.js +106 -0
  58. package/dist/internal/source-facts.js.map +1 -1
  59. package/dist/internal/workspace-packages.d.ts +22 -0
  60. package/dist/internal/workspace-packages.d.ts.map +1 -0
  61. package/dist/internal/workspace-packages.js +215 -0
  62. package/dist/internal/workspace-packages.js.map +1 -0
  63. package/dist/load.d.ts +7 -2
  64. package/dist/load.d.ts.map +1 -1
  65. package/dist/load.js +11 -2
  66. package/dist/load.js.map +1 -1
  67. package/dist/lock-links.d.ts +42 -0
  68. package/dist/lock-links.d.ts.map +1 -0
  69. package/dist/lock-links.js +144 -0
  70. package/dist/lock-links.js.map +1 -0
  71. package/dist/mcp-exec.d.ts.map +1 -1
  72. package/dist/mcp-exec.js +5 -2
  73. package/dist/mcp-exec.js.map +1 -1
  74. package/dist/mcp-http.js +1 -1
  75. package/dist/mcp-root.d.ts +6 -4
  76. package/dist/mcp-root.d.ts.map +1 -1
  77. package/dist/mcp-root.js +12 -8
  78. package/dist/mcp-root.js.map +1 -1
  79. package/dist/migrate-layout.d.ts +2 -1
  80. package/dist/migrate-layout.d.ts.map +1 -1
  81. package/dist/migrate-layout.js +434 -29
  82. package/dist/migrate-layout.js.map +1 -1
  83. package/dist/project-site.d.ts +7 -0
  84. package/dist/project-site.d.ts.map +1 -0
  85. package/dist/project-site.js +19 -0
  86. package/dist/project-site.js.map +1 -0
  87. package/dist/recipes/4.0.0.d.ts.map +1 -1
  88. package/dist/recipes/4.0.0.js +2 -0
  89. package/dist/recipes/4.0.0.js.map +1 -1
  90. package/dist/recipes/5.1.0.d.ts +9 -0
  91. package/dist/recipes/5.1.0.d.ts.map +1 -0
  92. package/dist/recipes/5.1.0.js +22 -0
  93. package/dist/recipes/5.1.0.js.map +1 -0
  94. package/dist/recipes/5.2.0.d.ts +10 -0
  95. package/dist/recipes/5.2.0.d.ts.map +1 -0
  96. package/dist/recipes/5.2.0.js +32 -0
  97. package/dist/recipes/5.2.0.js.map +1 -0
  98. package/dist/recipes/index.d.ts +3 -0
  99. package/dist/recipes/index.d.ts.map +1 -1
  100. package/dist/recipes/index.js +7 -0
  101. package/dist/recipes/index.js.map +1 -1
  102. package/dist/review.d.ts.map +1 -1
  103. package/dist/review.js +2 -0
  104. package/dist/review.js.map +1 -1
  105. package/dist/rule-explain.d.ts +26 -0
  106. package/dist/rule-explain.d.ts.map +1 -0
  107. package/dist/rule-explain.js +49 -0
  108. package/dist/rule-explain.js.map +1 -0
  109. package/dist/rules/codes.d.ts +2 -0
  110. package/dist/rules/codes.d.ts.map +1 -1
  111. package/dist/rules/codes.js +2 -0
  112. package/dist/rules/codes.js.map +1 -1
  113. package/dist/rules/contract-visibility.d.ts.map +1 -1
  114. package/dist/rules/contract-visibility.js +93 -21
  115. package/dist/rules/contract-visibility.js.map +1 -1
  116. package/dist/rules/explanations.d.ts +14 -0
  117. package/dist/rules/explanations.d.ts.map +1 -0
  118. package/dist/rules/explanations.js +316 -0
  119. package/dist/rules/explanations.js.map +1 -0
  120. package/dist/rules/legacy.d.ts.map +1 -1
  121. package/dist/rules/legacy.js +24 -1
  122. package/dist/rules/legacy.js.map +1 -1
  123. package/dist/rules/merge-auth.d.ts +12 -0
  124. package/dist/rules/merge-auth.d.ts.map +1 -0
  125. package/dist/rules/merge-auth.js +52 -0
  126. package/dist/rules/merge-auth.js.map +1 -0
  127. package/dist/rules/pages.d.ts +27 -0
  128. package/dist/rules/pages.d.ts.map +1 -1
  129. package/dist/rules/pages.js +177 -2
  130. package/dist/rules/pages.js.map +1 -1
  131. package/dist/rules/routes.d.ts +3 -2
  132. package/dist/rules/routes.d.ts.map +1 -1
  133. package/dist/rules/routes.js +4 -3
  134. package/dist/rules/routes.js.map +1 -1
  135. package/dist/rules/zones.d.ts.map +1 -1
  136. package/dist/rules/zones.js +3 -2
  137. package/dist/rules/zones.js.map +1 -1
  138. package/dist/typecheck-coverage.d.ts +11 -0
  139. package/dist/typecheck-coverage.d.ts.map +1 -1
  140. package/dist/typecheck-coverage.js +50 -7
  141. package/dist/typecheck-coverage.js.map +1 -1
  142. package/dist/upgrade.d.ts +37 -1
  143. package/dist/upgrade.d.ts.map +1 -1
  144. package/dist/upgrade.js +171 -20
  145. package/dist/upgrade.js.map +1 -1
  146. package/dist/verification-plan.d.ts.map +1 -1
  147. package/dist/verification-plan.js +2 -0
  148. package/dist/verification-plan.js.map +1 -1
  149. package/dist/version-drift.d.ts.map +1 -1
  150. package/dist/version-drift.js +12 -1
  151. package/dist/version-drift.js.map +1 -1
  152. package/dist/web-app-options.d.ts +1 -1
  153. package/dist/web-app-options.d.ts.map +1 -1
  154. package/dist/web-app-options.js.map +1 -1
  155. package/docs/examples.json +19 -1
  156. package/docs/llms-full.txt +625 -130
  157. package/docs/types.json +396 -50
  158. package/package.json +13 -12
  159. package/src/agent-files.ts +27 -17
  160. package/src/assure-hydration.ts +1 -0
  161. package/src/assure.ts +11 -1
  162. package/src/capabilities-tool.ts +159 -50
  163. package/src/check-diagnostics.ts +8 -0
  164. package/src/check-scan.ts +9 -3
  165. package/src/check.ts +67 -12
  166. package/src/cli.ts +24 -11
  167. package/src/command-catalog.ts +16 -8
  168. package/src/dev-bun-config.ts +13 -9
  169. package/src/dev-feed-tool.ts +40 -6
  170. package/src/doctor.ts +102 -66
  171. package/src/i18n-check.ts +254 -18
  172. package/src/init-agents.ts +221 -41
  173. package/src/internal/project-specifiers.ts +9 -1
  174. package/src/internal/source-facts.ts +124 -0
  175. package/src/internal/workspace-packages.ts +218 -0
  176. package/src/load.ts +19 -3
  177. package/src/lock-links.ts +173 -0
  178. package/src/mcp-exec.ts +5 -2
  179. package/src/mcp-http.ts +1 -1
  180. package/src/mcp-root.ts +14 -8
  181. package/src/migrate-layout.ts +495 -31
  182. package/src/project-site.ts +18 -0
  183. package/src/recipes/4.0.0.ts +2 -0
  184. package/src/recipes/5.1.0.ts +23 -0
  185. package/src/recipes/5.2.0.ts +33 -0
  186. package/src/recipes/index.ts +7 -0
  187. package/src/review.ts +2 -0
  188. package/src/rule-explain.ts +75 -0
  189. package/src/rules/codes.ts +2 -0
  190. package/src/rules/contract-visibility.ts +118 -20
  191. package/src/rules/explanations.ts +329 -0
  192. package/src/rules/legacy.ts +24 -1
  193. package/src/rules/merge-auth.ts +55 -0
  194. package/src/rules/pages.ts +221 -2
  195. package/src/rules/routes.ts +4 -3
  196. package/src/rules/zones.ts +3 -2
  197. package/src/typecheck-coverage.ts +51 -6
  198. package/src/upgrade.ts +227 -22
  199. package/src/verification-plan.ts +6 -0
  200. package/src/version-drift.ts +15 -0
  201. package/src/web-app-options.ts +9 -1
@@ -575,7 +575,7 @@ hydrates that, then renders the component with the data it already has. A client
575
575
  to the page renders the component directly. For a component that reads `window`,
576
576
  a canvas, or a browser-only library while it renders.
577
577
 
578
- ```ts
578
+ ```tsx
579
579
  // routes/map.tsx - a page whose component needs a browser to render.
580
580
  import type { Route } from "./+types/map"
581
581
 
@@ -611,12 +611,12 @@ combined with `hydrate = false`: nothing would ever render the page.
611
611
  Export a `searchSchema` - any Standard Schema (valibot, zod, arktype) - and the URL
612
612
  query becomes typed and validated on both sides: the loader receives it as
613
613
  `ctx.search` and the component reads the same value with
614
- `useSearch()`. Invalid or hostile input fails closed to the
614
+ `useSearch<typeof searchSchema>()`. Invalid or hostile input fails closed to the
615
615
  schema's defaults (never a 500), and the value is derived identically on the server and on each
616
616
  client navigation - so a query-reading page hydrates with no mismatch and never touches
617
617
  `window.location.search` by hand.
618
618
 
619
- ```ts
619
+ ```tsx
620
620
  // routes/reports.tsx - a typed, validated ?page=&sort= query.
621
621
  import { useSearch } from "@nifrajs/web-react/router"
622
622
  import * as v from "valibot" // any Standard Schema works (valibot, zod, arktype)
@@ -645,7 +645,7 @@ export async function loader({ search, api }: Route.LoaderArgs) {
645
645
  ```
646
646
 
647
647
  Without a `searchSchema`, `ctx.search` and `useSearch()` are
648
- the raw parsed query (`Record`). `useSearch` ships on
648
+ the raw parsed query (`Record<string, unknown>`). `useSearch` ships on
649
649
  every adapter (React, Preact, Vue, Solid, Svelte), each in that framework's shape - a value on
650
650
  React/Preact, a `Ref` on Vue, an accessor on Solid/Svelte. For imperative reads and
651
651
  writes of the raw query, `useSearchParams()` mirrors react-router's
@@ -679,7 +679,7 @@ around it (the nearest one wins), says when:
679
679
  -
680
680
  `none`: never; the route loads when the link is followed.
681
681
 
682
- ```ts
682
+ ```tsx
683
683
  // A docs sidebar: each link loads as it scrolls into view.
684
684
  <nav data-nifra-prefetch="viewport">
685
685
  <a href="/docs/routing">Routing</a>
@@ -712,7 +712,7 @@ query), `params` the ones it declares, and `data` its loader data (`null` withou
712
712
  can therefore build breadcrumbs, a title, or a section nav from what the routes below it
713
713
  export.
714
714
 
715
- ```ts
715
+ ```tsx
716
716
  // routes/orgs/[org]/_layout.tsx
717
717
  import type { ReactNode } from "react"
718
718
  import { useMatches } from "@nifrajs/web-react/router"
@@ -757,7 +757,7 @@ call `proceed()` to continue or `reset()` to stay. It mirrors
757
757
  react-router's shape - a plain boolean can't express an async "are you sure?", these two
758
758
  callbacks can.
759
759
 
760
- ```ts
760
+ ```tsx
761
761
  // routes/posts/[id]/edit.tsx - don't lose a half-finished edit to a stray click.
762
762
  import { useState } from "react"
763
763
  import { useBlocker } from "@nifrajs/web-react/router"
@@ -873,9 +873,9 @@ answers `422`.
873
873
  `GET /users/:id?` throws at registration, because both serve
874
874
  `GET /users`. Nothing of a rejected route is left registered.
875
875
 
876
- Other param modifiers (`:id+`, `:id*`, `:id(\\d+)`) are not
876
+ Other param modifiers (`:id+`, `:id*`, `:id(\d+)`) are not
877
877
  part of the path grammar and match as literal text. Where that text is intended, put
878
- `// nifra-expect NF-C026: ` above the registration.
878
+ `// nifra-expect NF-C026: <reason>` above the registration.
879
879
 
880
880
  ### Param constraints
881
881
 
@@ -902,10 +902,10 @@ A constraint is one of two things:
902
902
 
903
903
  -
904
904
  **One character class, with an optional count.** `[0-9]`,
905
- `[a-z0-9_-]`, `\\d` or `\\w`, followed by nothing
905
+ `[a-z0-9_-]`, `\d` or `\w`, followed by nothing
906
906
  (exactly one character), `+`, `{n}`, `{n,}` or
907
- `{n,m}`. A class holds letters, digits, ranges of them, `\\d`,
908
- `\\w` and the characters `. _ ~ ! $ & ' ( ) + , ; = @ -`. There
907
+ `{n,m}`. A class holds letters, digits, ranges of them, `\d`,
908
+ `\w` and the characters `. _ ~ ! $ & ' ( ) + , ; = @ -`. There
909
909
  is no negated class, and a count starts at one.
910
910
 
911
911
  -
@@ -916,7 +916,7 @@ is no negated class, and a count starts at one.
916
916
  Anything else in braces (`:id{int}`, `:id{[0-9]+|[a-z]+}`,
917
917
  `:id{.+}`) is not a constraint. It is literal text, as before, and
918
918
  `nifra check` reports it as `NF-C026`. In a JavaScript string
919
- `\\d` is written `{'"\\\\d"'}`.
919
+ `\d` is written `"\\d"`.
920
920
 
921
921
  -
922
922
  **The value is checked as it was sent,** before percent-decoding. `/users/4%32`
@@ -938,7 +938,7 @@ the same rule a literal route follows beside a param route.
938
938
 
939
939
  -
940
940
  **Two spellings of one constraint are one route.** `:id{[0-9]+}`,
941
- `:id{\\d+}` and `:id{[0-9]{1,}}` accept the same values, so
941
+ `:id{\d+}` and `:id{[0-9]{1,}}` accept the same values, so
942
942
  registering two of them for one method throws `DUPLICATE_ROUTE`, and different
943
943
  methods on them share one `Allow` list.
944
944
 
@@ -953,14 +953,14 @@ not look for another split.
953
953
  `/users/:id{[0-9]+}` serve no request in common, so `nifra check`
954
954
  (`NF-C024`) has nothing to report. A constrained route beside a bare
955
955
  `:param` route still overlaps and is still reported; mark the pair with
956
- `// nifra-expect NF-C024: ` where it is intended.
956
+ `// nifra-expect NF-C024: <reason>` where it is intended.
957
957
 
958
958
  -
959
959
  **OpenAPI and the typed client use the bare name.** The path is
960
960
  `/users/{id}`; the parameter's schema is
961
- `{'{ type: "string", pattern: "^[0-9]+$" }'}` for a class and an `enum`
961
+ `{ type: "string", pattern: "^[0-9]+$" }` for a class and an `enum`
962
962
  for a list, unless the route declares a `params` schema. The client call is
963
- `{'api.users({ id: "42" }).get()'}`. The client does not check the value: a value
963
+ `api.users({ id: "42" }).get()`. The client does not check the value: a value
964
964
  that does not fit is sent, and answered by whichever route it does match. Where two param
965
965
  routes share a position, give their params different names so that the call picks the route
966
966
  by name.
@@ -1052,8 +1052,11 @@ export const app = server()
1052
1052
 
1053
1053
  Prefer `c.set` over returning a raw `Response`. A `Response`
1054
1054
  return makes the typed client infer `data: never`, so you silently lose drift
1055
- detection for that route (`nifra check` flags it). `c.set` keeps your
1056
- plain-object return fully typed.
1055
+ detection for that route (`nifra check` flags it, NF-C007). `c.set`
1056
+ keeps your plain-object return fully typed. The check reads the functions a route
1057
+ registration or an `implement()` map passes, and a local function one returns a
1058
+ call to; a helper that answers an auth stage, or a handler registered from a list of route
1059
+ objects, is not read.
1057
1060
 
1058
1061
  A `Response` a handler or hook returns or throws still gets the
1059
1062
  `c.set.headers` it lacks and the queued cookies, so a guard's
@@ -1145,6 +1148,37 @@ A strict `t.object` here would reject real traffic. A signed cookie arrives as i
1145
1148
  `hasDuplicateCookie`. The OpenAPI document lists each declared field as an
1146
1149
  `in: cookie` parameter.
1147
1150
 
1151
+ ### Typed request headers (schema.headers)
1152
+
1153
+ A `headers` schema is validated before the handler like the other slots: a missing
1154
+ or malformed header is a `422` (`onValidationError` receives the kind
1155
+ `"headers"`), and `c.headers` becomes the schema&rsquo;s typed output.
1156
+ Every client sends headers no route declares - `host`, `user-agent`,
1157
+ `accept` - so a closed `t.object` validates only the names it declares,
1158
+ each read case-insensitively, which is also how the OpenAPI document lists them: one
1159
+ `in: header` parameter per declared name.
1160
+
1161
+ ```ts
1162
+ import { server } from "@nifrajs/core/server"
1163
+ import { t } from "@nifrajs/schema"
1164
+
1165
+ export const app = server()
1166
+ // Closed: validates only the names it declares, whatever else the client sends.
1167
+ .get("/reports", { headers: t.object({ "x-tenant": t.string() }) }, (c) => ({
1168
+ tenant: c.headers["x-tenant"], // string - a request without it is a 422
1169
+ }))
1170
+ // Open: every header arrives, names lower-cased, declared values coerced from text.
1171
+ .get("/jobs", { headers: t.headers({ "x-retry": t.optional(t.integer()) }) }, (c) => ({
1172
+ retry: c.headers["x-retry"] ?? 0, // number
1173
+ }))
1174
+ ```
1175
+
1176
+ `t.headers` is the open form: it receives every header with its name lower-cased,
1177
+ so it takes lower-case names only, and like `t.query` it coerces declared
1178
+ `t.integer()` / `t.number()` / `t.boolean()` fields from text.
1179
+ A schema nifra cannot read the names of - a Zod `.strict()` object or a Valibot
1180
+ `strictObject` - receives every header, so declare it open.
1181
+
1148
1182
  ### Requests no route matched (notFound)
1149
1183
 
1150
1184
  A path no route matches is answered `404` with
@@ -1271,12 +1305,12 @@ await api.files("report.json").get() // /files/:name.json
1271
1305
 
1272
1306
  A segment that is part literal, part param - `/files/:name.json`,
1273
1307
  `/post-:id`, `/v:major.:minor` - has no single param to name, so it is
1274
- called with the segment as the request carries it: `{'api.files("report.json")'}`,
1275
- `{'api("post-42")'}`, `{'api("v1.2")'}`. The argument is typed as the
1276
- segment's literal text around any string, so `{'api.files("report.txt")'}` does
1308
+ called with the segment as the request carries it: `api.files("report.json")`,
1309
+ `api("post-42")`, `api("v1.2")`. The argument is typed as the
1310
+ segment's literal text around any string, so `api.files("report.txt")` does
1277
1311
  not compile, and it is sent as one encoded segment: a `/` in it never adds a path
1278
1312
  level. `RequestPath` from `@nifrajs/core` is the same reading for a
1279
- whole path: `{'RequestPath'}` is
1313
+ whole path: `RequestPath<"/files/:name.json">` is
1280
1314
  ``/files/${string}.json``.
1281
1315
 
1282
1316
  **Reserved proxy keys.** The client proxy resolves a fixed set of property names
@@ -1293,7 +1327,7 @@ same call params use, accepting exactly the colliding segment names. The client
1293
1327
  the dot access at compile time with that guidance, and `nifra check` reports the
1294
1328
  collision (`NF-C018`, advisory). Prefer a verb-free segment
1295
1329
  (e.g. `/api/remove`) when you control the path; mark a route served only to
1296
- non-typed-client consumers with `// nifra-expect NF-C018: ` above its
1330
+ non-typed-client consumers with `// nifra-expect NF-C018: <reason>` above its
1297
1331
  registration.
1298
1332
 
1299
1333
  ### Results never throw
@@ -1642,7 +1676,7 @@ site.
1642
1676
  What a component usually wants around the call is state, and state is the part every framework
1643
1677
  spells differently. `useServerFn` adds exactly that.
1644
1678
 
1645
- ```ts
1679
+ ```tsx
1646
1680
  // doc-check: skip - JSX fragment, shown for the shape rather than compiled here.
1647
1681
  import { useServerFn } from "@nifrajs/web-react/fn"
1648
1682
  import { addTodo } from "./todos.fn.ts"
@@ -1707,7 +1741,7 @@ and `nifra assure` for free. The starter policy's
1707
1741
  `authenticated-write` rule matches any route declaring a domain write, so a function
1708
1742
  that writes and skips auth fails the check rather than shipping:
1709
1743
 
1710
- ```ts
1744
+ ```bash
1711
1745
  # A server function is a public POST endpoint, so the starter policy already covers it.
1712
1746
  nifra assure
1713
1747
 
@@ -2197,7 +2231,7 @@ that gap safe for you - you rarely have to think about it.
2197
2231
 
2198
2232
  ### Forms and links - nothing to do
2199
2233
 
2200
- A `` to a route, and any ``, use
2234
+ A `<form method="post">` to a route, and any `<a href>`, use
2201
2235
  progressive enhancement: native submit/navigation before hydration, a no-reload client
2202
2236
  takeover after.
2203
2237
 
@@ -2835,6 +2869,8 @@ UI idiom
2835
2869
  Build plugin
2836
2870
  Hydration bundle
2837
2871
 
2872
+ `{f.pkg}`
2873
+
2838
2874
  **Bundle** = the same minimal counter app, minified (not gzipped), for each framework -
2839
2875
  see `examples/web-*`. Indicative payload, not a benchmark.
2840
2876
 
@@ -3071,6 +3107,14 @@ yes
3071
3107
  the merged server&rsquo;s own - a route declaring `idempotency` without one is
3072
3108
  refused at registration
3073
3109
 
3110
+ Two checks catch the silent cases. In development and tests, `unusedScopedHooks`
3111
+ reports a hook followed only by `merge()` calls, and a `responseContract()`
3112
+ or `effectLedger()` installed after routes it would have covered.
3113
+ `nifra check` reports a `merge()` whose server authenticates none of its
3114
+ routes while this server&rsquo;s `authenticate()` or auth plugin covers its own
3115
+ (NF-C043); a module that is public on purpose takes
3116
+ `// nifra-expect NF-C043: <reason>` on the merge line.
3117
+
3074
3118
  ### Route/hook plugins: keep types with defineRouterPlugin
3075
3119
 
3076
3120
  A plugin that registers routes or hooks but adds **no context type** - e.g. mounting an auth
@@ -3084,7 +3128,7 @@ else typed).
3084
3128
 
3085
3129
  **Footgun:** reach for `definePlugin` here instead and a plain
3086
3130
  `definePlugin((app) => app.get(...))` infers `app` as
3087
- `Server`, collapsing `use()`'s result - and your whole typed
3131
+ `Server<any, any>`, collapsing `use()`'s result - and your whole typed
3088
3132
  client - to `any`, with **no type error and no runtime error**.
3089
3133
  `@nifrajs/better-auth` is built with the identity form, so
3090
3134
  `server().use(betterAuth(auth)).get(...)` keeps every route typed.
@@ -3588,9 +3632,44 @@ exposes `validate` and no way to enumerate declared keys. A _stripping_ schema
3588
3632
  response becomes a 500 and the detail goes to the logger, never to the caller.
3589
3633
  `{ extra: "strip" }` changes that for `t` schemas: they carry their
3590
3634
  JSON Schema, which does list the declared keys, so the payload is projected onto them - nested
3591
- objects, arrays and records included - before it is validated. In `"warn"`
3635
+ objects, arrays and records included - before it is validated. A union is projected when a
3636
+ value can meet only one of its branches: a single object branch, or object branches that all
3637
+ require one key holding literals no two of them share, such as `ok: true` and
3638
+ `ok: false`. Other unions are left to the validator. In `"warn"`
3592
3639
  mode the same option makes the log name the fields `"enforce"` would drop.
3593
3640
 
3641
+ Stripping is silent by design. To see a field the contract does not declare - a new column -
3642
+ before someone asks where it went, pass `logStripped: true` with
3643
+ `"enforce"`: the log names each stripped field, nested ones as
3644
+ `user.email` and array items as `items[].cost`, once per route for each
3645
+ distinct set of names. Values are never logged.
3646
+
3647
+ For a metric or an alert, pass `onReport`. It receives every response the
3648
+ contract has something to say about: `violation` (enforce mode, a 500 went out
3649
+ instead), `warn` (warn mode, sent anyway, with the undeclared keys in
3650
+ `fields` when they are the reason) and `stripped` (enforce mode, sent
3651
+ without `fields`). Each report carries the route&rsquo;s method and pattern and
3652
+ the log line&rsquo;s message, never a value. A hook that throws or rejects is logged once and
3653
+ changes no response.
3654
+
3655
+ ```ts
3656
+ import { server } from "@nifrajs/core/server"
3657
+ import { responseContract } from "@nifrajs/core/response-contract"
3658
+
3659
+ const counts = new Map<string, number>()
3660
+
3661
+ export const app = server().use(
3662
+ responseContract("enforce", {
3663
+ extra: "strip",
3664
+ // Every report, where the log speaks once per route. `route` is the pattern, so the keys stay bounded.
3665
+ onReport: ({ kind, method, route }) => {
3666
+ const key = `${kind} ${method} ${route}`
3667
+ counts.set(key, (counts.get(key) ?? 0) + 1)
3668
+ },
3669
+ }),
3670
+ )
3671
+ ```
3672
+
3594
3673
  A `merge()`d server&rsquo;s routes are covered by a contract the parent installed
3595
3674
  before the merge, as long as the route declares a response and its own server installed none.
3596
3675
  See [what a parent&rsquo;s use() covers](/docs/plugins#parent-use).
@@ -4340,6 +4419,10 @@ who asked" and have that be true.
4340
4419
  A route says what it does with `capabilities`, the same on a hand-written route or a
4341
4420
  server function:
4342
4421
 
4422
+ ```ts
4423
+ .post("/notes", { body: NoteInput, capabilities: ["db.write"] }, handler)
4424
+ ```
4425
+
4343
4426
  On its own that is an assertion. What makes it load-bearing is the other half:
4344
4427
  `provenance.imports` maps a module specifier to the capabilities that reaching it
4345
4428
  implies, so Nifra can compare what a route _says_ against what it _can do_.
@@ -4388,7 +4471,7 @@ the guarantee.
4388
4471
 
4389
4472
  Write to the database and declare nothing, and the check says so:
4390
4473
 
4391
- ```ts
4474
+ ```bash
4392
4475
  $ nifra check
4393
4476
 
4394
4477
  ✗ effect/capability assurance: 1
@@ -4397,7 +4480,7 @@ $ nifra check
4397
4480
 
4398
4481
  Declare it, and the policy takes over:
4399
4482
 
4400
- ```ts
4483
+ ```bash
4401
4484
  $ nifra check
4402
4485
  ✓ effect/capability assurance: none
4403
4486
 
@@ -4425,7 +4508,7 @@ is true: the handler really does have the connection in lexical scope.
4425
4508
 
4426
4509
  Which produces a specific dead end, and a specific finding for it:
4427
4510
 
4428
- ```ts
4511
+ ```bash
4429
4512
  $ nifra check
4430
4513
 
4431
4514
  ✗ effect/capability assurance: 1
@@ -4464,7 +4547,7 @@ A raw driver cannot tell a read from a write at the import, so it grants both -
4464
4547
  GET route in any module that can reach the driver is stuck. Putting your queries behind a seam
4465
4548
  split by access is what unsticks it, and it is what `create-nifra --db` scaffolds:
4466
4549
 
4467
- ```ts
4550
+ ```text
4468
4551
  db/
4469
4552
  index.ts the connection - no route module imports this
4470
4553
  read.ts reads, mapped to db.read
@@ -4483,9 +4566,13 @@ source without running it. It reads a path written as a string literal, or as a
4483
4566
  a module-level `const` string, with or without `as const`. The
4484
4567
  `const` can live in the same file or be exported from a project file it imports.
4485
4568
  The same holds for a WebSocket route's `app.ws(path, ...)`. A path built at runtime, such as a template with `${...}` in it, cannot be read
4486
- this way. `nifra check` names that expression in an NF-C036 finding, because the
4487
- route then has no module to start from. List the module in
4488
- `provenance.routeModules` to give it one.
4569
+ this way. So when `nifra.assurance.ts` loads the app, Nifra also records, in
4570
+ development, the module whose call registered each route, and the walk starts there too: a
4571
+ computed path, or a route on a server a helper builds, is still covered.
4572
+ `nifra check` still names such an expression in an NF-C036 finding, since the
4573
+ route lints read the source alone. When the registering module is not where the route&apos;s
4574
+ code lives, such as a shared helper that registers other modules&apos; handlers, list the
4575
+ right module in `provenance.routeModules`.
4489
4576
 
4490
4577
  ### Runtime beacons
4491
4578
 
@@ -4593,7 +4680,7 @@ record routes, not mounts, so review a new gap where it is listed: in the check
4593
4680
  same
4594
4681
  `opaque` field works on a `createWebApp` `mounts` entry.
4595
4682
 
4596
- ```ts
4683
+ ```bash
4597
4684
  $ nifra check
4598
4685
  • known gap, not capability-analyzed: /api/auth/* - better-auth's own handler; its effects are its own
4599
4686
  ```
@@ -4631,7 +4718,7 @@ Once assurance passes, snapshot the result. The lockfile is a review artifact: a
4631
4718
  starts touching something new shows up as a diff in the pull request rather than as nothing at
4632
4719
  all.
4633
4720
 
4634
- ```ts
4721
+ ```bash
4635
4722
  $ nifra capabilities snapshot # writes capabilities.lock.json
4636
4723
  $ nifra levels
4637
4724
  ✓ L0 typed contract
@@ -4891,6 +4978,15 @@ unauthenticated caller gets the 401 (or the refusal `run` returns), never a 413
4891
4978
  `apiKey` and `jwt` from `@nifrajs/middleware` run there. With
4892
4979
  `optional: true` they never refuse, so validation answers as usual.
4893
4980
 
4981
+ A stage that throws, or returns anything but `authenticated(principal)` or
4982
+ `rejected(...)`, fails closed with 503
4983
+ `{ ok: false, error: "auth_unavailable" }`, keeping 401 and 403 for the two
4984
+ real decisions and the cause out of the response. The cause goes where a handler's error
4985
+ goes: to `onError`, whose response replaces the 503, and when no hook answers, to
4986
+ the logger as `unhandled request error`. A database outage inside
4987
+ `authed()` is reported the same way. A thrown `Response` or
4988
+ `status(...)` is sent as thrown, as it is from a handler.
4989
+
4894
4990
  `run` receives the method, pathname, headers, path params, the raw
4895
4991
  `search` and the parsed `query` (frozen, read by the parser
4896
4992
  `c.query` uses; a repeated key is an array), the `request` (never read
@@ -4973,16 +5069,22 @@ own address (which would put all users in one bucket). Never key on a raw
4973
5069
  `X-Forwarded-For` value: a client writes whatever it likes there and gets a fresh bucket
4974
5070
  per request.
4975
5071
 
4976
- " }.
5072
+ ```ts
5073
+ import { server } from "@nifrajs/core/server"
5074
+ import { MemoryStore, rateLimit } from "@nifrajs/middleware"
5075
+
5076
+ // One reverse proxy you operate appends the caller to X-Forwarded-For. Behind a CDN that overwrites
5077
+ // a single header instead, declare { header: "<that header>" }.
4977
5078
  const app = server({ clientIp: { trustedHops: 1 } })
4978
- .use(
4979
- rateLimit({
4980
- store: new MemoryStore(), // use a shared store (Redis, etc.) in production
4981
- max: 5, // 5 attempts
4982
- windowMs: 15 * 60 * 1000, // per 15 minutes
4983
- .post("/login", …)
4984
- lang="ts"
4985
- />
5079
+ .use(
5080
+ rateLimit({
5081
+ store: new MemoryStore(), // use a shared store (Redis, etc.) in production
5082
+ max: 5, // 5 attempts
5083
+ windowMs: 15 * 60 * 1000, // per 15 minutes
5084
+ }),
5085
+ )
5086
+ .post("/login", …)
5087
+ ```
4986
5088
 
4987
5089
  Declare only hops you actually run: a directly reachable app with `trustedHops` set lets
4988
5090
  a client forge the forwarded address. Check your proxy's documentation for the header it sets
@@ -5259,9 +5361,14 @@ export const locales = defineLocales({
5259
5361
  gu: { draft: true }, // catalogs in progress: never routed, never an alternate
5260
5362
  },
5261
5363
  })
5262
- export const urls = defineI18nRouting(locales)
5364
+ export const urls = defineI18nRouting(locales, {
5365
+ // The pages that exist in some locales only, declared once; undefined = every served locale.
5366
+ pageLocales: (pathname) => (pathname.startsWith("/guides/") ? ["en", "hi"] : undefined),
5367
+ })
5263
5368
 
5264
5369
  urls.localizePathname("/kundli", "hi") // "/hi/kundli"
5370
+ urls.localizePathname("/guides/setup", "ur", { fallback: "default" }) // "/guides/setup"
5371
+ urls.localesOf("/hi/guides/setup") // ["en", "hi"]
5265
5372
  locales.chain("hi") // ["hi", "en"] - the catalog fallback order
5266
5373
  ```
5267
5374
 
@@ -5326,6 +5433,45 @@ export function meta({ params, origin }: MetaArgs): Meta {
5326
5433
  }
5327
5434
  ```
5328
5435
 
5436
+ A page that exists in some languages only is declared once, with `pageLocales`
5437
+ (given the path without its locale prefix; it must be pure). Then
5438
+ `matchSegment` answers not-found for the other locales, `alternates`
5439
+ lists only the page's own (none for a page in one locale), `localesOf(path)` names
5440
+ them for a prerender's static paths, and `localizePathname(path, locale, { fallback: "default" })`
5441
+ links a menu entry to the default locale's page where the page is missing. A
5442
+ `pageLocales` that throws, or names a locale the registry does not declare, throws
5443
+ rather than serving every locale.
5444
+
5445
+ ### Register the routing once
5446
+
5447
+ Export the router as `i18n` from `backend/framework.ts` (re-export it from
5448
+ `nifra.config.ts` when both exist), or pass it to a hand-written
5449
+ `createWebApp({ i18n })`. Every document then takes its locale from the URL:
5450
+
5451
+ - `<html lang dir>` come from `documentMeta(localeOf(path))`,
5452
+ unless the route's meta sets `lang`, on a hard load and after each client
5453
+ navigation alike.
5454
+
5455
+ - The response carries `Content-Language`.
5456
+
5457
+ - Each adapter's `useLocale()` names the page's locale key, and
5458
+ `<I18nProvider>` formats in its tag when no `locale` is passed;
5459
+ no loader has to hand either over.
5460
+
5461
+ - A route under a `[lang]` or `[[lang]]` directory runs
5462
+ `matchSegment` before any middleware: an unserved locale, or a page missing from
5463
+ it, is a 404 through your `_404`, and a non-canonical prefix (`/en/x`
5464
+ when the default is unprefixed) is a 308 to the canonical URL. The guard middleware above is
5465
+ then only needed for checks of your own.
5466
+
5467
+ ```ts
5468
+ // doc-check: skip - imports the app's own routing module.
5469
+ // backend/framework.ts - nifra dev, nifra build and the generated server entry read it from here.
5470
+ import { urls } from "../shared/i18n"
5471
+
5472
+ export const i18n = urls
5473
+ ```
5474
+
5329
5475
  ### Negotiate the locale
5330
5476
 
5331
5477
  `negotiateLocale` picks the best supported locale from a `?lang=` query
@@ -5470,6 +5616,9 @@ function Body() {
5470
5616
  }
5471
5617
  ```
5472
5618
 
5619
+ In an app that registers its routing, `locale` may be left out: the provider formats
5620
+ in the page's locale, and `useLocale()` reads the page's locale key anywhere below
5621
+ the route.
5473
5622
  `locale`, `messages` and `fallback` are serializable, so SSR
5474
5623
  renders the negotiated catalogs and the client rebuilds the same formatter on hydrate - no
5475
5624
  mismatch. Switching language re-navigates (a cookie or `?lang=`); the loader returns
@@ -5477,6 +5626,66 @@ the new catalog and the page re-renders. `localeCookie(name, locale)` builds the
5477
5626
  detector's own cookie for a switcher, so a choice made in the page and one made through
5478
5627
  `?lang=` are the same cookie.
5479
5628
 
5629
+ ### Copy tables
5630
+
5631
+ A catalog keys every message; a **copy table** keeps a page's text and its translations
5632
+ beside the code that shows it, with no key to name. `defineCopy(locales)` from
5633
+ `@nifrajs/i18n/copy` binds tables to the registry: the default locale's value is
5634
+ required, a locale the registry does not declare is a type error, and every other value has the
5635
+ default's shape - a list its length, a block its keys. Values are data (messages, lists, blocks);
5636
+ a message that takes values is ICU, read with `copy.format()`.
5637
+
5638
+ ```ts
5639
+ // shared/copy.ts - copy tables: the text and its translations beside the code that shows it.
5640
+ import { defineLocales } from "@nifrajs/i18n"
5641
+ import { defineCopy } from "@nifrajs/i18n/copy"
5642
+
5643
+ export const locales = defineLocales({ default: "en", locales: { en: {}, hi: {}, ta: {} } })
5644
+ export const copy = defineCopy(locales, {
5645
+ onMissing: ({ id, locale, fallback }) => console.warn(`${id ?? "a table"}: no ${locale}, showing ${fallback}`),
5646
+ })
5647
+
5648
+ // The default locale's value is required; every other locale is optional and shaped like it.
5649
+ export const TITLE = copy({ en: "Bicycle", hi: "साइकिल", ta: "மிதிவண்டி" })
5650
+ export const FAQ = copy.id("shop.faq", { en: ["Brakes?", "Gears?"], hi: ["ब्रेक?", "गियर?"] })
5651
+ export const PEDALS = copy({ en: "{n, plural, one {# pedal} other {# pedals}}", hi: "{n} पैडल" })
5652
+
5653
+ copy.pick(TITLE, "ta") // "மிதிவண்டி"
5654
+ copy.pick(FAQ, "ta") // ["Brakes?", "Gears?"] - the en value; onMissing fires once for ta
5655
+ copy.format(PEDALS, "en", { n: 3 }) // "3 pedals"
5656
+ ```
5657
+
5658
+ `copy.pick(table, locale)` walks `locales.chain(locale)`, and
5659
+ `onMissing` fires once per table and locale that falls back. A table's id is its
5660
+ `file:line`, or the one `copy.id()` names.
5661
+
5662
+ In a **production client build**, each table's values move out of the bundle into one chunk
5663
+ per locale, so a page's JavaScript carries the copy of the locale it renders in and none of the
5664
+ others; a chunk holds the fallback's value wherever its locale has none. The server bundle keeps
5665
+ every table whole. A page loads the chunk of its URL's locale (the first path segment when it is a
5666
+ served locale, or what `defineCopy(locales, { localeOf })` returns) and of the
5667
+ locale its `<html lang>` names, both preloaded; a client navigation loads the next
5668
+ URL's chunk with the route's code.
5669
+
5670
+ ```ts
5671
+ // doc-check: skip - continues a hand-written server.ts (adapter, manifest).
5672
+ // nifra build wires this itself; a server entry you write passes the client build's copyChunks.
5673
+ const assets = JSON.parse(await Bun.file("dist/manifest.json").text())
5674
+ export const app = createWebApp({
5675
+ adapter, manifest, clientEntry: assets.entry,
5676
+ copyChunks: assets.copyChunks, // locale -> chunk URL; each page preloads its own
5677
+ })
5678
+ ```
5679
+
5680
+ - The build reads tables statically: string literals, lists and blocks of them, and constants
5681
+ the same module declares. A table built any other way, or written in a `.svelte` or
5682
+ `.vue` file, keeps every locale in the bundle and still works;
5683
+ `nifra i18n check` says which tables those are.
5684
+
5685
+ - The build reads the source with the app's TypeScript (5.9 or 6). Without its compiler API
5686
+ (TypeScript 7 ships none) the build warns and keeps tables whole. It adds about 1 ms per
5687
+ module to a production build.
5688
+
5480
5689
  ### Rich text
5481
5690
 
5482
5691
  `rich(t, key, tags, vars)` renders a message's tags with your components, never
@@ -5505,7 +5714,7 @@ React, Preact, Solid and Vue export `rich()` from their `/i18n` entry,
5505
5714
  returning one node (each handler gets its tag's content as one node too). Svelte has
5506
5715
  `<Rich>`, which takes one snippet per tag:
5507
5716
 
5508
- ```ts
5717
+ ```svelte
5509
5718
  <!-- Svelte: each tag is a snippet that renders its content -->
5510
5719
  <script>
5511
5720
  import { Rich } from "@nifrajs/web-svelte/i18n"
@@ -5546,6 +5755,17 @@ the locale's script. Latin words (brands, units) stay allowed.
5546
5755
 
5547
5756
  - **Untranslated** messages identical to the default in another language, as a warning.
5548
5757
 
5758
+ - **Partly translated** text in a locale that does not write in Latin: a message of 6 words
5759
+ or more that is over 60% Latin-script words (`latin-share`; words split by
5760
+ `Intl.Segmenter`, so Japanese counts), with each locale's share in the coverage
5761
+ table and a warning above 10%; and a message of 80 graphemes or more translated to under 32%
5762
+ of its length (`volume`), a summary rather than a translation. Han scripts, which
5763
+ write a sentence in far fewer graphemes, are left out of `volume`. Every threshold
5764
+ is an option.
5765
+
5766
+ - **Your rules**: each of `rules` runs on every message of every locale, and
5767
+ its findings read `custom:<code>`, which `ignore` takes.
5768
+
5549
5769
  ```ts
5550
5770
  // doc-check: skip - imports the app's own catalog files.
5551
5771
  // shared/i18n.ts - the module `nifra i18n check` imports.
@@ -5563,8 +5783,22 @@ export const catalogs = {
5563
5783
  }
5564
5784
  // Keys a check skips: exact, a prefix ending in ".*", or "*".
5565
5785
  export const ignore = { script: ["languages.*"], untranslated: ["brand"] }
5786
+ // The rest of checkCatalogs()'s options: Latin words a translation keeps, and your own rules.
5787
+ export const check = {
5788
+ latinWords: ["PDF", "OK"],
5789
+ rules: [
5790
+ ({ message }: { readonly message: string }) =>
5791
+ message === message.trim() ? undefined : { code: "spacing", message: "starts or ends with a space" },
5792
+ ],
5793
+ }
5566
5794
  ```
5567
5795
 
5796
+ When the module also exports a `copy` from `defineCopy()` (or only
5797
+ that), the check finds its tables across the project's source, turns them into a catalog per
5798
+ locale and runs the same checks on them, reporting each at its `file:line`. Two tables
5799
+ with one id are an error (a production build refuses them too); a table it cannot read is a
5800
+ warning that says why.
5801
+
5568
5802
  It exits 1 on an error, and with `--strict` on a warning too; `--json`
5569
5803
  prints the result. Draft locales report missing keys as info. The checks themselves are
5570
5804
  `checkCatalogs()` from `@nifrajs/i18n/check`:
@@ -6173,7 +6407,7 @@ sessions, pub/sub) needs a shared store, as in any multi-instance deploy.
6173
6407
  Self-hosting (no CDN in front)? Hand `@nifrajs/node`'s `serve` a
6174
6408
  `static` mount and it serves the client bundle from disk - traversal-guarded,
6175
6409
  content-typed, with an immutable cache - before the app runs, leaving the SSR fast path
6176
- untouched: `serve(app, {'{ port, static: { dir: new URL("./assets/", import.meta.url) } }'})`.
6410
+ untouched: `serve(app, { port, static: { dir: new URL("./assets/", import.meta.url) } })`.
6177
6411
  On Cloudflare/Vercel the platform serves assets, so you don't need it there.
6178
6412
 
6179
6413
  Every file under the mount is cached as immutable by default. If the directory also holds
@@ -6341,6 +6575,12 @@ export const vitePlugins = [react()] // dev HMR (Fast Refresh)
6341
6575
  Nifra includes a conservative codemod for moving static Tailwind classes to StyleX. It is a dry
6342
6576
  run by default, so inspect the proposed edits first:
6343
6577
 
6578
+ ```sh
6579
+ nifra migrate --from tailwind --to stylex # report safe edits and manual issues
6580
+ nifra migrate --from tailwind --to stylex --write # apply only safe edits
6581
+ nifra migrate --from tailwind --to stylex --dir src
6582
+ ```
6583
+
6344
6584
  Supported static `className` attributes become `stylex.props(...)` calls
6345
6585
  backed by a local `stylex.create(...)` table. Responsive breakpoints and
6346
6586
  element-local pseudo-classes such as `hover:` are supported. Dynamic class
@@ -6351,7 +6591,7 @@ remain.
6351
6591
  StyleX compilation is native to Nifra&apos;s Bun pipeline. Install the runtime and compiler peers,
6352
6592
  then register both the browser and SSR transforms:
6353
6593
 
6354
- ```ts
6594
+ ```sh
6355
6595
  # Install the runtime and the optional compiler peers.
6356
6596
  bun add @stylexjs/stylex
6357
6597
  bun add -d @babel/core @stylexjs/babel-plugin @babel/plugin-syntax-flow \
@@ -6390,7 +6630,7 @@ target, keeping its `^` or `~` unless you pass `--exact`.
6390
6630
  The pins in `overrides`, `resolutions` and
6391
6631
  `pnpm.overrides` move with them, since an override decides what installs.
6392
6632
 
6393
- ```ts
6633
+ ```bash
6394
6634
  nifra upgrade --list # the release targets this CLI knows
6395
6635
  nifra upgrade 5.0.0 # dry-run: every planned edit, nothing written
6396
6636
  nifra upgrade 5.0.0 --write # apply, then nifra check verifies (--no-verify skips it)
@@ -6404,8 +6644,9 @@ that release&apos;s CLI. It edits files under the workspace root only: a symlink
6404
6644
  directory or `package.json` is never followed, and a group package installed by a
6405
6645
  link from outside the root is listed under "Left alone" for you to upgrade in its
6406
6646
  own repository. The MCP launch pin in `.mcp.json`, `.cursor/mcp.json`,
6407
- `CLAUDE.md` and `AGENTS.md` moves to the target, the edit
6408
- `nifra init-agents --sync-mcp` makes. Another version pinned outside
6647
+ `CLAUDE.md` and `AGENTS.md` moves to the target, or is dropped when
6648
+ the project declares `@nifrajs/cli` so the launch runs that install from then on:
6649
+ the edit `nifra init-agents --sync-mcp` makes. Another version pinned outside
6409
6650
  `package.json` is listed with its line: the rest of an agent file, an MCP config
6410
6651
  elsewhere, a Dockerfile or compose file, a CI workflow, and a lockfile other than the
6411
6652
  workspace&apos;s own (an image build&apos;s frozen lockfile, say), which you regenerate after
@@ -6413,7 +6654,20 @@ installing. With `--write` it also
6413
6654
  prints how hook scope changed across the
6414
6655
  upgrade (`--no-hooks` skips that). `nifra doctor` and
6415
6656
  `nifra check` (NF-D002) point here when a workspace carries more than one version;
6416
- see [mixed nifra versions](/docs/troubleshooting#mixed-versions).
6657
+ see [mixed nifra versions](/docs/troubleshooting#mixed-versions). A
6658
+ `file:` package whose dependencies this upgrade moves keeps its old ones in
6659
+ `bun.lock`, where Bun never refreshes them; the plan lists each, and
6660
+ `--write` drops those entries so the next `bun install` records them
6661
+ again (see [stale file: links](/docs/troubleshooting#stale-file-links)).
6662
+
6663
+ A `link:` or `file:` dependency outside the root that installs its own
6664
+ `@nifrajs/*` at another version stops the upgrade before anything is written: its
6665
+ imports resolve from its own `node_modules`, so after the upgrade a
6666
+ `server()` it builds cannot be merged into yours. The refusal names each one with
6667
+ the commands that move it to the target; upgrade those first, or pass
6668
+ `--allow-linked-skew` to go ahead. `nifra upgrade --list` shows the
6669
+ targets with the notes of every release after the one you declare: what an app can observe
6670
+ changing on the way up.
6417
6671
 
6418
6672
  ### Scope
6419
6673
 
@@ -6478,7 +6732,7 @@ need both). Anywhere else, add the URL.
6478
6732
 
6479
6733
  ### Setup
6480
6734
 
6481
- ```ts
6735
+ ```bash
6482
6736
  # Registers the MCP server and writes the agent files. Never clobbers what is already there.
6483
6737
  nifra init-agents
6484
6738
 
@@ -6491,9 +6745,14 @@ nifra init-agents
6491
6745
 
6492
6746
  # Then restart the agent so it picks the server up.
6493
6747
 
6494
- # The server is pinned to an exact @nifrajs/cli. After upgrading nifra, re-pin it to the version the
6495
- # project installs. Only that version string changes; every other byte of every file is kept.
6748
+ # A project that declares @nifrajs/cli launches `bunx @nifrajs/cli mcp`, unpinned: bunx runs the
6749
+ # installed CLI, so the server moves with every upgrade. Elsewhere the launch is pinned to an exact
6750
+ # version, since an unpinned bunx would fetch the latest release.
6751
+ # This moves an old pinned launch to that form: unpinned when the project declares the CLI, else the
6752
+ # version it installs. Only the version string changes; every other byte of every file is kept.
6496
6753
  # At a workspace root whose one nifra app is a member, the launch also names it: `mcp app`.
6754
+ # Run in that member, it also re-pins the root's files whose every nifra launch serves it (they stay
6755
+ # pinned: the root's own node_modules need not hold the CLI).
6497
6756
  nifra init-agents --sync-mcp
6498
6757
  ```
6499
6758
 
@@ -6502,7 +6761,7 @@ safe to re-run after a Nifra upgrade.
6502
6761
 
6503
6762
  ### The loop
6504
6763
 
6505
- ```ts
6764
+ ```bash
6506
6765
  # 1. What is here?
6507
6766
  nifra_context # routes, page routes, conventions - one call, unfiltered, as an index
6508
6767
  nifra_routes # API routes as JSON: { method, path, call, body?, query?, response? }
@@ -6539,7 +6798,7 @@ without being told a port. The server writes `.nifra/dev-server.json`, readable
6539
6798
  its owner, with its port and a token minted for that run; a tool checks that the server answers
6540
6799
  as itself before it reads anything.
6541
6800
 
6542
- ```ts
6801
+ ```bash
6543
6802
  nifra_errors # every open error, newest last
6544
6803
  nifra_errors {since: 41} # only what happened after a previous call's cursor
6545
6804
  nifra_errors {category: ["hydration"], includeStale: false}
@@ -6553,7 +6812,7 @@ nifra logs --level warn,error --grep cart
6553
6812
 
6554
6813
  Each error is a structured diagnostic, the same one the dev overlay renders:
6555
6814
 
6556
- ```ts
6815
+ ```json
6557
6816
  {
6558
6817
  "id": "e_5b6cbe9d",
6559
6818
  "category": "browser",
@@ -6632,7 +6891,7 @@ export const devDatabase = {
6632
6891
  }
6633
6892
  ```
6634
6893
 
6635
- ```ts
6894
+ ```bash
6636
6895
  nifra_db_schema # tables, row estimates, columns, keys, indexes
6637
6896
  nifra_db_schema {table: "orders"} # one table
6638
6897
  nifra_db_query {sql: "SELECT status, count(*) FROM orders GROUP BY 1"}
@@ -6748,7 +7007,7 @@ is.
6748
7007
  only by its owner: the SQL with secrets redacted, its fingerprint, the row count, the duration
6749
7008
  and the refusal code - never the rows. It rotates at 1 MB; `nifra db audit` reads it.
6750
7009
 
6751
- ```ts
7010
+ ```json
6752
7011
  {
6753
7012
  "ok": true,
6754
7013
  "tool": "query",
@@ -6857,7 +7116,7 @@ The teaching tools - `nifra_docs`, `nifra_example`,
6857
7116
  verified corpora, with no local checkout. It is read-only and needs no key. The project tools
6858
7117
  above still come from `nifra mcp` in your own repo, where they can see your routes.
6859
7118
 
6860
- ```ts
7119
+ ```bash
6861
7120
  # Claude Code
6862
7121
  claude mcp add --transport http nifra-docs https://mcp.nifra.dev
6863
7122
 
@@ -6882,7 +7141,7 @@ add Nifra docs to Cursor
6882
7141
  `nifra_check` is the one an agent should loop on. It returns structured
6883
7142
  diagnostics, each carrying its own fix, so a failure is a work item rather than a wall.
6884
7143
 
6885
- ```ts
7144
+ ```json
6886
7145
  {
6887
7146
  "ok": true,
6888
7147
  "typecheck": "pass",
@@ -6903,7 +7162,7 @@ contract (L0) to contract-derived invariant tests (L4). A scaffolded app starts
6903
7162
  rung it has not reached reports the specific thing missing - so the ladder doubles as the list
6904
7163
  of what to do next. See [the verification ladder](/docs/verification).
6905
7164
 
6906
- ```ts
7165
+ ```bash
6907
7166
  # The two an agent should gate on. Both exit non-zero on failure, so they work in CI unchanged.
6908
7167
  nifra check
6909
7168
  nifra levels --min 1
@@ -6964,7 +7223,7 @@ any Agent Client Protocol agent (Claude Code, Codex, Gemini CLI) over stdio; oth
6964
7223
  implement the same protocol port and can prove it with `checkAgentBackend` from
6965
7224
  `@nifrajs/agent-protocol/conformance`.
6966
7225
 
6967
- ```ts
7226
+ ```bash
6968
7227
  bun add @nifrajs/coding-agent @nifrajs/pi
6969
7228
 
6970
7229
  # Interactive, one-shot, JSON, and local RPC modes are available.
@@ -6979,7 +7238,7 @@ environments, and treats extensions as an explicit opt-in. Post-turn `check`,
6979
7238
  the gate until it passes or the attempt cap is reached. The local process adapter and extension
6980
7239
  worker are crash-containment helpers, not hostile-code sandboxes.
6981
7240
 
6982
- ```ts
7241
+ ```bash
6983
7242
  # Post-turn gates are opt-in. A failed gate becomes bounded repair work.
6984
7243
  bunx nifra-agent --backend pi --message "implement the change" \
6985
7244
  --verify-after-turn check,assure --max-repair-attempts 2
@@ -7509,6 +7768,13 @@ emits the _same_ error as the Bun build (one implementation, adapted to Rollup's
7509
7768
  so a refused import - a `node:` builtin, `backend/`, a route's
7510
7769
  `.backend.ts` half - fails the build either way.
7511
7770
 
7771
+ `import.meta.glob` is not one of them. The Bun build expands a literal pattern the
7772
+ way Vite does: a string or an array of strings starting with `./`,
7773
+ `../` or `/` (the app root), `!` excluding, with the
7774
+ `eager` and `import` options, keyed as Vite keys it. Any other form
7775
+ (a computed pattern, an alias, `query`) fails the build with the file and line, and
7776
+ so does a bundle that still calls the glob because another plugin loaded that module first.
7777
+
7512
7778
  ```ts
7513
7779
  // vite.config.ts - a Vite/Rollup PRODUCTION client build (the escape hatch, not the default).
7514
7780
  // Only reach for this when an app needs a Vite-only transform with no Bun equivalent; Nifra's default
@@ -7867,7 +8133,7 @@ Declare the packages in your app's `package.json`. It is a **static**
7867
8133
  declaration on purpose - `nifra check` reads it without importing your config, so
7868
8134
  the preflight never executes app code:
7869
8135
 
7870
- ```ts
8136
+ ```json
7871
8137
  {
7872
8138
  "name": "my-app",
7873
8139
  "dependencies": {
@@ -7902,7 +8168,7 @@ not: Bun's _runtime_ resolver never offers a
7902
8168
  bare specifier to a plugin, so `bun test`, `bun run`, and preloaded
7903
8169
  scripts still load both copies unless you preload the registrar:
7904
8170
 
7905
- ```ts
8171
+ ```toml
7906
8172
  # bunfig.toml
7907
8173
  preload = ["@nifrajs/core/single-copy/register"]
7908
8174
 
@@ -7949,7 +8215,7 @@ Vue, Solid, Svelte). Nifra dedupes the active adapter's runtime in build and dev
7949
8215
  `AGENTS.md`.
7950
8216
 
7951
8217
  ###
7952
- `client` resolves to `never` (or `data: never`)
8218
+ `client<typeof app>` resolves to `never` (or `data: never`)
7953
8219
 
7954
8220
  The typed client is derived from your backend's type. Two things collapse it:
7955
8221
 
@@ -7966,7 +8232,7 @@ plain object and shape the response with `c.set` - reach for `c.json` /
7966
8232
  -
7967
8233
  **A plugin widened the app's type.** A plugin that registers routes/hooks but whose return
7968
8234
  type isn't the concrete server (e.g. an untyped `app => app.onResponse(…)`)
7969
- makes `.use()` return `Server` and the client loses your
8235
+ makes `.use()` return `Server<any, any>` and the client loses your
7970
8236
  registry. Build it with `defineRouterPlugin(name, …)` (the clearer-named
7971
8237
  `defineIdentityPlugin`) so `.use()` returns your server unchanged and
7972
8238
  routes added after it stay typed. See
@@ -8062,10 +8328,10 @@ export const app = implement(contract, {
8062
8328
  Because the budget is per-expression and global to a compilation, a type-heavy construct
8063
8329
  _elsewhere_ in the program can push an otherwise-fine `.merge()` chain over the
8064
8330
  edge. It surfaces not as `TS2589` but as a `TS2345` assignability error
8065
- naming an **uninstantiated** `Server` - the shape
8331
+ naming an **uninstantiated** `Server<Registry, unknown>` - the shape
8066
8332
  the server type collapses to when the compiler gives up mid-inference. The usual trigger is a
8067
8333
  **generic higher-order function that wraps the builder** (a
8068
- `withX(app)` that threads the `Server` type through its own type
8334
+ `withX<T>(app)` that threads the `Server` type through its own type
8069
8335
  parameters); merely having that file in the program can be enough. Treat these as real
8070
8336
  constraints of an inference-first framework:
8071
8337
 
@@ -8076,10 +8342,10 @@ inference-heavy generics thread the `Server` / registry type through your own co
8076
8342
  -
8077
8343
  **Avoid generic HOF wrappers around the builder.** Wrap with a
8078
8344
  `defineRouterPlugin` (identity plugin) or compose with `.merge()` instead
8079
- of a `withX(app)` that re-infers the whole server type.
8345
+ of a `withX<T>(app)` that re-infers the whole server type.
8080
8346
 
8081
8347
  -
8082
- Put an explicit `Promise` return annotation on async callbacks that thread
8348
+ Put an explicit `Promise<T>` return annotation on async callbacks that thread
8083
8349
  framework types, so the compiler stops re-deriving the awaited type at each use.
8084
8350
 
8085
8351
  [!TIP]
@@ -8118,6 +8384,21 @@ workspace root only. A symlinked package directory or `package.json` is never
8118
8384
  followed, and a group package installed by a link from outside the root is listed under
8119
8385
  "Left alone" - upgrade that repository on its own.
8120
8386
 
8387
+ ### "records dependencies its file: packages no longer declare"
8388
+
8389
+ A `file:` dependency's own dependencies are recorded in `bun.lock` when
8390
+ Bun first installs it, and Bun does not read that package's `package.json` again:
8391
+ after the linked package moves to a new version of a dependency, `bun install`
8392
+ (even with `--force`) keeps installing the recorded one beside it, so the app can
8393
+ load two copies of the same package. `nifra doctor` (and `nifra check`,
8394
+ as the `NF-D003` warning) compares each recorded entry with the linked
8395
+ `package.json` and names every dependency that moved.
8396
+
8397
+ Run `bun update <package>` for each named package. `nifra upgrade`
8398
+ reads the lock against the manifests it is about to write, and with `--write` drops
8399
+ those entries so the next `bun install` records them again; run that install
8400
+ before committing `bun.lock`, or `bun install --frozen-lockfile` fails.
8401
+
8121
8402
  ### Still stuck?
8122
8403
 
8123
8404
  Run `nifra check --json` as the done-gate - it surfaces the import-chain leaks,
@@ -8224,10 +8505,14 @@ written down: `nifra fix --code NF-C035` adds
8224
8505
 
8225
8506
  With both files, `nifra dev` and `nifra build` take
8226
8507
  `apiPrefix`, `apiStrip`, `mounts`, `csp`,
8227
- `nonce`, `serverComponents` and `use` from
8228
- `backend/framework.ts` when `nifra.config.ts` does not set them, so the
8508
+ `nonce`, `serverComponents`, `i18n`, `use` and
8509
+ `publicEnvPrefix` from `backend/framework.ts` when
8510
+ `nifra.config.ts` does not set them, so the
8229
8511
  server entry and the dev server read one value without a re-export. A hand-written
8230
- `createWebApp` call passes `apiPrefix` itself.
8512
+ `createWebApp` call passes `apiPrefix` itself; import it from
8513
+ `backend/framework.ts` so production serves the backend where
8514
+ `nifra dev` does. `nifra check` reports `NF-C035` at a call
8515
+ that mounts a backend with no `apiPrefix`, or with a different one.
8231
8516
 
8232
8517
  Because the backend answers first and its 404 is final, a page file under the prefix (
8233
8518
  `routes/api/report.tsx`) could never render. Nifra refuses it instead of serving a
@@ -8237,7 +8522,7 @@ mount in front of the page router.
8237
8522
 
8238
8523
  An app run by `nifra dev` and `nifra build` sets these options from
8239
8524
  `backend/framework.ts`: `apiPrefix`, `apiStrip`, `mounts`,
8240
- `csp` and `nonce`. The generated server entry imports them from there, so
8525
+ `csp`, `nonce` and `i18n`. The generated server entry imports them from there, so
8241
8526
  export them from `framework.ts` (and re-export from `nifra.config.ts` when
8242
8527
  both exist). A `mounts` entry hands a path to another app; a single extra URL
8243
8528
  outside the prefix, such as a sitemap, is a plain route registered in `use`:
@@ -8320,7 +8605,7 @@ each other. Each domain therefore owns its full absolute paths (`/api/listings`,
8320
8605
  `.group(prefix, build)`
8321
8606
  **
8322
8607
  - declare routes under a static prefix. `app.group("/admin", (a) => a.get("/users",
8323
- list))` serves `/admin/users`, and the prefix is part of the typed client,
8608
+ list))` serves `/admin/users`, and the prefix is part of the typed client,
8324
8609
  `routes()`, OpenAPI, capability events and the effect ledger. The builder
8325
8610
  inherits this server's middleware chain as it stands at the call; what it adds stays in the
8326
8611
  group, and its `onRequest`/`onResponse` hooks run only for requests at
@@ -8401,7 +8686,7 @@ Two valid ways to mutate; pick by where the call originates.
8401
8686
 
8402
8687
  -
8403
8688
  **Route `action`** - the form/SSR path. A
8404
- `` (or the client submit) runs the route's
8689
+ `<form method="post">` (or the client submit) runs the route's
8405
8690
  `action(ctx)`, which typically calls `ctx.api` in-process and returns
8406
8691
  `actionData` (or a `redirect`). Progressive-enhancement: works with JS
8407
8692
  off, and the loader revalidates after. Reach for this for page-driven mutations tied to a
@@ -8612,7 +8897,7 @@ than something we vouch for.
8612
8897
 
8613
8898
  ### The report is the evidence
8614
8899
 
8615
- ```ts
8900
+ ```json
8616
8901
  {
8617
8902
  "schemaVersion": 1,
8618
8903
  "ok": true,
@@ -9124,7 +9409,7 @@ router and await auth-scope invalidation on identity, tenant or permission chang
9124
9409
  The programmatic `buildClient()` API emits a content-hashed directory plus a
9125
9410
  `manifest.json` you can hand to `createWebApp` (`entry`,
9126
9411
  `routes` for per-route preload, `css` + `routeStyles` for
9127
- `<link>` injection).
9412
+ `<link>` injection, `copyChunks` when the app has copy tables).
9128
9413
 
9129
9414
  ```ts
9130
9415
  // buildClient() writes a browser bundle + manifest.json for custom build pipelines:
@@ -9133,7 +9418,8 @@ The programmatic `buildClient()` API emits a content-hashed directory plus a
9133
9418
  "assets": ["/assets/…"], // every emitted chunk URL
9134
9419
  "routes": { "users/[id]": ["/assets/_layout-H.js", "/assets/_slug_-H.js"] },
9135
9420
  "css": ["/assets/app-H.css"], // aggregate stylesheets (fallback)
9136
- "routeStyles": { "users/[id]": ["/assets/_layout-H.css"] } // per-route CSS (chain only)
9421
+ "routeStyles": { "users/[id]": ["/assets/_layout-H.css"] }, // per-route CSS (chain only)
9422
+ "copyChunks": { "hi": "/assets/copy-hi-H.js" } // copy tables by locale (@nifrajs/i18n/copy)
9137
9423
  }
9138
9424
 
9139
9425
  // Invariants worth knowing:
@@ -9645,8 +9931,8 @@ says that the app kept it open.
9645
9931
  **Routes nifra cannot see.** A mounted handler such as better-auth answers paths that are
9646
9932
  not in your backend, and no typed client covers them. Declare the mount opaque,
9647
9933
  `
9648
- mounts: [{ path: "/api/auth", app: auth, opaque: "better-auth" }]
9649
- `
9934
+ mounts: [{ path: "/api/auth", app: auth, opaque: "better-auth" }]
9935
+ `
9650
9936
  , and when `nifra.assurance.ts` names this app as its `source`, the
9651
9937
  check skips a `fetch` into that prefix by itself. Without that, list the prefixes
9652
9938
  in `nifra.check.json` next to `package.json`:
@@ -9659,7 +9945,7 @@ in `nifra.check.json` next to `package.json`:
9659
9945
 
9660
9946
  -
9661
9947
  **One call nifra cannot type.** For a single call rather than a whole prefix, such as a
9662
- static file, put `// nifra-expect NF-C002: ` on the line or in the
9948
+ static file, put `// nifra-expect NF-C002: <reason>` on the line or in the
9663
9949
  comment block above it. The finding stays in the report as info, with your reason. A comment
9664
9950
  with no reason silences nothing.
9665
9951
 
@@ -9963,7 +10249,7 @@ do. The dev overlay shows it, `nifra_explain` returns it, and every entry
9963
10249
  recognise is `NIFRA_UNHANDLED`, still with its frames and a codeframe around the line
9964
10250
  in your source.
9965
10251
 
9966
- ```ts
10252
+ ```json
9967
10253
  {
9968
10254
  "code": "NIFRA_OUTPUT_SENSITIVE_FIELD",
9969
10255
  "name": "OutputGuardError",
@@ -10124,9 +10410,16 @@ its own.
10124
10410
 
10125
10411
  ### Silencing a nifra check finding
10126
10412
 
10127
- `nifra check` names each finding with an `NF-` code. Where a finding is
10128
- reviewed and intended, a comment on the flagged line, or anywhere in the comment block directly
10129
- above it, says so and why:
10413
+ `nifra check` names each finding with an `NF-` code;
10414
+ `nifra explain NF-C007` (or `nifra_explain` with the code as its
10415
+ `error`) says what the rule reports, why it matters, how to fix it and where it is
10416
+ documented. Where a finding is reviewed and intended, a comment on the flagged line, or anywhere
10417
+ in the comment block directly above it, says so and why:
10418
+
10419
+ ```ts
10420
+ // nifra-expect NF-S002: compares the challenge the sender echoes back, not a secret
10421
+ if (echoToken === challenge) return accept()
10422
+ ```
10130
10423
 
10131
10424
  The comment answers only the code it names. A finding that fails the check, and every security
10132
10425
  finding, is silenced only with a reason after the colon; an advisory also accepts the comment
@@ -10442,8 +10735,12 @@ and import edits; this guide covers the structural changes it deliberately canno
10442
10735
 
10443
10736
  ### 1. Run the executable upgrade
10444
10737
 
10445
- ```ts
10446
-
10738
+ ```sh
10739
+ nifra upgrade 2.0.0 # dry-run: inspect every planned edit
10740
+ nifra upgrade 2.0.0 --write # apply edits, then run nifra check
10741
+ bun install
10742
+ bun run test
10743
+ bun run build
10447
10744
  ```
10448
10745
 
10449
10746
  The command updates existing `@nifrajs/*`, `Nifra`, and
@@ -10461,7 +10758,26 @@ only the systems an app uses with `.use()`; registration fails loudly if a requi
10461
10758
  plugin is missing.
10462
10759
 
10463
10760
  ```ts
10761
+ // doc-check: skip - migration fragment uses the application's existing stores and handlers
10762
+ // 1.x
10763
+ import "@nifrajs/core/ws"
10764
+ const app = server({ idempotencyStore, effectLedger: { sink } })
10765
+ .ws("/chat", socketHandler)
10766
+
10767
+ // 2.0
10768
+ import { effectLedger } from "@nifrajs/core/effect-ledger"
10769
+ import { idempotency } from "@nifrajs/core/idempotency-plugin"
10770
+ import { mcp } from "@nifrajs/core/mcp"
10771
+ import { streaming } from "@nifrajs/core/sse"
10772
+ import { websocket } from "@nifrajs/core/ws"
10464
10773
 
10774
+ const app = server()
10775
+ .use(idempotency({ store: idempotencyStore }))
10776
+ .use(effectLedger({ sink }))
10777
+ .use(mcp()) // only when the app declares tools/resources/prompts
10778
+ .use(streaming()) // only when the app declares SSE routes
10779
+ .use(websocket())
10780
+ .ws("/chat", socketHandler)
10465
10781
  ```
10466
10782
 
10467
10783
  The `@nifrajs/node` adapter installs `nodeDirect()` automatically.
@@ -10475,7 +10791,12 @@ contracts, assurance, capabilities, budgets, manifests, reflection, SSE, WebSock
10475
10791
  other optional systems from their documented subpaths.
10476
10792
 
10477
10793
  ```ts
10794
+ // doc-check: skip - before/after migration block includes the removed 1.x package
10795
+ // 1.x
10796
+ import { createRequestBudget } from "@nifrajs/budget"
10478
10797
 
10798
+ // 2.0
10799
+ import { createRequestBudget } from "@nifrajs/core/budget"
10479
10800
  ```
10480
10801
 
10481
10802
  Contract-generated adversarial testing lives in `@nifrajs/testing`; the deprecated
@@ -10490,7 +10811,17 @@ result of `inProcessClient(backend)` or `testClient(backend)`; both
10490
10811
  already implement the interface and forward `env` and `waitUntil`.
10491
10812
 
10492
10813
  ```ts
10814
+ // doc-check: skip - fragment uses the application adapter, manifest, and client entry
10815
+ import { inProcessClient } from "@nifrajs/client"
10816
+ import { createWebApp } from "@nifrajs/web"
10817
+ import { backend } from "./backend"
10493
10818
 
10819
+ const app = createWebApp({
10820
+ adapter,
10821
+ manifest,
10822
+ clientEntry,
10823
+ api: inProcessClient(backend),
10824
+ })
10494
10825
  ```
10495
10826
 
10496
10827
  ### 5. Declare external library mounts
@@ -10500,8 +10831,10 @@ Nifra typed contract. A relative fetch to that library is intentional, but other
10500
10831
  a hand-rolled own-API call. Declare only the exact mounted prefix in
10501
10832
  `nifra.check.json` so `nifra check` does not keep CI red:
10502
10833
 
10503
- ```ts
10504
-
10834
+ ```json
10835
+ {
10836
+ "externalMounts": ["/auth"]
10837
+ }
10505
10838
  ```
10506
10839
 
10507
10840
  Prefixes are segment-anchored: `/auth` covers `/auth` and its children,
@@ -10516,7 +10849,14 @@ After checking `!result.ok`, also narrow `result.status` before reading
10516
10849
  typed failure data. Undeclared statuses and transport status `0` remain unknown.
10517
10850
 
10518
10851
  ```ts
10519
-
10852
+ const result = await api.users({ id }).get()
10853
+ if (!result.ok) {
10854
+ if (result.status === 404) {
10855
+ result.data.message // typed from errors[404]
10856
+ } else {
10857
+ // Undeclared status or transport status 0: result.data is unknown.
10858
+ }
10859
+ }
10520
10860
  ```
10521
10861
 
10522
10862
  ### 7. Apply the remaining web and protocol changes
@@ -10525,7 +10865,11 @@ typed failure data. Undeclared statuses and transport status `0` remain unknown.
10525
10865
  Redirects accept an options object as their second argument.
10526
10866
 
10527
10867
  ```ts
10868
+ // 1.x
10869
+ redirect("/done", 307)
10528
10870
 
10871
+ // 2.0
10872
+ redirect("/done", { status: 307 })
10529
10873
  ```
10530
10874
 
10531
10875
  -
@@ -10577,8 +10921,12 @@ cannot guess, plus the Node proxy transport default.
10577
10921
 
10578
10922
  ### 1. Run the executable upgrade
10579
10923
 
10580
- ```ts
10581
-
10924
+ ```sh
10925
+ nifra upgrade 3.0.0 # dry-run: inspect every planned edit
10926
+ nifra upgrade 3.0.0 --write # apply edits, then run nifra check
10927
+ bun install
10928
+ bun run test
10929
+ bun run build
10582
10930
  ```
10583
10931
 
10584
10932
  The command pins every matching `@nifrajs/*`, `Nifra`, and
@@ -10611,7 +10959,19 @@ through the second argument, and assert on `.plain` in tests. A hand-rolled
10611
10959
  itself returns changed.
10612
10960
 
10613
10961
  ```ts
10962
+ // 2.x - a redirect was a Web Response
10963
+ const r = redirect("/done")
10964
+ r.status // 302
10965
+ r.headers.get("location")
10966
+ r instanceof Response // true
10967
+
10968
+ // 3.0 - a redirect is plain render data
10969
+ const r = redirect("/done")
10970
+ r.plain // { status, headers, body }
10971
+ r.toResponse() // build a Response only when something genuinely needs one
10614
10972
 
10973
+ // Add headers through the second argument; cookies still ride c.set as before.
10974
+ redirect("/done", { status: 307, headers: { "cache-control": "no-store" } })
10615
10975
  ```
10616
10976
 
10617
10977
  ### 3. Fix reserved typed-client segments
@@ -10623,7 +10983,13 @@ because the proxy resolves the reserved key before a path segment. The types now
10623
10983
  access at compile time instead of silently reaching the wrong node.
10624
10984
 
10625
10985
  ```ts
10986
+ // A route whose path segment spells a reserved client key
10987
+ // (get/post/put/patch/delete/head/options, subscribe/ws/index/then)
10988
+ // is no longer reachable by property access:
10989
+ api.posts.delete.get() // 3.0: type error - `delete` is a reserved verb key
10626
10990
 
10991
+ // The typed spelling is a call on the parent node with the segment:
10992
+ api.posts("delete").get() // reaches /posts/delete
10627
10993
  ```
10628
10994
 
10629
10995
  Run `nifra fix --code NF-C018` to rewrite the affected call sites. It reads them
@@ -10634,7 +11000,11 @@ from the compiler rather than a text search, so it finds every one and never mis
10634
11000
  both the table and `--json`. The set is exported as the one place it is written down.
10635
11001
 
10636
11002
  ```ts
11003
+ // doc-check: skip - fragment reads the exported reserved-key contract
11004
+ import { RESERVED_VERB_KEYS, RESERVED_EXACT_KEYS, reservedKeyFor } from '@nifrajs/client'
10637
11005
 
11006
+ reservedKeyFor('delete') // 'delete'
11007
+ reservedKeyFor('posts') // undefined
10638
11008
  ```
10639
11009
 
10640
11010
  ### 4. Review the Node proxy transport (only if you use it)
@@ -10644,7 +11014,15 @@ On Node, `@nifrajs/proxy` now defaults to the undici transport, shipped from the
10644
11014
  `createProxy` to override it.
10645
11015
 
10646
11016
  ```ts
11017
+ // doc-check: skip - fragment shows the Node transport default and its override
11018
+ import { createProxy } from '@nifrajs/proxy'
11019
+ import { undiciTransport } from '@nifrajs/proxy/undici'
10647
11020
 
11021
+ // 3.0 on Node: undici is the default transport.
11022
+ const proxy = createProxy({ target })
11023
+
11024
+ // Override it explicitly when a different transport is wanted:
11025
+ const custom = createProxy({ target, transport: undiciTransport() })
10648
11026
  ```
10649
11027
 
10650
11028
  ### 5. Run the release gates
@@ -10672,8 +11050,10 @@ finished migration from one that needs a decision.
10672
11050
 
10673
11051
  ### 1. Run the executable upgrade
10674
11052
 
10675
- ```ts
10676
-
11053
+ ```sh
11054
+ bunx @nifrajs/cli@5.0.0 upgrade 5.0.0 # dry run: every release step from the installed version
11055
+ bunx @nifrajs/cli@5.0.0 upgrade 5.0.0 --write # apply the pins and import moves
11056
+ bun install
10677
11057
  ```
10678
11058
 
10679
11059
  Run the command from the release you are moving to. It chains every release recipe between
@@ -10681,13 +11061,16 @@ the installed version and 5.0, so a 3.x app takes the 4.0 steps (the retired
10681
11061
  `@nifrajs/web/server-only` import moves to `@nifrajs/web/backend-only`)
10682
11062
  and the 5.0 ones in one pass, and prints each release's notes. It lists every
10683
11063
  `@nifra-gate-reviewed` comment, which silences nothing in 5.0: after review, write
10684
- `// nifra-expect : ` with the code `nifra check`
11064
+ `// nifra-expect <code>: <reason>` with the code `nifra check`
10685
11065
  reports there. The upgrade never writes a reason for you.
10686
11066
 
10687
11067
  ### 2. Move onto the frontend/backend layout (from 3.x)
10688
11068
 
10689
- ```ts
10690
-
11069
+ ```sh
11070
+ nifra migrate layout # dry run: splits, moves, rewritten imports, issues
11071
+ nifra migrate layout --write # apply it
11072
+ nifra schemas --write # draft the output schemas it lists as follow-ups
11073
+ nifra check
10691
11074
  ```
10692
11075
 
10693
11076
  Each route file splits into `x.tsx`, the page, and `x.backend.ts`, which
@@ -10698,16 +11081,37 @@ to `frontend/`, `backend/` or `shared/` by who imports it at
10698
11081
  runtime. A folder whose imported files all land in one zone moves whole, so a component nothing
10699
11082
  imports yet travels with its folder; a folder split between zones is reported instead.
10700
11083
 
10701
- ```ts
11084
+ ```tsx
11085
+ // doc-check: skip - a route split into its two halves
11086
+ // routes/notes.tsx - the page, shipped to the browser whole
11087
+ import type { loader } from "./notes.backend.ts"
11088
+ export default function Notes({ data }: { data: Awaited<ReturnType<typeof loader>> }) {
11089
+ return <ul>{data.notes.map((note) => <li key={note.id}>{note.title}</li>)}</ul>
11090
+ }
10702
11091
 
11092
+ // routes/notes.backend.ts - loader, action, middleware and the other server exports
11093
+ import { t } from "@nifrajs/schema"
11094
+ export const loaderOutput = t.object({
11095
+ notes: t.array(t.object({ id: t.string(), title: t.string() })),
11096
+ })
11097
+ export async function loader() {
11098
+ return { notes: await listNotes() }
11099
+ }
10703
11100
  ```
10704
11101
 
10705
11102
  To keep a folder where it is, declare it a zone before migrating. The migration leaves zoned
10706
11103
  folders in place, and builds, `nifra dev` and `nifra check` enforce them
10707
11104
  like the default folders.
10708
11105
 
10709
- ```ts
10710
-
11106
+ ```json
11107
+ {
11108
+ "nifra": {
11109
+ "zones": {
11110
+ "frontend": ["src/ui"],
11111
+ "backend": ["server"]
11112
+ }
11113
+ }
11114
+ }
10711
11115
  ```
10712
11116
 
10713
11117
  `nifra migrate layout --zones` writes those entries for you: every module the
@@ -10718,9 +11122,10 @@ overrides it, so a backend file can sit in a frontend folder without moving.
10718
11122
 
10719
11123
  The command exits `0` when nothing needs a decision. A step with a known command,
10720
11124
  such as drafting an output schema for a backend half it did not write, is listed under
10721
- `next` and in `followUps` with `--json`, and does not fail it.
10722
- An issue (an import it could not place, a frontend that still uses a moved name at runtime)
10723
- exits `1`.
11125
+ `next` and in `followUps` with `--json`, and does not fail it;
11126
+ so is a moved path a module names only in comments, which is worth updating but changes
11127
+ nothing that runs. An issue (an import it could not place, a frontend that still uses a moved
11128
+ name at runtime, a moved path written in code or a string) exits `1`.
10724
11129
 
10725
11130
  5.0 refuses a route file that still exports a server name: `nifra build` and the
10726
11131
  server stop on it, and `nifra check` reports it as NF-C041.
@@ -10748,17 +11153,30 @@ browser call to `/api` reaches page routing. `nifra migrate layout` adds
10748
11153
  `nifra check` reports a framework config that sets none (NF-C035).
10749
11154
 
10750
11155
  ```ts
11156
+ // doc-check: skip - backend/framework.ts
11157
+ export { reactAdapter as adapter } from "@nifrajs/web-react"
10751
11158
 
11159
+ // Serve backend/app.ts at /api, as 3.x and 4.x did by default. "" keeps it loader-only.
11160
+ export const apiPrefix = "/api"
10752
11161
  ```
10753
11162
 
10754
11163
  With both `nifra.config.ts` and `backend/framework.ts`, every command
10755
11164
  takes `apiPrefix`, `apiStrip`, `mounts`, `csp`,
10756
- `nonce`, `serverComponents` and `use` from
10757
- `backend/framework.ts` when `nifra.config.ts` leaves them unset. The
11165
+ `nonce`, `serverComponents`, `use` and
11166
+ `publicEnvPrefix` from `backend/framework.ts` when
11167
+ `nifra.config.ts` leaves them unset. The
10758
11168
  backend sees each request's full path unless `apiStrip` is on, so its routes are
10759
11169
  registered under the prefix; `nifra routes` marks one outside it as in-process
10760
11170
  only, and `nifra dev` and `nifra build` warn about it.
10761
11171
 
11172
+ An app that strips the prefix itself, with a `Proxy` or a wrapper around the
11173
+ backend's `fetch` that cuts `/api` before routing, gets that warning
11174
+ for every route: the check reads the registered paths, and a rewrite at run time is invisible
11175
+ to it. Delete the wrapper and export `apiStrip = true` beside
11176
+ `apiPrefix`, which does the same cut where the framework can see it. A second
11177
+ prefix the wrapper served (a `/v1` alias, a webhook path) becomes an entry in
11178
+ `mounts`.
11179
+
10762
11180
  ### 5. Review the 5.0 defaults that changed
10763
11181
 
10764
11182
  -
@@ -10783,9 +11201,31 @@ request.
10783
11201
  `nifra check` fails a secret comparison (NF-S002) outside browser code of a web
10784
11202
  app.
10785
11203
 
11204
+ From 3.x, two 4.0 changes also show up in tests and tooling rather than in pages:
11205
+
11206
+ -
11207
+ Page data is handed over in one
11208
+ `<script type="application/json" id="__nifra-handover">`, not a script that
11209
+ assigns `window.__NIFRA_DATA__`. A test that read the data out of the HTML
11210
+ parses that element (`HANDOVER_ID` from `@nifrajs/web`).
11211
+
11212
+ -
11213
+ `x-nifra-isr-revalidate` and `x-nifra-isr-tags` are set only under a
11214
+ cache wrapper such as `withISR`, which removes them before responding. A test
11215
+ that read a page's TTL from them on an unwrapped app reads nothing.
11216
+
10786
11217
  `nifra upgrade` prints the full list with the finding or the one-line change that
10787
11218
  keeps the 4.x behavior for each.
10788
11219
 
11220
+ Past 5.0, 5.1 adds one change a frontend on another origin sees. A route with a
11221
+ `body` schema answers a urlencoded, multipart or `text/plain` body whose
11222
+ `Origin` names another site with `403 forbidden_origin`, before reading
11223
+ it. List that frontend&rsquo;s origin, or an identity provider&rsquo;s for a
11224
+ `form_post` callback, in the `formOrigins` server option (an array of
11225
+ exact origins or a function; `@nifrajs/edge` takes it too). JSON bodies are
11226
+ unchanged. [Security](/docs/security) covers what the check leaves to
11227
+ `csrf()`.
11228
+
10789
11229
  ### 6. Run the release gates
10790
11230
 
10791
11231
  -
@@ -10949,7 +11389,7 @@ Nifra's client router - `Link` + hover/focus prefetch, scroll restoration
10949
11389
  The biggest change: data fetching becomes a typed `loader` that calls your backend
10950
11390
  in-process during SSR - no `fetch` to your own API, no untyped JSON.
10951
11391
 
10952
- ```ts
11392
+ ```tsx
10953
11393
  // Next.js - app/users/[id]/page.tsx
10954
11394
  export default async function Page({ params }) {
10955
11395
  const res = await fetch(`https://api/users/${params.id}`)
@@ -11023,6 +11463,11 @@ mount small and temporary, and use typed routes for every migrated endpoint.
11023
11463
  `stripPrefix: true` when the legacy app declares paths relative to its mount point.
11024
11464
  The platform object is forwarded as the second argument when the runtime supplies one.
11025
11465
 
11466
+ A mounted fetch handler carries HTTP only. A WebSocket upgrade under the mount reaches it as
11467
+ an ordinary request and never becomes a socket, so keep the legacy app&apos;s sockets on its own
11468
+ server until they move to `app.ws()` routes (see
11469
+ [WebSockets in a composed app](/docs/websockets#composed)).
11470
+
11026
11471
  ```ts
11027
11472
  import { Hono } from "hono"
11028
11473
  import { server } from "@nifrajs/core/server"
@@ -11212,7 +11657,7 @@ only on Node, where `fetch` is undici.
11212
11657
  `GET /orders` reads through the cache, enqueues a job into a Postgres-backed store,
11213
11658
  and a separate worker process runs it. In Jaeger it is one trace:
11214
11659
 
11215
- ```ts
11660
+ ```text
11216
11661
  GET /orders orders-api server
11217
11662
  pg.query SELECT orders orders-api client (the cache loader)
11218
11663
  cache wrap orders-api internal outcome=miss
@@ -11718,12 +12163,12 @@ yes
11718
12163
  A file outside those folders joins a side with a suffix: `x.frontend.ts`,
11719
12164
  `x.backend.ts` or `x.shared.ts`. A workspace package declares its side
11720
12165
  in its `package.json`:
11721
- `{'"nifra": { "environment": "frontend" | "backend" | "shared" | "library" }'}`.
12166
+ `"nifra": { "environment": "frontend" | "backend" | "shared" | "library" }`.
11722
12167
  A file in no zone is a build error, so nothing is ever classified by accident.
11723
12168
 
11724
12169
  A package whose entries run on different sides gives each export subpath its own:
11725
12170
 
11726
- ```ts
12171
+ ```json
11727
12172
  {
11728
12173
  "name": "@shop/payments",
11729
12174
  "exports": {
@@ -11752,7 +12197,7 @@ an error.
11752
12197
  The app's own `package.json` can set sides too, so a folder that has to stay
11753
12198
  where it is, or a family of workspace packages, needs no edit of its own:
11754
12199
 
11755
- ```ts
12200
+ ```json
11756
12201
  {
11757
12202
  "name": "my-app",
11758
12203
  "nifra": {
@@ -11774,7 +12219,7 @@ frontend folder. One path listed under two sides is refused. Builds, dev servers
11774
12219
  `nifra check` and the editor plugin all read this setting.
11775
12220
 
11776
12221
  A project that serves no pages has no browser, so the zones do not apply to it. Declare that
11777
- in its `package.json` with `{'"nifra": { "kind": "api" }'}`:
12222
+ in its `package.json` with `"nifra": { "kind": "api" }`:
11778
12223
  `nifra check` then skips the zone checks and the server-only import check there,
11779
12224
  and treats every file as server code. It is read from the nearest `package.json`
11780
12225
  and only takes values `"api"` and `"web"`. A directory with web config
@@ -11842,7 +12287,7 @@ and `Route.ComponentProps` types `data` as exactly what
11842
12287
  `loaderOutput` lets through. `nifra dev`, `nifra build`,
11843
12288
  `nifra check` and `nifra types` write these files under
11844
12289
  `.nifra/types`; the app's `tsconfig.json` resolves them with
11845
- `{'"rootDirs": [".", "./.nifra/types"]'}`.
12290
+ `"rootDirs": [".", "./.nifra/types"]`.
11846
12291
 
11847
12292
  ### What may import what
11848
12293
 
@@ -11893,7 +12338,7 @@ page, `frontend/` or `shared/` fails the build, optional access (
11893
12338
  -
11894
12339
  **The build scans what it emits.** A client bundle, a public file or a prerendered page
11895
12340
  that contains what looks like a credential fails the build. A label in a message catalog (
11896
- `{'{ password: "Password" }'}`) and a documented placeholder (
12341
+ `{ password: "Password" }`) and a documented placeholder (
11897
12342
  `your-api-key`) are text, not credentials.
11898
12343
 
11899
12344
  The same rules run in `nifra dev` (a refused module is answered with a 403 before
@@ -11919,7 +12364,7 @@ needs a hand, such as an alias with no target that covers a moved file, a specif
11919
12364
  names nothing installed, or a sibling workspace package that names a moved file. It never
11920
12365
  edits files outside the app.
11921
12366
 
11922
- An API-only app, one that declares `{'"nifra": { "kind": "api" }'}` or has no web
12367
+ An API-only app, one that declares `"nifra": { "kind": "api" }` or has no web
11923
12368
  config, no `routes/` and a `backend.ts` that exports
11924
12369
  `backend`, migrates as one: only
11925
12370
  `backend.ts` moves, to `backend/app.ts`, with the imports from it and
@@ -12270,8 +12715,10 @@ The tooling reads the backend `backend/app.ts` exports. An app that
12270
12715
  `implement`s a contract somewhere else, such as a `createApp(deps)`
12271
12716
  factory, is invisible to the contract lock and the route lints until that file serves it.
12272
12717
  `nifra check` names each implemented operation the backend does not serve
12273
- (NF-C039), and counts them when there is no `backend/app.ts` at all. Export the
12274
- same app built with stand-in dependencies:
12718
+ (NF-C039), and counts them when there is no `backend/app.ts` at all. It reads a
12719
+ contract imported from a workspace package through that package&apos;s
12720
+ `exports`; a package installed from a registry is never read, and the check says
12721
+ so rather than passing it. Export the same app built with stand-in dependencies:
12275
12722
 
12276
12723
  ```ts
12277
12724
  // backend/app.ts - the backend nifra's tooling reads
@@ -12309,7 +12756,7 @@ The same routes and schemas feed coding agents. `nifra context` prints the live
12309
12756
  API surface as compact text, and `nifra mcp` serves it over the Model Context
12310
12757
  Protocol so Claude Code or Cursor read the real contract instead of guessing.
12311
12758
 
12312
- ```ts
12759
+ ```sh
12313
12760
  $ nifra context # the same contract as compact text - pipe into any agent prompt
12314
12761
  GET /users/:id → params { id: string } response { id, name, role }
12315
12762
 
@@ -12368,7 +12815,7 @@ executor with nothing skipped.
12368
12815
 
12369
12816
  ### Run it
12370
12817
 
12371
- ```ts
12818
+ ```sh
12372
12819
  # What does this project prove right now?
12373
12820
  nifra levels
12374
12821
 
@@ -12379,7 +12826,7 @@ nifra levels --min 2
12379
12826
  nifra levels --json
12380
12827
  ```
12381
12828
 
12382
- ```ts
12829
+ ```text
12383
12830
  L0 typed contract ok
12384
12831
  L1 route assurance ok
12385
12832
  L2 capability lockfile ok
@@ -12475,8 +12922,11 @@ and says which.
12475
12922
  The count does not fail a level on its own. To make L1 require enforcement, add a
12476
12923
  `baseline` rule selecting `hasResponse: true`: unlike
12477
12924
  `rules`, where the first match owns a route, a baseline rule is checked on every
12478
- route it matches, so one entry covers every class. `nifra assure --strict` also fails
12479
- while any declared route is typed-only or warn-only.
12925
+ route it matches, so one entry covers every class. A new app from `create-nifra`
12926
+ ships this baseline in its `nifra.assurance.ts`, beside the
12927
+ `responseContract("enforce")` its backend installs.
12928
+ `nifra assure --strict` also fails while any declared route is typed-only or
12929
+ warn-only.
12480
12930
 
12481
12931
  ```ts
12482
12932
  // nifra.assurance.ts
@@ -13657,6 +14107,9 @@ remember them. It does three things and exits non-zero if any fails:
13657
14107
  a screen that expects the wrong shape is a type error. Running the typecheck is what turns that latent
13658
14108
  guarantee into an enforced one. TypeScript sources with no `tsconfig.json` beside them fail this step,
13659
14109
  as a missing `typescript` install does: nothing typechecked them. A JavaScript-only project skips it.
14110
+ Every project `tsconfig.json` references is typechecked too, each as its own program; a project that
14111
+ splits its code across sibling configs lists them in `nifra.check.json`:
14112
+ `{ "tsconfigs": ["tsconfig.json", "tsconfig.server.json"] }`. A zoned file no program reads fails it.
13660
14113
  2. **Typed-client lint** - flags any hand-rolled `fetch()` to your own API (a relative URL like
13661
14114
  `fetch("/users")`), which bypasses the typed client so the compiler can't see the drift. External
13662
14115
  absolute-URL fetches are not flagged.
@@ -14708,6 +15161,17 @@ locales.documentMeta("ur") // { lang: "ur-PK", dir: "rtl" }
14708
15161
  Guard a `[lang]` route segment with `matchSegment()` in `routes/[lang]/_middleware.ts`: an unknown or
14709
15162
  draft value answers 404, and the default's prefix (`/en/...`) or a wrong case redirects.
14710
15163
 
15164
+ A page that exists in some locales only is declared once, with
15165
+ `defineI18nRouting(locales, { pageLocales: (pathname) => K[] | undefined })`: `matchSegment` answers
15166
+ 404 for the other locales, `alternates` lists only the page's own, `localesOf(path)` names them, and
15167
+ `localizePathname(path, locale, { fallback: "default" })` links to the default locale's page where the
15168
+ page is missing.
15169
+
15170
+ Register the router once, as `export const i18n = urls` in `backend/framework.ts`, and `@nifrajs/web`
15171
+ sets every document's `<html lang dir>` and `Content-Language` from it, guards `[lang]` and `[[lang]]`
15172
+ routes with `matchSegment`, and each adapter's `useLocale()` and `<I18nProvider>` read the page's
15173
+ locale.
15174
+
14711
15175
  ## Messages
14712
15176
 
14713
15177
  `createFormatter(locale, messages, options)` formats ICU messages: interpolation, `plural`,
@@ -14738,13 +15202,44 @@ entry exports a `rich()` that returns framework nodes (Svelte: `<Rich>` with one
14738
15202
  `localeCookie(name, locale)` is the browser half of the detector's `persist` cookie: assign it to
14739
15203
  `document.cookie` in a language switcher and it is byte-identical to the detector's `Set-Cookie`.
14740
15204
 
15205
+ ## Copy tables
15206
+
15207
+ `defineCopy(locales)` from `@nifrajs/i18n/copy` keeps a page's text and its translations beside the
15208
+ code that shows it, with no key to name. The default locale's value is required, an undeclared locale
15209
+ is a type error, and every other value has the default's shape. `copy.pick(table, locale)` falls back
15210
+ along `locales.chain()` and fires `onMissing` once per table and locale; `copy.format()` reads an ICU
15211
+ message.
15212
+
15213
+ ```ts
15214
+ import { defineCopy } from "@nifrajs/i18n/copy"
15215
+
15216
+ export const copy = defineCopy(locales, { onMissing: reportMissingCopy })
15217
+ export const TITLE = copy({ en: "Bicycle", hi: "साइकिल", ta: "மிதிவண்டி" })
15218
+ export const FAQ = copy.id("shop.faq", { en: ["Brakes?", "Gears?"], hi: ["ब्रेक?", "गियर?"] })
15219
+
15220
+ copy.pick(FAQ, "ta") // ["Brakes?", "Gears?"], from en
15221
+ ```
15222
+
15223
+ A production `@nifrajs/web` client build moves each table's values into one chunk per locale, so a
15224
+ page's JavaScript carries only the copy of the locale it renders in; the server keeps every table. It
15225
+ reads tables statically (literals, lists and blocks of them, same-module constants) with the app's
15226
+ TypeScript; a table written any other way keeps every locale in the bundle. `nifra i18n check` checks
15227
+ the tables of a `copy` export like catalogs, at each table's `file:line`; `tablesToCatalogs()` from
15228
+ `@nifrajs/i18n/check` is the pure transpose.
15229
+
14741
15230
  ## Checking catalogs
14742
15231
 
14743
15232
  `checkCatalogs({ locales, catalogs, ignore })` from `@nifrajs/i18n/check` reports coverage, missing
14744
15233
  and unused keys, ICU syntax errors, placeholder and rich-tag parity with the default message, plural
14745
15234
  cases the locale's grammar needs, script purity (`Intl.Locale(tag).maximize().script` against Unicode
14746
15235
  script properties - a Telugu sign in Gujarati, a Cyrillic `е` in English), and untranslated messages.
14747
- It is pure; `nifra i18n check [entry]` runs it over the module exporting `locales` and `catalogs`.
15236
+ It also catches partly translated text in a locale that does not write in Latin: `latin-share` reports
15237
+ a message of 6 words or more that is mostly Latin-script words (`latinWords` lists the brands a
15238
+ translation keeps), and each locale's coverage carries its `latinShare`; `volume` reports a long
15239
+ message translated to under a third of its length. `rules` adds the app's own checks, reported as
15240
+ `custom:<code>`.
15241
+ It is pure; `nifra i18n check [entry]` runs it over the module exporting `locales` and `catalogs`,
15242
+ and passes the rest of the options from its `check` export.
14748
15243
 
14749
15244
  ## Locale detection
14750
15245
 
@@ -17085,7 +17580,7 @@ done-gate, or `nifra mcp` to give the agent live project tools.
17085
17580
 
17086
17581
  ## @nifrajs/web
17087
17582
 
17088
- `ACTION_GLOBAL`, `Action`, `BOUNDARY_GLOBAL`, `BackendOnly`, `Blocker`, `BlockerController`, `BlockerFunction`, `BlockerLocation`, `BlockerState`, `Boundary`, `BoundaryDescriptor`, `BoundaryError`, `BoundaryMode`, `BoundaryRegistration`, `BoundaryRequestCtx`, `BoundaryState`, `BoundaryStates`, `BoundaryStatus`, `BrowserNavigate`, `CacheStore`, `CachedResponse`, `CdnPurgeOutcome`, `CdnPurgeTarget`, `ClientAction`, `ClientActionArgs`, `ClientActionResult`, `ClientLoader`, `ClientLoaderArgs`, `ClientRequestBody`, `ClientRouteHooks`, `ClientRouter`, `ClientRouterOptions`, `CreateCspPolicyOptions`, `CreateNonceResolverOptions`, `CreateWebAppOptions`, `CspHeaderContext`, `CspPolicy`, `CssLoadingMode`, `DATA_GLOBAL`, `DATA_HEADER`, `DEFAULT_CSS_LOADING`, `DEFAULT_DEV_PORT`, `DRAFT_COOKIE`, `Deferred`, `DehydratedState`, `DocumentParts`, `DraftCookieControls`, `DynamicBoundary`, `DynamicBoundaryBatch`, `EnableDraftOptions`, `FetchRouteData`, `Fetcher`, `FetcherState`, `FontDisplay`, `FontFace`, `FontPreloadInput`, `FontSource`, `GenerateClientEntryOptions`, `GenerateRouteSearchTypesOptions`, `GenerateServerManifestOptions`, `GetStaticPaths`, `HANDOVER_ID`, `HtmlSanitizer`, `IDLE_BLOCKER`, `ISRApp`, `ISROptions`, `ISRPlatform`, `ISRQuery`, `ISRStoreOp`, `ISR_REVALIDATE_HEADER`, `ISR_REVALIDATE_TAGS_HEADER`, `ISR_STATUS_HEADER`, `InertScriptType`, `InfiniteData`, `InfiniteQueryHandle`, `InfiniteQueryOptions`, `InterceptBoundary`, `KVCacheStore`, `KVCacheStoreOptions`, `KVNamespaceLike`, `LAYOUT_DATA_GLOBAL`, `LayoutEntry`, `LinkDescriptor`, `Loader`, `LoaderContext`, `LoaderResponseControls`, `LoadingEntry`, `Manifest`, `MatchChain`, `MemoryCacheStore`, `MemoryCacheStoreOptions`, `MemoryStaticBoundaryCache`, `Meta`, `MetaArgs`, `MetaDescriptor`, `MetaInput`, `MiddlewareOutcome`, `MountRouterOptions`, `MutationCallbacks`, `MutationHandle`, `MutationState`, `MutationStatus`, `NAV_FROM_HEADER`, `NavigateFunction`, `NavigateOptions`, `NavigateSearchOf`, `NavigateTargetInput`, `NonceContext`, `NonceGenerator`, `NonceHeader`, `NonceHeaderContext`, `NonceResolver`, `NotFoundEntry`, `NotFoundScope`, `OpenGraphInput`, `PRE_HYDRATION_GUARD`, `PendingBoundary`, `PrefetchMode`, `PreviewEndpointOptions`, `PublicDirCache`, `QueryClient`, `QueryClientOptions`, `QueryHandle`, `QueryOptions`, `QueryState`, `QueryStatus`, `REDIRECT_HEADER`, `RETAIN_HEADER`, `REVALIDATE_HEADER`, `ROOT_ATTRIBUTE`, `ROUTE_GLOBAL`, `RedirectOptions`, `RenderAdapter`, `RenderAdapterConformanceError`, `RenderAdapterConformanceFixture`, `RenderAssemblyCache`, `RenderPageInput`, `RenderPageOptions`, `RenderProps`, `RenderStreamOptions`, `RenderedPage`, `RevalidateEndpointOptions`, `RevalidateResult`, `RevalidateTags`, `RevalidateTagsInput`, `RouteEntry`, `RouteMatch`, `RouteMiddleware`, `RouteModule`, `RoutePattern`, `RouteSearch`, `RouterState`, `SERVER_FN_MODULE`, `STATUS_HEADER`, `SanitizedHtml`, `ScriptDescriptor`, `SearchOf`, `ServePublicDirOptions`, `ShouldRevalidate`, `ShouldRevalidateArgs`, `SsrModuleLoader`, `StaticBoundary`, `StaticBoundaryCache`, `StaticBoundaryImportEdge`, `StaticBoundaryRoot`, `StaticCtx`, `StaticPath`, `StaticPaths`, `StaticRoutes`, `StatusPageOptions`, `Submission`, `SubmitOptions`, `TrustedHtml`, `UIMatch`, `UnsafeScriptDescriptor`, `assertCssLoadingCompatible`, `assertRenderAdapterConformance`, `assertStaticBoundaryImports`, `boundaryDescriptors`, `boundaryModeKey`, `buildManifest`, `canonical`, `createClientRouter`, `createCspPolicy`, `createMatcher`, `createMutation`, `createNonceResolver`, `createQueryClient`, `createWebApp`, `defer`, `disableDraft`, `enableDraft`, `enumerateStaticRoutes`, `filePathToPattern`, `filePathToPatterns`, `fontFace`, `fontPreload`, `generateClientEntry`, `generateRouteSearchTypes`, `generateServerManifest`, `getBrowserNavigate`, `gone`, `hashQueryKey`, `isCacheablePage`, `isDraftEnabled`, `jsonLd`, `mergeHeads`, `nifraScriptHashes`, `normalizeCssLoading`, `notFound`, `openGraph`, `previewEndpoint`, `redirect`, `registerBlocker`, `renderPage`, `renderPageResult`, `resolveChainMeta`, `resolveDynamicBoundaries`, `resolveMeta`, `resolveNavigate`, `resolvePublicPath`, `resolveStaticBoundaries`, `revalidate`, `revalidateEndpoint`, `sanitizeHtml`, `sanitizedHtml`, `searchOf`, `searchOfChain`, `serializeData`, `serializeSearch`, `servePublicDir`, `setBlockerController`, `setBrowserNavigate`, `setSsrModuleLoader`, `ssrModuleLoader`, `startDynamicBoundaries`, `statusPage`, `trustHtml`, `unsafeInlineScript`, `webProjectEvidence`, `withISR`
17583
+ `ACTION_GLOBAL`, `Action`, `BOUNDARY_GLOBAL`, `BackendOnly`, `Blocker`, `BlockerController`, `BlockerFunction`, `BlockerLocation`, `BlockerState`, `Boundary`, `BoundaryDescriptor`, `BoundaryError`, `BoundaryMode`, `BoundaryRegistration`, `BoundaryRequestCtx`, `BoundaryState`, `BoundaryStates`, `BoundaryStatus`, `BrowserNavigate`, `CacheStore`, `CachedResponse`, `CdnPurgeOutcome`, `CdnPurgeTarget`, `ClientAction`, `ClientActionArgs`, `ClientActionResult`, `ClientLoader`, `ClientLoaderArgs`, `ClientRequestBody`, `ClientRouteHooks`, `ClientRouter`, `ClientRouterOptions`, `CreateCspPolicyOptions`, `CreateNonceResolverOptions`, `CreateWebAppOptions`, `CspHeaderContext`, `CspPolicy`, `CssLoadingMode`, `DATA_GLOBAL`, `DATA_HEADER`, `DEFAULT_CSS_LOADING`, `DEFAULT_DEV_PORT`, `DRAFT_COOKIE`, `Deferred`, `DehydratedState`, `DocumentParts`, `DraftCookieControls`, `DynamicBoundary`, `DynamicBoundaryBatch`, `EnableDraftOptions`, `FetchRouteData`, `Fetcher`, `FetcherState`, `FontDisplay`, `FontFace`, `FontPreloadInput`, `FontSource`, `GenerateClientEntryOptions`, `GenerateRouteSearchTypesOptions`, `GenerateServerManifestOptions`, `GetStaticPaths`, `HANDOVER_ID`, `HtmlSanitizer`, `IDLE_BLOCKER`, `ISRApp`, `ISROptions`, `ISRPlatform`, `ISRQuery`, `ISRStoreOp`, `ISR_REVALIDATE_HEADER`, `ISR_REVALIDATE_TAGS_HEADER`, `ISR_STATUS_HEADER`, `InertScriptType`, `InfiniteData`, `InfiniteQueryHandle`, `InfiniteQueryOptions`, `InterceptBoundary`, `KVCacheStore`, `KVCacheStoreOptions`, `KVNamespaceLike`, `LAYOUT_DATA_GLOBAL`, `LOCALES_GLOBAL`, `LayoutEntry`, `LinkDescriptor`, `Loader`, `LoaderContext`, `LoaderResponseControls`, `LoadingEntry`, `Manifest`, `MatchChain`, `MemoryCacheStore`, `MemoryCacheStoreOptions`, `MemoryStaticBoundaryCache`, `Meta`, `MetaArgs`, `MetaDescriptor`, `MetaInput`, `MiddlewareOutcome`, `MountRouterOptions`, `MutationCallbacks`, `MutationHandle`, `MutationState`, `MutationStatus`, `NAV_FROM_HEADER`, `NavigateFunction`, `NavigateOptions`, `NavigateSearchOf`, `NavigateTargetInput`, `NonceContext`, `NonceGenerator`, `NonceHeader`, `NonceHeaderContext`, `NonceResolver`, `NotFoundEntry`, `NotFoundScope`, `OpenGraphInput`, `PRE_HYDRATION_GUARD`, `PageLocale`, `PageLocales`, `PendingBoundary`, `PrefetchMode`, `PreviewEndpointOptions`, `PublicDirCache`, `QueryClient`, `QueryClientOptions`, `QueryHandle`, `QueryOptions`, `QueryState`, `QueryStatus`, `REDIRECT_HEADER`, `RETAIN_HEADER`, `REVALIDATE_HEADER`, `ROOT_ATTRIBUTE`, `ROUTE_GLOBAL`, `RedirectOptions`, `RenderAdapter`, `RenderAdapterConformanceError`, `RenderAdapterConformanceFixture`, `RenderAssemblyCache`, `RenderPageInput`, `RenderPageOptions`, `RenderProps`, `RenderStreamOptions`, `RenderedPage`, `RevalidateEndpointOptions`, `RevalidateResult`, `RevalidateTags`, `RevalidateTagsInput`, `RouteEntry`, `RouteMatch`, `RouteMiddleware`, `RouteModule`, `RoutePattern`, `RouteSearch`, `RouterState`, `SERVER_FN_MODULE`, `STATUS_HEADER`, `SanitizedHtml`, `ScriptDescriptor`, `SearchOf`, `ServePublicDirOptions`, `ShouldRevalidate`, `ShouldRevalidateArgs`, `SsrModuleLoader`, `StaticBoundary`, `StaticBoundaryCache`, `StaticBoundaryImportEdge`, `StaticBoundaryRoot`, `StaticCtx`, `StaticPath`, `StaticPaths`, `StaticRoutes`, `StatusPageOptions`, `Submission`, `SubmitOptions`, `TrustedHtml`, `UIMatch`, `UnsafeScriptDescriptor`, `WebAppI18n`, `assertCssLoadingCompatible`, `assertRenderAdapterConformance`, `assertStaticBoundaryImports`, `boundaryDescriptors`, `boundaryModeKey`, `buildManifest`, `canonical`, `createClientRouter`, `createCspPolicy`, `createMatcher`, `createMutation`, `createNonceResolver`, `createQueryClient`, `createWebApp`, `defer`, `disableDraft`, `enableDraft`, `enumerateStaticRoutes`, `filePathToPattern`, `filePathToPatterns`, `fontFace`, `fontPreload`, `generateClientEntry`, `generateRouteSearchTypes`, `generateServerManifest`, `getBrowserNavigate`, `gone`, `hashQueryKey`, `isCacheablePage`, `isDraftEnabled`, `jsonLd`, `localeOfProps`, `mergeHeads`, `nifraScriptHashes`, `normalizeCssLoading`, `notFound`, `openGraph`, `pageLocaleIn`, `previewEndpoint`, `redirect`, `registerBlocker`, `renderPage`, `renderPageResult`, `resolveChainMeta`, `resolveDynamicBoundaries`, `resolveMeta`, `resolveNavigate`, `resolvePublicPath`, `resolveStaticBoundaries`, `revalidate`, `revalidateEndpoint`, `sanitizeHtml`, `sanitizedHtml`, `searchOf`, `searchOfChain`, `serializeData`, `serializeSearch`, `servePublicDir`, `setBlockerController`, `setBrowserNavigate`, `setSsrModuleLoader`, `ssrModuleLoader`, `startDynamicBoundaries`, `statusPage`, `trustHtml`, `unsafeInlineScript`, `webProjectEvidence`, `withISR`
17089
17584
 
17090
17585
  ## @nifrajs/web-preact
17091
17586