@nifrajs/cli 5.8.0 → 5.10.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 (308) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/dist/agent-files.d.ts +0 -22
  3. package/dist/agent-files.d.ts.map +1 -1
  4. package/dist/agent-files.js +3 -1
  5. package/dist/agent-files.js.map +1 -1
  6. package/dist/assure-hydration.d.ts.map +1 -1
  7. package/dist/assure-hydration.js +2 -10
  8. package/dist/assure-hydration.js.map +1 -1
  9. package/dist/assure.d.ts.map +1 -1
  10. package/dist/assure.js +3 -3
  11. package/dist/assure.js.map +1 -1
  12. package/dist/check-diagnostics.d.ts +1 -0
  13. package/dist/check-diagnostics.d.ts.map +1 -1
  14. package/dist/check-diagnostics.js +4 -0
  15. package/dist/check-diagnostics.js.map +1 -1
  16. package/dist/check-scan.d.ts +3 -0
  17. package/dist/check-scan.d.ts.map +1 -1
  18. package/dist/check-scan.js +62 -87
  19. package/dist/check-scan.js.map +1 -1
  20. package/dist/check.d.ts +3 -0
  21. package/dist/check.d.ts.map +1 -1
  22. package/dist/check.js +27 -25
  23. package/dist/check.js.map +1 -1
  24. package/dist/cli.d.ts +8 -0
  25. package/dist/cli.d.ts.map +1 -1
  26. package/dist/cli.js +53 -20
  27. package/dist/cli.js.map +1 -1
  28. package/dist/command-catalog.d.ts +1 -5
  29. package/dist/command-catalog.d.ts.map +1 -1
  30. package/dist/command-catalog.js +20 -49
  31. package/dist/command-catalog.js.map +1 -1
  32. package/dist/config-target.js +1 -1
  33. package/dist/config-target.js.map +1 -1
  34. package/dist/db-child.js +3 -10
  35. package/dist/db-child.js.map +1 -1
  36. package/dist/db-config.d.ts +2 -0
  37. package/dist/db-config.d.ts.map +1 -1
  38. package/dist/db-config.js +2 -0
  39. package/dist/db-config.js.map +1 -1
  40. package/dist/doctor.d.ts +14 -3
  41. package/dist/doctor.d.ts.map +1 -1
  42. package/dist/doctor.js +91 -6
  43. package/dist/doctor.js.map +1 -1
  44. package/dist/frontend-guidance.d.ts +19 -0
  45. package/dist/frontend-guidance.d.ts.map +1 -1
  46. package/dist/frontend-guidance.js +267 -23
  47. package/dist/frontend-guidance.js.map +1 -1
  48. package/dist/hand-built-manifest.d.ts.map +1 -1
  49. package/dist/hand-built-manifest.js +1 -1
  50. package/dist/hand-built-manifest.js.map +1 -1
  51. package/dist/internal/control-character.d.ts +3 -0
  52. package/dist/internal/control-character.d.ts.map +1 -0
  53. package/dist/internal/control-character.js +10 -0
  54. package/dist/internal/control-character.js.map +1 -0
  55. package/dist/internal/escape-regexp.d.ts +3 -0
  56. package/dist/internal/escape-regexp.d.ts.map +1 -0
  57. package/dist/internal/escape-regexp.js +5 -0
  58. package/dist/internal/escape-regexp.js.map +1 -0
  59. package/dist/internal/line-at.d.ts +3 -0
  60. package/dist/internal/line-at.d.ts.map +1 -0
  61. package/dist/internal/line-at.js +5 -0
  62. package/dist/internal/line-at.js.map +1 -0
  63. package/dist/internal/nifra-project.d.ts.map +1 -1
  64. package/dist/internal/nifra-project.js +35 -41
  65. package/dist/internal/nifra-project.js.map +1 -1
  66. package/dist/internal/posix-path.d.ts +3 -0
  67. package/dist/internal/posix-path.d.ts.map +1 -0
  68. package/dist/internal/posix-path.js +5 -0
  69. package/dist/internal/posix-path.js.map +1 -0
  70. package/dist/internal/project-specifiers.d.ts.map +1 -1
  71. package/dist/internal/project-specifiers.js +3 -10
  72. package/dist/internal/project-specifiers.js.map +1 -1
  73. package/dist/internal/realpath-or-self.d.ts +3 -0
  74. package/dist/internal/realpath-or-self.d.ts.map +1 -0
  75. package/dist/internal/realpath-or-self.js +11 -0
  76. package/dist/internal/realpath-or-self.js.map +1 -0
  77. package/dist/internal/record.d.ts +3 -0
  78. package/dist/internal/record.d.ts.map +1 -0
  79. package/dist/internal/record.js +5 -0
  80. package/dist/internal/record.js.map +1 -0
  81. package/dist/internal/source-facts.d.ts +30 -0
  82. package/dist/internal/source-facts.d.ts.map +1 -1
  83. package/dist/internal/source-facts.js +155 -25
  84. package/dist/internal/source-facts.js.map +1 -1
  85. package/dist/introspect.d.ts +0 -22
  86. package/dist/introspect.d.ts.map +1 -1
  87. package/dist/introspect.js +11 -151
  88. package/dist/introspect.js.map +1 -1
  89. package/dist/levels-tool.d.ts +2 -0
  90. package/dist/levels-tool.d.ts.map +1 -1
  91. package/dist/levels-tool.js +54 -64
  92. package/dist/levels-tool.js.map +1 -1
  93. package/dist/load.d.ts +8 -1
  94. package/dist/load.d.ts.map +1 -1
  95. package/dist/load.js +5 -0
  96. package/dist/load.js.map +1 -1
  97. package/dist/local-cli.d.ts +7 -0
  98. package/dist/local-cli.d.ts.map +1 -1
  99. package/dist/local-cli.js +13 -0
  100. package/dist/local-cli.js.map +1 -1
  101. package/dist/mcp-docs-tools.d.ts +1 -1
  102. package/dist/mcp-docs-tools.d.ts.map +1 -1
  103. package/dist/mcp-docs-tools.js +46 -3
  104. package/dist/mcp-docs-tools.js.map +1 -1
  105. package/dist/mcp-http.d.ts +1 -1
  106. package/dist/mcp-http.js +2 -2
  107. package/dist/mcp-http.js.map +1 -1
  108. package/dist/mcp-io.d.ts +16 -0
  109. package/dist/mcp-io.d.ts.map +1 -1
  110. package/dist/mcp-io.js +63 -0
  111. package/dist/mcp-io.js.map +1 -1
  112. package/dist/mcp-isolate.d.ts.map +1 -1
  113. package/dist/mcp-isolate.js +2 -1
  114. package/dist/mcp-isolate.js.map +1 -1
  115. package/dist/mcp-project-child.d.ts.map +1 -1
  116. package/dist/mcp-project-child.js +5 -12
  117. package/dist/mcp-project-child.js.map +1 -1
  118. package/dist/mcp-render.d.ts.map +1 -1
  119. package/dist/mcp-render.js +9 -51
  120. package/dist/mcp-render.js.map +1 -1
  121. package/dist/mcp-root.js +1 -1
  122. package/dist/mcp-root.js.map +1 -1
  123. package/dist/mcp-run.d.ts.map +1 -1
  124. package/dist/mcp-run.js +3 -46
  125. package/dist/mcp-run.js.map +1 -1
  126. package/dist/mcp-tool-meta.d.ts.map +1 -1
  127. package/dist/mcp-tool-meta.js +0 -1
  128. package/dist/mcp-tool-meta.js.map +1 -1
  129. package/dist/mcp-ws.d.ts.map +1 -1
  130. package/dist/mcp-ws.js +2 -18
  131. package/dist/mcp-ws.js.map +1 -1
  132. package/dist/migrate-layout.d.ts.map +1 -1
  133. package/dist/migrate-layout.js +36 -57
  134. package/dist/migrate-layout.js.map +1 -1
  135. package/dist/output-schemas.d.ts.map +1 -1
  136. package/dist/output-schemas.js +7 -7
  137. package/dist/output-schemas.js.map +1 -1
  138. package/dist/port.d.ts.map +1 -1
  139. package/dist/port.js +1 -2
  140. package/dist/port.js.map +1 -1
  141. package/dist/ppr-read-fix.js +2 -2
  142. package/dist/ppr-read-fix.js.map +1 -1
  143. package/dist/recipes/5.10.0.d.ts +12 -0
  144. package/dist/recipes/5.10.0.d.ts.map +1 -0
  145. package/dist/recipes/5.10.0.js +44 -0
  146. package/dist/recipes/5.10.0.js.map +1 -0
  147. package/dist/recipes/5.9.0.d.ts +10 -0
  148. package/dist/recipes/5.9.0.d.ts.map +1 -0
  149. package/dist/recipes/5.9.0.js +41 -0
  150. package/dist/recipes/5.9.0.js.map +1 -0
  151. package/dist/recipes/index.d.ts +5 -0
  152. package/dist/recipes/index.d.ts.map +1 -1
  153. package/dist/recipes/index.js +4 -0
  154. package/dist/recipes/index.js.map +1 -1
  155. package/dist/review.d.ts.map +1 -1
  156. package/dist/review.js +12 -13
  157. package/dist/review.js.map +1 -1
  158. package/dist/rules/codes.d.ts +3 -0
  159. package/dist/rules/codes.d.ts.map +1 -1
  160. package/dist/rules/codes.js +3 -0
  161. package/dist/rules/codes.js.map +1 -1
  162. package/dist/rules/contract-visibility.d.ts.map +1 -1
  163. package/dist/rules/contract-visibility.js +3 -9
  164. package/dist/rules/contract-visibility.js.map +1 -1
  165. package/dist/rules/data-guard.d.ts.map +1 -1
  166. package/dist/rules/data-guard.js +3 -10
  167. package/dist/rules/data-guard.js.map +1 -1
  168. package/dist/rules/explanations.d.ts.map +1 -1
  169. package/dist/rules/explanations.js +15 -0
  170. package/dist/rules/explanations.js.map +1 -1
  171. package/dist/rules/internal-links.d.ts +5 -0
  172. package/dist/rules/internal-links.d.ts.map +1 -0
  173. package/dist/rules/internal-links.js +418 -0
  174. package/dist/rules/internal-links.js.map +1 -0
  175. package/dist/rules/legacy.d.ts.map +1 -1
  176. package/dist/rules/legacy.js +20 -0
  177. package/dist/rules/legacy.js.map +1 -1
  178. package/dist/rules/pages.d.ts.map +1 -1
  179. package/dist/rules/pages.js +41 -58
  180. package/dist/rules/pages.js.map +1 -1
  181. package/dist/rules/routes.d.ts.map +1 -1
  182. package/dist/rules/routes.js +20 -27
  183. package/dist/rules/routes.js.map +1 -1
  184. package/dist/rules/security.d.ts.map +1 -1
  185. package/dist/rules/security.js +206 -313
  186. package/dist/rules/security.js.map +1 -1
  187. package/dist/rules/server-fn-namespace.d.ts +8 -0
  188. package/dist/rules/server-fn-namespace.d.ts.map +1 -0
  189. package/dist/rules/server-fn-namespace.js +43 -0
  190. package/dist/rules/server-fn-namespace.js.map +1 -0
  191. package/dist/rules/source-scan.d.ts +29 -0
  192. package/dist/rules/source-scan.d.ts.map +1 -0
  193. package/dist/rules/source-scan.js +38 -0
  194. package/dist/rules/source-scan.js.map +1 -0
  195. package/dist/rules/text-slot-boolean.d.ts.map +1 -1
  196. package/dist/rules/text-slot-boolean.js +21 -43
  197. package/dist/rules/text-slot-boolean.js.map +1 -1
  198. package/dist/rules/zones.d.ts.map +1 -1
  199. package/dist/rules/zones.js +3 -10
  200. package/dist/rules/zones.js.map +1 -1
  201. package/dist/runtime-differences.d.ts +62 -0
  202. package/dist/runtime-differences.d.ts.map +1 -0
  203. package/dist/runtime-differences.js +222 -0
  204. package/dist/runtime-differences.js.map +1 -0
  205. package/dist/sdk.d.ts.map +1 -1
  206. package/dist/sdk.js +43 -43
  207. package/dist/sdk.js.map +1 -1
  208. package/dist/smoke.d.ts.map +1 -1
  209. package/dist/smoke.js +4 -12
  210. package/dist/smoke.js.map +1 -1
  211. package/dist/source-rewrites.d.ts +27 -0
  212. package/dist/source-rewrites.d.ts.map +1 -0
  213. package/dist/source-rewrites.js +517 -0
  214. package/dist/source-rewrites.js.map +1 -0
  215. package/dist/stylex-migrate.d.ts.map +1 -1
  216. package/dist/stylex-migrate.js +1 -1
  217. package/dist/stylex-migrate.js.map +1 -1
  218. package/dist/symptom-search.d.ts +5 -0
  219. package/dist/symptom-search.d.ts.map +1 -0
  220. package/dist/symptom-search.js +21 -0
  221. package/dist/symptom-search.js.map +1 -0
  222. package/dist/typecheck-coverage.d.ts +9 -0
  223. package/dist/typecheck-coverage.d.ts.map +1 -1
  224. package/dist/typecheck-coverage.js +16 -0
  225. package/dist/typecheck-coverage.js.map +1 -1
  226. package/dist/upgrade.d.ts +28 -3
  227. package/dist/upgrade.d.ts.map +1 -1
  228. package/dist/upgrade.js +153 -64
  229. package/dist/upgrade.js.map +1 -1
  230. package/dist/verification-plan.d.ts.map +1 -1
  231. package/dist/verification-plan.js +5 -3
  232. package/dist/verification-plan.js.map +1 -1
  233. package/docs/examples.json +51 -9
  234. package/docs/llms-full.txt +1296 -287
  235. package/docs/types.json +854 -170
  236. package/package.json +11 -11
  237. package/src/agent-files.ts +4 -1
  238. package/src/assure-hydration.ts +2 -9
  239. package/src/assure.ts +3 -4
  240. package/src/check-diagnostics.ts +5 -0
  241. package/src/check-scan.ts +74 -83
  242. package/src/check.ts +40 -26
  243. package/src/cli.ts +76 -20
  244. package/src/command-catalog.ts +22 -56
  245. package/src/config-target.ts +1 -1
  246. package/src/db-child.ts +3 -10
  247. package/src/db-config.ts +4 -0
  248. package/src/doctor.ts +128 -12
  249. package/src/frontend-guidance.ts +344 -25
  250. package/src/hand-built-manifest.ts +1 -2
  251. package/src/internal/control-character.ts +8 -0
  252. package/src/internal/escape-regexp.ts +4 -0
  253. package/src/internal/line-at.ts +4 -0
  254. package/src/internal/nifra-project.ts +39 -35
  255. package/src/internal/posix-path.ts +4 -0
  256. package/src/internal/project-specifiers.ts +3 -10
  257. package/src/internal/realpath-or-self.ts +10 -0
  258. package/src/internal/record.ts +4 -0
  259. package/src/internal/source-facts.ts +194 -29
  260. package/src/introspect.ts +16 -156
  261. package/src/levels-tool.ts +71 -78
  262. package/src/load.ts +15 -1
  263. package/src/local-cli.ts +12 -0
  264. package/src/mcp-docs-tools.ts +51 -3
  265. package/src/mcp-http.ts +2 -2
  266. package/src/mcp-io.ts +77 -0
  267. package/src/mcp-isolate.ts +2 -3
  268. package/src/mcp-project-child.ts +5 -14
  269. package/src/mcp-render.ts +11 -59
  270. package/src/mcp-root.ts +1 -1
  271. package/src/mcp-run.ts +5 -54
  272. package/src/mcp-tool-meta.ts +0 -1
  273. package/src/mcp-ws.ts +2 -19
  274. package/src/migrate-layout.ts +52 -72
  275. package/src/output-schemas.ts +7 -8
  276. package/src/port.ts +1 -4
  277. package/src/ppr-read-fix.ts +2 -2
  278. package/src/recipes/5.10.0.ts +45 -0
  279. package/src/recipes/5.9.0.ts +42 -0
  280. package/src/recipes/index.ts +9 -0
  281. package/src/review.ts +15 -15
  282. package/src/rules/codes.ts +3 -0
  283. package/src/rules/contract-visibility.ts +3 -8
  284. package/src/rules/data-guard.ts +3 -10
  285. package/src/rules/explanations.ts +15 -0
  286. package/src/rules/internal-links.ts +490 -0
  287. package/src/rules/legacy.ts +21 -0
  288. package/src/rules/pages.ts +47 -58
  289. package/src/rules/routes.ts +21 -27
  290. package/src/rules/security.ts +224 -255
  291. package/src/rules/server-fn-namespace.ts +47 -0
  292. package/src/rules/source-scan.ts +66 -0
  293. package/src/rules/text-slot-boolean.ts +26 -42
  294. package/src/rules/zones.ts +3 -10
  295. package/src/runtime-differences.ts +302 -0
  296. package/src/sdk.ts +55 -58
  297. package/src/smoke.ts +4 -13
  298. package/src/source-rewrites.ts +592 -0
  299. package/src/stylex-migrate.ts +1 -3
  300. package/src/symptom-search.ts +27 -0
  301. package/src/typecheck-coverage.ts +23 -0
  302. package/src/upgrade.ts +194 -74
  303. package/src/verification-plan.ts +10 -4
  304. package/dist/sync-routes.d.ts +0 -29
  305. package/dist/sync-routes.d.ts.map +0 -1
  306. package/dist/sync-routes.js +0 -56
  307. package/dist/sync-routes.js.map +0 -1
  308. package/src/sync-routes.ts +0 -70
