@nifrajs/cli 5.0.0 → 5.2.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 (296) hide show
  1. package/CHANGELOG.md +3211 -0
  2. package/README.md +10 -2
  3. package/dist/agent-files.d.ts +19 -11
  4. package/dist/agent-files.d.ts.map +1 -1
  5. package/dist/agent-files.js +26 -18
  6. package/dist/agent-files.js.map +1 -1
  7. package/dist/assure-hydration.d.ts.map +1 -1
  8. package/dist/assure-hydration.js +5 -2
  9. package/dist/assure-hydration.js.map +1 -1
  10. package/dist/assure.d.ts +12 -2
  11. package/dist/assure.d.ts.map +1 -1
  12. package/dist/assure.js +73 -9
  13. package/dist/assure.js.map +1 -1
  14. package/dist/capabilities-tool.d.ts.map +1 -1
  15. package/dist/capabilities-tool.js +152 -49
  16. package/dist/capabilities-tool.js.map +1 -1
  17. package/dist/check-diagnostics.d.ts +7 -0
  18. package/dist/check-diagnostics.d.ts.map +1 -1
  19. package/dist/check-diagnostics.js +3 -0
  20. package/dist/check-diagnostics.js.map +1 -1
  21. package/dist/check-scan.d.ts +8 -2
  22. package/dist/check-scan.d.ts.map +1 -1
  23. package/dist/check-scan.js +49 -13
  24. package/dist/check-scan.js.map +1 -1
  25. package/dist/check.d.ts.map +1 -1
  26. package/dist/check.js +91 -45
  27. package/dist/check.js.map +1 -1
  28. package/dist/cli.d.ts +2 -0
  29. package/dist/cli.d.ts.map +1 -1
  30. package/dist/cli.js +128 -59
  31. package/dist/cli.js.map +1 -1
  32. package/dist/client-module.d.ts +5 -3
  33. package/dist/client-module.d.ts.map +1 -1
  34. package/dist/client-module.js +34 -10
  35. package/dist/client-module.js.map +1 -1
  36. package/dist/command-catalog.d.ts +9 -1
  37. package/dist/command-catalog.d.ts.map +1 -1
  38. package/dist/command-catalog.js +75 -26
  39. package/dist/command-catalog.js.map +1 -1
  40. package/dist/dev-bun-config.d.ts +6 -3
  41. package/dist/dev-bun-config.d.ts.map +1 -1
  42. package/dist/dev-bun-config.js +13 -10
  43. package/dist/dev-bun-config.js.map +1 -1
  44. package/dist/dev-feed-tool.d.ts +19 -1
  45. package/dist/dev-feed-tool.d.ts.map +1 -1
  46. package/dist/dev-feed-tool.js +114 -0
  47. package/dist/dev-feed-tool.js.map +1 -1
  48. package/dist/doctor.d.ts +15 -1
  49. package/dist/doctor.d.ts.map +1 -1
  50. package/dist/doctor.js +79 -61
  51. package/dist/doctor.js.map +1 -1
  52. package/dist/fix-recipes.d.ts +2 -0
  53. package/dist/fix-recipes.d.ts.map +1 -1
  54. package/dist/fix-recipes.js +93 -12
  55. package/dist/fix-recipes.js.map +1 -1
  56. package/dist/i18n-check.d.ts +11 -1
  57. package/dist/i18n-check.d.ts.map +1 -1
  58. package/dist/i18n-check.js +170 -17
  59. package/dist/i18n-check.js.map +1 -1
  60. package/dist/init-agents.d.ts +60 -4
  61. package/dist/init-agents.d.ts.map +1 -1
  62. package/dist/init-agents.js +196 -33
  63. package/dist/init-agents.js.map +1 -1
  64. package/dist/internal/config-paths.d.ts +16 -0
  65. package/dist/internal/config-paths.d.ts.map +1 -0
  66. package/dist/internal/config-paths.js +124 -0
  67. package/dist/internal/config-paths.js.map +1 -0
  68. package/dist/internal/installed-package.d.ts +4 -0
  69. package/dist/internal/installed-package.d.ts.map +1 -0
  70. package/dist/internal/installed-package.js +17 -0
  71. package/dist/internal/installed-package.js.map +1 -0
  72. package/dist/internal/project-specifiers.d.ts +14 -1
  73. package/dist/internal/project-specifiers.d.ts.map +1 -1
  74. package/dist/internal/project-specifiers.js +63 -16
  75. package/dist/internal/project-specifiers.js.map +1 -1
  76. package/dist/internal/source-facts.d.ts +12 -1
  77. package/dist/internal/source-facts.d.ts.map +1 -1
  78. package/dist/internal/source-facts.js +117 -5
  79. package/dist/internal/source-facts.js.map +1 -1
  80. package/dist/internal/typescript-import.d.ts.map +1 -1
  81. package/dist/internal/typescript-import.js +5 -3
  82. package/dist/internal/typescript-import.js.map +1 -1
  83. package/dist/internal/workspace-packages.d.ts +22 -0
  84. package/dist/internal/workspace-packages.d.ts.map +1 -0
  85. package/dist/internal/workspace-packages.js +215 -0
  86. package/dist/internal/workspace-packages.js.map +1 -0
  87. package/dist/introspect.d.ts +9 -0
  88. package/dist/introspect.d.ts.map +1 -1
  89. package/dist/introspect.js +32 -1
  90. package/dist/introspect.js.map +1 -1
  91. package/dist/levels-tool.d.ts.map +1 -1
  92. package/dist/levels-tool.js +5 -8
  93. package/dist/levels-tool.js.map +1 -1
  94. package/dist/load.d.ts +9 -4
  95. package/dist/load.d.ts.map +1 -1
  96. package/dist/load.js +32 -3
  97. package/dist/load.js.map +1 -1
  98. package/dist/lock-links.d.ts +42 -0
  99. package/dist/lock-links.d.ts.map +1 -0
  100. package/dist/lock-links.js +144 -0
  101. package/dist/lock-links.js.map +1 -0
  102. package/dist/mcp-context.d.ts.map +1 -1
  103. package/dist/mcp-context.js +6 -21
  104. package/dist/mcp-context.js.map +1 -1
  105. package/dist/mcp-delegate.d.ts +2 -2
  106. package/dist/mcp-delegate.d.ts.map +1 -1
  107. package/dist/mcp-delegate.js +19 -7
  108. package/dist/mcp-delegate.js.map +1 -1
  109. package/dist/mcp-exec.d.ts +1 -0
  110. package/dist/mcp-exec.d.ts.map +1 -1
  111. package/dist/mcp-exec.js +13 -5
  112. package/dist/mcp-exec.js.map +1 -1
  113. package/dist/mcp-http.js +1 -1
  114. package/dist/mcp-io.d.ts +13 -0
  115. package/dist/mcp-io.d.ts.map +1 -1
  116. package/dist/mcp-io.js +23 -0
  117. package/dist/mcp-io.js.map +1 -1
  118. package/dist/mcp-path.d.ts +2 -1
  119. package/dist/mcp-path.d.ts.map +1 -1
  120. package/dist/mcp-path.js +9 -24
  121. package/dist/mcp-path.js.map +1 -1
  122. package/dist/mcp-root.d.ts +6 -4
  123. package/dist/mcp-root.d.ts.map +1 -1
  124. package/dist/mcp-root.js +12 -8
  125. package/dist/mcp-root.js.map +1 -1
  126. package/dist/mcp.d.ts.map +1 -1
  127. package/dist/mcp.js +40 -17
  128. package/dist/mcp.js.map +1 -1
  129. package/dist/migrate-layout.d.ts +41 -1
  130. package/dist/migrate-layout.d.ts.map +1 -1
  131. package/dist/migrate-layout.js +1729 -236
  132. package/dist/migrate-layout.js.map +1 -1
  133. package/dist/output-schemas.d.ts +34 -0
  134. package/dist/output-schemas.d.ts.map +1 -1
  135. package/dist/output-schemas.js +132 -21
  136. package/dist/output-schemas.js.map +1 -1
  137. package/dist/project-path.d.ts +6 -0
  138. package/dist/project-path.d.ts.map +1 -1
  139. package/dist/project-path.js +48 -14
  140. package/dist/project-path.js.map +1 -1
  141. package/dist/project-site.d.ts +7 -0
  142. package/dist/project-site.d.ts.map +1 -0
  143. package/dist/project-site.js +19 -0
  144. package/dist/project-site.js.map +1 -0
  145. package/dist/recipes/4.0.0.d.ts.map +1 -1
  146. package/dist/recipes/4.0.0.js +2 -0
  147. package/dist/recipes/4.0.0.js.map +1 -1
  148. package/dist/recipes/5.1.0.d.ts +9 -0
  149. package/dist/recipes/5.1.0.d.ts.map +1 -0
  150. package/dist/recipes/5.1.0.js +22 -0
  151. package/dist/recipes/5.1.0.js.map +1 -0
  152. package/dist/recipes/5.2.0.d.ts +10 -0
  153. package/dist/recipes/5.2.0.d.ts.map +1 -0
  154. package/dist/recipes/5.2.0.js +32 -0
  155. package/dist/recipes/5.2.0.js.map +1 -0
  156. package/dist/recipes/index.d.ts +3 -0
  157. package/dist/recipes/index.d.ts.map +1 -1
  158. package/dist/recipes/index.js +7 -0
  159. package/dist/recipes/index.js.map +1 -1
  160. package/dist/release-verification.d.ts +5 -0
  161. package/dist/release-verification.d.ts.map +1 -1
  162. package/dist/release-verification.js +14 -0
  163. package/dist/release-verification.js.map +1 -1
  164. package/dist/review.d.ts.map +1 -1
  165. package/dist/review.js +7 -0
  166. package/dist/review.js.map +1 -1
  167. package/dist/rule-explain.d.ts +26 -0
  168. package/dist/rule-explain.d.ts.map +1 -0
  169. package/dist/rule-explain.js +49 -0
  170. package/dist/rule-explain.js.map +1 -0
  171. package/dist/rules/codes.d.ts +5 -1
  172. package/dist/rules/codes.d.ts.map +1 -1
  173. package/dist/rules/codes.js +5 -1
  174. package/dist/rules/codes.js.map +1 -1
  175. package/dist/rules/contract-visibility.d.ts.map +1 -1
  176. package/dist/rules/contract-visibility.js +93 -21
  177. package/dist/rules/contract-visibility.js.map +1 -1
  178. package/dist/rules/data-guard.d.ts +6 -0
  179. package/dist/rules/data-guard.d.ts.map +1 -1
  180. package/dist/rules/data-guard.js +37 -0
  181. package/dist/rules/data-guard.js.map +1 -1
  182. package/dist/rules/explanations.d.ts +14 -0
  183. package/dist/rules/explanations.d.ts.map +1 -0
  184. package/dist/rules/explanations.js +316 -0
  185. package/dist/rules/explanations.js.map +1 -0
  186. package/dist/rules/legacy.d.ts.map +1 -1
  187. package/dist/rules/legacy.js +44 -2
  188. package/dist/rules/legacy.js.map +1 -1
  189. package/dist/rules/merge-auth.d.ts +12 -0
  190. package/dist/rules/merge-auth.d.ts.map +1 -0
  191. package/dist/rules/merge-auth.js +52 -0
  192. package/dist/rules/merge-auth.js.map +1 -0
  193. package/dist/rules/pages.d.ts +56 -3
  194. package/dist/rules/pages.d.ts.map +1 -1
  195. package/dist/rules/pages.js +412 -23
  196. package/dist/rules/pages.js.map +1 -1
  197. package/dist/rules/routes.d.ts +3 -2
  198. package/dist/rules/routes.d.ts.map +1 -1
  199. package/dist/rules/routes.js +4 -3
  200. package/dist/rules/routes.js.map +1 -1
  201. package/dist/rules/security.d.ts +3 -2
  202. package/dist/rules/security.d.ts.map +1 -1
  203. package/dist/rules/security.js +42 -11
  204. package/dist/rules/security.js.map +1 -1
  205. package/dist/rules/zones.d.ts.map +1 -1
  206. package/dist/rules/zones.js +34 -11
  207. package/dist/rules/zones.js.map +1 -1
  208. package/dist/stylex-migrate.d.ts.map +1 -1
  209. package/dist/stylex-migrate.js +127 -17
  210. package/dist/stylex-migrate.js.map +1 -1
  211. package/dist/test-tool.d.ts.map +1 -1
  212. package/dist/test-tool.js +3 -9
  213. package/dist/test-tool.js.map +1 -1
  214. package/dist/typecheck-coverage.d.ts +11 -0
  215. package/dist/typecheck-coverage.d.ts.map +1 -1
  216. package/dist/typecheck-coverage.js +50 -7
  217. package/dist/typecheck-coverage.js.map +1 -1
  218. package/dist/upgrade.d.ts +57 -6
  219. package/dist/upgrade.d.ts.map +1 -1
  220. package/dist/upgrade.js +247 -19
  221. package/dist/upgrade.js.map +1 -1
  222. package/dist/verification-plan.d.ts.map +1 -1
  223. package/dist/verification-plan.js +7 -2
  224. package/dist/verification-plan.js.map +1 -1
  225. package/dist/version-drift.d.ts.map +1 -1
  226. package/dist/version-drift.js +66 -3
  227. package/dist/version-drift.js.map +1 -1
  228. package/dist/web-app-options.d.ts +1 -1
  229. package/dist/web-app-options.d.ts.map +1 -1
  230. package/dist/web-app-options.js.map +1 -1
  231. package/docs/examples.json +21 -3
  232. package/docs/llms-full.txt +1083 -168
  233. package/docs/types.json +535 -112
  234. package/package.json +13 -12
  235. package/src/agent-files.ts +27 -17
  236. package/src/assure-hydration.ts +5 -1
  237. package/src/assure.ts +99 -11
  238. package/src/capabilities-tool.ts +188 -53
  239. package/src/check-diagnostics.ts +10 -0
  240. package/src/check-scan.ts +65 -12
  241. package/src/check.ts +122 -51
  242. package/src/cli.ts +127 -45
  243. package/src/client-module.ts +45 -9
  244. package/src/command-catalog.ts +92 -28
  245. package/src/dev-bun-config.ts +13 -9
  246. package/src/dev-feed-tool.ts +146 -1
  247. package/src/doctor.ts +102 -66
  248. package/src/fix-recipes.ts +101 -10
  249. package/src/i18n-check.ts +254 -18
  250. package/src/init-agents.ts +225 -44
  251. package/src/internal/config-paths.ts +154 -0
  252. package/src/internal/installed-package.ts +15 -0
  253. package/src/internal/project-specifiers.ts +78 -17
  254. package/src/internal/source-facts.ts +147 -5
  255. package/src/internal/typescript-import.ts +5 -3
  256. package/src/internal/workspace-packages.ts +218 -0
  257. package/src/introspect.ts +39 -1
  258. package/src/levels-tool.ts +7 -9
  259. package/src/load.ts +46 -4
  260. package/src/lock-links.ts +173 -0
  261. package/src/mcp-context.ts +5 -18
  262. package/src/mcp-delegate.ts +22 -10
  263. package/src/mcp-exec.ts +14 -4
  264. package/src/mcp-http.ts +1 -1
  265. package/src/mcp-io.ts +33 -0
  266. package/src/mcp-path.ts +8 -22
  267. package/src/mcp-root.ts +14 -8
  268. package/src/mcp.ts +48 -19
  269. package/src/migrate-layout.ts +1968 -245
  270. package/src/output-schemas.ts +179 -23
  271. package/src/project-path.ts +44 -13
  272. package/src/project-site.ts +18 -0
  273. package/src/recipes/4.0.0.ts +2 -0
  274. package/src/recipes/5.1.0.ts +23 -0
  275. package/src/recipes/5.2.0.ts +33 -0
  276. package/src/recipes/index.ts +7 -0
  277. package/src/release-verification.ts +20 -0
  278. package/src/review.ts +7 -0
  279. package/src/rule-explain.ts +75 -0
  280. package/src/rules/codes.ts +5 -1
  281. package/src/rules/contract-visibility.ts +118 -20
  282. package/src/rules/data-guard.ts +40 -0
  283. package/src/rules/explanations.ts +329 -0
  284. package/src/rules/legacy.ts +46 -2
  285. package/src/rules/merge-auth.ts +55 -0
  286. package/src/rules/pages.ts +486 -25
  287. package/src/rules/routes.ts +4 -3
  288. package/src/rules/security.ts +49 -11
  289. package/src/rules/zones.ts +33 -9
  290. package/src/stylex-migrate.ts +117 -17
  291. package/src/test-tool.ts +3 -9
  292. package/src/typecheck-coverage.ts +51 -6
  293. package/src/upgrade.ts +312 -19
  294. package/src/verification-plan.ts +15 -2
  295. package/src/version-drift.ts +68 -2
  296. package/src/web-app-options.ts +9 -1
