@nifrajs/cli 3.3.0 → 4.0.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 (425) hide show
  1. package/README.md +42 -3
  2. package/dist/app-files.d.ts +11 -0
  3. package/dist/app-files.d.ts.map +1 -0
  4. package/dist/app-files.js +34 -0
  5. package/dist/app-files.js.map +1 -0
  6. package/dist/assure-hydration.d.ts +7 -1
  7. package/dist/assure-hydration.d.ts.map +1 -1
  8. package/dist/assure-hydration.js +128 -43
  9. package/dist/assure-hydration.js.map +1 -1
  10. package/dist/assure.d.ts.map +1 -1
  11. package/dist/assure.js +16 -2
  12. package/dist/assure.js.map +1 -1
  13. package/dist/capabilities-tool.d.ts +5 -1
  14. package/dist/capabilities-tool.d.ts.map +1 -1
  15. package/dist/capabilities-tool.js +32 -10
  16. package/dist/capabilities-tool.js.map +1 -1
  17. package/dist/cdn-check.d.ts +41 -0
  18. package/dist/cdn-check.d.ts.map +1 -0
  19. package/dist/cdn-check.js +207 -0
  20. package/dist/cdn-check.js.map +1 -0
  21. package/dist/check-diagnostics.d.ts +7 -15
  22. package/dist/check-diagnostics.d.ts.map +1 -1
  23. package/dist/check-diagnostics.js +162 -713
  24. package/dist/check-diagnostics.js.map +1 -1
  25. package/dist/check-scan.d.ts +58 -7
  26. package/dist/check-scan.d.ts.map +1 -1
  27. package/dist/check-scan.js +323 -62
  28. package/dist/check-scan.js.map +1 -1
  29. package/dist/check.d.ts +1 -0
  30. package/dist/check.d.ts.map +1 -1
  31. package/dist/check.js +145 -54
  32. package/dist/check.js.map +1 -1
  33. package/dist/cli.d.ts +42 -16
  34. package/dist/cli.d.ts.map +1 -1
  35. package/dist/cli.js +306 -87
  36. package/dist/cli.js.map +1 -1
  37. package/dist/command-catalog.d.ts +60 -5
  38. package/dist/command-catalog.d.ts.map +1 -1
  39. package/dist/command-catalog.js +298 -33
  40. package/dist/command-catalog.js.map +1 -1
  41. package/dist/config-target.d.ts +8 -0
  42. package/dist/config-target.d.ts.map +1 -0
  43. package/dist/config-target.js +45 -0
  44. package/dist/config-target.js.map +1 -0
  45. package/dist/contracts.d.ts +3 -2
  46. package/dist/contracts.d.ts.map +1 -1
  47. package/dist/contracts.js +56 -16
  48. package/dist/contracts.js.map +1 -1
  49. package/dist/db-audit.d.ts +37 -0
  50. package/dist/db-audit.d.ts.map +1 -0
  51. package/dist/db-audit.js +99 -0
  52. package/dist/db-audit.js.map +1 -0
  53. package/dist/db-child.d.ts +64 -0
  54. package/dist/db-child.d.ts.map +1 -0
  55. package/dist/db-child.js +213 -0
  56. package/dist/db-child.js.map +1 -0
  57. package/dist/db-config.d.ts +60 -0
  58. package/dist/db-config.d.ts.map +1 -0
  59. package/dist/db-config.js +176 -0
  60. package/dist/db-config.js.map +1 -0
  61. package/dist/db-tool.d.ts +84 -0
  62. package/dist/db-tool.d.ts.map +1 -0
  63. package/dist/db-tool.js +537 -0
  64. package/dist/db-tool.js.map +1 -0
  65. package/dist/dev-bun-config.d.ts +20 -13
  66. package/dist/dev-bun-config.d.ts.map +1 -1
  67. package/dist/dev-bun-config.js +98 -41
  68. package/dist/dev-bun-config.js.map +1 -1
  69. package/dist/dev-feed-tool.d.ts +106 -0
  70. package/dist/dev-feed-tool.d.ts.map +1 -0
  71. package/dist/dev-feed-tool.js +713 -0
  72. package/dist/dev-feed-tool.js.map +1 -0
  73. package/dist/dev-server-client.d.ts +67 -0
  74. package/dist/dev-server-client.d.ts.map +1 -0
  75. package/dist/dev-server-client.js +195 -0
  76. package/dist/dev-server-client.js.map +1 -0
  77. package/dist/diagnostics.d.ts +86 -0
  78. package/dist/diagnostics.d.ts.map +1 -1
  79. package/dist/diagnostics.js +85 -0
  80. package/dist/diagnostics.js.map +1 -1
  81. package/dist/diff-tool.d.ts +3 -3
  82. package/dist/diff-tool.d.ts.map +1 -1
  83. package/dist/diff-tool.js +6 -5
  84. package/dist/diff-tool.js.map +1 -1
  85. package/dist/docs-search.d.ts.map +1 -1
  86. package/dist/docs-search.js +12 -4
  87. package/dist/docs-search.js.map +1 -1
  88. package/dist/doctor.d.ts +17 -0
  89. package/dist/doctor.d.ts.map +1 -1
  90. package/dist/doctor.js +76 -15
  91. package/dist/doctor.js.map +1 -1
  92. package/dist/env-file.d.ts +15 -0
  93. package/dist/env-file.d.ts.map +1 -1
  94. package/dist/env-file.js +73 -1
  95. package/dist/env-file.js.map +1 -1
  96. package/dist/fix-recipes.d.ts.map +1 -1
  97. package/dist/fix-recipes.js +41 -21
  98. package/dist/fix-recipes.js.map +1 -1
  99. package/dist/frontend-guidance.js +5 -5
  100. package/dist/frontend-guidance.js.map +1 -1
  101. package/dist/i18n-check.d.ts +16 -0
  102. package/dist/i18n-check.d.ts.map +1 -0
  103. package/dist/i18n-check.js +154 -0
  104. package/dist/i18n-check.js.map +1 -0
  105. package/dist/init-agents.d.ts +49 -13
  106. package/dist/init-agents.d.ts.map +1 -1
  107. package/dist/init-agents.js +239 -34
  108. package/dist/init-agents.js.map +1 -1
  109. package/dist/internal/code-unit-order.d.ts +4 -0
  110. package/dist/internal/code-unit-order.d.ts.map +1 -0
  111. package/dist/internal/code-unit-order.js +6 -0
  112. package/dist/internal/code-unit-order.js.map +1 -0
  113. package/dist/internal/script-kind.d.ts +7 -0
  114. package/dist/internal/script-kind.d.ts.map +1 -0
  115. package/dist/internal/script-kind.js +12 -0
  116. package/dist/internal/script-kind.js.map +1 -0
  117. package/dist/internal/source-facts.d.ts +5 -0
  118. package/dist/internal/source-facts.d.ts.map +1 -1
  119. package/dist/internal/source-facts.js +61 -5
  120. package/dist/internal/source-facts.js.map +1 -1
  121. package/dist/internal/typescript-import.d.ts +49 -24
  122. package/dist/internal/typescript-import.d.ts.map +1 -1
  123. package/dist/internal/typescript-import.js +507 -67
  124. package/dist/internal/typescript-import.js.map +1 -1
  125. package/dist/introspect.d.ts +6 -4
  126. package/dist/introspect.d.ts.map +1 -1
  127. package/dist/introspect.js +93 -74
  128. package/dist/introspect.js.map +1 -1
  129. package/dist/learn.js +3 -3
  130. package/dist/learn.js.map +1 -1
  131. package/dist/levels-tool.d.ts +10 -0
  132. package/dist/levels-tool.d.ts.map +1 -1
  133. package/dist/levels-tool.js +33 -3
  134. package/dist/levels-tool.js.map +1 -1
  135. package/dist/load.d.ts +71 -16
  136. package/dist/load.d.ts.map +1 -1
  137. package/dist/load.js +78 -18
  138. package/dist/load.js.map +1 -1
  139. package/dist/manifest-tool.d.ts.map +1 -1
  140. package/dist/manifest-tool.js +3 -2
  141. package/dist/manifest-tool.js.map +1 -1
  142. package/dist/mcp-app-tool.d.ts.map +1 -1
  143. package/dist/mcp-app-tool.js +2 -0
  144. package/dist/mcp-app-tool.js.map +1 -1
  145. package/dist/mcp-context.d.ts.map +1 -1
  146. package/dist/mcp-context.js +5 -6
  147. package/dist/mcp-context.js.map +1 -1
  148. package/dist/mcp-delegate.d.ts +57 -0
  149. package/dist/mcp-delegate.d.ts.map +1 -0
  150. package/dist/mcp-delegate.js +130 -0
  151. package/dist/mcp-delegate.js.map +1 -0
  152. package/dist/mcp-docs-tools.d.ts.map +1 -1
  153. package/dist/mcp-docs-tools.js +23 -5
  154. package/dist/mcp-docs-tools.js.map +1 -1
  155. package/dist/mcp-exec.d.ts +3 -0
  156. package/dist/mcp-exec.d.ts.map +1 -1
  157. package/dist/mcp-exec.js +263 -131
  158. package/dist/mcp-exec.js.map +1 -1
  159. package/dist/mcp-http.d.ts.map +1 -1
  160. package/dist/mcp-http.js +20 -5
  161. package/dist/mcp-http.js.map +1 -1
  162. package/dist/mcp-io.d.ts +26 -0
  163. package/dist/mcp-io.d.ts.map +1 -1
  164. package/dist/mcp-io.js +113 -0
  165. package/dist/mcp-io.js.map +1 -1
  166. package/dist/mcp-isolate.d.ts +48 -0
  167. package/dist/mcp-isolate.d.ts.map +1 -0
  168. package/dist/mcp-isolate.js +222 -0
  169. package/dist/mcp-isolate.js.map +1 -0
  170. package/dist/mcp-path.d.ts +10 -0
  171. package/dist/mcp-path.d.ts.map +1 -0
  172. package/dist/mcp-path.js +51 -0
  173. package/dist/mcp-path.js.map +1 -0
  174. package/dist/mcp-project-child.d.ts +74 -0
  175. package/dist/mcp-project-child.d.ts.map +1 -0
  176. package/dist/mcp-project-child.js +130 -0
  177. package/dist/mcp-project-child.js.map +1 -0
  178. package/dist/mcp-reflect.d.ts.map +1 -1
  179. package/dist/mcp-reflect.js +2 -2
  180. package/dist/mcp-reflect.js.map +1 -1
  181. package/dist/mcp-render.d.ts.map +1 -1
  182. package/dist/mcp-render.js +64 -45
  183. package/dist/mcp-render.js.map +1 -1
  184. package/dist/mcp-root.d.ts +37 -9
  185. package/dist/mcp-root.d.ts.map +1 -1
  186. package/dist/mcp-root.js +124 -25
  187. package/dist/mcp-root.js.map +1 -1
  188. package/dist/mcp-run.d.ts +18 -1
  189. package/dist/mcp-run.d.ts.map +1 -1
  190. package/dist/mcp-run.js +159 -55
  191. package/dist/mcp-run.js.map +1 -1
  192. package/dist/mcp-ws.js +4 -1
  193. package/dist/mcp-ws.js.map +1 -1
  194. package/dist/mcp.d.ts +18 -5
  195. package/dist/mcp.d.ts.map +1 -1
  196. package/dist/mcp.js +165 -82
  197. package/dist/mcp.js.map +1 -1
  198. package/dist/migrate-layout.d.ts +44 -0
  199. package/dist/migrate-layout.d.ts.map +1 -0
  200. package/dist/migrate-layout.js +982 -0
  201. package/dist/migrate-layout.js.map +1 -0
  202. package/dist/openapi-tool.d.ts +2 -2
  203. package/dist/openapi-tool.d.ts.map +1 -1
  204. package/dist/openapi-tool.js.map +1 -1
  205. package/dist/openapi-types.d.ts +2 -1
  206. package/dist/openapi-types.d.ts.map +1 -1
  207. package/dist/openapi-types.js +240 -12
  208. package/dist/openapi-types.js.map +1 -1
  209. package/dist/pipeline-report.d.ts +3 -2
  210. package/dist/pipeline-report.d.ts.map +1 -1
  211. package/dist/pipeline-report.js +19 -16
  212. package/dist/pipeline-report.js.map +1 -1
  213. package/dist/port.d.ts +5 -4
  214. package/dist/port.d.ts.map +1 -1
  215. package/dist/port.js +46 -29
  216. package/dist/port.js.map +1 -1
  217. package/dist/project-facts.d.ts +28 -4
  218. package/dist/project-facts.d.ts.map +1 -1
  219. package/dist/project-facts.js +12 -2
  220. package/dist/project-facts.js.map +1 -1
  221. package/dist/recipes/4.0.0.d.ts +9 -0
  222. package/dist/recipes/4.0.0.d.ts.map +1 -0
  223. package/dist/recipes/4.0.0.js +34 -0
  224. package/dist/recipes/4.0.0.js.map +1 -0
  225. package/dist/recipes/index.d.ts.map +1 -1
  226. package/dist/recipes/index.js +2 -0
  227. package/dist/recipes/index.js.map +1 -1
  228. package/dist/release-verification.d.ts +11 -1
  229. package/dist/release-verification.d.ts.map +1 -1
  230. package/dist/release-verification.js +47 -4
  231. package/dist/release-verification.js.map +1 -1
  232. package/dist/review.d.ts +21 -0
  233. package/dist/review.d.ts.map +1 -0
  234. package/dist/review.js +823 -0
  235. package/dist/review.js.map +1 -0
  236. package/dist/route-types.d.ts +28 -0
  237. package/dist/route-types.d.ts.map +1 -0
  238. package/dist/route-types.js +106 -0
  239. package/dist/route-types.js.map +1 -0
  240. package/dist/rules/codes.d.ts +9 -0
  241. package/dist/rules/codes.d.ts.map +1 -1
  242. package/dist/rules/codes.js +9 -0
  243. package/dist/rules/codes.js.map +1 -1
  244. package/dist/rules/data-guard.d.ts +12 -0
  245. package/dist/rules/data-guard.d.ts.map +1 -0
  246. package/dist/rules/data-guard.js +213 -0
  247. package/dist/rules/data-guard.js.map +1 -0
  248. package/dist/rules/index.d.ts +3 -0
  249. package/dist/rules/index.d.ts.map +1 -1
  250. package/dist/rules/index.js +17 -5
  251. package/dist/rules/index.js.map +1 -1
  252. package/dist/rules/islands.d.ts.map +1 -1
  253. package/dist/rules/islands.js +7 -4
  254. package/dist/rules/islands.js.map +1 -1
  255. package/dist/rules/legacy.d.ts +3 -1
  256. package/dist/rules/legacy.d.ts.map +1 -1
  257. package/dist/rules/legacy.js +829 -34
  258. package/dist/rules/legacy.js.map +1 -1
  259. package/dist/rules/nano.d.ts.map +1 -1
  260. package/dist/rules/nano.js +15 -6
  261. package/dist/rules/nano.js.map +1 -1
  262. package/dist/rules/pages.d.ts +15 -0
  263. package/dist/rules/pages.d.ts.map +1 -0
  264. package/dist/rules/pages.js +88 -0
  265. package/dist/rules/pages.js.map +1 -0
  266. package/dist/rules/routes.d.ts +11 -0
  267. package/dist/rules/routes.d.ts.map +1 -1
  268. package/dist/rules/routes.js +180 -2
  269. package/dist/rules/routes.js.map +1 -1
  270. package/dist/rules/secrets.d.ts +10 -0
  271. package/dist/rules/secrets.d.ts.map +1 -0
  272. package/dist/rules/secrets.js +169 -0
  273. package/dist/rules/secrets.js.map +1 -0
  274. package/dist/rules/security.d.ts +7 -0
  275. package/dist/rules/security.d.ts.map +1 -1
  276. package/dist/rules/security.js +171 -65
  277. package/dist/rules/security.js.map +1 -1
  278. package/dist/rules/typescript.d.ts +16 -0
  279. package/dist/rules/typescript.d.ts.map +1 -0
  280. package/dist/rules/typescript.js +59 -0
  281. package/dist/rules/typescript.js.map +1 -0
  282. package/dist/rules/zones.d.ts +17 -0
  283. package/dist/rules/zones.d.ts.map +1 -0
  284. package/dist/rules/zones.js +174 -0
  285. package/dist/rules/zones.js.map +1 -0
  286. package/dist/scaffold.d.ts +25 -12
  287. package/dist/scaffold.d.ts.map +1 -1
  288. package/dist/scaffold.js +154 -90
  289. package/dist/scaffold.js.map +1 -1
  290. package/dist/sdk.d.ts +17 -3
  291. package/dist/sdk.d.ts.map +1 -1
  292. package/dist/sdk.js +941 -153
  293. package/dist/sdk.js.map +1 -1
  294. package/dist/search-terms.d.ts +2 -0
  295. package/dist/search-terms.d.ts.map +1 -1
  296. package/dist/search-terms.js +23 -8
  297. package/dist/search-terms.js.map +1 -1
  298. package/dist/smoke.d.ts +79 -0
  299. package/dist/smoke.d.ts.map +1 -0
  300. package/dist/smoke.js +494 -0
  301. package/dist/smoke.js.map +1 -0
  302. package/dist/sync-manifest.d.ts.map +1 -1
  303. package/dist/sync-manifest.js +2 -1
  304. package/dist/sync-manifest.js.map +1 -1
  305. package/dist/sync-routes.d.ts +4 -3
  306. package/dist/sync-routes.d.ts.map +1 -1
  307. package/dist/sync-routes.js +4 -3
  308. package/dist/sync-routes.js.map +1 -1
  309. package/dist/test-tool.d.ts.map +1 -1
  310. package/dist/test-tool.js +30 -11
  311. package/dist/test-tool.js.map +1 -1
  312. package/dist/types-search.d.ts.map +1 -1
  313. package/dist/types-search.js +11 -5
  314. package/dist/types-search.js.map +1 -1
  315. package/dist/upgrade.d.ts +36 -6
  316. package/dist/upgrade.d.ts.map +1 -1
  317. package/dist/upgrade.js +167 -29
  318. package/dist/upgrade.js.map +1 -1
  319. package/dist/verification-plan.d.ts.map +1 -1
  320. package/dist/verification-plan.js +8 -0
  321. package/dist/verification-plan.js.map +1 -1
  322. package/dist/verification.d.ts.map +1 -1
  323. package/dist/verification.js +45 -12
  324. package/dist/verification.js.map +1 -1
  325. package/dist/web-app-options.d.ts +19 -0
  326. package/dist/web-app-options.d.ts.map +1 -0
  327. package/dist/web-app-options.js +49 -0
  328. package/dist/web-app-options.js.map +1 -0
  329. package/dist/work-graph.d.ts +3 -0
  330. package/dist/work-graph.d.ts.map +1 -1
  331. package/dist/work-graph.js +33 -16
  332. package/dist/work-graph.js.map +1 -1
  333. package/docs/examples.json +185 -29
  334. package/docs/llms-full.txt +4123 -548
  335. package/docs/types.json +14391 -10060
  336. package/package.json +19 -11
  337. package/src/app-files.ts +40 -0
  338. package/src/assure-hydration.ts +139 -46
  339. package/src/assure.ts +17 -2
  340. package/src/capabilities-tool.ts +35 -9
  341. package/src/cdn-check.ts +268 -0
  342. package/src/check-diagnostics.ts +199 -797
  343. package/src/check-scan.ts +394 -63
  344. package/src/check.ts +146 -58
  345. package/src/cli.ts +347 -92
  346. package/src/command-catalog.ts +407 -45
  347. package/src/config-target.ts +47 -0
  348. package/src/contracts.ts +66 -15
  349. package/src/db-audit.ts +128 -0
  350. package/src/db-child.ts +285 -0
  351. package/src/db-config.ts +224 -0
  352. package/src/db-tool.ts +690 -0
  353. package/src/dev-bun-config.ts +116 -40
  354. package/src/dev-feed-tool.ts +912 -0
  355. package/src/dev-server-client.ts +267 -0
  356. package/src/diagnostics.ts +179 -0
  357. package/src/diff-tool.ts +6 -5
  358. package/src/docs-search.ts +10 -3
  359. package/src/doctor.ts +98 -15
  360. package/src/env-file.ts +78 -1
  361. package/src/fix-recipes.ts +44 -31
  362. package/src/frontend-guidance.ts +5 -5
  363. package/src/i18n-check.ts +179 -0
  364. package/src/init-agents.ts +301 -38
  365. package/src/internal/code-unit-order.ts +5 -0
  366. package/src/internal/script-kind.ts +11 -0
  367. package/src/internal/source-facts.ts +96 -22
  368. package/src/internal/typescript-import.ts +663 -68
  369. package/src/introspect.ts +93 -82
  370. package/src/learn.ts +3 -3
  371. package/src/levels-tool.ts +47 -2
  372. package/src/load.ts +144 -32
  373. package/src/manifest-tool.ts +3 -2
  374. package/src/mcp-app-tool.ts +2 -0
  375. package/src/mcp-context.ts +5 -7
  376. package/src/mcp-delegate.ts +162 -0
  377. package/src/mcp-docs-tools.ts +23 -5
  378. package/src/mcp-exec.ts +301 -161
  379. package/src/mcp-http.ts +22 -5
  380. package/src/mcp-io.ts +130 -0
  381. package/src/mcp-isolate.ts +287 -0
  382. package/src/mcp-path.ts +50 -0
  383. package/src/mcp-project-child.ts +182 -0
  384. package/src/mcp-reflect.ts +3 -2
  385. package/src/mcp-render.ts +72 -42
  386. package/src/mcp-root.ts +130 -24
  387. package/src/mcp-run.ts +190 -56
  388. package/src/mcp-ws.ts +4 -1
  389. package/src/mcp.ts +193 -91
  390. package/src/migrate-layout.ts +1121 -0
  391. package/src/openapi-tool.ts +7 -3
  392. package/src/openapi-types.ts +315 -13
  393. package/src/pipeline-report.ts +22 -18
  394. package/src/port.ts +53 -30
  395. package/src/project-facts.ts +42 -8
  396. package/src/recipes/4.0.0.ts +35 -0
  397. package/src/recipes/index.ts +2 -0
  398. package/src/release-verification.ts +74 -5
  399. package/src/review.ts +988 -0
  400. package/src/route-types.ts +133 -0
  401. package/src/rules/codes.ts +9 -0
  402. package/src/rules/data-guard.ts +230 -0
  403. package/src/rules/index.ts +18 -5
  404. package/src/rules/islands.ts +12 -4
  405. package/src/rules/legacy.ts +947 -35
  406. package/src/rules/nano.ts +18 -6
  407. package/src/rules/pages.ts +99 -0
  408. package/src/rules/routes.ts +181 -2
  409. package/src/rules/secrets.ts +174 -0
  410. package/src/rules/security.ts +198 -70
  411. package/src/rules/typescript.ts +77 -0
  412. package/src/rules/zones.ts +195 -0
  413. package/src/scaffold.ts +175 -98
  414. package/src/sdk.ts +1215 -158
  415. package/src/search-terms.ts +24 -7
  416. package/src/smoke.ts +607 -0
  417. package/src/sync-manifest.ts +2 -1
  418. package/src/sync-routes.ts +4 -3
  419. package/src/test-tool.ts +32 -11
  420. package/src/types-search.ts +11 -4
  421. package/src/upgrade.ts +205 -25
  422. package/src/verification-plan.ts +27 -0
  423. package/src/verification.ts +50 -12
  424. package/src/web-app-options.ts +57 -0
  425. package/src/work-graph.ts +40 -16
