@nifrajs/cli 5.17.0 → 5.18.1

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 (178) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/dist/check-diagnostics.d.ts +7 -0
  3. package/dist/check-diagnostics.d.ts.map +1 -1
  4. package/dist/check-diagnostics.js +3 -0
  5. package/dist/check-diagnostics.js.map +1 -1
  6. package/dist/check-scan-sql.d.ts +95 -0
  7. package/dist/check-scan-sql.d.ts.map +1 -0
  8. package/dist/check-scan-sql.js +1190 -0
  9. package/dist/check-scan-sql.js.map +1 -0
  10. package/dist/check-scan.d.ts +5 -93
  11. package/dist/check-scan.d.ts.map +1 -1
  12. package/dist/check-scan.js +20 -1207
  13. package/dist/check-scan.js.map +1 -1
  14. package/dist/check.d.ts.map +1 -1
  15. package/dist/check.js +9 -0
  16. package/dist/check.js.map +1 -1
  17. package/dist/cli.d.ts +2 -6
  18. package/dist/cli.d.ts.map +1 -1
  19. package/dist/cli.js +249 -80
  20. package/dist/cli.js.map +1 -1
  21. package/dist/command-catalog.d.ts +3 -0
  22. package/dist/command-catalog.d.ts.map +1 -1
  23. package/dist/command-catalog.js +18 -4
  24. package/dist/command-catalog.js.map +1 -1
  25. package/dist/frontend-guidance.js +1 -1
  26. package/dist/frontend-guidance.js.map +1 -1
  27. package/dist/internal/a11y-element.d.ts +33 -0
  28. package/dist/internal/a11y-element.d.ts.map +1 -0
  29. package/dist/internal/a11y-element.js +124 -0
  30. package/dist/internal/a11y-element.js.map +1 -0
  31. package/dist/internal/a11y-jsx.d.ts +12 -0
  32. package/dist/internal/a11y-jsx.d.ts.map +1 -0
  33. package/dist/internal/a11y-jsx.js +42 -0
  34. package/dist/internal/a11y-jsx.js.map +1 -0
  35. package/dist/internal/a11y-template.d.ts +11 -0
  36. package/dist/internal/a11y-template.d.ts.map +1 -0
  37. package/dist/internal/a11y-template.js +56 -0
  38. package/dist/internal/a11y-template.js.map +1 -0
  39. package/dist/internal/aria-data.d.ts +23 -0
  40. package/dist/internal/aria-data.d.ts.map +1 -0
  41. package/dist/internal/aria-data.js +220 -0
  42. package/dist/internal/aria-data.js.map +1 -0
  43. package/dist/internal/edit-distance.d.ts +3 -0
  44. package/dist/internal/edit-distance.d.ts.map +1 -0
  45. package/dist/internal/edit-distance.js +12 -0
  46. package/dist/internal/edit-distance.js.map +1 -0
  47. package/dist/internal/imported-as.d.ts +10 -0
  48. package/dist/internal/imported-as.d.ts.map +1 -0
  49. package/dist/internal/imported-as.js +23 -0
  50. package/dist/internal/imported-as.js.map +1 -0
  51. package/dist/internal/source-facts.d.ts +3 -0
  52. package/dist/internal/source-facts.d.ts.map +1 -1
  53. package/dist/internal/source-facts.js +2 -0
  54. package/dist/internal/source-facts.js.map +1 -1
  55. package/dist/internal/template-markup.d.ts +58 -0
  56. package/dist/internal/template-markup.d.ts.map +1 -0
  57. package/dist/internal/template-markup.js +221 -0
  58. package/dist/internal/template-markup.js.map +1 -0
  59. package/dist/internal/typescript-import.d.ts.map +1 -1
  60. package/dist/internal/typescript-import.js +11 -0
  61. package/dist/internal/typescript-import.js.map +1 -1
  62. package/dist/mcp-exec.d.ts.map +1 -1
  63. package/dist/mcp-exec.js +37 -23
  64. package/dist/mcp-exec.js.map +1 -1
  65. package/dist/mcp-http.js +1 -1
  66. package/dist/mcp-io.d.ts.map +1 -1
  67. package/dist/mcp-io.js +5 -3
  68. package/dist/mcp-io.js.map +1 -1
  69. package/dist/mcp-root.js +1 -1
  70. package/dist/mcp-root.js.map +1 -1
  71. package/dist/mcp-ws.d.ts.map +1 -1
  72. package/dist/mcp-ws.js +3 -2
  73. package/dist/mcp-ws.js.map +1 -1
  74. package/dist/migrate-layout-config.d.ts +63 -0
  75. package/dist/migrate-layout-config.d.ts.map +1 -0
  76. package/dist/migrate-layout-config.js +507 -0
  77. package/dist/migrate-layout-config.js.map +1 -0
  78. package/dist/migrate-layout-split.d.ts +46 -0
  79. package/dist/migrate-layout-split.d.ts.map +1 -0
  80. package/dist/migrate-layout-split.js +687 -0
  81. package/dist/migrate-layout-split.js.map +1 -0
  82. package/dist/migrate-layout.d.ts +4 -24
  83. package/dist/migrate-layout.d.ts.map +1 -1
  84. package/dist/migrate-layout.js +8 -1183
  85. package/dist/migrate-layout.js.map +1 -1
  86. package/dist/output-schemas.d.ts.map +1 -1
  87. package/dist/output-schemas.js +78 -10
  88. package/dist/output-schemas.js.map +1 -1
  89. package/dist/recipes/5.18.0.d.ts +9 -0
  90. package/dist/recipes/5.18.0.d.ts.map +1 -0
  91. package/dist/recipes/5.18.0.js +56 -0
  92. package/dist/recipes/5.18.0.js.map +1 -0
  93. package/dist/recipes/index.d.ts.map +1 -1
  94. package/dist/recipes/index.js +2 -0
  95. package/dist/recipes/index.js.map +1 -1
  96. package/dist/review.d.ts.map +1 -1
  97. package/dist/review.js +6 -0
  98. package/dist/review.js.map +1 -1
  99. package/dist/rules/a11y.d.ts +5 -0
  100. package/dist/rules/a11y.d.ts.map +1 -0
  101. package/dist/rules/a11y.js +78 -0
  102. package/dist/rules/a11y.js.map +1 -0
  103. package/dist/rules/codes.d.ts +6 -0
  104. package/dist/rules/codes.d.ts.map +1 -1
  105. package/dist/rules/codes.js +6 -0
  106. package/dist/rules/codes.js.map +1 -1
  107. package/dist/rules/comment-markers.js +1 -1
  108. package/dist/rules/comment-markers.js.map +1 -1
  109. package/dist/rules/explanations.d.ts.map +1 -1
  110. package/dist/rules/explanations.js +30 -0
  111. package/dist/rules/explanations.js.map +1 -1
  112. package/dist/rules/host-exposure.d.ts +23 -0
  113. package/dist/rules/host-exposure.d.ts.map +1 -0
  114. package/dist/rules/host-exposure.js +380 -0
  115. package/dist/rules/host-exposure.js.map +1 -0
  116. package/dist/rules/internal-links.d.ts.map +1 -1
  117. package/dist/rules/internal-links.js +16 -141
  118. package/dist/rules/internal-links.js.map +1 -1
  119. package/dist/rules/islands.d.ts +54 -0
  120. package/dist/rules/islands.d.ts.map +1 -1
  121. package/dist/rules/islands.js +577 -80
  122. package/dist/rules/islands.js.map +1 -1
  123. package/dist/rules/security.d.ts +1 -0
  124. package/dist/rules/security.d.ts.map +1 -1
  125. package/dist/rules/security.js +34 -7
  126. package/dist/rules/security.js.map +1 -1
  127. package/dist/runtime-differences.js +3 -3
  128. package/dist/runtime-differences.js.map +1 -1
  129. package/dist/scaffold.d.ts +1 -1
  130. package/dist/scaffold.d.ts.map +1 -1
  131. package/dist/scaffold.js +2 -2
  132. package/dist/scaffold.js.map +1 -1
  133. package/dist/source-rewrites.d.ts.map +1 -1
  134. package/dist/source-rewrites.js +2 -19
  135. package/dist/source-rewrites.js.map +1 -1
  136. package/docs/examples.json +4 -4
  137. package/docs/llms-full.txt +422 -42
  138. package/docs/types.json +466 -56
  139. package/package.json +12 -12
  140. package/src/check-diagnostics.ts +11 -0
  141. package/src/check-scan-sql.ts +1746 -0
  142. package/src/check-scan.ts +34 -1754
  143. package/src/check.ts +10 -1
  144. package/src/cli.ts +258 -98
  145. package/src/command-catalog.ts +21 -4
  146. package/src/frontend-guidance.ts +1 -1
  147. package/src/internal/a11y-element.ts +227 -0
  148. package/src/internal/a11y-jsx.ts +54 -0
  149. package/src/internal/a11y-template.ts +74 -0
  150. package/src/internal/aria-data.ts +242 -0
  151. package/src/internal/edit-distance.ts +16 -0
  152. package/src/internal/imported-as.ts +30 -0
  153. package/src/internal/source-facts.ts +4 -0
  154. package/src/internal/template-markup.ts +270 -0
  155. package/src/internal/typescript-import.ts +15 -0
  156. package/src/mcp-exec.ts +43 -22
  157. package/src/mcp-http.ts +1 -1
  158. package/src/mcp-io.ts +5 -3
  159. package/src/mcp-root.ts +1 -1
  160. package/src/mcp-ws.ts +3 -2
  161. package/src/migrate-layout-config.ts +615 -0
  162. package/src/migrate-layout-split.ts +870 -0
  163. package/src/migrate-layout.ts +37 -1468
  164. package/src/output-schemas.ts +85 -17
  165. package/src/recipes/5.18.0.ts +63 -0
  166. package/src/recipes/index.ts +2 -0
  167. package/src/review.ts +6 -0
  168. package/src/rules/a11y.ts +119 -0
  169. package/src/rules/codes.ts +6 -0
  170. package/src/rules/comment-markers.ts +2 -2
  171. package/src/rules/explanations.ts +30 -0
  172. package/src/rules/host-exposure.ts +531 -0
  173. package/src/rules/internal-links.ts +21 -154
  174. package/src/rules/islands.ts +698 -86
  175. package/src/rules/security.ts +48 -7
  176. package/src/runtime-differences.ts +3 -3
  177. package/src/scaffold.ts +3 -3
  178. package/src/source-rewrites.ts +2 -15