@@ -17,7 +17,7 @@ import { cdnCheckSpec } from "./cdn-check.ts"
17
17
  import { type CheckResult, renderCheckReport } from "./check.ts"
18
18
  import type { ContractsLock } from "./contracts.ts"
19
19
  import { dbAuditSpec, dbQuerySpec, dbRoleSpec, dbSchemaSpec } from "./db-tool.ts"
20
- import { errorsSpec, logsSpec } from "./dev-feed-tool.ts"
20
+ import { errorsSpec, explainSpec, logsSpec } from "./dev-feed-tool.ts"
21
21
  import { type Diagnostic, diagnostic, normalizeSeverity, toSarifLog } from "./diagnostics.ts"
22
22
  import type { DoctorResult } from "./doctor.ts"
23
23
  import { type I18nCheckOutput, i18nCheckPassed, renderI18nCheck } from "./i18n-check.ts"
@@ -367,6 +367,8 @@ interface MigrateInput {
367
367
  readonly from?: "tailwind" | undefined
368
368
  readonly to?: "stylex" | undefined
369
369
  readonly write?: boolean | undefined
370
+ /** `migrate layout`: list the folders modules would leave in package.json zones instead. */
371
+ readonly zones?: boolean | undefined
370
372
  readonly json?: boolean | undefined
371
373
  readonly dir?: string | undefined
372
374
  }
