@moldea.ai/core 5.0.1 → 6.0.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.
Files changed (71) hide show
  1. package/README.md +11 -4
  2. package/dist/adapter/index.d.ts +16 -4
  3. package/dist/adapter/index.d.ts.map +1 -1
  4. package/dist/adapter-execution/index.d.ts +12 -9
  5. package/dist/adapter-execution/index.d.ts.map +1 -1
  6. package/dist/adapter-result-collection/collection.d.ts +13 -0
  7. package/dist/adapter-result-collection/collection.d.ts.map +1 -0
  8. package/dist/adapter-result-collection/index.d.ts +3 -0
  9. package/dist/adapter-result-collection/index.d.ts.map +1 -0
  10. package/dist/adapter-result-collection/types.d.ts +31 -0
  11. package/dist/adapter-result-collection/types.d.ts.map +1 -0
  12. package/dist/adapter.js +3 -2
  13. package/dist/adapter.js.map +1 -1
  14. package/dist/analysis-worker.js +190 -0
  15. package/dist/analysis-worker.js.map +1 -0
  16. package/dist/chunks/collection-CvbjjLf2.js +73 -0
  17. package/dist/chunks/collection-CvbjjLf2.js.map +1 -0
  18. package/dist/chunks/core-DchheNDz.js +5305 -0
  19. package/dist/chunks/core-DchheNDz.js.map +1 -0
  20. package/dist/chunks/errors-BQI1DEqf.js +446 -0
  21. package/dist/chunks/errors-BQI1DEqf.js.map +1 -0
  22. package/dist/chunks/{exceptions-HS9ofVy2.js → exceptions-lzD3buFw.js} +26 -15
  23. package/dist/chunks/exceptions-lzD3buFw.js.map +1 -0
  24. package/dist/chunks/lifecycle-4EkWgEHm.js +67 -0
  25. package/dist/chunks/lifecycle-4EkWgEHm.js.map +1 -0
  26. package/dist/chunks/options-CxCT3dZU.js +617 -0
  27. package/dist/chunks/options-CxCT3dZU.js.map +1 -0
  28. package/dist/chunks/repository-rpc-BWi6X1la.js +124 -0
  29. package/dist/chunks/repository-rpc-BWi6X1la.js.map +1 -0
  30. package/dist/contracts/index.d.ts +28 -18
  31. package/dist/contracts/index.d.ts.map +1 -1
  32. package/dist/custom-runtime-inspection/index.d.ts +2 -0
  33. package/dist/custom-runtime-inspection/index.d.ts.map +1 -0
  34. package/dist/custom-runtime-inspection/inspection.d.ts +11 -0
  35. package/dist/custom-runtime-inspection/inspection.d.ts.map +1 -0
  36. package/dist/exceptions/index.d.ts +23 -4
  37. package/dist/exceptions/index.d.ts.map +1 -1
  38. package/dist/index.d.ts +1 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +3 -5775
  41. package/dist/node/index.d.ts +4 -0
  42. package/dist/node/index.d.ts.map +1 -0
  43. package/dist/node-inspection/analysis-worker.d.ts +2 -0
  44. package/dist/node-inspection/analysis-worker.d.ts.map +1 -0
  45. package/dist/node-inspection/client.d.ts +32 -0
  46. package/dist/node-inspection/client.d.ts.map +1 -0
  47. package/dist/node-inspection/constants.d.ts +21 -0
  48. package/dist/node-inspection/constants.d.ts.map +1 -0
  49. package/dist/node-inspection/errors.d.ts +11 -0
  50. package/dist/node-inspection/errors.d.ts.map +1 -0
  51. package/dist/node-inspection/lifecycle.d.ts +15 -0
  52. package/dist/node-inspection/lifecycle.d.ts.map +1 -0
  53. package/dist/node-inspection/protocol.d.ts +20 -0
  54. package/dist/node-inspection/protocol.d.ts.map +1 -0
  55. package/dist/node-inspection/repository-rpc.d.ts +28 -0
  56. package/dist/node-inspection/repository-rpc.d.ts.map +1 -0
  57. package/dist/node-inspection/runner.d.ts +2 -0
  58. package/dist/node-inspection/runner.d.ts.map +1 -0
  59. package/dist/node-inspection/types.d.ts +99 -0
  60. package/dist/node-inspection/types.d.ts.map +1 -0
  61. package/dist/node-runner.js +149 -0
  62. package/dist/node-runner.js.map +1 -0
  63. package/dist/node.js +325 -0
  64. package/dist/node.js.map +1 -0
  65. package/dist/project-inspection/index.d.ts +22 -1
  66. package/dist/project-inspection/index.d.ts.map +1 -1
  67. package/dist/project-validation/index.d.ts +34 -10
  68. package/dist/project-validation/index.d.ts.map +1 -1
  69. package/package.json +9 -1
  70. package/dist/chunks/exceptions-HS9ofVy2.js.map +0 -1
  71. package/dist/index.js.map +0 -1
