@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,13 @@
|
|
|
1
|
+
import { type CheckReport, type RequestSharedReportOptions, type SharedSession, type SharedSessionOptions } from "./types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Starts an explicit long-lived shared analysis session bound to a single configuration and
|
|
4
|
+
* local socket/pipe endpoint. Reuses the same incremental update and rule execution pipeline
|
|
5
|
+
* as `watchProject`, and verifies disk state synchronously on every client query to avoid
|
|
6
|
+
* watcher debounce races.
|
|
7
|
+
*/
|
|
8
|
+
export declare function startSharedSession(options: SharedSessionOptions): Promise<SharedSession>;
|
|
9
|
+
/**
|
|
10
|
+
* Queries a running shared analysis session over its local socket/pipe endpoint
|
|
11
|
+
* and returns the latest complete `CheckReport`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function requestSharedReport(options: RequestSharedReportOptions): Promise<CheckReport>;
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { mkdirSync, rmSync } from "node:fs";
|
|
2
|
+
import { createConnection, createServer, } from "node:net";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { VeruleExecutionError, } from "./types.js";
|
|
5
|
+
import { createWorkspaceController, toExecutionErrorInfo, } from "./watch.js";
|
|
6
|
+
function isNamedPipeEndpoint(endpoint) {
|
|
7
|
+
return process.platform === "win32" && endpoint.startsWith("\\\\.\\pipe\\");
|
|
8
|
+
}
|
|
9
|
+
function resolveEndpointPath(cwd, endpoint) {
|
|
10
|
+
if (isNamedPipeEndpoint(endpoint)) {
|
|
11
|
+
return endpoint;
|
|
12
|
+
}
|
|
13
|
+
return resolve(cwd, endpoint);
|
|
14
|
+
}
|
|
15
|
+
function probeSocketActive(endpoint) {
|
|
16
|
+
return new Promise((resolveProbe) => {
|
|
17
|
+
const socket = createConnection(endpoint);
|
|
18
|
+
const finish = (active) => {
|
|
19
|
+
socket.removeAllListeners();
|
|
20
|
+
socket.destroy();
|
|
21
|
+
resolveProbe(active);
|
|
22
|
+
};
|
|
23
|
+
socket.setTimeout(250, () => finish(false));
|
|
24
|
+
socket.once("connect", () => finish(true));
|
|
25
|
+
socket.once("error", () => finish(false));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function bindServerOnce(server, endpoint) {
|
|
29
|
+
return new Promise((resolveBind, rejectBind) => {
|
|
30
|
+
const onError = (err) => {
|
|
31
|
+
server.off("listening", onListening);
|
|
32
|
+
rejectBind(err);
|
|
33
|
+
};
|
|
34
|
+
const onListening = () => {
|
|
35
|
+
server.off("error", onError);
|
|
36
|
+
resolveBind();
|
|
37
|
+
};
|
|
38
|
+
server.once("error", onError);
|
|
39
|
+
server.once("listening", onListening);
|
|
40
|
+
server.listen(endpoint);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async function listenEndpoint(server, endpoint) {
|
|
44
|
+
if (!isNamedPipeEndpoint(endpoint)) {
|
|
45
|
+
mkdirSync(dirname(endpoint), { recursive: true });
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
await bindServerOnce(server, endpoint);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
const nodeErr = err;
|
|
52
|
+
if (nodeErr.code !== "EADDRINUSE" || isNamedPipeEndpoint(endpoint)) {
|
|
53
|
+
throw new VeruleExecutionError("ENGINE_ERROR", `Failed to listen on shared session endpoint "${endpoint}": ${nodeErr.message}`, { cause: err });
|
|
54
|
+
}
|
|
55
|
+
const active = await probeSocketActive(endpoint);
|
|
56
|
+
if (active) {
|
|
57
|
+
throw new VeruleExecutionError("INVALID_CONFIG", `Shared session endpoint "${endpoint}" is already in use by an active session.`);
|
|
58
|
+
}
|
|
59
|
+
rmSync(endpoint, { force: true });
|
|
60
|
+
try {
|
|
61
|
+
await bindServerOnce(server, endpoint);
|
|
62
|
+
}
|
|
63
|
+
catch (retryErr) {
|
|
64
|
+
const msg = retryErr instanceof Error ? retryErr.message : String(retryErr);
|
|
65
|
+
throw new VeruleExecutionError("ENGINE_ERROR", `Failed to listen on shared session endpoint "${endpoint}": ${msg}`, { cause: retryErr });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function parseSharedRequest(rawLine) {
|
|
70
|
+
let parsed;
|
|
71
|
+
try {
|
|
72
|
+
parsed = JSON.parse(rawLine);
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
throw new VeruleExecutionError("INVALID_CONFIG", `Invalid shared session request JSON: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
76
|
+
}
|
|
77
|
+
if (typeof parsed !== "object" ||
|
|
78
|
+
parsed === null ||
|
|
79
|
+
typeof parsed.id !== "string" ||
|
|
80
|
+
parsed.method !== "check") {
|
|
81
|
+
throw new VeruleExecutionError("INVALID_CONFIG", 'Shared session request must include string "id" and method "check".');
|
|
82
|
+
}
|
|
83
|
+
return parsed;
|
|
84
|
+
}
|
|
85
|
+
function toCheckParams(params) {
|
|
86
|
+
if (!params)
|
|
87
|
+
return undefined;
|
|
88
|
+
return {
|
|
89
|
+
...(params.ruleIds !== undefined ? { ruleIds: params.ruleIds } : {}),
|
|
90
|
+
...(params.at !== undefined ? { at: params.at } : {}),
|
|
91
|
+
...(params.observe !== undefined ? { observe: params.observe } : {}),
|
|
92
|
+
...(params.observeLimit !== undefined
|
|
93
|
+
? { observeLimit: params.observeLimit }
|
|
94
|
+
: {}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Starts an explicit long-lived shared analysis session bound to a single configuration and
|
|
99
|
+
* local socket/pipe endpoint. Reuses the same incremental update and rule execution pipeline
|
|
100
|
+
* as `watchProject`, and verifies disk state synchronously on every client query to avoid
|
|
101
|
+
* watcher debounce races.
|
|
102
|
+
*/
|
|
103
|
+
export async function startSharedSession(options) {
|
|
104
|
+
if (options.signal?.aborted) {
|
|
105
|
+
throw new VeruleExecutionError("SESSION_CLOSED", "Shared session startup was aborted.");
|
|
106
|
+
}
|
|
107
|
+
const absCwd = resolve(options.cwd);
|
|
108
|
+
const endpoint = resolveEndpointPath(absCwd, options.endpoint);
|
|
109
|
+
const controller = createWorkspaceController({
|
|
110
|
+
cwd: absCwd,
|
|
111
|
+
...(options.adapterResolutionRoot !== undefined
|
|
112
|
+
? { adapterResolutionRoot: options.adapterResolutionRoot }
|
|
113
|
+
: {}),
|
|
114
|
+
...(options.config !== undefined ? { config: options.config } : {}),
|
|
115
|
+
...(options.loadConfig !== undefined
|
|
116
|
+
? { loadConfig: options.loadConfig }
|
|
117
|
+
: {}),
|
|
118
|
+
...(options.watchFiles !== undefined
|
|
119
|
+
? { watchFiles: options.watchFiles }
|
|
120
|
+
: {}),
|
|
121
|
+
...(options.observe !== undefined ? { observe: options.observe } : {}),
|
|
122
|
+
...(options.observeLimit !== undefined
|
|
123
|
+
? { observeLimit: options.observeLimit }
|
|
124
|
+
: {}),
|
|
125
|
+
...(options.debounceMs !== undefined
|
|
126
|
+
? { debounceMs: options.debounceMs }
|
|
127
|
+
: {}),
|
|
128
|
+
onBatchReady: () => {
|
|
129
|
+
// Keep the engine snapshot warm in the background; errors are captured for client queries.
|
|
130
|
+
void controller.applyPendingBatch().catch(() => { });
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
try {
|
|
134
|
+
await controller.openInitial();
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
await controller.close();
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
const activeSockets = new Set();
|
|
141
|
+
let isClosed = false;
|
|
142
|
+
let closePromise;
|
|
143
|
+
let resolveClosed;
|
|
144
|
+
const closedDone = new Promise((resolveDone) => {
|
|
145
|
+
resolveClosed = resolveDone;
|
|
146
|
+
});
|
|
147
|
+
const server = createServer((socket) => {
|
|
148
|
+
if (isClosed) {
|
|
149
|
+
socket.destroy();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
activeSockets.add(socket);
|
|
153
|
+
socket.setEncoding("utf8");
|
|
154
|
+
let buffer = "";
|
|
155
|
+
let handled = false;
|
|
156
|
+
const writeResponse = (response) => {
|
|
157
|
+
if (!socket.destroyed) {
|
|
158
|
+
socket.end(`${JSON.stringify(response)}\n`);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const handleLine = async (line) => {
|
|
162
|
+
if (handled)
|
|
163
|
+
return;
|
|
164
|
+
handled = true;
|
|
165
|
+
let requestId = "";
|
|
166
|
+
try {
|
|
167
|
+
const request = parseSharedRequest(line);
|
|
168
|
+
requestId = request.id;
|
|
169
|
+
const report = await controller.checkLatest(toCheckParams(request.params));
|
|
170
|
+
writeResponse({
|
|
171
|
+
id: requestId,
|
|
172
|
+
ok: true,
|
|
173
|
+
report,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
const info = toExecutionErrorInfo(err);
|
|
178
|
+
writeResponse({
|
|
179
|
+
id: requestId,
|
|
180
|
+
ok: false,
|
|
181
|
+
error: info,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
socket.on("data", (chunk) => {
|
|
186
|
+
if (handled)
|
|
187
|
+
return;
|
|
188
|
+
buffer += chunk;
|
|
189
|
+
const newlineIndex = buffer.indexOf("\n");
|
|
190
|
+
if (newlineIndex === -1)
|
|
191
|
+
return;
|
|
192
|
+
const line = buffer.slice(0, newlineIndex).trim();
|
|
193
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
194
|
+
if (line.length > 0) {
|
|
195
|
+
void handleLine(line);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
socket.on("error", () => {
|
|
199
|
+
activeSockets.delete(socket);
|
|
200
|
+
socket.destroy();
|
|
201
|
+
});
|
|
202
|
+
socket.on("close", () => {
|
|
203
|
+
activeSockets.delete(socket);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
try {
|
|
207
|
+
await listenEndpoint(server, endpoint);
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
await controller.close();
|
|
211
|
+
throw err;
|
|
212
|
+
}
|
|
213
|
+
const close = async () => {
|
|
214
|
+
if (closePromise) {
|
|
215
|
+
return closePromise;
|
|
216
|
+
}
|
|
217
|
+
closePromise = (async () => {
|
|
218
|
+
isClosed = true;
|
|
219
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
220
|
+
for (const socket of activeSockets) {
|
|
221
|
+
socket.destroy();
|
|
222
|
+
}
|
|
223
|
+
activeSockets.clear();
|
|
224
|
+
await new Promise((resolveServerClose) => {
|
|
225
|
+
server.close(() => resolveServerClose());
|
|
226
|
+
});
|
|
227
|
+
if (!isNamedPipeEndpoint(endpoint)) {
|
|
228
|
+
rmSync(endpoint, { force: true });
|
|
229
|
+
}
|
|
230
|
+
await controller.close();
|
|
231
|
+
resolveClosed();
|
|
232
|
+
})();
|
|
233
|
+
return closePromise;
|
|
234
|
+
};
|
|
235
|
+
const onAbort = () => {
|
|
236
|
+
void close();
|
|
237
|
+
};
|
|
238
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
239
|
+
return {
|
|
240
|
+
endpoint,
|
|
241
|
+
get snapshotId() {
|
|
242
|
+
return controller.session?.snapshotId ?? 0;
|
|
243
|
+
},
|
|
244
|
+
get projects() {
|
|
245
|
+
return controller.session?.projects ?? [];
|
|
246
|
+
},
|
|
247
|
+
get closed() {
|
|
248
|
+
return isClosed;
|
|
249
|
+
},
|
|
250
|
+
waitUntilClosed: () => closedDone,
|
|
251
|
+
close,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Queries a running shared analysis session over its local socket/pipe endpoint
|
|
256
|
+
* and returns the latest complete `CheckReport`.
|
|
257
|
+
*/
|
|
258
|
+
export async function requestSharedReport(options) {
|
|
259
|
+
const endpoint = resolveEndpointPath(options.cwd ?? process.cwd(), options.endpoint);
|
|
260
|
+
return new Promise((resolveReport, rejectReport) => {
|
|
261
|
+
const socket = createConnection(endpoint);
|
|
262
|
+
socket.setEncoding("utf8");
|
|
263
|
+
let buffer = "";
|
|
264
|
+
let settled = false;
|
|
265
|
+
const finishError = (err) => {
|
|
266
|
+
if (settled)
|
|
267
|
+
return;
|
|
268
|
+
settled = true;
|
|
269
|
+
socket.destroy();
|
|
270
|
+
rejectReport(err);
|
|
271
|
+
};
|
|
272
|
+
const finishSuccess = (report) => {
|
|
273
|
+
if (settled)
|
|
274
|
+
return;
|
|
275
|
+
settled = true;
|
|
276
|
+
socket.destroy();
|
|
277
|
+
resolveReport(report);
|
|
278
|
+
};
|
|
279
|
+
if (options.timeoutMs !== undefined) {
|
|
280
|
+
socket.setTimeout(options.timeoutMs, () => {
|
|
281
|
+
finishError(new VeruleExecutionError("ENGINE_ERROR", `Timed out waiting for shared session response from "${endpoint}".`));
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
socket.once("connect", () => {
|
|
285
|
+
const request = {
|
|
286
|
+
id: "1",
|
|
287
|
+
method: "check",
|
|
288
|
+
params: {
|
|
289
|
+
...(options.ruleIds !== undefined
|
|
290
|
+
? { ruleIds: options.ruleIds }
|
|
291
|
+
: {}),
|
|
292
|
+
...(options.at !== undefined ? { at: options.at } : {}),
|
|
293
|
+
...(options.observe !== undefined
|
|
294
|
+
? { observe: options.observe }
|
|
295
|
+
: {}),
|
|
296
|
+
...(options.observeLimit !== undefined
|
|
297
|
+
? { observeLimit: options.observeLimit }
|
|
298
|
+
: {}),
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
socket.write(`${JSON.stringify(request)}\n`);
|
|
302
|
+
});
|
|
303
|
+
socket.on("data", (chunk) => {
|
|
304
|
+
if (settled)
|
|
305
|
+
return;
|
|
306
|
+
buffer += chunk;
|
|
307
|
+
const newlineIndex = buffer.indexOf("\n");
|
|
308
|
+
if (newlineIndex === -1)
|
|
309
|
+
return;
|
|
310
|
+
const line = buffer.slice(0, newlineIndex).trim();
|
|
311
|
+
if (line.length === 0)
|
|
312
|
+
return;
|
|
313
|
+
let parsed;
|
|
314
|
+
try {
|
|
315
|
+
parsed = JSON.parse(line);
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
finishError(new VeruleExecutionError("ENGINE_ERROR", `Malformed response from shared session "${endpoint}": ${err instanceof Error ? err.message : String(err)}`, { cause: err }));
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (!parsed.ok) {
|
|
322
|
+
finishError(new VeruleExecutionError(parsed.error.code, parsed.error.message, parsed.error.conflict !== undefined
|
|
323
|
+
? { conflict: parsed.error.conflict }
|
|
324
|
+
: undefined));
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
finishSuccess(parsed.report);
|
|
328
|
+
});
|
|
329
|
+
socket.once("end", () => {
|
|
330
|
+
if (!settled) {
|
|
331
|
+
finishError(new VeruleExecutionError("ENGINE_ERROR", `Shared session at "${endpoint}" closed the connection before sending a report.`));
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
socket.once("error", (err) => {
|
|
335
|
+
finishError(new VeruleExecutionError("ENGINE_ERROR", `Failed to connect to shared session at "${endpoint}": ${err.message}`, { cause: err }));
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { type AdditionalInputEntry, type AdditionalInputSource, type ConfiguredAdapter, type DiagnosticLocation, type EngineProviderExtractionStats, type Evidence, type ExplainCleanupPath, type ExplainLocalGap, type ExplainProviderEvaluation, type FactConflictDetails, type Gap, type LibraryAdapter, type MemoryStats, type Model, type NativeAdapterObservation, type ObserveLimit, type ObserveLimitInput, type ObserveMode, type ObserveOptions, type ProjectContext, type ProjectSummary, type RecomputationScope, type SourceFileOrigin, type SourceTarget, type SyntaxRef, type TssaeErrorCode } from "tssae";
|
|
2
|
+
import type { DiagnosticBasis } from "tssae";
|
|
3
|
+
export type { AdditionalInputEntry, AdditionalInputSource, ConfiguredAdapter, DiagnosticLocation, EngineProviderExtractionStats, Evidence, ExplainCleanupPath, ExplainLocalGap, ExplainProviderEvaluation, FactConflictDetails, Gap, LibraryAdapter, MemoryStats, Model, NativeAdapterObservation, ObserveLimit, ObserveLimitInput, ObserveMode, ObserveOptions, ProjectContext, ProjectSummary, RecomputationScope, SourceFileOrigin, SourceTarget, SyntaxRef, TssaeErrorCode, } from "tssae";
|
|
4
|
+
export declare const REPORT_SCHEMA_VERSION: "1";
|
|
5
|
+
export type VeruleErrorCode = TssaeErrorCode | "RULE_EXECUTION_ERROR";
|
|
6
|
+
/** Execution failure raised when analysis configuration, loading, queries, or rules fail. */
|
|
7
|
+
export declare class VeruleExecutionError extends Error {
|
|
8
|
+
readonly code: VeruleErrorCode;
|
|
9
|
+
readonly conflict?: FactConflictDetails;
|
|
10
|
+
constructor(code: VeruleErrorCode, message: string, options?: ErrorOptions & {
|
|
11
|
+
readonly conflict?: FactConflictDetails;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/** Maps upstream `TssaeError` or unknown exceptions into `VeruleExecutionError`. */
|
|
15
|
+
export declare function toVeruleError(error: unknown, fallbackCode?: VeruleErrorCode): VeruleExecutionError;
|
|
16
|
+
export type CheckpointOutcome = "pass" | "exclude" | "info";
|
|
17
|
+
export type CheckpointTarget = DiagnosticLocation | SyntaxRef | {
|
|
18
|
+
readonly location: DiagnosticLocation;
|
|
19
|
+
};
|
|
20
|
+
export type DiagnosticInput = {
|
|
21
|
+
readonly at: DiagnosticLocation;
|
|
22
|
+
readonly message: string;
|
|
23
|
+
readonly findingKey?: string;
|
|
24
|
+
/** Selected query results and explicit evidence, in diagnostic display order. */
|
|
25
|
+
readonly basis?: readonly DiagnosticBasis[];
|
|
26
|
+
};
|
|
27
|
+
export type Diagnostic = {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly ruleId: string;
|
|
30
|
+
readonly at: DiagnosticLocation;
|
|
31
|
+
readonly message: string;
|
|
32
|
+
readonly evidence: readonly Evidence[];
|
|
33
|
+
readonly projects: readonly string[];
|
|
34
|
+
};
|
|
35
|
+
export type RuleIdentitySummary = {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly digest: string;
|
|
38
|
+
};
|
|
39
|
+
export type ModelIdentitySummary = {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly version?: string;
|
|
42
|
+
readonly digest: string;
|
|
43
|
+
};
|
|
44
|
+
export type ReportIdentity = {
|
|
45
|
+
readonly snapshotDigest: string;
|
|
46
|
+
readonly configDigest: string;
|
|
47
|
+
readonly rules: readonly RuleIdentitySummary[];
|
|
48
|
+
readonly models: readonly ModelIdentitySummary[];
|
|
49
|
+
};
|
|
50
|
+
export type ObservationPhases = {
|
|
51
|
+
readonly configAndOpenMs: number;
|
|
52
|
+
readonly engineQueryMs: number;
|
|
53
|
+
readonly ruleExecutionMs: number;
|
|
54
|
+
readonly totalMs: number;
|
|
55
|
+
};
|
|
56
|
+
export type ObservationRpcMetrics = {
|
|
57
|
+
readonly batches: number;
|
|
58
|
+
readonly queryBatches: number;
|
|
59
|
+
readonly bytesSent: number;
|
|
60
|
+
readonly bytesReceived: number;
|
|
61
|
+
};
|
|
62
|
+
export type ObservationOverhead = {
|
|
63
|
+
readonly checkpointMs: number;
|
|
64
|
+
readonly encodeMs: number;
|
|
65
|
+
readonly writeMs: number;
|
|
66
|
+
};
|
|
67
|
+
export type ObservationDetailEntry = {
|
|
68
|
+
readonly kind: "query" | "checkpoint" | "engineStep";
|
|
69
|
+
readonly ruleId?: string;
|
|
70
|
+
readonly projectId?: string;
|
|
71
|
+
readonly provider?: string;
|
|
72
|
+
readonly name?: string;
|
|
73
|
+
readonly outcome?: CheckpointOutcome;
|
|
74
|
+
readonly cacheStatus?: "computed" | "reused";
|
|
75
|
+
readonly candidateCount?: number;
|
|
76
|
+
readonly durationMs?: number;
|
|
77
|
+
readonly at?: DiagnosticLocation;
|
|
78
|
+
readonly summary: string;
|
|
79
|
+
readonly detail?: unknown;
|
|
80
|
+
};
|
|
81
|
+
export type ObservationReport = {
|
|
82
|
+
readonly mode: Exclude<ObserveMode, "off">;
|
|
83
|
+
readonly phases: ObservationPhases;
|
|
84
|
+
readonly rpc: ObservationRpcMetrics;
|
|
85
|
+
readonly overhead: ObservationOverhead;
|
|
86
|
+
readonly queryCount: number;
|
|
87
|
+
readonly computedQueryCount: number;
|
|
88
|
+
readonly reusedQueryCount: number;
|
|
89
|
+
readonly candidateCount: number;
|
|
90
|
+
readonly checkpointCount: number;
|
|
91
|
+
readonly providers: readonly string[];
|
|
92
|
+
readonly nativeAdapters: readonly NativeAdapterObservation[];
|
|
93
|
+
readonly limit?: ObserveLimit;
|
|
94
|
+
readonly truncated: boolean;
|
|
95
|
+
readonly droppedCount: number;
|
|
96
|
+
readonly engineExtractions: Readonly<Record<string, EngineProviderExtractionStats>>;
|
|
97
|
+
readonly details?: readonly ObservationDetailEntry[];
|
|
98
|
+
};
|
|
99
|
+
export type ExplainStatus = "reported" | "excluded_by_checkpoint" | "excluded_by_query" | "not_in_candidates" | "target_not_in_project" | "suppressed_by_ignore" | "blocked_by_gap" | "covered_by_cleanup" | "rule_filtered";
|
|
100
|
+
export type ExplainQueryStep = {
|
|
101
|
+
readonly queryIndex: number;
|
|
102
|
+
readonly op: string;
|
|
103
|
+
readonly projectId: string;
|
|
104
|
+
readonly provider: string;
|
|
105
|
+
readonly cacheStatus: "computed" | "reused";
|
|
106
|
+
readonly candidateCount: number;
|
|
107
|
+
readonly matchedTarget: boolean;
|
|
108
|
+
readonly durationMs: number;
|
|
109
|
+
readonly summary?: string;
|
|
110
|
+
readonly detail?: unknown;
|
|
111
|
+
};
|
|
112
|
+
export type ExplainCheckpointTrace = {
|
|
113
|
+
readonly name: string;
|
|
114
|
+
readonly ruleId: string;
|
|
115
|
+
readonly projectId: string;
|
|
116
|
+
readonly outcome: CheckpointOutcome;
|
|
117
|
+
readonly at?: DiagnosticLocation;
|
|
118
|
+
readonly detail?: unknown;
|
|
119
|
+
};
|
|
120
|
+
export type ExplainResult = {
|
|
121
|
+
readonly ruleId: string;
|
|
122
|
+
readonly target: SourceTarget;
|
|
123
|
+
readonly status: ExplainStatus;
|
|
124
|
+
readonly inCandidates: boolean;
|
|
125
|
+
readonly summary: string;
|
|
126
|
+
readonly projectsChecked: readonly string[];
|
|
127
|
+
readonly matchingCandidates: readonly DiagnosticLocation[];
|
|
128
|
+
readonly excludedByQuery?: ExplainQueryStep;
|
|
129
|
+
readonly excludedByCheckpoint?: ExplainCheckpointTrace;
|
|
130
|
+
readonly queries: readonly ExplainQueryStep[];
|
|
131
|
+
readonly checkpoints: readonly ExplainCheckpointTrace[];
|
|
132
|
+
readonly gaps: readonly Gap[];
|
|
133
|
+
readonly localGaps: readonly ExplainLocalGap[];
|
|
134
|
+
readonly providerEvaluations: readonly ExplainProviderEvaluation[];
|
|
135
|
+
readonly providers: readonly string[];
|
|
136
|
+
readonly cleanupPaths: readonly ExplainCleanupPath[];
|
|
137
|
+
readonly inlineIgnore?: {
|
|
138
|
+
readonly matched: boolean;
|
|
139
|
+
readonly ruleId?: string;
|
|
140
|
+
readonly reason?: string;
|
|
141
|
+
readonly commentAt?: DiagnosticLocation;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
export type InlineIgnoreStatus = "suppressed" | "unused" | "ambiguous" | "malformed" | "unknown_rule" | "undetermined";
|
|
145
|
+
export type InlineIgnoreEntry = {
|
|
146
|
+
readonly status: InlineIgnoreStatus;
|
|
147
|
+
readonly at: DiagnosticLocation;
|
|
148
|
+
readonly targetLine?: number;
|
|
149
|
+
readonly ruleId?: string;
|
|
150
|
+
readonly reason?: string;
|
|
151
|
+
readonly matchedLocations?: readonly DiagnosticLocation[];
|
|
152
|
+
readonly message?: string;
|
|
153
|
+
};
|
|
154
|
+
export type CheckReport = {
|
|
155
|
+
readonly reportVersion: typeof REPORT_SCHEMA_VERSION;
|
|
156
|
+
readonly status: "clean" | "findings";
|
|
157
|
+
readonly projects: readonly ProjectSummary[];
|
|
158
|
+
readonly fileOrigins: readonly SourceFileOrigin[];
|
|
159
|
+
readonly additionalInputs: readonly AdditionalInputEntry[];
|
|
160
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
161
|
+
readonly gaps: readonly Gap[];
|
|
162
|
+
readonly identity: ReportIdentity;
|
|
163
|
+
readonly inlineIgnores?: readonly InlineIgnoreEntry[];
|
|
164
|
+
readonly observation?: ObservationReport;
|
|
165
|
+
readonly explanation?: ExplainResult;
|
|
166
|
+
readonly explanations?: readonly ExplainResult[];
|
|
167
|
+
};
|
|
168
|
+
export type ExplainReport = CheckReport & {
|
|
169
|
+
readonly explanation: ExplainResult;
|
|
170
|
+
};
|
|
171
|
+
/** Execution context exposed to Verule rules, backed by TSSAE `ProjectContext` queries. */
|
|
172
|
+
export type RuleContext = ProjectContext & {
|
|
173
|
+
report: (diagnostic: DiagnosticInput) => void;
|
|
174
|
+
/**
|
|
175
|
+
* Records a named TS judgment checkpoint for explainability and detail observation.
|
|
176
|
+
* When observation and explanation are disabled, `detail` is never invoked.
|
|
177
|
+
*/
|
|
178
|
+
checkpoint: (name: string, target: CheckpointTarget, outcome: CheckpointOutcome, detail?: () => unknown) => void;
|
|
179
|
+
};
|
|
180
|
+
export type Rule = {
|
|
181
|
+
readonly id: string;
|
|
182
|
+
readonly description?: string;
|
|
183
|
+
readonly run: (ctx: RuleContext) => void | Promise<void>;
|
|
184
|
+
};
|
|
185
|
+
export type VeruleConfig = {
|
|
186
|
+
readonly tsconfig?: string;
|
|
187
|
+
readonly projects?: readonly string[];
|
|
188
|
+
readonly rules?: readonly Rule[];
|
|
189
|
+
readonly models?: readonly Model[];
|
|
190
|
+
readonly adapters?: readonly ConfiguredAdapter[];
|
|
191
|
+
readonly additionalInputs?: readonly string[];
|
|
192
|
+
};
|
|
193
|
+
export type NormalizedVeruleConfig = {
|
|
194
|
+
readonly tsconfig?: string;
|
|
195
|
+
readonly projects?: readonly string[];
|
|
196
|
+
readonly rules: readonly Rule[];
|
|
197
|
+
readonly models: readonly Model[];
|
|
198
|
+
readonly adapters: readonly LibraryAdapter[];
|
|
199
|
+
readonly adapterPackages: readonly string[];
|
|
200
|
+
readonly additionalInputs: readonly string[];
|
|
201
|
+
};
|
|
202
|
+
export type SessionCheckOptions = {
|
|
203
|
+
readonly rulesOverride?: readonly Rule[];
|
|
204
|
+
readonly ruleIds?: readonly string[];
|
|
205
|
+
readonly at?: string | SourceTarget;
|
|
206
|
+
readonly observe?: ObserveMode | ObserveOptions;
|
|
207
|
+
readonly observeLimit?: ObserveLimitInput;
|
|
208
|
+
readonly configLoadMs?: number;
|
|
209
|
+
};
|
|
210
|
+
export type ExplainOptions = {
|
|
211
|
+
readonly ruleId?: string;
|
|
212
|
+
readonly at: string | SourceTarget;
|
|
213
|
+
readonly observe?: ObserveMode | ObserveOptions;
|
|
214
|
+
readonly observeLimit?: ObserveLimitInput;
|
|
215
|
+
readonly rulesOverride?: readonly Rule[];
|
|
216
|
+
};
|
|
217
|
+
export type OpenSessionOptions = {
|
|
218
|
+
readonly cwd: string;
|
|
219
|
+
readonly config?: VeruleConfig | NormalizedVeruleConfig;
|
|
220
|
+
/** Directory used to resolve adapter package names; defaults to `cwd`. */
|
|
221
|
+
readonly adapterResolutionRoot?: string;
|
|
222
|
+
readonly observe?: ObserveMode | ObserveOptions;
|
|
223
|
+
readonly observeLimit?: ObserveLimitInput;
|
|
224
|
+
readonly configLoadMs?: number;
|
|
225
|
+
};
|
|
226
|
+
export type RunCheckOptions = OpenSessionOptions & {
|
|
227
|
+
readonly ruleIds?: readonly string[];
|
|
228
|
+
readonly at?: string | SourceTarget;
|
|
229
|
+
};
|
|
230
|
+
export type SessionUpdateOptions = {
|
|
231
|
+
readonly changed?: readonly string[];
|
|
232
|
+
readonly created?: readonly string[];
|
|
233
|
+
readonly deleted?: readonly string[];
|
|
234
|
+
readonly config?: VeruleConfig | NormalizedVeruleConfig;
|
|
235
|
+
readonly adapterResolutionRoot?: string;
|
|
236
|
+
readonly rules?: readonly Rule[];
|
|
237
|
+
readonly models?: readonly Model[];
|
|
238
|
+
readonly adapters?: readonly ConfiguredAdapter[];
|
|
239
|
+
readonly entries?: readonly string[];
|
|
240
|
+
readonly additionalInputs?: readonly string[];
|
|
241
|
+
};
|
|
242
|
+
export type SessionUpdateResult = {
|
|
243
|
+
readonly previousSnapshotId: number;
|
|
244
|
+
readonly snapshotId: number;
|
|
245
|
+
readonly projects: readonly ProjectSummary[];
|
|
246
|
+
readonly fileOrigins: readonly SourceFileOrigin[];
|
|
247
|
+
readonly additionalInputs: readonly AdditionalInputEntry[];
|
|
248
|
+
readonly recomputation: RecomputationScope;
|
|
249
|
+
readonly memory: MemoryStats;
|
|
250
|
+
};
|
|
251
|
+
export type AnalysisSession = {
|
|
252
|
+
readonly snapshotId: number;
|
|
253
|
+
readonly projects: readonly ProjectSummary[];
|
|
254
|
+
readonly fileOrigins: readonly SourceFileOrigin[];
|
|
255
|
+
readonly additionalInputs: readonly AdditionalInputEntry[];
|
|
256
|
+
readonly memory: MemoryStats;
|
|
257
|
+
registerAdditionalInput: (filePath: string, source: AdditionalInputSource) => AdditionalInputEntry;
|
|
258
|
+
check: (optionsOrRules?: readonly Rule[] | SessionCheckOptions) => Promise<CheckReport>;
|
|
259
|
+
update: (options?: SessionUpdateOptions) => Promise<SessionUpdateResult>;
|
|
260
|
+
explain: (options: ExplainOptions) => Promise<ExplainReport>;
|
|
261
|
+
close: () => Promise<void>;
|
|
262
|
+
};
|
|
263
|
+
export type WatchTrigger = "initial" | "change";
|
|
264
|
+
export type WatchConfigLoadResult = {
|
|
265
|
+
readonly config: VeruleConfig | NormalizedVeruleConfig;
|
|
266
|
+
readonly adapterResolutionRoot?: string;
|
|
267
|
+
readonly watchFiles?: readonly string[];
|
|
268
|
+
};
|
|
269
|
+
export type WatchProjectOptions = {
|
|
270
|
+
readonly cwd: string;
|
|
271
|
+
readonly config?: VeruleConfig | NormalizedVeruleConfig;
|
|
272
|
+
/** Directory used to resolve adapter package names; defaults to `cwd`. */
|
|
273
|
+
readonly adapterResolutionRoot?: string;
|
|
274
|
+
readonly loadConfig?: () => Promise<WatchConfigLoadResult>;
|
|
275
|
+
readonly watchFiles?: readonly string[];
|
|
276
|
+
readonly observe?: ObserveMode;
|
|
277
|
+
readonly observeLimit?: ObserveLimitInput;
|
|
278
|
+
readonly debounceMs?: number;
|
|
279
|
+
readonly signal?: AbortSignal;
|
|
280
|
+
};
|
|
281
|
+
export type WatchReportEvent = {
|
|
282
|
+
readonly kind: "report";
|
|
283
|
+
readonly sequence: number;
|
|
284
|
+
readonly trigger: WatchTrigger;
|
|
285
|
+
readonly snapshotId: number;
|
|
286
|
+
readonly recomputation: RecomputationScope;
|
|
287
|
+
readonly memory: MemoryStats;
|
|
288
|
+
readonly report: CheckReport;
|
|
289
|
+
};
|
|
290
|
+
export type WatchFailureEvent = {
|
|
291
|
+
readonly kind: "failed";
|
|
292
|
+
readonly sequence: number;
|
|
293
|
+
readonly trigger: WatchTrigger;
|
|
294
|
+
readonly code: VeruleErrorCode;
|
|
295
|
+
readonly message: string;
|
|
296
|
+
readonly conflict?: FactConflictDetails;
|
|
297
|
+
};
|
|
298
|
+
export type WatchEvent = WatchReportEvent | WatchFailureEvent;
|
|
299
|
+
export type SharedSessionOptions = {
|
|
300
|
+
readonly cwd: string;
|
|
301
|
+
readonly endpoint: string;
|
|
302
|
+
readonly config?: VeruleConfig | NormalizedVeruleConfig;
|
|
303
|
+
/** Directory used to resolve adapter package names; defaults to `cwd`. */
|
|
304
|
+
readonly adapterResolutionRoot?: string;
|
|
305
|
+
readonly loadConfig?: () => Promise<WatchConfigLoadResult>;
|
|
306
|
+
readonly watchFiles?: readonly string[];
|
|
307
|
+
readonly observe?: ObserveMode;
|
|
308
|
+
readonly observeLimit?: ObserveLimitInput;
|
|
309
|
+
readonly debounceMs?: number;
|
|
310
|
+
readonly signal?: AbortSignal;
|
|
311
|
+
};
|
|
312
|
+
export type SharedSession = {
|
|
313
|
+
readonly endpoint: string;
|
|
314
|
+
readonly snapshotId: number;
|
|
315
|
+
readonly projects: readonly ProjectSummary[];
|
|
316
|
+
readonly closed: boolean;
|
|
317
|
+
waitUntilClosed: () => Promise<void>;
|
|
318
|
+
close: () => Promise<void>;
|
|
319
|
+
};
|
|
320
|
+
export type RequestSharedReportOptions = {
|
|
321
|
+
readonly endpoint: string;
|
|
322
|
+
readonly cwd?: string;
|
|
323
|
+
readonly ruleIds?: readonly string[];
|
|
324
|
+
readonly at?: string | SourceTarget;
|
|
325
|
+
readonly observe?: ObserveMode | ObserveOptions;
|
|
326
|
+
readonly observeLimit?: ObserveLimitInput;
|
|
327
|
+
readonly timeoutMs?: number;
|
|
328
|
+
};
|