@nifrajs/cli 5.9.0 → 5.11.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 (136) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/dist/check-diagnostics.d.ts +1 -0
  3. package/dist/check-diagnostics.d.ts.map +1 -1
  4. package/dist/check-diagnostics.js +4 -0
  5. package/dist/check-diagnostics.js.map +1 -1
  6. package/dist/check-scan.d.ts +1 -0
  7. package/dist/check-scan.d.ts.map +1 -1
  8. package/dist/check-scan.js +8 -1
  9. package/dist/check-scan.js.map +1 -1
  10. package/dist/check.d.ts.map +1 -1
  11. package/dist/check.js +7 -2
  12. package/dist/check.js.map +1 -1
  13. package/dist/cli.d.ts.map +1 -1
  14. package/dist/cli.js +21 -20
  15. package/dist/cli.js.map +1 -1
  16. package/dist/command-catalog.d.ts +1 -5
  17. package/dist/command-catalog.d.ts.map +1 -1
  18. package/dist/command-catalog.js +2 -21
  19. package/dist/command-catalog.js.map +1 -1
  20. package/dist/doctor.js +2 -2
  21. package/dist/doctor.js.map +1 -1
  22. package/dist/internal/source-facts.d.ts +30 -0
  23. package/dist/internal/source-facts.d.ts.map +1 -1
  24. package/dist/internal/source-facts.js +127 -0
  25. package/dist/internal/source-facts.js.map +1 -1
  26. package/dist/load.d.ts +4 -2
  27. package/dist/load.d.ts.map +1 -1
  28. package/dist/load.js +6 -1
  29. package/dist/load.js.map +1 -1
  30. package/dist/mcp-delegate.d.ts +17 -3
  31. package/dist/mcp-delegate.d.ts.map +1 -1
  32. package/dist/mcp-delegate.js +24 -9
  33. package/dist/mcp-delegate.js.map +1 -1
  34. package/dist/mcp-http.js +1 -1
  35. package/dist/mcp-http.js.map +1 -1
  36. package/dist/mcp-relay.d.ts +37 -0
  37. package/dist/mcp-relay.d.ts.map +1 -0
  38. package/dist/mcp-relay.js +129 -0
  39. package/dist/mcp-relay.js.map +1 -0
  40. package/dist/mcp-tool-meta.d.ts.map +1 -1
  41. package/dist/mcp-tool-meta.js +0 -1
  42. package/dist/mcp-tool-meta.js.map +1 -1
  43. package/dist/mcp.d.ts.map +1 -1
  44. package/dist/mcp.js +55 -1
  45. package/dist/mcp.js.map +1 -1
  46. package/dist/migrate-layout.d.ts.map +1 -1
  47. package/dist/migrate-layout.js +45 -33
  48. package/dist/migrate-layout.js.map +1 -1
  49. package/dist/recipes/5.10.0.d.ts +13 -0
  50. package/dist/recipes/5.10.0.d.ts.map +1 -0
  51. package/dist/recipes/5.10.0.js +45 -0
  52. package/dist/recipes/5.10.0.js.map +1 -0
  53. package/dist/recipes/5.11.0.d.ts +10 -0
  54. package/dist/recipes/5.11.0.d.ts.map +1 -0
  55. package/dist/recipes/5.11.0.js +50 -0
  56. package/dist/recipes/5.11.0.js.map +1 -0
  57. package/dist/recipes/index.d.ts.map +1 -1
  58. package/dist/recipes/index.js +4 -0
  59. package/dist/recipes/index.js.map +1 -1
  60. package/dist/review.d.ts.map +1 -1
  61. package/dist/review.js +3 -0
  62. package/dist/review.js.map +1 -1
  63. package/dist/rules/codes.d.ts +3 -0
  64. package/dist/rules/codes.d.ts.map +1 -1
  65. package/dist/rules/codes.js +3 -0
  66. package/dist/rules/codes.js.map +1 -1
  67. package/dist/rules/explanations.d.ts.map +1 -1
  68. package/dist/rules/explanations.js +15 -0
  69. package/dist/rules/explanations.js.map +1 -1
  70. package/dist/rules/internal-links.d.ts +5 -0
  71. package/dist/rules/internal-links.d.ts.map +1 -0
  72. package/dist/rules/internal-links.js +418 -0
  73. package/dist/rules/internal-links.js.map +1 -0
  74. package/dist/rules/legacy.d.ts.map +1 -1
  75. package/dist/rules/legacy.js +20 -0
  76. package/dist/rules/legacy.js.map +1 -1
  77. package/dist/rules/server-fn-namespace.d.ts +8 -0
  78. package/dist/rules/server-fn-namespace.d.ts.map +1 -0
  79. package/dist/rules/server-fn-namespace.js +43 -0
  80. package/dist/rules/server-fn-namespace.js.map +1 -0
  81. package/dist/rules/source-scan.d.ts +29 -0
  82. package/dist/rules/source-scan.d.ts.map +1 -0
  83. package/dist/rules/source-scan.js +38 -0
  84. package/dist/rules/source-scan.js.map +1 -0
  85. package/dist/rules/text-slot-boolean.d.ts.map +1 -1
  86. package/dist/rules/text-slot-boolean.js +21 -43
  87. package/dist/rules/text-slot-boolean.js.map +1 -1
  88. package/dist/source-rewrites.d.ts +0 -5
  89. package/dist/source-rewrites.d.ts.map +1 -1
  90. package/dist/source-rewrites.js +350 -10
  91. package/dist/source-rewrites.js.map +1 -1
  92. package/dist/typecheck-coverage.d.ts +9 -0
  93. package/dist/typecheck-coverage.d.ts.map +1 -1
  94. package/dist/typecheck-coverage.js +16 -0
  95. package/dist/typecheck-coverage.js.map +1 -1
  96. package/dist/upgrade.d.ts +19 -1
  97. package/dist/upgrade.d.ts.map +1 -1
  98. package/dist/upgrade.js +55 -2
  99. package/dist/upgrade.js.map +1 -1
  100. package/docs/examples.json +21 -9
  101. package/docs/llms-full.txt +800 -262
  102. package/docs/types.json +868 -128
  103. package/package.json +11 -11
  104. package/src/check-diagnostics.ts +5 -0
  105. package/src/check-scan.ts +9 -1
  106. package/src/check.ts +15 -3
  107. package/src/cli.ts +25 -20
  108. package/src/command-catalog.ts +2 -26
  109. package/src/doctor.ts +2 -2
  110. package/src/internal/source-facts.ts +155 -0
  111. package/src/load.ts +15 -3
  112. package/src/mcp-delegate.ts +37 -11
  113. package/src/mcp-http.ts +1 -1
  114. package/src/mcp-relay.ts +155 -0
  115. package/src/mcp-tool-meta.ts +0 -1
  116. package/src/mcp.ts +51 -1
  117. package/src/migrate-layout.ts +61 -29
  118. package/src/recipes/5.10.0.ts +46 -0
  119. package/src/recipes/5.11.0.ts +51 -0
  120. package/src/recipes/index.ts +4 -0
  121. package/src/review.ts +3 -0
  122. package/src/rules/codes.ts +3 -0
  123. package/src/rules/explanations.ts +15 -0
  124. package/src/rules/internal-links.ts +490 -0
  125. package/src/rules/legacy.ts +21 -0
  126. package/src/rules/server-fn-namespace.ts +47 -0
  127. package/src/rules/source-scan.ts +66 -0
  128. package/src/rules/text-slot-boolean.ts +26 -42
  129. package/src/source-rewrites.ts +383 -12
  130. package/src/typecheck-coverage.ts +23 -0
  131. package/src/upgrade.ts +71 -3
  132. package/dist/sync-routes.d.ts +0 -29
  133. package/dist/sync-routes.d.ts.map +0 -1
  134. package/dist/sync-routes.js +0 -56
  135. package/dist/sync-routes.js.map +0 -1
  136. package/src/sync-routes.ts +0 -70
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nifrajs/cli",
3
- "version": "5.9.0",
3
+ "version": "5.11.0",
4
4
  "description": "The nifra CLI - zero-config dev/build/start for a nifra app (`nifra dev`, `nifra build`, `nifra start`).",
