@nifrajs/cli 5.5.1 → 5.7.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 (205) hide show
  1. package/CHANGELOG.md +314 -0
  2. package/dist/cdn-check.d.ts +7 -6
  3. package/dist/cdn-check.d.ts.map +1 -1
  4. package/dist/cdn-check.js +13 -1
  5. package/dist/cdn-check.js.map +1 -1
  6. package/dist/check-diagnostics.d.ts.map +1 -1
  7. package/dist/check-diagnostics.js +9 -3
  8. package/dist/check-diagnostics.js.map +1 -1
  9. package/dist/check-scan.d.ts +6 -0
  10. package/dist/check-scan.d.ts.map +1 -1
  11. package/dist/check-scan.js +30 -32
  12. package/dist/check-scan.js.map +1 -1
  13. package/dist/check.d.ts.map +1 -1
  14. package/dist/check.js +35 -12
  15. package/dist/check.js.map +1 -1
  16. package/dist/cli.d.ts +4 -0
  17. package/dist/cli.d.ts.map +1 -1
  18. package/dist/cli.js +66 -9
  19. package/dist/cli.js.map +1 -1
  20. package/dist/command-catalog.d.ts +19 -1
  21. package/dist/command-catalog.d.ts.map +1 -1
  22. package/dist/command-catalog.js +111 -6
  23. package/dist/command-catalog.js.map +1 -1
  24. package/dist/contracts.d.ts +42 -4
  25. package/dist/contracts.d.ts.map +1 -1
  26. package/dist/contracts.js +288 -9
  27. package/dist/contracts.js.map +1 -1
  28. package/dist/doctor.d.ts +12 -2
  29. package/dist/doctor.d.ts.map +1 -1
  30. package/dist/doctor.js +67 -1
  31. package/dist/doctor.js.map +1 -1
  32. package/dist/fix-recipes.d.ts.map +1 -1
  33. package/dist/fix-recipes.js +27 -0
  34. package/dist/fix-recipes.js.map +1 -1
  35. package/dist/frontend-guidance.d.ts +1 -1
  36. package/dist/frontend-guidance.d.ts.map +1 -1
  37. package/dist/frontend-guidance.js +17 -8
  38. package/dist/frontend-guidance.js.map +1 -1
  39. package/dist/internal/git-ignored.d.ts +12 -0
  40. package/dist/internal/git-ignored.d.ts.map +1 -0
  41. package/dist/internal/git-ignored.js +49 -0
  42. package/dist/internal/git-ignored.js.map +1 -0
  43. package/dist/internal/source-facts.d.ts +29 -0
  44. package/dist/internal/source-facts.d.ts.map +1 -1
  45. package/dist/internal/source-facts.js +160 -0
  46. package/dist/internal/source-facts.js.map +1 -1
  47. package/dist/introspect.js +1 -1
  48. package/dist/introspect.js.map +1 -1
  49. package/dist/load.d.ts +7 -1
  50. package/dist/load.d.ts.map +1 -1
  51. package/dist/load.js +18 -0
  52. package/dist/load.js.map +1 -1
  53. package/dist/local-cli.d.ts +15 -0
  54. package/dist/local-cli.d.ts.map +1 -0
  55. package/dist/local-cli.js +74 -0
  56. package/dist/local-cli.js.map +1 -0
  57. package/dist/lock-links.d.ts +0 -7
  58. package/dist/lock-links.d.ts.map +1 -1
  59. package/dist/lock-links.js +5 -44
  60. package/dist/lock-links.js.map +1 -1
  61. package/dist/mcp-delegate.d.ts +13 -5
  62. package/dist/mcp-delegate.d.ts.map +1 -1
  63. package/dist/mcp-delegate.js +24 -8
  64. package/dist/mcp-delegate.js.map +1 -1
  65. package/dist/mcp-exec.d.ts.map +1 -1
  66. package/dist/mcp-exec.js +57 -3
  67. package/dist/mcp-exec.js.map +1 -1
  68. package/dist/mcp-http.d.ts +2 -1
  69. package/dist/mcp-http.d.ts.map +1 -1
  70. package/dist/mcp-http.js +3 -2
  71. package/dist/mcp-http.js.map +1 -1
  72. package/dist/mcp-tool-meta.d.ts +21 -0
  73. package/dist/mcp-tool-meta.d.ts.map +1 -0
  74. package/dist/mcp-tool-meta.js +246 -0
  75. package/dist/mcp-tool-meta.js.map +1 -0
  76. package/dist/mcp.d.ts +3 -2
  77. package/dist/mcp.d.ts.map +1 -1
  78. package/dist/mcp.js +36 -98
  79. package/dist/mcp.js.map +1 -1
  80. package/dist/openapi-types.d.ts.map +1 -1
  81. package/dist/openapi-types.js +45 -2
  82. package/dist/openapi-types.js.map +1 -1
  83. package/dist/output-schemas.d.ts +8 -0
  84. package/dist/output-schemas.d.ts.map +1 -1
  85. package/dist/output-schemas.js +14 -0
  86. package/dist/output-schemas.js.map +1 -1
  87. package/dist/ppr-read-fix.d.ts +8 -0
  88. package/dist/ppr-read-fix.d.ts.map +1 -0
  89. package/dist/ppr-read-fix.js +356 -0
  90. package/dist/ppr-read-fix.js.map +1 -0
  91. package/dist/recipes/5.6.0.d.ts +10 -0
  92. package/dist/recipes/5.6.0.d.ts.map +1 -0
  93. package/dist/recipes/5.6.0.js +68 -0
  94. package/dist/recipes/5.6.0.js.map +1 -0
  95. package/dist/recipes/5.7.0.d.ts +12 -0
  96. package/dist/recipes/5.7.0.d.ts.map +1 -0
  97. package/dist/recipes/5.7.0.js +70 -0
  98. package/dist/recipes/5.7.0.js.map +1 -0
  99. package/dist/recipes/index.d.ts +13 -0
  100. package/dist/recipes/index.d.ts.map +1 -1
  101. package/dist/recipes/index.js +4 -0
  102. package/dist/recipes/index.js.map +1 -1
  103. package/dist/review.d.ts.map +1 -1
  104. package/dist/review.js +9 -2
  105. package/dist/review.js.map +1 -1
  106. package/dist/rules/codes.d.ts +10 -3
  107. package/dist/rules/codes.d.ts.map +1 -1
  108. package/dist/rules/codes.js +11 -4
  109. package/dist/rules/codes.js.map +1 -1
  110. package/dist/rules/explanations.d.ts.map +1 -1
  111. package/dist/rules/explanations.js +52 -16
  112. package/dist/rules/explanations.js.map +1 -1
  113. package/dist/rules/islands.d.ts +91 -0
  114. package/dist/rules/islands.d.ts.map +1 -1
  115. package/dist/rules/islands.js +757 -3
  116. package/dist/rules/islands.js.map +1 -1
  117. package/dist/rules/legacy.js +1 -1
  118. package/dist/rules/legacy.js.map +1 -1
  119. package/dist/rules/ppr.d.ts +16 -0
  120. package/dist/rules/ppr.d.ts.map +1 -0
  121. package/dist/rules/ppr.js +114 -0
  122. package/dist/rules/ppr.js.map +1 -0
  123. package/dist/rules/swap.d.ts +7 -0
  124. package/dist/rules/swap.d.ts.map +1 -0
  125. package/dist/rules/swap.js +338 -0
  126. package/dist/rules/swap.js.map +1 -0
  127. package/dist/rules/text-slot-boolean.d.ts +8 -0
  128. package/dist/rules/text-slot-boolean.d.ts.map +1 -0
  129. package/dist/rules/text-slot-boolean.js +57 -0
  130. package/dist/rules/text-slot-boolean.js.map +1 -0
  131. package/dist/rules/undeclared-response.d.ts +9 -0
  132. package/dist/rules/undeclared-response.d.ts.map +1 -0
  133. package/dist/rules/undeclared-response.js +93 -0
  134. package/dist/rules/undeclared-response.js.map +1 -0
  135. package/dist/scaffold-hole.d.ts +105 -0
  136. package/dist/scaffold-hole.d.ts.map +1 -0
  137. package/dist/scaffold-hole.js +688 -0
  138. package/dist/scaffold-hole.js.map +1 -0
  139. package/dist/scaffold.d.ts +5 -3
  140. package/dist/scaffold.d.ts.map +1 -1
  141. package/dist/scaffold.js +56 -46
  142. package/dist/scaffold.js.map +1 -1
  143. package/dist/upgrade.d.ts +34 -8
  144. package/dist/upgrade.d.ts.map +1 -1
  145. package/dist/upgrade.js +197 -25
  146. package/dist/upgrade.js.map +1 -1
  147. package/dist/verification-plan.d.ts.map +1 -1
  148. package/dist/verification-plan.js +12 -1
  149. package/dist/verification-plan.js.map +1 -1
  150. package/dist/version-drift.js +1 -1
  151. package/dist/version-drift.js.map +1 -1
  152. package/dist/web-app-options.d.ts +1 -1
  153. package/dist/web-app-options.d.ts.map +1 -1
  154. package/dist/web-app-options.js.map +1 -1
  155. package/docs/examples.json +70 -10
  156. package/docs/llms-full.txt +3162 -1196
  157. package/docs/types.json +1473 -322
  158. package/package.json +11 -11
  159. package/src/cdn-check.ts +21 -7
  160. package/src/check-diagnostics.ts +9 -3
  161. package/src/check-scan.ts +35 -32
  162. package/src/check.ts +32 -10
  163. package/src/cli.ts +71 -9
  164. package/src/command-catalog.ts +149 -6
  165. package/src/contracts.ts +348 -14
  166. package/src/doctor.ts +62 -3
  167. package/src/fix-recipes.ts +28 -0
  168. package/src/frontend-guidance.ts +20 -8
  169. package/src/internal/git-ignored.ts +47 -0
  170. package/src/internal/source-facts.ts +198 -0
  171. package/src/introspect.ts +1 -1
  172. package/src/load.ts +29 -0
  173. package/src/local-cli.ts +83 -0
  174. package/src/lock-links.ts +5 -43
  175. package/src/mcp-delegate.ts +30 -9
  176. package/src/mcp-exec.ts +74 -3
  177. package/src/mcp-http.ts +3 -2
  178. package/src/mcp-tool-meta.ts +268 -0
  179. package/src/mcp.ts +35 -99
  180. package/src/openapi-types.ts +43 -2
  181. package/src/output-schemas.ts +28 -0
  182. package/src/ppr-read-fix.ts +426 -0
  183. package/src/recipes/5.6.0.ts +69 -0
  184. package/src/recipes/5.7.0.ts +72 -0
  185. package/src/recipes/index.ts +18 -0
  186. package/src/review.ts +9 -2
  187. package/src/rules/codes.ts +11 -4
  188. package/src/rules/explanations.ts +52 -16
  189. package/src/rules/islands.ts +875 -3
  190. package/src/rules/legacy.ts +1 -1
  191. package/src/rules/ppr.ts +143 -0
  192. package/src/rules/swap.ts +402 -0
  193. package/src/rules/text-slot-boolean.ts +56 -0
  194. package/src/rules/undeclared-response.ts +92 -0
  195. package/src/scaffold-hole.ts +880 -0
  196. package/src/scaffold.ts +60 -49
  197. package/src/upgrade.ts +229 -33
  198. package/src/verification-plan.ts +20 -1
  199. package/src/version-drift.ts +1 -1
  200. package/src/web-app-options.ts +2 -0
  201. package/dist/rules/nano.d.ts +0 -6
  202. package/dist/rules/nano.d.ts.map +0 -1
  203. package/dist/rules/nano.js +0 -273
  204. package/dist/rules/nano.js.map +0 -1
  205. package/src/rules/nano.ts +0 -307