@@ -395,6 +397,7 @@ interface TypesInput {
395
397
 
396
398
  interface SchemasInput {
397
399
  readonly write?: boolean | undefined
400
+ readonly check?: boolean | undefined
398
401
  readonly json?: boolean | undefined
399
402
  readonly dir?: string | undefined
400
403
  }
@@ -486,6 +489,8 @@ interface FixCommandOutput {
486
489
  /** Recipes that refused, with the reason. A recipe that cannot act says so here instead of
487
490
  * aborting the run or - worse - reporting nothing at all. */
488
491
  readonly failed: readonly { readonly code: string; readonly reason: string }[]
492
+ /** Findings whose recipe runs only when its code is named, because its change needs review. */
493
+ readonly skipped: readonly { readonly code: string; readonly reason: string }[]
489
494
  readonly diagnostics: readonly unknown[]
490
495
  }
491
496
  type MigrateCommandOutput =
@@ -751,13 +756,14 @@ const MIGRATE_SCHEMA = input<MigrateInput>(
751
756
  from: { type: "string", enum: ["tailwind"] },
752
757
  to: { type: "string", enum: ["stylex"] },
753
758
  write: { type: "boolean" },
759
+ zones: { type: "boolean" },
754
760
  json: { type: "boolean" },
755
761
  dir: { type: "string" },
756
762
  }),