@@ -0,0 +1,446 @@
1
+ import { a as isCoreOperationErrorCode, i as isCoreOperation, n as CoreOperationException, r as isCoreConfigurationErrorCode, t as CoreConfigurationException } from "./exceptions-lzD3buFw.js";
2
+ import { RepositoryPathException, RepositorySourceException, isRepositoryPath } from "@moldea.ai/repository";
3
+ import { Buffer } from "node:buffer";
4
+ //#region src/node-inspection/constants.ts
5
+ var NODE_INSPECTION_LIFETIME_MS = 12e4;
6
+ var NODE_INSPECTION_TERMINATION_GRACE_MS = 1e3;
7
+ var NODE_INSPECTION_FILE_PAGE_BYTES = 65536;
8
+ var NODE_INSPECTION_MESSAGE_BYTES = 1048576;
9
+ var NODE_INSPECTION_STDIO_BYTES = 32768;
10
+ var NODE_INSPECTION_TRANSPORT_BYTES = 4 * NODE_INSPECTION_MESSAGE_BYTES * 2 * 2 * 3;
11
+ var NODE_INSPECTION_PROFILE = Object.freeze({
12
+ lifetimeMs: NODE_INSPECTION_LIFETIME_MS,
13
+ terminationGraceMs: NODE_INSPECTION_TERMINATION_GRACE_MS,
14
+ maxReaderRequests: 4,
15
+ maxFilePageBytes: NODE_INSPECTION_FILE_PAGE_BYTES,
16
+ maxMessageBytes: NODE_INSPECTION_MESSAGE_BYTES,
17
+ maxStdioBytes: NODE_INSPECTION_STDIO_BYTES,
18
+ transportBytes: NODE_INSPECTION_TRANSPORT_BYTES,
19
+ oldGenerationMiB: 512,
20
+ youngGenerationMiB: 24
21
+ });
22
+ //#endregion
23
+ //#region src/node-inspection/protocol.ts
24
+ /** Creates the safe failure for an untrusted or inconsistent private protocol record. */
25
+ var createInspectionProcessFailure = (cause) => new CoreOperationException({
26
+ code: "INSPECTION_PROCESS_FAILED",
27
+ operation: "create-project-inspection",
28
+ ...cause === void 0 ? {} : { cause }
29
+ });
30
+ var isRecord = (input) => input !== null && typeof input === "object" && !Array.isArray(input);
31
+ var JSON_SHORT_ESCAPES = /* @__PURE__ */ new Set([
32
+ 8,
33
+ 9,
34
+ 10,
35
+ 12,
36
+ 13
37
+ ]);
38
+ var isInteger = (input) => typeof input === "number" && Number.isSafeInteger(input) && input >= 0;
39
+ var hasKeys = (input, required, optional = []) => required.every((key) => Object.hasOwn(input, key)) && Object.keys(input).every((key) => required.includes(key) || optional.includes(key));
40
+ var isSnapshot = (input) => isRecord(input) && hasKeys(input, ["id", "sourceKind"]) && typeof input["id"] === "string" && input["id"].length > 0 && typeof input["sourceKind"] === "string" && input["sourceKind"].length > 0;
41
+ var isOptionalString = (input, key) => !Object.hasOwn(input, key) || typeof input[key] === "string";
42
+ var isRegistryUrl = (input) => {
43
+ if (typeof input !== "string") return false;
44
+ try {
45
+ const url = new URL(input);
46
+ return url.protocol === "file:" && url.search === "" && url.hash === "";
47
+ } catch {
48
+ return false;
49
+ }
50
+ };
51
+ var isPageInput = (input) => isRecord(input) && hasKeys(input, ["maxItems", "view"], ["cursor"]) && isInteger(input["maxItems"]) && input["maxItems"] > 0 && [
52
+ "all",
53
+ "diagnostics",
54
+ "evidence",
55
+ "metadata"
56
+ ].includes(String(input["view"])) && isOptionalString(input, "cursor");
57
+ var isLimits = (input) => isRecord(input) && hasKeys(input, [
58
+ "maxEntries",
59
+ "maxTotalBytesRead",
60
+ "maxFileBytes",
61
+ "maxManifestBytes",
62
+ "maxRetainedBytes",
63
+ "maxDiagnostics",
64
+ "maxEvidence"
65
+ ]) && Object.values(input).every((limit) => isInteger(limit) && limit > 0);
66
+ var isCounts = (input) => isRecord(input) && hasKeys(input, [
67
+ "agents",
68
+ "context",
69
+ "decisions",
70
+ "mirrors",
71
+ "runtimes",
72
+ "unresolved",
73
+ "diagnostics",
74
+ "errors",
75
+ "warnings",
76
+ "evidence",
77
+ "metadata"
78
+ ]) && Object.values(input).every(isInteger);
79
+ var isSummary = (input) => input === null || isRecord(input) && hasKeys(input, [
80
+ "counts",
81
+ "manifestDigest",
82
+ "manifestPath",
83
+ "projectDigest",
84
+ "projectPath"
85
+ ]) && isRecord(input["counts"]) && hasKeys(input["counts"], [
86
+ "agents",
87
+ "context",
88
+ "decisions",
89
+ "mirrors",
90
+ "runtimes",
91
+ "unresolved"
92
+ ]) && Object.values(input["counts"]).every(isInteger) && typeof input["manifestDigest"] === "string" && typeof input["projectDigest"] === "string" && isRepositoryPath(input["manifestPath"]) && isRepositoryPath(input["projectPath"]);
93
+ var isInspectionBase = (input) => isCounts(input["counts"]) && typeof input["valid"] === "boolean" && [
94
+ "complete",
95
+ "incomplete",
96
+ "not-run"
97
+ ].includes(String(input["runtimeInspection"])) && (input["formatVersion"] === null || input["formatVersion"] === 1) && typeof input["inspectionDigest"] === "string" && isSnapshot(input["source"]) && isSummary(input["summary"]);
98
+ var INSPECTION_KEYS = [
99
+ "counts",
100
+ "valid",
101
+ "runtimeInspection",
102
+ "formatVersion",
103
+ "inspectionDigest",
104
+ "source",
105
+ "summary"
106
+ ];
107
+ var isMetadata = (input) => isRecord(input) && hasKeys(input, [
108
+ ...INSPECTION_KEYS,
109
+ "resourceUsage",
110
+ "adapters",
111
+ "maxAnalysisHeapBytes"
112
+ ]) && isInspectionBase(input) && isInteger(input["maxAnalysisHeapBytes"]) && input["maxAnalysisHeapBytes"] > 0 && isRecord(input["resourceUsage"]) && hasKeys(input["resourceUsage"], [
113
+ "canonicalBytes",
114
+ "peakRetainedBytes",
115
+ "preparedBytes",
116
+ "retainedBytes",
117
+ "totalBytesRead"
118
+ ]) && Object.values(input["resourceUsage"]).every(isInteger) && Array.isArray(input["adapters"]) && input["adapters"].every((adapter) => isRecord(adapter) && hasKeys(adapter, ["id", "supportedRepositoryFormatVersions"]) && typeof adapter["id"] === "string" && Array.isArray(adapter["supportedRepositoryFormatVersions"]) && adapter["supportedRepositoryFormatVersions"].every((version) => isInteger(version) && version > 0));
119
+ var isPage = (input) => isRecord(input) && hasKeys(input, [
120
+ ...INSPECTION_KEYS,
121
+ "page",
122
+ "view"
123
+ ]) && isInspectionBase(input) && [
124
+ "all",
125
+ "diagnostics",
126
+ "evidence",
127
+ "metadata"
128
+ ].includes(String(input["view"])) && isRecord(input["page"]) && hasKeys(input["page"], [
129
+ "isComplete",
130
+ "records",
131
+ "nextCursor",
132
+ "totalItems"
133
+ ]) && typeof input["page"]["isComplete"] === "boolean" && isInteger(input["page"]["totalItems"]) && (input["page"]["nextCursor"] === null || typeof input["page"]["nextCursor"] === "string") && Array.isArray(input["page"]["records"]) && input["page"]["records"].every((record) => isRecord(record) && hasKeys(record, ["item", "nextCursor"]) && (record["nextCursor"] === null || typeof record["nextCursor"] === "string") && isRecord(record["item"]) && typeof record["item"]["kind"] === "string" && [
134
+ "agent",
135
+ "diagnostic",
136
+ "evidence",
137
+ "metadata"
138
+ ].includes(record["item"]["kind"]) && hasKeys(record["item"], ["kind", record["item"]["kind"]]) && isRecord(record["item"][record["item"]["kind"]]));
139
+ var isRequest = (input) => {
140
+ if (!isRecord(input)) return false;
141
+ switch (input["method"]) {
142
+ case "getEntry": return hasKeys(input, ["method", "path"]) && isRepositoryPath(input["path"]);
143
+ case "listEntriesPage": return hasKeys(input, ["method", "maxEntries"], ["cursor", "prefix"]) && isInteger(input["maxEntries"]) && input["maxEntries"] > 0 && input["maxEntries"] <= 128 && isOptionalString(input, "cursor") && (!Object.hasOwn(input, "prefix") || isRepositoryPath(input["prefix"]));
144
+ case "readFilePage": return hasKeys(input, [
145
+ "method",
146
+ "path",
147
+ "maxBytes",
148
+ "offset"
149
+ ]) && isRepositoryPath(input["path"]) && isInteger(input["offset"]) && isInteger(input["maxBytes"]) && input["maxBytes"] > 0 && input["maxBytes"] <= 65536;
150
+ default: return false;
151
+ }
152
+ };
153
+ /** Validates closed control envelopes and their typed operation payloads on both bridges. */
154
+ var isMessage = (input) => {
155
+ if (!isRecord(input) || typeof input["attemptId"] !== "string" || !/^[a-f0-9]{32}$/.test(input["attemptId"])) return false;
156
+ const keys = ["attemptId", "kind"];
157
+ switch (input["kind"]) {
158
+ case "start": return hasKeys(input, [
159
+ ...keys,
160
+ "registryUrl",
161
+ "snapshot",
162
+ "limits",
163
+ "deadline"
164
+ ]) && isRegistryUrl(input["registryUrl"]) && isSnapshot(input["snapshot"]) && isLimits(input["limits"]) && isInteger(input["deadline"]);
165
+ case "ready": return hasKeys(input, [...keys, "maxAnalysisHeapBytes"]) && isInteger(input["maxAnalysisHeapBytes"]) && input["maxAnalysisHeapBytes"] > 0;
166
+ case "run":
167
+ case "dispose": return hasKeys(input, keys);
168
+ case "prepared": return hasKeys(input, [...keys, "inspection"]) && isMetadata(input["inspection"]);
169
+ case "read-page": return hasKeys(input, [
170
+ ...keys,
171
+ "requestId",
172
+ "input"
173
+ ]) && isInteger(input["requestId"]) && isPageInput(input["input"]);
174
+ case "page": return hasKeys(input, [
175
+ ...keys,
176
+ "requestId",
177
+ "result"
178
+ ]) && isInteger(input["requestId"]) && isPage(input["result"]);
179
+ case "reader-request": return hasKeys(input, [
180
+ ...keys,
181
+ "requestId",
182
+ "request"
183
+ ]) && isInteger(input["requestId"]) && isRequest(input["request"]);
184
+ case "reader-response": return hasKeys(input, [
185
+ ...keys,
186
+ "requestId",
187
+ "result"
188
+ ]) && isInteger(input["requestId"]);
189
+ case "failure": return hasKeys(input, [...keys, "failure"]) && isRecord(input["failure"]) && hasKeys(input["failure"], ["family", "options"]) && [
190
+ "configuration",
191
+ "operation",
192
+ "repository",
193
+ "path"
194
+ ].includes(String(input["failure"]["family"])) && isRecord(input["failure"]["options"]);
195
+ default: return false;
196
+ }
197
+ };
198
+ /** Counts escaped JSON bytes without first allocating a serialized oversized message. */
199
+ var countJsonBytes = (input, ancestors, depth) => {
200
+ if (depth > 64) throw createInspectionProcessFailure();
201
+ if (input === null) return 4;
202
+ if (typeof input === "boolean") return input ? 4 : 5;
203
+ if (typeof input === "number" && Number.isFinite(input)) return String(input).length;
204
+ if (typeof input === "string") {
205
+ let bytes = 2;
206
+ for (let index = 0; index < input.length; index++) {
207
+ const code = input.charCodeAt(index);
208
+ if (code === 34 || code === 92 || JSON_SHORT_ESCAPES.has(code)) bytes += 2;
209
+ else if (code < 32) bytes += 6;
210
+ else if (code < 128) bytes++;
211
+ else if (code < 2048) bytes += 2;
212
+ else if (code >= 55296 && code <= 56319 && index + 1 < input.length && input.charCodeAt(index + 1) >= 56320 && input.charCodeAt(index + 1) <= 57343) {
213
+ bytes += 4;
214
+ index++;
215
+ } else bytes += code >= 55296 && code <= 57343 ? 6 : 3;
216
+ if (bytes > 1048576) return bytes;
217
+ }
218
+ return bytes;
219
+ }
220
+ if (typeof input !== "object" || ancestors.has(input)) throw createInspectionProcessFailure();
221
+ ancestors.add(input);
222
+ let bytes = 2;
223
+ let count = 0;
224
+ if (Array.isArray(input)) for (const element of input) {
225
+ bytes += (count++ === 0 ? 0 : 1) + countJsonBytes(element, ancestors, depth + 1);
226
+ if (bytes > 1048576) break;
227
+ }
228
+ else for (const key in input) {
229
+ if (!Object.hasOwn(input, key)) continue;
230
+ bytes += (count++ === 0 ? 0 : 1) + countJsonBytes(key, ancestors, depth + 1) + 1 + countJsonBytes(input[key], ancestors, depth + 1);
231
+ if (bytes > 1048576) break;
232
+ }
233
+ ancestors.delete(input);
234
+ return bytes;
235
+ };
236
+ /**
237
+ * Admits a complete bounded record before serialization; no record is truncated.
238
+ * @returns One private JSON frame.
239
+ * @throws
240
+ * - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.
241
+ * - INSPECTION_PROCESS_FAILED: The isolated project inspection failed.
242
+ */
243
+ var encodeInspectionMessage = (message) => {
244
+ const bytes = countJsonBytes(message, /* @__PURE__ */ new WeakSet(), 0);
245
+ if (bytes > 1048576) throw new CoreOperationException({
246
+ code: "RESOURCE_LIMIT_EXCEEDED",
247
+ limit: "maxInspectionMessageBytes",
248
+ limitMaximum: NODE_INSPECTION_MESSAGE_BYTES,
249
+ observedUsage: bytes,
250
+ nextAction: null,
251
+ operation: "create-project-inspection"
252
+ });
253
+ if (!isMessage(message)) throw createInspectionProcessFailure();
254
+ return JSON.stringify(message);
255
+ };
256
+ /**
257
+ * Checks frame size before parsing and validates the closed message contract.
258
+ * @returns A validated private message.
259
+ * @throws
260
+ * - INSPECTION_PROCESS_FAILED: The isolated project inspection failed.
261
+ */
262
+ var decodeInspectionMessage = (frame) => {
263
+ if (typeof frame !== "string" || Buffer.byteLength(frame) > 1048576) throw createInspectionProcessFailure();
264
+ let message;
265
+ try {
266
+ message = JSON.parse(frame);
267
+ } catch (cause) {
268
+ throw createInspectionProcessFailure(cause);
269
+ }
270
+ if (!isMessage(message)) throw createInspectionProcessFailure();
271
+ return message;
272
+ };
273
+ //#endregion
274
+ //#region src/node-inspection/errors.ts
275
+ /** Serializes only documented exception fields, excluding native messages, causes and stacks. */
276
+ var serializeInspectionFailure = (error) => {
277
+ if (error instanceof CoreConfigurationException) return {
278
+ family: "configuration",
279
+ options: {
280
+ code: error.code,
281
+ operation: error.operation,
282
+ ...error.adapterId === null ? {} : { adapterId: error.adapterId }
283
+ }
284
+ };
285
+ if (error instanceof CoreOperationException) return {
286
+ family: "operation",
287
+ options: {
288
+ code: error.code,
289
+ operation: error.operation,
290
+ ...error.adapterId === null ? {} : { adapterId: error.adapterId },
291
+ ...error.agentId === null ? {} : { agentId: error.agentId },
292
+ ...error.code !== "RESOURCE_LIMIT_EXCEEDED" ? {} : {
293
+ limit: error.limit,
294
+ limitMaximum: error.limitMaximum,
295
+ nextAction: error.nextAction,
296
+ observedUsage: error.observedUsage
297
+ }
298
+ }
299
+ };
300
+ if (error instanceof RepositoryPathException) return {
301
+ family: "path",
302
+ options: {}
303
+ };
304
+ if (error instanceof RepositorySourceException) return {
305
+ family: "repository",
306
+ options: {
307
+ code: error.code,
308
+ operation: error.operation,
309
+ path: error.path,
310
+ retryable: error.retryable,
311
+ ...error.resource === null ? {} : { resource: error.resource }
312
+ }
313
+ };
314
+ return {
315
+ family: "operation",
316
+ options: {
317
+ code: "INSPECTION_PROCESS_FAILED",
318
+ operation: "create-project-inspection"
319
+ }
320
+ };
321
+ };
322
+ var REPOSITORY_CODES = [
323
+ "ENTRY_NOT_FOUND",
324
+ "ENTRY_NOT_FILE",
325
+ "ENTRY_NOT_DIRECTORY",
326
+ "INVALID_PAGE_REQUEST",
327
+ "ACCESS_DENIED",
328
+ "SOURCE_UNAVAILABLE",
329
+ "SNAPSHOT_CHANGED",
330
+ "PROVIDER_INCOMPLETE",
331
+ "INVALID_SOURCE_DATA",
332
+ "RESOURCE_LIMIT_EXCEEDED",
333
+ "ABORTED"
334
+ ];
335
+ var REPOSITORY_OPERATIONS = [
336
+ "create-reader",
337
+ "create-comparison",
338
+ "get-entry",
339
+ "read-file-page",
340
+ "list-entries-page",
341
+ "list-changes-page"
342
+ ];
343
+ var isNumber = (input) => typeof input === "number" && Number.isSafeInteger(input) && input >= 0;
344
+ /**
345
+ * Reconstructs a documented typed failure after checking its safe transport fields.
346
+ * @returns A package exception without a remote native cause or stack.
347
+ * @throws
348
+ * - INSPECTION_PROCESS_FAILED: The isolated project inspection failed.
349
+ */
350
+ var deserializeInspectionFailure = (failure) => {
351
+ const options = failure.options;
352
+ const allowed = failure.family === "configuration" ? [
353
+ "code",
354
+ "operation",
355
+ "adapterId"
356
+ ] : failure.family === "operation" ? [
357
+ "code",
358
+ "operation",
359
+ "adapterId",
360
+ "agentId",
361
+ "limit",
362
+ "limitMaximum",
363
+ "nextAction",
364
+ "observedUsage"
365
+ ] : failure.family === "repository" ? [
366
+ "code",
367
+ "operation",
368
+ "path",
369
+ "retryable",
370
+ "resource"
371
+ ] : [];
372
+ if (Object.keys(options).some((key) => !allowed.includes(key)) || ["adapterId", "agentId"].some((key) => Object.hasOwn(options, key) && typeof options[key] !== "string")) throw createInspectionProcessFailure();
373
+ if ((failure.family === "operation" || failure.family === "configuration") && !isCoreOperation(options["operation"])) throw createInspectionProcessFailure();
374
+ const scope = {
375
+ operation: isCoreOperation(options["operation"]) ? options["operation"] : "create-project-inspection",
376
+ ...typeof options["adapterId"] === "string" ? { adapterId: options["adapterId"] } : {},
377
+ ...typeof options["agentId"] === "string" ? { agentId: options["agentId"] } : {}
378
+ };
379
+ if (failure.family === "path" && Object.keys(options).length === 0) return new RepositoryPathException();
380
+ if (failure.family === "configuration") {
381
+ const code = options["code"];
382
+ if (isCoreConfigurationErrorCode(code)) return new CoreConfigurationException({
383
+ ...scope,
384
+ code
385
+ });
386
+ }
387
+ if (failure.family === "operation") {
388
+ const code = options["code"];
389
+ if (isCoreOperationErrorCode(code) && code !== "RESOURCE_LIMIT_EXCEEDED" && ![
390
+ "limit",
391
+ "limitMaximum",
392
+ "nextAction",
393
+ "observedUsage"
394
+ ].some((key) => Object.hasOwn(options, key))) return new CoreOperationException({
395
+ ...scope,
396
+ code
397
+ });
398
+ if (options["code"] === "RESOURCE_LIMIT_EXCEEDED" && isNumber(options["limitMaximum"]) && options["limitMaximum"] > 0) {
399
+ if (options["limit"] === "maxAnalysisHeapBytes" && options["nextAction"] === "review-inspection-capacity" && options["observedUsage"] === null) return new CoreOperationException({
400
+ ...scope,
401
+ code: "RESOURCE_LIMIT_EXCEEDED",
402
+ limit: "maxAnalysisHeapBytes",
403
+ limitMaximum: options["limitMaximum"],
404
+ observedUsage: null,
405
+ nextAction: "review-inspection-capacity"
406
+ });
407
+ if ((options["limit"] === "maxInspectionMessageBytes" || options["limit"] === "maxReaderRequests") && options["nextAction"] === null && isNumber(options["observedUsage"])) return new CoreOperationException({
408
+ ...scope,
409
+ code: "RESOURCE_LIMIT_EXCEEDED",
410
+ limit: options["limit"],
411
+ limitMaximum: options["limitMaximum"],
412
+ nextAction: null,
413
+ observedUsage: options["observedUsage"]
414
+ });
415
+ if (typeof options["limit"] === "string" && ![
416
+ "maxAnalysisHeapBytes",
417
+ "maxInspectionMessageBytes",
418
+ "maxReaderRequests"
419
+ ].includes(options["limit"]) && options["nextAction"] === "reduce-input-or-increase-limit" && isNumber(options["observedUsage"])) return new CoreOperationException({
420
+ ...scope,
421
+ code: "RESOURCE_LIMIT_EXCEEDED",
422
+ limit: options["limit"],
423
+ limitMaximum: options["limitMaximum"],
424
+ nextAction: "reduce-input-or-increase-limit",
425
+ observedUsage: options["observedUsage"]
426
+ });
427
+ }
428
+ }
429
+ if (failure.family === "repository") {
430
+ const code = REPOSITORY_CODES.find((candidate) => candidate === options["code"]);
431
+ const operation = REPOSITORY_OPERATIONS.find((candidate) => candidate === options["operation"]);
432
+ const resource = options["resource"];
433
+ if (code !== void 0 && operation !== void 0 && typeof options["retryable"] === "boolean" && (options["path"] === null || isRepositoryPath(options["path"])) && (resource === void 0 || resource !== null && typeof resource === "object" && Object.keys(resource).length === 3 && "dimension" in resource && typeof resource.dimension === "string" && "limit" in resource && isNumber(resource.limit) && "observed" in resource && isNumber(resource.observed))) return new RepositorySourceException({
434
+ code,
435
+ operation,
436
+ path: options["path"],
437
+ retryable: options["retryable"],
438
+ ...resource === void 0 ? {} : { resource }
439
+ });
440
+ }
441
+ throw createInspectionProcessFailure();
442
+ };
443
+ //#endregion
444
+ export { encodeInspectionMessage as a, NODE_INSPECTION_PROFILE as c, NODE_INSPECTION_TRANSPORT_BYTES as d, decodeInspectionMessage as i, NODE_INSPECTION_STDIO_BYTES as l, serializeInspectionFailure as n, NODE_INSPECTION_FILE_PAGE_BYTES as o, createInspectionProcessFailure as r, NODE_INSPECTION_LIFETIME_MS as s, deserializeInspectionFailure as t, NODE_INSPECTION_TERMINATION_GRACE_MS as u };
445
+
446
+ //# sourceMappingURL=errors-BQI1DEqf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-BQI1DEqf.js","names":[],"sources":["../../src/node-inspection/constants.ts","../../src/node-inspection/protocol.ts","../../src/node-inspection/errors.ts"],"sourcesContent":["// whole-attempt lifetime and bounded bridge ownership, independent of source file size\nexport const NODE_INSPECTION_LIFETIME_MS = 120_000;\nexport const NODE_INSPECTION_TERMINATION_GRACE_MS = 1_000;\nexport const NODE_INSPECTION_MAX_REQUESTS = 4;\nexport const NODE_INSPECTION_FILE_PAGE_BYTES = 65_536;\nexport const NODE_INSPECTION_MESSAGE_BYTES = 1_048_576;\nexport const NODE_INSPECTION_STDIO_BYTES = 32_768;\n\n// two UTF-16 bytes per serialized byte, two copies at each owner, for every RPC credit\nexport const NODE_INSPECTION_TRANSPORT_BYTES =\n NODE_INSPECTION_MAX_REQUESTS * NODE_INSPECTION_MESSAGE_BYTES * 2 * 2 * 3;\n\n// fixed profile qualified in the constrained CLI and actual-worker lanes\nexport const NODE_INSPECTION_OLD_GENERATION_MIB = 512;\nexport const NODE_INSPECTION_YOUNG_GENERATION_MIB = 24;\n\n// immutable execution identity for consumers that authenticate prepared inspection state\nexport const NODE_INSPECTION_PROFILE = Object.freeze({\n lifetimeMs: NODE_INSPECTION_LIFETIME_MS,\n terminationGraceMs: NODE_INSPECTION_TERMINATION_GRACE_MS,\n maxReaderRequests: NODE_INSPECTION_MAX_REQUESTS,\n maxFilePageBytes: NODE_INSPECTION_FILE_PAGE_BYTES,\n maxMessageBytes: NODE_INSPECTION_MESSAGE_BYTES,\n maxStdioBytes: NODE_INSPECTION_STDIO_BYTES,\n transportBytes: NODE_INSPECTION_TRANSPORT_BYTES,\n oldGenerationMiB: NODE_INSPECTION_OLD_GENERATION_MIB,\n youngGenerationMiB: NODE_INSPECTION_YOUNG_GENERATION_MIB,\n});\n","import { Buffer } from 'node:buffer';\n\nimport { isRepositoryPath } from '@moldea.ai/repository';\n\nimport type { ICoreResourceLimits } from '../contracts/index.js';\nimport { CoreOperationException } from '../exceptions/index.js';\n\nimport { NODE_INSPECTION_FILE_PAGE_BYTES, NODE_INSPECTION_MESSAGE_BYTES } from './constants.js';\nimport type { INodeInspectionMessage } from './types.js';\n\n/** Creates the safe failure for an untrusted or inconsistent private protocol record. */\nexport const createInspectionProcessFailure = (cause?: unknown): CoreOperationException =>\n new CoreOperationException({\n code: 'INSPECTION_PROCESS_FAILED',\n operation: 'create-project-inspection',\n ...(cause === undefined ? {} : { cause }),\n });\n\nconst isRecord = (input: unknown): input is Record<string, unknown> =>\n input !== null && typeof input === 'object' && !Array.isArray(input);\nconst JSON_SHORT_ESCAPES = new Set([8, 9, 10, 12, 13]);\nconst isInteger = (input: unknown): input is number =>\n typeof input === 'number' && Number.isSafeInteger(input) && input >= 0;\nconst hasKeys = (\n input: Record<string, unknown>,\n required: string[],\n optional: string[] = [],\n): boolean =>\n required.every((key) => Object.hasOwn(input, key)) &&\n Object.keys(input).every((key) => required.includes(key) || optional.includes(key));\nconst isSnapshot = (input: unknown): boolean =>\n isRecord(input) &&\n hasKeys(input, ['id', 'sourceKind']) &&\n typeof input['id'] === 'string' &&\n input['id'].length > 0 &&\n typeof input['sourceKind'] === 'string' &&\n input['sourceKind'].length > 0;\nconst isOptionalString = (input: Record<string, unknown>, key: string): boolean =>\n !Object.hasOwn(input, key) || typeof input[key] === 'string';\nconst isRegistryUrl = (input: unknown): boolean => {\n if (typeof input !== 'string') return false;\n try {\n const url = new URL(input);\n return url.protocol === 'file:' && url.search === '' && url.hash === '';\n } catch {\n return false;\n }\n};\nconst isPageInput = (input: unknown): boolean =>\n isRecord(input) &&\n hasKeys(input, ['maxItems', 'view'], ['cursor']) &&\n isInteger(input['maxItems']) &&\n input['maxItems'] > 0 &&\n ['all', 'diagnostics', 'evidence', 'metadata'].includes(String(input['view'])) &&\n isOptionalString(input, 'cursor');\nconst isLimits = (input: unknown): input is ICoreResourceLimits =>\n isRecord(input) &&\n hasKeys(input, [\n 'maxEntries',\n 'maxTotalBytesRead',\n 'maxFileBytes',\n 'maxManifestBytes',\n 'maxRetainedBytes',\n 'maxDiagnostics',\n 'maxEvidence',\n ]) &&\n Object.values(input).every((limit) => isInteger(limit) && limit > 0);\nconst isCounts = (input: unknown): boolean =>\n isRecord(input) &&\n hasKeys(input, [\n 'agents',\n 'context',\n 'decisions',\n 'mirrors',\n 'runtimes',\n 'unresolved',\n 'diagnostics',\n 'errors',\n 'warnings',\n 'evidence',\n 'metadata',\n ]) &&\n Object.values(input).every(isInteger);\nconst isSummary = (input: unknown): boolean =>\n input === null ||\n (isRecord(input) &&\n hasKeys(input, ['counts', 'manifestDigest', 'manifestPath', 'projectDigest', 'projectPath']) &&\n isRecord(input['counts']) &&\n hasKeys(input['counts'], [\n 'agents',\n 'context',\n 'decisions',\n 'mirrors',\n 'runtimes',\n 'unresolved',\n ]) &&\n Object.values(input['counts']).every(isInteger) &&\n typeof input['manifestDigest'] === 'string' &&\n typeof input['projectDigest'] === 'string' &&\n isRepositoryPath(input['manifestPath']) &&\n isRepositoryPath(input['projectPath']));\nconst isInspectionBase = (input: Record<string, unknown>): boolean =>\n isCounts(input['counts']) &&\n typeof input['valid'] === 'boolean' &&\n ['complete', 'incomplete', 'not-run'].includes(String(input['runtimeInspection'])) &&\n (input['formatVersion'] === null || input['formatVersion'] === 1) &&\n typeof input['inspectionDigest'] === 'string' &&\n isSnapshot(input['source']) &&\n isSummary(input['summary']);\nconst INSPECTION_KEYS = [\n 'counts',\n 'valid',\n 'runtimeInspection',\n 'formatVersion',\n 'inspectionDigest',\n 'source',\n 'summary',\n];\nconst isMetadata = (input: unknown): boolean =>\n isRecord(input) &&\n hasKeys(input, [...INSPECTION_KEYS, 'resourceUsage', 'adapters', 'maxAnalysisHeapBytes']) &&\n isInspectionBase(input) &&\n isInteger(input['maxAnalysisHeapBytes']) &&\n input['maxAnalysisHeapBytes'] > 0 &&\n isRecord(input['resourceUsage']) &&\n hasKeys(input['resourceUsage'], [\n 'canonicalBytes',\n 'peakRetainedBytes',\n 'preparedBytes',\n 'retainedBytes',\n 'totalBytesRead',\n ]) &&\n Object.values(input['resourceUsage']).every(isInteger) &&\n Array.isArray(input['adapters']) &&\n input['adapters'].every(\n (adapter: unknown) =>\n isRecord(adapter) &&\n hasKeys(adapter, ['id', 'supportedRepositoryFormatVersions']) &&\n typeof adapter['id'] === 'string' &&\n Array.isArray(adapter['supportedRepositoryFormatVersions']) &&\n adapter['supportedRepositoryFormatVersions'].every(\n (version: unknown) => isInteger(version) && version > 0,\n ),\n );\nconst isPage = (input: unknown): boolean =>\n isRecord(input) &&\n hasKeys(input, [...INSPECTION_KEYS, 'page', 'view']) &&\n isInspectionBase(input) &&\n ['all', 'diagnostics', 'evidence', 'metadata'].includes(String(input['view'])) &&\n isRecord(input['page']) &&\n hasKeys(input['page'], ['isComplete', 'records', 'nextCursor', 'totalItems']) &&\n typeof input['page']['isComplete'] === 'boolean' &&\n isInteger(input['page']['totalItems']) &&\n (input['page']['nextCursor'] === null || typeof input['page']['nextCursor'] === 'string') &&\n Array.isArray(input['page']['records']) &&\n input['page']['records'].every(\n (record: unknown) =>\n isRecord(record) &&\n hasKeys(record, ['item', 'nextCursor']) &&\n (record['nextCursor'] === null || typeof record['nextCursor'] === 'string') &&\n isRecord(record['item']) &&\n typeof record['item']['kind'] === 'string' &&\n ['agent', 'diagnostic', 'evidence', 'metadata'].includes(record['item']['kind']) &&\n hasKeys(record['item'], ['kind', record['item']['kind']]) &&\n isRecord(record['item'][record['item']['kind']]),\n );\nconst isRequest = (input: unknown): boolean => {\n if (!isRecord(input)) return false;\n switch (input['method']) {\n case 'getEntry':\n return hasKeys(input, ['method', 'path']) && isRepositoryPath(input['path']);\n case 'listEntriesPage':\n return (\n hasKeys(input, ['method', 'maxEntries'], ['cursor', 'prefix']) &&\n isInteger(input['maxEntries']) &&\n input['maxEntries'] > 0 &&\n input['maxEntries'] <= 128 &&\n isOptionalString(input, 'cursor') &&\n (!Object.hasOwn(input, 'prefix') || isRepositoryPath(input['prefix']))\n );\n case 'readFilePage':\n return (\n hasKeys(input, ['method', 'path', 'maxBytes', 'offset']) &&\n isRepositoryPath(input['path']) &&\n isInteger(input['offset']) &&\n isInteger(input['maxBytes']) &&\n input['maxBytes'] > 0 &&\n input['maxBytes'] <= NODE_INSPECTION_FILE_PAGE_BYTES\n );\n default:\n return false;\n }\n};\n\n/** Validates closed control envelopes and their typed operation payloads on both bridges. */\nconst isMessage = (input: unknown): input is INodeInspectionMessage => {\n if (\n !isRecord(input) ||\n typeof input['attemptId'] !== 'string' ||\n !/^[a-f0-9]{32}$/.test(input['attemptId'])\n )\n return false;\n const keys = ['attemptId', 'kind'];\n switch (input['kind']) {\n case 'start':\n return (\n hasKeys(input, [...keys, 'registryUrl', 'snapshot', 'limits', 'deadline']) &&\n isRegistryUrl(input['registryUrl']) &&\n isSnapshot(input['snapshot']) &&\n isLimits(input['limits']) &&\n isInteger(input['deadline'])\n );\n case 'ready':\n return (\n hasKeys(input, [...keys, 'maxAnalysisHeapBytes']) &&\n isInteger(input['maxAnalysisHeapBytes']) &&\n input['maxAnalysisHeapBytes'] > 0\n );\n case 'run':\n case 'dispose':\n return hasKeys(input, keys);\n case 'prepared':\n return hasKeys(input, [...keys, 'inspection']) && isMetadata(input['inspection']);\n case 'read-page':\n return (\n hasKeys(input, [...keys, 'requestId', 'input']) &&\n isInteger(input['requestId']) &&\n isPageInput(input['input'])\n );\n case 'page':\n return (\n hasKeys(input, [...keys, 'requestId', 'result']) &&\n isInteger(input['requestId']) &&\n isPage(input['result'])\n );\n case 'reader-request':\n return (\n hasKeys(input, [...keys, 'requestId', 'request']) &&\n isInteger(input['requestId']) &&\n isRequest(input['request'])\n );\n case 'reader-response':\n return hasKeys(input, [...keys, 'requestId', 'result']) && isInteger(input['requestId']);\n case 'failure':\n return (\n hasKeys(input, [...keys, 'failure']) &&\n isRecord(input['failure']) &&\n hasKeys(input['failure'], ['family', 'options']) &&\n ['configuration', 'operation', 'repository', 'path'].includes(\n String(input['failure']['family']),\n ) &&\n isRecord(input['failure']['options'])\n );\n default:\n return false;\n }\n};\n\n/** Counts escaped JSON bytes without first allocating a serialized oversized message. */\nconst countJsonBytes = (input: unknown, ancestors: WeakSet<object>, depth: number): number => {\n if (depth > 64) throw createInspectionProcessFailure();\n if (input === null) return 4;\n if (typeof input === 'boolean') return input ? 4 : 5;\n if (typeof input === 'number' && Number.isFinite(input)) return String(input).length;\n if (typeof input === 'string') {\n let bytes = 2;\n for (let index = 0; index < input.length; index++) {\n const code = input.charCodeAt(index);\n if (code === 34 || code === 92 || JSON_SHORT_ESCAPES.has(code)) bytes += 2;\n else if (code < 32) bytes += 6;\n else if (code < 128) bytes++;\n else if (code < 2048) bytes += 2;\n else if (\n code >= 0xd800 &&\n code <= 0xdbff &&\n index + 1 < input.length &&\n input.charCodeAt(index + 1) >= 0xdc00 &&\n input.charCodeAt(index + 1) <= 0xdfff\n ) {\n bytes += 4;\n index++;\n } else bytes += code >= 0xd800 && code <= 0xdfff ? 6 : 3;\n if (bytes > NODE_INSPECTION_MESSAGE_BYTES) return bytes;\n }\n return bytes;\n }\n if (typeof input !== 'object' || ancestors.has(input)) throw createInspectionProcessFailure();\n ancestors.add(input);\n let bytes = 2;\n let count = 0;\n if (Array.isArray(input)) {\n for (const element of input) {\n bytes += (count++ === 0 ? 0 : 1) + countJsonBytes(element, ancestors, depth + 1);\n if (bytes > NODE_INSPECTION_MESSAGE_BYTES) break;\n }\n } else {\n for (const key in input) {\n if (!Object.hasOwn(input, key)) continue;\n bytes +=\n (count++ === 0 ? 0 : 1) +\n countJsonBytes(key, ancestors, depth + 1) +\n 1 +\n countJsonBytes((input as Record<string, unknown>)[key], ancestors, depth + 1);\n if (bytes > NODE_INSPECTION_MESSAGE_BYTES) break;\n }\n }\n ancestors.delete(input);\n return bytes;\n};\n\n/**\n * Admits a complete bounded record before serialization; no record is truncated.\n * @returns One private JSON frame.\n * @throws\n * - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.\n * - INSPECTION_PROCESS_FAILED: The isolated project inspection failed.\n */\nexport const encodeInspectionMessage = (message: INodeInspectionMessage): string => {\n const bytes = countJsonBytes(message, new WeakSet(), 0);\n if (bytes > NODE_INSPECTION_MESSAGE_BYTES)\n throw new CoreOperationException({\n code: 'RESOURCE_LIMIT_EXCEEDED',\n limit: 'maxInspectionMessageBytes',\n limitMaximum: NODE_INSPECTION_MESSAGE_BYTES,\n observedUsage: bytes,\n nextAction: null,\n operation: 'create-project-inspection',\n });\n if (!isMessage(message)) throw createInspectionProcessFailure();\n return JSON.stringify(message);\n};\n\n/**\n * Checks frame size before parsing and validates the closed message contract.\n * @returns A validated private message.\n * @throws\n * - INSPECTION_PROCESS_FAILED: The isolated project inspection failed.\n */\nexport const decodeInspectionMessage = (frame: unknown): INodeInspectionMessage => {\n if (typeof frame !== 'string' || Buffer.byteLength(frame) > NODE_INSPECTION_MESSAGE_BYTES)\n throw createInspectionProcessFailure();\n let message: unknown;\n try {\n message = JSON.parse(frame);\n } catch (cause) {\n throw createInspectionProcessFailure(cause);\n }\n if (!isMessage(message)) throw createInspectionProcessFailure();\n return message;\n};\n","import {\n RepositoryPathException,\n RepositorySourceException,\n isRepositoryPath,\n type IRepositoryOperation,\n type IRepositorySourceErrorCode,\n} from '@moldea.ai/repository';\n\nimport {\n CoreConfigurationException,\n CoreOperationException,\n isCoreConfigurationErrorCode,\n isCoreOperation,\n isCoreOperationErrorCode,\n} from '../exceptions/index.js';\n\nimport { createInspectionProcessFailure } from './protocol.js';\nimport type { INodeInspectionFailure } from './types.js';\n\n/** Serializes only documented exception fields, excluding native messages, causes and stacks. */\nexport const serializeInspectionFailure = (error: unknown): INodeInspectionFailure => {\n if (error instanceof CoreConfigurationException)\n return {\n family: 'configuration',\n options: {\n code: error.code,\n operation: error.operation,\n ...(error.adapterId === null ? {} : { adapterId: error.adapterId }),\n },\n };\n if (error instanceof CoreOperationException)\n return {\n family: 'operation',\n options: {\n code: error.code,\n operation: error.operation,\n ...(error.adapterId === null ? {} : { adapterId: error.adapterId }),\n ...(error.agentId === null ? {} : { agentId: error.agentId }),\n ...(error.code !== 'RESOURCE_LIMIT_EXCEEDED'\n ? {}\n : {\n limit: error.limit,\n limitMaximum: error.limitMaximum,\n nextAction: error.nextAction,\n observedUsage: error.observedUsage,\n }),\n },\n };\n if (error instanceof RepositoryPathException) return { family: 'path', options: {} };\n if (error instanceof RepositorySourceException)\n return {\n family: 'repository',\n options: {\n code: error.code,\n operation: error.operation,\n path: error.path,\n retryable: error.retryable,\n ...(error.resource === null ? {} : { resource: error.resource }),\n },\n };\n return {\n family: 'operation',\n options: {\n code: 'INSPECTION_PROCESS_FAILED',\n operation: 'create-project-inspection',\n },\n };\n};\nconst REPOSITORY_CODES: IRepositorySourceErrorCode[] = [\n 'ENTRY_NOT_FOUND',\n 'ENTRY_NOT_FILE',\n 'ENTRY_NOT_DIRECTORY',\n 'INVALID_PAGE_REQUEST',\n 'ACCESS_DENIED',\n 'SOURCE_UNAVAILABLE',\n 'SNAPSHOT_CHANGED',\n 'PROVIDER_INCOMPLETE',\n 'INVALID_SOURCE_DATA',\n 'RESOURCE_LIMIT_EXCEEDED',\n 'ABORTED',\n];\nconst REPOSITORY_OPERATIONS: IRepositoryOperation[] = [\n 'create-reader',\n 'create-comparison',\n 'get-entry',\n 'read-file-page',\n 'list-entries-page',\n 'list-changes-page',\n];\nconst isNumber = (input: unknown): input is number =>\n typeof input === 'number' && Number.isSafeInteger(input) && input >= 0;\n\n/**\n * Reconstructs a documented typed failure after checking its safe transport fields.\n * @returns A package exception without a remote native cause or stack.\n * @throws\n * - INSPECTION_PROCESS_FAILED: The isolated project inspection failed.\n */\nexport const deserializeInspectionFailure = (failure: INodeInspectionFailure): Error => {\n const options = failure.options;\n const allowed =\n failure.family === 'configuration'\n ? ['code', 'operation', 'adapterId']\n : failure.family === 'operation'\n ? [\n 'code',\n 'operation',\n 'adapterId',\n 'agentId',\n 'limit',\n 'limitMaximum',\n 'nextAction',\n 'observedUsage',\n ]\n : failure.family === 'repository'\n ? ['code', 'operation', 'path', 'retryable', 'resource']\n : [];\n if (\n Object.keys(options).some((key) => !allowed.includes(key)) ||\n ['adapterId', 'agentId'].some(\n (key) => Object.hasOwn(options, key) && typeof options[key] !== 'string',\n )\n )\n throw createInspectionProcessFailure();\n if (\n (failure.family === 'operation' || failure.family === 'configuration') &&\n !isCoreOperation(options['operation'])\n )\n throw createInspectionProcessFailure();\n const scope = {\n operation: isCoreOperation(options['operation'])\n ? options['operation']\n : ('create-project-inspection' as const),\n ...(typeof options['adapterId'] === 'string' ? { adapterId: options['adapterId'] } : {}),\n ...(typeof options['agentId'] === 'string' ? { agentId: options['agentId'] } : {}),\n };\n if (failure.family === 'path' && Object.keys(options).length === 0)\n return new RepositoryPathException();\n if (failure.family === 'configuration') {\n const code = options['code'];\n if (isCoreConfigurationErrorCode(code))\n return new CoreConfigurationException({ ...scope, code });\n }\n if (failure.family === 'operation') {\n const code = options['code'];\n if (\n isCoreOperationErrorCode(code) &&\n code !== 'RESOURCE_LIMIT_EXCEEDED' &&\n !['limit', 'limitMaximum', 'nextAction', 'observedUsage'].some((key) =>\n Object.hasOwn(options, key),\n )\n )\n return new CoreOperationException({ ...scope, code });\n if (\n options['code'] === 'RESOURCE_LIMIT_EXCEEDED' &&\n isNumber(options['limitMaximum']) &&\n options['limitMaximum'] > 0\n ) {\n if (\n options['limit'] === 'maxAnalysisHeapBytes' &&\n options['nextAction'] === 'review-inspection-capacity' &&\n options['observedUsage'] === null\n )\n return new CoreOperationException({\n ...scope,\n code: 'RESOURCE_LIMIT_EXCEEDED',\n limit: 'maxAnalysisHeapBytes',\n limitMaximum: options['limitMaximum'],\n observedUsage: null,\n nextAction: 'review-inspection-capacity',\n });\n if (\n (options['limit'] === 'maxInspectionMessageBytes' ||\n options['limit'] === 'maxReaderRequests') &&\n options['nextAction'] === null &&\n isNumber(options['observedUsage'])\n )\n return new CoreOperationException({\n ...scope,\n code: 'RESOURCE_LIMIT_EXCEEDED',\n limit: options['limit'],\n limitMaximum: options['limitMaximum'],\n nextAction: null,\n observedUsage: options['observedUsage'],\n });\n if (\n typeof options['limit'] === 'string' &&\n !['maxAnalysisHeapBytes', 'maxInspectionMessageBytes', 'maxReaderRequests'].includes(\n options['limit'],\n ) &&\n options['nextAction'] === 'reduce-input-or-increase-limit' &&\n isNumber(options['observedUsage'])\n )\n return new CoreOperationException({\n ...scope,\n code: 'RESOURCE_LIMIT_EXCEEDED',\n limit: options['limit'],\n limitMaximum: options['limitMaximum'],\n nextAction: 'reduce-input-or-increase-limit',\n observedUsage: options['observedUsage'],\n });\n }\n }\n if (failure.family === 'repository') {\n const code = REPOSITORY_CODES.find((candidate) => candidate === options['code']);\n const operation = REPOSITORY_OPERATIONS.find((candidate) => candidate === options['operation']);\n const resource = options['resource'];\n if (\n code !== undefined &&\n operation !== undefined &&\n typeof options['retryable'] === 'boolean' &&\n (options['path'] === null || isRepositoryPath(options['path'])) &&\n (resource === undefined ||\n (resource !== null &&\n typeof resource === 'object' &&\n Object.keys(resource).length === 3 &&\n 'dimension' in resource &&\n typeof resource.dimension === 'string' &&\n 'limit' in resource &&\n isNumber(resource.limit) &&\n 'observed' in resource &&\n isNumber(resource.observed)))\n ) {\n return new RepositorySourceException({\n code,\n operation,\n path: options['path'],\n retryable: options['retryable'],\n ...(resource === undefined\n ? {}\n : {\n resource: resource as {\n dimension: string;\n limit: number;\n observed: number;\n },\n }),\n });\n }\n }\n throw createInspectionProcessFailure();\n};\n"],"mappings":";;;;AACA,IAAa,8BAA8B;AAC3C,IAAa,uCAAuC;AAEpD,IAAa,kCAAkC;AAC/C,IAAa,gCAAgC;AAC7C,IAAa,8BAA8B;AAG3C,IAAa,kCAAA,IACoB,gCAAgC,IAAI,IAAI;AAOzE,IAAa,0BAA0B,OAAO,OAAO;CACnD,YAAY;CACZ,oBAAoB;CACpB,mBAAA;CACA,kBAAkB;CAClB,iBAAiB;CACjB,eAAe;CACf,gBAAgB;CAChB,kBAAA;CACA,oBAAA;AACF,CAAC;;;;AChBD,IAAa,kCAAkC,UAC7C,IAAI,uBAAuB;CACzB,MAAM;CACN,WAAW;CACX,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM;AACzC,CAAC;AAEH,IAAM,YAAY,UAChB,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AACrE,IAAM,qCAAqB,IAAI,IAAI;CAAC;CAAG;CAAG;CAAI;CAAI;AAAE,CAAC;AACrD,IAAM,aAAa,UACjB,OAAO,UAAU,YAAY,OAAO,cAAc,KAAK,KAAK,SAAS;AACvE,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0BAA0B;GACnC;GACA;GACA,MAAM,QAAQ;GACd,WAAW,QAAQ;GACnB,GAAI,aAAa,KAAA,IACb,CAAC,IACD,EACY,SAKZ;EACN,CAAC;CAEL;CACA,MAAM,+BAA+B;AACvC"}
@@ -1,18 +1,17 @@
1
1
  import { Exception } from "error-message-utils";