@@ -0,0 +1,66 @@
1
+ import type * as TSApi from "typescript"
2
+ import type { Diagnostic } from "../diagnostics.ts"
3
+ import { createSourceFacts, type SourceFacts } from "../internal/source-facts.ts"
4
+ import { commentBlockExpectation, MISSING_EXPECTATION_REASON } from "./comment-markers.ts"
5
+ import type { RuleContext } from "./index.ts"
6
+ import { loadRuleTypeScript } from "./typescript.ts"
7
+
8
+ /** One place in a file a source rule reports, once the line it sits on is known. */
9
+ export interface SourceFinding {
10
+ /** The offset in the file the finding is reported at. */
11
+ readonly position: number
12
+ /** Where a `nifra-expect` comment is read: the line of this offset, else the finding's own. */
13
+ readonly expectAt?: number
14
+ /** `note` is set when a `nifra-expect` comment names the finding but gives no reason. */
15
+ readonly report: (line: number, note?: string) => Diagnostic
16
+ }
17
+
18
+ export interface SourceScan {
19
+ /** The `nifra-expect` names that accept a finding. */
20
+ readonly expectation: readonly string[]
21
+ /** Whether a comment without a reason after its colon fails to accept a finding. */
22
+ readonly requireReason?: boolean
23
+ /** A cheap test of a file's text; the file is parsed only when it passes. */
24
+ readonly mayMatch: (text: string) => boolean
25
+ readonly find: (facts: SourceFacts, tree: TSApi.SourceFile) => readonly SourceFinding[]
26
+ }
27
+
28
+ /**
29
+ * The shared walk of a lint over TypeScript sources: every `.ts`/`.tsx` file whose text passes `mayMatch`
30
+ * is parsed, `find` names its findings, and one a `// nifra-expect <code>` block above its line
31
+ * accepts is dropped.
32
+ */
33
+ export async function scanSources(
34
+ ctx: RuleContext,
35
+ scan: SourceScan,
36
+ ): Promise<readonly Diagnostic[]> {
37
+ const loaded = await loadRuleTypeScript(ctx)
38
+ if (loaded.diagnostics !== undefined) return loaded.diagnostics
39
+ if (loaded.compiler === undefined) return []
40
+ const facts = createSourceFacts(loaded.compiler)
41
+ const findings: Diagnostic[] = []
42
+ for (const file of ctx.project.source.files) {
43
+ if (!/\.[cm]?tsx?$/.test(file)) continue
44
+ const text = ctx.project.source.read(file)
45
+ if (text === undefined || !scan.mayMatch(text)) continue
46
+ const tree = facts.parse(file, text)
47
+ if (tree === undefined) continue
48
+ const lines = text.split("\n")
49
+ const lineOf = (position: number): number =>
50
+ tree.getLineAndCharacterOfPosition(position).line + 1
51
+ for (const found of scan.find(facts, tree)) {
52
+ const line = lineOf(found.position)
53
+ const expected = commentBlockExpectation(
54
+ lines,
55
+ found.expectAt === undefined ? line : lineOf(found.expectAt),
56
+ scan.expectation,
57
+ )
58
+ if (expected !== undefined && (scan.requireReason !== true || expected.reason !== undefined))
59
+ continue
60
+ findings.push(
61
+ found.report(line, expected === undefined ? undefined : MISSING_EXPECTATION_REASON),
62
+ )
63
+ }
64
+ }
65
+ return findings
66
+ }
@@ -1,10 +1,8 @@
1
- import { type Diagnostic, diagnostic } from "../diagnostics.ts"
2
- import { createSourceFacts } from "../internal/source-facts.ts"
3
- import { commentBlockExpectation } from "./comment-markers.ts"
1
+ import { diagnostic } from "../diagnostics.ts"
4
2
  import type { CheckRule } from "./index.ts"