757
763
  (value) => {
758
764
  const raw = withDir(record(value))
759
765
  const flags = {
760
- ...parseBooleanFlags(raw, ["write", "json"]),
766
+ ...parseBooleanFlags(raw, ["write", "zones", "json"]),
761
767
  ...(raw.dir === undefined ? {} : { dir: raw.dir }),
762
768
  }
763
769
  const kind = optionalString(raw.kind, "kind")
@@ -766,6 +772,7 @@ const MIGRATE_SCHEMA = input<MigrateInput>(
766
772
  throw new TypeError("the migration must be `layout` (or --from tailwind --to stylex)")
767
773
  return { kind, ...flags }
768
774
  }
775
+ if (raw.zones === true) throw new TypeError("--zones applies to `migrate layout` only")
769
776
  const from = optionalString(raw.from, "from")
770
777
  const to = optionalString(raw.to, "to")
771
778
  if (from !== "tailwind") throw new TypeError("from must be tailwind")
@@ -799,11 +806,16 @@ const TYPES_SCHEMA = input<TypesInput>(
799
806
  )
800
807
 
801
808
  const SCHEMAS_SCHEMA = input<SchemasInput>(
802
- objectSchema({ write: { type: "boolean" }, json: { type: "boolean" }, dir: { type: "string" } }),
809
+ objectSchema({
810
+ write: { type: "boolean" },
811
+ check: { type: "boolean" },
812
+ json: { type: "boolean" },
813
+ dir: { type: "string" },
814
+ }),
803
815
  (value) => {
804
816
  const raw = withDir(record(value))
805
817
  return {
806
- ...parseBooleanFlags(raw, ["write", "json"]),
818
+ ...parseBooleanFlags(raw, ["write", "check", "json"]),
807
819
  ...(raw.dir === undefined ? {} : { dir: raw.dir }),
808
820
  }
809
821
  },
@@ -1370,6 +1382,9 @@ const openApiSpec: CommandSpec<OpenApiInput, OpenApiCommandOutput> = {
1370
1382
  json: (out) => (out.format === "json" ? JSON.parse(out.text) : out.text),
1371
1383
  }
1372
1384
 
1385
+ // `render` cannot load doctor.ts, so each run's report is built beside its result.
1386
+ const doctorReports = new WeakMap<DoctorResult, readonly string[]>()
1387
+
1373
1388
  const doctorSpec: CommandSpec<DoctorInput, DoctorResult> = {
1374
1389
  name: "doctor",
1375
1390
  summary: "Find undeclared imports, duplicate identity installs, and pipeline readiness drift.",
@@ -1397,14 +1412,18 @@ const doctorSpec: CommandSpec<DoctorInput, DoctorResult> = {
1397
1412
  ...(value.strict === undefined ? {} : { strict: value.strict }),
1398
1413
  ...(ctx.cliVersion === undefined ? {} : { cliVersion: ctx.cliVersion }),
1399
1414
  }
1400
- return value.autoFix === true
1401
- ? mod.applyDoctorAutoFix(ctx.cwd, options)
1402
- : mod.collectDoctorResult(ctx.cwd, options)
1415
+ const result =
1416
+ value.autoFix === true
1417
+ ? await mod.applyDoctorAutoFix(ctx.cwd, options)
1418
+ : await mod.collectDoctorResult(ctx.cwd, options)
1419
+ doctorReports.set(result, mod.doctorReport(result, ctx.cliVersion))
1420
+ return result
1403
1421
  },
1404
- render: (out) => [
1405
- out.ok ? "✓ doctor passed" : "✖ doctor found issues",
1406
- ...out.findings.map((f) => ` ${f.file}:${f.line} ${f.package}`),
1407
- ],
1422
+ render: (out) =>
1423
+ doctorReports.get(out) ?? [
1424
+ out.ok ? "✓ doctor passed" : "✖ doctor found issues",
1425
+ ...out.findings.map((f) => ` ${f.file}:${f.line} ${f.package}`),
1426
+ ],
1408
1427
  success: (out) => out.ok,
1409
1428
  }
1410
1429
 
@@ -1418,6 +1437,7 @@ const fixSpec: CommandSpec<FixInput, FixCommandOutput> = {
1418
1437
  ok: { type: "boolean" },
1419
1438
  changed: { type: "array" },
1420
1439
  failed: { type: "array" },
1440
+ skipped: { type: "array" },
1421
1441
  diagnostics: { type: "array" },
1422
1442
  },
1423
1443
  required: ["ok", "diagnostics"],
@@ -1432,25 +1452,37 @@ const fixSpec: CommandSpec<FixInput, FixCommandOutput> = {
1432
1452
  },
1433
1453
  async run(value, ctx) {
1434
1454
  const { collectCheckResult } = await import("./check.ts")
1435
- const { applyDiagnosticRecipe } = await import("./fix-recipes.ts")
1455
+ const { applyDiagnosticRecipe, getFixRecipe } = await import("./fix-recipes.ts")
1436
1456
  const result = await collectCheckResult(ctx.cwd, {
1437
1457
  lintsOnly: true,
1438
1458
  ...(ctx.signal === undefined ? {} : { signal: ctx.signal }),
1439
1459
  })
1440
1460
  const changed: string[] = []
1441
1461
  const failed: { code: string; reason: string }[] = []
1442
- for (const diagnostic of result.structuredDiagnostics ?? [])
1443
- if (value.code === undefined || diagnostic.code === value.code)
1444
- // One recipe that cannot act must not cancel the others, and must not pass silently either:
1445
- // record why and keep going, so a run over many diagnostics still reports every outcome.
1446
- try {
1447
- changed.push(...(await applyDiagnosticRecipe(ctx.cwd, diagnostic)))
1448
- } catch (error) {
1449
- failed.push({
1462
+ const skipped: { code: string; reason: string }[] = []
1463
+ for (const diagnostic of result.structuredDiagnostics ?? []) {
1464
+ if (value.code !== undefined && diagnostic.code !== value.code) continue
1465
+ const recipe =
1466
+ diagnostic.fix?.recipe === undefined ? undefined : getFixRecipe(diagnostic.fix.recipe)
1467
+ if (value.code === undefined && recipe?.onlyWhenNamed === true) {
1468
+ if (!skipped.some((entry) => entry.code === diagnostic.code))
1469
+ skipped.push({
1450
1470
  code: diagnostic.code,
1451
- reason: error instanceof Error ? error.message : String(error),
1471
+ reason: `${recipe.description} Review the finding, then run \`nifra fix --code ${diagnostic.code}\`.`,
1452
1472
  })
1453
- }
1473
+ continue
1474
+ }
1475
+ // One recipe that cannot act must not cancel the others, and must not pass silently either:
1476
+ // record why and keep going, so a run over many diagnostics still reports every outcome.
1477
+ try {
1478
+ changed.push(...(await applyDiagnosticRecipe(ctx.cwd, diagnostic)))
1479
+ } catch (error) {
1480
+ failed.push({
1481
+ code: diagnostic.code,
1482
+ reason: error instanceof Error ? error.message : String(error),
1483
+ })
1484
+ }
1485
+ }
1454
1486
  const final = await collectCheckResult(ctx.cwd, {
1455
1487
  lintsOnly: true,
1456
1488
  ...(ctx.signal === undefined ? {} : { signal: ctx.signal }),
@@ -1459,6 +1491,7 @@ const fixSpec: CommandSpec<FixInput, FixCommandOutput> = {
1459
1491
  ok: final.ok,
1460
1492
  changed,
1461
1493
  failed,
1494
+ skipped,
1462
1495
  diagnostics: final.structuredDiagnostics ?? final.diagnostics,
1463
1496
  }
1464
1497
  },
@@ -1466,6 +1499,7 @@ const fixSpec: CommandSpec<FixInput, FixCommandOutput> = {
1466
1499
  out.ok ? "✓ fixes applied" : "✖ unresolved diagnostics remain",
1467
1500
  ...out.changed.map((file) => ` changed ${file}`),
1468
1501
  ...out.failed.map((f) => ` could not fix ${f.code}: ${f.reason}`),
1502
+ ...out.skipped.map((s) => ` needs review ${s.code}: ${s.reason}`),
1469
1503
  ...out.diagnostics.map((d) => ` ${String((d as { code?: unknown }).code ?? "diagnostic")}`),
1470
1504
  ],
1471
1505
  success: (out) => out.ok,
@@ -1493,6 +1527,7 @@ const migrateSpec: CommandSpec<MigrateInput, MigrateCommandOutput> = {
1493
1527
  moves: { type: "array" },
1494
1528
  rewritten: { type: "array" },
1495
1529
  tooling: { type: "array" },
1530
+ followUps: { type: "array" },
1496
1531
  mode: { type: "string" },
1497
1532
  },
1498
1533
  required: ["ok", "write", "issues"],
@@ -1505,6 +1540,7 @@ const migrateSpec: CommandSpec<MigrateInput, MigrateCommandOutput> = {
1505
1540
  { name: "from", field: "from", type: "string" },
1506
1541
  { name: "to", field: "to", type: "string" },
1507
1542
  { name: "write", field: "write", type: "boolean" },
1543
+ { name: "zones", field: "zones", type: "boolean" },
1508
1544
  { name: "json", field: "json", type: "boolean" },
1509
1545
  { name: "dir", field: "dir", type: "string" },
1510
1546
  ],
@@ -1514,7 +1550,8 @@ const migrateSpec: CommandSpec<MigrateInput, MigrateCommandOutput> = {
1514
1550
  const write = value.write === undefined ? {} : { write: value.write }
1515
1551
  if (value.kind === "layout") {
1516
1552
  const { migrateLayout } = await import("./migrate-layout.ts")
1517
- return { kind: "layout" as const, ...(await migrateLayout(dir, write)) }
1553
+ const options = { ...write, zones: value.zones === true }
1554
+ return { kind: "layout" as const, ...(await migrateLayout(dir, options)) }
1518
1555
  }
1519
1556
  const { migrateTailwindToStylex } = await import("./stylex-migrate.ts")
1520
1557
  return migrateTailwindToStylex(dir, write)
@@ -1526,12 +1563,23 @@ const migrateSpec: CommandSpec<MigrateInput, MigrateCommandOutput> = {
1526
1563
  ? `✓ ${out.mode === "api" ? "API-only app" : `${out.splits.length} route file${out.splits.length === 1 ? "" : "s"} split`}, ${out.moves.length} file${out.moves.length === 1 ? "" : "s"} moved`
1527
1564
  : `⚠ ${out.issues.length} issue${out.issues.length === 1 ? "" : "s"} need a decision; everything else is planned`,
1528
1565
  ...out.splits.map(
1529
- (split) => ` split ${split.file} → ${split.backend} (${split.moved.join(", ")})`,
1566
+ (split) =>
1567
+ ` split ${split.file} → ${split.backend} (${split.moved.join(", ")})${split.shared === undefined ? "" : `, shared data → ${split.shared}`}`,
1530
1568
  ),
1531
1569
  ...out.moves.map((move) => ` move ${move.from} → ${move.to}`),
1532
1570
  ...out.rewritten.map((file) => ` edit ${file} (imports)`),
1533
1571
  ...out.tooling.map((edit) => ` edit ${edit.file} (${edit.change})`),
1572
+ ...out.schemas
1573
+ .filter((entry) => entry.reason === undefined)
1574
+ .map(
1575
+ (entry) =>
1576
+ ` draft ${entry.file} ${entry.schema} - review what it lets the browser see${entry.omitted === undefined ? "" : `; leaves out ${entry.omitted.join(", ")}`}${entry.open === undefined ? "" : `; admits any value at ${entry.open.join(", ")}, typed any or unknown`}`,
1577
+ ),
1534
1578
  ...out.issues.map((issue) => ` ⚠ ${issue.file}: ${issue.reason}`),
1579
+ ...out.followUps.map(
1580
+ (step) =>
1581
+ ` next ${step.file}: ${step.reason}${step.command === undefined ? "" : ` - \`${step.command}\``}`,
1582
+ ),
1535
1583
  ...(out.write ? [] : [" dry run: pass --write to apply"]),
1536
1584
  ]
1537
1585
  }
@@ -1683,18 +1731,22 @@ const schemasSpec: CommandSpec<SchemasInput, OutputSchemasReport> = {
1683
1731
  argv: {
1684
1732
  flags: [
1685
1733
  { name: "write", field: "write", type: "boolean" },
1734
+ { name: "check", field: "check", type: "boolean" },
1686
1735
  { name: "json", field: "json", type: "boolean" },
1687
1736
  { name: "dir", field: "dir", type: "string" },
1688
1737
  ],
1689
1738
  },
1690
1739
  async run(value, ctx) {
1691
1740
  const { outputSchemas } = await import("./output-schemas.ts")
1692
- return outputSchemas(resolve(ctx.cwd, value.dir ?? "."), { write: value.write === true })
1741
+ return outputSchemas(resolve(ctx.cwd, value.dir ?? "."), {
1742
+ write: value.write === true,
1743
+ check: value.check === true,
1744
+ })
1693
1745
  },
1694
1746
  render: (out) => {
1695
1747
  const shown = out.entries.filter(
1696
1748
  (entry) =>
1697
- entry.status !== "current" &&
1749
+ (entry.status !== "current" || entry.open !== undefined) &&
1698
1750
  entry.status !== "no-data" &&
1699
1751
  (entry.status !== "declared" || entry.dropped.length > 0),
1700
1752
  )
@@ -1709,8 +1761,19 @@ const schemasSpec: CommandSpec<SchemasInput, OutputSchemasReport> = {
1709
1761
  ? "edited by hand under its nifra:generated line"
1710
1762
  : entry.dropped.length > 0
1711
1763
  ? `drops ${entry.dropped.join(", ")}`
1712
- : undefined)
1713
- return ` ${SCHEMA_STATUS_LINE[entry.status]} ${entry.file}:${entry.line} ${entry.schema}${detail === undefined ? "" : ` - ${detail}`}`
1764
+ : entry.omitted !== undefined
1765
+ ? `leaves out ${entry.omitted.join(", ")}`
1766
+ : undefined)
1767
+ const open =
1768
+ entry.open === undefined
1769
+ ? []
1770
+ : [
1771
+ ` admits any value at ${entry.open.join(", ")}: the type there is any or unknown, so the output guard drops nothing below it`,
1772
+ ]
1773
+ return [
1774
+ ` ${SCHEMA_STATUS_LINE[entry.status]} ${entry.file}:${entry.line} ${entry.schema}${detail === undefined ? "" : ` - ${detail}`}`,
1775
+ ...open,
1776
+ ].join("\n")
1714
1777
  }),
1715
1778
  ...(out.write || !out.entries.some((e) => e.status === "missing" || e.status === "stale")
1716
1779
  ? []
@@ -2020,6 +2083,7 @@ export const commandSpecs = Object.freeze([
2020
2083
  portSpec,
2021
2084
  i18nSpec,
2022
2085
  errorsSpec,
2086
+ explainSpec,
2023
2087
  logsSpec,
2024
2088
  cdnCheckSpec,
2025
2089
  dbSchemaSpec,
@@ -221,12 +221,16 @@ function relativeSpecifier(fromDir: string, target: string): string {
221
221
  * `singleCopy` is whether `package.json` declares `"nifra": { "singleCopy": [...] }`. The declared
222
222
  * resolver then runs where `buildClient` runs it, after the zone guard; an app that also lists
223
223
  * `singleCopyPlugin()` in `clientPlugins` gets its own instance in that place, once.
224
+ *
225
+ * `publicEnvPrefix` is the value `loadApp` resolved across both configs, written in as a literal:
226
+ * importing it from `configPath` would miss one set only in `backend/framework.ts`.
224
227
  */
225
228
  export function renderBoundaryPluginModule(
226
229
  configPath?: string,
227
230
  pluginDir?: string,
228
231
  servePlugins: readonly string[] = [],
229
232
  singleCopy = false,
233
+ publicEnvPrefix?: string,
230
234
  ): string {
231
235
  const appImport =
232
236
  configPath !== undefined && pluginDir !== undefined
@@ -264,22 +268,18 @@ export function renderBoundaryPluginModule(
264
268
  }
265
269
  `
266
270
  return `// Generated by \`nifra dev\` (Bun pipeline) - do not edit. Regenerated on every dev start.
267
- import { serverFnStubPlugin, zoneGuardPlugin } from "@nifrajs/web/build"
271
+ import { importGlobPlugin, serverFnStubPlugin, zoneGuardPlugin } from "@nifrajs/web/build"
268
272
  import { reserveDevSpecifiers } from "@nifrajs/web/internal/dev-reserved"
269
273
  import { cssModulesBunPlugin } from "@nifrajs/web/plugins/css-modules"
270
274
  ${singleCopy ? 'import { singleCopyPlugin } from "@nifrajs/core/single-copy"\n' : ""}${appImport}
271
275
  // This module lives at <app>/.nifra/dev-bun/, so the app root is two directories up.
272
276
  const appRoot = Bun.fileURLToPath(new URL("../../", import.meta.url))
273
277
  const zones = zoneGuardPlugin({
274
- appRoot,${
275
- appImport === ""
276
- ? ""
277
- : `
278
- ...(typeof appConfig.publicEnvPrefix === "string" ? { publicEnvPrefix: appConfig.publicEnvPrefix } : {}),`
279
- }
278
+ appRoot,${publicEnvPrefix === undefined ? "" : `\n publicEnvPrefix: ${JSON.stringify(publicEnvPrefix)},`}
280
279
  })
281
280
  const fn = serverFnStubPlugin()
282
281
  const cssModules = cssModulesBunPlugin("dom")
282
+ const globs = importGlobPlugin({ root: appRoot })
283
283
 
284
284
  export default {
285
285
  name: "nifra-dev-boundary",
@@ -292,7 +292,9 @@ ${singleCopy ? appPluginsSetup : ""} // Boundary first: an app plugin must ne
292
292
  zones.setup(guarded)
293
293
  ${singleCopySetup} fn.setup(guarded)
294
294
  cssModules.setup(guarded)
295
- ${appSetup}${serveSetup} },
295
+ ${appSetup}${serveSetup} // Last, as in buildClient: a module another plugin loads is that plugin's.
296
+ globs.setup(guarded)
297
+ },
296
298
  }
297
299
  `
298
300
  }
@@ -308,11 +310,12 @@ const TOKEN_FILE = "launch-token"
308
310
  /** Write the generated config for an app; returns the bunfig path to re-exec with and the fresh
309
311
  * launch token to pass in the child's environment. `configPath` (the app's `nifra.config.ts` /
310
312
  * `backend/framework.ts`) is what lets the app's own `clientPlugins` reach Bun's dev-server
311
- * bundler; `define` is the config's own. */
313
+ * bundler; `define` and `publicEnvPrefix` are the loaded config's own. */
312
314
  export async function writeBunDevConfig(
313
315
  appRoot: string,
314
316
  configPath?: string,
315
317
  define?: Readonly<Record<string, string>>,
318
+ publicEnvPrefix?: string,
316
319
  ): Promise<BunDevConfig> {
317
320
  const dir = resolve(appRoot, ".nifra", "dev-bun")
318
321
  mkdirSync(dir, { recursive: true })
@@ -328,6 +331,7 @@ export async function writeBunDevConfig(
328
331
  dir,
329
332
  userServePlugins(user, appRoot),
330
333
  readSingleCopyDeclaration(appRoot) !== undefined,
334
+ publicEnvPrefix,
331
335
  ),
332
336
  )
333
337
  const bunfigPath = resolve(dir, "bunfig.toml")
@@ -18,6 +18,13 @@ import type {
18
18
  import type { Diagnostic } from "@nifrajs/web/diagnostic"
19
19
  import type { CommandCtx, CommandSpec } from "./command-catalog.ts"
20
20
  import type { DevServerLookup, LiveDevServer } from "./dev-server-client.ts"
21
+ import {
22
+ isRuleExplanation,
23
+ RULE_CODE_SHAPE,
24
+ type RuleExplainOutput,
25
+ renderRuleExplanation,
26
+ type UnknownRuleOutput,
27
+ } from "./rule-explain.ts"
21
28
 
22
29
  const CATEGORIES: readonly DevErrorCategory[] = [
23
30
  "ssr",
@@ -793,6 +800,144 @@ export const logsSpec: CommandSpec<LogsInput, LogsOutput> = {
793
800
  json: (out) => out,
794
801
  }
795
802
 
803
+ export interface ExplainInput {
804
+ readonly error?: string | undefined
805
+ readonly stack?: string | undefined
806
+ readonly name?: string | undefined
807
+ readonly port?: number | undefined
808
+ readonly dir?: string | undefined
809
+ readonly json?: boolean | undefined
810
+ }
811
+
812
+ /** A diagnostic, a rule code's catalog entry, or why there was nothing to explain. */
813
+ export type ExplainOutput =
814
+ | (Diagnostic & { readonly entry?: object; readonly note?: string })
815
+ | RuleExplainOutput
816
+ | UnknownRuleOutput
817
+ | { code: "NIFRA_NONE"; message: string }
818
+
819
+ const isRuleOutput = (out: ExplainOutput): out is RuleExplainOutput =>
820
+ "kind" in out && out.kind === "rule"
821
+ const explained = (out: ExplainOutput): out is Diagnostic =>
822
+ out.code !== "NIFRA_NONE" && out.code !== "NIFRA_UNKNOWN_RULE" && !isRuleOutput(out)
823
+
824
+ export const explainSpec: CommandSpec<ExplainInput, ExplainOutput> = {
825
+ name: "explain",
826
+ summary:
827
+ "Turn an error into a structured diagnostic: its code, the frame in your source with a codeframe, and the cause and fix when nifra recognises it. With no message, the running dev server's latest error. A rule code such as NF-C007 explains that rule.",
828
+ input: {
829
+ jsonSchema: {
830
+ type: "object",
831
+ properties: {
832
+ error: {
833
+ type: "string",
834
+ description: "The error message to explain, or a rule code such as NF-C007.",
835
+ },
836
+ stack: {
837
+ type: "string",
838
+ description: "Its stack trace, for the codeframe and source frame.",
839
+ },
840
+ name: { type: "string", description: "Its class name, such as TypeError." },
841
+ port: SHARED_PROPERTIES.port,
842
+ dir: { type: "string", description: "The app directory." },
843
+ json: { type: "boolean" },
844
+ },
845
+ additionalProperties: false,
846
+ },
847
+ parse: (value) => {
848
+ const raw = fields(value)
849
+ return {
850
+ error: text(raw, "error"),
851
+ stack: text(raw, "stack"),
852
+ name: text(raw, "name"),
853
+ port: count(raw, "port"),
854
+ dir: text(raw, "dir"),
855
+ json: flag(raw, "json"),
856
+ }
857
+ },
858
+ },
859
+ output: {
860
+ version: 1,
861
+ jsonSchema: {
862
+ type: "object",
863
+ properties: { code: { type: "string" }, message: { type: "string" } },
864
+ required: ["code", "message"],
865
+ },
866
+ parse: (value) => {
867
+ if (isRuleExplanation(value)) return value
868
+ if (isDiagnostic(value)) return value
869
+ if (
870
+ typeof value === "object" &&
871
+ value !== null &&
872
+ "code" in value &&
873
+ value.code === "NIFRA_UNKNOWN_RULE" &&
874
+ "message" in value &&
875
+ typeof value.message === "string"
876
+ )
877
+ return { code: "NIFRA_UNKNOWN_RULE", message: value.message }
878
+ if (
879
+ typeof value === "object" &&
880
+ value !== null &&
881
+ "code" in value &&
882
+ value.code === "NIFRA_NONE" &&
883
+ "message" in value &&
884
+ typeof value.message === "string"
885
+ )
886
+ return { code: "NIFRA_NONE", message: value.message }
887
+ throw new TypeError(
888
+ "explain output must be a diagnostic, a rule explanation, NIFRA_UNKNOWN_RULE or NIFRA_NONE",
889
+ )
890
+ },
891
+ },
892
+ transports: ["cli"],
893
+ stability: "experimental",
894
+ argv: {
895
+ positionals: ["error"],
896
+ flags: [
897
+ { name: "stack", field: "stack", type: "string" },
898
+ { name: "name", field: "name", type: "string" },
899
+ { name: "port", field: "port", type: "number" },
900
+ { name: "dir", field: "dir", type: "string" },
901
+ { name: "json", field: "json", type: "boolean" },
902
+ ],
903
+ },
904
+ async run(input, ctx) {
905
+ const code = input.error?.trim()
906
+ if (input.stack === undefined && code !== undefined && RULE_CODE_SHAPE.test(code)) {
907
+ const { explainRule } = await import("./rule-explain.ts")
908
+ return explainRule(code)
909
+ }
910
+ const root = resolve(ctx.cwd, input.dir ?? ".")
911
+ if (input.error === undefined && input.stack === undefined) {
912
+ return explainLatest(root, input.port, ctx.signal)
913
+ }
914
+ const { buildDiagnostic } = await import("@nifrajs/web/diagnostic")
915
+ const { explainSourceGate } = await import("./mcp-exec.ts")
916
+ const error = new Error(input.error ?? "")
917
+ if (input.name !== undefined) error.name = input.name
918
+ // Without --stack the frames would be this command's own, not the app's.
919
+ error.stack = input.stack ?? `${error.name}: ${error.message}`
920
+ return buildDiagnostic(error, { root, showSource: explainSourceGate(root) })
921
+ },
922
+ render: (out) => {
923
+ if (isRuleOutput(out)) return renderRuleExplanation(out)
924
+ if (!explained(out)) return [out.message]
925
+ const at = topFrame(out)
926
+ return [
927
+ `${out.code} ${headline(out)}`,
928
+ ...(at === undefined ? [] : [` at ${at}`]),
929
+ ...(out.codeframe?.lines ?? []).map(
930
+ (line) => ` ${line.caret ? ">" : " "} ${String(line.number).padStart(4)} | ${line.text}`,
931
+ ),
932
+ ...(out.cause === undefined ? [] : [` cause: ${out.cause}`]),
933
+ ...(out.fix === undefined ? [] : [` fix: ${out.fix}`]),
934
+ ]
935
+ },
936
+ exitCode: (out) =>
937
+ explained(out) || isRuleOutput(out) ? 0 : out.code === "NIFRA_UNKNOWN_RULE" ? 1 : 2,
938
+ json: (out) => out,
939
+ }
940
+
796
941
  // ---------------------------------------------------------------------------------------------------
797
942
  // nifra_explain / nifra_inspect reads
798
943
  // ---------------------------------------------------------------------------------------------------
@@ -802,7 +947,7 @@ export async function explainLatest(
802
947
  cwd: string,
803
948
  port: number | undefined,
804
949
  signal?: AbortSignal,
805
- ): Promise<unknown> {
950
+ ): Promise<ExplainOutput> {
806
951
  const { findDevServer, describeLookup, readDevFeed } = await import("./dev-server-client.ts")
807
952
  const lookup = await findDevServer(cwd, { port }, signal)
808
953
  if (lookup.status === "live") {