halfcode-compiler.xnl 0.2.1 → 0.2.2

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.
@@ -1,2 +1,432 @@
1
- import { n as loadResourceTree, r as validateResourceTree, t as ResourceValidationError } from "./src-DKkIFGWH.js";
2
- export { ResourceValidationError, loadResourceTree, validateResourceTree };
1
+ import { a as isLoadedResourceTreeAuthentic, c as sha256Digest, d as markEffectiveRegistryAuthentic, f as ResourceCompositionError, i as readonlyMap, l as effectiveRegistryLayerBindings, m as digestCanonical, n as loadResourceTree, o as buildResourceDependencySnapshot, p as compareCodeUnits, r as validateResourceTree, s as createResourceContentIdentity, t as ResourceValidationError, u as isEffectiveRegistryAuthentic } from "./src-DCRih45n.js";
2
+ //#region ../resource-core/src/layered-registry.ts
3
+ function composeLayeredResourceRegistry(input) {
4
+ const diagnostics = [];
5
+ const layerIds = /* @__PURE__ */ new Set();
6
+ const layers = [];
7
+ const entries = /* @__PURE__ */ new Map();
8
+ const kindDefinitions = /* @__PURE__ */ new Map();
9
+ input.layers.forEach((layer, layerIndex) => {
10
+ const layerId = layer.id.trim();
11
+ const packageId = layer.tree.manifest.resourceId;
12
+ if (layerId.length === 0) {
13
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_ID_EMPTY", layerLocation$1(layerIndex), "Resource layer id must be a non-empty explicit value."));
14
+ return;
15
+ }
16
+ if (layerIds.has(layerId)) {
17
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_ID_DUPLICATE", layerLocation$1(layerIndex, layerId), `Resource layer id '${layerId}' is declared more than once.`));
18
+ return;
19
+ }
20
+ layerIds.add(layerId);
21
+ layers.push(Object.freeze({
22
+ id: layerId,
23
+ index: layerIndex,
24
+ packageId
25
+ }));
26
+ mergeKindDefinitions(layer.tree, layerId, layerIndex, packageId, kindDefinitions, diagnostics);
27
+ mergeResources(layer.tree, layerId, layerIndex, packageId, entries, diagnostics);
28
+ applyTombstones(layer, layerId, layerIndex, packageId, entries, diagnostics);
29
+ });
30
+ if (diagnostics.length > 0) throw new ResourceCompositionError(stableDiagnostics$1(diagnostics));
31
+ const frozenEntries = [...entries.values()].sort((left, right) => compareCodeUnits(left.resourceId, right.resourceId)).map((entry) => freezeEntry(entry));
32
+ const byId = readonlyMap(frozenEntries.map((entry) => [entry.resourceId, entry]));
33
+ const byKindValues = /* @__PURE__ */ new Map();
34
+ for (const entry of frozenEntries) {
35
+ if (!entry.resource) continue;
36
+ const records = byKindValues.get(entry.kind) ?? [];
37
+ records.push(entry.resource);
38
+ byKindValues.set(entry.kind, records);
39
+ }
40
+ const byKind = readonlyMap([...byKindValues.entries()].sort(([left], [right]) => compareCodeUnits(left, right)).map(([kind, records]) => [kind, Object.freeze([...records].sort((left, right) => compareCodeUnits(left.resourceId, right.resourceId)))]));
41
+ const frozenDefinitions = [...kindDefinitions.entries()].sort(([left], [right]) => compareCodeUnits(left, right)).map(([kind, value]) => [kind, Object.freeze({
42
+ definition: value.definition,
43
+ origins: Object.freeze([...value.origins].sort(compareOrigins))
44
+ })]);
45
+ const publicKindDefinitions = readonlyMap(frozenDefinitions);
46
+ const frozenLayers = Object.freeze([...layers]);
47
+ const compositionRevision = digestCanonical({
48
+ layers: frozenLayers.map((layer) => ({
49
+ id: layer.id,
50
+ index: layer.index,
51
+ packageId: layer.packageId
52
+ })),
53
+ entries: frozenEntries.map(entryRevisionFact),
54
+ kindDefinitions: frozenDefinitions.map(([kind, value]) => ({
55
+ kind,
56
+ definitionResourceId: value.definition.resourceId,
57
+ contract: normalizedKindContract(value.definition),
58
+ origins: value.origins.map(stableOriginFact)
59
+ }))
60
+ });
61
+ return markEffectiveRegistryAuthentic(Object.freeze({
62
+ byId,
63
+ byKind,
64
+ kindDefinitions: publicKindDefinitions,
65
+ layers: frozenLayers,
66
+ compositionRevision,
67
+ revision: compositionRevision
68
+ }), frozenLayers.map((layer) => ({
69
+ id: layer.id,
70
+ tree: input.layers[layer.index].tree
71
+ })));
72
+ }
73
+ function mergeKindDefinitions(tree, layerId, layerIndex, packageId, definitions, diagnostics) {
74
+ for (const [kind, inputDefinition] of [...tree.registry.kindDefinitions.entries()].sort(([left], [right]) => compareCodeUnits(left, right))) {
75
+ if (!isCanonicalVfsDocumentUri(inputDefinition.documentUri)) {
76
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_PROVENANCE_INVALID", layerLocation$1(layerIndex, layerId, kind), `Resource kind '${kind}' must use canonical VFS document provenance.`));
77
+ continue;
78
+ }
79
+ const definition = cloneRegisteredKindDefinition(inputDefinition);
80
+ const origin = kindDefinitionOrigin(layerId, layerIndex, packageId, definition);
81
+ const current = definitions.get(kind);
82
+ if (!current) {
83
+ definitions.set(kind, {
84
+ definition,
85
+ origins: [origin]
86
+ });
87
+ continue;
88
+ }
89
+ if (JSON.stringify(normalizedKindContract(current.definition)) !== JSON.stringify(normalizedKindContract(definition))) {
90
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_KIND_DEFINITION_CONFLICT", layerLocation$1(layerIndex, layerId, kind), `Resource kind '${kind}' has incompatible KindDefinition contracts across layers.`));
91
+ continue;
92
+ }
93
+ current.origins.push(origin);
94
+ }
95
+ }
96
+ function mergeResources(tree, layerId, layerIndex, packageId, entries, diagnostics) {
97
+ const records = [...tree.registry.byKind.values()].flatMap((values) => [...values]).sort((left, right) => compareCodeUnits(left.resourceId, right.resourceId) || compareCodeUnits(left.kind, right.kind));
98
+ const seenInLayer = /* @__PURE__ */ new Set();
99
+ for (const resource of records) {
100
+ if (seenInLayer.has(resource.resourceId)) {
101
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_RESOURCE_DUPLICATE", layerLocation$1(layerIndex, layerId, resource.resourceId), `Resource '${resource.resourceId}' occurs more than once in layer '${layerId}'.`));
102
+ continue;
103
+ }
104
+ seenInLayer.add(resource.resourceId);
105
+ if (!isSafeLogicalPath(resource.logicalPath) || resource.documentUri !== `vfs://@/${resource.logicalPath}`) {
106
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_PROVENANCE_INVALID", layerLocation$1(layerIndex, layerId, resource.resourceId), `Resource '${resource.resourceId}' must use matching canonical VFS documentUri and safe logicalPath provenance.`));
107
+ continue;
108
+ }
109
+ const immutableResource = cloneResourceRecord(resource);
110
+ const origin = resourceOrigin(layerId, layerIndex, packageId, immutableResource);
111
+ const current = entries.get(resource.resourceId);
112
+ if (!current) {
113
+ entries.set(resource.resourceId, {
114
+ resourceId: resource.resourceId,
115
+ kind: resource.kind,
116
+ resource: immutableResource,
117
+ effectiveLayerId: layerId,
118
+ effectiveOrigin: origin,
119
+ shadowed: [],
120
+ tombstones: []
121
+ });
122
+ continue;
123
+ }
124
+ if (current.kind !== resource.kind) {
125
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_IDENTITY_KIND_CONFLICT", layerLocation$1(layerIndex, layerId, resource.resourceId), `Resource '${resource.resourceId}' changes kind from '${current.kind}' to '${resource.kind}' across layers.`));
126
+ continue;
127
+ }
128
+ if (current.effectiveOrigin) current.shadowed.push(current.effectiveOrigin);
129
+ current.resource = immutableResource;
130
+ current.effectiveLayerId = layerId;
131
+ current.effectiveOrigin = origin;
132
+ current.tombstone = void 0;
133
+ }
134
+ }
135
+ function applyTombstones(layer, layerId, layerIndex, packageId, entries, diagnostics) {
136
+ const tombstones = [...layer.tombstones ?? []].sort((left, right) => compareCodeUnits(left.resourceId, right.resourceId));
137
+ const seen = /* @__PURE__ */ new Set();
138
+ for (const tombstone of tombstones) {
139
+ const resourceId = tombstone.resourceId.trim();
140
+ if (resourceId.length === 0) {
141
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_TOMBSTONE_ID_EMPTY", layerLocation$1(layerIndex, layerId), "Resource tombstone target must be a non-empty resource id."));
142
+ continue;
143
+ }
144
+ if (seen.has(resourceId)) {
145
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_TOMBSTONE_DUPLICATE", layerLocation$1(layerIndex, layerId, resourceId), `Resource '${resourceId}' has more than one tombstone in layer '${layerId}'.`));
146
+ continue;
147
+ }
148
+ seen.add(resourceId);
149
+ const current = entries.get(resourceId);
150
+ if (!current) {
151
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_TOMBSTONE_TARGET_MISSING", layerLocation$1(layerIndex, layerId, resourceId), `Tombstone target '${resourceId}' does not exist in a lower or current layer.`));
152
+ continue;
153
+ }
154
+ if (current.effectiveLayerId === layerId) {
155
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_TOMBSTONE_RESOURCE_CONFLICT", layerLocation$1(layerIndex, layerId, resourceId), `Resource '${resourceId}' cannot be both effective and tombstoned in layer '${layerId}'.`));
156
+ continue;
157
+ }
158
+ if (tombstone.expectedKind !== void 0 && tombstone.expectedKind !== current.kind) {
159
+ diagnostics.push(diagnostic$1("RESOURCE_LAYER_TOMBSTONE_KIND_MISMATCH", layerLocation$1(layerIndex, layerId, resourceId), `Tombstone for '${resourceId}' expects kind '${tombstone.expectedKind}', but the target kind is '${current.kind}'.`));
160
+ continue;
161
+ }
162
+ const origin = Object.freeze({
163
+ resourceId,
164
+ ...tombstone.expectedKind === void 0 ? {} : { expectedKind: tombstone.expectedKind },
165
+ ...tombstone.reason === void 0 ? {} : { reason: tombstone.reason },
166
+ layerId,
167
+ layerIndex,
168
+ packageId
169
+ });
170
+ if (current.effectiveOrigin) current.shadowed.push(current.effectiveOrigin);
171
+ current.resource = void 0;
172
+ current.effectiveLayerId = void 0;
173
+ current.effectiveOrigin = void 0;
174
+ current.tombstone = origin;
175
+ current.tombstones.push(origin);
176
+ }
177
+ }
178
+ function resourceOrigin(layerId, layerIndex, packageId, resource) {
179
+ return Object.freeze({
180
+ layerId,
181
+ layerIndex,
182
+ packageId,
183
+ documentUri: resource.documentUri,
184
+ logicalPath: resource.logicalPath
185
+ });
186
+ }
187
+ function kindDefinitionOrigin(layerId, layerIndex, packageId, definition) {
188
+ return Object.freeze({
189
+ layerId,
190
+ layerIndex,
191
+ packageId,
192
+ documentUri: definition.documentUri
193
+ });
194
+ }
195
+ function freezeEntry(entry) {
196
+ return Object.freeze({
197
+ resourceId: entry.resourceId,
198
+ kind: entry.kind,
199
+ ...entry.resource === void 0 ? {} : { resource: entry.resource },
200
+ ...entry.effectiveLayerId === void 0 ? {} : { effectiveLayerId: entry.effectiveLayerId },
201
+ ...entry.effectiveOrigin === void 0 ? {} : { effectiveOrigin: entry.effectiveOrigin },
202
+ shadowed: Object.freeze([...entry.shadowed].sort(compareOrigins)),
203
+ ...entry.tombstone === void 0 ? {} : { tombstone: entry.tombstone },
204
+ tombstones: Object.freeze([...entry.tombstones].sort(compareTombstones))
205
+ });
206
+ }
207
+ function entryRevisionFact(entry) {
208
+ return {
209
+ resourceId: entry.resourceId,
210
+ kind: entry.kind,
211
+ resourcePresent: entry.resource !== void 0,
212
+ effectiveLayerId: entry.effectiveLayerId,
213
+ effectiveOrigin: entry.effectiveOrigin === void 0 ? void 0 : stableOriginFact(entry.effectiveOrigin),
214
+ shadowed: entry.shadowed.map(stableOriginFact),
215
+ tombstone: entry.tombstone === void 0 ? void 0 : stableTombstoneFact(entry.tombstone),
216
+ tombstones: entry.tombstones.map(stableTombstoneFact)
217
+ };
218
+ }
219
+ function cloneResourceRecord(resource) {
220
+ return Object.freeze({
221
+ kind: resource.kind,
222
+ ...resource.fqn === void 0 ? {} : { fqn: resource.fqn },
223
+ ...resource.name === void 0 ? {} : { name: resource.name },
224
+ ...resource.description === void 0 ? {} : { description: resource.description },
225
+ resourceId: resource.resourceId,
226
+ metadata: cloneResourceMetadata(resource.metadata),
227
+ sourceShape: resource.sourceShape,
228
+ logicalPath: resource.logicalPath,
229
+ documentUri: resource.documentUri,
230
+ format: resource.format,
231
+ node: cloneResourceValue(resource.node)
232
+ });
233
+ }
234
+ function cloneResourceMetadata(metadata) {
235
+ return Object.freeze({
236
+ apiVersion: metadata.apiVersion,
237
+ ...metadata.lifecycle === void 0 ? {} : { lifecycle: metadata.lifecycle },
238
+ ...metadata.version === void 0 ? {} : { version: metadata.version }
239
+ });
240
+ }
241
+ function cloneResourceValue(value) {
242
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
243
+ if (Array.isArray(value)) return Object.freeze(value.map((item) => cloneResourceValue(item)));
244
+ const clone = {};
245
+ for (const key of Object.keys(value).sort(compareCodeUnits)) clone[key] = cloneResourceValue(value[key]);
246
+ return Object.freeze(clone);
247
+ }
248
+ function cloneRegisteredKindDefinition(definition) {
249
+ return Object.freeze({
250
+ resourceId: definition.resourceId,
251
+ resourceKind: definition.resourceKind,
252
+ sourceShapes: Object.freeze([...definition.sourceShapes].sort(compareCodeUnits)),
253
+ requiredFiles: Object.freeze([...definition.requiredFiles].sort(compareCodeUnits)),
254
+ currentApiVersion: definition.currentApiVersion,
255
+ supportedApiVersions: Object.freeze([...definition.supportedApiVersions].sort(compareCodeUnits)),
256
+ documentCardinality: definition.documentCardinality,
257
+ documentUri: definition.documentUri
258
+ });
259
+ }
260
+ function normalizedKindContract(definition) {
261
+ return {
262
+ resourceKind: definition.resourceKind,
263
+ sourceShapes: [...definition.sourceShapes].sort(compareCodeUnits),
264
+ requiredFiles: [...definition.requiredFiles].sort(compareCodeUnits),
265
+ currentApiVersion: definition.currentApiVersion,
266
+ supportedApiVersions: [...definition.supportedApiVersions].sort(compareCodeUnits),
267
+ documentCardinality: definition.documentCardinality
268
+ };
269
+ }
270
+ function stableOriginFact(origin) {
271
+ return {
272
+ layerId: origin.layerId,
273
+ layerIndex: origin.layerIndex,
274
+ packageId: origin.packageId,
275
+ documentUri: origin.documentUri,
276
+ logicalPath: origin.logicalPath
277
+ };
278
+ }
279
+ function stableTombstoneFact(origin) {
280
+ return {
281
+ resourceId: origin.resourceId,
282
+ expectedKind: origin.expectedKind,
283
+ reason: origin.reason,
284
+ layerId: origin.layerId,
285
+ layerIndex: origin.layerIndex,
286
+ packageId: origin.packageId
287
+ };
288
+ }
289
+ function isCanonicalVfsDocumentUri(documentUri) {
290
+ return documentUri.startsWith("vfs://@/") && isSafeLogicalPath(documentUri.slice(8));
291
+ }
292
+ function isSafeLogicalPath(logicalPath) {
293
+ if (logicalPath.length === 0 || logicalPath.startsWith("/") || logicalPath.includes("\\")) return false;
294
+ return logicalPath.split("/").every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
295
+ }
296
+ function compareOrigins(left, right) {
297
+ return left.layerIndex - right.layerIndex || compareCodeUnits(left.layerId, right.layerId);
298
+ }
299
+ function compareTombstones(left, right) {
300
+ return left.layerIndex - right.layerIndex || compareCodeUnits(left.resourceId, right.resourceId);
301
+ }
302
+ function stableDiagnostics$1(diagnostics) {
303
+ return Object.freeze([...diagnostics].sort((left, right) => compareCodeUnits(left.location, right.location) || compareCodeUnits(left.code, right.code)));
304
+ }
305
+ function diagnostic$1(code, location, message) {
306
+ return Object.freeze({
307
+ code,
308
+ location,
309
+ message
310
+ });
311
+ }
312
+ function layerLocation$1(index, layerId, subject) {
313
+ return `layer:${index}:${layerId ?? "unnamed"}${subject === void 0 ? "" : `:${subject}`}`;
314
+ }
315
+ //#endregion
316
+ //#region ../resource-core/src/effective-content-identities.ts
317
+ function resolveEffectiveResourceContentIdentities(input) {
318
+ const diagnostics = [];
319
+ if (!isEffectiveRegistryAuthentic(input.registry)) throw compositionError(diagnostic("RESOURCE_CONTENT_IDENTITY_REGISTRY_UNTRUSTED", "content-projector:registry", "Effective content identities require an authentic registry returned by composeLayeredResourceRegistry()."));
320
+ const bindings = effectiveRegistryLayerBindings(input.registry) ?? [];
321
+ if (input.layers.length !== input.registry.layers.length || bindings.length !== input.registry.layers.length) diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_LAYER_COUNT_MISMATCH", "content-projector:layers", "Effective content identity layers must exactly match the composed registry layers."));
322
+ const loadedById = /* @__PURE__ */ new Map();
323
+ for (let index = 0; index < input.registry.layers.length; index += 1) {
324
+ const descriptor = input.registry.layers[index];
325
+ const layer = input.layers[index];
326
+ const binding = bindings[index];
327
+ if (!layer) continue;
328
+ if (!isLoadedResourceTreeAuthentic(layer.tree)) {
329
+ diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_LAYER_UNTRUSTED", layerLocation(index, layer.id), `Layer '${layer.id}' must use an authentic LoadedResourceTree returned by loadResourceTree().`));
330
+ continue;
331
+ }
332
+ if (layer.id !== descriptor.id || binding?.id !== descriptor.id) {
333
+ diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_LAYER_ID_MISMATCH", layerLocation(index, layer.id), `Layer at index ${index} must retain exact id '${descriptor.id}'.`));
334
+ continue;
335
+ }
336
+ if (descriptor.index !== index) {
337
+ diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_LAYER_INDEX_MISMATCH", layerLocation(index, layer.id), `Layer '${layer.id}' has inconsistent registry index ${descriptor.index}.`));
338
+ continue;
339
+ }
340
+ if (layer.tree.manifest.resourceId !== descriptor.packageId) {
341
+ diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_LAYER_PACKAGE_MISMATCH", layerLocation(index, layer.id), `Layer '${layer.id}' must retain package '${descriptor.packageId}'.`));
342
+ continue;
343
+ }
344
+ if (binding?.tree !== layer.tree) {
345
+ diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_LAYER_BINDING_MISMATCH", layerLocation(index, layer.id), `Layer '${layer.id}' must use the exact loaded tree composed into the registry.`));
346
+ continue;
347
+ }
348
+ validateLoadedIdentityCoverage(layer.tree, layer.id, diagnostics);
349
+ loadedById.set(layer.id, layer.tree);
350
+ }
351
+ const effectiveEntries = [...input.registry.byId.values()].filter((entry) => entry.resource !== void 0).sort((left, right) => compareCodeUnits(left.resourceId, right.resourceId));
352
+ const effectiveIds = new Set(effectiveEntries.map((entry) => entry.resourceId));
353
+ for (const resourceId of input.contributions?.keys() ?? []) if (!effectiveIds.has(resourceId)) diagnostics.push(diagnostic("RESOURCE_DIGEST_CONTRIBUTION_OWNER_UNKNOWN", contentLocation(resourceId), `Digest contributions target unknown effective resource '${resourceId}'.`));
354
+ const output = [];
355
+ for (const entry of effectiveEntries) {
356
+ const tree = entry.effectiveLayerId === void 0 ? void 0 : loadedById.get(entry.effectiveLayerId);
357
+ if (!tree || !entry.effectiveOrigin) {
358
+ diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_EFFECTIVE_ORIGIN_MISSING", contentLocation(entry.resourceId), `Effective resource '${entry.resourceId}' has no exact loaded layer origin.`));
359
+ continue;
360
+ }
361
+ validateEffectiveOrigin(entry, input.registry, tree, diagnostics);
362
+ const authorityIdentity = tree.contentIdentities.get(entry.resourceId);
363
+ if (!authorityIdentity) {
364
+ diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_MISSING", contentLocation(entry.resourceId), `Effective resource '${entry.resourceId}' is missing its loader authority identity.`));
365
+ continue;
366
+ }
367
+ try {
368
+ const identity = createResourceContentIdentity({
369
+ resourceId: entry.resourceId,
370
+ authorityDigest: authorityIdentity.authorityDigest,
371
+ contributions: input.contributions?.get(entry.resourceId) ?? []
372
+ });
373
+ output.push([entry.resourceId, identity]);
374
+ } catch (error) {
375
+ if (error instanceof ResourceCompositionError) diagnostics.push(...error.diagnostics);
376
+ else throw error;
377
+ }
378
+ }
379
+ if (diagnostics.length > 0) throw new ResourceCompositionError(stableDiagnostics(diagnostics));
380
+ return readonlyMap(output.sort(([left], [right]) => compareCodeUnits(left, right)));
381
+ }
382
+ function validateLoadedIdentityCoverage(tree, layerId, diagnostics) {
383
+ const resources = [...tree.registry.byKind.values()].flatMap((records) => [...records]).sort((left, right) => compareCodeUnits(left.resourceId, right.resourceId));
384
+ const resourcesById = new Map(resources.map((resource) => [resource.resourceId, resource]));
385
+ for (const resource of resources) {
386
+ const identity = tree.contentIdentities.get(resource.resourceId);
387
+ if (!identity) {
388
+ diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_MISSING", layerLocation(void 0, layerId, resource.resourceId), `Loaded resource '${resource.resourceId}' has no authority identity.`));
389
+ continue;
390
+ }
391
+ const normalized = createResourceContentIdentity({
392
+ resourceId: identity.resourceId,
393
+ authorityDigest: identity.authorityDigest,
394
+ contributions: []
395
+ });
396
+ if (identity.resourceId !== resource.resourceId || identity.contentDigest !== normalized.contentDigest) diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_INVALID", layerLocation(void 0, layerId, resource.resourceId), `Loaded resource '${resource.resourceId}' has an inconsistent authority identity.`));
397
+ }
398
+ for (const resourceId of tree.contentIdentities.keys()) if (!resourcesById.has(resourceId)) diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_EXTRA", layerLocation(void 0, layerId, resourceId), `Loaded tree contains an extra authority identity '${resourceId}'.`));
399
+ }
400
+ function validateEffectiveOrigin(entry, registry, tree, diagnostics) {
401
+ const origin = entry.effectiveOrigin;
402
+ const descriptor = registry.layers[origin.layerIndex];
403
+ const loadedRecord = findResource(tree, entry.resourceId);
404
+ if (!descriptor || descriptor.id !== origin.layerId || descriptor.packageId !== origin.packageId || tree.manifest.resourceId !== origin.packageId || !loadedRecord || loadedRecord.documentUri !== origin.documentUri || loadedRecord.logicalPath !== origin.logicalPath) diagnostics.push(diagnostic("RESOURCE_CONTENT_IDENTITY_EFFECTIVE_ORIGIN_MISMATCH", contentLocation(entry.resourceId), `Effective resource '${entry.resourceId}' does not match its exact layer/package/origin facts.`));
405
+ }
406
+ function findResource(tree, resourceId) {
407
+ for (const records of tree.registry.byKind.values()) {
408
+ const resource = records.find((record) => record.resourceId === resourceId);
409
+ if (resource) return resource;
410
+ }
411
+ }
412
+ function stableDiagnostics(diagnostics) {
413
+ return Object.freeze([...diagnostics].sort((left, right) => compareCodeUnits(left.location, right.location) || compareCodeUnits(left.code, right.code)));
414
+ }
415
+ function compositionError(diagnosticValue) {
416
+ return new ResourceCompositionError(Object.freeze([diagnosticValue]));
417
+ }
418
+ function diagnostic(code, location, message) {
419
+ return Object.freeze({
420
+ code,
421
+ location,
422
+ message
423
+ });
424
+ }
425
+ function layerLocation(index, layerId, resourceId) {
426
+ return `content-layer:${index ?? "unknown"}:${layerId}${resourceId === void 0 ? "" : `:${resourceId}`}`;
427
+ }
428
+ function contentLocation(resourceId) {
429
+ return `content:${resourceId || "unnamed"}`;
430
+ }
431
+ //#endregion
432
+ export { ResourceCompositionError, ResourceValidationError, buildResourceDependencySnapshot, composeLayeredResourceRegistry, createResourceContentIdentity, loadResourceTree, resolveEffectiveResourceContentIdentities, sha256Digest, validateResourceTree };
@@ -31,13 +31,26 @@ interface PlanResourceMappingsOptions {
31
31
  defaultSourceRoot?: string;
32
32
  reservedTargetPaths?: readonly string[];
33
33
  }