5
5
  "keywords": [
6
6
  "bun",
@@ -70,16 +70,16 @@
70
70
  "access": "public"
71
71
  },
72
72
  "dependencies": {
73
- "@nifrajs/client": "5.9.0",
74
- "@nifrajs/core": "5.9.0",
75
- "@nifrajs/agent-review": "5.9.0",
76
- "@nifrajs/i18n": "5.9.0",
77
- "@nifrajs/mcp": "5.9.0",
78
- "@nifrajs/mcp-db": "5.9.0",
79
- "@nifrajs/runner": "5.9.0",
80
- "@nifrajs/schema": "5.9.0",
81
- "@nifrajs/testing": "5.9.0",
82
- "@nifrajs/web": "5.9.0"
73
+ "@nifrajs/client": "5.11.0",
74
+ "@nifrajs/core": "5.11.0",
75
+ "@nifrajs/agent-review": "5.11.0",
76
+ "@nifrajs/i18n": "5.11.0",
77
+ "@nifrajs/mcp": "5.11.0",
78
+ "@nifrajs/mcp-db": "5.11.0",
79
+ "@nifrajs/runner": "5.11.0",
80
+ "@nifrajs/schema": "5.11.0",
81
+ "@nifrajs/testing": "5.11.0",
82
+ "@nifrajs/web": "5.11.0"
83
83
  },
