@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
@@ -13,12 +13,12 @@
13
13
 
14
14
  import { existsSync } from "node:fs"
15
15
  import { resolve } from "node:path"
16
- import type {
17
- AssuranceReport,
18
- AssuredRoute,
19
- InvariantSetup,
20
- InvariantSetupResult,
21
- InvariantsConfig,
16
+ import {
17
+ type AssuranceReport,
18
+ type AssuredRoute,
19
+ applyInvariantSetup,
20
+ type InvariantSetupResult,
21
+ type InvariantsConfig,
22
22
  } from "@nifrajs/core/assurance"
23
23
  import { snapshotCapabilities } from "@nifrajs/core/capabilities"
24
24
  import { buildNifraManifest, parseNifraManifest } from "@nifrajs/core/manifest"
@@ -41,6 +41,8 @@ export interface VerificationLevelStatus {
41
41
  readonly ok: boolean
42
42
  /** Why the level does not hold - a gate failure or a missing prerequisite. Empty when ok. */
43
43
  readonly reasons: readonly string[]
44
+ /** L4 only: the `"METHOD /path"` witnesses `invariants.setup` returned, when it returned any. */
45
+ readonly setupWitnesses?: readonly string[]
44
46
  }
45
47
 
46
48
  export interface VerificationLevelsResult {
@@ -79,7 +81,7 @@ export async function collectVerificationLevels(
79
81
  ...(options.config !== undefined ? { config: options.config } : {}),
80
82
  maxDiagnostics: 5,
81
83
  })
82
- const statuses: { level: number; name: string; ok: boolean; reasons: string[] }[] = []
84
+ const statuses: LevelStatusDraft[] = []
83
85
 
84
86
  // L0 - typed contract (`nifra check`).
85
87
  const check = await verification.check()
@@ -181,75 +183,81 @@ export async function collectVerificationLevels(
181
183
  })
182
184
 
183
185
  // L4 - contract-generated invariants against an explicitly isolated executor.
184
- const l4Reasons: string[] = []
185
- if (config.invariants === undefined) {
186
- l4Reasons.push(
187
- "no isolated invariant executor configured - add `invariants.executor` in nifra.assurance.ts",
188
- )
189
- } else {
190
- l4Reasons.push(...(await runInvariants(config.source, config.invariants, options.seed ?? 1)))
191
- }
192
- statuses.push({
186
+ const l4 =
187
+ config.invariants === undefined
188
+ ? {
189
+ reasons: [
190
+ "no isolated invariant executor configured - add `invariants.executor` in nifra.assurance.ts",
191
+ ],
192
+ setupWitnesses: [],
193
+ }
194
+ : await runInvariants(config.source, config.invariants, options.seed ?? 1)
195
+ const l4Status: LevelStatusDraft = {
193
196
  level: 4,
194
197
  name: "invariant-tested",
195
- ok: l4Reasons.length === 0,
196
- reasons: l4Reasons,
197
- })
198
+ ok: l4.reasons.length === 0,
199
+ reasons: l4.reasons,
200
+ }
201
+ if (l4.setupWitnesses.length > 0) l4Status.setupWitnesses = l4.setupWitnesses
202
+ statuses.push(l4Status)
198
203
 
199
204
  return finalize(statuses, assurance.routes)
200
205
  }
201
206
 
207
+ interface LevelStatusDraft {
208
+ level: number
209
+ name: string
210
+ ok: boolean
211
+ reasons: string[]
212
+ setupWitnesses?: readonly string[]
213
+ }
214
+
202
215
  /**
203
- * Run L4 against the configured target. `setup` runs at most once, on the first request, and its
204
- * `teardown` runs once the run ends - after a failure too - so an app can provision a throwaway target
205
- * only when L4 actually exercises it.
216
+ * Run L4 against the configured target. `setup` runs once, before the runner generates its first
217
+ * case, so the witnesses and prepareRequest it returns reach every case; its `teardown` runs once the
218
+ * run ends - after a failure too, a malformed setup result included.
206
219
  */