34
+ type SafePathLexicalKind = "segment" | "relative-path" | "relative-directory";
35
+ declare class ResourceMappingPathError extends Error {
36
+ readonly uri: string;
37
+ readonly attribute: "from" | "to";
38
+ readonly owner: string;
39
+ readonly rawPath: string;
40
+ readonly issue: string;
41
+ readonly code = "RESOURCE_MAPPING_PATH_INVALID";
42
+ constructor(uri: string, attribute: "from" | "to", owner: string, rawPath: string, issue: string);
43
+ }
34
44
  declare function parseResourceMappings(source: string, uri?: string): ResourceMappings;
35
45
  declare function planResourceMappings(mappings: ResourceMappings, options: PlanResourceMappingsOptions): Promise<ResourceMappingPlan>;
36
46
  declare function applyResourceMappingPlan(plan: ResourceMappingPlan, outputRoot: string): Promise<string[]>;
47
+ declare function safePathLexicalIssue(value: string, kind: SafePathLexicalKind): string | undefined;
48
+ declare function unsafeUnicodeCodeUnitIssue(value: string): string | undefined;
49
+ declare function unsafeControlCodePointIssue(value: string): string | undefined;
37
50
  declare const resourceMappingPackage: {
38
51
  readonly role: "framework";
39
52
  readonly area: "resource-mapping";
40
53
  readonly owns: "declarative multi-root resource copy planning and collision preflight";
41
54
  };