84
84
  "repository": {
85
85
  "type": "git",
@@ -25,6 +25,7 @@ import { freezeProjectFacts, type ProjectFactsSeed } from "./project-facts.ts"
25
25
  import { contractVisibilityRule } from "./rules/contract-visibility.ts"
26
26
  import { dataGuardRules } from "./rules/data-guard.ts"
27
27
  import { parseRulePacks, runRuleRegistry } from "./rules/index.ts"
28
+ import { internalLinkRules } from "./rules/internal-links.ts"
28
29
  import { islandRules } from "./rules/islands.ts"
29
30
  import { retiredLayoutRule } from "./rules/layout.ts"
30
31
  import { LEGACY_RULE_CODES, LEGACY_RULE_ORDER, legacyRules } from "./rules/legacy.ts"
@@ -35,6 +36,7 @@ import { routeStatementRule } from "./rules/route-statement.ts"
35
36
  import { routeRules } from "./rules/routes.ts"
36
37
  import { secretRules } from "./rules/secrets.ts"
37
38
  import { securityRules } from "./rules/security.ts"
39
+ import { serverFnNamespaceRule } from "./rules/server-fn-namespace.ts"
38
40
  import { swapRules } from "./rules/swap.ts"
39
41
  import { textSlotBooleanRule } from "./rules/text-slot-boolean.ts"
40
42
  import { undeclaredResponseRule } from "./rules/undeclared-response.ts"
@@ -381,6 +383,7 @@ export interface CheckTypecheckResult {
381
383
  /** TypeScript sources found with no tsconfig.json to typecheck them. */
382
384
  readonly sourcesWithoutTsconfig?: number
383
385
  readonly outsideProgram?: readonly string[]
386
+ readonly routeTableOutsideProgram?: string
384
387
  }
385
388
 
386
389
  export interface CheckAnalysisInput {
@@ -507,6 +510,8 @@ export async function collectCheckDiagnostics(
507
510
  routeStatementRule,
508
511
  undeclaredResponseRule,
509
512
  textSlotBooleanRule,
513
+ ...internalLinkRules,
514
+ serverFnNamespaceRule,
510
515
  ...zoneRules,
511
516
  ...dataGuardRules,
512
517
  ...secretRules,
package/src/check-scan.ts CHANGED
@@ -78,7 +78,7 @@ const IGNORED_DIR =
78
78
  // legitimately drives `fetch`, hand-rolls a client, and calls a route directly. It is NOT excluded from
79
79
  // `nifra doctor`: tsc typechecks tests, so an import a test declares nowhere is a real broken build.
80
80
  const TEST_FILE = /\.(test|spec)\.[cm]?[jt]sx?$/
81
- const IGNORED = new RegExp(`${IGNORED_DIR.source}|${TEST_FILE.source}`)
81
+ export const IGNORED = new RegExp(`${IGNORED_DIR.source}|${TEST_FILE.source}`)
82
82
 
83
83
  /** Paths crossing the scanner boundary are project-relative identifiers, not filesystem paths. Keep
84
84
  * them stable across runtimes so rules, diagnostics, ignore globs, and import chains have one shape. */
@@ -2150,6 +2150,14 @@ function writesTo(ts: TypeScriptApi, root: TSApi.Node, name: string): SqlWrite[]
2150
2150
  }
2151
2151
 
2152
2152
  function mentionsName(ts: TypeScriptApi, node: TSApi.Node, name: string): boolean {
2153
+ // A member/key named like the variable does not read that variable (`record = client.record()`).
2154
+ if (ts.isPropertyAccessExpression(node)) return mentionsName(ts, node.expression, name)
2155
+ if (ts.isPropertyAssignment(node)) {
2156
+ return (
2157
+ mentionsName(ts, node.initializer, name) ||
2158
+ (ts.isComputedPropertyName(node.name) && mentionsName(ts, node.name.expression, name))
2159
+ )
2160
+ }
2153
2161
  if (ts.isIdentifier(node)) return node.text === name
2154
2162
  return ts.forEachChild(node, (child) => mentionsName(ts, child, name) || undefined) === true
2155
2163
  }
package/src/check.ts CHANGED
@@ -50,7 +50,12 @@ import {
50
50
  import type { ContractCheckFacts, ProjectFactsSeed } from "./project-facts.ts"
51
51
  import { RULE_CODES } from "./rules/codes.ts"
52
52
  import { sourceIndex } from "./rules/index.ts"
53
- import { filesOutsideProgram, splitListedFiles, typecheckProjects } from "./typecheck-coverage.ts"
53
+ import {
54
+ filesOutsideProgram,
55
+ routeTableOutsideProgram,
56
+ splitListedFiles,
57
+ typecheckProjects,
58
+ } from "./typecheck-coverage.ts"
54
59
 
55
60
  export type {
56
61
  CheckAnalysisInput,
@@ -110,6 +115,8 @@ interface TypecheckResult {
110
115
  readonly programFiles?: readonly string[]
111
116
  /** Zoned TypeScript files outside the program, project-relative: the typecheck never read them. */
112
117
  readonly outsideProgram?: readonly string[]
118
+ /** The generated route table, when it exists and the program does not hold it. */
119
+ readonly routeTableOutsideProgram?: string
113
120
  }
114
121
 
115
122
  /**
@@ -384,7 +391,7 @@ function withoutTsconfig(
384
391
  function withProgramCoverage(
385
392
  cwd: string,
386
393
  result: TypecheckResult,
387
- sourceFiles: ReadonlyArray<{ readonly file: string }>,
394
+ sourceFiles: ReadonlyArray<{ readonly file: string; readonly content: string }>,
388
395
  checkConfig: CheckConfig,
389
396
  ): TypecheckResult {
390
397
  const { programFiles, ...rest } = result
@@ -395,7 +402,12 @@ function withProgramCoverage(
395
402
  sourceFiles.map((source) => source.file),
396
403
  programFiles,
397
404
  ).filter((file) => !ignore?.some((pattern) => safeIgnoreGlobMatch(pattern, file)))
398
- return outside.length === 0 ? rest : { ...rest, outsideProgram: outside }
405
+ const table = routeTableOutsideProgram(cwd, programFiles, sourceFiles)
406
+ return {
407
+ ...rest,
408
+ ...(outside.length === 0 ? {} : { outsideProgram: outside }),
409
+ ...(table === undefined ? {} : { routeTableOutsideProgram: table }),
410
+ }
399
411
  }
400
412
 
401
413
  /** Build the rule input from one source walk and the other check-wide scans. */
package/src/cli.ts CHANGED
@@ -159,6 +159,8 @@ Usage:
159
159
  _routes.json. The server entry is generated from your
160
160
  backend/framework.ts (adapter) + backend/app.ts + routes/.
161
161
  --report prints a per-chunk size + gzip table (biggest first).
162
+ Vercel defaults to Edge; export vercelRuntime = "node" from
163
+ nifra.config.ts for ordinary Node.js 22 serverless SSR.
162
164
  [--vite | --bun] Force the bundler. Without a flag it follows your config: Bun
163
165
  (faster, Bun-native) unless your ONLY transforms are
164
166
  \`vitePlugins\`, which the Bun build cannot run - then Vite,
@@ -238,9 +240,6 @@ Usage:
238
240
  nifra sync-manifest Regenerate a committed web server-manifest.ts from routes/ WITHOUT
239
241
  a full build - clears server-manifest drift after a route add/rename
240
242
  (a new hydrating component still needs a full build).
241
- nifra sync-routes Regenerate nifra-routes.d.ts from routes/ so navigate({ to, search })
242
- is typed against each static route's searchSchema (a stale shape is a
243
- tsc error). Include the file in your tsconfig. Pure file write.
244
243
  nifra snapshot [--out <file>] Write the backend's API contract (routes + schemas) as plain
245
244
  JSON - the baseline for \`nifra diff\`. Default api-snapshot.json.
246
245
  nifra diff [<baseline>] [--json] Breaking-change gate: re-snapshot the contract and compare
@@ -291,7 +290,9 @@ Usage:
291
290
  [--write] [--no-verify] installed version and it, oldest first: move removed packages,
292
291
  [--list] [--json] apply exact imports, pin every matching dependency (keeping
293
292
  [--exact] ^/~, or exact with --exact; a peer range only when it
294
- excludes the target), then verify with nifra check.
293
+ [--from <version>] excludes the target), then verify with nifra check. --from
294
+ names the installed version when the pins no longer do,
295
+ such as after bumping them by hand.
295
296
  [--allow-downgrade] Dry-run by default; --write applies, then verifies (--no-verify
296
297
  [--allow-linked-skew] to skip) and prints how hook scope changed (--no-hooks to skip)
297
298
  [--no-hooks] once the target is installed, else prints the install command
@@ -310,14 +311,15 @@ Usage:
310
311
  (--zones keeps them in place and lists them in package.json
311
312
  "nifra.zones"). Dry-run by default; --write applies.
312
313
  nifra scaffold hole <route> <name> [--shared] [--interactive] [--timeout <ms>] [--server] [--json]
313
- Experimental: add a partially prerendered hole to a route whose
314
+ Add a partially prerendered hole to a route whose
314
315
  backend half exports shellLoader - its definition and <Hole> in
315
316
  the page, its loader and output schema in the backend half. A
316
317
  Vue or Svelte page gets the code to paste; --server writes a
317
318
  React server component for the hole.
318
319
  nifra types [--check] [--json] Generate each route's ./+types module under .nifra/types: its
319
320
  params, the data its output schemas let through, and api typed
320
- by backend/app.ts. dev, build and check refresh them too;
321
+ by backend/app.ts, plus routes.d.ts, the table href() checks
322
+ links against. dev, build and check refresh them too;
321
323
  --check fails when one is stale.
322
324
  nifra schemas [--write] [--check] [--json]
323
325
  Draft loaderOutput/actionOutput from each loader's and
@@ -354,7 +356,7 @@ set in the process environment is never overwritten by a file.
354
356
  ${renderCommandCatalogHelp()}`
355
357
 
356
358
  // Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
357
- const CLI_VERSION = "5.9.0"
359
+ const CLI_VERSION = "5.11.0"
358
360
 
359
361
  // A render adapter + nifra server are opaque to the CLI (it just forwards them); cast at the seam.
360
362
  const asAdapter = (v: unknown): RenderAdapter => v as RenderAdapter
@@ -830,7 +832,9 @@ async function buildForTarget(
830
832
  flag: string | undefined,
831
833
  flags: Flags,
832
834
  ): Promise<void> {
833
- const { parseBuildTarget, renderSizeReport } = await import("@nifrajs/web/build")
835
+ const { parseBuildTarget, renderSizeReport, validateVercelRuntime } = await import(
836
+ "@nifrajs/web/build"
837
+ )
834
838
  const target = parseBuildTarget(
835
839
  flag ?? app.framework.target ?? "bun",
836
840
  flag === undefined ? "target in nifra.config.ts" : "--target",
@@ -839,7 +843,13 @@ async function buildForTarget(
839
843
  throw new Error("[nifra] `nifra build` takes `--vite` or `--bun`, not both.")
840
844
  }
841
845
  const { framework: fw } = app
846
+ validateVercelRuntime(target, fw.vercelRuntime)
842
847
  if (fw.componentPipeline !== undefined) {
848
+ // The component pipeline already owns its Vercel Node handler; this selector is ordinary SSR only.
849
+ if (fw.vercelRuntime !== undefined)
850
+ throw new Error(
851
+ "[nifra/components] vercelRuntime selects ordinary SSR only; omit it for the component pipeline",
852
+ )
843
853
  if (flags.bun)
844
854
  throw new Error(
845
855
  "[nifra/components] Components require the Vite 8 pipeline; Bun remains a server runtime",
@@ -954,6 +964,7 @@ async function buildForTarget(
954
964
  ...(fw.cssCodeSplit !== undefined ? { cssCodeSplit: fw.cssCodeSplit } : {}),
955
965
  ...(fw.cssLoading !== undefined ? { cssLoading: fw.cssLoading } : {}),
956
966
  ...(fw.clientIp !== undefined ? { clientIp: fw.clientIp } : {}),
967
+ ...(fw.vercelRuntime !== undefined ? { vercelRuntime: fw.vercelRuntime } : {}),
957
968
  ...(fw.selfHost !== undefined ? { selfHost: fw.selfHost } : {}),
958
969
  live: fw.live?.clientEntry,
959
970
  // Prerendering drives a built app: the static target is made of its pages, and a bun or node server
@@ -1150,7 +1161,6 @@ const READ_ONLY_COMMANDS: ReadonlySet<string> = new Set([
1150
1161
  "openapi",
1151
1162
  "routes",
1152
1163
  "sync-manifest",
1153
- "sync-routes",
1154
1164
  ])
1155
1165
 
1156
1166
  const HELD_OPEN_GRACE_MS = 2_000
@@ -1443,19 +1453,14 @@ async function main(): Promise<void> {
1443
1453
  // recipe, then verified with `nifra check`. Dispatch before the eager `loadApp` - it must run on any
1444
1454
  // repo (API-only, not built, or mid-upgrade with edits that don't yet typecheck under dry-run).
1445
1455
  if (command === "upgrade") {
1446
- const { runUpgrade } = await import("./upgrade.ts")
1447
- const version = argv.slice(1).find((arg) => !arg.startsWith("-"))
1456
+ if (argv.includes("--help") || argv.includes("-h")) {
1457
+ console.log(HELP)
1458
+ return
1459
+ }
1460
+ const { parseUpgradeArgs, runUpgrade } = await import("./upgrade.ts")
1448
1461
  try {
1449
1462
  const ok = await runUpgrade(process.cwd(), {
1450
- ...(version !== undefined ? { version } : {}),
1451
- write: argv.includes("--write"),
1452
- json: argv.includes("--json"),
1453
- list: argv.includes("--list"),
1454
- verify: !argv.includes("--no-verify"),
1455
- hooks: !argv.includes("--no-hooks"),
1456
- allowDowngrade: argv.includes("--allow-downgrade"),
1457
- allowLinkedSkew: argv.includes("--allow-linked-skew"),
1458
- exact: argv.includes("--exact"),
1463
+ ...parseUpgradeArgs(argv.slice(1)),
1459
1464
  cliVersion: CLI_VERSION,
1460
1465
  })
1461
1466
  if (!ok) process.exitCode = 1
@@ -533,10 +533,6 @@ interface ContractsCommandOutput {
533
533
  readonly present?: boolean
534
534
  readonly vacuous?: boolean
535
535
  }
536
- interface SyncCommandOutput {
537
- readonly ok: true
538
- readonly results: readonly unknown[]
539
- }
540
536
  interface SyncManifestCommandOutput {
541
537
  readonly ok: boolean
542
538
  readonly results: readonly SyncManifestResult[]
@@ -1674,7 +1670,7 @@ const scaffoldSpec: CommandSpec<ScaffoldInput, HoleScaffoldResult> = {
1674
1670
  required: ["ok", "page", "backend", "changed", "snippets", "next"],
1675
1671
  }),
1676
1672
  transports: ["cli"],
1677
- stability: "experimental",
1673
+ stability: "stable",
1678
1674
  argv: {
1679
1675
  positionals: ["kind", "route", "name"],
1680
1676
  flags: [
@@ -1785,7 +1781,7 @@ const targetSpec: CommandSpec<TargetInput, TargetOutput> = {
1785
1781
  const typesSpec: CommandSpec<TypesInput, RouteTypesReport> = {
1786
1782
  name: "types",
1787
1783
  summary:
1788
- "Generate each route's `./+types` module (params, schema-typed data, typed `api`); `--check` fails when one is stale.",
1784
+ "Generate each route's `./+types` module (params, schema-typed data, typed `api`) and `.nifra/types/routes.d.ts`, the route table `href()` checks links against; `--check` fails when one is stale.",
1789
1785
  input: TYPES_SCHEMA,
1790
1786
  output: output({
1791
1787
  type: "object",
@@ -2031,25 +2027,6 @@ const syncManifestSpec: CommandSpec<SyncInput, SyncManifestCommandOutput> = {
2031
2027
  success: (out) => out.ok,
2032
2028
  }
2033
2029
 
2034
- const syncRoutesSpec: CommandSpec<SyncInput, SyncCommandOutput> = {
2035
- name: "sync-routes",
2036
- summary: "Regenerate nifra-routes.d.ts so typed navigation follows route search schemas.",
2037
- input: SYNC_SCHEMA,
2038
- output: syncOutput(),
2039
- transports: ["cli", "mcp"],
2040
- stability: "stable",
2041
- argv: SYNC_ARGV,
2042
- async run(_value, ctx) {
2043
- const result = await (await import("./sync-routes.ts")).syncRouteTypes(ctx.cwd)
2044
- return { ok: true, results: result === null ? [] : [result] }
2045
- },
2046
- render: (out) => [
2047
- out.results.length === 0
2048
- ? "nifra sync-routes: no routes/ directory found. Run from your project root."
2049
- : `✓ checked ${out.results.length} route type output`,
2050
- ],
2051
- }
2052
-
2053
2030
  const proveSpec: CommandSpec<ProveInput, ProjectWorkGraphResult> = {
2054
2031
  name: "prove",
2055
2032
  summary:
@@ -2209,7 +2186,6 @@ export const commandSpecs = Object.freeze([
2209
2186
  diffSpec,
2210
2187
  contractsSpec,
2211
2188
  syncManifestSpec,
2212
- syncRoutesSpec,
2213
2189
  proveSpec,
2214
2190
  replaySpec,
2215
2191
  smokeSpec,
package/src/doctor.ts CHANGED
@@ -884,9 +884,9 @@ const KNOWN_AUTH_PACKAGES = [
884
884
  const IDENTITY_SIGNAL = /\b(?:identityCookies\s*:|rotateIdentityEpoch\s*\(|identityChanged\s*\()/
885
885
  // A session cookie renamed outright: Better Auth's `advanced.cookies.session_token.name`, Auth.js's
886
886
  // `cookies.sessionToken.name`, `@nifrajs/auth`'s `cookieName`. A Better Auth `cookiePrefix` keeps the
887
- // suffix the identity epoch matches, so it is not one.
887
+ // suffix the identity epoch matches, so it is not one, and neither is a type's `name: string`.
888
888
  const RENAMED_SESSION =
889
- /\b(?:session_token|sessionToken)\s*:\s*\{[^}]*\bname\s*:|\bcookieName\s*:\s*["'`]/
889
+ /\b(?:session_token|sessionToken)\s*:\s*\{[^}]*\bname\s*:\s*["'`]|\bcookieName\s*:\s*["'`]/
890
890
 
891
891
  // Below the app itself, only what a package loads at runtime is followed.
892
892
  const AUTH_RUNTIME_FIELDS = ["dependencies", "peerDependencies", "optionalDependencies"] as const
@@ -36,6 +36,28 @@ export interface TextSlotBooleanCoercion {
36
36
  readonly path: string
37
37
  }
38
38
 
39
+ /** An `<a href>` whose value is a path of this origin, from {@link SourceFacts.internalAnchors}. */
40
+ export interface InternalAnchor {
41
+ /** The start of the `href` attribute. */
42
+ readonly position: number
43
+ /** The path as written; each `${...}` of a template literal is {@link ANCHOR_HOLE}. */
44
+ readonly path: string
45
+ }
46
+
47
+ /** Stands for one `${...}` in {@link InternalAnchor.path}. */
48
+ export const ANCHOR_HOLE = "\u0000"
49
+
50
+ /** A `serverFunctions("namespace", module)` mount of a `*.fn.ts` module, from {@link SourceFacts.serverFunctionMounts}. */
51
+ export interface ServerFunctionMount {
52
+ /** The start of the namespace literal. */
53
+ readonly position: number
54
+ /** The start of the `serverFunctions(...)` call, where a `nifra-expect` comment is written above. */
55
+ readonly callPosition: number
56
+ readonly namespace: string
57
+ /** The specifier the mounted module namespace was imported from. */
58
+ readonly specifier: string
59
+ }
60
+
39
61
  export interface SourceFacts {
40
62
  parse(file: string, content: string): TSApi.SourceFile | undefined
41
63
  isValueImportAt(
@@ -92,6 +114,17 @@ export interface SourceFacts {
92
114
  * another file is not followed.
93
115
  */
94
116
  textSlotBooleanCoercions(source: TSApi.SourceFile): readonly TextSlotBooleanCoercion[]
117
+ /**
118
+ * The `serverFunctions("namespace", module)` calls in `source` whose `module` is a namespace import
119
+ * (`import * as todos from "./todos.fn"`) of a `*.fn` file. A module reached any other way is left out.
120
+ */
121
+ serverFunctionMounts(source: TSApi.SourceFile): readonly ServerFunctionMount[]
122
+ /**
123
+ * The `<a>` elements of `source` whose `href` is a string or template literal that starts with
124
+ * exactly one `/`. A value that is built (`href={url}`, `href={href({ to })}`), an external URL, a
125
+ * `#hash` and a `//host` are left out.
126
+ */
127
+ internalAnchors(source: TSApi.SourceFile): readonly InternalAnchor[]
95
128
  /** Whether the function `source` exports as `name` returns a raw `Response` on some path. */
96
129
  exportReturnsResponse(source: TSApi.SourceFile, name: string): boolean
97
130
  /** Whether the `import` keyword at `position` starts a runtime `import(specifier)` call (true) or a
@@ -172,6 +205,9 @@ function routeRegistration(
172
205
  return { name: node.expression.name, method, path: first.text, rest }
173
206
  }
174
207
 
208
+ const SERVER_FN_MODULE_ID = "@nifrajs/web/fn"
209
+ const SERVER_FN_FILE = /\.fn(?:\.[cm]?[jt]sx?)?$/
210
+
175
211
  const ZOD_MODULES: ReadonlySet<string> = new Set(["zod", "zod/v4", "zod/mini", "zod/v4/mini"])
176
212
 
177
213
  /** The names `source` binds zod's namespace to (`z`), and those it binds zod's `coerce` to. */
@@ -202,6 +238,23 @@ function zodBindings(
202
238
  return { namespaces, coerce }
203
239
  }
204
240
 
241
+ /** Every name `source` declares other than by import: variables, parameters, functions and classes, any scope. */
242
+ function declaredNames(ts: TypeScriptApi, source: TSApi.SourceFile): Set<string> {
243
+ const names = new Set<string>()
244
+ const bind = (name: TSApi.BindingName): void => {
245
+ if (ts.isIdentifier(name)) names.add(name.text)
246
+ else for (const element of name.elements) if (ts.isBindingElement(element)) bind(element.name)
247
+ }
248
+ const visit = (node: TSApi.Node): void => {
249
+ if (ts.isVariableDeclaration(node) || ts.isParameter(node)) bind(node.name)
250
+ else if ((ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) && node.name)
251
+ names.add(node.name.text)
252
+ ts.forEachChild(node, visit)
253
+ }
254
+ visit(source)
255
+ return names
256
+ }
257
+
205
258
  /** The initializer of each variable of `source`, any scope, by name: the first one wins. */
206
259
  function variableInitializers(
207
260
  ts: TypeScriptApi,
@@ -747,6 +800,40 @@ export function createSourceFacts(
747
800
  return routes.sort((a, b) => a.position - b.position)
748
801
  }
749
802
 
803
+ const internalAnchors = (source: TSApi.SourceFile): readonly InternalAnchor[] => {
804
+ const found: InternalAnchor[] = []
805
+ const pathOf = (node: TSApi.Expression): string | undefined => {
806
+ if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) return node.text
807
+ if (!ts.isTemplateExpression(node)) return undefined
808
+ return (
809
+ node.head.text + node.templateSpans.map((span) => ANCHOR_HOLE + span.literal.text).join("")
810
+ )
811
+ }
812
+ const visit = (node: TSApi.Node): void => {
813
+ if (
814
+ (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) &&
815
+ ts.isIdentifier(node.tagName) &&
816
+ node.tagName.text === "a"
817
+ ) {
818
+ for (const attribute of node.attributes.properties) {
819
+ if (!ts.isJsxAttribute(attribute) || attribute.name.getText(source) !== "href") continue
820
+ const init = attribute.initializer
821
+ if (init === undefined) continue
822
+ const path = ts.isStringLiteral(init)
823
+ ? init.text
824
+ : ts.isJsxExpression(init) && init.expression !== undefined
825
+ ? pathOf(init.expression)
826
+ : undefined
827
+ if (path?.startsWith("/") && !path.startsWith("//"))
828
+ found.push({ position: attribute.getStart(source), path })
829
+ }
830
+ }
831
+ ts.forEachChild(node, visit)
832
+ }
833
+ visit(source)
834
+ return found
835
+ }
836
+
750
837
  const textSlotBooleanCoercions = (
751
838
  source: TSApi.SourceFile,
752
839
  ): readonly TextSlotBooleanCoercion[] => {
@@ -853,6 +940,72 @@ export function createSourceFacts(
853
940
  }
854
941
  }
855
942
 
943
+ const serverFunctionMounts = (source: TSApi.SourceFile): readonly ServerFunctionMount[] => {
944
+ const callees = new Set<string>()
945
+ const members = new Set<string>()
946
+ const modules = new Map<string, string>()
947
+ for (const statement of source.statements) {
948
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
949
+ continue
950
+ const clause = statement.importClause
951
+ if (clause === undefined || clause.isTypeOnly) continue
952
+ const specifier = statement.moduleSpecifier.text
953
+ const bindings = clause.namedBindings
954
+ if (bindings === undefined) continue
955
+ if (ts.isNamespaceImport(bindings)) {
956
+ if (specifier === SERVER_FN_MODULE_ID) members.add(bindings.name.text)
957
+ else if (SERVER_FN_FILE.test(specifier)) modules.set(bindings.name.text, specifier)
958
+ } else if (specifier === SERVER_FN_MODULE_ID) {
959
+ for (const element of bindings.elements) {
960
+ if (
961
+ !element.isTypeOnly &&
962
+ (element.propertyName ?? element.name).text === "serverFunctions"
963
+ )
964
+ callees.add(element.name.text)
965
+ }
966
+ }
967
+ }
968
+ if (modules.size === 0 || (callees.size === 0 && members.size === 0)) return []
969
+ // A name the file declares again (a local `serverFunctions`, a parameter called like the module) is
970
+ // not the import, whatever scope it sits in: leave those calls out rather than guess the scope.
971
+ for (const name of declaredNames(ts, source)) {
972
+ callees.delete(name)
973
+ members.delete(name)
974
+ modules.delete(name)
975
+ }
976
+ const mounts: ServerFunctionMount[] = []
977
+ const visit = (node: TSApi.Node): void => {
978
+ if (ts.isCallExpression(node)) {
979
+ const callee = node.expression
980
+ const [namespace, module] = node.arguments
981
+ if (
982
+ (ts.isIdentifier(callee)
983
+ ? callees.has(callee.text)
984
+ : ts.isPropertyAccessExpression(callee) &&
985
+ ts.isIdentifier(callee.expression) &&
986
+ members.has(callee.expression.text) &&
987
+ callee.name.text === "serverFunctions") &&
988
+ namespace !== undefined &&
989
+ ts.isStringLiteralLike(namespace) &&
990
+ module !== undefined &&
991
+ ts.isIdentifier(module)
992
+ ) {
993
+ const specifier = modules.get(module.text)
994
+ if (specifier !== undefined)
995
+ mounts.push({
996
+ position: namespace.getStart(source),
997
+ callPosition: node.getStart(source),
998
+ namespace: namespace.text,
999
+ specifier,
1000
+ })
1001
+ }
1002
+ }
1003
+ ts.forEachChild(node, visit)
1004
+ }
1005
+ visit(source)
1006
+ return mounts
1007
+ }
1008
+
856
1009
  return {
857
1010
  parse,
858
1011
  isValueImportAt,
@@ -863,6 +1016,8 @@ export function createSourceFacts(
863
1016
  untypedResponseRoutes,
864
1017
  undeclaredResponseRoutes,
865
1018
  textSlotBooleanCoercions,
1019
+ internalAnchors,
1020
+ serverFunctionMounts,
866
1021
  exportReturnsResponse,
867
1022
  isDynamicImportAt,
868
1023
  }
package/src/load.ts CHANGED
@@ -71,6 +71,8 @@ export interface NifraFramework {
71
71
  /** The deploy target `nifra build` emits without `--target` (default `"bun"`); `nifra target <t>`
72
72
  * rewrites it. */
73
73
  readonly target?: string
74
+ /** Ordinary Vercel SSR: Edge by default, or opt into a Node.js 22 serverless handler. */
75
+ readonly vercelRuntime?: "edge" | "node"
74
76
  /** `"platform"` makes a `cloudflare` / `vercel` build read `c.clientIp` from the header that
75
77
  * platform's edge overwrites (`cf-connecting-ip` / `x-real-ip`). Left out, an edge build has no
76
78
  * caller address, so a per-caller `rateLimit` refuses every request. Declare it only while that edge
@@ -93,8 +95,8 @@ export interface NifraFramework {
93
95
  /** Client-visible environment prefix (default `"PUBLIC_"`; empty disables exposure). With both
94
96
  * configs, `nifra.config.ts` wins and `backend/framework.ts` fills it in when left unset. */
95
97
  readonly publicEnvPrefix?: string
96
- /** Reviewed false positives of `nifra build`'s secret scan, each `{ rule, file, reason }` (or
97
- * `{ rule: "private-env-value", env, reason }`). There is no exemption by value. */
98
+ /** Reviewed false positives of `nifra build`'s secret scan. A `file` scope applies throughout that
99
+ * file; for `private-env-value`, an `env` scope applies to every finding from that variable. */
98
100
  readonly secretExemptions?: readonly SecretExemption[]
99
101
  /** Vite production CSS output policy. `false` emits one aggregate stylesheet for the whole client. */
100
102
  readonly cssCodeSplit?: boolean
@@ -225,11 +227,21 @@ function assertFrameworkWebOptions(fw: Partial<NifraFramework>, configFile: stri
225
227
  wrong("publicEnvPrefix", 'a string such as "PUBLIC_", or "" to expose no environment variable')
226
228
  }
227
229
  if (fw.secretExemptions !== undefined && !Array.isArray(fw.secretExemptions)) {
228
- wrong("secretExemptions", "an array of { rule, file, reason } entries")
230
+ wrong(
231
+ "secretExemptions",
232
+ 'an array of { rule, file, reason } entries (or { rule: "private-env-value", env, reason })',
233
+ )
229
234
  }
230
235
  if (fw.target !== undefined && typeof fw.target !== "string") {
231
236
  wrong("target", 'a deploy target name such as "bun"')
232
237
  }
238
+ if (
239
+ fw.vercelRuntime !== undefined &&
240
+ fw.vercelRuntime !== "edge" &&
241
+ fw.vercelRuntime !== "node"
242
+ ) {
243
+ wrong("vercelRuntime", '"edge" or "node" (only for target "vercel")')
244
+ }
233
245
  if (fw.clientIp !== undefined && fw.clientIp !== "platform") {
234
246
  wrong("clientIp", '"platform" (trust the edge platform\'s client-address header), or left out')
235
247
  }
@@ -90,18 +90,22 @@ export function isOtherInstall(dir: string): boolean {
90
90
  }
91
91
 
92
92
  /**
93
- * Hand this stdio session to the project's own CLI when it installs a different version, or the same
94
- * version from another directory. Resolves to the child's exit code once the session ends, or
95
- * `undefined` when this process should serve itself (this is the project's CLI, no project CLI or
96
- * bin, already a hand-off, or the spawn failed). Must run before anything reads stdin: the child
97
- * inherits the descriptor and owns the whole conversation.
93
+ * The command that runs the project's own CLI as `nifra mcp`, when the project installs a different
94
+ * version, or the same version from another directory. `undefined` when this process should serve
95
+ * itself: this is the project's CLI, no project CLI or bin, or this process is already a hand-off.
98
96
  */
99
- export async function delegateToProjectCli(options: {
100
- readonly cwd: string
97
+ export async function projectCliCommand(options: {
101
98
  readonly root: string
102
99
  readonly version: string
103
100
  readonly args: readonly string[]
104
- }): Promise<number | undefined> {
101
+ }): Promise<
102
+ | {
103
+ readonly cli: ProjectCli
104
+ readonly command: readonly string[]
105
+ readonly env: Record<string, string | undefined>
106
+ }
107
+ | undefined
108
+ > {
105
109
  if (process.env[MCP_DELEGATED_ENV] === "1") return undefined
106
110
  const cli = await findProjectCli(options.root)
107
111
  if (
@@ -112,10 +116,32 @@ export async function delegateToProjectCli(options: {
112
116
  return undefined
113
117
  // Not the `.bin` shim: its `bun` would load the project's `.env`, and the inherited
114
118
  // NIFRA_MCP_WITHOUT_ENV_FILES then tells that CLI the values are already gone.
115
- return handOffSession([process.execPath, "--no-env-file", cli.bin, "mcp", ...options.args], {
116
- cwd: options.cwd,
119
+ return {
120
+ cli,
121
+ command: [process.execPath, "--no-env-file", cli.bin, "mcp", ...options.args],
117
122
  env: { ...process.env, [MCP_DELEGATED_ENV]: "1" },
118
- announce: `[nifra] mcp: this CLI is ${options.version}; the project installs @nifrajs/cli ${cli.version} - serving this session from ${cli.bin}`,
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Hand this stdio session to the project's own CLI when it installs a different version, or the same
128
+ * version from another directory. Resolves to the child's exit code once the session ends, or
129
+ * `undefined` when this process should serve itself (see {@link projectCliCommand}, or the spawn
130
+ * failed). Must run before anything reads stdin: the child inherits the descriptor and owns the whole
131
+ * conversation.
132
+ */
133
+ export async function delegateToProjectCli(options: {
134
+ readonly cwd: string
135
+ readonly root: string
136
+ readonly version: string
137
+ readonly args: readonly string[]
138
+ }): Promise<number | undefined> {
139
+ const target = await projectCliCommand(options)
140
+ if (target === undefined) return undefined
141
+ return handOffSession(target.command, {
142
+ cwd: options.cwd,
143
+ env: target.env,
144
+ announce: `[nifra] mcp: this CLI is ${options.version}; the project installs @nifrajs/cli ${target.cli.version} - serving this session from ${target.cli.bin}`,
119
145
  })
120
146
  }
121
147
 
package/src/mcp-http.ts CHANGED
@@ -30,7 +30,7 @@ export { docsTools } from "./mcp-docs-tools.ts"
30
30
  export type { TypeEntry } from "./types-search.ts"
31
31
 
32
32
  // Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
33
- const VERSION = "5.9.0"
33
+ const VERSION = "5.11.0"
34
34
  const SERVER_INFO = { name: "nifra-docs", version: VERSION }
35
35
  // Derive the GET/health tool list from the tools actually served, so the line can never drift from them.
36
36
  const docsHealth = (tools: McpTool[]): string =>