@boringparts/verule 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/additional-inputs.d.ts +13 -0
- package/dist/additional-inputs.js +68 -0
- package/dist/cli-command-identity.d.ts +13 -0
- package/dist/cli-command-identity.js +15 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +42 -0
- package/dist/config-loader.d.ts +14 -0
- package/dist/config-loader.js +105 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/inline-ignore.d.ts +44 -0
- package/dist/inline-ignore.js +297 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.js +594 -0
- package/dist/observation.d.ts +111 -0
- package/dist/observation.js +767 -0
- package/dist/projects.d.ts +21 -0
- package/dist/projects.js +168 -0
- package/dist/report-wire.d.ts +1623 -0
- package/dist/report-wire.js +738 -0
- package/dist/session-command.d.ts +48 -0
- package/dist/session-command.js +73 -0
- package/dist/session.d.ts +18 -0
- package/dist/session.js +812 -0
- package/dist/shared-session.d.ts +13 -0
- package/dist/shared-session.js +338 -0
- package/dist/types.d.ts +328 -0
- package/dist/types.js +41 -0
- package/dist/watch-command.d.ts +839 -0
- package/dist/watch-command.js +104 -0
- package/dist/watch.d.ts +59 -0
- package/dist/watch.js +806 -0
- package/package.json +44 -3
- package/README.md +0 -3
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type WriteCliOutput } from "@ykdz/cli-contract";
|
|
2
|
+
import type { CliCommandIdentity } from "./cli-command-identity.ts";
|
|
3
|
+
type CliRuntime = {
|
|
4
|
+
readonly argv: readonly string[];
|
|
5
|
+
readonly cwd?: string;
|
|
6
|
+
readonly write: WriteCliOutput;
|
|
7
|
+
readonly identity: CliCommandIdentity;
|
|
8
|
+
readonly signal?: AbortSignal;
|
|
9
|
+
};
|
|
10
|
+
/** Returns the process status after all output has been written. */
|
|
11
|
+
export declare function runCli(runtime: CliRuntime): Promise<number>;
|
|
12
|
+
export {};
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
import { performance } from "node:perf_hooks";
|
|
3
|
+
import { CliWriteError, defineCli, executeCli, helpCapability, parseCliInvocation, schemaCapability, text, versionCapability, } from "@ykdz/cli-contract";
|
|
4
|
+
import { isNodeBrokenPipe } from "@ykdz/cli-contract/node";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { loadProjectConfigWithDependencies } from "./config-loader.js";
|
|
7
|
+
import { REPORT_SCHEMA_VERSION, VeruleExecutionError, getEngineVersion, parseObserveLimit, requestSharedReport, runCheck, } from "./index.js";
|
|
8
|
+
import { appendGapLines, checkFailureSchema, checkReportSchema, formatDiagnosticsLines, formatScopeLines, toWireFactConflict, toWireReport, } from "./report-wire.js";
|
|
9
|
+
import { formatSessionReadyText, sessionReadyRecordSchema, streamSharedSession, } from "./session-command.js";
|
|
10
|
+
import { formatWatchReportText, streamWatchEvents, watchFailureRecordSchema, watchReportRecordSchema, } from "./watch-command.js";
|
|
11
|
+
function appendExplanationLines(lines, exp) {
|
|
12
|
+
const linePart = exp.target.line !== undefined ? `:${exp.target.line}` : "";
|
|
13
|
+
const colPart = exp.target.column !== undefined ? `:${exp.target.column}` : "";
|
|
14
|
+
lines.push(`Explanation [${exp.ruleId}] @ ${exp.target.file}${linePart}${colPart}: ${exp.status} (inCandidates=${String(exp.inCandidates)})`);
|
|
15
|
+
lines.push(` summary: ${exp.summary}`);
|
|
16
|
+
if (exp.inlineIgnore?.matched) {
|
|
17
|
+
const atSuffix = exp.inlineIgnore.commentAt
|
|
18
|
+
? ` at ${exp.inlineIgnore.commentAt.file}:${exp.inlineIgnore.commentAt.line}:${exp.inlineIgnore.commentAt.column}`
|
|
19
|
+
: "";
|
|
20
|
+
const reasonSuffix = exp.inlineIgnore.reason
|
|
21
|
+
? ` -- ${exp.inlineIgnore.reason}`
|
|
22
|
+
: "";
|
|
23
|
+
lines.push(` inlineIgnore: suppressed by verule-ignore-next-code-line${atSuffix}${reasonSuffix}`);
|
|
24
|
+
}
|
|
25
|
+
if (exp.excludedByCheckpoint) {
|
|
26
|
+
const detailSuffix = exp.excludedByCheckpoint.detail !== undefined
|
|
27
|
+
? ` detail=${JSON.stringify(exp.excludedByCheckpoint.detail)}`
|
|
28
|
+
: "";
|
|
29
|
+
lines.push(` excludedByCheckpoint: ${exp.excludedByCheckpoint.name} (${exp.excludedByCheckpoint.outcome})${detailSuffix}`);
|
|
30
|
+
}
|
|
31
|
+
if (exp.excludedByQuery) {
|
|
32
|
+
lines.push(` excludedByQuery: ${exp.excludedByQuery.op} (provider=${exp.excludedByQuery.provider}, cache=${exp.excludedByQuery.cacheStatus}, candidates=${exp.excludedByQuery.candidateCount})`);
|
|
33
|
+
}
|
|
34
|
+
if (exp.providers.length > 0) {
|
|
35
|
+
lines.push(` providers: ${exp.providers.join(", ")}`);
|
|
36
|
+
}
|
|
37
|
+
for (const evalEntry of exp.providerEvaluations) {
|
|
38
|
+
const factPart = evalEntry.factTypeId ? ` (${evalEntry.factTypeId})` : "";
|
|
39
|
+
const reasonPart = evalEntry.reason ? `: ${evalEntry.reason}` : "";
|
|
40
|
+
lines.push(` provider [${evalEntry.status}] ${evalEntry.providerId}${factPart}${reasonPart}`);
|
|
41
|
+
}
|
|
42
|
+
for (const gap of exp.gaps) {
|
|
43
|
+
const atSuffix = gap.at
|
|
44
|
+
? ` (${gap.at.file}:${gap.at.line}:${gap.at.column})`
|
|
45
|
+
: "";
|
|
46
|
+
lines.push(` gap [${gap.kind}]: ${gap.message}${atSuffix}`);
|
|
47
|
+
}
|
|
48
|
+
for (const local of exp.localGaps) {
|
|
49
|
+
const fieldPart = local.field ? ` field=${local.field}` : "";
|
|
50
|
+
const gapAt = local.gap.at
|
|
51
|
+
? ` at ${local.gap.at.file}:${local.gap.at.line}:${local.gap.at.column}`
|
|
52
|
+
: "";
|
|
53
|
+
const resolvedPart = local.resolvedBy
|
|
54
|
+
? ` -> resolved_by ${local.resolvedBy.providerId} (${local.resolvedBy.operation}: ${local.resolvedBy.conclusion}${local.resolvedBy.at
|
|
55
|
+
? ` at ${local.resolvedBy.at.file}:${local.resolvedBy.at.line}:${local.resolvedBy.at.column}`
|
|
56
|
+
: ""})`
|
|
57
|
+
: "";
|
|
58
|
+
const impactPart = local.impact ? ` [${local.impact}]` : "";
|
|
59
|
+
lines.push(` localGap [${local.status}] ${local.factTypeId} (${local.providerId})${fieldPart}: ${local.gap.message}${gapAt}${resolvedPart}${impactPart}`);
|
|
60
|
+
}
|
|
61
|
+
for (const cp of exp.cleanupPaths) {
|
|
62
|
+
const sites = cp.cleanupLocations
|
|
63
|
+
.map((loc) => `${loc.file}:${loc.line}:${loc.column}`)
|
|
64
|
+
.join(", ");
|
|
65
|
+
lines.push(` cleanupPath [${cp.instanceKey}]: ${cp.summary} (${sites})`);
|
|
66
|
+
}
|
|
67
|
+
for (const query of exp.queries) {
|
|
68
|
+
lines.push(` query #${query.queryIndex}: ${query.op} [provider=${query.provider}, cache=${query.cacheStatus}] candidates=${query.candidateCount} matchedTarget=${String(query.matchedTarget)}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function appendObservationLines(lines, obs) {
|
|
72
|
+
lines.push(`Observation (${obs.mode}): total=${obs.phases.totalMs}ms (configOpen=${obs.phases.configAndOpenMs}ms, engineQuery=${obs.phases.engineQueryMs}ms, ruleExec=${obs.phases.ruleExecutionMs}ms)`);
|
|
73
|
+
lines.push(` rpc: batches=${obs.rpc.batches} (queryBatches=${obs.rpc.queryBatches}), bytesSent=${obs.rpc.bytesSent}, bytesReceived=${obs.rpc.bytesReceived}`);
|
|
74
|
+
lines.push(` overhead: checkpoint=${obs.overhead.checkpointMs}ms, encode=${obs.overhead.encodeMs}ms, write=${obs.overhead.writeMs}ms`);
|
|
75
|
+
lines.push(` queries: total=${obs.queryCount}, computed=${obs.computedQueryCount}, reused=${obs.reusedQueryCount}, candidates=${obs.candidateCount}, checkpoints=${obs.checkpointCount}`);
|
|
76
|
+
if (obs.providers.length > 0) {
|
|
77
|
+
lines.push(` providers: ${obs.providers.join(", ")}`);
|
|
78
|
+
}
|
|
79
|
+
const nativeAdapters = obs.nativeAdapters.map((adapter) => `${adapter.packageName} (provider=${adapter.providerId}, status=${adapter.status})`);
|
|
80
|
+
lines.push(` native adapters: ${nativeAdapters.length > 0 ? nativeAdapters.join(", ") : "none"}`);
|
|
81
|
+
const nativeExtractions = Object.entries(obs.engineExtractions).map(([providerId, stats]) => `${providerId} (extractions=${stats.extractions}, candidates=${stats.candidates})`);
|
|
82
|
+
lines.push(` native extractions: ${nativeExtractions.length > 0 ? nativeExtractions.join(", ") : "none"}`);
|
|
83
|
+
if (obs.truncated) {
|
|
84
|
+
lines.push(` truncated: true (dropped=${obs.droppedCount})`);
|
|
85
|
+
}
|
|
86
|
+
if (obs.details) {
|
|
87
|
+
for (const detail of obs.details) {
|
|
88
|
+
const meta = [];
|
|
89
|
+
if (detail.ruleId !== undefined)
|
|
90
|
+
meta.push(`rule=${detail.ruleId}`);
|
|
91
|
+
if (detail.provider !== undefined)
|
|
92
|
+
meta.push(`provider=${detail.provider}`);
|
|
93
|
+
if (detail.cacheStatus !== undefined) {
|
|
94
|
+
meta.push(`cache=${detail.cacheStatus}`);
|
|
95
|
+
}
|
|
96
|
+
if (detail.candidateCount !== undefined) {
|
|
97
|
+
meta.push(`candidates=${detail.candidateCount}`);
|
|
98
|
+
}
|
|
99
|
+
const metaSuffix = meta.length > 0 ? ` (${meta.join(", ")})` : "";
|
|
100
|
+
lines.push(` detail [${detail.kind}]${metaSuffix}: ${detail.summary}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function appendExtrasText(lines, report) {
|
|
105
|
+
if (report.explanation) {
|
|
106
|
+
appendExplanationLines(lines, report.explanation);
|
|
107
|
+
}
|
|
108
|
+
else if (report.explanations) {
|
|
109
|
+
for (const exp of report.explanations) {
|
|
110
|
+
appendExplanationLines(lines, exp);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (report.observation) {
|
|
114
|
+
appendObservationLines(lines, report.observation);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function formatCheckCleanText(report) {
|
|
118
|
+
const lines = formatScopeLines(report);
|
|
119
|
+
appendGapLines(lines, report.gaps);
|
|
120
|
+
const summary = report.gaps.length > 0
|
|
121
|
+
? `No violations found across ${report.projects.length} project(s) (${report.gaps.length} gap(s)).`
|
|
122
|
+
: `No violations found across ${report.projects.length} project(s).`;
|
|
123
|
+
const extras = [];
|
|
124
|
+
appendExtrasText(extras, report);
|
|
125
|
+
const [first, ...rest] = [...lines, summary, ...extras];
|
|
126
|
+
return first !== undefined
|
|
127
|
+
? text.lines([first, ...rest])
|
|
128
|
+
: text.line(summary);
|
|
129
|
+
}
|
|
130
|
+
function formatCheckFindingsText(report) {
|
|
131
|
+
const lines = [
|
|
132
|
+
...formatScopeLines(report),
|
|
133
|
+
...formatDiagnosticsLines(report),
|
|
134
|
+
];
|
|
135
|
+
appendGapLines(lines, report.gaps);
|
|
136
|
+
const summary = report.gaps.length > 0
|
|
137
|
+
? `Found ${report.diagnostics.length} violation(s) (${report.gaps.length} gap(s)).`
|
|
138
|
+
: `Found ${report.diagnostics.length} violation(s).`;
|
|
139
|
+
const extras = [];
|
|
140
|
+
appendExtrasText(extras, report);
|
|
141
|
+
const [first, ...rest] = lines;
|
|
142
|
+
return first !== undefined
|
|
143
|
+
? text.lines([first, ...rest, summary, ...extras])
|
|
144
|
+
: text.lines([summary, ...extras]);
|
|
145
|
+
}
|
|
146
|
+
function createCliContract(identity, workingDirectory, signal) {
|
|
147
|
+
const define = defineCli();
|
|
148
|
+
const versionInput = z.object({});
|
|
149
|
+
const checkInput = z.object({
|
|
150
|
+
config: z.string().min(1).optional(),
|
|
151
|
+
session: z.string().min(1).optional(),
|
|
152
|
+
rule: z.string().min(1).optional(),
|
|
153
|
+
at: z.string().min(1).optional(),
|
|
154
|
+
observe: z.enum(["off", "summary", "detail"]).optional(),
|
|
155
|
+
observeLimit: z.string().min(1).optional(),
|
|
156
|
+
});
|
|
157
|
+
const watchInput = z.object({
|
|
158
|
+
config: z.string().min(1).optional(),
|
|
159
|
+
});
|
|
160
|
+
const sessionInput = z.object({
|
|
161
|
+
config: z.string().min(1).optional(),
|
|
162
|
+
socket: z.string().min(1),
|
|
163
|
+
});
|
|
164
|
+
async function executeCheck(input) {
|
|
165
|
+
try {
|
|
166
|
+
const observeLimit = input.observeLimit !== undefined
|
|
167
|
+
? parseObserveLimit(input.observeLimit)
|
|
168
|
+
: undefined;
|
|
169
|
+
if (input.session !== undefined) {
|
|
170
|
+
if (input.config !== undefined) {
|
|
171
|
+
throw new VeruleExecutionError("INVALID_CONFIG", 'Cannot combine "--session" with "--config"; the shared session is already bound to a configuration.');
|
|
172
|
+
}
|
|
173
|
+
const report = await requestSharedReport({
|
|
174
|
+
endpoint: input.session,
|
|
175
|
+
cwd: workingDirectory,
|
|
176
|
+
...(input.rule !== undefined ? { ruleIds: [input.rule] } : {}),
|
|
177
|
+
...(input.at !== undefined ? { at: input.at } : {}),
|
|
178
|
+
...(input.observe !== undefined ? { observe: input.observe } : {}),
|
|
179
|
+
...(observeLimit !== undefined ? { observeLimit } : {}),
|
|
180
|
+
});
|
|
181
|
+
return { ok: true, report: toWireReport(report) };
|
|
182
|
+
}
|
|
183
|
+
const configStart = performance.now();
|
|
184
|
+
const loaded = await loadProjectConfigWithDependencies(workingDirectory, input.config);
|
|
185
|
+
const configLoadMs = performance.now() - configStart;
|
|
186
|
+
const report = await runCheck({
|
|
187
|
+
cwd: workingDirectory,
|
|
188
|
+
config: loaded.config,
|
|
189
|
+
adapterResolutionRoot: dirname(loaded.configPath),
|
|
190
|
+
configLoadMs,
|
|
191
|
+
...(input.rule !== undefined ? { ruleIds: [input.rule] } : {}),
|
|
192
|
+
...(input.at !== undefined ? { at: input.at } : {}),
|
|
193
|
+
...(input.observe !== undefined ? { observe: input.observe } : {}),
|
|
194
|
+
...(observeLimit !== undefined ? { observeLimit } : {}),
|
|
195
|
+
});
|
|
196
|
+
return { ok: true, report: toWireReport(report) };
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
if (err instanceof VeruleExecutionError) {
|
|
200
|
+
return {
|
|
201
|
+
ok: false,
|
|
202
|
+
failure: {
|
|
203
|
+
reportVersion: REPORT_SCHEMA_VERSION,
|
|
204
|
+
code: err.code,
|
|
205
|
+
message: err.message,
|
|
206
|
+
...(err.conflict !== undefined
|
|
207
|
+
? { conflict: toWireFactConflict(err.conflict) }
|
|
208
|
+
: {}),
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
ok: false,
|
|
214
|
+
failure: {
|
|
215
|
+
reportVersion: REPORT_SCHEMA_VERSION,
|
|
216
|
+
code: "ENGINE_ERROR",
|
|
217
|
+
message: err instanceof Error ? err.message : String(err),
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return define({
|
|
223
|
+
root: "verule",
|
|
224
|
+
help: helpCapability({
|
|
225
|
+
shortAlias: "-h",
|
|
226
|
+
headings: {
|
|
227
|
+
usage: "Usage",
|
|
228
|
+
commands: "Commands",
|
|
229
|
+
options: "Options",
|
|
230
|
+
schema: "Contract Discovery",
|
|
231
|
+
},
|
|
232
|
+
wording: {
|
|
233
|
+
commandPlaceholder: "command",
|
|
234
|
+
choices: "(choices: {choices})",
|
|
235
|
+
default: "(default: {value})",
|
|
236
|
+
},
|
|
237
|
+
}),
|
|
238
|
+
version: versionCapability({
|
|
239
|
+
value: text.line(`${identity.commandName} ${identity.version}`),
|
|
240
|
+
description: "Print the CLI version.",
|
|
241
|
+
shortAlias: "-V",
|
|
242
|
+
}),
|
|
243
|
+
schema: schemaCapability({
|
|
244
|
+
description: text.line("Inspect the command contract."),
|
|
245
|
+
}),
|
|
246
|
+
usageFailureExitCode: 2,
|
|
247
|
+
commands: {
|
|
248
|
+
verule: {
|
|
249
|
+
kind: "rootGroup",
|
|
250
|
+
name: identity.commandName,
|
|
251
|
+
description: "Static analyzer for TypeScript and JavaScript projects.",
|
|
252
|
+
},
|
|
253
|
+
...define.command("version")({
|
|
254
|
+
kind: "command",
|
|
255
|
+
parent: "verule",
|
|
256
|
+
name: "version",
|
|
257
|
+
description: "Show the installed Verule CLI and analysis engine versions.",
|
|
258
|
+
input: versionInput,
|
|
259
|
+
outputs: define.outputModes("version", versionInput, (mode) => ({
|
|
260
|
+
default: "text",
|
|
261
|
+
modes: {
|
|
262
|
+
text: mode.atomic({
|
|
263
|
+
format: "text",
|
|
264
|
+
description: "Display the installed versions.",
|
|
265
|
+
success: {
|
|
266
|
+
kind: "data",
|
|
267
|
+
variants: {
|
|
268
|
+
versions: {
|
|
269
|
+
description: "Installed CLI and engine versions.",
|
|
270
|
+
schema: z.object({ cli: z.string(), engine: z.string() }),
|
|
271
|
+
exitCode: 0,
|
|
272
|
+
text: ({ cli, engine }) => text.line(`${identity.commandName} ${cli} (engine ${engine})`),
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
failures: {},
|
|
277
|
+
handler: async ({ outcome }) => {
|
|
278
|
+
return outcome.data.versions({
|
|
279
|
+
cli: identity.version,
|
|
280
|
+
engine: await getEngineVersion(),
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
}),
|
|
284
|
+
},
|
|
285
|
+
})),
|
|
286
|
+
}),
|
|
287
|
+
...define.command("check")({
|
|
288
|
+
kind: "command",
|
|
289
|
+
parent: "verule",
|
|
290
|
+
name: "check",
|
|
291
|
+
description: "Run configured project rules and report diagnostics.",
|
|
292
|
+
fields: {
|
|
293
|
+
config: {
|
|
294
|
+
kind: "valueOption",
|
|
295
|
+
longOption: "--config",
|
|
296
|
+
shortAlias: "-c",
|
|
297
|
+
description: "Path to the Verule configuration file.",
|
|
298
|
+
},
|
|
299
|
+
session: {
|
|
300
|
+
kind: "valueOption",
|
|
301
|
+
longOption: "--session",
|
|
302
|
+
description: "Query a running shared session socket instead of starting a new engine.",
|
|
303
|
+
},
|
|
304
|
+
rule: {
|
|
305
|
+
kind: "valueOption",
|
|
306
|
+
longOption: "--rule",
|
|
307
|
+
description: "Run only the specified rule ID.",
|
|
308
|
+
},
|
|
309
|
+
at: {
|
|
310
|
+
kind: "valueOption",
|
|
311
|
+
longOption: "--at",
|
|
312
|
+
description: "Explain why diagnostics did or did not trigger at <file[:line[:column]]>.",
|
|
313
|
+
},
|
|
314
|
+
observe: {
|
|
315
|
+
kind: "valueOption",
|
|
316
|
+
longOption: "--observe",
|
|
317
|
+
description: "Observation verbosity level (off, summary, or detail).",
|
|
318
|
+
},
|
|
319
|
+
observeLimit: {
|
|
320
|
+
kind: "valueOption",
|
|
321
|
+
longOption: "--observe-limit",
|
|
322
|
+
description: "Limit detail observation entries (e.g. 20 or 4096b).",
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
input: checkInput,
|
|
326
|
+
outputs: define.outputModes("check", checkInput, (mode) => ({
|
|
327
|
+
default: "text",
|
|
328
|
+
modes: {
|
|
329
|
+
text: mode.atomic({
|
|
330
|
+
format: "text",
|
|
331
|
+
description: "Display check diagnostics as human-readable text.",
|
|
332
|
+
success: {
|
|
333
|
+
kind: "data",
|
|
334
|
+
variants: {
|
|
335
|
+
clean: {
|
|
336
|
+
description: "Analysis completed with zero violations.",
|
|
337
|
+
schema: checkReportSchema,
|
|
338
|
+
exitCode: 0,
|
|
339
|
+
text: formatCheckCleanText,
|
|
340
|
+
},
|
|
341
|
+
findings: {
|
|
342
|
+
description: "Analysis completed and reported violations.",
|
|
343
|
+
schema: checkReportSchema,
|
|
344
|
+
exitCode: 1,
|
|
345
|
+
text: formatCheckFindingsText,
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
failures: {
|
|
350
|
+
failed: {
|
|
351
|
+
description: "Configuration, project loading, rule execution, or engine failure.",
|
|
352
|
+
schema: checkFailureSchema,
|
|
353
|
+
exitCode: 2,
|
|
354
|
+
text: ({ code, message, conflict }) => {
|
|
355
|
+
if (!conflict) {
|
|
356
|
+
return text.line(`Check failed [${code}]: ${message}`);
|
|
357
|
+
}
|
|
358
|
+
const loc = conflict.subjectLocation
|
|
359
|
+
? ` (${conflict.subjectLocation.file}:${conflict.subjectLocation.line}:${conflict.subjectLocation.column})`
|
|
360
|
+
: "";
|
|
361
|
+
const head = `Check failed [${code}]: ${message}`;
|
|
362
|
+
const tail = [
|
|
363
|
+
` factType: ${conflict.factTypeId}`,
|
|
364
|
+
` subject: ${conflict.subjectHandleId}${loc}`,
|
|
365
|
+
];
|
|
366
|
+
for (const party of conflict.parties) {
|
|
367
|
+
tail.push(` provider [${party.providerId}]: ${party.conclusionSummary}`);
|
|
368
|
+
for (const ev of party.evidence) {
|
|
369
|
+
const evLoc = ev.at
|
|
370
|
+
? ` (${ev.at.file}:${ev.at.line}:${ev.at.column})`
|
|
371
|
+
: "";
|
|
372
|
+
tail.push(` evidence (${ev.kind}): ${ev.message}${evLoc}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return text.lines([head, ...tail]);
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
handler: async ({ input, outcome }) => {
|
|
380
|
+
const outcomeResult = await executeCheck(input);
|
|
381
|
+
if (!outcomeResult.ok) {
|
|
382
|
+
return outcome.failure.failed(outcomeResult.failure);
|
|
383
|
+
}
|
|
384
|
+
return outcomeResult.report.status === "findings"
|
|
385
|
+
? outcome.data.findings(outcomeResult.report)
|
|
386
|
+
: outcome.data.clean(outcomeResult.report);
|
|
387
|
+
},
|
|
388
|
+
}),
|
|
389
|
+
json: mode.atomic({
|
|
390
|
+
format: "structured",
|
|
391
|
+
description: "Emit a versioned JSON check report.",
|
|
392
|
+
success: {
|
|
393
|
+
kind: "data",
|
|
394
|
+
variants: {
|
|
395
|
+
clean: {
|
|
396
|
+
description: "Analysis completed with zero violations.",
|
|
397
|
+
schema: checkReportSchema,
|
|
398
|
+
exitCode: 0,
|
|
399
|
+
},
|
|
400
|
+
findings: {
|
|
401
|
+
description: "Analysis completed and reported violations.",
|
|
402
|
+
schema: checkReportSchema,
|
|
403
|
+
exitCode: 1,
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
failures: {
|
|
408
|
+
failed: {
|
|
409
|
+
description: "Configuration, project loading, rule execution, or engine failure.",
|
|
410
|
+
schema: checkFailureSchema,
|
|
411
|
+
exitCode: 2,
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
handler: async ({ input, outcome }) => {
|
|
415
|
+
const outcomeResult = await executeCheck(input);
|
|
416
|
+
if (!outcomeResult.ok) {
|
|
417
|
+
return outcome.failure.failed(outcomeResult.failure);
|
|
418
|
+
}
|
|
419
|
+
return outcomeResult.report.status === "findings"
|
|
420
|
+
? outcome.data.findings(outcomeResult.report)
|
|
421
|
+
: outcome.data.clean(outcomeResult.report);
|
|
422
|
+
},
|
|
423
|
+
}),
|
|
424
|
+
},
|
|
425
|
+
})),
|
|
426
|
+
}),
|
|
427
|
+
...define.command("watch")({
|
|
428
|
+
kind: "command",
|
|
429
|
+
parent: "verule",
|
|
430
|
+
name: "watch",
|
|
431
|
+
description: "Watch project files and emit complete reports on every save.",
|
|
432
|
+
fields: {
|
|
433
|
+
config: {
|
|
434
|
+
kind: "valueOption",
|
|
435
|
+
longOption: "--config",
|
|
436
|
+
shortAlias: "-c",
|
|
437
|
+
description: "Path to the Verule configuration file.",
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
input: watchInput,
|
|
441
|
+
outputs: define.outputModes("watch", watchInput, (mode) => ({
|
|
442
|
+
default: "text",
|
|
443
|
+
modes: {
|
|
444
|
+
text: mode.stream({
|
|
445
|
+
format: "text",
|
|
446
|
+
description: "Display watch reports as human-readable text.",
|
|
447
|
+
success: {
|
|
448
|
+
kind: "stream",
|
|
449
|
+
records: {
|
|
450
|
+
report: {
|
|
451
|
+
description: "Complete analysis report for a snapshot.",
|
|
452
|
+
schema: watchReportRecordSchema,
|
|
453
|
+
text: formatWatchReportText,
|
|
454
|
+
},
|
|
455
|
+
failed: {
|
|
456
|
+
description: "Single-round check failure.",
|
|
457
|
+
schema: watchFailureRecordSchema,
|
|
458
|
+
text: ({ sequence, code, message }) => text.line(`[watch #${sequence}] Check failed [${code}]: ${message}`),
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
text: () => text.line("Watch stopped."),
|
|
462
|
+
},
|
|
463
|
+
failures: {},
|
|
464
|
+
handler: ({ input, outcome }) => streamWatchEvents(workingDirectory, input.config, signal, outcome),
|
|
465
|
+
}),
|
|
466
|
+
ndjson: mode.stream({
|
|
467
|
+
format: "structured",
|
|
468
|
+
description: "Emit complete analysis reports as NDJSON stream records.",
|
|
469
|
+
success: {
|
|
470
|
+
kind: "stream",
|
|
471
|
+
records: {
|
|
472
|
+
report: {
|
|
473
|
+
description: "Complete analysis report for a snapshot.",
|
|
474
|
+
schema: watchReportRecordSchema,
|
|
475
|
+
},
|
|
476
|
+
failed: {
|
|
477
|
+
description: "Single-round check failure.",
|
|
478
|
+
schema: watchFailureRecordSchema,
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
failures: {},
|
|
483
|
+
handler: ({ input, outcome }) => streamWatchEvents(workingDirectory, input.config, signal, outcome),
|
|
484
|
+
}),
|
|
485
|
+
},
|
|
486
|
+
})),
|
|
487
|
+
}),
|
|
488
|
+
...define.command("session")({
|
|
489
|
+
kind: "command",
|
|
490
|
+
parent: "verule",
|
|
491
|
+
name: "session",
|
|
492
|
+
description: "Start an explicit shared analysis session bound to a configuration and socket endpoint.",
|
|
493
|
+
fields: {
|
|
494
|
+
config: {
|
|
495
|
+
kind: "valueOption",
|
|
496
|
+
longOption: "--config",
|
|
497
|
+
shortAlias: "-c",
|
|
498
|
+
description: "Path to the Verule configuration file.",
|
|
499
|
+
},
|
|
500
|
+
socket: {
|
|
501
|
+
kind: "valueOption",
|
|
502
|
+
longOption: "--socket",
|
|
503
|
+
description: "Local Unix domain socket or Windows named pipe path.",
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
input: sessionInput,
|
|
507
|
+
outputs: define.outputModes("session", sessionInput, (mode) => ({
|
|
508
|
+
default: "text",
|
|
509
|
+
modes: {
|
|
510
|
+
text: mode.stream({
|
|
511
|
+
format: "text",
|
|
512
|
+
description: "Emit shared session readiness and shutdown text.",
|
|
513
|
+
success: {
|
|
514
|
+
kind: "stream",
|
|
515
|
+
records: {
|
|
516
|
+
ready: {
|
|
517
|
+
description: "Shared session is initialized and listening for queries.",
|
|
518
|
+
schema: sessionReadyRecordSchema,
|
|
519
|
+
text: formatSessionReadyText,
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
text: () => text.line("Shared session stopped."),
|
|
523
|
+
},
|
|
524
|
+
failures: {
|
|
525
|
+
failed: {
|
|
526
|
+
description: "Shared session failed to start.",
|
|
527
|
+
schema: checkFailureSchema,
|
|
528
|
+
exitCode: 2,
|
|
529
|
+
text: ({ code, message }) => text.line(`Session failed [${code}]: ${message}`),
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
handler: ({ input, outcome }) => streamSharedSession(workingDirectory, input.config, input.socket, signal, outcome),
|
|
533
|
+
}),
|
|
534
|
+
ndjson: mode.stream({
|
|
535
|
+
format: "structured",
|
|
536
|
+
description: "Emit shared session readiness and lifecycle events as NDJSON.",
|
|
537
|
+
success: {
|
|
538
|
+
kind: "stream",
|
|
539
|
+
records: {
|
|
540
|
+
ready: {
|
|
541
|
+
description: "Shared session is initialized and listening for queries.",
|
|
542
|
+
schema: sessionReadyRecordSchema,
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
failures: {
|
|
547
|
+
failed: {
|
|
548
|
+
description: "Shared session failed to start.",
|
|
549
|
+
schema: checkFailureSchema,
|
|
550
|
+
exitCode: 2,
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
handler: ({ input, outcome }) => streamSharedSession(workingDirectory, input.config, input.socket, signal, outcome),
|
|
554
|
+
}),
|
|
555
|
+
},
|
|
556
|
+
})),
|
|
557
|
+
}),
|
|
558
|
+
},
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
/** Returns the process status after all output has been written. */
|
|
562
|
+
export async function runCli(runtime) {
|
|
563
|
+
try {
|
|
564
|
+
const workingDirectory = runtime.cwd ?? process.cwd();
|
|
565
|
+
const contract = createCliContract(runtime.identity, workingDirectory, runtime.signal);
|
|
566
|
+
const rawArgs = runtime.argv.slice(2);
|
|
567
|
+
const effectiveArgs = rawArgs.length === 0 ? ["version"] : rawArgs;
|
|
568
|
+
const invocation = parseCliInvocation(contract, effectiveArgs);
|
|
569
|
+
const { exitCode } = await executeCli(contract, {
|
|
570
|
+
invocation,
|
|
571
|
+
dependencies: undefined,
|
|
572
|
+
write: runtime.write,
|
|
573
|
+
});
|
|
574
|
+
return exitCode;
|
|
575
|
+
}
|
|
576
|
+
catch (error) {
|
|
577
|
+
if (error instanceof CliWriteError) {
|
|
578
|
+
if (error.destination === "stderr")
|
|
579
|
+
return 2;
|
|
580
|
+
if (isNodeBrokenPipe(error))
|
|
581
|
+
return 0;
|
|
582
|
+
}
|
|
583
|
+
try {
|
|
584
|
+
await runtime.write({
|
|
585
|
+
destination: "stderr",
|
|
586
|
+
chunk: "Verule could not complete the command.\n",
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
catch {
|
|
590
|
+
// The command still failed if its diagnostic could not be written.
|
|
591
|
+
}
|
|
592
|
+
return 2;
|
|
593
|
+
}
|
|
594
|
+
}
|