@nifrajs/cli 2.1.0 → 2.3.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 (126) hide show
  1. package/README.md +25 -25
  2. package/dist/assure.d.ts +2 -2
  3. package/dist/assure.d.ts.map +1 -1
  4. package/dist/assure.js +17 -10
  5. package/dist/assure.js.map +1 -1
  6. package/dist/capabilities-tool.d.ts +7 -0
  7. package/dist/capabilities-tool.d.ts.map +1 -1
  8. package/dist/capabilities-tool.js +68 -16
  9. package/dist/capabilities-tool.js.map +1 -1
  10. package/dist/check.d.ts +64 -22
  11. package/dist/check.d.ts.map +1 -1
  12. package/dist/check.js +400 -83
  13. package/dist/check.js.map +1 -1
  14. package/dist/cli.d.ts +37 -0
  15. package/dist/cli.d.ts.map +1 -1
  16. package/dist/cli.js +291 -53
  17. package/dist/cli.js.map +1 -1
  18. package/dist/diff-tool.d.ts +3 -3
  19. package/dist/diff-tool.js +7 -7
  20. package/dist/docs-search.d.ts +3 -3
  21. package/dist/docs-search.js +6 -6
  22. package/dist/doctor.d.ts +8 -4
  23. package/dist/doctor.d.ts.map +1 -1
  24. package/dist/doctor.js +74 -14
  25. package/dist/doctor.js.map +1 -1
  26. package/dist/examples.d.ts +5 -5
  27. package/dist/examples.js +5 -5
  28. package/dist/init-agents.d.ts +14 -14
  29. package/dist/init-agents.js +14 -14
  30. package/dist/internal/typescript-import.d.ts +24 -0
  31. package/dist/internal/typescript-import.d.ts.map +1 -0
  32. package/dist/internal/typescript-import.js +32 -0
  33. package/dist/internal/typescript-import.js.map +1 -0
  34. package/dist/introspect.d.ts +12 -12
  35. package/dist/introspect.js +24 -24
  36. package/dist/levels-tool.d.ts +8 -8
  37. package/dist/levels-tool.d.ts.map +1 -1
  38. package/dist/levels-tool.js +33 -30
  39. package/dist/levels-tool.js.map +1 -1
  40. package/dist/load.d.ts +17 -6
  41. package/dist/load.d.ts.map +1 -1
  42. package/dist/load.js +45 -7
  43. package/dist/load.js.map +1 -1
  44. package/dist/manifest-tool.d.ts +1 -1
  45. package/dist/manifest-tool.d.ts.map +1 -1
  46. package/dist/manifest-tool.js +4 -2
  47. package/dist/manifest-tool.js.map +1 -1
  48. package/dist/mcp-docs-tools.d.ts +1 -1
  49. package/dist/mcp-docs-tools.d.ts.map +1 -1
  50. package/dist/mcp-docs-tools.js +14 -10
  51. package/dist/mcp-docs-tools.js.map +1 -1
  52. package/dist/mcp-http.d.ts +5 -5
  53. package/dist/mcp-http.js +7 -7
  54. package/dist/mcp-protocol.d.ts +2 -2
  55. package/dist/mcp-protocol.js +2 -2
  56. package/dist/mcp-render.d.ts +3 -3
  57. package/dist/mcp-render.js +15 -7
  58. package/dist/mcp-render.js.map +1 -1
  59. package/dist/mcp-run.d.ts +2 -2
  60. package/dist/mcp-run.js +2 -2
  61. package/dist/mcp.d.ts +14 -14
  62. package/dist/mcp.d.ts.map +1 -1
  63. package/dist/mcp.js +119 -47
  64. package/dist/mcp.js.map +1 -1
  65. package/dist/openapi-tool.d.ts +1 -1
  66. package/dist/openapi-tool.js +2 -2
  67. package/dist/pipeline-guard.d.ts +83 -0
  68. package/dist/pipeline-guard.d.ts.map +1 -0
  69. package/dist/pipeline-guard.js +136 -0
  70. package/dist/pipeline-guard.js.map +1 -0
  71. package/dist/port.d.ts +9 -9
  72. package/dist/port.js +27 -27
  73. package/dist/recipes/1.8.0.d.ts +2 -2
  74. package/dist/recipes/1.8.0.js +5 -5
  75. package/dist/recipes/index.d.ts +2 -2
  76. package/dist/recipes/index.js +1 -1
  77. package/dist/scaffold.d.ts +3 -3
  78. package/dist/scaffold.js +8 -8
  79. package/dist/sync-routes.d.ts +28 -0
  80. package/dist/sync-routes.d.ts.map +1 -0
  81. package/dist/sync-routes.js +55 -0
  82. package/dist/sync-routes.js.map +1 -0
  83. package/dist/types-search.d.ts +6 -6
  84. package/dist/types-search.d.ts.map +1 -1
  85. package/dist/types-search.js +53 -8
  86. package/dist/types-search.js.map +1 -1
  87. package/dist/upgrade.d.ts +7 -7
  88. package/dist/upgrade.js +12 -12
  89. package/dist/verification.d.ts +51 -0
  90. package/dist/verification.d.ts.map +1 -0
  91. package/dist/verification.js +80 -0
  92. package/dist/verification.js.map +1 -0
  93. package/docs/examples.json +178 -88
  94. package/docs/llms-full.txt +1766 -766
  95. package/docs/types.json +2171 -2807
  96. package/package.json +22 -11
  97. package/src/assure.ts +17 -18
  98. package/src/capabilities-tool.ts +82 -16
  99. package/src/check.ts +493 -100
  100. package/src/cli.ts +306 -54
  101. package/src/diff-tool.ts +8 -8
  102. package/src/docs-search.ts +6 -6
  103. package/src/doctor.ts +81 -16
  104. package/src/examples.ts +7 -7
  105. package/src/init-agents.ts +17 -17
  106. package/src/internal/typescript-import.ts +33 -0
  107. package/src/introspect.ts +28 -28
  108. package/src/levels-tool.ts +37 -31
  109. package/src/load.ts +65 -12
  110. package/src/manifest-tool.ts +4 -2
  111. package/src/mcp-docs-tools.ts +20 -10
  112. package/src/mcp-http.ts +7 -7
  113. package/src/mcp-protocol.ts +2 -2
  114. package/src/mcp-render.ts +15 -7
  115. package/src/mcp-run.ts +2 -2
  116. package/src/mcp.ts +127 -47
  117. package/src/openapi-tool.ts +2 -2
  118. package/src/pipeline-guard.ts +186 -0
  119. package/src/port.ts +31 -31
  120. package/src/recipes/1.8.0.ts +5 -5
  121. package/src/recipes/index.ts +2 -2
  122. package/src/scaffold.ts +8 -8
  123. package/src/sync-routes.ts +69 -0
  124. package/src/types-search.ts +57 -8
  125. package/src/upgrade.ts +12 -12
  126. package/src/verification.ts +123 -0