package/src/scaffold.ts CHANGED
@@ -1,17 +1,19 @@
1
1
  /**
2
- * `nifra_scaffold` - turn a URL path into the correct `routes/` file (the convention an agent most often
3
- * gets wrong) + a minimal, contract-correct stub. The mapping is the inverse of @nifrajs/web's
4
- * `filePathToPatterns`: `:id`/`[id]` → `[id]`, `*rest`/`[...rest]` → `[...rest]`, `[[lang]]` optional,
5
- * `/` → `index`. The framework (→ file extension) comes from the project's `clientModule`.
2
+ * `nifra_scaffold` - turn a URL path into the correct `routes/` files (the convention an agent most often
3
+ * gets wrong) + a minimal, contract-correct route pair: the page, and its `.backend.ts` half holding the
4
+ * loader and its output schema. The mapping is the inverse of @nifrajs/web's `filePathToPatterns`:
5
+ * `:id`/`[id]` → `[id]`, `*rest`/`[...rest]` → `[...rest]`, `[[lang]]` optional, `/` → `index`. The
6
+ * framework (→ file extension) comes from the project's `clientModule`.
6
7
  *
7
8
  * Page stubs are emitted for the JSX family (react/preact/solid - one shared, verified shape) and
8
9
  * for vanilla (a zero-runtime `html` page carrying the golden island pattern); for vue/svelte we
9
- * return the correct PATH + the route-module contract and point at `nifra_example` for the body,
10
- * rather than hand-writing an SFC we can't typecheck here.
10
+ * return the correct PATHS, the backend half and the route contract, and point at `nifra_example` for
11
+ * the page body, rather than hand-writing an SFC we can't typecheck here.
11
12
  */