package/src/mcp.ts CHANGED
@@ -40,8 +40,9 @@
40
40
  * handed to that CLI; when that is impossible the version-sensitive tools refuse rather than answer
41
41
  * for the wrong release (see `./mcp-delegate.ts`). The protocol is hand-rolled (newline-delimited JSON-RPC 2.0 over stdio), including
42
42
  * standard MCP progress notifications and request cancellation - no SDK dependency, the same
43
- * minimal-surface choice as the rest of nifra. The pure dispatch lives in `./mcp-protocol.ts`; this
44
- * module is the I/O shell (stdin loop, tool wiring, the run subprocess).
43
+ * minimal-surface choice as the rest of nifra. The pure dispatch lives in `./mcp-protocol.ts` and the
44
+ * stdio framing in `@nifrajs/mcp/stdio`; this module is the dispatch shell (roots, tool wiring, the run
45
+ * subprocess).
45
46
  *
46
47
  * This process runs no project code and holds none of the project's `.env`: the config, the backend
47
48
  * and everything they import run in a fresh subprocess per call (`./mcp-isolate.ts`), and a session
@@ -50,6 +51,7 @@
50
51
 
51
52
  import { stat } from "node:fs/promises"
52
53
  import { resolve } from "node:path"
54
+ import { runStdioTransport, type StdioConnection } from "@nifrajs/mcp/stdio"
53
55
  import { loadDocsCorpus } from "./docs-search.ts"
