@moldea.ai/core 4.0.0 → 4.0.1
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/README.md +2 -2
- package/dist/adapter-repository/index.d.ts +19 -1
- package/dist/adapter-repository/index.d.ts.map +1 -1
- package/dist/adapter-retained-memory/index.d.ts +8 -0
- package/dist/adapter-retained-memory/index.d.ts.map +1 -0
- package/dist/adapter.js +21 -2
- package/dist/adapter.js.map +1 -1
- package/dist/chunks/{exceptions-C_KfCIjE.js → exceptions-HS9ofVy2.js} +15 -2
- package/dist/chunks/exceptions-HS9ofVy2.js.map +1 -0
- package/dist/index.js +115 -89
- package/dist/index.js.map +1 -1
- package/dist/project-agent-assignments/index.d.ts +2 -2
- package/dist/project-agent-assignments/index.d.ts.map +1 -1
- package/dist/project-inspection/index.d.ts.map +1 -1
- package/dist/project-metadata/index.d.ts +2 -2
- package/dist/project-metadata/index.d.ts.map +1 -1
- package/dist/repository-inspection-session/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/exceptions-C_KfCIjE.js.map +0 -1
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ const result = await core.validateProject({ repository });
|
|
|
69
69
|
|
|
70
70
|
`createProjectInspection` validates the snapshot once, prepares one immutable content-free record set, and returns synchronous bounded page reads for the `metadata`, `diagnostics`, `evidence`, and `all` views. The `metadata` and `all` views include one independently keyed `agent` record per canonical agent with exactly its `agentId` and manifest-declared `runtimeId`, distinct from asset metadata and adapter evidence. Each page uses a semantic continuation cursor tied to the complete inspection digest and view. Page reads perform no repository access, revalidation, sorting, digesting, or adapter execution.
|
|
71
71
|
|
|
72
|
-
The prepared inspection retains only its content-free records, summary, source identity, deterministic resource accounting, and page indexes. It does not retain canonical document bodies. `readCanonicalContentPage` is the only Core project operation that returns a body, and it requires an explicit canonical `/moldea/**` file path, byte offset, and byte bound. Returned chunks end at a complete UTF-8 scalar.
|
|
72
|
+
The prepared inspection retains only its content-free records, summary, source identity, deterministic resource accounting, and page indexes. Core preflights the complete logical cost before it constructs the prepared collections, indexes, or digest. It does not retain canonical document bodies. `readCanonicalContentPage` is the only Core project operation that returns a body, and it requires an explicit canonical `/moldea/**` file path, byte offset, and byte bound. Returned chunks end at a complete UTF-8 scalar.
|
|
73
73
|
|
|
74
74
|
## Per-agent runtime adapters
|
|
75
75
|
|
|
@@ -79,7 +79,7 @@ Adapter evidence and diagnostics are validated, normalized, deduplicated, sorted
|
|
|
79
79
|
|
|
80
80
|
## Resource and trust boundaries
|
|
81
81
|
|
|
82
|
-
Core uses independent limits for distinct entries, total bytes read, per-file bytes, manifest bytes, logical retained bytes, diagnostics, and evidence. The default logical retained-memory ceiling is 512 MiB. Project inspection accounts for canonical validation state, transient read pages, and prepared content-free records before completing, and reports deterministic logical usage without exposing document bodies. The adapter-facing repository adds per-page entry and byte limits. Core executes no repository code, follows no symlink, receives no host path or source credential, and returns logical paths only.
|
|
82
|
+
Core uses independent limits for distinct entries, total bytes read, per-file bytes, manifest bytes, logical retained bytes, diagnostics, and evidence. The default logical retained-memory ceiling is 512 MiB. Project inspection accounts for canonical validation state, complete adapter file buffers, transient read pages, and prepared content-free records before completing, and reports deterministic logical usage without exposing document bodies. A complete adapter buffer is reserved before allocation and remains charged for the inspection lifetime. The adapter-facing repository adds per-page entry and byte limits. Core executes no repository code, follows no symlink, receives no host path or source credential, and returns logical paths only.
|
|
83
83
|
|
|
84
84
|
Every `RESOURCE_LIMIT_EXCEEDED` exception identifies the exceeded limit, its configured maximum, the observed or projected usage, and the stable `reduce-input-or-increase-limit` next action. Core refuses the operation before allocating retained state beyond the applicable ceiling.
|
|
85
85
|
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { type IRepositoryEntry, type IRepositoryOperationOptions, type IRepositoryPath } from '@moldea.ai/repository';
|
|
2
2
|
import type { IRuntimeAdapterRepository } from '../adapter/index.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Reads one complete adapter source file through bounded repository pages.
|
|
5
|
+
* @param repository The Core-created repository for the current adapter invocation.
|
|
6
|
+
* @param path The exact source file path.
|
|
7
|
+
* @param options Optional cancellation controls.
|
|
8
|
+
* @returns A promise resolving to one detached complete source buffer.
|
|
9
|
+
* @throws
|
|
10
|
+
* - INVALID_REPOSITORY_PATH: The repository path is invalid.
|
|
11
|
+
* - ENTRY_NOT_FOUND: The requested repository entry was not found.
|
|
12
|
+
* - ENTRY_NOT_FILE: The requested repository entry is not a file.
|
|
13
|
+
* - INVALID_PAGE_REQUEST: The repository page request is invalid.
|
|
14
|
+
* - ACCESS_DENIED: Access to the repository source was denied.
|
|
15
|
+
* - SOURCE_UNAVAILABLE: The repository source is unavailable.
|
|
16
|
+
* - SNAPSHOT_CHANGED: The repository snapshot changed during the operation.
|
|
17
|
+
* - INVALID_SOURCE_DATA: The repository source returned invalid data.
|
|
18
|
+
* - RESOURCE_LIMIT_EXCEEDED: A named repository resource limit was exceeded.
|
|
19
|
+
* - ABORTED: The repository operation was aborted.
|
|
20
|
+
* - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.
|
|
21
|
+
*/
|
|
4
22
|
export declare const readRuntimeAdapterFile: (repository: IRuntimeAdapterRepository, path: IRepositoryPath, options?: IRepositoryOperationOptions) => Promise<Uint8Array>;
|
|
5
23
|
/** Iterates one adapter-scoped descendant listing through bounded pages. */
|
|
6
24
|
export declare const iterateRuntimeAdapterEntries: (repository: IRuntimeAdapterRepository, options?: IRepositoryOperationOptions & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter-repository/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter-repository/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AA+BrE;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,sBAAsB,GACjC,YAAY,yBAAyB,EACrC,MAAM,eAAe,EACrB,UAAU,2BAA2B,KACpC,OAAO,CAAC,UAAU,CAyEpB,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,4BAA4B,GACvC,YAAY,yBAAyB,EACrC,UAAU,2BAA2B,GAAG;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAA;CAAE,KAC5E,aAAa,CAAC,gBAAgB,CA6DhC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IRuntimeAdapterRepository } from '../adapter/index.js';
|
|
2
|
+
type IRetainedByteReservation = (byteLength: number) => void;
|
|
3
|
+
/** Registers the retained-memory reservation owned by one inspection session. */
|
|
4
|
+
export declare const registerRuntimeAdapterRetainedByteReservation: (repository: IRuntimeAdapterRepository, reserve: IRetainedByteReservation) => void;
|
|
5
|
+
/** Reserves a complete adapter-owned buffer when Core owns the repository session. */
|
|
6
|
+
export declare const reserveRuntimeAdapterRetainedBytesIfTracked: (repository: IRuntimeAdapterRepository, byteLength: number) => void;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter-retained-memory/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,KAAK,wBAAwB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;AAK7D,iFAAiF;AACjF,eAAO,MAAM,6CAA6C,GACxD,YAAY,yBAAyB,EACrC,SAAS,wBAAwB,KAChC,IAMF,CAAC;AAEF,sFAAsF;AACtF,eAAO,MAAM,2CAA2C,GACtD,YAAY,yBAAyB,EACrC,YAAY,MAAM,KACjB,IAMF,CAAC"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as CoreOperationException } from "./chunks/exceptions-
|
|
1
|
+
import { i as reserveRuntimeAdapterRetainedBytesIfTracked, n as CoreOperationException } from "./chunks/exceptions-HS9ofVy2.js";
|
|
2
2
|
import { REPOSITORY_ROOT, RepositorySourceException, compareRepositoryPaths, parseRepositoryPath } from "@moldea.ai/repository";
|
|
3
3
|
//#region src/adapter-repository/index.ts
|
|
4
4
|
var invalidSourceData = (operation, path) => {
|
|
@@ -19,7 +19,25 @@ var throwResourceLimitExceeded = (limit, limitMaximum, observedUsage) => {
|
|
|
19
19
|
operation: "validate-project"
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Reads one complete adapter source file through bounded repository pages.
|
|
24
|
+
* @param repository The Core-created repository for the current adapter invocation.
|
|
25
|
+
* @param path The exact source file path.
|
|
26
|
+
* @param options Optional cancellation controls.
|
|
27
|
+
* @returns A promise resolving to one detached complete source buffer.
|
|
28
|
+
* @throws
|
|
29
|
+
* - INVALID_REPOSITORY_PATH: The repository path is invalid.
|
|
30
|
+
* - ENTRY_NOT_FOUND: The requested repository entry was not found.
|
|
31
|
+
* - ENTRY_NOT_FILE: The requested repository entry is not a file.
|
|
32
|
+
* - INVALID_PAGE_REQUEST: The repository page request is invalid.
|
|
33
|
+
* - ACCESS_DENIED: Access to the repository source was denied.
|
|
34
|
+
* - SOURCE_UNAVAILABLE: The repository source is unavailable.
|
|
35
|
+
* - SNAPSHOT_CHANGED: The repository snapshot changed during the operation.
|
|
36
|
+
* - INVALID_SOURCE_DATA: The repository source returned invalid data.
|
|
37
|
+
* - RESOURCE_LIMIT_EXCEEDED: A named repository resource limit was exceeded.
|
|
38
|
+
* - ABORTED: The repository operation was aborted.
|
|
39
|
+
* - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.
|
|
40
|
+
*/
|
|
23
41
|
var readRuntimeAdapterFile = async (repository, path, options) => {
|
|
24
42
|
const parsedPath = parseRepositoryPath(path);
|
|
25
43
|
const entry = await repository.getEntry(parsedPath, options);
|
|
@@ -36,6 +54,7 @@ var readRuntimeAdapterFile = async (repository, path, options) => {
|
|
|
36
54
|
retryable: false
|
|
37
55
|
});
|
|
38
56
|
if (entry.byteLength > repository.limits.maxFileBytes) return throwResourceLimitExceeded("maxFileBytes", repository.limits.maxFileBytes, entry.byteLength);
|
|
57
|
+
reserveRuntimeAdapterRetainedBytesIfTracked(repository, entry.byteLength);
|
|
39
58
|
const content = new Uint8Array(entry.byteLength);
|
|
40
59
|
let offset = 0;
|
|
41
60
|
let isFirstPage = true;
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","names":[],"sources":["../src/adapter-repository/index.ts"],"sourcesContent":["import {\n REPOSITORY_ROOT,\n RepositorySourceException,\n compareRepositoryPaths,\n parseRepositoryPath,\n type IRepositoryEntry,\n type IRepositoryOperationOptions,\n type IRepositoryPath,\n} from '@moldea.ai/repository';\n\nimport type { IRuntimeAdapterRepository } from '../adapter/index.js';\nimport { CoreOperationException } from '../exceptions/index.js';\n\nconst invalidSourceData = (\n operation: 'list-entries-page' | 'read-file-page',\n path: IRepositoryPath,\n): never => {\n throw new RepositorySourceException({\n code: 'INVALID_SOURCE_DATA',\n operation,\n path,\n retryable: false,\n });\n};\n\nconst throwResourceLimitExceeded = (\n limit: 'maxEntries' | 'maxFileBytes' | 'maxTotalBytesRead',\n limitMaximum: number,\n observedUsage: number,\n): never => {\n throw new CoreOperationException({\n code: 'RESOURCE_LIMIT_EXCEEDED',\n limit,\n limitMaximum,\n nextAction: 'reduce-input-or-increase-limit',\n observedUsage,\n operation: 'validate-project',\n });\n};\n\n
|
|
1
|
+
{"version":3,"file":"adapter.js","names":[],"sources":["../src/adapter-repository/index.ts"],"sourcesContent":["import {\n REPOSITORY_ROOT,\n RepositorySourceException,\n compareRepositoryPaths,\n parseRepositoryPath,\n type IRepositoryEntry,\n type IRepositoryOperationOptions,\n type IRepositoryPath,\n} from '@moldea.ai/repository';\n\nimport type { IRuntimeAdapterRepository } from '../adapter/index.js';\nimport { reserveRuntimeAdapterRetainedBytesIfTracked } from '../adapter-retained-memory/index.js';\nimport { CoreOperationException } from '../exceptions/index.js';\n\nconst invalidSourceData = (\n operation: 'list-entries-page' | 'read-file-page',\n path: IRepositoryPath,\n): never => {\n throw new RepositorySourceException({\n code: 'INVALID_SOURCE_DATA',\n operation,\n path,\n retryable: false,\n });\n};\n\nconst throwResourceLimitExceeded = (\n limit: 'maxEntries' | 'maxFileBytes' | 'maxTotalBytesRead',\n limitMaximum: number,\n observedUsage: number,\n): never => {\n throw new CoreOperationException({\n code: 'RESOURCE_LIMIT_EXCEEDED',\n limit,\n limitMaximum,\n nextAction: 'reduce-input-or-increase-limit',\n observedUsage,\n operation: 'validate-project',\n });\n};\n\n/**\n * Reads one complete adapter source file through bounded repository pages.\n * @param repository The Core-created repository for the current adapter invocation.\n * @param path The exact source file path.\n * @param options Optional cancellation controls.\n * @returns A promise resolving to one detached complete source buffer.\n * @throws\n * - INVALID_REPOSITORY_PATH: The repository path is invalid.\n * - ENTRY_NOT_FOUND: The requested repository entry was not found.\n * - ENTRY_NOT_FILE: The requested repository entry is not a file.\n * - INVALID_PAGE_REQUEST: The repository page request is invalid.\n * - ACCESS_DENIED: Access to the repository source was denied.\n * - SOURCE_UNAVAILABLE: The repository source is unavailable.\n * - SNAPSHOT_CHANGED: The repository snapshot changed during the operation.\n * - INVALID_SOURCE_DATA: The repository source returned invalid data.\n * - RESOURCE_LIMIT_EXCEEDED: A named repository resource limit was exceeded.\n * - ABORTED: The repository operation was aborted.\n * - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.\n */\nexport const readRuntimeAdapterFile = async (\n repository: IRuntimeAdapterRepository,\n path: IRepositoryPath,\n options?: IRepositoryOperationOptions,\n): Promise<Uint8Array> => {\n const parsedPath = parseRepositoryPath(path);\n const entry = await repository.getEntry(parsedPath, options);\n\n if (entry === null) {\n throw new RepositorySourceException({\n code: 'ENTRY_NOT_FOUND',\n operation: 'read-file-page',\n path: parsedPath,\n retryable: false,\n });\n }\n\n if (entry.type !== 'file' || entry.byteLength === null) {\n throw new RepositorySourceException({\n code: 'ENTRY_NOT_FILE',\n operation: 'read-file-page',\n path: parsedPath,\n retryable: false,\n });\n }\n\n if (entry.byteLength > repository.limits.maxFileBytes) {\n return throwResourceLimitExceeded(\n 'maxFileBytes',\n repository.limits.maxFileBytes,\n entry.byteLength,\n );\n }\n\n reserveRuntimeAdapterRetainedBytesIfTracked(repository, entry.byteLength);\n const content = new Uint8Array(entry.byteLength);\n let offset = 0;\n let isFirstPage = true;\n\n while (isFirstPage || offset < entry.byteLength) {\n isFirstPage = false;\n options?.signal?.throwIfAborted();\n const page = await repository.readFilePage(parsedPath, {\n maxBytes: Math.min(repository.limits.maxPageBytes, Math.max(1, entry.byteLength - offset)),\n offset,\n ...(options?.signal === undefined ? {} : { signal: options.signal }),\n });\n\n if (\n page.snapshot.id !== repository.snapshot.id ||\n page.offset !== offset ||\n page.totalBytes !== entry.byteLength ||\n !(page.bytes instanceof Uint8Array) ||\n page.bytes.byteLength > repository.limits.maxPageBytes ||\n page.bytes.byteLength > content.byteLength - offset ||\n (page.bytes.byteLength === 0 && !page.isComplete)\n ) {\n return invalidSourceData('read-file-page', parsedPath);\n }\n\n content.set(page.bytes, offset);\n offset += page.bytes.byteLength;\n\n if (page.isComplete) {\n if (page.nextOffset !== null || offset !== content.byteLength) {\n return invalidSourceData('read-file-page', parsedPath);\n }\n\n return content;\n }\n\n if (page.nextOffset !== offset) {\n return invalidSourceData('read-file-page', parsedPath);\n }\n }\n\n return invalidSourceData('read-file-page', parsedPath);\n};\n\n/** Iterates one adapter-scoped descendant listing through bounded pages. */\nexport const iterateRuntimeAdapterEntries = (\n repository: IRuntimeAdapterRepository,\n options?: IRepositoryOperationOptions & { readonly prefix?: IRepositoryPath },\n): AsyncIterable<IRepositoryEntry> => {\n const prefix =\n options?.prefix === undefined ? REPOSITORY_ROOT : parseRepositoryPath(options.prefix);\n\n return {\n async *[Symbol.asyncIterator](): AsyncIterator<IRepositoryEntry> {\n let cursor: string | undefined;\n let entryCount = 0;\n let previousPath: IRepositoryPath | null = null;\n\n do {\n options?.signal?.throwIfAborted();\n const page = await repository.listEntriesPage({\n ...(cursor === undefined ? {} : { cursor }),\n maxEntries: repository.limits.maxPageEntries,\n prefix,\n ...(options?.signal === undefined ? {} : { signal: options.signal }),\n });\n\n if (\n page.snapshot.id !== repository.snapshot.id ||\n page.entries.length > repository.limits.maxPageEntries ||\n (page.entries.length === 0 && !page.isComplete)\n ) {\n return invalidSourceData('list-entries-page', prefix);\n }\n\n for (const entry of page.entries) {\n if (previousPath !== null && compareRepositoryPaths(previousPath, entry.path) >= 0) {\n return invalidSourceData('list-entries-page', entry.path);\n }\n\n entryCount += 1;\n if (entryCount > repository.limits.maxEntries) {\n return throwResourceLimitExceeded(\n 'maxEntries',\n repository.limits.maxEntries,\n entryCount,\n );\n }\n\n previousPath = entry.path;\n yield entry;\n }\n\n if (page.isComplete) {\n if (page.nextCursor !== null) {\n return invalidSourceData('list-entries-page', prefix);\n }\n\n return;\n }\n\n if (page.nextCursor === null || page.nextCursor === cursor) {\n return invalidSourceData('list-entries-page', prefix);\n }\n\n cursor = page.nextCursor;\n } while (true);\n },\n };\n};\n"],"mappings":";;;AAcA,IAAM,qBACJ,WACA,SACU;CACV,MAAM,IAAI,0BAA0B;EAClC,MAAM;EACN;EACA;EACA,WAAW;CACb,CAAC;AACH;AAEA,IAAM,8BACJ,OACA,cACA,kBACU;CACV,MAAM,I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AAI,KAAK,eAAe,QAAQ,KAAK,eAAe,QAClD,OAAO,kBAAkB,qBAAqB,MAAM;GAGtD,SAAS,KAAK;EAChB,SAAS;CACX,EACF;AACF"}
|
|
@@ -1,4 +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
|
|
2
15
|
//#region src/exceptions/index.ts
|
|
3
16
|
var CONFIGURATION_ERROR_MESSAGES = {
|
|
4
17
|
DUPLICATE_ADAPTER_ID: "A runtime adapter ID is registered more than once.",
|
|
@@ -72,6 +85,6 @@ var CoreOperationException = class extends Exception {
|
|
|
72
85
|
}
|
|
73
86
|
};
|
|
74
87
|
//#endregion
|
|
75
|
-
export { CoreOperationException as n, CoreConfigurationException as t };
|
|
88
|
+
export { reserveRuntimeAdapterRetainedBytesIfTracked as i, CoreOperationException as n, registerRuntimeAdapterRetainedByteReservation as r, CoreConfigurationException as t };
|
|
76
89
|
|
|
77
|
-
//# sourceMappingURL=exceptions-
|
|
90
|
+
//# sourceMappingURL=exceptions-HS9ofVy2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions-HS9ofVy2.js","names":[],"sources":["../../src/adapter-retained-memory/index.ts","../../src/exceptions/index.ts"],"sourcesContent":["import type { IRuntimeAdapterRepository } from '../adapter/index.js';\ntype IRetainedByteReservation = (byteLength: number) => void;\n\n// reservations belong to Core-created adapter repositories and remain private to the session\nconst retainedByteReservations = new WeakMap<IRuntimeAdapterRepository, IRetainedByteReservation>();\n\n/** Registers the retained-memory reservation owned by one inspection session. */\nexport const registerRuntimeAdapterRetainedByteReservation = (\n repository: IRuntimeAdapterRepository,\n reserve: IRetainedByteReservation,\n): void => {\n if (retainedByteReservations.has(repository)) {\n throw new TypeError('The runtime adapter repository is already registered.');\n }\n\n retainedByteReservations.set(repository, reserve);\n};\n\n/** Reserves a complete adapter-owned buffer when Core owns the repository session. */\nexport const reserveRuntimeAdapterRetainedBytesIfTracked = (\n repository: IRuntimeAdapterRepository,\n byteLength: number,\n): void => {\n const reserve = retainedByteReservations.get(repository);\n\n if (reserve !== undefined) {\n reserve(byteLength);\n }\n};\n","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 | 'CONTENT_INVALID';\n\nexport type ICoreOperation =\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\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// complete resource-refusal metadata required by Core 4\nexport type ICoreResourceLimitNextAction = 'reduce-input-or-increase-limit';\n\nexport type ICoreOperationExceptionOptions = ICoreOperationExceptionOptionsBase &\n (\n | {\n readonly code: 'RESOURCE_LIMIT_EXCEEDED';\n readonly limit: string;\n readonly limitMaximum: number;\n readonly nextAction: ICoreResourceLimitNextAction;\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 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 RESOURCE_LIMIT_EXCEEDED: false,\n} as const satisfies Readonly<Record<ICoreOperationErrorCode, boolean>>;\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.observedUsage = options.observedUsage ?? null;\n attachCause(this, options.cause);\n }\n}\n"],"mappings":";;AAIA,IAAM,2CAA2B,IAAI,QAA6D;;AAGlG,IAAa,iDACX,YACA,YACS;CACT,IAAI,yBAAyB,IAAI,UAAU,GACzC,MAAM,IAAI,UAAU,uDAAuD;CAG7E,yBAAyB,IAAI,YAAY,OAAO;AAClD;;AAGA,IAAa,+CACX,YACA,eACS;CACT,MAAM,UAAU,yBAAyB,IAAI,UAAU;CAEvD,IAAI,YAAY,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jC;AACF"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as CoreOperationException, t as CoreConfigurationException } from "./chunks/exceptions-
|
|
1
|
+
import { n as CoreOperationException, r as registerRuntimeAdapterRetainedByteReservation, t as CoreConfigurationException } from "./chunks/exceptions-HS9ofVy2.js";
|
|
2
2
|
import { REPOSITORY_ROOT, RepositoryPathException, RepositorySourceException, compareRepositoryPaths, createRepositoryIdentity, isRepositoryPath, parseRepositoryPath } from "@moldea.ai/repository";
|
|
3
3
|
import { Parser, isAlias, isMap, isScalar, isSeq, parseAllDocuments } from "yaml";
|
|
4
4
|
//#region src/constants/index.ts
|
|
@@ -2312,11 +2312,13 @@ var parseManifestDocument = async (input, options, operation = "parse-manifest")
|
|
|
2312
2312
|
};
|
|
2313
2313
|
//#endregion
|
|
2314
2314
|
//#region src/project-agent-assignments/index.ts
|
|
2315
|
-
/**
|
|
2316
|
-
var
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2315
|
+
/** Iterates content-free agent-to-runtime assignments without retaining an intermediate array. */
|
|
2316
|
+
var iterateProjectAgentAssignments = function* (project) {
|
|
2317
|
+
for (const agent of project.agents) yield {
|
|
2318
|
+
agentId: agent.id,
|
|
2319
|
+
runtimeId: agent.declaration.runtime.id
|
|
2320
|
+
};
|
|
2321
|
+
};
|
|
2320
2322
|
//#endregion
|
|
2321
2323
|
//#region src/project-metadata/index.ts
|
|
2322
2324
|
var createAssetItem = (asset, kind, agentId = null, decisionId = null) => ({
|
|
@@ -2329,18 +2331,18 @@ var createAssetItem = (asset, kind, agentId = null, decisionId = null) => ({
|
|
|
2329
2331
|
path: asset.path,
|
|
2330
2332
|
scalarLength: asset.scalarLength
|
|
2331
2333
|
});
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
for (const context of project.context)
|
|
2337
|
-
for (const { decision } of project.decisions)
|
|
2338
|
-
for (const runtime of project.runtimes)
|
|
2334
|
+
/** Iterates content-free asset metadata without retaining a second project-sized collection. */
|
|
2335
|
+
var iterateProjectMetadata = function* (project) {
|
|
2336
|
+
yield createAssetItem(project.manifest.asset, "manifest");
|
|
2337
|
+
yield createAssetItem(project.project, "project");
|
|
2338
|
+
for (const context of project.context) yield createAssetItem(context.asset, "context");
|
|
2339
|
+
for (const { decision } of project.decisions) yield createAssetItem(decision.asset, "decision", null, decision.id);
|
|
2340
|
+
for (const runtime of project.runtimes) yield createAssetItem(runtime.asset, "runtime-guidance");
|
|
2339
2341
|
for (const agent of project.agents) {
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
if (agent.handoffDescription !== null)
|
|
2343
|
-
for (const mirror of agent.mirrors)
|
|
2342
|
+
yield createAssetItem(agent.description.asset, "agent-description", agent.id);
|
|
2343
|
+
yield createAssetItem(agent.instruction, "agent-instruction", agent.id);
|
|
2344
|
+
if (agent.handoffDescription !== null) yield createAssetItem(agent.handoffDescription.asset, "agent-handoff-description", agent.id);
|
|
2345
|
+
for (const mirror of agent.mirrors) yield {
|
|
2344
2346
|
agentId: agent.id,
|
|
2345
2347
|
byteLength: mirror.byteLength,
|
|
2346
2348
|
canonicalDigest: mirror.canonicalDigest,
|
|
@@ -2349,9 +2351,8 @@ var collectProjectMetadata = (project) => {
|
|
|
2349
2351
|
kind: "mirror",
|
|
2350
2352
|
path: mirror.path,
|
|
2351
2353
|
scalarLength: mirror.scalarLength
|
|
2352
|
-
}
|
|
2354
|
+
};
|
|
2353
2355
|
}
|
|
2354
|
-
return items.sort(compareMetadataItems);
|
|
2355
2356
|
};
|
|
2356
2357
|
/** Creates the content-free summary for one validated project snapshot. */
|
|
2357
2358
|
var createProjectSummary = (project) => ({
|
|
@@ -3148,6 +3149,7 @@ var createRepositoryInspectionSession = (repository, limits, signal) => {
|
|
|
3148
3149
|
readFilePage: readAdapterFilePage,
|
|
3149
3150
|
snapshot: repository.snapshot
|
|
3150
3151
|
});
|
|
3152
|
+
registerRuntimeAdapterRetainedByteReservation(adapterRepository, reserveRetainedBytes);
|
|
3151
3153
|
return Object.freeze({
|
|
3152
3154
|
adapterRepository,
|
|
3153
3155
|
getResourceUsage: () => Object.freeze({
|
|
@@ -4975,7 +4977,9 @@ var serializeDeterministically = (candidate) => {
|
|
|
4975
4977
|
if (Array.isArray(candidate)) return `[${candidate.map((item) => serializeDeterministically(item)).join(",")}]`;
|
|
4976
4978
|
return `{${Object.entries(candidate).filter(([, value]) => value !== void 0).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, value]) => `${JSON.stringify(key)}:${serializeDeterministically(value)}`).join(",")}}`;
|
|
4977
4979
|
};
|
|
4978
|
-
var createIdentity = (parts) => createRepositoryIdentity(
|
|
4980
|
+
var createIdentity = (parts) => createRepositoryIdentity((function* () {
|
|
4981
|
+
for (const part of parts) yield encoder.encode(part);
|
|
4982
|
+
})());
|
|
4979
4983
|
var createItemBaseKey = (item) => {
|
|
4980
4984
|
if (item.kind === "agent") return [
|
|
4981
4985
|
"3",
|
|
@@ -5007,19 +5011,19 @@ var createItemBaseKey = (item) => {
|
|
|
5007
5011
|
};
|
|
5008
5012
|
/** Assigns stable unique keys once without relying on collection offsets. */
|
|
5009
5013
|
var createKeyedItems = (items) => {
|
|
5010
|
-
const sorted =
|
|
5011
|
-
|
|
5012
|
-
item
|
|
5013
|
-
})).sort((left, right) => left.
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5014
|
+
const sorted = Array.from(items, (item) => ({
|
|
5015
|
+
item,
|
|
5016
|
+
key: createItemBaseKey(item)
|
|
5017
|
+
})).sort((left, right) => left.key < right.key ? -1 : left.key > right.key ? 1 : 0);
|
|
5018
|
+
let previousBaseKey = null;
|
|
5019
|
+
let occurrence = 0;
|
|
5020
|
+
for (const item of sorted) {
|
|
5021
|
+
const baseKey = item.key;
|
|
5022
|
+
occurrence = baseKey === previousBaseKey ? occurrence + 1 : 0;
|
|
5023
|
+
previousBaseKey = baseKey;
|
|
5024
|
+
item.key = `${baseKey}:${String(occurrence).padStart(10, "0")}`;
|
|
5025
|
+
}
|
|
5026
|
+
return sorted;
|
|
5023
5027
|
};
|
|
5024
5028
|
var createCursorChecksum = (inspectionDigest, lastKey, view) => createIdentity([
|
|
5025
5029
|
CURSOR_PREFIX,
|
|
@@ -5058,17 +5062,71 @@ var addRetainedBytes = (current, additional, retainedBeforePreparation, maximum)
|
|
|
5058
5062
|
if (!Number.isSafeInteger(additional) || additional < 0 || !Number.isSafeInteger(projectedUsage) || projectedUsage > maximum) return resourceLimitExceeded$1(maximum, Number.isSafeInteger(projectedUsage) ? projectedUsage : Number.MAX_SAFE_INTEGER);
|
|
5059
5063
|
return current + additional;
|
|
5060
5064
|
};
|
|
5061
|
-
/**
|
|
5062
|
-
var
|
|
5065
|
+
/** Iterates every content-free inspection item without retaining preparation state. */
|
|
5066
|
+
var iterateProjectInspectionItems = function* (state) {
|
|
5067
|
+
if (state.project !== null) for (const metadata of iterateProjectMetadata(state.project)) yield {
|
|
5068
|
+
kind: "metadata",
|
|
5069
|
+
metadata
|
|
5070
|
+
};
|
|
5071
|
+
for (const diagnostic of state.result.diagnostics) yield {
|
|
5072
|
+
diagnostic,
|
|
5073
|
+
kind: "diagnostic"
|
|
5074
|
+
};
|
|
5075
|
+
for (const evidence of state.result.evidence) yield {
|
|
5076
|
+
evidence,
|
|
5077
|
+
kind: "evidence"
|
|
5078
|
+
};
|
|
5079
|
+
if (state.project !== null) for (const agent of iterateProjectAgentAssignments(state.project)) yield {
|
|
5080
|
+
agent,
|
|
5081
|
+
kind: "agent"
|
|
5082
|
+
};
|
|
5083
|
+
};
|
|
5084
|
+
/** Preflights the complete logical prepared-state cost before retaining its collections. */
|
|
5085
|
+
var estimatePreparedProjectInspection = (state, baseCounts, maximum) => {
|
|
5086
|
+
const retainedBeforePreparation = state.resourceUsage.retainedBytes;
|
|
5063
5087
|
let bytes = addRetainedBytes(0, PREPARED_FIXED_BYTES, retainedBeforePreparation, maximum);
|
|
5064
|
-
|
|
5088
|
+
let metadataCount = 0;
|
|
5089
|
+
for (const item of iterateProjectInspectionItems(state)) {
|
|
5090
|
+
const key = `${createItemBaseKey(item)}:0000000000`;
|
|
5065
5091
|
const encodedBytes = encoder.encode(key).byteLength + encoder.encode(serializeDeterministically(item)).byteLength;
|
|
5066
|
-
bytes = addRetainedBytes(bytes, PREPARED_ITEM_FIXED_BYTES + encodedBytes * PREPARED_TEXT_BYTE_MULTIPLIER, retainedBeforePreparation, maximum);
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5092
|
+
bytes = addRetainedBytes(bytes, PREPARED_ITEM_FIXED_BYTES + encodedBytes * PREPARED_TEXT_BYTE_MULTIPLIER + PREPARED_VIEW_REFERENCE_BYTES, retainedBeforePreparation, maximum);
|
|
5093
|
+
if (item.kind === "metadata") metadataCount += 1;
|
|
5094
|
+
}
|
|
5095
|
+
const counts = {
|
|
5096
|
+
agents: baseCounts.agents,
|
|
5097
|
+
context: baseCounts.context,
|
|
5098
|
+
decisions: baseCounts.decisions,
|
|
5099
|
+
diagnostics: baseCounts.diagnostics,
|
|
5100
|
+
evidence: baseCounts.evidence,
|
|
5101
|
+
metadata: metadataCount,
|
|
5102
|
+
mirrors: baseCounts.mirrors,
|
|
5103
|
+
runtimes: baseCounts.runtimes,
|
|
5104
|
+
unresolved: baseCounts.unresolved
|
|
5105
|
+
};
|
|
5106
|
+
bytes = addRetainedBytes(bytes, encoder.encode(serializeDeterministically({
|
|
5107
|
+
counts,
|
|
5108
|
+
formatVersion: state.result.formatVersion,
|
|
5109
|
+
inspectionDigest: "sha256:0000000000000000000000000000000000000000000000000000000000000000",
|
|
5110
|
+
source: state.result.source,
|
|
5111
|
+
summary: state.result.summary,
|
|
5112
|
+
valid: state.result.valid
|
|
5113
|
+
})).byteLength * PREPARED_TEXT_BYTE_MULTIPLIER, retainedBeforePreparation, maximum);
|
|
5114
|
+
return {
|
|
5115
|
+
counts,
|
|
5116
|
+
preparedBytes: bytes
|
|
5117
|
+
};
|
|
5071
5118
|
};
|
|
5119
|
+
/** Creates the inspection digest without materializing a project-sized key projection. */
|
|
5120
|
+
var createInspectionDigest = (counts, formatVersion, items, summary, valid) => createIdentity((function* () {
|
|
5121
|
+
yield "core4-prepared-inspection";
|
|
5122
|
+
yield serializeDeterministically({
|
|
5123
|
+
counts,
|
|
5124
|
+
formatVersion,
|
|
5125
|
+
summary,
|
|
5126
|
+
valid
|
|
5127
|
+
});
|
|
5128
|
+
for (const { key } of items) yield key;
|
|
5129
|
+
})());
|
|
5072
5130
|
var findStartIndex = (items, lastKey) => {
|
|
5073
5131
|
if (lastKey === null) return 0;
|
|
5074
5132
|
let lower = 0;
|
|
@@ -5085,23 +5143,9 @@ var findStartIndex = (items, lastKey) => {
|
|
|
5085
5143
|
};
|
|
5086
5144
|
/** Creates the returned inspection from content-free state only. */
|
|
5087
5145
|
var createPreparedProjectInspection = (input) => {
|
|
5088
|
-
const { counts, formatVersion, items, maxEntries,
|
|
5146
|
+
const { counts, formatVersion, items, maxEntries, preparedBytes, resourceUsage: validationUsage, source, summary, valid } = input;
|
|
5089
5147
|
const views = createViews(items);
|
|
5090
|
-
const inspectionDigest =
|
|
5091
|
-
counts,
|
|
5092
|
-
formatVersion,
|
|
5093
|
-
itemKeys: items.map(({ key }) => key),
|
|
5094
|
-
summary,
|
|
5095
|
-
valid
|
|
5096
|
-
})]);
|
|
5097
|
-
const preparedBytes = calculatePreparedBytes(items, views, {
|
|
5098
|
-
counts,
|
|
5099
|
-
formatVersion,
|
|
5100
|
-
inspectionDigest,
|
|
5101
|
-
source,
|
|
5102
|
-
summary,
|
|
5103
|
-
valid
|
|
5104
|
-
}, validationUsage.retainedBytes, maxRetainedBytes);
|
|
5148
|
+
const inspectionDigest = createInspectionDigest(counts, formatVersion, items, summary, valid);
|
|
5105
5149
|
const resourceUsage = freezeRecursively({
|
|
5106
5150
|
canonicalBytes: validationUsage.canonicalBytes,
|
|
5107
5151
|
peakRetainedBytes: Math.max(validationUsage.peakRetainedBytes, validationUsage.retainedBytes + preparedBytes),
|
|
@@ -5150,42 +5194,24 @@ var createPreparedProjectInspection = (input) => {
|
|
|
5150
5194
|
/** Prepares one immutable content-free inspection for synchronous bounded page reads. */
|
|
5151
5195
|
var createProjectInspection = async (input, options) => {
|
|
5152
5196
|
const state = await validateProjectState(input, options);
|
|
5153
|
-
const
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
evidence,
|
|
5166
|
-
kind: "evidence"
|
|
5167
|
-
})),
|
|
5168
|
-
...agentAssignments.map((agent) => ({
|
|
5169
|
-
agent,
|
|
5170
|
-
kind: "agent"
|
|
5171
|
-
}))
|
|
5172
|
-
]));
|
|
5197
|
+
const estimate = estimatePreparedProjectInspection(state, {
|
|
5198
|
+
agents: state.result.summary?.counts.agents ?? 0,
|
|
5199
|
+
context: state.result.summary?.counts.context ?? 0,
|
|
5200
|
+
decisions: state.result.summary?.counts.decisions ?? 0,
|
|
5201
|
+
diagnostics: state.result.diagnostics.length,
|
|
5202
|
+
evidence: state.result.evidence.length,
|
|
5203
|
+
mirrors: state.result.summary?.counts.mirrors ?? 0,
|
|
5204
|
+
runtimes: state.result.summary?.counts.runtimes ?? 0,
|
|
5205
|
+
unresolved: state.result.summary?.counts.unresolved ?? 0
|
|
5206
|
+
}, options.limits.maxRetainedBytes);
|
|
5207
|
+
const counts = freezeRecursively(estimate.counts);
|
|
5208
|
+
const items = freezeRecursively(createKeyedItems(iterateProjectInspectionItems(state)));
|
|
5173
5209
|
return createPreparedProjectInspection({
|
|
5174
|
-
counts
|
|
5175
|
-
agents: state.result.summary?.counts.agents ?? 0,
|
|
5176
|
-
context: state.result.summary?.counts.context ?? 0,
|
|
5177
|
-
decisions: state.result.summary?.counts.decisions ?? 0,
|
|
5178
|
-
diagnostics: state.result.diagnostics.length,
|
|
5179
|
-
evidence: state.result.evidence.length,
|
|
5180
|
-
metadata: metadata.length,
|
|
5181
|
-
mirrors: state.result.summary?.counts.mirrors ?? 0,
|
|
5182
|
-
runtimes: state.result.summary?.counts.runtimes ?? 0,
|
|
5183
|
-
unresolved: state.result.summary?.counts.unresolved ?? 0
|
|
5184
|
-
}),
|
|
5210
|
+
counts,
|
|
5185
5211
|
formatVersion: state.result.formatVersion,
|
|
5186
5212
|
items,
|
|
5187
5213
|
maxEntries: options.limits.maxEntries,
|
|
5188
|
-
|
|
5214
|
+
preparedBytes: estimate.preparedBytes,
|
|
5189
5215
|
resourceUsage: state.resourceUsage,
|
|
5190
5216
|
source: state.result.source,
|
|
5191
5217
|
summary: state.result.summary,
|