12
13
 
13
14
  import { lstat, mkdir, realpath, writeFile } from "node:fs/promises"
14
- import { dirname, resolve, sep } from "node:path"
15
+ import { basename, dirname, resolve, sep } from "node:path"
16
+ import { paramConstraint } from "@nifrajs/core/pattern"
15
17
 
16
18
  export type Framework = "react" | "preact" | "solid" | "vue" | "svelte" | "vanilla"
17
19
 
@@ -45,11 +47,41 @@ function segmentToFile(seg: string): string {
45
47
  return seg
46
48
  }
47
49
 
50
+ /** Reject syntax that could be interpreted by the host filesystem rather than the route mapper. */
51
+ function assertSafeRouteSegment(segment: string, urlPath: string): void {
52
+ if (segment === "." || segment === ".." || segment.includes("\0") || segment.includes("\\")) {
53
+ throw new Error(
54
+ `invalid route segment in ${JSON.stringify(urlPath)}: ${JSON.stringify(segment)}`,
55
+ )
56
+ }
57
+ const brace = segment.indexOf("{")
58
+ if (segment.startsWith(":") && brace > 0 && paramConstraint(segment.slice(brace)) !== undefined) {
59
+ throw new Error(
60
+ `a param constraint cannot be written in a route file name: ${JSON.stringify(segment)} in ${JSON.stringify(urlPath)}. Scaffold the page without it and check the value in the route's loader.`,
61
+ )
62
+ }
63
+ const fileSegment = segmentToFile(segment)
64
+ if (
65
+ fileSegment === "." ||
66
+ fileSegment === ".." ||
67
+ fileSegment.includes("\0") ||
68
+ fileSegment.includes("/") ||
69
+ fileSegment.includes("\\") ||
70
+ fileSegment.includes(":") ||
71
+ /^[A-Za-z]:/.test(fileSegment)
72
+ ) {
73
+ throw new Error(
74
+ `invalid route segment in ${JSON.stringify(urlPath)}: ${JSON.stringify(segment)}`,
75
+ )
76
+ }
77
+ }
78
+
48
79
  /** Map a URL path to its `routes/` file path (relative to `routes/`, without extension prefix dir).
49
80
  * `/` → `index`; `/users/:id` → `users/[id]`; `/blog/*slug` → `blog/[...slug]`. */