54
56
  import { loadExamplesCorpus } from "./examples.ts"
55
57
  import type { AppLoader } from "./load.ts"
@@ -59,9 +61,6 @@ import { docsTools } from "./mcp-docs-tools.ts"
59
61
  import {
60
62
  createMcpProtocolState,
61
63
  handleRpc,
62
- isJsonRpcRequest,
63
- isJsonRpcResponse,
64
- type JsonRpcNotification,
65
64
  type JsonRpcRequest,
66
65
  type JsonRpcResponse,
67
66
  type McpPrompt,
@@ -188,8 +187,6 @@ const ANSWERED_WITHOUT_THE_APP: ReadonlySet<string> = new Set([
188
187
  "notifications/initialized",
189
188
  "notifications/roots/list_changed",
190
189
  ])
191
- const MAX_STDIO_MESSAGE_BYTES = 8 * 1024 * 1024
192
- const STDIO_ENCODER = new TextEncoder()
193
190
 
194
191
  interface ProjectApp {
195
192
  readonly name: string
@@ -268,29 +265,12 @@ export async function runMcpServer(
268
265
  let drift: ToolingDrift | undefined = await detectToolingDrift(rootState.root, version)
269
266
  const serverInfo = { name: "nifra", version }
270
267
  const state = createMcpProtocolState()
271
- const send = (message: JsonRpcResponse | JsonRpcNotification): void => {
272
- let encoded: string
273
- try {
274
- encoded = JSON.stringify(message)
275
- } catch {
276
- encoded = JSON.stringify(
277
- rpcError(responseIdOf(message), -32603, "MCP response is not serializable"),
278
- )
279
- }
280
- if (STDIO_ENCODER.encode(encoded).byteLength > MAX_STDIO_MESSAGE_BYTES)
281
- encoded = JSON.stringify(
282
- rpcError(responseIdOf(message), -32603, "MCP response exceeded the size limit"),
283
- )
284
- process.stdout.write(`${encoded}\n`)
285
- }
286
268
  let rootsSupported = false
287
269
  let rootsRequestPending = false
288
- const requestRoots = (): void => {
270
+ const requestRoots = (connection: StdioConnection): void => {
289
271
  if (!rootsSupported || rootsRequestPending) return
290
272
  rootsRequestPending = true
291
- process.stdout.write(
292
- `${JSON.stringify({ jsonrpc: "2.0", id: ROOTS_REQUEST_ID, method: "roots/list" })}\n`,
293
- )
273
+ connection.send({ jsonrpc: "2.0", id: ROOTS_REQUEST_ID, method: "roots/list" })
294
274
  }
295
275
  const onRootsAnswer = async (message: JsonRpcResponse): Promise<void> => {
296
276
  const result = "result" in message ? message.result : undefined
@@ -310,15 +290,20 @@ export async function runMcpServer(
310
290
  // must see the adopted root, even though dispatches themselves run concurrently.
311
291
  let rootsUpdate: Promise<void> = Promise.resolve()
312
292
 
313
- const dispatchRootsAnswer = (message: JsonRpcResponse): void => {
293
+ const dispatchRootsAnswer = (message: JsonRpcResponse): boolean => {
314
294
  // The roots answer is a response to a request initiated by this server, not a client RPC request.
315
295
  // Serialize adoption with normal dispatch so a following request cannot observe a half-updated root.
316
- if (!rootsRequestPending) return
296
+ if (message.id !== ROOTS_REQUEST_ID) return false
297
+ if (!rootsRequestPending) return true
317
298
  rootsRequestPending = false
318
299
  rootsUpdate = onRootsAnswer(message).catch(() => {})
300
+ return true
319
301
  }
320
302
 
321
- const dispatch = async (message: JsonRpcRequest): Promise<void> => {
303
+ const dispatch = async (
304
+ message: JsonRpcRequest,
305
+ connection: StdioConnection,
306
+ ): Promise<JsonRpcResponse | null> => {
322
307
  await rootsUpdate
323
308
  if (message.method === "initialize") {
324
309
  rootsSupported = clientSupportsRoots(message.params)
@@ -338,13 +323,12 @@ export async function runMcpServer(
338
323
  prompts: projectPrompts(),
339
324
  instructions: rootInstructions(rootState, drift),
340
325
  },
341
- { state, sendNotification: send, exposeToolErrors: true },
326
+ { state, sendNotification: connection.send, exposeToolErrors: true },
342
327
  )
343
- if (response) send(response)
344
328
  // Ask for the client's workspace roots once the handshake completes, and again whenever the
345
- // client says they changed. The answer comes back through the interception above.
346
- if (method.startsWith("notifications/")) requestRoots()
347
- return
329
+ // client says they changed. The answer comes back through `dispatchRootsAnswer`.
330
+ if (method.startsWith("notifications/")) requestRoots(connection)
331
+ return response
348
332
  }
349
333
  const project = await ctx
350
334
  let activeTools: McpTool[]
@@ -386,76 +370,28 @@ export async function runMcpServer(
386
370
  ...project.features,
387
371
  instructions: rootInstructions(rootState, drift),
388
372
  }
389
- const response = await handleRpc(message, activeTools, serverInfo, features, {
373
+ return handleRpc(message, activeTools, serverInfo, features, {
390
374
  state,
391
- sendNotification: send,
375
+ sendNotification: connection.send,
392
376
  // The stdio caller is the developer's own agent: a failure it cannot read it cannot fix.
393
377
  exposeToolErrors: true,
394
378
  })
395
- if (response) send(response)
396
379
  }
397
380
 
398
- const decoder = new TextDecoder()
399
- let buffer = ""
400
- let bufferBytes = 0
401
- let discardingOversized = false
402
- const processLine = (rawLine: string): void => {
403
- const line = rawLine.trim()
404
- if (line === "") return
405
- if (STDIO_ENCODER.encode(rawLine).byteLength > MAX_STDIO_MESSAGE_BYTES) {
406
- send(rpcError(null, -32600, "MCP message exceeded the size limit"))
407
- return
408
- }
409
- let parsed: unknown
410
- try {
411
- parsed = JSON.parse(line) as unknown
412
- } catch {
413
- send(rpcError(null, -32700, "parse error"))
414
- return
415
- }
416
- if (isJsonRpcRequest(parsed)) {
417
- void dispatch(parsed).catch((err) => {
418
- const msg = err instanceof Error ? err.message : String(err)
419
- send(rpcError(parsed.id ?? null, -32603, msg))
420
- })
421
- } else if (isJsonRpcResponse(parsed) && parsed.id === ROOTS_REQUEST_ID) {
422
- dispatchRootsAnswer(parsed)
423
- } else {
424
- // Do not let null, arrays, scalars, responses for unknown ids, or malformed envelopes reach the
425
- // dispatch shell. In particular, reading `.id` from a hostile `null` must never crash the loop.
426
- send(rpcError(null, -32600, "Invalid Request"))
427
- }
428
- }
429
- for await (const chunk of Bun.stdin.stream()) {
430
- let text = decoder.decode(chunk as Uint8Array, { stream: true })
431
- if (discardingOversized) {
432
- const newline = text.indexOf("\n")
433
- if (newline === -1) continue
434
- text = text.slice(newline + 1)
435
- discardingOversized = false
436
- }
437
- buffer += text
438
- bufferBytes += STDIO_ENCODER.encode(text).byteLength
439
- let nl = buffer.indexOf("\n")
440
- while (nl !== -1) {
441
- const line = buffer.slice(0, nl)
442
- buffer = buffer.slice(nl + 1)
443
- bufferBytes = Math.max(0, bufferBytes - STDIO_ENCODER.encode(line).byteLength - 1)
444
- nl = buffer.indexOf("\n")
445
- processLine(line)
446
- }
447
- if (bufferBytes > MAX_STDIO_MESSAGE_BYTES) {
448
- buffer = ""
449
- bufferBytes = 0
450
- discardingOversized = true
451
- send(rpcError(null, -32600, "MCP message exceeded the size limit"))
452
- }
381
+ try {
382
+ await runStdioTransport({
383
+ onRequest: async (message, connection) => {
384
+ try {
385
+ return await dispatch(message, connection)
386
+ } catch (err) {
387
+ // Same audience as `exposeToolErrors`: a project that fails to load says why.
388
+ if (message.id === undefined) return null
389
+ return rpcError(message.id, -32603, err instanceof Error ? err.message : String(err))
390
+ }
391
+ },
392
+ onResponse: dispatchRootsAnswer,
393
+ })
394
+ } finally {
395
+ closeWarmWorkers()
453
396
  }
454
- closeWarmWorkers()
455
- }
456
-
457
- function responseIdOf(message: JsonRpcResponse | JsonRpcNotification): string | number | null {
458
- if (!("id" in message)) return null
459
- const id = message.id
460
- return id === null || typeof id === "string" || typeof id === "number" ? id : null
461
397
  }
@@ -39,6 +39,43 @@ type TypeChecker = TSApi.TypeChecker
39
39
 
40
40
  const hasFlag = (type: Type, flag: number): boolean => (type.flags & flag) !== 0
41
41
 
42
+ /** A `bigint` as a nifra JSON response writes it: its decimal string. */
43
+ const BIGINT_SCHEMA: JsonSchema = { type: "string", pattern: "^-?(0|[1-9][0-9]*)$" }
44
+
45
+ /** `JSON.stringify` writes a typed array as an object keyed by index. */
46
+ const NUMBER_ARRAYS: ReadonlySet<string> = new Set([
47
+ "Int8Array",
48
+ "Uint8Array",
49
+ "Uint8ClampedArray",
50
+ "Int16Array",
51
+ "Uint16Array",
52
+ "Int32Array",
53
+ "Uint32Array",
54
+ "Float32Array",
55
+ "Float64Array",
56
+ ])
57
+ const NUMBER_ARRAY_SCHEMA: JsonSchema = { type: "object", additionalProperties: { type: "number" } }
58
+ /** A `BigInt64Array` or `BigUint64Array`: keyed by index too, each entry a `bigint`'s decimal string. */
59
+ const BIGINT_ARRAYS: ReadonlySet<string> = new Set(["BigInt64Array", "BigUint64Array"])
60
+ const BIGINT_ARRAY_SCHEMA: JsonSchema = { type: "object", additionalProperties: BIGINT_SCHEMA }
61
+ /** What a Node `Buffer`'s `toJSON` writes in place of the index object. */
62
+ const BUFFER_SCHEMA: JsonSchema = {
63
+ type: "object",
64
+ properties: {
65
+ type: { const: "Buffer" },
66
+ data: { type: "array", items: { type: "integer", minimum: 0, maximum: 255 } },
67
+ },
68
+ required: ["type", "data"],
69
+ }
70
+
71
+ /** The schema of a typed array or `Buffer` named `name`, as `JSON.stringify` writes it. */
72
+ function binarySchema(name: string | undefined): JsonSchema | undefined {
73
+ if (name === undefined) return undefined
74
+ if (name === "Buffer") return BUFFER_SCHEMA
75
+ if (BIGINT_ARRAYS.has(name)) return BIGINT_ARRAY_SCHEMA
76
+ return NUMBER_ARRAYS.has(name) ? NUMBER_ARRAY_SCHEMA : undefined
77
+ }
78
+
42
79
  function schemaForType(
43
80
  ts: TypeScriptApi,
44
81
  checker: TypeChecker,
@@ -66,7 +103,7 @@ function schemaForType(
66
103
  if (hasFlag(type, ts.TypeFlags.StringLike)) return { type: "string" }
67
104
  if (hasFlag(type, ts.TypeFlags.NumberLike)) return { type: "number" }
68
105
  if (hasFlag(type, ts.TypeFlags.BooleanLike)) return { type: "boolean" }
69
- if (hasFlag(type, ts.TypeFlags.BigIntLike)) return { type: "integer" }
106
+ if (hasFlag(type, ts.TypeFlags.BigIntLike)) return BIGINT_SCHEMA
70
107
  if (hasFlag(type, ts.TypeFlags.Null)) return { type: "null" }
71
108
 
72
109
  if (type.isUnion()) {
@@ -93,6 +130,8 @@ function schemaForType(
93
130
  }
94
131
 
95
132
  if (type.symbol?.name === "Date") return { type: "string", format: "date-time" }
133
+ const binary = binarySchema(type.symbol?.name)
134
+ if (binary !== undefined) return binary
96
135
  if ((type.flags & ts.TypeFlags.Object) === 0) return undefined
97
136
 
98
137
  seen.add(type)
@@ -255,7 +294,7 @@ async function schemaForType7(
255
294
  if ((input.flags & stringLikeFlag) !== 0) return { type: "string" }
256
295
  if ((input.flags & numberLikeFlag) !== 0) return { type: "number" }
257
296
  if ((input.flags & booleanLikeFlag) !== 0) return { type: "boolean" }
258
- if ((input.flags & bigintLikeFlag) !== 0) return { type: "integer" }
297
+ if ((input.flags & bigintLikeFlag) !== 0) return BIGINT_SCHEMA
259
298
  if ((input.flags & nullFlag) !== 0) return { type: "null" }
260
299
 
261
300
  if ((input.flags & unionFlag) !== 0) {
@@ -291,6 +330,8 @@ async function schemaForType7(
291
330
 
292
331
  const symbol = await input.getSymbol()
293
332
  if (symbol?.name === "Date") return { type: "string", format: "date-time" }
333
+ const binary = binarySchema(symbol?.name)
334
+ if (binary !== undefined) return binary
294
335
  if ((input.flags & objectFlag) === 0) return undefined
295
336
 
296
337
  seen.add(input)
@@ -496,6 +496,8 @@ interface ProbeRoute {
496
496
  readonly file: string
497
497
  readonly fns: readonly RouteFn[]
498
498
  readonly schemas: readonly OutputExport[]
499
+ /** Holes whose `boundaryLoaders` entry's `load` return type to read. */
500
+ readonly holes?: readonly string[]
499
501
  }
500
502
 
501
503
  /** Shapes keyed `<file>#<export>`: a route function's return type, or a schema's output type. */
@@ -532,6 +534,13 @@ function probeSource(routes: readonly ProbeRoute[]): {
532
534
  names.set(name, `${route.file}#${schema}`)
533
535
  lines.push(`declare const ${name}: __NifraDeclared<typeof __nifra_m${i}, "${schema}">`)
534
536
  }
537
+ route.holes?.forEach((hole, j) => {
538
+ const name = `__nifra_h${i}_${j}`
539
+ names.set(name, `${route.file}#boundaryLoaders.${hole}`)
540
+ lines.push(
541
+ `declare const ${name}: __NifraReturned<(typeof __nifra_m${i})["boundaryLoaders"][${JSON.stringify(hole)}], "load">`,
542
+ )
543
+ })
535
544
  })
536
545
  return { text: `${lines.join("\n")}\n`, names }
537
546
  }
@@ -1147,6 +1156,25 @@ export async function planOutputSchemas(
1147
1156
  return { entries, edits, warnings }
1148
1157
  }
1149
1158
 
1159
+ /**
1160
+ * What hole `hole`'s loader in the backend half `file` returns, with `text` read as that file: the
1161
+ * data a fix that writes the loader drafts its output schema from.
1162
+ */
1163
+ export async function holeLoaderShape(
1164
+ root: string,
1165
+ file: string,
1166
+ hole: string,
1167
+ text: string,
1168
+ ): Promise<{ readonly shape?: Shape; readonly warnings: readonly string[] }> {
1169
+ const { shapes, warnings } = await readShapes(
1170
+ root,
1171
+ [{ file, fns: [], schemas: [], holes: [hole] }],
1172
+ new Map([[file, text]]),
1173
+ )
1174
+ const shape = shapes.get(`${file}#boundaryLoaders.${hole}`)
1175
+ return shape === undefined ? { warnings } : { shape: dataShape(shape), warnings }
1176
+ }
1177
+
1150
1178
  // ---- entry points ------------------------------------------------------------------------------
1151
1179
 
1152
1180
  const ROUTE_BACKEND_TS = /\.backend\.[cm]?ts$/