package/dist/cli.js CHANGED
@@ -10,12 +10,11 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
10
10
  import { existsSync, readFileSync, realpathSync } from "node:fs";
11
11
  import { resolve } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
- import { createWebApp, DEFAULT_DEV_PORT, } from "@nifrajs/web";
14
13
  import { formatBuildLog } from "@nifrajs/web/diagnostic";
15
14
  import { discoverRoutes } from "@nifrajs/web/fs";
15
+ import { DEFAULT_DEV_PORT } from "@nifrajs/web/internal/runtime-contract";
16
16
  import { formatShadowedPages, shadowedPages } from "@nifrajs/web/route-manifest";
17
17
  import { adapterFile, BACKEND_APP_FILE } from "./app-files.js";
18
- import { bindCommandArgv, commandUsage, findCommandSpec, renderCommandCatalogHelp, } from "./command-catalog.js";
19
18
  import { applyEnvFiles, forgetAutoLoadedEnv, REFLECT_ENV, takeEnvFileFlags } from "./env-file.js";
20
19
  import { FRAMEWORK_WEB_OPTIONS, loadApp } from "./load.js";
21
20
  import { PROJECT_COMMANDS, runThroughLocalCli } from "./local-cli.js";
@@ -304,10 +303,25 @@ Env: \`--env-file <path>\` works on EVERY command and may be repeated (later fil
304
303
  reflect your app import it, so an app that validates its environment at module scope needs that
305
304
  environment present - without it the app aborts before nifra runs a single check. A variable already
306
305
  set in the process environment is never overwritten by a file.
307
- e.g. \`nifra check --env-file .env.local\`
306
+ e.g. \`nifra check --env-file .env.local\``;
307
+ const SHORT_HELP = `nifra - develop, build, and verify a nifra app
308
308
 
309
- ${renderCommandCatalogHelp()}`;
310
- const CLI_VERSION = "5.17.0";
309
+ Develop dev, build, start, scaffold, target, db
310
+ Verify check, review, assure, doctor, fix, smoke
311
+ Contracts routes, types, schemas, openapi, contracts
312
+ Agents mcp, docs-mcp, learn, context, runtime
313
+ nifra init-agents configures editor and agent discovery
314
+ nifra init-agents --sync-mcp refreshes MCP registrations
315
+
316
+ Run nifra <command> --help for command options or nifra help --all for the full catalog.
317
+
318
+ nifra check accepts --lints-only to skip typechecking.
319
+ With a contracts.lock.json, both modes import backend/app.ts (running its top-level code).`;
320
+ async function fullHelp() {
321
+ const { renderCommandCatalogHelp } = await import("./command-catalog.js");
322
+ return `${HELP}\n\n${renderCommandCatalogHelp()}`;
323
+ }
324
+ const CLI_VERSION = "5.18.1";
311
325
  const asAdapter = (v) => v;
312
326
  const asBunPlugins = (v) => v;
313
327
  const asComponentPlugins = (value) => value;
@@ -327,7 +341,7 @@ export function formatCliError(err) {
327
341
  return err.message;
328
342
  return String(err);
329
343
  }
330
- export function commandHelp(spec) {
344
+ function commandHelp(spec, usage) {
331
345
  const name = spec.name.replace(/^db-/, "db ");
332
346
  const lines = [];
333
347
  let inside = false;
@@ -343,13 +357,24 @@ export function commandHelp(spec) {
343
357
  }
344
358
  if (lines.length > 0)
345
359
  return ["Usage:", ...lines].join("\n");
346
- const usage = commandUsage(spec);
347
360
  return `Usage:\n nifra ${name}${usage === "" ? "" : ` ${usage}`} ${spec.summary}`;
348
361
  }
362
+ function manualBooleanFlag(args, name) {
363
+ let enabled = false;
364
+ for (const arg of args) {
365
+ if (arg === "--")
366
+ break;
367
+ if (arg === name)
368
+ enabled = true;
369
+ else if (arg.startsWith(`${name}=`))
370
+ enabled = arg.slice(name.length + 1) === "true";
371
+ }
372
+ return enabled;
373
+ }
349
374
  function reportFailure(err, argv) {
350
375
  const message = formatCliError(err);
351
376
  console.error(message);
352
- if (argv.includes("--json") || argv.includes("--json=true"))
377
+ if (manualBooleanFlag(argv, "--json"))
353
378
  console.log(JSON.stringify({ ok: false, error: message }, null, 2));
354
379
  }
355
380
  async function dev(app, flags) {
@@ -383,7 +408,7 @@ async function dev(app, flags) {
383
408
  }
384
409
  const { publicEnvDefines } = await import("@nifrajs/web/build");
385
410
  const { bunfigPath, launchToken } = await writeBunDevConfig(app.cwd, app.configPath, app.framework.define, app.framework.publicEnvPrefix, publicEnvDefines(app.framework.publicEnvPrefix ?? "PUBLIC_", process.env));
386
- const childCliArgv = [...cliArgv()];
411
+ const childCliArgv = [...(await cliArgv())];
387
412
  const child = Bun.spawn([
388
413
  process.execPath,
389
414
  `--config=${bunfigPath}`,
@@ -441,6 +466,7 @@ async function dev(app, flags) {
441
466
  for (const p of asBunPlugins(app.resolvedPlugins.serverPlugins))
442
467
  plugin(p);
443
468
  const { createDevServer } = await import("@nifrajs/web/dev");
469
+ const { createWebApp } = await import("@nifrajs/web");
444
470
  const { framework: fw, routesDir, outDir, backend } = app;
445
471
  const server = await createDevServer({
446
472
  routesDir,
@@ -477,6 +503,7 @@ async function dev(app, flags) {
477
503
  }
478
504
  const { createViteDevServer } = await import("@nifrajs/web/vite");
479
505
  const { framework: fw, routesDir, cwd, backend } = app;
506
+ const { createWebApp } = await import("@nifrajs/web");
480
507
  const server = await createViteDevServer({
481
508
  root: cwd,
482
509
  routesDir,
@@ -759,6 +786,7 @@ async function buildForTarget(app, flag, flags) {
759
786
  }
760
787
  async function buildPrerenderApp(app) {
761
788
  const { plugin } = await import("bun");
789
+ const { createWebApp } = await import("@nifrajs/web");
762
790
  const { framework: fw, routesDir, backend } = app;
763
791
  for (const p of asBunPlugins(app.resolvedPlugins.serverPlugins))
764
792
  plugin(p);
@@ -929,8 +957,78 @@ export function frontendCommandInput(argv, parseAdapter) {
929
957
  json: argv.includes("--json"),
930
958
  };
931
959
  }
960
+ const MANUAL_HELP_COMMANDS = new Set([
961
+ "mcp",
962
+ "docs-mcp",
963
+ "learn",
964
+ "frontend",
965
+ "runtime",
966
+ "verify",
967
+ "init-agents",
968
+ "sdk",
969
+ ]);
970
+ function manualHelp(command) {
971
+ return HELP.split(/\n(?= {2}nifra )/)
972
+ .filter((section) => section.startsWith(` nifra ${command} `))
973
+ .map((section) => section.trimEnd())
974
+ .join("\n");
975
+ }
976
+ function manualFlagValue(argv, name) {
977
+ for (const [index, arg] of argv.entries()) {
978
+ if (arg.startsWith(`${name}=`))
979
+ return arg.slice(name.length + 1);
980
+ if (arg === name) {
981
+ const value = argv[index + 1];
982
+ return value === undefined || value.startsWith("-") ? "" : value;
983
+ }
984
+ }
985
+ return undefined;
986
+ }
987
+ function rejectUnknownManualFlags(args, valueFlags, booleanFlags) {
988
+ const valueSet = new Set(valueFlags);
989
+ const boolSet = new Set(booleanFlags);
990
+ for (let index = 0; index < args.length; index++) {
991
+ const arg = args[index];
992
+ if (arg === undefined || arg === "--")
993
+ break;
994
+ if (!arg.startsWith("-"))
995
+ continue;
996
+ const eq = arg.indexOf("=");
997
+ const name = eq === -1 ? arg : arg.slice(0, eq);
998
+ if (name === "--help" || name === "-h")
999
+ continue;
1000
+ if (boolSet.has(name)) {
1001
+ if (eq !== -1 && arg.slice(eq + 1) !== "true" && arg.slice(eq + 1) !== "false") {
1002
+ throw new Error(`[nifra] ${name} takes no value`);
1003
+ }
1004
+ continue;
1005
+ }
1006
+ if (valueSet.has(name)) {
1007
+ if (eq !== -1) {
1008
+ if (arg.slice(eq + 1) === "")
1009
+ throw new Error(`[nifra] ${name} needs a value`);
1010
+ continue;
1011
+ }
1012
+ const next = args[index + 1];
1013
+ if (next === undefined || next.startsWith("-")) {
1014
+ throw new Error(`[nifra] ${name} needs a value`);
1015
+ }
1016
+ index++;
1017
+ continue;
1018
+ }
1019
+ throw new Error(`[nifra] unknown option: ${arg} - see \`nifra help\``);
1020
+ }
1021
+ }
932
1022
  async function main() {
933
- const { argv: rawArgv, files: envFiles } = takeEnvFileFlags(cliArgv());
1023
+ const { argv: rawArgv, files: envFiles } = takeEnvFileFlags(await cliArgv());
1024
+ const helpCommand = rawArgv[0];
1025
+ if (helpCommand !== undefined &&
1026
+ ((MANUAL_HELP_COMMANDS.has(helpCommand) &&
1027
+ (rawArgv.includes("--help") || rawArgv.includes("-h"))) ||
1028
+ (helpCommand === "db" && (rawArgv[1] === "--help" || rawArgv[1] === "-h")))) {
1029
+ console.log(manualHelp(helpCommand));
1030
+ return;
1031
+ }
934
1032
  const forgotten = rawArgv[0] === "mcp" && process.env[MCP_WITHOUT_ENV_FILES] !== "1"
935
1033
  ? await forgetAutoLoadedEnv()
936
1034
  : [];
@@ -943,7 +1041,7 @@ async function main() {
943
1041
  throw new Error("[nifra] the configured Bun dev child lost its command arguments; refusing to serve without " +
944
1042
  "the verified dev configuration. Re-run `nifra dev`.");
945
1043
  }
946
- console.log(HELP);
1044
+ console.log(argv.includes("--all") ? await fullHelp() : SHORT_HELP);
947
1045
  return;
948
1046
  }
