@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
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { REPORT_SCHEMA_VERSION, } from "./index.js";
|
|
3
|
+
export const locationSchema = z.object({
|
|
4
|
+
file: z.string(),
|
|
5
|
+
line: z.number().int().positive(),
|
|
6
|
+
column: z.number().int().positive(),
|
|
7
|
+
endLine: z.number().int().positive(),
|
|
8
|
+
endColumn: z.number().int().positive(),
|
|
9
|
+
start: z.number().int().nonnegative(),
|
|
10
|
+
end: z.number().int().nonnegative(),
|
|
11
|
+
});
|
|
12
|
+
export const evidenceSchema = z.object({
|
|
13
|
+
kind: z.enum(["source", "type", "note", "model"]),
|
|
14
|
+
message: z.string(),
|
|
15
|
+
at: locationSchema.optional(),
|
|
16
|
+
modelId: z.string().optional(),
|
|
17
|
+
declaration: z.string().optional(),
|
|
18
|
+
});
|
|
19
|
+
export const gapSchema = z.object({
|
|
20
|
+
kind: z.string(),
|
|
21
|
+
message: z.string(),
|
|
22
|
+
at: locationSchema.optional(),
|
|
23
|
+
});
|
|
24
|
+
export const diagnosticSchema = z.object({
|
|
25
|
+
id: z.string(),
|
|
26
|
+
ruleId: z.string(),
|
|
27
|
+
at: locationSchema,
|
|
28
|
+
message: z.string(),
|
|
29
|
+
evidence: z.array(evidenceSchema),
|
|
30
|
+
projects: z.array(z.string()),
|
|
31
|
+
});
|
|
32
|
+
export const compilerOptionsSummarySchema = z.object({
|
|
33
|
+
strict: z.boolean(),
|
|
34
|
+
allowJs: z.boolean(),
|
|
35
|
+
checkJs: z.boolean(),
|
|
36
|
+
composite: z.boolean(),
|
|
37
|
+
target: z.string().optional(),
|
|
38
|
+
module: z.string().optional(),
|
|
39
|
+
moduleResolution: z.string().optional(),
|
|
40
|
+
jsx: z.string().optional(),
|
|
41
|
+
paths: z.record(z.string(), z.array(z.string())),
|
|
42
|
+
customConditions: z.array(z.string()),
|
|
43
|
+
});
|
|
44
|
+
export const projectSummarySchema = z.object({
|
|
45
|
+
projectId: z.string(),
|
|
46
|
+
configFile: z.string(),
|
|
47
|
+
entryConfig: z.string(),
|
|
48
|
+
entryChain: z.array(z.string()),
|
|
49
|
+
referencedBy: z.array(z.string()),
|
|
50
|
+
projectReferences: z.array(z.string()),
|
|
51
|
+
compilerOptions: compilerOptionsSummarySchema,
|
|
52
|
+
sourceFiles: z.array(z.string()),
|
|
53
|
+
});
|
|
54
|
+
export const sourceFileProjectOriginSchema = z.object({
|
|
55
|
+
projectId: z.string(),
|
|
56
|
+
configFile: z.string(),
|
|
57
|
+
entryConfig: z.string(),
|
|
58
|
+
entryChain: z.array(z.string()),
|
|
59
|
+
});
|
|
60
|
+
export const sourceFileOriginSchema = z.object({
|
|
61
|
+
file: z.string(),
|
|
62
|
+
projects: z.array(sourceFileProjectOriginSchema),
|
|
63
|
+
});
|
|
64
|
+
export const additionalInputSourceSchema = z.discriminatedUnion("kind", [
|
|
65
|
+
z.object({ kind: z.literal("config") }),
|
|
66
|
+
z.object({ kind: z.literal("rule"), id: z.string() }),
|
|
67
|
+
z.object({ kind: z.literal("adapter"), id: z.string() }),
|
|
68
|
+
]);
|
|
69
|
+
export const additionalInputEntrySchema = z.object({
|
|
70
|
+
file: z.string(),
|
|
71
|
+
exists: z.boolean(),
|
|
72
|
+
digest: z.string().optional(),
|
|
73
|
+
sources: z.array(additionalInputSourceSchema),
|
|
74
|
+
});
|
|
75
|
+
export const ruleIdentitySchema = z.object({
|
|
76
|
+
id: z.string(),
|
|
77
|
+
digest: z.string(),
|
|
78
|
+
});
|
|
79
|
+
export const modelIdentitySchema = z.object({
|
|
80
|
+
id: z.string(),
|
|
81
|
+
version: z.string().optional(),
|
|
82
|
+
digest: z.string(),
|
|
83
|
+
});
|
|
84
|
+
export const reportIdentitySchema = z.object({
|
|
85
|
+
snapshotDigest: z.string(),
|
|
86
|
+
configDigest: z.string(),
|
|
87
|
+
rules: z.array(ruleIdentitySchema),
|
|
88
|
+
models: z.array(modelIdentitySchema),
|
|
89
|
+
});
|
|
90
|
+
export const observationDetailEntrySchema = z.object({
|
|
91
|
+
kind: z.enum(["query", "checkpoint", "engineStep"]),
|
|
92
|
+
ruleId: z.string().optional(),
|
|
93
|
+
projectId: z.string().optional(),
|
|
94
|
+
provider: z.string().optional(),
|
|
95
|
+
name: z.string().optional(),
|
|
96
|
+
outcome: z.enum(["pass", "exclude", "info"]).optional(),
|
|
97
|
+
cacheStatus: z.enum(["computed", "reused"]).optional(),
|
|
98
|
+
candidateCount: z.number().int().nonnegative().optional(),
|
|
99
|
+
durationMs: z.number().nonnegative().optional(),
|
|
100
|
+
at: locationSchema.optional(),
|
|
101
|
+
summary: z.string(),
|
|
102
|
+
detail: z.unknown().optional(),
|
|
103
|
+
});
|
|
104
|
+
export const observationSchema = z.object({
|
|
105
|
+
mode: z.enum(["summary", "detail"]),
|
|
106
|
+
phases: z.object({
|
|
107
|
+
configAndOpenMs: z.number().nonnegative(),
|
|
108
|
+
engineQueryMs: z.number().nonnegative(),
|
|
109
|
+
ruleExecutionMs: z.number().nonnegative(),
|
|
110
|
+
totalMs: z.number().nonnegative(),
|
|
111
|
+
}),
|
|
112
|
+
rpc: z.object({
|
|
113
|
+
batches: z.number().int().nonnegative(),
|
|
114
|
+
queryBatches: z.number().int().nonnegative(),
|
|
115
|
+
bytesSent: z.number().int().nonnegative(),
|
|
116
|
+
bytesReceived: z.number().int().nonnegative(),
|
|
117
|
+
}),
|
|
118
|
+
overhead: z.object({
|
|
119
|
+
checkpointMs: z.number().nonnegative(),
|
|
120
|
+
encodeMs: z.number().nonnegative(),
|
|
121
|
+
writeMs: z.number().nonnegative(),
|
|
122
|
+
}),
|
|
123
|
+
queryCount: z.number().int().nonnegative(),
|
|
124
|
+
computedQueryCount: z.number().int().nonnegative(),
|
|
125
|
+
reusedQueryCount: z.number().int().nonnegative(),
|
|
126
|
+
candidateCount: z.number().int().nonnegative(),
|
|
127
|
+
checkpointCount: z.number().int().nonnegative(),
|
|
128
|
+
providers: z.array(z.string()),
|
|
129
|
+
nativeAdapters: z.array(z.object({
|
|
130
|
+
packageName: z.string(),
|
|
131
|
+
providerId: z.string(),
|
|
132
|
+
status: z.enum(["loaded", "reused"]),
|
|
133
|
+
})),
|
|
134
|
+
limit: z
|
|
135
|
+
.object({
|
|
136
|
+
maxItems: z.number().int().nonnegative().optional(),
|
|
137
|
+
maxBytes: z.number().int().nonnegative().optional(),
|
|
138
|
+
})
|
|
139
|
+
.optional(),
|
|
140
|
+
truncated: z.boolean(),
|
|
141
|
+
droppedCount: z.number().int().nonnegative(),
|
|
142
|
+
engineExtractions: z.record(z.string(), z.object({
|
|
143
|
+
extractions: z.number().int().nonnegative(),
|
|
144
|
+
candidates: z.number().int().nonnegative(),
|
|
145
|
+
})),
|
|
146
|
+
details: z.array(observationDetailEntrySchema).optional(),
|
|
147
|
+
});
|
|
148
|
+
export const explainQueryStepSchema = z.object({
|
|
149
|
+
queryIndex: z.number().int().positive(),
|
|
150
|
+
op: z.string(),
|
|
151
|
+
projectId: z.string(),
|
|
152
|
+
provider: z.string(),
|
|
153
|
+
cacheStatus: z.enum(["computed", "reused"]),
|
|
154
|
+
candidateCount: z.number().int().nonnegative(),
|
|
155
|
+
matchedTarget: z.boolean(),
|
|
156
|
+
durationMs: z.number().nonnegative(),
|
|
157
|
+
summary: z.string().optional(),
|
|
158
|
+
detail: z.unknown().optional(),
|
|
159
|
+
});
|
|
160
|
+
export const explainCheckpointTraceSchema = z.object({
|
|
161
|
+
name: z.string(),
|
|
162
|
+
ruleId: z.string(),
|
|
163
|
+
projectId: z.string(),
|
|
164
|
+
outcome: z.enum(["pass", "exclude", "info"]),
|
|
165
|
+
at: locationSchema.optional(),
|
|
166
|
+
detail: z.unknown().optional(),
|
|
167
|
+
});
|
|
168
|
+
export const explainCleanupPathSchema = z.object({
|
|
169
|
+
instanceKey: z.string(),
|
|
170
|
+
allocationLocation: locationSchema.optional(),
|
|
171
|
+
scopeLocation: locationSchema,
|
|
172
|
+
cleanupLocations: z.array(locationSchema),
|
|
173
|
+
modelIds: z.array(z.string()),
|
|
174
|
+
summary: z.string(),
|
|
175
|
+
evidence: z.array(evidenceSchema),
|
|
176
|
+
});
|
|
177
|
+
export const explainGapResolutionSchema = z.object({
|
|
178
|
+
providerId: z.string(),
|
|
179
|
+
operation: z.string(),
|
|
180
|
+
conclusion: z.string(),
|
|
181
|
+
at: locationSchema.optional(),
|
|
182
|
+
});
|
|
183
|
+
export const explainLocalGapSchema = z.object({
|
|
184
|
+
status: z.enum(["unresolved", "resolved_by_override"]),
|
|
185
|
+
factTypeId: z.string(),
|
|
186
|
+
providerId: z.string(),
|
|
187
|
+
field: z.string().optional(),
|
|
188
|
+
gap: gapSchema,
|
|
189
|
+
subjectLocation: locationSchema.optional(),
|
|
190
|
+
resolvedBy: explainGapResolutionSchema.optional(),
|
|
191
|
+
impact: z.string().optional(),
|
|
192
|
+
});
|
|
193
|
+
export const explainProviderEvaluationSchema = z.object({
|
|
194
|
+
providerId: z.string(),
|
|
195
|
+
factTypeId: z.string().optional(),
|
|
196
|
+
status: z.enum(["evaluated", "reused", "skipped"]),
|
|
197
|
+
reason: z.string().optional(),
|
|
198
|
+
subjectLocation: locationSchema.optional(),
|
|
199
|
+
});
|
|
200
|
+
export const explainResultSchema = z.object({
|
|
201
|
+
ruleId: z.string(),
|
|
202
|
+
target: z.object({
|
|
203
|
+
file: z.string(),
|
|
204
|
+
line: z.number().int().positive().optional(),
|
|
205
|
+
column: z.number().int().positive().optional(),
|
|
206
|
+
}),
|
|
207
|
+
status: z.enum([
|
|
208
|
+
"reported",
|
|
209
|
+
"excluded_by_checkpoint",
|
|
210
|
+
"excluded_by_query",
|
|
211
|
+
"not_in_candidates",
|
|
212
|
+
"target_not_in_project",
|
|
213
|
+
"suppressed_by_ignore",
|
|
214
|
+
"blocked_by_gap",
|
|
215
|
+
"covered_by_cleanup",
|
|
216
|
+
"rule_filtered",
|
|
217
|
+
]),
|
|
218
|
+
inCandidates: z.boolean(),
|
|
219
|
+
summary: z.string(),
|
|
220
|
+
projectsChecked: z.array(z.string()),
|
|
221
|
+
matchingCandidates: z.array(locationSchema),
|
|
222
|
+
excludedByQuery: explainQueryStepSchema.optional(),
|
|
223
|
+
excludedByCheckpoint: explainCheckpointTraceSchema.optional(),
|
|
224
|
+
queries: z.array(explainQueryStepSchema),
|
|
225
|
+
checkpoints: z.array(explainCheckpointTraceSchema),
|
|
226
|
+
gaps: z.array(gapSchema),
|
|
227
|
+
localGaps: z.array(explainLocalGapSchema),
|
|
228
|
+
providerEvaluations: z.array(explainProviderEvaluationSchema),
|
|
229
|
+
providers: z.array(z.string()),
|
|
230
|
+
cleanupPaths: z.array(explainCleanupPathSchema),
|
|
231
|
+
inlineIgnore: z
|
|
232
|
+
.object({
|
|
233
|
+
matched: z.boolean(),
|
|
234
|
+
ruleId: z.string().optional(),
|
|
235
|
+
reason: z.string().optional(),
|
|
236
|
+
commentAt: locationSchema.optional(),
|
|
237
|
+
})
|
|
238
|
+
.optional(),
|
|
239
|
+
});
|
|
240
|
+
export const inlineIgnoreEntrySchema = z.object({
|
|
241
|
+
status: z.enum([
|
|
242
|
+
"suppressed",
|
|
243
|
+
"unused",
|
|
244
|
+
"ambiguous",
|
|
245
|
+
"malformed",
|
|
246
|
+
"unknown_rule",
|
|
247
|
+
"undetermined",
|
|
248
|
+
]),
|
|
249
|
+
at: locationSchema,
|
|
250
|
+
targetLine: z.number().int().positive().optional(),
|
|
251
|
+
ruleId: z.string().optional(),
|
|
252
|
+
reason: z.string().optional(),
|
|
253
|
+
matchedLocations: z.array(locationSchema).optional(),
|
|
254
|
+
message: z.string().optional(),
|
|
255
|
+
});
|
|
256
|
+
export const checkReportSchema = z.object({
|
|
257
|
+
reportVersion: z.literal(REPORT_SCHEMA_VERSION),
|
|
258
|
+
status: z.enum(["clean", "findings"]),
|
|
259
|
+
projects: z.array(projectSummarySchema),
|
|
260
|
+
fileOrigins: z.array(sourceFileOriginSchema),
|
|
261
|
+
additionalInputs: z.array(additionalInputEntrySchema),
|
|
262
|
+
diagnostics: z.array(diagnosticSchema),
|
|
263
|
+
gaps: z.array(gapSchema),
|
|
264
|
+
identity: reportIdentitySchema,
|
|
265
|
+
inlineIgnores: z.array(inlineIgnoreEntrySchema).optional(),
|
|
266
|
+
observation: observationSchema.optional(),
|
|
267
|
+
explanation: explainResultSchema.optional(),
|
|
268
|
+
explanations: z.array(explainResultSchema).optional(),
|
|
269
|
+
});
|
|
270
|
+
export const factConflictPartySchema = z.object({
|
|
271
|
+
providerId: z.string(),
|
|
272
|
+
providers: z.array(z.string()),
|
|
273
|
+
conclusion: z.unknown(),
|
|
274
|
+
conclusionSummary: z.string(),
|
|
275
|
+
evidence: z.array(evidenceSchema),
|
|
276
|
+
});
|
|
277
|
+
export const factConflictDetailsSchema = z.object({
|
|
278
|
+
factTypeId: z.string(),
|
|
279
|
+
projectId: z.string(),
|
|
280
|
+
snapshotId: z.number().int().positive(),
|
|
281
|
+
subjectHandleId: z.string(),
|
|
282
|
+
subjectLocation: locationSchema.optional(),
|
|
283
|
+
condition: z.unknown().optional(),
|
|
284
|
+
reason: z.string(),
|
|
285
|
+
parties: z.tuple([factConflictPartySchema, factConflictPartySchema]),
|
|
286
|
+
});
|
|
287
|
+
export const checkFailureSchema = z.object({
|
|
288
|
+
reportVersion: z.literal(REPORT_SCHEMA_VERSION),
|
|
289
|
+
code: z.string(),
|
|
290
|
+
message: z.string(),
|
|
291
|
+
conflict: factConflictDetailsSchema.optional(),
|
|
292
|
+
});
|
|
293
|
+
function toWireEvidence(ev) {
|
|
294
|
+
return {
|
|
295
|
+
kind: ev.kind,
|
|
296
|
+
message: ev.message,
|
|
297
|
+
...(ev.at !== undefined ? { at: { ...ev.at } } : {}),
|
|
298
|
+
...(ev.modelId !== undefined ? { modelId: ev.modelId } : {}),
|
|
299
|
+
...(ev.declaration !== undefined ? { declaration: ev.declaration } : {}),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
export function toWireFactConflict(conflict) {
|
|
303
|
+
const [party0, party1] = conflict.parties;
|
|
304
|
+
return {
|
|
305
|
+
factTypeId: conflict.factTypeId,
|
|
306
|
+
projectId: conflict.projectId,
|
|
307
|
+
snapshotId: conflict.snapshotId,
|
|
308
|
+
subjectHandleId: conflict.subjectHandleId,
|
|
309
|
+
...(conflict.subjectLocation !== undefined
|
|
310
|
+
? { subjectLocation: { ...conflict.subjectLocation } }
|
|
311
|
+
: {}),
|
|
312
|
+
...(conflict.condition !== undefined
|
|
313
|
+
? { condition: conflict.condition }
|
|
314
|
+
: {}),
|
|
315
|
+
reason: conflict.reason,
|
|
316
|
+
parties: [
|
|
317
|
+
{
|
|
318
|
+
providerId: party0.providerId,
|
|
319
|
+
providers: [...party0.providers],
|
|
320
|
+
conclusion: party0.conclusion,
|
|
321
|
+
conclusionSummary: party0.conclusionSummary,
|
|
322
|
+
evidence: party0.evidence.map(toWireEvidence),
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
providerId: party1.providerId,
|
|
326
|
+
providers: [...party1.providers],
|
|
327
|
+
conclusion: party1.conclusion,
|
|
328
|
+
conclusionSummary: party1.conclusionSummary,
|
|
329
|
+
evidence: party1.evidence.map(toWireEvidence),
|
|
330
|
+
},
|
|
331
|
+
],
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function sanitizeWireJsonValue(value) {
|
|
335
|
+
if (value === null ||
|
|
336
|
+
typeof value === "boolean" ||
|
|
337
|
+
typeof value === "string") {
|
|
338
|
+
return value;
|
|
339
|
+
}
|
|
340
|
+
if (typeof value === "number") {
|
|
341
|
+
return Number.isFinite(value) ? value : null;
|
|
342
|
+
}
|
|
343
|
+
if (Array.isArray(value)) {
|
|
344
|
+
return value.map((item) => item === undefined ? null : sanitizeWireJsonValue(item));
|
|
345
|
+
}
|
|
346
|
+
if (typeof value === "object") {
|
|
347
|
+
const out = {};
|
|
348
|
+
for (const [key, item] of Object.entries(value)) {
|
|
349
|
+
if (item !== undefined) {
|
|
350
|
+
out[key] = sanitizeWireJsonValue(item);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return out;
|
|
354
|
+
}
|
|
355
|
+
if (value === undefined) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
if (typeof value === "bigint" || typeof value === "symbol") {
|
|
359
|
+
return value.toString();
|
|
360
|
+
}
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
function toWireObservation(obs) {
|
|
364
|
+
return {
|
|
365
|
+
mode: obs.mode,
|
|
366
|
+
phases: { ...obs.phases },
|
|
367
|
+
rpc: { ...obs.rpc },
|
|
368
|
+
overhead: { ...obs.overhead },
|
|
369
|
+
queryCount: obs.queryCount,
|
|
370
|
+
computedQueryCount: obs.computedQueryCount,
|
|
371
|
+
reusedQueryCount: obs.reusedQueryCount,
|
|
372
|
+
candidateCount: obs.candidateCount,
|
|
373
|
+
checkpointCount: obs.checkpointCount,
|
|
374
|
+
providers: [...obs.providers],
|
|
375
|
+
nativeAdapters: obs.nativeAdapters.map((adapter) => ({ ...adapter })),
|
|
376
|
+
engineExtractions: Object.fromEntries(Object.entries(obs.engineExtractions).map(([providerId, stats]) => [
|
|
377
|
+
providerId,
|
|
378
|
+
{ ...stats },
|
|
379
|
+
])),
|
|
380
|
+
...(obs.limit !== undefined
|
|
381
|
+
? {
|
|
382
|
+
limit: {
|
|
383
|
+
...(obs.limit.maxItems !== undefined
|
|
384
|
+
? { maxItems: obs.limit.maxItems }
|
|
385
|
+
: {}),
|
|
386
|
+
...(obs.limit.maxBytes !== undefined
|
|
387
|
+
? { maxBytes: obs.limit.maxBytes }
|
|
388
|
+
: {}),
|
|
389
|
+
},
|
|
390
|
+
}
|
|
391
|
+
: {}),
|
|
392
|
+
truncated: obs.truncated,
|
|
393
|
+
droppedCount: obs.droppedCount,
|
|
394
|
+
...(obs.details !== undefined
|
|
395
|
+
? {
|
|
396
|
+
details: obs.details.map((entry) => ({
|
|
397
|
+
kind: entry.kind,
|
|
398
|
+
summary: entry.summary,
|
|
399
|
+
...(entry.ruleId !== undefined ? { ruleId: entry.ruleId } : {}),
|
|
400
|
+
...(entry.projectId !== undefined
|
|
401
|
+
? { projectId: entry.projectId }
|
|
402
|
+
: {}),
|
|
403
|
+
...(entry.provider !== undefined
|
|
404
|
+
? { provider: entry.provider }
|
|
405
|
+
: {}),
|
|
406
|
+
...(entry.name !== undefined ? { name: entry.name } : {}),
|
|
407
|
+
...(entry.outcome !== undefined ? { outcome: entry.outcome } : {}),
|
|
408
|
+
...(entry.cacheStatus !== undefined
|
|
409
|
+
? { cacheStatus: entry.cacheStatus }
|
|
410
|
+
: {}),
|
|
411
|
+
...(entry.candidateCount !== undefined
|
|
412
|
+
? { candidateCount: entry.candidateCount }
|
|
413
|
+
: {}),
|
|
414
|
+
...(entry.durationMs !== undefined
|
|
415
|
+
? { durationMs: entry.durationMs }
|
|
416
|
+
: {}),
|
|
417
|
+
...(entry.at !== undefined ? { at: { ...entry.at } } : {}),
|
|
418
|
+
...(entry.detail !== undefined
|
|
419
|
+
? { detail: sanitizeWireJsonValue(entry.detail) }
|
|
420
|
+
: {}),
|
|
421
|
+
})),
|
|
422
|
+
}
|
|
423
|
+
: {}),
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
function toWireExplainQueryStep(q) {
|
|
427
|
+
return {
|
|
428
|
+
queryIndex: q.queryIndex,
|
|
429
|
+
op: q.op,
|
|
430
|
+
projectId: q.projectId,
|
|
431
|
+
provider: q.provider,
|
|
432
|
+
cacheStatus: q.cacheStatus,
|
|
433
|
+
candidateCount: q.candidateCount,
|
|
434
|
+
matchedTarget: q.matchedTarget,
|
|
435
|
+
durationMs: q.durationMs,
|
|
436
|
+
...(q.summary !== undefined ? { summary: q.summary } : {}),
|
|
437
|
+
...(q.detail !== undefined
|
|
438
|
+
? { detail: sanitizeWireJsonValue(q.detail) }
|
|
439
|
+
: {}),
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function toWireExplainCheckpoint(cp) {
|
|
443
|
+
return {
|
|
444
|
+
name: cp.name,
|
|
445
|
+
ruleId: cp.ruleId,
|
|
446
|
+
projectId: cp.projectId,
|
|
447
|
+
outcome: cp.outcome,
|
|
448
|
+
...(cp.at !== undefined ? { at: { ...cp.at } } : {}),
|
|
449
|
+
...(cp.detail !== undefined
|
|
450
|
+
? { detail: sanitizeWireJsonValue(cp.detail) }
|
|
451
|
+
: {}),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
function toWireExplainResult(exp) {
|
|
455
|
+
return {
|
|
456
|
+
ruleId: exp.ruleId,
|
|
457
|
+
target: {
|
|
458
|
+
file: exp.target.file,
|
|
459
|
+
...(exp.target.line !== undefined ? { line: exp.target.line } : {}),
|
|
460
|
+
...(exp.target.column !== undefined ? { column: exp.target.column } : {}),
|
|
461
|
+
},
|
|
462
|
+
status: exp.status,
|
|
463
|
+
inCandidates: exp.inCandidates,
|
|
464
|
+
summary: exp.summary,
|
|
465
|
+
projectsChecked: [...exp.projectsChecked],
|
|
466
|
+
matchingCandidates: exp.matchingCandidates.map((loc) => ({ ...loc })),
|
|
467
|
+
...(exp.excludedByQuery !== undefined
|
|
468
|
+
? {
|
|
469
|
+
excludedByQuery: toWireExplainQueryStep(exp.excludedByQuery),
|
|
470
|
+
}
|
|
471
|
+
: {}),
|
|
472
|
+
...(exp.excludedByCheckpoint !== undefined
|
|
473
|
+
? {
|
|
474
|
+
excludedByCheckpoint: toWireExplainCheckpoint(exp.excludedByCheckpoint),
|
|
475
|
+
}
|
|
476
|
+
: {}),
|
|
477
|
+
queries: exp.queries.map(toWireExplainQueryStep),
|
|
478
|
+
checkpoints: exp.checkpoints.map(toWireExplainCheckpoint),
|
|
479
|
+
gaps: exp.gaps.map((g) => ({
|
|
480
|
+
kind: g.kind,
|
|
481
|
+
message: g.message,
|
|
482
|
+
...(g.at !== undefined ? { at: { ...g.at } } : {}),
|
|
483
|
+
})),
|
|
484
|
+
localGaps: exp.localGaps.map((lg) => ({
|
|
485
|
+
status: lg.status,
|
|
486
|
+
factTypeId: lg.factTypeId,
|
|
487
|
+
providerId: lg.providerId,
|
|
488
|
+
...(lg.field !== undefined ? { field: lg.field } : {}),
|
|
489
|
+
gap: {
|
|
490
|
+
kind: lg.gap.kind,
|
|
491
|
+
message: lg.gap.message,
|
|
492
|
+
...(lg.gap.at !== undefined ? { at: { ...lg.gap.at } } : {}),
|
|
493
|
+
},
|
|
494
|
+
...(lg.subjectLocation !== undefined
|
|
495
|
+
? { subjectLocation: { ...lg.subjectLocation } }
|
|
496
|
+
: {}),
|
|
497
|
+
...(lg.resolvedBy !== undefined
|
|
498
|
+
? {
|
|
499
|
+
resolvedBy: {
|
|
500
|
+
providerId: lg.resolvedBy.providerId,
|
|
501
|
+
operation: lg.resolvedBy.operation,
|
|
502
|
+
conclusion: lg.resolvedBy.conclusion,
|
|
503
|
+
...(lg.resolvedBy.at !== undefined
|
|
504
|
+
? { at: { ...lg.resolvedBy.at } }
|
|
505
|
+
: {}),
|
|
506
|
+
},
|
|
507
|
+
}
|
|
508
|
+
: {}),
|
|
509
|
+
...(lg.impact !== undefined ? { impact: lg.impact } : {}),
|
|
510
|
+
})),
|
|
511
|
+
providerEvaluations: exp.providerEvaluations.map((pe) => ({
|
|
512
|
+
providerId: pe.providerId,
|
|
513
|
+
...(pe.factTypeId !== undefined ? { factTypeId: pe.factTypeId } : {}),
|
|
514
|
+
status: pe.status,
|
|
515
|
+
...(pe.reason !== undefined ? { reason: pe.reason } : {}),
|
|
516
|
+
...(pe.subjectLocation !== undefined
|
|
517
|
+
? { subjectLocation: { ...pe.subjectLocation } }
|
|
518
|
+
: {}),
|
|
519
|
+
})),
|
|
520
|
+
providers: [...exp.providers],
|
|
521
|
+
cleanupPaths: exp.cleanupPaths.map((cp) => ({
|
|
522
|
+
instanceKey: cp.instanceKey,
|
|
523
|
+
...(cp.allocationLocation !== undefined
|
|
524
|
+
? { allocationLocation: { ...cp.allocationLocation } }
|
|
525
|
+
: {}),
|
|
526
|
+
scopeLocation: { ...cp.scopeLocation },
|
|
527
|
+
cleanupLocations: cp.cleanupLocations.map((loc) => ({ ...loc })),
|
|
528
|
+
modelIds: [...cp.modelIds],
|
|
529
|
+
summary: cp.summary,
|
|
530
|
+
evidence: cp.evidence.map((ev) => ({
|
|
531
|
+
kind: ev.kind,
|
|
532
|
+
message: ev.message,
|
|
533
|
+
...(ev.at !== undefined ? { at: { ...ev.at } } : {}),
|
|
534
|
+
...(ev.modelId !== undefined ? { modelId: ev.modelId } : {}),
|
|
535
|
+
...(ev.declaration !== undefined
|
|
536
|
+
? { declaration: ev.declaration }
|
|
537
|
+
: {}),
|
|
538
|
+
})),
|
|
539
|
+
})),
|
|
540
|
+
...(exp.inlineIgnore !== undefined
|
|
541
|
+
? {
|
|
542
|
+
inlineIgnore: {
|
|
543
|
+
matched: exp.inlineIgnore.matched,
|
|
544
|
+
...(exp.inlineIgnore.ruleId !== undefined
|
|
545
|
+
? { ruleId: exp.inlineIgnore.ruleId }
|
|
546
|
+
: {}),
|
|
547
|
+
...(exp.inlineIgnore.reason !== undefined
|
|
548
|
+
? { reason: exp.inlineIgnore.reason }
|
|
549
|
+
: {}),
|
|
550
|
+
...(exp.inlineIgnore.commentAt !== undefined
|
|
551
|
+
? { commentAt: { ...exp.inlineIgnore.commentAt } }
|
|
552
|
+
: {}),
|
|
553
|
+
},
|
|
554
|
+
}
|
|
555
|
+
: {}),
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
export function toWireProjects(projects) {
|
|
559
|
+
return projects.map((project) => ({
|
|
560
|
+
projectId: project.projectId,
|
|
561
|
+
configFile: project.configFile,
|
|
562
|
+
entryConfig: project.entryConfig,
|
|
563
|
+
entryChain: [...project.entryChain],
|
|
564
|
+
referencedBy: [...project.referencedBy],
|
|
565
|
+
projectReferences: [...project.projectReferences],
|
|
566
|
+
compilerOptions: {
|
|
567
|
+
strict: project.compilerOptions.strict,
|
|
568
|
+
allowJs: project.compilerOptions.allowJs,
|
|
569
|
+
checkJs: project.compilerOptions.checkJs,
|
|
570
|
+
composite: project.compilerOptions.composite,
|
|
571
|
+
...(project.compilerOptions.target !== undefined
|
|
572
|
+
? { target: project.compilerOptions.target }
|
|
573
|
+
: {}),
|
|
574
|
+
...(project.compilerOptions.module !== undefined
|
|
575
|
+
? { module: project.compilerOptions.module }
|
|
576
|
+
: {}),
|
|
577
|
+
...(project.compilerOptions.moduleResolution !== undefined
|
|
578
|
+
? { moduleResolution: project.compilerOptions.moduleResolution }
|
|
579
|
+
: {}),
|
|
580
|
+
...(project.compilerOptions.jsx !== undefined
|
|
581
|
+
? { jsx: project.compilerOptions.jsx }
|
|
582
|
+
: {}),
|
|
583
|
+
paths: Object.fromEntries(Object.entries(project.compilerOptions.paths).map(([key, vals]) => [
|
|
584
|
+
key,
|
|
585
|
+
[...vals],
|
|
586
|
+
])),
|
|
587
|
+
customConditions: [...project.compilerOptions.customConditions],
|
|
588
|
+
},
|
|
589
|
+
sourceFiles: [...project.sourceFiles],
|
|
590
|
+
}));
|
|
591
|
+
}
|
|
592
|
+
export function toWireReport(report) {
|
|
593
|
+
return {
|
|
594
|
+
reportVersion: report.reportVersion,
|
|
595
|
+
status: report.status,
|
|
596
|
+
projects: toWireProjects(report.projects),
|
|
597
|
+
fileOrigins: report.fileOrigins.map((origin) => ({
|
|
598
|
+
file: origin.file,
|
|
599
|
+
projects: origin.projects.map((proj) => ({
|
|
600
|
+
projectId: proj.projectId,
|
|
601
|
+
configFile: proj.configFile,
|
|
602
|
+
entryConfig: proj.entryConfig,
|
|
603
|
+
entryChain: [...proj.entryChain],
|
|
604
|
+
})),
|
|
605
|
+
})),
|
|
606
|
+
additionalInputs: report.additionalInputs.map((entry) => ({
|
|
607
|
+
file: entry.file,
|
|
608
|
+
exists: entry.exists,
|
|
609
|
+
...(entry.digest !== undefined ? { digest: entry.digest } : {}),
|
|
610
|
+
sources: entry.sources.map((src) => src.kind === "config"
|
|
611
|
+
? { kind: "config" }
|
|
612
|
+
: { kind: src.kind, id: src.id }),
|
|
613
|
+
})),
|
|
614
|
+
diagnostics: report.diagnostics.map((diag) => ({
|
|
615
|
+
id: diag.id,
|
|
616
|
+
ruleId: diag.ruleId,
|
|
617
|
+
at: { ...diag.at },
|
|
618
|
+
message: diag.message,
|
|
619
|
+
evidence: diag.evidence.map((item) => ({
|
|
620
|
+
kind: item.kind,
|
|
621
|
+
message: item.message,
|
|
622
|
+
...(item.at !== undefined ? { at: { ...item.at } } : {}),
|
|
623
|
+
...(item.modelId !== undefined ? { modelId: item.modelId } : {}),
|
|
624
|
+
...(item.declaration !== undefined
|
|
625
|
+
? { declaration: item.declaration }
|
|
626
|
+
: {}),
|
|
627
|
+
})),
|
|
628
|
+
projects: [...diag.projects],
|
|
629
|
+
})),
|
|
630
|
+
gaps: report.gaps.map((gap) => ({
|
|
631
|
+
kind: gap.kind,
|
|
632
|
+
message: gap.message,
|
|
633
|
+
...(gap.at !== undefined ? { at: { ...gap.at } } : {}),
|
|
634
|
+
})),
|
|
635
|
+
identity: {
|
|
636
|
+
snapshotDigest: report.identity.snapshotDigest,
|
|
637
|
+
configDigest: report.identity.configDigest,
|
|
638
|
+
rules: report.identity.rules.map((rule) => ({
|
|
639
|
+
id: rule.id,
|
|
640
|
+
digest: rule.digest,
|
|
641
|
+
})),
|
|
642
|
+
models: report.identity.models.map((model) => ({
|
|
643
|
+
id: model.id,
|
|
644
|
+
...(model.version !== undefined ? { version: model.version } : {}),
|
|
645
|
+
digest: model.digest,
|
|
646
|
+
})),
|
|
647
|
+
},
|
|
648
|
+
...(report.inlineIgnores !== undefined
|
|
649
|
+
? {
|
|
650
|
+
inlineIgnores: report.inlineIgnores.map((entry) => ({
|
|
651
|
+
status: entry.status,
|
|
652
|
+
at: { ...entry.at },
|
|
653
|
+
...(entry.targetLine !== undefined
|
|
654
|
+
? { targetLine: entry.targetLine }
|
|
655
|
+
: {}),
|
|
656
|
+
...(entry.ruleId !== undefined ? { ruleId: entry.ruleId } : {}),
|
|
657
|
+
...(entry.reason !== undefined ? { reason: entry.reason } : {}),
|
|
658
|
+
...(entry.matchedLocations !== undefined
|
|
659
|
+
? {
|
|
660
|
+
matchedLocations: entry.matchedLocations.map((loc) => ({
|
|
661
|
+
...loc,
|
|
662
|
+
})),
|
|
663
|
+
}
|
|
664
|
+
: {}),
|
|
665
|
+
...(entry.message !== undefined ? { message: entry.message } : {}),
|
|
666
|
+
})),
|
|
667
|
+
}
|
|
668
|
+
: {}),
|
|
669
|
+
...(report.observation !== undefined
|
|
670
|
+
? { observation: toWireObservation(report.observation) }
|
|
671
|
+
: {}),
|
|
672
|
+
...(report.explanation !== undefined
|
|
673
|
+
? { explanation: toWireExplainResult(report.explanation) }
|
|
674
|
+
: {}),
|
|
675
|
+
...(report.explanations !== undefined
|
|
676
|
+
? {
|
|
677
|
+
explanations: report.explanations.map(toWireExplainResult),
|
|
678
|
+
}
|
|
679
|
+
: {}),
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
export function formatDiagnosticsLines(report) {
|
|
683
|
+
const lines = [];
|
|
684
|
+
for (const diag of report.diagnostics) {
|
|
685
|
+
lines.push(`${diag.at.file}:${diag.at.line}:${diag.at.column} [${diag.ruleId}] (${diag.id}) ${diag.message} [projects: ${diag.projects.join(", ")}]`);
|
|
686
|
+
for (const item of diag.evidence) {
|
|
687
|
+
const locSuffix = item.at
|
|
688
|
+
? ` (${item.at.file}:${item.at.line}:${item.at.column})`
|
|
689
|
+
: "";
|
|
690
|
+
const modelSuffix = item.modelId !== undefined
|
|
691
|
+
? ` [model=${item.modelId}${item.declaration !== undefined ? `:${item.declaration}` : ""}]`
|
|
692
|
+
: "";
|
|
693
|
+
lines.push(` evidence (${item.kind}): ${item.message}${modelSuffix}${locSuffix}`);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return lines;
|
|
697
|
+
}
|
|
698
|
+
export function appendGapLines(lines, gaps) {
|
|
699
|
+
for (const gap of gaps) {
|
|
700
|
+
const locSuffix = gap.at
|
|
701
|
+
? ` (${gap.at.file}:${gap.at.line}:${gap.at.column})`
|
|
702
|
+
: "";
|
|
703
|
+
lines.push(`gap [${gap.kind}]: ${gap.message}${locSuffix}`);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
export function formatScopeLines(report) {
|
|
707
|
+
const lines = [`Projects (${report.projects.length}):`];
|
|
708
|
+
for (const project of report.projects) {
|
|
709
|
+
const chain = project.entryChain.join(" -> ");
|
|
710
|
+
const flags = [
|
|
711
|
+
`strict=${project.compilerOptions.strict}`,
|
|
712
|
+
`allowJs=${project.compilerOptions.allowJs}`,
|
|
713
|
+
`checkJs=${project.compilerOptions.checkJs}`,
|
|
714
|
+
...(project.compilerOptions.module !== undefined
|
|
715
|
+
? [`module=${project.compilerOptions.module}`]
|
|
716
|
+
: []),
|
|
717
|
+
`files=${project.sourceFiles.length}`,
|
|
718
|
+
];
|
|
719
|
+
const refsSuffix = project.projectReferences.length > 0
|
|
720
|
+
? `, references=[${project.projectReferences.join(", ")}]`
|
|
721
|
+
: "";
|
|
722
|
+
lines.push(` - ${project.configFile} (chain: ${chain}, ${flags.join(", ")}${refsSuffix})`);
|
|
723
|
+
}
|
|
724
|
+
lines.push(`Files (${report.fileOrigins.length}):`);
|
|
725
|
+
for (const origin of report.fileOrigins) {
|
|
726
|
+
const sources = origin.projects.map((proj) => `${proj.projectId} (via ${proj.entryChain.join(" -> ")})`);
|
|
727
|
+
lines.push(` - ${origin.file} <- ${sources.join(", ")}`);
|
|
728
|
+
}
|
|
729
|
+
if (report.additionalInputs.length > 0) {
|
|
730
|
+
lines.push(`Additional inputs (${report.additionalInputs.length}):`);
|
|
731
|
+
for (const input of report.additionalInputs) {
|
|
732
|
+
const sources = input.sources.map((src) => src.kind === "config" ? "config" : `${src.kind}:${src.id}`);
|
|
733
|
+
const statusSuffix = input.exists ? "" : " [missing]";
|
|
734
|
+
lines.push(` - ${input.file}${statusSuffix} <- ${sources.join(", ")}`);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
return lines;
|
|
738
|
+
}
|