@nifrajs/cli 3.2.0 → 3.5.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.
- package/dist/check-diagnostics.d.ts +3 -15
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +149 -713
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +9 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +32 -0
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts +1 -0
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +63 -8
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +46 -7
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +4 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +28 -7
- package/dist/command-catalog.js.map +1 -1
- package/dist/contracts.d.ts +3 -2
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +4 -3
- package/dist/contracts.js.map +1 -1
- package/dist/diagnostics.d.ts +86 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +85 -0
- package/dist/diagnostics.js.map +1 -1
- package/dist/introspect.d.ts +1 -3
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +1 -47
- package/dist/introspect.js.map +1 -1
- package/dist/load.d.ts +5 -0
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js.map +1 -1
- package/dist/mcp-context.d.ts.map +1 -1
- package/dist/mcp-context.js +4 -5
- package/dist/mcp-context.js.map +1 -1
- package/dist/mcp-exec.d.ts +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +133 -25
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.d.ts.map +1 -1
- package/dist/mcp-http.js +4 -1
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-io.d.ts +12 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +68 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-path.d.ts +10 -0
- package/dist/mcp-path.d.ts.map +1 -0
- package/dist/mcp-path.js +51 -0
- package/dist/mcp-path.js.map +1 -0
- package/dist/mcp-reflect.d.ts.map +1 -1
- package/dist/mcp-reflect.js +2 -2
- package/dist/mcp-reflect.js.map +1 -1
- package/dist/mcp-render.d.ts.map +1 -1
- package/dist/mcp-render.js +62 -43
- package/dist/mcp-render.js.map +1 -1
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +14 -2
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp-run.d.ts.map +1 -1
- package/dist/mcp-run.js +82 -51
- package/dist/mcp-run.js.map +1 -1
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +84 -29
- package/dist/mcp.js.map +1 -1
- package/dist/project-facts.d.ts +23 -4
- package/dist/project-facts.d.ts.map +1 -1
- package/dist/project-facts.js +12 -2
- package/dist/project-facts.js.map +1 -1
- package/dist/review.d.ts +21 -0
- package/dist/review.d.ts.map +1 -0
- package/dist/review.js +819 -0
- package/dist/review.js.map +1 -0
- package/dist/rules/legacy.d.ts +3 -1
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +796 -34
- package/dist/rules/legacy.js.map +1 -1
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +23 -4
- package/dist/scaffold.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +4 -0
- package/dist/verification-plan.js.map +1 -1
- package/dist/work-graph.d.ts +3 -0
- package/dist/work-graph.d.ts.map +1 -1
- package/dist/work-graph.js +4 -3
- package/dist/work-graph.js.map +1 -1
- package/docs/examples.json +10 -4
- package/docs/llms-full.txt +500 -46
- package/docs/types.json +1123 -82
- package/package.json +10 -9
- package/src/check-diagnostics.ts +181 -796
- package/src/check-scan.ts +36 -0
- package/src/check.ts +65 -12
- package/src/cli.ts +53 -7
- package/src/command-catalog.ts +33 -7
- package/src/contracts.ts +12 -3
- package/src/diagnostics.ts +179 -0
- package/src/introspect.ts +3 -55
- package/src/load.ts +5 -0
- package/src/mcp-context.ts +4 -6
- package/src/mcp-exec.ts +142 -30
- package/src/mcp-http.ts +4 -1
- package/src/mcp-io.ts +73 -0
- package/src/mcp-path.ts +50 -0
- package/src/mcp-reflect.ts +3 -2
- package/src/mcp-render.ts +70 -40
- package/src/mcp-root.ts +13 -2
- package/src/mcp-run.ts +90 -50
- package/src/mcp.ts +87 -27
- package/src/project-facts.ts +37 -8
- package/src/review.ts +983 -0
- package/src/rules/legacy.ts +915 -35
- package/src/scaffold.ts +29 -4
- package/src/verification-plan.ts +14 -0
- package/src/work-graph.ts +13 -3
package/dist/rules/legacy.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { snapshotProjectEvidence } from "@nifrajs/core/evidence";
|
|
4
|
+
import { SINGLE_COPY_REGISTER_SPECIFIER } from "@nifrajs/core/single-copy";
|
|
5
|
+
import { IDENT, parseSimpleFetchCall, REMOVED_IMPORTS, SIMPLE_REWRITE_METHODS, } from "../check-scan.js";
|
|
6
|
+
import { diagnostic, diagnosticWithCompatibility, } from "../diagnostics.js";
|
|
1
7
|
/** Legacy rule name → stable NF- code. Exported so `nifra.check.json` rule overrides can be keyed
|
|
2
8
|
* by either name and still hit both diagnostic views. */
|
|
3
9
|
export const LEGACY_RULE_CODES = Object.freeze({
|
|
@@ -38,48 +44,804 @@ const TITLES = Object.freeze({
|
|
|
38
44
|
"check-config": "Check configuration check",
|
|
39
45
|
"contract-drift": "Contract snapshot drift",
|
|
40
46
|
});
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
/** The order used by the original human/legacy result. Structured diagnostics keep registry order. */
|
|
48
|
+
export const LEGACY_RULE_ORDER = Object.freeze([
|
|
49
|
+
"check-config",
|
|
50
|
+
"typecheck",
|
|
51
|
+
"typed-client",
|
|
52
|
+
"removed-import",
|
|
53
|
+
"untyped-client",
|
|
54
|
+
"server-only-import",
|
|
55
|
+
"interpolated-sql",
|
|
56
|
+
"response-route",
|
|
57
|
+
"undeclared-dependency",
|
|
58
|
+
"duplicate-install",
|
|
59
|
+
"stale-workspace-dist",
|
|
60
|
+
"pipeline",
|
|
61
|
+
"server-manifest-drift",
|
|
62
|
+
"capability-assurance",
|
|
63
|
+
"manifest-drift",
|
|
64
|
+
"capability-config",
|
|
65
|
+
"contract-drift",
|
|
66
|
+
]);
|
|
67
|
+
const FETCH_HINT = "hand-rolled fetch() to your own API - call it through client<typeof app> (from @nifrajs/client) so the compiler catches drift";
|
|
68
|
+
const STREAM_HINT = "hand-rolled EventSource/WebSocket to your own API - subscribe through client<typeof app> (`.subscribe()` for `app.sse()` routes, `.ws()` for `app.ws()` routes) so the compiler catches drift";
|
|
69
|
+
const SERVER_IMPORT_HINT = "server-only import in a route module (bundled for the browser) - reach it via c.db / ctx.api inside a loader, never a top-level import";
|
|
70
|
+
const RESPONSE_ROUTE_HINT = "route handler returns a raw Response - the typed client infers `data: never`, so drift detection is lost for this route. Return a plain object (it's serialized for you); for a stream use a typed SSE route (`app.sse(...)`), which keeps typed events; or, if a raw Response is intended (file/redirect), add `{ response: t.… }` or a `// nifra-expect raw-response` comment to mark it and silence this";
|
|
71
|
+
const PIPELINE_DOC_HINT = "nifra runs one bundler per phase - `vitePlugins` feed Vite, `clientPlugins`/`serverPlugins` feed Bun, and the file `nifra build` imports the adapter from is bundled into the server. See the Gotchas section of the Dev & HMR guide.";
|
|
72
|
+
const UNDECLARED_DEP_HINT = "imported package is not declared in package.json dependencies - run bun add to declare it";
|
|
73
|
+
const SQL_COMPILER_MISSING_HINT = "the interpolated-SQL rule did NOT run - it parses source with the TypeScript compiler, which is an optional peer and is not installed here. This report says nothing about SQL injection either way. Install it with `bun add -d typescript`";
|
|
74
|
+
const SQL_INTERPOLATION_EXAMPLE = "$" + "{value}";
|
|
75
|
+
const INTERPOLATED_SQL_HINT = `SQL built by interpolating a value into the statement text - the value becomes statement, not a parameter, so anything the caller controls can end the literal and continue as SQL. Pass it as a bound parameter (\`?\` / \`$1\` and an argument), or use your driver's tagged template (sql\`… ${SQL_INTERPOLATION_EXAMPLE} …\`), which binds the substitutions for you`;
|
|
76
|
+
const MANIFEST_DRIFT_HINT = "server-manifest.ts is out of sync with routes/ - re-run the build to regenerate it (a disk-less worker bakes this route table, so the drift is a silent edge break), then commit it";
|
|
77
|
+
const TRUST_MANIFEST_DRIFT_HINT = "nifra.manifest.json is missing, invalid, or out of sync - run `nifra manifest emit`, review it, and commit the regenerated trust artifact";
|
|
78
|
+
const CAPABILITY_HINT = "effect/capability assurance failed - align the route declaration with approved adapter provenance; never bypass an owned effect seam";
|
|
79
|
+
const TSC_LINE = /^(.+?)\((\d+),\d+\):\s*(?:error|warning)\s+TS\d+:\s*(.+)$/;
|
|
80
|
+
const UNTYPED_CLIENT_HINT = 'client("…") without a type argument - write client<typeof app>("…") (or client(contract, url)) so the compiler can catch drift';
|
|
81
|
+
function canonicalRecipe(rule) {
|
|
82
|
+
if (rule === "stale-workspace-dist")
|
|
43
83
|
return { recipe: "workspace-dist.rebuild", command: "nifra fix --code NF-C010" };
|
|
44
|
-
if (
|
|
84
|
+
if (rule === "server-manifest-drift")
|
|
45
85
|
return { recipe: "manifest.sync", command: "nifra sync-manifest" };
|
|
46
|
-
if (
|
|
86
|
+
if (rule === "contract-drift")
|
|
47
87
|
return { recipe: "contracts.snapshot", command: "nifra contracts snapshot" };
|
|
48
88
|
return undefined;
|
|
49
89
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
90
|
+
/** Build the stable structured diagnostic and attach only the data the legacy renderer needs. */
|
|
91
|
+
function legacyDiagnostic(rule, fields) {
|
|
92
|
+
const code = LEGACY_RULE_CODES[rule];
|
|
93
|
+
if (code === undefined)
|
|
94
|
+
throw new Error(`unknown legacy rule ${rule}`);
|
|
95
|
+
const evidence = fields.evidence ?? fields.chain;
|
|
96
|
+
const fix = canonicalRecipe(rule);
|
|
97
|
+
const canonical = {
|
|
55
98
|
code,
|
|
56
|
-
severity,
|
|
57
|
-
message:
|
|
58
|
-
...(
|
|
59
|
-
...(
|
|
60
|
-
...(evidence === undefined ? {} : { evidence }),
|
|
99
|
+
severity: fields.severity === "warning" ? "warn" : fields.severity,
|
|
100
|
+
message: fields.message,
|
|
101
|
+
...(fields.file === undefined ? {} : { file: fields.file }),
|
|
102
|
+
...(fields.line === undefined ? {} : { line: fields.line }),
|
|
103
|
+
...(evidence === undefined ? {} : { evidence: Object.freeze([...evidence]) }),
|
|
61
104
|
...(fix === undefined ? {} : { fix }),
|
|
62
|
-
...(
|
|
63
|
-
}
|
|
105
|
+
...(fields.verify === undefined ? {} : { verify: fields.verify }),
|
|
106
|
+
};
|
|
107
|
+
const compatibility = {
|
|
108
|
+
rule,
|
|
109
|
+
...(fields.fix === undefined ? {} : { fix: fields.fix }),
|
|
110
|
+
...(fields.suggestion === undefined ? {} : { suggestion: fields.suggestion }),
|
|
111
|
+
...(fields.chain === undefined ? {} : { chain: fields.chain }),
|
|
112
|
+
...(fields.includeCode === true ? { includeCode: true } : {}),
|
|
113
|
+
};
|
|
114
|
+
return diagnosticWithCompatibility(canonical, compatibility);
|
|
64
115
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return [];
|
|
69
|
-
const code = LEGACY_RULE_CODES[rule];
|
|
70
|
-
if (code === undefined)
|
|
71
|
-
return [];
|
|
72
|
-
return findings
|
|
73
|
-
.filter((finding) => finding?.rule === rule)
|
|
74
|
-
.map((finding) => toDiagnostic(finding, code));
|
|
116
|
+
const bySite = (a, b) => a.file.localeCompare(b.file) || a.line - b.line;
|
|
117
|
+
function oneLineDiff(file, line, before, after) {
|
|
118
|
+
return `--- ${file}:${line}\n+++ ${file}:${line}\n@@\n-${before}\n+${after}`;
|
|
75
119
|
}
|
|
76
|
-
function
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
120
|
+
function untypedClientSuggestion(f) {
|
|
121
|
+
const replacement = f.snippet.replace(/(?<![.\w])client\s*\(/, "client<typeof app>(");
|
|
122
|
+
return replacement === f.snippet
|
|
123
|
+
? {
|
|
124
|
+
kind: "manual",
|
|
125
|
+
title: "Add the app type argument to the client factory",
|
|
126
|
+
steps: [
|
|
127
|
+
'Change `client("...")` to `client<typeof app>("...")`.',
|
|
128
|
+
"Make sure the backend app type is imported or otherwise in scope.",
|
|
129
|
+
],
|
|
130
|
+
}
|
|
131
|
+
: {
|
|
132
|
+
kind: "edit",
|
|
133
|
+
title: "Insert `<typeof app>` into the client factory call",
|
|
134
|
+
diff: oneLineDiff(f.file, f.line, f.snippet, replacement),
|
|
135
|
+
steps: ["Make sure the backend app type is imported or otherwise in scope."],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function routeKey(method, path) {
|
|
139
|
+
return `${method.toUpperCase()} ${path}`;
|
|
140
|
+
}
|
|
141
|
+
function typedClientCall(method, path) {
|
|
142
|
+
const segs = path.split("/").filter((seg) => seg !== "");
|
|
143
|
+
let chain = "api";
|
|
144
|
+
if (segs.length === 0)
|
|
145
|
+
chain += ".index";
|
|
146
|
+
else {
|
|
147
|
+
for (const seg of segs) {
|
|
148
|
+
chain += IDENT.test(seg) ? `.${seg}` : `[${JSON.stringify(seg)}]`;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return `${chain}.${method.toLowerCase()}()`;
|
|
152
|
+
}
|
|
153
|
+
function staticRouteMap(routes) {
|
|
154
|
+
const out = new Map();
|
|
155
|
+
for (const route of routes) {
|
|
156
|
+
if (route.path.includes(":") || route.path.includes("*"))
|
|
157
|
+
continue;
|
|
158
|
+
const key = routeKey(route.method, route.path);
|
|
159
|
+
const bucket = out.get(key);
|
|
160
|
+
if (bucket === undefined)
|
|
161
|
+
out.set(key, [route]);
|
|
162
|
+
else
|
|
163
|
+
bucket.push(route);
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
166
|
+
}
|
|
167
|
+
function ownFetchEditSuggestion(f, routes) {
|
|
168
|
+
const call = parseSimpleFetchCall(f.snippet);
|
|
169
|
+
if (call === undefined || !SIMPLE_REWRITE_METHODS.has(call.method))
|
|
170
|
+
return undefined;
|
|
171
|
+
const matches = routes.get(routeKey(call.method, call.path));
|
|
172
|
+
if (matches === undefined || matches.length !== 1)
|
|
173
|
+
return undefined;
|
|
174
|
+
const replacementCall = typedClientCall(call.method, call.path);
|
|
175
|
+
const replacement = `${f.snippet.slice(0, call.start)}${replacementCall}${f.snippet.slice(call.end)}`;
|
|
176
|
+
if (replacement === f.snippet)
|
|
177
|
+
return undefined;
|
|
178
|
+
const route = matches[0];
|
|
179
|
+
if (route === undefined)
|
|
180
|
+
return undefined;
|
|
181
|
+
return {
|
|
182
|
+
kind: "edit",
|
|
183
|
+
title: "Rewrite simple own-API fetch to the typed nifra client",
|
|
184
|
+
diff: oneLineDiff(f.file, f.line, f.snippet, replacement),
|
|
185
|
+
steps: [
|
|
186
|
+
`Matched ${route.method} ${route.path} at ${route.file}:${route.line}.`,
|
|
187
|
+
"Use an in-scope typed client named `api` (`client<typeof app>(baseUrl)` or the route loader/action `api`).",
|
|
188
|
+
"Update downstream `Response` handling to branch on `{ ok, data, error }` if this variable is used later.",
|
|
189
|
+
],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function ownFetchSuggestion(f, routes) {
|
|
193
|
+
const exact = ownFetchEditSuggestion(f, routes);
|
|
194
|
+
if (exact !== undefined)
|
|
195
|
+
return exact;
|
|
196
|
+
return {
|
|
197
|
+
kind: "manual",
|
|
198
|
+
title: "Replace own-API fetch with the typed nifra client",
|
|
199
|
+
steps: [
|
|
200
|
+
"Call `nifra_routes` or read `nifra://routes` for the exact typed-client call form.",
|
|
201
|
+
"Create `const api = client<typeof app>(baseUrl)` from `@nifrajs/client`.",
|
|
202
|
+
"Replace the relative `fetch()` call with the generated `api...get/post/...` call and branch on `{ ok, data, error }`.",
|
|
203
|
+
],
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function ownStreamSuggestion() {
|
|
207
|
+
return {
|
|
208
|
+
kind: "manual",
|
|
209
|
+
title: "Replace own-API EventSource/WebSocket with the typed nifra client",
|
|
210
|
+
steps: [
|
|
211
|
+
"Call `nifra_routes` or read `nifra://routes` for the exact typed-client call form.",
|
|
212
|
+
"Create `const api = client<typeof app>(baseUrl)` from `@nifrajs/client`.",
|
|
213
|
+
'Replace `new EventSource("/…")` with the generated `api.…subscribe(onEvent)` call for the matching `app.sse()` route.',
|
|
214
|
+
'Replace `new WebSocket("/…")` with the generated `api.….ws()` handle for the matching `app.ws()` route.',
|
|
215
|
+
],
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function serverImportSuggestion(specifier, chain, fallback) {
|
|
219
|
+
const sink = chain[chain.length - 1] ?? specifier;
|
|
220
|
+
const chainStep = chain.length > 2
|
|
221
|
+
? fallback
|
|
222
|
+
? `Server-only code reaches this route through \`${chain.join(" → ")}\` (the deeper chain couldn't be resolved precisely - trace it from \`${specifier}\`).`
|
|
223
|
+
: `Server-only code reaches this route transitively: \`${chain.join(" → ")}\`. The sink is \`${sink}\`; break the chain at the first hop (\`${specifier}\`) or move the sink behind the server boundary.`
|
|
224
|
+
: undefined;
|
|
225
|
+
return {
|
|
226
|
+
kind: "manual",
|
|
227
|
+
title: "Move server-only code behind the route server boundary",
|
|
228
|
+
steps: [
|
|
229
|
+
...(chainStep === undefined ? [] : [chainStep]),
|
|
230
|
+
`Remove the top-level \`import … from "${specifier}"\` from this route module (it's bundled for the browser).`,
|
|
231
|
+
"Access backend/data work through the route `loader`/`action` context (`api`, `env`, or project server context).",
|
|
232
|
+
`If a direct module import is unavoidable, lazy-load it (\`await import("${specifier}")\`) inside the server-only loader/action path.`,
|
|
233
|
+
],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function responseRouteSuggestion() {
|
|
237
|
+
return {
|
|
238
|
+
kind: "manual",
|
|
239
|
+
title: "Preserve typed-client response inference",
|
|
240
|
+
steps: [
|
|
241
|
+
"Prefer returning a plain object from JSON routes; nifra serializes it for you.",
|
|
242
|
+
"For a stream, use a typed SSE route - `app.sse(...)` (or `sse(c, run)` from `@nifrajs/core/server`) - which keeps typed events instead of collapsing the client to `data: never`.",
|
|
243
|
+
"If this route must return a raw Response (redirect, file), declare an explicit response schema, or add a `// nifra-expect raw-response` comment above the return to mark it intentional and silence this advisory.",
|
|
244
|
+
],
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
const typecheckRule = {
|
|
248
|
+
code: LEGACY_RULE_CODES.typecheck,
|
|
249
|
+
title: TITLES.typecheck,
|
|
250
|
+
async scan(ctx) {
|
|
251
|
+
const tc = ctx.project.check.typecheck;
|
|
252
|
+
const findings = [];
|
|
253
|
+
if (tc.missingTypeScript === true) {
|
|
254
|
+
findings.push(legacyDiagnostic("typecheck", {
|
|
255
|
+
severity: "error",
|
|
256
|
+
file: "tsconfig.json",
|
|
257
|
+
message: "tsconfig.json is present but no `typescript` install was found from this directory upward - the typecheck gate did NOT run",
|
|
258
|
+
fix: "bun add -d typescript",
|
|
259
|
+
suggestion: {
|
|
260
|
+
kind: "command",
|
|
261
|
+
title: "Install TypeScript so the contract gate can run",
|
|
262
|
+
command: ["bun", "add", "-d", "typescript"],
|
|
263
|
+
},
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
if (tc.ran && !tc.ok) {
|
|
267
|
+
const lines = (tc.output ?? "").split("\n");
|
|
268
|
+
let matched = false;
|
|
269
|
+
for (const line of lines) {
|
|
270
|
+
const match = TSC_LINE.exec(line.trim());
|
|
271
|
+
if (match === null)
|
|
272
|
+
continue;
|
|
273
|
+
matched = true;
|
|
274
|
+
findings.push(legacyDiagnostic("typecheck", {
|
|
275
|
+
severity: "error",
|
|
276
|
+
file: match[1],
|
|
277
|
+
line: Number(match[2]),
|
|
278
|
+
message: match[3],
|
|
279
|
+
suggestion: {
|
|
280
|
+
kind: "manual",
|
|
281
|
+
title: "Fix the TypeScript contract error",
|
|
282
|
+
steps: [
|
|
283
|
+
"Open the reported file and line.",
|
|
284
|
+
"Align the handler, route schema, or typed-client call with the compiler error.",
|
|
285
|
+
"Run `nifra_check` again after the edit.",
|
|
286
|
+
],
|
|
287
|
+
},
|
|
288
|
+
}));
|
|
289
|
+
}
|
|
290
|
+
if (!matched) {
|
|
291
|
+
findings.push(legacyDiagnostic("typecheck", {
|
|
292
|
+
severity: "error",
|
|
293
|
+
message: tc.output || "typecheck failed",
|
|
294
|
+
suggestion: {
|
|
295
|
+
kind: "manual",
|
|
296
|
+
title: "Fix the TypeScript contract error",
|
|
297
|
+
steps: ["Run `tsc --noEmit` locally for the full compiler output."],
|
|
298
|
+
},
|
|
299
|
+
}));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return findings;
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
const typedClientRule = {
|
|
306
|
+
code: LEGACY_RULE_CODES["typed-client"],
|
|
307
|
+
title: TITLES["typed-client"],
|
|
308
|
+
async scan(ctx) {
|
|
309
|
+
const routes = staticRouteMap(ctx.project.routes);
|
|
310
|
+
const fetchFindings = [...ctx.project.sourceFindings.fetches].sort(bySite).map((finding) => legacyDiagnostic("typed-client", {
|
|
311
|
+
severity: "error",
|
|
312
|
+
file: finding.file,
|
|
313
|
+
line: finding.line,
|
|
314
|
+
message: `${finding.snippet} - ${FETCH_HINT}`,
|
|
315
|
+
fix: FETCH_HINT,
|
|
316
|
+
suggestion: ownFetchSuggestion(finding, routes),
|
|
317
|
+
}));
|
|
318
|
+
const streamFindings = [...ctx.project.sourceFindings.streams].sort(bySite).map((finding) => legacyDiagnostic("typed-client", {
|
|
319
|
+
severity: "error",
|
|
320
|
+
file: finding.file,
|
|
321
|
+
line: finding.line,
|
|
322
|
+
message: `${finding.snippet} - ${STREAM_HINT}`,
|
|
323
|
+
fix: STREAM_HINT,
|
|
324
|
+
suggestion: ownStreamSuggestion(),
|
|
325
|
+
}));
|
|
326
|
+
return [...fetchFindings, ...streamFindings].sort((a, b) => (a.file ?? "").localeCompare(b.file ?? "") || (a.line ?? 0) - (b.line ?? 0));
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
const removedImportRule = {
|
|
330
|
+
code: LEGACY_RULE_CODES["removed-import"],
|
|
331
|
+
title: TITLES["removed-import"],
|
|
332
|
+
async scan(ctx) {
|
|
333
|
+
return [...ctx.project.sourceFindings.removedImports].sort(bySite).map((finding) => {
|
|
334
|
+
const entry = REMOVED_IMPORTS.find((candidate) => finding.snippet.includes(`"${candidate.specifier}`) ||
|
|
335
|
+
finding.snippet.includes(`'${candidate.specifier}`));
|
|
336
|
+
const replacement = entry?.replacement ?? "see the changelog";
|
|
337
|
+
return legacyDiagnostic("removed-import", {
|
|
338
|
+
severity: "error",
|
|
339
|
+
file: finding.file,
|
|
340
|
+
line: finding.line,
|
|
341
|
+
message: `${finding.snippet} - removed in nifra ${entry?.since ?? "2.0"}: ${replacement}`,
|
|
342
|
+
fix: replacement,
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
const untypedClientRule = {
|
|
348
|
+
code: LEGACY_RULE_CODES["untyped-client"],
|
|
349
|
+
title: TITLES["untyped-client"],
|
|
350
|
+
async scan(ctx) {
|
|
351
|
+
return [...ctx.project.sourceFindings.untypedClients].sort(bySite).map((finding) => legacyDiagnostic("untyped-client", {
|
|
352
|
+
severity: "error",
|
|
353
|
+
file: finding.file,
|
|
354
|
+
line: finding.line,
|
|
355
|
+
message: `${finding.snippet} - ${UNTYPED_CLIENT_HINT}`,
|
|
356
|
+
fix: UNTYPED_CLIENT_HINT,
|
|
357
|
+
suggestion: untypedClientSuggestion(finding),
|
|
358
|
+
}));
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
const serverOnlyImportRule = {
|
|
362
|
+
code: LEGACY_RULE_CODES["server-only-import"],
|
|
363
|
+
title: TITLES["server-only-import"],
|
|
364
|
+
async scan(ctx) {
|
|
365
|
+
return [...ctx.project.importGraph].sort(bySite).map((finding) => {
|
|
366
|
+
const chain = finding.chain;
|
|
367
|
+
const sink = chain[chain.length - 1] ?? finding.specifier;
|
|
368
|
+
return legacyDiagnostic("server-only-import", {
|
|
369
|
+
severity: "error",
|
|
370
|
+
file: finding.file,
|
|
371
|
+
line: finding.line,
|
|
372
|
+
message: `${finding.snippet} - server-only "${sink}" reaches the browser bundle via ${chain.join(" → ")}${finding.fallback ? " (direct edge - couldn't resolve the transitive chain precisely)" : ""}; ${SERVER_IMPORT_HINT}`,
|
|
373
|
+
fix: SERVER_IMPORT_HINT,
|
|
374
|
+
chain,
|
|
375
|
+
suggestion: serverImportSuggestion(finding.specifier, chain, finding.fallback),
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
const interpolatedSqlRule = {
|
|
381
|
+
code: LEGACY_RULE_CODES["interpolated-sql"],
|
|
382
|
+
title: TITLES["interpolated-sql"],
|
|
383
|
+
async scan(ctx) {
|
|
384
|
+
const findings = [];
|
|
385
|
+
if (!ctx.project.check.sqlCompilerAvailable) {
|
|
386
|
+
findings.push(legacyDiagnostic("interpolated-sql", {
|
|
387
|
+
severity: "warning",
|
|
388
|
+
message: SQL_COMPILER_MISSING_HINT,
|
|
389
|
+
fix: SQL_COMPILER_MISSING_HINT,
|
|
390
|
+
suggestion: {
|
|
391
|
+
kind: "command",
|
|
392
|
+
title: "Install TypeScript so the SQL rule can run",
|
|
393
|
+
// Keep the one-element command array used by the legacy renderer for exact output.
|
|
394
|
+
command: ["bun add -d typescript"],
|
|
395
|
+
},
|
|
396
|
+
}));
|
|
397
|
+
}
|
|
398
|
+
for (const finding of [...ctx.project.sourceFindings.interpolatedSql].sort(bySite)) {
|
|
399
|
+
findings.push(legacyDiagnostic("interpolated-sql", {
|
|
400
|
+
severity: "error",
|
|
401
|
+
file: finding.file,
|
|
402
|
+
line: finding.line,
|
|
403
|
+
message: `${finding.snippet} - ${INTERPOLATED_SQL_HINT}`,
|
|
404
|
+
fix: "bind the value as a parameter instead of interpolating it into the statement",
|
|
405
|
+
suggestion: {
|
|
406
|
+
kind: "manual",
|
|
407
|
+
title: "Bind the value instead of interpolating it",
|
|
408
|
+
steps: [
|
|
409
|
+
"Replace the interpolation with a placeholder your driver understands (`?` for SQLite/MySQL, `$1` for Postgres).",
|
|
410
|
+
"Pass the value as an argument alongside the statement, so the driver binds it.",
|
|
411
|
+
`Or switch to the driver's tagged template (sql\`… ${SQL_INTERPOLATION_EXAMPLE} …\`): the tag receives substitutions separately and binds them.`,
|
|
412
|
+
"An identifier that genuinely cannot be bound (a table or column name) must be checked against an allowlist you control, never taken from the request.",
|
|
413
|
+
"If the statement is dynamic but every value is already bound (generating `($1),($2),…` for a batch insert), mark it with a `// nifra-expect sql-dynamic: <reason>` comment on the line above - the reason is required.",
|
|
414
|
+
],
|
|
415
|
+
},
|
|
416
|
+
}));
|
|
417
|
+
}
|
|
418
|
+
return findings;
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
const responseRouteRule = {
|
|
422
|
+
code: LEGACY_RULE_CODES["response-route"],
|
|
423
|
+
title: TITLES["response-route"],
|
|
424
|
+
async scan(ctx) {
|
|
425
|
+
return [...ctx.project.sourceFindings.responseRoutes].sort(bySite).map((finding) => legacyDiagnostic("response-route", {
|
|
426
|
+
severity: "warning",
|
|
427
|
+
file: finding.file,
|
|
428
|
+
line: finding.line,
|
|
429
|
+
message: `${finding.snippet} - ${RESPONSE_ROUTE_HINT}`,
|
|
430
|
+
fix: RESPONSE_ROUTE_HINT,
|
|
431
|
+
suggestion: responseRouteSuggestion(),
|
|
432
|
+
}));
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
function copyLines(finding) {
|
|
436
|
+
return finding.copies.map((copy) => `${finding.package}@${copy.version} at ${copy.absolutePath ?? copy.path} - pulled in by ${copy.importers.join(", ")}`);
|
|
437
|
+
}
|
|
438
|
+
function duplicateSuggestion(finding) {
|
|
439
|
+
const lines = copyLines(finding);
|
|
440
|
+
return {
|
|
441
|
+
kind: "manual",
|
|
442
|
+
title: `Resolve ${finding.package} to one loaded copy`,
|
|
443
|
+
diff: [
|
|
444
|
+
"package.json:",
|
|
445
|
+
` "nifra": { "singleCopy": ["${finding.package}"] }`,
|
|
446
|
+
"bunfig.toml:",
|
|
447
|
+
` preload = ["${SINGLE_COPY_REGISTER_SPECIFIER}"]`,
|
|
448
|
+
" [test]",
|
|
449
|
+
` preload = ["${SINGLE_COPY_REGISTER_SPECIFIER}"]`,
|
|
450
|
+
].join("\n"),
|
|
451
|
+
steps: [
|
|
452
|
+
...lines.map((line) => `Copy: ${line}`),
|
|
453
|
+
"Fix 1 - deduplicate: align workspace dependency and peer ranges on one compatible version, remove stale nested installs, and reinstall from the workspace root so every importer resolves one physical copy.",
|
|
454
|
+
`Fix 2 - declare single-copy: apply the package.json and bunfig.toml config printed above; nifra then rewrites every duplicate to this app's copy.${finding.cause === "version-skew" ? " A declaration only covers same-version duplicates, so fix 1's range alignment must land first." : ""}`,
|
|
455
|
+
"Re-run `nifra check`; the gate stays failing until one fix lands.",
|
|
456
|
+
],
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
const doctorRules = Object.freeze([
|
|
460
|
+
{
|
|
461
|
+
code: LEGACY_RULE_CODES["undeclared-dependency"],
|
|
462
|
+
title: TITLES["undeclared-dependency"],
|
|
463
|
+
async scan(ctx) {
|
|
464
|
+
const doctor = ctx.project.packages.doctor;
|
|
465
|
+
if (!doctor.ran)
|
|
466
|
+
return [];
|
|
467
|
+
return doctor.findings.map((finding) => legacyDiagnostic("undeclared-dependency", {
|
|
468
|
+
severity: "error",
|
|
469
|
+
file: finding.file,
|
|
470
|
+
line: finding.line,
|
|
471
|
+
message: `imports ${finding.package} which is not declared in package.json - ${UNDECLARED_DEP_HINT}`,
|
|
472
|
+
fix: `add ${finding.package} to package.json dependencies`,
|
|
473
|
+
suggestion: {
|
|
474
|
+
kind: "command",
|
|
475
|
+
title: `Declare ${finding.package} in package.json`,
|
|
476
|
+
command: ["bun", "add", finding.package],
|
|
477
|
+
},
|
|
478
|
+
}));
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
code: LEGACY_RULE_CODES["duplicate-install"],
|
|
483
|
+
title: TITLES["duplicate-install"],
|
|
484
|
+
async scan(ctx) {
|
|
485
|
+
const doctor = ctx.project.packages.doctor;
|
|
486
|
+
if (!doctor.ran)
|
|
487
|
+
return [];
|
|
488
|
+
const findings = [];
|
|
489
|
+
for (const finding of doctor.duplicateInstalls) {
|
|
490
|
+
const copies = copyLines(finding);
|
|
491
|
+
findings.push(legacyDiagnostic("duplicate-install", {
|
|
492
|
+
severity: "error",
|
|
493
|
+
message: `${finding.package} identity preflight found ${finding.cause} - ${finding.explanation}${finding.topology === undefined ? "" : `. Topology: ${finding.topology}`}${finding.scope === undefined ? "" : `. Scope: ${finding.scope}`}`,
|
|
494
|
+
fix: finding.remediation,
|
|
495
|
+
evidence: copies,
|
|
496
|
+
suggestion: duplicateSuggestion(finding),
|
|
497
|
+
}));
|
|
498
|
+
}
|
|
499
|
+
for (const finding of doctor.deduplicatedInstalls ?? []) {
|
|
500
|
+
const paths = finding.copies.map((copy) => copy.path).join("; ");
|
|
501
|
+
findings.push(legacyDiagnostic("duplicate-install", {
|
|
502
|
+
severity: "warning",
|
|
503
|
+
message: `${finding.package} is installed at ${finding.copies.length} paths (${paths}) and is declared single-copy - nifra resolves every duplicate to this app's copy`,
|
|
504
|
+
fix: finding.remediation,
|
|
505
|
+
}));
|
|
506
|
+
}
|
|
507
|
+
return findings;
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
code: LEGACY_RULE_CODES["stale-workspace-dist"],
|
|
512
|
+
title: TITLES["stale-workspace-dist"],
|
|
513
|
+
async scan(ctx) {
|
|
514
|
+
const doctor = ctx.project.packages.doctor;
|
|
515
|
+
if (!doctor.ran)
|
|
516
|
+
return [];
|
|
517
|
+
return doctor.staleDists.map((finding) => {
|
|
518
|
+
const rebuild = finding.buildScript === undefined
|
|
519
|
+
? `${finding.packageDir} declares no build script - build it the way that package expects`
|
|
520
|
+
: `cd ${finding.packageDir} && bun run ${finding.buildScript} (or \`nifra fix --code NF-C010\`)`;
|
|
521
|
+
return legacyDiagnostic("stale-workspace-dist", {
|
|
522
|
+
severity: "warning",
|
|
523
|
+
message: finding.missing
|
|
524
|
+
? `${finding.package} was never built - ${finding.distFile} is missing, but its export map serves it to Vite SSR/node consumers while Bun reads src - ${rebuild}`
|
|
525
|
+
: `${finding.package} has a stale build artifact - ${finding.behindSeconds}s older than ${finding.sourceFile}, and Vite SSR/node consumers read the artifact while Bun reads src - ${rebuild}`,
|
|
526
|
+
fix: rebuild,
|
|
527
|
+
evidence: [finding.package, finding.distFile, finding.sourceFile, finding.packageDir],
|
|
528
|
+
suggestion: {
|
|
529
|
+
kind: "manual",
|
|
530
|
+
title: `Rebuild ${finding.package}`,
|
|
531
|
+
steps: [
|
|
532
|
+
rebuild,
|
|
533
|
+
"Only workspace-linked installs drift; npm tarballs are immutable and never flagged.",
|
|
534
|
+
],
|
|
535
|
+
},
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
]);
|
|
541
|
+
const pipelineRule = {
|
|
542
|
+
code: LEGACY_RULE_CODES.pipeline,
|
|
543
|
+
title: TITLES.pipeline,
|
|
544
|
+
async scan(ctx) {
|
|
545
|
+
return (ctx.project.packages.doctor.pipeline?.findings ?? []).map((finding) => legacyDiagnostic("pipeline", {
|
|
546
|
+
severity: finding.severity,
|
|
547
|
+
file: finding.file,
|
|
548
|
+
...(finding.line === undefined ? {} : { line: finding.line }),
|
|
549
|
+
message: finding.message,
|
|
550
|
+
fix: finding.fix,
|
|
551
|
+
suggestion: { kind: "manual", title: finding.fix, steps: [PIPELINE_DOC_HINT] },
|
|
552
|
+
}));
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
const serverManifestRule = {
|
|
556
|
+
code: LEGACY_RULE_CODES["server-manifest-drift"],
|
|
557
|
+
title: TITLES["server-manifest-drift"],
|
|
558
|
+
async scan(ctx) {
|
|
559
|
+
return ctx.project.packages.manifestDrift.map((finding) => {
|
|
560
|
+
const parts = [];
|
|
561
|
+
if (finding.missing.length > 0)
|
|
562
|
+
parts.push(`missing from manifest: ${finding.missing.join(", ")}`);
|
|
563
|
+
if (finding.extra.length > 0)
|
|
564
|
+
parts.push(`stale in manifest: ${finding.extra.join(", ")}`);
|
|
565
|
+
return legacyDiagnostic("server-manifest-drift", {
|
|
566
|
+
severity: "error",
|
|
567
|
+
file: finding.file,
|
|
568
|
+
message: `${finding.file} drifted from routes/ (${parts.join("; ")}) - ${MANIFEST_DRIFT_HINT}`,
|
|
569
|
+
fix: MANIFEST_DRIFT_HINT,
|
|
570
|
+
evidence: [...finding.missing, ...finding.extra],
|
|
571
|
+
suggestion: {
|
|
572
|
+
kind: "manual",
|
|
573
|
+
title: "Regenerate the committed server manifest",
|
|
574
|
+
steps: [
|
|
575
|
+
"Re-run your build (`nifra build --target <t>` or your build script) - it regenerates server-manifest.ts from the current routes/.",
|
|
576
|
+
"Commit the updated server-manifest.ts.",
|
|
577
|
+
],
|
|
578
|
+
},
|
|
579
|
+
});
|
|
580
|
+
});
|
|
581
|
+
},
|
|
582
|
+
};
|
|
583
|
+
function capabilityContext(ctx) {
|
|
584
|
+
const assurance = ctx.project.policies.assurance;
|
|
585
|
+
if (assurance === undefined || !assurance.present || assurance.error !== undefined)
|
|
586
|
+
return undefined;
|
|
587
|
+
if (assurance.config === undefined)
|
|
588
|
+
return undefined;
|
|
589
|
+
return {
|
|
590
|
+
config: assurance.config,
|
|
591
|
+
...(assurance.capability === undefined ? {} : { project: assurance.capability }),
|
|
592
|
+
...(assurance.routeAssurance === undefined ? {} : { routeAssurance: assurance.routeAssurance }),
|
|
593
|
+
...(assurance.evidence === undefined ? {} : { evidence: assurance.evidence }),
|
|
594
|
+
};
|
|
82
595
|
}
|
|
83
|
-
|
|
84
|
-
|
|
596
|
+
const capabilityAssuranceRule = {
|
|
597
|
+
code: LEGACY_RULE_CODES["capability-assurance"],
|
|
598
|
+
title: TITLES["capability-assurance"],
|
|
599
|
+
async scan(ctx) {
|
|
600
|
+
const context = capabilityContext(ctx);
|
|
601
|
+
const project = context?.project;
|
|
602
|
+
const config = context?.config;
|
|
603
|
+
if (project === undefined || config?.capabilities === undefined)
|
|
604
|
+
return [];
|
|
605
|
+
const findings = [];
|
|
606
|
+
for (const finding of project.report.findings) {
|
|
607
|
+
const violation = finding.code === "forbidden-effect-import"
|
|
608
|
+
? project.violations.find((candidate) => candidate.method === finding.method && candidate.path === finding.path)
|
|
609
|
+
: undefined;
|
|
610
|
+
const truncation = finding.code === "provenance-truncated"
|
|
611
|
+
? project.truncations.find((candidate) => candidate.method === finding.method && candidate.path === finding.path)
|
|
612
|
+
: undefined;
|
|
613
|
+
const seamFix = finding.code === "unmatched-provenance-seam"
|
|
614
|
+
? "Write the seam exactly as the code imports it, or delete the rule."
|
|
615
|
+
: undefined;
|
|
616
|
+
findings.push(legacyDiagnostic("capability-assurance", {
|
|
617
|
+
severity: "error",
|
|
618
|
+
...(violation === undefined
|
|
619
|
+
? truncation === undefined
|
|
620
|
+
? {}
|
|
621
|
+
: { chain: truncation.chain }
|
|
622
|
+
: { file: violation.module, chain: violation.chain }),
|
|
623
|
+
message: `${finding.message}${seamFix === undefined ? ` - ${CAPABILITY_HINT}` : ""}`,
|
|
624
|
+
fix: seamFix ?? CAPABILITY_HINT,
|
|
625
|
+
suggestion: seamFix === undefined
|
|
626
|
+
? {
|
|
627
|
+
kind: "manual",
|
|
628
|
+
title: "Restore declared effect provenance",
|
|
629
|
+
steps: [
|
|
630
|
+
"Route effectful work through an import listed in capabilities.provenance.imports.",
|
|
631
|
+
"Declare the exact capability token on the route; do not widen unrelated routes in the same file.",
|
|
632
|
+
"For domain writes, add the adapter the capability definition requires: `schema.idempotency` for the `request` tier, `.use(durableCommand({ journal }))` from @nifrajs/middleware for the `durable` tier.",
|
|
633
|
+
"Run `nifra capabilities snapshot` only after assurance passes, then review the lockfile diff.",
|
|
634
|
+
],
|
|
635
|
+
}
|
|
636
|
+
: {
|
|
637
|
+
kind: "manual",
|
|
638
|
+
title: "Point the provenance rule at a module that exists",
|
|
639
|
+
steps: [
|
|
640
|
+
"Copy the specifier from the import statement itself - it is matched as written, with no extension or index resolution.",
|
|
641
|
+
"Use a trailing `/*` when the seam is a directory of modules (`@myorg/db/*`).",
|
|
642
|
+
"For a routeModules entry, give the project-relative path of the file that implements the route.",
|
|
643
|
+
"Delete the rule if the seam it governed is gone; leaving it in place proves nothing.",
|
|
644
|
+
],
|
|
645
|
+
},
|
|
646
|
+
}));
|
|
647
|
+
}
|
|
648
|
+
return findings;
|
|
649
|
+
},
|
|
650
|
+
};
|
|
651
|
+
const manifestRule = {
|
|
652
|
+
code: LEGACY_RULE_CODES["manifest-drift"],
|
|
653
|
+
title: TITLES["manifest-drift"],
|
|
654
|
+
async scan(ctx) {
|
|
655
|
+
const context = capabilityContext(ctx);
|
|
656
|
+
if (context === undefined || context.config.manifest === undefined)
|
|
657
|
+
return [];
|
|
658
|
+
const { config, project, routeAssurance: knownAssurance } = context;
|
|
659
|
+
const capabilityReport = project?.report;
|
|
660
|
+
let assurance = knownAssurance;
|
|
661
|
+
let evidence = context.evidence;
|
|
662
|
+
try {
|
|
663
|
+
if (assurance === undefined) {
|
|
664
|
+
const { evaluateRouteAssurance } = await import("@nifrajs/core/assurance");
|
|
665
|
+
assurance = evaluateRouteAssurance(config.source, config.policy, {
|
|
666
|
+
...(config.capabilities === undefined
|
|
667
|
+
? {}
|
|
668
|
+
: { definitions: config.capabilities.definitions }),
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
evidence ??= snapshotProjectEvidence(config.source, {
|
|
672
|
+
assurance,
|
|
673
|
+
...(capabilityReport === undefined ? {} : { capabilities: capabilityReport }),
|
|
674
|
+
});
|
|
675
|
+
const manifest = config.manifest;
|
|
676
|
+
if (manifest === undefined)
|
|
677
|
+
return [];
|
|
678
|
+
const path = resolve(ctx.root, manifest.path ?? "nifra.manifest.json");
|
|
679
|
+
let message;
|
|
680
|
+
if (!assurance.ok || (capabilityReport !== undefined && !capabilityReport.ok)) {
|
|
681
|
+
message =
|
|
682
|
+
"the configured assurance policy is failing, so a trusted manifest cannot be built";
|
|
683
|
+
}
|
|
684
|
+
else if (!existsSync(path)) {
|
|
685
|
+
message = "the configured trust manifest is missing";
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
try {
|
|
689
|
+
const { buildNifraManifest, parseNifraManifest, serializeNifraManifest } = await import("@nifrajs/core/manifest");
|
|
690
|
+
const current = await buildNifraManifest({
|
|
691
|
+
evidence,
|
|
692
|
+
assurance,
|
|
693
|
+
...(capabilityReport === undefined ? {} : { capabilities: capabilityReport }),
|
|
694
|
+
});
|
|
695
|
+
const storedText = await Bun.file(path).text();
|
|
696
|
+
const stored = await parseNifraManifest(storedText, path);
|
|
697
|
+
const expectedText = `${serializeNifraManifest(current)}\n`;
|
|
698
|
+
if (storedText !== expectedText || stored.contentHash !== current.contentHash) {
|
|
699
|
+
message = "the configured trust manifest does not match live route reflection";
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
catch (error) {
|
|
703
|
+
message = `the configured trust manifest is invalid: ${error instanceof Error ? error.message : String(error)}`;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
if (message === undefined)
|
|
707
|
+
return [];
|
|
708
|
+
return [
|
|
709
|
+
legacyDiagnostic("manifest-drift", {
|
|
710
|
+
severity: "error",
|
|
711
|
+
file: path,
|
|
712
|
+
message: `${message} - ${TRUST_MANIFEST_DRIFT_HINT}`,
|
|
713
|
+
fix: TRUST_MANIFEST_DRIFT_HINT,
|
|
714
|
+
suggestion: {
|
|
715
|
+
kind: "command",
|
|
716
|
+
title: "Regenerate the signed-manifest input artifact",
|
|
717
|
+
command: ["nifra", "manifest", "emit"],
|
|
718
|
+
steps: [
|
|
719
|
+
"Review the route, assurance, capability, and classification delta before committing it.",
|
|
720
|
+
],
|
|
721
|
+
},
|
|
722
|
+
}),
|
|
723
|
+
];
|
|
724
|
+
}
|
|
725
|
+
catch {
|
|
726
|
+
// A config-load failure is owned and reported by capability-config. Do not duplicate it as a
|
|
727
|
+
// manifest failure, because there is no trustworthy input from which to compare a manifest.
|
|
728
|
+
return [];
|
|
729
|
+
}
|
|
730
|
+
},
|
|
731
|
+
};
|
|
732
|
+
const capabilityConfigRule = {
|
|
733
|
+
code: LEGACY_RULE_CODES["capability-config"],
|
|
734
|
+
title: TITLES["capability-config"],
|
|
735
|
+
async scan(ctx) {
|
|
736
|
+
const assurance = ctx.project.policies.assurance;
|
|
737
|
+
if (assurance === undefined || !assurance.present)
|
|
738
|
+
return [];
|
|
739
|
+
if (assurance.error === undefined && assurance.config !== undefined)
|
|
740
|
+
return [];
|
|
741
|
+
const error = assurance.error;
|
|
742
|
+
return [
|
|
743
|
+
legacyDiagnostic("capability-config", {
|
|
744
|
+
severity: "error",
|
|
745
|
+
file: "nifra.assurance.ts",
|
|
746
|
+
message: `capability assurance config could not be evaluated: ${error instanceof Error ? error.message : String(error ?? "configuration unavailable")}`,
|
|
747
|
+
suggestion: {
|
|
748
|
+
kind: "manual",
|
|
749
|
+
title: "Repair the assurance config",
|
|
750
|
+
steps: [
|
|
751
|
+
"Ensure nifra.assurance.ts default-exports defineAssuranceConfig({ source, policy, capabilities }).",
|
|
752
|
+
"Fix configuration/import errors; the provenance firewall fails closed when its policy cannot load.",
|
|
753
|
+
],
|
|
754
|
+
},
|
|
755
|
+
}),
|
|
756
|
+
];
|
|
757
|
+
},
|
|
758
|
+
};
|
|
759
|
+
const checkConfigRule = {
|
|
760
|
+
code: LEGACY_RULE_CODES["check-config"],
|
|
761
|
+
title: TITLES["check-config"],
|
|
762
|
+
async scan(ctx) {
|
|
763
|
+
const { checkConfigError, checkConfigWarnings } = ctx.project.check;
|
|
764
|
+
const findings = [];
|
|
765
|
+
if (checkConfigError !== undefined) {
|
|
766
|
+
findings.push(legacyDiagnostic("check-config", {
|
|
767
|
+
severity: "warning",
|
|
768
|
+
file: "nifra.check.json",
|
|
769
|
+
message: `nifra.check.json could not be parsed (${checkConfigError}) - its external-mount allowlist was ignored`,
|
|
770
|
+
fix: "Fix the JSON syntax in nifra.check.json",
|
|
771
|
+
}));
|
|
772
|
+
}
|
|
773
|
+
for (const warning of checkConfigWarnings) {
|
|
774
|
+
findings.push(legacyDiagnostic("check-config", {
|
|
775
|
+
severity: "warning",
|
|
776
|
+
file: "nifra.check.json",
|
|
777
|
+
message: `nifra.check.json: ${warning}`,
|
|
778
|
+
fix: "Fix the entry in nifra.check.json",
|
|
779
|
+
}));
|
|
780
|
+
}
|
|
781
|
+
return findings;
|
|
782
|
+
},
|
|
783
|
+
};
|
|
784
|
+
const contractRule = {
|
|
785
|
+
code: LEGACY_RULE_CODES["contract-drift"],
|
|
786
|
+
title: TITLES["contract-drift"],
|
|
787
|
+
async scan(ctx) {
|
|
788
|
+
const contract = ctx.project.check.contracts;
|
|
789
|
+
if (!contract.present) {
|
|
790
|
+
return [
|
|
791
|
+
diagnostic({
|
|
792
|
+
code: LEGACY_RULE_CODES["contract-drift"],
|
|
793
|
+
severity: "info",
|
|
794
|
+
message: "no contract lock; run `nifra contracts snapshot` to enable drift detection",
|
|
795
|
+
verify: "nifra contracts snapshot",
|
|
796
|
+
}),
|
|
797
|
+
];
|
|
798
|
+
}
|
|
799
|
+
if (contract.vacuous) {
|
|
800
|
+
return [
|
|
801
|
+
diagnostic({
|
|
802
|
+
code: LEGACY_RULE_CODES["contract-drift"],
|
|
803
|
+
severity: "info",
|
|
804
|
+
message: "no route schemas declared - the trust manifest is vacuous: every contract hash is the empty-schema digest, so drift detection guards nothing. Declare route schemas (body/query/params/response) so the lock has a contract to protect.",
|
|
805
|
+
verify: "nifra check --lints-only",
|
|
806
|
+
}),
|
|
807
|
+
];
|
|
808
|
+
}
|
|
809
|
+
if (contract.error !== undefined) {
|
|
810
|
+
return [
|
|
811
|
+
legacyDiagnostic("contract-drift", {
|
|
812
|
+
severity: "error",
|
|
813
|
+
message: `contract lock could not be checked: ${contract.error}`,
|
|
814
|
+
includeCode: true,
|
|
815
|
+
verify: "nifra contracts snapshot",
|
|
816
|
+
}),
|
|
817
|
+
];
|
|
818
|
+
}
|
|
819
|
+
return contract.diagnostics.map((finding) => legacyDiagnostic("contract-drift", {
|
|
820
|
+
severity: "error",
|
|
821
|
+
...(finding.route === undefined ? {} : { evidence: [finding.route] }),
|
|
822
|
+
message: finding.message,
|
|
823
|
+
fix: "run `nifra contracts snapshot` after reviewing the contract change",
|
|
824
|
+
includeCode: true,
|
|
825
|
+
verify: "nifra check --lints-only",
|
|
826
|
+
}));
|
|
827
|
+
},
|
|
828
|
+
};
|
|
829
|
+
/** Built-in rules that used to be formatted imperatively in check-diagnostics.ts. */
|
|
830
|
+
export const legacyRules = Object.freeze([
|
|
831
|
+
typecheckRule,
|
|
832
|
+
typedClientRule,
|
|
833
|
+
untypedClientRule,
|
|
834
|
+
serverOnlyImportRule,
|
|
835
|
+
removedImportRule,
|
|
836
|
+
interpolatedSqlRule,
|
|
837
|
+
responseRouteRule,
|
|
838
|
+
...doctorRules,
|
|
839
|
+
pipelineRule,
|
|
840
|
+
serverManifestRule,
|
|
841
|
+
manifestRule,
|
|
842
|
+
capabilityAssuranceRule,
|
|
843
|
+
capabilityConfigRule,
|
|
844
|
+
checkConfigRule,
|
|
845
|
+
contractRule,
|
|
846
|
+
]);
|
|
85
847
|
//# sourceMappingURL=legacy.js.map
|