@@ -0,0 +1,123 @@
1
+ /**
2
+ * One project verification, four commands. `nifra check`, `nifra assure`, `nifra levels`, and
3
+ * `nifra capabilities` are not separate audits - they are renderings of the same reflected project: the
4
+ * typed-contract scan, the route-assurance evaluation, and the static capability provenance. Historically
5
+ * each command re-derived the slice it needed, so a caller had to know which command ran which policy (and
6
+ * `levels` paid for the capability walk twice). `collectProjectVerification` runs each underlying policy
7
+ * exactly once and hands back a single value; the commands become thin formatters over subsets of it -
8
+ * `check`/`assure`/`levels` read their view directly, and `capabilities snapshot`/`check` read the same
9
+ * capability report before writing or diffing the lockfile.
10
+ *
11
+ * The typed-contract check is the one heavy pass (source walk + optional `tsc`), and `nifra assure`
12
+ * never needs it, so it is exposed as a lazily-invoked `check()` rather than computed up front.
13
+ */
14
+
15
+ import { existsSync } from "node:fs"
16
+ import { resolve } from "node:path"
17
+ import {
18
+ type AssuranceConfig,
19
+ type AssuranceReport,
20
+ evaluateRouteAssurance,
21
+ } from "@nifrajs/core/assurance"
22
+ import {
23
+ type CapabilityProjectReport,
24
+ collectCapabilityProjectReport,
25
+ } from "./capabilities-tool.ts"
26
+ import { type CheckAssuranceContext, type CheckResult, collectCheckResult } from "./check.ts"
27
+
28
+ export interface CollectProjectVerificationOptions {
29
+ /** Assurance config path, default `nifra.assurance.ts`. Honored by the assurance + levels views. */
30
+ readonly config?: string
31
+ /** Skip the `tsc` pass in the check view (the agent inner-loop mode). */
32
+ readonly lintsOnly?: boolean
33
+ /** Cancels the check view's typecheck. */
34
+ readonly signal?: AbortSignal
35
+ /** Cap the check view's diagnostics (the `levels` L0 and MCP paths set this). */
36
+ readonly maxDiagnostics?: number
37
+ }
38
+
39
+ export interface ProjectVerification {
40
+ readonly cwd: string
41
+ /** Whether `nifra.assurance.ts` (or the requested `config` path) exists. */
42
+ readonly assuranceConfigPresent: boolean
43
+ /** The loaded assurance config, when it loaded cleanly. */
44
+ readonly config?: AssuranceConfig
45
+ /** The error from loading/evaluating the config, if any; the assurance views surface or throw it. */
46
+ readonly configError?: unknown
47
+ /** `evaluateRouteAssurance` over the config's source + policy. Present whenever {@link config} is. */
48
+ readonly routeAssurance?: AssuranceReport
49
+ /** Static capability provenance, when the config declares a capabilities policy. */
50
+ readonly capability?: CapabilityProjectReport
51
+ /**
52
+ * The typed-contract check (scanners + typecheck + the assurance-fed capability/manifest diagnostics).
53
+ * Lazy and memoized: `nifra assure` never calls it, so that command pays nothing for the source walk.
54
+ */
55
+ check(): Promise<CheckResult>
56
+ }
57
+
58
+ /**
59
+ * Run each verification policy once and return the unified value. The config is loaded (and reflected)
60
+ * a single time; the resulting route-assurance + capability evidence is both returned for the assurance
61
+ * views and fed into the check view, so nothing is computed twice.
62
+ */
63
+ export async function collectProjectVerification(
64
+ cwd: string,
65
+ options: CollectProjectVerificationOptions = {},
66
+ ): Promise<ProjectVerification> {
67
+ const { loadAssuranceConfig, DEFAULT_ASSURANCE_CONFIG } = await import("./assure.ts")
68
+ const configPath = resolve(cwd, options.config ?? DEFAULT_ASSURANCE_CONFIG)
69
+ const assuranceConfigPresent = existsSync(configPath)
70
+
71
+ let config: AssuranceConfig | undefined
72
+ let configError: unknown
73
+ let routeAssurance: AssuranceReport | undefined
74
+ let capability: CapabilityProjectReport | undefined
75
+ // One try mirrors `check`'s single catch: any failure to load or reflect the config becomes the
76
+ // `configError` each view then renders in its own idiom (a diagnostic, a throw, a failed rung).
77
+ try {
78
+ config = await loadAssuranceConfig(cwd, options.config)
79
+ routeAssurance = evaluateRouteAssurance(config.source, config.policy, {
80
+ ...(config.capabilities !== undefined
81
+ ? { definitions: config.capabilities.definitions }
82
+ : {}),
83
+ })
84
+ if (config.capabilities !== undefined) {
85
+ capability = await collectCapabilityProjectReport(cwd, config.source, config.capabilities)
86
+ }
87
+ } catch (error) {
88
+ configError = error
89
+ config = undefined
90
+ routeAssurance = undefined
91
+ capability = undefined
92
+ }
93
+
94
+ // The check view's assurance inputs. Fed to `check()` only when no custom config path was requested,
95
+ // so `nifra check` (which always reads the default `nifra.assurance.ts`) and `levels` L0 keep reading
96
+ // exactly the config they read before; a `--config` override stays a route-assurance/levels concern.
97
+ const checkContext: CheckAssuranceContext = {
98
+ present: assuranceConfigPresent,
99
+ ...(config !== undefined ? { config } : {}),
100
+ ...(configError !== undefined ? { error: configError } : {}),
101
+ ...(routeAssurance !== undefined ? { routeAssurance } : {}),
102
+ ...(capability !== undefined ? { capability } : {}),
103
+ }
104
+
105
+ let checkResult: Promise<CheckResult> | undefined
106
+ return Object.freeze({
107
+ cwd,
108
+ assuranceConfigPresent,
109
+ ...(config !== undefined ? { config } : {}),
110
+ ...(configError !== undefined ? { configError } : {}),
111
+ ...(routeAssurance !== undefined ? { routeAssurance } : {}),
112
+ ...(capability !== undefined ? { capability } : {}),
113
+ check(): Promise<CheckResult> {
114
+ checkResult ??= collectCheckResult(cwd, {
115
+ lintsOnly: options.lintsOnly ?? false,
116
+ ...(options.signal !== undefined ? { signal: options.signal } : {}),
117
+ ...(options.maxDiagnostics !== undefined ? { maxDiagnostics: options.maxDiagnostics } : {}),
118
+ ...(options.config === undefined ? { assurance: checkContext } : {}),
119
+ })
120
+ return checkResult
121
+ },
122
+ })
123
+ }