42
55
  //#endregion
43
- export { NamedResourceMapping, PlanResourceMappingsOptions, PlannedResourceCopy, ResourceMappingOperation, ResourceMappingOperationKind, ResourceMappingPlan, ResourceMappings, applyResourceMappingPlan, parseResourceMappings, planResourceMappings, resourceMappingPackage };
56
+ export { NamedResourceMapping, PlanResourceMappingsOptions, PlannedResourceCopy, ResourceMappingOperation, ResourceMappingOperationKind, ResourceMappingPathError, ResourceMappingPlan, ResourceMappings, SafePathLexicalKind, applyResourceMappingPlan, parseResourceMappings, planResourceMappings, resourceMappingPackage, safePathLexicalIssue, unsafeControlCodePointIssue, unsafeUnicodeCodeUnitIssue };
@@ -1,2 +1,2 @@
1
- import { i as resourceMappingPackage, n as parseResourceMappings, r as planResourceMappings, t as applyResourceMappingPlan } from "./src-BlKlpg0J.js";
2
- export { applyResourceMappingPlan, parseResourceMappings, planResourceMappings, resourceMappingPackage };
1
+ import { a as resourceMappingPackage, c as unsafeUnicodeCodeUnitIssue, i as planResourceMappings, n as applyResourceMappingPlan, o as safePathLexicalIssue, r as parseResourceMappings, s as unsafeControlCodePointIssue, t as ResourceMappingPathError } from "./src-25wZPUyX.js";
2
+ export { ResourceMappingPathError, applyResourceMappingPlan, parseResourceMappings, planResourceMappings, resourceMappingPackage, safePathLexicalIssue, unsafeControlCodePointIssue, unsafeUnicodeCodeUnitIssue };
@@ -1,2 +1,2 @@
1
- import { n as resourceProjectionPackage, t as ResourceRegistry } from "./index-DKwcVwK6.js";
1
+ import { n as resourceProjectionPackage, t as ResourceRegistry } from "./index-D2mpux6L.js";
2
2
  export { ResourceRegistry, resourceProjectionPackage };