2
- //#region src/adapter-retained-memory/index.ts
3
- var retainedByteReservations = /* @__PURE__ */ new WeakMap();
4
- /** Registers the retained-memory reservation owned by one inspection session. */
5
- var registerRuntimeAdapterRetainedByteReservation = (repository, reserve) => {
6
- if (retainedByteReservations.has(repository)) throw new TypeError("The runtime adapter repository is already registered.");
7
- retainedByteReservations.set(repository, reserve);
8
- };
9
- /** Reserves a complete adapter-owned buffer when Core owns the repository session. */
10
- var reserveRuntimeAdapterRetainedBytesIfTracked = (repository, byteLength) => {
11
- const reserve = retainedByteReservations.get(repository);
12
- if (reserve !== void 0) reserve(byteLength);
13
- };
14
- //#endregion
15
2
  //#region src/exceptions/index.ts
3
+ var CORE_OPERATIONS = [
4
+ "create-core",
5
+ "normalize-text",
6
+ "calculate-content-digest",
7
+ "parse-manifest",
8
+ "match-manifest-scope",
9
+ "parse-decision",
10
+ "create-project-inspection",
11
+ "read-canonical-content-page",
12
+ "validate-project",
13
+ "validate-adapter"
14
+ ];
16
15
  var CONFIGURATION_ERROR_MESSAGES = {
17
16
  DUPLICATE_ADAPTER_ID: "A runtime adapter ID is registered more than once.",
18
17
  INVALID_ADAPTER_DEFINITION: "A runtime adapter definition is invalid.",
@@ -24,6 +23,9 @@ var OPERATION_ERROR_MESSAGES = {
24
23
  ADAPTER_EXECUTION_FAILED: "A runtime adapter failed during inspection.",
25
24
  CONTENT_INVALID: "The canonical content is not valid UTF-8 text.",
26
25
  INVALID_ARGUMENT: "The Core operation received an invalid argument.",
26
+ INSPECTION_BUSY: "Project inspection capacity is busy. Try again shortly.",
27
+ INSPECTION_TIMEOUT: "The isolated project inspection timed out.",
28
+ INSPECTION_PROCESS_FAILED: "The isolated project inspection failed.",
27
29
  RESOURCE_LIMIT_EXCEEDED: "A Core resource limit was exceeded."
28
30
  };
29
31
  var OPERATION_ERROR_RETRYABILITY = {
@@ -31,8 +33,17 @@ var OPERATION_ERROR_RETRYABILITY = {
31
33
  ADAPTER_EXECUTION_FAILED: false,
32
34
  CONTENT_INVALID: false,
33
35
  INVALID_ARGUMENT: false,
36
+ INSPECTION_BUSY: true,
37
+ INSPECTION_TIMEOUT: true,
38
+ INSPECTION_PROCESS_FAILED: false,
34
39
  RESOURCE_LIMIT_EXCEEDED: false
35
40
  };
41
+ /** Checks a transported operation against the authoritative Core operation set. */
42
+ var isCoreOperation = (input) => CORE_OPERATIONS.some((operation) => operation === input);
43
+ /** Checks a transported configuration code against the authoritative message registry. */
44
+ var isCoreConfigurationErrorCode = (input) => typeof input === "string" && Object.hasOwn(CONFIGURATION_ERROR_MESSAGES, input);
45
+ /** Checks a transported operation code against the authoritative message registry. */
46
+ var isCoreOperationErrorCode = (input) => typeof input === "string" && Object.hasOwn(OPERATION_ERROR_MESSAGES, input);
36
47
  var attachCause = (exception, cause) => {
37
48
  if (cause === void 0) return;
38
49
  Object.defineProperty(exception, "cause", {
@@ -85,6 +96,6 @@ var CoreOperationException = class extends Exception {
85
96
  }
86
97
  };
87
98
  //#endregion
88
- export { reserveRuntimeAdapterRetainedBytesIfTracked as i, CoreOperationException as n, registerRuntimeAdapterRetainedByteReservation as r, CoreConfigurationException as t };
99
+ export { isCoreOperationErrorCode as a, isCoreOperation as i, CoreOperationException as n, isCoreConfigurationErrorCode as r, CoreConfigurationException as t };
89
100
 
90
- //# sourceMappingURL=exceptions-HS9ofVy2.js.map
101
+ //# sourceMappingURL=exceptions-lzD3buFw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions-lzD3buFw.js","names":[],"sources":["../../src/exceptions/index.ts"],"sourcesContent":["import { Exception } from 'error-message-utils';\n\n// stable configuration and operation failure codes\nexport type ICoreConfigurationErrorCode =\n | 'DUPLICATE_ADAPTER_ID'\n | 'RESERVED_ADAPTER_ID'\n | 'INVALID_ADAPTER_DEFINITION'\n | 'INVALID_RESOURCE_LIMIT';\n\nexport type ICoreOperationErrorCode =\n | 'INVALID_ARGUMENT'\n | 'ABORTED'\n | 'RESOURCE_LIMIT_EXCEEDED'\n | 'ADAPTER_EXECUTION_FAILED'\n | 'INSPECTION_BUSY'\n | 'INSPECTION_TIMEOUT'\n | 'INSPECTION_PROCESS_FAILED'\n | 'CONTENT_INVALID';\n\nconst CORE_OPERATIONS = [\n 'create-core',\n 'normalize-text',\n 'calculate-content-digest',\n 'parse-manifest',\n 'match-manifest-scope',\n 'parse-decision',\n 'create-project-inspection',\n 'read-canonical-content-page',\n 'validate-project',\n 'validate-adapter',\n] as const;\n\nexport type ICoreOperation = (typeof CORE_OPERATIONS)[number];\n\n// safe construction options for exported Core exceptions\nexport interface ICoreConfigurationExceptionOptions {\n readonly code: ICoreConfigurationErrorCode;\n readonly operation: ICoreOperation;\n readonly adapterId?: string;\n readonly cause?: unknown;\n}\n\ninterface ICoreOperationExceptionOptionsBase {\n readonly operation: ICoreOperation;\n readonly adapterId?: string;\n readonly agentId?: string;\n readonly cause?: unknown;\n}\n\n// logical budget refusals and verified isolated-worker heap exhaustion\nexport type ICoreResourceLimitNextAction =\n 'reduce-input-or-increase-limit' | 'review-inspection-capacity';\n\nexport type ICoreOperationExceptionOptions = ICoreOperationExceptionOptionsBase &\n (\n | {\n readonly code: 'RESOURCE_LIMIT_EXCEEDED';\n readonly limit: string;\n readonly limitMaximum: number;\n readonly nextAction: 'reduce-input-or-increase-limit';\n readonly observedUsage: number;\n }\n | {\n readonly code: 'RESOURCE_LIMIT_EXCEEDED';\n readonly limit: 'maxAnalysisHeapBytes';\n readonly limitMaximum: number;\n readonly nextAction: 'review-inspection-capacity';\n readonly observedUsage: null;\n }\n | {\n readonly code: 'RESOURCE_LIMIT_EXCEEDED';\n readonly limit: 'maxInspectionMessageBytes' | 'maxReaderRequests';\n readonly limitMaximum: number;\n readonly nextAction: null;\n readonly observedUsage: number;\n }\n | {\n readonly code: Exclude<ICoreOperationErrorCode, 'RESOURCE_LIMIT_EXCEEDED'>;\n readonly limit?: never;\n readonly limitMaximum?: never;\n readonly nextAction?: never;\n readonly observedUsage?: never;\n }\n );\n\nconst CONFIGURATION_ERROR_MESSAGES = {\n DUPLICATE_ADAPTER_ID: 'A runtime adapter ID is registered more than once.',\n INVALID_ADAPTER_DEFINITION: 'A runtime adapter definition is invalid.',\n INVALID_RESOURCE_LIMIT: 'A Core resource limit is invalid.',\n RESERVED_ADAPTER_ID: 'A reserved runtime adapter ID was supplied.',\n} as const satisfies Readonly<Record<ICoreConfigurationErrorCode, string>>;\n\nconst OPERATION_ERROR_MESSAGES = {\n ABORTED: 'The Core operation was aborted.',\n ADAPTER_EXECUTION_FAILED: 'A runtime adapter failed during inspection.',\n CONTENT_INVALID: 'The canonical content is not valid UTF-8 text.',\n INVALID_ARGUMENT: 'The Core operation received an invalid argument.',\n INSPECTION_BUSY: 'Project inspection capacity is busy. Try again shortly.',\n INSPECTION_TIMEOUT: 'The isolated project inspection timed out.',\n INSPECTION_PROCESS_FAILED: 'The isolated project inspection failed.',\n RESOURCE_LIMIT_EXCEEDED: 'A Core resource limit was exceeded.',\n} as const satisfies Readonly<Record<ICoreOperationErrorCode, string>>;\n\nconst OPERATION_ERROR_RETRYABILITY = {\n ABORTED: true,\n ADAPTER_EXECUTION_FAILED: false,\n CONTENT_INVALID: false,\n INVALID_ARGUMENT: false,\n INSPECTION_BUSY: true,\n INSPECTION_TIMEOUT: true,\n INSPECTION_PROCESS_FAILED: false,\n RESOURCE_LIMIT_EXCEEDED: false,\n} as const satisfies Readonly<Record<ICoreOperationErrorCode, boolean>>;\n\n/** Checks a transported operation against the authoritative Core operation set. */\nexport const isCoreOperation = (input: unknown): input is ICoreOperation =>\n CORE_OPERATIONS.some((operation) => operation === input);\n\n/** Checks a transported configuration code against the authoritative message registry. */\nexport const isCoreConfigurationErrorCode = (\n input: unknown,\n): input is ICoreConfigurationErrorCode =>\n typeof input === 'string' && Object.hasOwn(CONFIGURATION_ERROR_MESSAGES, input);\n\n/** Checks a transported operation code against the authoritative message registry. */\nexport const isCoreOperationErrorCode = (input: unknown): input is ICoreOperationErrorCode =>\n typeof input === 'string' && Object.hasOwn(OPERATION_ERROR_MESSAGES, input);\n\nconst attachCause = (exception: Error, cause: unknown): void => {\n if (cause === undefined) {\n return;\n }\n\n Object.defineProperty(exception, 'cause', {\n configurable: true,\n enumerable: false,\n value: cause,\n writable: false,\n });\n};\n\n/** Represents invalid immutable Core configuration. */\nexport class CoreConfigurationException extends Exception {\n public override readonly code: ICoreConfigurationErrorCode;\n\n public readonly operation: ICoreOperation;\n\n public readonly adapterId: string | null;\n\n /** Creates a configuration exception with safe adapter metadata. */\n public constructor(options: ICoreConfigurationExceptionOptions) {\n super(CONFIGURATION_ERROR_MESSAGES[options.code], options.code);\n this.code = options.code;\n this.name = 'CoreConfigurationException';\n this.operation = options.operation;\n this.adapterId = options.adapterId ?? null;\n attachCause(this, options.cause);\n }\n}\n\n/** Represents an operational failure that prevented Core from completing. */\nexport class CoreOperationException extends Exception {\n public override readonly code: ICoreOperationErrorCode;\n\n public readonly operation: ICoreOperation;\n\n public readonly retryable: boolean;\n\n public readonly adapterId: string | null;\n\n public readonly agentId: string | null;\n\n public readonly limit: string | null;\n\n public readonly limitMaximum: number | null;\n\n public readonly nextAction: ICoreResourceLimitNextAction | null;\n\n public readonly observedUsage: number | null;\n\n /** Creates an operation exception with derived retry and safe scope metadata. */\n public constructor(options: ICoreOperationExceptionOptions) {\n super(OPERATION_ERROR_MESSAGES[options.code], options.code);\n this.code = options.code;\n this.name = 'CoreOperationException';\n this.operation = options.operation;\n this.retryable = OPERATION_ERROR_RETRYABILITY[options.code];\n this.adapterId = options.adapterId ?? null;\n this.agentId = options.agentId ?? null;\n this.limit = options.limit ?? null;\n this.limitMaximum = options.limitMaximum ?? null;\n this.nextAction = options.nextAction ?? null;\n this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