207
220
  async function runInvariants(
208
221
  source: unknown,
209
222
  invariants: InvariantsConfig,
210
223
  seed: number,
211
- ): Promise<string[]> {
212
- let provisioned: Promise<InvariantSetupResult | undefined> | undefined
213
- const provision = (setup: InvariantSetup): Promise<InvariantSetupResult | undefined> => {
214
- provisioned ??= Promise.resolve()
215
- .then(setup)
216
- .then(
217
- (result) => result ?? undefined,
218
- (error: unknown) => {
219
- throw new Error(`invariants.setup failed: ${messageOf(error)}`)
220
- },
221
- )
222
- return provisioned
223
- }
224
- const fetch = async (request: Request): Promise<Response> => {
225
- const ready = invariants.setup === undefined ? undefined : await provision(invariants.setup)
226
- const executor = ready?.executor ?? invariants.executor
224
+ ): Promise<{ reasons: string[]; setupWitnesses: readonly string[] }> {
225
+ const reasons: string[] = []
226
+ let provisioned: InvariantSetupResult | undefined
227
+ let setupWitnesses: readonly string[] = []
228
+ try {
229
+ let run = invariants
230
+ if (invariants.setup !== undefined) {
231
+ try {
232
+ provisioned = (await invariants.setup()) ?? undefined
233
+ } catch (error) {
234
+ throw new Error(`invariants.setup failed: ${messageOf(error)}`)
235
+ }
236
+ const applied = applyInvariantSetup(invariants, provisioned)
237
+ run = applied.invariants
238
+ setupWitnesses = applied.setupWitnesses
239
+ }
240
+ const executor = run.executor
227
241
  if (executor === undefined) {
228
242
  throw new Error(
229
243
  "no invariant executor: invariants.setup returned none and invariants.executor is not set",
230
244
  )
231
245
  }
232
- return executor(request)
233
- }
234
- const options: AdversarialContractOptions = {
235
- seed,
236
- runtimes: [{ name: "isolated", fetch }],
237
- expectedValidationStatuses: [400, 422],
238
- requireCoverage: true,
239
- }
240
- const runOptions: Record<string, unknown> = {}
241
- for (const name of INVARIANT_RUN_OPTIONS) {
242
- if (invariants[name] !== undefined) runOptions[name] = invariants[name]
243
- }
244
- const reasons: string[] = []
245
- try {
246
+ const runOptions: Record<string, unknown> = {}
247
+ for (const name of INVARIANT_RUN_OPTIONS) {
248
+ if (run[name] !== undefined) runOptions[name] = run[name]
249
+ }
250
+ const options: AdversarialContractOptions = {
251
+ seed,
252
+ runtimes: [{ name: "isolated", fetch: executor }],
253
+ expectedValidationStatuses: [400, 422],
254
+ requireCoverage: true,
255
+ }
246
256
  const report = await runAdversarialContract(source as ContractTestApp, {
247
257
  ...options,
248
258
  ...runOptions,
249
259
  })
250
- const target = await targetFailure(provisioned, invariants)
251
- if (target !== undefined) reasons.push(target)
252
- else if (!report.ok) {
260
+ if (!report.ok) {
253
261
  reasons.push(
254
262
  ...report.failures
255
263
  .slice(0, 5)
@@ -268,18 +276,17 @@ async function runInvariants(
268
276
  )
269
277
  }
270
278
  } catch (error) {
271
- reasons.push((await targetFailure(provisioned, invariants)) ?? messageOf(error))
279
+ reasons.push(messageOf(error))
272
280
  } finally {
273
- const ready = await provisioned?.catch(() => undefined)
274
- if (ready?.teardown !== undefined) {
281
+ if (typeof provisioned?.teardown === "function") {
275
282
  try {
276
- await ready.teardown()
283
+ await provisioned.teardown()
277
284
  } catch (error) {
278
285
  reasons.push(`invariants teardown failed: ${messageOf(error)}`)
279
286
  }
280
287
  }
281
288
  }
282
- return reasons
289
+ return { reasons, setupWitnesses }
283
290
  }
284
291
 
285
292
  const INVARIANT_RUN_OPTIONS = [
@@ -290,28 +297,11 @@ const INVARIANT_RUN_OPTIONS = [
290
297
  "maxMutationsPerInput",
291
298
  ] as const
292
299
 
293
- /** The setup or missing-executor failure every case hit, if the target never came up. */
294
- async function targetFailure(
295
- provisioned: Promise<InvariantSetupResult | undefined> | undefined,
296
- invariants: InvariantsConfig,
297
- ): Promise<string | undefined> {
298
- if (provisioned === undefined) return undefined
299
- try {
300
- const ready = await provisioned
301
- if (ready?.executor === undefined && invariants.executor === undefined) {
302
- return "no invariant executor: invariants.setup returned none and invariants.executor is not set"
303
- }
304
- return undefined
305
- } catch (error) {
306
- return messageOf(error)
307
- }
308
- }
309
-
310
300
  const messageOf = (error: unknown): string =>
311
301
  error instanceof Error ? error.message : String(error)
312
302
 
313
303
  function finalize(
314
- statuses: readonly { level: number; name: string; ok: boolean; reasons: string[] }[],
304
+ statuses: readonly LevelStatusDraft[],
315
305
  routes: readonly AssuredRoute[],
316
306
  ): VerificationLevelsResult {
317
307
  // Cumulative: the achieved level is the last rung with every rung below it also holding.
@@ -368,6 +358,9 @@ export async function runLevels(
368
358
  const mark = status.ok ? "✓" : "✗"
369
359
  console.log(`${mark} L${status.level} ${status.name}`)
370
360
  for (const reason of status.reasons) console.log(` - ${reason}`)
361
+ if (status.setupWitnesses !== undefined) {
362
+ console.log(` witnesses from setup: ${status.setupWitnesses.join(", ")}`)
363
+ }
371
364
  }
372
365
  console.log(
373
366
  `[nifra] response contracts: ${result.responseContracts.status} (${result.responseContracts.enforced} enforced, ${result.responseContracts.warnOnly} warn-only, ${result.responseContracts.typedOnly} typed-only)`,
package/src/load.ts CHANGED
@@ -16,7 +16,7 @@
16
16
  import { existsSync } from "node:fs"
17
17
  import { isAbsolute, resolve } from "node:path"
18
18
  import type { CreateWebAppOptions, CssLoadingMode } from "@nifrajs/web"
19
- import type { SecretExemption } from "@nifrajs/web/build"
19
+ import type { SecretExemption, ServerEntrySelfHost } from "@nifrajs/web/build"
20
20
  import { assertCurrentLayout, BACKEND_APP_FILE, CONFIG_FILE, FRAMEWORK_FILE } from "./app-files.ts"
21
21
  import { checkPipelineSeparation } from "./pipeline-guard.ts"
22
22
 
@@ -71,12 +71,19 @@ export interface NifraFramework {
71
71
  /** The deploy target `nifra build` emits without `--target` (default `"bun"`); `nifra target <t>`
72
72
  * rewrites it. */
73
73
  readonly target?: string
74
+ /** Ordinary Vercel SSR: Edge by default, or opt into a Node.js 22 serverless handler. */
75
+ readonly vercelRuntime?: "edge" | "node"
74
76
  /** `"platform"` makes a `cloudflare` / `vercel` build read `c.clientIp` from the header that
75
77
  * platform's edge overwrites (`cf-connecting-ip` / `x-real-ip`). Left out, an edge build has no
76
78
  * caller address, so a per-caller `rateLimit` refuses every request. Declare it only while that edge
77
79
  * is the sole way in: served any other way the header is whatever the client sent. Self-hosting
78
80
  * targets use the socket peer either way. */
79
81
  readonly clientIp?: "platform"
82
+ /** How the server a `bun`, `node` or `deno` build emits stops and keeps idle connections, `nifra start`
83
+ * included: `gracefulSignals` drains it on SIGTERM and SIGINT, `idleTimeoutSec` is Bun's idle
84
+ * connection timeout. `nifra build` checks it before building; an edge build ignores it. See
85
+ * `ServerEntrySelfHost` in `@nifrajs/web/build`. */
86
+ readonly selfHost?: ServerEntrySelfHost
80
87
  /** `nifra dev` settings. `indicator: false` turns the in-page issues badge off for every run
81
88
  * (`nifra dev --no-indicator` does it for one); browser errors still reach `nifra errors`.
82
89
  * `allowedHosts` lists host names the Bun dev server answers besides loopback ones; it refuses
@@ -225,6 +232,13 @@ function assertFrameworkWebOptions(fw: Partial<NifraFramework>, configFile: stri
225
232
  if (fw.target !== undefined && typeof fw.target !== "string") {
226
233
  wrong("target", 'a deploy target name such as "bun"')
227
234
  }
235
+ if (
236
+ fw.vercelRuntime !== undefined &&
237
+ fw.vercelRuntime !== "edge" &&
238
+ fw.vercelRuntime !== "node"
239
+ ) {
240
+ wrong("vercelRuntime", '"edge" or "node" (only for target "vercel")')
241
+ }
228
242
  if (fw.clientIp !== undefined && fw.clientIp !== "platform") {
229
243
  wrong("clientIp", '"platform" (trust the edge platform\'s client-address header), or left out')
230
244
  }
package/src/local-cli.ts CHANGED
@@ -51,6 +51,18 @@ function ownCore(): string | undefined {
51
51
  return undefined
52
52
  }
53
53
 
54
+ /**
55
+ * The project's `@nifrajs/core` when this CLI runs another copy - a `bunx` of a new release before the
56
+ * project installs it, say - else `undefined`. Not installed in the project counts as another copy.
57
+ */
58
+ export function otherProjectCore(cwd: string): { readonly project?: string } | undefined {
59
+ const own = ownCore()
60
+ if (own === undefined) return undefined
61
+ const project = projectCore(cwd)
62
+ if (project === own) return undefined
63
+ return project === undefined ? {} : { project }
64
+ }
65
+
54
66
  /**
55
67
  * Run `command` through the project's own CLI when this one is another install. Resolves to the
56
68
  * child's exit code, or `undefined` when this process should run the command itself: then, if the
@@ -9,15 +9,17 @@
9
9
 
10
10
  import { renderDocsResult } from "./docs-search.ts"
11
11
  import { type Example, renderExamplesResult } from "./examples.ts"
12
- import { renderFrontendResult } from "./frontend-guidance.ts"
12
+ import { renderFrontendResult, selectFrontendGuidance } from "./frontend-guidance.ts"
13
13
  import { renderLearnResult } from "./learn.ts"
14
14
  import type { McpTool } from "./mcp-protocol.ts"
15
+ import { renderRuntimeResult, selectRuntimeDifferences } from "./runtime-differences.ts"
15
16
  import { renderTypesResult, type TypeEntry } from "./types-search.ts"
16
17
 
18
+ /** Clamp optional MCP pagination input to a safe, deterministic range. */
17
19
  const clamp = (n: number | undefined, lo: number, hi: number, dflt: number): number =>
18
20
  Math.min(Math.max(typeof n === "number" ? n : dflt, lo), hi)
19
21
 
20
- /** Build `nifra_docs` + `nifra_example` + `nifra_types` over injected corpus loaders. */
22
+ /** Build the read-only docs, examples, types, learning, and frontend tools over injected loaders. */
21
23
  export function docsTools(
22
24
  loadDocs: () => Promise<string | undefined>,
23
25
  loadExamples: () => Promise<Example[] | undefined>,
@@ -199,7 +201,53 @@ export function docsTools(
199
201
  adapter?: string
200
202
  limit?: number
201
203
  }
202
- return renderFrontendResult({ symptom, adapter, limit: clamp(limit, 1, 5, 3) })
204
+ const input = { symptom, adapter, limit: clamp(limit, 1, 5, 3) }
205
+ return {
206
+ content: [{ type: "text", text: renderFrontendResult(input) }],
207
+ structuredContent: { ...selectFrontendGuidance(input) },
208
+ }
209
+ },
210
+ },
211
+ {
212
+ name: "nifra_runtime",
213
+ annotations: {
214
+ title: "Runtime differences",
215
+ readOnlyHint: true,
216
+ destructiveHint: false,
217
+ idempotentHint: true,
218
+ openWorldHint: false,
219
+ },
220
+ description:
221
+ 'Explain a behavior that differs between Bun, Node, Deno and Cloudflare Workers by symptom. These are runtime behaviors, not Nifra\'s: request-target and Host handling, pipelining, JSON content-type, engine error messages, recursion depth, .env loading, and runtime-specific APIs. Returns what each runtime does, the fix (and the Nifra option that decides it when there is one), how to verify it, and the versions it was measured on. Call with no args for the index; pass `symptom` (e.g. "path guard skipped", "env var undefined") and/or `runtime` to filter.',
222
+ inputSchema: {
223
+ type: "object",
224
+ properties: {
225
+ symptom: {
226
+ type: "string",
227
+ maxLength: 256,
228
+ description: "What you observe (omit for the index).",
229
+ },
230
+ runtime: {
231
+ type: "string",
232
+ enum: ["bun", "node", "deno", "workerd"],
233
+ description: "Filter to one runtime's entries.",
234
+ },
235
+ limit: { type: "number", description: "Max entries to return (default 3, max 5)." },
236
+ },
237
+ additionalProperties: false,
238
+ },
239
+ handler: async (args) => {
240
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: the MCP layer validated args against inputSchema
241
+ const { symptom, runtime, limit } = args as {
242
+ symptom?: string
243
+ runtime?: string
244
+ limit?: number
245
+ }
246
+ const input = { symptom, runtime, limit: clamp(limit, 1, 5, 3) }
247
+ return {
248
+ content: [{ type: "text", text: renderRuntimeResult(input) }],
249
+ structuredContent: { ...selectRuntimeDifferences(input) },
250
+ }
203
251
  },
204
252
  },
205
253
  ]
package/src/mcp-http.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The PUBLIC nifra docs MCP - Streamable-HTTP transport exposing the project-INDEPENDENT tools
3
- * (`nifra_docs`, `nifra_example`, `nifra_types`, `nifra_learn`, `nifra_frontend` + the `nifra_gallery`
3
+ * (`nifra_docs`, `nifra_example`, `nifra_types`, `nifra_learn`, `nifra_frontend`, `nifra_runtime` + the `nifra_gallery`
4
4
  * MCP Apps widget)
5
5
  * so any remote AI agent can learn nifra without a local checkout. They read the bundled corpus
6
6
  * (llms-full.txt / examples.json / types.json shipped in this package) and ignore `cwd`, so they reuse the
@@ -30,7 +30,7 @@ export { docsTools } from "./mcp-docs-tools.ts"
30
30
  export type { TypeEntry } from "./types-search.ts"
31
31
 
32
32
  // Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
33
- const VERSION = "5.8.0"
33
+ const VERSION = "5.10.0"
34
34
  const SERVER_INFO = { name: "nifra-docs", version: VERSION }
35
35
  // Derive the GET/health tool list from the tools actually served, so the line can never drift from them.
36
36
  const docsHealth = (tools: McpTool[]): string =>
package/src/mcp-io.ts CHANGED
@@ -5,6 +5,8 @@
5
5
  * these limits and stream readers so an untrusted local endpoint or child process cannot exhaust MCP.
6
6
  */
7
7
 
8
+ import { isRecord } from "./internal/record.ts"
9
+
8
10
  export const CHILD_TIMEOUT_MS = 30_000
9
11
  /** Maximum stdout or stderr retained from a project subprocess. The process is killed at the limit. */
10
12
  export const CHILD_OUTPUT_MAX_BYTES = 1_048_576
@@ -380,3 +382,78 @@ export async function readBoundedStream(
380
382
  reader.releaseLock()
381
383
  }
382
384
  }
385
+
386
+ /** Send console output to stderr so it never corrupts the newline-delimited JSON on stdout: a loader that
387
+ * logs would otherwise inject noise into a response line. */
388
+ export function redirectConsoleToStderr(): void {
389
+ const write = (level: string, args: unknown[]): void => {
390
+ Bun.stderr.write(`[${level}] ${args.map((arg) => String(arg)).join(" ")}\n`)
391
+ }
392
+ console.debug = (...args: unknown[]) => write("debug", args)
393
+ console.info = (...args: unknown[]) => write("info", args)
394
+ console.log = (...args: unknown[]) => write("log", args)
395
+ console.warn = (...args: unknown[]) => write("warn", args)
396
+ console.error = (...args: unknown[]) => write("error", args)
397
+ }
398
+
399
+ /** For a project child: send `console.log`, `info` and `debug` to stderr as plain lines and return
400
+ * stdout's own writer, taken before project code loads so nothing it patches reaches the answer channel. */
401
+ export function protocolStdout(): typeof process.stdout.write {
402
+ const stdout = process.stdout.write.bind(process.stdout)
403
+ const toStderr = (...args: unknown[]): void => {
404
+ process.stderr.write(`${args.map((arg) => String(arg)).join(" ")}\n`)
405
+ }
406
+ console.log = toStderr
407
+ console.info = toStderr
408
+ console.debug = toStderr
409
+ return stdout
410
+ }
411
+
412
+ function safeResponseId(value: unknown): number | string | null {
413
+ if (typeof value === "number" && Number.isSafeInteger(value)) return value
414
+ if (typeof value === "string" && value.length <= 128) return value
415
+ return null
416
+ }
417
+
418
+ /** A warm worker's reply: one `{ id, output }` line, with an output over the cap answered as an error. */
419
+ export function workerReplyWriter(
420
+ write: (line: string) => void,
421
+ ): (id: unknown, output: unknown) => void {
422
+ return (id, output) => {
423
+ const responseId = safeResponseId(id)
424
+ const encoded = serializeBoundedJson({ id: responseId, output }, CHILD_OUTPUT_MAX_BYTES - 1)
425
+ write(
426
+ `${encoded ?? JSON.stringify({ id: responseId, output: { error: "worker output exceeded the size limit" } })}\n`,
427
+ )
428
+ }
429
+ }
430
+
431
+ /** A warm worker's request line: its `id` and its `input` record, if the line carried one. */
432
+ export interface WorkerRequest {
433
+ readonly id: unknown
434
+ readonly input: Readonly<Record<string, unknown>> | undefined
435
+ }
436
+
437
+ /** Each request line a warm worker reads from stdin; an oversized or non-JSON line is answered through
438
+ * `send` and skipped. */
439
+ export async function* workerRequests(
440
+ send: (id: unknown, output: unknown) => void,
441
+ ): AsyncGenerator<WorkerRequest> {
442
+ for await (const item of readBoundedLines(Bun.stdin.stream(), CHILD_INPUT_MAX_BYTES)) {
443
+ if (item.kind === "too-large") {
444
+ send(null, { error: `worker input exceeded ${CHILD_INPUT_MAX_BYTES} bytes` })
445
+ continue
446
+ }
447
+ const line = item.text.trim()
448
+ if (line === "") continue
449
+ let message: unknown
450
+ try {
451
+ message = JSON.parse(line)
452
+ } catch {
453
+ send(null, { error: "invalid worker input: expected JSON line" })
454
+ continue
455
+ }
456
+ const record = isRecord(message) ? message : undefined
457
+ yield { id: record?.id, input: isRecord(record?.input) ? record.input : undefined }
458
+ }
459
+ }
@@ -11,6 +11,7 @@ import { existsSync } from "node:fs"
11
11
  import { resolve } from "node:path"
12
12
  import { fileURLToPath } from "node:url"
13
13
  import { CONFIG_FILE } from "./app-files.ts"
14
+ import { isRecord } from "./internal/record.ts"
14
15
  import type { NifraMonorepoConfig } from "./load.ts"
15
16
  import { appFingerprint } from "./mcp-exec.ts"
16
17
  import {
@@ -60,6 +61,7 @@ export const IN_PROCESS_TOOLS: ReadonlySet<string> = new Set([
60
61
  "nifra_types",
61
62
  "nifra_learn",
62
63
  "nifra_frontend",
64
+ "nifra_runtime",
63
65
  ])
64
66
 
65
67
  /** A tool result is bounded again by the stdio message limit when the server sends it. */
@@ -72,9 +74,6 @@ function childPath(): string {
72
74
  )
73
75
  }
74
76
 
75
- const isRecord = (value: unknown): value is Record<string, unknown> =>
76
- typeof value === "object" && value !== null && !Array.isArray(value)
77
-
78
77
  const isAnswer = (value: unknown): value is ProjectChildAnswer =>
79
78
  isRecord(value) &&
80
79
  (value.ok === true || (value.ok === false && typeof value.message === "string"))
@@ -9,10 +9,11 @@
9
9
  * prefixed with the request's token, so anything project code prints cannot be read as an answer.
10
10
  */
11
11
 
12
+ import { isRecord } from "./internal/record.ts"
12
13
  import { detectMonorepo } from "./load.ts"
13
14
  import { projectResources } from "./mcp-context.ts"
14
15
  import { createCachedAppLoader, projectTools } from "./mcp-exec.ts"
15
- import { CHILD_INPUT_MAX_BYTES, readBoundedStream } from "./mcp-io.ts"
16
+ import { CHILD_INPUT_MAX_BYTES, protocolStdout, readBoundedStream } from "./mcp-io.ts"
16
17
  import type {
17
18
  McpPrompt,
18
19
  McpPromptMessage,
@@ -109,9 +110,6 @@ export async function answerProjectRequest(
109
110
  }
110
111
  }
111
112
 
112
- const isArgs = (value: unknown): value is Record<string, unknown> =>
113
- typeof value === "object" && value !== null && !Array.isArray(value)
114
-
115
113
  function parseRequest(text: string): { token: string; request: ProjectChildRequest } | undefined {
116
114
  let value: unknown
117
115
  try {
@@ -119,12 +117,12 @@ function parseRequest(text: string): { token: string; request: ProjectChildReque
119
117
  } catch {
120
118
  return undefined
121
119
  }
122
- if (!isArgs(value)) return undefined
120
+ if (!isRecord(value)) return undefined
123
121
  const { token, op, name, uri, args } = value
124
122
  if (typeof token !== "string" || !/^[0-9a-f-]{16,64}$/.test(token)) return undefined
125
123
  if (op === "monorepo" || op === "surface") return { token, request: { op } }
126
124
  if (op === "resource" && typeof uri === "string") return { token, request: { op, uri } }
127
- if ((op === "tool" || op === "prompt") && typeof name === "string" && isArgs(args)) {
125
+ if ((op === "tool" || op === "prompt") && typeof name === "string" && isRecord(args)) {
128
126
  return { token, request: { op, name, args } }
129
127
  }
130
128
  return undefined
@@ -163,14 +161,7 @@ export async function serveProjectChild(
163
161
  }
164
162
 
165
163
  if (import.meta.main) {
166
- // Bound before project code loads, so nothing it patches can reach the protocol channel.
167
- const stdout = process.stdout.write.bind(process.stdout)
168
- const toStderr = (...args: unknown[]): void => {
169
- process.stderr.write(`${args.map((arg) => String(arg)).join(" ")}\n`)
170
- }
171
- console.log = toStderr
172
- console.info = toStderr
173
- console.debug = toStderr
164
+ const stdout = protocolStdout()
174
165
  const served = await serveProjectChild(
175
166
  process.argv[2] ?? process.cwd(),
176
167
  Bun.stdin.stream(),
package/src/mcp-render.ts CHANGED
@@ -17,9 +17,11 @@ import { loadApp, resolvePlugins } from "./load.ts"
17
17
  import {
18
18
  CHILD_INPUT_MAX_BYTES,
19
19
  CHILD_OUTPUT_MAX_BYTES,
20
- readBoundedLines,
21
20
  readBoundedStream,
21
+ redirectConsoleToStderr,
22
22
  serializeBoundedJson,
23
+ workerReplyWriter,
24
+ workerRequests,
23
25
  } from "./mcp-io.ts"
24
26
  import { frameworkWebAppOptions } from "./web-app-options.ts"
25
27
 
@@ -78,30 +80,6 @@ export async function renderPages(
78
80
  }
79
81
  }
80
82
 
81
- interface RenderWorkerMessage {
82
- readonly id?: unknown
83
- readonly input?: { readonly requests?: unknown }
84
- }
85
-
86
- /** Send console output to stderr so it never corrupts the newline-delimited JSON-RPC on stdout (mirrors
87
- * `mcp-run`'s worker). A loader that logs would otherwise inject noise into a response line. */
88
- function redirectConsoleToStderr(): void {
89
- const write = (level: string, args: unknown[]): void => {
90
- Bun.stderr.write(`[${level}] ${args.map((arg) => String(arg)).join(" ")}\n`)
91
- }
92
- console.debug = (...args: unknown[]) => write("debug", args)
93
- console.info = (...args: unknown[]) => write("info", args)
94
- console.log = (...args: unknown[]) => write("log", args)
95
- console.warn = (...args: unknown[]) => write("warn", args)
96
- console.error = (...args: unknown[]) => write("error", args)
97
- }
98
-
99
- function safeResponseId(value: unknown): number | string | null {
100
- if (typeof value === "number" && Number.isSafeInteger(value)) return value
101
- if (typeof value === "string" && value.length <= 128) return value
102
- return null
103
- }
104
-
105
83
  /**
106
84
  * Warm-worker loop (`--worker`): build the web app ONCE, then SSR each `{ id, input: { requests } }` line
107
85
  * against that hot app and reply `{ id, output }`. The parent (`mcp.ts`'s warm-render handler) spawns this,
@@ -113,51 +91,25 @@ async function runWorker(cwd: string): Promise<void> {
113
91
  // Build once; the same `{ error }` is returned for every request if the build failed, so an agent sees
114
92
  // the actionable message and the parent restarts the worker on the next file change.
115
93
  const built = await buildWebApp(cwd)
116
- const send = (id: unknown, output: unknown): void => {
117
- const responseId = safeResponseId(id)
118
- const encoded = serializeBoundedJson({ id: responseId, output }, CHILD_OUTPUT_MAX_BYTES - 1)
119
- process.stdout.write(
120
- `${encoded ?? JSON.stringify({ id: responseId, output: { error: "worker output exceeded the size limit" } })}\n`,
121
- )
122
- }
123
- for await (const item of readBoundedLines(Bun.stdin.stream(), CHILD_INPUT_MAX_BYTES)) {
124
- if (item.kind === "too-large") {
125
- send(null, { error: `worker input exceeded ${CHILD_INPUT_MAX_BYTES} bytes` })
126
- continue
127
- }
128
- const line = item.text.trim()
129
- if (line === "") continue
130
-
131
- let message: unknown
132
- try {
133
- message = JSON.parse(line) as unknown
134
- } catch {
135
- send(null, { error: "invalid worker input: expected JSON line" })
136
- continue
137
- }
138
- const record =
139
- message !== null && typeof message === "object" && !Array.isArray(message)
140
- ? (message as RenderWorkerMessage)
141
- : undefined
142
- const input =
143
- record?.input !== null && typeof record?.input === "object" && !Array.isArray(record.input)
144
- ? record.input
145
- : undefined
94
+ const send = workerReplyWriter((line) => {
95
+ process.stdout.write(line)
96
+ })
97
+ for await (const { id, input } of workerRequests(send)) {
146
98
  const requests = input?.requests
147
99
  if (!Array.isArray(requests)) {
148
- send(record?.id, { error: "expected { requests: [...] }" })
100
+ send(id, { error: "expected { requests: [...] }" })
149
101
  continue
150
102
  }
151
103
  if ("error" in built) {
152
- send(record?.id, built)
104
+ send(id, built)
153
105
  continue
154
106
  }
155
107
  try {
156
- send(record?.id, {
108
+ send(id, {
157
109
  results: await runApp(built.app, requests as Parameters<typeof runApp>[1]),
158
110
  })
159
111
  } catch (err) {
160
- send(record?.id, { error: errString(err) })
112
+ send(id, { error: errString(err) })
161
113
  }
162
114
  }
163
115
  }
package/src/mcp-root.ts CHANGED
@@ -117,7 +117,7 @@ async function workspaceMatches(
117
117
  ): Promise<string[]> {
118
118
  const segments = pattern
119
119
  .replace(/^\.\//, "")
120
- .replace(/\/+$/, "")
120
+ .replace(/(?<!\/)\/+$/, "")
121
121
  .split("/")
122
122
  .filter((segment) => segment !== "" && segment !== ".")
123
123
  const firstGlob = segments.findIndex((segment) => /[*?[{]/.test(segment))