949
1047
  if (command === "--version" || command === "-v") {
@@ -957,7 +1055,7 @@ async function main() {
957
1055
  const exitCode = await runThroughLocalCli({
958
1056
  cwd: process.cwd(),
959
1057
  version: CLI_VERSION,
960
- args: cliArgv(),
1058
+ args: await cliArgv(),
961
1059
  });
962
1060
  if (exitCode !== undefined) {
963
1061
  process.exitCode = exitCode;
@@ -965,6 +1063,14 @@ async function main() {
965
1063
  }
966
1064
  }
967
1065
  if (command === "mcp") {
1066
+ try {
1067
+ rejectUnknownManualFlags(argv.slice(1), [], []);
1068
+ }
1069
+ catch (err) {
1070
+ reportFailure(err, argv);
1071
+ process.exitCode = 1;
1072
+ return;
1073
+ }
968
1074
  if (forgotten.length > 0) {
969
1075
  const { handOffSession } = await import("./mcp-delegate.js");
970
1076
  const exitCode = await handOffSession([process.execPath, "--no-env-file", ...process.argv.slice(1)], { cwd: process.cwd(), env: { ...process.env, [MCP_WITHOUT_ENV_FILES]: "1" } });
@@ -979,20 +1085,34 @@ async function main() {
979
1085
  return;
980
1086
  }
981
1087
  if (command === "docs-mcp") {
982
- const { handleMcpHttp } = await import("./mcp-http.js");
983
- const portArg = argv[argv.indexOf("--port") + 1];
984
- const port = Number(portArg && argv.includes("--port") ? portArg : (Bun.env.PORT ?? 8787));
985
- if (!Number.isInteger(port) || port < 0 || port > 65535) {
986
- throw new Error(`[nifra] invalid --port: ${port}`);
1088
+ try {
1089
+ rejectUnknownManualFlags(argv.slice(1), ["--port", "-p"], []);
1090
+ const { handleMcpHttp } = await import("./mcp-http.js");
1091
+ const portArg = manualFlagValue(argv, "--port") ?? manualFlagValue(argv, "-p") ?? Bun.env.PORT ?? "8787";
1092
+ const port = /^\d+$/.test(portArg) ? Number(portArg) : Number.NaN;
1093
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
1094
+ throw new Error(`[nifra] invalid --port: ${portArg}`);
1095
+ }
1096
+ const server = Bun.serve({ port, fetch: handleMcpHttp });
1097
+ console.log(`nifra docs MCP (HTTP) → ${server.url}`);
1098
+ }
1099
+ catch (err) {
1100
+ reportFailure(err, argv);
1101
+ process.exitCode = 1;
987
1102
  }
988
- const server = Bun.serve({ port, fetch: handleMcpHttp });
989
- console.log(`nifra docs MCP (HTTP) → ${server.url}`);
990
1103
  return;
991
1104
  }
992
1105
  if (command === "learn") {
993
- const { renderLearnResult } = await import("./learn.js");
994
- const stepArg = argv[1];
995
- console.log(renderLearnResult(stepArg !== undefined && /^\d+$/.test(stepArg) ? Number(stepArg) : undefined));
1106
+ try {
1107
+ rejectUnknownManualFlags(argv.slice(1), [], []);
1108
+ const { renderLearnResult } = await import("./learn.js");
1109
+ const stepArg = argv[1];
1110
+ console.log(renderLearnResult(stepArg !== undefined && /^\d+$/.test(stepArg) ? Number(stepArg) : undefined));
1111
+ }
1112
+ catch (err) {
1113
+ reportFailure(err, argv);
1114
+ process.exitCode = 1;
1115
+ }
996
1116
  return;
997
1117
  }
998
1118
  if (command === "frontend") {
@@ -1013,6 +1133,7 @@ async function main() {
1013
1133
  return;
1014
1134
  }
1015
1135
  const dbSub = command === "db" && argv[1] !== undefined && !argv[1].startsWith("-") ? argv[1] : undefined;
1136
+ const { findCommandSpec, commandUsage, bindCommandArgv } = await import("./command-catalog.js");
1016
1137
  if (command === "db" && (dbSub === undefined || findCommandSpec(`db-${dbSub}`) === undefined)) {
1017
1138
  throw new Error("[nifra] usage: nifra db schema|query|role|audit - see `nifra help`");
1018
1139
  }
@@ -1020,7 +1141,7 @@ async function main() {
1020
1141
  if (catalogSpec?.transports.includes("cli")) {
1021
1142
  const commandArgs = argv.slice(dbSub === undefined ? 1 : 2);
1022
1143
  if (commandArgs.includes("--help") || commandArgs.includes("-h")) {
1023
- console.log(commandHelp(catalogSpec));
1144
+ console.log(commandHelp(catalogSpec, commandUsage(catalogSpec)));
1024
1145
  return;
1025
1146
  }
1026
1147
  const markReflecting = installReflectionExitHint();
@@ -1034,13 +1155,15 @@ async function main() {
1034
1155
  }
1035
1156
  catch (error) {
1036
1157
  const message = error instanceof Error ? error.message : String(error);
1037
- throw new Error(`[nifra] ${message}\n\n${commandHelp(catalogSpec)}`);
1158
+ throw new Error(`[nifra] ${message}\n\n${commandHelp(catalogSpec, commandUsage(catalogSpec))}`);
1038
1159
  }
1039
1160
  markReflecting(command);
1040
1161
  const output = await catalogSpec.run(input, { cwd: process.cwd(), cliVersion: CLI_VERSION });
1041
1162
  markReflecting(undefined);
1042
1163
  const asRecord = output;
1043
- const wantsJson = asRecord.json === true || argv.includes("--json");
1164
+ const jsonFlag = typeof input === "object" && input !== null ? Reflect.get(input, "json") : undefined;
1165
+ const wantsJson = asRecord.json === true ||
1166
+ (typeof jsonFlag === "boolean" ? jsonFlag : argv.includes("--json"));
1044
1167
  if (wantsJson) {
1045
1168
  const value = catalogSpec.json?.(output, input) ?? output;
1046
1169
  console.log(typeof value === "string" ? value : JSON.stringify(value, null, 2));
@@ -1073,49 +1196,61 @@ async function main() {
1073
1196
  return;
1074
1197
  }
1075
1198
  if (command === "verify") {
1076
- const { runReleaseVerification } = await import("./release-verification.js");
1077
- const ok = await runReleaseVerification(process.cwd(), {
1078
- mode: argv.includes("--release") ? "release" : "default",
1079
- json: argv.includes("--json"),
1080
- });
1081
- if (!ok)
1199
+ try {
1200
+ const commandArgs = argv.slice(1);
1201
+ rejectUnknownManualFlags(commandArgs, [], ["--release", "--json"]);
1202
+ const { runReleaseVerification } = await import("./release-verification.js");
1203
+ const ok = await runReleaseVerification(process.cwd(), {
1204
+ mode: manualBooleanFlag(commandArgs, "--release") ? "release" : "default",
1205
+ json: manualBooleanFlag(commandArgs, "--json"),
1206
+ });
1207
+ if (!ok)
1208
+ process.exitCode = 1;
1209
+ }
1210
+ catch (err) {
1211
+ reportFailure(err, argv);
1082
1212
  process.exitCode = 1;
1213
+ }
1083
1214
  return;
1084
1215
  }
1085
1216
  if (command === "init-agents") {
1086
- const { runInitAgents } = await import("./init-agents.js");
1087
- await runInitAgents(process.cwd(), {
1088
- json: argv.includes("--json"),
1089
- force: argv.includes("--force"),
1090
- syncMcp: argv.includes("--sync-mcp"),
1091
- });
1092
- return;
1093
- }
1094
- if (command === "sdk") {
1095
- const languageIndex = argv.indexOf("--lang");
1096
- const language = languageIndex === -1 ? undefined : argv[languageIndex + 1];
1097
- const outIndex = argv.indexOf("--out");
1098
- const out = outIndex === -1 ? undefined : argv[outIndex + 1];
1099
- if (language !== "python" && language !== "go") {
1100
- console.error("[nifra] sdk needs --lang python or --lang go");
1101
- process.exitCode = 1;
1102
- return;
1217
+ try {
1218
+ const commandArgs = argv.slice(1);
1219
+ rejectUnknownManualFlags(commandArgs, [], ["--force", "--sync-mcp", "--json"]);
1220
+ const { runInitAgents } = await import("./init-agents.js");
1221
+ await runInitAgents(process.cwd(), {
1222
+ json: manualBooleanFlag(commandArgs, "--json"),
1223
+ force: manualBooleanFlag(commandArgs, "--force"),
1224
+ syncMcp: manualBooleanFlag(commandArgs, "--sync-mcp"),
1225
+ });
1103
1226
  }
1104
- if (outIndex !== -1 && (out === undefined || out.startsWith("-"))) {
1105
- console.error("[nifra] --out needs a file path");
1227
+ catch (err) {
1228
+ reportFailure(err, argv);
1106
1229
  process.exitCode = 1;
1107
- return;
1108
1230
  }
1231
+ return;
1232
+ }
1233
+ if (command === "sdk") {
1109
1234
  try {
1235
+ const commandArgs = argv.slice(1);
1236
+ rejectUnknownManualFlags(commandArgs, ["--lang", "--out"], ["--strict", "--json"]);
1237
+ const language = manualFlagValue(argv, "--lang");
1238
+ const out = manualFlagValue(argv, "--out");
1239
+ if (language !== "python" && language !== "go") {
1240
+ throw new Error("[nifra] sdk needs --lang python or --lang go");
1241
+ }
1242
+ if (out === "") {
1243
+ throw new Error("[nifra] --out needs a file path");
1244
+ }
1110
1245
  const { runSdk } = await import("./sdk.js");
1111
1246
  await runSdk(process.cwd(), {
1112
1247
  language,
1113
1248
  ...(out !== undefined ? { out } : {}),
1114
- ...(argv.includes("--strict") ? { strict: true } : {}),
1249
+ ...(manualBooleanFlag(commandArgs, "--strict") ? { strict: true } : {}),
1115
1250
  });
1116
1251
  }
1117
1252
  catch (err) {
1118
- console.error(formatCliError(err));
1253
+ reportFailure(err, argv);
1119
1254
  process.exitCode = 1;
1120
1255
  }
1121
1256
  exitIfHeldOpen(command);
@@ -1123,7 +1258,7 @@ async function main() {
1123
1258
  }
1124
1259
  if (command === "upgrade") {
1125
1260
  if (argv.includes("--help") || argv.includes("-h")) {
1126
- console.log(HELP);
1261
+ console.log(manualHelp(command));
1127
1262
  return;
1128
1263
  }
1129
1264
  const { parseUpgradeArgs, runUpgrade } = await import("./upgrade.js");
@@ -1144,12 +1279,12 @@ async function main() {
1144
1279
  }
1145
1280
  if (command !== "dev" && command !== "build" && command !== "start") {
1146
1281
  console.error(`[nifra] unknown command: ${command}\n`);
1147
- console.error(HELP);
1282
+ console.error(SHORT_HELP);
1148
1283
  process.exitCode = 1;
1149
1284
  return;
1150
1285
  }
1151
1286
  if (argv.includes("--help") || argv.includes("-h")) {
1152
- console.log(HELP);
1287
+ console.log(manualHelp(command));
1153
1288
  return;
1154
1289
  }
1155
1290
  const flags = parseFlags(argv.slice(1));
@@ -1244,47 +1379,72 @@ function isMainModule() {
1244
1379
  }
1245
1380
  return false;
1246
1381
  }
1247
- function isCliCommandToken(value) {
1248
- return (value === "dev" ||
1382
+ async function isCliCommandToken(value) {
1383
+ if (value === "dev" ||
1249
1384
  value === "build" ||
1250
1385
  value === "start" ||
1251
- value === "mcp" ||
1252
- value === "init-agents" ||
1386
+ MANUAL_HELP_COMMANDS.has(value) ||
1253
1387
  value === "upgrade" ||
1254
1388
  value === "db" ||
1255
1389
  value === "help" ||
1256
1390
  value === "--help" ||
1257
1391
  value === "-h" ||
1258
1392
  value === "--version" ||
1259
- value === "-v" ||
1260
- findCommandSpec(value) !== undefined);
1393
+ value === "-v")
1394
+ return true;
1395
+ if (!/^[a-z][a-z0-9-]*$/.test(value))
1396
+ return false;
1397
+ const { findCommandSpec } = await import("./command-catalog.js");
1398
+ return findCommandSpec(value) !== undefined;
1261
1399
  }
1262
- function findCliCommand(values) {
1263
- return values.findIndex((value) => isCliCommandToken(value));
1400
+ async function findCliCommand(values) {
1401
+ for (const [index, value] of values.entries()) {
1402
+ if (values[index - 1] === "--env-file" && !value.startsWith("-"))
1403
+ continue;
1404
+ if (await isCliCommandToken(value))
1405
+ return index;
1406
+ }
1407
+ return -1;
1264
1408
  }
1265
1409
  export function commandArgv(values, commandIndex) {
1266
1410
  const command = values.slice(commandIndex);
1267
- const script = values[1];
1268
- if (commandIndex <= 2 || script === undefined || script.startsWith("-"))
1411
+ const runtimeEnvFile = values
1412
+ .slice(0, 2)
1413
+ .findIndex((value) => value === "--env-file" || value.startsWith("--env-file="));
1414
+ if (runtimeEnvFile === -1 && (values[1] === undefined || values[1].startsWith("-")))
1269
1415
  return command;
1270
- const leading = values.slice(2, commandIndex);
1416
+ const envFiles = [];
1417
+ let others = [];
1418
+ let scriptAhead = runtimeEnvFile !== -1;
1419
+ for (let index = scriptAhead ? runtimeEnvFile : 2; index < commandIndex; index++) {
1420
+ const value = values[index] ?? "";
1421
+ if (value === "--env-file")
1422
+ envFiles.push(...values.slice(index, ++index + 1));
1423
+ else if (value.startsWith("--env-file="))
1424
+ envFiles.push(value);
1425
+ else if (scriptAhead && !value.startsWith("-")) {
1426
+ scriptAhead = false;
1427
+ others = [];
1428
+ }
1429
+ else
1430
+ others.push(value);
1431
+ }
1271
1432
  const separator = command.indexOf("--");
1272
- return separator === -1
1273
- ? [...command, ...leading]
1274
- : [...command.slice(0, separator), ...leading, ...command.slice(separator)];
1433
+ const end = separator === -1 ? command.length : separator;
1434
+ return [...envFiles, ...command.slice(0, end), ...others, ...command.slice(end)];
1275
1435
  }
1276
- function cliArgv() {
1277
- const reexec = reexecCliArgv();
1436
+ async function cliArgv() {
1437
+ const reexec = await reexecCliArgv();
1278
1438
  if (reexec !== undefined)
1279
1439
  return reexec;
1280
1440
  for (const values of [Bun.argv, process.argv]) {
1281
- const commandIndex = findCliCommand(values);
1441
+ const commandIndex = await findCliCommand(values);
1282
1442
  if (commandIndex >= 0)
1283
1443
  return commandArgv(values, commandIndex);
1284
1444
  }
1285
1445
  return Bun.argv.slice(2);
1286
1446
  }
1287
- function reexecCliArgv() {
1447
+ async function reexecCliArgv() {
1288
1448
  if (!isBunDevReexecChild())
1289
1449
  return undefined;
1290
1450
  const encoded = process.env.NIFRA_BUN_DEV_ARGS;
@@ -1302,13 +1462,22 @@ function reexecCliArgv() {
1302
1462
  if (!parsed.every((value) => typeof value === "string" && value.length <= 16 * 1024 && !value.includes("\0"))) {
1303
1463
  return undefined;
1304
1464
  }
1305
- const command = parsed[0];
1465
+ let at = 0;
1466
+ while (at < parsed.length) {
1467
+ if (parsed[at] === "--env-file")
1468
+ at += 2;
1469
+ else if (String(parsed[at]).startsWith("--env-file="))
1470
+ at++;
1471
+ else
1472
+ break;
1473
+ }
1474
+ const command = parsed[at];
1306
1475
  if (typeof command !== "string")
1307
1476
  return undefined;
1308
- return isCliCommandToken(command) ? parsed : undefined;
1477
+ return (await isCliCommandToken(command)) ? parsed : undefined;
1309
1478
  }
1310
- function hasCliCommandToken() {
1311
- return findCliCommand(Bun.argv) >= 0 || findCliCommand(process.argv) >= 0;
1479
+ async function hasCliCommandToken() {
1480
+ return (await findCliCommand(Bun.argv)) >= 0 || (await findCliCommand(process.argv)) >= 0;
1312
1481
  }
1313
1482
  function isBunDevReexecChild() {
1314
1483
  const depth = Number(process.env.NIFRA_BUN_DEV_DEPTH);
@@ -1317,12 +1486,12 @@ function isBunDevReexecChild() {
1317
1486
  Number.isSafeInteger(depth) &&
1318
1487
  depth > 0);
1319
1488
  }
1320
- if (isMainModule() || isBunDevReexecChild() || hasCliCommandToken()) {
1489
+ if (isMainModule() || isBunDevReexecChild() || (await hasCliCommandToken())) {
1321
1490
  try {
1322
1491
  await main();
1323
1492
  }
1324
1493
  catch (err) {
1325
- reportFailure(err, cliArgv());
1494
+ reportFailure(err, await cliArgv());
1326
1495
  process.exitCode = 1;
1327
1496
  }
1328
1497
  }