@nifrajs/cli 5.3.0 → 5.4.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.
@@ -235,33 +235,15 @@ to full-stack later without a rewrite.
235
235
  -
236
236
  **Throughput - the realistic case.** Router micro-benchmarks flatter Hono (a single compiled
237
237
  regex), but a real request also pays for middleware and validation,
238
- context, and serialization. In the current matrix (median of 5 full runs) Nifra
239
- **tops the framework field on Bun** - level with Elysia on `GET /users/:id` at
240
- percentOf(
241
- httpWorkloadRps("Bun", "Nifra", "postUsers"),
242
- httpWorkloadRps("Bun", "Elysia", "postUsers"),
243
- of Elysia on the validated `POST` - and
244
- **leads every framework on Deno** on both workloads. On **Node** it
245
- **leads the framework field too** - at
246
- percentOf(
247
- httpWorkloadRps("Node", "Nifra", "postUsers"),
248
- httpWorkloadRps("Node", "Fastify", "postUsers"),
249
- of Fastify on the validated `POST` ({formatPercent(
250
- percentOf(
251
- httpWorkloadRps("Node", "Nifra", "postUsers"),
252
- httpWorkloadRps("Node", "node-raw", "postUsers"),
253
- )} of the raw-Node ceiling) and ahead on GET, with Elysia, Hono,
254
- and Express behind. In the realistic shape (security headers + CORS +
238
+ context, and serialization. In the current matrix Nifra runs **level with Elysia on Bun** -
239
+ 101% of Elysia on `GET /users/:id` and
240
+ 101% on the validated `POST` - and
241
+ **level with Fastify on Node** (98% of Fastify on GET,
242
+ 101% on the validated `POST`), with Elysia, Hono,
243
+ and Express behind. On **Deno** it runs at 97% of Elysia on
244
+ GET and 114% on the validated `POST`. In the realistic shape (security headers + CORS +
255
245
  bearer auth + cookies + validated query/body + a ~2.4 KB JSON response, measured with
256
- `oha`) Nifra runs at **{formatPercent(
257
- percentOf(
258
- httpRealworldRps("Bun", "Nifra", "get"),
259
- httpRealworldRps("Bun", "Elysia", "get"),
260
- )} of Elysia on GET and {formatPercent(
261
- percentOf(
262
- httpRealworldRps("Bun", "Nifra", "post"),
263
- httpRealworldRps("Bun", "Elysia", "post"),
264
- )} on POST**. Treat benchmark
246
+ `oha`) Nifra runs at **98% of Elysia on GET and 99% on POST**. Treat benchmark
265
247
  rows as same-run evidence, not a permanent law of nature.
266
248
 
267
249
  -
@@ -1159,7 +1141,7 @@ A strict `t.object` here would reject real traffic. A signed cookie arrives as i
1159
1141
 
1160
1142
  A `headers` schema is validated before the handler like the other slots: a missing
1161
1143
  or malformed header is a `422` (`onValidationError` receives the kind
1162
- `"headers"`), and `c.headers` becomes the schema’s typed output.
1144
+ `"headers"`), and `c.headers` becomes the schema's typed output.
1163
1145
  Every client sends headers no route declares - `host`, `user-agent`,
1164
1146
  `accept` - so a closed `t.object` validates only the names it declares,
1165
1147
  each read case-insensitively, which is also how the OpenAPI document lists them: one
@@ -2042,7 +2024,7 @@ export default {
2042
2024
  A store outage never fails a page. A read that throws, rejects, or outlives
2043
2025
  `storeTimeoutMs` is a miss and the page renders; a failed write still returns the
2044
2026
  rendered page; a failed background regeneration keeps the stale entry. Each failure goes to
2045
- `onStoreError(error, { op })`, which by default logs one line per operation
2027
+ `onStoreError(error, { op })`, which by default logs one line per operation
2046
2028
  per minute without the cache key. Set `storeTimeoutMs` for a network store, so a
2047
2029
  hung connection costs a miss rather than the request.
2048
2030
 
@@ -2135,7 +2117,7 @@ A purge is sent after the origin store is purged, coalesced for 250 ms, chunked
2135
2117
  provider's per-call limit, and retried on 429 or 5xx honoring `Retry-After`. The
2136
2118
  endpoint never reports a purge that did not happen: `202` while it is queued,
2137
2119
  `502` with `retryable` when the CDN refused it. After a mutation in app
2138
- code, `createInvalidator({ store, cdn, origin }).invalidate({ tags })`
2120
+ code, `createInvalidator({ store, cdn, origin }).invalidate({ tags })`
2139
2121
  does the same. Staleness compounds: a page can be up to the CDN's
2140
2122
  `stale-while-revalidate` older than ISR's own window.
2141
2123
 
@@ -2318,7 +2300,7 @@ else document.addEventListener("nifra:hydrated", start, { once: true })
2318
2300
  > Add interactivity to a zero-runtime vanilla page with islands - imperative DOM enhancers, no framework runtime, no hydration. Explicit code an AI (or a human) gets right first try: mount, coordinate over a typed bus, always return cleanup.
2319
2301
 
2320
2302
  A `@nifrajs/web-vanilla` page ships zero framework runtime. When one corner needs
2321
- to be interactive, you don't turn on hydration - you mount an **island**: a
2303
+ to be interactive, you don't turn on hydration - you mount an **island**: a
2322
2304
  small, plain-DOM enhancer over a server-rendered element. Explicit imperative code with no
2323
2305
  hidden reactivity - the shape an AI agent (or a human) gets right on the first try.
2324
2306
 
@@ -2337,7 +2319,7 @@ islands for widgets on an otherwise-static page.
2337
2319
 
2338
2320
  Render a `<nifra-island>` marker in your page (props are inline JSON), then
2339
2321
  bundle one entry (in `frontend/`) that calls `mountIslands`. Load it
2340
- with the `islandScripts` export of the route&apos;s `.backend.ts` half.
2322
+ with the `islandScripts` export of the route's `.backend.ts` half.
2341
2323
 
2342
2324
  ```ts
2343
2325
  // doc-check: skip - server-rendered island marker (HTML, not a checkable module).
@@ -2375,7 +2357,7 @@ function runs on soft-nav teardown; forget it and every navigation leaks the lis
2375
2357
  ### Coordinate islands with a typed bus
2376
2358
 
2377
2359
  Islands are isolated by design - each enhances one element and shares no state. When two must
2378
- talk (an &ldquo;add to cart&rdquo; button and a cart badge), use a
2360
+ talk (an "add to cart" button and a cart badge), use a
2379
2361
  `createIslandBus`: one typed channel, created once and closed over by each
2380
2362
  enhancer. No implicit global, so concurrent renders and tests never cross-talk.
2381
2363
 
@@ -2425,7 +2407,7 @@ mountIslands({ addButton, badge })
2425
2407
 
2426
2408
  ### Pattern: filter drives results
2427
2409
 
2428
- The same shape scales to any &ldquo;one island changes, another reacts&rdquo; case. Each
2410
+ The same shape scales to any "one island changes, another reacts" case. Each
2429
2411
  island owns only its own DOM; they meet on the channel, never in a shared store.
2430
2412
 
2431
2413
  ```ts
@@ -2457,7 +2439,7 @@ mountIslands({ filter, results })
2457
2439
 
2458
2440
  ### Load strategies
2459
2441
 
2460
- A marker&apos;s `data-strategy` defers its enhancer: `load` (default),
2442
+ A marker's `data-strategy` defers its enhancer: `load` (default),
2461
2443
  `idle`, `visible` (mount when it scrolls into view), or a
2462
2444
  `media` query. An island with no matching enhancer, or an invalid strategy, stays
2463
2445
  inert server-rendered HTML - forward-compatible, never a runtime error.
@@ -2511,7 +2493,7 @@ The deps array is the whole contract, and its one failure mode is catchable: a
2511
2493
  `computed` whose body reads a signal the array omits will never recompute when that
2512
2494
  signal changes. `nifra check` flags exactly that as `NF-C023` - the
2513
2495
  check reads which signals the body calls `.get()` on and compares them to the
2514
- array. A framework&apos;s auto-tracked effect gives a tool nothing to compare, which is why
2496
+ array. A framework's auto-tracked effect gives a tool nothing to compare, which is why
2515
2497
  the equivalent lint elsewhere is a best-effort warning, not a gate.
2516
2498
 
2517
2499
  ### Bind a signal to the DOM
@@ -2536,8 +2518,8 @@ label.set("world") // the <h1> updates synchronously
2536
2518
 
2537
2519
  ### Keyed lists with bindList
2538
2520
 
2539
- `bindList` keeps a container&apos;s children in sync with an array by key - a keyed
2540
- reconcile like a framework&apos;s list diff, but you spell the key out. Add, remove, and
2521
+ `bindList` keeps a container's children in sync with an array by key - a keyed
2522
+ reconcile like a framework's list diff, but you spell the key out. Add, remove, and
2541
2523
  reorder reuse the matching node (preserving focus and scroll) instead of rebuilding the list.
2542
2524
  Key by a **stable id** on the item; keying by the array index reuses the wrong
2543
2525
  node on reorder, and `nifra check` flags it as `NF-C022`.
@@ -2563,8 +2545,8 @@ todos.set([...todos.get(), { id: crypto.randomUUID(), text: "buy milk", done: fa
2563
2545
 
2564
2546
  ### Async state with resource
2565
2547
 
2566
- `resource(fetcher, [deps])` is nano&apos;s answer to &ldquo;suspense&rdquo; - an
2567
- async cell whose value is an explicit `&#123; status, value, error &#125;` union.
2548
+ `resource(fetcher, [deps])` is nano's answer to "suspense" - an
2549
+ async cell whose value is an explicit `{ status, value, error }` union.
2568
2550
  It runs the fetcher immediately and again whenever a declared dep changes, and it handles the
2569
2551
  two things people get wrong by hand: the fetcher receives an `AbortSignal`, and a
2570
2552
  superseded request is aborted with its late result dropped, so the newest fetch always wins -
@@ -2593,7 +2575,7 @@ userId.set(2) // refetches; the deps array is what NF-C023 checks against the fe
2593
2575
  ```
2594
2576
 
2595
2577
  The deps array is checked exactly like `computed`: a `resource` whose
2596
- fetcher reads a signal the array omits won&apos;t refetch when it changes, and
2578
+ fetcher reads a signal the array omits won't refetch when it changes, and
2597
2579
  `nifra check` flags it as `NF-C023`. Bind it to the DOM with
2598
2580
  `bindResource`, which dispatches on `status` - one handler per state,
2599
2581
  `ready` required, so a still-loading value can never render as a stray
@@ -2624,7 +2606,7 @@ const off = bindResource(document.querySelector("[data-user]")!, user, {
2624
2606
  nano owns state and DOM edges; an [island](/docs/islands) owns mount and teardown.
2625
2607
  Put the signals in the enhancer, collect every disposer, and return one cleanup that calls
2626
2608
  them all. Scaffold this shape with
2627
- `nifra_scaffold &#123; path, variant: "stateful" &#125;` on a vanilla
2609
+ `nifra_scaffold { path, variant: "stateful" }` on a vanilla
2628
2610
  project - it emits the golden pattern below.
2629
2611
 
2630
2612
  ```ts
@@ -2662,9 +2644,9 @@ mountIslands({ todos })
2662
2644
 
2663
2645
  ### The three checks
2664
2646
 
2665
- nano&apos;s explicitness is the whole point: because each reactive edge is a visible call, its
2647
+ nano's explicitness is the whole point: because each reactive edge is a visible call, its
2666
2648
  three mistakes are static lints with a fix recipe - the same closed loop (`scaffold`
2667
- &rarr; `check` &rarr; `fix` &rarr; `verify`) that makes the
2649
+ -> `check` -> `fix` -> `verify`) that makes the
2668
2650
  backend AI-safe, now on the frontend.
2669
2651
 
2670
2652
  -
@@ -2741,7 +2723,7 @@ NDJSON stream settles the deferred values), and it's framework-agnostic - React
2741
2723
 
2742
2724
  For server push - live feeds, progress, notifications - `sse(c, run)` returns a
2743
2725
  `text/event-stream` response a handler returns directly. Push frames with
2744
- `stream.send(&#123;&#125;)`; the connection stays open until `run`
2726
+ `stream.send({})`; the connection stays open until `run`
2745
2727
  resolves, you call `stream.close()`, or the client disconnects (
2746
2728
  `stream.signal`). It's a Web `ReadableStream` too, so it runs on Bun,
2747
2729
  Node, Deno, and the edge - no `new Function`, no per-runtime API.
@@ -2785,9 +2767,9 @@ read, or pass `Infinity` to turn the limit off.
2785
2767
  `stream.send()` is type-checked and the typed client grows
2786
2768
  `.subscribe(onEvent)` with the same event type. A route whose schema declares a
2787
2769
  `body` is a POST stream: the body validates as on any POST, and
2788
- `.subscribe(onEvent, &#123; body &#125;)` sends it. A GET stream reconnects after a
2770
+ `.subscribe(onEvent, { body })` sends it. A GET stream reconnects after a
2789
2771
  drop and resumes with `Last-Event-ID`; a POST stream does not reconnect unless you
2790
- pass `reconnect: true`, since a reconnect sends the body again. The client&apos;s
2772
+ pass `reconnect: true`, since a reconnect sends the body again. The client's
2791
2773
  `onRequest` hook runs before each connect, so a refreshed token reaches the stream.
2792
2774
 
2793
2775
  ```ts
@@ -3035,8 +3017,8 @@ deferred boundary. Put critical page data in the route `loader`; use
3035
3017
 
3036
3018
  ### Markup outside the page
3037
3019
 
3038
- Svelte&apos;s `<svelte:head>` renders into the document&apos;s
3039
- `<head>`, after the tags from the route&apos;s `meta`. The document
3020
+ Svelte's `<svelte:head>` renders into the document's
3021
+ `<head>`, after the tags from the route's `meta`. The document
3040
3022
  always has a `<title>` of its own and a browser uses the first one, so set the
3041
3023
  title in `meta`.
3042
3024
 
@@ -3050,7 +3032,7 @@ the client, with a warning in development.
3050
3032
  ### Dev HMR support
3051
3033
 
3052
3034
  Dev HMR works for all five adapters through `createViteDevServer` and the
3053
- framework&apos;s Vite plugin. React, Preact, and Vue preserve edited component state. Solid
3035
+ framework's Vite plugin. React, Preact, and Vue preserve edited component state. Solid
3054
3036
  and Svelte update live without a full page reload, and the edited component may remount. Full
3055
3037
  matrix in [Dev & HMR](/docs/dev).
3056
3038
 
@@ -3092,9 +3074,9 @@ app
3092
3074
  app.use((a) => a.decorate("db", db).derive((c) => ({ now: Date.now() })))
3093
3075
  ```
3094
3076
 
3095
- ### What a parent&rsquo;s use() covers
3077
+ ### What a parent's use() covers
3096
3078
 
3097
- A `group()` scope inherits the parent&rsquo;s chain as it stands at the call. A
3079
+ A `group()` scope inherits the parent's chain as it stands at the call. A
3098
3080
  `merge()`d server was compiled on its own, so its routes keep _their_ chain. Only
3099
3081
  what the parent installed **before** the `group()` or `merge()` counts.
3100
3082
 
@@ -3130,14 +3112,14 @@ yes, when the route declares capabilities and has no ledger of its own
3130
3112
 
3131
3113
  yes
3132
3114
 
3133
- the merged server&rsquo;s own - a route declaring `idempotency` without one is
3115
+ the merged server's own - a route declaring `idempotency` without one is
3134
3116
  refused at registration
3135
3117
 
3136
3118
  Two checks catch the silent cases. In development and tests, `unusedScopedHooks`
3137
3119
  reports a hook followed only by `merge()` calls, and a `responseContract()`
3138
3120
  or `effectLedger()` installed after routes it would have covered.
3139
3121
  `nifra check` reports a `merge()` whose server authenticates none of its
3140
- routes while this server&rsquo;s `authenticate()` or auth plugin covers its own
3122
+ routes while this server's `authenticate()` or auth plugin covers its own
3141
3123
  (NF-C043); a module that is public on purpose takes
3142
3124
  `// nifra-expect NF-C043: <reason>` on the merge line.
3143
3125
 
@@ -3227,7 +3209,7 @@ A **WebSocket** route, listed as `WS /path`, runs the request hooks, then the
3227
3209
  authentication stages, `derive`s, `beforeHandle`s and
3228
3210
  `onError` declared before it. Its handshake runs no `around`,
3229
3211
  `afterHandle` or response hooks, but a refused handshake carries the
3230
- app&rsquo;s `responseHeaders()`.
3212
+ app's `responseHeaders()`.
3231
3213
 
3232
3214
  `nifra routes --hooks --json` writes the report; `--since <file>`
3233
3215
  prints what runs differently from a saved one. `nifra upgrade --write` saves the
@@ -3607,10 +3589,10 @@ Express, and Elysia, see [security posture, compared](/docs/security-comparison)
3607
3589
 
3608
3590
  ### Responses that cannot leak more than they declare
3609
3591
 
3610
- A `response` schema is a **lower** bound: it says &ldquo;at least these
3611
- fields&rdquo;, never &ldquo;only these&rdquo;. A handler returning a database row that satisfies
3612
- it also ships every other column, and nothing points at it - TypeScript&rsquo;s
3613
- excess-property check does not reach a handler&rsquo;s return position, and the client&rsquo;s
3592
+ A `response` schema is a **lower** bound: it says "at least these
3593
+ fields", never "only these". A handler returning a database row that satisfies
3594
+ it also ships every other column, and nothing points at it - TypeScript's
3595
+ excess-property check does not reach a handler's return position, and the client's
3614
3596
  type reports the contract rather than the bytes. So the leak is invisible from both ends, and it
3615
3597
  can appear with no code change at all: add a column, and the next deploy ships it to browsers.
3616
3598
 
@@ -3639,7 +3621,7 @@ export const app = server().use(responseContract("enforce", { extra: "strip" }))
3639
3621
  // enforce, { extra: "strip" } -> 200 {"id":"u1","name":"Ada"}
3640
3622
  ```
3641
3623
 
3642
- Not installing the plugin is &ldquo;off&rdquo;, which is exactly today&rsquo;s behaviour and
3624
+ Not installing the plugin is "off", which is exactly today's behaviour and
3643
3625
  keeps the lane out of your bundle rather than shipping a disabled branch to everyone.
3644
3626
  `"warn"` checks every response, logs the undeclared fields by name, and
3645
3627
  serves the payload **unchanged** - so turning it on in staging can never be the
@@ -3651,10 +3633,10 @@ returns it early, or `onError` answers with it; only a hand-built
3651
3633
  should cover: like
3652
3634
  `idempotency()`, the decision is made per route at registration.
3653
3635
 
3654
- By default, enforcement follows your schema&rsquo;s own semantics, because Standard Schema
3636
+ By default, enforcement follows your schema's own semantics, because Standard Schema
3655
3637
  exposes `validate` and no way to enumerate declared keys. A _stripping_ schema
3656
3638
  (Zod, Valibot) yields a cleaned value, so the extra fields are dropped. A _strict_ one
3657
- (`@nifrajs/schema`&rsquo;s `t.object`) reports them as issues, so the
3639
+ (`@nifrajs/schema`'s `t.object`) reports them as issues, so the
3658
3640
  response becomes a 500 and the detail goes to the logger, never to the caller.
3659
3641
  `{ extra: "strip" }` changes that for `t` schemas: they carry their
3660
3642
  JSON Schema, which does list the declared keys, so the payload is projected onto them - nested
@@ -3674,8 +3656,8 @@ For a metric or an alert, pass `onReport`. It receives every response the
3674
3656
  contract has something to say about: `violation` (enforce mode, a 500 went out
3675
3657
  instead), `warn` (warn mode, sent anyway, with the undeclared keys in
3676
3658
  `fields` when they are the reason) and `stripped` (enforce mode, sent
3677
- without `fields`). Each report carries the route&rsquo;s method and pattern and
3678
- the log line&rsquo;s message, never a value. A hook that throws or rejects is logged once and
3659
+ without `fields`). Each report carries the route's method and pattern and
3660
+ the log line's message, never a value. A hook that throws or rejects is logged once and
3679
3661
  changes no response.
3680
3662
 
3681
3663
  ```ts
@@ -3696,14 +3678,14 @@ export const app = server().use(
3696
3678
  )
3697
3679
  ```
3698
3680
 
3699
- A `merge()`d server&rsquo;s routes are covered by a contract the parent installed
3681
+ A `merge()`d server's routes are covered by a contract the parent installed
3700
3682
  before the merge, as long as the route declares a response and its own server installed none.
3701
- See [what a parent&rsquo;s use() covers](/docs/plugins#parent-use).
3683
+ See [what a parent's use() covers](/docs/plugins#parent-use).
3702
3684
 
3703
3685
  The check itself is essentially free: with a compiled validator it measures in the
3704
3686
  ~100ns-per-response range, and a realistic middleware-carrying route benchmarks within noise
3705
3687
  of the same route with no contract at all, on Bun and Node alike. What a contracted route
3706
- does give up is the bare-route fused lane - the check needs the handler&rsquo;s value before
3688
+ does give up is the bare-route fused lane - the check needs the handler's value before
3707
3689
  it becomes bytes - and a route with any middleware, derive, or lifecycle hook has already
3708
3690
  left that lane. If a route looks like production, the contract costs nothing: declare it.
3709
3691
 
@@ -3843,14 +3825,14 @@ app.post(
3843
3825
  ```
3844
3826
 
3845
3827
  `t.file` checks the size before it reads a byte, and `accept` is matched
3846
- against the file&rsquo;s **leading bytes**, never the type the client claimed: a script renamed
3828
+ against the file's **leading bytes**, never the type the client claimed: a script renamed
3847
3829
  `photo.png` fails validation. With `accept` set, the file the handler
3848
3830
  receives carries the detected type. A type that has no signature to check (`text/csv`,
3849
3831
  `image/svg+xml`) is refused when the schema is built, not silently let through. Text
3850
3832
  fields are coerced from their string form, a repeated field becomes a list, and a field the form
3851
3833
  does not declare fails validation unless `additionalProperties` is set.
3852
3834
 
3853
- The body is bounded before any of it is validated. The route&rsquo;s `bodyLimit` caps
3835
+ The body is bounded before any of it is validated. The route's `bodyLimit` caps
3854
3836
  the whole request; `maxFields` (100), `maxFiles` (10),
3855
3837
  `maxFieldBytes` (64 KiB) and `maxFileBytes` cap what it may carry. A request
3856
3838
  over one is answered `413` with the limit it crossed (`payload_too_large`,
@@ -3903,14 +3885,14 @@ format behind it, and `application/zip` is also what a `.docx` or
3903
3885
 
3904
3886
  -
3905
3887
  **
3906
- `file.name` is the client&rsquo;s.
3888
+ `file.name` is the client's.
3907
3889
  **
3908
3890
  Path separators and control characters are removed, and that is all. Generate the storage key;
3909
3891
  never build a path from the name.
3910
3892
 
3911
3893
  -
3912
3894
  **
3913
- Without `accept`, `file.type` is the client&rsquo;s too.
3895
+ Without `accept`, `file.type` is the client's too.
3914
3896
  **
3915
3897
  Some runtimes derive it from the file extension. Only a type that `accept` matched is
3916
3898
  one the bytes proved.
@@ -3922,9 +3904,9 @@ one the bytes proved.
3922
3904
  -
3923
3905
  **A form post is a simple cross-origin request.** A browser sends
3924
3906
  `multipart/form-data`, urlencoded and `text/plain` with cookies and no
3925
- preflight. A body-schema route refuses one whose `Origin` is another site&rsquo;s
3907
+ preflight. A body-schema route refuses one whose `Origin` is another site's
3926
3908
  with `403` before reading it; list a site that must post forms to the app in the
3927
- server&rsquo;s `formOrigins`. A request without an `Origin` passes, so
3909
+ server's `formOrigins`. A request without an `Origin` passes, so
3928
3910
  a cookie-authenticated upload route still needs `csrf()` like any other state
3929
3911
  change.
3930
3912
 
@@ -3975,14 +3957,14 @@ app.post(
3975
3957
  ```
3976
3958
 
3977
3959
  The route opts in, not the app: a parser registered once for every route would widen what each
3978
- of them accepts. Before `parse` runs, the request&rsquo;s media type has matched one
3960
+ of them accepts. Before `parse` runs, the request's media type has matched one
3979
3961
  of `types` in full (case folded, parameters set aside) and the body has been read
3980
- under the route&rsquo;s `bodyLimit`, counted on the bytes delivered. After it, and
3962
+ under the route's `bodyLimit`, counted on the bytes delivered. After it, and
3981
3963
  before the schema:
3982
3964
 
3983
3965
  -
3984
3966
  **A parser that throws is a `400`.** The answer is `invalid_body`; the
3985
- parser&rsquo;s own message is not sent.
3967
+ parser's own message is not sent.
3986
3968
 
3987
3969
  -
3988
3970
  **The value must be a tree.** An object or array reached twice is what an alias or a cycle
@@ -3998,15 +3980,15 @@ and an object whose prototype the decoder replaced with data are rejected or str
3998
3980
  JSON. An instance of a class, such as a `Date` or a `Uint8Array`, is
3999
3981
  passed through without being looked into.
4000
3982
 
4001
- What stays yours is the decoder&rsquo;s own limits: nesting depth, alias expansion, and the size
3983
+ What stays yours is the decoder's own limits: nesting depth, alias expansion, and the size
4002
3984
  of a number or a string are spent inside `parse`, before anything above can look.
4003
3985
  Configure it for untrusted input.
4004
3986
 
4005
3987
  `types` takes full media types only, and refuses four: JSON, urlencoded and multipart
4006
3988
  already have readers, and `text/plain` is a body a browser sends from any site with
4007
- the user&rsquo;s cookies and no preflight. Every type it does accept is one a browser must
3989
+ the user's cookies and no preflight. Every type it does accept is one a browser must
4008
3990
  preflight, so your CORS policy sees the request first. The generated OpenAPI document lists
4009
- each type under the operation&rsquo;s request body. The typed client keeps sending JSON, which
3991
+ each type under the operation's request body. The typed client keeps sending JSON, which
4010
3992
  the route still reads; send another format with `fetch`.
4011
3993
 
4012
3994
  ### File uploads - `@nifrajs/uploads`
@@ -4233,20 +4215,20 @@ const app = server().use(securityHeaders({
4233
4215
  Every value is fixed at construction, so the headers are declared statically rather than
4234
4216
  written by a response hook - an app whose response middleware is only this keeps the fused
4235
4217
  native response lanes. A route that sets one of these names itself keeps its own value. A
4236
- group can apply its own configuration over the app&apos;s - `admin.use(securityHeaders({ contentSecurityPolicy: "default-src 'none'" }))`
4237
- inside `app.group("/admin", ...)` - and each header it sets replaces the app&apos;s
4238
- value on the group&apos;s routes only.
4218
+ group can apply its own configuration over the app's - `admin.use(securityHeaders({ contentSecurityPolicy: "default-src 'none'" }))`
4219
+ inside `app.group("/admin", ...)` - and each header it sets replaces the app's
4220
+ value on the group's routes only.
4239
4221
 
4240
- A fixed `Content-Security-Policy` here cannot allow nifra&apos;s inline scripts by
4222
+ A fixed `Content-Security-Policy` here cannot allow nifra's inline scripts by
4241
4223
  nonce. For a strict `script-src` on web pages, give `createWebApp` a
4242
- `csp` from `createCspPolicy`: it allows the framework&apos;s constant
4224
+ `csp` from `createCspPolicy`: it allows the framework's constant
4243
4225
  scripts by hash and adds a nonce only to a page that needs one, so every other page sends the
4244
4226
  same header and stays cacheable under `withISR` or a CDN. See
4245
4227
  [A strict CSP that still caches](/docs/contract#strict-csp).
4246
4228
 
4247
4229
  ### Route assurance - prove every route is guarded
4248
4230
 
4249
- Installing security middleware is not the same as proving it covers every route. Nifra&apos;s
4231
+ Installing security middleware is not the same as proving it covers every route. Nifra's
4250
4232
  official auth, CSRF, body-limit, rate-limit, idempotency, IP-restriction, and security-header
4251
4233
  modules publish reflection-safe evidence at the hook where they enforce it. A policy then
4252
4234
  classifies every route and fails closed when evidence is missing or forbidden.
@@ -4288,7 +4270,7 @@ runs only through reflection or `nifra assure`, so requests pay no assurance cos
4288
4270
 
4289
4271
  WebSocket routes are reflected under the pseudo-method `"WS"`, so a policy classifies
4290
4272
  every socket too. A handshake runs the auth guards registered before the socket and the
4291
- app&apos;s request hooks, so a socket carries authentication and rate-limit evidence from them.
4273
+ app's request hooks, so a socket carries authentication and rate-limit evidence from them.
4292
4274
  It never claims evidence whose enforcement its message handlers bypass, such as a durable
4293
4275
  command journal. A socket declares its effects with
4294
4276
  `app.ws(path, { capabilities })`, and capability assurance checks them against
@@ -4297,7 +4279,7 @@ the module that registers it.
4297
4279
  ### Effect assurance - declared capability versus provenance
4298
4280
 
4299
4281
  Authentication does not reveal what a route can do. Capability assurance compares an exact
4300
- route declaration against every approved effect import reachable through that route&apos;s local
4282
+ route declaration against every approved effect import reachable through that route's local
4301
4283
  module graph. Static, dynamic, `require`, and re-export edges are scanned; raw provider
4302
4284
  imports fail `nifra check`. Runtime beacons add denial at owned adapters, but are never
4303
4285
  treated as a substitute for static provenance.
@@ -4596,8 +4578,8 @@ this way. So when `nifra.assurance.ts` loads the app, Nifra also records, in
4596
4578
  development, the module whose call registered each route, and the walk starts there too: a
4597
4579
  computed path, or a route on a server a helper builds, is still covered.
4598
4580
  `nifra check` still names such an expression in an NF-C036 finding, since the
4599
- route lints read the source alone. When the registering module is not where the route&apos;s
4600
- code lives, such as a shared helper that registers other modules&apos; handlers, list the
4581
+ route lints read the source alone. When the registering module is not where the route's
4582
+ code lives, such as a shared helper that registers other modules' handlers, list the
4601
4583
  right module in `provenance.routeModules`.
4602
4584
 
4603
4585
  ### Runtime beacons
@@ -6150,7 +6132,8 @@ every other runtime.
6150
6132
 
6151
6133
  ```ts
6152
6134
  // doc-check: skip - Workers entry: a Durable Object hub holds the connections.
6153
- import { createWebSocketHub, toFetchHandler } from "@nifrajs/workers"
6135
+ import { toFetchHandler } from "@nifrajs/core/server"
6136
+ import { createWebSocketHub } from "@nifrajs/workers"
6154
6137
 
6155
6138
  export const NifraWebSocketHub = createWebSocketHub(app) // bind as NIFRA_WS_HUB in wrangler.toml
6156
6139
  export default toFetchHandler(app, { webSocketHub: (env) => env.NIFRA_WS_HUB })
@@ -6419,8 +6402,8 @@ host-specific deploy step for you to fill in (Fly, a registry push, SSH, …).
6419
6402
 
6420
6403
  ### Bun (its home)
6421
6404
 
6422
- `app.listen(3000)` - the native Bun server. Sits at the raw `Bun.serve`
6423
- ceiling (see [benchmarks](/benchmarks)).
6405
+ `app.listen(3000)` - the native Bun server. Bun is the runtime where Nifra measures
6406
+ fastest (see [benchmarks](/benchmarks)).
6424
6407
 
6425
6408
  **Every core:** Bun is single-threaded per process - for multi-core boxes,
6426
6409
  spawn one process per core, each binding the same port with
@@ -6446,10 +6429,20 @@ On Cloudflare/Vercel the platform serves assets, so you don't need it there.
6446
6429
  Every file under the mount is cached as immutable by default. If the directory also holds
6447
6430
  files that keep their name across deploys, pass the build manifest's `assets` as
6448
6431
  `hashedFiles`: only those URL paths stay immutable, and every other file is sent
6449
- with its validators so the browser revalidates it. The server that
6450
- `nifra build --target bun` or `node` generates does this already. It
6451
- caches only the client build's own content-hashed outputs as immutable. A file copied from
6452
- `public/`, even under `public/assets/`, gets a one-day policy.
6432
+ with its validators so the browser revalidates it, plus `cacheControl` when you
6433
+ set one. Its `ETag` comes from its bytes, so a deploy that keeps timestamps (a
6434
+ container image, `rsync -a`, the Nix store) still revalidates a changed file. The server that `nifra build --target bun` or `node`
6435
+ generates does this already. It caches only the client build's own content-hashed outputs as
6436
+ immutable. A file copied from `public/`, even under `public/assets/`,
6437
+ gets a one-day policy.
6438
+
6439
+ `static` also takes an array of mounts; a path goes to the first mount that
6440
+ takes it, by its prefix and, when set, its `files`. Give a mount
6441
+ `files` to serve only those URL paths from a directory that holds other things
6442
+ too; any other path passes to the next mount, so a later mount over the same paths can still
6443
+ serve it. The generated Node server mounts `/assets` and, at
6444
+ the root, only the `public/` files the build copied, so `server.js`
6445
+ beside them is never served. Dotfiles are refused, except `/.well-known`.
6453
6446
 
6454
6447
  ### HTTPS without a proxy
6455
6448
 
@@ -6522,12 +6515,13 @@ function under `.vercel/output`.
6522
6515
 
6523
6516
  ## Nifra - CLI
6524
6517
 
6525
- > The zero-config Nifra CLI (`nifra dev`, `nifra build`, `nifra start`): true HMR and complete target-specific deploy builds.
6518
+ > Every Nifra CLI command: dev, build and start, the check and contract gates, code generation, the agent and dev-server tools, and upgrades.
6526
6519
 
6527
- `Nifra` is zero-config: it reads `routes/`, `framework.ts`, and
6528
- (optionally) `backend.ts` from your project and wires the right
6529
- `@nifrajs/web` entrypoint - no `dev.ts`/`build.ts`/
6530
- `server.ts` to hand-write. (`create-nifra` scaffolds the conventions.)
6520
+ `nifra` runs, builds, checks and upgrades an app from its project root. It reads
6521
+ `routes/`, `backend/framework.ts`, `backend/app.ts` and
6522
+ `nifra.config.ts` and wires the right `@nifrajs/web` entrypoint, so there
6523
+ is no `dev.ts`, `build.ts` or `server.ts` to write.
6524
+ `create-nifra` scaffolds the layout.
6531
6525
 
6532
6526
  ```ts
6533
6527
  nifra dev # true-HMR dev server (Bun native HMR + Nifra SSR) - http://localhost:4321
@@ -6541,13 +6535,13 @@ nifra build --target cloudflare # also: node | deno | vercel | static; add --re
6541
6535
  # --vite | --bun (dev/build) force the pipeline
6542
6536
  ```
6543
6537
 
6544
- ### The conventions
6538
+ ### The layout the CLI reads
6545
6539
 
6546
- Four conventions at the project root. `nifra dev` runs the Bun-native
6547
- [HMR dev server](/docs/dev); `nifra build` runs the Bun-native production
6548
- build (content-hashed client assets plus a target-specific server); `nifra start`
6549
- runs the default Bun output. The generated server serves assets and SSR with matched-route
6550
- chunks preloaded and route CSS linked in each `<head>`.
6540
+ `nifra dev` runs the Bun-native [HMR dev server](/docs/dev);
6541
+ `nifra build` runs the production build (content-hashed client assets plus a
6542
+ target-specific server); `nifra start` runs the default Bun output. The generated
6543
+ server serves assets and SSR with matched-route chunks preloaded and route CSS linked in each
6544
+ `<head>`.
6551
6545
 
6552
6546
  **One rule picks the bundler, and it is the same rule in both phases** - so a
6553
6547
  project can never be bundled by one toolchain in dev and the other in production. Bun runs
@@ -6561,41 +6555,50 @@ answers the same question without starting a server - see
6561
6555
 
6562
6556
  ```ts
6563
6557
  my-app/
6564
- routes/ # file-based routes (index.tsx, _layout.tsx, [id].tsx, …)
6565
- framework.ts # deploy-safe render adapter
6566
- nifra.config.ts # CLI-only client module + dev/build plugins
6567
- backend.ts # export const backend = server()... (optional - the typed contract)
6568
- ```
6569
-
6570
- These paths are **fixed**, not configurable: the CLI resolves all four from the
6571
- project root, so `backend.ts` cannot move into `src/` or be renamed -
6572
- if the file is not at the root, `nifra dev|build` simply run without a backend
6573
- (it is optional, so nothing errors). Only the entry file is pinned; the feature modules it
6574
- `.merge()`s can live in any directory. Keep `backend.ts` a pure
6575
- composition root - merging modules, registering no routes of its own - so each route's
6576
- capability reach stays its own module's (see
6577
- [Backends & API](/docs/backends) and
6578
- [Verification](/docs/verification)).
6558
+ routes/ # the URL tree: index.tsx, _layout.tsx, [id].tsx, each with an optional x.backend.ts half
6559
+ backend/
6560
+ framework.ts # the render adapter and server options - deploy-safe
6561
+ app.ts # export const backend = server()... (optional - the typed API)
6562
+ frontend/ # components and browser code
6563
+ shared/ # schemas, types and helpers both sides import
6564
+ nifra.config.ts # CLI-only: client module, deploy target, dev/build plugins
6565
+ ```
6566
+
6567
+ These paths are **fixed**: the CLI resolves them from the project root.
6568
+ `backend/app.ts` is optional; without it `nifra dev` and
6569
+ `nifra build` run the pages alone. A root `backend.ts` or
6570
+ `framework.ts`, the layout before 4.0, is refused with the command that moves it,
6571
+ and `nifra check` reports it as NF-C038: run
6572
+ `nifra migrate layout`. Only the entry file is pinned; the feature modules it
6573
+ `.merge()`s can live anywhere under `backend/`. Keep
6574
+ `backend/app.ts` a composition root - merging modules, registering no routes of
6575
+ its own - so each route's capability reach stays its own module's. What goes in each
6576
+ zone, and what the builds refuse to cross, is on
6577
+ [Project structure](/docs/structure).
6579
6578
 
6580
- ### framework.ts - naming the framework once
6579
+ ### backend/framework.ts and nifra.config.ts
6581
6580
 
6582
- Keep the render `adapter` in deploy-safe `framework.ts`. Put
6583
- `clientModule`, Vite plugins, compiler plugins, conditions, and defines in CLI-only
6584
- `nifra.config.ts`. This prevents build tooling and native dependencies from entering
6585
- generated server bundles.
6581
+ Keep the render `adapter` and the server options (`apiPrefix`,
6582
+ `mounts`, `csp`, `i18n`) in deploy-safe
6583
+ `backend/framework.ts`: the generated server entry imports it. Put
6584
+ `clientModule`, the deploy `target`, Vite plugins, compiler plugins,
6585
+ conditions, and defines in CLI-only `nifra.config.ts`, which re-exports the
6586
+ adapter. This keeps build tooling and native dependencies out of generated server bundles.
6586
6587
 
6587
6588
  ```ts
6588
- // framework.ts - deploy-safe; generated server entries import this file.
6589
+ // backend/framework.ts - deploy-safe; the generated server entry imports this file.
6589
6590
  import { reactAdapter } from "@nifrajs/web-react"
6590
6591
 
6591
6592
  export const adapter = reactAdapter
6593
+ export const apiPrefix = "" // "" keeps backend/app.ts loader-only; "/api" also serves it over HTTP
6592
6594
 
6593
6595
  // nifra.config.ts - CLI-only build/dev tooling; never imported by a deployed server.
6594
6596
  // doc-check: skip - needs the third-party @vitejs/plugin-react; install it to run this.
6595
6597
  import react from "@vitejs/plugin-react"
6596
- export { adapter } from "./framework"
6598
+ export { adapter } from "./backend/framework"
6597
6599
  export const clientModule = "@nifrajs/web-react/client"
6598
- export const vitePlugins = [react()] // dev HMR (Fast Refresh)
6600
+ export const target = "bun" // what nifra build emits; nifra target <t> switches it
6601
+ export const vitePlugins = [react()] // only if you want Vite's dev pipeline
6599
6602
  // Vue/Svelte/Solid also export:
6600
6603
  // clientPlugins = [vueBunPlugin("dom")] // compile routes for the client build
6601
6604
  // serverPlugins = [vueBunPlugin("ssr")] // compile routes into the target's server bundle
@@ -6603,6 +6606,224 @@ export const vitePlugins = [react()] // dev HMR (Fast Refresh)
6603
6606
  // define = { __VUE_OPTIONS_API__: "true", ... } // Vue feature flags
6604
6607
  ```
6605
6608
 
6609
+ ### Command reference
6610
+
6611
+ Every command `nifra --help` lists, by what it is for. Most take
6612
+ `--json` for agents and CI. `--env-file <path>` works on every
6613
+ command and may repeat (a later file wins; a variable already set in the environment is never
6614
+ overwritten), which matters because commands that reflect your app import it. A dry run is
6615
+ the default wherever a command edits files.
6616
+
6617
+ #### Run and build
6618
+
6619
+ Develop, build a deploy directory, and run it.
6620
+
6621
+ Command
6622
+ What it does
6623
+
6624
+ `nifra dev [--port <n>] [--vite | --bun] [--poll]`
6625
+
6626
+ The dev server with true HMR, on port 4321. Bun runs it unless `vitePlugins` are the app's only transforms. `--no-indicator` hides the in-page issues badge.
6627
+
6628
+ `nifra build [--target <t>] [--out <dir>] [--report]`
6629
+
6630
+ A complete deploy directory for `bun`, `node`, `deno`, `cloudflare`, `vercel` or `static`. The server entry is generated from `backend/framework.ts`, `backend/app.ts` and `routes/`. `--report` prints each chunk's size.
6631
+
6632
+ `nifra start [--port <n>] [--out <dir>]`
6633
+
6634
+ Run the Bun build at `<out>/server.js`.
6635
+
6636
+ `nifra target [<target>]`
6637
+
6638
+ Show the deploy target kept in `nifra.config.ts`, or switch it. `nifra build` emits that target when no `--target` is given.
6639
+
6640
+ #### Check and gate
6641
+
6642
+ The gates to run before calling a change done, locally and in CI.
6643
+
6644
+ Command
6645
+ What it does
6646
+
6647
+ `nifra check [--lints-only] [--json] [--sarif]`
6648
+
6649
+ Typecheck plus contract lints: a hand-rolled `fetch()` to your own API, an untyped client, backend code reached from browser code. `--lints-only` skips tsc; `--sarif` emits SARIF 2.1.0.
6650
+
6651
+ `nifra review [--diff <ref>] [--strict] [--fix] [--write]`
6652
+
6653
+ A deterministic, evidence-backed review of the project or a diff. `--fix` plans the recipes it can apply; `--fix --write` applies them.
6654
+
6655
+ `nifra fix [--code <NF-code>]`
6656
+
6657
+ Apply the registered recipe for a diagnostic, then print the diagnostics that remain.
6658
+
6659
+ `nifra doctor [--strict] [--auto-fix] [--target <t>]`
6660
+
6661
+ Find undeclared imports and duplicate copies of `@nifrajs/core`, React and other identity-sensitive packages, and print production readiness. `--auto-fix` writes the safe dependency fixes.
6662
+
6663
+ `nifra port [--target <t>] [--ci] [--strict]`
6664
+
6665
+ A feature-by-deploy-target matrix (in-memory stores, in-process cron and WebSockets, runtime globals, `node:` built-ins) with file:line evidence. `--ci` fails on a feature the target lacks.
6666
+
6667
+ `nifra routes [--json] [--modes] [--hooks] [--graph]`
6668
+
6669
+ Every page and API route with its methods. `--modes` shows each page's render mode and fails against `--target`; `--hooks` lists the hooks each route runs; `--graph` draws the routes as Mermaid.
6670
+
6671
+ `nifra smoke [--fixture <file>] [--in-process]`
6672
+
6673
+ The declared production smoke checks: SSR, the mounted API, 404s, headers, auth, contracts and hydration.
6674
+
6675
+ `nifra cdn-check <url>`
6676
+
6677
+ Check a deployed page behind a CDN: served from cache, no internal headers reaching visitors, and soft navigations getting page data rather than the cached document.
6678
+
6679
+ `nifra i18n check [entry] [--strict]`
6680
+
6681
+ Check i18n catalogs: coverage, missing and unused keys, ICU syntax, placeholder parity and plural cases. It imports the entry module.
6682
+
6683
+ `nifra verify [--release]`
6684
+
6685
+ Run the verification gate plan against the project's `package.json` scripts; a gate with no script is reported, not run. `--release` adds the build, test, coverage and cross-runtime gates.
6686
+
6687
+ #### Contracts and assurance
6688
+
6689
+ Lock the API contract, prove the security posture, and fail CI when either regresses. See Verification for the ladder these build.
6690
+
6691
+ Command
6692
+ What it does
6693
+
6694
+ `nifra snapshot [--out <file>]`
6695
+
6696
+ Write the backend's API contract (routes and schemas) as JSON, `api-snapshot.json` by default: the baseline for `nifra diff`.
6697
+
6698
+ `nifra diff [<baseline>]`
6699
+
6700
+ The breaking-change gate. A new required request field or a removed response field breaks; a new response field does not. Exits non-zero on a break.
6701
+
6702
+ `nifra contracts snapshot | check`
6703
+
6704
+ Write the deterministic route contract lock, `contracts.lock.json`, or check the current routes against it.
6705
+
6706
+ `nifra assure [--config <file>]`
6707
+
6708
+ Classify every route against `nifra.assurance.ts` and list the evidence each one is missing.
6709
+
6710
+ `nifra assure --bundle [--strict] [--hydration] [--interact]`
6711
+
6712
+ One JSON verdict over every applicable gate, each recorded as pass, fail or skip. Exits non-zero unless the verdict is green.
6713
+
6714
+ `nifra levels [--min <n>]`
6715
+
6716
+ The verification ladder: L0 typed contract, L1 route assurance, L2 capability lockfile, L3 route manifest, L4 invariant-tested. `--min` fails below a level.
6717
+
6718
+ `nifra prove [--file <path>] [--min <n>]`
6719
+
6720
+ Plan the cheapest proofs for the changed files and report a machine-checkable stop condition. Needs a fresh build.
6721
+
6722
+ `nifra capabilities snapshot | check | explain`
6723
+
6724
+ Write the capability lockfile once provenance and idempotency assurance pass; fail CI on an effect import that bypasses it, drift, a GET that writes, or an idempotency gap; explain one route's tokens with `explain <METHOD> <path>`.
6725
+
6726
+ `nifra manifest emit | diff`
6727
+
6728
+ Emit the hash-verified route trust manifest, signed with `--sign <key-ref>` through the configured KMS signer, or compare two manifests and fail on a regression.
6729
+
6730
+ `nifra replay <file>`
6731
+
6732
+ Validate a token-only verification metadata file and run it against its gate.
6733
+
6734
+ #### Generate
6735
+
6736
+ Write the files the types and clients come from.
6737
+
6738
+ Command
6739
+ What it does
6740
+
6741
+ `nifra types [--check]`
6742
+
6743
+ Each route's `./+types` module under `.nifra/types`: params, schema-typed data, and `api` typed by `backend/app.ts`. `dev`, `build` and `check` refresh them too.
6744
+
6745
+ `nifra schemas [--write] [--check]`
6746
+
6747
+ Draft `loaderOutput` and `actionOutput` from each loader's and action's return type. `--write` adds the missing ones; it also lists returned fields a hand-written schema drops.
6748
+
6749
+ `nifra sync-routes`
6750
+
6751
+ Regenerate `nifra-routes.d.ts` so `navigate({ to, search })` is typed by each route's search schema.
6752
+
6753
+ `nifra sync-manifest`
6754
+
6755
+ Regenerate a committed `server-manifest.ts` from `routes/` without a full build.
6756
+
6757
+ `nifra openapi [--format json | yaml] [--path <prefix>]`
6758
+
6759
+ The backend's OpenAPI document, including response types inferred at build time.
6760
+
6761
+ `nifra sdk --lang python | go [--out <file>]`
6762
+
6763
+ A deterministic Python or Go SDK generated from `backend/app.ts`.
6764
+
6765
+ #### Agents and the dev server
6766
+
6767
+ What a coding agent reads and runs. nifra mcp serves the same information as tools; see Coding agents.
6768
+
6769
+ Command
6770
+ What it does
6771
+
6772
+ `nifra mcp [dir]`
6773
+
6774
+ Start the project's MCP server over stdio: the route index, scaffolding, `nifra_check`, SSR rendering, the dev server's errors and logs, and the declared dev database.
6775
+
6776
+ `nifra docs-mcp [--port <n>]`
6777
+
6778
+ Serve the public docs MCP (`nifra_docs`, `nifra_example`) over HTTP, on port 8787 by default.
6779
+
6780
+ `nifra context`
6781
+
6782
+ Print the project's route index and conventions for an agent's prompt.
6783
+
6784
+ `nifra learn [<step>]`
6785
+
6786
+ Print the guided build-an-app path, or one step's goal, actions and check.
6787
+
6788
+ `nifra init-agents [--force] [--sync-mcp]`
6789
+
6790
+ Add the agent files a new app ships (`.mcp.json`, the `AGENTS.md` sections, each agent's pointer) to an existing app. `--sync-mcp` re-pins the MCP launch to the installed nifra.
6791
+
6792
+ `nifra errors [--since <n>] [--category <c>]`
6793
+
6794
+ What the running dev server caught (SSR, loader, API, build, browser and hydration errors), each a structured diagnostic. Exits 1 while errors are open.
6795
+
6796
+ `nifra logs [--level <l>] [--grep <s>]`
6797
+
6798
+ The dev server's console, server and browser, each line tagged with its request.
6799
+
6800
+ `nifra explain [<message> | <NF-code>]`
6801
+
6802
+ A structured diagnostic for an error, or what a check rule reports and how to fix it.
6803
+
6804
+ `nifra db schema | query | role | audit`
6805
+
6806
+ Read the development database declared as `devDatabase` in `nifra.config.ts`: its tables, one read-only `SELECT` (rows capped, secrets masked), the SQL for a read-only Postgres role, and a log of what ran.
6807
+
6808
+ #### Migrate and upgrade
6809
+
6810
+ Move an app between layouts and releases. Each one is a dry run until --write.
6811
+
6812
+ Command
6813
+ What it does
6814
+
6815
+ `nifra migrate layout [--write] [--zones]`
6816
+
6817
+ Move an app onto the 4.0 layout: split each route into `x.tsx` and `x.backend.ts`, fold `_middleware.ts` into `_layout.backend.ts`, move `backend.ts` and `framework.ts` under `backend/`, and zone the other modules.
6818
+
6819
+ `nifra migrate --from tailwind --to stylex`
6820
+
6821
+ Move static Tailwind classes to StyleX; see below.
6822
+
6823
+ `nifra upgrade <version> [--write] [--list]`
6824
+
6825
+ Run every release recipe between the installed version and the target; see below.
6826
+
6606
6827
  ### Tailwind to StyleX
6607
6828
 
6608
6829
  Nifra includes a conservative codemod for moving static Tailwind classes to StyleX. It is a dry
@@ -6621,7 +6842,7 @@ expressions, arbitrary values, parent-dependent variants, and unknown utilities
6621
6842
  and are reported with file/line evidence. A non-zero exit status means manual migration issues
6622
6843
  remain.
6623
6844
 
6624
- StyleX compilation is native to Nifra&apos;s Bun pipeline. Install the runtime and compiler peers,
6845
+ StyleX compilation is native to Nifra's Bun pipeline. Install the runtime and compiler peers,
6625
6846
  then register both the browser and SSR transforms:
6626
6847
 
6627
6848
  ```sh
@@ -6640,7 +6861,7 @@ export const serverPlugins = [stylexBunPlugin("ssr")]
6640
6861
  ```
6641
6862
 
6642
6863
  If the project intentionally uses Vite, add the Vite adapter alongside its existing Vite
6643
- transforms. Nifra will use Vite when `vitePlugins` are the app&apos;s only transforms:
6864
+ transforms. Nifra will use Vite when `vitePlugins` are the app's only transforms:
6644
6865
 
6645
6866
  ```ts
6646
6867
  // doc-check: skip - requires the third-party Vite React plugin
@@ -6664,7 +6885,7 @@ The pins in `overrides`, `resolutions` and
6664
6885
  `pnpm.overrides` move with them, since an override decides what installs. A
6665
6886
  `peerDependencies` range is what a library accepts, not a pin: it is raised only
6666
6887
  when it excludes the target (keeping its operator, even with `--exact`), and a
6667
- library&apos;s `">=3.1.0"` floor never sets the version the upgrade
6888
+ library's `">=3.1.0"` floor never sets the version the upgrade
6668
6889
  starts from unless nothing else, installed or declared, names one.
6669
6890
 
6670
6891
  ```bash
@@ -6679,7 +6900,7 @@ nifra doctor # afterwards: no "mixed nifra versions" advisory l
6679
6900
  It is a dry-run until `--write`, and the same run twice makes no further edits. An
6680
6901
  unknown version or a target below what is installed is refused (`--allow-downgrade`
6681
6902
  when the rollback is intended); a target newer than the running CLI prints the command for
6682
- that release&apos;s CLI. It edits files under the workspace root only: a symlinked package
6903
+ that release's CLI. It edits files under the workspace root only: a symlinked package
6683
6904
  directory or `package.json` is never followed, and a group package installed by a
6684
6905
  link from outside the root is listed under "Left alone" for you to upgrade in its
6685
6906
  own repository. The MCP launch pin in `.mcp.json`, `.cursor/mcp.json`,
@@ -6688,7 +6909,7 @@ the project declares `@nifrajs/cli` so the launch runs that install from then on
6688
6909
  the edit `nifra init-agents --sync-mcp` makes. Another version pinned outside
6689
6910
  `package.json` is listed with its line: the rest of an agent file, an MCP config
6690
6911
  elsewhere, a Dockerfile or compose file, a CI workflow, and a lockfile other than the
6691
- workspace&apos;s own (an image build&apos;s frozen lockfile, say), which you regenerate after
6912
+ workspace's own (an image build's frozen lockfile, say), which you regenerate after
6692
6913
  installing. `nifra check` reads the installed packages, so `--write`
6693
6914
  runs it (`--no-verify` skips that) only once they match the target: until the new
6694
6915
  pins are installed it would judge the release you are leaving, and the command prints the
@@ -7965,7 +8186,7 @@ start - they are the edges you can hit later, collected in one place.
7965
8186
 
7966
8187
  #### Keep the adapter out of your config file
7967
8188
 
7968
- Split `framework.ts` (the adapter, imported by your server and edge entries) from
8189
+ Split `backend/framework.ts` (the adapter, imported by your server and edge entries) from
7969
8190
  `nifra.config.ts` (the CLI's config, where the Vite plugins and SFC compilers live).
7970
8191
  If your server entry reaches the adapter _through_ the config, everything the config
7971
8192
  imports is bundled into your production server - the Vite plugin, the framework compiler, and
@@ -7974,7 +8195,7 @@ native binding, which reads like a broken install rather than a config-shape pro
7974
8195
 
7975
8196
  ```ts
7976
8197
  // doc-check: skip - fragment: two files from one app, shown together.
7977
- // framework.ts - imported by your SERVER and edge entries. Adapter only, nothing else.
8198
+ // backend/framework.ts - imported by your SERVER and edge entries. Adapter only, nothing else.
7978
8199
  import { svelteAdapter } from "@nifrajs/web-svelte"
7979
8200
  export const adapter = svelteAdapter
7980
8201
 
@@ -7982,7 +8203,7 @@ export const adapter = svelteAdapter
7982
8203
  // belong here. Re-export the adapter; never define it here, or the dev toolchain it pulls in
7983
8204
  // (Vite, the SFC compiler, their native bindings) is bundled into your production server.
7984
8205
  import { svelte } from "@sveltejs/vite-plugin-svelte"
7985
- export { adapter } from "./framework"
8206
+ export { adapter } from "./backend/framework"
7986
8207
  export const clientModule = "@nifrajs/web-svelte/client"
7987
8208
  export const vitePlugins = [svelte()]
7988
8209
  ```
@@ -8288,7 +8509,7 @@ routes added after it stay typed. See
8288
8509
  ####
8289
8510
  Call site rejects `{ query: {…} }`
8290
8511
 
8291
- If `api.thing.get(&#123; query: &#123; … &#125; &#125;)` errors, the route declares no
8512
+ If `api.thing.get({ query: { … } })` errors, the route declares no
8292
8513
  `query` schema - its query types as `never`, so the client can't accept query
8293
8514
  params. The error reads out the fix; add a schema to the route:
8294
8515
  `.get("/thing", { query: z.object({ page: z.string() }) }, h)`. Then
@@ -8656,14 +8877,14 @@ each other. Each domain therefore owns its full absolute paths (`/api/listings`,
8656
8877
  `routes()`, OpenAPI, capability events and the effect ledger. The builder
8657
8878
  inherits this server's middleware chain as it stands at the call; what it adds stays in the
8658
8879
  group, and its `onRequest`/`onResponse` hooks run only for requests at
8659
- or under the prefix. A static header the group declares replaces the parent&apos;s value
8660
- of that name on the group&apos;s routes, so `securityHeaders()` with the group&apos;s
8661
- own configuration applies over the app&apos;s there. Any other plugin the parent already
8662
- applied stays the parent&apos;s: the group&apos;s `use()` of that same instance
8880
+ or under the prefix. A static header the group declares replaces the parent's value
8881
+ of that name on the group's routes, so `securityHeaders()` with the group's
8882
+ own configuration applies over the app's there. Any other plugin the parent already
8883
+ applied stays the parent's: the group's `use()` of that same instance
8663
8884
  does nothing, and its `use()` of another instance under the same name (another
8664
8885
  `cors()` policy) throws a `RouteConfigError` when the group is
8665
8886
  declared, rather than being dropped. A plugin the group applies still shares the
8666
- parent&apos;s copy of a plugin it `use()`s itself. The prefix is plain text (no
8887
+ parent's copy of a plugin it `use()`s itself. The prefix is plain text (no
8667
8888
  params or wildcards), and a collision throws before any group route is added.
8668
8889
 
8669
8890
  -
@@ -10434,7 +10655,7 @@ then up to 127 of `A-Z a-z 0-9 . _ : / -`), more than 32 tags, or something othe
10434
10655
  an array. Those tags were dropped, so a purge by them reaches nothing. The warning names the
10435
10656
  route, never the tag.
10436
10657
 
10437
- **Fix:** build tags from route params (`product:$&#123;params.id&#125;`),
10658
+ **Fix:** build tags from route params (`product:${params.id}`),
10438
10659
  keep to the allowed characters, and return at most 32.
10439
10660
 
10440
10661
  #### NIFRA_CDN_RATE_LIMITED
@@ -11268,7 +11489,7 @@ keeps the 4.x behavior for each.
11268
11489
  Past 5.0, 5.1 adds one change a frontend on another origin sees. A route with a
11269
11490
  `body` schema answers a urlencoded, multipart or `text/plain` body whose
11270
11491
  `Origin` names another site with `403 forbidden_origin`, before reading
11271
- it. List that frontend&rsquo;s origin, or an identity provider&rsquo;s for a
11492
+ it. List that frontend's origin, or an identity provider's for a
11272
11493
  `form_post` callback, in the `formOrigins` server option (an array of
11273
11494
  exact origins or a function; `@nifrajs/edge` takes it too). JSON bodies are
11274
11495
  unchanged. [Security](/docs/security) covers what the check leaves to
@@ -11483,6 +11704,8 @@ app.
11483
11704
 
11484
11705
  -
11485
11706
  **Much faster SSR** - the current dynamic-page snapshot reports Nifra at
11707
+ 20× the throughput of Next.js, 7× Nuxt, and
11708
+ 3.2× SvelteKit / 3.3× SolidStart, with a fraction
11486
11709
  of the client JavaScript. See [benchmarks](/benchmarks).
11487
11710
 
11488
11711
  -
@@ -11512,7 +11735,7 @@ mount small and temporary, and use typed routes for every migrated endpoint.
11512
11735
  The platform object is forwarded as the second argument when the runtime supplies one.
11513
11736
 
11514
11737
  A mounted fetch handler carries HTTP only. A WebSocket upgrade under the mount reaches it as
11515
- an ordinary request and never becomes a socket, so keep the legacy app&apos;s sockets on its own
11738
+ an ordinary request and never becomes a socket, so keep the legacy app's sockets on its own
11516
11739
  server until they move to `app.ws()` routes (see
11517
11740
  [WebSockets in a composed app](/docs/websockets#composed)).
11518
11741
 
@@ -11634,7 +11857,7 @@ and a `process <job>` consumer span per attempt. The process span is a child
11634
11857
  of the send span, plus a link to it, so one trace runs from the request to the worker even when
11635
11858
  the worker is another process. Retries are separate spans, and the attempt that dead-letters a
11636
11859
  job says so. A job store persists the trace context as an optional field;
11637
- `jobStoreCertificationProfile(&#123; traceparent: true &#125;)` checks it.
11860
+ `jobStoreCertificationProfile({ traceparent: true })` checks it.
11638
11861
 
11639
11862
  ### Event consumers
11640
11863
 
@@ -11729,7 +11952,7 @@ reads, no events, no extra frames.
11729
11952
 
11730
11953
  > A dimension-by-dimension security comparison of Nifra against the current releases of Hono, Fastify, Express, and Elysia - which hardening each framework ships by default, which is opt-in, and which is left to third-party packages.
11731
11954
 
11732
- Which hardening each framework actually ships. A dimension-by-dimension read of Nifra&rsquo;s
11955
+ Which hardening each framework actually ships. A dimension-by-dimension read of Nifra's
11733
11956
  security defaults against the **current releases** of Hono, Fastify, Express, and Elysia -
11734
11957
  what is on by default, what is opt-in, and what is left to a third-party package. For how each
11735
11958
  Nifra primitive works, see [Security & hardening](/docs/security).
@@ -11749,10 +11972,10 @@ verification, env-independent error responses, client-IP trust model.
11749
11972
  **Par with the best-in-class:** body limits (Fastify class), JSON prototype-poisoning
11750
11973
  rejection (par Fastify, default-on), schema validation (par Fastify/Elysia), CSRF (par
11751
11974
  Fastify), security headers (par Hono, first-party), cookie prefixes (par Hono), sessions,
11752
- JWT hardening, static serving, supply chain (par Hono&rsquo;s zero-dependency core).
11975
+ JWT hardening, static serving, supply chain (par Hono's zero-dependency core).
11753
11976
 
11754
11977
  **One caveat no capability table removes.** Hono, Fastify, and Express have orders of
11755
- magnitude more production exposure and more external researchers looking at them. Nifra&rsquo;s
11978
+ magnitude more production exposure and more external researchers looking at them. Nifra's
11756
11979
  protections are implementation-verified and unit-tested, but have not had that volume of
11757
11980
  adversarial attention or a third-party audit. Ongoing scrutiny is the part only time buys.
11758
11981
 
@@ -12027,10 +12250,10 @@ body is drained through a true streaming byte counter that cancels at the cap. T
12027
12250
  charged on the bytes actually **delivered**, never on the number a caller wrote in the
12028
12251
  header - so an adapter that rebuilds a request from an event envelope cannot smuggle a large
12029
12252
  payload behind a small declared length. Fastify enforces its 1 MiB default on real bytes and
12030
- is the gold standard among the four; Nifra matches it. Hono&rsquo;s `bodyLimit` is
12253
+ is the gold standard among the four; Nifra matches it. Hono's `bodyLimit` is
12031
12254
  an opt-in middleware that keys on `Content-Length`; Express relies on
12032
- body-parser&rsquo;s 100 KB default only if you mount it; Elysia inherits the runtime cap
12033
- (Bun&rsquo;s 128 MB).
12255
+ body-parser's 100 KB default only if you mount it; Elysia inherits the runtime cap
12256
+ (Bun's 128 MB).
12034
12257
 
12035
12258
  #### Prototype pollution
12036
12259
 
@@ -12040,7 +12263,7 @@ JSON body lane **rejects** the poisoning shape by default - an own `__proto__`
12040
12263
  key, or a `constructor` carrying a `prototype` - answering the same flat
12041
12264
  400 as malformed JSON, with `"strip"` and `"ignore"`
12042
12265
  as alternatives. That matches Fastify, whose `onProtoPoisoning` and
12043
- `onConstructorPoisoning` both default to `&apos;error&apos;`. Hono and
12266
+ `onConstructorPoisoning` both default to `'error'`. Hono and
12044
12267
  Express do not reject proto keys in the JSON body; Elysia strips undeclared keys only on a
12045
12268
  validated route via its schema normalization.
12046
12269
 
@@ -12050,38 +12273,38 @@ Nifra does per-route Standard Schema validation for body/query/params, and - the
12050
12273
  differentiating half - **response** schemas as an enforced upper bound:
12051
12274
  `"warn"` logs undeclared fields, `"enforce"` strips
12052
12275
  them. That kills the `passwordHash`-in-the-response class at the framework layer.
12053
- Fastify offers the same protection through a declared response schema (opt-in); Elysia&rsquo;s
12276
+ Fastify offers the same protection through a declared response schema (opt-in); Elysia's
12054
12277
  exactMirror normalization strips undeclared response fields and is its strongest default.
12055
- Hono&rsquo;s validator is opt-in with no response-side story, and Express ships nothing.
12278
+ Hono's validator is opt-in with no response-side story, and Express ships nothing.
12056
12279
 
12057
12280
  #### CORS, CSRF, and error handling
12058
12281
 
12059
- Nifra&rsquo;s `cors()` throws at construction when `credentials: true`
12282
+ Nifra's `cors()` throws at construction when `credentials: true`
12060
12283
  meets `origin: "*"`, never reflects an origin by default with credentials,
12061
12284
  and lands headers on error responses too - it is **the only one of the five where the
12062
12285
  dangerous configuration is a construction-time error**. The other four leave
12063
12286
  reflect-with-credentials configurable. CSRF is two independent layers (Origin/Referer check
12064
- plus a signed double-submit token, timing-safe); Hono&rsquo;s CSRF is an Origin /
12065
- Sec-Fetch-Site heuristic, Fastify&rsquo;s official token package is comparable, Express&rsquo;s
12287
+ plus a signed double-submit token, timing-safe); Hono's CSRF is an Origin /
12288
+ Sec-Fetch-Site heuristic, Fastify's official token package is comparable, Express's
12066
12289
  csurf is deprecated, and Elysia ships none in-tree. Uncaught errors become a flat 500
12067
- unconditionally - not env-gated - so no configuration leaks a stack to the wire; Express&rsquo;s
12290
+ unconditionally - not env-gated - so no configuration leaks a stack to the wire; Express's
12068
12291
  dev handler printing stacks when `NODE_ENV` is unset is the perennial
12069
12292
  counter-example.
12070
12293
 
12071
12294
  #### Headers, cookies, sessions, JWT
12072
12295
 
12073
12296
  Both Nifra and Hono ship a first-party security-headers middleware you add with
12074
- `use()`. Nifra&rsquo;s turns on nosniff, `X-Frame-Options: DENY`, and
12297
+ `use()`. Nifra's turns on nosniff, `X-Frame-Options: DENY`, and
12075
12298
  `Referrer-Policy: no-referrer`, and keeps the headers that can break a working app
12076
- (COOP/COEP/CORP, Permissions-Policy, CSP, HSTS) opt-in by design; Hono&rsquo;s covers a broader
12299
+ (COOP/COEP/CORP, Permissions-Policy, CSP, HSTS) opt-in by design; Hono's covers a broader
12077
12300
  list on by default once added, HSTS included. Cookie serialization enforces RFC 6265 name
12078
12301
  tokens, caps at 4096 bytes, and enforces `__Host-`/`__Secure-` prefix
12079
- preconditions at serialization time, throwing on a violation - the same behavior Hono&rsquo;s
12302
+ preconditions at serialization time, throwing on a violation - the same behavior Hono's
12080
12303
  cookie helper has, and stricter than a silent browser drop. Sessions are always HMAC-signed,
12081
12304
  HttpOnly, SameSite=Lax, fail-closed, with `regenerate()` for fixation - no
12082
12305
  competitor ships sessions in-tree. JWT verification demands an algorithm allowlist, rejects
12083
12306
  `alg: none`, blocks algorithm confusion at the key level, and requires
12084
- `exp` by default; Hono&rsquo;s JWT middleware takes a single required algorithm with
12307
+ `exp` by default; Hono's JWT middleware takes a single required algorithm with
12085
12308
  no enforced allowlist and treats `exp` as optional, so Nifra is stricter there.
12086
12309
 
12087
12310
  #### Static serving, redirects, uploads, proxying
@@ -12099,12 +12322,12 @@ bytes and strip EXIF/GPS by re-encode, where the others do size limits at best.
12099
12322
  #### Rate limiting, IP trust, load shedding
12100
12323
 
12101
12324
  The rate limiter keys on the caller IP the server resolved, never on a client-sent header, so
12102
- the &ldquo;trust proxy = spoofable keys&rdquo; footgun has no default path; with no resolvable
12325
+ the "trust proxy = spoofable keys" footgun has no default path; with no resolvable
12103
12326
  IP it fails closed instead of sharing one bucket.
12104
12327
  `X-Forwarded-For` is ignored at the default and counted from the right only when you
12105
12328
  declare trusted proxies. `c.clientIp` is the socket peer unless you pass an explicit
12106
12329
  trust config, and short chains fail closed. Admission sheds on live capacity evidence
12107
- (in-flight count plus event-loop lag). Fastify&rsquo;s under-pressure is the only peer for load
12330
+ (in-flight count plus event-loop lag). Fastify's under-pressure is the only peer for load
12108
12331
  shedding; nothing else in the field defaults to an unspoofable key or fails closed on IP trust.
12109
12332
 
12110
12333
  ### Beyond parity - what none of the four ship
@@ -12132,10 +12355,10 @@ third-party add-on for the others; Nifra ships them first-party with assurance i
12132
12355
 
12133
12356
  ### Where each alternative is still the right call
12134
12357
 
12135
- This is a security read, not a blanket &ldquo;pick Nifra&rdquo;. Hono&rsquo;s run-anywhere
12136
- minimalism and its zero-dependency core are genuinely excellent; Fastify&rsquo;s maturity,
12358
+ This is a security read, not a blanket "pick Nifra". Hono's run-anywhere
12359
+ minimalism and its zero-dependency core are genuinely excellent; Fastify's maturity,
12137
12360
  ecosystem, and years of adversarial attention are real advantages a young framework cannot
12138
- claim; Express&rsquo;s ubiquity means every hire already knows it. Nifra&rsquo;s argument is
12361
+ claim; Express's ubiquity means every hire already knows it. Nifra's argument is
12139
12362
  narrower and honest: it makes the dangerous configurations _unrepresentable_, ships the
12140
12363
  hardening primitives first-party, and lets `nifra assure` prove in CI that every
12141
12364
  route is guarded. For the full capability and throughput comparison, see
@@ -12447,7 +12670,7 @@ test("the API contract withstands hostile inputs", async () => {
12447
12670
  For every selected route, the laboratory synthesizes a valid **contract witness**. It then
12448
12671
  changes types, removes required fields, crosses numeric and length bounds, inserts unknown
12449
12672
  properties, and descends into nested objects and arrays. A mutation is sent only after the
12450
- route&apos;s own Standard Schema validator proves it invalid. Query values are proved after URL
12673
+ route's own Standard Schema validator proves it invalid. Query values are proved after URL
12451
12674
  serialization, exactly as the server receives them.
12452
12675
 
12453
12676
  Invalid inputs must produce 422 by default. A valid witness is also executed for every
@@ -12457,7 +12680,7 @@ has a different validation response.
12457
12680
 
12458
12681
  ### Assert the server keeps its own contract
12459
12682
 
12460
- A route&rsquo;s `response` schema types the handler and the client, but nothing
12683
+ A route's `response` schema types the handler and the client, but nothing
12461
12684
  re-checks the bytes that actually leave the app. `validateResponses` closes that gap
12462
12685
  in tests: every JSON response is validated against the schema declared for its status, and a
12463
12686
  mismatch throws `ResponseContractViolation` straight through the
@@ -12476,7 +12699,7 @@ const res = await api.me.get() // ResponseContractViolation if the payload dri
12476
12699
  ```
12477
12700
 
12478
12701
  Whether it catches _undeclared extra_ fields depends on your validator, not on nifra: a
12479
- strict schema (`@nifrajs/schema`&rsquo;s `t.object`) reports them and the
12702
+ strict schema (`@nifrajs/schema`'s `t.object`) reports them and the
12480
12703
  test fails, while a stripping one (Zod, Valibot) accepts them silently. To catch extras
12481
12704
  regardless, or to stop them reaching the wire in production, use
12482
12705
  [
@@ -12486,7 +12709,7 @@ regardless, or to stop them reaching the wire in production, use
12486
12709
 
12487
12710
  ### Opaque schemas stay validator-neutral
12488
12711
 
12489
- Nifra&apos;s `t` schemas carry inspectable JSON Schema, so witness generation is
12712
+ Nifra's `t` schemas carry inspectable JSON Schema, so witness generation is
12490
12713
  automatic. Other Standard Schema libraries do not have to expose structure. Supply a known-good
12491
12714
  witness; their own validator still proves every hostile mutation.
12492
12715
 
@@ -12764,7 +12987,7 @@ The tooling reads the backend `backend/app.ts` exports. An app that
12764
12987
  factory, is invisible to the contract lock and the route lints until that file serves it.
12765
12988
  `nifra check` names each implemented operation the backend does not serve
12766
12989
  (NF-C039), and counts them when there is no `backend/app.ts` at all. It reads a
12767
- contract imported from a workspace package through that package&apos;s
12990
+ contract imported from a workspace package through that package's
12768
12991
  `exports`; a package installed from a registry is never read, and the check says
12769
12992
  so rather than passing it. Export the same app built with stand-in dependencies:
12770
12993
 
@@ -16029,10 +16252,22 @@ the check there only makes it need repeated swaps. Mutable or attacker-writable
16029
16252
  therefore outside the adapter's guarantee on those platforms. Store user-controlled files outside the static root and serve them through
16030
16253
  an application or object-storage path with its own validation policy.
16031
16254
 
16032
- Every file carries a strong `ETag` (from mtime and size), `Last-Modified`, and
16033
- `Accept-Ranges: bytes`. `If-None-Match` and `If-Modified-Since` get a bodyless 304; a single
16034
- `Range` on GET gets 206 (or 416 when unsatisfiable), gated by `If-Range`. Multi-range requests get
16035
- the whole file.
16255
+ Every file carries `Accept-Ranges: bytes` and a strong `ETag` from its content: 128 bits of its
16256
+ SHA-256, the same for the same bytes on every instance and on `servePublicDir`. A replacement that
16257
+ keeps a file's size and timestamps - `cp -p`, `rsync -a`, tar, a container image layer,
16258
+ SOURCE_DATE_EPOCH, the Nix store - still changes its tag. The tag is remembered per file version
16259
+ (device, inode, size, mtime and ctime), so a known file costs no extra read; the first request for a
16260
+ file reads it once (a file up to 256 KiB is then served from those bytes), and one changed in the last
16261
+ 2 s is read again until its ctime settles. A file over 256 MiB is tagged by that identity instead of
16262
+ its bytes: still strong, but different on each instance.
16263
+
16264
+ `Last-Modified` is sent only while the file's mtime is the time of its own last change (it matches its
16265
+ ctime), since a copy that keeps or normalizes mtimes gives a changed file the old date. Explicit
16266
+ validator headers still apply. `If-None-Match` takes precedence over `If-Modified-Since`; a matching
16267
+ condition gets a bodyless 304. `Range` on GET is parsed by a copy of `@nifrajs/core/range`, the parser
16268
+ `servePublicDir` uses, and gated by `If-Range`: it must name the file's strong tag, or its exact date
16269
+ when the file has no strong tag. One range (overlapping or adjacent ones merge into one) gets 206, a
16270
+ range-set that selects nothing gets 416, and several disjoint ranges get the whole file.
16036
16271
 
16037
16272
  ## Graceful shutdown on signals
16038
16273