@nifrajs/cli 5.8.0 → 5.9.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 (248) hide show
  1. package/CHANGELOG.md +134 -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-scan.d.ts +2 -0
  13. package/dist/check-scan.d.ts.map +1 -1
  14. package/dist/check-scan.js +54 -86
  15. package/dist/check-scan.js.map +1 -1
  16. package/dist/check.d.ts +3 -0
  17. package/dist/check.d.ts.map +1 -1
  18. package/dist/check.js +20 -23
  19. package/dist/check.js.map +1 -1
  20. package/dist/cli.d.ts +8 -0
  21. package/dist/cli.d.ts.map +1 -1
  22. package/dist/cli.js +42 -13
  23. package/dist/cli.js.map +1 -1
  24. package/dist/command-catalog.d.ts.map +1 -1
  25. package/dist/command-catalog.js +20 -30
  26. package/dist/command-catalog.js.map +1 -1
  27. package/dist/config-target.js +1 -1
  28. package/dist/config-target.js.map +1 -1
  29. package/dist/db-child.js +3 -10
  30. package/dist/db-child.js.map +1 -1
  31. package/dist/db-config.d.ts +2 -0
  32. package/dist/db-config.d.ts.map +1 -1
  33. package/dist/db-config.js +2 -0
  34. package/dist/db-config.js.map +1 -1
  35. package/dist/doctor.d.ts +14 -3
  36. package/dist/doctor.d.ts.map +1 -1
  37. package/dist/doctor.js +91 -6
  38. package/dist/doctor.js.map +1 -1
  39. package/dist/frontend-guidance.d.ts +19 -0
  40. package/dist/frontend-guidance.d.ts.map +1 -1
  41. package/dist/frontend-guidance.js +267 -23
  42. package/dist/frontend-guidance.js.map +1 -1
  43. package/dist/hand-built-manifest.d.ts.map +1 -1
  44. package/dist/hand-built-manifest.js +1 -1
  45. package/dist/hand-built-manifest.js.map +1 -1
  46. package/dist/internal/control-character.d.ts +3 -0
  47. package/dist/internal/control-character.d.ts.map +1 -0
  48. package/dist/internal/control-character.js +10 -0
  49. package/dist/internal/control-character.js.map +1 -0
  50. package/dist/internal/escape-regexp.d.ts +3 -0
  51. package/dist/internal/escape-regexp.d.ts.map +1 -0
  52. package/dist/internal/escape-regexp.js +5 -0
  53. package/dist/internal/escape-regexp.js.map +1 -0
  54. package/dist/internal/line-at.d.ts +3 -0
  55. package/dist/internal/line-at.d.ts.map +1 -0
  56. package/dist/internal/line-at.js +5 -0
  57. package/dist/internal/line-at.js.map +1 -0
  58. package/dist/internal/nifra-project.d.ts.map +1 -1
  59. package/dist/internal/nifra-project.js +35 -41
  60. package/dist/internal/nifra-project.js.map +1 -1
  61. package/dist/internal/posix-path.d.ts +3 -0
  62. package/dist/internal/posix-path.d.ts.map +1 -0
  63. package/dist/internal/posix-path.js +5 -0
  64. package/dist/internal/posix-path.js.map +1 -0
  65. package/dist/internal/project-specifiers.d.ts.map +1 -1
  66. package/dist/internal/project-specifiers.js +3 -10
  67. package/dist/internal/project-specifiers.js.map +1 -1
  68. package/dist/internal/realpath-or-self.d.ts +3 -0
  69. package/dist/internal/realpath-or-self.d.ts.map +1 -0
  70. package/dist/internal/realpath-or-self.js +11 -0
  71. package/dist/internal/realpath-or-self.js.map +1 -0
  72. package/dist/internal/record.d.ts +3 -0
  73. package/dist/internal/record.d.ts.map +1 -0
  74. package/dist/internal/record.js +5 -0
  75. package/dist/internal/record.js.map +1 -0
  76. package/dist/internal/source-facts.d.ts.map +1 -1
  77. package/dist/internal/source-facts.js +28 -25
  78. package/dist/internal/source-facts.js.map +1 -1
  79. package/dist/introspect.d.ts +0 -22
  80. package/dist/introspect.d.ts.map +1 -1
  81. package/dist/introspect.js +11 -151
  82. package/dist/introspect.js.map +1 -1
  83. package/dist/levels-tool.d.ts +2 -0
  84. package/dist/levels-tool.d.ts.map +1 -1
  85. package/dist/levels-tool.js +54 -64
  86. package/dist/levels-tool.js.map +1 -1
  87. package/dist/load.d.ts +6 -1
  88. package/dist/load.d.ts.map +1 -1
  89. package/dist/load.js.map +1 -1
  90. package/dist/local-cli.d.ts +7 -0
  91. package/dist/local-cli.d.ts.map +1 -1
  92. package/dist/local-cli.js +13 -0
  93. package/dist/local-cli.js.map +1 -1
  94. package/dist/mcp-docs-tools.d.ts +1 -1
  95. package/dist/mcp-docs-tools.d.ts.map +1 -1
  96. package/dist/mcp-docs-tools.js +46 -3
  97. package/dist/mcp-docs-tools.js.map +1 -1
  98. package/dist/mcp-http.d.ts +1 -1
  99. package/dist/mcp-http.js +2 -2
  100. package/dist/mcp-io.d.ts +16 -0
  101. package/dist/mcp-io.d.ts.map +1 -1
  102. package/dist/mcp-io.js +63 -0
  103. package/dist/mcp-io.js.map +1 -1
  104. package/dist/mcp-isolate.d.ts.map +1 -1
  105. package/dist/mcp-isolate.js +2 -1
  106. package/dist/mcp-isolate.js.map +1 -1
  107. package/dist/mcp-project-child.d.ts.map +1 -1
  108. package/dist/mcp-project-child.js +5 -12
  109. package/dist/mcp-project-child.js.map +1 -1
  110. package/dist/mcp-render.d.ts.map +1 -1
  111. package/dist/mcp-render.js +9 -51
  112. package/dist/mcp-render.js.map +1 -1
  113. package/dist/mcp-root.js +1 -1
  114. package/dist/mcp-root.js.map +1 -1
  115. package/dist/mcp-run.d.ts.map +1 -1
  116. package/dist/mcp-run.js +3 -46
  117. package/dist/mcp-run.js.map +1 -1
  118. package/dist/mcp-ws.d.ts.map +1 -1
  119. package/dist/mcp-ws.js +2 -18
  120. package/dist/mcp-ws.js.map +1 -1
  121. package/dist/migrate-layout.d.ts.map +1 -1
  122. package/dist/migrate-layout.js +36 -57
  123. package/dist/migrate-layout.js.map +1 -1
  124. package/dist/output-schemas.d.ts.map +1 -1
  125. package/dist/output-schemas.js +7 -7
  126. package/dist/output-schemas.js.map +1 -1
  127. package/dist/port.d.ts.map +1 -1
  128. package/dist/port.js +1 -2
  129. package/dist/port.js.map +1 -1
  130. package/dist/ppr-read-fix.js +2 -2
  131. package/dist/ppr-read-fix.js.map +1 -1
  132. package/dist/recipes/5.9.0.d.ts +10 -0
  133. package/dist/recipes/5.9.0.d.ts.map +1 -0
  134. package/dist/recipes/5.9.0.js +41 -0
  135. package/dist/recipes/5.9.0.js.map +1 -0
  136. package/dist/recipes/index.d.ts +5 -0
  137. package/dist/recipes/index.d.ts.map +1 -1
  138. package/dist/recipes/index.js +2 -0
  139. package/dist/recipes/index.js.map +1 -1
  140. package/dist/review.d.ts.map +1 -1
  141. package/dist/review.js +9 -13
  142. package/dist/review.js.map +1 -1
  143. package/dist/rules/contract-visibility.d.ts.map +1 -1
  144. package/dist/rules/contract-visibility.js +3 -9
  145. package/dist/rules/contract-visibility.js.map +1 -1
  146. package/dist/rules/data-guard.d.ts.map +1 -1
  147. package/dist/rules/data-guard.js +3 -10
  148. package/dist/rules/data-guard.js.map +1 -1
  149. package/dist/rules/pages.d.ts.map +1 -1
  150. package/dist/rules/pages.js +41 -58
  151. package/dist/rules/pages.js.map +1 -1
  152. package/dist/rules/routes.d.ts.map +1 -1
  153. package/dist/rules/routes.js +20 -27
  154. package/dist/rules/routes.js.map +1 -1
  155. package/dist/rules/security.d.ts.map +1 -1
  156. package/dist/rules/security.js +206 -313
  157. package/dist/rules/security.js.map +1 -1
  158. package/dist/rules/zones.d.ts.map +1 -1
  159. package/dist/rules/zones.js +3 -10
  160. package/dist/rules/zones.js.map +1 -1
  161. package/dist/runtime-differences.d.ts +62 -0
  162. package/dist/runtime-differences.d.ts.map +1 -0
  163. package/dist/runtime-differences.js +222 -0
  164. package/dist/runtime-differences.js.map +1 -0
  165. package/dist/sdk.d.ts.map +1 -1
  166. package/dist/sdk.js +43 -43
  167. package/dist/sdk.js.map +1 -1
  168. package/dist/smoke.d.ts.map +1 -1
  169. package/dist/smoke.js +4 -12
  170. package/dist/smoke.js.map +1 -1
  171. package/dist/source-rewrites.d.ts +27 -0
  172. package/dist/source-rewrites.d.ts.map +1 -0
  173. package/dist/source-rewrites.js +402 -0
  174. package/dist/source-rewrites.js.map +1 -0
  175. package/dist/stylex-migrate.d.ts.map +1 -1
  176. package/dist/stylex-migrate.js +1 -1
  177. package/dist/stylex-migrate.js.map +1 -1
  178. package/dist/symptom-search.d.ts +5 -0
  179. package/dist/symptom-search.d.ts.map +1 -0
  180. package/dist/symptom-search.js +21 -0
  181. package/dist/symptom-search.js.map +1 -0
  182. package/dist/upgrade.d.ts +28 -3
  183. package/dist/upgrade.d.ts.map +1 -1
  184. package/dist/upgrade.js +153 -64
  185. package/dist/upgrade.js.map +1 -1
  186. package/dist/verification-plan.d.ts.map +1 -1
  187. package/dist/verification-plan.js +5 -3
  188. package/dist/verification-plan.js.map +1 -1
  189. package/docs/examples.json +32 -2
  190. package/docs/llms-full.txt +749 -95
  191. package/docs/types.json +300 -61
  192. package/package.json +11 -11
  193. package/src/agent-files.ts +4 -1
  194. package/src/assure-hydration.ts +2 -9
  195. package/src/assure.ts +3 -4
  196. package/src/check-scan.ts +65 -82
  197. package/src/check.ts +25 -23
  198. package/src/cli.ts +61 -13
  199. package/src/command-catalog.ts +22 -32
  200. package/src/config-target.ts +1 -1
  201. package/src/db-child.ts +3 -10
  202. package/src/db-config.ts +4 -0
  203. package/src/doctor.ts +128 -12
  204. package/src/frontend-guidance.ts +344 -25
  205. package/src/hand-built-manifest.ts +1 -2
  206. package/src/internal/control-character.ts +8 -0
  207. package/src/internal/escape-regexp.ts +4 -0
  208. package/src/internal/line-at.ts +4 -0
  209. package/src/internal/nifra-project.ts +39 -35
  210. package/src/internal/posix-path.ts +4 -0
  211. package/src/internal/project-specifiers.ts +3 -10
  212. package/src/internal/realpath-or-self.ts +10 -0
  213. package/src/internal/record.ts +4 -0
  214. package/src/internal/source-facts.ts +39 -29
  215. package/src/introspect.ts +16 -156
  216. package/src/levels-tool.ts +71 -78
  217. package/src/load.ts +6 -1
  218. package/src/local-cli.ts +12 -0
  219. package/src/mcp-docs-tools.ts +51 -3
  220. package/src/mcp-http.ts +2 -2
  221. package/src/mcp-io.ts +77 -0
  222. package/src/mcp-isolate.ts +2 -3
  223. package/src/mcp-project-child.ts +5 -14
  224. package/src/mcp-render.ts +11 -59
  225. package/src/mcp-root.ts +1 -1
  226. package/src/mcp-run.ts +5 -54
  227. package/src/mcp-ws.ts +2 -19
  228. package/src/migrate-layout.ts +52 -72
  229. package/src/output-schemas.ts +7 -8
  230. package/src/port.ts +1 -4
  231. package/src/ppr-read-fix.ts +2 -2
  232. package/src/recipes/5.9.0.ts +42 -0
  233. package/src/recipes/index.ts +7 -0
  234. package/src/review.ts +12 -15
  235. package/src/rules/contract-visibility.ts +3 -8
  236. package/src/rules/data-guard.ts +3 -10
  237. package/src/rules/pages.ts +47 -58
  238. package/src/rules/routes.ts +21 -27
  239. package/src/rules/security.ts +224 -255
  240. package/src/rules/zones.ts +3 -10
  241. package/src/runtime-differences.ts +302 -0
  242. package/src/sdk.ts +55 -58
  243. package/src/smoke.ts +4 -13
  244. package/src/source-rewrites.ts +463 -0
  245. package/src/stylex-migrate.ts +1 -3
  246. package/src/symptom-search.ts +27 -0
  247. package/src/upgrade.ts +194 -74
  248. package/src/verification-plan.ts +10 -4
