farseer-cli 1.15.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +328 -0
  2. package/dist/commands/code.js +104 -0
  3. package/dist/commands/code.js.map +7 -0
  4. package/dist/commands/model.js +14 -4
  5. package/dist/commands/model.js.map +2 -2
  6. package/dist/index.js +16 -0
  7. package/dist/index.js.map +2 -2
  8. package/dist/pipeline/generated-reference.json +30 -30
  9. package/dist/pipeline/service.js +2 -2
  10. package/dist/pipeline/service.js.map +2 -2
  11. package/dist/services/codefirst/api.js +269 -0
  12. package/dist/services/codefirst/api.js.map +7 -0
  13. package/dist/services/codefirst/binaryDisk.js +67 -0
  14. package/dist/services/codefirst/binaryDisk.js.map +7 -0
  15. package/dist/services/codefirst/byteHashes.js +129 -0
  16. package/dist/services/codefirst/byteHashes.js.map +7 -0
  17. package/dist/services/codefirst/documents.js +563 -0
  18. package/dist/services/codefirst/documents.js.map +7 -0
  19. package/dist/services/codefirst/layoutBinaryProjection.js +974 -0
  20. package/dist/services/codefirst/layoutBinaryProjection.js.map +7 -0
  21. package/dist/services/codefirst/layoutCompose.js +593 -0
  22. package/dist/services/codefirst/layoutCompose.js.map +7 -0
  23. package/dist/services/codefirst/layoutCore.js +260 -0
  24. package/dist/services/codefirst/layoutCore.js.map +7 -0
  25. package/dist/services/codefirst/layoutPaths.js +492 -0
  26. package/dist/services/codefirst/layoutPaths.js.map +7 -0
  27. package/dist/services/codefirst/layoutProjection.js +995 -0
  28. package/dist/services/codefirst/layoutProjection.js.map +7 -0
  29. package/dist/services/codefirst/layoutReadback.js +2552 -0
  30. package/dist/services/codefirst/layoutReadback.js.map +7 -0
  31. package/dist/services/codefirst/layoutReadbackPlacement.js +1517 -0
  32. package/dist/services/codefirst/layoutReadbackPlacement.js.map +7 -0
  33. package/dist/services/codefirst/layoutReceipt.js +1592 -0
  34. package/dist/services/codefirst/layoutReceipt.js.map +7 -0
  35. package/dist/services/codefirst/layoutScan.js +882 -0
  36. package/dist/services/codefirst/layoutScan.js.map +7 -0
  37. package/dist/services/codefirst/output.js +179 -0
  38. package/dist/services/codefirst/output.js.map +7 -0
  39. package/dist/services/codefirst/types.js +17 -0
  40. package/dist/services/codefirst/types.js.map +7 -0
  41. package/dist/services/codefirst/workflow.js +581 -0
  42. package/dist/services/codefirst/workflow.js.map +7 -0
  43. package/dist/services/codefirst/workspace.js +310 -0
  44. package/dist/services/codefirst/workspace.js.map +7 -0
  45. package/dist/services/codefirst/workspaceLock.js +148 -0
  46. package/dist/services/codefirst/workspaceLock.js.map +7 -0
  47. package/dist/services/codefirst/workspaceRoot.js +147 -0
  48. package/dist/services/codefirst/workspaceRoot.js.map +7 -0
  49. package/dist/utils/logger.js +9 -3
  50. package/dist/utils/logger.js.map +2 -2
  51. package/docs/pipeline-client-guide.md +2 -2
  52. package/docs/pipeline-reference.md +156 -99
  53. package/package.json +3 -2
  54. package/skills/pipeline-authoring/SKILL.md +10 -8
  55. package/skills/pipeline-authoring/practices.md +39 -25