50
81
  export function routePathToFile(urlPath: string, ext: string): string {
51
82
  const segments = urlPath.split("/").filter((s) => s.length > 0)
52
83
  if (segments.length === 0) return `routes/index.${ext}`
84
+ for (const segment of segments) assertSafeRouteSegment(segment, urlPath)
53
85
  const last = segments.length - 1
54
86
  // Catch-all must be the final segment (mirrors @nifrajs/web); flag it rather than emit an invalid file.
55
87
  for (let i = 0; i < last; i++) {
@@ -59,25 +91,69 @@ export function routePathToFile(urlPath: string, ext: string): string {
59
91
  return `routes/${segments.map(segmentToFile).join("/")}.${ext}`
60
92
  }
61
93
 
62
- const ROUTE_CONTRACT = `A route module may export:
63
- - \`export default function Page(props: { data: LoaderData<typeof loader> }) { … }\` - the page component.
64
- - \`export async function loader({ params, request, api }: LoaderArgs<typeof backend>) { … }\` - server-only; data for SSR. Reach the backend via \`api\` (typed) / DB via the backend, NEVER a top-level server-only import.
65
- - \`export async function action({ request, api }: ActionArgs<typeof backend>) { … }\` - server-only; handles the form POST.
66
- - \`export const meta = { title, meta:[…] }\` - head tags.
67
- Path params are typed on \`params\`.`
68
-
69
- function jsxStub(file: string, params: string[]): string {
70
- const paramsNote =
71
- params.length > 0 ? `params.${params.join(", params.")}` : "no path params on this route"
72
- const loaderLine =
73
- params.length > 0
74
- ? `// export async function loader({ params, api }: LoaderArgs<typeof backend>) { return { /* fetch by ${params[0]} */ } }`
75
- : `// export async function loader({ api }: LoaderArgs<typeof backend>) { return {} }`
76
- return `// ${file} - server-only loader/action allowed; never top-level-import server-only code (DB/secrets).
77
- // Available here: ${paramsNote}. Fetch data in a loader via the typed \`api\`; see nifra_example("loader").
78
- ${loaderLine}
79
- export default function Page() {
80
- return <main>TODO: ${file}</main>
94
+ const ROUTE_CONTRACT = `A route is two files:
95
+ - The page, \`routes/x.<ext>\` - ships to the browser: \`export default function Page({ data }: Route.ComponentProps)\` and \`export const meta = { title, meta: […] }\`. It never imports backend code.
96
+ - Its backend half, \`routes/x.backend.ts\` - never reaches the browser: \`export const loaderOutput = t.object({…})\` with \`export async function loader({ params, api }: Route.LoaderArgs)\` (data for SSR - only what the schema declares is sent), \`actionOutput\` with \`action\` (the form POST), and \`hydrate\`, \`islandScripts\`, \`revalidate\`, \`middleware\`. Reach the backend through the typed \`api\`.
97
+ Both import \`type { Route } from "./+types/<name>"\`, which \`nifra dev\`, \`nifra build\`, \`nifra check\` and \`nifra types\` generate. Path params are typed on \`params\`.`
98
+
99
+ interface RouteParam {
100
+ readonly name: string
101
+ readonly optional: boolean
102
+ }
103
+
104
+ /** Param names a route file declares, for the stubs. */
105
+ function paramsOf(file: string): RouteParam[] {
106
+ const out: RouteParam[] = []
107
+ for (const m of file.matchAll(/(\[)?\[(?:\.\.\.)?([A-Za-z_][A-Za-z0-9_]*)\]/g))
108
+ out.push({ name: m[2] as string, optional: m[1] !== undefined })
109
+ return out
110
+ }
111
+
112
+ /** `./+types/<name>` for a route file: the generated module both halves import `Route` from. */
113
+ const typesOf = (file: string): string => `./+types/${basename(file).replace(/\.[^.]+$/, "")}`
114
+
115
+ /** `routes/users/[id].tsx` → `routes/users/[id].backend.ts`. */
116
+ export const backendFileOf = (file: string): string => file.replace(/\.[^./]+$/, ".backend.ts")
117
+
118
+ /** The page's backend half: its loader, and the schema that bounds what the loader sends. */
119
+ function backendStub(file: string, params: readonly RouteParam[], vanilla: boolean): string {
120
+ const last = params.at(-1)
121
+ const loader =
122
+ last === undefined
123
+ ? `export async function loader(_args: Route.LoaderArgs) {
124
+ // Load through the typed backend client, \`api\` in these args; see nifra_example("loader").
125
+ return { title: "TODO" }
126
+ }`
127
+ : `export async function loader({ params }: Route.LoaderArgs) {
128
+ // Load by params.${last.name} through the typed backend client, \`api\` in these args; see nifra_example("loader").
129
+ return { title: \`TODO: \${params.${last.name}${last.optional ? ' ?? ""' : ""}}\` }
130
+ }`
131
+ const vanillaExports = vanilla
132
+ ? `
133
+
134
+ // No client framework to hydrate with - vanilla routes are documents, not hydrated apps.
135
+ export const hydrate = false
136
+
137
+ // The built URL of each island enhancer this page renders a marker for (./<name>.client.ts).
138
+ // export const islandScripts = []`
139
+ : ""
140
+ return `// ${backendFileOf(file)} - the server half of ${file}; it never reaches the browser.
141
+ import { t } from "@nifrajs/schema"
142
+ import type { Route } from "${typesOf(file)}"
143
+
144
+ // Only what this schema declares is sent to the page.
145
+ export const loaderOutput = t.object({ title: t.string() })
146
+
147
+ ${loader}${vanillaExports}
148
+ `
149
+ }
150
+
151
+ function jsxStub(file: string): string {
152
+ return `// ${file} - the page; it ships to the browser. Its data comes from ${basename(backendFileOf(file))}.
153
+ import type { Route } from "${typesOf(file)}"
154
+
155
+ export default function Page({ data }: Route.ComponentProps) {
156
+ return <main>{data.title}</main>
81
157
  }
82
158
  `
83
159
  }
@@ -89,29 +165,20 @@ export default function Page() {
89
165
  * returns its cleanup (the one thing NF-C020 checks), wired through `mountIslands`. Interactivity is
90
166
  * added by uncommenting and writing the companion `<name>.client.ts`, never by turning on hydration.
91
167
  */
92
- function vanillaStub(file: string, params: string[]): string {
93
- const paramsNote =
94
- params.length > 0 ? `params.${params.join(", params.")}` : "no path params on this route"
95
- const loaderLine =
96
- params.length > 0
97
- ? `// export async function loader({ params, api }: LoaderArgs<typeof backend>) { return { /* fetch by ${params[0]} */ } }`
98
- : `// export async function loader({ api }: LoaderArgs<typeof backend>) { return {} }`
99
- return `// ${file} - @nifrajs/web-vanilla route. Server-rendered HTML, ZERO framework runtime.
100
- // Available here: ${paramsNote}. Fetch data in a loader via the typed \`api\`; see nifra_example("loader").
168
+ function vanillaStub(file: string): string {
169
+ return `// ${file} - @nifrajs/web-vanilla page. Server-rendered HTML, ZERO framework runtime; its data,
170
+ // and \`hydrate = false\`, live in ${basename(backendFileOf(file))}.
101
171
  import { html } from "@nifrajs/web-vanilla"
172
+ import type { Route } from "${typesOf(file)}"
102
173
 
103
- // No client framework to hydrate with - vanilla routes are documents, not hydrated apps.
104
- export const hydrate = false
105
-
106
- ${loaderLine}
107
-
108
- export default function Page() {
109
- return html\`<main><h1>TODO: ${file}</h1></main>\`
174
+ export default function Page({ data }: Route.ComponentProps) {
175
+ return html\`<main><h1>\${data.title}</h1></main>\`
110
176
  }
111
177
 
112
178
  // --- Add interactivity the AI-safe way (islands), NOT hydration ---------------------------------
113
179
  // 1. Render a marker in the page above: html\`<nifra-island data-id="counter" data-props=\${JSON.stringify({ start: 0 })}></nifra-island>\`
114
- // 2. Wire the route to its enhancer bundle: export const islandScripts = [/* built URL of ./counter.client.ts */]
180
+ // 2. Wire the route to its enhancer bundle, in ${basename(backendFileOf(file))}:
181
+ // export const islandScripts = [/* built URL of ./counter.client.ts */]
115
182
  // 3. Write ./counter.client.ts as an imperative enhancer that ALWAYS returns its cleanup:
116
183
  //
117
184
  // import { defineIsland, mountIslands } from "@nifrajs/web/islands"
@@ -140,33 +207,21 @@ export default function Page() {
140
207
  * The page body is a valid, typecheckable static document; interactivity is added by writing the
141
208
  * companion client shown, never by turning on hydration.
142
209
  */
143
- function nanoStub(file: string, params: string[]): string {
144
- const paramsNote =
145
- params.length > 0 ? `params.${params.join(", params.")}` : "no path params on this route"
146
- const loaderLine =
147
- params.length > 0
148
- ? `// export async function loader({ params, api }: LoaderArgs<typeof backend>) { return { /* seed by ${params[0]} */ } }`
149
- : `// export async function loader({ api }: LoaderArgs<typeof backend>) { return {} }`
150
- return `// ${file} - @nifrajs/web-vanilla route + a nano island (explicit reactivity, zero VDOM).
151
- // Available here: ${paramsNote}. Seed data in a loader via the typed \`api\`; see nifra_example("loader").
210
+ function nanoStub(file: string): string {
211
+ return `// ${file} - @nifrajs/web-vanilla page + a nano island (explicit reactivity, zero VDOM). The
212
+ // document is static and the nano client below owns all interactivity; \`hydrate = false\` and the
213
+ // island's \`islandScripts\` URL live in ${basename(backendFileOf(file))}.
152
214
  import { html } from "@nifrajs/web-vanilla"
215
+ import type { Route } from "${typesOf(file)}"
153
216
 
154
- // The document is static; the nano client below owns all interactivity. No hydration.
155
- export const hydrate = false
156
-
157
- ${loaderLine}
158
-
159
- export default function Page() {
217
+ export default function Page({ data }: Route.ComponentProps) {
160
218
  // The island marker: data-props is the initial state the client reads on mount.
161
219
  return html\`<main>
162
- <h1>Todos</h1>
220
+ <h1>\${data.title}</h1>
163
221
  <nifra-island data-id="todos" data-props=\${JSON.stringify({ items: [] })}></nifra-island>
164
222
  </main>\`
165
223
  }
166
224
 
167
- // Wire the route to the built URL of ./todos.client.ts (the nano enhancer below).
168
- // export const islandScripts = [/* built URL of ./todos.client.ts */]
169
-
170
225
  // --- ./todos.client.ts - the golden nano pattern (write this as a companion file) -----------------
171
226
  //
172
227
  // import { defineIsland, mountIslands } from "@nifrajs/web/islands"
@@ -210,17 +265,13 @@ export default function Page() {
210
265
  `
211
266
  }
212
267
 
213
- /** Param names a route file declares, for the stub's notes. */
214
- function paramsOf(file: string): string[] {
215
- const out: string[] = []
216
- for (const m of file.matchAll(/\[(?:\.\.\.)?([A-Za-z_][A-Za-z0-9_]*)\]/g))
217
- out.push(m[1] as string)
218
- return out
219
- }
220
-
221
268
  export interface ScaffoldResult {
269
+ /** The page file. */
222
270
  readonly file: string
271
+ /** The page stub, when there is a verified one for the framework. */
223
272
  readonly content?: string
273
+ /** The page's backend half - framework-independent, so always present. */
274
+ readonly backend: { readonly file: string; readonly content: string }
224
275
  readonly note: string
225
276
  }
226
277
 
@@ -229,8 +280,9 @@ export interface ScaffoldWriteResult extends ScaffoldResult {
229
280
  readonly reason?: string
230
281
  }
231
282
 
232
- /** Scaffold a page route for `urlPath` under the project's `framework`. Returns the correct file path
233
- * always; a ready-to-write stub for the JSX family, contract guidance otherwise. */
283
+ /** Scaffold a page route for `urlPath` under the project's `framework`. Returns the correct file paths
284
+ * and the backend half always; a ready-to-write page stub for the JSX family and vanilla, contract
285
+ * guidance otherwise. */
234
286
  export function scaffoldRoute(
235
287
  urlPath: string,
236
288
  framework: Framework,
@@ -239,40 +291,49 @@ export function scaffoldRoute(
239
291
  const ext = EXT[framework]
240
292
  const file = routePathToFile(urlPath, ext)
241
293
  const params = paramsOf(file)
294
+ const backend = {
295
+ file: backendFileOf(file),
296
+ content: backendStub(file, params, framework === "vanilla"),
297
+ }
242
298
  // `stateful` is vanilla-only: it swaps the static island stub for the nano golden pattern. Asking
243
299
  // for it on a JSX/SFC framework is a no-op on the flavour (those lanes have their own reactivity).
244
300
  if (framework === "vanilla" && variant === "stateful") {
245
301
  return {
246
302
  file,
247
- content: nanoStub(file, params),
248
- note: `Create ${file} as a zero-runtime @nifrajs/web-vanilla route with a nano island. ${ROUTE_CONTRACT}\nThe stub embeds the golden nano client (signal + computed(fn,[deps]) + keyed bindList + collected cleanups); write it as the companion .client.ts. \`nifra check\` runs NF-C021/C022/C023 over it; nifra_docs("nano") is the full cookbook.`,
303
+ content: nanoStub(file),
304
+ backend,
305
+ note: `Create ${file} and ${backend.file} as a zero-runtime @nifrajs/web-vanilla route with a nano island. ${ROUTE_CONTRACT}\nThe stub embeds the golden nano client (signal + computed(fn,[deps]) + keyed bindList + collected cleanups); write it as the companion .client.ts. \`nifra check\` runs NF-C021/C022/C023 over it; nifra_docs("nano") is the full cookbook.`,
249
306
  }
250
307
  }
251
308
  if (framework === "react" || framework === "preact" || framework === "solid") {
252
309
  return {
253
310
  file,
254
- content: jsxStub(file, params),
255
- note: `Create ${file}. ${ROUTE_CONTRACT}\nIf the rendered page misbehaves (hydration warning, a value that stops updating), call nifra_frontend { adapter: "${framework}" } for the cause + fix.`,
311
+ content: jsxStub(file),
312
+ backend,
313
+ note: `Create ${file} and ${backend.file}. ${ROUTE_CONTRACT}\nIf the rendered page misbehaves (hydration warning, a value that stops updating), call nifra_frontend { adapter: "${framework}" } for the cause + fix.`,
256
314
  }
257
315
  }
258
316
  if (framework === "vanilla") {
259
317
  return {
260
318
  file,
261
- content: vanillaStub(file, params),
262
- note: `Create ${file} as a zero-runtime @nifrajs/web-vanilla route. ${ROUTE_CONTRACT}\nInteractivity comes from islands (imperative enhancers), never hydration - the stub embeds the golden pattern; nifra_example("islands") has the full cookbook. For explicit local state (a list a human edits), scaffold with variant "stateful" to get the nano pattern instead.`,
319
+ content: vanillaStub(file),
320
+ backend,
321
+ note: `Create ${file} and ${backend.file} as a zero-runtime @nifrajs/web-vanilla route. ${ROUTE_CONTRACT}\nInteractivity comes from islands (imperative enhancers), never hydration - the stub embeds the golden pattern; nifra_example("islands") has the full cookbook. For explicit local state (a list a human edits), scaffold with variant "stateful" to get the nano pattern instead.`,
263
322
  }
264
323
  }
265
324
  return {
266
325
  file,
267
- note: `Create ${file} as a ${framework} route module. ${ROUTE_CONTRACT}\nFor the ${framework} page body, call nifra_example (it ships verified ${framework} snippets) rather than guessing the SFC shape. If a value stops updating the template, call nifra_frontend { adapter: "${framework}" } for the ${framework} reactivity-loss fix.`,
326
+ backend,
327
+ note: `Create ${file} as a ${framework} route module, and ${backend.file} from the stub below. ${ROUTE_CONTRACT}\nFor the ${framework} page body, call nifra_example (it ships verified ${framework} snippets) rather than guessing the SFC shape. If a value stops updating the template, call nifra_frontend { adapter: "${framework}" } for the ${framework} reactivity-loss fix.`,
268
328
  }
269
329
  }
270
330
 
271
- function resolveInsideCwd(cwd: string, relativeFile: string): string {
331
+ function resolveInsideRoutes(cwd: string, relativeFile: string): string {
272
332
  const root = resolve(cwd)
333
+ const routesRoot = resolve(root, "routes")
273
334
  const target = resolve(root, relativeFile)
274
- if (target !== root && !target.startsWith(`${root}${sep}`)) {
275
- throw new Error(`refusing to write outside project root: ${relativeFile}`)
335
+ if (target === routesRoot || !target.startsWith(`${routesRoot}${sep}`)) {
336
+ throw new Error(`refusing to write outside routes directory: ${relativeFile}`)
276
337
  }
277
338
  return target
278
339
  }
@@ -308,9 +369,11 @@ async function assertNoSymlinkedAncestors(root: string, target: string): Promise
308
369
  }
309
370
  }
310
371
 
311
- /** Write a scaffolded route stub when the framework has a verified ready-to-write body. The write is
312
- * intentionally conservative: it refuses non-JSX stubs (where we only return contract guidance) and
313
- * uses `wx`, so an agent cannot overwrite user work by accident. */
372
+ /** Write a scaffolded route pair when the framework has a verified ready-to-write page body. The write
373
+ * is intentionally conservative: it refuses frameworks where we only return contract guidance (a
374
+ * backend half alone is a build error), refuses when either file exists, and uses `wx`, so an agent
375
+ * cannot overwrite user work by accident. It then generates the route's `./+types` module, so both
376
+ * halves typecheck at once. */
314
377
  export async function writeScaffoldRoute(
315
378
  cwd: string,
316
379
  urlPath: string,
@@ -325,22 +388,35 @@ export async function writeScaffoldRoute(
325
388
  reason: "no verified ready-to-write stub for this framework; use nifra_example for the body",
326
389
  }
327
390
  }
328
- const target = resolveInsideCwd(cwd, result.file)
329
- await assertNoSymlinkedAncestors(cwd, target)
330
- await mkdir(dirname(target), { recursive: true })
331
- await assertNoSymlinkedAncestors(cwd, target)
332
- try {
333
- await writeFile(target, result.content, { flag: "wx" })
334
- } catch (err) {
335
- if (err && typeof err === "object" && (err as { code?: string }).code === "EEXIST") {
336
- return { ...result, written: false, reason: `file already exists: ${result.file}` }
391
+ const files = [
392
+ { file: result.file, content: result.content },
393
+ { file: result.backend.file, content: result.backend.content },
394
+ ]
395
+ const targets = files.map(({ file }) => resolveInsideRoutes(cwd, file))
396
+ for (const target of targets) await assertNoSymlinkedAncestors(cwd, target)
397
+ for (const [i, target] of targets.entries()) {
398
+ if ((await lstat(target).catch(() => undefined)) !== undefined) {
399
+ return { ...result, written: false, reason: `file already exists: ${files[i]?.file}` }
400
+ }
401
+ }
402
+ await mkdir(dirname(targets[0] as string), { recursive: true })
403
+ for (const target of targets) await assertNoSymlinkedAncestors(cwd, target)
404
+ for (const [i, target] of targets.entries()) {
405
+ try {
406
+ await writeFile(target, files[i]?.content ?? "", { flag: "wx" })
407
+ } catch (err) {
408
+ if (err && typeof err === "object" && (err as { code?: string }).code === "EEXIST") {
409
+ return { ...result, written: false, reason: `file already exists: ${files[i]?.file}` }
410
+ }
411
+ throw err
337
412
  }
338
- throw err
339
413
  }
414
+ const { refreshRouteTypes } = await import("./route-types.ts")
415
+ refreshRouteTypes(cwd, () => {})
340
416
  return { ...result, written: true }
341
417
  }
342
418
 
343
- /** Render the tool result as markdown - the file path, the stub (if any), and the contract note. */
419
+ /** Render the tool result as markdown - the file paths, the stubs (if any), and the contract note. */
344
420
  export function renderScaffold(
345
421
  urlPath: string,
346
422
  framework: Framework,
@@ -352,6 +428,7 @@ export function renderScaffold(
352
428
  } catch (err) {
353
429
  return `Cannot scaffold ${JSON.stringify(urlPath)}: ${err instanceof Error ? err.message : String(err)}`
354
430
  }
355
- const stub = r.content ? `\n\n\`\`\`${EXT[framework]}\n${r.content}\`\`\`` : ""
356
- return `# Scaffold route \`${urlPath}\` (${framework})\n\n**File:** \`${r.file}\`\n\n${r.note}${stub}`
431
+ const page = r.content ? `\n\n\`${r.file}\`:\n\n\`\`\`${EXT[framework]}\n${r.content}\`\`\`` : ""
432
+ const backend = `\n\n\`${r.backend.file}\`:\n\n\`\`\`ts\n${r.backend.content}\`\`\``
433
+ return `# Scaffold route \`${urlPath}\` (${framework})\n\n**Files:** \`${r.file}\` + \`${r.backend.file}\`\n\n${r.note}${page}${backend}`
357
434
  }