@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.
- package/README.md +11 -4
- package/dist/adapter/index.d.ts +16 -4
- package/dist/adapter/index.d.ts.map +1 -1
- package/dist/adapter-execution/index.d.ts +12 -9
- package/dist/adapter-execution/index.d.ts.map +1 -1
- package/dist/adapter-result-collection/collection.d.ts +13 -0
- package/dist/adapter-result-collection/collection.d.ts.map +1 -0
- package/dist/adapter-result-collection/index.d.ts +3 -0
- package/dist/adapter-result-collection/index.d.ts.map +1 -0
- package/dist/adapter-result-collection/types.d.ts +31 -0
- package/dist/adapter-result-collection/types.d.ts.map +1 -0
- package/dist/adapter.js +3 -2
- package/dist/adapter.js.map +1 -1
- package/dist/analysis-worker.js +190 -0
- package/dist/analysis-worker.js.map +1 -0
- package/dist/chunks/collection-CvbjjLf2.js +73 -0
- package/dist/chunks/collection-CvbjjLf2.js.map +1 -0
- package/dist/chunks/core-DchheNDz.js +5305 -0
- package/dist/chunks/core-DchheNDz.js.map +1 -0
- package/dist/chunks/errors-BQI1DEqf.js +446 -0
- package/dist/chunks/errors-BQI1DEqf.js.map +1 -0
- package/dist/chunks/{exceptions-HS9ofVy2.js → exceptions-lzD3buFw.js} +26 -15
- package/dist/chunks/exceptions-lzD3buFw.js.map +1 -0
- package/dist/chunks/lifecycle-4EkWgEHm.js +67 -0
- package/dist/chunks/lifecycle-4EkWgEHm.js.map +1 -0
- package/dist/chunks/options-CxCT3dZU.js +617 -0
- package/dist/chunks/options-CxCT3dZU.js.map +1 -0
- package/dist/chunks/repository-rpc-BWi6X1la.js +124 -0
- package/dist/chunks/repository-rpc-BWi6X1la.js.map +1 -0
- package/dist/contracts/index.d.ts +28 -18
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/custom-runtime-inspection/index.d.ts +2 -0
- package/dist/custom-runtime-inspection/index.d.ts.map +1 -0
- package/dist/custom-runtime-inspection/inspection.d.ts +11 -0
- package/dist/custom-runtime-inspection/inspection.d.ts.map +1 -0
- package/dist/exceptions/index.d.ts +23 -4
- package/dist/exceptions/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5775
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node-inspection/analysis-worker.d.ts +2 -0
- package/dist/node-inspection/analysis-worker.d.ts.map +1 -0
- package/dist/node-inspection/client.d.ts +32 -0
- package/dist/node-inspection/client.d.ts.map +1 -0
- package/dist/node-inspection/constants.d.ts +21 -0
- package/dist/node-inspection/constants.d.ts.map +1 -0
- package/dist/node-inspection/errors.d.ts +11 -0
- package/dist/node-inspection/errors.d.ts.map +1 -0
- package/dist/node-inspection/lifecycle.d.ts +15 -0
- package/dist/node-inspection/lifecycle.d.ts.map +1 -0
- package/dist/node-inspection/protocol.d.ts +20 -0
- package/dist/node-inspection/protocol.d.ts.map +1 -0
- package/dist/node-inspection/repository-rpc.d.ts +28 -0
- package/dist/node-inspection/repository-rpc.d.ts.map +1 -0
- package/dist/node-inspection/runner.d.ts +2 -0
- package/dist/node-inspection/runner.d.ts.map +1 -0
- package/dist/node-inspection/types.d.ts +99 -0
- package/dist/node-inspection/types.d.ts.map +1 -0
- package/dist/node-runner.js +149 -0
- package/dist/node-runner.js.map +1 -0
- package/dist/node.js +325 -0
- package/dist/node.js.map +1 -0
- package/dist/project-inspection/index.d.ts +22 -1
- package/dist/project-inspection/index.d.ts.map +1 -1
- package/dist/project-validation/index.d.ts +34 -10
- package/dist/project-validation/index.d.ts.map +1 -1
- package/package.json +9 -1
- package/dist/chunks/exceptions-HS9ofVy2.js.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
Source-neutral, deterministic, content-safe interpretation of the `moldea` repository format.
|
|
6
6
|
|
|
7
|
-
Version
|
|
7
|
+
Version 6 accepts caller-supplied text and `@moldea.ai/repository` version 2 readers. The main, format, and adapter entry points remain environment-neutral. Repository access belongs to the caller-supplied reader. Project validation returns content-free summaries, diagnostics, evidence, agent assignments, and metadata. Canonical document bodies are available only through an explicit path-scoped byte-range operation.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
pnpm add @moldea.ai/core@
|
|
12
|
+
pnpm add @moldea.ai/core@6 @moldea.ai/repository@2
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Public entry points
|
|
@@ -17,6 +17,7 @@ pnpm add @moldea.ai/core@5 @moldea.ai/repository@2
|
|
|
17
17
|
- `@moldea.ai/core` exposes Core construction, operations, results, diagnostics, limits, and exceptions.
|
|
18
18
|
- `@moldea.ai/core/format` exposes repository-format contracts.
|
|
19
19
|
- `@moldea.ai/core/adapter` exposes the per-agent runtime-adapter contract and bounded reader utilities.
|
|
20
|
+
- `@moldea.ai/core/node` exposes supervised Node inspection with asynchronous paging and disposal. It imports only a caller-selected trusted installed adapter registry, never project application code. Its frozen `NODE_INSPECTION_PROFILE` reports the fixed heap, lifetime, bridge and transport settings for authenticated consumer state; it does not configure them. Each inspection handle separately reports the runtime's actual V8 heap limit.
|
|
20
21
|
|
|
21
22
|
## Text and document parsing
|
|
22
23
|
|
|
@@ -65,7 +66,9 @@ const repository = createMemoryRepositoryReader([
|
|
|
65
66
|
const result = await core.validateProject({ repository });
|
|
66
67
|
```
|
|
67
68
|
|
|
68
|
-
`validateProject` returns validity, format version, source identity, summary counts and digests, diagnostics, and runtime evidence. It never returns manifest, project, context, decision, runtime-guidance, mirror, description, or instruction bodies.
|
|
69
|
+
`validateProject` returns validity, runtime-inspection status, format version, source identity, summary counts and digests, diagnostics, and runtime evidence. It never returns manifest, project, context, decision, runtime-guidance, mirror, description, or instruction bodies.
|
|
70
|
+
|
|
71
|
+
`runtimeInspection` is `complete` when applicable runtime checks finish without unverified relationships, `incomplete` when any relationship remains unverified, and `not-run` when universal checks or adapter availability prevent runtime inspection. Validity remains based on errors. Warning-only results are valid, and projects without runtime relationships are complete. Every prepared inspection and page preserves the same aggregate status.
|
|
69
72
|
|
|
70
73
|
`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
74
|
|
|
@@ -73,7 +76,11 @@ The prepared inspection retains only its content-free records, summary, source i
|
|
|
73
76
|
|
|
74
77
|
## Per-agent runtime adapters
|
|
75
78
|
|
|
76
|
-
Universal validation must succeed before adapters run. Core invokes a configured package adapter once for each matching agent, in deterministic adapter and agent order. Each invocation receives only that agent, a bounded reader, a shared cancellation signal, and an exact same-runtime `resolveAgent(reference)` function for bindings that genuinely require another agent. It never receives the complete agent collection.
|
|
79
|
+
Universal validation must succeed before adapters run. Core invokes a configured package adapter once for each matching agent, in deterministic adapter and agent order. Each invocation receives only that agent, a bounded reader, a shared cancellation signal, the remaining operation-wide diagnostic/evidence allowance as `outputBudget`, and an exact same-runtime `resolveAgent(reference)` function for bindings that genuinely require another agent. It never receives the complete agent collection.
|
|
80
|
+
|
|
81
|
+
Adapters use `createRuntimeAdapterResultCollector(context)` from `@moldea.ai/core/adapter`. Its `diagnostics.add(factory)` and `evidence.add(factory)` methods reserve raw admission before constructing records; `finalize()` returns the existing `{ evidence, diagnostics }` result. Earlier invocations consume the allowance before deduplication. Exhaustion raises `RESOURCE_LIMIT_EXCEEDED`, and Core still checks the complete raw result independently.
|
|
82
|
+
|
|
83
|
+
For the reserved `custom` runtime, Core reports `CUSTOM_RUNTIME_RELATIONSHIP_UNVERIFIED` warnings for declared bindings, capabilities, schemas, and variable providers. Core registers no custom adapter and infers no SDK or native handoff graph.
|
|
77
84
|
|
|
78
85
|
Adapter evidence and diagnostics are validated, normalized, deduplicated, sorted, and limited before exposure. An unexpected adapter failure or invalid output rejects the complete operation with `ADAPTER_EXECUTION_FAILED`.
|
|
79
86
|
|
package/dist/adapter/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IRepositoryEntry, IRepositoryEntryPage, IRepositoryEntryPageOptions, IRepositoryFilePage, IRepositoryFilePageOptions, IRepositoryOperationOptions, IRepositoryPath, IRepositorySnapshot } from '@moldea.ai/repository';
|
|
2
2
|
import type { IIndexedAgent, IIndexedDescriptionAsset } from '../contracts/index.js';
|
|
3
|
+
import type { IRuntimeAdapterOutputBudget } from '../adapter-result-collection/index.js';
|
|
3
4
|
import type { IAdapterDiagnostic, IDiagnosticDetails } from '../diagnostics/index.js';
|
|
4
5
|
import type { IRepositoryFormatVersion, IRepositoryReference } from '../format/index.js';
|
|
5
6
|
export interface IRuntimeAdapter {
|
|
@@ -16,15 +17,19 @@ export interface IRuntimeAdapter {
|
|
|
16
17
|
* - ENTRY_NOT_DIRECTORY: The requested repository entry is not a directory.
|
|
17
18
|
* - ACCESS_DENIED: Access to the repository source was denied.
|
|
18
19
|
* - SOURCE_UNAVAILABLE: The repository source is unavailable.
|
|
20
|
+
* - PROVIDER_INCOMPLETE: The repository provider cannot expose a complete result.
|
|
19
21
|
* - SNAPSHOT_CHANGED: The repository snapshot changed during the operation.
|
|
20
22
|
* - INVALID_SOURCE_DATA: The repository source returned invalid data.
|
|
21
23
|
* - RESOURCE_LIMIT_EXCEEDED: A named repository resource limit was exceeded.
|
|
24
|
+
* - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.
|
|
22
25
|
* - ABORTED: The repository operation was aborted.
|
|
26
|
+
* - ABORTED: The Core operation was aborted.
|
|
23
27
|
*/
|
|
24
28
|
inspect(context: IRuntimeAdapterContext): Promise<IRuntimeAdapterResult>;
|
|
25
29
|
}
|
|
26
30
|
export interface IRuntimeAdapterContext {
|
|
27
31
|
readonly agent: IIndexedAgent;
|
|
32
|
+
readonly outputBudget: IRuntimeAdapterOutputBudget;
|
|
28
33
|
readonly repository: IRuntimeAdapterRepository;
|
|
29
34
|
readonly signal?: AbortSignal;
|
|
30
35
|
/**
|
|
@@ -61,10 +66,13 @@ export interface IRuntimeAdapterRepository {
|
|
|
61
66
|
* - INVALID_REPOSITORY_PATH: The repository path is invalid.
|
|
62
67
|
* - ACCESS_DENIED: Access to the repository source was denied.
|
|
63
68
|
* - SOURCE_UNAVAILABLE: The repository source is unavailable.
|
|
64
|
-
* -
|
|
65
|
-
* -
|
|
66
|
-
* -
|
|
67
|
-
* -
|
|
69
|
+
* - PROVIDER_INCOMPLETE: The repository provider cannot expose a complete result.
|
|
70
|
+
* - SNAPSHOT_CHANGED: The repository snapshot changed during the operation.
|
|
71
|
+
* - INVALID_SOURCE_DATA: The repository source returned invalid data.
|
|
72
|
+
* - RESOURCE_LIMIT_EXCEEDED: A named repository resource limit was exceeded.
|
|
73
|
+
* - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.
|
|
74
|
+
* - ABORTED: The repository operation was aborted.
|
|
75
|
+
* - ABORTED: The Core operation was aborted.
|
|
68
76
|
*/
|
|
69
77
|
getEntry(path: IRepositoryPath, options?: IRepositoryOperationOptions): Promise<IRepositoryEntry | null>;
|
|
70
78
|
/**
|
|
@@ -78,6 +86,7 @@ export interface IRuntimeAdapterRepository {
|
|
|
78
86
|
* - INVALID_PAGE_REQUEST: The repository page request is invalid.
|
|
79
87
|
* - ACCESS_DENIED: Access to the repository source was denied.
|
|
80
88
|
* - SOURCE_UNAVAILABLE: The repository source is unavailable.
|
|
89
|
+
* - PROVIDER_INCOMPLETE: The repository provider cannot expose a complete result.
|
|
81
90
|
* - SNAPSHOT_CHANGED: The repository snapshot changed during the operation.
|
|
82
91
|
* - INVALID_SOURCE_DATA: The repository source returned invalid data.
|
|
83
92
|
* - RESOURCE_LIMIT_EXCEEDED: A named repository resource limit was exceeded.
|
|
@@ -96,6 +105,7 @@ export interface IRuntimeAdapterRepository {
|
|
|
96
105
|
* - INVALID_PAGE_REQUEST: The repository page request is invalid.
|
|
97
106
|
* - ACCESS_DENIED: Access to the repository source was denied.
|
|
98
107
|
* - SOURCE_UNAVAILABLE: The repository source is unavailable.
|
|
108
|
+
* - PROVIDER_INCOMPLETE: The repository provider cannot expose a complete result.
|
|
99
109
|
* - SNAPSHOT_CHANGED: The repository snapshot changed during the operation.
|
|
100
110
|
* - INVALID_SOURCE_DATA: The repository source returned invalid data.
|
|
101
111
|
* - RESOURCE_LIMIT_EXCEEDED: A named repository resource limit was exceeded.
|
|
@@ -128,4 +138,6 @@ export interface IRuntimeAdapterResult {
|
|
|
128
138
|
export type { IAdapterDiagnostic, IAdapterErrorDiagnostic, IAdapterWarningDiagnostic, IUnverifiedRelationship, IUnverifiedRelationshipDetails, } from '../diagnostics/index.js';
|
|
129
139
|
export type { IIndexedAgent, IIndexedContextAsset, IIndexedDecision, IIndexedDescriptionAsset, IIndexedManifest, IIndexedMirror, IIndexedRuntimeGuidance, IIndexedTextAsset, } from '../contracts/index.js';
|
|
130
140
|
export { iterateRuntimeAdapterEntries, readRuntimeAdapterFile, } from '../adapter-repository/index.js';
|
|
141
|
+
export type { IRuntimeAdapterOutputBudget, IRuntimeAdapterRecordCollector, IRuntimeAdapterResultCollector, } from '../adapter-result-collection/index.js';
|
|
142
|
+
export { createRuntimeAdapterResultCollector } from '../adapter-result-collection/index.js';
|
|
131
143
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,0BAA0B,EAC1B,2BAA2B,EAC3B,eAAe,EACf,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO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EACd,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AAGxC,YAAY,EACV,2BAA2B,EAC3B,8BAA8B,EAC9B,8BAA8B,GAC/B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,mCAAmC,EAAE,MAAM,uCAAuC,CAAC"}
|
|
@@ -15,17 +15,20 @@ export interface IRuntimeAdapterInspectionResult {
|
|
|
15
15
|
* @param signal Optional cancellation shared by the complete inspection.
|
|
16
16
|
* @returns A promise resolving to normalized evidence and adapter diagnostics.
|
|
17
17
|
* @throws
|
|
18
|
-
* - INVALID_REPOSITORY_PATH:
|
|
19
|
-
* - ENTRY_NOT_FOUND:
|
|
20
|
-
* - ENTRY_NOT_FILE:
|
|
21
|
-
* - ENTRY_NOT_DIRECTORY:
|
|
18
|
+
* - INVALID_REPOSITORY_PATH: The repository path is invalid.
|
|
19
|
+
* - ENTRY_NOT_FOUND: The requested repository entry was not found.
|
|
20
|
+
* - ENTRY_NOT_FILE: The requested repository entry is not a file.
|
|
21
|
+
* - ENTRY_NOT_DIRECTORY: The requested repository entry is not a directory.
|
|
22
22
|
* - ACCESS_DENIED: Access to the repository source was denied.
|
|
23
23
|
* - SOURCE_UNAVAILABLE: The repository source is unavailable.
|
|
24
|
-
* -
|
|
25
|
-
* -
|
|
26
|
-
* -
|
|
27
|
-
* -
|
|
28
|
-
* -
|
|
24
|
+
* - PROVIDER_INCOMPLETE: The repository provider cannot expose a complete result.
|
|
25
|
+
* - SNAPSHOT_CHANGED: The repository snapshot changed during the operation.
|
|
26
|
+
* - INVALID_SOURCE_DATA: The repository source returned invalid data.
|
|
27
|
+
* - RESOURCE_LIMIT_EXCEEDED: A named repository resource limit was exceeded.
|
|
28
|
+
* - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.
|
|
29
|
+
* - ABORTED: The repository operation was aborted.
|
|
30
|
+
* - ABORTED: The Core operation was aborted.
|
|
31
|
+
* - ADAPTER_EXECUTION_FAILED: A runtime adapter failed during inspection.
|
|
29
32
|
*/
|
|
30
33
|
export declare const inspectRuntimeAdapters: (project: IMoldeaProjectIndex, session: IRepositoryInspectionSession, options: ICoreOptionsSnapshot, signal?: AbortSignal) => Promise<IRuntimeAdapterInspectionResult>;
|
|
31
34
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter-execution/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,uBAAuB,EAGxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAiB,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter-execution/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,uBAAuB,EAGxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAiB,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAQhF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAIlE,OAAO,KAAK,EAAE,oBAAoB,EAA2B,MAAM,qBAAqB,CAAC;AAEzF,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AAG9F,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,QAAQ,EAAE,SAAS,uBAAuB,EAAE,CAAC;IACtD,QAAQ,CAAC,WAAW,EAAE,SAAS,kBAAkB,EAAE,CAAC;CACrD;AA2ID;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,mBAAmB,EAC5B,SAAS,4BAA4B,EACrC,SAAS,oBAAoB,EAC7B,SAAS,WAAW,KACnB,OAAO,CAAC,+BAA+B,CA6CzC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IRuntimeAdapterContext } from '../adapter/index.js';
|
|
2
|
+
import type { IRuntimeAdapterOutputCounts } from '../adapter-validation/index.js';
|
|
3
|
+
import type { ICoreResourceLimits } from '../contracts/index.js';
|
|
4
|
+
import type { IRuntimeAdapterOutputBudget, IRuntimeAdapterResultCollector } from './types.js';
|
|
5
|
+
/** Creates the immutable admission view from Core's authoritative raw counters. */
|
|
6
|
+
export declare const createRuntimeAdapterOutputBudget: (counts: IRuntimeAdapterOutputCounts, limits: ICoreResourceLimits) => IRuntimeAdapterOutputBudget;
|
|
7
|
+
/**
|
|
8
|
+
* Collects one adapter result without constructing records beyond its remaining allowance.
|
|
9
|
+
* @param context The trusted invocation agent, raw output budget, and operation signal.
|
|
10
|
+
* @returns Independent collectors and one final immutable adapter result.
|
|
11
|
+
*/
|
|
12
|
+
export declare const createRuntimeAdapterResultCollector: (context: Pick<IRuntimeAdapterContext, "agent" | "outputBudget" | "signal">) => IRuntimeAdapterResultCollector;
|
|
13
|
+
//# sourceMappingURL=collection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../src/adapter-result-collection/collection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EAGvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAIjE,OAAO,KAAK,EACV,2BAA2B,EAE3B,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AAEpB,mFAAmF;AACnF,eAAO,MAAM,gCAAgC,GAC3C,QAAQ,2BAA2B,EACnC,QAAQ,mBAAmB,KAC1B,2BAUC,CAAC;AAEL;;;;GAIG;AACH,eAAO,MAAM,mCAAmC,GAC9C,SAAS,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,cAAc,GAAG,QAAQ,CAAC,KACzE,8BAkDF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter-result-collection/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,2BAA2B,EAC3B,8BAA8B,EAC9B,8BAA8B,GAC/B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,gCAAgC,EAChC,mCAAmC,GACpC,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { IAdapterDiagnostic } from '../diagnostics/index.js';
|
|
2
|
+
import type { IRuntimeAdapterEvidence, IRuntimeAdapterResult } from '../adapter/index.js';
|
|
3
|
+
export interface IRuntimeAdapterOutputBudget {
|
|
4
|
+
readonly diagnostics: {
|
|
5
|
+
readonly maximum: number;
|
|
6
|
+
readonly remaining: number;
|
|
7
|
+
};
|
|
8
|
+
readonly evidence: {
|
|
9
|
+
readonly maximum: number;
|
|
10
|
+
readonly remaining: number;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface IRuntimeAdapterRecordCollector<TRecord> {
|
|
14
|
+
/**
|
|
15
|
+
* Admits one record before executing its factory.
|
|
16
|
+
* @param factory Constructs the record only after admission succeeds.
|
|
17
|
+
* @throws
|
|
18
|
+
* - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.
|
|
19
|
+
* - ABORTED: The Core operation was aborted.
|
|
20
|
+
*/
|
|
21
|
+
add(factory: () => TRecord): void;
|
|
22
|
+
/** Checks admitted records without exposing or copying the result collection. */
|
|
23
|
+
some(predicate: (record: TRecord) => boolean): boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface IRuntimeAdapterResultCollector {
|
|
26
|
+
readonly diagnostics: IRuntimeAdapterRecordCollector<IAdapterDiagnostic>;
|
|
27
|
+
readonly evidence: IRuntimeAdapterRecordCollector<IRuntimeAdapterEvidence>;
|
|
28
|
+
/** Returns the complete immutable result for Core's authoritative validation. */
|
|
29
|
+
finalize(): IRuntimeAdapterResult;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/adapter-result-collection/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG1F,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,WAAW,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/E,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7E;AAGD,MAAM,WAAW,8BAA8B,CAAC,OAAO;IACrD;;;;;;OAMG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,OAAO,GAAG,IAAI,CAAC;IAClC,iFAAiF;IACjF,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC;CACxD;AAGD,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,WAAW,EAAE,8BAA8B,CAAC,kBAAkB,CAAC,CAAC;IACzE,QAAQ,CAAC,QAAQ,EAAE,8BAA8B,CAAC,uBAAuB,CAAC,CAAC;IAE3E,iFAAiF;IACjF,QAAQ,IAAI,qBAAqB,CAAC;CACnC"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { i as reserveRuntimeAdapterRetainedBytesIfTracked, n as
|
|
1
|
+
import { i as reserveRuntimeAdapterRetainedBytesIfTracked, n as createRuntimeAdapterResultCollector } from "./chunks/collection-CvbjjLf2.js";
|
|
2
|
+
import { n as CoreOperationException } from "./chunks/exceptions-lzD3buFw.js";
|
|
2
3
|
import { REPOSITORY_ROOT, RepositorySourceException, compareRepositoryPaths, parseRepositoryPath } from "@moldea.ai/repository";
|
|
3
4
|
//#region src/adapter-repository/index.ts
|
|
4
5
|
var invalidSourceData = (operation, path) => {
|
|
@@ -110,6 +111,6 @@ var iterateRuntimeAdapterEntries = (repository, options) => {
|
|
|
110
111
|
} };
|
|
111
112
|
};
|
|
112
113
|
//#endregion
|
|
113
|
-
export { iterateRuntimeAdapterEntries, readRuntimeAdapterFile };
|
|
114
|
+
export { createRuntimeAdapterResultCollector, iterateRuntimeAdapterEntries, readRuntimeAdapterFile };
|
|
114
115
|
|
|
115
116
|
//# sourceMappingURL=adapter.js.map
|
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 { 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":"
|
|
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,IAAI,uBAAuB;EAC/B,MAAM;EACN;EACA;EACA,YAAY;EACZ;EACA,WAAW;CACb,CAAC;AACH;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,yBAAyB,OACpC,YACA,MACA,YACwB;CACxB,MAAM,aAAa,oBAAoB,IAAI;CAC3C,MAAM,QAAQ,MAAM,WAAW,SAAS,YAAY,OAAO;CAE3D,IAAI,UAAU,MACZ,MAAM,IAAI,0BAA0B;EAClC,MAAM;EACN,WAAW;EACX,MAAM;EACN,WAAW;CACb,CAAC;CAGH,IAAI,MAAM,SAAS,UAAU,MAAM,eAAe,MAChD,MAAM,IAAI,0BAA0B;EAClC,MAAM;EACN,WAAW;EACX,MAAM;EACN,WAAW;CACb,CAAC;CAGH,IAAI,MAAM,aAAa,WAAW,OAAO,cACvC,OAAO,2BACL,gBACA,WAAW,OAAO,cAClB,MAAM,UACR;CAGF,4CAA4C,YAAY,MAAM,UAAU;CACxE,MAAM,UAAU,IAAI,WAAW,MAAM,UAAU;CAC/C,IAAI,SAAS;CACb,IAAI,cAAc;CAElB,OAAO,eAAe,SAAS,MAAM,YAAY;EAC/C,cAAc;EACd,SAAS,QAAQ,eAAe;EAChC,MAAM,OAAO,MAAM,WAAW,aAAa,YAAY;GACrD,UAAU,KAAK,IAAI,WAAW,OAAO,cAAc,KAAK,IAAI,GAAG,MAAM,aAAa,MAAM,CAAC;GACzF;GACA,GAAI,SAAS,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,QAAQ,OAAO;EACpE,CAAC;EAED,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AM,IAAI,KAAK,GAC/E,OAAO,kBAAkB,qBAAqB,MAAM,IAAI;IAG1D,cAAc;IACd,IAAI,aAAa,WAAW,OAAO,YACjC,OAAO,2BACL,cACA,WAAW,OAAO,YAClB,UACF;IAGF,eAAe,MAAM;IACrB,MAAM;GACR;GAEA,IAAI,KAAK,YAAY;IACnB,IAAI,KAAK,eAAe,MACtB,OAAO,kBAAkB,qBAAqB,MAAM;IAGtD;GACF;GAEA,IAAI,KAAK,eAAe,QAAQ,KAAK,eAAe,QAClD,OAAO,kBAAkB,qBAAqB,MAAM;GAGtD,SAAS,KAAK;EAChB,SAAS;CACX,EACF;AACF"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { n as CoreOperationException } from "./chunks/exceptions-lzD3buFw.js";
|
|
2
|
+
import { n as normalizeCoreOptions } from "./chunks/options-CxCT3dZU.js";
|
|
3
|
+
import { a as encodeInspectionMessage, d as NODE_INSPECTION_TRANSPORT_BYTES, i as decodeInspectionMessage, n as serializeInspectionFailure, o as NODE_INSPECTION_FILE_PAGE_BYTES, r as createInspectionProcessFailure } from "./chunks/errors-BQI1DEqf.js";
|
|
4
|
+
import { i as parseRpcFilePage, n as parseRpcEntry, r as parseRpcEntryPage } from "./chunks/repository-rpc-BWi6X1la.js";
|
|
5
|
+
import { RepositorySourceException } from "@moldea.ai/repository";
|
|
6
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
7
|
+
import { getHeapStatistics } from "node:v8";
|
|
8
|
+
//#region src/node-inspection/analysis-worker.ts
|
|
9
|
+
var port = parentPort;
|
|
10
|
+
if (port === null) throw createInspectionProcessFailure();
|
|
11
|
+
var start = decodeInspectionMessage(workerData);
|
|
12
|
+
if (start.kind !== "start") throw createInspectionProcessFailure();
|
|
13
|
+
var attemptId = start.attemptId;
|
|
14
|
+
var maxAnalysisHeapBytes = getHeapStatistics().heap_size_limit;
|
|
15
|
+
var inspection;
|
|
16
|
+
var hasRun = false;
|
|
17
|
+
var isReadingPage = false;
|
|
18
|
+
var nextRequestId = 0;
|
|
19
|
+
var pending = /* @__PURE__ */ new Map();
|
|
20
|
+
var send = (message) => {
|
|
21
|
+
port.postMessage(encodeInspectionMessage(message));
|
|
22
|
+
};
|
|
23
|
+
/** Admits at most four requests across both bridges; no unbounded transport wait queue exists. */
|
|
24
|
+
var requestReader = (request) => {
|
|
25
|
+
if (pending.size >= 4) return Promise.reject(new CoreOperationException({
|
|
26
|
+
code: "RESOURCE_LIMIT_EXCEEDED",
|
|
27
|
+
operation: "create-project-inspection",
|
|
28
|
+
limit: "maxReaderRequests",
|
|
29
|
+
limitMaximum: 4,
|
|
30
|
+
observedUsage: pending.size + 1,
|
|
31
|
+
nextAction: null
|
|
32
|
+
}));
|
|
33
|
+
const requestId = nextRequestId++;
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
pending.set(requestId, {
|
|
36
|
+
resolve,
|
|
37
|
+
reject
|
|
38
|
+
});
|
|
39
|
+
try {
|
|
40
|
+
send({
|
|
41
|
+
attemptId,
|
|
42
|
+
kind: "reader-request",
|
|
43
|
+
requestId,
|
|
44
|
+
request
|
|
45
|
+
});
|
|
46
|
+
} catch (cause) {
|
|
47
|
+
pending.delete(requestId);
|
|
48
|
+
reject(cause instanceof Error ? cause : createInspectionProcessFailure(cause));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
var repository = {
|
|
53
|
+
snapshot: start.snapshot,
|
|
54
|
+
getEntry: async (path) => parseRpcEntry(await requestReader({
|
|
55
|
+
method: "getEntry",
|
|
56
|
+
path
|
|
57
|
+
})),
|
|
58
|
+
listEntriesPage: async (options) => parseRpcEntryPage(await requestReader({
|
|
59
|
+
method: "listEntriesPage",
|
|
60
|
+
maxEntries: Math.min(128, options.maxEntries),
|
|
61
|
+
...options.cursor === void 0 ? {} : { cursor: options.cursor },
|
|
62
|
+
...options.prefix === void 0 ? {} : { prefix: options.prefix }
|
|
63
|
+
})),
|
|
64
|
+
readFilePage: async (path, options) => parseRpcFilePage(await requestReader({
|
|
65
|
+
method: "readFilePage",
|
|
66
|
+
path,
|
|
67
|
+
offset: options.offset,
|
|
68
|
+
maxBytes: Math.min(NODE_INSPECTION_FILE_PAGE_BYTES, options.maxBytes)
|
|
69
|
+
})),
|
|
70
|
+
compare: () => Promise.reject(new RepositorySourceException({
|
|
71
|
+
code: "SOURCE_UNAVAILABLE",
|
|
72
|
+
operation: "create-comparison",
|
|
73
|
+
path: null,
|
|
74
|
+
retryable: false
|
|
75
|
+
}))
|
|
76
|
+
};
|
|
77
|
+
/** Imports only the caller-selected installed registry, after the parent acknowledges the heap. */
|
|
78
|
+
var prepare = async () => {
|
|
79
|
+
const registry = await import(start.registryUrl);
|
|
80
|
+
if (registry === null || typeof registry !== "object" || !("adapters" in registry) || !Array.isArray(registry.adapters)) throw createInspectionProcessFailure();
|
|
81
|
+
const adapters = registry.adapters;
|
|
82
|
+
const { createCore } = await import("./chunks/core-DchheNDz.js").then((n) => n.t);
|
|
83
|
+
const options = normalizeCoreOptions({
|
|
84
|
+
adapters,
|
|
85
|
+
limits: {
|
|
86
|
+
...start.limits,
|
|
87
|
+
maxRetainedBytes: start.limits.maxRetainedBytes - NODE_INSPECTION_TRANSPORT_BYTES
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
inspection = await createCore(options).createProjectInspection({ repository });
|
|
91
|
+
const metadata = {
|
|
92
|
+
source: inspection.source,
|
|
93
|
+
formatVersion: inspection.formatVersion,
|
|
94
|
+
valid: inspection.valid,
|
|
95
|
+
runtimeInspection: inspection.runtimeInspection,
|
|
96
|
+
counts: inspection.counts,
|
|
97
|
+
summary: inspection.summary,
|
|
98
|
+
resourceUsage: inspection.resourceUsage,
|
|
99
|
+
inspectionDigest: inspection.inspectionDigest
|
|
100
|
+
};
|
|
101
|
+
send({
|
|
102
|
+
attemptId,
|
|
103
|
+
kind: "prepared",
|
|
104
|
+
inspection: {
|
|
105
|
+
...metadata,
|
|
106
|
+
maxAnalysisHeapBytes,
|
|
107
|
+
adapters: options.adapters.map((adapter) => ({
|
|
108
|
+
id: adapter.id,
|
|
109
|
+
supportedRepositoryFormatVersions: [...adapter.supportedRepositoryFormatVersions]
|
|
110
|
+
})),
|
|
111
|
+
resourceUsage: {
|
|
112
|
+
...metadata.resourceUsage,
|
|
113
|
+
retainedBytes: metadata.resourceUsage.retainedBytes + NODE_INSPECTION_TRANSPORT_BYTES,
|
|
114
|
+
peakRetainedBytes: metadata.resourceUsage.peakRetainedBytes + NODE_INSPECTION_TRANSPORT_BYTES
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
/** Translates worker failures to safe package contracts while the supervisor stays responsive. */
|
|
120
|
+
var fail = (cause) => {
|
|
121
|
+
try {
|
|
122
|
+
const failure = serializeInspectionFailure(cause);
|
|
123
|
+
if (cause instanceof CoreOperationException && cause.code === "RESOURCE_LIMIT_EXCEEDED" && cause.limit === "maxRetainedBytes" && cause.observedUsage !== null) {
|
|
124
|
+
failure.options["limitMaximum"] = start.limits.maxRetainedBytes;
|
|
125
|
+
failure.options["observedUsage"] = cause.observedUsage + NODE_INSPECTION_TRANSPORT_BYTES;
|
|
126
|
+
}
|
|
127
|
+
send({
|
|
128
|
+
attemptId,
|
|
129
|
+
kind: "failure",
|
|
130
|
+
failure
|
|
131
|
+
});
|
|
132
|
+
} catch {
|
|
133
|
+
port.close();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
port.on("message", (frame) => {
|
|
137
|
+
try {
|
|
138
|
+
const message = decodeInspectionMessage(frame);
|
|
139
|
+
if (message.attemptId !== attemptId) throw createInspectionProcessFailure();
|
|
140
|
+
if (message.kind === "run") {
|
|
141
|
+
if (hasRun) throw createInspectionProcessFailure();
|
|
142
|
+
hasRun = true;
|
|
143
|
+
prepare().catch(fail);
|
|
144
|
+
} else if (message.kind === "reader-response") {
|
|
145
|
+
const request = pending.get(message.requestId);
|
|
146
|
+
if (request === void 0) throw createInspectionProcessFailure();
|
|
147
|
+
pending.delete(message.requestId);
|
|
148
|
+
request.resolve(message.result);
|
|
149
|
+
} else if (message.kind === "read-page") {
|
|
150
|
+
if (inspection === void 0 || isReadingPage) throw createInspectionProcessFailure();
|
|
151
|
+
isReadingPage = true;
|
|
152
|
+
try {
|
|
153
|
+
if (message.input.maxItems > start.limits.maxEntries) throw new CoreOperationException({
|
|
154
|
+
code: "INVALID_ARGUMENT",
|
|
155
|
+
operation: "create-project-inspection"
|
|
156
|
+
});
|
|
157
|
+
let maxItems = Math.min(256, message.input.maxItems);
|
|
158
|
+
while (true) try {
|
|
159
|
+
const frame = encodeInspectionMessage({
|
|
160
|
+
attemptId,
|
|
161
|
+
kind: "page",
|
|
162
|
+
requestId: message.requestId,
|
|
163
|
+
result: inspection.readPage({
|
|
164
|
+
...message.input,
|
|
165
|
+
maxItems
|
|
166
|
+
})
|
|
167
|
+
});
|
|
168
|
+
port.postMessage(frame);
|
|
169
|
+
break;
|
|
170
|
+
} catch (cause) {
|
|
171
|
+
if (!(cause instanceof CoreOperationException) || cause.code !== "RESOURCE_LIMIT_EXCEEDED" || cause.limit !== "maxInspectionMessageBytes" || maxItems === 1) throw cause;
|
|
172
|
+
maxItems = Math.max(1, Math.floor(maxItems / 2));
|
|
173
|
+
}
|
|
174
|
+
} finally {
|
|
175
|
+
isReadingPage = false;
|
|
176
|
+
}
|
|
177
|
+
} else throw createInspectionProcessFailure();
|
|
178
|
+
} catch (cause) {
|
|
179
|
+
fail(cause);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
port.on("messageerror", fail);
|
|
183
|
+
send({
|
|
184
|
+
attemptId,
|
|
185
|
+
kind: "ready",
|
|
186
|
+
maxAnalysisHeapBytes
|
|
187
|
+
});
|
|
188
|
+
//#endregion
|
|
189
|
+
|
|
190
|
+
//# sourceMappingURL=analysis-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analysis-worker.js","names":[],"sources":["../src/node-inspection/analysis-worker.ts"],"sourcesContent":["import { getHeapStatistics } from 'node:v8';\nimport { parentPort, workerData } from 'node:worker_threads';\n\nimport { RepositorySourceException, type IRepositoryReader } from '@moldea.ai/repository';\n\nimport type { IRuntimeAdapter } from '../adapter/index.js';\nimport type { IProjectInspection } from '../contracts/index.js';\nimport { CoreOperationException } from '../exceptions/index.js';\nimport { normalizeCoreOptions } from '../options/index.js';\n\nimport {\n NODE_INSPECTION_FILE_PAGE_BYTES,\n NODE_INSPECTION_MAX_REQUESTS,\n NODE_INSPECTION_TRANSPORT_BYTES,\n} from './constants.js';\nimport { serializeInspectionFailure } from './errors.js';\nimport {\n createInspectionProcessFailure,\n decodeInspectionMessage,\n encodeInspectionMessage,\n} from './protocol.js';\nimport { parseRpcEntry, parseRpcEntryPage, parseRpcFilePage } from './repository-rpc.js';\nimport type { INodeInspectionMessage, INodeReaderRequest } from './types.js';\n\nconst port = parentPort;\nif (port === null) throw createInspectionProcessFailure();\nconst start = decodeInspectionMessage(workerData);\nif (start.kind !== 'start') throw createInspectionProcessFailure();\nconst attemptId = start.attemptId;\nconst maxAnalysisHeapBytes = getHeapStatistics().heap_size_limit;\nlet inspection: IProjectInspection | undefined;\nlet hasRun = false;\nlet isReadingPage = false;\nlet nextRequestId = 0;\nconst pending = new Map<\n number,\n { resolve: (result: unknown) => void; reject: (cause: unknown) => void }\n>();\nconst send = (message: INodeInspectionMessage): void => {\n port.postMessage(encodeInspectionMessage(message));\n};\n\n/** Admits at most four requests across both bridges; no unbounded transport wait queue exists. */\nconst requestReader = (request: INodeReaderRequest): Promise<unknown> => {\n if (pending.size >= NODE_INSPECTION_MAX_REQUESTS)\n return Promise.reject(\n new CoreOperationException({\n code: 'RESOURCE_LIMIT_EXCEEDED',\n operation: 'create-project-inspection',\n limit: 'maxReaderRequests',\n limitMaximum: NODE_INSPECTION_MAX_REQUESTS,\n observedUsage: pending.size + 1,\n nextAction: null,\n }),\n );\n const requestId = nextRequestId++;\n return new Promise<unknown>((resolve, reject) => {\n pending.set(requestId, { resolve, reject });\n try {\n send({ attemptId, kind: 'reader-request', requestId, request });\n } catch (cause) {\n pending.delete(requestId);\n reject(cause instanceof Error ? cause : createInspectionProcessFailure(cause));\n }\n });\n};\n\nconst repository: IRepositoryReader = {\n snapshot: start.snapshot,\n getEntry: async (path) => parseRpcEntry(await requestReader({ method: 'getEntry', path })),\n listEntriesPage: async (options) =>\n parseRpcEntryPage(\n await requestReader({\n method: 'listEntriesPage',\n maxEntries: Math.min(128, options.maxEntries),\n ...(options.cursor === undefined ? {} : { cursor: options.cursor }),\n ...(options.prefix === undefined ? {} : { prefix: options.prefix }),\n }),\n ),\n readFilePage: async (path, options) =>\n parseRpcFilePage(\n await requestReader({\n method: 'readFilePage',\n path,\n offset: options.offset,\n maxBytes: Math.min(NODE_INSPECTION_FILE_PAGE_BYTES, options.maxBytes),\n }),\n ),\n compare: () =>\n Promise.reject(\n new RepositorySourceException({\n code: 'SOURCE_UNAVAILABLE',\n operation: 'create-comparison',\n path: null,\n retryable: false,\n }),\n ),\n};\n\n/** Imports only the caller-selected installed registry, after the parent acknowledges the heap. */\nconst prepare = async (): Promise<void> => {\n const registry: unknown = await import(start.registryUrl);\n if (\n registry === null ||\n typeof registry !== 'object' ||\n !('adapters' in registry) ||\n !Array.isArray(registry.adapters)\n )\n throw createInspectionProcessFailure();\n // Core remains the authoritative validator for every executable adapter definition.\n const adapters = registry.adapters as IRuntimeAdapter[];\n const { createCore } = await import('../core/index.js');\n const options = normalizeCoreOptions({\n adapters,\n limits: {\n ...start.limits,\n maxRetainedBytes: start.limits.maxRetainedBytes - NODE_INSPECTION_TRANSPORT_BYTES,\n },\n });\n const core = createCore(options);\n inspection = await core.createProjectInspection({ repository });\n const metadata = {\n source: inspection.source,\n formatVersion: inspection.formatVersion,\n valid: inspection.valid,\n runtimeInspection: inspection.runtimeInspection,\n counts: inspection.counts,\n summary: inspection.summary,\n resourceUsage: inspection.resourceUsage,\n inspectionDigest: inspection.inspectionDigest,\n };\n send({\n attemptId,\n kind: 'prepared',\n inspection: {\n ...metadata,\n maxAnalysisHeapBytes,\n adapters: options.adapters.map((adapter) => ({\n id: adapter.id,\n supportedRepositoryFormatVersions: [...adapter.supportedRepositoryFormatVersions],\n })),\n resourceUsage: {\n ...metadata.resourceUsage,\n retainedBytes: metadata.resourceUsage.retainedBytes + NODE_INSPECTION_TRANSPORT_BYTES,\n peakRetainedBytes:\n metadata.resourceUsage.peakRetainedBytes + NODE_INSPECTION_TRANSPORT_BYTES,\n },\n },\n });\n};\n\n/** Translates worker failures to safe package contracts while the supervisor stays responsive. */\nconst fail = (cause: unknown): void => {\n try {\n const failure = serializeInspectionFailure(cause);\n if (\n cause instanceof CoreOperationException &&\n cause.code === 'RESOURCE_LIMIT_EXCEEDED' &&\n cause.limit === 'maxRetainedBytes' &&\n cause.observedUsage !== null\n ) {\n failure.options['limitMaximum'] = start.limits.maxRetainedBytes;\n failure.options['observedUsage'] = cause.observedUsage + NODE_INSPECTION_TRANSPORT_BYTES;\n }\n send({ attemptId, kind: 'failure', failure });\n } catch {\n port.close();\n }\n};\n\nport.on('message', (frame: unknown) => {\n try {\n const message = decodeInspectionMessage(frame);\n if (message.attemptId !== attemptId) throw createInspectionProcessFailure();\n if (message.kind === 'run') {\n if (hasRun) throw createInspectionProcessFailure();\n hasRun = true;\n void prepare().catch(fail);\n } else if (message.kind === 'reader-response') {\n const request = pending.get(message.requestId);\n if (request === undefined) throw createInspectionProcessFailure();\n pending.delete(message.requestId);\n request.resolve(message.result);\n } else if (message.kind === 'read-page') {\n if (inspection === undefined || isReadingPage) throw createInspectionProcessFailure();\n isReadingPage = true;\n try {\n if (message.input.maxItems > start.limits.maxEntries)\n throw new CoreOperationException({\n code: 'INVALID_ARGUMENT',\n operation: 'create-project-inspection',\n });\n let maxItems = Math.min(256, message.input.maxItems);\n while (true) {\n try {\n const frame = encodeInspectionMessage({\n attemptId,\n kind: 'page',\n requestId: message.requestId,\n result: inspection.readPage({ ...message.input, maxItems }),\n });\n port.postMessage(frame);\n break;\n } catch (cause) {\n if (\n !(cause instanceof CoreOperationException) ||\n cause.code !== 'RESOURCE_LIMIT_EXCEEDED' ||\n cause.limit !== 'maxInspectionMessageBytes' ||\n maxItems === 1\n )\n throw cause;\n maxItems = Math.max(1, Math.floor(maxItems / 2));\n }\n }\n } finally {\n isReadingPage = false;\n }\n } else throw createInspectionProcessFailure();\n } catch (cause) {\n fail(cause);\n }\n});\nport.on('messageerror', fail);\nsend({ attemptId, kind: 'ready', maxAnalysisHeapBytes });\n"],"mappings":";;;;;;;;AAwBA,IAAM,OAAO;AACb,IAAI,SAAS,MAAM,MAAM,+BAA+B;AACxD,IAAM,QAAQ,wBAAwB,UAAU;AAChD,IAAI,MAAM,SAAS,SAAS,MAAM,+BAA+B;AACjE,IAAM,YAAY,MAAM;AACxB,IAAM,uBAAuB,kBAAkB,CAAC,CAAC;AACjD,IAAI;AACJ,IAAI,SAAS;AACb,IAAI,gBAAgB;AACpB,IAAI,gBAAgB;AACpB,IAAM,0BAAU,IAAI,IAGlB;AACF,IAAM,QAAQ,YAA0C;CACtD,KAAK,YAAY,wBAAwB,OAAO,CAAC;AACnD;;AAGA,IAAM,iBAAiB,YAAkD;CACvE,IAAI,QAAQ,QAAA,GACV,OAAO,QAAQ,OACb,IAAI,uBAAuB;EACzB,MAAM;EACN,WAAW;EACX,OAAO;EACP,cAAA;EACA,eAAe,QAAQ,OAAO;EAC9B,YAAY;CACd,CAAC,CACH;CACF,MAAM,YAAY;CAClB,OAAO,IAAI,SAAkB,SAAS,WAAW;EAC/C,QAAQ,IAAI,WAAW;GAAE;GAAS;EAAO,CAAC;EAC1C,IAAI;GACF,KAAK;IAAE;IAAW,MAAM;IAAkB;IAAW;GAAQ,CAAC;EAChE,SAAS,OAAO;GACd,QAAQ,OAAO,SAAS;GACxB,OAAO,iBAAiB,QAAQ,QAAQ,+BAA+B,KAAK,CAAC;EAC/E;CACF,CAAC;AACH;AAEA,IAAM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,OAAO,YACxC,MAAM,IAAI,uBAAuB;KAC/B,MAAM;KACN,WAAW;IACb,CAAC;IACH,IAAI,WAAW,KAAK,IAAI,KAAK,QAAQ,MAAM,QAAQ;IACnD,OAAO,MACL,IAAI;KACF,MAAM,QAAQ,wBAAwB;MACpC;MACA,MAAM;MACN,WAAW,QAAQ;MACnB,QAAQ,WAAW,SAAS;OAAE,GAAG,QAAQ;OAAO;MAAS,CAAC;KAC5D,CAAC;KACD,KAAK,YAAY,KAAK;KACtB;IACF,SAAS,OAAO;KACd,IACE,EAAE,iBAAiB,2BACnB,MAAM,SAAS,6BACf,MAAM,UAAU,+BAChB,aAAa,GAEb,MAAM;KACR,WAAW,KAAK,IAAI,GAAG,KAAK,MAAM,WAAW,CAAC,CAAC;IACjD;GAEJ,UAAU;IACR,gBAAgB;GAClB;EACF,OAAO,MAAM,+BAA+B;CAC9C,SAAS,OAAO;EACd,KAAK,KAAK;CACZ;AACF,CAAC;AACD,KAAK,GAAG,gBAAgB,IAAI;AAC5B,KAAK;CAAE;CAAW,MAAM;CAAS;AAAqB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { n as CoreOperationException } from "./exceptions-lzD3buFw.js";
|
|
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
|
+
//#region src/adapter-result-collection/collection.ts
|
|
16
|
+
/** Creates the immutable admission view from Core's authoritative raw counters. */
|
|
17
|
+
var createRuntimeAdapterOutputBudget = (counts, limits) => Object.freeze({
|
|
18
|
+
diagnostics: Object.freeze({
|
|
19
|
+
maximum: limits.maxDiagnostics,
|
|
20
|
+
remaining: limits.maxDiagnostics - counts.diagnostics
|
|
21
|
+
}),
|
|
22
|
+
evidence: Object.freeze({
|
|
23
|
+
maximum: limits.maxEvidence,
|
|
24
|
+
remaining: limits.maxEvidence - counts.evidence
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Collects one adapter result without constructing records beyond its remaining allowance.
|
|
29
|
+
* @param context The trusted invocation agent, raw output budget, and operation signal.
|
|
30
|
+
* @returns Independent collectors and one final immutable adapter result.
|
|
31
|
+
*/
|
|
32
|
+
var createRuntimeAdapterResultCollector = (context) => {
|
|
33
|
+
const diagnostics = [];
|
|
34
|
+
const evidence = [];
|
|
35
|
+
const createCollector = (kind, records) => {
|
|
36
|
+
const { maximum, remaining } = context.outputBudget[kind];
|
|
37
|
+
let admitted = 0;
|
|
38
|
+
return Object.freeze({
|
|
39
|
+
some: (predicate) => records.some(predicate),
|
|
40
|
+
add: (factory) => {
|
|
41
|
+
if (context.signal?.aborted) throw new CoreOperationException({
|
|
42
|
+
adapterId: context.agent.declaration.runtime.id,
|
|
43
|
+
cause: context.signal.reason,
|
|
44
|
+
code: "ABORTED",
|
|
45
|
+
operation: "validate-adapter"
|
|
46
|
+
});
|
|
47
|
+
if (admitted >= remaining) throw new CoreOperationException({
|
|
48
|
+
adapterId: context.agent.declaration.runtime.id,
|
|
49
|
+
code: "RESOURCE_LIMIT_EXCEEDED",
|
|
50
|
+
limit: kind === "diagnostics" ? "maxDiagnostics" : "maxEvidence",
|
|
51
|
+
limitMaximum: maximum,
|
|
52
|
+
nextAction: "reduce-input-or-increase-limit",
|
|
53
|
+
observedUsage: maximum - remaining + admitted + 1,
|
|
54
|
+
operation: "validate-adapter"
|
|
55
|
+
});
|
|
56
|
+
admitted += 1;
|
|
57
|
+
records.push(factory());
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
return Object.freeze({
|
|
62
|
+
diagnostics: createCollector("diagnostics", diagnostics),
|
|
63
|
+
evidence: createCollector("evidence", evidence),
|
|
64
|
+
finalize: () => Object.freeze({
|
|
65
|
+
diagnostics: Object.freeze(diagnostics),
|
|
66
|
+
evidence: Object.freeze(evidence)
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
export { reserveRuntimeAdapterRetainedBytesIfTracked as i, createRuntimeAdapterResultCollector as n, registerRuntimeAdapterRetainedByteReservation as r, createRuntimeAdapterOutputBudget as t };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=collection-CvbjjLf2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection-CvbjjLf2.js","names":[],"sources":["../../src/adapter-retained-memory/index.ts","../../src/adapter-result-collection/collection.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 type {\n IRuntimeAdapterContext,\n IRuntimeAdapterEvidence,\n IRuntimeAdapterResult,\n} from '../adapter/index.js';\nimport type { IRuntimeAdapterOutputCounts } from '../adapter-validation/index.js';\nimport type { ICoreResourceLimits } from '../contracts/index.js';\nimport type { IAdapterDiagnostic } from '../diagnostics/index.js';\nimport { CoreOperationException } from '../exceptions/index.js';\n\nimport type {\n IRuntimeAdapterOutputBudget,\n IRuntimeAdapterRecordCollector,\n IRuntimeAdapterResultCollector,\n} from './types.js';\n\n/** Creates the immutable admission view from Core's authoritative raw counters. */\nexport const createRuntimeAdapterOutputBudget = (\n counts: IRuntimeAdapterOutputCounts,\n limits: ICoreResourceLimits,\n): IRuntimeAdapterOutputBudget =>\n Object.freeze({\n diagnostics: Object.freeze({\n maximum: limits.maxDiagnostics,\n remaining: limits.maxDiagnostics - counts.diagnostics,\n }),\n evidence: Object.freeze({\n maximum: limits.maxEvidence,\n remaining: limits.maxEvidence - counts.evidence,\n }),\n });\n\n/**\n * Collects one adapter result without constructing records beyond its remaining allowance.\n * @param context The trusted invocation agent, raw output budget, and operation signal.\n * @returns Independent collectors and one final immutable adapter result.\n */\nexport const createRuntimeAdapterResultCollector = (\n context: Pick<IRuntimeAdapterContext, 'agent' | 'outputBudget' | 'signal'>,\n): IRuntimeAdapterResultCollector => {\n const diagnostics: IAdapterDiagnostic[] = [];\n const evidence: IRuntimeAdapterEvidence[] = [];\n\n const createCollector = <TRecord>(\n kind: keyof IRuntimeAdapterOutputBudget,\n records: TRecord[],\n ): IRuntimeAdapterRecordCollector<TRecord> => {\n const { maximum, remaining } = context.outputBudget[kind];\n let admitted = 0;\n\n return Object.freeze({\n some: (predicate: (record: TRecord) => boolean): boolean => records.some(predicate),\n add: (factory: () => TRecord): void => {\n if (context.signal?.aborted) {\n throw new CoreOperationException({\n adapterId: context.agent.declaration.runtime.id,\n cause: context.signal.reason,\n code: 'ABORTED',\n operation: 'validate-adapter',\n });\n }\n\n if (admitted >= remaining) {\n throw new CoreOperationException({\n adapterId: context.agent.declaration.runtime.id,\n code: 'RESOURCE_LIMIT_EXCEEDED',\n limit: kind === 'diagnostics' ? 'maxDiagnostics' : 'maxEvidence',\n limitMaximum: maximum,\n nextAction: 'reduce-input-or-increase-limit',\n observedUsage: maximum - remaining + admitted + 1,\n operation: 'validate-adapter',\n });\n }\n\n admitted += 1;\n records.push(factory());\n },\n });\n };\n\n return Object.freeze({\n diagnostics: createCollector('diagnostics', diagnostics),\n evidence: createCollector('evidence', evidence),\n finalize: (): IRuntimeAdapterResult =>\n Object.freeze({\n diagnostics: Object.freeze(diagnostics),\n evidence: Object.freeze(evidence),\n }),\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,KAAA,GACd,QAAQ,UAAU;AAEtB;;;;ACXA,IAAa,oCACX,QACA,WAEA,OAAO,OAAO;CACZ,aAAa,OAAO,OAAO;EACzB,SAAS,OAAO;EAChB,WAAW,OAAO,iBAAiB,OAAO;CAC5C,CAAC;CACD,UAAU,OAAO,OAAO;EACtB,SAAS,OAAO;EAChB,WAAW,OAAO,cAAc,OAAO;CACzC,CAAC;AACH,CAAC;;;;;;AAOH,IAAa,uCACX,YACmC;CACnC,MAAM,cAAoC,CAAC;CAC3C,MAAM,WAAsC,CAAC;CAE7C,MAAM,mBACJ,MACA,YAC4C;EAC5C,MAAM,EAAE,SAAS,cAAc,QAAQ,aAAa;EACpD,IAAI,WAAW;EAEf,OAAO,OAAO,OAAO;GACnB,OAAO,cAAqD,QAAQ,KAAK,SAAS;GAClF,MAAM,YAAiC;IACrC,IAAI,QAAQ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