@@ -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
+ }
package/src/sdk.ts CHANGED
@@ -102,7 +102,7 @@ function identifier(value: string, fallback: string): string {
102
102
  const normalized = value
103
103
  .replace(/[^A-Za-z0-9_]+/g, "_")
104
104
  .replace(/_+/g, "_")
105
- .replace(/^_+|_+$/g, "")
105
+ .replace(/^_+|(?<!_)_+$/g, "")
106
106
  const safe = /^\d/.test(normalized) ? `_${normalized}` : normalized
107
107
  return safe === "" || safe === "_" ? fallback : safe
108
108
  }
@@ -199,6 +199,13 @@ function schemaProperties(schema: JsonSchema): Readonly<Record<string, JsonSchem
199
199
  return properties as Readonly<Record<string, JsonSchema>> | undefined
200
200
  }
201
201
 
202
+ /** A map's value schema, `true` for any value: an object with open `additionalProperties` and no `properties`. */
203
+ function schemaMapValues(schema: JsonSchema): JsonSchema | true | undefined {
204
+ if (schemaProperties(schema) !== undefined) return undefined
205
+ const extra = recordOf(schema)?.additionalProperties
206
+ return extra === undefined || extra === false ? undefined : (extra as JsonSchema | true)
207
+ }
208
+
202
209
  function schemaRequired(schema: JsonSchema): ReadonlySet<string> {
203
210
  const required = recordOf(schema)?.required
204
211
  return new Set(
@@ -328,16 +335,12 @@ function pythonType(
328
335
  const properties = schemaProperties(schema)
329
336
  const type = schemaType(schema)
330
337
  if (type === "object" || properties !== undefined) {
331
- if (
332
- properties === undefined &&
333
- recordOf(schema)?.additionalProperties !== undefined &&
334
- recordOf(schema)?.additionalProperties !== false
335
- ) {
336
- const extra = recordOf(schema)?.additionalProperties
338
+ const extra = schemaMapValues(schema)
339
+ if (extra !== undefined) {
337
340
  const extraType =
338
341
  typeof extra === "boolean"
339
342
  ? "Any"
340
- : pythonType(extra as JsonSchema, `${hint}Value`, catalog, tracker, operation, location)
343
+ : pythonType(extra, `${hint}Value`, catalog, tracker, operation, location)
341
344
  return `dict[str, ${extraType}]`
342
345
  }
343
346
  return catalog.model(schema, hint)
@@ -421,32 +424,36 @@ function pythonModelFields(
421
424
  return fields.length === 0 ? " pass" : fields.join("\n")
422
425
  }
423
426
 
424
- function renderPythonModels(catalog: SchemaCatalog, tracker: OpaqueTracker): string {
427
+ /** Every catalog model rendered, those added while rendering included, joined by a blank line. */
428
+ function renderModels(
429
+ catalog: SchemaCatalog,
430
+ render: (name: string, schema: JsonSchema) => string,
431
+ ): string {
425
432
  const rendered: string[] = []
426
433
  let index = 0
427
434
  while (index < catalog.models.size) {
428
435
  const entries = [...catalog.models.entries()]
429
436
  const [name, schema] = entries[index++]!
430
- if (isObjectModel(schema)) {
431
- rendered.push(
432
- "@dataclass(frozen=True)\nclass " +
433
- name +
434
- ":\n" +
435
- pythonModelFields(schema, name, catalog, tracker),
436
- )
437
- } else {
438
- // A `type` statement evaluates lazily, so an alias may name a model declared below it.
439
- rendered.push(
440
- "type " +
441
- name +
442
- " = " +
443
- pythonType(schema, name, catalog, tracker, "schema", `model ${name}`),
444
- )
445
- }
437
+ rendered.push(render(name, schema))
446
438
  }
447
439
  return rendered.join("\n\n")
448
440
  }
449
441
 
442
+ function renderPythonModels(catalog: SchemaCatalog, tracker: OpaqueTracker): string {
443
+ return renderModels(catalog, (name, schema) =>
444
+ isObjectModel(schema)
445
+ ? "@dataclass(frozen=True)\nclass " +
446
+ name +
447
+ ":\n" +
448
+ pythonModelFields(schema, name, catalog, tracker)
449
+ : // A `type` statement evaluates lazily, so an alias may name a model declared below it.
450
+ "type " +
451
+ name +
452
+ " = " +
453
+ pythonType(schema, name, catalog, tracker, "schema", `model ${name}`),
454
+ )
455
+ }
456
+
450
457
  function pythonErrorAliases(
451
458
  entries: readonly OperationEntry[],
452
459
  names: readonly string[],
@@ -483,13 +490,21 @@ function pythonErrorAliases(
483
490
  return aliases.join("\n")
484
491
  }
485
492
 
486
- function pythonSdk(document: OpenAPIDocument, options: SdkRenderOptions): string {
493
+ /** What each SDK renderer starts from: the operations, a unique name for each, and the schema catalog and tracker. */
494
+ function sdkPlan(document: OpenAPIDocument) {
487
495
  const entries = operations(document)
488
- const names = uniqueNames(
489
- entries.map(({ method, path, operation }) => operationName(operation, method, path)),
490
- )
491
- const catalog = new SchemaCatalog(document.components?.schemas)
492
- const tracker = new OpaqueTracker()
496
+ return {
497
+ entries,
498
+ names: uniqueNames(
499
+ entries.map(({ method, path, operation }) => operationName(operation, method, path)),
500
+ ),
501
+ catalog: new SchemaCatalog(document.components?.schemas),
502
+ tracker: new OpaqueTracker(),
503
+ }
504
+ }
505
+
506
+ function pythonSdk(document: OpenAPIDocument, options: SdkRenderOptions): string {
507
+ const { entries, names, catalog, tracker } = sdkPlan(document)
493
508
  const methods: string[] = []
494
509
 
495
510
  entries.forEach((entry, index) => {
@@ -761,16 +776,12 @@ function goType(
761
776
  const properties = schemaProperties(schema)
762
777
  const type = schemaType(schema)
763
778
  if (type === "object" || properties !== undefined) {
764
- if (
765
- properties === undefined &&
766
- recordOf(schema)?.additionalProperties !== undefined &&
767
- recordOf(schema)?.additionalProperties !== false
768
- ) {
769
- const extra = recordOf(schema)?.additionalProperties
779
+ const extra = schemaMapValues(schema)
780
+ if (extra !== undefined) {
770
781
  const extraType =
771
782
  typeof extra === "boolean"
772
783
  ? "any"
773
- : goType(extra as JsonSchema, `${hint}Value`, catalog, tracker, operation, location)
784
+ : goType(extra, `${hint}Value`, catalog, tracker, operation, location)
774
785
  return `map[string]${extraType}`
775
786
  }
776
787
  return catalog.model(schema, hint)
@@ -891,21 +902,12 @@ function goModelFields(
891
902
  }
892
903
 
893
904
  function renderGoModels(catalog: SchemaCatalog, tracker: OpaqueTracker): string {
894
- const rendered: string[] = []
895
- let index = 0
896
- while (index < catalog.models.size) {
897
- const entries = [...catalog.models.entries()]
898
- const [name, schema] = entries[index++]!
905
+ return renderModels(catalog, (name, schema) => {
899
906
  const fields = goModelFields(schema, name, catalog, tracker)
900
- if (isObjectModel(schema)) {
901
- rendered.push(`type ${name} struct {\n${fields}\n}`)
902
- } else {
903
- rendered.push(
904
- `type ${name} = ${goType(schema, name, catalog, tracker, "schema", `model ${name}`)}`,
905
- )
906
- }
907
- }
908
- return rendered.join("\n\n")
907
+ return isObjectModel(schema)
908
+ ? `type ${name} struct {\n${fields}\n}`
909
+ : `type ${name} = ${goType(schema, name, catalog, tracker, "schema", `model ${name}`)}`
910
+ })
909
911
  }
910
912
 
911
913
  interface GoErrorInfo {
@@ -1058,12 +1060,7 @@ function goQueryDefinition(
1058
1060
  }
1059
1061
 
1060
1062
  function goSdk(document: OpenAPIDocument, options: SdkRenderOptions): string {
1061
- const entries = operations(document)
1062
- const names = uniqueNames(
1063
- entries.map(({ method, path, operation }) => operationName(operation, method, path)),
1064
- )
1065
- const catalog = new SchemaCatalog(document.components?.schemas)
1066
- const tracker = new OpaqueTracker()
1063
+ const { entries, names, catalog, tracker } = sdkPlan(document)
1067
1064
  const methods: string[] = []
1068
1065
  const queries: string[] = []
1069
1066
  const errors: string[] = []
package/src/smoke.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { realpath, stat } from "node:fs/promises"
2
2
  import { isAbsolute, relative, resolve } from "node:path"
3
3
  import { pathToFileURL } from "node:url"
4
+ import { hasControlCharacter } from "./internal/control-character.ts"
5
+ import { isRecord } from "./internal/record.ts"
4
6
 
5
7
  export interface SmokeApp {
6
8
  fetch(request: Request): Response | Promise<Response>
@@ -126,18 +128,6 @@ const MAX_SMOKE_HEADER_VALUE_LENGTH = 8_192
126
128
  const HTTP_TOKEN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/
127
129
  const SCHEME_PREFIX = /^[A-Za-z][A-Za-z0-9+.-]*:/
128
130
 
129
- function hasControlCharacter(value: string, includeBackslash = false): boolean {
130
- for (let index = 0; index < value.length; index++) {
131
- const code = value.charCodeAt(index)
132
- if (code <= 0x1f || code === 0x7f || (includeBackslash && code === 0x5c)) return true
133
- }
134
- return false
135
- }
136
-
137
- function isRecord(value: unknown): value is Record<string, unknown> {
138
- return typeof value === "object" && value !== null && !Array.isArray(value)
139
- }
140
-
141
131
  function validStatus(value: unknown): value is number {
142
132
  return typeof value === "number" && Number.isInteger(value) && value >= 100 && value <= 599
143
133
  }
@@ -150,7 +140,8 @@ function validRelativePath(value: unknown): value is string {
150
140
  value.startsWith("/") &&
151
141
  !value.startsWith("//") &&
152
142
  !SCHEME_PREFIX.test(value) &&
153
- !hasControlCharacter(value, true)
143
+ !hasControlCharacter(value) &&
144
+ !value.includes("\\")
154
145
  )
155
146
  }
156
147