@@ -1,2 +1,3 @@
1
- import { a as SkillReference, c as compilerSkillPackage, i as SkillDescriptor, n as CompileSkillCapsuleInput, o as compileResourceSkillCapsule, r as SkillCapsulePlan, s as compileSkillCapsule, t as CompileResourceSkillCapsuleInput } from "./index-wU-iKJnW.js";
2
- export { CompileResourceSkillCapsuleInput, CompileSkillCapsuleInput, SkillCapsulePlan, SkillDescriptor, SkillReference, compileResourceSkillCapsule, compileSkillCapsule, compilerSkillPackage };
1
+ import { I as SkillCapsuleDependency } from "./index-Cqh9pEBa.js";
2
+ import { S as skillCapsuleDistributionProjection, _ as applySkillCapsuleDistributionPlan, a as PlannedSkillCapsule, b as compilerSkillPackage, c as SkillCapsuleContentDigest, d as SkillCapsuleDistributionReceipt, f as SkillCapsuleIdentity, g as SkillReference, h as SkillDescriptor, i as PlanSkillCapsuleDistributionInput, l as SkillCapsuleDistributionError, m as SkillCapsuleProvenanceManifest, n as CompileResourceSkillCapsuleInput, o as PlannedSkillFile, p as SkillCapsulePlan, r as CompileSkillCapsuleInput, s as SkillCapsuleApplyStep, t as ApplySkillCapsuleDistributionOptions, u as SkillCapsuleDistributionPlan, v as compileResourceSkillCapsule, x as planSkillCapsuleDistribution, y as compileSkillCapsule } from "./index-96qHPZj2.js";
3
+ export { ApplySkillCapsuleDistributionOptions, CompileResourceSkillCapsuleInput, CompileSkillCapsuleInput, PlanSkillCapsuleDistributionInput, PlannedSkillCapsule, PlannedSkillFile, SkillCapsuleApplyStep, SkillCapsuleContentDigest, type SkillCapsuleDependency, SkillCapsuleDistributionError, SkillCapsuleDistributionPlan, SkillCapsuleDistributionReceipt, SkillCapsuleIdentity, SkillCapsulePlan, SkillCapsuleProvenanceManifest, SkillDescriptor, SkillReference, applySkillCapsuleDistributionPlan, compileResourceSkillCapsule, compileSkillCapsule, compilerSkillPackage, planSkillCapsuleDistribution, skillCapsuleDistributionProjection };
@@ -1,2 +1,2 @@
1
- import { n as compileSkillCapsule, r as compilerSkillPackage, t as compileResourceSkillCapsule } from "./src-D8xlMdXx.js";
2
- export { compileResourceSkillCapsule, compileSkillCapsule, compilerSkillPackage };
1
+ import { a as compilerSkillPackage, i as compileSkillCapsule, n as applySkillCapsuleDistributionPlan, o as planSkillCapsuleDistribution, r as compileResourceSkillCapsule, s as skillCapsuleDistributionProjection, t as SkillCapsuleDistributionError } from "./src-D1Bmq7Lo.js";
2
+ export { SkillCapsuleDistributionError, applySkillCapsuleDistributionPlan, compileResourceSkillCapsule, compileSkillCapsule, compilerSkillPackage, planSkillCapsuleDistribution, skillCapsuleDistributionProjection };