@@ -0,0 +1,593 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var layoutCompose_exports = {};
20
+ __export(layoutCompose_exports, {
21
+ composeLayoutSubmission: () => composeLayoutSubmission,
22
+ inspectCurrentLayoutPlacement: () => inspectCurrentLayoutPlacement,
23
+ submittedDocumentFiles: () => submittedDocumentFiles
24
+ });
25
+ module.exports = __toCommonJS(layoutCompose_exports);
26
+ var import_layoutBinaryProjection = require("./layoutBinaryProjection");
27
+ var import_layoutCore = require("./layoutCore");
28
+ var import_layoutPaths = require("./layoutPaths");
29
+ var import_layoutProjection = require("./layoutProjection");
30
+ function sourceEquals(left, right) {
31
+ return (0, import_layoutCore.sourceIdentityKey)(left) === (0, import_layoutCore.sourceIdentityKey)(right);
32
+ }
33
+ function validSemanticPlacement(placement) {
34
+ if (!placement.name || placement.parent.some((part) => !part)) return false;
35
+ try {
36
+ (0, import_layoutPaths.encodeLayoutSegment)(placement.name);
37
+ for (const part of placement.parent) (0, import_layoutPaths.encodeLayoutSegment)(part);
38
+ return true;
39
+ } catch {
40
+ return false;
41
+ }
42
+ }
43
+ function detachedDocumentPlacement(value) {
44
+ if (value.kind === "folder") {
45
+ if (!Array.isArray(value.path) || value.path.length === 0 || value.path.some((part) => typeof part !== "string" || part.length === 0))
46
+ return void 0;
47
+ const names = value.path;
48
+ const placement2 = {
49
+ parent: names.slice(0, -1),
50
+ name: names.at(-1),
51
+ role: "directory"
52
+ };
53
+ return validSemanticPlacement(placement2) ? placement2 : void 0;
54
+ }
55
+ if (typeof value.kind !== "string" || !["variable", "dimension_table", "sheet", "dashboard", "remote_job"].includes(value.kind) || typeof value.name !== "string" || value.name.length === 0 || !Array.isArray(value.folder) || value.folder.some((part) => typeof part !== "string" || part.length === 0))
56
+ return void 0;
57
+ const placement = {
58
+ parent: value.folder,
59
+ name: value.name,
60
+ extension: ".json",
61
+ role: "document"
62
+ };
63
+ return validSemanticPlacement(placement) ? placement : void 0;
64
+ }
65
+ function rawPlacement(name, folder) {
66
+ if (!Array.isArray(folder) || folder.some((part) => typeof part !== "string" || part.length === 0))
67
+ return void 0;
68
+ const placement = { parent: folder, name, role: "raw" };
69
+ return validSemanticPlacement(placement) ? placement : void 0;
70
+ }
71
+ function placementRequest(placement, identity, directory) {
72
+ return {
73
+ directory,
74
+ name: placement.name,
75
+ ...placement.extension ? { extension: placement.extension } : {},
76
+ role: placement.role,
77
+ identity,
78
+ ...placement.role === "directory" ? { requiredChildren: ["_folder.json"] } : {}
79
+ };
80
+ }
81
+ function sameRequest(left, right) {
82
+ try {
83
+ return left.directory === right.directory && left.name === right.name && (left.extension ?? "") === (right.extension ?? "") && (left.kind ?? (left.role === "directory" ? "directory" : "file")) === (right.kind ?? (right.role === "directory" ? "directory" : "file")) && left.role === right.role && left.identity === right.identity && JSON.stringify((0, import_layoutPaths.normalizeRequiredLayoutChildren)(left)) === JSON.stringify((0, import_layoutPaths.normalizeRequiredLayoutChildren)(right));
84
+ } catch {
85
+ return false;
86
+ }
87
+ }
88
+ function inspectCurrentLayoutPlacement(input) {
89
+ const diagnostics = [];
90
+ const markers = new Map(
91
+ input.scan.artifacts.filter((artifact) => artifact.role === "folder-control" && artifact.present).map((artifact) => [(0, import_layoutPaths.folderDirectory)(artifact.path), artifact])
92
+ );
93
+ const folderNames = (directory, file) => {
94
+ const relative = directory === "tree" ? "" : directory.slice("tree/".length);
95
+ if (!relative) return [];
96
+ const parts = relative.split("/");
97
+ const names = [];
98
+ for (let index = 0; index < parts.length; index++) {
99
+ const physical = `tree/${parts.slice(0, index + 1).join("/")}`;
100
+ const marker = markers.get(physical);
101
+ if (!marker?.decodedName) {
102
+ diagnostics.push(
103
+ (0, import_layoutCore.diagnostic)("incomplete-folder-chain", file, `Managed folder marker is missing for ${physical}`)
104
+ );
105
+ return void 0;
106
+ }
107
+ names.push(marker.decodedName);
108
+ }
109
+ return names;
110
+ };
111
+ const normalParents = /* @__PURE__ */ new Map([[(0, import_layoutCore.canonicalFragmentHash)([]), ["tree"]]]);
112
+ const normalMarkerNames = /* @__PURE__ */ new Map();
113
+ for (const [directory, marker] of markers) {
114
+ const names = folderNames(directory, marker.path);
115
+ if (!names) continue;
116
+ normalMarkerNames.set(directory, names);
117
+ const key = (0, import_layoutCore.canonicalFragmentHash)(names);
118
+ normalParents.set(key, [...normalParents.get(key) ?? [], directory]);
119
+ }
120
+ const detachedParents = /* @__PURE__ */ new Map();
121
+ for (const artifact of input.scan.artifacts) {
122
+ if (artifact.role !== "detached-document" || !artifact.present) continue;
123
+ const value = (0, import_layoutCore.object)(artifact.json);
124
+ const semantic = value?.kind === "folder" ? detachedDocumentPlacement(value) : void 0;
125
+ if (!value || !semantic) continue;
126
+ const semanticPath = [...semantic.parent, semantic.name];
127
+ const key = (0, import_layoutCore.canonicalFragmentHash)(semanticPath);
128
+ const claim = {
129
+ artifact,
130
+ source: (0, import_layoutCore.sourceFromValue)(value),
131
+ semanticPath,
132
+ healthy: false
133
+ };
134
+ detachedParents.set(key, [...detachedParents.get(key) ?? [], claim]);
135
+ }
136
+ const resolveParent = (semantic) => {
137
+ const semanticPathHash = (0, import_layoutCore.canonicalFragmentHash)(semantic.parent);
138
+ const normal = normalParents.get(semanticPathHash) ?? [];
139
+ const detached = detachedParents.get(semanticPathHash) ?? [];
140
+ if (normal.length + detached.length !== 1) return void 0;
141
+ if (normal.length === 1) return { type: "normal", directory: normal[0] };
142
+ const parent = detached[0];
143
+ return parent.healthy && parent.source ? { type: "detached", source: parent.source, semanticPathHash } : void 0;
144
+ };
145
+ const validateRepresentationFallback = (proof, source, semantic) => {
146
+ if (proof.sourceKey !== (0, import_layoutCore.sourceIdentityKey)(source)) return false;
147
+ const direct = proof.request !== void 0 || proof.existingClaims !== void 0;
148
+ const inherited = proof.inheritedFrom !== void 0;
149
+ if (direct === inherited) return false;
150
+ const parent = resolveParent(semantic);
151
+ if (!parent) return false;
152
+ const identity = "id" in source.resource ? source.resource.id : source.resource.key;
153
+ if (parent.type === "detached")
154
+ return inherited && proof.request === void 0 && proof.existingClaims === void 0 && proof.inheritedFrom.sourceKey === (0, import_layoutCore.sourceIdentityKey)(parent.source) && proof.inheritedFrom.semanticPathHash === parent.semanticPathHash;
155
+ if (!direct || inherited || !proof.request || !proof.existingClaims) return false;
156
+ const expectedRequest = placementRequest(semantic, identity, parent.directory);
157
+ return sameRequest(proof.request, expectedRequest) && (0, import_layoutPaths.provesUnrepresentableRequest)(proof.request, proof.existingClaims);
158
+ };
159
+ const validateDetachedDocument = (artifact, value) => {
160
+ const source = (0, import_layoutCore.sourceFromValue)(value);
161
+ const proof = input.detachedDocumentProofs[artifact.path];
162
+ if (!source || !proof) return false;
163
+ const identity = "id" in source.resource ? source.resource.id : source.resource.key;
164
+ let expected;
165
+ try {
166
+ expected = `detached/${source.resource.kind}/${(0, import_layoutPaths.encodeLayoutSegment)(identity)}.json`;
167
+ } catch {
168
+ return false;
169
+ }
170
+ if (artifact.path !== expected || proof.sourceKey !== (0, import_layoutCore.sourceIdentityKey)(source)) return false;
171
+ const placementHash = (0, import_layoutCore.canonicalFragmentHash)({
172
+ name: value.name ?? null,
173
+ folder: value.folder ?? null,
174
+ path: value.path ?? null,
175
+ parent: value.parent ?? null
176
+ });
177
+ if (proof.reason === "damage-proof") {
178
+ if (!("id" in source.resource)) return false;
179
+ const baseline = input.canonicalBaseline[`${source.resource.kind}/${source.resource.id}`];
180
+ const definitionSlot = value.kind === "dimension_table" ? "table-definition" : "document";
181
+ const routes = input.groupedRoutes.filter((route) => sourceEquals(route.source, source));
182
+ const retained = routes.length === 0 || routes.some((route) => route.selector.file === artifact.path && route.selector.slot === definitionSlot);
183
+ const semantic2 = value.kind === "folder" ? detachedDocumentPlacement(value) : void 0;
184
+ const ownClaims = semantic2 ? (normalParents.get((0, import_layoutCore.canonicalFragmentHash)([...semantic2.parent, semantic2.name]))?.length ?? 0) + (detachedParents.get((0, import_layoutCore.canonicalFragmentHash)([...semantic2.parent, semantic2.name]))?.length ?? 0) : 0;
185
+ return proof.placementHash === placementHash && proof.baselineHash === baseline && retained && (!semantic2 || ownClaims === 1);
186
+ }
187
+ const semantic = detachedDocumentPlacement(value);
188
+ if (!semantic || !validateRepresentationFallback(proof, source, semantic)) return false;
189
+ if (value.kind !== "folder") return true;
190
+ const ownKey = (0, import_layoutCore.canonicalFragmentHash)([...semantic.parent, semantic.name]);
191
+ return (normalParents.get(ownKey)?.length ?? 0) + (detachedParents.get(ownKey)?.length ?? 0) === 1;
192
+ };
193
+ const detachedValidation = /* @__PURE__ */ new Map();
194
+ const folderClaims = [...detachedParents.values()].flat().sort(
195
+ (left, right) => left.semanticPath.length - right.semanticPath.length || (0, import_layoutCore.compareText)(left.artifact.path, right.artifact.path)
196
+ );
197
+ for (const claim of folderClaims) {
198
+ const value = (0, import_layoutCore.object)(claim.artifact.json);
199
+ const valid = validateDetachedDocument(claim.artifact, value);
200
+ detachedValidation.set(claim.artifact.path, valid);
201
+ const proof = input.detachedDocumentProofs[claim.artifact.path];
202
+ if (valid && proof?.reason === "representation-fallback") claim.healthy = true;
203
+ }
204
+ const bind = (groupedSources) => {
205
+ const sourceBoundFolders = /* @__PURE__ */ new Map();
206
+ const collidingFolders = /* @__PURE__ */ new Map();
207
+ const collisionKey = (semanticPath) => (0, import_layoutCore.canonicalFragmentHash)(semanticPath.map(import_layoutPaths.layoutCollisionKey));
208
+ const addSourceBoundFolder = (folder) => {
209
+ const key = (0, import_layoutCore.canonicalFragmentHash)([...folder.semanticPath]);
210
+ sourceBoundFolders.set(key, [...sourceBoundFolders.get(key) ?? [], folder]);
211
+ const folded = collisionKey(folder.semanticPath);
212
+ collidingFolders.set(folded, [...collidingFolders.get(folded) ?? [], folder]);
213
+ };
214
+ for (const [directory, marker] of markers) {
215
+ const names = normalMarkerNames.get(directory);
216
+ const value = (0, import_layoutCore.object)(marker.json);
217
+ const authoredSource = value && (0, import_layoutCore.sourceFromValue)({ ...value, kind: "folder" });
218
+ if (!names) continue;
219
+ const routes = groupedSources.filter(
220
+ (mapping) => mapping.selector.file === marker.path && mapping.selector.slot === "document" && (authoredSource ? sourceEquals(mapping.source, authoredSource) : mapping.source.type === "transient")
221
+ );
222
+ if (routes.length === 1)
223
+ addSourceBoundFolder({
224
+ type: "normal",
225
+ source: routes[0].source,
226
+ semanticPath: names,
227
+ directory
228
+ });
229
+ }
230
+ for (const claim of folderClaims) {
231
+ const source = claim.source;
232
+ const proof = input.detachedDocumentProofs[claim.artifact.path];
233
+ if (!source || !proof || !detachedValidation.get(claim.artifact.path)) continue;
234
+ const routes = groupedSources.filter(
235
+ (mapping) => sourceEquals(mapping.source, source) && mapping.selector.file === claim.artifact.path && mapping.selector.slot === "document"
236
+ );
237
+ if (routes.length !== 1) continue;
238
+ addSourceBoundFolder(
239
+ proof.reason === "representation-fallback" ? {
240
+ type: "detached-representation",
241
+ source,
242
+ semanticPath: claim.semanticPath,
243
+ semanticPathHash: (0, import_layoutCore.canonicalFragmentHash)(claim.semanticPath)
244
+ } : { type: "damaged", source, semanticPath: claim.semanticPath }
245
+ );
246
+ }
247
+ return {
248
+ folderNames,
249
+ folderPlacement: (semanticPath) => {
250
+ const matches = sourceBoundFolders.get((0, import_layoutCore.canonicalFragmentHash)([...semanticPath])) ?? [];
251
+ return matches.length === 1 ? matches[0] : void 0;
252
+ },
253
+ collidingFolderPlacements: (semanticPath) => collidingFolders.get(collisionKey(semanticPath)) ?? [],
254
+ detachedDocumentValid: (artifact, value) => detachedValidation.get(artifact.path) ?? validateDetachedDocument(artifact, value),
255
+ detachedFileValid: (artifact, value, folder) => {
256
+ const proof = artifact.source ? input.detachedFileProofs[artifact.source] : void 0;
257
+ if (proof?.reason !== "representation-fallback") return true;
258
+ const source = (0, import_layoutCore.sourceFromValue)({ ...value, kind: "file" });
259
+ const semantic = artifact.decodedName ? rawPlacement(artifact.decodedName, folder) : void 0;
260
+ return !!source && !!semantic && validateRepresentationFallback(proof, source, semantic);
261
+ },
262
+ withGroupedSources: bind
263
+ };
264
+ };
265
+ return { placement: bind(input.groupedSources ?? []), diagnostics };
266
+ }
267
+ function submittedDocumentFiles(sources) {
268
+ const files = /* @__PURE__ */ new Map();
269
+ for (const { codec, mapping } of sources) {
270
+ if (codec === "grouped" && mapping.selector.slot === "owner-navigation") continue;
271
+ const file = codec === "grouped" ? mapping.selector.file : mapping.selector.sidecar;
272
+ if (!files.has(mapping.documentIndex)) files.set(mapping.documentIndex, file);
273
+ }
274
+ return files;
275
+ }
276
+ function rawNavigationEvidenceDiagnostics(routes) {
277
+ const diagnostics = [];
278
+ const sources = /* @__PURE__ */ new Set();
279
+ for (const route of routes) {
280
+ const sourceKey = (0, import_layoutCore.sourceIdentityKey)(route.source);
281
+ const identity = route.selector.identity;
282
+ const sourceMatches = route.source.resource.kind === "file" && ("id" in route.source.resource && "id" in identity && route.source.resource.id === identity.id || "key" in route.source.resource && "key" in identity && route.source.resource.key === identity.key);
283
+ const valid = sourceMatches && !sources.has(sourceKey) && (0, import_layoutPaths.isRawSidecarPath)(route.selector.sidecar) && route.sourcePath.length === 1 && route.sourcePath[0] === "shares" && /^access\/shares\/[^/]+\.json$/.test(route.groupFile) && route.priorCleanHash === (0, import_layoutCore.canonicalFragmentHash)(route.groupFile);
284
+ if (!valid)
285
+ diagnostics.push({
286
+ code: "invalid-raw-navigation-route",
287
+ path: route.selector.sidecar,
288
+ sourcePath: ["shares"],
289
+ message: "Raw share navigation evidence is not source-bound and internally consistent"
290
+ });
291
+ sources.add(sourceKey);
292
+ }
293
+ return diagnostics;
294
+ }
295
+ function prepareArtifacts(scan, evidence) {
296
+ const inspected = inspectCurrentLayoutPlacement({
297
+ scan,
298
+ detachedDocumentProofs: evidence.detachedDocumentProofs,
299
+ detachedFileProofs: evidence.detachedFileProofs,
300
+ canonicalBaseline: evidence.canonicalBaseline,
301
+ groupedRoutes: evidence.groupedRoutes
302
+ });
303
+ const diagnostics = inspected.diagnostics;
304
+ const placement = inspected.placement;
305
+ const grouped = [];
306
+ const raw = [];
307
+ const attachments = [];
308
+ for (const artifact of scan.artifacts) {
309
+ if (!artifact.present && artifact.role !== "raw" || artifact.role === "raw-metadata" || artifact.role === "attachment")
310
+ continue;
311
+ const value = (0, import_layoutCore.object)(artifact.json);
312
+ if (!value) {
313
+ diagnostics.push((0, import_layoutCore.diagnostic)("unclassified-layout-artifact", artifact.path, "Artifact is not JSON"));
314
+ continue;
315
+ }
316
+ if (artifact.role === "raw") {
317
+ const directory = (0, import_layoutPaths.parentDirectory)(artifact.path);
318
+ const detached = artifact.path.startsWith("detached/files/");
319
+ const folder = detached ? value.folder : placement.folderNames(directory, artifact.path);
320
+ if (!artifact.source || !artifact.decodedName || folder === void 0) {
321
+ diagnostics.push(
322
+ (0, import_layoutCore.diagnostic)("incomplete-raw-artifact", artifact.path, "Raw artifact lacks sidecar placement")
323
+ );
324
+ continue;
325
+ }
326
+ const detachedProof = detached ? evidence.detachedFileProofs[artifact.source] : void 0;
327
+ if (detachedProof?.reason === "representation-fallback" && !placement.detachedFileValid(artifact, value, folder)) {
328
+ diagnostics.push(
329
+ (0, import_layoutCore.diagnostic)(
330
+ "invalid-detached-proof",
331
+ artifact.source,
332
+ "Detached raw placement lacks trusted parent proof"
333
+ )
334
+ );
335
+ continue;
336
+ }
337
+ raw.push({
338
+ sidecar: artifact.source,
339
+ bytes: artifact.path,
340
+ metadata: value,
341
+ name: artifact.decodedName,
342
+ folder,
343
+ ...detachedProof ? { detached: detachedProof } : {}
344
+ });
345
+ continue;
346
+ }
347
+ let semantic = { ...value };
348
+ if (artifact.role === "folder-control") {
349
+ const names = placement.folderNames((0, import_layoutPaths.folderDirectory)(artifact.path), artifact.path);
350
+ if (!names) continue;
351
+ semantic = { ...semantic, kind: "folder", path: names };
352
+ delete semantic.name;
353
+ } else if (artifact.role === "document") {
354
+ const folder = placement.folderNames((0, import_layoutPaths.parentDirectory)(artifact.path), artifact.path);
355
+ if (!folder || !artifact.decodedName) continue;
356
+ semantic = { ...semantic, name: artifact.decodedName, folder };
357
+ } else if (import_layoutCore.FILENAME_NAME_ROLES.has(artifact.role)) {
358
+ if (!artifact.decodedName) {
359
+ diagnostics.push(
360
+ (0, import_layoutCore.diagnostic)("missing-layout-name", artifact.path, "Artifact name cannot be decoded")
361
+ );
362
+ continue;
363
+ }
364
+ semantic = { ...semantic, name: artifact.decodedName };
365
+ } else if (artifact.role === "detached-document" && !placement.detachedDocumentValid(artifact, semantic)) {
366
+ diagnostics.push(
367
+ (0, import_layoutCore.diagnostic)(
368
+ "invalid-detached-proof",
369
+ artifact.path,
370
+ "Detached document lacks trusted placement proof"
371
+ )
372
+ );
373
+ continue;
374
+ }
375
+ const role = artifact.role === "share-group" ? "share-group" : semantic.kind === "dimension_table" ? "combined-table" : "document";
376
+ const groupedArtifact = { role, path: artifact.path, value: semantic };
377
+ grouped.push(groupedArtifact);
378
+ const field = (0, import_layoutCore.attachmentField)(semantic);
379
+ if (field)
380
+ attachments.push({
381
+ artifact: groupedArtifact,
382
+ input: {
383
+ origin: "local",
384
+ ownerFile: artifact.path,
385
+ ownerDocument: semantic,
386
+ field
387
+ }
388
+ });
389
+ }
390
+ return { grouped, raw, attachments, diagnostics, placement };
391
+ }
392
+ function binaryBaselines(raw, baseline) {
393
+ return raw.flatMap((candidate) => {
394
+ const id = candidate.metadata.id;
395
+ return typeof id === "string" && baseline[`file/${id}`] ? [
396
+ {
397
+ source: { type: "resource", resource: { kind: "file", id } },
398
+ canonicalHash: baseline[`file/${id}`]
399
+ }
400
+ ] : [];
401
+ });
402
+ }
403
+ function blocked(diagnostics, byteFacts) {
404
+ return { status: "blocked", diagnostics: [...diagnostics], byteFacts };
405
+ }
406
+ function composeLayoutSubmission(input) {
407
+ const initialDiagnostics = [
408
+ ...input.scan.diagnostics.map((diagnostic) => ({ ...diagnostic })),
409
+ ...input.byteEvidence.diagnostics
410
+ ];
411
+ if (initialDiagnostics.length > 0) return blocked(initialDiagnostics, input.byteEvidence.facts);
412
+ const warnings = [];
413
+ for (const artifact of input.scan.artifacts)
414
+ if (artifact.ignoredNameOverride !== void 0 && artifact.decodedName !== void 0)
415
+ warnings.push(
416
+ (0, import_layoutCore.diagnostic)(
417
+ "name-override-ignored",
418
+ artifact.source ?? artifact.path,
419
+ `the "name" field says ${JSON.stringify(artifact.ignoredNameOverride)} but the filename names ${JSON.stringify(artifact.decodedName)}; the filename is the name, so rename the file to rename the resource`
420
+ )
421
+ );
422
+ const blocking = (diagnostics) => {
423
+ const rest = [];
424
+ for (const item of diagnostics) (item.code === "lost-source-correspondence" ? warnings : rest).push(item);
425
+ return rest;
426
+ };
427
+ const prepared = prepareArtifacts(input.scan, input.evidence);
428
+ if (prepared.diagnostics.length > 0) return blocked(prepared.diagnostics, input.byteEvidence.facts);
429
+ const navigationDiagnostics = rawNavigationEvidenceDiagnostics(input.evidence.rawNavigationRoutes);
430
+ if (navigationDiagnostics.length > 0) return blocked(navigationDiagnostics, input.byteEvidence.facts);
431
+ const retainedBinaryRoutes = input.evidence.binaryRoutes.filter(
432
+ (route) => !(route.source.type === "transient" && route.selector.slot === "owner-attachment")
433
+ );
434
+ const preflightAttachments = prepared.attachments.map(({ input: attachment }, index) => {
435
+ const value = (0, import_layoutCore.object)(attachment.ownerDocument);
436
+ return {
437
+ ...attachment,
438
+ ownerSource: (0, import_layoutCore.sourceFromValue)(value) ?? { type: "transient", token: `layout-preflight:${index + 1}` }
439
+ };
440
+ });
441
+ const preflight = (0, import_layoutBinaryProjection.composeBinaryLayout)({
442
+ rawFiles: prepared.raw,
443
+ attachments: preflightAttachments,
444
+ bytes: input.byteEvidence.facts,
445
+ priorRoutes: retainedBinaryRoutes,
446
+ submissionProofs: input.evidence.binarySubmissionProofs,
447
+ reservedTransientTokens: input.evidence.reservedTransientTokens,
448
+ authoritativeBaselines: binaryBaselines(prepared.raw, input.evidence.canonicalBaseline)
449
+ });
450
+ const preflightBlocking = blocking(preflight.diagnostics);
451
+ if (preflightBlocking.length > 0) return blocked(preflightBlocking, input.byteEvidence.facts);
452
+ const unkeyedNavigation = preflight.navigation.find((navigation) => navigation.source.type === "transient");
453
+ if (unkeyedNavigation)
454
+ return blocked(
455
+ [
456
+ {
457
+ code: "unkeyed-raw-share-owner",
458
+ path: unkeyedNavigation.selector.sidecar,
459
+ sourcePath: [...unkeyedNavigation.sourcePath],
460
+ message: "A raw share pointer requires an ID or committed key"
461
+ }
462
+ ],
463
+ input.byteEvidence.facts
464
+ );
465
+ const normalizedArtifacts = prepared.grouped.map((artifact) => {
466
+ const projected = preflight.ownerFields.filter((field) => field.ownerFile === artifact.path);
467
+ if (projected.length === 0 || artifact.role === "share-group") return artifact;
468
+ const value = { ...artifact.value };
469
+ for (const field of projected) {
470
+ if (field.status === "value") value[field.field] = field.value;
471
+ else if (field.status === "omitted") delete value[field.field];
472
+ }
473
+ return { ...artifact, value };
474
+ });
475
+ const navigationBySource = new Map(
476
+ preflight.navigation.map((navigation) => [(0, import_layoutCore.sourceIdentityKey)(navigation.source), navigation])
477
+ );
478
+ const priorNavigationBySource = new Map(
479
+ input.evidence.rawNavigationRoutes.map((navigation) => [(0, import_layoutCore.sourceIdentityKey)(navigation.source), navigation])
480
+ );
481
+ const externalOwners = preflight.rawSources.flatMap((mapping) => {
482
+ if (mapping.source.type !== "resource") return [];
483
+ const document = preflight.rawDocuments[mapping.documentIndex];
484
+ const owner = "id" in mapping.source.resource ? { kind: "file", id: mapping.source.resource.id } : { kind: "file", key: mapping.source.resource.key };
485
+ const currentNavigation = navigationBySource.get((0, import_layoutCore.sourceIdentityKey)(mapping.source));
486
+ const priorNavigation = priorNavigationBySource.get((0, import_layoutCore.sourceIdentityKey)(mapping.source));
487
+ return [
488
+ {
489
+ source: mapping.source,
490
+ owner,
491
+ value: document,
492
+ location: { file: mapping.selector.sidecar, path: [] },
493
+ ...currentNavigation ? { currentGroupFile: currentNavigation.groupFile } : {},
494
+ ...priorNavigation ? { priorGroupFile: priorNavigation.groupFile } : {}
495
+ }
496
+ ];
497
+ });
498
+ const grouped = (0, import_layoutProjection.composeGroupedLayout)({
499
+ artifacts: normalizedArtifacts,
500
+ externalOwners,
501
+ priorRoutes: input.evidence.groupedRoutes,
502
+ submissionProofs: input.evidence.groupedSubmissionProofs,
503
+ reservedTransientTokens: input.evidence.reservedTransientTokens,
504
+ derivedSourceProofs: input.evidence.derivedSourceProofs
505
+ });
506
+ const groupedBlocking = blocking(grouped.diagnostics);
507
+ if (groupedBlocking.length > 0) return blocked(groupedBlocking, input.byteEvidence.facts);
508
+ grouped.diagnostics = groupedBlocking;
509
+ const finalAttachments = prepared.attachments.flatMap(({ input: attachment }) => {
510
+ const mapping = grouped.sources.find(
511
+ (source) => source.selector.file === attachment.ownerFile && source.selector.slot === "document"
512
+ );
513
+ return mapping ? [{ ...attachment, ownerSource: mapping.source }] : [];
514
+ });
515
+ if (finalAttachments.length !== prepared.attachments.length)
516
+ return blocked(
517
+ [(0, import_layoutCore.diagnostic)("missing-owner-source", ".", "Attachment owner has no grouped source mapping")],
518
+ input.byteEvidence.facts
519
+ );
520
+ const binary = (0, import_layoutBinaryProjection.composeBinaryLayout)({
521
+ rawFiles: prepared.raw,
522
+ attachments: finalAttachments,
523
+ bytes: input.byteEvidence.facts,
524
+ priorRoutes: retainedBinaryRoutes,
525
+ submissionProofs: input.evidence.binarySubmissionProofs,
526
+ reservedTransientTokens: input.evidence.reservedTransientTokens,
527
+ authoritativeBaselines: binaryBaselines(prepared.raw, input.evidence.canonicalBaseline)
528
+ });
529
+ const binaryBlocking = blocking(binary.diagnostics);
530
+ if (binaryBlocking.length > 0) return blocked(binaryBlocking, input.byteEvidence.facts);
531
+ binary.diagnostics = binaryBlocking;
532
+ const rawNavigation = [];
533
+ const matchedPrior = /* @__PURE__ */ new Set();
534
+ for (const current of binary.navigation) {
535
+ if (current.source.type !== "resource") continue;
536
+ const key = (0, import_layoutCore.sourceIdentityKey)(current.source);
537
+ const prior = priorNavigationBySource.get(key);
538
+ if (prior) matchedPrior.add(key);
539
+ rawNavigation.push({
540
+ source: current.source,
541
+ selector: current.selector,
542
+ sourcePath: current.sourcePath,
543
+ groupFile: current.groupFile,
544
+ currentHash: current.currentHash,
545
+ ...prior ? { priorCleanHash: prior.priorCleanHash } : {},
546
+ state: prior ? prior.priorCleanHash === current.currentHash ? "clean" : "dirty" : "new"
547
+ });
548
+ }
549
+ for (const prior of input.evidence.rawNavigationRoutes)
550
+ if (!matchedPrior.has((0, import_layoutCore.sourceIdentityKey)(prior.source)))
551
+ rawNavigation.push({
552
+ source: prior.source,
553
+ selector: prior.selector,
554
+ sourcePath: prior.sourcePath,
555
+ priorCleanHash: prior.priorCleanHash,
556
+ state: "absent"
557
+ });
558
+ const documents = [...grouped.documents, ...binary.rawDocuments];
559
+ const sources = [
560
+ ...grouped.sources.map((mapping) => ({ codec: "grouped", mapping })),
561
+ ...binary.rawSources.map((mapping) => ({
562
+ codec: "raw",
563
+ mapping: { ...mapping, documentIndex: mapping.documentIndex + grouped.documents.length }
564
+ }))
565
+ ];
566
+ const composed = (0, import_layoutCore.clone)({
567
+ status: "complete",
568
+ documents,
569
+ sources,
570
+ grouped,
571
+ binary,
572
+ rawNavigation,
573
+ byteFacts: input.byteEvidence.facts,
574
+ warnings,
575
+ context: {
576
+ scan: input.scan,
577
+ evidence: input.evidence,
578
+ groupedArtifacts: normalizedArtifacts,
579
+ byteFacts: input.byteEvidence.facts
580
+ }
581
+ });
582
+ return {
583
+ ...composed,
584
+ context: { ...composed.context, placement: prepared.placement.withGroupedSources(grouped.sources) }
585
+ };
586
+ }
587
+ // Annotate the CommonJS export names for ESM import in node:
588
+ 0 && (module.exports = {
589
+ composeLayoutSubmission,
590
+ inspectCurrentLayoutPlacement,
591
+ submittedDocumentFiles
592
+ });
593
+ //# sourceMappingURL=layoutCompose.js.map