5
- import { loadRuleTypeScript } from "./typescript.ts"
3
+ import { scanSources } from "./source-scan.ts"
6
4
 
7
- const TEXT_SLOT_BOOLEAN_EXPECTATION = ["NF-C055", "text-slot-boolean"]
5
+ const TEXT_SLOT_BOOLEAN_EXPECTATION = ["NF-C055", "text-slot-boolean"] as const
8
6
  const ZOD_IMPORT = /from\s+["']zod(?:\/v4)?(?:\/mini)?["']/
9
7
  const VALUE_IN = { query: "query", headers: "header", cookies: "cookie" } as const
10
8
 
@@ -16,41 +14,27 @@ const VALUE_IN = { query: "query", headers: "header", cookies: "cookie" } as con
16
14
  export const textSlotBooleanRule: CheckRule = {
17
15
  code: "NF-C055",
18
16
  title: "zod coerce.boolean() reads request text",
19
- async scan(ctx) {
20
- const loaded = await loadRuleTypeScript(ctx)
21
- if (loaded.diagnostics !== undefined) return loaded.diagnostics
22
- const ts = loaded.compiler
23
- if (ts === undefined) return []
24
- const facts = createSourceFacts(ts)
25
- const findings: Diagnostic[] = []
26
- for (const file of ctx.project.source.files) {
27
- if (!/\.[cm]?tsx?$/.test(file)) continue
28
- const text = ctx.project.source.read(file)
29
- if (text === undefined || !text.includes("coerce") || !ZOD_IMPORT.test(text)) continue
30
- const tree = facts.parse(file, text)
31
- if (tree === undefined) continue
32
- const lines = text.split("\n")
33
- for (const found of facts.textSlotBooleanCoercions(tree)) {
34
- const line = tree.getLineAndCharacterOfPosition(found.position).line + 1
35
- if (commentBlockExpectation(lines, line, TEXT_SLOT_BOOLEAN_EXPECTATION) !== undefined)
36
- continue
37
- findings.push(
38
- diagnostic({
39
- code: "NF-C055",
40
- severity: "warn",
41
- file,
42
- line,
43
- message: `\`coerce.boolean()\` in the \`${found.slot}\` schema of ${found.method} ${found.path} reads every non-empty value as true, "false" and "0" included: a ${VALUE_IN[found.slot]} value is always text. Use \`z.stringbool()\`, which reads "false", "0", "no" and "off" as false and refuses text it does not know.`,
44
- evidence: [
45
- "zod's coerce.boolean() is Boolean(value): any non-empty string is true",
46
- `${found.slot} values arrive as text, so "false" never reaches the schema as false`,
47
- "a use kept on purpose: `// nifra-expect NF-C055: <reason>` above the call",
48
- ],
49
- verify: "nifra check",
50
- }),
51
- )
52
- }
53
- }
54
- return findings
55
- },
17
+ scan: (ctx) =>
18
+ scanSources(ctx, {
19
+ expectation: TEXT_SLOT_BOOLEAN_EXPECTATION,
20
+ mayMatch: (text) => text.includes("coerce") && ZOD_IMPORT.test(text),
21
+ find: (facts, tree) =>
22
+ facts.textSlotBooleanCoercions(tree).map((found) => ({
23
+ position: found.position,
24
+ report: (line) =>
25
+ diagnostic({
26
+ code: "NF-C055",
27
+ severity: "warn",
28
+ file: tree.fileName,
29
+ line,
30
+ message: `\`coerce.boolean()\` in the \`${found.slot}\` schema of ${found.method} ${found.path} reads every non-empty value as true, "false" and "0" included: a ${VALUE_IN[found.slot]} value is always text. Use \`z.stringbool()\`, which reads "false", "0", "no" and "off" as false and refuses text it does not know.`,
31
+ evidence: [
32
+ "zod's coerce.boolean() is Boolean(value): any non-empty string is true",
33
+ `${found.slot} values arrive as text, so "false" never reaches the schema as false`,
34
+ "a use kept on purpose: `// nifra-expect NF-C055: <reason>` above the call",
35
+ ],
36
+ verify: "nifra check",
37
+ }),
38
+ })),
39
+ }),
56
40
  }
@@ -7,7 +7,7 @@
7
7
  * file importing one in no zone, backend code importing frontend code, and shared code importing
8
8
  * anything but shared code. NF-C029 owns private environment reads in browser code.
9
9
  */
10
- import { existsSync, readFileSync, realpathSync } from "node:fs"
10
+ import { existsSync, readFileSync } from "node:fs"
11
11
  import { isAbsolute, join, relative } from "node:path"
12
12
  import {
13
13
  browserDenial,
@@ -37,6 +37,7 @@ import {
37
37
  withApiKindHint,
38
38
  } from "../internal/nifra-project.ts"
39
39
  import { createSpecifierResolver } from "../internal/project-specifiers.ts"
40
+ import { realpathOrSelf } from "../internal/realpath-or-self.ts"
40
41
  import { createSourceFacts } from "../internal/source-facts.ts"
41
42
  import type { CheckRule, RuleContext } from "./index.ts"
42
43
  import { loadRuleTypeScript } from "./typescript.ts"
@@ -147,18 +148,10 @@ export function zonedFiles(ctx: RuleContext): {
147
148
  return { files, classifierFor, configErrors }
148
149
  }
149
150
 
150
- const real = (path: string): string => {
151
- try {
152
- return realpathSync(path)
153
- } catch {
154
- return path
155
- }
156
- }
157
-
158
151
  /** Where a resolved import lands, as the project names it. Both sides are real paths: a checkout
159
152
  * reached through a symlink (`/var` -> `/private/var` on macOS) still names files project-relative. */
160
153
  function display(root: string, file: string): string {
161
- const rel = relative(real(root), real(file)).replaceAll("\\", "/")
154
+ const rel = relative(realpathOrSelf(root), realpathOrSelf(file)).replaceAll("\\", "/")
162
155
  return rel.startsWith("../") || isAbsolute(rel) ? file : rel
163
156
  }
164
157
 
@@ -0,0 +1,302 @@
1
+ /**
2
+ * `nifra_runtime` - a symptom-indexed catalog of the places where Bun, Node, Deno and Cloudflare
3
+ * Workers answer the same request, call or flag differently. None of them is Nifra's doing: they are
4
+ * behaviors of the runtimes Nifra runs on. Where Nifra has a switch that decides which one an app
5
+ * gets, the entry names it.
6
+ *
7
+ * The runtime-side companion to `nifra_frontend`: that catalog covers the browser and the frontend
8
+ * frameworks, this one covers the server runtime. One source, two heads - `nifra_runtime` (MCP) and
9
+ * `nifra runtime` (CLI) both call {@link renderRuntimeResult}, so they cannot drift.
10
+ *
11
+ * Every entry records the versions it was measured on. A runtime release can change one; when it
12
+ * does, update the entry and its `versions` rather than adding a second one.
13
+ */
14
+
15
+ import { rankBySymptom, symptomQuery } from "./symptom-search.ts"
16
+
17
+ /** A runtime an entry applies to, or `all` for a difference every runtime shows. */
18
+ export type RuntimeName = "bun" | "node" | "deno" | "workerd" | "all"
19
+
20
+ export interface RuntimeEntry {
21
+ /** Stable slug, e.g. `pipelined-requests`. */
22
+ readonly id: string
23
+ /** Which runtimes show the difference. */
24
+ readonly runtimes: readonly RuntimeName[]
25
+ /** What you observe - the searchable symptom, phrased as the failure, not the cause. */
26
+ readonly symptom: string
27
+ /** What each runtime does. */
28
+ readonly cause: string
29
+ /** What to do, including the Nifra option that decides it when there is one. */
30
+ readonly fix: string
31
+ /** How to confirm it on your own runtime. */
32
+ readonly verify: string
33
+ /** Where to go deeper - a `nifra_docs` query. */
34
+ readonly seeAlso?: string | undefined
35
+ /** The runtime versions the entry was measured on. */
36
+ readonly versions: readonly string[]
37
+ /** Coarse category used by JSON consumers to group related cases. */
38
+ readonly category: "request" | "response" | "language" | "process" | "files" | "edge"
39
+ }
40
+
41
+ export interface RuntimeResult {
42
+ readonly schemaVersion: 1
43
+ readonly runtime?: RuntimeName | undefined
44
+ readonly symptom?: string | undefined
45
+ readonly matched: boolean
46
+ readonly entries: readonly RuntimeEntry[]
47
+ }
48
+
49
+ const MEASURED = ["Bun 1.4.4", "Node 26.12", "Deno 2.9.8"] as const
50
+
51
+ export const RUNTIME_DIFFERENCES: readonly RuntimeEntry[] = [
52
+ {
53
+ id: "dot-segment-targets",
54
+ runtimes: ["bun", "node", "deno", "workerd"],
55
+ symptom:
56
+ "A path guard on `/admin` is skipped, or one request reaches different routes on different runtimes: `GET /public/../admin` or `/users/%2e%2e/9`.",
57
+ cause:
58
+ "Bun and Cloudflare Workers hand the app a URL their parser has already resolved, so `/public/../admin` arrives as `/admin`. Deno's `Request.url` and Node's `IncomingMessage.url` carry the target exactly as the client sent it, dot segments included.",
59
+ fix: "Set `normalizeTarget: true` (`server({ normalizeTarget: true })` on Deno, `serve(app, { normalizeTarget: true })` from `@nifrajs/node`) so Nifra resolves dot segments, backslashes and the characters a URL parser percent-encodes before routing. It is off by default because it costs about 3% of a bare route on Deno. Turn it on when guards or proxies upstream use a different path policy, or when your path guards run after Nifra normalizes the target. Or normalize paths in the proxy in front of the app.",
60
+ verify:
61
+ "Send the raw target with `curl --path-as-is http://host/public/../admin` to each runtime and compare the route that answers.",
62
+ seeAlso: "normalizeTarget request target dot segments",
63
+ versions: MEASURED,
64
+ category: "request",
65
+ },
66
+ {
67
+ id: "host-builds-url",
68
+ runtimes: ["deno", "bun"],
69
+ symptom:
70
+ "`c.req.url` points at a path the client did not ask for, or is a relative string, after a request with an odd `Host` header such as `Host: h.test/admin#`.",
71
+ cause:
72
+ "With `Host: h.test/admin#` and no options set, Deno builds `Request.url` from the Host as received and routes `/admin`, Bun leaves `c.req.url` relative (`/url`), and `@nifrajs/node` answers `400 Bad Request`.",
73
+ fix: "Set `validateHost: true` so Nifra answers `400 invalid_host` for a Host the request target cannot safely be built on. Off by default: reading the Host header measured about 6% of a bare route on Bun.",
74
+ verify:
75
+ "`printf 'GET /url HTTP/1.1\\r\\nhost: h.test/admin#\\r\\n\\r\\n' | nc 127.0.0.1 <port>` against a route that echoes `c.req.url`.",
76
+ seeAlso: "validateHost invalid_host Host header",
77
+ versions: MEASURED,
78
+ category: "request",
79
+ },
80
+ {
81
+ id: "missing-or-repeated-host",
82
+ runtimes: ["bun", "node", "deno"],
83
+ symptom:
84
+ "`new URL(c.req.url)` throws, or the request is answered 400, for an HTTP/1.0 request with no Host or a request that sends Host twice.",
85
+ cause:
86
+ "With no Host (HTTP/1.0), `c.req.url` is relative (`/url`) on Bun, `http://localhost/url` through `@nifrajs/node`, and `http://localhost:<port>/url` on Deno. With `Host: a.test` and `Host: b.test`, Bun builds the URL on the first, while `@nifrajs/node` and Deno answer `400`.",
87
+ fix: "Parse against a base when you must, `new URL(c.req.url, base)`, or enable `validateHost: true` so Nifra refuses the malformed Hosts it can see with a `400`. Do not use the Host header for security decisions.",
88
+ verify:
89
+ "Send `GET /url HTTP/1.0` with no Host, and a request with two Host lines, to a route that echoes `c.req.url` and the `host` header.",
90
+ seeAlso: "validateHost Host header relative url",
91
+ versions: MEASURED,
92
+ category: "request",
93
+ },
94
+ {
95
+ id: "pipelined-requests",
96
+ runtimes: ["node", "bun", "deno"],
97
+ symptom:
98
+ "A client that writes many requests down one connection without waiting makes a Node server run all their handlers at once, using far more memory than on Bun or Deno.",
99
+ cause:
100
+ "Node's `http` server dispatches every pipelined request it has parsed: 30 requests in one write ran 30 handlers concurrently through `@nifrajs/node`. Bun and Deno ran one at a time per connection.",
101
+ fix: "Bound per-connection work yourself on Node: cap buffered response size, use `requestTimeoutMs`, and put a connection or concurrency limit in the proxy in front. Measure with unread pipelined load, not only one slow client.",
102
+ verify:
103
+ "Write 30 `GET` requests in one `socket.write`, never read, and count handlers running at once with an in-flight counter.",
104
+ seeAlso: "requestTimeoutMs slow client capacity",
105
+ versions: MEASURED,
106
+ category: "request",
107
+ },
108
+ {
109
+ id: "json-content-type",
110
+ runtimes: ["bun", "node", "deno"],
111
+ symptom:
112
+ "A test or client that compares the `content-type` of a JSON response exactly passes on one runtime and fails on another.",
113
+ cause:
114
+ "`Response.json(...)` sets `application/json;charset=utf-8` on Bun and `application/json` on Node (undici) and Deno, and Nifra keeps each runtime's own value: the same route answered `application/json;charset=utf-8` on Bun and `application/json` on Node and Deno.",
115
+ fix: "Compare the media type, not the whole header: `contentType.split(';')[0]` or `startsWith('application/json')`. When you must pin one value, set the header yourself on every response.",
116
+ verify:
117
+ "Return `Response.json({ a: 1 })` and print `response.headers.get('content-type')` on each runtime.",
118
+ seeAlso: "response content-type json headers",
119
+ versions: MEASURED,
120
+ category: "response",
121
+ },
122
+ {
123
+ id: "engine-error-messages",
124
+ runtimes: ["bun", "node", "deno"],
125
+ symptom:
126
+ "A test or log filter that matches an error message from `JSON.parse`, `new URL` or a property read on `null` breaks when the app moves runtime.",
127
+ cause:
128
+ "Bun runs JavaScriptCore; Node and Deno run V8. `JSON.parse('{')` reads `JSON Parse error: Expected '}'` on Bun and `Expected property name or '}' in JSON at position 1 (line 1 column 2)` on Node and Deno. `new URL('not a url')` says `Invalid URL` on Bun and Node and `Invalid URL: 'not a url'` on Deno. `null.x` reads `null is not an object (evaluating 'null.x')` on Bun and `Cannot read properties of null (reading 'x')` elsewhere.",
129
+ fix: "Match on the error's class or an app-owned code, never its message. Nifra's own client errors carry stable codes; use those, not text from the runtime.",
130
+ verify: "Run the snippet in each runtime's REPL and print `error.message`.",
131
+ seeAlso: "errors error codes structured",
132
+ versions: MEASURED,
133
+ category: "language",
134
+ },
135
+ {
136
+ id: "deep-recursion",
137
+ runtimes: ["bun", "node", "deno"],
138
+ symptom:
139
+ "A recursive helper works on Bun with 200,000 levels and throws `RangeError: Maximum call stack size exceeded` on Node or Deno at roughly 10,000.",
140
+ cause:
141
+ "JavaScriptCore runs `return f()` as a proper tail call, so a tail-recursive function never grows the stack on Bun. V8 does not, so Node and Deno overflow, in this probe somewhere between 9,000 and 20,000 frames.",
142
+ fix: "Iterate with a loop, or re-enter only after an `await`. Run any stack-depth test on Node (or Deno), not only Bun.",
143
+ verify:
144
+ "`const f = (n) => (n === 0 ? 0 : f(n - 1)); f(20000)` in each runtime; it returns on Bun and throws on Node.",
145
+ seeAlso: "stack depth recursion middleware chain",
146
+ versions: MEASURED,
147
+ category: "language",
148
+ },
149
+ {
150
+ id: "dotenv-autoload",
151
+ runtimes: ["bun", "node", "deno"],
152
+ symptom:
153
+ "An app reads `process.env.X` from a `.env` file in development on Bun, and gets `undefined` on Node or Deno.",
154
+ cause:
155
+ "Bun loads `.env`, `.env.local` and the mode-specific files from the working directory at startup. Node and Deno load nothing unless started with `--env-file=.env`.",
156
+ fix: "Pass `--env-file` on Node and Deno (and `nifra`'s own `--env-file`), or set the variables in the environment. Use `bun --no-env-file` when a Bun process must not inherit a file's values.",
157
+ verify:
158
+ "Put `X=1` in `.env` and print the value with `bun`, `node` and `deno run -A` from the same directory; add `--env-file=.env` to the last two.",
159
+ seeAlso: "environment variables env file deployment",
160
+ versions: MEASURED,
161
+ category: "process",
162
+ },
163
+ {
164
+ id: "spawn-env",
165
+ runtimes: ["bun"],
166
+ symptom:
167
+ "A child process started with `Bun.spawn` does not see an environment variable the parent set after startup.",
168
+ cause:
169
+ "Without an `env` option, `Bun.spawn` passes the environment Bun started with, not later `process.env` assignments. Node's `child_process` uses the live `process.env`.",
170
+ fix: "Pass `env: process.env` (or an explicit object) to every `Bun.spawn` and `Bun.spawnSync` call that depends on a variable you changed.",
171
+ verify:
172
+ "Set `process.env.Y = 'y'`, spawn `sh -c 'echo $Y'` with and without `env: process.env`, and compare.",
173
+ seeAlso: "environment variables child process",
174
+ versions: ["Bun 1.4.4"],
175
+ category: "process",
176
+ },
177
+ {
178
+ id: "glob-symlinks",
179
+ runtimes: ["bun"],
180
+ symptom:
181
+ "`Bun.Glob` finds fewer files than a shell glob: symlinked files and the contents of symlinked directories are missing.",
182
+ cause:
183
+ "`new Bun.Glob(pattern).scanSync({ cwd })` skips symlinks entirely unless `followSymlinks: true` is set. In the probe, a tree with one real file, a symlinked file and a symlinked directory returned only the real file.",
184
+ fix: "Set `followSymlinks` on purpose. Leave it off when the scan is a write or deletion boundary, and say so in a comment.",
185
+ verify:
186
+ "Create a real file, a symlink to it and a symlinked directory, and compare `scanSync` with and without `followSymlinks: true`.",
187
+ seeAlso: "file scanning glob",
188
+ versions: ["Bun 1.4.4"],
189
+ category: "files",
190
+ },
191
+ {
192
+ id: "workerd-node-builtins",
193
+ runtimes: ["workerd"],
194
+ symptom:
195
+ "A Worker that imports `node:async_hooks` (or another Node builtin) fails to start on an older `compatibility_date`, or works on a newer one without `nodejs_compat`.",
196
+ cause:
197
+ "Which `node:` builtins a Cloudflare Worker gets without the `nodejs_compat` flag depends on its `compatibility_date`. With the 2026-08-18 date, `import 'node:async_hooks'` works. With 2024-06-01, the Worker fails to start on that import, and `process` is undefined.",
198
+ fix: "Do not `import` a Node builtin in code that also runs on Workers. Look it up lazily behind a guard, `typeof process !== 'undefined' ? process.getBuiltinModule('node:async_hooks') : undefined`, and handle `undefined`: `process` does not exist on an old date without Node compatibility. Set the compatibility date and flags in `wrangler.toml` deliberately.",
199
+ verify:
200
+ "Run the Worker under `wrangler dev` with each `compatibility_date` and check that it starts and the lookup returns a module or `undefined`.",
201
+ seeAlso: "cloudflare workers edge nodejs_compat compatibility date",
202
+ versions: ["wrangler dev (measured 2026-10-10)"],
203
+ category: "edge",
204
+ },
205
+ ]
206
+
207
+ const RUNTIME_ALIASES: Record<string, RuntimeName> = {
208
+ all: "all",
209
+ bun: "bun",
210
+ node: "node",
211
+ nodejs: "node",
212
+ deno: "deno",
213
+ workerd: "workerd",
214
+ workers: "workerd",
215
+ cloudflare: "workerd",
216
+ }
217
+
218
+ /** Normalize a free-text runtime argument to a known runtime, or `undefined` if it is not one. */
219
+ export function parseRuntime(value: string | undefined): RuntimeName | undefined {
220
+ if (value === undefined) return undefined
221
+ return RUNTIME_ALIASES[value.trim().toLowerCase()]
222
+ }
223
+
224
+ const appliesTo = (entry: RuntimeEntry, runtime: RuntimeName): boolean =>
225
+ runtime === "all" || entry.runtimes.includes("all") || entry.runtimes.includes(runtime)
226
+
227
+ function scopedEntries(runtime: RuntimeName | undefined): readonly RuntimeEntry[] {
228
+ return runtime === undefined
229
+ ? RUNTIME_DIFFERENCES
230
+ : RUNTIME_DIFFERENCES.filter((entry) => appliesTo(entry, runtime))
231
+ }
232
+
233
+ function score(entry: RuntimeEntry, words: readonly string[]): number {
234
+ const hay =
235
+ `${entry.id} ${entry.symptom} ${entry.cause} ${entry.fix} ${entry.seeAlso ?? ""} ${entry.category} ${entry.versions.join(" ")}`.toLowerCase()
236
+ let hits = 0
237
+ for (const w of words) if (hay.includes(w)) hits++
238
+ return hits
239
+ }
240
+
241
+ /** Select the entries rendered by the CLI and MCP heads; also the stable JSON shape for agents. */
242
+ export function selectRuntimeDifferences(args: {
243
+ runtime?: string | undefined
244
+ symptom?: string | undefined
245
+ limit?: number | undefined
246
+ }): RuntimeResult {
247
+ const runtime = parseRuntime(args.runtime)
248
+ const scoped = scopedEntries(runtime)
249
+ const query = symptomQuery(args.symptom)
250
+ if (query === undefined) {
251
+ return { schemaVersion: 1, runtime, matched: true, entries: scoped }
252
+ }
253
+ const entries = rankBySymptom(scoped, query, args.limit, score)
254
+ return { schemaVersion: 1, runtime, symptom: query, matched: entries.length > 0, entries }
255
+ }
256
+
257
+ function renderEntry(entry: RuntimeEntry): string {
258
+ const scope = entry.runtimes.includes("all") ? "all runtimes" : entry.runtimes.join(", ")
259
+ const parts = [
260
+ `[${entry.id}] (${scope})`,
261
+ `Symptom: ${entry.symptom}`,
262
+ `Cause: ${entry.cause}`,
263
+ `Fix: ${entry.fix}`,
264
+ `Verify: ${entry.verify}`,
265
+ `Measured: ${entry.versions.join(", ")}`,
266
+ `Category: ${entry.category}`,
267
+ ]
268
+ if (entry.seeAlso !== undefined) parts.push(`See: ${entry.seeAlso}`)
269
+ return parts.join("\n")
270
+ }
271
+
272
+ function renderIndex(entries: readonly RuntimeEntry[], runtime: RuntimeName | undefined): string {
273
+ const scope = runtime === undefined ? "all runtimes" : `runtime: ${runtime}`
274
+ const lines = entries.map((e) => {
275
+ const s = e.runtimes.includes("all") ? "all" : e.runtimes.join("/")
276
+ return `- ${e.id} (${s}) - ${e.symptom}`
277
+ })
278
+ return [
279
+ `nifra runtime differences (${entries.length} of ${RUNTIME_DIFFERENCES.length}, ${scope}). Pass a symptom to get the cause + fix + how to verify; pass a runtime to filter.`,
280
+ "",
281
+ ...lines,
282
+ ].join("\n")
283
+ }
284
+
285
+ /**
286
+ * Render the catalog. Filters by `runtime` (when it names a known one), then by a `symptom` keyword
287
+ * query. With no query it returns the (filtered) index; with a query it returns the best-matching
288
+ * entries in full, or the index plus a "no match" note when nothing scores. Pure, so both heads agree.
289
+ */
290
+ export function renderRuntimeResult(args: {
291
+ runtime?: string | undefined
292
+ symptom?: string | undefined
293
+ limit?: number | undefined
294
+ }): string {
295
+ const selected = selectRuntimeDifferences(args)
296
+ const scoped = scopedEntries(selected.runtime)
297
+ if (selected.symptom === undefined) return renderIndex(scoped, selected.runtime)
298
+ if (!selected.matched) {
299
+ return `No runtime-difference entry matched "${selected.symptom}"${selected.runtime ? ` for ${selected.runtime}` : ""}.\n\n${renderIndex(scoped, selected.runtime)}`
300
+ }
301
+ return selected.entries.map(renderEntry).join("\n\n")
302
+ }