@boringparts/verule 0.0.0-stage → 0.2.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.
@@ -0,0 +1,629 @@
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 summaryDiscoverySourceSchema = z.enum([
13
+ "local",
14
+ "package",
15
+ "community",
16
+ "builtin",
17
+ ]);
18
+ export const evidenceSchema = z.object({
19
+ kind: z.enum(["source", "type", "note", "summary"]),
20
+ message: z.string(),
21
+ at: locationSchema.optional(),
22
+ summaryId: z.string().optional(),
23
+ summarySource: summaryDiscoverySourceSchema.optional(),
24
+ declaration: z.string().optional(),
25
+ });
26
+ export const gapSchema = z.object({
27
+ kind: z.string(),
28
+ message: z.string(),
29
+ at: locationSchema.optional(),
30
+ });
31
+ export const diagnosticSchema = z.object({
32
+ id: z.string(),
33
+ ruleId: z.string(),
34
+ at: locationSchema,
35
+ message: z.string(),
36
+ evidence: z.array(evidenceSchema),
37
+ projects: z.array(z.string()),
38
+ });
39
+ export const compilerOptionsSummarySchema = z.object({
40
+ strict: z.boolean(),
41
+ allowJs: z.boolean(),
42
+ checkJs: z.boolean(),
43
+ composite: z.boolean(),
44
+ target: z.string().optional(),
45
+ module: z.string().optional(),
46
+ moduleResolution: z.string().optional(),
47
+ jsx: z.string().optional(),
48
+ paths: z.record(z.string(), z.array(z.string())),
49
+ customConditions: z.array(z.string()),
50
+ });
51
+ export const projectSummarySchema = z.object({
52
+ projectId: z.string(),
53
+ configFile: z.string(),
54
+ entryConfig: z.string(),
55
+ entryChain: z.array(z.string()),
56
+ referencedBy: z.array(z.string()),
57
+ projectReferences: z.array(z.string()),
58
+ compilerOptions: compilerOptionsSummarySchema,
59
+ sourceFiles: z.array(z.string()),
60
+ });
61
+ export const sourceFileProjectOriginSchema = z.object({
62
+ projectId: z.string(),
63
+ configFile: z.string(),
64
+ entryConfig: z.string(),
65
+ entryChain: z.array(z.string()),
66
+ });
67
+ export const sourceFileOriginSchema = z.object({
68
+ file: z.string(),
69
+ projects: z.array(sourceFileProjectOriginSchema),
70
+ });
71
+ export const additionalInputSourceSchema = z.discriminatedUnion("kind", [
72
+ z.object({ kind: z.literal("config") }),
73
+ z.object({ kind: z.literal("rule"), id: z.string() }),
74
+ z.object({ kind: z.literal("summary"), id: z.string() }),
75
+ ]);
76
+ export const additionalInputEntrySchema = z.object({
77
+ file: z.string(),
78
+ exists: z.boolean(),
79
+ digest: z.string().optional(),
80
+ sources: z.array(additionalInputSourceSchema),
81
+ });
82
+ export const ruleIdentitySchema = z.object({
83
+ id: z.string(),
84
+ digest: z.string(),
85
+ });
86
+ export const reportIdentitySchema = z.object({
87
+ snapshotDigest: z.string(),
88
+ configDigest: z.string(),
89
+ rules: z.array(ruleIdentitySchema),
90
+ });
91
+ export const observationDetailEntrySchema = z.object({
92
+ kind: z.enum(["query", "checkpoint", "engineStep"]),
93
+ ruleId: z.string().optional(),
94
+ projectId: z.string().optional(),
95
+ provider: z.string().optional(),
96
+ name: z.string().optional(),
97
+ outcome: z.enum(["pass", "exclude", "info"]).optional(),
98
+ cacheStatus: z.enum(["computed", "reused"]).optional(),
99
+ candidateCount: z.number().int().nonnegative().optional(),
100
+ durationMs: z.number().nonnegative().optional(),
101
+ at: locationSchema.optional(),
102
+ summary: z.string(),
103
+ detail: z.unknown().optional(),
104
+ });
105
+ export const engineLoweringMetricsSchema = z.object({
106
+ functionsLowered: z.number().int().nonnegative(),
107
+ verticesCreated: z.number().int().nonnegative(),
108
+ durationMs: z.number().nonnegative(),
109
+ });
110
+ export const engineIrCacheMetricsSchema = z.object({
111
+ functionHits: z.number().int().nonnegative(),
112
+ functionMisses: z.number().int().nonnegative(),
113
+ filesReused: z.number().int().nonnegative(),
114
+ filesInvalidated: z.number().int().nonnegative(),
115
+ });
116
+ export const engineSummaryLookupMetricsSchema = z.object({
117
+ lookups: z.number().int().nonnegative(),
118
+ hits: z.number().int().nonnegative(),
119
+ misses: z.number().int().nonnegative(),
120
+ hitsBySource: z.object({
121
+ local: z.number().int().nonnegative(),
122
+ package: z.number().int().nonnegative(),
123
+ community: z.number().int().nonnegative(),
124
+ builtin: z.number().int().nonnegative(),
125
+ }),
126
+ });
127
+ export const observationSchema = z.object({
128
+ mode: z.enum(["summary", "detail"]),
129
+ phases: z.object({
130
+ configAndOpenMs: z.number().nonnegative(),
131
+ engineQueryMs: z.number().nonnegative(),
132
+ ruleExecutionMs: z.number().nonnegative(),
133
+ totalMs: z.number().nonnegative(),
134
+ }),
135
+ rpc: z.object({
136
+ batches: z.number().int().nonnegative(),
137
+ queryBatches: z.number().int().nonnegative(),
138
+ bytesSent: z.number().int().nonnegative(),
139
+ bytesReceived: z.number().int().nonnegative(),
140
+ }),
141
+ overhead: z.object({
142
+ checkpointMs: z.number().nonnegative(),
143
+ encodeMs: z.number().nonnegative(),
144
+ writeMs: z.number().nonnegative(),
145
+ }),
146
+ queryCount: z.number().int().nonnegative(),
147
+ computedQueryCount: z.number().int().nonnegative(),
148
+ reusedQueryCount: z.number().int().nonnegative(),
149
+ candidateCount: z.number().int().nonnegative(),
150
+ checkpointCount: z.number().int().nonnegative(),
151
+ providers: z.array(z.string()),
152
+ lowering: engineLoweringMetricsSchema,
153
+ irCache: engineIrCacheMetricsSchema,
154
+ summaryLookup: engineSummaryLookupMetricsSchema,
155
+ limit: z
156
+ .object({
157
+ maxItems: z.number().int().nonnegative().optional(),
158
+ maxBytes: z.number().int().nonnegative().optional(),
159
+ })
160
+ .optional(),
161
+ truncated: z.boolean(),
162
+ droppedCount: z.number().int().nonnegative(),
163
+ details: z.array(observationDetailEntrySchema).optional(),
164
+ });
165
+ export const explainQueryStepSchema = z.object({
166
+ queryIndex: z.number().int().positive(),
167
+ op: z.string(),
168
+ projectId: z.string(),
169
+ provider: z.string(),
170
+ cacheStatus: z.enum(["computed", "reused"]),
171
+ candidateCount: z.number().int().nonnegative(),
172
+ matchedTarget: z.boolean(),
173
+ durationMs: z.number().nonnegative(),
174
+ summary: z.string().optional(),
175
+ detail: z.unknown().optional(),
176
+ });
177
+ export const explainCheckpointTraceSchema = z.object({
178
+ name: z.string(),
179
+ ruleId: z.string(),
180
+ projectId: z.string(),
181
+ outcome: z.enum(["pass", "exclude", "info"]),
182
+ at: locationSchema.optional(),
183
+ detail: z.unknown().optional(),
184
+ });
185
+ export const explainCleanupPathSchema = z.object({
186
+ instanceKey: z.string(),
187
+ allocationLocation: locationSchema.optional(),
188
+ scopeLocation: locationSchema,
189
+ cleanupLocations: z.array(locationSchema),
190
+ summaryIds: z.array(z.string()),
191
+ summary: z.string(),
192
+ evidence: z.array(evidenceSchema),
193
+ });
194
+ export const explainResultSchema = z.object({
195
+ ruleId: z.string(),
196
+ target: z.object({
197
+ file: z.string(),
198
+ line: z.number().int().positive().optional(),
199
+ column: z.number().int().positive().optional(),
200
+ }),
201
+ status: z.enum([
202
+ "reported",
203
+ "excluded_by_checkpoint",
204
+ "excluded_by_query",
205
+ "not_in_candidates",
206
+ "target_not_in_project",
207
+ "suppressed_by_ignore",
208
+ "blocked_by_gap",
209
+ "covered_by_cleanup",
210
+ "rule_filtered",
211
+ ]),
212
+ inCandidates: z.boolean(),
213
+ summary: z.string(),
214
+ projectsChecked: z.array(z.string()),
215
+ matchingCandidates: z.array(locationSchema),
216
+ excludedByQuery: explainQueryStepSchema.optional(),
217
+ excludedByCheckpoint: explainCheckpointTraceSchema.optional(),
218
+ queries: z.array(explainQueryStepSchema),
219
+ checkpoints: z.array(explainCheckpointTraceSchema),
220
+ gaps: z.array(gapSchema),
221
+ providers: z.array(z.string()),
222
+ cleanupPaths: z.array(explainCleanupPathSchema),
223
+ inlineIgnore: z
224
+ .object({
225
+ matched: z.boolean(),
226
+ ruleId: z.string().optional(),
227
+ reason: z.string().optional(),
228
+ commentAt: locationSchema.optional(),
229
+ })
230
+ .optional(),
231
+ });
232
+ export const inlineIgnoreEntrySchema = z.object({
233
+ status: z.enum([
234
+ "suppressed",
235
+ "unused",
236
+ "ambiguous",
237
+ "malformed",
238
+ "unknown_rule",
239
+ "undetermined",
240
+ ]),
241
+ at: locationSchema,
242
+ targetLine: z.number().int().positive().optional(),
243
+ ruleId: z.string().optional(),
244
+ reason: z.string().optional(),
245
+ matchedLocations: z.array(locationSchema).optional(),
246
+ message: z.string().optional(),
247
+ });
248
+ export const checkReportSchema = z.object({
249
+ reportVersion: z.literal(REPORT_SCHEMA_VERSION),
250
+ status: z.enum(["clean", "findings"]),
251
+ projects: z.array(projectSummarySchema),
252
+ fileOrigins: z.array(sourceFileOriginSchema),
253
+ additionalInputs: z.array(additionalInputEntrySchema),
254
+ diagnostics: z.array(diagnosticSchema),
255
+ gaps: z.array(gapSchema),
256
+ identity: reportIdentitySchema,
257
+ inlineIgnores: z.array(inlineIgnoreEntrySchema).optional(),
258
+ observation: observationSchema.optional(),
259
+ explanation: explainResultSchema.optional(),
260
+ explanations: z.array(explainResultSchema).optional(),
261
+ });
262
+ export const checkFailureSchema = z.object({
263
+ reportVersion: z.literal(REPORT_SCHEMA_VERSION),
264
+ code: z.string(),
265
+ message: z.string(),
266
+ });
267
+ function toWireEvidence(ev) {
268
+ return {
269
+ kind: ev.kind,
270
+ message: ev.message,
271
+ ...(ev.at !== undefined ? { at: { ...ev.at } } : {}),
272
+ ...(ev.summaryId !== undefined ? { summaryId: ev.summaryId } : {}),
273
+ ...(ev.summarySource !== undefined
274
+ ? { summarySource: ev.summarySource }
275
+ : {}),
276
+ ...(ev.declaration !== undefined ? { declaration: ev.declaration } : {}),
277
+ };
278
+ }
279
+ function sanitizeWireJsonValue(value) {
280
+ if (value === null ||
281
+ typeof value === "boolean" ||
282
+ typeof value === "string") {
283
+ return value;
284
+ }
285
+ if (typeof value === "number") {
286
+ return Number.isFinite(value) ? value : null;
287
+ }
288
+ if (Array.isArray(value)) {
289
+ return value.map((item) => item === undefined ? null : sanitizeWireJsonValue(item));
290
+ }
291
+ if (typeof value === "object") {
292
+ const out = {};
293
+ for (const [key, item] of Object.entries(value)) {
294
+ if (item !== undefined) {
295
+ out[key] = sanitizeWireJsonValue(item);
296
+ }
297
+ }
298
+ return out;
299
+ }
300
+ if (value === undefined) {
301
+ return null;
302
+ }
303
+ if (typeof value === "bigint" || typeof value === "symbol") {
304
+ return value.toString();
305
+ }
306
+ return null;
307
+ }
308
+ function toWireObservation(obs) {
309
+ return {
310
+ mode: obs.mode,
311
+ phases: { ...obs.phases },
312
+ rpc: { ...obs.rpc },
313
+ overhead: { ...obs.overhead },
314
+ queryCount: obs.queryCount,
315
+ computedQueryCount: obs.computedQueryCount,
316
+ reusedQueryCount: obs.reusedQueryCount,
317
+ candidateCount: obs.candidateCount,
318
+ checkpointCount: obs.checkpointCount,
319
+ providers: [...obs.providers],
320
+ lowering: { ...obs.lowering },
321
+ irCache: { ...obs.irCache },
322
+ summaryLookup: {
323
+ lookups: obs.summaryLookup.lookups,
324
+ hits: obs.summaryLookup.hits,
325
+ misses: obs.summaryLookup.misses,
326
+ hitsBySource: { ...obs.summaryLookup.hitsBySource },
327
+ },
328
+ ...(obs.limit !== undefined
329
+ ? {
330
+ limit: {
331
+ ...(obs.limit.maxItems !== undefined
332
+ ? { maxItems: obs.limit.maxItems }
333
+ : {}),
334
+ ...(obs.limit.maxBytes !== undefined
335
+ ? { maxBytes: obs.limit.maxBytes }
336
+ : {}),
337
+ },
338
+ }
339
+ : {}),
340
+ truncated: obs.truncated,
341
+ droppedCount: obs.droppedCount,
342
+ ...(obs.details !== undefined
343
+ ? {
344
+ details: obs.details.map((entry) => ({
345
+ kind: entry.kind,
346
+ summary: entry.summary,
347
+ ...(entry.ruleId !== undefined ? { ruleId: entry.ruleId } : {}),
348
+ ...(entry.projectId !== undefined
349
+ ? { projectId: entry.projectId }
350
+ : {}),
351
+ ...(entry.provider !== undefined
352
+ ? { provider: entry.provider }
353
+ : {}),
354
+ ...(entry.name !== undefined ? { name: entry.name } : {}),
355
+ ...(entry.outcome !== undefined ? { outcome: entry.outcome } : {}),
356
+ ...(entry.cacheStatus !== undefined
357
+ ? { cacheStatus: entry.cacheStatus }
358
+ : {}),
359
+ ...(entry.candidateCount !== undefined
360
+ ? { candidateCount: entry.candidateCount }
361
+ : {}),
362
+ ...(entry.durationMs !== undefined
363
+ ? { durationMs: entry.durationMs }
364
+ : {}),
365
+ ...(entry.at !== undefined ? { at: { ...entry.at } } : {}),
366
+ ...(entry.detail !== undefined
367
+ ? { detail: sanitizeWireJsonValue(entry.detail) }
368
+ : {}),
369
+ })),
370
+ }
371
+ : {}),
372
+ };
373
+ }
374
+ function toWireExplainQueryStep(q) {
375
+ return {
376
+ queryIndex: q.queryIndex,
377
+ op: q.op,
378
+ projectId: q.projectId,
379
+ provider: q.provider,
380
+ cacheStatus: q.cacheStatus,
381
+ candidateCount: q.candidateCount,
382
+ matchedTarget: q.matchedTarget,
383
+ durationMs: q.durationMs,
384
+ ...(q.summary !== undefined ? { summary: q.summary } : {}),
385
+ ...(q.detail !== undefined
386
+ ? { detail: sanitizeWireJsonValue(q.detail) }
387
+ : {}),
388
+ };
389
+ }
390
+ function toWireExplainCheckpoint(cp) {
391
+ return {
392
+ name: cp.name,
393
+ ruleId: cp.ruleId,
394
+ projectId: cp.projectId,
395
+ outcome: cp.outcome,
396
+ ...(cp.at !== undefined ? { at: { ...cp.at } } : {}),
397
+ ...(cp.detail !== undefined
398
+ ? { detail: sanitizeWireJsonValue(cp.detail) }
399
+ : {}),
400
+ };
401
+ }
402
+ function toWireExplainResult(exp) {
403
+ return {
404
+ ruleId: exp.ruleId,
405
+ target: {
406
+ file: exp.target.file,
407
+ ...(exp.target.line !== undefined ? { line: exp.target.line } : {}),
408
+ ...(exp.target.column !== undefined ? { column: exp.target.column } : {}),
409
+ },
410
+ status: exp.status,
411
+ inCandidates: exp.inCandidates,
412
+ summary: exp.summary,
413
+ projectsChecked: [...exp.projectsChecked],
414
+ matchingCandidates: exp.matchingCandidates.map((loc) => ({ ...loc })),
415
+ ...(exp.excludedByQuery !== undefined
416
+ ? {
417
+ excludedByQuery: toWireExplainQueryStep(exp.excludedByQuery),
418
+ }
419
+ : {}),
420
+ ...(exp.excludedByCheckpoint !== undefined
421
+ ? {
422
+ excludedByCheckpoint: toWireExplainCheckpoint(exp.excludedByCheckpoint),
423
+ }
424
+ : {}),
425
+ queries: exp.queries.map(toWireExplainQueryStep),
426
+ checkpoints: exp.checkpoints.map(toWireExplainCheckpoint),
427
+ gaps: exp.gaps.map((g) => ({
428
+ kind: g.kind,
429
+ message: g.message,
430
+ ...(g.at !== undefined ? { at: { ...g.at } } : {}),
431
+ })),
432
+ providers: [...exp.providers],
433
+ cleanupPaths: exp.cleanupPaths.map((cp) => ({
434
+ instanceKey: cp.instanceKey,
435
+ ...(cp.allocationLocation !== undefined
436
+ ? { allocationLocation: { ...cp.allocationLocation } }
437
+ : {}),
438
+ scopeLocation: { ...cp.scopeLocation },
439
+ cleanupLocations: cp.cleanupLocations.map((loc) => ({ ...loc })),
440
+ summaryIds: [...cp.summaryIds],
441
+ summary: cp.summary,
442
+ evidence: cp.evidence.map(toWireEvidence),
443
+ })),
444
+ ...(exp.inlineIgnore !== undefined
445
+ ? {
446
+ inlineIgnore: {
447
+ matched: exp.inlineIgnore.matched,
448
+ ...(exp.inlineIgnore.ruleId !== undefined
449
+ ? { ruleId: exp.inlineIgnore.ruleId }
450
+ : {}),
451
+ ...(exp.inlineIgnore.reason !== undefined
452
+ ? { reason: exp.inlineIgnore.reason }
453
+ : {}),
454
+ ...(exp.inlineIgnore.commentAt !== undefined
455
+ ? { commentAt: { ...exp.inlineIgnore.commentAt } }
456
+ : {}),
457
+ },
458
+ }
459
+ : {}),
460
+ };
461
+ }
462
+ export function toWireProjects(projects) {
463
+ return projects.map((project) => ({
464
+ projectId: project.projectId,
465
+ configFile: project.configFile,
466
+ entryConfig: project.entryConfig,
467
+ entryChain: [...project.entryChain],
468
+ referencedBy: [...project.referencedBy],
469
+ projectReferences: [...project.projectReferences],
470
+ compilerOptions: {
471
+ strict: project.compilerOptions.strict,
472
+ allowJs: project.compilerOptions.allowJs,
473
+ checkJs: project.compilerOptions.checkJs,
474
+ composite: project.compilerOptions.composite,
475
+ ...(project.compilerOptions.target !== undefined
476
+ ? { target: project.compilerOptions.target }
477
+ : {}),
478
+ ...(project.compilerOptions.module !== undefined
479
+ ? { module: project.compilerOptions.module }
480
+ : {}),
481
+ ...(project.compilerOptions.moduleResolution !== undefined
482
+ ? { moduleResolution: project.compilerOptions.moduleResolution }
483
+ : {}),
484
+ ...(project.compilerOptions.jsx !== undefined
485
+ ? { jsx: project.compilerOptions.jsx }
486
+ : {}),
487
+ paths: Object.fromEntries(Object.entries(project.compilerOptions.paths).map(([key, vals]) => [
488
+ key,
489
+ [...vals],
490
+ ])),
491
+ customConditions: [...project.compilerOptions.customConditions],
492
+ },
493
+ sourceFiles: [...project.sourceFiles],
494
+ }));
495
+ }
496
+ export function toWireReport(report) {
497
+ return {
498
+ reportVersion: report.reportVersion,
499
+ status: report.status,
500
+ projects: toWireProjects(report.projects),
501
+ fileOrigins: report.fileOrigins.map((origin) => ({
502
+ file: origin.file,
503
+ projects: origin.projects.map((proj) => ({
504
+ projectId: proj.projectId,
505
+ configFile: proj.configFile,
506
+ entryConfig: proj.entryConfig,
507
+ entryChain: [...proj.entryChain],
508
+ })),
509
+ })),
510
+ additionalInputs: report.additionalInputs.map((entry) => ({
511
+ file: entry.file,
512
+ exists: entry.exists,
513
+ ...(entry.digest !== undefined ? { digest: entry.digest } : {}),
514
+ sources: entry.sources.map((src) => src.kind === "config"
515
+ ? { kind: "config" }
516
+ : { kind: src.kind, id: src.id }),
517
+ })),
518
+ diagnostics: report.diagnostics.map((diag) => ({
519
+ id: diag.id,
520
+ ruleId: diag.ruleId,
521
+ at: { ...diag.at },
522
+ message: diag.message,
523
+ evidence: diag.evidence.map(toWireEvidence),
524
+ projects: [...diag.projects],
525
+ })),
526
+ gaps: report.gaps.map((gap) => ({
527
+ kind: gap.kind,
528
+ message: gap.message,
529
+ ...(gap.at !== undefined ? { at: { ...gap.at } } : {}),
530
+ })),
531
+ identity: {
532
+ snapshotDigest: report.identity.snapshotDigest,
533
+ configDigest: report.identity.configDigest,
534
+ rules: report.identity.rules.map((rule) => ({
535
+ id: rule.id,
536
+ digest: rule.digest,
537
+ })),
538
+ },
539
+ ...(report.inlineIgnores !== undefined
540
+ ? {
541
+ inlineIgnores: report.inlineIgnores.map((entry) => ({
542
+ status: entry.status,
543
+ at: { ...entry.at },
544
+ ...(entry.targetLine !== undefined
545
+ ? { targetLine: entry.targetLine }
546
+ : {}),
547
+ ...(entry.ruleId !== undefined ? { ruleId: entry.ruleId } : {}),
548
+ ...(entry.reason !== undefined ? { reason: entry.reason } : {}),
549
+ ...(entry.matchedLocations !== undefined
550
+ ? {
551
+ matchedLocations: entry.matchedLocations.map((loc) => ({
552
+ ...loc,
553
+ })),
554
+ }
555
+ : {}),
556
+ ...(entry.message !== undefined ? { message: entry.message } : {}),
557
+ })),
558
+ }
559
+ : {}),
560
+ ...(report.observation !== undefined
561
+ ? { observation: toWireObservation(report.observation) }
562
+ : {}),
563
+ ...(report.explanation !== undefined
564
+ ? { explanation: toWireExplainResult(report.explanation) }
565
+ : {}),
566
+ ...(report.explanations !== undefined
567
+ ? {
568
+ explanations: report.explanations.map(toWireExplainResult),
569
+ }
570
+ : {}),
571
+ };
572
+ }
573
+ export function formatDiagnosticsLines(report) {
574
+ const lines = [];
575
+ for (const diag of report.diagnostics) {
576
+ lines.push(`${diag.at.file}:${diag.at.line}:${diag.at.column} [${diag.ruleId}] (${diag.id}) ${diag.message} [projects: ${diag.projects.join(", ")}]`);
577
+ for (const item of diag.evidence) {
578
+ const locSuffix = item.at
579
+ ? ` (${item.at.file}:${item.at.line}:${item.at.column})`
580
+ : "";
581
+ const summarySuffix = item.summaryId !== undefined
582
+ ? ` [summary=${item.summaryId}${item.summarySource !== undefined ? `@${item.summarySource}` : ""}${item.declaration !== undefined ? `:${item.declaration}` : ""}]`
583
+ : "";
584
+ lines.push(` evidence (${item.kind}): ${item.message}${summarySuffix}${locSuffix}`);
585
+ }
586
+ }
587
+ return lines;
588
+ }
589
+ export function appendGapLines(lines, gaps) {
590
+ for (const gap of gaps) {
591
+ const locSuffix = gap.at
592
+ ? ` (${gap.at.file}:${gap.at.line}:${gap.at.column})`
593
+ : "";
594
+ lines.push(`gap [${gap.kind}]: ${gap.message}${locSuffix}`);
595
+ }
596
+ }
597
+ export function formatScopeLines(report) {
598
+ const lines = [`Projects (${report.projects.length}):`];
599
+ for (const project of report.projects) {
600
+ const chain = project.entryChain.join(" -> ");
601
+ const flags = [
602
+ `strict=${project.compilerOptions.strict}`,
603
+ `allowJs=${project.compilerOptions.allowJs}`,
604
+ `checkJs=${project.compilerOptions.checkJs}`,
605
+ ...(project.compilerOptions.module !== undefined
606
+ ? [`module=${project.compilerOptions.module}`]
607
+ : []),
608
+ `files=${project.sourceFiles.length}`,
609
+ ];
610
+ const refsSuffix = project.projectReferences.length > 0
611
+ ? `, references=[${project.projectReferences.join(", ")}]`
612
+ : "";
613
+ lines.push(` - ${project.configFile} (chain: ${chain}, ${flags.join(", ")}${refsSuffix})`);
614
+ }
615
+ lines.push(`Files (${report.fileOrigins.length}):`);
616
+ for (const origin of report.fileOrigins) {
617
+ const sources = origin.projects.map((proj) => `${proj.projectId} (via ${proj.entryChain.join(" -> ")})`);
618
+ lines.push(` - ${origin.file} <- ${sources.join(", ")}`);
619
+ }
620
+ if (report.additionalInputs.length > 0) {
621
+ lines.push(`Additional inputs (${report.additionalInputs.length}):`);
622
+ for (const input of report.additionalInputs) {
623
+ const sources = input.sources.map((src) => src.kind === "config" ? "config" : `${src.kind}:${src.id}`);
624
+ const statusSuffix = input.exists ? "" : " [missing]";
625
+ lines.push(` - ${input.file}${statusSuffix} <- ${sources.join(", ")}`);
626
+ }
627
+ }
628
+ return lines;
629
+ }
@@ -0,0 +1,48 @@
1
+ import { z } from "zod";
2
+ import { REPORT_SCHEMA_VERSION } from "./index.ts";
3
+ export declare const sessionReadyRecordSchema: z.ZodObject<{
4
+ reportVersion: z.ZodLiteral<"1">;
5
+ endpoint: z.ZodString;
6
+ snapshotId: z.ZodNumber;
7
+ projects: z.ZodArray<z.ZodObject<{
8
+ projectId: z.ZodString;
9
+ configFile: z.ZodString;
10
+ entryConfig: z.ZodString;
11
+ entryChain: z.ZodArray<z.ZodString>;
12
+ referencedBy: z.ZodArray<z.ZodString>;
13
+ projectReferences: z.ZodArray<z.ZodString>;
14
+ compilerOptions: z.ZodObject<{
15
+ strict: z.ZodBoolean;
16
+ allowJs: z.ZodBoolean;
17
+ checkJs: z.ZodBoolean;
18
+ composite: z.ZodBoolean;
19
+ target: z.ZodOptional<z.ZodString>;
20
+ module: z.ZodOptional<z.ZodString>;
21
+ moduleResolution: z.ZodOptional<z.ZodString>;
22
+ jsx: z.ZodOptional<z.ZodString>;
23
+ paths: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
24
+ customConditions: z.ZodArray<z.ZodString>;
25
+ }, z.core.$strip>;
26
+ sourceFiles: z.ZodArray<z.ZodString>;
27
+ }, z.core.$strip>>;
28
+ }, z.core.$strip>;
29
+ export type WireSessionReadyRecord = z.infer<typeof sessionReadyRecordSchema>;
30
+ export declare function formatSessionReadyText(record: WireSessionReadyRecord): import("@boringparts/cli-contract").TextLine;
31
+ /**
32
+ * Starts a long-lived shared session bound to a single project configuration, emits
33
+ * a ready notification, serves cross-process `verule check --session` queries, and cleans
34
+ * up the socket endpoint and engine subprocess on shutdown.
35
+ */
36
+ export declare function streamSharedSession<TReadyFact, TSuccessFact, TFailureFact>(workingDirectory: string, configOption: string | undefined, socketOption: string, signal: AbortSignal | undefined, outcome: {
37
+ readonly record: {
38
+ readonly ready: (payload: WireSessionReadyRecord) => TReadyFact;
39
+ };
40
+ readonly streamSuccess: () => TSuccessFact;
41
+ readonly failure: {
42
+ readonly failed: (payload: {
43
+ readonly reportVersion: typeof REPORT_SCHEMA_VERSION;
44
+ readonly code: string;
45
+ readonly message: string;
46
+ }) => TFailureFact;
47
+ };
48
+ }): AsyncGenerator<TReadyFact, TSuccessFact | TFailureFact, void>;